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,239 @@
1
+ import { API_URL } from '../config';
2
+ import httpClient from '../services/http';
3
+ export const reservationApi = {
4
+ // Get quote for reservation parts
5
+ async getQuote({ token, businessId, market, currency, userId, parts, paymentMethod = 'CASH', promoCode, }) {
6
+ try {
7
+ const lines = parts.map(part => ({
8
+ type: 'SERVICE',
9
+ serviceId: part.serviceId,
10
+ quantity: 1,
11
+ }));
12
+ const payload = {
13
+ businessId,
14
+ market,
15
+ currency,
16
+ userId,
17
+ paymentMethod,
18
+ lines,
19
+ promoCode: promoCode || undefined,
20
+ shippingMethodId: null,
21
+ };
22
+ const res = await fetch(`${API_URL}/v1/payments/quote`, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ 'Authorization': `Bearer ${token}`,
27
+ },
28
+ body: JSON.stringify(payload),
29
+ });
30
+ const text = await res.text();
31
+ if (!res.ok) {
32
+ try {
33
+ const json = JSON.parse(text);
34
+ return { success: false, error: json.reason || json.error || 'Failed to fetch quote', code: json.code };
35
+ }
36
+ catch {
37
+ return { success: false, error: text || 'Failed to fetch quote' };
38
+ }
39
+ }
40
+ const quote = text ? JSON.parse(text) : null;
41
+ return { success: true, data: quote };
42
+ }
43
+ catch (e) {
44
+ return {
45
+ success: false,
46
+ error: e.message || 'Failed to fetch quote',
47
+ };
48
+ }
49
+ },
50
+ // Get available slots for a service
51
+ async getAvailableSlots({ businessId, serviceId, from, to, limit = 1000, providerId = null, }) {
52
+ const url = `${API_URL}/v1/businesses/${businessId}/services/${serviceId}/available-slots`;
53
+ const response = await httpClient.get(url, {
54
+ params: {
55
+ from,
56
+ to,
57
+ limit,
58
+ providerId
59
+ }
60
+ });
61
+ if (response.success) {
62
+ const json = response.value;
63
+ return {
64
+ success: true,
65
+ data: json.data?.items || json.items || [],
66
+ };
67
+ }
68
+ else {
69
+ console.error("Error fetching available slots:", response.error);
70
+ return {
71
+ success: false,
72
+ error: response.error,
73
+ data: [],
74
+ };
75
+ }
76
+ },
77
+ // Get all providers for a service
78
+ async getProviders({ businessId, serviceId, limit = 50 }) {
79
+ const url = `${API_URL}/v1/businesses/${businessId}/providers`;
80
+ const response = await httpClient.get(url, {
81
+ params: {
82
+ serviceId,
83
+ limit
84
+ }
85
+ });
86
+ if (response.success) {
87
+ const json = response.value;
88
+ return {
89
+ success: true,
90
+ data: json.items || [],
91
+ };
92
+ }
93
+ else {
94
+ console.error("Error loading providers:", response.error);
95
+ return {
96
+ success: false,
97
+ error: response.error,
98
+ data: [],
99
+ };
100
+ }
101
+ },
102
+ // Get guest token or create a new one
103
+ async getGuestToken() {
104
+ try {
105
+ const res = await fetch(`${API_URL}/v1/users/login`, {
106
+ method: "POST",
107
+ headers: { "Content-Type": "application/json" },
108
+ body: JSON.stringify({ provider: "GUEST" }),
109
+ });
110
+ if (!res.ok)
111
+ throw new Error("Guest login failed");
112
+ const json = await res.json();
113
+ return {
114
+ success: true,
115
+ data: { token: json.accessToken },
116
+ };
117
+ }
118
+ catch (e) {
119
+ return {
120
+ success: false,
121
+ error: e.message,
122
+ };
123
+ }
124
+ },
125
+ // Update user's phone number
126
+ async updateProfilePhone({ token, phoneNumber }) {
127
+ try {
128
+ const res = await fetch(`${API_URL}/v1/users/update`, {
129
+ method: "PUT",
130
+ headers: {
131
+ "Content-Type": "application/json",
132
+ Authorization: `Bearer ${token}`,
133
+ },
134
+ body: JSON.stringify({
135
+ phoneNumber,
136
+ phoneNumbers: [],
137
+ addresses: [],
138
+ }),
139
+ });
140
+ if (!res.ok) {
141
+ const error = (await res.text()) || res.statusText;
142
+ return {
143
+ success: false,
144
+ error,
145
+ };
146
+ }
147
+ return {
148
+ success: true,
149
+ };
150
+ }
151
+ catch (e) {
152
+ return {
153
+ success: false,
154
+ error: e.message,
155
+ };
156
+ }
157
+ },
158
+ // Verify phone number with code
159
+ async verifyPhoneCode({ token, phoneNumber, code }) {
160
+ try {
161
+ const res = await fetch(`${API_URL}/v1/users/confirm/phone-number`, {
162
+ method: "PUT",
163
+ headers: {
164
+ "Content-Type": "application/json",
165
+ Authorization: `Bearer ${token}`,
166
+ },
167
+ body: JSON.stringify({
168
+ phoneNumber,
169
+ code,
170
+ }),
171
+ });
172
+ if (!res.ok) {
173
+ const error = (await res.text()) || res.statusText;
174
+ return {
175
+ success: false,
176
+ error,
177
+ };
178
+ }
179
+ return {
180
+ success: true,
181
+ };
182
+ }
183
+ catch (e) {
184
+ return {
185
+ success: false,
186
+ error: e.message,
187
+ };
188
+ }
189
+ },
190
+ // Complete reservation checkout - Backend calculates currency from market
191
+ async checkout({ token, businessId, parts, paymentMethod = "CASH", blocks = [], market = "US", promoCode }) {
192
+ try {
193
+ const payload = {
194
+ businessId,
195
+ blocks: blocks,
196
+ market,
197
+ parts: parts.map((p) => ({
198
+ serviceId: p.serviceId,
199
+ from: p.from,
200
+ to: p.to,
201
+ blocks: p.blocks,
202
+ reservationMethod: p.reservationMethod,
203
+ providerId: p.providerId,
204
+ })),
205
+ };
206
+ // Only add payment method if it's defined (not for inquiry-only reservations)
207
+ if (paymentMethod !== undefined) {
208
+ payload.paymentMethod = paymentMethod;
209
+ }
210
+ // Add promo code if provided
211
+ if (promoCode) {
212
+ payload.promoCode = promoCode;
213
+ }
214
+ const res = await fetch(`${API_URL}/v1/reservations/checkout`, {
215
+ method: "POST",
216
+ headers: {
217
+ "Content-Type": "application/json",
218
+ Authorization: `Bearer ${token}`,
219
+ },
220
+ body: JSON.stringify(payload),
221
+ });
222
+ if (!res.ok) {
223
+ const error = (await res.text()) || res.statusText;
224
+ throw new Error(error);
225
+ }
226
+ const json = await res.json();
227
+ return {
228
+ success: true,
229
+ data: json, // Should include reservationId and clientSecret for payments
230
+ };
231
+ }
232
+ catch (e) {
233
+ return {
234
+ success: false,
235
+ error: e.message,
236
+ };
237
+ }
238
+ },
239
+ };
@@ -0,0 +1,15 @@
1
+ export interface ArkyConfig {
2
+ apiUrl: string;
3
+ businessId: string;
4
+ storageUrl?: string;
5
+ auth?: {
6
+ type: 'guest' | 'api-token';
7
+ apiToken?: string;
8
+ };
9
+ }
10
+ export declare function setGlobalConfig(config: ArkyConfig): void;
11
+ export declare function getGlobalConfig(): ArkyConfig;
12
+ export declare let API_URL: string;
13
+ export declare let BUSINESS_ID: string;
14
+ export declare let STORAGE_URL: string;
15
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE;QACH,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC;QAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACL;AAKD,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAMxD;AAED,wBAAgB,eAAe,IAAI,UAAU,CAO5C;AAGD,eAAO,IAAI,OAAO,QAAK,CAAC;AACxB,eAAO,IAAI,WAAW,QAAK,CAAC;AAC5B,eAAO,IAAI,WAAW,QAAK,CAAC"}
package/dist/config.js ADDED
@@ -0,0 +1,20 @@
1
+ // SDK Configuration Types and Global State
2
+ // Global configuration (set by initArky or ArkyClient)
3
+ let globalConfig = null;
4
+ export function setGlobalConfig(config) {
5
+ globalConfig = config;
6
+ // Update module-level exports
7
+ API_URL = config.apiUrl;
8
+ BUSINESS_ID = config.businessId;
9
+ STORAGE_URL = config.storageUrl || '';
10
+ }
11
+ export function getGlobalConfig() {
12
+ if (!globalConfig) {
13
+ throw new Error('Arky SDK not initialized. Call initArky() or create an ArkyClient instance.');
14
+ }
15
+ return globalConfig;
16
+ }
17
+ // Module-level exports (mutable, updated by setGlobalConfig)
18
+ export let API_URL = '';
19
+ export let BUSINESS_ID = '';
20
+ export let STORAGE_URL = '';
@@ -0,0 +1,26 @@
1
+ export * from './config';
2
+ export type { ArkyConfig } from './config';
3
+ export * from './types';
4
+ export type { ApiResponse, EshopCartItem, EshopStoreState, ReservationStoreState, ReservationCartPart, Business, Block, Price } from './types';
5
+ export * from './api';
6
+ export * from './services/auth';
7
+ export { default as httpClient } from './services/http';
8
+ export * from './utils/blocks';
9
+ export * from './utils/errors';
10
+ export * from './utils/price';
11
+ export * from './utils/svg';
12
+ export * from './utils/text';
13
+ export * from './utils/timezone';
14
+ export * from './utils/validation';
15
+ export { validatePhoneNumber, validateEmail, validateVerificationCode, validateRequired } from './utils/validation';
16
+ export { getBlockLabel, getBlockTextValue, getBlockValue, getBlockValues, getImageUrl, thumbnailUrl } from './utils/blocks';
17
+ export { getGuestToken, updateProfilePhone, verifyPhoneCode, getBusinessConfig } from './services/auth';
18
+ export { fetchSvgContent, getSvgContentForAstro, injectSvgIntoElement } from './utils/svg';
19
+ export { slugify, humanize, categorify, formatDate } from './utils/text';
20
+ export { findTimeZone, tzGroups } from './utils/timezone';
21
+ export { getErrorMessage, isErrorCode, ERROR_CODES, ERROR_CONSTANTS } from './utils/errors';
22
+ export declare const SDK_VERSION = "0.1.0";
23
+ export declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
24
+ import { type ArkyConfig } from './config';
25
+ export declare function initArky(config: ArkyConfig): ArkyConfig;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,cAAc,SAAS,CAAC;AACxB,YAAY,EACR,WAAW,EACX,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,QAAQ,EACR,KAAK,EACL,KAAK,EACR,MAAM,SAAS,CAAC;AAGjB,cAAc,OAAO,CAAC;AAGtB,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAMxD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAInC,OAAO,EAEH,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,gBAAgB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEH,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAEH,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEH,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAEH,OAAO,EACP,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEH,YAAY,EACZ,QAAQ,EACX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEH,eAAe,EACf,WAAW,EACX,WAAW,EACX,eAAe,EAClB,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,oBAAoB,yDAA0D,CAAC;AAG5F,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5D,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAUvD"}
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ // Main export file for @arky/sdk
2
+ // Configuration
3
+ export * from './config';
4
+ // Types
5
+ export * from './types';
6
+ // APIs
7
+ export * from './api';
8
+ // Services
9
+ export * from './services/auth';
10
+ export { default as httpClient } from './services/http';
11
+ // NOTE: Stores are exported via separate entry point: @arky/sdk/stores
12
+ // This keeps the main bundle small for API-only users
13
+ // Utilities
14
+ export * from './utils/blocks';
15
+ export * from './utils/errors';
16
+ export * from './utils/price';
17
+ export * from './utils/svg';
18
+ export * from './utils/text';
19
+ export * from './utils/timezone';
20
+ export * from './utils/validation';
21
+ // Re-export commonly used functions for convenience
22
+ export {
23
+ // Validation utilities
24
+ validatePhoneNumber, validateEmail, validateVerificationCode, validateRequired } from './utils/validation';
25
+ export {
26
+ // Block utilities
27
+ getBlockLabel, getBlockTextValue, getBlockValue, getBlockValues, getImageUrl, thumbnailUrl } from './utils/blocks';
28
+ export {
29
+ // Auth utilities
30
+ getGuestToken, updateProfilePhone, verifyPhoneCode, getBusinessConfig } from './services/auth';
31
+ export {
32
+ // SVG utilities
33
+ fetchSvgContent, getSvgContentForAstro, injectSvgIntoElement } from './utils/svg';
34
+ export {
35
+ // Text utilities
36
+ slugify, humanize, categorify, formatDate } from './utils/text';
37
+ export {
38
+ // Timezone utilities
39
+ findTimeZone, tzGroups } from './utils/timezone';
40
+ export {
41
+ // Error utilities
42
+ getErrorMessage, isErrorCode, ERROR_CODES, ERROR_CONSTANTS } from './utils/errors';
43
+ // SDK Version
44
+ export const SDK_VERSION = '0.1.0';
45
+ export const SUPPORTED_FRAMEWORKS = ['astro', 'react', 'vue', 'svelte', 'vanilla'];
46
+ // SDK initialization function
47
+ import { setGlobalConfig } from './config';
48
+ export function initArky(config) {
49
+ if (!config.apiUrl) {
50
+ throw new Error('apiUrl is required');
51
+ }
52
+ if (!config.businessId) {
53
+ throw new Error('businessId is required');
54
+ }
55
+ setGlobalConfig(config);
56
+ return config;
57
+ }
@@ -0,0 +1,17 @@
1
+ export declare function getGuestToken(currentToken?: string | null): Promise<string>;
2
+ export declare function updateProfilePhone(token: string, phoneNumber: string): Promise<{
3
+ success: boolean;
4
+ }>;
5
+ export declare function verifyPhoneCode(token: string, phoneNumber: string, code: string): Promise<{
6
+ success: boolean;
7
+ }>;
8
+ export declare function getBusinessConfig(businessId: string): Promise<{
9
+ success: boolean;
10
+ data: any;
11
+ error?: undefined;
12
+ } | {
13
+ success: boolean;
14
+ error: any;
15
+ data?: undefined;
16
+ }>;
17
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAIA,wBAAsB,aAAa,CAAC,YAAY,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAQvF;AAGD,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;;GAY1E;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;GAYrF;AAGD,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;;;;;GAwBzD"}
@@ -0,0 +1,62 @@
1
+ import { reservationApi } from "../api/reservation";
2
+ import { API_URL } from "../config";
3
+ // Shared guest token management
4
+ export async function getGuestToken(currentToken = null) {
5
+ if (currentToken)
6
+ return currentToken;
7
+ const response = await reservationApi.getGuestToken();
8
+ if (response.success && response.data) {
9
+ return response.data.token;
10
+ }
11
+ throw new Error("Failed to get guest token");
12
+ }
13
+ // Shared phone verification
14
+ export async function updateProfilePhone(token, phoneNumber) {
15
+ if (!phoneNumber) {
16
+ throw new Error("Phone number is required");
17
+ }
18
+ const response = await reservationApi.updateProfilePhone({ token, phoneNumber });
19
+ if (response.success) {
20
+ return { success: true };
21
+ }
22
+ else {
23
+ throw new Error(response.error || "Failed to send verification code");
24
+ }
25
+ }
26
+ export async function verifyPhoneCode(token, phoneNumber, code) {
27
+ if (!code) {
28
+ throw new Error("Verification code is required");
29
+ }
30
+ const response = await reservationApi.verifyPhoneCode({ token, phoneNumber, code });
31
+ if (response.success) {
32
+ return { success: true };
33
+ }
34
+ else {
35
+ throw new Error(response.error || "Invalid verification code");
36
+ }
37
+ }
38
+ // Shared business configuration fetching
39
+ export async function getBusinessConfig(businessId) {
40
+ try {
41
+ const response = await fetch(`${API_URL}/v1/businesses/${businessId}`, {
42
+ method: "GET",
43
+ headers: {
44
+ "Content-Type": "application/json",
45
+ },
46
+ });
47
+ if (!response.ok) {
48
+ throw new Error(`Failed to fetch business config: ${response.status}`);
49
+ }
50
+ const business = await response.json();
51
+ return {
52
+ success: true,
53
+ data: business,
54
+ };
55
+ }
56
+ catch (error) {
57
+ return {
58
+ success: false,
59
+ error: error.message,
60
+ };
61
+ }
62
+ }
@@ -0,0 +1,20 @@
1
+ import type { QueryParams } from '../utils/queryParams';
2
+ interface HttpOptions {
3
+ successMessage?: string;
4
+ errorMessage?: string;
5
+ schema?: any;
6
+ params?: QueryParams;
7
+ }
8
+ export interface HttpResponse<T = any> {
9
+ value: T;
10
+ success: boolean;
11
+ error?: string;
12
+ }
13
+ declare function get<T = any>(url: string, options?: HttpOptions): Promise<HttpResponse<T>>;
14
+ declare function post<T = any>(url: string, data: any, options?: HttpOptions): Promise<HttpResponse<T>>;
15
+ declare const httpClient: {
16
+ get: typeof get;
17
+ post: typeof post;
18
+ };
19
+ export default httpClient;
20
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/services/http.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,UAAU,WAAW;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,GAAG;IACjC,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,iBAAe,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAmCxF;AAED,iBAAe,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAuCpG;AAED,QAAA,MAAM,UAAU;;;CAGf,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,73 @@
1
+ // Toast notifications should be handled by UI layer
2
+ import { appendQueryString } from '../utils/queryParams';
3
+ async function get(url, options) {
4
+ try {
5
+ // Append query parameters if provided
6
+ const finalUrl = options?.params ? appendQueryString(url, options.params) : url;
7
+ const response = await fetch(finalUrl);
8
+ if (!response.ok) {
9
+ throw new Error(`HTTP error! status: ${response.status}`);
10
+ }
11
+ const data = await response.json();
12
+ // Success message should be handled by UI layer
13
+ // if (options?.successMessage) {
14
+ // showToast(options.successMessage, 'success');
15
+ // }
16
+ return {
17
+ value: data,
18
+ success: true
19
+ };
20
+ }
21
+ catch (error) {
22
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error occurred';
23
+ // Error message should be handled by UI layer
24
+ // if (options?.errorMessage) {
25
+ // showToast(options.errorMessage, 'error');
26
+ // }
27
+ return {
28
+ value: null,
29
+ success: false,
30
+ error: errorMsg
31
+ };
32
+ }
33
+ }
34
+ async function post(url, data, options) {
35
+ try {
36
+ const response = await fetch(url, {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ },
41
+ body: JSON.stringify(data)
42
+ });
43
+ if (!response.ok) {
44
+ throw new Error(`HTTP error! status: ${response.status}`);
45
+ }
46
+ const responseData = await response.json();
47
+ // Success message should be handled by UI layer
48
+ // if (options?.successMessage) {
49
+ // showToast(options.successMessage, 'success');
50
+ // }
51
+ return {
52
+ value: responseData,
53
+ success: true
54
+ };
55
+ }
56
+ catch (error) {
57
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error occurred';
58
+ // Error message should be handled by UI layer
59
+ // if (options?.errorMessage) {
60
+ // showToast(options.errorMessage, 'error');
61
+ // }
62
+ return {
63
+ value: null,
64
+ success: false,
65
+ error: errorMsg
66
+ };
67
+ }
68
+ }
69
+ const httpClient = {
70
+ get,
71
+ post
72
+ };
73
+ export default httpClient;
@@ -0,0 +1,28 @@
1
+ import type { Business, Market, Zone, ShippingMethod, PaymentProviderConfig } from "../types";
2
+ export declare const businessStore: import("nanostores").DeepMapStore<{
3
+ data: Business | null;
4
+ loading: boolean;
5
+ error: string | null;
6
+ initialized: boolean;
7
+ }>;
8
+ export declare const selectedMarket: import("nanostores").ReadableAtom<Market>;
9
+ export declare const currency: import("nanostores").ReadableAtom<string>;
10
+ export declare const currencySymbol: import("nanostores").ReadableAtom<string>;
11
+ export declare const markets: import("nanostores").ReadableAtom<Market[]>;
12
+ export declare const zones: import("nanostores").ReadableAtom<Zone[]>;
13
+ export declare const getZoneByCountry: (countryCode: string) => Zone | null;
14
+ export declare const getShippingMethodsForCountry: (countryCode: string) => ShippingMethod[];
15
+ export declare const paymentMethods: import("nanostores").ReadableAtom<any[]>;
16
+ export declare const paymentConfig: import("nanostores").ReadableAtom<{
17
+ provider: PaymentProviderConfig;
18
+ enabled: boolean;
19
+ }>;
20
+ export declare const orderBlocks: import("nanostores").ReadableAtom<any[]>;
21
+ export declare const reservationBlocks: import("nanostores").ReadableAtom<any[]>;
22
+ export declare const businessActions: {
23
+ init(): Promise<void>;
24
+ reset(): void;
25
+ getBusiness(): Promise<Business | null>;
26
+ };
27
+ export { businessStore as store, businessActions as actions };
28
+ //# sourceMappingURL=business.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"business.d.ts","sourceRoot":"","sources":["../../src/stores/business.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAyB,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAKrH,eAAO,MAAM,aAAa;UACR,QAAQ,GAAG,IAAI;;WAEd,MAAM,GAAG,IAAI;;EAE9B,CAAC;AAGH,eAAO,MAAM,cAAc,2CAQzB,CAAC;AAEH,eAAO,MAAM,QAAQ,2CAEnB,CAAC;AAEH,eAAO,MAAM,cAAc,2CAEzB,CAAC;AAEH,eAAO,MAAM,OAAO,6CAGlB,CAAC;AAEH,eAAO,MAAM,KAAK,2CAGhB,CAAC;AAGH,eAAO,MAAM,gBAAgB,GAAI,aAAa,MAAM,KAAG,IAAI,GAAG,IAM7D,CAAC;AAGF,eAAO,MAAM,4BAA4B,GAAI,aAAa,MAAM,KAAG,cAAc,EAGhF,CAAC;AAEF,eAAO,MAAM,cAAc,0CAIzB,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAUxB,CAAC;AAEH,eAAO,MAAM,WAAW,0CAEtB,CAAC;AAEH,eAAO,MAAM,iBAAiB,0CAE5B,CAAC;AAGH,eAAO,MAAM,eAAe;YAEV,OAAO,CAAC,IAAI,CAAC;aA4BlB,IAAI;mBAQQ,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAOhD,CAAC;AAGF,OAAO,EACH,aAAa,IAAI,KAAK,EACtB,eAAe,IAAI,OAAO,EAC7B,CAAC"}