@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,911 @@
1
+ import { I as IQAuthEnvironment, T as TokenPair, W as IQAuthRetryConfig, L as LoginResult, a$ as SignupRequest, D as MfaVerifyResult, d as SessionUser, J as JwtClaims, h as Session, U as UserProfile, H as ProvisionUserRequest, K as ProvisionUserResponse, G as UserPermissions, O as OidcDiscovery, t as JwksResponse, u as OidcTokenResponse, b0 as HostedClientContext, i as TenantInfo, C as CreateTenantRequest, j as UpdateTenantRequest, P as PromoteToVendorRequest, k as PromoteToVendorResult, a7 as TenantUser, l as InviteTenantUserRequest, m as InviteTenantUserResult, n as TenantUserRoleUpdate, M as MigrateUserRequest, E as PasswordPolicy, F as MfaPolicy, B as BrandingConfig, _ as AppInfo, $ as PermissionNodeInfo, Z as AppManifest, a0 as AppSyncResult, a1 as Role, a2 as CreateRoleRequest, a3 as UpdateRoleRequest, a4 as AssignRoleRequest, a5 as UserRoleAssignment, a8 as PermissionGroup, a9 as GroupPermission, aa as AddGroupPermissionRequest, ab as InheritanceRelation, a6 as UserGroupAssignment, ac as UserPermissionOverride, ad as AddUserOverrideRequest, ae as EffectivePermission, af as PermissionCheckResult, ah as CreateApiKeyRequest, ai as CreateApiKeyResult, ag as ApiKeyInfo, aj as ApiKeyIntrospection, al as CreateInviteRequest, ak as Invitation, am as InviteValidation, an as AcceptInviteRequest, ap as CreateWebhookRequest, aq as CreateWebhookResult, ao as WebhookEndpoint, ar as WebhookDelivery, as as WebhookTestResult, at as Entitlement, au as GrantEntitlementRequest, av as Vendor, aw as CreateVendorRequest, ax as UpdateVendorRequest, az as CreateSourceRequest, ay as Source, aA as UpdateSourceRequest, aC as CreateClientRequest, aB as Client, aD as UpdateClientRequest, aE as HierarchyVendor, aH as HierarchyLink, aL as MembershipWithDetails, aJ as CreateMembershipRequest, aI as Membership, aK as UpdateMembershipRequest, aM as AvailableScopesTree, aQ as ScopeSwitchResult, aR as GdprExportData, aS as PinStatus, aU as MfaAvailableMethods, aV as TotpEnrollResult, aW as TotpVerifyResult, aX as SmsEnrollResult, y as MfaEnrollment, aY as EmailEnrollResult, aZ as BackupCodesResult, a_ as BackupCodeCountResult, o as UpdateBrandingRequest, q as UploadAssetRequest, p as BrandingAsset, r as BrandingDomainMapping, a as IQAuthClientConfig, c as IQAuthBrowserSessionClientConfig, b as IQAuthTokenClientConfig } from './types-Cxl3bQHt.mjs';
2
+ import jwt from 'jsonwebtoken';
3
+
4
+ /**
5
+ * SOURCE REFS:
6
+ * - Route file: src/lib/response.ts (envelope: { success: true, data } / { success: false, error: { code, message } })
7
+ * - Route file: src/middleware/requireAuth.ts (Authorization: Bearer header)
8
+ * - Route file: src/middleware/requireApiKey.ts (X-API-Key header)
9
+ * - Verified claims: N/A (HTTP transport layer)
10
+ * - Last verified: Phase 0 Research Summary
11
+ */
12
+
13
+ interface HttpClientConfig {
14
+ baseUrl: string;
15
+ environment: IQAuthEnvironment;
16
+ getAccessToken: () => string | undefined;
17
+ getRefreshToken: () => string | undefined;
18
+ getApiKey: () => string | undefined;
19
+ setTokens: (tokens: TokenPair) => void;
20
+ autoRefresh: boolean;
21
+ onTokenRefresh?: (tokens: TokenPair) => void;
22
+ sessionHeaderName?: string;
23
+ sessionHeaderValue?: string;
24
+ retry?: IQAuthRetryConfig;
25
+ }
26
+ declare class HttpClient {
27
+ private config;
28
+ private refreshPromise;
29
+ private retryConfig;
30
+ constructor(config: HttpClientConfig);
31
+ private computeBackoffDelay;
32
+ private isRetryableStatus;
33
+ private fetchWithRetry;
34
+ get baseUrl(): string;
35
+ get environment(): IQAuthEnvironment;
36
+ isBrowserSession(): boolean;
37
+ hasCredentials(): boolean;
38
+ private buildHeaders;
39
+ private isTokenExpiringSoon;
40
+ private attemptRefresh;
41
+ request<T>(method: string, path: string, body?: unknown, options?: {
42
+ authMode?: "bearer" | "apikey";
43
+ skipAutoRefresh?: boolean;
44
+ }): Promise<T>;
45
+ private requestWithRetry;
46
+ requestRaw<T>(method: string, path: string, body?: unknown): Promise<T>;
47
+ }
48
+
49
+ declare class AuthModule {
50
+ private http;
51
+ constructor(http: HttpClient);
52
+ login(email: string, password: string): Promise<LoginResult>;
53
+ signup(input: SignupRequest): Promise<LoginResult>;
54
+ completeMfa(mfaChallengeToken: string, code: string, method?: string): Promise<MfaVerifyResult>;
55
+ completeMfaWithBackup(mfaChallengeToken: string, backupCode: string): Promise<MfaVerifyResult>;
56
+ sendMfaChallenge(mfaChallengeToken: string, method: string): Promise<{
57
+ sent: boolean;
58
+ method: string;
59
+ }>;
60
+ selectTenant(tenantSelectionToken: string, tenantId: string): Promise<LoginResult>;
61
+ logout(): Promise<{
62
+ message: string;
63
+ }>;
64
+ logoutAll(): Promise<{
65
+ terminatedCount: number;
66
+ }>;
67
+ refreshTokens(refreshToken: string): Promise<TokenPair>;
68
+ forgotPassword(email: string): Promise<{
69
+ message: string;
70
+ resetToken?: string;
71
+ warning?: string;
72
+ email?: string;
73
+ expiresInMinutes?: number;
74
+ }>;
75
+ resetPassword(token: string, newPassword: string): Promise<{
76
+ message: string;
77
+ }>;
78
+ changePassword(currentPassword: string, newPassword: string): Promise<{
79
+ message: string;
80
+ }>;
81
+ verifyToken(): Promise<Record<string, unknown>>;
82
+ exchangeOAuthCode(code: string): Promise<LoginResult>;
83
+ getSessionUser(): Promise<SessionUser>;
84
+ }
85
+
86
+ /**
87
+ * SOURCE REFS:
88
+ * - Route file: src/services/token.service.ts (RS256, issuer "auth.dispositioniq.com", audience array)
89
+ * - Route file: src/routes/wellknown.routes.ts (JWKS endpoint /.well-known/jwks.json)
90
+ * - Route file: src/lib/crypto.ts (key rotation with kid)
91
+ * - Verified claims: sub, email, name, tenantId, vendorId, roles, entitlements, sessionId, jti, iss, aud, exp, iat, scopeContext, loginMethod
92
+ * - Last verified: Phase 0 Research Summary
93
+ */
94
+
95
+ declare const DEFAULT_TOKEN_ISSUER = "auth.dispositioniq.com";
96
+ declare const DEFAULT_TOKEN_AUDIENCE: string[];
97
+ declare const DEFAULT_CLOCK_TOLERANCE_SECONDS = 30;
98
+ interface TokenVerifyOptions {
99
+ issuer?: string | string[];
100
+ audience?: string | string[];
101
+ clockTolerance?: number;
102
+ algorithms?: jwt.Algorithm[];
103
+ }
104
+ interface TokensModuleOptions {
105
+ issuer?: string | string[];
106
+ audience?: string | string[];
107
+ clockTolerance?: number;
108
+ }
109
+ declare class TokensModule {
110
+ private baseUrl;
111
+ private jwksCache;
112
+ private inFlightRefresh;
113
+ private defaultIssuer;
114
+ private defaultAudience;
115
+ private defaultClockTolerance;
116
+ constructor(baseUrl: string, options?: TokensModuleOptions);
117
+ /**
118
+ * Verify a JWT access token using RS256 via JWKS from /.well-known/jwks.json.
119
+ * Caches JWKS keys for 1 hour. Retries once on unknown `kid`.
120
+ *
121
+ * @remarks Validates against /.well-known/jwks.json. Issuer, audience, and
122
+ * clock tolerance default to client config but can be overridden per call.
123
+ */
124
+ verify(token: string, options?: TokenVerifyOptions): Promise<JwtClaims>;
125
+ /**
126
+ * Decode a JWT without verification. Returns null if malformed.
127
+ *
128
+ * @remarks Local decode only — no network call
129
+ */
130
+ decode(token: string): JwtClaims | null;
131
+ /**
132
+ * Check if a token is expired based on the `exp` claim.
133
+ *
134
+ * @remarks Local check only — no network call
135
+ */
136
+ isExpired(token: string): boolean;
137
+ /**
138
+ * Get the claims from a token without verification.
139
+ *
140
+ * @remarks Local decode only — no network call
141
+ */
142
+ getClaims(token: string): JwtClaims;
143
+ private getPublicKey;
144
+ private refreshJwks;
145
+ private jwkToPem;
146
+ /** @internal Exposed for testing — clears JWKS cache */
147
+ clearCache(): void;
148
+ }
149
+
150
+ /**
151
+ * SOURCE REFS:
152
+ * - Route file: src/routes/sessions.routes.ts (GET /, DELETE /:sessionId)
153
+ * - Route file: src/routes/auth.routes.ts (GET /sessions, DELETE /sessions/:sessionId, POST /logout-all)
154
+ * - Verified claims: sub, sessionId
155
+ * - Last verified: Phase 0 Research Summary
156
+ */
157
+
158
+ declare class SessionsModule {
159
+ private http;
160
+ constructor(http: HttpClient);
161
+ /**
162
+ * List all active sessions for the current user.
163
+ *
164
+ * @remarks Wraps GET /api/v1/sessions
165
+ */
166
+ list(): Promise<Session[]>;
167
+ /**
168
+ * Revoke (terminate) a specific session by ID.
169
+ *
170
+ * @remarks Wraps DELETE /api/v1/sessions/:sessionId
171
+ */
172
+ revoke(sessionId: string): Promise<{
173
+ message: string;
174
+ }>;
175
+ /**
176
+ * Revoke all sessions for the current user.
177
+ *
178
+ * @remarks Wraps POST /api/v1/auth/logout-all
179
+ */
180
+ revokeAll(): Promise<{
181
+ terminatedCount: number;
182
+ }>;
183
+ }
184
+
185
+ /**
186
+ * SOURCE REFS:
187
+ * - Route file: src/routes/users.routes.ts (GET /me, PATCH /me, GET /, GET /:id, PATCH /:id/deactivate, PATCH /:id/reactivate, PATCH /:id/unlock)
188
+ * - Route file: src/routes/tenants.routes.ts (POST /:tenantId/users/provision)
189
+ * - Verified claims: sub, email, name, tenantId, roles
190
+ * - Last verified: Phase 0 Research Summary
191
+ */
192
+
193
+ declare class UsersModule {
194
+ private http;
195
+ constructor(http: HttpClient);
196
+ /**
197
+ * Get the currently authenticated user's profile.
198
+ *
199
+ * @remarks Wraps GET /api/v1/users/me
200
+ */
201
+ getCurrent(): Promise<UserProfile>;
202
+ /**
203
+ * Get a user by ID.
204
+ *
205
+ * @remarks Wraps GET /api/v1/users/:id
206
+ */
207
+ getById(userId: string): Promise<UserProfile>;
208
+ /**
209
+ * List users in the current tenant. Requires tenant_admin role.
210
+ *
211
+ * @remarks Wraps GET /api/v1/users
212
+ */
213
+ list(params?: {
214
+ email?: string;
215
+ tenantId?: string;
216
+ }): Promise<UserProfile[]>;
217
+ /**
218
+ * Provision (create) a new user in a tenant. Requires platform_admin or tenant-scoped API key with admin role.
219
+ *
220
+ * @remarks Wraps POST /api/v1/tenants/:tenantId/users/provision
221
+ */
222
+ create(tenantId: string, data: ProvisionUserRequest): Promise<ProvisionUserResponse>;
223
+ /**
224
+ * Update the current user's profile (name, picture).
225
+ *
226
+ * @remarks Wraps PATCH /api/v1/users/me
227
+ */
228
+ update(data: {
229
+ name?: string;
230
+ picture?: string;
231
+ }): Promise<UserProfile>;
232
+ /**
233
+ * Deactivate a user in the current tenant. Requires tenant_admin role.
234
+ *
235
+ * @remarks Wraps PATCH /api/v1/users/:id/deactivate
236
+ */
237
+ deactivate(userId: string): Promise<{
238
+ message: string;
239
+ }>;
240
+ /**
241
+ * Reactivate a user in the current tenant. Requires tenant_admin role.
242
+ *
243
+ * @remarks Wraps PATCH /api/v1/users/:id/reactivate
244
+ */
245
+ reactivate(userId: string): Promise<{
246
+ message: string;
247
+ }>;
248
+ /**
249
+ * Unlock a locked user account in the current tenant. Requires tenant_admin role.
250
+ *
251
+ * @remarks Wraps PATCH /api/v1/users/:id/unlock
252
+ */
253
+ unlock(userId: string): Promise<{
254
+ message: string;
255
+ }>;
256
+ /**
257
+ * Get effective permissions for a user for a specific product.
258
+ *
259
+ * @remarks Wraps GET /api/v1/users/:id/permissions?product=...
260
+ */
261
+ getPermissions(userId: string, product: string): Promise<UserPermissions>;
262
+ /**
263
+ * Change the current user's password.
264
+ *
265
+ * @remarks Wraps POST /api/v1/auth/password/change
266
+ */
267
+ updatePassword(currentPassword: string, newPassword: string): Promise<{
268
+ message: string;
269
+ }>;
270
+ }
271
+
272
+ /**
273
+ * SOURCE REFS:
274
+ * - Route file: src/types/index.ts (JwtPayload.roles, JwtPayload.entitlements)
275
+ * - Route file: src/services/auth.service.ts (roles and entitlements written into JWT)
276
+ * - Verified claims: roles (string[]), entitlements (string[])
277
+ * - Last verified: Phase 0 Research Summary
278
+ */
279
+
280
+ declare class PermissionsModule {
281
+ private getClaims;
282
+ constructor(claimsProvider: () => JwtClaims | null);
283
+ /**
284
+ * Get the roles from the current JWT claims.
285
+ *
286
+ * @remarks Extracted from JWT claim `roles` (string[])
287
+ */
288
+ getRoles(): string[];
289
+ /**
290
+ * Get the entitlements from the current JWT claims.
291
+ *
292
+ * @remarks Extracted from JWT claim `entitlements` (string[])
293
+ */
294
+ getEntitlements(): string[];
295
+ /**
296
+ * Check if the current user has a specific role.
297
+ *
298
+ * @remarks Checks against JWT claim `roles`
299
+ */
300
+ hasRole(role: string): boolean;
301
+ /**
302
+ * Check if the current user has a specific entitlement.
303
+ *
304
+ * @remarks Checks against JWT claim `entitlements`
305
+ */
306
+ hasEntitlement(entitlement: string): boolean;
307
+ /**
308
+ * Check if the current user has all of the specified roles.
309
+ *
310
+ * @remarks Checks against JWT claim `roles`
311
+ */
312
+ hasAllRoles(roles: string[]): boolean;
313
+ /**
314
+ * Check if the current user has any of the specified roles.
315
+ *
316
+ * @remarks Checks against JWT claim `roles`
317
+ */
318
+ hasAnyRole(roles: string[]): boolean;
319
+ /**
320
+ * Check if the current user has all of the specified entitlements.
321
+ *
322
+ * @remarks Checks against JWT claim `entitlements`
323
+ */
324
+ hasAllEntitlements(entitlements: string[]): boolean;
325
+ /**
326
+ * Check if the current user has any of the specified entitlements.
327
+ *
328
+ * @remarks Checks against JWT claim `entitlements`
329
+ */
330
+ hasAnyEntitlement(entitlements: string[]): boolean;
331
+ }
332
+
333
+ /**
334
+ * SOURCE REFS:
335
+ * - Route file: src/routes/oidc.routes.ts (GET /discovery, POST /token, GET /userinfo)
336
+ * - Route file: src/routes/wellknown.routes.ts (GET /.well-known/openid-configuration, GET /.well-known/jwks.json)
337
+ * - Verified claims: sub, email, name, picture, roles, at_hash, auth_time
338
+ * - Last verified: Phase 0 Research Summary
339
+ */
340
+
341
+ interface OidcStoredRequest {
342
+ codeVerifier: string;
343
+ state: string;
344
+ nonce: string;
345
+ redirectUri: string;
346
+ clientId: string;
347
+ expiresAt: number;
348
+ }
349
+ /**
350
+ * Pluggable storage adapter for PKCE/state/nonce binding. The default
351
+ * implementation is in-memory and adequate for single-process Node servers
352
+ * and short-lived browser sessions; provide your own (Redis, signed cookies,
353
+ * etc.) for distributed/cross-tab scenarios.
354
+ */
355
+ interface OidcStateStore {
356
+ set(state: string, value: OidcStoredRequest): void | Promise<void>;
357
+ get(state: string): OidcStoredRequest | null | Promise<OidcStoredRequest | null>;
358
+ delete(state: string): void | Promise<void>;
359
+ }
360
+ declare class InMemoryOidcStateStore implements OidcStateStore {
361
+ private map;
362
+ set(state: string, value: OidcStoredRequest): void;
363
+ get(state: string): OidcStoredRequest | null;
364
+ delete(state: string): void;
365
+ }
366
+ interface OidcModuleOptions {
367
+ stateStore?: OidcStateStore;
368
+ /** TTL for stored auth requests in milliseconds. Defaults to 10 minutes. */
369
+ requestTtlMs?: number;
370
+ /** Tokens module used to verify id_token signatures and claims. */
371
+ tokens?: TokensModule;
372
+ }
373
+ interface OidcAuthRequest {
374
+ authorizationUrl: string;
375
+ state: string;
376
+ nonce: string;
377
+ codeVerifier: string;
378
+ codeChallenge: string;
379
+ codeChallengeMethod: "S256";
380
+ }
381
+ interface OidcCallbackResult {
382
+ tokens: OidcTokenResponse;
383
+ idTokenClaims: JwtClaims | null;
384
+ }
385
+ declare class OidcModule {
386
+ private http;
387
+ private baseUrl;
388
+ private stateStore;
389
+ private requestTtlMs;
390
+ private tokensModule?;
391
+ constructor(http: HttpClient, baseUrl: string, options?: OidcModuleOptions);
392
+ /** @internal Allow the client to inject its TokensModule after construction. */
393
+ _setTokensModule(tokens: TokensModule): void;
394
+ /**
395
+ * Fetch the OpenID Connect discovery document.
396
+ *
397
+ * @remarks Wraps GET /.well-known/openid-configuration
398
+ */
399
+ getDiscovery(): Promise<OidcDiscovery>;
400
+ /**
401
+ * Fetch the JSON Web Key Set.
402
+ *
403
+ * @remarks Wraps GET /.well-known/jwks.json
404
+ */
405
+ getJwks(): Promise<JwksResponse>;
406
+ /**
407
+ * Build an OIDC authorization URL for redirect-based login.
408
+ *
409
+ * @remarks Constructs URL pointing to /oidc/authorize. Prefer
410
+ * {@link createAuthRequest} which also generates and stores PKCE/state/nonce.
411
+ */
412
+ buildAuthorizationUrl(params: {
413
+ clientId: string;
414
+ redirectUri: string;
415
+ scope?: string;
416
+ state: string;
417
+ nonce?: string;
418
+ codeChallenge?: string;
419
+ codeChallengeMethod?: string;
420
+ }): string;
421
+ /**
422
+ * Generate `code_verifier`, `code_challenge`, `state`, and `nonce`, persist
423
+ * them via the configured storage adapter, and return an authorization URL
424
+ * ready to redirect the user to.
425
+ */
426
+ createAuthRequest(params: {
427
+ clientId: string;
428
+ redirectUri: string;
429
+ scope?: string;
430
+ }): Promise<OidcAuthRequest>;
431
+ /**
432
+ * Validate the callback `state`, exchange the code with the bound PKCE
433
+ * verifier, and verify that the returned `id_token` (if any) carries the
434
+ * stored `nonce` and `aud === clientId`.
435
+ */
436
+ handleCallback(params: {
437
+ code: string;
438
+ state: string;
439
+ /** Optional client secret if your client is confidential. */
440
+ clientSecret?: string;
441
+ }): Promise<OidcCallbackResult>;
442
+ /**
443
+ * Exchange an authorization code for tokens at the OIDC token endpoint.
444
+ *
445
+ * @remarks Wraps POST /oidc/token (or /api/v1/oidc/token)
446
+ */
447
+ exchangeCode(params: {
448
+ code: string;
449
+ redirectUri: string;
450
+ clientId: string;
451
+ clientSecret?: string;
452
+ codeVerifier?: string;
453
+ }): Promise<OidcTokenResponse>;
454
+ /**
455
+ * Get user info from the OIDC userinfo endpoint.
456
+ *
457
+ * @remarks Wraps GET /oidc/userinfo (requires Bearer token)
458
+ */
459
+ getUserInfo(): Promise<Record<string, unknown>>;
460
+ getClientContext(clientId: string): Promise<HostedClientContext>;
461
+ }
462
+
463
+ declare class TenantsModule {
464
+ private http;
465
+ constructor(http: HttpClient);
466
+ getCurrent(tenantId: string): Promise<TenantInfo>;
467
+ get(tenantId: string): Promise<TenantInfo>;
468
+ list(params?: {
469
+ vendorId?: string;
470
+ }): Promise<TenantInfo[] | TenantInfo | null>;
471
+ create(data: CreateTenantRequest): Promise<TenantInfo>;
472
+ update(tenantId: string, data: UpdateTenantRequest): Promise<TenantInfo>;
473
+ delete(tenantId: string): Promise<{
474
+ message: string;
475
+ }>;
476
+ promoteToVendor(tenantId: string, data: PromoteToVendorRequest): Promise<PromoteToVendorResult>;
477
+ getUsers(tenantId: string): Promise<TenantUser[]>;
478
+ inviteUser(tenantId: string, data: InviteTenantUserRequest): Promise<InviteTenantUserResult>;
479
+ changeUserRole(tenantId: string, userId: string, role: string): Promise<TenantUserRoleUpdate>;
480
+ migrateUser(tenantId: string, userId: string, data: MigrateUserRequest): Promise<{
481
+ message: string;
482
+ }>;
483
+ removeUser(tenantId: string, userId: string): Promise<{
484
+ message: string;
485
+ }>;
486
+ getPasswordPolicy(tenantId: string): Promise<PasswordPolicy>;
487
+ updatePasswordPolicy(tenantId: string, data: Partial<PasswordPolicy>): Promise<PasswordPolicy>;
488
+ getMfaPolicies(tenantId: string): Promise<MfaPolicy[]>;
489
+ updateMfaPolicy(tenantId: string, role: string, data: Partial<MfaPolicy>): Promise<MfaPolicy>;
490
+ getPublicBranding(params?: {
491
+ vendor?: string;
492
+ }): Promise<BrandingConfig | null>;
493
+ getPublicBrandingBySlug(vendorSlug: string): Promise<BrandingConfig | null>;
494
+ }
495
+
496
+ /**
497
+ * SOURCE REFS:
498
+ * - Route file: src/routes/apps.routes.ts (GET /, GET /:appKey, POST /sync)
499
+ * - Service file: src/services/appManifest.service.ts (AppManifest, PermissionNodeManifest, syncManifest)
500
+ * - Service file: src/services/bootstrapApps.ts (manifest shape example)
501
+ * - Verified claims: requires auth + apps.view/apps.manage permissions, platform_admin for sync
502
+ * - Last verified: Phase 0 Research Summary + apps.routes.ts
503
+ */
504
+
505
+ interface CreateAppRequest {
506
+ name: string;
507
+ key?: string;
508
+ description?: string;
509
+ redirectUris?: string[];
510
+ allowedOrigins?: string[];
511
+ mode?: "test" | "live";
512
+ }
513
+ interface CreateAppResponse {
514
+ app: AppInfo & {
515
+ appKey: string;
516
+ };
517
+ client: {
518
+ clientId: string;
519
+ clientSecret: string;
520
+ };
521
+ publishableKey: {
522
+ id: string;
523
+ rawKey: string;
524
+ kid: string;
525
+ };
526
+ secretKey: {
527
+ id: string;
528
+ rawKey: string;
529
+ };
530
+ origins: string[];
531
+ }
532
+ declare class AppsModule {
533
+ private http;
534
+ constructor(http: HttpClient);
535
+ /**
536
+ * Self-service Phase A: provision an app + OIDC client + key pair in one shot.
537
+ * Caller must be authenticated as a tenant_admin (or platform_admin).
538
+ *
539
+ * @remarks Wraps POST /api/v1/apps
540
+ */
541
+ create(data: CreateAppRequest): Promise<CreateAppResponse>;
542
+ update(id: string, data: {
543
+ name?: string;
544
+ description?: string;
545
+ mode?: "test" | "live";
546
+ isActive?: boolean;
547
+ }): Promise<unknown>;
548
+ remove(id: string): Promise<{
549
+ id: string;
550
+ }>;
551
+ listOrigins(id: string): Promise<{
552
+ origins: string[];
553
+ }>;
554
+ addOrigin(id: string, origin: string): Promise<{
555
+ origin: string;
556
+ }>;
557
+ removeOrigin(id: string, origin: string): Promise<{
558
+ removed: boolean;
559
+ }>;
560
+ listKeys(id: string): Promise<Array<{
561
+ id: string;
562
+ kind: string;
563
+ mode: string;
564
+ keyPrefix: string;
565
+ isActive: boolean;
566
+ }>>;
567
+ createKey(id: string, data: {
568
+ kind: "publishable" | "secret";
569
+ mode?: "test" | "live";
570
+ name?: string;
571
+ }): Promise<unknown>;
572
+ rotateKey(id: string, keyId: string): Promise<{
573
+ rawKey: string;
574
+ previousKeyExpiresAt: string | null;
575
+ }>;
576
+ revokeKey(id: string, keyId: string): Promise<{
577
+ revoked: boolean;
578
+ }>;
579
+ /**
580
+ * List all registered applications.
581
+ * Requires `apps.view` permission on the `iqauth-admin` app.
582
+ *
583
+ * @remarks Wraps GET /api/v1/apps
584
+ */
585
+ list(): Promise<AppInfo[]>;
586
+ /**
587
+ * Get a registered application by its unique key, including its permission nodes.
588
+ * Requires `apps.view` permission on the `iqauth-admin` app.
589
+ *
590
+ * @remarks Wraps GET /api/v1/apps/:appKey
591
+ */
592
+ get(appKey: string): Promise<AppInfo & {
593
+ permissionNodes: PermissionNodeInfo[];
594
+ }>;
595
+ /**
596
+ * Register or sync an application manifest. This is an idempotent upsert —
597
+ * it creates the app if it doesn't exist, or updates it if it does.
598
+ * Permission nodes are also upserted (created or updated) from the manifest tree.
599
+ *
600
+ * Requires `platform_admin` role and `apps.manage` permission.
601
+ *
602
+ * @remarks Wraps POST /api/v1/apps/sync
603
+ */
604
+ register(manifest: AppManifest): Promise<AppSyncResult>;
605
+ /**
606
+ * Check if an application is registered by its key.
607
+ * Returns `true` if the app exists, `false` otherwise.
608
+ *
609
+ * @remarks Uses GET /api/v1/apps/:appKey — catches 404 errors
610
+ */
611
+ isRegistered(appKey: string): Promise<boolean>;
612
+ }
613
+
614
+ declare class RolesModule {
615
+ private http;
616
+ constructor(http: HttpClient);
617
+ list(tenantId: string): Promise<Role[]>;
618
+ create(tenantId: string, data: CreateRoleRequest): Promise<Role>;
619
+ update(tenantId: string, roleId: string, data: UpdateRoleRequest): Promise<Role>;
620
+ delete(tenantId: string, roleId: string): Promise<{
621
+ message: string;
622
+ }>;
623
+ getUserRoles(tenantId: string, userId: string): Promise<Role[]>;
624
+ assignRole(tenantId: string, userId: string, data: AssignRoleRequest): Promise<UserRoleAssignment>;
625
+ removeRole(tenantId: string, userId: string, roleId: string): Promise<{
626
+ message: string;
627
+ }>;
628
+ }
629
+
630
+ declare class PermissionGroupsModule {
631
+ private http;
632
+ constructor(http: HttpClient);
633
+ list(tenantId: string): Promise<PermissionGroup[]>;
634
+ create(tenantId: string, name: string, description?: string): Promise<PermissionGroup>;
635
+ update(tenantId: string, groupId: string, data: {
636
+ name?: string;
637
+ description?: string;
638
+ }): Promise<PermissionGroup>;
639
+ delete(tenantId: string, groupId: string): Promise<{
640
+ message: string;
641
+ }>;
642
+ getPermissions(tenantId: string, groupId: string): Promise<GroupPermission[]>;
643
+ addPermission(tenantId: string, groupId: string, data: AddGroupPermissionRequest): Promise<GroupPermission>;
644
+ removePermission(tenantId: string, groupId: string, permissionId: string): Promise<{
645
+ message: string;
646
+ }>;
647
+ addInheritance(tenantId: string, groupId: string, inheritsFromGroupId: string): Promise<InheritanceRelation>;
648
+ removeInheritance(tenantId: string, groupId: string, inheritedGroupId: string): Promise<{
649
+ message: string;
650
+ }>;
651
+ getUserGroups(tenantId: string, userId: string): Promise<PermissionGroup[]>;
652
+ assignUserToGroup(tenantId: string, userId: string, groupId: string): Promise<UserGroupAssignment>;
653
+ removeUserFromGroup(tenantId: string, userId: string, groupId: string): Promise<{
654
+ message: string;
655
+ }>;
656
+ getUserOverrides(tenantId: string, userId: string): Promise<UserPermissionOverride[]>;
657
+ addUserOverride(tenantId: string, userId: string, data: AddUserOverrideRequest): Promise<UserPermissionOverride>;
658
+ removeUserOverride(tenantId: string, userId: string, overrideId: string): Promise<{
659
+ message: string;
660
+ }>;
661
+ getEffectivePermissions(tenantId: string, userId: string, params: {
662
+ product?: string;
663
+ appKey?: string;
664
+ }): Promise<EffectivePermission[]>;
665
+ checkPermission(tenantId: string, userId: string, appKey: string, nodeKey: string): Promise<PermissionCheckResult>;
666
+ }
667
+
668
+ declare class ApiKeysModule {
669
+ private http;
670
+ constructor(http: HttpClient);
671
+ create(data: CreateApiKeyRequest): Promise<CreateApiKeyResult>;
672
+ list(params?: {
673
+ tenantId?: string;
674
+ }): Promise<ApiKeyInfo[]>;
675
+ revoke(id: string): Promise<{
676
+ message: string;
677
+ }>;
678
+ introspect(apiKey: string): Promise<ApiKeyIntrospection>;
679
+ }
680
+
681
+ declare class InvitesModule {
682
+ private http;
683
+ constructor(http: HttpClient);
684
+ create(data: CreateInviteRequest): Promise<{
685
+ invitation: Invitation;
686
+ inviteToken?: string;
687
+ warning?: string;
688
+ }>;
689
+ validate(token: string): Promise<InviteValidation>;
690
+ accept(token: string, data: AcceptInviteRequest): Promise<{
691
+ message: string;
692
+ userId?: string;
693
+ }>;
694
+ }
695
+
696
+ declare class WebhooksModule {
697
+ private http;
698
+ constructor(http: HttpClient);
699
+ createEndpoint(data: CreateWebhookRequest): Promise<CreateWebhookResult>;
700
+ listEndpoints(): Promise<WebhookEndpoint[]>;
701
+ deleteEndpoint(id: string): Promise<{
702
+ message: string;
703
+ }>;
704
+ getDeliveries(endpointId: string): Promise<WebhookDelivery[]>;
705
+ testEndpoint(id: string): Promise<WebhookTestResult>;
706
+ rotateSecret(id: string): Promise<{
707
+ newSecret: string;
708
+ }>;
709
+ }
710
+
711
+ declare class EntitlementsModule {
712
+ private http;
713
+ constructor(http: HttpClient);
714
+ list(tenantId: string): Promise<Entitlement[]>;
715
+ grant(tenantId: string, data: GrantEntitlementRequest): Promise<Entitlement>;
716
+ revoke(tenantId: string, product: string): Promise<{
717
+ message: string;
718
+ }>;
719
+ }
720
+
721
+ declare class VendorsModule {
722
+ private http;
723
+ constructor(http: HttpClient);
724
+ list(): Promise<Vendor[]>;
725
+ get(vendorId: string): Promise<Vendor>;
726
+ create(data: CreateVendorRequest): Promise<Vendor>;
727
+ update(vendorId: string, data: UpdateVendorRequest): Promise<Vendor>;
728
+ delete(vendorId: string): Promise<{
729
+ message: string;
730
+ }>;
731
+ }
732
+
733
+ declare class SourcesModule {
734
+ private http;
735
+ constructor(http: HttpClient);
736
+ create(vendorId: string, data: CreateSourceRequest): Promise<Source>;
737
+ listForVendor(vendorId: string): Promise<Source[]>;
738
+ get(sourceId: string): Promise<Source>;
739
+ update(sourceId: string, data: UpdateSourceRequest): Promise<Source>;
740
+ delete(sourceId: string): Promise<{
741
+ message: string;
742
+ }>;
743
+ createClient(sourceId: string, data: CreateClientRequest): Promise<Client>;
744
+ listClients(sourceId: string): Promise<Client[]>;
745
+ }
746
+
747
+ declare class ClientsModule {
748
+ private http;
749
+ constructor(http: HttpClient);
750
+ get(clientId: string): Promise<Client>;
751
+ update(clientId: string, data: UpdateClientRequest): Promise<Client>;
752
+ delete(clientId: string): Promise<{
753
+ message: string;
754
+ }>;
755
+ }
756
+
757
+ declare class HierarchyModule {
758
+ private http;
759
+ constructor(http: HttpClient);
760
+ getGraph(): Promise<HierarchyVendor[]>;
761
+ linkVendorSource(vendorId: string, sourceId: string): Promise<HierarchyLink>;
762
+ unlinkVendorSource(vendorId: string, sourceId: string): Promise<{
763
+ removed: boolean;
764
+ }>;
765
+ linkSourceClient(sourceId: string, clientId: string): Promise<HierarchyLink>;
766
+ unlinkSourceClient(sourceId: string, clientId: string): Promise<{
767
+ removed: boolean;
768
+ }>;
769
+ }
770
+
771
+ declare class MembershipsModule {
772
+ private http;
773
+ constructor(http: HttpClient);
774
+ listForUser(userId: string, tenantId: string): Promise<{
775
+ memberships: MembershipWithDetails[];
776
+ }>;
777
+ listForScope(scopeType: string, scopeId: string): Promise<{
778
+ memberships: MembershipWithDetails[];
779
+ }>;
780
+ grant(data: CreateMembershipRequest): Promise<Membership>;
781
+ revoke(id: string): Promise<{
782
+ message: string;
783
+ }>;
784
+ update(id: string, data: UpdateMembershipRequest): Promise<Membership>;
785
+ listForTenant(params?: {
786
+ scopeType?: string;
787
+ roleName?: string;
788
+ }): Promise<{
789
+ memberships: MembershipWithDetails[];
790
+ }>;
791
+ }
792
+
793
+ declare class ScopeModule {
794
+ private http;
795
+ constructor(http: HttpClient);
796
+ getAvailable(): Promise<AvailableScopesTree>;
797
+ switchScope(scopeType: string, scopeId: string): Promise<ScopeSwitchResult>;
798
+ }
799
+
800
+ declare class GdprModule {
801
+ private http;
802
+ constructor(http: HttpClient);
803
+ exportData(): Promise<GdprExportData>;
804
+ deleteAccount(confirmEmail: string): Promise<{
805
+ message: string;
806
+ }>;
807
+ }
808
+
809
+ declare class PinModule {
810
+ private http;
811
+ constructor(http: HttpClient);
812
+ set(pin: string): Promise<{
813
+ message: string;
814
+ }>;
815
+ change(currentPin: string, newPin: string): Promise<{
816
+ message: string;
817
+ }>;
818
+ remove(): Promise<{
819
+ message: string;
820
+ }>;
821
+ getStatus(): Promise<PinStatus>;
822
+ login(email: string, pin: string, deviceFingerprint?: string): Promise<LoginResult>;
823
+ }
824
+
825
+ declare class MfaModule {
826
+ private http;
827
+ constructor(http: HttpClient);
828
+ getAvailableMethods(): Promise<MfaAvailableMethods>;
829
+ enrollTotp(): Promise<TotpEnrollResult>;
830
+ verifyTotpEnrollment(code: string, secret: string): Promise<TotpVerifyResult>;
831
+ enrollSms(phoneNumber: string): Promise<SmsEnrollResult>;
832
+ verifySmsEnrollment(code: string, phoneNumber: string): Promise<{
833
+ enrollment: MfaEnrollment;
834
+ }>;
835
+ startEmailEnrollment(): Promise<EmailEnrollResult>;
836
+ verifyEmailEnrollment(code: string): Promise<{
837
+ enrollment: MfaEnrollment;
838
+ }>;
839
+ listEnrollments(): Promise<MfaEnrollment[]>;
840
+ setPrimaryEnrollment(enrollmentId: string): Promise<MfaEnrollment>;
841
+ deactivateEnrollment(enrollmentId: string): Promise<{
842
+ message: string;
843
+ }>;
844
+ regenerateBackupCodes(): Promise<BackupCodesResult>;
845
+ getBackupCodeCount(): Promise<BackupCodeCountResult>;
846
+ }
847
+
848
+ declare class BrandingModule {
849
+ private http;
850
+ constructor(http: HttpClient);
851
+ get(vendorId: string): Promise<BrandingConfig>;
852
+ updateBranding(vendorId: string, data: UpdateBrandingRequest): Promise<BrandingConfig>;
853
+ publishBranding(vendorId: string): Promise<BrandingConfig>;
854
+ unpublishBranding(vendorId: string): Promise<BrandingConfig>;
855
+ resetBranding(vendorId: string): Promise<BrandingConfig>;
856
+ uploadAsset(vendorId: string, data: UploadAssetRequest): Promise<BrandingAsset>;
857
+ listAssets(vendorId: string): Promise<BrandingAsset[]>;
858
+ deleteAsset(vendorId: string, assetId: string): Promise<{
859
+ deleted: boolean;
860
+ }>;
861
+ listDomains(vendorId: string): Promise<BrandingDomainMapping[]>;
862
+ addDomain(vendorId: string, domain: string): Promise<BrandingDomainMapping>;
863
+ removeDomain(vendorId: string, domainId: string): Promise<{
864
+ deleted: boolean;
865
+ }>;
866
+ }
867
+
868
+ declare class IQAuthClient {
869
+ private config;
870
+ private httpClient;
871
+ private _accessToken?;
872
+ private _refreshToken?;
873
+ private _apiKey?;
874
+ readonly auth: AuthModule;
875
+ readonly tokens: TokensModule;
876
+ readonly sessions: SessionsModule;
877
+ readonly users: UsersModule;
878
+ readonly permissions: PermissionsModule;
879
+ readonly oidc: OidcModule;
880
+ readonly tenants: TenantsModule;
881
+ readonly apps: AppsModule;
882
+ readonly roles: RolesModule;
883
+ readonly permissionGroups: PermissionGroupsModule;
884
+ readonly apiKeys: ApiKeysModule;
885
+ readonly invites: InvitesModule;
886
+ readonly webhooks: WebhooksModule;
887
+ readonly entitlements: EntitlementsModule;
888
+ readonly vendors: VendorsModule;
889
+ readonly sources: SourcesModule;
890
+ readonly clients: ClientsModule;
891
+ readonly hierarchy: HierarchyModule;
892
+ readonly memberships: MembershipsModule;
893
+ readonly scope: ScopeModule;
894
+ readonly gdpr: GdprModule;
895
+ readonly pin: PinModule;
896
+ readonly mfa: MfaModule;
897
+ readonly branding: BrandingModule;
898
+ readonly environment: IQAuthEnvironment;
899
+ constructor(config: IQAuthClientConfig);
900
+ static forBrowserSession(config: Omit<IQAuthBrowserSessionClientConfig, "environment">): IQAuthClient;
901
+ static forServer(config: IQAuthTokenClientConfig): IQAuthClient;
902
+ static forMobile(config: IQAuthTokenClientConfig): IQAuthClient;
903
+ static forService(config: IQAuthTokenClientConfig): IQAuthClient;
904
+ setTokens(tokens: TokenPair): void;
905
+ getAccessToken(): string | undefined;
906
+ getRefreshToken(): string | undefined;
907
+ private getCurrentClaims;
908
+ private static resolveEnvironment;
909
+ }
910
+
911
+ export { AuthModule as A, BrandingModule as B, type CreateAppRequest as C, DEFAULT_TOKEN_ISSUER as D, EntitlementsModule as E, GdprModule as G, HierarchyModule as H, IQAuthClient as I, MembershipsModule as M, OidcModule as O, PermissionsModule as P, RolesModule as R, SessionsModule as S, TokensModule as T, UsersModule as U, VendorsModule as V, WebhooksModule as W, InMemoryOidcStateStore as a, type OidcStateStore as b, type OidcStoredRequest as c, type OidcAuthRequest as d, type OidcCallbackResult as e, type OidcModuleOptions as f, DEFAULT_TOKEN_AUDIENCE as g, DEFAULT_CLOCK_TOLERANCE_SECONDS as h, type TokenVerifyOptions as i, type TokensModuleOptions as j, TenantsModule as k, AppsModule as l, type CreateAppResponse as m, PermissionGroupsModule as n, ApiKeysModule as o, InvitesModule as p, SourcesModule as q, ClientsModule as r, ScopeModule as s, PinModule as t, MfaModule as u };