arky-sdk 0.3.7 → 0.3.8

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,243 +1,355 @@
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) {
14
- return apiConfig.httpClient.post(
15
- `/v1/businesses/${apiConfig.businessId}/collections`,
16
- params,
17
- options
18
- );
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);
19
178
  },
20
- async updateCollection(params, options) {
21
- return apiConfig.httpClient.put(
22
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
23
- params,
24
- options
25
- );
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);
26
186
  },
27
- async deleteCollection(params, options) {
28
- return apiConfig.httpClient.delete(
29
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
30
- options
31
- );
187
+ async verifyPhoneCode(params, options) {
188
+ return apiConfig.httpClient.put("/v1/users/confirm/phone-number", params, options);
32
189
  },
33
- async getCollection(params, options) {
34
- return apiConfig.httpClient.get(
35
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
36
- options
37
- );
190
+ async getUserLocation(options) {
191
+ return apiConfig.httpClient.get("/v1/users/location", options);
38
192
  },
39
- async getCollections(params, options) {
40
- return apiConfig.httpClient.get(
41
- `/v1/businesses/${apiConfig.businessId}/collections`,
42
- {
43
- ...options,
44
- params: params || {}
45
- }
46
- );
193
+ async getMe(options) {
194
+ return apiConfig.httpClient.get("/v1/users/me", options);
47
195
  },
48
- async generateBlocks(params, options) {
49
- return apiConfig.httpClient.post(
50
- `/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
51
- params,
52
- options
53
- );
196
+ async searchUsers(params, options) {
197
+ return apiConfig.httpClient.get("/v1/users/search", {
198
+ ...options,
199
+ params
200
+ });
54
201
  },
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;
60
- return apiConfig.httpClient.get(
61
- `/v1/businesses/${apiConfig.businessId}/entries`,
62
- {
63
- ...options,
64
- params: finalParams
65
- }
66
- );
202
+ async setUserRole(params, options) {
203
+ return apiConfig.httpClient.put("/v1/users/set-role", params, options);
67
204
  },
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
- );
205
+ // ===== AUTHENTICATION =====
206
+ async loginUser(params, options) {
207
+ return apiConfig.httpClient.post("/v1/users/login", params, options);
79
208
  },
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
- };
86
- return apiConfig.httpClient.put(
87
- `/v1/businesses/${apiConfig.businessId}/entries/${id}`,
88
- payload,
89
- options
90
- );
209
+ async registerUser(params, options) {
210
+ return apiConfig.httpClient.post("/v1/users/register", params, options);
91
211
  },
92
- async deleteCollectionEntry(params, options) {
93
- return apiConfig.httpClient.delete(
94
- `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
95
- options
96
- );
212
+ async logout(options) {
213
+ return apiConfig.httpClient.post("/v1/users/logout", {}, options);
97
214
  },
98
- async getCollectionEntry(params, options) {
99
- return apiConfig.httpClient.get(
100
- `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
101
- options
102
- );
215
+ async confirmUser(params, options) {
216
+ return apiConfig.httpClient.put("/v1/users/confirm", params, options);
103
217
  },
104
- async sendEntry(params, options) {
105
- const { entryId, scheduledAt } = params;
106
- return apiConfig.httpClient.post(
107
- `/v1/businesses/${apiConfig.businessId}/entries/${entryId}/send`,
108
- {
109
- businessId: apiConfig.businessId,
110
- entryId,
111
- scheduledAt: scheduledAt || Date.now()
112
- },
113
- options
114
- );
218
+ async getLoginUrl(params, options) {
219
+ return apiConfig.httpClient.get("/v1/users/login/url", {
220
+ ...options,
221
+ params
222
+ });
115
223
  },
116
- // ===== VARIABLES / METADATA =====
117
- async getVariableMetadata(params, options) {
118
- return apiConfig.httpClient.get(
119
- `/v1/collections/entry-types/${params.entryType}/variables`,
120
- options
121
- );
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);
122
246
  }
123
247
  };
124
248
  };
125
249
 
126
- // src/api/eshop.ts
127
- var createEshopApi = (apiConfig) => {
250
+ // src/api/business.ts
251
+ var createBusinessApi = (apiConfig) => {
128
252
  return {
129
- // ===== PRODUCTS =====
130
- async createProduct(params, options) {
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) {
131
281
  return apiConfig.httpClient.post(
132
- `/v1/businesses/${apiConfig.businessId}/products`,
282
+ `/v1/businesses/${params.businessId}/subscription`,
133
283
  params,
134
284
  options
135
285
  );
136
286
  },
137
- async updateProduct(params, options) {
287
+ async updateSubscription(params, options) {
138
288
  return apiConfig.httpClient.put(
139
- `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
289
+ `/v1/businesses/${params.businessId}/subscription`,
140
290
  params,
141
291
  options
142
292
  );
143
293
  },
144
- async deleteProduct(id, options) {
145
- return apiConfig.httpClient.delete(
146
- `/v1/businesses/${apiConfig.businessId}/products/${id}`,
147
- options
148
- );
149
- },
150
- async getProduct(params, options) {
151
- return apiConfig.httpClient.get(
152
- `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
153
- options
154
- );
155
- },
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
163
- }
164
- );
294
+ async cancelSubscription(params, options) {
295
+ return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
296
+ ...options,
297
+ params: { immediately: params.immediately || false }
298
+ });
165
299
  },
166
- // ===== ORDERS =====
167
- async createOrder(params, options) {
300
+ async reactivateSubscription(params, options) {
168
301
  return apiConfig.httpClient.post(
169
- `/v1/businesses/${apiConfig.businessId}/orders`,
302
+ `/v1/businesses/${params.businessId}/subscription/reactivate`,
170
303
  params,
171
304
  options
172
305
  );
173
306
  },
174
- async updateOrder(params, options) {
175
- return apiConfig.httpClient.put(
176
- `/v1/businesses/${apiConfig.businessId}/orders/update`,
307
+ async createPortalSession(params, options) {
308
+ return apiConfig.httpClient.post(
309
+ `/v1/businesses/${params.businessId}/subscription/portal`,
177
310
  params,
178
311
  options
179
312
  );
180
313
  },
181
- async getOrder(params, options) {
182
- return apiConfig.httpClient.get(
183
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
314
+ async inviteUser(params, options) {
315
+ const { businessId, ...payload } = params;
316
+ return apiConfig.httpClient.post(
317
+ `/v1/businesses/${businessId}/invitation`,
318
+ payload,
184
319
  options
185
320
  );
186
321
  },
187
- async getOrders(params, options) {
188
- return apiConfig.httpClient.get(
189
- `/v1/businesses/${apiConfig.businessId}/orders`,
190
- {
191
- ...options,
192
- params: params || {}
193
- }
194
- );
195
- },
196
- async updateOrderStatus(params, options) {
322
+ async handleInvitation(params, options) {
323
+ const { businessId, ...payload } = params;
197
324
  return apiConfig.httpClient.put(
198
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
199
- params,
325
+ `/v1/businesses/${businessId}/invitation`,
326
+ payload,
200
327
  options
201
328
  );
202
329
  },
203
- async updateOrderPaymentStatus(params, options) {
204
- return apiConfig.httpClient.put(
205
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/payment-status`,
206
- params,
330
+ async testWebhook(params, options) {
331
+ return apiConfig.httpClient.post(
332
+ `/v1/businesses/${params.businessId}/webhooks/test`,
333
+ params.webhook,
207
334
  options
208
335
  );
209
336
  },
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);
337
+ async getBusinessMedia(params, options) {
338
+ return apiConfig.httpClient.get(
339
+ `/v1/businesses/${params.id}/media`,
340
+ {
341
+ ...options,
342
+ params: {
343
+ cursor: params.cursor,
344
+ limit: params.limit || 20
345
+ }
346
+ }
347
+ );
228
348
  },
229
- async checkout(params, options) {
230
- 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 }
238
- };
239
- return apiConfig.httpClient.post(
240
- `/v1/businesses/${apiConfig.businessId}/orders/checkout`,
349
+ async setProviderSchedule(params, options) {
350
+ const { id, ...payload } = params;
351
+ return apiConfig.httpClient.put(
352
+ `/v1/businesses/${id}/schedules`,
241
353
  payload,
242
354
  options
243
355
  );
@@ -245,446 +357,407 @@ var createEshopApi = (apiConfig) => {
245
357
  };
246
358
  };
247
359
 
248
- // src/api/reservation.ts
249
- var createReservationApi = (apiConfig) => {
360
+ // src/api/media.ts
361
+ var createMediaApi = (apiConfig) => {
250
362
  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
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
+ }
257
376
  });
377
+ if (!response.ok) {
378
+ throw new Error("Upload failed, server said no");
379
+ }
380
+ return await response.json();
258
381
  },
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
- });
382
+ async deleteBusinessMedia(params, options) {
383
+ const { id, mediaId } = params;
384
+ return apiConfig.httpClient.delete(
385
+ `/v1/businesses/${id}/upload`,
386
+ {
387
+ ...options,
388
+ params: { mediaId }
389
+ }
390
+ );
266
391
  },
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
- });
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);
281
413
  },
