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
@@ -1,239 +0,0 @@
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
- };
package/dist/config.d.ts DELETED
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,20 +0,0 @@
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 = '';
@@ -1 +0,0 @@
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"}
@@ -1,17 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,62 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,73 +0,0 @@
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;
@@ -1,28 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,122 +0,0 @@
1
- // Unified Business Store - Single Source of Truth
2
- import { computed, deepMap } from "nanostores";
3
- import { BUSINESS_ID } from "../config";
4
- import * as authService from "../services/auth";
5
- import { getCurrencySymbol } from "../utils/currency";
6
- // Core business state
7
- export const businessStore = deepMap({
8
- data: null,
9
- loading: false,
10
- error: null,
11
- initialized: false,
12
- });
13
- // Computed values derived from business data
14
- export const selectedMarket = computed(businessStore, (state) => {
15
- if (!state.data?.configs?.markets)
16
- return null;
17
- const markets = state.data.configs.markets;
18
- // For arky website, always use 'us' market (hardcoded for headless)
19
- return markets.find(m => m.id === 'us') ||
20
- markets[0] ||
21
- null;
22
- });
23
- export const currency = computed(selectedMarket, (market) => {
24
- return market?.currency || 'USD';
25
- });
26
- export const currencySymbol = computed(selectedMarket, (market) => {
27
- return getCurrencySymbol(market?.currency || 'USD');
28
- });
29
- export const markets = computed(businessStore, (state) => {
30
- if (!state.data?.configs?.markets)
31
- return [];
32
- return state.data.configs.markets;
33
- });
34
- export const zones = computed(businessStore, (state) => {
35
- if (!state.data?.configs?.zones)
36
- return [];
37
- return state.data.configs.zones;
38
- });
39
- // Get zone by country code
40
- export const getZoneByCountry = (countryCode) => {
41
- const allZones = zones.get();
42
- return allZones.find(zone => zone.countries.length === 0 || // Empty = all countries
43
- zone.countries.includes(countryCode.toUpperCase())) || null;
44
- };
45
- // Get shipping methods for a specific country
46
- export const getShippingMethodsForCountry = (countryCode) => {
47
- const zone = getZoneByCountry(countryCode);
48
- return zone?.shippingMethods || [];
49
- };
50
- export const paymentMethods = computed(selectedMarket, (market) => {
51
- if (!market)
52
- return ['CASH'];
53
- const methods = market.paymentMethods || [];
54
- return methods.map((pm) => pm.method || pm);
55
- });
56
- export const paymentConfig = computed(businessStore, (state) => {
57
- if (!state.data?.configs)
58
- return { provider: null, enabled: false };
59
- const provider = state.data.configs.paymentProvider || null;
60
- const hasCreditCard = paymentMethods.get().includes('CREDIT_CARD');
61
- return {
62
- provider,
63
- enabled: hasCreditCard && !!provider
64
- };
65
- });
66
- export const orderBlocks = computed(businessStore, (state) => {
67
- return state.data?.configs?.orderBlocks || [];
68
- });
69
- export const reservationBlocks = computed(businessStore, (state) => {
70
- return state.data?.configs?.reservationBlocks || [];
71
- });
72
- // Actions
73
- export const businessActions = {
74
- // Initialize business data - SINGLE API CALL for entire app
75
- async init() {
76
- const state = businessStore.get();
77
- if (state.initialized && state.data) {
78
- // Already loaded, skip
79
- return;
80
- }
81
- try {
82
- businessStore.setKey('loading', true);
83
- businessStore.setKey('error', null);
84
- const result = await authService.getBusinessConfig(BUSINESS_ID);
85
- if (result.success) {
86
- businessStore.setKey('data', result.data);
87
- businessStore.setKey('initialized', true);
88
- }
89
- else {
90
- throw new Error(result.error || 'Failed to load business configuration');
91
- }
92
- }
93
- catch (error) {
94
- businessStore.setKey('error', error.message);
95
- console.error('Business store initialization failed:', error);
96
- }
97
- finally {
98
- businessStore.setKey('loading', false);
99
- }
100
- },
101
- // Reset store (useful for testing)
102
- reset() {
103
- businessStore.setKey('data', null);
104
- businessStore.setKey('loading', false);
105
- businessStore.setKey('error', null);
106
- businessStore.setKey('initialized', false);
107
- },
108
- // Get business data (with auto-init)
109
- async getBusiness() {
110
- const state = businessStore.get();
111
- if (!state.initialized || !state.data) {
112
- await this.init();
113
- }
114
- return businessStore.get().data;
115
- }
116
- };
117
- // Export everything for easy access
118
- export { businessStore as store, businessActions as actions };
119
- // Auto-initialize on first import (ensures data is always available)
120
- if (typeof window !== 'undefined') {
121
- businessActions.init().catch(console.error);
122
- }
@@ -1,8 +0,0 @@
1
- export declare const totalCartItems: import("nanostores").ReadableAtom<number>;
2
- export declare const hasEshopItems: import("nanostores").ReadableAtom<boolean>;
3
- export declare const hasReservationItems: import("nanostores").ReadableAtom<boolean>;
4
- export declare const isCartEmpty: import("nanostores").ReadableAtom<boolean>;
5
- export declare const showEshopSection: import("nanostores").ReadableAtom<boolean>;
6
- export declare const showReservationSection: import("nanostores").ReadableAtom<boolean>;
7
- export declare const showBothSections: import("nanostores").ReadableAtom<boolean>;
8
- //# sourceMappingURL=cart.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../../src/stores/cart.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,2CAIzB,CAAC;AAGH,eAAO,MAAM,aAAa,4CAAqD,CAAC;AAChF,eAAO,MAAM,mBAAmB,4CAA2D,CAAC;AAC5F,eAAO,MAAM,WAAW,4CAEtB,CAAC;AAGH,eAAO,MAAM,gBAAgB,4CAAqF,CAAC;AACnH,eAAO,MAAM,sBAAsB,4CAAuG,CAAC;AAC3I,eAAO,MAAM,gBAAgB,4CAA2G,CAAC"}
@@ -1,20 +0,0 @@
1
- // Unified cart store that manages both e-shop and reservation carts
2
- import { computed } from "nanostores";
3
- import { cartItems as eshopItems } from "./eshop";
4
- import { cartParts as reservationItems } from "./reservation";
5
- // Combined cart count
6
- export const totalCartItems = computed([eshopItems, reservationItems], (eshop, reservation) => {
7
- const eshopCount = eshop?.reduce((sum, item) => sum + item.quantity, 0) || 0;
8
- const reservationCount = reservation?.length || 0;
9
- return eshopCount + reservationCount;
10
- });
11
- // Cart state helpers
12
- export const hasEshopItems = computed(eshopItems, (items) => items?.length > 0);
13
- export const hasReservationItems = computed(reservationItems, (items) => items?.length > 0);
14
- export const isCartEmpty = computed([eshopItems, reservationItems], (eshop, reservation) => {
15
- return (!eshop || eshop.length === 0) && (!reservation || reservation.length === 0);
16
- });
17
- // Cart section visibility logic
18
- export const showEshopSection = computed([hasEshopItems, isCartEmpty], (hasEshop, isEmpty) => hasEshop || isEmpty);
19
- export const showReservationSection = computed([hasReservationItems, isCartEmpty], (hasReservation, isEmpty) => hasReservation || isEmpty);
20
- export const showBothSections = computed([hasEshopItems, hasReservationItems], (hasEshop, hasReservation) => hasEshop && hasReservation);