@amplifyup/sdk 0.1.33 → 0.1.35
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 +30 -1
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +30 -5
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +30 -5
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +208 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -11
- 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/query-6BmINKLR.d.mts +157 -0
- package/dist/query-DjIuJ71C.d.ts +157 -0
- package/dist/react.d.mts +7 -3
- package/dist/react.d.ts +7 -3
- package/dist/react.js +272 -19
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +267 -20
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +42 -5
- package/dist/server.d.ts +42 -5
- package/dist/server.js +278 -7
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +265 -8
- 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.mjs
CHANGED
|
@@ -195,6 +195,7 @@ var AWSAdapter = class {
|
|
|
195
195
|
// src/storage.ts
|
|
196
196
|
var INSTANCE_ID_KEY = "amplifyup_instance_id";
|
|
197
197
|
var USER_ID_KEY = "amplifyup_user_id";
|
|
198
|
+
var ANON_COOKIE_NAME = "amplifyup_anon_id";
|
|
198
199
|
function generateGuid() {
|
|
199
200
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
200
201
|
return crypto.randomUUID();
|
|
@@ -205,16 +206,39 @@ function generateGuid() {
|
|
|
205
206
|
return v.toString(16);
|
|
206
207
|
});
|
|
207
208
|
}
|
|
209
|
+
function readCookie(name) {
|
|
210
|
+
if (typeof document === "undefined") return null;
|
|
211
|
+
const parts = document.cookie.split(";");
|
|
212
|
+
for (const part of parts) {
|
|
213
|
+
const idx = part.indexOf("=");
|
|
214
|
+
if (idx === -1) continue;
|
|
215
|
+
if (part.slice(0, idx).trim() !== name) continue;
|
|
216
|
+
const value = part.slice(idx + 1).trim();
|
|
217
|
+
try {
|
|
218
|
+
return value ? decodeURIComponent(value) : null;
|
|
219
|
+
} catch {
|
|
220
|
+
return value || null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
function writeCookie(name, value) {
|
|
226
|
+
if (typeof document === "undefined") return;
|
|
227
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=31536000; SameSite=Lax`;
|
|
228
|
+
}
|
|
208
229
|
function getInstanceId() {
|
|
209
230
|
if (typeof window === "undefined") {
|
|
210
231
|
return "";
|
|
211
232
|
}
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
233
|
+
const fromCookie = readCookie(ANON_COOKIE_NAME);
|
|
234
|
+
const fromLs = localStorage.getItem(INSTANCE_ID_KEY);
|
|
235
|
+
const instanceId = fromLs || fromCookie || `browser_${generateGuid()}`;
|
|
236
|
+
if (fromLs !== instanceId) {
|
|
237
|
+
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
238
|
+
}
|
|
239
|
+
if (fromCookie !== instanceId) {
|
|
240
|
+
writeCookie(ANON_COOKIE_NAME, instanceId);
|
|
215
241
|
}
|
|
216
|
-
const instanceId = `browser_${generateGuid()}`;
|
|
217
|
-
localStorage.setItem(INSTANCE_ID_KEY, instanceId);
|
|
218
242
|
return instanceId;
|
|
219
243
|
}
|
|
220
244
|
function getUserId() {
|
|
@@ -235,6 +259,7 @@ function clearIds() {
|
|
|
235
259
|
}
|
|
236
260
|
localStorage.removeItem(INSTANCE_ID_KEY);
|
|
237
261
|
localStorage.removeItem(USER_ID_KEY);
|
|
262
|
+
document.cookie = `${ANON_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
238
263
|
}
|
|
239
264
|
|
|
240
265
|
// src/targets.ts
|
|
@@ -362,6 +387,19 @@ function normalizeRoute(route) {
|
|
|
362
387
|
return path || "/";
|
|
363
388
|
}
|
|
364
389
|
|
|
390
|
+
// src/edge/variantKeys.ts
|
|
391
|
+
function serializeVariantKeys(keys) {
|
|
392
|
+
if (!keys) return "";
|
|
393
|
+
const parts = [];
|
|
394
|
+
const zoneIds = Object.keys(keys).sort();
|
|
395
|
+
for (const zoneId of zoneIds) {
|
|
396
|
+
const variant = keys[zoneId];
|
|
397
|
+
if (!variant || variant === "default") continue;
|
|
398
|
+
parts.push(`${zoneId}:${variant}`);
|
|
399
|
+
}
|
|
400
|
+
return parts.join(",");
|
|
401
|
+
}
|
|
402
|
+
|
|
365
403
|
// src/edge/resolve.ts
|
|
366
404
|
var EdgeResolveError = class extends Error {
|
|
367
405
|
constructor(message, status, body) {
|
|
@@ -379,12 +417,23 @@ async function fetchEdgeResolve(options) {
|
|
|
379
417
|
trackingId: options.trackingId
|
|
380
418
|
});
|
|
381
419
|
if (options.siteId) params.set("site", options.siteId);
|
|
382
|
-
|
|
420
|
+
const variantParam = serializeVariantKeys(options.variantKeys);
|
|
421
|
+
if (variantParam) {
|
|
422
|
+
params.set("variants", variantParam);
|
|
423
|
+
} else if (options.anonId) {
|
|
424
|
+
params.set("anonId", options.anonId);
|
|
425
|
+
}
|
|
383
426
|
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
384
|
-
const
|
|
427
|
+
const init2 = {
|
|
385
428
|
method: "GET",
|
|
386
429
|
headers: { Accept: "application/json" }
|
|
387
|
-
}
|
|
430
|
+
};
|
|
431
|
+
if (options.revalidate !== void 0) {
|
|
432
|
+
init2.next = { revalidate: options.revalidate };
|
|
433
|
+
} else {
|
|
434
|
+
init2.cache = "no-store";
|
|
435
|
+
}
|
|
436
|
+
const res = await fetchFn(`${base}/v1/resolve?${params.toString()}`, init2);
|
|
388
437
|
const body = await res.json().catch(() => ({}));
|
|
389
438
|
if (!res.ok) {
|
|
390
439
|
throw new EdgeResolveError(
|
|
@@ -473,9 +522,11 @@ async function fetchContent(options) {
|
|
|
473
522
|
edgeUrl: options.edgeUrl,
|
|
474
523
|
trackingId: options.trackingId,
|
|
475
524
|
route: options.route,
|
|
476
|
-
anonId: options.anonId,
|
|
525
|
+
anonId: options.variantKeys ? void 0 : options.anonId,
|
|
477
526
|
siteId: options.siteId,
|
|
478
|
-
fetch: options.fetchFn
|
|
527
|
+
fetch: options.fetchFn,
|
|
528
|
+
revalidate: options.revalidate,
|
|
529
|
+
variantKeys: options.variantKeys
|
|
479
530
|
});
|
|
480
531
|
const pageConfig = mapResolvedToPageConfig(payload);
|
|
481
532
|
const degraded = collectDegraded(payload);
|
|
@@ -513,6 +564,145 @@ async function fetchContent(options) {
|
|
|
513
564
|
}
|
|
514
565
|
}
|
|
515
566
|
|
|
567
|
+
// src/edge/select.ts
|
|
568
|
+
var SelectVariantsError = class extends Error {
|
|
569
|
+
constructor(message, status, body) {
|
|
570
|
+
super(message);
|
|
571
|
+
this.name = "SelectVariantsError";
|
|
572
|
+
this.status = status;
|
|
573
|
+
this.body = body;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
async function fetchEdgeSelect(options) {
|
|
577
|
+
const base = options.edgeUrl.replace(/\/+$/, "");
|
|
578
|
+
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
579
|
+
if (!options.trackingId && !options.site) {
|
|
580
|
+
throw new SelectVariantsError("trackingId or site is required", 400);
|
|
581
|
+
}
|
|
582
|
+
const res = await fetchFn(`${base}/v1/select`, {
|
|
583
|
+
method: "POST",
|
|
584
|
+
headers: {
|
|
585
|
+
Accept: "application/json",
|
|
586
|
+
"Content-Type": "application/json"
|
|
587
|
+
},
|
|
588
|
+
cache: "no-store",
|
|
589
|
+
signal: options.signal,
|
|
590
|
+
body: JSON.stringify({
|
|
591
|
+
view: normalizeRoute(options.view),
|
|
592
|
+
...options.trackingId ? { trackingId: options.trackingId } : {},
|
|
593
|
+
...options.site ? { site: options.site } : {},
|
|
594
|
+
anonId: options.anonId,
|
|
595
|
+
...options.zones?.length ? { zones: options.zones } : {},
|
|
596
|
+
...options.context ? { context: options.context } : {}
|
|
597
|
+
})
|
|
598
|
+
});
|
|
599
|
+
const body = await res.json().catch(() => ({}));
|
|
600
|
+
if (!res.ok) {
|
|
601
|
+
throw new SelectVariantsError(
|
|
602
|
+
body.error || `Select failed (${res.status})`,
|
|
603
|
+
res.status,
|
|
604
|
+
body
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
return {
|
|
608
|
+
siteId: String(body.siteId || ""),
|
|
609
|
+
view: String(body.view || normalizeRoute(options.view)),
|
|
610
|
+
variantKeys: body.variantKeys && typeof body.variantKeys === "object" ? body.variantKeys : {},
|
|
611
|
+
meta: body.meta
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
async function selectVariants(options) {
|
|
615
|
+
const target = resolveAmplifyUpTarget({ configTarget: options.target });
|
|
616
|
+
const { edgeUrl } = resolveAmplifyUpUrls(target);
|
|
617
|
+
return fetchEdgeSelect({
|
|
618
|
+
edgeUrl: options.edgeUrl || edgeUrl,
|
|
619
|
+
trackingId: options.trackingId,
|
|
620
|
+
site: options.site,
|
|
621
|
+
view: options.view,
|
|
622
|
+
anonId: options.anonId,
|
|
623
|
+
zones: options.zones,
|
|
624
|
+
context: options.context,
|
|
625
|
+
fetch: options.fetch,
|
|
626
|
+
signal: options.signal
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// src/edge/query.ts
|
|
631
|
+
var QueryContentError = class extends Error {
|
|
632
|
+
constructor(message, status, body) {
|
|
633
|
+
super(message);
|
|
634
|
+
this.name = "QueryContentError";
|
|
635
|
+
this.status = status;
|
|
636
|
+
this.body = body;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
async function fetchEdgeQuery(options) {
|
|
640
|
+
const base = options.edgeUrl.replace(/\/+$/, "");
|
|
641
|
+
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
642
|
+
const limit = Math.max(1, Number(options.spec.limit) || 10);
|
|
643
|
+
const offset = Math.max(0, Number(options.spec.offset) || 0);
|
|
644
|
+
const res = await fetchFn(`${base}/v1/query`, {
|
|
645
|
+
method: "POST",
|
|
646
|
+
headers: {
|
|
647
|
+
Accept: "application/json",
|
|
648
|
+
"Content-Type": "application/json"
|
|
649
|
+
},
|
|
650
|
+
cache: "no-store",
|
|
651
|
+
signal: options.signal,
|
|
652
|
+
body: JSON.stringify({
|
|
653
|
+
route: normalizeRoute(options.route),
|
|
654
|
+
trackingId: options.trackingId,
|
|
655
|
+
...options.siteId ? { site: options.siteId } : {},
|
|
656
|
+
spec: { ...options.spec, limit, offset }
|
|
657
|
+
})
|
|
658
|
+
});
|
|
659
|
+
const body = await res.json().catch(() => ({}));
|
|
660
|
+
if (!res.ok) {
|
|
661
|
+
throw new QueryContentError(
|
|
662
|
+
body.error || `Content query failed (${res.status})`,
|
|
663
|
+
res.status,
|
|
664
|
+
body
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
const results = Array.isArray(body.results) ? body.results : [];
|
|
668
|
+
const resolvedLimit = Number(body.limit) || limit;
|
|
669
|
+
const resolvedOffset = Number.isFinite(Number(body.offset)) ? Number(body.offset) : offset;
|
|
670
|
+
return {
|
|
671
|
+
results,
|
|
672
|
+
count: Number(body.count) || results.length,
|
|
673
|
+
hasMore: !!body.hasMore,
|
|
674
|
+
limit: resolvedLimit,
|
|
675
|
+
offset: resolvedOffset,
|
|
676
|
+
nextOffset: Number(body.nextOffset) || resolvedOffset + resolvedLimit,
|
|
677
|
+
degraded: body.degraded
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
async function queryContent(options) {
|
|
681
|
+
const target = resolveAmplifyUpTarget({ configTarget: options.target });
|
|
682
|
+
const { edgeUrl } = resolveAmplifyUpUrls(target);
|
|
683
|
+
return fetchEdgeQuery({
|
|
684
|
+
edgeUrl,
|
|
685
|
+
trackingId: options.trackingId,
|
|
686
|
+
route: options.route,
|
|
687
|
+
spec: options.spec,
|
|
688
|
+
siteId: options.siteId,
|
|
689
|
+
fetch: options.fetch,
|
|
690
|
+
signal: options.signal
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
function nextPageSpec(pagination) {
|
|
694
|
+
return { ...pagination.spec, offset: pagination.nextOffset };
|
|
695
|
+
}
|
|
696
|
+
function searchSpec(pagination, field, term) {
|
|
697
|
+
const value = String(term || "").trim();
|
|
698
|
+
const base = { ...pagination.spec, offset: 0 };
|
|
699
|
+
if (!value) return base;
|
|
700
|
+
return {
|
|
701
|
+
...base,
|
|
702
|
+
filter: [...base.filter || [], { field, op: "contains", value }]
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
516
706
|
// src/index.ts
|
|
517
707
|
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
518
708
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
@@ -2840,6 +3030,6 @@ var verifyAWSConnection = () => {
|
|
|
2840
3030
|
};
|
|
2841
3031
|
var index_default = getSDK();
|
|
2842
3032
|
|
|
2843
|
-
export { AmplifyUpSDK, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, index_default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId2 as getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId2 as getUserId, identify, init, isAmplifyUpTarget, isComposerPreview, isPreviewRequest, isWorkingContentRequest, mapResolvedToPageConfig, normalizeAmplifyUpTarget, normalizeRoute, page, refreshEventTracking, reset, resolveAmplifyUpTarget, resolveAmplifyUpUrls, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
3033
|
+
export { AmplifyUpSDK, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, QueryContentError, SESSION_IDLE_GAP_MS, SelectVariantsError, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, index_default as default, fetchContent, fetchEdgeQuery, fetchEdgeResolve, fetchEdgeSelect, fetchPageConfig, getDiagnostics, getInstanceId2 as getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId2 as getUserId, identify, init, isAmplifyUpTarget, isComposerPreview, isPreviewRequest, isWorkingContentRequest, mapResolvedToPageConfig, nextPageSpec, normalizeAmplifyUpTarget, normalizeRoute, page, queryContent, refreshEventTracking, reset, resolveAmplifyUpTarget, resolveAmplifyUpUrls, routeChange, searchSpec, selectVariants, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
|
|
2844
3034
|
//# sourceMappingURL=index.mjs.map
|
|
2845
3035
|
//# sourceMappingURL=index.mjs.map
|