282
- async getReservation(params, options) {
283
- return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
284
- ...options,
285
- params: params.businessId ? { businessId: params.businessId } : {}
286
- });
414
+ async updateRole(params, options) {
415
+ return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, options);
287
416
  },
288
- async getReservationParts(params, options) {
289
- return apiConfig.httpClient.get(`/v1/reservations/parts`, {
290
- ...options,
291
- params: params || {}
292
- });
417
+ async deleteRole(params, options) {
418
+ return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
293
419
  },
294
- async searchReservations(params, options) {
295
- return apiConfig.httpClient.get(`/v1/reservations/search`, {
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`, {
296
425
  ...options,
297
- params
426
+ params: params ? {
427
+ businessId: apiConfig.businessId,
428
+ action: params.action || "READ"
429
+ } : {
430
+ businessId: apiConfig.businessId,
431
+ action: "READ"
432
+ }
298
433
  });
299
- },
300
- async searchMyReservations(params, options) {
301
- return apiConfig.httpClient.get(`/v1/reservations`, {
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`, {
302
443
  ...options,
303
- params: params || {}
444
+ params: {
445
+ limit: params.limit,
446
+ previous_id: params.previous_id
447
+ }
304
448
  });
305
449
  },
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
- }));
313
- 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 }
320
- };
321
- return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
450
+ async updateNotifications(options) {
451
+ return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
322
452
  },
