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