@amplifyup/sdk 0.1.21 → 0.1.23

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/dist/index.d.mts CHANGED
@@ -1,7 +1,99 @@
1
- import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-Cy5aWQ5c.mjs';
2
- export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-Cy5aWQ5c.mjs';
1
+ import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, a as CDPAdapter, b as AmplifyUpConfig, E as EventProperties, I as IdentifyInput, c as IdentifyTraits, d as ProfileFieldsInput, e as AmplifyUpTarget, f as EventTrackingConfig$1 } from './types-BxpG9Gsy.mjs';
2
+ export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-BxpG9Gsy.mjs';
3
3
  export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
4
4
 
5
+ interface FetchContentResult {
6
+ pageConfig: PageConfig | null;
7
+ source: ContentSource;
8
+ meta: AmplifyContentMeta | null;
9
+ error: string | null;
10
+ }
11
+ interface FetchContentOptions {
12
+ route: string;
13
+ trackingId: string;
14
+ anonId?: string | null;
15
+ siteId?: string | null;
16
+ /** Force preview (Composer); otherwise uses isComposerPreview() in browser. */
17
+ preview?: boolean;
18
+ orchestratorUrl: string;
19
+ edgeUrl: string;
20
+ /** Orchestrator layout fetch (SDK instance method or server helper). */
21
+ fetchOrchestratorPage: (route: string, preview: boolean) => Promise<PageConfig | null>;
22
+ fetchFn?: typeof fetch;
23
+ }
24
+ /**
25
+ * Single content entry point:
26
+ * - Composer / preview → orchestrator layout provider (drafts + live edits)
27
+ * - Production visitors → Edge /v1/resolve (personalized + CMS-populated)
28
+ *
29
+ * Production never falls back to the orchestrator on Edge failure —
30
+ * callers should render site fallback instead.
31
+ */
32
+ declare function fetchContent(options: FetchContentOptions): Promise<FetchContentResult>;
33
+
34
+ /** Mirrors Edge ResolvedComponent — SDK maps this into layoutTree nodes. */
35
+ interface EdgeResolvedComponent {
36
+ instanceId: string;
37
+ componentId: string;
38
+ props: Record<string, unknown>;
39
+ children?: Record<string, EdgeResolvedComponent[]>;
40
+ appliedRules?: string[];
41
+ degraded?: boolean;
42
+ }
43
+ interface EdgeResolvedPayload {
44
+ siteId: string;
45
+ route: string;
46
+ version: number;
47
+ zones: Record<string, EdgeResolvedComponent[]>;
48
+ tree?: EdgeResolvedComponent[];
49
+ meta: {
50
+ variantKeys: Record<string, string>;
51
+ audienceLookup?: {
52
+ status: string;
53
+ durationMs: number;
54
+ };
55
+ decideLookup?: {
56
+ status: string;
57
+ durationMs: number;
58
+ checks: number;
59
+ };
60
+ experiments?: Array<{
61
+ key: string;
62
+ variantKey: string;
63
+ bucket: number;
64
+ }>;
65
+ bot?: unknown;
66
+ resolvedAt: string;
67
+ degraded?: boolean;
68
+ };
69
+ }
70
+ declare class EdgeResolveError extends Error {
71
+ status: number;
72
+ body: unknown;
73
+ constructor(message: string, status: number, body?: unknown);
74
+ }
75
+ declare function fetchEdgeResolve(options: {
76
+ edgeUrl: string;
77
+ trackingId: string;
78
+ route: string;
79
+ anonId?: string | null;
80
+ siteId?: string | null;
81
+ fetch?: typeof fetch;
82
+ }): Promise<EdgeResolvedPayload>;
83
+
84
+ /**
85
+ * Map Edge /v1/resolve payload → PageConfig for AmplifyRenderer.
86
+ * Prefers `tree` (full page skeleton with zones spliced in); falls back to
87
+ * flattening zone roots when older snapshots lack structure.
88
+ */
89
+ declare function mapResolvedToPageConfig(payload: EdgeResolvedPayload): PageConfig;
90
+
91
+ /**
92
+ * Normalize a route path for Edge resolve requests.
93
+ * Leading slash, no trailing slash (except root), query/hash stripped.
94
+ */
95
+ declare function normalizeRoute(route: string): string;
96
+
5
97
  /**
6
98
  * AmplifyUp Tracking SDK
7
99
  *
@@ -11,6 +103,11 @@ export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUv
11
103
  * All runtime data (events, profiles, decisions) lives in AWS.
12
104
  */
