@amplifyup/sdk 0.1.34 → 0.1.36
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 -2
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +140 -1
- package/dist/index.mjs.map +1 -1
- package/dist/query-6BmINKLR.d.mts +157 -0
- package/dist/query-DjIuJ71C.d.ts +157 -0
- package/dist/react.d.mts +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +163 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +158 -2
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +147 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +140 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
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
|
+
export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-6BmINKLR.mjs';
|
|
4
5
|
|
|
5
6
|
interface FetchContentResult {
|
|
6
7
|
pageConfig: PageConfig | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
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
|
+
export { g as FetchEdgeQueryOptions, F as FetchEdgeSelectOptions, Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, c as fetchEdgeQuery, f as fetchEdgeSelect, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DjIuJ71C.js';
|
|
4
5
|
|
|
5
6
|
interface FetchContentResult {
|
|
6
7
|
pageConfig: PageConfig | null;
|
package/dist/index.js
CHANGED
|
@@ -568,6 +568,145 @@ async function fetchContent(options) {
|
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
// src/edge/select.ts
|
|
572
|
+
var SelectVariantsError = class extends Error {
|
|
573
|
+
constructor(message, status, body) {
|
|
574
|
+
super(message);
|
|
575
|
+
this.name = "SelectVariantsError";
|
|
576
|
+
this.status = status;
|
|
577
|
+
this.body = body;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
async function fetchEdgeSelect(options) {
|
|
581
|
+
const base = options.edgeUrl.replace(/\/+$/, "");
|
|
582
|
+
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
583
|
+
if (!options.trackingId && !options.site) {
|
|
584
|
+
throw new SelectVariantsError("trackingId or site is required", 400);
|
|
585
|
+
}
|
|
586
|
+
const res = await fetchFn(`${base}/v1/select`, {
|
|
587
|
+
method: "POST",
|
|
588
|
+
headers: {
|
|
589
|
+
Accept: "application/json",
|
|
590
|
+
"Content-Type": "application/json"
|
|
591
|
+
},
|
|
592
|
+
cache: "no-store",
|
|
593
|
+
signal: options.signal,
|
|
594
|
+
body: JSON.stringify({
|
|
595
|
+
view: normalizeRoute(options.view),
|
|
596
|
+
...options.trackingId ? { trackingId: options.trackingId } : {},
|
|
597
|
+
...options.site ? { site: options.site } : {},
|
|
598
|
+
anonId: options.anonId,
|
|
599
|
+
...options.zones?.length ? { zones: options.zones } : {},
|
|
600
|
+
...options.context ? { context: options.context } : {}
|
|
601
|
+
})
|
|
602
|
+
});
|
|
603
|
+
const body = await res.json().catch(() => ({}));
|
|
604
|
+
if (!res.ok) {
|
|
605
|
+
throw new SelectVariantsError(
|
|
606
|
+
body.error || `Select failed (${res.status})`,
|
|
607
|
+
res.status,
|
|
608
|
+
body
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
siteId: String(body.siteId || ""),
|
|
613
|
+
view: String(body.view || normalizeRoute(options.view)),
|
|
614
|
+
variantKeys: body.variantKeys && typeof body.variantKeys === "object" ? body.variantKeys : {},
|
|
615
|
+
meta: body.meta
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
async function selectVariants(options) {
|
|
619
|
+
const target = resolveAmplifyUpTarget({ configTarget: options.target });
|
|
620
|
+
const { edgeUrl } = resolveAmplifyUpUrls(target);
|
|
621
|
+
return fetchEdgeSelect({
|
|
622
|
+
edgeUrl: options.edgeUrl || edgeUrl,
|
|
623
|
+
trackingId: options.trackingId,
|
|
624
|
+
site: options.site,
|
|
625
|
+
view: options.view,
|
|
626
|
+
anonId: options.anonId,
|
|
627
|
+
zones: options.zones,
|
|
628
|
+
context: options.context,
|
|
629
|
+
fetch: options.fetch,
|
|
630
|
+
signal: options.signal
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/edge/query.ts
|
|
635
|
+
var QueryContentError = class extends Error {
|
|
636
|
+
constructor(message, status, body) {
|
|
637
|
+
super(message);
|
|
638
|
+
this.name = "QueryContentError";
|
|
639
|
+
this.status = status;
|
|
640
|
+
this.body = body;
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
async function fetchEdgeQuery(options) {
|
|
644
|
+
const base = options.edgeUrl.replace(/\/+$/, "");
|
|
645
|
+
const fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
646
|
+
const limit = Math.max(1, Number(options.spec.limit) || 10);
|
|
647
|
+
const offset = Math.max(0, Number(options.spec.offset) || 0);
|
|
648
|
+
const res = await fetchFn(`${base}/v1/query`, {
|
|
649
|
+
method: "POST",
|
|
650
|
+
headers: {
|
|
651
|
+
Accept: "application/json",
|
|
652
|
+
"Content-Type": "application/json"
|
|
653
|
+
},
|
|
654
|
+
cache: "no-store",
|
|
655
|
+
signal: options.signal,
|
|
656
|
+
body: JSON.stringify({
|
|
657
|
+
route: normalizeRoute(options.route),
|
|
658
|
+
trackingId: options.trackingId,
|
|
659
|
+
...options.siteId ? { site: options.siteId } : {},
|
|
660
|
+
spec: { ...options.spec, limit, offset }
|
|
661
|
+
})
|
|
662
|
+
});
|
|
663
|
+
const body = await res.json().catch(() => ({}));
|
|
664
|
+
if (!res.ok) {
|
|
665
|
+
throw new QueryContentError(
|
|
666
|
+
body.error || `Content query failed (${res.status})`,
|
|
667
|
+
res.status,
|
|
668
|
+
body
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
const results = Array.isArray(body.results) ? body.results : [];
|
|
672
|
+
const resolvedLimit = Number(body.limit) || limit;
|
|
673
|
+
const resolvedOffset = Number.isFinite(Number(body.offset)) ? Number(body.offset) : offset;
|
|
674
|
+
return {
|
|
675
|
+
results,
|
|
676
|
+
count: Number(body.count) || results.length,
|
|
677
|
+
hasMore: !!body.hasMore,
|
|
678
|
+
limit: resolvedLimit,
|
|
679
|
+
offset: resolvedOffset,
|
|
680
|
+
nextOffset: Number(body.nextOffset) || resolvedOffset + resolvedLimit,
|
|
681
|
+
degraded: body.degraded
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
async function queryContent(options) {
|
|
685
|
+
const target = resolveAmplifyUpTarget({ configTarget: options.target });
|
|
686
|
+
const { edgeUrl } = resolveAmplifyUpUrls(target);
|
|
687
|
+
return fetchEdgeQuery({
|
|
688
|
+
edgeUrl,
|
|
689
|
+
trackingId: options.trackingId,
|
|
690
|
+
route: options.route,
|
|
691
|
+
spec: options.spec,
|
|
692
|
+
siteId: options.siteId,
|
|
693
|
+
fetch: options.fetch,
|
|
694
|
+
signal: options.signal
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
function nextPageSpec(pagination) {
|
|
698
|
+
return { ...pagination.spec, offset: pagination.nextOffset };
|
|
699
|
+
}
|
|
700
|
+
function searchSpec(pagination, field, term) {
|
|
701
|
+
const value = String(term || "").trim();
|
|
702
|
+
const base = { ...pagination.spec, offset: 0 };
|
|
703
|
+
if (!value) return base;
|
|
704
|
+
return {
|
|
705
|
+
...base,
|
|
706
|
+
filter: [...base.filter || [], { field, op: "contains", value }]
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
|
|
571
710
|
// src/index.ts
|
|
572
711
|
var SESSION_IDLE_GAP_MS = 30 * 60 * 1e3;
|
|
573
712
|
var DWELL_ACTIVITY_IDLE_MS = 2 * 60 * 1e3;
|
|
@@ -2898,13 +3037,17 @@ var index_default = getSDK();
|
|
|
2898
3037
|
exports.AmplifyUpSDK = AmplifyUpSDK;
|
|
2899
3038
|
exports.DWELL_ACTIVITY_IDLE_MS = DWELL_ACTIVITY_IDLE_MS;
|
|
2900
3039
|
exports.EdgeResolveError = EdgeResolveError;
|
|
3040
|
+
exports.QueryContentError = QueryContentError;
|
|
2901
3041
|
exports.SESSION_IDLE_GAP_MS = SESSION_IDLE_GAP_MS;
|
|
3042
|
+
exports.SelectVariantsError = SelectVariantsError;
|
|
2902
3043
|
exports.buildLayoutProviderUrl = buildLayoutProviderUrl;
|
|
2903
3044
|
exports.buildPageRenderUrl = buildPageRenderUrl;
|
|
2904
3045
|
exports.cleanupEventTracking = cleanupEventTracking;
|
|
2905
3046
|
exports.default = index_default;
|
|
2906
3047
|
exports.fetchContent = fetchContent;
|
|
3048
|
+
exports.fetchEdgeQuery = fetchEdgeQuery;
|
|
2907
3049
|
exports.fetchEdgeResolve = fetchEdgeResolve;
|
|
3050
|
+
exports.fetchEdgeSelect = fetchEdgeSelect;
|
|
2908
3051
|
exports.fetchPageConfig = fetchPageConfig;
|
|
2909
3052
|
exports.getDiagnostics = getDiagnostics;
|
|
2910
3053
|
exports.getInstanceId = getInstanceId2;
|
|
@@ -2921,14 +3064,18 @@ exports.isComposerPreview = isComposerPreview;
|
|
|
2921
3064
|
exports.isPreviewRequest = isPreviewRequest;
|
|
2922
3065
|
exports.isWorkingContentRequest = isWorkingContentRequest;
|
|
2923
3066
|
exports.mapResolvedToPageConfig = mapResolvedToPageConfig;
|
|
3067
|
+
exports.nextPageSpec = nextPageSpec;
|
|
2924
3068
|
exports.normalizeAmplifyUpTarget = normalizeAmplifyUpTarget;
|
|
2925
3069
|
exports.normalizeRoute = normalizeRoute;
|
|
2926
3070
|
exports.page = page;
|
|
3071
|
+
exports.queryContent = queryContent;
|
|
2927
3072
|
exports.refreshEventTracking = refreshEventTracking;
|
|
2928
3073
|
exports.reset = reset;
|
|
2929
3074
|
exports.resolveAmplifyUpTarget = resolveAmplifyUpTarget;
|
|
2930
3075
|
exports.resolveAmplifyUpUrls = resolveAmplifyUpUrls;
|
|
2931
3076
|
exports.routeChange = routeChange;
|
|
3077
|
+
exports.searchSpec = searchSpec;
|
|
3078
|
+
exports.selectVariants = selectVariants;
|
|
2932
3079
|
exports.setProfileFields = setProfileFields;
|
|
2933
3080
|
exports.setupComponentViewTracking = setupComponentViewTracking;
|
|
2934
3081
|
exports.setupEventTracking = setupEventTracking;
|