@contentful/optimization-node 0.1.0-alpha13 → 0.1.0-alpha15

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/dist/260.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha13";
1
+ const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha15";
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 };
@@ -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-alpha13";
33
+ const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha15";
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-alpha13";
9
+ const OPTIMIZATION_NODE_SDK_VERSION = "0.1.0-alpha15";
10
10
  const OPTIMIZATION_NODE_SDK_NAME = "@contentful/optimization-node";
11
11
  }
12
12
  };
@@ -50,26 +50,29 @@ var __webpack_exports__ = {};
50
50
  default: ()=>src
51
51
  });
52
52
  const optimization_core_namespaceObject = require("@contentful/optimization-core");
53
- const external_es_toolkit_namespaceObject = require("es-toolkit");
54
53
  var constants = __webpack_require__("./src/constants.ts");
55
- function mergeConfig(config) {
56
- const { app, ...restConfig } = config;
57
- const defaultConfig = {
58
- eventBuilder: {
59
- app,
60
- channel: 'server',
61
- library: {
62
- name: constants.OPTIMIZATION_NODE_SDK_NAME,
63
- version: constants.OPTIMIZATION_NODE_SDK_VERSION
64
- }
65
- }
66
- };
67
- return (0, external_es_toolkit_namespaceObject.merge)(defaultConfig, restConfig);
68
- }
54
+ const DEFAULT_NODE_ALLOWED_EVENT_TYPES = [
55
+ 'identify',
56
+ 'page'
57
+ ];
69
58
  class ContentfulOptimization extends optimization_core_namespaceObject.CoreStateless {
70
- constructor(config){
71
- const mergedConfig = mergeConfig(config);
72
- super(mergedConfig);
59
+ constructor({ app, allowedEventTypes, eventBuilder, ...config }){
60
+ const { library, getConsent: _getConsent, ...eventBuilderConfig } = eventBuilder ?? {};
61
+ super({
62
+ ...config,
63
+ allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,
64
+ eventBuilder: {
65
+ app,
66
+ channel: 'server',
67
+ library: {
68
+ name: constants.OPTIMIZATION_NODE_SDK_NAME,
69
+ version: constants.OPTIMIZATION_NODE_SDK_VERSION,
70
+ ...library
71
+ },
72
+ getConsent: ()=>false,
73
+ ...eventBuilderConfig
74
+ }
75
+ });
73
76
  }
74
77
  }
75
78
  const src_ContentfulOptimization = ContentfulOptimization;
@@ -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 { 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"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/constants.ts","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/naming-convention -- Replaced at build-time\ndeclare const __OPTIMIZATION_VERSION__: string | undefined\n// eslint-disable-next-line @typescript-eslint/naming-convention -- Replaced at build-time\ndeclare const __OPTIMIZATION_PACKAGE_NAME__: string | undefined\n\n/**\n * The current version of the Optimization Node SDK, injected at build-time.\n *\n * @defaultValue `'0.0.0'` when the build-time replacement is unavailable.\n *\n * @public\n */\nexport const OPTIMIZATION_NODE_SDK_VERSION =\n typeof __OPTIMIZATION_VERSION__ === 'string' ? __OPTIMIZATION_VERSION__ : '0.0.0'\n\n/**\n * The package name of the Optimization Node SDK, injected at build-time.\n *\n * @defaultValue `'@contentful/optimization-node'` when the build-time replacement is unavailable.\n *\n * @public\n */\nexport const OPTIMIZATION_NODE_SDK_NAME =\n typeof __OPTIMIZATION_PACKAGE_NAME__ === 'string'\n ? __OPTIMIZATION_PACKAGE_NAME__\n : '@contentful/optimization-node'\n\n/**\n * Re-exports of anonymous identifier constants used by the Optimization Core.\n *\n * @remarks\n * This constant is surfaced here to provide a stable import path for Node SDK\n * consumers. It represents the cookie key used by the Optimization Framework\n * to persist an anonymous identifier for tracking optimization and insights\n * events when no explicit profile is known.\n *\n * @example\n * ```ts\n * import { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from '@contentful/optimization-node/constants'\n * const cookieId = request.cookies[ANONYMOUS_ID_COOKIE]\n * const storageId = localStorage.getItem(ANONYMOUS_ID_KEY)\n * ```\n *\n * @see {@link ANONYMOUS_ID_COOKIE} and {@link ANONYMOUS_ID_KEY} in\n * `@contentful/optimization-core` for the\n * authoritative definition and documentation.\n *\n * @public\n */\nexport { ANONYMOUS_ID_COOKIE, ANONYMOUS_ID_KEY } from '@contentful/optimization-core/constants'\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import {\n CoreStateless,\n type CoreStatelessConfig,\n type EventType,\n} from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\n\nconst DEFAULT_NODE_ALLOWED_EVENT_TYPES: EventType[] = ['identify', 'page']\n\ntype NodeEventBuilderConfig = Partial<Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app'>>\n\n/**\n * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.\n *\n * @remarks\n * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`\n * is intentionally omitted from singleton SDK configuration.\n *\n * @public\n */\nexport type PublicNodeEventBuilderConfig = Partial<\n Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>\n>\n\n/**\n * Configuration for the Node-specific ContentfulOptimization SDK.\n *\n * @remarks\n * This configuration extends {@link CoreStatelessConfig} but allows partial\n * overrides of the event-builder configuration. SDKs commonly inject their own\n * library metadata or channel definitions.\n *\n * @see {@link CoreStatelessConfig}\n *\n * @public\n */\nexport interface OptimizationNodeConfig extends Omit<CoreStatelessConfig, 'eventBuilder'> {\n /**\n * The application definition used to attribute events to a specific consumer app.\n *\n * @remarks\n * When not provided, events will not contain app metadata in their context.\n */\n app?: App\n\n /**\n * Partial overrides for the event builder configuration.\n *\n * @remarks\n * Any provided fields are merged with the default Node SDK metadata.\n * Request-scoped consent should be bound with `forRequest()`, not configured\n * on the SDK singleton.\n *\n * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: PublicNodeEventBuilderConfig\n}\n\n/**\n * Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.\n *\n * @remarks\n * This class adapts the stateless ContentfulOptimization Core for Node runtimes by\n * applying environment-appropriate defaults (e.g., server channel, Node SDK\n * library metadata). No core runtime behavior is modified; only configuration\n * defaults differ.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const sdk = new ContentfulOptimization({\n * clientId: 'abc-123',\n * environment: 'main',\n * logLevel: 'info',\n * })\n *\n * const requestOptimization = sdk.forRequest({\n * consent: true,\n * locale: 'fr-CA',\n * profile: { id: 'profile-id' },\n * })\n *\n * const { accepted, data } = await requestOptimization.page()\n * ```\n *\n * @see {@link CoreStateless}\n *\n * @public\n */\nclass ContentfulOptimization extends CoreStateless {\n /**\n * Create an instance of the Node SDK with merged defaults.\n *\n * @param config - Partial Node-specific configuration. Any eventBuilder\n * fields provided are merged with Node's defaults.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })\n * ```\n */\n constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig) {\n const {\n library,\n getConsent: _getConsent,\n ...eventBuilderConfig\n } = (eventBuilder ?? {}) as NodeEventBuilderConfig\n\n super({\n ...config,\n allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,\n eventBuilder: {\n app,\n channel: 'server',\n library: {\n name: OPTIMIZATION_NODE_SDK_NAME,\n version: OPTIMIZATION_NODE_SDK_VERSION,\n ...library,\n },\n getConsent: () => false,\n ...eventBuilderConfig,\n },\n })\n }\n}\n\nexport default ContentfulOptimization\n","/**\n * Contentful ContentfulOptimization Node SDK.\n *\n * @remarks\n * Adds Node-specific defaults via the {@link ContentfulOptimization} class.\n * Core and transitive API exports are available from dedicated entrypoints:\n * `@contentful/optimization-node/core-sdk`,\n * `@contentful/optimization-node/api-client`,\n * and `@contentful/optimization-node/api-schemas`.\n *\n * @packageDocumentation\n */\n\nimport ContentfulOptimization from './ContentfulOptimization'\n\nexport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\nexport * from './ContentfulOptimization'\n\nexport default ContentfulOptimization\n"],"names":["OPTIMIZATION_NODE_SDK_VERSION","__OPTIMIZATION_VERSION__","OPTIMIZATION_NODE_SDK_NAME","__OPTIMIZATION_PACKAGE_NAME__","__webpack_require__","definition","key","Object","obj","prop","Symbol","DEFAULT_NODE_ALLOWED_EVENT_TYPES","ContentfulOptimization","CoreStateless","app","allowedEventTypes","eventBuilder","config","library","_getConsent","eventBuilderConfig"],"mappings":";;;;;;;;QAYO,MAAMA,gCACoCC;QAS1C,MAAMC,6BAEPC;;;;;;;;;;;;;;ICxBNC,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;ICEA,MAAMI,mCAAgD;QAAC;QAAY;KAAO;IAoF1E,MAAMC,+BAA+BC,kCAAAA,aAAaA;QAchD,YAAY,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGC,QAAgC,CAAE;YACvF,MAAM,EACJC,OAAO,EACP,YAAYC,WAAW,EACvB,GAAGC,oBACJ,GAAIJ,gBAAgB,CAAC;YAEtB,KAAK,CAAC;gBACJ,GAAGC,MAAM;gBACT,mBAAmBF,qBAAqBJ;gBACxC,cAAc;oBACZG;oBACA,SAAS;oBACT,SAAS;wBACP,MAAMZ,UAAAA,0BAA0BA;wBAChC,SAASF,UAAAA,6BAA6BA;wBACtC,GAAGkB,OAAO;oBACZ;oBACA,YAAY,IAAM;oBAClB,GAAGE,kBAAkB;gBACvB;YACF;QACF;IACF;IAEA,mCAAeR;ICjHf,YAAeA"}
package/dist/index.d.cts CHANGED
@@ -34,9 +34,13 @@ import { CoreStatelessConfig } from '@contentful/optimization-core';
34
34
  * logLevel: 'info',
