@bgord/bun 1.4.19 → 1.4.21
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/hcaptcha-secret-key.vo.js +1 -1
- package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.d.ts +7 -1
- package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.d.ts.map +1 -1
- package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.js +4 -4
- package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.js.map +1 -1
- package/dist/prerequisites/clock-drift.d.ts +6 -3
- package/dist/prerequisites/clock-drift.d.ts.map +1 -1
- package/dist/prerequisites/clock-drift.js +5 -4
- package/dist/prerequisites/clock-drift.js.map +1 -1
- package/dist/prerequisites/log-file.d.ts +6 -4
- package/dist/prerequisites/log-file.d.ts.map +1 -1
- package/dist/prerequisites/log-file.js +4 -4
- package/dist/prerequisites/log-file.js.map +1 -1
- package/dist/prerequisites/mailer.d.ts +6 -3
- package/dist/prerequisites/mailer.d.ts.map +1 -1
- package/dist/prerequisites/mailer.js +4 -4
- package/dist/prerequisites/mailer.js.map +1 -1
- package/dist/prerequisites/space.d.ts +6 -3
- package/dist/prerequisites/space.d.ts.map +1 -1
- package/dist/prerequisites/space.js +5 -4
- package/dist/prerequisites/space.js.map +1 -1
- package/dist/prerequisites/ssl-certificate-expiry.d.ts +6 -3
- package/dist/prerequisites/ssl-certificate-expiry.d.ts.map +1 -1
- package/dist/prerequisites/ssl-certificate-expiry.js +4 -4
- package/dist/prerequisites/ssl-certificate-expiry.js.map +1 -1
- package/dist/prerequisites/translations.d.ts +7 -5
- package/dist/prerequisites/translations.d.ts.map +1 -1
- package/dist/prerequisites/translations.js +5 -6
- package/dist/prerequisites/translations.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/hcaptcha-secret-key.vo.ts +1 -1
- package/src/modules/preferences/command-handlers/handleSetUserLanguageCommand.ts +11 -10
- package/src/prerequisites/clock-drift.ts +7 -8
- package/src/prerequisites/log-file.ts +7 -6
- package/src/prerequisites/mailer.ts +7 -4
- package/src/prerequisites/space.ts +6 -4
- package/src/prerequisites/ssl-certificate-expiry.ts +5 -8
- package/src/prerequisites/translations.ts +6 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@axiomhq/winston": "1.3.1",
|
|
41
|
-
"@bgord/tools": "1.1.
|
|
41
|
+
"@bgord/tools": "1.1.20",
|
|
42
42
|
"@hono/ua-blocker": "0.1.21",
|
|
43
|
-
"better-auth": "1.4.
|
|
43
|
+
"better-auth": "1.4.7",
|
|
44
44
|
"croner": "9.1.0",
|
|
45
45
|
"csv": "6.4.1",
|
|
46
46
|
"hcaptcha": "0.2.0",
|
|
47
|
-
"hono": "4.
|
|
47
|
+
"hono": "4.11.0",
|
|
48
48
|
"isomorphic-dompurify": "2.34.0",
|
|
49
49
|
"lodash": "4.17.21",
|
|
50
50
|
"marked": "17.0.1",
|
|
@@ -7,7 +7,7 @@ export const HCaptchaSecretKeyError = {
|
|
|
7
7
|
|
|
8
8
|
export const HCaptchaSecretKey = z
|
|
9
9
|
.string(HCaptchaSecretKeyError.Type)
|
|
10
|
-
.length(
|
|
10
|
+
.length(35, HCaptchaSecretKeyError.Length)
|
|
11
11
|
.brand("HCaptchaSecretKey");
|
|
12
12
|
|
|
13
13
|
export type HCaptchaSecretKeyType = z.infer<typeof HCaptchaSecretKey>;
|
|
@@ -9,27 +9,28 @@ import * as Invariants from "../invariants";
|
|
|
9
9
|
import type * as Ports from "../ports";
|
|
10
10
|
import type * as VO from "../value-objects";
|
|
11
11
|
|
|
12
|
+
type Dependencies = {
|
|
13
|
+
EventStore: EventStoreLike<AcceptedEvent>;
|
|
14
|
+
IdProvider: IdProviderPort;
|
|
15
|
+
Clock: ClockPort;
|
|
16
|
+
UserLanguageQuery: Ports.UserLanguageQueryPort;
|
|
17
|
+
};
|
|
18
|
+
|
|
12
19
|
type AcceptedEvent = Events.UserLanguageSetEventType;
|
|
13
20
|
|
|
14
21
|
export const handleSetUserLanguageCommand =
|
|
15
|
-
<L extends readonly tools.LanguageType[]>(
|
|
16
|
-
EventStore: EventStoreLike<AcceptedEvent>,
|
|
17
|
-
IdProvider: IdProviderPort,
|
|
18
|
-
Clock: ClockPort,
|
|
19
|
-
query: Ports.UserLanguageQueryPort,
|
|
20
|
-
supported: VO.SupportedLanguagesSet<L>,
|
|
21
|
-
) =>
|
|
22
|
+
<L extends readonly tools.LanguageType[]>(supported: VO.SupportedLanguagesSet<L>, deps: Dependencies) =>
|
|
22
23
|
async (command: Commands.SetUserLanguageCommandType) => {
|
|
23
24
|
const candidate = supported.ensure(command.payload.language);
|
|
24
|
-
const current = await
|
|
25
|
+
const current = await deps.UserLanguageQuery.get(command.payload.userId);
|
|
25
26
|
|
|
26
27
|
if (Invariants.UserLanguageHasChanged.fails({ current, candidate: command.payload.language })) return;
|
|
27
28
|
|
|
28
29
|
const event = Events.UserLanguageSetEvent.parse({
|
|
29
|
-
...createEventEnvelope(`preferences_${command.payload.userId}`,
|
|
30
|
+
...createEventEnvelope(`preferences_${command.payload.userId}`, deps),
|
|
30
31
|
name: Events.USER_LANGUAGE_SET_EVENT,
|
|
31
32
|
payload: { userId: command.payload.userId, language: candidate },
|
|
32
33
|
} satisfies Events.UserLanguageSetEventType);
|
|
33
34
|
|
|
34
|
-
await EventStore.save([event]);
|
|
35
|
+
await deps.EventStore.save([event]);
|
|
35
36
|
};
|
|
@@ -5,38 +5,37 @@ import type { TimekeeperPort } from "../timekeeper.port";
|
|
|
5
5
|
import { TimekeeperGoogleAdapter } from "../timekeeper-google.adapter";
|
|
6
6
|
import { Timeout } from "../timeout.service";
|
|
7
7
|
|
|
8
|
+
type Dependencies = { Timekeeper?: TimekeeperPort };
|
|
9
|
+
|
|
8
10
|
export class PrerequisiteClockDrift implements prereqs.Prerequisite {
|
|
9
11
|
readonly kind = "clock-drift";
|
|
10
12
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
11
13
|
readonly enabled?: boolean = true;
|
|
12
14
|
|
|
13
15
|
readonly skew: tools.Duration;
|
|
14
|
-
readonly Timekeeper: TimekeeperPort;
|
|
15
16
|
readonly timeout: tools.Duration;
|
|
16
17
|
|
|
17
18
|
constructor(
|
|
18
|
-
config: prereqs.PrerequisiteConfigType & {
|
|
19
|
-
|
|
20
|
-
Timekeeper?: TimekeeperPort;
|
|
21
|
-
timeout?: tools.Duration;
|
|
22
|
-
},
|
|
19
|
+
config: prereqs.PrerequisiteConfigType & { skew: tools.Duration; timeout?: tools.Duration },
|
|
20
|
+
private readonly deps?: Dependencies,
|
|
23
21
|
) {
|
|
24
22
|
this.label = config.label;
|
|
25
23
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
26
24
|
|
|
27
25
|
this.skew = config.skew;
|
|
28
|
-
this.Timekeeper = config.Timekeeper ?? new TimekeeperGoogleAdapter();
|
|
29
26
|
this.timeout = config.timeout ?? tools.Duration.Seconds(2);
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
30
|
+
const Timekeeper = this.deps?.Timekeeper ?? new TimekeeperGoogleAdapter();
|
|
31
|
+
|
|
33
32
|
const stopwatch = new tools.Stopwatch(clock.now());
|
|
34
33
|
|
|
35
34
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
36
35
|
|
|
37
36
|
try {
|
|
38
37
|
const timestamp = await Timeout.cancellable(
|
|
39
|
-
(signal: AbortSignal) =>
|
|
38
|
+
(signal: AbortSignal) => Timekeeper.get(signal),
|
|
40
39
|
this.timeout,
|
|
41
40
|
);
|
|
42
41
|
if (!timestamp) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
@@ -3,18 +3,19 @@ import type { ClockPort } from "../clock.port";
|
|
|
3
3
|
import type { LoggerPort } from "../logger.port";
|
|
4
4
|
import * as prereqs from "../prerequisites.service";
|
|
5
5
|
|
|
6
|
+
type Dependencies = { Logger: LoggerPort };
|
|
7
|
+
|
|
6
8
|
export class PrerequisiteLogFile implements prereqs.Prerequisite {
|
|
7
9
|
readonly kind = "log-file";
|
|
8
10
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
9
11
|
readonly enabled?: boolean = true;
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
constructor(
|
|
14
|
+
config: prereqs.PrerequisiteConfigType,
|
|
15
|
+
private readonly deps: Dependencies,
|
|
16
|
+
) {
|
|
14
17
|
this.label = config.label;
|
|
15
18
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
16
|
-
|
|
17
|
-
this.Logger = config.Logger;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
@@ -23,7 +24,7 @@ export class PrerequisiteLogFile implements prereqs.Prerequisite {
|
|
|
23
24
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
24
25
|
|
|
25
26
|
try {
|
|
26
|
-
const path = this.Logger.getFilePath();
|
|
27
|
+
const path = this.deps.Logger.getFilePath();
|
|
27
28
|
if (!path) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
28
29
|
|
|
29
30
|
const result = await Bun.file(path.get()).exists();
|
|
@@ -4,19 +4,22 @@ import type { MailerPort } from "../mailer.port";
|
|
|
4
4
|
import * as prereqs from "../prerequisites.service";
|
|
5
5
|
import { Timeout } from "../timeout.service";
|
|
6
6
|
|
|
7
|
+
type Dependencies = { Mailer: MailerPort };
|
|
8
|
+
|
|
7
9
|
export class PrerequisiteMailer implements prereqs.Prerequisite {
|
|
8
10
|
readonly kind = "mailer";
|
|
9
11
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
10
12
|
readonly enabled?: boolean = true;
|
|
11
13
|
|
|
12
|
-
private readonly Mailer: MailerPort;
|
|
13
14
|
readonly timeout: tools.Duration;
|
|
14
15
|
|
|
15
|
-
constructor(
|
|
16
|
+
constructor(
|
|
17
|
+
config: prereqs.PrerequisiteConfigType & { timeout?: tools.Duration },
|
|
18
|
+
private readonly deps: Dependencies,
|
|
19
|
+
) {
|
|
16
20
|
this.label = config.label;
|
|
17
21
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
18
22
|
|
|
19
|
-
this.Mailer = config.Mailer;
|
|
20
23
|
this.timeout = config.timeout ?? tools.Duration.Seconds(2);
|
|
21
24
|
}
|
|
22
25
|
|
|
@@ -26,7 +29,7 @@ export class PrerequisiteMailer implements prereqs.Prerequisite {
|
|
|
26
29
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
27
30
|
|
|
28
31
|
try {
|
|
29
|
-
await Timeout.run(this.Mailer.verify(), this.timeout);
|
|
32
|
+
await Timeout.run(this.deps.Mailer.verify(), this.timeout);
|
|
30
33
|
return prereqs.Verification.success(stopwatch.stop());
|
|
31
34
|
} catch (error) {
|
|
32
35
|
return prereqs.Verification.failure(stopwatch.stop(), error as Error);
|
|
@@ -5,32 +5,34 @@ import type { DiskSpaceCheckerPort } from "../disk-space-checker.port";
|
|
|
5
5
|
import { DiskSpaceCheckerBunAdapter } from "../disk-space-checker-bun.adapter";
|
|
6
6
|
import * as prereqs from "../prerequisites.service";
|
|
7
7
|
|
|
8
|
+
type Dependencies = { DiskSpaceChecker?: DiskSpaceCheckerPort };
|
|
9
|
+
|
|
8
10
|
export class PrerequisiteSpace implements prereqs.Prerequisite {
|
|
9
11
|
readonly kind = "space";
|
|
10
12
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
11
13
|
readonly enabled?: boolean = true;
|
|
12
14
|
|
|
13
15
|
private readonly minimum: tools.Size;
|
|
14
|
-
private readonly DiskSpaceChecker: DiskSpaceCheckerPort;
|
|
15
16
|
|
|
16
17
|
constructor(
|
|
17
|
-
config: prereqs.PrerequisiteConfigType & { minimum: tools.Size
|
|
18
|
+
config: prereqs.PrerequisiteConfigType & { minimum: tools.Size },
|
|
19
|
+
private readonly deps?: Dependencies,
|
|
18
20
|
) {
|
|
19
21
|
this.label = config.label;
|
|
20
22
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
21
23
|
|
|
22
24
|
this.minimum = config.minimum;
|
|
23
|
-
this.DiskSpaceChecker = config.DiskSpaceChecker ?? new DiskSpaceCheckerBunAdapter();
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
28
|
+
const DiskSpaceChecker = this.deps?.DiskSpaceChecker ?? new DiskSpaceCheckerBunAdapter();
|
|
27
29
|
const stopwatch = new tools.Stopwatch(clock.now());
|
|
28
30
|
|
|
29
31
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
30
32
|
|
|
31
33
|
try {
|
|
32
34
|
const root = path.sep;
|
|
33
|
-
const freeDiskSpace = await
|
|
35
|
+
const freeDiskSpace = await DiskSpaceChecker.get(root);
|
|
34
36
|
|
|
35
37
|
if (freeDiskSpace.isGreaterThan(this.minimum)) return prereqs.Verification.success(stopwatch.stop());
|
|
36
38
|
return prereqs.Verification.failure(stopwatch.stop(), {
|
|
@@ -3,6 +3,8 @@ import type { CertificateInspectorPort } from "../certificate-inspector.port";
|
|
|
3
3
|
import type { ClockPort } from "../clock.port";
|
|
4
4
|
import * as prereqs from "../prerequisites.service";
|
|
5
5
|
|
|
6
|
+
type Dependencies = { CertificateInspector: CertificateInspectorPort };
|
|
7
|
+
|
|
6
8
|
export class PrerequisiteSSLCertificateExpiry implements prereqs.Prerequisite {
|
|
7
9
|
readonly kind = "ssl-certificate-expiry";
|
|
8
10
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
@@ -10,21 +12,16 @@ export class PrerequisiteSSLCertificateExpiry implements prereqs.Prerequisite {
|
|
|
10
12
|
|
|
11
13
|
private readonly hostname: string;
|
|
12
14
|
private readonly days: number;
|
|
13
|
-
private readonly CertificateInspector: CertificateInspectorPort;
|
|
14
15
|
|
|
15
16
|
constructor(
|
|
16
|
-
config: prereqs.PrerequisiteConfigType & {
|
|
17
|
-
|
|
18
|
-
days: number;
|
|
19
|
-
CertificateInspector: CertificateInspectorPort;
|
|
20
|
-
},
|
|
17
|
+
config: prereqs.PrerequisiteConfigType & { hostname: string; days: number },
|
|
18
|
+
private readonly deps: Dependencies,
|
|
21
19
|
) {
|
|
22
20
|
this.label = config.label;
|
|
23
21
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
24
22
|
|
|
25
23
|
this.hostname = config.hostname;
|
|
26
24
|
this.days = config.days;
|
|
27
|
-
this.CertificateInspector = config.CertificateInspector;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
@@ -32,7 +29,7 @@ export class PrerequisiteSSLCertificateExpiry implements prereqs.Prerequisite {
|
|
|
32
29
|
|
|
33
30
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
34
31
|
|
|
35
|
-
const result = await this.CertificateInspector.inspect(this.hostname);
|
|
32
|
+
const result = await this.deps.CertificateInspector.inspect(this.hostname);
|
|
36
33
|
|
|
37
34
|
if (!result.success)
|
|
38
35
|
return prereqs.Verification.failure(stopwatch.stop(), { message: "Certificate unavailable" });
|
|
@@ -15,6 +15,8 @@ type PrerequisiteTranslationsProblemType = {
|
|
|
15
15
|
missingIn: tools.LanguageType;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
type Dependencies = { Logger: LoggerPort; JsonFileReader?: JsonFileReaderPort };
|
|
19
|
+
|
|
18
20
|
export class PrerequisiteTranslations implements prereqs.Prerequisite {
|
|
19
21
|
readonly kind = "translations";
|
|
20
22
|
readonly label: prereqs.PrerequisiteLabelType;
|
|
@@ -23,28 +25,23 @@ export class PrerequisiteTranslations implements prereqs.Prerequisite {
|
|
|
23
25
|
private readonly translationsPath?: typeof I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
24
26
|
private readonly supportedLanguages: types.I18nConfigType["supportedLanguages"];
|
|
25
27
|
|
|
26
|
-
private readonly Logger: LoggerPort;
|
|
27
|
-
private readonly JsonFileReader: JsonFileReaderPort;
|
|
28
|
-
|
|
29
28
|
constructor(
|
|
30
29
|
config: prereqs.PrerequisiteConfigType & {
|
|
31
30
|
translationsPath?: typeof I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
32
31
|
supportedLanguages: types.I18nConfigType["supportedLanguages"];
|
|
33
|
-
Logger: LoggerPort;
|
|
34
|
-
JsonFileReader?: JsonFileReaderPort;
|
|
35
32
|
},
|
|
33
|
+
private readonly deps: Dependencies,
|
|
36
34
|
) {
|
|
37
35
|
this.label = config.label;
|
|
38
36
|
this.enabled = config.enabled === undefined ? true : config.enabled;
|
|
39
37
|
|
|
40
38
|
this.translationsPath = config.translationsPath;
|
|
41
39
|
this.supportedLanguages = config.supportedLanguages;
|
|
42
|
-
|
|
43
|
-
this.Logger = config.Logger;
|
|
44
|
-
this.JsonFileReader = config.JsonFileReader ?? new JsonFileReaderBunForgivingAdapter();
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
async verify(clock: ClockPort): Promise<prereqs.VerifyOutcome> {
|
|
43
|
+
const JsonFileReader = this.deps.JsonFileReader ?? new JsonFileReaderBunForgivingAdapter();
|
|
44
|
+
|
|
48
45
|
const stopwatch = new tools.Stopwatch(clock.now());
|
|
49
46
|
|
|
50
47
|
if (!this.enabled) return prereqs.Verification.undetermined(stopwatch.stop());
|
|
@@ -52,7 +49,7 @@ export class PrerequisiteTranslations implements prereqs.Prerequisite {
|
|
|
52
49
|
const translationsPath = this.translationsPath ?? I18n.DEFAULT_TRANSLATIONS_PATH;
|
|
53
50
|
|
|
54
51
|
const supportedLanguages = Object.keys(this.supportedLanguages);
|
|
55
|
-
const i18n = new I18n({ Logger: this.Logger, JsonFileReader:
|
|
52
|
+
const i18n = new I18n({ Logger: this.deps.Logger, JsonFileReader: JsonFileReader });
|
|
56
53
|
|
|
57
54
|
try {
|
|
58
55
|
await fsp.access(translationsPath, constants.R_OK);
|