323
- // ===== SERVICES =====
324
- async createService(params, options) {
453
+ async trackEmailOpen(params, options) {
454
+ return apiConfig.httpClient.get(
455
+ `/v1/notifications/track/email/${params.trackingPixelId}`,
456
+ options
457
+ );
458
+ },
459
+ async getDeliveryStats(params, options) {
460
+ return apiConfig.httpClient.get(
461
+ `/v1/notifications/track/stats/${apiConfig.businessId}`,
462
+ options
463
+ );
464
+ }
465
+ };
466
+ };
467
+
468
+ // src/api/promoCode.ts
469
+ var createPromoCodeApi = (apiConfig) => {
470
+ return {
471
+ async createPromoCode(params, options) {
325
472
  return apiConfig.httpClient.post(
326
- `/v1/businesses/${apiConfig.businessId}/services`,
473
+ `/v1/businesses/${apiConfig.businessId}/promo-codes`,
327
474
  params,
328
- {
329
- successMessage: "Service created successfully",
330
- errorMessage: "Failed to create service",
331
- ...options
332
- }
475
+ options
333
476
  );
334
477
  },
335
- async updateService(params, options) {
478
+ async updatePromoCode(params, options) {
336
479
  return apiConfig.httpClient.put(
337
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
480
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
338
481
  params,
339
- {
340
- successMessage: "Service updated successfully",
341
- errorMessage: "Failed to update service",
342
- ...options
343
- }
482
+ options
344
483
  );
345
484
  },
346
- async deleteService(params, options) {
485
+ async deletePromoCode(params, options) {
347
486
  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
- }
487
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
488
+ options
354
489
  );
355
490
  },
356
- async getService(params, options) {
491
+ async getPromoCode(params, options) {
357
492
  return apiConfig.httpClient.get(
358
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
493
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
359
494
  options
360
495
  );
361
496
  },
362
- async getServices(params, options) {
363
- const queryParams = params ? { ...params } : {};
364
- return apiConfig.httpClient.get(
365
- `/v1/businesses/${apiConfig.businessId}/services`,
366
- {
367
- ...options,
368
- 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
369
504
  }
370
- );
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
+ });
371
519
  },
372
- async getAvailableSlots(params, options) {
373
- const { serviceId, ...queryParams } = params;
374
- 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
- }
383
- );
520
+ async getAnalyticsHealth(params, options) {
521
+ return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}/health`, options);
384
522
  },
385
- // ===== PROVIDERS =====
386
- async createProvider(params, options) {
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) {
387
534
  return apiConfig.httpClient.post(
388
- `/v1/businesses/${apiConfig.businessId}/providers`,
535
+ `/v1/businesses/${apiConfig.businessId}/collections`,
389
536
  params,
390
- {
391
- successMessage: "Provider created successfully",
392
- errorMessage: "Failed to create provider",
393
- ...options
394
- }
537
+ options
395
538
  );
396
539
  },
397
- async updateProvider(params, options) {
540
+ async updateCollection(params, options) {
398
541
  return apiConfig.httpClient.put(
399
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
542
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
400
543
  params,
401
- {
402
- successMessage: "Provider updated successfully",
403
- errorMessage: "Failed to update provider",
404
- ...options
405
- }
544
+ options
406
545
  );
407
546
  },
408
- async deleteProvider(params, options) {
547
+ async deleteCollection(params, options) {
409
548
  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
- }
549
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
550
+ options
416
551
  );
417
552
  },
418
- async getProvider(params, options) {
553
+ async getCollection(params, options) {
419
554
  return apiConfig.httpClient.get(
420
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
555
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
421
556
  options
422
557
  );
423
558
  },
424
- async getProviders(params, options) {
425
- const { businessId, ...queryParams } = params;
559
+ async getCollections(params, options) {
426
560
  return apiConfig.httpClient.get(
427
- `/v1/businesses/${apiConfig.businessId}/providers`,
561
+ `/v1/businesses/${apiConfig.businessId}/collections`,
428
562
  {
429
563
  ...options,
430
- params: queryParams
564
+ params: params || {}
431
565
  }
432
566
  );
433
567
  },
434
- async getProviderWorkingTime(params, options) {
435
- const { businessId, providerId, ...queryParams } = params;
568
+ async generateBlocks(params, options) {
569
+ return apiConfig.httpClient.post(
570
+ `/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
571
+ params,
572
+ options
573
+ );
574
+ },
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;
436
580
  return apiConfig.httpClient.get(
437
- `/v1/businesses/${apiConfig.businessId}/providers/${providerId}/working-time`,
581
+ `/v1/businesses/${apiConfig.businessId}/entries`,
438
582
  {
439
583
  ...options,
440
- params: queryParams
584
+ params: finalParams
441
585
  }
442
586
  );
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
- },
463
- async update(params, options) {
464
- return apiConfig.httpClient.put(`/v1/newsletters/${params.id}`, params, options);
465
- },
466
- async delete(params, options) {
467
- return apiConfig.httpClient.delete(`/v1/newsletters/${params.id}`, options);
468
- },
469
- // ===== SUBSCRIBERS =====
470
- async getSubscribers(params, options) {
471
- return apiConfig.httpClient.get(`/v1/newsletters/${params.id}/subscribers`, options);
472
587
  },
