@punks/backend-entity-manager 0.0.356 → 0.0.358
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/cjs/index.js +36 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/email.d.ts +10 -0
- package/dist/cjs/types/abstractions/serializer.d.ts +14 -2
- package/dist/cjs/types/base/serializer.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/models/parsing.d.ts +5 -0
- package/dist/cjs/types/utils/validators.d.ts +2 -2
- package/dist/esm/index.js +36 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/email.d.ts +10 -0
- package/dist/esm/types/abstractions/serializer.d.ts +14 -2
- package/dist/esm/types/base/serializer.d.ts +1 -0
- package/dist/esm/types/platforms/nest/models/parsing.d.ts +5 -0
- package/dist/esm/types/utils/validators.d.ts +2 -2
- package/dist/index.d.ts +31 -4
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
export interface IEmailTemplateMiddleware {
|
|
2
3
|
processPayload(payload: unknown): Promise<unknown>;
|
|
3
4
|
}
|
|
@@ -9,6 +10,13 @@ export interface IEmailTemplatesCollection {
|
|
|
9
10
|
registerTemplate(id: string, template: IEmailTemplate<unknown, unknown, unknown>): void;
|
|
10
11
|
getTemplate<TTemplateData, TPayload, TAugmentedPayload = TPayload>(id: string): IEmailTemplate<TTemplateData, TPayload, TAugmentedPayload>;
|
|
11
12
|
}
|
|
13
|
+
export type EmailAttachmentData = {
|
|
14
|
+
content: string | Buffer;
|
|
15
|
+
filename: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
disposition?: string;
|
|
18
|
+
contentId?: string;
|
|
19
|
+
};
|
|
12
20
|
export type TemplatedEmailInput<TPayload> = {
|
|
13
21
|
from?: string;
|
|
14
22
|
to?: string[];
|
|
@@ -18,6 +26,7 @@ export type TemplatedEmailInput<TPayload> = {
|
|
|
18
26
|
templateId: string;
|
|
19
27
|
languageCode: string;
|
|
20
28
|
payload: TPayload;
|
|
29
|
+
attachments?: EmailAttachmentData[];
|
|
21
30
|
};
|
|
22
31
|
export interface HtmlEmailInput<TPayload> {
|
|
23
32
|
replyTo?: string;
|
|
@@ -28,6 +37,7 @@ export interface HtmlEmailInput<TPayload> {
|
|
|
28
37
|
subjectTemplate: string;
|
|
29
38
|
bodyTemplate: string;
|
|
30
39
|
payload: TPayload;
|
|
40
|
+
attachments?: EmailAttachmentData[];
|
|
31
41
|
}
|
|
32
42
|
export interface IEmailProvider<TTemplateData> {
|
|
33
43
|
sendTemplatedEmail<TPayload, TAugmentedPayload>(input: TemplatedEmailInput<TPayload>, template: IEmailTemplate<TTemplateData, TPayload, TAugmentedPayload>): Promise<void>;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
export type EntryValidationError = {
|
|
3
|
+
errorCode: string;
|
|
4
|
+
};
|
|
5
|
+
export type EntryValidationResult = {
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
validationErrors: EntryValidationError[];
|
|
8
|
+
};
|
|
2
9
|
export type ImportEntryValidationError = {
|
|
3
10
|
errorCode: string;
|
|
11
|
+
column: {
|
|
12
|
+
name: string;
|
|
13
|
+
key: string;
|
|
14
|
+
};
|
|
4
15
|
};
|
|
5
16
|
export type ImportEntryValidationResult = {
|
|
6
17
|
isValid: boolean;
|
|
@@ -11,11 +22,12 @@ export type EntitySerializerColumnParseAction<TSheetItem> = (value: any, item: T
|
|
|
11
22
|
export type EntitySerializerColumnConverter<TSheetItem> = (value: any, item: TSheetItem) => any;
|
|
12
23
|
export type EntitySerializerColumnValidator<TSheetItem> = {
|
|
13
24
|
key: string;
|
|
14
|
-
fn: (item: TSheetItem) =>
|
|
25
|
+
fn: (item: TSheetItem) => EntryValidationResult;
|
|
15
26
|
};
|
|
16
27
|
export type EntitySerializerColumnDefinition<TSheetItem> = {
|
|
17
28
|
name: string;
|
|
18
|
-
|
|
29
|
+
key: string;
|
|
30
|
+
selector: keyof TSheetItem | ((item: TSheetItem) => any);
|
|
19
31
|
colSpan?: number;
|
|
20
32
|
sampleValue?: any;
|
|
21
33
|
parser?: EntitySerializerColumnParser;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
export declare class EntityParseValidationColumn {
|
|
2
|
+
name: string;
|
|
3
|
+
key: string;
|
|
4
|
+
}
|
|
1
5
|
export declare class EntityParseValidationError {
|
|
2
6
|
errorCode: string;
|
|
7
|
+
column: EntityParseValidationColumn;
|
|
3
8
|
}
|
|
4
9
|
export declare class EntityParseStatus {
|
|
5
10
|
isValid: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) =>
|
|
1
|
+
import { EntryValidationResult } from "../abstractions/serializer";
|
|
2
|
+
export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => EntryValidationResult;
|
package/dist/esm/index.js
CHANGED
|
@@ -227,10 +227,12 @@ class EntitySerializer {
|
|
|
227
227
|
for (const column of definition.columns) {
|
|
228
228
|
if (column.parseAction) {
|
|
229
229
|
column.parseAction(record[column.name], entity);
|
|
230
|
+
continue;
|
|
230
231
|
}
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
if (typeof column.selector === "function") {
|
|
233
|
+
throw new Error("Function selectors are not supported with parseAction specified");
|
|
233
234
|
}
|
|
235
|
+
entity[column.selector] = this.parseColumnValue(record, column);
|
|
234
236
|
}
|
|
235
237
|
const validationErrors = [];
|
|
236
238
|
for (const column of definition.columns) {
|
|
@@ -239,13 +241,19 @@ class EntitySerializer {
|
|
|
239
241
|
if (!result.isValid) {
|
|
240
242
|
validationErrors.push({
|
|
241
243
|
errorCode: validator.key,
|
|
244
|
+
column: {
|
|
245
|
+
name: column.name,
|
|
246
|
+
key: column.key,
|
|
247
|
+
},
|
|
242
248
|
});
|
|
243
249
|
}
|
|
244
250
|
}
|
|
245
251
|
}
|
|
246
252
|
const idField = definition.columns.find((x) => x.idColumn || x.selector === "id");
|
|
247
253
|
return {
|
|
248
|
-
id: idField
|
|
254
|
+
id: idField
|
|
255
|
+
? this.selectColumnValue(entity, idField.selector)
|
|
256
|
+
: undefined,
|
|
249
257
|
item: entity,
|
|
250
258
|
rowIndex,
|
|
251
259
|
status: {
|
|
@@ -385,11 +393,14 @@ class EntitySerializer {
|
|
|
385
393
|
}
|
|
386
394
|
}
|
|
387
395
|
getColumnValue(item, definition) {
|
|
388
|
-
const rawValue = item
|
|
396
|
+
const rawValue = this.selectColumnValue(item, definition.selector);
|
|
389
397
|
return definition.converter
|
|
390
398
|
? definition.converter(rawValue, item)
|
|
391
399
|
: rawValue;
|
|
392
400
|
}
|
|
401
|
+
selectColumnValue(item, selector) {
|
|
402
|
+
return typeof selector === "function" ? selector(item) : item[selector];
|
|
403
|
+
}
|
|
393
404
|
buildExportFileName(input) {
|
|
394
405
|
return `${input.refDate.toISOString().replaceAll(":", "_")}_${this.entityName}.${input.format}`;
|
|
395
406
|
}
|
|
@@ -34831,12 +34842,26 @@ class AppExceptionsFilterBase {
|
|
|
34831
34842
|
}
|
|
34832
34843
|
}
|
|
34833
34844
|
|
|
34845
|
+
class EntityParseValidationColumn {
|
|
34846
|
+
}
|
|
34847
|
+
__decorate([
|
|
34848
|
+
ApiProperty(),
|
|
34849
|
+
__metadata("design:type", String)
|
|
34850
|
+
], EntityParseValidationColumn.prototype, "name", void 0);
|
|
34851
|
+
__decorate([
|
|
34852
|
+
ApiProperty(),
|
|
34853
|
+
__metadata("design:type", String)
|
|
34854
|
+
], EntityParseValidationColumn.prototype, "key", void 0);
|
|
34834
34855
|
class EntityParseValidationError {
|
|
34835
34856
|
}
|
|
34836
34857
|
__decorate([
|
|
34837
34858
|
ApiProperty(),
|
|
34838
34859
|
__metadata("design:type", String)
|
|
34839
34860
|
], EntityParseValidationError.prototype, "errorCode", void 0);
|
|
34861
|
+
__decorate([
|
|
34862
|
+
ApiProperty(),
|
|
34863
|
+
__metadata("design:type", EntityParseValidationColumn)
|
|
34864
|
+
], EntityParseValidationError.prototype, "column", void 0);
|
|
34840
34865
|
class EntityParseStatus {
|
|
34841
34866
|
}
|
|
34842
34867
|
__decorate([
|
|
@@ -40360,6 +40385,7 @@ let AwsSesEmailProvider = class AwsSesEmailProvider {
|
|
|
40360
40385
|
bcc: input.bcc ?? templateData.bcc,
|
|
40361
40386
|
cc: input.cc ?? templateData.cc,
|
|
40362
40387
|
from: input.from ?? templateData.from,
|
|
40388
|
+
attachments: input.attachments,
|
|
40363
40389
|
});
|
|
40364
40390
|
}
|
|
40365
40391
|
async sendHtmlEmail(input) {
|
|
@@ -40486,6 +40512,12 @@ let SendgridEmailProvider = class SendgridEmailProvider {
|
|
|
40486
40512
|
...processedPayload,
|
|
40487
40513
|
},
|
|
40488
40514
|
templateId: templateData.sendgridTemplateId,
|
|
40515
|
+
attachments: input.attachments?.map((attachment) => ({
|
|
40516
|
+
...attachment,
|
|
40517
|
+
content: attachment.content instanceof Buffer
|
|
40518
|
+
? attachment.content.toString("utf-8")
|
|
40519
|
+
: attachment.content,
|
|
40520
|
+
})),
|
|
40489
40521
|
});
|
|
40490
40522
|
if (sendgridSettings.value.loggingEnabled) {
|
|
40491
40523
|
this.logger.info("Sending templated email", {
|