@bgord/bun 1.4.13 → 1.4.15
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/basic-auth.service.d.ts +7 -2
- package/dist/basic-auth.service.d.ts.map +1 -1
- package/dist/basic-auth.service.js +4 -4
- package/dist/basic-auth.service.js.map +1 -1
- package/dist/environment-validator.service.d.ts +14 -0
- package/dist/environment-validator.service.d.ts.map +1 -0
- package/dist/environment-validator.service.js +13 -0
- package/dist/environment-validator.service.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/node-env.vo.d.ts +3 -0
- package/dist/node-env.vo.d.ts.map +1 -1
- package/dist/node-env.vo.js +2 -1
- package/dist/node-env.vo.js.map +1 -1
- package/dist/shield-basic-auth.adapter.d.ts +14 -0
- package/dist/shield-basic-auth.adapter.d.ts.map +1 -0
- package/dist/shield-basic-auth.adapter.js +10 -0
- package/dist/shield-basic-auth.adapter.js.map +1 -0
- package/dist/shield-timeout.adapter.d.ts +14 -0
- package/dist/shield-timeout.adapter.d.ts.map +1 -0
- package/dist/shield-timeout.adapter.js +12 -0
- package/dist/shield-timeout.adapter.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/readme.md +3 -1
- package/src/basic-auth.service.ts +6 -7
- package/src/environment-validator.service.ts +16 -0
- package/src/index.ts +3 -1
- package/src/node-env.vo.ts +3 -1
- package/src/shield-basic-auth.adapter.ts +17 -0
- package/src/shield-timeout.adapter.ts +19 -0
- package/dist/env-validator.service.d.ts +0 -21
- package/dist/env-validator.service.d.ts.map +0 -1
- package/dist/env-validator.service.js +0 -19
- package/dist/env-validator.service.js.map +0 -1
- package/src/env-validator.service.ts +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@types/nodemailer": "7.0.4",
|
|
29
29
|
"@types/yazl": "3.3.0",
|
|
30
30
|
"cspell": "9.4.0",
|
|
31
|
-
"knip": "5.73.
|
|
32
|
-
"lefthook": "2.0.
|
|
31
|
+
"knip": "5.73.4",
|
|
32
|
+
"lefthook": "2.0.11",
|
|
33
33
|
"only-allow": "1.2.2",
|
|
34
34
|
"sharp": "0.34.5",
|
|
35
35
|
"shellcheck": "4.1.0",
|
package/readme.md
CHANGED
|
@@ -71,7 +71,7 @@ src/
|
|
|
71
71
|
├── encryption-key.vo.ts
|
|
72
72
|
├── encryption-noop.adapter.ts
|
|
73
73
|
├── encryption.port.ts
|
|
74
|
-
├──
|
|
74
|
+
├── environment-validator.service.ts
|
|
75
75
|
├── etag-extractor.middleware.ts
|
|
76
76
|
├── event-bus-like.types.ts
|
|
77
77
|
├── event-envelope.ts
|
|
@@ -239,11 +239,13 @@ src/
|
|
|
239
239
|
├── setup.service.ts
|
|
240
240
|
├── shield-api-key.adapter.ts
|
|
241
241
|
├── shield-auth.middleware.ts
|
|
242
|
+
├── shield-basic-auth.adapter.ts
|
|
242
243
|
├── shield-captcha-hcaptcha-local.adapter.ts
|
|
243
244
|
├── shield-captcha-hcaptcha.adapter.ts
|
|
244
245
|
├── shield-captcha-recaptcha.adapter.ts
|
|
245
246
|
├── shield-noop.adapter.ts
|
|
246
247
|
├── shield-rate-limit.adapter.ts
|
|
248
|
+
├── shield-timeout.adapter.ts
|
|
247
249
|
├── shield.port.ts
|
|
248
250
|
├── simulated-error.middleware.ts
|
|
249
251
|
├── slower.middleware.ts
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type { BasicAuthPasswordType } from "./basic-auth-password.vo";
|
|
2
2
|
import type { BasicAuthUsernameType } from "./basic-auth-username.vo";
|
|
3
3
|
|
|
4
|
+
type BasicAuthConfigType = { username: BasicAuthUsernameType; password: BasicAuthPasswordType };
|
|
5
|
+
|
|
4
6
|
export class BasicAuth {
|
|
5
|
-
static toHeaderValue(
|
|
6
|
-
|
|
7
|
-
password: BasicAuthPasswordType,
|
|
8
|
-
): { authorization: string } {
|
|
9
|
-
return { authorization: `Basic ${btoa(`${username}:${password}`)}` };
|
|
7
|
+
static toHeaderValue(config: BasicAuthConfigType): { authorization: string } {
|
|
8
|
+
return { authorization: `Basic ${btoa(`${config.username}:${config.password}`)}` };
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
static toHeader(
|
|
13
|
-
return new Headers(BasicAuth.toHeaderValue(
|
|
11
|
+
static toHeader(config: BasicAuthConfigType): Headers {
|
|
12
|
+
return new Headers(BasicAuth.toHeaderValue(config));
|
|
14
13
|
}
|
|
15
14
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { z } from "zod/v4";
|
|
2
|
+
import { NodeEnvironment, type NodeEnvironmentEnum } from "../src/node-env.vo";
|
|
3
|
+
|
|
4
|
+
export class EnvironmentValidator<Schema extends z.ZodObject<any>> {
|
|
5
|
+
private readonly type: NodeEnvironmentEnum;
|
|
6
|
+
private readonly schema: Schema;
|
|
7
|
+
|
|
8
|
+
constructor(config: { type: string | undefined; schema: Schema }) {
|
|
9
|
+
this.schema = config.schema;
|
|
10
|
+
this.type = NodeEnvironment.parse(config.type);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
load(env: NodeJS.ProcessEnv): z.infer<Schema> & { type: NodeEnvironmentEnum } {
|
|
14
|
+
return { ...this.schema.parse(env), type: this.type };
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ export * from "./encryption.port";
|
|
|
43
43
|
export * from "./encryption-bun.adapter";
|
|
44
44
|
export * from "./encryption-key.vo";
|
|
45
45
|
export * from "./encryption-noop.adapter";
|
|
46
|
-
export * from "./
|
|
46
|
+
export * from "./environment-validator.service";
|
|
47
47
|
export * from "./etag-extractor.middleware";
|
|
48
48
|
export * from "./event.types";
|
|
49
49
|
export * from "./event-bus-like.types";
|
|
@@ -161,11 +161,13 @@ export * from "./setup.service";
|
|
|
161
161
|
export * from "./shield.port";
|
|
162
162
|
export * from "./shield-api-key.adapter";
|
|
163
163
|
export * from "./shield-auth.middleware";
|
|
164
|
+
export * from "./shield-basic-auth.adapter";
|
|
164
165
|
export * from "./shield-captcha-hcaptcha.adapter";
|
|
165
166
|
export * from "./shield-captcha-hcaptcha-local.adapter";
|
|
166
167
|
export * from "./shield-captcha-recaptcha.adapter";
|
|
167
168
|
export * from "./shield-noop.adapter";
|
|
168
169
|
export * from "./shield-rate-limit.adapter";
|
|
170
|
+
export * from "./shield-timeout.adapter";
|
|
169
171
|
export * from "./simulated-error.middleware";
|
|
170
172
|
export * from "./slower.middleware";
|
|
171
173
|
export * from "./static-files.service";
|
package/src/node-env.vo.ts
CHANGED
|
@@ -7,4 +7,6 @@ export enum NodeEnvironmentEnum {
|
|
|
7
7
|
production = "production",
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const NodeEnvironmentError = { Invalid: "node.environment.invalid" } as const;
|
|
11
|
+
|
|
12
|
+
export const NodeEnvironment = z.enum(NodeEnvironmentEnum, { error: NodeEnvironmentError.Invalid });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { basicAuth } from "hono/basic-auth";
|
|
2
|
+
import { createMiddleware } from "hono/factory";
|
|
3
|
+
import type { BasicAuthPasswordType } from "./basic-auth-password.vo";
|
|
4
|
+
import type { BasicAuthUsernameType } from "./basic-auth-username.vo";
|
|
5
|
+
import type { ShieldPort } from "./shield.port";
|
|
6
|
+
|
|
7
|
+
type ShieldBasicAuthConfigType = { username: BasicAuthUsernameType; password: BasicAuthPasswordType };
|
|
8
|
+
|
|
9
|
+
export class ShieldBasicAuthAdapter implements ShieldPort {
|
|
10
|
+
private readonly basicAuth;
|
|
11
|
+
|
|
12
|
+
constructor(config: ShieldBasicAuthConfigType) {
|
|
13
|
+
this.basicAuth = basicAuth(config);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
verify = createMiddleware(async (c, next) => this.basicAuth(c, next));
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as tools from "@bgord/tools";
|
|
2
|
+
import { createMiddleware } from "hono/factory";
|
|
3
|
+
import { HTTPException } from "hono/http-exception";
|
|
4
|
+
import { timeout } from "hono/timeout";
|
|
5
|
+
import type { ShieldPort } from "./shield.port";
|
|
6
|
+
|
|
7
|
+
export const RequestTimeoutError = new HTTPException(408, { message: "request_timeout_error" });
|
|
8
|
+
|
|
9
|
+
type ShieldTimeoutConfigType = { duration: tools.Duration };
|
|
10
|
+
|
|
11
|
+
export class ShieldTimeoutAdapter implements ShieldPort {
|
|
12
|
+
private readonly timeout;
|
|
13
|
+
|
|
14
|
+
constructor(config: ShieldTimeoutConfigType) {
|
|
15
|
+
this.timeout = timeout(config.duration.ms, RequestTimeoutError);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
verify = createMiddleware(async (c, next) => this.timeout(c, next));
|
|
19
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod/v4";
|
|
2
|
-
import { NodeEnvironment } from "../src/node-env.vo";
|
|
3
|
-
type NodeEnvironmentEnumType = z.infer<typeof NodeEnvironment>;
|
|
4
|
-
type AnyZodSchema = z.ZodSchema<any, any>;
|
|
5
|
-
type EnvironmentValidatorConfig = {
|
|
6
|
-
type: unknown;
|
|
7
|
-
schema: AnyZodSchema;
|
|
8
|
-
};
|
|
9
|
-
export declare const EnvironmentValidatorError: {
|
|
10
|
-
readonly Invalid: "environment.validator.invalid";
|
|
11
|
-
};
|
|
12
|
-
export declare class EnvironmentValidator<SchemaType> {
|
|
13
|
-
type: NodeEnvironmentEnumType;
|
|
14
|
-
schema: z.Schema<SchemaType>;
|
|
15
|
-
constructor(config: EnvironmentValidatorConfig);
|
|
16
|
-
load(): SchemaType & {
|
|
17
|
-
type: NodeEnvironmentEnumType;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=env-validator.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env-validator.service.d.ts","sourceRoot":"","sources":["../src/env-validator.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC/D,KAAK,YAAY,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1C,KAAK,0BAA0B,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,CAAC;AAE1E,eAAO,MAAM,yBAAyB;;CAAwD,CAAC;AAE/F,qBAAa,oBAAoB,CAAC,UAAU;IAC1C,IAAI,EAAE,uBAAuB,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAEjB,MAAM,EAAE,0BAA0B;IAa9C,IAAI,IAAI,UAAU,GAAG;QAAE,IAAI,EAAE,uBAAuB,CAAA;KAAE;CAGvD"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NodeEnvironment } from "../src/node-env.vo";
|
|
2
|
-
export const EnvironmentValidatorError = { Invalid: "environment.validator.invalid" };
|
|
3
|
-
export class EnvironmentValidator {
|
|
4
|
-
type;
|
|
5
|
-
schema;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.schema = config.schema;
|
|
8
|
-
const result = NodeEnvironment.safeParse(config.type);
|
|
9
|
-
if (result.success) {
|
|
10
|
-
this.type = result.data;
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
throw new Error(EnvironmentValidatorError.Invalid);
|
|
14
|
-
}
|
|
15
|
-
load() {
|
|
16
|
-
return { ...this.schema.parse(process.env), type: this.type };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=env-validator.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env-validator.service.js","sourceRoot":"","sources":["../src/env-validator.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMrD,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,OAAO,EAAE,+BAA+B,EAAW,CAAC;AAE/F,MAAM,OAAO,oBAAoB;IAC/B,IAAI,CAA0B;IAC9B,MAAM,CAAuB;IAE7B,YAAY,MAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE5B,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEtD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACxB,OAAO;QACT,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,IAAI;QACF,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod/v4";
|
|
2
|
-
import { NodeEnvironment } from "../src/node-env.vo";
|
|
3
|
-
|
|
4
|
-
type NodeEnvironmentEnumType = z.infer<typeof NodeEnvironment>;
|
|
5
|
-
type AnyZodSchema = z.ZodSchema<any, any>;
|
|
6
|
-
type EnvironmentValidatorConfig = { type: unknown; schema: AnyZodSchema };
|
|
7
|
-
|
|
8
|
-
export const EnvironmentValidatorError = { Invalid: "environment.validator.invalid" } as const;
|
|
9
|
-
|
|
10
|
-
export class EnvironmentValidator<SchemaType> {
|
|
11
|
-
type: NodeEnvironmentEnumType;
|
|
12
|
-
schema: z.Schema<SchemaType>;
|
|
13
|
-
|
|
14
|
-
constructor(config: EnvironmentValidatorConfig) {
|
|
15
|
-
this.schema = config.schema;
|
|
16
|
-
|
|
17
|
-
const result = NodeEnvironment.safeParse(config.type);
|
|
18
|
-
|
|
19
|
-
if (result.success) {
|
|
20
|
-
this.type = result.data;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
throw new Error(EnvironmentValidatorError.Invalid);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
load(): SchemaType & { type: NodeEnvironmentEnumType } {
|
|
28
|
-
return { ...this.schema.parse(process.env), type: this.type };
|
|
29
|
-
}
|
|
30
|
-
}
|