arky-sdk 0.4.0 → 0.4.1

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.js CHANGED
@@ -8,9 +8,10 @@ var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
8
8
 
9
9
  // src/utils/errors.ts
10
10
  var convertServerErrorToRequestError = (serverError, renameRules) => {
11
+ const validationErrors = serverError?.validationErrors ?? [];
11
12
  return {
12
13
  ...serverError,
13
- validationErrors: serverError.validationErrors.map((validationError) => {
14
+ validationErrors: validationErrors.map((validationError) => {
14
15
  const field = validationError.field;
15
16
  return {
16
17
  field,
@@ -44,14 +45,14 @@ function buildQueryString(params) {
44
45
 
45
46
  // src/services/createHttpClient.ts
46
47
  function createHttpClient(cfg) {
47
- const refreshEndpoint = `${cfg.baseUrl}/v1/users/refresh-access-token`;
48
+ const refreshEndpoint = `${cfg.baseUrl}/v1/auth/refresh`;
48
49
  let refreshPromise = null;
49
50
  async function ensureFreshToken() {
50
51
  if (refreshPromise) {
51
52
  return refreshPromise;
52
53
  }
53
54
  refreshPromise = (async () => {
54
- const { refreshToken, provider } = await cfg.getToken();
55
+ const { refreshToken } = await cfg.getToken();
55
56
  if (!refreshToken) {
56
57
  cfg.logout();
57
58
  const err = new Error("No refresh token available");
@@ -62,7 +63,7 @@ function createHttpClient(cfg) {
62
63
  const refRes = await fetch(refreshEndpoint, {
63
64
  method: "POST",
64
65
  headers: { Accept: "application/json", "Content-Type": "application/json" },
65
- body: JSON.stringify({ provider, refreshToken })
66
+ body: JSON.stringify({ refreshToken })
66
67
  });
67
68
  if (!refRes.ok) {
68
69
  cfg.logout();
@@ -87,20 +88,15 @@ function createHttpClient(cfg) {
87
88
  "Content-Type": "application/json",
88
89
  ...options?.headers || {}
89
90
  };
90
- let { accessToken, expiresAt, provider } = await cfg.getToken();
91
+ let { accessToken, expiresAt } = await cfg.getToken();
91
92
  const nowSec = Date.now() / 1e3;
92
93
  if (expiresAt && nowSec > expiresAt) {
93
94
  await ensureFreshToken();
94
95
  const tokens = await cfg.getToken();
95
96
  accessToken = tokens.accessToken;
96
- provider = tokens.provider;
97
97
  }
98
98
  if (accessToken) {
99
- if (provider === "API") {
100
- headers["X-API-Key"] = accessToken;
101
- } else {
102
- headers["Authorization"] = `Bearer ${accessToken}`;
103
- }
99
+ headers["Authorization"] = `Bearer ${accessToken}`;
104
100
  }
105
101
  const finalPath = options?.params ? path + buildQueryString(options.params) : path;
106
102
  const fetchOpts = { method, headers };
@@ -210,32 +206,31 @@ function createHttpClient(cfg) {
210
206
  };
211
207
  }
212
208
 
213
- // src/api/user.ts
214
- var createUserApi = (apiConfig) => {
209
+ // src/api/account.ts
210
+ var createAccountApi = (apiConfig) => {
215
211
  return {
216
- // ===== USER PROFILE =====
217
- async updateUser(params, options) {
212
+ // ===== ACCOUNT PROFILE =====
213
+ async updateAccount(params, options) {
218
214
  const payload = {};
219
- if (params.name !== void 0) payload.name = params.name;
220
215
  if (params.phoneNumbers !== void 0) payload.phoneNumbers = params.phoneNumbers;
221
216
  if (params.addresses !== void 0) payload.addresses = params.addresses;
222
217
  if (params.apiTokens !== void 0) payload.apiTokens = params.apiTokens;
223
- return apiConfig.httpClient.put("/v1/users", payload, options);
218
+ return apiConfig.httpClient.put("/v1/accounts", payload, options);
224
219
  },
225
- async deleteUser(params, options) {
226
- return apiConfig.httpClient.delete("/v1/users", options);
220
+ async deleteAccount(params, options) {
221
+ return apiConfig.httpClient.delete("/v1/accounts", options);
227
222
  },
228
223
  async addPhoneNumber(params, options) {
229
- return apiConfig.httpClient.post("/v1/users/phone-number", params, options);
224
+ return apiConfig.httpClient.post("/v1/accounts/phone-number", params, options);
230
225
  },
231
226
  async phoneNumberConfirm(params, options) {
232
- return apiConfig.httpClient.post("/v1/users/phone-number/confirm", params, options);
227
+ return apiConfig.httpClient.post("/v1/accounts/phone-number/confirm", params, options);
233
228
  },
234
229
  async getMe(params, options) {
235
- return apiConfig.httpClient.get("/v1/users/me", options);
230
+ return apiConfig.httpClient.get("/v1/accounts/me", options);
236
231
  },
237
- async searchUsers(params, options) {
238
- return apiConfig.httpClient.get("/v1/users/search", {
232
+ async searchAccounts(params, options) {
233
+ return apiConfig.httpClient.get("/v1/accounts/search", {
239
234
  ...options,
240
235
  params: {
241
236
  ...params,
@@ -243,40 +238,99 @@ var createUserApi = (apiConfig) => {
243
238
  }
244
239
  });
245
240
  },
246
- async setRole(params, options) {
247
- return apiConfig.httpClient.put("/v1/users/set-role", params, options);
248
- },
249
- // ===== AUTHENTICATION =====
250
- async loginUser(params, options) {
251
- return apiConfig.httpClient.post("/v1/users/login", params, options);
241
+ // ===== SUBSCRIPTION =====
242
+ async subscribe(params, options) {
243
+ return apiConfig.httpClient.post("/v1/accounts/subscribe", params, options);
244
+ }
245
+ };
246
+ };
247
+
248
+ // src/api/auth.ts
249
+ var createAuthApi = (apiConfig) => {
250
+ return {
251
+ /**
252
+ * Create a guest session (anonymous user)
253
+ * POST /auth/session
254
+ */
255
+ async session(options) {
256
+ return apiConfig.httpClient.post("/v1/auth/session", {}, options);
252
257
  },
253
- async registerUser(params, options) {
254
- return apiConfig.httpClient.post("/v1/users/register", params, options);
258
+ /**
259
+ * Sign in anonymously (creates guest session if not already authenticated)
260
+ * Following Firebase/Supabase pattern - idempotent, safe to call multiple times
261
+ */
262
+ async signInAnonymously(options) {
263
+ const tokens = await apiConfig.getToken();
264
+ if (tokens?.accessToken) {
265
+ return tokens;
266
+ }
267
+ const result = await apiConfig.httpClient.post("/v1/auth/session", {}, options);
268
+ if (result?.accessToken) {
269
+ apiConfig.setToken({ ...result, isGuest: true });
270
+ }
271
+ return result;
255
272
  },
256
- async logout(params, options) {
257
- return apiConfig.httpClient.post("/v1/users/logout", {}, options);
273
+ /**
274
+ * Check if current user is a guest (anonymous)
275
+ * Guest emails follow pattern: guest+uuid@arky.io
276
+ */
277
+ async isGuest() {
278
+ const tokens = await apiConfig.getToken();
279
+ if (!tokens?.accessToken) return true;
280
+ const email = tokens.email || "";
281
+ return !email || email.startsWith("guest+");
258
282
  },
259
- async confirmUser(params, options) {
260
- return apiConfig.httpClient.put("/v1/users/confirm", params, options);
283
+ // ==================== PLATFORM AUTH (Admin) ====================
284
+ /**
285
+ * Request platform auth code (Arky admin)
286
+ * POST /auth/code
287
+ */
288
+ async code(params, options) {
289
+ return apiConfig.httpClient.post("/v1/auth/code", params, options);
261
290
  },
262
- async getLoginUrl(params, options) {
263
- return apiConfig.httpClient.get("/v1/users/login/url", {
264
- ...options,
265
- params
266
- });
291
+ /**
292
+ * Verify platform auth code - automatically sets token on success
293
+ * POST /auth/verify
294
+ */
295
+ async verify(params, options) {
296
+ const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
297
+ if (result?.accessToken) {
298
+ apiConfig.setToken({ ...result, email: params.email, isGuest: false });
299
+ }
300
+ return result;
267
301
  },
268
- // ===== PASSWORD MANAGEMENT =====
269
- async forgotPassword(params, options) {
270
- return apiConfig.httpClient.post("/v1/users/forgot-password", params, options);
302
+ /**
303
+ * Refresh access token
304
+ * POST /auth/refresh
305
+ */
306
+ async refresh(params, options) {
307
+ return apiConfig.httpClient.post("/v1/auth/refresh", params, options);
271
308
  },
272
- async resetForgotPassword(params, options) {
273
- return apiConfig.httpClient.post("/v1/users/reset-forgot-password", params, options);
309
+ // ==================== BUSINESS AUTH (arky.io, delfin, korvus) ====================
310
+ /**
311
+ * Request business auth code
312
+ * POST /businesses/{businessId}/auth/code
313
+ */
314
+ async businessCode(businessId, params, options) {
315
+ return apiConfig.httpClient.post(`/v1/businesses/${businessId}/auth/code`, params, options);
274
316
  },
275
- async resetPassword(params, options) {
276
- return apiConfig.httpClient.post("/v1/users/reset-password", params, options);
317
+ /**
318
+ * Verify business auth code - automatically sets token on success
319
+ * POST /businesses/{businessId}/auth/verify
320
+ */
321
+ async businessVerify(businessId, params, options) {
322
+ const result = await apiConfig.httpClient.post(`/v1/businesses/${businessId}/auth/verify`, params, options);
323
+ if (result?.accessToken) {
324
+ apiConfig.setToken({ ...result, email: params.email, isGuest: false });
325
+ }
326
+ return result;
277
327
  },
278
- async subscribe(params, options) {
279
- return apiConfig.httpClient.post("/v1/users/subscribe", params, options);
328
+ // ==================== DEPRECATED (for backwards compatibility) ====================
329
+ /**
330
+ * @deprecated Use code() instead
331
+ */
332
+ async magicLink(params, options) {
333
+ return apiConfig.httpClient.post("/v1/auth/code", params, options);
280
334
  }
281
335
  };
282
336
  };
@@ -307,7 +361,10 @@ var createBusinessApi = (apiConfig) => {
307
361
  );
308
362
  },
309
363
  async getBusinesses(params, options) {
310
- return apiConfig.httpClient.get(`/v1/businesses`, options);
364
+ return apiConfig.httpClient.get(`/v1/businesses`, {
365
+ ...options,
366
+ params
367
+ });
311
368
  },
312
369
  async getBusinessParents(params, options) {
313
370
  return apiConfig.httpClient.get(
@@ -367,22 +424,20 @@ var createBusinessApi = (apiConfig) => {
367
424
  );
368
425
  },
369
426
  async getBusinessMedia(params, options) {
427
+ const queryParams = {
428
+ limit: params.limit
429
+ };
430
+ if (params.cursor) queryParams.cursor = params.cursor;
431
+ if (params.ids && params.ids.length > 0) queryParams.ids = params.ids.join(",");
432
+ if (params.query) queryParams.query = params.query;
433
+ if (params.mimeType) queryParams.mimeType = params.mimeType;
434
+ if (params.sortField) queryParams.sortField = params.sortField;
435
+ if (params.sortDirection) queryParams.sortDirection = params.sortDirection;
370
436
  return apiConfig.httpClient.get(`/v1/businesses/${params.id}/media`, {
371
437
  ...options,
372
- params: {
373
- cursor: params.cursor,
374
- limit: params.limit || 20
375
- }
438
+ params: queryParams
376
439
  });
377
440
  },
378
- async setProviderSchedule(params, options) {
379
- const { id, ...payload } = params;
380
- return apiConfig.httpClient.put(
381
- `/v1/businesses/${id}/schedules`,
382
- payload,
383
- options
384
- );
385
- },
386
441
  async processRefund(params, options) {
387
442
  const { id, ...payload } = params;
388
443
  return apiConfig.httpClient.post(
@@ -398,11 +453,12 @@ var createBusinessApi = (apiConfig) => {
398
453
  var createMediaApi = (apiConfig) => {
399
454
  return {
400
455
  async uploadBusinessMedia(params, options) {
401
- const { files = [], urls = [] } = params;
402
- const url = `${apiConfig.baseUrl}/v1/businesses/${apiConfig.businessId}/media`;
456
+ const { businessId, files = [], urls = [] } = params;
457
+ const targetBusinessId = businessId || apiConfig.businessId;
458
+ const url = `${apiConfig.baseUrl}/v1/businesses/${targetBusinessId}/media`;
403
459
  const formData = new FormData();
404
460
  files.forEach((file) => formData.append("files", file));
405
- urls.forEach((url2) => formData.append("files", url2));
461
+ urls.forEach((url2) => formData.append("urls", url2));
406
462
  const tokens = await apiConfig.getToken();
407
463
  const response = await fetch(url, {
408
464
  method: "POST",
@@ -424,12 +480,23 @@ var createMediaApi = (apiConfig) => {
424
480
  );
425
481
  },
426
482
  async getBusinessMedia(params, options) {
427
- const { cursor = null, limit = 20 } = params;
428
- const url = `${apiConfig.baseUrl}/v1/businesses/${apiConfig.businessId}/media`;
429
- const queryParams = { limit };
483
+ const { businessId, cursor, limit, ids, query, mimeType, sortField, sortDirection } = params;
484
+ const targetBusinessId = businessId || apiConfig.businessId;
485
+ const url = `${apiConfig.baseUrl}/v1/businesses/${targetBusinessId}/media`;
486
+ const queryParams = { limit: String(limit) };
430
487
  if (cursor) queryParams.cursor = cursor;
488
+ if (ids && ids.length > 0) queryParams.ids = ids.join(",");
489
+ if (query) queryParams.query = query;
490
+ if (mimeType) queryParams.mimeType = mimeType;
491
+ if (sortField) queryParams.sortField = sortField;
492
+ if (sortDirection) queryParams.sortDirection = sortDirection;
431
493
  const queryString = new URLSearchParams(queryParams).toString();
432
- const response = await fetch(`${url}?${queryString}`);
494
+ const tokens = await apiConfig.getToken();
495
+ const response = await fetch(`${url}?${queryString}`, {
496
+ headers: {
497
+ Authorization: `Bearer ${tokens.accessToken}`
498
+ }
499
+ });
433
500
  if (!response.ok) {
434
501
  const errorData = await response.json().catch(() => null);
435
502
  throw new Error(errorData?.message || "Failed to fetch media");
@@ -437,9 +504,10 @@ var createMediaApi = (apiConfig) => {
437
504
  return await response.json();
438
505
  },
439
506
  async updateMedia(params, options) {
440
- const { mediaId, ...updateData } = params;
507
+ const { mediaId, businessId, ...updateData } = params;
508
+ const targetBusinessId = businessId || apiConfig.businessId;
441
509
  return apiConfig.httpClient.put(
442
- `/v1/businesses/${apiConfig.businessId}/media/${mediaId}`,
510
+ `/v1/businesses/${targetBusinessId}/media/${mediaId}`,
443
511
  updateData,
444
512
  options
445
513
  );
@@ -447,37 +515,6 @@ var createMediaApi = (apiConfig) => {
447
515
  };
448
516
  };
449
517
 
450
- // src/api/role.ts
451
- var createRoleApi = (apiConfig) => {
452
- return {
453
- async createRole(params, options) {
454
- return apiConfig.httpClient.post(`/v1/roles`, params, options);
455
- },
456
- async updateRole(params, options) {
457
- return apiConfig.httpClient.put(
458
- `/v1/roles/${params.id}`,
459
- params,
460
- options
461
- );
462
- },
463
- async deleteRole(params, options) {
464
- return apiConfig.httpClient.delete(`/v1/roles/${params.id}`, options);
465
- },
466
- async getRole(params, options) {
467
- return apiConfig.httpClient.get(`/v1/roles/${params.id}`, options);
468
- },
469
- async getRoles(params, options) {
470
- return apiConfig.httpClient.get(`/v1/roles`, {
471
- ...options,
472
- params: {
473
- action: params.action,
474
- businessId: apiConfig.businessId
475
- }
476
- });
477
- }
478
- };
479
- };
480
-
481
518
  // src/api/notification.ts
482
519
  var createNotificationApi = (apiConfig) => {
483
520
  return {
@@ -546,21 +583,6 @@ var createAnalyticsApi = (apiConfig) => {
546
583
  };
547
584
  };
548
585
 
549
- // src/utils/slug.ts
550
- var isUuid = (str) => {
551
- const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
552
- return uuidRegex.test(str);
553
- };
554
- var formatIdOrSlug = (id, apiConfig) => {
555
- if (isUuid(id)) {
556
- return id;
557
- }
558
- if (id.includes(":")) {
559
- return id;
560
- }
561
- return `${apiConfig.businessId}:${apiConfig.locale}:${id}`;
562
- };
563
-
564
586
  // src/utils/blocks.ts
565
587
  function getBlockLabel(block, locale = "en") {
566
588
  if (!block) return "";
@@ -660,7 +682,7 @@ function unwrapBlock(block, locale) {
660
682
  return parsed;
661
683
  });
662
684
  }
663
- const isLocalized = block.type === "TEXT";
685
+ const isLocalized = block.type === "LOCALIZED_TEXT" || block.type === "MARKDOWN";
664
686
  const isList = block.properties?.ui === "list" || (block.properties?.maxValues ?? 1) > 1 || block.value.length > 1;
665
687
  if (isList) {
666
688
  return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
@@ -672,7 +694,13 @@ var getBlockObjectValues = (entry, blockKey, locale = "en") => {
672
694
  return [];
673
695
  }
674
696
  const values = getBlockValues(entry, blockKey);
697
+ if (!values || !Array.isArray(values)) {
698
+ return [];
699
+ }
675
700
  const parsed = values.map((obj) => {
701
+ if (!obj || !obj.value || !Array.isArray(obj.value)) {
702
+ return {};
703
+ }
676
704
  const res = obj.value.reduce((acc, current) => {
677
705
  acc[current.key] = unwrapBlock(current, locale);
678
706
  return acc;
@@ -683,13 +711,16 @@ var getBlockObjectValues = (entry, blockKey, locale = "en") => {
683
711
  };
684
712
  var getBlockFromArray = (entry, blockKey, locale = "en") => {
685
713
  if (!entry) {
686
- return [];
714
+ return {};
687
715
  }
688
716
  const values = getBlockValues(entry, blockKey);
717
+ if (!values || !Array.isArray(values)) {
718
+ return {};
719
+ }
689
720
  return values.reduce((acc, current) => {
690
721
  acc[current.key] = unwrapBlock(current, locale);
691
722
  return acc;
692
- });
723
+ }, {});
693
724
  };
694
725
  var getImageUrl = (imageBlock, isBlock = true) => {
695
726
  if (!imageBlock) return null;
@@ -722,31 +753,45 @@ var getImageUrl = (imageBlock, isBlock = true) => {
722
753
  // src/api/cms.ts
723
754
  var createCmsApi = (apiConfig) => {
724
755
  return {
725
- // ===== COLLECTIONS =====
726
- async createCollection(params, options) {
756
+ async createNode(params, options) {
757
+ const { businessId, ...payload } = params;
758
+ const targetBusinessId = businessId || apiConfig.businessId;
727
759
  return apiConfig.httpClient.post(
728
- `/v1/businesses/${apiConfig.businessId}/collections`,
729
- params,
760
+ `/v1/businesses/${targetBusinessId}/nodes`,
761
+ payload,
730
762
  options
731
763
  );
732
764
  },
733
- async updateCollection(params, options) {
765
+ async updateNode(params, options) {
766
+ const { businessId, ...payload } = params;
767
+ const targetBusinessId = businessId || apiConfig.businessId;
734
768
  return apiConfig.httpClient.put(
735
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
736
- params,
769
+ `/v1/businesses/${targetBusinessId}/nodes/${params.id}`,
770
+ payload,
737
771
  options
738
772
  );
739
773
  },
740
- async deleteCollection(params, options) {
774
+ async deleteNode(params, options) {
775
+ const targetBusinessId = params.businessId || apiConfig.businessId;
741
776
  return apiConfig.httpClient.delete(
742
- `/v1/businesses/${apiConfig.businessId}/collections/${params.id}`,
777
+ `/v1/businesses/${targetBusinessId}/nodes/${params.id}`,
743
778
  options
744
779
  );
745
780
  },
746
- async getCollection(params, options) {
747
- const formattedId = formatIdOrSlug(params.id, apiConfig);
781
+ async getNode(params, options) {
782
+ const targetBusinessId = params.businessId || apiConfig.businessId;
783
+ let identifier;
784
+ if (params.id) {
785
+ identifier = params.id;
786
+ } else if (params.slug) {
787
+ identifier = `${targetBusinessId}:${apiConfig.locale}:${params.slug}`;
788
+ } else if (params.key) {
789
+ identifier = `${targetBusinessId}:${params.key}`;
790
+ } else {
791
+ throw new Error("GetNodeParams requires id, slug, or key");
792
+ }
748
793
  const response = await apiConfig.httpClient.get(
749
- `/v1/businesses/${apiConfig.businessId}/collections/${formattedId}`,
794
+ `/v1/businesses/${targetBusinessId}/nodes/${identifier}`,
750
795
  options
751
796
  );
752
797
  return {
@@ -763,86 +808,38 @@ var createCmsApi = (apiConfig) => {
763
808
  }
764
809
  };
765
810
  },
766
- async getCollections(params, options) {
811
+ async getNodes(params, options) {
812
+ const { businessId, ...queryParams } = params;
813
+ const targetBusinessId = businessId || apiConfig.businessId;
767
814
  return apiConfig.httpClient.get(
768
- `/v1/businesses/${apiConfig.businessId}/collections`,
815
+ `/v1/businesses/${targetBusinessId}/nodes`,
769
816
  {
770
817
  ...options,
771
- params
818
+ params: queryParams
772
819
  }
773
820
  );
774
821
  },
775
- async generateBlocks(params, options) {
776
- return apiConfig.httpClient.post(
777
- `/v1/businesses/${apiConfig.businessId}/collections/blocks/generate`,
778
- params,
779
- options
780
- );
781
- },
782
- // ===== ENTRIES =====
783
- async getCollectionEntries(params, options) {
784
- const { collectionId, ...queryParams } = params;
822
+ async getNodeChildren(params, options) {
823
+ const { id, businessId, ...queryParams } = params;
824
+ const targetBusinessId = businessId || apiConfig.businessId;
785
825
  return apiConfig.httpClient.get(
786
- `/v1/businesses/${apiConfig.businessId}/collections/${collectionId}/entries`,
826
+ `/v1/businesses/${targetBusinessId}/nodes/${id}/children`,
787
827
  {
788
828
  ...options,
789
829
  params: queryParams
790
830
  }
791
831
  );
792
832
  },
793
- async createCollectionEntry(params, options) {
794
- const { collectionId, ...payload } = params;
795
- return apiConfig.httpClient.post(
796
- `/v1/businesses/${apiConfig.businessId}/collections/${collectionId}/entries`,
797
- { ...payload, collectionId },
798
- options
799
- );
800
- },
801
- async updateCollectionEntry(params, options) {
802
- const { collectionId, id, ...payload } = params;
803
- return apiConfig.httpClient.put(
804
- `/v1/businesses/${apiConfig.businessId}/collections/${collectionId}/entries/${id}`,
805
- { ...payload, collectionId },
806
- options
807
- );
808
- },
809
- async deleteCollectionEntry(params, options) {
810
- return apiConfig.httpClient.delete(
811
- `/v1/businesses/${apiConfig.businessId}/collections/${params.collectionId}/entries/${params.id}`,
812
- options
813
- );
814
- },
815
- async getCollectionEntry(params, options) {
816
- const formattedId = formatIdOrSlug(params.id, apiConfig);
817
- return apiConfig.httpClient.get(
818
- `/v1/businesses/${apiConfig.businessId}/collections/${params.collectionId}/entries/${formattedId}`,
819
- options
820
- );
821
- },
822
- async sendEntry(params, options) {
823
- const { collectionId, entryId, scheduledAt } = params;
833
+ async generateBlocks(params, options) {
824
834
  return apiConfig.httpClient.post(
825
- `/v1/businesses/${apiConfig.businessId}/collections/${collectionId}/entries/${entryId}/send`,
826
- {
827
- businessId: apiConfig.businessId,
828
- entryId,
829
- scheduledAt: scheduledAt ?? Math.floor(Date.now() / 1e3)
830
- },
835
+ `/v1/businesses/${apiConfig.businessId}/nodes/blocks/generate`,
836
+ params,
831
837
  options
832
838
  );
833
839
  },
834
- // ===== VARIABLES / METADATA =====
835
840
  async getVariableMetadata(params, options) {
836
841
  return apiConfig.httpClient.get(
837
- `/v1/collections/entry-types/${params.entryType}/variables`,
838
- options
839
- );
840
- },
841
- // ===== COLLECTION SUBSCRIPTIONS =====
842
- async getCollectionSubscribers(params, options) {
843
- const formattedId = formatIdOrSlug(params.id, apiConfig);
844
- return apiConfig.httpClient.get(
845
- `/v1/businesses/${apiConfig.businessId}/collections/${formattedId}/subscribers`,
842
+ `/v1/businesses/${apiConfig.businessId}/nodes/types/${params.nodeType}/variables`,
846
843
  options
847
844
  );
848
845
  }
@@ -874,22 +871,18 @@ var createEshopApi = (apiConfig) => {
874
871
  );
875
872
  },
876
873
  async getProduct(params, options) {
877
- const formattedId = formatIdOrSlug(params.id, apiConfig);
878
- const response = await apiConfig.httpClient.get(
879
- `/v1/businesses/${apiConfig.businessId}/products/${formattedId}`,
874
+ let identifier;
875
+ if (params.id) {
876
+ identifier = params.id;
877
+ } else if (params.slug) {
878
+ identifier = `${apiConfig.businessId}:${apiConfig.locale}:${params.slug}`;
879
+ } else {
880
+ throw new Error("GetProductParams requires id or slug");
881
+ }
882
+ return apiConfig.httpClient.get(
883
+ `/v1/businesses/${apiConfig.businessId}/products/${identifier}`,
880
884
  options
881
885
  );
882
- return {
883
- ...response,
884
- getName() {
885
- const locale = apiConfig.locale;
886
- return response.name?.[locale] || response.name?.en || response.name || "";
887
- },
888
- getDescription() {
889
- const locale = apiConfig.locale;
890
- return response.description?.[locale] || response.description?.en || response.description || "";
891
- }
892
- };
893
886
  },
894
887
  async getProducts(params, options) {
895
888
  return apiConfig.httpClient.get(
@@ -910,7 +903,7 @@ var createEshopApi = (apiConfig) => {
910
903
  },
911
904
  async updateOrder(params, options) {
912
905
  return apiConfig.httpClient.put(
913
- `/v1/businesses/${apiConfig.businessId}/orders/update`,
906
+ `/v1/businesses/${apiConfig.businessId}/orders/${params.id}`,
914
907
  params,
915
908
  options
916
909
  );
@@ -930,42 +923,31 @@ var createEshopApi = (apiConfig) => {
930
923
  }
931
924
  );
932
925
  },
933
- async updateOrderStatus(params, options) {
934
- return apiConfig.httpClient.put(
935
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/status`,
936
- params,
937
- options
938
- );
939
- },
940
- async updateOrderPaymentStatus(params, options) {
941
- return apiConfig.httpClient.put(
942
- `/v1/businesses/${apiConfig.businessId}/orders/${params.id}/payment-status`,
943
- params,
944
- options
945
- );
946
- },
947
926
  // ===== PAYMENTS =====
948
927
  async getQuote(params, options) {
949
- const lines = params.items.map((item) => ({
950
- type: "PRODUCT_VARIANT",
951
- productId: item.productId,
952
- variantId: item.variantId,
953
- quantity: item.quantity
954
- }));
955
- const { items, ...rest } = params;
956
928
  const payload = {
957
- businessId: apiConfig.businessId,
958
929
  market: apiConfig.market,
959
- lines,
960
- ...rest
930
+ items: params.items,
931
+ blocks: params.blocks || [],
932
+ paymentMethodId: params.paymentMethodId,
933
+ shippingMethodId: params.shippingMethodId,
934
+ promoCode: params.promoCode
961
935
  };
962
- return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
936
+ return apiConfig.httpClient.post(
937
+ `/v1/businesses/${apiConfig.businessId}/orders/quote`,
938
+ payload,
939
+ options
940
+ );
963
941
  },
964
942
  async checkout(params, options) {
965
943
  const payload = {
966
944
  businessId: apiConfig.businessId,
967
945
  market: apiConfig.market,
968
- ...params
946
+ items: params.items,
947
+ blocks: params.blocks || [],
948
+ paymentMethodId: params.paymentMethodId,
949
+ shippingMethodId: params.shippingMethodId,
950
+ promoCodeId: params.promoCodeId
969
951
  };
970
952
  return apiConfig.httpClient.post(
971
953
  `/v1/businesses/${apiConfig.businessId}/orders/checkout`,
@@ -995,129 +977,131 @@ var createReservationApi = (apiConfig) => {
995
977
  },
996
978
  // ===== RESERVATIONS =====
997
979
  async createReservation(params, options) {
980
+ const { businessId, ...rest } = params;
981
+ const targetBusinessId = businessId || apiConfig.businessId;
998
982
  const payload = {
999
- businessId: apiConfig.businessId,
1000
983
  market: apiConfig.market,
1001
- ...params
984
+ ...rest
1002
985
  };
1003
- return apiConfig.httpClient.post(`/v1/reservations`, payload, options);
986
+ return apiConfig.httpClient.post(
987
+ `/v1/businesses/${targetBusinessId}/reservations`,
988
+ payload,
989
+ options
990
+ );
1004
991
  },
1005
992
  async updateReservation(params, options) {
1006
993
  const { id, ...payload } = params;
1007
994
  return apiConfig.httpClient.put(
1008
- `/v1/reservations/${id}`,
995
+ `/v1/businesses/${apiConfig.businessId}/reservations/${id}`,
1009
996
  payload,
1010
997
  options
1011
998
  );
1012
999
  },
1013
1000
  async checkout(params, options) {
1014
- const items = params?.items || cart.map((s) => ({
1001
+ const { businessId, ...rest } = params || {};
1002
+ const targetBusinessId = businessId || apiConfig.businessId;
1003
+ const items = rest?.items || cart.map((s) => ({
1015
1004
  serviceId: s.serviceId,
1016
1005
  providerId: s.providerId,
1017
1006
  from: s.from,
1018
1007
  to: s.to
1019
1008
  }));
1020
1009
  const payload = {
1021
- businessId: apiConfig.businessId,
1022
1010
  market: apiConfig.market,
1023
- ...params,
1011
+ ...rest,
1024
1012
  items
1025
1013
  };
1026
1014
  return apiConfig.httpClient.post(
1027
- `/v1/reservations/checkout`,
1015
+ `/v1/businesses/${targetBusinessId}/reservations/checkout`,
1028
1016
  payload,
1029
1017
  options
1030
1018
  );
1031
1019
  },
1032
1020
  async getReservation(params, options) {
1033
- return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
1034
- ...options,
1035
- params: { businessId: apiConfig.businessId }
1036
- });
1021
+ const targetBusinessId = params.businessId || apiConfig.businessId;
1022
+ return apiConfig.httpClient.get(
1023
+ `/v1/businesses/${targetBusinessId}/reservations/${params.id}`,
1024
+ options
1025
+ );
1037
1026
  },
1038
1027
  async searchReservations(params, options) {
1039
- return apiConfig.httpClient.get(`/v1/reservations/search`, {
1040
- ...options,
1041
- params: {
1042
- ...params,
1043
- businessId: apiConfig.businessId
1028
+ const { businessId, ...queryParams } = params;
1029
+ const targetBusinessId = businessId || apiConfig.businessId;
1030
+ return apiConfig.httpClient.get(
1031
+ `/v1/businesses/${targetBusinessId}/reservations`,
1032
+ {
1033
+ ...options,
1034
+ params: queryParams
1044
1035
  }
1045
- });
1046
- },
1047
- async searchMyReservations(params, options) {
1048
- return apiConfig.httpClient.get(`/v1/reservations`, {
1049
- ...options,
1050
- params
1051
- });
1036
+ );
1052
1037
  },
1053
1038
  // ===== QUOTES =====
1054
1039
  async getQuote(params, options) {
1055
- const lines = params.items.map((item) => ({
1056
- type: "SERVICE",
1057
- serviceId: item.serviceId,
1058
- quantity: 1
1059
- }));
1060
- const { items, ...rest } = params;
1040
+ const { businessId, ...rest } = params;
1041
+ const targetBusinessId = businessId || apiConfig.businessId;
1061
1042
  const payload = {
1062
- businessId: apiConfig.businessId,
1063
1043
  market: apiConfig.market,
1064
- lines,
1065
1044
  ...rest
1066
1045
  };
1067
- return apiConfig.httpClient.post(`/v1/payments/quote`, payload, options);
1046
+ return apiConfig.httpClient.post(
1047
+ `/v1/businesses/${targetBusinessId}/reservations/quote`,
1048
+ payload,
1049
+ options
1050
+ );
1068
1051
  },
1069
1052
  // ===== SERVICES =====
1070
1053
  async createService(params, options) {
1054
+ const { businessId, ...payload } = params;
1055
+ const targetBusinessId = businessId || apiConfig.businessId;
1071
1056
  return apiConfig.httpClient.post(
1072
- `/v1/businesses/${apiConfig.businessId}/services`,
1073
- params,
1057
+ `/v1/businesses/${targetBusinessId}/services`,
1058
+ payload,
1074
1059
  options
1075
1060
  );
1076
1061
  },
1077
1062
  async updateService(params, options) {
1063
+ const { businessId, ...payload } = params;
1064
+ const targetBusinessId = businessId || apiConfig.businessId;
1078
1065
  return apiConfig.httpClient.put(
1079
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
1080
- params,
1066
+ `/v1/businesses/${targetBusinessId}/services/${params.id}`,
1067
+ payload,
1081
1068
  options
1082
1069
  );
1083
1070
  },
1084
1071
  async deleteService(params, options) {
1072
+ const targetBusinessId = params.businessId || apiConfig.businessId;
1085
1073
  return apiConfig.httpClient.delete(
1086
- `/v1/businesses/${apiConfig.businessId}/services/${params.id}`,
1074
+ `/v1/businesses/${targetBusinessId}/services/${params.id}`,
1087
1075
  options
1088
1076
  );
1089
1077
  },
1090
- async getService(params, options) {
1091
- const formattedId = formatIdOrSlug(params.id, apiConfig);
1092
- const response = await apiConfig.httpClient.get(
1093
- `/v1/businesses/${apiConfig.businessId}/services/${formattedId}`,
1078
+ async bulkSchedule(params, options) {
1079
+ return apiConfig.httpClient.post(
1080
+ `/v1/businesses/${apiConfig.businessId}/services/bulk-schedule`,
1081
+ params,
1094
1082
  options
1095
1083
  );
1096
- return {
1097
- ...response,
1098
- getName() {
1099
- const locale = apiConfig.locale;
1100
- return response.name?.[locale] || response.name?.en || response.name || "";
1101
- },
1102
- getDescription() {
1103
- const locale = apiConfig.locale;
1104
- return response.description?.[locale] || response.description?.en || response.description || "";
1105
- }
1106
- };
1107
1084
  },
1108
- async getServices(params, options) {
1085
+ async getService(params, options) {
1086
+ const businessId = params.businessId || apiConfig.businessId;
1087
+ let identifier;
1088
+ if (params.id) {
1089
+ identifier = params.id;
1090
+ } else if (params.slug) {
1091
+ identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
1092
+ } else {
1093
+ throw new Error("GetServiceParams requires id or slug");
1094
+ }
1109
1095
  return apiConfig.httpClient.get(
1110
- `/v1/businesses/${apiConfig.businessId}/services`,
1111
- {
1112
- ...options,
1113
- params
1114
- }
1096
+ `/v1/businesses/${businessId}/services/${identifier}`,
1097
+ options
1115
1098
  );
1116
1099
  },
1117
- async getServiceProviders(params, options) {
1118
- const { serviceId, ...queryParams } = params;
1100
+ async getServices(params, options) {
1101
+ const { businessId, ...queryParams } = params;
1102
+ const targetBusinessId = businessId || apiConfig.businessId;
1119
1103
  return apiConfig.httpClient.get(
1120
- `/v1/businesses/${apiConfig.businessId}/services/${serviceId}/providers`,
1104
+ `/v1/businesses/${targetBusinessId}/services`,
1121
1105
  {
1122
1106
  ...options,
1123
1107
  params: queryParams
@@ -1126,37 +1110,53 @@ var createReservationApi = (apiConfig) => {
1126
1110
  },
1127
1111
  // ===== PROVIDERS =====
1128
1112
  async createProvider(params, options) {
1113
+ const { businessId, ...payload } = params;
1114
+ const targetBusinessId = businessId || apiConfig.businessId;
1129
1115
  return apiConfig.httpClient.post(
1130
- `/v1/businesses/${apiConfig.businessId}/providers`,
1131
- params,
1116
+ `/v1/businesses/${targetBusinessId}/providers`,
1117
+ payload,
1132
1118
  options
1133
1119
  );
1134
1120
  },
1135
1121
  async updateProvider(params, options) {
1122
+ const { businessId, ...payload } = params;
1123
+ const targetBusinessId = businessId || apiConfig.businessId;
1136
1124
  return apiConfig.httpClient.put(
1137
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
1138
- params,
1125
+ `/v1/businesses/${targetBusinessId}/providers/${params.id}`,
1126
+ payload,
1139
1127
  options
1140
1128
  );
1141
1129
  },
1142
1130
  async deleteProvider(params, options) {
1131
+ const targetBusinessId = params.businessId || apiConfig.businessId;
1143
1132
  return apiConfig.httpClient.delete(
1144
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
1133
+ `/v1/businesses/${targetBusinessId}/providers/${params.id}`,
1145
1134
  options
1146
1135
  );
1147
1136
  },
1148
1137
  async getProvider(params, options) {
1138
+ const businessId = params.businessId || apiConfig.businessId;
1139
+ let identifier;
1140
+ if (params.id) {
1141
+ identifier = params.id;
1142
+ } else if (params.slug) {
1143
+ identifier = `${businessId}:${apiConfig.locale}:${params.slug}`;
1144
+ } else {
1145
+ throw new Error("GetProviderParams requires id or slug");
1146
+ }
1149
1147
  return apiConfig.httpClient.get(
1150
- `/v1/businesses/${apiConfig.businessId}/providers/${params.id}`,
1148
+ `/v1/businesses/${businessId}/providers/${identifier}`,
1151
1149
  options
1152
1150
  );
1153
1151
  },
1154
1152
  async getProviders(params, options) {
1153
+ const { businessId, ...queryParams } = params;
1154
+ const targetBusinessId = businessId || apiConfig.businessId;
1155
1155
  return apiConfig.httpClient.get(
1156
- `/v1/businesses/${apiConfig.businessId}/providers`,
1156
+ `/v1/businesses/${targetBusinessId}/providers`,
1157
1157
  {
1158
1158
  ...options,
1159
- params
1159
+ params: queryParams
1160
1160
  }
1161
1161
  );
1162
1162
  },
@@ -1182,7 +1182,8 @@ var createDatabaseApi = (apiConfig) => {
1182
1182
  {
1183
1183
  ...options,
1184
1184
  params: {
1185
- key: params.key
1185
+ key: params.key,
1186
+ limit: params.limit || 200
1186
1187
  }
1187
1188
  }
1188
1189
  );
@@ -1212,144 +1213,216 @@ var createDatabaseApi = (apiConfig) => {
1212
1213
  };
1213
1214
  };
1214
1215
 
1215
- // src/api/featureFlags.ts
1216
- var createFeatureFlagsApi = (apiConfig) => {
1216
+ // src/api/location.ts
1217
+ var createLocationApi = (apiConfig) => {
1217
1218
  return {
1218
- /**
1219
- * Create a new feature flag
1220
- */
1221
- async createFlag(params, options) {
1222
- return apiConfig.httpClient.post(
1223
- `/v1/businesses/${apiConfig.businessId}/feature-flags`,
1224
- params,
1225
- options
1226
- );
1219
+ async getCountries(options) {
1220
+ return apiConfig.httpClient.get(`/v1/operations/location/countries`, options);
1227
1221
  },
1228
- /**
1229
- * Get a feature flag by ID
1230
- */
1231
- async getFlag(params, options) {
1222
+ async getCountryStates(countryCode, options) {
1232
1223
  return apiConfig.httpClient.get(
1233
- `/v1/businesses/${apiConfig.businessId}/feature-flags/${params.id}`,
1224
+ `/v1/operations/location/countries/${countryCode}/states`,
1234
1225
  options
1235
1226
  );
1227
+ }
1228
+ };
1229
+ };
1230
+
1231
+ // src/api/network.ts
1232
+ var createNetworkApi = (apiConfig) => {
1233
+ return {
1234
+ /**
1235
+ * Search services across all businesses that have opted into a network
1236
+ * @param networkKey - The network key (e.g., "delfin")
1237
+ * @param params - Search parameters
1238
+ */
1239
+ async searchServices(networkKey, params, options) {
1240
+ const queryParams = {};
1241
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
1242
+ if (params?.cursor) queryParams.cursor = params.cursor;
1243
+ if (params?.query) queryParams.query = params.query;
1244
+ if (params?.nodeId) queryParams.nodeId = params.nodeId;
1245
+ if (params?.nodeIds && params.nodeIds.length > 0)
1246
+ queryParams.nodeIds = params.nodeIds.join(",");
1247
+ if (params?.statuses && params.statuses.length > 0)
1248
+ queryParams.statuses = params.statuses.join(",");
1249
+ if (params?.sortField) queryParams.sortField = params.sortField;
1250
+ if (params?.sortDirection) queryParams.sortDirection = params.sortDirection;
1251
+ if (params?.createdAtFrom !== void 0)
1252
+ queryParams.createdAtFrom = params.createdAtFrom;
1253
+ if (params?.createdAtTo !== void 0)
1254
+ queryParams.createdAtTo = params.createdAtTo;
1255
+ if (params?.priceFrom !== void 0) queryParams.priceFrom = params.priceFrom;
1256
+ if (params?.priceTo !== void 0) queryParams.priceTo = params.priceTo;
1257
+ if (params?.matchAll !== void 0) queryParams.matchAll = params.matchAll;
1258
+ if (params?.blocks && params.blocks.length > 0)
1259
+ queryParams.blocks = JSON.stringify(params.blocks);
1260
+ return apiConfig.httpClient.get(`/v1/networks/${networkKey}/services`, {
1261
+ ...options,
1262
+ params: queryParams
1263
+ });
1236
1264
  },
1237
1265
  /**
1238
- * List all feature flags for the business
1266
+ * Search products across all businesses that have opted into a network
1267
+ * @param networkKey - The network key (e.g., "delfin")
1268
+ * @param params - Search parameters
1239
1269
  */
1240
- async getFlags(params, options) {
1241
- return apiConfig.httpClient.get(
1242
- `/v1/businesses/${apiConfig.businessId}/feature-flags`,
1243
- {
1244
- ...options,
1245
- params
1246
- }
1247
- );
1270
+ async searchProducts(networkKey, params, options) {
1271
+ const queryParams = {};
1272
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
1273
+ if (params?.cursor) queryParams.cursor = params.cursor;
1274
+ if (params?.query) queryParams.query = params.query;
1275
+ if (params?.nodeId) queryParams.nodeId = params.nodeId;
1276
+ if (params?.nodeIds && params.nodeIds.length > 0)
1277
+ queryParams.nodeIds = params.nodeIds.join(",");
1278
+ if (params?.statuses && params.statuses.length > 0)
1279
+ queryParams.statuses = params.statuses.join(",");
1280
+ if (params?.sortField) queryParams.sortField = params.sortField;
1281
+ if (params?.sortDirection) queryParams.sortDirection = params.sortDirection;
1282
+ if (params?.createdAtFrom !== void 0)
1283
+ queryParams.createdAtFrom = params.createdAtFrom;
1284
+ if (params?.createdAtTo !== void 0)
1285
+ queryParams.createdAtTo = params.createdAtTo;
1286
+ if (params?.priceFrom !== void 0) queryParams.priceFrom = params.priceFrom;
1287
+ if (params?.priceTo !== void 0) queryParams.priceTo = params.priceTo;
1288
+ if (params?.matchAll !== void 0) queryParams.matchAll = params.matchAll;
1289
+ if (params?.blocks && params.blocks.length > 0)
1290
+ queryParams.blocks = JSON.stringify(params.blocks);
1291
+ return apiConfig.httpClient.get(`/v1/networks/${networkKey}/products`, {
1292
+ ...options,
1293
+ params: queryParams
1294
+ });
1248
1295
  },
1249
1296
  /**
1250
- * Update a feature flag
1297
+ * Search providers across all businesses that have opted into a network
1298
+ * @param networkKey - The network key (e.g., "delfin")
1299
+ * @param params - Search parameters
1251
1300
  */
1252
- async updateFlag(params, options) {
1253
- const { id, ...body } = params;
1301
+ async searchProviders(networkKey, params, options) {
1302
+ const queryParams = {};
1303
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
1304
+ if (params?.cursor) queryParams.cursor = params.cursor;
1305
+ if (params?.query) queryParams.query = params.query;
1306
+ if (params?.nodeId) queryParams.nodeId = params.nodeId;
1307
+ if (params?.nodeIds && params.nodeIds.length > 0)
1308
+ queryParams.nodeIds = params.nodeIds.join(",");
1309
+ if (params?.statuses && params.statuses.length > 0)
1310
+ queryParams.statuses = params.statuses.join(",");
1311
+ if (params?.sortField) queryParams.sortField = params.sortField;
1312
+ if (params?.sortDirection) queryParams.sortDirection = params.sortDirection;
1313
+ if (params?.createdAtFrom !== void 0)
1314
+ queryParams.createdAtFrom = params.createdAtFrom;
1315
+ if (params?.createdAtTo !== void 0)
1316
+ queryParams.createdAtTo = params.createdAtTo;
1317
+ if (params?.matchAll !== void 0) queryParams.matchAll = params.matchAll;
1318
+ if (params?.blocks && params.blocks.length > 0)
1319
+ queryParams.blocks = JSON.stringify(params.blocks);
1320
+ return apiConfig.httpClient.get(`/v1/networks/${networkKey}/providers`, {
1321
+ ...options,
1322
+ params: queryParams
1323
+ });
1324
+ }
1325
+ };
1326
+ };
1327
+
1328
+ // src/api/workflow.ts
1329
+ var createWorkflowApi = (apiConfig) => {
1330
+ return {
1331
+ async createWorkflow(params, options) {
1332
+ const businessId = params.businessId || apiConfig.businessId;
1333
+ return apiConfig.httpClient.post(
1334
+ `/v1/businesses/${businessId}/workflows`,
1335
+ { ...params, businessId },
1336
+ options
1337
+ );
1338
+ },
1339
+ async updateWorkflow(params, options) {
1254
1340
  return apiConfig.httpClient.put(
1255
- `/v1/businesses/${apiConfig.businessId}/feature-flags/${id}`,
1256
- body,
1341
+ `/v1/businesses/${apiConfig.businessId}/workflows/${params.id}`,
1342
+ params,
1257
1343
  options
1258
1344
  );
1259
1345
  },
1260
- /**
1261
- * Delete a feature flag
1262
- */
1263
- async deleteFlag(params, options) {
1346
+ async deleteWorkflow(params, options) {
1264
1347
  return apiConfig.httpClient.delete(
1265
- `/v1/businesses/${apiConfig.businessId}/feature-flags/${params.id}`,
1348
+ `/v1/businesses/${apiConfig.businessId}/workflows/${params.id}`,
1266
1349
  options
1267
1350
  );
1268
1351
  },
1269
- /**
1270
- * Get experiment results for a feature flag
1271
- */
1272
- async getResults(params, options) {
1352
+ async getWorkflow(params, options) {
1273
1353
  return apiConfig.httpClient.get(
1274
- `/v1/businesses/${apiConfig.businessId}/feature-flags/${params.id}/results`,
1354
+ `/v1/businesses/${apiConfig.businessId}/workflows/${params.id}`,
1275
1355
  options
1276
1356
  );
1277
1357
  },
1358
+ async getWorkflows(params, options) {
1359
+ const businessId = params?.businessId || apiConfig.businessId;
1360
+ const { businessId: _, ...queryParams } = params || {};
1361
+ return apiConfig.httpClient.get(`/v1/businesses/${businessId}/workflows`, {
1362
+ ...options,
1363
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
1364
+ });
1365
+ },
1278
1366
  /**
1279
- * Get the variant assignment for the current user
1280
- * This is the main method for feature flag evaluation
1367
+ * Trigger a workflow execution via webhook
1368
+ * No authentication required - the secret in the URL validates the request
1281
1369
  */
1282
- async getVariant(params, options) {
1283
- return apiConfig.httpClient.get(
1284
- `/v1/businesses/${apiConfig.businessId}/feature-flags/key/${params.flagKey}/variant`,
1370
+ async triggerWorkflow(params, options) {
1371
+ const { secret, ...input } = params;
1372
+ return apiConfig.httpClient.post(`/v1/workflows/trigger/${secret}`, input, options);
1373
+ }
1374
+ };
1375
+ };
1376
+
1377
+ // src/api/audience.ts
1378
+ var createAudienceApi = (apiConfig) => {
1379
+ return {
1380
+ async createAudience(params, options) {
1381
+ return apiConfig.httpClient.post(
1382
+ `/v1/businesses/${apiConfig.businessId}/audiences`,
1383
+ params,
1285
1384
  options
1286
1385
  );
1287
1386
  },
1288
- /**
1289
- * Track a conversion event for A/B testing
1290
- */
1291
- async trackEvent(params, options) {
1292
- return apiConfig.httpClient.post(
1293
- `/v1/businesses/${apiConfig.businessId}/feature-flags/track`,
1387
+ async updateAudience(params, options) {
1388
+ return apiConfig.httpClient.put(
1389
+ `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}`,
1294
1390
  params,
1295
1391
  options
1296
1392
  );
1297
1393
  },
1298
- // ===== CONVENIENCE METHODS =====
1299
- /**
1300
- * Check if a feature is enabled (returns true if variant is not 'control')
1301
- * Convenience method for simple on/off flags
1302
- */
1303
- async isEnabled(flagKey) {
1304
- try {
1305
- const response = await this.getVariant({ flagKey });
1306
- return response.variantKey !== "control";
1307
- } catch {
1308
- return false;
1309
- }
1394
+ async deleteAudience(params, options) {
1395
+ return apiConfig.httpClient.delete(
1396
+ `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}`,
1397
+ options
1398
+ );
1310
1399
  },
1311
- /**
1312
- * Get variant with payload, returning a default if flag not found
1313
- * Useful for getting configuration values from variants
1314
- */
1315
- async getVariantWithDefault(flagKey, defaultValue) {
1316
- try {
1317
- const response = await this.getVariant({ flagKey });
1318
- return {
1319
- variantKey: response.variantKey,
1320
- payload: response.payload ?? defaultValue
1321
- };
1322
- } catch {
1323
- return {
1324
- variantKey: "control",
1325
- payload: defaultValue
1326
- };
1327
- }
1400
+ async getAudience(params, options) {
1401
+ return apiConfig.httpClient.get(
1402
+ `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}`,
1403
+ options
1404
+ );
1328
1405
  },
1329
- /**
1330
- * Activate a draft flag
1331
- */
1332
- async activateFlag(id) {
1333
- return this.updateFlag({ id, status: "ACTIVE" });
1406
+ async getAudiences(params, options) {
1407
+ return apiConfig.httpClient.get(
1408
+ `/v1/businesses/${apiConfig.businessId}/audiences`,
1409
+ { ...options, params }
1410
+ );
1334
1411
  },
1335
- /**
1336
- * Archive an active flag
1337
- */
1338
- async archiveFlag(id) {
1339
- return this.updateFlag({ id, status: "ARCHIVED" });
1340
- }
1341
- };
1342
- };
1343
-
1344
- // src/api/location.ts
1345
- var createLocationApi = (apiConfig) => {
1346
- return {
1347
- async getCountries(options) {
1348
- return apiConfig.httpClient.get(`/v1/operations/location/countries`, options);
1412
+ async subscribe(params, options) {
1413
+ return apiConfig.httpClient.post(
1414
+ `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribe`,
1415
+ {
1416
+ priceId: params.priceId,
1417
+ successUrl: params.successUrl,
1418
+ cancelUrl: params.cancelUrl
1419
+ },
1420
+ options
1421
+ );
1349
1422
  },
1350
- async getCountryStates(countryCode, options) {
1423
+ async checkAccess(params, options) {
1351
1424
  return apiConfig.httpClient.get(
1352
- `/v1/operations/location/countries/${countryCode}/states`,
1425
+ `/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/access`,
1353
1426
  options
1354
1427
  );
1355
1428
  }
@@ -1559,6 +1632,8 @@ function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMeth
1559
1632
  shipping: 0,
1560
1633
  discount,
1561
1634
  total,
1635
+ paid: 0,
1636
+ refunds: [],
1562
1637
  type: paymentMethod,
1563
1638
  ...taxAmount > 0 && {
1564
1639
  tax: {
@@ -1710,8 +1785,37 @@ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1710
1785
  }
1711
1786
  }
1712
1787
 
1788
+ // src/utils/keyValidation.ts
1789
+ var KEY_PATTERN = /^[a-zA-Z0-9_-]+$/;
1790
+ function isValidKey(key) {
1791
+ if (!key || key.length === 0) return false;
1792
+ return KEY_PATTERN.test(key);
1793
+ }
1794
+ function validateKey(key) {
1795
+ if (!key || key.length === 0) {
1796
+ return { valid: false, error: "Key is required" };
1797
+ }
1798
+ if (key.length > 255) {
1799
+ return { valid: false, error: "Key must be 255 characters or less" };
1800
+ }
1801
+ if (!KEY_PATTERN.test(key)) {
1802
+ return {
1803
+ valid: false,
1804
+ error: "Key can only contain letters, numbers, underscores (_) and hyphens (-)"
1805
+ };
1806
+ }
1807
+ return { valid: true };
1808
+ }
1809
+ function toKey(input) {
1810
+ if (!input) return "";
1811
+ return input.toLowerCase().trim().replace(/\s+/g, "_").replace(/[^a-z0-9_-]/g, "").replace(/^[-_]+|[-_]+$/g, "").replace(/[-_]{2,}/g, "_");
1812
+ }
1813
+ function nameToKey(name) {
1814
+ return toKey(name);
1815
+ }
1816
+
1713
1817
  // src/index.ts
1714
- var SDK_VERSION = "0.4.0";
1818
+ var SDK_VERSION = "0.3.167";
1715
1819
  var SUPPORTED_FRAMEWORKS = [
1716
1820
  "astro",
1717
1821
  "react",
@@ -1731,28 +1835,13 @@ async function createArkySDK(config) {
1731
1835
  setToken: config.setToken,
1732
1836
  getToken: config.getToken
1733
1837
  };
1734
- const userApi = createUserApi(apiConfig);
1735
- const autoGuest = config.autoGuest !== void 0 ? config.autoGuest : true;
1736
- if (autoGuest) {
1737
- try {
1738
- const tokens = await config.getToken();
1739
- if (!tokens.accessToken && !tokens.refreshToken) {
1740
- const result = await httpClient.post("/v1/users/login", {
1741
- provider: "GUEST"
1742
- });
1743
- const token = result.accessToken || result.token || "";
1744
- if (token) {
1745
- config.setToken(result);
1746
- }
1747
- }
1748
- } catch (error) {
1749
- }
1750
- }
1838
+ const accountApi = createAccountApi(apiConfig);
1839
+ const authApi = createAuthApi(apiConfig);
1751
1840
  const sdk = {
1752
- user: userApi,
1841
+ auth: authApi,
1842
+ account: accountApi,
1753
1843
  business: createBusinessApi(apiConfig),
1754
1844
  media: createMediaApi(apiConfig),
1755
- role: createRoleApi(apiConfig),
1756
1845
  notification: createNotificationApi(apiConfig),
1757
1846
  promoCode: createPromoCodeApi(apiConfig),
1758
1847
  analytics: createAnalyticsApi(apiConfig),
@@ -1760,8 +1849,10 @@ async function createArkySDK(config) {
1760
1849
  eshop: createEshopApi(apiConfig),
1761
1850
  reservation: createReservationApi(apiConfig),
1762
1851
  database: createDatabaseApi(apiConfig),
1763
- featureFlags: createFeatureFlagsApi(apiConfig),
1764
1852
  location: createLocationApi(apiConfig),
1853
+ network: createNetworkApi(apiConfig),
1854
+ workflow: createWorkflowApi(apiConfig),
1855
+ audience: createAudienceApi(apiConfig),
1765
1856
  setBusinessId: (businessId) => {
1766
1857
  apiConfig.businessId = businessId;
1767
1858
  },
@@ -1812,7 +1903,12 @@ async function createArkySDK(config) {
1812
1903
  // SVG utilities
1813
1904
  getSvgContentForAstro,
1814
1905
  fetchSvgContent,
1815
- injectSvgIntoElement
1906
+ injectSvgIntoElement,
1907
+ // Key validation utilities
1908
+ isValidKey,
1909
+ validateKey,
1910
+ toKey,
1911
+ nameToKey
1816
1912
  }
1817
1913
  };
1818
1914
  return sdk;