@contentful/optimization-node 0.1.0-alpha11 → 0.1.0-alpha13
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 +48 -17
- package/dist/260.mjs +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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-alpha13/contentful-icon.png" width="150">
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
<div align="center">
|
|
12
12
|
|
|
13
|
-
[Guides](https://contentful.github.io/optimization/documents/Guides.html) ·
|
|
14
|
-
[Reference](https://contentful.github.io/optimization) · [Contributing](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
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-alpha13/CONTRIBUTING.md)
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
> The Optimization SDK Suite is pre-release (alpha). Breaking changes may be published at any time.
|
|
21
21
|
|
|
22
22
|
The Optimization Node SDK implements functionality specific to Node environments, based on the
|
|
23
|
-
[Optimization Core Library](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
24
|
-
[Contentful Optimization SDK Suite](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
23
|
+
[Optimization Core Library](https://github.com/contentful/optimization/blob/v0.1.0-alpha13/packages/universal/core-sdk/README.md). This SDK is part of the
|
|
24
|
+
[Contentful Optimization SDK Suite](https://github.com/contentful/optimization/blob/v0.1.0-alpha13/README.md).
|
|
25
25
|
|
|
26
26
|
<details>
|
|
27
27
|
<summary>Table of Contents</summary>
|
|
@@ -72,15 +72,28 @@ Configure and initialize the Optimization Node SDK:
|
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
const optimization = new ContentfulOptimization({ clientId: 'abc123' })
|
|
75
|
-
const
|
|
75
|
+
const requestOptions = { locale: 'en-US' }
|
|
76
|
+
|
|
77
|
+
await optimization.page({}, requestOptions)
|
|
76
78
|
```
|
|
77
79
|
|
|
78
|
-
Create `optimization` once per module or process, then
|
|
79
|
-
incoming request.
|
|
80
|
+
Create `optimization` once per module or process, then pass request-scoped Experience options as the
|
|
81
|
+
final argument to stateless event methods inside each incoming request.
|
|
82
|
+
|
|
83
|
+
## Caching Guidance
|
|
84
|
+
|
|
85
|
+
The Node SDK is stateless, but that does not mean all request work is cacheable.
|
|
86
|
+
|
|
87
|
+
- Cache raw Contentful delivery payloads in your application layer.
|
|
88
|
+
- Treat cached Contentful entries as immutable.
|
|
89
|
+
- Use `resolveOptimizedEntry()` and `getMergeTagValue()` as request-local helpers when rendering.
|
|
90
|
+
- Do not memoize `page()`, `identify()`, `screen()`, `track()`, `trackView()`, `trackClick()`,
|
|
91
|
+
`trackHover()`, or `trackFlagView()`. Those methods emit outbound events and/or return profile
|
|
92
|
+
state for the current request.
|
|
80
93
|
|
|
81
94
|
For a step-by-step Express-style walkthrough that covers request context, profile persistence,
|
|
82
95
|
Contentful entry resolution, and hybrid Node + browser setups, see
|
|
83
|
-
[Integrating the Optimization Node SDK in a Node App](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
96
|
+
[Integrating the Optimization Node SDK in a Node App](https://github.com/contentful/optimization/blob/v0.1.0-alpha13/documentation/guides/integrating-the-node-sdk-in-a-node-app.md).
|
|
84
97
|
|
|
85
98
|
## Development Harness
|
|
86
99
|
|
|
@@ -100,11 +113,11 @@ package directory.
|
|
|
100
113
|
Reference implementations illustrate how the SDK may be used under common scenarios, as well as
|
|
101
114
|
select less-common scenarios, with the most basic example solution possible.
|
|
102
115
|
|
|
103
|
-
- [Node SSR Only](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
116
|
+
- [Node SSR Only](https://github.com/contentful/optimization/blob/v0.1.0-alpha13/implementations/node-sdk/README.md): Example application that uses the
|
|
104
117
|
Node SDK to render an optimized Web page
|
|
105
|
-
- [Node SSR + Web Vanilla](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
118
|
+
- [Node SSR + Web Vanilla](https://github.com/contentful/optimization/blob/v0.1.0-alpha13/implementations/node-sdk+web-sdk/README.md): Example application
|
|
106
119
|
demonstrating simple profile synchronization between the Node and
|
|
107
|
-
[Web](https://github.com/contentful/optimization/blob/v0.1.0-
|
|
120
|
+
[Web](https://github.com/contentful/optimization/blob/v0.1.0-alpha13/packages/web/web-sdk/README.md) SDKs via cookie
|
|
108
121
|
|
|
109
122
|
## Configuration
|
|
110
123
|
|
|
@@ -128,8 +141,8 @@ select less-common scenarios, with the most basic example solution possible.
|
|
|
128
141
|
| `insightsBaseUrl` | No | `'https://ingest.insights.ninetailed.co/'` | Base URL for the Insights API |
|
|
129
142
|
| `enabledFeatures` | No | `['ip-enrichment', 'location']` | Enabled features the Experience API may use for each request |
|
|
130
143
|
|
|
131
|
-
Request-scoped Experience API options are
|
|
132
|
-
SDK constructor:
|
|
144
|
+
Request-scoped Experience API options are passed to stateless event methods as their final argument
|
|
145
|
+
instead of the SDK constructor:
|
|
133
146
|
|
|
134
147
|
| Option | Required? | Default | Description |
|
|
135
148
|
| ----------- | --------- | ----------- | ------------------------------------------------------------------------------ |
|
|
@@ -240,14 +253,20 @@ Arguments:
|
|
|
240
253
|
|
|
241
254
|
### Experience API and Insights API Event Methods
|
|
242
255
|
|
|
243
|
-
|
|
256
|
+
Pass request-scoped Experience options as the final argument to stateless event methods:
|
|
244
257
|
|
|
245
258
|
```ts
|
|
246
|
-
const
|
|
259
|
+
const requestOptions = {
|
|
247
260
|
locale: req.acceptsLanguages()[0] ?? 'en-US',
|
|
248
|
-
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
await optimization.page({ ...requestContext, profile }, requestOptions)
|
|
249
264
|
```
|
|
250
265
|
|
|
266
|
+
Request-scoped Experience options stay separate from the event payload. Event context such as page
|
|
267
|
+
data, locale metadata on the event, and user agent belong in `payload`, while `ip`, `locale`,
|
|
268
|
+
`plainText`, and `preflight` belong in `requestOptions`.
|
|
269
|
+
|
|
251
270
|
Only the following methods may return an `OptimizationData` object:
|
|
252
271
|
|
|
253
272
|
- `identify`
|
|
@@ -276,6 +295,7 @@ Arguments:
|
|
|
276
295
|
|
|
277
296
|
- `payload`\*: Identify event builder arguments object, including an optional `profile` property
|
|
278
297
|
with a `PartialProfile` value that requires only an `id`
|
|
298
|
+
- `requestOptions`: Optional request-scoped Experience API options passed as the final argument
|
|
279
299
|
|
|
280
300
|
#### `page`
|
|
281
301
|
|
|
@@ -285,6 +305,7 @@ Arguments:
|
|
|
285
305
|
|
|
286
306
|
- `payload`\*: Page view event builder arguments object, including an optional `profile` property
|
|
287
307
|
with a `PartialProfile` value that requires only an `id`
|
|
308
|
+
- `requestOptions`: Optional request-scoped Experience API options passed as the final argument
|
|
288
309
|
|
|
289
310
|
#### `screen`
|
|
290
311
|
|
|
@@ -294,6 +315,7 @@ Arguments:
|
|
|
294
315
|
|
|
295
316
|
- `payload`\*: Screen view event builder arguments object, including an optional `profile` property
|
|
296
317
|
with a `PartialProfile` value that requires only an `id`
|
|
318
|
+
- `requestOptions`: Optional request-scoped Experience API options passed as the final argument
|
|
297
319
|
|
|
298
320
|
#### `track`
|
|
299
321
|
|
|
@@ -303,6 +325,7 @@ Arguments:
|
|
|
303
325
|
|
|
304
326
|
- `payload`\*: Track event builder arguments object, including an optional `profile` property with a
|
|
305
327
|
`PartialProfile` value that requires only an `id`
|
|
328
|
+
- `requestOptions`: Optional request-scoped Experience API options passed as the final argument
|
|
306
329
|
|
|
307
330
|
#### `trackView`
|
|
308
331
|
|
|
@@ -315,6 +338,8 @@ Arguments:
|
|
|
315
338
|
- `payload`\*: Entry view event builder arguments object. When `payload.sticky` is `true`, `profile`
|
|
316
339
|
is optional and the returned Experience profile is reused for Insights delivery. Otherwise,
|
|
317
340
|
`profile` is required and must contain at least an `id`
|
|
341
|
+
- `requestOptions`: Optional request-scoped Experience API options passed as the final argument.
|
|
342
|
+
Only used when `payload.sticky` is `true`
|
|
318
343
|
|
|
319
344
|
#### `trackClick`
|
|
320
345
|
|
|
@@ -328,6 +353,8 @@ Arguments:
|
|
|
328
353
|
|
|
329
354
|
- `payload`\*: Entry click event builder arguments object, including a required `profile` property
|
|
330
355
|
with a `PartialProfile` value that requires only an `id`
|
|
356
|
+
- `requestOptions`: Optional request-scoped Experience API options accepted for signature
|
|
357
|
+
consistency; currently unused
|
|
331
358
|
|
|
332
359
|
#### `trackHover`
|
|
333
360
|
|
|
@@ -341,6 +368,8 @@ Arguments:
|
|
|
341
368
|
|
|
342
369
|
- `payload`\*: Entry hover event builder arguments object, including a required `profile` property
|
|
343
370
|
with a `PartialProfile` value that requires only an `id`
|
|
371
|
+
- `requestOptions`: Optional request-scoped Experience API options accepted for signature
|
|
372
|
+
consistency; currently unused
|
|
344
373
|
|
|
345
374
|
#### `trackFlagView`
|
|
346
375
|
|
|
@@ -355,6 +384,8 @@ Arguments:
|
|
|
355
384
|
|
|
356
385
|
- `payload`\*: Flag view event builder arguments object, including a required `profile` property
|
|
357
386
|
with a `PartialProfile` value that requires only an `id`
|
|
387
|
+
- `requestOptions`: Optional request-scoped Experience API options accepted for signature
|
|
388
|
+
consistency; currently unused
|
|
358
389
|
|
|
359
390
|
## Interceptors
|
|
360
391
|
|
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-alpha13";
|
|
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-alpha13";
|
|
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 = "0.1.0-
|
|
9
|
+
const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha13";
|
|
10
10
|
const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
|
|
11
11
|
}
|
|
12
12
|
};
|
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 { type CoreStatelessConfig
|
|
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 { CoreStateless, type CoreStatelessConfig } from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { merge } from 'es-toolkit'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\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 * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: Partial<Omit<CoreStatelessConfig['eventBuilder'], 'app'>>\n}\n\n/**\n * Merge user-supplied configuration with defaults for the Node SDK.\n *\n * @param config - The input configuration supplied by the caller.\n * @returns A fully composed {@link CoreStatelessConfig} object suitable for\n * constructing the core runtime.\n *\n * @remarks\n * Ensures that the Node SDK always identifies itself via a `server` channel\n * and a `library` metadata block unless explicitly overridden.\n *\n * @internal\n */\nfunction mergeConfig(config: OptimizationNodeConfig): CoreStatelessConfig {\n const { app, ...restConfig } = config\n\n const defaultConfig: Partial<CoreStatelessConfig> = {\n eventBuilder: {\n app,\n channel: 'server',\n library: { name: OPTIMIZATION_NODE_SDK_NAME, version: OPTIMIZATION_NODE_SDK_VERSION },\n },\n }\n return merge(defaultConfig, restConfig)\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 requestOptions = { locale: 'en-US' }\n *\n * await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)\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(config: OptimizationNodeConfig) {\n const mergedConfig: CoreStatelessConfig = mergeConfig(config)\n\n super(mergedConfig)\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","mergeConfig","config","app","restConfig","defaultConfig","merge","ContentfulOptimization","CoreStateless","mergedConfig"],"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;;;;;;;;;;;;;IC4CA,SAASI,YAAYC,MAA8B;QACjD,MAAM,EAAEC,GAAG,EAAE,GAAGC,YAAY,GAAGF;QAE/B,MAAMG,gBAA8C;YAClD,cAAc;gBACZF;gBACA,SAAS;gBACT,SAAS;oBAAE,MAAMX,UAAAA,0BAA0BA;oBAAE,SAASF,UAAAA,6BAA6BA;gBAAC;YACtF;QACF;QACA,OAAOgB,AAAAA,IAAAA,oCAAAA,KAAAA,AAAAA,EAAMD,eAAeD;IAC9B;IA8BA,MAAMG,+BAA+BC,kCAAAA,aAAaA;QAchD,YAAYN,MAA8B,CAAE;YAC1C,MAAMO,eAAoCR,YAAYC;YAEtD,KAAK,CAACO;QACR;IACF;IAEA,mCAAeF;IC9Ff,YAAeA"}
|
package/dist/index.d.cts
CHANGED
|
@@ -34,9 +34,9 @@ import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
|
34
34
|
* logLevel: 'info',
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
|
-
* const
|
|
37
|
+
* const requestOptions = { locale: 'en-US' }
|
|
38
38
|
*
|
|
39
|
-
* await
|
|
39
|
+
* await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* @see {@link CoreStateless}
|
package/dist/index.d.mts
CHANGED
|
@@ -34,9 +34,9 @@ import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
|
34
34
|
* logLevel: 'info',
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
|
-
* const
|
|
37
|
+
* const requestOptions = { locale: 'en-US' }
|
|
38
38
|
*
|
|
39
|
-
* await
|
|
39
|
+
* await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* @see {@link CoreStateless}
|
package/dist/index.d.ts
CHANGED
|
@@ -34,9 +34,9 @@ import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
|
34
34
|
* logLevel: 'info',
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
|
-
* const
|
|
37
|
+
* const requestOptions = { locale: 'en-US' }
|
|
38
38
|
*
|
|
39
|
-
* await
|
|
39
|
+
* await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* @see {@link CoreStateless}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["import { type CoreStatelessConfig
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["import { CoreStateless, type CoreStatelessConfig } from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { merge } from 'es-toolkit'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\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 * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: Partial<Omit<CoreStatelessConfig['eventBuilder'], 'app'>>\n}\n\n/**\n * Merge user-supplied configuration with defaults for the Node SDK.\n *\n * @param config - The input configuration supplied by the caller.\n * @returns A fully composed {@link CoreStatelessConfig} object suitable for\n * constructing the core runtime.\n *\n * @remarks\n * Ensures that the Node SDK always identifies itself via a `server` channel\n * and a `library` metadata block unless explicitly overridden.\n *\n * @internal\n */\nfunction mergeConfig(config: OptimizationNodeConfig): CoreStatelessConfig {\n const { app, ...restConfig } = config\n\n const defaultConfig: Partial<CoreStatelessConfig> = {\n eventBuilder: {\n app,\n channel: 'server',\n library: { name: OPTIMIZATION_NODE_SDK_NAME, version: OPTIMIZATION_NODE_SDK_VERSION },\n },\n }\n return merge(defaultConfig, restConfig)\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 requestOptions = { locale: 'en-US' }\n *\n * await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)\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(config: OptimizationNodeConfig) {\n const mergedConfig: CoreStatelessConfig = mergeConfig(config)\n\n super(mergedConfig)\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":["mergeConfig","config","app","restConfig","defaultConfig","OPTIMIZATION_NODE_SDK_NAME","OPTIMIZATION_NODE_SDK_VERSION","merge","ContentfulOptimization","CoreStateless","mergedConfig"],"mappings":";;;AAkDA,SAASA,YAAYC,MAA8B;IACjD,MAAM,EAAEC,GAAG,EAAE,GAAGC,YAAY,GAAGF;IAE/B,MAAMG,gBAA8C;QAClD,cAAc;YACZF;YACA,SAAS;YACT,SAAS;gBAAE,MAAMG;gBAA4B,SAASC;YAA8B;QACtF;IACF;IACA,OAAOC,MAAMH,eAAeD;AAC9B;AA8BA,MAAMK,+BAA+BC,yDAAAA,aAAaA;IAchD,YAAYR,MAA8B,CAAE;QAC1C,MAAMS,eAAoCV,YAAYC;QAEtD,KAAK,CAACS;IACR;AACF;AAEA,mCAAeF;AC9Ff,YAAeA"}
|
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-alpha13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"es-toolkit": "^1.
|
|
90
|
-
"@contentful/optimization-core": "0.1.0-
|
|
89
|
+
"es-toolkit": "^1.45.1",
|
|
90
|
+
"@contentful/optimization-core": "0.1.0-alpha13"
|
|
91
91
|
}
|
|
92
92
|
}
|