@fufulog/brevomorphic-cms-sdk 1.0.1 → 1.0.2
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/brevoClient.js +11 -2
- package/dist/repository.js +15 -0
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/brevoClient.ts +14 -2
- package/src/repository.ts +16 -1
- package/src/types.ts +1 -1
package/dist/brevoClient.js
CHANGED
|
@@ -127,11 +127,20 @@ export class BrevoClient {
|
|
|
127
127
|
*/
|
|
128
128
|
async sendEmail(params) {
|
|
129
129
|
try {
|
|
130
|
-
|
|
130
|
+
const replyToEmail = params.variables?.replyToEmail;
|
|
131
|
+
const replyToName = params.variables?.replyToName;
|
|
132
|
+
const payload = {
|
|
131
133
|
templateId: params.templateId,
|
|
132
134
|
to: [{ email: params.to }],
|
|
133
135
|
params: params.variables || {},
|
|
134
|
-
}
|
|
136
|
+
};
|
|
137
|
+
if (replyToEmail) {
|
|
138
|
+
payload.replyTo = {
|
|
139
|
+
email: replyToEmail,
|
|
140
|
+
...(replyToName ? { name: replyToName } : {}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
await this.client.post('/smtp/email', payload);
|
|
135
144
|
}
|
|
136
145
|
catch (error) {
|
|
137
146
|
const msg = error.response?.data?.message || error.message;
|
package/dist/repository.js
CHANGED
|
@@ -33,6 +33,9 @@ export class EmailTemplateRepository {
|
|
|
33
33
|
* Fetch all event-to-template mappings from the local database
|
|
34
34
|
*/
|
|
35
35
|
async getAllMappings() {
|
|
36
|
+
if (this.dbType === 'custom') {
|
|
37
|
+
return this.dbClient.getAllMappings();
|
|
38
|
+
}
|
|
36
39
|
if (this.dbType === 'firestore') {
|
|
37
40
|
const snapshot = await this.dbClient.collection(this.tableName).get();
|
|
38
41
|
const mappings = [];
|
|
@@ -64,6 +67,9 @@ export class EmailTemplateRepository {
|
|
|
64
67
|
* Fetch mapping for a specific template ID
|
|
65
68
|
*/
|
|
66
69
|
async getMappingByTemplateId(templateId) {
|
|
70
|
+
if (this.dbType === 'custom') {
|
|
71
|
+
return this.dbClient.getMappingByTemplateId(templateId);
|
|
72
|
+
}
|
|
67
73
|
if (this.dbType === 'firestore') {
|
|
68
74
|
const doc = await this.dbClient.collection(this.tableName).doc(templateId.toString()).get();
|
|
69
75
|
if (!doc.exists)
|
|
@@ -98,6 +104,9 @@ export class EmailTemplateRepository {
|
|
|
98
104
|
* Assumes we want the active template linked to this event.
|
|
99
105
|
*/
|
|
100
106
|
async getActiveMappingByEvent(eventName) {
|
|
107
|
+
if (this.dbType === 'custom') {
|
|
108
|
+
return this.dbClient.getActiveMappingByEvent(eventName);
|
|
109
|
+
}
|
|
101
110
|
if (this.dbType === 'firestore') {
|
|
102
111
|
const snapshot = await this.dbClient
|
|
103
112
|
.collection(this.tableName)
|
|
@@ -140,6 +149,9 @@ export class EmailTemplateRepository {
|
|
|
140
149
|
* Upsert a mapping (insert or update template config)
|
|
141
150
|
*/
|
|
142
151
|
async upsertMapping(templateId, eventName, isActive) {
|
|
152
|
+
if (this.dbType === 'custom') {
|
|
153
|
+
return this.dbClient.upsertMapping(templateId, eventName, isActive);
|
|
154
|
+
}
|
|
143
155
|
if (this.dbType === 'firestore') {
|
|
144
156
|
await this.dbClient
|
|
145
157
|
.collection(this.tableName)
|
|
@@ -186,6 +198,9 @@ export class EmailTemplateRepository {
|
|
|
186
198
|
* If mapping does not exist, insert blank inactive mapping.
|
|
187
199
|
*/
|
|
188
200
|
async insertJITMapping(templateId) {
|
|
201
|
+
if (this.dbType === 'custom') {
|
|
202
|
+
return this.dbClient.insertJITMapping(templateId);
|
|
203
|
+
}
|
|
189
204
|
if (this.dbType === 'firestore') {
|
|
190
205
|
const docRef = this.dbClient.collection(this.tableName).doc(templateId.toString());
|
|
191
206
|
const doc = await docRef.get();
|
package/dist/types.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface SDKConfig {
|
|
|
40
40
|
name?: string;
|
|
41
41
|
email: string;
|
|
42
42
|
};
|
|
43
|
-
dbType: 'postgres' | 'mysql' | 'firestore';
|
|
43
|
+
dbType: 'postgres' | 'mysql' | 'firestore' | 'custom';
|
|
44
44
|
/**
|
|
45
45
|
* For 'postgres': an object satisfying { query: (sql, params) => Promise<{ rows: any[] }> } or equivalent
|
|
46
46
|
* For 'mysql': an object satisfying { query: (sql, params) => Promise<[any[], any]> } or equivalent
|
package/package.json
CHANGED
package/src/brevoClient.ts
CHANGED
|
@@ -158,11 +158,23 @@ export class BrevoClient {
|
|
|
158
158
|
variables?: Record<string, any>;
|
|
159
159
|
}): Promise<void> {
|
|
160
160
|
try {
|
|
161
|
-
|
|
161
|
+
const replyToEmail = params.variables?.replyToEmail;
|
|
162
|
+
const replyToName = params.variables?.replyToName;
|
|
163
|
+
|
|
164
|
+
const payload: any = {
|
|
162
165
|
templateId: params.templateId,
|
|
163
166
|
to: [{ email: params.to }],
|
|
164
167
|
params: params.variables || {},
|
|
165
|
-
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (replyToEmail) {
|
|
171
|
+
payload.replyTo = {
|
|
172
|
+
email: replyToEmail,
|
|
173
|
+
...(replyToName ? { name: replyToName } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
await this.client.post('/smtp/email', payload);
|
|
166
178
|
} catch (error: any) {
|
|
167
179
|
const msg = error.response?.data?.message || error.message;
|
|
168
180
|
throw new Error(`Failed to send event email via Brevo: ${msg}`);
|
package/src/repository.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SDKConfig, LocalMapping } from './types.js';
|
|
2
2
|
|
|
3
3
|
export class EmailTemplateRepository {
|
|
4
|
-
private dbType: 'postgres' | 'mysql' | 'firestore';
|
|
4
|
+
private dbType: 'postgres' | 'mysql' | 'firestore' | 'custom';
|
|
5
5
|
private dbClient: any;
|
|
6
6
|
private tableName: string;
|
|
7
7
|
|
|
@@ -38,6 +38,9 @@ export class EmailTemplateRepository {
|
|
|
38
38
|
* Fetch all event-to-template mappings from the local database
|
|
39
39
|
*/
|
|
40
40
|
async getAllMappings(): Promise<LocalMapping[]> {
|
|
41
|
+
if (this.dbType === 'custom') {
|
|
42
|
+
return this.dbClient.getAllMappings();
|
|
43
|
+
}
|
|
41
44
|
if (this.dbType === 'firestore') {
|
|
42
45
|
const snapshot = await this.dbClient.collection(this.tableName).get();
|
|
43
46
|
const mappings: LocalMapping[] = [];
|
|
@@ -69,6 +72,9 @@ export class EmailTemplateRepository {
|
|
|
69
72
|
* Fetch mapping for a specific template ID
|
|
70
73
|
*/
|
|
71
74
|
async getMappingByTemplateId(templateId: number): Promise<LocalMapping | null> {
|
|
75
|
+
if (this.dbType === 'custom') {
|
|
76
|
+
return this.dbClient.getMappingByTemplateId(templateId);
|
|
77
|
+
}
|
|
72
78
|
if (this.dbType === 'firestore') {
|
|
73
79
|
const doc = await this.dbClient.collection(this.tableName).doc(templateId.toString()).get();
|
|
74
80
|
if (!doc.exists) return null;
|
|
@@ -102,6 +108,9 @@ export class EmailTemplateRepository {
|
|
|
102
108
|
* Assumes we want the active template linked to this event.
|
|
103
109
|
*/
|
|
104
110
|
async getActiveMappingByEvent(eventName: string): Promise<LocalMapping | null> {
|
|
111
|
+
if (this.dbType === 'custom') {
|
|
112
|
+
return this.dbClient.getActiveMappingByEvent(eventName);
|
|
113
|
+
}
|
|
105
114
|
if (this.dbType === 'firestore') {
|
|
106
115
|
const snapshot = await this.dbClient
|
|
107
116
|
.collection(this.tableName)
|
|
@@ -145,6 +154,9 @@ export class EmailTemplateRepository {
|
|
|
145
154
|
* Upsert a mapping (insert or update template config)
|
|
146
155
|
*/
|
|
147
156
|
async upsertMapping(templateId: number, eventName: string, isActive: boolean): Promise<void> {
|
|
157
|
+
if (this.dbType === 'custom') {
|
|
158
|
+
return this.dbClient.upsertMapping(templateId, eventName, isActive);
|
|
159
|
+
}
|
|
148
160
|
if (this.dbType === 'firestore') {
|
|
149
161
|
await this.dbClient
|
|
150
162
|
.collection(this.tableName)
|
|
@@ -193,6 +205,9 @@ export class EmailTemplateRepository {
|
|
|
193
205
|
* If mapping does not exist, insert blank inactive mapping.
|
|
194
206
|
*/
|
|
195
207
|
async insertJITMapping(templateId: number): Promise<void> {
|
|
208
|
+
if (this.dbType === 'custom') {
|
|
209
|
+
return this.dbClient.insertJITMapping(templateId);
|
|
210
|
+
}
|
|
196
211
|
if (this.dbType === 'firestore') {
|
|
197
212
|
const docRef = this.dbClient.collection(this.tableName).doc(templateId.toString());
|
|
198
213
|
const doc = await docRef.get();
|
package/src/types.ts
CHANGED
|
@@ -46,7 +46,7 @@ export interface SDKConfig {
|
|
|
46
46
|
name?: string;
|
|
47
47
|
email: string;
|
|
48
48
|
};
|
|
49
|
-
dbType: 'postgres' | 'mysql' | 'firestore';
|
|
49
|
+
dbType: 'postgres' | 'mysql' | 'firestore' | 'custom';
|
|
50
50
|
/**
|
|
51
51
|
* For 'postgres': an object satisfying { query: (sql, params) => Promise<{ rows: any[] }> } or equivalent
|
|
52
52
|
* For 'mysql': an object satisfying { query: (sql, params) => Promise<[any[], any]> } or equivalent
|