473
- async subscribe(params, options) {
474
- const { newsletterId, email, customerId, payment } = params;
588
+ async createCollectionEntry(params, options) {
589
+ const { collectionId, owner, ...rest } = params;
475
590
  const payload = {
476
- newsletterId,
477
- email,
478
- market: apiConfig.market,
479
- ...customerId && { customerId },
480
- ...payment && { payment }
591
+ ...rest,
592
+ owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
481
593
  };
482
594
  return apiConfig.httpClient.post(
483
- `/v1/newsletters/${newsletterId}/subscribe`,
595
+ `/v1/businesses/${apiConfig.businessId}/entries`,
484
596
  payload,
485
597
  options
486
598
  );
487
599
  },
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
- }
497
- };
498
- };
499
-
500
- // src/api/user.ts
501
- var createUserApi = (apiConfig) => {
502
- 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) {
600
+ async updateCollectionEntry(params, options) {
601
+ const { id, collectionId, owner, ...rest } = params;
515
602
  const payload = {
516
- phoneNumbers: [],
517
- phoneNumber: params.phoneNumber,
518
- addresses: []
603
+ ...rest,
604
+ owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
519
605
  };
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
535
- });
536
- },
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
557
- });
558
- },
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);
606
+ return apiConfig.httpClient.put(
607
+ `/v1/businesses/${apiConfig.businessId}/entries/${id}`,
608
+ payload,
609
+ options
610
+ );
605
611
  },
606
- async triggerBuilds(params, options) {
607
- return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
612
+ async deleteCollectionEntry(params, options) {
613
+ return apiConfig.httpClient.delete(
614
+ `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
615
+ options
616
+ );
608
617
  },
609
- async getSubscriptionPlans(options) {
610
- return apiConfig.httpClient.get("/v1/businesses/plans", options);
618
+ async getCollectionEntry(params, options) {
619
+ return apiConfig.httpClient.get(
620
+ `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
621
+ options
622
+ );
611
623
  },
612
- async getSubscription(params, options) {
613
- return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/subscription`, options);
624
+ async sendEntry(params, options) {
625
+ const { entryId, scheduledAt } = params;
626
+ return apiConfig.httpClient.post(
627
+ `/v1/businesses/${apiConfig.businessId}/entries/${entryId}/send`,
628
+ {
629
+ businessId: apiConfig.businessId,
630
+ entryId,
631
+ scheduledAt: scheduledAt || Date.now()
632
+ },
633
+ options
634
+ );
614
635
  },
615
- async createSubscription(params, options) {
636
+ // ===== VARIABLES / METADATA =====
637
+ async getVariableMetadata(params, options) {
638
+ return apiConfig.httpClient.get(
639
+ `/v1/collections/entry-types/${params.entryType}/variables`,
640
+ options
641
+ );
642
+ }
643
+ };
644
+ };
645
+
646
+ // src/api/eshop.ts
647
+ var createEshopApi = (apiConfig) => {
648
+ return {
649
+ // ===== PRODUCTS =====
650
+ async createProduct(params, options) {
616
651
  return apiConfig.httpClient.post(
617
- `/v1/businesses/${params.businessId}/subscription`,
652
+ `/v1/businesses/${apiConfig.businessId}/products`,
618
653
  params,
619
654
  options
620
655
  );
621
656
  },
622
- async updateSubscription(params, options) {
657
+ async updateProduct(params, options) {
623
658
  return apiConfig.httpClient.put(
624
- `/v1/businesses/${params.businessId}/subscription`,
659
+ `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
625
660
  params,
626
661
  options
627
662
  );
628
663
  },
