@salla.sa/embedded-sdk 0.1.0-beta.1 → 0.1.0-beta.10
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 +47 -239
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +633 -464
- package/dist/esm/index.js.map +1 -1
- package/dist/system/index.js +3 -3
- package/dist/system/index.js.map +1 -1
- package/dist/types/index.d.ts +558 -117
- package/dist/umd/index.js +3 -3
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -1,42 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback for action button clicks.
|
|
3
|
+
*/
|
|
4
|
+
declare type ActionClickCallback = (url?: string, value?: string) => void;
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Auth module interface.
|
|
3
8
|
*/
|
|
4
9
|
export declare interface AuthModule {
|
|
5
10
|
/**
|
|
6
|
-
* Get the
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
getAccessToken(): string | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Check if the SDK is authenticated.
|
|
11
|
+
* Get the token from the URL query parameter.
|
|
12
|
+
* The token is passed to the iframe via ?token=XXX
|
|
13
|
+
* @returns The token string or null if not present
|
|
12
14
|
*/
|
|
13
|
-
|
|
15
|
+
getToken(): string | null;
|
|
14
16
|
/**
|
|
15
|
-
* Get the
|
|
17
|
+
* Get the app ID from the URL query parameter.
|
|
18
|
+
* The app ID is passed to the iframe via ?app_id=XXX
|
|
19
|
+
* @returns The app ID string or null if not present
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
getAppId(): string | null;
|
|
18
22
|
/**
|
|
19
|
-
*
|
|
23
|
+
* Request a token refresh from the host.
|
|
24
|
+
* This will re-render the iframe with a new token URL.
|
|
20
25
|
*/
|
|
21
|
-
|
|
26
|
+
refresh(): void;
|
|
22
27
|
/**
|
|
23
|
-
*
|
|
28
|
+
* Introspect (verify) a short-lived token with Salla's API.
|
|
29
|
+
* This method verifies the token and returns token information.
|
|
30
|
+
*
|
|
31
|
+
* @param options - Optional params (appId, token, refreshOnError); auto extracted from URL if not provided.
|
|
32
|
+
* @returns Promise with introspect result.
|
|
33
|
+
* @throws {Error} If required params missing.
|
|
24
34
|
*/
|
|
25
|
-
|
|
35
|
+
introspect(options?: IntrospectOptions): Promise<IntrospectResponse>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checkout module interface.
|
|
40
|
+
*/
|
|
41
|
+
export declare interface CheckoutModule {
|
|
26
42
|
/**
|
|
27
|
-
*
|
|
43
|
+
* Create/initiate a checkout flow.
|
|
44
|
+
*
|
|
45
|
+
* @param payload - Checkout data
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* embedded.checkout.create({
|
|
50
|
+
* items: [{ productId: 123, quantity: 1 }],
|
|
51
|
+
* amount: 99.99,
|
|
52
|
+
* currency: 'SAR'
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
28
55
|
*/
|
|
29
|
-
|
|
56
|
+
create(payload: CheckoutPayload): void;
|
|
30
57
|
}
|
|
31
58
|
|
|
32
59
|
/**
|
|
33
|
-
*
|
|
60
|
+
* @fileoverview Type definitions for the checkout module.
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Checkout payload structure.
|
|
34
64
|
*/
|
|
35
|
-
export declare interface
|
|
36
|
-
|
|
37
|
-
|
|
65
|
+
export declare interface CheckoutPayload {
|
|
66
|
+
/** Cart items or product IDs */
|
|
67
|
+
items?: unknown[];
|
|
68
|
+
/** Total amount */
|
|
69
|
+
amount?: number;
|
|
70
|
+
/** Currency code */
|
|
71
|
+
currency?: string;
|
|
72
|
+
/** Additional checkout data */
|
|
73
|
+
[key: string]: unknown;
|
|
38
74
|
}
|
|
39
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Confirm dialog options.
|
|
78
|
+
*/
|
|
79
|
+
export declare interface ConfirmOptions {
|
|
80
|
+
/** Dialog title */
|
|
81
|
+
title: string;
|
|
82
|
+
/** Dialog message/body */
|
|
83
|
+
message: string;
|
|
84
|
+
/** Text for the confirm button (default: "Confirm") */
|
|
85
|
+
confirmText?: string;
|
|
86
|
+
/** Text for the cancel button (default: "Cancel") */
|
|
87
|
+
cancelText?: string;
|
|
88
|
+
/** Visual variant for the dialog (default: "info") */
|
|
89
|
+
variant?: ConfirmVariant;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Confirm dialog result.
|
|
94
|
+
*/
|
|
95
|
+
export declare interface ConfirmResult {
|
|
96
|
+
/** Whether the user confirmed (true) or cancelled (false) */
|
|
97
|
+
confirmed: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Confirm dialog variant.
|
|
102
|
+
*/
|
|
103
|
+
export declare type ConfirmVariant = "danger" | "warning" | "info";
|
|
104
|
+
|
|
40
105
|
export declare const embedded: EmbeddedApp;
|
|
41
106
|
|
|
42
107
|
/**
|
|
@@ -46,15 +111,22 @@ export declare const embedded: EmbeddedApp;
|
|
|
46
111
|
export declare class EmbeddedApp {
|
|
47
112
|
private config;
|
|
48
113
|
private state;
|
|
114
|
+
private themeCallbacks;
|
|
115
|
+
private initCallbacks;
|
|
116
|
+
private appReady;
|
|
49
117
|
/** Auth module for token management */
|
|
50
118
|
auth: AuthModule;
|
|
51
|
-
/** Page module for
|
|
119
|
+
/** Page module for navigation and resize */
|
|
52
120
|
page: PageModule;
|
|
53
121
|
/** Nav module for primary actions */
|
|
54
122
|
nav: NavModule;
|
|
123
|
+
/** UI module for loading, overlay, toast, modal */
|
|
124
|
+
ui: UIModule;
|
|
125
|
+
/** Checkout module for checkout flow */
|
|
126
|
+
checkout: CheckoutModule;
|
|
55
127
|
constructor();
|
|
56
128
|
/**
|
|
57
|
-
* Get current SDK state.
|
|
129
|
+
* Get current SDK state (layout info only, no token).
|
|
58
130
|
*/
|
|
59
131
|
getState(): Readonly<EmbeddedState>;
|
|
60
132
|
/**
|
|
@@ -62,40 +134,106 @@ export declare class EmbeddedApp {
|
|
|
62
134
|
*/
|
|
63
135
|
getConfig(): Readonly<EmbeddedConfig>;
|
|
64
136
|
/**
|
|
65
|
-
* Check if SDK is
|
|
137
|
+
* Check if SDK is initialized.
|
|
66
138
|
*/
|
|
67
139
|
isReady(): boolean;
|
|
68
140
|
/**
|
|
69
|
-
*
|
|
141
|
+
* Unified internal logging function that supports all console log types.
|
|
142
|
+
*
|
|
143
|
+
* @param type - Log type (log, warn, error, info, debug)
|
|
144
|
+
* @param args - Arguments to log
|
|
70
145
|
*/
|
|
71
|
-
private
|
|
146
|
+
private internalLog;
|
|
72
147
|
/**
|
|
73
|
-
*
|
|
148
|
+
* Set up listener for theme changes from host.
|
|
74
149
|
*/
|
|
75
|
-
private
|
|
150
|
+
private setupThemeListener;
|
|
76
151
|
/**
|
|
77
|
-
*
|
|
152
|
+
* Set up listeners for async response events from host.
|
|
153
|
+
*/
|
|
154
|
+
private setupResponseListeners;
|
|
155
|
+
/**
|
|
156
|
+
* Subscribe to theme changes.
|
|
78
157
|
*
|
|
79
|
-
* @param
|
|
80
|
-
* @returns
|
|
158
|
+
* @param callback - Function called when theme changes
|
|
159
|
+
* @returns Unsubscribe function
|
|
81
160
|
*
|
|
82
161
|
* @example
|
|
83
162
|
* ```typescript
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* env: 'prod',
|
|
87
|
-
* debug: true
|
|
163
|
+
* const unsubscribe = embedded.onThemeChange((theme) => {
|
|
164
|
+
* document.body.classList.toggle('dark-mode', theme === 'dark');
|
|
88
165
|
* });
|
|
89
166
|
* ```
|
|
90
167
|
*/
|
|
91
|
-
|
|
168
|
+
onThemeChange(callback: ThemeChangeCallback): () => void;
|
|
169
|
+
/**
|
|
170
|
+
* Subscribe to init completion. If called after init, fires immediately.
|
|
171
|
+
*
|
|
172
|
+
* @param callback - Function called when init completes
|
|
173
|
+
* @returns Unsubscribe function
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* embedded.onInit((state) => {
|
|
178
|
+
* console.log('SDK initialized with layout:', state.layout);
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
onInit(callback: InitCallback): () => void;
|
|
183
|
+
/**
|
|
184
|
+
* Send log message to host for debugging/monitoring.
|
|
185
|
+
*
|
|
186
|
+
* @param level - Log level (info, warn, error)
|
|
187
|
+
* @param message - Log message
|
|
188
|
+
* @param context - Additional context
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* embedded.log('error', 'Failed to load data', { endpoint: '/api/data' });
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
log(level: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
196
|
+
/**
|
|
197
|
+
* Signal that the app is fully loaded and ready.
|
|
198
|
+
* This removes the host's loading overlay.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* // After verifying token and loading initial data
|
|
203
|
+
* embedded.ready();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
ready(): void;
|
|
207
|
+
/**
|
|
208
|
+
* Initialize the SDK and establish connection with the host.
|
|
209
|
+
*
|
|
210
|
+
* @param options - Initialization options (optional)
|
|
211
|
+
* @returns Promise that resolves with layout info
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const { layout } = await embedded.init({ debug: true });
|
|
216
|
+
* console.log('Theme:', layout.theme);
|
|
217
|
+
* console.log('Locale:', layout.locale);
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
init(options?: InitOptions): Promise<{
|
|
221
|
+
layout: LayoutInfo;
|
|
222
|
+
}>;
|
|
92
223
|
/**
|
|
93
|
-
* Wait for
|
|
224
|
+
* Wait for initialization to complete.
|
|
94
225
|
* Useful when multiple calls to init() might happen.
|
|
95
226
|
*/
|
|
96
|
-
private
|
|
227
|
+
private waitForInit;
|
|
97
228
|
/**
|
|
98
229
|
* Destroy the SDK instance and clean up resources.
|
|
230
|
+
* Sends a destroy event to the host to navigate away from the embedded view.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* // On auth failure or when app needs to exit
|
|
235
|
+
* embedded.destroy();
|
|
236
|
+
* ```
|
|
99
237
|
*/
|
|
100
238
|
destroy(): void;
|
|
101
239
|
}
|
|
@@ -104,8 +242,6 @@ export declare class EmbeddedApp {
|
|
|
104
242
|
* Internal configuration after initialization.
|
|
105
243
|
*/
|
|
106
244
|
declare interface EmbeddedConfig {
|
|
107
|
-
appId: string;
|
|
108
|
-
env: Environment;
|
|
109
245
|
debug: boolean;
|
|
110
246
|
initialized: boolean;
|
|
111
247
|
}
|
|
@@ -114,42 +250,24 @@ declare interface EmbeddedConfig {
|
|
|
114
250
|
* Current state of the embedded SDK.
|
|
115
251
|
*/
|
|
116
252
|
export declare interface EmbeddedState {
|
|
117
|
-
/** Whether the SDK is ready
|
|
253
|
+
/** Whether the SDK is ready */
|
|
118
254
|
ready: boolean;
|
|
119
255
|
/** Whether initialization is in progress */
|
|
120
256
|
initializing: boolean;
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
/** Store ID from merchant context */
|
|
124
|
-
storeId?: number;
|
|
125
|
-
/** User ID from merchant context */
|
|
126
|
-
userId?: number;
|
|
127
|
-
/** Merchant plan */
|
|
128
|
-
merchantPlan?: string;
|
|
129
|
-
/** Current dark mode state */
|
|
130
|
-
isDarkMode?: boolean;
|
|
131
|
-
/** Parent window width */
|
|
132
|
-
parentWidth?: number;
|
|
133
|
-
/** Base URL of the host */
|
|
134
|
-
baseUrl?: string;
|
|
135
|
-
/** Base API URL */
|
|
136
|
-
baseApiUrl?: string;
|
|
257
|
+
/** Layout information from the host */
|
|
258
|
+
layout: LayoutInfo;
|
|
137
259
|
}
|
|
138
260
|
|
|
139
|
-
/**
|
|
140
|
-
* @fileoverview Core type definitions for the Embedded SDK.
|
|
141
|
-
*/
|
|
142
|
-
/**
|
|
143
|
-
* Environment mode for the SDK.
|
|
144
|
-
*/
|
|
145
|
-
export declare type Environment = "prod" | "dev";
|
|
146
|
-
|
|
147
261
|
/**
|
|
148
262
|
* Extended action for navigation.
|
|
149
263
|
*/
|
|
150
264
|
export declare interface ExtendedAction {
|
|
151
265
|
title: string;
|
|
266
|
+
subTitle?: string;
|
|
152
267
|
url?: string;
|
|
268
|
+
value?: string;
|
|
269
|
+
icon?: string;
|
|
270
|
+
disabled?: boolean;
|
|
153
271
|
}
|
|
154
272
|
|
|
155
273
|
/**
|
|
@@ -157,107 +275,277 @@ export declare interface ExtendedAction {
|
|
|
157
275
|
*/
|
|
158
276
|
export declare function getEmbeddedApp(): EmbeddedApp;
|
|
159
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Init callback type for onInit subscribers.
|
|
280
|
+
*/
|
|
281
|
+
declare type InitCallback = (state: EmbeddedState) => void;
|
|
282
|
+
|
|
160
283
|
/**
|
|
161
284
|
* Options for initializing the embedded SDK.
|
|
162
285
|
*/
|
|
163
286
|
export declare interface InitOptions {
|
|
164
|
-
/** The unique identifier for the app */
|
|
165
|
-
app_id: string;
|
|
166
|
-
/** Environment mode (defaults to 'prod') */
|
|
167
|
-
env?: Environment;
|
|
168
287
|
/** Enable debug logging */
|
|
169
288
|
debug?: boolean;
|
|
170
289
|
}
|
|
171
290
|
|
|
172
291
|
/**
|
|
173
|
-
*
|
|
292
|
+
* Options for the introspect method.
|
|
293
|
+
*/
|
|
294
|
+
declare interface IntrospectOptions {
|
|
295
|
+
/** Application ID (audience). If not provided, will be extracted from URL params. */
|
|
296
|
+
appId?: string;
|
|
297
|
+
/** Short-lived token. If not provided, will be extracted from URL params. */
|
|
298
|
+
token?: string;
|
|
299
|
+
/** Automatically refresh token on error (default: true) */
|
|
300
|
+
refreshOnError?: boolean;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Response from the introspect API.
|
|
305
|
+
*/
|
|
306
|
+
declare interface IntrospectResponse {
|
|
307
|
+
/** Whether the token was verified successfully */
|
|
308
|
+
isVerified: boolean;
|
|
309
|
+
/** Whether an error occurred */
|
|
310
|
+
isError: boolean;
|
|
311
|
+
/** Error content if an error occurred */
|
|
312
|
+
error?: unknown;
|
|
313
|
+
/** Response data (null on error) */
|
|
314
|
+
data: IntrospectResponseData | null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Response data from the introspect API.
|
|
319
|
+
*/
|
|
320
|
+
declare interface IntrospectResponseData {
|
|
321
|
+
/** Token ID */
|
|
322
|
+
id: number;
|
|
323
|
+
/** User ID */
|
|
324
|
+
user_id: number;
|
|
325
|
+
/** Expiration time in ISO 8601 format */
|
|
326
|
+
exp: string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Layout information from the host.
|
|
331
|
+
*/
|
|
332
|
+
declare interface LayoutInfo {
|
|
333
|
+
/** Current theme */
|
|
334
|
+
theme: Theme;
|
|
335
|
+
/** Parent window width */
|
|
336
|
+
width: number;
|
|
337
|
+
/** Current locale */
|
|
338
|
+
locale: string;
|
|
339
|
+
/** Current currency */
|
|
340
|
+
currency: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Loading mode.
|
|
174
345
|
*/
|
|
175
346
|
export declare type LoadingMode = "full" | "component";
|
|
176
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Loading sub-module interface.
|
|
350
|
+
*/
|
|
351
|
+
declare interface LoadingSubModule {
|
|
352
|
+
/**
|
|
353
|
+
* Show loading indicator.
|
|
354
|
+
* @param mode - Loading display mode
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* embedded.ui.loading.show();
|
|
359
|
+
* await fetchData();
|
|
360
|
+
* embedded.ui.loading.hide();
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
show(mode?: LoadingMode): void;
|
|
364
|
+
/**
|
|
365
|
+
* Hide loading indicator.
|
|
366
|
+
*/
|
|
367
|
+
hide(): void;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Log level type.
|
|
372
|
+
*/
|
|
373
|
+
declare type LogLevel = "info" | "warn" | "error";
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Modal action types.
|
|
377
|
+
*/
|
|
378
|
+
export declare type ModalAction = "open" | "close";
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Modal action type.
|
|
382
|
+
*/
|
|
383
|
+
declare type ModalAction_2 = "open" | "close";
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Modal control options.
|
|
387
|
+
*/
|
|
388
|
+
export declare interface ModalOptions {
|
|
389
|
+
/** Modal action */
|
|
390
|
+
action: ModalAction_2;
|
|
391
|
+
/** Modal identifier */
|
|
392
|
+
id?: string;
|
|
393
|
+
/** Modal content/data */
|
|
394
|
+
content?: unknown;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Modal sub-module interface.
|
|
399
|
+
*/
|
|
400
|
+
declare interface ModalSubModule {
|
|
401
|
+
/**
|
|
402
|
+
* Open a modal.
|
|
403
|
+
* @param id - Modal identifier
|
|
404
|
+
* @param content - Modal content/data
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* embedded.ui.modal.open('confirm-delete', { itemId: 123 });
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
open(id?: string, content?: unknown): void;
|
|
412
|
+
/**
|
|
413
|
+
* Close a modal.
|
|
414
|
+
* @param id - Modal identifier
|
|
415
|
+
*/
|
|
416
|
+
close(id?: string): void;
|
|
417
|
+
}
|
|
418
|
+
|
|
177
419
|
/**
|
|
178
420
|
* Nav module interface.
|
|
179
421
|
*/
|
|
180
422
|
export declare interface NavModule {
|
|
181
423
|
/**
|
|
182
|
-
* Set the primary action button in the
|
|
424
|
+
* Set the primary action button in the navbar.
|
|
183
425
|
*
|
|
184
|
-
* @param config -
|
|
426
|
+
* @param config - Action button configuration
|
|
185
427
|
*
|
|
186
428
|
* @example
|
|
187
429
|
* ```typescript
|
|
188
|
-
*
|
|
430
|
+
* embedded.nav.setAction({
|
|
189
431
|
* title: 'Create Product',
|
|
190
|
-
*
|
|
432
|
+
* onClick: () => {
|
|
433
|
+
* // Handle click
|
|
434
|
+
* }
|
|
435
|
+
* });
|
|
436
|
+
*
|
|
437
|
+
* // With optional props
|
|
438
|
+
* embedded.nav.setAction({
|
|
439
|
+
* title: 'Save',
|
|
440
|
+
* subTitle: 'Save changes',
|
|
441
|
+
* icon: 'sicon-save',
|
|
442
|
+
* disabled: false,
|
|
443
|
+
* onClick: () => {
|
|
444
|
+
* handleSave();
|
|
445
|
+
* }
|
|
446
|
+
* });
|
|
447
|
+
*
|
|
448
|
+
* // With extended actions dropdown
|
|
449
|
+
* embedded.nav.setAction({
|
|
450
|
+
* title: 'Actions',
|
|
451
|
+
* value: 'main-action',
|
|
191
452
|
* extendedActions: [
|
|
192
|
-
* { title: 'Import
|
|
193
|
-
* { title: '
|
|
453
|
+
* { title: 'Import', url: '/import' },
|
|
454
|
+
* { title: 'Export', value: 'export' }
|
|
194
455
|
* ]
|
|
195
456
|
* });
|
|
196
457
|
* ```
|
|
197
458
|
*/
|
|
198
|
-
|
|
459
|
+
setAction(config: PrimaryActionConfig): void;
|
|
199
460
|
/**
|
|
200
461
|
* Clear the primary action button.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```typescript
|
|
465
|
+
* embedded.nav.clearAction();
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
clearAction(): void;
|
|
469
|
+
/**
|
|
470
|
+
* Subscribe to action button click events.
|
|
471
|
+
*
|
|
472
|
+
* @param callback - Function called when action is clicked
|
|
473
|
+
* @returns Unsubscribe function
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* const unsubscribe = embedded.nav.onActionClick((url, value) => {
|
|
478
|
+
* if (value === 'export') {
|
|
479
|
+
* handleExport();
|
|
480
|
+
* }
|
|
481
|
+
* });
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
onActionClick(callback: ActionClickCallback): Unsubscribe;
|
|
485
|
+
/**
|
|
486
|
+
* @deprecated Use setAction instead
|
|
487
|
+
*/
|
|
488
|
+
primaryAction(config: PrimaryActionConfig): void;
|
|
489
|
+
/**
|
|
490
|
+
* @deprecated Use clearAction instead
|
|
201
491
|
*/
|
|
202
492
|
clearPrimaryAction(): void;
|
|
203
493
|
}
|
|
204
494
|
|
|
205
495
|
/**
|
|
206
|
-
*
|
|
496
|
+
* @fileoverview Type definitions for the page module.
|
|
207
497
|
*/
|
|
208
|
-
export declare interface NavToOptions {
|
|
209
|
-
/** Navigation mode */
|
|
210
|
-
mode?: "iframe" | "redirect";
|
|
211
|
-
}
|
|
212
|
-
|
|
213
498
|
/**
|
|
214
|
-
*
|
|
499
|
+
* Options for navigation.
|
|
215
500
|
*/
|
|
216
|
-
export declare
|
|
501
|
+
export declare interface NavToOptions {
|
|
502
|
+
/** State to pass to the route */
|
|
503
|
+
state?: Record<string, unknown>;
|
|
504
|
+
/** Replace history entry instead of push */
|
|
505
|
+
replace?: boolean;
|
|
506
|
+
}
|
|
217
507
|
|
|
218
508
|
/**
|
|
219
509
|
* Page module interface.
|
|
220
510
|
*/
|
|
221
511
|
export declare interface PageModule {
|
|
222
512
|
/**
|
|
223
|
-
*
|
|
513
|
+
* Navigate to a path using React Router (SPA navigation).
|
|
514
|
+
* Use this for internal dashboard paths.
|
|
224
515
|
*
|
|
225
|
-
* @param
|
|
226
|
-
* @param
|
|
516
|
+
* @param path - The path to navigate to
|
|
517
|
+
* @param options - Navigation options
|
|
227
518
|
*
|
|
228
519
|
* @example
|
|
229
520
|
* ```typescript
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* // Hide loading (content ready)
|
|
234
|
-
* salla.embedded.page.loading(true);
|
|
521
|
+
* embedded.page.navigate('/products');
|
|
522
|
+
* embedded.page.navigate('/orders', { replace: true });
|
|
235
523
|
* ```
|
|
236
524
|
*/
|
|
237
|
-
|
|
525
|
+
navigate(path: string, options?: NavToOptions): void;
|
|
238
526
|
/**
|
|
239
|
-
*
|
|
527
|
+
* Redirect to a URL (full page reload).
|
|
528
|
+
* Use this for external URLs or when a full reload is needed.
|
|
240
529
|
*
|
|
241
|
-
* @param
|
|
530
|
+
* @param url - The URL to redirect to
|
|
242
531
|
*
|
|
243
532
|
* @example
|
|
244
533
|
* ```typescript
|
|
245
|
-
*
|
|
246
|
-
* // ... show modal content
|
|
247
|
-
* salla.embedded.page.overlay('close');
|
|
534
|
+
* embedded.page.redirect('https://external-site.com');
|
|
248
535
|
* ```
|
|
249
536
|
*/
|
|
250
|
-
|
|
537
|
+
redirect(url: string): void;
|
|
251
538
|
/**
|
|
252
|
-
* Navigate to a path.
|
|
539
|
+
* Navigate to a path - auto-detects internal vs external.
|
|
540
|
+
* Internal paths use React Router, external URLs use redirect.
|
|
253
541
|
*
|
|
254
|
-
* @param path - The path to navigate to
|
|
255
|
-
* @param options - Navigation options
|
|
542
|
+
* @param path - The path or URL to navigate to
|
|
543
|
+
* @param options - Navigation options (only for internal paths)
|
|
256
544
|
*
|
|
257
545
|
* @example
|
|
258
546
|
* ```typescript
|
|
259
|
-
*
|
|
260
|
-
*
|
|
547
|
+
* embedded.page.navTo('/products'); // SPA navigation
|
|
548
|
+
* embedded.page.navTo('https://external.com'); // Full redirect
|
|
261
549
|
* ```
|
|
262
550
|
*/
|
|
263
551
|
navTo(path: string, options?: NavToOptions): void;
|
|
@@ -265,36 +553,54 @@ export declare interface PageModule {
|
|
|
265
553
|
* Update the iframe height.
|
|
266
554
|
*
|
|
267
555
|
* @param height - Height in pixels
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* embedded.page.resize(800);
|
|
560
|
+
* ```
|
|
268
561
|
*/
|
|
269
562
|
resize(height: number): void;
|
|
270
563
|
/**
|
|
271
|
-
*
|
|
564
|
+
* Auto-resize iframe to content height.
|
|
565
|
+
* Measures document.documentElement.scrollHeight and sends resize.
|
|
272
566
|
*
|
|
273
|
-
* @
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* // After content changes
|
|
570
|
+
* embedded.page.autoResize();
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
autoResize(): void;
|
|
574
|
+
/**
|
|
575
|
+
* Set the page title in the host document.
|
|
576
|
+
*
|
|
577
|
+
* @param title - The title to set
|
|
274
578
|
*
|
|
275
579
|
* @example
|
|
276
580
|
* ```typescript
|
|
277
|
-
*
|
|
278
|
-
* { label: 'Home', path: '/' },
|
|
279
|
-
* { label: 'Products', path: '/products' },
|
|
280
|
-
* { label: 'Current Product' }
|
|
281
|
-
* ]);
|
|
581
|
+
* embedded.page.setTitle('Product Details');
|
|
282
582
|
* ```
|
|
283
583
|
*/
|
|
284
|
-
|
|
584
|
+
setTitle(title: string): void;
|
|
285
585
|
}
|
|
286
586
|
|
|
287
587
|
/**
|
|
288
|
-
*
|
|
588
|
+
* Configuration for the primary action button.
|
|
289
589
|
*/
|
|
290
590
|
export declare interface PrimaryActionConfig {
|
|
291
591
|
/** Button title */
|
|
292
592
|
title: string;
|
|
293
|
-
/**
|
|
294
|
-
|
|
295
|
-
/** Custom value
|
|
593
|
+
/** Callback function to execute when clicked (replaces url) */
|
|
594
|
+
onClick?: () => void;
|
|
595
|
+
/** Custom value for identifying the action (passed to onClick callback) */
|
|
296
596
|
value?: string;
|
|
297
|
-
/**
|
|
597
|
+
/** Optional subtitle */
|
|
598
|
+
subTitle?: string;
|
|
599
|
+
/** Optional icon class name */
|
|
600
|
+
icon?: string;
|
|
601
|
+
/** Whether the button is disabled */
|
|
602
|
+
disabled?: boolean;
|
|
603
|
+
/** Extended dropdown actions */
|
|
298
604
|
extendedActions?: ExtendedAction[];
|
|
299
605
|
}
|
|
300
606
|
|
|
@@ -303,6 +609,141 @@ export declare interface PrimaryActionConfig {
|
|
|
303
609
|
*/
|
|
304
610
|
export declare function resetEmbeddedApp(): void;
|
|
305
611
|
|
|
306
|
-
|
|
612
|
+
/**
|
|
613
|
+
* @fileoverview Core type definitions for the Embedded SDK.
|
|
614
|
+
*/
|
|
615
|
+
/**
|
|
616
|
+
* Theme type for the SDK.
|
|
617
|
+
*/
|
|
618
|
+
declare type Theme = "light" | "dark";
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Theme change callback type.
|
|
622
|
+
*/
|
|
623
|
+
declare type ThemeChangeCallback = (theme: "light" | "dark") => void;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Toast notification options.
|
|
627
|
+
*/
|
|
628
|
+
export declare interface ToastOptions {
|
|
629
|
+
/** Toast type */
|
|
630
|
+
type: ToastType_2;
|
|
631
|
+
/** Message to display */
|
|
632
|
+
message: string;
|
|
633
|
+
/** Duration in milliseconds (optional) */
|
|
634
|
+
duration?: number;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Toast sub-module interface.
|
|
639
|
+
*/
|
|
640
|
+
declare interface ToastSubModule {
|
|
641
|
+
/**
|
|
642
|
+
* Show a toast notification.
|
|
643
|
+
* @param options - Toast configuration
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```typescript
|
|
647
|
+
* embedded.ui.toast.show({
|
|
648
|
+
* type: 'success',
|
|
649
|
+
* message: 'Product saved!',
|
|
650
|
+
* duration: 3000
|
|
651
|
+
* });
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
show(options: ToastOptions): void;
|
|
655
|
+
/**
|
|
656
|
+
* Show success toast.
|
|
657
|
+
* @param message - Message to display
|
|
658
|
+
* @param duration - Duration in ms
|
|
659
|
+
*/
|
|
660
|
+
success(message: string, duration?: number): void;
|
|
661
|
+
/**
|
|
662
|
+
* Show error toast.
|
|
663
|
+
* @param message - Message to display
|
|
664
|
+
* @param duration - Duration in ms
|
|
665
|
+
*/
|
|
666
|
+
error(message: string, duration?: number): void;
|
|
667
|
+
/**
|
|
668
|
+
* Show warning toast.
|
|
669
|
+
* @param message - Message to display
|
|
670
|
+
* @param duration - Duration in ms
|
|
671
|
+
*/
|
|
672
|
+
warning(message: string, duration?: number): void;
|
|
673
|
+
/**
|
|
674
|
+
* Show info toast.
|
|
675
|
+
* @param message - Message to display
|
|
676
|
+
* @param duration - Duration in ms
|
|
677
|
+
*/
|
|
678
|
+
info(message: string, duration?: number): void;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Toast notification types.
|
|
683
|
+
*/
|
|
684
|
+
export declare type ToastType = "success" | "error" | "warning" | "info";
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Toast type.
|
|
688
|
+
*/
|
|
689
|
+
declare type ToastType_2 = "success" | "error" | "warning" | "info";
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* UI module interface with nested sub-modules.
|
|
693
|
+
*/
|
|
694
|
+
export declare interface UIModule {
|
|
695
|
+
/**
|
|
696
|
+
* Loading state control.
|
|
697
|
+
*/
|
|
698
|
+
loading: LoadingSubModule;
|
|
699
|
+
/**
|
|
700
|
+
* Toast notifications.
|
|
701
|
+
*/
|
|
702
|
+
toast: ToastSubModule;
|
|
703
|
+
/**
|
|
704
|
+
* Modal control.
|
|
705
|
+
*/
|
|
706
|
+
modal: ModalSubModule;
|
|
707
|
+
/**
|
|
708
|
+
* Show a confirmation dialog and wait for user response.
|
|
709
|
+
*
|
|
710
|
+
* @param options - Confirm dialog options
|
|
711
|
+
* @returns Promise that resolves with the user's choice
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* const result = await embedded.ui.confirm({
|
|
716
|
+
* title: 'Delete Product?',
|
|
717
|
+
* message: 'This action cannot be undone.',
|
|
718
|
+
* confirmText: 'Delete',
|
|
719
|
+
* variant: 'danger',
|
|
720
|
+
* });
|
|
721
|
+
* if (result.confirmed) {
|
|
722
|
+
* // User confirmed
|
|
723
|
+
* }
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
confirm(options: ConfirmOptions): Promise<ConfirmResult>;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Unsubscribe function returned by message listeners.
|
|
731
|
+
*/
|
|
732
|
+
declare type Unsubscribe = () => void;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @fileoverview Validation types for SDK payload validation.
|
|
736
|
+
*/
|
|
737
|
+
/**
|
|
738
|
+
* Result of a validation check.
|
|
739
|
+
*/
|
|
740
|
+
export declare interface ValidationResult {
|
|
741
|
+
/** Whether the validation passed */
|
|
742
|
+
valid: boolean;
|
|
743
|
+
/** Array of error messages if validation failed */
|
|
744
|
+
errors: string[];
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export declare const version: string;
|
|
307
748
|
|
|
308
749
|
export { }
|