@amplifyup/sdk 0.1.77 → 0.1.78
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 -0
- package/dist/AmplifyRenderer.js +13 -3
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +13 -3
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +85 -39
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +86 -40
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React3, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, useRef, Component,
|
|
2
|
+
import React3, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, useRef, Component, useCallback, useSyncExternalStore } from 'react';
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import { marked } from 'marked';
|
|
5
5
|
|
|
@@ -166,6 +166,7 @@ var AWSAdapter = class {
|
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
169
|
+
const debug = this.config?.debug;
|
|
169
170
|
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
170
171
|
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
171
172
|
try {
|
|
@@ -180,15 +181,15 @@ var AWSAdapter = class {
|
|
|
180
181
|
keepalive: true
|
|
181
182
|
});
|
|
182
183
|
if (!response.ok) {
|
|
183
|
-
if (
|
|
184
|
+
if (debug) {
|
|
184
185
|
console.warn(`AmplifyUp SDK: Event tracking failed: ${response.status} ${response.statusText}`);
|
|
185
186
|
}
|
|
186
|
-
} else if (
|
|
187
|
+
} else if (debug) {
|
|
187
188
|
const result = await response.json().catch(() => ({}));
|
|
188
189
|
console.log("AmplifyUp SDK: Event tracked", result);
|
|
189
190
|
}
|
|
190
191
|
} catch (error) {
|
|
191
|
-
if (
|
|
192
|
+
if (debug) {
|
|
192
193
|
console.error("AmplifyUp SDK: Event tracking error:", error);
|
|
193
194
|
}
|
|
194
195
|
}
|
|
@@ -3951,6 +3952,14 @@ function getSDK(adapter) {
|
|
|
3951
3952
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3952
3953
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3953
3954
|
getSDK();
|
|
3955
|
+
var PageContentRegistryContext = createContext(null);
|
|
3956
|
+
function useRegisterPageContent(enabled = true) {
|
|
3957
|
+
const register = useContext(PageContentRegistryContext);
|
|
3958
|
+
useEffect(() => {
|
|
3959
|
+
if (!enabled || !register) return;
|
|
3960
|
+
return register();
|
|
3961
|
+
}, [enabled, register]);
|
|
3962
|
+
}
|
|
3954
3963
|
function useInComposer(force = false) {
|
|
3955
3964
|
const [detected, setDetected] = useState(false);
|
|
3956
3965
|
useEffect(() => {
|
|
@@ -4189,6 +4198,7 @@ function AmplifyRendererInner({
|
|
|
4189
4198
|
composerPreview
|
|
4190
4199
|
}) {
|
|
4191
4200
|
const clientHook = useAmplifyUp();
|
|
4201
|
+
useRegisterPageContent(!serverPageConfig);
|
|
4192
4202
|
const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
|
|
4193
4203
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
4194
4204
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
@@ -4703,6 +4713,7 @@ function AmplifyPageContent({
|
|
|
4703
4713
|
errorComponent
|
|
4704
4714
|
}) {
|
|
4705
4715
|
const client = useAmplifyUp();
|
|
4716
|
+
useRegisterPageContent();
|
|
4706
4717
|
const preview = useComposerPreviewFlag(forceComposerPreview);
|
|
4707
4718
|
const clientLayout = hasAmplifyLayout(client.pageConfig) ? client.pageConfig : null;
|
|
4708
4719
|
const serverLayout = hasAmplifyLayout(pageConfigProp) ? pageConfigProp : null;
|
|
@@ -5599,11 +5610,24 @@ function AmplifyUpProvider({
|
|
|
5599
5610
|
if (!initialized || !pageContext) return;
|
|
5600
5611
|
getSDK().setPageContext(pageContext);
|
|
5601
5612
|
}, [initialized, pageContextKey]);
|
|
5613
|
+
const contentMountsRef = useRef(0);
|
|
5614
|
+
const [hasPageContent, setHasPageContent] = useState(false);
|
|
5615
|
+
const registerPageContent = useCallback(() => {
|
|
5616
|
+
contentMountsRef.current += 1;
|
|
5617
|
+
setHasPageContent(true);
|
|
5618
|
+
return () => {
|
|
5619
|
+
contentMountsRef.current -= 1;
|
|
5620
|
+
if (contentMountsRef.current === 0) setHasPageContent(false);
|
|
5621
|
+
};
|
|
5622
|
+
}, []);
|
|
5623
|
+
const [initVersion, setInitVersion] = useState(0);
|
|
5624
|
+
const overlayEnabled = () => isComposerPreview() || config.clientPersonalization !== false;
|
|
5602
5625
|
useEffect(() => {
|
|
5603
5626
|
let cancelled = false;
|
|
5604
5627
|
const sdk = getSDK();
|
|
5605
|
-
|
|
5606
|
-
|
|
5628
|
+
if (contentMountsRef.current > 0 && overlayEnabled()) {
|
|
5629
|
+
sdk.beginPageResolve(getActualRoute());
|
|
5630
|
+
}
|
|
5607
5631
|
const run = async () => {
|
|
5608
5632
|
try {
|
|
5609
5633
|
await sdk.init({
|
|
@@ -5613,20 +5637,59 @@ function AmplifyUpProvider({
|
|
|
5613
5637
|
if (cancelled) return;
|
|
5614
5638
|
if (pageContext) sdk.setPageContext(pageContext);
|
|
5615
5639
|
const actualRoute = getActualRoute();
|
|
5616
|
-
if (
|
|
5640
|
+
if (actualRoute) sdk.routeChange(actualRoute);
|
|
5641
|
+
} catch (err) {
|
|
5642
|
+
if (cancelled) return;
|
|
5643
|
+
console.error("Error initializing AmplifyUp SDK:", err);
|
|
5644
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5645
|
+
} finally {
|
|
5646
|
+
if (!cancelled) {
|
|
5617
5647
|
setInitialized(true);
|
|
5618
|
-
|
|
5619
|
-
return;
|
|
5648
|
+
setInitVersion((v) => v + 1);
|
|
5620
5649
|
}
|
|
5621
|
-
|
|
5650
|
+
}
|
|
5651
|
+
};
|
|
5652
|
+
void run();
|
|
5653
|
+
return () => {
|
|
5654
|
+
cancelled = true;
|
|
5655
|
+
};
|
|
5656
|
+
}, [
|
|
5657
|
+
pathname,
|
|
5658
|
+
config.trackingId,
|
|
5659
|
+
config.target,
|
|
5660
|
+
config.debug,
|
|
5661
|
+
config.dev,
|
|
5662
|
+
config.siteId,
|
|
5663
|
+
config.clientPersonalization,
|
|
5664
|
+
pageContextKey
|
|
5665
|
+
]);
|
|
5666
|
+
const resolveRunRef = useRef(null);
|
|
5667
|
+
useEffect(() => {
|
|
5668
|
+
return () => {
|
|
5669
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5670
|
+
};
|
|
5671
|
+
}, []);
|
|
5672
|
+
useEffect(() => {
|
|
5673
|
+
if (initVersion === 0) return;
|
|
5674
|
+
if (resolveRunRef.current?.version === initVersion) return;
|
|
5675
|
+
const sdk = getSDK();
|
|
5676
|
+
const actualRoute = getActualRoute();
|
|
5677
|
+
if (!actualRoute || contentMountsRef.current === 0 || !overlayEnabled()) {
|
|
5678
|
+
if (actualRoute) sdk.endPageResolve(actualRoute);
|
|
5679
|
+
setPageConfig(null);
|
|
5680
|
+
setLoading(false);
|
|
5681
|
+
return;
|
|
5682
|
+
}
|
|
5683
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5684
|
+
const runState = { version: initVersion, cancelled: false };
|
|
5685
|
+
resolveRunRef.current = runState;
|
|
5686
|
+
const finish = () => {
|
|
5687
|
+
sdk.endPageResolve(actualRoute);
|
|
5688
|
+
if (!runState.cancelled) setLoading(false);
|
|
5689
|
+
};
|
|
5690
|
+
const run = async () => {
|
|
5691
|
+
try {
|
|
5622
5692
|
const preview = isComposerPreview();
|
|
5623
|
-
const overlay = preview || config.clientPersonalization !== false;
|
|
5624
|
-
if (!overlay) {
|
|
5625
|
-
setInitialized(true);
|
|
5626
|
-
setPageConfig(null);
|
|
5627
|
-
setLoading(false);
|
|
5628
|
-
return;
|
|
5629
|
-
}
|
|
5630
5693
|
if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
|
|
5631
5694
|
setPageConfig(null);
|
|
5632
5695
|
setError(null);
|
|
@@ -5635,9 +5698,7 @@ function AmplifyUpProvider({
|
|
|
5635
5698
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
5636
5699
|
const trackingId = sdk.getTrackingId();
|
|
5637
5700
|
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
5638
|
-
setInitialized(true);
|
|
5639
5701
|
setError("SDK not initialized");
|
|
5640
|
-
setLoading(false);
|
|
5641
5702
|
return;
|
|
5642
5703
|
}
|
|
5643
5704
|
let variantKeys;
|
|
@@ -5670,7 +5731,7 @@ function AmplifyUpProvider({
|
|
|
5670
5731
|
variantKeys,
|
|
5671
5732
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
5672
5733
|
});
|
|
5673
|
-
if (cancelled) return;
|
|
5734
|
+
if (runState.cancelled) return;
|
|
5674
5735
|
const nextConfig = result.pageConfig || {
|
|
5675
5736
|
id: "default",
|
|
5676
5737
|
route: actualRoute,
|
|
@@ -5687,7 +5748,6 @@ function AmplifyUpProvider({
|
|
|
5687
5748
|
result.pageConfig.pageTaxonomies || null
|
|
5688
5749
|
);
|
|
5689
5750
|
}
|
|
5690
|
-
setInitialized(true);
|
|
5691
5751
|
setSource((prev) => prev === result.source ? prev : result.source);
|
|
5692
5752
|
setMeta(
|
|
5693
5753
|
(prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
|
|
@@ -5701,31 +5761,17 @@ function AmplifyUpProvider({
|
|
|
5701
5761
|
});
|
|
5702
5762
|
loadedRouteRef.current = actualRoute;
|
|
5703
5763
|
} catch (err) {
|
|
5704
|
-
if (cancelled) return;
|
|
5764
|
+
if (runState.cancelled) return;
|
|
5705
5765
|
console.error("Error fetching page config:", err);
|
|
5706
|
-
setInitialized(true);
|
|
5707
5766
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5708
5767
|
setSource(null);
|
|
5709
5768
|
setMeta(null);
|
|
5710
5769
|
} finally {
|
|
5711
|
-
|
|
5712
|
-
if (!cancelled) setLoading(false);
|
|
5770
|
+
finish();
|
|
5713
5771
|
}
|
|
5714
5772
|
};
|
|
5715
5773
|
void run();
|
|
5716
|
-
|
|
5717
|
-
cancelled = true;
|
|
5718
|
-
};
|
|
5719
|
-
}, [
|
|
5720
|
-
pathname,
|
|
5721
|
-
config.trackingId,
|
|
5722
|
-
config.target,
|
|
5723
|
-
config.debug,
|
|
5724
|
-
config.dev,
|
|
5725
|
-
config.siteId,
|
|
5726
|
-
config.clientPersonalization,
|
|
5727
|
-
pageContextKey
|
|
5728
|
-
]);
|
|
5774
|
+
}, [initVersion, hasPageContent]);
|
|
5729
5775
|
useEffect(() => {
|
|
5730
5776
|
const applyLayoutTree = (layoutTree) => {
|
|
5731
5777
|
if (!Array.isArray(layoutTree)) return;
|
|
@@ -5759,13 +5805,13 @@ function AmplifyUpProvider({
|
|
|
5759
5805
|
window.removeEventListener("amplifyup:layout-patch", onCustom);
|
|
5760
5806
|
};
|
|
5761
5807
|
}, []);
|
|
5762
|
-
return /* @__PURE__ */ jsx(
|
|
5808
|
+
return /* @__PURE__ */ jsx(PageContentRegistryContext.Provider, { value: registerPageContent, children: /* @__PURE__ */ jsx(
|
|
5763
5809
|
AmplifyUpContext.Provider,
|
|
5764
5810
|
{
|
|
5765
5811
|
value: { pageConfig, loading, error, source, meta },
|
|
5766
5812
|
children
|
|
5767
5813
|
}
|
|
5768
|
-
);
|
|
5814
|
+
) });
|
|
5769
5815
|
}
|
|
5770
5816
|
function useAmplifyUp() {
|
|
5771
5817
|
const context = useContext(AmplifyUpContext);
|