@bgord/bun 0.18.21 → 0.18.24
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/history/event-handlers/index.d.ts +3 -0
- package/dist/modules/history/event-handlers/index.d.ts.map +1 -0
- package/dist/modules/history/event-handlers/index.js +3 -0
- package/dist/modules/history/event-handlers/index.js.map +1 -0
- package/dist/modules/history/event-handlers/onHistoryClearedEvent.d.ts +4 -0
- package/dist/modules/history/event-handlers/onHistoryClearedEvent.d.ts.map +1 -0
- package/dist/modules/history/event-handlers/onHistoryClearedEvent.js +4 -0
- package/dist/modules/history/event-handlers/onHistoryClearedEvent.js.map +1 -0
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.d.ts +4 -0
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.d.ts.map +1 -0
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.js +6 -0
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.js.map +1 -0
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.d.ts +16 -0
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.d.ts.map +1 -0
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.js +16 -0
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.js.map +1 -0
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts +19 -0
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts.map +1 -0
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.js +21 -0
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.js.map +1 -0
- package/dist/modules/history/events/index.d.ts +3 -0
- package/dist/modules/history/events/index.d.ts.map +1 -0
- package/dist/modules/history/events/index.js +3 -0
- package/dist/modules/history/events/index.js.map +1 -0
- package/dist/modules/history/index.d.ts +6 -0
- package/dist/modules/history/index.d.ts.map +1 -0
- package/dist/modules/history/index.js +7 -0
- package/dist/modules/history/index.js.map +1 -0
- package/dist/modules/history/repositories/history-repository.d.ts +7 -0
- package/dist/modules/history/repositories/history-repository.d.ts.map +1 -0
- package/dist/modules/history/repositories/history-repository.js +2 -0
- package/dist/modules/history/repositories/history-repository.js.map +1 -0
- package/dist/modules/history/repositories/index.d.ts +2 -0
- package/dist/modules/history/repositories/index.d.ts.map +1 -0
- package/dist/modules/history/repositories/index.js +2 -0
- package/dist/modules/history/repositories/index.js.map +1 -0
- package/dist/modules/history/services/history-writer.d.ts +6 -0
- package/dist/modules/history/services/history-writer.d.ts.map +1 -0
- package/dist/modules/history/services/history-writer.js +2 -0
- package/dist/modules/history/services/history-writer.js.map +1 -0
- package/dist/modules/history/services/index.d.ts +2 -0
- package/dist/modules/history/services/index.d.ts.map +1 -0
- package/dist/modules/history/services/index.js +2 -0
- package/dist/modules/history/services/index.js.map +1 -0
- package/dist/modules/history/value-objects/history-id.d.ts +2 -0
- package/dist/modules/history/value-objects/history-id.d.ts.map +1 -0
- package/dist/modules/history/value-objects/history-id.js +3 -0
- package/dist/modules/history/value-objects/history-id.js.map +1 -0
- package/dist/modules/history/value-objects/history-operation.d.ts +3 -0
- package/dist/modules/history/value-objects/history-operation.d.ts.map +1 -0
- package/dist/modules/history/value-objects/history-operation.js +3 -0
- package/dist/modules/history/value-objects/history-operation.js.map +1 -0
- package/dist/modules/history/value-objects/history-payload.d.ts +4 -0
- package/dist/modules/history/value-objects/history-payload.d.ts.map +1 -0
- package/dist/modules/history/value-objects/history-payload.js +12 -0
- package/dist/modules/history/value-objects/history-payload.js.map +1 -0
- package/dist/modules/history/value-objects/history-subject.d.ts +4 -0
- package/dist/modules/history/value-objects/history-subject.d.ts.map +1 -0
- package/dist/modules/history/value-objects/history-subject.js +3 -0
- package/dist/modules/history/value-objects/history-subject.js.map +1 -0
- package/dist/modules/history/value-objects/history.d.ts +17 -0
- package/dist/modules/history/value-objects/history.d.ts.map +1 -0
- package/dist/modules/history/value-objects/history.js +18 -0
- package/dist/modules/history/value-objects/history.js.map +1 -0
- package/dist/modules/history/value-objects/index.d.ts +6 -0
- package/dist/modules/history/value-objects/index.d.ts.map +1 -0
- package/dist/modules/history/value-objects/index.js +6 -0
- package/dist/modules/history/value-objects/index.js.map +1 -0
- package/dist/smtp-mailer-with-mailer.adapter.d.ts +17 -0
- package/dist/smtp-mailer-with-mailer.adapter.d.ts.map +1 -0
- package/dist/smtp-mailer-with-mailer.adapter.js +30 -0
- package/dist/smtp-mailer-with-mailer.adapter.js.map +1 -0
- package/dist/smtp-mailer.adapter.d.ts.map +1 -1
- package/dist/smtp-mailer.adapter.js +1 -4
- package/dist/smtp-mailer.adapter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/readme.md +19 -0
- package/src/index.ts +2 -0
- package/src/modules/history/event-handlers/index.ts +2 -0
- package/src/modules/history/event-handlers/onHistoryClearedEvent.ts +7 -0
- package/src/modules/history/event-handlers/onHistoryPopulatedEvent.ts +9 -0
- package/src/modules/history/events/HISTORY_CLEARED_EVENT.ts +19 -0
- package/src/modules/history/events/HISTORY_POPULATED_EVENT.ts +23 -0
- package/src/modules/history/events/index.ts +2 -0
- package/src/modules/history/index.ts +6 -0
- package/src/modules/history/repositories/history-repository.ts +8 -0
- package/src/modules/history/repositories/index.ts +1 -0
- package/src/modules/history/services/history-writer.ts +6 -0
- package/src/modules/history/services/index.ts +1 -0
- package/src/modules/history/value-objects/history-id.ts +3 -0
- package/src/modules/history/value-objects/history-operation.ts +3 -0
- package/src/modules/history/value-objects/history-payload.ts +12 -0
- package/src/modules/history/value-objects/history-subject.ts +4 -0
- package/src/modules/history/value-objects/history.ts +23 -0
- package/src/modules/history/value-objects/index.ts +5 -0
- package/src/smtp-mailer-with-mailer.adapter.ts +43 -0
- package/src/smtp-mailer.adapter.ts +1 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/bun": "1.2.20",
|
|
27
27
|
"@types/lodash": "4.17.20",
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
|
-
"@types/nodemailer": "
|
|
29
|
+
"@types/nodemailer": "7.0.0",
|
|
30
30
|
"@types/yazl": "3.3.0",
|
|
31
31
|
"cspell": "9.2.0",
|
|
32
32
|
"knip": "5.62.0",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@axiomhq/winston": "1.3.1",
|
|
40
|
-
"@bgord/tools": "0.12.
|
|
40
|
+
"@bgord/tools": "0.12.11",
|
|
41
41
|
"@hono/ua-blocker": "0.1.7",
|
|
42
42
|
"better-auth": "1.3.6",
|
|
43
43
|
"check-disk-space": "3.4.0",
|
|
44
44
|
"croner": "9.1.0",
|
|
45
45
|
"hcaptcha": "0.2.0",
|
|
46
|
-
"hono": "4.9.
|
|
46
|
+
"hono": "4.9.2",
|
|
47
47
|
"lodash": "4.17.21",
|
|
48
48
|
"mime-types": "3.0.1",
|
|
49
49
|
"node-cache": "5.1.2",
|
package/readme.md
CHANGED
|
@@ -67,6 +67,24 @@ src/
|
|
|
67
67
|
├── logger.service.ts
|
|
68
68
|
├── mailer.port.ts
|
|
69
69
|
├── memory-consumption.service.ts
|
|
70
|
+
├── modules
|
|
71
|
+
│ └── history
|
|
72
|
+
│ ├── event-handlers
|
|
73
|
+
│ │ ├── onHistoryClearedEvent.ts
|
|
74
|
+
│ │ └── onHistoryPopulatedEvent.ts
|
|
75
|
+
│ ├── events
|
|
76
|
+
│ │ ├── HISTORY_CLEARED_EVENT.ts
|
|
77
|
+
│ │ ├── HISTORY_POPULATED_EVENT.ts
|
|
78
|
+
│ ├── repositories
|
|
79
|
+
│ │ ├── history-repository.ts
|
|
80
|
+
│ ├── services
|
|
81
|
+
│ │ ├── history-writer.ts
|
|
82
|
+
│ └── value-objects
|
|
83
|
+
│ ├── history-id.ts
|
|
84
|
+
│ ├── history-operation.ts
|
|
85
|
+
│ ├── history-payload.ts
|
|
86
|
+
│ ├── history-subject.ts
|
|
87
|
+
│ ├── history.ts
|
|
70
88
|
├── node-cache-rate-limit-store.adapter.ts
|
|
71
89
|
├── node-env.vo.ts
|
|
72
90
|
├── noop-mailer.adapter.ts
|
|
@@ -101,6 +119,7 @@ src/
|
|
|
101
119
|
├── simulated-error.middleware.ts
|
|
102
120
|
├── sitemap.service.ts
|
|
103
121
|
├── slower.middleware.ts
|
|
122
|
+
├── smtp-mailer-with-mailer.adapter.ts
|
|
104
123
|
├── smtp-mailer.adapter.ts
|
|
105
124
|
├── time-zone-offset.middleware.ts
|
|
106
125
|
├── to-event-map.types.ts
|
package/src/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export * from "./jobs.service";
|
|
|
40
40
|
export * from "./logger.service";
|
|
41
41
|
export * from "./mailer.port";
|
|
42
42
|
export * from "./memory-consumption.service";
|
|
43
|
+
export * as History from "./modules/history";
|
|
43
44
|
export * from "./node-cache-rate-limit-store.adapter";
|
|
44
45
|
export * from "./node-env.vo";
|
|
45
46
|
export * from "./noop-mailer.adapter";
|
|
@@ -56,6 +57,7 @@ export * from "./simulated-error.middleware";
|
|
|
56
57
|
export * from "./sitemap.service";
|
|
57
58
|
export * from "./slower.middleware";
|
|
58
59
|
export * from "./smtp-mailer.adapter";
|
|
60
|
+
export * from "./smtp-mailer-with-mailer.adapter";
|
|
59
61
|
export * from "./time-zone-offset.middleware";
|
|
60
62
|
export * from "./to-event-map.types";
|
|
61
63
|
export * from "./translations.service";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Events from "../events";
|
|
2
|
+
import * as Repos from "../repositories";
|
|
3
|
+
|
|
4
|
+
export const onHistoryClearedEvent =
|
|
5
|
+
(repository: Repos.HistoryRepositoryPort) => async (event: Events.HistoryClearedEventType) => {
|
|
6
|
+
await repository.clear(event.payload.subject);
|
|
7
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as Events from "../events";
|
|
2
|
+
import * as Repos from "../repositories";
|
|
3
|
+
import * as VO from "../value-objects";
|
|
4
|
+
|
|
5
|
+
export const onHistoryPopulatedEvent =
|
|
6
|
+
(repository: Repos.HistoryRepositoryPort) => async (event: Events.HistoryPopulatedEventType) => {
|
|
7
|
+
const data = VO.HistoryParsed.parse(event.payload);
|
|
8
|
+
await repository.append(data, event.createdAt);
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { UUID } from "../../../uuid.vo";
|
|
4
|
+
import * as VO from "../value-objects";
|
|
5
|
+
|
|
6
|
+
export const HISTORY_CLEARED_EVENT = "HISTORY_CLEARED_EVENT";
|
|
7
|
+
|
|
8
|
+
export const HistoryClearedEvent = z.object({
|
|
9
|
+
id: UUID,
|
|
10
|
+
correlationId: UUID,
|
|
11
|
+
createdAt: tools.Timestamp,
|
|
12
|
+
stream: z.string().min(1),
|
|
13
|
+
name: z.literal(HISTORY_CLEARED_EVENT),
|
|
14
|
+
version: z.literal(1),
|
|
15
|
+
revision: tools.RevisionValue.optional(),
|
|
16
|
+
payload: z.object({ subject: VO.HistorySubject }),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type HistoryClearedEventType = z.infer<typeof HistoryClearedEvent>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { UUID } from "../../../uuid.vo";
|
|
4
|
+
import * as VO from "../value-objects";
|
|
5
|
+
|
|
6
|
+
export const HISTORY_POPULATED_EVENT = "HISTORY_POPULATED_EVENT";
|
|
7
|
+
|
|
8
|
+
export const HistoryPopulatedEvent = z.object({
|
|
9
|
+
id: UUID,
|
|
10
|
+
correlationId: UUID,
|
|
11
|
+
createdAt: tools.Timestamp,
|
|
12
|
+
stream: z.string().min(1),
|
|
13
|
+
name: z.literal(HISTORY_POPULATED_EVENT),
|
|
14
|
+
version: z.literal(1),
|
|
15
|
+
revision: tools.RevisionValue.optional(),
|
|
16
|
+
payload: z.object({
|
|
17
|
+
id: VO.HistoryId,
|
|
18
|
+
operation: VO.HistoryOperation,
|
|
19
|
+
subject: VO.HistorySubject,
|
|
20
|
+
payload: VO.HistoryPayload,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
export type HistoryPopulatedEventType = z.infer<typeof HistoryPopulatedEvent>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import * as VO from "../value-objects";
|
|
3
|
+
|
|
4
|
+
export interface HistoryRepositoryPort {
|
|
5
|
+
append(data: VO.HistoryParsedType, createdAt: tools.TimestampType): Promise<void>;
|
|
6
|
+
|
|
7
|
+
clear(subject: VO.HistoryParsedType["subject"]): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./history-repository";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./history-writer";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export const HistoryPayload = z.record(z.string(), z.any());
|
|
4
|
+
|
|
5
|
+
export const HistoryPayloadParsed = HistoryPayload.refine((value) => {
|
|
6
|
+
try {
|
|
7
|
+
JSON.parse(JSON.stringify(value));
|
|
8
|
+
return true;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}).transform((value) => JSON.stringify(value));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { HistoryId } from "./history-id";
|
|
3
|
+
import { HistoryOperation } from "./history-operation";
|
|
4
|
+
import { HistoryPayload, HistoryPayloadParsed } from "./history-payload";
|
|
5
|
+
import { HistorySubject } from "./history-subject";
|
|
6
|
+
|
|
7
|
+
const History = z.object({
|
|
8
|
+
id: HistoryId,
|
|
9
|
+
operation: HistoryOperation,
|
|
10
|
+
payload: HistoryPayload,
|
|
11
|
+
subject: HistorySubject,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type HistoryType = z.infer<typeof History>;
|
|
15
|
+
|
|
16
|
+
export const HistoryParsed = z.object({
|
|
17
|
+
id: HistoryId,
|
|
18
|
+
operation: HistoryOperation,
|
|
19
|
+
payload: HistoryPayloadParsed,
|
|
20
|
+
subject: HistorySubject,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type HistoryParsedType = z.infer<typeof HistoryParsed>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SendMailOptions } from "nodemailer";
|
|
2
|
+
import { Logger } from "./logger.service";
|
|
3
|
+
import { MailerPort } from "./mailer.port";
|
|
4
|
+
import { SmtpMailerAdapter } from "./smtp-mailer.adapter";
|
|
5
|
+
|
|
6
|
+
type MailerSendOptionsType = SendMailOptions;
|
|
7
|
+
|
|
8
|
+
type SmtpMailerWithLoggerConfigType = {
|
|
9
|
+
smtpMailer: SmtpMailerAdapter;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class SmtpMailerWithLoggerAdapter implements MailerPort {
|
|
14
|
+
constructor(private readonly config: SmtpMailerWithLoggerConfigType) {}
|
|
15
|
+
|
|
16
|
+
async send(message: MailerSendOptionsType): Promise<unknown> {
|
|
17
|
+
try {
|
|
18
|
+
this.config.logger.info({ message: "Mailer attempt", operation: "mailer", metadata: message });
|
|
19
|
+
|
|
20
|
+
const result = await this.config.smtpMailer.send(message);
|
|
21
|
+
|
|
22
|
+
this.config.logger.info({
|
|
23
|
+
message: "Mailer success",
|
|
24
|
+
operation: "mailer",
|
|
25
|
+
metadata: { message, result },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
this.config.logger.error({
|
|
31
|
+
message: "Mailer error",
|
|
32
|
+
operation: "mailer",
|
|
33
|
+
metadata: this.config.logger.formatError(error),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async verify() {
|
|
41
|
+
return this.config.smtpMailer.verify();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -56,10 +56,7 @@ export class SmtpMailerAdapter implements MailerPort {
|
|
|
56
56
|
this.transport = nodemailer.createTransport({
|
|
57
57
|
host: config.SMTP_HOST,
|
|
58
58
|
port: config.SMTP_PORT,
|
|
59
|
-
auth: {
|
|
60
|
-
user: config.SMTP_USER,
|
|
61
|
-
pass: config.SMTP_PASS,
|
|
62
|
-
},
|
|
59
|
+
auth: { user: config.SMTP_USER, pass: config.SMTP_PASS },
|
|
63
60
|
});
|
|
64
61
|
}
|
|
65
62
|
|