@develit-services/notification 0.0.14 → 0.0.16

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.
Files changed (45) hide show
  1. package/dist/database/schema.cjs +9 -0
  2. package/dist/database/schema.d.cts +2 -0
  3. package/dist/database/schema.d.mts +2 -0
  4. package/dist/database/schema.d.ts +2 -0
  5. package/dist/database/schema.mjs +3 -0
  6. package/dist/export/worker.cjs +41 -41
  7. package/dist/export/worker.d.cts +2 -201
  8. package/dist/export/worker.d.mts +2 -201
  9. package/dist/export/worker.d.ts +2 -201
  10. package/dist/export/worker.mjs +41 -41
  11. package/dist/shared/notification.4b3eUEIG.cjs +22 -0
  12. package/dist/shared/notification.BJyMXKGH.d.cts +203 -0
  13. package/dist/shared/notification.BJyMXKGH.d.mts +203 -0
  14. package/dist/shared/notification.BJyMXKGH.d.ts +203 -0
  15. package/dist/shared/notification.C0X8Orrh.mjs +19 -0
  16. package/package.json +5 -5
  17. package/@types/consts/audit-log.consts.ts +0 -7
  18. package/@types/consts/index.ts +0 -1
  19. package/@types/database/audit-log.types.ts +0 -7
  20. package/@types/database/index.ts +0 -1
  21. package/@types/email/IEmail.connector.ts +0 -21
  22. package/@types/email/IEmail.types.ts +0 -25
  23. package/@types/email/ecomail/ecomail.connector.ts +0 -139
  24. package/@types/email/ecomail/ecomail.types.ts +0 -27
  25. package/@types/email/ecomail/index.ts +0 -2
  26. package/@types/email/index.ts +0 -3
  27. package/@types/index.ts +0 -9
  28. package/@types/io/index.ts +0 -3
  29. package/@types/io/sendEmail.ts +0 -18
  30. package/@types/io/sendSlack.ts +0 -19
  31. package/@types/io/sendSms.ts +0 -20
  32. package/@types/pushNotification/IPushNotification.ts +0 -1
  33. package/@types/pushNotification/index.ts +0 -1
  34. package/@types/queue.ts +0 -19
  35. package/@types/service.ts +0 -30
  36. package/@types/slack/ISlack.types.ts +0 -3
  37. package/@types/slack/index.ts +0 -1
  38. package/@types/slack/slack.connector.ts +0 -27
  39. package/@types/sms/ISms.connector.ts +0 -22
  40. package/@types/sms/ISms.types.ts +0 -4
  41. package/@types/sms/index.ts +0 -3
  42. package/@types/sms/twilio/index.ts +0 -1
  43. package/@types/sms/twilio/twilio.connector.ts +0 -35
  44. package/src/database/schema/audit-log.schema.ts +0 -13
  45. package/src/database/schema/index.ts +0 -1
