@openfn/language-mailchimp 0.3.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.
- package/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +56 -0
- package/ast.json +423 -0
- package/configuration-schema.json +25 -0
- package/dist/index.cjs +163 -0
- package/dist/index.js +136 -0
- package/package.json +51 -0
- package/types/Adaptor.d.ts +92 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.js
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
alterState: () => import_language_common2.alterState,
|
|
29
|
+
axios: () => import_axios.default,
|
|
30
|
+
dataPath: () => import_language_common2.dataPath,
|
|
31
|
+
dataValue: () => import_language_common2.dataValue,
|
|
32
|
+
default: () => src_default,
|
|
33
|
+
each: () => import_language_common2.each,
|
|
34
|
+
execute: () => execute,
|
|
35
|
+
field: () => import_language_common2.field,
|
|
36
|
+
fields: () => import_language_common2.fields,
|
|
37
|
+
fn: () => import_language_common2.fn,
|
|
38
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
39
|
+
listBatches: () => listBatches,
|
|
40
|
+
md5: () => import_md5.default,
|
|
41
|
+
merge: () => import_language_common2.merge,
|
|
42
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
43
|
+
startBatch: () => startBatch,
|
|
44
|
+
tagMembers: () => tagMembers,
|
|
45
|
+
upsertMembers: () => upsertMembers
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(src_exports);
|
|
48
|
+
|
|
49
|
+
// src/Adaptor.js
|
|
50
|
+
var Adaptor_exports = {};
|
|
51
|
+
__export(Adaptor_exports, {
|
|
52
|
+
alterState: () => import_language_common2.alterState,
|
|
53
|
+
axios: () => import_axios.default,
|
|
54
|
+
dataPath: () => import_language_common2.dataPath,
|
|
55
|
+
dataValue: () => import_language_common2.dataValue,
|
|
56
|
+
each: () => import_language_common2.each,
|
|
57
|
+
execute: () => execute,
|
|
58
|
+
field: () => import_language_common2.field,
|
|
59
|
+
fields: () => import_language_common2.fields,
|
|
60
|
+
fn: () => import_language_common2.fn,
|
|
61
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
62
|
+
listBatches: () => listBatches,
|
|
63
|
+
md5: () => import_md5.default,
|
|
64
|
+
merge: () => import_language_common2.merge,
|
|
65
|
+
sourceValue: () => import_language_common2.sourceValue,
|
|
66
|
+
startBatch: () => startBatch,
|
|
67
|
+
tagMembers: () => tagMembers,
|
|
68
|
+
upsertMembers: () => upsertMembers
|
|
69
|
+
});
|
|
70
|
+
var import_language_common = require("@openfn/language-common");
|
|
71
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
72
|
+
var import_mailchimp_marketing = __toESM(require("@mailchimp/mailchimp_marketing"), 1);
|
|
73
|
+
var import_md5 = __toESM(require("md5"), 1);
|
|
74
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
75
|
+
function execute(...operations) {
|
|
76
|
+
const initialState = {
|
|
77
|
+
references: [],
|
|
78
|
+
data: null
|
|
79
|
+
};
|
|
80
|
+
return (state) => {
|
|
81
|
+
return (0, import_language_common.execute)(...operations)({
|
|
82
|
+
...initialState,
|
|
83
|
+
...state
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function upsertMembers(params) {
|
|
88
|
+
return (state) => {
|
|
89
|
+
const { apiKey, server } = state.configuration;
|
|
90
|
+
const { listId, users, options } = (0, import_language_common.expandReferences)(params)(state);
|
|
91
|
+
import_mailchimp_marketing.default.setConfig({ apiKey, server });
|
|
92
|
+
return Promise.all(
|
|
93
|
+
users.map(
|
|
94
|
+
(user) => import_mailchimp_marketing.default.lists.setListMember(listId, (0, import_md5.default)(user.email), {
|
|
95
|
+
email_address: user.email,
|
|
96
|
+
status_if_new: user.status,
|
|
97
|
+
merge_fields: user.mergeFields
|
|
98
|
+
}).then((response) => {
|
|
99
|
+
state.references.push(response);
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
).then(() => {
|
|
103
|
+
return state;
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function tagMembers(params) {
|
|
108
|
+
return (state) => {
|
|
109
|
+
const { apiKey, server } = state.configuration;
|
|
110
|
+
const { listId, tagId, members } = (0, import_language_common.expandReferences)(params)(state);
|
|
111
|
+
import_mailchimp_marketing.default.setConfig({ apiKey, server });
|
|
112
|
+
return import_mailchimp_marketing.default.lists.batchSegmentMembers({ members_to_add: members }, listId, tagId).then((response) => {
|
|
113
|
+
const nextState = (0, import_language_common.composeNextState)(state, response);
|
|
114
|
+
return nextState;
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function startBatch(params) {
|
|
119
|
+
return (state) => {
|
|
120
|
+
const { apiKey, server } = state.configuration;
|
|
121
|
+
const { operations } = (0, import_language_common.expandReferences)(params)(state);
|
|
122
|
+
import_mailchimp_marketing.default.setConfig({ apiKey, server });
|
|
123
|
+
return import_mailchimp_marketing.default.batches.start({ operations: [...operations] }).then((response) => {
|
|
124
|
+
console.log(response);
|
|
125
|
+
const nextState = (0, import_language_common.composeNextState)(state, response);
|
|
126
|
+
return nextState;
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function listBatches(params) {
|
|
131
|
+
return (state) => {
|
|
132
|
+
const { apiKey, server } = state.configuration;
|
|
133
|
+
import_mailchimp_marketing.default.setConfig({ apiKey, server });
|
|
134
|
+
return import_mailchimp_marketing.default.batches.list().then((response) => {
|
|
135
|
+
console.log(response);
|
|
136
|
+
const nextState = (0, import_language_common.composeNextState)(state, response);
|
|
137
|
+
return nextState;
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/index.js
|
|
143
|
+
var src_default = Adaptor_exports;
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
alterState,
|
|
147
|
+
axios,
|
|
148
|
+
dataPath,
|
|
149
|
+
dataValue,
|
|
150
|
+
each,
|
|
151
|
+
execute,
|
|
152
|
+
field,
|
|
153
|
+
fields,
|
|
154
|
+
fn,
|
|
155
|
+
lastReferenceValue,
|
|
156
|
+
listBatches,
|
|
157
|
+
md5,
|
|
158
|
+
merge,
|
|
159
|
+
sourceValue,
|
|
160
|
+
startBatch,
|
|
161
|
+
tagMembers,
|
|
162
|
+
upsertMembers
|
|
163
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/Adaptor.js
|
|
8
|
+
var Adaptor_exports = {};
|
|
9
|
+
__export(Adaptor_exports, {
|
|
10
|
+
alterState: () => alterState,
|
|
11
|
+
axios: () => axios,
|
|
12
|
+
dataPath: () => dataPath,
|
|
13
|
+
dataValue: () => dataValue,
|
|
14
|
+
each: () => each,
|
|
15
|
+
execute: () => execute,
|
|
16
|
+
field: () => field,
|
|
17
|
+
fields: () => fields,
|
|
18
|
+
fn: () => fn,
|
|
19
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
20
|
+
listBatches: () => listBatches,
|
|
21
|
+
md5: () => md5,
|
|
22
|
+
merge: () => merge,
|
|
23
|
+
sourceValue: () => sourceValue,
|
|
24
|
+
startBatch: () => startBatch,
|
|
25
|
+
tagMembers: () => tagMembers,
|
|
26
|
+
upsertMembers: () => upsertMembers
|
|
27
|
+
});
|
|
28
|
+
import {
|
|
29
|
+
execute as commonExecute,
|
|
30
|
+
composeNextState,
|
|
31
|
+
expandReferences
|
|
32
|
+
} from "@openfn/language-common";
|
|
33
|
+
import axios from "axios";
|
|
34
|
+
import client from "@mailchimp/mailchimp_marketing";
|
|
35
|
+
import md5 from "md5";
|
|
36
|
+
import {
|
|
37
|
+
fn,
|
|
38
|
+
alterState,
|
|
39
|
+
dataPath,
|
|
40
|
+
dataValue,
|
|
41
|
+
each,
|
|
42
|
+
field,
|
|
43
|
+
fields,
|
|
44
|
+
lastReferenceValue,
|
|
45
|
+
merge,
|
|
46
|
+
sourceValue
|
|
47
|
+
} from "@openfn/language-common";
|
|
48
|
+
function execute(...operations) {
|
|
49
|
+
const initialState = {
|
|
50
|
+
references: [],
|
|
51
|
+
data: null
|
|
52
|
+
};
|
|
53
|
+
return (state) => {
|
|
54
|
+
return commonExecute(...operations)({
|
|
55
|
+
...initialState,
|
|
56
|
+
...state
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function upsertMembers(params) {
|
|
61
|
+
return (state) => {
|
|
62
|
+
const { apiKey, server } = state.configuration;
|
|
63
|
+
const { listId, users, options } = expandReferences(params)(state);
|
|
64
|
+
client.setConfig({ apiKey, server });
|
|
65
|
+
return Promise.all(
|
|
66
|
+
users.map(
|
|
67
|
+
(user) => client.lists.setListMember(listId, md5(user.email), {
|
|
68
|
+
email_address: user.email,
|
|
69
|
+
status_if_new: user.status,
|
|
70
|
+
merge_fields: user.mergeFields
|
|
71
|
+
}).then((response) => {
|
|
72
|
+
state.references.push(response);
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
).then(() => {
|
|
76
|
+
return state;
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function tagMembers(params) {
|
|
81
|
+
return (state) => {
|
|
82
|
+
const { apiKey, server } = state.configuration;
|
|
83
|
+
const { listId, tagId, members } = expandReferences(params)(state);
|
|
84
|
+
client.setConfig({ apiKey, server });
|
|
85
|
+
return client.lists.batchSegmentMembers({ members_to_add: members }, listId, tagId).then((response) => {
|
|
86
|
+
const nextState = composeNextState(state, response);
|
|
87
|
+
return nextState;
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function startBatch(params) {
|
|
92
|
+
return (state) => {
|
|
93
|
+
const { apiKey, server } = state.configuration;
|
|
94
|
+
const { operations } = expandReferences(params)(state);
|
|
95
|
+
client.setConfig({ apiKey, server });
|
|
96
|
+
return client.batches.start({ operations: [...operations] }).then((response) => {
|
|
97
|
+
console.log(response);
|
|
98
|
+
const nextState = composeNextState(state, response);
|
|
99
|
+
return nextState;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function listBatches(params) {
|
|
104
|
+
return (state) => {
|
|
105
|
+
const { apiKey, server } = state.configuration;
|
|
106
|
+
client.setConfig({ apiKey, server });
|
|
107
|
+
return client.batches.list().then((response) => {
|
|
108
|
+
console.log(response);
|
|
109
|
+
const nextState = composeNextState(state, response);
|
|
110
|
+
return nextState;
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/index.js
|
|
116
|
+
var src_default = Adaptor_exports;
|
|
117
|
+
export {
|
|
118
|
+
alterState,
|
|
119
|
+
axios,
|
|
120
|
+
dataPath,
|
|
121
|
+
dataValue,
|
|
122
|
+
src_default as default,
|
|
123
|
+
each,
|
|
124
|
+
execute,
|
|
125
|
+
field,
|
|
126
|
+
fields,
|
|
127
|
+
fn,
|
|
128
|
+
lastReferenceValue,
|
|
129
|
+
listBatches,
|
|
130
|
+
md5,
|
|
131
|
+
merge,
|
|
132
|
+
sourceValue,
|
|
133
|
+
startBatch,
|
|
134
|
+
tagMembers,
|
|
135
|
+
upsertMembers
|
|
136
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-mailchimp",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "An OpenFn adaptor for use with Mailchimp",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"author": "Open Function Group",
|
|
7
|
+
"license": "LGPLv3",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"types/",
|
|
11
|
+
"ast.json",
|
|
12
|
+
"configuration-schema.json"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@mailchimp/mailchimp_marketing": "^3.0.80",
|
|
16
|
+
"@openfn/language-common": "^1.7.5",
|
|
17
|
+
"axios": "^0.20.0",
|
|
18
|
+
"md5": "^2.3.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@openfn/buildtools": "^1.0.2",
|
|
22
|
+
"@openfn/simple-ast": "0.4.1",
|
|
23
|
+
"assertion-error": "^1.1.0",
|
|
24
|
+
"chai": "^3.5.0",
|
|
25
|
+
"deep-eql": "^0.1.3",
|
|
26
|
+
"esno": "^0.16.3",
|
|
27
|
+
"mocha": "^7.2.0",
|
|
28
|
+
"nock": "^12.0.3",
|
|
29
|
+
"rimraf": "^3.0.2"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"require": "./dist/index.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"types": "types/index.d.ts",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "pnpm clean && build-adaptor mailchimp",
|
|
46
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
47
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
48
|
+
"clean": "rimraf dist types docs",
|
|
49
|
+
"pack": "pnpm pack --pack-destination ../../dist"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a sequence of operations.
|
|
3
|
+
* Wraps `@openfn/language-common/execute`, and prepends initial state for http.
|
|
4
|
+
* @example
|
|
5
|
+
* execute(
|
|
6
|
+
* create('foo'),
|
|
7
|
+
* delete('bar')
|
|
8
|
+
* )(state)
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {Operations} operations - Operations to be performed.
|
|
11
|
+
* @returns {Operation}
|
|
12
|
+
*/
|
|
13
|
+
export function execute(...operations: Operations): Operation;
|
|
14
|
+
export class execute {
|
|
15
|
+
/**
|
|
16
|
+
* Execute a sequence of operations.
|
|
17
|
+
* Wraps `@openfn/language-common/execute`, and prepends initial state for http.
|
|
18
|
+
* @example
|
|
19
|
+
* execute(
|
|
20
|
+
* create('foo'),
|
|
21
|
+
* delete('bar')
|
|
22
|
+
* )(state)
|
|
23
|
+
* @constructor
|
|
24
|
+
* @param {Operations} operations - Operations to be performed.
|
|
25
|
+
* @returns {Operation}
|
|
26
|
+
*/
|
|
27
|
+
constructor(...operations: Operations);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add members to a particular audience
|
|
31
|
+
* @example
|
|
32
|
+
* upsertMembers(params)
|
|
33
|
+
* @constructor
|
|
34
|
+
* @param {object} params - a listId, users, and options
|
|
35
|
+
* @returns {Operation}
|
|
36
|
+
*/
|
|
37
|
+
export function upsertMembers(params: object): Operation;
|
|
38
|
+
export class upsertMembers {
|
|
39
|
+
/**
|
|
40
|
+
* Add members to a particular audience
|
|
41
|
+
* @example
|
|
42
|
+
* upsertMembers(params)
|
|
43
|
+
* @constructor
|
|
44
|
+
* @param {object} params - a listId, users, and options
|
|
45
|
+
* @returns {Operation}
|
|
46
|
+
*/
|
|
47
|
+
constructor(params: object);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Tag members with a particular tag
|
|
51
|
+
* @example
|
|
52
|
+
* tagMembers(params)
|
|
53
|
+
* @constructor
|
|
54
|
+
* @param {object} params - a tagId, members, and a list
|
|
55
|
+
* @returns {Operation}
|
|
56
|
+
*/
|
|
57
|
+
export function tagMembers(params: object): Operation;
|
|
58
|
+
export class tagMembers {
|
|
59
|
+
/**
|
|
60
|
+
* Tag members with a particular tag
|
|
61
|
+
* @example
|
|
62
|
+
* tagMembers(params)
|
|
63
|
+
* @constructor
|
|
64
|
+
* @param {object} params - a tagId, members, and a list
|
|
65
|
+
* @returns {Operation}
|
|
66
|
+
*/
|
|
67
|
+
constructor(params: object);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Start a batch with a list of operations.
|
|
71
|
+
* @example
|
|
72
|
+
* startBatch(params)
|
|
73
|
+
* @constructor
|
|
74
|
+
* @param {object} params - operations batch job
|
|
75
|
+
* @returns {Operation}
|
|
76
|
+
*/
|
|
77
|
+
export function startBatch(params: object): Operation;
|
|
78
|
+
export class startBatch {
|
|
79
|
+
/**
|
|
80
|
+
* Start a batch with a list of operations.
|
|
81
|
+
* @example
|
|
82
|
+
* startBatch(params)
|
|
83
|
+
* @constructor
|
|
84
|
+
* @param {object} params - operations batch job
|
|
85
|
+
* @returns {Operation}
|
|
86
|
+
*/
|
|
87
|
+
constructor(params: object);
|
|
88
|
+
}
|
|
89
|
+
export function listBatches(params: any): (state: any) => any;
|
|
90
|
+
import axios from "axios";
|
|
91
|
+
export { axios, md5 };
|
|
92
|
+
export { fn, alterState, dataPath, dataValue, each, field, fields, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED