@iqauth/sdk 2.2.0 → 2.5.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.
- package/README.md +134 -0
- package/dist/browser-session.d.mts +3 -3
- package/dist/browser-session.d.ts +3 -3
- package/dist/browser-session.js +89 -68
- package/dist/browser-session.mjs +2 -1
- package/dist/browser.d.mts +64 -29
- package/dist/browser.d.ts +64 -29
- package/dist/browser.js +794 -39
- package/dist/browser.mjs +44 -4
- package/dist/bundle-LUKDQYVQ.mjs +374 -0
- package/dist/chunk-3JULWS6F.mjs +106 -0
- package/dist/chunk-5T7GHBX6.mjs +1165 -0
- package/dist/{chunk-M4J6BPK7.mjs → chunk-6TDJJER7.mjs} +12 -3
- package/dist/{chunk-QZB745C2.mjs → chunk-76W5TLQQ.mjs} +264 -211
- package/dist/{chunk-D72UL5HL.mjs → chunk-BVV54LPI.mjs} +36 -4
- package/dist/chunk-LIZYFXH7.mjs +90 -0
- package/dist/chunk-MKKZULZR.mjs +241 -0
- package/dist/chunk-SL3KRS4W.mjs +54 -0
- package/dist/chunk-TKZTCPEK.mjs +232 -0
- package/dist/chunk-UKZLOHZG.mjs +83 -0
- package/dist/chunk-UNYDG2L4.mjs +209 -0
- package/dist/{chunk-MDUHPQMM.mjs → chunk-W3F4JYGP.mjs} +8 -180
- package/dist/{chunk-QEJB7WEQ.mjs → chunk-WQWBJSSS.mjs} +1 -1
- package/dist/cli/index.js +144 -36
- package/dist/cli/index.mjs +1 -1
- package/dist/{client-DXbHb2ul.d.ts → client-BNQe3AgF.d.ts} +3 -67
- package/dist/{client-Dv4v92Mj.d.mts → client-kYlJFgPv.d.mts} +3 -67
- package/dist/doctor-YYNHNMLD.mjs +198 -0
- package/dist/{express-BZmF1llh.d.mts → express-B6_1vBYZ.d.mts} +23 -2
- package/dist/{express-B4o3P8vK.d.ts → express-CHpfa7D_.d.ts} +23 -2
- package/dist/express.d.mts +77 -6
- package/dist/express.d.ts +77 -6
- package/dist/express.js +336 -74
- package/dist/express.mjs +209 -8
- package/dist/fastify.js +103 -72
- package/dist/fastify.mjs +6 -4
- package/dist/hono.js +102 -72
- package/dist/hono.mjs +5 -4
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +590 -73
- package/dist/index.mjs +30 -8
- package/dist/locales.d.mts +53 -0
- package/dist/locales.d.ts +53 -0
- package/dist/locales.js +1202 -0
- package/dist/locales.mjs +29 -0
- package/dist/mobile.d.mts +3 -3
- package/dist/mobile.d.ts +3 -3
- package/dist/mobile.js +89 -68
- package/dist/mobile.mjs +2 -1
- package/dist/next.d.mts +10 -1
- package/dist/next.d.ts +10 -1
- package/dist/next.js +101 -1618
- package/dist/next.mjs +9 -9
- package/dist/provisioningBridge-88xjOS2n.d.mts +86 -0
- package/dist/provisioningBridge-DnTfzdZK.d.ts +86 -0
- package/dist/react.d.mts +1349 -10
- package/dist/react.d.ts +1349 -10
- package/dist/react.js +2998 -569
- package/dist/react.mjs +1518 -95
- package/dist/reverify-4UEJXUS6.mjs +16 -0
- package/dist/server/handlers.d.mts +12 -1
- package/dist/server/handlers.d.ts +12 -1
- package/dist/server/handlers.js +12 -3
- package/dist/server/handlers.mjs +2 -2
- package/dist/server.d.mts +5 -4
- package/dist/server.d.ts +5 -4
- package/dist/server.js +188 -73
- package/dist/server.mjs +13 -8
- package/dist/service.d.mts +3 -3
- package/dist/service.d.ts +3 -3
- package/dist/service.js +89 -68
- package/dist/service.mjs +2 -1
- package/dist/signIn-CCY4JE5G.mjs +15 -0
- package/dist/{signIn-D_kP3v-c.d.mts → signIn-CiIBTJIh.d.mts} +232 -4
- package/dist/{signIn-BVDTIA_t.d.ts → signIn-OCr88Zf8.d.ts} +232 -4
- package/dist/test.d.mts +86 -0
- package/dist/test.d.ts +86 -0
- package/dist/test.js +289 -0
- package/dist/test.mjs +9 -0
- package/dist/tokens-DCyzzn8L.d.mts +63 -0
- package/dist/tokens-aHiGFr_E.d.ts +63 -0
- package/dist/types-6bNdxesb.d.mts +196 -0
- package/dist/types-6bNdxesb.d.ts +196 -0
- package/dist/{types-Cxl3bQHt.d.ts → types-DZAflmmq.d.mts} +6 -0
- package/dist/{types-Cxl3bQHt.d.mts → types-DZAflmmq.d.ts} +6 -0
- package/dist/webhooks.d.mts +61 -0
- package/dist/webhooks.d.ts +61 -0
- package/dist/webhooks.js +119 -0
- package/dist/webhooks.mjs +11 -0
- package/dist/ws.d.mts +73 -0
- package/dist/ws.d.ts +73 -0
- package/dist/ws.js +397 -0
- package/dist/ws.mjs +12 -0
- package/package.json +24 -3
- package/dist/doctor-XCI77BQS.mjs +0 -90
package/dist/next.mjs
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
handleRefresh,
|
|
4
4
|
handleSignout,
|
|
5
5
|
serializeCookie
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6TDJJER7.mjs";
|
|
7
7
|
import {
|
|
8
8
|
assertPublishableKey
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WQWBJSSS.mjs";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
TokensModule
|
|
12
|
+
} from "./chunk-UNYDG2L4.mjs";
|
|
13
13
|
import "./chunk-6I6RM4MN.mjs";
|
|
14
14
|
import "./chunk-Y6FXYEAI.mjs";
|
|
15
15
|
|
|
@@ -59,7 +59,7 @@ function handler(options) {
|
|
|
59
59
|
if (action === "signout") {
|
|
60
60
|
const auth = req.headers.get("authorization");
|
|
61
61
|
const accessToken = auth && auth.replace(/^Bearer /i, "") || readCookieFromHeader(cookieHeader, accessCookie);
|
|
62
|
-
return toResponse(await handleSignout(helperConfig, { accessToken }));
|
|
62
|
+
return toResponse(await handleSignout(helperConfig, { accessToken, ssoCookieHeader: cookieHeader ?? void 0 }));
|
|
63
63
|
}
|
|
64
64
|
return new Response(JSON.stringify({ success: false, error: { code: "NOT_FOUND", message: `Unknown action: ${action}` } }), {
|
|
65
65
|
status: 404,
|
|
@@ -71,7 +71,7 @@ function createMiddleware(options) {
|
|
|
71
71
|
const parsed = assertPublishableKey(options.publishableKey, { context: "@iqauth/sdk/next createMiddleware" });
|
|
72
72
|
const issuer = (options.issuer ?? (parsed.iss.startsWith("http") ? parsed.iss : `https://${parsed.iss}`)).replace(/\/+$/, "");
|
|
73
73
|
const accessCookie = options.accessCookieName ?? "iqauth_at";
|
|
74
|
-
const
|
|
74
|
+
const tokens = new TokensModule(issuer);
|
|
75
75
|
return async (req) => {
|
|
76
76
|
const auth = req.headers.get("authorization");
|
|
77
77
|
let token;
|
|
@@ -84,7 +84,7 @@ function createMiddleware(options) {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
try {
|
|
87
|
-
await
|
|
87
|
+
await tokens.verify(token);
|
|
88
88
|
return void 0;
|
|
89
89
|
} catch (err) {
|
|
90
90
|
const code = err.code || "TOKEN_INVALID";
|
|
@@ -113,9 +113,9 @@ async function getAuth(options) {
|
|
|
113
113
|
}
|
|
114
114
|
const token = cookieJar?.get(accessCookie)?.value;
|
|
115
115
|
if (!token) return null;
|
|
116
|
-
const
|
|
116
|
+
const tokens = new TokensModule(issuer);
|
|
117
117
|
try {
|
|
118
|
-
return await
|
|
118
|
+
return await tokens.verify(token);
|
|
119
119
|
} catch {
|
|
120
120
|
return null;
|
|
121
121
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { J as JwtClaims } from './types-DZAflmmq.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* createProvisioningBridge — server-side helper that lifts the
|
|
5
|
+
* "provision-on-first-login" pattern out of every downstream app.
|
|
6
|
+
*
|
|
7
|
+
* Pattern (extracted from IQValidate's iqauth-provision.ts):
|
|
8
|
+
* 1. On every authenticated request, look up the local user record by
|
|
9
|
+
* `iqauthUserId` (the `sub` claim from the JWT).
|
|
10
|
+
* 2. If not found, fall back to lookup by `email` and adopt the row by
|
|
11
|
+
* writing the iqauthUserId — handles users that existed locally before
|
|
12
|
+
* IQAuth was integrated.
|
|
13
|
+
* 3. If still not found, INSERT a new local user row from the JWT claims.
|
|
14
|
+
* Race-safe: if a concurrent request already inserted the row
|
|
15
|
+
* (Postgres unique-violation 23505 / SQLite SQLITE_CONSTRAINT), retry
|
|
16
|
+
* the lookup once.
|
|
17
|
+
* 4. Optionally apply a `roleMapper(claims)` to map IQAuth roles into the
|
|
18
|
+
* local app's role enum on insert/update.
|
|
19
|
+
*
|
|
20
|
+
* The factory is db-engine and ORM-agnostic — pass adapters that read/write
|
|
21
|
+
* your local user table. See the JSDoc on each adapter for the contract.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
interface ProvisioningContext<TUser> {
|
|
25
|
+
claims: JwtClaims;
|
|
26
|
+
/** The local user record, looked up or freshly inserted. */
|
|
27
|
+
user: TUser;
|
|
28
|
+
/** True if `user` was just created by this request. */
|
|
29
|
+
created: boolean;
|
|
30
|
+
/** True if `user` existed locally and was adopted by writing iqauthUserId. */
|
|
31
|
+
adopted: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface ProvisioningStorage<TUser> {
|
|
34
|
+
/** Find local user by IQAuth `sub` claim. Returns `null` when not found. */
|
|
35
|
+
findByIqAuthUserId(iqauthUserId: string): Promise<TUser | null>;
|
|
36
|
+
/** Find local user by email (case-insensitive recommended). */
|
|
37
|
+
findByEmail(email: string): Promise<TUser | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Insert a fresh user row from the JWT claims. The implementation should
|
|
40
|
+
* set the local `iqauthUserId` column to `claims.sub` and copy email/name.
|
|
41
|
+
* If a unique-constraint violation fires (concurrent insert), throw the
|
|
42
|
+
* error — the bridge catches it and retries the read. Common Postgres
|
|
43
|
+
* error code is `23505`; SQLite uses `SQLITE_CONSTRAINT_UNIQUE`.
|
|
44
|
+
*/
|
|
45
|
+
insertFromClaims(claims: JwtClaims, mappedRole?: string | null): Promise<TUser>;
|
|
46
|
+
/**
|
|
47
|
+
* Adopt a pre-existing local row (matched by email) by writing the
|
|
48
|
+
* iqauthUserId. Returns the updated user. Optional — when omitted, the
|
|
49
|
+
* bridge falls through to insertFromClaims.
|
|
50
|
+
*/
|
|
51
|
+
adoptByEmail?: (existing: TUser, claims: JwtClaims, mappedRole?: string | null) => Promise<TUser>;
|
|
52
|
+
}
|
|
53
|
+
interface ProvisioningBridgeOptions<TUser> {
|
|
54
|
+
storage: ProvisioningStorage<TUser>;
|
|
55
|
+
/** Map IQAuth role strings into the local app's role on insert/adopt. */
|
|
56
|
+
roleMapper?: (claims: JwtClaims) => string | null | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Heuristic that classifies a thrown DB error as a unique-constraint race.
|
|
59
|
+
* Defaults to checking for Postgres `23505` and SQLite `SQLITE_CONSTRAINT_UNIQUE`.
|
|
60
|
+
*/
|
|
61
|
+
isUniqueViolation?: (err: unknown) => boolean;
|
|
62
|
+
}
|
|
63
|
+
interface ProvisioningBridge<TUser> {
|
|
64
|
+
/**
|
|
65
|
+
* Resolve (or provision) the local user that corresponds to a verified
|
|
66
|
+
* IQAuth JWT. Idempotent and race-safe.
|
|
67
|
+
*/
|
|
68
|
+
ensureUser(claims: JwtClaims): Promise<ProvisioningContext<TUser>>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a provisioning bridge. Returns an `ensureUser(claims)` function that
|
|
72
|
+
* handles lookup → adopt → insert → race-retry. Apps typically wrap this in
|
|
73
|
+
* Express middleware:
|
|
74
|
+
*
|
|
75
|
+
* const bridge = createProvisioningBridge({ storage, roleMapper });
|
|
76
|
+
* app.use(iqAuth({ ... }));
|
|
77
|
+
* app.use(async (req, _res, next) => {
|
|
78
|
+
* if (!req.auth) return next();
|
|
79
|
+
* const ctx = await bridge.ensureUser(req.auth);
|
|
80
|
+
* (req as any).localUser = ctx.user;
|
|
81
|
+
* next();
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
declare function createProvisioningBridge<TUser>(options: ProvisioningBridgeOptions<TUser>): ProvisioningBridge<TUser>;
|
|
85
|
+
|
|
86
|
+
export { type ProvisioningBridge as P, type ProvisioningBridgeOptions as a, type ProvisioningStorage as b, createProvisioningBridge as c, type ProvisioningContext as d };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { J as JwtClaims } from './types-DZAflmmq.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* createProvisioningBridge — server-side helper that lifts the
|
|
5
|
+
* "provision-on-first-login" pattern out of every downstream app.
|
|
6
|
+
*
|
|
7
|
+
* Pattern (extracted from IQValidate's iqauth-provision.ts):
|
|
8
|
+
* 1. On every authenticated request, look up the local user record by
|
|
9
|
+
* `iqauthUserId` (the `sub` claim from the JWT).
|
|
10
|
+
* 2. If not found, fall back to lookup by `email` and adopt the row by
|
|
11
|
+
* writing the iqauthUserId — handles users that existed locally before
|
|
12
|
+
* IQAuth was integrated.
|
|
13
|
+
* 3. If still not found, INSERT a new local user row from the JWT claims.
|
|
14
|
+
* Race-safe: if a concurrent request already inserted the row
|
|
15
|
+
* (Postgres unique-violation 23505 / SQLite SQLITE_CONSTRAINT), retry
|
|
16
|
+
* the lookup once.
|
|
17
|
+
* 4. Optionally apply a `roleMapper(claims)` to map IQAuth roles into the
|
|
18
|
+
* local app's role enum on insert/update.
|
|
19
|
+
*
|
|
20
|
+
* The factory is db-engine and ORM-agnostic — pass adapters that read/write
|
|
21
|
+
* your local user table. See the JSDoc on each adapter for the contract.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
interface ProvisioningContext<TUser> {
|
|
25
|
+
claims: JwtClaims;
|
|
26
|
+
/** The local user record, looked up or freshly inserted. */
|
|
27
|
+
user: TUser;
|
|
28
|
+
/** True if `user` was just created by this request. */
|
|
29
|
+
created: boolean;
|
|
30
|
+
/** True if `user` existed locally and was adopted by writing iqauthUserId. */
|
|
31
|
+
adopted: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface ProvisioningStorage<TUser> {
|
|
34
|
+
/** Find local user by IQAuth `sub` claim. Returns `null` when not found. */
|
|
35
|
+
findByIqAuthUserId(iqauthUserId: string): Promise<TUser | null>;
|
|
36
|
+
/** Find local user by email (case-insensitive recommended). */
|
|
37
|
+
findByEmail(email: string): Promise<TUser | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Insert a fresh user row from the JWT claims. The implementation should
|
|
40
|
+
* set the local `iqauthUserId` column to `claims.sub` and copy email/name.
|
|
41
|
+
* If a unique-constraint violation fires (concurrent insert), throw the
|
|
42
|
+
* error — the bridge catches it and retries the read. Common Postgres
|
|
43
|
+
* error code is `23505`; SQLite uses `SQLITE_CONSTRAINT_UNIQUE`.
|
|
44
|
+
*/
|
|
45
|
+
insertFromClaims(claims: JwtClaims, mappedRole?: string | null): Promise<TUser>;
|
|
46
|
+
/**
|
|
47
|
+
* Adopt a pre-existing local row (matched by email) by writing the
|
|
48
|
+
* iqauthUserId. Returns the updated user. Optional — when omitted, the
|
|
49
|
+
* bridge falls through to insertFromClaims.
|
|
50
|
+
*/
|
|
51
|
+
adoptByEmail?: (existing: TUser, claims: JwtClaims, mappedRole?: string | null) => Promise<TUser>;
|
|
52
|
+
}
|
|
53
|
+
interface ProvisioningBridgeOptions<TUser> {
|
|
54
|
+
storage: ProvisioningStorage<TUser>;
|
|
55
|
+
/** Map IQAuth role strings into the local app's role on insert/adopt. */
|
|
56
|
+
roleMapper?: (claims: JwtClaims) => string | null | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Heuristic that classifies a thrown DB error as a unique-constraint race.
|
|
59
|
+
* Defaults to checking for Postgres `23505` and SQLite `SQLITE_CONSTRAINT_UNIQUE`.
|
|
60
|
+
*/
|
|
61
|
+
isUniqueViolation?: (err: unknown) => boolean;
|
|
62
|
+
}
|
|
63
|
+
interface ProvisioningBridge<TUser> {
|
|
64
|
+
/**
|
|
65
|
+
* Resolve (or provision) the local user that corresponds to a verified
|
|
66
|
+
* IQAuth JWT. Idempotent and race-safe.
|
|
67
|
+
*/
|
|
68
|
+
ensureUser(claims: JwtClaims): Promise<ProvisioningContext<TUser>>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a provisioning bridge. Returns an `ensureUser(claims)` function that
|
|
72
|
+
* handles lookup → adopt → insert → race-retry. Apps typically wrap this in
|
|
73
|
+
* Express middleware:
|
|
74
|
+
*
|
|
75
|
+
* const bridge = createProvisioningBridge({ storage, roleMapper });
|
|
76
|
+
* app.use(iqAuth({ ... }));
|
|
77
|
+
* app.use(async (req, _res, next) => {
|
|
78
|
+
* if (!req.auth) return next();
|
|
79
|
+
* const ctx = await bridge.ensureUser(req.auth);
|
|
80
|
+
* (req as any).localUser = ctx.user;
|
|
81
|
+
* next();
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
declare function createProvisioningBridge<TUser>(options: ProvisioningBridgeOptions<TUser>): ProvisioningBridge<TUser>;
|
|
85
|
+
|
|
86
|
+
export { type ProvisioningBridge as P, type ProvisioningBridgeOptions as a, type ProvisioningStorage as b, createProvisioningBridge as c, type ProvisioningContext as d };
|