@contentful/optimization-core 0.1.0-alpha10 → 0.1.0-alpha12

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 CHANGED
@@ -1,17 +1,17 @@
1
1
  <p align="center">
2
2
  <a href="https://www.contentful.com/developers/docs/personalization/">
3
- <img alt="Contentful Logo" title="Contentful" src="../../contentful-icon.png" width="150">
3
+ <img alt="Contentful Logo" title="Contentful" src="https://raw.githubusercontent.com/contentful/optimization/v0.1.0-alpha12/contentful-icon.png" width="150">
4
4
  </a>
5
5
  </p>
6
6
 
7
- <h1 align="center">Contentful Personalization & Analytics</h1>
7
+ <h1 align="center">Contentful Optimization Core SDK</h1>
8
8
 
9
9
  <h3 align="center">Optimization Core SDK</h3>
10
10
 
11
11
  <div align="center">
12
12
 
13
- [Readme](./README.md) · [Reference](https://contentful.github.io/optimization) ·
14
- [Contributing](../../CONTRIBUTING.md)
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-alpha12/CONTRIBUTING.md)
15
15
 
16
16
  </div>
17
17
 
@@ -31,22 +31,23 @@ other SDKs descend from the Core SDK.
31
31
  - [Working with Stateful Core](#working-with-stateful-core)
32
32
  - [Configuration](#configuration)
33
33
  - [Top-level Configuration Options](#top-level-configuration-options)
34
- - [Analytics Options](#analytics-options)
34
+ - [API Options](#api-options)
35
35
  - [Event Builder Options](#event-builder-options)
36
36
  - [Fetch Options](#fetch-options)
37
- - [Personalization Options](#personalization-options)
37
+ - [Queue Policy Options](#queue-policy-options)
38
38
  - [Core Methods](#core-methods)
39
- - [Personalization Data Resolution Methods](#personalization-data-resolution-methods)
40
- - [`getCustomFlag`](#getcustomflag)
41
- - [`personalizeEntry`](#personalizeentry)
39
+ - [Optimization Data Resolution Methods](#optimization-data-resolution-methods)
40
+ - [`getFlag`](#getflag)
41
+ - [`resolveOptimizedEntry`](#resolveoptimizedentry)
42
42
  - [`getMergeTagValue`](#getmergetagvalue)
43
- - [Personalization and Analytics Event Methods](#personalization-and-analytics-event-methods)
43
+ - [Event Methods](#event-methods)
44
44
  - [`identify`](#identify)
45
45
  - [`page`](#page)
46
46
  - [`screen`](#screen)
47
47
  - [`track`](#track)
48
- - [`trackComponentView`](#trackcomponentview)
49
- - [`trackComponentClick`](#trackcomponentclick)
48
+ - [`trackView`](#trackview)
49
+ - [`trackClick`](#trackclick)
50
+ - [`trackHover`](#trackhover)
50
51
  - [`trackFlagView`](#trackflagview)
51
52
  - [Stateful-only Core Methods](#stateful-only-core-methods)
52
53
  - [`consent`](#consent)
@@ -54,7 +55,7 @@ other SDKs descend from the Core SDK.
54
55
  - [`flush`](#flush)
55
56
  - [`destroy`](#destroy)
56
57
  - [`registerPreviewPanel` (preview tooling only)](#registerpreviewpanel-preview-tooling-only)
57
- - [Stateful-only Core Properties](#stateful-only-core-properties)
58
+ - [Core States (`CoreStateful` only)](#core-states-corestateful-only)
58
59
  - [Interceptors](#interceptors)
59
60
  - [Life-cycle Interceptors](#life-cycle-interceptors)
60
61
 
@@ -81,9 +82,11 @@ import { CoreStateless } from '@contentful/optimization-core'
81
82
  Configure and initialize the Core SDK:
82
83
 
83
84
  ```ts
84
- const optimization = new CoreStateful({ clientId: 'abc123' })
85
- // or
86
- const optimization = new CoreStateless({ clientId: 'abc123' })
85
+ const statefulOptimization = new CoreStateful({ clientId: 'abc123' })
86
+ const statelessOptimization = new CoreStateless({ clientId: 'abc123' })
87
+ const requestOptions = { locale: 'de-DE' }
88
+
89
+ await statelessOptimization.page({}, requestOptions)
87
90
  ```
88
91
 
89
92
  ## Working with Stateless Core
@@ -96,6 +99,9 @@ In stateless environments, Core will not maintain any internal state, which incl
96
99
  These concerns should be handled by consumers to fit their specific architectural and design
97
100
  specifications.
98
101
 
102
+ Request-scoped Experience options in `CoreStateless` are passed as the final argument to each
103
+ stateless event method.
104
+
99
105
  ## Working with Stateful Core
100
106
 
101
107
  The `CoreStateful` class is intended to be used as the basis for SDKs that would run in stateful
@@ -114,15 +120,14 @@ exposed externally as read-only observables.
114
120
 
115
121
  ### Top-level Configuration Options
116
122
 
117
- | Option | Required? | Default | Description |
118
- | ----------------- | --------- | ----------------------------- | ------------------------------------------------------------ |
119
- | `analytics` | No | See "Analytics Options" | Configuration specific to the Analytics/Insights API |
120
- | `clientId` | Yes | N/A | The Optimization API key |
121
- | `environment` | No | `'main'` | The environment identifier |
122
- | `eventBuilder` | No | See "Event Builder Options" | Event builder configuration (channel/library metadata, etc.) |
123
- | `fetchOptions` | No | See "Fetch Options" | Configuration for Fetch timeout and retry functionality |
124
- | `logLevel` | No | `'error'` | Minimum log level for the default console sink |
125
- | `personalization` | No | See "Personalization Options" | Configuration specific to the Personalization/Experience API |
123
+ | Option | Required? | Default | Description |
124
+ | -------------- | --------- | --------------------------- | ----------------------------------------------------------------------- |
125
+ | `api` | No | See "API Options" | Unified configuration for the Experience API and Insights API endpoints |
126
+ | `clientId` | Yes | N/A | Shared API key for Experience API and Insights API requests |
127
+ | `environment` | No | `'main'` | The environment identifier |
128
+ | `eventBuilder` | No | See "Event Builder Options" | Event builder configuration (channel/library metadata, etc.) |
129
+ | `fetchOptions` | No | See "Fetch Options" | Configuration for Fetch timeout and retry functionality |
130
+ | `logLevel` | No | `'error'` | Minimum log level for the default console sink |
126
131
 
127
132
  The following configuration options apply only in stateful environments:
128
133
 
@@ -132,32 +137,48 @@ The following configuration options apply only in stateful environments:
132
137
  | `defaults` | No | `undefined` | Set of default state values applied on initialization |
133
138
  | `getAnonymousId` | No | `undefined` | Function used to obtain an anonymous user identifier |
134
139
  | `onEventBlocked` | No | `undefined` | Callback invoked when an event call is blocked by guards |
140
+ | `queuePolicy` | No | See "Queue Policy Options" | Shared queue and retry configuration for stateful delivery |
135
141
 
136
142
  Configuration method signatures:
137
143
 
138
144
  - `getAnonymousId`: `() => string | undefined`
139
145
  - `onEventBlocked`: `(event: BlockedEvent) => void`
140
146
 
141
- ### Analytics Options
147
+ ### API Options
142
148
 
143
- | Option | Required? | Default | Description |
144
- | --------- | --------- | ------------------------------------------ | ----------------------------- |
145
- | `baseUrl` | No | `'https://ingest.insights.ninetailed.co/'` | Base URL for the Insights API |
149
+ | Option | Required? | Default | Description |
150
+ | ------------------- | --------- | ------------------------------------------ | ------------------------------------------------------------ |
151
+ | `experienceBaseUrl` | No | `'https://experience.ninetailed.co/'` | Base URL for the Experience API |
152
+ | `insightsBaseUrl` | No | `'https://ingest.insights.ninetailed.co/'` | Base URL for the Insights API |
153
+ | `enabledFeatures` | No | `['ip-enrichment', 'location']` | Enabled features the Experience API may use for each request |
146
154
 
147
- The following configuration options apply only in stateful environments:
155
+ The following configuration option applies only in stateful environments:
148
156
 
149
- | Option | Required? | Default | Description |
150
- | --------------- | --------- | --------------------- | ------------------------------------------------------------------------ |
151
- | `beaconHandler` | No | `undefined` | Handler used to enqueue events via the Beacon API or a similar mechanism |
152
- | `queuePolicy` | No | See method signatures | Queue flush retry/backoff/circuit policy for stateful analytics |
157
+ | Option | Required? | Default | Description |
158
+ | --------------- | --------- | ----------- | ------------------------------------------------------------------------------ |
159
+ | `beaconHandler` | No | `undefined` | Handler used to enqueue Insights API events via the Beacon API or equivalent |
160
+ | `ip` | No | `undefined` | IP address override used by the Experience API for location analysis |
161
+ | `locale` | No | `'en-US'` | Locale used to translate `location.city` and `location.country` |
162
+ | `plainText` | No | `false` | Sends performance-critical Experience API endpoints in plain text |
163
+ | `preflight` | No | `false` | Instructs the Experience API to aggregate a new profile state but not store it |
153
164
 
154
165
  Configuration method signatures:
155
166
 
156
167
  - `beaconHandler`: `(url: string | URL, data: BatchInsightsEventArray) => boolean`
157
- - `queuePolicy`:
158
168
 
159
- ```ts
160
- {
169
+ In stateless environments, pass `ip`, `locale`, `plainText`, and `preflight` as the final argument
170
+ to stateless event methods instead of constructor config.
171
+
172
+ ### Queue Policy Options
173
+
174
+ `queuePolicy` is available only in `CoreStateful` and combines shared flush retry settings with
175
+ Experience API offline buffering controls.
176
+
177
+ Configuration shape:
178
+
179
+ ```ts
180
+ {
181
+ flush?: {
161
182
  baseBackoffMs?: number,
162
183
  maxBackoffMs?: number,
163
184
  jitterRatio?: number,
@@ -166,29 +187,42 @@ Configuration method signatures:
166
187
  onFlushFailure?: (context: QueueFlushFailureContext) => void,
167
188
  onCircuitOpen?: (context: QueueFlushFailureContext) => void,
168
189
  onFlushRecovered?: (context: QueueFlushRecoveredContext) => void
169
- }
170
- ```
190
+ },
191
+ offlineMaxEvents?: number,
192
+ onOfflineDrop?: (context: ExperienceQueueDropContext) => void
193
+ }
194
+ ```
171
195
 
172
- Supporting callback payloads:
196
+ Supporting callback payloads:
173
197
 
174
- ```ts
175
- type QueueFlushFailureContext = {
176
- consecutiveFailures: number
177
- queuedBatches: number
178
- queuedEvents: number
179
- retryDelayMs: number
180
- }
198
+ ```ts
199
+ type ExperienceQueueDropContext = {
200
+ droppedCount: number
201
+ droppedEvents: ExperienceEventArray
202
+ maxEvents: number
203
+ queuedEvents: number
204
+ }
205
+
206
+ type QueueFlushFailureContext = {
207
+ consecutiveFailures: number
208
+ queuedBatches: number
209
+ queuedEvents: number
210
+ retryDelayMs: number
211
+ }
212
+
213
+ type QueueFlushRecoveredContext = {
214
+ consecutiveFailures: number
215
+ }
216
+ ```
181
217
 
182
- type QueueFlushRecoveredContext = {
183
- consecutiveFailures: number
184
- }
185
- ```
218
+ Notes:
186
219
 
187
- Notes:
188
- - Invalid numeric values fall back to defaults.
189
- - `jitterRatio` is clamped to `[0, 1]`.
190
- - `maxBackoffMs` is normalized to be at least `baseBackoffMs`.
191
- - Failed flush attempts include both `false` responses and thrown send errors.
220
+ - `flush` applies the same retry/backoff/circuit policy to both Insights API flushing and Experience
221
+ API offline replay.
222
+ - Invalid numeric values fall back to defaults.
223
+ - `jitterRatio` is clamped to `[0, 1]`.
224
+ - `maxBackoffMs` is normalized to be at least `baseBackoffMs`.
225
+ - Failed flush attempts include both `false` responses and thrown send errors.
192
226
 
193
227
  ### Event Builder Options
194
228
 
@@ -236,7 +270,7 @@ Configuration method signatures:
236
270
  ### Fetch Options
237
271
 
238
272
  Fetch options allow for configuration of a Fetch API-compatible fetch method and the retry/timeout
239
- logic integrated into the Optimization API Client. Specify the `fetchMethod` when the host
273
+ logic integrated into the SDK's bundled API clients. Specify the `fetchMethod` when the host
240
274
  application environment does not offer a `fetch` method that is compatible with the standard Fetch
241
275
  API in its global scope.
242
276
 
@@ -258,75 +292,9 @@ Configuration method signatures:
258
292
  >
259
293
  > Core inherits the API Client retry contract: default retries intentionally apply only to HTTP
260
294
  > `503` responses (`Service Unavailable`). This is deliberate and aligned with current Experience
261
- > and Insights API expectations; do not broaden retry status handling without an explicit API
295
+ > API and Insights API expectations; do not broaden retry status handling without an explicit API
262
296
  > contract change.
263
297
 
264
- ### Personalization Options
265
-
266
- | Option | Required? | Default | Description |
267
- | ----------------- | --------- | ------------------------------------- | ------------------------------------------------------------------- |
268
- | `baseUrl` | No | `'https://experience.ninetailed.co/'` | Base URL for the Experience API |
269
- | `enabledFeatures` | No | `['ip-enrichment', 'location']` | Enabled features which the API may use for each request |
270
- | `ip` | No | `undefined` | IP address to override the API behavior for IP analysis |
271
- | `locale` | No | `'en-US'` (in API) | Locale used to translate `location.city` and `location.country` |
272
- | `plainText` | No | `false` | Sends performance-critical endpoints in plain text |
273
- | `preflight` | No | `false` | Instructs the API to aggregate a new profile state but not store it |
274
-
275
- The following configuration options apply only in stateful environments:
276
-
277
- | Option | Required? | Default | Description |
278
- | ------------- | --------- | --------------------- | --------------------------------------------------------------------------- |
279
- | `queuePolicy` | No | See method signatures | Queue and flush-retry policy for stateful personalization offline buffering |
280
-
281
- Configuration method signatures:
282
-
283
- - `queuePolicy`:
284
-
285
- ```ts
286
- {
287
- maxEvents?: number,
288
- onDrop?: (context: PersonalizationOfflineQueueDropContext) => void,
289
- flushPolicy?: {
290
- baseBackoffMs?: number,
291
- maxBackoffMs?: number,
292
- jitterRatio?: number,
293
- maxConsecutiveFailures?: number,
294
- circuitOpenMs?: number,
295
- onFlushFailure?: (context: QueueFlushFailureContext) => void,
296
- onCircuitOpen?: (context: QueueFlushFailureContext) => void,
297
- onFlushRecovered?: (context: QueueFlushRecoveredContext) => void
298
- }
299
- }
300
- ```
301
-
302
- Supporting callback payloads:
303
-
304
- ```ts
305
- type PersonalizationOfflineQueueDropContext = {
306
- droppedCount: number
307
- droppedEvents: ExperienceEventArray
308
- maxEvents: number
309
- queuedEvents: number
310
- }
311
-
312
- type QueueFlushFailureContext = {
313
- consecutiveFailures: number
314
- queuedBatches: number
315
- queuedEvents: number
316
- retryDelayMs: number
317
- }
318
-
319
- type QueueFlushRecoveredContext = {
320
- consecutiveFailures: number
321
- }
322
- ```
323
-
324
- Notes:
325
- - Default `maxEvents` is `100`.
326
- - If the queue is full while offline, oldest events are dropped first.
327
- - `onDrop` is best-effort; callback errors are swallowed.
328
- - `flushPolicy` uses the same normalization semantics as `analytics.queuePolicy`.
329
-
330
298
  ## Core Methods
331
299
 
332
300
  The methods in this section are available in both stateful and stateless Core classes. However, be
@@ -335,9 +303,9 @@ implementations.
335
303
 
336
304
  Arguments marked with an asterisk (\*) are always required.
337
305
 
338
- ### Personalization Data Resolution Methods
306
+ ### Optimization Data Resolution Methods
339
307
 
340
- #### `getCustomFlag`
308
+ #### `getFlag`
341
309
 
342
310
  Get the specified Custom Flag's value from the provided changes array, or from the current internal
343
311
  state in stateful implementations.
@@ -351,15 +319,23 @@ Returns:
351
319
 
352
320
  - The resolved value for the specified Custom Flag, or `undefined` if it cannot be found.
353
321
 
322
+ Behavior notes:
323
+
324
+ - In `CoreStateful`, calling `getFlag(...)` automatically emits a flag view event via
325
+ `trackFlagView`.
326
+ - In `CoreStateless`, `getFlag(...)` does not auto-emit a flag view event.
327
+ - If full map resolution is needed for advanced use cases, use
328
+ `optimization.flagsResolver.resolve(changes)`.
329
+
354
330
  > [!NOTE]
355
331
  >
356
332
  > If the `changes` argument is omitted in stateless implementations, the method will return
357
333
  > `undefined`.
358
334
 
359
- #### `personalizeEntry`
335
+ #### `resolveOptimizedEntry`
360
336
 
361
- Resolve a baseline Contentful entry to a personalized variant using the provided selected
362
- personalizations, or from the current internal state in stateful implementations.
337
+ Resolve a baseline Contentful entry to an optimized variant using the provided selected
338
+ optimizations, or from the current internal state in stateful implementations.
363
339
 
364
340
  Type arguments:
365
341
 
@@ -369,18 +345,18 @@ Type arguments:
369
345
 
370
346
  Arguments:
371
347
 
372
- - `entry`\*: The entry to personalize
373
- - `personalizations`: Selected personalizations
348
+ - `entry`\*: The baseline entry to resolve
349
+ - `selectedOptimizations`: Selected optimizations
374
350
 
375
351
  Returns:
376
352
 
377
- - The resolved personalized entry variant, or the supplied baseline entry if baseline is the
378
- selected variant or a variant cannot be found.
353
+ - The resolved optimized entry variant, or the supplied baseline entry if baseline is the selected
354
+ variant or a variant cannot be found.
379
355
 
380
356
  > [!NOTE]
381
357
  >
382
- > If the `personalizations` argument is omitted in stateless implementations, the method will return
383
- > the baseline entry.
358
+ > If the `selectedOptimizations` argument is omitted in stateless implementations, the method will
359
+ > return the baseline entry.
384
360
 
385
361
  #### `getMergeTagValue`
386
362
 
@@ -398,7 +374,21 @@ Arguments:
398
374
  > If the `profile` argument is omitted in stateless implementations, the method will return the
399
375
  > merge tag's fallback value.
400
376
 
401
- ### Personalization and Analytics Event Methods
377
+ ### Event Methods
378
+
379
+ In `CoreStateful`, call these methods on the root instance. In `CoreStateless`, call them on the
380
+ root instance and pass request-scoped Experience options as the final argument when needed:
381
+
382
+ ```ts
383
+ const requestOptions = {
384
+ locale: 'de-DE',
385
+ }
386
+
387
+ await optimization.page({ ...requestContext, profile }, requestOptions)
388
+ ```
389
+
390
+ Request-scoped Experience options stay separate from the event payload. Event context data belongs
391
+ in `payload`, while `ip`, `locale`, `plainText`, and `preflight` belong in `requestOptions`.
402
392
 
403
393
  Only the following methods may return an `OptimizationData` object:
404
394
 
@@ -406,15 +396,20 @@ Only the following methods may return an `OptimizationData` object:
406
396
  - `page`
407
397
  - `screen`
408
398
  - `track`
409
- - `trackComponentView` (when `payload.sticky` is `true`)
399
+ - `trackView` (when `payload.sticky` is `true`)
410
400
 
411
- `trackComponentClick` and `trackFlagView` return no data. When returned, `OptimizationData`
401
+ `trackClick`, `trackHover`, and `trackFlagView` return no data. When returned, `OptimizationData`
412
402
  contains:
413
403
 
414
404
  - `changes`: Currently used for Custom Flags
415
- - `personalizations`: Selected personalizations for the profile
405
+ - `selectedOptimizations`: Selected optimizations for the profile
416
406
  - `profile`: Profile associated with the evaluated events
417
407
 
408
+ In stateless runtimes, Insights-backed methods require a profile for delivery. Non-sticky
409
+ `trackView`, `trackClick`, `trackHover`, and `trackFlagView` require `payload.profile.id`. Sticky
410
+ `trackView` may omit `profile`, because the returned Experience profile is reused for the paired
411
+ Insights event.
412
+
418
413
  #### `identify`
419
414
 
420
415
  Identify the current profile/visitor to associate traits with a profile.
@@ -423,48 +418,55 @@ Arguments:
423
418
 
424
419
  - `payload`\*: Identify event builder arguments object, including an optional `profile` property
425
420
  with a `PartialProfile` value that requires only an `id`
421
+ - `requestOptions`: Optional request-scoped Experience API options passed as the final argument
426
422
 
427
423
  #### `page`
428
424
 
429
- Record a personalization page view.
425
+ Record an Experience API page view.
430
426
 
431
427
  Arguments:
432
428
 
433
429
  - `payload`\*: Page view event builder arguments object, including an optional `profile` property
434
430
  with a `PartialProfile` value that requires only an `id`
431
+ - `requestOptions`: Optional request-scoped Experience API options passed as the final argument
435
432
 
436
433
  #### `screen`
437
434
 
438
- Record a personalization screen view.
435
+ Record an Experience API screen view.
439
436
 
440
437
  Arguments:
441
438
 
442
439
  - `payload`\*: Screen view event builder arguments object, including an optional `profile` property
443
440
  with a `PartialProfile` value that requires only an `id`
441
+ - `requestOptions`: Optional request-scoped Experience API options passed as the final argument
444
442
 
445
443
  #### `track`
446
444
 
447
- Record a personalization custom track event.
445
+ Record an Experience API custom track event.
448
446
 
449
447
  Arguments:
450
448
 
451
449
  - `payload`\*: Track event builder arguments object, including an optional `profile` property with a
452
450
  `PartialProfile` value that requires only an `id`
451
+ - `requestOptions`: Optional request-scoped Experience API options passed as the final argument
453
452
 
454
- #### `trackComponentView`
453
+ #### `trackView`
455
454
 
456
- Record an analytics component view event. When the payload marks the component as "sticky", an
457
- additional personalization component view is recorded. This method only returns `OptimizationData`
458
- when the component is marked as "sticky".
455
+ Record an Insights API entry view event. When the payload marks the entry as "sticky", an additional
456
+ Experience API entry view is recorded. This method only returns `OptimizationData` when the entry is
457
+ marked as "sticky".
459
458
 
460
459
  Arguments:
461
460
 
462
- - `payload`\*: Component view event builder arguments object, including an optional `profile`
463
- property with a `PartialProfile` value that requires only an `id`
461
+ - `payload`\*: Entry view event builder arguments object. When `payload.sticky` is `true`, `profile`
462
+ is optional and the returned Experience profile is reused for Insights delivery. Otherwise,
463
+ `profile` is required and must contain at least an `id`
464
+ - `requestOptions`: Optional request-scoped Experience API options passed as the final argument.
465
+ Only used when `payload.sticky` is `true`
464
466
 
465
- #### `trackComponentClick`
467
+ #### `trackClick`
466
468
 
467
- Record an analytics component click event.
469
+ Record an Insights API entry click event.
468
470
 
469
471
  Returns:
470
472
 
@@ -472,11 +474,29 @@ Returns:
472
474
 
473
475
  Arguments:
474
476
 
475
- - `payload`\*: Component click event builder arguments object
477
+ - `payload`\*: Entry click event builder arguments object, including a required `profile` property
478
+ with a `PartialProfile` value that requires only an `id`
479
+ - `requestOptions`: Optional request-scoped Experience API options accepted for signature
480
+ consistency; currently unused
481
+
482
+ #### `trackHover`
483
+
484
+ Record an Insights API entry hover event.
485
+
486
+ Returns:
487
+
488
+ - `void`
489
+
490
+ Arguments:
491
+
492
+ - `payload`\*: Entry hover event builder arguments object, including a required `profile` property
493
+ with a `PartialProfile` value that requires only an `id`
494
+ - `requestOptions`: Optional request-scoped Experience API options accepted for signature
495
+ consistency; currently unused
476
496
 
477
497
  #### `trackFlagView`
478
498
 
479
- Track a feature flag view via analytics. This is functionally the same as a non-sticky component
499
+ Track a feature flag view via the Insights API. This is functionally the same as a non-sticky flag
480
500
  view event.
481
501
 
482
502
  Returns:
@@ -485,7 +505,10 @@ Returns:
485
505
 
486
506
  Arguments:
487
507
 
488
- - `payload`\*: Component view event builder arguments object
508
+ - `payload`\*: Flag view event builder arguments object, including a required `profile` property
509
+ with a `PartialProfile` value that requires only an `id`
510
+ - `requestOptions`: Optional request-scoped Experience API options accepted for signature
511
+ consistency; currently unused
489
512
 
490
513
  ## Stateful-only Core Methods
491
514
 
@@ -503,8 +526,8 @@ Resets all internal state _except_ consent. This method expects no arguments and
503
526
 
504
527
  ### `flush`
505
528
 
506
- Flushes queued analytics and personalization events. This method expects no arguments and returns a
507
- `Promise<void>`.
529
+ Flushes queued Insights API and Experience API events. This method expects no arguments and returns
530
+ a `Promise<void>`.
508
531
 
509
532
  ### `destroy`
510
533
 
@@ -552,25 +575,67 @@ const signalFns = previewBridge[PREVIEW_PANEL_SIGNAL_FNS_SYMBOL]
552
575
  > interceptors) to apply immediate local overrides without network round-trips. This coupling is
553
576
  > deliberate and necessary for preview functionality.
554
577
 
555
- ## Stateful-only Core Properties
578
+ ## Core States (`CoreStateful` only)
579
+
580
+ `states` is available on `CoreStateful` and exposes signal-backed observables for runtime state.
581
+
582
+ Available state streams:
583
+
584
+ - `consent`: Current consent state (`boolean | undefined`)
585
+ - `blockedEventStream`: Latest blocked-call metadata (`BlockedEvent | undefined`)
586
+ - `eventStream`: Latest emitted Insights API or Experience API event
587
+ (`InsightsEvent | ExperienceEvent | undefined`)
588
+ - `flag(name)`: Key-scoped flag observable (`Observable<Json>`)
589
+ - `canOptimize`: Whether optimization selections are available (`boolean`;
590
+ `selectedOptimizations !== undefined`)
591
+ - `profile`: Current profile (`Profile | undefined`)
592
+ - `selectedOptimizations`: Current selected optimizations (`SelectedOptimizationArray | undefined`)
593
+ - `previewPanelAttached`: Preview panel attachment state (`boolean`)
594
+ - `previewPanelOpen`: Preview panel open state (`boolean`)
595
+
596
+ Each observable provides:
597
+
598
+ - `current`: Deep-cloned snapshot of the latest value
599
+ - `subscribe(next)`: Immediately emits `current`, then emits future updates
600
+ - `subscribeOnce(next)`: Emits the first non-nullish value, then auto-unsubscribes
601
+
602
+ `current` and callback payloads are deep-cloned snapshots, so local mutations do not affect Core's
603
+ internal signal state.
604
+
605
+ Update behavior:
556
606
 
557
- - `states`: Returns an object mapping of observables for all internal states
558
- - `consent`: The current state of user consent
559
- - `blockedEventStream`: The latest blocked event payload
560
- - `eventStream`: The latest event to be queued
561
- - `flags`: All current resolved Custom Flags
562
- - `profile`: The current user profile
563
- - `personalizations`: The current collection of selected personalizations
607
+ - `blockedEventStream` updates whenever a call is blocked by consent guards.
608
+ - `eventStream` updates when a valid event is accepted for send/queue.
609
+ - `flag(name)` updates when the resolved value for that key changes.
610
+ - `canOptimize` updates whenever `selectedOptimizations` becomes defined or `undefined`.
611
+ - `consent` updates from defaults and `optimization.consent(...)`.
612
+ - `previewPanelAttached` and `previewPanelOpen` are controlled by preview tooling and are preserved
613
+ across `reset()`.
564
614
 
565
- The `blockedEventStream` state is updated whenever a call is blocked by consent guards. Each state
566
- except `consent`, `eventStream`, and `blockedEventStream` is updated internally whenever a response
567
- from the Experience API contains a new or updated respective state.
615
+ Example: read the latest snapshot synchronously:
616
+
617
+ ```ts
618
+ const profile = optimization.states.profile.current
619
+ if (profile) console.log(`Current profile: ${profile.id}`)
620
+ ```
621
+
622
+ Example: subscribe and clean up:
623
+
624
+ ```ts
625
+ const sub = optimization.states.profile.subscribe((profile) => {
626
+ if (!profile) return
627
+ console.log(`Profile ${profile.id} updated`)
628
+ })
629
+
630
+ // later (component unmount / teardown)
631
+ sub.unsubscribe()
632
+ ```
568
633
 
569
- Example `states` observable usage:
634
+ Example: wait for first available profile:
570
635
 
571
636
  ```ts
572
- optimization.states.profile.subscribe((profile) => {
573
- console.log(`Profile ${profile.id} updated!`)
637
+ optimization.states.profile.subscribeOnce((profile) => {
638
+ console.log(`Profile ${profile.id} loaded`)
574
639
  })
575
640
  ```
576
641
 
package/dist/160.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import * as __rspack_external__contentful_optimization_api_client_api_schemas_4192893e from "@contentful/optimization-api-client/api-schemas";
2
+ var PartialProfile = __rspack_external__contentful_optimization_api_client_api_schemas_4192893e.PartialProfile;
3
+ export { PartialProfile, __rspack_external__contentful_optimization_api_client_api_schemas_4192893e };
package/dist/260.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const OPTIMIZATION_CORE_SDK_VERSION = "0.1.0-alpha10";
1
+ const OPTIMIZATION_CORE_SDK_VERSION = "0.1.0-alpha12";
2
2
  const OPTIMIZATION_CORE_SDK_NAME = "@contentful/optimization-core";
3
3
  const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';
4
4
  const ANONYMOUS_ID_KEY = '__ctfl_opt_anonymous_id__';
@@ -6,9 +6,9 @@ const CONSENT_KEY = '__ctfl_opt_consent__';
6
6
  const CHANGES_CACHE_KEY = '__ctfl_opt_changes__';
7
7
  const DEBUG_FLAG_KEY = '__ctfl_opt_debug__';
8
8
  const PROFILE_CACHE_KEY = '__ctfl_opt_profile__';
9
- const PERSONALIZATIONS_CACHE_KEY = '__ctfl_opt_personalizations__';
9
+ const SELECTED_OPTIMIZATIONS_CACHE_KEY = '__ctfl_opt_selected-optimizations__';
10
10
  const ANONYMOUS_ID_COOKIE_LEGACY = 'ntaid';
11
11
  const ANONYMOUS_ID_KEY_LEGACY = '__nt_anonymous_id__';
12
- export { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_COOKIE_LEGACY, ANONYMOUS_ID_KEY, ANONYMOUS_ID_KEY_LEGACY, CHANGES_CACHE_KEY, CONSENT_KEY, DEBUG_FLAG_KEY, OPTIMIZATION_CORE_SDK_NAME, OPTIMIZATION_CORE_SDK_VERSION, PERSONALIZATIONS_CACHE_KEY, PROFILE_CACHE_KEY };
12
+ export { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_COOKIE_LEGACY, ANONYMOUS_ID_KEY, ANONYMOUS_ID_KEY_LEGACY, CHANGES_CACHE_KEY, CONSENT_KEY, DEBUG_FLAG_KEY, OPTIMIZATION_CORE_SDK_NAME, OPTIMIZATION_CORE_SDK_VERSION, PROFILE_CACHE_KEY, SELECTED_OPTIMIZATIONS_CACHE_KEY };
13
13
 
14
14
  //# sourceMappingURL=260.mjs.map