@amplifyup/sdk 0.1.22 → 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
  *
@@ -32,6 +124,8 @@ declare class AmplifyUpSDK {
32
124
  private apiGatewayUrl;
33
125
  private orchestratorUrl;
34
126
  private decisionApiUrl;
127
+ private edgeUrl;
128
+ private siteId;
35
129
  private target;
36
130
  private initialized;
37
131
  /** Prevents overlapping init() from React Strict Mode double-mount */
@@ -148,9 +242,17 @@ declare class AmplifyUpSDK {
148
242
  */
149
243
  trackContentView(contentId: string, contentType: string, properties?: EventProperties): void;
150
244
  /**
151
- * 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
152
249
  */
153
- identify(userId: string, traits?: IdentifyTraits): void;
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.
254
+ */
255
+ setProfileFields(fields: ProfileFieldsInput): void;
154
256
  /**
155
257
  * Track content engagement (when user interacts with personalized content)
156
258
  */
@@ -214,6 +316,14 @@ declare class AmplifyUpSDK {
214
316
  * Get decision API URL
215
317
  */
216
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;
217
327
  /**
218
328
  * Build API URL for fetching page config from the Layout Provider
219
329
  */
@@ -344,7 +454,8 @@ declare const trackClick: (elementId: string, elementText: string, properties?:
344
454
  declare const trackFormSubmit: (formId: string, formData?: EventProperties) => void;
345
455
  declare const trackFormFieldInteraction: (fieldName: string, fieldValue?: string) => void;
346
456
  declare const trackContentView: (contentId: string, contentType: string, properties?: EventProperties) => void;
347
- declare const identify: (userId: string, traits?: IdentifyTraits) => void;
457
+ declare const identify: (userIdOrIdentifiers: IdentifyInput, traits?: IdentifyTraits) => void;
458
+ declare const setProfileFields: (fields: ProfileFieldsInput) => void;
348
459
  declare const trackContentEngagement: (contentId: string, engagementType: "view" | "click" | "dismiss") => void;
349
460
  declare const reset: () => void;
350
461
  declare const getInstanceId: () => string;
@@ -394,4 +505,4 @@ declare const verifyAWSConnection: () => {
394
505
 
395
506
  declare const _default: AmplifyUpSDK;
396
507
 
397
- export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, SESSION_IDLE_GAP_MS, 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
  *
@@ -32,6 +124,8 @@ declare class AmplifyUpSDK {
32
124
  private apiGatewayUrl;
33
125
  private orchestratorUrl;
34
126
  private decisionApiUrl;
127
+ private edgeUrl;
128
+ private siteId;
35
129
  private target;
36
130
  private initialized;
37
131
  /** Prevents overlapping init() from React Strict Mode double-mount */
@@ -148,9 +242,17 @@ declare class AmplifyUpSDK {
148
242
  */
149
243
  trackContentView(contentId: string, contentType: string, properties?: EventProperties): void;
150
244
  /**
151
- * 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
152
249
  */
153
- identify(userId: string, traits?: IdentifyTraits): void;
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.
254
+ */
255
+ setProfileFields(fields: ProfileFieldsInput): void;
154
256
  /**
155
257
  * Track content engagement (when user interacts with personalized content)
156
258
  */
@@ -214,6 +316,14 @@ declare class AmplifyUpSDK {
214
316
  * Get decision API URL
215
317
  */
216
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;
217
327
  /**
218
328
  * Build API URL for fetching page config from the Layout Provider
219
329
  */
@@ -344,7 +454,8 @@ declare const trackClick: (elementId: string, elementText: string, properties?:
344
454
  declare const trackFormSubmit: (formId: string, formData?: EventProperties) => void;
345
455
  declare const trackFormFieldInteraction: (fieldName: string, fieldValue?: string) => void;
346
456
  declare const trackContentView: (contentId: string, contentType: string, properties?: EventProperties) => void;
347
- declare const identify: (userId: string, traits?: IdentifyTraits) => void;
457
+ declare const identify: (userIdOrIdentifiers: IdentifyInput, traits?: IdentifyTraits) => void;
458
+ declare const setProfileFields: (fields: ProfileFieldsInput) => void;
348
459
  declare const trackContentEngagement: (contentId: string, engagementType: "view" | "click" | "dismiss") => void;
349
460
  declare const reset: () => void;
350
461
  declare const getInstanceId: () => string;
@@ -394,4 +505,4 @@ declare const verifyAWSConnection: () => {
394
505
 
395
506
  declare const _default: AmplifyUpSDK;
396
507
 
397
- export { AmplifyUpConfig, AmplifyUpSDK, AmplifyUpTarget, CDPAdapter, EventProperties, EventTrackingConfig$1 as EventTrackingConfig, IdentifyTraits, SESSION_IDLE_GAP_MS, 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 };