arky-sdk 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +919 -1138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -192
- package/dist/index.d.ts +21 -192
- package/dist/index.js +920 -1075
- package/dist/index.js.map +1 -1
- package/dist/{index-DEmVFs0E.d.ts → svg-BhIM4HZW.d.ts} +37 -164
- package/dist/{index-DOEos-hV.d.cts → svg-CFjyTGXu.d.cts} +37 -164
- package/dist/utils.d.cts +122 -1
- package/dist/utils.d.ts +122 -1
- package/package.json +1 -11
package/dist/index.js
CHANGED
|
@@ -1,862 +1,1018 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
// src/utils/errors.ts
|
|
2
|
+
var convertServerErrorToRequestError = (serverError, renameRules) => {
|
|
3
|
+
return {
|
|
4
|
+
...serverError,
|
|
5
|
+
validationErrors: serverError.validationErrors.map((validationError) => {
|
|
6
|
+
const field = validationError.field;
|
|
7
|
+
return {
|
|
8
|
+
field,
|
|
9
|
+
error: validationError.error || "GENERAL.VALIDATION_ERROR"
|
|
10
|
+
};
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
};
|
|
8
14
|
|
|
9
|
-
// src/
|
|
10
|
-
|
|
15
|
+
// src/utils/queryParams.ts
|
|
16
|
+
function buildQueryString(params) {
|
|
17
|
+
const queryParts = [];
|
|
18
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
19
|
+
if (value === null || value === void 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
const jsonString = JSON.stringify(value);
|
|
24
|
+
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
25
|
+
} else if (typeof value === "string") {
|
|
26
|
+
queryParts.push(`${key}=${encodeURIComponent(value)}`);
|
|
27
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
28
|
+
queryParts.push(`${key}=${value}`);
|
|
29
|
+
} else if (typeof value === "object") {
|
|
30
|
+
const jsonString = JSON.stringify(value);
|
|
31
|
+
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/services/createHttpClient.ts
|
|
38
|
+
function createHttpClient(cfg) {
|
|
39
|
+
const refreshEndpoint = `${cfg.baseUrl}/v1/users/refresh-access-token`;
|
|
40
|
+
let refreshPromise = null;
|
|
41
|
+
async function ensureFreshToken() {
|
|
42
|
+
if (refreshPromise) {
|
|
43
|
+
return refreshPromise;
|
|
44
|
+
}
|
|
45
|
+
refreshPromise = (async () => {
|
|
46
|
+
const { refreshToken, provider } = await cfg.getToken();
|
|
47
|
+
if (!refreshToken) {
|
|
48
|
+
cfg.logout();
|
|
49
|
+
const err = new Error("No refresh token available");
|
|
50
|
+
err.name = "ApiError";
|
|
51
|
+
err.statusCode = 401;
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
const refRes = await fetch(refreshEndpoint, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify({ provider, refreshToken })
|
|
58
|
+
});
|
|
59
|
+
if (!refRes.ok) {
|
|
60
|
+
cfg.logout();
|
|
61
|
+
const err = new Error("Token refresh failed");
|
|
62
|
+
err.name = "ApiError";
|
|
63
|
+
err.statusCode = 401;
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
const data = await refRes.json();
|
|
67
|
+
cfg.setToken(data);
|
|
68
|
+
})().finally(() => {
|
|
69
|
+
refreshPromise = null;
|
|
70
|
+
});
|
|
71
|
+
return refreshPromise;
|
|
72
|
+
}
|
|
73
|
+
async function request(method, path, body, options) {
|
|
74
|
+
if (options?.transformRequest) {
|
|
75
|
+
body = options.transformRequest(body);
|
|
76
|
+
}
|
|
77
|
+
const headers = {
|
|
78
|
+
Accept: "application/json",
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
...options?.headers || {}
|
|
81
|
+
};
|
|
82
|
+
let { accessToken, expiresAt } = await cfg.getToken();
|
|
83
|
+
const nowSec = Date.now() / 1e3;
|
|
84
|
+
if (expiresAt && nowSec > expiresAt) {
|
|
85
|
+
await ensureFreshToken();
|
|
86
|
+
const tokens = await cfg.getToken();
|
|
87
|
+
accessToken = tokens.accessToken;
|
|
88
|
+
}
|
|
89
|
+
if (accessToken) {
|
|
90
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
91
|
+
}
|
|
92
|
+
const finalPath = options?.params ? path + buildQueryString(options.params) : path;
|
|
93
|
+
const fetchOpts = { method, headers };
|
|
94
|
+
if (!["GET", "DELETE"].includes(method) && body !== void 0) {
|
|
95
|
+
fetchOpts.body = JSON.stringify(body);
|
|
96
|
+
}
|
|
97
|
+
const fullUrl = `${cfg.baseUrl}${finalPath}`;
|
|
98
|
+
let res;
|
|
99
|
+
let data;
|
|
100
|
+
try {
|
|
101
|
+
res = await fetch(fullUrl, fetchOpts);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const err = new Error(error instanceof Error ? error.message : "Network request failed");
|
|
104
|
+
err.name = "NetworkError";
|
|
105
|
+
err.method = method;
|
|
106
|
+
err.url = fullUrl;
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
if (res.status === 401 && !options?.["_retried"]) {
|
|
110
|
+
try {
|
|
111
|
+
await ensureFreshToken();
|
|
112
|
+
const tokens = await cfg.getToken();
|
|
113
|
+
headers["Authorization"] = `Bearer ${tokens.accessToken}`;
|
|
114
|
+
fetchOpts.headers = headers;
|
|
115
|
+
return request(method, path, body, { ...options, _retried: true });
|
|
116
|
+
} catch (refreshError) {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const contentLength = res.headers.get("content-length");
|
|
121
|
+
const contentType = res.headers.get("content-type");
|
|
122
|
+
if (res.status === 204 || contentLength === "0" || !contentType?.includes("application/json")) {
|
|
123
|
+
data = {};
|
|
124
|
+
} else {
|
|
125
|
+
data = await res.json();
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const err = new Error("Failed to parse response");
|
|
129
|
+
err.name = "ParseError";
|
|
130
|
+
err.method = method;
|
|
131
|
+
err.url = fullUrl;
|
|
132
|
+
err.status = res.status;
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
if (!res.ok) {
|
|
136
|
+
const serverErr = data;
|
|
137
|
+
const reqErr = convertServerErrorToRequestError(serverErr);
|
|
138
|
+
if (options?.errorMessage && cfg.notify) {
|
|
139
|
+
cfg.notify({ message: options.errorMessage, type: "error" });
|
|
140
|
+
}
|
|
141
|
+
const err = new Error(serverErr.message || "Request failed");
|
|
142
|
+
err.name = "ApiError";
|
|
143
|
+
err.statusCode = serverErr.statusCode || res.status;
|
|
144
|
+
err.validationErrors = reqErr.validationErrors;
|
|
145
|
+
err.method = method;
|
|
146
|
+
err.url = fullUrl;
|
|
147
|
+
const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
|
|
148
|
+
if (requestId) err.requestId = requestId;
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
151
|
+
if (options?.successMessage && cfg.notify) {
|
|
152
|
+
cfg.notify({ message: options.successMessage, type: "success" });
|
|
153
|
+
}
|
|
154
|
+
return data;
|
|
155
|
+
}
|
|
11
156
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
157
|
+
get: (path, opts) => request("GET", path, void 0, opts),
|
|
158
|
+
post: (path, body, opts) => request("POST", path, body, opts),
|
|
159
|
+
put: (path, body, opts) => request("PUT", path, body, opts),
|
|
160
|
+
patch: (path, body, opts) => request("PATCH", path, body, opts),
|
|
161
|
+
delete: (path, opts) => request("DELETE", path, void 0, opts)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/api/user.ts
|
|
166
|
+
var createUserApi = (apiConfig) => {
|
|
167
|
+
return {
|
|
168
|
+
// ===== USER PROFILE =====
|
|
169
|
+
async updateUser(params, options) {
|
|
170
|
+
const payload = {
|
|
171
|
+
name: params.name,
|
|
172
|
+
phoneNumbers: params.phoneNumbers || [],
|
|
173
|
+
phoneNumber: params.phoneNumber || null,
|
|
174
|
+
addresses: params.addresses || [],
|
|
175
|
+
...params.apiTokens !== void 0 && { apiTokens: params.apiTokens }
|
|
176
|
+
};
|
|
177
|
+
return apiConfig.httpClient.put("/v1/users/update", payload, options);
|
|
178
|
+
},
|
|
179
|
+
async updateProfilePhone(params, options) {
|
|
180
|
+
const payload = {
|
|
181
|
+
phoneNumbers: [],
|
|
182
|
+
phoneNumber: params.phoneNumber,
|
|
183
|
+
addresses: []
|
|
184
|
+
};
|
|
185
|
+
return apiConfig.httpClient.put("/v1/users/update", payload, options);
|
|
186
|
+
},
|
|
187
|
+
async verifyPhoneCode(params, options) {
|
|
188
|
+
return apiConfig.httpClient.put("/v1/users/confirm/phone-number", params, options);
|
|
189
|
+
},
|
|
190
|
+
async getUserLocation(options) {
|
|
191
|
+
return apiConfig.httpClient.get("/v1/users/location", options);
|
|
192
|
+
},
|
|
193
|
+
async getMe(options) {
|
|
194
|
+
return apiConfig.httpClient.get("/v1/users/me", options);
|
|
195
|
+
},
|
|
196
|
+
async searchUsers(params, options) {
|
|
197
|
+
return apiConfig.httpClient.get("/v1/users/search", {
|
|
198
|
+
...options,
|
|
199
|
+
params
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
async setUserRole(params, options) {
|
|
203
|
+
return apiConfig.httpClient.put("/v1/users/set-role", params, options);
|
|
204
|
+
},
|
|
205
|
+
// ===== AUTHENTICATION =====
|
|
206
|
+
async loginUser(params, options) {
|
|
207
|
+
return apiConfig.httpClient.post("/v1/users/login", params, options);
|
|
208
|
+
},
|
|
209
|
+
async registerUser(params, options) {
|
|
210
|
+
return apiConfig.httpClient.post("/v1/users/register", params, options);
|
|
211
|
+
},
|
|
212
|
+
async logout(options) {
|
|
213
|
+
return apiConfig.httpClient.post("/v1/users/logout", {}, options);
|
|
214
|
+
},
|
|
215
|
+
async confirmUser(params, options) {
|
|
216
|
+
return apiConfig.httpClient.put("/v1/users/confirm", params, options);
|
|
217
|
+
},
|
|
218
|
+
async getLoginUrl(params, options) {
|
|
219
|
+
return apiConfig.httpClient.get("/v1/users/login/url", {
|
|
220
|
+
...options,
|
|
221
|
+
params
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
async getGuestToken(params, options) {
|
|
225
|
+
if (params.existingToken) {
|
|
226
|
+
return params.existingToken;
|
|
227
|
+
}
|
|
228
|
+
const result = await apiConfig.httpClient.post("/v1/users/login", {
|
|
229
|
+
provider: "GUEST"
|
|
230
|
+
}, options);
|
|
231
|
+
const token = result.accessToken || result.token || "";
|
|
232
|
+
if (token) {
|
|
233
|
+
apiConfig.setTokens(result);
|
|
234
|
+
}
|
|
235
|
+
return token;
|
|
236
|
+
},
|
|
237
|
+
// ===== PASSWORD MANAGEMENT =====
|
|
238
|
+
async forgotPassword(params, options) {
|
|
239
|
+
return apiConfig.httpClient.post("/v1/users/forgot-password", params, options);
|
|
240
|
+
},
|
|
241
|
+
async resetForgotPassword(params, options) {
|
|
242
|
+
return apiConfig.httpClient.post("/v1/users/reset-forgot-password", params, options);
|
|
243
|
+
},
|
|
244
|
+
async resetPassword(params, options) {
|
|
245
|
+
return apiConfig.httpClient.post("/v1/users/reset-password", params, options);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// src/api/business.ts
|
|
251
|
+
var createBusinessApi = (apiConfig) => {
|
|
252
|
+
return {
|
|
253
|
+
async createBusiness(params, options) {
|
|
254
|
+
return apiConfig.httpClient.post(`/v1/businesses`, params, options);
|
|
255
|
+
},
|
|
256
|
+
async updateBusiness(params, options) {
|
|
257
|
+
return apiConfig.httpClient.put(`/v1/businesses/${params.id}`, params, options);
|
|
258
|
+
},
|
|
259
|
+
async deleteBusiness(params, options) {
|
|
260
|
+
return apiConfig.httpClient.delete(`/v1/businesses/${params.id}`, options);
|
|
261
|
+
},
|
|
262
|
+
async getBusiness(params, options) {
|
|
263
|
+
return apiConfig.httpClient.get(`/v1/businesses/${params.id}`, options);
|
|
264
|
+
},
|
|
265
|
+
async getBusinesses(options) {
|
|
266
|
+
return apiConfig.httpClient.get(`/v1/businesses`, options);
|
|
267
|
+
},
|
|
268
|
+
async getBusinessParents(params, options) {
|
|
269
|
+
return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/parents`, options);
|
|
270
|
+
},
|
|
271
|
+
async triggerBuilds(params, options) {
|
|
272
|
+
return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
|
|
273
|
+
},
|
|
274
|
+
async getSubscriptionPlans(options) {
|
|
275
|
+
return apiConfig.httpClient.get("/v1/businesses/plans", options);
|
|
276
|
+
},
|
|
277
|
+
async getSubscription(params, options) {
|
|
278
|
+
return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/subscription`, options);
|
|
279
|
+
},
|
|
280
|
+
async createSubscription(params, options) {
|
|
14
281
|
return apiConfig.httpClient.post(
|
|
15
|
-
`/v1/businesses/${
|
|
282
|
+
`/v1/businesses/${params.businessId}/subscription`,
|
|
283
|
+
params,
|
|
284
|
+
options
|
|
285
|
+
);
|
|
286
|
+
},
|
|
287
|
+
async updateSubscription(params, options) {
|
|
288
|
+
return apiConfig.httpClient.put(
|
|
289
|
+
`/v1/businesses/${params.businessId}/subscription`,
|
|
16
290
|
params,
|
|
17
291
|
options
|
|
18
292
|
);
|
|
19
293
|
},
|
|
20
|
-
async
|
|
21
|
-
return apiConfig.httpClient.
|
|
22
|
-
|
|
294
|
+
async cancelSubscription(params, options) {
|
|
295
|
+
return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
|
|
296
|
+
...options,
|
|
297
|
+
params: { immediately: params.immediately || false }
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
async reactivateSubscription(params, options) {
|
|
301
|
+
return apiConfig.httpClient.post(
|
|
302
|
+
`/v1/businesses/${params.businessId}/subscription/reactivate`,
|
|
23
303
|
params,
|
|
24
304
|
options
|
|
25
305
|
);
|
|
26
306
|
},
|
|
27
|
-
async
|
|
28
|
-
return apiConfig.httpClient.
|
|
29
|
-
`/v1/businesses/${
|
|
307
|
+
async createPortalSession(params, options) {
|
|
308
|
+
return apiConfig.httpClient.post(
|
|
309
|
+
`/v1/businesses/${params.businessId}/subscription/portal`,
|
|
310
|
+
params,
|
|
30
311
|
options
|
|
31
312
|
);
|
|
32
313
|
},
|
|
33
|
-
async
|
|
34
|
-
|
|
35
|
-
|
|
314
|
+
async inviteUser(params, options) {
|
|
315
|
+
const { businessId, ...payload } = params;
|
|
316
|
+
return apiConfig.httpClient.post(
|
|
317
|
+
`/v1/businesses/${businessId}/invitation`,
|
|
318
|
+
payload,
|
|
36
319
|
options
|
|
37
320
|
);
|
|
38
321
|
},
|
|
39
|
-
async
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
322
|
+
async handleInvitation(params, options) {
|
|
323
|
+
const { businessId, ...payload } = params;
|
|
324
|
+
return apiConfig.httpClient.put(
|
|
325
|
+
`/v1/businesses/${businessId}/invitation`,
|
|
326
|
+
payload,
|
|
327
|
+
options
|
|
46
328
|
);
|
|
47
329
|
},
|
|
48
|
-
async
|
|
330
|
+
async testWebhook(params, options) {
|
|
49
331
|
return apiConfig.httpClient.post(
|
|
50
|
-
`/v1/businesses/${
|
|
51
|
-
params,
|
|
332
|
+
`/v1/businesses/${params.businessId}/webhooks/test`,
|
|
333
|
+
params.webhook,
|
|
52
334
|
options
|
|
53
335
|
);
|
|
54
336
|
},
|
|
55
|
-
|
|
56
|
-
// Note: Backend uses /entries NOT /collections/{id}/entries
|
|
57
|
-
async getCollectionEntries(params, options) {
|
|
58
|
-
const { collectionId, ...queryParams } = params || {};
|
|
59
|
-
const finalParams = collectionId ? { ...queryParams, owner: `collection:${collectionId}` } : queryParams;
|
|
337
|
+
async getBusinessMedia(params, options) {
|
|
60
338
|
return apiConfig.httpClient.get(
|
|
61
|
-
`/v1/businesses/${
|
|
339
|
+
`/v1/businesses/${params.id}/media`,
|
|
62
340
|
{
|
|
63
341
|
...options,
|
|
64
|
-
params:
|
|
342
|
+
params: {
|
|
343
|
+
cursor: params.cursor,
|
|
344
|
+
limit: params.limit || 20
|
|
345
|
+
}
|
|
65
346
|
}
|
|
66
347
|
);
|
|
67
348
|
},
|
|
68
|
-
async
|
|
69
|
-
const {
|
|
70
|
-
const payload = {
|
|
71
|
-
...rest,
|
|
72
|
-
owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
|
|
73
|
-
};
|
|
74
|
-
return apiConfig.httpClient.post(
|
|
75
|
-
`/v1/businesses/${apiConfig.businessId}/entries`,
|
|
76
|
-
payload,
|
|
77
|
-
options
|
|
78
|
-
);
|
|
79
|
-
},
|
|
80
|
-
async updateCollectionEntry(params, options) {
|
|
81
|
-
const { id, collectionId, owner, ...rest } = params;
|
|
82
|
-
const payload = {
|
|
83
|
-
...rest,
|
|
84
|
-
owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
|
|
85
|
-
};
|
|
349
|
+
async setProviderSchedule(params, options) {
|
|
350
|
+
const { id, ...payload } = params;
|
|
86
351
|
return apiConfig.httpClient.put(
|
|
87
|
-
`/v1/businesses/${
|
|
352
|
+
`/v1/businesses/${id}/schedules`,
|
|
88
353
|
payload,
|
|
89
354
|
options
|
|
90
355
|
);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// src/api/media.ts
|
|
361
|
+
var createMediaApi = (apiConfig) => {
|
|
362
|
+
return {
|
|
363
|
+
async uploadBusinessMedia(params) {
|
|
364
|
+
const { businessId, files = [], urls = [] } = params;
|
|
365
|
+
const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/upload`;
|
|
366
|
+
const formData = new FormData();
|
|
367
|
+
files.forEach((file) => formData.append("files", file));
|
|
368
|
+
urls.forEach((url2) => formData.append("files", url2));
|
|
369
|
+
const tokens = await apiConfig.getTokens();
|
|
370
|
+
const response = await fetch(url, {
|
|
371
|
+
method: "POST",
|
|
372
|
+
body: formData,
|
|
373
|
+
headers: {
|
|
374
|
+
Authorization: `Bearer ${tokens.accessToken}`
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
if (!response.ok) {
|
|
378
|
+
throw new Error("Upload failed, server said no");
|
|
379
|
+
}
|
|
380
|
+
return await response.json();
|
|
91
381
|
},
|
|
92
|
-
async
|
|
382
|
+
async deleteBusinessMedia(params, options) {
|
|
383
|
+
const { id, mediaId } = params;
|
|
93
384
|
return apiConfig.httpClient.delete(
|
|
94
|
-
`/v1/businesses/${
|
|
95
|
-
|
|
385
|
+
`/v1/businesses/${id}/upload`,
|
|
386
|
+
{
|
|
387
|
+
...options,
|
|
388
|
+
params: { mediaId }
|
|
389
|
+
}
|
|
96
390
|
);
|
|
97
391
|
},
|
|
98
|
-
async
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
392
|
+
async getBusinessMedia(params) {
|
|
393
|
+
const { businessId, cursor = null, limit = 20 } = params;
|
|
394
|
+
const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/media`;
|
|
395
|
+
const queryParams = { limit };
|
|
396
|
+
if (cursor) queryParams.cursor = cursor;
|
|
397
|
+
const queryString = new URLSearchParams(queryParams).toString();
|
|
398
|
+
const response = await fetch(`${url}?${queryString}`);
|
|
399
|
+
if (!response.ok) {
|
|
400
|
+
const errorData = await response.json().catch(() => null);
|
|
401
|
+
throw new Error(errorData?.message || "Failed to fetch media");
|
|
402
|
+
}
|
|
403
|
+
return await response.json();
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// src/api/role.ts
|
|
409
|
+
var createRoleApi = (apiConfig) => {
|
|
410
|
+
return {
|
|
411
|
+
async createRole(params, options) {
|
|
412
|
+
return apiConfig.httpClient.post(`/v1/roles`, params, options);
|
|
103
413
|
},
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
414
|
+
async updateRole(params, options) {
|
|
415
|
+
return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, options);
|
|
416
|
+
},
|
|
417
|
+
async deleteRole(params, options) {
|
|
418
|
+
return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
|
|
419
|
+
},
|
|
420
|
+
async getRole(params, options) {
|
|
421
|
+
return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
|
|
422
|
+
},
|
|
423
|
+
async getRoles(params, options) {
|
|
424
|
+
return apiConfig.httpClient.get(`/v1/roles`, {
|
|
425
|
+
...options,
|
|
426
|
+
params: params ? {
|
|
109
427
|
businessId: apiConfig.businessId,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
428
|
+
action: params.action || "READ"
|
|
429
|
+
} : {
|
|
430
|
+
businessId: apiConfig.businessId,
|
|
431
|
+
action: "READ"
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/api/notification.ts
|
|
439
|
+
var createNotificationApi = (apiConfig) => {
|
|
440
|
+
return {
|
|
441
|
+
async getNotifications(params, options) {
|
|
442
|
+
return apiConfig.httpClient.get(`/v1/notifications`, {
|
|
443
|
+
...options,
|
|
444
|
+
params: {
|
|
445
|
+
limit: params.limit,
|
|
446
|
+
previous_id: params.previous_id
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
},
|
|
450
|
+
async updateNotifications(options) {
|
|
451
|
+
return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
|
|
452
|
+
},
|
|
453
|
+
async trackEmailOpen(params, options) {
|
|
454
|
+
return apiConfig.httpClient.get(
|
|
455
|
+
`/v1/notifications/track/email/${params.trackingPixelId}`,
|
|
113
456
|
options
|
|
114
457
|
);
|
|
115
458
|
},
|
|
116
|
-
|
|
117
|
-
async getVariableMetadata(params, options) {
|
|
459
|
+
async getDeliveryStats(params, options) {
|
|
118
460
|
return apiConfig.httpClient.get(
|
|
119
|
-
`/v1/
|
|
461
|
+
`/v1/notifications/track/stats/${apiConfig.businessId}`,
|
|
120
462
|
options
|
|
121
463
|
);
|
|
122
464
|
}
|
|
123
465
|
};
|
|
124
466
|
};
|
|
125
467
|
|
|
126
|
-
// src/api/
|
|
127
|
-
var
|
|
468
|
+
// src/api/promoCode.ts
|
|
469
|
+
var createPromoCodeApi = (apiConfig) => {
|
|
128
470
|
return {
|
|
129
|
-
|
|
130
|
-
async createProduct(params, options) {
|
|
471
|
+
async createPromoCode(params, options) {
|
|
131
472
|
return apiConfig.httpClient.post(
|
|
132
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
473
|
+
`/v1/businesses/${apiConfig.businessId}/promo-codes`,
|
|
133
474
|
params,
|
|
134
475
|
options
|
|
135
476
|
);
|
|
136
477
|
},
|
|
137
|
-
async
|
|
478
|
+
async updatePromoCode(params, options) {
|
|
138
479
|
return apiConfig.httpClient.put(
|
|
139
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
480
|
+
`/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
|
|
140
481
|
params,
|
|
141
482
|
options
|
|
142
483
|
);
|
|
143
484
|
},
|
|
144
|
-
async
|
|
485
|
+
async deletePromoCode(params, options) {
|
|
145
486
|
return apiConfig.httpClient.delete(
|
|
146
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
487
|
+
`/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
|
|
147
488
|
options
|
|
148
489
|
);
|
|
149
490
|
},
|
|
150
|
-
async
|
|
491
|
+
async getPromoCode(params, options) {
|
|
151
492
|
return apiConfig.httpClient.get(
|
|
152
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
493
|
+
`/v1/businesses/${apiConfig.businessId}/promo-codes/${params.id}`,
|
|
153
494
|
options
|
|
154
495
|
);
|
|
155
496
|
},
|
|
156
|
-
async
|
|
157
|
-
const
|
|
158
|
-
return apiConfig.httpClient.get(
|
|
159
|
-
|
|
160
|
-
{
|
|
161
|
-
...
|
|
162
|
-
|
|
497
|
+
async getPromoCodes(params, options) {
|
|
498
|
+
const { businessId, statuses, ...restParams } = params;
|
|
499
|
+
return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/promo-codes`, {
|
|
500
|
+
...options,
|
|
501
|
+
params: {
|
|
502
|
+
...restParams,
|
|
503
|
+
statuses: statuses && statuses.length > 0 ? statuses : void 0
|
|
163
504
|
}
|
|
164
|
-
);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// src/api/analytics.ts
|
|
511
|
+
var createAnalyticsApi = (apiConfig) => {
|
|
512
|
+
return {
|
|
513
|
+
async getAnalytics(params, options) {
|
|
514
|
+
const { businessId, ...queryParams } = params;
|
|
515
|
+
return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}`, {
|
|
516
|
+
...options,
|
|
517
|
+
params: queryParams
|
|
518
|
+
});
|
|
165
519
|
},
|
|
166
|
-
|
|
167
|
-
|
|
520
|
+
async getAnalyticsHealth(params, options) {
|
|
521
|
+
return apiConfig.httpClient.get(`/v1/analytics/${apiConfig.businessId}/health`, options);
|
|
522
|
+
},
|
|
523
|
+
async setupAnalytics(params, options) {
|
|
524
|
+
return apiConfig.httpClient.post(`/v1/analytics/admin/setup`, params, options);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// src/api/cms.ts
|
|
530
|
+
var createCmsApi = (apiConfig) => {
|
|
531
|
+
return {
|
|
532
|
+
// ===== COLLECTIONS =====
|
|
533
|
+
async createCollection(params, options) {
|
|
168
534
|
return apiConfig.httpClient.post(
|
|
169
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
535
|
+
`/v1/businesses/${apiConfig.businessId}/collections`,
|
|
170
536
|
params,
|
|
171
537
|
options
|
|
172
538
|
);
|
|
173
539
|
},
|
|
174
|
-
async
|
|
540
|
+
async updateCollection(params, options) {
|
|
175
541
|
return apiConfig.httpClient.put(
|
|
176
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
542
|
+
`/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
|
|
177
543
|
params,
|
|
178
544
|
options
|
|
179
545
|
);
|
|
180
546
|
},
|
|
181
|
-
async
|
|
547
|
+
async deleteCollection(params, options) {
|
|
548
|
+
return apiConfig.httpClient.delete(
|
|
549
|
+
`/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
|
|
550
|
+
options
|
|
551
|
+
);
|
|
552
|
+
},
|
|
553
|
+
async getCollection(params, options) {
|
|
182
554
|
return apiConfig.httpClient.get(
|
|
183
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
555
|
+
`/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
|
|
184
556
|
options
|
|
185
557
|
);
|
|
186
558
|
},
|
|
187
|
-
async
|
|
559
|
+
async getCollections(params, options) {
|
|
188
560
|
return apiConfig.httpClient.get(
|
|
189
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
561
|
+
`/v1/businesses/${apiConfig.businessId}/collections`,
|
|
190
562
|
{
|
|
191
563
|
...options,
|
|
192
564
|
params: params || {}
|
|
193
565
|
}
|
|
194
566
|
);
|
|
195
567
|
},
|
|
196
|
-
async
|
|
197
|
-
return apiConfig.httpClient.
|
|
198
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
568
|
+
async generateBlocks(params, options) {
|
|
569
|
+
return apiConfig.httpClient.post(
|
|
570
|
+
`/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
|
|
199
571
|
params,
|
|
200
572
|
options
|
|
201
573
|
);
|
|
202
574
|
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
575
|
+
// ===== ENTRIES =====
|
|
576
|
+
// Note: Backend uses /entries NOT /collections/{id}/entries
|
|
577
|
+
async getCollectionEntries(params, options) {
|
|
578
|
+
const { collectionId, ...queryParams } = params || {};
|
|
579
|
+
const finalParams = collectionId ? { ...queryParams, owner: `collection:${collectionId}` } : queryParams;
|
|
580
|
+
return apiConfig.httpClient.get(
|
|
581
|
+
`/v1/businesses/${apiConfig.businessId}/entries`,
|
|
582
|
+
{
|
|
583
|
+
...options,
|
|
584
|
+
params: finalParams
|
|
585
|
+
}
|
|
208
586
|
);
|
|
209
587
|
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const lines = params.items.map((item) => ({
|
|
213
|
-
type: "PRODUCT_VARIANT",
|
|
214
|
-
productId: item.productId,
|
|
215
|
-
variantId: item.variantId,
|
|
216
|
-
quantity: item.quantity
|
|
217
|
-
}));
|
|
218
|
-
const payload = {
|
|
219
|
-
businessId: apiConfig.businessId,
|
|
220
|
-
market: apiConfig.market,
|
|
221
|
-
currency: params.currency,
|
|
222
|
-
paymentMethod: params.paymentMethod,
|
|
223
|
-
lines,
|
|
224
|
-
...params.shippingMethodId && { shippingMethodId: params.shippingMethodId },
|
|
225
|
-
...params.promoCode && { promoCode: params.promoCode }
|
|
226
|
-
};
|
|
227
|
-
return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
|
|
228
|
-
},
|
|
229
|
-
async checkout(params, options) {
|
|
588
|
+
async createCollectionEntry(params, options) {
|
|
589
|
+
const { collectionId, owner, ...rest } = params;
|
|
230
590
|
const payload = {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
paymentMethod: params.paymentMethod,
|
|
234
|
-
shippingMethodId: params.shippingMethodId,
|
|
235
|
-
items: params.items,
|
|
236
|
-
blocks: params.blocks || [],
|
|
237
|
-
...params.promoCode && { promoCode: params.promoCode }
|
|
591
|
+
...rest,
|
|
592
|
+
owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
|
|
238
593
|
};
|
|
239
594
|
return apiConfig.httpClient.post(
|
|
240
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
595
|
+
`/v1/businesses/${apiConfig.businessId}/entries`,
|
|
241
596
|
payload,
|
|
242
597
|
options
|
|
243
598
|
);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// src/api/reservation.ts
|
|
249
|
-
var createReservationApi = (apiConfig) => {
|
|
250
|
-
return {
|
|
251
|
-
// ===== RESERVATIONS =====
|
|
252
|
-
async createReservation(params, options) {
|
|
253
|
-
return apiConfig.httpClient.post(`/v1/reservations`, params, {
|
|
254
|
-
successMessage: "Reservation created successfully",
|
|
255
|
-
errorMessage: "Failed to create reservation",
|
|
256
|
-
...options
|
|
257
|
-
});
|
|
258
|
-
},
|
|
259
|
-
async updateReservation(params, options) {
|
|
260
|
-
const { id, ...payload } = params;
|
|
261
|
-
return apiConfig.httpClient.put(`/v1/reservations/${id}`, payload, {
|
|
262
|
-
successMessage: "Reservation updated successfully",
|
|
263
|
-
errorMessage: "Failed to update reservation",
|
|
264
|
-
...options
|
|
265
|
-
});
|
|
266
|
-
},
|
|
267
|
-
async checkout(params, options) {
|
|
268
|
-
const payload = {
|
|
269
|
-
businessId: apiConfig.businessId,
|
|
270
|
-
market: apiConfig.market,
|
|
271
|
-
blocks: params.blocks || [],
|
|
272
|
-
parts: params.parts,
|
|
273
|
-
...params.paymentMethod && { paymentMethod: params.paymentMethod },
|
|
274
|
-
...params.promoCode && { promoCode: params.promoCode }
|
|
275
|
-
};
|
|
276
|
-
return apiConfig.httpClient.post(`/v1/reservations/checkout`, payload, {
|
|
277
|
-
successMessage: "Reservation checkout completed",
|
|
278
|
-
errorMessage: "Failed to complete checkout",
|
|
279
|
-
...options
|
|
280
|
-
});
|
|
281
|
-
},
|
|
282
|
-
async getReservation(params, options) {
|
|
283
|
-
return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
|
|
284
|
-
...options,
|
|
285
|
-
params: params.businessId ? { businessId: params.businessId } : {}
|
|
286
|
-
});
|
|
287
599
|
},
|
|
288
|
-
async
|
|
289
|
-
|
|
290
|
-
...options,
|
|
291
|
-
params: params || {}
|
|
292
|
-
});
|
|
293
|
-
},
|
|
294
|
-
async searchReservations(params, options) {
|
|
295
|
-
return apiConfig.httpClient.get(`/v1/reservations/search`, {
|
|
296
|
-
...options,
|
|
297
|
-
params
|
|
298
|
-
});
|
|
299
|
-
},
|
|
300
|
-
async searchMyReservations(params, options) {
|
|
301
|
-
return apiConfig.httpClient.get(`/v1/reservations`, {
|
|
302
|
-
...options,
|
|
303
|
-
params: params || {}
|
|
304
|
-
});
|
|
305
|
-
},
|
|
306
|
-
// ===== QUOTES =====
|
|
307
|
-
async getQuote(params, options) {
|
|
308
|
-
const lines = params.parts.map((part) => ({
|
|
309
|
-
type: "SERVICE",
|
|
310
|
-
serviceId: part.serviceId,
|
|
311
|
-
quantity: 1
|
|
312
|
-
}));
|
|
600
|
+
async updateCollectionEntry(params, options) {
|
|
601
|
+
const { id, collectionId, owner, ...rest } = params;
|
|
313
602
|
const payload = {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
currency: params.currency,
|
|
317
|
-
paymentMethod: params.paymentMethod,
|
|
318
|
-
lines,
|
|
319
|
-
...params.promoCode && { promoCode: params.promoCode }
|
|
603
|
+
...rest,
|
|
604
|
+
owner: owner || (collectionId ? `collection:${collectionId}` : void 0)
|
|
320
605
|
};
|
|
321
|
-
return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
|
|
322
|
-
},
|
|
323
|
-
// ===== SERVICES =====
|
|
324
|
-
async createService(params, options) {
|
|
325
|
-
return apiConfig.httpClient.post(
|
|
326
|
-
`/v1/businesses/${apiConfig.businessId}/services`,
|
|
327
|
-
params,
|
|
328
|
-
{
|
|
329
|
-
successMessage: "Service created successfully",
|
|
330
|
-
errorMessage: "Failed to create service",
|
|
331
|
-
...options
|
|
332
|
-
}
|
|
333
|
-
);
|
|
334
|
-
},
|
|
335
|
-
async updateService(params, options) {
|
|
336
606
|
return apiConfig.httpClient.put(
|
|
337
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
successMessage: "Service updated successfully",
|
|
341
|
-
errorMessage: "Failed to update service",
|
|
342
|
-
...options
|
|
343
|
-
}
|
|
607
|
+
`/v1/businesses/${apiConfig.businessId}/entries/${id}`,
|
|
608
|
+
payload,
|
|
609
|
+
options
|
|
344
610
|
);
|
|
345
611
|
},
|
|
346
|
-
async
|
|
612
|
+
async deleteCollectionEntry(params, options) {
|
|
347
613
|
return apiConfig.httpClient.delete(
|
|
348
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
349
|
-
|
|
350
|
-
successMessage: "Service deleted successfully",
|
|
351
|
-
errorMessage: "Failed to delete service",
|
|
352
|
-
...options
|
|
353
|
-
}
|
|
614
|
+
`/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
|
|
615
|
+
options
|
|
354
616
|
);
|
|
355
617
|
},
|
|
356
|
-
async
|
|
618
|
+
async getCollectionEntry(params, options) {
|
|
357
619
|
return apiConfig.httpClient.get(
|
|
358
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
620
|
+
`/v1/businesses/${apiConfig.businessId}/entries/${params.id}`,
|
|
359
621
|
options
|
|
360
622
|
);
|
|
361
623
|
},
|
|
362
|
-
async
|
|
363
|
-
const
|
|
364
|
-
return apiConfig.httpClient.
|
|
365
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
624
|
+
async sendEntry(params, options) {
|
|
625
|
+
const { entryId, scheduledAt } = params;
|
|
626
|
+
return apiConfig.httpClient.post(
|
|
627
|
+
`/v1/businesses/${apiConfig.businessId}/entries/${entryId}/send`,
|
|
366
628
|
{
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
629
|
+
businessId: apiConfig.businessId,
|
|
630
|
+
entryId,
|
|
631
|
+
scheduledAt: scheduledAt || Date.now()
|
|
632
|
+
},
|
|
633
|
+
options
|
|
370
634
|
);
|
|
371
635
|
},
|
|
372
|
-
|
|
373
|
-
|
|
636
|
+
// ===== VARIABLES / METADATA =====
|
|
637
|
+
async getVariableMetadata(params, options) {
|
|
374
638
|
return apiConfig.httpClient.get(
|
|
375
|
-
`/v1/
|
|
376
|
-
|
|
377
|
-
...options,
|
|
378
|
-
params: {
|
|
379
|
-
...queryParams,
|
|
380
|
-
limit: queryParams.limit || 1e3
|
|
381
|
-
}
|
|
382
|
-
}
|
|
639
|
+
`/v1/collections/entry-types/${params.entryType}/variables`,
|
|
640
|
+
options
|
|
383
641
|
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/api/eshop.ts
|
|
647
|
+
var createEshopApi = (apiConfig) => {
|
|
648
|
+
return {
|
|
649
|
+
// ===== PRODUCTS =====
|
|
650
|
+
async createProduct(params, options) {
|
|
387
651
|
return apiConfig.httpClient.post(
|
|
388
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
652
|
+
`/v1/businesses/${apiConfig.businessId}/products`,
|
|
389
653
|
params,
|
|
390
|
-
|
|
391
|
-
successMessage: "Provider created successfully",
|
|
392
|
-
errorMessage: "Failed to create provider",
|
|
393
|
-
...options
|
|
394
|
-
}
|
|
654
|
+
options
|
|
395
655
|
);
|
|
396
656
|
},
|
|
397
|
-
async
|
|
657
|
+
async updateProduct(params, options) {
|
|
398
658
|
return apiConfig.httpClient.put(
|
|
399
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
659
|
+
`/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
|
|
400
660
|
params,
|
|
401
|
-
|
|
402
|
-
successMessage: "Provider updated successfully",
|
|
403
|
-
errorMessage: "Failed to update provider",
|
|
404
|
-
...options
|
|
405
|
-
}
|
|
661
|
+
options
|
|
406
662
|
);
|
|
407
663
|
},
|
|
408
|
-
async
|
|
664
|
+
async deleteProduct(id, options) {
|
|
409
665
|
return apiConfig.httpClient.delete(
|
|
410
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
411
|
-
|
|
412
|
-
successMessage: "Provider deleted successfully",
|
|
413
|
-
errorMessage: "Failed to delete provider",
|
|
414
|
-
...options
|
|
415
|
-
}
|
|
666
|
+
`/v1/businesses/${apiConfig.businessId}/products/${id}`,
|
|
667
|
+
options
|
|
416
668
|
);
|
|
417
669
|
},
|
|
418
|
-
async
|
|
670
|
+
async getProduct(params, options) {
|
|
419
671
|
return apiConfig.httpClient.get(
|
|
420
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
672
|
+
`/v1/businesses/${apiConfig.businessId}/products/${params.id}`,
|
|
421
673
|
options
|
|
422
674
|
);
|
|
423
675
|
},
|
|
424
|
-
async
|
|
425
|
-
const {
|
|
676
|
+
async getProducts(params, options) {
|
|
677
|
+
const queryParams = params ? { ...params } : {};
|
|
426
678
|
return apiConfig.httpClient.get(
|
|
427
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
679
|
+
`/v1/businesses/${encodeURIComponent(apiConfig.businessId)}/products`,
|
|
428
680
|
{
|
|
429
681
|
...options,
|
|
430
682
|
params: queryParams
|
|
431
683
|
}
|
|
432
684
|
);
|
|
433
685
|
},
|
|
434
|
-
|
|
435
|
-
|
|
686
|
+
// ===== ORDERS =====
|
|
687
|
+
async createOrder(params, options) {
|
|
688
|
+
return apiConfig.httpClient.post(
|
|
689
|
+
`/v1/businesses/${apiConfig.businessId}/orders`,
|
|
690
|
+
params,
|
|
691
|
+
options
|
|
692
|
+
);
|
|
693
|
+
},
|
|
694
|
+
async updateOrder(params, options) {
|
|
695
|
+
return apiConfig.httpClient.put(
|
|
696
|
+
`/v1/businesses/${apiConfig.businessId}/orders/update`,
|
|
697
|
+
params,
|
|
698
|
+
options
|
|
699
|
+
);
|
|
700
|
+
},
|
|
701
|
+
async getOrder(params, options) {
|
|
436
702
|
return apiConfig.httpClient.get(
|
|
437
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
703
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
|
|
704
|
+
options
|
|
705
|
+
);
|
|
706
|
+
},
|
|
707
|
+
async getOrders(params, options) {
|
|
708
|
+
return apiConfig.httpClient.get(
|
|
709
|
+
`/v1/businesses/${apiConfig.businessId}/orders`,
|
|
438
710
|
{
|
|
439
711
|
...options,
|
|
440
|
-
params:
|
|
712
|
+
params: params || {}
|
|
441
713
|
}
|
|
442
714
|
);
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
// src/api/newsletter.ts
|
|
448
|
-
var createNewsletterApi = (apiConfig) => {
|
|
449
|
-
return {
|
|
450
|
-
// ===== NEWSLETTERS =====
|
|
451
|
-
async find(params, options) {
|
|
452
|
-
return apiConfig.httpClient.get(`/v1/newsletters`, {
|
|
453
|
-
...options,
|
|
454
|
-
params: { businessId: params.businessId }
|
|
455
|
-
});
|
|
456
|
-
},
|
|
457
|
-
async get(params, options) {
|
|
458
|
-
return apiConfig.httpClient.get(`/v1/newsletters/${params.id}`, options);
|
|
459
|
-
},
|
|
460
|
-
async create(params, options) {
|
|
461
|
-
return apiConfig.httpClient.post(`/v1/newsletters`, params, options);
|
|
462
715
|
},
|
|
463
|
-
async
|
|
464
|
-
return apiConfig.httpClient.put(
|
|
716
|
+
async updateOrderStatus(params, options) {
|
|
717
|
+
return apiConfig.httpClient.put(
|
|
718
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
|
|
719
|
+
params,
|
|
720
|
+
options
|
|
721
|
+
);
|
|
465
722
|
},
|
|
466
|
-
async
|
|
467
|
-
return apiConfig.httpClient.
|
|
723
|
+
async updateOrderPaymentStatus(params, options) {
|
|
724
|
+
return apiConfig.httpClient.put(
|
|
725
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${params.id}/payment-status`,
|
|
726
|
+
params,
|
|
727
|
+
options
|
|
728
|
+
);
|
|
468
729
|
},
|
|
469
|
-
// =====
|
|
470
|
-
async
|
|
471
|
-
|
|
730
|
+
// ===== PAYMENTS =====
|
|
731
|
+
async getQuote(params, options) {
|
|
732
|
+
const lines = params.items.map((item) => ({
|
|
733
|
+
type: "PRODUCT_VARIANT",
|
|
734
|
+
productId: item.productId,
|
|
735
|
+
variantId: item.variantId,
|
|
736
|
+
quantity: item.quantity
|
|
737
|
+
}));
|
|
738
|
+
const payload = {
|
|
739
|
+
businessId: apiConfig.businessId,
|
|
740
|
+
market: apiConfig.market,
|
|
741
|
+
currency: params.currency,
|
|
742
|
+
paymentMethod: params.paymentMethod,
|
|
743
|
+
lines,
|
|
744
|
+
...params.shippingMethodId && { shippingMethodId: params.shippingMethodId },
|
|
745
|
+
...params.promoCode && { promoCode: params.promoCode }
|
|
746
|
+
};
|
|
747
|
+
return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
|
|
472
748
|
},
|
|
473
|
-
async
|
|
474
|
-
const { newsletterId, email, customerId, payment } = params;
|
|
749
|
+
async checkout(params, options) {
|
|
475
750
|
const payload = {
|
|
476
|
-
|
|
477
|
-
email,
|
|
751
|
+
businessId: apiConfig.businessId,
|
|
478
752
|
market: apiConfig.market,
|
|
479
|
-
|
|
480
|
-
|
|
753
|
+
paymentMethod: params.paymentMethod,
|
|
754
|
+
shippingMethodId: params.shippingMethodId,
|
|
755
|
+
items: params.items,
|
|
756
|
+
blocks: params.blocks || [],
|
|
757
|
+
...params.promoCode && { promoCode: params.promoCode }
|
|
481
758
|
};
|
|
482
759
|
return apiConfig.httpClient.post(
|
|
483
|
-
`/v1/
|
|
760
|
+
`/v1/businesses/${apiConfig.businessId}/orders/checkout`,
|
|
484
761
|
payload,
|
|
485
762
|
options
|
|
486
763
|
);
|
|
487
|
-
},
|
|
488
|
-
async unsubscribe(params, options) {
|
|
489
|
-
return apiConfig.httpClient.post(`/v1/newsletters/unsubscribe`, params, options);
|
|
490
|
-
},
|
|
491
|
-
async unsubscribeWithToken(params, options) {
|
|
492
|
-
return apiConfig.httpClient.get(`/v1/newsletters/unsubscribe`, {
|
|
493
|
-
...options,
|
|
494
|
-
params
|
|
495
|
-
});
|
|
496
764
|
}
|
|
497
765
|
};
|
|
498
766
|
};
|
|
499
767
|
|
|
500
|
-
// src/api/
|
|
501
|
-
var
|
|
768
|
+
// src/api/reservation.ts
|
|
769
|
+
var createReservationApi = (apiConfig) => {
|
|
502
770
|
return {
|
|
503
|
-
// =====
|
|
504
|
-
async
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
addresses: params.addresses || [],
|
|
510
|
-
...params.apiTokens !== void 0 && { apiTokens: params.apiTokens }
|
|
511
|
-
};
|
|
512
|
-
return apiConfig.httpClient.put("/v1/users/update", payload, options);
|
|
513
|
-
},
|
|
514
|
-
async updateProfilePhone(params, options) {
|
|
515
|
-
const payload = {
|
|
516
|
-
phoneNumbers: [],
|
|
517
|
-
phoneNumber: params.phoneNumber,
|
|
518
|
-
addresses: []
|
|
519
|
-
};
|
|
520
|
-
return apiConfig.httpClient.put("/v1/users/update", payload, options);
|
|
521
|
-
},
|
|
522
|
-
async verifyPhoneCode(params, options) {
|
|
523
|
-
return apiConfig.httpClient.put("/v1/users/confirm/phone-number", params, options);
|
|
524
|
-
},
|
|
525
|
-
async getUserLocation(options) {
|
|
526
|
-
return apiConfig.httpClient.get("/v1/users/location", options);
|
|
527
|
-
},
|
|
528
|
-
async getMe(options) {
|
|
529
|
-
return apiConfig.httpClient.get("/v1/users/me", options);
|
|
530
|
-
},
|
|
531
|
-
async searchUsers(params, options) {
|
|
532
|
-
return apiConfig.httpClient.get("/v1/users/search", {
|
|
533
|
-
...options,
|
|
534
|
-
params
|
|
771
|
+
// ===== RESERVATIONS =====
|
|
772
|
+
async createReservation(params, options) {
|
|
773
|
+
return apiConfig.httpClient.post(`/v1/reservations`, params, {
|
|
774
|
+
successMessage: "Reservation created successfully",
|
|
775
|
+
errorMessage: "Failed to create reservation",
|
|
776
|
+
...options
|
|
535
777
|
});
|
|
536
778
|
},
|
|
537
|
-
async
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
},
|
|
544
|
-
async registerUser(params, options) {
|
|
545
|
-
return apiConfig.httpClient.post("/v1/users/register", params, options);
|
|
546
|
-
},
|
|
547
|
-
async logout(options) {
|
|
548
|
-
return apiConfig.httpClient.post("/v1/users/logout", {}, options);
|
|
549
|
-
},
|
|
550
|
-
async confirmUser(params, options) {
|
|
551
|
-
return apiConfig.httpClient.put("/v1/users/confirm", params, options);
|
|
552
|
-
},
|
|
553
|
-
async getLoginUrl(params, options) {
|
|
554
|
-
return apiConfig.httpClient.get("/v1/users/login/url", {
|
|
555
|
-
...options,
|
|
556
|
-
params
|
|
779
|
+
async updateReservation(params, options) {
|
|
780
|
+
const { id, ...payload } = params;
|
|
781
|
+
return apiConfig.httpClient.put(`/v1/reservations/${id}`, payload, {
|
|
782
|
+
successMessage: "Reservation updated successfully",
|
|
783
|
+
errorMessage: "Failed to update reservation",
|
|
784
|
+
...options
|
|
557
785
|
});
|
|
558
786
|
},
|
|
559
|
-
async
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
async forgotPassword(params, options) {
|
|
574
|
-
return apiConfig.httpClient.post("/v1/users/forgot-password", params, options);
|
|
575
|
-
},
|
|
576
|
-
async resetForgotPassword(params, options) {
|
|
577
|
-
return apiConfig.httpClient.post("/v1/users/reset-forgot-password", params, options);
|
|
578
|
-
},
|
|
579
|
-
async resetPassword(params, options) {
|
|
580
|
-
return apiConfig.httpClient.post("/v1/users/reset-password", params, options);
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
// src/api/business.ts
|
|
586
|
-
var createBusinessApi = (apiConfig) => {
|
|
587
|
-
return {
|
|
588
|
-
async createBusiness(params, options) {
|
|
589
|
-
return apiConfig.httpClient.post(`/v1/businesses`, params, options);
|
|
590
|
-
},
|
|
591
|
-
async updateBusiness(params, options) {
|
|
592
|
-
return apiConfig.httpClient.put(`/v1/businesses/${params.id}`, params, options);
|
|
593
|
-
},
|
|
594
|
-
async deleteBusiness(params, options) {
|
|
595
|
-
return apiConfig.httpClient.delete(`/v1/businesses/${params.id}`, options);
|
|
596
|
-
},
|
|
597
|
-
async getBusiness(params, options) {
|
|
598
|
-
return apiConfig.httpClient.get(`/v1/businesses/${params.id}`, options);
|
|
599
|
-
},
|
|
600
|
-
async getBusinesses(options) {
|
|
601
|
-
return apiConfig.httpClient.get(`/v1/businesses`, options);
|
|
602
|
-
},
|
|
603
|
-
async getBusinessParents(params, options) {
|
|
604
|
-
return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/parents`, options);
|
|
605
|
-
},
|
|
606
|
-
async triggerBuilds(params, options) {
|
|
607
|
-
return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
|
|
608
|
-
},
|
|
609
|
-
async getSubscriptionPlans(options) {
|
|
610
|
-
return apiConfig.httpClient.get("/v1/businesses/plans", options);
|
|
787
|
+
async checkout(params, options) {
|
|
788
|
+
const payload = {
|
|
789
|
+
businessId: apiConfig.businessId,
|
|
790
|
+
market: apiConfig.market,
|
|
791
|
+
blocks: params.blocks || [],
|
|
792
|
+
parts: params.parts,
|
|
793
|
+
...params.paymentMethod && { paymentMethod: params.paymentMethod },
|
|
794
|
+
...params.promoCode && { promoCode: params.promoCode }
|
|
795
|
+
};
|
|
796
|
+
return apiConfig.httpClient.post(`/v1/reservations/checkout`, payload, {
|
|
797
|
+
successMessage: "Reservation checkout completed",
|
|
798
|
+
errorMessage: "Failed to complete checkout",
|
|
799
|
+
...options
|
|
800
|
+
});
|
|
611
801
|
},
|
|
612
|
-
async
|
|
613
|
-
return apiConfig.httpClient.get(`/v1/
|
|
802
|
+
async getReservation(params, options) {
|
|
803
|
+
return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
|
|
804
|
+
...options,
|
|
805
|
+
params: params.businessId ? { businessId: params.businessId } : {}
|
|
806
|
+
});
|
|
614
807
|
},
|
|
615
|
-
async
|
|
616
|
-
return apiConfig.httpClient.
|
|
617
|
-
|
|
618
|
-
params
|
|
619
|
-
|
|
620
|
-
);
|
|
808
|
+
async getReservationParts(params, options) {
|
|
809
|
+
return apiConfig.httpClient.get(`/v1/reservations/parts`, {
|
|
810
|
+
...options,
|
|
811
|
+
params: params || {}
|
|
812
|
+
});
|
|
621
813
|
},
|
|
622
|
-
async
|
|
623
|
-
return apiConfig.httpClient.
|
|
624
|
-
|
|
625
|
-
params
|
|
626
|
-
|
|
627
|
-
);
|
|
814
|
+
async searchReservations(params, options) {
|
|
815
|
+
return apiConfig.httpClient.get(`/v1/reservations/search`, {
|
|
816
|
+
...options,
|
|
817
|
+
params
|
|
818
|
+
});
|
|
628
819
|
},
|
|
629
|
-
async
|
|
630
|
-
return apiConfig.httpClient.
|
|
820
|
+
async searchMyReservations(params, options) {
|
|
821
|
+
return apiConfig.httpClient.get(`/v1/reservations`, {
|
|
631
822
|
...options,
|
|
632
|
-
params:
|
|
823
|
+
params: params || {}
|
|
633
824
|
});
|
|
634
825
|
},
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
826
|
+
// ===== QUOTES =====
|
|
827
|
+
async getQuote(params, options) {
|
|
828
|
+
const lines = params.parts.map((part) => ({
|
|
829
|
+
type: "SERVICE",
|
|
830
|
+
serviceId: part.serviceId,
|
|
831
|
+
quantity: 1
|
|
832
|
+
}));
|
|
833
|
+
const payload = {
|
|
834
|
+
businessId: apiConfig.businessId,
|
|
835
|
+
market: apiConfig.market,
|
|
836
|
+
currency: params.currency,
|
|
837
|
+
paymentMethod: params.paymentMethod,
|
|
838
|
+
lines,
|
|
839
|
+
...params.promoCode && { promoCode: params.promoCode }
|
|
840
|
+
};
|
|
841
|
+
return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
|
|
641
842
|
},
|
|
642
|
-
|
|
843
|
+
// ===== SERVICES =====
|
|
844
|
+
async createService(params, options) {
|
|
643
845
|
return apiConfig.httpClient.post(
|
|
644
|
-
`/v1/businesses/${
|
|
846
|
+
`/v1/businesses/${apiConfig.businessId}/services`,
|
|
645
847
|
params,
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
return apiConfig.httpClient.post(
|
|
652
|
-
`/v1/businesses/${businessId}/invitation`,
|
|
653
|
-
payload,
|
|
654
|
-
options
|
|
848
|
+
{
|
|
849
|
+
successMessage: "Service created successfully",
|
|
850
|
+
errorMessage: "Failed to create service",
|
|
851
|
+
...options
|
|
852
|
+
}
|
|
655
853
|
);
|
|
656
854
|
},
|
|
657
|
-
async
|
|
658
|
-
const { businessId, ...payload } = params;
|
|
855
|
+
async updateService(params, options) {
|
|
659
856
|
return apiConfig.httpClient.put(
|
|
660
|
-
`/v1/businesses/${businessId}/
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
`/v1/businesses/${params.businessId}/webhooks/test`,
|
|
668
|
-
params.webhook,
|
|
669
|
-
options
|
|
857
|
+
`/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
|
|
858
|
+
params,
|
|
859
|
+
{
|
|
860
|
+
successMessage: "Service updated successfully",
|
|
861
|
+
errorMessage: "Failed to update service",
|
|
862
|
+
...options
|
|
863
|
+
}
|
|
670
864
|
);
|
|
671
865
|
},
|
|
672
|
-
async
|
|
673
|
-
return apiConfig.httpClient.
|
|
674
|
-
`/v1/businesses/${params.id}
|
|
866
|
+
async deleteService(params, options) {
|
|
867
|
+
return apiConfig.httpClient.delete(
|
|
868
|
+
`/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
|
|
675
869
|
{
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
limit: params.limit || 20
|
|
680
|
-
}
|
|
870
|
+
successMessage: "Service deleted successfully",
|
|
871
|
+
errorMessage: "Failed to delete service",
|
|
872
|
+
...options
|
|
681
873
|
}
|
|
682
874
|
);
|
|
683
875
|
},
|
|
684
|
-
async
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
`/v1/businesses/${id}/schedules`,
|
|
688
|
-
payload,
|
|
876
|
+
async getService(params, options) {
|
|
877
|
+
return apiConfig.httpClient.get(
|
|
878
|
+
`/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
|
|
689
879
|
options
|
|
690
880
|
);
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
};
|
|
694
|
-
|
|
695
|
-
// src/api/media.ts
|
|
696
|
-
var createMediaApi = (apiConfig) => {
|
|
697
|
-
return {
|
|
698
|
-
async uploadBusinessMedia(params) {
|
|
699
|
-
const { businessId, files = [], urls = [] } = params;
|
|
700
|
-
const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/upload`;
|
|
701
|
-
const formData = new FormData();
|
|
702
|
-
files.forEach((file) => formData.append("files", file));
|
|
703
|
-
urls.forEach((url2) => formData.append("files", url2));
|
|
704
|
-
const tokens = await apiConfig.getTokens();
|
|
705
|
-
const response = await fetch(url, {
|
|
706
|
-
method: "POST",
|
|
707
|
-
body: formData,
|
|
708
|
-
headers: {
|
|
709
|
-
Authorization: `Bearer ${tokens.accessToken}`
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
if (!response.ok) {
|
|
713
|
-
throw new Error("Upload failed, server said no");
|
|
714
|
-
}
|
|
715
|
-
return await response.json();
|
|
716
881
|
},
|
|
717
|
-
async
|
|
718
|
-
const {
|
|
719
|
-
return apiConfig.httpClient.
|
|
720
|
-
`/v1/businesses/${
|
|
882
|
+
async getServices(params, options) {
|
|
883
|
+
const queryParams = params ? { ...params } : {};
|
|
884
|
+
return apiConfig.httpClient.get(
|
|
885
|
+
`/v1/businesses/${apiConfig.businessId}/services`,
|
|
721
886
|
{
|
|
722
887
|
...options,
|
|
723
|
-
params:
|
|
888
|
+
params: queryParams
|
|
724
889
|
}
|
|
725
890
|
);
|
|
726
891
|
},
|
|
727
|
-
async
|
|
728
|
-
const {
|
|
729
|
-
const url = `${apiConfig.baseUrl}/v1/businesses/${businessId}/media`;
|
|
730
|
-
const queryParams = { limit };
|
|
731
|
-
if (cursor) queryParams.cursor = cursor;
|
|
732
|
-
const queryString = new URLSearchParams(queryParams).toString();
|
|
733
|
-
const response = await fetch(`${url}?${queryString}`);
|
|
734
|
-
if (!response.ok) {
|
|
735
|
-
const errorData = await response.json().catch(() => null);
|
|
736
|
-
throw new Error(errorData?.message || "Failed to fetch media");
|
|
737
|
-
}
|
|
738
|
-
return await response.json();
|
|
739
|
-
}
|
|
740
|
-
};
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
// src/api/role.ts
|
|
744
|
-
var createRoleApi = (apiConfig) => {
|
|
745
|
-
return {
|
|
746
|
-
async createRole(params, options) {
|
|
747
|
-
return apiConfig.httpClient.post(`/v1/roles`, params, options);
|
|
748
|
-
},
|
|
749
|
-
async updateRole(params, options) {
|
|
750
|
-
return apiConfig.httpClient.put(`/v1/roles/${params.id}`, params, options);
|
|
751
|
-
},
|
|
752
|
-
async deleteRole(params, options) {
|
|
753
|
-
return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
|
|
754
|
-
},
|
|
755
|
-
async getRole(params, options) {
|
|
756
|
-
return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
|
|
757
|
-
},
|
|
758
|
-
async getRoles(params, options) {
|
|
759
|
-
return apiConfig.httpClient.get(`/v1/roles`, {
|
|
760
|
-
...options,
|
|
761
|
-
params: params ? {
|
|
762
|
-
businessId: apiConfig.businessId,
|
|
763
|
-
action: params.action || "READ"
|
|
764
|
-
} : {
|
|
765
|
-
businessId: apiConfig.businessId,
|
|
766
|
-
action: "READ"
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
// src/api/notification.ts
|
|
774
|
-
var createNotificationApi = (apiConfig) => {
|
|
775
|
-
return {
|
|
776
|
-
async getNotifications(params, options) {
|
|
777
|
-
return apiConfig.httpClient.get(`/v1/notifications`, {
|
|
778
|
-
...options,
|
|
779
|
-
params: {
|
|
780
|
-
limit: params.limit,
|
|
781
|
-
previous_id: params.previous_id
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
},
|
|
785
|
-
async updateNotifications(options) {
|
|
786
|
-
return apiConfig.httpClient.put(`/v1/notifications`, { seen: true }, options);
|
|
787
|
-
},
|
|
788
|
-
async trackEmailOpen(params, options) {
|
|
892
|
+
async getAvailableSlots(params, options) {
|
|
893
|
+
const { serviceId, ...queryParams } = params;
|
|
789
894
|
return apiConfig.httpClient.get(
|
|
790
|
-
`/v1/
|
|
791
|
-
|
|
895
|
+
`/v1/businesses/${apiConfig.businessId}/services/${serviceId}/available-slots`,
|
|
896
|
+
{
|
|
897
|
+
...options,
|
|
898
|
+
params: {
|
|
899
|
+
...queryParams,
|
|
900
|
+
limit: queryParams.limit || 1e3
|
|
901
|
+
}
|
|
902
|
+
}
|
|
792
903
|
);
|
|
793
904
|
},
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
`/v1/notifications/track/stats/${apiConfig.businessId}`,
|
|
797
|
-
options
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
// src/api/promoCode.ts
|
|
804
|
-
var createPromoCodeApi = (apiConfig) => {
|
|
805
|
-
return {
|
|
806
|
-
async createPromoCode(params, options) {
|
|
905
|
+
// ===== PROVIDERS =====
|
|
906
|
+
async createProvider(params, options) {
|
|
807
907
|
return apiConfig.httpClient.post(
|
|
808
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
908
|
+
`/v1/businesses/${apiConfig.businessId}/providers`,
|
|
809
909
|
params,
|
|
810
|
-
|
|
910
|
+
{
|
|
911
|
+
successMessage: "Provider created successfully",
|
|
912
|
+
errorMessage: "Failed to create provider",
|
|
913
|
+
...options
|
|
914
|
+
}
|
|
811
915
|
);
|
|
812
916
|
},
|
|
813
|
-
async
|
|
917
|
+
async updateProvider(params, options) {
|
|
814
918
|
return apiConfig.httpClient.put(
|
|
815
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
919
|
+
`/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
|
|
816
920
|
params,
|
|
817
|
-
|
|
921
|
+
{
|
|
922
|
+
successMessage: "Provider updated successfully",
|
|
923
|
+
errorMessage: "Failed to update provider",
|
|
924
|
+
...options
|
|
925
|
+
}
|
|
818
926
|
);
|
|
819
927
|
},
|
|
820
|
-
async
|
|
928
|
+
async deleteProvider(params, options) {
|
|
821
929
|
return apiConfig.httpClient.delete(
|
|
822
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
823
|
-
|
|
930
|
+
`/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
|
|
931
|
+
{
|
|
932
|
+
successMessage: "Provider deleted successfully",
|
|
933
|
+
errorMessage: "Failed to delete provider",
|
|
934
|
+
...options
|
|
935
|
+
}
|
|
824
936
|
);
|
|
825
937
|
},
|
|
826
|
-
async
|
|
938
|
+
async getProvider(params, options) {
|
|
827
939
|
return apiConfig.httpClient.get(
|
|
828
|
-
`/v1/businesses/${apiConfig.businessId}/
|
|
940
|
+
`/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
|
|
829
941
|
options
|
|
830
942
|
);
|
|
831
943
|
},
|
|
832
|
-
async
|
|
833
|
-
const { businessId,
|
|
834
|
-
return apiConfig.httpClient.get(
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
...
|
|
838
|
-
|
|
944
|
+
async getProviders(params, options) {
|
|
945
|
+
const { businessId, ...queryParams } = params;
|
|
946
|
+
return apiConfig.httpClient.get(
|
|
947
|
+
`/v1/businesses/${apiConfig.businessId}/providers`,
|
|
948
|
+
{
|
|
949
|
+
...options,
|
|
950
|
+
params: queryParams
|
|
839
951
|
}
|
|
840
|
-
|
|
952
|
+
);
|
|
953
|
+
},
|
|
954
|
+
async getProviderWorkingTime(params, options) {
|
|
955
|
+
const { businessId, providerId, ...queryParams } = params;
|
|
956
|
+
return apiConfig.httpClient.get(
|
|
957
|
+
`/v1/businesses/${apiConfig.businessId}/providers/${providerId}/working-time`,
|
|
958
|
+
{
|
|
959
|
+
...options,
|
|
960
|
+
params: queryParams
|
|
961
|
+
}
|
|
962
|
+
);
|
|
841
963
|
}
|
|
842
964
|
};
|
|
843
965
|
};
|
|
844
966
|
|
|
845
|
-
// src/api/
|
|
846
|
-
var
|
|
967
|
+
// src/api/newsletter.ts
|
|
968
|
+
var createNewsletterApi = (apiConfig) => {
|
|
847
969
|
return {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
return apiConfig.httpClient.get(`/v1/
|
|
970
|
+
// ===== NEWSLETTERS =====
|
|
971
|
+
async find(params, options) {
|
|
972
|
+
return apiConfig.httpClient.get(`/v1/newsletters`, {
|
|
851
973
|
...options,
|
|
852
|
-
params:
|
|
974
|
+
params: { businessId: params.businessId }
|
|
853
975
|
});
|
|
854
976
|
},
|
|
855
|
-
async
|
|
856
|
-
return apiConfig.httpClient.get(`/v1/
|
|
977
|
+
async get(params, options) {
|
|
978
|
+
return apiConfig.httpClient.get(`/v1/newsletters/${params.id}`, options);
|
|
857
979
|
},
|
|
858
|
-
async
|
|
859
|
-
return apiConfig.httpClient.post(`/v1/
|
|
980
|
+
async create(params, options) {
|
|
981
|
+
return apiConfig.httpClient.post(`/v1/newsletters`, params, options);
|
|
982
|
+
},
|
|
983
|
+
async update(params, options) {
|
|
984
|
+
return apiConfig.httpClient.put(`/v1/newsletters/${params.id}`, params, options);
|
|
985
|
+
},
|
|
986
|
+
async delete(params, options) {
|
|
987
|
+
return apiConfig.httpClient.delete(`/v1/newsletters/${params.id}`, options);
|
|
988
|
+
},
|
|
989
|
+
// ===== SUBSCRIBERS =====
|
|
990
|
+
async getSubscribers(params, options) {
|
|
991
|
+
return apiConfig.httpClient.get(`/v1/newsletters/${params.id}/subscribers`, options);
|
|
992
|
+
},
|
|
993
|
+
async subscribe(params, options) {
|
|
994
|
+
const { newsletterId, email, customerId, payment } = params;
|
|
995
|
+
const payload = {
|
|
996
|
+
newsletterId,
|
|
997
|
+
email,
|
|
998
|
+
market: apiConfig.market,
|
|
999
|
+
...customerId && { customerId },
|
|
1000
|
+
...payment && { payment }
|
|
1001
|
+
};
|
|
1002
|
+
return apiConfig.httpClient.post(
|
|
1003
|
+
`/v1/newsletters/${newsletterId}/subscribe`,
|
|
1004
|
+
payload,
|
|
1005
|
+
options
|
|
1006
|
+
);
|
|
1007
|
+
},
|
|
1008
|
+
async unsubscribe(params, options) {
|
|
1009
|
+
return apiConfig.httpClient.post(`/v1/newsletters/unsubscribe`, params, options);
|
|
1010
|
+
},
|
|
1011
|
+
async unsubscribeWithToken(params, options) {
|
|
1012
|
+
return apiConfig.httpClient.get(`/v1/newsletters/unsubscribe`, {
|
|
1013
|
+
...options,
|
|
1014
|
+
params
|
|
1015
|
+
});
|
|
860
1016
|
}
|
|
861
1017
|
};
|
|
862
1018
|
};
|
|
@@ -1063,20 +1219,6 @@ function thumbnailUrl(service, storageUrl = "") {
|
|
|
1063
1219
|
const path = getGalleryThumbnail(service.gallery);
|
|
1064
1220
|
return path ? `${storageUrl}/${path}` : null;
|
|
1065
1221
|
}
|
|
1066
|
-
var translateMap = (labels, lang, fallback = "unknown") => {
|
|
1067
|
-
let parsedLang = "en";
|
|
1068
|
-
if (lang === "sr") {
|
|
1069
|
-
parsedLang = "bih";
|
|
1070
|
-
}
|
|
1071
|
-
if (!labels) {
|
|
1072
|
-
return fallback;
|
|
1073
|
-
}
|
|
1074
|
-
const label = labels[parsedLang];
|
|
1075
|
-
if (!label) {
|
|
1076
|
-
return fallback;
|
|
1077
|
-
}
|
|
1078
|
-
return label;
|
|
1079
|
-
};
|
|
1080
1222
|
|
|
1081
1223
|
// src/utils/currency.ts
|
|
1082
1224
|
function getCurrencySymbol(currency) {
|
|
@@ -1167,143 +1309,6 @@ function isSymbolAfterCurrency(currency) {
|
|
|
1167
1309
|
return SYMBOL_AFTER_CURRENCIES.includes(currency.toUpperCase());
|
|
1168
1310
|
}
|
|
1169
1311
|
|
|
1170
|
-
// src/utils/errors.ts
|
|
1171
|
-
var ERROR_CODES = {
|
|
1172
|
-
// General errors
|
|
1173
|
-
"GENERAL.001": "GENERAL.BAD_REQUEST",
|
|
1174
|
-
"GENERAL.002": "GENERAL.VALIDATION_ERROR",
|
|
1175
|
-
"GENERAL.003": "GENERAL.FORBIDDEN_ERROR",
|
|
1176
|
-
"GENERAL.004": "GENERAL.INTERNAL_SERVER_ERROR",
|
|
1177
|
-
"GENERAL.005": "GENERAL.UNAUTHORIZED",
|
|
1178
|
-
"GENERAL.006": "GENERAL.UNAUTHENTICATED",
|
|
1179
|
-
// Google/OAuth errors
|
|
1180
|
-
"GOOGLE.001": "GOOGLE.INVALID_ORIGIN_URI",
|
|
1181
|
-
"GOOGLE.002": "GOOGLE.INVALID_REDIRECT_URI",
|
|
1182
|
-
"GOOGLE.003": "GOOGLE.FAILED_TO_CALL_API",
|
|
1183
|
-
"GOOGLE.004": "GOOGLE.FAILED_LOGIN",
|
|
1184
|
-
"GOOGLE.005": "GOOGLE.FAILED_LOGOUT",
|
|
1185
|
-
"GOOGLE.006": "GOOGLE.FAILED_REFRESH_TOKEN",
|
|
1186
|
-
"GOOGLE.007": "GOOGLE.INVALID_PROVIDER_PASSED",
|
|
1187
|
-
// User errors
|
|
1188
|
-
"USER.001": "USER.NOT_FOUND",
|
|
1189
|
-
"USER.002": "USER.FAILED_TO_CREATE",
|
|
1190
|
-
"USER.003": "USER.FAILED_TO_UPDATE",
|
|
1191
|
-
"USER.004": "USER.FAILED_TO_DELETE",
|
|
1192
|
-
"USER.005": "USER.EMAIL_EXISTS",
|
|
1193
|
-
"USER.006": "USER.FAILED_TO_GET_UPLOAD_URL",
|
|
1194
|
-
// Business errors
|
|
1195
|
-
"BUSINESS.001": "BUSINESS.NOT_FOUND",
|
|
1196
|
-
"BUSINESS.002": "BUSINESS.FAILED_TO_CREATE",
|
|
1197
|
-
"BUSINESS.003": "BUSINESS.FAILED_TO_UPDATE",
|
|
1198
|
-
"BUSINESS.004": "BUSINESS.FAILED_TO_DELETE",
|
|
1199
|
-
"BUSINESS.005": "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
|
|
1200
|
-
"BUSINESS.006": "BUSINESS.NAME_REQUIRED",
|
|
1201
|
-
"BUSINESS.007": "BUSINESS.BUSINESS_ID_REQUIRED",
|
|
1202
|
-
"BUSINESS.010": "BUSINESS.DESCRIPTION_REQUIRED",
|
|
1203
|
-
"BUSINESS.011": "BUSINESS.SLUG_INVALID",
|
|
1204
|
-
// Provider errors
|
|
1205
|
-
"PROVIDER.001": "PROVIDER.NOT_FOUND",
|
|
1206
|
-
"PROVIDER.002": "PROVIDER.FAILED_TO_CREATE",
|
|
1207
|
-
"PROVIDER.003": "PROVIDER.FAILED_TO_UPDATE",
|
|
1208
|
-
"PROVIDER.004": "PROVIDER.FAILED_TO_DELETE",
|
|
1209
|
-
"PROVIDER.005": "PROVIDER.FAILED_TO_GET_UPLOAD_URL",
|
|
1210
|
-
"PROVIDER.006": "PROVIDER.NAME_REQUIRED",
|
|
1211
|
-
"PROVIDER.007": "PROVIDER.BUSINESS_ID_REQUIRED",
|
|
1212
|
-
"PROVIDER.008": "PROVIDER.DESCRIPTION_REQUIRED"
|
|
1213
|
-
};
|
|
1214
|
-
var ERROR_CONSTANTS = {
|
|
1215
|
-
GENERAL: {
|
|
1216
|
-
BAD_REQUEST: "GENERAL.BAD_REQUEST",
|
|
1217
|
-
VALIDATION_ERROR: "GENERAL.VALIDATION_ERROR",
|
|
1218
|
-
FORBIDDEN_ERROR: "GENERAL.FORBIDDEN_ERROR",
|
|
1219
|
-
INTERNAL_SERVER_ERROR: "GENERAL.INTERNAL_SERVER_ERROR",
|
|
1220
|
-
UNAUTHORIZED: "GENERAL.UNAUTHORIZED",
|
|
1221
|
-
UNAUTHENTICATED: "GENERAL.UNAUTHENTICATED"
|
|
1222
|
-
},
|
|
1223
|
-
USER: {
|
|
1224
|
-
NOT_FOUND: "USER.NOT_FOUND",
|
|
1225
|
-
FAILED_TO_CREATE: "USER.FAILED_TO_CREATE",
|
|
1226
|
-
FAILED_TO_UPDATE: "USER.FAILED_TO_UPDATE",
|
|
1227
|
-
FAILED_TO_DELETE: "USER.FAILED_TO_DELETE",
|
|
1228
|
-
EMAIL_EXISTS: "USER.EMAIL_EXISTS",
|
|
1229
|
-
FAILED_TO_GET_UPLOAD_URL: "USER.FAILED_TO_GET_UPLOAD_URL"
|
|
1230
|
-
},
|
|
1231
|
-
BUSINESS: {
|
|
1232
|
-
NOT_FOUND: "BUSINESS.NOT_FOUND",
|
|
1233
|
-
FAILED_TO_CREATE: "BUSINESS.FAILED_TO_CREATE",
|
|
1234
|
-
FAILED_TO_UPDATE: "BUSINESS.FAILED_TO_UPDATE",
|
|
1235
|
-
FAILED_TO_DELETE: "BUSINESS.FAILED_TO_DELETE",
|
|
1236
|
-
FAILED_TO_GET_UPLOAD_URL: "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
|
|
1237
|
-
NAME_REQUIRED: "BUSINESS.NAME_REQUIRED",
|
|
1238
|
-
BUSINESS_ID_REQUIRED: "BUSINESS.BUSINESS_ID_REQUIRED",
|
|
1239
|
-
DESCRIPTION_REQUIRED: "BUSINESS.DESCRIPTION_REQUIRED",
|
|
1240
|
-
SLUG_INVALID: "BUSINESS.SLUG_INVALID"
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
function getErrorMessage(code) {
|
|
1244
|
-
return ERROR_CODES[code] || code;
|
|
1245
|
-
}
|
|
1246
|
-
function isErrorCode(code) {
|
|
1247
|
-
return code in ERROR_CODES;
|
|
1248
|
-
}
|
|
1249
|
-
var transformErrors = (zodError) => {
|
|
1250
|
-
const customErrors = [];
|
|
1251
|
-
if (!zodError.issues) return customErrors;
|
|
1252
|
-
zodError.issues.forEach((issue) => {
|
|
1253
|
-
const field = issue.path.join(".");
|
|
1254
|
-
const error = issue.message;
|
|
1255
|
-
if (!customErrors.some(
|
|
1256
|
-
(customError) => customError.field === field && customError.error === error
|
|
1257
|
-
)) {
|
|
1258
|
-
customErrors.push({ field, error });
|
|
1259
|
-
}
|
|
1260
|
-
});
|
|
1261
|
-
return customErrors;
|
|
1262
|
-
};
|
|
1263
|
-
var convertServerErrorToRequestError = (serverError, renameRules) => {
|
|
1264
|
-
return {
|
|
1265
|
-
...serverError,
|
|
1266
|
-
validationErrors: serverError.validationErrors.map((validationError) => {
|
|
1267
|
-
const field = renameRules && renameRules[validationError.field] ? renameRules[validationError.field] : validationError.field;
|
|
1268
|
-
return {
|
|
1269
|
-
field,
|
|
1270
|
-
error: validationError.error || "GENERAL.VALIDATION_ERROR"
|
|
1271
|
-
};
|
|
1272
|
-
})
|
|
1273
|
-
};
|
|
1274
|
-
};
|
|
1275
|
-
var errors = ERROR_CONSTANTS;
|
|
1276
|
-
|
|
1277
|
-
// src/utils/i18n.ts
|
|
1278
|
-
var defaultLocale = "en";
|
|
1279
|
-
function setDefaultLocale(locale) {
|
|
1280
|
-
defaultLocale = locale;
|
|
1281
|
-
}
|
|
1282
|
-
function getLocale() {
|
|
1283
|
-
if (typeof window !== "undefined" && window.navigator) {
|
|
1284
|
-
return window.navigator.language.split("-")[0] || defaultLocale;
|
|
1285
|
-
}
|
|
1286
|
-
return defaultLocale;
|
|
1287
|
-
}
|
|
1288
|
-
function getLocaleFromUrl(url) {
|
|
1289
|
-
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
1290
|
-
const potentialLocale = pathParts[0];
|
|
1291
|
-
const validLocales = ["en", "fr", "es", "de", "it", "pt", "ja", "zh", "ko", "ru"];
|
|
1292
|
-
if (potentialLocale && validLocales.includes(potentialLocale)) {
|
|
1293
|
-
return potentialLocale;
|
|
1294
|
-
}
|
|
1295
|
-
return getLocale();
|
|
1296
|
-
}
|
|
1297
|
-
function getLocalizedString(value, locale) {
|
|
1298
|
-
if (!value) return "";
|
|
1299
|
-
if (typeof value === "string") return value;
|
|
1300
|
-
if (typeof value === "object") {
|
|
1301
|
-
const targetLocale = locale || getLocale();
|
|
1302
|
-
return value[targetLocale] || value["en"] || value[Object.keys(value)[0]] || "";
|
|
1303
|
-
}
|
|
1304
|
-
return String(value);
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
1312
|
// src/utils/price.ts
|
|
1308
1313
|
var MARKET_CURRENCIES = {
|
|
1309
1314
|
"US": "USD",
|
|
@@ -1315,9 +1320,6 @@ var MARKET_CURRENCIES = {
|
|
|
1315
1320
|
function convertToMajor(minorAmount) {
|
|
1316
1321
|
return (minorAmount ?? 0) / 100;
|
|
1317
1322
|
}
|
|
1318
|
-
function convertToMinor(majorAmount) {
|
|
1319
|
-
return Math.round((majorAmount ?? 0) * 100);
|
|
1320
|
-
}
|
|
1321
1323
|
function getCurrencyFromMarket(marketId) {
|
|
1322
1324
|
return MARKET_CURRENCIES[marketId] || "USD";
|
|
1323
1325
|
}
|
|
@@ -1399,135 +1401,46 @@ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
|
|
|
1399
1401
|
}
|
|
1400
1402
|
return formattedPrice;
|
|
1401
1403
|
}
|
|
1402
|
-
function getPriceAmount(prices, marketId, fallbackMarket) {
|
|
1403
|
-
if (!prices || prices.length === 0) return 0;
|
|
1404
|
-
let price = prices.find((p) => p.market === marketId);
|
|
1405
|
-
if (!price && fallbackMarket) {
|
|
1406
|
-
price = prices.find((p) => p.market === fallbackMarket);
|
|
1407
|
-
}
|
|
1408
|
-
if (!price) {
|
|
1409
|
-
price = prices[0];
|
|
1410
|
-
}
|
|
1411
|
-
return price?.amount || 0;
|
|
1412
|
-
}
|
|
1413
|
-
function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
|
|
1414
|
-
const { discount = 0, tax = 0, promoCodeId } = options;
|
|
1415
|
-
const total = subtotalMinor - discount + tax;
|
|
1416
|
-
return {
|
|
1417
|
-
currency,
|
|
1418
|
-
market: marketId,
|
|
1419
|
-
subtotal: subtotalMinor,
|
|
1420
|
-
shipping: 0,
|
|
1421
|
-
discount,
|
|
1422
|
-
tax,
|
|
1423
|
-
total,
|
|
1424
|
-
promoCodeId,
|
|
1425
|
-
method: paymentMethod
|
|
1426
|
-
};
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
// src/utils/queryParams.ts
|
|
1430
|
-
function buildQueryString(params) {
|
|
1431
|
-
const queryParts = [];
|
|
1432
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
1433
|
-
if (value === null || value === void 0) {
|
|
1434
|
-
return;
|
|
1435
|
-
}
|
|
1436
|
-
if (Array.isArray(value)) {
|
|
1437
|
-
const jsonString = JSON.stringify(value);
|
|
1438
|
-
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
1439
|
-
} else if (typeof value === "string") {
|
|
1440
|
-
queryParts.push(`${key}=${encodeURIComponent(value)}`);
|
|
1441
|
-
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
1442
|
-
queryParts.push(`${key}=${value}`);
|
|
1443
|
-
} else if (typeof value === "object") {
|
|
1444
|
-
const jsonString = JSON.stringify(value);
|
|
1445
|
-
queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
|
|
1446
|
-
}
|
|
1447
|
-
});
|
|
1448
|
-
return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
|
|
1449
|
-
}
|
|
1450
|
-
function appendQueryString(url, params) {
|
|
1451
|
-
const queryString = buildQueryString(params);
|
|
1452
|
-
return queryString ? `${url}${queryString}` : url;
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
// src/utils/svg.ts
|
|
1456
|
-
async function fetchSvgContent(mediaObject) {
|
|
1457
|
-
if (!mediaObject) return null;
|
|
1458
|
-
const svgUrl = getImageUrl(mediaObject, false);
|
|
1459
|
-
try {
|
|
1460
|
-
const response = await fetch(svgUrl);
|
|
1461
|
-
if (!response.ok) {
|
|
1462
|
-
console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
|
|
1463
|
-
return null;
|
|
1464
|
-
}
|
|
1465
|
-
const svgContent = await response.text();
|
|
1466
|
-
return svgContent;
|
|
1467
|
-
} catch (error) {
|
|
1468
|
-
console.error("Error fetching SVG:", error);
|
|
1469
|
-
return null;
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
async function getSvgContentForAstro(mediaObject) {
|
|
1473
|
-
try {
|
|
1474
|
-
const svgContent = await fetchSvgContent(mediaObject);
|
|
1475
|
-
return svgContent || "";
|
|
1476
|
-
} catch (error) {
|
|
1477
|
-
console.error("Error getting SVG content for Astro:", error);
|
|
1478
|
-
return "";
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
async function injectSvgIntoElement(mediaObject, targetElement, className) {
|
|
1482
|
-
if (!targetElement) return;
|
|
1483
|
-
try {
|
|
1484
|
-
const svgContent = await fetchSvgContent(mediaObject);
|
|
1485
|
-
if (svgContent) {
|
|
1486
|
-
targetElement.innerHTML = svgContent;
|
|
1487
|
-
if (className) {
|
|
1488
|
-
const svgElement = targetElement.querySelector("svg");
|
|
1489
|
-
if (svgElement) {
|
|
1490
|
-
svgElement.classList.add(...className.split(" "));
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
} catch (error) {
|
|
1495
|
-
console.error("Error injecting SVG:", error);
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
// src/utils/text.ts
|
|
1500
|
-
var locales = ["en", "sr-latn"];
|
|
1501
|
-
var localeMap = {
|
|
1502
|
-
"en": "en-US",
|
|
1503
|
-
"sr-latn": "sr-RS"
|
|
1504
|
-
};
|
|
1505
|
-
function slugify(text) {
|
|
1506
|
-
return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
1507
|
-
}
|
|
1508
|
-
function humanize(text) {
|
|
1509
|
-
const slugifiedText = slugify(text);
|
|
1510
|
-
return slugifiedText.replace(/-/g, " ").replace(
|
|
1511
|
-
// upper case first letter of every word, and lower case the rest
|
|
1512
|
-
/\w\S*/g,
|
|
1513
|
-
(w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
|
|
1514
|
-
);
|
|
1404
|
+
function getPriceAmount(prices, marketId, fallbackMarket) {
|
|
1405
|
+
if (!prices || prices.length === 0) return 0;
|
|
1406
|
+
let price = prices.find((p) => p.market === marketId);
|
|
1407
|
+
if (!price && fallbackMarket) {
|
|
1408
|
+
price = prices.find((p) => p.market === fallbackMarket);
|
|
1409
|
+
}
|
|
1410
|
+
if (!price) {
|
|
1411
|
+
price = prices[0];
|
|
1412
|
+
}
|
|
1413
|
+
return price?.amount || 0;
|
|
1515
1414
|
}
|
|
1516
|
-
function
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1415
|
+
function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
|
|
1416
|
+
const { discount = 0, tax = 0, promoCodeId } = options;
|
|
1417
|
+
const total = subtotalMinor - discount + tax;
|
|
1418
|
+
return {
|
|
1419
|
+
currency,
|
|
1420
|
+
market: marketId,
|
|
1421
|
+
subtotal: subtotalMinor,
|
|
1422
|
+
shipping: 0,
|
|
1423
|
+
discount,
|
|
1424
|
+
tax,
|
|
1425
|
+
total,
|
|
1426
|
+
promoCodeId,
|
|
1427
|
+
method: paymentMethod
|
|
1428
|
+
};
|
|
1519
1429
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1430
|
+
|
|
1431
|
+
// src/utils/validation.ts
|
|
1432
|
+
function validatePhoneNumber(phone) {
|
|
1433
|
+
if (!phone) {
|
|
1434
|
+
return { isValid: false, error: "Phone number is required" };
|
|
1524
1435
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1436
|
+
const cleaned = phone.replace(/\D/g, "");
|
|
1437
|
+
if (cleaned.length < 8) {
|
|
1438
|
+
return { isValid: false, error: "Phone number is too short" };
|
|
1439
|
+
}
|
|
1440
|
+
if (cleaned.length > 15) {
|
|
1441
|
+
return { isValid: false, error: "Phone number is too long" };
|
|
1442
|
+
}
|
|
1443
|
+
return { isValid: true };
|
|
1531
1444
|
}
|
|
1532
1445
|
|
|
1533
1446
|
// src/utils/timezone.ts
|
|
@@ -1576,177 +1489,86 @@ function findTimeZone(groups) {
|
|
|
1576
1489
|
}
|
|
1577
1490
|
}
|
|
1578
1491
|
|
|
1579
|
-
// src/utils/
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
}
|
|
1588
|
-
if (cleaned.length > 15) {
|
|
1589
|
-
return { isValid: false, error: "Phone number is too long" };
|
|
1590
|
-
}
|
|
1591
|
-
return { isValid: true };
|
|
1492
|
+
// src/utils/text.ts
|
|
1493
|
+
var locales = ["en", "sr-latn"];
|
|
1494
|
+
var localeMap = {
|
|
1495
|
+
"en": "en-US",
|
|
1496
|
+
"sr-latn": "sr-RS"
|
|
1497
|
+
};
|
|
1498
|
+
function slugify(text) {
|
|
1499
|
+
return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
1592
1500
|
}
|
|
1593
|
-
function
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
}
|
|
1601
|
-
return { isValid: true };
|
|
1501
|
+
function humanize(text) {
|
|
1502
|
+
const slugifiedText = slugify(text);
|
|
1503
|
+
return slugifiedText.replace(/-/g, " ").replace(
|
|
1504
|
+
// upper case first letter of every word, and lower case the rest
|
|
1505
|
+
/\w\S*/g,
|
|
1506
|
+
(w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
|
|
1507
|
+
);
|
|
1602
1508
|
}
|
|
1603
|
-
function
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
}
|
|
1607
|
-
const cleaned = code.replace(/\D/g, "");
|
|
1608
|
-
if (cleaned.length !== 4) {
|
|
1609
|
-
return { isValid: false, error: "Please enter a 4-digit verification code" };
|
|
1610
|
-
}
|
|
1611
|
-
return { isValid: true };
|
|
1509
|
+
function categorify(text) {
|
|
1510
|
+
const slugifiedText = slugify(text);
|
|
1511
|
+
return slugifiedText.replace(/-/g, " ").toUpperCase();
|
|
1612
1512
|
}
|
|
1613
|
-
function
|
|
1614
|
-
|
|
1615
|
-
|
|
1513
|
+
function formatDate(date, locale) {
|
|
1514
|
+
let localeString = "en-US";
|
|
1515
|
+
if (locales.includes(locale)) {
|
|
1516
|
+
localeString = localeMap[locale];
|
|
1616
1517
|
}
|
|
1617
|
-
return
|
|
1518
|
+
return new Date(date).toLocaleDateString(localeString, {
|
|
1519
|
+
timeZone: "UTC",
|
|
1520
|
+
year: "numeric",
|
|
1521
|
+
month: "short",
|
|
1522
|
+
day: "numeric"
|
|
1523
|
+
});
|
|
1618
1524
|
}
|
|
1619
1525
|
|
|
1620
|
-
// src/
|
|
1621
|
-
function
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1526
|
+
// src/utils/svg.ts
|
|
1527
|
+
async function fetchSvgContent(mediaObject) {
|
|
1528
|
+
if (!mediaObject) return null;
|
|
1529
|
+
const svgUrl = getImageUrl(mediaObject, false);
|
|
1530
|
+
try {
|
|
1531
|
+
const response = await fetch(svgUrl);
|
|
1532
|
+
if (!response.ok) {
|
|
1533
|
+
console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
|
|
1534
|
+
return null;
|
|
1627
1535
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
err.name = "ApiError";
|
|
1634
|
-
err.statusCode = 401;
|
|
1635
|
-
throw err;
|
|
1636
|
-
}
|
|
1637
|
-
const refRes = await fetch(refreshEndpoint, {
|
|
1638
|
-
method: "POST",
|
|
1639
|
-
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
1640
|
-
body: JSON.stringify({ provider, refreshToken })
|
|
1641
|
-
});
|
|
1642
|
-
if (!refRes.ok) {
|
|
1643
|
-
cfg.logout();
|
|
1644
|
-
const err = new Error("Token refresh failed");
|
|
1645
|
-
err.name = "ApiError";
|
|
1646
|
-
err.statusCode = 401;
|
|
1647
|
-
throw err;
|
|
1648
|
-
}
|
|
1649
|
-
const data = await refRes.json();
|
|
1650
|
-
cfg.setToken(data);
|
|
1651
|
-
})().finally(() => {
|
|
1652
|
-
refreshPromise = null;
|
|
1653
|
-
});
|
|
1654
|
-
return refreshPromise;
|
|
1536
|
+
const svgContent = await response.text();
|
|
1537
|
+
return svgContent;
|
|
1538
|
+
} catch (error) {
|
|
1539
|
+
console.error("Error fetching SVG:", error);
|
|
1540
|
+
return null;
|
|
1655
1541
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
if (!["GET", "DELETE"].includes(method) && body !== void 0) {
|
|
1678
|
-
fetchOpts.body = JSON.stringify(body);
|
|
1679
|
-
}
|
|
1680
|
-
const fullUrl = `${cfg.baseUrl}${finalPath}`;
|
|
1681
|
-
let res;
|
|
1682
|
-
let data;
|
|
1683
|
-
try {
|
|
1684
|
-
res = await fetch(fullUrl, fetchOpts);
|
|
1685
|
-
} catch (error) {
|
|
1686
|
-
const err = new Error(error instanceof Error ? error.message : "Network request failed");
|
|
1687
|
-
err.name = "NetworkError";
|
|
1688
|
-
err.method = method;
|
|
1689
|
-
err.url = fullUrl;
|
|
1690
|
-
throw err;
|
|
1691
|
-
}
|
|
1692
|
-
if (res.status === 401 && !options?.["_retried"]) {
|
|
1693
|
-
try {
|
|
1694
|
-
await ensureFreshToken();
|
|
1695
|
-
const tokens = await cfg.getToken();
|
|
1696
|
-
headers["Authorization"] = `Bearer ${tokens.accessToken}`;
|
|
1697
|
-
fetchOpts.headers = headers;
|
|
1698
|
-
return request(method, path, body, { ...options, _retried: true });
|
|
1699
|
-
} catch (refreshError) {
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
try {
|
|
1703
|
-
const contentLength = res.headers.get("content-length");
|
|
1704
|
-
const contentType = res.headers.get("content-type");
|
|
1705
|
-
if (res.status === 204 || contentLength === "0" || !contentType?.includes("application/json")) {
|
|
1706
|
-
data = {};
|
|
1707
|
-
} else {
|
|
1708
|
-
data = await res.json();
|
|
1709
|
-
}
|
|
1710
|
-
} catch (error) {
|
|
1711
|
-
const err = new Error("Failed to parse response");
|
|
1712
|
-
err.name = "ParseError";
|
|
1713
|
-
err.method = method;
|
|
1714
|
-
err.url = fullUrl;
|
|
1715
|
-
err.status = res.status;
|
|
1716
|
-
throw err;
|
|
1717
|
-
}
|
|
1718
|
-
if (!res.ok) {
|
|
1719
|
-
const serverErr = data;
|
|
1720
|
-
const reqErr = convertServerErrorToRequestError(serverErr);
|
|
1721
|
-
if (options?.errorMessage && cfg.notify) {
|
|
1722
|
-
cfg.notify({ message: options.errorMessage, type: "error" });
|
|
1542
|
+
}
|
|
1543
|
+
async function getSvgContentForAstro(mediaObject) {
|
|
1544
|
+
try {
|
|
1545
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
1546
|
+
return svgContent || "";
|
|
1547
|
+
} catch (error) {
|
|
1548
|
+
console.error("Error getting SVG content for Astro:", error);
|
|
1549
|
+
return "";
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
async function injectSvgIntoElement(mediaObject, targetElement, className) {
|
|
1553
|
+
if (!targetElement) return;
|
|
1554
|
+
try {
|
|
1555
|
+
const svgContent = await fetchSvgContent(mediaObject);
|
|
1556
|
+
if (svgContent) {
|
|
1557
|
+
targetElement.innerHTML = svgContent;
|
|
1558
|
+
if (className) {
|
|
1559
|
+
const svgElement = targetElement.querySelector("svg");
|
|
1560
|
+
if (svgElement) {
|
|
1561
|
+
svgElement.classList.add(...className.split(" "));
|
|
1562
|
+
}
|
|
1723
1563
|
}
|
|
1724
|
-
const err = new Error(serverErr.message || "Request failed");
|
|
1725
|
-
err.name = "ApiError";
|
|
1726
|
-
err.statusCode = serverErr.statusCode || res.status;
|
|
1727
|
-
err.validationErrors = reqErr.validationErrors;
|
|
1728
|
-
err.method = method;
|
|
1729
|
-
err.url = fullUrl;
|
|
1730
|
-
const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
|
|
1731
|
-
if (requestId) err.requestId = requestId;
|
|
1732
|
-
throw err;
|
|
1733
|
-
}
|
|
1734
|
-
if (options?.successMessage && cfg.notify) {
|
|
1735
|
-
cfg.notify({ message: options.successMessage, type: "success" });
|
|
1736
1564
|
}
|
|
1737
|
-
|
|
1565
|
+
} catch (error) {
|
|
1566
|
+
console.error("Error injecting SVG:", error);
|
|
1738
1567
|
}
|
|
1739
|
-
return {
|
|
1740
|
-
get: (path, opts) => request("GET", path, void 0, opts),
|
|
1741
|
-
post: (path, body, opts) => request("POST", path, body, opts),
|
|
1742
|
-
put: (path, body, opts) => request("PUT", path, body, opts),
|
|
1743
|
-
patch: (path, body, opts) => request("PATCH", path, body, opts),
|
|
1744
|
-
delete: (path, opts) => request("DELETE", path, void 0, opts)
|
|
1745
|
-
};
|
|
1746
1568
|
}
|
|
1747
1569
|
|
|
1748
1570
|
// src/index.ts
|
|
1749
|
-
var SDK_VERSION = "0.3.
|
|
1571
|
+
var SDK_VERSION = "0.3.9";
|
|
1750
1572
|
var SUPPORTED_FRAMEWORKS = [
|
|
1751
1573
|
"astro",
|
|
1752
1574
|
"react",
|
|
@@ -1796,18 +1618,41 @@ function createArkySDK(config) {
|
|
|
1796
1618
|
logout: config.logout,
|
|
1797
1619
|
setToken: config.setToken,
|
|
1798
1620
|
utils: {
|
|
1621
|
+
// Block utilities
|
|
1799
1622
|
getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
|
|
1800
1623
|
thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
|
|
1801
1624
|
getGalleryThumbnail,
|
|
1625
|
+
getBlockValue,
|
|
1626
|
+
getBlockValues,
|
|
1627
|
+
getBlockLabel,
|
|
1628
|
+
getBlockTextValue,
|
|
1629
|
+
getBlockObjectValues,
|
|
1630
|
+
getBlockFromArray,
|
|
1631
|
+
formatBlockValue,
|
|
1632
|
+
prepareBlocksForSubmission,
|
|
1633
|
+
extractBlockValues,
|
|
1634
|
+
// Price utilities
|
|
1802
1635
|
getMarketPrice,
|
|
1803
1636
|
getPriceAmount,
|
|
1804
1637
|
formatPayment,
|
|
1805
1638
|
formatMinor,
|
|
1806
1639
|
createPaymentForCheckout,
|
|
1640
|
+
// Currency utilities
|
|
1807
1641
|
getCurrencySymbol,
|
|
1642
|
+
// Validation utilities
|
|
1808
1643
|
validatePhoneNumber,
|
|
1644
|
+
// Timezone utilities
|
|
1809
1645
|
tzGroups,
|
|
1810
|
-
findTimeZone
|
|
1646
|
+
findTimeZone,
|
|
1647
|
+
// Text utilities
|
|
1648
|
+
slugify,
|
|
1649
|
+
humanize,
|
|
1650
|
+
categorify,
|
|
1651
|
+
formatDate,
|
|
1652
|
+
// SVG utilities
|
|
1653
|
+
getSvgContentForAstro,
|
|
1654
|
+
fetchSvgContent,
|
|
1655
|
+
injectSvgIntoElement
|
|
1811
1656
|
}
|
|
1812
1657
|
};
|
|
1813
1658
|
if (autoGuest) {
|
|
@@ -1831,6 +1676,6 @@ function createArkySDK(config) {
|
|
|
1831
1676
|
return sdk;
|
|
1832
1677
|
}
|
|
1833
1678
|
|
|
1834
|
-
export {
|
|
1679
|
+
export { SDK_VERSION, SUPPORTED_FRAMEWORKS, createArkySDK };
|
|
1835
1680
|
//# sourceMappingURL=index.js.map
|
|
1836
1681
|
//# sourceMappingURL=index.js.map
|