35
35
  * })
36
36
  *
37
- * const requestOptions = { locale: 'en-US' }
37
+ * const requestOptimization = sdk.forRequest({
38
+ * consent: true,
39
+ * locale: 'fr-CA',
40
+ * profile: { id: 'profile-id' },
41
+ * })
38
42
  *
39
- * await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)
43
+ * const { accepted, data } = await requestOptimization.page()
40
44
  * ```
41
45
  *
42
46
  * @see {@link CoreStateless}
@@ -57,7 +61,7 @@ declare class ContentfulOptimization extends CoreStateless {
57
61
  * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })
58
62
  * ```
59
63
  */
60
- constructor(config: OptimizationNodeConfig);
64
+ constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig);
61
65
  }
62
66
  export default ContentfulOptimization;
63
67
 
@@ -104,10 +108,24 @@ export declare interface OptimizationNodeConfig extends Omit<CoreStatelessConfig
104
108
  *
105
109
  * @remarks
106
110
  * Any provided fields are merged with the default Node SDK metadata.
111
+ * Request-scoped consent should be bound with `forRequest()`, not configured
112
+ * on the SDK singleton.
113
+ *
107
114
  * This differs from {@link CoreStatelessConfig} eventBuilder, which expects
108
115
  * a full configuration object.
