@amplifyup/sdk 0.1.4 → 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 +46 -8
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +52 -34
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +52 -34
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +80 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -35
- 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 +29 -3
- package/dist/react.d.ts +29 -3
- package/dist/react.js +139 -53
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +137 -54
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +0 -6
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +0 -6
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Xv9P55Dj.d.mts → types-B2Swk8BW.d.mts} +10 -7
- package/dist/{types-Xv9P55Dj.d.ts → types-B2Swk8BW.d.ts} +10 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,24 +9,62 @@ Configure a `trackingId`, and optionally a `target` for which environment to use
|
|
|
9
9
|
|
|
10
10
|
## Environment targets
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
**Default: production (live).** Hosting your site on `localhost` does not switch environments.
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
|
17
|
-
|
|
14
|
+
Opt into `local` only when developing inside the AmplifyUp monorepo:
|
|
15
|
+
|
|
16
|
+
| Target | When | Layouts / config | Events + personalize |
|
|
17
|
+
|--------|------|------------------|----------------------|
|
|
18
|
+
| `production` (default) | Customer sites, staging, production | `https://amplifyup.ai` | `https://api.amplifyup.ai` |
|
|
19
|
+
| `local` (explicit) | AmplifyUp monorepo dev | `NEXT_PUBLIC_ORCHESTRATOR_URL` | `https://api-dev.amplifyup.ai` |
|
|
18
20
|
|
|
19
21
|
```bash
|
|
20
|
-
#
|
|
22
|
+
# AmplifyUp monorepo only (apps/demo, apps/orchestrator locally)
|
|
21
23
|
NEXT_PUBLIC_ORCHESTRATOR_URL=http://localhost:5001
|
|
22
24
|
NEXT_PUBLIC_AMPLIFYUP_TARGET=local
|
|
23
25
|
|
|
24
|
-
#
|
|
25
|
-
# NEXT_PUBLIC_AMPLIFYUP_API_URL=https://api-dev.amplifyup.ai
|
|
26
|
+
# Customer sites: omit NEXT_PUBLIC_AMPLIFYUP_TARGET — always live
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
Check active URLs in the browser: `AmplifyUp.getStatus()`
|
|
29
30
|
|
|
31
|
+
### Hybrid pages (native content + Composer)
|
|
32
|
+
|
|
33
|
+
For pages with native content that should only appear for real visitors:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
// app/insights/page.tsx (server)
|
|
37
|
+
import { isPreviewRequest } from '@amplifyup/sdk';
|
|
38
|
+
import { AmplifyPageContent } from '@amplifyup/sdk/react';
|
|
39
|
+
|
|
40
|
+
export default async function InsightsPage({ searchParams }) {
|
|
41
|
+
const params = await searchParams;
|
|
42
|
+
|
|
43
|
+
if (isPreviewRequest(params)) {
|
|
44
|
+
// Composer: no blog fetch, no native fallback HTML
|
|
45
|
+
return (
|
|
46
|
+
<Layout>
|
|
47
|
+
<AmplifyPageContent renderComponent={renderAmplifyComponent} />
|
|
48
|
+
</Layout>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const posts = await getPosts();
|
|
53
|
+
return (
|
|
54
|
+
<Layout>
|
|
55
|
+
<PostsProvider value={posts}>
|
|
56
|
+
<AmplifyPageContent
|
|
57
|
+
fallback={<InsightsFallback />}
|
|
58
|
+
renderComponent={renderAmplifyComponent}
|
|
59
|
+
/>
|
|
60
|
+
</PostsProvider>
|
|
61
|
+
</Layout>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
In Composer preview, `AmplifyPageContent` shows an empty layout canvas — never `fallback`.
|
|
67
|
+
|
|
30
68
|
## Installation
|
|
31
69
|
|
|
32
70
|
```bash
|
package/dist/AmplifyRenderer.js
CHANGED
|
@@ -242,14 +242,16 @@ function resolveAmplifyUpTarget(options) {
|
|
|
242
242
|
if (isAmplifyUpTarget(envTarget)) {
|
|
243
243
|
return normalizeAmplifyUpTarget(envTarget);
|
|
244
244
|
}
|
|
245
|
-
if (typeof window !== "undefined") {
|
|
246
|
-
const host = window.location.hostname;
|
|
247
|
-
if (host === "localhost" || host === "127.0.0.1") {
|
|
248
|
-
return "local";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
245
|
return "production";
|
|
252
246
|
}
|
|
247
|
+
function isRemoteOrchestratorUrl(orchestratorUrl) {
|
|
248
|
+
try {
|
|
249
|
+
const host = new URL(orchestratorUrl).hostname.toLowerCase();
|
|
250
|
+
return host !== "localhost" && host !== "127.0.0.1" && host !== "::1";
|
|
251
|
+
} catch {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
253
255
|
function localOrchestratorUrl() {
|
|
254
256
|
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
255
257
|
return (fromEnv || "http://localhost:5001").replace(/\/$/, "");
|
|
@@ -405,6 +407,7 @@ var AmplifyUpSDK = class {
|
|
|
405
407
|
*/
|
|
406
408
|
async init(config) {
|
|
407
409
|
if (this.initialized && this.adapter?.isInitialized()) {
|
|
410
|
+
this.ensureWindowBridge();
|
|
408
411
|
return;
|
|
409
412
|
}
|
|
410
413
|
if (this.initPromise) {
|
|
@@ -417,6 +420,32 @@ var AmplifyUpSDK = class {
|
|
|
417
420
|
this.initPromise = null;
|
|
418
421
|
}
|
|
419
422
|
}
|
|
423
|
+
/** Attach console helpers to window (idempotent; survives Fast Refresh). */
|
|
424
|
+
ensureWindowBridge() {
|
|
425
|
+
if (typeof window === "undefined") return;
|
|
426
|
+
window.AmplifyUp = {
|
|
427
|
+
getInstanceId: () => this.getInstanceId(),
|
|
428
|
+
getUserId: () => this.getUserId(),
|
|
429
|
+
getTrackingId: () => this.getTrackingId(),
|
|
430
|
+
getTarget: () => this.getTarget(),
|
|
431
|
+
getDiagnostics: () => this.getDiagnostics(),
|
|
432
|
+
getStatus: () => {
|
|
433
|
+
console.log(this.getStatus());
|
|
434
|
+
return this.getDiagnostics();
|
|
435
|
+
},
|
|
436
|
+
testTracking: () => this.testTracking(),
|
|
437
|
+
verifyAWSConnection: () => {
|
|
438
|
+
const result = this.verifyAWSConnection();
|
|
439
|
+
console.log("AWS Connection Verification:", result.message);
|
|
440
|
+
console.log("Full details:", result);
|
|
441
|
+
return result;
|
|
442
|
+
},
|
|
443
|
+
isInitialized: () => this.isInitialized(),
|
|
444
|
+
page: (url, properties) => this.page(url, properties),
|
|
445
|
+
track: (eventName, properties) => this.track(eventName, properties),
|
|
446
|
+
identify: (userId, traits) => this.identify(userId, traits)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
420
449
|
async performInit(config) {
|
|
421
450
|
if (!this.adapter) {
|
|
422
451
|
this.adapter = new AWSAdapter();
|
|
@@ -432,6 +461,12 @@ var AmplifyUpSDK = class {
|
|
|
432
461
|
const previewOverrides = readPreviewQueryOverrides();
|
|
433
462
|
if (previewOverrides.orchestratorUrl) {
|
|
434
463
|
this.orchestratorUrl = previewOverrides.orchestratorUrl;
|
|
464
|
+
if (isRemoteOrchestratorUrl(previewOverrides.orchestratorUrl)) {
|
|
465
|
+
const prodUrls = resolveAmplifyUpUrls("production");
|
|
466
|
+
this.target = "production";
|
|
467
|
+
this.apiGatewayUrl = prodUrls.apiGatewayUrl;
|
|
468
|
+
this.decisionApiUrl = prodUrls.decisionApiUrl;
|
|
469
|
+
}
|
|
435
470
|
}
|
|
436
471
|
this.config = {
|
|
437
472
|
trackingId: previewOverrides.trackingId || config.trackingId,
|
|
@@ -449,34 +484,10 @@ var AmplifyUpSDK = class {
|
|
|
449
484
|
};
|
|
450
485
|
await this.adapter.init(adapterConfig);
|
|
451
486
|
this.initialized = this.adapter.isInitialized();
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
getTrackingId: () => this.getTrackingId(),
|
|
457
|
-
getTarget: () => this.getTarget(),
|
|
458
|
-
getDiagnostics: () => this.getDiagnostics(),
|
|
459
|
-
getStatus: () => {
|
|
460
|
-
console.log(this.getStatus());
|
|
461
|
-
return this.getDiagnostics();
|
|
462
|
-
},
|
|
463
|
-
testTracking: () => this.testTracking(),
|
|
464
|
-
verifyAWSConnection: () => {
|
|
465
|
-
const result = this.verifyAWSConnection();
|
|
466
|
-
console.log("AWS Connection Verification:", result.message);
|
|
467
|
-
console.log("Full details:", result);
|
|
468
|
-
return result;
|
|
469
|
-
},
|
|
470
|
-
isInitialized: () => this.isInitialized(),
|
|
471
|
-
// Re-export main tracking methods for convenience
|
|
472
|
-
page: (url, properties) => this.page(url, properties),
|
|
473
|
-
track: (eventName, properties) => this.track(eventName, properties),
|
|
474
|
-
identify: (userId, traits) => this.identify(userId, traits)
|
|
475
|
-
};
|
|
476
|
-
if (this.config?.debug) {
|
|
477
|
-
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
478
|
-
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
479
|
-
}
|
|
487
|
+
this.ensureWindowBridge();
|
|
488
|
+
if (this.config?.debug) {
|
|
489
|
+
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
490
|
+
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
480
491
|
}
|
|
481
492
|
this.clearTrackingIntervals();
|
|
482
493
|
if (this.isPreviewMode()) {
|
|
@@ -1487,10 +1498,17 @@ Available Console Commands:
|
|
|
1487
1498
|
}
|
|
1488
1499
|
};
|
|
1489
1500
|
var sdkInstance = null;
|
|
1501
|
+
if (typeof window !== "undefined" && window.__AMPLIFYUP_SDK__) {
|
|
1502
|
+
sdkInstance = window.__AMPLIFYUP_SDK__;
|
|
1503
|
+
}
|
|
1490
1504
|
function getSDK(adapter) {
|
|
1491
1505
|
if (!sdkInstance) {
|
|
1492
1506
|
sdkInstance = new AmplifyUpSDK(adapter);
|
|
1507
|
+
if (typeof window !== "undefined") {
|
|
1508
|
+
window.__AMPLIFYUP_SDK__ = sdkInstance;
|
|
1509
|
+
}
|
|
1493
1510
|
}
|
|
1511
|
+
sdkInstance.ensureWindowBridge();
|
|
1494
1512
|
return sdkInstance;
|
|
1495
1513
|
}
|
|
1496
1514
|
var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);
|