@iqauth/sdk 2.6.3 → 2.7.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 (112) hide show
  1. package/README.md +173 -1
  2. package/dist/browser-session.d.mts +4 -4
  3. package/dist/browser-session.d.ts +4 -4
  4. package/dist/browser-session.js +181 -41
  5. package/dist/browser-session.mjs +3 -3
  6. package/dist/browser.d.mts +5 -5
  7. package/dist/browser.d.ts +5 -5
  8. package/dist/browser.js +271 -32
  9. package/dist/browser.mjs +10 -8
  10. package/dist/{chunk-6I6RM4MN.mjs → chunk-6PJRLRB4.mjs} +33 -3
  11. package/dist/chunk-C2ZTBOAC.mjs +36 -0
  12. package/dist/{chunk-LIZYFXH7.mjs → chunk-DFWHSDYQ.mjs} +1 -1
  13. package/dist/chunk-GLXSIGVS.mjs +66 -0
  14. package/dist/{chunk-TKZTCPEK.mjs → chunk-GN37E64I.mjs} +32 -40
  15. package/dist/{chunk-WQWBJSSS.mjs → chunk-HVHNYPDC.mjs} +6 -6
  16. package/dist/{chunk-W3F4JYGP.mjs → chunk-JXQI62A7.mjs} +108 -18
  17. package/dist/{chunk-UNYDG2L4.mjs → chunk-NUO2I65G.mjs} +56 -23
  18. package/dist/chunk-PMAFENVI.mjs +229 -0
  19. package/dist/chunk-RR2MGPTK.mjs +2724 -0
  20. package/dist/{chunk-76W5TLQQ.mjs → chunk-RTJAIBXY.mjs} +220 -20
  21. package/dist/{chunk-6TDJJER7.mjs → chunk-RUJXRTEW.mjs} +164 -5
  22. package/dist/{chunk-3JULWS6F.mjs → chunk-WCELYTJ3.mjs} +3 -3
  23. package/dist/{chunk-MKKZULZR.mjs → chunk-WIFG74IK.mjs} +1 -1
  24. package/dist/{chunk-BVV54LPI.mjs → chunk-YVALAG3B.mjs} +10 -4
  25. package/dist/cli/index.js +2 -2
  26. package/dist/cli/index.mjs +2 -2
  27. package/dist/{client-kYlJFgPv.d.mts → client-BGFnBpfc.d.mts} +47 -4
  28. package/dist/{client-BNQe3AgF.d.ts → client-CDQ21LvW.d.ts} +47 -4
  29. package/dist/{doctor-YYNHNMLD.mjs → doctor-JAFXWU3X.mjs} +2 -2
  30. package/dist/errors-Jl1Jtm-6.d.mts +107 -0
  31. package/dist/errors-Jl1Jtm-6.d.ts +107 -0
  32. package/dist/{express-B6_1vBYZ.d.mts → express-CVNQEkOr.d.mts} +2 -2
  33. package/dist/{express-CHpfa7D_.d.ts → express-Piv2WhWM.d.ts} +2 -2
  34. package/dist/express.d.mts +7 -6
  35. package/dist/express.d.ts +7 -6
  36. package/dist/express.js +349 -52
  37. package/dist/express.mjs +39 -12
  38. package/dist/fastify.d.mts +2 -0
  39. package/dist/fastify.d.ts +2 -0
  40. package/dist/fastify.js +332 -52
  41. package/dist/fastify.mjs +23 -8
  42. package/dist/hono.d.mts +2 -0
  43. package/dist/hono.d.ts +2 -0
  44. package/dist/hono.js +329 -52
  45. package/dist/hono.mjs +20 -8
  46. package/dist/index-5KSZEnDe.d.ts +1626 -0
  47. package/dist/index-CKoZHAoc.d.mts +1626 -0
  48. package/dist/index.d.mts +56 -8
  49. package/dist/index.d.ts +56 -8
  50. package/dist/index.js +565 -69
  51. package/dist/index.mjs +29 -9
  52. package/dist/{keys-NLWFAOEM.mjs → keys-6Y776TG2.mjs} +2 -2
  53. package/dist/locales.d.mts +1 -1
  54. package/dist/locales.d.ts +1 -1
  55. package/dist/mobile.d.mts +77 -7
  56. package/dist/mobile.d.ts +77 -7
  57. package/dist/mobile.js +276 -41
  58. package/dist/mobile.mjs +98 -3
  59. package/dist/next.d.mts +2 -1
  60. package/dist/next.d.ts +2 -1
  61. package/dist/next.js +391 -201
  62. package/dist/next.mjs +22 -7
  63. package/dist/pkce-7WKV4OIN.mjs +11 -0
  64. package/dist/{provisioningBridge-DnTfzdZK.d.ts → provisioningBridge-CGpMRie4.d.ts} +1 -1
  65. package/dist/{provisioningBridge-88xjOS2n.d.mts → provisioningBridge-M5G47LWO.d.mts} +1 -1
  66. package/dist/{publishableKey-BaR0HoAH.d.ts → publishableKey-f2kq-rKw.d.mts} +1 -1
  67. package/dist/{publishableKey-BaR0HoAH.d.mts → publishableKey-f2kq-rKw.d.ts} +1 -1
  68. package/dist/react-permissions.d.mts +52 -0
  69. package/dist/react-permissions.d.ts +52 -0
  70. package/dist/react-permissions.js +239 -0
  71. package/dist/react-permissions.mjs +97 -0
  72. package/dist/react.d.mts +9 -1624
  73. package/dist/react.d.ts +9 -1624
  74. package/dist/react.js +343 -36
  75. package/dist/react.mjs +59 -2611
  76. package/dist/{reverify-4UEJXUS6.mjs → reverify-C64QXKJO.mjs} +2 -2
  77. package/dist/server/handlers.d.mts +148 -3
  78. package/dist/server/handlers.d.ts +148 -3
  79. package/dist/server/handlers.js +410 -11
  80. package/dist/server/handlers.mjs +12 -3
  81. package/dist/server.d.mts +151 -8
  82. package/dist/server.d.ts +151 -8
  83. package/dist/server.js +406 -50
  84. package/dist/server.mjs +93 -11
  85. package/dist/service.d.mts +4 -4
  86. package/dist/service.d.ts +4 -4
  87. package/dist/service.js +181 -41
  88. package/dist/service.mjs +3 -3
  89. package/dist/{signIn-CiIBTJIh.d.mts → signIn-BLFnz8SV.d.ts} +78 -3
  90. package/dist/{signIn-CCY4JE5G.mjs → signIn-SHBW6Z4T.mjs} +2 -1
  91. package/dist/{signIn-OCr88Zf8.d.ts → signIn-T-CZ6t6r.d.mts} +78 -3
  92. package/dist/test.mjs +3 -3
  93. package/dist/{tokens-DCyzzn8L.d.mts → tokens-Bqhmqq_R.d.ts} +9 -2
  94. package/dist/{tokens-aHiGFr_E.d.ts → tokens-CITeoG6P.d.mts} +9 -2
  95. package/dist/{types-6bNdxesb.d.ts → types-BdQ2lqfT.d.mts} +1 -1
  96. package/dist/{types-6bNdxesb.d.mts → types-BdQ2lqfT.d.ts} +1 -1
  97. package/dist/{types-DZAflmmq.d.mts → types-XOV9XPVi.d.mts} +99 -10
  98. package/dist/{types-DZAflmmq.d.ts → types-XOV9XPVi.d.ts} +99 -10
  99. package/dist/webhooks.d.mts +100 -17
  100. package/dist/webhooks.d.ts +100 -17
  101. package/dist/webhooks.js +164 -15
  102. package/dist/webhooks.mjs +7 -1
  103. package/dist/ws.d.mts +2 -2
  104. package/dist/ws.d.ts +2 -2
  105. package/dist/ws.js +80 -30
  106. package/dist/ws.mjs +4 -4
  107. package/docs/error-handling.md +101 -0
  108. package/docs/guides/effective-permissions.md +171 -0
  109. package/package.json +13 -3
  110. package/dist/chunk-UKZLOHZG.mjs +0 -83
  111. package/dist/errors-CDdl24MP.d.mts +0 -52
  112. package/dist/errors-CDdl24MP.d.ts +0 -52
