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