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