@@ -0,0 +1,203 @@
1
+ import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
2
+
3
+ declare const auditLog: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4
+ name: "audit_log";
5
+ schema: undefined;
6
+ columns: {
7
+ event: drizzle_orm_sqlite_core.SQLiteColumn<{
8
+ name: "event";
9
+ tableName: "audit_log";
10
+ dataType: "string";
11
+ columnType: "SQLiteText";
12
+ data: "EMAIL" | "SMS" | "PUSH_NOTIFICATION" | "SLACK";
13
+ driverParam: string;
14
+ notNull: true;
15
+ hasDefault: false;
16
+ isPrimaryKey: false;
17
+ isAutoincrement: false;
18
+ hasRuntimeDefault: false;
19
+ enumValues: [string, ...string[]];
20
+ baseColumn: never;
21
+ identity: undefined;
22
+ generated: undefined;
23
+ }, {}, {
24
+ length: number | undefined;
25
+ $type: "EMAIL" | "SMS" | "PUSH_NOTIFICATION" | "SLACK";
26
+ }>;
27
+ ip: drizzle_orm_sqlite_core.SQLiteColumn<{
28
+ name: "ip";
29
+ tableName: "audit_log";
30
+ dataType: "string";
31
+ columnType: "SQLiteText";
32
+ data: string;
33
+ driverParam: string;
34
+ notNull: false;
35
+ hasDefault: false;
36
+ isPrimaryKey: false;
37
+ isAutoincrement: false;
38
+ hasRuntimeDefault: false;
39
+ enumValues: [string, ...string[]];
40
+ baseColumn: never;
41
+ identity: undefined;
42
+ generated: undefined;
43
+ }, {}, {
44
+ length: number | undefined;
45
+ }>;
46
+ userAgent: drizzle_orm_sqlite_core.SQLiteColumn<{
47
+ name: "user_agent";
48
+ tableName: "audit_log";
49
+ dataType: "string";
50
+ columnType: "SQLiteText";
51
+ data: string;
52
+ driverParam: string;
53
+ notNull: false;
54
+ hasDefault: false;
55
+ isPrimaryKey: false;
56
+ isAutoincrement: false;
57
+ hasRuntimeDefault: false;
58
+ enumValues: [string, ...string[]];
59
+ baseColumn: never;
60
+ identity: undefined;
61
+ generated: undefined;
62
+ }, {}, {
63
+ length: number | undefined;
64
+ }>;
65
+ description: drizzle_orm_sqlite_core.SQLiteColumn<{
66
+ name: "description";
67
+ tableName: "audit_log";
68
+ dataType: "string";
69
+ columnType: "SQLiteText";
70
+ data: string;
71
+ driverParam: string;
72
+ notNull: false;
73
+ hasDefault: false;
74
+ isPrimaryKey: false;
75
+ isAutoincrement: false;
76
+ hasRuntimeDefault: false;
77
+ enumValues: [string, ...string[]];
78
+ baseColumn: never;
79
+ identity: undefined;
80
+ generated: undefined;
81
+ }, {}, {
82
+ length: number | undefined;
83
+ }>;
84
+ initiatorService: drizzle_orm_sqlite_core.SQLiteColumn<{
85
+ name: "initiator_service";
86
+ tableName: "audit_log";
87
+ dataType: "string";
88
+ columnType: "SQLiteText";
89
+ data: string;
90
+ driverParam: string;
91
+ notNull: true;
92
+ hasDefault: false;
93
+ isPrimaryKey: false;
94
+ isAutoincrement: false;
95
+ hasRuntimeDefault: false;
96
+ enumValues: [string, ...string[]];
97
+ baseColumn: never;
98
+ identity: undefined;
99
+ generated: undefined;
100
+ }, {}, {
101
+ length: number | undefined;
102
+ }>;
103
+ initiatorUserId: drizzle_orm_sqlite_core.SQLiteColumn<{
104
+ name: "initiator_user_id";
105
+ tableName: "audit_log";
106
+ dataType: "string";
107
+ columnType: "SQLiteText";
108
+ data: string;
109
+ driverParam: string;
110
+ notNull: false;
111
+ hasDefault: false;
112
+ isPrimaryKey: false;
113
+ isAutoincrement: false;
114
+ hasRuntimeDefault: false;
115
+ enumValues: [string, ...string[]];
116
+ baseColumn: never;
117
+ identity: undefined;
118
+ generated: undefined;
119
+ }, {}, {
120
+ length: number | undefined;
121
+ }>;
122
+ id: drizzle_orm_sqlite_core.SQLiteColumn<{
123
+ name: "id";
124
+ tableName: "audit_log";
125
+ dataType: "string";
126
+ columnType: "SQLiteText";
127
+ data: string;
128
+ driverParam: string;
129
+ notNull: true;
130
+ hasDefault: false;
131
+ isPrimaryKey: true;
132
+ isAutoincrement: false;
133
+ hasRuntimeDefault: false;
134
+ enumValues: [string, ...string[]];
135
+ baseColumn: never;
136
+ identity: undefined;
137
+ generated: undefined;
138
+ }, {}, {
139
+ length: number | undefined;
140
+ }>;
141
+ createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
142
+ name: "created_at";
143
+ tableName: "audit_log";
144
+ dataType: "date";
145
+ columnType: "SQLiteTimestamp";
146
+ data: Date;
147
+ driverParam: number;
148
+ notNull: false;
149
+ hasDefault: true;
150
+ isPrimaryKey: false;
151
+ isAutoincrement: false;
152
+ hasRuntimeDefault: false;
153
+ enumValues: undefined;
154
+ baseColumn: never;
155
+ identity: undefined;
156
+ generated: undefined;
157
+ }, {}, {}>;
158
+ updatedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
159
+ name: "updated_at";
160
+ tableName: "audit_log";
161
+ dataType: "date";
162
+ columnType: "SQLiteTimestamp";
163
+ data: Date;
164
+ driverParam: number;
165
+ notNull: false;
166
+ hasDefault: true;
167
+ isPrimaryKey: false;
168
+ isAutoincrement: false;
169
+ hasRuntimeDefault: false;
170
+ enumValues: undefined;
171
+ baseColumn: never;
172
+ identity: undefined;
173
+ generated: undefined;
174
+ }, {}, {}>;
175
+ deletedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
176
+ name: "deleted_at";
177
+ tableName: "audit_log";
178
+ dataType: "date";
179
+ columnType: "SQLiteTimestamp";
180
+ data: Date;
181
+ driverParam: number;
182
+ notNull: false;
183
+ hasDefault: true;
184
+ isPrimaryKey: false;
185
+ isAutoincrement: false;
186
+ hasRuntimeDefault: false;
187
+ enumValues: undefined;
188
+ baseColumn: never;
189
+ identity: undefined;
190
+ generated: undefined;
191
+ }, {}, {}>;
192
+ };
193
+ dialect: "sqlite";
194
+ }>;
195
+
196
+ declare const schema_auditLog: typeof auditLog;
197
+ declare namespace schema {
198
+ export {
199
+ schema_auditLog as auditLog,
200
+ };
201
+ }
202
+
203
+ export { auditLog as a, schema as s };
@@ -0,0 +1,203 @@
1
+ import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
2
+
3
+ declare const auditLog: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
4
+ name: "audit_log";
5
+ schema: undefined;
6
+ columns: {
7
+ event: drizzle_orm_sqlite_core.SQLiteColumn<{
8
+ name: "event";
9
+ tableName: "audit_log";
10
+ dataType: "string";
11
+ columnType: "SQLiteText";
12
+ data: "EMAIL" | "SMS" | "PUSH_NOTIFICATION" | "SLACK";
13
+ driverParam: string;
14
+ notNull: true;
15
+ hasDefault: false;
16
+ isPrimaryKey: false;
17
+ isAutoincrement: false;
18
+ hasRuntimeDefault: false;
19
+ enumValues: [string, ...string[]];
20
+ baseColumn: never;
21
+ identity: undefined;
22
+ generated: undefined;
23
+ }, {}, {
24
+ length: number | undefined;
25
+ $type: "EMAIL" | "SMS" | "PUSH_NOTIFICATION" | "SLACK";
26
+ }>;
27
+ ip: drizzle_orm_sqlite_core.SQLiteColumn<{
28
+ name: "ip";
29
+ tableName: "audit_log";
30
+ dataType: "string";
31
+ columnType: "SQLiteText";
32
+ data: string;
33
+ driverParam: string;
34
+ notNull: false;
35
+ hasDefault: false;
36
+ isPrimaryKey: false;
37
+ isAutoincrement: false;
38
+ hasRuntimeDefault: false;
39
+ enumValues: [string, ...string[]];
40
+ baseColumn: never;
41
+ identity: undefined;
42
+ generated: undefined;
43
+ }, {}, {
44
+ length: number | undefined;
45
+ }>;
46
+ userAgent: drizzle_orm_sqlite_core.SQLiteColumn<{
47
+ name: "user_agent";
48
+ tableName: "audit_log";
49
+ dataType: "string";
50
+ columnType: "SQLiteText";
51
+ data: string;
52
+ driverParam: string;
53
+ notNull: false;
54
+ hasDefault: false;
55
+ isPrimaryKey: false;
56
+ isAutoincrement: false;
57
+ hasRuntimeDefault: false;
58
+ enumValues: [string, ...string[]];
59
+ baseColumn: never;
60
+ identity: undefined;
61
+ generated: undefined;
62
+ }, {}, {
63
+ length: number | undefined;
64
+ }>;
65
+ description: drizzle_orm_sqlite_core.SQLiteColumn<{
66
+ name: "description";
67
+ tableName: "audit_log";
68
+ dataType: "string";
69
+ columnType: "SQLiteText";
70
+ data: string;
71
+ driverParam: string;
72
+ notNull: false;
73
+ hasDefault: false;
74
+ isPrimaryKey: false;
75
+ isAutoincrement: false;
76
+ hasRuntimeDefault: false;
77
+ enumValues: [string, ...string[]];
78
+ baseColumn: never;
79
+ identity: undefined;
80
+ generated: undefined;
81
+ }, {}, {
82
+ length: number | undefined;
83
+ }>;
84
+ initiatorService: drizzle_orm_sqlite_core.SQLiteColumn<{
85
+ name: "initiator_service";
86
+ tableName: "audit_log";
87
+ dataType: "string";
88
+ columnType: "SQLiteText";
89
+ data: string;
90
+ driverParam: string;
91
+ notNull: true;
92
+ hasDefault: false;
93
+ isPrimaryKey: false;
94
+ isAutoincrement: false;
95
+ hasRuntimeDefault: false;
96
+ enumValues: [string, ...string[]];
97
+ baseColumn: never;
98
+ identity: undefined;
99
+ generated: undefined;
100
+ }, {}, {
101
+ length: number | undefined;
102
+ }>;
103
+ initiatorUserId: drizzle_orm_sqlite_core.SQLiteColumn<{
104
+ name: "initiator_user_id";
105
+ tableName: "audit_log";
106
+ dataType: "string";
107
+ columnType: "SQLiteText";
108
+ data: string;
109
+ driverParam: string;
110
+ notNull: false;
111
+ hasDefault: false;
112
+ isPrimaryKey: false;
113
+ isAutoincrement: false;
114
+ hasRuntimeDefault: false;
115
+ enumValues: [string, ...string[]];
116
+ baseColumn: never;
117
+ identity: undefined;
118
+ generated: undefined;
119
+ }, {}, {
120
+ length: number | undefined;
121
+ }>;
122
+ id: drizzle_orm_sqlite_core.SQLiteColumn<{
123
+ name: "id";
124
+ tableName: "audit_log";
125
+ dataType: "string";
126
+ columnType: "SQLiteText";
127
+ data: string;
128
+ driverParam: string;
129
+ notNull: true;
130
+ hasDefault: false;
131
+ isPrimaryKey: true;
132
+ isAutoincrement: false;
133
+ hasRuntimeDefault: false;
134
+ enumValues: [string, ...string[]];
135
+ baseColumn: never;
136
+ identity: undefined;
137
+ generated: undefined;
138
+ }, {}, {
139
+ length: number | undefined;
140
+ }>;
141
+ createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
142
+ name: "created_at";
143
+ tableName: "audit_log";
144
+ dataType: "date";
145
+ columnType: "SQLiteTimestamp";
146
+ data: Date;
147
+ driverParam: number;
148
+ notNull: false;
149
+ hasDefault: true;
150
+ isPrimaryKey: false;
151
+ isAutoincrement: false;
152
+ hasRuntimeDefault: false;
153
+ enumValues: undefined;
154
+ baseColumn: never;
155
+ identity: undefined;
156
+ generated: undefined;
157
+ }, {}, {}>;
158
+ updatedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
159
+ name: "updated_at";
160
+ tableName: "audit_log";
161
+ dataType: "date";
162
+ columnType: "SQLiteTimestamp";
163
+ data: Date;
164
+ driverParam: number;
165
+ notNull: false;
166
+ hasDefault: true;
167
+ isPrimaryKey: false;
168
+ isAutoincrement: false;
169
+ hasRuntimeDefault: false;
170
+ enumValues: undefined;
171
+ baseColumn: never;
172
+ identity: undefined;
173
+ generated: undefined;
174
+ }, {}, {}>;
175
+ deletedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
176
+ name: "deleted_at";
177
+ tableName: "audit_log";
178
+ dataType: "date";
179
+ columnType: "SQLiteTimestamp";
180
+ data: Date;
181
+ driverParam: number;
182
+ notNull: false;
183
+ hasDefault: true;
184
+ isPrimaryKey: false;
185
+ isAutoincrement: false;
186
+ hasRuntimeDefault: false;
187
+ enumValues: undefined;
188
+ baseColumn: never;
189
+ identity: undefined;
190
+ generated: undefined;
191
+ }, {}, {}>;
192
+ };
193
+ dialect: "sqlite";
194
+ }>;
195
+
196
+ declare const schema_auditLog: typeof auditLog;
197
+ declare namespace schema {
198
+ export {
199
+ schema_auditLog as auditLog,
200
+ };
201
+ }
202
+
203
+ export { auditLog as a, schema as s };
@@ -0,0 +1,19 @@
1
+ import { base } from '@develit-io/backend-sdk';
2
+ import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
3
+
4
+ const auditLog = sqliteTable("audit_log", {
5
+ ...base,
6
+ event: text("event").$type().notNull(),
7
+ ip: text("ip"),
8
+ userAgent: text("user_agent"),
9
+ description: text("description"),
10
+ initiatorService: text("initiator_service").notNull(),
11
+ initiatorUserId: text("initiator_user_id")
12
+ });
13
+
14
+ const schema = {
15
+ __proto__: null,
16
+ auditLog: auditLog
17
+ };
18
+
19
+ export { auditLog as a, schema as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-services/notification",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "author": "Develit.io s.r.o.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -15,14 +15,14 @@
15
15
  "require": "./dist/export/worker.cjs"
16
16
  },
