@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/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as CDPAdapter, b as AmplifyUpConfig, c as EventProperties, I as IdentifyInput, d as IdentifyTraits, e as ProfileFieldsInput, f as AmplifyUpTarget } from './types-
|
|
2
|
-
export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-
|
|
3
|
-
export { i as isComposerPreview, a as isPreviewRequest } from './preview-
|
|
1
|
+
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as CDPAdapter, b as AmplifyUpConfig, c as EventProperties, I as IdentifyInput, d as IdentifyTraits, e as ProfileFieldsInput, f as AmplifyUpTarget } from './types-CBoVIFI8.mjs';
|
|
2
|
+
export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-CBoVIFI8.mjs';
|
|
3
|
+
export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
|
|
4
4
|
|
|
5
5
|
interface FetchContentResult {
|
|
6
6
|
pageConfig: PageConfig | null;
|
|
@@ -20,6 +20,10 @@ interface FetchContentOptions {
|
|
|
20
20
|
/** Orchestrator layout fetch (SDK instance method or server helper). */
|
|
21
21
|
fetchOrchestratorPage: (route: string, preview: boolean) => Promise<PageConfig | null>;
|
|
22
22
|
fetchFn?: typeof fetch;
|
|
23
|
+
/** Next.js ISR for Edge resolve (server/SSG only). */
|
|
24
|
+
revalidate?: number | false;
|
|
25
|
+
/** Deterministic variants for ISR (no visitor id in the cache key). */
|
|
26
|
+
variantKeys?: Record<string, string> | null;
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
29
|
* Single content entry point:
|
|
@@ -80,7 +84,14 @@ declare function fetchEdgeResolve(options: {
|
|
|
80
84
|
route: string;
|
|
81
85
|
anonId?: string | null;
|
|
82
86
|
siteId?: string | null;
|
|
87
|
+
/** Deterministic variant combo — cacheable; do not send with anonId. */
|
|
88
|
+
variantKeys?: Record<string, string> | null;
|
|
83
89
|
fetch?: typeof fetch;
|
|
90
|
+
/**
|
|
91
|
+
* Next.js Data Cache / ISR. When set, the server fetch can be baked into
|
|
92
|
+
* SSG. Omit on the client so visitor-specific resolve stays fresh.
|
|
93
|
+
*/
|
|
94
|
+
revalidate?: number | false;
|
|
84
95
|
}): Promise<EdgeResolvedPayload>;
|
|
85
96
|
|
|
86
97
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as CDPAdapter, b as AmplifyUpConfig, c as EventProperties, I as IdentifyInput, d as IdentifyTraits, e as ProfileFieldsInput, f as AmplifyUpTarget } from './types-
|
|
2
|
-
export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-
|
|
3
|
-
export { i as isComposerPreview, a as isPreviewRequest } from './preview-
|
|
1
|
+
import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, E as EventTrackingConfig$1, a as CDPAdapter, b as AmplifyUpConfig, c as EventProperties, I as IdentifyInput, d as IdentifyTraits, e as ProfileFieldsInput, f as AmplifyUpTarget } from './types-CBoVIFI8.js';
|
|
2
|
+
export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-CBoVIFI8.js';
|
|
3
|
+
export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
|
|
4
4
|
|
|
5
5
|
interface FetchContentResult {
|
|
6
6
|
pageConfig: PageConfig | null;
|
|
@@ -20,6 +20,10 @@ interface FetchContentOptions {
|
|
|
20
20
|
/** Orchestrator layout fetch (SDK instance method or server helper). */
|
|
21
21
|
fetchOrchestratorPage: (route: string, preview: boolean) => Promise<PageConfig | null>;
|
|
22
22
|
fetchFn?: typeof fetch;
|
|
23
|
+
/** Next.js ISR for Edge resolve (server/SSG only). */
|
|
24
|
+
revalidate?: number | false;
|
|
25
|
+
/** Deterministic variants for ISR (no visitor id in the cache key). */
|
|
26
|
+
variantKeys?: Record<string, string> | null;
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
29
|
* Single content entry point:
|
|
@@ -80,7 +84,14 @@ declare function fetchEdgeResolve(options: {
|
|
|
80
84
|
route: string;
|
|
81
85
|
anonId?: string | null;
|
|
82
86
|
siteId?: string | null;
|
|
87
|
+
/** Deterministic variant combo — cacheable; do not send with anonId. */
|
|
88
|
+
variantKeys?: Record<string, string> | null;
|
|
83
89
|
fetch?: typeof fetch;
|
|
90
|
+
/**
|
|
91
|
+
* Next.js Data Cache / ISR. When set, the server fetch can be baked into
|
|
92
|
+
* SSG. Omit on the client so visitor-specific resolve stays fresh.
|
|
93
|
+
*/
|
|
94
|
+
revalidate?: number | false;
|
|
84
95
|
}): Promise<EdgeResolvedPayload>;
|
|
85
96
|
|
|
86
97
|
/**
|
package/dist/index.js
CHANGED
|
@@ -199,6 +199,7 @@ var AWSAdapter = class {
|
|
|
199
199
|
// src/storage.ts
|
|
200
200
|
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
201
201
|
var USER_ID_KEY = "amplifyup_user_id";
|
|
202
|
+
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
202
203
|
function generateGuid() {
|
|
203
204
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
204
205
|
return crypto.randomUUID();
|
|
@@ -209,16 +210,39 @@ function generateGuid() {
|
|
|
209
210
|
return v.toString(16);
|
|
210
211
|
});
|
|
211
212
|
}
|
|
213
|
+
function readCookie(name) {
|
|
214
|
+
if (typeof document === "undefined") return null;
|
|
215
|
+
const parts = document.cookie.split(";");
|
|
216
|
+
for (const part of parts) {
|
|
217
|
+
const idx = part.indexOf("=");
|
|
218
|
+
if (idx === -1) continue;
|
|
219
|
+
if (part.slice(0, idx).trim() !== name) continue;
|
|
220
|
+
const value = part.slice(idx + 1).trim();
|
|
221
|
+
try {
|
|
222
|
+
return value ? decodeURIComponent(value) : null;
|
|
223
|
+
} catch {
|
|
224
|
+
return value || null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
function writeCookie(name, value) {
|
|
230
|
+
if (typeof document === "undefined") return;
|
|
231
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=31536000; SameSite=Lax`;
|
|
232
|
+
}
|
|
212
233
|
function getInstanceId() {
|
|
213
234
|
if (typeof window === "undefined") {
|
|
214
235
|
return "";
|
|
215
236
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
237
|
+
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
238
|
+
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
239
|
+
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
240
|
+
if (fromLs !== instanceId) {
|
|
241
|
+
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
242
|
+
}
|
|
243
|
+
if (fromCookie !== instanceId) {
|
|
244
|
+
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
219
245
|
}
|
|
220
|
-
const instanceId = `browser_${generateGuid()}`;
|
|
221
|
-
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
222
246
|
return instanceId;
|
|
223
247
|
}
|
|
224
248
|
function getUserId() {
|
|
@@ -239,6 +263,7 @@ function clearIds() {
|
|
|
239
263
|
}
|
|
240
264
|
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
241
265
|
localStorage.removeItem(USER_ID_KEY);
|
|
266
|
+
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
242
267
|
}
|
|
243
268
|
|
|
244
269
|
// src/targets.ts
|
|
@@ -316,12 +341,17 @@ function resolveAmplifyUpUrls(target) {
|
|
|
316
341
|
|
|
317
342
|
// src/preview.ts
|
|
318
343
|
function isPreviewRequest(searchParams) {
|
|
344
|
+
return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
|
|
345
|
+
}
|
|
346
|
+
function isWorkingContentRequest(searchParams) {
|
|
347
|
+
return paramIsTrue(searchParams, "working");
|
|
348
|
+
}
|
|
349
|
+
function paramIsTrue(searchParams, key) {
|
|
319
350
|
if (searchParams instanceof URLSearchParams) {
|
|
320
|
-
return searchParams.get(
|
|
351
|
+
return searchParams.get(key) === "true";
|
|
321
352
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
return preview === "true" || visualEditor === "true";
|
|
353
|
+
const value = searchParams[key];
|
|
354
|
+
return value === "true" || Array.isArray(value) && value[0] === "true";
|
|
325
355
|
}
|
|
326
356
|
function isComposerPreview() {
|
|
327
357
|
if (typeof window === "undefined") return false;
|
|
@@ -361,6 +391,19 @@ function normalizeRoute(route) {
|
|
|
361
391
|
return path || "/";
|
|
362
392
|
}
|
|
363
393
|
|
|
394
|
+
// src/edge/variantKeys.ts
|
|
395
|
+
function serializeVariantKeys(keys) {
|
|
396
|
+
if (!keys) return "";
|
|
397
|
+
const parts = [];
|
|
398
|
+
const zoneIds = Object.keys(keys).sort();
|
|
399
|
+
for (const zoneId of zoneIds) {
|
|
400
|
+
const variant = keys[zoneId];
|
|
401
|
+
if (!variant || variant === "default") continue;
|
|
402
|
+
parts.push(`${zoneId}:${variant}`);
|
|
403
|
+
}
|
|
404
|
+
return parts.join(",");
|
|
405
|
+
}
|
|
406
|
+
|
|
364
407
|
// src/edge/resolve.ts
|
|
365
408
|
var EdgeResolveError = class extends Error {
|
|
366
409
|
constructor(message, status, body) {
|
|
@@ -378,12 +421,23 @@ async function fetchEdgeResolve(options) {
|
|
|
378
421
|
trackingId: options.trackingId
|
|
379
422
|
});
|
|
380
423
|
if (options.siteId) params.set("site", options.siteId);
|
|
381
|
-
|
|
424
|
+
const variantParam = serializeVariantKeys(options.variantKeys);
|
|
425
|
+
if (variantParam) {
|
|
426
|
+
params.set("variants", variantParam);
|
|
427
|
+
} else if (options.anonId) {
|
|
428
|
+
params.set("anonId", options.anonId);
|
|
429
|
+
}
|
|
382
430
|
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
383
|
-
const
|
|
431
|
+
const init2 = {
|
|
384
432
|
method: "GET",
|
|
385
433
|
headers: { Accept: "application/json" }
|
|
386
|
-
}
|
|
434
|
+
};
|
|
435
|
+
if (options.revalidate !== void 0) {
|
|
436
|
+
init2.next = { revalidate: options.revalidate };
|
|
437
|
+
} else {
|
|
438
|
+
init2.cache = "no-store";
|
|
439
|
+
}
|
|
440
|
+
const res = await fetchFn(`${base}/v1/resolve?${params.toString()}`, init2);
|
|
387
441
|
const body = await res.json().catch(() => ({}));
|
|
388
442
|
if (!res.ok) {
|
|
389
443
|
throw new EdgeResolveError(
|
|
@@ -472,9 +526,11 @@ async function fetchContent(options) {
|
|
|
472
526
|
edgeUrl: options.edgeUrl,
|
|
473
527
|
trackingId: options.trackingId,
|
|
474
528
|
route: options.route,
|
|
475
|
-
anonId: options.anonId,
|
|
529
|
+
anonId: options.variantKeys ? void 0 : options.anonId,
|
|
476
530
|
siteId: options.siteId,
|
|
477
|
-
fetch: options.fetchFn
|
|
531
|
+
fetch: options.fetchFn,
|
|
532
|
+
revalidate: options.revalidate,
|
|
533
|
+
variantKeys: options.variantKeys
|
|
478
534
|
});
|
|
479
535
|
const pageConfig = mapResolvedToPageConfig(payload);
|
|
480
536
|
const degraded = collectDegraded(payload);
|
|
@@ -1457,6 +1513,9 @@ Available Console Commands:
|
|
|
1457
1513
|
});
|
|
1458
1514
|
if (preview) {
|
|
1459
1515
|
params.set("preview", "true");
|
|
1516
|
+
if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
|
|
1517
|
+
params.set("working", "true");
|
|
1518
|
+
}
|
|
1460
1519
|
}
|
|
1461
1520
|
if (isOnOrchestratorOrigin) {
|
|
1462
1521
|
return `/api/layout/provider?${params.toString()}`;
|
|
@@ -2860,6 +2919,7 @@ exports.init = init;
|
|
|
2860
2919
|
exports.isAmplifyUpTarget = isAmplifyUpTarget;
|
|
2861
2920
|
exports.isComposerPreview = isComposerPreview;
|
|
2862
2921
|
exports.isPreviewRequest = isPreviewRequest;
|
|
2922
|
+
exports.isWorkingContentRequest = isWorkingContentRequest;
|
|
2863
2923
|
exports.mapResolvedToPageConfig = mapResolvedToPageConfig;
|
|
2864
2924
|
exports.normalizeAmplifyUpTarget = normalizeAmplifyUpTarget;
|
|
2865
2925
|
exports.normalizeRoute = normalizeRoute;
|