13
105
 
106
+ /**
107
+ * Idle gap that starts a new logical visit when a tab is reactivated.
108
+ * Must stay aligned with SESSION_GAP_MS in apps/orchestrator/lib/aws-profiles.ts.
109
+ */
110
+ declare const SESSION_IDLE_GAP_MS: number;
14
111
  interface EventTrackingConfig {
15
112
  eventName: string;
16
113
  eventType: string;
@@ -27,6 +124,8 @@ declare class AmplifyUpSDK {
27
124
  private apiGatewayUrl;
28
125
  private orchestratorUrl;
29
126
  private decisionApiUrl;
127
+ private edgeUrl;
128
+ private siteId;
30
129
  private target;
31
130
  private initialized;
32
131
  /** Prevents overlapping init() from React Strict Mode double-mount */
@@ -99,7 +198,10 @@ declare class AmplifyUpSDK {
99
198
  * State lives on the instance so SPA route changes can reset milestones.
100
199
  */
101
200
  private setupPageEngagement;
201
+ /** Flush dwell then reset — used on SPA route changes. */
102
202
  private resetEngagementForNewPage;
203
+ /** Reset dwell/scroll state without emitting (idle resume already flushed on hide). */
204
+ private resetEngagementQuiet;
103
205
  /**
104
206
  * SPA / soft navigation: fire a page view and reset engagement.
105
207
  * No-op when the path has not changed. Safe for React Strict Mode remounts.
@@ -140,9 +242,17 @@ declare class AmplifyUpSDK {
140
242
  */
141
243
  trackContentView(contentId: string, contentType: string, properties?: EventProperties): void;
142
244
  /**
143
- * Identify user (when they sign up or log in)
245
+ * Identify a visitor.
246
+ * - identify('user_123') — bare string; server maps via org default type
247
+ * - identify({ email: '...', crm_id: '...' }) — explicit types
248
+ * - identify('user_123', traits) — legacy form
249
+ */
250
+ identify(userIdOrIdentifiers: IdentifyInput, traits?: IdentifyTraits): void;
251
+ /**
252
+ * Set profile fields (partial update). Omitted keys are left alone;
253
+ * an explicit empty value clears the field.
144
254
  */
145
- identify(userId: string, traits?: IdentifyTraits): void;
255
+ setProfileFields(fields: ProfileFieldsInput): void;
146
256
  /**
147
257
  * Track content engagement (when user interacts with personalized content)
148
258
  */
@@ -206,6 +316,14 @@ declare class AmplifyUpSDK {
206
316
  * Get decision API URL
207
317
  */
208
318
  getDecisionApiUrl(): string | undefined;
319
+ /**
320
+ * Get Edge Worker URL (production content resolve)
321
+ */
322
+ getEdgeUrl(): string | undefined;
323
+ /**
324
+ * Optional site id from config (Edge can resolve via trackingId alone).
325
+ */
326
+ getSiteId(): string | undefined;
209
327
  /**
210
328
  * Build API URL for fetching page config from the Layout Provider
211
329
  */
@@ -336,7 +454,8 @@ declare const trackClick: (elementId: string, elementText: string, properties?:
336
454
  declare const trackFormSubmit: (formId: string, formData?: EventProperties) => void;
337
455
  declare const trackFormFieldInteraction: (fieldName: string, fieldValue?: string) => void;
338
456
  declare const trackContentView: (contentId: string, contentType: string, properties?: EventProperties) => void;
339
- declare const identify: (userId: string, traits?: IdentifyTraits) => void;
457
+ declare const identify: (userIdOrIdentifiers: IdentifyInput, traits?: IdentifyTraits) => void;
458
+ declare const setProfileFields: (fields: ProfileFieldsInput) => void;
340
459
  declare const trackContentEngagement: (contentId: string, engagementType: "view" | "click" | "dismiss") => void;
341
460
  declare const reset: () => void;
342
461
  declare const getInstanceId: () => string;
@@ -386,4 +505,4 @@ declare const verifyAWSConnection: () => {
386
505
 
387
506
  declare const _default: AmplifyUpSDK;
388
507
 
389
- export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, page, refreshEventTracking, reset, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
508
+ export { AmplifyContentMeta, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, IdentifyInput, IdentifyTraits, PageConfig, ProfileFieldsInput, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,99 @@
1
- import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-Cy5aWQ5c.js';
2
- export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-Cy5aWQ5c.js';
1
+ import { P as PageConfig, C as ContentSource, A as AmplifyContentMeta, a as CDPAdapter, b as AmplifyUpConfig, E as EventProperties, I as IdentifyInput, c as IdentifyTraits, d as ProfileFieldsInput, e as AmplifyUpTarget, f as EventTrackingConfig$1 } from './types-BxpG9Gsy.js';
2
+ export { Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, g as resolveAmplifyUpUrls } from './types-BxpG9Gsy.js';
3
3
  export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
4
4
 
5
+ interface FetchContentResult {
6
+ pageConfig: PageConfig | null;
7
+ source: ContentSource;
8
+ meta: AmplifyContentMeta | null;
9
+ error: string | null;
10
+ }
11
+ interface FetchContentOptions {
12
+ route: string;
13
+ trackingId: string;
14
+ anonId?: string | null;
15
+ siteId?: string | null;
16
+ /** Force preview (Composer); otherwise uses isComposerPreview() in browser. */
17
+ preview?: boolean;
18
+ orchestratorUrl: string;
19
+ edgeUrl: string;
20
+ /** Orchestrator layout fetch (SDK instance method or server helper). */
21
+ fetchOrchestratorPage: (route: string, preview: boolean) => Promise<PageConfig | null>;
22
+ fetchFn?: typeof fetch;
23
+ }
24
+ /**
25
+ * Single content entry point:
26
+ * - Composer / preview → orchestrator layout provider (drafts + live edits)
27
+ * - Production visitors → Edge /v1/resolve (personalized + CMS-populated)
28
+ *
29
+ * Production never falls back to the orchestrator on Edge failure —
30
+ * callers should render site fallback instead.
31
+ */
32
+ declare function fetchContent(options: FetchContentOptions): Promise<FetchContentResult>;
33
+
34
+ /** Mirrors Edge ResolvedComponent — SDK maps this into layoutTree nodes. */
35
+ interface EdgeResolvedComponent {
36
+ instanceId: string;
37
+ componentId: string;
38
+ props: Record<string, unknown>;
39
+ children?: Record<string, EdgeResolvedComponent[]>;
40
+ appliedRules?: string[];
41
+ degraded?: boolean;
42
+ }
43
+ interface EdgeResolvedPayload {
44
+ siteId: string;
45
+ route: string;
46
+ version: number;
47
+ zones: Record<string, EdgeResolvedComponent[]>;
48
+ tree?: EdgeResolvedComponent[];
49
+ meta: {
50
+ variantKeys: Record<string, string>;
51
+ audienceLookup?: {
52
+ status: string;
53
+ durationMs: number;
54
+ };
55
+ decideLookup?: {
56
+ status: string;
57
+ durationMs: number;
58
+ checks: number;
59
+ };
60
+ experiments?: Array<{
61
+ key: string;
62
+ variantKey: string;
63
+ bucket: number;
64
+ }>;
65
+ bot?: unknown;
66
+ resolvedAt: string;
67
+ degraded?: boolean;
68
+ };
69
+ }
70
+ declare class EdgeResolveError extends Error {
71
+ status: number;
72
+ body: unknown;
73
+ constructor(message: string, status: number, body?: unknown);
74
+ }
75
+ declare function fetchEdgeResolve(options: {
76
+ edgeUrl: string;
77
+ trackingId: string;
78
+ route: string;
79
+ anonId?: string | null;
80
+ siteId?: string | null;
81
+ fetch?: typeof fetch;
82
+ }): Promise<EdgeResolvedPayload>;
83
+
84
+ /**
85
+ * Map Edge /v1/resolve payload → PageConfig for AmplifyRenderer.
86
+ * Prefers `tree` (full page skeleton with zones spliced in); falls back to
87
+ * flattening zone roots when older snapshots lack structure.
88
+ */
89
+ declare function mapResolvedToPageConfig(payload: EdgeResolvedPayload): PageConfig;
90
+
91
+ /**
92
+ * Normalize a route path for Edge resolve requests.
93
+ * Leading slash, no trailing slash (except root), query/hash stripped.
94
+ */
95
+ declare function normalizeRoute(route: string): string;
96
+
5
97
  /**
6
98
  * AmplifyUp Tracking SDK
7
99
  *
@@ -11,6 +103,11 @@ export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUv
11
103
  * All runtime data (events, profiles, decisions) lives in AWS.
12
104
  */
13
105
 
106
+ /**
107
+ * Idle gap that starts a new logical visit when a tab is reactivated.
108
+ * Must stay aligned with SESSION_GAP_MS in apps/orchestrator/lib/aws-profiles.ts.
109
+ */
110
+ declare const SESSION_IDLE_GAP_MS: number;
14
111
  interface EventTrackingConfig {
15
112
  eventName: string;
16
113
  eventType: string;
@@ -27,6 +124,8 @@ declare class AmplifyUpSDK {
27
124
  private apiGatewayUrl;
28
125
  private orchestratorUrl;
29
126
  private decisionApiUrl;
127
+ private edgeUrl;
128
+ private siteId;
30
129
  private target;
31
130
  private initialized;
32
131
  /** Prevents overlapping init() from React Strict Mode double-mount */
@@ -99,7 +198,10 @@ declare class AmplifyUpSDK {
99
198
  * State lives on the instance so SPA route changes can reset milestones.
100
199
  */
101
200
  private setupPageEngagement;
201
+ /** Flush dwell then reset — used on SPA route changes. */
102
202
  private resetEngagementForNewPage;
203
+ /** Reset dwell/scroll state without emitting (idle resume already flushed on hide). */
204
+ private resetEngagementQuiet;
103
205
  /**
104
206
  * SPA / soft navigation: fire a page view and reset engagement.
105
207
  * No-op when the path has not changed. Safe for React Strict Mode remounts.
@@ -140,9 +242,17 @@ declare class AmplifyUpSDK {
140
242
  */
141
243
  trackContentView(contentId: string, contentType: string, properties?: EventProperties): void;
142
244
  /**
143
- * Identify user (when they sign up or log in)
245
+ * Identify a visitor.
246
+ * - identify('user_123') — bare string; server maps via org default type
247
+ * - identify({ email: '...', crm_id: '...' }) — explicit types
248
+ * - identify('user_123', traits) — legacy form
249
+ */
250
+ identify(userIdOrIdentifiers: IdentifyInput, traits?: IdentifyTraits): void;
251
+ /**
252
+ * Set profile fields (partial update). Omitted keys are left alone;
253
+ * an explicit empty value clears the field.
144
254
  */
145
- identify(userId: string, traits?: IdentifyTraits): void;
255
+ setProfileFields(fields: ProfileFieldsInput): void;
146
256
  /**
147
257
  * Track content engagement (when user interacts with personalized content)
148
258
  */
@@ -206,6 +316,14 @@ declare class AmplifyUpSDK {
206
316
  * Get decision API URL
207
317
  */
208
318
  getDecisionApiUrl(): string | undefined;
319
+ /**
320
+ * Get Edge Worker URL (production content resolve)
321
+ */
322
+ getEdgeUrl(): string | undefined;
323
+ /**
324
+ * Optional site id from config (Edge can resolve via trackingId alone).
325
+ */
326
+ getSiteId(): string | undefined;
209
327
  /**
210
328
  * Build API URL for fetching page config from the Layout Provider
211
329
  */
@@ -336,7 +454,8 @@ declare const trackClick: (elementId: string, elementText: string, properties?:
336
454
  declare const trackFormSubmit: (formId: string, formData?: EventProperties) => void;
337
455
  declare const trackFormFieldInteraction: (fieldName: string, fieldValue?: string) => void;
338
456
  declare const trackContentView: (contentId: string, contentType: string, properties?: EventProperties) => void;
339
- declare const identify: (userId: string, traits?: IdentifyTraits) => void;
457
+ declare const identify: (userIdOrIdentifiers: IdentifyInput, traits?: IdentifyTraits) => void;
458
+ declare const setProfileFields: (fields: ProfileFieldsInput) => void;
340
459
  declare const trackContentEngagement: (contentId: string, engagementType: "view" | "click" | "dismiss") => void;
341
460
  declare const reset: () => void;
342
461
  declare const getInstanceId: () => string;
@@ -386,4 +505,4 @@ declare const verifyAWSConnection: () => {
386
505
 
387
506
  declare const _default: AmplifyUpSDK;
388
507
 
389
- export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, page, refreshEventTracking, reset, routeChange, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
508
+ export { AmplifyContentMeta, AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, ContentSource, EdgeResolveError, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, type FetchContentOptions, type FetchContentResult, IdentifyInput, IdentifyTraits, PageConfig, ProfileFieldsInput, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, _default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId, identify, init, mapResolvedToPageConfig, normalizeRoute, page, refreshEventTracking, reset, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };