@commercengine/js 0.1.0

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.
@@ -0,0 +1,341 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Commerce Engine Checkout - Type Definitions
4
+ *
5
+ * @commercengine/js
6
+ *
7
+ * This is the single source of truth for checkout configuration.
8
+ * The checkout app parses these from URL parameters.
9
+ */
10
+ /**
11
+ * Authentication mode
12
+ * - 'managed': Checkout manages token lifecycle (refresh, storage)
13
+ * - 'provided': Parent manages tokens. Checkout uses in-memory only, syncs via events
14
+ */
15
+ type AuthMode = "managed" | "provided";
16
+ /**
17
+ * Item to add to cart
18
+ */
19
+ interface AddToCartItem {
20
+ /**
21
+ * Product ID (required)
22
+ */
23
+ productId: string;
24
+ /**
25
+ * Variant ID (required, null for non-variant products)
26
+ */
27
+ variantId: string | null;
28
+ /**
29
+ * Quantity to add
30
+ * @default 1
31
+ */
32
+ quantity?: number;
33
+ }
34
+ /**
35
+ * Quick buy configuration for initialization
36
+ * Adds a product to cart when checkout initializes
37
+ */
38
+ interface QuickBuyConfig {
39
+ /**
40
+ * Product ID (required)
41
+ */
42
+ productId: string;
43
+ /**
44
+ * Variant ID (required, null for non-variant products)
45
+ */
46
+ variantId: string | null;
47
+ /**
48
+ * Quantity to add
49
+ * @default 1
50
+ */
51
+ quantity?: number;
52
+ }
53
+ /**
54
+ * Session behavior mode
55
+ * - 'continue-existing': Add quick-buy item to existing cart (default)
56
+ * - 'force-new': Clear cart and start fresh
57
+ */
58
+ type SessionMode = "continue-existing" | "force-new";
59
+ /**
60
+ * Configuration for initializing checkout
61
+ *
62
+ * Either provide `url` directly (for local development) or
63
+ * provide `storeId` + `apiKey` (for production).
64
+ */
65
+ interface CheckoutConfig {
66
+ /**
67
+ * Direct checkout URL (for local development)
68
+ * If provided, storeId and apiKey are optional.
69
+ * @example "http://localhost:8080"
70
+ */
71
+ url?: string;
72
+ /**
73
+ * Your Commerce Engine Store ID
74
+ * Required if `url` is not provided.
75
+ * @example "store_abc123"
76
+ */
77
+ storeId?: string;
78
+ /**
79
+ * Your Commerce Engine API Key
80
+ * Required if `url` is not provided.
81
+ * @example "ak_test_xyz789"
82
+ */
83
+ apiKey?: string;
84
+ /**
85
+ * Theme preference
86
+ * @default "system"
87
+ */
88
+ theme?: "light" | "dark" | "system";
89
+ /**
90
+ * Appearance customization
91
+ */
92
+ appearance?: {
93
+ /**
94
+ * Z-index for the checkout overlay
95
+ * @default 99999
96
+ */
97
+ zIndex?: number;
98
+ };
99
+ /**
100
+ * Authentication mode
101
+ * - 'managed': Checkout manages token lifecycle (default)
102
+ * - 'provided': Parent manages tokens, checkout uses in-memory only
103
+ * @default "managed"
104
+ */
105
+ authMode?: AuthMode;
106
+ /**
107
+ * Initial access token (if user already logged in on parent site)
108
+ */
109
+ accessToken?: string;
110
+ /**
111
+ * Initial refresh token
112
+ */
113
+ refreshToken?: string;
114
+ /**
115
+ * Quick buy configuration for "Buy Now" flows
116
+ * When provided, adds the product to cart on initialization
117
+ */
118
+ quickBuy?: QuickBuyConfig;
119
+ /**
120
+ * Session behavior when quick buy is used
121
+ * @default "continue-existing"
122
+ */
123
+ sessionMode?: SessionMode;
124
+ /**
125
+ * Auto-detect quick buy params from parent page URL
126
+ * When enabled, SDK parses window.location.search for:
127
+ * - product_id, variant_id, qty/quantity, session_mode
128
+ * Useful for ad-driven traffic to embedded checkout pages
129
+ * @default false
130
+ */
131
+ autoDetectQuickBuy?: boolean;
132
+ /**
133
+ * Called when checkout iframe is loaded and ready
134
+ */
135
+ onReady?: () => void;
136
+ /**
137
+ * Called when checkout drawer is opened
138
+ */
139
+ onOpen?: () => void;
140
+ /**
141
+ * Called when checkout is closed (all drawers closed)
142
+ */
143
+ onClose?: () => void;
144
+ /**
145
+ * Called when order is completed successfully
146
+ */
147
+ onComplete?: (order: OrderData) => void;
148
+ /**
149
+ * Called when cart state changes (items added/removed/updated)
150
+ * Use this to update cart badge count on parent site
151
+ */
152
+ onCartUpdate?: (cart: CartData) => void;
153
+ /**
154
+ * Called when auth state changes (login, logout, token refresh)
155
+ */
156
+ onAuthChange?: (auth: AuthChangeData) => void;
157
+ /**
158
+ * Called when checkout encounters a configuration error
159
+ * This happens when credentials are missing or invalid.
160
+ * The error drawer will still be shown, but you can use this
161
+ * callback to log the error or show custom UI.
162
+ */
163
+ onError?: (error: ErrorData) => void;
164
+ }
165
+ /**
166
+ * Cart state data emitted on cart:updated event
167
+ */
168
+ interface CartData {
169
+ /** Number of items in cart */
170
+ count: number;
171
+ /** Cart subtotal amount */
172
+ total: number;
173
+ /** Currency code (e.g., "INR", "USD") */
174
+ currency: string;
175
+ }
176
+ /**
177
+ * Order data emitted on checkout:complete event
178
+ */
179
+ interface OrderData {
180
+ /** Order ID */
181
+ id: string;
182
+ /** Human-readable order number */
183
+ orderNumber: string;
184
+ }
185
+ /**
186
+ * Auth change data emitted on auth events
187
+ */
188
+ interface AuthChangeData {
189
+ /** Type of auth change */
190
+ type: "login" | "logout" | "refresh";
191
+ /** New access token (for login/refresh) */
192
+ accessToken?: string;
193
+ /** New refresh token (for login/refresh) */
194
+ refreshToken?: string;
195
+ }
196
+ /**
197
+ * Error data emitted on checkout:error event
198
+ */
199
+ interface ErrorData {
200
+ /** Error message */
201
+ message: string;
202
+ }
203
+ /**
204
+ * Events emitted by checkout
205
+ */
206
+ type CheckoutEventType = "ready" | "open" | "close" | "complete" | "error" | "cart:updated" | "auth:change";
207
+ /**
208
+ * Event listener function type
209
+ */
210
+ type EventListener<T = unknown> = (data: T) => void;
211
+ //#endregion
212
+ //#region src/events.d.ts
213
+ declare class EventEmitter {
214
+ private listeners;
215
+ /**
216
+ * Subscribe to an event
217
+ */
218
+ on<T = unknown>(event: CheckoutEventType, listener: EventListener<T>): void;
219
+ /**
220
+ * Unsubscribe from an event
221
+ */
222
+ off<T = unknown>(event: CheckoutEventType, listener: EventListener<T>): void;
223
+ /**
224
+ * Subscribe to an event (once)
225
+ */
226
+ once<T = unknown>(event: CheckoutEventType, listener: EventListener<T>): void;
227
+ /**
228
+ * Emit an event to all subscribers
229
+ */
230
+ protected emit<T = unknown>(event: CheckoutEventType, data?: T): void;
231
+ /**
232
+ * Remove all listeners
233
+ */
234
+ protected removeAllListeners(): void;
235
+ }
236
+ //#endregion
237
+ //#region src/checkout.d.ts
238
+ declare class Checkout extends EventEmitter {
239
+ private config;
240
+ private iframe;
241
+ private isReady;
242
+ private isOpen;
243
+ private cartState;
244
+ private boundMessageHandler;
245
+ private hasQuickBuyParams;
246
+ constructor(config: CheckoutConfig);
247
+ private initialize;
248
+ /**
249
+ * Remove quick buy params from the parent URL to prevent duplicate adds on refresh
250
+ * Uses replaceState to avoid adding to browser history
251
+ */
252
+ private cleanQuickBuyParamsFromUrl;
253
+ private handleMessage;
254
+ private handleReady;
255
+ private handleError;
256
+ private handleOpen;
257
+ private handleClose;
258
+ private handleComplete;
259
+ private handleCartUpdate;
260
+ private handleAuthChange;
261
+ /**
262
+ * Open the cart drawer
263
+ */
264
+ openCart(): void;
265
+ /**
266
+ * Open the checkout drawer directly (e.g., for Buy Now flow)
267
+ */
268
+ openCheckout(): void;
269
+ /**
270
+ * Close the checkout overlay
271
+ */
272
+ close(): void;
273
+ /**
274
+ * Update authentication tokens
275
+ * Use this when user logs in/out on the parent site
276
+ */
277
+ updateTokens(accessToken: string, refreshToken?: string): void;
278
+ /**
279
+ * Add an item to cart and open the cart drawer
280
+ *
281
+ * @param productId - Product ID (required)
282
+ * @param variantId - Variant ID (required, null for non-variant products)
283
+ * @param quantity - Quantity to add (default: 1)
284
+ */
285
+ addToCart(productId: string, variantId: string | null, quantity?: number): void;
286
+ /**
287
+ * Get current cart state
288
+ */
289
+ getCart(): CartData;
290
+ /**
291
+ * Check if checkout is ready
292
+ */
293
+ get ready(): boolean;
294
+ /**
295
+ * Check if checkout overlay is currently open
296
+ */
297
+ get open(): boolean;
298
+ /**
299
+ * Subscribe to an event
300
+ * @override EventEmitter.on with typed overloads
301
+ */
302
+ on(event: "ready", listener: EventListener<void>): void;
303
+ on(event: "open", listener: EventListener<void>): void;
304
+ on(event: "close", listener: EventListener<void>): void;
305
+ on(event: "complete", listener: EventListener<OrderData>): void;
306
+ on(event: "cart:updated", listener: EventListener<CartData>): void;
307
+ on(event: "auth:change", listener: EventListener<AuthChangeData>): void;
308
+ /**
309
+ * Destroy the checkout instance
310
+ * Removes iframe and cleans up event listeners
311
+ */
312
+ destroy(): void;
313
+ }
314
+ //#endregion
315
+ //#region src/index.d.ts
316
+ /**
317
+ * Global Commercengine object interface
318
+ */
319
+ interface CommercengineGlobal {
320
+ /**
321
+ * Initialize checkout with configuration
322
+ * @returns Promise that resolves to Checkout instance
323
+ */
324
+ init: (config: CheckoutConfig) => Promise<Checkout>;
325
+ /**
326
+ * Callback invoked when script has loaded
327
+ * Set this BEFORE including the script to be notified when ready
328
+ */
329
+ onLoad?: () => void;
330
+ /**
331
+ * Current checkout instance (if initialized)
332
+ */
333
+ instance?: Checkout;
334
+ }
335
+ /**
336
+ * Global Commercengine namespace
337
+ */
338
+ declare const Commercengine: CommercengineGlobal;
339
+ //#endregion
340
+ export { type AddToCartItem, type AuthChangeData, type AuthMode, type CartData, Checkout, type CheckoutConfig, type CheckoutEventType, Commercengine, Commercengine as default, type ErrorData, type OrderData, type QuickBuyConfig, type SessionMode };
341
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/events.ts","../src/checkout.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;AAkBA;AASA;AAsBA;AA2BA;AAYA;;;;;;;;AAuI6B,KA7MjB,QAAA,GA6MiB,SAAA,GAAA,UAAA;AAU7B;AAYA;AAUA;AAYiB,UAhPA,aAAA,CAgPS;EAYd;AAYZ;;;;AC3RA;;EAMoE,SAAA,EAAA,MAAA,GAAA,IAAA;EAAd;;;;EAoB3B,QAAA,CAAA,EAAA,MAAA;;;;;;UDeV,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MAAA;EAMC,QAAA,MAAA;EAKA,QAAA,OAAA;EAQJ,QAAA,MAAA;EAAS,QAAA,SAAA;EAUZ,QAAA,mBAAQ;EAYR,QAAA,iBAAS;EAUT,WAAA,CAAA,MAAc,EEzLT,cFyLS;EAYd,QAAA,UAAS;EAYd;AAYZ;;;;EC3Ra,QAAA,aAAY;EAMA,QAAA,WAAA;EAA2C,QAAA,WAAA;EAAd,QAAA,UAAA;EAU5B,QAAA,WAAA;EAA2C,QAAA,cAAA;EAAd,QAAA,gBAAA;EAU5B,QAAA,gBAAA;EAA2C;;;EAWP,QAAA,CAAA,CAAA,EAAA,IAAA;EAAC;;;;ECgBnD;;;EAuWkB,KAAA,CAAA,CAAA,EAAA,IAAA;EACD;;;;EAGsB,YAAA,CAAA,WAAA,EAAA,MAAA,EAAA,YAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAd;;;;;;;;EC1W5B;;;EAK0B,OAAA,CAAA,CAAA,ED2UvB,QC3UuB;EAWvB;;AAAQ;;;;;;;;;;+BDsVU;8BACD;+BACC;kCACG,cAAc;sCACV,cAAc;qCACf,cAAc;;;;;;;;;AA5WnD;;;UCCU,mBAAA,CDsWqB;EACD;;;;EAGsB,IAAA,EAAA,CAAA,MAAA,ECrWnC,cDqWmC,EAAA,GCrWhB,ODqWgB,CCrWR,QDqWQ,CAAA;EAAd;;;;EA3WI,MAAA,CAAA,EAAA,GAAA,GAAA,IAAA;;;;ECChC,QAAA,CAAA,EAgBG,QAhBH;;;;;cAsBJ,aANe,EAMA,mBANA"}
@@ -0,0 +1,341 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Commerce Engine Checkout - Type Definitions
4
+ *
5
+ * @commercengine/js
6
+ *
7
+ * This is the single source of truth for checkout configuration.
8
+ * The checkout app parses these from URL parameters.
9
+ */
10
+ /**
11
+ * Authentication mode
12
+ * - 'managed': Checkout manages token lifecycle (refresh, storage)
13
+ * - 'provided': Parent manages tokens. Checkout uses in-memory only, syncs via events
14
+ */
15
+ type AuthMode = "managed" | "provided";
16
+ /**
17
+ * Item to add to cart
18
+ */
19
+ interface AddToCartItem {
20
+ /**
21
+ * Product ID (required)
22
+ */
23
+ productId: string;
24
+ /**
25
+ * Variant ID (required, null for non-variant products)
26
+ */
27
+ variantId: string | null;
28
+ /**
29
+ * Quantity to add
30
+ * @default 1
31
+ */
32
+ quantity?: number;
33
+ }
34
+ /**
35
+ * Quick buy configuration for initialization
36
+ * Adds a product to cart when checkout initializes
37
+ */
38
+ interface QuickBuyConfig {
39
+ /**
40
+ * Product ID (required)
41
+ */
42
+ productId: string;
43
+ /**
44
+ * Variant ID (required, null for non-variant products)
45
+ */
46
+ variantId: string | null;
47
+ /**
48
+ * Quantity to add
49
+ * @default 1
50
+ */
51
+ quantity?: number;
52
+ }
53
+ /**
54
+ * Session behavior mode
55
+ * - 'continue-existing': Add quick-buy item to existing cart (default)
56
+ * - 'force-new': Clear cart and start fresh
57
+ */
58
+ type SessionMode = "continue-existing" | "force-new";
59
+ /**
60
+ * Configuration for initializing checkout
61
+ *
62
+ * Either provide `url` directly (for local development) or
63
+ * provide `storeId` + `apiKey` (for production).
64
+ */
65
+ interface CheckoutConfig {
66
+ /**
67
+ * Direct checkout URL (for local development)
68
+ * If provided, storeId and apiKey are optional.
69
+ * @example "http://localhost:8080"
70
+ */
71
+ url?: string;
72
+ /**
73
+ * Your Commerce Engine Store ID
74
+ * Required if `url` is not provided.
75
+ * @example "store_abc123"
76
+ */
77
+ storeId?: string;
78
+ /**
79
+ * Your Commerce Engine API Key
80
+ * Required if `url` is not provided.
81
+ * @example "ak_test_xyz789"
82
+ */
83
+ apiKey?: string;
84
+ /**
85
+ * Theme preference
86
+ * @default "system"
87
+ */
88
+ theme?: "light" | "dark" | "system";
89
+ /**
90
+ * Appearance customization
91
+ */
92
+ appearance?: {
93
+ /**
94
+ * Z-index for the checkout overlay
95
+ * @default 99999
96
+ */
97
+ zIndex?: number;
98
+ };
99
+ /**
100
+ * Authentication mode
101
+ * - 'managed': Checkout manages token lifecycle (default)
102
+ * - 'provided': Parent manages tokens, checkout uses in-memory only
103
+ * @default "managed"
104
+ */
105
+ authMode?: AuthMode;
106
+ /**
107
+ * Initial access token (if user already logged in on parent site)
108
+ */
109
+ accessToken?: string;
110
+ /**
111
+ * Initial refresh token
112
+ */
113
+ refreshToken?: string;
114
+ /**
115
+ * Quick buy configuration for "Buy Now" flows
116
+ * When provided, adds the product to cart on initialization
117
+ */
118
+ quickBuy?: QuickBuyConfig;
119
+ /**
120
+ * Session behavior when quick buy is used
121
+ * @default "continue-existing"
122
+ */
123
+ sessionMode?: SessionMode;
124
+ /**
125
+ * Auto-detect quick buy params from parent page URL
126
+ * When enabled, SDK parses window.location.search for:
127
+ * - product_id, variant_id, qty/quantity, session_mode
128
+ * Useful for ad-driven traffic to embedded checkout pages
129
+ * @default false
130
+ */
131
+ autoDetectQuickBuy?: boolean;
132
+ /**
133
+ * Called when checkout iframe is loaded and ready
134
+ */
135
+ onReady?: () => void;
136
+ /**
137
+ * Called when checkout drawer is opened
138
+ */
139
+ onOpen?: () => void;
140
+ /**
141
+ * Called when checkout is closed (all drawers closed)
142
+ */
143
+ onClose?: () => void;
144
+ /**
145
+ * Called when order is completed successfully
146
+ */
147
+ onComplete?: (order: OrderData) => void;
148
+ /**
149
+ * Called when cart state changes (items added/removed/updated)
150
+ * Use this to update cart badge count on parent site
151
+ */
152
+ onCartUpdate?: (cart: CartData) => void;
153
+ /**
154
+ * Called when auth state changes (login, logout, token refresh)
155
+ */
156
+ onAuthChange?: (auth: AuthChangeData) => void;
157
+ /**
158
+ * Called when checkout encounters a configuration error
159
+ * This happens when credentials are missing or invalid.
160
+ * The error drawer will still be shown, but you can use this
161
+ * callback to log the error or show custom UI.
162
+ */
163
+ onError?: (error: ErrorData) => void;
164
+ }
165
+ /**
166
+ * Cart state data emitted on cart:updated event
167
+ */
168
+ interface CartData {
169
+ /** Number of items in cart */
170
+ count: number;
171
+ /** Cart subtotal amount */
172
+ total: number;
173
+ /** Currency code (e.g., "INR", "USD") */
174
+ currency: string;
175
+ }
176
+ /**
177
+ * Order data emitted on checkout:complete event
178
+ */
179
+ interface OrderData {
180
+ /** Order ID */
181
+ id: string;
182
+ /** Human-readable order number */
183
+ orderNumber: string;
184
+ }
185
+ /**
186
+ * Auth change data emitted on auth events
187
+ */
188
+ interface AuthChangeData {
189
+ /** Type of auth change */
190
+ type: "login" | "logout" | "refresh";
191
+ /** New access token (for login/refresh) */
192
+ accessToken?: string;
193
+ /** New refresh token (for login/refresh) */
194
+ refreshToken?: string;
195
+ }
196
+ /**
197
+ * Error data emitted on checkout:error event
198
+ */
199
+ interface ErrorData {
200
+ /** Error message */
201
+ message: string;
202
+ }
203
+ /**
204
+ * Events emitted by checkout
205
+ */
206
+ type CheckoutEventType = "ready" | "open" | "close" | "complete" | "error" | "cart:updated" | "auth:change";
207
+ /**
208
+ * Event listener function type
209
+ */
210
+ type EventListener<T = unknown> = (data: T) => void;
211
+ //#endregion
212
+ //#region src/events.d.ts
213
+ declare class EventEmitter {
214
+ private listeners;
215
+ /**
216
+ * Subscribe to an event
217
+ */
218
+ on<T = unknown>(event: CheckoutEventType, listener: EventListener<T>): void;
219
+ /**
220
+ * Unsubscribe from an event
221
+ */
222
+ off<T = unknown>(event: CheckoutEventType, listener: EventListener<T>): void;
223
+ /**
224
+ * Subscribe to an event (once)
225
+ */
226
+ once<T = unknown>(event: CheckoutEventType, listener: EventListener<T>): void;
227
+ /**
228
+ * Emit an event to all subscribers
229
+ */
230
+ protected emit<T = unknown>(event: CheckoutEventType, data?: T): void;
231
+ /**
232
+ * Remove all listeners
233
+ */
234
+ protected removeAllListeners(): void;
235
+ }
236
+ //#endregion
237
+ //#region src/checkout.d.ts
238
+ declare class Checkout extends EventEmitter {
239
+ private config;
240
+ private iframe;
241
+ private isReady;
242
+ private isOpen;
243
+ private cartState;
244
+ private boundMessageHandler;
245
+ private hasQuickBuyParams;
246
+ constructor(config: CheckoutConfig);
247
+ private initialize;
248
+ /**
249
+ * Remove quick buy params from the parent URL to prevent duplicate adds on refresh
250
+ * Uses replaceState to avoid adding to browser history
251
+ */
252
+ private cleanQuickBuyParamsFromUrl;
253
+ private handleMessage;
254
+ private handleReady;
255
+ private handleError;
256
+ private handleOpen;
257
+ private handleClose;
258
+ private handleComplete;
259
+ private handleCartUpdate;
260
+ private handleAuthChange;
261
+ /**
262
+ * Open the cart drawer
263
+ */
264
+ openCart(): void;
265
+ /**
266
+ * Open the checkout drawer directly (e.g., for Buy Now flow)
267
+ */
268
+ openCheckout(): void;
269
+ /**
270
+ * Close the checkout overlay
271
+ */
272
+ close(): void;
273
+ /**
274
+ * Update authentication tokens
275
+ * Use this when user logs in/out on the parent site
276
+ */
277
+ updateTokens(accessToken: string, refreshToken?: string): void;
278
+ /**
279
+ * Add an item to cart and open the cart drawer
280
+ *
281
+ * @param productId - Product ID (required)
282
+ * @param variantId - Variant ID (required, null for non-variant products)
283
+ * @param quantity - Quantity to add (default: 1)
284
+ */
285
+ addToCart(productId: string, variantId: string | null, quantity?: number): void;
286
+ /**
287
+ * Get current cart state
288
+ */
289
+ getCart(): CartData;
290
+ /**
291
+ * Check if checkout is ready
292
+ */
293
+ get ready(): boolean;
294
+ /**
295
+ * Check if checkout overlay is currently open
296
+ */
297
+ get open(): boolean;
298
+ /**
299
+ * Subscribe to an event
300
+ * @override EventEmitter.on with typed overloads
301
+ */
302
+ on(event: "ready", listener: EventListener<void>): void;
303
+ on(event: "open", listener: EventListener<void>): void;
304
+ on(event: "close", listener: EventListener<void>): void;
305
+ on(event: "complete", listener: EventListener<OrderData>): void;
306
+ on(event: "cart:updated", listener: EventListener<CartData>): void;
307
+ on(event: "auth:change", listener: EventListener<AuthChangeData>): void;
308
+ /**
309
+ * Destroy the checkout instance
310
+ * Removes iframe and cleans up event listeners
311
+ */
312
+ destroy(): void;
313
+ }
314
+ //#endregion
315
+ //#region src/index.d.ts
316
+ /**
317
+ * Global Commercengine object interface
318
+ */
319
+ interface CommercengineGlobal {
320
+ /**
321
+ * Initialize checkout with configuration
322
+ * @returns Promise that resolves to Checkout instance
323
+ */
324
+ init: (config: CheckoutConfig) => Promise<Checkout>;
325
+ /**
326
+ * Callback invoked when script has loaded
327
+ * Set this BEFORE including the script to be notified when ready
328
+ */
329
+ onLoad?: () => void;
330
+ /**
331
+ * Current checkout instance (if initialized)
332
+ */
333
+ instance?: Checkout;
334
+ }
335
+ /**
336
+ * Global Commercengine namespace
337
+ */
338
+ declare const Commercengine: CommercengineGlobal;
339
+ //#endregion
340
+ export { type AddToCartItem, type AuthChangeData, type AuthMode, type CartData, Checkout, type CheckoutConfig, type CheckoutEventType, Commercengine, Commercengine as default, type ErrorData, type OrderData, type QuickBuyConfig, type SessionMode };
341
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/events.ts","../src/checkout.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;AAkBA;AASA;AAsBA;AA2BA;AAYA;;;;;;;;AAuI6B,KA7MjB,QAAA,GA6MiB,SAAA,GAAA,UAAA;AAU7B;AAYA;AAUA;AAYiB,UAhPA,aAAA,CAgPS;EAYd;AAYZ;;;;AC3RA;;EAMoE,SAAA,EAAA,MAAA,GAAA,IAAA;EAAd;;;;EAoB3B,QAAA,CAAA,EAAA,MAAA;;;;;;UDeV,cAAA;;;AEYjB;EASsB,SAAA,EAAA,MAAA;EAwUT;;;EAwBkB,SAAA,EAAA,MAAA,GAAA,IAAA;EACiB;;;;EAEG,QAAA,CAAA,EAAA,MAAA;;;;;;;AC3WzC,KHcE,WAAA,GGdiB,mBAAA,GAAA,WAAA;;;;;;AAgBR;UHUJ,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAyDJ;;;;;;;;;;;;;aAoBA;;;;;gBAMG;;;;;;;;;;;;;;;;;;;;;;;;uBAiCO;;;;;wBAMC;;;;wBAKA;;;;;;;oBAQJ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