n8n-nodes-cakemail 1.1.5 → 1.2.0
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.
|
@@ -7,6 +7,11 @@ export declare class CakemailTrigger implements INodeType {
|
|
|
7
7
|
create(this: IHookFunctions): Promise<boolean>;
|
|
8
8
|
delete(this: IHookFunctions): Promise<boolean>;
|
|
9
9
|
};
|
|
10
|
+
setup: {
|
|
11
|
+
checkExists(this: IHookFunctions): Promise<boolean>;
|
|
12
|
+
create(this: IHookFunctions): Promise<boolean>;
|
|
13
|
+
delete(this: IHookFunctions): Promise<boolean>;
|
|
14
|
+
};
|
|
10
15
|
};
|
|
11
16
|
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
12
17
|
}
|
|
@@ -29,6 +29,12 @@ class CakemailTrigger {
|
|
|
29
29
|
responseMode: 'onReceived',
|
|
30
30
|
path: 'webhook',
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
name: 'setup',
|
|
34
|
+
httpMethod: 'POST',
|
|
35
|
+
responseMode: 'onReceived',
|
|
36
|
+
path: 'webhook',
|
|
37
|
+
},
|
|
32
38
|
],
|
|
33
39
|
properties: [
|
|
34
40
|
{
|
|
@@ -242,18 +248,96 @@ class CakemailTrigger {
|
|
|
242
248
|
return true;
|
|
243
249
|
},
|
|
244
250
|
},
|
|
251
|
+
setup: {
|
|
252
|
+
async checkExists() {
|
|
253
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
254
|
+
if (webhookData.setupWebhookId === undefined) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const credentials = await this.getCredentials('cakemailApi');
|
|
258
|
+
const client = new cakemail_sdk_1.CakemailClient({
|
|
259
|
+
email: credentials.email,
|
|
260
|
+
password: credentials.password,
|
|
261
|
+
baseURL: credentials.baseURL || 'https://api.cakemail.dev',
|
|
262
|
+
});
|
|
263
|
+
try {
|
|
264
|
+
await client.webhooks.get(webhookData.setupWebhookId);
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
async create() {
|
|
272
|
+
const webhookUrl = this.getNodeWebhookUrl('setup');
|
|
273
|
+
const event = this.getNodeParameter('event');
|
|
274
|
+
const rateLimit = this.getNodeParameter('rateLimit', 100);
|
|
275
|
+
const rateLimitPeriod = this.getNodeParameter('rateLimitPeriod', 'minute');
|
|
276
|
+
const credentials = await this.getCredentials('cakemailApi');
|
|
277
|
+
const client = new cakemail_sdk_1.CakemailClient({
|
|
278
|
+
email: credentials.email,
|
|
279
|
+
password: credentials.password,
|
|
280
|
+
baseURL: credentials.baseURL || 'https://api.cakemail.dev',
|
|
281
|
+
});
|
|
282
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
283
|
+
try {
|
|
284
|
+
const createResponse = await client.webhooks.create({
|
|
285
|
+
event,
|
|
286
|
+
url: webhookUrl,
|
|
287
|
+
rate_limit: rateLimit,
|
|
288
|
+
rate_limit_period: rateLimitPeriod,
|
|
289
|
+
});
|
|
290
|
+
if (!createResponse || !createResponse.id) {
|
|
291
|
+
throw new Error('Failed to create setup webhook: no webhook ID returned');
|
|
292
|
+
}
|
|
293
|
+
const webhookDetails = await client.webhooks.get(createResponse.id);
|
|
294
|
+
if (!webhookDetails || !webhookDetails.signature || !webhookDetails.signature.key) {
|
|
295
|
+
throw new Error(`Failed to retrieve setup webhook signature. Response: ${JSON.stringify(webhookDetails)}`);
|
|
296
|
+
}
|
|
297
|
+
webhookData.setupWebhookId = createResponse.id;
|
|
298
|
+
webhookData.setupWebhookSecret = webhookDetails.signature.key;
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
throw new Error(`Failed to create setup webhook: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
async delete() {
|
|
306
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
307
|
+
if (webhookData.setupWebhookId !== undefined) {
|
|
308
|
+
const credentials = await this.getCredentials('cakemailApi');
|
|
309
|
+
const client = new cakemail_sdk_1.CakemailClient({
|
|
310
|
+
email: credentials.email,
|
|
311
|
+
password: credentials.password,
|
|
312
|
+
baseURL: credentials.baseURL || 'https://api.cakemail.dev',
|
|
313
|
+
});
|
|
314
|
+
try {
|
|
315
|
+
await client.webhooks.archive(webhookData.setupWebhookId);
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
delete webhookData.setupWebhookId;
|
|
321
|
+
delete webhookData.setupWebhookSecret;
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
},
|
|
325
|
+
},
|
|
245
326
|
};
|
|
246
327
|
async webhook() {
|
|
247
328
|
const req = this.getRequestObject();
|
|
248
329
|
const webhookData = this.getWorkflowStaticData('node');
|
|
249
330
|
const credentials = await this.getCredentials('cakemailApi');
|
|
331
|
+
const webhookName = this.getWebhookName();
|
|
250
332
|
const client = new cakemail_sdk_1.CakemailClient({
|
|
251
333
|
email: credentials.email,
|
|
252
334
|
password: credentials.password,
|
|
253
335
|
baseURL: credentials.baseURL || 'https://api.cakemail.dev',
|
|
254
336
|
});
|
|
255
337
|
const signature = req.headers['x-signature'];
|
|
256
|
-
const secret =
|
|
338
|
+
const secret = webhookName === 'setup'
|
|
339
|
+
? webhookData.setupWebhookSecret
|
|
340
|
+
: webhookData.webhookSecret;
|
|
257
341
|
if (!signature || !secret) {
|
|
258
342
|
return {
|
|
259
343
|
webhookResponse: { status: 401, body: 'Unauthorized: Missing signature' },
|
|
@@ -39,6 +39,12 @@ export class CakemailTrigger implements INodeType {
|
|
|
39
39
|
responseMode: 'onReceived',
|
|
40
40
|
path: 'webhook',
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
name: 'setup',
|
|
44
|
+
httpMethod: 'POST',
|
|
45
|
+
responseMode: 'onReceived',
|
|
46
|
+
path: 'webhook',
|
|
47
|
+
},
|
|
42
48
|
],
|
|
43
49
|
properties: [
|
|
44
50
|
{
|
|
@@ -194,7 +200,7 @@ export class CakemailTrigger implements INodeType {
|
|
|
194
200
|
});
|
|
195
201
|
|
|
196
202
|
try {
|
|
197
|
-
await client.webhooks.get(webhookData.webhookId as
|
|
203
|
+
await client.webhooks.get(webhookData.webhookId as string);
|
|
198
204
|
return true;
|
|
199
205
|
} catch (error) {
|
|
200
206
|
return false;
|
|
@@ -258,7 +264,7 @@ export class CakemailTrigger implements INodeType {
|
|
|
258
264
|
});
|
|
259
265
|
|
|
260
266
|
try {
|
|
261
|
-
await client.webhooks.archive(webhookData.webhookId as
|
|
267
|
+
await client.webhooks.archive(webhookData.webhookId as string);
|
|
262
268
|
} catch (error) {
|
|
263
269
|
return false;
|
|
264
270
|
}
|
|
@@ -267,6 +273,96 @@ export class CakemailTrigger implements INodeType {
|
|
|
267
273
|
delete webhookData.webhookSecret;
|
|
268
274
|
}
|
|
269
275
|
|
|
276
|
+
return true;
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
setup: {
|
|
280
|
+
async checkExists(this: IHookFunctions): Promise<boolean> {
|
|
281
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
282
|
+
if (webhookData.setupWebhookId === undefined) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const credentials = await this.getCredentials('cakemailApi');
|
|
287
|
+
const client = new CakemailClient({
|
|
288
|
+
email: credentials.email as string,
|
|
289
|
+
password: credentials.password as string,
|
|
290
|
+
baseURL: credentials.baseURL as string || 'https://api.cakemail.dev',
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
await client.webhooks.get(webhookData.setupWebhookId as string);
|
|
295
|
+
return true;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
async create(this: IHookFunctions): Promise<boolean> {
|
|
302
|
+
const webhookUrl = this.getNodeWebhookUrl('setup');
|
|
303
|
+
const event = this.getNodeParameter('event') as WebhookEventType;
|
|
304
|
+
const rateLimit = this.getNodeParameter('rateLimit', 100) as number;
|
|
305
|
+
const rateLimitPeriod = this.getNodeParameter('rateLimitPeriod', 'minute') as 'second' | 'minute' | 'hour' | 'day';
|
|
306
|
+
|
|
307
|
+
const credentials = await this.getCredentials('cakemailApi');
|
|
308
|
+
const client = new CakemailClient({
|
|
309
|
+
email: credentials.email as string,
|
|
310
|
+
password: credentials.password as string,
|
|
311
|
+
baseURL: credentials.baseURL as string || 'https://api.cakemail.dev',
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
// Create the webhook
|
|
318
|
+
const createResponse = await client.webhooks.create({
|
|
319
|
+
event,
|
|
320
|
+
url: webhookUrl as string,
|
|
321
|
+
rate_limit: rateLimit,
|
|
322
|
+
rate_limit_period: rateLimitPeriod,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (!createResponse || !createResponse.id) {
|
|
326
|
+
throw new Error('Failed to create setup webhook: no webhook ID returned');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Get the webhook details to retrieve the signature secret
|
|
330
|
+
const webhookDetails = await client.webhooks.get(createResponse.id);
|
|
331
|
+
|
|
332
|
+
if (!webhookDetails || !webhookDetails.signature || !webhookDetails.signature.key) {
|
|
333
|
+
throw new Error(`Failed to retrieve setup webhook signature. Response: ${JSON.stringify(webhookDetails)}`);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
webhookData.setupWebhookId = createResponse.id;
|
|
337
|
+
webhookData.setupWebhookSecret = webhookDetails.signature.key;
|
|
338
|
+
|
|
339
|
+
return true;
|
|
340
|
+
} catch (error) {
|
|
341
|
+
throw new Error(`Failed to create setup webhook: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
async delete(this: IHookFunctions): Promise<boolean> {
|
|
346
|
+
const webhookData = this.getWorkflowStaticData('node');
|
|
347
|
+
|
|
348
|
+
if (webhookData.setupWebhookId !== undefined) {
|
|
349
|
+
const credentials = await this.getCredentials('cakemailApi');
|
|
350
|
+
const client = new CakemailClient({
|
|
351
|
+
email: credentials.email as string,
|
|
352
|
+
password: credentials.password as string,
|
|
353
|
+
baseURL: credentials.baseURL as string || 'https://api.cakemail.dev',
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
try {
|
|
357
|
+
await client.webhooks.archive(webhookData.setupWebhookId as string);
|
|
358
|
+
} catch (error) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
delete webhookData.setupWebhookId;
|
|
363
|
+
delete webhookData.setupWebhookSecret;
|
|
364
|
+
}
|
|
365
|
+
|
|
270
366
|
return true;
|
|
271
367
|
},
|
|
272
368
|
},
|
|
@@ -276,6 +372,7 @@ export class CakemailTrigger implements INodeType {
|
|
|
276
372
|
const req = this.getRequestObject();
|
|
277
373
|
const webhookData = this.getWorkflowStaticData('node');
|
|
278
374
|
const credentials = await this.getCredentials('cakemailApi');
|
|
375
|
+
const webhookName = this.getWebhookName();
|
|
279
376
|
|
|
280
377
|
const client = new CakemailClient({
|
|
281
378
|
email: credentials.email as string,
|
|
@@ -285,7 +382,11 @@ export class CakemailTrigger implements INodeType {
|
|
|
285
382
|
|
|
286
383
|
// Get signature from header
|
|
287
384
|
const signature = req.headers['x-signature'] as string;
|
|
288
|
-
|
|
385
|
+
|
|
386
|
+
// Determine which secret to use based on webhook name
|
|
387
|
+
const secret = webhookName === 'setup'
|
|
388
|
+
? (webhookData.setupWebhookSecret as string)
|
|
389
|
+
: (webhookData.webhookSecret as string);
|
|
289
390
|
|
|
290
391
|
if (!signature || !secret) {
|
|
291
392
|
return {
|