package/dist/index.mjs CHANGED
@@ -1,27 +1,38 @@
1
+ import {
2
+ expandPermissions,
3
+ hasPermission
4
+ } from "./chunk-GLXSIGVS.mjs";
1
5
  import {
2
6
  createProvisioningBridge
3
7
  } from "./chunk-SL3KRS4W.mjs";
4
8
  import {
5
9
  createTestIssuer
6
- } from "./chunk-MKKZULZR.mjs";
10
+ } from "./chunk-WIFG74IK.mjs";
7
11
  import {
12
+ IQAUTH_SIGNATURE_HEADER,
13
+ LEGACY_SIGNATURE_HEADERS,
8
14
  WebhookSignatureError,
9
15
  isValidWebhookSignature,
16
+ parseWebhookEvent,
10
17
  verifyWebhookSignature
11
- } from "./chunk-UKZLOHZG.mjs";
18
+ } from "./chunk-PMAFENVI.mjs";
12
19
  import {
13
20
  verifyWsUpgrade
14
- } from "./chunk-3JULWS6F.mjs";
21
+ } from "./chunk-WCELYTJ3.mjs";
15
22
  import {
16
23
  iqAuthMiddleware
17
- } from "./chunk-BVV54LPI.mjs";
24
+ } from "./chunk-YVALAG3B.mjs";
25
+ import {
26
+ buildUserinfoResponse,
27
+ handleUserinfo
28
+ } from "./chunk-RUJXRTEW.mjs";
18
29
  import {
19
30
  assertPublishableKey,
20
31
  encodePublishableKey,
21
32
  isPublishableKey,
22
33
  isSecretKey,
23
34
  parsePublishableKey
24
- } from "./chunk-WQWBJSSS.mjs";
35
+ } from "./chunk-HVHNYPDC.mjs";
25
36
  import {
26
37
  ApiKeysModule,
27
38
  AppsModule,
@@ -48,17 +59,18 @@ import {
48
59
  UsersModule,
49
60
  VendorsModule,
50
61
  WebhooksModule
51
- } from "./chunk-W3F4JYGP.mjs";
62
+ } from "./chunk-JXQI62A7.mjs";
52
63
  import {
53
64
  DEFAULT_CLOCK_TOLERANCE_SECONDS,
54
65
  DEFAULT_TOKEN_AUDIENCE,
55
66
  DEFAULT_TOKEN_ISSUER,
56
67
  TokensModule
57
- } from "./chunk-UNYDG2L4.mjs";
68
+ } from "./chunk-NUO2I65G.mjs";
58
69
  import {
59
70
  ErrorCodes,
60
- IQAuthError
61
- } from "./chunk-6I6RM4MN.mjs";
71
+ IQAuthError,
72
+ IQ_AUTH_ERROR_CODES
73
+ } from "./chunk-6PJRLRB4.mjs";
62
74
  import "./chunk-Y6FXYEAI.mjs";
