@nocios/crudify-ui 1.0.70 → 1.0.71

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/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import * as _nocios_crudify_browser from '@nocios/crudify-browser';
2
1
  export * from '@nocios/crudify-browser';
3
2
  export { default as crudify } from '@nocios/crudify-browser';
4
3
  import React from 'react';
5
4
 
6
5
  type BoxScreenType = "login" | "signUp" | "forgotPassword" | "resetPassword" | "checkCode";
7
6
  interface CrudifyLoginConfig {
8
- publicApiKey?: string;
7
+ publicApiKey?: string | null;
9
8
  env?: "dev" | "stg" | "api" | "prod";
10
9
  appName?: string;
11
10
  logo?: string;
@@ -35,13 +34,94 @@ interface CrudifyLoginProps {
35
34
 
36
35
  declare const CrudifyLogin: React.FC<CrudifyLoginProps>;
37
36
 
37
+ interface CrudifyApiResponse<T = unknown> {
38
+ success: boolean;
39
+ data?: T;
40
+ errors?: string | Record<string, string[]> | string[];
41
+ errorCode?: string;
42
+ fieldsWarning?: Record<string, string[]>;
43
+ }
44
+ interface CrudifyTransactionResponse {
45
+ success: boolean;
46
+ data?: TransactionResponseData[];
47
+ errors?: string | Record<string, string[]>;
48
+ errorCode?: string;
49
+ }
50
+ interface TransactionResponseData {
51
+ response?: {
52
+ status: string;
53
+ data?: unknown;
54
+ message?: string;
55
+ };
56
+ errors?: string | Record<string, string[]>;
57
+ }
58
+ interface UserProfile {
59
+ id: string | number;
60
+ email: string;
61
+ username?: string;
62
+ firstName?: string;
63
+ lastName?: string;
64
+ fullName?: string;
65
+ avatar?: string;
66
+ role?: string;
67
+ permissions?: string[];
68
+ lastLogin?: string;
69
+ isActive?: boolean;
70
+ createdAt?: string;
71
+ updatedAt?: string;
72
+ [key: string]: unknown;
73
+ }
74
+ interface LoginResponse {
75
+ token: string;
76
+ user?: UserProfile;
77
+ expiresIn?: number;
78
+ refreshToken?: string;
79
+ }
80
+ interface LoginRequest {
81
+ identifier: string;
82
+ password: string;
83
+ }
84
+ interface ForgotPasswordRequest {
85
+ email: string;
86
+ }
87
+ interface ResetPasswordRequest {
88
+ email: string;
89
+ code: string;
90
+ newPassword: string;
91
+ }
92
+ interface ValidateCodeRequest {
93
+ email: string;
94
+ codePassword: string;
95
+ }
96
+ interface JwtPayload {
97
+ sub?: string;
98
+ email?: string;
99
+ username?: string;
100
+ iat?: number;
101
+ exp?: number;
102
+ iss?: string;
103
+ aud?: string;
104
+ [key: string]: unknown;
105
+ }
106
+ interface ApiError {
107
+ code: string;
108
+ message: string;
109
+ field?: string;
110
+ details?: Record<string, unknown>;
111
+ }
112
+ interface ValidationError {
113
+ field: string;
114
+ message: string;
115
+ code: string;
116
+ }
117
+
38
118
  interface UseUserProfileOptions {
39
119
  autoFetch?: boolean;
40
120
  retryOnError?: boolean;
41
121
  maxRetries?: number;
42
122
  }
43
123
  interface UseUserProfileReturn {
44
- userProfile: any | null;
124
+ userProfile: UserProfile | null;
45
125
  loading: boolean;
46
126
  error: string | null;
47
127
  refreshProfile: () => Promise<void>;
@@ -54,21 +134,16 @@ interface UseCrudifyLoginOptions {
54
134
  showSuccessNotifications?: boolean;
55
135
  }
56
136
  declare const useCrudifyLogin: (config: CrudifyLoginConfig, _options?: UseCrudifyLoginOptions) => {
57
- crudify: {
58
- login: (identifier: string, password: string) => Promise<_nocios_crudify_browser.CrudifyResponse>;
59
- transaction: (data: any, options?: any) => Promise<_nocios_crudify_browser.CrudifyResponse>;
60
- } | null;
137
+ config: {
138
+ publicApiKey: string | null;
139
+ env: "dev" | "stg" | "prod";
140
+ appName: string;
141
+ loginActions: string[];
142
+ };
61
143
  };
62
144
 
63
- interface JWTPayload {
64
- email?: string;
145
+ interface JWTPayload extends JwtPayload {
65
146
  "cognito:username"?: string;
66
- sub?: string;
67
- exp?: number;
68
- iat?: number;
69
- iss?: string;
70
- aud?: string;
71
- [key: string]: any;
72
147
  }
73
148
  declare const decodeJwtSafely: (token: string) => JWTPayload | null;
74
149
  declare const getCurrentUserEmail: () => string | null;
@@ -90,4 +165,57 @@ declare class SecureStorage {
90
165
  declare const secureSessionStorage: SecureStorage;
91
166
  declare const secureLocalStorage: SecureStorage;
92
167
 
93
- export { type BoxScreenType, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, decodeJwtSafely, getCookie, getCurrentUserEmail, isTokenExpired, secureLocalStorage, secureSessionStorage, useCrudifyLogin, useUserProfile };
168
+ declare const ERROR_CODES: {
169
+ readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
170
+ readonly UNAUTHORIZED: "UNAUTHORIZED";
171
+ readonly INVALID_API_KEY: "INVALID_API_KEY";
172
+ readonly USER_NOT_FOUND: "USER_NOT_FOUND";
173
+ readonly USER_NOT_ACTIVE: "USER_NOT_ACTIVE";
174
+ readonly NO_PERMISSION: "NO_PERMISSION";
175
+ readonly ITEM_NOT_FOUND: "ITEM_NOT_FOUND";
176
+ readonly NOT_FOUND: "NOT_FOUND";
177
+ readonly IN_USE: "IN_USE";
178
+ readonly FIELD_ERROR: "FIELD_ERROR";
179
+ readonly BAD_REQUEST: "BAD_REQUEST";
180
+ readonly INVALID_EMAIL: "INVALID_EMAIL";
181
+ readonly INVALID_CODE: "INVALID_CODE";
182
+ readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
183
+ readonly DATABASE_CONNECTION_ERROR: "DATABASE_CONNECTION_ERROR";
184
+ readonly INVALID_CONFIGURATION: "INVALID_CONFIGURATION";
185
+ readonly UNKNOWN_OPERATION: "UNKNOWN_OPERATION";
186
+ readonly TOO_MANY_REQUESTS: "TOO_MANY_REQUESTS";
187
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
188
+ readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
189
+ };
190
+ type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
191
+ type ErrorSeverity = 'info' | 'warning' | 'error' | 'critical';
192
+ declare const ERROR_SEVERITY_MAP: Record<ErrorCode, ErrorSeverity>;
193
+ interface ParsedError {
194
+ code: ErrorCode;
195
+ message: string;
196
+ severity: ErrorSeverity;
197
+ field?: string;
198
+ details?: Record<string, unknown>;
199
+ }
200
+ /**
201
+ * Parse a Crudify API response and extract standardized error information
202
+ */
203
+ declare function parseApiError(response: unknown): ParsedError[];
204
+ /**
205
+ * Parse transaction response errors
206
+ */
207
+ declare function parseTransactionError(response: unknown): ParsedError[];
208
+ /**
209
+ * Get a human-readable error message for an error code
210
+ */
211
+ declare function getErrorMessage(code: ErrorCode): string;
212
+ /**
213
+ * Handle JavaScript/Network errors and convert to ParsedError
214
+ */
215
+ declare function parseJavaScriptError(error: unknown): ParsedError;
216
+ /**
217
+ * Universal error handler that can process any type of error from Crudify APIs
218
+ */
219
+ declare function handleCrudifyError(error: unknown): ParsedError[];
220
+
221
+ export { type ApiError, type BoxScreenType, type CrudifyApiResponse, CrudifyLogin, type CrudifyLoginConfig, type CrudifyLoginProps, type CrudifyLoginTranslations, type CrudifyTransactionResponse, ERROR_CODES, ERROR_SEVERITY_MAP, type ErrorCode, type ErrorSeverity, type ForgotPasswordRequest, type JwtPayload, type LoginRequest, type LoginResponse, type ParsedError, type ResetPasswordRequest, type TransactionResponseData, type UserProfile, type ValidateCodeRequest, type ValidationError, decodeJwtSafely, getCookie, getCurrentUserEmail, getErrorMessage, handleCrudifyError, isTokenExpired, parseApiError, parseJavaScriptError, parseTransactionError, secureLocalStorage, secureSessionStorage, useCrudifyLogin, useUserProfile };