@passflow/core 0.20.0 → 0.21.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.
Files changed (129) hide show
  1. package/README.md +54 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +6362 -0
  5. package/dist/index.d.ts +6362 -0
  6. package/dist/index.mjs +2644 -880
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +15 -7
  9. package/dist/lib/api/app.d.ts +0 -11
  10. package/dist/lib/api/app.d.ts.map +0 -1
  11. package/dist/lib/api/auth.d.ts +0 -42
  12. package/dist/lib/api/auth.d.ts.map +0 -1
  13. package/dist/lib/api/axios-client.d.ts +0 -109
  14. package/dist/lib/api/axios-client.d.ts.map +0 -1
  15. package/dist/lib/api/cli-auth.d.ts +0 -12
  16. package/dist/lib/api/cli-auth.d.ts.map +0 -1
  17. package/dist/lib/api/index.d.ts +0 -11
  18. package/dist/lib/api/index.d.ts.map +0 -1
  19. package/dist/lib/api/invitation.d.ts +0 -80
  20. package/dist/lib/api/invitation.d.ts.map +0 -1
  21. package/dist/lib/api/model.d.ts +0 -844
  22. package/dist/lib/api/model.d.ts.map +0 -1
  23. package/dist/lib/api/setting.d.ts +0 -13
  24. package/dist/lib/api/setting.d.ts.map +0 -1
  25. package/dist/lib/api/tenant.d.ts +0 -216
  26. package/dist/lib/api/tenant.d.ts.map +0 -1
  27. package/dist/lib/api/two-factor.d.ts +0 -137
  28. package/dist/lib/api/two-factor.d.ts.map +0 -1
  29. package/dist/lib/api/upgrade.d.ts +0 -39
  30. package/dist/lib/api/upgrade.d.ts.map +0 -1
  31. package/dist/lib/api/user.d.ts +0 -22
  32. package/dist/lib/api/user.d.ts.map +0 -1
  33. package/dist/lib/constants/index.d.ts +0 -33
  34. package/dist/lib/constants/index.d.ts.map +0 -1
  35. package/dist/lib/device/index.d.ts +0 -17
  36. package/dist/lib/device/index.d.ts.map +0 -1
  37. package/dist/lib/index.d.ts +0 -22
  38. package/dist/lib/index.d.ts.map +0 -1
  39. package/dist/lib/interceptors/fetch-registry.d.ts +0 -96
  40. package/dist/lib/interceptors/fetch-registry.d.ts.map +0 -1
  41. package/dist/lib/m2m/client.d.ts +0 -196
  42. package/dist/lib/m2m/client.d.ts.map +0 -1
  43. package/dist/lib/m2m/errors.d.ts +0 -107
  44. package/dist/lib/m2m/errors.d.ts.map +0 -1
  45. package/dist/lib/m2m/index.d.ts +0 -27
  46. package/dist/lib/m2m/index.d.ts.map +0 -1
  47. package/dist/lib/m2m/types.d.ts +0 -217
  48. package/dist/lib/m2m/types.d.ts.map +0 -1
  49. package/dist/lib/passflow.d.ts +0 -1224
  50. package/dist/lib/passflow.d.ts.map +0 -1
  51. package/dist/lib/pkce.d.ts +0 -13
  52. package/dist/lib/pkce.d.ts.map +0 -1
  53. package/dist/lib/platform/index.d.ts +0 -4
  54. package/dist/lib/platform/index.d.ts.map +0 -1
  55. package/dist/lib/platform/types.d.ts +0 -206
  56. package/dist/lib/platform/types.d.ts.map +0 -1
  57. package/dist/lib/platform/web-adapter.d.ts +0 -104
  58. package/dist/lib/platform/web-adapter.d.ts.map +0 -1
  59. package/dist/lib/services/auth-service.d.ts +0 -197
  60. package/dist/lib/services/auth-service.d.ts.map +0 -1
  61. package/dist/lib/services/index.d.ts +0 -8
  62. package/dist/lib/services/index.d.ts.map +0 -1
  63. package/dist/lib/services/invitation-service.d.ts +0 -44
  64. package/dist/lib/services/invitation-service.d.ts.map +0 -1
  65. package/dist/lib/services/logger.d.ts +0 -24
  66. package/dist/lib/services/logger.d.ts.map +0 -1
  67. package/dist/lib/services/tenant-service.d.ts +0 -200
  68. package/dist/lib/services/tenant-service.d.ts.map +0 -1
  69. package/dist/lib/services/tenant-user-membership.d.ts +0 -76
  70. package/dist/lib/services/tenant-user-membership.d.ts.map +0 -1
  71. package/dist/lib/services/token-cache-service.d.ts +0 -36
  72. package/dist/lib/services/token-cache-service.d.ts.map +0 -1
  73. package/dist/lib/services/two-factor-service.d.ts +0 -193
  74. package/dist/lib/services/two-factor-service.d.ts.map +0 -1
  75. package/dist/lib/services/user-service.d.ts +0 -41
  76. package/dist/lib/services/user-service.d.ts.map +0 -1
  77. package/dist/lib/storage/index.d.ts +0 -106
  78. package/dist/lib/storage/index.d.ts.map +0 -1
  79. package/dist/lib/store.d.ts +0 -175
  80. package/dist/lib/store.d.ts.map +0 -1
  81. package/dist/lib/token/delivery-manager.d.ts +0 -121
  82. package/dist/lib/token/delivery-manager.d.ts.map +0 -1
  83. package/dist/lib/token/index.d.ts +0 -4
  84. package/dist/lib/token/index.d.ts.map +0 -1
  85. package/dist/lib/token/membership.d.ts +0 -37
  86. package/dist/lib/token/membership.d.ts.map +0 -1
  87. package/dist/lib/token/service.d.ts +0 -47
  88. package/dist/lib/token/service.d.ts.map +0 -1
  89. package/dist/lib/token/token.d.ts +0 -55
  90. package/dist/lib/token/token.d.ts.map +0 -1
  91. package/dist/lib/types/index.d.ts +0 -24
  92. package/dist/lib/types/index.d.ts.map +0 -1
  93. package/dist/lib/upgrade/acr.d.ts +0 -85
  94. package/dist/lib/upgrade/acr.d.ts.map +0 -1
  95. package/dist/lib/upgrade/axios-adapter.d.ts +0 -81
  96. package/dist/lib/upgrade/axios-adapter.d.ts.map +0 -1
  97. package/dist/lib/upgrade/challenge.d.ts +0 -217
  98. package/dist/lib/upgrade/challenge.d.ts.map +0 -1
  99. package/dist/lib/upgrade/client.d.ts +0 -29
  100. package/dist/lib/upgrade/client.d.ts.map +0 -1
  101. package/dist/lib/upgrade/controller.d.ts +0 -435
  102. package/dist/lib/upgrade/controller.d.ts.map +0 -1
  103. package/dist/lib/upgrade/core.d.ts +0 -353
  104. package/dist/lib/upgrade/core.d.ts.map +0 -1
  105. package/dist/lib/upgrade/errors.d.ts +0 -208
  106. package/dist/lib/upgrade/errors.d.ts.map +0 -1
  107. package/dist/lib/upgrade/facade.d.ts +0 -188
  108. package/dist/lib/upgrade/facade.d.ts.map +0 -1
  109. package/dist/lib/upgrade/factors.d.ts +0 -97
  110. package/dist/lib/upgrade/factors.d.ts.map +0 -1
  111. package/dist/lib/upgrade/fetch-adapter.d.ts +0 -30
  112. package/dist/lib/upgrade/fetch-adapter.d.ts.map +0 -1
  113. package/dist/lib/upgrade/index.d.ts +0 -17
  114. package/dist/lib/upgrade/index.d.ts.map +0 -1
  115. package/dist/lib/upgrade/markers.d.ts +0 -64
  116. package/dist/lib/upgrade/markers.d.ts.map +0 -1
  117. package/dist/lib/upgrade/replay.d.ts +0 -132
  118. package/dist/lib/upgrade/replay.d.ts.map +0 -1
  119. package/dist/lib/upgrade/select.d.ts +0 -48
  120. package/dist/lib/upgrade/select.d.ts.map +0 -1
  121. package/dist/lib/upgrade/session.d.ts +0 -72
  122. package/dist/lib/upgrade/session.d.ts.map +0 -1
  123. package/dist/lib/upgrade/snapshot.d.ts +0 -196
  124. package/dist/lib/upgrade/snapshot.d.ts.map +0 -1
  125. package/dist/lib/upgrade/transport.d.ts +0 -69
  126. package/dist/lib/upgrade/transport.d.ts.map +0 -1
  127. package/dist/lib/utils/validation.d.ts +0 -54
  128. package/dist/lib/utils/validation.d.ts.map +0 -1
  129. package/dist/tsconfig.build.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -517,6 +517,52 @@ const handleRedirect = () => {
517
517
  };
