@amplifyup/sdk 0.1.1 → 0.1.2
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 +23 -18
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +112 -36
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +112 -36
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +117 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -37
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +144 -49
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +144 -49
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +6 -2
- package/dist/server.d.ts +6 -2
- package/dist/server.js +77 -1385
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +76 -1386
- package/dist/server.mjs.map +1 -1
- package/dist/{types-B9nHG2Cl.d.mts → types-Xv9P55Dj.d.mts} +51 -1
- package/dist/{types-B9nHG2Cl.d.ts → types-Xv9P55Dj.d.ts} +51 -1
- package/package.json +4 -4
package/dist/AmplifyRenderer.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { createContext, useState, useEffect, useContext } from 'react';
|
|
2
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
3
4
|
|
|
@@ -218,9 +219,69 @@ function clearIds() {
|
|
|
218
219
|
localStorage.removeItem(USER_ID_KEY);
|
|
219
220
|
}
|
|
220
221
|
|
|
222
|
+
// src/targets.ts
|
|
223
|
+
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
224
|
+
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
225
|
+
var PROD_ORCHESTRATOR = "https://amplifyup.ai";
|
|
226
|
+
function isAmplifyUpTarget(value) {
|
|
227
|
+
return value === "local" || value === "dev" || value === "production";
|
|
228
|
+
}
|
|
229
|
+
function normalizeAmplifyUpTarget(value) {
|
|
230
|
+
return value === "dev" ? "local" : value;
|
|
231
|
+
}
|
|
232
|
+
function resolveAmplifyUpTarget(options) {
|
|
233
|
+
if (options?.configTarget && isAmplifyUpTarget(options.configTarget)) {
|
|
234
|
+
return normalizeAmplifyUpTarget(options.configTarget);
|
|
235
|
+
}
|
|
236
|
+
if (options?.configDev === true) {
|
|
237
|
+
return "local";
|
|
238
|
+
}
|
|
239
|
+
const envTarget = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_TARGET : void 0;
|
|
240
|
+
if (isAmplifyUpTarget(envTarget)) {
|
|
241
|
+
return normalizeAmplifyUpTarget(envTarget);
|
|
242
|
+
}
|
|
243
|
+
if (typeof window !== "undefined") {
|
|
244
|
+
const host = window.location.hostname;
|
|
245
|
+
if (host === "localhost" || host === "127.0.0.1") {
|
|
246
|
+
return "local";
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return "production";
|
|
250
|
+
}
|
|
251
|
+
function localOrchestratorUrl() {
|
|
252
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
253
|
+
return (fromEnv || "http://localhost:5001").replace(/\/$/, "");
|
|
254
|
+
}
|
|
255
|
+
function localAwsApiUrl() {
|
|
256
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL : void 0;
|
|
257
|
+
return (fromEnv || AWS_DEV_API).replace(/\/$/, "");
|
|
258
|
+
}
|
|
259
|
+
function resolveAmplifyUpUrls(target) {
|
|
260
|
+
if (target === "local") {
|
|
261
|
+
const orchestratorUrl2 = localOrchestratorUrl();
|
|
262
|
+
const apiGatewayUrl = localAwsApiUrl();
|
|
263
|
+
return {
|
|
264
|
+
target: "local",
|
|
265
|
+
// Layouts / site config / composer APIs → local orchestrator + Neon
|
|
266
|
+
orchestratorUrl: orchestratorUrl2,
|
|
267
|
+
// Events + personalize → AWS development stack
|
|
268
|
+
apiGatewayUrl,
|
|
269
|
+
decisionApiUrl: `${apiGatewayUrl}/v1/personalize`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const resolvedApi = typeof process !== "undefined" && process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL?.replace(/\/$/, "") || AWS_PROD_API;
|
|
273
|
+
const orchestratorFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
274
|
+
const isLocalOrchestrator = !!orchestratorFromEnv && (orchestratorFromEnv.includes("localhost") || orchestratorFromEnv.includes("127.0.0.1"));
|
|
275
|
+
const orchestratorUrl = isLocalOrchestrator || !orchestratorFromEnv ? PROD_ORCHESTRATOR : orchestratorFromEnv.replace(/\/$/, "");
|
|
276
|
+
return {
|
|
277
|
+
target: "production",
|
|
278
|
+
apiGatewayUrl: resolvedApi,
|
|
279
|
+
orchestratorUrl,
|
|
280
|
+
decisionApiUrl: `${resolvedApi}/v1/personalize`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
221
284
|
// src/index.ts
|
|
222
|
-
var PROD_API_URL = "https://api.amplifyup.ai" ;
|
|
223
|
-
var PROD_ORCHESTRATOR_URL = "https://amplifyup.ai" ;
|
|
224
285
|
var AmplifyUpSDK = class {
|
|
225
286
|
constructor(adapter) {
|
|
226
287
|
this.config = null;
|
|
@@ -228,7 +289,12 @@ var AmplifyUpSDK = class {
|
|
|
228
289
|
this.apiGatewayUrl = "";
|
|
229
290
|
this.orchestratorUrl = "";
|
|
230
291
|
this.decisionApiUrl = "";
|
|
292
|
+
this.target = "local";
|
|
231
293
|
this.initialized = false;
|
|
294
|
+
/** Prevents overlapping init() from React Strict Mode double-mount */
|
|
295
|
+
this.initPromise = null;
|
|
296
|
+
/** Ensures auto page() on init fires once per page load */
|
|
297
|
+
this.initialPageSent = false;
|
|
232
298
|
this.highlightingEnabled = false;
|
|
233
299
|
this.componentRegistry = [];
|
|
234
300
|
this.messageListener = null;
|
|
@@ -311,46 +377,41 @@ var AmplifyUpSDK = class {
|
|
|
311
377
|
}
|
|
312
378
|
return false;
|
|
313
379
|
}
|
|
314
|
-
/**
|
|
315
|
-
* Get production URLs
|
|
316
|
-
*
|
|
317
|
-
* URLs are baked in at build time via tsup.config.ts
|
|
318
|
-
*
|
|
319
|
-
* API Gateway endpoints:
|
|
320
|
-
* - /v1/track - Event tracking (ingestion)
|
|
321
|
-
* - /v1/page - Page view tracking (ingestion)
|
|
322
|
-
* - /v1/personalize - Decision engine (personalization)
|
|
323
|
-
*/
|
|
324
|
-
getProductionUrls() {
|
|
325
|
-
return {
|
|
326
|
-
apiGatewayUrl: PROD_API_URL,
|
|
327
|
-
orchestratorUrl: PROD_ORCHESTRATOR_URL,
|
|
328
|
-
decisionApiUrl: `${PROD_API_URL}/v1/personalize`
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
380
|
/**
|
|
332
381
|
* Initialize the SDK
|
|
333
|
-
*
|
|
382
|
+
* Resolves local | dev | production targets for ingestion + personalization URLs.
|
|
334
383
|
*/
|
|
335
384
|
async init(config) {
|
|
385
|
+
if (this.initialized && this.adapter?.isInitialized()) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (this.initPromise) {
|
|
389
|
+
return this.initPromise;
|
|
390
|
+
}
|
|
391
|
+
this.initPromise = this.performInit(config);
|
|
392
|
+
try {
|
|
393
|
+
await this.initPromise;
|
|
394
|
+
} finally {
|
|
395
|
+
this.initPromise = null;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async performInit(config) {
|
|
336
399
|
if (!this.adapter) {
|
|
337
400
|
this.adapter = new AWSAdapter();
|
|
338
401
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
this.orchestratorUrl = urls.orchestratorUrl;
|
|
348
|
-
this.decisionApiUrl = urls.decisionApiUrl;
|
|
349
|
-
}
|
|
402
|
+
this.target = resolveAmplifyUpTarget({
|
|
403
|
+
configTarget: config.target,
|
|
404
|
+
configDev: config.dev
|
|
405
|
+
});
|
|
406
|
+
const urls = resolveAmplifyUpUrls(this.target);
|
|
407
|
+
this.apiGatewayUrl = urls.apiGatewayUrl;
|
|
408
|
+
this.orchestratorUrl = urls.orchestratorUrl;
|
|
409
|
+
this.decisionApiUrl = urls.decisionApiUrl;
|
|
350
410
|
this.config = {
|
|
351
411
|
trackingId: config.trackingId,
|
|
352
412
|
debug: config.debug ?? true,
|
|
353
413
|
// Enable debug by default
|
|
414
|
+
target: this.target,
|
|
354
415
|
dev: config.dev
|
|
355
416
|
};
|
|
356
417
|
try {
|
|
@@ -367,6 +428,7 @@ var AmplifyUpSDK = class {
|
|
|
367
428
|
getInstanceId: () => this.getInstanceId(),
|
|
368
429
|
getUserId: () => this.getUserId(),
|
|
369
430
|
getTrackingId: () => this.getTrackingId(),
|
|
431
|
+
getTarget: () => this.getTarget(),
|
|
370
432
|
getDiagnostics: () => this.getDiagnostics(),
|
|
371
433
|
getStatus: () => {
|
|
372
434
|
console.log(this.getStatus());
|
|
@@ -387,7 +449,7 @@ var AmplifyUpSDK = class {
|
|
|
387
449
|
};
|
|
388
450
|
if (this.config?.debug) {
|
|
389
451
|
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
390
|
-
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.
|
|
452
|
+
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
391
453
|
}
|
|
392
454
|
}
|
|
393
455
|
this.clearTrackingIntervals();
|
|
@@ -399,11 +461,20 @@ var AmplifyUpSDK = class {
|
|
|
399
461
|
if (this.isPreviewMode()) {
|
|
400
462
|
return;
|
|
401
463
|
}
|
|
402
|
-
|
|
403
|
-
|
|
464
|
+
if (!this.initialPageSent) {
|
|
465
|
+
this.initialPageSent = true;
|
|
466
|
+
const url = window.location.pathname;
|
|
467
|
+
this.page(url);
|
|
468
|
+
}
|
|
404
469
|
}
|
|
405
470
|
if (this.config?.debug && this.initialized) {
|
|
406
|
-
console.log("AmplifyUp SDK: Initialized successfully", {
|
|
471
|
+
console.log("AmplifyUp SDK: Initialized successfully", {
|
|
472
|
+
trackingId: config.trackingId,
|
|
473
|
+
target: this.target,
|
|
474
|
+
apiGatewayUrl: this.apiGatewayUrl,
|
|
475
|
+
orchestratorUrl: this.orchestratorUrl,
|
|
476
|
+
decisionApiUrl: this.decisionApiUrl || "(orchestrator fallback)"
|
|
477
|
+
});
|
|
407
478
|
}
|
|
408
479
|
} catch (error) {
|
|
409
480
|
console.error("AmplifyUp SDK: Initialization failed", error);
|
|
@@ -604,6 +675,7 @@ var AmplifyUpSDK = class {
|
|
|
604
675
|
instanceId,
|
|
605
676
|
userId,
|
|
606
677
|
trackingId: this.config?.trackingId,
|
|
678
|
+
target: this.target,
|
|
607
679
|
config: {
|
|
608
680
|
apiGatewayUrl: this.apiGatewayUrl,
|
|
609
681
|
decisionApiUrl: this.decisionApiUrl,
|
|
@@ -612,6 +684,9 @@ var AmplifyUpSDK = class {
|
|
|
612
684
|
}
|
|
613
685
|
};
|
|
614
686
|
}
|
|
687
|
+
getTarget() {
|
|
688
|
+
return this.target;
|
|
689
|
+
}
|
|
615
690
|
/**
|
|
616
691
|
* Test tracking by sending a test event
|
|
617
692
|
*/
|
|
@@ -669,6 +744,7 @@ var AmplifyUpSDK = class {
|
|
|
669
744
|
AmplifyUp SDK Status:
|
|
670
745
|
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
671
746
|
Initialized: ${diag.initialized ? "\u2705 Yes" : "\u274C No"}
|
|
747
|
+
Target: ${diag.target}
|
|
672
748
|
Instance ID: ${diag.instanceId}
|
|
673
749
|
User ID: ${diag.userId || "Not identified"}
|
|
674
750
|
Tracking ID: ${diag.trackingId || "Not set"}
|
|
@@ -680,11 +756,11 @@ Config:
|
|
|
680
756
|
API Gateway: ${this.apiGatewayUrl || "Not set (required)"}
|
|
681
757
|
Decision API: ${this.decisionApiUrl || "Not set (using Orchestrator fallback)"}
|
|
682
758
|
Orchestrator: ${this.orchestratorUrl || "Not set"}
|
|
683
|
-
Debug: ${diag.config.debug ? "Enabled" : "Disabled"}
|
|
684
759
|
|
|
685
760
|
Available Console Commands:
|
|
686
761
|
AmplifyUp.getStatus() - Show this status
|
|
687
762
|
AmplifyUp.getDiagnostics() - Get full diagnostic object
|
|
763
|
+
AmplifyUp.getTarget() - Current environment target
|
|
688
764
|
AmplifyUp.getInstanceId() - Get instance ID (browser/session ID)
|
|
689
765
|
AmplifyUp.getUserId() - Get user ID if identified
|
|
690
766
|
AmplifyUp.testTracking() - Send a test event
|