n8n-nodes-mailchimp-cmdesign 0.1.34 → 0.2.1

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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MailchimpCmNode = void 0;
7
7
  console.log('>>>> LOADING MailchimpCmNode.node.ts');
8
8
  const subscriberInputs_1 = __importDefault(require("./subscriberInputs"));
9
+ const createUpdateSubscriber_1 = require("./actions/createUpdateSubscriber");
9
10
  class MailchimpCmNode {
10
11
  constructor() {
11
12
  this.description = {
@@ -136,7 +137,15 @@ class MailchimpCmNode {
136
137
  }
137
138
  async execute() {
138
139
  const returnData = [];
139
- returnData.push({ json: { success: true, message: 'Execute működik, de nincs még API hívás.' } });
140
+ const credentials = await this.getCredentials('mailchimpCmApi');
141
+ const apiKey = credentials.apiKey;
142
+ const server = credentials.serverPrefix;
143
+ const apiUrl = `https://${server}.api.mailchimp.com/3.0`;
144
+ const action = this.getNodeParameter('action', 0);
145
+ if (action === 'createUpdateSubscriber') {
146
+ const response = await createUpdateSubscriber_1.createUpdateSubscriber.call(this, apiUrl, apiKey);
147
+ returnData.push({ json: response });
148
+ }
140
149
  return [returnData];
141
150
  }
142
151
  }
@@ -0,0 +1,2 @@
1
+ import type { IExecuteFunctions } from 'n8n-workflow';
2
+ export declare function createUpdateSubscriber(this: IExecuteFunctions, apiUrl: string, apiKey: string): Promise<any>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUpdateSubscriber = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ async function createUpdateSubscriber(apiUrl, apiKey) {
6
+ var _a, _b;
7
+ const listId = this.getNodeParameter('listId', 0);
8
+ const email = this.getNodeParameter('email', 0);
9
+ const createIfNotExists = this.getNodeParameter('createIfNotExists', 0);
10
+ const mapping = this.getNodeParameter('subscriberFieldMapping', 0);
11
+ const mergeFields = {};
12
+ if (((_a = mapping === null || mapping === void 0 ? void 0 : mapping.subscriberFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
13
+ for (const field of mapping.subscriberFields) {
14
+ mergeFields[field.mailChimpField] = String((_b = field.subscriberIncomingKey) !== null && _b !== void 0 ? _b : '');
15
+ }
16
+ }
17
+ const body = {
18
+ members: [
19
+ {
20
+ email_address: email,
21
+ status: 'subscribed',
22
+ merge_fields: mergeFields,
23
+ },
24
+ ],
25
+ update_existing: createIfNotExists,
26
+ };
27
+ try {
28
+ return await this.helpers.httpRequest({
29
+ method: 'POST',
30
+ url: `${apiUrl}/lists/${listId}`,
31
+ headers: {
32
+ Authorization: `apikey ${apiKey}`,
33
+ },
34
+ body,
35
+ json: true,
36
+ });
37
+ }
38
+ catch (error) {
39
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
40
+ message: 'Hiba történt az előfizető létrehozása/frissítése közben.',
41
+ });
42
+ }
43
+ }
44
+ exports.createUpdateSubscriber = createUpdateSubscriber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-mailchimp-cmdesign",
3
- "version": "0.1.34",
3
+ "version": "0.2.1",
4
4
  "description": "n8n node to interact with Mailchimp API",
5
5
  "main": "index.js",
6
6
  "scripts": {