@bgord/bun 0.12.0 → 0.13.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/bots.vo.d.ts +2 -0
- package/dist/bots.vo.d.ts.map +1 -0
- package/dist/bots.vo.js +4 -0
- package/dist/bots.vo.js.map +1 -0
- package/dist/command-logger.d.ts +8 -0
- package/dist/command-logger.d.ts.map +1 -0
- package/dist/command-logger.js +19 -0
- package/dist/command-logger.js.map +1 -0
- package/dist/command.types.d.ts +12 -0
- package/dist/command.types.d.ts.map +1 -0
- package/dist/command.types.js +2 -0
- package/dist/command.types.js.map +1 -0
- package/dist/correlation-id.vo.d.ts +1 -1
- package/dist/correlation-id.vo.d.ts.map +1 -1
- package/dist/correlation-id.vo.js +1 -1
- package/dist/correlation-id.vo.js.map +1 -1
- package/dist/correlation-storage.service.d.ts +9 -0
- package/dist/correlation-storage.service.d.ts.map +1 -0
- package/dist/correlation-storage.service.js +22 -0
- package/dist/correlation-storage.service.js.map +1 -0
- package/dist/dispatching-event-store.d.ts +15 -0
- package/dist/dispatching-event-store.d.ts.map +1 -0
- package/dist/dispatching-event-store.js +13 -0
- package/dist/dispatching-event-store.js.map +1 -0
- package/dist/event-handler.service.d.ts +2 -1
- package/dist/event-handler.service.d.ts.map +1 -1
- package/dist/event-handler.service.js.map +1 -1
- package/dist/event-publisher.types.d.ts +4 -0
- package/dist/event-publisher.types.d.ts.map +1 -0
- package/dist/event-publisher.types.js +2 -0
- package/dist/event-publisher.types.js.map +1 -0
- package/dist/event.types.d.ts +1 -0
- package/dist/event.types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/setup.service.d.ts.map +1 -1
- package/dist/setup.service.js +6 -1
- package/dist/setup.service.js.map +1 -1
- package/dist/to-event-map.types.d.ts +6 -0
- package/dist/to-event-map.types.d.ts.map +1 -0
- package/dist/to-event-map.types.js +2 -0
- package/dist/to-event-map.types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/bots.vo.ts +3 -0
- package/src/command-logger.ts +24 -0
- package/src/command.types.ts +15 -0
- package/src/correlation-id.vo.ts +1 -1
- package/src/correlation-storage.service.ts +35 -0
- package/src/dispatching-event-store.ts +28 -0
- package/src/event-handler.service.ts +2 -1
- package/src/event-publisher.types.ts +3 -0
- package/src/event.types.ts +1 -0
- package/src/index.ts +6 -0
- package/src/setup.service.ts +6 -1
- package/src/to-event-map.types.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"preinstall": "bunx only-allow bun"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@biomejs/biome": "2.0.
|
|
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.
|
|
27
|
-
"@types/lodash": "4.17.
|
|
26
|
+
"@types/bun": "1.2.17",
|
|
27
|
+
"@types/lodash": "4.17.19",
|
|
28
28
|
"@types/mime-types": "3.0.1",
|
|
29
29
|
"@types/nodemailer": "6.4.17",
|
|
30
|
-
"cspell": "9.1.
|
|
31
|
-
"knip": "5.61.
|
|
30
|
+
"cspell": "9.1.2",
|
|
31
|
+
"knip": "5.61.3",
|
|
32
32
|
"lefthook": "1.11.14",
|
|
33
33
|
"only-allow": "1.2.1",
|
|
34
34
|
"shellcheck": "3.1.0",
|
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@bgord/tools": "0.9.3",
|
|
39
|
+
"@hono/ua-blocker": "0.1.2",
|
|
39
40
|
"check-disk-space": "3.4.0",
|
|
40
41
|
"croner": "9.1.0",
|
|
41
42
|
"hcaptcha": "0.2.0",
|
|
42
|
-
"hono": "4.8.
|
|
43
|
+
"hono": "4.8.3",
|
|
43
44
|
"lodash": "4.17.21",
|
|
44
45
|
"lucia": "3.2.2",
|
|
45
46
|
"mime-types": "3.0.1",
|
package/src/bots.vo.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const BOTS_REGEX =
|
|
2
|
+
// cspell:disable-next-line
|
|
3
|
+
/(AI2BOT|AI2BOT-DOLMA|AIHITBOT|AMAZONBOT|ANDIBOT|ANTHROPIC-AI|APPLEBOT|APPLEBOT-EXTENDED|BEDROCKBOT|BRIGHTBOT 1.0|BYTESPIDER|CCBOT|CHATGPT-USER|CLAUDE-SEARCHBOT|CLAUDE-USER|CLAUDE-WEB|CLAUDEBOT|COHERE-AI|COHERE-TRAINING-DATA-CRAWLER|COTOYOGI|CRAWLSPACE|DIFFBOT|DUCKASSISTBOT|ECHOBOXBOT|FACEBOOKBOT|FACEBOOKEXTERNALHIT|FACTSET_SPYDERBOT|FIRECRAWLAGENT|FRIENDLYCRAWLER|GOOGLE-CLOUDVERTEXBOT|GOOGLE-EXTENDED|GOOGLEOTHER|GOOGLEOTHER-IMAGE|GOOGLEOTHER-VIDEO|GPTBOT|IASKSPIDER\/2.0|ICC-CRAWLER|IMAGESIFTBOT|IMG2DATASET|ISSCYBERRISKCRAWLER|KANGAROO BOT|META-EXTERNALAGENT|META-EXTERNALAGENT|META-EXTERNALFETCHER|META-EXTERNALFETCHER|MISTRALAI-USER\/1.0|MYCENTRALAISCRAPERBOT|NOVAACT|OAI-SEARCHBOT|OMGILI|OMGILIBOT|OPERATOR|PANGUBOT|PANSCIENT|PANSCIENT.COM|PERPLEXITY-USER|PERPLEXITYBOT|PETALBOT|PHINDBOT|POSEIDON RESEARCH CRAWLER|QUALIFIEDBOT|QUILLBOT|QUILLBOT.COM|SBINTUITIONSBOT|SCRAPY|SEMRUSHBOT|SEMRUSHBOT-BA|SEMRUSHBOT-CT|SEMRUSHBOT-OCOB|SEMRUSHBOT-SI|SEMRUSHBOT-SWA|SIDETRADE INDEXER BOT|TIKTOKSPIDER|TIMPIBOT|VELENPUBLICWEBCRAWLER|WEBZIO-EXTENDED|WPBOT|YANDEXADDITIONAL|YANDEXADDITIONALBOT|YOUBOT)/;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Logger } from "./logger.service";
|
|
2
|
+
|
|
3
|
+
export class CommandLogger {
|
|
4
|
+
constructor(private readonly logger: Logger) {}
|
|
5
|
+
|
|
6
|
+
private _handle(
|
|
7
|
+
type: string,
|
|
8
|
+
_debugName: string,
|
|
9
|
+
commandName: string | undefined,
|
|
10
|
+
commandData: Record<string, any> | undefined,
|
|
11
|
+
) {
|
|
12
|
+
if (type === "subscribe") return;
|
|
13
|
+
|
|
14
|
+
if (typeof commandName === "symbol") return;
|
|
15
|
+
|
|
16
|
+
this.logger.info({
|
|
17
|
+
message: `${commandName} emitted`,
|
|
18
|
+
operation: "command_emitted",
|
|
19
|
+
metadata: commandData,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
handle = this._handle.bind(this);
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
|
|
3
|
+
export type GenericCommandSchema = z.ZodObject<{
|
|
4
|
+
id: z.ZodType<string>;
|
|
5
|
+
correlationId: z.ZodType<string>;
|
|
6
|
+
createdAt: z.ZodType<number>;
|
|
7
|
+
name: z.ZodLiteral<string>;
|
|
8
|
+
payload: z.ZodType<any>;
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
export type GenericParsedCommandSchema = z.ZodObject<
|
|
12
|
+
Omit<GenericCommandSchema["shape"], "payload"> & {
|
|
13
|
+
payload: z.ZodString;
|
|
14
|
+
}
|
|
15
|
+
>;
|
package/src/correlation-id.vo.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createMiddleware } from "hono/factory";
|
|
3
|
+
|
|
4
|
+
import type { CorrelationIdType } from "./correlation-id.vo";
|
|
5
|
+
|
|
6
|
+
interface CorrelationContext {
|
|
7
|
+
correlationId: CorrelationIdType;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class CorrelationStorage {
|
|
11
|
+
private static readonly GLOBAL_KEY = Symbol.for("bgord.CorrelationStorage");
|
|
12
|
+
|
|
13
|
+
// biome-ignore lint: lint/suspicious/noAssignInExpressions
|
|
14
|
+
private static readonly als: AsyncLocalStorage<CorrelationContext> = ((globalThis as any)[
|
|
15
|
+
this.GLOBAL_KEY
|
|
16
|
+
] ??=
|
|
17
|
+
new AsyncLocalStorage<CorrelationContext>());
|
|
18
|
+
|
|
19
|
+
static run<T>(correlationId: CorrelationIdType, fn: () => T | Promise<T>): T | Promise<T> {
|
|
20
|
+
return CorrelationStorage.als.run({ correlationId }, fn);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static get(): CorrelationIdType {
|
|
24
|
+
const store = CorrelationStorage.als.getStore();
|
|
25
|
+
if (!store) throw new Error("CorrelationId missing from context");
|
|
26
|
+
return store.correlationId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static handle = () =>
|
|
30
|
+
createMiddleware(async (c, next) => {
|
|
31
|
+
const correlationId = c.get("requestId");
|
|
32
|
+
|
|
33
|
+
return CorrelationStorage.run(correlationId, next);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import type { GenericEventSchema, GenericParsedEventSchema } from "./event.types";
|
|
3
|
+
import type { EventPublisher } from "./event-publisher.types";
|
|
4
|
+
import { EventStore as BaseStore } from "./event-store";
|
|
5
|
+
import type { EventStreamType } from "./event-stream.vo";
|
|
6
|
+
import { ToEventMap } from "./to-event-map.types";
|
|
7
|
+
|
|
8
|
+
export class DispatchingEventStore<AllEvents extends GenericEventSchema> extends BaseStore<AllEvents> {
|
|
9
|
+
constructor(
|
|
10
|
+
config: {
|
|
11
|
+
finder: (stream: EventStreamType, names: string[]) => Promise<z.infer<GenericEventSchema>[]>;
|
|
12
|
+
inserter: (events: z.infer<GenericParsedEventSchema>[]) => Promise<void>;
|
|
13
|
+
},
|
|
14
|
+
private readonly publisher: EventPublisher<ToEventMap<z.infer<AllEvents>>>,
|
|
15
|
+
) {
|
|
16
|
+
super(config);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async save(events: z.infer<AllEvents>[]) {
|
|
20
|
+
await super.save(events);
|
|
21
|
+
|
|
22
|
+
await Promise.all(
|
|
23
|
+
events.map((event) =>
|
|
24
|
+
this.publisher.emit(event.name as keyof ToEventMap<z.infer<AllEvents>>, event as any),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
1
2
|
import type { GenericEventSchema } from "./event.types";
|
|
2
3
|
import { Logger } from "./logger.service";
|
|
3
4
|
|
|
4
5
|
export class EventHandler {
|
|
5
6
|
constructor(private readonly logger: Logger) {}
|
|
6
7
|
|
|
7
|
-
handle<T extends { name: GenericEventSchema["shape"]["name"] }>(fn: (event: T) => Promise<void>) {
|
|
8
|
+
handle<T extends { name: z.infer<GenericEventSchema["shape"]["name"]> }>(fn: (event: T) => Promise<void>) {
|
|
8
9
|
return async (event: T) => {
|
|
9
10
|
try {
|
|
10
11
|
await fn(event);
|
package/src/event.types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as sharp } from "sharp";
|
|
2
|
+
|
|
2
3
|
export * from "./api-key-shield.middleware";
|
|
3
4
|
export * from "./api-version.middleware";
|
|
4
5
|
export * from "./auth-shield.middleware";
|
|
@@ -7,9 +8,13 @@ export * from "./build-info-repository.service";
|
|
|
7
8
|
export * from "./cache-resolver.service";
|
|
8
9
|
export * from "./cache-response.middleware";
|
|
9
10
|
export * from "./cache-static-files.middleware";
|
|
11
|
+
export * from "./command.types";
|
|
12
|
+
export * from "./command-logger";
|
|
10
13
|
export * from "./context.middleware";
|
|
11
14
|
export * from "./correlation-id.vo";
|
|
15
|
+
export * from "./correlation-storage.service";
|
|
12
16
|
export * from "./decorators.service";
|
|
17
|
+
export * from "./dispatching-event-store";
|
|
13
18
|
export * from "./download-file.service";
|
|
14
19
|
export * from "./encryption.service";
|
|
15
20
|
export * from "./env-validator.service";
|
|
@@ -51,6 +56,7 @@ export * from "./simulated-error.middleware";
|
|
|
51
56
|
export * from "./sitemap.service";
|
|
52
57
|
export * from "./slower.middleware";
|
|
53
58
|
export * from "./time-zone-offset.middleware";
|
|
59
|
+
export * from "./to-event-map.types";
|
|
54
60
|
export * from "./uptime.service";
|
|
55
61
|
export * from "./url-wo-trailing-slash.vo";
|
|
56
62
|
export * from "./username.vo";
|
package/src/setup.service.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as tools from "@bgord/tools";
|
|
2
|
+
import { uaBlocker } from "@hono/ua-blocker";
|
|
2
3
|
import { bodyLimit } from "hono/body-limit";
|
|
3
4
|
import { cors } from "hono/cors";
|
|
4
5
|
import { languageDetector } from "hono/language";
|
|
@@ -7,7 +8,9 @@ import { secureHeaders } from "hono/secure-headers";
|
|
|
7
8
|
import { timing } from "hono/timing";
|
|
8
9
|
|
|
9
10
|
import { ApiVersion } from "./api-version.middleware";
|
|
11
|
+
import { BOTS_REGEX } from "./bots.vo";
|
|
10
12
|
import { Context } from "./context.middleware";
|
|
13
|
+
import { CorrelationStorage } from "./correlation-storage.service";
|
|
11
14
|
import { ETagExtractor } from "./etag-extractor.middleware";
|
|
12
15
|
import { HttpLogger } from "./http-logger.middleware";
|
|
13
16
|
import { I18nConfigType } from "./i18n.service";
|
|
@@ -25,19 +28,21 @@ export class Setup {
|
|
|
25
28
|
return [
|
|
26
29
|
secureHeaders(),
|
|
27
30
|
bodyLimit({ maxSize: BODY_LIMIT_MAX_SIZE }),
|
|
31
|
+
uaBlocker({ blocklist: BOTS_REGEX }),
|
|
28
32
|
ApiVersion.attach,
|
|
29
33
|
cors({ origin: "*" }),
|
|
30
34
|
languageDetector({
|
|
31
35
|
supportedLanguages: Object.keys(i18n.supportedLanguages),
|
|
32
36
|
fallbackLanguage: i18n.defaultLanguage,
|
|
33
37
|
}),
|
|
34
|
-
requestId({ limitLength: 36 }),
|
|
38
|
+
requestId({ limitLength: 36, headerName: "x-correlation-id" }),
|
|
35
39
|
TimeZoneOffset.attach,
|
|
36
40
|
Context.attach,
|
|
37
41
|
WeakETagExtractor.attach,
|
|
38
42
|
ETagExtractor.attach,
|
|
39
43
|
HttpLogger.build(logger),
|
|
40
44
|
timing(),
|
|
45
|
+
CorrelationStorage.handle(),
|
|
41
46
|
];
|
|
42
47
|
}
|
|
43
48
|
}
|