17
17
  "./db-schema": {
18
- "import": "./src/database/schema/index.ts"
18
+ "types": "./dist/database/schema.d.ts",
19
+ "import": "./dist/database/schema.mjs",
20
+ "require": "./dist/database/schema.cjs"
19
21
  },
20
22
  "./package.json": "./package.json"
21
23
  },
22
24
  "files": [
23
- "./dist",
24
- "./@types",
25
- "./src/database/schema"
25
+ "./dist"
26
26
  ],
27
27
  "scripts": {
28
28
  "postinstall": "bun cf:typegen",
@@ -1,7 +0,0 @@
1
- export const AUDIT_LOG_EVENT_TYPES = [
2
- 'EMAIL',
3
- 'SMS',
4
- 'PUSH_NOTIFICATION',
5
- 'SLACK',
6
- ] as const
7
- export type AuditLogEventType = (typeof AUDIT_LOG_EVENT_TYPES)[number]
@@ -1 +0,0 @@
1
- export * from './audit-log.consts'
@@ -1,7 +0,0 @@
1
- import type { tables } from '@services/notification/src/database/drizzle'
2
- import type { InferInsertModel, InferSelectModel } from 'drizzle-orm'
3
-
4
- export interface AuditLogSelectType
5
- extends InferSelectModel<typeof tables.auditLog> {}
6
- export interface AuditLogInsertType
7
- extends InferInsertModel<typeof tables.auditLog> {}
@@ -1 +0,0 @@
1
- export * from './audit-log.types'
@@ -1,21 +0,0 @@
1
- import type { IContact, IEmail } from '../../@types'
2
-
3
- export abstract class IEmailConnector {
4
- static providerName: string
5
-
6
- public API_KEY: string
7
- public SMTP_HOST: string
8
- public SENDER: IContact
9
-
10
- protected constructor({
11
- API_KEY,
12
- SMTP_HOST,
13
- SENDER,
14
- }: { API_KEY: string; SMTP_HOST: string; SENDER: IContact }) {
15
- this.API_KEY = API_KEY
16
- this.SMTP_HOST = SMTP_HOST
17
- this.SENDER = SENDER
18
- }
19
-
20
- abstract sendEmail(email: IEmail): Promise<Response | null>
21
- }
@@ -1,25 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- export const iContactSchema = z.union([
4
- z.string(),
5
- z.object({
6
- email: z.string(),
7
- name: z.union([z.string(), z.undefined()]),
8
- }),
9
- ])
10
-
11
- export const iEmailSchema = z.object({
12
- to: z.union([iContactSchema, z.array(iContactSchema)]),
13
- replyTo: z.union([iContactSchema, z.array(iContactSchema)]).optional(),
14
- cc: z.union([iContactSchema, z.array(iContactSchema)]).optional(),
15
- bcc: z.union([iContactSchema, z.array(iContactSchema)]).optional(),
16
- from: iContactSchema.optional(),
17
- subject: z.string(),
18
- text: z.string().optional(),
19
- html: z.string().optional(),
20
- templateId: z.number().optional(),
21
- templateVariables: z.record(z.string(), z.string()).optional(),
22
- })
23
-
24
- export type IContact = z.infer<typeof iContactSchema>
25
- export type IEmail = z.infer<typeof iEmailSchema>
@@ -1,139 +0,0 @@
1
- import { useResult } from '@develit-io/backend-sdk'
2
- import {
3
- type EMAttachment,
4
- type EMContact,
5
- type EMEmail,
6
- type IContact,
7
- type IEmail,
8
- IEmailConnector,
9
- } from '../../email'
10
-
11
- export class EcomailConnector extends IEmailConnector {
12
- static providerName = 'ecomail'
13
-
14
- constructor({
15
- API_KEY,
16
- SMTP_HOST,
17
- SENDER,
18
- }: { API_KEY: string; SMTP_HOST: string; SENDER: IContact }) {
19
- super({ API_KEY, SMTP_HOST, SENDER })
20
- }
21
-
22
- async sendEmail(email: IEmail): Promise<Response | null> {
23
- // This is needed only for ecomail connector because when template variables includes word 'localhost' it does not send email
24
- if (email.templateVariables) {
25
- for (const [key, value] of Object.entries(email.templateVariables)) {
26
- if (
27
- typeof value === 'string' &&
28
- String(value).includes('localhost') &&
29
- key in email.templateVariables
30
- ) {
31
- email.templateVariables[key as keyof typeof email.templateVariables] =
32
- String(value).replace('localhost', 'origin')
33
- }
34
- }
35
- }
36
-
37
- const emEmail: EMEmail = this.convertEmail(email)
38
- const uri = emEmail.message.template_id
39
- ? 'https://api2.ecomailapp.cz/transactional/send-template'
40
- : 'https://api2.ecomailapp.cz/transactional/send-message'
41
-
42
- const [data, error] = await useResult(
43
- fetch(uri, {
44
- method: 'POST',
45
- headers: {
46
- 'Content-Type': 'application/json',
47
- key: this.API_KEY,
48
- },
49
- body: JSON.stringify(emEmail),
50
- }),
51
- )
52
- if (error) throw error
53
-
54
- return data
55
- }
56
-
57
- protected convertEmail(email: IEmail): EMEmail {
58
- const toContacts: EMContact[] = this.convertContacts(email.to)
59
- const ccContacts: EMContact[] = email.cc
60
- ? this.convertContacts(email.cc)
61
- : []
62
- const bccContacts: EMContact[] = email.bcc
63
- ? this.convertContacts(email.bcc)
64
- : []
65
-
66
- const replyTo: EMContact | undefined = email.replyTo
67
- ? this.convertContacts(email.replyTo)[0]
68
- : undefined
69
-
70
- const from: EMContact = this.convertContact(email.from || this.SENDER)
71
- const subject: string = email.subject
72
-
73
- const textAttachments: EMAttachment[] = email.text
74
- ? [{ name: 'plain', type: 'text/plain', content: email.text }]
75
- : []
76
-
77
- const htmlAttachments: EMAttachment[] = email.html
78
- ? [{ type: 'text/html', content: email.html, name: 'email_body.html' }]
79
- : []
80
-
81
- const attachments: EMAttachment[] = [...textAttachments, ...htmlAttachments]
82
-
83
- const contacts: EMContact[] = toContacts.flatMap((to) => {
84
- const entries: EMContact[] = []
85
- if (ccContacts.length > 0) {
86
- ccContacts.forEach((cc) => {
87
- entries.push({ email: cc?.email, name: cc?.name, cc: cc?.email })
88
- })
89
- }
90
- if (bccContacts.length > 0) {
91
- bccContacts.forEach((bcc) => {
92
- entries.push({ email: bcc?.email, name: bcc?.name, bcc: bcc?.email })
93
- })
94
- }
95
- return entries.length > 0 ? entries : [to]
96
- })
97
-
98
- return {
99
- message: {
100
- from_email: from?.email,
101
- from_name: from.name || '',
102
- subject,
103
- attachments,
104
- to: contacts,
105
- text: email.text,
106
- html: email.html,
107
- reply_to: replyTo?.email,
108
- template_id: email.templateId,
109
- global_merge_vars: email.templateVariables
110
- ? Object.keys(email.templateVariables).map((key) => ({
111
- name: key,
112
- content:
113
- email.templateVariables![
114
- key as keyof typeof email.templateVariables
115
- ],
116
- }))
117
- : null,
118
- },
119
- }
120
- }
121
-
122
- protected convertContacts(contacts: IContact | IContact[]): EMContact[] {
123
- if (!contacts) {
124
- return []
125
- }
126
- const contactArray: IContact[] = Array.isArray(contacts)
127
- ? contacts
128
- : [contacts]
129
- return contactArray.map(this.convertContact)
130
- }
131
-
132
- protected convertContact(contact: IContact): EMContact {
133
- if (typeof contact === 'string') {
134
- return { email: contact, name: undefined }
135
- }
136
-
137
- return { email: contact?.email, name: contact?.name }
138
- }
139
- }
@@ -1,27 +0,0 @@
1
- export interface EMContact {
2
- email: string
3
- name?: string
4
- cc?: string
5
- bcc?: string
6
- }
7
-
8
- export interface EMAttachment {
9
- type: string
10
- name: string
11
- content: string
12
- }
13
-
14
- export interface EMEmail {
15
- message: {
16
- template_id?: number
17
- subject: string
18
- from_name: string
19
- from_email: string
20
- reply_to?: string
21
- to: EMContact[]
22
- attachments: EMAttachment[]
23
- text?: string
24
- html?: string
25
- global_merge_vars: object | null
26
- }
27
- }
@@ -1,2 +0,0 @@
1
- export * from './ecomail.connector'
2
- export * from './ecomail.types'