@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DispositionIQ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # @iqauth/sdk
2
+
3
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg)](https://www.typescriptlang.org/)
4
+ [![License](https://img.shields.io/badge/license-proprietary-lightgrey.svg)]()
5
+ [![Module Format](https://img.shields.io/badge/format-CJS%20%2B%20ESM-blue.svg)]()
6
+ [![Docs](https://img.shields.io/badge/docs-environment--specific-blue.svg)](./docs/)
7
+
8
+ Type-safe TypeScript SDK for IQAuthService.
9
+
10
+ ## Five-line integration
11
+
12
+ **React (client):**
13
+ ```tsx
14
+ import { IQAuthProvider, SignedIn, SignedOut, RedirectToSignIn } from "@iqauth/sdk/react";
15
+
16
+ <IQAuthProvider publishableKey={import.meta.env.VITE_IQAUTH_PUBLISHABLE_KEY}>
17
+ <SignedIn><App /></SignedIn>
18
+ <SignedOut><RedirectToSignIn /></SignedOut>
19
+ </IQAuthProvider>
20
+ ```
21
+
22
+ **Express / Fastify / Hono / Next.js (server):**
23
+ ```js
24
+ import express from "express";
25
+ import { iqAuth } from "@iqauth/sdk/express"; // or /fastify, /hono, /next
26
+
27
+ const app = express();
28
+ app.use(express.json());
29
+ const auth = iqAuth({ publishableKey: process.env.IQAUTH_PUBLISHABLE_KEY, secretKey: process.env.IQAUTH_SECRET_KEY });
30
+ auth.attachHelpers(app); // mounts /api/iqauth/{callback,refresh,signout} (httpOnly cookies)
31
+ app.use(auth); // verifies Bearer or iqauth_at cookie; populates req.auth
32
+ ```
33
+
34
+ The middleware is **cookie-aware** (Bearer header OR `iqauth_at` cookie) and the issuer is **auto-discovered from your publishable key** — no extra config.
35
+
36
+ Working examples live in `examples/{react-vite,express,fastify,hono,next}/`.
37
+
38
+ ## CLI
39
+
40
+ ```sh
41
+ npx iqauth init # bootstrap a new app + write IQAUTH_* keys to .env
42
+ npx iqauth doctor # check .env, issuer reachability, JWKS, redirect URI
43
+ npx iqauth keys list --app <id>
44
+ npx iqauth keys rotate --app <id> --key-id <id> --yes
45
+ npx iqauth dev # run the bundled React example with your key
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Environment Matrix
51
+
52
+ This package is not one auth model for every environment. The safe integration pattern depends on where credentials live.
53
+
54
+ | Environment | Recommended pattern | Refresh token owner | Primary SDK fit |
55
+ |--------|--------|--------|--------|
56
+ | First-party browser app | Backend proxy + `httpOnly` cookies | Backend only | Resource calls, server verification, shared API modules |
57
+ | Native mobile app | Authorization code + PKCE + secure OS storage | Mobile app secure storage | Token-owning client patterns |
58
+ | Server-side app | Direct token handling or request-scoped bearer verification | Server | Strong fit |
59
+ | Service / automation | API key or dedicated service credentials | Service | Strong fit |
60
+
61
+ ## Start Here
62
+
63
+ ### First-party browser apps
64
+
65
+ Do not treat this SDK's token-owning client as the default browser integration path.
66
+
67
+ For first-party web applications:
68
+
69
+ - proxy login, MFA, tenant selection, refresh, and logout through your backend
70
+ - store access and refresh tokens in `httpOnly` cookies
71
+ - restore session with a backend endpoint such as `/auth/me`
72
+ - do not store refresh tokens in `localStorage`, `sessionStorage`, or browser-readable memory as your durable session model
73
+
74
+ The browser should call your backend. Your backend should call IQAuth.
75
+
76
+ ### Native mobile apps
77
+
78
+ Use authorization code flow with PKCE:
79
+
80
+ - generate `state`, `nonce`, and PKCE verifier/challenge on device
81
+ - complete auth in the system browser
82
+ - exchange the authorization code
83
+ - store tokens only in Keychain / Keystore / secure OS-backed storage
84
+
85
+ ### Server-side apps
86
+
87
+ This SDK is a good fit for:
88
+
89
+ - trusted backend services
90
+ - Express resource servers
91
+ - admin tooling
92
+ - request-scoped token handling
93
+ - bearer-token verification through JWKS
94
+
95
+ ### Service clients
96
+
97
+ Prefer API keys or dedicated service credentials over interactive user session flows.
98
+
99
+ ## Current SDK Shape
100
+
101
+ The current package surface is still token-oriented. That is acceptable for server, mobile, and service contexts, but it should not be read as a recommendation to store refresh tokens directly in first-party browser JavaScript.
102
+
103
+ Use the package today with that distinction in mind:
104
+
105
+ - server: recommended
106
+ - mobile: acceptable with PKCE + secure storage discipline
107
+ - browser first-party: use only behind a backend session boundary
108
+ - service: recommended with API keys
109
+
110
+ ## Install
111
+
112
+ ```bash
113
+ npm install @iqauth/sdk
114
+ ```
115
+
116
+ Supports both CommonJS and ES Modules. Ships with TypeScript declarations.
117
+
118
+ ## Entry Points
119
+
120
+ Use the entry point that matches your environment:
121
+
122
+ ```typescript
123
+ import { createBrowserSessionClient } from "@iqauth/sdk/browser-session";
124
+ import { createServerClient, ServerIQAuthClient } from "@iqauth/sdk/server";
125
+ import { createMobileClient } from "@iqauth/sdk/mobile";
126
+ import { createServiceClient } from "@iqauth/sdk/service";
127
+ ```
128
+
129
+ ## Server Quick Start
130
+
131
+ Use the provided middleware by default for Express resource servers.
132
+
133
+ ```typescript
134
+ import express from "express";
135
+ import { createServerClient } from "@iqauth/sdk/server";
136
+
137
+ const client = createServerClient({
138
+ baseUrl: "https://auth.dispositioniq.com",
139
+ });
140
+
141
+ const app = express();
142
+
143
+ app.use("/api", client.middleware());
144
+
145
+ app.get("/api/me", (req, res) => {
146
+ res.json({
147
+ sub: req.auth!.sub,
148
+ email: req.auth!.email,
149
+ tenantId: req.auth!.tenantId,
150
+ roles: req.auth!.roles,
151
+ });
152
+ });
153
+ ```
154
+
155
+ If you are building an Express API that accepts bearer tokens, the platform should use the SDK middleware rather than re-implementing token verification manually unless there is a concrete framework constraint.
156
+
157
+ ## Browser Quick Start
158
+
159
+ Use a backend proxy. Example shape:
160
+
161
+ ```typescript
162
+ // frontend
163
+ await fetch("/auth/login", {
164
+ method: "POST",
165
+ credentials: "include",
166
+ headers: { "Content-Type": "application/json" },
167
+ body: JSON.stringify({ email, password }),
168
+ });
169
+
170
+ const me = await fetch("/auth/me", {
171
+ credentials: "include",
172
+ }).then((res) => res.json());
173
+ ```
174
+
175
+ ```typescript
176
+ // backend
177
+ app.post("/auth/login", async (req, res) => {
178
+ const result = await iqauth.auth.login(req.body.email, req.body.password);
179
+ // set httpOnly cookies here, not localStorage in the browser
180
+ });
181
+ ```
182
+
183
+ For the full backend-proxy pattern, see the Fresh Implementation Guide.
184
+
185
+ ## Mobile Quick Start
186
+
187
+ ```typescript
188
+ import { IQAuthClient } from "@iqauth/sdk";
189
+
190
+ const client = new IQAuthClient({
191
+ baseUrl: "https://auth.dispositioniq.com",
192
+ accessToken: await secureStore.get("accessToken"),
193
+ refreshToken: await secureStore.get("refreshToken"),
194
+ onTokenRefresh: async (tokens) => {
195
+ await secureStore.set("accessToken", tokens.accessToken);
196
+ await secureStore.set("refreshToken", tokens.refreshToken);
197
+ },
198
+ });
199
+ ```
200
+
201
+ This is only appropriate when the tokens are stored in secure OS-backed storage and the login flow uses PKCE.
202
+
203
+ ## API Key Quick Start
204
+
205
+ ```typescript
206
+ import { IQAuthClient } from "@iqauth/sdk";
207
+
208
+ const client = new IQAuthClient({
209
+ baseUrl: "https://auth.dispositioniq.com",
210
+ apiKey: process.env.IQAUTH_API_KEY,
211
+ });
212
+
213
+ const keys = await client.apiKeys.list();
214
+ ```
215
+
216
+ ## Main Modules
217
+
218
+ | Module | Access | Purpose |
219
+ |--------|--------|---------|
220
+ | `auth` | `client.auth` | Login, MFA, tenant selection, logout, password reset, OAuth |
221
+ | `tokens` | `client.tokens` | JWT verification (RS256/JWKS), decode, expiry checks |
222
+ | `sessions` | `client.sessions` | List and revoke sessions |
223
+ | `users` | `client.users` | Profile and user management |
224
+ | `permissions` | `client.permissions` | Role and entitlement helpers |
225
+ | `oidc` | `client.oidc` | Discovery, JWKS, authorization helpers, code exchange |
226
+ | `apiKeys` | `client.apiKeys` | API key create/list/revoke/introspect |
227
+ | `webhooks` | `client.webhooks` | Endpoint CRUD, deliveries, test, secret rotation |
228
+ | `mfa` | `client.mfa` | MFA enrollment, backup codes |
229
+ | `branding` | `client.branding` | Branding config CRUD |
230
+
231
+ ## Express Middleware
232
+
233
+ ```typescript
234
+ import { createServerClient } from "@iqauth/sdk/server";
235
+
236
+ const client = createServerClient({
237
+ baseUrl: "https://auth.dispositioniq.com",
238
+ });
239
+
240
+ app.use(
241
+ "/admin",
242
+ client.middleware({
243
+ requiredRoles: ["tenant_admin", "platform_admin"],
244
+ requiredEntitlements: ["iqcapture"],
245
+ }),
246
+ );
247
+ ```
248
+
249
+ The middleware attaches verified claims to `req.auth` and is the recommended integration path for platforms consuming bearer tokens.
250
+
251
+ ## Error Handling
252
+
253
+ All API errors throw `IQAuthError`.
254
+
255
+ ```typescript
256
+ import { IQAuthError, ErrorCodes } from "@iqauth/sdk";
257
+
258
+ try {
259
+ await client.auth.login(email, password);
260
+ } catch (err) {
261
+ if (err instanceof IQAuthError && err.code === ErrorCodes.ACCOUNT_LOCKED) {
262
+ // handle lockout
263
+ }
264
+ }
265
+ ```
266
+
267
+ ## Documentation
268
+
269
+ - [App Integration Matrix](./docs/APP_INTEGRATION_MATRIX.md)
270
+ - [Fresh Implementation Guide](./docs/FRESH_IMPLEMENTATION_GUIDE.md)
271
+ - [Browser Session Migration Guide](./docs/BROWSER_SESSION_MIGRATION.md)
272
+ - [Tarball Release Workflow](./docs/TARBALL_RELEASE_WORKFLOW.md)
273
+ - [Auth Flows](./docs/guides/auth-flows.md)
274
+ - [Session Management](./docs/guides/session-management.md)
275
+ - [Mobile / Native Guide](./docs/guides/mobile-native.md)
276
+ - [Server Platform Integration](./docs/guides/server-platform-integration.md)
277
+ - [Service Automation Integration](./docs/guides/service-automation-integration.md)
278
+ - [Token Verification](./docs/guides/token-verification.md)
279
+ - [API Keys](./docs/guides/api-keys.md)
280
+ - [Middleware Reference](./docs/guides/middleware-reference.md)
281
+ - [Error Handling](./docs/guides/error-handling.md)
282
+ - [V1 to V2 Upgrade Guide](./docs/V1_TO_V2_UPGRADE_GUIDE.md)
283
+ - [Integration Prompts](./docs/integration-prompts/)
284
+
285
+ ## License
286
+
287
+ Private — DispositionIQ internal use.
@@ -0,0 +1,12 @@
1
+ import { c as IQAuthBrowserSessionClientConfig, d as SessionUser } from './types-Cxl3bQHt.mjs';
2
+ import { I as IQAuthClient } from './client-C1DXfB8Z.mjs';
3
+ export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
4
+ import 'jsonwebtoken';
5
+
6
+ declare class BrowserSessionIQAuthClient extends IQAuthClient {
7
+ constructor(config: Omit<IQAuthBrowserSessionClientConfig, "environment">);
8
+ getSessionUser(): Promise<SessionUser>;
9
+ }
10
+ declare function createBrowserSessionClient(config: Omit<IQAuthBrowserSessionClientConfig, "environment">): BrowserSessionIQAuthClient;
11
+
12
+ export { BrowserSessionIQAuthClient, IQAuthBrowserSessionClientConfig, IQAuthClient, createBrowserSessionClient };
@@ -0,0 +1,12 @@
1
+ import { c as IQAuthBrowserSessionClientConfig, d as SessionUser } from './types-Cxl3bQHt.js';
2
+ import { I as IQAuthClient } from './client-CggvJmmm.js';
3
+ export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
4
+ import 'jsonwebtoken';
5
+
6
+ declare class BrowserSessionIQAuthClient extends IQAuthClient {
7
+ constructor(config: Omit<IQAuthBrowserSessionClientConfig, "environment">);
8
+ getSessionUser(): Promise<SessionUser>;
9
+ }
10
+ declare function createBrowserSessionClient(config: Omit<IQAuthBrowserSessionClientConfig, "environment">): BrowserSessionIQAuthClient;
11
+
12
+ export { BrowserSessionIQAuthClient, IQAuthBrowserSessionClientConfig, IQAuthClient, createBrowserSessionClient };