109
116
  */
110
- eventBuilder?: Partial<Omit<CoreStatelessConfig['eventBuilder'], 'app'>>;
117
+ eventBuilder?: PublicNodeEventBuilderConfig;
111
118
  }
112
119
 
120
+ /**
121
+ * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.
122
+ *
123
+ * @remarks
124
+ * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`
125
+ * is intentionally omitted from singleton SDK configuration.
126
+ *
127
+ * @public
128
+ */
129
+ export declare type PublicNodeEventBuilderConfig = Partial<Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>>;
130
+
113
131
  export { }
package/dist/index.d.mts CHANGED
@@ -34,9 +34,13 @@ import { CoreStatelessConfig } from '@contentful/optimization-core';
34
34
  * logLevel: 'info',
35
35
  * })
36
36
  *
37
- * const requestOptions = { locale: 'en-US' }
37
+ * const requestOptimization = sdk.forRequest({
38
+ * consent: true,
39
+ * locale: 'fr-CA',
40
+ * profile: { id: 'profile-id' },
41
+ * })
38
42
  *
39
- * await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)
43
+ * const { accepted, data } = await requestOptimization.page()
40
44
  * ```
41
45
  *
42
46
  * @see {@link CoreStateless}
@@ -57,7 +61,7 @@ declare class ContentfulOptimization extends CoreStateless {
57
61
  * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })
58
62
  * ```
