@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/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-
|
|
2
|
-
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-
|
|
1
|
+
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-B2Swk8BW.mjs';
|
|
2
|
+
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-B2Swk8BW.mjs';
|
|
3
|
+
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* AmplifyUp Tracking SDK
|
|
@@ -59,6 +60,8 @@ declare class AmplifyUpSDK {
|
|
|
59
60
|
* Resolves local | dev | production targets for ingestion + personalization URLs.
|
|
60
61
|
*/
|
|
61
62
|
init(config: AmplifyUpConfig): Promise<void>;
|
|
63
|
+
/** Attach console helpers to window (idempotent; survives Fast Refresh). */
|
|
64
|
+
ensureWindowBridge(): void;
|
|
62
65
|
private performInit;
|
|
63
66
|
/**
|
|
64
67
|
* Check if SDK is initialized
|
|
@@ -243,6 +246,11 @@ declare class AmplifyUpSDK {
|
|
|
243
246
|
*/
|
|
244
247
|
cleanup(): void;
|
|
245
248
|
}
|
|
249
|
+
declare global {
|
|
250
|
+
interface Window {
|
|
251
|
+
__AMPLIFYUP_SDK__?: AmplifyUpSDK;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
246
254
|
/**
|
|
247
255
|
* Get or create the SDK instance
|
|
248
256
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-
|
|
2
|
-
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-
|
|
1
|
+
import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-B2Swk8BW.js';
|
|
2
|
+
export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-B2Swk8BW.js';
|
|
3
|
+
export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* AmplifyUp Tracking SDK
|
|
@@ -59,6 +60,8 @@ declare class AmplifyUpSDK {
|
|
|
59
60
|
* Resolves local | dev | production targets for ingestion + personalization URLs.
|
|
60
61
|
*/
|
|
61
62
|
init(config: AmplifyUpConfig): Promise<void>;
|
|
63
|
+
/** Attach console helpers to window (idempotent; survives Fast Refresh). */
|
|
64
|
+
ensureWindowBridge(): void;
|
|
62
65
|
private performInit;
|
|
63
66
|
/**
|
|
64
67
|
* Check if SDK is initialized
|
|
@@ -243,6 +246,11 @@ declare class AmplifyUpSDK {
|
|
|
243
246
|
*/
|
|
244
247
|
cleanup(): void;
|
|
245
248
|
}
|
|
249
|
+
declare global {
|
|
250
|
+
interface Window {
|
|
251
|
+
__AMPLIFYUP_SDK__?: AmplifyUpSDK;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
246
254
|
/**
|
|
247
255
|
* Get or create the SDK instance
|
|
248
256
|
*/
|
package/dist/index.js
CHANGED
|
@@ -234,14 +234,16 @@ function resolveAmplifyUpTarget(options) {
|
|
|
234
234
|
if (isAmplifyUpTarget(envTarget)) {
|
|
235
235
|
return normalizeAmplifyUpTarget(envTarget);
|
|
236
236
|
}
|
|
237
|
-
if (typeof window !== "undefined") {
|
|
238
|
-
const host = window.location.hostname;
|
|
239
|
-
if (host === "localhost" || host === "127.0.0.1") {
|
|
240
|
-
return "local";
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
237
|
return "production";
|
|
244
238
|
}
|
|
239
|
+
function isRemoteOrchestratorUrl(orchestratorUrl) {
|
|
240
|
+
try {
|
|
241
|
+
const host = new URL(orchestratorUrl).hostname.toLowerCase();
|
|
242
|
+
return host !== "localhost" && host !== "127.0.0.1" && host !== "::1";
|
|
243
|
+
} catch {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
245
247
|
function localOrchestratorUrl() {
|
|
246
248
|
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
247
249
|
return (fromEnv || "http://localhost:5001").replace(/\/$/, "");
|
|
@@ -275,6 +277,32 @@ function resolveAmplifyUpUrls(target) {
|
|
|
275
277
|
};
|
|
276
278
|
}
|
|
277
279
|
|
|
280
|
+
// src/preview.ts
|
|
281
|
+
function isPreviewRequest(searchParams) {
|
|
282
|
+
if (searchParams instanceof URLSearchParams) {
|
|
283
|
+
return searchParams.get("preview") === "true" || searchParams.get("visualEditor") === "true";
|
|
284
|
+
}
|
|
285
|
+
const preview = searchParams.preview;
|
|
286
|
+
const visualEditor = searchParams.visualEditor;
|
|
287
|
+
return preview === "true" || visualEditor === "true";
|
|
288
|
+
}
|
|
289
|
+
function isComposerPreview() {
|
|
290
|
+
if (typeof window === "undefined") return false;
|
|
291
|
+
if (window.__AMPLIFYUP_PREVIEW_MODE__ === true) return true;
|
|
292
|
+
const params = new URLSearchParams(window.location.search);
|
|
293
|
+
if (isPreviewRequest(params)) return true;
|
|
294
|
+
if (window.self !== window.top && document.referrer) {
|
|
295
|
+
try {
|
|
296
|
+
const refUrl = new URL(document.referrer);
|
|
297
|
+
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/")) {
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
|
|
278
306
|
// src/index.ts
|
|
279
307
|
function readPreviewQueryOverrides() {
|
|
280
308
|
if (typeof window === "undefined") return {};
|
|
@@ -397,6 +425,7 @@ var AmplifyUpSDK = class {
|
|
|
397
425
|
*/
|
|
398
426
|
async init(config) {
|
|
399
427
|
if (this.initialized && this.adapter?.isInitialized()) {
|
|
428
|
+
this.ensureWindowBridge();
|
|
400
429
|
return;
|
|
401
430
|
}
|
|
402
431
|
if (this.initPromise) {
|
|
@@ -409,6 +438,32 @@ var AmplifyUpSDK = class {
|
|
|
409
438
|
this.initPromise = null;
|
|
410
439
|
}
|
|
411
440
|
}
|
|
441
|
+
/** Attach console helpers to window (idempotent; survives Fast Refresh). */
|
|
442
|
+
ensureWindowBridge() {
|
|
443
|
+
if (typeof window === "undefined") return;
|
|
444
|
+
window.AmplifyUp = {
|
|
445
|
+
getInstanceId: () => this.getInstanceId(),
|
|
446
|
+
getUserId: () => this.getUserId(),
|
|
447
|
+
getTrackingId: () => this.getTrackingId(),
|
|
448
|
+
getTarget: () => this.getTarget(),
|
|
449
|
+
getDiagnostics: () => this.getDiagnostics(),
|
|
450
|
+
getStatus: () => {
|
|
451
|
+
console.log(this.getStatus());
|
|
452
|
+
return this.getDiagnostics();
|
|
453
|
+
},
|
|
454
|
+
testTracking: () => this.testTracking(),
|
|
455
|
+
verifyAWSConnection: () => {
|
|
456
|
+
const result = this.verifyAWSConnection();
|
|
457
|
+
console.log("AWS Connection Verification:", result.message);
|
|
458
|
+
console.log("Full details:", result);
|
|
459
|
+
return result;
|
|
460
|
+
},
|
|
461
|
+
isInitialized: () => this.isInitialized(),
|
|
462
|
+
page: (url, properties) => this.page(url, properties),
|
|
463
|
+
track: (eventName, properties) => this.track(eventName, properties),
|
|
464
|
+
identify: (userId, traits) => this.identify(userId, traits)
|
|
465
|
+
};
|
|
466
|
+
}
|
|
412
467
|
async performInit(config) {
|
|
413
468
|
if (!this.adapter) {
|
|
414
469
|
this.adapter = new AWSAdapter();
|
|
@@ -424,6 +479,12 @@ var AmplifyUpSDK = class {
|
|
|
424
479
|
const previewOverrides = readPreviewQueryOverrides();
|
|
425
480
|
if (previewOverrides.orchestratorUrl) {
|
|
426
481
|
this.orchestratorUrl = previewOverrides.orchestratorUrl;
|
|
482
|
+
if (isRemoteOrchestratorUrl(previewOverrides.orchestratorUrl)) {
|
|
483
|
+
const prodUrls = resolveAmplifyUpUrls("production");
|
|
484
|
+
this.target = "production";
|
|
485
|
+
this.apiGatewayUrl = prodUrls.apiGatewayUrl;
|
|
486
|
+
this.decisionApiUrl = prodUrls.decisionApiUrl;
|
|
487
|
+
}
|
|
427
488
|
}
|
|
428
489
|
this.config = {
|
|
429
490
|
trackingId: previewOverrides.trackingId || config.trackingId,
|
|
@@ -441,34 +502,10 @@ var AmplifyUpSDK = class {
|
|
|
441
502
|
};
|
|
442
503
|
await this.adapter.init(adapterConfig);
|
|
443
504
|
this.initialized = this.adapter.isInitialized();
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
getTrackingId: () => this.getTrackingId(),
|
|
449
|
-
getTarget: () => this.getTarget(),
|
|
450
|
-
getDiagnostics: () => this.getDiagnostics(),
|
|
451
|
-
getStatus: () => {
|
|
452
|
-
console.log(this.getStatus());
|
|
453
|
-
return this.getDiagnostics();
|
|
454
|
-
},
|
|
455
|
-
testTracking: () => this.testTracking(),
|
|
456
|
-
verifyAWSConnection: () => {
|
|
457
|
-
const result = this.verifyAWSConnection();
|
|
458
|
-
console.log("AWS Connection Verification:", result.message);
|
|
459
|
-
console.log("Full details:", result);
|
|
460
|
-
return result;
|
|
461
|
-
},
|
|
462
|
-
isInitialized: () => this.isInitialized(),
|
|
463
|
-
// Re-export main tracking methods for convenience
|
|
464
|
-
page: (url, properties) => this.page(url, properties),
|
|
465
|
-
track: (eventName, properties) => this.track(eventName, properties),
|
|
466
|
-
identify: (userId, traits) => this.identify(userId, traits)
|
|
467
|
-
};
|
|
468
|
-
if (this.config?.debug) {
|
|
469
|
-
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
470
|
-
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
471
|
-
}
|
|
505
|
+
this.ensureWindowBridge();
|
|
506
|
+
if (this.config?.debug) {
|
|
507
|
+
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
508
|
+
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
472
509
|
}
|
|
473
510
|
this.clearTrackingIntervals();
|
|
474
511
|
if (this.isPreviewMode()) {
|
|
@@ -1479,10 +1516,17 @@ Available Console Commands:
|
|
|
1479
1516
|
}
|
|
1480
1517
|
};
|
|
1481
1518
|
var sdkInstance = null;
|
|
1519
|
+
if (typeof window !== "undefined" && window.__AMPLIFYUP_SDK__) {
|
|
1520
|
+
sdkInstance = window.__AMPLIFYUP_SDK__;
|
|
1521
|
+
}
|
|
1482
1522
|
function getSDK(adapter) {
|
|
1483
1523
|
if (!sdkInstance) {
|
|
1484
1524
|
sdkInstance = new AmplifyUpSDK(adapter);
|
|
1525
|
+
if (typeof window !== "undefined") {
|
|
1526
|
+
window.__AMPLIFYUP_SDK__ = sdkInstance;
|
|
1527
|
+
}
|
|
1485
1528
|
}
|
|
1529
|
+
sdkInstance.ensureWindowBridge();
|
|
1486
1530
|
return sdkInstance;
|
|
1487
1531
|
}
|
|
1488
1532
|
async function init(config) {
|
|
@@ -1541,6 +1585,8 @@ exports.getUserId = getUserId2;
|
|
|
1541
1585
|
exports.identify = identify;
|
|
1542
1586
|
exports.init = init;
|
|
1543
1587
|
exports.isAmplifyUpTarget = isAmplifyUpTarget;
|
|
1588
|
+
exports.isComposerPreview = isComposerPreview;
|
|
1589
|
+
exports.isPreviewRequest = isPreviewRequest;
|
|
1544
1590
|
exports.normalizeAmplifyUpTarget = normalizeAmplifyUpTarget;
|
|
1545
1591
|
exports.page = page;
|
|
1546
1592
|
exports.refreshEventTracking = refreshEventTracking;
|