518
518
  ```
519
519
 
520
+ ### Token refresh across tabs
521
+
522
+ Every refresh in a `Passflow` instance (`refreshToken()`, `getTokens(true)`,
523
+ `getTokensWithRefresh()`, the refresh before an SDK API call whose access token expires within
524
+ 30 s, and the step-up commit) goes through one refresh controller. In a browser it coordinates
525
+ with the other tabs of the origin, so the engine's one-time refresh tokens are never replayed:
526
+
527
+ - **One refresh per browser.** One tab refreshes under the Web Lock `passflow-refresh`; the others
528
+ adopt its tokens through the `BroadcastChannel` `passflow-auth` and send nothing.
529
+ - **Compare-and-set save.** An answer is saved only if storage still holds the token that was
530
+ sent; a late answer never rolls a newer token back.
531
+ - **Failures are classified.** Network errors, timeouts, 429 and 5xx keep the tokens and retry
532
+ on one shared schedule: 1, 3, 10, 30 s, then every 60 s, plus up to 20 % jitter, never sooner
533
+ than a `Retry-After`. Authentication failures end the session after `refreshStrikes` (default
534
+ 3). `error.token.blocked` (the token was already used by another tab) never signs anyone out.
535
+ - **Events.** `RefreshFailing` once when an outage starts, `RefreshRecovered` once when it ends,
536
+ `Refresh` with `source: 'refresh' | 'upgrade' | 'adopted'`, `SessionExpired` only for a real end,
537
+ and exactly one `SignOut` per sign-out in every tab of the user.
538
+
539
+ ```javascript
540
+ const passflow = new Passflow({
541
+ appId: "your-app-id",
542
+ refreshCoordination: "web-locks", // default; 'none' or a custom coordinator
543
+ refreshStrikes: 3, // default
544
+ });
545
+
546
+ passflow.subscribe({
547
+ onAuthChange: (event, payload) => {
548
+ if (event === "refresh:failing") showNotice("Reconnecting…"); // tokens are kept
549
+ if (event === "refresh:recovered") hideNotice();
550
+ if (event === "session:expired" || event === "signout") goToSignIn();
551
+ },
552
+ });
553
+
554
+ // On SPA teardown (never called by the SDK itself):
555
+ passflow.dispose();
556
+ ```
557
+
558
+ Without `navigator.locks` or `BroadcastChannel` each tab refreshes on its own, still with the
559
+ compare-and-set save, and the SDK writes one `[passflow]` warning at the first refresh. Cookie and
560
+ BFF modes use the same lock, schedule and strikes.
561
+
562
+ The full contract (options, exact event payloads and order, the classification table, the exact
563
+ retry schedule and what resets it, the wire protocol, fallback, cookie/BFF, and migration from
564
+ 0.20.1) is in [docs/token-refresh.md](docs/token-refresh.md).
565
+
520
566
  ## Tenant Management
521
567
 
522
568
  ```javascript
@@ -762,6 +808,8 @@ type PassflowConfig = {
762
808
  createTenantForNewUser?: boolean;
763
809
  parseQueryParams?: boolean;
764
810
  keyStoragePrefix?: string;
811
+ refreshCoordination?: "web-locks" | "none" | RefreshCoordinator; // see docs/token-refresh.md
812
+ refreshStrikes?: number;
765
813
  };
766
814
  ```
767
815
 
@@ -836,6 +884,12 @@ enum PassflowEvent {
836
884
  SignOut = "signout",
837
885
  Error = "error",
838
886
  Refresh = "refresh",
887
+ RefreshStart = "refresh:start",
888
+ RefreshFailing = "refresh:failing",
889
+ RefreshRecovered = "refresh:recovered",
890
+ SessionExpired = "session:expired",
891
+ TokenCacheExpired = "token-cache-expired",
892
+ // ...and the sign-in, 2FA and session events; see lib/store.ts
839
893
  }
840
894
  ```
841
895