arky-sdk 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,19 +1,5 @@
1
1
  'use strict';
2
2
 
3
- // src/config.ts
4
- var globalConfig = null;
5
- function setGlobalConfig(config) {
6
- globalConfig = config;
7
- }
8
- function getGlobalConfig() {
9
- if (!globalConfig) {
10
- throw new Error(
11
- "Arky SDK not initialized. Call initArky() first."
12
- );
13
- }
14
- return globalConfig;
15
- }
16
-
17
3
  // src/types/index.ts
18
4
  var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
19
5
  PaymentMethod2["Cash"] = "CASH";
@@ -22,725 +8,888 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
22
8
  return PaymentMethod2;
23
9
  })(PaymentMethod || {});
24
10
 
25
- // src/utils/queryParams.ts
26
- function buildQueryString(params) {
27
- const queryParts = [];
28
- Object.entries(params).forEach(([key, value]) => {
29
- if (value === null || value === void 0) {
30
- return;
31
- }
32
- if (Array.isArray(value)) {
33
- const jsonString = JSON.stringify(value);
34
- queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
35
- } else if (typeof value === "string") {
36
- queryParts.push(`${key}=${encodeURIComponent(value)}`);
37
- } else if (typeof value === "number" || typeof value === "boolean") {
38
- queryParts.push(`${key}=${value}`);
39
- } else if (typeof value === "object") {
40
- const jsonString = JSON.stringify(value);
41
- queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
42
- }
43
- });
44
- return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
45
- }
46
- function appendQueryString(url, params) {
47
- const queryString = buildQueryString(params);
48
- return queryString ? `${url}${queryString}` : url;
49
- }
50
-
51
- // src/services/http.ts
52
- async function get(url, options) {
53
- try {
54
- const finalUrl = options?.params ? appendQueryString(url, options.params) : url;
55
- const response = await fetch(finalUrl);
56
- if (!response.ok) {
57
- throw new Error(`HTTP error! status: ${response.status}`);
58
- }
59
- const data = await response.json();
60
- return {
61
- value: data,
62
- success: true
63
- };
64
- } catch (error) {
65
- const errorMsg = error instanceof Error ? error.message : "Unknown error occurred";
66
- return {
67
- value: null,
68
- success: false,
69
- error: errorMsg
70
- };
71
- }
72
- }
73
- async function post(url, data, options) {
74
- try {
75
- const response = await fetch(url, {
76
- method: "POST",
77
- headers: {
78
- "Content-Type": "application/json"
79
- },
80
- body: JSON.stringify(data)
81
- });
82
- if (!response.ok) {
83
- throw new Error(`HTTP error! status: ${response.status}`);
11
+ // src/api/cms.ts
12
+ var createCmsApi = (apiConfig) => {
13
+ return {
14
+ // ===== COLLECTIONS =====
15
+ async createCollection(params, options) {
16
+ return apiConfig.httpClient.post(
17
+ `/v1/businesses/${apiConfig.businessId}/collections`,
18
+ params,
19
+ options
20
+ );
21
+ },
22
+ async updateCollection(params, options) {
23
+ return apiConfig.httpClient.put(
24
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
25
+ params,
26
+ options
27
+ );
28
+ },
29
+ async deleteCollection(params, options) {
30
+ return apiConfig.httpClient.delete(
31
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
32
+ options
33
+ );
34
+ },
35
+ async getCollection(params, options) {
36
+ return apiConfig.httpClient.get(
37
+ `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
38
+ options
39
+ );
40
+ },
41
+ async getCollections(params, options) {
42
+ return apiConfig.httpClient.get(
43
+ `/v1/businesses/${apiConfig.businessId}/collections`,
44
+ {
45
+ ...options,
46
+ params: params || {}
47
+ }
48
+ );
49
+ },
50
+ async generateBlocks(params, options) {
51
+ return apiConfig.httpClient.post(
52
+ `/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
53
+ params,
54
+ options
55
+ );
56
+ },
57
+ // ===== ENTRIES =====
58
+ // Note: Backend uses /entries NOT /collections/{id}/entries
59
+ async getCollectionEntries(params, options) {
60
+ const { collectionId, ...queryParams } = params || {};
61
+ const finalParams = collectionId ? { ...queryParams, owner: `collection:${collectionId}` } : queryParams;
62
+ return apiConfig.httpClient.get(
63
+ `/v1/businesses/${apiConfig.businessId}/entries`,
64
+ {
65
+ ...options,
66
+ params: finalParams
67
+ }
68
+ );
69
+ },
70
+ async createCollectionEntry(params, options) {
71
+ const { collectionId, owner, ...rest } = params;
72
+ const payload = {
73
+ ...rest,
74
+ owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
75
+ };
76
+ return apiConfig.httpClient.post(
77
+ `/v1/businesses/${apiConfig.businessId}/entries`,
78
+ payload,
79
+ options
80
+ );
81
+ },
82
+ async updateCollectionEntry(params, options) {
83
+ const { id, collectionId, owner, ...rest } = params;
84
+ const payload = {
85
+ ...rest,
86
+ owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
87
+ };
88
+ return apiConfig.httpClient.put(
89
+ `/v1/businesses/${apiConfig.businessId}/entries/${id}`,
90
+ payload,
91
+ options
92
+ );
93
+ },
94
+ async deleteCollectionEntry(params, options) {
95
+ return apiConfig.httpClient.delete(
96
+ `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
97
+ options
98
+ );
99
+ },
100
+ async getCollectionEntry(params, options) {
101
+ return apiConfig.httpClient.get(
102
+ `/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
103
+ options
104
+ );
105
+ },
106
+ async sendEntry(params, options) {
107
+ const { entryId, scheduledAt } = params;
108
+ return apiConfig.httpClient.post(
109
+ `/v1/businesses/${apiConfig.businessId}/entries/${entryId}/send`,
110
+ {
111
+ businessId: apiConfig.businessId,
112
+ entryId,
113
+ scheduledAt: scheduledAt || Date.now()
114
+ },
115
+ options
116
+ );
117
+ },
118
+ // ===== VARIABLES / METADATA =====
119
+ async getVariableMetadata(params, options) {
120
+ return apiConfig.httpClient.get(
121
+ `/v1/collections/entry-types/${params.entryType}/variables`,
122
+ options
123
+ );
84
124
  }
85
- const responseData = await response.json();
86
- return {
87
- value: responseData,
88
- success: true
89
- };
90
- } catch (error) {
91
- const errorMsg = error instanceof Error ? error.message : "Unknown error occurred";
92
- return {
93
- value: null,
94
- success: false,
95
- error: errorMsg
96
- };
97
- }
98
- }
99
- var httpClient = {
100
- get,
101
- post
125
+ };
102
126
  };
103
- var http_default = httpClient;
104
127
 
105
- // src/api/cms.ts
106
- var getCollection = async (id) => {
107
- const config = getGlobalConfig();
108
- const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${id}`;
109
- const { value } = await http_default.get(url);
110
- return value;
111
- };
112
- var getCollections = async ({ name = null, ids = null }) => {
113
- const config = getGlobalConfig();
114
- const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections`;
115
- const response = await http_default.get(url, {
116
- params: { name, ids }
117
- });
118
- return response.value;
119
- };
120
- var getCollectionEntries = async ({
121
- collectionId,
122
- limit,
123
- cursor,
124
- ids = null
125
- }) => {
126
- const config = getGlobalConfig();
127
- const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries`;
128
- const response = await http_default.get(url, {
129
- params: { limit, cursor, ids }
130
- });
131
- return response.value;
132
- };
133
- var createCollectionEntry = async (collectionEntryData) => {
134
- const config = getGlobalConfig();
135
- const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionEntryData.collectionId}/entries`;
136
- const result = await http_default.post(url, collectionEntryData, {
137
- successMessage: "Created successfully",
138
- errorMessage: "Failed to create collection"
139
- });
140
- return result;
141
- };
142
- var getCollectionEntry = async ({ collectionId, id }) => {
143
- const config = getGlobalConfig();
144
- const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries/${id}`;
145
- const response = await http_default.get(url);
146
- return response;
147
- };
148
- var cmsApi = {
149
- getCollection,
150
- getCollections,
151
- getCollectionEntries,
152
- getCollectionEntry,
153
- createCollectionEntry
128
+ // src/api/eshop.ts
129
+ var createEshopApi = (apiConfig) => {
130
+ return {
131
+ // ===== PRODUCTS =====
132
+ async createProduct(params, options) {
133
+ return apiConfig.httpClient.post(
134
+ `/v1/businesses/${apiConfig.businessId}/products`,
135
+ params,
136
+ options
137
+ );
138
+ },
139
+ async updateProduct(params, options) {
140
+ return apiConfig.httpClient.put(
141
+ `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
142
+ params,
143
+ options
144
+ );
145
+ },
146
+ async deleteProduct(id, options) {
147
+ return apiConfig.httpClient.delete(
148
+ `/v1/businesses/${apiConfig.businessId}/products/${id}`,
149
+ options
150
+ );
151
+ },
152
+ async getProduct(params, options) {
153
+ return apiConfig.httpClient.get(
154
+ `/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
155
+ options
156
+ );
157
+ },
158
+ async getProducts(params, options) {
159
+ const queryParams = params ? { ...params } : {};
160
+ return apiConfig.httpClient.get(
161
+ `/v1/businesses/${encodeURIComponent(apiConfig.businessId)}/products`,
162
+ {
163
+ ...options,
164
+ params: queryParams
165
+ }
166
+ );
167
+ },
168
+ async getProductBySlug(params, options) {
169
+ const { businessId, slug } = params;
170
+ return apiConfig.httpClient.get(
171
+ `/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`,
172
+ options
173
+ );
174
+ },
175
+ // ===== ORDERS =====
176
+ async createOrder(params, options) {
177
+ return apiConfig.httpClient.post(
178
+ `/v1/businesses/${apiConfig.businessId}/orders`,
179
+ params,
180
+ options
181
+ );
182
+ },
183
+ async updateOrder(params, options) {
184
+ return apiConfig.httpClient.put(
185
+ `/v1/businesses/${apiConfig.businessId}/orders/update`,
186
+ params,
187
+ options
188
+ );
189
+ },
190
+ async getOrder(params, options) {
191
+ return apiConfig.httpClient.get(
192
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
193
+ options
194
+ );
195
+ },
196
+ async getOrders(params, options) {
197
+ return apiConfig.httpClient.get(
198
+ `/v1/businesses/${apiConfig.businessId}/orders`,
199
+ {
200
+ ...options,
201
+ params: params || {}
202
+ }
203
+ );
204
+ },
205
+ async updateOrderStatus(params, options) {
206
+ return apiConfig.httpClient.put(
207
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
208
+ params,
209
+ options
210
+ );
211
+ },
212
+ async updateOrderPaymentStatus(params, options) {
213
+ return apiConfig.httpClient.put(
214
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/payment-status`,
215
+ params,
216
+ options
217
+ );
218
+ },
219
+ // ===== PAYMENTS =====
220
+ async getQuote(params, options) {
221
+ const lines = params.items.map((item) => ({
222
+ type: "PRODUCT_VARIANT",
223
+ productId: item.productId,
224
+ variantId: item.variantId,
225
+ quantity: item.quantity
226
+ }));
227
+ const payload = {
228
+ businessId: apiConfig.businessId,
229
+ market: params.market,
230
+ currency: params.currency,
231
+ paymentMethod: params.paymentMethod,
232
+ lines,
233
+ ...params.shippingMethodId && { shippingMethodId: params.shippingMethodId },
234
+ ...params.promoCode && { promoCode: params.promoCode }
235
+ };
236
+ return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
237
+ },
238
+ async checkout(params, options) {
239
+ const payload = {
240
+ businessId: apiConfig.businessId,
241
+ market: params.market,
242
+ paymentMethod: params.paymentMethod,
243
+ shippingMethodId: params.shippingMethodId,
244
+ items: params.items,
245
+ blocks: params.blocks || [],
246
+ ...params.promoCode && { promoCode: params.promoCode }
247
+ };
248
+ return apiConfig.httpClient.post(
249
+ `/v1/businesses/${apiConfig.businessId}/orders/checkout`,
250
+ payload,
251
+ options
252
+ );
253
+ }
254
+ };
154
255
  };
