arky-sdk 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,864 +1,1020 @@
1
1
  'use strict';
2
2
 
3
- // src/types/index.ts
4
- var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
5
- PaymentMethod2["Cash"] = "CASH";
6
- PaymentMethod2["CreditCard"] = "CREDIT_CARD";
7
- PaymentMethod2["Free"] = "FREE";
8
- return PaymentMethod2;
9
- })(PaymentMethod || {});
3
+ // src/utils/errors.ts
4
+ var convertServerErrorToRequestError = (serverError, renameRules) => {
5
+ return {
6
+ ...serverError,
7
+ validationErrors: serverError.validationErrors.map((validationError) => {
8
+ const field = validationError.field;
9
+ return {
10
+ field,
11
+ error: validationError.error || "GENERAL.VALIDATION_ERROR"
12
+ };
13
+ })
14
+ };
15
+ };
10
16
 
11
- // src/api/cms.ts
12
- var createCmsApi = (apiConfig) => {
17
+ // src/utils/queryParams.ts
18
+ function buildQueryString(params) {
19
+ const queryParts = [];
20
+ Object.entries(params).forEach(([key, value]) => {
21
+ if (value === null || value === void 0) {
22
+ return;
23
+ }
24
+ if (Array.isArray(value)) {
25
+ const jsonString = JSON.stringify(value);
26
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
27
+ } else if (typeof value === "string") {
28
+ queryParts.push(`${key}=${encodeURIComponent(value)}`);
29
+ } else if (typeof value === "number" || typeof value === "boolean") {
30
+ queryParts.push(`${key}=${value}`);
31
+ } else if (typeof value === "object") {
32
+ const jsonString = JSON.stringify(value);
33
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
34
+ }
35
+ });
36
+ return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
37
+ }
38
+
39
+ // src/services/createHttpClient.ts
40
+ function createHttpClient(cfg) {
41
+ const refreshEndpoint = `${cfg.baseUrl}/v1/users/refresh-access-token`;
42
+ let refreshPromise = null;
43
+ async function ensureFreshToken() {
44
+ if (refreshPromise) {
45
+ return refreshPromise;
46
+ }
47
+ refreshPromise = (async () => {
48
+ const { refreshToken, provider } = await cfg.getToken();
49
+ if (!refreshToken) {
50
+ cfg.logout();
51
+ const err = new Error("No refresh token available");
52
+ err.name = "ApiError";
53
+ err.statusCode = 401;
54
+ throw err;
55
+ }
56
+ const refRes = await fetch(refreshEndpoint, {
57
+ method: "POST",
58
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
59
+ body: JSON.stringify({ provider, refreshToken })
60
+ });
61
+ if (!refRes.ok) {
62
+ cfg.logout();
63
+ const err = new Error("Token refresh failed");
64
+ err.name = "ApiError";
65
+ err.statusCode = 401;
66
+ throw err;
67
+ }
68
+ const data = await refRes.json();
69
+ cfg.setToken(data);
70
+ })().finally(() => {
71
+ refreshPromise = null;
72
+ });
73
+ return refreshPromise;
74
+ }
75
+ async function request(method, path, body, options) {
76
+ if (options?.transformRequest) {
77
+ body = options.transformRequest(body);
78
+ }
79
+ const headers = {
80
+ Accept: "application/json",
81
+ "Content-Type": "application/json",
82
+ ...options?.headers || {}
83
+ };
84
+ let { accessToken, expiresAt } = await cfg.getToken();
85
+ const nowSec = Date.now() / 1e3;
86
+ if (expiresAt && nowSec > expiresAt) {
87
+ await ensureFreshToken();
88
+ const tokens = await cfg.getToken();
89
+ accessToken = tokens.accessToken;
90
+ }
91
+ if (accessToken) {
92
+ headers["Authorization"] = `Bearer ${accessToken}`;
93
+ }
94
+ const finalPath = options?.params ? path + buildQueryString(options.params) : path;
95
+ const fetchOpts = { method, headers };
96
+ if (!["GET", "DELETE"].includes(method) && body !== void 0) {
97
+ fetchOpts.body = JSON.stringify(body);
98
+ }
99
+ const fullUrl = `${cfg.baseUrl}${finalPath}`;
100
+ let res;
101
+ let data;
102
+ try {
103
+ res = await fetch(fullUrl, fetchOpts);
104
+ } catch (error) {
105
+ const err = new Error(error instanceof Error ? error.message : "Network request failed");
106
+ err.name = "NetworkError";
107
+ err.method = method;
108
+ err.url = fullUrl;
109
+ throw err;
110
+ }
111
+ if (res.status === 401 && !options?.["_retried"]) {
112
+ try {
113
+ await ensureFreshToken();
114
+ const tokens = await cfg.getToken();
115
+ headers["Authorization"] = `Bearer ${tokens.accessToken}`;
116
+ fetchOpts.headers = headers;
117
+ return request(method, path, body, { ...options, _retried: true });
118
+ } catch (refreshError) {
119
+ }
120
+ }
121
+ try {
122
+ const contentLength = res.headers.get("content-length");
123
+ const contentType = res.headers.get("content-type");
124
+ if (res.status === 204 || contentLength === "0" || !contentType?.includes("application/json")) {
125
+ data = {};
126
+ } else {
127
+ data = await res.json();
128
+ }
129
+ } catch (error) {
130
+ const err = new Error("Failed to parse response");
131
+ err.name = "ParseError";
132
+ err.method = method;
133
+ err.url = fullUrl;
134
+ err.status = res.status;
135
+ throw err;
136
+ }
137
+ if (!res.ok) {
138
+ const serverErr = data;
139
+ const reqErr = convertServerErrorToRequestError(serverErr);
140
+ if (options?.errorMessage && cfg.notify) {
141
+ cfg.notify({ message: options.errorMessage, type: "error" });
142
+ }
143
+ const err = new Error(serverErr.message || "Request failed");
144
+ err.name = "ApiError";
145
+ err.statusCode = serverErr.statusCode || res.status;
146
+ err.validationErrors = reqErr.validationErrors;
147
+ err.method = method;
148
+ err.url = fullUrl;
149
+ const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
150
+ if (requestId) err.requestId = requestId;
151
+ throw err;
152
+ }
153
+ if (options?.successMessage && cfg.notify) {
154
+ cfg.notify({ message: options.successMessage, type: "success" });
155
+ }
156
+ return data;
157
+ }
13
158
  return {
14
- // ===== COLLECTIONS =====
15
- async createCollection(params, options) {
159
+ get: (path, opts) => request("GET", path, void 0, opts),
160
+ post: (path, body, opts) => request("POST", path, body, opts),
161
+ put: (path, body, opts) => request("PUT", path, body, opts),
162
+ patch: (path, body, opts) => request("PATCH", path, body, opts),
163
+ delete: (path, opts) => request("DELETE", path, void 0, opts)
164
+ };
165
+ }
166
+
167
+ // src/api/user.ts
168
+ var createUserApi = (apiConfig) => {
169
+ return {
170
+ // ===== USER PROFILE =====
171
+ async updateUser(params, options) {
172
+ const payload = {
173
+ name: params.name,
174
+ phoneNumbers: params.phoneNumbers || [],
175
+ phoneNumber: params.phoneNumber || null,
176
+ addresses: params.addresses || [],
177
+ ...params.apiTokens !== void 0 && { apiTokens: params.apiTokens }
178
+ };
179
+ return apiConfig.httpClient.put("/v1/users/update", payload, options);
180
+ },
181
+ async updateProfilePhone(params, options) {
182
+ const payload = {
183
+ phoneNumbers: [],
184
+ phoneNumber: params.phoneNumber,
185
+ addresses: []
186
+ };
187
+ return apiConfig.httpClient.put("/v1/users/update", payload, options);
188
+ },
189
+ async verifyPhoneCode(params, options) {
190
+ return apiConfig.httpClient.put("/v1/users/confirm/phone-number", params, options);
191
+ },
192
+ async getUserLocation(options) {
193
+ return apiConfig.httpClient.get("/v1/users/location", options);
194
+ },
195
+ async getMe(options) {
196
+ return apiConfig.httpClient.get("/v1/users/me", options);
197
+ },
198
+ async searchUsers(params, options) {
199
+ return apiConfig.httpClient.get("/v1/users/search", {
200
+ ...options,
201
+ params
202
+ });
203
+ },
204
+ async setUserRole(params, options) {
205
+ return apiConfig.httpClient.put("/v1/users/set-role", params, options);
206
+ },
207
+ // ===== AUTHENTICATION =====
208
+ async loginUser(params, options) {
209
+ return apiConfig.httpClient.post("/v1/users/login", params, options);
210
+ },
211
+ async registerUser(params, options) {
212
+ return apiConfig.httpClient.post("/v1/users/register", params, options);
213
+ },
214
+ async logout(options) {
215
+ return apiConfig.httpClient.post("/v1/users/logout", {}, options);
216
+ },
217
+ async confirmUser(params, options) {
218
+ return apiConfig.httpClient.put("/v1/users/confirm", params, options);
219
+ },
220
+ async getLoginUrl(params, options) {
221
+ return apiConfig.httpClient.get("/v1/users/login/url", {
222
+ ...options,
223
+ params
224
+ });
225
+ },
226
+ async getGuestToken(params, options) {
227
+ if (params.existingToken) {
228
+ return params.existingToken;
229
+ }
230
+ const result = await apiConfig.httpClient.post("/v1/users/login", {
231
+ provider: "GUEST"
232
+ }, options);
233
+ const token = result.accessToken || result.token || "";
234
+ if (token) {
235
+ apiConfig.setTokens(result);
236
+ }
237
+ return token;
238
+ },
239
+ // ===== PASSWORD MANAGEMENT =====
240
+ async forgotPassword(params, options) {
241
+ return apiConfig.httpClient.post("/v1/users/forgot-password", params, options);
242
+ },
243
+ async resetForgotPassword(params, options) {
244
+ return apiConfig.httpClient.post("/v1/users/reset-forgot-password", params, options);
245
+ },
246
+ async resetPassword(params, options) {
247
+ return apiConfig.httpClient.post("/v1/users/reset-password", params, options);
248
+ }
249
+ };
250
+ };
251
+
252
+ // src/api/business.ts
253
+ var createBusinessApi = (apiConfig) => {
254
+ return {
255
+ async createBusiness(params, options) {
256
+ return apiConfig.httpClient.post(`/v1/businesses`, params, options);
257
+ },
258
+ async updateBusiness(params, options) {
259
+ return apiConfig.httpClient.put(`/v1/businesses/${params.id}`, params, options);
260
+ },
261
+ async deleteBusiness(params, options) {
262
+ return apiConfig.httpClient.delete(`/v1/businesses/${params.id}`, options);
263
+ },
264
+ async getBusiness(params, options) {
265
+ return apiConfig.httpClient.get(`/v1/businesses/${params.id}`, options);
266
+ },
267
+ async getBusinesses(options) {
268
+ return apiConfig.httpClient.get(`/v1/businesses`, options);
269
+ },
270
+ async getBusinessParents(params, options) {
271
+ return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/parents`, options);
272
+ },
273
+ async triggerBuilds(params, options) {
274
+ return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
275
+ },
276
+ async getSubscriptionPlans(options) {
277
+ return apiConfig.httpClient.get("/v1/businesses/plans", options);
278
+ },
279
+ async getSubscription(params, options) {
280
+ return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/subscription`, options);
281
+ },
282
+ async createSubscription(params, options) {
16
283
  return apiConfig.httpClient.post(
17
- `/v1/businesses/${apiConfig.businessId}/collections`,
284
+ `/v1/businesses/${params.businessId}/subscription`,
285
+ params,
286
+ options
287
+ );
288
+ },
289
+ async updateSubscription(params, options) {
290
+ return apiConfig.httpClient.put(
291
+ `/v1/businesses/${params.businessId}/subscription`,
18
292
  params,
19
293
  options
20
294
  );
21
295
  },
22
- async updateCollection(params, options) {
23
- return apiConfig.httpClient.put(
24
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
296
+ async cancelSubscription(params, options) {
297
+ return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
298
+ ...options,
299
+ params: { immediately: params.immediately || false }
300
+ });
301
+ },
302
+ async reactivateSubscription(params, options) {
303
+ return apiConfig.httpClient.post(
304
+ `/v1/businesses/${params.businessId}/subscription/reactivate`,
25
305
  params,
26
306
  options
27
307
  );
28
308
  },
29
- async deleteCollection(params, options) {
30
- return apiConfig.httpClient.delete(
31
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
309
+ async createPortalSession(params, options) {
310
+ return apiConfig.httpClient.post(
311
+ `/v1/businesses/${params.businessId}/subscription/portal`,
312
+ params,
32
313
  options
33
314
  );
34
315
  },
35
- async getCollection(params, options) {
36
- return apiConfig.httpClient.get(
37
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
316
+ async inviteUser(params, options) {
317
+ const { businessId, ...payload } = params;
318
+ return apiConfig.httpClient.post(
319
+ `/v1/businesses/${businessId}/invitation`,
320
+ payload,
38
321
  options
39
322
  );
40
323
  },
41
- async getCollections(params, options) {
42
- return apiConfig.httpClient.get(
43
- `/v1/businesses/${apiConfig.businessId}/collections`,
44
- {
45
- ...options,
46
- params: params || {}
47
- }
324
+ async handleInvitation(params, options) {
325
+ const { businessId, ...payload } = params;
326
+ return apiConfig.httpClient.put(
327
+ `/v1/businesses/${businessId}/invitation`,
328
+ payload,
329
+ options
48
330
  );
49
331
  },
50
- async generateBlocks(params, options) {
332
+ async testWebhook(params, options) {
51
333
  return apiConfig.httpClient.post(
52
- `/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
53
- params,
334
+ `/v1/businesses/${params.businessId}/webhooks/test`,
335
+ params.webhook,
54
336
  options
55
337
  );
56
338
  },
57
- // ===== ENTRIES =====
58
- // Note: Backend uses /entries NOT /collections/{id}/entries
59
- async getCollectionEntries(params, options) {
60
- const { collectionId, ...queryParams } = params || {};
61
- const finalParams = collectionId ? { ...queryParams, owner: `collection:${collectionId}` } : queryParams;
339
+ async getBusinessMedia(params, options) {
62
340
  return apiConfig.httpClient.get(
63
- `/v1/businesses/${apiConfig.businessId}/entries`,
341
+ `/v1/businesses/${params.id}/media`,
64
342
  {
65
343
  ...options,
66
- params: finalParams
344
+ params: {
345
+ cursor: params.cursor,
346
+ limit: params.limit || 20
347
+ }
67
348
  }
68
349
  );
69
350
  },
70
- async createCollectionEntry(params, options) {
71
- const { collectionId, owner, ...rest } = params;
72
- const payload = {
73
- ...rest,
74
- owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
75
- };
76
- return apiConfig.httpClient.post(
77
- `/v1/businesses/${apiConfig.businessId}/entries`,
78
- payload,
79
- options
80
- );
81
- },
82
- async updateCollectionEntry(params, options) {
83
- const { id, collectionId, owner, ...rest } = params;
84
- const payload = {
85
- ...rest,
86
- owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
87
- };
351
+ async setProviderSchedule(params, options) {
352
+ const { id, ...payload } = params;
88
353
  return apiConfig.httpClient.put(
89
- `/v1/businesses/${apiConfig.businessId}/entries/${id}`,
354
+ `/v1/businesses/${id}/schedules`,
90
355
  payload,
91
356
  options
92
357
  );
358
+ }
359
+ };
360
+ };
361
+
362
+ // src/api/media.ts
363
+ var createMediaApi = (apiConfig) => {
364
+ return {
365
+ async uploadBusinessMedia(params) {
366
+ const { businessId, files = [], urls = [] } = params;
367
+ const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/upload`;
368
+ const formData = new FormData();
369
+ files.forEach((file) => formData.append("files", file));
370
+ urls.forEach((url2) => formData.append("files", url2));
371
+ const tokens = await apiConfig.getTokens();
372
+ const response = await fetch(url, {
373
+ method: "POST",
374
+ body: formData,
375
+ headers: {
376
+ Authorization: `Bearer ${tokens.accessToken}`
377
+ }
378
+ });
379
+ if (!response.ok) {
380
+ throw new Error("Upload failed, server said no");
381
+ }
382
+ return await response.json();
93
383
  },
94
- async deleteCollectionEntry(params, options) {
384
+ async deleteBusinessMedia(params, options) {
385
+ const { id, mediaId } = params;
95
386
  return apiConfig.httpClient.delete(
96
- `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
97
- options
387
+ `/v1/businesses/${id}/upload`,
388
+ {
389
+ ...options,
390
+ params: { mediaId }
391
+ }
98
392
  );
99
393
  },
100
- async getCollectionEntry(params, options) {
101
- return apiConfig.httpClient.get(
102
- `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
103
- options
104
- );
394
+ async getBusinessMedia(params) {
395
+ const { businessId, cursor = null, limit = 20 } = params;
396
+ const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/media`;
397
+ const queryParams = { limit };
398
+ if (cursor) queryParams.cursor = cursor;
399
+ const queryString = new URLSearchParams(queryParams).toString();
400
+ const response = await fetch(`${url}?${queryString}`);
401
+ if (!response.ok) {
402
+ const errorData = await response.json().catch(() => null);
403
+ throw new Error(errorData?.message || "Failed to fetch media");
404
+ }
405
+ return await response.json();
406
+ }
407
+ };
408
+ };
409
+
410
+ // src/api/role.ts
411
+ var createRoleApi = (apiConfig) => {
412
+ return {
413
+ async createRole(params, options) {
414
+ return apiConfig.httpClient.post(`/v1/roles`, params, options);
105
415
  },
106
- async sendEntry(params, options) {
107
- const { entryId, scheduledAt } = params;
108
- return apiConfig.httpClient.post(
109
- `/v1/businesses/${apiConfig.businessId}/entries/${entryId}/send`,
110
- {
416
+ async updateRole(params, options) {
417
+ return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, options);
418
+ },
419
+ async deleteRole(params, options) {
420
+ return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
421
+ },
422
+ async getRole(params, options) {
423
+ return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
424
+ },
425
+ async getRoles(params, options) {
426
+ return apiConfig.httpClient.get(`/v1/roles`, {
427
+ ...options,
428
+ params: params ? {
111
429
  businessId: apiConfig.businessId,
112
- entryId,
113
- scheduledAt: scheduledAt || Date.now()
114
- },
430
+ action: params.action || "READ"
431
+ } : {
432
+ businessId: apiConfig.businessId,
433
+ action: "READ"
434
+ }
435
+ });
436
+ }
437
+ };
438
+ };
439
+
440
+ // src/api/notification.ts
441
+ var createNotificationApi = (apiConfig) => {
442
+ return {
443
+ async getNotifications(params, options) {
444
+ return apiConfig.httpClient.get(`/v1/notifications`, {
445
+ ...options,
446
+ params: {
447
+ limit: params.limit,
448
+ previous_id: params.previous_id
449
+ }
450
+ });
451
+ },
452
+ async updateNotifications(options) {
453
+ return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
454
+ },
455
+ async trackEmailOpen(params, options) {
456
+ return apiConfig.httpClient.get(
457
+ `/v1/notifications/track/email/${params.trackingPixelId}`,
115
458
  options
116
459
  );
117
460
  },
118
- // ===== VARIABLES / METADATA =====
119
- async getVariableMetadata(params, options) {
461
+ async getDeliveryStats(params, options) {
120
462
  return apiConfig.httpClient.get(
121
- `/v1/collections/entry-types/${params.entryType}/variables`,
463
+ `/v1/notifications/track/stats/${apiConfig.businessId}`,
122
464
  options
123
465
  );
124
466
  }
125
467
  };
126
468
  };
127
469
 
128
- // src/api/eshop.ts
129
- var createEshopApi = (apiConfig) => {
470
+ // src/api/promoCode.ts
471
+ var createPromoCodeApi = (apiConfig) => {
130
472
  return {
131
- // ===== PRODUCTS =====
132
- async createProduct(params, options) {
473
+ async createPromoCode(params, options) {
133
474
  return apiConfig.httpClient.post(
134
- `/v1/businesses/${apiConfig.businessId}/products`,
475
+ `/v1/businesses/${apiConfig.businessId}/promo-codes`,
135
476
  params,
136
477
  options
137
478
  );
138
479
  },
139
- async updateProduct(params, options) {
480
+ async updatePromoCode(params, options) {
140
481
  return apiConfig.httpClient.put(
141
- `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
482
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
142
483
  params,
143
484
  options
144
485
  );
145
486
  },
146
- async deleteProduct(id, options) {
487
+ async deletePromoCode(params, options) {
147
488
  return apiConfig.httpClient.delete(
148
- `/v1/businesses/${apiConfig.businessId}/products/${id}`,
489
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
149
490
  options
150
491
  );
151
492
  },
152
- async getProduct(params, options) {
493
+ async getPromoCode(params, options) {
153
494
  return apiConfig.httpClient.get(
154
- `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
495
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
155
496
  options
156
497
  );
157
498
  },
158
- async getProducts(params, options) {
159
- const queryParams = params ? { ...params } : {};
160
- return apiConfig.httpClient.get(
161
- `/v1/businesses/${encodeURIComponent(apiConfig.businessId)}/products`,
162
- {
163
- ...options,
164
- params: queryParams
499
+ async getPromoCodes(params, options) {
500
+ const { businessId, statuses, ...restParams } = params;
501
+ return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/promo-codes`, {
502
+ ...options,
503
+ params: {
504
+ ...restParams,
505
+ statuses: statuses && statuses.length > 0 ? statuses : void 0
165
506
  }
166
- );
507
+ });
508
+ }
509
+ };
510
+ };
511
+
512
+ // src/api/analytics.ts
513
+ var createAnalyticsApi = (apiConfig) => {
514
+ return {
515
+ async getAnalytics(params, options) {
516
+ const { businessId, ...queryParams } = params;
517
+ return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}`, {
518
+ ...options,
519
+ params: queryParams
520
+ });
167
521
  },
168
- // ===== ORDERS =====
169
- async createOrder(params, options) {
522
+ async getAnalyticsHealth(params, options) {
523
+ return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}/health`, options);
524
+ },
525
+ async setupAnalytics(params, options) {
526
+ return apiConfig.httpClient.post(`/v1/analytics/admin/setup`, params, options);
527
+ }
528
+ };
529
+ };
530
+
531
+ // src/api/cms.ts
532
+ var createCmsApi = (apiConfig) => {
533
+ return {
534
+ // ===== COLLECTIONS =====
535
+ async createCollection(params, options) {
170
536
  return apiConfig.httpClient.post(
171
- `/v1/businesses/${apiConfig.businessId}/orders`,
537
+ `/v1/businesses/${apiConfig.businessId}/collections`,
172
538
  params,
173
539
  options
174
540
  );
175
541
  },
176
- async updateOrder(params, options) {
542
+ async updateCollection(params, options) {
177
543
  return apiConfig.httpClient.put(
178
- `/v1/businesses/${apiConfig.businessId}/orders/update`,
544
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
179
545
  params,
180
546
  options
181
547
  );
182
548
  },
183
- async getOrder(params, options) {
549
+ async deleteCollection(params, options) {
550
+ return apiConfig.httpClient.delete(
551
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
552
+ options
553
+ );
554
+ },
555
+ async getCollection(params, options) {
184
556
  return apiConfig.httpClient.get(
185
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
557
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
186
558
  options
187
559
  );
188
560
  },
189
- async getOrders(params, options) {
561
+ async getCollections(params, options) {
190
562
  return apiConfig.httpClient.get(
191
- `/v1/businesses/${apiConfig.businessId}/orders`,
563
+ `/v1/businesses/${apiConfig.businessId}/collections`,
192
564
  {
193
565
  ...options,
194
566
  params: params || {}
195
567
  }
196
568
  );
197
569
  },
198
- async updateOrderStatus(params, options) {
199
- return apiConfig.httpClient.put(
200
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
570
+ async generateBlocks(params, options) {
571
+ return apiConfig.httpClient.post(
572
+ `/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
201
573
  params,
202
574
  options
203
575
  );
204
576
  },
205
- async updateOrderPaymentStatus(params, options) {
206
- return apiConfig.httpClient.put(
207
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/payment-status`,
208
- params,
209
- options
577
+ // ===== ENTRIES =====
578
+ // Note: Backend uses /entries NOT /collections/{id}/entries
579
+ async getCollectionEntries(params, options) {
580
+ const { collectionId, ...queryParams } = params || {};
581
+ const finalParams = collectionId ? { ...queryParams, owner: `collection:${collectionId}` } : queryParams;
582
+ return apiConfig.httpClient.get(
583
+ `/v1/businesses/${apiConfig.businessId}/entries`,
584
+ {
585
+ ...options,
586
+ params: finalParams
587
+ }
210
588
  );
211
589
  },
212
- // ===== PAYMENTS =====
213
- async getQuote(params, options) {
214
- const lines = params.items.map((item) => ({
215
- type: "PRODUCT_VARIANT",
216
- productId: item.productId,
217
- variantId: item.variantId,
218
- quantity: item.quantity
219
- }));
220
- const payload = {
221
- businessId: apiConfig.businessId,
222
- market: apiConfig.market,
223
- currency: params.currency,
224
- paymentMethod: params.paymentMethod,
225
- lines,
226
- ...params.shippingMethodId && { shippingMethodId: params.shippingMethodId },
227
- ...params.promoCode && { promoCode: params.promoCode }
228
- };
229
- return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
230
- },
231
- async checkout(params, options) {
590
+ async createCollectionEntry(params, options) {
591
+ const { collectionId, owner, ...rest } = params;
232
592
  const payload = {
233
- businessId: apiConfig.businessId,
234
- market: apiConfig.market,
235
- paymentMethod: params.paymentMethod,
236
- shippingMethodId: params.shippingMethodId,
237
- items: params.items,
238
- blocks: params.blocks || [],
239
- ...params.promoCode && { promoCode: params.promoCode }
593
+ ...rest,
594
+ owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
240
595
  };
241
596
  return apiConfig.httpClient.post(
242
- `/v1/businesses/${apiConfig.businessId}/orders/checkout`,
597
+ `/v1/businesses/${apiConfig.businessId}/entries`,
243
598
  payload,
244
599
  options
245
600
  );
246
- }
247
- };
248
- };
249
-
250
- // src/api/reservation.ts
251
- var createReservationApi = (apiConfig) => {
252
- return {
253
- // ===== RESERVATIONS =====
254
- async createReservation(params, options) {
255
- return apiConfig.httpClient.post(`/v1/reservations`, params, {
256
- successMessage: "Reservation created successfully",
257
- errorMessage: "Failed to create reservation",
258
- ...options
259
- });
260
- },
261
- async updateReservation(params, options) {
262
- const { id, ...payload } = params;
263
- return apiConfig.httpClient.put(`/v1/reservations/${id}`, payload, {
264
- successMessage: "Reservation updated successfully",
265
- errorMessage: "Failed to update reservation",
266
- ...options
267
- });
268
- },
269
- async checkout(params, options) {
270
- const payload = {
271
- businessId: apiConfig.businessId,
272
- market: apiConfig.market,
273
- blocks: params.blocks || [],
274
- parts: params.parts,
275
- ...params.paymentMethod && { paymentMethod: params.paymentMethod },
276
- ...params.promoCode && { promoCode: params.promoCode }
277
- };
278
- return apiConfig.httpClient.post(`/v1/reservations/checkout`, payload, {
279
- successMessage: "Reservation checkout completed",
280
- errorMessage: "Failed to complete checkout",
281
- ...options
282
- });
283
- },
284
- async getReservation(params, options) {
285
- return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
286
- ...options,
287
- params: params.businessId ? { businessId: params.businessId } : {}
288
- });
289
601
  },
290
- async getReservationParts(params, options) {
291
- return apiConfig.httpClient.get(`/v1/reservations/parts`, {
292
- ...options,
293
- params: params || {}
294
- });
295
- },
296
- async searchReservations(params, options) {
297
- return apiConfig.httpClient.get(`/v1/reservations/search`, {
298
- ...options,
299
- params
300
- });
301
- },
302
- async searchMyReservations(params, options) {
303
- return apiConfig.httpClient.get(`/v1/reservations`, {
304
- ...options,
305
- params: params || {}
306
- });
307
- },
308
- // ===== QUOTES =====
309
- async getQuote(params, options) {
310
- const lines = params.parts.map((part) => ({
311
- type: "SERVICE",
312
- serviceId: part.serviceId,
313
- quantity: 1
314
- }));
602
+ async updateCollectionEntry(params, options) {
603
+ const { id, collectionId, owner, ...rest } = params;
315
604
  const payload = {
316
- businessId: apiConfig.businessId,
317
- market: apiConfig.market,
318
- currency: params.currency,
319
- paymentMethod: params.paymentMethod,
320
- lines,
321
- ...params.promoCode && { promoCode: params.promoCode }
605
+ ...rest,
606
+ owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
322
607
  };
323
- return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
324
- },
325
- // ===== SERVICES =====
326
- async createService(params, options) {
327
- return apiConfig.httpClient.post(
328
- `/v1/businesses/${apiConfig.businessId}/services`,
329
- params,
330
- {
331
- successMessage: "Service created successfully",
332
- errorMessage: "Failed to create service",
333
- ...options
334
- }
335
- );
336
- },
337
- async updateService(params, options) {
338
608
  return apiConfig.httpClient.put(
339
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
340
- params,
341
- {
342
- successMessage: "Service updated successfully",
343
- errorMessage: "Failed to update service",
344
- ...options
345
- }
609
+ `/v1/businesses/${apiConfig.businessId}/entries/${id}`,
610
+ payload,
611
+ options
346
612
  );
347
613
  },
348
- async deleteService(params, options) {
614
+ async deleteCollectionEntry(params, options) {
349
615
  return apiConfig.httpClient.delete(
350
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
351
- {
352
- successMessage: "Service deleted successfully",
353
- errorMessage: "Failed to delete service",
354
- ...options
355
- }
616
+ `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
617
+ options
356
618
  );
357
619
  },
358
- async getService(params, options) {
620
+ async getCollectionEntry(params, options) {
359
621
  return apiConfig.httpClient.get(
360
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
622
+ `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
361
623
  options
362
624
  );
363
625
  },
364
- async getServices(params, options) {
365
- const queryParams = params ? { ...params } : {};
366
- return apiConfig.httpClient.get(
367
- `/v1/businesses/${apiConfig.businessId}/services`,
626
+ async sendEntry(params, options) {
627
+ const { entryId, scheduledAt } = params;
628
+ return apiConfig.httpClient.post(
629
+ `/v1/businesses/${apiConfig.businessId}/entries/${entryId}/send`,
368
630
  {
369
- ...options,
370
- params: queryParams
371
- }
631
+ businessId: apiConfig.businessId,
632
+ entryId,
633
+ scheduledAt: scheduledAt || Date.now()
634
+ },
635
+ options
372
636
  );
373
637
  },
374
- async getAvailableSlots(params, options) {
375
- const { serviceId, ...queryParams } = params;
638
+ // ===== VARIABLES / METADATA =====
639
+ async getVariableMetadata(params, options) {
376
640
  return apiConfig.httpClient.get(
377
- `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
378
- {
379
- ...options,
380
- params: {
381
- ...queryParams,
382
- limit: queryParams.limit || 1e3
383
- }
384
- }
641
+ `/v1/collections/entry-types/${params.entryType}/variables`,
642
+ options
385
643
  );
386
- },
387
- // ===== PROVIDERS =====
388
- async createProvider(params, options) {
644
+ }
645
+ };
646
+ };
647
+
648
+ // src/api/eshop.ts
649
+ var createEshopApi = (apiConfig) => {
650
+ return {
651
+ // ===== PRODUCTS =====
652
+ async createProduct(params, options) {
389
653
  return apiConfig.httpClient.post(
390
- `/v1/businesses/${apiConfig.businessId}/providers`,
654
+ `/v1/businesses/${apiConfig.businessId}/products`,
391
655
  params,
392
- {
393
- successMessage: "Provider created successfully",
394
- errorMessage: "Failed to create provider",
395
- ...options
396
- }
656
+ options
397
657
  );
398
658
  },
399
- async updateProvider(params, options) {
659
+ async updateProduct(params, options) {
400
660
  return apiConfig.httpClient.put(
401
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
661
+ `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
402
662
  params,
403
- {
404
- successMessage: "Provider updated successfully",
405
- errorMessage: "Failed to update provider",
406
- ...options
407
- }
663
+ options
408
664
  );
409
665
  },
410
- async deleteProvider(params, options) {
666
+ async deleteProduct(id, options) {
411
667
  return apiConfig.httpClient.delete(
412
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
413
- {
414
- successMessage: "Provider deleted successfully",
415
- errorMessage: "Failed to delete provider",
416
- ...options
417
- }
668
+ `/v1/businesses/${apiConfig.businessId}/products/${id}`,
669
+ options
418
670
  );
419
671
  },
420
- async getProvider(params, options) {
672
+ async getProduct(params, options) {
421
673
  return apiConfig.httpClient.get(
422
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
674
+ `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
423
675
  options
424
676
  );
425
677
  },
426
- async getProviders(params, options) {
427
- const { businessId, ...queryParams } = params;
678
+ async getProducts(params, options) {
679
+ const queryParams = params ? { ...params } : {};
428
680
  return apiConfig.httpClient.get(
429
- `/v1/businesses/${apiConfig.businessId}/providers`,
681
+ `/v1/businesses/${encodeURIComponent(apiConfig.businessId)}/products`,
430
682
  {
431
683
  ...options,
432
684
  params: queryParams
433
685
  }
434
686
  );
435
687
  },
436
- async getProviderWorkingTime(params, options) {
437
- const { businessId, providerId, ...queryParams } = params;
688
+ // ===== ORDERS =====
689
+ async createOrder(params, options) {
690
+ return apiConfig.httpClient.post(
691
+ `/v1/businesses/${apiConfig.businessId}/orders`,
692
+ params,
693
+ options
694
+ );
695
+ },
696
+ async updateOrder(params, options) {
697
+ return apiConfig.httpClient.put(
698
+ `/v1/businesses/${apiConfig.businessId}/orders/update`,
699
+ params,
700
+ options
701
+ );
702
+ },
703
+ async getOrder(params, options) {
438
704
  return apiConfig.httpClient.get(
439
- `/v1/businesses/${apiConfig.businessId}/providers/${providerId}/working-time`,
705
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
706
+ options
707
+ );
708
+ },
709
+ async getOrders(params, options) {
710
+ return apiConfig.httpClient.get(
711
+ `/v1/businesses/${apiConfig.businessId}/orders`,
440
712
  {
441
713
  ...options,
442
- params: queryParams
714
+ params: params || {}
443
715
  }
444
716
  );
445
- }
446
- };
447
- };
448
-
449
- // src/api/newsletter.ts
450
- var createNewsletterApi = (apiConfig) => {
451
- return {
452
- // ===== NEWSLETTERS =====
453
- async find(params, options) {
454
- return apiConfig.httpClient.get(`/v1/newsletters`, {
455
- ...options,
456
- params: { businessId: params.businessId }
457
- });
458
- },
459
- async get(params, options) {
460
- return apiConfig.httpClient.get(`/v1/newsletters/${params.id}`, options);
461
- },
462
- async create(params, options) {
463
- return apiConfig.httpClient.post(`/v1/newsletters`, params, options);
464
717
  },
465
- async update(params, options) {
466
- return apiConfig.httpClient.put(`/v1/newsletters/${params.id}`, params, options);
718
+ async updateOrderStatus(params, options) {
719
+ return apiConfig.httpClient.put(
720
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
721
+ params,
722
+ options
723
+ );
467
724
  },
468
- async delete(params, options) {
469
- return apiConfig.httpClient.delete(`/v1/newsletters/${params.id}`, options);
725
+ async updateOrderPaymentStatus(params, options) {
726
+ return apiConfig.httpClient.put(
727
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/payment-status`,
728
+ params,
729
+ options
730
+ );
470
731
  },
471
- // ===== SUBSCRIBERS =====
472
- async getSubscribers(params, options) {
473
- return apiConfig.httpClient.get(`/v1/newsletters/${params.id}/subscribers`, options);
732
+ // ===== PAYMENTS =====
733
+ async getQuote(params, options) {
734
+ const lines = params.items.map((item) => ({
735
+ type: "PRODUCT_VARIANT",
736
+ productId: item.productId,
737
+ variantId: item.variantId,
738
+ quantity: item.quantity
739
+ }));
740
+ const payload = {
741
+ businessId: apiConfig.businessId,
742
+ market: apiConfig.market,
743
+ currency: params.currency,
744
+ paymentMethod: params.paymentMethod,
745
+ lines,
746
+ ...params.shippingMethodId && { shippingMethodId: params.shippingMethodId },
747
+ ...params.promoCode && { promoCode: params.promoCode }
748
+ };
749
+ return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
474
750
  },
475
- async subscribe(params, options) {
476
- const { newsletterId, email, customerId, payment } = params;
751
+ async checkout(params, options) {
477
752
  const payload = {
478
- newsletterId,
479
- email,
753
+ businessId: apiConfig.businessId,
480
754
  market: apiConfig.market,
481
- ...customerId && { customerId },
482
- ...payment && { payment }
755
+ paymentMethod: params.paymentMethod,
756
+ shippingMethodId: params.shippingMethodId,
757
+ items: params.items,
758
+ blocks: params.blocks || [],
759
+ ...params.promoCode && { promoCode: params.promoCode }
483
760
  };
484
761
  return apiConfig.httpClient.post(
485
- `/v1/newsletters/${newsletterId}/subscribe`,
762
+ `/v1/businesses/${apiConfig.businessId}/orders/checkout`,
486
763
  payload,
487
764
  options
488
765
  );
489
- },
490
- async unsubscribe(params, options) {
491
- return apiConfig.httpClient.post(`/v1/newsletters/unsubscribe`, params, options);
492
- },
493
- async unsubscribeWithToken(params, options) {
494
- return apiConfig.httpClient.get(`/v1/newsletters/unsubscribe`, {
495
- ...options,
496
- params
497
- });
498
766
  }
499
767
  };
500
768
  };
501
769
 
502
- // src/api/user.ts
503
- var createUserApi = (apiConfig) => {
770
+ // src/api/reservation.ts
771
+ var createReservationApi = (apiConfig) => {
504
772
  return {
505
- // ===== USER PROFILE =====
506
- async updateUser(params, options) {
507
- const payload = {
508
- name: params.name,
509
- phoneNumbers: params.phoneNumbers || [],
510
- phoneNumber: params.phoneNumber || null,
511
- addresses: params.addresses || [],
512
- ...params.apiTokens !== void 0 && { apiTokens: params.apiTokens }
513
- };
514
- return apiConfig.httpClient.put("/v1/users/update", payload, options);
515
- },
516
- async updateProfilePhone(params, options) {
517
- const payload = {
518
- phoneNumbers: [],
519
- phoneNumber: params.phoneNumber,
520
- addresses: []
521
- };
522
- return apiConfig.httpClient.put("/v1/users/update", payload, options);
523
- },
524
- async verifyPhoneCode(params, options) {
525
- return apiConfig.httpClient.put("/v1/users/confirm/phone-number", params, options);
526
- },
527
- async getUserLocation(options) {
528
- return apiConfig.httpClient.get("/v1/users/location", options);
529
- },
530
- async getMe(options) {
531
- return apiConfig.httpClient.get("/v1/users/me", options);
532
- },
533
- async searchUsers(params, options) {
534
- return apiConfig.httpClient.get("/v1/users/search", {
535
- ...options,
536
- params
773
+ // ===== RESERVATIONS =====
774
+ async createReservation(params, options) {
775
+ return apiConfig.httpClient.post(`/v1/reservations`, params, {
776
+ successMessage: "Reservation created successfully",
777
+ errorMessage: "Failed to create reservation",
778
+ ...options
537
779
  });
538
780
  },
539
- async setUserRole(params, options) {
540
- return apiConfig.httpClient.put("/v1/users/set-role", params, options);
541
- },
542
- // ===== AUTHENTICATION =====
543
- async loginUser(params, options) {
544
- return apiConfig.httpClient.post("/v1/users/login", params, options);
545
- },
546
- async registerUser(params, options) {
547
- return apiConfig.httpClient.post("/v1/users/register", params, options);
548
- },
549
- async logout(options) {
550
- return apiConfig.httpClient.post("/v1/users/logout", {}, options);
551
- },
552
- async confirmUser(params, options) {
553
- return apiConfig.httpClient.put("/v1/users/confirm", params, options);
554
- },
555
- async getLoginUrl(params, options) {
556
- return apiConfig.httpClient.get("/v1/users/login/url", {
557
- ...options,
558
- params
781
+ async updateReservation(params, options) {
782
+ const { id, ...payload } = params;
783
+ return apiConfig.httpClient.put(`/v1/reservations/${id}`, payload, {
784
+ successMessage: "Reservation updated successfully",
785
+ errorMessage: "Failed to update reservation",
786
+ ...options
559
787
  });
560
788
  },
561
- async getGuestToken(params, options) {
562
- if (params.existingToken) {
563
- return params.existingToken;
564
- }
565
- const result = await apiConfig.httpClient.post("/v1/users/login", {
566
- provider: "GUEST"
567
- }, options);
568
- const token = result.accessToken || result.token || "";
569
- if (token) {
570
- apiConfig.setTokens(result);
571
- }
572
- return token;
573
- },
574
- // ===== PASSWORD MANAGEMENT =====
575
- async forgotPassword(params, options) {
576
- return apiConfig.httpClient.post("/v1/users/forgot-password", params, options);
577
- },
578
- async resetForgotPassword(params, options) {
579
- return apiConfig.httpClient.post("/v1/users/reset-forgot-password", params, options);
580
- },
581
- async resetPassword(params, options) {
582
- return apiConfig.httpClient.post("/v1/users/reset-password", params, options);
583
- }
584
- };
585
- };
586
-
587
- // src/api/business.ts
588
- var createBusinessApi = (apiConfig) => {
589
- return {
590
- async createBusiness(params, options) {
591
- return apiConfig.httpClient.post(`/v1/businesses`, params, options);
592
- },
593
- async updateBusiness(params, options) {
594
- return apiConfig.httpClient.put(`/v1/businesses/${params.id}`, params, options);
595
- },
596
- async deleteBusiness(params, options) {
597
- return apiConfig.httpClient.delete(`/v1/businesses/${params.id}`, options);
598
- },
599
- async getBusiness(params, options) {
600
- return apiConfig.httpClient.get(`/v1/businesses/${params.id}`, options);
601
- },
602
- async getBusinesses(options) {
603
- return apiConfig.httpClient.get(`/v1/businesses`, options);
604
- },
605
- async getBusinessParents(params, options) {
606
- return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/parents`, options);
607
- },
608
- async triggerBuilds(params, options) {
609
- return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
610
- },
611
- async getSubscriptionPlans(options) {
612
- return apiConfig.httpClient.get("/v1/businesses/plans", options);
789
+ async checkout(params, options) {
790
+ const payload = {
791
+ businessId: apiConfig.businessId,
792
+ market: apiConfig.market,
793
+ blocks: params.blocks || [],
794
+ parts: params.parts,
795
+ ...params.paymentMethod && { paymentMethod: params.paymentMethod },
796
+ ...params.promoCode && { promoCode: params.promoCode }
797
+ };
798
+ return apiConfig.httpClient.post(`/v1/reservations/checkout`, payload, {
799
+ successMessage: "Reservation checkout completed",
800
+ errorMessage: "Failed to complete checkout",
801
+ ...options
802
+ });
613
803
  },
614
- async getSubscription(params, options) {
615
- return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/subscription`, options);
804
+ async getReservation(params, options) {
805
+ return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
806
+ ...options,
807
+ params: params.businessId ? { businessId: params.businessId } : {}
808
+ });
616
809
  },
617
- async createSubscription(params, options) {
618
- return apiConfig.httpClient.post(
619
- `/v1/businesses/${params.businessId}/subscription`,
620
- params,
621
- options
622
- );
810
+ async getReservationParts(params, options) {
811
+ return apiConfig.httpClient.get(`/v1/reservations/parts`, {
812
+ ...options,
813
+ params: params || {}
814
+ });
623
815
  },
624
- async updateSubscription(params, options) {
625
- return apiConfig.httpClient.put(
626
- `/v1/businesses/${params.businessId}/subscription`,
627
- params,
628
- options
629
- );
816
+ async searchReservations(params, options) {
817
+ return apiConfig.httpClient.get(`/v1/reservations/search`, {
818
+ ...options,
819
+ params
820
+ });
630
821
  },
631
- async cancelSubscription(params, options) {
632
- return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
822
+ async searchMyReservations(params, options) {
823
+ return apiConfig.httpClient.get(`/v1/reservations`, {
633
824
  ...options,
634
- params: { immediately: params.immediately || false }
825
+ params: params || {}
635
826
  });
636
827
  },
637
- async reactivateSubscription(params, options) {
638
- return apiConfig.httpClient.post(
639
- `/v1/businesses/${params.businessId}/subscription/reactivate`,
640
- params,
641
- options
642
- );
828
+ // ===== QUOTES =====
829
+ async getQuote(params, options) {
830
+ const lines = params.parts.map((part) => ({
831
+ type: "SERVICE",
832
+ serviceId: part.serviceId,
833
+ quantity: 1
834
+ }));
835
+ const payload = {
836
+ businessId: apiConfig.businessId,
837
+ market: apiConfig.market,
838
+ currency: params.currency,
839
+ paymentMethod: params.paymentMethod,
840
+ lines,
841
+ ...params.promoCode && { promoCode: params.promoCode }
842
+ };
843
+ return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
643
844
  },
644
- async createPortalSession(params, options) {
845
+ // ===== SERVICES =====
846
+ async createService(params, options) {
645
847
  return apiConfig.httpClient.post(
646
- `/v1/businesses/${params.businessId}/subscription/portal`,
848
+ `/v1/businesses/${apiConfig.businessId}/services`,
647
849
  params,
648
- options
649
- );
650
- },
651
- async inviteUser(params, options) {
652
- const { businessId, ...payload } = params;
653
- return apiConfig.httpClient.post(
654
- `/v1/businesses/${businessId}/invitation`,
655
- payload,
656
- options
850
+ {
851
+ successMessage: "Service created successfully",
852
+ errorMessage: "Failed to create service",
853
+ ...options
854
+ }
657
855
  );
658
856
  },
659
- async handleInvitation(params, options) {
660
- const { businessId, ...payload } = params;
857
+ async updateService(params, options) {
661
858
  return apiConfig.httpClient.put(
662
- `/v1/businesses/${businessId}/invitation`,
663
- payload,
664
- options
665
- );
666
- },
667
- async testWebhook(params, options) {
668
- return apiConfig.httpClient.post(
669
- `/v1/businesses/${params.businessId}/webhooks/test`,
670
- params.webhook,
671
- options
859
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
860
+ params,
861
+ {
862
+ successMessage: "Service updated successfully",
863
+ errorMessage: "Failed to update service",
864
+ ...options
865
+ }
672
866
  );
673
867
  },
674
- async getBusinessMedia(params, options) {
675
- return apiConfig.httpClient.get(
676
- `/v1/businesses/${params.id}/media`,
868
+ async deleteService(params, options) {
869
+ return apiConfig.httpClient.delete(
870
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
677
871
  {
678
- ...options,
679
- params: {
680
- cursor: params.cursor,
681
- limit: params.limit || 20
682
- }
872
+ successMessage: "Service deleted successfully",
873
+ errorMessage: "Failed to delete service",
874
+ ...options
683
875
  }
684
876
  );
685
877
  },
686
- async setProviderSchedule(params, options) {
687
- const { id, ...payload } = params;
688
- return apiConfig.httpClient.put(
689
- `/v1/businesses/${id}/schedules`,
690
- payload,
878
+ async getService(params, options) {
879
+ return apiConfig.httpClient.get(
880
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
691
881
  options
692
882
  );
693
- }
694
- };
695
- };
696
-
697
- // src/api/media.ts
698
- var createMediaApi = (apiConfig) => {
699
- return {
700
- async uploadBusinessMedia(params) {
701
- const { businessId, files = [], urls = [] } = params;
702
- const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/upload`;
703
- const formData = new FormData();
704
- files.forEach((file) => formData.append("files", file));
705
- urls.forEach((url2) => formData.append("files", url2));
706
- const tokens = await apiConfig.getTokens();
707
- const response = await fetch(url, {
708
- method: "POST",
709
- body: formData,
710
- headers: {
711
- Authorization: `Bearer ${tokens.accessToken}`
712
- }
713
- });
714
- if (!response.ok) {
715
- throw new Error("Upload failed, server said no");
716
- }
717
- return await response.json();
718
883
  },
719
- async deleteBusinessMedia(params, options) {
720
- const { id, mediaId } = params;
721
- return apiConfig.httpClient.delete(
722
- `/v1/businesses/${id}/upload`,
884
+ async getServices(params, options) {
885
+ const queryParams = params ? { ...params } : {};
886
+ return apiConfig.httpClient.get(
887
+ `/v1/businesses/${apiConfig.businessId}/services`,
723
888
  {
724
889
  ...options,
725
- params: { mediaId }
890
+ params: queryParams
726
891
  }
727
892
  );
728
893
  },
729
- async getBusinessMedia(params) {
730
- const { businessId, cursor = null, limit = 20 } = params;
731
- const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/media`;
732
- const queryParams = { limit };
733
- if (cursor) queryParams.cursor = cursor;
734
- const queryString = new URLSearchParams(queryParams).toString();
735
- const response = await fetch(`${url}?${queryString}`);
736
- if (!response.ok) {
737
- const errorData = await response.json().catch(() => null);
738
- throw new Error(errorData?.message || "Failed to fetch media");
739
- }
740
- return await response.json();
741
- }
742
- };
743
- };
744
-
745
- // src/api/role.ts
746
- var createRoleApi = (apiConfig) => {
747
- return {
748
- async createRole(params, options) {
749
- return apiConfig.httpClient.post(`/v1/roles`, params, options);
750
- },
751
- async updateRole(params, options) {
752
- return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, options);
753
- },
754
- async deleteRole(params, options) {
755
- return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
756
- },
757
- async getRole(params, options) {
758
- return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
759
- },
760
- async getRoles(params, options) {
761
- return apiConfig.httpClient.get(`/v1/roles`, {
762
- ...options,
763
- params: params ? {
764
- businessId: apiConfig.businessId,
765
- action: params.action || "READ"
766
- } : {
767
- businessId: apiConfig.businessId,
768
- action: "READ"
769
- }
770
- });
771
- }
772
- };
773
- };
774
-
775
- // src/api/notification.ts
776
- var createNotificationApi = (apiConfig) => {
777
- return {
778
- async getNotifications(params, options) {
779
- return apiConfig.httpClient.get(`/v1/notifications`, {
780
- ...options,
781
- params: {
782
- limit: params.limit,
783
- previous_id: params.previous_id
784
- }
785
- });
786
- },
787
- async updateNotifications(options) {
788
- return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
789
- },
790
- async trackEmailOpen(params, options) {
894
+ async getAvailableSlots(params, options) {
895
+ const { serviceId, ...queryParams } = params;
791
896
  return apiConfig.httpClient.get(
792
- `/v1/notifications/track/email/${params.trackingPixelId}`,
793
- options
897
+ `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
898
+ {
899
+ ...options,
900
+ params: {
901
+ ...queryParams,
902
+ limit: queryParams.limit || 1e3
903
+ }
904
+ }
794
905
  );
795
906
  },
796
- async getDeliveryStats(params, options) {
797
- return apiConfig.httpClient.get(
798
- `/v1/notifications/track/stats/${apiConfig.businessId}`,
799
- options
800
- );
801
- }
802
- };
803
- };
804
-
805
- // src/api/promoCode.ts
806
- var createPromoCodeApi = (apiConfig) => {
807
- return {
808
- async createPromoCode(params, options) {
907
+ // ===== PROVIDERS =====
908
+ async createProvider(params, options) {
809
909
  return apiConfig.httpClient.post(
810
- `/v1/businesses/${apiConfig.businessId}/promo-codes`,
910
+ `/v1/businesses/${apiConfig.businessId}/providers`,
811
911
  params,
812
- options
912
+ {
913
+ successMessage: "Provider created successfully",
914
+ errorMessage: "Failed to create provider",
915
+ ...options
916
+ }
813
917
  );
814
918
  },
815
- async updatePromoCode(params, options) {
919
+ async updateProvider(params, options) {
816
920
  return apiConfig.httpClient.put(
817
- `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
921
+ `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
818
922
  params,
819
- options
923
+ {
924
+ successMessage: "Provider updated successfully",
925
+ errorMessage: "Failed to update provider",
926
+ ...options
927
+ }
820
928
  );
821
929
  },
822
- async deletePromoCode(params, options) {
930
+ async deleteProvider(params, options) {
823
931
  return apiConfig.httpClient.delete(
824
- `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
825
- options
932
+ `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
933
+ {
934
+ successMessage: "Provider deleted successfully",
935
+ errorMessage: "Failed to delete provider",
936
+ ...options
937
+ }
826
938
  );
827
939
  },
828
- async getPromoCode(params, options) {
940
+ async getProvider(params, options) {
829
941
  return apiConfig.httpClient.get(
830
- `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
942
+ `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
831
943
  options
832
944
  );
833
945
  },
834
- async getPromoCodes(params, options) {
835
- const { businessId, statuses, ...restParams } = params;
836
- return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/promo-codes`, {
837
- ...options,
838
- params: {
839
- ...restParams,
840
- statuses: statuses && statuses.length > 0 ? statuses : void 0
946
+ async getProviders(params, options) {
947
+ const { businessId, ...queryParams } = params;
948
+ return apiConfig.httpClient.get(
949
+ `/v1/businesses/${apiConfig.businessId}/providers`,
950
+ {
951
+ ...options,
952
+ params: queryParams
841
953
  }
842
- });
954
+ );
955
+ },
956
+ async getProviderWorkingTime(params, options) {
957
+ const { businessId, providerId, ...queryParams } = params;
958
+ return apiConfig.httpClient.get(
959
+ `/v1/businesses/${apiConfig.businessId}/providers/${providerId}/working-time`,
960
+ {
961
+ ...options,
962
+ params: queryParams
963
+ }
964
+ );
843
965
  }
844
966
  };
845
967
  };
846
968
 
847
- // src/api/analytics.ts
848
- var createAnalyticsApi = (apiConfig) => {
969
+ // src/api/newsletter.ts
970
+ var createNewsletterApi = (apiConfig) => {
849
971
  return {
850
- async getAnalytics(params, options) {
851
- const { businessId, ...queryParams } = params;
852
- return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}`, {
972
+ // ===== NEWSLETTERS =====
973
+ async find(params, options) {
974
+ return apiConfig.httpClient.get(`/v1/newsletters`, {
853
975
  ...options,
854
- params: queryParams
976
+ params: { businessId: params.businessId }
855
977
  });
856
978
  },
857
- async getAnalyticsHealth(params, options) {
858
- return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}/health`, options);
979
+ async get(params, options) {
980
+ return apiConfig.httpClient.get(`/v1/newsletters/${params.id}`, options);
859
981
  },
860
- async setupAnalytics(params, options) {
861
- return apiConfig.httpClient.post(`/v1/analytics/admin/setup`, params, options);
982
+ async create(params, options) {
983
+ return apiConfig.httpClient.post(`/v1/newsletters`, params, options);
984
+ },
985
+ async update(params, options) {
986
+ return apiConfig.httpClient.put(`/v1/newsletters/${params.id}`, params, options);
987
+ },
988
+ async delete(params, options) {
989
+ return apiConfig.httpClient.delete(`/v1/newsletters/${params.id}`, options);
990
+ },
991
+ // ===== SUBSCRIBERS =====
992
+ async getSubscribers(params, options) {
993
+ return apiConfig.httpClient.get(`/v1/newsletters/${params.id}/subscribers`, options);
994
+ },
995
+ async subscribe(params, options) {
996
+ const { newsletterId, email, customerId, payment } = params;
997
+ const payload = {
998
+ newsletterId,
999
+ email,
1000
+ market: apiConfig.market,
1001
+ ...customerId && { customerId },
1002
+ ...payment && { payment }
1003
+ };
1004
+ return apiConfig.httpClient.post(
1005
+ `/v1/newsletters/${newsletterId}/subscribe`,
1006
+ payload,
1007
+ options
1008
+ );
1009
+ },
1010
+ async unsubscribe(params, options) {
1011
+ return apiConfig.httpClient.post(`/v1/newsletters/unsubscribe`, params, options);
1012
+ },
1013
+ async unsubscribeWithToken(params, options) {
1014
+ return apiConfig.httpClient.get(`/v1/newsletters/unsubscribe`, {
1015
+ ...options,
1016
+ params
1017
+ });
862
1018
  }
863
1019
  };
864
1020
  };
@@ -1065,20 +1221,6 @@ function thumbnailUrl(service, storageUrl = "") {
1065
1221
  const path = getGalleryThumbnail(service.gallery);
1066
1222
  return path ? `${storageUrl}/${path}` : null;
1067
1223
  }
1068
- var translateMap = (labels, lang, fallback = "unknown") => {
1069
- let parsedLang = "en";
1070
- if (lang === "sr") {
1071
- parsedLang = "bih";
1072
- }
1073
- if (!labels) {
1074
- return fallback;
1075
- }
1076
- const label = labels[parsedLang];
1077
- if (!label) {
1078
- return fallback;
1079
- }
1080
- return label;
1081
- };
1082
1224
 
1083
1225
  // src/utils/currency.ts
1084
1226
  function getCurrencySymbol(currency) {
@@ -1169,143 +1311,6 @@ function isSymbolAfterCurrency(currency) {
1169
1311
  return SYMBOL_AFTER_CURRENCIES.includes(currency.toUpperCase());
1170
1312
  }
1171
1313
 
1172
- // src/utils/errors.ts
1173
- var ERROR_CODES = {
1174
- // General errors
1175
- "GENERAL.001": "GENERAL.BAD_REQUEST",
1176
- "GENERAL.002": "GENERAL.VALIDATION_ERROR",
1177
- "GENERAL.003": "GENERAL.FORBIDDEN_ERROR",
1178
- "GENERAL.004": "GENERAL.INTERNAL_SERVER_ERROR",
1179
- "GENERAL.005": "GENERAL.UNAUTHORIZED",
1180
- "GENERAL.006": "GENERAL.UNAUTHENTICATED",
1181
- // Google/OAuth errors
1182
- "GOOGLE.001": "GOOGLE.INVALID_ORIGIN_URI",
1183
- "GOOGLE.002": "GOOGLE.INVALID_REDIRECT_URI",
1184
- "GOOGLE.003": "GOOGLE.FAILED_TO_CALL_API",
1185
- "GOOGLE.004": "GOOGLE.FAILED_LOGIN",
1186
- "GOOGLE.005": "GOOGLE.FAILED_LOGOUT",
1187
- "GOOGLE.006": "GOOGLE.FAILED_REFRESH_TOKEN",
1188
- "GOOGLE.007": "GOOGLE.INVALID_PROVIDER_PASSED",
1189
- // User errors
1190
- "USER.001": "USER.NOT_FOUND",
1191
- "USER.002": "USER.FAILED_TO_CREATE",
1192
- "USER.003": "USER.FAILED_TO_UPDATE",
1193
- "USER.004": "USER.FAILED_TO_DELETE",
1194
- "USER.005": "USER.EMAIL_EXISTS",
1195
- "USER.006": "USER.FAILED_TO_GET_UPLOAD_URL",
1196
- // Business errors
1197
- "BUSINESS.001": "BUSINESS.NOT_FOUND",
1198
- "BUSINESS.002": "BUSINESS.FAILED_TO_CREATE",
1199
- "BUSINESS.003": "BUSINESS.FAILED_TO_UPDATE",
1200
- "BUSINESS.004": "BUSINESS.FAILED_TO_DELETE",
1201
- "BUSINESS.005": "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
1202
- "BUSINESS.006": "BUSINESS.NAME_REQUIRED",
1203
- "BUSINESS.007": "BUSINESS.BUSINESS_ID_REQUIRED",
1204
- "BUSINESS.010": "BUSINESS.DESCRIPTION_REQUIRED",
1205
- "BUSINESS.011": "BUSINESS.SLUG_INVALID",
1206
- // Provider errors
1207
- "PROVIDER.001": "PROVIDER.NOT_FOUND",
1208
- "PROVIDER.002": "PROVIDER.FAILED_TO_CREATE",
1209
- "PROVIDER.003": "PROVIDER.FAILED_TO_UPDATE",
1210
- "PROVIDER.004": "PROVIDER.FAILED_TO_DELETE",
1211
- "PROVIDER.005": "PROVIDER.FAILED_TO_GET_UPLOAD_URL",
1212
- "PROVIDER.006": "PROVIDER.NAME_REQUIRED",
1213
- "PROVIDER.007": "PROVIDER.BUSINESS_ID_REQUIRED",
1214
- "PROVIDER.008": "PROVIDER.DESCRIPTION_REQUIRED"
1215
- };
1216
- var ERROR_CONSTANTS = {
1217
- GENERAL: {
1218
- BAD_REQUEST: "GENERAL.BAD_REQUEST",
1219
- VALIDATION_ERROR: "GENERAL.VALIDATION_ERROR",
1220
- FORBIDDEN_ERROR: "GENERAL.FORBIDDEN_ERROR",
1221
- INTERNAL_SERVER_ERROR: "GENERAL.INTERNAL_SERVER_ERROR",
1222
- UNAUTHORIZED: "GENERAL.UNAUTHORIZED",
1223
- UNAUTHENTICATED: "GENERAL.UNAUTHENTICATED"
1224
- },
1225
- USER: {
1226
- NOT_FOUND: "USER.NOT_FOUND",
1227
- FAILED_TO_CREATE: "USER.FAILED_TO_CREATE",
1228
- FAILED_TO_UPDATE: "USER.FAILED_TO_UPDATE",
1229
- FAILED_TO_DELETE: "USER.FAILED_TO_DELETE",
1230
- EMAIL_EXISTS: "USER.EMAIL_EXISTS",
1231
- FAILED_TO_GET_UPLOAD_URL: "USER.FAILED_TO_GET_UPLOAD_URL"
1232
- },
1233
- BUSINESS: {
1234
- NOT_FOUND: "BUSINESS.NOT_FOUND",
1235
- FAILED_TO_CREATE: "BUSINESS.FAILED_TO_CREATE",
1236
- FAILED_TO_UPDATE: "BUSINESS.FAILED_TO_UPDATE",
1237
- FAILED_TO_DELETE: "BUSINESS.FAILED_TO_DELETE",
1238
- FAILED_TO_GET_UPLOAD_URL: "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
1239
- NAME_REQUIRED: "BUSINESS.NAME_REQUIRED",
1240
- BUSINESS_ID_REQUIRED: "BUSINESS.BUSINESS_ID_REQUIRED",
1241
- DESCRIPTION_REQUIRED: "BUSINESS.DESCRIPTION_REQUIRED",
1242
- SLUG_INVALID: "BUSINESS.SLUG_INVALID"
1243
- }
1244
- };
1245
- function getErrorMessage(code) {
1246
- return ERROR_CODES[code] || code;
1247
- }
1248
- function isErrorCode(code) {
1249
- return code in ERROR_CODES;
1250
- }
1251
- var transformErrors = (zodError) => {
1252
- const customErrors = [];
1253
- if (!zodError.issues) return customErrors;
1254
- zodError.issues.forEach((issue) => {
1255
- const field = issue.path.join(".");
1256
- const error = issue.message;
1257
- if (!customErrors.some(
1258
- (customError) => customError.field === field && customError.error === error
1259
- )) {
1260
- customErrors.push({ field, error });
1261
- }
1262
- });
1263
- return customErrors;
1264
- };
1265
- var convertServerErrorToRequestError = (serverError, renameRules) => {
1266
- return {
1267
- ...serverError,
1268
- validationErrors: serverError.validationErrors.map((validationError) => {
1269
- const field = renameRules && renameRules[validationError.field] ? renameRules[validationError.field] : validationError.field;
1270
- return {
1271
- field,
1272
- error: validationError.error || "GENERAL.VALIDATION_ERROR"
1273
- };
1274
- })
1275
- };
1276
- };
1277
- var errors = ERROR_CONSTANTS;
1278
-
1279
- // src/utils/i18n.ts
1280
- var defaultLocale = "en";
1281
- function setDefaultLocale(locale) {
1282
- defaultLocale = locale;
1283
- }
1284
- function getLocale() {
1285
- if (typeof window !== "undefined" && window.navigator) {
1286
- return window.navigator.language.split("-")[0] || defaultLocale;
1287
- }
1288
- return defaultLocale;
1289
- }
1290
- function getLocaleFromUrl(url) {
1291
- const pathParts = url.pathname.split("/").filter(Boolean);
1292
- const potentialLocale = pathParts[0];
1293
- const validLocales = ["en", "fr", "es", "de", "it", "pt", "ja", "zh", "ko", "ru"];
1294
- if (potentialLocale && validLocales.includes(potentialLocale)) {
1295
- return potentialLocale;
1296
- }
1297
- return getLocale();
1298
- }
1299
- function getLocalizedString(value, locale) {
1300
- if (!value) return "";
1301
- if (typeof value === "string") return value;
1302
- if (typeof value === "object") {
1303
- const targetLocale = locale || getLocale();
1304
- return value[targetLocale] || value["en"] || value[Object.keys(value)[0]] || "";
1305
- }
1306
- return String(value);
1307
- }
1308
-
1309
1314
  // src/utils/price.ts
1310
1315
  var MARKET_CURRENCIES = {
1311
1316
  "US": "USD",
@@ -1317,9 +1322,6 @@ var MARKET_CURRENCIES = {
1317
1322
  function convertToMajor(minorAmount) {
1318
1323
  return (minorAmount ?? 0) / 100;
1319
1324
  }
1320
- function convertToMinor(majorAmount) {
1321
- return Math.round((majorAmount ?? 0) * 100);
1322
- }
1323
1325
  function getCurrencyFromMarket(marketId) {
1324
1326
  return MARKET_CURRENCIES[marketId] || "USD";
1325
1327
  }
@@ -1401,135 +1403,46 @@ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
1401
1403
  }
1402
1404
  return formattedPrice;
1403
1405
  }
1404
- function getPriceAmount(prices, marketId, fallbackMarket) {
1405
- if (!prices || prices.length === 0) return 0;
1406
- let price = prices.find((p) => p.market === marketId);
1407
- if (!price && fallbackMarket) {
1408
- price = prices.find((p) => p.market === fallbackMarket);
1409
- }
1410
- if (!price) {
1411
- price = prices[0];
1412
- }
1413
- return price?.amount || 0;
1414
- }
1415
- function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
1416
- const { discount = 0, tax = 0, promoCodeId } = options;
1417
- const total = subtotalMinor - discount + tax;
1418
- return {
1419
- currency,
1420
- market: marketId,
1421
- subtotal: subtotalMinor,
1422
- shipping: 0,
1423
- discount,
1424
- tax,
1425
- total,
1426
- promoCodeId,
1427
- method: paymentMethod
1428
- };
1429
- }
1430
-
1431
- // src/utils/queryParams.ts
1432
- function buildQueryString(params) {
1433
- const queryParts = [];
1434
- Object.entries(params).forEach(([key, value]) => {
1435
- if (value === null || value === void 0) {
1436
- return;
1437
- }
1438
- if (Array.isArray(value)) {
1439
- const jsonString = JSON.stringify(value);
1440
- queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
1441
- } else if (typeof value === "string") {
1442
- queryParts.push(`${key}=${encodeURIComponent(value)}`);
1443
- } else if (typeof value === "number" || typeof value === "boolean") {
1444
- queryParts.push(`${key}=${value}`);
1445
- } else if (typeof value === "object") {
1446
- const jsonString = JSON.stringify(value);
1447
- queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
1448
- }
1449
- });
1450
- return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
1451
- }
1452
- function appendQueryString(url, params) {
1453
- const queryString = buildQueryString(params);
1454
- return queryString ? `${url}${queryString}` : url;
1455
- }
1456
-
1457
- // src/utils/svg.ts
1458
- async function fetchSvgContent(mediaObject) {
1459
- if (!mediaObject) return null;
1460
- const svgUrl = getImageUrl(mediaObject, false);
1461
- try {
1462
- const response = await fetch(svgUrl);
1463
- if (!response.ok) {
1464
- console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
1465
- return null;
1466
- }
1467
- const svgContent = await response.text();
1468
- return svgContent;
1469
- } catch (error) {
1470
- console.error("Error fetching SVG:", error);
1471
- return null;
1472
- }
1473
- }
1474
- async function getSvgContentForAstro(mediaObject) {
1475
- try {
1476
- const svgContent = await fetchSvgContent(mediaObject);
1477
- return svgContent || "";
1478
- } catch (error) {
1479
- console.error("Error getting SVG content for Astro:", error);
1480
- return "";
1481
- }
1482
- }
1483
- async function injectSvgIntoElement(mediaObject, targetElement, className) {
1484
- if (!targetElement) return;
1485
- try {
1486
- const svgContent = await fetchSvgContent(mediaObject);
1487
- if (svgContent) {
1488
- targetElement.innerHTML = svgContent;
1489
- if (className) {
1490
- const svgElement = targetElement.querySelector("svg");
1491
- if (svgElement) {
1492
- svgElement.classList.add(...className.split(" "));
1493
- }
1494
- }
1495
- }
1496
- } catch (error) {
1497
- console.error("Error injecting SVG:", error);
1498
- }
1499
- }
1500
-
1501
- // src/utils/text.ts
1502
- var locales = ["en", "sr-latn"];
1503
- var localeMap = {
1504
- "en": "en-US",
1505
- "sr-latn": "sr-RS"
1506
- };
1507
- function slugify(text) {
1508
- return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1509
- }
1510
- function humanize(text) {
1511
- const slugifiedText = slugify(text);
1512
- return slugifiedText.replace(/-/g, " ").replace(
1513
- // upper case first letter of every word, and lower case the rest
1514
- /\w\S*/g,
1515
- (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
1516
- );
1406
+ function getPriceAmount(prices, marketId, fallbackMarket) {
1407
+ if (!prices || prices.length === 0) return 0;
1408
+ let price = prices.find((p) => p.market === marketId);
1409
+ if (!price && fallbackMarket) {
1410
+ price = prices.find((p) => p.market === fallbackMarket);
1411
+ }
1412
+ if (!price) {
1413
+ price = prices[0];
1414
+ }
1415
+ return price?.amount || 0;
1517
1416
  }
1518
- function categorify(text) {
1519
- const slugifiedText = slugify(text);
1520
- return slugifiedText.replace(/-/g, " ").toUpperCase();
1417
+ function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
1418
+ const { discount = 0, tax = 0, promoCodeId } = options;
1419
+ const total = subtotalMinor - discount + tax;
1420
+ return {
1421
+ currency,
1422
+ market: marketId,
1423
+ subtotal: subtotalMinor,
1424
+ shipping: 0,
1425
+ discount,
1426
+ tax,
1427
+ total,
1428
+ promoCodeId,
1429
+ method: paymentMethod
1430
+ };
1521
1431
  }
1522
- function formatDate(date, locale) {
1523
- let localeString = "en-US";
1524
- if (locales.includes(locale)) {
1525
- localeString = localeMap[locale];
1432
+
1433
+ // src/utils/validation.ts
1434
+ function validatePhoneNumber(phone) {
1435
+ if (!phone) {
1436
+ return { isValid: false, error: "Phone number is required" };
1526
1437
  }
1527
- return new Date(date).toLocaleDateString(localeString, {
1528
- timeZone: "UTC",
1529
- year: "numeric",
1530
- month: "short",
1531
- day: "numeric"
1532
- });
1438
+ const cleaned = phone.replace(/\D/g, "");
1439
+ if (cleaned.length < 8) {
1440
+ return { isValid: false, error: "Phone number is too short" };
1441
+ }
1442
+ if (cleaned.length > 15) {
1443
+ return { isValid: false, error: "Phone number is too long" };
1444
+ }
1445
+ return { isValid: true };
1533
1446
  }
1534
1447
 
1535
1448
  // src/utils/timezone.ts
@@ -1578,177 +1491,86 @@ function findTimeZone(groups) {
1578
1491
  }
1579
1492
  }
1580
1493
 
1581
- // src/utils/validation.ts
1582
- function validatePhoneNumber(phone) {
1583
- if (!phone) {
1584
- return { isValid: false, error: "Phone number is required" };
1585
- }
1586
- const cleaned = phone.replace(/\D/g, "");
1587
- if (cleaned.length < 8) {
1588
- return { isValid: false, error: "Phone number is too short" };
1589
- }
1590
- if (cleaned.length > 15) {
1591
- return { isValid: false, error: "Phone number is too long" };
1592
- }
1593
- return { isValid: true };
1494
+ // src/utils/text.ts
1495
+ var locales = ["en", "sr-latn"];
1496
+ var localeMap = {
1497
+ "en": "en-US",
1498
+ "sr-latn": "sr-RS"
1499
+ };
1500
+ function slugify(text) {
1501
+ return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1594
1502
  }
1595
- function validateEmail(email) {
1596
- if (!email) {
1597
- return { isValid: false, error: "Email is required" };
1598
- }
1599
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1600
- if (!emailRegex.test(email)) {
1601
- return { isValid: false, error: "Please enter a valid email address" };
1602
- }
1603
- return { isValid: true };
1503
+ function humanize(text) {
1504
+ const slugifiedText = slugify(text);
1505
+ return slugifiedText.replace(/-/g, " ").replace(
1506
+ // upper case first letter of every word, and lower case the rest
1507
+ /\w\S*/g,
1508
+ (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
1509
+ );
1604
1510
  }
1605
- function validateVerificationCode(code) {
1606
- if (!code) {
1607
- return { isValid: false, error: "Verification code is required" };
1608
- }
1609
- const cleaned = code.replace(/\D/g, "");
1610
- if (cleaned.length !== 4) {
1611
- return { isValid: false, error: "Please enter a 4-digit verification code" };
1612
- }
1613
- return { isValid: true };
1511
+ function categorify(text) {
1512
+ const slugifiedText = slugify(text);
1513
+ return slugifiedText.replace(/-/g, " ").toUpperCase();
1614
1514
  }
1615
- function validateRequired(value, fieldName = "This field") {
1616
- if (value === null || value === void 0 || value === "") {
1617
- return { isValid: false, error: `${fieldName} is required` };
1515
+ function formatDate(date, locale) {
1516
+ let localeString = "en-US";
1517
+ if (locales.includes(locale)) {
1518
+ localeString = localeMap[locale];
1618
1519
  }
1619
- return { isValid: true };
1520
+ return new Date(date).toLocaleDateString(localeString, {
1521
+ timeZone: "UTC",
1522
+ year: "numeric",
1523
+ month: "short",
1524
+ day: "numeric"
1525
+ });
1620
1526
  }
1621
1527
 
1622
- // src/services/createHttpClient.ts
1623
- function createHttpClient(cfg) {
1624
- const refreshEndpoint = `${cfg.baseUrl}/v1/users/refresh-access-token`;
1625
- let refreshPromise = null;
1626
- async function ensureFreshToken() {
1627
- if (refreshPromise) {
1628
- return refreshPromise;
1528
+ // src/utils/svg.ts
1529
+ async function fetchSvgContent(mediaObject) {
1530
+ if (!mediaObject) return null;
1531
+ const svgUrl = getImageUrl(mediaObject, false);
1532
+ try {
1533
+ const response = await fetch(svgUrl);
1534
+ if (!response.ok) {
1535
+ console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
1536
+ return null;
1629
1537
  }
1630
- refreshPromise = (async () => {
1631
- const { refreshToken, provider } = await cfg.getToken();
1632
- if (!refreshToken) {
1633
- cfg.logout();
1634
- const err = new Error("No refresh token available");
1635
- err.name = "ApiError";
1636
- err.statusCode = 401;
1637
- throw err;
1638
- }
1639
- const refRes = await fetch(refreshEndpoint, {
1640
- method: "POST",
1641
- headers: { Accept: "application/json", "Content-Type": "application/json" },
1642
- body: JSON.stringify({ provider, refreshToken })
1643
- });
1644
- if (!refRes.ok) {
1645
- cfg.logout();
1646
- const err = new Error("Token refresh failed");
1647
- err.name = "ApiError";
1648
- err.statusCode = 401;
1649
- throw err;
1650
- }
1651
- const data = await refRes.json();
1652
- cfg.setToken(data);
1653
- })().finally(() => {
1654
- refreshPromise = null;
1655
- });
1656
- return refreshPromise;
1538
+ const svgContent = await response.text();
1539
+ return svgContent;
1540
+ } catch (error) {
1541
+ console.error("Error fetching SVG:", error);
1542
+ return null;
1657
1543
  }
1658
- async function request(method, path, body, options) {
1659
- if (options?.transformRequest) {
1660
- body = options.transformRequest(body);
1661
- }
1662
- const headers = {
1663
- Accept: "application/json",
1664
- "Content-Type": "application/json",
1665
- ...options?.headers || {}
1666
- };
1667
- let { accessToken, expiresAt } = await cfg.getToken();
1668
- const nowSec = Date.now() / 1e3;
1669
- if (expiresAt && nowSec > expiresAt) {
1670
- await ensureFreshToken();
1671
- const tokens = await cfg.getToken();
1672
- accessToken = tokens.accessToken;
1673
- }
1674
- if (accessToken) {
1675
- headers["Authorization"] = `Bearer ${accessToken}`;
1676
- }
1677
- const finalPath = options?.params ? path + buildQueryString(options.params) : path;
1678
- const fetchOpts = { method, headers };
1679
- if (!["GET", "DELETE"].includes(method) && body !== void 0) {
1680
- fetchOpts.body = JSON.stringify(body);
1681
- }
1682
- const fullUrl = `${cfg.baseUrl}${finalPath}`;
1683
- let res;
1684
- let data;
1685
- try {
1686
- res = await fetch(fullUrl, fetchOpts);
1687
- } catch (error) {
1688
- const err = new Error(error instanceof Error ? error.message : "Network request failed");
1689
- err.name = "NetworkError";
1690
- err.method = method;
1691
- err.url = fullUrl;
1692
- throw err;
1693
- }
1694
- if (res.status === 401 && !options?.["_retried"]) {
1695
- try {
1696
- await ensureFreshToken();
1697
- const tokens = await cfg.getToken();
1698
- headers["Authorization"] = `Bearer ${tokens.accessToken}`;
1699
- fetchOpts.headers = headers;
1700
- return request(method, path, body, { ...options, _retried: true });
1701
- } catch (refreshError) {
1702
- }
1703
- }
1704
- try {
1705
- const contentLength = res.headers.get("content-length");
1706
- const contentType = res.headers.get("content-type");
1707
- if (res.status === 204 || contentLength === "0" || !contentType?.includes("application/json")) {
1708
- data = {};
1709
- } else {
1710
- data = await res.json();
1711
- }
1712
- } catch (error) {
1713
- const err = new Error("Failed to parse response");
1714
- err.name = "ParseError";
1715
- err.method = method;
1716
- err.url = fullUrl;
1717
- err.status = res.status;
1718
- throw err;
1719
- }
1720
- if (!res.ok) {
1721
- const serverErr = data;
1722
- const reqErr = convertServerErrorToRequestError(serverErr);
1723
- if (options?.errorMessage && cfg.notify) {
1724
- cfg.notify({ message: options.errorMessage, type: "error" });
1544
+ }
1545
+ async function getSvgContentForAstro(mediaObject) {
1546
+ try {
1547
+ const svgContent = await fetchSvgContent(mediaObject);
1548
+ return svgContent || "";
1549
+ } catch (error) {
1550
+ console.error("Error getting SVG content for Astro:", error);
1551
+ return "";
1552
+ }
1553
+ }
1554
+ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1555
+ if (!targetElement) return;
1556
+ try {
1557
+ const svgContent = await fetchSvgContent(mediaObject);
1558
+ if (svgContent) {
1559
+ targetElement.innerHTML = svgContent;
1560
+ if (className) {
1561
+ const svgElement = targetElement.querySelector("svg");
1562
+ if (svgElement) {
1563
+ svgElement.classList.add(...className.split(" "));
1564
+ }
1725
1565
  }
1726
- const err = new Error(serverErr.message || "Request failed");
1727
- err.name = "ApiError";
1728
- err.statusCode = serverErr.statusCode || res.status;
1729
- err.validationErrors = reqErr.validationErrors;
1730
- err.method = method;
1731
- err.url = fullUrl;
1732
- const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
1733
- if (requestId) err.requestId = requestId;
1734
- throw err;
1735
- }
1736
- if (options?.successMessage && cfg.notify) {
1737
- cfg.notify({ message: options.successMessage, type: "success" });
1738
1566
  }
1739
- return data;
1567
+ } catch (error) {
1568
+ console.error("Error injecting SVG:", error);
1740
1569
  }
1741
- return {
1742
- get: (path, opts) => request("GET", path, void 0, opts),
1743
- post: (path, body, opts) => request("POST", path, body, opts),
1744
- put: (path, body, opts) => request("PUT", path, body, opts),
1745
- patch: (path, body, opts) => request("PATCH", path, body, opts),
1746
- delete: (path, opts) => request("DELETE", path, void 0, opts)
1747
- };
1748
1570
  }
1749
1571
 
1750
1572
  // src/index.ts
1751
- var SDK_VERSION = "0.3.7";
1573
+ var SDK_VERSION = "0.3.9";
1752
1574
  var SUPPORTED_FRAMEWORKS = [
1753
1575
  "astro",
1754
1576
  "react",
@@ -1798,18 +1620,41 @@ function createArkySDK(config) {
1798
1620
  logout: config.logout,
1799
1621
  setToken: config.setToken,
1800
1622
  utils: {
1623
+ // Block utilities
1801
1624
  getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
1802
1625
  thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
1803
1626
  getGalleryThumbnail,
1627
+ getBlockValue,
1628
+ getBlockValues,
1629
+ getBlockLabel,
1630
+ getBlockTextValue,
1631
+ getBlockObjectValues,
1632
+ getBlockFromArray,
1633
+ formatBlockValue,
1634
+ prepareBlocksForSubmission,
1635
+ extractBlockValues,
1636
+ // Price utilities
1804
1637
  getMarketPrice,
1805
1638
  getPriceAmount,
1806
1639
  formatPayment,
1807
1640
  formatMinor,
1808
1641
  createPaymentForCheckout,
1642
+ // Currency utilities
1809
1643
  getCurrencySymbol,
1644
+ // Validation utilities
1810
1645
  validatePhoneNumber,
1646
+ // Timezone utilities
1811
1647
  tzGroups,
1812
- findTimeZone
1648
+ findTimeZone,
1649
+ // Text utilities
1650
+ slugify,
1651
+ humanize,
1652
+ categorify,
1653
+ formatDate,
1654
+ // SVG utilities
1655
+ getSvgContentForAstro,
1656
+ fetchSvgContent,
1657
+ injectSvgIntoElement
1813
1658
  }
1814
1659
  };
1815
1660
  if (autoGuest) {
@@ -1833,72 +1678,8 @@ function createArkySDK(config) {
1833
1678
  return sdk;
1834
1679
  }
1835
1680
 
1836
- exports.ERROR_CODES = ERROR_CODES;
1837
- exports.ERROR_CONSTANTS = ERROR_CONSTANTS;
1838
- exports.PaymentMethod = PaymentMethod;
1839
1681
  exports.SDK_VERSION = SDK_VERSION;
1840
1682
  exports.SUPPORTED_FRAMEWORKS = SUPPORTED_FRAMEWORKS;
1841
- exports.SYMBOL_AFTER_CURRENCIES = SYMBOL_AFTER_CURRENCIES;
1842
- exports.appendQueryString = appendQueryString;
1843
- exports.buildQueryString = buildQueryString;
1844
- exports.categorify = categorify;
1845
- exports.convertServerErrorToRequestError = convertServerErrorToRequestError;
1846
- exports.convertToMajor = convertToMajor;
1847
- exports.convertToMinor = convertToMinor;
1848
- exports.createAnalyticsApi = createAnalyticsApi;
1849
1683
  exports.createArkySDK = createArkySDK;
1850
- exports.createBusinessApi = createBusinessApi;
1851
- exports.createCmsApi = createCmsApi;
1852
- exports.createEshopApi = createEshopApi;
1853
- exports.createMediaApi = createMediaApi;
1854
- exports.createNewsletterApi = createNewsletterApi;
1855
- exports.createNotificationApi = createNotificationApi;
1856
- exports.createPaymentApi = createPaymentApi;
1857
- exports.createPaymentForCheckout = createPaymentForCheckout;
1858
- exports.createPromoCodeApi = createPromoCodeApi;
1859
- exports.createReservationApi = createReservationApi;
1860
- exports.createRoleApi = createRoleApi;
1861
- exports.createUserApi = createUserApi;
1862
- exports.errors = errors;
1863
- exports.extractBlockValues = extractBlockValues;
1864
- exports.fetchSvgContent = fetchSvgContent;
1865
- exports.findTimeZone = findTimeZone;
1866
- exports.formatBlockValue = formatBlockValue;
1867
- exports.formatCurrencyAmount = formatCurrencyAmount;
1868
- exports.formatDate = formatDate;
1869
- exports.formatMinor = formatMinor;
1870
- exports.formatPayment = formatPayment;
1871
- exports.getBlockFromArray = getBlockFromArray;
1872
- exports.getBlockLabel = getBlockLabel;
1873
- exports.getBlockObjectValues = getBlockObjectValues;
1874
- exports.getBlockTextValue = getBlockTextValue;
1875
- exports.getBlockValue = getBlockValue;
1876
- exports.getBlockValues = getBlockValues;
1877
- exports.getCurrencyFromMarket = getCurrencyFromMarket;
1878
- exports.getCurrencySymbol = getCurrencySymbol;
1879
- exports.getErrorMessage = getErrorMessage;
1880
- exports.getGalleryThumbnail = getGalleryThumbnail;
1881
- exports.getImageUrl = getImageUrl;
1882
- exports.getLocale = getLocale;
1883
- exports.getLocaleFromUrl = getLocaleFromUrl;
1884
- exports.getLocalizedString = getLocalizedString;
1885
- exports.getMarketPrice = getMarketPrice;
1886
- exports.getPriceAmount = getPriceAmount;
1887
- exports.getSvgContentForAstro = getSvgContentForAstro;
1888
- exports.humanize = humanize;
1889
- exports.injectSvgIntoElement = injectSvgIntoElement;
1890
- exports.isErrorCode = isErrorCode;
1891
- exports.isSymbolAfterCurrency = isSymbolAfterCurrency;
1892
- exports.prepareBlocksForSubmission = prepareBlocksForSubmission;
1893
- exports.setDefaultLocale = setDefaultLocale;
1894
- exports.slugify = slugify;
1895
- exports.thumbnailUrl = thumbnailUrl;
1896
- exports.transformErrors = transformErrors;
1897
- exports.translateMap = translateMap;
1898
- exports.tzGroups = tzGroups;
1899
- exports.validateEmail = validateEmail;
1900
- exports.validatePhoneNumber = validatePhoneNumber;
1901
- exports.validateRequired = validateRequired;
1902
- exports.validateVerificationCode = validateVerificationCode;
1903
1684
  //# sourceMappingURL=index.cjs.map
1904
1685
  //# sourceMappingURL=index.cjs.map