arky-sdk 0.7.92 → 0.7.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/admin.js ADDED
@@ -0,0 +1,2322 @@
1
+ // src/utils/blocks.ts
2
+ function getBlockLabel(block) {
3
+ if (!block) return "";
4
+ return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) ?? "";
5
+ }
6
+ function formatBlockValue(block) {
7
+ if (!block || block.value === null || block.value === void 0) return "";
8
+ const value = block.value;
9
+ switch (block.type) {
10
+ case "boolean":
11
+ return value ? "Yes" : "No";
12
+ case "number":
13
+ if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
14
+ return new Date(value).toLocaleDateString();
15
+ }
16
+ return String(value);
17
+ case "relationship_entry":
18
+ case "relationship_media":
19
+ if (value && typeof value === "object") {
20
+ return value.mime_type ? value.name || value.id : value.title || value.name || value.id;
21
+ }
22
+ return String(value);
23
+ default:
24
+ return String(value);
25
+ }
26
+ }
27
+ function prepareBlocksForSubmission(formData, blockTypes) {
28
+ return Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).map((key) => ({
29
+ key,
30
+ value: blockTypes?.[key] === "list" && !Array.isArray(formData[key]) ? [formData[key]] : formData[key]
31
+ }));
32
+ }
33
+ function extractBlockValues(blocks) {
34
+ const values = {};
35
+ blocks.forEach((block) => {
36
+ values[block.key] = block.value ?? null;
37
+ });
38
+ return values;
39
+ }
40
+ var getBlockValue = (entry, blockKey) => {
41
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
42
+ return block?.value ?? null;
43
+ };
44
+ var getBlockTextValue = (block, locale = "en") => {
45
+ if (!block || block.value === null || block.value === void 0) return "";
46
+ if (block.type === "localized_text" || block.type === "markdown") {
47
+ if (typeof block.value === "object" && block.value !== null) {
48
+ return block.value[locale] ?? block.value["en"] ?? "";
49
+ }
50
+ }
51
+ if (typeof block.value === "string") return block.value;
52
+ return String(block.value ?? "");
53
+ };
54
+ var getBlockValues = (entry, blockKey) => {
55
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
56
+ if (!block) return [];
57
+ if (block.type === "list" && Array.isArray(block.value)) {
58
+ return block.value;
59
+ }
60
+ return [];
61
+ };
62
+ function unwrapBlock(block, locale) {
63
+ if (!block?.type || block.value === void 0) return block;
64
+ if (block.type === "list") {
65
+ return block.value.map((obj) => {
66
+ const parsed = {};
67
+ for (const [k, v] of Object.entries(obj)) {
68
+ parsed[k] = unwrapBlock(v, locale);
69
+ }
70
+ return parsed;
71
+ });
72
+ }
73
+ if (block.type === "map") {
74
+ const parsed = {};
75
+ for (const [k, v] of Object.entries(block.value || {})) {
76
+ parsed[k] = unwrapBlock(v, locale);
77
+ }
78
+ return parsed;
79
+ }
80
+ if (block.type === "localized_text" || block.type === "markdown") {
81
+ return block.value?.[locale];
82
+ }
83
+ return block.value;
84
+ }
85
+ var getBlockObjectValues = (entry, blockKey, locale = "en") => {
86
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
87
+ if (!block || block.type !== "list" || !Array.isArray(block.value)) return [];
88
+ return block.value.map((obj) => {
89
+ if (!obj?.value || !Array.isArray(obj.value)) return {};
90
+ return obj.value.reduce((acc, current) => {
91
+ acc[current.key] = unwrapBlock(current, locale);
92
+ return acc;
93
+ }, {});
94
+ });
95
+ };
96
+ var getBlockFromArray = (entry, blockKey, locale = "en") => {
97
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
98
+ if (!block) return {};
99
+ if (block.type === "list" && Array.isArray(block.value)) {
100
+ return block.value.reduce((acc, current) => {
101
+ acc[current.key] = unwrapBlock(current, locale);
102
+ return acc;
103
+ }, {});
104
+ }
105
+ if (block.type === "map" && block.value && typeof block.value === "object") {
106
+ const result = {};
107
+ for (const [k, v] of Object.entries(block.value)) {
108
+ result[k] = unwrapBlock(v, locale);
109
+ }
110
+ return result;
111
+ }
112
+ return { [block.key]: unwrapBlock(block, locale) };
113
+ };
114
+ var getImageUrl = (imageBlock, isBlock = true) => {
115
+ if (!imageBlock) return null;
116
+ if (imageBlock.type === "relationship_media") {
117
+ const mediaValue = imageBlock.value;
118
+ return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
119
+ }
120
+ if (isBlock) {
121
+ if (typeof imageBlock === "string") return imageBlock;
122
+ if (imageBlock.url) return imageBlock.url;
123
+ }
124
+ return imageBlock.resolutions?.original?.url || null;
125
+ };
126
+
127
+ // src/utils/errors.ts
128
+ var convertServerErrorToRequestError = (serverError, renameRules) => {
129
+ const validationErrors = serverError?.validationErrors ?? [];
130
+ return {
131
+ ...serverError,
132
+ validationErrors: validationErrors.map((validationError) => {
133
+ const field = validationError.field;
134
+ return {
135
+ field,
136
+ error: validationError.error || "GENERAL.VALIDATION_ERROR"
137
+ };
138
+ })
139
+ };
140
+ };
141
+
142
+ // src/utils/queryParams.ts
143
+ function buildQueryString(params) {
144
+ const queryParts = [];
145
+ Object.entries(params).forEach(([key, value]) => {
146
+ if (value === null || value === void 0) {
147
+ return;
148
+ }
149
+ if (Array.isArray(value)) {
150
+ const jsonString = JSON.stringify(value);
151
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
152
+ } else if (typeof value === "string") {
153
+ queryParts.push(`${key}=${encodeURIComponent(value)}`);
154
+ } else if (typeof value === "number" || typeof value === "boolean") {
155
+ queryParts.push(`${key}=${value}`);
156
+ } else if (typeof value === "object") {
157
+ const jsonString = JSON.stringify(value);
158
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
159
+ }
160
+ });
161
+ return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
162
+ }
163
+
164
+ // src/services/createHttpClient.ts
165
+ var STORAGE_KEYS = {
166
+ access_token: "arky_token",
167
+ refresh_token: "arky_refresh",
168
+ access_expires_at: "arky_expires_at"
169
+ };
170
+ function defaultGetToken() {
171
+ if (typeof window === "undefined") return { access_token: "" };
172
+ return {
173
+ access_token: localStorage.getItem(STORAGE_KEYS.access_token) || "",
174
+ refresh_token: localStorage.getItem(STORAGE_KEYS.refresh_token) || "",
175
+ access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.access_expires_at) || "0", 10)
176
+ };
177
+ }
178
+ function defaultSetToken(tokens) {
179
+ if (typeof window === "undefined") return;
180
+ if (tokens.access_token) {
181
+ localStorage.setItem(STORAGE_KEYS.access_token, tokens.access_token);
182
+ localStorage.setItem(STORAGE_KEYS.refresh_token, tokens.refresh_token || "");
183
+ localStorage.setItem(STORAGE_KEYS.access_expires_at, (tokens.access_expires_at || 0).toString());
184
+ } else {
185
+ Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
186
+ }
187
+ }
188
+ function defaultLogout() {
189
+ if (typeof window === "undefined") return;
190
+ Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
191
+ }
192
+ function defaultIsAuthenticated() {
193
+ if (typeof window === "undefined") return false;
194
+ const token = localStorage.getItem(STORAGE_KEYS.access_token) || "";
195
+ return token.startsWith("customer_") || token.startsWith("account_");
196
+ }
197
+ function createHttpClient(cfg) {
198
+ const getToken = cfg.getToken || defaultGetToken;
199
+ const setToken = cfg.setToken || defaultSetToken;
200
+ const logout = cfg.logout || defaultLogout;
201
+ let refreshPromise = null;
202
+ function getRefreshEndpoint() {
203
+ const refreshPath = typeof cfg.refreshPath === "function" ? cfg.refreshPath() : cfg.refreshPath || "/v1/auth/refresh";
204
+ return `${cfg.baseUrl}${refreshPath}`;
205
+ }
206
+ async function ensureFreshToken() {
207
+ if (refreshPromise) {
208
+ return refreshPromise;
209
+ }
210
+ refreshPromise = (async () => {
211
+ const { refresh_token } = await getToken();
212
+ if (!refresh_token) {
213
+ logout();
214
+ const err = new Error("No refresh token available");
215
+ err.name = "ApiError";
216
+ err.statusCode = 401;
217
+ throw err;
218
+ }
219
+ const refRes = await fetch(getRefreshEndpoint(), {
220
+ method: "POST",
221
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
222
+ body: JSON.stringify({ refresh_token })
223
+ });
224
+ if (!refRes.ok) {
225
+ logout();
226
+ const err = new Error("Token refresh failed");
227
+ err.name = "ApiError";
228
+ err.statusCode = 401;
229
+ throw err;
230
+ }
231
+ const data = await refRes.json();
232
+ setToken(data);
233
+ })().finally(() => {
234
+ refreshPromise = null;
235
+ });
236
+ return refreshPromise;
237
+ }
238
+ async function request(method, path, body, options) {
239
+ if (options?.transformRequest) {
240
+ body = options.transformRequest(body);
241
+ }
242
+ const headers = {
243
+ Accept: "application/json",
244
+ "Content-Type": "application/json",
245
+ ...options?.headers || {}
246
+ };
247
+ let { access_token, access_expires_at } = await getToken();
248
+ const nowSec = Date.now() / 1e3;
249
+ if (access_expires_at && nowSec > access_expires_at) {
250
+ await ensureFreshToken();
251
+ const tokens = await getToken();
252
+ access_token = tokens.access_token;
253
+ }
254
+ if (access_token) {
255
+ headers["Authorization"] = `Bearer ${access_token}`;
256
+ }
257
+ const finalPath = options?.params ? path + buildQueryString(options.params) : path;
258
+ const fetchOpts = { method, headers };
259
+ if (!["GET", "DELETE"].includes(method) && body !== void 0) {
260
+ fetchOpts.body = JSON.stringify(body);
261
+ }
262
+ const fullUrl = `${cfg.baseUrl}${finalPath}`;
263
+ let res;
264
+ let data;
265
+ const startedAt = Date.now();
266
+ try {
267
+ res = await fetch(fullUrl, fetchOpts);
268
+ } catch (error) {
269
+ const err = new Error(error instanceof Error ? error.message : "Network request failed");
270
+ err.name = "NetworkError";
271
+ err.method = method;
272
+ err.url = fullUrl;
273
+ if (options?.onError && method !== "GET") {
274
+ Promise.resolve(
275
+ options.onError({ error: err, method, url: fullUrl, aborted: false })
276
+ ).catch(() => {
277
+ });
278
+ }
279
+ throw err;
280
+ }
281
+ if (res.status === 401 && !options?.["_retried"]) {
282
+ try {
283
+ await ensureFreshToken();
284
+ const tokens = await getToken();
285
+ headers["Authorization"] = `Bearer ${tokens.access_token}`;
286
+ fetchOpts.headers = headers;
287
+ return request(method, path, body, { ...options, _retried: true });
288
+ } catch (refreshError) {
289
+ throw refreshError;
290
+ }
291
+ }
292
+ try {
293
+ const contentLength = res.headers.get("content-length");
294
+ const contentType = res.headers.get("content-type");
295
+ if (res.status === 204 || contentLength === "0" || !contentType?.includes("application/json")) {
296
+ data = {};
297
+ } else {
298
+ data = await res.json();
299
+ }
300
+ } catch (error) {
301
+ const err = new Error("Failed to parse response");
302
+ err.name = "ParseError";
303
+ err.method = method;
304
+ err.url = fullUrl;
305
+ err.status = res.status;
306
+ if (options?.onError && method !== "GET") {
307
+ Promise.resolve(
308
+ options.onError({ error: err, method, url: fullUrl, status: res.status })
309
+ ).catch(() => {
310
+ });
311
+ }
312
+ throw err;
313
+ }
314
+ if (!res.ok) {
315
+ const serverErr = data;
316
+ const reqErr = convertServerErrorToRequestError(serverErr);
317
+ const err = new Error(serverErr.message || "Request failed");
318
+ err.name = "ApiError";
319
+ err.statusCode = serverErr.statusCode || res.status;
320
+ err.validationErrors = reqErr.validationErrors;
321
+ err.method = method;
322
+ err.url = fullUrl;
323
+ const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
324
+ if (requestId) err.requestId = requestId;
325
+ if (options?.onError && method !== "GET") {
326
+ Promise.resolve(
327
+ options.onError({
328
+ error: err,
329
+ method,
330
+ url: fullUrl,
331
+ status: res.status,
332
+ response: serverErr,
333
+ request_id: requestId || null,
334
+ duration_ms: Date.now() - startedAt
335
+ })
336
+ ).catch(() => {
337
+ });
338
+ }
339
+ throw err;
340
+ }
341
+ if (options?.onSuccess && method !== "GET") {
342
+ const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
343
+ Promise.resolve(
344
+ options.onSuccess({
345
+ data,
346
+ method,
347
+ url: fullUrl,
348
+ status: res.status,
349
+ request_id: requestId || null,
350
+ duration_ms: Date.now() - startedAt
351
+ })
352
+ ).catch(() => {
353
+ });
354
+ }
355
+ return data;
356
+ }
357
+ return {
358
+ get: (path, opts) => request("GET", path, void 0, opts),
359
+ post: (path, body, opts) => request("POST", path, body, opts),
360
+ put: (path, body, opts) => request("PUT", path, body, opts),
361
+ patch: (path, body, opts) => request("PATCH", path, body, opts),
362
+ delete: (path, opts) => request("DELETE", path, void 0, opts)
363
+ };
364
+ }
365
+
366
+ // src/api/account.ts
367
+ var createAccountApi = (apiConfig) => {
368
+ return {
369
+ async updateAccount(params, options) {
370
+ const payload = {};
371
+ if (params.phone_numbers !== void 0) payload.phone_numbers = params.phone_numbers;
372
+ if (params.addresses !== void 0) payload.addresses = params.addresses;
373
+ if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
374
+ return apiConfig.httpClient.put("/v1/accounts", payload, options);
375
+ },
376
+ async deleteAccount(params, options) {
377
+ return apiConfig.httpClient.delete("/v1/accounts", options);
378
+ },
379
+ async getMe(params, options) {
380
+ return apiConfig.httpClient.get("/v1/accounts/me", options);
381
+ },
382
+ async searchAccounts(params, options) {
383
+ return apiConfig.httpClient.get("/v1/accounts/search", {
384
+ ...options,
385
+ params: {
386
+ ...params,
387
+ store_id: apiConfig.storeId
388
+ }
389
+ });
390
+ }
391
+ };
392
+ };
393
+
394
+ // src/api/auth.ts
395
+ var createAuthApi = (apiConfig) => {
396
+ return {
397
+ async code(params, options) {
398
+ return apiConfig.httpClient.post("/v1/auth/code", params, options);
399
+ },
400
+ async verify(params, options) {
401
+ const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
402
+ if (result?.access_token) {
403
+ apiConfig.setToken({ ...result, email: params.email, is_verified: true });
404
+ }
405
+ return result;
406
+ },
407
+ async refresh(params, options) {
408
+ return apiConfig.httpClient.post("/v1/auth/refresh", params, options);
409
+ },
410
+ async storeCode(storeId, params, options) {
411
+ return apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
412
+ },
413
+ async storeVerify(storeId, params, options) {
414
+ const result = await apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/verify`, params, options);
415
+ if (result?.access_token) {
416
+ apiConfig.setToken({ ...result, email: params.email, is_verified: true });
417
+ }
418
+ return result;
419
+ },
420
+ async magicLink(params, options) {
421
+ return apiConfig.httpClient.post("/v1/auth/code", params, options);
422
+ }
423
+ };
424
+ };
425
+
426
+ // src/api/store.ts
427
+ var createStoreApi = (apiConfig) => {
428
+ return {
429
+ async createStore(params, options) {
430
+ return apiConfig.httpClient.post(`/v1/stores`, params, options);
431
+ },
432
+ async updateStore(params, options) {
433
+ return apiConfig.httpClient.put(
434
+ `/v1/stores/${params.id}`,
435
+ params,
436
+ options
437
+ );
438
+ },
439
+ async deleteStore(params, options) {
440
+ return apiConfig.httpClient.delete(
441
+ `/v1/stores/${params.id}`,
442
+ options
443
+ );
444
+ },
445
+ async getStore(params, options) {
446
+ return apiConfig.httpClient.get(
447
+ `/v1/stores/${apiConfig.storeId}`,
448
+ options
449
+ );
450
+ },
451
+ async getStores(params, options) {
452
+ return apiConfig.httpClient.get(`/v1/stores`, {
453
+ ...options,
454
+ params
455
+ });
456
+ },
457
+ async getSubscriptionPlans(params, options) {
458
+ return apiConfig.httpClient.get("/v1/stores/plans", options);
459
+ },
460
+ async subscribe(params, options) {
461
+ const { store_id, plan_id, success_url, cancel_url } = params;
462
+ const target_store_id = store_id || apiConfig.storeId;
463
+ return apiConfig.httpClient.put(
464
+ `/v1/stores/${target_store_id}/subscribe`,
465
+ { plan_id, success_url, cancel_url },
466
+ options
467
+ );
468
+ },
469
+ async createPortalSession(params, options) {
470
+ const store_id = params.store_id || apiConfig.storeId;
471
+ return apiConfig.httpClient.post(
472
+ `/v1/stores/${store_id}/subscription/portal`,
473
+ { return_url: params.return_url },
474
+ options
475
+ );
476
+ },
477
+ async inviteUser(params, options) {
478
+ return apiConfig.httpClient.post(
479
+ `/v1/stores/${apiConfig.storeId}/invitation`,
480
+ params,
481
+ options
482
+ );
483
+ },
484
+ async removeMember(params, options) {
485
+ return apiConfig.httpClient.delete(
486
+ `/v1/stores/${apiConfig.storeId}/members/${params.account_id}`,
487
+ options
488
+ );
489
+ },
490
+ async handleInvitation(params, options) {
491
+ const { store_id, ...payload } = params;
492
+ return apiConfig.httpClient.put(
493
+ `/v1/stores/${store_id || apiConfig.storeId}/invitation`,
494
+ payload,
495
+ options
496
+ );
497
+ },
498
+ async testWebhook(params, options) {
499
+ return apiConfig.httpClient.post(
500
+ `/v1/stores/${apiConfig.storeId}/webhooks/test`,
501
+ params.webhook,
502
+ options
503
+ );
504
+ },
505
+ async getStoreMedia(params, options) {
506
+ const queryParams = {
507
+ limit: params.limit
508
+ };
509
+ if (params.cursor) queryParams.cursor = params.cursor;
510
+ if (params.ids && params.ids.length > 0) queryParams.ids = params.ids.join(",");
511
+ if (params.query) queryParams.query = params.query;
512
+ if (params.mime_type) queryParams.mime_type = params.mime_type;
513
+ if (params.sort_field) queryParams.sort_field = params.sort_field;
514
+ if (params.sort_direction) queryParams.sort_direction = params.sort_direction;
515
+ return apiConfig.httpClient.get(`/v1/stores/${params.id}/media`, {
516
+ ...options,
517
+ params: queryParams
518
+ });
519
+ },
520
+ async oauthConnect(params, options) {
521
+ return apiConfig.httpClient.post(
522
+ `/v1/stores/${params.store_id}/oauth/connect`,
523
+ { provider: params.provider, code: params.code, redirect_uri: params.redirect_uri },
524
+ options
525
+ );
526
+ },
527
+ async oauthDisconnect(params, options) {
528
+ return apiConfig.httpClient.post(
529
+ `/v1/stores/${params.store_id}/oauth/disconnect`,
530
+ { provider: params.provider },
531
+ options
532
+ );
533
+ },
534
+ async listIntegrations(params, options) {
535
+ return apiConfig.httpClient.get(
536
+ `/v1/stores/${params.store_id}/integrations`,
537
+ options
538
+ );
539
+ },
540
+ async createIntegration(params, options) {
541
+ const { store_id, ...payload } = params;
542
+ return apiConfig.httpClient.post(
543
+ `/v1/stores/${store_id}/integrations`,
544
+ payload,
545
+ options
546
+ );
547
+ },
548
+ async updateIntegration(params, options) {
549
+ const { store_id, id, ...payload } = params;
550
+ return apiConfig.httpClient.put(
551
+ `/v1/stores/${store_id}/integrations/${id}`,
552
+ payload,
553
+ options
554
+ );
555
+ },
556
+ async deleteIntegration(params, options) {
557
+ return apiConfig.httpClient.delete(
558
+ `/v1/stores/${params.store_id}/integrations/${params.id}`,
559
+ options
560
+ );
561
+ },
562
+ async getIntegrationConfig(params, options) {
563
+ return apiConfig.httpClient.get(
564
+ `/v1/stores/${params.store_id}/integrations/config/${params.type}`,
565
+ options
566
+ );
567
+ },
568
+ async listWebhooks(params, options) {
569
+ return apiConfig.httpClient.get(
570
+ `/v1/stores/${params.store_id}/webhooks`,
571
+ options
572
+ );
573
+ },
574
+ async createWebhook(params, options) {
575
+ const { store_id, ...payload } = params;
576
+ return apiConfig.httpClient.post(
577
+ `/v1/stores/${store_id}/webhooks`,
578
+ payload,
579
+ options
580
+ );
581
+ },
582
+ async updateWebhook(params, options) {
583
+ const { store_id, id, ...payload } = params;
584
+ return apiConfig.httpClient.put(
585
+ `/v1/stores/${store_id}/webhooks/${id}`,
586
+ payload,
587
+ options
588
+ );
589
+ },
590
+ async deleteWebhook(params, options) {
591
+ return apiConfig.httpClient.delete(
592
+ `/v1/stores/${params.store_id}/webhooks/${params.id}`,
593
+ options
594
+ );
595
+ }
596
+ };
597
+ };
598
+
599
+ // src/api/media.ts
600
+ var createMediaApi = (apiConfig) => {
601
+ return {
602
+ async getMedia(params, options) {
603
+ const target_store_id = params.store_id || apiConfig.storeId;
604
+ return apiConfig.httpClient.get(
605
+ `/v1/stores/${target_store_id}/media/${params.media_id}`,
606
+ options
607
+ );
608
+ },
609
+ async uploadStoreMedia(params, options) {
610
+ const { store_id, files = [], urls = [] } = params;
611
+ const target_store_id = store_id || apiConfig.storeId;
612
+ const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
613
+ const formData = new FormData();
614
+ files.forEach((file) => formData.append("files", file));
615
+ urls.forEach((url2) => formData.append("urls", url2));
616
+ const tokens = await apiConfig.getToken();
617
+ const response = await fetch(url, {
618
+ method: "POST",
619
+ body: formData,
620
+ headers: {
621
+ Authorization: `Bearer ${tokens.access_token}`
622
+ }
623
+ });
624
+ if (!response.ok) {
625
+ throw new Error("Upload failed, server said no");
626
+ }
627
+ return await response.json();
628
+ },
629
+ async deleteStoreMedia(params, options) {
630
+ const { id, media_id } = params;
631
+ return apiConfig.httpClient.delete(
632
+ `/v1/stores/${id}/media/${media_id}`,
633
+ options
634
+ );
635
+ },
636
+ async getStoreMedia(params, options) {
637
+ const { store_id, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
638
+ const target_store_id = store_id || apiConfig.storeId;
639
+ const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
640
+ const queryParams = { limit: String(limit) };
641
+ if (cursor) queryParams.cursor = cursor;
642
+ if (ids && ids.length > 0) queryParams.ids = ids.join(",");
643
+ if (query) queryParams.query = query;
644
+ if (mime_type) queryParams.mime_type = mime_type;
645
+ if (sort_field) queryParams.sort_field = sort_field;
646
+ if (sort_direction) queryParams.sort_direction = sort_direction;
647
+ const queryString = new URLSearchParams(queryParams).toString();
648
+ const tokens = await apiConfig.getToken();
649
+ const response = await fetch(`${url}?${queryString}`, {
650
+ headers: {
651
+ Authorization: `Bearer ${tokens.access_token}`
652
+ }
653
+ });
654
+ if (!response.ok) {
655
+ const errorData = await response.json().catch(() => null);
656
+ throw new Error(errorData?.message || "Failed to fetch media");
657
+ }
658
+ return await response.json();
659
+ },
660
+ async updateMedia(params, options) {
661
+ const { media_id, store_id, ...payload } = params;
662
+ const target_store_id = store_id || apiConfig.storeId;
663
+ return apiConfig.httpClient.put(
664
+ `/v1/stores/${target_store_id}/media/${media_id}`,
665
+ payload,
666
+ options
667
+ );
668
+ }
669
+ };
670
+ };
671
+
672
+ // src/api/notification.ts
673
+ var createNotificationApi = (apiConfig) => {
674
+ return {
675
+ async trackEmailOpen(params, options) {
676
+ return apiConfig.httpClient.get(
677
+ `/v1/notifications/track/pixel/${params.tracking_pixel_id}`,
678
+ options
679
+ );
680
+ },
681
+ async trigger(params, options) {
682
+ return apiConfig.httpClient.post(
683
+ "/v1/notifications/trigger",
684
+ params,
685
+ options
686
+ );
687
+ }
688
+ };
689
+ };
690
+
691
+ // src/api/promoCode.ts
692
+ var createPromoCodeApi = (apiConfig) => {
693
+ return {
694
+ async createPromoCode(params, options) {
695
+ const { store_id, ...payload } = params;
696
+ const target_store_id = store_id || apiConfig.storeId;
697
+ return apiConfig.httpClient.post(
698
+ `/v1/stores/${target_store_id}/promo-codes`,
699
+ payload,
700
+ options
701
+ );
702
+ },
703
+ async updatePromoCode(params, options) {
704
+ const { store_id, ...payload } = params;
705
+ const target_store_id = store_id || apiConfig.storeId;
706
+ return apiConfig.httpClient.put(
707
+ `/v1/stores/${target_store_id}/promo-codes/${params.id}`,
708
+ payload,
709
+ options
710
+ );
711
+ },
712
+ async deletePromoCode(params, options) {
713
+ const target_store_id = params.store_id || apiConfig.storeId;
714
+ return apiConfig.httpClient.delete(
715
+ `/v1/stores/${target_store_id}/promo-codes/${params.id}`,
716
+ options
717
+ );
718
+ },
719
+ async getPromoCode(params, options) {
720
+ const target_store_id = params.store_id || apiConfig.storeId;
721
+ return apiConfig.httpClient.get(
722
+ `/v1/stores/${target_store_id}/promo-codes/${params.id}`,
723
+ options
724
+ );
725
+ },
726
+ async getPromoCodes(params, options) {
727
+ const { store_id, ...queryParams } = params;
728
+ const target_store_id = store_id || apiConfig.storeId;
729
+ return apiConfig.httpClient.get(`/v1/stores/${target_store_id}/promo-codes`, {
730
+ ...options,
731
+ params: queryParams
732
+ });
733
+ }
734
+ };
735
+ };
736
+
737
+ // src/api/cms.ts
738
+ var createCmsApi = (apiConfig) => {
739
+ return {
740
+ async createNode(params, options) {
741
+ const { store_id, ...payload } = params;
742
+ const target_store_id = store_id || apiConfig.storeId;
743
+ return apiConfig.httpClient.post(
744
+ `/v1/stores/${target_store_id}/nodes`,
745
+ payload,
746
+ options
747
+ );
748
+ },
749
+ async updateNode(params, options) {
750
+ const { store_id, ...payload } = params;
751
+ const target_store_id = store_id || apiConfig.storeId;
752
+ return apiConfig.httpClient.put(
753
+ `/v1/stores/${target_store_id}/nodes/${params.id}`,
754
+ payload,
755
+ options
756
+ );
757
+ },
758
+ async deleteNode(params, options) {
759
+ const target_store_id = params.store_id || apiConfig.storeId;
760
+ return apiConfig.httpClient.delete(
761
+ `/v1/stores/${target_store_id}/nodes/${params.id}`,
762
+ options
763
+ );
764
+ },
765
+ async getNode(params, options) {
766
+ const target_store_id = params.store_id || apiConfig.storeId;
767
+ let identifier;
768
+ if (params.id) {
769
+ identifier = params.id;
770
+ } else if (params.slug) {
771
+ identifier = `${target_store_id}:${apiConfig.locale}:${params.slug}`;
772
+ } else if (params.key) {
773
+ identifier = `${target_store_id}:${params.key}`;
774
+ } else {
775
+ throw new Error("GetNodeParams requires id, slug, or key");
776
+ }
777
+ const response = await apiConfig.httpClient.get(
778
+ `/v1/stores/${target_store_id}/nodes/${identifier}`,
779
+ options
780
+ );
781
+ return {
782
+ ...response,
783
+ getBlock(key) {
784
+ return getBlockFromArray(response, key, apiConfig.locale);
785
+ },
786
+ getBlockValues(key) {
787
+ return getBlockObjectValues(response, key, apiConfig.locale);
788
+ },
789
+ getImage(key) {
790
+ const block = getBlockFromArray(response, key, apiConfig.locale);
791
+ return getImageUrl(block, true);
792
+ }
793
+ };
794
+ },
795
+ async getNodes(params, options) {
796
+ const { store_id, ...queryParams } = params;
797
+ const target_store_id = store_id || apiConfig.storeId;
798
+ return apiConfig.httpClient.get(
799
+ `/v1/stores/${target_store_id}/nodes`,
800
+ {
801
+ ...options,
802
+ params: queryParams
803
+ }
804
+ );
805
+ },
806
+ async getNodeChildren(params, options) {
807
+ const { id, store_id, ...queryParams } = params;
808
+ const target_store_id = store_id || apiConfig.storeId;
809
+ return apiConfig.httpClient.get(
810
+ `/v1/stores/${target_store_id}/nodes/${id}/children`,
811
+ {
812
+ ...options,
813
+ params: queryParams
814
+ }
815
+ );
816
+ }
817
+ };
818
+ };
819
+
820
+ // src/api/eshop.ts
821
+ var createEshopApi = (apiConfig) => {
822
+ return {
823
+ async createProduct(params, options) {
824
+ const { store_id, ...payload } = params;
825
+ const target_store_id = store_id || apiConfig.storeId;
826
+ return apiConfig.httpClient.post(
827
+ `/v1/stores/${target_store_id}/products`,
828
+ payload,
829
+ options
830
+ );
831
+ },
832
+ async updateProduct(params, options) {
833
+ const { store_id, ...payload } = params;
834
+ const target_store_id = store_id || apiConfig.storeId;
835
+ return apiConfig.httpClient.put(
836
+ `/v1/stores/${target_store_id}/products/${params.id}`,
837
+ payload,
838
+ options
839
+ );
840
+ },
841
+ async deleteProduct(params, options) {
842
+ const target_store_id = params.store_id || apiConfig.storeId;
843
+ return apiConfig.httpClient.delete(
844
+ `/v1/stores/${target_store_id}/products/${params.id}`,
845
+ options
846
+ );
847
+ },
848
+ async getProduct(params, options) {
849
+ const target_store_id = params.store_id || apiConfig.storeId;
850
+ let identifier;
851
+ if (params.id) {
852
+ identifier = params.id;
853
+ } else if (params.slug) {
854
+ identifier = `${target_store_id}:${apiConfig.locale}:${params.slug}`;
855
+ } else {
856
+ throw new Error("GetProductParams requires id or slug");
857
+ }
858
+ return apiConfig.httpClient.get(
859
+ `/v1/stores/${target_store_id}/products/${identifier}`,
860
+ options
861
+ );
862
+ },
863
+ async getProducts(params, options) {
864
+ const { store_id, ...queryParams } = params;
865
+ const target_store_id = store_id || apiConfig.storeId;
866
+ return apiConfig.httpClient.get(
867
+ `/v1/stores/${encodeURIComponent(target_store_id)}/products`,
868
+ {
869
+ ...options,
870
+ params: queryParams
871
+ }
872
+ );
873
+ },
874
+ async createOrder(params, options) {
875
+ const { store_id, ...payload } = params;
876
+ const target_store_id = store_id || apiConfig.storeId;
877
+ return apiConfig.httpClient.post(
878
+ `/v1/stores/${target_store_id}/orders`,
879
+ payload,
880
+ options
881
+ );
882
+ },
883
+ async updateOrder(params, options) {
884
+ const { store_id, ...payload } = params;
885
+ const target_store_id = store_id || apiConfig.storeId;
886
+ return apiConfig.httpClient.put(
887
+ `/v1/stores/${target_store_id}/orders/${params.id}`,
888
+ payload,
889
+ options
890
+ );
891
+ },
892
+ async getOrder(params, options) {
893
+ const target_store_id = params.store_id || apiConfig.storeId;
894
+ return apiConfig.httpClient.get(
895
+ `/v1/stores/${target_store_id}/orders/${params.id}`,
896
+ options
897
+ );
898
+ },
899
+ async getOrders(params, options) {
900
+ const { store_id, ...queryParams } = params;
901
+ const target_store_id = store_id || apiConfig.storeId;
902
+ return apiConfig.httpClient.get(
903
+ `/v1/stores/${target_store_id}/orders`,
904
+ {
905
+ ...options,
906
+ params: queryParams
907
+ }
908
+ );
909
+ },
910
+ async getQuote(params, options) {
911
+ const { location, ...rest } = params;
912
+ const shipping_address = location ? {
913
+ country: location.country || "",
914
+ state: location.state || "",
915
+ city: location.city || "",
916
+ postal_code: location.postal_code || "",
917
+ name: "",
918
+ street1: "",
919
+ street2: null
920
+ } : void 0;
921
+ return apiConfig.httpClient.post(
922
+ `/v1/stores/${apiConfig.storeId}/orders/quote`,
923
+ { ...rest, shipping_address, market: apiConfig.market },
924
+ options
925
+ );
926
+ },
927
+ async processRefund(params, options) {
928
+ return apiConfig.httpClient.post(
929
+ `/v1/stores/${apiConfig.storeId}/orders/${params.id}/refund`,
930
+ { amount: params.amount },
931
+ options
932
+ );
933
+ }
934
+ };
935
+ };
936
+
937
+ // src/api/booking.ts
938
+ var createBookingApi = (apiConfig) => {
939
+ let cart = [];
940
+ return {
941
+ addToCart(slot) {
942
+ cart.push(slot);
943
+ },
944
+ removeFromCart(slotId) {
945
+ cart = cart.filter((s) => s.id !== slotId);
946
+ },
947
+ getCart() {
948
+ return [...cart];
949
+ },
950
+ clearCart() {
951
+ cart = [];
952
+ },
953
+ async createBooking(params, options) {
954
+ const { store_id, ...payload } = params;
955
+ const target_store_id = store_id || apiConfig.storeId;
956
+ return apiConfig.httpClient.post(
957
+ `/v1/stores/${target_store_id}/bookings`,
958
+ { market: "booking", ...payload },
959
+ options
960
+ );
961
+ },
962
+ async updateBooking(params, options) {
963
+ const { id, ...payload } = params;
964
+ return apiConfig.httpClient.put(
965
+ `/v1/stores/${apiConfig.storeId}/bookings/${id}`,
966
+ payload,
967
+ options
968
+ );
969
+ },
970
+ async getBooking(params, options) {
971
+ const target_store_id = params.store_id || apiConfig.storeId;
972
+ return apiConfig.httpClient.get(
973
+ `/v1/stores/${target_store_id}/bookings/${params.id}`,
974
+ options
975
+ );
976
+ },
977
+ async searchBookings(params, options) {
978
+ const { store_id, ...queryParams } = params;
979
+ const target_store_id = store_id || apiConfig.storeId;
980
+ return apiConfig.httpClient.get(
981
+ `/v1/stores/${target_store_id}/bookings`,
982
+ {
983
+ ...options,
984
+ params: queryParams
985
+ }
986
+ );
987
+ },
988
+ async getQuote(params, options) {
989
+ const { store_id, ...payload } = params;
990
+ const target_store_id = store_id || apiConfig.storeId;
991
+ return apiConfig.httpClient.post(
992
+ `/v1/stores/${target_store_id}/bookings/quote`,
993
+ { market: "booking", ...payload },
994
+ options
995
+ );
996
+ },
997
+ async processRefund(params, options) {
998
+ return apiConfig.httpClient.post(
999
+ `/v1/stores/${apiConfig.storeId}/bookings/${params.id}/refund`,
1000
+ { amount: params.amount },
1001
+ options
1002
+ );
1003
+ },
1004
+ async getAvailability(params, options) {
1005
+ const { store_id, ...query } = params;
1006
+ const target_store_id = store_id || apiConfig.storeId;
1007
+ return apiConfig.httpClient.get(
1008
+ `/v1/stores/${target_store_id}/bookings/availability`,
1009
+ { ...options, params: query }
1010
+ );
1011
+ },
1012
+ async createService(params, options) {
1013
+ const { store_id, ...payload } = params;
1014
+ const target_store_id = store_id || apiConfig.storeId;
1015
+ return apiConfig.httpClient.post(
1016
+ `/v1/stores/${target_store_id}/services`,
1017
+ payload,
1018
+ options
1019
+ );
1020
+ },
1021
+ async updateService(params, options) {
1022
+ const { store_id, ...payload } = params;
1023
+ const target_store_id = store_id || apiConfig.storeId;
1024
+ return apiConfig.httpClient.put(
1025
+ `/v1/stores/${target_store_id}/services/${params.id}`,
1026
+ payload,
1027
+ options
1028
+ );
1029
+ },
1030
+ async deleteService(params, options) {
1031
+ const target_store_id = params.store_id || apiConfig.storeId;
1032
+ return apiConfig.httpClient.delete(
1033
+ `/v1/stores/${target_store_id}/services/${params.id}`,
1034
+ options
1035
+ );
1036
+ },
1037
+ async getService(params, options) {
1038
+ const store_id = params.store_id || apiConfig.storeId;
1039
+ let identifier;
1040
+ if (params.id) {
1041
+ identifier = params.id;
1042
+ } else if (params.slug) {
1043
+ identifier = `${store_id}:${apiConfig.locale}:${params.slug}`;
1044
+ } else {
1045
+ throw new Error("GetServiceParams requires id or slug");
1046
+ }
1047
+ return apiConfig.httpClient.get(
1048
+ `/v1/stores/${store_id}/services/${identifier}`,
1049
+ options
1050
+ );
1051
+ },
1052
+ async getServices(params, options) {
1053
+ const { store_id, ...queryParams } = params;
1054
+ const target_store_id = store_id || apiConfig.storeId;
1055
+ return apiConfig.httpClient.get(
1056
+ `/v1/stores/${target_store_id}/services`,
1057
+ {
1058
+ ...options,
1059
+ params: queryParams
1060
+ }
1061
+ );
1062
+ },
1063
+ async createProvider(params, options) {
1064
+ const { store_id, ...payload } = params;
1065
+ const target_store_id = store_id || apiConfig.storeId;
1066
+ return apiConfig.httpClient.post(
1067
+ `/v1/stores/${target_store_id}/providers`,
1068
+ payload,
1069
+ options
1070
+ );
1071
+ },
1072
+ async updateProvider(params, options) {
1073
+ const { store_id, ...payload } = params;
1074
+ const target_store_id = store_id || apiConfig.storeId;
1075
+ return apiConfig.httpClient.put(
1076
+ `/v1/stores/${target_store_id}/providers/${params.id}`,
1077
+ payload,
1078
+ options
1079
+ );
1080
+ },
1081
+ async deleteProvider(params, options) {
1082
+ const target_store_id = params.store_id || apiConfig.storeId;
1083
+ return apiConfig.httpClient.delete(
1084
+ `/v1/stores/${target_store_id}/providers/${params.id}`,
1085
+ options
1086
+ );
1087
+ },
1088
+ async getProvider(params, options) {
1089
+ const store_id = params.store_id || apiConfig.storeId;
1090
+ let identifier;
1091
+ if (params.id) {
1092
+ identifier = params.id;
1093
+ } else if (params.slug) {
1094
+ identifier = `${store_id}:${apiConfig.locale}:${params.slug}`;
1095
+ } else {
1096
+ throw new Error("GetProviderParams requires id or slug");
1097
+ }
1098
+ return apiConfig.httpClient.get(
1099
+ `/v1/stores/${store_id}/providers/${identifier}`,
1100
+ options
1101
+ );
1102
+ },
1103
+ async getProviders(params, options) {
1104
+ const { store_id, ...queryParams } = params;
1105
+ const target_store_id = store_id || apiConfig.storeId;
1106
+ return apiConfig.httpClient.get(
1107
+ `/v1/stores/${target_store_id}/providers`,
1108
+ {
1109
+ ...options,
1110
+ params: queryParams
1111
+ }
1112
+ );
1113
+ },
1114
+ async cancelBookingItem(params, options) {
1115
+ const { store_id, booking_id, item_id, ...payload } = params;
1116
+ const target_store_id = store_id || apiConfig.storeId;
1117
+ return apiConfig.httpClient.post(
1118
+ `/v1/stores/${target_store_id}/bookings/${booking_id}/items/${item_id}/cancel`,
1119
+ payload,
1120
+ options
1121
+ );
1122
+ },
1123
+ async findServiceProviders(params, options) {
1124
+ const { store_id, ...queryParams } = params;
1125
+ const target_store_id = store_id || apiConfig.storeId;
1126
+ return apiConfig.httpClient.get(
1127
+ `/v1/stores/${target_store_id}/service-providers`,
1128
+ { ...options, params: queryParams }
1129
+ );
1130
+ },
1131
+ async createServiceProvider(params, options) {
1132
+ const { store_id, ...payload } = params;
1133
+ const target_store_id = store_id || apiConfig.storeId;
1134
+ return apiConfig.httpClient.post(
1135
+ `/v1/stores/${target_store_id}/service-providers`,
1136
+ payload,
1137
+ options
1138
+ );
1139
+ },
1140
+ async updateServiceProvider(params, options) {
1141
+ const { store_id, id, ...payload } = params;
1142
+ const target_store_id = store_id || apiConfig.storeId;
1143
+ return apiConfig.httpClient.put(
1144
+ `/v1/stores/${target_store_id}/service-providers/${id}`,
1145
+ payload,
1146
+ options
1147
+ );
1148
+ },
1149
+ async deleteServiceProvider(params, options) {
1150
+ const target_store_id = params.store_id || apiConfig.storeId;
1151
+ return apiConfig.httpClient.delete(
1152
+ `/v1/stores/${target_store_id}/service-providers/${params.id}`,
1153
+ options
1154
+ );
1155
+ }
1156
+ };
1157
+ };
1158
+
1159
+ // src/api/location.ts
1160
+ var createLocationApi = (apiConfig) => {
1161
+ return {
1162
+ async getCountries(options) {
1163
+ return apiConfig.httpClient.get(`/v1/platform/countries`, options);
1164
+ },
1165
+ async getCountry(countryCode, options) {
1166
+ return apiConfig.httpClient.get(
1167
+ `/v1/platform/countries/${countryCode}`,
1168
+ options
1169
+ );
1170
+ },
1171
+ async list(options) {
1172
+ return apiConfig.httpClient.get(
1173
+ `/v1/stores/${apiConfig.storeId}/locations`,
1174
+ options
1175
+ );
1176
+ },
1177
+ async get(id, options) {
1178
+ return apiConfig.httpClient.get(
1179
+ `/v1/stores/${apiConfig.storeId}/locations/${id}`,
1180
+ options
1181
+ );
1182
+ },
1183
+ async create(params, options) {
1184
+ return apiConfig.httpClient.post(
1185
+ `/v1/stores/${apiConfig.storeId}/locations`,
1186
+ { ...params, store_id: apiConfig.storeId },
1187
+ options
1188
+ );
1189
+ },
1190
+ async update(params, options) {
1191
+ return apiConfig.httpClient.put(
1192
+ `/v1/stores/${apiConfig.storeId}/locations/${params.id}`,
1193
+ { ...params, store_id: apiConfig.storeId },
1194
+ options
1195
+ );
1196
+ },
1197
+ async delete(params, options) {
1198
+ return apiConfig.httpClient.delete(
1199
+ `/v1/stores/${apiConfig.storeId}/locations/${params.id}`,
1200
+ options
1201
+ );
1202
+ }
1203
+ };
1204
+ };
1205
+
1206
+ // src/api/market.ts
1207
+ var createMarketApi = (apiConfig) => {
1208
+ return {
1209
+ async list(options) {
1210
+ return apiConfig.httpClient.get(
1211
+ `/v1/stores/${apiConfig.storeId}/markets`,
1212
+ options
1213
+ );
1214
+ },
1215
+ async get(id, options) {
1216
+ return apiConfig.httpClient.get(
1217
+ `/v1/stores/${apiConfig.storeId}/markets/${id}`,
1218
+ options
1219
+ );
1220
+ },
1221
+ async create(params, options) {
1222
+ return apiConfig.httpClient.post(
1223
+ `/v1/stores/${apiConfig.storeId}/markets`,
1224
+ { ...params, store_id: apiConfig.storeId },
1225
+ options
1226
+ );
1227
+ },
1228
+ async update(params, options) {
1229
+ return apiConfig.httpClient.put(
1230
+ `/v1/stores/${apiConfig.storeId}/markets/${params.id}`,
1231
+ { ...params, store_id: apiConfig.storeId },
1232
+ options
1233
+ );
1234
+ },
1235
+ async delete(params, options) {
1236
+ return apiConfig.httpClient.delete(
1237
+ `/v1/stores/${apiConfig.storeId}/markets/${params.id}`,
1238
+ options
1239
+ );
1240
+ }
1241
+ };
1242
+ };
1243
+
1244
+ // src/api/crm.ts
1245
+ var createActivityAdminApi = (apiConfig) => ({
1246
+ async timeline(params, options) {
1247
+ const store_id = params.store_id || apiConfig.storeId;
1248
+ const queryParams = { customer_id: params.customer_id };
1249
+ if (params.limit !== void 0) queryParams.limit = params.limit;
1250
+ if (params.cursor) queryParams.cursor = params.cursor;
1251
+ return apiConfig.httpClient.get(
1252
+ `/v1/stores/${store_id}/activities/timeline`,
1253
+ { ...options, params: queryParams }
1254
+ );
1255
+ }
1256
+ });
1257
+ var createCustomerApi = (apiConfig) => {
1258
+ return {
1259
+ async create(params, options) {
1260
+ const { store_id, ...payload } = params;
1261
+ return apiConfig.httpClient.post(
1262
+ `/v1/stores/${store_id || apiConfig.storeId}/customers`,
1263
+ payload,
1264
+ options
1265
+ );
1266
+ },
1267
+ async get(params, options) {
1268
+ return apiConfig.httpClient.get(
1269
+ `/v1/stores/${params.store_id || apiConfig.storeId}/customers/${params.id}`,
1270
+ options
1271
+ );
1272
+ },
1273
+ async find(params, options) {
1274
+ const store_id = params?.store_id || apiConfig.storeId;
1275
+ const queryParams = {};
1276
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
1277
+ if (params?.cursor) queryParams.cursor = params.cursor;
1278
+ if (params?.query) queryParams.query = params.query;
1279
+ if (params?.sort_field) queryParams.sort_field = params.sort_field;
1280
+ if (params?.sort_direction) queryParams.sort_direction = params.sort_direction;
1281
+ return apiConfig.httpClient.get(
1282
+ `/v1/stores/${store_id}/customers`,
1283
+ {
1284
+ ...options,
1285
+ params: queryParams
1286
+ }
1287
+ );
1288
+ },
1289
+ async update(params, options) {
1290
+ const { id, store_id, ...body } = params;
1291
+ return apiConfig.httpClient.put(
1292
+ `/v1/stores/${store_id || apiConfig.storeId}/customers/${id}`,
1293
+ body,
1294
+ options
1295
+ );
1296
+ },
1297
+ async merge(params, options) {
1298
+ const store_id = params.store_id || apiConfig.storeId;
1299
+ return apiConfig.httpClient.post(
1300
+ `/v1/stores/${store_id}/customers/${params.target_id}/merge`,
1301
+ { source_id: params.source_id, store_id },
1302
+ options
1303
+ );
1304
+ },
1305
+ async revokeToken(params, options) {
1306
+ const store_id = params.store_id || apiConfig.storeId;
1307
+ return apiConfig.httpClient.delete(
1308
+ `/v1/stores/${store_id}/customers/${params.id}/sessions/${params.token_id}`,
1309
+ options
1310
+ );
1311
+ },
1312
+ async revokeAllTokens(params, options) {
1313
+ const store_id = params.store_id || apiConfig.storeId;
1314
+ return apiConfig.httpClient.delete(
1315
+ `/v1/stores/${store_id}/customers/${params.id}/sessions`,
1316
+ options
1317
+ );
1318
+ },
1319
+ audiences: {
1320
+ async create(params, options) {
1321
+ return apiConfig.httpClient.post(
1322
+ `/v1/stores/${apiConfig.storeId}/audiences`,
1323
+ params,
1324
+ options
1325
+ );
1326
+ },
1327
+ async update(params, options) {
1328
+ return apiConfig.httpClient.put(
1329
+ `/v1/stores/${apiConfig.storeId}/audiences/${params.id}`,
1330
+ params,
1331
+ options
1332
+ );
1333
+ },
1334
+ async get(params, options) {
1335
+ let identifier;
1336
+ if (params.id) {
1337
+ identifier = params.id;
1338
+ } else if (params.key) {
1339
+ identifier = `${apiConfig.storeId}:${params.key}`;
1340
+ } else {
1341
+ throw new Error("GetAudienceParams requires id or key");
1342
+ }
1343
+ return apiConfig.httpClient.get(
1344
+ `/v1/stores/${apiConfig.storeId}/audiences/${identifier}`,
1345
+ options
1346
+ );
1347
+ },
1348
+ async find(params, options) {
1349
+ return apiConfig.httpClient.get(
1350
+ `/v1/stores/${apiConfig.storeId}/audiences`,
1351
+ { ...options, params }
1352
+ );
1353
+ },
1354
+ async getSubscribers(params, options) {
1355
+ return apiConfig.httpClient.get(
1356
+ `/v1/stores/${apiConfig.storeId}/audiences/${params.id}/subscribers`,
1357
+ {
1358
+ ...options,
1359
+ params: { limit: params.limit, cursor: params.cursor }
1360
+ }
1361
+ );
1362
+ },
1363
+ async addSubscriber(params, options) {
1364
+ return apiConfig.httpClient.post(
1365
+ `/v1/stores/${apiConfig.storeId}/audiences/${params.id}/subscribers`,
1366
+ { customer_id: params.customer_id },
1367
+ options
1368
+ );
1369
+ },
1370
+ async removeSubscriber(params, options) {
1371
+ return apiConfig.httpClient.delete(
1372
+ `/v1/stores/${apiConfig.storeId}/audiences/${params.id}/subscribers/${params.customer_id}`,
1373
+ options
1374
+ );
1375
+ }
1376
+ },
1377
+ activity: createActivityAdminApi(apiConfig)
1378
+ };
1379
+ };
1380
+
1381
+ // src/api/workflow.ts
1382
+ var createWorkflowApi = (apiConfig) => {
1383
+ return {
1384
+ async createWorkflow(params, options) {
1385
+ const { store_id, ...payload } = params;
1386
+ const target_store_id = store_id || apiConfig.storeId;
1387
+ return apiConfig.httpClient.post(
1388
+ `/v1/stores/${target_store_id}/workflows`,
1389
+ { ...payload, store_id: target_store_id },
1390
+ options
1391
+ );
1392
+ },
1393
+ async updateWorkflow(params, options) {
1394
+ const { store_id, id, ...payload } = params;
1395
+ const target_store_id = store_id || apiConfig.storeId;
1396
+ return apiConfig.httpClient.put(
1397
+ `/v1/stores/${target_store_id}/workflows/${id}`,
1398
+ payload,
1399
+ options
1400
+ );
1401
+ },
1402
+ async deleteWorkflow(params, options) {
1403
+ const store_id = params.store_id || apiConfig.storeId;
1404
+ return apiConfig.httpClient.delete(
1405
+ `/v1/stores/${store_id}/workflows/${params.id}`,
1406
+ options
1407
+ );
1408
+ },
1409
+ async getWorkflow(params, options) {
1410
+ const store_id = params.store_id || apiConfig.storeId;
1411
+ return apiConfig.httpClient.get(
1412
+ `/v1/stores/${store_id}/workflows/${params.id}`,
1413
+ options
1414
+ );
1415
+ },
1416
+ async getWorkflows(params, options) {
1417
+ const store_id = params?.store_id || apiConfig.storeId;
1418
+ const { store_id: _, ...queryParams } = params || {};
1419
+ return apiConfig.httpClient.get(`/v1/stores/${store_id}/workflows`, {
1420
+ ...options,
1421
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1422
+ });
1423
+ },
1424
+ async triggerWorkflow(params, options) {
1425
+ const { secret, ...payload } = params;
1426
+ return apiConfig.httpClient.post(`/v1/workflows/trigger/${secret}`, payload, options);
1427
+ },
1428
+ async getWorkflowExecutions(params, options) {
1429
+ const store_id = params.store_id || apiConfig.storeId;
1430
+ const { store_id: _, workflow_id, ...queryParams } = params;
1431
+ return apiConfig.httpClient.get(
1432
+ `/v1/stores/${store_id}/workflows/${workflow_id}/executions`,
1433
+ {
1434
+ ...options,
1435
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1436
+ }
1437
+ );
1438
+ },
1439
+ async getWorkflowExecution(params, options) {
1440
+ const store_id = params.store_id || apiConfig.storeId;
1441
+ return apiConfig.httpClient.get(
1442
+ `/v1/stores/${store_id}/workflows/${params.workflow_id}/executions/${params.execution_id}`,
1443
+ options
1444
+ );
1445
+ }
1446
+ };
1447
+ };
1448
+
1449
+ // src/api/platform.ts
1450
+ var createPlatformApi = (apiConfig) => {
1451
+ return {
1452
+ async getCurrencies(options) {
1453
+ return apiConfig.httpClient.get("/v1/platform/currencies", options);
1454
+ },
1455
+ async getIntegrationServices(options) {
1456
+ return apiConfig.httpClient.get("/v1/platform/integration-services", options);
1457
+ },
1458
+ async getWebhookEvents(options) {
1459
+ return apiConfig.httpClient.get("/v1/platform/events", options);
1460
+ }
1461
+ };
1462
+ };
1463
+
1464
+ // src/api/shipping.ts
1465
+ var createShippingApi = (apiConfig) => {
1466
+ return {
1467
+ async getRates(params, options) {
1468
+ const { order_id, ...payload } = params;
1469
+ return apiConfig.httpClient.post(
1470
+ `/v1/stores/${apiConfig.storeId}/orders/${order_id}/shipping/rates`,
1471
+ payload,
1472
+ options
1473
+ );
1474
+ },
1475
+ async ship(params, options) {
1476
+ const { order_id, ...payload } = params;
1477
+ return apiConfig.httpClient.post(
1478
+ `/v1/stores/${apiConfig.storeId}/orders/${order_id}/ship`,
1479
+ payload,
1480
+ options
1481
+ );
1482
+ }
1483
+ };
1484
+ };
1485
+
1486
+ // src/api/agent.ts
1487
+ var createAgentApi = (apiConfig) => {
1488
+ return {
1489
+ async createAgent(params, options) {
1490
+ const { store_id, ...payload } = params;
1491
+ const target_store_id = store_id || apiConfig.storeId;
1492
+ return apiConfig.httpClient.post(
1493
+ `/v1/stores/${target_store_id}/agents`,
1494
+ { ...payload, store_id: target_store_id },
1495
+ options
1496
+ );
1497
+ },
1498
+ async updateAgent(params, options) {
1499
+ const { store_id, id, ...payload } = params;
1500
+ const target_store_id = store_id || apiConfig.storeId;
1501
+ return apiConfig.httpClient.put(
1502
+ `/v1/stores/${target_store_id}/agents/${id}`,
1503
+ payload,
1504
+ options
1505
+ );
1506
+ },
1507
+ async deleteAgent(params, options) {
1508
+ const store_id = params.store_id || apiConfig.storeId;
1509
+ return apiConfig.httpClient.delete(
1510
+ `/v1/stores/${store_id}/agents/${params.id}`,
1511
+ options
1512
+ );
1513
+ },
1514
+ async getAgent(params, options) {
1515
+ const store_id = params.store_id || apiConfig.storeId;
1516
+ return apiConfig.httpClient.get(
1517
+ `/v1/stores/${store_id}/agents/${params.id}`,
1518
+ options
1519
+ );
1520
+ },
1521
+ async getAgents(params, options) {
1522
+ const store_id = params?.store_id || apiConfig.storeId;
1523
+ const { store_id: _, ...queryParams } = params || {};
1524
+ return apiConfig.httpClient.get(`/v1/stores/${store_id}/agents`, {
1525
+ ...options,
1526
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1527
+ });
1528
+ },
1529
+ async sendMessage(params, options) {
1530
+ const store_id = params.store_id || apiConfig.storeId;
1531
+ const body = { message: params.message };
1532
+ if (params.chat_id) body.chat_id = params.chat_id;
1533
+ if (params.direct) body.direct = params.direct;
1534
+ return apiConfig.httpClient.post(
1535
+ `/v1/stores/${store_id}/agents/${params.id}/chats/messages`,
1536
+ body,
1537
+ options
1538
+ );
1539
+ },
1540
+ async getChats(params, options) {
1541
+ const store_id = params.store_id || apiConfig.storeId;
1542
+ const queryParams = {};
1543
+ if (params.limit) queryParams.limit = String(params.limit);
1544
+ if (params.cursor) queryParams.cursor = params.cursor;
1545
+ return apiConfig.httpClient.get(
1546
+ `/v1/stores/${store_id}/agents/${params.id}/chats`,
1547
+ {
1548
+ ...options,
1549
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1550
+ }
1551
+ );
1552
+ },
1553
+ async getChat(params, options) {
1554
+ const store_id = params.store_id || apiConfig.storeId;
1555
+ return apiConfig.httpClient.get(
1556
+ `/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}`,
1557
+ options
1558
+ );
1559
+ },
1560
+ async updateChat(params, options) {
1561
+ const store_id = params.store_id || apiConfig.storeId;
1562
+ return apiConfig.httpClient.put(
1563
+ `/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}`,
1564
+ { status: params.status },
1565
+ options
1566
+ );
1567
+ },
1568
+ async rateChat(params, options) {
1569
+ const store_id = params.store_id || apiConfig.storeId;
1570
+ const body = { rating: params.rating };
1571
+ if (params.comment) body.comment = params.comment;
1572
+ return apiConfig.httpClient.post(
1573
+ `/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}/rate`,
1574
+ body,
1575
+ options
1576
+ );
1577
+ },
1578
+ async getStoreChats(params, options) {
1579
+ const store_id = params.store_id || apiConfig.storeId;
1580
+ const { store_id: _, ...queryParams } = params;
1581
+ return apiConfig.httpClient.get(`/v1/stores/${store_id}/chats`, {
1582
+ ...options,
1583
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1584
+ });
1585
+ },
1586
+ async getChatMessages(params, options) {
1587
+ const store_id = params.store_id || apiConfig.storeId;
1588
+ const queryParams = {};
1589
+ if (params.limit) queryParams.limit = String(params.limit);
1590
+ return apiConfig.httpClient.get(
1591
+ `/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}/messages`,
1592
+ {
1593
+ ...options,
1594
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1595
+ }
1596
+ );
1597
+ }
1598
+ };
1599
+ };
1600
+
1601
+ // src/api/emailTemplate.ts
1602
+ var createEmailTemplateApi = (apiConfig) => {
1603
+ return {
1604
+ async createEmailTemplate(params, options) {
1605
+ const { store_id, ...payload } = params;
1606
+ const target_store_id = store_id || apiConfig.storeId;
1607
+ return apiConfig.httpClient.post(
1608
+ `/v1/stores/${target_store_id}/email-templates`,
1609
+ payload,
1610
+ options
1611
+ );
1612
+ },
1613
+ async updateEmailTemplate(params, options) {
1614
+ const { store_id, ...payload } = params;
1615
+ const target_store_id = store_id || apiConfig.storeId;
1616
+ return apiConfig.httpClient.put(
1617
+ `/v1/stores/${target_store_id}/email-templates/${params.id}`,
1618
+ payload,
1619
+ options
1620
+ );
1621
+ },
1622
+ async deleteEmailTemplate(params, options) {
1623
+ const target_store_id = params.store_id || apiConfig.storeId;
1624
+ return apiConfig.httpClient.delete(
1625
+ `/v1/stores/${target_store_id}/email-templates/${params.id}`,
1626
+ options
1627
+ );
1628
+ },
1629
+ async getEmailTemplate(params, options) {
1630
+ const target_store_id = params.store_id || apiConfig.storeId;
1631
+ let identifier;
1632
+ if (params.id) {
1633
+ identifier = params.id;
1634
+ } else if (params.key) {
1635
+ identifier = `${target_store_id}:${params.key}`;
1636
+ } else {
1637
+ throw new Error("GetEmailTemplateParams requires id or key");
1638
+ }
1639
+ return apiConfig.httpClient.get(
1640
+ `/v1/stores/${target_store_id}/email-templates/${identifier}`,
1641
+ options
1642
+ );
1643
+ },
1644
+ async getEmailTemplates(params, options) {
1645
+ const { store_id, ...queryParams } = params;
1646
+ const target_store_id = store_id || apiConfig.storeId;
1647
+ return apiConfig.httpClient.get(
1648
+ `/v1/stores/${target_store_id}/email-templates`,
1649
+ {
1650
+ ...options,
1651
+ params: queryParams
1652
+ }
1653
+ );
1654
+ }
1655
+ };
1656
+ };
1657
+
1658
+ // src/api/form.ts
1659
+ var createFormApi = (apiConfig) => {
1660
+ return {
1661
+ async createForm(params, options) {
1662
+ const { store_id, ...payload } = params;
1663
+ const target_store_id = store_id || apiConfig.storeId;
1664
+ return apiConfig.httpClient.post(
1665
+ `/v1/stores/${target_store_id}/forms`,
1666
+ payload,
1667
+ options
1668
+ );
1669
+ },
1670
+ async updateForm(params, options) {
1671
+ const { store_id, ...payload } = params;
1672
+ const target_store_id = store_id || apiConfig.storeId;
1673
+ return apiConfig.httpClient.put(
1674
+ `/v1/stores/${target_store_id}/forms/${params.id}`,
1675
+ payload,
1676
+ options
1677
+ );
1678
+ },
1679
+ async deleteForm(params, options) {
1680
+ const target_store_id = params.store_id || apiConfig.storeId;
1681
+ return apiConfig.httpClient.delete(
1682
+ `/v1/stores/${target_store_id}/forms/${params.id}`,
1683
+ options
1684
+ );
1685
+ },
1686
+ async getForm(params, options) {
1687
+ const target_store_id = params.store_id || apiConfig.storeId;
1688
+ let identifier;
1689
+ if (params.id) {
1690
+ identifier = params.id;
1691
+ } else if (params.key) {
1692
+ identifier = `${target_store_id}:${params.key}`;
1693
+ } else {
1694
+ throw new Error("GetFormParams requires id or key");
1695
+ }
1696
+ return apiConfig.httpClient.get(
1697
+ `/v1/stores/${target_store_id}/forms/${identifier}`,
1698
+ options
1699
+ );
1700
+ },
1701
+ async getForms(params, options) {
1702
+ const { store_id, ...queryParams } = params;
1703
+ const target_store_id = store_id || apiConfig.storeId;
1704
+ return apiConfig.httpClient.get(
1705
+ `/v1/stores/${target_store_id}/forms`,
1706
+ {
1707
+ ...options,
1708
+ params: queryParams
1709
+ }
1710
+ );
1711
+ },
1712
+ async submit(params, options) {
1713
+ const { store_id, form_id, ...payload } = params;
1714
+ const target_store_id = store_id || apiConfig.storeId;
1715
+ return apiConfig.httpClient.post(
1716
+ `/v1/stores/${target_store_id}/forms/${form_id}/submissions`,
1717
+ { ...payload, form_id, store_id: target_store_id },
1718
+ options
1719
+ );
1720
+ },
1721
+ async getSubmissions(params, options) {
1722
+ const { store_id, form_id, ...queryParams } = params;
1723
+ const target_store_id = store_id || apiConfig.storeId;
1724
+ return apiConfig.httpClient.get(
1725
+ `/v1/stores/${target_store_id}/forms/${form_id}/submissions`,
1726
+ {
1727
+ ...options,
1728
+ params: { ...queryParams, form_id, store_id: target_store_id }
1729
+ }
1730
+ );
1731
+ },
1732
+ async getSubmission(params, options) {
1733
+ const target_store_id = params.store_id || apiConfig.storeId;
1734
+ return apiConfig.httpClient.get(
1735
+ `/v1/stores/${target_store_id}/forms/${params.form_id}/submissions/${params.id}`,
1736
+ options
1737
+ );
1738
+ },
1739
+ async updateSubmission(params, options) {
1740
+ const { store_id, form_id, id, ...payload } = params;
1741
+ const target_store_id = store_id || apiConfig.storeId;
1742
+ return apiConfig.httpClient.put(
1743
+ `/v1/stores/${target_store_id}/forms/${form_id}/submissions/${id}`,
1744
+ { ...payload, form_id, store_id: target_store_id, id },
1745
+ options
1746
+ );
1747
+ }
1748
+ };
1749
+ };
1750
+
1751
+ // src/api/taxonomy.ts
1752
+ var createTaxonomyApi = (apiConfig) => {
1753
+ return {
1754
+ async createTaxonomy(params, options) {
1755
+ const { store_id, ...payload } = params;
1756
+ const target_store_id = store_id || apiConfig.storeId;
1757
+ return apiConfig.httpClient.post(
1758
+ `/v1/stores/${target_store_id}/taxonomies`,
1759
+ payload,
1760
+ options
1761
+ );
1762
+ },
1763
+ async updateTaxonomy(params, options) {
1764
+ const { store_id, ...payload } = params;
1765
+ const target_store_id = store_id || apiConfig.storeId;
1766
+ return apiConfig.httpClient.put(
1767
+ `/v1/stores/${target_store_id}/taxonomies/${params.id}`,
1768
+ payload,
1769
+ options
1770
+ );
1771
+ },
1772
+ async deleteTaxonomy(params, options) {
1773
+ const target_store_id = params.store_id || apiConfig.storeId;
1774
+ return apiConfig.httpClient.delete(
1775
+ `/v1/stores/${target_store_id}/taxonomies/${params.id}`,
1776
+ options
1777
+ );
1778
+ },
1779
+ async getTaxonomy(params, options) {
1780
+ const target_store_id = params.store_id || apiConfig.storeId;
1781
+ let identifier;
1782
+ if (params.id) {
1783
+ identifier = params.id;
1784
+ } else if (params.key) {
1785
+ identifier = `${target_store_id}:${params.key}`;
1786
+ } else {
1787
+ throw new Error("GetTaxonomyParams requires id or key");
1788
+ }
1789
+ return apiConfig.httpClient.get(
1790
+ `/v1/stores/${target_store_id}/taxonomies/${identifier}`,
1791
+ options
1792
+ );
1793
+ },
1794
+ async getTaxonomies(params, options) {
1795
+ const { store_id, ...queryParams } = params;
1796
+ const target_store_id = store_id || apiConfig.storeId;
1797
+ return apiConfig.httpClient.get(
1798
+ `/v1/stores/${target_store_id}/taxonomies`,
1799
+ {
1800
+ ...options,
1801
+ params: queryParams
1802
+ }
1803
+ );
1804
+ },
1805
+ async getTaxonomyChildren(params, options) {
1806
+ const { id, store_id } = params;
1807
+ const target_store_id = store_id || apiConfig.storeId;
1808
+ return apiConfig.httpClient.get(
1809
+ `/v1/stores/${target_store_id}/taxonomies/${id}/children`,
1810
+ options
1811
+ );
1812
+ }
1813
+ };
1814
+ };
1815
+
1816
+ // src/api/analytics.ts
1817
+ var createAnalyticsApi = (apiConfig) => {
1818
+ return {
1819
+ async query(spec, options) {
1820
+ const store_id = options?.store_id || apiConfig.storeId;
1821
+ return apiConfig.httpClient.post(
1822
+ `/v1/stores/${store_id}/analytics/query`,
1823
+ spec,
1824
+ options
1825
+ );
1826
+ }
1827
+ };
1828
+ };
1829
+
1830
+ // src/utils/price.ts
1831
+ function formatCurrency(amount, currencyCode, locale = "en") {
1832
+ if (!currencyCode) return "";
1833
+ return new Intl.NumberFormat(locale, {
1834
+ style: "currency",
1835
+ currency: currencyCode.toUpperCase()
1836
+ }).format(amount);
1837
+ }
1838
+ function getMinorUnits(currency) {
1839
+ try {
1840
+ const formatter = new Intl.NumberFormat("en", {
1841
+ style: "currency",
1842
+ currency: currency.toUpperCase()
1843
+ });
1844
+ const parts = formatter.formatToParts(1.11);
1845
+ const fractionPart = parts.find((p) => p.type === "fraction");
1846
+ return fractionPart?.value.length ?? 2;
1847
+ } catch {
1848
+ return 2;
1849
+ }
1850
+ }
1851
+ function convertToMajor(minorAmount, currency) {
1852
+ const units = getMinorUnits(currency);
1853
+ return minorAmount / Math.pow(10, units);
1854
+ }
1855
+ function getCurrencySymbol(currency) {
1856
+ try {
1857
+ return new Intl.NumberFormat("en", {
1858
+ style: "currency",
1859
+ currency: currency.toUpperCase(),
1860
+ currencyDisplay: "narrowSymbol"
1861
+ }).formatToParts(0).find((p) => p.type === "currency")?.value || currency.toUpperCase();
1862
+ } catch {
1863
+ return currency.toUpperCase();
1864
+ }
1865
+ }
1866
+ function getCurrencyName(currency) {
1867
+ try {
1868
+ return new Intl.DisplayNames(["en"], { type: "currency" }).of(currency.toUpperCase()) || currency.toUpperCase();
1869
+ } catch {
1870
+ return currency.toUpperCase();
1871
+ }
1872
+ }
1873
+ function formatMinor(amountMinor, currency) {
1874
+ if (!currency) return "";
1875
+ return formatCurrency(convertToMajor(amountMinor, currency), currency);
1876
+ }
1877
+ function formatPayment(payment) {
1878
+ return formatMinor(payment.total, payment.currency);
1879
+ }
1880
+ function formatPrice(prices, marketId) {
1881
+ if (!prices || prices.length === 0) return "";
1882
+ const price = marketId ? prices.find((p) => p.market === marketId) || prices[0] : prices[0];
1883
+ if (!price) return "";
1884
+ return formatMinor(price.amount, price.currency);
1885
+ }
1886
+ function getPriceAmount(prices, marketId) {
1887
+ if (!prices || prices.length === 0) return 0;
1888
+ const price = prices.find((p) => p.market === marketId) || prices[0];
1889
+ return price?.amount || 0;
1890
+ }
1891
+
1892
+ // src/utils/validation.ts
1893
+ function validatePhoneNumber(phone) {
1894
+ if (!phone) {
1895
+ return { isValid: false, error: "Phone number is required" };
1896
+ }
1897
+ const cleaned = phone.replace(/\D/g, "");
1898
+ if (cleaned.length < 8) {
1899
+ return { isValid: false, error: "Phone number is too short" };
1900
+ }
1901
+ if (cleaned.length > 15) {
1902
+ return { isValid: false, error: "Phone number is too long" };
1903
+ }
1904
+ return { isValid: true };
1905
+ }
1906
+
1907
+ // src/utils/timezone.ts
1908
+ var tzGroups = [
1909
+ {
1910
+ label: "US",
1911
+ zones: [
1912
+ { label: "Eastern Time", value: "America/New_York" },
1913
+ { label: "Central Time", value: "America/Chicago" },
1914
+ { label: "Mountain Time", value: "America/Denver" },
1915
+ { label: "Pacific Time", value: "America/Los_Angeles" }
1916
+ ]
1917
+ },
1918
+ {
1919
+ label: "Europe",
1920
+ zones: [
1921
+ { label: "London", value: "Europe/London" },
1922
+ { label: "Paris", value: "Europe/Paris" },
1923
+ { label: "Berlin", value: "Europe/Berlin" },
1924
+ { label: "Rome", value: "Europe/Rome" }
1925
+ ]
1926
+ },
1927
+ {
1928
+ label: "Asia",
1929
+ zones: [
1930
+ { label: "Tokyo", value: "Asia/Tokyo" },
1931
+ { label: "Shanghai", value: "Asia/Shanghai" },
1932
+ { label: "Mumbai", value: "Asia/Kolkata" },
1933
+ { label: "Dubai", value: "Asia/Dubai" }
1934
+ ]
1935
+ }
1936
+ ];
1937
+ function findTimeZone(groups) {
1938
+ try {
1939
+ const detected = Intl.DateTimeFormat().resolvedOptions().timeZone;
1940
+ for (const group of groups) {
1941
+ for (const zone of group.zones) {
1942
+ if (zone.value === detected) {
1943
+ return detected;
1944
+ }
1945
+ }
1946
+ }
1947
+ return "UTC";
1948
+ } catch (e) {
1949
+ return "UTC";
1950
+ }
1951
+ }
1952
+
1953
+ // src/utils/text.ts
1954
+ var locales = ["en", "sr-latn"];
1955
+ var localeMap = {
1956
+ "en": "en-US",
1957
+ "sr-latn": "sr-RS"
1958
+ };
1959
+ function slugify(text) {
1960
+ return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1961
+ }
1962
+ function humanize(text) {
1963
+ const slugifiedText = slugify(text);
1964
+ return slugifiedText.replace(/-/g, " ").replace(
1965
+ /\w\S*/g,
1966
+ (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
1967
+ );
1968
+ }
1969
+ function categorify(text) {
1970
+ const slugifiedText = slugify(text);
1971
+ return slugifiedText.replace(/-/g, " ").toUpperCase();
1972
+ }
1973
+ function formatDate(date, locale) {
1974
+ let localeString = "en-US";
1975
+ if (locales.includes(locale)) {
1976
+ localeString = localeMap[locale];
1977
+ }
1978
+ return new Date(date).toLocaleDateString(localeString, {
1979
+ timeZone: "UTC",
1980
+ year: "numeric",
1981
+ month: "short",
1982
+ day: "numeric"
1983
+ });
1984
+ }
1985
+
1986
+ // src/utils/svg.ts
1987
+ async function fetchSvgContent(mediaObject) {
1988
+ if (!mediaObject) return null;
1989
+ const svgUrl = getImageUrl(mediaObject, false);
1990
+ try {
1991
+ const response = await fetch(svgUrl);
1992
+ if (!response.ok) {
1993
+ console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
1994
+ return null;
1995
+ }
1996
+ const svgContent = await response.text();
1997
+ return svgContent;
1998
+ } catch (error) {
1999
+ console.error("Error fetching SVG:", error);
2000
+ return null;
2001
+ }
2002
+ }
2003
+ async function getSvgContentForAstro(mediaObject) {
2004
+ try {
2005
+ const svgContent = await fetchSvgContent(mediaObject);
2006
+ return svgContent || "";
2007
+ } catch (error) {
2008
+ console.error("Error getting SVG content for Astro:", error);
2009
+ return "";
2010
+ }
2011
+ }
2012
+ async function injectSvgIntoElement(mediaObject, targetElement, className) {
2013
+ if (!targetElement) return;
2014
+ try {
2015
+ const svgContent = await fetchSvgContent(mediaObject);
2016
+ if (svgContent) {
2017
+ targetElement.innerHTML = svgContent;
2018
+ if (className) {
2019
+ const svgElement = targetElement.querySelector("svg");
2020
+ if (svgElement) {
2021
+ svgElement.classList.add(...className.split(" "));
2022
+ }
2023
+ }
2024
+ }
2025
+ } catch (error) {
2026
+ console.error("Error injecting SVG:", error);
2027
+ }
2028
+ }
2029
+
2030
+ // src/utils/keyValidation.ts
2031
+ var KEY_PATTERN = /^[a-zA-Z0-9_-]+$/;
2032
+ function isValidKey(key) {
2033
+ if (!key || key.length === 0) return false;
2034
+ return KEY_PATTERN.test(key);
2035
+ }
2036
+ function validateKey(key) {
2037
+ if (!key || key.length === 0) {
2038
+ return { valid: false, error: "Key is required" };
2039
+ }
2040
+ if (key.length > 255) {
2041
+ return { valid: false, error: "Key must be 255 characters or less" };
2042
+ }
2043
+ if (!KEY_PATTERN.test(key)) {
2044
+ return {
2045
+ valid: false,
2046
+ error: "Key can only contain letters, numbers, underscores (_) and hyphens (-)"
2047
+ };
2048
+ }
2049
+ return { valid: true };
2050
+ }
2051
+ function toKey(input) {
2052
+ if (!input) return "";
2053
+ return input.toLowerCase().trim().replace(/\s+/g, "_").replace(/[^a-z0-9_-]/g, "").replace(/^[-_]+|[-_]+$/g, "").replace(/[-_]{2,}/g, "_");
2054
+ }
2055
+ function nameToKey(name) {
2056
+ return toKey(name);
2057
+ }
2058
+
2059
+ // src/utils/inventory.ts
2060
+ function getAvailableStock(variant) {
2061
+ if (!variant?.inventory) return 0;
2062
+ return variant.inventory.reduce((sum, inv) => sum + inv.available, 0);
2063
+ }
2064
+ function getReservedStock(variant) {
2065
+ if (!variant?.inventory) return 0;
2066
+ return variant.inventory.reduce((sum, inv) => sum + inv.reserved, 0);
2067
+ }
2068
+ function hasStock(variant, quantity = 1) {
2069
+ return getAvailableStock(variant) >= quantity;
2070
+ }
2071
+ function getInventoryAt(variant, locationId) {
2072
+ return variant?.inventory?.find((inv) => inv.location_id === locationId);
2073
+ }
2074
+ function getFirstAvailableFCId(variant, quantity = 1) {
2075
+ const inv = variant?.inventory?.find((i) => i.available >= quantity);
2076
+ return inv?.location_id;
2077
+ }
2078
+
2079
+ // src/index.ts
2080
+ function createUtilitySurface(apiConfig) {
2081
+ return {
2082
+ getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock),
2083
+ getBlockValue,
2084
+ getBlockTextValue,
2085
+ getBlockValues,
2086
+ getBlockLabel,
2087
+ getBlockObjectValues,
2088
+ getBlockFromArray,
2089
+ formatBlockValue,
2090
+ prepareBlocksForSubmission,
2091
+ extractBlockValues,
2092
+ formatPrice: (prices) => formatPrice(prices, apiConfig.market),
2093
+ getPriceAmount: (prices) => getPriceAmount(prices, apiConfig.market),
2094
+ formatPayment,
2095
+ formatMinor,
2096
+ getCurrencySymbol,
2097
+ getCurrencyName,
2098
+ validatePhoneNumber,
2099
+ tzGroups,
2100
+ findTimeZone,
2101
+ slugify,
2102
+ humanize,
2103
+ categorify,
2104
+ formatDate,
2105
+ getSvgContentForAstro,
2106
+ fetchSvgContent,
2107
+ injectSvgIntoElement,
2108
+ isValidKey,
2109
+ validateKey,
2110
+ toKey,
2111
+ nameToKey,
2112
+ getAvailableStock,
2113
+ getReservedStock,
2114
+ hasStock,
2115
+ getInventoryAt,
2116
+ getFirstAvailableFCId
2117
+ };
2118
+ }
2119
+ function createAdmin(config) {
2120
+ const locale = config.locale || "en";
2121
+ const getToken = config.getToken || defaultGetToken;
2122
+ const setToken = config.setToken || defaultSetToken;
2123
+ const logout = config.logout || defaultLogout;
2124
+ const isAuthenticated = config.isAuthenticated || defaultIsAuthenticated;
2125
+ const httpClient = createHttpClient({ ...config, getToken, setToken, logout });
2126
+ const apiConfig = {
2127
+ httpClient,
2128
+ storeId: config.storeId,
2129
+ baseUrl: config.baseUrl,
2130
+ market: config.market,
2131
+ locale,
2132
+ setToken,
2133
+ getToken
2134
+ };
2135
+ const accountApi = createAccountApi(apiConfig);
2136
+ const authApi = createAuthApi(apiConfig);
2137
+ const storeApi = createStoreApi(apiConfig);
2138
+ const platformApi = createPlatformApi(apiConfig);
2139
+ const cmsApi = createCmsApi(apiConfig);
2140
+ const eshopApi = createEshopApi(apiConfig);
2141
+ const bookingApi = createBookingApi(apiConfig);
2142
+ const crmApi = createCustomerApi(apiConfig);
2143
+ const locationApi = createLocationApi(apiConfig);
2144
+ const marketApi = createMarketApi(apiConfig);
2145
+ const agentApi = createAgentApi(apiConfig);
2146
+ const workflowApi = createWorkflowApi(apiConfig);
2147
+ const formApi = createFormApi(apiConfig);
2148
+ const taxonomyApi = createTaxonomyApi(apiConfig);
2149
+ const emailTemplateApi = createEmailTemplateApi(apiConfig);
2150
+ const analyticsApi = createAnalyticsApi(apiConfig);
2151
+ const sdk = {
2152
+ auth: authApi,
2153
+ account: accountApi,
2154
+ store: {
2155
+ ...storeApi,
2156
+ location: locationApi,
2157
+ market: marketApi
2158
+ },
2159
+ media: createMediaApi(apiConfig),
2160
+ notification: createNotificationApi(apiConfig),
2161
+ promoCode: createPromoCodeApi(apiConfig),
2162
+ platform: platformApi,
2163
+ shipping: createShippingApi(apiConfig),
2164
+ cms: {
2165
+ node: {
2166
+ create: cmsApi.createNode,
2167
+ update: cmsApi.updateNode,
2168
+ delete: cmsApi.deleteNode,
2169
+ get: cmsApi.getNode,
2170
+ find: cmsApi.getNodes,
2171
+ getChildren: cmsApi.getNodeChildren
2172
+ },
2173
+ form: {
2174
+ create: formApi.createForm,
2175
+ update: formApi.updateForm,
2176
+ delete: formApi.deleteForm,
2177
+ get: formApi.getForm,
2178
+ find: formApi.getForms,
2179
+ submit: formApi.submit,
2180
+ getSubmissions: formApi.getSubmissions,
2181
+ getSubmission: formApi.getSubmission,
2182
+ updateSubmission: formApi.updateSubmission
2183
+ },
2184
+ taxonomy: {
2185
+ create: taxonomyApi.createTaxonomy,
2186
+ update: taxonomyApi.updateTaxonomy,
2187
+ delete: taxonomyApi.deleteTaxonomy,
2188
+ get: taxonomyApi.getTaxonomy,
2189
+ find: taxonomyApi.getTaxonomies,
2190
+ getChildren: taxonomyApi.getTaxonomyChildren
2191
+ },
2192
+ emailTemplate: {
2193
+ create: emailTemplateApi.createEmailTemplate,
2194
+ update: emailTemplateApi.updateEmailTemplate,
2195
+ delete: emailTemplateApi.deleteEmailTemplate,
2196
+ get: emailTemplateApi.getEmailTemplate,
2197
+ find: emailTemplateApi.getEmailTemplates
2198
+ }
2199
+ },
2200
+ eshop: {
2201
+ product: {
2202
+ create: eshopApi.createProduct,
2203
+ update: eshopApi.updateProduct,
2204
+ delete: eshopApi.deleteProduct,
2205
+ get: eshopApi.getProduct,
2206
+ find: eshopApi.getProducts
2207
+ },
2208
+ order: {
2209
+ create: eshopApi.createOrder,
2210
+ update: eshopApi.updateOrder,
2211
+ get: eshopApi.getOrder,
2212
+ find: eshopApi.getOrders,
2213
+ getQuote: eshopApi.getQuote,
2214
+ processRefund: eshopApi.processRefund
2215
+ }
2216
+ },
2217
+ booking: {
2218
+ addToCart: bookingApi.addToCart,
2219
+ removeFromCart: bookingApi.removeFromCart,
2220
+ getCart: bookingApi.getCart,
2221
+ clearCart: bookingApi.clearCart,
2222
+ create: bookingApi.createBooking,
2223
+ update: bookingApi.updateBooking,
2224
+ get: bookingApi.getBooking,
2225
+ find: bookingApi.searchBookings,
2226
+ getQuote: bookingApi.getQuote,
2227
+ processRefund: bookingApi.processRefund,
2228
+ getAvailability: bookingApi.getAvailability,
2229
+ cancelItem: bookingApi.cancelBookingItem,
2230
+ service: {
2231
+ create: bookingApi.createService,
2232
+ update: bookingApi.updateService,
2233
+ delete: bookingApi.deleteService,
2234
+ get: bookingApi.getService,
2235
+ find: bookingApi.getServices,
2236
+ findProviders: bookingApi.findServiceProviders,
2237
+ createProvider: bookingApi.createServiceProvider,
2238
+ updateProvider: bookingApi.updateServiceProvider,
2239
+ deleteProvider: bookingApi.deleteServiceProvider
2240
+ },
2241
+ provider: {
2242
+ create: bookingApi.createProvider,
2243
+ update: bookingApi.updateProvider,
2244
+ delete: bookingApi.deleteProvider,
2245
+ get: bookingApi.getProvider,
2246
+ find: bookingApi.getProviders
2247
+ }
2248
+ },
2249
+ crm: {
2250
+ customer: {
2251
+ create: crmApi.create,
2252
+ get: crmApi.get,
2253
+ find: crmApi.find,
2254
+ update: crmApi.update,
2255
+ merge: crmApi.merge,
2256
+ revokeToken: crmApi.revokeToken,
2257
+ revokeAllTokens: crmApi.revokeAllTokens
2258
+ },
2259
+ audience: {
2260
+ create: crmApi.audiences.create,
2261
+ update: crmApi.audiences.update,
2262
+ get: crmApi.audiences.get,
2263
+ find: crmApi.audiences.find,
2264
+ getSubscribers: crmApi.audiences.getSubscribers,
2265
+ addSubscriber: crmApi.audiences.addSubscriber,
2266
+ removeSubscriber: crmApi.audiences.removeSubscriber
2267
+ },
2268
+ activity: crmApi.activity
2269
+ },
2270
+ automation: {
2271
+ agent: {
2272
+ create: agentApi.createAgent,
2273
+ update: agentApi.updateAgent,
2274
+ delete: agentApi.deleteAgent,
2275
+ get: agentApi.getAgent,
2276
+ find: agentApi.getAgents,
2277
+ sendMessage: agentApi.sendMessage,
2278
+ getChats: agentApi.getChats,
2279
+ getChat: agentApi.getChat,
2280
+ updateChat: agentApi.updateChat,
2281
+ rateChat: agentApi.rateChat,
2282
+ getStoreChats: agentApi.getStoreChats,
2283
+ getChatMessages: agentApi.getChatMessages
2284
+ },
2285
+ workflow: {
2286
+ create: workflowApi.createWorkflow,
2287
+ update: workflowApi.updateWorkflow,
2288
+ delete: workflowApi.deleteWorkflow,
2289
+ get: workflowApi.getWorkflow,
2290
+ find: workflowApi.getWorkflows,
2291
+ trigger: workflowApi.triggerWorkflow,
2292
+ getExecutions: workflowApi.getWorkflowExecutions,
2293
+ getExecution: workflowApi.getWorkflowExecution
2294
+ }
2295
+ },
2296
+ analytics: {
2297
+ query: analyticsApi.query
2298
+ },
2299
+ setStoreId: (storeId) => {
2300
+ apiConfig.storeId = storeId;
2301
+ },
2302
+ getStoreId: () => apiConfig.storeId,
2303
+ setMarket: (market) => {
2304
+ apiConfig.market = market;
2305
+ },
2306
+ getMarket: () => apiConfig.market,
2307
+ setLocale: (locale2) => {
2308
+ apiConfig.locale = locale2;
2309
+ },
2310
+ getLocale: () => apiConfig.locale,
2311
+ isAuthenticated,
2312
+ logout,
2313
+ setToken,
2314
+ extractBlockValues,
2315
+ utils: createUtilitySurface(apiConfig)
2316
+ };
2317
+ return sdk;
2318
+ }
2319
+
2320
+ export { createAdmin };
2321
+ //# sourceMappingURL=admin.js.map
2322
+ //# sourceMappingURL=admin.js.map