@plyaz/types 1.11.1 → 1.11.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.
- package/dist/core/services.d.ts +54 -5
- package/package.json +1 -1
package/dist/core/services.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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:
|
|
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
|
*
|
package/package.json
CHANGED