@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/AmplifyRenderer.mjs
CHANGED
|
@@ -151,17 +151,42 @@ var AWSAdapter = class {
|
|
|
151
151
|
};
|
|
152
152
|
this.sendEvent("/v1/track", eventData);
|
|
153
153
|
}
|
|
154
|
-
identify(
|
|
154
|
+
identify(userIdOrIdentifiers, traits = {}) {
|
|
155
155
|
if (!this.initialized) {
|
|
156
156
|
console.warn("AmplifyUp SDK: Not initialized. Call init() first.");
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
|
+
const isMap = userIdOrIdentifiers !== null && typeof userIdOrIdentifiers === "object" && !Array.isArray(userIdOrIdentifiers);
|
|
160
|
+
const identifiers = isMap ? userIdOrIdentifiers : traits.identifiers;
|
|
161
|
+
const userId = isMap ? void 0 : String(userIdOrIdentifiers);
|
|
159
162
|
const eventData = {
|
|
160
163
|
type: "identify",
|
|
161
|
-
userId,
|
|
162
164
|
anonymousId: traits.instanceId,
|
|
163
165
|
traits: {
|
|
164
|
-
...traits
|
|
166
|
+
...traits,
|
|
167
|
+
...identifiers ? { identifiers } : {}
|
|
168
|
+
},
|
|
169
|
+
...identifiers ? { identifiers } : {},
|
|
170
|
+
...userId ? { userId } : {},
|
|
171
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
172
|
+
};
|
|
173
|
+
this.sendEvent("/v1/track", eventData);
|
|
174
|
+
}
|
|
175
|
+
setProfileFields(fields, context = {}) {
|
|
176
|
+
if (!this.initialized) {
|
|
177
|
+
console.warn("AmplifyUp SDK: Not initialized. Call init() first.");
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const eventData = {
|
|
181
|
+
type: "set_fields",
|
|
182
|
+
anonymousId: context.instanceId,
|
|
183
|
+
fields,
|
|
184
|
+
traits: {
|
|
185
|
+
instanceId: context.instanceId,
|
|
186
|
+
trackingId: context.trackingId
|
|
187
|
+
},
|
|
188
|
+
properties: {
|
|
189
|
+
trackingId: context.trackingId
|
|
165
190
|
},
|
|
166
191
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
167
192
|
};
|
|
@@ -223,6 +248,7 @@ function clearIds() {
|
|
|
223
248
|
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
224
249
|
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
225
250
|
var PROD_ORCHESTRATOR = "https://amplifyup.ai";
|
|
251
|
+
var PROD_EDGE = "https://edge.amplifyup.ai";
|
|
226
252
|
function isAmplifyUpTarget(value) {
|
|
227
253
|
return value === "local" || value === "dev" || value === "production";
|
|
228
254
|
}
|
|
@@ -258,6 +284,10 @@ function localAwsApiUrl() {
|
|
|
258
284
|
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL : void 0;
|
|
259
285
|
return (fromEnv || AWS_DEV_API).replace(/\/$/, "");
|
|
260
286
|
}
|
|
287
|
+
function localEdgeUrl() {
|
|
288
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_EDGE_URL : void 0;
|
|
289
|
+
return (fromEnv || "http://localhost:8787").replace(/\/$/, "");
|
|
290
|
+
}
|
|
261
291
|
function resolveAmplifyUpUrls(target) {
|
|
262
292
|
if (target === "local") {
|
|
263
293
|
const orchestratorUrl2 = localOrchestratorUrl();
|
|
@@ -268,18 +298,22 @@ function resolveAmplifyUpUrls(target) {
|
|
|
268
298
|
orchestratorUrl: orchestratorUrl2,
|
|
269
299
|
// Events + personalize → AWS development stack
|
|
270
300
|
apiGatewayUrl,
|
|
271
|
-
decisionApiUrl: `${apiGatewayUrl}/v1/personalize
|
|
301
|
+
decisionApiUrl: `${apiGatewayUrl}/v1/personalize`,
|
|
302
|
+
edgeUrl: localEdgeUrl()
|
|
272
303
|
};
|
|
273
304
|
}
|
|
274
305
|
const resolvedApi = typeof process !== "undefined" && process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL?.replace(/\/$/, "") || AWS_PROD_API;
|
|
275
306
|
const orchestratorFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
276
307
|
const isLocalOrchestrator = !!orchestratorFromEnv && (orchestratorFromEnv.includes("localhost") || orchestratorFromEnv.includes("127.0.0.1"));
|
|
277
308
|
const orchestratorUrl = isLocalOrchestrator || !orchestratorFromEnv ? PROD_ORCHESTRATOR : orchestratorFromEnv.replace(/\/$/, "");
|
|
309
|
+
const edgeFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_EDGE_URL?.replace(/\/$/, "") : void 0;
|
|
310
|
+
const edgeUrl = edgeFromEnv && !edgeFromEnv.includes("localhost") && !edgeFromEnv.includes("127.0.0.1") ? edgeFromEnv : PROD_EDGE;
|
|
278
311
|
return {
|
|
279
312
|
target: "production",
|
|
280
313
|
apiGatewayUrl: resolvedApi,
|
|
281
314
|
orchestratorUrl,
|
|
282
|
-
decisionApiUrl: `${resolvedApi}/v1/personalize
|
|
315
|
+
decisionApiUrl: `${resolvedApi}/v1/personalize`,
|
|
316
|
+
edgeUrl
|
|
283
317
|
};
|
|
284
318
|
}
|
|
285
319
|
|
|
@@ -338,6 +372,8 @@ var AmplifyUpSDK = class {
|
|
|
338
372
|
this.apiGatewayUrl = "";
|
|
339
373
|
this.orchestratorUrl = "";
|
|
340
374
|
this.decisionApiUrl = "";
|
|
375
|
+
this.edgeUrl = "";
|
|
376
|
+
this.siteId = "";
|
|
341
377
|
this.target = "local";
|
|
342
378
|
this.initialized = false;
|
|
343
379
|
/** Prevents overlapping init() from React Strict Mode double-mount */
|
|
@@ -494,7 +530,8 @@ var AmplifyUpSDK = class {
|
|
|
494
530
|
isInitialized: () => this.isInitialized(),
|
|
495
531
|
page: (url, properties) => this.page(url, properties),
|
|
496
532
|
track: (eventName, properties) => this.track(eventName, properties),
|
|
497
|
-
identify: (
|
|
533
|
+
identify: (userIdOrIdentifiers, traits) => this.identify(userIdOrIdentifiers, traits),
|
|
534
|
+
setProfileFields: (fields) => this.setProfileFields(fields)
|
|
498
535
|
};
|
|
499
536
|
}
|
|
500
537
|
async performInit(config) {
|
|
@@ -509,6 +546,8 @@ var AmplifyUpSDK = class {
|
|
|
509
546
|
this.apiGatewayUrl = urls.apiGatewayUrl;
|
|
510
547
|
this.orchestratorUrl = urls.orchestratorUrl;
|
|
511
548
|
this.decisionApiUrl = urls.decisionApiUrl;
|
|
549
|
+
this.edgeUrl = urls.edgeUrl;
|
|
550
|
+
this.siteId = config.siteId || "";
|
|
512
551
|
const previewOverrides = readPreviewQueryOverrides();
|
|
513
552
|
if (previewOverrides.orchestratorUrl) {
|
|
514
553
|
this.orchestratorUrl = previewOverrides.orchestratorUrl;
|
|
@@ -517,6 +556,7 @@ var AmplifyUpSDK = class {
|
|
|
517
556
|
this.target = "production";
|
|
518
557
|
this.apiGatewayUrl = prodUrls.apiGatewayUrl;
|
|
519
558
|
this.decisionApiUrl = prodUrls.decisionApiUrl;
|
|
559
|
+
this.edgeUrl = prodUrls.edgeUrl;
|
|
520
560
|
}
|
|
521
561
|
}
|
|
522
562
|
this.config = {
|
|
@@ -524,7 +564,8 @@ var AmplifyUpSDK = class {
|
|
|
524
564
|
debug: config.debug ?? true,
|
|
525
565
|
// Enable debug by default
|
|
526
566
|
target: this.target,
|
|
527
|
-
dev: config.dev
|
|
567
|
+
dev: config.dev,
|
|
568
|
+
...config.siteId ? { siteId: config.siteId } : {}
|
|
528
569
|
};
|
|
529
570
|
try {
|
|
530
571
|
const adapterConfig = {
|
|
@@ -922,12 +963,17 @@ var AmplifyUpSDK = class {
|
|
|
922
963
|
});
|
|
923
964
|
}
|
|
924
965
|
/**
|
|
925
|
-
* Identify
|
|
966
|
+
* Identify a visitor.
|
|
967
|
+
* - identify('user_123') — bare string; server maps via org default type
|
|
968
|
+
* - identify({ email: '...', crm_id: '...' }) — explicit types
|
|
969
|
+
* - identify('user_123', traits) — legacy form
|
|
926
970
|
*/
|
|
927
|
-
identify(
|
|
971
|
+
identify(userIdOrIdentifiers, traits) {
|
|
928
972
|
if (this.isPreviewMode()) {
|
|
929
973
|
if (this.config?.debug) {
|
|
930
|
-
console.log("AmplifyUp SDK: Identify tracking disabled in preview mode", {
|
|
974
|
+
console.log("AmplifyUp SDK: Identify tracking disabled in preview mode", {
|
|
975
|
+
userIdOrIdentifiers
|
|
976
|
+
});
|
|
931
977
|
}
|
|
932
978
|
return;
|
|
933
979
|
}
|
|
@@ -943,10 +989,45 @@ var AmplifyUpSDK = class {
|
|
|
943
989
|
trackingId: this.config?.trackingId,
|
|
944
990
|
...traits
|
|
945
991
|
};
|
|
946
|
-
this.adapter.identify(
|
|
947
|
-
|
|
992
|
+
this.adapter.identify(userIdOrIdentifiers, identifyTraits);
|
|
993
|
+
if (typeof userIdOrIdentifiers === "string") {
|
|
994
|
+
setUserId(userIdOrIdentifiers);
|
|
995
|
+
}
|
|
996
|
+
if (this.config?.debug) {
|
|
997
|
+
console.log("AmplifyUp SDK: User identified", {
|
|
998
|
+
userIdOrIdentifiers,
|
|
999
|
+
instanceId
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Set profile fields (partial update). Omitted keys are left alone;
|
|
1005
|
+
* an explicit empty value clears the field.
|
|
1006
|
+
*/
|
|
1007
|
+
setProfileFields(fields) {
|
|
1008
|
+
if (this.isPreviewMode()) {
|
|
1009
|
+
if (this.config?.debug) {
|
|
1010
|
+
console.log("AmplifyUp SDK: setProfileFields disabled in preview mode", {
|
|
1011
|
+
fields
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (!this.isInitialized()) {
|
|
1017
|
+
if (this.config?.debug) {
|
|
1018
|
+
console.warn("AmplifyUp SDK: Not initialized. setProfileFields not called.");
|
|
1019
|
+
}
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
const instanceId = getInstanceId();
|
|
1023
|
+
if (typeof this.adapter.setProfileFields === "function") {
|
|
1024
|
+
this.adapter.setProfileFields(fields, {
|
|
1025
|
+
instanceId: instanceId || void 0,
|
|
1026
|
+
trackingId: this.config?.trackingId
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
948
1029
|
if (this.config?.debug) {
|
|
949
|
-
console.log("AmplifyUp SDK:
|
|
1030
|
+
console.log("AmplifyUp SDK: Profile fields set", { fields, instanceId });
|
|
950
1031
|
}
|
|
951
1032
|
}
|
|
952
1033
|
/**
|
|
@@ -1121,6 +1202,18 @@ Available Console Commands:
|
|
|
1121
1202
|
getDecisionApiUrl() {
|
|
1122
1203
|
return this.decisionApiUrl || void 0;
|
|
1123
1204
|
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Get Edge Worker URL (production content resolve)
|
|
1207
|
+
*/
|
|
1208
|
+
getEdgeUrl() {
|
|
1209
|
+
return this.edgeUrl || void 0;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Optional site id from config (Edge can resolve via trackingId alone).
|
|
1213
|
+
*/
|
|
1214
|
+
getSiteId() {
|
|
1215
|
+
return this.siteId || this.config?.siteId || void 0;
|
|
1216
|
+
}
|
|
1124
1217
|
/**
|
|
1125
1218
|
* Build API URL for fetching page config from the Layout Provider
|
|
1126
1219
|
*/
|
|
@@ -2426,6 +2519,7 @@ function AmplifyRenderer({
|
|
|
2426
2519
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
2427
2520
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
2428
2521
|
const error = serverPageConfig ? null : clientHook.error;
|
|
2522
|
+
const contentSource = clientHook.source;
|
|
2429
2523
|
const [variantCache, setVariantCache] = useState({});
|
|
2430
2524
|
useEffect(() => {
|
|
2431
2525
|
if (typeof window !== "undefined") {
|
|
@@ -2567,6 +2661,9 @@ function AmplifyRenderer({
|
|
|
2567
2661
|
}, [pageConfig]);
|
|
2568
2662
|
useEffect(() => {
|
|
2569
2663
|
if (!pageConfig?.layoutTree || !pageConfig.layoutId) return;
|
|
2664
|
+
const roots = pageConfig.layoutTree;
|
|
2665
|
+
const fromEdge = contentSource === "edge" || roots.some((n) => n._contentSource === "edge");
|
|
2666
|
+
if (fromEdge) return;
|
|
2570
2667
|
const sdk = getSDK();
|
|
2571
2668
|
const instanceId = sdk.getInstanceId();
|
|
2572
2669
|
const decisionApiUrl = sdk.getDecisionApiUrl();
|
|
@@ -2661,7 +2758,7 @@ function AmplifyRenderer({
|
|
|
2661
2758
|
setVariantCache(newCache);
|
|
2662
2759
|
};
|
|
2663
2760
|
fetchVariants();
|
|
2664
|
-
}, [pageConfig?.layoutTree, pageConfig?.layoutId, pageConfig?.route]);
|
|
2761
|
+
}, [pageConfig?.layoutTree, pageConfig?.layoutId, pageConfig?.route, contentSource]);
|
|
2665
2762
|
if (loading) {
|
|
2666
2763
|
return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent || /* @__PURE__ */ jsx("div", { className: "min-h-screen bg-gray-50", children: /* @__PURE__ */ jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsxs("div", { className: "animate-pulse", children: [
|
|
2667
2764
|
/* @__PURE__ */ jsx("div", { className: "h-8 bg-gray-200 rounded w-1/4 mb-4" }),
|