@amplifyup/sdk 0.1.1 → 0.1.3
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 +5 -5
package/README.md
CHANGED
|
@@ -4,7 +4,28 @@ AmplifyUp Tracking SDK - CDP-agnostic event tracking library.
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This SDK provides event tracking
|
|
7
|
+
This SDK provides event tracking and personalization against AmplifyUp backends.
|
|
8
|
+
Configure a `trackingId`, and optionally a `target` for which environment to use.
|
|
9
|
+
|
|
10
|
+
## Environment targets
|
|
11
|
+
|
|
12
|
+
Two environments — `local` and `production`. Legacy `dev` maps to `local`.
|
|
13
|
+
|
|
14
|
+
| Target | Layouts / config (Neon) | Events + personalize |
|
|
15
|
+
|--------|-------------------------|----------------------|
|
|
16
|
+
| `local` | `NEXT_PUBLIC_ORCHESTRATOR_URL` (e.g. `http://localhost:5001`) | `https://api-dev.amplifyup.ai` (AWS development) |
|
|
17
|
+
| `production` | `https://amplifyup.ai` | `https://api.amplifyup.ai` |
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Demo on http://localhost:5000 — pages from local Neon, events to AWS-dev
|
|
21
|
+
NEXT_PUBLIC_ORCHESTRATOR_URL=http://localhost:5001
|
|
22
|
+
NEXT_PUBLIC_AMPLIFYUP_TARGET=local
|
|
23
|
+
|
|
24
|
+
# Optional: override AWS API base used by local (default api-dev)
|
|
25
|
+
# NEXT_PUBLIC_AMPLIFYUP_API_URL=https://api-dev.amplifyup.ai
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Check active URLs in the browser: `AmplifyUp.getStatus()`
|
|
8
29
|
|
|
9
30
|
## Installation
|
|
10
31
|
|
|
@@ -19,10 +40,9 @@ npm install @amplifyup/sdk
|
|
|
19
40
|
```typescript
|
|
20
41
|
import { init } from '@amplifyup/sdk';
|
|
21
42
|
|
|
22
|
-
// Initialize the SDK (URLs are hardcoded)
|
|
23
43
|
await init({
|
|
24
44
|
trackingId: 'your-tracking-id',
|
|
25
|
-
debug: true,
|
|
45
|
+
debug: true,
|
|
26
46
|
});
|
|
27
47
|
```
|
|
28
48
|
|
|
@@ -100,21 +120,6 @@ npm run dev
|
|
|
100
120
|
npm run lint
|
|
101
121
|
```
|
|
102
122
|
|
|
103
|
-
## Publishing (maintainers)
|
|
104
|
-
|
|
105
|
-
CI publishes via **npm Trusted Publishing** (GitHub ↔ npm, no long-lived token).
|
|
106
|
-
|
|
107
|
-
**One-time setup on npm:**
|
|
108
|
-
|
|
109
|
-
1. **If the package has never been published:** Publish once with a token so the package exists: add `NPM_TOKEN` (Automation token) in repo Secrets, run the workflow, then remove the token and continue below.
|
|
110
|
-
2. On [npmjs.com](https://www.npmjs.com): sign in → **Packages** → **@amplifyup/sdk** → **Settings** → **Trusted publishing**.
|
|
111
|
-
3. Under “Select your publisher” choose **GitHub Actions** and set:
|
|
112
|
-
- **Workflow filename:** `publish-sdk.yml` (must match exactly)
|
|
113
|
-
- Repository/owner as prompted.
|
|
114
|
-
4. Save. Future runs publish with no `NPM_TOKEN` secret.
|
|
115
|
-
|
|
116
|
-
Requires Node 22.14+ and npm 11.5.1+ (workflow uses Node 22).
|
|
117
|
-
|
|
118
123
|
## License
|
|
119
124
|
|
|
120
125
|
MIT
|
package/dist/AmplifyRenderer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
var react = require('react');
|
|
@@ -220,9 +221,69 @@ function clearIds() {
|
|
|
220
221
|
localStorage.removeItem(USER_ID_KEY);
|
|
221
222
|
}
|
|
222
223
|
|
|
224
|
+
// src/targets.ts
|
|
225
|
+
var AWS_DEV_API = "https://api-dev.amplifyup.ai";
|
|
226
|
+
var AWS_PROD_API = "https://api.amplifyup.ai";
|
|
227
|
+
var PROD_ORCHESTRATOR = "https://amplifyup.ai";
|
|
228
|
+
function isAmplifyUpTarget(value) {
|
|
229
|
+
return value === "local" || value === "dev" || value === "production";
|
|
230
|
+
}
|
|
231
|
+
function normalizeAmplifyUpTarget(value) {
|
|
232
|
+
return value === "dev" ? "local" : value;
|
|
233
|
+
}
|
|
234
|
+
function resolveAmplifyUpTarget(options) {
|
|
235
|
+
if (options?.configTarget && isAmplifyUpTarget(options.configTarget)) {
|
|
236
|
+
return normalizeAmplifyUpTarget(options.configTarget);
|
|
237
|
+
}
|
|
238
|
+
if (options?.configDev === true) {
|
|
239
|
+
return "local";
|
|
240
|
+
}
|
|
241
|
+
const envTarget = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_TARGET : void 0;
|
|
242
|
+
if (isAmplifyUpTarget(envTarget)) {
|
|
243
|
+
return normalizeAmplifyUpTarget(envTarget);
|
|
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
|
+
return "production";
|
|
252
|
+
}
|
|
253
|
+
function localOrchestratorUrl() {
|
|
254
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
255
|
+
return (fromEnv || "http://localhost:5001").replace(/\/$/, "");
|
|
256
|
+
}
|
|
257
|
+
function localAwsApiUrl() {
|
|
258
|
+
const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL : void 0;
|
|
259
|
+
return (fromEnv || AWS_DEV_API).replace(/\/$/, "");
|
|
260
|
+
}
|
|
261
|
+
function resolveAmplifyUpUrls(target) {
|
|
262
|
+
if (target === "local") {
|
|
263
|
+
const orchestratorUrl2 = localOrchestratorUrl();
|
|
264
|
+
const apiGatewayUrl = localAwsApiUrl();
|
|
265
|
+
return {
|
|
266
|
+
target: "local",
|
|
267
|
+
// Layouts / site config / composer APIs → local orchestrator + Neon
|
|
268
|
+
orchestratorUrl: orchestratorUrl2,
|
|
269
|
+
// Events + personalize → AWS development stack
|
|
270
|
+
apiGatewayUrl,
|
|
271
|
+
decisionApiUrl: `${apiGatewayUrl}/v1/personalize`
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const resolvedApi = typeof process !== "undefined" && process.env.NEXT_PUBLIC_AMPLIFYUP_API_URL?.replace(/\/$/, "") || AWS_PROD_API;
|
|
275
|
+
const orchestratorFromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
|
|
276
|
+
const isLocalOrchestrator = !!orchestratorFromEnv && (orchestratorFromEnv.includes("localhost") || orchestratorFromEnv.includes("127.0.0.1"));
|
|
277
|
+
const orchestratorUrl = isLocalOrchestrator || !orchestratorFromEnv ? PROD_ORCHESTRATOR : orchestratorFromEnv.replace(/\/$/, "");
|
|
278
|
+
return {
|
|
279
|
+
target: "production",
|
|
280
|
+
apiGatewayUrl: resolvedApi,
|
|
281
|
+
orchestratorUrl,
|
|
282
|
+
decisionApiUrl: `${resolvedApi}/v1/personalize`
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
223
286
|
// src/index.ts
|
|
224
|
-
var PROD_API_URL = "https://api.amplifyup.ai" ;
|
|
225
|
-
var PROD_ORCHESTRATOR_URL = "https://amplifyup.ai" ;
|
|
226
287
|
var AmplifyUpSDK = class {
|
|
227
288
|
constructor(adapter) {
|
|
228
289
|
this.config = null;
|
|
@@ -230,7 +291,12 @@ var AmplifyUpSDK = class {
|
|
|
230
291
|
this.apiGatewayUrl = "";
|
|
231
292
|
this.orchestratorUrl = "";
|
|
232
293
|
this.decisionApiUrl = "";
|
|
294
|
+
this.target = "local";
|
|
233
295
|
this.initialized = false;
|
|
296
|
+
/** Prevents overlapping init() from React Strict Mode double-mount */
|
|
297
|
+
this.initPromise = null;
|
|
298
|
+
/** Ensures auto page() on init fires once per page load */
|
|
299
|
+
this.initialPageSent = false;
|
|
234
300
|
this.highlightingEnabled = false;
|
|
235
301
|
this.componentRegistry = [];
|
|
236
302
|
this.messageListener = null;
|
|
@@ -313,46 +379,41 @@ var AmplifyUpSDK = class {
|
|
|
313
379
|
}
|
|
314
380
|
return false;
|
|
315
381
|
}
|
|
316
|
-
/**
|
|
317
|
-
* Get production URLs
|
|
318
|
-
*
|
|
319
|
-
* URLs are baked in at build time via tsup.config.ts
|
|
320
|
-
*
|
|
321
|
-
* API Gateway endpoints:
|
|
322
|
-
* - /v1/track - Event tracking (ingestion)
|
|
323
|
-
* - /v1/page - Page view tracking (ingestion)
|
|
324
|
-
* - /v1/personalize - Decision engine (personalization)
|
|
325
|
-
*/
|
|
326
|
-
getProductionUrls() {
|
|
327
|
-
return {
|
|
328
|
-
apiGatewayUrl: PROD_API_URL,
|
|
329
|
-
orchestratorUrl: PROD_ORCHESTRATOR_URL,
|
|
330
|
-
decisionApiUrl: `${PROD_API_URL}/v1/personalize`
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
382
|
/**
|
|
334
383
|
* Initialize the SDK
|
|
335
|
-
*
|
|
384
|
+
* Resolves local | dev | production targets for ingestion + personalization URLs.
|
|
336
385
|
*/
|
|
337
386
|
async init(config) {
|
|
387
|
+
if (this.initialized && this.adapter?.isInitialized()) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (this.initPromise) {
|
|
391
|
+
return this.initPromise;
|
|
392
|
+
}
|
|
393
|
+
this.initPromise = this.performInit(config);
|
|
394
|
+
try {
|
|
395
|
+
await this.initPromise;
|
|
396
|
+
} finally {
|
|
397
|
+
this.initPromise = null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async performInit(config) {
|
|
338
401
|
if (!this.adapter) {
|
|
339
402
|
this.adapter = new AWSAdapter();
|
|
340
403
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
this.orchestratorUrl = urls.orchestratorUrl;
|
|
350
|
-
this.decisionApiUrl = urls.decisionApiUrl;
|
|
351
|
-
}
|
|
404
|
+
this.target = resolveAmplifyUpTarget({
|
|
405
|
+
configTarget: config.target,
|
|
406
|
+
configDev: config.dev
|
|
407
|
+
});
|
|
408
|
+
const urls = resolveAmplifyUpUrls(this.target);
|
|
409
|
+
this.apiGatewayUrl = urls.apiGatewayUrl;
|
|
410
|
+
this.orchestratorUrl = urls.orchestratorUrl;
|
|
411
|
+
this.decisionApiUrl = urls.decisionApiUrl;
|
|
352
412
|
this.config = {
|
|
353
413
|
trackingId: config.trackingId,
|
|
354
414
|
debug: config.debug ?? true,
|
|
355
415
|
// Enable debug by default
|
|
416
|
+
target: this.target,
|
|
356
417
|
dev: config.dev
|
|
357
418
|
};
|
|
358
419
|
try {
|
|
@@ -369,6 +430,7 @@ var AmplifyUpSDK = class {
|
|
|
369
430
|
getInstanceId: () => this.getInstanceId(),
|
|
370
431
|
getUserId: () => this.getUserId(),
|
|
371
432
|
getTrackingId: () => this.getTrackingId(),
|
|
433
|
+
getTarget: () => this.getTarget(),
|
|
372
434
|
getDiagnostics: () => this.getDiagnostics(),
|
|
373
435
|
getStatus: () => {
|
|
374
436
|
console.log(this.getStatus());
|
|
@@ -389,7 +451,7 @@ var AmplifyUpSDK = class {
|
|
|
389
451
|
};
|
|
390
452
|
if (this.config?.debug) {
|
|
391
453
|
console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
|
|
392
|
-
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.
|
|
454
|
+
console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
|
|
393
455
|
}
|
|
394
456
|
}
|
|
395
457
|
this.clearTrackingIntervals();
|
|
@@ -401,11 +463,20 @@ var AmplifyUpSDK = class {
|
|
|
401
463
|
if (this.isPreviewMode()) {
|
|
402
464
|
return;
|
|
403
465
|
}
|
|
404
|
-
|
|
405
|
-
|
|
466
|
+
if (!this.initialPageSent) {
|
|
467
|
+
this.initialPageSent = true;
|
|
468
|
+
const url = window.location.pathname;
|
|
469
|
+
this.page(url);
|
|
470
|
+
}
|
|
406
471
|
}
|
|
407
472
|
if (this.config?.debug && this.initialized) {
|
|
408
|
-
console.log("AmplifyUp SDK: Initialized successfully", {
|
|
473
|
+
console.log("AmplifyUp SDK: Initialized successfully", {
|
|
474
|
+
trackingId: config.trackingId,
|
|
475
|
+
target: this.target,
|
|
476
|
+
apiGatewayUrl: this.apiGatewayUrl,
|
|
477
|
+
orchestratorUrl: this.orchestratorUrl,
|
|
478
|
+
decisionApiUrl: this.decisionApiUrl || "(orchestrator fallback)"
|
|
479
|
+
});
|
|
409
480
|
}
|
|
410
481
|
} catch (error) {
|
|
411
482
|
console.error("AmplifyUp SDK: Initialization failed", error);
|
|
@@ -606,6 +677,7 @@ var AmplifyUpSDK = class {
|
|
|
606
677
|
instanceId,
|
|
607
678
|
userId,
|
|
608
679
|
trackingId: this.config?.trackingId,
|
|
680
|
+
target: this.target,
|
|
609
681
|
config: {
|
|
610
682
|
apiGatewayUrl: this.apiGatewayUrl,
|
|
611
683
|
decisionApiUrl: this.decisionApiUrl,
|
|
@@ -614,6 +686,9 @@ var AmplifyUpSDK = class {
|
|
|
614
686
|
}
|
|
615
687
|
};
|
|
616
688
|
}
|
|
689
|
+
getTarget() {
|
|
690
|
+
return this.target;
|
|
691
|
+
}
|
|
617
692
|
/**
|
|
618
693
|
* Test tracking by sending a test event
|
|
619
694
|
*/
|
|
@@ -671,6 +746,7 @@ var AmplifyUpSDK = class {
|
|
|
671
746
|
AmplifyUp SDK Status:
|
|
672
747
|
\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
|
|
673
748
|
Initialized: ${diag.initialized ? "\u2705 Yes" : "\u274C No"}
|
|
749
|
+
Target: ${diag.target}
|
|
674
750
|
Instance ID: ${diag.instanceId}
|
|
675
751
|
User ID: ${diag.userId || "Not identified"}
|
|
676
752
|
Tracking ID: ${diag.trackingId || "Not set"}
|
|
@@ -682,11 +758,11 @@ Config:
|
|
|
682
758
|
API Gateway: ${this.apiGatewayUrl || "Not set (required)"}
|
|
683
759
|
Decision API: ${this.decisionApiUrl || "Not set (using Orchestrator fallback)"}
|
|
684
760
|
Orchestrator: ${this.orchestratorUrl || "Not set"}
|
|
685
|
-
Debug: ${diag.config.debug ? "Enabled" : "Disabled"}
|
|
686
761
|
|
|
687
762
|
Available Console Commands:
|
|
688
763
|
AmplifyUp.getStatus() - Show this status
|
|
689
764
|
AmplifyUp.getDiagnostics() - Get full diagnostic object
|
|
765
|
+
AmplifyUp.getTarget() - Current environment target
|
|
690
766
|
AmplifyUp.getInstanceId() - Get instance ID (browser/session ID)
|
|
691
767
|
AmplifyUp.getUserId() - Get user ID if identified
|
|
692
768
|
AmplifyUp.testTracking() - Send a test event
|