@iqauth/sdk 2.0.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/LICENSE +21 -0
  2. package/README.md +287 -0
  3. package/dist/browser-session.d.mts +12 -0
  4. package/dist/browser-session.d.ts +12 -0
  5. package/dist/browser-session.js +1812 -0
  6. package/dist/browser-session.mjs +28 -0
  7. package/dist/browser.d.mts +46 -0
  8. package/dist/browser.d.ts +46 -0
  9. package/dist/browser.js +768 -0
  10. package/dist/browser.mjs +47 -0
  11. package/dist/chunk-5HF3OBNO.mjs +189 -0
  12. package/dist/chunk-5WFR6Y33.mjs +59 -0
  13. package/dist/chunk-6I6RM4MN.mjs +51 -0
  14. package/dist/chunk-73R6BEGO.mjs +176 -0
  15. package/dist/chunk-E46DKOVI.mjs +632 -0
  16. package/dist/chunk-JQWYIIIS.mjs +1740 -0
  17. package/dist/chunk-X3K3WOBR.mjs +64 -0
  18. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  19. package/dist/cli/index.d.mts +1 -0
  20. package/dist/cli/index.d.ts +1 -0
  21. package/dist/cli/index.js +581 -0
  22. package/dist/cli/index.mjs +57 -0
  23. package/dist/client-C1DXfB8Z.d.mts +911 -0
  24. package/dist/client-CggvJmmm.d.ts +911 -0
  25. package/dist/dev-FUTJZSWN.mjs +56 -0
  26. package/dist/doctor-OHJRZBBT.mjs +89 -0
  27. package/dist/errors-CDdl24MP.d.mts +52 -0
  28. package/dist/errors-CDdl24MP.d.ts +52 -0
  29. package/dist/express-BKAXB5Nl.d.ts +61 -0
  30. package/dist/express-CpfyYTmw.d.mts +61 -0
  31. package/dist/express.d.mts +45 -0
  32. package/dist/express.d.ts +45 -0
  33. package/dist/express.js +2252 -0
  34. package/dist/express.mjs +122 -0
  35. package/dist/fastify.d.mts +23 -0
  36. package/dist/fastify.d.ts +23 -0
  37. package/dist/fastify.js +2062 -0
  38. package/dist/fastify.mjs +118 -0
  39. package/dist/hono.d.mts +22 -0
  40. package/dist/hono.d.ts +22 -0
  41. package/dist/hono.js +2051 -0
  42. package/dist/hono.mjs +107 -0
  43. package/dist/index.d.mts +6 -0
  44. package/dist/index.d.ts +6 -0
  45. package/dist/index.js +2070 -0
  46. package/dist/index.mjs +83 -0
  47. package/dist/init-LLCSQGNL.mjs +198 -0
  48. package/dist/keys-NLWFAOEM.mjs +63 -0
  49. package/dist/mobile.d.mts +11 -0
  50. package/dist/mobile.d.ts +11 -0
  51. package/dist/mobile.js +1809 -0
  52. package/dist/mobile.mjs +25 -0
  53. package/dist/next.d.mts +37 -0
  54. package/dist/next.d.ts +37 -0
  55. package/dist/next.js +2078 -0
  56. package/dist/next.mjs +130 -0
  57. package/dist/publishableKey-B5DIK81A.d.mts +24 -0
  58. package/dist/publishableKey-B5DIK81A.d.ts +24 -0
  59. package/dist/react.d.mts +196 -0
  60. package/dist/react.d.ts +196 -0
  61. package/dist/react.js +1457 -0
  62. package/dist/react.mjs +787 -0
  63. package/dist/server/handlers.d.mts +96 -0
  64. package/dist/server/handlers.d.ts +96 -0
  65. package/dist/server/handlers.js +243 -0
  66. package/dist/server/handlers.mjs +14 -0
  67. package/dist/server.d.mts +14 -0
  68. package/dist/server.d.ts +14 -0
  69. package/dist/server.js +2195 -0
  70. package/dist/server.mjs +47 -0
  71. package/dist/service.d.mts +11 -0
  72. package/dist/service.d.ts +11 -0
  73. package/dist/service.js +1809 -0
  74. package/dist/service.mjs +25 -0
  75. package/dist/signIn-C8f6qVjD.d.mts +238 -0
  76. package/dist/signIn-Cy2lbEXb.d.ts +238 -0
  77. package/dist/types-Cxl3bQHt.d.mts +900 -0
  78. package/dist/types-Cxl3bQHt.d.ts +900 -0
  79. package/docs/APP_INTEGRATION_MATRIX.md +59 -0
  80. package/docs/BROWSER_SESSION_MIGRATION.md +69 -0
  81. package/docs/FRESH_IMPLEMENTATION_GUIDE.md +188 -0
  82. package/docs/TARBALL_RELEASE_WORKFLOW.md +98 -0
  83. package/docs/V1_TO_V2_UPGRADE_GUIDE.md +318 -0
  84. package/docs/guides/api-keys.md +130 -0
  85. package/docs/guides/app-registration.md +149 -0
  86. package/docs/guides/auth-flows.md +168 -0
  87. package/docs/guides/branding.md +160 -0
  88. package/docs/guides/entitlements.md +115 -0
  89. package/docs/guides/entity-hierarchy.md +200 -0
  90. package/docs/guides/error-handling.md +251 -0
  91. package/docs/guides/gdpr-compliance.md +123 -0
  92. package/docs/guides/invitations.md +143 -0
  93. package/docs/guides/mfa-enrollment.md +170 -0
  94. package/docs/guides/middleware-reference.md +205 -0
  95. package/docs/guides/mobile-native.md +110 -0
  96. package/docs/guides/roles-and-permissions.md +220 -0
  97. package/docs/guides/scoped-authorization.md +247 -0
  98. package/docs/guides/server-platform-integration.md +52 -0
  99. package/docs/guides/service-automation-integration.md +36 -0
  100. package/docs/guides/session-management.md +97 -0
  101. package/docs/guides/tenant-management.md +216 -0
  102. package/docs/guides/token-verification.md +178 -0
  103. package/docs/guides/user-management.md +184 -0
  104. package/docs/guides/webhooks.md +136 -0
  105. package/docs/integration-prompts/README.md +20 -0
  106. package/docs/integration-prompts/first-party-browser-app.md +29 -0
  107. package/docs/integration-prompts/install-from-tarball.md +41 -0
  108. package/docs/integration-prompts/migrate-from-local-packages-source.md +57 -0
  109. package/docs/integration-prompts/native-mobile-app.md +24 -0
  110. package/docs/integration-prompts/server-platform-app.md +20 -0
  111. package/docs/integration-prompts/service-automation-app.md +20 -0
  112. package/package.json +115 -0
