arky-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/api/cms.d.ts +19 -0
  2. package/dist/api/cms.d.ts.map +1 -0
  3. package/dist/api/cms.js +41 -0
  4. package/dist/api/eshop.d.ts +89 -0
  5. package/dist/api/eshop.d.ts.map +1 -0
  6. package/dist/api/eshop.js +183 -0
  7. package/dist/api/index.d.ts +6 -0
  8. package/dist/api/index.d.ts.map +1 -0
  9. package/dist/api/index.js +5 -0
  10. package/dist/api/newsletter.d.ts +32 -0
  11. package/dist/api/newsletter.d.ts.map +1 -0
  12. package/dist/api/newsletter.js +70 -0
  13. package/dist/api/reservation.d.ts +84 -0
  14. package/dist/api/reservation.d.ts.map +1 -0
  15. package/dist/api/reservation.js +239 -0
  16. package/dist/config.d.ts +15 -0
  17. package/dist/config.d.ts.map +1 -0
  18. package/dist/config.js +20 -0
  19. package/dist/index.d.ts +26 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +57 -0
  22. package/dist/services/auth.d.ts +17 -0
  23. package/dist/services/auth.d.ts.map +1 -0
  24. package/dist/services/auth.js +62 -0
  25. package/dist/services/http.d.ts +20 -0
  26. package/dist/services/http.d.ts.map +1 -0
  27. package/dist/services/http.js +73 -0
  28. package/dist/stores/business.d.ts +28 -0
  29. package/dist/stores/business.d.ts.map +1 -0
  30. package/dist/stores/business.js +122 -0
  31. package/dist/stores/cart.d.ts +8 -0
  32. package/dist/stores/cart.d.ts.map +1 -0
  33. package/dist/stores/cart.js +20 -0
  34. package/dist/stores/eshop.d.ts +121 -0
  35. package/dist/stores/eshop.d.ts.map +1 -0
  36. package/dist/stores/eshop.js +377 -0
  37. package/dist/stores/index.d.ts +7 -0
  38. package/dist/stores/index.d.ts.map +1 -0
  39. package/dist/stores/index.js +19 -0
  40. package/dist/stores/reservation.d.ts +237 -0
  41. package/dist/stores/reservation.d.ts.map +1 -0
  42. package/dist/stores/reservation.js +853 -0
  43. package/dist/types/index.d.ts +244 -0
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/dist/types/index.js +8 -0
  46. package/dist/utils/blocks.d.ts +30 -0
  47. package/dist/utils/blocks.d.ts.map +1 -0
  48. package/dist/utils/blocks.js +237 -0
  49. package/dist/utils/currency.d.ts +9 -0
  50. package/dist/utils/currency.d.ts.map +1 -0
  51. package/dist/utils/currency.js +99 -0
  52. package/dist/utils/errors.d.ts +121 -0
  53. package/dist/utils/errors.d.ts.map +1 -0
  54. package/dist/utils/errors.js +114 -0
  55. package/dist/utils/i18n.d.ts +5 -0
  56. package/dist/utils/i18n.d.ts.map +1 -0
  57. package/dist/utils/i18n.js +37 -0
  58. package/dist/utils/index.d.ts +9 -0
  59. package/dist/utils/index.d.ts.map +1 -0
  60. package/dist/utils/index.js +10 -0
  61. package/dist/utils/price.d.ts +33 -0
  62. package/dist/utils/price.d.ts.map +1 -0
  63. package/dist/utils/price.js +141 -0
  64. package/dist/utils/queryParams.d.ts +21 -0
  65. package/dist/utils/queryParams.d.ts.map +1 -0
  66. package/dist/utils/queryParams.js +47 -0
  67. package/dist/utils/svg.d.ts +17 -0
  68. package/dist/utils/svg.d.ts.map +1 -0
  69. package/dist/utils/svg.js +62 -0
  70. package/dist/utils/text.d.ts +26 -0
  71. package/dist/utils/text.d.ts.map +1 -0
  72. package/dist/utils/text.js +64 -0
  73. package/dist/utils/timezone.d.ts +9 -0
  74. package/dist/utils/timezone.d.ts.map +1 -0
  75. package/dist/utils/timezone.js +49 -0
  76. package/dist/utils/validation.d.ts +9 -0
  77. package/dist/utils/validation.d.ts.map +1 -0
  78. package/dist/utils/validation.js +44 -0
  79. package/package.json +58 -0
