@plyaz/types 1.11.1 → 1.11.3

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.
@@ -195,26 +195,75 @@ export interface ApiEnvironmentConfig {
195
195
  * - Success/error callbacks for integration with state management
196
196
  * - Singleton pattern - only initializes once per app lifecycle
197
197
  *
198
+ * **Important**:
199
+ * - Initialization runs ONCE on mount, regardless of prop changes
200
+ * - Config changes after mount are NOT supported (singleton pattern)
201
+ * - If you need to change config, use `ApiClientService.reinitialize()` manually
202
+ * - To avoid unnecessary re-renders, memoize `envConfig` and `apiConfig` in parent component
203
+ *
198
204
  * @example
199
205
  * ```tsx
200
206
  * // Basic usage in Next.js app layout
207
+ * // IMPORTANT: For client components, pass sensitive config from server-side props/actions
201
208
  * import { ApiProvider } from '@plyaz/core';
209
+ * import { useMemo } from 'react';
202
210
  *
203
211
  * export default function RootLayout({ children }) {
204
- * const envConfig = {
212
+ * // Memoize configs to prevent unnecessary re-renders
213
+ * const envConfig = useMemo(() => ({
205
214
  * env: process.env.NODE_ENV as 'production',
215
+ * // ✅ OK: API keys can be public (handled by API gateway)
206
216
  * apiKey: process.env.NEXT_PUBLIC_API_KEY,
217
+ * }), []);
218
+ *
219
+ * const apiConfig = useMemo(() => ({
220
+ * // ✅ OK: Public configuration
221
+ * baseURL: process.env.NEXT_PUBLIC_API_URL!,
222
+ * timeout: 30000,
223
+ * retry: { attempts: 3 },
224
+ * }), []);
225
+ *
226
+ * return (
227
+ * <ApiProvider envConfig={envConfig} apiConfig={apiConfig}>
228
+ * {children}
229
+ * </ApiProvider>
230
+ * );
231
+ * }
232
+ * ```
233
+ *
234
+ * @example
235
+ * ```tsx
236
+ * // Server-side initialization with encryption (Next.js Server Component)
237
+ * // Use this pattern when you need encryption keys or other sensitive config
238
+ * import { ApiProvider } from '@plyaz/core';
239
+ *
240
+ * export default async function RootLayout({ children }) {
241
+ * // Server-only: Get encryption key from server environment
242
+ * // ❌ NEVER use NEXT_PUBLIC_* for encryption keys!
243
+ * const encryptionKey = process.env.ENCRYPTION_KEY; // Server-only
244
+ *
245
+ * const envConfig = {
246
+ * env: process.env.NODE_ENV as 'production',
207
247
  * };
208
248
  *
209
249
  * const apiConfig = {
210
250
  * baseURL: process.env.NEXT_PUBLIC_API_URL!,
251
+ * // ✅ Correct encryption key shape
211
252
  * encryption: {
253
+ * enabled: true,
212
254
  * key: {
213
255
  * id: 'prod-key-v1',
214
- * key: process.env.NEXT_PUBLIC_ENCRYPTION_KEY!,
215
- * algorithm: 'AES-GCM',
216
- * format: 'raw'
217
- * }
256
+ * key: encryptionKey!, // From server environment
257
+ * algorithm: 'AES-GCM' as const,
258
+ * format: 'raw' as const,
259
+ * },
260
+ * // Optional: Specify fields to encrypt
261
+ * fields: [
262
+ * '*.email',
263
+ * '*.ssn',
264
+ * 'user.*.phone',
265
+ * 'payment.cardNumber',
266
+ * ],
218
267
  * },
219
268
  * };
220
269
  *
@@ -1,6 +1,7 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { WithStatusCode, WithErrorCode, WithMessage, WithCorrelationId, WithTimestamp, WithValidationError } from '../common/types';
3
3
  import type { ERRORS_CODES } from '@plyaz/config';
4
+ import type { ERROR_CATEGORY } from './enums';
4
5
  /**
5
6
  * Represents the structure of an error response returned by the application.
6
7
  * @template ErrorDetails - The type of the `errors` array, defaults to `ErrorDetailsList`.
@@ -69,7 +70,7 @@ export interface ValidationErrorResponse {
69
70
  }
70
71
  export interface BaseErrorResponse {
71
72
  /** Category of the error. */
72
- type: 'form' | 'auth' | 'server' | 'network' | 'runtime';
73
+ type: (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY];
73
74
  /** Human-readable error message. */
74
75
  message: string;
75
76
  /** ISO timestamp when the error occurred. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.11.1",
3
+ "version": "1.11.3",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",