arky-sdk 0.1.1 → 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 +49 -71
- 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 +50 -72
- 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
|
@@ -9,8 +9,5 @@ interface ArkyConfig {
|
|
|
9
9
|
}
|
|
10
10
|
declare function setGlobalConfig(config: ArkyConfig): void;
|
|
11
11
|
declare function getGlobalConfig(): ArkyConfig;
|
|
12
|
-
declare let API_URL: string;
|
|
13
|
-
declare let BUSINESS_ID: string;
|
|
14
|
-
declare let STORAGE_URL: string;
|
|
15
12
|
|
|
16
|
-
export { type ArkyConfig as A,
|
|
13
|
+
export { type ArkyConfig as A, getGlobalConfig as g, setGlobalConfig as s };
|
|
@@ -9,8 +9,5 @@ interface ArkyConfig {
|
|
|
9
9
|
}
|
|
10
10
|
declare function setGlobalConfig(config: ArkyConfig): void;
|
|
11
11
|
declare function getGlobalConfig(): ArkyConfig;
|
|
12
|
-
declare let API_URL: string;
|
|
13
|
-
declare let BUSINESS_ID: string;
|
|
14
|
-
declare let STORAGE_URL: string;
|
|
15
12
|
|
|
16
|
-
export { type ArkyConfig as A,
|
|
13
|
+
export { type ArkyConfig as A, getGlobalConfig as g, setGlobalConfig as s };
|
package/dist/index.cjs
CHANGED
|
@@ -1,50 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
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
3
|
// src/config.ts
|
|
14
|
-
var
|
|
15
|
-
__export(config_exports, {
|
|
16
|
-
API_URL: () => exports.API_URL,
|
|
17
|
-
BUSINESS_ID: () => exports.BUSINESS_ID,
|
|
18
|
-
STORAGE_URL: () => exports.STORAGE_URL,
|
|
19
|
-
getGlobalConfig: () => getGlobalConfig,
|
|
20
|
-
setGlobalConfig: () => setGlobalConfig
|
|
21
|
-
});
|
|
4
|
+
var globalConfig = null;
|
|
22
5
|
function setGlobalConfig(config) {
|
|
23
6
|
globalConfig = config;
|
|
24
|
-
exports.API_URL = config.apiUrl;
|
|
25
|
-
exports.BUSINESS_ID = config.businessId;
|
|
26
|
-
exports.STORAGE_URL = config.storageUrl || "";
|
|
27
7
|
}
|
|
28
8
|
function getGlobalConfig() {
|
|
29
9
|
if (!globalConfig) {
|
|
30
10
|
throw new Error(
|
|
31
|
-
"Arky SDK not initialized. Call initArky()
|
|
11
|
+
"Arky SDK not initialized. Call initArky() first."
|
|
32
12
|
);
|
|
33
13
|
}
|
|
34
14
|
return globalConfig;
|
|
35
15
|
}
|
|
36
|
-
var globalConfig; exports.API_URL = void 0; exports.BUSINESS_ID = void 0; exports.STORAGE_URL = void 0;
|
|
37
|
-
var init_config = __esm({
|
|
38
|
-
"src/config.ts"() {
|
|
39
|
-
globalConfig = null;
|
|
40
|
-
exports.API_URL = "";
|
|
41
|
-
exports.BUSINESS_ID = "";
|
|
42
|
-
exports.STORAGE_URL = "";
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// src/index.ts
|
|
47
|
-
init_config();
|
|
48
16
|
|
|
49
17
|
// src/types/index.ts
|
|
50
18
|
var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
|
|
@@ -54,9 +22,6 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
|
|
|
54
22
|
return PaymentMethod2;
|
|
55
23
|
})(PaymentMethod || {});
|
|
56
24
|
|
|
57
|
-
// src/api/cms.ts
|
|
58
|
-
init_config();
|
|
59
|
-
|
|
60
25
|
// src/utils/queryParams.ts
|
|
61
26
|
function buildQueryString(params) {
|
|
62
27
|
const queryParts = [];
|
|
@@ -139,12 +104,14 @@ var http_default = httpClient;
|
|
|
139
104
|
|
|
140
105
|
// src/api/cms.ts
|
|
141
106
|
var getCollection = async (id) => {
|
|
142
|
-
const
|
|
107
|
+
const config = getGlobalConfig();
|
|
108
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${id}`;
|
|
143
109
|
const { value } = await http_default.get(url);
|
|
144
110
|
return value;
|
|
145
111
|
};
|
|
146
112
|
var getCollections = async ({ name = null, ids = null }) => {
|
|
147
|
-
const
|
|
113
|
+
const config = getGlobalConfig();
|
|
114
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections`;
|
|
148
115
|
const response = await http_default.get(url, {
|
|
149
116
|
params: { name, ids }
|
|
150
117
|
});
|
|
@@ -156,14 +123,16 @@ var getCollectionEntries = async ({
|
|
|
156
123
|
cursor,
|
|
157
124
|
ids = null
|
|
158
125
|
}) => {
|
|
159
|
-
const
|
|
126
|
+
const config = getGlobalConfig();
|
|
127
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries`;
|
|
160
128
|
const response = await http_default.get(url, {
|
|
161
129
|
params: { limit, cursor, ids }
|
|
162
130
|
});
|
|
163
131
|
return response.value;
|
|
164
132
|
};
|
|
165
133
|
var createCollectionEntry = async (collectionEntryData) => {
|
|
166
|
-
const
|
|
134
|
+
const config = getGlobalConfig();
|
|
135
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionEntryData.collectionId}/entries`;
|
|
167
136
|
const result = await http_default.post(url, collectionEntryData, {
|
|
168
137
|
successMessage: "Created successfully",
|
|
169
138
|
errorMessage: "Failed to create collection"
|
|
@@ -171,7 +140,8 @@ var createCollectionEntry = async (collectionEntryData) => {
|
|
|
171
140
|
return result;
|
|
172
141
|
};
|
|
173
142
|
var getCollectionEntry = async ({ collectionId, id }) => {
|
|
174
|
-
const
|
|
143
|
+
const config = getGlobalConfig();
|
|
144
|
+
const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries/${id}`;
|
|
175
145
|
const response = await http_default.get(url);
|
|
176
146
|
return response;
|
|
177
147
|
};
|
|
@@ -183,11 +153,7 @@ var cmsApi = {
|
|
|
183
153
|
createCollectionEntry
|
|
184
154
|
};
|
|
185
155
|
|
|
186
|
-
// src/api/eshop.ts
|
|
187
|
-
init_config();
|
|
188
|
-
|
|
189
156
|
// src/api/reservation.ts
|
|
190
|
-
init_config();
|
|
191
157
|
var reservationApi = {
|
|
192
158
|
// Get quote for reservation parts
|
|
193
159
|
async getQuote({
|
|
@@ -201,6 +167,7 @@ var reservationApi = {
|
|
|
201
167
|
promoCode
|
|
202
168
|
}) {
|
|
203
169
|
try {
|
|
170
|
+
const config = getGlobalConfig();
|
|
204
171
|
const lines = parts.map((part) => ({
|
|
205
172
|
type: "SERVICE",
|
|
206
173
|
serviceId: part.serviceId,
|
|
@@ -216,7 +183,7 @@ var reservationApi = {
|
|
|
216
183
|
promoCode: promoCode || void 0,
|
|
217
184
|
shippingMethodId: null
|
|
218
185
|
};
|
|
219
|
-
const res = await fetch(`${
|
|
186
|
+
const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
|
|
220
187
|
method: "POST",
|
|
221
188
|
headers: {
|
|
222
189
|
"Content-Type": "application/json",
|
|
@@ -251,7 +218,8 @@ var reservationApi = {
|
|
|
251
218
|
limit = 1e3,
|
|
252
219
|
providerId = null
|
|
253
220
|
}) {
|
|
254
|
-
const
|
|
221
|
+
const config = getGlobalConfig();
|
|
222
|
+
const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
|
|
255
223
|
const response = await http_default.get(url, {
|
|
256
224
|
params: {
|
|
257
225
|
from,
|
|
@@ -277,7 +245,8 @@ var reservationApi = {
|
|
|
277
245
|
},
|
|
278
246
|
// Get all providers for a service
|
|
279
247
|
async getProviders({ businessId, serviceId, limit = 50 }) {
|
|
280
|
-
const
|
|
248
|
+
const config = getGlobalConfig();
|
|
249
|
+
const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
|
|
281
250
|
const response = await http_default.get(url, {
|
|
282
251
|
params: {
|
|
283
252
|
serviceId,
|
|
@@ -302,7 +271,8 @@ var reservationApi = {
|
|
|
302
271
|
// Get guest token or create a new one
|
|
303
272
|
async getGuestToken() {
|
|
304
273
|
try {
|
|
305
|
-
const
|
|
274
|
+
const config = getGlobalConfig();
|
|
275
|
+
const res = await fetch(`${config.apiUrl}/v1/users/login`, {
|
|
306
276
|
method: "POST",
|
|
307
277
|
headers: { "Content-Type": "application/json" },
|
|
308
278
|
body: JSON.stringify({ provider: "GUEST" })
|
|
@@ -323,7 +293,8 @@ var reservationApi = {
|
|
|
323
293
|
// Update user's phone number
|
|
324
294
|
async updateProfilePhone({ token, phoneNumber }) {
|
|
325
295
|
try {
|
|
326
|
-
const
|
|
296
|
+
const config = getGlobalConfig();
|
|
297
|
+
const res = await fetch(`${config.apiUrl}/v1/users/update`, {
|
|
327
298
|
method: "PUT",
|
|
328
299
|
headers: {
|
|
329
300
|
"Content-Type": "application/json",
|
|
@@ -355,7 +326,8 @@ var reservationApi = {
|
|
|
355
326
|
// Verify phone number with code
|
|
356
327
|
async verifyPhoneCode({ token, phoneNumber, code }) {
|
|
357
328
|
try {
|
|
358
|
-
const
|
|
329
|
+
const config = getGlobalConfig();
|
|
330
|
+
const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
|
|
359
331
|
method: "PUT",
|
|
360
332
|
headers: {
|
|
361
333
|
"Content-Type": "application/json",
|
|
@@ -394,6 +366,7 @@ var reservationApi = {
|
|
|
394
366
|
promoCode
|
|
395
367
|
}) {
|
|
396
368
|
try {
|
|
369
|
+
const config = getGlobalConfig();
|
|
397
370
|
const payload = {
|
|
398
371
|
businessId,
|
|
399
372
|
blocks,
|
|
@@ -413,7 +386,7 @@ var reservationApi = {
|
|
|
413
386
|
if (promoCode) {
|
|
414
387
|
payload.promoCode = promoCode;
|
|
415
388
|
}
|
|
416
|
-
const res = await fetch(`${
|
|
389
|
+
const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
|
|
417
390
|
method: "POST",
|
|
418
391
|
headers: {
|
|
419
392
|
"Content-Type": "application/json",
|
|
@@ -450,7 +423,8 @@ var eshopApi = {
|
|
|
450
423
|
limit = 20,
|
|
451
424
|
cursor = null
|
|
452
425
|
}) {
|
|
453
|
-
const
|
|
426
|
+
const config = getGlobalConfig();
|
|
427
|
+
const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
|
|
454
428
|
const response = await http_default.get(url, {
|
|
455
429
|
params: {
|
|
456
430
|
categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
|
|
@@ -479,7 +453,8 @@ var eshopApi = {
|
|
|
479
453
|
// Get product by slug
|
|
480
454
|
async getProductBySlug({ businessId, slug }) {
|
|
481
455
|
try {
|
|
482
|
-
const
|
|
456
|
+
const config = getGlobalConfig();
|
|
457
|
+
const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
|
|
483
458
|
const res = await fetch(url);
|
|
484
459
|
if (!res.ok) throw new Error("Product not found");
|
|
485
460
|
const json = await res.json();
|
|
@@ -509,6 +484,7 @@ var eshopApi = {
|
|
|
509
484
|
promoCode
|
|
510
485
|
}) {
|
|
511
486
|
try {
|
|
487
|
+
const config = getGlobalConfig();
|
|
512
488
|
const lines = items.map((item) => ({
|
|
513
489
|
type: "PRODUCT_VARIANT",
|
|
514
490
|
productId: item.productId,
|
|
@@ -525,7 +501,7 @@ var eshopApi = {
|
|
|
525
501
|
...shippingMethodId && { shippingMethodId },
|
|
526
502
|
...promoCode && { promoCode }
|
|
527
503
|
};
|
|
528
|
-
const res = await fetch(`${
|
|
504
|
+
const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
|
|
529
505
|
method: "POST",
|
|
530
506
|
headers: {
|
|
531
507
|
"Content-Type": "application/json",
|
|
@@ -565,6 +541,7 @@ var eshopApi = {
|
|
|
565
541
|
paymentIntentId = null
|
|
566
542
|
}) {
|
|
567
543
|
try {
|
|
544
|
+
const config = getGlobalConfig();
|
|
568
545
|
const payload = {
|
|
569
546
|
businessId,
|
|
570
547
|
items,
|
|
@@ -575,7 +552,7 @@ var eshopApi = {
|
|
|
575
552
|
...promoCode && { promoCode },
|
|
576
553
|
...paymentIntentId && { paymentIntentId }
|
|
577
554
|
};
|
|
578
|
-
const res = await fetch(`${
|
|
555
|
+
const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
|
|
579
556
|
method: "POST",
|
|
580
557
|
headers: {
|
|
581
558
|
"Content-Type": "application/json",
|
|
@@ -604,12 +581,13 @@ var eshopApi = {
|
|
|
604
581
|
// Create payment intent for Stripe
|
|
605
582
|
async createPaymentIntent({ amount, currency, businessId }) {
|
|
606
583
|
try {
|
|
584
|
+
const config = getGlobalConfig();
|
|
607
585
|
const tokenResponse = await reservationApi.getGuestToken();
|
|
608
586
|
if (!tokenResponse.success || !tokenResponse.data) {
|
|
609
587
|
throw new Error("Failed to get guest token");
|
|
610
588
|
}
|
|
611
589
|
const token = tokenResponse.data.token;
|
|
612
|
-
const res = await fetch(`${
|
|
590
|
+
const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
|
|
613
591
|
method: "POST",
|
|
614
592
|
headers: {
|
|
615
593
|
"Content-Type": "application/json",
|
|
@@ -643,11 +621,11 @@ var eshopApi = {
|
|
|
643
621
|
// src/api/newsletter.ts
|
|
644
622
|
var newsletterApi = {
|
|
645
623
|
async find(payload) {
|
|
624
|
+
const config = getGlobalConfig();
|
|
646
625
|
const params = new URLSearchParams({
|
|
647
626
|
businessId: payload.business_id
|
|
648
627
|
});
|
|
649
|
-
const
|
|
650
|
-
const url = `${API_URL2}/v1/newsletters?${params.toString()}`;
|
|
628
|
+
const url = `${config.apiUrl}/v1/newsletters?${params.toString()}`;
|
|
651
629
|
const response = await fetch(url);
|
|
652
630
|
if (!response.ok) {
|
|
653
631
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
@@ -663,8 +641,8 @@ var newsletterApi = {
|
|
|
663
641
|
};
|
|
664
642
|
},
|
|
665
643
|
async get(id) {
|
|
666
|
-
const
|
|
667
|
-
const url = `${
|
|
644
|
+
const config = getGlobalConfig();
|
|
645
|
+
const url = `${config.apiUrl}/v1/newsletters/${id}`;
|
|
668
646
|
const response = await fetch(url);
|
|
669
647
|
if (!response.ok) {
|
|
670
648
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
@@ -673,8 +651,8 @@ var newsletterApi = {
|
|
|
673
651
|
},
|
|
674
652
|
async subscribe(payload) {
|
|
675
653
|
try {
|
|
676
|
-
const
|
|
677
|
-
const url = `${
|
|
654
|
+
const config = getGlobalConfig();
|
|
655
|
+
const url = `${config.apiUrl}/v1/newsletters/${payload.newsletterId}/subscribe`;
|
|
678
656
|
const response = await fetch(url, {
|
|
679
657
|
method: "POST",
|
|
680
658
|
headers: {
|
|
@@ -709,7 +687,6 @@ var newsletterApi = {
|
|
|
709
687
|
};
|
|
710
688
|
|
|
711
689
|
// src/services/auth.ts
|
|
712
|
-
init_config();
|
|
713
690
|
async function getGuestToken(currentToken = null) {
|
|
714
691
|
if (currentToken) return currentToken;
|
|
715
692
|
const response = await reservationApi.getGuestToken();
|
|
@@ -742,7 +719,8 @@ async function verifyPhoneCode(token, phoneNumber, code) {
|
|
|
742
719
|
}
|
|
743
720
|
async function getBusinessConfig(businessId) {
|
|
744
721
|
try {
|
|
745
|
-
const
|
|
722
|
+
const config = getGlobalConfig();
|
|
723
|
+
const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
|
|
746
724
|
method: "GET",
|
|
747
725
|
headers: {
|
|
748
726
|
"Content-Type": "application/json"
|
|
@@ -765,7 +743,6 @@ async function getBusinessConfig(businessId) {
|
|
|
765
743
|
}
|
|
766
744
|
|
|
767
745
|
// src/utils/blocks.ts
|
|
768
|
-
init_config();
|
|
769
746
|
function getBlockLabel(block, locale = "en") {
|
|
770
747
|
if (!block) return "";
|
|
771
748
|
if (block.properties?.label) {
|
|
@@ -897,7 +874,8 @@ var getBlockFromArray = (entry, blockKey, locale = "en") => {
|
|
|
897
874
|
};
|
|
898
875
|
var getImageUrl = (imageBlock, isBlock = true) => {
|
|
899
876
|
if (!imageBlock) return null;
|
|
900
|
-
const
|
|
877
|
+
const config = getGlobalConfig();
|
|
878
|
+
const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
|
|
901
879
|
const isExternalUrl = (url) => {
|
|
902
880
|
return url.startsWith("http://") || url.startsWith("https://");
|
|
903
881
|
};
|
|
@@ -944,7 +922,8 @@ function getGalleryThumbnail(gallery) {
|
|
|
944
922
|
return res?.url || null;
|
|
945
923
|
}
|
|
946
924
|
function thumbnailUrl(service) {
|
|
947
|
-
const
|
|
925
|
+
const config = getGlobalConfig();
|
|
926
|
+
const storageUrl = config.storageUrl || "";
|
|
948
927
|
const path = getGalleryThumbnail(service.gallery);
|
|
949
928
|
return path ? `${storageUrl}/${path}` : null;
|
|
950
929
|
}
|
|
@@ -1441,8 +1420,7 @@ function validateRequired(value, fieldName = "This field") {
|
|
|
1441
1420
|
}
|
|
1442
1421
|
|
|
1443
1422
|
// src/index.ts
|
|
1444
|
-
|
|
1445
|
-
var SDK_VERSION = "0.1.0";
|
|
1423
|
+
var SDK_VERSION = "0.2.0";
|
|
1446
1424
|
var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
|
|
1447
1425
|
function initArky(config) {
|
|
1448
1426
|
if (!config.apiUrl) {
|