arky-sdk 0.3.8 → 0.3.10

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.cjs CHANGED
@@ -268,7 +268,7 @@ var createBusinessApi = (apiConfig) => {
268
268
  return apiConfig.httpClient.get(`/v1/businesses`, options);
269
269
  },
270
270
  async getBusinessParents(params, options) {
271
- return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/parents`, options);
271
+ return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/parents`, options);
272
272
  },
273
273
  async triggerBuilds(params, options) {
274
274
  return apiConfig.httpClient.post(`/v1/businesses/${params.id}/trigger-builds`, {}, options);
@@ -277,61 +277,59 @@ var createBusinessApi = (apiConfig) => {
277
277
  return apiConfig.httpClient.get("/v1/businesses/plans", options);
278
278
  },
279
279
  async getSubscription(params, options) {
280
- return apiConfig.httpClient.get(`/v1/businesses/${params.businessId}/subscription`, options);
280
+ return apiConfig.httpClient.get(`/v1/businesses/${apiConfig.businessId}/subscription`, options);
281
281
  },
282
282
  async createSubscription(params, options) {
283
283
  return apiConfig.httpClient.post(
284
- `/v1/businesses/${params.businessId}/subscription`,
284
+ `/v1/businesses/${apiConfig.businessId}/subscription`,
285
285
  params,
286
286
  options
287
287
  );
288
288
  },
289
289
  async updateSubscription(params, options) {
290
290
  return apiConfig.httpClient.put(
291
- `/v1/businesses/${params.businessId}/subscription`,
291
+ `/v1/businesses/${apiConfig.businessId}/subscription`,
292
292
  params,
293
293
  options
294
294
  );
295
295
  },
296
296
  async cancelSubscription(params, options) {
297
- return apiConfig.httpClient.delete(`/v1/businesses/${params.businessId}/subscription`, {
297
+ return apiConfig.httpClient.delete(`/v1/businesses/${apiConfig.businessId}/subscription`, {
298
298
  ...options,
299
299
  params: { immediately: params.immediately || false }
300
300
  });
301
301
  },
302
302
  async reactivateSubscription(params, options) {
303
303
  return apiConfig.httpClient.post(
304
- `/v1/businesses/${params.businessId}/subscription/reactivate`,
304
+ `/v1/businesses/${apiConfig.businessId}/subscription/reactivate`,
305
305
  params,
306
306
  options
307
307
  );
308
308
  },
309
309
  async createPortalSession(params, options) {
310
310
  return apiConfig.httpClient.post(
311
- `/v1/businesses/${params.businessId}/subscription/portal`,
311
+ `/v1/businesses/${apiConfig.businessId}/subscription/portal`,
312
312
  params,
313
313
  options
314
314
  );
315
315
  },
316
316
  async inviteUser(params, options) {
317
- const { businessId, ...payload } = params;
318
317
  return apiConfig.httpClient.post(
319
- `/v1/businesses/${businessId}/invitation`,
320
- payload,
318
+ `/v1/businesses/${apiConfig.businessId}/invitation`,
319
+ params,
321
320
  options
322
321
  );
323
322
  },
324
323
  async handleInvitation(params, options) {
325
- const { businessId, ...payload } = params;
326
324
  return apiConfig.httpClient.put(
327
- `/v1/businesses/${businessId}/invitation`,
328
- payload,
325
+ `/v1/businesses/${apiConfig.businessId}/invitation`,
326
+ params,
329
327
  options
330
328
  );
331
329
  },
332
330
  async testWebhook(params, options) {
333
331
  return apiConfig.httpClient.post(
334
- `/v1/businesses/${params.businessId}/webhooks/test`,
332
+ `/v1/businesses/${apiConfig.businessId}/webhooks/test`,
335
333
  params.webhook,
336
334
  options
337
335
  );
@@ -804,7 +802,7 @@ var createReservationApi = (apiConfig) => {
804
802
  async getReservation(params, options) {
805
803
  return apiConfig.httpClient.get(`/v1/reservations/${params.id}`, {
806
804
  ...options,
807
- params: params.businessId ? { businessId: params.businessId } : {}
805
+ params: { businessId: apiConfig.businessId }
808
806
  });
809
807
  },
810
808
  async getReservationParts(params, options) {
@@ -973,7 +971,7 @@ var createNewsletterApi = (apiConfig) => {
973
971
  async find(params, options) {
974
972
  return apiConfig.httpClient.get(`/v1/newsletters`, {
975
973
  ...options,
976
- params: { businessId: params.businessId }
974
+ params: { businessId: apiConfig.businessId }
977
975
  });
978
976
  },
979
977
  async get(params, options) {
@@ -1041,6 +1039,135 @@ var createPaymentApi = (apiConfig) => {
1041
1039
  };
1042
1040
 
1043
1041
  // src/utils/blocks.ts
1042
+ function getBlockLabel(block, locale = "en") {
1043
+ if (!block) return "";
1044
+ if (block.properties?.label) {
1045
+ if (typeof block.properties.label === "object") {
1046
+ return block.properties.label[locale] || block.properties.label.en || Object.values(block.properties.label)[0] || "";
1047
+ }
1048
+ if (typeof block.properties.label === "string") {
1049
+ return block.properties.label;
1050
+ }
1051
+ }
1052
+ return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) || "";
1053
+ }
1054
+ function formatBlockValue(block) {
1055
+ if (!block || block.value === null || block.value === void 0) {
1056
+ return "";
1057
+ }
1058
+ switch (block.type) {
1059
+ case "BOOLEAN":
1060
+ return block.value ? "Yes" : "No";
1061
+ case "NUMBER":
1062
+ if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
1063
+ try {
1064
+ return new Date(block.value).toLocaleDateString();
1065
+ } catch (e) {
1066
+ return String(block.value);
1067
+ }
1068
+ }
1069
+ return String(block.value);
1070
+ case "RELATIONSHIP":
1071
+ if (Array.isArray(block.value) && block.value.length > 0) {
1072
+ const firstValue = block.value[0];
1073
+ if (firstValue && firstValue.mimeType) {
1074
+ return firstValue.name || firstValue.id || "Media";
1075
+ }
1076
+ return firstValue.title || firstValue.name || firstValue.id || "Entry";
1077
+ }
1078
+ return String(block.value);
1079
+ default:
1080
+ return String(block.value);
1081
+ }
1082
+ }
1083
+ function prepareBlocksForSubmission(formData) {
1084
+ const preparedBlocks = [];
1085
+ Object.keys(formData).forEach((key) => {
1086
+ if (formData[key] !== null && formData[key] !== void 0) {
1087
+ preparedBlocks.push({
1088
+ key,
1089
+ value: [formData[key]]
1090
+ });
1091
+ }
1092
+ });
1093
+ return preparedBlocks;
1094
+ }
1095
+ function extractBlockValues(blocks) {
1096
+ const values = {};
1097
+ blocks.forEach((block) => {
1098
+ if (block.value && block.value.length > 0) {
1099
+ values[block.key] = block.value[0];
1100
+ } else {
1101
+ values[block.key] = null;
1102
+ }
1103
+ });
1104
+ return values;
1105
+ }
1106
+ function getBlockTextValue(block, locale = "en") {
1107
+ if (!block || !block.value || block.value.length === 0) return "";
1108
+ const firstValue = block.value[0];
1109
+ if (typeof firstValue === "object" && firstValue !== null) {
1110
+ if (firstValue[locale]) return firstValue[locale];
1111
+ if (firstValue.en) return firstValue.en;
1112
+ const values = Object.values(firstValue);
1113
+ return String(values[0] || "");
1114
+ }
1115
+ return String(firstValue);
1116
+ }
1117
+ var getBlockValue = (entry, blockKey) => {
1118
+ if (!entry || !entry.blocks) return null;
1119
+ const block = entry.blocks.find((f) => f.key === blockKey);
1120
+ if (!block || !block.value || block.value.length === 0) return null;
1121
+ return block.value[0];
1122
+ };
1123
+ var getBlockValues = (entry, blockKey) => {
1124
+ if (!entry || !entry.blocks) return null;
1125
+ const block = entry.blocks.find((f) => f.key === blockKey);
1126
+ if (!block || !block.value || block.value.length === 0) return null;
1127
+ return block.value;
1128
+ };
1129
+ function unwrapBlock(block, locale) {
1130
+ if (!block?.type || block.value === void 0) return block;
1131
+ if (block.type === "BLOCK") {
1132
+ return block.value.map((obj) => {
1133
+ const parsed = {};
1134
+ for (const [k, v] of Object.entries(obj)) {
1135
+ parsed[k] = unwrapBlock(v, locale);
1136
+ }
1137
+ return parsed;
1138
+ });
1139
+ }
1140
+ const isLocalized = block.type === "TEXT";
1141
+ const isList = block.properties?.ui === "list" || (block.properties?.maxValues ?? 1) > 1 || block.value.length > 1;
1142
+ if (isList) {
1143
+ return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
1144
+ }
1145
+ return isLocalized ? block.value[0][locale] || block.value[0]["en"] : block.value[0];
1146
+ }
1147
+ var getBlockObjectValues = (entry, blockKey, locale = "en") => {
1148
+ if (!entry) {
1149
+ return [];
1150
+ }
1151
+ const values = getBlockValues(entry, blockKey);
1152
+ const parsed = values.map((obj) => {
1153
+ const res = obj.value.reduce((acc, current) => {
1154
+ acc[current.key] = unwrapBlock(current, locale);
1155
+ return acc;
1156
+ }, {});
1157
+ return res;
1158
+ });
1159
+ return parsed;
1160
+ };
1161
+ var getBlockFromArray = (entry, blockKey, locale = "en") => {
1162
+ if (!entry) {
1163
+ return [];
1164
+ }
1165
+ const values = getBlockValues(entry, blockKey);
1166
+ return values.reduce((acc, current) => {
1167
+ acc[current.key] = unwrapBlock(current, locale);
1168
+ return acc;
1169
+ });
1170
+ };
1044
1171
  var getImageUrl = (imageBlock, isBlock = true, storageUrl = "https://storage.arky.io/dev") => {
1045
1172
  if (!imageBlock) return null;
1046
1173
  const isExternalUrl = (url) => {
@@ -1362,8 +1489,86 @@ function findTimeZone(groups) {
1362
1489
  }
1363
1490
  }
1364
1491
 
1492
+ // src/utils/text.ts
1493
+ var locales = ["en", "sr-latn"];
1494
+ var localeMap = {
1495
+ "en": "en-US",
1496
+ "sr-latn": "sr-RS"
1497
+ };
1498
+ function slugify(text) {
1499
+ return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1500
+ }
1501
+ function humanize(text) {
1502
+ const slugifiedText = slugify(text);
1503
+ return slugifiedText.replace(/-/g, " ").replace(
1504
+ // upper case first letter of every word, and lower case the rest
1505
+ /\w\S*/g,
1506
+ (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
1507
+ );
1508
+ }
1509
+ function categorify(text) {
1510
+ const slugifiedText = slugify(text);
1511
+ return slugifiedText.replace(/-/g, " ").toUpperCase();
1512
+ }
1513
+ function formatDate(date, locale) {
1514
+ let localeString = "en-US";
1515
+ if (locales.includes(locale)) {
1516
+ localeString = localeMap[locale];
1517
+ }
1518
+ return new Date(date).toLocaleDateString(localeString, {
1519
+ timeZone: "UTC",
1520
+ year: "numeric",
1521
+ month: "short",
1522
+ day: "numeric"
1523
+ });
1524
+ }
1525
+
1526
+ // src/utils/svg.ts
1527
+ async function fetchSvgContent(mediaObject) {
1528
+ if (!mediaObject) return null;
1529
+ const svgUrl = getImageUrl(mediaObject, false);
1530
+ try {
1531
+ const response = await fetch(svgUrl);
1532
+ if (!response.ok) {
1533
+ console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
1534
+ return null;
1535
+ }
1536
+ const svgContent = await response.text();
1537
+ return svgContent;
1538
+ } catch (error) {
1539
+ console.error("Error fetching SVG:", error);
1540
+ return null;
1541
+ }
1542
+ }
1543
+ async function getSvgContentForAstro(mediaObject) {
1544
+ try {
1545
+ const svgContent = await fetchSvgContent(mediaObject);
1546
+ return svgContent || "";
1547
+ } catch (error) {
1548
+ console.error("Error getting SVG content for Astro:", error);
1549
+ return "";
1550
+ }
1551
+ }
1552
+ async function injectSvgIntoElement(mediaObject, targetElement, className) {
1553
+ if (!targetElement) return;
1554
+ try {
1555
+ const svgContent = await fetchSvgContent(mediaObject);
1556
+ if (svgContent) {
1557
+ targetElement.innerHTML = svgContent;
1558
+ if (className) {
1559
+ const svgElement = targetElement.querySelector("svg");
1560
+ if (svgElement) {
1561
+ svgElement.classList.add(...className.split(" "));
1562
+ }
1563
+ }
1564
+ }
1565
+ } catch (error) {
1566
+ console.error("Error injecting SVG:", error);
1567
+ }
1568
+ }
1569
+
1365
1570
  // src/index.ts
1366
- var SDK_VERSION = "0.3.8";
1571
+ var SDK_VERSION = "0.3.9";
1367
1572
  var SUPPORTED_FRAMEWORKS = [
1368
1573
  "astro",
1369
1574
  "react",
@@ -1413,18 +1618,41 @@ function createArkySDK(config) {
1413
1618
  logout: config.logout,
1414
1619
  setToken: config.setToken,
1415
1620
  utils: {
1621
+ // Block utilities
1416
1622
  getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock, storageUrl),
1417
1623
  thumbnailUrl: (service) => thumbnailUrl(service, storageUrl),
1418
1624
  getGalleryThumbnail,
1625
+ getBlockValue,
1626
+ getBlockValues,
1627
+ getBlockLabel,
1628
+ getBlockTextValue,
1629
+ getBlockObjectValues,
1630
+ getBlockFromArray,
1631
+ formatBlockValue,
1632
+ prepareBlocksForSubmission,
1633
+ extractBlockValues,
1634
+ // Price utilities
1419
1635
  getMarketPrice,
1420
1636
  getPriceAmount,
1421
1637
  formatPayment,
1422
1638
  formatMinor,
1423
1639
  createPaymentForCheckout,
1640
+ // Currency utilities
1424
1641
  getCurrencySymbol,
1642
+ // Validation utilities
1425
1643
  validatePhoneNumber,
1644
+ // Timezone utilities
1426
1645
  tzGroups,
1427
- findTimeZone
1646
+ findTimeZone,
1647
+ // Text utilities
1648
+ slugify,
1649
+ humanize,
1650
+ categorify,
1651
+ formatDate,
1652
+ // SVG utilities
1653
+ getSvgContentForAstro,
1654
+ fetchSvgContent,
1655
+ injectSvgIntoElement
1428
1656
  }
1429
1657
  };
1430
1658
  if (autoGuest) {