arky-sdk 0.7.72 → 0.7.75

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
@@ -7,143 +7,823 @@ var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
7
7
  return PaymentMethodType2;
8
8
  })(PaymentMethodType || {});
9
9
 
10
- // src/utils/errors.ts
11
- var convertServerErrorToRequestError = (serverError, renameRules) => {
12
- const validationErrors = serverError?.validationErrors ?? [];
13
- return {
14
- ...serverError,
15
- validationErrors: validationErrors.map((validationError) => {
16
- const field = validationError.field;
17
- return {
18
- field,
19
- error: validationError.error || "GENERAL.VALIDATION_ERROR"
20
- };
21
- })
22
- };
23
- };
24
-
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
-
47
- // src/services/createHttpClient.ts
48
- var STORAGE_KEYS = {
49
- accessToken: "arky_token",
50
- refreshToken: "arky_refresh",
51
- accessExpiresAt: "arky_expires_at"
52
- };
53
- function defaultGetToken() {
54
- if (typeof window === "undefined") return { accessToken: "" };
55
- return {
56
- accessToken: localStorage.getItem(STORAGE_KEYS.accessToken) || "",
57
- refreshToken: localStorage.getItem(STORAGE_KEYS.refreshToken) || "",
58
- accessExpiresAt: parseInt(localStorage.getItem(STORAGE_KEYS.accessExpiresAt) || "0", 10)
59
- };
10
+ // src/utils/blocks.ts
11
+ function getBlockLabel(block) {
12
+ if (!block) return "";
13
+ return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) ?? "";
60
14
  }
61
- function defaultSetToken(tokens) {
62
- if (typeof window === "undefined") return;
63
- if (tokens.accessToken) {
64
- localStorage.setItem(STORAGE_KEYS.accessToken, tokens.accessToken);
65
- localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.refreshToken || "");
66
- localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.accessExpiresAt || 0).toString());
67
- } else {
68
- Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
15
+ function formatBlockValue(block) {
16
+ if (!block || block.value === null || block.value === void 0) return "";
17
+ const value = block.value;
18
+ switch (block.type) {
19
+ case "boolean":
20
+ return value ? "Yes" : "No";
21
+ case "number":
22
+ if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
23
+ return new Date(value).toLocaleDateString();
24
+ }
25
+ return String(value);
26
+ case "relationship_entry":
27
+ case "relationship_media":
28
+ if (value && typeof value === "object") {
29
+ return value.mimeType ? value.name || value.id : value.title || value.name || value.id;
30
+ }
31
+ return String(value);
32
+ default:
33
+ return String(value);
69
34
  }
70
35
  }
71
- function defaultLogout() {
72
- if (typeof window === "undefined") return;
73
- Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
36
+ function prepareBlocksForSubmission(formData, blockTypes) {
37
+ return Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).map((key) => ({
38
+ key,
39
+ value: blockTypes?.[key] === "list" && !Array.isArray(formData[key]) ? [formData[key]] : formData[key]
40
+ }));
74
41
  }