629
- async cancelSubscription(params, options) {
630
- return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
631
- ...options,
632
- params: { immediately: params.immediately || false }
633
- });
634
- },
635
- async reactivateSubscription(params, options) {
636
- return apiConfig.httpClient.post(
637
- `/v1/businesses/${params.businessId}/subscription/reactivate`,
638
- params,
664
+ async deleteProduct(id, options) {
665
+ return apiConfig.httpClient.delete(
666
+ `/v1/businesses/${apiConfig.businessId}/products/${id}`,
639
667
  options
640
668
  );
641
669
  },
642
- async createPortalSession(params, options) {
643
- return apiConfig.httpClient.post(
644
- `/v1/businesses/${params.businessId}/subscription/portal`,
645
- params,
670
+ async getProduct(params, options) {
671
+ return apiConfig.httpClient.get(
672
+ `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
646
673
  options
647
674
  );
648
675
  },
649
- async inviteUser(params, options) {
650
- const { businessId, ...payload } = params;
676
+ async getProducts(params, options) {
677
+ const queryParams = params ? { ...params } : {};
678
+ return apiConfig.httpClient.get(
679
+ `/v1/businesses/${encodeURIComponent(apiConfig.businessId)}/products`,
680
+ {
681
+ ...options,
682
+ params: queryParams
683
+ }
684
+ );
685
+ },
686
+ // ===== ORDERS =====
687
+ async createOrder(params, options) {
651
688
  return apiConfig.httpClient.post(
652
- `/v1/businesses/${businessId}/invitation`,
653
- payload,
689
+ `/v1/businesses/${apiConfig.businessId}/orders`,
690
+ params,
654
691
  options
655
692
  );
656
693
  },
657
- async handleInvitation(params, options) {
658
- const { businessId, ...payload } = params;
694
+ async updateOrder(params, options) {
659
695
  return apiConfig.httpClient.put(
660
- `/v1/businesses/${businessId}/invitation`,
661
- payload,
696
+ `/v1/businesses/${apiConfig.businessId}/orders/update`,
697
+ params,
662
698
  options
663
699
  );
664
700
  },
665
- async testWebhook(params, options) {
666
- return apiConfig.httpClient.post(
667
- `/v1/businesses/${params.businessId}/webhooks/test`,
668
- params.webhook,
701
+ async getOrder(params, options) {
702
+ return apiConfig.httpClient.get(
703
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
669
704
  options
670
705
  );
671
706
  },
672
- async getBusinessMedia(params, options) {
707
+ async getOrders(params, options) {
673
708
  return apiConfig.httpClient.get(
674
- `/v1/businesses/${params.id}/media`,
709
+ `/v1/businesses/${apiConfig.businessId}/orders`,
675
710
  {
676
711
  ...options,
677
- params: {
678
- cursor: params.cursor,
679
- limit: params.limit || 20
680
- }
712
+ params: params || {}
681
713
  }
682
714
  );
683
715
  },
684
- async setProviderSchedule(params, options) {
685
- const { id, ...payload } = params;
716
+ async updateOrderStatus(params, options) {
686
717
  return apiConfig.httpClient.put(
687
- `/v1/businesses/${id}/schedules`,
718
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
719
+ params,
720
+ options
721
+ );
722
+ },
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
+ );
729
+ },
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);
748
+ },
749
+ async checkout(params, options) {
750
+ const payload = {
751
+ businessId: apiConfig.businessId,
752
+ market: apiConfig.market,
753
+ paymentMethod: params.paymentMethod,
754
+ shippingMethodId: params.shippingMethodId,
755
+ items: params.items,
756
+ blocks: params.blocks || [],
757
+ ...params.promoCode && { promoCode: params.promoCode }
758
+ };
759
+ return apiConfig.httpClient.post(
760
+ `/v1/businesses/${apiConfig.businessId}/orders/checkout`,
688
761
  payload,
689
762
  options
690
763
  );
@@ -692,171 +765,254 @@ var createBusinessApi = (apiConfig) => {
692
765
  };
693
766
  };
694
767
 
695
- // src/api/media.ts
696
- var createMediaApi = (apiConfig) => {
768
+ // src/api/reservation.ts
769
+ var createReservationApi = (apiConfig) => {
697
770
  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
- }
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
711
777
  });
712
- if (!response.ok) {
713
- throw new Error("Upload failed, server said no");
714
- }
715
- return await response.json();
716
778
  },
717
- async deleteBusinessMedia(params, options) {
718
- const { id, mediaId } = params;
719
- return apiConfig.httpClient.delete(
720
- `/v1/businesses/${id}/upload`,
721
- {
722
- ...options,
723
- params: { mediaId }
724
- }
725
- );
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
785
+ });
726
786
  },
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);
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
+ });
748
801
  },
749
- async updateRole(params, options) {
750
- return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, 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
+ });
751
807
  },
752
- async deleteRole(params, options) {
753
- return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
808
+ async getReservationParts(params, options) {
809
+ return apiConfig.httpClient.get(`/v1/reservations/parts`, {
810
+ ...options,
811
+ params: params || {}
812
+ });
754
813
  },
755
- async getRole(params, options) {
756
- return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
814
+ async searchReservations(params, options) {
815
+ return apiConfig.httpClient.get(`/v1/reservations/search`, {
816
+ ...options,
817
+ params
818
+ });
819
+ },
820
+ async searchMyReservations(params, options) {
821
+ return apiConfig.httpClient.get(`/v1/reservations`, {
822
+ ...options,
823
+ params: params || {}
824
+ });
825
+ },
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);
757
842
  },
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"
843
+ // ===== SERVICES =====
844
+ async createService(params, options) {
845
+ return apiConfig.httpClient.post(
846
+ `/v1/businesses/${apiConfig.businessId}/services`,
847
+ params,
848
+ {
849
+ successMessage: "Service created successfully",
850
+ errorMessage: "Failed to create service",
851
+ ...options
767
852
  }
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
853
+ );
854
+ },
855
+ async updateService(params, options) {
856
+ return apiConfig.httpClient.put(
857
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
858
+ params,
859
+ {
860
+ successMessage: "Service updated successfully",
861
+ errorMessage: "Failed to update service",
862
+ ...options
782
863
  }
783
- });
864
+ );
784
865
  },
785
- async updateNotifications(options) {
786
- return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
866
+ async deleteService(params, options) {
867
+ return apiConfig.httpClient.delete(
868
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
869
+ {
870
+ successMessage: "Service deleted successfully",
871
+ errorMessage: "Failed to delete service",
872
+ ...options
873
+ }
874
+ );
787
875
  },
788
- async trackEmailOpen(params, options) {
876
+ async getService(params, options) {
789
877
  return apiConfig.httpClient.get(
790
- `/v1/notifications/track/email/${params.trackingPixelId}`,
878
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
791
879
  options
792
880
  );
793
881
  },
794
- async getDeliveryStats(params, options) {
882
+ async getServices(params, options) {
883
+ const queryParams = params ? { ...params } : {};
795
884
  return apiConfig.httpClient.get(
796
- `/v1/notifications/track/stats/${apiConfig.businessId}`,
797
- options
885
+ `/v1/businesses/${apiConfig.businessId}/services`,
886
+ {
887
+ ...options,
888
+ params: queryParams
889
+ }
798
890
  );
799
- }
800
- };
801
- };
802
-
803
- // src/api/promoCode.ts
804
- var createPromoCodeApi = (apiConfig) => {
805
- return {
806
- async createPromoCode(params, options) {
891
+ },
892
+ async getAvailableSlots(params, options) {
893
+ const { serviceId, ...queryParams } = params;
894
+ return apiConfig.httpClient.get(
895
+ `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
896
+ {
897
+ ...options,
898
+ params: {
899
+ ...queryParams,
900
+ limit: queryParams.limit || 1e3
901
+ }
902
+ }
903
+ );
904
+ },
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
  };
@@ -868,150 +1024,21 @@ var createPaymentApi = (apiConfig) => {
868
1024
  return apiConfig.httpClient.post(`/v1/payments/webhooks/stripe`, params, options);
869
1025
  },
870
1026
  async getBusinessMarkets(params, options) {
871
- return apiConfig.httpClient.get(
872
- `/v1/payments/businesses/${apiConfig.businessId}/markets`,
873
- options
874
- );
875
- },
876
- async getBusinessMarket(params, options) {
877
- return apiConfig.httpClient.get(
878
- `/v1/payments/businesses/${apiConfig.businessId}/markets/${params.marketId}`,
879
- options
880
- );
881
- }
882
- };
883
- };
884
-
885
- // src/utils/blocks.ts
886
- function getBlockLabel(block, locale = "en") {
887
- if (!block) return "";
888
- if (block.properties?.label) {
889
- if (typeof block.properties.label === "object") {
890
- return block.properties.label[locale] || block.properties.label.en || Object.values(block.properties.label)[0] || "";
891
- }
892
- if (typeof block.properties.label === "string") {
893
- return block.properties.label;
894
- }
895
- }
896
- return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) || "";
897
- }
898
- function formatBlockValue(block) {
899
- if (!block || block.value === null || block.value === void 0) {
900
- return "";
901
- }
902
- switch (block.type) {
903
- case "BOOLEAN":
904
- return block.value ? "Yes" : "No";
905
- case "NUMBER":
906
- if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
907
- try {
908
- return new Date(block.value).toLocaleDateString();
909
- } catch (e) {
910
- return String(block.value);
911
- }
912
- }
913
- return String(block.value);
914
- case "RELATIONSHIP":
915
- if (Array.isArray(block.value) && block.value.length > 0) {
916
- const firstValue = block.value[0];
917
- if (firstValue && firstValue.mimeType) {
918
- return firstValue.name || firstValue.id || "Media";
919
- }
920
- return firstValue.title || firstValue.name || firstValue.id || "Entry";
921
- }
922
- return String(block.value);
923
- default:
924
- return String(block.value);
925
- }
926
- }
927
- function prepareBlocksForSubmission(formData) {
928
- const preparedBlocks = [];
929
- Object.keys(formData).forEach((key) => {
930
- if (formData[key] !== null && formData[key] !== void 0) {
931
- preparedBlocks.push({
932
- key,
933
- value: [formData[key]]
934
- });
935
- }
936
- });
937
- return preparedBlocks;
938
- }
939
- function extractBlockValues(blocks) {
940
- const values = {};
941
- blocks.forEach((block) => {
942
- if (block.value && block.value.length > 0) {
943
- values[block.key] = block.value[0];
944
- } else {
945
- values[block.key] = null;
946
- }
947
- });
948
- return values;
949
- }
950
- function getBlockTextValue(block, locale = "en") {
951
- if (!block || !block.value || block.value.length === 0) return "";
952
- const firstValue = block.value[0];
953
- if (typeof firstValue === "object" && firstValue !== null) {
954
- if (firstValue[locale]) return firstValue[locale];
955
- if (firstValue.en) return firstValue.en;
956
- const values = Object.values(firstValue);
957
- return String(values[0] || "");
958
- }
959
- return String(firstValue);
960
- }
961
- var getBlockValue = (entry, blockKey) => {
962
- if (!entry || !entry.blocks) return null;
963
- const block = entry.blocks.find((f) => f.key === blockKey);
964
- if (!block || !block.value || block.value.length === 0) return null;
965
- return block.value[0];
966
- };
967
- var getBlockValues = (entry, blockKey) => {
968
- if (!entry || !entry.blocks) return null;
969
- const block = entry.blocks.find((f) => f.key === blockKey);
970
- if (!block || !block.value || block.value.length === 0) return null;
971
- return block.value;
972
- };
973
- function unwrapBlock(block, locale) {
974
- if (!block?.type || block.value === void 0) return block;
975
- if (block.type === "BLOCK") {
976
- return block.value.map((obj) => {
977
- const parsed = {};
978
- for (const [k, v] of Object.entries(obj)) {
979
- parsed[k] = unwrapBlock(v, locale);
980
- }
981
- return parsed;
982
- });
983
- }
984
- const isLocalized = block.type === "TEXT";
985
- const isList = block.properties?.ui === "list" || (block.properties?.maxValues ?? 1) > 1 || block.value.length > 1;
986
- if (isList) {
987
- return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
988
- }
989
- return isLocalized ? block.value[0][locale] || block.value[0]["en"] : block.value[0];
990
- }
991
- var getBlockObjectValues = (entry, blockKey, locale = "en") => {
992
- if (!entry) {
993
- return [];
994
- }
995
- const values = getBlockValues(entry, blockKey);
996
- const parsed = values.map((obj) => {
997
- const res = obj.value.reduce((acc, current) => {
998
- acc[current.key] = unwrapBlock(current, locale);
999
- return acc;
1000
- }, {});
1001
- return res;
1002
- });
1003
- return parsed;
1004
- };
1005
- var getBlockFromArray = (entry, blockKey, locale = "en") => {
1006
- if (!entry) {
1007
- return [];
1008
- }
1009
- const values = getBlockValues(entry, blockKey);
1010
- return values.reduce((acc, current) => {
1011
- acc[current.key] = unwrapBlock(current, locale);
1012
- return acc;
1013
- });
1027
+ return apiConfig.httpClient.get(
1028
+ `/v1/payments/businesses/${apiConfig.businessId}/markets`,
1029
+ options
1030
+ );
1031
+ },
1032
+ async getBusinessMarket(params, options) {
1033
+ return apiConfig.httpClient.get(
1034
+ `/v1/payments/businesses/${apiConfig.businessId}/markets/${params.marketId}`,
1035
+ options
1036
+ );
1037
+ }
1038
+ };
1014
1039
  };