@@ -0,0 +1,59 @@
1
+ # App Integration Matrix
2
+
3
+ Canonical integration matrix for applications adopting `@iqauth/sdk`.
4
+
5
+ Use this document before implementing or upgrading any app.
6
+
7
+ ## Environment Matrix
8
+
9
+ | App type | Runtime trust level | Auth model | SDK entry point | Credential owner | Required platform pattern |
10
+ | --- | --- | --- | --- | --- | --- |
11
+ | First-party browser admin or product app | Untrusted browser | Backend-managed cookie session | `@iqauth/sdk/browser-session` behind backend proxy | Backend only | `/auth/login`, `/auth/select-tenant`, `/auth/mfa/verify`, `/auth/refresh`, `/auth/logout`, `/auth/me` |
12
+ | Native mobile app | Secure mobile runtime | Authorization code + PKCE | `@iqauth/sdk/mobile` | Secure OS storage | PKCE, system browser, deep/universal links, Keychain/Keystore |
13
+ | Server platform app / resource server | Trusted backend | Bearer token verification and request-scoped auth | `@iqauth/sdk/server` | Server | Use `client.middleware()` by default |
14
+ | Service / automation worker | Trusted backend | API key or service credential | `@iqauth/sdk/service` | Service | Prefer API keys, not interactive user sessions |
15
+
16
+ ## Non-Negotiable Rules
17
+
18
+ ### First-party browser apps
19
+
20
+ - Do not store refresh tokens in `localStorage`, `sessionStorage`, or durable browser-readable state.
21
+ - Do not treat browser JavaScript as the system of record for session state.
22
+ - Restore auth through `/auth/me`.
23
+ - Let the backend own refresh, logout, and invalidation.
24
+
25
+ ### Mobile apps
26
+
27
+ - Use PKCE.
28
+ - Use secure OS-backed token storage only.
29
+ - Do not copy browser session patterns into mobile.
30
+
31
+ ### Server apps
32
+
33
+ - Use the provided middleware when accepting bearer tokens.
34
+ - Do not re-implement token verification unless the framework forces it.
35
+ - Keep token state request-scoped or service-scoped, not shared across unrelated users.
36
+
37
+ ### Service apps
38
+
39
+ - Prefer API keys.
40
+ - Avoid interactive login flows unless a product requirement explicitly demands it.
41
+
42
+ ## Required Deliverables Per App
43
+
44
+ Before an app is considered aligned, it should have:
45
+
46
+ - the correct SDK entry point for its environment
47
+ - the correct auth ownership model
48
+ - a documented session/refresh/logout strategy
49
+ - environment-specific tests or verification notes
50
+ - a migration note if it previously used browser-owned tokens
51
+
52
+ ## Recommended Companion Docs
53
+
54
+ - [Fresh Implementation Guide](./FRESH_IMPLEMENTATION_GUIDE.md)
55
+ - [Browser Session Migration Guide](./BROWSER_SESSION_MIGRATION.md)
56
+ - [Auth Flows](./guides/auth-flows.md)
57
+ - [Mobile / Native Guide](./guides/mobile-native.md)
58
+ - [Server Platform Integration](./guides/server-platform-integration.md)
59
+ - [Service Automation Integration](./guides/service-automation-integration.md)
@@ -0,0 +1,69 @@
1
+ # Browser Session Migration Guide
2
+
3
+ Use this guide when a first-party web app currently owns IQAuth tokens in browser code and needs to move to the supported session model.
4
+
5
+ ## Target Model
6
+
7
+ - browser talks to app backend
8
+ - app backend talks to IQAuth
9
+ - backend stores access and refresh tokens in `httpOnly` cookies
10
+ - browser restores session from `/auth/me`
11
+
12
+ ## Migration Checklist
13
+
14
+ ### 1. Stop durable browser token ownership
15
+
16
+ Remove any pattern that:
17
+
18
+ - stores refresh tokens in `localStorage`
19
+ - restores auth by reading JWTs from browser storage on page load
20
+ - refreshes directly from browser-owned refresh tokens as the default session model
21
+
22
+ ### 2. Add backend auth proxy routes
23
+
24
+ Your backend should own:
25
+
26
+ - `POST /auth/login`
27
+ - `POST /auth/select-tenant`
28
+ - `POST /auth/mfa/verify`
29
+ - `POST /auth/mfa/verify-backup`
30
+ - `POST /auth/refresh`
31
+ - `POST /auth/logout`
32
+ - `GET /auth/me`
33
+
34
+ ### 3. Use the browser-session SDK entry point where appropriate
35
+
36
+ ```ts
37
+ import { createBrowserSessionClient } from "@iqauth/sdk/browser-session";
38
+
39
+ const client = createBrowserSessionClient({
40
+ baseUrl: process.env.IQAUTH_BASE_URL!,
41
+ });
42
+ ```
43
+
44
+ This is for backend/session-aware browser flows. It is not a license to move refresh tokens back into browser state.
45
+
46
+ ### 4. Update frontend boot logic
47
+
48
+ On app startup:
49
+
50
+ 1. call `/auth/me`
51
+ 2. if authenticated, hydrate user/session state
52
+ 3. if not authenticated, render signed-out state
53
+
54
+ ### 5. Update MFA and tenant-selection handling
55
+
56
+ The browser should still handle the UX, but the backend should own the IQAuth exchange and cookie updates.
57
+
58
+ ### 6. Update logout and invalidation handling
59
+
60
+ - logout should call backend logout
61
+ - revoked or inactive sessions should force a clean signed-out state
62
+ - session-expired UX should come from backend session truth, not stale browser state
63
+
64
+ ## Success Criteria
65
+
66
+ - no refresh token is stored in durable browser-readable storage
67
+ - page refresh restores auth through `/auth/me`
68
+ - login, MFA, tenant selection, refresh, and logout all work through the backend boundary
69
+ - revoked sessions do not strand the UI in a fake authenticated state
@@ -0,0 +1,188 @@
1
+ # Fresh Implementation Guide
2
+
3
+ Step-by-step integration guide for `@iqauth/sdk`, organized by environment.
4
+
5
+ Do not start with code samples until you first choose the client model.
6
+
7
+ ## 1. Choose Your Environment
8
+
9
+ | Environment | Recommended integration model |
10
+ |--------|--------|
11
+ | First-party web app | Backend proxy + `httpOnly` cookies |
12
+ | Native mobile app | Authorization code + PKCE + secure storage |
13
+ | Server-side app | Direct tokens or bearer-token verification |
14
+ | Service / automation | API key |
15
+
16
+ If you are building a browser application that you control, the default answer is: do not let browser JavaScript own the refresh token.
17
+
18
+ ## 2. First-Party Browser Apps
19
+
20
+ ### Recommended architecture
21
+
22
+ - frontend talks to your backend
23
+ - your backend talks to IQAuth
24
+ - backend sets `httpOnly` cookies
25
+ - frontend restores session from `/auth/me`
26
+
27
+ ### Backend responsibilities
28
+
29
+ - `/auth/login`
30
+ - `/auth/select-tenant`
31
+ - `/auth/mfa/verify`
32
+ - `/auth/mfa/verify-backup`
33
+ - `/auth/refresh`
34
+ - `/auth/logout`
35
+ - `/auth/me`
36
+
37
+ ### Browser responsibilities
38
+
39
+ - submit credentials to your backend
40
+ - handle MFA and tenant selection UX
41
+ - call `/auth/me` on app boot
42
+ - let the backend own refresh and session invalidation
43
+
44
+ ### Minimal frontend shape
45
+
46
+ ```typescript
47
+ async function login(email: string, password: string) {
48
+ const res = await fetch("/auth/login", {
49
+ method: "POST",
50
+ credentials: "include",
51
+ headers: { "Content-Type": "application/json" },
52
+ body: JSON.stringify({ email, password }),
53
+ });
54
+
55
+ return res.json();
56
+ }
57
+
58
+ async function loadSession() {
59
+ const res = await fetch("/auth/me", {
60
+ credentials: "include",
61
+ });
62
+
63
+ if (!res.ok) return null;
64
+ return res.json();
65
+ }
66
+ ```
67
+
68
+ ### What not to do
69
+
70
+ - do not store refresh tokens in `localStorage`
71
+ - do not make the browser the source of truth for durable auth state
72
+ - do not normalize direct token persistence as the default first-party pattern
73
+
74
+ ## 3. Native Mobile Apps
75
+
76
+ ### Recommended architecture
77
+
78
+ - authorization code flow with PKCE
79
+ - system browser / ASWebAuthenticationSession / Custom Tabs
80
+ - deep link or universal link callback
81
+ - secure storage only
82
+
83
+ ### Required elements
84
+
85
+ - `state`
86
+ - `nonce`
87
+ - PKCE code verifier
88
+ - PKCE code challenge (`S256`)
89
+
90
+ ### Token storage
91
+
92
+ Allowed:
93
+
94
+ - iOS Keychain
95
+ - Android Keystore
96
+ - an equivalent secure-storage abstraction
97
+
98
+ Not acceptable:
99
+
100
+ - plaintext async storage
101
+ - shared preferences without secure wrapping
102
+ - browser-style storage assumptions
103
+
104
+ ### Minimal mobile client shape
105
+
106
+ ```typescript
107
+ const client = new IQAuthClient({
108
+ baseUrl: "https://auth.dispositioniq.com",
109
+ accessToken: await secureStore.get("accessToken"),
110
+ refreshToken: await secureStore.get("refreshToken"),
111
+ onTokenRefresh: async (tokens) => {
112
+ await secureStore.set("accessToken", tokens.accessToken);
113
+ await secureStore.set("refreshToken", tokens.refreshToken);
114
+ },
115
+ });
116
+ ```
117
+
118
+ Use this only after a PKCE-based login.
119
+
120
+ ## 4. Server-Side Applications
121
+
122
+ This is the strongest current fit for the SDK.
123
+
124
+ ### Typical use cases
125
+
126
+ - Express resource server
127
+ - internal admin service
128
+ - backend calling IQAuth APIs directly
129
+ - request-scoped bearer verification
130
+
131
+ ### Example
132
+
133
+ ```typescript
134
+ import { createServerClient } from "@iqauth/sdk/server";
135
+
136
+ const client = createServerClient({
137
+ baseUrl: process.env.IQAUTH_BASE_URL!,
138
+ });
139
+
140
+ app.use("/api", client.middleware());
141
+ ```
142
+
143
+ ### Guidance
144
+
145
+ - prefer request-scoped auth context
146
+ - avoid shared mutable multi-user token state
147
+ - use the provided `client.middleware()` for incoming bearer tokens by default
148
+ - only drop to manual token verification when your framework cannot use the middleware shape
149
+
150
+ ## 5. Service / Automation Clients
151
+
152
+ Use API keys whenever possible.
153
+
154
+ ```typescript
155
+ const client = new IQAuthClient({
156
+ baseUrl: process.env.IQAUTH_BASE_URL!,
157
+ apiKey: process.env.IQAUTH_API_KEY!,
158
+ });
159
+ ```
160
+
161
+ Do not model services like interactive user sessions unless there is a specific product requirement.
162
+
163
+ ## 6. Authentication State Machine
164
+
165
+ The login state machine still has three outcomes:
166
+
167
+ ```typescript
168
+ type LoginResult =
169
+ | { status: "authenticated"; authMode: "token"; tokens: TokenPair; user: UserProfile }
170
+ | { status: "authenticated"; authMode: "session"; user: SessionUser }
171
+ | { status: "mfa_required"; mfaChallengeToken: string; availableMethods: string[] }
172
+ | { status: "tenant_selection"; tenantSelectionToken: string; tenants: Tenant[] };
173
+ ```
174
+
175
+ That state machine is most directly usable in:
176
+
177
+ - server-side apps
178
+ - native mobile flows
179
+ - controlled backend proxies
180
+
181
+ It should not be read as permission to store the resulting refresh token in browser-readable storage for first-party web apps.
182
+
183
+ ## 7. Where To Go Next
184
+
185
+ - Browser apps: [Auth Flows](./guides/auth-flows.md)
186
+ - Mobile apps: [Mobile / Native Guide](./guides/mobile-native.md)
187
+ - Session lifecycle: [Session Management](./guides/session-management.md)
188
+ - Server verification: [Token Verification](./guides/token-verification.md)
@@ -0,0 +1,98 @@
1
+ # Tarball Release Workflow
2
+
3
+ Use this workflow if you want `@iqauth/sdk` to be consumable by private application repos without publishing to public npm and without requiring each app to use registry auth tokens.
4
+
5
+ ## Recommended Flow
6
+
7
+ 1. bump the SDK version
8
+ 2. build the SDK
9
+ 3. generate a `.tgz` with `npm pack`
10
+ 4. distribute that tarball to the consuming app
11
+ 5. install the tarball into the app
12
+ 6. if the installed version changed, run the environment-specific setup prompt for that app
13
+
14
+ ## Release Commands
15
+
16
+ From `packages/iqauth-sdk`:
17
+
18
+ ```bash
19
+ npm version patch
20
+ npm run build
21
+ npm pack --cache /tmp/iqauth-npm-cache
22
+ ```
23
+
24
+ That produces a tarball like:
25
+
26
+ ```bash
27
+ iq-auth-sdk-1.0.1.tgz
28
+ ```
29
+
30
+ ## Install Commands
31
+
32
+ ### Local file path
33
+
34
+ ```bash
35
+ npm install ./vendor/iq-auth-sdk-1.0.1.tgz
36
+ ```
37
+
38
+ ### Relative path during local development
39
+
40
+ ```bash
41
+ npm install ../iq-auth-sdk-1.0.1.tgz
42
+ ```
43
+
44
+ ## Suggested App-Repo Layout
45
+
46
+ If you want the app to carry the tarball directly:
47
+
48
+ ```text
49
+ your-app/
50
+ vendor/
51
+ iq-auth-sdk-1.0.1.tgz
52
+ ```
53
+
54
+ Then install from that path and commit the dependency reference in `package.json` or the lockfile.
55
+
56
+ ## Required Handoff After Install
57
+
58
+ After installing a new tarball version:
59
+
60
+ - identify the app type
61
+ - run the matching setup prompt
62
+ - verify the app against the current integration matrix
63
+
64
+ App types:
65
+
66
+ - first-party browser app
67
+ - native mobile app
68
+ - server platform app
69
+ - service automation app
70
+
71
+ See:
72
+
73
+ - [App Integration Matrix](./APP_INTEGRATION_MATRIX.md)
74
+ - [Integration Prompts](./integration-prompts/)
75
+
76
+ ## Version-Change Rule
77
+
78
+ If the tarball version changed, do not stop at install.
79
+
80
+ You should also:
81
+
82
+ 1. review the release notes or migration notes
83
+ 2. run the matching environment prompt
84
+ 3. verify that the app still follows the supported auth model
85
+
86
+ ## Why this flow exists
87
+
88
+ This approach avoids:
89
+
90
+ - public npm publication
91
+ - self-hosted registry overhead
92
+ - per-project registry auth tokens
93
+
94
+ while still preserving:
95
+
96
+ - versioned releases
97
+ - reproducible installs
98
+ - a clear migration path for app teams