@amplifyup/sdk 0.1.22 → 0.1.23
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 +65 -38
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +111 -14
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +111 -14
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +117 -6
- package/dist/index.d.ts +117 -6
- package/dist/index.js +285 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +280 -15
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +5 -3
- package/dist/react.d.ts +5 -3
- package/dist/react.js +350 -42
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +350 -42
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +26 -8
- package/dist/server.d.ts +26 -8
- package/dist/server.js +277 -20
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +277 -21
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Cy5aWQ5c.d.mts → types-BxpG9Gsy.d.mts} +37 -2
- package/dist/{types-Cy5aWQ5c.d.ts → types-BxpG9Gsy.d.ts} +37 -2
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { P as PageConfig,
|
|
4
|
-
export { Z as ZoneConfig } from './types-
|
|
3
|
+
import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-BxpG9Gsy.mjs';
|
|
4
|
+
export { Z as ZoneConfig } from './types-BxpG9Gsy.mjs';
|
|
5
5
|
export { AmplifyRenderer } from './AmplifyRenderer.mjs';
|
|
6
6
|
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
|
|
7
7
|
export { fetchPageConfigServer } from './server.mjs';
|
|
@@ -115,6 +115,8 @@ interface AmplifyUpContextType {
|
|
|
115
115
|
pageConfig: PageConfig | null;
|
|
116
116
|
loading: boolean;
|
|
117
117
|
error: string | null;
|
|
118
|
+
source: ContentSource | null;
|
|
119
|
+
meta: AmplifyContentMeta | null;
|
|
118
120
|
}
|
|
119
121
|
interface AmplifyUpProviderProps {
|
|
120
122
|
children: ReactNode;
|
|
@@ -123,4 +125,4 @@ interface AmplifyUpProviderProps {
|
|
|
123
125
|
declare function AmplifyUpProvider({ children, config }: AmplifyUpProviderProps): react_jsx_runtime.JSX.Element;
|
|
124
126
|
declare function useAmplifyUp(): AmplifyUpContextType;
|
|
125
127
|
|
|
126
|
-
export {
|
|
128
|
+
export { AmplifyContentMeta, AmplifyPageContent, AmplifyUpProvider, ComponentContextProvider, ContentSource, Field, PageConfig, Slot, useAmplifyUp };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { P as PageConfig,
|
|
4
|
-
export { Z as ZoneConfig } from './types-
|
|
3
|
+
import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-BxpG9Gsy.js';
|
|
4
|
+
export { Z as ZoneConfig } from './types-BxpG9Gsy.js';
|
|
5
5
|
export { AmplifyRenderer } from './AmplifyRenderer.js';
|
|
6
6
|
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
|
|
7
7
|
export { fetchPageConfigServer } from './server.js';
|
|
@@ -115,6 +115,8 @@ interface AmplifyUpContextType {
|
|
|
115
115
|
pageConfig: PageConfig | null;
|
|
116
116
|
loading: boolean;
|
|
117
117
|
error: string | null;
|
|
118
|
+
source: ContentSource | null;
|
|
119
|
+
meta: AmplifyContentMeta | null;
|
|
118
120
|
}
|
|
119
121
|
interface AmplifyUpProviderProps {
|
|
120
122
|
children: ReactNode;
|
|
@@ -123,4 +125,4 @@ interface AmplifyUpProviderProps {
|
|
|
123
125
|
declare function AmplifyUpProvider({ children, config }: AmplifyUpProviderProps): react_jsx_runtime.JSX.Element;
|
|
124
126
|
declare function useAmplifyUp(): AmplifyUpContextType;
|
|
125
127
|
|
|
126
|
-
export {
|
|
128
|
+
export { AmplifyContentMeta, AmplifyPageContent, AmplifyUpProvider, ComponentContextProvider, ContentSource, Field, PageConfig, Slot, useAmplifyUp };
|
package/dist/react.js
CHANGED
|
@@ -153,17 +153,42 @@ var AWSAdapter = class {
|
|
|
153
153
|
};
|
|
154
154
|
this.sendEvent("/v1/track", eventData);
|
|
155
155
|
}
|
|
156
|
-
identify(
|
|
156
|
+
identify(userIdOrIdentifiers, traits = {}) {
|
|
157
157
|
if (!this.initialized) {
|
|
158
158
|
console.warn("AmplifyUp SDK: Not initialized. Call init() first.");
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
+
const isMap = userIdOrIdentifiers !== null && typeof userIdOrIdentifiers === "object" && !Array.isArray(userIdOrIdentifiers);
|
|
162
|
+
const identifiers = isMap ? userIdOrIdentifiers : traits.identifiers;
|
|
163
|
+
const userId = isMap ? void 0 : String(userIdOrIdentifiers);
|
|
161
164
|
const eventData = {
|
|
162
165
|
type: "identify",
|
|
163
|
-
userId,
|
|
164
166
|
anonymousId: traits.instanceId,
|
|
165
167
|
traits: {
|
|
166
|
-
...traits
|
|
168
|
+
...traits,
|
|
169
|
+
...identifiers ? { identifiers } : {}
|
|
170
|
+
},
|
|
171
|
+
...identifiers ? { identifiers } : {},
|
|
172
|
+
...userId ? { userId } : {},
|
|
173
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
174
|
+
};
|
|
175
|
+
this.sendEvent("/v1/track", eventData);
|
|
176
|
+
}
|
|
177
|
+
setProfileFields(fields, context = {}) {
|
|
178
|
+
if (!this.initialized) {
|
|
179
|
+
console.warn("AmplifyUp SDK: Not initialized. Call init() first.");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const eventData = {
|
|
183
|
+
type: "set_fields",
|
|
184
|
+
anonymousId: context.instanceId,
|
|
185
|
+
fields,
|
|
186
|
+
traits: {
|
|
187
|
+
instanceId: context.instanceId,
|
|
188
|
+
trackingId: context.trackingId
|
|
189
|
+
},
|
|
190
|
+
properties: {
|
|
191
|
+
trackingId: context.trackingId
|
|
167
192
|
},
|
|
168
193
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
169
194
|
};
|
|
@@ -225,6 +250,7 @@ function clearIds() {
|
|
|
225
250
|
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
226
251
|
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
227
252
|
var PROD_ORCHESTRATOR = "https://amplifyup.ai";
|
|
253
|
+
var PROD_EDGE = "https://edge.amplifyup.ai";
|
|
228
254
|
function isAmplifyUpTarget(value) {
|
|
229
255
|
return value === "local" || value === "dev" || value === "production";
|
|
230
256
|
}
|
|
@@ -260,6 +286,10 @@ function localAwsApiUrl() {
|
|
|
260
286
|
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL : void 0;
|
|
261
287
|
return (fromEnv || AWS_DEV_API).replace(/\/$/, "");
|
|
262
288
|
}
|
|
289
|
+
function localEdgeUrl() {
|
|
290
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_EDGE_URL : void 0;
|
|
291
|
+
return (fromEnv || "http://localhost:8787").replace(/\/$/, "");
|
|
292
|
+
}
|
|
263
293
|
function resolveAmplifyUpUrls(target) {
|
|
264
294
|
if (target === "local") {
|
|
265
295
|
const orchestratorUrl2 = localOrchestratorUrl();
|
|
@@ -270,18 +300,22 @@ function resolveAmplifyUpUrls(target) {
|
|
|
270
300
|
orchestratorUrl: orchestratorUrl2,
|
|
271
301
|
// Events + personalize → AWS development stack
|
|
272
302
|
apiGatewayUrl,
|
|
273
|
-
decisionApiUrl: `${apiGatewayUrl}/v1/personalize
|
|
303
|
+
decisionApiUrl: `${apiGatewayUrl}/v1/personalize`,
|
|
304
|
+
edgeUrl: localEdgeUrl()
|
|
274
305
|
};
|
|
275
306
|
}
|
|
276
307
|
const resolvedApi = typeof process !== "undefined" && process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL?.replace(/\/$/, "") || AWS_PROD_API;
|
|
277
308
|
const orchestratorFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
278
309
|
const isLocalOrchestrator = !!orchestratorFromEnv && (orchestratorFromEnv.includes("localhost") || orchestratorFromEnv.includes("127.0.0.1"));
|
|
279
310
|
const orchestratorUrl = isLocalOrchestrator || !orchestratorFromEnv ? PROD_ORCHESTRATOR : orchestratorFromEnv.replace(/\/$/, "");
|
|
311
|
+
const edgeFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_EDGE_URL?.replace(/\/$/, "") : void 0;
|
|
312
|
+
const edgeUrl = edgeFromEnv && !edgeFromEnv.includes("localhost") && !edgeFromEnv.includes("127.0.0.1") ? edgeFromEnv : PROD_EDGE;
|
|
280
313
|
return {
|
|
281
314
|
target: "production",
|
|
282
315
|
apiGatewayUrl: resolvedApi,
|
|
283
316
|
orchestratorUrl,
|
|
284
|
-
decisionApiUrl: `${resolvedApi}/v1/personalize
|
|
317
|
+
decisionApiUrl: `${resolvedApi}/v1/personalize`,
|
|
318
|
+
edgeUrl
|
|
285
319
|
};
|
|
286
320
|
}
|
|
287
321
|
|
|
@@ -311,6 +345,177 @@ function isComposerPreview() {
|
|
|
311
345
|
return false;
|
|
312
346
|
}
|
|
313
347
|
|
|
348
|
+
// src/edge/normalizeRoute.ts
|
|
349
|
+
function normalizeRoute(route) {
|
|
350
|
+
let path = String(route || "").trim();
|
|
351
|
+
if (!path) return "/";
|
|
352
|
+
try {
|
|
353
|
+
if (/^https?:\/\//i.test(path)) {
|
|
354
|
+
path = new URL(path).pathname;
|
|
355
|
+
}
|
|
356
|
+
} catch {
|
|
357
|
+
}
|
|
358
|
+
const q = path.indexOf("?");
|
|
359
|
+
if (q >= 0) path = path.slice(0, q);
|
|
360
|
+
const h = path.indexOf("#");
|
|
361
|
+
if (h >= 0) path = path.slice(0, h);
|
|
362
|
+
if (!path.startsWith("/")) path = `/${path}`;
|
|
363
|
+
if (path.length > 1 && path.endsWith("/")) {
|
|
364
|
+
path = path.replace(/\/+$/, "");
|
|
365
|
+
}
|
|
366
|
+
return path || "/";
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/edge/resolve.ts
|
|
370
|
+
var EdgeResolveError = class extends Error {
|
|
371
|
+
constructor(message, status, body) {
|
|
372
|
+
super(message);
|
|
373
|
+
this.name = "EdgeResolveError";
|
|
374
|
+
this.status = status;
|
|
375
|
+
this.body = body;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
async function fetchEdgeResolve(options) {
|
|
379
|
+
const base = options.edgeUrl.replace(/\/+$/, "");
|
|
380
|
+
const route = normalizeRoute(options.route);
|
|
381
|
+
const params = new URLSearchParams({
|
|
382
|
+
route,
|
|
383
|
+
trackingId: options.trackingId
|
|
384
|
+
});
|
|
385
|
+
if (options.siteId) params.set("site", options.siteId);
|
|
386
|
+
if (options.anonId) params.set("anonId", options.anonId);
|
|
387
|
+
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
388
|
+
const res = await fetchFn(`${base}/v1/resolve?${params.toString()}`, {
|
|
389
|
+
method: "GET",
|
|
390
|
+
headers: { Accept: "application/json" }
|
|
391
|
+
});
|
|
392
|
+
const body = await res.json().catch(() => ({}));
|
|
393
|
+
if (!res.ok) {
|
|
394
|
+
throw new EdgeResolveError(
|
|
395
|
+
(body && typeof body === "object" && "error" in body ? String(body.error) : `Edge resolve failed (${res.status})`) || `Edge resolve failed (${res.status})`,
|
|
396
|
+
res.status,
|
|
397
|
+
body
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
return body;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/edge/mapResolvedToPageConfig.ts
|
|
404
|
+
function mapResolvedComponent(node) {
|
|
405
|
+
const slots = [];
|
|
406
|
+
if (node.children) {
|
|
407
|
+
for (const [slotId, kids] of Object.entries(node.children)) {
|
|
408
|
+
slots.push({
|
|
409
|
+
slotId,
|
|
410
|
+
children: (kids || []).map(mapResolvedComponent)
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
id: node.instanceId,
|
|
416
|
+
componentId: node.componentId,
|
|
417
|
+
props: { ...node.props || {} },
|
|
418
|
+
...slots.length > 0 ? { slots } : {},
|
|
419
|
+
_contentSource: "edge"
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function mapResolvedToPageConfig(payload) {
|
|
423
|
+
let layoutTree = [];
|
|
424
|
+
if (payload.tree && payload.tree.length > 0) {
|
|
425
|
+
layoutTree = payload.tree.map(mapResolvedComponent);
|
|
426
|
+
} else {
|
|
427
|
+
const zoneIds = Object.keys(payload.zones || {}).sort();
|
|
428
|
+
for (const zoneId of zoneIds) {
|
|
429
|
+
const roots = payload.zones[zoneId] || [];
|
|
430
|
+
layoutTree.push(...roots.map(mapResolvedComponent));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
id: `edge:${payload.siteId}:${payload.route}:v${payload.version}`,
|
|
435
|
+
route: payload.route,
|
|
436
|
+
title: "",
|
|
437
|
+
layoutTree,
|
|
438
|
+
meta: {
|
|
439
|
+
// Stash edge meta for diagnostics (not visitor-facing)
|
|
440
|
+
description: payload.meta?.degraded ? "degraded" : void 0
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function collectDegraded(payload) {
|
|
445
|
+
if (payload.meta?.degraded) return true;
|
|
446
|
+
const walk = (nodes) => nodes.some(
|
|
447
|
+
(n) => !!n.degraded || (n.children ? Object.values(n.children).some((kids) => walk(kids || [])) : false)
|
|
448
|
+
);
|
|
449
|
+
if (payload.tree && walk(payload.tree)) return true;
|
|
450
|
+
return Object.values(payload.zones || {}).some((roots) => walk(roots || []));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/content/fetchContent.ts
|
|
454
|
+
async function fetchContent(options) {
|
|
455
|
+
const preview = options.preview ?? (typeof window !== "undefined" ? isComposerPreview() : false);
|
|
456
|
+
if (preview) {
|
|
457
|
+
try {
|
|
458
|
+
const page = await options.fetchOrchestratorPage(options.route, true);
|
|
459
|
+
return {
|
|
460
|
+
pageConfig: page,
|
|
461
|
+
source: "orchestrator",
|
|
462
|
+
meta: { source: "orchestrator" },
|
|
463
|
+
error: null
|
|
464
|
+
};
|
|
465
|
+
} catch (err) {
|
|
466
|
+
return {
|
|
467
|
+
pageConfig: null,
|
|
468
|
+
source: "orchestrator",
|
|
469
|
+
meta: { source: "orchestrator" },
|
|
470
|
+
error: err instanceof Error ? err.message : "Failed to load preview"
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
try {
|
|
475
|
+
const payload = await fetchEdgeResolve({
|
|
476
|
+
edgeUrl: options.edgeUrl,
|
|
477
|
+
trackingId: options.trackingId,
|
|
478
|
+
route: options.route,
|
|
479
|
+
anonId: options.anonId,
|
|
480
|
+
siteId: options.siteId,
|
|
481
|
+
fetch: options.fetchFn
|
|
482
|
+
});
|
|
483
|
+
const pageConfig = mapResolvedToPageConfig(payload);
|
|
484
|
+
const degraded = collectDegraded(payload);
|
|
485
|
+
return {
|
|
486
|
+
pageConfig,
|
|
487
|
+
source: "edge",
|
|
488
|
+
meta: {
|
|
489
|
+
source: "edge",
|
|
490
|
+
version: payload.version,
|
|
491
|
+
siteId: payload.siteId,
|
|
492
|
+
variantKeys: payload.meta?.variantKeys,
|
|
493
|
+
degraded,
|
|
494
|
+
audienceLookup: payload.meta?.audienceLookup,
|
|
495
|
+
decideLookup: payload.meta?.decideLookup,
|
|
496
|
+
resolvedAt: payload.meta?.resolvedAt
|
|
497
|
+
},
|
|
498
|
+
error: null
|
|
499
|
+
};
|
|
500
|
+
} catch (err) {
|
|
501
|
+
if (err instanceof EdgeResolveError && err.status === 404) {
|
|
502
|
+
return {
|
|
503
|
+
pageConfig: null,
|
|
504
|
+
source: "edge",
|
|
505
|
+
meta: { source: "edge" },
|
|
506
|
+
error: null
|
|
507
|
+
// unpublished → site fallback, not an error banner
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
pageConfig: null,
|
|
512
|
+
source: "edge",
|
|
513
|
+
meta: { source: "edge" },
|
|
514
|
+
error: err instanceof Error ? err.message : "Couldn't load page content."
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
314
519
|
// src/index.ts
|
|
315
520
|
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
316
521
|
function readPreviewQueryOverrides() {
|
|
@@ -340,6 +545,8 @@ var AmplifyUpSDK = class {
|
|
|
340
545
|
this.apiGatewayUrl = "";
|
|
341
546
|
this.orchestratorUrl = "";
|
|
342
547
|
this.decisionApiUrl = "";
|
|
548
|
+
this.edgeUrl = "";
|
|
549
|
+
this.siteId = "";
|
|
343
550
|
this.target = "local";
|
|
344
551
|
this.initialized = false;
|
|
345
552
|
/** Prevents overlapping init() from React Strict Mode double-mount */
|
|
@@ -496,7 +703,8 @@ var AmplifyUpSDK = class {
|
|
|
496
703
|
isInitialized: () => this.isInitialized(),
|
|
497
704
|
page: (url, properties) => this.page(url, properties),
|
|
498
705
|
track: (eventName, properties) => this.track(eventName, properties),
|
|
499
|
-
identify: (
|
|
706
|
+
identify: (userIdOrIdentifiers, traits) => this.identify(userIdOrIdentifiers, traits),
|
|
707
|
+
setProfileFields: (fields) => this.setProfileFields(fields)
|
|
500
708
|
};
|
|
501
709
|
}
|
|
502
710
|
async performInit(config) {
|
|
@@ -511,6 +719,8 @@ var AmplifyUpSDK = class {
|
|
|
511
719
|
this.apiGatewayUrl = urls.apiGatewayUrl;
|
|
512
720
|
this.orchestratorUrl = urls.orchestratorUrl;
|
|
513
721
|
this.decisionApiUrl = urls.decisionApiUrl;
|
|
722
|
+
this.edgeUrl = urls.edgeUrl;
|
|
723
|
+
this.siteId = config.siteId || "";
|
|
514
724
|
const previewOverrides = readPreviewQueryOverrides();
|
|
515
725
|
if (previewOverrides.orchestratorUrl) {
|
|
516
726
|
this.orchestratorUrl = previewOverrides.orchestratorUrl;
|
|
@@ -519,6 +729,7 @@ var AmplifyUpSDK = class {
|
|
|
519
729
|
this.target = "production";
|
|
520
730
|
this.apiGatewayUrl = prodUrls.apiGatewayUrl;
|
|
521
731
|
this.decisionApiUrl = prodUrls.decisionApiUrl;
|
|
732
|
+
this.edgeUrl = prodUrls.edgeUrl;
|
|
522
733
|
}
|
|
523
734
|
}
|
|
524
735
|
this.config = {
|
|
@@ -526,7 +737,8 @@ var AmplifyUpSDK = class {
|
|
|
526
737
|
debug: config.debug ?? true,
|
|
527
738
|
// Enable debug by default
|
|
528
739
|
target: this.target,
|
|
529
|
-
dev: config.dev
|
|
740
|
+
dev: config.dev,
|
|
741
|
+
...config.siteId ? { siteId: config.siteId } : {}
|
|
530
742
|
};
|
|
531
743
|
try {
|
|
532
744
|
const adapterConfig = {
|
|
@@ -924,12 +1136,17 @@ var AmplifyUpSDK = class {
|
|
|
924
1136
|
});
|
|
925
1137
|
}
|
|
926
1138
|
/**
|
|
927
|
-
* Identify
|
|
1139
|
+
* Identify a visitor.
|
|
1140
|
+
* - identify('user_123') — bare string; server maps via org default type
|
|
1141
|
+
* - identify({ email: '...', crm_id: '...' }) — explicit types
|
|
1142
|
+
* - identify('user_123', traits) — legacy form
|
|
928
1143
|
*/
|
|
929
|
-
identify(
|
|
1144
|
+
identify(userIdOrIdentifiers, traits) {
|
|
930
1145
|
if (this.isPreviewMode()) {
|
|
931
1146
|
if (this.config?.debug) {
|
|
932
|
-
console.log("AmplifyUp SDK: Identify tracking disabled in preview mode", {
|
|
1147
|
+
console.log("AmplifyUp SDK: Identify tracking disabled in preview mode", {
|
|
1148
|
+
userIdOrIdentifiers
|
|
1149
|
+
});
|
|
933
1150
|
}
|
|
934
1151
|
return;
|
|
935
1152
|
}
|
|
@@ -945,10 +1162,45 @@ var AmplifyUpSDK = class {
|
|
|
945
1162
|
trackingId: this.config?.trackingId,
|
|
946
1163
|
...traits
|
|
947
1164
|
};
|
|
948
|
-
this.adapter.identify(
|
|
949
|
-
|
|
1165
|
+
this.adapter.identify(userIdOrIdentifiers, identifyTraits);
|
|
1166
|
+
if (typeof userIdOrIdentifiers === "string") {
|
|
1167
|
+
setUserId(userIdOrIdentifiers);
|
|
1168
|
+
}
|
|
950
1169
|
if (this.config?.debug) {
|
|
951
|
-
console.log("AmplifyUp SDK: User identified", {
|
|
1170
|
+
console.log("AmplifyUp SDK: User identified", {
|
|
1171
|
+
userIdOrIdentifiers,
|
|
1172
|
+
instanceId
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Set profile fields (partial update). Omitted keys are left alone;
|
|
1178
|
+
* an explicit empty value clears the field.
|
|
1179
|
+
*/
|
|
1180
|
+
setProfileFields(fields) {
|
|
1181
|
+
if (this.isPreviewMode()) {
|
|
1182
|
+
if (this.config?.debug) {
|
|
1183
|
+
console.log("AmplifyUp SDK: setProfileFields disabled in preview mode", {
|
|
1184
|
+
fields
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
if (!this.isInitialized()) {
|
|
1190
|
+
if (this.config?.debug) {
|
|
1191
|
+
console.warn("AmplifyUp SDK: Not initialized. setProfileFields not called.");
|
|
1192
|
+
}
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
const instanceId = getInstanceId();
|
|
1196
|
+
if (typeof this.adapter.setProfileFields === "function") {
|
|
1197
|
+
this.adapter.setProfileFields(fields, {
|
|
1198
|
+
instanceId: instanceId || void 0,
|
|
1199
|
+
trackingId: this.config?.trackingId
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
if (this.config?.debug) {
|
|
1203
|
+
console.log("AmplifyUp SDK: Profile fields set", { fields, instanceId });
|
|
952
1204
|
}
|
|
953
1205
|
}
|
|
954
1206
|
/**
|
|
@@ -1123,6 +1375,18 @@ Available Console Commands:
|
|
|
1123
1375
|
getDecisionApiUrl() {
|
|
1124
1376
|
return this.decisionApiUrl || void 0;
|
|
1125
1377
|
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Get Edge Worker URL (production content resolve)
|
|
1380
|
+
*/
|
|
1381
|
+
getEdgeUrl() {
|
|
1382
|
+
return this.edgeUrl || void 0;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Optional site id from config (Edge can resolve via trackingId alone).
|
|
1386
|
+
*/
|
|
1387
|
+
getSiteId() {
|
|
1388
|
+
return this.siteId || this.config?.siteId || void 0;
|
|
1389
|
+
}
|
|
1126
1390
|
/**
|
|
1127
1391
|
* Build API URL for fetching page config from the Layout Provider
|
|
1128
1392
|
*/
|
|
@@ -2409,6 +2673,7 @@ function AmplifyRenderer({
|
|
|
2409
2673
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
2410
2674
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
2411
2675
|
const error = serverPageConfig ? null : clientHook.error;
|
|
2676
|
+
const contentSource = clientHook.source;
|
|
2412
2677
|
const [variantCache, setVariantCache] = react.useState({});
|
|
2413
2678
|
react.useEffect(() => {
|
|
2414
2679
|
if (typeof window !== "undefined") {
|
|
@@ -2550,6 +2815,9 @@ function AmplifyRenderer({
|
|
|
2550
2815
|
}, [pageConfig]);
|
|
2551
2816
|
react.useEffect(() => {
|
|
2552
2817
|
if (!pageConfig?.layoutTree || !pageConfig.layoutId) return;
|
|
2818
|
+
const roots = pageConfig.layoutTree;
|
|
2819
|
+
const fromEdge = contentSource === "edge" || roots.some((n) => n._contentSource === "edge");
|
|
2820
|
+
if (fromEdge) return;
|
|
2553
2821
|
const sdk = getSDK();
|
|
2554
2822
|
const instanceId = sdk.getInstanceId();
|
|
2555
2823
|
const decisionApiUrl = sdk.getDecisionApiUrl();
|
|
@@ -2644,7 +2912,7 @@ function AmplifyRenderer({
|
|
|
2644
2912
|
setVariantCache(newCache);
|
|
2645
2913
|
};
|
|
2646
2914
|
fetchVariants();
|
|
2647
|
-
}, [pageConfig?.layoutTree, pageConfig?.layoutId, pageConfig?.route]);
|
|
2915
|
+
}, [pageConfig?.layoutTree, pageConfig?.layoutId, pageConfig?.route, contentSource]);
|
|
2648
2916
|
if (loading) {
|
|
2649
2917
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: loadingComponent || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-screen bg-gray-50", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "animate-pulse", children: [
|
|
2650
2918
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-8 bg-gray-200 rounded w-1/4 mb-4" }),
|
|
@@ -2845,28 +3113,38 @@ async function fetchPageConfigServer(route, trackingId, preview = false, options
|
|
|
2845
3113
|
const target = resolveAmplifyUpTarget({
|
|
2846
3114
|
configTarget: options?.target
|
|
2847
3115
|
});
|
|
2848
|
-
const { orchestratorUrl } = resolveAmplifyUpUrls(target);
|
|
2849
|
-
const
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
params.set("preview", "true");
|
|
2855
|
-
}
|
|
2856
|
-
const url = `${orchestratorUrl}/api/layout/provider?${params.toString()}`;
|
|
2857
|
-
try {
|
|
2858
|
-
const res = await fetch(url, {
|
|
2859
|
-
cache: "no-store",
|
|
2860
|
-
headers: { Accept: "application/json" }
|
|
3116
|
+
const { orchestratorUrl, edgeUrl } = resolveAmplifyUpUrls(target);
|
|
3117
|
+
const previewFlag = preview || (options?.searchParams ? isPreviewRequest(options.searchParams) : false);
|
|
3118
|
+
const fetchOrchestratorPage = async (pageRoute, isPreview) => {
|
|
3119
|
+
const params = new URLSearchParams({
|
|
3120
|
+
route: pageRoute,
|
|
3121
|
+
trackingId
|
|
2861
3122
|
});
|
|
2862
|
-
if (
|
|
3123
|
+
if (isPreview) params.set("preview", "true");
|
|
3124
|
+
const url = `${orchestratorUrl}/api/layout/provider?${params.toString()}`;
|
|
3125
|
+
try {
|
|
3126
|
+
const res = await fetch(url, {
|
|
3127
|
+
cache: "no-store",
|
|
3128
|
+
headers: { Accept: "application/json" }
|
|
3129
|
+
});
|
|
3130
|
+
if (!res.ok) return null;
|
|
3131
|
+
const data = await res.json();
|
|
3132
|
+
return data.page || null;
|
|
3133
|
+
} catch {
|
|
2863
3134
|
return null;
|
|
2864
3135
|
}
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
3136
|
+
};
|
|
3137
|
+
const result = await fetchContent({
|
|
3138
|
+
route,
|
|
3139
|
+
trackingId,
|
|
3140
|
+
anonId: options?.anonId,
|
|
3141
|
+
siteId: options?.siteId,
|
|
3142
|
+
preview: previewFlag,
|
|
3143
|
+
orchestratorUrl,
|
|
3144
|
+
edgeUrl,
|
|
3145
|
+
fetchOrchestratorPage
|
|
3146
|
+
});
|
|
3147
|
+
return result.pageConfig;
|
|
2870
3148
|
}
|
|
2871
3149
|
var ComponentContext = react.createContext(null);
|
|
2872
3150
|
function ComponentContextProvider({
|
|
@@ -3025,6 +3303,8 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3025
3303
|
const [pageConfig, setPageConfig] = react.useState(null);
|
|
3026
3304
|
const [loading, setLoading] = react.useState(true);
|
|
3027
3305
|
const [error, setError] = react.useState(null);
|
|
3306
|
+
const [source, setSource] = react.useState(null);
|
|
3307
|
+
const [meta, setMeta] = react.useState(null);
|
|
3028
3308
|
const getActualRoute = () => {
|
|
3029
3309
|
if (typeof window === "undefined") return "";
|
|
3030
3310
|
const currentPath = window.location.pathname;
|
|
@@ -3090,10 +3370,10 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3090
3370
|
return () => {
|
|
3091
3371
|
cancelled = true;
|
|
3092
3372
|
};
|
|
3093
|
-
}, [config.trackingId, config.target, config.debug, config.dev]);
|
|
3373
|
+
}, [config.trackingId, config.target, config.debug, config.dev, config.siteId]);
|
|
3094
3374
|
react.useEffect(() => {
|
|
3095
3375
|
if (!initialized) return;
|
|
3096
|
-
const
|
|
3376
|
+
const load = async () => {
|
|
3097
3377
|
try {
|
|
3098
3378
|
setLoading(true);
|
|
3099
3379
|
setError(null);
|
|
@@ -3104,29 +3384,57 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3104
3384
|
}
|
|
3105
3385
|
const sdk = getSDK();
|
|
3106
3386
|
sdk.routeChange(actualRoute);
|
|
3107
|
-
const
|
|
3108
|
-
const
|
|
3109
|
-
|
|
3387
|
+
const preview = isComposerPreview();
|
|
3388
|
+
const edgeUrl = sdk.getEdgeUrl();
|
|
3389
|
+
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
3390
|
+
const trackingId = sdk.getTrackingId();
|
|
3391
|
+
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
3392
|
+
setError("SDK not initialized");
|
|
3393
|
+
setLoading(false);
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
const result = await fetchContent({
|
|
3397
|
+
route: actualRoute,
|
|
3398
|
+
trackingId,
|
|
3399
|
+
anonId: sdk.getInstanceId(),
|
|
3400
|
+
siteId: sdk.getSiteId() || null,
|
|
3401
|
+
preview,
|
|
3402
|
+
orchestratorUrl,
|
|
3403
|
+
edgeUrl,
|
|
3404
|
+
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
3405
|
+
});
|
|
3406
|
+
setSource(result.source);
|
|
3407
|
+
setMeta(result.meta);
|
|
3408
|
+
setError(result.error);
|
|
3409
|
+
if (!result.pageConfig) {
|
|
3110
3410
|
setPageConfig({
|
|
3111
3411
|
id: "default",
|
|
3112
3412
|
route: actualRoute,
|
|
3113
3413
|
title: "Page Not Configured",
|
|
3114
|
-
description: "This page has not been
|
|
3414
|
+
description: "This page has not been published yet.",
|
|
3115
3415
|
layoutTree: []
|
|
3116
3416
|
});
|
|
3117
3417
|
} else {
|
|
3118
|
-
setPageConfig(
|
|
3418
|
+
setPageConfig(result.pageConfig);
|
|
3119
3419
|
}
|
|
3120
3420
|
} catch (err) {
|
|
3121
3421
|
console.error("Error fetching page config:", err);
|
|
3122
3422
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
3423
|
+
setSource(null);
|
|
3424
|
+
setMeta(null);
|
|
3123
3425
|
} finally {
|
|
3124
3426
|
setLoading(false);
|
|
3125
3427
|
}
|
|
3126
3428
|
};
|
|
3127
|
-
|
|
3429
|
+
void load();
|
|
3128
3430
|
}, [pathname, initialized]);
|
|
3129
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3431
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3432
|
+
AmplifyUpContext.Provider,
|
|
3433
|
+
{
|
|
3434
|
+
value: { pageConfig, loading, error, source, meta },
|
|
3435
|
+
children
|
|
3436
|
+
}
|
|
3437
|
+
);
|
|
3130
3438
|
}
|
|
3131
3439
|
function useAmplifyUp() {
|
|
3132
3440
|
const context = react.useContext(AmplifyUpContext);
|