@amplifyup/sdk 0.1.33 → 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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
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-npF_lNoq.mjs';
2
- export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-npF_lNoq.mjs';
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
3
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
4
4
 
5
5
  interface FetchContentResult {
@@ -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,5 +1,5 @@
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-npF_lNoq.js';
2
- export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-npF_lNoq.js';
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
3
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
4
4
 
5
5
  interface FetchContentResult {
@@ -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 stored = localStorage.getItem(INSTANCE_ID_KEY);
217
- if (stored) {
218
- return stored;
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
@@ -366,6 +391,19 @@ function normalizeRoute(route) {
366
391
  return path || "/";
367
392
  }
368
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
+
369
407
  // src/edge/resolve.ts
370
408
  var EdgeResolveError = class extends Error {
371
409
  constructor(message, status, body) {
@@ -383,12 +421,23 @@ async function fetchEdgeResolve(options) {
383
421
  trackingId: options.trackingId
384
422
  });
385
423
  if (options.siteId) params.set("site", options.siteId);
386
- if (options.anonId) params.set("anonId", options.anonId);
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
+ }
387
430
  const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
388
- const res = await fetchFn(`${base}/v1/resolve?${params.toString()}`, {
431
+ const init2 = {
389
432
  method: "GET",
390
433
  headers: { Accept: "application/json" }
391
- });
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);
392
441
  const body = await res.json().catch(() => ({}));
393
442
  if (!res.ok) {
394
443
  throw new EdgeResolveError(
@@ -477,9 +526,11 @@ async function fetchContent(options) {
477
526
  edgeUrl: options.edgeUrl,
478
527
  trackingId: options.trackingId,
479
528
  route: options.route,
480
- anonId: options.anonId,
529
+ anonId: options.variantKeys ? void 0 : options.anonId,
481
530
  siteId: options.siteId,
482
- fetch: options.fetchFn
531
+ fetch: options.fetchFn,
532
+ revalidate: options.revalidate,
533
+ variantKeys: options.variantKeys
483
534
  });
484
535
  const pageConfig = mapResolvedToPageConfig(payload);
485
536
  const degraded = collectDegraded(payload);