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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as ArkyConfig } from './config-CPkOgumU.js';
2
- export { a as API_URL, B as BUSINESS_ID, S as STORAGE_URL, g as getGlobalConfig, s as setGlobalConfig } from './config-CPkOgumU.js';
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.1.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,48 +1,16 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __esm = (fn, res) => function __init() {
4
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
- };
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
-
11
1
  // src/config.ts
12
- var config_exports = {};
13
- __export(config_exports, {
14
- API_URL: () => API_URL,
15
- BUSINESS_ID: () => BUSINESS_ID,
16
- STORAGE_URL: () => STORAGE_URL,
17
- getGlobalConfig: () => getGlobalConfig,
18
- setGlobalConfig: () => setGlobalConfig
19
- });
2
+ var globalConfig = null;
20
3
  function setGlobalConfig(config) {
21
4
  globalConfig = config;
22
- API_URL = config.apiUrl;
23
- BUSINESS_ID = config.businessId;
24
- STORAGE_URL = config.storageUrl || "";
25
5
  }
26
6
  function getGlobalConfig() {
27
7
  if (!globalConfig) {
28
8
  throw new Error(
29
- "Arky SDK not initialized. Call initArky() or create an ArkyClient instance."
9
+ "Arky SDK not initialized. Call initArky() first."
30
10
  );
31
11
  }
32
12
  return globalConfig;
33
13
  }
34
- var globalConfig, API_URL, BUSINESS_ID, STORAGE_URL;
35
- var init_config = __esm({
36
- "src/config.ts"() {
37
- globalConfig = null;
38
- API_URL = "";
39
- BUSINESS_ID = "";
40
- STORAGE_URL = "";
41
- }
42
- });
43
-
44
- // src/index.ts
45
- init_config();
46
14
 
47
15
  // src/types/index.ts
48
16
  var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
@@ -52,9 +20,6 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
52
20
  return PaymentMethod2;
53
21
  })(PaymentMethod || {});
54
22
 
55
- // src/api/cms.ts
56
- init_config();
57
-
58
23
  // src/utils/queryParams.ts
