@nocios/crudify-components 1.0.0 → 2.0.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.
- package/coverage/coverage-final.json +13 -13
- package/coverage/index.html +48 -48
- package/dist/chunk-4ILUXVPW.mjs +1 -0
- package/dist/{chunk-5HFI5CZ5.js → chunk-4VN5YRYZ.js} +1 -1
- package/dist/chunk-7ORHVSWL.mjs +1 -0
- package/dist/chunk-AOPB3KXB.js +1 -0
- package/dist/chunk-CR5KJUST.js +1 -0
- package/dist/{chunk-NBQH6QOU.mjs → chunk-GT7B57S5.mjs} +1 -1
- package/dist/{chunk-CHDM7KGH.js → chunk-LK6QVSG4.js} +1 -1
- package/dist/chunk-RJBX4MWF.mjs +1 -0
- package/dist/{chunk-2XOTIEKS.js → chunk-RORGWKHP.js} +1 -1
- package/dist/{chunk-U4RS66TB.mjs → chunk-XZ6OGRJR.mjs} +1 -1
- package/dist/components.js +1 -1
- package/dist/components.mjs +1 -1
- package/dist/errorTranslation-By5Av0tL.d.ts +335 -0
- package/dist/errorTranslation-DeeDj7Vt.d.mts +335 -0
- package/dist/hooks.js +1 -1
- package/dist/hooks.mjs +1 -1
- package/dist/index.d.mts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/utils.d.mts +2 -48
- package/dist/utils.d.ts +2 -48
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-HVTRRU4W.mjs +0 -1
- package/dist/chunk-JNEWPO2J.mjs +0 -1
- package/dist/chunk-MFYHD6S5.js +0 -1
- package/dist/chunk-MGJZTOEM.mjs +0 -1
- package/dist/chunk-PNI3ZBZV.js +0 -1
- package/dist/errorTranslation-DGdrMidg.d.ts +0 -143
- package/dist/errorTranslation-qwwQTvCO.d.mts +0 -143
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { J as JwtPayload } from './api-B4uXiHF0.js';
|
|
2
|
+
|
|
3
|
+
interface JWTPayload extends JwtPayload {
|
|
4
|
+
"cognito:username"?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const decodeJwtSafely: (token: string) => JWTPayload | null;
|
|
7
|
+
declare const getCurrentUserEmail: () => string | null;
|
|
8
|
+
declare const isTokenExpired: (token: string) => boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration resolver for crudify-components
|
|
12
|
+
*
|
|
13
|
+
* PRIORITY (v2.0.0 - No longer uses cookies):
|
|
14
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge)
|
|
15
|
+
* 2. Props (development - from .env variables)
|
|
16
|
+
* 3. Error (no configuration available)
|
|
17
|
+
*
|
|
18
|
+
* This module now delegates to tenantConfig.ts for the actual resolution.
|
|
19
|
+
* It maintains backward compatibility with the old API.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface ResolvedConfig {
|
|
23
|
+
publicApiKey?: string;
|
|
24
|
+
env?: CrudifyEnvironment;
|
|
25
|
+
appName?: string;
|
|
26
|
+
logo?: string;
|
|
27
|
+
loginActions?: string[];
|
|
28
|
+
featureKeys?: string[];
|
|
29
|
+
theme?: Record<string, unknown>;
|
|
30
|
+
configSource: "props" | "cookies" | "none";
|
|
31
|
+
}
|
|
32
|
+
interface ConfigResolverOptions {
|
|
33
|
+
publicApiKey?: string;
|
|
34
|
+
env?: CrudifyEnvironment;
|
|
35
|
+
appName?: string;
|
|
36
|
+
logo?: string;
|
|
37
|
+
loginActions?: string[];
|
|
38
|
+
featureKeys?: string[];
|
|
39
|
+
enableDebug?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves Crudify configuration with the following priority:
|
|
43
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge) - HIGHEST PRIORITY
|
|
44
|
+
* 2. Props (development - from .env variables) - FALLBACK
|
|
45
|
+
* 3. None (error - no configuration available)
|
|
46
|
+
*
|
|
47
|
+
* @param options - Configuration options including props for development
|
|
48
|
+
* @returns Resolved configuration with source indicator
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // In production (Lambda@Edge injects window.__TENANT_CONFIG__)
|
|
53
|
+
* const config = resolveConfig();
|
|
54
|
+
* console.log(config.publicApiKey); // From injected config
|
|
55
|
+
* console.log(config.configSource); // "cookies" (for backward compatibility)
|
|
56
|
+
*
|
|
57
|
+
* // In development (with .env variables)
|
|
58
|
+
* const config = resolveConfig({
|
|
59
|
+
* publicApiKey: import.meta.env.VITE_PUBLIC_API_KEY,
|
|
60
|
+
* env: import.meta.env.VITE_ENV,
|
|
61
|
+
* });
|
|
62
|
+
* console.log(config.configSource); // "props"
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function resolveConfig(options?: ConfigResolverOptions): ResolvedConfig;
|
|
66
|
+
/**
|
|
67
|
+
* React hook to use config resolver
|
|
68
|
+
* Useful when you need config in a component
|
|
69
|
+
*
|
|
70
|
+
* @param options - Configuration options
|
|
71
|
+
* @returns Resolved configuration
|
|
72
|
+
*/
|
|
73
|
+
declare function useResolvedConfig(options?: ConfigResolverOptions): ResolvedConfig;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Global type declarations for window extensions used by Crudify
|
|
77
|
+
*
|
|
78
|
+
* These types enable type-safe access to window properties that are
|
|
79
|
+
* set dynamically at runtime by Crudify components.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Tenant configuration injected by Lambda@Edge into the HTML
|
|
86
|
+
* This is the primary source of configuration in production
|
|
87
|
+
*/
|
|
88
|
+
interface TenantConfig {
|
|
89
|
+
publicApiKey: string;
|
|
90
|
+
environment: "dev" | "stg" | "api" | "prod";
|
|
91
|
+
appName?: string;
|
|
92
|
+
logo?: string;
|
|
93
|
+
loginActions?: string[];
|
|
94
|
+
featureKeys?: string[];
|
|
95
|
+
theme?: Record<string, unknown>;
|
|
96
|
+
enabledServices?: string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare global {
|
|
100
|
+
interface Window {
|
|
101
|
+
// NEW: Tenant configuration injected by Lambda@Edge (primary source in production)
|
|
102
|
+
__TENANT_CONFIG__?: TenantConfig;
|
|
103
|
+
|
|
104
|
+
// Crudify environment configuration (legacy, kept for compatibility)
|
|
105
|
+
__CRUDIFY_ENV__?: CrudifyEnvironment;
|
|
106
|
+
__CRUDIFY_DEBUG_MODE__?: boolean;
|
|
107
|
+
__CRUDIFY_RESOLVED_CONFIG?: ResolvedConfig;
|
|
108
|
+
|
|
109
|
+
// i18next integration (optional, used when auto-syncing translations)
|
|
110
|
+
i18next?: {
|
|
111
|
+
addResourceBundle: (lang: string, ns: string, resources: Record<string, string>, deep?: boolean, overwrite?: boolean) => void;
|
|
112
|
+
language?: string;
|
|
113
|
+
changeLanguage: (lang: string) => void;
|
|
114
|
+
};
|
|
115
|
+
i18n?: Window["i18next"];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Centralized tenant configuration system for crudify-components
|
|
121
|
+
*
|
|
122
|
+
* This module provides a unified way to access tenant configuration
|
|
123
|
+
* that is injected by Lambda@Edge in production or provided via props
|
|
124
|
+
* in development.
|
|
125
|
+
*
|
|
126
|
+
* PRIORITY:
|
|
127
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge)
|
|
128
|
+
* 2. Props (development - from .env variables)
|
|
129
|
+
* 3. Error (no configuration available)
|
|
130
|
+
*
|
|
131
|
+
* This replaces the cookie-based system to avoid race conditions
|
|
132
|
+
* where cookies from Set-Cookie headers are not immediately available
|
|
133
|
+
* to JavaScript on the first page load.
|
|
134
|
+
*/
|
|
135
|
+
type CrudifyEnvironment = "dev" | "stg" | "api" | "prod";
|
|
136
|
+
interface ResolvedTenantConfig {
|
|
137
|
+
publicApiKey?: string;
|
|
138
|
+
environment?: CrudifyEnvironment;
|
|
139
|
+
appName?: string;
|
|
140
|
+
logo?: string;
|
|
141
|
+
loginActions?: string[];
|
|
142
|
+
featureKeys?: string[];
|
|
143
|
+
theme?: Record<string, unknown>;
|
|
144
|
+
enabledServices?: string[];
|
|
145
|
+
configSource: "injected" | "props" | "none";
|
|
146
|
+
}
|
|
147
|
+
interface TenantConfigOptions {
|
|
148
|
+
publicApiKey?: string;
|
|
149
|
+
env?: CrudifyEnvironment;
|
|
150
|
+
appName?: string;
|
|
151
|
+
logo?: string;
|
|
152
|
+
loginActions?: string[];
|
|
153
|
+
featureKeys?: string[];
|
|
154
|
+
theme?: Record<string, unknown>;
|
|
155
|
+
enabledServices?: string[];
|
|
156
|
+
enableDebug?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Resolves tenant configuration with the following priority:
|
|
160
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge) - HIGHEST PRIORITY
|
|
161
|
+
* 2. Props (development - from .env variables) - FALLBACK
|
|
162
|
+
* 3. None (error - no configuration available)
|
|
163
|
+
*
|
|
164
|
+
* @param options - Configuration options including props for development
|
|
165
|
+
* @returns Resolved configuration with source indicator
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // In production (Lambda@Edge injects window.__TENANT_CONFIG__)
|
|
170
|
+
* const config = resolveTenantConfig();
|
|
171
|
+
* console.log(config.publicApiKey); // From injected config
|
|
172
|
+
* console.log(config.configSource); // "injected"
|
|
173
|
+
*
|
|
174
|
+
* // In development (with .env variables)
|
|
175
|
+
* const config = resolveTenantConfig({
|
|
176
|
+
* publicApiKey: import.meta.env.VITE_PUBLIC_API_KEY,
|
|
177
|
+
* env: import.meta.env.VITE_ENV,
|
|
178
|
+
* });
|
|
179
|
+
* console.log(config.configSource); // "props"
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare function resolveTenantConfig(options?: TenantConfigOptions): ResolvedTenantConfig;
|
|
183
|
+
/**
|
|
184
|
+
* React hook to access tenant configuration
|
|
185
|
+
*
|
|
186
|
+
* @param options - Configuration options
|
|
187
|
+
* @returns Resolved tenant configuration
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* function MyComponent() {
|
|
192
|
+
* const config = useTenantConfig();
|
|
193
|
+
*
|
|
194
|
+
* if (config.configSource === "none") {
|
|
195
|
+
* return <Error>No configuration available</Error>;
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* return <div>API Key: {config.publicApiKey}</div>;
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare function useTenantConfig(options?: TenantConfigOptions): ResolvedTenantConfig;
|
|
203
|
+
|
|
204
|
+
declare class SecureStorage {
|
|
205
|
+
private readonly storage;
|
|
206
|
+
private encryptionKey;
|
|
207
|
+
private salt;
|
|
208
|
+
private initPromise;
|
|
209
|
+
private initialized;
|
|
210
|
+
constructor(storageType?: "localStorage" | "sessionStorage");
|
|
211
|
+
/**
|
|
212
|
+
* Initialize encryption key asynchronously
|
|
213
|
+
* Must be called before using encryption methods
|
|
214
|
+
*/
|
|
215
|
+
private ensureInitialized;
|
|
216
|
+
private initialize;
|
|
217
|
+
private generateFingerprint;
|
|
218
|
+
private clearLegacyData;
|
|
219
|
+
setItem(key: string, value: string, expiryMinutes?: number): Promise<void>;
|
|
220
|
+
getItem(key: string): Promise<string | null>;
|
|
221
|
+
removeItem(key: string): void;
|
|
222
|
+
clear(): void;
|
|
223
|
+
setToken(token: string): Promise<void>;
|
|
224
|
+
getToken(): Promise<string | null>;
|
|
225
|
+
hasValidToken(): Promise<boolean>;
|
|
226
|
+
migrateFromLocalStorage(key: string): Promise<void>;
|
|
227
|
+
private uint8ArrayToBase64;
|
|
228
|
+
private base64ToUint8Array;
|
|
229
|
+
}
|
|
230
|
+
declare const secureSessionStorage: SecureStorage;
|
|
231
|
+
declare const secureLocalStorage: SecureStorage;
|
|
232
|
+
|
|
233
|
+
declare const ERROR_CODES: {
|
|
234
|
+
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
|
|
235
|
+
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
236
|
+
readonly INVALID_API_KEY: "INVALID_API_KEY";
|
|
237
|
+
readonly USER_NOT_FOUND: "USER_NOT_FOUND";
|
|
238
|
+
readonly USER_NOT_ACTIVE: "USER_NOT_ACTIVE";
|
|
239
|
+
readonly NO_PERMISSION: "NO_PERMISSION";
|
|
240
|
+
readonly ITEM_NOT_FOUND: "ITEM_NOT_FOUND";
|
|
241
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
242
|
+
readonly IN_USE: "IN_USE";
|
|
243
|
+
readonly FIELD_ERROR: "FIELD_ERROR";
|
|
244
|
+
readonly BAD_REQUEST: "BAD_REQUEST";
|
|
245
|
+
readonly INVALID_EMAIL: "INVALID_EMAIL";
|
|
246
|
+
readonly INVALID_CODE: "INVALID_CODE";
|
|
247
|
+
readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
|
|
248
|
+
readonly DATABASE_CONNECTION_ERROR: "DATABASE_CONNECTION_ERROR";
|
|
249
|
+
readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
|
|
250
|
+
readonly UNKNOWN_OPERATION: "UNKNOWN_OPERATION";
|
|
251
|
+
readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
|
|
252
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
253
|
+
readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
|
|
254
|
+
};
|
|
255
|
+
type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
256
|
+
type ErrorSeverity = "info" | "warning" | "error" | "critical";
|
|
257
|
+
declare const ERROR_SEVERITY_MAP: Record<ErrorCode, ErrorSeverity>;
|
|
258
|
+
interface ParsedError {
|
|
259
|
+
code: ErrorCode;
|
|
260
|
+
message: string;
|
|
261
|
+
severity: ErrorSeverity;
|
|
262
|
+
field?: string;
|
|
263
|
+
details?: Record<string, unknown>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Parse a Crudify API response and extract standardized error information
|
|
267
|
+
*/
|
|
268
|
+
declare function parseApiError(response: unknown): ParsedError[];
|
|
269
|
+
/**
|
|
270
|
+
* Parse transaction response errors
|
|
271
|
+
*/
|
|
272
|
+
declare function parseTransactionError(response: unknown): ParsedError[];
|
|
273
|
+
/**
|
|
274
|
+
* Get a human-readable error message for an error code
|
|
275
|
+
*/
|
|
276
|
+
declare function getErrorMessage(code: ErrorCode): string;
|
|
277
|
+
/**
|
|
278
|
+
* Handle JavaScript/Network errors and convert to ParsedError
|
|
279
|
+
*/
|
|
280
|
+
declare function parseJavaScriptError(error: unknown): ParsedError;
|
|
281
|
+
/**
|
|
282
|
+
* Universal error handler that can process any type of error from Crudify APIs
|
|
283
|
+
*/
|
|
284
|
+
declare function handleCrudifyError(error: unknown): ParsedError[];
|
|
285
|
+
|
|
286
|
+
interface ErrorTranslationConfig {
|
|
287
|
+
/** Función de traducción de i18next */
|
|
288
|
+
translateFn: (key: string) => string;
|
|
289
|
+
/** Idioma actual (opcional, para logging) */
|
|
290
|
+
currentLanguage?: string;
|
|
291
|
+
/** Habilitar logs de debug */
|
|
292
|
+
enableDebug?: boolean;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Traduce un código de error usando jerarquía de fallbacks
|
|
296
|
+
*/
|
|
297
|
+
declare function translateErrorCode(errorCode: string, config: ErrorTranslationConfig): string;
|
|
298
|
+
/**
|
|
299
|
+
* Traduce múltiples códigos de error
|
|
300
|
+
*/
|
|
301
|
+
declare function translateErrorCodes(errorCodes: string[], config: ErrorTranslationConfig): string[];
|
|
302
|
+
/**
|
|
303
|
+
* Traduce un error completo (código + mensaje personalizado)
|
|
304
|
+
*/
|
|
305
|
+
declare function translateError(error: {
|
|
306
|
+
code: string;
|
|
307
|
+
message?: string;
|
|
308
|
+
field?: string;
|
|
309
|
+
}, config: ErrorTranslationConfig): string;
|
|
310
|
+
/**
|
|
311
|
+
* Hook para usar en componentes React con i18next
|
|
312
|
+
*/
|
|
313
|
+
declare function createErrorTranslator(translateFn: (key: string) => string, options?: {
|
|
314
|
+
currentLanguage?: string;
|
|
315
|
+
enableDebug?: boolean;
|
|
316
|
+
}): {
|
|
317
|
+
translateErrorCode: (code: string) => string;
|
|
318
|
+
translateErrorCodes: (codes: string[]) => string[];
|
|
319
|
+
translateError: (error: {
|
|
320
|
+
code: string;
|
|
321
|
+
message?: string;
|
|
322
|
+
field?: string;
|
|
323
|
+
}) => string;
|
|
324
|
+
translateApiError: (apiResponse: {
|
|
325
|
+
data?: {
|
|
326
|
+
response?: {
|
|
327
|
+
status?: string;
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
status?: string;
|
|
331
|
+
code?: string;
|
|
332
|
+
} | null | undefined) => string;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export { type ConfigResolverOptions as C, ERROR_CODES as E, type ParsedError as P, type ResolvedTenantConfig as R, type TenantConfig as T, secureLocalStorage as a, type TenantConfigOptions as b, resolveConfig as c, decodeJwtSafely as d, useResolvedConfig as e, type ResolvedConfig as f, getCurrentUserEmail as g, type CrudifyEnvironment as h, isTokenExpired as i, handleCrudifyError as j, parseTransactionError as k, parseJavaScriptError as l, getErrorMessage as m, ERROR_SEVERITY_MAP as n, translateErrorCodes as o, parseApiError as p, translateError as q, resolveTenantConfig as r, secureSessionStorage as s, translateErrorCode as t, useTenantConfig as u, createErrorTranslator as v, type ErrorCode as w, type ErrorSeverity as x, type ErrorTranslationConfig as y };
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { J as JwtPayload } from './api-B4uXiHF0.mjs';
|
|
2
|
+
|
|
3
|
+
interface JWTPayload extends JwtPayload {
|
|
4
|
+
"cognito:username"?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const decodeJwtSafely: (token: string) => JWTPayload | null;
|
|
7
|
+
declare const getCurrentUserEmail: () => string | null;
|
|
8
|
+
declare const isTokenExpired: (token: string) => boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration resolver for crudify-components
|
|
12
|
+
*
|
|
13
|
+
* PRIORITY (v2.0.0 - No longer uses cookies):
|
|
14
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge)
|
|
15
|
+
* 2. Props (development - from .env variables)
|
|
16
|
+
* 3. Error (no configuration available)
|
|
17
|
+
*
|
|
18
|
+
* This module now delegates to tenantConfig.ts for the actual resolution.
|
|
19
|
+
* It maintains backward compatibility with the old API.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface ResolvedConfig {
|
|
23
|
+
publicApiKey?: string;
|
|
24
|
+
env?: CrudifyEnvironment;
|
|
25
|
+
appName?: string;
|
|
26
|
+
logo?: string;
|
|
27
|
+
loginActions?: string[];
|
|
28
|
+
featureKeys?: string[];
|
|
29
|
+
theme?: Record<string, unknown>;
|
|
30
|
+
configSource: "props" | "cookies" | "none";
|
|
31
|
+
}
|
|
32
|
+
interface ConfigResolverOptions {
|
|
33
|
+
publicApiKey?: string;
|
|
34
|
+
env?: CrudifyEnvironment;
|
|
35
|
+
appName?: string;
|
|
36
|
+
logo?: string;
|
|
37
|
+
loginActions?: string[];
|
|
38
|
+
featureKeys?: string[];
|
|
39
|
+
enableDebug?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves Crudify configuration with the following priority:
|
|
43
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge) - HIGHEST PRIORITY
|
|
44
|
+
* 2. Props (development - from .env variables) - FALLBACK
|
|
45
|
+
* 3. None (error - no configuration available)
|
|
46
|
+
*
|
|
47
|
+
* @param options - Configuration options including props for development
|
|
48
|
+
* @returns Resolved configuration with source indicator
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // In production (Lambda@Edge injects window.__TENANT_CONFIG__)
|
|
53
|
+
* const config = resolveConfig();
|
|
54
|
+
* console.log(config.publicApiKey); // From injected config
|
|
55
|
+
* console.log(config.configSource); // "cookies" (for backward compatibility)
|
|
56
|
+
*
|
|
57
|
+
* // In development (with .env variables)
|
|
58
|
+
* const config = resolveConfig({
|
|
59
|
+
* publicApiKey: import.meta.env.VITE_PUBLIC_API_KEY,
|
|
60
|
+
* env: import.meta.env.VITE_ENV,
|
|
61
|
+
* });
|
|
62
|
+
* console.log(config.configSource); // "props"
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function resolveConfig(options?: ConfigResolverOptions): ResolvedConfig;
|
|
66
|
+
/**
|
|
67
|
+
* React hook to use config resolver
|
|
68
|
+
* Useful when you need config in a component
|
|
69
|
+
*
|
|
70
|
+
* @param options - Configuration options
|
|
71
|
+
* @returns Resolved configuration
|
|
72
|
+
*/
|
|
73
|
+
declare function useResolvedConfig(options?: ConfigResolverOptions): ResolvedConfig;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Global type declarations for window extensions used by Crudify
|
|
77
|
+
*
|
|
78
|
+
* These types enable type-safe access to window properties that are
|
|
79
|
+
* set dynamically at runtime by Crudify components.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Tenant configuration injected by Lambda@Edge into the HTML
|
|
86
|
+
* This is the primary source of configuration in production
|
|
87
|
+
*/
|
|
88
|
+
interface TenantConfig {
|
|
89
|
+
publicApiKey: string;
|
|
90
|
+
environment: "dev" | "stg" | "api" | "prod";
|
|
91
|
+
appName?: string;
|
|
92
|
+
logo?: string;
|
|
93
|
+
loginActions?: string[];
|
|
94
|
+
featureKeys?: string[];
|
|
95
|
+
theme?: Record<string, unknown>;
|
|
96
|
+
enabledServices?: string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare global {
|
|
100
|
+
interface Window {
|
|
101
|
+
// NEW: Tenant configuration injected by Lambda@Edge (primary source in production)
|
|
102
|
+
__TENANT_CONFIG__?: TenantConfig;
|
|
103
|
+
|
|
104
|
+
// Crudify environment configuration (legacy, kept for compatibility)
|
|
105
|
+
__CRUDIFY_ENV__?: CrudifyEnvironment;
|
|
106
|
+
__CRUDIFY_DEBUG_MODE__?: boolean;
|
|
107
|
+
__CRUDIFY_RESOLVED_CONFIG?: ResolvedConfig;
|
|
108
|
+
|
|
109
|
+
// i18next integration (optional, used when auto-syncing translations)
|
|
110
|
+
i18next?: {
|
|
111
|
+
addResourceBundle: (lang: string, ns: string, resources: Record<string, string>, deep?: boolean, overwrite?: boolean) => void;
|
|
112
|
+
language?: string;
|
|
113
|
+
changeLanguage: (lang: string) => void;
|
|
114
|
+
};
|
|
115
|
+
i18n?: Window["i18next"];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Centralized tenant configuration system for crudify-components
|
|
121
|
+
*
|
|
122
|
+
* This module provides a unified way to access tenant configuration
|
|
123
|
+
* that is injected by Lambda@Edge in production or provided via props
|
|
124
|
+
* in development.
|
|
125
|
+
*
|
|
126
|
+
* PRIORITY:
|
|
127
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge)
|
|
128
|
+
* 2. Props (development - from .env variables)
|
|
129
|
+
* 3. Error (no configuration available)
|
|
130
|
+
*
|
|
131
|
+
* This replaces the cookie-based system to avoid race conditions
|
|
132
|
+
* where cookies from Set-Cookie headers are not immediately available
|
|
133
|
+
* to JavaScript on the first page load.
|
|
134
|
+
*/
|
|
135
|
+
type CrudifyEnvironment = "dev" | "stg" | "api" | "prod";
|
|
136
|
+
interface ResolvedTenantConfig {
|
|
137
|
+
publicApiKey?: string;
|
|
138
|
+
environment?: CrudifyEnvironment;
|
|
139
|
+
appName?: string;
|
|
140
|
+
logo?: string;
|
|
141
|
+
loginActions?: string[];
|
|
142
|
+
featureKeys?: string[];
|
|
143
|
+
theme?: Record<string, unknown>;
|
|
144
|
+
enabledServices?: string[];
|
|
145
|
+
configSource: "injected" | "props" | "none";
|
|
146
|
+
}
|
|
147
|
+
interface TenantConfigOptions {
|
|
148
|
+
publicApiKey?: string;
|
|
149
|
+
env?: CrudifyEnvironment;
|
|
150
|
+
appName?: string;
|
|
151
|
+
logo?: string;
|
|
152
|
+
loginActions?: string[];
|
|
153
|
+
featureKeys?: string[];
|
|
154
|
+
theme?: Record<string, unknown>;
|
|
155
|
+
enabledServices?: string[];
|
|
156
|
+
enableDebug?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Resolves tenant configuration with the following priority:
|
|
160
|
+
* 1. window.__TENANT_CONFIG__ (production - injected by Lambda@Edge) - HIGHEST PRIORITY
|
|
161
|
+
* 2. Props (development - from .env variables) - FALLBACK
|
|
162
|
+
* 3. None (error - no configuration available)
|
|
163
|
+
*
|
|
164
|
+
* @param options - Configuration options including props for development
|
|
165
|
+
* @returns Resolved configuration with source indicator
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // In production (Lambda@Edge injects window.__TENANT_CONFIG__)
|
|
170
|
+
* const config = resolveTenantConfig();
|
|
171
|
+
* console.log(config.publicApiKey); // From injected config
|
|
172
|
+
* console.log(config.configSource); // "injected"
|
|
173
|
+
*
|
|
174
|
+
* // In development (with .env variables)
|
|
175
|
+
* const config = resolveTenantConfig({
|
|
176
|
+
* publicApiKey: import.meta.env.VITE_PUBLIC_API_KEY,
|
|
177
|
+
* env: import.meta.env.VITE_ENV,
|
|
178
|
+
* });
|
|
179
|
+
* console.log(config.configSource); // "props"
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare function resolveTenantConfig(options?: TenantConfigOptions): ResolvedTenantConfig;
|
|
183
|
+
/**
|
|
184
|
+
* React hook to access tenant configuration
|
|
185
|
+
*
|
|
186
|
+
* @param options - Configuration options
|
|
187
|
+
* @returns Resolved tenant configuration
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* function MyComponent() {
|
|
192
|
+
* const config = useTenantConfig();
|
|
193
|
+
*
|
|
194
|
+
* if (config.configSource === "none") {
|
|
195
|
+
* return <Error>No configuration available</Error>;
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* return <div>API Key: {config.publicApiKey}</div>;
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare function useTenantConfig(options?: TenantConfigOptions): ResolvedTenantConfig;
|
|
203
|
+
|
|
204
|
+
declare class SecureStorage {
|
|
205
|
+
private readonly storage;
|
|
206
|
+
private encryptionKey;
|
|
207
|
+
private salt;
|
|
208
|
+
private initPromise;
|
|
209
|
+
private initialized;
|
|
210
|
+
constructor(storageType?: "localStorage" | "sessionStorage");
|
|
211
|
+
/**
|
|
212
|
+
* Initialize encryption key asynchronously
|
|
213
|
+
* Must be called before using encryption methods
|
|
214
|
+
*/
|
|
215
|
+
private ensureInitialized;
|
|
216
|
+
private initialize;
|
|
217
|
+
private generateFingerprint;
|
|
218
|
+
private clearLegacyData;
|
|
219
|
+
setItem(key: string, value: string, expiryMinutes?: number): Promise<void>;
|
|
220
|
+
getItem(key: string): Promise<string | null>;
|
|
221
|
+
removeItem(key: string): void;
|
|
222
|
+
clear(): void;
|
|
223
|
+
setToken(token: string): Promise<void>;
|
|
224
|
+
getToken(): Promise<string | null>;
|
|
225
|
+
hasValidToken(): Promise<boolean>;
|
|
226
|
+
migrateFromLocalStorage(key: string): Promise<void>;
|
|
227
|
+
private uint8ArrayToBase64;
|
|
228
|
+
private base64ToUint8Array;
|
|
229
|
+
}
|
|
230
|
+
declare const secureSessionStorage: SecureStorage;
|
|
231
|
+
declare const secureLocalStorage: SecureStorage;
|
|
232
|
+
|
|
233
|
+
declare const ERROR_CODES: {
|
|
234
|
+
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
|
|
235
|
+
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
236
|
+
readonly INVALID_API_KEY: "INVALID_API_KEY";
|
|
237
|
+
readonly USER_NOT_FOUND: "USER_NOT_FOUND";
|
|
238
|
+
readonly USER_NOT_ACTIVE: "USER_NOT_ACTIVE";
|
|
239
|
+
readonly NO_PERMISSION: "NO_PERMISSION";
|
|
240
|
+
readonly ITEM_NOT_FOUND: "ITEM_NOT_FOUND";
|
|
241
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
242
|
+
readonly IN_USE: "IN_USE";
|
|
243
|
+
readonly FIELD_ERROR: "FIELD_ERROR";
|
|
244
|
+
readonly BAD_REQUEST: "BAD_REQUEST";
|
|
245
|
+
readonly INVALID_EMAIL: "INVALID_EMAIL";
|
|
246
|
+
readonly INVALID_CODE: "INVALID_CODE";
|
|
247
|
+
readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
|
|
248
|
+
readonly DATABASE_CONNECTION_ERROR: "DATABASE_CONNECTION_ERROR";
|
|
249
|
+
readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
|
|
250
|
+
readonly UNKNOWN_OPERATION: "UNKNOWN_OPERATION";
|
|
251
|
+
readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
|
|
252
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
253
|
+
readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
|
|
254
|
+
};
|
|
255
|
+
type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
256
|
+
type ErrorSeverity = "info" | "warning" | "error" | "critical";
|
|
257
|
+
declare const ERROR_SEVERITY_MAP: Record<ErrorCode, ErrorSeverity>;
|
|
258
|
+
interface ParsedError {
|
|
259
|
+
code: ErrorCode;
|
|
260
|
+
message: string;
|
|
261
|
+
severity: ErrorSeverity;
|
|
262
|
+
field?: string;
|
|
263
|
+
details?: Record<string, unknown>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Parse a Crudify API response and extract standardized error information
|
|
267
|
+
*/
|
|
268
|
+
declare function parseApiError(response: unknown): ParsedError[];
|
|
269
|
+
/**
|
|
270
|
+
* Parse transaction response errors
|
|
271
|
+
*/
|
|
272
|
+
declare function parseTransactionError(response: unknown): ParsedError[];
|
|
273
|
+
/**
|
|
274
|
+
* Get a human-readable error message for an error code
|
|
275
|
+
*/
|
|
276
|
+
declare function getErrorMessage(code: ErrorCode): string;
|
|
277
|
+
/**
|
|
278
|
+
* Handle JavaScript/Network errors and convert to ParsedError
|
|
279
|
+
*/
|
|
280
|
+
declare function parseJavaScriptError(error: unknown): ParsedError;
|
|
281
|
+
/**
|
|
282
|
+
* Universal error handler that can process any type of error from Crudify APIs
|
|
283
|
+
*/
|
|
284
|
+
declare function handleCrudifyError(error: unknown): ParsedError[];
|
|
285
|
+
|
|
286
|
+
interface ErrorTranslationConfig {
|
|
287
|
+
/** Función de traducción de i18next */
|
|
288
|
+
translateFn: (key: string) => string;
|
|
289
|
+
/** Idioma actual (opcional, para logging) */
|
|
290
|
+
currentLanguage?: string;
|
|
291
|
+
/** Habilitar logs de debug */
|
|
292
|
+
enableDebug?: boolean;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Traduce un código de error usando jerarquía de fallbacks
|
|
296
|
+
*/
|
|
297
|
+
declare function translateErrorCode(errorCode: string, config: ErrorTranslationConfig): string;
|
|
298
|
+
/**
|
|
299
|
+
* Traduce múltiples códigos de error
|
|
300
|
+
*/
|
|
301
|
+
declare function translateErrorCodes(errorCodes: string[], config: ErrorTranslationConfig): string[];
|
|
302
|
+
/**
|
|
303
|
+
* Traduce un error completo (código + mensaje personalizado)
|
|
304
|
+
*/
|
|
305
|
+
declare function translateError(error: {
|
|
306
|
+
code: string;
|
|
307
|
+
message?: string;
|
|
308
|
+
field?: string;
|
|
309
|
+
}, config: ErrorTranslationConfig): string;
|
|
310
|
+
/**
|
|
311
|
+
* Hook para usar en componentes React con i18next
|
|
312
|
+
*/
|
|
313
|
+
declare function createErrorTranslator(translateFn: (key: string) => string, options?: {
|
|
314
|
+
currentLanguage?: string;
|
|
315
|
+
enableDebug?: boolean;
|
|
316
|
+
}): {
|
|
317
|
+
translateErrorCode: (code: string) => string;
|
|
318
|
+
translateErrorCodes: (codes: string[]) => string[];
|
|
319
|
+
translateError: (error: {
|
|
320
|
+
code: string;
|
|
321
|
+
message?: string;
|
|
322
|
+
field?: string;
|
|
323
|
+
}) => string;
|
|
324
|
+
translateApiError: (apiResponse: {
|
|
325
|
+
data?: {
|
|
326
|
+
response?: {
|
|
327
|
+
status?: string;
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
status?: string;
|
|
331
|
+
code?: string;
|
|
332
|
+
} | null | undefined) => string;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export { type ConfigResolverOptions as C, ERROR_CODES as E, type ParsedError as P, type ResolvedTenantConfig as R, type TenantConfig as T, secureLocalStorage as a, type TenantConfigOptions as b, resolveConfig as c, decodeJwtSafely as d, useResolvedConfig as e, type ResolvedConfig as f, getCurrentUserEmail as g, type CrudifyEnvironment as h, isTokenExpired as i, handleCrudifyError as j, parseTransactionError as k, parseJavaScriptError as l, getErrorMessage as m, ERROR_SEVERITY_MAP as n, translateErrorCodes as o, parseApiError as p, translateError as q, resolveTenantConfig as r, secureSessionStorage as s, translateErrorCode as t, useTenantConfig as u, createErrorTranslator as v, type ErrorCode as w, type ErrorSeverity as x, type ErrorTranslationConfig as y };
|
package/dist/hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkRORGWKHPjs = require('./chunk-RORGWKHP.js');var _chunkLK6QVSG4js = require('./chunk-LK6QVSG4.js');require('./chunk-CR5KJUST.js');exports.useAuth = _chunkRORGWKHPjs.b; exports.useAutoGenerate = _chunkLK6QVSG4js.o; exports.useCrudifyWithNotifications = _chunkRORGWKHPjs.d; exports.useData = _chunkRORGWKHPjs.c; exports.useFileUpload = _chunkLK6QVSG4js.r; exports.useSession = _chunkLK6QVSG4js.e; exports.useUserData = _chunkRORGWKHPjs.a; exports.useUserProfile = _chunkLK6QVSG4js.n;
|
package/dist/hooks.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s,b as p,c as u,d as a}from"./chunk-
|
|
1
|
+
import{a as s,b as p,c as u,d as a}from"./chunk-XZ6OGRJR.mjs";import{e,n as t,o,r}from"./chunk-GT7B57S5.mjs";import"./chunk-4ILUXVPW.mjs";export{p as useAuth,o as useAutoGenerate,a as useCrudifyWithNotifications,u as useData,r as useFileUpload,e as useSession,s as useUserData,t as useUserProfile};
|