@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 CHANGED
@@ -84,9 +84,10 @@ Field names must match the component registry in AmplifyUp. Connect CMS document
84
84
  | Mode | Source | When |
85
85
  |------|--------|------|
86
86
  | Production visitors | Edge `/v1/resolve` | Default |
87
+ | Next.js SSG / ISR | Edge `/v1/routes` then `/v1/resolve` | `generateAmplifyStaticParams` + `fetchPageConfigServer` |
87
88
  | Composer preview | Orchestrator layout provider | `?preview=true` / Composer iframe |
88
89
 
89
- The SDK maps Edge’s resolved tree into `layoutTree` and renders it. Edge already applies personalization and CMS projection — the site does not call CMS or Decision APIs for layout.
90
+ The SDK maps Edge’s resolved tree into `layoutTree` and renders it. Edge already applies personalization and CMS projection — the site does not call CMS or Decision APIs for layout. Visitor-specific variants overlay the static HTML in the browser by default (`clientPersonalization`).
90
91
 
91
92
  ## Track events
92
93
 
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { P as PageConfig } from './types-npF_lNoq.mjs';
3
+ import { P as PageConfig } from './types-CBoVIFI8.mjs';
4
4
 
5
5
  interface AmplifyRendererProps {
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { P as PageConfig } from './types-npF_lNoq.js';
3
+ import { P as PageConfig } from './types-CBoVIFI8.js';
4
4
 
5
5
  interface AmplifyRendererProps {
6
6
  /**
@@ -208,6 +208,7 @@ var AWSAdapter = class {
208
208
  // src/storage.ts
209
209
  var INSTANCE_ID_KEY = "amplifyup_instance_id";
210
210
  var USER_ID_KEY = "amplifyup_user_id";
211
+ var ANON_COOKIE_NAME = "amplifyup_anon_id";
211
212
  function generateGuid() {
212
213
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
213
214
  return crypto.randomUUID();
@@ -218,16 +219,39 @@ function generateGuid() {
218
219
  return v.toString(16);
219
220
  });
220
221
  }
222
+ function readCookie(name) {
223
+ if (typeof document === "undefined") return null;
224
+ const parts = document.cookie.split(";");
225
+ for (const part of parts) {
226
+ const idx = part.indexOf("=");
227
+ if (idx === -1) continue;
228
+ if (part.slice(0, idx).trim() !== name) continue;
229
+ const value = part.slice(idx + 1).trim();
230
+ try {
231
+ return value ? decodeURIComponent(value) : null;
232
+ } catch {
233
+ return value || null;
234
+ }
235
+ }
236
+ return null;
237
+ }
238
+ function writeCookie(name, value) {
239
+ if (typeof document === "undefined") return;
240
+ document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=31536000; SameSite=Lax`;
241
+ }
221
242
  function getInstanceId() {
222
243
  if (typeof window === "undefined") {
223
244
  return "";
224
245
  }
225
- const stored = localStorage.getItem(INSTANCE_ID_KEY);
226
- if (stored) {
227
- return stored;
246
+ const fromCookie = readCookie(ANON_COOKIE_NAME);
247
+ const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
248
+ const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
249
+ if (fromLs !== instanceId) {
250
+ localStorage.setItem(INSTANCE_ID_KEY, instanceId);
251
+ }
252
+ if (fromCookie !== instanceId) {
253
+ writeCookie(ANON_COOKIE_NAME, instanceId);
228
254
  }
229
- const instanceId = `browser_${generateGuid()}`;
230
- localStorage.setItem(INSTANCE_ID_KEY, instanceId);
231
255
  return instanceId;
232
256
  }
233
257
  function getUserId() {
@@ -248,6 +272,7 @@ function clearIds() {
248
272
  }
249
273
  localStorage.removeItem(INSTANCE_ID_KEY);
250
274
  localStorage.removeItem(USER_ID_KEY);
275
+ document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
251
276
  }
252
277
 
253
278
  // src/targets.ts
@@ -325,12 +350,17 @@ function resolveAmplifyUpUrls(target) {
325
350
 
326
351
  // src/preview.ts
327
352
  function isPreviewRequest(searchParams) {
353
+ return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
354
+ }
355
+ function isWorkingContentRequest(searchParams) {
356
+ return paramIsTrue(searchParams, "working");
357
+ }
358
+ function paramIsTrue(searchParams, key) {
328
359
  if (searchParams instanceof URLSearchParams) {
329
- return searchParams.get("preview") === "true" || searchParams.get("visualEditor") === "true";
360
+ return searchParams.get(key) === "true";
330
361
  }
331
- const preview = searchParams.preview;
332
- const visualEditor = searchParams.visualEditor;
333
- return preview === "true" || visualEditor === "true";
362
+ const value = searchParams[key];
363
+ return value === "true" || Array.isArray(value) && value[0] === "true";
334
364
  }
335
365
  function isComposerPreview() {
336
366
  if (typeof window === "undefined") return false;
@@ -1294,6 +1324,9 @@ Available Console Commands:
1294
1324
  });
1295
1325
  if (preview) {
1296
1326
  params.set("preview", "true");
1327
+ if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
1328
+ params.set("working", "true");
1329
+ }
1297
1330
  }
1298
1331
  if (isOnOrchestratorOrigin) {
1299
1332
  return `/api/layout/provider?${params.toString()}`;