personalize-connect-sdk 1.1.0 → 1.2.1

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/index.d.mts CHANGED
@@ -24,13 +24,13 @@ interface PersonalizeConnectConfig {
24
24
  interface PersonalizeConnectResponse {
25
25
  contentKey: string;
26
26
  }
27
- /** What the SDK sends to Personalize /v2/callFlows */
27
+ /** What the SDK sends to Personalize /v2/callFlows (legacy direct mode) */
28
28
  interface CallFlowsRequest {
29
- clientKey: string;
29
+ clientKey?: string;
30
30
  channel: string;
31
31
  language: string;
32
32
  currencyCode: string;
33
- pointOfSale: string;
33
+ pointOfSale?: string;
34
34
  browserId: string;
35
35
  friendlyId: string;
36
36
  params?: {
@@ -41,20 +41,30 @@ interface CallFlowsRequest {
41
41
  }
42
42
  /** Provider configuration */
43
43
  interface PersonalizeConnectProviderProps {
44
- clientKey: string;
45
- pointOfSale: string;
44
+ /** Sitecore Edge Context ID. When provided, all calls route through the Edge proxy. */
45
+ sitecoreEdgeContextId?: string;
46
+ /** Edge platform base URL. Defaults to https://edge-platform.sitecorecloud.io */
47
+ sitecoreEdgeUrl?: string;
48
+ /** XM Cloud site name, used with Context ID for personalize and init calls. */
49
+ siteName?: string;
50
+ /** Personalize API client key (legacy mode). Not needed when using sitecoreEdgeContextId. */
51
+ clientKey?: string;
52
+ /** Point of sale identifier (legacy mode). Not needed when using sitecoreEdgeContextId. */
53
+ pointOfSale?: string;
54
+ /** Experience Edge GraphQL endpoint for direct access (legacy). Not needed with Context ID. */
55
+ edgeUrl?: string;
56
+ /** Sitecore API key for Experience Edge (legacy). Not needed with Context ID. */
57
+ apiKey?: string;
46
58
  channel?: string;
47
59
  language?: string;
48
60
  currencyCode?: string;
49
61
  timeout?: number;
50
- /** Custom function to fetch datasource fields by item ID. When omitted and edgeUrl + apiKey are set, the SDK resolves via Experience Edge. */
62
+ /** Custom function to fetch datasource fields by item ID. When omitted the SDK resolves via Edge. */
51
63
  resolveDatasource?: (datasourceId: string) => Promise<ComponentFields>;
52
- /** Experience Edge GraphQL endpoint (e.g. GRAPH_QL_ENDPOINT). Enables built-in datasource resolution when resolveDatasource is not provided. */
53
- edgeUrl?: string;
54
- /** Sitecore API key for Experience Edge (e.g. SITECORE_API_KEY). Required alongside edgeUrl for built-in resolution. */
55
- apiKey?: string;
56
- /** Override editing mode detection. When true the HOC renders a visual indicator. When omitted the SDK auto-detects Page Builder / Experience Editor. */
64
+ /** Override editing mode detection. When true the HOC renders a visual indicator. */
57
65
  isEditing?: boolean;
66
+ /** Enable debug logging to the browser console. */
67
+ debug?: boolean;
58
68
  children: ReactNode;
59
69
  }
60
70
  /** Resolved datasource fields passed as component props */
@@ -70,30 +80,34 @@ interface PersonalizeContextValue {
70
80
  browserId: string;
71
81
  resolveDatasource: (datasourceId: string) => Promise<ComponentFields>;
72
82
  isEditing: boolean;
83
+ /** True when operating in Edge Context ID mode */
84
+ useEdgeProxy: boolean;
85
+ /** Edge proxy base URL (only set in Context ID mode) */
86
+ edgeProxyUrl: string;
87
+ /** Context ID (only set in Context ID mode) */
88
+ sitecoreEdgeContextId: string;
89
+ /** Site name (only set in Context ID mode) */
90
+ siteName: string;
73
91
  }
74
92
 
75
- declare function PersonalizeProvider({ children, clientKey, pointOfSale, channel, language, currencyCode, timeout, resolveDatasource, edgeUrl, apiKey, isEditing: isEditingProp, }: PersonalizeConnectProviderProps): react_jsx_runtime.JSX.Element;
93
+ declare function PersonalizeProvider({ children, sitecoreEdgeContextId, sitecoreEdgeUrl, siteName, clientKey, pointOfSale, edgeUrl, apiKey, channel, language, currencyCode, timeout, resolveDatasource, isEditing: isEditingProp, debug, }: PersonalizeConnectProviderProps): react_jsx_runtime.JSX.Element;
76
94
  declare function usePersonalizeContext(): PersonalizeContextValue | null;
77
95
 
78
96
  /**
79
- * Thin async wrapper around POST /v2/callFlows.
80
- * Enforces timeout, parses response, validates contentKey.
97
+ * Calls Sitecore Personalize to resolve the active content key.
98
+ *
99
+ * Legacy mode: POST https://api.boxever.com/v2/callFlows
100
+ * Context ID: POST {edgeUrl}/v1/personalize?sitecoreContextId=...&siteName=...
81
101
  */
82
102
 
83
103
  interface CallPersonalizeOptions {
84
104
  config: PersonalizeConnectConfig;
85
105
  context: PersonalizeContextValue;
86
- /** Optional: override API base URL (e.g. region-specific) */
106
+ /** Override API base URL (legacy mode only) */
87
107
  apiBase?: string;
88
- /** Optional: component ref for params */
89
108
  componentRef?: string;
90
- /** Optional: page route for params */
91
109
  pageRoute?: string;
92
110
  }
93
- /**
94
- * Call Personalize /v2/callFlows to get the active content key.
95
- * Returns the contentKey on success, null on any failure.
96
- */
97
111
  declare function callPersonalize(options: CallPersonalizeOptions): Promise<string | null>;
98
112
 
99
113
  /**
@@ -119,13 +133,13 @@ declare function resolveContent(options: ResolveContentOptions): Promise<Resolve
119
133
 
120
134
  type GetConfigFromProps<P> = (props: P) => PersonalizeConnectConfig | undefined;
121
135
  /**
122
- * HOC that wraps any JSS/Content SDK component.
136
+ * HOC that wraps any JSS component.
123
137
  * If the rendering has a personalizeConnect config, it renders with defaultKey first,
124
138
  * then asynchronously fetches the personalized content and re-renders.
125
139
  * If no config, passes through unchanged.
126
140
  *
127
- * In editing mode (Page Builder / Experience Editor), renders a visual
128
- * indicator (border + badge) on components that have personalization configured.
141
+ * In Page Builder, renders a visual indicator (border + badge) on
142
+ * components that have personalization configured.
129
143
  */
130
144
  declare function withPersonalizeConnect<P extends object>(WrappedComponent: ComponentType<P>, getConfig?: GetConfigFromProps<P>): ComponentType<P>;
131
145
 
@@ -143,36 +157,63 @@ declare function usePersonalizeExperience(config: PersonalizeConnectConfig | und
143
157
 
144
158
  /**
145
159
  * Built-in Experience Edge datasource resolver.
146
- * Queries Experience Edge GraphQL by item GUID, returns fields in JSS shape.
160
+ *
161
+ * Legacy mode: Direct Edge GraphQL with sc_apikey header.
162
+ * Context ID mode: Edge proxy GraphQL — Context ID is the auth, no API key needed.
147
163
  */
148
164
 
149
165
  /**
150
- * Creates a datasource resolver backed by Experience Edge GraphQL.
151
- * When passed as (or used in place of) `resolveDatasource`, allows the SDK
152
- * to fetch datasource fields without the consuming app providing any resolver.
166
+ * Legacy: creates a resolver that calls Experience Edge directly with an API key.
153
167
  */
154
168
  declare function createEdgeResolver(edgeUrl: string, apiKey: string, language?: string): (datasourceId: string) => Promise<ComponentFields>;
169
+ /**
170
+ * Context ID mode: creates a resolver that calls the Edge proxy GraphQL endpoint.
171
+ * No API key header — the Context ID in the URL is the auth.
172
+ */
173
+ declare function createEdgeProxyResolver(edgeBaseUrl: string, contextId: string, language?: string): (datasourceId: string) => Promise<ComponentFields>;
155
174
 
156
175
  /**
157
- * Lightweight Sitecore editing mode detection.
158
- * Works in Experience Editor and XM Cloud Pages without importing JSS.
176
+ * XM Cloud Pages (Page Builder) editing mode detection.
177
+ * Uses the same Sitecore context shape that JSS for XMC writes to __NEXT_DATA__.
159
178
  */
160
179
  /**
161
- * Detects whether the page is currently rendered inside a Sitecore editor
162
- * (Experience Editor or XM Cloud Pages). Result is cached after the first call.
180
+ * Detects whether the page is rendered inside XM Cloud Pages (Page Builder).
181
+ * Checks the JSS Sitecore context for pageEditing / pageState, and whether
182
+ * the rendering host is loaded in an iframe (Pages always iframes the site).
183
+ * Result is cached after the first call.
163
184
  */
164
185
  declare function isEditingMode(): boolean;
165
186
  /** Reset the cached result (useful for testing). */
166
187
  declare function resetEditingDetectionCache(): void;
167
188
 
168
189
  /**
169
- * Manages the Sitecore CDP browser ID cookie (bid_<clientKey>).
170
- * Used for session continuity across Personalize decisions.
190
+ * SDK debug logger. All output is prefixed with [PersonalizeConnect].
191
+ * Enable by passing debug={true} on PersonalizeProvider.
171
192
  */
193
+ declare function setDebug(on: boolean): void;
194
+ declare function isDebugEnabled(): boolean;
195
+
172
196
  /**
173
- * Get or create the browser ID for the given client key.
174
- * Reads from cookie bid_<clientKey>, writes if missing, and returns the value.
197
+ * Manages the Sitecore CDP browser ID.
198
+ *
199
+ * Legacy mode: cookie bid_<clientKey>, generated locally.
200
+ * Context ID mode: fetched from Edge proxy /v1/init, stored in cookie sc_<contextId>_personalize.
201
+ */
202
+ /**
203
+ * Legacy: get or create browser ID from a local cookie keyed by clientKey.
175
204
  */
176
205
  declare function getBrowserId(clientKey: string): string;
206
+ /** Response shape from the Edge proxy /v1/init endpoint */
207
+ interface EdgeInitResponse {
208
+ browserId: string;
209
+ guestId?: string;
210
+ }
211
+ /**
212
+ * Context ID mode: fetch browser ID from the Edge proxy init endpoint.
213
+ * Checks cookie first; if missing, calls /v1/init and caches the result.
214
+ */
215
+ declare function getEdgeBrowserId(edgeUrl: string, contextId: string, siteName: string): Promise<string>;
216
+ /** Reset the cached init promise (for testing). */
217
+ declare function resetEdgeInitCache(): void;
177
218
 
178
- export { type CallFlowsRequest, type CallPersonalizeOptions, type ComponentFields, type GetConfigFromProps, type PersonalizeConnectConfig, type PersonalizeConnectProviderProps, type PersonalizeConnectResponse, type PersonalizeContextValue, PersonalizeProvider, type ResolveContentOptions, type ResolvedContent, type UsePersonalizeExperienceResult, callPersonalize, createEdgeResolver, getBrowserId, isEditingMode, resetEditingDetectionCache, resolveContent, usePersonalizeContext, usePersonalizeExperience, withPersonalizeConnect };
219
+ export { type CallFlowsRequest, type CallPersonalizeOptions, type ComponentFields, type EdgeInitResponse, type GetConfigFromProps, type PersonalizeConnectConfig, type PersonalizeConnectProviderProps, type PersonalizeConnectResponse, type PersonalizeContextValue, PersonalizeProvider, type ResolveContentOptions, type ResolvedContent, type UsePersonalizeExperienceResult, callPersonalize, createEdgeProxyResolver, createEdgeResolver, getBrowserId, getEdgeBrowserId, isDebugEnabled, isEditingMode, resetEdgeInitCache, resetEditingDetectionCache, resolveContent, setDebug, usePersonalizeContext, usePersonalizeExperience, withPersonalizeConnect };
package/dist/index.d.ts CHANGED
@@ -24,13 +24,13 @@ interface PersonalizeConnectConfig {
24
24
  interface PersonalizeConnectResponse {
25
25
  contentKey: string;
26
26
  }
27
- /** What the SDK sends to Personalize /v2/callFlows */
27
+ /** What the SDK sends to Personalize /v2/callFlows (legacy direct mode) */
28
28
  interface CallFlowsRequest {
29
- clientKey: string;
29
+ clientKey?: string;
30
30
  channel: string;
31
31
  language: string;
32
32
  currencyCode: string;
33
- pointOfSale: string;
33
+ pointOfSale?: string;
34
34
  browserId: string;
35
35
  friendlyId: string;
36
36
  params?: {
@@ -41,20 +41,30 @@ interface CallFlowsRequest {
41
41
  }
42
42
  /** Provider configuration */
43
43
  interface PersonalizeConnectProviderProps {
44
- clientKey: string;
45
- pointOfSale: string;
44
+ /** Sitecore Edge Context ID. When provided, all calls route through the Edge proxy. */
45
+ sitecoreEdgeContextId?: string;
46
+ /** Edge platform base URL. Defaults to https://edge-platform.sitecorecloud.io */
47
+ sitecoreEdgeUrl?: string;
48
+ /** XM Cloud site name, used with Context ID for personalize and init calls. */
49
+ siteName?: string;
50
+ /** Personalize API client key (legacy mode). Not needed when using sitecoreEdgeContextId. */
51
+ clientKey?: string;
52
+ /** Point of sale identifier (legacy mode). Not needed when using sitecoreEdgeContextId. */
53
+ pointOfSale?: string;
54
+ /** Experience Edge GraphQL endpoint for direct access (legacy). Not needed with Context ID. */
55
+ edgeUrl?: string;
56
+ /** Sitecore API key for Experience Edge (legacy). Not needed with Context ID. */
57
+ apiKey?: string;
46
58
  channel?: string;
47
59
  language?: string;
48
60
  currencyCode?: string;
49
61
  timeout?: number;
50
- /** Custom function to fetch datasource fields by item ID. When omitted and edgeUrl + apiKey are set, the SDK resolves via Experience Edge. */
62
+ /** Custom function to fetch datasource fields by item ID. When omitted the SDK resolves via Edge. */
51
63
  resolveDatasource?: (datasourceId: string) => Promise<ComponentFields>;
52
- /** Experience Edge GraphQL endpoint (e.g. GRAPH_QL_ENDPOINT). Enables built-in datasource resolution when resolveDatasource is not provided. */
53
- edgeUrl?: string;
54
- /** Sitecore API key for Experience Edge (e.g. SITECORE_API_KEY). Required alongside edgeUrl for built-in resolution. */
55
- apiKey?: string;
56
- /** Override editing mode detection. When true the HOC renders a visual indicator. When omitted the SDK auto-detects Page Builder / Experience Editor. */
64
+ /** Override editing mode detection. When true the HOC renders a visual indicator. */
57
65
  isEditing?: boolean;
66
+ /** Enable debug logging to the browser console. */
67
+ debug?: boolean;
58
68
  children: ReactNode;
59
69
  }
60
70
  /** Resolved datasource fields passed as component props */
@@ -70,30 +80,34 @@ interface PersonalizeContextValue {
70
80
  browserId: string;
71
81
  resolveDatasource: (datasourceId: string) => Promise<ComponentFields>;
72
82
  isEditing: boolean;
83
+ /** True when operating in Edge Context ID mode */
84
+ useEdgeProxy: boolean;
85
+ /** Edge proxy base URL (only set in Context ID mode) */
86
+ edgeProxyUrl: string;
87
+ /** Context ID (only set in Context ID mode) */
88
+ sitecoreEdgeContextId: string;
89
+ /** Site name (only set in Context ID mode) */
90
+ siteName: string;
73
91
  }
74
92
 
75
- declare function PersonalizeProvider({ children, clientKey, pointOfSale, channel, language, currencyCode, timeout, resolveDatasource, edgeUrl, apiKey, isEditing: isEditingProp, }: PersonalizeConnectProviderProps): react_jsx_runtime.JSX.Element;
93
+ declare function PersonalizeProvider({ children, sitecoreEdgeContextId, sitecoreEdgeUrl, siteName, clientKey, pointOfSale, edgeUrl, apiKey, channel, language, currencyCode, timeout, resolveDatasource, isEditing: isEditingProp, debug, }: PersonalizeConnectProviderProps): react_jsx_runtime.JSX.Element;
76
94
  declare function usePersonalizeContext(): PersonalizeContextValue | null;
77
95
 
78
96
  /**
79
- * Thin async wrapper around POST /v2/callFlows.
80
- * Enforces timeout, parses response, validates contentKey.
97
+ * Calls Sitecore Personalize to resolve the active content key.
98
+ *
99
+ * Legacy mode: POST https://api.boxever.com/v2/callFlows
100
+ * Context ID: POST {edgeUrl}/v1/personalize?sitecoreContextId=...&siteName=...
81
101
  */
82
102
 
83
103
  interface CallPersonalizeOptions {
84
104
  config: PersonalizeConnectConfig;
85
105
  context: PersonalizeContextValue;
86
- /** Optional: override API base URL (e.g. region-specific) */
106
+ /** Override API base URL (legacy mode only) */
87
107
  apiBase?: string;
88
- /** Optional: component ref for params */
89
108
  componentRef?: string;
90
- /** Optional: page route for params */
91
109
  pageRoute?: string;
92
110
  }
93
- /**
94
- * Call Personalize /v2/callFlows to get the active content key.
95
- * Returns the contentKey on success, null on any failure.
96
- */
97
111
  declare function callPersonalize(options: CallPersonalizeOptions): Promise<string | null>;
98
112
 
99
113
  /**
@@ -119,13 +133,13 @@ declare function resolveContent(options: ResolveContentOptions): Promise<Resolve
119
133
 
120
134
  type GetConfigFromProps<P> = (props: P) => PersonalizeConnectConfig | undefined;
121
135
  /**
122
- * HOC that wraps any JSS/Content SDK component.
136
+ * HOC that wraps any JSS component.
123
137
  * If the rendering has a personalizeConnect config, it renders with defaultKey first,
124
138
  * then asynchronously fetches the personalized content and re-renders.
125
139
  * If no config, passes through unchanged.
126
140
  *
127
- * In editing mode (Page Builder / Experience Editor), renders a visual
128
- * indicator (border + badge) on components that have personalization configured.
141
+ * In Page Builder, renders a visual indicator (border + badge) on
142
+ * components that have personalization configured.
129
143
  */
130
144
  declare function withPersonalizeConnect<P extends object>(WrappedComponent: ComponentType<P>, getConfig?: GetConfigFromProps<P>): ComponentType<P>;
131
145
 
@@ -143,36 +157,63 @@ declare function usePersonalizeExperience(config: PersonalizeConnectConfig | und
143
157
 
144
158
  /**
145
159
  * Built-in Experience Edge datasource resolver.
146
- * Queries Experience Edge GraphQL by item GUID, returns fields in JSS shape.
160
+ *
161
+ * Legacy mode: Direct Edge GraphQL with sc_apikey header.
162
+ * Context ID mode: Edge proxy GraphQL — Context ID is the auth, no API key needed.
147
163
  */
148
164
 
149
165
  /**
150
- * Creates a datasource resolver backed by Experience Edge GraphQL.
151
- * When passed as (or used in place of) `resolveDatasource`, allows the SDK
152
- * to fetch datasource fields without the consuming app providing any resolver.
166
+ * Legacy: creates a resolver that calls Experience Edge directly with an API key.
153
167
  */
154
168
  declare function createEdgeResolver(edgeUrl: string, apiKey: string, language?: string): (datasourceId: string) => Promise<ComponentFields>;
169
+ /**
170
+ * Context ID mode: creates a resolver that calls the Edge proxy GraphQL endpoint.
171
+ * No API key header — the Context ID in the URL is the auth.
172
+ */
173
+ declare function createEdgeProxyResolver(edgeBaseUrl: string, contextId: string, language?: string): (datasourceId: string) => Promise<ComponentFields>;
155
174
 
156
175
  /**
157
- * Lightweight Sitecore editing mode detection.
158
- * Works in Experience Editor and XM Cloud Pages without importing JSS.
176
+ * XM Cloud Pages (Page Builder) editing mode detection.
177
+ * Uses the same Sitecore context shape that JSS for XMC writes to __NEXT_DATA__.
159
178
  */
160
179
  /**
161
- * Detects whether the page is currently rendered inside a Sitecore editor
162
- * (Experience Editor or XM Cloud Pages). Result is cached after the first call.
180
+ * Detects whether the page is rendered inside XM Cloud Pages (Page Builder).
181
+ * Checks the JSS Sitecore context for pageEditing / pageState, and whether
182
+ * the rendering host is loaded in an iframe (Pages always iframes the site).
183
+ * Result is cached after the first call.
163
184
  */
164
185
  declare function isEditingMode(): boolean;
165
186
  /** Reset the cached result (useful for testing). */
166
187
  declare function resetEditingDetectionCache(): void;
167
188
 
168
189
  /**
169
- * Manages the Sitecore CDP browser ID cookie (bid_<clientKey>).
170
- * Used for session continuity across Personalize decisions.
190
+ * SDK debug logger. All output is prefixed with [PersonalizeConnect].
191
+ * Enable by passing debug={true} on PersonalizeProvider.
171
192
  */
193
+ declare function setDebug(on: boolean): void;
194
+ declare function isDebugEnabled(): boolean;
195
+
172
196
  /**
173
- * Get or create the browser ID for the given client key.
174
- * Reads from cookie bid_<clientKey>, writes if missing, and returns the value.
197
+ * Manages the Sitecore CDP browser ID.
198
+ *
199
+ * Legacy mode: cookie bid_<clientKey>, generated locally.
200
+ * Context ID mode: fetched from Edge proxy /v1/init, stored in cookie sc_<contextId>_personalize.
201
+ */
202
+ /**
203
+ * Legacy: get or create browser ID from a local cookie keyed by clientKey.
175
204
  */
176
205
  declare function getBrowserId(clientKey: string): string;
206
+ /** Response shape from the Edge proxy /v1/init endpoint */
207
+ interface EdgeInitResponse {
208
+ browserId: string;
209
+ guestId?: string;
210
+ }
211
+ /**
212
+ * Context ID mode: fetch browser ID from the Edge proxy init endpoint.
213
+ * Checks cookie first; if missing, calls /v1/init and caches the result.
214
+ */
215
+ declare function getEdgeBrowserId(edgeUrl: string, contextId: string, siteName: string): Promise<string>;
216
+ /** Reset the cached init promise (for testing). */
217
+ declare function resetEdgeInitCache(): void;
177
218
 
178
- export { type CallFlowsRequest, type CallPersonalizeOptions, type ComponentFields, type GetConfigFromProps, type PersonalizeConnectConfig, type PersonalizeConnectProviderProps, type PersonalizeConnectResponse, type PersonalizeContextValue, PersonalizeProvider, type ResolveContentOptions, type ResolvedContent, type UsePersonalizeExperienceResult, callPersonalize, createEdgeResolver, getBrowserId, isEditingMode, resetEditingDetectionCache, resolveContent, usePersonalizeContext, usePersonalizeExperience, withPersonalizeConnect };
219
+ export { type CallFlowsRequest, type CallPersonalizeOptions, type ComponentFields, type EdgeInitResponse, type GetConfigFromProps, type PersonalizeConnectConfig, type PersonalizeConnectProviderProps, type PersonalizeConnectResponse, type PersonalizeContextValue, PersonalizeProvider, type ResolveContentOptions, type ResolvedContent, type UsePersonalizeExperienceResult, callPersonalize, createEdgeProxyResolver, createEdgeResolver, getBrowserId, getEdgeBrowserId, isDebugEnabled, isEditingMode, resetEdgeInitCache, resetEditingDetectionCache, resolveContent, setDebug, usePersonalizeContext, usePersonalizeExperience, withPersonalizeConnect };