@mapnests/gateway-web-sdk 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +7 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -43,7 +43,7 @@ This setup covers bootstrap on app start and three API patterns:
43
43
  import React from 'react';
44
44
  import ReactDOM from 'react-dom/client';
45
45
  import { SessionManager } from 'gateway-web-sdk';
46
- import { API_BASE_URL, BOOTSTRAP_PATH, TOKEN_COOKIE_NAME, REFRESH_INTERVAL, TOKEN_EXPIRY, CREDENTIALS } from './config.js';
46
+ import { API_BASE_URL, BOOTSTRAP_PATH, TOKEN_COOKIE_NAME } from './config.js';
47
47
  import App from './App';
48
48
 
49
49
  const sessionManager = SessionManager.getInstance();
@@ -51,9 +51,6 @@ try {
51
51
  sessionManager.configure({
52
52
  bootstrapUrl: `${API_BASE_URL}${BOOTSTRAP_PATH}`,
53
53
  tokenCookieName: TOKEN_COOKIE_NAME,
54
- refreshInterval: (REFRESH_INTERVAL ? parseInt(REFRESH_INTERVAL) : 25) * 60 * 1000,
55
- tokenExpiry: (TOKEN_EXPIRY ? parseInt(TOKEN_EXPIRY) : 30) * 60 * 1000,
56
- credentials: CREDENTIALS === 'true',
57
54
  });
58
55
  } catch (error) {
59
56
  console.error('Failed to configure session manager:', error);
@@ -222,12 +219,9 @@ import App from './App';
222
219
  const sessionManager = SessionManager.getInstance();
223
220
  sessionManager.configure({
224
221
  bootstrapUrl: 'https://your-api.com/session/bootstrap',
225
- refreshInterval: 25 * 60 * 1000, // 25 minutes
226
- tokenExpiry: 30 * 60 * 1000, // 30 minutes
227
222
  headers: {
228
223
  'X-Custom-Header': 'value',
229
224
  },
230
- credentials: true, // Include cookies in requests
231
225
  });
232
226
 
233
227
  ReactDOM.createRoot(document.getElementById('root')).render(
@@ -252,7 +246,6 @@ export default function RootLayout({ children }) {
252
246
  const sessionManager = SessionManager.getInstance();
253
247
  sessionManager.configure({
254
248
  bootstrapUrl: '/api/session/bootstrap',
255
- refreshInterval: 25 * 60 * 1000,
256
249
  });
257
250
 
258
251
  sessionManager.initialize();
@@ -277,7 +270,6 @@ function MyApp({ Component, pageProps }) {
277
270
  const sessionManager = SessionManager.getInstance();
278
271
  sessionManager.configure({
279
272
  bootstrapUrl: '/api/session/bootstrap',
280
- refreshInterval: 25 * 60 * 1000,
281
273
  });
282
274
 
283
275
  sessionManager.initialize();
@@ -330,14 +322,14 @@ Configure the session manager.
330
322
  sessionManager.configure({
331
323
  bootstrapUrl: '/session/bootstrap', // Required: Bootstrap API endpoint
332
324
  tokenCookieName: 'stoken', // Optional: Custom token cookie name
333
- refreshInterval: 25 * 60 * 1000, // Optional: Refresh interval (ms)
334
- tokenExpiry: 30 * 60 * 1000, // Optional: Token expiry (ms)
335
325
  maxRetries: 3, // Optional: Max retry attempts
336
326
  headers: {}, // Optional: Additional headers
337
- credentials: true, // Optional: Include credentials
327
+ credentials: true, // Optional: Include credentials (default: true)
338
328
  });
339
329
  ```
340
330
 
331
+ Note: `refreshInterval` and `tokenExpiry` are automatically set by the server's bootstrap response (`refresh_time` and `expire` fields). You don't need to configure them manually.
332
+
341
333
  ##### `initialize()`
342
334
 
343
335
  Initialize session by calling bootstrap API.
@@ -413,10 +405,10 @@ const api = setupAxiosInterceptor(axios.create({
413
405
  ## Client-Side Best Practices
414
406
 
415
407
  1. Single Instance: Call configure() once at app startup and reuse the singleton.
416
- 2. Token Timing: Set refreshInterval about 5 minutes before tokenExpiry to avoid race conditions.
408
+ 2. Token Timing: The server controls refresh and expiry timing via bootstrap response.
417
409
  3. Error Handling: Handle errors and provide user feedback for limited mode.
418
410
  4. HTTPS: Use secure, production-grade origins (https) in production environments.
419
- 5. CORS/Credentials: If cross-origin, ensure credentials are enabled in client config and server CORS.
411
+ 5. CORS/Credentials: If cross-origin, ensure credentials are enabled in server CORS (SDK defaults to credentials: true).
420
412
  6. Initialization: Initialize after configure() and before issuing business API calls.
421
413
 
422
414
  ## Troubleshooting
@@ -430,7 +422,7 @@ const api = setupAxiosInterceptor(axios.create({
430
422
  ### Automatic refresh not working
431
423
 
432
424
  - Check browser console for errors
433
- - Verify `refreshInterval` is set correctly
425
+ - Verify server is sending `refresh_time` in bootstrap response
434
426
  - Ensure timer isn't being cleared prematurely
435
427
 
436
428
  ### Multiple initializations
@@ -454,7 +446,6 @@ import type { SessionConfig, SessionState, UseSessionOptions } from 'gateway-web
454
446
 
455
447
  const config: SessionConfig = {
456
448
  bootstrapUrl: '/api/session',
457
- refreshInterval: 25 * 60 * 1000
458
449
  };
459
450
 
460
451
  const manager = SessionManager.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapnests/gateway-web-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Session token management SDK with automatic refresh for React/Next.js applications",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",