@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.LESSER ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Language Mailchimp
2
+
3
+ An OpenFn **_adaptor_** for building integration jobs for use with the Mailchimp
4
+ marketing API.
5
+
6
+ ## Documentation
7
+
8
+ #### sample configuration
9
+
10
+ ```json
11
+ {
12
+ "apiKey": "someSecretShhh",
13
+ "server": "us11"
14
+ }
15
+ ```
16
+
17
+ #### sample expression with multiple operations
18
+
19
+ ```js
20
+ upsertMembers({
21
+ listId: 'someId',
22
+ users: state =>
23
+ state.response.body.rows.map(u => ({
24
+ email: u.email,
25
+ status: u.allow_other_emails ? 'subscribed' : 'unsubscribed',
26
+ mergeFields: { FNAME: u.first_name, LNAME: u.last_name },
27
+ })),
28
+ options: {},
29
+ });
30
+
31
+ tagMembers({
32
+ listId: 'someId', // All Subscribers
33
+ tagId: 'someTag', // User
34
+ members: state => state.response.body.rows.map(u => u.email),
35
+ });
36
+
37
+ tagMembers({
38
+ listId: 'someId', // All Subscribers
39
+ tagId: 'someTag', // Other Emails Allowed
40
+ members: state =>
41
+ state.response.body.rows
42
+ .filter(u => u.allow_other_emails)
43
+ .map(u => u.email),
44
+ });
45
+ ```
46
+
47
+ ## Development
48
+
49
+ Clone the [adaptors monorepo](https://github.com/OpenFn/adaptors). Follow the
50
+ `Getting Started` guide inside to get set up.
51
+
52
+ Run tests using `pnpm run test` or `pnpm run test:watch`
53
+
54
+ Build the project using `pnpm build`.
55
+
56
+ To just build the docs run `pnpm build docs`
package/ast.json ADDED
@@ -0,0 +1,423 @@
1
+ {
2
+ "operations": [],
3
+ "exports": [],
4
+ "common": [
5
+ {
6
+ "name": "fn",
7
+ "params": [
8
+ "func"
9
+ ],
10
+ "docs": {
11
+ "description": "Creates a custom step (or operation) for more flexible job writing.",
12
+ "tags": [
13
+ {
14
+ "title": "public",
15
+ "description": null,
16
+ "type": null
17
+ },
18
+ {
19
+ "title": "example",
20
+ "description": "fn(state => {\n // do some things to state\n return state;\n});"
21
+ },
22
+ {
23
+ "title": "function",
24
+ "description": null,
25
+ "name": null
26
+ },
27
+ {
28
+ "title": "param",
29
+ "description": "is the function",
30
+ "type": {
31
+ "type": "NameExpression",
32
+ "name": "Function"
33
+ },
34
+ "name": "func"
35
+ },
36
+ {
37
+ "title": "returns",
38
+ "description": null,
39
+ "type": {
40
+ "type": "NameExpression",
41
+ "name": "Operation"
42
+ }
43
+ }
44
+ ]
45
+ },
46
+ "valid": true
47
+ },
48
+ {
49
+ "name": "sourceValue",
50
+ "params": [
51
+ "path"
52
+ ],
53
+ "docs": {
54
+ "description": "Picks out a single value from source data.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
55
+ "tags": [
56
+ {
57
+ "title": "public",
58
+ "description": null,
59
+ "type": null
60
+ },
61
+ {
62
+ "title": "example",
63
+ "description": "sourceValue('$.key')"
64
+ },
65
+ {
66
+ "title": "function",
67
+ "description": null,
68
+ "name": null
69
+ },
70
+ {
71
+ "title": "param",
72
+ "description": "JSONPath referencing a point in `state`.",
73
+ "type": {
74
+ "type": "NameExpression",
75
+ "name": "String"
76
+ },
77
+ "name": "path"
78
+ },
79
+ {
80
+ "title": "returns",
81
+ "description": null,
82
+ "type": {
83
+ "type": "NameExpression",
84
+ "name": "Operation"
85
+ }
86
+ }
87
+ ]
88
+ },
89
+ "valid": true
90
+ },
91
+ {
92
+ "name": "dataPath",
93
+ "params": [
94
+ "path"
95
+ ],
96
+ "docs": {
97
+ "description": "Ensures a path points at the data.",
98
+ "tags": [
99
+ {
100
+ "title": "public",
101
+ "description": null,
102
+ "type": null
103
+ },
104
+ {
105
+ "title": "example",
106
+ "description": "dataPath('key')"
107
+ },
108
+ {
109
+ "title": "function",
110
+ "description": null,
111
+ "name": null
112
+ },
113
+ {
114
+ "title": "param",
115
+ "description": "JSONPath referencing a point in `data`.",
116
+ "type": {
117
+ "type": "NameExpression",
118
+ "name": "string"
119
+ },
120
+ "name": "path"
121
+ },
122
+ {
123
+ "title": "returns",
124
+ "description": null,
125
+ "type": {
126
+ "type": "NameExpression",
127
+ "name": "string"
128
+ }
129
+ }
130
+ ]
131
+ },
132
+ "valid": true
133
+ },
134
+ {
135
+ "name": "dataValue",
136
+ "params": [
137
+ "path"
138
+ ],
139
+ "docs": {
140
+ "description": "Picks out a single value from the source data object—usually `state.data`.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
141
+ "tags": [
142
+ {
143
+ "title": "public",
144
+ "description": null,
145
+ "type": null
146
+ },
147
+ {
148
+ "title": "example",
149
+ "description": "dataValue('key')"
150
+ },
151
+ {
152
+ "title": "function",
153
+ "description": null,
154
+ "name": null
155
+ },
156
+ {
157
+ "title": "param",
158
+ "description": "JSONPath referencing a point in `data`.",
159
+ "type": {
160
+ "type": "NameExpression",
161
+ "name": "String"
162
+ },
163
+ "name": "path"
164
+ },
165
+ {
166
+ "title": "returns",
167
+ "description": null,
168
+ "type": {
169
+ "type": "NameExpression",
170
+ "name": "Operation"
171
+ }
172
+ }
173
+ ]
174
+ },
175
+ "valid": true
176
+ },
177
+ {
178
+ "name": "lastReferenceValue",
179
+ "params": [
180
+ "path"
181
+ ],
182
+ "docs": {
183
+ "description": "Picks out the last reference value from source data.",
184
+ "tags": [
185
+ {
186
+ "title": "public",
187
+ "description": null,
188
+ "type": null
189
+ },
190
+ {
191
+ "title": "example",
192
+ "description": "lastReferenceValue('key')"
193
+ },
194
+ {
195
+ "title": "function",
196
+ "description": null,
197
+ "name": null
198
+ },
199
+ {
200
+ "title": "param",
201
+ "description": "JSONPath referencing a point in `references`.",
202
+ "type": {
203
+ "type": "NameExpression",
204
+ "name": "String"
205
+ },
206
+ "name": "path"
207
+ },
208
+ {
209
+ "title": "returns",
210
+ "description": null,
211
+ "type": {
212
+ "type": "NameExpression",
213
+ "name": "Operation"
214
+ }
215
+ }
216
+ ]
217
+ },
218
+ "valid": true
219
+ },
220
+ {
221
+ "name": "each",
222
+ "params": [
223
+ "dataSource",
224
+ "operation"
225
+ ],
226
+ "docs": {
227
+ "description": "Scopes an array of data based on a JSONPath.\nUseful when the source data has `n` items you would like to map to\nan operation.\nThe operation will receive a slice of the data based of each item\nof the JSONPath provided.\n\nIt also ensures the results of an operation make their way back into\nthe state's references.",
228
+ "tags": [
229
+ {
230
+ "title": "public",
231
+ "description": null,
232
+ "type": null
233
+ },
234
+ {
235
+ "title": "example",
236
+ "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
237
+ },
238
+ {
239
+ "title": "function",
240
+ "description": null,
241
+ "name": null
242
+ },
243
+ {
244
+ "title": "param",
245
+ "description": "JSONPath referencing a point in `state`.",
246
+ "type": {
247
+ "type": "NameExpression",
248
+ "name": "DataSource"
249
+ },
250
+ "name": "dataSource"
251
+ },
252
+ {
253
+ "title": "param",
254
+ "description": "The operation needed to be repeated.",
255
+ "type": {
256
+ "type": "NameExpression",
257
+ "name": "Operation"
258
+ },
259
+ "name": "operation"
260
+ },
261
+ {
262
+ "title": "returns",
263
+ "description": null,
264
+ "type": {
265
+ "type": "NameExpression",
266
+ "name": "Operation"
267
+ }
268
+ }
269
+ ]
270
+ },
271
+ "valid": true
272
+ },
273
+ {
274
+ "name": "field",
275
+ "params": [
276
+ "key",
277
+ "value"
278
+ ],
279
+ "docs": {
280
+ "description": "Returns a key, value pair in an array.",
281
+ "tags": [
282
+ {
283
+ "title": "public",
284
+ "description": null,
285
+ "type": null
286
+ },
287
+ {
288
+ "title": "example",
289
+ "description": "field('destination_field_name__c', 'value')"
290
+ },
291
+ {
292
+ "title": "function",
293
+ "description": null,
294
+ "name": null
295
+ },
296
+ {
297
+ "title": "param",
298
+ "description": "Name of the field",
299
+ "type": {
300
+ "type": "NameExpression",
301
+ "name": "string"
302
+ },
303
+ "name": "key"
304
+ },
305
+ {
306
+ "title": "param",
307
+ "description": "The value itself or a sourceable operation.",
308
+ "type": {
309
+ "type": "NameExpression",
310
+ "name": "Value"
311
+ },
312
+ "name": "value"
313
+ },
314
+ {
315
+ "title": "returns",
316
+ "description": null,
317
+ "type": {
318
+ "type": "NameExpression",
319
+ "name": "Field"
320
+ }
321
+ }
322
+ ]
323
+ },
324
+ "valid": true
325
+ },
326
+ {
327
+ "name": "fields",
328
+ "params": [
329
+ "fields"
330
+ ],
331
+ "docs": {
332
+ "description": "Zips key value pairs into an object.",
333
+ "tags": [
334
+ {
335
+ "title": "public",
336
+ "description": null,
337
+ "type": null
338
+ },
339
+ {
340
+ "title": "example",
341
+ "description": "fields(list_of_fields)"
342
+ },
343
+ {
344
+ "title": "function",
345
+ "description": null,
346
+ "name": null
347
+ },
348
+ {
349
+ "title": "param",
350
+ "description": "a list of fields",
351
+ "type": {
352
+ "type": "NameExpression",
353
+ "name": "Fields"
354
+ },
355
+ "name": "fields"
356
+ },
357
+ {
358
+ "title": "returns",
359
+ "description": null,
360
+ "type": {
361
+ "type": "NameExpression",
362
+ "name": "Object"
363
+ }
364
+ }
365
+ ]
366
+ },
367
+ "valid": true
368
+ },
369
+ {
370
+ "name": "merge",
371
+ "params": [
372
+ "dataSource",
373
+ "fields"
374
+ ],
375
+ "docs": {
376
+ "description": "Merges fields into each item in an array.",
377
+ "tags": [
378
+ {
379
+ "title": "public",
380
+ "description": null,
381
+ "type": null
382
+ },
383
+ {
384
+ "title": "example",
385
+ "description": "merge(\n \"$.books[*]\",\n fields(\n field( \"publisher\", sourceValue(\"$.publisher\") )\n )\n)"
386
+ },
387
+ {
388
+ "title": "function",
389
+ "description": null,
390
+ "name": null
391
+ },
392
+ {
393
+ "title": "param",
394
+ "description": null,
395
+ "type": {
396
+ "type": "NameExpression",
397
+ "name": "DataSource"
398
+ },
399
+ "name": "dataSource"
400
+ },
401
+ {
402
+ "title": "param",
403
+ "description": "Group of fields to merge in.",
404
+ "type": {
405
+ "type": "NameExpression",
406
+ "name": "Object"
407
+ },
408
+ "name": "fields"
409
+ },
410
+ {
411
+ "title": "returns",
412
+ "description": null,
413
+ "type": {
414
+ "type": "NameExpression",
415
+ "name": "DataSource"
416
+ }
417
+ }
418
+ ]
419
+ },
420
+ "valid": true
421
+ }
422
+ ]
423
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "server": {
5
+ "title": "Server URL",
6
+ "type": "string",
7
+ "description": "Mailchimp API domain URL",
8
+ "format": "uri",
9
+ "minLength": 1
10
+ },
11
+ "apiKey": {
12
+ "title": "API Key",
13
+ "type": "string",
14
+ "description": "Mailchimp API Key",
15
+ "writeOnly": true,
16
+ "minLength": 1
17
+ }
18
+ },
19
+ "type": "object",
20
+ "additionalProperties": true,
21
+ "required": [
22
+ "server",
23
+ "apiKey"
24
+ ]
25
+ }