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