@enhancely/node
v1.0.1
Published
Enhance your NodeJS project with AI-generated JSON-LD schema for better SEO and LLM results
Downloads
216
Readme
Enhancely JSON-LD for NodeJS
Enhancely NodeJS 20+ client for fetching AI-generated JSON-LD schema for your pages.
Installation
npm install @enhancely/nodepnpm install @enhancely/nodeyarn add @enhancely/nodebun add @enhancely/nodePaid Account
Get an account at enhancely.ai to get your own API key for the targeted domain.
Usage with ETag
jsonld(url, etag?) accepts an optional second parameter. If you pass a non-empty ETag, the client forwards it as If-None-Match upstream.
import { setApiKey, jsonld } from '@enhancely/node';
// Option A: provide API key via environment variable ENHANCELY_API_KEY
// Option B: set it at runtime:
setApiKey(process.env.ENHANCELY_API_KEY);
// from your cache or previous response or null
const prevEtag = 'abc123';
const resp = await jsonld('https://example.com/path', prevEtag);
// check for 412|304 Not Modified
if (resp.notModified()) {
// unchanged – use your cached data
} else if (resp.ready()) {
// 1) TODO: update cache with resp.etag() and resp.json()/resp.toString()
// 2) output json-ld with resp.toString()
} else if (resp.queued()) {
// 201 – queued for generation
} else if (resp.processing()) {
// 202 – still generating
} else {
// error
console.error(resp.error());
}
console.log(resp.toString()); // ready-to-embed <script type="application/ld+json"> or HTML comment
console.log(resp.json()); // parsed JSON object
console.log(resp.ready()); // true if status 200 (JSON-LD ready)
console.log(resp.ok()); // true if 2xx
console.log(resp.queued()); // true if 201 (queued)
console.log(resp.processing()); // true if 202 (generating)
console.log(resp.notModified()); // true if 412/304
console.log(resp.validJsonLd()); // true if response contains valid JSON-LD
console.log(resp.etag()); // ETag header
console.log(resp.hash()); // X-URL-HASH header
console.log(resp.error()); // error message (extracted from RFC 7807 on 4xx)
console.log(resp.rateLimit()); // rate limit max
console.log(resp.rateLimitRemaining()); // remaining requests[!TIP] We strongly recommend caching the response ETag and data to avoid unnecessary requests and hitting the rate limit.
Testing in the terminal
request jsonld generation
curl -X POST "https://enhancely.com/api/v1/jsonld" \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/blog/automatic-jsonld-with-enhancely"}'Common Questions
What about existing and/or duplicate JSON-LDs?
They can co-exist and will be evaluated and merged by the processing crawlers, like Google.
Disclaimer
This software is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
