arky-sdk 0.7.72 → 0.7.74
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 +1079 -1215
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -107
- package/dist/index.d.ts +59 -107
- package/dist/index.js +1079 -1212
- package/dist/index.js.map +1 -1
- package/dist/types.d.cts +0 -1
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,143 +5,822 @@ var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
|
|
|
5
5
|
return PaymentMethodType2;
|
|
6
6
|
})(PaymentMethodType || {});
|
|
7
7
|
|
|
8
|
-
// src/utils/
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
return
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
110
|
-
setToken(data);
|
|
111
|
-
})().finally(() => {
|
|
112
|
-
refreshPromise = null;
|
|
77
|
+
return parsed;
|
|
113
78
|
});
|
|
114
|
-
return refreshPromise;
|
|
115
79
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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}/customer/initialize`,
|
|
159
|
+
{
|
|
160
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
|
|
134
161
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
162
|
+
);
|
|
163
|
+
const accessToken = response?.tokens?.accessToken;
|
|
164
|
+
const refreshToken = response?.tokens?.refreshToken;
|
|
165
|
+
if (accessToken) {
|
|
166
|
+
apiConfig.setToken?.({ accessToken, refreshToken });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
var createActivityApi = (apiConfig) => ({
|
|
170
|
+
COMMON_ACTIVITY_TYPES,
|
|
171
|
+
async track(params) {
|
|
172
|
+
await ensureCustomer(apiConfig);
|
|
173
|
+
await apiConfig.httpClient.post(
|
|
174
|
+
`/v1/storefront/${apiConfig.businessId}/activities/track`,
|
|
175
|
+
{ type: params.type, payload: params.payload }
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
function groupCartToItems(cart) {
|
|
180
|
+
const groups = /* @__PURE__ */ new Map();
|
|
181
|
+
for (const slot of cart) {
|
|
182
|
+
const key = `${slot.serviceId}:${slot.providerId}`;
|
|
183
|
+
if (!groups.has(key)) {
|
|
184
|
+
groups.set(key, {
|
|
185
|
+
serviceId: slot.serviceId,
|
|
186
|
+
providerId: slot.providerId,
|
|
187
|
+
slots: []
|
|
188
|
+
});
|
|
139
189
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
190
|
+
groups.get(key).slots.push({ from: slot.from, to: slot.to });
|
|
191
|
+
}
|
|
192
|
+
return [...groups.values()];
|
|
193
|
+
}
|
|
194
|
+
var createStorefrontApi = (apiConfig) => {
|
|
195
|
+
const base = (businessId = apiConfig.businessId) => `/v1/storefront/${businessId}`;
|
|
196
|
+
let cart = [];
|
|
197
|
+
return {
|
|
198
|
+
business: {
|
|
199
|
+
getBusiness(options) {
|
|
200
|
+
return apiConfig.httpClient.get(base(), options);
|
|
201
|
+
},
|
|
202
|
+
getIntegrationConfig(params, options) {
|
|
203
|
+
return apiConfig.httpClient.get(
|
|
204
|
+
`${base(params.businessId)}/integrations/config/${params.type}`,
|
|
205
|
+
options
|
|
206
|
+
);
|
|
207
|
+
},
|
|
208
|
+
location: {
|
|
209
|
+
getCountries(options) {
|
|
210
|
+
return apiConfig.httpClient.get(`/v1/platform/countries`, options);
|
|
211
|
+
},
|
|
212
|
+
getCountry(countryCode, options) {
|
|
213
|
+
return apiConfig.httpClient.get(
|
|
214
|
+
`/v1/platform/countries/${countryCode}`,
|
|
215
|
+
options
|
|
216
|
+
);
|
|
217
|
+
},
|
|
218
|
+
list(options) {
|
|
219
|
+
return apiConfig.httpClient.get(`${base()}/locations`, options);
|
|
220
|
+
},
|
|
221
|
+
get(id, options) {
|
|
222
|
+
return apiConfig.httpClient.get(`${base()}/locations/${id}`, options);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
market: {
|
|
226
|
+
list(options) {
|
|
227
|
+
return apiConfig.httpClient.get(`${base()}/markets`, options);
|
|
228
|
+
},
|
|
229
|
+
get(id, options) {
|
|
230
|
+
return apiConfig.httpClient.get(`${base()}/markets/${id}`, options);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
cms: {
|
|
235
|
+
node: {
|
|
236
|
+
async get(params, options) {
|
|
237
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
238
|
+
let identifier;
|
|
239
|
+
if (params.id) {
|
|
240
|
+
identifier = params.id;
|
|
241
|
+
} else if (params.slug) {
|
|
242
|
+
identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
|
|
243
|
+
} else if (params.key) {
|
|
244
|
+
identifier = `${businessId}:${params.key}`;
|
|
245
|
+
} else {
|
|
246
|
+
throw new Error("GetNodeParams requires id, slug, or key");
|
|
247
|
+
}
|
|
248
|
+
const response = await apiConfig.httpClient.get(
|
|
249
|
+
`${base(businessId)}/nodes/${identifier}`,
|
|
250
|
+
options
|
|
251
|
+
);
|
|
252
|
+
return {
|
|
253
|
+
...response,
|
|
254
|
+
getBlock(key) {
|
|
255
|
+
return getBlockFromArray(response, key, apiConfig.locale);
|
|
256
|
+
},
|
|
257
|
+
getBlockValues(key) {
|
|
258
|
+
return getBlockObjectValues(response, key, apiConfig.locale);
|
|
259
|
+
},
|
|
260
|
+
getImage(key) {
|
|
261
|
+
const block = getBlockFromArray(response, key, apiConfig.locale);
|
|
262
|
+
return getImageUrl(block, true);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
find(params, options) {
|
|
267
|
+
const { businessId, ...queryParams } = params;
|
|
268
|
+
return apiConfig.httpClient.get(`${base(businessId)}/nodes`, {
|
|
269
|
+
...options,
|
|
270
|
+
params: queryParams
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
getChildren(params, options) {
|
|
274
|
+
const { id, businessId, ...queryParams } = params;
|
|
275
|
+
return apiConfig.httpClient.get(`${base(businessId)}/nodes/${id}/children`, {
|
|
276
|
+
...options,
|
|
277
|
+
params: queryParams
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
form: {
|
|
282
|
+
get(params, options) {
|
|
283
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
284
|
+
let identifier;
|
|
285
|
+
if (params.id) {
|
|
286
|
+
identifier = params.id;
|
|
287
|
+
} else if (params.key) {
|
|
288
|
+
identifier = `${businessId}:${params.key}`;
|
|
289
|
+
} else {
|
|
290
|
+
throw new Error("GetFormParams requires id or key");
|
|
291
|
+
}
|
|
292
|
+
return apiConfig.httpClient.get(
|
|
293
|
+
`${base(businessId)}/forms/${identifier}`,
|
|
294
|
+
options
|
|
295
|
+
);
|
|
296
|
+
},
|
|
297
|
+
submit(params, options) {
|
|
298
|
+
const { businessId, formId, ...payload } = params;
|
|
299
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
300
|
+
return apiConfig.httpClient.post(
|
|
301
|
+
`${base(targetBusinessId)}/forms/${formId}/submissions`,
|
|
302
|
+
{ ...payload, formId, businessId: targetBusinessId },
|
|
303
|
+
options
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
taxonomy: {
|
|
308
|
+
get(params, options) {
|
|
309
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
310
|
+
let identifier;
|
|
311
|
+
if (params.id) {
|
|
312
|
+
identifier = params.id;
|
|
313
|
+
} else if (params.key) {
|
|
314
|
+
identifier = `${businessId}:${params.key}`;
|
|
315
|
+
} else {
|
|
316
|
+
throw new Error("GetTaxonomyParams requires id or key");
|
|
317
|
+
}
|
|
318
|
+
return apiConfig.httpClient.get(
|
|
319
|
+
`${base(businessId)}/taxonomies/${identifier}`,
|
|
320
|
+
options
|
|
321
|
+
);
|
|
322
|
+
},
|
|
323
|
+
getChildren(params, options) {
|
|
324
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
325
|
+
return apiConfig.httpClient.get(
|
|
326
|
+
`${base(businessId)}/taxonomies/${params.id}/children`,
|
|
327
|
+
options
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
eshop: {
|
|
333
|
+
product: {
|
|
334
|
+
get(params, options) {
|
|
335
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
336
|
+
let identifier;
|
|
337
|
+
if (params.id) {
|
|
338
|
+
identifier = params.id;
|
|
339
|
+
} else if (params.slug) {
|
|
340
|
+
identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
|
|
341
|
+
} else {
|
|
342
|
+
throw new Error("GetProductParams requires id or slug");
|
|
343
|
+
}
|
|
344
|
+
return apiConfig.httpClient.get(
|
|
345
|
+
`${base(businessId)}/products/${identifier}`,
|
|
346
|
+
options
|
|
347
|
+
);
|
|
348
|
+
},
|
|
349
|
+
find(params, options) {
|
|
350
|
+
const { businessId, ...queryParams } = params;
|
|
351
|
+
return apiConfig.httpClient.get(`${base(businessId)}/products`, {
|
|
352
|
+
...options,
|
|
353
|
+
params: queryParams
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
order: {
|
|
358
|
+
getQuote(params, options) {
|
|
359
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
360
|
+
const { location, businessId: _businessId, ...rest } = params;
|
|
361
|
+
const shippingAddress = location ? {
|
|
362
|
+
country: location.country || "",
|
|
363
|
+
state: location.state || "",
|
|
364
|
+
city: location.city || "",
|
|
365
|
+
postalCode: location.postalCode || "",
|
|
366
|
+
name: "",
|
|
367
|
+
street1: "",
|
|
368
|
+
street2: null
|
|
369
|
+
} : void 0;
|
|
370
|
+
return apiConfig.httpClient.post(
|
|
371
|
+
`${base(businessId)}/orders/quote`,
|
|
372
|
+
{ ...rest, shippingAddress, market: apiConfig.market },
|
|
373
|
+
options
|
|
374
|
+
);
|
|
375
|
+
},
|
|
376
|
+
checkout(params, options) {
|
|
377
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
378
|
+
return apiConfig.httpClient.post(
|
|
379
|
+
`${base(businessId)}/orders/checkout`,
|
|
380
|
+
{ ...params, businessId, market: apiConfig.market },
|
|
381
|
+
options
|
|
382
|
+
);
|
|
383
|
+
},
|
|
384
|
+
get(params, options) {
|
|
385
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
386
|
+
return apiConfig.httpClient.get(
|
|
387
|
+
`${base(businessId)}/orders/${params.id}`,
|
|
388
|
+
options
|
|
389
|
+
);
|
|
390
|
+
},
|
|
391
|
+
find(params, options) {
|
|
392
|
+
const { businessId, ...queryParams } = params;
|
|
393
|
+
return apiConfig.httpClient.get(`${base(businessId)}/orders`, {
|
|
394
|
+
...options,
|
|
395
|
+
params: queryParams
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
booking: {
|
|
401
|
+
addToCart(slot) {
|
|
402
|
+
cart.push(slot);
|
|
403
|
+
},
|
|
404
|
+
removeFromCart(slotId) {
|
|
405
|
+
cart = cart.filter((slot) => slot.id !== slotId);
|
|
406
|
+
},
|
|
407
|
+
getCart() {
|
|
408
|
+
return [...cart];
|
|
409
|
+
},
|
|
410
|
+
clearCart() {
|
|
411
|
+
cart = [];
|
|
412
|
+
},
|
|
413
|
+
checkout(params, options) {
|
|
414
|
+
const { businessId, items: paramItems, ...payload } = params || {};
|
|
415
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
416
|
+
const items = paramItems || groupCartToItems(cart);
|
|
417
|
+
return apiConfig.httpClient.post(
|
|
418
|
+
`${base(targetBusinessId)}/bookings/checkout`,
|
|
419
|
+
{ market: "booking", ...payload, items },
|
|
420
|
+
options
|
|
421
|
+
);
|
|
422
|
+
},
|
|
423
|
+
get(params, options) {
|
|
424
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
425
|
+
return apiConfig.httpClient.get(
|
|
426
|
+
`${base(businessId)}/bookings/${params.id}`,
|
|
427
|
+
options
|
|
428
|
+
);
|
|
429
|
+
},
|
|
430
|
+
find(params, options) {
|
|
431
|
+
const { businessId, ...queryParams } = params;
|
|
432
|
+
return apiConfig.httpClient.get(`${base(businessId)}/bookings`, {
|
|
433
|
+
...options,
|
|
434
|
+
params: queryParams
|
|
435
|
+
});
|
|
436
|
+
},
|
|
437
|
+
getQuote(params, options) {
|
|
438
|
+
const { businessId, ...payload } = params;
|
|
439
|
+
return apiConfig.httpClient.post(
|
|
440
|
+
`${base(businessId)}/bookings/quote`,
|
|
441
|
+
{ market: "booking", ...payload },
|
|
442
|
+
options
|
|
443
|
+
);
|
|
444
|
+
},
|
|
445
|
+
getAvailability(params, options) {
|
|
446
|
+
const { businessId, ...queryParams } = params;
|
|
447
|
+
return apiConfig.httpClient.get(
|
|
448
|
+
`${base(businessId)}/bookings/availability`,
|
|
449
|
+
{ ...options, params: queryParams }
|
|
450
|
+
);
|
|
451
|
+
},
|
|
452
|
+
cancelItem(params, options) {
|
|
453
|
+
const { businessId, bookingId, itemId, ...payload } = params;
|
|
454
|
+
return apiConfig.httpClient.post(
|
|
455
|
+
`${base(businessId)}/bookings/${bookingId}/items/${itemId}/cancel`,
|
|
456
|
+
payload,
|
|
457
|
+
options
|
|
458
|
+
);
|
|
459
|
+
},
|
|
460
|
+
service: {
|
|
461
|
+
get(params, options) {
|
|
462
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
463
|
+
let identifier;
|
|
464
|
+
if (params.id) {
|
|
465
|
+
identifier = params.id;
|
|
466
|
+
} else if (params.slug) {
|
|
467
|
+
identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
|
|
468
|
+
} else {
|
|
469
|
+
throw new Error("GetServiceParams requires id or slug");
|
|
470
|
+
}
|
|
471
|
+
return apiConfig.httpClient.get(
|
|
472
|
+
`${base(businessId)}/services/${identifier}`,
|
|
473
|
+
options
|
|
474
|
+
);
|
|
475
|
+
},
|
|
476
|
+
find(params, options) {
|
|
477
|
+
const { businessId, ...queryParams } = params;
|
|
478
|
+
return apiConfig.httpClient.get(`${base(businessId)}/services`, {
|
|
479
|
+
...options,
|
|
480
|
+
params: queryParams
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
findProviders(params, options) {
|
|
484
|
+
const { businessId, ...queryParams } = params;
|
|
485
|
+
return apiConfig.httpClient.get(`${base(businessId)}/service-providers`, {
|
|
486
|
+
...options,
|
|
487
|
+
params: queryParams
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
provider: {
|
|
492
|
+
get(params, options) {
|
|
493
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
494
|
+
let identifier;
|
|
495
|
+
if (params.id) {
|
|
496
|
+
identifier = params.id;
|
|
497
|
+
} else if (params.slug) {
|
|
498
|
+
identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
|
|
499
|
+
} else {
|
|
500
|
+
throw new Error("GetProviderParams requires id or slug");
|
|
501
|
+
}
|
|
502
|
+
return apiConfig.httpClient.get(
|
|
503
|
+
`${base(businessId)}/providers/${identifier}`,
|
|
504
|
+
options
|
|
505
|
+
);
|
|
506
|
+
},
|
|
507
|
+
find(params, options) {
|
|
508
|
+
const { businessId, ...queryParams } = params;
|
|
509
|
+
return apiConfig.httpClient.get(`${base(businessId)}/providers`, {
|
|
510
|
+
...options,
|
|
511
|
+
params: queryParams
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
crm: {
|
|
517
|
+
customer: {
|
|
518
|
+
initialize(params, options) {
|
|
519
|
+
const businessId = params?.businessId || apiConfig.businessId;
|
|
520
|
+
return apiConfig.httpClient.post(
|
|
521
|
+
`${base(businessId)}/customers/initialize`,
|
|
522
|
+
{ businessId },
|
|
523
|
+
options
|
|
524
|
+
);
|
|
525
|
+
},
|
|
526
|
+
signInAnonymously(params, options) {
|
|
527
|
+
const businessId = params?.businessId || apiConfig.businessId;
|
|
528
|
+
return apiConfig.httpClient.post(
|
|
529
|
+
`${base(businessId)}/customers/initialize`,
|
|
530
|
+
{ businessId },
|
|
531
|
+
options
|
|
532
|
+
);
|
|
533
|
+
},
|
|
534
|
+
connect(params, options) {
|
|
535
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
536
|
+
return apiConfig.httpClient.post(
|
|
537
|
+
`${base(businessId)}/customers/connect`,
|
|
538
|
+
{ email: params.email, businessId },
|
|
539
|
+
options
|
|
540
|
+
);
|
|
541
|
+
},
|
|
542
|
+
requestCode(params, options) {
|
|
543
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
544
|
+
return apiConfig.httpClient.post(
|
|
545
|
+
`${base(businessId)}/customers/auth/code`,
|
|
546
|
+
{ email: params.email, businessId },
|
|
547
|
+
options
|
|
548
|
+
);
|
|
549
|
+
},
|
|
550
|
+
verify(params, options) {
|
|
551
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
552
|
+
return apiConfig.httpClient.post(
|
|
553
|
+
`${base(businessId)}/customers/auth/verify`,
|
|
554
|
+
{ email: params.email, code: params.code, businessId },
|
|
555
|
+
options
|
|
556
|
+
);
|
|
557
|
+
},
|
|
558
|
+
refreshToken(params, options) {
|
|
559
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
560
|
+
return apiConfig.httpClient.post(
|
|
561
|
+
`${base(businessId)}/customers/auth/refresh`,
|
|
562
|
+
{ refreshToken: params.refreshToken },
|
|
563
|
+
options
|
|
564
|
+
);
|
|
565
|
+
},
|
|
566
|
+
getMe(options) {
|
|
567
|
+
return apiConfig.httpClient.get(`${base()}/customers/me`, options);
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
audience: {
|
|
571
|
+
get(params, options) {
|
|
572
|
+
let identifier;
|
|
573
|
+
if (params.id) {
|
|
574
|
+
identifier = params.id;
|
|
575
|
+
} else if (params.key) {
|
|
576
|
+
identifier = `${apiConfig.businessId}:${params.key}`;
|
|
577
|
+
} else {
|
|
578
|
+
throw new Error("GetAudienceParams requires id or key");
|
|
579
|
+
}
|
|
580
|
+
return apiConfig.httpClient.get(
|
|
581
|
+
`${base(apiConfig.businessId)}/audiences/${identifier}`,
|
|
582
|
+
options
|
|
583
|
+
);
|
|
584
|
+
},
|
|
585
|
+
find(params, options) {
|
|
586
|
+
return apiConfig.httpClient.get(`${base()}/audiences`, {
|
|
587
|
+
...options,
|
|
588
|
+
params
|
|
589
|
+
});
|
|
590
|
+
},
|
|
591
|
+
subscribe(params, options) {
|
|
592
|
+
return apiConfig.httpClient.post(
|
|
593
|
+
`${base()}/audiences/${params.id}/subscribe`,
|
|
594
|
+
{
|
|
595
|
+
customerId: params.customerId,
|
|
596
|
+
priceId: params.priceId,
|
|
597
|
+
successUrl: params.successUrl,
|
|
598
|
+
cancelUrl: params.cancelUrl,
|
|
599
|
+
confirmUrl: params.confirmUrl
|
|
600
|
+
},
|
|
601
|
+
options
|
|
602
|
+
);
|
|
603
|
+
},
|
|
604
|
+
checkAccess(params, options) {
|
|
605
|
+
return apiConfig.httpClient.get(
|
|
606
|
+
`${base()}/audiences/${params.id}/access`,
|
|
607
|
+
options
|
|
608
|
+
);
|
|
609
|
+
},
|
|
610
|
+
unsubscribe(token, options) {
|
|
611
|
+
return apiConfig.httpClient.get(`${base()}/audiences/unsubscribe`, {
|
|
612
|
+
...options,
|
|
613
|
+
params: { token }
|
|
614
|
+
});
|
|
615
|
+
},
|
|
616
|
+
confirm(token, options) {
|
|
617
|
+
return apiConfig.httpClient.get(`${base()}/audiences/confirm`, {
|
|
618
|
+
...options,
|
|
619
|
+
params: { token }
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
activity: createActivityApi(apiConfig),
|
|
625
|
+
automation: {
|
|
626
|
+
agent: {
|
|
627
|
+
getAgents(params, options) {
|
|
628
|
+
const businessId = params?.businessId || apiConfig.businessId;
|
|
629
|
+
const queryParams = { ...params || {} };
|
|
630
|
+
delete queryParams.businessId;
|
|
631
|
+
return apiConfig.httpClient.get(`${base(businessId)}/agents`, {
|
|
632
|
+
...options,
|
|
633
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
634
|
+
});
|
|
635
|
+
},
|
|
636
|
+
getAgent(params, options) {
|
|
637
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
638
|
+
return apiConfig.httpClient.get(
|
|
639
|
+
`${base(businessId)}/agents/${params.id}`,
|
|
640
|
+
options
|
|
641
|
+
);
|
|
642
|
+
},
|
|
643
|
+
sendMessage(params, options) {
|
|
644
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
645
|
+
const body = { message: params.message };
|
|
646
|
+
if (params.chatId) body.chatId = params.chatId;
|
|
647
|
+
return apiConfig.httpClient.post(
|
|
648
|
+
`${base(businessId)}/agents/${params.id}/chats/messages`,
|
|
649
|
+
body,
|
|
650
|
+
options
|
|
651
|
+
);
|
|
652
|
+
},
|
|
653
|
+
getChat(params, options) {
|
|
654
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
655
|
+
return apiConfig.httpClient.get(
|
|
656
|
+
`${base(businessId)}/agents/${params.id}/chats/${params.chatId}`,
|
|
657
|
+
options
|
|
658
|
+
);
|
|
659
|
+
},
|
|
660
|
+
getChatMessages(params, options) {
|
|
661
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
662
|
+
const queryParams = {};
|
|
663
|
+
if (params.limit) queryParams.limit = String(params.limit);
|
|
664
|
+
return apiConfig.httpClient.get(
|
|
665
|
+
`${base(businessId)}/agents/${params.id}/chats/${params.chatId}/messages`,
|
|
666
|
+
{
|
|
667
|
+
...options,
|
|
668
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
},
|
|
672
|
+
rateChat(params, options) {
|
|
673
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
674
|
+
const body = { rating: params.rating };
|
|
675
|
+
if (params.comment) body.comment = params.comment;
|
|
676
|
+
return apiConfig.httpClient.post(
|
|
677
|
+
`${base(businessId)}/agents/${params.id}/chats/${params.chatId}/rate`,
|
|
678
|
+
body,
|
|
679
|
+
options
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// src/utils/errors.ts
|
|
688
|
+
var convertServerErrorToRequestError = (serverError, renameRules) => {
|
|
689
|
+
const validationErrors = serverError?.validationErrors ?? [];
|
|
690
|
+
return {
|
|
691
|
+
...serverError,
|
|
692
|
+
validationErrors: validationErrors.map((validationError) => {
|
|
693
|
+
const field = validationError.field;
|
|
694
|
+
return {
|
|
695
|
+
field,
|
|
696
|
+
error: validationError.error || "GENERAL.VALIDATION_ERROR"
|
|
697
|
+
};
|
|
698
|
+
})
|
|
699
|
+
};
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// src/utils/queryParams.ts
|
|
703
|
+
function buildQueryString(params) {
|
|
704
|
+
const queryParts = [];
|
|
705
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
706
|
+
if (value === null || value === void 0) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (Array.isArray(value)) {
|
|
710
|
+
const jsonString = JSON.stringify(value);
|
|
711
|
+
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
712
|
+
} else if (typeof value === "string") {
|
|
713
|
+
queryParts.push(`${key}=${encodeURIComponent(value)}`);
|
|
714
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
715
|
+
queryParts.push(`${key}=${value}`);
|
|
716
|
+
} else if (typeof value === "object") {
|
|
717
|
+
const jsonString = JSON.stringify(value);
|
|
718
|
+
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// src/services/createHttpClient.ts
|
|
725
|
+
var STORAGE_KEYS = {
|
|
726
|
+
accessToken: "arky_token",
|
|
727
|
+
refreshToken: "arky_refresh",
|
|
728
|
+
accessExpiresAt: "arky_expires_at"
|
|
729
|
+
};
|
|
730
|
+
function defaultGetToken() {
|
|
731
|
+
if (typeof window === "undefined") return { accessToken: "" };
|
|
732
|
+
return {
|
|
733
|
+
accessToken: localStorage.getItem(STORAGE_KEYS.accessToken) || "",
|
|
734
|
+
refreshToken: localStorage.getItem(STORAGE_KEYS.refreshToken) || "",
|
|
735
|
+
accessExpiresAt: parseInt(localStorage.getItem(STORAGE_KEYS.accessExpiresAt) || "0", 10)
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function defaultSetToken(tokens) {
|
|
739
|
+
if (typeof window === "undefined") return;
|
|
740
|
+
if (tokens.accessToken) {
|
|
741
|
+
localStorage.setItem(STORAGE_KEYS.accessToken, tokens.accessToken);
|
|
742
|
+
localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.refreshToken || "");
|
|
743
|
+
localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.accessExpiresAt || 0).toString());
|
|
744
|
+
} else {
|
|
745
|
+
Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function defaultLogout() {
|
|
749
|
+
if (typeof window === "undefined") return;
|
|
750
|
+
Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
|
|
751
|
+
}
|
|
752
|
+
function defaultIsAuthenticated() {
|
|
753
|
+
if (typeof window === "undefined") return false;
|
|
754
|
+
const token = localStorage.getItem(STORAGE_KEYS.accessToken) || "";
|
|
755
|
+
return token.startsWith("customer_") || token.startsWith("account_");
|
|
756
|
+
}
|
|
757
|
+
function createHttpClient(cfg) {
|
|
758
|
+
const getToken = cfg.getToken || defaultGetToken;
|
|
759
|
+
const setToken = cfg.setToken || defaultSetToken;
|
|
760
|
+
const logout = cfg.logout || defaultLogout;
|
|
761
|
+
const refreshEndpoint = `${cfg.baseUrl}${cfg.refreshPath || "/v1/auth/refresh"}`;
|
|
762
|
+
let refreshPromise = null;
|
|
763
|
+
async function ensureFreshToken() {
|
|
764
|
+
if (refreshPromise) {
|
|
765
|
+
return refreshPromise;
|
|
766
|
+
}
|
|
767
|
+
refreshPromise = (async () => {
|
|
768
|
+
const { refreshToken } = await getToken();
|
|
769
|
+
if (!refreshToken) {
|
|
770
|
+
logout();
|
|
771
|
+
const err = new Error("No refresh token available");
|
|
772
|
+
err.name = "ApiError";
|
|
773
|
+
err.statusCode = 401;
|
|
774
|
+
throw err;
|
|
775
|
+
}
|
|
776
|
+
const refRes = await fetch(refreshEndpoint, {
|
|
777
|
+
method: "POST",
|
|
778
|
+
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
779
|
+
body: JSON.stringify({ refreshToken })
|
|
780
|
+
});
|
|
781
|
+
if (!refRes.ok) {
|
|
782
|
+
logout();
|
|
783
|
+
const err = new Error("Token refresh failed");
|
|
784
|
+
err.name = "ApiError";
|
|
785
|
+
err.statusCode = 401;
|
|
786
|
+
throw err;
|
|
787
|
+
}
|
|
788
|
+
const data = await refRes.json();
|
|
789
|
+
setToken(data);
|
|
790
|
+
})().finally(() => {
|
|
791
|
+
refreshPromise = null;
|
|
792
|
+
});
|
|
793
|
+
return refreshPromise;
|
|
794
|
+
}
|
|
795
|
+
async function request(method, path, body, options) {
|
|
796
|
+
if (options?.transformRequest) {
|
|
797
|
+
body = options.transformRequest(body);
|
|
798
|
+
}
|
|
799
|
+
const headers = {
|
|
800
|
+
Accept: "application/json",
|
|
801
|
+
"Content-Type": "application/json",
|
|
802
|
+
...options?.headers || {}
|
|
803
|
+
};
|
|
804
|
+
let { accessToken, accessExpiresAt } = await getToken();
|
|
805
|
+
const nowSec = Date.now() / 1e3;
|
|
806
|
+
if (accessExpiresAt && nowSec > accessExpiresAt) {
|
|
807
|
+
await ensureFreshToken();
|
|
808
|
+
const tokens = await getToken();
|
|
809
|
+
accessToken = tokens.accessToken;
|
|
810
|
+
}
|
|
811
|
+
if (accessToken) {
|
|
812
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
813
|
+
}
|
|
814
|
+
const finalPath = options?.params ? path + buildQueryString(options.params) : path;
|
|
815
|
+
const fetchOpts = { method, headers };
|
|
816
|
+
if (!["GET", "DELETE"].includes(method) && body !== void 0) {
|
|
817
|
+
fetchOpts.body = JSON.stringify(body);
|
|
818
|
+
}
|
|
819
|
+
const fullUrl = `${cfg.baseUrl}${finalPath}`;
|
|
820
|
+
let res;
|
|
821
|
+
let data;
|
|
822
|
+
const startedAt = Date.now();
|
|
823
|
+
try {
|
|
145
824
|
res = await fetch(fullUrl, fetchOpts);
|
|
146
825
|
} catch (error) {
|
|
147
826
|
const err = new Error(error instanceof Error ? error.message : "Network request failed");
|
|
@@ -599,132 +1278,6 @@ var createPromoCodeApi = (apiConfig) => {
|
|
|
599
1278
|
};
|
|
600
1279
|
};
|
|
601
1280
|
|
|
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
1281
|
// src/api/cms.ts
|
|
729
1282
|
var createCmsApi = (apiConfig) => {
|
|
730
1283
|
return {
|
|
@@ -1218,6 +1771,37 @@ var createMarketApi = (apiConfig) => {
|
|
|
1218
1771
|
};
|
|
1219
1772
|
|
|
1220
1773
|
// src/api/crm.ts
|
|
1774
|
+
var createActivityAdminApi = (apiConfig) => ({
|
|
1775
|
+
async timeline(params, options) {
|
|
1776
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
1777
|
+
const queryParams = { customerId: params.customerId };
|
|
1778
|
+
if (params.limit !== void 0) queryParams.limit = params.limit;
|
|
1779
|
+
if (params.cursor) queryParams.cursor = params.cursor;
|
|
1780
|
+
return apiConfig.httpClient.get(
|
|
1781
|
+
`/v1/businesses/${businessId}/activities/timeline`,
|
|
1782
|
+
{ ...options, params: queryParams }
|
|
1783
|
+
);
|
|
1784
|
+
},
|
|
1785
|
+
async count(params, options) {
|
|
1786
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
1787
|
+
const queryParams = {};
|
|
1788
|
+
if (params.type) queryParams.type = params.type;
|
|
1789
|
+
if (params.payloadKey) queryParams.payloadKey = params.payloadKey;
|
|
1790
|
+
if (params.payloadValue) queryParams.payloadValue = params.payloadValue;
|
|
1791
|
+
if (params.windowSeconds !== void 0) queryParams.windowSeconds = params.windowSeconds;
|
|
1792
|
+
return apiConfig.httpClient.get(
|
|
1793
|
+
`/v1/businesses/${businessId}/activities/count`,
|
|
1794
|
+
{ ...options, params: queryParams }
|
|
1795
|
+
);
|
|
1796
|
+
},
|
|
1797
|
+
async types(params, options) {
|
|
1798
|
+
const businessId = params?.businessId || apiConfig.businessId;
|
|
1799
|
+
return apiConfig.httpClient.get(
|
|
1800
|
+
`/v1/businesses/${businessId}/activities/types`,
|
|
1801
|
+
options
|
|
1802
|
+
);
|
|
1803
|
+
}
|
|
1804
|
+
});
|
|
1221
1805
|
var createCustomerApi = (apiConfig) => {
|
|
1222
1806
|
return {
|
|
1223
1807
|
async create(params, options) {
|
|
@@ -1336,149 +1920,8 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1336
1920
|
options
|
|
1337
1921
|
);
|
|
1338
1922
|
}
|
|
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
|
-
}
|
|
1923
|
+
},
|
|
1924
|
+
activity: createActivityAdminApi(apiConfig)
|
|
1482
1925
|
};
|
|
1483
1926
|
};
|
|
1484
1927
|
|
|
@@ -1656,847 +2099,271 @@ var createAgentApi = (apiConfig) => {
|
|
|
1656
2099
|
);
|
|
1657
2100
|
},
|
|
1658
2101
|
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
|
-
}
|
|
2102
|
+
const body = { rating: params.rating };
|
|
2103
|
+
if (params.comment) body.comment = params.comment;
|
|
2104
|
+
return apiConfig.httpClient.post(
|
|
2105
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/rate`,
|
|
2106
|
+
body,
|
|
2107
|
+
options
|
|
1914
2108
|
);
|
|
1915
2109
|
},
|
|
1916
|
-
async
|
|
2110
|
+
async getBusinessChats(params, options) {
|
|
2111
|
+
const businessId = params.businessId || apiConfig.businessId;
|
|
2112
|
+
const { businessId: _, ...queryParams } = params;
|
|
2113
|
+
return apiConfig.httpClient.get(`/v1/businesses/${businessId}/chats`, {
|
|
2114
|
+
...options,
|
|
2115
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
2116
|
+
});
|
|
2117
|
+
},
|
|
2118
|
+
async getChatMessages(params, options) {
|
|
2119
|
+
const queryParams = {};
|
|
2120
|
+
if (params.limit) queryParams.limit = String(params.limit);
|
|
1917
2121
|
return apiConfig.httpClient.get(
|
|
1918
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
2122
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chatId}/messages`,
|
|
1919
2123
|
{
|
|
1920
2124
|
...options,
|
|
1921
|
-
params
|
|
2125
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1922
2126
|
}
|
|
1923
2127
|
);
|
|
1924
2128
|
}
|
|
1925
2129
|
};
|
|
1926
2130
|
};
|
|
1927
2131
|
|
|
1928
|
-
// src/api/
|
|
1929
|
-
|
|
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 = [];
|
|
2132
|
+
// src/api/emailTemplate.ts
|
|
2133
|
+
var createEmailTemplateApi = (apiConfig) => {
|
|
1947
2134
|
return {
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
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
|
-
}
|
|
2135
|
+
async createEmailTemplate(params, options) {
|
|
2136
|
+
const { businessId, ...payload } = params;
|
|
2137
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2138
|
+
return apiConfig.httpClient.post(
|
|
2139
|
+
`/v1/businesses/${targetBusinessId}/email-templates`,
|
|
2140
|
+
payload,
|
|
2141
|
+
options
|
|
2142
|
+
);
|
|
2081
2143
|
},
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
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
|
-
});
|
|
2144
|
+
async updateEmailTemplate(params, options) {
|
|
2145
|
+
const { businessId, ...payload } = params;
|
|
2146
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2147
|
+
return apiConfig.httpClient.put(
|
|
2148
|
+
`/v1/businesses/${targetBusinessId}/email-templates/${params.id}`,
|
|
2149
|
+
payload,
|
|
2150
|
+
options
|
|
2151
|
+
);
|
|
2152
|
+
},
|
|
2153
|
+
async deleteEmailTemplate(params, options) {
|
|
2154
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2155
|
+
return apiConfig.httpClient.delete(
|
|
2156
|
+
`/v1/businesses/${targetBusinessId}/email-templates/${params.id}`,
|
|
2157
|
+
options
|
|
2158
|
+
);
|
|
2159
|
+
},
|
|
2160
|
+
async getEmailTemplate(params, options) {
|
|
2161
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2162
|
+
let identifier;
|
|
2163
|
+
if (params.id) {
|
|
2164
|
+
identifier = params.id;
|
|
2165
|
+
} else if (params.key) {
|
|
2166
|
+
identifier = `${targetBusinessId}:${params.key}`;
|
|
2167
|
+
} else {
|
|
2168
|
+
throw new Error("GetEmailTemplateParams requires id or key");
|
|
2169
|
+
}
|
|
2170
|
+
return apiConfig.httpClient.get(
|
|
2171
|
+
`/v1/businesses/${targetBusinessId}/email-templates/${identifier}`,
|
|
2172
|
+
options
|
|
2173
|
+
);
|
|
2174
|
+
},
|
|
2175
|
+
async getEmailTemplates(params, options) {
|
|
2176
|
+
const { businessId, ...queryParams } = params;
|
|
2177
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2178
|
+
return apiConfig.httpClient.get(
|
|
2179
|
+
`/v1/businesses/${targetBusinessId}/email-templates`,
|
|
2180
|
+
{
|
|
2181
|
+
...options,
|
|
2182
|
+
params: queryParams
|
|
2147
2183
|
}
|
|
2184
|
+
);
|
|
2185
|
+
}
|
|
2186
|
+
};
|
|
2187
|
+
};
|
|
2188
|
+
|
|
2189
|
+
// src/api/form.ts
|
|
2190
|
+
var createFormApi = (apiConfig) => {
|
|
2191
|
+
return {
|
|
2192
|
+
async createForm(params, options) {
|
|
2193
|
+
const { businessId, ...payload } = params;
|
|
2194
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2195
|
+
return apiConfig.httpClient.post(
|
|
2196
|
+
`/v1/businesses/${targetBusinessId}/forms`,
|
|
2197
|
+
payload,
|
|
2198
|
+
options
|
|
2199
|
+
);
|
|
2200
|
+
},
|
|
2201
|
+
async updateForm(params, options) {
|
|
2202
|
+
const { businessId, ...payload } = params;
|
|
2203
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2204
|
+
return apiConfig.httpClient.put(
|
|
2205
|
+
`/v1/businesses/${targetBusinessId}/forms/${params.id}`,
|
|
2206
|
+
payload,
|
|
2207
|
+
options
|
|
2208
|
+
);
|
|
2209
|
+
},
|
|
2210
|
+
async deleteForm(params, options) {
|
|
2211
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2212
|
+
return apiConfig.httpClient.delete(
|
|
2213
|
+
`/v1/businesses/${targetBusinessId}/forms/${params.id}`,
|
|
2214
|
+
options
|
|
2215
|
+
);
|
|
2216
|
+
},
|
|
2217
|
+
async getForm(params, options) {
|
|
2218
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2219
|
+
let identifier;
|
|
2220
|
+
if (params.id) {
|
|
2221
|
+
identifier = params.id;
|
|
2222
|
+
} else if (params.key) {
|
|
2223
|
+
identifier = `${targetBusinessId}:${params.key}`;
|
|
2224
|
+
} else {
|
|
2225
|
+
throw new Error("GetFormParams requires id or key");
|
|
2148
2226
|
}
|
|
2227
|
+
return apiConfig.httpClient.get(
|
|
2228
|
+
`/v1/businesses/${targetBusinessId}/forms/${identifier}`,
|
|
2229
|
+
options
|
|
2230
|
+
);
|
|
2149
2231
|
},
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
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`, {
|
|
2232
|
+
async getForms(params, options) {
|
|
2233
|
+
const { businessId, ...queryParams } = params;
|
|
2234
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2235
|
+
return apiConfig.httpClient.get(
|
|
2236
|
+
`/v1/businesses/${targetBusinessId}/forms`,
|
|
2237
|
+
{
|
|
2183
2238
|
...options,
|
|
2184
2239
|
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
2240
|
}
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
return apiConfig.httpClient.get(`${base(businessId)}/providers`, {
|
|
2260
|
-
...options,
|
|
2261
|
-
params: queryParams
|
|
2262
|
-
});
|
|
2241
|
+
);
|
|
2242
|
+
},
|
|
2243
|
+
async submit(params, options) {
|
|
2244
|
+
const { businessId, formId, ...payload } = params;
|
|
2245
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2246
|
+
return apiConfig.httpClient.post(
|
|
2247
|
+
`/v1/businesses/${targetBusinessId}/forms/${formId}/submissions`,
|
|
2248
|
+
{ ...payload, formId, businessId: targetBusinessId },
|
|
2249
|
+
options
|
|
2250
|
+
);
|
|
2251
|
+
},
|
|
2252
|
+
async getSubmissions(params, options) {
|
|
2253
|
+
const { businessId, formId, ...queryParams } = params;
|
|
2254
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2255
|
+
return apiConfig.httpClient.get(
|
|
2256
|
+
`/v1/businesses/${targetBusinessId}/forms/${formId}/submissions`,
|
|
2257
|
+
{
|
|
2258
|
+
...options,
|
|
2259
|
+
params: { ...queryParams, formId, businessId: targetBusinessId }
|
|
2263
2260
|
}
|
|
2261
|
+
);
|
|
2262
|
+
},
|
|
2263
|
+
async getSubmission(params, options) {
|
|
2264
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2265
|
+
return apiConfig.httpClient.get(
|
|
2266
|
+
`/v1/businesses/${targetBusinessId}/forms/${params.formId}/submissions/${params.id}`,
|
|
2267
|
+
options
|
|
2268
|
+
);
|
|
2269
|
+
},
|
|
2270
|
+
async updateSubmission(params, options) {
|
|
2271
|
+
const { businessId, formId, id, ...payload } = params;
|
|
2272
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2273
|
+
return apiConfig.httpClient.put(
|
|
2274
|
+
`/v1/businesses/${targetBusinessId}/forms/${formId}/submissions/${id}`,
|
|
2275
|
+
{ ...payload, formId, businessId: targetBusinessId, id },
|
|
2276
|
+
options
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
};
|
|
2281
|
+
|
|
2282
|
+
// src/api/taxonomy.ts
|
|
2283
|
+
var createTaxonomyApi = (apiConfig) => {
|
|
2284
|
+
return {
|
|
2285
|
+
async createTaxonomy(params, options) {
|
|
2286
|
+
const { businessId, ...payload } = params;
|
|
2287
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2288
|
+
return apiConfig.httpClient.post(
|
|
2289
|
+
`/v1/businesses/${targetBusinessId}/taxonomies`,
|
|
2290
|
+
payload,
|
|
2291
|
+
options
|
|
2292
|
+
);
|
|
2293
|
+
},
|
|
2294
|
+
async updateTaxonomy(params, options) {
|
|
2295
|
+
const { businessId, ...payload } = params;
|
|
2296
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2297
|
+
return apiConfig.httpClient.put(
|
|
2298
|
+
`/v1/businesses/${targetBusinessId}/taxonomies/${params.id}`,
|
|
2299
|
+
payload,
|
|
2300
|
+
options
|
|
2301
|
+
);
|
|
2302
|
+
},
|
|
2303
|
+
async deleteTaxonomy(params, options) {
|
|
2304
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2305
|
+
return apiConfig.httpClient.delete(
|
|
2306
|
+
`/v1/businesses/${targetBusinessId}/taxonomies/${params.id}`,
|
|
2307
|
+
options
|
|
2308
|
+
);
|
|
2309
|
+
},
|
|
2310
|
+
async getTaxonomy(params, options) {
|
|
2311
|
+
const targetBusinessId = params.businessId || apiConfig.businessId;
|
|
2312
|
+
let identifier;
|
|
2313
|
+
if (params.id) {
|
|
2314
|
+
identifier = params.id;
|
|
2315
|
+
} else if (params.key) {
|
|
2316
|
+
identifier = `${targetBusinessId}:${params.key}`;
|
|
2317
|
+
} else {
|
|
2318
|
+
throw new Error("GetTaxonomyParams requires id or key");
|
|
2264
2319
|
}
|
|
2320
|
+
return apiConfig.httpClient.get(
|
|
2321
|
+
`/v1/businesses/${targetBusinessId}/taxonomies/${identifier}`,
|
|
2322
|
+
options
|
|
2323
|
+
);
|
|
2265
2324
|
},
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
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
|
-
});
|
|
2325
|
+
async getTaxonomies(params, options) {
|
|
2326
|
+
const { businessId, ...queryParams } = params;
|
|
2327
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2328
|
+
return apiConfig.httpClient.get(
|
|
2329
|
+
`/v1/businesses/${targetBusinessId}/taxonomies`,
|
|
2330
|
+
{
|
|
2331
|
+
...options,
|
|
2332
|
+
params: queryParams
|
|
2371
2333
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
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
|
-
});
|
|
2334
|
+
);
|
|
2335
|
+
},
|
|
2336
|
+
async getTaxonomyChildren(params, options) {
|
|
2337
|
+
const { id, businessId } = params;
|
|
2338
|
+
const targetBusinessId = businessId || apiConfig.businessId;
|
|
2339
|
+
return apiConfig.httpClient.get(
|
|
2340
|
+
`/v1/businesses/${targetBusinessId}/taxonomies/${id}/children`,
|
|
2341
|
+
options
|
|
2342
|
+
);
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
};
|
|
2346
|
+
|
|
2347
|
+
// src/api/analytics.ts
|
|
2348
|
+
var createAnalyticsApi = (apiConfig) => {
|
|
2349
|
+
return {
|
|
2350
|
+
async getSummary(params, options) {
|
|
2351
|
+
return apiConfig.httpClient.get(
|
|
2352
|
+
`/v1/businesses/${apiConfig.businessId}/analytics/summary`,
|
|
2353
|
+
{
|
|
2354
|
+
...options,
|
|
2355
|
+
params: params || {}
|
|
2439
2356
|
}
|
|
2440
|
-
|
|
2357
|
+
);
|
|
2441
2358
|
},
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
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
|
-
);
|
|
2359
|
+
async getStatusBreakdown(params, options) {
|
|
2360
|
+
return apiConfig.httpClient.get(
|
|
2361
|
+
`/v1/businesses/${apiConfig.businessId}/analytics/status`,
|
|
2362
|
+
{
|
|
2363
|
+
...options,
|
|
2364
|
+
params
|
|
2498
2365
|
}
|
|
2499
|
-
|
|
2366
|
+
);
|
|
2500
2367
|
}
|
|
2501
2368
|
};
|
|
2502
2369
|
};
|
|
@@ -2771,7 +2638,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
|
|
|
2771
2638
|
}
|
|
2772
2639
|
|
|
2773
2640
|
// src/index.ts
|
|
2774
|
-
var SDK_VERSION = "0.7.
|
|
2641
|
+
var SDK_VERSION = "0.7.74";
|
|
2775
2642
|
var SUPPORTED_FRAMEWORKS = [
|
|
2776
2643
|
"astro",
|
|
2777
2644
|
"react",
|
|
@@ -2854,7 +2721,6 @@ async function createAdmin(config) {
|
|
|
2854
2721
|
const eshopApi = createEshopApi(apiConfig);
|
|
2855
2722
|
const bookingApi = createBookingApi(apiConfig);
|
|
2856
2723
|
const crmApi = createCustomerApi(apiConfig);
|
|
2857
|
-
const reactionApi = createReactionApi(apiConfig);
|
|
2858
2724
|
const locationApi = createLocationApi(apiConfig);
|
|
2859
2725
|
const marketApi = createMarketApi(apiConfig);
|
|
2860
2726
|
const agentApi = createAgentApi(apiConfig);
|
|
@@ -2980,7 +2846,7 @@ async function createAdmin(config) {
|
|
|
2980
2846
|
addSubscriber: crmApi.audiences.addSubscriber,
|
|
2981
2847
|
removeSubscriber: crmApi.audiences.removeSubscriber
|
|
2982
2848
|
},
|
|
2983
|
-
|
|
2849
|
+
activity: crmApi.activity
|
|
2984
2850
|
},
|
|
2985
2851
|
automation: {
|
|
2986
2852
|
agent: {
|
|
@@ -3093,6 +2959,7 @@ async function createStorefront(config) {
|
|
|
3093
2959
|
eshop: storefrontApi.eshop,
|
|
3094
2960
|
booking: storefrontApi.booking,
|
|
3095
2961
|
crm: storefrontApi.crm,
|
|
2962
|
+
activity: storefrontApi.activity,
|
|
3096
2963
|
automation: storefrontApi.automation,
|
|
3097
2964
|
analytics: {
|
|
3098
2965
|
track
|
|
@@ -3117,6 +2984,6 @@ async function createStorefront(config) {
|
|
|
3117
2984
|
};
|
|
3118
2985
|
}
|
|
3119
2986
|
|
|
3120
|
-
export {
|
|
2987
|
+
export { COMMON_ACTIVITY_TYPES, PaymentMethodType, SDK_VERSION, SUPPORTED_FRAMEWORKS, createAdmin, createStorefront };
|
|
3121
2988
|
//# sourceMappingURL=index.js.map
|
|
3122
2989
|
//# sourceMappingURL=index.js.map
|