@se-studio/contentful-rest-api 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +17 -0
- package/dist/api/article-type.d.ts.map +1 -1
- package/dist/api/article-type.js +6 -5
- package/dist/api/article-type.js.map +1 -1
- package/dist/api/banner.d.ts.map +1 -1
- package/dist/api/banner.js +5 -2
- package/dist/api/banner.js.map +1 -1
- package/dist/api/breadcrumb.d.ts.map +1 -1
- package/dist/api/breadcrumb.js +7 -21
- package/dist/api/breadcrumb.js.map +1 -1
- package/dist/api/helpers.d.ts +2 -0
- package/dist/api/helpers.d.ts.map +1 -1
- package/dist/api/helpers.js +13 -4
- package/dist/api/helpers.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/links.d.ts.map +1 -1
- package/dist/api/links.js +87 -66
- package/dist/api/links.js.map +1 -1
- package/dist/api/navigation.d.ts +1 -0
- package/dist/api/navigation.d.ts.map +1 -1
- package/dist/api/navigation.js +1 -0
- package/dist/api/navigation.js.map +1 -1
- package/dist/api/page.d.ts.map +1 -1
- package/dist/api/page.js +1 -0
- package/dist/api/page.js.map +1 -1
- package/dist/api/person.d.ts.map +1 -1
- package/dist/api/person.js +6 -5
- package/dist/api/person.js.map +1 -1
- package/dist/api/redirects.d.ts.map +1 -1
- package/dist/api/redirects.js +5 -2
- package/dist/api/redirects.js.map +1 -1
- package/dist/api/tag-type.d.ts.map +1 -1
- package/dist/api/tag-type.js +6 -5
- package/dist/api/tag-type.js.map +1 -1
- package/dist/api/tag.d.ts.map +1 -1
- package/dist/api/tag.js +6 -5
- package/dist/api/tag.js.map +1 -1
- package/dist/api/types.d.ts +2 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +12 -2
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/navigation/cacheOptions.d.ts +2 -0
- package/dist/navigation/cacheOptions.d.ts.map +1 -1
- package/dist/navigation/cacheOptions.js +7 -0
- package/dist/navigation/cacheOptions.js.map +1 -1
- package/dist/navigation/enrichModelNavigation.d.ts.map +1 -1
- package/dist/navigation/enrichModelNavigation.js +10 -4
- package/dist/navigation/enrichModelNavigation.js.map +1 -1
- package/dist/navigation/linkIndex.d.ts +1 -0
- package/dist/navigation/linkIndex.d.ts.map +1 -1
- package/dist/navigation/linkIndex.js +22 -78
- package/dist/navigation/linkIndex.js.map +1 -1
- package/dist/navigation/listingLinkBundle.d.ts +22 -0
- package/dist/navigation/listingLinkBundle.d.ts.map +1 -0
- package/dist/navigation/listingLinkBundle.js +88 -0
- package/dist/navigation/listingLinkBundle.js.map +1 -0
- package/dist/navigation/registry.d.ts +1 -0
- package/dist/navigation/registry.d.ts.map +1 -1
- package/dist/navigation/registry.js +23 -6
- package/dist/navigation/registry.js.map +1 -1
- package/dist/navigation/requestCache.d.ts +18 -0
- package/dist/navigation/requestCache.d.ts.map +1 -0
- package/dist/navigation/requestCache.js +66 -0
- package/dist/navigation/requestCache.js.map +1 -0
- package/dist/revalidation/entry-handlers.d.ts +39 -0
- package/dist/revalidation/entry-handlers.d.ts.map +1 -0
- package/dist/revalidation/entry-handlers.js +103 -0
- package/dist/revalidation/entry-handlers.js.map +1 -0
- package/dist/revalidation/handlers.d.ts +4 -37
- package/dist/revalidation/handlers.d.ts.map +1 -1
- package/dist/revalidation/handlers.js +2 -100
- package/dist/revalidation/handlers.js.map +1 -1
- package/dist/telemetry/deriveOperation.d.ts +8 -0
- package/dist/telemetry/deriveOperation.d.ts.map +1 -0
- package/dist/telemetry/deriveOperation.js +59 -0
- package/dist/telemetry/deriveOperation.js.map +1 -0
- package/dist/telemetry/queryContext.d.ts +7 -0
- package/dist/telemetry/queryContext.d.ts.map +1 -0
- package/dist/telemetry/queryContext.js +9 -0
- package/dist/telemetry/queryContext.js.map +1 -0
- package/dist/telemetry/queryLog.d.ts +17 -0
- package/dist/telemetry/queryLog.d.ts.map +1 -0
- package/dist/telemetry/queryLog.js +54 -0
- package/dist/telemetry/queryLog.js.map +1 -0
- package/docs/llms.md +24 -0
- package/package.json +3 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface CmsQueryContext {
|
|
2
|
+
operation: string;
|
|
3
|
+
identifier?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function withCmsQueryContext<T>(context: CmsQueryContext, fn: () => T): T;
|
|
6
|
+
export declare function getCmsQueryContext(): CmsQueryContext | undefined;
|
|
7
|
+
//# sourceMappingURL=queryContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryContext.d.ts","sourceRoot":"","sources":["../../src/telemetry/queryContext.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE/E;AAED,wBAAgB,kBAAkB,IAAI,eAAe,GAAG,SAAS,CAEhE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const storage = new AsyncLocalStorage();
|
|
3
|
+
export function withCmsQueryContext(context, fn) {
|
|
4
|
+
return storage.run(context, fn);
|
|
5
|
+
}
|
|
6
|
+
export function getCmsQueryContext() {
|
|
7
|
+
return storage.getStore();
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=queryContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryContext.js","sourceRoot":"","sources":["../../src/telemetry/queryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAmB,CAAC;AAEzD,MAAM,UAAU,mBAAmB,CAAI,OAAwB,EAAE,EAAW;IAC1E,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface CmsQueryLogEntry {
|
|
2
|
+
url: string;
|
|
3
|
+
operation: string;
|
|
4
|
+
identifier?: string;
|
|
5
|
+
bytes: number;
|
|
6
|
+
ms: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function isCmsQueryLoggingEnabled(): boolean;
|
|
9
|
+
/** Format byte count as a compact human-readable size (e.g. 23.5k, 1.2M). */
|
|
10
|
+
export declare function formatPayloadSize(bytes: number): string;
|
|
11
|
+
export declare function logCmsQuery(entry: Omit<CmsQueryLogEntry, 'operation' | 'identifier'> & Partial<Pick<CmsQueryLogEntry, 'operation' | 'identifier'>>): void;
|
|
12
|
+
/** Read response body bytes and return text for JSON parsing. */
|
|
13
|
+
export declare function readResponseBodyWithSize(response: Response): Promise<{
|
|
14
|
+
bytes: number;
|
|
15
|
+
text: string;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=queryLog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryLog.d.ts","sourceRoot":"","sources":["../../src/telemetry/queryLog.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,wBAAwB,IAAI,OAAO,CAElD;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,YAAY,CAAC,GACvD,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC,GAC5D,IAAI,CAuBN;AAED,iEAAiE;AACjE,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAc1C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { deriveOperationFromUrl } from './deriveOperation.js';
|
|
2
|
+
import { getCmsQueryContext } from './queryContext.js';
|
|
3
|
+
export function isCmsQueryLoggingEnabled() {
|
|
4
|
+
return process.env.LOG_CMS_QUERIES === '1';
|
|
5
|
+
}
|
|
6
|
+
/** Format byte count as a compact human-readable size (e.g. 23.5k, 1.2M). */
|
|
7
|
+
export function formatPayloadSize(bytes) {
|
|
8
|
+
if (bytes < 1024)
|
|
9
|
+
return `${bytes}`;
|
|
10
|
+
if (bytes < 1024 * 1024) {
|
|
11
|
+
const kb = bytes / 1024;
|
|
12
|
+
return kb >= 100 ? `${Math.round(kb)}k` : `${kb.toFixed(1)}k`;
|
|
13
|
+
}
|
|
14
|
+
const mb = bytes / (1024 * 1024);
|
|
15
|
+
return mb >= 100 ? `${Math.round(mb)}M` : `${mb.toFixed(1)}M`;
|
|
16
|
+
}
|
|
17
|
+
export function logCmsQuery(entry) {
|
|
18
|
+
if (!isCmsQueryLoggingEnabled())
|
|
19
|
+
return;
|
|
20
|
+
const context = getCmsQueryContext();
|
|
21
|
+
const derived = deriveOperationFromUrl(entry.url);
|
|
22
|
+
const payload = {
|
|
23
|
+
url: entry.url,
|
|
24
|
+
operation: entry.operation ?? context?.operation ?? derived.operation,
|
|
25
|
+
...(entry.identifier !== undefined
|
|
26
|
+
? entry.identifier
|
|
27
|
+
? { identifier: entry.identifier }
|
|
28
|
+
: {}
|
|
29
|
+
: context?.identifier
|
|
30
|
+
? { identifier: context.identifier }
|
|
31
|
+
: derived.identifier
|
|
32
|
+
? { identifier: derived.identifier }
|
|
33
|
+
: {}),
|
|
34
|
+
bytes: entry.bytes,
|
|
35
|
+
ms: entry.ms,
|
|
36
|
+
};
|
|
37
|
+
console.log(`[CMS query] ${JSON.stringify(payload)}`);
|
|
38
|
+
}
|
|
39
|
+
/** Read response body bytes and return text for JSON parsing. */
|
|
40
|
+
export async function readResponseBodyWithSize(response) {
|
|
41
|
+
const contentLength = response.headers.get('content-length');
|
|
42
|
+
if (contentLength) {
|
|
43
|
+
const parsed = Number.parseInt(contentLength, 10);
|
|
44
|
+
const text = await response.text();
|
|
45
|
+
return {
|
|
46
|
+
bytes: Number.isNaN(parsed) ? Buffer.byteLength(text, 'utf8') : parsed,
|
|
47
|
+
text,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const buffer = await response.arrayBuffer();
|
|
51
|
+
const text = new TextDecoder().decode(buffer);
|
|
52
|
+
return { bytes: buffer.byteLength, text };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=queryLog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryLog.js","sourceRoot":"","sources":["../../src/telemetry/queryLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAUpD,MAAM,UAAU,wBAAwB;IACtC,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,GAAG,CAAC;AAC7C,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,iBAAiB,CAAC,KAAa;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,CAAC,UAAU;oBAClB,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE;oBACpC,CAAC,CAAC,EAAE,CAAC;QACX,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,EAAE,EAAE,KAAK,CAAC,EAAE;KACb,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,QAAkB;IAElB,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC7D,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;YACtE,IAAI;SACL,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;AAC5C,CAAC"}
|
package/docs/llms.md
CHANGED
|
@@ -304,6 +304,30 @@ import {
|
|
|
304
304
|
} from '@se-studio/contentful-rest-api';
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
+
## Query logging (dev)
|
|
308
|
+
|
|
309
|
+
Set `LOG_CMS_QUERIES=1` to emit structured per-fetch lines:
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
[CMS query] {"url":"...","operation":"Reading article","identifier":"my-slug","bytes":24064,"ms":45}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Merge with Next.js dev fetch cache lines (`(cache hit|miss)`) after the fact:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
pnpm dev 2>&1 | tee dev.log
|
|
319
|
+
pnpm --filter @se-studio/contentful-rest-api consolidate-cms-logs -- dev.log
|
|
320
|
+
# => Reading article my-slug - 23.5k (cached) in 12ms
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
For reliable URL matching, enable full fetch URLs in the app's `next.config.js`:
|
|
324
|
+
|
|
325
|
+
```js
|
|
326
|
+
logging: { fetches: { fullUrl: true } }
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Related: `LOG_CMS=1` (conversion warnings), `LOG_CMS_FETCH=1` (raw URLs only).
|
|
330
|
+
|
|
307
331
|
## Important Constraints
|
|
308
332
|
|
|
309
333
|
- Always supply `spaceId`, `accessToken`, and `environment`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@se-studio/contentful-rest-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Type-safe Contentful REST API client with caching and rate limiting for Next.js applications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -78,7 +78,8 @@
|
|
|
78
78
|
"dev": "tsc --project tsconfig.build.json --watch",
|
|
79
79
|
"type-check": "tsc --noEmit",
|
|
80
80
|
"lint": "biome lint .",
|
|
81
|
-
"test": "vitest run",
|
|
81
|
+
"test": "vitest run && node --test scripts/cms-query-log-consolidate.test.mjs",
|
|
82
|
+
"consolidate-cms-logs": "node scripts/consolidate-cms-query-logs.mjs",
|
|
82
83
|
"clean": "rm -rf dist .turbo *.tsbuildinfo",
|
|
83
84
|
"extract-single-page": "bash -c 'set -a && source ../../.env.local && set +a && tsx scripts/extract-page.ts \"$@\"' --",
|
|
84
85
|
"extract-single-article": "bash -c 'set -a && source ../../.env.local && set +a && tsx scripts/extract-article.ts \"$@\"' --"
|