@@ -0,0 +1,121 @@
1
+ export declare const ERROR_CODES: {
2
+ "GENERAL.001": string;
3
+ "GENERAL.002": string;
4
+ "GENERAL.003": string;
5
+ "GENERAL.004": string;
6
+ "GENERAL.005": string;
7
+ "GENERAL.006": string;
8
+ "GOOGLE.001": string;
9
+ "GOOGLE.002": string;
10
+ "GOOGLE.003": string;
11
+ "GOOGLE.004": string;
12
+ "GOOGLE.005": string;
13
+ "GOOGLE.006": string;
14
+ "GOOGLE.007": string;
15
+ "USER.001": string;
16
+ "USER.002": string;
17
+ "USER.003": string;
18
+ "USER.004": string;
19
+ "USER.005": string;
20
+ "USER.006": string;
21
+ "BUSINESS.001": string;
22
+ "BUSINESS.002": string;
23
+ "BUSINESS.003": string;
24
+ "BUSINESS.004": string;
25
+ "BUSINESS.005": string;
26
+ "BUSINESS.006": string;
27
+ "BUSINESS.007": string;
28
+ "BUSINESS.010": string;
29
+ "BUSINESS.011": string;
30
+ "PROVIDER.001": string;
31
+ "PROVIDER.002": string;
32
+ "PROVIDER.003": string;
33
+ "PROVIDER.004": string;
34
+ "PROVIDER.005": string;
35
+ "PROVIDER.006": string;
36
+ "PROVIDER.007": string;
37
+ "PROVIDER.008": string;
38
+ };
39
+ export declare const ERROR_CONSTANTS: {
40
+ GENERAL: {
41
+ BAD_REQUEST: string;
42
+ VALIDATION_ERROR: string;
43
+ FORBIDDEN_ERROR: string;
44
+ INTERNAL_SERVER_ERROR: string;
45
+ UNAUTHORIZED: string;
46
+ UNAUTHENTICATED: string;
47
+ };
48
+ USER: {
49
+ NOT_FOUND: string;
50
+ FAILED_TO_CREATE: string;
51
+ FAILED_TO_UPDATE: string;
52
+ FAILED_TO_DELETE: string;
53
+ EMAIL_EXISTS: string;
54
+ FAILED_TO_GET_UPLOAD_URL: string;
55
+ };
56
+ BUSINESS: {
57
+ NOT_FOUND: string;
58
+ FAILED_TO_CREATE: string;
59
+ FAILED_TO_UPDATE: string;
60
+ FAILED_TO_DELETE: string;
61
+ FAILED_TO_GET_UPLOAD_URL: string;
62
+ NAME_REQUIRED: string;
63
+ BUSINESS_ID_REQUIRED: string;
64
+ DESCRIPTION_REQUIRED: string;
65
+ SLUG_INVALID: string;
66
+ };
67
+ };
68
+ export type ServerError = {
69
+ error: string;
70
+ reason: string;
71
+ code: string;
72
+ statusCode: number;
73
+ validationErrors: {
74
+ field: string;
75
+ code: string;
76
+ }[];
77
+ };
78
+ export type ValidationError = {
79
+ field: string;
80
+ message: string;
81
+ };
82
+ export type RequestError = {
83
+ validationErrors: ValidationError[];
84
+ };
85
+ export declare function getErrorMessage(code: string): string;
86
+ export declare function isErrorCode(code: string): boolean;
87
+ export declare const transformErrors: (zodError: any) => ValidationError[];
88
+ export declare const convertServerErrorToRequestError: (serverError: ServerError, renameRules?: {
89
+ [key: string]: string;
90
+ }) => RequestError;
91
+ export declare const errors: {
92
+ GENERAL: {
93
+ BAD_REQUEST: string;
94
+ VALIDATION_ERROR: string;
95
+ FORBIDDEN_ERROR: string;
96
+ INTERNAL_SERVER_ERROR: string;
97
+ UNAUTHORIZED: string;
98
+ UNAUTHENTICATED: string;
99
+ };
100
+ USER: {
101
+ NOT_FOUND: string;
102
+ FAILED_TO_CREATE: string;
103
+ FAILED_TO_UPDATE: string;
104
+ FAILED_TO_DELETE: string;
105
+ EMAIL_EXISTS: string;
106
+ FAILED_TO_GET_UPLOAD_URL: string;
107
+ };
108
+ BUSINESS: {
109
+ NOT_FOUND: string;
110
+ FAILED_TO_CREATE: string;
111
+ FAILED_TO_UPDATE: string;
112
+ FAILED_TO_DELETE: string;
113
+ FAILED_TO_GET_UPLOAD_URL: string;
114
+ NAME_REQUIRED: string;
115
+ BUSINESS_ID_REQUIRED: string;
116
+ DESCRIPTION_REQUIRED: string;
117
+ SLUG_INVALID: string;
118
+ };
119
+ };
120
+ export default ERROR_CODES;
121
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CvB,CAAC;AAGF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4B3B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACP,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB,gBAAgB,EAAE,eAAe,EAAE,CAAC;CACvC,CAAC;AAGF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAID,eAAO,MAAM,eAAe,GAAI,UAAU,GAAG,KAAG,eAAe,EAmB9D,CAAC;AAEF,eAAO,MAAM,gCAAgC,GACzC,aAAa,WAAW,EACxB,cAAc;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,KACxC,YAeF,CAAC;AAGF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkB,CAAC;AACtC,eAAe,WAAW,CAAC"}
@@ -0,0 +1,114 @@
1
+ // Error handling utilities (combined from errorCodes.ts and errorHelpers.ts)
2
+ // Comprehensive error code system with both numeric codes and named constants
3
+ export const ERROR_CODES = {
4
+ // General errors
5
+ "GENERAL.001": "GENERAL.BAD_REQUEST",
6
+ "GENERAL.002": "GENERAL.VALIDATION_ERROR",
7
+ "GENERAL.003": "GENERAL.FORBIDDEN_ERROR",
8
+ "GENERAL.004": "GENERAL.INTERNAL_SERVER_ERROR",
9
+ "GENERAL.005": "GENERAL.UNAUTHORIZED",
10
+ "GENERAL.006": "GENERAL.UNAUTHENTICATED",
11
+ // Google/OAuth errors
12
+ "GOOGLE.001": "GOOGLE.INVALID_ORIGIN_URI",
13
+ "GOOGLE.002": "GOOGLE.INVALID_REDIRECT_URI",
14
+ "GOOGLE.003": "GOOGLE.FAILED_TO_CALL_API",
15
+ "GOOGLE.004": "GOOGLE.FAILED_LOGIN",
16
+ "GOOGLE.005": "GOOGLE.FAILED_LOGOUT",
17
+ "GOOGLE.006": "GOOGLE.FAILED_REFRESH_TOKEN",
18
+ "GOOGLE.007": "GOOGLE.INVALID_PROVIDER_PASSED",
19
+ // User errors
20
+ "USER.001": "USER.NOT_FOUND",
21
+ "USER.002": "USER.FAILED_TO_CREATE",
22
+ "USER.003": "USER.FAILED_TO_UPDATE",
23
+ "USER.004": "USER.FAILED_TO_DELETE",
24
+ "USER.005": "USER.EMAIL_EXISTS",
25
+ "USER.006": "USER.FAILED_TO_GET_UPLOAD_URL",
26
+ // Business errors
27
+ "BUSINESS.001": "BUSINESS.NOT_FOUND",
28
+ "BUSINESS.002": "BUSINESS.FAILED_TO_CREATE",
29
+ "BUSINESS.003": "BUSINESS.FAILED_TO_UPDATE",
30
+ "BUSINESS.004": "BUSINESS.FAILED_TO_DELETE",
31
+ "BUSINESS.005": "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
32
+ "BUSINESS.006": "BUSINESS.NAME_REQUIRED",
33
+ "BUSINESS.007": "BUSINESS.BUSINESS_ID_REQUIRED",
34
+ "BUSINESS.010": "BUSINESS.DESCRIPTION_REQUIRED",
35
+ "BUSINESS.011": "BUSINESS.SLUG_INVALID",
36
+ // Provider errors
37
+ "PROVIDER.001": "PROVIDER.NOT_FOUND",
38
+ "PROVIDER.002": "PROVIDER.FAILED_TO_CREATE",
39
+ "PROVIDER.003": "PROVIDER.FAILED_TO_UPDATE",
40
+ "PROVIDER.004": "PROVIDER.FAILED_TO_DELETE",
41
+ "PROVIDER.005": "PROVIDER.FAILED_TO_GET_UPLOAD_URL",
42
+ "PROVIDER.006": "PROVIDER.NAME_REQUIRED",
43
+ "PROVIDER.007": "PROVIDER.BUSINESS_ID_REQUIRED",
44
+ "PROVIDER.008": "PROVIDER.DESCRIPTION_REQUIRED",
45
+ };
46
+ // Named error constants for direct access
47
+ export const ERROR_CONSTANTS = {
48
+ GENERAL: {
49
+ BAD_REQUEST: "GENERAL.BAD_REQUEST",
50
+ VALIDATION_ERROR: "GENERAL.VALIDATION_ERROR",
51
+ FORBIDDEN_ERROR: "GENERAL.FORBIDDEN_ERROR",
52
+ INTERNAL_SERVER_ERROR: "GENERAL.INTERNAL_SERVER_ERROR",
53
+ UNAUTHORIZED: "GENERAL.UNAUTHORIZED",
54
+ UNAUTHENTICATED: "GENERAL.UNAUTHENTICATED",
55
+ },
56
+ USER: {
57
+ NOT_FOUND: "USER.NOT_FOUND",
58
+ FAILED_TO_CREATE: "USER.FAILED_TO_CREATE",
59
+ FAILED_TO_UPDATE: "USER.FAILED_TO_UPDATE",
60
+ FAILED_TO_DELETE: "USER.FAILED_TO_DELETE",
61
+ EMAIL_EXISTS: "USER.EMAIL_EXISTS",
62
+ FAILED_TO_GET_UPLOAD_URL: "USER.FAILED_TO_GET_UPLOAD_URL",
63
+ },
64
+ BUSINESS: {
65
+ NOT_FOUND: "BUSINESS.NOT_FOUND",
66
+ FAILED_TO_CREATE: "BUSINESS.FAILED_TO_CREATE",
67
+ FAILED_TO_UPDATE: "BUSINESS.FAILED_TO_UPDATE",
68
+ FAILED_TO_DELETE: "BUSINESS.FAILED_TO_DELETE",
69
+ FAILED_TO_GET_UPLOAD_URL: "BUSINESS.FAILED_TO_GET_UPLOAD_URL",
70
+ NAME_REQUIRED: "BUSINESS.NAME_REQUIRED",
71
+ BUSINESS_ID_REQUIRED: "BUSINESS.BUSINESS_ID_REQUIRED",
72
+ DESCRIPTION_REQUIRED: "BUSINESS.DESCRIPTION_REQUIRED",
73
+ SLUG_INVALID: "BUSINESS.SLUG_INVALID",
74
+ },
75
+ };
76
+ // Utility functions for error handling
77
+ export function getErrorMessage(code) {
78
+ return ERROR_CODES[code] || code;
79
+ }
80
+ export function isErrorCode(code) {
81
+ return code in ERROR_CODES;
82
+ }
83
+ // Note: transformErrors requires zod which is not a dependency
84
+ // If you need zod validation, add it to package.json dependencies
85
+ export const transformErrors = (zodError) => {
86
+ const customErrors = [];
87
+ if (!zodError.issues)
88
+ return customErrors;
89
+ zodError.issues.forEach((issue) => {
90
+ const field = issue.path.join(".");
91
+ const message = issue.message;
92
+ if (!customErrors.some((customError) => customError.field === field && customError.message === message)) {
93
+ customErrors.push({ field, message });
94
+ }
95
+ });
96
+ return customErrors;
97
+ };
98
+ export const convertServerErrorToRequestError = (serverError, renameRules) => {
99
+ return {
100
+ ...serverError,
101
+ validationErrors: serverError.validationErrors.map((validationError) => {
102
+ const field = renameRules && renameRules[validationError.field]
103
+ ? renameRules[validationError.field]
104
+ : validationError.field;
105
+ return {
106
+ field: field,
107
+ message: ERROR_CODES[validationError.code] || "Unknown error",
108
+ };
109
+ }),
110
+ };
111
+ };
112
+ // Export for backward compatibility
113
+ export const errors = ERROR_CONSTANTS;
114
+ export default ERROR_CODES;
@@ -0,0 +1,5 @@
1
+ export declare function setDefaultLocale(locale: string): void;
2
+ export declare function getLocale(): string;
3
+ export declare function getLocaleFromUrl(url: URL): string;
4
+ export declare function getLocalizedString(value: any, locale?: string): string;
5
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/utils/i18n.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAErD;AAED,wBAAgB,SAAS,IAAI,MAAM,CAMlC;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAajD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAatE"}
@@ -0,0 +1,37 @@
1
+ // Simple i18n utilities for SDK
2
+ // Can be enhanced or replaced by user's i18n library
3
+ let defaultLocale = 'en';
4
+ export function setDefaultLocale(locale) {
5
+ defaultLocale = locale;
6
+ }
7
+ export function getLocale() {
8
+ // Try to get from browser if available
9
+ if (typeof window !== 'undefined' && window.navigator) {
10
+ return window.navigator.language.split('-')[0] || defaultLocale;
11
+ }
12
+ return defaultLocale;
13
+ }
14
+ export function getLocaleFromUrl(url) {
15
+ // Simple implementation - can be enhanced
16
+ const pathParts = url.pathname.split('/').filter(Boolean);
17
+ const potentialLocale = pathParts[0];
18
+ // Common locale codes
19
+ const validLocales = ['en', 'fr', 'es', 'de', 'it', 'pt', 'ja', 'zh', 'ko', 'ru'];
20
+ if (potentialLocale && validLocales.includes(potentialLocale)) {
21
+ return potentialLocale;
22
+ }
23
+ return getLocale();
24
+ }
25
+ export function getLocalizedString(value, locale) {
26
+ if (!value)
27
+ return '';
28
+ // If it's already a string, return it
29
+ if (typeof value === 'string')
30
+ return value;
31
+ // If it's an object with locale keys
32
+ if (typeof value === 'object') {
33
+ const targetLocale = locale || getLocale();
34
+ return value[targetLocale] || value['en'] || value[Object.keys(value)[0]] || '';
35
+ }
36
+ return String(value);
37
+ }
@@ -0,0 +1,9 @@
1
+ export * from './blocks';
2
+ export * from './errors';
3
+ export * from './price';
4
+ export * from './svg';
5
+ export * from './text';
6
+ export * from './timezone';
7
+ export * from './validation';
8
+ export { getCurrencySymbol } from './currency';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAG7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ // Utilities entry point (@arky/sdk/utils)
2
+ export * from './blocks';
3
+ export * from './errors';
4
+ export * from './price';
5
+ export * from './svg';
6
+ export * from './text';
7
+ export * from './timezone';
8
+ export * from './validation';
9
+ // Export specific functions from currency to avoid conflicts with price.ts
10
+ export { getCurrencySymbol } from './currency';
@@ -0,0 +1,33 @@
1
+ import type { Payment, Price } from '../types';
2
+ export declare function convertToMajor(minorAmount: number): number;
3
+ export declare function convertToMinor(majorAmount: number): number;
4
+ export declare function getSymbol(currency: string): string;
5
+ export declare function getCurrencyFromMarket(marketId: string): string;
6
+ export declare function formatCurrencyAmount(amount: number, currency: string, options?: {
7
+ showSymbols?: boolean;
8
+ decimalPlaces?: number;
9
+ customSymbol?: string;
10
+ }): string;
11
+ export declare function formatMinor(amountMinor: number, currency: string, options?: {
12
+ showSymbols?: boolean;
13
+ decimalPlaces?: number;
14
+ customSymbol?: string;
15
+ }): string;
16
+ export declare function formatPayment(payment: Payment, options?: {
17
+ showSymbols?: boolean;
18
+ decimalPlaces?: number;
19
+ showBreakdown?: boolean;
20
+ }): string;
21
+ export declare function getMarketPrice(prices: Price[], marketId: string, businessMarkets?: any[], options?: {
22
+ showSymbols?: boolean;
23
+ decimalPlaces?: number;
24
+ showCompareAt?: boolean;
25
+ fallbackMarket?: string;
26
+ }): string;
27
+ export declare function getPriceAmount(prices: Price[], marketId: string, fallbackMarket?: string): number;
28
+ export declare function createPaymentForCheckout(subtotalMinor: number, marketId: string, currency: string, paymentMethod: any, options?: {
29
+ discount?: number;
30
+ tax?: number;
31
+ promoCodeId?: string;
32
+ }): Payment;
33
+ //# sourceMappingURL=price.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAqB9D,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1D;AAGD,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1D;AAGD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElD;AAGD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IACL,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACpB,GACP,MAAM,CAUR;AAGD,wBAAgB,WAAW,CACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IACL,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACpB,GACP,MAAM,CAGR;AAGD,wBAAgB,aAAa,CACzB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IACL,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACtB,GACP,MAAM,CAmBR;AAGD,wBAAgB,cAAc,CAC1B,MAAM,EAAE,KAAK,EAAE,EACf,QAAQ,EAAE,MAAM,EAChB,eAAe,CAAC,EAAE,GAAG,EAAE,EACvB,OAAO,GAAE;IACL,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;CACtB,GACP,MAAM,CAwDR;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,GAAE,MAAa,GAAG,MAAM,CASvG;AAGD,wBAAgB,wBAAwB,CACpC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,GAAG,EAClB,OAAO,GAAE;IACL,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACnB,GACP,OAAO,CAeT"}
@@ -0,0 +1,141 @@
1
+ import { getCurrencySymbol } from './currency';
2
+ // Market-based currency symbols mapping
3
+ const CURRENCY_SYMBOLS = {
4
+ 'USD': '$',
5
+ 'EUR': '€',
6
+ 'GBP': '£',
7
+ 'CAD': 'C$',
8
+ 'AUD': 'A$'
9
+ };
10
+ const MARKET_CURRENCIES = {
11
+ 'US': 'USD',
12
+ 'EU': 'EUR',
13
+ 'UK': 'GBP',
14
+ 'CA': 'CAD',
15
+ 'AU': 'AUD'
16
+ };
17
+ // Convert minor units (cents) to major units (dollars)
18
+ export function convertToMajor(minorAmount) {
19
+ return (minorAmount ?? 0) / 100;
20
+ }
21
+ // Convert major units to minor units
22
+ export function convertToMinor(majorAmount) {
23
+ return Math.round((majorAmount ?? 0) * 100);
24
+ }
25
+ // Get currency symbol from currency code
26
+ export function getSymbol(currency) {
27
+ return CURRENCY_SYMBOLS[currency] || '$';
28
+ }
29
+ // Get currency from market ID
30
+ export function getCurrencyFromMarket(marketId) {
31
+ return MARKET_CURRENCIES[marketId] || 'USD';
32
+ }
33
+ // Format currency amount with symbol
34
+ export function formatCurrencyAmount(amount, currency, options = {}) {
35
+ const { showSymbols = true, decimalPlaces = 2, customSymbol } = options;
36
+ const roundedAmount = amount.toFixed(decimalPlaces);
37
+ if (!showSymbols) {
38
+ return `${roundedAmount} ${currency}`;
39
+ }
40
+ const symbol = customSymbol || getSymbol(currency);
41
+ return `${symbol}${roundedAmount}`;
42
+ }
43
+ // Format minor units with currency
44
+ export function formatMinor(amountMinor, currency, options = {}) {
45
+ const major = convertToMajor(amountMinor);
46
+ return formatCurrencyAmount(major, currency, options);
47
+ }
48
+ // Format Payment structure for display
49
+ export function formatPayment(payment, options = {}) {
50
+ if (!payment)
51
+ return '';
52
+ const { showSymbols = true, decimalPlaces = 2, showBreakdown = false } = options;
53
+ if (showBreakdown) {
54
+ const subtotal = formatMinor(payment.subtotal, payment.currency, { showSymbols, decimalPlaces });
55
+ const discount = (payment.discount ?? 0) > 0 ? formatMinor(payment.discount, payment.currency, { showSymbols, decimalPlaces }) : null;
56
+ const tax = (payment.tax ?? 0) > 0 ? formatMinor(payment.tax, payment.currency, { showSymbols, decimalPlaces }) : null;
57
+ const total = formatMinor(payment.total, payment.currency, { showSymbols, decimalPlaces });
58
+ let result = `Subtotal: ${subtotal}`;
59
+ if (discount)
60
+ result += `, Discount: -${discount}`;
61
+ if (tax)
62
+ result += `, Tax: ${tax}`;
63
+ result += `, Total: ${total}`;
64
+ return result;
65
+ }
66
+ return formatMinor(payment.total, payment.currency, { showSymbols, decimalPlaces });
67
+ }
68
+ // Format market-based prices (from product variants)
69
+ export function getMarketPrice(prices, marketId, businessMarkets, options = {}) {
70
+ if (!prices || prices.length === 0)
71
+ return '';
72
+ const { showSymbols = true, decimalPlaces = 2, showCompareAt = true, fallbackMarket = 'US', } = options;
73
+ // Find price for the specific market
74
+ let price = prices.find(p => p.market === marketId);
75
+ // Fallback to first available or fallback market
76
+ if (!price) {
77
+ price = prices.find(p => p.market === fallbackMarket) || prices[0];
78
+ }
79
+ if (!price)
80
+ return '';
81
+ let currency;
82
+ let symbol;
83
+ // If we have business markets, use the currency directly from market data
84
+ if (businessMarkets) {
85
+ const marketData = businessMarkets.find(m => m.id === price.market || m.code === price.market);
86
+ if (marketData?.currency) {
87
+ currency = marketData.currency;
88
+ symbol = getCurrencySymbol(currency);
89
+ }
90
+ else {
91
+ currency = getCurrencyFromMarket(price.market);
92
+ symbol = getSymbol(currency);
93
+ }
94
+ }
95
+ else {
96
+ currency = getCurrencyFromMarket(price.market);
97
+ symbol = getSymbol(currency);
98
+ }
99
+ // Format price with custom symbol
100
+ const formattedPrice = formatMinor(price.amount ?? 0, currency, {
101
+ showSymbols,
102
+ decimalPlaces,
103
+ customSymbol: symbol
104
+ });
105
+ // Add compare-at price if available
106
+ if (showCompareAt && price.compareAt && price.compareAt > (price.amount ?? 0)) {
107
+ const formattedCompareAt = formatMinor(price.compareAt, currency, {
108
+ showSymbols,
109
+ decimalPlaces,
110
+ customSymbol: symbol
111
+ });
112
+ return `${formattedPrice} was ${formattedCompareAt}`;
113
+ }
114
+ return formattedPrice;
115
+ }
116
+ // Get price amount from market-based prices (for calculations)
117
+ export function getPriceAmount(prices, marketId, fallbackMarket = 'US') {
118
+ if (!prices || prices.length === 0)
119
+ return 0;
120
+ const price = prices.find(p => p.market === marketId) ||
121
+ prices.find(p => p.market === fallbackMarket) ||
122
+ prices[0];
123
+ // Amounts are stored in minor units (e.g., cents)
124
+ return price?.amount || 0;
125
+ }
126
+ // Create Payment structure for checkout (all amounts in minor units)
127
+ export function createPaymentForCheckout(subtotalMinor, marketId, currency, paymentMethod, options = {}) {
128
+ const { discount = 0, tax = 0, promoCodeId } = options;
129
+ const total = subtotalMinor - discount + tax;
130
+ return {
131
+ currency,
132
+ market: marketId,
133
+ subtotal: subtotalMinor,
134
+ shipping: 0,
135
+ discount,
136
+ tax,
137
+ total,
138
+ promoCodeId,
139
+ method: paymentMethod,
140
+ };
141
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Query parameter builder utility that maintains exact backward compatibility
3
+ * with existing API parameter encoding patterns
4
+ */
5
+ export interface QueryParams {
6
+ [key: string]: string | number | boolean | string[] | number[] | null | undefined;
7
+ }
8
+ /**
9
+ * Builds a query string from parameters following the exact encoding patterns
10
+ * used by the existing API implementation:
11
+ * - Arrays: JSON.stringify then encodeURIComponent
12
+ * - Strings: encodeURIComponent
13
+ * - Numbers: No encoding
14
+ * - Null/undefined: Skip
15
+ */
16
+ export declare function buildQueryString(params: QueryParams): string;
17
+ /**
18
+ * Appends query string to a URL
19
+ */
20
+ export declare function appendQueryString(url: string, params: QueryParams): string;
21
+ //# sourceMappingURL=queryParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryParams.d.ts","sourceRoot":"","sources":["../../src/utils/queryParams.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;CACrF;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CA8B5D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,CAG1E"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Query parameter builder utility that maintains exact backward compatibility
3
+ * with existing API parameter encoding patterns
4
+ */
5
+ /**
6
+ * Builds a query string from parameters following the exact encoding patterns
7
+ * used by the existing API implementation:
8
+ * - Arrays: JSON.stringify then encodeURIComponent
9
+ * - Strings: encodeURIComponent
10
+ * - Numbers: No encoding
11
+ * - Null/undefined: Skip
12
+ */
13
+ export function buildQueryString(params) {
14
+ const queryParts = [];
15
+ Object.entries(params).forEach(([key, value]) => {
16
+ // Skip null and undefined values
17
+ if (value === null || value === undefined) {
18
+ return;
19
+ }
20
+ // Handle arrays: JSON.stringify then encode
21
+ if (Array.isArray(value)) {
22
+ const jsonString = JSON.stringify(value);
23
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
24
+ }
25
+ // Handle strings: encode
26
+ else if (typeof value === 'string') {
27
+ queryParts.push(`${key}=${encodeURIComponent(value)}`);
28
+ }
29
+ // Handle numbers and booleans: no encoding
30
+ else if (typeof value === 'number' || typeof value === 'boolean') {
31
+ queryParts.push(`${key}=${value}`);
32
+ }
33
+ // Handle objects (in case needed in future): JSON.stringify then encode
34
+ else if (typeof value === 'object') {
35
+ const jsonString = JSON.stringify(value);
36
+ queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
37
+ }
38
+ });
39
+ return queryParts.length > 0 ? `?${queryParts.join('&')}` : '';
40
+ }
41
+ /**
42
+ * Appends query string to a URL
43
+ */
44
+ export function appendQueryString(url, params) {
45
+ const queryString = buildQueryString(params);
46
+ return queryString ? `${url}${queryString}` : url;
47
+ }
@@ -0,0 +1,17 @@
1
+ export declare function fetchSvgContent(mediaObject: any): Promise<string | null>;
2
+ /**
3
+ * Server-side helper for Astro components to fetch SVG content during SSR
4
+ *
5
+ * @param mediaObject The media object from the CMS
6
+ * @returns The SVG content as a string, or empty string on failure
7
+ */
8
+ export declare function getSvgContentForAstro(mediaObject: any): Promise<string>;
9
+ /**
10
+ * Client-side helper to fetch and inject SVG content into DOM elements
11
+ *
12
+ * @param mediaObject The media object from the CMS
13
+ * @param targetElement The DOM element to inject the SVG into
14
+ * @param className Optional CSS class to add to the SVG
15
+ */
16
+ export declare function injectSvgIntoElement(mediaObject: any, targetElement: HTMLElement, className?: string): Promise<void>;
17
+ //# sourceMappingURL=svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../src/utils/svg.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmB9E;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ7E;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACzC,WAAW,EAAE,GAAG,EAChB,aAAa,EAAE,WAAW,EAC1B,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAoBf"}
@@ -0,0 +1,62 @@
1
+ import { getImageUrl } from "./blocks";
2
+ export async function fetchSvgContent(mediaObject) {
3
+ if (!mediaObject)
4
+ return null;
5
+ const svgUrl = getImageUrl(mediaObject, false);
6
+ try {
7
+ const response = await fetch(svgUrl);
8
+ if (!response.ok) {
9
+ console.error(`Failed to fetch SVG: ${response.status} ${response.statusText}`);
10
+ return null;
11
+ }
12
+ const svgContent = await response.text();
13
+ return svgContent;
14
+ }
15
+ catch (error) {
16
+ console.error("Error fetching SVG:", error);
17
+ return null;
18
+ }
19
+ }
20
+ /**
21
+ * Server-side helper for Astro components to fetch SVG content during SSR
22
+ *
23
+ * @param mediaObject The media object from the CMS
24
+ * @returns The SVG content as a string, or empty string on failure
25
+ */
26
+ export async function getSvgContentForAstro(mediaObject) {
27
+ try {
28
+ const svgContent = await fetchSvgContent(mediaObject);
29
+ return svgContent || "";
30
+ }
31
+ catch (error) {
32
+ console.error("Error getting SVG content for Astro:", error);
33
+ return "";
34
+ }
35
+ }
36
+ /**
37
+ * Client-side helper to fetch and inject SVG content into DOM elements
38
+ *
39
+ * @param mediaObject The media object from the CMS
40
+ * @param targetElement The DOM element to inject the SVG into
41
+ * @param className Optional CSS class to add to the SVG
42
+ */
43
+ export async function injectSvgIntoElement(mediaObject, targetElement, className) {
44
+ if (!targetElement)
45
+ return;
46
+ try {
47
+ const svgContent = await fetchSvgContent(mediaObject);
48
+ if (svgContent) {
49
+ targetElement.innerHTML = svgContent;
50
+ // Add class if provided
51
+ if (className) {
52
+ const svgElement = targetElement.querySelector("svg");
53
+ if (svgElement) {
54
+ svgElement.classList.add(...className.split(" "));
55
+ }
56
+ }
57
+ }
58
+ }
59
+ catch (error) {
60
+ console.error("Error injecting SVG:", error);
61
+ }
62
+ }