59
63
  */
60
- constructor(config: OptimizationNodeConfig);
64
+ constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig);
61
65
  }
62
66
  export default ContentfulOptimization;
63
67
 
@@ -104,10 +108,24 @@ export declare interface OptimizationNodeConfig extends Omit<CoreStatelessConfig
104
108
  *
105
109
  * @remarks
106
110
  * Any provided fields are merged with the default Node SDK metadata.
111
+ * Request-scoped consent should be bound with `forRequest()`, not configured
112
+ * on the SDK singleton.
113
+ *
107
114
  * This differs from {@link CoreStatelessConfig} eventBuilder, which expects
108
115
  * a full configuration object.
109
116
  */
110
- eventBuilder?: Partial<Omit<CoreStatelessConfig['eventBuilder'], 'app'>>;
117
+ eventBuilder?: PublicNodeEventBuilderConfig;
111
118
  }
112
119
 
120
+ /**
121
+ * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.
122
+ *
123
+ * @remarks
124
+ * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`
125
+ * is intentionally omitted from singleton SDK configuration.
126
+ *
127
+ * @public
128
+ */
129
+ export declare type PublicNodeEventBuilderConfig = Partial<Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>>;
130
+
113
131
  export { }
package/dist/index.d.ts CHANGED
@@ -34,9 +34,13 @@ import { CoreStatelessConfig } from '@contentful/optimization-core';
34
34
  * logLevel: 'info',
35
35
  * })
36
36
  *
37
- * const requestOptions = { locale: 'en-US' }
37
+ * const requestOptimization = sdk.forRequest({
38
+ * consent: true,
39
+ * locale: 'fr-CA',
40
+ * profile: { id: 'profile-id' },
41
+ * })
38
42
  *
39
- * await sdk.track({ event: 'server_event', properties: { id: 1 } }, requestOptions)
43
+ * const { accepted, data } = await requestOptimization.page()
40
44
  * ```
41
45
  *
42
46
  * @see {@link CoreStateless}
@@ -57,7 +61,7 @@ declare class ContentfulOptimization extends CoreStateless {
57
61
  * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })
58
62
  * ```
59
63
  */
60
- constructor(config: OptimizationNodeConfig);
64
+ constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig);
61
65
  }
62
66
  export default ContentfulOptimization;
63
67
 
@@ -104,10 +108,24 @@ export declare interface OptimizationNodeConfig extends Omit<CoreStatelessConfig
104
108
  *
105
109
  * @remarks
106
110
  * Any provided fields are merged with the default Node SDK metadata.
111
+ * Request-scoped consent should be bound with `forRequest()`, not configured
112
+ * on the SDK singleton.
113
+ *
107
114
  * This differs from {@link CoreStatelessConfig} eventBuilder, which expects
108
115
  * a full configuration object.
109
116
  */
110
- eventBuilder?: Partial<Omit<CoreStatelessConfig['eventBuilder'], 'app'>>;
117
+ eventBuilder?: PublicNodeEventBuilderConfig;
111
118
  }
112
119
 
120
+ /**
121
+ * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.
122
+ *
123
+ * @remarks
124
+ * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`
125
+ * is intentionally omitted from singleton SDK configuration.
126
+ *
127
+ * @public
128
+ */
129
+ export declare type PublicNodeEventBuilderConfig = Partial<Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>>;
130
+
113
131
  export { }
package/dist/index.mjs CHANGED
@@ -1,24 +1,27 @@
1
- import { merge } from "es-toolkit";
2
1
  import { __rspack_external__contentful_optimization_core_7d4758c6 } from "./987.mjs";
