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/stores.cjs CHANGED
@@ -4,14 +4,18 @@ var nanostores = require('nanostores');
4
4
  var persistent = require('@nanostores/persistent');
5
5
 
6
6
  // src/config.ts
7
+ var globalConfig = null;
7
8
  function setGlobalConfig(config) {
8
- API_URL = config.apiUrl;
9
- BUSINESS_ID = config.businessId;
10
- STORAGE_URL = config.storageUrl || "";
9
+ globalConfig = config;
10
+ }
11
+ function getGlobalConfig() {
12
+ if (!globalConfig) {
13
+ throw new Error(
14
+ "Arky SDK not initialized. Call initArky() first."
15
+ );
16
+ }
17
+ return globalConfig;
11
18
  }
12
- var API_URL = "";
13
- var BUSINESS_ID = "";
14
- var STORAGE_URL = "";
15
19
 
16
20
  // src/utils/queryParams.ts
17
21
  function buildQueryString(params) {
@@ -107,6 +111,7 @@ var reservationApi = {
107
111
  promoCode
108
112
  }) {
109
113
  try {
114
+ const config = getGlobalConfig();
110
115
  const lines = parts.map((part) => ({
111
116
  type: "SERVICE",
112
117
  serviceId: part.serviceId,
@@ -122,7 +127,7 @@ var reservationApi = {
122
127
  promoCode: promoCode || void 0,
123
128
  shippingMethodId: null
124
129
  };
125
- const res = await fetch(`${API_URL}/v1/payments/quote`, {
130
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
126
131
  method: "POST",
127
132
  headers: {
128
133
  "Content-Type": "application/json",
@@ -157,7 +162,8 @@ var reservationApi = {
157
162
  limit = 1e3,
158
163
  providerId = null
159
164
  }) {
160
- const url = `${API_URL}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
165
+ const config = getGlobalConfig();
166
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
161
167
  const response = await http_default.get(url, {
162
168
  params: {
163
169
  from,
@@ -183,7 +189,8 @@ var reservationApi = {
183
189
  },
184
190
  // Get all providers for a service
185
191
  async getProviders({ businessId, serviceId, limit = 50 }) {
186
- const url = `${API_URL}/v1/businesses/${businessId}/providers`;
192
+ const config = getGlobalConfig();
193
+ const url = `${config.apiUrl}/v1/businesses/${businessId}/providers`;
187
194
  const response = await http_default.get(url, {
188
195
  params: {
189
196
  serviceId,
@@ -208,7 +215,8 @@ var reservationApi = {
208
215
  // Get guest token or create a new one
209
216
  async getGuestToken() {
210
217
  try {
211
- const res = await fetch(`${API_URL}/v1/users/login`, {
218
+ const config = getGlobalConfig();
219
+ const res = await fetch(`${config.apiUrl}/v1/users/login`, {
212
220
  method: "POST",
213
221
  headers: { "Content-Type": "application/json" },
214
222
  body: JSON.stringify({ provider: "GUEST" })
@@ -229,7 +237,8 @@ var reservationApi = {
229
237
  // Update user's phone number
230
238
  async updateProfilePhone({ token, phoneNumber }) {
231
239
  try {
232
- const res = await fetch(`${API_URL}/v1/users/update`, {
240
+ const config = getGlobalConfig();
241
+ const res = await fetch(`${config.apiUrl}/v1/users/update`, {
233
242
  method: "PUT",
234
243
  headers: {
235
244
  "Content-Type": "application/json",
@@ -261,7 +270,8 @@ var reservationApi = {
261
270
  // Verify phone number with code
262
271
  async verifyPhoneCode({ token, phoneNumber, code }) {
263
272
  try {
264
- const res = await fetch(`${API_URL}/v1/users/confirm/phone-number`, {
273
+ const config = getGlobalConfig();
274
+ const res = await fetch(`${config.apiUrl}/v1/users/confirm/phone-number`, {
265
275
  method: "PUT",
266
276
  headers: {
267
277
  "Content-Type": "application/json",
@@ -300,6 +310,7 @@ var reservationApi = {
300
310
  promoCode
301
311
  }) {
302
312
  try {
313
+ const config = getGlobalConfig();
303
314
  const payload = {
304
315
  businessId,
305
316
  blocks,
@@ -319,7 +330,7 @@ var reservationApi = {
319
330
  if (promoCode) {
320
331
  payload.promoCode = promoCode;
321
332
  }
322
- const res = await fetch(`${API_URL}/v1/reservations/checkout`, {
333
+ const res = await fetch(`${config.apiUrl}/v1/reservations/checkout`, {
323
334
  method: "POST",
324
335
  headers: {
325
336
  "Content-Type": "application/json",
@@ -379,7 +390,8 @@ async function verifyPhoneCode(token, phoneNumber, code) {
379
390
  }
380
391
  async function getBusinessConfig(businessId) {
381
392
  try {
382
- const response = await fetch(`${API_URL}/v1/businesses/${businessId}`, {
393
+ const config = getGlobalConfig();
394
+ const response = await fetch(`${config.apiUrl}/v1/businesses/${businessId}`, {
383
395
  method: "GET",
384
396
  headers: {
385
397
  "Content-Type": "application/json"
@@ -553,7 +565,8 @@ var businessActions = {
553
565
  try {
554
566
  businessStore.setKey("loading", true);
555
567
  businessStore.setKey("error", null);
556
- const result = await getBusinessConfig(BUSINESS_ID);
568
+ const config = getGlobalConfig();
569
+ const result = await getBusinessConfig(config.businessId);
557
570
  if (result.success) {
558
571
  businessStore.setKey("data", result.data);
559
572
  businessStore.setKey("initialized", true);
@@ -583,9 +596,6 @@ var businessActions = {
583
596
  return businessStore.get().data;
584
597
  }
585
598
  };
586
- if (typeof window !== "undefined" && BUSINESS_ID) {
587
- businessActions.init().catch(console.error);
588
- }
589
599
 
590
600
  // src/api/eshop.ts
591
601
  var eshopApi = {
@@ -597,7 +607,8 @@ var eshopApi = {
597
607
  limit = 20,
598
608
  cursor = null
599
609
  }) {
600
- const url = `${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products`;
610
+ const config = getGlobalConfig();
611
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products`;
601
612
  const response = await http_default.get(url, {
602
613
  params: {
603
614
  categoryIds: categoryIds && categoryIds.length > 0 ? categoryIds : void 0,
@@ -626,7 +637,8 @@ var eshopApi = {
626
637
  // Get product by slug
627
638
  async getProductBySlug({ businessId, slug }) {
628
639
  try {
629
- const url = `${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
640
+ const config = getGlobalConfig();
641
+ const url = `${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/products/slug/${encodeURIComponent(businessId)}/${encodeURIComponent(slug)}`;
630
642
  const res = await fetch(url);
631
643
  if (!res.ok) throw new Error("Product not found");
632
644
  const json = await res.json();
@@ -656,6 +668,7 @@ var eshopApi = {
656
668
  promoCode
657
669
  }) {
658
670
  try {
671
+ const config = getGlobalConfig();
659
672
  const lines = items.map((item) => ({
660
673
  type: "PRODUCT_VARIANT",
661
674
  productId: item.productId,
@@ -672,7 +685,7 @@ var eshopApi = {
672
685
  ...shippingMethodId && { shippingMethodId },
673
686
  ...promoCode && { promoCode }
674
687
  };
675
- const res = await fetch(`${API_URL}/v1/payments/quote`, {
688
+ const res = await fetch(`${config.apiUrl}/v1/payments/quote`, {
676
689
  method: "POST",
677
690
  headers: {
678
691
  "Content-Type": "application/json",
@@ -712,6 +725,7 @@ var eshopApi = {
712
725
  paymentIntentId = null
713
726
  }) {
714
727
  try {
728
+ const config = getGlobalConfig();
715
729
  const payload = {
716
730
  businessId,
717
731
  items,
@@ -722,7 +736,7 @@ var eshopApi = {
722
736
  ...promoCode && { promoCode },
723
737
  ...paymentIntentId && { paymentIntentId }
724
738
  };
725
- const res = await fetch(`${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
739
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/orders/checkout`, {
726
740
  method: "POST",
727
741
  headers: {
728
742
  "Content-Type": "application/json",
@@ -751,12 +765,13 @@ var eshopApi = {
751
765
  // Create payment intent for Stripe
752
766
  async createPaymentIntent({ amount, currency: currency2, businessId }) {
753
767
  try {
768
+ const config = getGlobalConfig();
754
769
  const tokenResponse = await reservationApi.getGuestToken();
755
770
  if (!tokenResponse.success || !tokenResponse.data) {
756
771
  throw new Error("Failed to get guest token");
757
772
  }
758
773
  const token = tokenResponse.data.token;
759
- const res = await fetch(`${API_URL}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
774
+ const res = await fetch(`${config.apiUrl}/v1/businesses/${encodeURIComponent(businessId)}/payment/create-intent`, {
760
775
  method: "POST",
761
776
  headers: {
762
777
  "Content-Type": "application/json",
@@ -903,7 +918,6 @@ var cartItems = persistent.persistentAtom("eshopCart", [], {
903
918
  var promoCodeAtom = nanostores.atom(null);
904
919
  var quoteAtom = nanostores.atom(null);
905
920
  var store = nanostores.deepMap({
906
- businessId: BUSINESS_ID,
907
921
  selectedShippingMethodId: null,
908
922
  // Selected shipping method ID
909
923
  shippingLocation: null,
@@ -1046,10 +1060,11 @@ var actions = {
1046
1060
  if (!shippingMethod) {
1047
1061
  throw new Error("No shipping method available");
1048
1062
  }
1063
+ const config = getGlobalConfig();
1049
1064
  const promo = promoCode !== void 0 ? promoCode : promoCodeAtom.get();
1050
1065
  const response = await eshopApi.checkout({
1051
1066
  token,
1052
- businessId: BUSINESS_ID,
1067
+ businessId: config.businessId,
1053
1068
  items: orderItems,
1054
1069
  paymentMethod,
1055
1070
  blocks,
@@ -1156,11 +1171,12 @@ var actions = {
1156
1171
  try {
1157
1172
  store.setKey("fetchingQuote", true);
1158
1173
  store.setKey("quoteError", null);
1174
+ const config = getGlobalConfig();
1159
1175
  const token = await this.getGuestToken();
1160
1176
  const shippingMethodId = state.selectedShippingMethodId || void 0;
1161
1177
  const response = await eshopApi.getQuote({
1162
1178
  token,
1163
- businessId: BUSINESS_ID,
1179
+ businessId: config.businessId,
1164
1180
  items: items.map((item) => ({
1165
1181
  productId: item.productId,
1166
1182
  variantId: item.variantId,
@@ -1351,9 +1367,6 @@ var store2 = nanostores.deepMap({
1351
1367
  // Service & config
1352
1368
  guestToken: null,
1353
1369
  service: null,
1354
- apiUrl: API_URL,
1355
- businessId: BUSINESS_ID,
1356
- storageUrl: STORAGE_URL,
1357
1370
  timezone: findTimeZone(tzGroups),
1358
1371
  tzGroups,
1359
1372
  parts: []
@@ -1609,8 +1622,9 @@ var actions2 = {
1609
1622
  store2.setKey("loading", true);
1610
1623
  store2.setKey("providers", []);
1611
1624
  try {
1612
- const { businessId, service } = store2.get();
1613
- const res = await reservationApi.getProviders({ businessId, serviceId: service.id });
1625
+ const config = getGlobalConfig();
1626
+ const { service } = store2.get();
1627
+ const res = await reservationApi.getProviders({ businessId: config.businessId, serviceId: service.id });
1614
1628
  store2.setKey("providers", res.success ? res.data : []);
1615
1629
  } catch (e) {
1616
1630
  console.error("Error loading providers:", e);
@@ -1659,7 +1673,8 @@ var actions2 = {
1659
1673
  store2.setKey("loading", false);
1660
1674
  return;
1661
1675
  }
1662
- const params = { businessId: state.businessId, serviceId: state.service.id, from, to, limit };
1676
+ const config = getGlobalConfig();
1677
+ const params = { businessId: config.businessId, serviceId: state.service.id, from, to, limit };
1663
1678
  if (state.selectedProvider) params.providerId = state.selectedProvider.id;
1664
1679
  const result = await reservationApi.getAvailableSlots(params);
1665
1680
  if (!result.success) {
@@ -1932,9 +1947,10 @@ var actions2 = {
1932
1947
  store2.setKey("loading", true);
1933
1948
  try {
1934
1949
  const token = await this.getGuestToken();
1950
+ const config = getGlobalConfig();
1935
1951
  const result = await reservationApi.checkout({
1936
1952
  token,
1937
- businessId: state.businessId,
1953
+ businessId: config.businessId,
1938
1954
  blocks: reservationBlocks3 || [],
1939
1955
  parts: state.parts,
1940
1956
  paymentMethod,
@@ -1975,9 +1991,10 @@ var actions2 = {
1975
1991
  const market = marketObj?.id || "us";
1976
1992
  const curr = currency.get() || "USD";
1977
1993
  console.log("Calling reservationApi.getQuote with:", { market, currency: curr, promoCode });
1994
+ const config = getGlobalConfig();
1978
1995
  const result = await reservationApi.getQuote({
1979
1996
  token,
1980
- businessId: state.businessId,
1997
+ businessId: config.businessId,
1981
1998
  market,
1982
1999
  currency: curr,
1983
2000
  userId: token,