@bgord/bun 1.21.7 → 1.21.9

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.
Files changed (114) hide show
  1. package/dist/alert-channel-composite.adapter.js +1 -1
  2. package/dist/alert-channel-composite.adapter.js.map +1 -1
  3. package/dist/cache-repository-redis.adapter.js.map +1 -1
  4. package/dist/command-envelope.d.ts +4 -4
  5. package/dist/correlation-id.vo.d.ts +1 -1
  6. package/dist/correlation-id.vo.d.ts.map +1 -1
  7. package/dist/crypto-aes-gcm.service.d.ts +2 -2
  8. package/dist/crypto-aes-gcm.service.d.ts.map +1 -1
  9. package/dist/crypto-aes-gcm.service.js +2 -2
  10. package/dist/crypto-aes-gcm.service.js.map +1 -1
  11. package/dist/crypto-key-provider-file.adapter.d.ts.map +1 -1
  12. package/dist/crypto-key-provider-file.adapter.js +4 -1
  13. package/dist/crypto-key-provider-file.adapter.js.map +1 -1
  14. package/dist/crypto-key-provider-memory.adapter.js.map +1 -1
  15. package/dist/encryption-iv.vo.d.ts +1 -1
  16. package/dist/encryption-iv.vo.d.ts.map +1 -1
  17. package/dist/encryption-key.vo.d.ts +1 -1
  18. package/dist/encryption-key.vo.d.ts.map +1 -1
  19. package/dist/event-envelope.d.ts +2 -2
  20. package/dist/healthcheck-hono.handler.d.ts +1 -67
  21. package/dist/healthcheck-hono.handler.d.ts.map +1 -1
  22. package/dist/healthcheck-hono.handler.js +2 -2
  23. package/dist/healthcheck-hono.handler.js.map +1 -1
  24. package/dist/id-provider-crypto.adapter.d.ts +1 -1
  25. package/dist/id-provider-crypto.adapter.d.ts.map +1 -1
  26. package/dist/id-provider-crypto.adapter.js +3 -1
  27. package/dist/id-provider-crypto.adapter.js.map +1 -1
  28. package/dist/job-envelope.d.ts +2 -2
  29. package/dist/job-registry.adapter.js.map +1 -1
  30. package/dist/languages.vo.js +1 -1
  31. package/dist/languages.vo.js.map +1 -1
  32. package/dist/liveness-hono.handler.d.ts +1 -3
  33. package/dist/liveness-hono.handler.d.ts.map +1 -1
  34. package/dist/liveness-hono.handler.js +2 -2
  35. package/dist/liveness-hono.handler.js.map +1 -1
  36. package/dist/message-bus-with-logger.adapter.d.ts.map +1 -1
  37. package/dist/message-bus-with-logger.adapter.js.map +1 -1
  38. package/dist/modules/history/events/HISTORY_CLEARED_EVENT.d.ts +3 -3
  39. package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts +8 -6
  40. package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts.map +1 -1
  41. package/dist/modules/history/value-objects/history-id.d.ts +3 -1
  42. package/dist/modules/history/value-objects/history-id.d.ts.map +1 -1
  43. package/dist/modules/history/value-objects/history-id.js +3 -1
  44. package/dist/modules/history/value-objects/history-id.js.map +1 -1
  45. package/dist/modules/history/value-objects/history-operation.d.ts +2 -1
  46. package/dist/modules/history/value-objects/history-operation.d.ts.map +1 -1
  47. package/dist/modules/history/value-objects/history-operation.js +3 -1
  48. package/dist/modules/history/value-objects/history-operation.js.map +1 -1
  49. package/dist/modules/history/value-objects/history-payload.d.ts +10 -4
  50. package/dist/modules/history/value-objects/history-payload.d.ts.map +1 -1
  51. package/dist/modules/history/value-objects/history-payload.js +6 -2
  52. package/dist/modules/history/value-objects/history-payload.js.map +1 -1
  53. package/dist/modules/history/value-objects/history-subject.d.ts +1 -1
  54. package/dist/modules/history/value-objects/history-subject.d.ts.map +1 -1
  55. package/dist/modules/history/value-objects/history-subject.js +3 -1
  56. package/dist/modules/history/value-objects/history-subject.js.map +1 -1
  57. package/dist/modules/history/value-objects/history.d.ts +14 -10
  58. package/dist/modules/history/value-objects/history.d.ts.map +1 -1
  59. package/dist/modules/preferences/commands/SET_USER_LANGUAGE_COMMAND.d.ts +3 -3
  60. package/dist/modules/preferences/events/USER_LANGUAGE_SET_EVENT.d.ts +3 -3
  61. package/dist/modules/system/events/HOUR_HAS_PASSED_EVENT.d.ts +2 -2
  62. package/dist/modules/system/events/MINUTE_HAS_PASSED_EVENT.d.ts +2 -2
  63. package/dist/modules/system/events/SECURITY_VIOLATION_DETECTED_EVENT.d.ts +3 -3
  64. package/dist/modules/system/jobs/SEND_EMAIL_JOB.d.ts +2 -2
  65. package/dist/readiness-hono.handler.d.ts +1 -4
  66. package/dist/readiness-hono.handler.d.ts.map +1 -1
  67. package/dist/readiness-hono.handler.js +2 -2
  68. package/dist/readiness-hono.handler.js.map +1 -1
  69. package/dist/request-context-hono.adapter.d.ts.map +1 -1
  70. package/dist/request-context-hono.adapter.js +10 -0
  71. package/dist/request-context-hono.adapter.js.map +1 -1
  72. package/dist/request-context.port.d.ts +6 -0
  73. package/dist/request-context.port.d.ts.map +1 -1
  74. package/dist/shield-maintenance-hono.strategy.js +1 -1
  75. package/dist/shield-maintenance-hono.strategy.js.map +1 -1
  76. package/dist/shield-security-hono.strategy.d.ts.map +1 -1
  77. package/dist/shield-security-hono.strategy.js +4 -4
  78. package/dist/shield-security-hono.strategy.js.map +1 -1
  79. package/dist/smtp-port.vo.d.ts +2 -2
  80. package/dist/smtp-port.vo.d.ts.map +1 -1
  81. package/dist/smtp-port.vo.js +2 -1
  82. package/dist/smtp-port.vo.js.map +1 -1
  83. package/dist/translations-hono.handler.js +1 -1
  84. package/dist/translations-hono.handler.js.map +1 -1
  85. package/dist/uuid.vo.d.ts +1 -1
  86. package/dist/uuid.vo.d.ts.map +1 -1
  87. package/dist/uuid.vo.js +1 -1
  88. package/dist/uuid.vo.js.map +1 -1
  89. package/package.json +10 -10
  90. package/src/alert-channel-composite.adapter.ts +1 -1
  91. package/src/cache-repository-redis.adapter.ts +1 -1
  92. package/src/crypto-aes-gcm.service.ts +8 -12
  93. package/src/crypto-key-provider-file.adapter.ts +4 -7
  94. package/src/crypto-key-provider-memory.adapter.ts +1 -1
  95. package/src/encryption-iv.vo.ts +1 -1
  96. package/src/encryption-key.vo.ts +1 -1
  97. package/src/healthcheck-hono.handler.ts +2 -2
  98. package/src/id-provider-crypto.adapter.ts +3 -2
  99. package/src/job-registry.adapter.ts +1 -1
  100. package/src/languages.vo.ts +1 -1
  101. package/src/liveness-hono.handler.ts +2 -2
  102. package/src/message-bus-with-logger.adapter.ts +2 -2
  103. package/src/modules/history/value-objects/history-id.ts +5 -1
  104. package/src/modules/history/value-objects/history-operation.ts +4 -0
  105. package/src/modules/history/value-objects/history-payload.ts +11 -1
  106. package/src/modules/history/value-objects/history-subject.ts +2 -0
  107. package/src/readiness-hono.handler.ts +2 -2
  108. package/src/request-context-hono.adapter.ts +9 -0
  109. package/src/request-context.port.ts +5 -0
  110. package/src/shield-maintenance-hono.strategy.ts +1 -1
  111. package/src/shield-security-hono.strategy.ts +4 -5
  112. package/src/smtp-port.vo.ts +2 -2
  113. package/src/translations-hono.handler.ts +1 -1
  114. package/src/uuid.vo.ts +1 -1
