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