arky-sdk 0.7.93 → 0.7.102

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