@amplifyup/sdk 0.1.32 → 0.1.34
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 +2 -1
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +42 -9
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +42 -9
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +74 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -15
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.d.mts +22 -0
- package/dist/middleware.d.ts +22 -0
- package/dist/middleware.js +198 -0
- package/dist/middleware.js.map +1 -0
- package/dist/middleware.mjs +193 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/{preview-BMrIgUvp.d.mts → preview-_vHmzRen.d.mts} +6 -1
- package/dist/{preview-BMrIgUvp.d.ts → preview-_vHmzRen.d.ts} +6 -1
- package/dist/react.d.mts +7 -4
- package/dist/react.d.ts +7 -4
- package/dist/react.js +124 -22
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +124 -23
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +41 -5
- package/dist/server.d.ts +41 -5
- package/dist/server.js +144 -11
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +139 -12
- package/dist/server.mjs.map +1 -1
- package/dist/{types-npF_lNoq.d.mts → types-CBoVIFI8.d.mts} +6 -0
- package/dist/{types-npF_lNoq.d.ts → types-CBoVIFI8.d.ts} +6 -0
- package/package.json +6 -1
package/dist/react.mjs
CHANGED
|
@@ -206,6 +206,7 @@ var AWSAdapter = class {
|
|
|
206
206
|
// src/storage.ts
|
|
207
207
|
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
208
208
|
var USER_ID_KEY = "amplifyup_user_id";
|
|
209
|
+
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
209
210
|
function generateGuid() {
|
|
210
211
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
211
212
|
return crypto.randomUUID();
|
|
@@ -216,16 +217,39 @@ function generateGuid() {
|
|
|
216
217
|
return v.toString(16);
|
|
217
218
|
});
|
|
218
219
|
}
|
|
220
|
+
function readCookie(name) {
|
|
221
|
+
if (typeof document === "undefined") return null;
|
|
222
|
+
const parts = document.cookie.split(";");
|
|
223
|
+
for (const part of parts) {
|
|
224
|
+
const idx = part.indexOf("=");
|
|
225
|
+
if (idx === -1) continue;
|
|
226
|
+
if (part.slice(0, idx).trim() !== name) continue;
|
|
227
|
+
const value = part.slice(idx + 1).trim();
|
|
228
|
+
try {
|
|
229
|
+
return value ? decodeURIComponent(value) : null;
|
|
230
|
+
} catch {
|
|
231
|
+
return value || null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
function writeCookie(name, value) {
|
|
237
|
+
if (typeof document === "undefined") return;
|
|
238
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=31536000; SameSite=Lax`;
|
|
239
|
+
}
|
|
219
240
|
function getInstanceId() {
|
|
220
241
|
if (typeof window === "undefined") {
|
|
221
242
|
return "";
|
|
222
243
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
244
|
+
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
245
|
+
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
246
|
+
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
247
|
+
if (fromLs !== instanceId) {
|
|
248
|
+
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
249
|
+
}
|
|
250
|
+
if (fromCookie !== instanceId) {
|
|
251
|
+
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
226
252
|
}
|
|
227
|
-
const instanceId = `browser_${generateGuid()}`;
|
|
228
|
-
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
229
253
|
return instanceId;
|
|
230
254
|
}
|
|
231
255
|
function getUserId() {
|
|
@@ -246,6 +270,7 @@ function clearIds() {
|
|
|
246
270
|
}
|
|
247
271
|
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
248
272
|
localStorage.removeItem(USER_ID_KEY);
|
|
273
|
+
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
249
274
|
}
|
|
250
275
|
|
|
251
276
|
// src/targets.ts
|
|
@@ -323,12 +348,17 @@ function resolveAmplifyUpUrls(target) {
|
|
|
323
348
|
|
|
324
349
|
// src/preview.ts
|
|
325
350
|
function isPreviewRequest(searchParams) {
|
|
351
|
+
return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
|
|
352
|
+
}
|
|
353
|
+
function isWorkingContentRequest(searchParams) {
|
|
354
|
+
return paramIsTrue(searchParams, "working");
|
|
355
|
+
}
|
|
356
|
+
function paramIsTrue(searchParams, key) {
|
|
326
357
|
if (searchParams instanceof URLSearchParams) {
|
|
327
|
-
return searchParams.get(
|
|
358
|
+
return searchParams.get(key) === "true";
|
|
328
359
|
}
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
return preview === "true" || visualEditor === "true";
|
|
360
|
+
const value = searchParams[key];
|
|
361
|
+
return value === "true" || Array.isArray(value) && value[0] === "true";
|
|
332
362
|
}
|
|
333
363
|
function isComposerPreview() {
|
|
334
364
|
if (typeof window === "undefined") return false;
|
|
@@ -368,6 +398,19 @@ function normalizeRoute(route) {
|
|
|
368
398
|
return path || "/";
|
|
369
399
|
}
|
|
370
400
|
|
|
401
|
+
// src/edge/variantKeys.ts
|
|
402
|
+
function serializeVariantKeys(keys) {
|
|
403
|
+
if (!keys) return "";
|
|
404
|
+
const parts = [];
|
|
405
|
+
const zoneIds = Object.keys(keys).sort();
|
|
406
|
+
for (const zoneId of zoneIds) {
|
|
407
|
+
const variant = keys[zoneId];
|
|
408
|
+
if (!variant || variant === "default") continue;
|
|
409
|
+
parts.push(`${zoneId}:${variant}`);
|
|
410
|
+
}
|
|
411
|
+
return parts.join(",");
|
|
412
|
+
}
|
|
413
|
+
|
|
371
414
|
// src/edge/resolve.ts
|
|
372
415
|
var EdgeResolveError = class extends Error {
|
|
373
416
|
constructor(message, status, body) {
|
|
@@ -385,12 +428,23 @@ async function fetchEdgeResolve(options) {
|
|
|
385
428
|
trackingId: options.trackingId
|
|
386
429
|
});
|
|
387
430
|
if (options.siteId) params.set("site", options.siteId);
|
|
388
|
-
|
|
431
|
+
const variantParam = serializeVariantKeys(options.variantKeys);
|
|
432
|
+
if (variantParam) {
|
|
433
|
+
params.set("variants", variantParam);
|
|
434
|
+
} else if (options.anonId) {
|
|
435
|
+
params.set("anonId", options.anonId);
|
|
436
|
+
}
|
|
389
437
|
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
390
|
-
const
|
|
438
|
+
const init = {
|
|
391
439
|
method: "GET",
|
|
392
440
|
headers: { Accept: "application/json" }
|
|
393
|
-
}
|
|
441
|
+
};
|
|
442
|
+
if (options.revalidate !== void 0) {
|
|
443
|
+
init.next = { revalidate: options.revalidate };
|
|
444
|
+
} else {
|
|
445
|
+
init.cache = "no-store";
|
|
446
|
+
}
|
|
447
|
+
const res = await fetchFn(`${base}/v1/resolve?${params.toString()}`, init);
|
|
394
448
|
const body = await res.json().catch(() => ({}));
|
|
395
449
|
if (!res.ok) {
|
|
396
450
|
throw new EdgeResolveError(
|
|
@@ -479,9 +533,11 @@ async function fetchContent(options) {
|
|
|
479
533
|
edgeUrl: options.edgeUrl,
|
|
480
534
|
trackingId: options.trackingId,
|
|
481
535
|
route: options.route,
|
|
482
|
-
anonId: options.anonId,
|
|
536
|
+
anonId: options.variantKeys ? void 0 : options.anonId,
|
|
483
537
|
siteId: options.siteId,
|
|
484
|
-
fetch: options.fetchFn
|
|
538
|
+
fetch: options.fetchFn,
|
|
539
|
+
revalidate: options.revalidate,
|
|
540
|
+
variantKeys: options.variantKeys
|
|
485
541
|
});
|
|
486
542
|
const pageConfig = mapResolvedToPageConfig(payload);
|
|
487
543
|
const degraded = collectDegraded(payload);
|
|
@@ -1464,6 +1520,9 @@ Available Console Commands:
|
|
|
1464
1520
|
});
|
|
1465
1521
|
if (preview) {
|
|
1466
1522
|
params.set("preview", "true");
|
|
1523
|
+
if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
|
|
1524
|
+
params.set("working", "true");
|
|
1525
|
+
}
|
|
1467
1526
|
}
|
|
1468
1527
|
if (isOnOrchestratorOrigin) {
|
|
1469
1528
|
return `/api/layout/provider?${params.toString()}`;
|
|
@@ -3766,6 +3825,21 @@ function defaultPreviewCanvas() {
|
|
|
3766
3825
|
function hasAmplifyLayout(pageConfig) {
|
|
3767
3826
|
return !!(pageConfig && pageConfig.id !== "default" && Array.isArray(pageConfig.layoutTree) && pageConfig.layoutTree.length > 0);
|
|
3768
3827
|
}
|
|
3828
|
+
function normalizeRoutePath(route) {
|
|
3829
|
+
if (!route) return "";
|
|
3830
|
+
const path = route.split("?")[0] || "/";
|
|
3831
|
+
if (path.length > 1 && path.endsWith("/")) return path.replace(/\/+$/, "");
|
|
3832
|
+
return path || "/";
|
|
3833
|
+
}
|
|
3834
|
+
function samePageRoute(a, b) {
|
|
3835
|
+
const ar = normalizeRoutePath(a?.route);
|
|
3836
|
+
const br = normalizeRoutePath(b?.route);
|
|
3837
|
+
return !!ar && !!br && ar === br;
|
|
3838
|
+
}
|
|
3839
|
+
function layoutTreesEqual(a, b) {
|
|
3840
|
+
if (!a || !b) return a === b;
|
|
3841
|
+
return JSON.stringify(a.layoutTree) === JSON.stringify(b.layoutTree);
|
|
3842
|
+
}
|
|
3769
3843
|
function AmplifyPageContent({
|
|
3770
3844
|
fallback,
|
|
3771
3845
|
renderComponent,
|
|
@@ -3779,9 +3853,18 @@ function AmplifyPageContent({
|
|
|
3779
3853
|
}) {
|
|
3780
3854
|
const client = useAmplifyUp();
|
|
3781
3855
|
const preview = forceComposerPreview || isComposerPreview();
|
|
3782
|
-
const
|
|
3783
|
-
const
|
|
3784
|
-
|
|
3856
|
+
const clientLayout = hasAmplifyLayout(client.pageConfig) ? client.pageConfig : null;
|
|
3857
|
+
const serverLayout = hasAmplifyLayout(pageConfigProp) ? pageConfigProp : null;
|
|
3858
|
+
let pageConfig = serverLayout ?? clientLayout;
|
|
3859
|
+
if (preview && clientLayout) {
|
|
3860
|
+
pageConfig = clientLayout;
|
|
3861
|
+
} else if (clientLayout && serverLayout && samePageRoute(clientLayout, serverLayout) && !layoutTreesEqual(clientLayout, serverLayout)) {
|
|
3862
|
+
pageConfig = clientLayout;
|
|
3863
|
+
} else if (clientLayout && !serverLayout) {
|
|
3864
|
+
pageConfig = clientLayout;
|
|
3865
|
+
}
|
|
3866
|
+
const loading = !hasAmplifyLayout(pageConfig) && client.loading;
|
|
3867
|
+
const error = hasAmplifyLayout(pageConfig) ? null : pageConfigProp ? null : client.error;
|
|
3785
3868
|
const previewCanvas = previewEmptyComponent ?? defaultPreviewCanvas();
|
|
3786
3869
|
const previewLoading = previewLoadingComponent ?? previewCanvas;
|
|
3787
3870
|
if (preview) {
|
|
@@ -3820,18 +3903,21 @@ function AmplifyPageContent({
|
|
|
3820
3903
|
}
|
|
3821
3904
|
|
|
3822
3905
|
// src/server.tsx
|
|
3906
|
+
var AMPLIFY_DEFAULT_REVALIDATE = 60;
|
|
3823
3907
|
async function fetchPageConfigServer(route, trackingId, preview = false, options) {
|
|
3824
3908
|
const target = resolveAmplifyUpTarget({
|
|
3825
3909
|
configTarget: options?.target
|
|
3826
3910
|
});
|
|
3827
3911
|
const { orchestratorUrl, edgeUrl } = resolveAmplifyUpUrls(target);
|
|
3828
3912
|
const previewFlag = preview || (options?.searchParams ? isPreviewRequest(options.searchParams) : false);
|
|
3913
|
+
const workingFlag = options?.searchParams ? isWorkingContentRequest(options.searchParams) : false;
|
|
3829
3914
|
const fetchOrchestratorPage = async (pageRoute, isPreview) => {
|
|
3830
3915
|
const params = new URLSearchParams({
|
|
3831
3916
|
route: pageRoute,
|
|
3832
3917
|
trackingId
|
|
3833
3918
|
});
|
|
3834
3919
|
if (isPreview) params.set("preview", "true");
|
|
3920
|
+
if (workingFlag) params.set("working", "true");
|
|
3835
3921
|
const url = `${orchestratorUrl}/api/layout/provider?${params.toString()}`;
|
|
3836
3922
|
try {
|
|
3837
3923
|
const res = await fetch(url, {
|
|
@@ -3853,7 +3939,9 @@ async function fetchPageConfigServer(route, trackingId, preview = false, options
|
|
|
3853
3939
|
preview: previewFlag,
|
|
3854
3940
|
orchestratorUrl,
|
|
3855
3941
|
edgeUrl,
|
|
3856
|
-
fetchOrchestratorPage
|
|
3942
|
+
fetchOrchestratorPage,
|
|
3943
|
+
revalidate: previewFlag ? void 0 : options?.revalidate ?? AMPLIFY_DEFAULT_REVALIDATE,
|
|
3944
|
+
variantKeys: previewFlag ? void 0 : options?.variantKeys
|
|
3857
3945
|
});
|
|
3858
3946
|
return result.pageConfig;
|
|
3859
3947
|
}
|
|
@@ -3943,10 +4031,9 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3943
4031
|
}, [config.trackingId, config.target, config.debug, config.dev, config.siteId]);
|
|
3944
4032
|
useEffect(() => {
|
|
3945
4033
|
if (!initialized) return;
|
|
4034
|
+
let cancelled = false;
|
|
3946
4035
|
const load = async () => {
|
|
3947
4036
|
try {
|
|
3948
|
-
setLoading(true);
|
|
3949
|
-
setError(null);
|
|
3950
4037
|
const actualRoute = getActualRoute();
|
|
3951
4038
|
if (!actualRoute) {
|
|
3952
4039
|
setLoading(false);
|
|
@@ -3955,6 +4042,15 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3955
4042
|
const sdk = getSDK();
|
|
3956
4043
|
sdk.routeChange(actualRoute);
|
|
3957
4044
|
const preview = isComposerPreview();
|
|
4045
|
+
const overlay = preview || config.clientPersonalization !== false;
|
|
4046
|
+
if (!overlay) {
|
|
4047
|
+
setPageConfig(null);
|
|
4048
|
+
setLoading(false);
|
|
4049
|
+
return;
|
|
4050
|
+
}
|
|
4051
|
+
setPageConfig(null);
|
|
4052
|
+
setError(null);
|
|
4053
|
+
setLoading(false);
|
|
3958
4054
|
const edgeUrl = sdk.getEdgeUrl();
|
|
3959
4055
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
3960
4056
|
const trackingId = sdk.getTrackingId();
|
|
@@ -3973,6 +4069,7 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3973
4069
|
edgeUrl,
|
|
3974
4070
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
3975
4071
|
});
|
|
4072
|
+
if (cancelled) return;
|
|
3976
4073
|
setSource(result.source);
|
|
3977
4074
|
setMeta(result.meta);
|
|
3978
4075
|
setError(result.error);
|
|
@@ -3988,16 +4085,20 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
3988
4085
|
setPageConfig(result.pageConfig);
|
|
3989
4086
|
}
|
|
3990
4087
|
} catch (err) {
|
|
4088
|
+
if (cancelled) return;
|
|
3991
4089
|
console.error("Error fetching page config:", err);
|
|
3992
4090
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
3993
4091
|
setSource(null);
|
|
3994
4092
|
setMeta(null);
|
|
3995
4093
|
} finally {
|
|
3996
|
-
setLoading(false);
|
|
4094
|
+
if (!cancelled) setLoading(false);
|
|
3997
4095
|
}
|
|
3998
4096
|
};
|
|
3999
4097
|
void load();
|
|
4000
|
-
|
|
4098
|
+
return () => {
|
|
4099
|
+
cancelled = true;
|
|
4100
|
+
};
|
|
4101
|
+
}, [pathname, initialized, config.clientPersonalization]);
|
|
4001
4102
|
return /* @__PURE__ */ jsx(
|
|
4002
4103
|
AmplifyUpContext.Provider,
|
|
4003
4104
|
{
|
|
@@ -4014,6 +4115,6 @@ function useAmplifyUp() {
|
|
|
4014
4115
|
return context;
|
|
4015
4116
|
}
|
|
4016
4117
|
|
|
4017
|
-
export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, Field, Image, RichText, Slot, fetchPageConfigServer, isComposerPreview, isPreviewRequest, useAmplifyUp, useComponentProps, useLiveComposerProps };
|
|
4118
|
+
export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, Field, Image, RichText, Slot, fetchPageConfigServer, isComposerPreview, isPreviewRequest, isWorkingContentRequest, useAmplifyUp, useComponentProps, useLiveComposerProps };
|
|
4018
4119
|
//# sourceMappingURL=react.mjs.map
|
|
4019
4120
|
//# sourceMappingURL=react.mjs.map
|