arky-sdk 0.1.0 → 0.1.2

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.
Files changed (104) hide show
  1. package/dist/config-CPkOgumU.d.cts +16 -0
  2. package/dist/config-CPkOgumU.d.ts +16 -0
  3. package/dist/index.cjs +1615 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +268 -0
  6. package/dist/index.d.ts +268 -26
  7. package/dist/index.js +1555 -56
  8. package/dist/index.js.map +1 -0
  9. package/dist/stores.cjs +2148 -0
  10. package/dist/stores.cjs.map +1 -0
  11. package/dist/stores.d.cts +218 -0
  12. package/dist/stores.d.ts +218 -0
  13. package/dist/stores.js +2111 -0
  14. package/dist/stores.js.map +1 -0
  15. package/dist/types.cjs +13 -0
  16. package/dist/types.cjs.map +1 -0
  17. package/dist/{types/index.d.ts → types.d.cts} +25 -24
  18. package/dist/types.d.ts +245 -0
  19. package/dist/types.js +11 -0
  20. package/dist/types.js.map +1 -0
  21. package/dist/utils.cjs +725 -0
  22. package/dist/utils.cjs.map +1 -0
  23. package/dist/utils.d.cts +9 -0
  24. package/dist/utils.d.ts +9 -0
  25. package/dist/utils.js +680 -0
  26. package/dist/utils.js.map +1 -0
  27. package/dist/validation-C9UAYKke.d.cts +245 -0
  28. package/dist/validation-DIvAzYjG.d.ts +245 -0
  29. package/package.json +17 -11
  30. package/dist/api/cms.d.ts +0 -19
  31. package/dist/api/cms.d.ts.map +0 -1
  32. package/dist/api/cms.js +0 -41
  33. package/dist/api/eshop.d.ts +0 -89
  34. package/dist/api/eshop.d.ts.map +0 -1
  35. package/dist/api/eshop.js +0 -183
  36. package/dist/api/index.d.ts +0 -6
  37. package/dist/api/index.d.ts.map +0 -1
  38. package/dist/api/index.js +0 -5
  39. package/dist/api/newsletter.d.ts +0 -32
  40. package/dist/api/newsletter.d.ts.map +0 -1
  41. package/dist/api/newsletter.js +0 -70
  42. package/dist/api/reservation.d.ts +0 -84
  43. package/dist/api/reservation.d.ts.map +0 -1
  44. package/dist/api/reservation.js +0 -239
  45. package/dist/config.d.ts +0 -15
  46. package/dist/config.d.ts.map +0 -1
  47. package/dist/config.js +0 -20
  48. package/dist/index.d.ts.map +0 -1
  49. package/dist/services/auth.d.ts +0 -17
  50. package/dist/services/auth.d.ts.map +0 -1
  51. package/dist/services/auth.js +0 -62
  52. package/dist/services/http.d.ts +0 -20
  53. package/dist/services/http.d.ts.map +0 -1
  54. package/dist/services/http.js +0 -73
  55. package/dist/stores/business.d.ts +0 -28
  56. package/dist/stores/business.d.ts.map +0 -1
  57. package/dist/stores/business.js +0 -122
  58. package/dist/stores/cart.d.ts +0 -8
  59. package/dist/stores/cart.d.ts.map +0 -1
  60. package/dist/stores/cart.js +0 -20
  61. package/dist/stores/eshop.d.ts +0 -121
  62. package/dist/stores/eshop.d.ts.map +0 -1
  63. package/dist/stores/eshop.js +0 -377
  64. package/dist/stores/index.d.ts +0 -7
  65. package/dist/stores/index.d.ts.map +0 -1
  66. package/dist/stores/index.js +0 -19
  67. package/dist/stores/reservation.d.ts +0 -237
  68. package/dist/stores/reservation.d.ts.map +0 -1
  69. package/dist/stores/reservation.js +0 -853
  70. package/dist/types/index.d.ts.map +0 -1
  71. package/dist/types/index.js +0 -8
  72. package/dist/utils/blocks.d.ts +0 -30
  73. package/dist/utils/blocks.d.ts.map +0 -1
  74. package/dist/utils/blocks.js +0 -237
  75. package/dist/utils/currency.d.ts +0 -9
  76. package/dist/utils/currency.d.ts.map +0 -1
  77. package/dist/utils/currency.js +0 -99
  78. package/dist/utils/errors.d.ts +0 -121
  79. package/dist/utils/errors.d.ts.map +0 -1
  80. package/dist/utils/errors.js +0 -114
  81. package/dist/utils/i18n.d.ts +0 -5
  82. package/dist/utils/i18n.d.ts.map +0 -1
  83. package/dist/utils/i18n.js +0 -37
  84. package/dist/utils/index.d.ts +0 -9
  85. package/dist/utils/index.d.ts.map +0 -1
  86. package/dist/utils/index.js +0 -10
  87. package/dist/utils/price.d.ts +0 -33
  88. package/dist/utils/price.d.ts.map +0 -1
  89. package/dist/utils/price.js +0 -141
  90. package/dist/utils/queryParams.d.ts +0 -21
  91. package/dist/utils/queryParams.d.ts.map +0 -1
  92. package/dist/utils/queryParams.js +0 -47
  93. package/dist/utils/svg.d.ts +0 -17
  94. package/dist/utils/svg.d.ts.map +0 -1
  95. package/dist/utils/svg.js +0 -62
  96. package/dist/utils/text.d.ts +0 -26
  97. package/dist/utils/text.d.ts.map +0 -1
  98. package/dist/utils/text.js +0 -64
  99. package/dist/utils/timezone.d.ts +0 -9
  100. package/dist/utils/timezone.d.ts.map +0 -1
  101. package/dist/utils/timezone.js +0 -49
  102. package/dist/utils/validation.d.ts +0 -9
  103. package/dist/utils/validation.d.ts.map +0 -1
  104. package/dist/utils/validation.js +0 -44