1040
+
1041
+ // src/utils/blocks.ts
1015
1042
  var getImageUrl = (imageBlock, isBlock = true, storageUrl = "https://storage.arky.io/dev") => {
1016
1043
  if (!imageBlock) return null;
1017
1044
  const isExternalUrl = (url) => {
@@ -1063,20 +1090,6 @@ function thumbnailUrl(service, storageUrl = "") {
1063
1090
  const path = getGalleryThumbnail(service.gallery);
1064
1091
  return path ? `${storageUrl}/${path}` : null;
1065
1092
  }
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
1093
 
1081
1094
  // src/utils/currency.ts
1082
1095
  function getCurrencySymbol(currency) {
@@ -1167,143 +1180,6 @@ function isSymbolAfterCurrency(currency) {
1167
1180
  return SYMBOL_AFTER_CURRENCIES.includes(currency.toUpperCase());
1168
1181
  }
1169
1182
 
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
1183
  // src/utils/price.ts
1308
1184
  var MARKET_CURRENCIES = {
1309
1185
  "US": "USD",
@@ -1315,9 +1191,6 @@ var MARKET_CURRENCIES = {
1315
1191
  function convertToMajor(minorAmount) {
1316
1192
  return (minorAmount ?? 0) / 100;
1317
1193
  }
1318
- function convertToMinor(majorAmount) {
1319
- return Math.round((majorAmount ?? 0) * 100);
1320
- }
1321
1194
  function getCurrencyFromMarket(marketId) {
1322
1195
  return MARKET_CURRENCIES[marketId] || "USD";
1323
1196
  }
@@ -1426,108 +1299,19 @@ function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMeth
1426
1299
  };
1427
1300
  }
1428
1301
 
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 "";
1302
+ // src/utils/validation.ts
1303
+ function validatePhoneNumber(phone) {
1304
+ if (!phone) {
1305
+ return { isValid: false, error: "Phone number is required" };
1479
1306
  }
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);
1307
+ const cleaned = phone.replace(/\D/g, "");
1308
+ if (cleaned.length < 8) {
1309
+ return { isValid: false, error: "Phone number is too short" };
1496
1310
  }
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
- );
1515
- }
1516
- function categorify(text) {
1517
- const slugifiedText = slugify(text);
1518
- return slugifiedText.replace(/-/g, " ").toUpperCase();
1519
- }
1520
- function formatDate(date, locale) {
1521
- let localeString = "en-US";
1522
- if (locales.includes(locale)) {
1523
- localeString = localeMap[locale];
1311
+ if (cleaned.length > 15) {
1312
+ return { isValid: false, error: "Phone number is too long" };
1524
1313
  }
1525
- return new Date(date).toLocaleDateString(localeString, {
1526
- timeZone: "UTC",
1527
- year: "numeric",
1528
- month: "short",
1529
- day: "numeric"
1530
- });
1314
+ return { isValid: true };
1531
1315
  }
1532
1316
 
1533
1317
  // src/utils/timezone.ts
@@ -1576,177 +1360,8 @@ function findTimeZone(groups) {
1576
1360
  }
1577
1361
  }
1578
1362
 
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 };
1592
- }
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 };
1602
- }
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 };
1612
- }
1613
- function validateRequired(value, fieldName = "This field") {
1614
- if (value === null || value === void 0 || value === "") {
1615
- return { isValid: false, error: `${fieldName} is required` };
1616
- }
1617
- return { isValid: true };
1618
- }
1619
-
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;
1627
- }
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;
1655
- }
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" });
1723
- }
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
- }
1737
- return data;
1738
- }
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
- }
1747
-
1748
1363
  // src/index.ts
1749
- var SDK_VERSION = "0.3.7";
1364
+ var SDK_VERSION = "0.3.8";
1750
1365
  var SUPPORTED_FRAMEWORKS = [
1751
1366
  "astro",
1752
1367
  "react",
@@ -1831,6 +1446,6 @@ function createArkySDK(config) {
1831
1446
  return sdk;
1832
1447
  }
1833
1448
 
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 };
1449
+ export { SDK_VERSION, SUPPORTED_FRAMEWORKS, createArkySDK };
1835
1450
  //# sourceMappingURL=index.js.map
1836
1451
  //# sourceMappingURL=index.js.map