63
75
  export {
64
76
  ApiKeysModule,
@@ -73,10 +85,13 @@ export {
73
85
  ErrorCodes,
74
86
  GdprModule,
75
87
  HierarchyModule,
88
+ IQAUTH_SIGNATURE_HEADER,
76
89
  IQAuthClient,
77
90
  IQAuthError,
91
+ IQ_AUTH_ERROR_CODES,
78
92
  InMemoryOidcStateStore,
79
93
  InvitesModule,
94
+ LEGACY_SIGNATURE_HEADERS,
80
95
  MembershipsModule,
81
96
  MfaModule,
82
97
  OidcModule,
@@ -94,14 +109,19 @@ export {
94
109
  WebhookSignatureError,
95
110
  WebhooksModule,
96
111
  assertPublishableKey,
112
+ buildUserinfoResponse,
97
113
  createProvisioningBridge,
98
114
  createTestIssuer,
99
115
  encodePublishableKey,
116
+ expandPermissions,
117
+ handleUserinfo,
118
+ hasPermission,
100
119
  iqAuthMiddleware,
101
120
  isPublishableKey,
102
121
  isSecretKey,
103
122
  isValidWebhookSignature,
104
123
  parsePublishableKey,
124
+ parseWebhookEvent,
105
125
  verifyWebhookSignature,
106
126
  verifyWsUpgrade
107
127
  };
@@ -10,10 +10,10 @@ async function getCtx(flags) {
10
10
  const env = await loadEnv(flags.get("env-file") || ".env");
11
11
  const baseUrl = flags.get("base-url") || env.IQAUTH_ISSUER;
12
12
  const token = flags.get("token") || env.IQAUTH_ADMIN_TOKEN || env.IQAUTH_SECRET_KEY;
13
- const app = flags.get("app") || env.IQAUTH_APP_ID || env.IQAUTH_APP_KEY;
13
+ const app = flags.get("app") || env.IQAUTH_APP_ID;
14
14
  if (!baseUrl) throw new Error("Missing --base-url (or IQAUTH_ISSUER in env).");
15
15
  if (!token) throw new Error("Missing --token (or IQAUTH_ADMIN_TOKEN / IQAUTH_SECRET_KEY in env).");
16
- if (!app) throw new Error("Missing --app <appId|appKey> (or IQAUTH_APP_ID in env).");
16
+ if (!app) throw new Error("Missing --app <appId> (or IQAUTH_APP_ID in env). The `IQAUTH_APP_KEY` env-var fallback has been removed (Task #130) \u2014 pass --app explicitly.");
17
17
  return { baseUrl, token, app };
18
18
  }
19
19
  async function runKeys(argv) {
@@ -1,4 +1,4 @@
1
- import { I as IQAuthLocaleBundle, a as IQAuthLocaleOverride, b as IQAuthLocaleKey } from './types-6bNdxesb.mjs';
1
+ import { I as IQAuthLocaleBundle, b as IQAuthLocaleOverride, a as IQAuthLocaleKey } from './types-BdQ2lqfT.mjs';
2
2
 
3
3
  declare const enUS: IQAuthLocaleBundle;
4
4
 
package/dist/locales.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as IQAuthLocaleBundle, a as IQAuthLocaleOverride, b as IQAuthLocaleKey } from './types-6bNdxesb.js';
1
+ import { I as IQAuthLocaleBundle, b as IQAuthLocaleOverride, a as IQAuthLocaleKey } from './types-BdQ2lqfT.js';
2
2
 
3
3
  declare const enUS: IQAuthLocaleBundle;
4
4
 
package/dist/mobile.d.mts CHANGED
@@ -1,11 +1,81 @@
1
- import { I as IQAuthClient } from './client-kYlJFgPv.mjs';
2
- import { b as IQAuthTokenClientConfig } from './types-DZAflmmq.mjs';
3
- export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
4
- import './tokens-DCyzzn8L.mjs';
1
+ import { I as IQAuthClient } from './client-BGFnBpfc.mjs';
2
+ import { f as IQAuthTokenClientConfig } from './types-XOV9XPVi.mjs';
3
+ export { E as ErrorCodes, I as IQAuthError } from './errors-Jl1Jtm-6.mjs';
4
+ import './tokens-CITeoG6P.mjs';
5
5
 
6
+ /**
7
+ * Mobile client — wraps IQAuthClient with React Native / Expo–aware behavior.
8
+ *
9
+ * Notable mode: `autoRefresh: 'app-state'`
10
+ * The default per-request "expiring soon" proactive refresh fights with
11
+ * Expo / React Native's app-suspension lifecycle (the JS engine pauses in
12
+ * background, fetch in-flight when the OS suspends the app fails on resume,
13
+ * and the resulting cascade of refresh attempts can blow up with
14
+ * `Network request failed` rather than recovering cleanly).
15
+ *
16
+ * In `'app-state'` mode the SDK:
17
+ * - DISABLES the per-request proactive refresh.
18
+ * - KEEPS the reactive 401 retry on TOKEN_EXPIRED (one attempt).
19
+ * - SUBSCRIBES to `AppState.addEventListener('change', ...)` and triggers
20
+ * a refresh when the app transitions back to `'active'` from background
21
+ * or inactive — but only if a refresh token exists and the access token
22
+ * is within 5 minutes of expiry (or already expired).
23
+ *
24
+ * The AppState listener is started automatically when `'app-state'` mode is
25
+ * selected and react-native is resolvable. Call `client.stop()` to remove
26
+ * the subscription (e.g. in a unit test or on logout).
27
+ */
28
+
29
+ type AppStateStatus = "active" | "background" | "inactive" | string;
30
+ interface AppStateLike {
31
+ currentState: AppStateStatus;
32
+ addEventListener(type: "change", handler: (state: AppStateStatus) => void): {
33
+ remove: () => void;
34
+ } | (() => void) | void;
35
+ removeEventListener?: (type: "change", handler: (state: AppStateStatus) => void) => void;
36
+ }
37
+ interface MobileClientOptions extends IQAuthTokenClientConfig {
38
+ /**
39
+ * Override how AppState is resolved. Defaults to a runtime
40
+ * `require('react-native').AppState`. Tests inject a fake here.
41
+ */
42
+ appState?: AppStateLike | null;
43
+ /**
44
+ * Seconds-of-life-remaining threshold below which a foreground transition
45
+ * triggers a refresh. Default 300 (5 min).
46
+ */
47
+ appStateRefreshLeewaySeconds?: number;
48
+ /**
49
+ * Optional hook invoked when an AppState-triggered refresh fails. The
50
+ * default behavior is to swallow the error so the host app doesn't crash
51
+ * on a foreground tick — the next API call's reactive 401 path will
52
+ * surface the same error to the caller. Use this hook for telemetry.
53
+ */
54
+ onAppStateRefreshError?: (err: unknown) => void;
55
+ }
6
56
  declare class MobileIQAuthClient extends IQAuthClient {
7
- constructor(config: IQAuthTokenClientConfig);
57
+ private appStateSub;
58
+ private appStateMode;
59
+ private leewaySeconds;
60
+ private lastAppState;
61
+ private refreshing;
62
+ private onTokenRefreshCb?;
63
+ private onAppStateRefreshError?;
64
+ constructor(config: MobileClientOptions);
65
+ /** True iff the client is configured for AppState-driven refresh. */
66
+ get isAppStateMode(): boolean;
67
+ private startAppStateListener;
68
+ /**
69
+ * Public hook: call this from your own AppState handler if you've passed
70
+ * `appState: null` to opt out of the auto-subscription. Returns true if a
71
+ * refresh was attempted.
72
+ */
73
+ refreshIfStale(): Promise<boolean>;
74
+ private maybeRefreshOnForeground;
75
+ private isAccessTokenStale;
76
+ /** Remove the AppState subscription. Idempotent. */
77
+ stop(): void;
8
78
  }
9
- declare function createMobileClient(config: IQAuthTokenClientConfig): MobileIQAuthClient;
79
+ declare function createMobileClient(config: MobileClientOptions): MobileIQAuthClient;
10
80
 
11
- export { IQAuthClient, IQAuthTokenClientConfig, MobileIQAuthClient, createMobileClient };
81
+ export { IQAuthClient, IQAuthTokenClientConfig, type MobileClientOptions, MobileIQAuthClient, createMobileClient };
package/dist/mobile.d.ts CHANGED
@@ -1,11 +1,81 @@
1
- import { I as IQAuthClient } from './client-BNQe3AgF.js';
2
- import { b as IQAuthTokenClientConfig } from './types-DZAflmmq.js';
3
- export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
4
- import './tokens-aHiGFr_E.js';
1
+ import { I as IQAuthClient } from './client-CDQ21LvW.js';
2
+ import { f as IQAuthTokenClientConfig } from './types-XOV9XPVi.js';
3
+ export { E as ErrorCodes, I as IQAuthError } from './errors-Jl1Jtm-6.js';
4
+ import './tokens-Bqhmqq_R.js';
5
5
 
6
+ /**
7
+ * Mobile client — wraps IQAuthClient with React Native / Expo–aware behavior.
8
+ *
9
+ * Notable mode: `autoRefresh: 'app-state'`
10
+ * The default per-request "expiring soon" proactive refresh fights with
11
+ * Expo / React Native's app-suspension lifecycle (the JS engine pauses in
12
+ * background, fetch in-flight when the OS suspends the app fails on resume,
13
+ * and the resulting cascade of refresh attempts can blow up with
14
+ * `Network request failed` rather than recovering cleanly).
15
+ *
16
+ * In `'app-state'` mode the SDK:
17
+ * - DISABLES the per-request proactive refresh.
18
+ * - KEEPS the reactive 401 retry on TOKEN_EXPIRED (one attempt).
19
+ * - SUBSCRIBES to `AppState.addEventListener('change', ...)` and triggers
20
+ * a refresh when the app transitions back to `'active'` from background
21
+ * or inactive — but only if a refresh token exists and the access token
22
+ * is within 5 minutes of expiry (or already expired).
23
+ *
24
+ * The AppState listener is started automatically when `'app-state'` mode is
25
+ * selected and react-native is resolvable. Call `client.stop()` to remove
26
+ * the subscription (e.g. in a unit test or on logout).
27
+ */
28
+
29
+ type AppStateStatus = "active" | "background" | "inactive" | string;
30
+ interface AppStateLike {
31
+ currentState: AppStateStatus;
32
+ addEventListener(type: "change", handler: (state: AppStateStatus) => void): {
33
+ remove: () => void;
34
+ } | (() => void) | void;
35
+ removeEventListener?: (type: "change", handler: (state: AppStateStatus) => void) => void;
36
+ }
37
+ interface MobileClientOptions extends IQAuthTokenClientConfig {
38
+ /**
39
+ * Override how AppState is resolved. Defaults to a runtime
40
+ * `require('react-native').AppState`. Tests inject a fake here.
41
+ */
42
+ appState?: AppStateLike | null;
43
+ /**
44
+ * Seconds-of-life-remaining threshold below which a foreground transition
45
+ * triggers a refresh. Default 300 (5 min).
46
+ */
47
+ appStateRefreshLeewaySeconds?: number;
48
+ /**
49
+ * Optional hook invoked when an AppState-triggered refresh fails. The
50
+ * default behavior is to swallow the error so the host app doesn't crash
51
+ * on a foreground tick — the next API call's reactive 401 path will
52
+ * surface the same error to the caller. Use this hook for telemetry.
53
+ */
54
+ onAppStateRefreshError?: (err: unknown) => void;
55
+ }
6
56
  declare class MobileIQAuthClient extends IQAuthClient {
7
- constructor(config: IQAuthTokenClientConfig);
57
+ private appStateSub;
58
+ private appStateMode;
59
+ private leewaySeconds;
60
+ private lastAppState;
61
+ private refreshing;
62
+ private onTokenRefreshCb?;
63
+ private onAppStateRefreshError?;
64
+ constructor(config: MobileClientOptions);
65
+ /** True iff the client is configured for AppState-driven refresh. */
66
+ get isAppStateMode(): boolean;
67
+ private startAppStateListener;
68
+ /**
69
+ * Public hook: call this from your own AppState handler if you've passed
70
+ * `appState: null` to opt out of the auto-subscription. Returns true if a
71
+ * refresh was attempted.
72
+ */
73
+ refreshIfStale(): Promise<boolean>;
74
+ private maybeRefreshOnForeground;
75
+ private isAccessTokenStale;
76
+ /** Remove the AppState subscription. Idempotent. */
77
+ stop(): void;
8
78
  }
9
- declare function createMobileClient(config: IQAuthTokenClientConfig): MobileIQAuthClient;
79
+ declare function createMobileClient(config: MobileClientOptions): MobileIQAuthClient;
10
80
 
11
- export { IQAuthClient, IQAuthTokenClientConfig, MobileIQAuthClient, createMobileClient };
81
+ export { IQAuthClient, IQAuthTokenClientConfig, type MobileClientOptions, MobileIQAuthClient, createMobileClient };