@iqauth/sdk 2.3.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.
Files changed (87) hide show
  1. package/README.md +110 -0
  2. package/dist/browser-session.d.mts +3 -2
  3. package/dist/browser-session.d.ts +3 -2
  4. package/dist/browser.d.mts +64 -29
  5. package/dist/browser.d.ts +64 -29
  6. package/dist/browser.js +782 -38
  7. package/dist/browser.mjs +43 -3
  8. package/dist/bundle-LUKDQYVQ.mjs +374 -0
  9. package/dist/chunk-3JULWS6F.mjs +106 -0
  10. package/dist/chunk-5T7GHBX6.mjs +1165 -0
  11. package/dist/{chunk-KGEPDXHU.mjs → chunk-6TDJJER7.mjs} +2 -2
  12. package/dist/{chunk-RACIPVLD.mjs → chunk-76W5TLQQ.mjs} +262 -220
  13. package/dist/{chunk-EKTNEZIH.mjs → chunk-BVV54LPI.mjs} +37 -5
  14. package/dist/chunk-LIZYFXH7.mjs +90 -0
  15. package/dist/chunk-MKKZULZR.mjs +241 -0
  16. package/dist/chunk-SL3KRS4W.mjs +54 -0
  17. package/dist/chunk-TKZTCPEK.mjs +232 -0
  18. package/dist/chunk-UKZLOHZG.mjs +83 -0
  19. package/dist/cli/index.js +144 -36
  20. package/dist/cli/index.mjs +1 -1
  21. package/dist/{client-DTX4hNdS.d.ts → client-BNQe3AgF.d.ts} +3 -62
  22. package/dist/{client-vdh2a9fJ.d.mts → client-kYlJFgPv.d.mts} +3 -62
  23. package/dist/doctor-YYNHNMLD.mjs +198 -0
  24. package/dist/{express-A0-dWEMy.d.mts → express-B6_1vBYZ.d.mts} +23 -2
  25. package/dist/{express-Bo_pJKHN.d.ts → express-CHpfa7D_.d.ts} +23 -2
  26. package/dist/express.d.mts +5 -4
  27. package/dist/express.d.ts +5 -4
  28. package/dist/express.js +36 -4
  29. package/dist/express.mjs +8 -8
  30. package/dist/fastify.js +2 -2
  31. package/dist/fastify.mjs +4 -4
  32. package/dist/hono.js +2 -2
  33. package/dist/hono.mjs +4 -4
  34. package/dist/index.d.mts +8 -3
  35. package/dist/index.d.ts +8 -3
  36. package/dist/index.js +500 -4
  37. package/dist/index.mjs +29 -9
  38. package/dist/locales.d.mts +53 -0
  39. package/dist/locales.d.ts +53 -0
  40. package/dist/locales.js +1202 -0
  41. package/dist/locales.mjs +29 -0
  42. package/dist/mobile.d.mts +3 -2
  43. package/dist/mobile.d.ts +3 -2
  44. package/dist/next.d.mts +1 -1
  45. package/dist/next.d.ts +1 -1
  46. package/dist/next.js +2 -2
  47. package/dist/next.mjs +1 -1
  48. package/dist/provisioningBridge-88xjOS2n.d.mts +86 -0
  49. package/dist/provisioningBridge-DnTfzdZK.d.ts +86 -0
  50. package/dist/react.d.mts +1349 -10
  51. package/dist/react.d.ts +1349 -10
  52. package/dist/react.js +2985 -567
  53. package/dist/react.mjs +1517 -94
  54. package/dist/reverify-4UEJXUS6.mjs +16 -0
  55. package/dist/server/handlers.d.mts +10 -1
  56. package/dist/server/handlers.d.ts +10 -1
  57. package/dist/server/handlers.js +2 -2
  58. package/dist/server/handlers.mjs +1 -1
  59. package/dist/server.d.mts +5 -3
  60. package/dist/server.d.ts +5 -3
  61. package/dist/server.js +89 -4
  62. package/dist/server.mjs +12 -8
  63. package/dist/service.d.mts +3 -2
  64. package/dist/service.d.ts +3 -2
  65. package/dist/signIn-CCY4JE5G.mjs +15 -0
  66. package/dist/{signIn-Cd0P4y9d.d.mts → signIn-CiIBTJIh.d.mts} +224 -4
  67. package/dist/{signIn-DKakyzeu.d.ts → signIn-OCr88Zf8.d.ts} +224 -4
  68. package/dist/test.d.mts +86 -0
  69. package/dist/test.d.ts +86 -0
  70. package/dist/test.js +289 -0
  71. package/dist/test.mjs +9 -0
  72. package/dist/tokens-DCyzzn8L.d.mts +63 -0
  73. package/dist/tokens-aHiGFr_E.d.ts +63 -0
  74. package/dist/types-6bNdxesb.d.mts +196 -0
  75. package/dist/types-6bNdxesb.d.ts +196 -0
  76. package/dist/{types-Cxl3bQHt.d.mts → types-DZAflmmq.d.mts} +6 -0
  77. package/dist/{types-Cxl3bQHt.d.ts → types-DZAflmmq.d.ts} +6 -0
  78. package/dist/webhooks.d.mts +61 -0
  79. package/dist/webhooks.d.ts +61 -0
  80. package/dist/webhooks.js +119 -0
  81. package/dist/webhooks.mjs +11 -0
  82. package/dist/ws.d.mts +73 -0
  83. package/dist/ws.d.ts +73 -0
  84. package/dist/ws.js +397 -0
  85. package/dist/ws.mjs +12 -0
  86. package/package.json +22 -2
  87. package/dist/doctor-A5E7LSFW.mjs +0 -90
