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