@iqauth/sdk 2.6.4 → 2.8.1
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 +173 -1
- package/dist/browser-session.d.mts +4 -4
- package/dist/browser-session.d.ts +4 -4
- package/dist/browser-session.js +212 -46
- package/dist/browser-session.mjs +3 -3
- package/dist/browser.d.mts +5 -5
- package/dist/browser.d.ts +5 -5
- package/dist/browser.js +293 -34
- package/dist/browser.mjs +5 -5
- package/dist/{chunk-BVV54LPI.mjs → chunk-25SSYDIP.mjs} +10 -4
- package/dist/{chunk-XAWYUPMO.mjs → chunk-4V7FKOTG.mjs} +242 -22
- package/dist/{chunk-6I6RM4MN.mjs → chunk-6PJRLRB4.mjs} +33 -3
- package/dist/{chunk-SL3KRS4W.mjs → chunk-CIJORODR.mjs} +23 -1
- package/dist/{chunk-LIZYFXH7.mjs → chunk-DFWHSDYQ.mjs} +1 -1
- package/dist/chunk-GLXSIGVS.mjs +66 -0
- package/dist/{chunk-DJIBN2N7.mjs → chunk-GN37E64I.mjs} +29 -7
- package/dist/{chunk-WQWBJSSS.mjs → chunk-HVHNYPDC.mjs} +6 -6
- package/dist/chunk-JRDVUWAL.mjs +46 -0
- package/dist/{chunk-UNYDG2L4.mjs → chunk-NUO2I65G.mjs} +56 -23
- package/dist/{chunk-5T7GHBX6.mjs → chunk-TLET552H.mjs} +36 -0
- package/dist/chunk-VYQ3ETCK.mjs +244 -0
- package/dist/{chunk-3JULWS6F.mjs → chunk-WCELYTJ3.mjs} +3 -3
- package/dist/chunk-WHT6WKTY.mjs +3180 -0
- package/dist/{chunk-MKKZULZR.mjs → chunk-WIFG74IK.mjs} +1 -1
- package/dist/chunk-WSH4SW7F.mjs +490 -0
- package/dist/{chunk-W3F4JYGP.mjs → chunk-ZLJPABB7.mjs} +139 -23
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.mjs +2 -2
- package/dist/{client-BNQe3AgF.d.ts → client-D8L-PaWr.d.mts} +59 -6
- package/dist/{client-kYlJFgPv.d.mts → client-DkPL0EPZ.d.ts} +59 -6
- package/dist/{doctor-YYNHNMLD.mjs → doctor-JAFXWU3X.mjs} +2 -2
- package/dist/errors-Jl1Jtm-6.d.mts +107 -0
- package/dist/errors-Jl1Jtm-6.d.ts +107 -0
- package/dist/{express-CHpfa7D_.d.ts → express-Budysq4h.d.ts} +2 -2
- package/dist/{express-B6_1vBYZ.d.mts → express-DDTA3qV1.d.mts} +2 -2
- package/dist/express.d.mts +7 -6
- package/dist/express.d.ts +7 -6
- package/dist/express.js +563 -85
- package/dist/express.mjs +73 -34
- package/dist/fastify.d.mts +10 -0
- package/dist/fastify.d.ts +10 -0
- package/dist/fastify.js +589 -65
- package/dist/fastify.mjs +101 -11
- package/dist/hono.d.mts +10 -0
- package/dist/hono.d.ts +10 -0
- package/dist/hono.js +566 -65
- package/dist/hono.mjs +78 -11
- package/dist/index-Cko-d5po.d.mts +1848 -0
- package/dist/index-RNqwEcmY.d.ts +1848 -0
- package/dist/index.d.mts +56 -8
- package/dist/index.d.ts +56 -8
- package/dist/index.js +694 -75
- package/dist/index.mjs +30 -10
- package/dist/{keys-NLWFAOEM.mjs → keys-6Y776TG2.mjs} +2 -2
- package/dist/locales.d.mts +1 -1
- package/dist/locales.d.ts +1 -1
- package/dist/locales.js +36 -0
- package/dist/locales.mjs +1 -1
- package/dist/mobile.d.mts +77 -7
- package/dist/mobile.d.ts +77 -7
- package/dist/mobile.js +307 -46
- package/dist/mobile.mjs +98 -3
- package/dist/next.d.mts +10 -1
- package/dist/next.d.ts +10 -1
- package/dist/next.js +596 -205
- package/dist/next.mjs +83 -10
- package/dist/{provisioningBridge-88xjOS2n.d.mts → provisioningBridge-BXPMZCLe.d.ts} +30 -2
- package/dist/{provisioningBridge-DnTfzdZK.d.ts → provisioningBridge-IEycmsgb.d.mts} +30 -2
- package/dist/{publishableKey-BaR0HoAH.d.ts → publishableKey-f2kq-rKw.d.mts} +1 -1
- package/dist/{publishableKey-BaR0HoAH.d.mts → publishableKey-f2kq-rKw.d.ts} +1 -1
- package/dist/react-permissions.d.mts +52 -0
- package/dist/react-permissions.d.ts +52 -0
- package/dist/react-permissions.js +239 -0
- package/dist/react-permissions.mjs +98 -0
- package/dist/react.d.mts +9 -1624
- package/dist/react.d.ts +9 -1624
- package/dist/react.js +882 -73
- package/dist/react.mjs +71 -2631
- package/dist/{reverify-4UEJXUS6.mjs → reverify-C64QXKJO.mjs} +2 -2
- package/dist/server/handlers.d.mts +200 -4
- package/dist/server/handlers.d.ts +200 -4
- package/dist/server/handlers.js +530 -16
- package/dist/server/handlers.mjs +14 -3
- package/dist/server.d.mts +171 -8
- package/dist/server.d.ts +171 -8
- package/dist/server.js +579 -61
- package/dist/server.mjs +99 -12
- package/dist/service.d.mts +4 -4
- package/dist/service.d.ts +4 -4
- package/dist/service.js +212 -46
- package/dist/service.mjs +3 -3
- package/dist/{signIn-CiIBTJIh.d.mts → signIn-CReqfXsh.d.mts} +95 -3
- package/dist/{signIn-OCr88Zf8.d.ts → signIn-Cfa1GTpO.d.ts} +95 -3
- package/dist/{signIn-4OKLDEIH.mjs → signIn-SHBW6Z4T.mjs} +1 -1
- package/dist/test.mjs +3 -3
- package/dist/{tokens-DCyzzn8L.d.mts → tokens-9F6ETrzk.d.ts} +9 -2
- package/dist/{tokens-aHiGFr_E.d.ts → tokens-B06VtvUi.d.mts} +9 -2
- package/dist/{types-DZAflmmq.d.mts → types-Bn8O-OEd.d.mts} +164 -11
- package/dist/{types-DZAflmmq.d.ts → types-Bn8O-OEd.d.ts} +164 -11
- package/dist/{types-6bNdxesb.d.ts → types-DnU2LhXR.d.mts} +7 -1
- package/dist/{types-6bNdxesb.d.mts → types-DnU2LhXR.d.ts} +7 -1
- package/dist/webhooks.d.mts +113 -17
- package/dist/webhooks.d.ts +113 -17
- package/dist/webhooks.js +179 -15
- package/dist/webhooks.mjs +7 -1
- package/dist/ws.d.mts +2 -2
- package/dist/ws.d.ts +2 -2
- package/dist/ws.js +80 -30
- package/dist/ws.mjs +4 -4
- package/docs/error-handling.md +101 -0
- package/docs/guides/effective-permissions.md +171 -0
- package/docs/guides/invitations.md +65 -0
- package/package.json +19 -4
- package/dist/chunk-6TDJJER7.mjs +0 -217
- package/dist/chunk-UKZLOHZG.mjs +0 -83
- package/dist/errors-CDdl24MP.d.mts +0 -52
- package/dist/errors-CDdl24MP.d.ts +0 -52
package/dist/mobile.mjs
CHANGED
|
@@ -1,17 +1,112 @@
|
|
|
1
1
|
import {
|
|
2
2
|
IQAuthClient
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-ZLJPABB7.mjs";
|
|
4
|
+
import "./chunk-NUO2I65G.mjs";
|
|
5
5
|
import {
|
|
6
6
|
ErrorCodes,
|
|
7
7
|
IQAuthError
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-6PJRLRB4.mjs";
|
|
9
9
|
import "./chunk-Y6FXYEAI.mjs";
|
|
10
10
|
|
|
11
11
|
// src/mobile.ts
|
|
12
|
+
function resolveAppState() {
|
|
13
|
+
try {
|
|
14
|
+
const rn = Function("return require")()("react-native");
|
|
15
|
+
return rn?.AppState ?? null;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
12
20
|
var MobileIQAuthClient = class extends IQAuthClient {
|
|
13
21
|
constructor(config) {
|
|
14
22
|
super({ ...config, environment: "mobile" });
|
|
23
|
+
this.appStateSub = null;
|
|
24
|
+
this.lastAppState = "active";
|
|
25
|
+
this.refreshing = false;
|
|
26
|
+
this.appStateMode = config.autoRefresh === "app-state";
|
|
27
|
+
this.leewaySeconds = config.appStateRefreshLeewaySeconds ?? 300;
|
|
28
|
+
this.onTokenRefreshCb = config.onTokenRefresh;
|
|
29
|
+
this.onAppStateRefreshError = config.onAppStateRefreshError;
|
|
30
|
+
if (this.appStateMode) {
|
|
31
|
+
const appState = config.appState !== void 0 ? config.appState : resolveAppState();
|
|
32
|
+
if (appState) this.startAppStateListener(appState);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** True iff the client is configured for AppState-driven refresh. */
|
|
36
|
+
get isAppStateMode() {
|
|
37
|
+
return this.appStateMode;
|
|
38
|
+
}
|
|
39
|
+
startAppStateListener(appState) {
|
|
40
|
+
this.lastAppState = appState.currentState ?? "active";
|
|
41
|
+
const handler = (next) => {
|
|
42
|
+
const prev = this.lastAppState;
|
|
43
|
+
this.lastAppState = next;
|
|
44
|
+
if (next === "active" && prev !== "active") {
|
|
45
|
+
void this.maybeRefreshOnForeground();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const sub = appState.addEventListener("change", handler);
|
|
49
|
+
if (sub && typeof sub.remove === "function") {
|
|
50
|
+
this.appStateSub = sub;
|
|
51
|
+
} else if (typeof sub === "function") {
|
|
52
|
+
this.appStateSub = { remove: sub };
|
|
53
|
+
} else if (typeof appState.removeEventListener === "function") {
|
|
54
|
+
this.appStateSub = {
|
|
55
|
+
remove: () => appState.removeEventListener("change", handler)
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
this.appStateSub = { remove: () => {
|
|
59
|
+
} };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Public hook: call this from your own AppState handler if you've passed
|
|
64
|
+
* `appState: null` to opt out of the auto-subscription. Returns true if a
|
|
65
|
+
* refresh was attempted.
|
|
66
|
+
*/
|
|
67
|
+
async refreshIfStale() {
|
|
68
|
+
return this.maybeRefreshOnForeground();
|
|
69
|
+
}
|
|
70
|
+
async maybeRefreshOnForeground() {
|
|
71
|
+
if (this.refreshing) return false;
|
|
72
|
+
if (!this.getRefreshToken()) return false;
|
|
73
|
+
if (!this.isAccessTokenStale()) return false;
|
|
74
|
+
const refreshToken = this.getRefreshToken();
|
|
75
|
+
if (!refreshToken) return false;
|
|
76
|
+
this.refreshing = true;
|
|
77
|
+
try {
|
|
78
|
+
const next = await this.auth.refreshTokens(refreshToken);
|
|
79
|
+
this.setTokens(next);
|
|
80
|
+
this.onTokenRefreshCb?.(next);
|
|
81
|
+
return true;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
this.onAppStateRefreshError?.(err);
|
|
84
|
+
return false;
|
|
85
|
+
} finally {
|
|
86
|
+
this.refreshing = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
isAccessTokenStale() {
|
|
90
|
+
const token = this.getAccessToken();
|
|
91
|
+
if (!token) return true;
|
|
92
|
+
try {
|
|
93
|
+
const parts = token.split(".");
|
|
94
|
+
if (parts.length !== 3) return true;
|
|
95
|
+
const payload = JSON.parse(
|
|
96
|
+
typeof atob === "function" ? atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")) : Buffer.from(parts[1], "base64url").toString("utf8")
|
|
97
|
+
);
|
|
98
|
+
if (!payload.exp) return false;
|
|
99
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
100
|
+
return payload.exp - now < this.leewaySeconds;
|
|
101
|
+
} catch {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Remove the AppState subscription. Idempotent. */
|
|
106
|
+
stop() {
|
|
107
|
+
const sub = this.appStateSub;
|
|
108
|
+
this.appStateSub = null;
|
|
109
|
+
sub?.remove();
|
|
15
110
|
}
|
|
16
111
|
};
|
|
17
112
|
function createMobileClient(config) {
|
package/dist/next.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IQAuthHelperConfig } from './server/handlers.mjs';
|
|
2
|
-
import { J as JwtClaims } from './types-
|
|
2
|
+
import { J as JwtClaims } from './types-Bn8O-OEd.mjs';
|
|
3
|
+
import './tokens-B06VtvUi.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @iqauth/sdk/next — Next.js (App Router) adapter.
|
|
@@ -20,6 +21,14 @@ import { J as JwtClaims } from './types-DZAflmmq.mjs';
|
|
|
20
21
|
interface IQAuthNextOptions extends IQAuthHelperConfig {
|
|
21
22
|
/** Path prefix where the helper routes live. */
|
|
22
23
|
mountPath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Cookie name the browser SDK publishes the post-login destination into
|
|
26
|
+
* before redirect. The callback handler reads it, surfaces it as `returnTo`
|
|
27
|
+
* in the JSON response body after a successful exchange, and clears it on
|
|
28
|
+
* success. Mirrors the express inline-callback adapter. Defaults to
|
|
29
|
+
* `iqauth_return_to`.
|
|
30
|
+
*/
|
|
31
|
+
returnToCookieName?: string;
|
|
23
32
|
}
|
|
24
33
|
declare function handler(options: IQAuthNextOptions): (req: Request) => Promise<Response>;
|
|
25
34
|
/**
|
package/dist/next.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IQAuthHelperConfig } from './server/handlers.js';
|
|
2
|
-
import { J as JwtClaims } from './types-
|
|
2
|
+
import { J as JwtClaims } from './types-Bn8O-OEd.js';
|
|
3
|
+
import './tokens-9F6ETrzk.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @iqauth/sdk/next — Next.js (App Router) adapter.
|
|
@@ -20,6 +21,14 @@ import { J as JwtClaims } from './types-DZAflmmq.js';
|
|
|
20
21
|
interface IQAuthNextOptions extends IQAuthHelperConfig {
|
|
21
22
|
/** Path prefix where the helper routes live. */
|
|
22
23
|
mountPath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Cookie name the browser SDK publishes the post-login destination into
|
|
26
|
+
* before redirect. The callback handler reads it, surfaces it as `returnTo`
|
|
27
|
+
* in the JSON response body after a successful exchange, and clears it on
|
|
28
|
+
* success. Mirrors the express inline-callback adapter. Defaults to
|
|
29
|
+
* `iqauth_return_to`.
|
|
30
|
+
*/
|
|
31
|
+
returnToCookieName?: string;
|
|
23
32
|
}
|
|
24
33
|
declare function handler(options: IQAuthNextOptions): (req: Request) => Promise<Response>;
|
|
25
34
|
/**
|