@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.js
CHANGED
|
@@ -172,6 +172,7 @@ var AWSAdapter = class {
|
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
const trackingId = eventData?.trackingId || this.config?.trackingId;
|
|
175
|
+
const debug = this.config?.debug;
|
|
175
176
|
const query = trackingId ? `?tid=${encodeURIComponent(trackingId)}` : "";
|
|
176
177
|
const url = `${this.apiGatewayUrl}${endpoint}${query}`;
|
|
177
178
|
try {
|
|
@@ -186,15 +187,15 @@ var AWSAdapter = class {
|
|
|
186
187
|
keepalive: true
|
|
187
188
|
});
|
|
188
189
|
if (!response.ok) {
|
|
189
|
-
if (
|
|
190
|
+
if (debug) {
|
|
190
191
|
console.warn(`AmplifyUp SDK: Event tracking failed: ${response.status} ${response.statusText}`);
|
|
191
192
|
}
|
|
192
|
-
} else if (
|
|
193
|
+
} else if (debug) {
|
|
193
194
|
const result = await response.json().catch(() => ({}));
|
|
194
195
|
console.log("AmplifyUp SDK: Event tracked", result);
|
|
195
196
|
}
|
|
196
197
|
} catch (error) {
|
|
197
|
-
if (
|
|
198
|
+
if (debug) {
|
|
198
199
|
console.error("AmplifyUp SDK: Event tracking error:", error);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
@@ -3957,6 +3958,14 @@ function getSDK(adapter) {
|
|
|
3957
3958
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
3958
3959
|
var refreshEventTracking = () => getSDK().refreshEventTracking();
|
|
3959
3960
|
getSDK();
|
|
3961
|
+
var PageContentRegistryContext = React3.createContext(null);
|
|
3962
|
+
function useRegisterPageContent(enabled = true) {
|
|
3963
|
+
const register = React3.useContext(PageContentRegistryContext);
|
|
3964
|
+
React3.useEffect(() => {
|
|
3965
|
+
if (!enabled || !register) return;
|
|
3966
|
+
return register();
|
|
3967
|
+
}, [enabled, register]);
|
|
3968
|
+
}
|
|
3960
3969
|
function useInComposer(force = false) {
|
|
3961
3970
|
const [detected, setDetected] = React3.useState(false);
|
|
3962
3971
|
React3.useEffect(() => {
|
|
@@ -4195,6 +4204,7 @@ function AmplifyRendererInner({
|
|
|
4195
4204
|
composerPreview
|
|
4196
4205
|
}) {
|
|
4197
4206
|
const clientHook = useAmplifyUp();
|
|
4207
|
+
useRegisterPageContent(!serverPageConfig);
|
|
4198
4208
|
const composerPreviewFlag = useComposerPreviewFlag(!!composerPreview);
|
|
4199
4209
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
4200
4210
|
const loading = serverPageConfig ? false : clientHook.loading;
|
|
@@ -4709,6 +4719,7 @@ function AmplifyPageContent({
|
|
|
4709
4719
|
errorComponent
|
|
4710
4720
|
}) {
|
|
4711
4721
|
const client = useAmplifyUp();
|
|
4722
|
+
useRegisterPageContent();
|
|
4712
4723
|
const preview = useComposerPreviewFlag(forceComposerPreview);
|
|
4713
4724
|
const clientLayout = hasAmplifyLayout(client.pageConfig) ? client.pageConfig : null;
|
|
4714
4725
|
const serverLayout = hasAmplifyLayout(pageConfigProp) ? pageConfigProp : null;
|
|
@@ -5605,11 +5616,24 @@ function AmplifyUpProvider({
|
|
|
5605
5616
|
if (!initialized || !pageContext) return;
|
|
5606
5617
|
getSDK().setPageContext(pageContext);
|
|
5607
5618
|
}, [initialized, pageContextKey]);
|
|
5619
|
+
const contentMountsRef = React3.useRef(0);
|
|
5620
|
+
const [hasPageContent, setHasPageContent] = React3.useState(false);
|
|
5621
|
+
const registerPageContent = React3.useCallback(() => {
|
|
5622
|
+
contentMountsRef.current += 1;
|
|
5623
|
+
setHasPageContent(true);
|
|
5624
|
+
return () => {
|
|
5625
|
+
contentMountsRef.current -= 1;
|
|
5626
|
+
if (contentMountsRef.current === 0) setHasPageContent(false);
|
|
5627
|
+
};
|
|
5628
|
+
}, []);
|
|
5629
|
+
const [initVersion, setInitVersion] = React3.useState(0);
|
|
5630
|
+
const overlayEnabled = () => isComposerPreview() || config.clientPersonalization !== false;
|
|
5608
5631
|
React3.useEffect(() => {
|
|
5609
5632
|
let cancelled = false;
|
|
5610
5633
|
const sdk = getSDK();
|
|
5611
|
-
|
|
5612
|
-
|
|
5634
|
+
if (contentMountsRef.current > 0 && overlayEnabled()) {
|
|
5635
|
+
sdk.beginPageResolve(getActualRoute());
|
|
5636
|
+
}
|
|
5613
5637
|
const run = async () => {
|
|
5614
5638
|
try {
|
|
5615
5639
|
await sdk.init({
|
|
@@ -5619,20 +5643,59 @@ function AmplifyUpProvider({
|
|
|
5619
5643
|
if (cancelled) return;
|
|
5620
5644
|
if (pageContext) sdk.setPageContext(pageContext);
|
|
5621
5645
|
const actualRoute = getActualRoute();
|
|
5622
|
-
if (
|
|
5646
|
+
if (actualRoute) sdk.routeChange(actualRoute);
|
|
5647
|
+
} catch (err) {
|
|
5648
|
+
if (cancelled) return;
|
|
5649
|
+
console.error("Error initializing AmplifyUp SDK:", err);
|
|
5650
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5651
|
+
} finally {
|
|
5652
|
+
if (!cancelled) {
|
|
5623
5653
|
setInitialized(true);
|
|
5624
|
-
|
|
5625
|
-
return;
|
|
5654
|
+
setInitVersion((v) => v + 1);
|
|
5626
5655
|
}
|
|
5627
|
-
|
|
5656
|
+
}
|
|
5657
|
+
};
|
|
5658
|
+
void run();
|
|
5659
|
+
return () => {
|
|
5660
|
+
cancelled = true;
|
|
5661
|
+
};
|
|
5662
|
+
}, [
|
|
5663
|
+
pathname,
|
|
5664
|
+
config.trackingId,
|
|
5665
|
+
config.target,
|
|
5666
|
+
config.debug,
|
|
5667
|
+
config.dev,
|
|
5668
|
+
config.siteId,
|
|
5669
|
+
config.clientPersonalization,
|
|
5670
|
+
pageContextKey
|
|
5671
|
+
]);
|
|
5672
|
+
const resolveRunRef = React3.useRef(null);
|
|
5673
|
+
React3.useEffect(() => {
|
|
5674
|
+
return () => {
|
|
5675
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5676
|
+
};
|
|
5677
|
+
}, []);
|
|
5678
|
+
React3.useEffect(() => {
|
|
5679
|
+
if (initVersion === 0) return;
|
|
5680
|
+
if (resolveRunRef.current?.version === initVersion) return;
|
|
5681
|
+
const sdk = getSDK();
|
|
5682
|
+
const actualRoute = getActualRoute();
|
|
5683
|
+
if (!actualRoute || contentMountsRef.current === 0 || !overlayEnabled()) {
|
|
5684
|
+
if (actualRoute) sdk.endPageResolve(actualRoute);
|
|
5685
|
+
setPageConfig(null);
|
|
5686
|
+
setLoading(false);
|
|
5687
|
+
return;
|
|
5688
|
+
}
|
|
5689
|
+
if (resolveRunRef.current) resolveRunRef.current.cancelled = true;
|
|
5690
|
+
const runState = { version: initVersion, cancelled: false };
|
|
5691
|
+
resolveRunRef.current = runState;
|
|
5692
|
+
const finish = () => {
|
|
5693
|
+
sdk.endPageResolve(actualRoute);
|
|
5694
|
+
if (!runState.cancelled) setLoading(false);
|
|
5695
|
+
};
|
|
5696
|
+
const run = async () => {
|
|
5697
|
+
try {
|
|
5628
5698
|
const preview = isComposerPreview();
|
|
5629
|
-
const overlay = preview || config.clientPersonalization !== false;
|
|
5630
|
-
if (!overlay) {
|
|
5631
|
-
setInitialized(true);
|
|
5632
|
-
setPageConfig(null);
|
|
5633
|
-
setLoading(false);
|
|
5634
|
-
return;
|
|
5635
|
-
}
|
|
5636
5699
|
if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
|
|
5637
5700
|
setPageConfig(null);
|
|
5638
5701
|
setError(null);
|
|
@@ -5641,9 +5704,7 @@ function AmplifyUpProvider({
|
|
|
5641
5704
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
5642
5705
|
const trackingId = sdk.getTrackingId();
|
|
5643
5706
|
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
5644
|
-
setInitialized(true);
|
|
5645
5707
|
setError("SDK not initialized");
|
|
5646
|
-
setLoading(false);
|
|
5647
5708
|
return;
|
|
5648
5709
|
}
|
|
5649
5710
|
let variantKeys;
|
|
@@ -5676,7 +5737,7 @@ function AmplifyUpProvider({
|
|
|
5676
5737
|
variantKeys,
|
|
5677
5738
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
5678
5739
|
});
|
|
5679
|
-
if (cancelled) return;
|
|
5740
|
+
if (runState.cancelled) return;
|
|
5680
5741
|
const nextConfig = result.pageConfig || {
|
|
5681
5742
|
id: "default",
|
|
5682
5743
|
route: actualRoute,
|
|
@@ -5693,7 +5754,6 @@ function AmplifyUpProvider({
|
|
|
5693
5754
|
result.pageConfig.pageTaxonomies || null
|
|
5694
5755
|
);
|
|
5695
5756
|
}
|
|
5696
|
-
setInitialized(true);
|
|
5697
5757
|
setSource((prev) => prev === result.source ? prev : result.source);
|
|
5698
5758
|
setMeta(
|
|
5699
5759
|
(prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
|
|
@@ -5707,31 +5767,17 @@ function AmplifyUpProvider({
|
|
|
5707
5767
|
});
|
|
5708
5768
|
loadedRouteRef.current = actualRoute;
|
|
5709
5769
|
} catch (err) {
|
|
5710
|
-
if (cancelled) return;
|
|
5770
|
+
if (runState.cancelled) return;
|
|
5711
5771
|
console.error("Error fetching page config:", err);
|
|
5712
|
-
setInitialized(true);
|
|
5713
5772
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
5714
5773
|
setSource(null);
|
|
5715
5774
|
setMeta(null);
|
|
5716
5775
|
} finally {
|
|
5717
|
-
|
|
5718
|
-
if (!cancelled) setLoading(false);
|
|
5776
|
+
finish();
|
|
5719
5777
|
}
|
|
5720
5778
|
};
|
|
5721
5779
|
void run();
|
|
5722
|
-
|
|
5723
|
-
cancelled = true;
|
|
5724
|
-
};
|
|
5725
|
-
}, [
|
|
5726
|
-
pathname,
|
|
5727
|
-
config.trackingId,
|
|
5728
|
-
config.target,
|
|
5729
|
-
config.debug,
|
|
5730
|
-
config.dev,
|
|
5731
|
-
config.siteId,
|
|
5732
|
-
config.clientPersonalization,
|
|
5733
|
-
pageContextKey
|
|
5734
|
-
]);
|
|
5780
|
+
}, [initVersion, hasPageContent]);
|
|
5735
5781
|
React3.useEffect(() => {
|
|
5736
5782
|
const applyLayoutTree = (layoutTree) => {
|
|
5737
5783
|
if (!Array.isArray(layoutTree)) return;
|
|
@@ -5765,13 +5811,13 @@ function AmplifyUpProvider({
|
|
|
5765
5811
|
window.removeEventListener("amplifyup:layout-patch", onCustom);
|
|
5766
5812
|
};
|
|
5767
5813
|
}, []);
|
|
5768
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5814
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PageContentRegistryContext.Provider, { value: registerPageContent, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
5769
5815
|
AmplifyUpContext.Provider,
|
|
5770
5816
|
{
|
|
5771
5817
|
value: { pageConfig, loading, error, source, meta },
|
|
5772
5818
|
children
|
|
5773
5819
|
}
|
|
5774
|
-
);
|
|
5820
|
+
) });
|
|
5775
5821
|
}
|
|
5776
5822
|
function useAmplifyUp() {
|
|
5777
5823
|
const context = React3.useContext(AmplifyUpContext);
|