package/dist/utils.js ADDED
@@ -0,0 +1,680 @@
1
+ // src/config.ts
2
+
3
+ // src/utils/blocks.ts
4
+ function getBlockLabel(block, locale = "en") {
5
+ if (!block) return "";
6
+ if (block.properties?.label) {
7
+ if (typeof block.properties.label === "object") {
8
+ return block.properties.label[locale] || block.properties.label.en || Object.values(block.properties.label)[0] || "";
9
+ }
10
+ if (typeof block.properties.label === "string") {
11
+ return block.properties.label;
12
+ }
13
+ }
14
+ return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) || "";
15
+ }
16
+ function formatBlockValue(block) {
17
+ if (!block || block.value === null || block.value === void 0) {
18
+ return "";
19
+ }
20
+ switch (block.type) {
21
+ case "BOOLEAN":
22
+ return block.value ? "Yes" : "No";
23
+ case "NUMBER":
24
+ if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
25
+ try {
26
+ return new Date(block.value).toLocaleDateString();
27
+ } catch (e) {
28
+ return String(block.value);
29
+ }
30
+ }
31
+ return String(block.value);
32
+ case "RELATIONSHIP":
33
+ if (Array.isArray(block.value) && block.value.length > 0) {
34
+ const firstValue = block.value[0];
35
+ if (firstValue && firstValue.mimeType) {
36
+ return firstValue.name || firstValue.id || "Media";
37
+ }
38
+ return firstValue.title || firstValue.name || firstValue.id || "Entry";
39
+ }
40
+ return String(block.value);
41
+ default:
42
+ return String(block.value);
43
+ }
44
+ }
45
+ function prepareBlocksForSubmission(formData) {
46
+ const preparedBlocks = [];
47
+ Object.keys(formData).forEach((key) => {
48
+ if (formData[key] !== null && formData[key] !== void 0) {
49
+ preparedBlocks.push({
50
+ key,
51
+ value: [formData[key]]
52
+ });
53
+ }
54
+ });
55
+ return preparedBlocks;
56
+ }
57
+ function extractBlockValues(blocks) {
58
+ const values = {};
59
+ blocks.forEach((block) => {
60
+ if (block.value && block.value.length > 0) {
61
+ values[block.key] = block.value[0];
62
+ } else {
63
+ values[block.key] = null;
64
+ }
65
+ });
66
+ return values;
67
+ }
68
+ function getBlockTextValue(block, locale = "en") {
69
+ if (!block || !block.value || block.value.length === 0) return "";
70
+ const firstValue = block.value[0];
71
+ if (typeof firstValue === "object" && firstValue !== null) {
72
+ if (firstValue[locale]) return firstValue[locale];
73
+ if (firstValue.en) return firstValue.en;
74
+ const values = Object.values(firstValue);
75
+ return String(values[0] || "");
76
+ }
77
+ return String(firstValue);
78
+ }
79
+ var getBlockValue = (entry, blockKey) => {
80
+ if (!entry || !entry.blocks) return null;
81
+ const block = entry.blocks.find((f) => f.key === blockKey);
82
+ if (!block || !block.value || block.value.length === 0) return null;
83
+ return block.value[0];
84
+ };
85
+ var getBlockValues = (entry, blockKey) => {
86
+ if (!entry || !entry.blocks) return null;
87
+ const block = entry.blocks.find((f) => f.key === blockKey);
88
+ if (!block || !block.value || block.value.length === 0) return null;
89
+ return block.value;
90
+ };
91
+ function unwrapBlock(block, locale) {
92
+ if (!block?.type || block.value === void 0) return block;
93
+ if (block.type === "BLOCK") {
94
+ return block.value.map((obj) => {
95
+ const parsed = {};
96
+ for (const [k, v] of Object.entries(obj)) {
97
+ parsed[k] = unwrapBlock(v, locale);
98
+ }
99
+ return parsed;
100
+ });
101
+ }
102
+ const isLocalized = block.type === "TEXT";
103
+ const isList = block.properties?.ui === "list" || (block.properties?.maxValues ?? 1) > 1 || block.value.length > 1;
104
+ if (isList) {
105
+ return isLocalized ? block.value.map((v) => v[locale] || v["en"]) : [...block.value];
106
+ }
107
+ return isLocalized ? block.value[0][locale] || block.value[0]["en"] : block.value[0];
108
+ }
109
+ var getBlockObjectValues = (entry, blockKey, locale = "en") => {
110
+ if (!entry) {
111
+ return [];
112
+ }
113
+ const values = getBlockValues(entry, blockKey);
114
+ const parsed = values.map((obj) => {
115
+ const res = obj.value.reduce((acc, current) => {
116
+ acc[current.key] = unwrapBlock(current, locale);
117
+ return acc;
118
+ }, {});
119
+ return res;
120
+ });
121
+ return parsed;
122
+ };
123
+ var getBlockFromArray = (entry, blockKey, locale = "en") => {
124
+ if (!entry) {
125
+ return [];
126
+ }
127
+ const values = getBlockValues(entry, blockKey);
128
+ return values.reduce((acc, current) => {
129
+ acc[current.key] = unwrapBlock(current, locale);
130
+ return acc;
131
+ });
132
+ };
133
+ var getImageUrl = (imageBlock, isBlock = true) => {
134
+ if (!imageBlock) return null;
135
+ const storageUrl = "https://storage.arky.io/dev";
136
+ const isExternalUrl = (url) => {
137
+ return url.startsWith("http://") || url.startsWith("https://");
138
+ };
139
+ if (imageBlock.type === "RELATIONSHIP" && Array.isArray(imageBlock.value)) {
140
+ const mediaValue = imageBlock.value[0];
141
+ if (mediaValue && mediaValue.mimeType) {
142
+ if (mediaValue.resolutions && mediaValue.resolutions.original && mediaValue.resolutions.original.url) {
143
+ const url = mediaValue.resolutions.original.url;
144
+ return isExternalUrl(url) ? url : `${storageUrl}/${url}`;
145
+ }
146
+ if (mediaValue.url) {
147
+ return isExternalUrl(mediaValue.url) ? mediaValue.url : `${storageUrl}/${mediaValue.url}`;
148
+ }
149
+ }
150
+ return null;
151
+ }
152
+ if (isBlock) {
153
+ if (typeof imageBlock === "string") {
154
+ if (isExternalUrl(imageBlock)) {
155
+ return imageBlock;
156
+ }
157
+ return `${storageUrl}/${imageBlock}`;
158
+ }
159
+ if (imageBlock.url) {
160
+ if (isExternalUrl(imageBlock.url)) {
161
+ return imageBlock.url;
162
+ }
163
+ return `${storageUrl}/${imageBlock.url}`;
164
+ }
165
+ }
166
+ if (imageBlock.resolutions && imageBlock.resolutions.original && imageBlock.resolutions.original.url) {
167
+ const url = imageBlock.resolutions.original.url;
168
+ if (isExternalUrl(url)) {
169
+ return url;
170
+ }
171
+ return `${storageUrl}/${url}`;
172
+ }
173
+ return null;
174
+ };
175
+ function getGalleryThumbnail(gallery) {
176
+ if (!gallery?.length) return null;
177
+ const item = gallery.find((g) => g.settings.isThumbnail) || gallery[0];
178
+ const res = item.media.resolutions.thumbnail || item.media.resolutions.original;
179
+ return res?.url || null;
180
+ }
181
+ function thumbnailUrl(service) {
182
+ const storageUrl = "";
183
+ const path = getGalleryThumbnail(service.gallery);
184
+ return path ? `${storageUrl}/${path}` : null;
185
+ }
186
+ var translateMap = (labels, lang, fallback = "unknown") => {
187
+ let parsedLang = "en";
188
+ if (lang === "sr") {
189
+ parsedLang = "bih";
190
+ }
191
+ if (!labels) {
192
+ return fallback;
193
+ }
194
+ const label = labels[parsedLang];
195
+ if (!label) {
196
+ return fallback;
197
+ }
198
+ return label;
199
+ };
200
+
201
+ // src/utils/errors.ts
202
+ var ERROR_CODES = {
203
+ // General errors
204
+ "GENERAL.001": "GENERAL.BAD_REQUEST",
205
+ "GENERAL.002": "GENERAL.VALIDATION_ERROR",
206
+ "GENERAL.003": "GENERAL.FORBIDDEN_ERROR",
207
+ "GENERAL.004": "GENERAL.INTERNAL_SERVER_ERROR",
208
+ "GENERAL.005": "GENERAL.UNAUTHORIZED",
209
+ "GENERAL.006": "GENERAL.UNAUTHENTICATED",
210
+ // Google/OAuth errors
211
+ "GOOGLE.001": "GOOGLE.INVALID_ORIGIN_URI",
212
+ "GOOGLE.002": "GOOGLE.INVALID_REDIRECT_URI",
213
+ "GOOGLE.003": "GOOGLE.FAILED_TO_CALL_API",
214
+ "GOOGLE.004": "GOOGLE.FAILED_LOGIN",
215
+ "GOOGLE.005": "GOOGLE.FAILED_LOGOUT",
216
+ "GOOGLE.006": "GOOGLE.FAILED_REFRESH_TOKEN",
217
+ "GOOGLE.007": "GOOGLE.INVALID_PROVIDER_PASSED",
218
+ // User errors
219
+ "USER.001": "USER.NOT_FOUND",
220
+ "USER.002": "USER.FAILED_TO_CREATE",
221
+ "USER.003": "USER.FAILED_TO_UPDATE",
222
+ "USER.004": "USER.FAILED_TO_DELETE",
223
+ "USER.005": "USER.EMAIL_EXISTS",
224
+ "USER.006": "USER.FAILED_TO_GET_UPLOAD_URL",
225
+ // Business errors
226
+ "BUSINESS.001": "BUSINESS.NOT_FOUND",
227
+ "BUSINESS.002": "BUSINESS.FAILED_TO_CREATE",
228
+ "BUSINESS.003": "BUSINESS.FAILED_TO_UPDATE",
229
+ "BUSINESS.004": "BUSINESS.FAILED_TO_DELETE",
230
+ "BUSINESS.005": "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
231
+ "BUSINESS.006": "BUSINESS.NAME_REQUIRED",
232
+ "BUSINESS.007": "BUSINESS.BUSINESS_ID_REQUIRED",
233
+ "BUSINESS.010": "BUSINESS.DESCRIPTION_REQUIRED",
234
+ "BUSINESS.011": "BUSINESS.SLUG_INVALID",
235
+ // Provider errors
236
+ "PROVIDER.001": "PROVIDER.NOT_FOUND",
237
+ "PROVIDER.002": "PROVIDER.FAILED_TO_CREATE",
238
+ "PROVIDER.003": "PROVIDER.FAILED_TO_UPDATE",
239
+ "PROVIDER.004": "PROVIDER.FAILED_TO_DELETE",
240
+ "PROVIDER.005": "PROVIDER.FAILED_TO_GET_UPLOAD_URL",
241
+ "PROVIDER.006": "PROVIDER.NAME_REQUIRED",
242
+ "PROVIDER.007": "PROVIDER.BUSINESS_ID_REQUIRED",
243
+ "PROVIDER.008": "PROVIDER.DESCRIPTION_REQUIRED"
244
+ };
245
+ var ERROR_CONSTANTS = {
246
+ GENERAL: {
247
+ BAD_REQUEST: "GENERAL.BAD_REQUEST",
248
+ VALIDATION_ERROR: "GENERAL.VALIDATION_ERROR",
249
+ FORBIDDEN_ERROR: "GENERAL.FORBIDDEN_ERROR",
250
+ INTERNAL_SERVER_ERROR: "GENERAL.INTERNAL_SERVER_ERROR",
251
+ UNAUTHORIZED: "GENERAL.UNAUTHORIZED",
252
+ UNAUTHENTICATED: "GENERAL.UNAUTHENTICATED"
253
+ },
254
+ USER: {
255
+ NOT_FOUND: "USER.NOT_FOUND",
256
+ FAILED_TO_CREATE: "USER.FAILED_TO_CREATE",
257
+ FAILED_TO_UPDATE: "USER.FAILED_TO_UPDATE",
258
+ FAILED_TO_DELETE: "USER.FAILED_TO_DELETE",
259
+ EMAIL_EXISTS: "USER.EMAIL_EXISTS",
260
+ FAILED_TO_GET_UPLOAD_URL: "USER.FAILED_TO_GET_UPLOAD_URL"
261
+ },
262
+ BUSINESS: {
263
+ NOT_FOUND: "BUSINESS.NOT_FOUND",
264
+ FAILED_TO_CREATE: "BUSINESS.FAILED_TO_CREATE",
265
+ FAILED_TO_UPDATE: "BUSINESS.FAILED_TO_UPDATE",
266
+ FAILED_TO_DELETE: "BUSINESS.FAILED_TO_DELETE",
267
+ FAILED_TO_GET_UPLOAD_URL: "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
268
+ NAME_REQUIRED: "BUSINESS.NAME_REQUIRED",
269
+ BUSINESS_ID_REQUIRED: "BUSINESS.BUSINESS_ID_REQUIRED",
270
+ DESCRIPTION_REQUIRED: "BUSINESS.DESCRIPTION_REQUIRED",
271
+ SLUG_INVALID: "BUSINESS.SLUG_INVALID"
272
+ }
273
+ };
274
+ function getErrorMessage(code) {
275
+ return ERROR_CODES[code] || code;
276
+ }
277
+ function isErrorCode(code) {
278
+ return code in ERROR_CODES;
279
+ }
280
+ var transformErrors = (zodError) => {
281
+ const customErrors = [];
282
+ if (!zodError.issues) return customErrors;
283
+ zodError.issues.forEach((issue) => {
284
+ const field = issue.path.join(".");
285
+ const message = issue.message;
286
+ if (!customErrors.some(
287
+ (customError) => customError.field === field && customError.message === message
288
+ )) {
289
+ customErrors.push({ field, message });
290
+ }
291
+ });
292
+ return customErrors;
293
+ };
294
+ var convertServerErrorToRequestError = (serverError, renameRules) => {
295
+ return {
296
+ ...serverError,
297
+ validationErrors: serverError.validationErrors.map((validationError) => {
298
+ const field = renameRules && renameRules[validationError.field] ? renameRules[validationError.field] : validationError.field;
299
+ return {
300
+ field,
301
+ message: ERROR_CODES[validationError.code] || "Unknown error"
302
+ };
303
+ })
304
+ };
305
+ };
306
+ var errors = ERROR_CONSTANTS;
307
+
308
+ // src/utils/currency.ts
309
+ function getCurrencySymbol(currency) {
310
+ const currencySymbols = {
311
+ USD: "$",
312
+ EUR: "\u20AC",
313
+ GBP: "\xA3",
314
+ CAD: "C$",
315
+ AUD: "A$",
316
+ JPY: "\xA5",
317
+ CHF: "CHF",
318
+ SEK: "kr",
319
+ NOK: "kr",
320
+ DKK: "kr",
321
+ PLN: "z\u0142",
322
+ CZK: "K\u010D",
323
+ HUF: "Ft",
324
+ RON: "lei",
325
+ BGN: "\u043B\u0432",
326
+ HRK: "kn",
327
+ RSD: "\u0434\u0438\u043D",
328
+ BAM: "KM",
329
+ MKD: "\u0434\u0435\u043D",
330
+ ALL: "L",
331
+ TRY: "\u20BA",
332
+ RUB: "\u20BD",
333
+ UAH: "\u20B4",
334
+ BYN: "Br",
335
+ CNY: "\xA5",
336
+ INR: "\u20B9",
337
+ KRW: "\u20A9",
338
+ THB: "\u0E3F",
339
+ VND: "\u20AB",
340
+ SGD: "S$",
341
+ MYR: "RM",
342
+ IDR: "Rp",
343
+ PHP: "\u20B1",
344
+ BRL: "R$",
345
+ ARS: "$",
346
+ CLP: "$",
347
+ COP: "$",
348
+ PEN: "S/",
349
+ MXN: "$",
350
+ ZAR: "R",
351
+ EGP: "E\xA3",
352
+ NGN: "\u20A6",
353
+ KES: "KSh",
354
+ GHS: "\u20B5",
355
+ MAD: "DH",
356
+ TND: "\u062F.\u062A",
357
+ DZD: "\u062F.\u062C",
358
+ LYD: "\u0644.\u062F",
359
+ AED: "\u062F.\u0625",
360
+ SAR: "\u0631.\u0633",
361
+ QAR: "\u0631.\u0642",
362
+ KWD: "\u062F.\u0643",
363
+ BHD: "\u0628.\u062F",
364
+ OMR: "\u0631.\u0639",
365
+ JOD: "\u062F.\u0623",
366
+ LBP: "\u0644.\u0644",
367
+ SYP: "\u0644.\u0633",
368
+ IQD: "\u0639.\u062F",
369
+ IRR: "\uFDFC",
370
+ AFN: "\u060B",
371
+ PKR: "\u20A8",
372
+ LKR: "\u20A8",
373
+ NPR: "\u20A8",
374
+ BDT: "\u09F3",
375
+ MMK: "K",
376
+ LAK: "\u20AD",
377
+ KHR: "\u17DB",
378
+ MNT: "\u20AE",
379
+ KZT: "\u20B8",
380
+ UZS: "\u043B\u0432",
381
+ KGS: "\u043B\u0432",
382
+ TJS: "SM",
383
+ TMT: "T",
384
+ AZN: "\u20BC",
385
+ GEL: "\u20BE",
386
+ AMD: "\u058F",
387
+ BYR: "p.",
388
+ MDL: "L"
389
+ };
390
+ return currencySymbols[currency.toUpperCase()] || currency;
391
+ }
392
+
393
+ // src/utils/price.ts
394
+ var CURRENCY_SYMBOLS = {
395
+ "USD": "$",
396
+ "EUR": "\u20AC",
397
+ "GBP": "\xA3",
398
+ "CAD": "C$",
399
+ "AUD": "A$"
400
+ };
401
+ var MARKET_CURRENCIES = {
402
+ "US": "USD",
403
+ "EU": "EUR",
404
+ "UK": "GBP",
405
+ "CA": "CAD",
406
+ "AU": "AUD"
407
+ };
408
+ function convertToMajor(minorAmount) {
409
+ return (minorAmount ?? 0) / 100;
410
+ }
411
+ function convertToMinor(majorAmount) {
412
+ return Math.round((majorAmount ?? 0) * 100);
413
+ }
414
+ function getSymbol(currency) {
415
+ return CURRENCY_SYMBOLS[currency] || "$";
416
+ }
417
+ function getCurrencyFromMarket(marketId) {
418
+ return MARKET_CURRENCIES[marketId] || "USD";
419
+ }
420
+ function formatCurrencyAmount(amount, currency, options = {}) {
421
+ const { showSymbols = true, decimalPlaces = 2, customSymbol } = options;
422
+ const roundedAmount = amount.toFixed(decimalPlaces);
423
+ if (!showSymbols) {
424
+ return `${roundedAmount} ${currency}`;
425
+ }
426
+ const symbol = customSymbol || getSymbol(currency);
427
+ return `${symbol}${roundedAmount}`;
428
+ }
429
+ function formatMinor(amountMinor, currency, options = {}) {
430
+ const major = convertToMajor(amountMinor);
431
+ return formatCurrencyAmount(major, currency, options);
432
+ }
433
+ function formatPayment(payment, options = {}) {
434
+ if (!payment) return "";
435
+ const { showSymbols = true, decimalPlaces = 2, showBreakdown = false } = options;
436
+ if (showBreakdown) {
437
+ const subtotal = formatMinor(payment.subtotal, payment.currency, { showSymbols, decimalPlaces });
438
+ const discount = (payment.discount ?? 0) > 0 ? formatMinor(payment.discount, payment.currency, { showSymbols, decimalPlaces }) : null;
439
+ const tax = (payment.tax ?? 0) > 0 ? formatMinor(payment.tax, payment.currency, { showSymbols, decimalPlaces }) : null;
440
+ const total = formatMinor(payment.total, payment.currency, { showSymbols, decimalPlaces });
441
+ let result = `Subtotal: ${subtotal}`;
442
+ if (discount) result += `, Discount: -${discount}`;
443
+ if (tax) result += `, Tax: ${tax}`;
444
+ result += `, Total: ${total}`;
445
+ return result;
446
+ }
447
+ return formatMinor(payment.total, payment.currency, { showSymbols, decimalPlaces });
448
+ }
449
+ function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
450
+ if (!prices || prices.length === 0) return "";
451
+ const {
452
+ showSymbols = true,
453
+ decimalPlaces = 2,
454
+ showCompareAt = true,
455
+ fallbackMarket = "US"
456
+ } = options;
457
+ let price = prices.find((p) => p.market === marketId);
458
+ if (!price) {
459
+ price = prices.find((p) => p.market === fallbackMarket) || prices[0];
460
+ }
461
+ if (!price) return "";
462
+ let currency;
463
+ let symbol;
464
+ if (businessMarkets) {
465
+ const marketData = businessMarkets.find((m) => m.id === price.market || m.code === price.market);
466
+ if (marketData?.currency) {
467
+ currency = marketData.currency;
468
+ symbol = getCurrencySymbol(currency);
469
+ } else {
470
+ currency = getCurrencyFromMarket(price.market);
471
+ symbol = getSymbol(currency);
472
+ }
473
+ } else {
474
+ currency = getCurrencyFromMarket(price.market);
475
+ symbol = getSymbol(currency);
476
+ }
477
+ const formattedPrice = formatMinor(price.amount ?? 0, currency, {
478
+ showSymbols,
479
+ decimalPlaces,
480
+ customSymbol: symbol
481
+ });
482
+ if (showCompareAt && price.compareAt && price.compareAt > (price.amount ?? 0)) {
483
+ const formattedCompareAt = formatMinor(price.compareAt, currency, {
484
+ showSymbols,
485
+ decimalPlaces,
486
+ customSymbol: symbol
487
+ });
488
+ return `${formattedPrice} was ${formattedCompareAt}`;
489
+ }
490
+ return formattedPrice;
491
+ }
492
+ function getPriceAmount(prices, marketId, fallbackMarket = "US") {
493
+ if (!prices || prices.length === 0) return 0;
494
+ const price = prices.find((p) => p.market === marketId) || prices.find((p) => p.market === fallbackMarket) || prices[0];
495
+ return price?.amount || 0;
496
+ }
497
+ function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
498
+ const { discount = 0, tax = 0, promoCodeId } = options;
499
+ const total = subtotalMinor - discount + tax;
500
+ return {
501
+ currency,
502
+ market: marketId,
503
+ subtotal: subtotalMinor,
504
+ shipping: 0,
505
+ discount,
506
+ tax,
507
+ total,
508
+ promoCodeId,
509
+ method: paymentMethod
510
+ };
511
+ }
512
+
513
+ // src/utils/svg.ts
514
+ async function fetchSvgContent(mediaObject) {
515
+ if (!mediaObject) return null;
516
+ const svgUrl = getImageUrl(mediaObject, false);
517
+ try {
518
+ const response = await fetch(svgUrl);
519
+ if (!response.ok) {
520
+ console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
521
+ return null;
522
+ }
523
+ const svgContent = await response.text();
524
+ return svgContent;
525
+ } catch (error) {
526
+ console.error("Error fetching SVG:", error);
527
+ return null;
528
+ }
529
+ }
530
+ async function getSvgContentForAstro(mediaObject) {
531
+ try {
532
+ const svgContent = await fetchSvgContent(mediaObject);
533
+ return svgContent || "";
534
+ } catch (error) {
535
+ console.error("Error getting SVG content for Astro:", error);
536
+ return "";
537
+ }
538
+ }
539
+ async function injectSvgIntoElement(mediaObject, targetElement, className) {
540
+ if (!targetElement) return;
541
+ try {
542
+ const svgContent = await fetchSvgContent(mediaObject);
543
+ if (svgContent) {
544
+ targetElement.innerHTML = svgContent;
545
+ if (className) {
546
+ const svgElement = targetElement.querySelector("svg");
547
+ if (svgElement) {
548
+ svgElement.classList.add(...className.split(" "));
549
+ }
550
+ }
551
+ }
552
+ } catch (error) {
553
+ console.error("Error injecting SVG:", error);
554
+ }
555
+ }
556
+
557
+ // src/utils/text.ts
558
+ var locales = ["en", "sr-latn"];
559
+ var localeMap = {
560
+ "en": "en-US",
561
+ "sr-latn": "sr-RS"
562
+ };
563
+ function slugify(text) {
564
+ return text.toString().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
565
+ }
566
+ function humanize(text) {
567
+ const slugifiedText = slugify(text);
568
+ return slugifiedText.replace(/-/g, " ").replace(
569
+ // upper case first letter of every word, and lower case the rest
570
+ /\w\S*/g,
571
+ (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()
572
+ );
573
+ }
574
+ function categorify(text) {
575
+ const slugifiedText = slugify(text);
576
+ return slugifiedText.replace(/-/g, " ").toUpperCase();
577
+ }
578
+ function formatDate(date, locale) {
579
+ let localeString = "en-US";
580
+ if (locales.includes(locale)) {
581
+ localeString = localeMap[locale];
582
+ }
583
+ return new Date(date).toLocaleDateString(localeString, {
584
+ timeZone: "UTC",
585
+ year: "numeric",
586
+ month: "short",
587
+ day: "numeric"
588
+ });
589
+ }
590
+
591
+ // src/utils/timezone.ts
592
+ var tzGroups = [
593
+ {
594
+ label: "US",
595
+ zones: [
596
+ { label: "Eastern Time", value: "America/New_York" },
597
+ { label: "Central Time", value: "America/Chicago" },
598
+ { label: "Mountain Time", value: "America/Denver" },
599
+ { label: "Pacific Time", value: "America/Los_Angeles" }
600
+ ]
601
+ },
602
+ {
603
+ label: "Europe",
604
+ zones: [
605
+ { label: "London", value: "Europe/London" },
606
+ { label: "Paris", value: "Europe/Paris" },
607
+ { label: "Berlin", value: "Europe/Berlin" },
608
+ { label: "Rome", value: "Europe/Rome" }
609
+ ]
610
+ },
611
+ {
612
+ label: "Asia",
613
+ zones: [
614
+ { label: "Tokyo", value: "Asia/Tokyo" },
615
+ { label: "Shanghai", value: "Asia/Shanghai" },
616
+ { label: "Mumbai", value: "Asia/Kolkata" },
617
+ { label: "Dubai", value: "Asia/Dubai" }
618
+ ]
619
+ }
620
+ ];
621
+ function findTimeZone(groups) {
622
+ try {
623
+ const detected = Intl.DateTimeFormat().resolvedOptions().timeZone;
624
+ for (const group of groups) {
625
+ for (const zone of group.zones) {
626
+ if (zone.value === detected) {
627
+ return detected;
628
+ }
629
+ }
630
+ }
631
+ return "UTC";
632
+ } catch (e) {
633
+ return "UTC";
634
+ }
635
+ }
636
+
637
+ // src/utils/validation.ts
638
+ function validatePhoneNumber(phone) {
639
+ if (!phone) {
640
+ return { isValid: false, error: "Phone number is required" };
641
+ }
642
+ const cleaned = phone.replace(/\D/g, "");
643
+ if (cleaned.length < 8) {
644
+ return { isValid: false, error: "Phone number is too short" };
645
+ }
646
+ if (cleaned.length > 15) {
647
+ return { isValid: false, error: "Phone number is too long" };
648
+ }
649
+ return { isValid: true };
650
+ }
651
+ function validateEmail(email) {
652
+ if (!email) {
653
+ return { isValid: false, error: "Email is required" };
654
+ }
655
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
656
+ if (!emailRegex.test(email)) {
657
+ return { isValid: false, error: "Please enter a valid email address" };
658
+ }
659
+ return { isValid: true };
660
+ }
661
+ function validateVerificationCode(code) {
662
+ if (!code) {
663
+ return { isValid: false, error: "Verification code is required" };
664
+ }
665
+ const cleaned = code.replace(/\D/g, "");
666
+ if (cleaned.length !== 4) {
667
+ return { isValid: false, error: "Please enter a 4-digit verification code" };
668
+ }
669
+ return { isValid: true };
670
+ }
671
+ function validateRequired(value, fieldName = "This field") {
672
+ if (value === null || value === void 0 || value === "") {
673
+ return { isValid: false, error: `${fieldName} is required` };
674
+ }
675
+ return { isValid: true };
676
+ }
677
+
678
+ export { ERROR_CODES, ERROR_CONSTANTS, categorify, convertServerErrorToRequestError, convertToMajor, convertToMinor, createPaymentForCheckout, errors, extractBlockValues, fetchSvgContent, findTimeZone, formatBlockValue, formatCurrencyAmount, formatDate, formatMinor, formatPayment, getBlockFromArray, getBlockLabel, getBlockObjectValues, getBlockTextValue, getBlockValue, getBlockValues, getCurrencyFromMarket, getCurrencySymbol, getErrorMessage, getGalleryThumbnail, getImageUrl, getMarketPrice, getPriceAmount, getSvgContentForAstro, getSymbol, humanize, injectSvgIntoElement, isErrorCode, prepareBlocksForSubmission, slugify, thumbnailUrl, transformErrors, translateMap, tzGroups, validateEmail, validatePhoneNumber, validateRequired, validateVerificationCode };
679
+ //# sourceMappingURL=utils.js.map
680
+ //# sourceMappingURL=utils.js.map