59
24
  function buildQueryString(params) {
60
25
  const queryParts = [];
@@ -137,12 +102,14 @@ var http_default = httpClient;
137
102
 
138
103
  // src/api/cms.ts
139
104
  var getCollection = async (id) => {
140
- const url = `${API_URL}/v1/businesses/${BUSINESS_ID}/collections/${id}`;
105
+ const config = getGlobalConfig();
106
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${id}`;
141
107
  const { value } = await http_default.get(url);
142
108
  return value;
143
109
  };
144
110
  var getCollections = async ({ name = null, ids = null }) => {
145
- const url = `${API_URL}/v1/businesses/${BUSINESS_ID}/collections`;
111
+ const config = getGlobalConfig();
112
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections`;
146
113
  const response = await http_default.get(url, {
147
114
  params: { name, ids }
148
115
  });
@@ -154,14 +121,16 @@ var getCollectionEntries = async ({
154
121
  cursor,
155
122
  ids = null
156
123
  }) => {
157
- const url = `${API_URL}/v1/businesses/${BUSINESS_ID}/collections/${collectionId}/entries`;
124
+ const config = getGlobalConfig();
125
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries`;
158
126
  const response = await http_default.get(url, {
159
127
  params: { limit, cursor, ids }
160
128
  });
161
129
  return response.value;
162
130
  };
163
131
  var createCollectionEntry = async (collectionEntryData) => {
164
- const url = `${API_URL}/v1/businesses/${BUSINESS_ID}/collections/${collectionEntryData.collectionId}/entries`;
132
+ const config = getGlobalConfig();
133
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionEntryData.collectionId}/entries`;
165
134
  const result = await http_default.post(url, collectionEntryData, {
166
135
  successMessage: "Created successfully",
167
136
  errorMessage: "Failed to create collection"
@@ -169,7 +138,8 @@ var createCollectionEntry = async (collectionEntryData) => {
169
138
  return result;
170
139
  };
171
140
  var getCollectionEntry = async ({ collectionId, id }) => {
172
- const url = `${API_URL}/v1/businesses/${BUSINESS_ID}/collections/${collectionId}/entries/${id}`;
141
+ const config = getGlobalConfig();
142
+ const url = `${config.apiUrl}/v1/businesses/${config.businessId}/collections/${collectionId}/entries/${id}`;
173
143
  const response = await http_default.get(url);
174
144
  return response;
175
145
  };
@@ -181,11 +151,7 @@ var cmsApi = {
181
151
  createCollectionEntry
182
152
  };
183
153
 
184
- // src/api/eshop.ts
185
- init_config();
186
-
187
154
  // src/api/reservation.ts
188
- init_config();
189
155
  var reservationApi = {
190
156
  // Get quote for reservation parts
191
157
  async getQuote({
@@ -199,6 +165,7 @@ var reservationApi = {
199
165
  promoCode
200
166
  }) {
201
167
  try {
168
+ const config = getGlobalConfig();
202
169
  const lines = parts.map((part) => ({
203
170
  type: "SERVICE",
204
171
  serviceId: part.serviceId,
@@ -214,7 +181,7 @@ var reservationApi = {
214
181
  promoCode: promoCode || void 0,
215
182
  shippingMethodId: null
216
183
  };
217
- const res = await fetch(`${API_URL}/v1/payments/quote`, {
184
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
218
185
  method: "POST",
219
186
  headers: {
220
187
  "Content-Type": "application/json",
@@ -249,7 +216,8 @@ var reservationApi = {
249
216
  limit = 1e3,
250
217
  providerId = null
251
218
  }) {
252
- const url = `${API_URL}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
219
+ const config = getGlobalConfig();
220
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
253
221
  const response = await http_default.get(url, {
254
222
  params: {
255
223
  from,
@@ -275,7 +243,8 @@ var reservationApi = {
275
243
  },
276
244
  // Get all providers for a service
277
245
  async getProviders({ businessId, serviceId, limit = 50 }) {
278
- const url = `${API_URL}/v1/businesses/${businessId}/providers`;
246
+ const config = getGlobalConfig();
247
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
279
248
  const response = await http_default.get(url, {
280
249
  params: {
281
250
  serviceId,
@@ -300,7 +269,8 @@ var reservationApi = {
300
269
  // Get guest token or create a new one
301
270
  async getGuestToken() {
302
271
  try {
303
- const res = await fetch(`${API_URL}/v1/users/login`, {
272
+ const config = getGlobalConfig();
273
+ const res = await fetch(`${config.apiUrl}/v1/users/login`, {
304
274
  method: "POST",
305
275
  headers: { "Content-Type": "application/json" },
306
276
  body: JSON.stringify({ provider: "GUEST" })
@@ -321,7 +291,8 @@ var reservationApi = {
321
291
  // Update user's phone number
322
292
  async updateProfilePhone({ token, phoneNumber }) {
323
293
  try {
324
- const res = await fetch(`${API_URL}/v1/users/update`, {
294
+ const config = getGlobalConfig();
295
+ const res = await fetch(`${config.apiUrl}/v1/users/update`, {
325
296
  method: "PUT",
326
297
  headers: {
327
298
  "Content-Type": "application/json",
@@ -353,7 +324,8 @@ var reservationApi = {
353
324
  // Verify phone number with code
354
325
  async verifyPhoneCode({ token, phoneNumber, code }) {
355
326
  try {
356
- const res = await fetch(`${API_URL}/v1/users/confirm/phone-number`, {
327
+ const config = getGlobalConfig();
328
+ const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
357
329
  method: "PUT",
358
330
  headers: {
359
331
  "Content-Type": "application/json",
@@ -392,6 +364,7 @@ var reservationApi = {
392
364
  promoCode
393
365
  }) {
394
366
  try {
367
+ const config = getGlobalConfig();
395
368
  const payload = {
396
369
  businessId,
397
370
  blocks,
@@ -411,7 +384,7 @@ var reservationApi = {
411
384
  if (promoCode) {
412
385
  payload.promoCode = promoCode;
413
386
  }
414
- const res = await fetch(`${API_URL}/v1/reservations/checkout`, {
387
+ const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
415
388
  method: "POST",
416
389
  headers: {
417
390
  "Content-Type": "application/json",
@@ -448,7 +421,8 @@ var eshopApi = {
448
421
  limit = 20,
449
422
  cursor = null
450
423
  }) {
451
- const url = `${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products`;
424
+ const config = getGlobalConfig();
425
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
452
426
  const response = await http_default.get(url, {
453
427
  params: {
454
428
  categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
@@ -477,7 +451,8 @@ var eshopApi = {
477
451
  // Get product by slug
478
452
  async getProductBySlug({ businessId, slug }) {
479
453
  try {
480
- const url = `${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
454
+ const config = getGlobalConfig();
455
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
481
456
  const res = await fetch(url);
482
457
  if (!res.ok) throw new Error("Product not found");
483
458
  const json = await res.json();
@@ -507,6 +482,7 @@ var eshopApi = {
507
482
  promoCode
508
483
  }) {
509
484
  try {
485
+ const config = getGlobalConfig();
510
486
  const lines = items.map((item) => ({
511
487
  type: "PRODUCT_VARIANT",
512
488
  productId: item.productId,
@@ -523,7 +499,7 @@ var eshopApi = {
523
499
  ...shippingMethodId && { shippingMethodId },
524
500
  ...promoCode && { promoCode }
525
501
  };
526
- const res = await fetch(`${API_URL}/v1/payments/quote`, {
502
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
527
503
  method: "POST",
528
504
  headers: {
529
505
  "Content-Type": "application/json",
@@ -563,6 +539,7 @@ var eshopApi = {
563
539
  paymentIntentId = null
564
540
  }) {
565
541
  try {
542
+ const config = getGlobalConfig();
566
543
  const payload = {
567
544
  businessId,
568
545
  items,
@@ -573,7 +550,7 @@ var eshopApi = {
573
550
  ...promoCode && { promoCode },
574
551
  ...paymentIntentId && { paymentIntentId }
575
552
  };
576
- const res = await fetch(`${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
553
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
577
554
  method: "POST",
578
555
  headers: {
579
556
  "Content-Type": "application/json",
@@ -602,12 +579,13 @@ var eshopApi = {
602
579
  // Create payment intent for Stripe
603
580
  async createPaymentIntent({ amount, currency, businessId }) {
604
581
  try {
582
+ const config = getGlobalConfig();
605
583
  const tokenResponse = await reservationApi.getGuestToken();
606
584
  if (!tokenResponse.success || !tokenResponse.data) {
607
585
  throw new Error("Failed to get guest token");
608
586
  }
609
587
  const token = tokenResponse.data.token;
610
- const res = await fetch(`${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
588
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
611
589
  method: "POST",
612
590
  headers: {
613
591
  "Content-Type": "application/json",
@@ -641,11 +619,11 @@ var eshopApi = {
641
619
  // src/api/newsletter.ts
642
620
  var newsletterApi = {
643
621
  async find(payload) {
622
+ const config = getGlobalConfig();
644
623
  const params = new URLSearchParams({
645
624
  businessId: payload.business_id
646
625
  });
647
- const { API_URL: API_URL2 } = await Promise.resolve().then(() => (init_config(), config_exports));
648
- const url = `${API_URL2}/v1/newsletters?${params.toString()}`;
626
+ const url = `${config.apiUrl}/v1/newsletters?${params.toString()}`;
649
627
  const response = await fetch(url);
650
628
  if (!response.ok) {
651
629
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -661,8 +639,8 @@ var newsletterApi = {
661
639
  };
662
640
  },
663
641
  async get(id) {
664
- const { API_URL: API_URL2 } = await Promise.resolve().then(() => (init_config(), config_exports));
665
- const url = `${API_URL2}/v1/newsletters/${id}`;
642
+ const config = getGlobalConfig();
643
+ const url = `${config.apiUrl}/v1/newsletters/${id}`;
666
644
  const response = await fetch(url);
667
645
  if (!response.ok) {
668
646
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -671,8 +649,8 @@ var newsletterApi = {
671
649
  },
672
650
  async subscribe(payload) {
673
651
  try {
674
- const { API_URL: API_URL2 } = await Promise.resolve().then(() => (init_config(), config_exports));
675
- const url = `${API_URL2}/v1/newsletters/${payload.newsletterId}/subscribe`;
652
+ const config = getGlobalConfig();
653
+ const url = `${config.apiUrl}/v1/newsletters/${payload.newsletterId}/subscribe`;
676
654
  const response = await fetch(url, {
677
655
  method: "POST",
678
656
  headers: {
@@ -707,7 +685,6 @@ var newsletterApi = {
707
685
  };
708
686
 
709
687
  // src/services/auth.ts
710
- init_config();
711
688
  async function getGuestToken(currentToken = null) {
712
689
  if (currentToken) return currentToken;
713
690
  const response = await reservationApi.getGuestToken();
@@ -740,7 +717,8 @@ async function verifyPhoneCode(token, phoneNumber, code) {
740
717
  }
741
718
  async function getBusinessConfig(businessId) {
742
719
  try {
743
- const response = await fetch(`${API_URL}/v1/businesses/${businessId}`, {
720
+ const config = getGlobalConfig();
721
+ const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
744
722
  method: "GET",
745
723
  headers: {
746
724
  "Content-Type": "application/json"
@@ -763,7 +741,6 @@ async function getBusinessConfig(businessId) {
763
741
  }
764
742
 
765
743
  // src/utils/blocks.ts
766
- init_config();
767
744
  function getBlockLabel(block, locale = "en") {
768
745
  if (!block) return "";
769
746
  if (block.properties?.label) {
@@ -895,7 +872,8 @@ var getBlockFromArray = (entry, blockKey, locale = "en") => {
895
872
  };
896
873
  var getImageUrl = (imageBlock, isBlock = true) => {
897
874
  if (!imageBlock) return null;
898
- const storageUrl = "https://storage.arky.io/dev";
875
+ const config = getGlobalConfig();
876
+ const storageUrl = config.storageUrl || "https://storage.arky.io/dev";
899
877
  const isExternalUrl = (url) => {
900
878
  return url.startsWith("http://") || url.startsWith("https://");
901
879
  };
@@ -942,7 +920,8 @@ function getGalleryThumbnail(gallery) {
942
920
  return res?.url || null;
943
921
  }
944
922
  function thumbnailUrl(service) {
945
- const storageUrl = STORAGE_URL || "";
923
+ const config = getGlobalConfig();
924
+ const storageUrl = config.storageUrl || "";
946
925
  const path = getGalleryThumbnail(service.gallery);
947
926
  return path ? `${storageUrl}/${path}` : null;
948
927
  }
@@ -1439,8 +1418,7 @@ function validateRequired(value, fieldName = "This field") {
1439
1418
  }
1440
1419
 
1441
1420
  // src/index.ts
1442
- init_config();
1443
- var SDK_VERSION = "0.1.0";
1421
+ var SDK_VERSION = "0.2.0";
1444
1422
  var SUPPORTED_FRAMEWORKS = ["astro", "react", "vue", "svelte", "vanilla"];
1445
1423
  function initArky(config) {
1446
1424
  if (!config.apiUrl) {
@@ -1453,6 +1431,6 @@ function initArky(config) {
1453
1431
  return config;
1454
1432
  }
1455
1433
 
1456
- export { API_URL, BUSINESS_ID, ERROR_CODES, ERROR_CONSTANTS, PaymentMethod, SDK_VERSION, STORAGE_URL, 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 };
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 };
1457
1435
  //# sourceMappingURL=index.js.map
1458
1436
  //# sourceMappingURL=index.js.map