@bgord/bun 0.17.0 → 0.18.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/dist/auth-shield.middleware.d.ts +11 -24
- package/dist/auth-shield.middleware.d.ts.map +1 -1
- package/dist/auth-shield.middleware.js +21 -60
- package/dist/auth-shield.middleware.js.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/policy.service.d.ts +3 -3
- package/dist/policy.service.d.ts.map +1 -1
- package/dist/policy.service.js +4 -4
- package/dist/policy.service.js.map +1 -1
- package/dist/setup.service.d.ts +8 -2
- package/dist/setup.service.d.ts.map +1 -1
- package/dist/setup.service.js +4 -2
- package/dist/setup.service.js.map +1 -1
- package/dist/translations.service.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/readme.md +0 -3
- package/src/auth-shield.middleware.ts +24 -97
- package/src/index.ts +0 -3
- package/src/policy.service.ts +5 -5
- package/src/setup.service.ts +10 -2
- package/dist/passwords.vo.d.ts +0 -21
- package/dist/passwords.vo.d.ts.map +0 -1
- package/dist/passwords.vo.js +0 -42
- package/dist/passwords.vo.js.map +0 -1
- package/dist/session-id.vo.d.ts +0 -7
- package/dist/session-id.vo.d.ts.map +0 -1
- package/dist/session-id.vo.js +0 -10
- package/dist/session-id.vo.js.map +0 -1
- package/dist/username.vo.d.ts +0 -11
- package/dist/username.vo.d.ts.map +0 -1
- package/dist/username.vo.js +0 -13
- package/dist/username.vo.js.map +0 -1
- package/src/passwords.vo.ts +0 -56
- package/src/session-id.vo.ts +0 -13
- package/src/username.vo.ts +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"@biomejs/biome": "2.0.6",
|
|
24
24
|
"@commitlint/cli": "19.8.1",
|
|
25
25
|
"@commitlint/config-conventional": "19.8.1",
|
|
26
|
-
"@types/bun": "1.2.
|
|
26
|
+
"@types/bun": "1.2.19",
|
|
27
27
|
"@types/lodash": "4.17.20",
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
29
|
"@types/nodemailer": "6.4.17",
|
|
30
|
-
"cspell": "9.
|
|
31
|
-
"knip": "5.
|
|
30
|
+
"cspell": "9.2.0",
|
|
31
|
+
"knip": "5.62.0",
|
|
32
32
|
"lefthook": "1.12.2",
|
|
33
33
|
"only-allow": "1.2.1",
|
|
34
34
|
"shellcheck": "3.1.0",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@axiomhq/winston": "1.3.1",
|
|
39
|
-
"@bgord/tools": "0.
|
|
40
|
-
"@hono/ua-blocker": "0.1.
|
|
39
|
+
"@bgord/tools": "0.12.0",
|
|
40
|
+
"@hono/ua-blocker": "0.1.6",
|
|
41
|
+
"better-auth": "1.3.2",
|
|
41
42
|
"check-disk-space": "3.4.0",
|
|
42
43
|
"croner": "9.1.0",
|
|
43
44
|
"hcaptcha": "0.2.0",
|
|
44
|
-
"hono": "4.8.
|
|
45
|
+
"hono": "4.8.5",
|
|
45
46
|
"lodash": "4.17.21",
|
|
46
|
-
"lucia": "3.2.2",
|
|
47
47
|
"mime-types": "3.0.1",
|
|
48
48
|
"node-cache": "5.1.2",
|
|
49
49
|
"nodemailer": "7.0.5",
|
package/readme.md
CHANGED
|
@@ -67,7 +67,6 @@ src/
|
|
|
67
67
|
├── new-uuid.service.ts
|
|
68
68
|
├── node-env.vo.ts
|
|
69
69
|
├── open-graph.service.ts
|
|
70
|
-
├── passwords.vo.ts
|
|
71
70
|
├── path.vo.ts
|
|
72
71
|
├── policy-error-handler.service.ts
|
|
73
72
|
├── policy.service.ts
|
|
@@ -95,7 +94,6 @@ src/
|
|
|
95
94
|
├── rate-limit-shield.middleware.ts
|
|
96
95
|
├── recaptcha-shield.middleware.ts
|
|
97
96
|
├── safe-parse-body.service.ts
|
|
98
|
-
├── session-id.vo.ts
|
|
99
97
|
├── setup.service.ts
|
|
100
98
|
├── simulated-error.middleware.ts
|
|
101
99
|
├── sitemap.service.ts
|
|
@@ -105,7 +103,6 @@ src/
|
|
|
105
103
|
├── translations.service.ts
|
|
106
104
|
├── uptime.service.ts
|
|
107
105
|
├── url-wo-trailing-slash.vo.ts
|
|
108
|
-
├── username.vo.ts
|
|
109
106
|
├── uuid.vo.ts
|
|
110
107
|
└── weak-etag-extractor.middleware.ts
|
|
111
108
|
```
|
|
@@ -1,44 +1,37 @@
|
|
|
1
|
+
// TODO: tests
|
|
2
|
+
|
|
3
|
+
import type { betterAuth } from "better-auth";
|
|
1
4
|
import hono from "hono";
|
|
2
5
|
import { createMiddleware } from "hono/factory";
|
|
3
6
|
import { HTTPException } from "hono/http-exception";
|
|
4
|
-
import { Lucia } from "lucia";
|
|
5
|
-
|
|
6
|
-
import { HashedPassword, Password, PasswordType } from "./passwords.vo";
|
|
7
|
-
import { SessionId } from "./session-id.vo";
|
|
8
|
-
import { IdType, Username } from "./username.vo";
|
|
9
|
-
|
|
10
|
-
type AuthShieldConfigType<T> = {
|
|
11
|
-
Username: typeof Username;
|
|
12
|
-
Password: typeof Password;
|
|
13
|
-
HashedPassword: typeof HashedPassword;
|
|
14
|
-
lucia: Lucia;
|
|
15
|
-
findUniqueUserOrThrow: (username: Username) => Promise<T>;
|
|
16
|
-
};
|
|
17
7
|
|
|
18
8
|
export const AccessDeniedAuthShieldError = new HTTPException(403, {
|
|
19
9
|
message: "access_denied_auth_shield",
|
|
20
10
|
});
|
|
21
11
|
|
|
22
|
-
export class AuthShield
|
|
23
|
-
|
|
12
|
+
export class AuthShield {
|
|
13
|
+
cors = {
|
|
14
|
+
origin: ["http://localhost:5173", "http://localhost:3000"],
|
|
15
|
+
credentials: true,
|
|
16
|
+
allowHeaders: ["Content-Type"],
|
|
17
|
+
exposeHeaders: ["Set-Cookie"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
constructor(private readonly Auth: ReturnType<typeof betterAuth>) {}
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Username: overrides.Username ?? Username,
|
|
34
|
-
Password: overrides.Password ?? Password,
|
|
35
|
-
HashedPassword: overrides.HashedPassword ?? HashedPassword,
|
|
36
|
-
lucia: overrides.lucia,
|
|
37
|
-
findUniqueUserOrThrow: overrides.findUniqueUserOrThrow,
|
|
38
|
-
};
|
|
22
|
+
attach = createMiddleware(async (c: hono.Context, next: hono.Next) => {
|
|
23
|
+
const session = await this.Auth.api.getSession({ headers: c.req.raw.headers });
|
|
24
|
+
|
|
25
|
+
if (!session) {
|
|
26
|
+
c.set("user", null);
|
|
27
|
+
c.set("session", null);
|
|
28
|
+
return next();
|
|
29
|
+
}
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
c.set("user", session.user);
|
|
32
|
+
c.set("session", session.session);
|
|
33
|
+
return next();
|
|
34
|
+
});
|
|
42
35
|
|
|
43
36
|
verify = createMiddleware(async (c: hono.Context, next: hono.Next) => {
|
|
44
37
|
const user = c.get("user");
|
|
@@ -59,70 +52,4 @@ export class AuthShield<T extends { password: PasswordType; id: IdType }> {
|
|
|
59
52
|
|
|
60
53
|
return next();
|
|
61
54
|
});
|
|
62
|
-
|
|
63
|
-
detach = createMiddleware(async (c: hono.Context, next: hono.Next) => {
|
|
64
|
-
const cookie = c.req.header("cookie");
|
|
65
|
-
|
|
66
|
-
const sessionId = new SessionId(cookie, this.config.lucia).get();
|
|
67
|
-
|
|
68
|
-
if (!sessionId) return next();
|
|
69
|
-
|
|
70
|
-
await this.config.lucia.invalidateSession(sessionId);
|
|
71
|
-
|
|
72
|
-
return next();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
build = createMiddleware(async (c: hono.Context, next: hono.Next) => {
|
|
76
|
-
const cookie = c.req.header("cookie");
|
|
77
|
-
|
|
78
|
-
const sessionId = new SessionId(cookie, this.config.lucia).get();
|
|
79
|
-
|
|
80
|
-
if (!sessionId) {
|
|
81
|
-
c.set("user", null);
|
|
82
|
-
c.set("session", null);
|
|
83
|
-
|
|
84
|
-
return next();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const { session, user } = await this.config.lucia.validateSession(sessionId);
|
|
88
|
-
|
|
89
|
-
if (!session) {
|
|
90
|
-
c.res.headers.set("Set-Cookie", this.config.lucia.createBlankSessionCookie().serialize());
|
|
91
|
-
c.set("user", null);
|
|
92
|
-
c.set("session", null);
|
|
93
|
-
|
|
94
|
-
return next();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (session.fresh) {
|
|
98
|
-
c.res.headers.set("Set-Cookie", this.config.lucia.createSessionCookie(session.id).serialize());
|
|
99
|
-
}
|
|
100
|
-
c.set("user", user);
|
|
101
|
-
c.set("session", session);
|
|
102
|
-
|
|
103
|
-
return next();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
attach = createMiddleware(async (c: hono.Context, next: hono.Next) => {
|
|
107
|
-
try {
|
|
108
|
-
const body = await c.req.raw.clone().formData();
|
|
109
|
-
|
|
110
|
-
const username = new this.config.Username(body.get("username") as string);
|
|
111
|
-
const password = new this.config.Password(body.get("password") as string);
|
|
112
|
-
|
|
113
|
-
const user = await this.config.findUniqueUserOrThrow(username);
|
|
114
|
-
|
|
115
|
-
const hashedPassword = await this.config.HashedPassword.fromHash(user.password);
|
|
116
|
-
await hashedPassword.matchesOrThrow(password);
|
|
117
|
-
|
|
118
|
-
const session = await this.config.lucia.createSession(user.id, {});
|
|
119
|
-
const sessionCookie = this.config.lucia.createSessionCookie(session.id);
|
|
120
|
-
|
|
121
|
-
c.res.headers.set("Set-Cookie", sessionCookie.serialize());
|
|
122
|
-
|
|
123
|
-
return next();
|
|
124
|
-
} catch (_error) {
|
|
125
|
-
throw AccessDeniedAuthShieldError;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,6 @@ export * from "./memory-consumption.service";
|
|
|
41
41
|
export * from "./new-uuid.service";
|
|
42
42
|
export * from "./node-env.vo";
|
|
43
43
|
export * from "./open-graph.service";
|
|
44
|
-
export * from "./passwords.vo";
|
|
45
44
|
export * from "./path.vo";
|
|
46
45
|
export * from "./policy.service";
|
|
47
46
|
export * from "./policy-error-handler.service";
|
|
@@ -51,7 +50,6 @@ export * from "./prerequisites.service";
|
|
|
51
50
|
export * from "./rate-limit-shield.middleware";
|
|
52
51
|
export * from "./recaptcha-shield.middleware";
|
|
53
52
|
export * from "./safe-parse-body.service";
|
|
54
|
-
export * from "./session-id.vo";
|
|
55
53
|
export * from "./setup.service";
|
|
56
54
|
export * from "./simulated-error.middleware";
|
|
57
55
|
export * from "./sitemap.service";
|
|
@@ -61,6 +59,5 @@ export * from "./to-event-map.types";
|
|
|
61
59
|
export * from "./translations.service";
|
|
62
60
|
export * from "./uptime.service";
|
|
63
61
|
export * from "./url-wo-trailing-slash.vo";
|
|
64
|
-
export * from "./username.vo";
|
|
65
62
|
export * from "./uuid.vo";
|
|
66
63
|
export * from "./weak-etag-extractor.middleware";
|
package/src/policy.service.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ContentfulStatusCode } from "hono/utils/http-status";
|
|
|
4
4
|
type BasePolicyConfig = Record<string, unknown>;
|
|
5
5
|
|
|
6
6
|
export abstract class Policy<T extends BasePolicyConfig> {
|
|
7
|
-
abstract fails(config: T):
|
|
7
|
+
abstract fails(config: T): boolean;
|
|
8
8
|
|
|
9
9
|
abstract error: Constructor<Error>;
|
|
10
10
|
|
|
@@ -16,13 +16,13 @@ export abstract class Policy<T extends BasePolicyConfig> {
|
|
|
16
16
|
throw new this.error();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
if (
|
|
19
|
+
perform(config: T) {
|
|
20
|
+
if (this.fails(config)) {
|
|
21
21
|
this.throw();
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
return !
|
|
25
|
+
passes(config: T) {
|
|
26
|
+
return !this.fails(config);
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/setup.service.ts
CHANGED
|
@@ -23,17 +23,25 @@ export const BODY_LIMIT_MAX_SIZE = new tools.Size({
|
|
|
23
23
|
unit: tools.SizeUnit.kB,
|
|
24
24
|
}).toBytes();
|
|
25
25
|
|
|
26
|
+
// TODO: test custom cors options
|
|
27
|
+
type CorsOptions = Parameters<typeof cors>[0];
|
|
28
|
+
|
|
29
|
+
type SetupOverridesType = { cors?: CorsOptions };
|
|
30
|
+
|
|
26
31
|
export class Setup {
|
|
27
|
-
static essentials(logger: Logger, i18n: I18nConfigType) {
|
|
32
|
+
static essentials(logger: Logger, i18n: I18nConfigType, overrides?: SetupOverridesType) {
|
|
33
|
+
const corsOptions = overrides?.cors ?? { origin: "*" };
|
|
34
|
+
|
|
28
35
|
return [
|
|
29
36
|
secureHeaders(),
|
|
30
37
|
bodyLimit({ maxSize: BODY_LIMIT_MAX_SIZE }),
|
|
31
38
|
uaBlocker({ blocklist: BOTS_REGEX }),
|
|
32
39
|
ApiVersion.attach,
|
|
33
|
-
cors(
|
|
40
|
+
cors(corsOptions),
|
|
34
41
|
languageDetector({
|
|
35
42
|
supportedLanguages: Object.keys(i18n.supportedLanguages),
|
|
36
43
|
fallbackLanguage: i18n.defaultLanguage,
|
|
44
|
+
caches: false,
|
|
37
45
|
}),
|
|
38
46
|
requestId({ limitLength: 36, headerName: "x-correlation-id" }),
|
|
39
47
|
TimeZoneOffset.attach,
|
package/dist/passwords.vo.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
export type PasswordType = string;
|
|
3
|
-
type HashedPasswordType = string;
|
|
4
|
-
export declare class Password {
|
|
5
|
-
private schema;
|
|
6
|
-
private value;
|
|
7
|
-
constructor(value: PasswordType, schema?: z.ZodSchema);
|
|
8
|
-
hash(): Promise<HashedPassword>;
|
|
9
|
-
read(): PasswordType;
|
|
10
|
-
}
|
|
11
|
-
export declare class HashedPassword {
|
|
12
|
-
private value;
|
|
13
|
-
private constructor();
|
|
14
|
-
static fromPassword(password: Password): Promise<HashedPassword>;
|
|
15
|
-
static fromHash(value: HashedPasswordType): Promise<HashedPassword>;
|
|
16
|
-
read(): HashedPasswordType;
|
|
17
|
-
matches(password: Password): Promise<boolean>;
|
|
18
|
-
matchesOrThrow(password: Password): Promise<true>;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=passwords.vo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"passwords.vo.d.ts","sourceRoot":"","sources":["../src/passwords.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,KAAK,kBAAkB,GAAG,MAAM,CAAC;AAEjC,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAA2C;IAEzD,OAAO,CAAC,KAAK,CAAe;gBAEhB,KAAK,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS;IAK/C,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC;IAIrC,IAAI,IAAI,YAAY;CAGrB;AAED,qBAAa,cAAc;IACL,OAAO,CAAC,KAAK;IAAjC,OAAO;WAEM,YAAY,CAAC,QAAQ,EAAE,QAAQ;WAM/B,QAAQ,CAAC,KAAK,EAAE,kBAAkB;IAI/C,IAAI,IAAI,kBAAkB;IAIpB,OAAO,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7C,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CASxD"}
|
package/dist/passwords.vo.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
export class Password {
|
|
3
|
-
schema = z.string().min(1).max(256);
|
|
4
|
-
value;
|
|
5
|
-
constructor(value, schema) {
|
|
6
|
-
this.schema = schema ?? this.schema;
|
|
7
|
-
this.value = this.schema.parse(value);
|
|
8
|
-
}
|
|
9
|
-
async hash() {
|
|
10
|
-
return HashedPassword.fromPassword(this);
|
|
11
|
-
}
|
|
12
|
-
read() {
|
|
13
|
-
return this.value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class HashedPassword {
|
|
17
|
-
value;
|
|
18
|
-
constructor(value) {
|
|
19
|
-
this.value = value;
|
|
20
|
-
}
|
|
21
|
-
static async fromPassword(password) {
|
|
22
|
-
const hash = await Bun.password.hash(password.read());
|
|
23
|
-
return new HashedPassword(hash);
|
|
24
|
-
}
|
|
25
|
-
static async fromHash(value) {
|
|
26
|
-
return new HashedPassword(value);
|
|
27
|
-
}
|
|
28
|
-
read() {
|
|
29
|
-
return this.value;
|
|
30
|
-
}
|
|
31
|
-
async matches(password) {
|
|
32
|
-
return Bun.password.verify(password.read(), this.read());
|
|
33
|
-
}
|
|
34
|
-
async matchesOrThrow(password) {
|
|
35
|
-
const matches = await Bun.password.verify(password.read(), this.read());
|
|
36
|
-
if (!matches) {
|
|
37
|
-
throw new Error("HashedPassword does not match the provided password");
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=passwords.vo.js.map
|
package/dist/passwords.vo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"passwords.vo.js","sourceRoot":"","sources":["../src/passwords.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAM3B,MAAM,OAAO,QAAQ;IACX,MAAM,GAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEjD,KAAK,CAAe;IAE5B,YAAY,KAAmB,EAAE,MAAoB;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAiB,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAED,MAAM,OAAO,cAAc;IACG;IAA5B,YAA4B,KAAyB;QAAzB,UAAK,GAAL,KAAK,CAAoB;IAAG,CAAC;IAEzD,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,QAAkB;QAC1C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAEtD,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAyB;QAC7C,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAkB;QAC9B,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,QAAkB;QACrC,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAExE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/session-id.vo.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-id.vo.d.ts","sourceRoot":"","sources":["../src/session-id.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAgB;gBAEjB,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK;IAIpD,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC;CAG1B"}
|
package/dist/session-id.vo.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-id.vo.js","sourceRoot":"","sources":["../src/session-id.vo.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,SAAS;IACZ,KAAK,CAAgB;IAE7B,YAAY,MAA0B,EAAE,KAAY;QAClD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,iBAAiB,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
package/dist/username.vo.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
export type IdType = string;
|
|
3
|
-
type UsernameType = string;
|
|
4
|
-
export declare class Username {
|
|
5
|
-
private readonly schema;
|
|
6
|
-
private readonly value;
|
|
7
|
-
constructor(value: UsernameType, schema?: z.ZodSchema);
|
|
8
|
-
read(): UsernameType;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=username.vo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"username.vo.d.ts","sourceRoot":"","sources":["../src/username.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,KAAK,YAAY,GAAG,MAAM,CAAC;AAE3B,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAE3D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEzB,KAAK,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS;IAKrD,IAAI,IAAI,YAAY;CAGrB"}
|
package/dist/username.vo.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
export class Username {
|
|
3
|
-
schema = z.string().max(256);
|
|
4
|
-
value;
|
|
5
|
-
constructor(value, schema) {
|
|
6
|
-
this.schema = schema ?? this.schema;
|
|
7
|
-
this.value = this.schema.parse(value);
|
|
8
|
-
}
|
|
9
|
-
read() {
|
|
10
|
-
return this.value;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=username.vo.js.map
|
package/dist/username.vo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"username.vo.js","sourceRoot":"","sources":["../src/username.vo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAM3B,MAAM,OAAO,QAAQ;IACF,MAAM,GAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAE1C,KAAK,CAAe;IAErC,YAAY,KAAmB,EAAE,MAAoB;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAiB,CAAC;IACxD,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
package/src/passwords.vo.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
|
|
3
|
-
export type PasswordType = string;
|
|
4
|
-
|
|
5
|
-
type HashedPasswordType = string;
|
|
6
|
-
|
|
7
|
-
export class Password {
|
|
8
|
-
private schema: z.ZodSchema = z.string().min(1).max(256);
|
|
9
|
-
|
|
10
|
-
private value: PasswordType;
|
|
11
|
-
|
|
12
|
-
constructor(value: PasswordType, schema?: z.ZodSchema) {
|
|
13
|
-
this.schema = schema ?? this.schema;
|
|
14
|
-
this.value = this.schema.parse(value) as PasswordType;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async hash(): Promise<HashedPassword> {
|
|
18
|
-
return HashedPassword.fromPassword(this);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
read(): PasswordType {
|
|
22
|
-
return this.value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class HashedPassword {
|
|
27
|
-
private constructor(private value: HashedPasswordType) {}
|
|
28
|
-
|
|
29
|
-
static async fromPassword(password: Password) {
|
|
30
|
-
const hash = await Bun.password.hash(password.read());
|
|
31
|
-
|
|
32
|
-
return new HashedPassword(hash);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static async fromHash(value: HashedPasswordType) {
|
|
36
|
-
return new HashedPassword(value);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
read(): HashedPasswordType {
|
|
40
|
-
return this.value;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async matches(password: Password): Promise<boolean> {
|
|
44
|
-
return Bun.password.verify(password.read(), this.read());
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async matchesOrThrow(password: Password): Promise<true> {
|
|
48
|
-
const matches = await Bun.password.verify(password.read(), this.read());
|
|
49
|
-
|
|
50
|
-
if (!matches) {
|
|
51
|
-
throw new Error("HashedPassword does not match the provided password");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/session-id.vo.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Lucia } from "lucia";
|
|
2
|
-
|
|
3
|
-
export class SessionId {
|
|
4
|
-
private value: string | null;
|
|
5
|
-
|
|
6
|
-
constructor(cookie: string | undefined, lucia: Lucia) {
|
|
7
|
-
this.value = lucia.readSessionCookie(cookie ?? "");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get(): SessionId["value"] {
|
|
11
|
-
return this.value;
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/username.vo.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
|
|
3
|
-
export type IdType = string;
|
|
4
|
-
|
|
5
|
-
type UsernameType = string;
|
|
6
|
-
|
|
7
|
-
export class Username {
|
|
8
|
-
private readonly schema: z.ZodSchema = z.string().max(256);
|
|
9
|
-
|
|
10
|
-
private readonly value: UsernameType;
|
|
11
|
-
|
|
12
|
-
constructor(value: UsernameType, schema?: z.ZodSchema) {
|
|
13
|
-
this.schema = schema ?? this.schema;
|
|
14
|
-
this.value = this.schema.parse(value) as UsernameType;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
read(): UsernameType {
|
|
18
|
-
return this.value;
|
|
19
|
-
}
|
|
20
|
-
}
|