@bgord/bun 1.19.7 → 1.19.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.
- package/dist/crypto-aes-gcm.service.d.ts.map +1 -1
- package/dist/crypto-aes-gcm.service.js +0 -1
- package/dist/crypto-aes-gcm.service.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/modules/history/event-handlers/onHistoryClearedEvent.d.ts.map +1 -1
- package/dist/modules/history/event-handlers/onHistoryClearedEvent.js.map +1 -1
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.d.ts.map +1 -1
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.js +0 -1
- package/dist/modules/history/event-handlers/onHistoryPopulatedEvent.js.map +1 -1
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.d.ts.map +1 -1
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.js +0 -1
- package/dist/modules/history/events/HISTORY_CLEARED_EVENT.js.map +1 -1
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.d.ts.map +1 -1
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.js +0 -1
- package/dist/modules/history/events/HISTORY_POPULATED_EVENT.js.map +1 -1
- package/dist/modules/history/index.d.ts.map +1 -1
- package/dist/modules/history/index.js +0 -1
- package/dist/modules/history/index.js.map +1 -1
- package/dist/modules/history/ports/history-reader.d.ts.map +1 -1
- package/dist/modules/history/ports/history-writer.d.ts.map +1 -1
- package/dist/modules/history/value-objects/history-created-at.d.ts.map +1 -1
- package/dist/modules/history/value-objects/history-operation.d.ts.map +1 -1
- package/dist/modules/history/value-objects/history-operation.js +0 -1
- package/dist/modules/history/value-objects/history-operation.js.map +1 -1
- package/dist/modules/history/value-objects/history-payload.d.ts.map +1 -1
- package/dist/modules/history/value-objects/history-payload.js +0 -1
- package/dist/modules/history/value-objects/history-payload.js.map +1 -1
- package/dist/modules/history/value-objects/history-subject.d.ts.map +1 -1
- package/dist/modules/history/value-objects/history-subject.js +0 -1
- package/dist/modules/history/value-objects/history-subject.js.map +1 -1
- package/dist/modules/history/value-objects/history.d.ts.map +1 -1
- package/dist/modules/history/value-objects/history.js +0 -1
- package/dist/modules/history/value-objects/history.js.map +1 -1
- package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.d.ts.map +1 -1
- package/dist/modules/preferences/command-handlers/handleSetUserLanguageCommand.js.map +1 -1
- package/dist/modules/preferences/commands/SET_USER_LANGUAGE_COMMAND.d.ts.map +1 -1
- package/dist/modules/preferences/commands/SET_USER_LANGUAGE_COMMAND.js +0 -1
- package/dist/modules/preferences/commands/SET_USER_LANGUAGE_COMMAND.js.map +1 -1
- package/dist/modules/preferences/events/USER_LANGUAGE_SET_EVENT.d.ts.map +1 -1
- package/dist/modules/preferences/events/USER_LANGUAGE_SET_EVENT.js +0 -1
- package/dist/modules/preferences/events/USER_LANGUAGE_SET_EVENT.js.map +1 -1
- package/dist/modules/preferences/index.d.ts.map +1 -1
- package/dist/modules/preferences/index.js +0 -1
- package/dist/modules/preferences/index.js.map +1 -1
- package/dist/modules/preferences/open-host-queries/user-language.d.ts.map +1 -1
- package/dist/modules/preferences/open-host-queries/user-language.js.map +1 -1
- package/dist/modules/preferences/ports/user-language-resolver.d.ts.map +1 -1
- package/dist/modules/preferences/ports/user-language-resolver.js.map +1 -1
- package/dist/modules/system/events/HOUR_HAS_PASSED_EVENT.d.ts.map +1 -1
- package/dist/modules/system/events/HOUR_HAS_PASSED_EVENT.js +0 -1
- package/dist/modules/system/events/HOUR_HAS_PASSED_EVENT.js.map +1 -1
- package/dist/modules/system/events/MINUTE_HAS_PASSED_EVENT.d.ts.map +1 -1
- package/dist/modules/system/events/MINUTE_HAS_PASSED_EVENT.js +0 -1
- package/dist/modules/system/events/MINUTE_HAS_PASSED_EVENT.js.map +1 -1
- package/dist/modules/system/events/SECURITY_VIOLATION_DETECTED_EVENT.d.ts.map +1 -1
- package/dist/modules/system/events/SECURITY_VIOLATION_DETECTED_EVENT.js +0 -1
- package/dist/modules/system/events/SECURITY_VIOLATION_DETECTED_EVENT.js.map +1 -1
- package/dist/node-env.vo.d.ts.map +1 -1
- package/dist/node-env.vo.js +0 -1
- package/dist/node-env.vo.js.map +1 -1
- package/dist/prerequisite-verifier-translations.adapter.d.ts +2 -4
- package/dist/prerequisite-verifier-translations.adapter.d.ts.map +1 -1
- package/dist/prerequisite-verifier-translations.adapter.js +1 -3
- package/dist/prerequisite-verifier-translations.adapter.js.map +1 -1
- package/dist/sitemap-changefreq.vo.d.ts.map +1 -1
- package/dist/sitemap-changefreq.vo.js +0 -1
- package/dist/sitemap-changefreq.vo.js.map +1 -1
- package/dist/translations-hono.handler.d.ts +2 -4
- package/dist/translations-hono.handler.d.ts.map +1 -1
- package/dist/translations-hono.handler.js.map +1 -1
- package/dist/translations-provider-json.adapter.d.ts +19 -0
- package/dist/translations-provider-json.adapter.d.ts.map +1 -0
- package/dist/translations-provider-json.adapter.js +21 -0
- package/dist/translations-provider-json.adapter.js.map +1 -0
- package/dist/translations-provider-noop.adapter.d.ts +8 -0
- package/dist/translations-provider-noop.adapter.d.ts.map +1 -0
- package/dist/translations-provider-noop.adapter.js +10 -0
- package/dist/translations-provider-noop.adapter.js.map +1 -0
- package/dist/translations-provider.port.d.ts +11 -0
- package/dist/translations-provider.port.d.ts.map +1 -0
- package/dist/translations-provider.port.js +2 -0
- package/dist/translations-provider.port.js.map +1 -0
- package/dist/translations.handler.d.ts +2 -6
- package/dist/translations.handler.d.ts.map +1 -1
- package/dist/translations.handler.js +1 -4
- package/dist/translations.handler.js.map +1 -1
- package/dist/translator.service.d.ts +5 -0
- package/dist/translator.service.d.ts.map +1 -0
- package/dist/translator.service.js +13 -0
- package/dist/translator.service.js.map +1 -0
- package/package.json +9 -14
- package/readme.md +4 -2
- package/src/crypto-aes-gcm.service.ts +0 -1
- package/src/index.ts +1 -2
- package/src/modules/history/event-handlers/onHistoryClearedEvent.ts +0 -1
- package/src/modules/history/event-handlers/onHistoryPopulatedEvent.ts +0 -1
- package/src/modules/history/events/HISTORY_CLEARED_EVENT.ts +0 -1
- package/src/modules/history/events/HISTORY_POPULATED_EVENT.ts +0 -1
- package/src/modules/history/index.ts +0 -1
- package/src/modules/history/ports/history-reader.ts +0 -1
- package/src/modules/history/ports/history-writer.ts +0 -1
- package/src/modules/history/value-objects/history-created-at.ts +0 -1
- package/src/modules/history/value-objects/history-operation.ts +0 -1
- package/src/modules/history/value-objects/history-payload.ts +0 -1
- package/src/modules/history/value-objects/history-subject.ts +0 -1
- package/src/modules/history/value-objects/history.ts +0 -1
- package/src/modules/preferences/command-handlers/handleSetUserLanguageCommand.ts +0 -1
- package/src/modules/preferences/commands/SET_USER_LANGUAGE_COMMAND.ts +0 -1
- package/src/modules/preferences/events/USER_LANGUAGE_SET_EVENT.ts +0 -1
- package/src/modules/preferences/index.ts +0 -1
- package/src/modules/preferences/open-host-queries/user-language.ts +0 -1
- package/src/modules/preferences/ports/user-language-resolver.ts +0 -1
- package/src/modules/system/events/HOUR_HAS_PASSED_EVENT.ts +0 -1
- package/src/modules/system/events/MINUTE_HAS_PASSED_EVENT.ts +0 -1
- package/src/modules/system/events/SECURITY_VIOLATION_DETECTED_EVENT.ts +0 -1
- package/src/node-env.vo.ts +0 -2
- package/src/prerequisite-verifier-translations.adapter.ts +5 -9
- package/src/sitemap-changefreq.vo.ts +0 -2
- package/src/translations-hono.handler.ts +2 -3
- package/src/translations-provider-json.adapter.ts +29 -0
- package/src/translations-provider-noop.adapter.ts +10 -0
- package/src/translations-provider.port.ts +13 -0
- package/src/translations.handler.ts +4 -10
- package/src/translator.service.ts +21 -0
- package/LICENSE +0 -21
- package/dist/i18n.service.d.ts +0 -25
- package/dist/i18n.service.d.ts.map +0 -1
- package/dist/i18n.service.js +0 -36
- package/dist/i18n.service.js.map +0 -1
- package/dist/mailer-resend.adapter.d.ts +0 -18
- package/dist/mailer-resend.adapter.d.ts.map +0 -1
- package/dist/mailer-resend.adapter.js +0 -31
- package/dist/mailer-resend.adapter.js.map +0 -1
- package/src/i18n.service.ts +0 -59
- package/src/mailer-resend.adapter.ts +0 -45
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type * as tools from "@bgord/tools";
|
|
2
2
|
import { createFactory } from "hono/factory";
|
|
3
|
-
import type { FileReaderJsonPort } from "./file-reader-json.port";
|
|
4
3
|
import type { HandlerHonoPort } from "./handler-hono.port";
|
|
5
4
|
import type { LanguageDetectorVariables } from "./language-detector-hono.middleware";
|
|
6
5
|
import type { Languages } from "./languages.vo";
|
|
7
|
-
import type { LoggerPort } from "./logger.port";
|
|
8
6
|
import { TranslationsHandler } from "./translations.handler";
|
|
7
|
+
import type { TranslationsProviderPort } from "./translations-provider.port";
|
|
9
8
|
|
|
10
|
-
type Dependencies = {
|
|
9
|
+
type Dependencies = { TranslationsProvider: TranslationsProviderPort };
|
|
11
10
|
|
|
12
11
|
const factory = createFactory();
|
|
13
12
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as tools from "@bgord/tools";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import type { FileReaderJsonPort } from "./file-reader-json.port";
|
|
4
|
+
import type { TranslationsProviderPort, TranslationsType } from "./translations-provider.port";
|
|
5
|
+
|
|
6
|
+
type Config = { path?: tools.DirectoryPathRelativeType };
|
|
7
|
+
type Dependencies = { FileReaderJson: FileReaderJsonPort };
|
|
8
|
+
|
|
9
|
+
export class TranslationsProviderJsonAdapter implements TranslationsProviderPort {
|
|
10
|
+
static readonly DEFAULT_PATH = v.parse(tools.DirectoryPathRelativeSchema, "infra/translations");
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
private readonly deps: Dependencies,
|
|
14
|
+
private readonly config?: Config,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
async getTranslationsFor(language: tools.LanguageType): Promise<TranslationsType> {
|
|
18
|
+
const path = tools.FilePathRelative.fromParts(
|
|
19
|
+
this.config?.path ?? TranslationsProviderJsonAdapter.DEFAULT_PATH,
|
|
20
|
+
tools.Filename.fromParts(language, "json"),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
return await this.deps.FileReaderJson.read(path);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as tools from "@bgord/tools";
|
|
2
|
+
import type { TranslationsProviderPort, TranslationsType } from "./translations-provider.port";
|
|
3
|
+
|
|
4
|
+
export class TranslationsProviderNoopAdapter implements TranslationsProviderPort {
|
|
5
|
+
constructor(private readonly translations: Record<tools.LanguageType, TranslationsType>) {}
|
|
6
|
+
|
|
7
|
+
async getTranslationsFor(language: tools.LanguageType): Promise<TranslationsType> {
|
|
8
|
+
return this.translations[language] ?? {};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as tools from "@bgord/tools";
|
|
2
|
+
|
|
3
|
+
export type TranslationsKeyType = string;
|
|
4
|
+
export type TranslationsValueType = string;
|
|
5
|
+
export type TranslationsType = Record<TranslationsKeyType, TranslationsValueType>;
|
|
6
|
+
|
|
7
|
+
export type TranslationPlaceholderType = string;
|
|
8
|
+
export type TranslationPlaceholderValueType = string | number;
|
|
9
|
+
export type TranslationVariableType = Record<TranslationPlaceholderType, TranslationPlaceholderValueType>;
|
|
10
|
+
|
|
11
|
+
export interface TranslationsProviderPort {
|
|
12
|
+
getTranslationsFor(language: tools.LanguageType): Promise<TranslationsType>;
|
|
13
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type * as tools from "@bgord/tools";
|
|
2
|
-
import type { FileReaderJsonPort } from "./file-reader-json.port";
|
|
3
|
-
import { I18n, type TranslationsType } from "./i18n.service";
|
|
4
2
|
import type { Languages } from "./languages.vo";
|
|
5
|
-
import type {
|
|
3
|
+
import type { TranslationsProviderPort, TranslationsType } from "./translations-provider.port";
|
|
6
4
|
|
|
7
|
-
type Dependencies = {
|
|
5
|
+
type Dependencies = { TranslationsProvider: TranslationsProviderPort };
|
|
8
6
|
|
|
9
7
|
export type TranslationsResult<T extends tools.LanguageType> = {
|
|
10
8
|
translations: TranslationsType;
|
|
@@ -13,17 +11,13 @@ export type TranslationsResult<T extends tools.LanguageType> = {
|
|
|
13
11
|
};
|
|
14
12
|
|
|
15
13
|
export class TranslationsHandler<T extends tools.LanguageType> {
|
|
16
|
-
private readonly I18n: I18n;
|
|
17
|
-
|
|
18
14
|
constructor(
|
|
19
15
|
private readonly config: Languages<T>,
|
|
20
16
|
private readonly deps: Dependencies,
|
|
21
|
-
) {
|
|
22
|
-
this.I18n = new I18n(this.deps);
|
|
23
|
-
}
|
|
17
|
+
) {}
|
|
24
18
|
|
|
25
19
|
async execute(language: tools.LanguageType): Promise<TranslationsResult<T>> {
|
|
26
|
-
const translations = await this.
|
|
20
|
+
const translations = await this.deps.TranslationsProvider.getTranslationsFor(language);
|
|
27
21
|
|
|
28
22
|
return { translations, language, supportedLanguages: this.config.supported };
|
|
29
23
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TranslationsKeyType,
|
|
3
|
+
TranslationsType,
|
|
4
|
+
TranslationVariableType,
|
|
5
|
+
} from "./translations-provider.port";
|
|
6
|
+
|
|
7
|
+
export class TranslatorService {
|
|
8
|
+
static use(translations: TranslationsType) {
|
|
9
|
+
return function translate(key: TranslationsKeyType, variables?: TranslationVariableType) {
|
|
10
|
+
const translation = translations[key];
|
|
11
|
+
|
|
12
|
+
if (!translation) return key;
|
|
13
|
+
if (!variables) return translation;
|
|
14
|
+
|
|
15
|
+
return Object.entries(variables).reduce(
|
|
16
|
+
(result, [placeholder, value]) => result.replaceAll(`{{${placeholder}}}`, String(value)),
|
|
17
|
+
translation,
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Bartosz Gordon
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/i18n.service.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as tools from "@bgord/tools";
|
|
2
|
-
import * as v from "valibot";
|
|
3
|
-
import type { FileReaderJsonPort } from "./file-reader-json.port";
|
|
4
|
-
import type { LoggerPort } from "./logger.port";
|
|
5
|
-
export type TranslationsKeyType = string;
|
|
6
|
-
export type TranslationsValueType = string;
|
|
7
|
-
export type TranslationsType = Record<TranslationsKeyType, TranslationsValueType>;
|
|
8
|
-
export type TranslationPlaceholderType = string;
|
|
9
|
-
export type TranslationPlaceholderValueType = string | number;
|
|
10
|
-
export type TranslationVariableType = Record<TranslationPlaceholderType, TranslationPlaceholderValueType>;
|
|
11
|
-
type Dependencies = {
|
|
12
|
-
FileReaderJson: FileReaderJsonPort;
|
|
13
|
-
Logger: LoggerPort;
|
|
14
|
-
};
|
|
15
|
-
export declare class I18n {
|
|
16
|
-
private readonly deps;
|
|
17
|
-
private translationsPath;
|
|
18
|
-
static DEFAULT_TRANSLATIONS_PATH: string & v.Brand<"DirectoryPathRelativeSchema">;
|
|
19
|
-
constructor(deps: Dependencies, translationsPath?: tools.DirectoryPathRelativeType);
|
|
20
|
-
getTranslations(language: tools.LanguageType): Promise<TranslationsType>;
|
|
21
|
-
useTranslations(translations: TranslationsType): (key: TranslationsKeyType, variables?: TranslationVariableType) => string;
|
|
22
|
-
getTranslationPathForLanguage(language: tools.LanguageType): tools.FilePathRelative;
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=i18n.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.service.d.ts","sourceRoot":"","sources":["../src/i18n.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACzC,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAC3C,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,CAAC,CAAC;AAClF,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAChD,MAAM,MAAM,+BAA+B,GAAG,MAAM,GAAG,MAAM,CAAC;AAC9D,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,0BAA0B,EAAE,+BAA+B,CAAC,CAAC;AAE1G,KAAK,YAAY,GAAG;IAAE,cAAc,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE/E,qBAAa,IAAI;IAIb,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,gBAAgB;IAJ1B,MAAM,CAAC,yBAAyB,kDAAoE;IAEpG,YACmB,IAAI,EAAE,YAAY,EAC3B,gBAAgB,GAAE,KAAK,CAAC,yBAA0D,EACxF;IAEE,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAE7E;IAED,eAAe,CAAC,YAAY,EAAE,gBAAgB,SAGb,mBAAmB,cAAc,uBAAuB,YAqBxF;IAED,6BAA6B,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,gBAAgB,CAKlF;CACF"}
|
package/dist/i18n.service.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as tools from "@bgord/tools";
|
|
2
|
-
import * as v from "valibot";
|
|
3
|
-
export class I18n {
|
|
4
|
-
deps;
|
|
5
|
-
translationsPath;
|
|
6
|
-
static DEFAULT_TRANSLATIONS_PATH = v.parse(tools.DirectoryPathRelativeSchema, "infra/translations");
|
|
7
|
-
constructor(deps, translationsPath = I18n.DEFAULT_TRANSLATIONS_PATH) {
|
|
8
|
-
this.deps = deps;
|
|
9
|
-
this.translationsPath = translationsPath;
|
|
10
|
-
}
|
|
11
|
-
async getTranslations(language) {
|
|
12
|
-
return this.deps.FileReaderJson.read(this.getTranslationPathForLanguage(language));
|
|
13
|
-
}
|
|
14
|
-
useTranslations(translations) {
|
|
15
|
-
const that = this;
|
|
16
|
-
return function translate(key, variables) {
|
|
17
|
-
const translation = translations[key];
|
|
18
|
-
if (!translation) {
|
|
19
|
-
that.deps.Logger.warn({
|
|
20
|
-
message: "Missing translation key",
|
|
21
|
-
component: "infra",
|
|
22
|
-
operation: "translations",
|
|
23
|
-
metadata: { key },
|
|
24
|
-
});
|
|
25
|
-
return key;
|
|
26
|
-
}
|
|
27
|
-
if (!variables)
|
|
28
|
-
return translation;
|
|
29
|
-
return Object.entries(variables).reduce((result, [placeholder, value]) => result.replaceAll(`{{${placeholder}}}`, String(value)), translation);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
getTranslationPathForLanguage(language) {
|
|
33
|
-
return tools.FilePathRelative.fromParts(this.translationsPath, tools.Filename.fromParts(language, "json"));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=i18n.service.js.map
|
package/dist/i18n.service.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.service.js","sourceRoot":"","sources":["../src/i18n.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAa7B,MAAM,OAAO,IAAI;IAII,IAAI;IACb,gBAAgB;IAJ1B,MAAM,CAAC,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,2BAA2B,EAAE,oBAAoB,CAAC,CAAC;IAEpG,YACmB,IAAkB,EAC3B,gBAAgB,GAAoC,IAAI,CAAC,yBAAyB;oBADzE,IAAI;gCACb,gBAAgB;IACvB,CAAC;IAEJ,KAAK,CAAC,eAAe,CAAC,QAA4B;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,eAAe,CAAC,YAA8B;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,OAAO,SAAS,SAAS,CAAC,GAAwB,EAAE,SAAmC;YACrF,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;YAEtC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;oBACpB,OAAO,EAAE,yBAAyB;oBAClC,SAAS,EAAE,OAAO;oBAClB,SAAS,EAAE,cAAc;oBACzB,QAAQ,EAAE,EAAE,GAAG,EAAE;iBAClB,CAAC,CAAC;gBAEH,OAAO,GAAG,CAAC;YACb,CAAC;YAED,IAAI,CAAC,SAAS;gBAAE,OAAO,WAAW,CAAC;YAEnC,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CACrC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,WAAW,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EACxF,WAAW,CACZ,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,6BAA6B,CAAC,QAA4B;QACxD,OAAO,KAAK,CAAC,gBAAgB,CAAC,SAAS,CACrC,IAAI,CAAC,gBAAgB,EACrB,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAC3C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { MailerPort } from "./mailer.port";
|
|
2
|
-
import type { MailerTemplate } from "./mailer-template.vo";
|
|
3
|
-
export declare const MailerResendAdapterError: {
|
|
4
|
-
MissingDependency: string;
|
|
5
|
-
};
|
|
6
|
-
type Config = {
|
|
7
|
-
key: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class MailerResendAdapter implements MailerPort {
|
|
10
|
-
private readonly transport;
|
|
11
|
-
private static readonly importer;
|
|
12
|
-
private constructor();
|
|
13
|
-
static build(config: Config): Promise<MailerResendAdapter>;
|
|
14
|
-
send(template: MailerTemplate): Promise<void>;
|
|
15
|
-
verify(): Promise<boolean>;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=mailer-resend.adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mailer-resend.adapter.d.ts","sourceRoot":"","sources":["../src/mailer-resend.adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,eAAO,MAAM,wBAAwB;IACnC,iBAAiB;CAClB,CAAC;AAEF,KAAK,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAG9B,qBAAa,mBAAoB,YAAW,UAAU;IAMhC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAL9C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAG9B;IAEF,OAAO,eAAmD;IAE1D,OAAa,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAI/D;IAEK,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAalD;IAEK,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAE/B;CACF"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DynamicImport } from "./dynamic-import.service";
|
|
2
|
-
export const MailerResendAdapterError = {
|
|
3
|
-
MissingDependency: "mailer.resend.adapter.error.missing.dependency",
|
|
4
|
-
};
|
|
5
|
-
export class MailerResendAdapter {
|
|
6
|
-
transport;
|
|
7
|
-
static importer = DynamicImport.for("resend", MailerResendAdapterError.MissingDependency);
|
|
8
|
-
constructor(transport) {
|
|
9
|
-
this.transport = transport;
|
|
10
|
-
}
|
|
11
|
-
static async build(config) {
|
|
12
|
-
const library = await MailerResendAdapter.importer.resolve();
|
|
13
|
-
return new MailerResendAdapter(new library.Resend(config.key));
|
|
14
|
-
}
|
|
15
|
-
async send(template) {
|
|
16
|
-
const result = await this.transport.emails.send({
|
|
17
|
-
...template.config,
|
|
18
|
-
...template.message,
|
|
19
|
-
attachments: template.attachments,
|
|
20
|
-
});
|
|
21
|
-
if (!result.error)
|
|
22
|
-
return;
|
|
23
|
-
const error = new Error(result.error.message);
|
|
24
|
-
error.name = result.error.name;
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
async verify() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=mailer-resend.adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mailer-resend.adapter.js","sourceRoot":"","sources":["../src/mailer-resend.adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAIzD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,iBAAiB,EAAE,gDAAgD;CACpE,CAAC;AAKF,MAAM,OAAO,mBAAmB;IAMO,SAAS;IALtC,MAAM,CAAU,QAAQ,GAAG,aAAa,CAAC,GAAG,CAClD,QAAQ,EACR,wBAAwB,CAAC,iBAAiB,CAC3C,CAAC;IAEF,YAAqC,SAAiB;yBAAjB,SAAS;IAAW,CAAC;IAE1D,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAc;QAC/B,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAE7D,OAAO,IAAI,mBAAmB,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAwB;QACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;YAC9C,GAAG,QAAQ,CAAC,MAAM;YAClB,GAAG,QAAQ,CAAC,OAAO;YACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK;YAAE,OAAO;QAE1B,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QAE/B,MAAM,KAAK,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/src/i18n.service.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as tools from "@bgord/tools";
|
|
2
|
-
import * as v from "valibot";
|
|
3
|
-
import type { FileReaderJsonPort } from "./file-reader-json.port";
|
|
4
|
-
import type { LoggerPort } from "./logger.port";
|
|
5
|
-
|
|
6
|
-
export type TranslationsKeyType = string;
|
|
7
|
-
export type TranslationsValueType = string;
|
|
8
|
-
export type TranslationsType = Record<TranslationsKeyType, TranslationsValueType>;
|
|
9
|
-
export type TranslationPlaceholderType = string;
|
|
10
|
-
export type TranslationPlaceholderValueType = string | number;
|
|
11
|
-
export type TranslationVariableType = Record<TranslationPlaceholderType, TranslationPlaceholderValueType>;
|
|
12
|
-
|
|
13
|
-
type Dependencies = { FileReaderJson: FileReaderJsonPort; Logger: LoggerPort };
|
|
14
|
-
|
|
15
|
-
export class I18n {
|
|
16
|
-
static DEFAULT_TRANSLATIONS_PATH = v.parse(tools.DirectoryPathRelativeSchema, "infra/translations");
|
|
17
|
-
|
|
18
|
-
constructor(
|
|
19
|
-
private readonly deps: Dependencies,
|
|
20
|
-
private translationsPath: tools.DirectoryPathRelativeType = I18n.DEFAULT_TRANSLATIONS_PATH,
|
|
21
|
-
) {}
|
|
22
|
-
|
|
23
|
-
async getTranslations(language: tools.LanguageType): Promise<TranslationsType> {
|
|
24
|
-
return this.deps.FileReaderJson.read(this.getTranslationPathForLanguage(language));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
useTranslations(translations: TranslationsType) {
|
|
28
|
-
const that = this;
|
|
29
|
-
|
|
30
|
-
return function translate(key: TranslationsKeyType, variables?: TranslationVariableType) {
|
|
31
|
-
const translation = translations[key];
|
|
32
|
-
|
|
33
|
-
if (!translation) {
|
|
34
|
-
that.deps.Logger.warn({
|
|
35
|
-
message: "Missing translation key",
|
|
36
|
-
component: "infra",
|
|
37
|
-
operation: "translations",
|
|
38
|
-
metadata: { key },
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return key;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!variables) return translation;
|
|
45
|
-
|
|
46
|
-
return Object.entries(variables).reduce(
|
|
47
|
-
(result, [placeholder, value]) => result.replaceAll(`{{${placeholder}}}`, String(value)),
|
|
48
|
-
translation,
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
getTranslationPathForLanguage(language: tools.LanguageType): tools.FilePathRelative {
|
|
54
|
-
return tools.FilePathRelative.fromParts(
|
|
55
|
-
this.translationsPath,
|
|
56
|
-
tools.Filename.fromParts(language, "json"),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { Resend } from "resend";
|
|
2
|
-
import { DynamicImport } from "./dynamic-import.service";
|
|
3
|
-
import type { MailerPort } from "./mailer.port";
|
|
4
|
-
import type { MailerTemplate } from "./mailer-template.vo";
|
|
5
|
-
|
|
6
|
-
export const MailerResendAdapterError = {
|
|
7
|
-
MissingDependency: "mailer.resend.adapter.error.missing.dependency",
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type Config = { key: string };
|
|
11
|
-
type ResendLibrary = typeof import("resend");
|
|
12
|
-
|
|
13
|
-
export class MailerResendAdapter implements MailerPort {
|
|
14
|
-
private static readonly importer = DynamicImport.for<ResendLibrary>(
|
|
15
|
-
"resend",
|
|
16
|
-
MailerResendAdapterError.MissingDependency,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
private constructor(private readonly transport: Resend) {}
|
|
20
|
-
|
|
21
|
-
static async build(config: Config): Promise<MailerResendAdapter> {
|
|
22
|
-
const library = await MailerResendAdapter.importer.resolve();
|
|
23
|
-
|
|
24
|
-
return new MailerResendAdapter(new library.Resend(config.key));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async send(template: MailerTemplate): Promise<void> {
|
|
28
|
-
const result = await this.transport.emails.send({
|
|
29
|
-
...template.config,
|
|
30
|
-
...template.message,
|
|
31
|
-
attachments: template.attachments,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (!result.error) return;
|
|
35
|
-
|
|
36
|
-
const error = new Error(result.error.message);
|
|
37
|
-
error.name = result.error.name;
|
|
38
|
-
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async verify(): Promise<boolean> {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|