@groundbrick/sveltekit-adapter 0.8.0 → 0.10.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 (70) hide show
  1. package/README.md +227 -502
  2. package/dist/analytics/components/FacebookPixel.svelte +8 -27
  3. package/dist/analytics/components/GoogleAnalytics.svelte +12 -16
  4. package/dist/analytics/config/analytics.config.js +1 -1
  5. package/dist/analytics/config/analytics.config.js.map +1 -1
  6. package/dist/analytics/interfaces/IAnalyticsService.d.ts +5 -6
  7. package/dist/analytics/interfaces/IAnalyticsService.d.ts.map +1 -1
  8. package/dist/analytics/services/AnalyticsService.d.ts +2 -4
  9. package/dist/analytics/services/AnalyticsService.d.ts.map +1 -1
  10. package/dist/analytics/services/AnalyticsService.js +10 -9
  11. package/dist/analytics/services/AnalyticsService.js.map +1 -1
  12. package/dist/analytics/utils/consent.js +3 -3
  13. package/dist/analytics/utils/consent.js.map +1 -1
  14. package/dist/auth/index.d.ts.map +1 -1
  15. package/dist/auth/index.js +1 -5
  16. package/dist/auth/index.js.map +1 -1
  17. package/dist/client/ApiClient.d.ts.map +1 -1
  18. package/dist/client/ApiClient.js +4 -10
  19. package/dist/client/ApiClient.js.map +1 -1
  20. package/dist/client/apiWrapper.d.ts +49 -41
  21. package/dist/client/apiWrapper.d.ts.map +1 -1
  22. package/dist/client/apiWrapper.js +35 -35
  23. package/dist/client/apiWrapper.js.map +1 -1
  24. package/dist/client/authErrorHandler.d.ts.map +1 -1
  25. package/dist/client/authErrorHandler.js +3 -7
  26. package/dist/client/authErrorHandler.js.map +1 -1
  27. package/dist/client/hooks.d.ts +2 -2
  28. package/dist/client/hooks.js +2 -2
  29. package/dist/client/index.d.ts +2 -1
  30. package/dist/client/index.d.ts.map +1 -1
  31. package/dist/client/index.js +3 -1
  32. package/dist/client/index.js.map +1 -1
  33. package/dist/client/jwtDecoder.d.ts +8 -8
  34. package/dist/client/jwtDecoder.d.ts.map +1 -1
  35. package/dist/client/jwtDecoder.js +12 -15
  36. package/dist/client/jwtDecoder.js.map +1 -1
  37. package/dist/client/stores.d.ts.map +1 -1
  38. package/dist/client/stores.js +7 -16
  39. package/dist/client/stores.js.map +1 -1
  40. package/dist/consent/components/CookieConsent.svelte +3 -4
  41. package/dist/consent/config/consent.config.js +13 -13
  42. package/dist/consent/config/consent.config.js.map +1 -1
  43. package/dist/consent/index.js +1 -1
  44. package/dist/consent/index.js.map +1 -1
  45. package/dist/consent/services/ConsentService.d.ts.map +1 -1
  46. package/dist/consent/services/ConsentService.js +5 -11
  47. package/dist/consent/services/ConsentService.js.map +1 -1
  48. package/dist/consent/utils/analytics.js +2 -2
  49. package/dist/consent/utils/analytics.js.map +1 -1
  50. package/dist/cookies/index.d.ts +10 -23
  51. package/dist/cookies/index.d.ts.map +1 -1
  52. package/dist/cookies/index.js +9 -22
  53. package/dist/cookies/index.js.map +1 -1
  54. package/dist/hooks/index.d.ts +1 -0
  55. package/dist/hooks/index.d.ts.map +1 -1
  56. package/dist/hooks/index.js +68 -65
  57. package/dist/hooks/index.js.map +1 -1
  58. package/dist/navigation/returnUrl.d.ts +17 -0
  59. package/dist/navigation/returnUrl.d.ts.map +1 -0
  60. package/dist/navigation/returnUrl.js +32 -0
  61. package/dist/navigation/returnUrl.js.map +1 -0
  62. package/dist/sentry/index.d.ts.map +1 -1
  63. package/dist/sentry/index.js +1 -1
  64. package/dist/sentry/index.js.map +1 -1
  65. package/dist/tracking/services/TrackingService.d.ts.map +1 -1
  66. package/dist/tracking/services/TrackingService.js +6 -7
  67. package/dist/tracking/services/TrackingService.js.map +1 -1
  68. package/dist/types/index.d.ts +19 -10
  69. package/dist/types/index.d.ts.map +1 -1
  70. package/package.json +5 -3
