@contentful/optimization-node 1.0.0 → 1.1.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/README.md +7 -11
- package/THIRD_PARTY_NOTICES.txt +30 -25
- package/dist/260.mjs +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/index.cjs +30 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
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/optimization-node-v1.
|
|
3
|
+
<img alt="Contentful Logo" title="Contentful" src="https://raw.githubusercontent.com/contentful/optimization/optimization-node-v1.1.0/contentful-icon.png" width="150">
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -11,16 +11,12 @@
|
|
|
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/optimization-node-v1.
|
|
14
|
+
[Reference](https://contentful.github.io/optimization) · [Contributing](https://github.com/contentful/optimization/blob/optimization-node-v1.1.0/CONTRIBUTING.md)
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
-
> [!WARNING]
|
|
19
|
-
>
|
|
20
|
-
> The Optimization SDK Suite is pre-release (alpha). Breaking changes can be published at any time.
|
|
21
|
-
|
|
22
18
|
The Optimization Node SDK implements stateless server-side optimization behavior on top of the
|
|
23
|
-
[Optimization Core SDK](https://github.com/contentful/optimization/blob/optimization-node-v1.
|
|
19
|
+
[Optimization Core SDK](https://github.com/contentful/optimization/blob/optimization-node-v1.1.0/packages/universal/core-sdk/README.md). Use it for server rendering, server
|
|
24
20
|
functions, and Node services that need request-scoped profile evaluation or event emission.
|
|
25
21
|
|
|
26
22
|
If you are integrating a Node application, start with [Getting Started](#getting-started), then use
|
|
@@ -108,7 +104,7 @@ are part of the same application.
|
|
|
108
104
|
|
|
109
105
|
The Node SDK is stateless. It does not maintain consent, profile, or browser persistence state
|
|
110
106
|
between requests. For cross-SDK consent guidance, see
|
|
111
|
-
[Consent management in the Optimization SDK Suite](https://github.com/contentful/optimization/blob/optimization-node-v1.
|
|
107
|
+
[Consent management in the Optimization SDK Suite](https://github.com/contentful/optimization/blob/optimization-node-v1.1.0/documentation/concepts/consent-management-in-the-optimization-sdk-suite.md).
|
|
112
108
|
|
|
113
109
|
| Option | Required? | Default | Description |
|
|
114
110
|
| ------------------- | --------- | ---------------------- | ----------------------------------------------------------- |
|
|
@@ -312,9 +308,9 @@ package directory.
|
|
|
312
308
|
step-by-step server-side integration guide
|
|
313
309
|
- [Node SDK generated reference](https://contentful.github.io/optimization/modules/_contentful_optimization-node.html) -
|
|
314
310
|
exported API reference
|
|
315
|
-
- [Node reference implementation](https://github.com/contentful/optimization/blob/optimization-node-v1.
|
|
311
|
+
- [Node reference implementation](https://github.com/contentful/optimization/blob/optimization-node-v1.1.0/implementations/node-sdk/README.md) - server-rendered
|
|
316
312
|
implementation using request-scoped SDK calls
|
|
317
|
-
- [Node + Web reference implementation](https://github.com/contentful/optimization/blob/optimization-node-v1.
|
|
313
|
+
- [Node + Web reference implementation](https://github.com/contentful/optimization/blob/optimization-node-v1.1.0/implementations/node-sdk+web-sdk/README.md) -
|
|
318
314
|
hybrid SSR and browser implementation
|
|
319
|
-
- [Optimization Web SDK](https://github.com/contentful/optimization/blob/optimization-node-v1.
|
|
315
|
+
- [Optimization Web SDK](https://github.com/contentful/optimization/blob/optimization-node-v1.1.0/packages/web/web-sdk/README.md) - browser SDK used when the same application
|
|
320
316
|
also needs client-side consent, persistence, tracking, or live updates
|
package/THIRD_PARTY_NOTICES.txt
CHANGED
|
@@ -464,31 +464,6 @@ SOFTWARE.
|
|
|
464
464
|
|
|
465
465
|
---
|
|
466
466
|
|
|
467
|
-
The following software may be included in this product: debug (4.3.7)
|
|
468
|
-
This software contains the following license and notice below:
|
|
469
|
-
|
|
470
|
-
(The MIT License)
|
|
471
|
-
|
|
472
|
-
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
|
473
|
-
Copyright (c) 2018-2021 Josh Junon
|
|
474
|
-
|
|
475
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
476
|
-
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
|
477
|
-
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
478
|
-
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
479
|
-
subject to the following conditions:
|
|
480
|
-
|
|
481
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
482
|
-
portions of the Software.
|
|
483
|
-
|
|
484
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
485
|
-
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
486
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
487
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
488
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
489
|
-
|
|
490
|
-
---
|
|
491
|
-
|
|
492
467
|
The following software may be included in this product: debug (4.4.3)
|
|
493
468
|
This software contains the following license and notice below:
|
|
494
469
|
|
|
@@ -917,6 +892,21 @@ SOFTWARE.
|
|
|
917
892
|
|
|
918
893
|
---
|
|
919
894
|
|
|
895
|
+
The following software may be included in this product: has-flag (4.0.0)
|
|
896
|
+
This software contains the following license and notice below:
|
|
897
|
+
|
|
898
|
+
MIT License
|
|
899
|
+
|
|
900
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
901
|
+
|
|
902
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
903
|
+
|
|
904
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
905
|
+
|
|
906
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
907
|
+
|
|
908
|
+
---
|
|
909
|
+
|
|
920
910
|
The following software may be included in this product: has-symbols (1.1.0)
|
|
921
911
|
This software contains the following license and notice below:
|
|
922
912
|
|
|
@@ -1446,6 +1436,21 @@ SOFTWARE.
|
|
|
1446
1436
|
|
|
1447
1437
|
---
|
|
1448
1438
|
|
|
1439
|
+
The following software may be included in this product: supports-color (8.1.1)
|
|
1440
|
+
This software contains the following license and notice below:
|
|
1441
|
+
|
|
1442
|
+
MIT License
|
|
1443
|
+
|
|
1444
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
1445
|
+
|
|
1446
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
1447
|
+
|
|
1448
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
1449
|
+
|
|
1450
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1451
|
+
|
|
1452
|
+
---
|
|
1453
|
+
|
|
1449
1454
|
The following software may be included in this product: zod (4.3.6)
|
|
1450
1455
|
This software contains the following license and notice below:
|
|
1451
1456
|
|
package/dist/260.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const OPTIMIZATION_NODE_SDK_VERSION = "1.
|
|
1
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "1.1.0";
|
|
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 = "1.
|
|
33
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "1.1.0";
|
|
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/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 = "1.
|
|
9
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "1.1.0";
|
|
10
10
|
const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
|
|
11
11
|
}
|
|
12
12
|
};
|
|
@@ -46,8 +46,9 @@ var __webpack_exports__ = {};
|
|
|
46
46
|
__webpack_require__.r(__webpack_exports__);
|
|
47
47
|
__webpack_require__.d(__webpack_exports__, {
|
|
48
48
|
OPTIMIZATION_NODE_SDK_NAME: ()=>constants.OPTIMIZATION_NODE_SDK_NAME,
|
|
49
|
+
default: ()=>src,
|
|
49
50
|
OPTIMIZATION_NODE_SDK_VERSION: ()=>constants.OPTIMIZATION_NODE_SDK_VERSION,
|
|
50
|
-
|
|
51
|
+
createRequestHandoffFromData: ()=>createRequestHandoffFromData
|
|
51
52
|
});
|
|
52
53
|
const optimization_core_namespaceObject = require("@contentful/optimization-core");
|
|
53
54
|
var constants = __webpack_require__("./src/constants.ts");
|
|
@@ -76,14 +77,41 @@ var __webpack_exports__ = {};
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
const src_ContentfulOptimization = ContentfulOptimization;
|
|
80
|
+
function assertRequestHandoffCacheMetadata(cache) {
|
|
81
|
+
if ('private-request' === cache.scope) return;
|
|
82
|
+
throw new TypeError('Request handoffs must use private-request cache scope. Use public permutation handoffs for public cache scopes, or a non-request handoff for static output.');
|
|
83
|
+
}
|
|
84
|
+
function createRequestHandoffFromData(input) {
|
|
85
|
+
const cache = input.cache ?? {
|
|
86
|
+
scope: 'private-request'
|
|
87
|
+
};
|
|
88
|
+
assertRequestHandoffCacheMetadata(cache);
|
|
89
|
+
const handoff = {
|
|
90
|
+
cache,
|
|
91
|
+
...void 0 === input.entries ? {} : {
|
|
92
|
+
entries: input.entries
|
|
93
|
+
},
|
|
94
|
+
...void 0 === input.data ? {} : {
|
|
95
|
+
state: {
|
|
96
|
+
selectedOptimizations: input.data.selectedOptimizations,
|
|
97
|
+
changes: input.data.changes,
|
|
98
|
+
profile: input.data.profile
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
(0, optimization_core_namespaceObject.assertOptimizationCacheSafety)(handoff);
|
|
103
|
+
return handoff;
|
|
104
|
+
}
|
|
79
105
|
const src = src_ContentfulOptimization;
|
|
80
106
|
})();
|
|
81
107
|
exports.OPTIMIZATION_NODE_SDK_NAME = __webpack_exports__.OPTIMIZATION_NODE_SDK_NAME;
|
|
82
108
|
exports.OPTIMIZATION_NODE_SDK_VERSION = __webpack_exports__.OPTIMIZATION_NODE_SDK_VERSION;
|
|
109
|
+
exports.createRequestHandoffFromData = __webpack_exports__.createRequestHandoffFromData;
|
|
83
110
|
exports["default"] = __webpack_exports__["default"];
|
|
84
111
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
85
112
|
"OPTIMIZATION_NODE_SDK_NAME",
|
|
86
113
|
"OPTIMIZATION_NODE_SDK_VERSION",
|
|
114
|
+
"createRequestHandoffFromData",
|
|
87
115
|
"default"
|
|
88
116
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
89
117
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/constants.ts","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/naming-convention -- Replaced at build-time\ndeclare const __OPTIMIZATION_VERSION__: string | undefined\n// eslint-disable-next-line @typescript-eslint/naming-convention -- Replaced at build-time\ndeclare const __OPTIMIZATION_PACKAGE_NAME__: string | undefined\n\n/**\n * The current version of the Optimization Node SDK, injected at build-time.\n *\n * @defaultValue `'0.0.0'` when the build-time replacement is unavailable.\n *\n * @public\n */\nexport const OPTIMIZATION_NODE_SDK_VERSION =\n typeof __OPTIMIZATION_VERSION__ === 'string' ? __OPTIMIZATION_VERSION__ : '0.0.0'\n\n/**\n * The package name of the Optimization Node SDK, injected at build-time.\n *\n * @defaultValue `'@contentful/optimization-node'` when the build-time replacement is unavailable.\n *\n * @public\n */\nexport const OPTIMIZATION_NODE_SDK_NAME =\n typeof __OPTIMIZATION_PACKAGE_NAME__ === 'string'\n ? __OPTIMIZATION_PACKAGE_NAME__\n : '@contentful/optimization-node'\n\n/**\n * Re-exports of anonymous identifier constants used by the Optimization Core.\n *\n * @remarks\n * This constant is surfaced here to provide a stable import path for Node SDK\n * consumers. It represents the cookie key used by the Optimization Framework\n * to persist an anonymous identifier for tracking optimization and insights\n * events when no explicit profile is known.\n *\n * @example\n * ```ts\n * import { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from '@contentful/optimization-node/constants'\n * const cookieId = request.cookies[ANONYMOUS_ID_COOKIE]\n * const storageId = localStorage.getItem(ANONYMOUS_ID_KEY)\n * ```\n *\n * @see {@link ANONYMOUS_ID_COOKIE} and {@link ANONYMOUS_ID_KEY} in\n * `@contentful/optimization-core` for the\n * authoritative definition and documentation.\n *\n * @public\n */\nexport { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from '@contentful/optimization-core/constants'\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};","import {\n CoreStateless,\n type CoreStatelessConfig,\n type EventType,\n} from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\n\nconst DEFAULT_NODE_ALLOWED_EVENT_TYPES: EventType[] = ['identify', 'page']\n\n/**\n * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.\n *\n * @remarks\n * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`\n * is intentionally omitted from singleton SDK configuration.\n *\n * @public\n */\nexport type PublicNodeEventBuilderConfig = Partial<\n Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>\n>\n\n/**\n * Configuration for the Node-specific ContentfulOptimization SDK.\n *\n * @remarks\n * This configuration extends {@link CoreStatelessConfig} but allows partial\n * overrides of the event-builder configuration. SDKs commonly inject their own\n * library metadata or channel definitions.\n *\n * @see {@link CoreStatelessConfig}\n *\n * @public\n */\nexport interface OptimizationNodeConfig extends Omit<CoreStatelessConfig, 'eventBuilder'> {\n /**\n * The application definition used to attribute events to a specific consumer app.\n *\n * @remarks\n * When not provided, events will not contain app metadata in their context.\n */\n app?: App\n\n /**\n * Partial overrides for the event builder configuration.\n *\n * @remarks\n * Any provided fields are merged with the default Node SDK metadata.\n * Request-scoped consent should be bound with `forRequest()`, not configured\n * on the SDK singleton.\n *\n * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: PublicNodeEventBuilderConfig\n}\n\n/**\n * Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.\n *\n * @remarks\n * This class adapts the stateless ContentfulOptimization Core for Node runtimes by\n * applying environment-appropriate defaults (e.g., server channel, Node SDK\n * library metadata). No core runtime behavior is modified; only configuration\n * defaults differ.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const sdk = new ContentfulOptimization({\n * clientId: 'abc-123',\n * environment: 'main',\n * logLevel: 'info',\n * })\n *\n * const requestOptimization = sdk.forRequest({\n * consent: true,\n * locale: 'fr-CA',\n * profile: { id: 'profile-id' },\n * })\n *\n * const { accepted, data } = await requestOptimization.page()\n * ```\n *\n * @see {@link CoreStateless}\n *\n * @public\n */\nclass ContentfulOptimization extends CoreStateless {\n /**\n * Create an instance of the Node SDK with merged defaults.\n *\n * @param config - Partial Node-specific configuration. Any eventBuilder\n * fields provided are merged with Node's defaults.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })\n * ```\n */\n constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig) {\n const { library, ...eventBuilderConfig } = eventBuilder ?? {}\n\n super({\n ...config,\n allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,\n eventBuilder: {\n app,\n channel: 'server',\n ...eventBuilderConfig,\n library: {\n name: OPTIMIZATION_NODE_SDK_NAME,\n version: OPTIMIZATION_NODE_SDK_VERSION,\n ...library,\n },\n getConsent: () => false,\n },\n })\n }\n}\n\nexport default ContentfulOptimization\n","/**\n * Contentful ContentfulOptimization Node SDK.\n *\n * @remarks\n * Adds Node-specific defaults via the {@link ContentfulOptimization} class.\n * Core and transitive API exports are available from dedicated entrypoints:\n * `@contentful/optimization-node/core-sdk`,\n * `@contentful/optimization-node/api-client`,\n * and `@contentful/optimization-node/api-schemas`.\n *\n * @packageDocumentation\n */\n\nimport ContentfulOptimization from './ContentfulOptimization'\n\nexport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\nexport * from './ContentfulOptimization'\n\nexport default ContentfulOptimization\n"],"names":["OPTIMIZATION_NODE_SDK_VERSION","__OPTIMIZATION_VERSION__","OPTIMIZATION_NODE_SDK_NAME","__OPTIMIZATION_PACKAGE_NAME__","__webpack_require__","definition","key","Object","obj","prop","Symbol","DEFAULT_NODE_ALLOWED_EVENT_TYPES","ContentfulOptimization","CoreStateless","app","allowedEventTypes","eventBuilder","config","library","eventBuilderConfig"],"mappings":";;;;;;;;QAYO,MAAMA,gCACoCC;QAS1C,MAAMC,6BAEPC;;;;;;;;;;;;;;ICxBNC,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;ICEA,MAAMI,mCAAgD;QAAC;QAAY;KAAO;IAkF1E,MAAMC,+BAA+BC,kCAAAA,aAAaA;QAchD,YAAY,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGC,QAAgC,CAAE;YACvF,MAAM,EAAEC,OAAO,EAAE,GAAGC,oBAAoB,GAAGH,gBAAgB,CAAC;YAE5D,KAAK,CAAC;gBACJ,GAAGC,MAAM;gBACT,mBAAmBF,qBAAqBJ;gBACxC,cAAc;oBACZG;oBACA,SAAS;oBACT,GAAGK,kBAAkB;oBACrB,SAAS;wBACP,MAAMjB,UAAAA,0BAA0BA;wBAChC,SAASF,UAAAA,6BAA6BA;wBACtC,GAAGkB,OAAO;oBACZ;oBACA,YAAY,IAAM;gBACpB;YACF;QACF;IACF;IAEA,mCAAeN;IC3Gf,YAAeA"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/constants.ts","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/ContentfulOptimization.ts","../src/handoff.ts","../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/naming-convention -- Replaced at build-time\ndeclare const __OPTIMIZATION_VERSION__: string | undefined\n// eslint-disable-next-line @typescript-eslint/naming-convention -- Replaced at build-time\ndeclare const __OPTIMIZATION_PACKAGE_NAME__: string | undefined\n\n/**\n * The current version of the Optimization Node SDK, injected at build-time.\n *\n * @defaultValue `'0.0.0'` when the build-time replacement is unavailable.\n *\n * @public\n */\nexport const OPTIMIZATION_NODE_SDK_VERSION =\n typeof __OPTIMIZATION_VERSION__ === 'string' ? __OPTIMIZATION_VERSION__ : '0.0.0'\n\n/**\n * The package name of the Optimization Node SDK, injected at build-time.\n *\n * @defaultValue `'@contentful/optimization-node'` when the build-time replacement is unavailable.\n *\n * @public\n */\nexport const OPTIMIZATION_NODE_SDK_NAME =\n typeof __OPTIMIZATION_PACKAGE_NAME__ === 'string'\n ? __OPTIMIZATION_PACKAGE_NAME__\n : '@contentful/optimization-node'\n\n/**\n * Re-exports of anonymous identifier constants used by the Optimization Core.\n *\n * @remarks\n * This constant is surfaced here to provide a stable import path for Node SDK\n * consumers. It represents the cookie key used by the Optimization Framework\n * to persist an anonymous identifier for tracking optimization and insights\n * events when no explicit profile is known.\n *\n * @example\n * ```ts\n * import { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from '@contentful/optimization-node/constants'\n * const cookieId = request.cookies[ANONYMOUS_ID_COOKIE]\n * const storageId = localStorage.getItem(ANONYMOUS_ID_KEY)\n * ```\n *\n * @see {@link ANONYMOUS_ID_COOKIE} and {@link ANONYMOUS_ID_KEY} in\n * `@contentful/optimization-core` for the\n * authoritative definition and documentation.\n *\n * @public\n */\nexport { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from '@contentful/optimization-core/constants'\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};","import {\n CoreStateless,\n type CoreStatelessConfig,\n type EventType,\n} from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\n\nconst DEFAULT_NODE_ALLOWED_EVENT_TYPES: EventType[] = ['identify', 'page']\n\n/**\n * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.\n *\n * @remarks\n * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`\n * is intentionally omitted from singleton SDK configuration.\n *\n * @public\n */\nexport type PublicNodeEventBuilderConfig = Partial<\n Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>\n>\n\n/**\n * Configuration for the Node-specific ContentfulOptimization SDK.\n *\n * @remarks\n * This configuration extends {@link CoreStatelessConfig} but allows partial\n * overrides of the event-builder configuration. SDKs commonly inject their own\n * library metadata or channel definitions.\n *\n * @see {@link CoreStatelessConfig}\n *\n * @public\n */\nexport interface OptimizationNodeConfig extends Omit<CoreStatelessConfig, 'eventBuilder'> {\n /**\n * The application definition used to attribute events to a specific consumer app.\n *\n * @remarks\n * When not provided, events will not contain app metadata in their context.\n */\n app?: App\n\n /**\n * Partial overrides for the event builder configuration.\n *\n * @remarks\n * Any provided fields are merged with the default Node SDK metadata.\n * Request-scoped consent should be bound with `forRequest()`, not configured\n * on the SDK singleton.\n *\n * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: PublicNodeEventBuilderConfig\n}\n\n/**\n * Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.\n *\n * @remarks\n * This class adapts the stateless ContentfulOptimization Core for Node runtimes by\n * applying environment-appropriate defaults (e.g., server channel, Node SDK\n * library metadata). No core runtime behavior is modified; only configuration\n * defaults differ.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const sdk = new ContentfulOptimization({\n * clientId: 'abc-123',\n * environment: 'main',\n * logLevel: 'info',\n * })\n *\n * const requestOptimization = sdk.forRequest({\n * consent: true,\n * locale: 'fr-CA',\n * profile: { id: 'profile-id' },\n * })\n *\n * const { accepted, data } = await requestOptimization.page()\n * ```\n *\n * @see {@link CoreStateless}\n *\n * @public\n */\nclass ContentfulOptimization extends CoreStateless {\n /**\n * Create an instance of the Node SDK with merged defaults.\n *\n * @param config - Partial Node-specific configuration. Any eventBuilder\n * fields provided are merged with Node's defaults.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })\n * ```\n */\n constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig) {\n const { library, ...eventBuilderConfig } = eventBuilder ?? {}\n\n super({\n ...config,\n allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,\n eventBuilder: {\n app,\n channel: 'server',\n ...eventBuilderConfig,\n library: {\n name: OPTIMIZATION_NODE_SDK_NAME,\n version: OPTIMIZATION_NODE_SDK_VERSION,\n ...library,\n },\n getConsent: () => false,\n },\n })\n }\n}\n\nexport default ContentfulOptimization\n","import {\n assertOptimizationCacheSafety,\n type ManagedEntryHandoff,\n type OptimizationCacheMetadata,\n type OptimizationData,\n type OptimizationHandoff,\n type PrivateRequestOptimizationCacheMetadata,\n} from '@contentful/optimization-core'\n\nfunction assertRequestHandoffCacheMetadata(\n cache: OptimizationCacheMetadata,\n): asserts cache is PrivateRequestOptimizationCacheMetadata {\n if (cache.scope === 'private-request') return\n\n throw new TypeError(\n 'Request handoffs must use private-request cache scope. Use public permutation handoffs for public cache scopes, or a non-request handoff for static output.',\n )\n}\n\n/**\n * Create a framework-neutral handoff from completed Node request optimization data.\n *\n * @remarks\n * This helper serializes data that a caller already received from a request-bound Experience call.\n * It does not emit page or analytics events.\n *\n * @public\n */\nexport function createRequestHandoffFromData(input: {\n readonly data?: OptimizationData\n readonly entries?: readonly ManagedEntryHandoff[]\n readonly cache?: PrivateRequestOptimizationCacheMetadata\n}): OptimizationHandoff {\n const cache: PrivateRequestOptimizationCacheMetadata = input.cache ?? { scope: 'private-request' }\n assertRequestHandoffCacheMetadata(cache)\n\n const handoff: OptimizationHandoff = {\n cache,\n ...(input.entries === undefined ? {} : { entries: input.entries }),\n ...(input.data === undefined\n ? {}\n : {\n state: {\n selectedOptimizations: input.data.selectedOptimizations,\n changes: input.data.changes,\n profile: input.data.profile,\n },\n }),\n }\n\n assertOptimizationCacheSafety(handoff)\n\n return handoff\n}\n","/**\n * Contentful ContentfulOptimization Node SDK.\n *\n * @remarks\n * Adds Node-specific defaults via the {@link ContentfulOptimization} class.\n * Core and transitive API exports are available from dedicated entrypoints:\n * `@contentful/optimization-node/core-sdk`,\n * `@contentful/optimization-node/api-client`,\n * and `@contentful/optimization-node/api-schemas`.\n *\n * @packageDocumentation\n */\n\nimport ContentfulOptimization from './ContentfulOptimization'\n\nexport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\nexport * from './ContentfulOptimization'\nexport * from './handoff'\n\nexport default ContentfulOptimization\n"],"names":["OPTIMIZATION_NODE_SDK_VERSION","__OPTIMIZATION_VERSION__","OPTIMIZATION_NODE_SDK_NAME","__OPTIMIZATION_PACKAGE_NAME__","__webpack_require__","definition","key","Object","obj","prop","Symbol","DEFAULT_NODE_ALLOWED_EVENT_TYPES","ContentfulOptimization","CoreStateless","app","allowedEventTypes","eventBuilder","config","library","eventBuilderConfig","assertRequestHandoffCacheMetadata","cache","TypeError","createRequestHandoffFromData","input","handoff","undefined","assertOptimizationCacheSafety"],"mappings":";;;;;;;;QAYO,MAAMA,gCACoCC;QAS1C,MAAMC,6BAEPC;;;;;;;;;;;;;;ICxBNC,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;ICEA,MAAMI,mCAAgD;QAAC;QAAY;KAAO;IAkF1E,MAAMC,+BAA+BC,kCAAAA,aAAaA;QAchD,YAAY,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGC,QAAgC,CAAE;YACvF,MAAM,EAAEC,OAAO,EAAE,GAAGC,oBAAoB,GAAGH,gBAAgB,CAAC;YAE5D,KAAK,CAAC;gBACJ,GAAGC,MAAM;gBACT,mBAAmBF,qBAAqBJ;gBACxC,cAAc;oBACZG;oBACA,SAAS;oBACT,GAAGK,kBAAkB;oBACrB,SAAS;wBACP,MAAMjB,UAAAA,0BAA0BA;wBAChC,SAASF,UAAAA,6BAA6BA;wBACtC,GAAGkB,OAAO;oBACZ;oBACA,YAAY,IAAM;gBACpB;YACF;QACF;IACF;IAEA,mCAAeN;ICpHf,SAASQ,kCACPC,KAAgC;QAEhC,IAAIA,AAAgB,sBAAhBA,MAAM,KAAK,EAAwB;QAEvC,MAAM,IAAIC,UACR;IAEJ;IAWO,SAASC,6BAA6BC,KAI5C;QACC,MAAMH,QAAiDG,MAAM,KAAK,IAAI;YAAE,OAAO;QAAkB;QACjGJ,kCAAkCC;QAElC,MAAMI,UAA+B;YACnCJ;YACA,GAAIG,AAAkBE,WAAlBF,MAAM,OAAO,GAAiB,CAAC,IAAI;gBAAE,SAASA,MAAM,OAAO;YAAC,CAAC;YACjE,GAAIA,AAAeE,WAAfF,MAAM,IAAI,GACV,CAAC,IACD;gBACE,OAAO;oBACL,uBAAuBA,MAAM,IAAI,CAAC,qBAAqB;oBACvD,SAASA,MAAM,IAAI,CAAC,OAAO;oBAC3B,SAASA,MAAM,IAAI,CAAC,OAAO;gBAC7B;YACF,CAAC;QACP;QAEAG,IAAAA,kCAAAA,6BAAAA,AAAAA,EAA8BF;QAE9B,OAAOA;IACT;IClCA,YAAeb"}
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
import type { App } from '@contentful/optimization-core/api-schemas';
|
|
15
15
|
import { CoreStateless } from '@contentful/optimization-core';
|
|
16
16
|
import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
17
|
+
import { ManagedEntryHandoff } from '@contentful/optimization-core';
|
|
18
|
+
import { OptimizationData } from '@contentful/optimization-core';
|
|
19
|
+
import { OptimizationHandoff } from '@contentful/optimization-core';
|
|
20
|
+
import { PrivateRequestOptimizationCacheMetadata } from '@contentful/optimization-core';
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.
|
|
@@ -65,6 +69,21 @@ declare class ContentfulOptimization extends CoreStateless {
|
|
|
65
69
|
}
|
|
66
70
|
export default ContentfulOptimization;
|
|
67
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Create a framework-neutral handoff from completed Node request optimization data.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This helper serializes data that a caller already received from a request-bound Experience call.
|
|
77
|
+
* It does not emit page or analytics events.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare function createRequestHandoffFromData(input: {
|
|
82
|
+
readonly data?: OptimizationData;
|
|
83
|
+
readonly entries?: readonly ManagedEntryHandoff[];
|
|
84
|
+
readonly cache?: PrivateRequestOptimizationCacheMetadata;
|
|
85
|
+
}): OptimizationHandoff;
|
|
86
|
+
|
|
68
87
|
/**
|
|
69
88
|
* The package name of the Optimization Node SDK, injected at build-time.
|
|
70
89
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
import type { App } from '@contentful/optimization-core/api-schemas';
|
|
15
15
|
import { CoreStateless } from '@contentful/optimization-core';
|
|
16
16
|
import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
17
|
+
import { ManagedEntryHandoff } from '@contentful/optimization-core';
|
|
18
|
+
import { OptimizationData } from '@contentful/optimization-core';
|
|
19
|
+
import { OptimizationHandoff } from '@contentful/optimization-core';
|
|
20
|
+
import { PrivateRequestOptimizationCacheMetadata } from '@contentful/optimization-core';
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.
|
|
@@ -65,6 +69,21 @@ declare class ContentfulOptimization extends CoreStateless {
|
|
|
65
69
|
}
|
|
66
70
|
export default ContentfulOptimization;
|
|
67
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Create a framework-neutral handoff from completed Node request optimization data.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This helper serializes data that a caller already received from a request-bound Experience call.
|
|
77
|
+
* It does not emit page or analytics events.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare function createRequestHandoffFromData(input: {
|
|
82
|
+
readonly data?: OptimizationData;
|
|
83
|
+
readonly entries?: readonly ManagedEntryHandoff[];
|
|
84
|
+
readonly cache?: PrivateRequestOptimizationCacheMetadata;
|
|
85
|
+
}): OptimizationHandoff;
|
|
86
|
+
|
|
68
87
|
/**
|
|
69
88
|
* The package name of the Optimization Node SDK, injected at build-time.
|
|
70
89
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
import type { App } from '@contentful/optimization-core/api-schemas';
|
|
15
15
|
import { CoreStateless } from '@contentful/optimization-core';
|
|
16
16
|
import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
17
|
+
import { ManagedEntryHandoff } from '@contentful/optimization-core';
|
|
18
|
+
import { OptimizationData } from '@contentful/optimization-core';
|
|
19
|
+
import { OptimizationHandoff } from '@contentful/optimization-core';
|
|
20
|
+
import { PrivateRequestOptimizationCacheMetadata } from '@contentful/optimization-core';
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.
|
|
@@ -65,6 +69,21 @@ declare class ContentfulOptimization extends CoreStateless {
|
|
|
65
69
|
}
|
|
66
70
|
export default ContentfulOptimization;
|
|
67
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Create a framework-neutral handoff from completed Node request optimization data.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This helper serializes data that a caller already received from a request-bound Experience call.
|
|
77
|
+
* It does not emit page or analytics events.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare function createRequestHandoffFromData(input: {
|
|
82
|
+
readonly data?: OptimizationData;
|
|
83
|
+
readonly entries?: readonly ManagedEntryHandoff[];
|
|
84
|
+
readonly cache?: PrivateRequestOptimizationCacheMetadata;
|
|
85
|
+
}): OptimizationHandoff;
|
|
86
|
+
|
|
68
87
|
/**
|
|
69
88
|
* The package name of the Optimization Node SDK, injected at build-time.
|
|
70
89
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -25,8 +25,34 @@ class ContentfulOptimization extends __rspack_external__contentful_optimization_
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
const src_ContentfulOptimization = ContentfulOptimization;
|
|
28
|
+
function assertRequestHandoffCacheMetadata(cache) {
|
|
29
|
+
if ('private-request' === cache.scope) return;
|
|
30
|
+
throw new TypeError('Request handoffs must use private-request cache scope. Use public permutation handoffs for public cache scopes, or a non-request handoff for static output.');
|
|
31
|
+
}
|
|
32
|
+
function createRequestHandoffFromData(input) {
|
|
33
|
+
const cache = input.cache ?? {
|
|
34
|
+
scope: 'private-request'
|
|
35
|
+
};
|
|
36
|
+
assertRequestHandoffCacheMetadata(cache);
|
|
37
|
+
const handoff = {
|
|
38
|
+
cache,
|
|
39
|
+
...void 0 === input.entries ? {} : {
|
|
40
|
+
entries: input.entries
|
|
41
|
+
},
|
|
42
|
+
...void 0 === input.data ? {} : {
|
|
43
|
+
state: {
|
|
44
|
+
selectedOptimizations: input.data.selectedOptimizations,
|
|
45
|
+
changes: input.data.changes,
|
|
46
|
+
profile: input.data.profile
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
(0, __rspack_external__contentful_optimization_core_7d4758c6.assertOptimizationCacheSafety)(handoff);
|
|
51
|
+
return handoff;
|
|
52
|
+
}
|
|
28
53
|
const src = src_ContentfulOptimization;
|
|
29
54
|
export { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from "./260.mjs";
|
|
30
55
|
export default src;
|
|
56
|
+
export { createRequestHandoffFromData };
|
|
31
57
|
|
|
32
58
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["import {\n CoreStateless,\n type CoreStatelessConfig,\n type EventType,\n} from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\n\nconst DEFAULT_NODE_ALLOWED_EVENT_TYPES: EventType[] = ['identify', 'page']\n\n/**\n * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.\n *\n * @remarks\n * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`\n * is intentionally omitted from singleton SDK configuration.\n *\n * @public\n */\nexport type PublicNodeEventBuilderConfig = Partial<\n Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>\n>\n\n/**\n * Configuration for the Node-specific ContentfulOptimization SDK.\n *\n * @remarks\n * This configuration extends {@link CoreStatelessConfig} but allows partial\n * overrides of the event-builder configuration. SDKs commonly inject their own\n * library metadata or channel definitions.\n *\n * @see {@link CoreStatelessConfig}\n *\n * @public\n */\nexport interface OptimizationNodeConfig extends Omit<CoreStatelessConfig, 'eventBuilder'> {\n /**\n * The application definition used to attribute events to a specific consumer app.\n *\n * @remarks\n * When not provided, events will not contain app metadata in their context.\n */\n app?: App\n\n /**\n * Partial overrides for the event builder configuration.\n *\n * @remarks\n * Any provided fields are merged with the default Node SDK metadata.\n * Request-scoped consent should be bound with `forRequest()`, not configured\n * on the SDK singleton.\n *\n * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: PublicNodeEventBuilderConfig\n}\n\n/**\n * Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.\n *\n * @remarks\n * This class adapts the stateless ContentfulOptimization Core for Node runtimes by\n * applying environment-appropriate defaults (e.g., server channel, Node SDK\n * library metadata). No core runtime behavior is modified; only configuration\n * defaults differ.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const sdk = new ContentfulOptimization({\n * clientId: 'abc-123',\n * environment: 'main',\n * logLevel: 'info',\n * })\n *\n * const requestOptimization = sdk.forRequest({\n * consent: true,\n * locale: 'fr-CA',\n * profile: { id: 'profile-id' },\n * })\n *\n * const { accepted, data } = await requestOptimization.page()\n * ```\n *\n * @see {@link CoreStateless}\n *\n * @public\n */\nclass ContentfulOptimization extends CoreStateless {\n /**\n * Create an instance of the Node SDK with merged defaults.\n *\n * @param config - Partial Node-specific configuration. Any eventBuilder\n * fields provided are merged with Node's defaults.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })\n * ```\n */\n constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig) {\n const { library, ...eventBuilderConfig } = eventBuilder ?? {}\n\n super({\n ...config,\n allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,\n eventBuilder: {\n app,\n channel: 'server',\n ...eventBuilderConfig,\n library: {\n name: OPTIMIZATION_NODE_SDK_NAME,\n version: OPTIMIZATION_NODE_SDK_VERSION,\n ...library,\n },\n getConsent: () => false,\n },\n })\n }\n}\n\nexport default ContentfulOptimization\n","/**\n * Contentful ContentfulOptimization Node SDK.\n *\n * @remarks\n * Adds Node-specific defaults via the {@link ContentfulOptimization} class.\n * Core and transitive API exports are available from dedicated entrypoints:\n * `@contentful/optimization-node/core-sdk`,\n * `@contentful/optimization-node/api-client`,\n * and `@contentful/optimization-node/api-schemas`.\n *\n * @packageDocumentation\n */\n\nimport ContentfulOptimization from './ContentfulOptimization'\n\nexport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\nexport * from './ContentfulOptimization'\n\nexport default ContentfulOptimization\n"],"names":["DEFAULT_NODE_ALLOWED_EVENT_TYPES","ContentfulOptimization","CoreStateless","app","allowedEventTypes","eventBuilder","config","library","eventBuilderConfig","OPTIMIZATION_NODE_SDK_NAME","OPTIMIZATION_NODE_SDK_VERSION"],"mappings":";;AAQA,MAAMA,mCAAgD;IAAC;IAAY;CAAO;AAkF1E,MAAMC,+BAA+BC,yDAAAA,aAAaA;IAchD,YAAY,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGC,QAAgC,CAAE;QACvF,MAAM,EAAEC,OAAO,EAAE,GAAGC,oBAAoB,GAAGH,gBAAgB,CAAC;QAE5D,KAAK,CAAC;YACJ,GAAGC,MAAM;YACT,mBAAmBF,qBAAqBJ;YACxC,cAAc;gBACZG;gBACA,SAAS;gBACT,GAAGK,kBAAkB;gBACrB,SAAS;oBACP,MAAMC;oBACN,SAASC;oBACT,GAAGH,OAAO;gBACZ;gBACA,YAAY,IAAM;YACpB;QACF;IACF;AACF;AAEA,mCAAeN;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/ContentfulOptimization.ts","../src/handoff.ts","../src/index.ts"],"sourcesContent":["import {\n CoreStateless,\n type CoreStatelessConfig,\n type EventType,\n} from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\n\nconst DEFAULT_NODE_ALLOWED_EVENT_TYPES: EventType[] = ['identify', 'page']\n\n/**\n * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.\n *\n * @remarks\n * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`\n * is intentionally omitted from singleton SDK configuration.\n *\n * @public\n */\nexport type PublicNodeEventBuilderConfig = Partial<\n Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>\n>\n\n/**\n * Configuration for the Node-specific ContentfulOptimization SDK.\n *\n * @remarks\n * This configuration extends {@link CoreStatelessConfig} but allows partial\n * overrides of the event-builder configuration. SDKs commonly inject their own\n * library metadata or channel definitions.\n *\n * @see {@link CoreStatelessConfig}\n *\n * @public\n */\nexport interface OptimizationNodeConfig extends Omit<CoreStatelessConfig, 'eventBuilder'> {\n /**\n * The application definition used to attribute events to a specific consumer app.\n *\n * @remarks\n * When not provided, events will not contain app metadata in their context.\n */\n app?: App\n\n /**\n * Partial overrides for the event builder configuration.\n *\n * @remarks\n * Any provided fields are merged with the default Node SDK metadata.\n * Request-scoped consent should be bound with `forRequest()`, not configured\n * on the SDK singleton.\n *\n * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: PublicNodeEventBuilderConfig\n}\n\n/**\n * Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.\n *\n * @remarks\n * This class adapts the stateless ContentfulOptimization Core for Node runtimes by\n * applying environment-appropriate defaults (e.g., server channel, Node SDK\n * library metadata). No core runtime behavior is modified; only configuration\n * defaults differ.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const sdk = new ContentfulOptimization({\n * clientId: 'abc-123',\n * environment: 'main',\n * logLevel: 'info',\n * })\n *\n * const requestOptimization = sdk.forRequest({\n * consent: true,\n * locale: 'fr-CA',\n * profile: { id: 'profile-id' },\n * })\n *\n * const { accepted, data } = await requestOptimization.page()\n * ```\n *\n * @see {@link CoreStateless}\n *\n * @public\n */\nclass ContentfulOptimization extends CoreStateless {\n /**\n * Create an instance of the Node SDK with merged defaults.\n *\n * @param config - Partial Node-specific configuration. Any eventBuilder\n * fields provided are merged with Node's defaults.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })\n * ```\n */\n constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig) {\n const { library, ...eventBuilderConfig } = eventBuilder ?? {}\n\n super({\n ...config,\n allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,\n eventBuilder: {\n app,\n channel: 'server',\n ...eventBuilderConfig,\n library: {\n name: OPTIMIZATION_NODE_SDK_NAME,\n version: OPTIMIZATION_NODE_SDK_VERSION,\n ...library,\n },\n getConsent: () => false,\n },\n })\n }\n}\n\nexport default ContentfulOptimization\n","import {\n assertOptimizationCacheSafety,\n type ManagedEntryHandoff,\n type OptimizationCacheMetadata,\n type OptimizationData,\n type OptimizationHandoff,\n type PrivateRequestOptimizationCacheMetadata,\n} from '@contentful/optimization-core'\n\nfunction assertRequestHandoffCacheMetadata(\n cache: OptimizationCacheMetadata,\n): asserts cache is PrivateRequestOptimizationCacheMetadata {\n if (cache.scope === 'private-request') return\n\n throw new TypeError(\n 'Request handoffs must use private-request cache scope. Use public permutation handoffs for public cache scopes, or a non-request handoff for static output.',\n )\n}\n\n/**\n * Create a framework-neutral handoff from completed Node request optimization data.\n *\n * @remarks\n * This helper serializes data that a caller already received from a request-bound Experience call.\n * It does not emit page or analytics events.\n *\n * @public\n */\nexport function createRequestHandoffFromData(input: {\n readonly data?: OptimizationData\n readonly entries?: readonly ManagedEntryHandoff[]\n readonly cache?: PrivateRequestOptimizationCacheMetadata\n}): OptimizationHandoff {\n const cache: PrivateRequestOptimizationCacheMetadata = input.cache ?? { scope: 'private-request' }\n assertRequestHandoffCacheMetadata(cache)\n\n const handoff: OptimizationHandoff = {\n cache,\n ...(input.entries === undefined ? {} : { entries: input.entries }),\n ...(input.data === undefined\n ? {}\n : {\n state: {\n selectedOptimizations: input.data.selectedOptimizations,\n changes: input.data.changes,\n profile: input.data.profile,\n },\n }),\n }\n\n assertOptimizationCacheSafety(handoff)\n\n return handoff\n}\n","/**\n * Contentful ContentfulOptimization Node SDK.\n *\n * @remarks\n * Adds Node-specific defaults via the {@link ContentfulOptimization} class.\n * Core and transitive API exports are available from dedicated entrypoints:\n * `@contentful/optimization-node/core-sdk`,\n * `@contentful/optimization-node/api-client`,\n * and `@contentful/optimization-node/api-schemas`.\n *\n * @packageDocumentation\n */\n\nimport ContentfulOptimization from './ContentfulOptimization'\n\nexport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\nexport * from './ContentfulOptimization'\nexport * from './handoff'\n\nexport default ContentfulOptimization\n"],"names":["DEFAULT_NODE_ALLOWED_EVENT_TYPES","ContentfulOptimization","CoreStateless","app","allowedEventTypes","eventBuilder","config","library","eventBuilderConfig","OPTIMIZATION_NODE_SDK_NAME","OPTIMIZATION_NODE_SDK_VERSION","assertRequestHandoffCacheMetadata","cache","TypeError","createRequestHandoffFromData","input","handoff","undefined","assertOptimizationCacheSafety"],"mappings":";;AAQA,MAAMA,mCAAgD;IAAC;IAAY;CAAO;AAkF1E,MAAMC,+BAA+BC,yDAAAA,aAAaA;IAchD,YAAY,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGC,QAAgC,CAAE;QACvF,MAAM,EAAEC,OAAO,EAAE,GAAGC,oBAAoB,GAAGH,gBAAgB,CAAC;QAE5D,KAAK,CAAC;YACJ,GAAGC,MAAM;YACT,mBAAmBF,qBAAqBJ;YACxC,cAAc;gBACZG;gBACA,SAAS;gBACT,GAAGK,kBAAkB;gBACrB,SAAS;oBACP,MAAMC;oBACN,SAASC;oBACT,GAAGH,OAAO;gBACZ;gBACA,YAAY,IAAM;YACpB;QACF;IACF;AACF;AAEA,mCAAeN;ACpHf,SAASU,kCACPC,KAAgC;IAEhC,IAAIA,AAAgB,sBAAhBA,MAAM,KAAK,EAAwB;IAEvC,MAAM,IAAIC,UACR;AAEJ;AAWO,SAASC,6BAA6BC,KAI5C;IACC,MAAMH,QAAiDG,MAAM,KAAK,IAAI;QAAE,OAAO;IAAkB;IACjGJ,kCAAkCC;IAElC,MAAMI,UAA+B;QACnCJ;QACA,GAAIG,AAAkBE,WAAlBF,MAAM,OAAO,GAAiB,CAAC,IAAI;YAAE,SAASA,MAAM,OAAO;QAAC,CAAC;QACjE,GAAIA,AAAeE,WAAfF,MAAM,IAAI,GACV,CAAC,IACD;YACE,OAAO;gBACL,uBAAuBA,MAAM,IAAI,CAAC,qBAAqB;gBACvD,SAASA,MAAM,IAAI,CAAC,OAAO;gBAC3B,SAASA,MAAM,IAAI,CAAC,OAAO;YAC7B;QACF,CAAC;IACP;IAEAG,IAAAA,yDAAAA,6BAAAA,AAAAA,EAA8BF;IAE9B,OAAOA;AACT;AClCA,YAAef"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/optimization-node",
|
|
3
|
-
"
|
|
3
|
+
"description": "Node.js SDK for Contentful Optimization",
|
|
4
|
+
"version": "1.1.0",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -81,12 +82,12 @@
|
|
|
81
82
|
"buildTools": {
|
|
82
83
|
"bundleSize": {
|
|
83
84
|
"gzipBudgets": {
|
|
84
|
-
"index.cjs":
|
|
85
|
-
"index.mjs":
|
|
85
|
+
"index.cjs": 1500,
|
|
86
|
+
"index.mjs": 1300
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
90
|
"dependencies": {
|
|
90
|
-
"@contentful/optimization-core": "1.
|
|
91
|
+
"@contentful/optimization-core": "1.1.0"
|
|
91
92
|
}
|
|
92
93
|
}
|