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