@contentful/optimization-node 0.1.0-alpha10 → 0.1.0-alpha11
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 +135 -79
- package/dist/260.mjs +1 -1
- package/dist/260.mjs.map +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -14
- package/dist/index.d.mts +16 -14
- package/dist/index.d.ts +16 -14
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -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="
|
|
3
|
+
<img alt="Contentful Logo" title="Contentful" src="https://raw.githubusercontent.com/contentful/optimization/v0.1.0-alpha11/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
|
-
[
|
|
14
|
-
[Contributing](
|
|
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-alpha11/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](
|
|
24
|
-
[Contentful Optimization SDK Suite](
|
|
23
|
+
[Optimization Core Library](https://github.com/contentful/optimization/blob/v0.1.0-alpha11/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-alpha11/README.md).
|
|
25
25
|
|
|
26
26
|
<details>
|
|
27
27
|
<summary>Table of Contents</summary>
|
|
@@ -31,22 +31,22 @@ The Optimization Node SDK implements functionality specific to Node environments
|
|
|
31
31
|
- [Reference Implementations](#reference-implementations)
|
|
32
32
|
- [Configuration](#configuration)
|
|
33
33
|
- [Top-level Configuration Options](#top-level-configuration-options)
|
|
34
|
-
- [
|
|
34
|
+
- [API Options](#api-options)
|
|
35
35
|
- [Event Builder Options](#event-builder-options)
|
|
36
36
|
- [Fetch Options](#fetch-options)
|
|
37
|
-
- [Personalization Options](#personalization-options)
|
|
38
37
|
- [Optimization Methods](#optimization-methods)
|
|
39
|
-
- [
|
|
40
|
-
- [`
|
|
41
|
-
- [`
|
|
38
|
+
- [Optimization Data Resolution Methods](#optimization-data-resolution-methods)
|
|
39
|
+
- [`getFlag`](#getflag)
|
|
40
|
+
- [`resolveOptimizedEntry`](#resolveoptimizedentry)
|
|
42
41
|
- [`getMergeTagValue`](#getmergetagvalue)
|
|
43
|
-
- [
|
|
42
|
+
- [Experience API and Insights API Event Methods](#experience-api-and-insights-api-event-methods)
|
|
44
43
|
- [`identify`](#identify)
|
|
45
44
|
- [`page`](#page)
|
|
46
45
|
- [`screen`](#screen)
|
|
47
46
|
- [`track`](#track)
|
|
48
|
-
- [`
|
|
49
|
-
- [`
|
|
47
|
+
- [`trackView`](#trackview)
|
|
48
|
+
- [`trackClick`](#trackclick)
|
|
49
|
+
- [`trackHover`](#trackhover)
|
|
50
50
|
- [`trackFlagView`](#trackflagview)
|
|
51
51
|
- [Interceptors](#interceptors)
|
|
52
52
|
- [Life-cycle Interceptors](#life-cycle-interceptors)
|
|
@@ -65,61 +65,93 @@ pnpm install @contentful/optimization-node
|
|
|
65
65
|
Import the Optimization class; both CJS and ESM module systems are supported, ESM preferred:
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
|
-
import
|
|
68
|
+
import ContentfulOptimization from '@contentful/optimization-node'
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Configure and initialize the Optimization Node SDK:
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
|
-
const optimization = new
|
|
74
|
+
const optimization = new ContentfulOptimization({ clientId: 'abc123' })
|
|
75
|
+
const requestOptimization = optimization.forRequest()
|
|
75
76
|
```
|
|
76
77
|
|
|
78
|
+
Create `optimization` once per module or process, then call `optimization.forRequest(...)` once per
|
|
79
|
+
incoming request.
|
|
80
|
+
|
|
81
|
+
For a step-by-step Express-style walkthrough that covers request context, profile persistence,
|
|
82
|
+
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-alpha11/documentation/integrating-the-node-sdk-in-a-node-app.md).
|
|
84
|
+
|
|
85
|
+
## Development Harness
|
|
86
|
+
|
|
87
|
+
The package-local dev harness runs from `packages/node/node-sdk/dev/` and reads `.env` from this
|
|
88
|
+
package directory.
|
|
89
|
+
|
|
90
|
+
1. Start from `.env.example` and create or update `packages/node/node-sdk/.env`.
|
|
91
|
+
2. Prefer the repo-standard `PUBLIC_...` variable names shown in `.env.example`.
|
|
92
|
+
3. Start the harness from the repo root:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
pnpm --filter @contentful/optimization-node dev
|
|
96
|
+
```
|
|
97
|
+
|
|
77
98
|
## Reference Implementations
|
|
78
99
|
|
|
79
100
|
Reference implementations illustrate how the SDK may be used under common scenarios, as well as
|
|
80
101
|
select less-common scenarios, with the most basic example solution possible.
|
|
81
102
|
|
|
82
|
-
- [Node SSR Only](
|
|
83
|
-
Node SDK to render
|
|
84
|
-
- [Node SSR + Web Vanilla](
|
|
103
|
+
- [Node SSR Only](https://github.com/contentful/optimization/blob/v0.1.0-alpha11/implementations/node-sdk/README.md): Example application that uses the
|
|
104
|
+
Node SDK to render an optimized Web page
|
|
105
|
+
- [Node SSR + Web Vanilla](https://github.com/contentful/optimization/blob/v0.1.0-alpha11/implementations/node-sdk+web-sdk/README.md): Example application
|
|
85
106
|
demonstrating simple profile synchronization between the Node and
|
|
86
|
-
[Web](
|
|
107
|
+
[Web](https://github.com/contentful/optimization/blob/v0.1.0-alpha11/packages/web/web-sdk/README.md) SDKs via cookie
|
|
87
108
|
|
|
88
109
|
## Configuration
|
|
89
110
|
|
|
90
111
|
### Top-level Configuration Options
|
|
91
112
|
|
|
92
|
-
| Option
|
|
93
|
-
|
|
|
94
|
-
| `
|
|
95
|
-
| `app`
|
|
96
|
-
| `clientId`
|
|
97
|
-
| `environment`
|
|
98
|
-
| `eventBuilder`
|
|
99
|
-
| `fetchOptions`
|
|
100
|
-
| `logLevel`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
| `
|
|
113
|
+
| Option | Required? | Default | Description |
|
|
114
|
+
| -------------- | --------- | --------------------------- | ------------------------------------------------------------------------------ |
|
|
115
|
+
| `api` | No | See "API Options" | Unified configuration for the Experience API and Insights API endpoints |
|
|
116
|
+
| `app` | No | `undefined` | The application definition used to attribute events to a specific consumer app |
|
|
117
|
+
| `clientId` | Yes | N/A | Shared API key for Experience API and Insights API requests |
|
|
118
|
+
| `environment` | No | `'main'` | The environment identifier |
|
|
119
|
+
| `eventBuilder` | No | See "Event Builder Options" | Event builder configuration (channel/library metadata, etc.) |
|
|
120
|
+
| `fetchOptions` | No | See "Fetch Options" | Configuration for Fetch timeout and retry functionality |
|
|
121
|
+
| `logLevel` | No | `'error'` | Minimum log level for the default console sink |
|
|
122
|
+
|
|
123
|
+
### API Options
|
|
124
|
+
|
|
125
|
+
| Option | Required? | Default | Description |
|
|
126
|
+
| ------------------- | --------- | ------------------------------------------ | ------------------------------------------------------------ |
|
|
127
|
+
| `experienceBaseUrl` | No | `'https://experience.ninetailed.co/'` | Base URL for the Experience API |
|
|
128
|
+
| `insightsBaseUrl` | No | `'https://ingest.insights.ninetailed.co/'` | Base URL for the Insights API |
|
|
129
|
+
| `enabledFeatures` | No | `['ip-enrichment', 'location']` | Enabled features the Experience API may use for each request |
|
|
130
|
+
|
|
131
|
+
Request-scoped Experience API options are bound with `optimization.forRequest(...)` instead of the
|
|
132
|
+
SDK constructor:
|
|
133
|
+
|
|
134
|
+
| Option | Required? | Default | Description |
|
|
135
|
+
| ----------- | --------- | ----------- | ------------------------------------------------------------------------------ |
|
|
136
|
+
| `ip` | No | `undefined` | IP address override used by the Experience API for location analysis |
|
|
137
|
+
| `locale` | No | `undefined` | Locale used to translate `location.city` and `location.country` |
|
|
138
|
+
| `plainText` | No | `undefined` | Sends performance-critical Experience API endpoints in plain text |
|
|
139
|
+
| `preflight` | No | `undefined` | Instructs the Experience API to aggregate a new profile state but not store it |
|
|
108
140
|
|
|
109
141
|
### Event Builder Options
|
|
110
142
|
|
|
111
143
|
Event builder options should only be supplied when building an SDK on top of the Optimization Node
|
|
112
144
|
SDK or any of its descendent SDKs.
|
|
113
145
|
|
|
114
|
-
| Option | Required? | Default
|
|
115
|
-
| --------- | --------- |
|
|
116
|
-
| `channel` | No | `'server'`
|
|
117
|
-
| `library` | No | `{ name: '
|
|
146
|
+
| Option | Required? | Default | Description |
|
|
147
|
+
| --------- | --------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
148
|
+
| `channel` | No | `'server'` | The channel that identifies where events originate from (e.g. `'web'`, `'mobile'`) |
|
|
149
|
+
| `library` | No | `{ name: '@contentful/optimization-node', version: '0.0.0' }` | The client library metadata that is attached to all events |
|
|
118
150
|
|
|
119
151
|
### Fetch Options
|
|
120
152
|
|
|
121
153
|
Fetch options allow for configuration of a Fetch API-compatible fetch method and the retry/timeout
|
|
122
|
-
logic integrated into the
|
|
154
|
+
logic integrated into the SDK's bundled API clients. Specify the `fetchMethod` when the host
|
|
123
155
|
application environment does not offer a `fetch` method that is compatible with the standard Fetch
|
|
124
156
|
API in its global scope.
|
|
125
157
|
|
|
@@ -137,24 +169,13 @@ Configuration method signatures:
|
|
|
137
169
|
- `fetchMethod`: `(url: string | URL, init: RequestInit) => Promise<Response>`
|
|
138
170
|
- `onFailedAttempt` and `onRequestTimeout`: `(options: FetchMethodCallbackOptions) => void`
|
|
139
171
|
|
|
140
|
-
### Personalization Options
|
|
141
|
-
|
|
142
|
-
| Option | Required? | Default | Description |
|
|
143
|
-
| ----------------- | --------- | ------------------------------------- | ------------------------------------------------------------------- |
|
|
144
|
-
| `baseUrl` | No | `'https://experience.ninetailed.co/'` | Base URL for the Experience API |
|
|
145
|
-
| `enabledFeatures` | No | `['ip-enrichment', 'location']` | Enabled features which the API may use for each request |
|
|
146
|
-
| `ip` | No | `undefined` | IP address to override the API behavior for IP analysis |
|
|
147
|
-
| `locale` | No | `'en-US'` (in API) | Locale used to translate `location.city` and `location.country` |
|
|
148
|
-
| `plainText` | No | `false` | Sends performance-critical endpoints in plain text |
|
|
149
|
-
| `preflight` | No | `false` | Instructs the API to aggregate a new profile state but not store it |
|
|
150
|
-
|
|
151
172
|
## Optimization Methods
|
|
152
173
|
|
|
153
174
|
Arguments marked with an asterisk (\*) are always required.
|
|
154
175
|
|
|
155
|
-
###
|
|
176
|
+
### Optimization Data Resolution Methods
|
|
156
177
|
|
|
157
|
-
#### `
|
|
178
|
+
#### `getFlag`
|
|
158
179
|
|
|
159
180
|
Get the specified Custom Flag's value from the provided changes array.
|
|
160
181
|
|
|
@@ -167,14 +188,20 @@ Returns:
|
|
|
167
188
|
|
|
168
189
|
- The resolved value for the specified Custom Flag, or `undefined` if it cannot be found.
|
|
169
190
|
|
|
191
|
+
Behavior notes:
|
|
192
|
+
|
|
193
|
+
- Node SDK is stateless; `getFlag(...)` does not auto-emit `trackFlagView`.
|
|
194
|
+
- If full map resolution is needed for advanced use cases, use
|
|
195
|
+
`optimization.flagsResolver.resolve(changes)`.
|
|
196
|
+
|
|
170
197
|
> [!NOTE]
|
|
171
198
|
>
|
|
172
199
|
> If the `changes` argument is omitted, the method will return `undefined`.
|
|
173
200
|
|
|
174
|
-
#### `
|
|
201
|
+
#### `resolveOptimizedEntry`
|
|
175
202
|
|
|
176
|
-
Resolve a baseline Contentful entry to
|
|
177
|
-
|
|
203
|
+
Resolve a baseline Contentful entry to an optimized variant using the provided selected
|
|
204
|
+
optimizations.
|
|
178
205
|
|
|
179
206
|
Type arguments:
|
|
180
207
|
|
|
@@ -184,17 +211,17 @@ Type arguments:
|
|
|
184
211
|
|
|
185
212
|
Arguments:
|
|
186
213
|
|
|
187
|
-
- `entry`\*: The entry to
|
|
188
|
-
- `
|
|
214
|
+
- `entry`\*: The baseline entry to resolve
|
|
215
|
+
- `selectedOptimizations`: Selected optimizations
|
|
189
216
|
|
|
190
217
|
Returns:
|
|
191
218
|
|
|
192
|
-
- The resolved
|
|
193
|
-
|
|
219
|
+
- The resolved optimized entry variant, or the supplied baseline entry if baseline is the selected
|
|
220
|
+
variant or a variant cannot be found.
|
|
194
221
|
|
|
195
222
|
> [!NOTE]
|
|
196
223
|
>
|
|
197
|
-
> If the `
|
|
224
|
+
> If the `selectedOptimizations` argument is omitted, the method will return the baseline entry.
|
|
198
225
|
|
|
199
226
|
#### `getMergeTagValue`
|
|
200
227
|
|
|
@@ -211,7 +238,15 @@ Arguments:
|
|
|
211
238
|
>
|
|
212
239
|
> If the `profile` argument is omitted, the method will return the merge tag's fallback value.
|
|
213
240
|
|
|
214
|
-
###
|
|
241
|
+
### Experience API and Insights API Event Methods
|
|
242
|
+
|
|
243
|
+
Create a request scope once per incoming request, then call event methods on that scope:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
const requestOptimization = optimization.forRequest({
|
|
247
|
+
locale: req.acceptsLanguages()[0] ?? 'en-US',
|
|
248
|
+
})
|
|
249
|
+
```
|
|
215
250
|
|
|
216
251
|
Only the following methods may return an `OptimizationData` object:
|
|
217
252
|
|
|
@@ -219,15 +254,20 @@ Only the following methods may return an `OptimizationData` object:
|
|
|
219
254
|
- `page`
|
|
220
255
|
- `screen`
|
|
221
256
|
- `track`
|
|
222
|
-
- `
|
|
257
|
+
- `trackView` (when `payload.sticky` is `true`)
|
|
223
258
|
|
|
224
|
-
`
|
|
259
|
+
`trackClick`, `trackHover`, and `trackFlagView` return no data. When returned, `OptimizationData`
|
|
225
260
|
contains:
|
|
226
261
|
|
|
227
262
|
- `changes`: Currently used for Custom Flags
|
|
228
|
-
- `
|
|
263
|
+
- `selectedOptimizations`: Selected optimizations for the profile
|
|
229
264
|
- `profile`: Profile associated with the evaluated events
|
|
230
265
|
|
|
266
|
+
In stateless runtimes, Insights-backed methods require a profile for delivery. Non-sticky
|
|
267
|
+
`trackView`, `trackClick`, `trackHover`, and `trackFlagView` require `payload.profile.id`. Sticky
|
|
268
|
+
`trackView` may omit `profile`, because the returned Experience profile is reused for the paired
|
|
269
|
+
Insights event.
|
|
270
|
+
|
|
231
271
|
#### `identify`
|
|
232
272
|
|
|
233
273
|
Identify the current profile/visitor to associate traits with a profile.
|
|
@@ -239,7 +279,7 @@ Arguments:
|
|
|
239
279
|
|
|
240
280
|
#### `page`
|
|
241
281
|
|
|
242
|
-
Record
|
|
282
|
+
Record an Experience API page view.
|
|
243
283
|
|
|
244
284
|
Arguments:
|
|
245
285
|
|
|
@@ -248,7 +288,7 @@ Arguments:
|
|
|
248
288
|
|
|
249
289
|
#### `screen`
|
|
250
290
|
|
|
251
|
-
Record
|
|
291
|
+
Record an Experience API screen view.
|
|
252
292
|
|
|
253
293
|
Arguments:
|
|
254
294
|
|
|
@@ -257,27 +297,28 @@ Arguments:
|
|
|
257
297
|
|
|
258
298
|
#### `track`
|
|
259
299
|
|
|
260
|
-
Record
|
|
300
|
+
Record an Experience API custom track event.
|
|
261
301
|
|
|
262
302
|
Arguments:
|
|
263
303
|
|
|
264
304
|
- `payload`\*: Track event builder arguments object, including an optional `profile` property with a
|
|
265
305
|
`PartialProfile` value that requires only an `id`
|
|
266
306
|
|
|
267
|
-
#### `
|
|
307
|
+
#### `trackView`
|
|
268
308
|
|
|
269
|
-
Record an
|
|
270
|
-
|
|
271
|
-
|
|
309
|
+
Record an Insights API entry view event. When the payload marks the entry as "sticky", an additional
|
|
310
|
+
Experience API entry view is recorded. This method only returns `OptimizationData` when the entry is
|
|
311
|
+
marked as "sticky".
|
|
272
312
|
|
|
273
313
|
Arguments:
|
|
274
314
|
|
|
275
|
-
- `payload`\*:
|
|
276
|
-
|
|
315
|
+
- `payload`\*: Entry view event builder arguments object. When `payload.sticky` is `true`, `profile`
|
|
316
|
+
is optional and the returned Experience profile is reused for Insights delivery. Otherwise,
|
|
317
|
+
`profile` is required and must contain at least an `id`
|
|
277
318
|
|
|
278
|
-
#### `
|
|
319
|
+
#### `trackClick`
|
|
279
320
|
|
|
280
|
-
Record an
|
|
321
|
+
Record an Insights API entry click event.
|
|
281
322
|
|
|
282
323
|
Returns:
|
|
283
324
|
|
|
@@ -285,11 +326,25 @@ Returns:
|
|
|
285
326
|
|
|
286
327
|
Arguments:
|
|
287
328
|
|
|
288
|
-
- `payload`\*:
|
|
329
|
+
- `payload`\*: Entry click event builder arguments object, including a required `profile` property
|
|
330
|
+
with a `PartialProfile` value that requires only an `id`
|
|
331
|
+
|
|
332
|
+
#### `trackHover`
|
|
333
|
+
|
|
334
|
+
Record an Insights API entry hover event.
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
|
|
338
|
+
- `void`
|
|
339
|
+
|
|
340
|
+
Arguments:
|
|
341
|
+
|
|
342
|
+
- `payload`\*: Entry hover event builder arguments object, including a required `profile` property
|
|
343
|
+
with a `PartialProfile` value that requires only an `id`
|
|
289
344
|
|
|
290
345
|
#### `trackFlagView`
|
|
291
346
|
|
|
292
|
-
Track a feature flag view via
|
|
347
|
+
Track a feature flag view via the Insights API. This is functionally the same as a non-sticky flag
|
|
293
348
|
view event.
|
|
294
349
|
|
|
295
350
|
Returns:
|
|
@@ -298,7 +353,8 @@ Returns:
|
|
|
298
353
|
|
|
299
354
|
Arguments:
|
|
300
355
|
|
|
301
|
-
- `payload`\*:
|
|
356
|
+
- `payload`\*: Flag view event builder arguments object, including a required `profile` property
|
|
357
|
+
with a `PartialProfile` value that requires only an `id`
|
|
302
358
|
|
|
303
359
|
## Interceptors
|
|
304
360
|
|
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-alpha11";
|
|
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/260.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"260.mjs","sources":["../src/constants.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
|
|
1
|
+
{"version":3,"file":"260.mjs","sources":["../src/constants.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"],"names":["OPTIMIZATION_NODE_SDK_VERSION","__OPTIMIZATION_VERSION__","OPTIMIZATION_NODE_SDK_NAME","__OPTIMIZATION_PACKAGE_NAME__"],"mappings":"AAYO,MAAMA,gCACoCC;AAS1C,MAAMC,6BAEPC"}
|
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-alpha11";
|
|
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/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/constants.ts"],"sourcesContent":["__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};","// 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
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/constants.ts"],"sourcesContent":["__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};","// 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"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","OPTIMIZATION_NODE_SDK_VERSION","__OPTIMIZATION_VERSION__","OPTIMIZATION_NODE_SDK_NAME","__OPTIMIZATION_PACKAGE_NAME__"],"mappings":";;;IAAAA,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;;;;;;;;;;;ACMO,MAAMI,gCACoCC;AAS1C,MAAMC,6BAEPC"}
|
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-alpha11";
|
|
10
10
|
const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
|
|
11
11
|
}
|
|
12
12
|
};
|
|
@@ -66,14 +66,14 @@ var __webpack_exports__ = {};
|
|
|
66
66
|
};
|
|
67
67
|
return (0, external_es_toolkit_namespaceObject.merge)(defaultConfig, restConfig);
|
|
68
68
|
}
|
|
69
|
-
class
|
|
69
|
+
class ContentfulOptimization extends optimization_core_namespaceObject.CoreStateless {
|
|
70
70
|
constructor(config){
|
|
71
71
|
const mergedConfig = mergeConfig(config);
|
|
72
72
|
super(mergedConfig);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
const src =
|
|
75
|
+
const src_ContentfulOptimization = ContentfulOptimization;
|
|
76
|
+
const src = src_ContentfulOptimization;
|
|
77
77
|
})();
|
|
78
78
|
exports.OPTIMIZATION_NODE_SDK_NAME = __webpack_exports__.OPTIMIZATION_NODE_SDK_NAME;
|
|
79
79
|
exports.OPTIMIZATION_NODE_SDK_VERSION = __webpack_exports__.OPTIMIZATION_NODE_SDK_VERSION;
|
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/
|
|
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, CoreStateless } 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 request = sdk.forRequest({ locale: 'en-US' })\n *\n * await request.track({ event: 'server_event', properties: { id: 1 } })\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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Contentful
|
|
2
|
+
* Contentful ContentfulOptimization Node SDK.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* Adds Node-specific defaults via the {@link
|
|
5
|
+
* Adds Node-specific defaults via the {@link ContentfulOptimization} class.
|
|
6
6
|
* Core and transitive API exports are available from dedicated entrypoints:
|
|
7
7
|
* `@contentful/optimization-node/core-sdk`,
|
|
8
8
|
* `@contentful/optimization-node/api-client`,
|
|
@@ -16,32 +16,34 @@ import { CoreStateless } from '@contentful/optimization-core';
|
|
|
16
16
|
import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Node-specific
|
|
19
|
+
* Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.
|
|
20
20
|
*
|
|
21
21
|
* @remarks
|
|
22
|
-
* This class adapts the stateless
|
|
22
|
+
* This class adapts the stateless ContentfulOptimization Core for Node runtimes by
|
|
23
23
|
* applying environment-appropriate defaults (e.g., server channel, Node SDK
|
|
24
|
-
* library metadata). No
|
|
25
|
-
*
|
|
24
|
+
* library metadata). No core runtime behavior is modified; only configuration
|
|
25
|
+
* defaults differ.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```ts
|
|
29
|
-
* import
|
|
29
|
+
* import ContentfulOptimization from '@contentful/optimization-node'
|
|
30
30
|
*
|
|
31
|
-
* const sdk = new
|
|
31
|
+
* const sdk = new ContentfulOptimization({
|
|
32
32
|
* clientId: 'abc-123',
|
|
33
33
|
* environment: 'main',
|
|
34
34
|
* logLevel: 'info',
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* const request = sdk.forRequest({ locale: 'en-US' })
|
|
38
|
+
*
|
|
39
|
+
* await request.track({ event: 'server_event', properties: { id: 1 } })
|
|
38
40
|
* ```
|
|
39
41
|
*
|
|
40
42
|
* @see {@link CoreStateless}
|
|
41
43
|
*
|
|
42
44
|
* @public
|
|
43
45
|
*/
|
|
44
|
-
declare class
|
|
46
|
+
declare class ContentfulOptimization extends CoreStateless {
|
|
45
47
|
/**
|
|
46
48
|
* Create an instance of the Node SDK with merged defaults.
|
|
47
49
|
*
|
|
@@ -50,14 +52,14 @@ declare class Optimization extends CoreStateless {
|
|
|
50
52
|
*
|
|
51
53
|
* @example
|
|
52
54
|
* ```ts
|
|
53
|
-
* import
|
|
55
|
+
* import ContentfulOptimization from '@contentful/optimization-node'
|
|
54
56
|
*
|
|
55
|
-
* const optimization = new
|
|
57
|
+
* const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
58
60
|
constructor(config: OptimizationNodeConfig);
|
|
59
61
|
}
|
|
60
|
-
export default
|
|
62
|
+
export default ContentfulOptimization;
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
65
|
* The package name of the Optimization Node SDK, injected at build-time.
|
|
@@ -78,7 +80,7 @@ export declare const OPTIMIZATION_NODE_SDK_NAME: string;
|
|
|
78
80
|
export declare const OPTIMIZATION_NODE_SDK_VERSION: string;
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* Configuration for the Node-specific
|
|
83
|
+
* Configuration for the Node-specific ContentfulOptimization SDK.
|
|
82
84
|
*
|
|
83
85
|
* @remarks
|
|
84
86
|
* This configuration extends {@link CoreStatelessConfig} but allows partial
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Contentful
|
|
2
|
+
* Contentful ContentfulOptimization Node SDK.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* Adds Node-specific defaults via the {@link
|
|
5
|
+
* Adds Node-specific defaults via the {@link ContentfulOptimization} class.
|
|
6
6
|
* Core and transitive API exports are available from dedicated entrypoints:
|
|
7
7
|
* `@contentful/optimization-node/core-sdk`,
|
|
8
8
|
* `@contentful/optimization-node/api-client`,
|
|
@@ -16,32 +16,34 @@ import { CoreStateless } from '@contentful/optimization-core';
|
|
|
16
16
|
import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Node-specific
|
|
19
|
+
* Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.
|
|
20
20
|
*
|
|
21
21
|
* @remarks
|
|
22
|
-
* This class adapts the stateless
|
|
22
|
+
* This class adapts the stateless ContentfulOptimization Core for Node runtimes by
|
|
23
23
|
* applying environment-appropriate defaults (e.g., server channel, Node SDK
|
|
24
|
-
* library metadata). No
|
|
25
|
-
*
|
|
24
|
+
* library metadata). No core runtime behavior is modified; only configuration
|
|
25
|
+
* defaults differ.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```ts
|
|
29
|
-
* import
|
|
29
|
+
* import ContentfulOptimization from '@contentful/optimization-node'
|
|
30
30
|
*
|
|
31
|
-
* const sdk = new
|
|
31
|
+
* const sdk = new ContentfulOptimization({
|
|
32
32
|
* clientId: 'abc-123',
|
|
33
33
|
* environment: 'main',
|
|
34
34
|
* logLevel: 'info',
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* const request = sdk.forRequest({ locale: 'en-US' })
|
|
38
|
+
*
|
|
39
|
+
* await request.track({ event: 'server_event', properties: { id: 1 } })
|
|
38
40
|
* ```
|
|
39
41
|
*
|
|
40
42
|
* @see {@link CoreStateless}
|
|
41
43
|
*
|
|
42
44
|
* @public
|
|
43
45
|
*/
|
|
44
|
-
declare class
|
|
46
|
+
declare class ContentfulOptimization extends CoreStateless {
|
|
45
47
|
/**
|
|
46
48
|
* Create an instance of the Node SDK with merged defaults.
|
|
47
49
|
*
|
|
@@ -50,14 +52,14 @@ declare class Optimization extends CoreStateless {
|
|
|
50
52
|
*
|
|
51
53
|
* @example
|
|
52
54
|
* ```ts
|
|
53
|
-
* import
|
|
55
|
+
* import ContentfulOptimization from '@contentful/optimization-node'
|
|
54
56
|
*
|
|
55
|
-
* const optimization = new
|
|
57
|
+
* const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
58
60
|
constructor(config: OptimizationNodeConfig);
|
|
59
61
|
}
|
|
60
|
-
export default
|
|
62
|
+
export default ContentfulOptimization;
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
65
|
* The package name of the Optimization Node SDK, injected at build-time.
|
|
@@ -78,7 +80,7 @@ export declare const OPTIMIZATION_NODE_SDK_NAME: string;
|
|
|
78
80
|
export declare const OPTIMIZATION_NODE_SDK_VERSION: string;
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* Configuration for the Node-specific
|
|
83
|
+
* Configuration for the Node-specific ContentfulOptimization SDK.
|
|
82
84
|
*
|
|
83
85
|
* @remarks
|
|
84
86
|
* This configuration extends {@link CoreStatelessConfig} but allows partial
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Contentful
|
|
2
|
+
* Contentful ContentfulOptimization Node SDK.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* Adds Node-specific defaults via the {@link
|
|
5
|
+
* Adds Node-specific defaults via the {@link ContentfulOptimization} class.
|
|
6
6
|
* Core and transitive API exports are available from dedicated entrypoints:
|
|
7
7
|
* `@contentful/optimization-node/core-sdk`,
|
|
8
8
|
* `@contentful/optimization-node/api-client`,
|
|
@@ -16,32 +16,34 @@ import { CoreStateless } from '@contentful/optimization-core';
|
|
|
16
16
|
import { CoreStatelessConfig } from '@contentful/optimization-core';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Node-specific
|
|
19
|
+
* Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.
|
|
20
20
|
*
|
|
21
21
|
* @remarks
|
|
22
|
-
* This class adapts the stateless
|
|
22
|
+
* This class adapts the stateless ContentfulOptimization Core for Node runtimes by
|
|
23
23
|
* applying environment-appropriate defaults (e.g., server channel, Node SDK
|
|
24
|
-
* library metadata). No
|
|
25
|
-
*
|
|
24
|
+
* library metadata). No core runtime behavior is modified; only configuration
|
|
25
|
+
* defaults differ.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```ts
|
|
29
|
-
* import
|
|
29
|
+
* import ContentfulOptimization from '@contentful/optimization-node'
|
|
30
30
|
*
|
|
31
|
-
* const sdk = new
|
|
31
|
+
* const sdk = new ContentfulOptimization({
|
|
32
32
|
* clientId: 'abc-123',
|
|
33
33
|
* environment: 'main',
|
|
34
34
|
* logLevel: 'info',
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* const request = sdk.forRequest({ locale: 'en-US' })
|
|
38
|
+
*
|
|
39
|
+
* await request.track({ event: 'server_event', properties: { id: 1 } })
|
|
38
40
|
* ```
|
|
39
41
|
*
|
|
40
42
|
* @see {@link CoreStateless}
|
|
41
43
|
*
|
|
42
44
|
* @public
|
|
43
45
|
*/
|
|
44
|
-
declare class
|
|
46
|
+
declare class ContentfulOptimization extends CoreStateless {
|
|
45
47
|
/**
|
|
46
48
|
* Create an instance of the Node SDK with merged defaults.
|
|
47
49
|
*
|
|
@@ -50,14 +52,14 @@ declare class Optimization extends CoreStateless {
|
|
|
50
52
|
*
|
|
51
53
|
* @example
|
|
52
54
|
* ```ts
|
|
53
|
-
* import
|
|
55
|
+
* import ContentfulOptimization from '@contentful/optimization-node'
|
|
54
56
|
*
|
|
55
|
-
* const optimization = new
|
|
57
|
+
* const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
58
60
|
constructor(config: OptimizationNodeConfig);
|
|
59
61
|
}
|
|
60
|
-
export default
|
|
62
|
+
export default ContentfulOptimization;
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
65
|
* The package name of the Optimization Node SDK, injected at build-time.
|
|
@@ -78,7 +80,7 @@ export declare const OPTIMIZATION_NODE_SDK_NAME: string;
|
|
|
78
80
|
export declare const OPTIMIZATION_NODE_SDK_VERSION: string;
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* Configuration for the Node-specific
|
|
83
|
+
* Configuration for the Node-specific ContentfulOptimization SDK.
|
|
82
84
|
*
|
|
83
85
|
* @remarks
|
|
84
86
|
* This configuration extends {@link CoreStatelessConfig} but allows partial
|
package/dist/index.mjs
CHANGED
|
@@ -15,14 +15,14 @@ function mergeConfig(config) {
|
|
|
15
15
|
};
|
|
16
16
|
return merge(defaultConfig, restConfig);
|
|
17
17
|
}
|
|
18
|
-
class
|
|
18
|
+
class ContentfulOptimization extends __rspack_external__contentful_optimization_core_7d4758c6.CoreStateless {
|
|
19
19
|
constructor(config){
|
|
20
20
|
const mergedConfig = mergeConfig(config);
|
|
21
21
|
super(mergedConfig);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
const src =
|
|
24
|
+
const src_ContentfulOptimization = ContentfulOptimization;
|
|
25
|
+
const src = src_ContentfulOptimization;
|
|
26
26
|
export { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from "./260.mjs";
|
|
27
27
|
export default src;
|
|
28
28
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["import { type CoreStatelessConfig, CoreStateless } 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 request = sdk.forRequest({ locale: 'en-US' })\n *\n * await request.track({ event: 'server_event', properties: { id: 1 } })\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,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/optimization-node",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha11",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/contentful/optimization.git",
|
|
8
|
+
"directory": "packages/node/node-sdk"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"main": "./dist/index.cjs",
|
|
7
12
|
"module": "./dist/index.mjs",
|
|
@@ -72,8 +77,16 @@
|
|
|
72
77
|
"files": [
|
|
73
78
|
"dist/**/*"
|
|
74
79
|
],
|
|
80
|
+
"buildTools": {
|
|
81
|
+
"bundleSize": {
|
|
82
|
+
"gzipBudgets": {
|
|
83
|
+
"index.cjs": 1200,
|
|
84
|
+
"index.mjs": 500
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
75
88
|
"dependencies": {
|
|
76
89
|
"es-toolkit": "^1.44.0",
|
|
77
|
-
"@contentful/optimization-core": "0.1.0-
|
|
90
|
+
"@contentful/optimization-core": "0.1.0-alpha11"
|
|
78
91
|
}
|
|
79
92
|
}
|