75
- function defaultIsAuthenticated() {
76
- if (typeof window === "undefined") return false;
77
- const token = localStorage.getItem(STORAGE_KEYS.accessToken) || "";
78
- return token.startsWith("customer_") || token.startsWith("account_");
42
+ function extractBlockValues(blocks) {
43
+ const values = {};
44
+ blocks.forEach((block) => {
45
+ values[block.key] = block.value ?? null;
46
+ });
47
+ return values;
79
48
  }
80
- function createHttpClient(cfg) {
81
- const getToken = cfg.getToken || defaultGetToken;
82
- const setToken = cfg.setToken || defaultSetToken;
83
- const logout = cfg.logout || defaultLogout;
84
- const refreshEndpoint = `${cfg.baseUrl}${cfg.refreshPath || "/v1/auth/refresh"}`;
85
- let refreshPromise = null;
86
- async function ensureFreshToken() {
87
- if (refreshPromise) {
88
- return refreshPromise;
49
+ var getBlockValue = (entry, blockKey) => {
50
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
51
+ return block?.value ?? null;
52
+ };
53
+ var getBlockTextValue = (block, locale = "en") => {
54
+ if (!block || block.value === null || block.value === void 0) return "";
55
+ if (block.type === "localized_text" || block.type === "markdown") {
56
+ if (typeof block.value === "object" && block.value !== null) {
57
+ return block.value[locale] ?? block.value["en"] ?? "";
89
58
  }
90
- refreshPromise = (async () => {
91
- const { refreshToken } = await getToken();
92
- if (!refreshToken) {
93
- logout();
94
- const err = new Error("No refresh token available");
95
- err.name = "ApiError";
96
- err.statusCode = 401;
97
- throw err;
98
- }
99
- const refRes = await fetch(refreshEndpoint, {
100
- method: "POST",
101
- headers: { Accept: "application/json", "Content-Type": "application/json" },
102
- body: JSON.stringify({ refreshToken })
103
- });
104
- if (!refRes.ok) {
105
- logout();
106
- const err = new Error("Token refresh failed");
107
- err.name = "ApiError";
108
- err.statusCode = 401;
109
- throw err;
59
+ }
60
+ if (typeof block.value === "string") return block.value;
61
+ return String(block.value ?? "");
62
+ };
63
+ var getBlockValues = (entry, blockKey) => {
64
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
65
+ if (!block) return [];
66
+ if (block.type === "list" && Array.isArray(block.value)) {
67
+ return block.value;
68
+ }
69
+ return [];
70
+ };
71
+ function unwrapBlock(block, locale) {
72
+ if (!block?.type || block.value === void 0) return block;
73
+ if (block.type === "list") {
74
+ return block.value.map((obj) => {
75
+ const parsed = {};
76
+ for (const [k, v] of Object.entries(obj)) {
77
+ parsed[k] = unwrapBlock(v, locale);
110
78
  }
111
- const data = await refRes.json();
112
- setToken(data);
113
- })().finally(() => {
114
- refreshPromise = null;
79
+ return parsed;
115
80
  });
116
- return refreshPromise;
117
81
  }
118
- async function request(method, path, body, options) {
119
- if (options?.transformRequest) {
120
- body = options.transformRequest(body);
82
+ if (block.type === "map") {
83
+ const parsed = {};
84
+ for (const [k, v] of Object.entries(block.value || {})) {
85
+ parsed[k] = unwrapBlock(v, locale);
121
86
  }
122
- const headers = {
123
- Accept: "application/json",
124
- "Content-Type": "application/json",
125
- ...options?.headers || {}
126
- };
127
- let { accessToken, accessExpiresAt } = await getToken();
128
- const nowSec = Date.now() / 1e3;
129
- if (accessExpiresAt && nowSec > accessExpiresAt) {
130
- await ensureFreshToken();
131
- const tokens = await getToken();
132
- accessToken = tokens.accessToken;
87
+ return parsed;
88
+ }
89
+ if (block.type === "localized_text" || block.type === "markdown") {
90
+ return block.value?.[locale];
91
+ }
92
+ return block.value;
93
+ }
94
+ var getBlockObjectValues = (entry, blockKey, locale = "en") => {
95
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
96
+ if (!block || block.type !== "list" || !Array.isArray(block.value)) return [];
97
+ return block.value.map((obj) => {
98
+ if (!obj?.value || !Array.isArray(obj.value)) return {};
99
+ return obj.value.reduce((acc, current) => {
100
+ acc[current.key] = unwrapBlock(current, locale);
101
+ return acc;
102
+ }, {});
103
+ });
104
+ };
105
+ var getBlockFromArray = (entry, blockKey, locale = "en") => {
106
+ const block = entry?.blocks?.find((f) => f.key === blockKey);
107
+ if (!block) return {};
108
+ if (block.type === "list" && Array.isArray(block.value)) {
109
+ return block.value.reduce((acc, current) => {
110
+ acc[current.key] = unwrapBlock(current, locale);
111
+ return acc;
112
+ }, {});
113
+ }
114
+ if (block.type === "map" && block.value && typeof block.value === "object") {
115
+ const result = {};
116
+ for (const [k, v] of Object.entries(block.value)) {
117
+ result[k] = unwrapBlock(v, locale);
133
118
  }
134
- if (accessToken) {
135
- headers["Authorization"] = `Bearer ${accessToken}`;
119
+ return result;
120
+ }
121
+ return { [block.key]: unwrapBlock(block, locale) };
122
+ };
123
+ var getImageUrl = (imageBlock, isBlock = true) => {
124
+ if (!imageBlock) return null;
125
+ if (imageBlock.type === "relationship_media") {
126
+ const mediaValue = imageBlock.value;
127
+ return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
128
+ }
129
+ if (isBlock) {
130
+ if (typeof imageBlock === "string") return imageBlock;
131
+ if (imageBlock.url) return imageBlock.url;
132
+ }
133
+ return imageBlock.resolutions?.original?.url || null;
134
+ };
135
+
136
+ // src/api/storefront.ts
137
+ var COMMON_ACTIVITY_TYPES = [
138
+ "page_view",
139
+ "product_view",
140
+ "service_view",
141
+ "provider_view",
142
+ "cart_added",
143
+ "cart_removed",
144
+ "checkout_started",
145
+ "purchase",
146
+ "booking_created",
147
+ "signin",
148
+ "signup",
149
+ "verified_email",
150
+ "search",
151
+ "share",
152
+ "wishlist_added"
153
+ ];
154
+ async function ensureCustomer(apiConfig) {
155
+ if (apiConfig.getToken) {
156
+ const tokens = await apiConfig.getToken();
157
+ if (tokens?.accessToken) return;
158
+ }
159
+ const response = await apiConfig.httpClient.post(
160
+ `/v1/storefront/${apiConfig.businessId}/customers/initialize`,
161
+ {
162
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
136
163
  }
137
- const finalPath = options?.params ? path + buildQueryString(options.params) : path;
138
- const fetchOpts = { method, headers };
139
- if (!["GET", "DELETE"].includes(method) && body !== void 0) {
140
- fetchOpts.body = JSON.stringify(body);
164
+ );
165
+ const accessToken = response?.accessToken;
166
+ const refreshToken = response?.refreshToken;
167
+ const accessExpiresAt = response?.accessExpiresAt;
168
+ if (accessToken) {
169
+ apiConfig.setToken?.({ accessToken, refreshToken, accessExpiresAt });
170
+ }
171
+ }
172
+ var createActivityApi = (apiConfig) => ({
173
+ COMMON_ACTIVITY_TYPES,
174
+ async track(params) {
175
+ await ensureCustomer(apiConfig);
176
+ await apiConfig.httpClient.post(
177
+ `/v1/storefront/${apiConfig.businessId}/activities/track`,
178
+ { type: params.type, payload: params.payload }
179
+ );
180
+ }
181
+ });
182
+ function groupCartToItems(cart) {
183
+ const groups = /* @__PURE__ */ new Map();
184
+ for (const slot of cart) {
185
+ const key = `${slot.serviceId}:${slot.providerId}`;
186
+ if (!groups.has(key)) {
187
+ groups.set(key, {
188
+ serviceId: slot.serviceId,
189
+ providerId: slot.providerId,
190
+ slots: []
191
+ });
141
192
  }
142
- const fullUrl = `${cfg.baseUrl}${finalPath}`;
143
- let res;
144
- let data;
145
- const startedAt = Date.now();
146
- try {
193
+ groups.get(key).slots.push({ from: slot.from, to: slot.to });
194
+ }
195
+ return [...groups.values()];
196
+ }
197
+ var createStorefrontApi = (apiConfig) => {
198
+ const base = (businessId = apiConfig.businessId) => `/v1/storefront/${businessId}`;
199
+ let cart = [];
200
+ return {
201
+ business: {
202
+ getBusiness(options) {
203
+ return apiConfig.httpClient.get(base(), options);
204
+ },
205
+ getIntegrationConfig(params, options) {
206
+ return apiConfig.httpClient.get(
207
+ `${base(params.businessId)}/integrations/config/${params.type}`,
208
+ options
209
+ );
210
+ },
211
+ location: {
212
+ getCountries(options) {
213
+ return apiConfig.httpClient.get(`/v1/platform/countries`, options);
214
+ },
215
+ getCountry(countryCode, options) {
216
+ return apiConfig.httpClient.get(
217
+ `/v1/platform/countries/${countryCode}`,
218
+ options
219
+ );
220
+ },
221
+ list(options) {
222
+ return apiConfig.httpClient.get(`${base()}/locations`, options);
223
+ },
224
+ get(id, options) {
225
+ return apiConfig.httpClient.get(`${base()}/locations/${id}`, options);
226
+ }
227
+ },
228
+ market: {
229
+ list(options) {
230
+ return apiConfig.httpClient.get(`${base()}/markets`, options);
231
+ },
232
+ get(id, options) {
233
+ return apiConfig.httpClient.get(`${base()}/markets/${id}`, options);
234
+ }
235
+ }
236
+ },
237
+ cms: {
238
+ node: {
239
+ async get(params, options) {
240
+ const businessId = params.businessId || apiConfig.businessId;
241
+ let identifier;
242
+ if (params.id) {
243
+ identifier = params.id;
244
+ } else if (params.slug) {
245
+ identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
246
+ } else if (params.key) {
247
+ identifier = `${businessId}:${params.key}`;
248
+ } else {
249
+ throw new Error("GetNodeParams requires id, slug, or key");
250
+ }
251
+ const response = await apiConfig.httpClient.get(
252
+ `${base(businessId)}/nodes/${identifier}`,
253
+ options
254
+ );
255
+ return {
256
+ ...response,
257
+ getBlock(key) {
258
+ return getBlockFromArray(response, key, apiConfig.locale);
259
+ },
260
+ getBlockValues(key) {
261
+ return getBlockObjectValues(response, key, apiConfig.locale);
262
+ },
263
+ getImage(key) {
264
+ const block = getBlockFromArray(response, key, apiConfig.locale);
265
+ return getImageUrl(block, true);
266
+ }
267
+ };
268
+ },
269
+ find(params, options) {
270
+ const { businessId, ...queryParams } = params;
271
+ return apiConfig.httpClient.get(`${base(businessId)}/nodes`, {
272
+ ...options,
273
+ params: queryParams
274
+ });
275
+ },
276
+ getChildren(params, options) {
277
+ const { id, businessId, ...queryParams } = params;
278
+ return apiConfig.httpClient.get(`${base(businessId)}/nodes/${id}/children`, {
279
+ ...options,
280
+ params: queryParams
281
+ });
282
+ }
283
+ },
284
+ form: {
285
+ get(params, options) {
286
+ const businessId = params.businessId || apiConfig.businessId;
287
+ let identifier;
288
+ if (params.id) {
289
+ identifier = params.id;
290
+ } else if (params.key) {
291
+ identifier = `${businessId}:${params.key}`;
292
+ } else {
293
+ throw new Error("GetFormParams requires id or key");
294
+ }
295
+ return apiConfig.httpClient.get(
296
+ `${base(businessId)}/forms/${identifier}`,
297
+ options
298
+ );
299
+ },
300
+ submit(params, options) {
301
+ const { businessId, formId, ...payload } = params;
302
+ const targetBusinessId = businessId || apiConfig.businessId;
303
+ return apiConfig.httpClient.post(
304
+ `${base(targetBusinessId)}/forms/${formId}/submissions`,
305
+ { ...payload, formId, businessId: targetBusinessId },
306
+ options
307
+ );
308
+ }
309
+ },
310
+ taxonomy: {
311
+ get(params, options) {
312
+ const businessId = params.businessId || apiConfig.businessId;
313
+ let identifier;
314
+ if (params.id) {
315
+ identifier = params.id;
316
+ } else if (params.key) {
317
+ identifier = `${businessId}:${params.key}`;
318
+ } else {
319
+ throw new Error("GetTaxonomyParams requires id or key");
320
+ }
321
+ return apiConfig.httpClient.get(
322
+ `${base(businessId)}/taxonomies/${identifier}`,
323
+ options
324
+ );
325
+ },
326
+ getChildren(params, options) {
327
+ const businessId = params.businessId || apiConfig.businessId;
328
+ return apiConfig.httpClient.get(
329
+ `${base(businessId)}/taxonomies/${params.id}/children`,
330
+ options
331
+ );
332
+ }
333
+ }
334
+ },
335
+ eshop: {
336
+ product: {
337
+ get(params, options) {
338
+ const businessId = params.businessId || apiConfig.businessId;
339
+ let identifier;
340
+ if (params.id) {
341
+ identifier = params.id;
342
+ } else if (params.slug) {
343
+ identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
344
+ } else {
345
+ throw new Error("GetProductParams requires id or slug");
346
+ }
347
+ return apiConfig.httpClient.get(
348
+ `${base(businessId)}/products/${identifier}`,
349
+ options
350
+ );
351
+ },
352
+ find(params, options) {
353
+ const { businessId, ...queryParams } = params;
354
+ return apiConfig.httpClient.get(`${base(businessId)}/products`, {
355
+ ...options,
356
+ params: queryParams
357
+ });
358
+ }
359
+ },
360
+ order: {
361
+ getQuote(params, options) {
362
+ const businessId = params.businessId || apiConfig.businessId;
363
+ const { location, businessId: _businessId, ...rest } = params;
364
+ const shippingAddress = location ? {
365
+ country: location.country || "",
366
+ state: location.state || "",
367
+ city: location.city || "",
368
+ postalCode: location.postalCode || "",
369
+ name: "",
370
+ street1: "",
371
+ street2: null
372
+ } : void 0;
373
+ return apiConfig.httpClient.post(
374
+ `${base(businessId)}/orders/quote`,
375
+ { ...rest, shippingAddress, market: apiConfig.market },
376
+ options
377
+ );
378
+ },
379
+ checkout(params, options) {
380
+ const businessId = params.businessId || apiConfig.businessId;
381
+ return apiConfig.httpClient.post(
382
+ `${base(businessId)}/orders/checkout`,
383
+ { ...params, businessId, market: apiConfig.market },
384
+ options
385
+ );
386
+ },
387
+ get(params, options) {
388
+ const businessId = params.businessId || apiConfig.businessId;
389
+ return apiConfig.httpClient.get(
390
+ `${base(businessId)}/orders/${params.id}`,
391
+ options
392
+ );
393
+ },
394
+ find(params, options) {
395
+ const { businessId, ...queryParams } = params;
396
+ return apiConfig.httpClient.get(`${base(businessId)}/orders`, {
397
+ ...options,
398
+ params: queryParams
399
+ });
400
+ }
401
+ }
402
+ },
403
+ booking: {
404
+ addToCart(slot) {
405
+ cart.push(slot);
406
+ },
407
+ removeFromCart(slotId) {
408
+ cart = cart.filter((slot) => slot.id !== slotId);
409
+ },
410
+ getCart() {
411
+ return [...cart];
412
+ },
413
+ clearCart() {
414
+ cart = [];
415
+ },
416
+ checkout(params, options) {
417
+ const { businessId, items: paramItems, ...payload } = params || {};
418
+ const targetBusinessId = businessId || apiConfig.businessId;
419
+ const items = paramItems || groupCartToItems(cart);
420
+ return apiConfig.httpClient.post(
421
+ `${base(targetBusinessId)}/bookings/checkout`,
422
+ { market: "booking", ...payload, items },
423
+ options
424
+ );
425
+ },
426
+ get(params, options) {
427
+ const businessId = params.businessId || apiConfig.businessId;
428
+ return apiConfig.httpClient.get(
429
+ `${base(businessId)}/bookings/${params.id}`,
430
+ options
431
+ );
432
+ },
433
+ find(params, options) {
434
+ const { businessId, ...queryParams } = params;
435
+ return apiConfig.httpClient.get(`${base(businessId)}/bookings`, {
436
+ ...options,
437
+ params: queryParams
438
+ });
439
+ },
440
+ getQuote(params, options) {
441
+ const { businessId, ...payload } = params;
442
+ return apiConfig.httpClient.post(
443
+ `${base(businessId)}/bookings/quote`,
444
+ { market: "booking", ...payload },
445
+ options
446
+ );
447
+ },
448
+ getAvailability(params, options) {
449
+ const { businessId, ...queryParams } = params;
450
+ return apiConfig.httpClient.get(
451
+ `${base(businessId)}/bookings/availability`,
452
+ { ...options, params: queryParams }
453
+ );
454
+ },
455
+ cancelItem(params, options) {
456
+ const { businessId, bookingId, itemId, ...payload } = params;
457
+ return apiConfig.httpClient.post(
458
+ `${base(businessId)}/bookings/${bookingId}/items/${itemId}/cancel`,
459
+ payload,
460
+ options
461
+ );
462
+ },
463
+ service: {
464
+ get(params, options) {
465
+ const businessId = params.businessId || apiConfig.businessId;
466
+ let identifier;
467
+ if (params.id) {
468
+ identifier = params.id;
469
+ } else if (params.slug) {
470
+ identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
471
+ } else {
472
+ throw new Error("GetServiceParams requires id or slug");
473
+ }
474
+ return apiConfig.httpClient.get(
475
+ `${base(businessId)}/services/${identifier}`,
476
+ options
477
+ );
478
+ },
479
+ find(params, options) {
480
+ const { businessId, ...queryParams } = params;
481
+ return apiConfig.httpClient.get(`${base(businessId)}/services`, {
482
+ ...options,
483
+ params: queryParams
484
+ });
485
+ },
486
+ findProviders(params, options) {
487
+ const { businessId, ...queryParams } = params;
488
+ return apiConfig.httpClient.get(`${base(businessId)}/service-providers`, {
489
+ ...options,
490
+ params: queryParams
491
+ });
492
+ }
493
+ },
494
+ provider: {
495
+ get(params, options) {
496
+ const businessId = params.businessId || apiConfig.businessId;
497
+ let identifier;
498
+ if (params.id) {
499
+ identifier = params.id;
500
+ } else if (params.slug) {
501
+ identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
502
+ } else {
503
+ throw new Error("GetProviderParams requires id or slug");
504
+ }
505
+ return apiConfig.httpClient.get(
506
+ `${base(businessId)}/providers/${identifier}`,
507
+ options
508
+ );
509
+ },
510
+ find(params, options) {
511
+ const { businessId, ...queryParams } = params;
512
+ return apiConfig.httpClient.get(`${base(businessId)}/providers`, {
513
+ ...options,
514
+ params: queryParams
515
+ });
516
+ }
517
+ }
518
+ },
519
+ crm: {
520
+ customer: {
521
+ initialize(params, options) {
522
+ const businessId = params?.businessId || apiConfig.businessId;
523
+ return apiConfig.httpClient.post(
524
+ `${base(businessId)}/customers/initialize`,
525
+ { businessId },
526
+ options
527
+ );
528
+ },
529
+ signInAnonymously(params, options) {
530
+ const businessId = params?.businessId || apiConfig.businessId;
531
+ return apiConfig.httpClient.post(
532
+ `${base(businessId)}/customers/initialize`,
533
+ { businessId },
534
+ options
535
+ );
536
+ },
537
+ connect(params, options) {
538
+ const businessId = params.businessId || apiConfig.businessId;
539
+ return apiConfig.httpClient.post(
540
+ `${base(businessId)}/customers/connect`,
541
+ { email: params.email, businessId },
542
+ options
543
+ );
544
+ },
545
+ requestCode(params, options) {
546
+ const businessId = params.businessId || apiConfig.businessId;
547
+ return apiConfig.httpClient.post(
548
+ `${base(businessId)}/customers/auth/code`,
549
+ { email: params.email, businessId },
550
+ options
551
+ );
552
+ },
553
+ verify(params, options) {
554
+ const businessId = params.businessId || apiConfig.businessId;
555
+ return apiConfig.httpClient.post(
556
+ `${base(businessId)}/customers/auth/verify`,
557
+ { email: params.email, code: params.code, businessId },
558
+ options
559
+ );
560
+ },
561
+ refreshToken(params, options) {
562
+ const businessId = params.businessId || apiConfig.businessId;
563
+ return apiConfig.httpClient.post(
564
+ `${base(businessId)}/customers/auth/refresh`,
565
+ { refreshToken: params.refreshToken },
566
+ options
567
+ );
568
+ },
569
+ getMe(options) {
570
+ return apiConfig.httpClient.get(`${base()}/customers/me`, options);
571
+ }
572
+ },
573
+ audience: {
574
+ get(params, options) {
575
+ let identifier;
576
+ if (params.id) {
577
+ identifier = params.id;
578
+ } else if (params.key) {
579
+ identifier = `${apiConfig.businessId}:${params.key}`;
580
+ } else {
581
+ throw new Error("GetAudienceParams requires id or key");
582
+ }
583
+ return apiConfig.httpClient.get(
584
+ `${base(apiConfig.businessId)}/audiences/${identifier}`,
585
+ options
586
+ );
587
+ },
588
+ find(params, options) {
589
+ return apiConfig.httpClient.get(`${base()}/audiences`, {
590
+ ...options,
591
+ params
592
+ });
593
+ },
594
+ subscribe(params, options) {
595
+ return apiConfig.httpClient.post(
596
+ `${base()}/audiences/${params.id}/subscribe`,
597
+ {
598
+ customerId: params.customerId,
599
+ priceId: params.priceId,
600
+ successUrl: params.successUrl,
601
+ cancelUrl: params.cancelUrl,
602
+ confirmUrl: params.confirmUrl
603
+ },
604
+ options
605
+ );
606
+ },
607
+ checkAccess(params, options) {
608
+ return apiConfig.httpClient.get(
609
+ `${base()}/audiences/${params.id}/access`,
610
+ options
611
+ );
612
+ },
613
+ unsubscribe(token, options) {
614
+ return apiConfig.httpClient.get(`${base()}/audiences/unsubscribe`, {
615
+ ...options,
616
+ params: { token }
617
+ });
618
+ },
619
+ confirm(token, options) {
620
+ return apiConfig.httpClient.get(`${base()}/audiences/confirm`, {
621
+ ...options,
622
+ params: { token }
623
+ });
624
+ }
625
+ }
626
+ },
627
+ activity: createActivityApi(apiConfig),
628
+ automation: {
629
+ agent: {
630
+ getAgents(params, options) {
631
+ const businessId = params?.businessId || apiConfig.businessId;
632
+ const queryParams = { ...params || {} };
633
+ delete queryParams.businessId;
634
+ return apiConfig.httpClient.get(`${base(businessId)}/agents`, {
635
+ ...options,
636
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
637
+ });
638
+ },
639
+ getAgent(params, options) {
640
+ const businessId = params.businessId || apiConfig.businessId;
641
+ return apiConfig.httpClient.get(
642
+ `${base(businessId)}/agents/${params.id}`,
643
+ options
644
+ );
645
+ },
646
+ sendMessage(params, options) {
647
+ const businessId = params.businessId || apiConfig.businessId;
648
+ const body = { message: params.message };
649
+ if (params.chatId) body.chatId = params.chatId;
650
+ return apiConfig.httpClient.post(
651
+ `${base(businessId)}/agents/${params.id}/chats/messages`,
652
+ body,
653
+ options
654
+ );
655
+ },
656
+ getChat(params, options) {
657
+ const businessId = params.businessId || apiConfig.businessId;
658
+ return apiConfig.httpClient.get(
659
+ `${base(businessId)}/agents/${params.id}/chats/${params.chatId}`,
660
+ options
661
+ );
662
+ },
663
+ getChatMessages(params, options) {
664
+ const businessId = params.businessId || apiConfig.businessId;
665
+ const queryParams = {};
666
+ if (params.limit) queryParams.limit = String(params.limit);
667
+ return apiConfig.httpClient.get(
668
+ `${base(businessId)}/agents/${params.id}/chats/${params.chatId}/messages`,
669
+ {
670
+ ...options,
671
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
672
+ }
673
+ );
674
+ },
675
+ rateChat(params, options) {
676
+ const businessId = params.businessId || apiConfig.businessId;
677
+ const body = { rating: params.rating };
678
+ if (params.comment) body.comment = params.comment;
679
+ return apiConfig.httpClient.post(
680
+ `${base(businessId)}/agents/${params.id}/chats/${params.chatId}/rate`,
681
+ body,
682
+ options
683
+ );
684
+ }
685
+ }
686
+ }
687
+ };
688
+ };
689
+
690
+ // src/utils/errors.ts
691
+ var convertServerErrorToRequestError = (serverError, renameRules) => {
692
+ const validationErrors = serverError?.validationErrors ?? [];
693
+ return {
694
+ ...serverError,
695
+ validationErrors: validationErrors.map((validationError) => {
696
+ const field = validationError.field;
697
+ return {
698
+ field,
699
+ error: validationError.error || "GENERAL.VALIDATION_ERROR"
700
+ };
701
+ })
702
+ };
703
+ };
704
+
705
+ // src/utils/queryParams.ts
706
+ function buildQueryString(params) {
707
+ const queryParts = [];
708
+ Object.entries(params).forEach(([key, value]) => {
709
+ if (value === null || value === void 0) {
710
+ return;
711
+ }
712
+ if (Array.isArray(value)) {
713
+ const jsonString = JSON.stringify(value);
714
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
715
+ } else if (typeof value === "string") {
716
+ queryParts.push(`${key}=${encodeURIComponent(value)}`);
717
+ } else if (typeof value === "number" || typeof value === "boolean") {
718
+ queryParts.push(`${key}=${value}`);
719
+ } else if (typeof value === "object") {
720
+ const jsonString = JSON.stringify(value);
721
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
722
+ }
723
+ });
724
+ return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
725
+ }
726
+
727
+ // src/services/createHttpClient.ts
728
+ var STORAGE_KEYS = {
729
+ accessToken: "arky_token",
730
+ refreshToken: "arky_refresh",
731
+ accessExpiresAt: "arky_expires_at"
732
+ };
733
+ function defaultGetToken() {
734
+ if (typeof window === "undefined") return { accessToken: "" };
735
+ return {
736
+ accessToken: localStorage.getItem(STORAGE_KEYS.accessToken) || "",
737
+ refreshToken: localStorage.getItem(STORAGE_KEYS.refreshToken) || "",
738
+ accessExpiresAt: parseInt(localStorage.getItem(STORAGE_KEYS.accessExpiresAt) || "0", 10)
739
+ };
740
+ }
741
+ function defaultSetToken(tokens) {
742
+ if (typeof window === "undefined") return;
743
+ if (tokens.accessToken) {
744
+ localStorage.setItem(STORAGE_KEYS.accessToken, tokens.accessToken);
745
+ localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.refreshToken || "");
746
+ localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.accessExpiresAt || 0).toString());
747
+ } else {
748
+ Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
749
+ }
750
+ }
751
+ function defaultLogout() {
752
+ if (typeof window === "undefined") return;
753
+ Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
754
+ }
755
+ function defaultIsAuthenticated() {
756
+ if (typeof window === "undefined") return false;
757
+ const token = localStorage.getItem(STORAGE_KEYS.accessToken) || "";
758
+ return token.startsWith("customer_") || token.startsWith("account_");
759
+ }
760
+ function createHttpClient(cfg) {
761
+ const getToken = cfg.getToken || defaultGetToken;
762
+ const setToken = cfg.setToken || defaultSetToken;
763
+ const logout = cfg.logout || defaultLogout;
764
+ const refreshEndpoint = `${cfg.baseUrl}${cfg.refreshPath || "/v1/auth/refresh"}`;
765
+ let refreshPromise = null;
766
+ async function ensureFreshToken() {
767
+ if (refreshPromise) {
768
+ return refreshPromise;
769
+ }
770
+ refreshPromise = (async () => {
771
+ const { refreshToken } = await getToken();
772
+ if (!refreshToken) {
773
+ logout();
774
+ const err = new Error("No refresh token available");
775
+ err.name = "ApiError";
776
+ err.statusCode = 401;
777
+ throw err;
778
+ }
779
+ const refRes = await fetch(refreshEndpoint, {
780
+ method: "POST",
781
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
782
+ body: JSON.stringify({ refreshToken })
783
+ });
784
+ if (!refRes.ok) {
785
+ logout();
786
+ const err = new Error("Token refresh failed");
787
+ err.name = "ApiError";
788
+ err.statusCode = 401;
789
+ throw err;
790
+ }
791
+ const data = await refRes.json();
792
+ setToken(data);
793
+ })().finally(() => {
794
+ refreshPromise = null;
795
+ });
796
+ return refreshPromise;
797
+ }
798
+ async function request(method, path, body, options) {
799
+ if (options?.transformRequest) {
800
+ body = options.transformRequest(body);
801
+ }
802
+ const headers = {
803
+ Accept: "application/json",
804
+ "Content-Type": "application/json",
805
+ ...options?.headers || {}
806
+ };
807
+ let { accessToken, accessExpiresAt } = await getToken();
808
+ const nowSec = Date.now() / 1e3;
809
+ if (accessExpiresAt && nowSec > accessExpiresAt) {
810
+ await ensureFreshToken();
811
+ const tokens = await getToken();
812
+ accessToken = tokens.accessToken;
813
+ }
814
+ if (accessToken) {
815
+ headers["Authorization"] = `Bearer ${accessToken}`;
816
+ }
817
+ const finalPath = options?.params ? path + buildQueryString(options.params) : path;
818
+ const fetchOpts = { method, headers };
819
+ if (!["GET", "DELETE"].includes(method) && body !== void 0) {
820
+ fetchOpts.body = JSON.stringify(body);
821
+ }
822
+ const fullUrl = `${cfg.baseUrl}${finalPath}`;
823
+ let res;
824
+ let data;
825
+ const startedAt = Date.now();
826
+ try {
147
827
  res = await fetch(fullUrl, fetchOpts);
148
828
  } catch (error) {
149
829
  const err = new Error(error instanceof Error ? error.message : "Network request failed");
@@ -601,132 +1281,6 @@ var createPromoCodeApi = (apiConfig) => {
601
1281
  };
602
1282
  };
603
1283
 
604
- // src/utils/blocks.ts
605
- function getBlockLabel(block) {
606
- if (!block) return "";
607
- return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) ?? "";
608
- }
609
- function formatBlockValue(block) {
610
- if (!block || block.value === null || block.value === void 0) return "";
611
- const value = block.value;
612
- switch (block.type) {
613
- case "boolean":
614
- return value ? "Yes" : "No";
615
- case "number":
616
- if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
617
- return new Date(value).toLocaleDateString();
618
- }
619
- return String(value);
620
- case "relationship_entry":
621
- case "relationship_media":
622
- if (value && typeof value === "object") {
623
- return value.mimeType ? value.name || value.id : value.title || value.name || value.id;
624
- }
625
- return String(value);
626
- default:
627
- return String(value);
628
- }
629
- }
630
- function prepareBlocksForSubmission(formData, blockTypes) {
631
- return Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).map((key) => ({
632
- key,
633
- value: blockTypes?.[key] === "list" && !Array.isArray(formData[key]) ? [formData[key]] : formData[key]
634
- }));
635
- }
636
- function extractBlockValues(blocks) {
637
- const values = {};
638
- blocks.forEach((block) => {
639
- values[block.key] = block.value ?? null;
640
- });
641
- return values;
642
- }
643
- var getBlockValue = (entry, blockKey) => {
644
- const block = entry?.blocks?.find((f) => f.key === blockKey);
645
- return block?.value ?? null;
646
- };
647
- var getBlockTextValue = (block, locale = "en") => {
648
- if (!block || block.value === null || block.value === void 0) return "";
649
- if (block.type === "localized_text" || block.type === "markdown") {
650
- if (typeof block.value === "object" && block.value !== null) {
651
- return block.value[locale] ?? block.value["en"] ?? "";
652
- }
653
- }
654
- if (typeof block.value === "string") return block.value;
655
- return String(block.value ?? "");
656
- };
657
- var getBlockValues = (entry, blockKey) => {
658
- const block = entry?.blocks?.find((f) => f.key === blockKey);
659
- if (!block) return [];
660
- if (block.type === "list" && Array.isArray(block.value)) {
661
- return block.value;
662
- }
663
- return [];
664
- };
665
- function unwrapBlock(block, locale) {
666
- if (!block?.type || block.value === void 0) return block;
667
- if (block.type === "list") {
668
- return block.value.map((obj) => {
669
- const parsed = {};
670
- for (const [k, v] of Object.entries(obj)) {
671
- parsed[k] = unwrapBlock(v, locale);
672
- }
673
- return parsed;
674
- });
675
- }
676
- if (block.type === "map") {
677
- const parsed = {};
678
- for (const [k, v] of Object.entries(block.value || {})) {
679
- parsed[k] = unwrapBlock(v, locale);
680
- }
681
- return parsed;
682
- }
683
- if (block.type === "localized_text" || block.type === "markdown") {
684
- return block.value?.[locale];
685
- }
686
- return block.value;
687
- }
688
- var getBlockObjectValues = (entry, blockKey, locale = "en") => {
689
- const block = entry?.blocks?.find((f) => f.key === blockKey);
690
- if (!block || block.type !== "list" || !Array.isArray(block.value)) return [];
691
- return block.value.map((obj) => {
692
- if (!obj?.value || !Array.isArray(obj.value)) return {};
693
- return obj.value.reduce((acc, current) => {
694
- acc[current.key] = unwrapBlock(current, locale);
695
- return acc;
696
- }, {});
697
- });
698
- };
699
- var getBlockFromArray = (entry, blockKey, locale = "en") => {
700
- const block = entry?.blocks?.find((f) => f.key === blockKey);
701
- if (!block) return {};
702
- if (block.type === "list" && Array.isArray(block.value)) {
703
- return block.value.reduce((acc, current) => {
704
- acc[current.key] = unwrapBlock(current, locale);
705
- return acc;
706
- }, {});
707
- }
708
- if (block.type === "map" && block.value && typeof block.value === "object") {
709
- const result = {};
710
- for (const [k, v] of Object.entries(block.value)) {
711
- result[k] = unwrapBlock(v, locale);
712
- }
713
- return result;
714
- }
715
- return { [block.key]: unwrapBlock(block, locale) };
716
- };
717
- var getImageUrl = (imageBlock, isBlock = true) => {
718
- if (!imageBlock) return null;
719
- if (imageBlock.type === "relationship_media") {
720
- const mediaValue = imageBlock.value;
721
- return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
722
- }
723
- if (isBlock) {
724
- if (typeof imageBlock === "string") return imageBlock;
725
- if (imageBlock.url) return imageBlock.url;
726
- }
727
- return imageBlock.resolutions?.original?.url || null;
728
- };
729
-
730
1284
  // src/api/cms.ts
731
1285
  var createCmsApi = (apiConfig) => {
732
1286
  return {
@@ -1220,6 +1774,37 @@ var createMarketApi = (apiConfig) => {
1220
1774
  };
1221
1775
 
1222
1776
  // src/api/crm.ts
1777
+ var createActivityAdminApi = (apiConfig) => ({
1778
+ async timeline(params, options) {
1779
+ const businessId = params.businessId || apiConfig.businessId;
1780
+ const queryParams = { customerId: params.customerId };
1781
+ if (params.limit !== void 0) queryParams.limit = params.limit;
1782
+ if (params.cursor) queryParams.cursor = params.cursor;
1783
+ return apiConfig.httpClient.get(
1784
+ `/v1/businesses/${businessId}/activities/timeline`,
1785
+ { ...options, params: queryParams }
1786
+ );
1787
+ },
1788
+ async count(params, options) {
1789
+ const businessId = params.businessId || apiConfig.businessId;
1790
+ const queryParams = {};
1791
+ if (params.type) queryParams.type = params.type;
1792
+ if (params.payloadKey) queryParams.payloadKey = params.payloadKey;
1793
+ if (params.payloadValue) queryParams.payloadValue = params.payloadValue;
1794
+ if (params.windowSeconds !== void 0) queryParams.windowSeconds = params.windowSeconds;
1795
+ return apiConfig.httpClient.get(
1796
+ `/v1/businesses/${businessId}/activities/count`,
1797
+ { ...options, params: queryParams }
1798
+ );
1799
+ },
1800
+ async types(params, options) {
1801
+ const businessId = params?.businessId || apiConfig.businessId;
1802
+ return apiConfig.httpClient.get(
1803
+ `/v1/businesses/${businessId}/activities/types`,
1804
+ options
1805
+ );
1806
+ }
1807
+ });
1223
1808
  var createCustomerApi = (apiConfig) => {
1224
1809
  return {
1225
1810
  async create(params, options) {
@@ -1338,149 +1923,8 @@ var createCustomerApi = (apiConfig) => {
1338
1923
  options
1339
1924
  );
1340
1925
  }
1341
- }
1342
- };
1343
- };
1344
-
1345
- // src/api/reaction.ts
1346
- var DEFAULT_REACTION_KINDS = [
1347
- "like",
1348
- "love",
1349
- "laugh",
1350
- "wow",
1351
- "sad",
1352
- "insightful",
1353
- "review",
1354
- "comment",
1355
- "star_1",
1356
- "star_2",
1357
- "star_3",
1358
- "star_4",
1359
- "star_5"
1360
- ];
1361
- var REACTION_KIND_REGEX = /^[a-z0-9_]{1,32}$/;
1362
- function isValidReactionKind(kind) {
1363
- return REACTION_KIND_REGEX.test(kind);
1364
- }
1365
- function computeAverageStars(counts) {
1366
- let total = 0;
1367
- let weighted = 0;
1368
- for (let i = 1; i <= 5; i++) {
1369
- const c = counts[`star_${i}`] ?? 0;
1370
- total += c;
1371
- weighted += c * i;
1372
- }
1373
- return {
1374
- average: total > 0 ? weighted / total : 0,
1375
- count: total
1376
- };
1377
- }
1378
- var createReactionApi = (apiConfig) => {
1379
- const base = (businessId) => `/v1/businesses/${businessId || apiConfig.businessId}/reactions`;
1380
- return {
1381
- DEFAULT_REACTION_KINDS,
1382
- isValidReactionKind,
1383
- computeAverageStars,
1384
- async create(params, options) {
1385
- const businessId = params.businessId || apiConfig.businessId;
1386
- return apiConfig.httpClient.post(
1387
- base(businessId),
1388
- {
1389
- businessId,
1390
- target: params.target,
1391
- kind: params.kind,
1392
- blocks: params.blocks || [],
1393
- parentId: params.parentId,
1394
- taxonomies: params.taxonomies || []
1395
- },
1396
- options
1397
- );
1398
- },
1399
- async get(params, options) {
1400
- const businessId = params.businessId || apiConfig.businessId;
1401
- return apiConfig.httpClient.get(
1402
- `${base(businessId)}/${params.id}`,
1403
- options
1404
- );
1405
- },
1406
- async find(params, options) {
1407
- const businessId = params?.businessId || apiConfig.businessId;
1408
- const queryParams = {};
1409
- if (params?.targetType) queryParams.targetType = params.targetType;
1410
- if (params?.targetId) queryParams.targetId = params.targetId;
1411
- if (params?.parentId) queryParams.parentId = params.parentId;
1412
- if (params?.customerId) queryParams.customerId = params.customerId;
1413
- if (params?.kind) queryParams.kind = params.kind;
1414
- if (params?.status) queryParams.status = params.status;
1415
- if (params?.contentOnly !== void 0)
1416
- queryParams.contentOnly = params.contentOnly;
1417
- if (params?.verified !== void 0)
1418
- queryParams.verified = params.verified;
1419
- if (params?.query) queryParams.query = params.query;
1420
- if (params?.limit !== void 0) queryParams.limit = params.limit;
1421
- if (params?.cursor) queryParams.cursor = params.cursor;
1422
- return apiConfig.httpClient.get(
1423
- base(businessId),
1424
- { ...options, params: queryParams }
1425
- );
1426
- },
1427
- async update(params, options) {
1428
- const businessId = params.businessId || apiConfig.businessId;
1429
- return apiConfig.httpClient.put(
1430
- `${base(businessId)}/${params.id}`,
1431
- {
1432
- id: params.id,
1433
- businessId,
1434
- blocks: params.blocks,
1435
- taxonomies: params.taxonomies
1436
- },
1437
- options
1438
- );
1439
- },
1440
- async remove(params, options) {
1441
- const businessId = params.businessId || apiConfig.businessId;
1442
- return apiConfig.httpClient.delete(
1443
- `${base(businessId)}/${params.id}`,
1444
- options
1445
- );
1446
- },
1447
- async moderate(params, options) {
1448
- const businessId = params.businessId || apiConfig.businessId;
1449
- return apiConfig.httpClient.post(
1450
- `${base(businessId)}/${params.id}/moderate`,
1451
- {
1452
- id: params.id,
1453
- businessId,
1454
- status: params.status
1455
- },
1456
- options
1457
- );
1458
- },
1459
- async listAdmin(params, options) {
1460
- const businessId = params.businessId || apiConfig.businessId;
1461
- const queryParams = { businessId };
1462
- if (params.limit !== void 0) queryParams.limit = params.limit;
1463
- if (params.cursor) queryParams.cursor = params.cursor;
1464
- return apiConfig.httpClient.get(
1465
- `${base(businessId)}/admin`,
1466
- { ...options, params: queryParams }
1467
- );
1468
- },
1469
- async summary(params, options) {
1470
- const businessId = params.businessId || apiConfig.businessId;
1471
- return apiConfig.httpClient.get(
1472
- `${base(businessId)}/summary`,
1473
- {
1474
- ...options,
1475
- params: {
1476
- businessId,
1477
- targetType: params.targetType,
1478
- targetId: params.targetId,
1479
- parentId: params.parentId
1480
- }
1481
- }
1482
- );
1483
- }
1926
+ },
1927
+ activity: createActivityAdminApi(apiConfig)
1484
1928
  };
1485
1929
  };
1486
1930
 
@@ -1658,847 +2102,271 @@ var createAgentApi = (apiConfig) => {
1658
2102
  );
1659
2103
  },
1660
2104
  async rateChat(params, options) {
1661
- const body = { rating: params.rating };
1662
- if (params.comment) body.comment = params.comment;
1663
- return apiConfig.httpClient.post(
1664
- `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/rate`,
1665
- body,
1666
- options
1667
- );
1668
- },
1669
- async getBusinessChats(params, options) {
1670
- const businessId = params.businessId || apiConfig.businessId;
1671
- const { businessId: _, ...queryParams } = params;
1672
- return apiConfig.httpClient.get(`/v1/businesses/${businessId}/chats`, {
1673
- ...options,
1674
- params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1675
- });
1676
- },
1677
- async getChatMessages(params, options) {
1678
- const queryParams = {};
1679
- if (params.limit) queryParams.limit = String(params.limit);
1680
- return apiConfig.httpClient.get(
1681
- `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/messages`,
1682
- {
1683
- ...options,
1684
- params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1685
- }
1686
- );
1687
- }
1688
- };
1689
- };
1690
-
1691
- // src/api/emailTemplate.ts
1692
- var createEmailTemplateApi = (apiConfig) => {
1693
- return {
1694
- async createEmailTemplate(params, options) {
1695
- const { businessId, ...payload } = params;
1696
- const targetBusinessId = businessId || apiConfig.businessId;
1697
- return apiConfig.httpClient.post(
1698
- `/v1/businesses/${targetBusinessId}/email-templates`,
1699
- payload,
1700
- options
1701
- );
1702
- },
1703
- async updateEmailTemplate(params, options) {
1704
- const { businessId, ...payload } = params;
1705
- const targetBusinessId = businessId || apiConfig.businessId;
1706
- return apiConfig.httpClient.put(
1707
- `/v1/businesses/${targetBusinessId}/email-templates/${params.id}`,
1708
- payload,
1709
- options
1710
- );
1711
- },
1712
- async deleteEmailTemplate(params, options) {
1713
- const targetBusinessId = params.businessId || apiConfig.businessId;
1714
- return apiConfig.httpClient.delete(
1715
- `/v1/businesses/${targetBusinessId}/email-templates/${params.id}`,
1716
- options
1717
- );
1718
- },
1719
- async getEmailTemplate(params, options) {
1720
- const targetBusinessId = params.businessId || apiConfig.businessId;
1721
- let identifier;
1722
- if (params.id) {
1723
- identifier = params.id;
1724
- } else if (params.key) {
1725
- identifier = `${targetBusinessId}:${params.key}`;
1726
- } else {
1727
- throw new Error("GetEmailTemplateParams requires id or key");
1728
- }
1729
- return apiConfig.httpClient.get(
1730
- `/v1/businesses/${targetBusinessId}/email-templates/${identifier}`,
1731
- options
1732
- );
1733
- },
1734
- async getEmailTemplates(params, options) {
1735
- const { businessId, ...queryParams } = params;
1736
- const targetBusinessId = businessId || apiConfig.businessId;
1737
- return apiConfig.httpClient.get(
1738
- `/v1/businesses/${targetBusinessId}/email-templates`,
1739
- {
1740
- ...options,
1741
- params: queryParams
1742
- }
1743
- );
1744
- }
1745
- };
1746
- };
1747
-
1748
- // src/api/form.ts
1749
- var createFormApi = (apiConfig) => {
1750
- return {
1751
- async createForm(params, options) {
1752
- const { businessId, ...payload } = params;
1753
- const targetBusinessId = businessId || apiConfig.businessId;
1754
- return apiConfig.httpClient.post(
1755
- `/v1/businesses/${targetBusinessId}/forms`,
1756
- payload,
1757
- options
1758
- );
1759
- },
1760
- async updateForm(params, options) {
1761
- const { businessId, ...payload } = params;
1762
- const targetBusinessId = businessId || apiConfig.businessId;
1763
- return apiConfig.httpClient.put(
1764
- `/v1/businesses/${targetBusinessId}/forms/${params.id}`,
1765
- payload,
1766
- options
1767
- );
1768
- },
1769
- async deleteForm(params, options) {
1770
- const targetBusinessId = params.businessId || apiConfig.businessId;
1771
- return apiConfig.httpClient.delete(
1772
- `/v1/businesses/${targetBusinessId}/forms/${params.id}`,
1773
- options
1774
- );
1775
- },
1776
- async getForm(params, options) {
1777
- const targetBusinessId = params.businessId || apiConfig.businessId;
1778
- let identifier;
1779
- if (params.id) {
1780
- identifier = params.id;
1781
- } else if (params.key) {
1782
- identifier = `${targetBusinessId}:${params.key}`;
1783
- } else {
1784
- throw new Error("GetFormParams requires id or key");
1785
- }
1786
- return apiConfig.httpClient.get(
1787
- `/v1/businesses/${targetBusinessId}/forms/${identifier}`,
1788
- options
1789
- );
1790
- },
1791
- async getForms(params, options) {
1792
- const { businessId, ...queryParams } = params;
1793
- const targetBusinessId = businessId || apiConfig.businessId;
1794
- return apiConfig.httpClient.get(
1795
- `/v1/businesses/${targetBusinessId}/forms`,
1796
- {
1797
- ...options,
1798
- params: queryParams
1799
- }
1800
- );
1801
- },
1802
- async submit(params, options) {
1803
- const { businessId, formId, ...payload } = params;
1804
- const targetBusinessId = businessId || apiConfig.businessId;
1805
- return apiConfig.httpClient.post(
1806
- `/v1/businesses/${targetBusinessId}/forms/${formId}/submissions`,
1807
- { ...payload, formId, businessId: targetBusinessId },
1808
- options
1809
- );
1810
- },
1811
- async getSubmissions(params, options) {
1812
- const { businessId, formId, ...queryParams } = params;
1813
- const targetBusinessId = businessId || apiConfig.businessId;
1814
- return apiConfig.httpClient.get(
1815
- `/v1/businesses/${targetBusinessId}/forms/${formId}/submissions`,
1816
- {
1817
- ...options,
1818
- params: { ...queryParams, formId, businessId: targetBusinessId }
1819
- }
1820
- );
1821
- },
1822
- async getSubmission(params, options) {
1823
- const targetBusinessId = params.businessId || apiConfig.businessId;
1824
- return apiConfig.httpClient.get(
1825
- `/v1/businesses/${targetBusinessId}/forms/${params.formId}/submissions/${params.id}`,
1826
- options
1827
- );
1828
- },
1829
- async updateSubmission(params, options) {
1830
- const { businessId, formId, id, ...payload } = params;
1831
- const targetBusinessId = businessId || apiConfig.businessId;
1832
- return apiConfig.httpClient.put(
1833
- `/v1/businesses/${targetBusinessId}/forms/${formId}/submissions/${id}`,
1834
- { ...payload, formId, businessId: targetBusinessId, id },
1835
- options
1836
- );
1837
- }
1838
- };
1839
- };
1840
-
1841
- // src/api/taxonomy.ts
1842
- var createTaxonomyApi = (apiConfig) => {
1843
- return {
1844
- async createTaxonomy(params, options) {
1845
- const { businessId, ...payload } = params;
1846
- const targetBusinessId = businessId || apiConfig.businessId;
1847
- return apiConfig.httpClient.post(
1848
- `/v1/businesses/${targetBusinessId}/taxonomies`,
1849
- payload,
1850
- options
1851
- );
1852
- },
1853
- async updateTaxonomy(params, options) {
1854
- const { businessId, ...payload } = params;
1855
- const targetBusinessId = businessId || apiConfig.businessId;
1856
- return apiConfig.httpClient.put(
1857
- `/v1/businesses/${targetBusinessId}/taxonomies/${params.id}`,
1858
- payload,
1859
- options
1860
- );
1861
- },
1862
- async deleteTaxonomy(params, options) {
1863
- const targetBusinessId = params.businessId || apiConfig.businessId;
1864
- return apiConfig.httpClient.delete(
1865
- `/v1/businesses/${targetBusinessId}/taxonomies/${params.id}`,
1866
- options
1867
- );
1868
- },
1869
- async getTaxonomy(params, options) {
1870
- const targetBusinessId = params.businessId || apiConfig.businessId;
1871
- let identifier;
1872
- if (params.id) {
1873
- identifier = params.id;
1874
- } else if (params.key) {
1875
- identifier = `${targetBusinessId}:${params.key}`;
1876
- } else {
1877
- throw new Error("GetTaxonomyParams requires id or key");
1878
- }
1879
- return apiConfig.httpClient.get(
1880
- `/v1/businesses/${targetBusinessId}/taxonomies/${identifier}`,
1881
- options
1882
- );
1883
- },
1884
- async getTaxonomies(params, options) {
1885
- const { businessId, ...queryParams } = params;
1886
- const targetBusinessId = businessId || apiConfig.businessId;
1887
- return apiConfig.httpClient.get(
1888
- `/v1/businesses/${targetBusinessId}/taxonomies`,
1889
- {
1890
- ...options,
1891
- params: queryParams
1892
- }
1893
- );
1894
- },
1895
- async getTaxonomyChildren(params, options) {
1896
- const { id, businessId } = params;
1897
- const targetBusinessId = businessId || apiConfig.businessId;
1898
- return apiConfig.httpClient.get(
1899
- `/v1/businesses/${targetBusinessId}/taxonomies/${id}/children`,
1900
- options
1901
- );
1902
- }
1903
- };
1904
- };
1905
-
1906
- // src/api/analytics.ts
1907
- var createAnalyticsApi = (apiConfig) => {
1908
- return {
1909
- async getSummary(params, options) {
1910
- return apiConfig.httpClient.get(
1911
- `/v1/businesses/${apiConfig.businessId}/analytics/summary`,
1912
- {
1913
- ...options,
1914
- params: params || {}
1915
- }
2105
+ const body = { rating: params.rating };
2106
+ if (params.comment) body.comment = params.comment;
2107
+ return apiConfig.httpClient.post(
2108
+ `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/rate`,
2109
+ body,
2110
+ options
1916
2111
  );
1917
2112
  },
1918
- async getStatusBreakdown(params, options) {
2113
+ async getBusinessChats(params, options) {
2114
+ const businessId = params.businessId || apiConfig.businessId;
2115
+ const { businessId: _, ...queryParams } = params;
2116
+ return apiConfig.httpClient.get(`/v1/businesses/${businessId}/chats`, {
2117
+ ...options,
2118
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
2119
+ });
2120
+ },
2121
+ async getChatMessages(params, options) {
2122
+ const queryParams = {};
2123
+ if (params.limit) queryParams.limit = String(params.limit);
1919
2124
  return apiConfig.httpClient.get(
1920
- `/v1/businesses/${apiConfig.businessId}/analytics/status`,
2125
+ `/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/messages`,
1921
2126
  {
1922
2127
  ...options,
1923
- params
2128
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1924
2129
  }
1925
2130
  );
1926
2131
  }
1927
2132
  };
1928
2133
  };
1929
2134
 
1930
- // src/api/storefront.ts
1931
- function groupCartToItems(cart) {
1932
- const groups = /* @__PURE__ */ new Map();
1933
- for (const slot of cart) {
1934
- const key = `${slot.serviceId}:${slot.providerId}`;
1935
- if (!groups.has(key)) {
1936
- groups.set(key, {
1937
- serviceId: slot.serviceId,
1938
- providerId: slot.providerId,
1939
- slots: []
1940
- });
1941
- }
1942
- groups.get(key).slots.push({ from: slot.from, to: slot.to });
1943
- }
1944
- return [...groups.values()];
1945
- }
1946
- var createStorefrontApi = (apiConfig) => {
1947
- const base = (businessId = apiConfig.businessId) => `/v1/storefront/${businessId}`;
1948
- let cart = [];
2135
+ // src/api/emailTemplate.ts
2136
+ var createEmailTemplateApi = (apiConfig) => {
1949
2137
  return {
1950
- business: {
1951
- getBusiness(options) {
1952
- return apiConfig.httpClient.get(base(), options);
1953
- },
1954
- getIntegrationConfig(params, options) {
1955
- return apiConfig.httpClient.get(
1956
- `${base(params.businessId)}/integrations/config/${params.type}`,
1957
- options
1958
- );
1959
- },
1960
- location: {
1961
- getCountries(options) {
1962
- return apiConfig.httpClient.get(`/v1/platform/countries`, options);
1963
- },
1964
- getCountry(countryCode, options) {
1965
- return apiConfig.httpClient.get(
1966
- `/v1/platform/countries/${countryCode}`,
1967
- options
1968
- );
1969
- },
1970
- list(options) {
1971
- return apiConfig.httpClient.get(`${base()}/locations`, options);
1972
- },
1973
- get(id, options) {
1974
- return apiConfig.httpClient.get(`${base()}/locations/${id}`, options);
1975
- }
1976
- },
1977
- market: {
1978
- list(options) {
1979
- return apiConfig.httpClient.get(`${base()}/markets`, options);
1980
- },
1981
- get(id, options) {
1982
- return apiConfig.httpClient.get(`${base()}/markets/${id}`, options);
1983
- }
1984
- }
1985
- },
1986
- cms: {
1987
- node: {
1988
- async get(params, options) {
1989
- const businessId = params.businessId || apiConfig.businessId;
1990
- let identifier;
1991
- if (params.id) {
1992
- identifier = params.id;
1993
- } else if (params.slug) {
1994
- identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
1995
- } else if (params.key) {
1996
- identifier = `${businessId}:${params.key}`;
1997
- } else {
1998
- throw new Error("GetNodeParams requires id, slug, or key");
1999
- }
2000
- const response = await apiConfig.httpClient.get(
2001
- `${base(businessId)}/nodes/${identifier}`,
2002
- options
2003
- );
2004
- return {
2005
- ...response,
2006
- getBlock(key) {
2007
- return getBlockFromArray(response, key, apiConfig.locale);
2008
- },
2009
- getBlockValues(key) {
2010
- return getBlockObjectValues(response, key, apiConfig.locale);
2011
- },
2012
- getImage(key) {
2013
- const block = getBlockFromArray(response, key, apiConfig.locale);
2014
- return getImageUrl(block, true);
2015
- }
2016
- };
2017
- },
2018
- find(params, options) {
2019
- const { businessId, ...queryParams } = params;
2020
- return apiConfig.httpClient.get(`${base(businessId)}/nodes`, {
2021
- ...options,
2022
- params: queryParams
2023
- });
2024
- },
2025
- getChildren(params, options) {
2026
- const { id, businessId, ...queryParams } = params;
2027
- return apiConfig.httpClient.get(`${base(businessId)}/nodes/${id}/children`, {
2028
- ...options,
2029
- params: queryParams
2030
- });
2031
- }
2032
- },
2033
- form: {
2034
- get(params, options) {
2035
- const businessId = params.businessId || apiConfig.businessId;
2036
- let identifier;
2037
- if (params.id) {
2038
- identifier = params.id;
2039
- } else if (params.key) {
2040
- identifier = `${businessId}:${params.key}`;
2041
- } else {
2042
- throw new Error("GetFormParams requires id or key");
2043
- }
2044
- return apiConfig.httpClient.get(
2045
- `${base(businessId)}/forms/${identifier}`,
2046
- options
2047
- );
2048
- },
2049
- submit(params, options) {
2050
- const { businessId, formId, ...payload } = params;
2051
- const targetBusinessId = businessId || apiConfig.businessId;
2052
- return apiConfig.httpClient.post(
2053
- `${base(targetBusinessId)}/forms/${formId}/submissions`,
2054
- { ...payload, formId, businessId: targetBusinessId },
2055
- options
2056
- );
2057
- }
2058
- },
2059
- taxonomy: {
2060
- get(params, options) {
2061
- const businessId = params.businessId || apiConfig.businessId;
2062
- let identifier;
2063
- if (params.id) {
2064
- identifier = params.id;
2065
- } else if (params.key) {
2066
- identifier = `${businessId}:${params.key}`;
2067
- } else {
2068
- throw new Error("GetTaxonomyParams requires id or key");
2069
- }
2070
- return apiConfig.httpClient.get(
2071
- `${base(businessId)}/taxonomies/${identifier}`,
2072
- options
2073
- );
2074
- },
2075
- getChildren(params, options) {
2076
- const businessId = params.businessId || apiConfig.businessId;
2077
- return apiConfig.httpClient.get(
2078
- `${base(businessId)}/taxonomies/${params.id}/children`,
2079
- options
2080
- );
2081
- }
2082
- }
2138
+ async createEmailTemplate(params, options) {
2139
+ const { businessId, ...payload } = params;
2140
+ const targetBusinessId = businessId || apiConfig.businessId;
2141
+ return apiConfig.httpClient.post(
2142
+ `/v1/businesses/${targetBusinessId}/email-templates`,
2143
+ payload,
2144
+ options
2145
+ );
2083
2146
  },
2084
- eshop: {
2085
- product: {
2086
- get(params, options) {
2087
- const businessId = params.businessId || apiConfig.businessId;
2088
- let identifier;
2089
- if (params.id) {
2090
- identifier = params.id;
2091
- } else if (params.slug) {
2092
- identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
2093
- } else {
2094
- throw new Error("GetProductParams requires id or slug");
2095
- }
2096
- return apiConfig.httpClient.get(
2097
- `${base(businessId)}/products/${identifier}`,
2098
- options
2099
- );
2100
- },
2101
- find(params, options) {
2102
- const { businessId, ...queryParams } = params;
2103
- return apiConfig.httpClient.get(`${base(businessId)}/products`, {
2104
- ...options,
2105
- params: queryParams
2106
- });
2107
- }
2108
- },
2109
- order: {
2110
- getQuote(params, options) {
2111
- const businessId = params.businessId || apiConfig.businessId;
2112
- const { location, businessId: _businessId, ...rest } = params;
2113
- const shippingAddress = location ? {
2114
- country: location.country || "",
2115
- state: location.state || "",
2116
- city: location.city || "",
2117
- postalCode: location.postalCode || "",
2118
- name: "",
2119
- street1: "",
2120
- street2: null
2121
- } : void 0;
2122
- return apiConfig.httpClient.post(
2123
- `${base(businessId)}/orders/quote`,
2124
- { ...rest, shippingAddress, market: apiConfig.market },
2125
- options
2126
- );
2127
- },
2128
- checkout(params, options) {
2129
- const businessId = params.businessId || apiConfig.businessId;
2130
- return apiConfig.httpClient.post(
2131
- `${base(businessId)}/orders/checkout`,
2132
- { ...params, businessId, market: apiConfig.market },
2133
- options
2134
- );
2135
- },
2136
- get(params, options) {
2137
- const businessId = params.businessId || apiConfig.businessId;
2138
- return apiConfig.httpClient.get(
2139
- `${base(businessId)}/orders/${params.id}`,
2140
- options
2141
- );
2142
- },
2143
- find(params, options) {
2144
- const { businessId, ...queryParams } = params;
2145
- return apiConfig.httpClient.get(`${base(businessId)}/orders`, {
2146
- ...options,
2147
- params: queryParams
2148
- });
2147
+ async updateEmailTemplate(params, options) {
2148
+ const { businessId, ...payload } = params;
2149
+ const targetBusinessId = businessId || apiConfig.businessId;
2150
+ return apiConfig.httpClient.put(
2151
+ `/v1/businesses/${targetBusinessId}/email-templates/${params.id}`,
2152
+ payload,
2153
+ options
2154
+ );
2155
+ },
2156
+ async deleteEmailTemplate(params, options) {
2157
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2158
+ return apiConfig.httpClient.delete(
2159
+ `/v1/businesses/${targetBusinessId}/email-templates/${params.id}`,
2160
+ options
2161
+ );
2162
+ },
2163
+ async getEmailTemplate(params, options) {
2164
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2165
+ let identifier;
2166
+ if (params.id) {
2167
+ identifier = params.id;
2168
+ } else if (params.key) {
2169
+ identifier = `${targetBusinessId}:${params.key}`;
2170
+ } else {
2171
+ throw new Error("GetEmailTemplateParams requires id or key");
2172
+ }
2173
+ return apiConfig.httpClient.get(
2174
+ `/v1/businesses/${targetBusinessId}/email-templates/${identifier}`,
2175
+ options
2176
+ );
2177
+ },
2178
+ async getEmailTemplates(params, options) {
2179
+ const { businessId, ...queryParams } = params;
2180
+ const targetBusinessId = businessId || apiConfig.businessId;
2181
+ return apiConfig.httpClient.get(
2182
+ `/v1/businesses/${targetBusinessId}/email-templates`,
2183
+ {
2184
+ ...options,
2185
+ params: queryParams
2149
2186
  }
2187
+ );
2188
+ }
2189
+ };
2190
+ };
2191
+
2192
+ // src/api/form.ts
2193
+ var createFormApi = (apiConfig) => {
2194
+ return {
2195
+ async createForm(params, options) {
2196
+ const { businessId, ...payload } = params;
2197
+ const targetBusinessId = businessId || apiConfig.businessId;
2198
+ return apiConfig.httpClient.post(
2199
+ `/v1/businesses/${targetBusinessId}/forms`,
2200
+ payload,
2201
+ options
2202
+ );
2203
+ },
2204
+ async updateForm(params, options) {
2205
+ const { businessId, ...payload } = params;
2206
+ const targetBusinessId = businessId || apiConfig.businessId;
2207
+ return apiConfig.httpClient.put(
2208
+ `/v1/businesses/${targetBusinessId}/forms/${params.id}`,
2209
+ payload,
2210
+ options
2211
+ );
2212
+ },
2213
+ async deleteForm(params, options) {
2214
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2215
+ return apiConfig.httpClient.delete(
2216
+ `/v1/businesses/${targetBusinessId}/forms/${params.id}`,
2217
+ options
2218
+ );
2219
+ },
2220
+ async getForm(params, options) {
2221
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2222
+ let identifier;
2223
+ if (params.id) {
2224
+ identifier = params.id;
2225
+ } else if (params.key) {
2226
+ identifier = `${targetBusinessId}:${params.key}`;
2227
+ } else {
2228
+ throw new Error("GetFormParams requires id or key");
2150
2229
  }
2230
+ return apiConfig.httpClient.get(
2231
+ `/v1/businesses/${targetBusinessId}/forms/${identifier}`,
2232
+ options
2233
+ );
2151
2234
  },
2152
- booking: {
2153
- addToCart(slot) {
2154
- cart.push(slot);
2155
- },
2156
- removeFromCart(slotId) {
2157
- cart = cart.filter((slot) => slot.id !== slotId);
2158
- },
2159
- getCart() {
2160
- return [...cart];
2161
- },
2162
- clearCart() {
2163
- cart = [];
2164
- },
2165
- checkout(params, options) {
2166
- const { businessId, items: paramItems, ...payload } = params || {};
2167
- const targetBusinessId = businessId || apiConfig.businessId;
2168
- const items = paramItems || groupCartToItems(cart);
2169
- return apiConfig.httpClient.post(
2170
- `${base(targetBusinessId)}/bookings/checkout`,
2171
- { market: "booking", ...payload, items },
2172
- options
2173
- );
2174
- },
2175
- get(params, options) {
2176
- const businessId = params.businessId || apiConfig.businessId;
2177
- return apiConfig.httpClient.get(
2178
- `${base(businessId)}/bookings/${params.id}`,
2179
- options
2180
- );
2181
- },
2182
- find(params, options) {
2183
- const { businessId, ...queryParams } = params;
2184
- return apiConfig.httpClient.get(`${base(businessId)}/bookings`, {
2235
+ async getForms(params, options) {
2236
+ const { businessId, ...queryParams } = params;
2237
+ const targetBusinessId = businessId || apiConfig.businessId;
2238
+ return apiConfig.httpClient.get(
2239
+ `/v1/businesses/${targetBusinessId}/forms`,
2240
+ {
2185
2241
  ...options,
2186
2242
  params: queryParams
2187
- });
2188
- },
2189
- getQuote(params, options) {
2190
- const { businessId, ...payload } = params;
2191
- return apiConfig.httpClient.post(
2192
- `${base(businessId)}/bookings/quote`,
2193
- { market: "booking", ...payload },
2194
- options
2195
- );
2196
- },
2197
- getAvailability(params, options) {
2198
- const { businessId, ...queryParams } = params;
2199
- return apiConfig.httpClient.get(
2200
- `${base(businessId)}/bookings/availability`,
2201
- { ...options, params: queryParams }
2202
- );
2203
- },
2204
- cancelItem(params, options) {
2205
- const { businessId, bookingId, itemId, ...payload } = params;
2206
- return apiConfig.httpClient.post(
2207
- `${base(businessId)}/bookings/${bookingId}/items/${itemId}/cancel`,
2208
- payload,
2209
- options
2210
- );
2211
- },
2212
- service: {
2213
- get(params, options) {
2214
- const businessId = params.businessId || apiConfig.businessId;
2215
- let identifier;
2216
- if (params.id) {
2217
- identifier = params.id;
2218
- } else if (params.slug) {
2219
- identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
2220
- } else {
2221
- throw new Error("GetServiceParams requires id or slug");
2222
- }
2223
- return apiConfig.httpClient.get(
2224
- `${base(businessId)}/services/${identifier}`,
2225
- options
2226
- );
2227
- },
2228
- find(params, options) {
2229
- const { businessId, ...queryParams } = params;
2230
- return apiConfig.httpClient.get(`${base(businessId)}/services`, {
2231
- ...options,
2232
- params: queryParams
2233
- });
2234
- },
2235
- findProviders(params, options) {
2236
- const { businessId, ...queryParams } = params;
2237
- return apiConfig.httpClient.get(`${base(businessId)}/service-providers`, {
2238
- ...options,
2239
- params: queryParams
2240
- });
2241
2243
  }
2242
- },
2243
- provider: {
2244
- get(params, options) {
2245
- const businessId = params.businessId || apiConfig.businessId;
2246
- let identifier;
2247
- if (params.id) {
2248
- identifier = params.id;
2249
- } else if (params.slug) {
2250
- identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
2251
- } else {
2252
- throw new Error("GetProviderParams requires id or slug");
2253
- }
2254
- return apiConfig.httpClient.get(
2255
- `${base(businessId)}/providers/${identifier}`,
2256
- options
2257
- );
2258
- },
2259
- find(params, options) {
2260
- const { businessId, ...queryParams } = params;
2261
- return apiConfig.httpClient.get(`${base(businessId)}/providers`, {
2262
- ...options,
2263
- params: queryParams
2264
- });
2244
+ );
2245
+ },
2246
+ async submit(params, options) {
2247
+ const { businessId, formId, ...payload } = params;
2248
+ const targetBusinessId = businessId || apiConfig.businessId;
2249
+ return apiConfig.httpClient.post(
2250
+ `/v1/businesses/${targetBusinessId}/forms/${formId}/submissions`,
2251
+ { ...payload, formId, businessId: targetBusinessId },
2252
+ options
2253
+ );
2254
+ },
2255
+ async getSubmissions(params, options) {
2256
+ const { businessId, formId, ...queryParams } = params;
2257
+ const targetBusinessId = businessId || apiConfig.businessId;
2258
+ return apiConfig.httpClient.get(
2259
+ `/v1/businesses/${targetBusinessId}/forms/${formId}/submissions`,
2260
+ {
2261
+ ...options,
2262
+ params: { ...queryParams, formId, businessId: targetBusinessId }
2265
2263
  }
2264
+ );
2265
+ },
2266
+ async getSubmission(params, options) {
2267
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2268
+ return apiConfig.httpClient.get(
2269
+ `/v1/businesses/${targetBusinessId}/forms/${params.formId}/submissions/${params.id}`,
2270
+ options
2271
+ );
2272
+ },
2273
+ async updateSubmission(params, options) {
2274
+ const { businessId, formId, id, ...payload } = params;
2275
+ const targetBusinessId = businessId || apiConfig.businessId;
2276
+ return apiConfig.httpClient.put(
2277
+ `/v1/businesses/${targetBusinessId}/forms/${formId}/submissions/${id}`,
2278
+ { ...payload, formId, businessId: targetBusinessId, id },
2279
+ options
2280
+ );
2281
+ }
2282
+ };
2283
+ };
2284
+
2285
+ // src/api/taxonomy.ts
2286
+ var createTaxonomyApi = (apiConfig) => {
2287
+ return {
2288
+ async createTaxonomy(params, options) {
2289
+ const { businessId, ...payload } = params;
2290
+ const targetBusinessId = businessId || apiConfig.businessId;
2291
+ return apiConfig.httpClient.post(
2292
+ `/v1/businesses/${targetBusinessId}/taxonomies`,
2293
+ payload,
2294
+ options
2295
+ );
2296
+ },
2297
+ async updateTaxonomy(params, options) {
2298
+ const { businessId, ...payload } = params;
2299
+ const targetBusinessId = businessId || apiConfig.businessId;
2300
+ return apiConfig.httpClient.put(
2301
+ `/v1/businesses/${targetBusinessId}/taxonomies/${params.id}`,
2302
+ payload,
2303
+ options
2304
+ );
2305
+ },
2306
+ async deleteTaxonomy(params, options) {
2307
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2308
+ return apiConfig.httpClient.delete(
2309
+ `/v1/businesses/${targetBusinessId}/taxonomies/${params.id}`,
2310
+ options
2311
+ );
2312
+ },
2313
+ async getTaxonomy(params, options) {
2314
+ const targetBusinessId = params.businessId || apiConfig.businessId;
2315
+ let identifier;
2316
+ if (params.id) {
2317
+ identifier = params.id;
2318
+ } else if (params.key) {
2319
+ identifier = `${targetBusinessId}:${params.key}`;
2320
+ } else {
2321
+ throw new Error("GetTaxonomyParams requires id or key");
2266
2322
  }
2323
+ return apiConfig.httpClient.get(
2324
+ `/v1/businesses/${targetBusinessId}/taxonomies/${identifier}`,
2325
+ options
2326
+ );
2267
2327
  },
2268
- crm: {
2269
- customer: {
2270
- initialize(params, options) {
2271
- const businessId = params?.businessId || apiConfig.businessId;
2272
- return apiConfig.httpClient.post(
2273
- `${base(businessId)}/customers/initialize`,
2274
- { businessId },
2275
- options
2276
- );
2277
- },
2278
- signInAnonymously(params, options) {
2279
- const businessId = params?.businessId || apiConfig.businessId;
2280
- return apiConfig.httpClient.post(
2281
- `${base(businessId)}/customers/initialize`,
2282
- { businessId },
2283
- options
2284
- );
2285
- },
2286
- connect(params, options) {
2287
- const businessId = params.businessId || apiConfig.businessId;
2288
- return apiConfig.httpClient.post(
2289
- `${base(businessId)}/customers/connect`,
2290
- { email: params.email, businessId },
2291
- options
2292
- );
2293
- },
2294
- requestCode(params, options) {
2295
- const businessId = params.businessId || apiConfig.businessId;
2296
- return apiConfig.httpClient.post(
2297
- `${base(businessId)}/customers/auth/code`,
2298
- { email: params.email, businessId },
2299
- options
2300
- );
2301
- },
2302
- verify(params, options) {
2303
- const businessId = params.businessId || apiConfig.businessId;
2304
- return apiConfig.httpClient.post(
2305
- `${base(businessId)}/customers/auth/verify`,
2306
- { email: params.email, code: params.code, businessId },
2307
- options
2308
- );
2309
- },
2310
- refreshToken(params, options) {
2311
- const businessId = params.businessId || apiConfig.businessId;
2312
- return apiConfig.httpClient.post(
2313
- `${base(businessId)}/customers/auth/refresh`,
2314
- { refreshToken: params.refreshToken },
2315
- options
2316
- );
2317
- },
2318
- getMe(options) {
2319
- return apiConfig.httpClient.get(`${base()}/customers/me`, options);
2320
- }
2321
- },
2322
- audience: {
2323
- get(params, options) {
2324
- let identifier;
2325
- if (params.id) {
2326
- identifier = params.id;
2327
- } else if (params.key) {
2328
- identifier = `${apiConfig.businessId}:${params.key}`;
2329
- } else {
2330
- throw new Error("GetAudienceParams requires id or key");
2331
- }
2332
- return apiConfig.httpClient.get(
2333
- `${base(apiConfig.businessId)}/audiences/${identifier}`,
2334
- options
2335
- );
2336
- },
2337
- find(params, options) {
2338
- return apiConfig.httpClient.get(`${base()}/audiences`, {
2339
- ...options,
2340
- params
2341
- });
2342
- },
2343
- subscribe(params, options) {
2344
- return apiConfig.httpClient.post(
2345
- `${base()}/audiences/${params.id}/subscribe`,
2346
- {
2347
- customerId: params.customerId,
2348
- priceId: params.priceId,
2349
- successUrl: params.successUrl,
2350
- cancelUrl: params.cancelUrl,
2351
- confirmUrl: params.confirmUrl
2352
- },
2353
- options
2354
- );
2355
- },
2356
- checkAccess(params, options) {
2357
- return apiConfig.httpClient.get(
2358
- `${base()}/audiences/${params.id}/access`,
2359
- options
2360
- );
2361
- },
2362
- unsubscribe(token, options) {
2363
- return apiConfig.httpClient.get(`${base()}/audiences/unsubscribe`, {
2364
- ...options,
2365
- params: { token }
2366
- });
2367
- },
2368
- confirm(token, options) {
2369
- return apiConfig.httpClient.get(`${base()}/audiences/confirm`, {
2370
- ...options,
2371
- params: { token }
2372
- });
2328
+ async getTaxonomies(params, options) {
2329
+ const { businessId, ...queryParams } = params;
2330
+ const targetBusinessId = businessId || apiConfig.businessId;
2331
+ return apiConfig.httpClient.get(
2332
+ `/v1/businesses/${targetBusinessId}/taxonomies`,
2333
+ {
2334
+ ...options,
2335
+ params: queryParams
2373
2336
  }
2374
- },
2375
- reaction: {
2376
- DEFAULT_REACTION_KINDS,
2377
- isValidReactionKind,
2378
- computeAverageStars,
2379
- create(params, options) {
2380
- const businessId = params.businessId || apiConfig.businessId;
2381
- return apiConfig.httpClient.post(
2382
- `${base(businessId)}/reactions`,
2383
- {
2384
- businessId,
2385
- target: params.target,
2386
- kind: params.kind,
2387
- blocks: params.blocks || [],
2388
- parentId: params.parentId,
2389
- taxonomies: params.taxonomies || []
2390
- },
2391
- options
2392
- );
2393
- },
2394
- get(params, options) {
2395
- const businessId = params.businessId || apiConfig.businessId;
2396
- return apiConfig.httpClient.get(
2397
- `${base(businessId)}/reactions/${params.id}`,
2398
- options
2399
- );
2400
- },
2401
- find(params, options) {
2402
- const businessId = params?.businessId || apiConfig.businessId;
2403
- const queryParams = { ...params || {} };
2404
- delete queryParams.businessId;
2405
- return apiConfig.httpClient.get(`${base(businessId)}/reactions`, {
2406
- ...options,
2407
- params: queryParams
2408
- });
2409
- },
2410
- update(params, options) {
2411
- const businessId = params.businessId || apiConfig.businessId;
2412
- return apiConfig.httpClient.put(
2413
- `${base(businessId)}/reactions/${params.id}`,
2414
- {
2415
- id: params.id,
2416
- businessId,
2417
- blocks: params.blocks,
2418
- taxonomies: params.taxonomies
2419
- },
2420
- options
2421
- );
2422
- },
2423
- remove(params, options) {
2424
- const businessId = params.businessId || apiConfig.businessId;
2425
- return apiConfig.httpClient.delete(
2426
- `${base(businessId)}/reactions/${params.id}`,
2427
- options
2428
- );
2429
- },
2430
- summary(params, options) {
2431
- const businessId = params.businessId || apiConfig.businessId;
2432
- return apiConfig.httpClient.get(`${base(businessId)}/reactions/summary`, {
2433
- ...options,
2434
- params: {
2435
- businessId,
2436
- targetType: params.targetType,
2437
- targetId: params.targetId,
2438
- parentId: params.parentId
2439
- }
2440
- });
2337
+ );
2338
+ },
2339
+ async getTaxonomyChildren(params, options) {
2340
+ const { id, businessId } = params;
2341
+ const targetBusinessId = businessId || apiConfig.businessId;
2342
+ return apiConfig.httpClient.get(
2343
+ `/v1/businesses/${targetBusinessId}/taxonomies/${id}/children`,
2344
+ options
2345
+ );
2346
+ }
2347
+ };
2348
+ };
2349
+
2350
+ // src/api/analytics.ts
2351
+ var createAnalyticsApi = (apiConfig) => {
2352
+ return {
2353
+ async getSummary(params, options) {
2354
+ return apiConfig.httpClient.get(
2355
+ `/v1/businesses/${apiConfig.businessId}/analytics/summary`,
2356
+ {
2357
+ ...options,
2358
+ params: params || {}
2441
2359
  }
2442
- }
2360
+ );
2443
2361
  },
2444
- automation: {
2445
- agent: {
2446
- getAgents(params, options) {
2447
- const businessId = params?.businessId || apiConfig.businessId;
2448
- const queryParams = { ...params || {} };
2449
- delete queryParams.businessId;
2450
- return apiConfig.httpClient.get(`${base(businessId)}/agents`, {
2451
- ...options,
2452
- params: Object.keys(queryParams).length > 0 ? queryParams : void 0
2453
- });
2454
- },
2455
- getAgent(params, options) {
2456
- const businessId = params.businessId || apiConfig.businessId;
2457
- return apiConfig.httpClient.get(
2458
- `${base(businessId)}/agents/${params.id}`,
2459
- options
2460
- );
2461
- },
2462
- sendMessage(params, options) {
2463
- const businessId = params.businessId || apiConfig.businessId;
2464
- const body = { message: params.message };
2465
- if (params.chatId) body.chatId = params.chatId;
2466
- return apiConfig.httpClient.post(
2467
- `${base(businessId)}/agents/${params.id}/chats/messages`,
2468
- body,
2469
- options
2470
- );
2471
- },
2472
- getChat(params, options) {
2473
- const businessId = params.businessId || apiConfig.businessId;
2474
- return apiConfig.httpClient.get(
2475
- `${base(businessId)}/agents/${params.id}/chats/${params.chatId}`,
2476
- options
2477
- );
2478
- },
2479
- getChatMessages(params, options) {
2480
- const businessId = params.businessId || apiConfig.businessId;
2481
- const queryParams = {};
2482
- if (params.limit) queryParams.limit = String(params.limit);
2483
- return apiConfig.httpClient.get(
2484
- `${base(businessId)}/agents/${params.id}/chats/${params.chatId}/messages`,
2485
- {
2486
- ...options,
2487
- params: Object.keys(queryParams).length > 0 ? queryParams : void 0
2488
- }
2489
- );
2490
- },
2491
- rateChat(params, options) {
2492
- const businessId = params.businessId || apiConfig.businessId;
2493
- const body = { rating: params.rating };
2494
- if (params.comment) body.comment = params.comment;
2495
- return apiConfig.httpClient.post(
2496
- `${base(businessId)}/agents/${params.id}/chats/${params.chatId}/rate`,
2497
- body,
2498
- options
2499
- );
2362
+ async getStatusBreakdown(params, options) {
2363
+ return apiConfig.httpClient.get(
2364
+ `/v1/businesses/${apiConfig.businessId}/analytics/status`,
2365
+ {
2366
+ ...options,
2367
+ params
2500
2368
  }
2501
- }
2369
+ );
2502
2370
  }
2503
2371
  };
2504
2372
  };
@@ -2773,7 +2641,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
2773
2641
  }
2774
2642
 
2775
2643
  // src/index.ts
2776
- var SDK_VERSION = "0.7.72";
2644
+ var SDK_VERSION = "0.7.74";
2777
2645
  var SUPPORTED_FRAMEWORKS = [
2778
2646
  "astro",
2779
2647
  "react",
@@ -2856,7 +2724,6 @@ async function createAdmin(config) {
2856
2724
  const eshopApi = createEshopApi(apiConfig);
2857
2725
  const bookingApi = createBookingApi(apiConfig);
2858
2726
  const crmApi = createCustomerApi(apiConfig);
2859
- const reactionApi = createReactionApi(apiConfig);
2860
2727
  const locationApi = createLocationApi(apiConfig);
2861
2728
  const marketApi = createMarketApi(apiConfig);
2862
2729
  const agentApi = createAgentApi(apiConfig);
@@ -2982,7 +2849,7 @@ async function createAdmin(config) {
2982
2849
  addSubscriber: crmApi.audiences.addSubscriber,
2983
2850
  removeSubscriber: crmApi.audiences.removeSubscriber
2984
2851
  },
2985
- reaction: reactionApi
2852
+ activity: crmApi.activity
2986
2853
  },
2987
2854
  automation: {
2988
2855
  agent: {
@@ -3095,6 +2962,7 @@ async function createStorefront(config) {
3095
2962
  eshop: storefrontApi.eshop,
3096
2963
  booking: storefrontApi.booking,
3097
2964
  crm: storefrontApi.crm,
2965
+ activity: storefrontApi.activity,
3098
2966
  automation: storefrontApi.automation,
3099
2967
  analytics: {
3100
2968
  track
@@ -3119,14 +2987,11 @@ async function createStorefront(config) {
3119
2987
  };
3120
2988
  }
3121
2989
 
3122
- exports.DEFAULT_REACTION_KINDS = DEFAULT_REACTION_KINDS;
2990
+ exports.COMMON_ACTIVITY_TYPES = COMMON_ACTIVITY_TYPES;
3123
2991
  exports.PaymentMethodType = PaymentMethodType;
3124
- exports.REACTION_KIND_REGEX = REACTION_KIND_REGEX;
3125
2992
  exports.SDK_VERSION = SDK_VERSION;
3126
2993
  exports.SUPPORTED_FRAMEWORKS = SUPPORTED_FRAMEWORKS;
3127
- exports.computeAverageStars = computeAverageStars;
3128
2994
  exports.createAdmin = createAdmin;
3129
2995
  exports.createStorefront = createStorefront;
3130
- exports.isValidReactionKind = isValidReactionKind;
3131
2996
  //# sourceMappingURL=index.cjs.map
3132
2997
  //# sourceMappingURL=index.cjs.map