3
2
  import { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from "./260.mjs";
4
- function mergeConfig(config) {
5
- const { app, ...restConfig } = config;
6
- const defaultConfig = {
7
- eventBuilder: {
8
- app,
9
- channel: 'server',
10
- library: {
11
- name: OPTIMIZATION_NODE_SDK_NAME,
12
- version: OPTIMIZATION_NODE_SDK_VERSION
13
- }
14
- }
15
- };
16
- return merge(defaultConfig, restConfig);
17
- }
3
+ const DEFAULT_NODE_ALLOWED_EVENT_TYPES = [
4
+ 'identify',
5
+ 'page'
6
+ ];
18
7
  class ContentfulOptimization extends __rspack_external__contentful_optimization_core_7d4758c6.CoreStateless {
19
- constructor(config){
20
- const mergedConfig = mergeConfig(config);
21
- super(mergedConfig);
8
+ constructor({ app, allowedEventTypes, eventBuilder, ...config }){
9
+ const { library, getConsent: _getConsent, ...eventBuilderConfig } = eventBuilder ?? {};
10
+ super({
11
+ ...config,
12
+ allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,
13
+ eventBuilder: {
14
+ app,
15
+ channel: 'server',
16
+ library: {
17
+ name: OPTIMIZATION_NODE_SDK_NAME,
18
+ version: OPTIMIZATION_NODE_SDK_VERSION,
19
+ ...library
20
+ },
21
+ getConsent: ()=>false,
22
+ ...eventBuilderConfig
23
+ }
24
+ });
22
25
  }
23
26
  }
24
27
  const src_ContentfulOptimization = ContentfulOptimization;
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/ContentfulOptimization.ts","../src/index.ts"],"sourcesContent":["import {\n CoreStateless,\n type CoreStatelessConfig,\n type EventType,\n} from '@contentful/optimization-core'\nimport type { App } from '@contentful/optimization-core/api-schemas'\nimport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\n\nconst DEFAULT_NODE_ALLOWED_EVENT_TYPES: EventType[] = ['identify', 'page']\n\ntype NodeEventBuilderConfig = Partial<Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app'>>\n\n/**\n * Public Node event-builder overrides accepted by {@link OptimizationNodeConfig.eventBuilder}.\n *\n * @remarks\n * Request-scoped consent is bound with {@link ContentfulOptimization.forRequest}, so `getConsent`\n * is intentionally omitted from singleton SDK configuration.\n *\n * @public\n */\nexport type PublicNodeEventBuilderConfig = Partial<\n Omit<NonNullable<CoreStatelessConfig['eventBuilder']>, 'app' | 'getConsent'>\n>\n\n/**\n * Configuration for the Node-specific ContentfulOptimization SDK.\n *\n * @remarks\n * This configuration extends {@link CoreStatelessConfig} but allows partial\n * overrides of the event-builder configuration. SDKs commonly inject their own\n * library metadata or channel definitions.\n *\n * @see {@link CoreStatelessConfig}\n *\n * @public\n */\nexport interface OptimizationNodeConfig extends Omit<CoreStatelessConfig, 'eventBuilder'> {\n /**\n * The application definition used to attribute events to a specific consumer app.\n *\n * @remarks\n * When not provided, events will not contain app metadata in their context.\n */\n app?: App\n\n /**\n * Partial overrides for the event builder configuration.\n *\n * @remarks\n * Any provided fields are merged with the default Node SDK metadata.\n * Request-scoped consent should be bound with `forRequest()`, not configured\n * on the SDK singleton.\n *\n * This differs from {@link CoreStatelessConfig} eventBuilder, which expects\n * a full configuration object.\n */\n eventBuilder?: PublicNodeEventBuilderConfig\n}\n\n/**\n * Node-specific ContentfulOptimization SDK built on {@link CoreStateless}.\n *\n * @remarks\n * This class adapts the stateless ContentfulOptimization Core for Node runtimes by\n * applying environment-appropriate defaults (e.g., server channel, Node SDK\n * library metadata). No core runtime behavior is modified; only configuration\n * defaults differ.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const sdk = new ContentfulOptimization({\n * clientId: 'abc-123',\n * environment: 'main',\n * logLevel: 'info',\n * })\n *\n * const requestOptimization = sdk.forRequest({\n * consent: true,\n * locale: 'fr-CA',\n * profile: { id: 'profile-id' },\n * })\n *\n * const { accepted, data } = await requestOptimization.page()\n * ```\n *\n * @see {@link CoreStateless}\n *\n * @public\n */\nclass ContentfulOptimization extends CoreStateless {\n /**\n * Create an instance of the Node SDK with merged defaults.\n *\n * @param config - Partial Node-specific configuration. Any eventBuilder\n * fields provided are merged with Node's defaults.\n *\n * @example\n * ```ts\n * import ContentfulOptimization from '@contentful/optimization-node'\n *\n * const optimization = new ContentfulOptimization({ clientId: 'my-client-id' })\n * ```\n */\n constructor({ app, allowedEventTypes, eventBuilder, ...config }: OptimizationNodeConfig) {\n const {\n library,\n getConsent: _getConsent,\n ...eventBuilderConfig\n } = (eventBuilder ?? {}) as NodeEventBuilderConfig\n\n super({\n ...config,\n allowedEventTypes: allowedEventTypes ?? DEFAULT_NODE_ALLOWED_EVENT_TYPES,\n eventBuilder: {\n app,\n channel: 'server',\n library: {\n name: OPTIMIZATION_NODE_SDK_NAME,\n version: OPTIMIZATION_NODE_SDK_VERSION,\n ...library,\n },\n getConsent: () => false,\n ...eventBuilderConfig,\n },\n })\n }\n}\n\nexport default ContentfulOptimization\n","/**\n * Contentful ContentfulOptimization Node SDK.\n *\n * @remarks\n * Adds Node-specific defaults via the {@link ContentfulOptimization} class.\n * Core and transitive API exports are available from dedicated entrypoints:\n * `@contentful/optimization-node/core-sdk`,\n * `@contentful/optimization-node/api-client`,\n * and `@contentful/optimization-node/api-schemas`.\n *\n * @packageDocumentation\n */\n\nimport ContentfulOptimization from './ContentfulOptimization'\n\nexport { OPTIMIZATION_NODE_SDK_NAME, OPTIMIZATION_NODE_SDK_VERSION } from './constants'\nexport * from './ContentfulOptimization'\n\nexport default ContentfulOptimization\n"],"names":["DEFAULT_NODE_ALLOWED_EVENT_TYPES","ContentfulOptimization","CoreStateless","app","allowedEventTypes","eventBuilder","config","library","_getConsent","eventBuilderConfig","OPTIMIZATION_NODE_SDK_NAME","OPTIMIZATION_NODE_SDK_VERSION"],"mappings":";;AAQA,MAAMA,mCAAgD;IAAC;IAAY;CAAO;AAoF1E,MAAMC,+BAA+BC,yDAAAA,aAAaA;IAchD,YAAY,EAAEC,GAAG,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGC,QAAgC,CAAE;QACvF,MAAM,EACJC,OAAO,EACP,YAAYC,WAAW,EACvB,GAAGC,oBACJ,GAAIJ,gBAAgB,CAAC;QAEtB,KAAK,CAAC;YACJ,GAAGC,MAAM;YACT,mBAAmBF,qBAAqBJ;YACxC,cAAc;gBACZG;gBACA,SAAS;gBACT,SAAS;oBACP,MAAMO;oBACN,SAASC;oBACT,GAAGJ,OAAO;gBACZ;gBACA,YAAY,IAAM;gBAClB,GAAGE,kBAAkB;YACvB;QACF;IACF;AACF;AAEA,mCAAeR;ACjHf,YAAeA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/optimization-node",
3
- "version": "0.1.0-alpha13",
3
+ "version": "0.1.0-alpha15",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -75,18 +75,19 @@
75
75
  "./package.json": "./package.json"
76
76
  },
77
77
  "files": [
78
- "dist/**/*"
78
+ "dist/**/*",
79
+ "THIRD_PARTY_NOTICES.txt"
79
80
  ],
80
81
  "buildTools": {
81
82
  "bundleSize": {
82
83
  "gzipBudgets": {
83
- "index.cjs": 1200,
84
- "index.mjs": 500
84
+ "index.cjs": 2000,
85
+ "index.mjs": 1500
85
86
  }
86
87
  }
87
88
  },
88
89
  "dependencies": {
89
90
  "es-toolkit": "^1.45.1",
90
- "@contentful/optimization-core": "0.1.0-alpha13"
91
+ "@contentful/optimization-core": "0.1.0-alpha15"
91
92
  }
92
93
  }