@@ -0,0 +1,29 @@
1
+ import {
2
+ builtInLocales,
3
+ deDE,
4
+ defaultBundle,
5
+ enUS,
6
+ esES,
7
+ frFR,
8
+ jaJP,
9
+ localizeErrorCode,
10
+ negotiateLocale,
11
+ ptBR,
12
+ resolveBundle,
13
+ t
14
+ } from "./chunk-5T7GHBX6.mjs";
15
+ import "./chunk-Y6FXYEAI.mjs";
16
+ export {
17
+ builtInLocales,
18
+ deDE,
19
+ defaultBundle,
20
+ enUS,
21
+ esES,
22
+ frFR,
23
+ jaJP,
24
+ localizeErrorCode,
25
+ negotiateLocale,
26
+ ptBR,
27
+ resolveBundle,
28
+ t
29
+ };
package/dist/mobile.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { I as IQAuthClient } from './client-vdh2a9fJ.mjs';
2
- import { b as IQAuthTokenClientConfig } from './types-Cxl3bQHt.mjs';
1
+ import { I as IQAuthClient } from './client-kYlJFgPv.mjs';
2
+ import { b as IQAuthTokenClientConfig } from './types-DZAflmmq.mjs';
3
3
  export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.mjs';
4
+ import './tokens-DCyzzn8L.mjs';
4
5
 
5
6
  declare class MobileIQAuthClient extends IQAuthClient {
6
7
  constructor(config: IQAuthTokenClientConfig);
package/dist/mobile.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { I as IQAuthClient } from './client-DTX4hNdS.js';
2
- import { b as IQAuthTokenClientConfig } from './types-Cxl3bQHt.js';
1
+ import { I as IQAuthClient } from './client-BNQe3AgF.js';
2
+ import { b as IQAuthTokenClientConfig } from './types-DZAflmmq.js';
3
3
  export { E as ErrorCodes, I as IQAuthError } from './errors-CDdl24MP.js';
4
+ import './tokens-aHiGFr_E.js';
4
5
 
5
6
  declare class MobileIQAuthClient extends IQAuthClient {
6
7
  constructor(config: IQAuthTokenClientConfig);
package/dist/next.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IQAuthHelperConfig } from './server/handlers.mjs';
2
- import { J as JwtClaims } from './types-Cxl3bQHt.mjs';
2
+ import { J as JwtClaims } from './types-DZAflmmq.mjs';
3
3
 
4
4
  /**
5
5
  * @iqauth/sdk/next — Next.js (App Router) adapter.
package/dist/next.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IQAuthHelperConfig } from './server/handlers.js';
2
- import { J as JwtClaims } from './types-Cxl3bQHt.js';
2
+ import { J as JwtClaims } from './types-DZAflmmq.js';
3
3
 
4
4
  /**
5
5
  * @iqauth/sdk/next — Next.js (App Router) adapter.
package/dist/next.js CHANGED
@@ -132,8 +132,8 @@ function resolve(config) {
132
132
  publishableKey: config.publishableKey,
133
133
  secretKey: config.secretKey,
134
134
  issuer: (config.issuer ?? inferredIssuer).replace(/\/+$/, ""),
135
- accessCookieName: config.accessCookieName ?? "iqauth_at",
136
- refreshCookieName: config.refreshCookieName ?? "iqauth_rt",
135
+ accessCookieName: config.accessCookieName ?? config.cookieNames?.access ?? "iqauth_at",
136
+ refreshCookieName: config.refreshCookieName ?? config.cookieNames?.refresh ?? "iqauth_rt",
137
137
  cookieDomain: config.cookieDomain,
138
138
  sameSite: config.sameSite ?? "lax",
139
139
  secure: config.secure ?? true,
package/dist/next.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  handleRefresh,
4
4
  handleSignout,
5
5
  serializeCookie
6
- } from "./chunk-KGEPDXHU.mjs";
6
+ } from "./chunk-6TDJJER7.mjs";
7
7
  import {
8
8
  assertPublishableKey
9
9
  } from "./chunk-WQWBJSSS.mjs";
@@ -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 };