@holeauth/core 0.0.1-alpha.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/LICENSE +21 -0
- package/README.md +5 -0
- package/cjs-error.cjs +8 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/cookies/index.d.ts +3 -0
- package/dist/cookies/index.js +74 -0
- package/dist/cookies/index.js.map +1 -0
- package/dist/errors/index.d.ts +40 -0
- package/dist/errors/index.js +70 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +52 -0
- package/dist/events/index.js.map +1 -0
- package/dist/flows/index.d.ts +4 -0
- package/dist/flows/index.js +835 -0
- package/dist/flows/index.js.map +1 -0
- package/dist/index-BIXESLma.d.ts +58 -0
- package/dist/index-BYtkmk9_.d.ts +18 -0
- package/dist/index-BbEXbI_k.d.ts +116 -0
- package/dist/index-BmYQquGs.d.ts +563 -0
- package/dist/index-BwEvEa8-.d.ts +20 -0
- package/dist/index-CHS-socJ.d.ts +97 -0
- package/dist/index-CNtnPdzk.d.ts +136 -0
- package/dist/index-CjEXpqaW.d.ts +22 -0
- package/dist/index-CotvcK_b.d.ts +42 -0
- package/dist/index-D57PvFMN.d.ts +105 -0
- package/dist/index-DRN-5E_H.d.ts +26 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +1757 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt/index.d.ts +2 -0
- package/dist/jwt/index.js +53 -0
- package/dist/jwt/index.js.map +1 -0
- package/dist/otp/index.d.ts +1 -0
- package/dist/otp/index.js +16 -0
- package/dist/otp/index.js.map +1 -0
- package/dist/password/index.d.ts +1 -0
- package/dist/password/index.js +75 -0
- package/dist/password/index.js.map +1 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +480 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/registry-CZhM1tEB.d.ts +101 -0
- package/dist/session/index.d.ts +3 -0
- package/dist/session/index.js +346 -0
- package/dist/session/index.js.map +1 -0
- package/dist/sso/index.d.ts +3 -0
- package/dist/sso/index.js +475 -0
- package/dist/sso/index.js.map +1 -0
- package/package.json +121 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Kratz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/cjs-error.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Shim loaded when a CommonJS consumer does `require('@holeauth/<pkg>')`.
|
|
2
|
+
// All @holeauth/* packages are ESM-only.
|
|
3
|
+
throw new Error(
|
|
4
|
+
'[@holeauth] This package is ESM-only. ' +
|
|
5
|
+
'Use `import` (or a dynamic `import()`) instead of `require()`. ' +
|
|
6
|
+
'If you are in a CommonJS project, add `"type": "module"` to your package.json ' +
|
|
7
|
+
'or migrate the consuming file to `.mjs`.',
|
|
8
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { c as AccountAdapter, d as AdapterAccount, a as AdapterAuditEvent, e as AdapterSession, A as AdapterUser, f as AdapterVerificationToken, b as AuditLogAdapter, S as SessionAdapter, T as TransactionAdapter, U as UserAdapter, V as VerificationTokenAdapter } from '../index-CNtnPdzk.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { B as BuildCookieInput, C as CSRF_HEADER, a as CookieName, b as CookieSpec, c as buildCookie, d as cookieName, e as deleteCookie, g as generateCsrfToken, f as isProduction, s as serializeCookie, v as verifyCsrf } from '../index-BIXESLma.js';
|
|
2
|
+
import '../index-BmYQquGs.js';
|
|
3
|
+
import '../index-CNtnPdzk.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/cookies/spec.ts
|
|
2
|
+
function cookieName(cfg, kind) {
|
|
3
|
+
const prefix = cfg.tokens?.cookiePrefix ?? "holeauth";
|
|
4
|
+
switch (kind) {
|
|
5
|
+
case "access":
|
|
6
|
+
return `${prefix}.at`;
|
|
7
|
+
case "refresh":
|
|
8
|
+
return `${prefix}.rt`;
|
|
9
|
+
case "csrf":
|
|
10
|
+
return `${prefix}.csrf`;
|
|
11
|
+
case "pending":
|
|
12
|
+
return `${prefix}.pending`;
|
|
13
|
+
case "oauthState":
|
|
14
|
+
return `${prefix}.oauth.state`;
|
|
15
|
+
case "oauthPkce":
|
|
16
|
+
return `${prefix}.oauth.pkce`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function isProduction() {
|
|
20
|
+
return globalThis.process?.env?.NODE_ENV === "production";
|
|
21
|
+
}
|
|
22
|
+
function buildCookie(cfg, input) {
|
|
23
|
+
const httpOnly = input.httpOnly ?? input.kind !== "csrf";
|
|
24
|
+
const secure = cfg.tokens?.cookieSecure ?? isProduction();
|
|
25
|
+
return {
|
|
26
|
+
name: cookieName(cfg, input.kind),
|
|
27
|
+
value: input.value,
|
|
28
|
+
maxAge: input.maxAge,
|
|
29
|
+
httpOnly,
|
|
30
|
+
secure,
|
|
31
|
+
sameSite: input.sameSite ?? cfg.tokens?.sameSite ?? "lax",
|
|
32
|
+
path: input.path ?? "/",
|
|
33
|
+
domain: cfg.tokens?.cookieDomain
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function serializeCookie(c) {
|
|
37
|
+
const parts = [`${c.name}=${encodeURIComponent(c.value)}`];
|
|
38
|
+
parts.push(`Path=${c.path}`);
|
|
39
|
+
if (c.domain) parts.push(`Domain=${c.domain}`);
|
|
40
|
+
if (c.maxAge !== void 0) {
|
|
41
|
+
parts.push(`Max-Age=${c.maxAge}`);
|
|
42
|
+
if (c.maxAge === 0) parts.push("Expires=Thu, 01 Jan 1970 00:00:00 GMT");
|
|
43
|
+
}
|
|
44
|
+
if (c.httpOnly) parts.push("HttpOnly");
|
|
45
|
+
if (c.secure) parts.push("Secure");
|
|
46
|
+
parts.push(`SameSite=${c.sameSite.charAt(0).toUpperCase()}${c.sameSite.slice(1)}`);
|
|
47
|
+
return parts.join("; ");
|
|
48
|
+
}
|
|
49
|
+
function deleteCookie(cfg, kind) {
|
|
50
|
+
return buildCookie(cfg, { kind, value: "", maxAge: 0 });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/cookies/csrf.ts
|
|
54
|
+
var b64urlChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
55
|
+
function generateCsrfToken() {
|
|
56
|
+
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
57
|
+
let out = "";
|
|
58
|
+
for (const b of bytes) out += b64urlChars[b % 64];
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function verifyCsrf(cookieValue, headerValue) {
|
|
62
|
+
if (!cookieValue || !headerValue) return false;
|
|
63
|
+
if (cookieValue.length !== headerValue.length) return false;
|
|
64
|
+
let diff = 0;
|
|
65
|
+
for (let i = 0; i < cookieValue.length; i++) {
|
|
66
|
+
diff |= cookieValue.charCodeAt(i) ^ headerValue.charCodeAt(i);
|
|
67
|
+
}
|
|
68
|
+
return diff === 0;
|
|
69
|
+
}
|
|
70
|
+
var CSRF_HEADER = "x-csrf-token";
|
|
71
|
+
|
|
72
|
+
export { CSRF_HEADER, buildCookie, cookieName, deleteCookie, generateCsrfToken, isProduction, serializeCookie, verifyCsrf };
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cookies/spec.ts","../../src/cookies/csrf.ts"],"names":[],"mappings":";AAeO,SAAS,UAAA,CAAW,KAAqB,IAAA,EAA0B;AACxE,EAAA,MAAM,MAAA,GAAS,GAAA,CAAI,MAAA,EAAQ,YAAA,IAAgB,UAAA;AAC3C,EAAA,QAAQ,IAAA;AAAM,IACZ,KAAK,QAAA;AAAc,MAAA,OAAO,GAAG,MAAM,CAAA,GAAA,CAAA;AAAA,IACnC,KAAK,SAAA;AAAc,MAAA,OAAO,GAAG,MAAM,CAAA,GAAA,CAAA;AAAA,IACnC,KAAK,MAAA;AAAc,MAAA,OAAO,GAAG,MAAM,CAAA,KAAA,CAAA;AAAA,IACnC,KAAK,SAAA;AAAc,MAAA,OAAO,GAAG,MAAM,CAAA,QAAA,CAAA;AAAA,IACnC,KAAK,YAAA;AAAc,MAAA,OAAO,GAAG,MAAM,CAAA,YAAA,CAAA;AAAA,IACnC,KAAK,WAAA;AAAc,MAAA,OAAO,GAAG,MAAM,CAAA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,GAAI,WAAA,CAAY,QAAQ,CAAA,EAAA,EAAK;AAC3C,IAAA,IAAA,IAAQ,YAAY,UAAA,CAAW,CAAC,CAAA,GAAI,WAAA,CAAY,WAAW,CAAC,CAAA;AAAA,EAC9D;AACA,EAAA,OAAO,IAAA,KAAS,CAAA;AAClB;AAEO,IAAM,WAAA,GAAc","file":"index.js","sourcesContent":["import type { HoleauthConfig } from '../types/index.js';\n\nexport interface CookieSpec {\n name: string;\n value: string;\n maxAge?: number; // seconds; 0 means delete\n httpOnly: boolean;\n secure: boolean;\n sameSite: 'lax' | 'strict' | 'none';\n path: string;\n domain?: string;\n}\n\nexport type CookieName = 'access' | 'refresh' | 'csrf' | 'pending' | 'oauthState' | 'oauthPkce';\n\nexport function cookieName(cfg: HoleauthConfig, kind: CookieName): string {\n const prefix = cfg.tokens?.cookiePrefix ?? 'holeauth';\n switch (kind) {\n case 'access': return `${prefix}.at`;\n case 'refresh': return `${prefix}.rt`;\n case 'csrf': return `${prefix}.csrf`;\n case 'pending': return `${prefix}.pending`;\n case 'oauthState': return `${prefix}.oauth.state`;\n case 'oauthPkce': return `${prefix}.oauth.pkce`;\n }\n}\n\nexport function isProduction(): boolean {\n return (globalThis as { process?: { env?: { NODE_ENV?: string } } }).process?.env?.NODE_ENV === 'production';\n}\n\nexport interface BuildCookieInput {\n kind: CookieName;\n value: string;\n maxAge?: number; // seconds; 0 deletes\n /** CSRF is readable by JS — everything else is httpOnly. */\n httpOnly?: boolean;\n /** Override SameSite for the OAuth hop. */\n sameSite?: 'lax' | 'strict' | 'none';\n path?: string;\n}\n\nexport function buildCookie(cfg: HoleauthConfig, input: BuildCookieInput): CookieSpec {\n const httpOnly = input.httpOnly ?? input.kind !== 'csrf';\n const secure = cfg.tokens?.cookieSecure ?? isProduction();\n return {\n name: cookieName(cfg, input.kind),\n value: input.value,\n maxAge: input.maxAge,\n httpOnly,\n secure,\n sameSite: input.sameSite ?? cfg.tokens?.sameSite ?? 'lax',\n path: input.path ?? '/',\n domain: cfg.tokens?.cookieDomain,\n };\n}\n\n/** RFC 6265 serialisation used by Set-Cookie headers. */\nexport function serializeCookie(c: CookieSpec): string {\n const parts = [`${c.name}=${encodeURIComponent(c.value)}`];\n parts.push(`Path=${c.path}`);\n if (c.domain) parts.push(`Domain=${c.domain}`);\n if (c.maxAge !== undefined) {\n parts.push(`Max-Age=${c.maxAge}`);\n if (c.maxAge === 0) parts.push('Expires=Thu, 01 Jan 1970 00:00:00 GMT');\n }\n if (c.httpOnly) parts.push('HttpOnly');\n if (c.secure) parts.push('Secure');\n parts.push(`SameSite=${c.sameSite.charAt(0).toUpperCase()}${c.sameSite.slice(1)}`);\n return parts.join('; ');\n}\n\nexport function deleteCookie(cfg: HoleauthConfig, kind: CookieName): CookieSpec {\n return buildCookie(cfg, { kind, value: '', maxAge: 0 });\n}\n","/**\n * Double-submit CSRF protection.\n * The cookie holeauth.csrf is readable by JS (httpOnly:false). The client\n * echoes its value in header `x-csrf-token`; the server compares the two.\n * Because cross-origin JS cannot read the cookie, an attacker cannot mint\n * a matching header, defeating the cross-site POST scenario.\n */\n\nconst b64urlChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n\nexport function generateCsrfToken(): string {\n const bytes = crypto.getRandomValues(new Uint8Array(32));\n let out = '';\n for (const b of bytes) out += b64urlChars[b % 64];\n return out;\n}\n\n/** Constant-time compare. */\nexport function verifyCsrf(cookieValue: string | undefined, headerValue: string | undefined): boolean {\n if (!cookieValue || !headerValue) return false;\n if (cookieValue.length !== headerValue.length) return false;\n let diff = 0;\n for (let i = 0; i < cookieValue.length; i++) {\n diff |= cookieValue.charCodeAt(i) ^ headerValue.charCodeAt(i);\n }\n return diff === 0;\n}\n\nexport const CSRF_HEADER = 'x-csrf-token';\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
declare class HoleauthError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly status: number;
|
|
4
|
+
constructor(code: string, message: string, status?: number);
|
|
5
|
+
}
|
|
6
|
+
declare class InvalidTokenError extends HoleauthError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
declare class SessionExpiredError extends HoleauthError {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
declare class AdapterError extends HoleauthError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
declare class ProviderError extends HoleauthError {
|
|
16
|
+
constructor(message?: string);
|
|
17
|
+
}
|
|
18
|
+
declare class CsrfError extends HoleauthError {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
declare class CredentialsError extends HoleauthError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
declare class AccountConflictError extends HoleauthError {
|
|
25
|
+
constructor(message?: string);
|
|
26
|
+
}
|
|
27
|
+
declare class RefreshReuseError extends HoleauthError {
|
|
28
|
+
constructor(message?: string);
|
|
29
|
+
}
|
|
30
|
+
declare class PendingChallengeError extends HoleauthError {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
declare class RegistrationDisabledError extends HoleauthError {
|
|
34
|
+
constructor(message?: string);
|
|
35
|
+
}
|
|
36
|
+
declare class NotSupportedError extends HoleauthError {
|
|
37
|
+
constructor(message?: string);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { AccountConflictError, AdapterError, CredentialsError, CsrfError, HoleauthError, InvalidTokenError, NotSupportedError, PendingChallengeError, ProviderError, RefreshReuseError, RegistrationDisabledError, SessionExpiredError };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/errors/index.ts
|
|
2
|
+
var HoleauthError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
constructor(code, message, status = 400) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "HoleauthError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.status = status;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var InvalidTokenError = class extends HoleauthError {
|
|
13
|
+
constructor(message = "Invalid token") {
|
|
14
|
+
super("INVALID_TOKEN", message, 401);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var SessionExpiredError = class extends HoleauthError {
|
|
18
|
+
constructor(message = "Session expired") {
|
|
19
|
+
super("SESSION_EXPIRED", message, 401);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var AdapterError = class extends HoleauthError {
|
|
23
|
+
constructor(message = "Adapter error") {
|
|
24
|
+
super("ADAPTER_ERROR", message, 500);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var ProviderError = class extends HoleauthError {
|
|
28
|
+
constructor(message = "Provider error") {
|
|
29
|
+
super("PROVIDER_ERROR", message, 502);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var CsrfError = class extends HoleauthError {
|
|
33
|
+
constructor(message = "CSRF validation failed") {
|
|
34
|
+
super("CSRF_FAILED", message, 403);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var CredentialsError = class extends HoleauthError {
|
|
38
|
+
constructor(message = "Invalid credentials") {
|
|
39
|
+
super("INVALID_CREDENTIALS", message, 401);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var AccountConflictError = class extends HoleauthError {
|
|
43
|
+
constructor(message = "Account conflict") {
|
|
44
|
+
super("ACCOUNT_CONFLICT", message, 409);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var RefreshReuseError = class extends HoleauthError {
|
|
48
|
+
constructor(message = "Refresh token reuse detected") {
|
|
49
|
+
super("REFRESH_REUSE", message, 401);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var PendingChallengeError = class extends HoleauthError {
|
|
53
|
+
constructor(message = "Pending challenge required") {
|
|
54
|
+
super("PENDING_CHALLENGE", message, 401);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var RegistrationDisabledError = class extends HoleauthError {
|
|
58
|
+
constructor(message = "Self-registration is disabled") {
|
|
59
|
+
super("REGISTRATION_DISABLED", message, 403);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var NotSupportedError = class extends HoleauthError {
|
|
63
|
+
constructor(message = "Operation not supported by adapter") {
|
|
64
|
+
super("NOT_SUPPORTED", message, 501);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { AccountConflictError, AdapterError, CredentialsError, CsrfError, HoleauthError, InvalidTokenError, NotSupportedError, PendingChallengeError, ProviderError, RefreshReuseError, RegistrationDisabledError, SessionExpiredError };
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,IAAA;AAAA,EACA,MAAA;AAAA,EACT,WAAA,CAAY,IAAA,EAAc,OAAA,EAAiB,MAAA,GAAS,GAAA,EAAK;AACvD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF;AACO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,WAAA,CAAY,UAAU,eAAA,EAAiB;AAAE,IAAA,KAAA,CAAM,eAAA,EAAiB,SAAS,GAAG,CAAA;AAAA,EAAG;AACjF;AACO,IAAM,mBAAA,GAAN,cAAkC,aAAA,CAAc;AAAA,EACrD,WAAA,CAAY,UAAU,iBAAA,EAAmB;AAAE,IAAA,KAAA,CAAM,iBAAA,EAAmB,SAAS,GAAG,CAAA;AAAA,EAAG;AACrF;AACO,IAAM,YAAA,GAAN,cAA2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SAAS,GAAG,CAAA;AAAA,EAAG;AACzG;AACO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,WAAA,CAAY,UAAU,oCAAA,EAAsC;AAAE,IAAA,KAAA,CAAM,eAAA,EAAiB,SAAS,GAAG,CAAA;AAAA,EAAG;AACtG","file":"index.js","sourcesContent":["export class HoleauthError extends Error {\n readonly code: string;\n readonly status: number;\n constructor(code: string, message: string, status = 400) {\n super(message);\n this.name = 'HoleauthError';\n this.code = code;\n this.status = status;\n }\n}\nexport class InvalidTokenError extends HoleauthError {\n constructor(message = 'Invalid token') { super('INVALID_TOKEN', message, 401); }\n}\nexport class SessionExpiredError extends HoleauthError {\n constructor(message = 'Session expired') { super('SESSION_EXPIRED', message, 401); }\n}\nexport class AdapterError extends HoleauthError {\n constructor(message = 'Adapter error') { super('ADAPTER_ERROR', message, 500); }\n}\nexport class ProviderError extends HoleauthError {\n constructor(message = 'Provider error') { super('PROVIDER_ERROR', message, 502); }\n}\nexport class CsrfError extends HoleauthError {\n constructor(message = 'CSRF validation failed') { super('CSRF_FAILED', message, 403); }\n}\nexport class CredentialsError extends HoleauthError {\n constructor(message = 'Invalid credentials') { super('INVALID_CREDENTIALS', message, 401); }\n}\nexport class AccountConflictError extends HoleauthError {\n constructor(message = 'Account conflict') { super('ACCOUNT_CONFLICT', message, 409); }\n}\nexport class RefreshReuseError extends HoleauthError {\n constructor(message = 'Refresh token reuse detected') { super('REFRESH_REUSE', message, 401); }\n}\nexport class PendingChallengeError extends HoleauthError {\n constructor(message = 'Pending challenge required') { super('PENDING_CHALLENGE', message, 401); }\n}\nexport class RegistrationDisabledError extends HoleauthError {\n constructor(message = 'Self-registration is disabled') { super('REGISTRATION_DISABLED', message, 403); }\n}\nexport class NotSupportedError extends HoleauthError {\n constructor(message = 'Operation not supported by adapter') { super('NOT_SUPPORTED', message, 501); }\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/events/emitter.ts
|
|
2
|
+
var busByConfig = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function getBus(cfg) {
|
|
4
|
+
let bus = busByConfig.get(cfg);
|
|
5
|
+
if (!bus) {
|
|
6
|
+
bus = { byType: /* @__PURE__ */ new Map(), wildcard: /* @__PURE__ */ new Set() };
|
|
7
|
+
busByConfig.set(cfg, bus);
|
|
8
|
+
}
|
|
9
|
+
return bus;
|
|
10
|
+
}
|
|
11
|
+
function subscribe(cfg, type, handler) {
|
|
12
|
+
const bus = getBus(cfg);
|
|
13
|
+
if (type === "*") {
|
|
14
|
+
bus.wildcard.add(handler);
|
|
15
|
+
return () => bus.wildcard.delete(handler);
|
|
16
|
+
}
|
|
17
|
+
let set = bus.byType.get(type);
|
|
18
|
+
if (!set) {
|
|
19
|
+
set = /* @__PURE__ */ new Set();
|
|
20
|
+
bus.byType.set(type, set);
|
|
21
|
+
}
|
|
22
|
+
set.add(handler);
|
|
23
|
+
return () => set.delete(handler);
|
|
24
|
+
}
|
|
25
|
+
function unsubscribe(cfg, type, handler) {
|
|
26
|
+
const bus = getBus(cfg);
|
|
27
|
+
if (type === "*") {
|
|
28
|
+
bus.wildcard.delete(handler);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
bus.byType.get(type)?.delete(handler);
|
|
32
|
+
}
|
|
33
|
+
async function emit(cfg, event) {
|
|
34
|
+
const withTimestamp = { at: /* @__PURE__ */ new Date(), ...event };
|
|
35
|
+
await cfg.adapters.auditLog.record(withTimestamp);
|
|
36
|
+
const bus = getBus(cfg);
|
|
37
|
+
const typed = bus.byType.get(withTimestamp.type);
|
|
38
|
+
const fire = (h) => {
|
|
39
|
+
Promise.resolve().then(() => h(withTimestamp)).catch(() => {
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
if (typed) for (const h of typed) fire(h);
|
|
43
|
+
for (const h of bus.wildcard) fire(h);
|
|
44
|
+
if (cfg.onEvent) {
|
|
45
|
+
Promise.resolve().then(() => cfg.onEvent?.(withTimestamp)).catch(() => {
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { emit, subscribe, unsubscribe };
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/events/emitter.ts"],"names":[],"mappings":";AAUA,IAAM,WAAA,uBAAkB,OAAA,EAAkC;AAE1D,SAAS,OAAO,GAAA,EAA+B;AAC7C,EAAA,IAAI,GAAA,GAAM,WAAA,CAAY,GAAA,CAAI,GAAG,CAAA;AAC7B,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,GAAA,GAAM,EAAE,wBAAQ,IAAI,GAAA,IAAO,QAAA,kBAAU,IAAI,KAAI,EAAE;AAC/C,IAAA,WAAA,CAAY,GAAA,CAAI,KAAK,GAAG,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,SAAA,CAAU,GAAA,EAAqB,IAAA,EAAc,OAAA,EAA8B;AACzF,EAAA,MAAM,GAAA,GAAM,OAAO,GAAG,CAAA;AACtB,EAAA,IAAI,SAAS,GAAA,EAAK;AAChB,IAAA,GAAA,CAAI,QAAA,CAAS,IAAI,OAAO,CAAA;AACxB,IAAA,OAAO,MAAM,GAAA,CAAI,QAAA,CAAS,MAAA,CAAO,OAAO,CAAA;AAAA,EAC1C;AACA,EAAA,IAAI,GAAA,GAAM,GAAA,CAAI,MAAA,CAAO,GAAA,CAAI,IAAI,CAAA;AAC7B,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,GAAA,uBAAU,GAAA,EAAI;AACd,IAAA,GAAA,CAAI,MAAA,CAAO,GAAA,CAAI,IAAA,EAAM,GAAG,CAAA;AAAA,EAC1B;AACA,EAAA,GAAA,CAAI,IAAI,OAAO,CAAA;AACf,EAAA,OAAO,MAAM,GAAA,CAAK,MAAA,CAAO,OAAO,CAAA;AAClC;AA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import type { HoleauthConfig } from '../types/index.js';\nimport type { HoleauthEvent } from './types.js';\n\ntype Handler = (e: HoleauthEvent) => void | Promise<void>;\n\ninterface EventBus {\n byType: Map<string, Set<Handler>>;\n wildcard: Set<Handler>;\n}\n\nconst busByConfig = new WeakMap<HoleauthConfig, EventBus>();\n\nfunction getBus(cfg: HoleauthConfig): EventBus {\n let bus = busByConfig.get(cfg);\n if (!bus) {\n bus = { byType: new Map(), wildcard: new Set() };\n busByConfig.set(cfg, bus);\n }\n return bus;\n}\n\n/** Subscribe to an event type. Use '*' to match all events. Returns an unsubscribe fn. */\nexport function subscribe(cfg: HoleauthConfig, type: string, handler: Handler): () => void {\n const bus = getBus(cfg);\n if (type === '*') {\n bus.wildcard.add(handler);\n return () => bus.wildcard.delete(handler);\n }\n let set = bus.byType.get(type);\n if (!set) {\n set = new Set();\n bus.byType.set(type, set);\n }\n set.add(handler);\n return () => set!.delete(handler);\n}\n\nexport function unsubscribe(cfg: HoleauthConfig, type: string, handler: Handler): void {\n const bus = getBus(cfg);\n if (type === '*') {\n bus.wildcard.delete(handler);\n return;\n }\n bus.byType.get(type)?.delete(handler);\n}\n\n/**\n * emit() persists the event via the mandatory AuditLogAdapter and\n * additionally fans out to all subscribers (typed + wildcard) plus the\n * legacy `cfg.onEvent` hook — all fire-and-forget so business flows are\n * never blocked by observer failures.\n *\n * Callers MUST await emit(): audit persistence is a hard requirement.\n */\nexport async function emit(cfg: HoleauthConfig, event: HoleauthEvent): Promise<void> {\n const withTimestamp: HoleauthEvent = { at: new Date(), ...event };\n await cfg.adapters.auditLog.record(withTimestamp);\n\n const bus = getBus(cfg);\n const typed = bus.byType.get(withTimestamp.type);\n const fire = (h: Handler) => {\n Promise.resolve()\n .then(() => h(withTimestamp))\n .catch(() => { /* observer errors do not propagate */ });\n };\n if (typed) for (const h of typed) fire(h);\n for (const h of bus.wildcard) fire(h);\n\n if (cfg.onEvent) {\n Promise.resolve()\n .then(() => cfg.onEvent?.(withTimestamp))\n .catch(() => { /* observer errors do not propagate */ });\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { c as changePassword, a as consumeInvite, b as consumePasswordReset, d as createInvite, e as deleteUser, g as getInviteInfo, f as issuePendingToken, l as listInvites, r as refresh, h as register, j as requestPasswordReset, k as revokeInvite, s as signIn, m as signOut, u as updateUser, v as verifyPendingToken } from '../index-BbEXbI_k.js';
|
|
2
|
+
import '../index-BmYQquGs.js';
|
|
3
|
+
import '../index-CNtnPdzk.js';
|
|
4
|
+
import '../registry-CZhM1tEB.js';
|