arky-sdk 0.1.2 → 0.2.0
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/{config-CPkOgumU.d.cts → config-B7Oy_bdX.d.cts} +1 -4
- package/dist/{config-CPkOgumU.d.ts → config-B7Oy_bdX.d.ts} +1 -4
- package/dist/index.cjs +75 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +76 -196
- package/dist/index.js.map +1 -1
- package/dist/stores.cjs +51 -34
- package/dist/stores.cjs.map +1 -1
- package/dist/stores.d.cts +1 -5
- package/dist/stores.d.ts +1 -5
- package/dist/stores.js +51 -34
- package/dist/stores.js.map +1 -1
- package/dist/utils.cjs +11 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +11 -2
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as ArkyConfig } from './config-
|
|
2
|
-
export {
|
|
1
|
+
import { A as ArkyConfig } from './config-B7Oy_bdX.cjs';
|
|
2
|
+
export { g as getGlobalConfig, s as setGlobalConfig } from './config-B7Oy_bdX.cjs';
|
|
3
3
|
import { ApiResponse, Quote, PaginatedResponse, Newsletter, Payment } from './types.cjs';
|
|
4
4
|
export { Block, Business, BusinessConfig, BusinessPaymentMethod, EshopCartItem, EshopStoreState, Location, Market, MarketConfigClient, PaymentMethod, PaymentProviderConfig, Price, PromoCodeValidation, QuoteLineItem, ReservationCartPart, ReservationStoreState, ShippingMethod, Zone } from './types.cjs';
|
|
5
5
|
export { C as Collection, w as CollectionEntry, E as ERROR_CODES, u as ERROR_CONSTANTS, R as RequestError, S as ServerError, V as ValidationError, W as ValidationResult, m as categorify, H as convertServerErrorToRequestError, J as convertToMajor, K as convertToMinor, U as createPaymentForCheckout, I as errors, z as extractBlockValues, i as fetchSvgContent, o as findTimeZone, x as formatBlockValue, N as formatCurrencyAmount, n as formatDate, O as formatMinor, P as formatPayment, B as getBlockFromArray, g as getBlockLabel, A as getBlockObjectValues, d as getBlockTextValue, e as getBlockValue, f as getBlockValues, M as getCurrencyFromMarket, q as getErrorMessage, D as getGalleryThumbnail, h as getImageUrl, Q as getMarketPrice, T as getPriceAmount, j as getSvgContentForAstro, L as getSymbol, l as humanize, k as injectSvgIntoElement, r as isErrorCode, y as prepareBlocksForSubmission, s as slugify, t as thumbnailUrl, G as transformErrors, F as translateMap, p as tzGroups, a as validateEmail, v as validatePhoneNumber, c as validateRequired, b as validateVerificationCode } from './validation-C9UAYKke.cjs';
|
|
@@ -260,7 +260,7 @@ declare function getBusinessConfig(businessId: string): Promise<{
|
|
|
260
260
|
data?: undefined;
|
|
261
261
|
}>;
|
|
262
262
|
|
|
263
|
-
declare const SDK_VERSION = "0.
|
|
263
|
+
declare const SDK_VERSION = "0.2.0";
|
|
264
264
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
265
265
|
|
|
266
266
|
declare function initArky(config: ArkyConfig): ArkyConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as ArkyConfig } from './config-
|
|
2
|
-
export {
|
|
1
|
+
import { A as ArkyConfig } from './config-B7Oy_bdX.js';
|
|
2
|
+
export { g as getGlobalConfig, s as setGlobalConfig } from './config-B7Oy_bdX.js';
|
|
3
3
|
import { ApiResponse, Quote, PaginatedResponse, Newsletter, Payment } from './types.js';
|
|
4
4
|
export { Block, Business, BusinessConfig, BusinessPaymentMethod, EshopCartItem, EshopStoreState, Location, Market, MarketConfigClient, PaymentMethod, PaymentProviderConfig, Price, PromoCodeValidation, QuoteLineItem, ReservationCartPart, ReservationStoreState, ShippingMethod, Zone } from './types.js';
|
|
5
5
|
export { C as Collection, w as CollectionEntry, E as ERROR_CODES, u as ERROR_CONSTANTS, R as RequestError, S as ServerError, V as ValidationError, W as ValidationResult, m as categorify, H as convertServerErrorToRequestError, J as convertToMajor, K as convertToMinor, U as createPaymentForCheckout, I as errors, z as extractBlockValues, i as fetchSvgContent, o as findTimeZone, x as formatBlockValue, N as formatCurrencyAmount, n as formatDate, O as formatMinor, P as formatPayment, B as getBlockFromArray, g as getBlockLabel, A as getBlockObjectValues, d as getBlockTextValue, e as getBlockValue, f as getBlockValues, M as getCurrencyFromMarket, q as getErrorMessage, D as getGalleryThumbnail, h as getImageUrl, Q as getMarketPrice, T as getPriceAmount, j as getSvgContentForAstro, L as getSymbol, l as humanize, k as injectSvgIntoElement, r as isErrorCode, y as prepareBlocksForSubmission, s as slugify, t as thumbnailUrl, G as transformErrors, F as translateMap, p as tzGroups, a as validateEmail, v as validatePhoneNumber, c as validateRequired, b as validateVerificationCode } from './validation-DIvAzYjG.js';
|
|
@@ -260,7 +260,7 @@ declare function getBusinessConfig(businessId: string): Promise<{
|
|
|
260
260
|
data?: undefined;
|
|
261
261
|
}>;
|
|
262
262
|
|
|
263
|
-
declare const SDK_VERSION = "0.
|
|
263
|
+
declare const SDK_VERSION = "0.2.0";
|
|
264
264
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
265
265
|
|
|
266
266
|
declare function initArky(config: ArkyConfig): ArkyConfig;
|
package/dist/index.js
CHANGED
|
@@ -1,50 +1,16 @@
|
|
|
1
|
-
import { deepMap, computed } from 'nanostores';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __esm = (fn, res) => function __init() {
|
|
6
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
|
-
};
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
|
|
13
1
|
// src/config.ts
|
|
14
|
-
var
|
|
15
|
-
__export(config_exports, {
|
|
16
|
-
API_URL: () => API_URL,
|
|
17
|
-
BUSINESS_ID: () => BUSINESS_ID,
|
|
18
|
-
STORAGE_URL: () => STORAGE_URL,
|
|
19
|
-
getGlobalConfig: () => getGlobalConfig,
|
|
20
|
-
setGlobalConfig: () => setGlobalConfig
|
|
21
|
-
});
|
|
2
|
+
var globalConfig = null;
|
|
22
3
|
function setGlobalConfig(config) {
|
|
23
4
|
globalConfig = config;
|
|
24
|
-
API_URL = config.apiUrl;
|
|
25
|
-
BUSINESS_ID = config.businessId;
|
|
26
|
-
STORAGE_URL = config.storageUrl || "";
|
|
27
5
|
}
|
|
28
6
|
function getGlobalConfig() {
|
|
29
7
|
if (!globalConfig) {
|
|
30
8
|
throw new Error(
|
|
31
|
-
"Arky SDK not initialized. Call initArky()
|
|
9
|
+
"Arky SDK not initialized. Call initArky() first."
|
|
32
10
|
);
|
|
33
11
|
}
|
|
34
12
|
return globalConfig;
|
|
35
13
|
}
|
|
36
|
-
var globalConfig, API_URL, BUSINESS_ID, STORAGE_URL;
|
|
37
|
-
var init_config = __esm({
|
|
38
|
-
"src/config.ts"() {
|
|
39
|
-
globalConfig = null;
|
|
40
|
-
API_URL = "";
|
|
41
|
-
BUSINESS_ID = "";
|
|
42
|
-
STORAGE_URL = "";
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// src/index.ts
|
|
47
|
-
init_config();
|
|
48
14
|
|
|
49
15
|
// src/types/index.ts
|
|
50
16
|
var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
|
|
@@ -54,9 +20,6 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
|
|
|
54
20
|
return PaymentMethod2;
|
|
55
21
|
})(PaymentMethod || {});
|
|
56
22
|
|
|
57
|
-
// src/api/cms.ts
|
|
58
|
-
init_config();
|
|
59
|
-
|
|
60
23
|
// src/utils/queryParams.ts
|
|
61
24
|
function buildQueryString(params) {
|
|
62
25
|
const queryParts = [];
|
|
@@ -139,12 +102,14 @@ var http_default = httpClient;
|
|
|
139
102
|
|
|
140
103
|
// src/api/cms.ts
|
|
141
104
|
var getCollection = async (id) => {
|
|
142
|
-
const
|
|
105
|
+
const config = getGlobalConfig();
|
|
106
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${id}`;
|
|
143
107
|
const { value } = await http_default.get(url);
|
|
144
108
|
return value;
|
|
145
109
|
};
|
|
146
110
|
var getCollections = async ({ name = null, ids = null }) => {
|
|
147
|
-
const
|
|
111
|
+
const config = getGlobalConfig();
|
|
112
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections`;
|
|
148
113
|
const response = await http_default.get(url, {
|
|
149
114
|
params: { name, ids }
|
|
150
115
|
});
|
|
@@ -156,14 +121,16 @@ var getCollectionEntries = async ({
|
|
|
156
121
|
cursor,
|
|
157
122
|
ids = null
|
|
158
123
|
}) => {
|
|
159
|
-
const
|
|
124
|
+
const config = getGlobalConfig();
|
|
125
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries`;
|
|
160
126
|
const response = await http_default.get(url, {
|
|
161
127
|
params: { limit, cursor, ids }
|
|
162
128
|
});
|
|
163
129
|
return response.value;
|
|
164
130
|
};
|
|
165
131
|
var createCollectionEntry = async (collectionEntryData) => {
|
|
166
|
-
const
|
|
132
|
+
const config = getGlobalConfig();
|
|
133
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionEntryData.collectionId}/entries`;
|
|
167
134
|
const result = await http_default.post(url, collectionEntryData, {
|
|
168
135
|
successMessage: "Created successfully",
|
|
169
136
|
errorMessage: "Failed to create collection"
|
|
@@ -171,7 +138,8 @@ var createCollectionEntry = async (collectionEntryData) => {
|
|
|
171
138
|
return result;
|
|
172
139
|
};
|
|
173
140
|
var getCollectionEntry = async ({ collectionId, id }) => {
|
|
174
|
-
const
|
|
141
|
+
const config = getGlobalConfig();
|
|
142
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries/${id}`;
|
|
175
143
|
const response = await http_default.get(url);
|
|
176
144
|
return response;
|
|
177
145
|
};
|
|
@@ -183,24 +151,21 @@ var cmsApi = {
|
|
|
183
151
|
createCollectionEntry
|
|
184
152
|
};
|
|
185
153
|
|
|
186
|
-
// src/api/eshop.ts
|
|
187
|
-
init_config();
|
|
188
|
-
|
|
189
154
|
// src/api/reservation.ts
|
|
190
|
-
init_config();
|
|
191
155
|
var reservationApi = {
|
|
192
156
|
// Get quote for reservation parts
|
|
193
157
|
async getQuote({
|
|
194
158
|
token,
|
|
195
159
|
businessId,
|
|
196
160
|
market,
|
|
197
|
-
currency
|
|
161
|
+
currency,
|
|
198
162
|
userId,
|
|
199
163
|
parts,
|
|
200
164
|
paymentMethod = "CASH",
|
|
201
165
|
promoCode
|
|
202
166
|
}) {
|
|
203
167
|
try {
|
|
168
|
+
const config = getGlobalConfig();
|
|
204
169
|
const lines = parts.map((part) => ({
|
|
205
170
|
type: "SERVICE",
|
|
206
171
|
serviceId: part.serviceId,
|
|
@@ -209,14 +174,14 @@ var reservationApi = {
|
|
|
209
174
|
const payload = {
|
|
210
175
|
businessId,
|
|
211
176
|
market,
|
|
212
|
-
currency
|
|
177
|
+
currency,
|
|
213
178
|
userId,
|
|
214
179
|
paymentMethod,
|
|
215
180
|
lines,
|
|
216
181
|
promoCode: promoCode || void 0,
|
|
217
182
|
shippingMethodId: null
|
|
218
183
|
};
|
|
219
|
-
const res = await fetch(`${
|
|
184
|
+
const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
|
|
220
185
|
method: "POST",
|
|
221
186
|
headers: {
|
|
222
187
|
"Content-Type": "application/json",
|
|
@@ -251,7 +216,8 @@ var reservationApi = {
|
|
|
251
216
|
limit = 1e3,
|
|
252
217
|
providerId = null
|
|
253
218
|
}) {
|
|
254
|
-
const
|
|
219
|
+
const config = getGlobalConfig();
|
|
220
|
+
const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
|
|
255
221
|
const response = await http_default.get(url, {
|
|
256
222
|
params: {
|
|
257
223
|
from,
|
|
@@ -277,7 +243,8 @@ var reservationApi = {
|
|
|
277
243
|
},
|
|
278
244
|
// Get all providers for a service
|
|
279
245
|
async getProviders({ businessId, serviceId, limit = 50 }) {
|
|
280
|
-
const
|
|
246
|
+
const config = getGlobalConfig();
|
|
247
|
+
const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
|
|
281
248
|
const response = await http_default.get(url, {
|
|
282
249
|
params: {
|
|
283
250
|
serviceId,
|
|
@@ -302,7 +269,8 @@ var reservationApi = {
|
|
|
302
269
|
// Get guest token or create a new one
|
|
303
270
|
async getGuestToken() {
|
|
304
271
|
try {
|
|
305
|
-
const
|
|
272
|
+
const config = getGlobalConfig();
|
|
273
|
+
const res = await fetch(`${config.apiUrl}/v1/users/login`, {
|
|
306
274
|
method: "POST",
|
|
307
275
|
headers: { "Content-Type": "application/json" },
|
|
308
276
|
body: JSON.stringify({ provider: "GUEST" })
|
|
@@ -323,7 +291,8 @@ var reservationApi = {
|
|
|
323
291
|
// Update user's phone number
|
|
324
292
|
async updateProfilePhone({ token, phoneNumber }) {
|
|
325
293
|
try {
|
|
326
|
-
const
|
|
294
|
+
const config = getGlobalConfig();
|
|
295
|
+
const res = await fetch(`${config.apiUrl}/v1/users/update`, {
|
|
327
296
|
method: "PUT",
|
|
328
297
|
headers: {
|
|
329
298
|
"Content-Type": "application/json",
|
|
@@ -355,7 +324,8 @@ var reservationApi = {
|
|
|
355
324
|
// Verify phone number with code
|
|
356
325
|
async verifyPhoneCode({ token, phoneNumber, code }) {
|
|
357
326
|
try {
|
|
358
|
-
const
|
|
327
|
+
const config = getGlobalConfig();
|
|
328
|
+
const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
|
|
359
329
|
method: "PUT",
|
|
360
330
|
headers: {
|
|
361
331
|
"Content-Type": "application/json",
|
|
@@ -394,6 +364,7 @@ var reservationApi = {
|
|
|
394
364
|
promoCode
|
|
395
365
|
}) {
|
|
396
366
|
try {
|
|
367
|
+
const config = getGlobalConfig();
|
|
397
368
|
const payload = {
|
|
398
369
|
businessId,
|
|
399
370
|
blocks,
|
|
@@ -413,7 +384,7 @@ var reservationApi = {
|
|
|
413
384
|
if (promoCode) {
|
|
414
385
|
payload.promoCode = promoCode;
|
|
415
386
|
}
|
|
416
|
-
const res = await fetch(`${
|
|
387
|
+
const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
|
|
417
388
|
method: "POST",
|
|
418
389
|
headers: {
|
|
419
390
|
"Content-Type": "application/json",
|
|
@@ -450,7 +421,8 @@ var eshopApi = {
|
|
|
450
421
|
limit = 20,
|
|
451
422
|
cursor = null
|
|
452
423
|
}) {
|
|
453
|
-
const
|
|
424
|
+
const config = getGlobalConfig();
|
|
425
|
+
const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
|
|
454
426
|
const response = await http_default.get(url, {
|
|
455
427
|
params: {
|
|
456
428
|
categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
|
|
@@ -479,7 +451,8 @@ var eshopApi = {
|
|
|
479
451
|
// Get product by slug
|
|
480
452
|
async getProductBySlug({ businessId, slug }) {
|
|
481
453
|
try {
|
|
482
|
-
const
|
|
454
|
+
const config = getGlobalConfig();
|
|
455
|
+
const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
|
|
483
456
|
const res = await fetch(url);
|
|
484
457
|
if (!res.ok) throw new Error("Product not found");
|
|
485
458
|
const json = await res.json();
|
|
@@ -502,13 +475,14 @@ var eshopApi = {
|
|
|
502
475
|
businessId,
|
|
503
476
|
items,
|
|
504
477
|
market,
|
|
505
|
-
currency
|
|
478
|
+
currency,
|
|
506
479
|
userId,
|
|
507
480
|
paymentMethod,
|
|
508
481
|
shippingMethodId,
|
|
509
482
|
promoCode
|
|
510
483
|
}) {
|
|
511
484
|
try {
|
|
485
|
+
const config = getGlobalConfig();
|
|
512
486
|
const lines = items.map((item) => ({
|
|
513
487
|
type: "PRODUCT_VARIANT",
|
|
514
488
|
productId: item.productId,
|
|
@@ -518,14 +492,14 @@ var eshopApi = {
|
|
|
518
492
|
const payload = {
|
|
519
493
|
businessId,
|
|
520
494
|
market,
|
|
521
|
-
currency
|
|
495
|
+
currency,
|
|
522
496
|
userId,
|
|
523
497
|
paymentMethod,
|
|
524
498
|
lines,
|
|
525
499
|
...shippingMethodId && { shippingMethodId },
|
|
526
500
|
...promoCode && { promoCode }
|
|
527
501
|
};
|
|
528
|
-
const res = await fetch(`${
|
|
502
|
+
const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
|
|
529
503
|
method: "POST",
|
|
530
504
|
headers: {
|
|
531
505
|
"Content-Type": "application/json",
|
|
@@ -565,6 +539,7 @@ var eshopApi = {
|
|
|
565
539
|
paymentIntentId = null
|
|
566
540
|
}) {
|
|
567
541
|
try {
|
|
542
|
+
const config = getGlobalConfig();
|
|
568
543
|
const payload = {
|
|
569
544
|
businessId,
|
|
570
545
|
items,
|
|
@@ -575,7 +550,7 @@ var eshopApi = {
|
|
|
575
550
|
...promoCode && { promoCode },
|
|
576
551
|
...paymentIntentId && { paymentIntentId }
|
|
577
552
|
};
|
|
578
|
-
const res = await fetch(`${
|
|
553
|
+
const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
|
|
579
554
|
method: "POST",
|
|
580
555
|
headers: {
|
|
581
556
|
"Content-Type": "application/json",
|
|
@@ -602,14 +577,15 @@ var eshopApi = {
|
|
|
602
577
|
}
|
|
603
578
|
},
|
|
604
579
|
// Create payment intent for Stripe
|
|
605
|
-
async createPaymentIntent({ amount, currency
|
|
580
|
+
async createPaymentIntent({ amount, currency, businessId }) {
|
|
606
581
|
try {
|
|
582
|
+
const config = getGlobalConfig();
|
|
607
583
|
const tokenResponse = await reservationApi.getGuestToken();
|
|
608
584
|
if (!tokenResponse.success || !tokenResponse.data) {
|
|
609
585
|
throw new Error("Failed to get guest token");
|
|
610
586
|
}
|
|
611
587
|
const token = tokenResponse.data.token;
|
|
612
|
-
const res = await fetch(`${
|
|
588
|
+
const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
|
|
613
589
|
method: "POST",
|
|
614
590
|
headers: {
|
|
615
591
|
"Content-Type": "application/json",
|
|
@@ -617,7 +593,7 @@ var eshopApi = {
|
|
|
617
593
|
},
|
|
618
594
|
body: JSON.stringify({
|
|
619
595
|
amount,
|
|
620
|
-
currency
|
|
596
|
+
currency,
|
|
621
597
|
businessId
|
|
622
598
|
})
|
|
623
599
|
});
|
|
@@ -643,11 +619,11 @@ var eshopApi = {
|
|
|
643
619
|
// src/api/newsletter.ts
|
|
644
620
|
var newsletterApi = {
|
|
645
621
|
async find(payload) {
|
|
622
|
+
const config = getGlobalConfig();
|
|
646
623
|
const params = new URLSearchParams({
|
|
647
624
|
businessId: payload.business_id
|
|
648
625
|
});
|
|
649
|
-
const
|
|
650
|
-
const url = `${API_URL2}/v1/newsletters?${params.toString()}`;
|
|
626
|
+
const url = `${config.apiUrl}/v1/newsletters?${params.toString()}`;
|
|
651
627
|
const response = await fetch(url);
|
|
652
628
|
if (!response.ok) {
|
|
653
629
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
@@ -663,8 +639,8 @@ var newsletterApi = {
|
|
|
663
639
|
};
|
|
664
640
|
},
|
|
665
641
|
async get(id) {
|
|
666
|
-
const
|
|
667
|
-
const url = `${
|
|
642
|
+
const config = getGlobalConfig();
|
|
643
|
+
const url = `${config.apiUrl}/v1/newsletters/${id}`;
|
|
668
644
|
const response = await fetch(url);
|
|
669
645
|
if (!response.ok) {
|
|
670
646
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
@@ -673,8 +649,8 @@ var newsletterApi = {
|
|
|
673
649
|
},
|
|
674
650
|
async subscribe(payload) {
|
|
675
651
|
try {
|
|
676
|
-
const
|
|
677
|
-
const url = `${
|
|
652
|
+
const config = getGlobalConfig();
|
|
653
|
+
const url = `${config.apiUrl}/v1/newsletters/${payload.newsletterId}/subscribe`;
|
|
678
654
|
const response = await fetch(url, {
|
|
679
655
|
method: "POST",
|
|
680
656
|
headers: {
|
|
@@ -709,7 +685,6 @@ var newsletterApi = {
|
|
|
709
685
|
};
|
|
710
686
|
|
|
711
687
|
// src/services/auth.ts
|
|
712
|
-
init_config();
|
|
713
688
|
async function getGuestToken(currentToken = null) {
|
|
714
689
|
if (currentToken) return currentToken;
|
|
715
690
|
const response = await reservationApi.getGuestToken();
|
|
@@ -742,7 +717,8 @@ async function verifyPhoneCode(token, phoneNumber, code) {
|
|
|
742
717
|
}
|
|
743
718
|
async function getBusinessConfig(businessId) {
|
|
744
719
|
try {
|
|
745
|
-
const
|
|
720
|
+
const config = getGlobalConfig();
|
|
721
|
+
const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
|
|
746
722
|
method: "GET",
|
|
747
723
|
headers: {
|
|
748
724
|
"Content-Type": "application/json"
|
|
@@ -765,7 +741,6 @@ async function getBusinessConfig(businessId) {
|
|
|
765
741
|
}
|
|
766
742
|
|
|
767
743
|
// src/utils/blocks.ts
|
|
768
|
-
init_config();
|
|
769
744
|
function getBlockLabel(block, locale = "en") {
|
|
770
745
|
if (!block) return "";
|
|
771
746
|
if (block.properties?.label) {
|
|
@@ -897,7 +872,8 @@ var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
|
897
872
|
};
|
|
898
873
|
var getImageUrl = (imageBlock, isBlock = true) => {
|
|
899
874
|
if (!imageBlock) return null;
|
|
900
|
-
const
|
|
875
|
+
const config = getGlobalConfig();
|
|
876
|
+
const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
|
|
901
877
|
const isExternalUrl = (url) => {
|
|
902
878
|
return url.startsWith("http://") || url.startsWith("https://");
|
|
903
879
|
};
|
|
@@ -944,7 +920,8 @@ function getGalleryThumbnail(gallery) {
|
|
|
944
920
|
return res?.url || null;
|
|
945
921
|
}
|
|
946
922
|
function thumbnailUrl(service) {
|
|
947
|
-
const
|
|
923
|
+
const config = getGlobalConfig();
|
|
924
|
+
const storageUrl = config.storageUrl || "";
|
|
948
925
|
const path = getGalleryThumbnail(service.gallery);
|
|
949
926
|
return path ? `${storageUrl}/${path}` : null;
|
|
950
927
|
}
|
|
@@ -1071,7 +1048,7 @@ var convertServerErrorToRequestError = (serverError, renameRules) => {
|
|
|
1071
1048
|
var errors = ERROR_CONSTANTS;
|
|
1072
1049
|
|
|
1073
1050
|
// src/utils/currency.ts
|
|
1074
|
-
function getCurrencySymbol(
|
|
1051
|
+
function getCurrencySymbol(currency) {
|
|
1075
1052
|
const currencySymbols = {
|
|
1076
1053
|
USD: "$",
|
|
1077
1054
|
EUR: "\u20AC",
|
|
@@ -1152,7 +1129,7 @@ function getCurrencySymbol(currency2) {
|
|
|
1152
1129
|
BYR: "p.",
|
|
1153
1130
|
MDL: "L"
|
|
1154
1131
|
};
|
|
1155
|
-
return currencySymbols[
|
|
1132
|
+
return currencySymbols[currency.toUpperCase()] || currency;
|
|
1156
1133
|
}
|
|
1157
1134
|
|
|
1158
1135
|
// src/utils/price.ts
|
|
@@ -1176,24 +1153,24 @@ function convertToMajor(minorAmount) {
|
|
|
1176
1153
|
function convertToMinor(majorAmount) {
|
|
1177
1154
|
return Math.round((majorAmount ?? 0) * 100);
|
|
1178
1155
|
}
|
|
1179
|
-
function getSymbol(
|
|
1180
|
-
return CURRENCY_SYMBOLS[
|
|
1156
|
+
function getSymbol(currency) {
|
|
1157
|
+
return CURRENCY_SYMBOLS[currency] || "$";
|
|
1181
1158
|
}
|
|
1182
1159
|
function getCurrencyFromMarket(marketId) {
|
|
1183
1160
|
return MARKET_CURRENCIES[marketId] || "USD";
|
|
1184
1161
|
}
|
|
1185
|
-
function formatCurrencyAmount(amount,
|
|
1162
|
+
function formatCurrencyAmount(amount, currency, options = {}) {
|
|
1186
1163
|
const { showSymbols = true, decimalPlaces = 2, customSymbol } = options;
|
|
1187
1164
|
const roundedAmount = amount.toFixed(decimalPlaces);
|
|
1188
1165
|
if (!showSymbols) {
|
|
1189
|
-
return `${roundedAmount} ${
|
|
1166
|
+
return `${roundedAmount} ${currency}`;
|
|
1190
1167
|
}
|
|
1191
|
-
const symbol = customSymbol || getSymbol(
|
|
1168
|
+
const symbol = customSymbol || getSymbol(currency);
|
|
1192
1169
|
return `${symbol}${roundedAmount}`;
|
|
1193
1170
|
}
|
|
1194
|
-
function formatMinor(amountMinor,
|
|
1171
|
+
function formatMinor(amountMinor, currency, options = {}) {
|
|
1195
1172
|
const major = convertToMajor(amountMinor);
|
|
1196
|
-
return formatCurrencyAmount(major,
|
|
1173
|
+
return formatCurrencyAmount(major, currency, options);
|
|
1197
1174
|
}
|
|
1198
1175
|
function formatPayment(payment, options = {}) {
|
|
1199
1176
|
if (!payment) return "";
|
|
@@ -1224,28 +1201,28 @@ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
|
|
|
1224
1201
|
price = prices.find((p) => p.market === fallbackMarket) || prices[0];
|
|
1225
1202
|
}
|
|
1226
1203
|
if (!price) return "";
|
|
1227
|
-
let
|
|
1204
|
+
let currency;
|
|
1228
1205
|
let symbol;
|
|
1229
1206
|
if (businessMarkets) {
|
|
1230
1207
|
const marketData = businessMarkets.find((m) => m.id === price.market || m.code === price.market);
|
|
1231
1208
|
if (marketData?.currency) {
|
|
1232
|
-
|
|
1233
|
-
symbol = getCurrencySymbol(
|
|
1209
|
+
currency = marketData.currency;
|
|
1210
|
+
symbol = getCurrencySymbol(currency);
|
|
1234
1211
|
} else {
|
|
1235
|
-
|
|
1236
|
-
symbol = getSymbol(
|
|
1212
|
+
currency = getCurrencyFromMarket(price.market);
|
|
1213
|
+
symbol = getSymbol(currency);
|
|
1237
1214
|
}
|
|
1238
1215
|
} else {
|
|
1239
|
-
|
|
1240
|
-
symbol = getSymbol(
|
|
1216
|
+
currency = getCurrencyFromMarket(price.market);
|
|
1217
|
+
symbol = getSymbol(currency);
|
|
1241
1218
|
}
|
|
1242
|
-
const formattedPrice = formatMinor(price.amount ?? 0,
|
|
1219
|
+
const formattedPrice = formatMinor(price.amount ?? 0, currency, {
|
|
1243
1220
|
showSymbols,
|
|
1244
1221
|
decimalPlaces,
|
|
1245
1222
|
customSymbol: symbol
|
|
1246
1223
|
});
|
|
1247
1224
|
if (showCompareAt && price.compareAt && price.compareAt > (price.amount ?? 0)) {
|
|
1248
|
-
const formattedCompareAt = formatMinor(price.compareAt,
|
|
1225
|
+
const formattedCompareAt = formatMinor(price.compareAt, currency, {
|
|
1249
1226
|
showSymbols,
|
|
1250
1227
|
decimalPlaces,
|
|
1251
1228
|
customSymbol: symbol
|
|
@@ -1259,11 +1236,11 @@ function getPriceAmount(prices, marketId, fallbackMarket = "US") {
|
|
|
1259
1236
|
const price = prices.find((p) => p.market === marketId) || prices.find((p) => p.market === fallbackMarket) || prices[0];
|
|
1260
1237
|
return price?.amount || 0;
|
|
1261
1238
|
}
|
|
1262
|
-
function createPaymentForCheckout(subtotalMinor, marketId,
|
|
1239
|
+
function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
|
|
1263
1240
|
const { discount = 0, tax = 0, promoCodeId } = options;
|
|
1264
1241
|
const total = subtotalMinor - discount + tax;
|
|
1265
1242
|
return {
|
|
1266
|
-
currency
|
|
1243
|
+
currency,
|
|
1267
1244
|
market: marketId,
|
|
1268
1245
|
subtotal: subtotalMinor,
|
|
1269
1246
|
shipping: 0,
|
|
@@ -1441,101 +1418,7 @@ function validateRequired(value, fieldName = "This field") {
|
|
|
1441
1418
|
}
|
|
1442
1419
|
|
|
1443
1420
|
// src/index.ts
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
// src/stores/business.ts
|
|
1447
|
-
init_config();
|
|
1448
|
-
var businessStore = deepMap({
|
|
1449
|
-
data: null,
|
|
1450
|
-
loading: false,
|
|
1451
|
-
error: null,
|
|
1452
|
-
initialized: false
|
|
1453
|
-
});
|
|
1454
|
-
var selectedMarket = computed(businessStore, (state) => {
|
|
1455
|
-
if (!state.data?.configs?.markets) return null;
|
|
1456
|
-
const markets2 = state.data.configs.markets;
|
|
1457
|
-
return markets2.find((m) => m.id === "us") || markets2[0] || null;
|
|
1458
|
-
});
|
|
1459
|
-
computed(selectedMarket, (market) => {
|
|
1460
|
-
return market?.currency || "USD";
|
|
1461
|
-
});
|
|
1462
|
-
computed(selectedMarket, (market) => {
|
|
1463
|
-
return getCurrencySymbol(market?.currency || "USD");
|
|
1464
|
-
});
|
|
1465
|
-
computed(businessStore, (state) => {
|
|
1466
|
-
if (!state.data?.configs?.markets) return [];
|
|
1467
|
-
return state.data.configs.markets;
|
|
1468
|
-
});
|
|
1469
|
-
computed(businessStore, (state) => {
|
|
1470
|
-
if (!state.data?.configs?.zones) return [];
|
|
1471
|
-
return state.data.configs.zones;
|
|
1472
|
-
});
|
|
1473
|
-
var paymentMethods = computed(selectedMarket, (market) => {
|
|
1474
|
-
if (!market) return ["CASH"];
|
|
1475
|
-
const methods = market.paymentMethods || [];
|
|
1476
|
-
return methods.map((pm) => pm.method || pm);
|
|
1477
|
-
});
|
|
1478
|
-
computed(businessStore, (state) => {
|
|
1479
|
-
if (!state.data?.configs) return { provider: null, enabled: false };
|
|
1480
|
-
const provider = state.data.configs.paymentProvider || null;
|
|
1481
|
-
const hasCreditCard = paymentMethods.get().includes("CREDIT_CARD");
|
|
1482
|
-
return {
|
|
1483
|
-
provider,
|
|
1484
|
-
enabled: hasCreditCard && !!provider
|
|
1485
|
-
};
|
|
1486
|
-
});
|
|
1487
|
-
computed(businessStore, (state) => {
|
|
1488
|
-
return state.data?.configs?.orderBlocks || [];
|
|
1489
|
-
});
|
|
1490
|
-
computed(businessStore, (state) => {
|
|
1491
|
-
return state.data?.configs?.reservationBlocks || [];
|
|
1492
|
-
});
|
|
1493
|
-
var businessActions = {
|
|
1494
|
-
// Initialize business data - SINGLE API CALL for entire app
|
|
1495
|
-
async init() {
|
|
1496
|
-
const state = businessStore.get();
|
|
1497
|
-
if (state.initialized && state.data) {
|
|
1498
|
-
return;
|
|
1499
|
-
}
|
|
1500
|
-
try {
|
|
1501
|
-
businessStore.setKey("loading", true);
|
|
1502
|
-
businessStore.setKey("error", null);
|
|
1503
|
-
const result = await getBusinessConfig(BUSINESS_ID);
|
|
1504
|
-
if (result.success) {
|
|
1505
|
-
businessStore.setKey("data", result.data);
|
|
1506
|
-
businessStore.setKey("initialized", true);
|
|
1507
|
-
} else {
|
|
1508
|
-
throw new Error(result.error || "Failed to load business configuration");
|
|
1509
|
-
}
|
|
1510
|
-
} catch (error) {
|
|
1511
|
-
businessStore.setKey("error", error.message);
|
|
1512
|
-
console.error("Business store initialization failed:", error);
|
|
1513
|
-
} finally {
|
|
1514
|
-
businessStore.setKey("loading", false);
|
|
1515
|
-
}
|
|
1516
|
-
},
|
|
1517
|
-
// Reset store (useful for testing)
|
|
1518
|
-
reset() {
|
|
1519
|
-
businessStore.setKey("data", null);
|
|
1520
|
-
businessStore.setKey("loading", false);
|
|
1521
|
-
businessStore.setKey("error", null);
|
|
1522
|
-
businessStore.setKey("initialized", false);
|
|
1523
|
-
},
|
|
1524
|
-
// Get business data (with auto-init)
|
|
1525
|
-
async getBusiness() {
|
|
1526
|
-
const state = businessStore.get();
|
|
1527
|
-
if (!state.initialized || !state.data) {
|
|
1528
|
-
await this.init();
|
|
1529
|
-
}
|
|
1530
|
-
return businessStore.get().data;
|
|
1531
|
-
}
|
|
1532
|
-
};
|
|
1533
|
-
if (typeof window !== "undefined" && BUSINESS_ID) {
|
|
1534
|
-
businessActions.init().catch(console.error);
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
// src/index.ts
|
|
1538
|
-
var SDK_VERSION = "0.1.2";
|
|
1421
|
+
var SDK_VERSION = "0.2.0";
|
|
1539
1422
|
var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
|
|
1540
1423
|
function initArky(config) {
|
|
1541
1424
|
if (!config.apiUrl) {
|
|
@@ -1545,12 +1428,9 @@ function initArky(config) {
|
|
|
1545
1428
|
throw new Error("businessId is required");
|
|
1546
1429
|
}
|
|
1547
1430
|
setGlobalConfig(config);
|
|
1548
|
-
if (typeof window !== "undefined") {
|
|
1549
|
-
businessActions.init().catch(console.error);
|
|
1550
|
-
}
|
|
1551
1431
|
return config;
|
|
1552
1432
|
}
|
|
1553
1433
|
|
|
1554
|
-
export {
|
|
1434
|
+
export { ERROR_CODES, ERROR_CONSTANTS, PaymentMethod, SDK_VERSION, SUPPORTED_FRAMEWORKS, categorify, cmsApi, convertServerErrorToRequestError, convertToMajor, convertToMinor, createPaymentForCheckout, errors, eshopApi, extractBlockValues, fetchSvgContent, findTimeZone, formatBlockValue, formatCurrencyAmount, formatDate, formatMinor, formatPayment, getBlockFromArray, getBlockLabel, getBlockObjectValues, getBlockTextValue, getBlockValue, getBlockValues, getBusinessConfig, getCurrencyFromMarket, getErrorMessage, getGalleryThumbnail, getGlobalConfig, getGuestToken, getImageUrl, getMarketPrice, getPriceAmount, getSvgContentForAstro, getSymbol, http_default as httpClient, humanize, initArky, injectSvgIntoElement, isErrorCode, newsletterApi, prepareBlocksForSubmission, reservationApi, setGlobalConfig, slugify, thumbnailUrl, transformErrors, translateMap, tzGroups, updateProfilePhone, validateEmail, validatePhoneNumber, validateRequired, validateVerificationCode, verifyPhoneCode };
|
|
1555
1435
|
//# sourceMappingURL=index.js.map
|
|
1556
1436
|
//# sourceMappingURL=index.js.map
|