arky-sdk 0.7.93 → 0.7.95
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/README.md +19 -19
- package/dist/admin.cjs +2324 -0
- package/dist/admin.cjs.map +1 -0
- package/dist/admin.d.cts +3 -0
- package/dist/admin.d.ts +3 -0
- package/dist/admin.js +2322 -0
- package/dist/admin.js.map +1 -0
- package/dist/index.cjs +518 -523
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -86
- package/dist/index.d.ts +55 -86
- package/dist/index.js +518 -523
- package/dist/index.js.map +1 -1
- package/dist/storefront.cjs +1359 -0
- package/dist/storefront.cjs.map +1 -0
- package/dist/storefront.d.cts +3 -0
- package/dist/storefront.d.ts +3 -0
- package/dist/storefront.js +1356 -0
- package/dist/storefront.js.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +164 -164
- package/dist/types.d.ts +164 -164
- package/dist/types.js.map +1 -1
- package/package.json +12 -5
package/dist/admin.cjs
ADDED
|
@@ -0,0 +1,2324 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/blocks.ts
|
|
4
|
+
function getBlockLabel(block) {
|
|
5
|
+
if (!block) return "";
|
|
6
|
+
return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) ?? "";
|
|
7
|
+
}
|
|
8
|
+
function formatBlockValue(block) {
|
|
9
|
+
if (!block || block.value === null || block.value === void 0) return "";
|
|
10
|
+
const value = block.value;
|
|
11
|
+
switch (block.type) {
|
|
12
|
+
case "boolean":
|
|
13
|
+
return value ? "Yes" : "No";
|
|
14
|
+
case "number":
|
|
15
|
+
if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
|
|
16
|
+
return new Date(value).toLocaleDateString();
|
|
17
|
+
}
|
|
18
|
+
return String(value);
|
|
19
|
+
case "relationship_entry":
|
|
20
|
+
case "relationship_media":
|
|
21
|
+
if (value && typeof value === "object") {
|
|
22
|
+
return value.mime_type ? value.name || value.id : value.title || value.name || value.id;
|
|
23
|
+
}
|
|
24
|
+
return String(value);
|
|
25
|
+
default:
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function prepareBlocksForSubmission(formData, blockTypes) {
|
|
30
|
+
return Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).map((key) => ({
|
|
31
|
+
key,
|
|
32
|
+
value: blockTypes?.[key] === "list" && !Array.isArray(formData[key]) ? [formData[key]] : formData[key]
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
function extractBlockValues(blocks) {
|
|
36
|
+
const values = {};
|
|
37
|
+
blocks.forEach((block) => {
|
|
38
|
+
values[block.key] = block.value ?? null;
|
|
39
|
+
});
|
|
40
|
+
return values;
|
|
41
|
+
}
|
|
42
|
+
var getBlockValue = (entry, blockKey) => {
|
|
43
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
44
|
+
return block?.value ?? null;
|
|
45
|
+
};
|
|
46
|
+
var getBlockTextValue = (block, locale = "en") => {
|
|
47
|
+
if (!block || block.value === null || block.value === void 0) return "";
|
|
48
|
+
if (block.type === "localized_text" || block.type === "markdown") {
|
|
49
|
+
if (typeof block.value === "object" && block.value !== null) {
|
|
50
|
+
return block.value[locale] ?? block.value["en"] ?? "";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (typeof block.value === "string") return block.value;
|
|
54
|
+
return String(block.value ?? "");
|
|
55
|
+
};
|
|
56
|
+
var getBlockValues = (entry, blockKey) => {
|
|
57
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
58
|
+
if (!block) return [];
|
|
59
|
+
if (block.type === "list" && Array.isArray(block.value)) {
|
|
60
|
+
return block.value;
|
|
61
|
+
}
|
|
62
|
+
return [];
|
|
63
|
+
};
|
|
64
|
+
function unwrapBlock(block, locale) {
|
|
65
|
+
if (!block?.type || block.value === void 0) return block;
|
|
66
|
+
if (block.type === "list") {
|
|
67
|
+
return block.value.map((obj) => {
|
|
68
|
+
const parsed = {};
|
|
69
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
70
|
+
parsed[k] = unwrapBlock(v, locale);
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (block.type === "map") {
|
|
76
|
+
const parsed = {};
|
|
77
|
+
for (const [k, v] of Object.entries(block.value || {})) {
|
|
78
|
+
parsed[k] = unwrapBlock(v, locale);
|
|
79
|
+
}
|
|
80
|
+
return parsed;
|
|
81
|
+
}
|
|
82
|
+
if (block.type === "localized_text" || block.type === "markdown") {
|
|
83
|
+
return block.value?.[locale];
|
|
84
|
+
}
|
|
85
|
+
return block.value;
|
|
86
|
+
}
|
|
87
|
+
var getBlockObjectValues = (entry, blockKey, locale = "en") => {
|
|
88
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
89
|
+
if (!block || block.type !== "list" || !Array.isArray(block.value)) return [];
|
|
90
|
+
return block.value.map((obj) => {
|
|
91
|
+
if (!obj?.value || !Array.isArray(obj.value)) return {};
|
|
92
|
+
return obj.value.reduce((acc, current) => {
|
|
93
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
94
|
+
return acc;
|
|
95
|
+
}, {});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
99
|
+
const block = entry?.blocks?.find((f) => f.key === blockKey);
|
|
100
|
+
if (!block) return {};
|
|
101
|
+
if (block.type === "list" && Array.isArray(block.value)) {
|
|
102
|
+
return block.value.reduce((acc, current) => {
|
|
103
|
+
acc[current.key] = unwrapBlock(current, locale);
|
|
104
|
+
return acc;
|
|
105
|
+
}, {});
|
|
106
|
+
}
|
|
107
|
+
if (block.type === "map" && block.value && typeof block.value === "object") {
|
|
108
|
+
const result = {};
|
|
109
|
+
for (const [k, v] of Object.entries(block.value)) {
|
|
110
|
+
result[k] = unwrapBlock(v, locale);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
return { [block.key]: unwrapBlock(block, locale) };
|
|
115
|
+
};
|
|
116
|
+
var getImageUrl = (imageBlock, isBlock = true) => {
|
|
117
|
+
if (!imageBlock) return null;
|
|
118
|
+
if (imageBlock.type === "relationship_media") {
|
|
119
|
+
const mediaValue = imageBlock.value;
|
|
120
|
+
return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
|
|
121
|
+
}
|
|
122
|
+
if (isBlock) {
|
|
123
|
+
if (typeof imageBlock === "string") return imageBlock;
|
|
124
|
+
if (imageBlock.url) return imageBlock.url;
|
|
125
|
+
}
|
|
126
|
+
return imageBlock.resolutions?.original?.url || null;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/utils/errors.ts
|
|
130
|
+
var convertServerErrorToRequestError = (serverError, renameRules) => {
|
|
131
|
+
const validationErrors = serverError?.validationErrors ?? [];
|
|
132
|
+
return {
|
|
133
|
+
...serverError,
|
|
134
|
+
validationErrors: validationErrors.map((validationError) => {
|
|
135
|
+
const field = validationError.field;
|
|
136
|
+
return {
|
|
137
|
+
field,
|
|
138
|
+
error: validationError.error || "GENERAL.VALIDATION_ERROR"
|
|
139
|
+
};
|
|
140
|
+
})
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/utils/queryParams.ts
|
|
145
|
+
function buildQueryString(params) {
|
|
146
|
+
const queryParts = [];
|
|
147
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
148
|
+
if (value === null || value === void 0) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(value)) {
|
|
152
|
+
const jsonString = JSON.stringify(value);
|
|
153
|
+
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
154
|
+
} else if (typeof value === "string") {
|
|
155
|
+
queryParts.push(`${key}=${encodeURIComponent(value)}`);
|
|
156
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
157
|
+
queryParts.push(`${key}=${value}`);
|
|
158
|
+
} else if (typeof value === "object") {
|
|
159
|
+
const jsonString = JSON.stringify(value);
|
|
160
|
+
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/services/createHttpClient.ts
|
|
167
|
+
var STORAGE_KEYS = {
|
|
168
|
+
access_token: "arky_token",
|
|
169
|
+
refresh_token: "arky_refresh",
|
|
170
|
+
access_expires_at: "arky_expires_at"
|
|
171
|
+
};
|
|
172
|
+
function defaultGetToken() {
|
|
173
|
+
if (typeof window === "undefined") return { access_token: "" };
|
|
174
|
+
return {
|
|
175
|
+
access_token: localStorage.getItem(STORAGE_KEYS.access_token) || "",
|
|
176
|
+
refresh_token: localStorage.getItem(STORAGE_KEYS.refresh_token) || "",
|
|
177
|
+
access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.access_expires_at) || "0", 10)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function defaultSetToken(tokens) {
|
|
181
|
+
if (typeof window === "undefined") return;
|
|
182
|
+
if (tokens.access_token) {
|
|
183
|
+
localStorage.setItem(STORAGE_KEYS.access_token, tokens.access_token);
|
|
184
|
+
localStorage.setItem(STORAGE_KEYS.refresh_token, tokens.refresh_token || "");
|
|
185
|
+
localStorage.setItem(STORAGE_KEYS.access_expires_at, (tokens.access_expires_at || 0).toString());
|
|
186
|
+
} else {
|
|
187
|
+
Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function defaultLogout() {
|
|
191
|
+
if (typeof window === "undefined") return;
|
|
192
|
+
Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
|
|
193
|
+
}
|
|
194
|
+
function defaultIsAuthenticated() {
|
|
195
|
+
if (typeof window === "undefined") return false;
|
|
196
|
+
const token = localStorage.getItem(STORAGE_KEYS.access_token) || "";
|
|
197
|
+
return token.startsWith("customer_") || token.startsWith("account_");
|
|
198
|
+
}
|
|
199
|
+
function createHttpClient(cfg) {
|
|
200
|
+
const getToken = cfg.getToken || defaultGetToken;
|
|
201
|
+
const setToken = cfg.setToken || defaultSetToken;
|
|
202
|
+
const logout = cfg.logout || defaultLogout;
|
|
203
|
+
let refreshPromise = null;
|
|
204
|
+
function getRefreshEndpoint() {
|
|
205
|
+
const refreshPath = typeof cfg.refreshPath === "function" ? cfg.refreshPath() : cfg.refreshPath || "/v1/auth/refresh";
|
|
206
|
+
return `${cfg.baseUrl}${refreshPath}`;
|
|
207
|
+
}
|
|
208
|
+
async function ensureFreshToken() {
|
|
209
|
+
if (refreshPromise) {
|
|
210
|
+
return refreshPromise;
|
|
211
|
+
}
|
|
212
|
+
refreshPromise = (async () => {
|
|
213
|
+
const { refresh_token } = await getToken();
|
|
214
|
+
if (!refresh_token) {
|
|
215
|
+
logout();
|
|
216
|
+
const err = new Error("No refresh token available");
|
|
217
|
+
err.name = "ApiError";
|
|
218
|
+
err.statusCode = 401;
|
|
219
|
+
throw err;
|
|
220
|
+
}
|
|
221
|
+
const refRes = await fetch(getRefreshEndpoint(), {
|
|
222
|
+
method: "POST",
|
|
223
|
+
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
224
|
+
body: JSON.stringify({ refresh_token })
|
|
225
|
+
});
|
|
226
|
+
if (!refRes.ok) {
|
|
227
|
+
logout();
|
|
228
|
+
const err = new Error("Token refresh failed");
|
|
229
|
+
err.name = "ApiError";
|
|
230
|
+
err.statusCode = 401;
|
|
231
|
+
throw err;
|
|
232
|
+
}
|
|
233
|
+
const data = await refRes.json();
|
|
234
|
+
setToken(data);
|
|
235
|
+
})().finally(() => {
|
|
236
|
+
refreshPromise = null;
|
|
237
|
+
});
|
|
238
|
+
return refreshPromise;
|
|
239
|
+
}
|
|
240
|
+
async function request(method, path, body, options) {
|
|
241
|
+
if (options?.transformRequest) {
|
|
242
|
+
body = options.transformRequest(body);
|
|
243
|
+
}
|
|
244
|
+
const headers = {
|
|
245
|
+
Accept: "application/json",
|
|
246
|
+
"Content-Type": "application/json",
|
|
247
|
+
...options?.headers || {}
|
|
248
|
+
};
|
|
249
|
+
let { access_token, access_expires_at } = await getToken();
|
|
250
|
+
const nowSec = Date.now() / 1e3;
|
|
251
|
+
if (access_expires_at && nowSec > access_expires_at) {
|
|
252
|
+
await ensureFreshToken();
|
|
253
|
+
const tokens = await getToken();
|
|
254
|
+
access_token = tokens.access_token;
|
|
255
|
+
}
|
|
256
|
+
if (access_token) {
|
|
257
|
+
headers["Authorization"] = `Bearer ${access_token}`;
|
|
258
|
+
}
|
|
259
|
+
const finalPath = options?.params ? path + buildQueryString(options.params) : path;
|
|
260
|
+
const fetchOpts = { method, headers };
|
|
261
|
+
if (!["GET", "DELETE"].includes(method) && body !== void 0) {
|
|
262
|
+
fetchOpts.body = JSON.stringify(body);
|
|
263
|
+
}
|
|
264
|
+
const fullUrl = `${cfg.baseUrl}${finalPath}`;
|
|
265
|
+
let res;
|
|
266
|
+
let data;
|
|
267
|
+
const startedAt = Date.now();
|
|
268
|
+
try {
|
|
269
|
+
res = await fetch(fullUrl, fetchOpts);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
const err = new Error(error instanceof Error ? error.message : "Network request failed");
|
|
272
|
+
err.name = "NetworkError";
|
|
273
|
+
err.method = method;
|
|
274
|
+
err.url = fullUrl;
|
|
275
|
+
if (options?.onError && method !== "GET") {
|
|
276
|
+
Promise.resolve(
|
|
277
|
+
options.onError({ error: err, method, url: fullUrl, aborted: false })
|
|
278
|
+
).catch(() => {
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
throw err;
|
|
282
|
+
}
|
|
283
|
+
if (res.status === 401 && !options?.["_retried"]) {
|
|
284
|
+
try {
|
|
285
|
+
await ensureFreshToken();
|
|
286
|
+
const tokens = await getToken();
|
|
287
|
+
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
288
|
+
fetchOpts.headers = headers;
|
|
289
|
+
return request(method, path, body, { ...options, _retried: true });
|
|
290
|
+
} catch (refreshError) {
|
|
291
|
+
throw refreshError;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
const contentLength = res.headers.get("content-length");
|
|
296
|
+
const contentType = res.headers.get("content-type");
|
|
297
|
+
if (res.status === 204 || contentLength === "0" || !contentType?.includes("application/json")) {
|
|
298
|
+
data = {};
|
|
299
|
+
} else {
|
|
300
|
+
data = await res.json();
|
|
301
|
+
}
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const err = new Error("Failed to parse response");
|
|
304
|
+
err.name = "ParseError";
|
|
305
|
+
err.method = method;
|
|
306
|
+
err.url = fullUrl;
|
|
307
|
+
err.status = res.status;
|
|
308
|
+
if (options?.onError && method !== "GET") {
|
|
309
|
+
Promise.resolve(
|
|
310
|
+
options.onError({ error: err, method, url: fullUrl, status: res.status })
|
|
311
|
+
).catch(() => {
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
throw err;
|
|
315
|
+
}
|
|
316
|
+
if (!res.ok) {
|
|
317
|
+
const serverErr = data;
|
|
318
|
+
const reqErr = convertServerErrorToRequestError(serverErr);
|
|
319
|
+
const err = new Error(serverErr.message || "Request failed");
|
|
320
|
+
err.name = "ApiError";
|
|
321
|
+
err.statusCode = serverErr.statusCode || res.status;
|
|
322
|
+
err.validationErrors = reqErr.validationErrors;
|
|
323
|
+
err.method = method;
|
|
324
|
+
err.url = fullUrl;
|
|
325
|
+
const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
|
|
326
|
+
if (requestId) err.requestId = requestId;
|
|
327
|
+
if (options?.onError && method !== "GET") {
|
|
328
|
+
Promise.resolve(
|
|
329
|
+
options.onError({
|
|
330
|
+
error: err,
|
|
331
|
+
method,
|
|
332
|
+
url: fullUrl,
|
|
333
|
+
status: res.status,
|
|
334
|
+
response: serverErr,
|
|
335
|
+
request_id: requestId || null,
|
|
336
|
+
duration_ms: Date.now() - startedAt
|
|
337
|
+
})
|
|
338
|
+
).catch(() => {
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
throw err;
|
|
342
|
+
}
|
|
343
|
+
if (options?.onSuccess && method !== "GET") {
|
|
344
|
+
const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
|
|
345
|
+
Promise.resolve(
|
|
346
|
+
options.onSuccess({
|
|
347
|
+
data,
|
|
348
|
+
method,
|
|
349
|
+
url: fullUrl,
|
|
350
|
+
status: res.status,
|
|
351
|
+
request_id: requestId || null,
|
|
352
|
+
duration_ms: Date.now() - startedAt
|
|
353
|
+
})
|
|
354
|
+
).catch(() => {
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return data;
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
get: (path, opts) => request("GET", path, void 0, opts),
|
|
361
|
+
post: (path, body, opts) => request("POST", path, body, opts),
|
|
362
|
+
put: (path, body, opts) => request("PUT", path, body, opts),
|
|
363
|
+
patch: (path, body, opts) => request("PATCH", path, body, opts),
|
|
364
|
+
delete: (path, opts) => request("DELETE", path, void 0, opts)
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/api/account.ts
|
|
369
|
+
var createAccountApi = (apiConfig) => {
|
|
370
|
+
return {
|
|
371
|
+
async updateAccount(params, options) {
|
|
372
|
+
const payload = {};
|
|
373
|
+
if (params.phone_numbers !== void 0) payload.phone_numbers = params.phone_numbers;
|
|
374
|
+
if (params.addresses !== void 0) payload.addresses = params.addresses;
|
|
375
|
+
if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
|
|
376
|
+
return apiConfig.httpClient.put("/v1/accounts", payload, options);
|
|
377
|
+
},
|
|
378
|
+
async deleteAccount(params, options) {
|
|
379
|
+
return apiConfig.httpClient.delete("/v1/accounts", options);
|
|
380
|
+
},
|
|
381
|
+
async getMe(params, options) {
|
|
382
|
+
return apiConfig.httpClient.get("/v1/accounts/me", options);
|
|
383
|
+
},
|
|
384
|
+
async searchAccounts(params, options) {
|
|
385
|
+
return apiConfig.httpClient.get("/v1/accounts/search", {
|
|
386
|
+
...options,
|
|
387
|
+
params: {
|
|
388
|
+
...params,
|
|
389
|
+
store_id: apiConfig.storeId
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// src/api/auth.ts
|
|
397
|
+
var createAuthApi = (apiConfig) => {
|
|
398
|
+
return {
|
|
399
|
+
async code(params, options) {
|
|
400
|
+
return apiConfig.httpClient.post("/v1/auth/code", params, options);
|
|
401
|
+
},
|
|
402
|
+
async verify(params, options) {
|
|
403
|
+
const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
|
|
404
|
+
if (result?.access_token) {
|
|
405
|
+
apiConfig.setToken({ ...result, email: params.email, is_verified: true });
|
|
406
|
+
}
|
|
407
|
+
return result;
|
|
408
|
+
},
|
|
409
|
+
async refresh(params, options) {
|
|
410
|
+
return apiConfig.httpClient.post("/v1/auth/refresh", params, options);
|
|
411
|
+
},
|
|
412
|
+
async storeCode(storeId, params, options) {
|
|
413
|
+
return apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
|
|
414
|
+
},
|
|
415
|
+
async storeVerify(storeId, params, options) {
|
|
416
|
+
const result = await apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/verify`, params, options);
|
|
417
|
+
if (result?.access_token) {
|
|
418
|
+
apiConfig.setToken({ ...result, email: params.email, is_verified: true });
|
|
419
|
+
}
|
|
420
|
+
return result;
|
|
421
|
+
},
|
|
422
|
+
async magicLink(params, options) {
|
|
423
|
+
return apiConfig.httpClient.post("/v1/auth/code", params, options);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// src/api/store.ts
|
|
429
|
+
var createStoreApi = (apiConfig) => {
|
|
430
|
+
return {
|
|
431
|
+
async createStore(params, options) {
|
|
432
|
+
return apiConfig.httpClient.post(`/v1/stores`, params, options);
|
|
433
|
+
},
|
|
434
|
+
async updateStore(params, options) {
|
|
435
|
+
return apiConfig.httpClient.put(
|
|
436
|
+
`/v1/stores/${params.id}`,
|
|
437
|
+
params,
|
|
438
|
+
options
|
|
439
|
+
);
|
|
440
|
+
},
|
|
441
|
+
async deleteStore(params, options) {
|
|
442
|
+
return apiConfig.httpClient.delete(
|
|
443
|
+
`/v1/stores/${params.id}`,
|
|
444
|
+
options
|
|
445
|
+
);
|
|
446
|
+
},
|
|
447
|
+
async getStore(params, options) {
|
|
448
|
+
return apiConfig.httpClient.get(
|
|
449
|
+
`/v1/stores/${apiConfig.storeId}`,
|
|
450
|
+
options
|
|
451
|
+
);
|
|
452
|
+
},
|
|
453
|
+
async getStores(params, options) {
|
|
454
|
+
return apiConfig.httpClient.get(`/v1/stores`, {
|
|
455
|
+
...options,
|
|
456
|
+
params
|
|
457
|
+
});
|
|
458
|
+
},
|
|
459
|
+
async getSubscriptionPlans(params, options) {
|
|
460
|
+
return apiConfig.httpClient.get("/v1/stores/plans", options);
|
|
461
|
+
},
|
|
462
|
+
async subscribe(params, options) {
|
|
463
|
+
const { store_id, plan_id, success_url, cancel_url } = params;
|
|
464
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
465
|
+
return apiConfig.httpClient.put(
|
|
466
|
+
`/v1/stores/${target_store_id}/subscribe`,
|
|
467
|
+
{ plan_id, success_url, cancel_url },
|
|
468
|
+
options
|
|
469
|
+
);
|
|
470
|
+
},
|
|
471
|
+
async createPortalSession(params, options) {
|
|
472
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
473
|
+
return apiConfig.httpClient.post(
|
|
474
|
+
`/v1/stores/${store_id}/subscription/portal`,
|
|
475
|
+
{ return_url: params.return_url },
|
|
476
|
+
options
|
|
477
|
+
);
|
|
478
|
+
},
|
|
479
|
+
async inviteUser(params, options) {
|
|
480
|
+
return apiConfig.httpClient.post(
|
|
481
|
+
`/v1/stores/${apiConfig.storeId}/invitation`,
|
|
482
|
+
params,
|
|
483
|
+
options
|
|
484
|
+
);
|
|
485
|
+
},
|
|
486
|
+
async removeMember(params, options) {
|
|
487
|
+
return apiConfig.httpClient.delete(
|
|
488
|
+
`/v1/stores/${apiConfig.storeId}/members/${params.account_id}`,
|
|
489
|
+
options
|
|
490
|
+
);
|
|
491
|
+
},
|
|
492
|
+
async handleInvitation(params, options) {
|
|
493
|
+
const { store_id, ...payload } = params;
|
|
494
|
+
return apiConfig.httpClient.put(
|
|
495
|
+
`/v1/stores/${store_id || apiConfig.storeId}/invitation`,
|
|
496
|
+
payload,
|
|
497
|
+
options
|
|
498
|
+
);
|
|
499
|
+
},
|
|
500
|
+
async testWebhook(params, options) {
|
|
501
|
+
return apiConfig.httpClient.post(
|
|
502
|
+
`/v1/stores/${apiConfig.storeId}/webhooks/test`,
|
|
503
|
+
params.webhook,
|
|
504
|
+
options
|
|
505
|
+
);
|
|
506
|
+
},
|
|
507
|
+
async getStoreMedia(params, options) {
|
|
508
|
+
const queryParams = {
|
|
509
|
+
limit: params.limit
|
|
510
|
+
};
|
|
511
|
+
if (params.cursor) queryParams.cursor = params.cursor;
|
|
512
|
+
if (params.ids && params.ids.length > 0) queryParams.ids = params.ids.join(",");
|
|
513
|
+
if (params.query) queryParams.query = params.query;
|
|
514
|
+
if (params.mime_type) queryParams.mime_type = params.mime_type;
|
|
515
|
+
if (params.sort_field) queryParams.sort_field = params.sort_field;
|
|
516
|
+
if (params.sort_direction) queryParams.sort_direction = params.sort_direction;
|
|
517
|
+
return apiConfig.httpClient.get(`/v1/stores/${params.id}/media`, {
|
|
518
|
+
...options,
|
|
519
|
+
params: queryParams
|
|
520
|
+
});
|
|
521
|
+
},
|
|
522
|
+
async oauthConnect(params, options) {
|
|
523
|
+
return apiConfig.httpClient.post(
|
|
524
|
+
`/v1/stores/${params.store_id}/oauth/connect`,
|
|
525
|
+
{ provider: params.provider, code: params.code, redirect_uri: params.redirect_uri },
|
|
526
|
+
options
|
|
527
|
+
);
|
|
528
|
+
},
|
|
529
|
+
async oauthDisconnect(params, options) {
|
|
530
|
+
return apiConfig.httpClient.post(
|
|
531
|
+
`/v1/stores/${params.store_id}/oauth/disconnect`,
|
|
532
|
+
{ provider: params.provider },
|
|
533
|
+
options
|
|
534
|
+
);
|
|
535
|
+
},
|
|
536
|
+
async listIntegrations(params, options) {
|
|
537
|
+
return apiConfig.httpClient.get(
|
|
538
|
+
`/v1/stores/${params.store_id}/integrations`,
|
|
539
|
+
options
|
|
540
|
+
);
|
|
541
|
+
},
|
|
542
|
+
async createIntegration(params, options) {
|
|
543
|
+
const { store_id, ...payload } = params;
|
|
544
|
+
return apiConfig.httpClient.post(
|
|
545
|
+
`/v1/stores/${store_id}/integrations`,
|
|
546
|
+
payload,
|
|
547
|
+
options
|
|
548
|
+
);
|
|
549
|
+
},
|
|
550
|
+
async updateIntegration(params, options) {
|
|
551
|
+
const { store_id, id, ...payload } = params;
|
|
552
|
+
return apiConfig.httpClient.put(
|
|
553
|
+
`/v1/stores/${store_id}/integrations/${id}`,
|
|
554
|
+
payload,
|
|
555
|
+
options
|
|
556
|
+
);
|
|
557
|
+
},
|
|
558
|
+
async deleteIntegration(params, options) {
|
|
559
|
+
return apiConfig.httpClient.delete(
|
|
560
|
+
`/v1/stores/${params.store_id}/integrations/${params.id}`,
|
|
561
|
+
options
|
|
562
|
+
);
|
|
563
|
+
},
|
|
564
|
+
async getIntegrationConfig(params, options) {
|
|
565
|
+
return apiConfig.httpClient.get(
|
|
566
|
+
`/v1/stores/${params.store_id}/integrations/config/${params.type}`,
|
|
567
|
+
options
|
|
568
|
+
);
|
|
569
|
+
},
|
|
570
|
+
async listWebhooks(params, options) {
|
|
571
|
+
return apiConfig.httpClient.get(
|
|
572
|
+
`/v1/stores/${params.store_id}/webhooks`,
|
|
573
|
+
options
|
|
574
|
+
);
|
|
575
|
+
},
|
|
576
|
+
async createWebhook(params, options) {
|
|
577
|
+
const { store_id, ...payload } = params;
|
|
578
|
+
return apiConfig.httpClient.post(
|
|
579
|
+
`/v1/stores/${store_id}/webhooks`,
|
|
580
|
+
payload,
|
|
581
|
+
options
|
|
582
|
+
);
|
|
583
|
+
},
|
|
584
|
+
async updateWebhook(params, options) {
|
|
585
|
+
const { store_id, id, ...payload } = params;
|
|
586
|
+
return apiConfig.httpClient.put(
|
|
587
|
+
`/v1/stores/${store_id}/webhooks/${id}`,
|
|
588
|
+
payload,
|
|
589
|
+
options
|
|
590
|
+
);
|
|
591
|
+
},
|
|
592
|
+
async deleteWebhook(params, options) {
|
|
593
|
+
return apiConfig.httpClient.delete(
|
|
594
|
+
`/v1/stores/${params.store_id}/webhooks/${params.id}`,
|
|
595
|
+
options
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// src/api/media.ts
|
|
602
|
+
var createMediaApi = (apiConfig) => {
|
|
603
|
+
return {
|
|
604
|
+
async getMedia(params, options) {
|
|
605
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
606
|
+
return apiConfig.httpClient.get(
|
|
607
|
+
`/v1/stores/${target_store_id}/media/${params.media_id}`,
|
|
608
|
+
options
|
|
609
|
+
);
|
|
610
|
+
},
|
|
611
|
+
async uploadStoreMedia(params, options) {
|
|
612
|
+
const { store_id, files = [], urls = [] } = params;
|
|
613
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
614
|
+
const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
|
|
615
|
+
const formData = new FormData();
|
|
616
|
+
files.forEach((file) => formData.append("files", file));
|
|
617
|
+
urls.forEach((url2) => formData.append("urls", url2));
|
|
618
|
+
const tokens = await apiConfig.getToken();
|
|
619
|
+
const response = await fetch(url, {
|
|
620
|
+
method: "POST",
|
|
621
|
+
body: formData,
|
|
622
|
+
headers: {
|
|
623
|
+
Authorization: `Bearer ${tokens.access_token}`
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
if (!response.ok) {
|
|
627
|
+
throw new Error("Upload failed, server said no");
|
|
628
|
+
}
|
|
629
|
+
return await response.json();
|
|
630
|
+
},
|
|
631
|
+
async deleteStoreMedia(params, options) {
|
|
632
|
+
const { id, media_id } = params;
|
|
633
|
+
return apiConfig.httpClient.delete(
|
|
634
|
+
`/v1/stores/${id}/media/${media_id}`,
|
|
635
|
+
options
|
|
636
|
+
);
|
|
637
|
+
},
|
|
638
|
+
async getStoreMedia(params, options) {
|
|
639
|
+
const { store_id, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
|
|
640
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
641
|
+
const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
|
|
642
|
+
const queryParams = { limit: String(limit) };
|
|
643
|
+
if (cursor) queryParams.cursor = cursor;
|
|
644
|
+
if (ids && ids.length > 0) queryParams.ids = ids.join(",");
|
|
645
|
+
if (query) queryParams.query = query;
|
|
646
|
+
if (mime_type) queryParams.mime_type = mime_type;
|
|
647
|
+
if (sort_field) queryParams.sort_field = sort_field;
|
|
648
|
+
if (sort_direction) queryParams.sort_direction = sort_direction;
|
|
649
|
+
const queryString = new URLSearchParams(queryParams).toString();
|
|
650
|
+
const tokens = await apiConfig.getToken();
|
|
651
|
+
const response = await fetch(`${url}?${queryString}`, {
|
|
652
|
+
headers: {
|
|
653
|
+
Authorization: `Bearer ${tokens.access_token}`
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
if (!response.ok) {
|
|
657
|
+
const errorData = await response.json().catch(() => null);
|
|
658
|
+
throw new Error(errorData?.message || "Failed to fetch media");
|
|
659
|
+
}
|
|
660
|
+
return await response.json();
|
|
661
|
+
},
|
|
662
|
+
async updateMedia(params, options) {
|
|
663
|
+
const { media_id, store_id, ...payload } = params;
|
|
664
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
665
|
+
return apiConfig.httpClient.put(
|
|
666
|
+
`/v1/stores/${target_store_id}/media/${media_id}`,
|
|
667
|
+
payload,
|
|
668
|
+
options
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
// src/api/notification.ts
|
|
675
|
+
var createNotificationApi = (apiConfig) => {
|
|
676
|
+
return {
|
|
677
|
+
async trackEmailOpen(params, options) {
|
|
678
|
+
return apiConfig.httpClient.get(
|
|
679
|
+
`/v1/notifications/track/pixel/${params.tracking_pixel_id}`,
|
|
680
|
+
options
|
|
681
|
+
);
|
|
682
|
+
},
|
|
683
|
+
async trigger(params, options) {
|
|
684
|
+
return apiConfig.httpClient.post(
|
|
685
|
+
"/v1/notifications/trigger",
|
|
686
|
+
params,
|
|
687
|
+
options
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// src/api/promoCode.ts
|
|
694
|
+
var createPromoCodeApi = (apiConfig) => {
|
|
695
|
+
return {
|
|
696
|
+
async createPromoCode(params, options) {
|
|
697
|
+
const { store_id, ...payload } = params;
|
|
698
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
699
|
+
return apiConfig.httpClient.post(
|
|
700
|
+
`/v1/stores/${target_store_id}/promo-codes`,
|
|
701
|
+
payload,
|
|
702
|
+
options
|
|
703
|
+
);
|
|
704
|
+
},
|
|
705
|
+
async updatePromoCode(params, options) {
|
|
706
|
+
const { store_id, ...payload } = params;
|
|
707
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
708
|
+
return apiConfig.httpClient.put(
|
|
709
|
+
`/v1/stores/${target_store_id}/promo-codes/${params.id}`,
|
|
710
|
+
payload,
|
|
711
|
+
options
|
|
712
|
+
);
|
|
713
|
+
},
|
|
714
|
+
async deletePromoCode(params, options) {
|
|
715
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
716
|
+
return apiConfig.httpClient.delete(
|
|
717
|
+
`/v1/stores/${target_store_id}/promo-codes/${params.id}`,
|
|
718
|
+
options
|
|
719
|
+
);
|
|
720
|
+
},
|
|
721
|
+
async getPromoCode(params, options) {
|
|
722
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
723
|
+
return apiConfig.httpClient.get(
|
|
724
|
+
`/v1/stores/${target_store_id}/promo-codes/${params.id}`,
|
|
725
|
+
options
|
|
726
|
+
);
|
|
727
|
+
},
|
|
728
|
+
async getPromoCodes(params, options) {
|
|
729
|
+
const { store_id, ...queryParams } = params;
|
|
730
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
731
|
+
return apiConfig.httpClient.get(`/v1/stores/${target_store_id}/promo-codes`, {
|
|
732
|
+
...options,
|
|
733
|
+
params: queryParams
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
// src/api/cms.ts
|
|
740
|
+
var createCmsApi = (apiConfig) => {
|
|
741
|
+
return {
|
|
742
|
+
async createNode(params, options) {
|
|
743
|
+
const { store_id, ...payload } = params;
|
|
744
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
745
|
+
return apiConfig.httpClient.post(
|
|
746
|
+
`/v1/stores/${target_store_id}/nodes`,
|
|
747
|
+
payload,
|
|
748
|
+
options
|
|
749
|
+
);
|
|
750
|
+
},
|
|
751
|
+
async updateNode(params, options) {
|
|
752
|
+
const { store_id, ...payload } = params;
|
|
753
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
754
|
+
return apiConfig.httpClient.put(
|
|
755
|
+
`/v1/stores/${target_store_id}/nodes/${params.id}`,
|
|
756
|
+
payload,
|
|
757
|
+
options
|
|
758
|
+
);
|
|
759
|
+
},
|
|
760
|
+
async deleteNode(params, options) {
|
|
761
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
762
|
+
return apiConfig.httpClient.delete(
|
|
763
|
+
`/v1/stores/${target_store_id}/nodes/${params.id}`,
|
|
764
|
+
options
|
|
765
|
+
);
|
|
766
|
+
},
|
|
767
|
+
async getNode(params, options) {
|
|
768
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
769
|
+
let identifier;
|
|
770
|
+
if (params.id) {
|
|
771
|
+
identifier = params.id;
|
|
772
|
+
} else if (params.slug) {
|
|
773
|
+
identifier = `${target_store_id}:${apiConfig.locale}:${params.slug}`;
|
|
774
|
+
} else if (params.key) {
|
|
775
|
+
identifier = `${target_store_id}:${params.key}`;
|
|
776
|
+
} else {
|
|
777
|
+
throw new Error("GetNodeParams requires id, slug, or key");
|
|
778
|
+
}
|
|
779
|
+
const response = await apiConfig.httpClient.get(
|
|
780
|
+
`/v1/stores/${target_store_id}/nodes/${identifier}`,
|
|
781
|
+
options
|
|
782
|
+
);
|
|
783
|
+
return {
|
|
784
|
+
...response,
|
|
785
|
+
getBlock(key) {
|
|
786
|
+
return getBlockFromArray(response, key, apiConfig.locale);
|
|
787
|
+
},
|
|
788
|
+
getBlockValues(key) {
|
|
789
|
+
return getBlockObjectValues(response, key, apiConfig.locale);
|
|
790
|
+
},
|
|
791
|
+
getImage(key) {
|
|
792
|
+
const block = getBlockFromArray(response, key, apiConfig.locale);
|
|
793
|
+
return getImageUrl(block, true);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
},
|
|
797
|
+
async getNodes(params, options) {
|
|
798
|
+
const { store_id, ...queryParams } = params;
|
|
799
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
800
|
+
return apiConfig.httpClient.get(
|
|
801
|
+
`/v1/stores/${target_store_id}/nodes`,
|
|
802
|
+
{
|
|
803
|
+
...options,
|
|
804
|
+
params: queryParams
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
},
|
|
808
|
+
async getNodeChildren(params, options) {
|
|
809
|
+
const { id, store_id, ...queryParams } = params;
|
|
810
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
811
|
+
return apiConfig.httpClient.get(
|
|
812
|
+
`/v1/stores/${target_store_id}/nodes/${id}/children`,
|
|
813
|
+
{
|
|
814
|
+
...options,
|
|
815
|
+
params: queryParams
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
// src/api/eshop.ts
|
|
823
|
+
var createEshopApi = (apiConfig) => {
|
|
824
|
+
return {
|
|
825
|
+
async createProduct(params, options) {
|
|
826
|
+
const { store_id, ...payload } = params;
|
|
827
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
828
|
+
return apiConfig.httpClient.post(
|
|
829
|
+
`/v1/stores/${target_store_id}/products`,
|
|
830
|
+
payload,
|
|
831
|
+
options
|
|
832
|
+
);
|
|
833
|
+
},
|
|
834
|
+
async updateProduct(params, options) {
|
|
835
|
+
const { store_id, ...payload } = params;
|
|
836
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
837
|
+
return apiConfig.httpClient.put(
|
|
838
|
+
`/v1/stores/${target_store_id}/products/${params.id}`,
|
|
839
|
+
payload,
|
|
840
|
+
options
|
|
841
|
+
);
|
|
842
|
+
},
|
|
843
|
+
async deleteProduct(params, options) {
|
|
844
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
845
|
+
return apiConfig.httpClient.delete(
|
|
846
|
+
`/v1/stores/${target_store_id}/products/${params.id}`,
|
|
847
|
+
options
|
|
848
|
+
);
|
|
849
|
+
},
|
|
850
|
+
async getProduct(params, options) {
|
|
851
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
852
|
+
let identifier;
|
|
853
|
+
if (params.id) {
|
|
854
|
+
identifier = params.id;
|
|
855
|
+
} else if (params.slug) {
|
|
856
|
+
identifier = `${target_store_id}:${apiConfig.locale}:${params.slug}`;
|
|
857
|
+
} else {
|
|
858
|
+
throw new Error("GetProductParams requires id or slug");
|
|
859
|
+
}
|
|
860
|
+
return apiConfig.httpClient.get(
|
|
861
|
+
`/v1/stores/${target_store_id}/products/${identifier}`,
|
|
862
|
+
options
|
|
863
|
+
);
|
|
864
|
+
},
|
|
865
|
+
async getProducts(params, options) {
|
|
866
|
+
const { store_id, ...queryParams } = params;
|
|
867
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
868
|
+
return apiConfig.httpClient.get(
|
|
869
|
+
`/v1/stores/${encodeURIComponent(target_store_id)}/products`,
|
|
870
|
+
{
|
|
871
|
+
...options,
|
|
872
|
+
params: queryParams
|
|
873
|
+
}
|
|
874
|
+
);
|
|
875
|
+
},
|
|
876
|
+
async createOrder(params, options) {
|
|
877
|
+
const { store_id, ...payload } = params;
|
|
878
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
879
|
+
return apiConfig.httpClient.post(
|
|
880
|
+
`/v1/stores/${target_store_id}/orders`,
|
|
881
|
+
payload,
|
|
882
|
+
options
|
|
883
|
+
);
|
|
884
|
+
},
|
|
885
|
+
async updateOrder(params, options) {
|
|
886
|
+
const { store_id, ...payload } = params;
|
|
887
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
888
|
+
return apiConfig.httpClient.put(
|
|
889
|
+
`/v1/stores/${target_store_id}/orders/${params.id}`,
|
|
890
|
+
payload,
|
|
891
|
+
options
|
|
892
|
+
);
|
|
893
|
+
},
|
|
894
|
+
async getOrder(params, options) {
|
|
895
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
896
|
+
return apiConfig.httpClient.get(
|
|
897
|
+
`/v1/stores/${target_store_id}/orders/${params.id}`,
|
|
898
|
+
options
|
|
899
|
+
);
|
|
900
|
+
},
|
|
901
|
+
async getOrders(params, options) {
|
|
902
|
+
const { store_id, ...queryParams } = params;
|
|
903
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
904
|
+
return apiConfig.httpClient.get(
|
|
905
|
+
`/v1/stores/${target_store_id}/orders`,
|
|
906
|
+
{
|
|
907
|
+
...options,
|
|
908
|
+
params: queryParams
|
|
909
|
+
}
|
|
910
|
+
);
|
|
911
|
+
},
|
|
912
|
+
async getQuote(params, options) {
|
|
913
|
+
const { location, ...rest } = params;
|
|
914
|
+
const shipping_address = location ? {
|
|
915
|
+
country: location.country || "",
|
|
916
|
+
state: location.state || "",
|
|
917
|
+
city: location.city || "",
|
|
918
|
+
postal_code: location.postal_code || "",
|
|
919
|
+
name: "",
|
|
920
|
+
street1: "",
|
|
921
|
+
street2: null
|
|
922
|
+
} : void 0;
|
|
923
|
+
return apiConfig.httpClient.post(
|
|
924
|
+
`/v1/stores/${apiConfig.storeId}/orders/quote`,
|
|
925
|
+
{ ...rest, shipping_address, market: apiConfig.market },
|
|
926
|
+
options
|
|
927
|
+
);
|
|
928
|
+
},
|
|
929
|
+
async processRefund(params, options) {
|
|
930
|
+
return apiConfig.httpClient.post(
|
|
931
|
+
`/v1/stores/${apiConfig.storeId}/orders/${params.id}/refund`,
|
|
932
|
+
{ amount: params.amount },
|
|
933
|
+
options
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
// src/api/booking.ts
|
|
940
|
+
var createBookingApi = (apiConfig) => {
|
|
941
|
+
let cart = [];
|
|
942
|
+
return {
|
|
943
|
+
addToCart(slot) {
|
|
944
|
+
cart.push(slot);
|
|
945
|
+
},
|
|
946
|
+
removeFromCart(slotId) {
|
|
947
|
+
cart = cart.filter((s) => s.id !== slotId);
|
|
948
|
+
},
|
|
949
|
+
getCart() {
|
|
950
|
+
return [...cart];
|
|
951
|
+
},
|
|
952
|
+
clearCart() {
|
|
953
|
+
cart = [];
|
|
954
|
+
},
|
|
955
|
+
async createBooking(params, options) {
|
|
956
|
+
const { store_id, ...payload } = params;
|
|
957
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
958
|
+
return apiConfig.httpClient.post(
|
|
959
|
+
`/v1/stores/${target_store_id}/bookings`,
|
|
960
|
+
{ market: "booking", ...payload },
|
|
961
|
+
options
|
|
962
|
+
);
|
|
963
|
+
},
|
|
964
|
+
async updateBooking(params, options) {
|
|
965
|
+
const { id, ...payload } = params;
|
|
966
|
+
return apiConfig.httpClient.put(
|
|
967
|
+
`/v1/stores/${apiConfig.storeId}/bookings/${id}`,
|
|
968
|
+
payload,
|
|
969
|
+
options
|
|
970
|
+
);
|
|
971
|
+
},
|
|
972
|
+
async getBooking(params, options) {
|
|
973
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
974
|
+
return apiConfig.httpClient.get(
|
|
975
|
+
`/v1/stores/${target_store_id}/bookings/${params.id}`,
|
|
976
|
+
options
|
|
977
|
+
);
|
|
978
|
+
},
|
|
979
|
+
async searchBookings(params, options) {
|
|
980
|
+
const { store_id, ...queryParams } = params;
|
|
981
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
982
|
+
return apiConfig.httpClient.get(
|
|
983
|
+
`/v1/stores/${target_store_id}/bookings`,
|
|
984
|
+
{
|
|
985
|
+
...options,
|
|
986
|
+
params: queryParams
|
|
987
|
+
}
|
|
988
|
+
);
|
|
989
|
+
},
|
|
990
|
+
async getQuote(params, options) {
|
|
991
|
+
const { store_id, ...payload } = params;
|
|
992
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
993
|
+
return apiConfig.httpClient.post(
|
|
994
|
+
`/v1/stores/${target_store_id}/bookings/quote`,
|
|
995
|
+
{ market: "booking", ...payload },
|
|
996
|
+
options
|
|
997
|
+
);
|
|
998
|
+
},
|
|
999
|
+
async processRefund(params, options) {
|
|
1000
|
+
return apiConfig.httpClient.post(
|
|
1001
|
+
`/v1/stores/${apiConfig.storeId}/bookings/${params.id}/refund`,
|
|
1002
|
+
{ amount: params.amount },
|
|
1003
|
+
options
|
|
1004
|
+
);
|
|
1005
|
+
},
|
|
1006
|
+
async getAvailability(params, options) {
|
|
1007
|
+
const { store_id, ...query } = params;
|
|
1008
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1009
|
+
return apiConfig.httpClient.get(
|
|
1010
|
+
`/v1/stores/${target_store_id}/bookings/availability`,
|
|
1011
|
+
{ ...options, params: query }
|
|
1012
|
+
);
|
|
1013
|
+
},
|
|
1014
|
+
async createService(params, options) {
|
|
1015
|
+
const { store_id, ...payload } = params;
|
|
1016
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1017
|
+
return apiConfig.httpClient.post(
|
|
1018
|
+
`/v1/stores/${target_store_id}/services`,
|
|
1019
|
+
payload,
|
|
1020
|
+
options
|
|
1021
|
+
);
|
|
1022
|
+
},
|
|
1023
|
+
async updateService(params, options) {
|
|
1024
|
+
const { store_id, ...payload } = params;
|
|
1025
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1026
|
+
return apiConfig.httpClient.put(
|
|
1027
|
+
`/v1/stores/${target_store_id}/services/${params.id}`,
|
|
1028
|
+
payload,
|
|
1029
|
+
options
|
|
1030
|
+
);
|
|
1031
|
+
},
|
|
1032
|
+
async deleteService(params, options) {
|
|
1033
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1034
|
+
return apiConfig.httpClient.delete(
|
|
1035
|
+
`/v1/stores/${target_store_id}/services/${params.id}`,
|
|
1036
|
+
options
|
|
1037
|
+
);
|
|
1038
|
+
},
|
|
1039
|
+
async getService(params, options) {
|
|
1040
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1041
|
+
let identifier;
|
|
1042
|
+
if (params.id) {
|
|
1043
|
+
identifier = params.id;
|
|
1044
|
+
} else if (params.slug) {
|
|
1045
|
+
identifier = `${store_id}:${apiConfig.locale}:${params.slug}`;
|
|
1046
|
+
} else {
|
|
1047
|
+
throw new Error("GetServiceParams requires id or slug");
|
|
1048
|
+
}
|
|
1049
|
+
return apiConfig.httpClient.get(
|
|
1050
|
+
`/v1/stores/${store_id}/services/${identifier}`,
|
|
1051
|
+
options
|
|
1052
|
+
);
|
|
1053
|
+
},
|
|
1054
|
+
async getServices(params, options) {
|
|
1055
|
+
const { store_id, ...queryParams } = params;
|
|
1056
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1057
|
+
return apiConfig.httpClient.get(
|
|
1058
|
+
`/v1/stores/${target_store_id}/services`,
|
|
1059
|
+
{
|
|
1060
|
+
...options,
|
|
1061
|
+
params: queryParams
|
|
1062
|
+
}
|
|
1063
|
+
);
|
|
1064
|
+
},
|
|
1065
|
+
async createProvider(params, options) {
|
|
1066
|
+
const { store_id, ...payload } = params;
|
|
1067
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1068
|
+
return apiConfig.httpClient.post(
|
|
1069
|
+
`/v1/stores/${target_store_id}/providers`,
|
|
1070
|
+
payload,
|
|
1071
|
+
options
|
|
1072
|
+
);
|
|
1073
|
+
},
|
|
1074
|
+
async updateProvider(params, options) {
|
|
1075
|
+
const { store_id, ...payload } = params;
|
|
1076
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1077
|
+
return apiConfig.httpClient.put(
|
|
1078
|
+
`/v1/stores/${target_store_id}/providers/${params.id}`,
|
|
1079
|
+
payload,
|
|
1080
|
+
options
|
|
1081
|
+
);
|
|
1082
|
+
},
|
|
1083
|
+
async deleteProvider(params, options) {
|
|
1084
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1085
|
+
return apiConfig.httpClient.delete(
|
|
1086
|
+
`/v1/stores/${target_store_id}/providers/${params.id}`,
|
|
1087
|
+
options
|
|
1088
|
+
);
|
|
1089
|
+
},
|
|
1090
|
+
async getProvider(params, options) {
|
|
1091
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1092
|
+
let identifier;
|
|
1093
|
+
if (params.id) {
|
|
1094
|
+
identifier = params.id;
|
|
1095
|
+
} else if (params.slug) {
|
|
1096
|
+
identifier = `${store_id}:${apiConfig.locale}:${params.slug}`;
|
|
1097
|
+
} else {
|
|
1098
|
+
throw new Error("GetProviderParams requires id or slug");
|
|
1099
|
+
}
|
|
1100
|
+
return apiConfig.httpClient.get(
|
|
1101
|
+
`/v1/stores/${store_id}/providers/${identifier}`,
|
|
1102
|
+
options
|
|
1103
|
+
);
|
|
1104
|
+
},
|
|
1105
|
+
async getProviders(params, options) {
|
|
1106
|
+
const { store_id, ...queryParams } = params;
|
|
1107
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1108
|
+
return apiConfig.httpClient.get(
|
|
1109
|
+
`/v1/stores/${target_store_id}/providers`,
|
|
1110
|
+
{
|
|
1111
|
+
...options,
|
|
1112
|
+
params: queryParams
|
|
1113
|
+
}
|
|
1114
|
+
);
|
|
1115
|
+
},
|
|
1116
|
+
async cancelBookingItem(params, options) {
|
|
1117
|
+
const { store_id, booking_id, item_id, ...payload } = params;
|
|
1118
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1119
|
+
return apiConfig.httpClient.post(
|
|
1120
|
+
`/v1/stores/${target_store_id}/bookings/${booking_id}/items/${item_id}/cancel`,
|
|
1121
|
+
payload,
|
|
1122
|
+
options
|
|
1123
|
+
);
|
|
1124
|
+
},
|
|
1125
|
+
async findServiceProviders(params, options) {
|
|
1126
|
+
const { store_id, ...queryParams } = params;
|
|
1127
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1128
|
+
return apiConfig.httpClient.get(
|
|
1129
|
+
`/v1/stores/${target_store_id}/service-providers`,
|
|
1130
|
+
{ ...options, params: queryParams }
|
|
1131
|
+
);
|
|
1132
|
+
},
|
|
1133
|
+
async createServiceProvider(params, options) {
|
|
1134
|
+
const { store_id, ...payload } = params;
|
|
1135
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1136
|
+
return apiConfig.httpClient.post(
|
|
1137
|
+
`/v1/stores/${target_store_id}/service-providers`,
|
|
1138
|
+
payload,
|
|
1139
|
+
options
|
|
1140
|
+
);
|
|
1141
|
+
},
|
|
1142
|
+
async updateServiceProvider(params, options) {
|
|
1143
|
+
const { store_id, id, ...payload } = params;
|
|
1144
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1145
|
+
return apiConfig.httpClient.put(
|
|
1146
|
+
`/v1/stores/${target_store_id}/service-providers/${id}`,
|
|
1147
|
+
payload,
|
|
1148
|
+
options
|
|
1149
|
+
);
|
|
1150
|
+
},
|
|
1151
|
+
async deleteServiceProvider(params, options) {
|
|
1152
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1153
|
+
return apiConfig.httpClient.delete(
|
|
1154
|
+
`/v1/stores/${target_store_id}/service-providers/${params.id}`,
|
|
1155
|
+
options
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1161
|
+
// src/api/location.ts
|
|
1162
|
+
var createLocationApi = (apiConfig) => {
|
|
1163
|
+
return {
|
|
1164
|
+
async getCountries(options) {
|
|
1165
|
+
return apiConfig.httpClient.get(`/v1/platform/countries`, options);
|
|
1166
|
+
},
|
|
1167
|
+
async getCountry(countryCode, options) {
|
|
1168
|
+
return apiConfig.httpClient.get(
|
|
1169
|
+
`/v1/platform/countries/${countryCode}`,
|
|
1170
|
+
options
|
|
1171
|
+
);
|
|
1172
|
+
},
|
|
1173
|
+
async list(options) {
|
|
1174
|
+
return apiConfig.httpClient.get(
|
|
1175
|
+
`/v1/stores/${apiConfig.storeId}/locations`,
|
|
1176
|
+
options
|
|
1177
|
+
);
|
|
1178
|
+
},
|
|
1179
|
+
async get(id, options) {
|
|
1180
|
+
return apiConfig.httpClient.get(
|
|
1181
|
+
`/v1/stores/${apiConfig.storeId}/locations/${id}`,
|
|
1182
|
+
options
|
|
1183
|
+
);
|
|
1184
|
+
},
|
|
1185
|
+
async create(params, options) {
|
|
1186
|
+
return apiConfig.httpClient.post(
|
|
1187
|
+
`/v1/stores/${apiConfig.storeId}/locations`,
|
|
1188
|
+
{ ...params, store_id: apiConfig.storeId },
|
|
1189
|
+
options
|
|
1190
|
+
);
|
|
1191
|
+
},
|
|
1192
|
+
async update(params, options) {
|
|
1193
|
+
return apiConfig.httpClient.put(
|
|
1194
|
+
`/v1/stores/${apiConfig.storeId}/locations/${params.id}`,
|
|
1195
|
+
{ ...params, store_id: apiConfig.storeId },
|
|
1196
|
+
options
|
|
1197
|
+
);
|
|
1198
|
+
},
|
|
1199
|
+
async delete(params, options) {
|
|
1200
|
+
return apiConfig.httpClient.delete(
|
|
1201
|
+
`/v1/stores/${apiConfig.storeId}/locations/${params.id}`,
|
|
1202
|
+
options
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// src/api/market.ts
|
|
1209
|
+
var createMarketApi = (apiConfig) => {
|
|
1210
|
+
return {
|
|
1211
|
+
async list(options) {
|
|
1212
|
+
return apiConfig.httpClient.get(
|
|
1213
|
+
`/v1/stores/${apiConfig.storeId}/markets`,
|
|
1214
|
+
options
|
|
1215
|
+
);
|
|
1216
|
+
},
|
|
1217
|
+
async get(id, options) {
|
|
1218
|
+
return apiConfig.httpClient.get(
|
|
1219
|
+
`/v1/stores/${apiConfig.storeId}/markets/${id}`,
|
|
1220
|
+
options
|
|
1221
|
+
);
|
|
1222
|
+
},
|
|
1223
|
+
async create(params, options) {
|
|
1224
|
+
return apiConfig.httpClient.post(
|
|
1225
|
+
`/v1/stores/${apiConfig.storeId}/markets`,
|
|
1226
|
+
{ ...params, store_id: apiConfig.storeId },
|
|
1227
|
+
options
|
|
1228
|
+
);
|
|
1229
|
+
},
|
|
1230
|
+
async update(params, options) {
|
|
1231
|
+
return apiConfig.httpClient.put(
|
|
1232
|
+
`/v1/stores/${apiConfig.storeId}/markets/${params.id}`,
|
|
1233
|
+
{ ...params, store_id: apiConfig.storeId },
|
|
1234
|
+
options
|
|
1235
|
+
);
|
|
1236
|
+
},
|
|
1237
|
+
async delete(params, options) {
|
|
1238
|
+
return apiConfig.httpClient.delete(
|
|
1239
|
+
`/v1/stores/${apiConfig.storeId}/markets/${params.id}`,
|
|
1240
|
+
options
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
// src/api/crm.ts
|
|
1247
|
+
var createActivityAdminApi = (apiConfig) => ({
|
|
1248
|
+
async timeline(params, options) {
|
|
1249
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1250
|
+
const queryParams = { customer_id: params.customer_id };
|
|
1251
|
+
if (params.limit !== void 0) queryParams.limit = params.limit;
|
|
1252
|
+
if (params.cursor) queryParams.cursor = params.cursor;
|
|
1253
|
+
return apiConfig.httpClient.get(
|
|
1254
|
+
`/v1/stores/${store_id}/activities/timeline`,
|
|
1255
|
+
{ ...options, params: queryParams }
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
var createCustomerApi = (apiConfig) => {
|
|
1260
|
+
return {
|
|
1261
|
+
async create(params, options) {
|
|
1262
|
+
const { store_id, ...payload } = params;
|
|
1263
|
+
return apiConfig.httpClient.post(
|
|
1264
|
+
`/v1/stores/${store_id || apiConfig.storeId}/customers`,
|
|
1265
|
+
payload,
|
|
1266
|
+
options
|
|
1267
|
+
);
|
|
1268
|
+
},
|
|
1269
|
+
async get(params, options) {
|
|
1270
|
+
return apiConfig.httpClient.get(
|
|
1271
|
+
`/v1/stores/${params.store_id || apiConfig.storeId}/customers/${params.id}`,
|
|
1272
|
+
options
|
|
1273
|
+
);
|
|
1274
|
+
},
|
|
1275
|
+
async find(params, options) {
|
|
1276
|
+
const store_id = params?.store_id || apiConfig.storeId;
|
|
1277
|
+
const queryParams = {};
|
|
1278
|
+
if (params?.limit !== void 0) queryParams.limit = params.limit;
|
|
1279
|
+
if (params?.cursor) queryParams.cursor = params.cursor;
|
|
1280
|
+
if (params?.query) queryParams.query = params.query;
|
|
1281
|
+
if (params?.sort_field) queryParams.sort_field = params.sort_field;
|
|
1282
|
+
if (params?.sort_direction) queryParams.sort_direction = params.sort_direction;
|
|
1283
|
+
return apiConfig.httpClient.get(
|
|
1284
|
+
`/v1/stores/${store_id}/customers`,
|
|
1285
|
+
{
|
|
1286
|
+
...options,
|
|
1287
|
+
params: queryParams
|
|
1288
|
+
}
|
|
1289
|
+
);
|
|
1290
|
+
},
|
|
1291
|
+
async update(params, options) {
|
|
1292
|
+
const { id, store_id, ...body } = params;
|
|
1293
|
+
return apiConfig.httpClient.put(
|
|
1294
|
+
`/v1/stores/${store_id || apiConfig.storeId}/customers/${id}`,
|
|
1295
|
+
body,
|
|
1296
|
+
options
|
|
1297
|
+
);
|
|
1298
|
+
},
|
|
1299
|
+
async merge(params, options) {
|
|
1300
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1301
|
+
return apiConfig.httpClient.post(
|
|
1302
|
+
`/v1/stores/${store_id}/customers/${params.target_id}/merge`,
|
|
1303
|
+
{ source_id: params.source_id, store_id },
|
|
1304
|
+
options
|
|
1305
|
+
);
|
|
1306
|
+
},
|
|
1307
|
+
async revokeToken(params, options) {
|
|
1308
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1309
|
+
return apiConfig.httpClient.delete(
|
|
1310
|
+
`/v1/stores/${store_id}/customers/${params.id}/sessions/${params.token_id}`,
|
|
1311
|
+
options
|
|
1312
|
+
);
|
|
1313
|
+
},
|
|
1314
|
+
async revokeAllTokens(params, options) {
|
|
1315
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1316
|
+
return apiConfig.httpClient.delete(
|
|
1317
|
+
`/v1/stores/${store_id}/customers/${params.id}/sessions`,
|
|
1318
|
+
options
|
|
1319
|
+
);
|
|
1320
|
+
},
|
|
1321
|
+
audiences: {
|
|
1322
|
+
async create(params, options) {
|
|
1323
|
+
return apiConfig.httpClient.post(
|
|
1324
|
+
`/v1/stores/${apiConfig.storeId}/audiences`,
|
|
1325
|
+
params,
|
|
1326
|
+
options
|
|
1327
|
+
);
|
|
1328
|
+
},
|
|
1329
|
+
async update(params, options) {
|
|
1330
|
+
return apiConfig.httpClient.put(
|
|
1331
|
+
`/v1/stores/${apiConfig.storeId}/audiences/${params.id}`,
|
|
1332
|
+
params,
|
|
1333
|
+
options
|
|
1334
|
+
);
|
|
1335
|
+
},
|
|
1336
|
+
async get(params, options) {
|
|
1337
|
+
let identifier;
|
|
1338
|
+
if (params.id) {
|
|
1339
|
+
identifier = params.id;
|
|
1340
|
+
} else if (params.key) {
|
|
1341
|
+
identifier = `${apiConfig.storeId}:${params.key}`;
|
|
1342
|
+
} else {
|
|
1343
|
+
throw new Error("GetAudienceParams requires id or key");
|
|
1344
|
+
}
|
|
1345
|
+
return apiConfig.httpClient.get(
|
|
1346
|
+
`/v1/stores/${apiConfig.storeId}/audiences/${identifier}`,
|
|
1347
|
+
options
|
|
1348
|
+
);
|
|
1349
|
+
},
|
|
1350
|
+
async find(params, options) {
|
|
1351
|
+
return apiConfig.httpClient.get(
|
|
1352
|
+
`/v1/stores/${apiConfig.storeId}/audiences`,
|
|
1353
|
+
{ ...options, params }
|
|
1354
|
+
);
|
|
1355
|
+
},
|
|
1356
|
+
async getSubscribers(params, options) {
|
|
1357
|
+
return apiConfig.httpClient.get(
|
|
1358
|
+
`/v1/stores/${apiConfig.storeId}/audiences/${params.id}/subscribers`,
|
|
1359
|
+
{
|
|
1360
|
+
...options,
|
|
1361
|
+
params: { limit: params.limit, cursor: params.cursor }
|
|
1362
|
+
}
|
|
1363
|
+
);
|
|
1364
|
+
},
|
|
1365
|
+
async addSubscriber(params, options) {
|
|
1366
|
+
return apiConfig.httpClient.post(
|
|
1367
|
+
`/v1/stores/${apiConfig.storeId}/audiences/${params.id}/subscribers`,
|
|
1368
|
+
{ customer_id: params.customer_id },
|
|
1369
|
+
options
|
|
1370
|
+
);
|
|
1371
|
+
},
|
|
1372
|
+
async removeSubscriber(params, options) {
|
|
1373
|
+
return apiConfig.httpClient.delete(
|
|
1374
|
+
`/v1/stores/${apiConfig.storeId}/audiences/${params.id}/subscribers/${params.customer_id}`,
|
|
1375
|
+
options
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
},
|
|
1379
|
+
activity: createActivityAdminApi(apiConfig)
|
|
1380
|
+
};
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
// src/api/workflow.ts
|
|
1384
|
+
var createWorkflowApi = (apiConfig) => {
|
|
1385
|
+
return {
|
|
1386
|
+
async createWorkflow(params, options) {
|
|
1387
|
+
const { store_id, ...payload } = params;
|
|
1388
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1389
|
+
return apiConfig.httpClient.post(
|
|
1390
|
+
`/v1/stores/${target_store_id}/workflows`,
|
|
1391
|
+
{ ...payload, store_id: target_store_id },
|
|
1392
|
+
options
|
|
1393
|
+
);
|
|
1394
|
+
},
|
|
1395
|
+
async updateWorkflow(params, options) {
|
|
1396
|
+
const { store_id, id, ...payload } = params;
|
|
1397
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1398
|
+
return apiConfig.httpClient.put(
|
|
1399
|
+
`/v1/stores/${target_store_id}/workflows/${id}`,
|
|
1400
|
+
payload,
|
|
1401
|
+
options
|
|
1402
|
+
);
|
|
1403
|
+
},
|
|
1404
|
+
async deleteWorkflow(params, options) {
|
|
1405
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1406
|
+
return apiConfig.httpClient.delete(
|
|
1407
|
+
`/v1/stores/${store_id}/workflows/${params.id}`,
|
|
1408
|
+
options
|
|
1409
|
+
);
|
|
1410
|
+
},
|
|
1411
|
+
async getWorkflow(params, options) {
|
|
1412
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1413
|
+
return apiConfig.httpClient.get(
|
|
1414
|
+
`/v1/stores/${store_id}/workflows/${params.id}`,
|
|
1415
|
+
options
|
|
1416
|
+
);
|
|
1417
|
+
},
|
|
1418
|
+
async getWorkflows(params, options) {
|
|
1419
|
+
const store_id = params?.store_id || apiConfig.storeId;
|
|
1420
|
+
const { store_id: _, ...queryParams } = params || {};
|
|
1421
|
+
return apiConfig.httpClient.get(`/v1/stores/${store_id}/workflows`, {
|
|
1422
|
+
...options,
|
|
1423
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1424
|
+
});
|
|
1425
|
+
},
|
|
1426
|
+
async triggerWorkflow(params, options) {
|
|
1427
|
+
const { secret, ...payload } = params;
|
|
1428
|
+
return apiConfig.httpClient.post(`/v1/workflows/trigger/${secret}`, payload, options);
|
|
1429
|
+
},
|
|
1430
|
+
async getWorkflowExecutions(params, options) {
|
|
1431
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1432
|
+
const { store_id: _, workflow_id, ...queryParams } = params;
|
|
1433
|
+
return apiConfig.httpClient.get(
|
|
1434
|
+
`/v1/stores/${store_id}/workflows/${workflow_id}/executions`,
|
|
1435
|
+
{
|
|
1436
|
+
...options,
|
|
1437
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1438
|
+
}
|
|
1439
|
+
);
|
|
1440
|
+
},
|
|
1441
|
+
async getWorkflowExecution(params, options) {
|
|
1442
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1443
|
+
return apiConfig.httpClient.get(
|
|
1444
|
+
`/v1/stores/${store_id}/workflows/${params.workflow_id}/executions/${params.execution_id}`,
|
|
1445
|
+
options
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/api/platform.ts
|
|
1452
|
+
var createPlatformApi = (apiConfig) => {
|
|
1453
|
+
return {
|
|
1454
|
+
async getCurrencies(options) {
|
|
1455
|
+
return apiConfig.httpClient.get("/v1/platform/currencies", options);
|
|
1456
|
+
},
|
|
1457
|
+
async getIntegrationServices(options) {
|
|
1458
|
+
return apiConfig.httpClient.get("/v1/platform/integration-services", options);
|
|
1459
|
+
},
|
|
1460
|
+
async getWebhookEvents(options) {
|
|
1461
|
+
return apiConfig.httpClient.get("/v1/platform/events", options);
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
// src/api/shipping.ts
|
|
1467
|
+
var createShippingApi = (apiConfig) => {
|
|
1468
|
+
return {
|
|
1469
|
+
async getRates(params, options) {
|
|
1470
|
+
const { order_id, ...payload } = params;
|
|
1471
|
+
return apiConfig.httpClient.post(
|
|
1472
|
+
`/v1/stores/${apiConfig.storeId}/orders/${order_id}/shipping/rates`,
|
|
1473
|
+
payload,
|
|
1474
|
+
options
|
|
1475
|
+
);
|
|
1476
|
+
},
|
|
1477
|
+
async ship(params, options) {
|
|
1478
|
+
const { order_id, ...payload } = params;
|
|
1479
|
+
return apiConfig.httpClient.post(
|
|
1480
|
+
`/v1/stores/${apiConfig.storeId}/orders/${order_id}/ship`,
|
|
1481
|
+
payload,
|
|
1482
|
+
options
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
};
|
|
1487
|
+
|
|
1488
|
+
// src/api/agent.ts
|
|
1489
|
+
var createAgentApi = (apiConfig) => {
|
|
1490
|
+
return {
|
|
1491
|
+
async createAgent(params, options) {
|
|
1492
|
+
const { store_id, ...payload } = params;
|
|
1493
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1494
|
+
return apiConfig.httpClient.post(
|
|
1495
|
+
`/v1/stores/${target_store_id}/agents`,
|
|
1496
|
+
{ ...payload, store_id: target_store_id },
|
|
1497
|
+
options
|
|
1498
|
+
);
|
|
1499
|
+
},
|
|
1500
|
+
async updateAgent(params, options) {
|
|
1501
|
+
const { store_id, id, ...payload } = params;
|
|
1502
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1503
|
+
return apiConfig.httpClient.put(
|
|
1504
|
+
`/v1/stores/${target_store_id}/agents/${id}`,
|
|
1505
|
+
payload,
|
|
1506
|
+
options
|
|
1507
|
+
);
|
|
1508
|
+
},
|
|
1509
|
+
async deleteAgent(params, options) {
|
|
1510
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1511
|
+
return apiConfig.httpClient.delete(
|
|
1512
|
+
`/v1/stores/${store_id}/agents/${params.id}`,
|
|
1513
|
+
options
|
|
1514
|
+
);
|
|
1515
|
+
},
|
|
1516
|
+
async getAgent(params, options) {
|
|
1517
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1518
|
+
return apiConfig.httpClient.get(
|
|
1519
|
+
`/v1/stores/${store_id}/agents/${params.id}`,
|
|
1520
|
+
options
|
|
1521
|
+
);
|
|
1522
|
+
},
|
|
1523
|
+
async getAgents(params, options) {
|
|
1524
|
+
const store_id = params?.store_id || apiConfig.storeId;
|
|
1525
|
+
const { store_id: _, ...queryParams } = params || {};
|
|
1526
|
+
return apiConfig.httpClient.get(`/v1/stores/${store_id}/agents`, {
|
|
1527
|
+
...options,
|
|
1528
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1529
|
+
});
|
|
1530
|
+
},
|
|
1531
|
+
async sendMessage(params, options) {
|
|
1532
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1533
|
+
const body = { message: params.message };
|
|
1534
|
+
if (params.chat_id) body.chat_id = params.chat_id;
|
|
1535
|
+
if (params.direct) body.direct = params.direct;
|
|
1536
|
+
return apiConfig.httpClient.post(
|
|
1537
|
+
`/v1/stores/${store_id}/agents/${params.id}/chats/messages`,
|
|
1538
|
+
body,
|
|
1539
|
+
options
|
|
1540
|
+
);
|
|
1541
|
+
},
|
|
1542
|
+
async getChats(params, options) {
|
|
1543
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1544
|
+
const queryParams = {};
|
|
1545
|
+
if (params.limit) queryParams.limit = String(params.limit);
|
|
1546
|
+
if (params.cursor) queryParams.cursor = params.cursor;
|
|
1547
|
+
return apiConfig.httpClient.get(
|
|
1548
|
+
`/v1/stores/${store_id}/agents/${params.id}/chats`,
|
|
1549
|
+
{
|
|
1550
|
+
...options,
|
|
1551
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1552
|
+
}
|
|
1553
|
+
);
|
|
1554
|
+
},
|
|
1555
|
+
async getChat(params, options) {
|
|
1556
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1557
|
+
return apiConfig.httpClient.get(
|
|
1558
|
+
`/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}`,
|
|
1559
|
+
options
|
|
1560
|
+
);
|
|
1561
|
+
},
|
|
1562
|
+
async updateChat(params, options) {
|
|
1563
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1564
|
+
return apiConfig.httpClient.put(
|
|
1565
|
+
`/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}`,
|
|
1566
|
+
{ status: params.status },
|
|
1567
|
+
options
|
|
1568
|
+
);
|
|
1569
|
+
},
|
|
1570
|
+
async rateChat(params, options) {
|
|
1571
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1572
|
+
const body = { rating: params.rating };
|
|
1573
|
+
if (params.comment) body.comment = params.comment;
|
|
1574
|
+
return apiConfig.httpClient.post(
|
|
1575
|
+
`/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}/rate`,
|
|
1576
|
+
body,
|
|
1577
|
+
options
|
|
1578
|
+
);
|
|
1579
|
+
},
|
|
1580
|
+
async getStoreChats(params, options) {
|
|
1581
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1582
|
+
const { store_id: _, ...queryParams } = params;
|
|
1583
|
+
return apiConfig.httpClient.get(`/v1/stores/${store_id}/chats`, {
|
|
1584
|
+
...options,
|
|
1585
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1586
|
+
});
|
|
1587
|
+
},
|
|
1588
|
+
async getChatMessages(params, options) {
|
|
1589
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
1590
|
+
const queryParams = {};
|
|
1591
|
+
if (params.limit) queryParams.limit = String(params.limit);
|
|
1592
|
+
return apiConfig.httpClient.get(
|
|
1593
|
+
`/v1/stores/${store_id}/agents/${params.id}/chats/${params.chat_id}/messages`,
|
|
1594
|
+
{
|
|
1595
|
+
...options,
|
|
1596
|
+
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1597
|
+
}
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/api/emailTemplate.ts
|
|
1604
|
+
var createEmailTemplateApi = (apiConfig) => {
|
|
1605
|
+
return {
|
|
1606
|
+
async createEmailTemplate(params, options) {
|
|
1607
|
+
const { store_id, ...payload } = params;
|
|
1608
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1609
|
+
return apiConfig.httpClient.post(
|
|
1610
|
+
`/v1/stores/${target_store_id}/email-templates`,
|
|
1611
|
+
payload,
|
|
1612
|
+
options
|
|
1613
|
+
);
|
|
1614
|
+
},
|
|
1615
|
+
async updateEmailTemplate(params, options) {
|
|
1616
|
+
const { store_id, ...payload } = params;
|
|
1617
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1618
|
+
return apiConfig.httpClient.put(
|
|
1619
|
+
`/v1/stores/${target_store_id}/email-templates/${params.id}`,
|
|
1620
|
+
payload,
|
|
1621
|
+
options
|
|
1622
|
+
);
|
|
1623
|
+
},
|
|
1624
|
+
async deleteEmailTemplate(params, options) {
|
|
1625
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1626
|
+
return apiConfig.httpClient.delete(
|
|
1627
|
+
`/v1/stores/${target_store_id}/email-templates/${params.id}`,
|
|
1628
|
+
options
|
|
1629
|
+
);
|
|
1630
|
+
},
|
|
1631
|
+
async getEmailTemplate(params, options) {
|
|
1632
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1633
|
+
let identifier;
|
|
1634
|
+
if (params.id) {
|
|
1635
|
+
identifier = params.id;
|
|
1636
|
+
} else if (params.key) {
|
|
1637
|
+
identifier = `${target_store_id}:${params.key}`;
|
|
1638
|
+
} else {
|
|
1639
|
+
throw new Error("GetEmailTemplateParams requires id or key");
|
|
1640
|
+
}
|
|
1641
|
+
return apiConfig.httpClient.get(
|
|
1642
|
+
`/v1/stores/${target_store_id}/email-templates/${identifier}`,
|
|
1643
|
+
options
|
|
1644
|
+
);
|
|
1645
|
+
},
|
|
1646
|
+
async getEmailTemplates(params, options) {
|
|
1647
|
+
const { store_id, ...queryParams } = params;
|
|
1648
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1649
|
+
return apiConfig.httpClient.get(
|
|
1650
|
+
`/v1/stores/${target_store_id}/email-templates`,
|
|
1651
|
+
{
|
|
1652
|
+
...options,
|
|
1653
|
+
params: queryParams
|
|
1654
|
+
}
|
|
1655
|
+
);
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
// src/api/form.ts
|
|
1661
|
+
var createFormApi = (apiConfig) => {
|
|
1662
|
+
return {
|
|
1663
|
+
async createForm(params, options) {
|
|
1664
|
+
const { store_id, ...payload } = params;
|
|
1665
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1666
|
+
return apiConfig.httpClient.post(
|
|
1667
|
+
`/v1/stores/${target_store_id}/forms`,
|
|
1668
|
+
payload,
|
|
1669
|
+
options
|
|
1670
|
+
);
|
|
1671
|
+
},
|
|
1672
|
+
async updateForm(params, options) {
|
|
1673
|
+
const { store_id, ...payload } = params;
|
|
1674
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1675
|
+
return apiConfig.httpClient.put(
|
|
1676
|
+
`/v1/stores/${target_store_id}/forms/${params.id}`,
|
|
1677
|
+
payload,
|
|
1678
|
+
options
|
|
1679
|
+
);
|
|
1680
|
+
},
|
|
1681
|
+
async deleteForm(params, options) {
|
|
1682
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1683
|
+
return apiConfig.httpClient.delete(
|
|
1684
|
+
`/v1/stores/${target_store_id}/forms/${params.id}`,
|
|
1685
|
+
options
|
|
1686
|
+
);
|
|
1687
|
+
},
|
|
1688
|
+
async getForm(params, options) {
|
|
1689
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1690
|
+
let identifier;
|
|
1691
|
+
if (params.id) {
|
|
1692
|
+
identifier = params.id;
|
|
1693
|
+
} else if (params.key) {
|
|
1694
|
+
identifier = `${target_store_id}:${params.key}`;
|
|
1695
|
+
} else {
|
|
1696
|
+
throw new Error("GetFormParams requires id or key");
|
|
1697
|
+
}
|
|
1698
|
+
return apiConfig.httpClient.get(
|
|
1699
|
+
`/v1/stores/${target_store_id}/forms/${identifier}`,
|
|
1700
|
+
options
|
|
1701
|
+
);
|
|
1702
|
+
},
|
|
1703
|
+
async getForms(params, options) {
|
|
1704
|
+
const { store_id, ...queryParams } = params;
|
|
1705
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1706
|
+
return apiConfig.httpClient.get(
|
|
1707
|
+
`/v1/stores/${target_store_id}/forms`,
|
|
1708
|
+
{
|
|
1709
|
+
...options,
|
|
1710
|
+
params: queryParams
|
|
1711
|
+
}
|
|
1712
|
+
);
|
|
1713
|
+
},
|
|
1714
|
+
async submit(params, options) {
|
|
1715
|
+
const { store_id, form_id, ...payload } = params;
|
|
1716
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1717
|
+
return apiConfig.httpClient.post(
|
|
1718
|
+
`/v1/stores/${target_store_id}/forms/${form_id}/submissions`,
|
|
1719
|
+
{ ...payload, form_id, store_id: target_store_id },
|
|
1720
|
+
options
|
|
1721
|
+
);
|
|
1722
|
+
},
|
|
1723
|
+
async getSubmissions(params, options) {
|
|
1724
|
+
const { store_id, form_id, ...queryParams } = params;
|
|
1725
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1726
|
+
return apiConfig.httpClient.get(
|
|
1727
|
+
`/v1/stores/${target_store_id}/forms/${form_id}/submissions`,
|
|
1728
|
+
{
|
|
1729
|
+
...options,
|
|
1730
|
+
params: { ...queryParams, form_id, store_id: target_store_id }
|
|
1731
|
+
}
|
|
1732
|
+
);
|
|
1733
|
+
},
|
|
1734
|
+
async getSubmission(params, options) {
|
|
1735
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1736
|
+
return apiConfig.httpClient.get(
|
|
1737
|
+
`/v1/stores/${target_store_id}/forms/${params.form_id}/submissions/${params.id}`,
|
|
1738
|
+
options
|
|
1739
|
+
);
|
|
1740
|
+
},
|
|
1741
|
+
async updateSubmission(params, options) {
|
|
1742
|
+
const { store_id, form_id, id, ...payload } = params;
|
|
1743
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1744
|
+
return apiConfig.httpClient.put(
|
|
1745
|
+
`/v1/stores/${target_store_id}/forms/${form_id}/submissions/${id}`,
|
|
1746
|
+
{ ...payload, form_id, store_id: target_store_id, id },
|
|
1747
|
+
options
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
};
|
|
1752
|
+
|
|
1753
|
+
// src/api/taxonomy.ts
|
|
1754
|
+
var createTaxonomyApi = (apiConfig) => {
|
|
1755
|
+
return {
|
|
1756
|
+
async createTaxonomy(params, options) {
|
|
1757
|
+
const { store_id, ...payload } = params;
|
|
1758
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1759
|
+
return apiConfig.httpClient.post(
|
|
1760
|
+
`/v1/stores/${target_store_id}/taxonomies`,
|
|
1761
|
+
payload,
|
|
1762
|
+
options
|
|
1763
|
+
);
|
|
1764
|
+
},
|
|
1765
|
+
async updateTaxonomy(params, options) {
|
|
1766
|
+
const { store_id, ...payload } = params;
|
|
1767
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1768
|
+
return apiConfig.httpClient.put(
|
|
1769
|
+
`/v1/stores/${target_store_id}/taxonomies/${params.id}`,
|
|
1770
|
+
payload,
|
|
1771
|
+
options
|
|
1772
|
+
);
|
|
1773
|
+
},
|
|
1774
|
+
async deleteTaxonomy(params, options) {
|
|
1775
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1776
|
+
return apiConfig.httpClient.delete(
|
|
1777
|
+
`/v1/stores/${target_store_id}/taxonomies/${params.id}`,
|
|
1778
|
+
options
|
|
1779
|
+
);
|
|
1780
|
+
},
|
|
1781
|
+
async getTaxonomy(params, options) {
|
|
1782
|
+
const target_store_id = params.store_id || apiConfig.storeId;
|
|
1783
|
+
let identifier;
|
|
1784
|
+
if (params.id) {
|
|
1785
|
+
identifier = params.id;
|
|
1786
|
+
} else if (params.key) {
|
|
1787
|
+
identifier = `${target_store_id}:${params.key}`;
|
|
1788
|
+
} else {
|
|
1789
|
+
throw new Error("GetTaxonomyParams requires id or key");
|
|
1790
|
+
}
|
|
1791
|
+
return apiConfig.httpClient.get(
|
|
1792
|
+
`/v1/stores/${target_store_id}/taxonomies/${identifier}`,
|
|
1793
|
+
options
|
|
1794
|
+
);
|
|
1795
|
+
},
|
|
1796
|
+
async getTaxonomies(params, options) {
|
|
1797
|
+
const { store_id, ...queryParams } = params;
|
|
1798
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1799
|
+
return apiConfig.httpClient.get(
|
|
1800
|
+
`/v1/stores/${target_store_id}/taxonomies`,
|
|
1801
|
+
{
|
|
1802
|
+
...options,
|
|
1803
|
+
params: queryParams
|
|
1804
|
+
}
|
|
1805
|
+
);
|
|
1806
|
+
},
|
|
1807
|
+
async getTaxonomyChildren(params, options) {
|
|
1808
|
+
const { id, store_id } = params;
|
|
1809
|
+
const target_store_id = store_id || apiConfig.storeId;
|
|
1810
|
+
return apiConfig.httpClient.get(
|
|
1811
|
+
`/v1/stores/${target_store_id}/taxonomies/${id}/children`,
|
|
1812
|
+
options
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
};
|
|
1817
|
+
|
|
1818
|
+
// src/api/analytics.ts
|
|
1819
|
+
var createAnalyticsApi = (apiConfig) => {
|
|
1820
|
+
return {
|
|
1821
|
+
async query(spec, options) {
|
|
1822
|
+
const store_id = options?.store_id || apiConfig.storeId;
|
|
1823
|
+
return apiConfig.httpClient.post(
|
|
1824
|
+
`/v1/stores/${store_id}/analytics/query`,
|
|
1825
|
+
spec,
|
|
1826
|
+
options
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
};
|
|
1831
|
+
|
|
1832
|
+
// src/utils/price.ts
|
|
1833
|
+
function formatCurrency(amount, currencyCode, locale = "en") {
|
|
1834
|
+
if (!currencyCode) return "";
|
|
1835
|
+
return new Intl.NumberFormat(locale, {
|
|
1836
|
+
style: "currency",
|
|
1837
|
+
currency: currencyCode.toUpperCase()
|
|
1838
|
+
}).format(amount);
|
|
1839
|
+
}
|
|
1840
|
+
function getMinorUnits(currency) {
|
|
1841
|
+
try {
|
|
1842
|
+
const formatter = new Intl.NumberFormat("en", {
|
|
1843
|
+
style: "currency",
|
|
1844
|
+
currency: currency.toUpperCase()
|
|
1845
|
+
});
|
|
1846
|
+
const parts = formatter.formatToParts(1.11);
|
|
1847
|
+
const fractionPart = parts.find((p) => p.type === "fraction");
|
|
1848
|
+
return fractionPart?.value.length ?? 2;
|
|
1849
|
+
} catch {
|
|
1850
|
+
return 2;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
function convertToMajor(minorAmount, currency) {
|
|
1854
|
+
const units = getMinorUnits(currency);
|
|
1855
|
+
return minorAmount / Math.pow(10, units);
|
|
1856
|
+
}
|
|
1857
|
+
function getCurrencySymbol(currency) {
|
|
1858
|
+
try {
|
|
1859
|
+
return new Intl.NumberFormat("en", {
|
|
1860
|
+
style: "currency",
|
|
1861
|
+
currency: currency.toUpperCase(),
|
|
1862
|
+
currencyDisplay: "narrowSymbol"
|
|
1863
|
+
}).formatToParts(0).find((p) => p.type === "currency")?.value || currency.toUpperCase();
|
|
1864
|
+
} catch {
|
|
1865
|
+
return currency.toUpperCase();
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
function getCurrencyName(currency) {
|
|
1869
|
+
try {
|
|
1870
|
+
return new Intl.DisplayNames(["en"], { type: "currency" }).of(currency.toUpperCase()) || currency.toUpperCase();
|
|
1871
|
+
} catch {
|
|
1872
|
+
return currency.toUpperCase();
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
function formatMinor(amountMinor, currency) {
|
|
1876
|
+
if (!currency) return "";
|
|
1877
|
+
return formatCurrency(convertToMajor(amountMinor, currency), currency);
|
|
1878
|
+
}
|
|
1879
|
+
function formatPayment(payment) {
|
|
1880
|
+
return formatMinor(payment.total, payment.currency);
|
|
1881
|
+
}
|
|
1882
|
+
function formatPrice(prices, marketId) {
|
|
1883
|
+
if (!prices || prices.length === 0) return "";
|
|
1884
|
+
const price = marketId ? prices.find((p) => p.market === marketId) || prices[0] : prices[0];
|
|
1885
|
+
if (!price) return "";
|
|
1886
|
+
return formatMinor(price.amount, price.currency);
|
|
1887
|
+
}
|
|
1888
|
+
function getPriceAmount(prices, marketId) {
|
|
1889
|
+
if (!prices || prices.length === 0) return 0;
|
|
1890
|
+
const price = prices.find((p) => p.market === marketId) || prices[0];
|
|
1891
|
+
return price?.amount || 0;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// src/utils/validation.ts
|
|
1895
|
+
function validatePhoneNumber(phone) {
|
|
1896
|
+
if (!phone) {
|
|
1897
|
+
return { isValid: false, error: "Phone number is required" };
|
|
1898
|
+
}
|
|
1899
|
+
const cleaned = phone.replace(/\D/g, "");
|
|
1900
|
+
if (cleaned.length < 8) {
|
|
1901
|
+
return { isValid: false, error: "Phone number is too short" };
|
|
1902
|
+
}
|
|
1903
|
+
if (cleaned.length > 15) {
|
|
1904
|
+
return { isValid: false, error: "Phone number is too long" };
|
|
1905
|
+
}
|
|
1906
|
+
return { isValid: true };
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
// src/utils/timezone.ts
|
|
1910
|
+
var tzGroups = [
|
|
1911
|
+
{
|
|
1912
|
+
label: "US",
|
|
1913
|
+
zones: [
|
|
1914
|
+
{ label: "Eastern Time", value: "America/New_York" },
|
|
1915
|
+
{ label: "Central Time", value: "America/Chicago" },
|
|
1916
|
+
{ label: "Mountain Time", value: "America/Denver" },
|
|
1917
|
+
{ label: "Pacific Time", value: "America/Los_Angeles" }
|
|
1918
|
+
]
|
|
1919
|
+
},
|
|
1920
|
+
{
|
|
1921
|
+
label: "Europe",
|
|
1922
|
+
zones: [
|
|
1923
|
+
{ label: "London", value: "Europe/London" },
|
|
1924
|
+
{ label: "Paris", value: "Europe/Paris" },
|
|
1925
|
+
{ label: "Berlin", value: "Europe/Berlin" },
|
|
1926
|
+
{ label: "Rome", value: "Europe/Rome" }
|
|
1927
|
+
]
|
|
1928
|
+
},
|
|
1929
|
+
{
|
|
1930
|
+
label: "Asia",
|
|
1931
|
+
zones: [
|
|
1932
|
+
{ label: "Tokyo", value: "Asia/Tokyo" },
|
|
1933
|
+
{ label: "Shanghai", value: "Asia/Shanghai" },
|
|
1934
|
+
{ label: "Mumbai", value: "Asia/Kolkata" },
|
|
1935
|
+
{ label: "Dubai", value: "Asia/Dubai" }
|
|
1936
|
+
]
|
|
1937
|
+
}
|
|
1938
|
+
];
|
|
1939
|
+
function findTimeZone(groups) {
|
|
1940
|
+
try {
|
|
1941
|
+
const detected = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1942
|
+
for (const group of groups) {
|
|
1943
|
+
for (const zone of group.zones) {
|
|
1944
|
+
if (zone.value === detected) {
|
|
1945
|
+
return detected;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
return "UTC";
|
|
1950
|
+
} catch (e) {
|
|
1951
|
+
return "UTC";
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
// src/utils/text.ts
|
|
1956
|
+
var locales = ["en", "sr-latn"];
|
|
1957
|
+
var localeMap = {
|
|
1958
|
+
"en": "en-US",
|
|
1959
|
+
"sr-latn": "sr-RS"
|
|
1960
|
+
};
|
|
1961
|
+
function slugify(text) {
|
|
1962
|
+
return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
1963
|
+
}
|
|
1964
|
+
function humanize(text) {
|
|
1965
|
+
const slugifiedText = slugify(text);
|
|
1966
|
+
return slugifiedText.replace(/-/g, " ").replace(
|
|
1967
|
+
/\w\S*/g,
|
|
1968
|
+
(w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
|
|
1969
|
+
);
|
|
1970
|
+
}
|
|
1971
|
+
function categorify(text) {
|
|
1972
|
+
const slugifiedText = slugify(text);
|
|
1973
|
+
return slugifiedText.replace(/-/g, " ").toUpperCase();
|
|
1974
|
+
}
|
|
1975
|
+
function formatDate(date, locale) {
|
|
1976
|
+
let localeString = "en-US";
|
|
1977
|
+
if (locales.includes(locale)) {
|
|
1978
|
+
localeString = localeMap[locale];
|
|
1979
|
+
}
|
|
1980
|
+
return new Date(date).toLocaleDateString(localeString, {
|
|
1981
|
+
timeZone: "UTC",
|
|
1982
|
+
year: "numeric",
|
|
1983
|
+
month: "short",
|
|
1984
|
+
day: "numeric"
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// src/utils/svg.ts
|
|
1989
|
+
async function fetchSvgContent(mediaObject) {
|
|
1990
|
+
if (!mediaObject) return null;
|
|
1991
|
+
const svgUrl = getImageUrl(mediaObject, false);
|
|
1992
|
+
try {
|
|
1993
|
+
const response = await fetch(svgUrl);
|
|
1994
|
+
if (!response.ok) {
|
|
1995
|
+
console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
|
|
1996
|
+
return null;
|
|
1997
|
+
}
|
|
1998
|
+
const svgContent = await response.text();
|
|
1999
|
+
return svgContent;
|
|
2000
|
+
} catch (error) {
|
|
2001
|
+
console.error("Error fetching SVG:", error);
|
|
2002
|
+
return null;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
async function getSvgContentForAstro(mediaObject) {
|
|
2006
|
+
try {
|
|
2007
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
2008
|
+
return svgContent || "";
|
|
2009
|
+
} catch (error) {
|
|
2010
|
+
console.error("Error getting SVG content for Astro:", error);
|
|
2011
|
+
return "";
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
async function injectSvgIntoElement(mediaObject, targetElement, className) {
|
|
2015
|
+
if (!targetElement) return;
|
|
2016
|
+
try {
|
|
2017
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
2018
|
+
if (svgContent) {
|
|
2019
|
+
targetElement.innerHTML = svgContent;
|
|
2020
|
+
if (className) {
|
|
2021
|
+
const svgElement = targetElement.querySelector("svg");
|
|
2022
|
+
if (svgElement) {
|
|
2023
|
+
svgElement.classList.add(...className.split(" "));
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
} catch (error) {
|
|
2028
|
+
console.error("Error injecting SVG:", error);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
// src/utils/keyValidation.ts
|
|
2033
|
+
var KEY_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
2034
|
+
function isValidKey(key) {
|
|
2035
|
+
if (!key || key.length === 0) return false;
|
|
2036
|
+
return KEY_PATTERN.test(key);
|
|
2037
|
+
}
|
|
2038
|
+
function validateKey(key) {
|
|
2039
|
+
if (!key || key.length === 0) {
|
|
2040
|
+
return { valid: false, error: "Key is required" };
|
|
2041
|
+
}
|
|
2042
|
+
if (key.length > 255) {
|
|
2043
|
+
return { valid: false, error: "Key must be 255 characters or less" };
|
|
2044
|
+
}
|
|
2045
|
+
if (!KEY_PATTERN.test(key)) {
|
|
2046
|
+
return {
|
|
2047
|
+
valid: false,
|
|
2048
|
+
error: "Key can only contain letters, numbers, underscores (_) and hyphens (-)"
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
return { valid: true };
|
|
2052
|
+
}
|
|
2053
|
+
function toKey(input) {
|
|
2054
|
+
if (!input) return "";
|
|
2055
|
+
return input.toLowerCase().trim().replace(/\s+/g, "_").replace(/[^a-z0-9_-]/g, "").replace(/^[-_]+|[-_]+$/g, "").replace(/[-_]{2,}/g, "_");
|
|
2056
|
+
}
|
|
2057
|
+
function nameToKey(name) {
|
|
2058
|
+
return toKey(name);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
// src/utils/inventory.ts
|
|
2062
|
+
function getAvailableStock(variant) {
|
|
2063
|
+
if (!variant?.inventory) return 0;
|
|
2064
|
+
return variant.inventory.reduce((sum, inv) => sum + inv.available, 0);
|
|
2065
|
+
}
|
|
2066
|
+
function getReservedStock(variant) {
|
|
2067
|
+
if (!variant?.inventory) return 0;
|
|
2068
|
+
return variant.inventory.reduce((sum, inv) => sum + inv.reserved, 0);
|
|
2069
|
+
}
|
|
2070
|
+
function hasStock(variant, quantity = 1) {
|
|
2071
|
+
return getAvailableStock(variant) >= quantity;
|
|
2072
|
+
}
|
|
2073
|
+
function getInventoryAt(variant, locationId) {
|
|
2074
|
+
return variant?.inventory?.find((inv) => inv.location_id === locationId);
|
|
2075
|
+
}
|
|
2076
|
+
function getFirstAvailableFCId(variant, quantity = 1) {
|
|
2077
|
+
const inv = variant?.inventory?.find((i) => i.available >= quantity);
|
|
2078
|
+
return inv?.location_id;
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
// src/index.ts
|
|
2082
|
+
function createUtilitySurface(apiConfig) {
|
|
2083
|
+
return {
|
|
2084
|
+
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock),
|
|
2085
|
+
getBlockValue,
|
|
2086
|
+
getBlockTextValue,
|
|
2087
|
+
getBlockValues,
|
|
2088
|
+
getBlockLabel,
|
|
2089
|
+
getBlockObjectValues,
|
|
2090
|
+
getBlockFromArray,
|
|
2091
|
+
formatBlockValue,
|
|
2092
|
+
prepareBlocksForSubmission,
|
|
2093
|
+
extractBlockValues,
|
|
2094
|
+
formatPrice: (prices) => formatPrice(prices, apiConfig.market),
|
|
2095
|
+
getPriceAmount: (prices) => getPriceAmount(prices, apiConfig.market),
|
|
2096
|
+
formatPayment,
|
|
2097
|
+
formatMinor,
|
|
2098
|
+
getCurrencySymbol,
|
|
2099
|
+
getCurrencyName,
|
|
2100
|
+
validatePhoneNumber,
|
|
2101
|
+
tzGroups,
|
|
2102
|
+
findTimeZone,
|
|
2103
|
+
slugify,
|
|
2104
|
+
humanize,
|
|
2105
|
+
categorify,
|
|
2106
|
+
formatDate,
|
|
2107
|
+
getSvgContentForAstro,
|
|
2108
|
+
fetchSvgContent,
|
|
2109
|
+
injectSvgIntoElement,
|
|
2110
|
+
isValidKey,
|
|
2111
|
+
validateKey,
|
|
2112
|
+
toKey,
|
|
2113
|
+
nameToKey,
|
|
2114
|
+
getAvailableStock,
|
|
2115
|
+
getReservedStock,
|
|
2116
|
+
hasStock,
|
|
2117
|
+
getInventoryAt,
|
|
2118
|
+
getFirstAvailableFCId
|
|
2119
|
+
};
|
|
2120
|
+
}
|
|
2121
|
+
function createAdmin(config) {
|
|
2122
|
+
const locale = config.locale || "en";
|
|
2123
|
+
const getToken = config.getToken || defaultGetToken;
|
|
2124
|
+
const setToken = config.setToken || defaultSetToken;
|
|
2125
|
+
const logout = config.logout || defaultLogout;
|
|
2126
|
+
const isAuthenticated = config.isAuthenticated || defaultIsAuthenticated;
|
|
2127
|
+
const httpClient = createHttpClient({ ...config, getToken, setToken, logout });
|
|
2128
|
+
const apiConfig = {
|
|
2129
|
+
httpClient,
|
|
2130
|
+
storeId: config.storeId,
|
|
2131
|
+
baseUrl: config.baseUrl,
|
|
2132
|
+
market: config.market,
|
|
2133
|
+
locale,
|
|
2134
|
+
setToken,
|
|
2135
|
+
getToken
|
|
2136
|
+
};
|
|
2137
|
+
const accountApi = createAccountApi(apiConfig);
|
|
2138
|
+
const authApi = createAuthApi(apiConfig);
|
|
2139
|
+
const storeApi = createStoreApi(apiConfig);
|
|
2140
|
+
const platformApi = createPlatformApi(apiConfig);
|
|
2141
|
+
const cmsApi = createCmsApi(apiConfig);
|
|
2142
|
+
const eshopApi = createEshopApi(apiConfig);
|
|
2143
|
+
const bookingApi = createBookingApi(apiConfig);
|
|
2144
|
+
const crmApi = createCustomerApi(apiConfig);
|
|
2145
|
+
const locationApi = createLocationApi(apiConfig);
|
|
2146
|
+
const marketApi = createMarketApi(apiConfig);
|
|
2147
|
+
const agentApi = createAgentApi(apiConfig);
|
|
2148
|
+
const workflowApi = createWorkflowApi(apiConfig);
|
|
2149
|
+
const formApi = createFormApi(apiConfig);
|
|
2150
|
+
const taxonomyApi = createTaxonomyApi(apiConfig);
|
|
2151
|
+
const emailTemplateApi = createEmailTemplateApi(apiConfig);
|
|
2152
|
+
const analyticsApi = createAnalyticsApi(apiConfig);
|
|
2153
|
+
const sdk = {
|
|
2154
|
+
auth: authApi,
|
|
2155
|
+
account: accountApi,
|
|
2156
|
+
store: {
|
|
2157
|
+
...storeApi,
|
|
2158
|
+
location: locationApi,
|
|
2159
|
+
market: marketApi
|
|
2160
|
+
},
|
|
2161
|
+
media: createMediaApi(apiConfig),
|
|
2162
|
+
notification: createNotificationApi(apiConfig),
|
|
2163
|
+
promoCode: createPromoCodeApi(apiConfig),
|
|
2164
|
+
platform: platformApi,
|
|
2165
|
+
shipping: createShippingApi(apiConfig),
|
|
2166
|
+
cms: {
|
|
2167
|
+
node: {
|
|
2168
|
+
create: cmsApi.createNode,
|
|
2169
|
+
update: cmsApi.updateNode,
|
|
2170
|
+
delete: cmsApi.deleteNode,
|
|
2171
|
+
get: cmsApi.getNode,
|
|
2172
|
+
find: cmsApi.getNodes,
|
|
2173
|
+
getChildren: cmsApi.getNodeChildren
|
|
2174
|
+
},
|
|
2175
|
+
form: {
|
|
2176
|
+
create: formApi.createForm,
|
|
2177
|
+
update: formApi.updateForm,
|
|
2178
|
+
delete: formApi.deleteForm,
|
|
2179
|
+
get: formApi.getForm,
|
|
2180
|
+
find: formApi.getForms,
|
|
2181
|
+
submit: formApi.submit,
|
|
2182
|
+
getSubmissions: formApi.getSubmissions,
|
|
2183
|
+
getSubmission: formApi.getSubmission,
|
|
2184
|
+
updateSubmission: formApi.updateSubmission
|
|
2185
|
+
},
|
|
2186
|
+
taxonomy: {
|
|
2187
|
+
create: taxonomyApi.createTaxonomy,
|
|
2188
|
+
update: taxonomyApi.updateTaxonomy,
|
|
2189
|
+
delete: taxonomyApi.deleteTaxonomy,
|
|
2190
|
+
get: taxonomyApi.getTaxonomy,
|
|
2191
|
+
find: taxonomyApi.getTaxonomies,
|
|
2192
|
+
getChildren: taxonomyApi.getTaxonomyChildren
|
|
2193
|
+
},
|
|
2194
|
+
emailTemplate: {
|
|
2195
|
+
create: emailTemplateApi.createEmailTemplate,
|
|
2196
|
+
update: emailTemplateApi.updateEmailTemplate,
|
|
2197
|
+
delete: emailTemplateApi.deleteEmailTemplate,
|
|
2198
|
+
get: emailTemplateApi.getEmailTemplate,
|
|
2199
|
+
find: emailTemplateApi.getEmailTemplates
|
|
2200
|
+
}
|
|
2201
|
+
},
|
|
2202
|
+
eshop: {
|
|
2203
|
+
product: {
|
|
2204
|
+
create: eshopApi.createProduct,
|
|
2205
|
+
update: eshopApi.updateProduct,
|
|
2206
|
+
delete: eshopApi.deleteProduct,
|
|
2207
|
+
get: eshopApi.getProduct,
|
|
2208
|
+
find: eshopApi.getProducts
|
|
2209
|
+
},
|
|
2210
|
+
order: {
|
|
2211
|
+
create: eshopApi.createOrder,
|
|
2212
|
+
update: eshopApi.updateOrder,
|
|
2213
|
+
get: eshopApi.getOrder,
|
|
2214
|
+
find: eshopApi.getOrders,
|
|
2215
|
+
getQuote: eshopApi.getQuote,
|
|
2216
|
+
processRefund: eshopApi.processRefund
|
|
2217
|
+
}
|
|
2218
|
+
},
|
|
2219
|
+
booking: {
|
|
2220
|
+
addToCart: bookingApi.addToCart,
|
|
2221
|
+
removeFromCart: bookingApi.removeFromCart,
|
|
2222
|
+
getCart: bookingApi.getCart,
|
|
2223
|
+
clearCart: bookingApi.clearCart,
|
|
2224
|
+
create: bookingApi.createBooking,
|
|
2225
|
+
update: bookingApi.updateBooking,
|
|
2226
|
+
get: bookingApi.getBooking,
|
|
2227
|
+
find: bookingApi.searchBookings,
|
|
2228
|
+
getQuote: bookingApi.getQuote,
|
|
2229
|
+
processRefund: bookingApi.processRefund,
|
|
2230
|
+
getAvailability: bookingApi.getAvailability,
|
|
2231
|
+
cancelItem: bookingApi.cancelBookingItem,
|
|
2232
|
+
service: {
|
|
2233
|
+
create: bookingApi.createService,
|
|
2234
|
+
update: bookingApi.updateService,
|
|
2235
|
+
delete: bookingApi.deleteService,
|
|
2236
|
+
get: bookingApi.getService,
|
|
2237
|
+
find: bookingApi.getServices,
|
|
2238
|
+
findProviders: bookingApi.findServiceProviders,
|
|
2239
|
+
createProvider: bookingApi.createServiceProvider,
|
|
2240
|
+
updateProvider: bookingApi.updateServiceProvider,
|
|
2241
|
+
deleteProvider: bookingApi.deleteServiceProvider
|
|
2242
|
+
},
|
|
2243
|
+
provider: {
|
|
2244
|
+
create: bookingApi.createProvider,
|
|
2245
|
+
update: bookingApi.updateProvider,
|
|
2246
|
+
delete: bookingApi.deleteProvider,
|
|
2247
|
+
get: bookingApi.getProvider,
|
|
2248
|
+
find: bookingApi.getProviders
|
|
2249
|
+
}
|
|
2250
|
+
},
|
|
2251
|
+
crm: {
|
|
2252
|
+
customer: {
|
|
2253
|
+
create: crmApi.create,
|
|
2254
|
+
get: crmApi.get,
|
|
2255
|
+
find: crmApi.find,
|
|
2256
|
+
update: crmApi.update,
|
|
2257
|
+
merge: crmApi.merge,
|
|
2258
|
+
revokeToken: crmApi.revokeToken,
|
|
2259
|
+
revokeAllTokens: crmApi.revokeAllTokens
|
|
2260
|
+
},
|
|
2261
|
+
audience: {
|
|
2262
|
+
create: crmApi.audiences.create,
|
|
2263
|
+
update: crmApi.audiences.update,
|
|
2264
|
+
get: crmApi.audiences.get,
|
|
2265
|
+
find: crmApi.audiences.find,
|
|
2266
|
+
getSubscribers: crmApi.audiences.getSubscribers,
|
|
2267
|
+
addSubscriber: crmApi.audiences.addSubscriber,
|
|
2268
|
+
removeSubscriber: crmApi.audiences.removeSubscriber
|
|
2269
|
+
},
|
|
2270
|
+
activity: crmApi.activity
|
|
2271
|
+
},
|
|
2272
|
+
automation: {
|
|
2273
|
+
agent: {
|
|
2274
|
+
create: agentApi.createAgent,
|
|
2275
|
+
update: agentApi.updateAgent,
|
|
2276
|
+
delete: agentApi.deleteAgent,
|
|
2277
|
+
get: agentApi.getAgent,
|
|
2278
|
+
find: agentApi.getAgents,
|
|
2279
|
+
sendMessage: agentApi.sendMessage,
|
|
2280
|
+
getChats: agentApi.getChats,
|
|
2281
|
+
getChat: agentApi.getChat,
|
|
2282
|
+
updateChat: agentApi.updateChat,
|
|
2283
|
+
rateChat: agentApi.rateChat,
|
|
2284
|
+
getStoreChats: agentApi.getStoreChats,
|
|
2285
|
+
getChatMessages: agentApi.getChatMessages
|
|
2286
|
+
},
|
|
2287
|
+
workflow: {
|
|
2288
|
+
create: workflowApi.createWorkflow,
|
|
2289
|
+
update: workflowApi.updateWorkflow,
|
|
2290
|
+
delete: workflowApi.deleteWorkflow,
|
|
2291
|
+
get: workflowApi.getWorkflow,
|
|
2292
|
+
find: workflowApi.getWorkflows,
|
|
2293
|
+
trigger: workflowApi.triggerWorkflow,
|
|
2294
|
+
getExecutions: workflowApi.getWorkflowExecutions,
|
|
2295
|
+
getExecution: workflowApi.getWorkflowExecution
|
|
2296
|
+
}
|
|
2297
|
+
},
|
|
2298
|
+
analytics: {
|
|
2299
|
+
query: analyticsApi.query
|
|
2300
|
+
},
|
|
2301
|
+
setStoreId: (storeId) => {
|
|
2302
|
+
apiConfig.storeId = storeId;
|
|
2303
|
+
},
|
|
2304
|
+
getStoreId: () => apiConfig.storeId,
|
|
2305
|
+
setMarket: (market) => {
|
|
2306
|
+
apiConfig.market = market;
|
|
2307
|
+
},
|
|
2308
|
+
getMarket: () => apiConfig.market,
|
|
2309
|
+
setLocale: (locale2) => {
|
|
2310
|
+
apiConfig.locale = locale2;
|
|
2311
|
+
},
|
|
2312
|
+
getLocale: () => apiConfig.locale,
|
|
2313
|
+
isAuthenticated,
|
|
2314
|
+
logout,
|
|
2315
|
+
setToken,
|
|
2316
|
+
extractBlockValues,
|
|
2317
|
+
utils: createUtilitySurface(apiConfig)
|
|
2318
|
+
};
|
|
2319
|
+
return sdk;
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
exports.createAdmin = createAdmin;
|
|
2323
|
+
//# sourceMappingURL=admin.cjs.map
|
|
2324
|
+
//# sourceMappingURL=admin.cjs.map
|