155
256
 
156
257
  // src/api/reservation.ts
157
- var reservationApi = {
158
- // Get quote for reservation parts
159
- async getQuote({
160
- token,
161
- businessId,
162
- market,
163
- currency,
164
- userId,
165
- parts,
166
- paymentMethod = "CASH",
167
- promoCode
168
- }) {
169
- try {
170
- const config = getGlobalConfig();
171
- const lines = parts.map((part) => ({
258
+ var createReservationApi = (apiConfig) => {
259
+ return {
260
+ // ===== RESERVATIONS =====
261
+ async createReservation(params, options) {
262
+ return apiConfig.httpClient.post(`/v1/reservations`, params, {
263
+ successMessage: "Reservation created successfully",
264
+ errorMessage: "Failed to create reservation",
265
+ ...options
266
+ });
267
+ },
268
+ async updateReservation(params, options) {
269
+ const { id, ...payload } = params;
270
+ return apiConfig.httpClient.put(`/v1/reservations/${id}`, payload, {
271
+ successMessage: "Reservation updated successfully",
272
+ errorMessage: "Failed to update reservation",
273
+ ...options
274
+ });
275
+ },
276
+ async checkout(params, options) {
277
+ const payload = {
278
+ businessId: apiConfig.businessId,
279
+ blocks: params.blocks || [],
280
+ market: params.market || "US",
281
+ parts: params.parts,
282
+ ...params.paymentMethod && { paymentMethod: params.paymentMethod },
283
+ ...params.promoCode && { promoCode: params.promoCode }
284
+ };
285
+ return apiConfig.httpClient.post(`/v1/reservations/checkout`, payload, {
286
+ successMessage: "Reservation checkout completed",
287
+ errorMessage: "Failed to complete checkout",
288
+ ...options
289
+ });
290
+ },
291
+ async getReservation(params, options) {
292
+ return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
293
+ ...options,
294
+ params: params.businessId ? { businessId: params.businessId } : {}
295
+ });
296
+ },
297
+ async getReservationParts(params, options) {
298
+ return apiConfig.httpClient.get(`/v1/reservations/parts`, {
299
+ ...options,
300
+ params: params || {}
301
+ });
302
+ },
303
+ async searchReservations(params, options) {
304
+ return apiConfig.httpClient.get(`/v1/reservations/search`, {
305
+ ...options,
306
+ params
307
+ });
308
+ },
309
+ async searchMyReservations(params, options) {
310
+ return apiConfig.httpClient.get(`/v1/reservations`, {
311
+ ...options,
312
+ params: params || {}
313
+ });
314
+ },
315
+ // ===== QUOTES =====
316
+ async getQuote(params, options) {
317
+ const lines = params.parts.map((part) => ({
172
318
  type: "SERVICE",
173
319
  serviceId: part.serviceId,
174
320
  quantity: 1
175
321
  }));
176
322
  const payload = {
177
- businessId,
178
- market,
179
- currency,
180
- userId,
181
- paymentMethod,
323
+ businessId: apiConfig.businessId,
324
+ market: params.market,
325
+ currency: params.currency,
326
+ paymentMethod: params.paymentMethod,
182
327
  lines,
183
- promoCode: promoCode || void 0,
184
- shippingMethodId: null
328
+ ...params.promoCode && { promoCode: params.promoCode }
185
329
  };
186
- const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
187
- method: "POST",
188
- headers: {
189
- "Content-Type": "application/json",
190
- "Authorization": `Bearer ${token}`
191
- },
192
- body: JSON.stringify(payload)
193
- });
194
- const text = await res.text();
195
- if (!res.ok) {
196
- try {
197
- const json = JSON.parse(text);
198
- return { success: false, error: json.reason || json.error || "Failed to fetch quote", code: json.code };
199
- } catch {
200
- return { success: false, error: text || "Failed to fetch quote" };
330
+ return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
331
+ },
332
+ // ===== SERVICES =====
333
+ async createService(params, options) {
334
+ return apiConfig.httpClient.post(
335
+ `/v1/businesses/${apiConfig.businessId}/services`,
336
+ params,
337
+ {
338
+ successMessage: "Service created successfully",
339
+ errorMessage: "Failed to create service",
340
+ ...options
201
341
  }
202
- }
203
- const quote = text ? JSON.parse(text) : null;
204
- return { success: true, data: quote };
205
- } catch (e) {
206
- return {
207
- success: false,
208
- error: e.message || "Failed to fetch quote"
209
- };
210
- }
211
- },
212
- // Get available slots for a service
213
- async getAvailableSlots({
214
- businessId,
215
- serviceId,
216
- from,
217
- to,
218
- limit = 1e3,
219
- providerId = null
220
- }) {
221
- const config = getGlobalConfig();
222
- const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
223
- const response = await http_default.get(url, {
224
- params: {
225
- from,
226
- to,
227
- limit,
228
- providerId
229
- }
230
- });
231
- if (response.success) {
232
- const json = response.value;
233
- return {
234
- success: true,
235
- data: json.data?.items || json.items || []
236
- };
237
- } else {
238
- console.error("Error fetching available slots:", response.error);
239
- return {
240
- success: false,
241
- error: response.error,
242
- data: []
243
- };
244
- }
245
- },
246
- // Get all providers for a service
247
- async getProviders({ businessId, serviceId, limit = 50 }) {
248
- const config = getGlobalConfig();
249
- const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
250
- const response = await http_default.get(url, {
251
- params: {
252
- serviceId,
253
- limit
254
- }
255
- });
256
- if (response.success) {
257
- const json = response.value;
258
- return {
259
- success: true,
260
- data: json.items || []
261
- };
262
- } else {
263
- console.error("Error loading providers:", response.error);
264
- return {
265
- success: false,
266
- error: response.error,
267
- data: []
268
- };
342
+ );
343
+ },
344
+ async updateService(params, options) {
345
+ return apiConfig.httpClient.put(
346
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
347
+ params,
348
+ {
349
+ successMessage: "Service updated successfully",
350
+ errorMessage: "Failed to update service",
351
+ ...options
352
+ }
353
+ );
354
+ },
355
+ async deleteService(params, options) {
356
+ return apiConfig.httpClient.delete(
357
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
358
+ {
359
+ successMessage: "Service deleted successfully",
360
+ errorMessage: "Failed to delete service",
361
+ ...options
362
+ }
363
+ );
364
+ },
365
+ async getService(params, options) {
366
+ return apiConfig.httpClient.get(
367
+ `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
368
+ options
369
+ );
370
+ },
371
+ async getServices(params, options) {
372
+ const queryParams = params ? { ...params } : {};
373
+ return apiConfig.httpClient.get(
374
+ `/v1/businesses/${apiConfig.businessId}/services`,
375
+ {
376
+ ...options,
377
+ params: queryParams
378
+ }
379
+ );
380
+ },
381
+ async getAvailableSlots(params, options) {
382
+ const { serviceId, ...queryParams } = params;
383
+ return apiConfig.httpClient.get(
384
+ `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
385
+ {
386
+ ...options,
387
+ params: {
388
+ ...queryParams,
389
+ limit: queryParams.limit || 1e3
390
+ }
391
+ }
392
+ );
393
+ },
394
+ // ===== PROVIDERS =====
395
+ async createProvider(params, options) {
396
+ return apiConfig.httpClient.post(
397
+ `/v1/businesses/${apiConfig.businessId}/providers`,
398
+ params,
399
+ {
400
+ successMessage: "Provider created successfully",
401
+ errorMessage: "Failed to create provider",
402
+ ...options
403
+ }
404
+ );
405
+ },
406
+ async updateProvider(params, options) {
407
+ return apiConfig.httpClient.put(
408
+ `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
409
+ params,
410
+ {
411
+ successMessage: "Provider updated successfully",
412
+ errorMessage: "Failed to update provider",
413
+ ...options
414
+ }
415
+ );
416
+ },
417
+ async deleteProvider(params, options) {
418
+ return apiConfig.httpClient.delete(
419
+ `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
420
+ {
421
+ successMessage: "Provider deleted successfully",
422
+ errorMessage: "Failed to delete provider",
423
+ ...options
424
+ }
425
+ );
426
+ },
427
+ async getProvider(params, options) {
428
+ return apiConfig.httpClient.get(
429
+ `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
430
+ options
431
+ );
432
+ },
433
+ async getProviders(params, options) {
434
+ const { businessId, ...queryParams } = params;
435
+ return apiConfig.httpClient.get(
436
+ `/v1/businesses/${apiConfig.businessId}/providers`,
437
+ {
438
+ ...options,
439
+ params: queryParams
440
+ }
441
+ );
442
+ },
443
+ async getProviderWorkingTime(params, options) {
444
+ const { businessId, providerId, ...queryParams } = params;
445
+ return apiConfig.httpClient.get(
446
+ `/v1/businesses/${apiConfig.businessId}/providers/${providerId}/working-time`,
447
+ {
448
+ ...options,
449
+ params: queryParams
450
+ }
451
+ );
269
452
  }
270
- },
271
- // Get guest token or create a new one
272
- async getGuestToken() {
273
- try {
274
- const config = getGlobalConfig();
275
- const res = await fetch(`${config.apiUrl}/v1/users/login`, {
276
- method: "POST",
277
- headers: { "Content-Type": "application/json" },
278
- body: JSON.stringify({ provider: "GUEST" })
453
+ };
454
+ };
455
+
456
+ // src/api/newsletter.ts
457
+ var createNewsletterApi = (apiConfig) => {
458
+ return {
459
+ // ===== NEWSLETTERS =====
460
+ async find(params, options) {
461
+ return apiConfig.httpClient.get(`/v1/newsletters`, {
462
+ ...options,
463
+ params: { businessId: params.businessId }
279
464
  });
280
- if (!res.ok) throw new Error("Guest login failed");
281
- const json = await res.json();
282
- return {
283
- success: true,
284
- data: { token: json.accessToken }
285
- };
286
- } catch (e) {
287
- return {
288
- success: false,
289
- error: e.message
465
+ },
466
+ async get(params, options) {
467
+ return apiConfig.httpClient.get(`/v1/newsletters/${params.id}`, options);
468
+ },
469
+ async create(params, options) {
470
+ return apiConfig.httpClient.post(`/v1/newsletters`, params, options);
471
+ },
472
+ async update(params, options) {
473
+ return apiConfig.httpClient.put(`/v1/newsletters/${params.id}`, params, options);
474
+ },
475
+ async delete(params, options) {
476
+ return apiConfig.httpClient.delete(`/v1/newsletters/${params.id}`, options);
477
+ },
478
+ // ===== SUBSCRIBERS =====
479
+ async getSubscribers(params, options) {
480
+ return apiConfig.httpClient.get(`/v1/newsletters/${params.id}/subscribers`, options);
481
+ },
482
+ async subscribe(params, options) {
483
+ const { newsletterId, email, customerId, payment } = params;
484
+ const payload = {
485
+ newsletterId,
486
+ email,
487
+ market: "US",
488
+ ...customerId && { customerId },
489
+ ...payment && { payment }
290
490
  };
291
- }
292
- },
293
- // Update user's phone number
294
- async updateProfilePhone({ token, phoneNumber }) {
295
- try {
296
- const config = getGlobalConfig();
297
- const res = await fetch(`${config.apiUrl}/v1/users/update`, {
298
- method: "PUT",
299
- headers: {
300
- "Content-Type": "application/json",
301
- Authorization: `Bearer ${token}`
302
- },
303
- body: JSON.stringify({
304
- phoneNumber,
305
- phoneNumbers: [],
306
- addresses: []
307
- })
491
+ return apiConfig.httpClient.post(
492
+ `/v1/newsletters/${newsletterId}/subscribe`,
493
+ payload,
494
+ options
495
+ );
496
+ },
497
+ async unsubscribe(params, options) {
498
+ return apiConfig.httpClient.post(`/v1/newsletters/unsubscribe`, params, options);
499
+ },
500
+ async unsubscribeWithToken(params, options) {
501
+ return apiConfig.httpClient.get(`/v1/newsletters/unsubscribe`, {
502
+ ...options,
503
+ params
308
504
  });
309
- if (!res.ok) {
310
- const error = await res.text() || res.statusText;
311
- return {
312
- success: false,
313
- error
314
- };
315
- }
316
- return {
317
- success: true
318
- };
319
- } catch (e) {
320
- return {
321
- success: false,
322
- error: e.message
323
- };
324
505
  }
325
- },
326
- // Verify phone number with code
327
- async verifyPhoneCode({ token, phoneNumber, code }) {
328
- try {
329
- const config = getGlobalConfig();
330
- const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
331
- method: "PUT",
332
- headers: {
333
- "Content-Type": "application/json",
334
- Authorization: `Bearer ${token}`
335
- },
336
- body: JSON.stringify({
337
- phoneNumber,
338
- code
339
- })
340
- });
341
- if (!res.ok) {
342
- const error = await res.text() || res.statusText;
343
- return {
344
- success: false,
345
- error
346
- };
347
- }
348
- return {
349
- success: true
350
- };
351
- } catch (e) {
352
- return {
353
- success: false,
354
- error: e.message
506
+ };
507
+ };
508
+
509
+ // src/api/user.ts
510
+ var createUserApi = (apiConfig) => {
511
+ return {
512
+ // ===== USER PROFILE =====
513
+ async updateUser(params, options) {
514
+ const payload = {
515
+ name: params.name,
516
+ phoneNumbers: params.phoneNumbers || [],
517
+ phoneNumber: params.phoneNumber || null,
518
+ addresses: params.addresses || [],
519
+ ...params.apiTokens !== void 0 && { apiTokens: params.apiTokens }
355
520
  };
356
- }
357
- },
358
- // Complete reservation checkout - Backend calculates currency from market
359
- async checkout({
360
- token,
361
- businessId,
362
- parts,
363
- paymentMethod = "CASH",
364
- blocks = [],
365
- market = "US",
366
- promoCode
367
- }) {
368
- try {
369
- const config = getGlobalConfig();
521
+ return apiConfig.httpClient.put("/v1/users/update", payload, options);
522
+ },
523
+ async updateProfilePhone(params, options) {
370
524
  const payload = {
371
- businessId,
372
- blocks,
373
- market,
374
- parts: parts.map((p) => ({
375
- serviceId: p.serviceId,
376
- from: p.from,
377
- to: p.to,
378
- blocks: p.blocks,
379
- reservationMethod: p.reservationMethod,
380
- providerId: p.providerId
381
- }))
525
+ phoneNumbers: [],
526
+ phoneNumber: params.phoneNumber,
527
+ addresses: []
382
528
  };
383
- if (paymentMethod !== void 0) {
384
- payload.paymentMethod = paymentMethod;
385
- }
386
- if (promoCode) {
387
- payload.promoCode = promoCode;
388
- }
389
- const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
390
- method: "POST",
391
- headers: {
392
- "Content-Type": "application/json",
393
- Authorization: `Bearer ${token}`
394
- },
395
- body: JSON.stringify(payload)
529
+ return apiConfig.httpClient.put("/v1/users/update", payload, options);
530
+ },
531
+ async verifyPhoneCode(params, options) {
532
+ return apiConfig.httpClient.put("/v1/users/confirm/phone-number", params, options);
533
+ },
534
+ async getUserLocation(options) {
535
+ return apiConfig.httpClient.get("/v1/users/location", options);
536
+ },
537
+ async getMe(options) {
538
+ return apiConfig.httpClient.get("/v1/users/me", options);
539
+ },
540
+ async searchUsers(params, options) {
541
+ return apiConfig.httpClient.get("/v1/users/search", {
542
+ ...options,
543
+ params
544
+ });
545
+ },
546
+ async setUserRole(params, options) {
547
+ return apiConfig.httpClient.put("/v1/users/set-role", params, options);
548
+ },
549
+ // ===== AUTHENTICATION =====
550
+ async loginUser(params, options) {
551
+ return apiConfig.httpClient.post("/v1/users/login", params, options);
552
+ },
553
+ async registerUser(params, options) {
554
+ return apiConfig.httpClient.post("/v1/users/register", params, options);
555
+ },
556
+ async logout(options) {
557
+ return apiConfig.httpClient.post("/v1/users/logout", {}, options);
558
+ },
559
+ async confirmUser(params, options) {
560
+ return apiConfig.httpClient.put("/v1/users/confirm", params, options);
561
+ },
562
+ async getLoginUrl(params, options) {
563
+ return apiConfig.httpClient.get("/v1/users/login/url", {
564
+ ...options,
565
+ params
396
566
  });
397
- if (!res.ok) {
398
- const error = await res.text() || res.statusText;
399
- throw new Error(error);
567
+ },
568
+ async getGuestToken(params, options) {
569
+ if (params.existingToken) {
570
+ return params.existingToken;
400
571
  }
401
- const json = await res.json();
402
- return {
403
- success: true,
404
- data: json
405
- // Should include reservationId and clientSecret for payments
406
- };
407
- } catch (e) {
408
- return {
409
- success: false,
410
- error: e.message
411
- };
572
+ const result = await apiConfig.httpClient.post("/v1/users/login", {
573
+ provider: "GUEST"
574
+ }, options);
575
+ const token = result.accessToken || result.token || "";
576
+ if (token) {
577
+ apiConfig.setTokens(result);
578
+ }
579
+ return token;
580
+ },
581
+ // ===== PASSWORD MANAGEMENT =====
582
+ async forgotPassword(params, options) {
583
+ return apiConfig.httpClient.post("/v1/users/forgot-password", params, options);
584
+ },
585
+ async resetForgotPassword(params, options) {
586
+ return apiConfig.httpClient.post("/v1/users/reset-forgot-password", params, options);
587
+ },
588
+ async resetPassword(params, options) {
589
+ return apiConfig.httpClient.post("/v1/users/reset-password", params, options);
412
590
  }
413
- }
591
+ };
414
592
  };
415
593
 
416
- // src/api/eshop.ts
417
- var eshopApi = {
418
- // Get products
419
- async getProducts({
420
- businessId,
421
- categoryIds = null,
422
- status = "ACTIVE",
423
- limit = 20,
424
- cursor = null
425
- }) {
426
- const config = getGlobalConfig();
427
- const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
428
- const response = await http_default.get(url, {
429
- params: {
430
- categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
431
- status,
432
- limit,
433
- cursor
434
- }
435
- });
436
- if (response.success) {
437
- const json = response.value;
438
- return {
439
- success: true,
440
- data: json.items || [],
441
- cursor: json.cursor,
442
- total: json.total || 0
443
- };
444
- } else {
445
- console.error("Error fetching products:", response.error);
446
- return {
447
- success: false,
448
- error: response.error,
449
- data: []
450
- };
451
- }
452
- },
453
- // Get product by slug
454
- async getProductBySlug({ businessId, slug }) {
455
- try {
456
- const config = getGlobalConfig();
457
- const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
458
- const res = await fetch(url);
459
- if (!res.ok) throw new Error("Product not found");
460
- const json = await res.json();
461
- return {
462
- success: true,
463
- data: json
464
- };
465
- } catch (e) {
466
- console.error("Error fetching product:", e);
467
- return {
468
- success: false,
469
- error: e.message,
470
- data: null
471
- };
472
- }
473
- },
474
- // Get quote for cart (pricing with promo codes, shipping, taxes)
475
- async getQuote({
476
- token,
477
- businessId,
478
- items,
479
- market,
480
- currency,
481
- userId,
482
- paymentMethod,
483
- shippingMethodId,
484
- promoCode
485
- }) {
486
- try {
487
- const config = getGlobalConfig();
488
- const lines = items.map((item) => ({
489
- type: "PRODUCT_VARIANT",
490
- productId: item.productId,
491
- variantId: item.variantId,
492
- quantity: item.quantity
493
- }));
494
- const payload = {
495
- businessId,
496
- market,
497
- currency,
498
- userId,
499
- paymentMethod,
500
- lines,
501
- ...shippingMethodId && { shippingMethodId },
502
- ...promoCode && { promoCode }
503
- };
504
- const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
505
- method: "POST",
506
- headers: {
507
- "Content-Type": "application/json",
508
- Authorization: `Bearer ${token}`
509
- },
510
- body: JSON.stringify(payload)
594
+ // src/api/business.ts
595
+ var createBusinessApi = (apiConfig) => {
596
+ return {
597
+ async createBusiness(params, options) {
598
+ return apiConfig.httpClient.post(`/v1/businesses`, params, options);
599
+ },
600
+ async updateBusiness(params, options) {
601
+ return apiConfig.httpClient.put(`/v1/businesses/${params.id}`, params, options);
602
+ },
603
+ async deleteBusiness(params, options) {
604
+ return apiConfig.httpClient.delete(`/v1/businesses/${params.id}`, options);
605
+ },
606
+ async getBusiness(params, options) {
607
+ return apiConfig.httpClient.get(`/v1/businesses/${params.id}`, options);
608
+ },
609
+ async getBusinesses(options) {
610
+ return apiConfig.httpClient.get(`/v1/businesses`, options);
611
+ },
612
+ async getBusinessParents(params, options) {
613
+ return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/parents`, options);
614
+ },
615
+ async triggerBuilds(params, options) {
616
+ return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
617
+ },
618
+ async getSubscriptionPlans(options) {
619
+ return apiConfig.httpClient.get("/v1/businesses/plans", options);
620
+ },
621
+ async getSubscription(params, options) {
622
+ return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/subscription`, options);
623
+ },
624
+ async createSubscription(params, options) {
625
+ return apiConfig.httpClient.post(
626
+ `/v1/businesses/${params.businessId}/subscription`,
627
+ params,
628
+ options
629
+ );
630
+ },
631
+ async updateSubscription(params, options) {
632
+ return apiConfig.httpClient.put(
633
+ `/v1/businesses/${params.businessId}/subscription`,
634
+ params,
635
+ options
636
+ );
637
+ },
638
+ async cancelSubscription(params, options) {
639
+ return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
640
+ ...options,
641
+ params: { immediately: params.immediately || false }
511
642
  });
512
- const text = await res.text();
513
- if (!res.ok) {
514
- try {
515
- const json = JSON.parse(text);
516
- return { success: false, error: json.reason || json.error || res.statusText, code: json.code };
517
- } catch {
518
- return { success: false, error: text || res.statusText };
643
+ },
644
+ async reactivateSubscription(params, options) {
645
+ return apiConfig.httpClient.post(
646
+ `/v1/businesses/${params.businessId}/subscription/reactivate`,
647
+ params,
648
+ options
649
+ );
650
+ },
651
+ async createPortalSession(params, options) {
652
+ return apiConfig.httpClient.post(
653
+ `/v1/businesses/${params.businessId}/subscription/portal`,
654
+ params,
655
+ options
656
+ );
657
+ },
658
+ async inviteUser(params, options) {
659
+ const { businessId, ...payload } = params;
660
+ return apiConfig.httpClient.post(
661
+ `/v1/businesses/${businessId}/invitation`,
662
+ payload,
663
+ options
664
+ );
665
+ },
666
+ async handleInvitation(params, options) {
667
+ const { businessId, ...payload } = params;
668
+ return apiConfig.httpClient.put(
669
+ `/v1/businesses/${businessId}/invitation`,
670
+ payload,
671
+ options
672
+ );
673
+ },
674
+ async testWebhook(params, options) {
675
+ return apiConfig.httpClient.post(
676
+ `/v1/businesses/${params.businessId}/webhooks/test`,
677
+ params.webhook,
678
+ options
679
+ );
680
+ },
681
+ async getBusinessMedia(params, options) {
682
+ return apiConfig.httpClient.get(
683
+ `/v1/businesses/${params.id}/media`,
684
+ {
685
+ ...options,
686
+ params: {
687
+ cursor: params.cursor,
688
+ limit: params.limit || 20
689
+ }
519
690
  }
520
- }
521
- const quote = text ? JSON.parse(text) : null;
522
- return { success: true, data: quote };
523
- } catch (e) {
524
- console.error("Quote fetch failed:", e);
525
- return {
526
- success: false,
527
- error: e.message
528
- };
691
+ );
692
+ },
693
+ async setProviderSchedule(params, options) {
694
+ const { id, ...payload } = params;
695
+ return apiConfig.httpClient.put(
696
+ `/v1/businesses/${id}/schedules`,
697
+ payload,
698
+ options
699
+ );
529
700
  }
530
- },
531
- // Checkout - Backend calculates currency from market
532
- async checkout({
533
- token,
534
- businessId,
535
- items,
536
- paymentMethod,
537
- blocks,
538
- market = "US",
539
- shippingMethodId,
540
- promoCode,
541
- paymentIntentId = null
542
- }) {
543
- try {
544
- const config = getGlobalConfig();
545
- const payload = {
546
- businessId,
547
- items,
548
- paymentMethod,
549
- blocks,
550
- market,
551
- ...shippingMethodId && { shippingMethodId },
552
- ...promoCode && { promoCode },
553
- ...paymentIntentId && { paymentIntentId }
554
- };
555
- const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
701
+ };
702
+ };
703
+
704
+ // src/api/media.ts
705
+ var createMediaApi = (apiConfig) => {
706
+ return {
707
+ async uploadBusinessMedia(params) {
708
+ const { businessId, files = [], urls = [] } = params;
709
+ const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/upload`;
710
+ const formData = new FormData();
711
+ files.forEach((file) => formData.append("files", file));
712
+ urls.forEach((url2) => formData.append("files", url2));
713
+ const tokens = await apiConfig.getTokens();
714
+ const response = await fetch(url, {
556
715
  method: "POST",
716
+ body: formData,
557
717
  headers: {
558
- "Content-Type": "application/json",
559
- Authorization: `Bearer ${token}`
560
- },
561
- body: JSON.stringify(payload)
718
+ Authorization: `Bearer ${tokens.accessToken}`
719
+ }
562
720
  });
563
- const text = await res.text();
564
- if (!res.ok) {
565
- try {
566
- const json2 = JSON.parse(text);
567
- return { success: false, error: json2.reason || json2.error || res.statusText, code: json2.code };
568
- } catch {
569
- return { success: false, error: text || res.statusText };
721
+ if (!response.ok) {
722
+ throw new Error("Upload failed, server said no");
723
+ }
724
+ return await response.json();
725
+ },
726
+ async deleteBusinessMedia(params, options) {
727
+ const { id, mediaId } = params;
728
+ return apiConfig.httpClient.delete(
729
+ `/v1/businesses/${id}/upload`,
730
+ {
731
+ ...options,
732
+ params: { mediaId }
570
733
  }
734
+ );
735
+ },
736
+ async getBusinessMedia(params) {
737
+ const { businessId, cursor = null, limit = 20 } = params;
738
+ const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/media`;
739
+ const queryParams = { limit };
740
+ if (cursor) queryParams.cursor = cursor;
741
+ const queryString = new URLSearchParams(queryParams).toString();
742
+ const response = await fetch(`${url}?${queryString}`);
743
+ if (!response.ok) {
744
+ const errorData = await response.json().catch(() => null);
745
+ throw new Error(errorData?.message || "Failed to fetch media");
571
746
  }
572
- const json = text ? JSON.parse(text) : null;
573
- return { success: true, data: json };
574
- } catch (e) {
575
- return {
576
- success: false,
577
- error: e.message
578
- };
747
+ return await response.json();
579
748
  }
580
- },
581
- // Create payment intent for Stripe
582
- async createPaymentIntent({ amount, currency, businessId }) {
583
- try {
584
- const config = getGlobalConfig();
585
- const tokenResponse = await reservationApi.getGuestToken();
586
- if (!tokenResponse.success || !tokenResponse.data) {
587
- throw new Error("Failed to get guest token");
588
- }
589
- const token = tokenResponse.data.token;
590
- const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
591
- method: "POST",
592
- headers: {
593
- "Content-Type": "application/json",
594
- Authorization: `Bearer ${token}`
595
- },
596
- body: JSON.stringify({
597
- amount,
598
- currency,
599
- businessId
600
- })
749
+ };
750
+ };
751
+
752
+ // src/api/role.ts
753
+ var createRoleApi = (apiConfig) => {
754
+ return {
755
+ async createRole(params, options) {
756
+ return apiConfig.httpClient.post(`/v1/roles`, params, options);
757
+ },
758
+ async updateRole(params, options) {
759
+ return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, options);
760
+ },
761
+ async deleteRole(params, options) {
762
+ return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
763
+ },
764
+ async getRole(params, options) {
765
+ return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
766
+ },
767
+ async getRoles(params, options) {
768
+ return apiConfig.httpClient.get(`/v1/roles`, {
769
+ ...options,
770
+ params: params ? {
771
+ businessId: apiConfig.businessId,
772
+ action: params.action || "READ"
773
+ } : {
774
+ businessId: apiConfig.businessId,
775
+ action: "READ"
776
+ }
601
777
  });
602
- if (!res.ok) {
603
- const error = await res.text() || res.statusText;
604
- throw new Error(error);
605
- }
606
- const json = await res.json();
607
- return {
608
- success: true,
609
- data: json
610
- };
611
- } catch (e) {
612
- console.error("Payment intent creation failed:", e);
613
- return {
614
- success: false,
615
- error: e.message
616
- };
617
778
  }
618
- }
779
+ };
619
780
  };
620
781
 
621
- // src/api/newsletter.ts
622
- var newsletterApi = {
623
- async find(payload) {
624
- const config = getGlobalConfig();
625
- const params = new URLSearchParams({
626
- businessId: payload.business_id
627
- });
628
- const url = `${config.apiUrl}/v1/newsletters?${params.toString()}`;
629
- const response = await fetch(url);
630
- if (!response.ok) {
631
- throw new Error(`HTTP error! status: ${response.status}`);
782
+ // src/api/notification.ts
783
+ var createNotificationApi = (apiConfig) => {
784
+ return {
785
+ async getNotifications(params, options) {
786
+ return apiConfig.httpClient.get(`/v1/notifications`, {
787
+ ...options,
788
+ params: {
789
+ limit: params.limit,
790
+ previous_id: params.previous_id
791
+ }
792
+ });
793
+ },
794
+ async updateNotifications(options) {
795
+ return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
796
+ },
797
+ async trackEmailOpen(params, options) {
798
+ return apiConfig.httpClient.get(
799
+ `/v1/notifications/track/email/${params.trackingPixelId}`,
800
+ options
801
+ );
802
+ },
803
+ async getDeliveryStats(params, options) {
804
+ return apiConfig.httpClient.get(
805
+ `/v1/notifications/track/stats/${apiConfig.businessId}`,
806
+ options
807
+ );
632
808
  }
633
- const backendResponse = await response.json();
634
- return {
635
- data: backendResponse.items || [],
636
- meta: {
637
- total: backendResponse.items?.length || 0,
638
- page: 1,
639
- per_page: backendResponse.items?.length || 0
640
- }
641
- };
642
- },
643
- async get(id) {
644
- const config = getGlobalConfig();
645
- const url = `${config.apiUrl}/v1/newsletters/${id}`;
646
- const response = await fetch(url);
647
- if (!response.ok) {
648
- throw new Error(`HTTP error! status: ${response.status}`);
809
+ };
810
+ };
811
+
812
+ // src/api/promoCode.ts
813
+ var createPromoCodeApi = (apiConfig) => {
814
+ return {
815
+ async createPromoCode(params, options) {
816
+ return apiConfig.httpClient.post(
817
+ `/v1/businesses/${apiConfig.businessId}/promo-codes`,
818
+ params,
819
+ options
820
+ );
821
+ },
822
+ async updatePromoCode(params, options) {
823
+ return apiConfig.httpClient.put(
824
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
825
+ params,
826
+ options
827
+ );
828
+ },
829
+ async deletePromoCode(params, options) {
830
+ return apiConfig.httpClient.delete(
831
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
832
+ options
833
+ );
834
+ },
835
+ async getPromoCode(params, options) {
836
+ return apiConfig.httpClient.get(
837
+ `/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
838
+ options
839
+ );
840
+ },
841
+ async getPromoCodes(params, options) {
842
+ const { businessId, statuses, ...restParams } = params;
843
+ return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/promo-codes`, {
844
+ ...options,
845
+ params: {
846
+ ...restParams,
847
+ statuses: statuses && statuses.length > 0 ? statuses : void 0
848
+ }
849
+ });
649
850
  }
650
- return await response.json();
651
- },
652
- async subscribe(payload) {
653
- try {
654
- const config = getGlobalConfig();
655
- const url = `${config.apiUrl}/v1/newsletters/${payload.newsletterId}/subscribe`;
656
- const response = await fetch(url, {
657
- method: "POST",
658
- headers: {
659
- "Content-Type": "application/json"
660
- },
661
- body: JSON.stringify({
662
- newsletterId: payload.newsletterId,
663
- email: payload.email,
664
- market: "US",
665
- // Backend resolves currency from market
666
- ...payload.customerId && { customerId: payload.customerId },
667
- ...payload.payment && { payment: payload.payment }
668
- })
851
+ };
852
+ };
853
+
854
+ // src/api/analytics.ts
855
+ var createAnalyticsApi = (apiConfig) => {
856
+ return {
857
+ async getAnalytics(params, options) {
858
+ const { businessId, ...queryParams } = params;
859
+ return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}`, {
860
+ ...options,
861
+ params: queryParams
669
862
  });
670
- if (!response.ok) {
671
- const errorData = await response.json().catch(() => ({}));
672
- throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
673
- }
674
- const data = await response.json();
675
- return {
676
- success: true,
677
- data
678
- };
679
- } catch (error) {
680
- console.error("Newsletter subscription error:", error);
681
- return {
682
- success: false,
683
- error: error instanceof Error ? error.message : "Failed to subscribe to newsletter"
684
- };
863
+ },
864
+ async getAnalyticsHealth(params, options) {
865
+ return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}/health`, options);
866
+ },
867
+ async setupAnalytics(params, options) {
868
+ return apiConfig.httpClient.post(`/v1/analytics/admin/setup`, params, options);
685
869
  }
686
- }
870
+ };
687
871
  };
688
872
 
689
- // src/services/auth.ts
690
- async function getGuestToken(currentToken = null) {
691
- if (currentToken) return currentToken;
692
- const response = await reservationApi.getGuestToken();
693
- if (response.success && response.data) {
694
- return response.data.token;
695
- }
696
- throw new Error("Failed to get guest token");
697
- }
698
- async function updateProfilePhone(token, phoneNumber) {
699
- if (!phoneNumber) {
700
- throw new Error("Phone number is required");
701
- }
702
- const response = await reservationApi.updateProfilePhone({ token, phoneNumber });
703
- if (response.success) {
704
- return { success: true };
705
- } else {
706
- throw new Error(response.error || "Failed to send verification code");
707
- }
708
- }
709
- async function verifyPhoneCode(token, phoneNumber, code) {
710
- if (!code) {
711
- throw new Error("Verification code is required");
712
- }
713
- const response = await reservationApi.verifyPhoneCode({ token, phoneNumber, code });
714
- if (response.success) {
715
- return { success: true };
716
- } else {
717
- throw new Error(response.error || "Invalid verification code");
718
- }
719
- }
720
- async function getBusinessConfig(businessId) {
721
- try {
722
- const config = getGlobalConfig();
723
- const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
724
- method: "GET",
725
- headers: {
726
- "Content-Type": "application/json"
727
- }
728
- });
729
- if (!response.ok) {
730
- throw new Error(`Failed to fetch business config: ${response.status}`);
873
+ // src/api/payment.ts
874
+ var createPaymentApi = (apiConfig) => {
875
+ return {
876
+ async handleStripeWebhook(params, options) {
877
+ return apiConfig.httpClient.post(`/v1/payments/webhooks/stripe`, params, options);
878
+ },
879
+ async getBusinessMarkets(params, options) {
880
+ return apiConfig.httpClient.get(
881
+ `/v1/payments/businesses/${apiConfig.businessId}/markets`,
882
+ options
883
+ );
884
+ },
885
+ async getBusinessMarket(params, options) {
886
+ return apiConfig.httpClient.get(
887
+ `/v1/payments/businesses/${apiConfig.businessId}/markets/${params.marketId}`,
888
+ options
889
+ );
731
890
  }
732
- const business = await response.json();
733
- return {
734
- success: true,
735
- data: business
736
- };
737
- } catch (error) {
738
- return {
739
- success: false,
740
- error: error.message
741
- };
742
- }
743
- }
891
+ };
892
+ };
744
893
 
745
894
  // src/utils/blocks.ts
746
895
  function getBlockLabel(block, locale = "en") {
@@ -872,10 +1021,8 @@ var getBlockFromArray = (entry, blockKey, locale = "en") => {
872
1021
  return acc;
873
1022
  });
874
1023
  };
875
- var getImageUrl = (imageBlock, isBlock = true) => {
1024
+ var getImageUrl = (imageBlock, isBlock = true, storageUrl = "https://storage.arky.io/dev") => {
876
1025
  if (!imageBlock) return null;
877
- const config = getGlobalConfig();
878
- const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
879
1026
  const isExternalUrl = (url) => {
880
1027
  return url.startsWith("http://") || url.startsWith("https://");
881
1028
  };
@@ -921,9 +1068,7 @@ function getGalleryThumbnail(gallery) {
921
1068
  const res = item.media.resolutions.thumbnail || item.media.resolutions.original;
922
1069
  return res?.url || null;
923
1070
  }
924
- function thumbnailUrl(service) {
925
- const config = getGlobalConfig();
926
- const storageUrl = config.storageUrl || "";
1071
+ function thumbnailUrl(service, storageUrl = "") {
927
1072
  const path = getGalleryThumbnail(service.gallery);
928
1073
  return path ? `${storageUrl}/${path}` : null;
929
1074
  }
@@ -942,6 +1087,95 @@ var translateMap = (labels, lang, fallback = "unknown") => {
942
1087
  return label;
943
1088
  };
944
1089
 
1090
+ // src/utils/currency.ts
1091
+ function getCurrencySymbol(currency) {
1092
+ const currencySymbols = {
1093
+ USD: "$",
1094
+ EUR: "\u20AC",
1095
+ GBP: "\xA3",
1096
+ CAD: "C$",
1097
+ AUD: "A$",
1098
+ JPY: "\xA5",
1099
+ CHF: "CHF",
1100
+ SEK: "kr",
1101
+ NOK: "kr",
1102
+ DKK: "kr",
1103
+ PLN: "z\u0142",
1104
+ CZK: "K\u010D",
1105
+ HUF: "Ft",
1106
+ RON: "lei",
1107
+ BGN: "\u043B\u0432",
1108
+ HRK: "kn",
1109
+ RSD: "\u0434\u0438\u043D",
1110
+ BAM: "KM",
1111
+ MKD: "\u0434\u0435\u043D",
1112
+ ALL: "L",
1113
+ TRY: "\u20BA",
1114
+ RUB: "\u20BD",
1115
+ UAH: "\u20B4",
1116
+ BYN: "Br",
1117
+ CNY: "\xA5",
1118
+ INR: "\u20B9",
1119
+ KRW: "\u20A9",
1120
+ THB: "\u0E3F",
1121
+ VND: "\u20AB",
1122
+ SGD: "S$",
1123
+ MYR: "RM",
1124
+ IDR: "Rp",
1125
+ PHP: "\u20B1",
1126
+ BRL: "R$",
1127
+ ARS: "$",
1128
+ CLP: "$",
1129
+ COP: "$",
1130
+ PEN: "S/",
1131
+ MXN: "$",
1132
+ ZAR: "R",
1133
+ EGP: "E\xA3",
1134
+ NGN: "\u20A6",
1135
+ KES: "KSh",
1136
+ GHS: "\u20B5",
1137
+ MAD: "DH",
1138
+ TND: "\u062F.\u062A",
1139
+ DZD: "\u062F.\u062C",
1140
+ LYD: "\u0644.\u062F",
1141
+ AED: "\u062F.\u0625",
1142
+ SAR: "\u0631.\u0633",
1143
+ QAR: "\u0631.\u0642",
1144
+ KWD: "\u062F.\u0643",
1145
+ BHD: "\u0628.\u062F",
1146
+ OMR: "\u0631.\u0639",
1147
+ JOD: "\u062F.\u0623",
1148
+ LBP: "\u0644.\u0644",
1149
+ SYP: "\u0644.\u0633",
1150
+ IQD: "\u0639.\u062F",
1151
+ IRR: "\uFDFC",
1152
+ AFN: "\u060B",
1153
+ PKR: "\u20A8",
1154
+ LKR: "\u20A8",
1155
+ NPR: "\u20A8",
1156
+ BDT: "\u09F3",
1157
+ MMK: "K",
1158
+ LAK: "\u20AD",
1159
+ KHR: "\u17DB",
1160
+ MNT: "\u20AE",
1161
+ KZT: "\u20B8",
1162
+ UZS: "\u043B\u0432",
1163
+ KGS: "\u043B\u0432",
1164
+ TJS: "SM",
1165
+ TMT: "T",
1166
+ AZN: "\u20BC",
1167
+ GEL: "\u20BE",
1168
+ AMD: "\u058F",
1169
+ BYR: "p.",
1170
+ MDL: "L"
1171
+ };
1172
+ return currencySymbols[currency.toUpperCase()] || currency;
1173
+ }
1174
+ var SYMBOL_AFTER_CURRENCIES = ["SEK", "NOK", "DKK", "PLN", "CZK", "HUF", "RON", "BGN", "HRK"];
1175
+ function isSymbolAfterCurrency(currency) {
1176
+ return SYMBOL_AFTER_CURRENCIES.includes(currency.toUpperCase());
1177
+ }
1178
+
945
1179
  // src/utils/errors.ts
946
1180
  var ERROR_CODES = {
947
1181
  // General errors
@@ -976,7 +1210,7 @@ var ERROR_CODES = {
976
1210
  "BUSINESS.007": "BUSINESS.BUSINESS_ID_REQUIRED",
977
1211
  "BUSINESS.010": "BUSINESS.DESCRIPTION_REQUIRED",
978
1212
  "BUSINESS.011": "BUSINESS.SLUG_INVALID",
979
- // Provider errors
1213
+ // Provider errors
980
1214
  "PROVIDER.001": "PROVIDER.NOT_FOUND",
981
1215
  "PROVIDER.002": "PROVIDER.FAILED_TO_CREATE",
982
1216
  "PROVIDER.003": "PROVIDER.FAILED_TO_UPDATE",
@@ -1026,11 +1260,11 @@ var transformErrors = (zodError) => {
1026
1260
  if (!zodError.issues) return customErrors;
1027
1261
  zodError.issues.forEach((issue) => {
1028
1262
  const field = issue.path.join(".");
1029
- const message = issue.message;
1263
+ const error = issue.message;
1030
1264
  if (!customErrors.some(
1031
- (customError) => customError.field === field && customError.message === message
1265
+ (customError) => customError.field === field && customError.error === error
1032
1266
  )) {
1033
- customErrors.push({ field, message });
1267
+ customErrors.push({ field, error });
1034
1268
  }
1035
1269
  });
1036
1270
  return customErrors;
@@ -1042,106 +1276,44 @@ var convertServerErrorToRequestError = (serverError, renameRules) => {
1042
1276
  const field = renameRules && renameRules[validationError.field] ? renameRules[validationError.field] : validationError.field;
1043
1277
  return {
1044
1278
  field,
1045
- message: ERROR_CODES[validationError.code] || "Unknown error"
1279
+ error: validationError.error || "GENERAL.VALIDATION_ERROR"
1046
1280
  };
1047
1281
  })
1048
1282
  };
1049
1283
  };
1050
1284
  var errors = ERROR_CONSTANTS;
1051
1285
 
1052
- // src/utils/currency.ts
1053
- function getCurrencySymbol(currency) {
1054
- const currencySymbols = {
1055
- USD: "$",
1056
- EUR: "\u20AC",
1057
- GBP: "\xA3",
1058
- CAD: "C$",
1059
- AUD: "A$",
1060
- JPY: "\xA5",
1061
- CHF: "CHF",
1062
- SEK: "kr",
1063
- NOK: "kr",
1064
- DKK: "kr",
1065
- PLN: "z\u0142",
1066
- CZK: "K\u010D",
1067
- HUF: "Ft",
1068
- RON: "lei",
1069
- BGN: "\u043B\u0432",
1070
- HRK: "kn",
1071
- RSD: "\u0434\u0438\u043D",
1072
- BAM: "KM",
1073
- MKD: "\u0434\u0435\u043D",
1074
- ALL: "L",
1075
- TRY: "\u20BA",
1076
- RUB: "\u20BD",
1077
- UAH: "\u20B4",
1078
- BYN: "Br",
1079
- CNY: "\xA5",
1080
- INR: "\u20B9",
1081
- KRW: "\u20A9",
1082
- THB: "\u0E3F",
1083
- VND: "\u20AB",
1084
- SGD: "S$",
1085
- MYR: "RM",
1086
- IDR: "Rp",
1087
- PHP: "\u20B1",
1088
- BRL: "R$",
1089
- ARS: "$",
1090
- CLP: "$",
1091
- COP: "$",
1092
- PEN: "S/",
1093
- MXN: "$",
1094
- ZAR: "R",
1095
- EGP: "E\xA3",
1096
- NGN: "\u20A6",
1097
- KES: "KSh",
1098
- GHS: "\u20B5",
1099
- MAD: "DH",
1100
- TND: "\u062F.\u062A",
1101
- DZD: "\u062F.\u062C",
1102
- LYD: "\u0644.\u062F",
1103
- AED: "\u062F.\u0625",
1104
- SAR: "\u0631.\u0633",
1105
- QAR: "\u0631.\u0642",
1106
- KWD: "\u062F.\u0643",
1107
- BHD: "\u0628.\u062F",
1108
- OMR: "\u0631.\u0639",
1109
- JOD: "\u062F.\u0623",
1110
- LBP: "\u0644.\u0644",
1111
- SYP: "\u0644.\u0633",
1112
- IQD: "\u0639.\u062F",
1113
- IRR: "\uFDFC",
1114
- AFN: "\u060B",
1115
- PKR: "\u20A8",
1116
- LKR: "\u20A8",
1117
- NPR: "\u20A8",
1118
- BDT: "\u09F3",
1119
- MMK: "K",
1120
- LAK: "\u20AD",
1121
- KHR: "\u17DB",
1122
- MNT: "\u20AE",
1123
- KZT: "\u20B8",
1124
- UZS: "\u043B\u0432",
1125
- KGS: "\u043B\u0432",
1126
- TJS: "SM",
1127
- TMT: "T",
1128
- AZN: "\u20BC",
1129
- GEL: "\u20BE",
1130
- AMD: "\u058F",
1131
- BYR: "p.",
1132
- MDL: "L"
1133
- };
1134
- return currencySymbols[currency.toUpperCase()] || currency;
1286
+ // src/utils/i18n.ts
1287
+ var defaultLocale = "en";
1288
+ function setDefaultLocale(locale) {
1289
+ defaultLocale = locale;
1290
+ }
1291
+ function getLocale() {
1292
+ if (typeof window !== "undefined" && window.navigator) {
1293
+ return window.navigator.language.split("-")[0] || defaultLocale;
1294
+ }
1295
+ return defaultLocale;
1296
+ }
1297
+ function getLocaleFromUrl(url) {
1298
+ const pathParts = url.pathname.split("/").filter(Boolean);
1299
+ const potentialLocale = pathParts[0];
1300
+ const validLocales = ["en", "fr", "es", "de", "it", "pt", "ja", "zh", "ko", "ru"];
1301
+ if (potentialLocale && validLocales.includes(potentialLocale)) {
1302
+ return potentialLocale;
1303
+ }
1304
+ return getLocale();
1305
+ }
1306
+ function getLocalizedString(value, locale) {
1307
+ if (!value) return "";
1308
+ if (typeof value === "string") return value;
1309
+ if (typeof value === "object") {
1310
+ const targetLocale = locale || getLocale();
1311
+ return value[targetLocale] || value["en"] || value[Object.keys(value)[0]] || "";
1312
+ }
1313
+ return String(value);
1135
1314
  }
1136
1315
 
1137
1316
  // src/utils/price.ts
1138
- var CURRENCY_SYMBOLS = {
1139
- "USD": "$",
1140
- "EUR": "\u20AC",
1141
- "GBP": "\xA3",
1142
- "CAD": "C$",
1143
- "AUD": "A$"
1144
- };
1145
1317
  var MARKET_CURRENCIES = {
1146
1318
  "US": "USD",
1147
1319
  "EU": "EUR",
@@ -1155,9 +1327,6 @@ function convertToMajor(minorAmount) {
1155
1327
  function convertToMinor(majorAmount) {
1156
1328
  return Math.round((majorAmount ?? 0) * 100);
1157
1329
  }
1158
- function getSymbol(currency) {
1159
- return CURRENCY_SYMBOLS[currency] || "$";
1160
- }
1161
1330
  function getCurrencyFromMarket(marketId) {
1162
1331
  return MARKET_CURRENCIES[marketId] || "USD";
1163
1332
  }
@@ -1167,7 +1336,10 @@ function formatCurrencyAmount(amount, currency, options = {}) {
1167
1336
  if (!showSymbols) {
1168
1337
  return `${roundedAmount} ${currency}`;
1169
1338
  }
1170
- const symbol = customSymbol || getSymbol(currency);
1339
+ const symbol = customSymbol || getCurrencySymbol(currency);
1340
+ if (isSymbolAfterCurrency(currency)) {
1341
+ return `${roundedAmount} ${symbol}`;
1342
+ }
1171
1343
  return `${symbol}${roundedAmount}`;
1172
1344
  }
1173
1345
  function formatMinor(amountMinor, currency, options = {}) {
@@ -1212,11 +1384,11 @@ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
1212
1384
  symbol = getCurrencySymbol(currency);
1213
1385
  } else {
1214
1386
  currency = getCurrencyFromMarket(price.market);
1215
- symbol = getSymbol(currency);
1387
+ symbol = getCurrencySymbol(currency);
1216
1388
  }
1217
1389
  } else {
1218
1390
  currency = getCurrencyFromMarket(price.market);
1219
- symbol = getSymbol(currency);
1391
+ symbol = getCurrencySymbol(currency);
1220
1392
  }
1221
1393
  const formattedPrice = formatMinor(price.amount ?? 0, currency, {
1222
1394
  showSymbols,
@@ -1254,6 +1426,32 @@ function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMeth
1254
1426
  };
1255
1427
  }
1256
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
+
1257
1455
  // src/utils/svg.ts
1258
1456
  async function fetchSvgContent(mediaObject) {
1259
1457
  if (!mediaObject) return null;
@@ -1419,18 +1617,169 @@ function validateRequired(value, fieldName = "This field") {
1419
1617
  return { isValid: true };
1420
1618
  }
1421
1619
 
1620
+ // src/services/createHttpClient.ts
1621
+ function createHttpClient(cfg) {
1622
+ const refreshEndpoint = `${cfg.baseUrl}/v1/users/refresh-access-token`;
1623
+ async function request(method, path, body, options) {
1624
+ if (options?.transformRequest) {
1625
+ body = options.transformRequest(body);
1626
+ }
1627
+ const headers = {
1628
+ Accept: "application/json",
1629
+ "Content-Type": "application/json",
1630
+ ...options?.headers || {}
1631
+ };
1632
+ let { accessToken, refreshToken, provider, expiresAt } = await cfg.getTokens();
1633
+ const nowSec = Date.now() / 1e3;
1634
+ if (expiresAt && nowSec > expiresAt) {
1635
+ if (refreshToken) {
1636
+ const refRes = await fetch(refreshEndpoint, {
1637
+ method: "POST",
1638
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
1639
+ body: JSON.stringify({ provider, refreshToken })
1640
+ });
1641
+ if (refRes.ok) {
1642
+ const data2 = await refRes.json();
1643
+ cfg.setTokens(data2);
1644
+ accessToken = data2.accessToken;
1645
+ } else {
1646
+ cfg.onAuthFailure();
1647
+ if (cfg.loginFallbackPath) {
1648
+ cfg.navigate?.(cfg.loginFallbackPath);
1649
+ }
1650
+ const err = new Error("Error refreshing token");
1651
+ err.name = "ApiError";
1652
+ err.statusCode = 401;
1653
+ throw err;
1654
+ }
1655
+ } else {
1656
+ cfg.onAuthFailure();
1657
+ if (cfg.loginFallbackPath) {
1658
+ cfg.navigate?.(cfg.loginFallbackPath);
1659
+ }
1660
+ const err = new Error("No refresh token");
1661
+ err.name = "ApiError";
1662
+ err.statusCode = 401;
1663
+ throw err;
1664
+ }
1665
+ }
1666
+ if (accessToken) {
1667
+ headers["Authorization"] = `Bearer ${accessToken}`;
1668
+ }
1669
+ const finalPath = options?.params ? path + buildQueryString(options.params) : path;
1670
+ const fetchOpts = { method, headers };
1671
+ if (!["GET", "DELETE"].includes(method) && body !== void 0) {
1672
+ fetchOpts.body = JSON.stringify(body);
1673
+ }
1674
+ let res;
1675
+ let data;
1676
+ try {
1677
+ const fullUrl = `${cfg.baseUrl}${finalPath}`;
1678
+ console.log("[SDK] Fetching:", method, fullUrl, fetchOpts);
1679
+ res = await fetch(fullUrl, fetchOpts);
1680
+ data = await res.json();
1681
+ } catch (error) {
1682
+ const err = new Error(error instanceof Error ? error.message : "Network request failed");
1683
+ err.name = "NetworkError";
1684
+ throw err;
1685
+ }
1686
+ if (!res.ok) {
1687
+ const serverErr = data;
1688
+ const reqErr = convertServerErrorToRequestError(serverErr);
1689
+ if (options?.errorMessage && cfg.notify) {
1690
+ cfg.notify({ message: options.errorMessage, type: "error" });
1691
+ }
1692
+ const err = new Error(serverErr.message || "Request failed");
1693
+ err.name = "ApiError";
1694
+ err.statusCode = serverErr.statusCode;
1695
+ err.validationErrors = reqErr.validationErrors;
1696
+ throw err;
1697
+ }
1698
+ if (options?.successMessage && cfg.notify) {
1699
+ cfg.notify({ message: options.successMessage, type: "success" });
1700
+ }
1701
+ return data;
1702
+ }
1703
+ return {
1704
+ get: (path, opts) => request("GET", path, void 0, opts),
1705
+ post: (path, body, opts) => request("POST", path, body, opts),
1706
+ put: (path, body, opts) => request("PUT", path, body, opts),
1707
+ patch: (path, body, opts) => request("PATCH", path, body, opts),
1708
+ delete: (path, opts) => request("DELETE", path, void 0, opts)
1709
+ };
1710
+ }
1711
+
1422
1712
  // src/index.ts
1423
- var SDK_VERSION = "0.3.0";
1713
+ var SDK_VERSION = "0.3.1";
1424
1714
  var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
1425
- function initArky(config) {
1426
- if (!config.apiUrl) {
1427
- throw new Error("apiUrl is required");
1428
- }
1429
- if (!config.businessId) {
1430
- throw new Error("businessId is required");
1715
+ function createArkySDK(config) {
1716
+ const httpClient = createHttpClient(config);
1717
+ const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
1718
+ const apiConfig = {
1719
+ httpClient,
1720
+ businessId: config.businessId,
1721
+ storageUrl,
1722
+ baseUrl: config.baseUrl,
1723
+ market: config.market || "US",
1724
+ setTokens: config.setTokens,
1725
+ getTokens: config.getTokens
1726
+ };
1727
+ const userApi = createUserApi(apiConfig);
1728
+ const autoGuest = config.autoGuest !== void 0 ? config.autoGuest : true;
1729
+ const sdk = {
1730
+ user: userApi,
1731
+ business: createBusinessApi(apiConfig),
1732
+ media: createMediaApi(apiConfig),
1733
+ role: createRoleApi(apiConfig),
1734
+ notification: createNotificationApi(apiConfig),
1735
+ promoCode: createPromoCodeApi(apiConfig),
1736
+ analytics: createAnalyticsApi(apiConfig),
1737
+ cms: createCmsApi(apiConfig),
1738
+ eshop: createEshopApi(apiConfig),
1739
+ reservation: createReservationApi(apiConfig),
1740
+ newsletter: createNewsletterApi(apiConfig),
1741
+ payment: createPaymentApi(apiConfig),
1742
+ setBusinessId: (businessId) => {
1743
+ apiConfig.businessId = businessId;
1744
+ },
1745
+ getBusinessId: () => apiConfig.businessId,
1746
+ auth: {
1747
+ isAuthenticated: config.isAuthenticated || (() => false),
1748
+ logout: config.logout || config.onAuthFailure,
1749
+ setUserToken: config.setUserToken || (() => {
1750
+ })
1751
+ },
1752
+ utils: {
1753
+ getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
1754
+ thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
1755
+ getGalleryThumbnail,
1756
+ getMarketPrice,
1757
+ getPriceAmount,
1758
+ formatPayment,
1759
+ formatMinor,
1760
+ createPaymentForCheckout,
1761
+ getCurrencySymbol,
1762
+ validatePhoneNumber,
1763
+ tzGroups,
1764
+ findTimeZone
1765
+ }
1766
+ };
1767
+ if (autoGuest) {
1768
+ Promise.resolve().then(async () => {
1769
+ try {
1770
+ const tokens = await config.getTokens();
1771
+ if (!tokens.accessToken && !tokens.refreshToken) {
1772
+ const guestToken = await userApi.getGuestToken({});
1773
+ console.log("[SDK Init] Created guest token:", guestToken ? "Success" : "Failed");
1774
+ } else {
1775
+ console.log("[SDK Init] Using existing token from storage");
1776
+ }
1777
+ } catch (error) {
1778
+ console.error("[SDK Init] Failed to initialize auth:", error);
1779
+ }
1780
+ });
1431
1781
  }
1432
- setGlobalConfig(config);
1433
- return config;
1782
+ return sdk;
1434
1783
  }
1435
1784
 
1436
1785
  exports.ERROR_CODES = ERROR_CODES;
@@ -1438,14 +1787,28 @@ exports.ERROR_CONSTANTS = ERROR_CONSTANTS;
1438
1787
  exports.PaymentMethod = PaymentMethod;
1439
1788
  exports.SDK_VERSION = SDK_VERSION;
1440
1789
  exports.SUPPORTED_FRAMEWORKS = SUPPORTED_FRAMEWORKS;
1790
+ exports.SYMBOL_AFTER_CURRENCIES = SYMBOL_AFTER_CURRENCIES;
1791
+ exports.appendQueryString = appendQueryString;
1792
+ exports.buildQueryString = buildQueryString;
1441
1793
  exports.categorify = categorify;
1442
- exports.cmsApi = cmsApi;
1443
1794
  exports.convertServerErrorToRequestError = convertServerErrorToRequestError;
1444
1795
  exports.convertToMajor = convertToMajor;
1445
1796
  exports.convertToMinor = convertToMinor;
1797
+ exports.createAnalyticsApi = createAnalyticsApi;
1798
+ exports.createArkySDK = createArkySDK;
1799
+ exports.createBusinessApi = createBusinessApi;
1800
+ exports.createCmsApi = createCmsApi;
1801
+ exports.createEshopApi = createEshopApi;
1802
+ exports.createMediaApi = createMediaApi;
1803
+ exports.createNewsletterApi = createNewsletterApi;
1804
+ exports.createNotificationApi = createNotificationApi;
1805
+ exports.createPaymentApi = createPaymentApi;
1446
1806
  exports.createPaymentForCheckout = createPaymentForCheckout;
1807
+ exports.createPromoCodeApi = createPromoCodeApi;
1808
+ exports.createReservationApi = createReservationApi;
1809
+ exports.createRoleApi = createRoleApi;
1810
+ exports.createUserApi = createUserApi;
1447
1811
  exports.errors = errors;
1448
- exports.eshopApi = eshopApi;
1449
1812
  exports.extractBlockValues = extractBlockValues;
1450
1813
  exports.fetchSvgContent = fetchSvgContent;
1451
1814
  exports.findTimeZone = findTimeZone;
@@ -1460,36 +1823,31 @@ exports.getBlockObjectValues = getBlockObjectValues;
1460
1823
  exports.getBlockTextValue = getBlockTextValue;
1461
1824
  exports.getBlockValue = getBlockValue;
1462
1825
  exports.getBlockValues = getBlockValues;
1463
- exports.getBusinessConfig = getBusinessConfig;
1464
1826
  exports.getCurrencyFromMarket = getCurrencyFromMarket;
1827
+ exports.getCurrencySymbol = getCurrencySymbol;
1465
1828
  exports.getErrorMessage = getErrorMessage;
1466
1829
  exports.getGalleryThumbnail = getGalleryThumbnail;
1467
- exports.getGlobalConfig = getGlobalConfig;
1468
- exports.getGuestToken = getGuestToken;
1469
1830
  exports.getImageUrl = getImageUrl;
1831
+ exports.getLocale = getLocale;
1832
+ exports.getLocaleFromUrl = getLocaleFromUrl;
1833
+ exports.getLocalizedString = getLocalizedString;
1470
1834
  exports.getMarketPrice = getMarketPrice;
1471
1835
  exports.getPriceAmount = getPriceAmount;
1472
1836
  exports.getSvgContentForAstro = getSvgContentForAstro;
1473
- exports.getSymbol = getSymbol;
1474
- exports.httpClient = http_default;
1475
1837
  exports.humanize = humanize;
1476
- exports.initArky = initArky;
1477
1838
  exports.injectSvgIntoElement = injectSvgIntoElement;
1478
1839
  exports.isErrorCode = isErrorCode;
1479
- exports.newsletterApi = newsletterApi;
1840
+ exports.isSymbolAfterCurrency = isSymbolAfterCurrency;
1480
1841
  exports.prepareBlocksForSubmission = prepareBlocksForSubmission;
1481
- exports.reservationApi = reservationApi;
1482
- exports.setGlobalConfig = setGlobalConfig;
1842
+ exports.setDefaultLocale = setDefaultLocale;
1483
1843
  exports.slugify = slugify;
1484
1844
  exports.thumbnailUrl = thumbnailUrl;
1485
1845
  exports.transformErrors = transformErrors;
1486
1846
  exports.translateMap = translateMap;
1487
1847
  exports.tzGroups = tzGroups;
1488
- exports.updateProfilePhone = updateProfilePhone;
1489
1848
  exports.validateEmail = validateEmail;
1490
1849
  exports.validatePhoneNumber = validatePhoneNumber;
1491
1850
  exports.validateRequired = validateRequired;
1492
1851
  exports.validateVerificationCode = validateVerificationCode;
1493
- exports.verifyPhoneCode = verifyPhoneCode;
1494
1852
  //# sourceMappingURL=index.cjs.map
1495
1853
  //# sourceMappingURL=index.cjs.map