@amplifyup/sdk 0.1.5 → 0.1.6
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 +37 -0
- package/dist/AmplifyRenderer.js +38 -28
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +38 -28
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +66 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -29
- package/dist/index.mjs.map +1 -1
- package/dist/preview-BMrIgUvp.d.mts +13 -0
- package/dist/preview-BMrIgUvp.d.ts +13 -0
- package/dist/react.d.mts +28 -2
- package/dist/react.d.ts +28 -2
- package/dist/react.js +125 -47
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +123 -48
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer / visual-editor preview detection.
|
|
3
|
+
* Shared by AmplifyPageContent, AmplifyUpProvider, and AmplifyRenderer.
|
|
4
|
+
*/
|
|
5
|
+
/** True when `preview=true` (or legacy visualEditor) is in request search params. */
|
|
6
|
+
declare function isPreviewRequest(searchParams: Record<string, string | string[] | undefined> | URLSearchParams): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Client-only: true when the page is loaded inside AmplifyUp Composer.
|
|
9
|
+
* Does NOT treat every iframe as preview — only Composer referrers / query flags.
|
|
10
|
+
*/
|
|
11
|
+
declare function isComposerPreview(): boolean;
|
|
12
|
+
|
|
13
|
+
export { isPreviewRequest as a, isComposerPreview as i };
|
package/dist/react.d.mts
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { P as PageConfig, A as AmplifyUpConfig } from './types-B2Swk8BW.mjs';
|
|
4
4
|
export { Z as ZoneConfig } from './types-B2Swk8BW.mjs';
|
|
5
5
|
export { AmplifyRenderer } from './AmplifyRenderer.mjs';
|
|
6
|
+
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
|
|
6
7
|
export { fetchPageConfigServer } from './server.mjs';
|
|
7
8
|
|
|
9
|
+
type RenderComponentFn = (componentId: string, props: Record<string, any>, slots?: Record<string, ReactNode>) => ReactNode;
|
|
10
|
+
interface AmplifyPageContentProps {
|
|
11
|
+
/**
|
|
12
|
+
* Native page content shown to visitors when no AmplifyUp layout is configured.
|
|
13
|
+
* Never rendered in Composer preview — only the layout canvas is shown there.
|
|
14
|
+
*/
|
|
15
|
+
fallback?: ReactNode;
|
|
16
|
+
/** Maps AmplifyUp component IDs to your React components. */
|
|
17
|
+
renderComponent: RenderComponentFn;
|
|
18
|
+
/** Optional pre-fetched layout (e.g. from server in preview mode). */
|
|
19
|
+
pageConfig?: PageConfig | null;
|
|
20
|
+
/** Shown while layout loads in Composer (default: empty main canvas). */
|
|
21
|
+
previewLoadingComponent?: ReactNode;
|
|
22
|
+
/** Shown when no layout components exist yet in Composer (default: empty main canvas). */
|
|
23
|
+
previewEmptyComponent?: ReactNode;
|
|
24
|
+
loadingComponent?: ReactNode;
|
|
25
|
+
emptyComponent?: ReactNode;
|
|
26
|
+
errorComponent?: (error: string) => ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hybrid page wrapper: Composer shows only the AmplifyUp layout canvas;
|
|
30
|
+
* normal visits show the configured layout or your native `fallback`.
|
|
31
|
+
*/
|
|
32
|
+
declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
|
|
33
|
+
|
|
8
34
|
/**
|
|
9
35
|
* ComponentContextProvider - Provides slots and props to child components
|
|
10
36
|
* This should wrap each component when rendering
|
|
@@ -86,4 +112,4 @@ interface AmplifyUpProviderProps {
|
|
|
86
112
|
declare function AmplifyUpProvider({ children, config }: AmplifyUpProviderProps): react_jsx_runtime.JSX.Element;
|
|
87
113
|
declare function useAmplifyUp(): AmplifyUpContextType;
|
|
88
114
|
|
|
89
|
-
export { AmplifyUpProvider, ComponentContextProvider, Field, PageConfig, Slot, useAmplifyUp };
|
|
115
|
+
export { AmplifyPageContent, type AmplifyPageContentProps, AmplifyUpProvider, ComponentContextProvider, Field, PageConfig, Slot, useAmplifyUp };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { P as PageConfig, A as AmplifyUpConfig } from './types-B2Swk8BW.js';
|
|
4
4
|
export { Z as ZoneConfig } from './types-B2Swk8BW.js';
|
|
5
5
|
export { AmplifyRenderer } from './AmplifyRenderer.js';
|
|
6
|
+
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
|
|
6
7
|
export { fetchPageConfigServer } from './server.js';
|
|
7
8
|
|
|
9
|
+
type RenderComponentFn = (componentId: string, props: Record<string, any>, slots?: Record<string, ReactNode>) => ReactNode;
|
|
10
|
+
interface AmplifyPageContentProps {
|
|
11
|
+
/**
|
|
12
|
+
* Native page content shown to visitors when no AmplifyUp layout is configured.
|
|
13
|
+
* Never rendered in Composer preview — only the layout canvas is shown there.
|
|
14
|
+
*/
|
|
15
|
+
fallback?: ReactNode;
|
|
16
|
+
/** Maps AmplifyUp component IDs to your React components. */
|
|
17
|
+
renderComponent: RenderComponentFn;
|
|
18
|
+
/** Optional pre-fetched layout (e.g. from server in preview mode). */
|
|
19
|
+
pageConfig?: PageConfig | null;
|
|
20
|
+
/** Shown while layout loads in Composer (default: empty main canvas). */
|
|
21
|
+
previewLoadingComponent?: ReactNode;
|
|
22
|
+
/** Shown when no layout components exist yet in Composer (default: empty main canvas). */
|
|
23
|
+
previewEmptyComponent?: ReactNode;
|
|
24
|
+
loadingComponent?: ReactNode;
|
|
25
|
+
emptyComponent?: ReactNode;
|
|
26
|
+
errorComponent?: (error: string) => ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hybrid page wrapper: Composer shows only the AmplifyUp layout canvas;
|
|
30
|
+
* normal visits show the configured layout or your native `fallback`.
|
|
31
|
+
*/
|
|
32
|
+
declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
|
|
33
|
+
|
|
8
34
|
/**
|
|
9
35
|
* ComponentContextProvider - Provides slots and props to child components
|
|
10
36
|
* This should wrap each component when rendering
|
|
@@ -86,4 +112,4 @@ interface AmplifyUpProviderProps {
|
|
|
86
112
|
declare function AmplifyUpProvider({ children, config }: AmplifyUpProviderProps): react_jsx_runtime.JSX.Element;
|
|
87
113
|
declare function useAmplifyUp(): AmplifyUpContextType;
|
|
88
114
|
|
|
89
|
-
export { AmplifyUpProvider, ComponentContextProvider, Field, PageConfig, Slot, useAmplifyUp };
|
|
115
|
+
export { AmplifyPageContent, type AmplifyPageContentProps, AmplifyUpProvider, ComponentContextProvider, Field, PageConfig, Slot, useAmplifyUp };
|
package/dist/react.js
CHANGED
|
@@ -285,6 +285,32 @@ function resolveAmplifyUpUrls(target) {
|
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
// src/preview.ts
|
|
289
|
+
function isPreviewRequest(searchParams) {
|
|
290
|
+
if (searchParams instanceof URLSearchParams) {
|
|
291
|
+
return searchParams.get("preview") === "true" || searchParams.get("visualEditor") === "true";
|
|
292
|
+
}
|
|
293
|
+
const preview = searchParams.preview;
|
|
294
|
+
const visualEditor = searchParams.visualEditor;
|
|
295
|
+
return preview === "true" || visualEditor === "true";
|
|
296
|
+
}
|
|
297
|
+
function isComposerPreview() {
|
|
298
|
+
if (typeof window === "undefined") return false;
|
|
299
|
+
if (window.__AMPLIFYUP_PREVIEW_MODE__ === true) return true;
|
|
300
|
+
const params = new URLSearchParams(window.location.search);
|
|
301
|
+
if (isPreviewRequest(params)) return true;
|
|
302
|
+
if (window.self !== window.top && document.referrer) {
|
|
303
|
+
try {
|
|
304
|
+
const refUrl = new URL(document.referrer);
|
|
305
|
+
if (refUrl.hostname === "amplifyup.ai" || refUrl.hostname.endsWith(".amplifyup.ai") || refUrl.hostname === "localhost" && refUrl.port === "5001" || refUrl.pathname.includes("/dashboard/composer") || refUrl.pathname.includes("/dashboard/routes/")) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
} catch {
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
|
|
288
314
|
// src/index.ts
|
|
289
315
|
function readPreviewQueryOverrides() {
|
|
290
316
|
if (typeof window === "undefined") return {};
|
|
@@ -407,6 +433,7 @@ var AmplifyUpSDK = class {
|
|
|
407
433
|
*/
|
|
408
434
|
async init(config) {
|
|
409
435
|
if (this.initialized && this.adapter?.isInitialized()) {
|
|
436
|
+
this.ensureWindowBridge();
|
|
410
437
|
return;
|
|
411
438
|
}
|
|
412
439
|
if (this.initPromise) {
|
|
@@ -419,6 +446,32 @@ var AmplifyUpSDK = class {
|
|
|
419
446
|
this.initPromise = null;
|
|
420
447
|
}
|
|
421
448
|
}
|
|
449
|
+
/** Attach console helpers to window (idempotent; survives Fast Refresh). */
|
|
450
|
+
ensureWindowBridge() {
|
|
451
|
+
if (typeof window === "undefined") return;
|
|
452
|
+
window.AmplifyUp = {
|
|
453
|
+
getInstanceId: () => this.getInstanceId(),
|
|
454
|
+
getUserId: () => this.getUserId(),
|
|
455
|
+
getTrackingId: () => this.getTrackingId(),
|
|
456
|
+
getTarget: () => this.getTarget(),
|
|
457
|
+
getDiagnostics: () => this.getDiagnostics(),
|
|
458
|
+
getStatus: () => {
|
|
459
|
+
console.log(this.getStatus());
|
|
460
|
+
return this.getDiagnostics();
|
|
461
|
+
},
|
|
462
|
+
testTracking: () => this.testTracking(),
|
|
463
|
+
verifyAWSConnection: () => {
|
|
464
|
+
const result = this.verifyAWSConnection();
|
|
465
|
+
console.log("AWS Connection Verification:", result.message);
|
|
466
|
+
console.log("Full details:", result);
|
|
467
|
+
return result;
|
|
468
|
+
},
|
|
469
|
+
isInitialized: () => this.isInitialized(),
|
|
470
|
+
page: (url, properties) => this.page(url, properties),
|
|
471
|
+
track: (eventName, properties) => this.track(eventName, properties),
|
|
472
|
+
identify: (userId, traits) => this.identify(userId, traits)
|
|
473
|
+
};
|
|
474
|
+
}
|
|
422
475
|
async performInit(config) {
|
|
423
476
|
if (!this.adapter) {
|
|
424
477
|
this.adapter = new AWSAdapter();
|
|
@@ -457,34 +510,10 @@ var AmplifyUpSDK = class {
|
|
|
457
510
|
};
|
|
458
511
|
await this.adapter.init(adapterConfig);
|
|
459
512
|
this.initialized = this.adapter.isInitialized();
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
getTrackingId: () => this.getTrackingId(),
|
|
465
|
-
getTarget: () => this.getTarget(),
|
|
466
|
-
getDiagnostics: () => this.getDiagnostics(),
|
|
467
|
-
getStatus: () => {
|
|
468
|
-
console.log(this.getStatus());
|
|
469
|
-
return this.getDiagnostics();
|
|
470
|
-
},
|
|
471
|
-
testTracking: () => this.testTracking(),
|
|
472
|
-
verifyAWSConnection: () => {
|
|
473
|
-
const result = this.verifyAWSConnection();
|
|
474
|
-
console.log("AWS Connection Verification:", result.message);
|
|
475
|
-
console.log("Full details:", result);
|
|
476
|
-
return result;
|
|
477
|
-
},
|
|
478
|
-
isInitialized: () => this.isInitialized(),
|
|
479
|
-
// Re-export main tracking methods for convenience
|
|
480
|
-
page: (url, properties) => this.page(url, properties),
|
|
481
|
-
track: (eventName, properties) => this.track(eventName, properties),
|
|
482
|
-
identify: (userId, traits) => this.identify(userId, traits)
|
|
483
|
-
};
|
|
484
|
-
if (this.config?.debug) {
|
|
485
|
-
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
486
|
-
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
487
|
-
}
|
|
513
|
+
this.ensureWindowBridge();
|
|
514
|
+
if (this.config?.debug) {
|
|
515
|
+
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
516
|
+
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
488
517
|
}
|
|
489
518
|
this.clearTrackingIntervals();
|
|
490
519
|
if (this.isPreviewMode()) {
|
|
@@ -1495,10 +1524,17 @@ Available Console Commands:
|
|
|
1495
1524
|
}
|
|
1496
1525
|
};
|
|
1497
1526
|
var sdkInstance = null;
|
|
1527
|
+
if (typeof window !== "undefined" && window.__AMPLIFYUP_SDK__) {
|
|
1528
|
+
sdkInstance = window.__AMPLIFYUP_SDK__;
|
|
1529
|
+
}
|
|
1498
1530
|
function getSDK(adapter) {
|
|
1499
1531
|
if (!sdkInstance) {
|
|
1500
1532
|
sdkInstance = new AmplifyUpSDK(adapter);
|
|
1533
|
+
if (typeof window !== "undefined") {
|
|
1534
|
+
window.__AMPLIFYUP_SDK__ = sdkInstance;
|
|
1535
|
+
}
|
|
1501
1536
|
}
|
|
1537
|
+
sdkInstance.ensureWindowBridge();
|
|
1502
1538
|
return sdkInstance;
|
|
1503
1539
|
}
|
|
1504
1540
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|
|
@@ -1801,6 +1837,62 @@ function AmplifyRenderer({
|
|
|
1801
1837
|
}
|
|
1802
1838
|
return /* @__PURE__ */ jsxRuntime.jsx("main", { children: layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderNode(node) }, node.id)) });
|
|
1803
1839
|
}
|
|
1840
|
+
function defaultPreviewCanvas() {
|
|
1841
|
+
return /* @__PURE__ */ jsxRuntime.jsx("main", { className: "min-h-[50vh]", "data-amplifyup-composer-canvas": true });
|
|
1842
|
+
}
|
|
1843
|
+
function hasAmplifyLayout(pageConfig) {
|
|
1844
|
+
return !!(pageConfig && pageConfig.id !== "default" && Array.isArray(pageConfig.layoutTree) && pageConfig.layoutTree.length > 0);
|
|
1845
|
+
}
|
|
1846
|
+
function AmplifyPageContent({
|
|
1847
|
+
fallback,
|
|
1848
|
+
renderComponent,
|
|
1849
|
+
pageConfig: pageConfigProp,
|
|
1850
|
+
previewLoadingComponent,
|
|
1851
|
+
previewEmptyComponent,
|
|
1852
|
+
loadingComponent,
|
|
1853
|
+
emptyComponent,
|
|
1854
|
+
errorComponent
|
|
1855
|
+
}) {
|
|
1856
|
+
const client = useAmplifyUp();
|
|
1857
|
+
const preview = isComposerPreview();
|
|
1858
|
+
const pageConfig = pageConfigProp ?? client.pageConfig;
|
|
1859
|
+
const loading = pageConfigProp ? false : client.loading;
|
|
1860
|
+
const error = pageConfigProp ? null : client.error;
|
|
1861
|
+
const previewCanvas = previewEmptyComponent ?? defaultPreviewCanvas();
|
|
1862
|
+
const previewLoading = previewLoadingComponent ?? previewCanvas;
|
|
1863
|
+
if (preview) {
|
|
1864
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1865
|
+
AmplifyRenderer,
|
|
1866
|
+
{
|
|
1867
|
+
pageConfig: pageConfig ?? void 0,
|
|
1868
|
+
renderComponent,
|
|
1869
|
+
loadingComponent: loadingComponent ?? previewLoading,
|
|
1870
|
+
emptyComponent: emptyComponent ?? previewCanvas,
|
|
1871
|
+
errorComponent: errorComponent ?? (() => previewCanvas)
|
|
1872
|
+
}
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
if (loading) {
|
|
1876
|
+
return loadingComponent ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: loadingComponent }) : null;
|
|
1877
|
+
}
|
|
1878
|
+
if (error) {
|
|
1879
|
+
if (errorComponent) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: errorComponent(error) });
|
|
1880
|
+
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
1881
|
+
}
|
|
1882
|
+
if (!hasAmplifyLayout(pageConfig)) {
|
|
1883
|
+
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
1884
|
+
}
|
|
1885
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1886
|
+
AmplifyRenderer,
|
|
1887
|
+
{
|
|
1888
|
+
pageConfig: pageConfig ?? void 0,
|
|
1889
|
+
renderComponent,
|
|
1890
|
+
loadingComponent,
|
|
1891
|
+
emptyComponent,
|
|
1892
|
+
errorComponent
|
|
1893
|
+
}
|
|
1894
|
+
);
|
|
1895
|
+
}
|
|
1804
1896
|
|
|
1805
1897
|
// src/server.tsx
|
|
1806
1898
|
async function fetchPageConfigServer(route, trackingId, preview = false, options) {
|
|
@@ -2030,7 +2122,7 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
2030
2122
|
return () => {
|
|
2031
2123
|
cancelled = true;
|
|
2032
2124
|
};
|
|
2033
|
-
}, []);
|
|
2125
|
+
}, [config.trackingId, config.target, config.debug, config.dev]);
|
|
2034
2126
|
react.useEffect(() => {
|
|
2035
2127
|
if (!initialized) return;
|
|
2036
2128
|
const fetchConfig = async () => {
|
|
@@ -2043,24 +2135,7 @@ function AmplifyUpProvider({ children, config }) {
|
|
|
2043
2135
|
return;
|
|
2044
2136
|
}
|
|
2045
2137
|
const sdk = getSDK();
|
|
2046
|
-
const isPreviewContext = (
|
|
2047
|
-
if (typeof window === "undefined") return false;
|
|
2048
|
-
if (window.__AMPLIFYUP_PREVIEW_MODE__ === true) return true;
|
|
2049
|
-
const params = new URLSearchParams(window.location.search);
|
|
2050
|
-
if (params.get("preview") === "true" || params.get("visualEditor") === "true") return true;
|
|
2051
|
-
if (window.self !== window.top) {
|
|
2052
|
-
if (document.referrer) {
|
|
2053
|
-
try {
|
|
2054
|
-
const refUrl = new URL(document.referrer);
|
|
2055
|
-
if (refUrl.hostname === "localhost" && refUrl.port === "5001" || refUrl.pathname.includes("/dashboard/composer") || refUrl.pathname.includes("/dashboard/routes/")) {
|
|
2056
|
-
return true;
|
|
2057
|
-
}
|
|
2058
|
-
} catch {
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
return false;
|
|
2063
|
-
})();
|
|
2138
|
+
const isPreviewContext = isComposerPreview();
|
|
2064
2139
|
const page = await sdk.fetchPageConfig(actualRoute, isPreviewContext);
|
|
2065
2140
|
if (!page) {
|
|
2066
2141
|
setPageConfig({
|
|
@@ -2092,12 +2167,15 @@ function useAmplifyUp() {
|
|
|
2092
2167
|
return context;
|
|
2093
2168
|
}
|
|
2094
2169
|
|
|
2170
|
+
exports.AmplifyPageContent = AmplifyPageContent;
|
|
2095
2171
|
exports.AmplifyRenderer = AmplifyRenderer;
|
|
2096
2172
|
exports.AmplifyUpProvider = AmplifyUpProvider;
|
|
2097
2173
|
exports.ComponentContextProvider = ComponentContextProvider;
|
|
2098
2174
|
exports.Field = Field;
|
|
2099
2175
|
exports.Slot = Slot;
|
|
2100
2176
|
exports.fetchPageConfigServer = fetchPageConfigServer;
|
|
2177
|
+
exports.isComposerPreview = isComposerPreview;
|
|
2178
|
+
exports.isPreviewRequest = isPreviewRequest;
|
|
2101
2179
|
exports.useAmplifyUp = useAmplifyUp;
|
|
2102
2180
|
//# sourceMappingURL=react.js.map
|
|
2103
2181
|
//# sourceMappingURL=react.js.map
|