@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/dist/next.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import {
2
+ handleCallback,
3
+ handleRefresh,
4
+ handleSignout,
5
+ serializeCookie
6
+ } from "./chunk-5HF3OBNO.mjs";
7
+ import {
8
+ parsePublishableKey
9
+ } from "./chunk-5WFR6Y33.mjs";
10
+ import {
11
+ IQAuthClient
12
+ } from "./chunk-JQWYIIIS.mjs";
13
+ import "./chunk-6I6RM4MN.mjs";
14
+ import "./chunk-Y6FXYEAI.mjs";
15
+
16
+ // src/next.ts
17
+ function readCookieFromHeader(header, name) {
18
+ if (!header) return void 0;
19
+ const target = `${name}=`;
20
+ for (const seg of header.split(";")) {
21
+ const t = seg.trim();
22
+ if (t.startsWith(target)) {
23
+ try {
24
+ return decodeURIComponent(t.slice(target.length));
25
+ } catch {
26
+ return t.slice(target.length);
27
+ }
28
+ }
29
+ }
30
+ return void 0;
31
+ }
32
+ function toResponse(hr) {
33
+ const headers = new Headers({ "Content-Type": "application/json" });
34
+ for (const c of hr.cookies) headers.append("set-cookie", serializeCookie(c));
35
+ return new Response(JSON.stringify(hr.body), { status: hr.status, headers });
36
+ }
37
+ function handler(options) {
38
+ const parsed = parsePublishableKey(options.publishableKey);
39
+ if (!parsed) throw new Error("@iqauth/sdk/next: invalid publishable key");
40
+ const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
41
+ const helperConfig = { ...options, issuer };
42
+ const accessCookie = options.accessCookieName ?? "iqauth_at";
43
+ const refreshCookie = options.refreshCookieName ?? "iqauth_rt";
44
+ return async (req) => {
45
+ const url = new URL(req.url);
46
+ const action = url.pathname.split("/").pop();
47
+ const body = await req.json().catch(() => ({}));
48
+ const cookieHeader = req.headers.get("cookie");
49
+ if (action === "callback") {
50
+ return toResponse(await handleCallback(helperConfig, {
51
+ code: body.code,
52
+ codeVerifier: body.codeVerifier,
53
+ redirectUri: body.redirectUri
54
+ }));
55
+ }
56
+ if (action === "refresh") {
57
+ const refreshToken = body.refreshToken || readCookieFromHeader(cookieHeader, refreshCookie);
58
+ return toResponse(await handleRefresh(helperConfig, { refreshToken }));
59
+ }
60
+ if (action === "signout") {
61
+ const auth = req.headers.get("authorization");
62
+ const accessToken = auth && auth.replace(/^Bearer /i, "") || readCookieFromHeader(cookieHeader, accessCookie);
63
+ return toResponse(await handleSignout(helperConfig, { accessToken }));
64
+ }
65
+ return new Response(JSON.stringify({ success: false, error: { code: "NOT_FOUND", message: `Unknown action: ${action}` } }), {
66
+ status: 404,
67
+ headers: { "Content-Type": "application/json" }
68
+ });
69
+ };
70
+ }
71
+ function createMiddleware(options) {
72
+ const parsed = parsePublishableKey(options.publishableKey);
73
+ if (!parsed) throw new Error("@iqauth/sdk/next: invalid publishable key");
74
+ const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
75
+ const accessCookie = options.accessCookieName ?? "iqauth_at";
76
+ const client = new IQAuthClient({ baseUrl: issuer, environment: "server" });
77
+ return async (req) => {
78
+ const auth = req.headers.get("authorization");
79
+ let token;
80
+ if (auth && auth.startsWith("Bearer ")) token = auth.slice(7);
81
+ if (!token) token = readCookieFromHeader(req.headers.get("cookie"), accessCookie);
82
+ if (!token) {
83
+ return new Response(JSON.stringify({ success: false, error: { code: "TOKEN_INVALID", message: "Missing access token" } }), {
84
+ status: 401,
85
+ headers: { "Content-Type": "application/json" }
86
+ });
87
+ }
88
+ try {
89
+ await client.tokens.verify(token);
90
+ return void 0;
91
+ } catch (err) {
92
+ const code = err.code || "TOKEN_INVALID";
93
+ return new Response(JSON.stringify({ success: false, error: { code, message: "Authentication failed" } }), {
94
+ status: 401,
95
+ headers: { "Content-Type": "application/json" }
96
+ });
97
+ }
98
+ };
99
+ }
100
+ async function getAuth(options) {
101
+ const parsed = parsePublishableKey(options.publishableKey);
102
+ if (!parsed) throw new Error("@iqauth/sdk/next: invalid publishable key");
103
+ const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
104
+ const accessCookie = options.accessCookieName ?? "iqauth_at";
105
+ let cookieJar = null;
106
+ try {
107
+ const specifier = ["next", "headers"].join("/");
108
+ const mod = await import(
109
+ /* @vite-ignore */
110
+ /* webpackIgnore: true */
111
+ specifier
112
+ );
113
+ cookieJar = mod.cookies ? mod.cookies() : null;
114
+ } catch {
115
+ cookieJar = null;
116
+ }
117
+ const token = cookieJar?.get(accessCookie)?.value;
118
+ if (!token) return null;
119
+ const client = new IQAuthClient({ baseUrl: issuer, environment: "server" });
120
+ try {
121
+ return await client.tokens.verify(token);
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ export {
127
+ createMiddleware,
128
+ getAuth,
129
+ handler
130
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Publishable key codec — browser-safe, no Node deps.
3
+ *
4
+ * Format: pk_<env>_<base64url(JSON{iss,appId,tenantId,kid})>
5
+ *
6
+ * Mirrors the server-side codec at src/lib/publishableKey.ts. Keep in sync.
7
+ */
8
+ type KeyMode = "test" | "live";
9
+ interface PublishableKeyPayload {
10
+ iss: string;
11
+ appId: string;
12
+ tenantId: string;
13
+ kid: string;
14
+ }
15
+ interface ParsedPublishableKey extends PublishableKeyPayload {
16
+ mode: KeyMode;
17
+ raw: string;
18
+ }
19
+ declare function encodePublishableKey(mode: KeyMode, payload: PublishableKeyPayload): string;
20
+ declare function parsePublishableKey(raw: string): ParsedPublishableKey | null;
21
+ declare function isPublishableKey(raw: string): boolean;
22
+ declare function isSecretKey(raw: string): boolean;
23
+
24
+ export { type KeyMode as K, type PublishableKeyPayload as P, isSecretKey as a, type ParsedPublishableKey as b, encodePublishableKey as e, isPublishableKey as i, parsePublishableKey as p };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Publishable key codec — browser-safe, no Node deps.
3
+ *
4
+ * Format: pk_<env>_<base64url(JSON{iss,appId,tenantId,kid})>
5
+ *
6
+ * Mirrors the server-side codec at src/lib/publishableKey.ts. Keep in sync.
7
+ */
8
+ type KeyMode = "test" | "live";
9
+ interface PublishableKeyPayload {
10
+ iss: string;
11
+ appId: string;
12
+ tenantId: string;
13
+ kid: string;
14
+ }
15
+ interface ParsedPublishableKey extends PublishableKeyPayload {
16
+ mode: KeyMode;
17
+ raw: string;
18
+ }
19
+ declare function encodePublishableKey(mode: KeyMode, payload: PublishableKeyPayload): string;
20
+ declare function parsePublishableKey(raw: string): ParsedPublishableKey | null;
21
+ declare function isPublishableKey(raw: string): boolean;
22
+ declare function isSecretKey(raw: string): boolean;
23
+
24
+ export { type KeyMode as K, type PublishableKeyPayload as P, isSecretKey as a, type ParsedPublishableKey as b, encodePublishableKey as e, isPublishableKey as i, parsePublishableKey as p };
@@ -0,0 +1,196 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { S as SessionManager, a as SessionSnapshot, b as SignInOptions, c as SignOutOptions, C as CallbackResult } from './signIn-C8f6qVjD.mjs';
5
+ import { d as SessionUser, J as JwtClaims } from './types-Cxl3bQHt.mjs';
6
+ import './publishableKey-B5DIK81A.mjs';
7
+
8
+ interface IQAuthContextValue {
9
+ manager: SessionManager;
10
+ snapshot: SessionSnapshot;
11
+ }
12
+ interface IQAuthProviderProps {
13
+ publishableKey: string;
14
+ /** Override the IQAuth issuer URL. Inferred from the key by default. */
15
+ issuer?: string;
16
+ /** Disable cross-tab broadcast (rarely useful; primarily for tests). */
17
+ channelName?: string;
18
+ /** Disable proactive ~60s-before-expiry refresh. */
19
+ proactiveRefresh?: boolean;
20
+ /** Optional pre-built manager (advanced; tests). */
21
+ manager?: SessionManager;
22
+ children?: ReactNode;
23
+ }
24
+ /**
25
+ * Boots the IQAuth browser SDK from a single publishable key. Provides the
26
+ * session context to all hooks and gating components below it. Strict-mode
27
+ * safe — a single SessionManager instance is created per provider and reused
28
+ * across remounts.
29
+ */
30
+ declare function IQAuthProvider({ publishableKey, issuer, channelName, proactiveRefresh, manager: externalManager, children, }: IQAuthProviderProps): React.FunctionComponentElement<React.ProviderProps<IQAuthContextValue | null>>;
31
+ interface SessionError {
32
+ code: string;
33
+ message: string;
34
+ }
35
+ interface UseUserResult {
36
+ isLoaded: boolean;
37
+ isSignedIn: boolean;
38
+ user: SessionUser | null;
39
+ error: SessionError | null;
40
+ }
41
+ declare function useUser(): UseUserResult;
42
+ interface UseSessionResult {
43
+ isLoaded: boolean;
44
+ isSignedIn: boolean;
45
+ claims: JwtClaims | null;
46
+ accessToken: string | null;
47
+ error: SessionError | null;
48
+ }
49
+ declare function useSession(): UseSessionResult;
50
+ interface UseAuthResult {
51
+ isLoaded: boolean;
52
+ isSignedIn: boolean;
53
+ userId: string | null;
54
+ tenantId: string | null;
55
+ error: SessionError | null;
56
+ signIn: (opts?: SignInOptions) => Promise<void>;
57
+ signOut: (opts?: SignOutOptions) => Promise<void>;
58
+ redirectToSignIn: (opts?: SignInOptions) => Promise<void>;
59
+ getToken: () => Promise<string | null>;
60
+ fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
61
+ }
62
+ declare function useAuth(): UseAuthResult;
63
+ interface UseOrganizationResult {
64
+ isLoaded: boolean;
65
+ organization: {
66
+ id: string;
67
+ tenantId: string;
68
+ } | null;
69
+ error: SessionError | null;
70
+ }
71
+ /**
72
+ * In IQAuth a "tenant" is the closest analog to Clerk's organization. This
73
+ * hook returns the tenant the active session is scoped to.
74
+ */
75
+ declare function useOrganization(): UseOrganizationResult;
76
+ /**
77
+ * Returns a fetch-like function that auto-attaches the access token and
78
+ * coordinates refresh. Identical to `useAuth().fetch` but exposed as its own
79
+ * hook for ergonomic destructuring.
80
+ */
81
+ declare function useAuthFetch(): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
82
+ declare function SignedIn({ children }: {
83
+ children?: ReactNode;
84
+ }): React.FunctionComponentElement<{
85
+ children?: ReactNode | undefined;
86
+ }> | null;
87
+ declare function SignedOut({ children }: {
88
+ children?: ReactNode;
89
+ }): React.FunctionComponentElement<{
90
+ children?: ReactNode | undefined;
91
+ }> | null;
92
+ interface RedirectToSignInProps extends SignInOptions {
93
+ }
94
+ declare function RedirectToSignIn(props?: RedirectToSignInProps): null;
95
+ /**
96
+ * Drop-in callback route. Mount at the path you registered as your
97
+ * `redirect_uri` (e.g. `/auth/callback`) and the SDK will exchange the code
98
+ * and navigate to the original `return_to`.
99
+ */
100
+ interface AuthCallbackProps {
101
+ /** Override the default `window.location.replace` navigation. */
102
+ onComplete?: (result: CallbackResult) => void;
103
+ /** Render while the exchange is in flight. */
104
+ fallback?: ReactNode;
105
+ }
106
+ declare function AuthCallback({ onComplete, fallback }?: AuthCallbackProps): React.FunctionComponentElement<{
107
+ children?: ReactNode | undefined;
108
+ }>;
109
+ interface IQAuthBranding {
110
+ brandName: string | null;
111
+ logoUrl: string | null;
112
+ loginHeadline: string | null;
113
+ loginSubheadline: string | null;
114
+ primaryColor: string | null;
115
+ accentColor: string | null;
116
+ backgroundColor: string | null;
117
+ surfaceColor: string | null;
118
+ textColor: string | null;
119
+ supportEmail?: string | null;
120
+ supportUrl?: string | null;
121
+ termsUrl?: string | null;
122
+ privacyUrl?: string | null;
123
+ }
124
+ interface IQAuthSignInContext {
125
+ app: {
126
+ id: string;
127
+ key: string;
128
+ name: string;
129
+ tenantId: string | null;
130
+ mode: string;
131
+ defaultClientId: string | null;
132
+ };
133
+ providers?: {
134
+ google?: boolean;
135
+ };
136
+ allowedOrigins: string[];
137
+ returnAllowed: boolean;
138
+ branding: IQAuthBranding | null;
139
+ }
140
+ interface SharedComponentProps {
141
+ /** Base URL of the IQAuth service (e.g. https://auth.dispositioniq.com). */
142
+ iqAuthBaseUrl: string;
143
+ /** App key registered via Phase A's POST /api/v1/apps. */
144
+ appKey: string;
145
+ /** Optional className for the outer wrapper. */
146
+ className?: string;
147
+ }
148
+ /**
149
+ * Hook that loads the public sign-in context for an app (branding + allowed origins).
150
+ */
151
+ declare function useIQAuthSignInContext(iqAuthBaseUrl: string, appKey: string, returnTo: string): {
152
+ ctx: IQAuthSignInContext | null;
153
+ loading: boolean;
154
+ error: string | null;
155
+ };
156
+ interface SignInProps extends SharedComponentProps {
157
+ /** URL the IQAuth backend should redirect back to with `?code=...`. Must be in the app's allowed_origins. */
158
+ returnTo: string;
159
+ /** Called after successful redirect. By default, `window.location.href = url`. */
160
+ onRedirect?: (url: string) => void;
161
+ }
162
+ declare function SignIn({ iqAuthBaseUrl, appKey, returnTo, onRedirect, className }: SignInProps): react_jsx_runtime.JSX.Element;
163
+ interface SignUpProps extends SharedComponentProps {
164
+ returnTo?: string;
165
+ onSuccess?: () => void;
166
+ }
167
+ declare function SignUp({ iqAuthBaseUrl, appKey, returnTo, onSuccess, className }: SignUpProps): react_jsx_runtime.JSX.Element;
168
+ interface UserSummary {
169
+ sub: string;
170
+ email: string;
171
+ name: string;
172
+ picture?: string | null;
173
+ }
174
+ interface UserButtonProps {
175
+ iqAuthBaseUrl: string;
176
+ /** Where to send the user when they click "Account". Defaults to `${iqAuthBaseUrl}/account`. */
177
+ accountUrl?: string;
178
+ /** Called after sign-out. Defaults to navigating to /sign-in if a returnTo+appKey are provided, else `window.location.reload()`. */
179
+ onSignOut?: () => void;
180
+ className?: string;
181
+ }
182
+ declare function UserButton({ iqAuthBaseUrl, accountUrl, onSignOut, className }: UserButtonProps): react_jsx_runtime.JSX.Element | null;
183
+ interface UserProfileProps {
184
+ iqAuthBaseUrl: string;
185
+ className?: string;
186
+ }
187
+ declare function UserProfile({ iqAuthBaseUrl, className }: UserProfileProps): react_jsx_runtime.JSX.Element;
188
+ interface OrganizationSwitcherProps {
189
+ iqAuthBaseUrl: string;
190
+ onSwitched?: (tenantId: string) => void;
191
+ className?: string;
192
+ }
193
+ declare function OrganizationSwitcher({ iqAuthBaseUrl, onSwitched, className }: OrganizationSwitcherProps): react_jsx_runtime.JSX.Element;
194
+ declare const __version__ = "phase-bc-1.0.0";
195
+
196
+ export { AuthCallback, type AuthCallbackProps, type IQAuthBranding, IQAuthProvider, type IQAuthProviderProps, type IQAuthSignInContext, OrganizationSwitcher, type OrganizationSwitcherProps, RedirectToSignIn, type RedirectToSignInProps, type SessionError, type SharedComponentProps, SignIn, type SignInProps, SignUp, type SignUpProps, SignedIn, SignedOut, type UseAuthResult, type UseOrganizationResult, type UseSessionResult, type UseUserResult, UserButton, type UserButtonProps, UserProfile, type UserProfileProps, type UserSummary, __version__, useAuth, useAuthFetch, useIQAuthSignInContext, useOrganization, useSession, useUser };
@@ -0,0 +1,196 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { S as SessionManager, a as SessionSnapshot, b as SignInOptions, c as SignOutOptions, C as CallbackResult } from './signIn-Cy2lbEXb.js';
5
+ import { d as SessionUser, J as JwtClaims } from './types-Cxl3bQHt.js';
6
+ import './publishableKey-B5DIK81A.js';
7
+
8
+ interface IQAuthContextValue {
9
+ manager: SessionManager;
10
+ snapshot: SessionSnapshot;
11
+ }
12
+ interface IQAuthProviderProps {
13
+ publishableKey: string;
14
+ /** Override the IQAuth issuer URL. Inferred from the key by default. */
15
+ issuer?: string;
16
+ /** Disable cross-tab broadcast (rarely useful; primarily for tests). */
17
+ channelName?: string;
18
+ /** Disable proactive ~60s-before-expiry refresh. */
19
+ proactiveRefresh?: boolean;
20
+ /** Optional pre-built manager (advanced; tests). */
21
+ manager?: SessionManager;
22
+ children?: ReactNode;
23
+ }
24
+ /**
25
+ * Boots the IQAuth browser SDK from a single publishable key. Provides the
26
+ * session context to all hooks and gating components below it. Strict-mode
27
+ * safe — a single SessionManager instance is created per provider and reused
28
+ * across remounts.
29
+ */
30
+ declare function IQAuthProvider({ publishableKey, issuer, channelName, proactiveRefresh, manager: externalManager, children, }: IQAuthProviderProps): React.FunctionComponentElement<React.ProviderProps<IQAuthContextValue | null>>;
31
+ interface SessionError {
32
+ code: string;
33
+ message: string;
34
+ }
35
+ interface UseUserResult {
36
+ isLoaded: boolean;
37
+ isSignedIn: boolean;
38
+ user: SessionUser | null;
39
+ error: SessionError | null;
40
+ }
41
+ declare function useUser(): UseUserResult;
42
+ interface UseSessionResult {
43
+ isLoaded: boolean;
44
+ isSignedIn: boolean;
45
+ claims: JwtClaims | null;
46
+ accessToken: string | null;
47
+ error: SessionError | null;
48
+ }
49
+ declare function useSession(): UseSessionResult;
50
+ interface UseAuthResult {
51
+ isLoaded: boolean;
52
+ isSignedIn: boolean;
53
+ userId: string | null;
54
+ tenantId: string | null;
55
+ error: SessionError | null;
56
+ signIn: (opts?: SignInOptions) => Promise<void>;
57
+ signOut: (opts?: SignOutOptions) => Promise<void>;
58
+ redirectToSignIn: (opts?: SignInOptions) => Promise<void>;
59
+ getToken: () => Promise<string | null>;
60
+ fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
61
+ }
62
+ declare function useAuth(): UseAuthResult;
63
+ interface UseOrganizationResult {
64
+ isLoaded: boolean;
65
+ organization: {
66
+ id: string;
67
+ tenantId: string;
68
+ } | null;
69
+ error: SessionError | null;
70
+ }
71
+ /**
72
+ * In IQAuth a "tenant" is the closest analog to Clerk's organization. This
73
+ * hook returns the tenant the active session is scoped to.
74
+ */
75
+ declare function useOrganization(): UseOrganizationResult;
76
+ /**
77
+ * Returns a fetch-like function that auto-attaches the access token and
78
+ * coordinates refresh. Identical to `useAuth().fetch` but exposed as its own
79
+ * hook for ergonomic destructuring.
80
+ */
81
+ declare function useAuthFetch(): (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
82
+ declare function SignedIn({ children }: {
83
+ children?: ReactNode;
84
+ }): React.FunctionComponentElement<{
85
+ children?: ReactNode | undefined;
86
+ }> | null;
87
+ declare function SignedOut({ children }: {
88
+ children?: ReactNode;
89
+ }): React.FunctionComponentElement<{
90
+ children?: ReactNode | undefined;
91
+ }> | null;
92
+ interface RedirectToSignInProps extends SignInOptions {
93
+ }
94
+ declare function RedirectToSignIn(props?: RedirectToSignInProps): null;
95
+ /**
96
+ * Drop-in callback route. Mount at the path you registered as your
97
+ * `redirect_uri` (e.g. `/auth/callback`) and the SDK will exchange the code
98
+ * and navigate to the original `return_to`.
99
+ */
100
+ interface AuthCallbackProps {
101
+ /** Override the default `window.location.replace` navigation. */
102
+ onComplete?: (result: CallbackResult) => void;
103
+ /** Render while the exchange is in flight. */
104
+ fallback?: ReactNode;
105
+ }
106
+ declare function AuthCallback({ onComplete, fallback }?: AuthCallbackProps): React.FunctionComponentElement<{
107
+ children?: ReactNode | undefined;
108
+ }>;
109
+ interface IQAuthBranding {
110
+ brandName: string | null;
111
+ logoUrl: string | null;
112
+ loginHeadline: string | null;
113
+ loginSubheadline: string | null;
114
+ primaryColor: string | null;
115
+ accentColor: string | null;
116
+ backgroundColor: string | null;
117
+ surfaceColor: string | null;
118
+ textColor: string | null;
119
+ supportEmail?: string | null;
120
+ supportUrl?: string | null;
121
+ termsUrl?: string | null;
122
+ privacyUrl?: string | null;
123
+ }
124
+ interface IQAuthSignInContext {
125
+ app: {
126
+ id: string;
127
+ key: string;
128
+ name: string;
129
+ tenantId: string | null;
130
+ mode: string;
131
+ defaultClientId: string | null;
132
+ };
133
+ providers?: {
134
+ google?: boolean;
135
+ };
136
+ allowedOrigins: string[];
137
+ returnAllowed: boolean;
138
+ branding: IQAuthBranding | null;
139
+ }
140
+ interface SharedComponentProps {
141
+ /** Base URL of the IQAuth service (e.g. https://auth.dispositioniq.com). */
142
+ iqAuthBaseUrl: string;
143
+ /** App key registered via Phase A's POST /api/v1/apps. */
144
+ appKey: string;
145
+ /** Optional className for the outer wrapper. */
146
+ className?: string;
147
+ }
148
+ /**
149
+ * Hook that loads the public sign-in context for an app (branding + allowed origins).
150
+ */
151
+ declare function useIQAuthSignInContext(iqAuthBaseUrl: string, appKey: string, returnTo: string): {
152
+ ctx: IQAuthSignInContext | null;
153
+ loading: boolean;
154
+ error: string | null;
155
+ };
156
+ interface SignInProps extends SharedComponentProps {
157
+ /** URL the IQAuth backend should redirect back to with `?code=...`. Must be in the app's allowed_origins. */
158
+ returnTo: string;
159
+ /** Called after successful redirect. By default, `window.location.href = url`. */
160
+ onRedirect?: (url: string) => void;
161
+ }
162
+ declare function SignIn({ iqAuthBaseUrl, appKey, returnTo, onRedirect, className }: SignInProps): react_jsx_runtime.JSX.Element;
163
+ interface SignUpProps extends SharedComponentProps {
164
+ returnTo?: string;
165
+ onSuccess?: () => void;
166
+ }
167
+ declare function SignUp({ iqAuthBaseUrl, appKey, returnTo, onSuccess, className }: SignUpProps): react_jsx_runtime.JSX.Element;
168
+ interface UserSummary {
169
+ sub: string;
170
+ email: string;
171
+ name: string;
172
+ picture?: string | null;
173
+ }
174
+ interface UserButtonProps {
175
+ iqAuthBaseUrl: string;
176
+ /** Where to send the user when they click "Account". Defaults to `${iqAuthBaseUrl}/account`. */
177
+ accountUrl?: string;
178
+ /** Called after sign-out. Defaults to navigating to /sign-in if a returnTo+appKey are provided, else `window.location.reload()`. */
179
+ onSignOut?: () => void;
180
+ className?: string;
181
+ }
182
+ declare function UserButton({ iqAuthBaseUrl, accountUrl, onSignOut, className }: UserButtonProps): react_jsx_runtime.JSX.Element | null;
183
+ interface UserProfileProps {
184
+ iqAuthBaseUrl: string;
185
+ className?: string;
186
+ }
187
+ declare function UserProfile({ iqAuthBaseUrl, className }: UserProfileProps): react_jsx_runtime.JSX.Element;
188
+ interface OrganizationSwitcherProps {
189
+ iqAuthBaseUrl: string;
190
+ onSwitched?: (tenantId: string) => void;
191
+ className?: string;
192
+ }
193
+ declare function OrganizationSwitcher({ iqAuthBaseUrl, onSwitched, className }: OrganizationSwitcherProps): react_jsx_runtime.JSX.Element;
194
+ declare const __version__ = "phase-bc-1.0.0";
195
+
196
+ export { AuthCallback, type AuthCallbackProps, type IQAuthBranding, IQAuthProvider, type IQAuthProviderProps, type IQAuthSignInContext, OrganizationSwitcher, type OrganizationSwitcherProps, RedirectToSignIn, type RedirectToSignInProps, type SessionError, type SharedComponentProps, SignIn, type SignInProps, SignUp, type SignUpProps, SignedIn, SignedOut, type UseAuthResult, type UseOrganizationResult, type UseSessionResult, type UseUserResult, UserButton, type UserButtonProps, UserProfile, type UserProfileProps, type UserSummary, __version__, useAuth, useAuthFetch, useIQAuthSignInContext, useOrganization, useSession, useUser };