@@ -17,9 +17,7 @@ export interface ApiErrorResponse {
17
17
  code?: string;
18
18
  status?: number;
19
19
  /**
20
- * Structured payload the server attached to the error (BusinessError context).
21
- * Carries what the UI needs to act on a code — an id to restore, a list of
22
- * conflicts — instead of forcing it to parse the message.
20
+ * Structured payload the server attached to the error.
23
21
  */
24
22
  details?: Record<string, unknown>;
25
23
  };
@@ -47,7 +45,7 @@ export type ApiResponse<T = unknown> = ApiSuccessResponse<T> | ApiErrorResponse;
47
45
  * showErrorNotification: false
48
46
  * });
49
47
  *
50
- * // Login endpoint (skip auth error handling to prevent redirect loops)
48
+ * // Login endpoint (skip auth error handling)
51
49
  * await apiWrapper.post('/api/auth/login', credentials, {
52
50
  * skipAuthHandling: true,
53
51
  * customErrorMessage: 'Invalid credentials. Please try again.'
@@ -59,11 +57,8 @@ export interface ApiWrapperOptions {
59
57
  * Controls whether to show loading state in the apiStore
60
58
  *
61
59
  * When true (default), the apiStore loading state will be set to true
62
- * during the API call and false when completed. This is useful for
63
- * showing loading spinners or disabling UI elements.
64
- *
65
- * Set to false for background operations or when you want to handle
66
- * loading states manually.
60
+ * during the API call and false when completed. When false, the store
61
+ * is left untouched.
67
62
  *
68
63
  * @default true
69
64
  *
@@ -81,8 +76,8 @@ export interface ApiWrapperOptions {
81
76
  * Controls whether to automatically show error notifications
82
77
  *
83
78
  * When true (default), errors will be displayed to the user via
84
- * the notification system (toast messages). Set to false when you
85
- * want to handle errors manually or for silent operations.
79
+ * the notification system (toast messages). When false, no
80
+ * notification is shown.
86
81
  *
87
82
  * @default true
88
83
  *
@@ -92,11 +87,9 @@ export interface ApiWrapperOptions {
92
87
  * await apiWrapper.get('/api/users', { showErrorNotification: true });
93
88
  *
94
89
  * // Handle errors manually
95
- * try {
96
- * await apiWrapper.get('/api/data', { showErrorNotification: false });
97
- * } catch (error) {
98
- * // Custom error handling
99
- * console.log('Custom error handling:', error);
90
+ * const result = await apiWrapper.get('/api/data', { showErrorNotification: false });
91
+ * if (!result.success) {
92
+ * console.log('Custom error handling:', result.error);
100
93
  * }
101
94
  * ```
102
95
  */
@@ -104,9 +97,8 @@ export interface ApiWrapperOptions {
104
97
  /**
105
98
  * Custom error message to display instead of the server-provided error
106
99
  *
107
- * When provided, this message will be shown to the user instead of
108
- * the error message from the server. Useful for providing user-friendly
109
- * error messages or localization.
100
+ * When provided, this message is shown in the notification. The returned
101
+ * error and the apiStore keep the server message.
110
102
  *
111
103
  * @example
112
104
  * ```typescript
@@ -116,35 +108,34 @@ export interface ApiWrapperOptions {
116
108
  * });
117
109
  *
118
110
  * // Localized error message
119
- * await apiWrapper.post('/api/appointments', data, {
120
- * customErrorMessage: 'Não foi possível criar o agendamento.'
111
+ * await apiWrapper.post('/api/orders', data, {
112
+ * customErrorMessage: 'Não foi possível criar a encomenda.'
121
113
  * });
122
114
  * ```
123
115
  */
124
116
  customErrorMessage?: string;
125
117
  /**
126
- * Códigos que este pedido considera resposta e não falha (ex.: `[404]` num
127
- * recurso que ainda pode não existir). O resultado chega na mesma como erro
128
- * a quem chamou; deixa é de ser registado como aviso no cliente.
118
+ * Códigos HTTP (ex.: `[404]`) que não são registados como aviso no cliente.
119
+ * O resultado chega na mesma como erro a quem chamou. Aplica-se a `get`.
129
120
  */
130
121
  expectedStatuses?: number[];
131
122
  /**
132
123
  * Skip authentication error handling for login/logout endpoints
133
124
  *
134
125
  * When true, a 401 will not trigger automatic authentication
135
- * error handling (like redirecting to login page). This is essential
136
- * for login/logout endpoints to prevent redirect loops.
126
+ * error handling (like redirecting to login page). The same applies to
127
+ * a 403 that is handled like an invalid session.
137
128
  *
138
129
  * @default false
139
130
  *
140
131
  * @example
141
132
  * ```typescript
142
- * // Login endpoint - prevent redirect loops
133
+ * // Login endpoint
143
134
  * await apiWrapper.post('/api/auth/login', credentials, {
144
135
  * skipAuthHandling: true
145
136
  * });
146
137
  *
147
- * // Logout endpoint - prevent redirect loops
138
+ * // Logout endpoint
148
139
  * await apiWrapper.post('/api/auth/logout', {}, {
149
140
  * skipAuthHandling: true
150
141
  * });
@@ -155,6 +146,18 @@ export interface ApiWrapperOptions {
155
146
  */
156
147
  skipAuthHandling?: boolean;
157
148
  }
149
+ /**
150
+ * Configuration of an ApiWrapper instance
151
+ */
152
+ export interface ApiWrapperConfig {
153
+ /**
154
+ * Error codes that make a 403 be handled like an invalid session (logout and
155
+ * redirect). A 403 with any other code keeps the session.
156
+ *
157
+ * @default []
158
+ */
159
+ sessionInvalidCodes?: string[];
160
+ }
158
161
  /**
159
162
  * Wraps API client calls with common error handling, loading states, and notifications
160
163
  *
@@ -166,20 +169,22 @@ export interface ApiWrapperOptions {
166
169
  */
167
170
  export declare class ApiWrapper {
168
171
  private apiClient;
172
+ private config;
169
173
  /**
170
174
  * Creates a new ApiWrapper instance
171
175
  *
172
176
  * @param apiClient - The underlying API client instance (e.g., axios, fetch wrapper)
173
177
  * Should provide methods: get, post, put, patch, delete
178
+ * @param config - Configuration of the instance
174
179
  */
175
- constructor(apiClient: any);
180
+ constructor(apiClient: any, config?: ApiWrapperConfig);
176
181
  private isClientReady;
177
182
  /**
178
183
  * Wraps a single API call with comprehensive error handling and loading state management
179
184
  *
180
185
  * This is the core method that provides:
181
186
  * - Automatic loading state management via apiStore
182
- * - Authentication error handling (401 redirects; a 403 only notifies)
187
+ * - Authentication error handling (401 and session-invalid 403 codes log out and redirect; any other 403 only notifies)
183
188
  * - Error notifications via toast system
184
189
  * - Error state management in the store
185
190
  *
@@ -191,7 +196,7 @@ export declare class ApiWrapper {
191
196
  * @param options.customErrorMessage - Custom error message to display instead of server error
192
197
  * @param options.skipAuthHandling - Skip the 401 logout/redirect for login/logout endpoints (default: false)
193
198
  *
194
- * @returns Promise that resolves to the API response or void on error
199
+ * @returns Promise that resolves to the API response, or to an error response (`success: false`) on failure
195
200
  *
196
201
  * @example
197
202
  * ```typescript
@@ -201,6 +206,7 @@ export declare class ApiWrapper {
201
206
  * );
202
207
  * ```
203
208
  */
209
+ private isSessionInvalidForbidden;
204
210
  /** As opções do wrapper que o cliente HTTP também precisa de conhecer. */
205
211
  private requestOptions;
206
212
  call<T>(apiCall: () => Promise<T>, options?: ApiWrapperOptions): Promise<ApiResponse<T>>;
@@ -292,29 +298,31 @@ export declare class ApiWrapper {
292
298
  /**
293
299
  * Executes multiple API calls in parallel with shared error handling and loading state
294
300
  *
295
- * All API calls will be executed simultaneously using Promise.all(), providing better
296
- * performance than sequential calls. If any call fails, the entire operation fails
297
- * and error handling is applied to the first error encountered.
301
+ * All API calls will be executed simultaneously using Promise.all(). If any call
302
+ * rejects or resolves to `success: false`, error handling is applied to it and
303
+ * an error response is returned.
298
304
  *
299
305
  * @template T - Tuple type representing the return types of all API calls
300
306
  * @param apiCalls - Array of functions that return API call promises
301
307
  * @param options - Optional configuration for error handling and loading state
302
- * @returns Promise resolving to an array of all API call results
308
+ * @returns Promise resolving to a response whose `data` holds the results, in order
303
309
  *
304
310
  * @example
305
311
  * ```typescript
306
- * const [users, posts, comments] = await apiWrapper.parallel([
312
+ * const response = await apiWrapper.parallel<[ApiResponse<User[]>, ApiResponse<Post[]>]>([
307
313
  * () => apiClient.get('/api/users'),
308
- * () => apiClient.get('/api/posts'),
309
- * () => apiClient.get('/api/comments')
314
+ * () => apiClient.get('/api/posts')
310
315
  * ]);
316
+ * if (response.success) {
317
+ * const [users, posts] = response.data!;
318
+ * }
311
319
  * ```
312
320
  *
313
321
  * @example
314
322
  * ```typescript
315
323
  * // With error handling options
316
324
  * const results = await apiWrapper.parallel(
317
- * [() => fetch('/api/data1'), () => fetch('/api/data2')],
325
+ * [() => apiClient.get('/api/data1'), () => apiClient.get('/api/data2')],
318
326
  * { customErrorMessage: 'Failed to load dashboard data' }
319
327
  * );
320
328
  * ```
@@ -324,12 +332,12 @@ export declare class ApiWrapper {
324
332
  /**
325
333
  * Factory function to create an ApiWrapper instance
326
334
  *
327
- * Provides a convenient way to create an ApiWrapper with the specified API client.
328
335
  * The API client should implement standard HTTP methods (get, post, put, patch, delete)
329
336
  * that return promises.
330
337
  *
331
338
  * @param apiClient - The underlying API client instance (e.g., axios instance, custom fetch wrapper)
332
339
  * Must provide methods: get, post, put, patch, delete
340
+ * @param config - Configuration of the instance
333
341
  * @returns A new ApiWrapper instance configured with the provided client
334
342
  *
335
343
  * @example
@@ -359,5 +367,5 @@ export declare class ApiWrapper {
359
367
  * const apiWrapper = createApiWrapper(fetchClient);
360
368
  * ```
361
369
  */
362
- export declare function createApiWrapper(apiClient: any): ApiWrapper;
370
+ export declare function createApiWrapper(apiClient: any, config?: ApiWrapperConfig): ApiWrapper;
363
371
  //# sourceMappingURL=apiWrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiWrapper.d.ts","sourceRoot":"","sources":["../../src/client/apiWrapper.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC3C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE;QACJ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAAC,E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AAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIrG;;;;;;;;;;;;;;;;;OAiBG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIpG;;;;;;;;;;;;;;;;OAgBG;IACG,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAItG;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,QAAQ,CAAC,CAAC,SAAS,GAAG,EAAE,EAC1B,QAAQ,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAChC,OAAO,CAAC,EAAE,iBAAiB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAM7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAEtF"}
@@ -1,14 +1,7 @@
1
1
  import { apiStore } from './stores.js';
2
2
  import { handleAuthError } from './authErrorHandler.js';
3
3
  import { showError, showWarning } from './notifications.js';
4
- // Error codes that turn a 403 into "your session is not usable here" (the user
5
- // is authenticated, but not in this tenant). Anything else with a 403 is a plain
6
- // authorization failure and must never log anyone out.
7
- const SESSION_INVALID_FORBIDDEN_CODES = ['PETSHOP_ACCESS_DENIED'];
8
- function isSessionInvalidForbidden(error) {
9
- return error?.status === 403 && SESSION_INVALID_FORBIDDEN_CODES.includes(error?.code);
10
- }
11
- // Throttle for the session-expired warning (see the 401 handling below).
4
+ // Timestamp of the last session-expired warning.
12
5
  let lastSessionExpiredNoticeAt = 0;
13
6
  /**
14
7
  * Wraps API client calls with common error handling, loading states, and notifications
@@ -21,14 +14,17 @@ let lastSessionExpiredNoticeAt = 0;
21
14
  */
22
15
  export class ApiWrapper {
23
16
  apiClient;
17
+ config;
24
18
  /**
25
19
  * Creates a new ApiWrapper instance
26
20
  *
27
21
  * @param apiClient - The underlying API client instance (e.g., axios, fetch wrapper)
28
22
  * Should provide methods: get, post, put, patch, delete
23
+ * @param config - Configuration of the instance
29
24
  */
30
- constructor(apiClient) {
25
+ constructor(apiClient, config = {}) {
31
26
  this.apiClient = apiClient;
27
+ this.config = config;
32
28
  }
33
29
  isClientReady = typeof window !== 'undefined';
34
30
  /**
@@ -36,7 +32,7 @@ export class ApiWrapper {
36
32
  *
37
33
  * This is the core method that provides:
38
34
  * - Automatic loading state management via apiStore
39
- * - Authentication error handling (401 redirects; a 403 only notifies)
35
+ * - Authentication error handling (401 and session-invalid 403 codes log out and redirect; any other 403 only notifies)
40
36
  * - Error notifications via toast system
41
37
  * - Error state management in the store
42
38
  *
@@ -48,7 +44,7 @@ export class ApiWrapper {
48
44
  * @param options.customErrorMessage - Custom error message to display instead of server error
49
45
  * @param options.skipAuthHandling - Skip the 401 logout/redirect for login/logout endpoints (default: false)
50
46
  *
51
- * @returns Promise that resolves to the API response or void on error
47
+ * @returns Promise that resolves to the API response, or to an error response (`success: false`) on failure
52
48
  *
53
49
  * @example
54
50
  * ```typescript
@@ -58,6 +54,9 @@ export class ApiWrapper {
58
54
  * );
59
55
  * ```
60
56
  */
57
+ isSessionInvalidForbidden(error) {
58
+ return error.status === 403 && (this.config.sessionInvalidCodes ?? []).includes(error.code);
59
+ }
61
60
  /** As opções do wrapper que o cliente HTTP também precisa de conhecer. */
62
61
  requestOptions(options) {
63
62
  return options?.expectedStatuses ? { expectedStatuses: options.expectedStatuses } : undefined;
@@ -73,19 +72,15 @@ export class ApiWrapper {
73
72
  if (result?.success)
74
73
  return result;
75
74
  else
76
- throw result?.error;
75
+ throw result?.error ?? { message: result?.message };
77
76
  }
78
- catch (error) {
79
- // A 401 means there is no valid session. A 403 usually means the
80
- // opposite: the session is fine, the account just may not do this - so
81
- // it falls through to the notification branch, keeps the session and
82
- // shows the server message. The exception is a 403 whose code says the
83
- // session itself does not belong here (wrong tenant), which is as good
84
- // as not being logged in and still sends the user to login.
85
- if (!skipAuthHandling && (error.status === 401 || isSessionInvalidForbidden(error))) {
86
- // Friendly heads-up before the redirect to login; without it the
87
- // user lands on the login page with no explanation. Throttled so a
88
- // burst of parallel 401s doesn't stack identical toasts.
77
+ catch (caught) {
78
+ const error = caught ?? {};
79
+ // A 401, or a 403 with a session-invalid code, logs out and redirects
80
+ // to login. Any other error goes to the notification branch.
81
+ if (!skipAuthHandling && (error.status === 401 || this.isSessionInvalidForbidden(error))) {
82
+ // Shows the session-expired warning before the redirect, at most
83
+ // once every 5 seconds.
89
84
  if (error.status === 401 && this.isClientReady && Date.now() - lastSessionExpiredNoticeAt > 5000) {
90
85
  lastSessionExpiredNoticeAt = Date.now();
91
86
  showWarning('A sua sessão expirou. Por favor, inicie sessão novamente.');
@@ -216,46 +211,51 @@ export class ApiWrapper {
216
211
  /**
217
212
  * Executes multiple API calls in parallel with shared error handling and loading state
218
213
  *
219
- * All API calls will be executed simultaneously using Promise.all(), providing better
220
- * performance than sequential calls. If any call fails, the entire operation fails
221
- * and error handling is applied to the first error encountered.
214
+ * All API calls will be executed simultaneously using Promise.all(). If any call
215
+ * rejects or resolves to `success: false`, error handling is applied to it and
216
+ * an error response is returned.
222
217
  *
223
218
  * @template T - Tuple type representing the return types of all API calls
224
219
  * @param apiCalls - Array of functions that return API call promises
225
220
  * @param options - Optional configuration for error handling and loading state
226
- * @returns Promise resolving to an array of all API call results
221
+ * @returns Promise resolving to a response whose `data` holds the results, in order
227
222
  *
228
223
  * @example
229
224
  * ```typescript
230
- * const [users, posts, comments] = await apiWrapper.parallel([
225
+ * const response = await apiWrapper.parallel<[ApiResponse<User[]>, ApiResponse<Post[]>]>([
231
226
  * () => apiClient.get('/api/users'),
232
- * () => apiClient.get('/api/posts'),
233
- * () => apiClient.get('/api/comments')
227
+ * () => apiClient.get('/api/posts')
234
228
  * ]);
229
+ * if (response.success) {
230
+ * const [users, posts] = response.data!;
231
+ * }
235
232
  * ```
236
233
  *
237
234
  * @example
238
235
  * ```typescript
239
236
  * // With error handling options
240
237
  * const results = await apiWrapper.parallel(
241
- * [() => fetch('/api/data1'), () => fetch('/api/data2')],
238
+ * [() => apiClient.get('/api/data1'), () => apiClient.get('/api/data2')],
242
239
  * { customErrorMessage: 'Failed to load dashboard data' }
243
240
  * );
244
241
  * ```
245
242
  */
246
243
  async parallel(apiCalls, options) {
247
- return this.call(() => Promise.all(apiCalls.map(fn => fn())), options);
244
+ return this.call(async () => {
245
+ const results = await Promise.all(apiCalls.map(fn => fn()));
246
+ return results.find(result => result?.success === false) ?? { success: true, data: results };
247
+ }, options);
248
248
  }
249
249
  }
250
250
  /**
251
251
  * Factory function to create an ApiWrapper instance
252
252
  *
253
- * Provides a convenient way to create an ApiWrapper with the specified API client.
254
253
  * The API client should implement standard HTTP methods (get, post, put, patch, delete)
255
254
  * that return promises.
256
255
  *
257
256
  * @param apiClient - The underlying API client instance (e.g., axios instance, custom fetch wrapper)
258
257
  * Must provide methods: get, post, put, patch, delete
258
+ * @param config - Configuration of the instance
259
259
  * @returns A new ApiWrapper instance configured with the provided client
260
260
  *
261
261
  * @example
@@ -285,7 +285,7 @@ export class ApiWrapper {
285
285
  * const apiWrapper = createApiWrapper(fetchClient);
286
286
  * ```
287
287
  */
288
- export function createApiWrapper(apiClient) {
289
- return new ApiWrapper(apiClient);
288
+ export function createApiWrapper(apiClient, config) {
289
+ return new ApiWrapper(apiClient, config);
290
290
  }
291
291
  //# sourceMappingURL=apiWrapper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiWrapper.js","sourceRoot":"","sources":["../../src/client/apiWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D,+EAA+E;AAC/E,iFAAiF;AACjF,uDAAuD;AACvD,MAAM,+BAA+B,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAElE,SAAS,yBAAyB,CAAC,KAAU;IACzC,OAAO,KAAK,EAAE,MAAM,KAAK,GAAG,IAAI,+BAA+B,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAC1F,CAAC;AAED,yEAAyE;AACzE,IAAI,0BAA0B,GAAG,CAAC,CAAC;AAuKnC;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAU;IAOC;IANpB;;;;;OAKG;IACH,YAAoB,SAAc;QAAd,cAAS,GAAT,SAAS,CAAK;IAAI,CAAC;IAE/B,aAAa,GAAY,OAAO,MAAM,KAAK,WAAW,CAAC;IAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,0EAA0E;IAClE,cAAc,CAAC,OAA2B;QAC9C,OAAO,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAClG,CAAC;IAED,KAAK,CAAC,IAAI,CAAI,OAAyB,EAAE,UAA6B,EAAE;QACpE,MAAM,EACF,WAAW,GAAG,IAAI,EAClB,qBAAqB,GAAG,IAA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;YAC7B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAC5D,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QACjG,CAAC,EAAE,OAAO,CAA4B,CAAC;IAC3C,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAc,EAAE,MAAyB;IACtE,OAAO,IAAI,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"authErrorHandler.d.ts","sourceRoot":"","sources":["../../src/client/authErrorHandler.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,SAAU,SAAQ,KAAK;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,GAAG,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,YAAY,CAAS;gBAEjB,YAAY,GAAE,MAAiB;IAI3C;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBzD;AAGD,eAAO,MAAM,gBAAgB,kBAAyB,CAAC;AAGvD,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,kBAA4C,CAAC"}
1
+ {"version":3,"file":"authErrorHandler.d.ts","sourceRoot":"","sources":["../../src/client/authErrorHandler.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,SAAU,SAAQ,KAAK;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,GAAG,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,YAAY,CAAS;gBAEjB,YAAY,GAAE,MAAiB;IAI3C;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBzD;AAGD,eAAO,MAAM,gBAAgB,kBAAyB,CAAC;AAGvD,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,kBAA4C,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { goto } from '$app/navigation';
2
2
  import { browser } from '$app/environment';
3
3
  import { createLogger } from '@groundbrick/logger';
4
+ import { withReturnUrl } from '../navigation/returnUrl.js';
4
5
  import { authStore } from './stores.js';
5
6
  const logger = createLogger().child('auth-handler');
6
7
  /**
@@ -22,15 +23,10 @@ export class AuthErrorHandler {
22
23
  message: error.message,
23
24
  });
24
25
  authStore.logout();
25
- // Redirect to login page if needed
26
+ // Redirect to login page
26
27
  const redirectTo = error.redirectTo || this.redirectPath;
27
28
  logger.info('Redirecting to login page', { redirectTo });
28
- // Add current page as return URL
29
- const currentPath = window.location.pathname;
30
- const returnUrl = currentPath !== '/' && currentPath !== redirectTo
31
- ? `?returnUrl=${encodeURIComponent(currentPath)}`
32
- : '';
33
- await goto(`${redirectTo}${returnUrl}`);
29
+ await goto(withReturnUrl(redirectTo, window.location));
34
30
  }
35
31
  }
36
32
  // Create a default instance
@@ -1 +1 @@
1
- {"version":3,"file":"authErrorHandler.js","sourceRoot":"","sources":["../../src/client/authErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MA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function useNavigationNotificationClear(): void;
6
6
  /**
7
- * Alternative hook that can be used in specific pages/components
8
- * to clear notifications when the component is mounted
7
+ * Clears non-persistent notifications when called in the browser.
8
+ * Call it from a page or component.
9
9
  */
10
10
  export declare function useClearNotificationsOnMount(): void;
11
11
  //# sourceMappingURL=hooks.d.ts.map
@@ -17,8 +17,8 @@ export function useNavigationNotificationClear() {
17
17
  });
18
18
  }
19
19
  /**
20
- * Alternative hook that can be used in specific pages/components
21
- * to clear notifications when the component is mounted
20
+ * Clears non-persistent notifications when called in the browser.
21
+ * Call it from a page or component.
22
22
  */
23
23
  export function useClearNotificationsOnMount() {
24
24
  if (browser) {
@@ -4,5 +4,6 @@ export { decodeJwtToken, safeDecodeJwt, hasPermission, hasAnyPermission, hasAllP
4
4
  export { notificationStore, notifications, errorNotifications, successNotifications, warningNotifications, infoNotifications, latestError, latestSuccess, hasNotifications, hasErrors, hasSuccess, showSuccess, showError, showWarning, showInfo, clearAllNotifications, clearNotificationsByType, clearNonPersistentNotifications, removeNotification } from './notifications.js';
5
5
  export { useNavigationNotificationClear, useClearNotificationsOnMount } from './hooks.js';
6
6
  export { authErrorHandler, handleAuthError, } from './authErrorHandler.js';
7
- export { ApiWrapper, createApiWrapper, type ApiWrapperOptions, type ApiResponse, type ApiSuccessResponse, type ApiErrorResponse } from './apiWrapper.js';
7
+ export { ApiWrapper, createApiWrapper, type ApiWrapperConfig, type ApiWrapperOptions, type ApiResponse, type ApiSuccessResponse, type ApiErrorResponse } from './apiWrapper.js';
8
+ export { RETURN_URL_PARAM, safeReturnUrl, withReturnUrl } from '../navigation/returnUrl.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC"}
@@ -2,7 +2,7 @@ export { ApiClient, createApiClient } from './ApiClient.js';
2
2
  export { authStore, apiStore, currentUser, isLoading, currentError, initializeStores, initializeAuth, initializeFromJwt, initializeFromToken, clearErrors, } from './stores.js';
3
3
  // Export JWT decoder utilities
4
4
  export { decodeJwtToken, safeDecodeJwt, hasPermission, hasAnyPermission, hasAllPermissions, getUserDisplayName, getAdditionalFields } from './jwtDecoder.js';
5
- // Export new notification system
5
+ // Export notification system
6
6
  export { notificationStore, notifications, errorNotifications, successNotifications, warningNotifications, infoNotifications, latestError, latestSuccess, hasNotifications, hasErrors, hasSuccess, showSuccess, showError, showWarning, showInfo, clearAllNotifications, clearNotificationsByType, clearNonPersistentNotifications, removeNotification } from './notifications.js';
7
7
  // Export navigation hooks
8
8
  export { useNavigationNotificationClear, useClearNotificationsOnMount } from './hooks.js';
@@ -10,4 +10,6 @@ export { useNavigationNotificationClear, useClearNotificationsOnMount } from './
10
10
  export { authErrorHandler, handleAuthError, } from './authErrorHandler.js';
11
11
  // Export API wrapper utility
12
12
  export { ApiWrapper, createApiWrapper } from './apiWrapper.js';
13
+ // Export return URL helpers
14
+ export { RETURN_URL_PARAM, safeReturnUrl, withReturnUrl } from '../navigation/returnUrl.js';
13
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,+BAA+B;AAC/B,OAAO,EACL,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,iCAAiC;AACjC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,0BAA0B;AAC1B,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,4BAA4B;AAC5B,OAAO,EACL,gBAAgB,EAChB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,6BAA6B;AAC7B,OAAO,EACL,UAAU,EACV,gBAAgB,EAKjB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,+BAA+B;AAC/B,OAAO,EACL,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,6BAA6B;AAC7B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,0BAA0B;AAC1B,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,4BAA4B;AAC5B,OAAO,EACL,gBAAgB,EAChB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,6BAA6B;AAC7B,OAAO,EACL,UAAU,EACV,gBAAgB,EAMjB,MAAM,iBAAiB,CAAC;AAEzB,4BAA4B;AAC5B,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC"}
@@ -16,21 +16,20 @@ export interface DecodedJwt {
16
16
  }
17
17
  /**
18
18
  * Safely decode JWT token client-side without verification
19
- * This only decodes the payload - server-side verification is still required for security
19
+ * This only decodes the payload; the signature is not verified.
20
+ * Returns null when the token cannot be decoded.
20
21
  */
21
22
  export declare function decodeJwtToken(token: string): DecodedJwt | null;
22
23
  /**
23
- * Get JWT token from HTTP-only cookie (server-side only) or return null
24
- * In browser, this will return null as HTTP-only cookies are not accessible
24
+ * Always returns null, on the server and in the browser.
25
25
  */
26
26
  export declare function getAuthTokenFromCookie(): string | null;
27
27
  /**
28
28
  * Check if user has specific permission based on role hierarchy
29
29
  * - staff: check permissions array
30
- * - admin: has all permissions for their petshop
31
- * - super_admin: has all permissions everywhere
32
- * - customer: has no admin permissions
33
- TODO: REMOVE ANY REFERENCE TO FIXED ROLES - MAKE IT GENERIC
30
+ * - admin: has all permissions
31
+ * - super_admin: has all permissions
32
+ * - any other role: has no permissions
34
33
  */
35
34
  export declare function hasPermission(payload: JwtPayload, permission: string): boolean;
36
35
  /**
@@ -50,7 +49,8 @@ export declare function getUserDisplayName(payload: JwtPayload): string;
50
49
  */
51
50
  export declare function getAdditionalFields(payload: JwtPayload): Record<string, any>;
52
51
  /**
53
- * Utility to safely decode and validate JWT token with error handling
52
+ * Decodes a JWT token. Returns null for an empty or undecodable token; an
53
+ * expired token is returned with `isExpired: true`.
54
54
  */
55
55
  export declare function safeDecodeJwt(token: string | null | undefined): DecodedJwt | null;
56
56
  //# sourceMappingURL=jwtDecoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwtDecoder.d.ts","sourceRoot":"","sources":["../../src/client/jwtDecoder.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,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