@tstdl/base 0.90.24 → 0.90.26
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/authentication/server/authentication.api-controller.d.ts +7 -2
- package/authentication/server/authentication.api-controller.js +11 -1
- package/examples/mail/basic.js +1 -1
- package/mail/clients/nodemailer.mail-client.d.ts +8 -5
- package/mail/clients/nodemailer.mail-client.js +25 -19
- package/mail/mail.client.d.ts +1 -1
- package/mail/mail.service.d.ts +1 -6
- package/mail/mail.service.js +8 -28
- package/mail/module.d.ts +3 -3
- package/mail/module.js +4 -4
- package/package.json +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ApiController, ApiRequestContext, ApiServerResult } from '../../api/types.js';
|
|
2
|
-
import
|
|
2
|
+
import { HttpServerResponse } from '../../http/server/index.js';
|
|
3
|
+
import type { ObjectSchemaOrType, SchemaTestable } from '../../schema/index.js';
|
|
4
|
+
import type { Record, Type } from '../../types.js';
|
|
3
5
|
import type { AuthenticationApiDefinition } from '../authentication.api.js';
|
|
6
|
+
import type { TokenResult } from './authentication.service.js';
|
|
4
7
|
import { AuthenticationService } from './authentication.service.js';
|
|
5
8
|
export declare class AuthenticationApiController<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData extends Record> implements ApiController<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>> {
|
|
6
9
|
readonly authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
|
|
@@ -12,5 +15,7 @@ export declare class AuthenticationApiController<AdditionalTokenPayload extends
|
|
|
12
15
|
resetSecret({ parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'resetSecret'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'resetSecret'>>;
|
|
13
16
|
checkSecret({ parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'checkSecret'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'checkSecret'>>;
|
|
14
17
|
timestamp(): ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'timestamp'>;
|
|
15
|
-
|
|
18
|
+
protected getTokenResponse({ token, jsonToken, refreshToken }: TokenResult<AdditionalTokenPayload>): HttpServerResponse;
|
|
16
19
|
}
|
|
20
|
+
export declare function getAuthenticationApiController<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData extends Record>(// eslint-disable-line @typescript-eslint/explicit-function-return-type
|
|
21
|
+
additionalTokenPayloadSchema: ObjectSchemaOrType<AdditionalTokenPayload>, authenticationDataSchema: SchemaTestable<AuthenticationData>, additionalInitSecretResetData: ObjectSchemaOrType<AdditionalInitSecretResetData>): Type<AuthenticationApiController<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>>;
|
|
@@ -11,7 +11,7 @@ import { apiController } from '../../api/server/index.js';
|
|
|
11
11
|
import { InvalidCredentialsError } from '../../errors/invalid-credentials.error.js';
|
|
12
12
|
import { HttpServerResponse } from '../../http/server/index.js';
|
|
13
13
|
import { currentTimestamp } from '../../utils/date-time.js';
|
|
14
|
-
import { authenticationApiDefinition } from '../authentication.api.js';
|
|
14
|
+
import { authenticationApiDefinition, getAuthenticationApiDefinition } from '../authentication.api.js';
|
|
15
15
|
import { AuthenticationService } from './authentication.service.js';
|
|
16
16
|
import { tryGetAuthorizationTokenStringFromRequest } from './helper.js';
|
|
17
17
|
const cookieBaseOptions = { path: '/', httpOnly: true, secure: true, sameSite: 'strict' };
|
|
@@ -94,3 +94,13 @@ AuthenticationApiController = __decorate([
|
|
|
94
94
|
__metadata("design:paramtypes", [AuthenticationService])
|
|
95
95
|
], AuthenticationApiController);
|
|
96
96
|
export { AuthenticationApiController };
|
|
97
|
+
export function getAuthenticationApiController(// eslint-disable-line @typescript-eslint/explicit-function-return-type
|
|
98
|
+
additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetData) {
|
|
99
|
+
const apiDefinition = getAuthenticationApiDefinition(additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetData);
|
|
100
|
+
let KfinAuthenticationApi = class KfinAuthenticationApi extends AuthenticationApiController {
|
|
101
|
+
};
|
|
102
|
+
KfinAuthenticationApi = __decorate([
|
|
103
|
+
apiController(apiDefinition)
|
|
104
|
+
], KfinAuthenticationApi);
|
|
105
|
+
return KfinAuthenticationApi;
|
|
106
|
+
}
|
package/examples/mail/basic.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Disposable } from '../../disposable/disposable.js';
|
|
2
|
+
import type { MailClientConfig } from '../mail.client.js';
|
|
3
|
+
import { MailClient } from '../mail.client.js';
|
|
2
4
|
import type { MailData, MailSendResult } from '../models/index.js';
|
|
3
|
-
export declare class NodemailerMailClient extends MailClient {
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
send(data: MailData): Promise<MailSendResult>;
|
|
5
|
+
export declare class NodemailerMailClient extends MailClient implements Disposable {
|
|
6
|
+
#private;
|
|
7
|
+
[Symbol.dispose](): void;
|
|
8
|
+
send(data: MailData, clientConfig?: MailClientConfig): Promise<MailSendResult>;
|
|
9
|
+
private getTransport;
|
|
7
10
|
}
|
|
8
11
|
/**
|
|
9
12
|
* @param register whether to register for {@link MailClient}
|
|
@@ -4,26 +4,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
7
|
import { createTransport } from 'nodemailer';
|
|
14
|
-
import {
|
|
8
|
+
import { Singleton, injectArgument } from '../../injector/index.js';
|
|
15
9
|
import { Injector } from '../../injector/injector.js';
|
|
16
|
-
import { isUndefined } from '../../utils/type-guards.js';
|
|
17
|
-
import { MailClient
|
|
10
|
+
import { assertDefined, isUndefined } from '../../utils/type-guards.js';
|
|
11
|
+
import { MailClient } from '../mail.client.js';
|
|
18
12
|
let NodemailerMailClient = class NodemailerMailClient extends MailClient {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
13
|
+
#stack = new DisposableStack();
|
|
14
|
+
#transports = new Map();
|
|
15
|
+
#defaultClientConfig = injectArgument(this, { optional: true });
|
|
16
|
+
[Symbol.dispose]() {
|
|
17
|
+
this.#stack.dispose();
|
|
24
18
|
}
|
|
25
|
-
async send(data) {
|
|
26
|
-
const
|
|
19
|
+
async send(data, clientConfig) {
|
|
20
|
+
const config = clientConfig ?? this.#defaultClientConfig;
|
|
21
|
+
assertDefined(config, 'No mail client config provided.');
|
|
22
|
+
const transport = this.getTransport(config);
|
|
23
|
+
const result = await transport.sendMail({
|
|
27
24
|
from: data.from,
|
|
28
25
|
sender: data.sender,
|
|
29
26
|
to: data.to,
|
|
@@ -44,11 +41,20 @@ let NodemailerMailClient = class NodemailerMailClient extends MailClient {
|
|
|
44
41
|
pending: result.pending
|
|
45
42
|
};
|
|
46
43
|
}
|
|
44
|
+
getTransport(config) {
|
|
45
|
+
const options = convertConfig(config);
|
|
46
|
+
const optionsJson = JSON.stringify(options);
|
|
47
|
+
if (this.#transports.has(optionsJson)) {
|
|
48
|
+
return this.#transports.get(optionsJson);
|
|
49
|
+
}
|
|
50
|
+
const transport = createTransport(options);
|
|
51
|
+
this.#transports.set(optionsJson, transport);
|
|
52
|
+
this.#stack.adopt(transport, () => transport.close());
|
|
53
|
+
return transport;
|
|
54
|
+
}
|
|
47
55
|
};
|
|
48
56
|
NodemailerMailClient = __decorate([
|
|
49
|
-
Singleton()
|
|
50
|
-
__param(0, InjectArg()),
|
|
51
|
-
__metadata("design:paramtypes", [MailClientConfig])
|
|
57
|
+
Singleton()
|
|
52
58
|
], NodemailerMailClient);
|
|
53
59
|
export { NodemailerMailClient };
|
|
54
60
|
function convertConfig(config) {
|
package/mail/mail.client.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ export declare class MailClientConfig {
|
|
|
13
13
|
}
|
|
14
14
|
export declare abstract class MailClient implements Resolvable<MailClientConfig> {
|
|
15
15
|
readonly [resolveArgumentType]: MailClientConfig;
|
|
16
|
-
abstract send(data: MailData): Promise<MailSendResult>;
|
|
16
|
+
abstract send(data: MailData, clientConfig?: MailClientConfig): Promise<MailSendResult>;
|
|
17
17
|
}
|
package/mail/mail.service.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { Logger } from '../logger/index.js';
|
|
2
|
-
import { TemplateService } from '../templates/template.service.js';
|
|
3
1
|
import type { TypedOmit } from '../types.js';
|
|
4
|
-
import {
|
|
5
|
-
import { MailClient } from './mail.client.js';
|
|
6
|
-
import type { DefaultMailData, MailData, MailSendResult, MailTemplate } from './models/index.js';
|
|
2
|
+
import type { MailData, MailSendResult, MailTemplate } from './models/index.js';
|
|
7
3
|
export declare class MailService {
|
|
8
4
|
private readonly mailClient;
|
|
9
5
|
private readonly templateService;
|
|
10
6
|
private readonly mailLogRepository;
|
|
11
7
|
private readonly defaultData;
|
|
12
8
|
private readonly logger;
|
|
13
|
-
constructor(mailClient: MailClient, templateService: TemplateService, mailLogRepository: MailLogRepository | undefined, logger: Logger, defaultData: DefaultMailData | undefined);
|
|
14
9
|
send(mailData: MailData): Promise<MailSendResult>;
|
|
15
10
|
/** @deprecated internal */
|
|
16
11
|
send(mailData: MailData, templateName?: string): Promise<MailSendResult>;
|
package/mail/mail.service.js
CHANGED
|
@@ -4,34 +4,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { Inject, Optional, ResolveArg, Singleton } from '../injector/index.js';
|
|
7
|
+
import { Singleton, inject } from '../injector/index.js';
|
|
14
8
|
import { Logger } from '../logger/index.js';
|
|
15
9
|
import { TemplateService } from '../templates/template.service.js';
|
|
16
10
|
import { currentTimestamp } from '../utils/date-time.js';
|
|
17
11
|
import { formatError } from '../utils/format-error.js';
|
|
18
12
|
import { isDefined } from '../utils/type-guards.js';
|
|
19
|
-
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
20
13
|
import { MailClient } from './mail.client.js';
|
|
14
|
+
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
21
15
|
import { MAIL_DEFAULT_DATA } from './tokens.js';
|
|
22
16
|
let MailService = class MailService {
|
|
23
|
-
mailClient;
|
|
24
|
-
templateService;
|
|
25
|
-
mailLogRepository;
|
|
26
|
-
defaultData;
|
|
27
|
-
logger;
|
|
28
|
-
constructor(mailClient, templateService, mailLogRepository, logger, defaultData) {
|
|
29
|
-
this.mailClient = mailClient;
|
|
30
|
-
this.templateService = templateService;
|
|
31
|
-
this.mailLogRepository = mailLogRepository;
|
|
32
|
-
this.defaultData = defaultData ?? {};
|
|
33
|
-
this.logger = logger;
|
|
34
|
-
}
|
|
17
|
+
mailClient = inject(MailClient);
|
|
18
|
+
templateService = inject(TemplateService);
|
|
19
|
+
mailLogRepository = inject(MailLogRepository, undefined, { optional: true });
|
|
20
|
+
defaultData = inject(MAIL_DEFAULT_DATA, undefined, { optional: true });
|
|
21
|
+
logger = inject(Logger, 'MailService');
|
|
35
22
|
async send(mailData, templateName) {
|
|
36
23
|
const data = { ...this.defaultData, ...mailData };
|
|
37
24
|
let mailLog;
|
|
@@ -71,13 +58,6 @@ let MailService = class MailService {
|
|
|
71
58
|
}
|
|
72
59
|
};
|
|
73
60
|
MailService = __decorate([
|
|
74
|
-
Singleton()
|
|
75
|
-
__param(2, Inject(MailLogRepository)),
|
|
76
|
-
__param(2, Optional()),
|
|
77
|
-
__param(3, ResolveArg('MailService')),
|
|
78
|
-
__param(4, Inject(MAIL_DEFAULT_DATA)),
|
|
79
|
-
__param(4, Optional()),
|
|
80
|
-
__metadata("design:paramtypes", [MailClient,
|
|
81
|
-
TemplateService, Object, Logger, Object])
|
|
61
|
+
Singleton()
|
|
82
62
|
], MailService);
|
|
83
63
|
export { MailService };
|
package/mail/module.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Type } from '../types.js';
|
|
2
|
-
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
3
2
|
import { MailClient, MailClientConfig } from './mail.client.js';
|
|
4
3
|
import type { DefaultMailData } from './models/index.js';
|
|
4
|
+
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
5
5
|
export type MailModuleConfig = {
|
|
6
|
-
|
|
6
|
+
defaultClientConfig: MailClientConfig;
|
|
7
7
|
client: Type<MailClient>;
|
|
8
8
|
logRepository: Type<MailLogRepository>;
|
|
9
9
|
defaultData: DefaultMailData;
|
|
@@ -11,4 +11,4 @@ export type MailModuleConfig = {
|
|
|
11
11
|
/**
|
|
12
12
|
* configure mail module
|
|
13
13
|
*/
|
|
14
|
-
export declare function configureMail({
|
|
14
|
+
export declare function configureMail({ defaultClientConfig, client, logRepository, defaultData }: Partial<MailModuleConfig>): void;
|
package/mail/module.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Injector } from '../injector/injector.js';
|
|
2
2
|
import { isDefined } from '../utils/type-guards.js';
|
|
3
|
-
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
4
3
|
import { MailClient, MailClientConfig } from './mail.client.js';
|
|
4
|
+
import { MailLogRepository } from './repositories/mail-log.repository.js';
|
|
5
5
|
import { MAIL_DEFAULT_DATA } from './tokens.js';
|
|
6
6
|
/**
|
|
7
7
|
* configure mail module
|
|
8
8
|
*/
|
|
9
|
-
export function configureMail({
|
|
10
|
-
if (isDefined(
|
|
11
|
-
Injector.registerSingleton(MailClientConfig, { useValue:
|
|
9
|
+
export function configureMail({ defaultClientConfig, client, logRepository, defaultData }) {
|
|
10
|
+
if (isDefined(defaultClientConfig)) {
|
|
11
|
+
Injector.registerSingleton(MailClientConfig, { useValue: defaultClientConfig });
|
|
12
12
|
}
|
|
13
13
|
if (isDefined(client)) {
|
|
14
14
|
Injector.registerSingleton(MailClient, { useToken: client });
|