@contentful/optimization-node 0.1.0-alpha16 → 0.1.0-alpha18
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/README.md +43 -19
- package/dist/260.mjs +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/core-sdk.cjs +15 -2
- package/dist/core-sdk.cjs.map +1 -1
- package/dist/core-sdk.d.cts +13 -0
- package/dist/core-sdk.d.mts +13 -0
- package/dist/core-sdk.d.ts +13 -0
- package/dist/core-sdk.mjs +1 -0
- package/dist/index.cjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://www.contentful.com/developers/docs/personalization/">
|
|
3
|
-
<img alt="Contentful Logo" title="Contentful" src="https://raw.githubusercontent.com/contentful/optimization/v0.1.0-
|
|
3
|
+
<img alt="Contentful Logo" title="Contentful" src="https://raw.githubusercontent.com/contentful/optimization/v0.1.0-alpha18/contentful-icon.png" width="150">
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<div align="center">
|
|
12
12
|
|
|
13
13
|
[Guides](https://contentful.github.io/optimization/documents/Documentation.Guides.html) ·
|
|
14
|
-
[Reference](https://contentful.github.io/optimization) · [Contributing](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
14
|
+
[Reference](https://contentful.github.io/optimization) · [Contributing](https://github.com/contentful/optimization/blob/v0.1.0-alpha18/CONTRIBUTING.md)
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
> The Optimization SDK Suite is pre-release (alpha). Breaking changes can be published at any time.
|
|
21
21
|
|
|
22
22
|
The Optimization Node SDK implements stateless server-side optimization behavior on top of the
|
|
23
|
-
[Optimization Core SDK](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
23
|
+
[Optimization Core SDK](https://github.com/contentful/optimization/blob/v0.1.0-alpha18/packages/universal/core-sdk/README.md). Use it for server rendering, server
|
|
24
24
|
functions, and Node services that need request-scoped profile evaluation or event emission.
|
|
25
25
|
|
|
26
26
|
If you are integrating a Node application, start with [Getting Started](#getting-started), then use
|
|
@@ -54,6 +54,9 @@ Install using an NPM-compatible package manager, pnpm for example:
|
|
|
54
54
|
pnpm add @contentful/optimization-node
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
Add `contentful` too when the SDK will use your app-owned `contentful.js` client for managed entry
|
|
58
|
+
fetching.
|
|
59
|
+
|
|
57
60
|
Import the Optimization class; both CJS and ESM module systems are supported, ESM preferred:
|
|
58
61
|
|
|
59
62
|
```ts
|
|
@@ -105,7 +108,7 @@ are part of the same application.
|
|
|
105
108
|
|
|
106
109
|
The Node SDK is stateless. It does not maintain consent, profile, or browser persistence state
|
|
107
110
|
between requests. For cross-SDK consent guidance, see
|
|
108
|
-
[Consent management in the Optimization SDK Suite](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
111
|
+
[Consent management in the Optimization SDK Suite](https://github.com/contentful/optimization/blob/v0.1.0-alpha18/documentation/concepts/consent-management-in-the-optimization-sdk-suite.md).
|
|
109
112
|
|
|
110
113
|
| Option | Required? | Default | Description |
|
|
111
114
|
| ------------------- | --------- | ---------------------- | ----------------------------------------------------------- |
|
|
@@ -113,6 +116,7 @@ between requests. For cross-SDK consent guidance, see
|
|
|
113
116
|
| `environment` | No | `'main'` | Contentful environment identifier |
|
|
114
117
|
| `api` | No | See API options below | Experience API and Insights API endpoint options |
|
|
115
118
|
| `app` | No | `undefined` | Application metadata attached to outgoing event context |
|
|
119
|
+
| `contentful` | No | `undefined` | App-owned `contentful.js` client, default query, and cache |
|
|
116
120
|
| `locale` | No | `undefined` | Default SDK Experience API and event locale |
|
|
117
121
|
| `fetchOptions` | No | SDK defaults | Fetch timeout and retry behavior |
|
|
118
122
|
| `allowedEventTypes` | No | `['identify', 'page']` | Event types allowed before request event consent is granted |
|
|
@@ -222,22 +226,41 @@ to `forRequest()`.
|
|
|
222
226
|
|
|
223
227
|
### Content resolution
|
|
224
228
|
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
When a `contentful.js` client is available, prefer SDK-managed fetching by entry ID. Configure the
|
|
230
|
+
client once, then call `fetchOptimizedEntry()` on a request-bound client after an accepted
|
|
231
|
+
Experience API call. `forRequest()` clients use the latest selected optimizations when omitted;
|
|
232
|
+
singleton calls require explicit `selectedOptimizations`.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
const optimization = new ContentfulOptimization({
|
|
236
|
+
clientId: 'client-id',
|
|
237
|
+
contentful: { client: contentfulClient },
|
|
238
|
+
environment: 'main',
|
|
239
|
+
locale: appLocale,
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const requestOptimization = optimization.forRequest({ consent: true, profile })
|
|
243
|
+
await requestOptimization.page()
|
|
244
|
+
const { baselineEntry, entry } = await requestOptimization.fetchOptimizedEntry('hero-entry')
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
If your application already fetched the baseline entry, keep using the manual resolver:
|
|
227
248
|
|
|
228
249
|
```ts
|
|
250
|
+
const pageResult = await requestOptimization.page()
|
|
229
251
|
const resolvedEntry = optimization.resolveOptimizedEntry(
|
|
230
252
|
baselineEntry,
|
|
231
|
-
|
|
253
|
+
pageResult.accepted ? pageResult.data.selectedOptimizations : undefined,
|
|
232
254
|
)
|
|
233
255
|
```
|
|
234
256
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
`
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
257
|
+
Use one CDA locale in either path. For localized apps, configure your application locale. A
|
|
258
|
+
request-bound client uses `forRequest({ locale: appLocale })` as the managed Contentful query locale
|
|
259
|
+
when neither `contentful.defaultQuery` nor the per-call query sets `locale`. Pass the same value to
|
|
260
|
+
app-owned Contentful CDA requests and to `forRequest({ locale: appLocale })` when MergeTags that
|
|
261
|
+
read localized profile fields match the rendered entry language. Do not pass all-locale CDA
|
|
262
|
+
responses from `withAllLocales` or `locale=*`; the resolver expects direct single-locale field
|
|
263
|
+
values. See
|
|
241
264
|
[Entry personalization and variant resolution](https://contentful.github.io/optimization/documents/Documentation.Concepts.Entry_personalization_and_variant_resolution.html#single-locale-cda-entry-contract)
|
|
242
265
|
for the entry contract and
|
|
243
266
|
[Locale handling in the Optimization SDK Suite](https://contentful.github.io/optimization/documents/Documentation.Concepts.Locale_handling_in_the_Optimization_SDK_Suite.html)
|
|
@@ -250,12 +273,13 @@ stateless, so `getFlag()` does not automatically emit flag-view tracking.
|
|
|
250
273
|
|
|
251
274
|
### Caching guidance
|
|
252
275
|
|
|
253
|
-
Cache raw Contentful delivery payloads in your application layer
|
|
254
|
-
results.
|
|
276
|
+
Cache raw Contentful delivery payloads in your application layer or with the SDK-managed entry
|
|
277
|
+
cache, not profile-evaluated SDK event results. Use `clearContentfulEntryCache()` when an SDK
|
|
278
|
+
instance must drop cached CDA entries.
|
|
255
279
|
|
|
256
280
|
| Data or call | Cache across requests? | Reason |
|
|
257
281
|
| --------------------------------------------------------------------------- | ---------------------- | -------------------------------------------------------------------- |
|
|
258
|
-
| Raw Contentful entries fetched from CDA
|
|
282
|
+
| Raw Contentful entries fetched from CDA or the SDK-managed entry cache | Yes | They are content snapshots and can be resolved per request |
|
|
259
283
|
| `resolveOptimizedEntry()` and `getMergeTagValue()` results | Request-local only | Results depend on the current profile and optimization data |
|
|
260
284
|
| `page()`, `identify()`, `screen()`, `track()`, and sticky `trackView()` | No | These calls perform side effects and return request-specific profile |
|
|
261
285
|
| Non-sticky `trackView()`, `trackClick()`, `trackHover()`, `trackFlagView()` | No | These calls emit Insights API events |
|
|
@@ -284,9 +308,9 @@ package directory.
|
|
|
284
308
|
step-by-step server-side integration guide
|
|
285
309
|
- [Node SDK generated reference](https://contentful.github.io/optimization/modules/_contentful_optimization-node.html) -
|
|
286
310
|
exported API reference
|
|
287
|
-
- [Node reference implementation](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
311
|
+
- [Node reference implementation](https://github.com/contentful/optimization/blob/v0.1.0-alpha18/implementations/node-sdk/README.md) - server-rendered
|
|
288
312
|
implementation using request-scoped SDK calls
|
|
289
|
-
- [Node + Web reference implementation](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
313
|
+
- [Node + Web reference implementation](https://github.com/contentful/optimization/blob/v0.1.0-alpha18/implementations/node-sdk+web-sdk/README.md) -
|
|
290
314
|
hybrid SSR and browser implementation
|
|
291
|
-
- [Optimization Web SDK](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
315
|
+
- [Optimization Web SDK](https://github.com/contentful/optimization/blob/v0.1.0-alpha18/packages/web/web-sdk/README.md) - browser SDK used when the same application
|
|
292
316
|
also needs client-side consent, persistence, tracking, or live updates
|
package/dist/260.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-
|
|
1
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha18";
|
|
2
2
|
const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
|
|
3
3
|
export { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from "@contentful/optimization-core/constants";
|
|
4
4
|
export { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION };
|
package/dist/constants.cjs
CHANGED
|
@@ -30,7 +30,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
30
30
|
OPTIMIZATION_NODE_SDK_VERSION: ()=>OPTIMIZATION_NODE_SDK_VERSION
|
|
31
31
|
});
|
|
32
32
|
const constants_namespaceObject = require("@contentful/optimization-core/constants");
|
|
33
|
-
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-
|
|
33
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha18";
|
|
34
34
|
const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
|
|
35
35
|
exports.ANONYMOUS_ID_COOKIE = __webpack_exports__.ANONYMOUS_ID_COOKIE;
|
|
36
36
|
exports.ANONYMOUS_ID_KEY = __webpack_exports__.ANONYMOUS_ID_KEY;
|
package/dist/core-sdk.cjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
3
|
"@contentful/optimization-core" (module) {
|
|
4
4
|
module.exports = require("@contentful/optimization-core");
|
|
5
|
+
},
|
|
6
|
+
"@contentful/optimization-core/entry-source" (module) {
|
|
7
|
+
module.exports = require("@contentful/optimization-core/entry-source");
|
|
5
8
|
}
|
|
6
9
|
};
|
|
7
10
|
var __webpack_module_cache__ = {};
|
|
@@ -47,12 +50,22 @@ function __webpack_require__(moduleId) {
|
|
|
47
50
|
var __webpack_exports__ = {};
|
|
48
51
|
(()=>{
|
|
49
52
|
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
prefetchOptimizedEntries: ()=>_contentful_optimization_core_entry_source__rspack_import_1.prefetchOptimizedEntries
|
|
55
|
+
});
|
|
50
56
|
var _contentful_optimization_core__rspack_import_0 = __webpack_require__("@contentful/optimization-core");
|
|
51
57
|
var __rspack_reexport = {};
|
|
52
|
-
for(const __rspack_import_key in _contentful_optimization_core__rspack_import_0)if (
|
|
58
|
+
for(const __rspack_import_key in _contentful_optimization_core__rspack_import_0)if ([
|
|
59
|
+
"prefetchOptimizedEntries",
|
|
60
|
+
"default"
|
|
61
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_contentful_optimization_core__rspack_import_0[__rspack_import_key];
|
|
53
62
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
63
|
+
var _contentful_optimization_core_entry_source__rspack_import_1 = __webpack_require__("@contentful/optimization-core/entry-source");
|
|
54
64
|
})();
|
|
55
|
-
|
|
65
|
+
exports.prefetchOptimizedEntries = __webpack_exports__.prefetchOptimizedEntries;
|
|
66
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
67
|
+
"prefetchOptimizedEntries"
|
|
68
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
69
|
Object.defineProperty(exports, '__esModule', {
|
|
57
70
|
value: true
|
|
58
71
|
});
|
package/dist/core-sdk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-sdk.cjs","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol"],"mappings":"
|
|
1
|
+
{"version":3,"file":"core-sdk.cjs","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol"],"mappings":";;;;;;;;;;;;;;;;;;;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ,CAACJ,oBAAoB,CAAC,CAAC,UAASI,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAJ,oBAAoB,CAAC,GAAG,CAACM,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFP,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOQ,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D"}
|
package/dist/core-sdk.d.cts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { OptimizedEntryPrefetchDescriptor } from '@contentful/optimization-core/entry-source';
|
|
2
|
+
import { OptimizedEntryPrefetchRuntime } from '@contentful/optimization-core/entry-source';
|
|
3
|
+
import { prefetchOptimizedEntries } from '@contentful/optimization-core/entry-source';
|
|
4
|
+
import { ServerOptimizedEntryHandoff } from '@contentful/optimization-core/entry-source';
|
|
5
|
+
|
|
6
|
+
export { OptimizedEntryPrefetchDescriptor }
|
|
7
|
+
|
|
8
|
+
export { OptimizedEntryPrefetchRuntime }
|
|
9
|
+
|
|
10
|
+
export { prefetchOptimizedEntries }
|
|
11
|
+
|
|
12
|
+
export { ServerOptimizedEntryHandoff }
|
|
13
|
+
|
|
1
14
|
|
|
2
15
|
export * from "@contentful/optimization-core";
|
|
3
16
|
|
package/dist/core-sdk.d.mts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { OptimizedEntryPrefetchDescriptor } from '@contentful/optimization-core/entry-source';
|
|
2
|
+
import { OptimizedEntryPrefetchRuntime } from '@contentful/optimization-core/entry-source';
|
|
3
|
+
import { prefetchOptimizedEntries } from '@contentful/optimization-core/entry-source';
|
|
4
|
+
import { ServerOptimizedEntryHandoff } from '@contentful/optimization-core/entry-source';
|
|
5
|
+
|
|
6
|
+
export { OptimizedEntryPrefetchDescriptor }
|
|
7
|
+
|
|
8
|
+
export { OptimizedEntryPrefetchRuntime }
|
|
9
|
+
|
|
10
|
+
export { prefetchOptimizedEntries }
|
|
11
|
+
|
|
12
|
+
export { ServerOptimizedEntryHandoff }
|
|
13
|
+
|
|
1
14
|
|
|
2
15
|
export * from "@contentful/optimization-core";
|
|
3
16
|
|
package/dist/core-sdk.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { OptimizedEntryPrefetchDescriptor } from '@contentful/optimization-core/entry-source';
|
|
2
|
+
import { OptimizedEntryPrefetchRuntime } from '@contentful/optimization-core/entry-source';
|
|
3
|
+
import { prefetchOptimizedEntries } from '@contentful/optimization-core/entry-source';
|
|
4
|
+
import { ServerOptimizedEntryHandoff } from '@contentful/optimization-core/entry-source';
|
|
5
|
+
|
|
6
|
+
export { OptimizedEntryPrefetchDescriptor }
|
|
7
|
+
|
|
8
|
+
export { OptimizedEntryPrefetchRuntime }
|
|
9
|
+
|
|
10
|
+
export { prefetchOptimizedEntries }
|
|
11
|
+
|
|
12
|
+
export { ServerOptimizedEntryHandoff }
|
|
13
|
+
|
|
1
14
|
|
|
2
15
|
export * from "@contentful/optimization-core";
|
|
3
16
|
|
package/dist/core-sdk.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __webpack_modules__ = {
|
|
|
6
6
|
OPTIMIZATION_NODE_SDK_VERSION: ()=>OPTIMIZATION_NODE_SDK_VERSION
|
|
7
7
|
});
|
|
8
8
|
require("@contentful/optimization-core/constants");
|
|
9
|
-
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-
|
|
9
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha18";
|
|
10
10
|
const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
|
|
11
11
|
}
|
|
12
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/optimization-node",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -87,6 +87,6 @@
|
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@contentful/optimization-core": "0.1.0-
|
|
90
|
+
"@contentful/optimization-core": "0.1.0-alpha18"
|
|
91
91
|
}
|
|
92
92
|
}
|