@gatwech/auth 1.0.0-beta.18 → 1.0.0-beta.19
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 +8 -14
- package/dist/{access-C6O_osEz.mjs → access-CrwEFPHE.mjs} +1 -1
- package/dist/{access-DT1f6l5k.mjs → access-bhklJd7m.mjs} +1 -1
- package/dist/{adapter-factory-BZ2Qiqpn.mjs → adapter-factory-xbLUJt85.mjs} +2 -2
- package/dist/adapters/drizzle-adapter/index.mjs +6 -5
- package/dist/adapters/index.d.mts +5 -5
- package/dist/adapters/index.mjs +6 -5
- package/dist/adapters/kysely-adapter/index.d.mts +1 -1
- package/dist/adapters/kysely-adapter/index.mjs +8 -7
- package/dist/adapters/memory-adapter/index.d.mts +1 -1
- package/dist/adapters/memory-adapter/index.mjs +6 -5
- package/dist/adapters/mongodb-adapter/index.mjs +6 -5
- package/dist/adapters/prisma-adapter/index.mjs +6 -5
- package/dist/adapters/test.mjs +4 -3
- package/dist/{admin-Bcq53Nwj.mjs → admin-BzUJL6tr.mjs} +6 -6
- package/dist/{anonymous-CRt1imBW.mjs → anonymous-BjlTk4gl.mjs} +5 -5
- package/dist/api/index.d.mts +5 -5
- package/dist/api/index.mjs +12 -11
- package/dist/{api-0pR_I-Nx.mjs → api-Dk8Yj_J5.mjs} +15 -5
- package/dist/audit-log-DKsUWR8O.mjs +772 -0
- package/dist/{auth-CBUoBX6o.mjs → auth-vfCyIIeV.mjs} +8 -8
- package/dist/{bearer-Djf_awfo.mjs → bearer-DvQLM00l.mjs} +2 -2
- package/dist/client/index.d.mts +21 -21
- package/dist/client/index.mjs +4 -4
- package/dist/client/plugins/index.d.mts +53 -45
- package/dist/client/plugins/index.mjs +16 -12
- package/dist/client/react/index.d.mts +19 -19
- package/dist/client/react/index.mjs +2 -2
- package/dist/client-4QEb0rUr.mjs +95 -0
- package/dist/client-CSOs1YN7.d.mts +14 -0
- package/dist/client-DZHNfxuR.d.mts +75 -0
- package/dist/client-DzOqXJUm.mjs +15 -0
- package/dist/{client-aExCkfwm.mjs → client-xga7yFIX.mjs} +2 -2
- package/dist/cookies/index.d.mts +6 -6
- package/dist/cookies/index.mjs +2 -2
- package/dist/{cookies-cJObLwn1.mjs → cookies-BuvlgcA-.mjs} +1 -1
- package/dist/crypto/index.mjs +2 -1
- package/dist/{crypto-Bb42eMrH.mjs → crypto-CCyta8xj.mjs} +1 -6
- package/dist/{custom-session-L3t7ecsd.mjs → custom-session-DN_-pfi_.mjs} +2 -2
- package/dist/db/index.d.mts +5 -5
- package/dist/db/index.mjs +9 -8
- package/dist/{db-BrstmDhc.mjs → db-7vHnL1XA.mjs} +15 -9
- package/dist/{device-authorization-V4s3h4Mj.mjs → device-authorization-BKnNhlsz.mjs} +4 -4
- package/dist/{dialect-CeddeGHf.mjs → dialect-HsWUfpYY.mjs} +2 -2
- package/dist/{email-otp-BtDHSw14.mjs → email-otp-Dw0DypjQ.mjs} +7 -6
- package/dist/{generic-oauth-CL5X27ZI.mjs → generic-oauth-DFj27JY8.mjs} +4 -4
- package/dist/{has-permission-BpAr7uCn.mjs → has-permission-Bvg8de8g.mjs} +1 -1
- package/dist/{haveibeenpwned-cMpJvmzI.mjs → haveibeenpwned-CzNda7Tn.mjs} +28 -15
- package/dist/{client-CNY0tn9g.d.mts → index-BAVzFqII.d.mts} +21 -21
- package/dist/{index-DaBcikv9.d.mts → index-BNDRYfTF.d.mts} +2 -2
- package/dist/{index-Cxi7TbLE.d.mts → index-BNhJglHC.d.mts} +122 -122
- package/dist/{index-BYMI9r_d.d.mts → index-Blmhq6eA.d.mts} +4 -4
- package/dist/{index-BHoQlf7a.d.mts → index-CKnPAS5n.d.mts} +178 -178
- package/dist/{index-34ONrP8l.d.mts → index-COGe8UJx.d.mts} +11 -11
- package/dist/{index-Buhn3hkR.d.mts → index-CP3FNbOZ.d.mts} +8 -8
- package/dist/{index-D_k662QG.d.mts → index-CUknVRZp.d.mts} +14 -14
- package/dist/{index-DKNNV1kb.d.mts → index-CaqpCfE5.d.mts} +8 -8
- package/dist/{index-BBm8nQ9Q.d.mts → index-CgeC2eGC.d.mts} +2 -2
- package/dist/{index-DR0xXno9.d.mts → index-CsxtcAO0.d.mts} +1 -1
- package/dist/{index-CuFzhoS6.d.mts → index-Cv9iMevV.d.mts} +10 -10
- package/dist/{index-C7fQuk-V.d.mts → index-CxlWnL9c.d.mts} +1 -1
- package/dist/{index-zjjNBRY2.d.mts → index-DG-X1PK5.d.mts} +6 -6
- package/dist/index-DRM35ir1.d.mts +3769 -0
- package/dist/{index-BqhKCbPH.d.mts → index-DS-R7st3.d.mts} +6 -6
- package/dist/{index-C-u1h_WX.d.mts → index-DXVU0HGr.d.mts} +5 -5
- package/dist/{index-DoXZYQpq.d.mts → index-Db8jqUq2.d.mts} +10 -10
- package/dist/{index-65G5U5DB-DSdjzreF.d.mts → index-Df0KhQRf-BEa5tdwJ.d.mts} +3 -2
- package/dist/{index-B-XKqFvY.d.mts → index-Df4SvZaE.d.mts} +11 -4
- package/dist/{index-G6V0Z_Mn.d.mts → index-DyH_CgmX.d.mts} +10 -10
- package/dist/{admin-DtfO1PLg.d.mts → index-EABwA_BH.d.mts} +36 -36
- package/dist/{index-z0KSvE5i.d.mts → index-QmocqGM-.d.mts} +1 -1
- package/dist/{index-DlaMq1nb.d.mts → index-mxEUX2Gs.d.mts} +14 -14
- package/dist/{client-BOX93C3d.d.mts → index-xoYsoOiR.d.mts} +52 -52
- package/dist/{index-B3n8e37d.d.mts → index-zBdYQGaS.d.mts} +7 -7
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +16 -15
- package/dist/integrations/next-js.mjs +2 -2
- package/dist/integrations/node.d.mts +5 -5
- package/dist/integrations/react-start.d.mts +4 -4
- package/dist/integrations/react-start.mjs +2 -2
- package/dist/{jwt-lHV4QHpD.mjs → jwt-DBN2mu0r.mjs} +4 -4
- package/dist/{kysely-adapter-DpzYO8Yf.mjs → kysely-adapter-Bkm1liPW.mjs} +1 -1
- package/dist/{magic-link-Bk-ueorR.mjs → magic-link-D9Em1aOR.mjs} +3 -3
- package/dist/{multi-session-DRrLKrg9.mjs → multi-session-Dno_8DxC.mjs} +5 -5
- package/dist/{oauth-proxy-D1sWh9B_.mjs → oauth-proxy-DW-zt8wv.mjs} +2 -2
- package/dist/oauth2/index.d.mts +5 -5
- package/dist/oauth2/index.mjs +12 -11
- package/dist/{one-tap-DMswkTEc.mjs → one-tap-CodeyQb8.mjs} +2 -2
- package/dist/{organization-BArHO_5v.mjs → organization-CkTKs7bx.mjs} +9 -9
- package/dist/{passkey-CcD4CnhM.mjs → passkey-JNQTz5a0.mjs} +5 -5
- package/dist/{phone-number-rHDIlh-2.mjs → phone-number-Dqz8aeyF.mjs} +4 -4
- package/dist/plugins/access/index.d.mts +2 -2
- package/dist/plugins/access/index.mjs +1 -1
- package/dist/plugins/admin/access/index.d.mts +2 -2
- package/dist/plugins/admin/access/index.mjs +2 -2
- package/dist/plugins/admin/index.d.mts +7 -8
- package/dist/plugins/admin/index.mjs +17 -16
- package/dist/plugins/anonymous/index.d.mts +6 -6
- package/dist/plugins/anonymous/index.mjs +13 -12
- package/dist/plugins/audit-log/client.d.mts +30 -0
- package/dist/plugins/audit-log/client.mjs +3 -0
- package/dist/plugins/audit-log/index.d.mts +29 -0
- package/dist/plugins/audit-log/index.mjs +20 -0
- package/dist/plugins/bearer/index.d.mts +1 -1
- package/dist/plugins/bearer/index.mjs +3 -3
- package/dist/plugins/captcha/index.d.mts +1 -1
- package/dist/plugins/captcha/index.mjs +1 -1
- package/dist/plugins/custom-session/index.d.mts +6 -6
- package/dist/plugins/custom-session/index.mjs +14 -13
- package/dist/plugins/device-authorization/index.d.mts +3 -3
- package/dist/plugins/device-authorization/index.mjs +13 -12
- package/dist/plugins/email-otp/index.d.mts +2 -2
- package/dist/plugins/email-otp/index.mjs +14 -13
- package/dist/plugins/generic-oauth/index.d.mts +6 -6
- package/dist/plugins/generic-oauth/index.mjs +13 -12
- package/dist/plugins/haveibeenpwned/index.d.mts +2 -2
- package/dist/plugins/haveibeenpwned/index.mjs +14 -13
- package/dist/plugins/index.d.mts +29 -139
- package/dist/plugins/index.mjs +47 -42
- package/dist/plugins/jwt/index.d.mts +6 -6
- package/dist/plugins/jwt/index.mjs +13 -12
- package/dist/plugins/magic-link/index.d.mts +1 -1
- package/dist/plugins/magic-link/index.mjs +13 -12
- package/dist/plugins/multi-session/index.d.mts +2 -2
- package/dist/plugins/multi-session/index.mjs +13 -12
- package/dist/plugins/oauth-proxy/index.d.mts +1 -1
- package/dist/plugins/oauth-proxy/index.mjs +13 -12
- package/dist/plugins/one-tap/index.d.mts +1 -1
- package/dist/plugins/one-tap/index.mjs +13 -12
- package/dist/plugins/one-time-token/index.d.mts +6 -6
- package/dist/plugins/one-time-token/index.mjs +46 -41
- package/dist/plugins/organization/access/index.d.mts +3 -3
- package/dist/plugins/organization/access/index.mjs +2 -2
- package/dist/plugins/organization/index.d.mts +8 -8
- package/dist/plugins/organization/index.mjs +17 -16
- package/dist/plugins/passkey/index.d.mts +6 -6
- package/dist/plugins/passkey/index.mjs +13 -12
- package/dist/plugins/phone-number/index.d.mts +6 -6
- package/dist/plugins/phone-number/index.mjs +13 -12
- package/dist/plugins/sentinel/client.d.mts +30 -0
- package/dist/plugins/sentinel/client.mjs +5 -0
- package/dist/plugins/sentinel/index.d.mts +29 -0
- package/dist/plugins/sentinel/index.mjs +22 -0
- package/dist/plugins/two-factor/index.d.mts +6 -6
- package/dist/plugins/two-factor/index.mjs +15 -14
- package/dist/plugins/username/index.d.mts +3 -3
- package/dist/plugins/username/index.mjs +13 -12
- package/dist/{plugins-hFZT3hmK.d.mts → plugins-Dy_FrD4Y.d.mts} +1 -1
- package/dist/{plugins-3jfNste3.mjs → plugins-yF8CFUDR.mjs} +11 -8
- package/dist/pow-OK01yPG3.mjs +61 -0
- package/dist/{proxy-CL9PZXJA.mjs → proxy-C_KXfOhk.mjs} +1 -1
- package/dist/random-32E3cU5o.mjs +7 -0
- package/dist/registry-CqG_3Qnx.mjs +194 -0
- package/dist/sentinel-C-D1IHJo.mjs +1395 -0
- package/dist/{session-Dgp133Yt.mjs → session-BB3oqApE.mjs} +2 -2
- package/dist/src/adapters/memory-adapter/memory-adapter.d.ts +1 -1
- package/dist/src/adapters/prisma-adapter/test/auth.d.ts +1 -1
- package/dist/src/adapters/tests/auth-flow.d.ts +3 -3
- package/dist/src/adapters/tests/normal.d.ts +1 -1
- package/dist/src/adapters/tests/number-id.d.ts +3 -3
- package/dist/src/adapters/tests/performance.d.ts +3 -3
- package/dist/src/adapters/tests/transactions.d.ts +3 -3
- package/dist/src/api/index.d.ts +8 -8
- package/dist/src/client/plugins/index.d.ts +2 -0
- package/dist/src/plugins/admin/admin.d.ts +2 -2
- package/dist/src/plugins/api-key/index.d.ts +2 -2
- package/dist/src/plugins/audit-log/client.d.ts +10 -0
- package/dist/src/plugins/audit-log/events.d.ts +90 -0
- package/dist/src/plugins/audit-log/index.d.ts +614 -0
- package/dist/src/plugins/audit-log/registry.d.ts +13 -0
- package/dist/src/plugins/audit-log/remote.d.ts +34 -0
- package/dist/src/plugins/audit-log/schema.d.ts +50 -0
- package/dist/src/plugins/audit-log/types.d.ts +117 -0
- package/dist/src/plugins/email-otp/index.d.ts +1 -1
- package/dist/src/plugins/haveibeenpwned/index.d.ts +6 -0
- package/dist/src/plugins/index.d.ts +2 -0
- package/dist/src/plugins/multi-session/index.d.ts +8 -8
- package/dist/src/plugins/organization/organization.d.ts +5 -5
- package/dist/src/plugins/organization/routes/crud-access-control.d.ts +8 -8
- package/dist/src/plugins/organization/routes/crud-invites.d.ts +46 -46
- package/dist/src/plugins/organization/routes/crud-members.d.ts +40 -40
- package/dist/src/plugins/organization/routes/crud-org.d.ts +36 -36
- package/dist/src/plugins/organization/routes/crud-team.d.ts +50 -50
- package/dist/src/plugins/sentinel/actions.d.ts +64 -0
- package/dist/src/plugins/sentinel/client.d.ts +67 -0
- package/dist/src/plugins/sentinel/email.d.ts +22 -0
- package/dist/src/plugins/sentinel/geo.d.ts +22 -0
- package/dist/src/plugins/sentinel/index.d.ts +326 -0
- package/dist/src/plugins/sentinel/intel.d.ts +45 -0
- package/dist/src/plugins/sentinel/pow.d.ts +21 -0
- package/dist/src/plugins/sentinel/schema.d.ts +110 -0
- package/dist/src/plugins/sentinel/store.d.ts +37 -0
- package/dist/src/plugins/sentinel/types.d.ts +412 -0
- package/dist/src/test-utils/memory-secondary-storage.d.ts +16 -0
- package/dist/src/test-utils/password.d.ts +12 -0
- package/dist/src/test-utils/test-instance.d.ts +25 -25
- package/dist/test-utils/index.d.mts +1048 -1048
- package/dist/test-utils/index.mjs +53 -48
- package/dist/{two-factor-ClUXxom2.mjs → two-factor-CDVjxx4f.mjs} +6 -5
- package/dist/types/index.d.mts +5 -5
- package/dist/types/index.mjs +1 -1
- package/dist/{username-DiGklOGl.mjs → username-BHNvcvsY.mjs} +3 -3
- package/dist/{utils-SOMB4Px5.mjs → utils-B03WRaGi.mjs} +2 -1
- package/package.json +36 -3
- package/dist/index-CM-CFWwr.d.mts +0 -1919
- package/dist/index-DB7t8whN.d.mts +0 -1
- /package/dist/{access-BO2g7QVe.mjs → access-BM6jSA5j.mjs} +0 -0
- /package/dist/{bun-sqlite-dialect-CeNvMaZz.mjs → bun-sqlite-dialect-CDGusFqF.mjs} +0 -0
- /package/dist/{captcha-BqaMxlKC.mjs → captcha-DGP9lCRe.mjs} +0 -0
- /package/dist/{client-CygJhqeB.mjs → client-BuveH3MN.mjs} +0 -0
- /package/dist/{client-WiN43tAS.mjs → client-cBiytuOL.mjs} +0 -0
- /package/dist/{date-Cx2yCiC4.mjs → date-CMr04reD.mjs} +0 -0
- /package/dist/{esm-C-QicDNz.mjs → esm-BbvI87Z2.mjs} +0 -0
- /package/dist/{get-tables-BQP7YW9c.mjs → get-tables-CKvSyDST.mjs} +0 -0
- /package/dist/{helper-tmxW3BHj.d.mts → helper-BgOIGHsu.d.mts} +0 -0
- /package/dist/{misc-beA1w3XV.mjs → misc-fKH4d5XQ.mjs} +0 -0
- /package/dist/{node-sqlite-dialect-BcKxBQnm.mjs → node-sqlite-dialect-CIOjcg31.mjs} +0 -0
- /package/dist/{parser-DcrIEuXE.mjs → parser-D7EkhAjZ.mjs} +0 -0
- /package/dist/{password-sVC4nePO.mjs → password-5CdcAVaH.mjs} +0 -0
- /package/dist/{permission-DLYUF3cW.mjs → permission-CDDWgA_O.mjs} +0 -0
- /package/dist/{plugin-helper-4L-lzsjZ.mjs → plugin-helper-RJJBTOba.mjs} +0 -0
- /package/dist/{promise-8rrEHRXd.mjs → promise-D7Oo6_cY.mjs} +0 -0
- /package/dist/{types-Bjn15Uy6.mjs → types-DCPpFKUB.mjs} +0 -0
- /package/dist/{types-B1OL7hyf.d.mts → types-DNQ9XQrB.d.mts} +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import type { AuthContext, GenericEndpointContext } from "@gatwech/core";
|
|
2
|
+
import type { User } from "../../types";
|
|
3
|
+
import { SENTINEL_ERROR_CODES } from "./actions";
|
|
4
|
+
import { schema } from "./schema";
|
|
5
|
+
import type { GeoLocation, SecurityAction, SentinelOptions } from "./types";
|
|
6
|
+
export { normalizeEmail } from "./email";
|
|
7
|
+
export { haversineDistanceKm } from "./geo";
|
|
8
|
+
export * from "./pow";
|
|
9
|
+
export type * from "./types";
|
|
10
|
+
export { SENTINEL_ERROR_CODES };
|
|
11
|
+
export declare const sentinel: (options?: SentinelOptions | undefined) => {
|
|
12
|
+
id: "sentinel";
|
|
13
|
+
init(ctx: AuthContext<import("@gatwech/core").PayvoAuthOptions>): {
|
|
14
|
+
options: {
|
|
15
|
+
databaseHooks: {
|
|
16
|
+
user: {
|
|
17
|
+
create: {
|
|
18
|
+
before(user: {
|
|
19
|
+
id: string;
|
|
20
|
+
createdAt: Date;
|
|
21
|
+
updatedAt: Date;
|
|
22
|
+
email: string;
|
|
23
|
+
emailVerified: boolean;
|
|
24
|
+
name: string;
|
|
25
|
+
image?: string | null | undefined;
|
|
26
|
+
} & Record<string, unknown>, context: GenericEndpointContext<import("@gatwech/core").PayvoAuthOptions> | undefined): Promise<{
|
|
27
|
+
data: {
|
|
28
|
+
normalizedEmail: string;
|
|
29
|
+
id: string;
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
email: string;
|
|
33
|
+
emailVerified: boolean;
|
|
34
|
+
name: string;
|
|
35
|
+
image?: string | null | undefined;
|
|
36
|
+
};
|
|
37
|
+
} | undefined>;
|
|
38
|
+
after(user: {
|
|
39
|
+
id: string;
|
|
40
|
+
createdAt: Date;
|
|
41
|
+
updatedAt: Date;
|
|
42
|
+
email: string;
|
|
43
|
+
emailVerified: boolean;
|
|
44
|
+
name: string;
|
|
45
|
+
image?: string | null | undefined;
|
|
46
|
+
} & Record<string, unknown>, context: GenericEndpointContext<import("@gatwech/core").PayvoAuthOptions> | undefined): Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
update: {
|
|
49
|
+
before(data: Partial<{
|
|
50
|
+
id: string;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
updatedAt: Date;
|
|
53
|
+
email: string;
|
|
54
|
+
emailVerified: boolean;
|
|
55
|
+
name: string;
|
|
56
|
+
image?: string | null | undefined;
|
|
57
|
+
}> & Record<string, unknown>): Promise<{
|
|
58
|
+
data: {
|
|
59
|
+
normalizedEmail: string;
|
|
60
|
+
id?: string | undefined;
|
|
61
|
+
createdAt?: Date | undefined;
|
|
62
|
+
updatedAt?: Date | undefined;
|
|
63
|
+
email?: string | undefined;
|
|
64
|
+
emailVerified?: boolean | undefined;
|
|
65
|
+
name?: string | undefined;
|
|
66
|
+
image?: string | null | undefined;
|
|
67
|
+
};
|
|
68
|
+
} | undefined>;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
} | undefined;
|
|
74
|
+
onRequest(request: Request, ctx: AuthContext<import("@gatwech/core").PayvoAuthOptions>): Promise<{
|
|
75
|
+
response: Response;
|
|
76
|
+
} | undefined>;
|
|
77
|
+
hooks: {
|
|
78
|
+
before: ({
|
|
79
|
+
matcher(context: import("@gatwech/core").HookEndpointContext): boolean;
|
|
80
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
81
|
+
context: {
|
|
82
|
+
body: any;
|
|
83
|
+
};
|
|
84
|
+
} | undefined>;
|
|
85
|
+
} | {
|
|
86
|
+
matcher(context: import("@gatwech/core").HookEndpointContext): boolean;
|
|
87
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
88
|
+
})[];
|
|
89
|
+
after: ({
|
|
90
|
+
matcher(context: import("@gatwech/core").HookEndpointContext): boolean;
|
|
91
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
92
|
+
} | {
|
|
93
|
+
matcher(context: import("@gatwech/core").HookEndpointContext): boolean;
|
|
94
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<({
|
|
95
|
+
status: ("OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED") | import("better-call").Status;
|
|
96
|
+
body: ({
|
|
97
|
+
message?: string;
|
|
98
|
+
code?: string;
|
|
99
|
+
cause?: unknown;
|
|
100
|
+
} & Record<string, any>) | undefined;
|
|
101
|
+
headers: HeadersInit;
|
|
102
|
+
statusCode: number;
|
|
103
|
+
name: string;
|
|
104
|
+
message: string;
|
|
105
|
+
stack?: string;
|
|
106
|
+
cause?: unknown;
|
|
107
|
+
} & {
|
|
108
|
+
errorStack: string | undefined;
|
|
109
|
+
}) | undefined>;
|
|
110
|
+
})[];
|
|
111
|
+
};
|
|
112
|
+
schema: {
|
|
113
|
+
sentinelCounter: {
|
|
114
|
+
fields: {
|
|
115
|
+
key: {
|
|
116
|
+
type: "string";
|
|
117
|
+
required: true;
|
|
118
|
+
unique: true;
|
|
119
|
+
};
|
|
120
|
+
count: {
|
|
121
|
+
type: "number";
|
|
122
|
+
required: true;
|
|
123
|
+
};
|
|
124
|
+
expiresAt: {
|
|
125
|
+
type: "date";
|
|
126
|
+
required: true;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
sentinelSignIn: {
|
|
131
|
+
fields: {
|
|
132
|
+
userId: {
|
|
133
|
+
type: "string";
|
|
134
|
+
required: true;
|
|
135
|
+
references: {
|
|
136
|
+
model: string;
|
|
137
|
+
field: string;
|
|
138
|
+
onDelete: "cascade";
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
ipAddress: {
|
|
142
|
+
type: "string";
|
|
143
|
+
required: false;
|
|
144
|
+
};
|
|
145
|
+
visitorId: {
|
|
146
|
+
type: "string";
|
|
147
|
+
required: false;
|
|
148
|
+
};
|
|
149
|
+
userAgent: {
|
|
150
|
+
type: "string";
|
|
151
|
+
required: false;
|
|
152
|
+
};
|
|
153
|
+
country: {
|
|
154
|
+
type: "string";
|
|
155
|
+
required: false;
|
|
156
|
+
};
|
|
157
|
+
city: {
|
|
158
|
+
type: "string";
|
|
159
|
+
required: false;
|
|
160
|
+
};
|
|
161
|
+
latitude: {
|
|
162
|
+
type: "number";
|
|
163
|
+
required: false;
|
|
164
|
+
};
|
|
165
|
+
longitude: {
|
|
166
|
+
type: "number";
|
|
167
|
+
required: false;
|
|
168
|
+
};
|
|
169
|
+
createdAt: {
|
|
170
|
+
type: "date";
|
|
171
|
+
required: true;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
powChallenge: {
|
|
176
|
+
fields: {
|
|
177
|
+
nonce: {
|
|
178
|
+
type: "string";
|
|
179
|
+
required: true;
|
|
180
|
+
unique: true;
|
|
181
|
+
};
|
|
182
|
+
difficulty: {
|
|
183
|
+
type: "number";
|
|
184
|
+
required: true;
|
|
185
|
+
};
|
|
186
|
+
reason: {
|
|
187
|
+
type: "string";
|
|
188
|
+
required: true;
|
|
189
|
+
};
|
|
190
|
+
ipAddress: {
|
|
191
|
+
type: "string";
|
|
192
|
+
required: false;
|
|
193
|
+
};
|
|
194
|
+
visitorId: {
|
|
195
|
+
type: "string";
|
|
196
|
+
required: false;
|
|
197
|
+
};
|
|
198
|
+
expiresAt: {
|
|
199
|
+
type: "date";
|
|
200
|
+
required: true;
|
|
201
|
+
};
|
|
202
|
+
createdAt: {
|
|
203
|
+
type: "date";
|
|
204
|
+
required: true;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
$ERROR_CODES: {
|
|
210
|
+
readonly POW_CHALLENGE_REQUIRED: "Challenge required";
|
|
211
|
+
readonly SECURITY_BLOCKED: "Request blocked for security reasons";
|
|
212
|
+
};
|
|
213
|
+
options: {
|
|
214
|
+
failOpen: boolean;
|
|
215
|
+
apiUrl?: string | undefined;
|
|
216
|
+
apiKey?: string | undefined;
|
|
217
|
+
kvUrl?: string | undefined;
|
|
218
|
+
kvOptions?: {
|
|
219
|
+
timeout?: number | undefined;
|
|
220
|
+
retry?: {
|
|
221
|
+
attempts?: number | undefined;
|
|
222
|
+
baseDelay?: number | undefined;
|
|
223
|
+
maxDelay?: number | undefined;
|
|
224
|
+
} | undefined;
|
|
225
|
+
headers?: Record<string, string> | undefined;
|
|
226
|
+
} | undefined;
|
|
227
|
+
apiOptions?: {
|
|
228
|
+
timeout?: number | undefined;
|
|
229
|
+
headers?: Record<string, string> | undefined;
|
|
230
|
+
} | undefined;
|
|
231
|
+
providers?: {
|
|
232
|
+
getClientIp?: ((request: Request | Headers) => string | null) | undefined;
|
|
233
|
+
isSuspiciousIp?: ((ip: string) => boolean | Promise<boolean>) | undefined;
|
|
234
|
+
isBot?: ((request: Request) => boolean | Promise<boolean>) | undefined;
|
|
235
|
+
resolveGeo?: ((ip: string) => GeoLocation | null | Promise<GeoLocation | null>) | undefined;
|
|
236
|
+
} | undefined;
|
|
237
|
+
sendNotification?: ((notification: {
|
|
238
|
+
type: "unknown-device" | "stale-account";
|
|
239
|
+
recipient: "user" | "admin";
|
|
240
|
+
email: string;
|
|
241
|
+
user: User;
|
|
242
|
+
signIn: {
|
|
243
|
+
at: Date;
|
|
244
|
+
ipAddress: string | null;
|
|
245
|
+
userAgent: string | null;
|
|
246
|
+
location: string | null;
|
|
247
|
+
};
|
|
248
|
+
daysInactive?: number | undefined;
|
|
249
|
+
}) => void | Promise<void>) | undefined;
|
|
250
|
+
security?: {
|
|
251
|
+
credentialStuffing?: {
|
|
252
|
+
enabled: boolean;
|
|
253
|
+
action?: SecurityAction | undefined;
|
|
254
|
+
thresholds?: {
|
|
255
|
+
challenge: number;
|
|
256
|
+
block: number;
|
|
257
|
+
} | undefined;
|
|
258
|
+
windowSeconds?: number | undefined;
|
|
259
|
+
cooldownSeconds?: number | undefined;
|
|
260
|
+
} | undefined;
|
|
261
|
+
velocity?: {
|
|
262
|
+
enabled: boolean;
|
|
263
|
+
thresholds?: {
|
|
264
|
+
challenge: number;
|
|
265
|
+
block: number;
|
|
266
|
+
} | undefined;
|
|
267
|
+
maxSignupsPerVisitor?: number | undefined;
|
|
268
|
+
maxPasswordResetsPerIp?: number | undefined;
|
|
269
|
+
maxSignInsPerIp?: number | undefined;
|
|
270
|
+
windowSeconds?: number | undefined;
|
|
271
|
+
action?: SecurityAction | undefined;
|
|
272
|
+
} | undefined;
|
|
273
|
+
freeTrialAbuse?: {
|
|
274
|
+
enabled: boolean;
|
|
275
|
+
thresholds?: {
|
|
276
|
+
challenge: number;
|
|
277
|
+
block: number;
|
|
278
|
+
} | undefined;
|
|
279
|
+
maxAccountsPerVisitor?: number | undefined;
|
|
280
|
+
retentionSeconds?: number | undefined;
|
|
281
|
+
action?: SecurityAction | undefined;
|
|
282
|
+
} | undefined;
|
|
283
|
+
botBlocking?: (boolean | {
|
|
284
|
+
action: SecurityAction;
|
|
285
|
+
}) | undefined;
|
|
286
|
+
suspiciousIpBlocking?: (boolean | {
|
|
287
|
+
action: SecurityAction;
|
|
288
|
+
}) | undefined;
|
|
289
|
+
unknownDeviceNotification?: boolean | undefined;
|
|
290
|
+
impossibleTravel?: {
|
|
291
|
+
enabled: boolean;
|
|
292
|
+
maxSpeedKmh?: number | undefined;
|
|
293
|
+
action?: SecurityAction | undefined;
|
|
294
|
+
} | undefined;
|
|
295
|
+
geoBlocking?: {
|
|
296
|
+
allowList?: string[] | undefined;
|
|
297
|
+
denyList?: string[] | undefined;
|
|
298
|
+
action?: Exclude<SecurityAction, "log"> | undefined;
|
|
299
|
+
} | undefined;
|
|
300
|
+
compromisedPassword?: {
|
|
301
|
+
enabled: boolean;
|
|
302
|
+
action?: SecurityAction | undefined;
|
|
303
|
+
minBreachCount?: number | undefined;
|
|
304
|
+
} | undefined;
|
|
305
|
+
emailValidation?: {
|
|
306
|
+
enabled: boolean;
|
|
307
|
+
strictness?: ("low" | "medium" | "high") | undefined;
|
|
308
|
+
action?: SecurityAction | undefined;
|
|
309
|
+
domainAllowlist?: string[] | undefined;
|
|
310
|
+
} | undefined;
|
|
311
|
+
emailNormalization?: {
|
|
312
|
+
enabled?: boolean | undefined;
|
|
313
|
+
} | undefined;
|
|
314
|
+
staleUsers?: {
|
|
315
|
+
enabled: boolean;
|
|
316
|
+
staleDays?: number | undefined;
|
|
317
|
+
action?: SecurityAction | undefined;
|
|
318
|
+
notifyUser?: boolean | undefined;
|
|
319
|
+
notifyAdmin?: boolean | undefined;
|
|
320
|
+
adminEmail?: string | undefined;
|
|
321
|
+
} | undefined;
|
|
322
|
+
challengeDifficulty?: number | undefined;
|
|
323
|
+
} | undefined;
|
|
324
|
+
schema?: import("..").InferOptionSchema<typeof schema> | undefined;
|
|
325
|
+
};
|
|
326
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AuthContext } from "@gatwech/core";
|
|
2
|
+
import type { GeoLocation, SentinelOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Local bot heuristics, used when neither a provider nor the hosted backend
|
|
5
|
+
* gives a verdict
|
|
6
|
+
*/
|
|
7
|
+
export declare function looksLikeBot(request: Request): boolean;
|
|
8
|
+
type RequestIntel = {
|
|
9
|
+
suspiciousIp: boolean | null;
|
|
10
|
+
bot: boolean | null;
|
|
11
|
+
geo: GeoLocation | null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Asks the hosted backend about a request's IP address and client. Verdicts
|
|
15
|
+
* are cached in secondary storage for as long as the backend allows.
|
|
16
|
+
* Returns null verdicts when the backend isn't configured or can't answer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createIntelClient(options: SentinelOptions): {
|
|
19
|
+
configured: boolean;
|
|
20
|
+
/** Visitor ids are checked with the identification service */
|
|
21
|
+
verifiesVisitors: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A backend URL is set without a key, or a key without a URL, so
|
|
24
|
+
* checks that need the backend fall back to allow mode
|
|
25
|
+
*/
|
|
26
|
+
misconfigured: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Checks a client-sent visitor id with the identification service.
|
|
29
|
+
* Returns the canonical visitor id (or the one sent, when no
|
|
30
|
+
* identification service is configured), null when it isn't genuine, or
|
|
31
|
+
* undefined when the check failed.
|
|
32
|
+
*/
|
|
33
|
+
verifyVisitor(auth: AuthContext, request: {
|
|
34
|
+
visitorId: string;
|
|
35
|
+
ip: string | null;
|
|
36
|
+
userAgent: string | null;
|
|
37
|
+
}): Promise<string | null | undefined>;
|
|
38
|
+
lookup(auth: AuthContext, request: {
|
|
39
|
+
ip: string | null;
|
|
40
|
+
visitorId: string | null;
|
|
41
|
+
userAgent: string | null;
|
|
42
|
+
acceptLanguage: string | null;
|
|
43
|
+
}): Promise<RequestIntel>;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const POW_CHALLENGE_HEADER = "x-pow-challenge";
|
|
2
|
+
export declare const POW_REASON_HEADER = "x-pow-reason";
|
|
3
|
+
export declare const POW_SOLUTION_HEADER = "x-pow-solution";
|
|
4
|
+
export declare function createNonce(): string;
|
|
5
|
+
/** Whether a hash starts with at least `difficulty` zero bits */
|
|
6
|
+
export declare function hasLeadingZeroBits(hash: Uint8Array, difficulty: number): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Whether `sha256("<nonce>:<solution>")` has at least `difficulty` leading
|
|
9
|
+
* zero bits
|
|
10
|
+
*/
|
|
11
|
+
export declare function verifySolution(nonce: string, solution: string, difficulty: number): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Find a solution for a challenge by trying incrementing counters. Yields to
|
|
14
|
+
* the event loop between batches, so solving doesn't block the page.
|
|
15
|
+
*/
|
|
16
|
+
export declare function solveChallenge(nonce: string, difficulty: number): Promise<string>;
|
|
17
|
+
/** Parses `<nonce>:<value>` header values */
|
|
18
|
+
export declare function parsePowHeader(value: string | null | undefined): {
|
|
19
|
+
nonce: string;
|
|
20
|
+
value: string;
|
|
21
|
+
} | null;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Added to users when `emailNormalization` is enabled */
|
|
2
|
+
export declare const normalizedEmailSchema: {
|
|
3
|
+
user: {
|
|
4
|
+
fields: {
|
|
5
|
+
normalizedEmail: {
|
|
6
|
+
type: "string";
|
|
7
|
+
required: false;
|
|
8
|
+
input: false;
|
|
9
|
+
returned: false;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const schema: {
|
|
15
|
+
sentinelCounter: {
|
|
16
|
+
fields: {
|
|
17
|
+
key: {
|
|
18
|
+
type: "string";
|
|
19
|
+
required: true;
|
|
20
|
+
unique: true;
|
|
21
|
+
};
|
|
22
|
+
count: {
|
|
23
|
+
type: "number";
|
|
24
|
+
required: true;
|
|
25
|
+
};
|
|
26
|
+
expiresAt: {
|
|
27
|
+
type: "date";
|
|
28
|
+
required: true;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
sentinelSignIn: {
|
|
33
|
+
fields: {
|
|
34
|
+
userId: {
|
|
35
|
+
type: "string";
|
|
36
|
+
required: true;
|
|
37
|
+
references: {
|
|
38
|
+
model: string;
|
|
39
|
+
field: string;
|
|
40
|
+
onDelete: "cascade";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
ipAddress: {
|
|
44
|
+
type: "string";
|
|
45
|
+
required: false;
|
|
46
|
+
};
|
|
47
|
+
visitorId: {
|
|
48
|
+
type: "string";
|
|
49
|
+
required: false;
|
|
50
|
+
};
|
|
51
|
+
userAgent: {
|
|
52
|
+
type: "string";
|
|
53
|
+
required: false;
|
|
54
|
+
};
|
|
55
|
+
country: {
|
|
56
|
+
type: "string";
|
|
57
|
+
required: false;
|
|
58
|
+
};
|
|
59
|
+
city: {
|
|
60
|
+
type: "string";
|
|
61
|
+
required: false;
|
|
62
|
+
};
|
|
63
|
+
latitude: {
|
|
64
|
+
type: "number";
|
|
65
|
+
required: false;
|
|
66
|
+
};
|
|
67
|
+
longitude: {
|
|
68
|
+
type: "number";
|
|
69
|
+
required: false;
|
|
70
|
+
};
|
|
71
|
+
createdAt: {
|
|
72
|
+
type: "date";
|
|
73
|
+
required: true;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
powChallenge: {
|
|
78
|
+
fields: {
|
|
79
|
+
nonce: {
|
|
80
|
+
type: "string";
|
|
81
|
+
required: true;
|
|
82
|
+
unique: true;
|
|
83
|
+
};
|
|
84
|
+
difficulty: {
|
|
85
|
+
type: "number";
|
|
86
|
+
required: true;
|
|
87
|
+
};
|
|
88
|
+
reason: {
|
|
89
|
+
type: "string";
|
|
90
|
+
required: true;
|
|
91
|
+
};
|
|
92
|
+
ipAddress: {
|
|
93
|
+
type: "string";
|
|
94
|
+
required: false;
|
|
95
|
+
};
|
|
96
|
+
visitorId: {
|
|
97
|
+
type: "string";
|
|
98
|
+
required: false;
|
|
99
|
+
};
|
|
100
|
+
expiresAt: {
|
|
101
|
+
type: "date";
|
|
102
|
+
required: true;
|
|
103
|
+
};
|
|
104
|
+
createdAt: {
|
|
105
|
+
type: "date";
|
|
106
|
+
required: true;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AuthContext } from "@gatwech/core";
|
|
2
|
+
type StoredChallenge = {
|
|
3
|
+
nonce: string;
|
|
4
|
+
difficulty: number;
|
|
5
|
+
reason: string;
|
|
6
|
+
ipAddress: string | null;
|
|
7
|
+
visitorId: string | null;
|
|
8
|
+
expiresAt: Date;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Counters and challenges, kept in secondary storage when it's configured
|
|
12
|
+
* and in the database otherwise
|
|
13
|
+
*/
|
|
14
|
+
export declare function createSentinelStore(auth: AuthContext): {
|
|
15
|
+
/**
|
|
16
|
+
* Increments a counter that expires a fixed window after it was created,
|
|
17
|
+
* and returns the new count
|
|
18
|
+
*/
|
|
19
|
+
increment(name: string, ttlSeconds: number, options?: {
|
|
20
|
+
/**
|
|
21
|
+
* Restart the expiry on every increment instead of keeping a fixed
|
|
22
|
+
* window
|
|
23
|
+
*/
|
|
24
|
+
sliding?: boolean;
|
|
25
|
+
}): Promise<number>;
|
|
26
|
+
/** Returns a counter's current value, or 0 when it's missing or expired */
|
|
27
|
+
get(name: string): Promise<number>;
|
|
28
|
+
reset(name: string): Promise<void>;
|
|
29
|
+
saveChallenge(challenge: StoredChallenge): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a challenge and removes it, so it can only be used once.
|
|
32
|
+
* Returns null when it doesn't exist, was already used or expired.
|
|
33
|
+
*/
|
|
34
|
+
consumeChallenge(nonce: string): Promise<StoredChallenge | null>;
|
|
35
|
+
};
|
|
36
|
+
export type SentinelStore = ReturnType<typeof createSentinelStore>;
|
|
37
|
+
export {};
|