@@ -1,7 +1,7 @@
1
1
  export class EncryptionIV {
2
2
  static readonly LENGTH = 12;
3
3
 
4
- static generate(): Uint8Array {
4
+ static generate(): Uint8Array<ArrayBuffer> {
5
5
  const iv = new Uint8Array(EncryptionIV.LENGTH);
6
6
  crypto.getRandomValues(iv);
7
7
 
@@ -24,7 +24,7 @@ export class EncryptionKey {
24
24
  return this.key === another.key;
25
25
  }
26
26
 
27
- toBytes(): Uint8Array {
27
+ toBytes(): Uint8Array<ArrayBuffer> {
28
28
  return Uint8Array.fromHex(this.key);
29
29
  }
30
30
 
@@ -16,10 +16,10 @@ export class HealthcheckHonoHandler implements HandlerHonoPort {
16
16
  }
17
17
 
18
18
  handle() {
19
- return factory.createHandlers(async (c) => {
19
+ return factory.createHandlers(async () => {
20
20
  const healthcheck = await this.handler.check();
21
21
 
22
- return c.json(healthcheck, healthcheck.code);
22
+ return Response.json(healthcheck, { status: healthcheck.code });
23
23
  });
24
24
  }
25
25
  }
@@ -1,8 +1,9 @@
1
+ import * as v from "valibot";
1
2
  import type { IdProviderPort } from "./id-provider.port";
2
- import type { UUIDType } from "./uuid.vo";
3
+ import { UUID, type UUIDType } from "./uuid.vo";
3
4
 
4
5
  export class IdProviderCryptoAdapter implements IdProviderPort {
5
6
  generate(): UUIDType {
6
- return crypto.randomUUID();
7
+ return v.parse(UUID, crypto.randomUUID());
7
8
  }
8
9
  }
@@ -53,6 +53,6 @@ export class JobRegistryAdapter<Job extends GenericJob> implements JobRegistryPo
53
53
  const entry = this.map.get(name);
54
54
  if (!entry) throw new Error(JobRegistryAdapterError.UnknownJob);
55
55
 
56
- return entry.handler as JobHandler<Job>;
56
+ return entry.handler;
57
57
  }
58
58
  }
@@ -22,6 +22,6 @@ export class Languages<T extends tools.LanguageType> {
22
22
  }
23
23
 
24
24
  isSupported(value: unknown): value is T {
25
- return this.values.includes(value as T);
25
+ return this.values.some((language) => language === value);
26
26
  }
27
27
  }
@@ -8,10 +8,10 @@ export class LivenessHonoHandler implements HandlerHonoPort {
8
8
  private readonly handler = new LivenessHandler();
9
9
 
10
10
  handle() {
11
- return factory.createHandlers(async (c) => {
11
+ return factory.createHandlers(async () => {
12
12
  const { headers, ...body } = this.handler.execute();
13
13
 
14
- return c.json(body, 200, headers);
14
+ return Response.json(body, { status: 200, headers });
15
15
  });
16
16
  }
17
17
  }
@@ -1,5 +1,5 @@
1
1
  import { CorrelationStorage } from "./correlation-storage.service";
2
- import type { LogCoreType, LoggerPort } from "./logger.port";
2
+ import type { LoggerPort } from "./logger.port";
3
3
  import type { Message, ToMessageMap } from "./message.types";
4
4
  import type { MessageBusPort } from "./message-bus.port";
5
5
 
@@ -13,7 +13,7 @@ export class MessageBusWithLoggerAdapter<Messages extends Message> implements Me
13
13
  async emit<M extends Messages>(message: M): Promise<void> {
14
14
  this.deps.Logger.info({
15
15
  message: `${message.name} emitted`,
16
- metadata: message as LogCoreType["metadata"],
16
+ metadata: message,
17
17
  correlationId: CorrelationStorage.get(),
18
18
  ...this.base,
19
19
  });
@@ -1,3 +1,7 @@
1
+ import * as v from "valibot";
1
2
  import { UUID } from "../../../uuid.vo";
2
3
 
3
- export const HistoryId = UUID;
4
+ // Stryker disable next-line StringLiteral
5
+ export const HistoryId = v.pipe(UUID, v.brand("HistoryId"));
6
+
7
+ export type HistoryIdType = v.InferOutput<typeof HistoryId>;
@@ -10,4 +10,8 @@ export const HistoryOperation = v.pipe(
10
10
  v.string(HistoryOperationError.Type),
11
11
  v.minLength(1, HistoryOperationError.Empty),
12
12
  v.maxLength(128, HistoryOperationError.TooLong),
13
+ // Stryker disable next-line StringLiteral
14
+ v.brand("HistoryOperation"),
13
15
  );
16
+
17
+ export type HistoryOperationType = v.InferOutput<typeof HistoryOperation>;
@@ -1,6 +1,12 @@
1
1
  import * as v from "valibot";
2
2
 
3
- export const HistoryPayload = v.record(v.string(), v.unknown());
3
+ export const HistoryPayload = v.pipe(
4
+ v.record(v.string(), v.unknown()),
5
+ // Stryker disable next-line StringLiteral
6
+ v.brand("HistoryPayload"),
7
+ );
8
+
9
+ export type HistoryPayloadType = v.InferOutput<typeof HistoryPayload>;
4
10
 
5
11
  export const HistoryPayloadParsedError = {
6
12
  NotSerializable: "history.payload.parsed.not.serializable",
@@ -18,4 +24,8 @@ export const HistoryPayloadParsed = v.pipe(
18
24
  }
19
25
  }, HistoryPayloadParsedError.NotSerializable),
20
26
  v.transform((value) => JSON.stringify(value)),
27
+ // Stryker disable next-line StringLiteral
28
+ v.brand("HistoryPayloadParsed"),
21
29
  );
30
+
31
+ export type HistoryPayloadParsedType = v.InferOutput<typeof HistoryPayloadParsed>;
@@ -10,6 +10,8 @@ export const HistorySubject = v.pipe(
10
10
  v.string(HistorySubjectError.Type),
11
11
  v.minLength(1, HistorySubjectError.Empty),
12
12
  v.maxLength(128, HistorySubjectError.TooLong),
13
+ // Stryker disable next-line StringLiteral
14
+ v.brand("HistorySubject"),
13
15
  );
14
16
 
15
17
  export type HistorySubjectType = v.InferOutput<typeof HistorySubject>;
@@ -12,10 +12,10 @@ export class ReadinessHonoHandler implements HandlerHonoPort {
12
12
  }
13
13
 
14
14
  handle() {
15
- return factory.createHandlers(async (c) => {
15
+ return factory.createHandlers(async () => {
16
16
  const result = await this.handler.check();
17
17
 
18
- return c.json(result.details, result.code, result.headers);
18
+ return Response.json(result.details, { status: result.code, headers: result.headers });
19
19
  });
20
20
  }
21
21
  }
@@ -3,7 +3,9 @@ import * as tools from "@bgord/tools";
3
3
  import type { Context } from "hono";
4
4
  import { getConnInfo } from "hono/bun";
5
5
  import { getCookie } from "hono/cookie";
6
+ import { HTTPException } from "hono/http-exception";
6
7
  import type { RequestContext } from "./request-context.port";
8
+ import { ShieldAuthStrategyError } from "./shield-auth.strategy";
7
9
 
8
10
  export class RequestContextHonoAdapter implements RequestContext {
9
11
  readonly request: RequestContext["request"];
@@ -49,6 +51,13 @@ export class RequestContextHonoAdapter implements RequestContext {
49
51
 
50
52
  this.identity = {
51
53
  userId: () => context.get("user")?.id,
54
+ authenticatedUserId: () => {
55
+ const user = context.get("user");
56
+
57
+ if (user === undefined) throw new Error(ShieldAuthStrategyError.NotAttached);
58
+ if (user === null) throw new HTTPException(401, { message: ShieldAuthStrategyError.Rejected });
59
+ return user.id;
60
+ },
52
61
  ip: () =>
53
62
  context.req.header("x-real-ip") ||
54
63
  context.req.header("x-forwarded-for")?.split(",")[0]?.trim() ||
@@ -21,6 +21,7 @@ export interface RequestContext {
21
21
 
22
22
  readonly identity: {
23
23
  userId(): UUIDType | undefined;
24
+ authenticatedUserId(): UUIDType;
24
25
  ip(): string | undefined;
25
26
  remoteIp(): string | undefined;
26
27
  ua(): string | undefined;
@@ -93,6 +94,10 @@ export interface HasIdentityUserId {
93
94
  readonly identity: { userId(): UUIDType | undefined };
94
95
  }
95
96
 
97
+ export interface HasIdentityAuthenticatedUserId {
98
+ readonly identity: { authenticatedUserId(): UUIDType };
99
+ }
100
+
96
101
  export interface HasIdentityIp {
97
102
  readonly identity: { ip(): string | undefined };
98
103
  }
@@ -20,7 +20,7 @@ export class ShieldMaintenanceHonoStrategy implements MiddlewareHonoPort {
20
20
 
21
21
  if (!maintenance.enabled) return next();
22
22
 
23
- return c.json(maintenance.body, maintenance.code, maintenance.headers);
23
+ return Response.json(maintenance.body, { status: maintenance.code, headers: maintenance.headers });
24
24
  };
25
25
  }
26
26
  }
@@ -1,5 +1,4 @@
1
1
  import type { MiddlewareHandler } from "hono";
2
- import type { ContentfulStatusCode } from "hono/utils/http-status";
3
2
  import type { MiddlewareHonoPort } from "./middleware-hono.port";
4
3
  import { RequestContextHonoAdapter } from "./request-context-hono.adapter";
5
4
  import type { SecurityPolicy } from "./security-policy.vo";
@@ -34,10 +33,10 @@ export class ShieldSecurityHonoStrategy implements MiddlewareHonoPort {
34
33
  return next();
35
34
 
36
35
  case "deny":
37
- return c.text(action.reason, action.response.status as ContentfulStatusCode);
36
+ return new Response(action.reason, { status: action.response.status });
38
37
 
39
38
  case "mirage":
40
- return c.json({}, action.response.status as ContentfulStatusCode);
39
+ return Response.json({}, { status: action.response.status });
41
40
 
42
41
  case "delay": {
43
42
  await this.deps.Sleeper.wait(action.duration);
@@ -47,10 +46,10 @@ export class ShieldSecurityHonoStrategy implements MiddlewareHonoPort {
47
46
  return next();
48
47
 
49
48
  case "deny":
50
- return c.text(action.after.reason, action.after.response.status as ContentfulStatusCode);
49
+ return new Response(action.after.reason, { status: action.after.response.status });
51
50
 
52
51
  case "mirage":
53
- return c.json({}, action.after.response.status as ContentfulStatusCode);
52
+ return Response.json({}, { status: action.after.response.status });
54
53
 
55
54
  default:
56
55
  throw new Error(ShieldSecurityHonoStrategyError.Unhandled);
@@ -1,5 +1,5 @@
1
- import type * as v from "valibot";
1
+ import * as v from "valibot";
2
2
  import { Port } from "./port.vo";
3
3
 
4
- export const SmtpPort = Port;
4
+ export const SmtpPort = v.pipe(Port, v.brand("SmtpPort"));
5
5
  export type SmtpPortType = v.InferOutput<typeof SmtpPort>;
@@ -22,7 +22,7 @@ export class TranslationsHonoHandler<T extends tools.LanguageType> implements Ha
22
22
  const language = c.get("language");
23
23
  const result = await this.handler.execute(language);
24
24
 
25
- return c.json(result);
25
+ return Response.json(result);
26
26
  });
27
27
  }
28
28
  }
package/src/uuid.vo.ts CHANGED
@@ -2,6 +2,6 @@ import * as v from "valibot";
2
2
 
3
3
  export const UUIDError = { Type: "uuid.type" } as const;
4
4
 
5
- export const UUID = v.pipe(v.string(UUIDError.Type), v.uuid(UUIDError.Type));
5
+ export const UUID = v.pipe(v.string(UUIDError.Type), v.uuid(UUIDError.Type), v.brand("UUID"));
6
6
 
7
7
  export type UUIDType = v.InferOutput<typeof UUID>;