@tstdl/base 0.90.45 → 0.90.47
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/examples/api/basic-overview.js +4 -4
- package/examples/api/streaming.js +1 -1
- package/mail/clients/nodemailer.mail-client.d.ts +1 -2
- package/mail/clients/nodemailer.mail-client.js +3 -3
- package/mail/mail.service.d.ts +2 -6
- package/mail/mail.service.js +18 -16
- package/package.json +8 -10
- package/utils/timing.js +1 -1
|
@@ -38,11 +38,11 @@ const users = [
|
|
|
38
38
|
{ id: 3, name: 'Bob' }
|
|
39
39
|
];
|
|
40
40
|
const usersApiDefinition = defineApi({
|
|
41
|
-
resource: 'users',
|
|
41
|
+
resource: 'users', // /api/:version/users
|
|
42
42
|
endpoints: {
|
|
43
43
|
load: {
|
|
44
|
-
method: 'GET',
|
|
45
|
-
resource: ':id',
|
|
44
|
+
method: 'GET', // GET is default
|
|
45
|
+
resource: ':id', // => /api/v1/users/:id
|
|
46
46
|
version: 1,
|
|
47
47
|
parameters: object({
|
|
48
48
|
id: number({ coerce: true })
|
|
@@ -54,7 +54,7 @@ const usersApiDefinition = defineApi({
|
|
|
54
54
|
},
|
|
55
55
|
delete: {
|
|
56
56
|
method: 'DELETE',
|
|
57
|
-
resource: ':id',
|
|
57
|
+
resource: ':id', // => /api/v1/users/:id
|
|
58
58
|
parameters: object({
|
|
59
59
|
id: number({ coerce: true })
|
|
60
60
|
}),
|
|
@@ -26,7 +26,7 @@ import { Agent } from 'undici';
|
|
|
26
26
|
configureTstdl();
|
|
27
27
|
const logger = getGlobalInjector().resolve(CORE_LOGGER);
|
|
28
28
|
const streamingApiDefinition = defineApi({
|
|
29
|
-
resource: 'streams',
|
|
29
|
+
resource: 'streams', // /api/:version/users
|
|
30
30
|
endpoints: {
|
|
31
31
|
echo: {
|
|
32
32
|
method: 'POST',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Disposable } from '../../disposable/disposable.js';
|
|
2
|
-
import
|
|
3
|
-
import { MailClient } from '../mail.client.js';
|
|
2
|
+
import { MailClient, MailClientConfig } from '../mail.client.js';
|
|
4
3
|
import type { MailData, MailSendResult } from '../models/index.js';
|
|
5
4
|
export declare class NodemailerMailClient extends MailClient implements Disposable {
|
|
6
5
|
#private;
|
|
@@ -5,14 +5,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { createTransport } from 'nodemailer';
|
|
8
|
-
import { Singleton, injectArgument } from '../../injector/index.js';
|
|
8
|
+
import { Singleton, inject, injectArgument } from '../../injector/index.js';
|
|
9
9
|
import { Injector } from '../../injector/injector.js';
|
|
10
10
|
import { assertDefined, isUndefined } from '../../utils/type-guards.js';
|
|
11
|
-
import { MailClient } from '../mail.client.js';
|
|
11
|
+
import { MailClient, MailClientConfig } from '../mail.client.js';
|
|
12
12
|
let NodemailerMailClient = class NodemailerMailClient extends MailClient {
|
|
13
13
|
#stack = new DisposableStack();
|
|
14
14
|
#transports = new Map();
|
|
15
|
-
#defaultClientConfig = injectArgument(this, { optional: true });
|
|
15
|
+
#defaultClientConfig = injectArgument(this, { optional: true }) ?? inject(MailClientConfig, undefined, { optional: true });
|
|
16
16
|
[Symbol.dispose]() {
|
|
17
17
|
this.#stack.dispose();
|
|
18
18
|
}
|
package/mail/mail.service.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { TypedOmit } from '../types.js';
|
|
2
|
-
import
|
|
2
|
+
import { MailClientConfig } from './mail.client.js';
|
|
3
3
|
import type { MailData, MailSendResult, MailTemplate } from './models/index.js';
|
|
4
4
|
export declare class MailService {
|
|
5
|
-
private
|
|
6
|
-
private readonly templateService;
|
|
7
|
-
private readonly mailLogRepository;
|
|
8
|
-
private readonly defaultData;
|
|
9
|
-
private readonly logger;
|
|
5
|
+
#private;
|
|
10
6
|
send(mailData: MailData, clientConfig?: MailClientConfig): Promise<MailSendResult>;
|
|
11
7
|
/** @deprecated internal */
|
|
12
8
|
send(mailData: MailData, clientConfig?: MailClientConfig, templateName?: string): Promise<MailSendResult>;
|
package/mail/mail.service.js
CHANGED
|
@@ -9,22 +9,24 @@ import { Logger } from '../logger/index.js';
|
|
|
9
9
|
import { TemplateService } from '../templates/template.service.js';
|
|
10
10
|
import { currentTimestamp } from '../utils/date-time.js';
|
|
11
11
|
import { formatError } from '../utils/format-error.js';
|
|
12
|
-
import { isDefined } from '../utils/type-guards.js';
|
|
13
|
-
import { MailClient } from './mail.client.js';
|
|
12
|
+
import { assertDefined, isDefined } from '../utils/type-guards.js';
|
|
13
|
+
import { MailClient, MailClientConfig } from './mail.client.js';
|
|
14
14
|
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
15
15
|
import { MAIL_DEFAULT_DATA } from './tokens.js';
|
|
16
16
|
let MailService = class MailService {
|
|
17
|
-
mailClient = inject(MailClient);
|
|
18
|
-
templateService = inject(TemplateService);
|
|
19
|
-
mailLogRepository = inject(MailLogRepository, undefined, { optional: true });
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
#mailClient = inject(MailClient);
|
|
18
|
+
#templateService = inject(TemplateService);
|
|
19
|
+
#mailLogRepository = inject(MailLogRepository, undefined, { optional: true });
|
|
20
|
+
#defaultClientConfig = inject(MailClientConfig, undefined, { optional: true });
|
|
21
|
+
#defaultData = inject(MAIL_DEFAULT_DATA, undefined, { optional: true });
|
|
22
|
+
#logger = inject(Logger, 'MailService');
|
|
22
23
|
async send(mailData, clientConfigOrTemplateName, templateNameOrNothing) {
|
|
23
|
-
const clientConfig = (typeof clientConfigOrTemplateName == 'object') ? clientConfigOrTemplateName :
|
|
24
|
+
const clientConfig = (typeof clientConfigOrTemplateName == 'object') ? clientConfigOrTemplateName : this.#defaultClientConfig;
|
|
24
25
|
const templateName = (typeof clientConfigOrTemplateName == 'object') ? templateNameOrNothing : clientConfigOrTemplateName;
|
|
25
|
-
|
|
26
|
+
assertDefined(clientConfig, 'No mail client config provided.');
|
|
27
|
+
const data = { ...this.#defaultData, ...mailData };
|
|
26
28
|
let mailLog;
|
|
27
|
-
if (isDefined(this
|
|
29
|
+
if (isDefined(this.#mailLogRepository)) {
|
|
28
30
|
const log = {
|
|
29
31
|
timestamp: currentTimestamp(),
|
|
30
32
|
template: templateName ?? null,
|
|
@@ -32,29 +34,29 @@ let MailService = class MailService {
|
|
|
32
34
|
sendResult: null,
|
|
33
35
|
errors: null
|
|
34
36
|
};
|
|
35
|
-
mailLog = await this
|
|
37
|
+
mailLog = await this.#mailLogRepository.insert(log);
|
|
36
38
|
}
|
|
37
39
|
try {
|
|
38
|
-
const result = await this
|
|
40
|
+
const result = await this.#mailClient.send(data, clientConfig);
|
|
39
41
|
if (isDefined(mailLog)) {
|
|
40
|
-
await this
|
|
42
|
+
await this.#mailLogRepository.patch(mailLog, { sendResult: result });
|
|
41
43
|
}
|
|
42
44
|
return result;
|
|
43
45
|
}
|
|
44
46
|
catch (error) {
|
|
45
47
|
try {
|
|
46
48
|
if (isDefined(mailLog)) {
|
|
47
|
-
await this
|
|
49
|
+
await this.#mailLogRepository.patch(mailLog, { errors: [formatError(error)] });
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
catch (logError) {
|
|
51
|
-
this
|
|
53
|
+
this.#logger.error(logError);
|
|
52
54
|
}
|
|
53
55
|
throw error;
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
async sendTemplate(keyOrTemplate, mailData, templateContext, clientConfig) {
|
|
57
|
-
const { name, fields: { subject, html, text } } = await this
|
|
59
|
+
const { name, fields: { subject, html, text } } = await this.#templateService.render(keyOrTemplate, templateContext);
|
|
58
60
|
const fullMailData = { ...mailData, subject, content: { html, text } };
|
|
59
61
|
return this.send(fullMailData, clientConfig, name);
|
|
60
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.90.
|
|
3
|
+
"version": "0.90.47",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
"./tsconfig.json": "./tsconfig.json",
|
|
23
|
-
|
|
24
23
|
".": "./index.js",
|
|
25
24
|
"./environment": "./environment.js",
|
|
26
25
|
"./interfaces": "./interfaces.js",
|
|
@@ -30,7 +29,6 @@
|
|
|
30
29
|
"./tokens": "./tokens.js",
|
|
31
30
|
"./types": "./types.js",
|
|
32
31
|
"./web-types": "./web-types.js",
|
|
33
|
-
|
|
34
32
|
"./api": "./api/index.js",
|
|
35
33
|
"./application": "./application/index.js",
|
|
36
34
|
"./authentication": "./authentication/index.js",
|
|
@@ -110,7 +108,7 @@
|
|
|
110
108
|
"luxon": "^3.4",
|
|
111
109
|
"reflect-metadata": "^0.1",
|
|
112
110
|
"rxjs": "^7.8",
|
|
113
|
-
"type-fest": "
|
|
111
|
+
"type-fest": "4.7"
|
|
114
112
|
},
|
|
115
113
|
"devDependencies": {
|
|
116
114
|
"@mxssfd/typedoc-theme": "1.1",
|
|
@@ -121,17 +119,17 @@
|
|
|
121
119
|
"@types/mjml": "4.7",
|
|
122
120
|
"@types/node": "20",
|
|
123
121
|
"@types/nodemailer": "6.4",
|
|
124
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
125
|
-
"@typescript-eslint/parser": "6.
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "6.12",
|
|
123
|
+
"@typescript-eslint/parser": "6.12",
|
|
126
124
|
"concurrently": "8.2",
|
|
127
125
|
"esbuild": "0.19",
|
|
128
|
-
"eslint": "8.
|
|
126
|
+
"eslint": "8.54",
|
|
129
127
|
"eslint-import-resolver-typescript": "3.6",
|
|
130
128
|
"eslint-plugin-import": "2.29",
|
|
131
129
|
"tsc-alias": "1.8",
|
|
132
130
|
"typedoc": "0.25",
|
|
133
131
|
"typedoc-plugin-missing-exports": "2.1",
|
|
134
|
-
"typescript": "5.
|
|
132
|
+
"typescript": "5.3"
|
|
135
133
|
},
|
|
136
134
|
"peerDependencies": {
|
|
137
135
|
"@elastic/elasticsearch": "^8.10",
|
|
@@ -146,9 +144,9 @@
|
|
|
146
144
|
"koa": "^2.14",
|
|
147
145
|
"minio": "^7.1",
|
|
148
146
|
"mjml": "^4.14",
|
|
149
|
-
"mongodb": "^6.
|
|
147
|
+
"mongodb": "^6.3",
|
|
150
148
|
"nodemailer": "^6.9",
|
|
151
|
-
"playwright": "^1.
|
|
149
|
+
"playwright": "^1.40",
|
|
152
150
|
"preact": "^10.19",
|
|
153
151
|
"preact-render-to-string": "^6.3",
|
|
154
152
|
"undici": "^5.27",
|
package/utils/timing.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function timeoutUntil(timestamp) {
|
|
|
21
21
|
/** timeout for specified duration */
|
|
22
22
|
export async function cancelableTimeout(milliseconds, cancelSignal) {
|
|
23
23
|
return firstValueFrom(race([
|
|
24
|
-
timer(milliseconds).pipe(map(() => false)),
|
|
24
|
+
timer(milliseconds).pipe(map(() => false)), // eslint-disable-line @typescript-eslint/no-unsafe-argument
|
|
25
25
|
cancelSignal.set$.pipe(map(() => true)) // eslint-disable-line @typescript-eslint/no-unsafe-argument
|
|
26
26
|
]));
|
|
27
27
|
}
|