@bgord/bun 1.4.13 → 1.4.14
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/{env-validator.service.d.ts → environment-validator.service.d.ts} +5 -4
- package/dist/environment-validator.service.d.ts.map +1 -0
- package/dist/{env-validator.service.js → environment-validator.service.js} +1 -1
- 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/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/{env-validator.service.ts → environment-validator.service.ts} +3 -1
- package/src/index.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.map +0 -1
- package/dist/env-validator.service.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.14",
|
|
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
|
}
|
|
@@ -5,6 +5,8 @@ type NodeEnvironmentEnumType = z.infer<typeof NodeEnvironment>;
|
|
|
5
5
|
type AnyZodSchema = z.ZodSchema<any, any>;
|
|
6
6
|
type EnvironmentValidatorConfig = { type: unknown; schema: AnyZodSchema };
|
|
7
7
|
|
|
8
|
+
export type EnvironmentResultType<SchemaType> = SchemaType & { type: NodeEnvironmentEnumType };
|
|
9
|
+
|
|
8
10
|
export const EnvironmentValidatorError = { Invalid: "environment.validator.invalid" } as const;
|
|
9
11
|
|
|
10
12
|
export class EnvironmentValidator<SchemaType> {
|
|
@@ -24,7 +26,7 @@ export class EnvironmentValidator<SchemaType> {
|
|
|
24
26
|
throw new Error(EnvironmentValidatorError.Invalid);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
load(): SchemaType
|
|
29
|
+
load(): EnvironmentResultType<SchemaType> {
|
|
28
30
|
return { ...this.schema.parse(process.env), type: this.type };
|
|
29
31
|
}
|
|
30
32
|
}
|
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";
|
|
@@ -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 +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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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