@openfn/language-mailchimp 0.7.4 → 1.0.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/ast.json +53 -0
- package/dist/index.cjs +31 -15
- package/dist/index.js +31 -15
- package/package.json +2 -2
- package/types/Adaptor.d.ts +1 -1
package/ast.json
CHANGED
|
@@ -45,6 +45,59 @@
|
|
|
45
45
|
},
|
|
46
46
|
"valid": true
|
|
47
47
|
},
|
|
48
|
+
{
|
|
49
|
+
"name": "fnIf",
|
|
50
|
+
"params": [
|
|
51
|
+
"condition",
|
|
52
|
+
"operation"
|
|
53
|
+
],
|
|
54
|
+
"docs": {
|
|
55
|
+
"description": "A custom operation that will only execute the function if the condition returns true",
|
|
56
|
+
"tags": [
|
|
57
|
+
{
|
|
58
|
+
"title": "public",
|
|
59
|
+
"description": null,
|
|
60
|
+
"type": null
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"title": "example",
|
|
64
|
+
"description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"title": "function",
|
|
68
|
+
"description": null,
|
|
69
|
+
"name": null
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"title": "param",
|
|
73
|
+
"description": "The condition that returns true",
|
|
74
|
+
"type": {
|
|
75
|
+
"type": "NameExpression",
|
|
76
|
+
"name": "Boolean"
|
|
77
|
+
},
|
|
78
|
+
"name": "condition"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"title": "param",
|
|
82
|
+
"description": "The operation needed to be executed.",
|
|
83
|
+
"type": {
|
|
84
|
+
"type": "NameExpression",
|
|
85
|
+
"name": "Operation"
|
|
86
|
+
},
|
|
87
|
+
"name": "operation"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"title": "returns",
|
|
91
|
+
"description": null,
|
|
92
|
+
"type": {
|
|
93
|
+
"type": "NameExpression",
|
|
94
|
+
"name": "Operation"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
"valid": true
|
|
100
|
+
},
|
|
48
101
|
{
|
|
49
102
|
"name": "sourceValue",
|
|
50
103
|
"params": [
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
field: () => import_language_common3.field,
|
|
40
40
|
fields: () => import_language_common3.fields,
|
|
41
41
|
fn: () => import_language_common3.fn,
|
|
42
|
+
fnIf: () => import_language_common3.fnIf,
|
|
42
43
|
get: () => get,
|
|
43
44
|
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
44
45
|
listAudienceInfo: () => listAudienceInfo,
|
|
@@ -74,6 +75,7 @@ __export(Adaptor_exports, {
|
|
|
74
75
|
field: () => import_language_common3.field,
|
|
75
76
|
fields: () => import_language_common3.fields,
|
|
76
77
|
fn: () => import_language_common3.fn,
|
|
78
|
+
fnIf: () => import_language_common3.fnIf,
|
|
77
79
|
get: () => get,
|
|
78
80
|
lastReferenceValue: () => import_language_common3.lastReferenceValue,
|
|
79
81
|
listAudienceInfo: () => listAudienceInfo,
|
|
@@ -250,17 +252,23 @@ var defaultOptions = {
|
|
|
250
252
|
query: {},
|
|
251
253
|
body: void 0
|
|
252
254
|
};
|
|
253
|
-
var assertOK = (response, fullUrl) => {
|
|
254
|
-
if (response.
|
|
255
|
-
const
|
|
256
|
-
|
|
255
|
+
var assertOK = async (response, fullUrl) => {
|
|
256
|
+
if (response.statusCode >= 400) {
|
|
257
|
+
const message = `Request to ${fullUrl} failed with status: ${response.statusCode}`;
|
|
258
|
+
console.error(message);
|
|
259
|
+
let mailchimpError;
|
|
260
|
+
try {
|
|
261
|
+
mailchimpError = await response.body.json();
|
|
262
|
+
} catch (e) {
|
|
263
|
+
console.warning("Error parsing mailchimp error body");
|
|
264
|
+
console.warning(e);
|
|
265
|
+
}
|
|
266
|
+
if (mailchimpError) {
|
|
267
|
+
throw mailchimpError;
|
|
268
|
+
}
|
|
269
|
+
const error = new Error(message);
|
|
270
|
+
error.status = response.statusCode;
|
|
257
271
|
error.url = fullUrl;
|
|
258
|
-
error.type = response.type;
|
|
259
|
-
error.title = response.title;
|
|
260
|
-
error.status = response.status;
|
|
261
|
-
error.detail = response.detail;
|
|
262
|
-
error.instance = response.instance;
|
|
263
|
-
error.errors = response.errors;
|
|
264
272
|
throw error;
|
|
265
273
|
}
|
|
266
274
|
};
|
|
@@ -290,13 +298,20 @@ function request(method, path, options, callback) {
|
|
|
290
298
|
query,
|
|
291
299
|
body: body ? JSON.stringify(body) : void 0
|
|
292
300
|
});
|
|
293
|
-
console.log(
|
|
294
|
-
|
|
295
|
-
|
|
301
|
+
console.log(response.statusCode, urlPath);
|
|
302
|
+
await assertOK(response, `https://${server}.api.mailchimp.com${urlPath}`);
|
|
303
|
+
let data = {};
|
|
304
|
+
if (response.statusCode !== 204) {
|
|
305
|
+
data = await response.body.json();
|
|
306
|
+
}
|
|
296
307
|
const nextState = {
|
|
297
308
|
...state,
|
|
298
|
-
data
|
|
299
|
-
response:
|
|
309
|
+
data,
|
|
310
|
+
response: {
|
|
311
|
+
headers: response.headers,
|
|
312
|
+
body: data,
|
|
313
|
+
statusCode: response.statusCode
|
|
314
|
+
}
|
|
300
315
|
};
|
|
301
316
|
if (callback)
|
|
302
317
|
return callback(nextState);
|
|
@@ -327,6 +342,7 @@ var src_default = Adaptor_exports;
|
|
|
327
342
|
field,
|
|
328
343
|
fields,
|
|
329
344
|
fn,
|
|
345
|
+
fnIf,
|
|
330
346
|
get,
|
|
331
347
|
lastReferenceValue,
|
|
332
348
|
listAudienceInfo,
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __export(Adaptor_exports, {
|
|
|
20
20
|
field: () => field,
|
|
21
21
|
fields: () => fields,
|
|
22
22
|
fn: () => fn,
|
|
23
|
+
fnIf: () => fnIf,
|
|
23
24
|
get: () => get,
|
|
24
25
|
lastReferenceValue: () => lastReferenceValue,
|
|
25
26
|
listAudienceInfo: () => listAudienceInfo,
|
|
@@ -66,6 +67,7 @@ function handleResponse(response, state, callback) {
|
|
|
66
67
|
// src/Adaptor.js
|
|
67
68
|
import {
|
|
68
69
|
fn,
|
|
70
|
+
fnIf,
|
|
69
71
|
alterState,
|
|
70
72
|
dataPath,
|
|
71
73
|
dataValue,
|
|
@@ -208,17 +210,23 @@ var defaultOptions = {
|
|
|
208
210
|
query: {},
|
|
209
211
|
body: void 0
|
|
210
212
|
};
|
|
211
|
-
var assertOK = (response, fullUrl) => {
|
|
212
|
-
if (response.
|
|
213
|
-
const
|
|
214
|
-
|
|
213
|
+
var assertOK = async (response, fullUrl) => {
|
|
214
|
+
if (response.statusCode >= 400) {
|
|
215
|
+
const message = `Request to ${fullUrl} failed with status: ${response.statusCode}`;
|
|
216
|
+
console.error(message);
|
|
217
|
+
let mailchimpError;
|
|
218
|
+
try {
|
|
219
|
+
mailchimpError = await response.body.json();
|
|
220
|
+
} catch (e) {
|
|
221
|
+
console.warning("Error parsing mailchimp error body");
|
|
222
|
+
console.warning(e);
|
|
223
|
+
}
|
|
224
|
+
if (mailchimpError) {
|
|
225
|
+
throw mailchimpError;
|
|
226
|
+
}
|
|
227
|
+
const error = new Error(message);
|
|
228
|
+
error.status = response.statusCode;
|
|
215
229
|
error.url = fullUrl;
|
|
216
|
-
error.type = response.type;
|
|
217
|
-
error.title = response.title;
|
|
218
|
-
error.status = response.status;
|
|
219
|
-
error.detail = response.detail;
|
|
220
|
-
error.instance = response.instance;
|
|
221
|
-
error.errors = response.errors;
|
|
222
230
|
throw error;
|
|
223
231
|
}
|
|
224
232
|
};
|
|
@@ -248,13 +256,20 @@ function request(method, path, options, callback) {
|
|
|
248
256
|
query,
|
|
249
257
|
body: body ? JSON.stringify(body) : void 0
|
|
250
258
|
});
|
|
251
|
-
console.log(
|
|
252
|
-
|
|
253
|
-
|
|
259
|
+
console.log(response.statusCode, urlPath);
|
|
260
|
+
await assertOK(response, `https://${server}.api.mailchimp.com${urlPath}`);
|
|
261
|
+
let data = {};
|
|
262
|
+
if (response.statusCode !== 204) {
|
|
263
|
+
data = await response.body.json();
|
|
264
|
+
}
|
|
254
265
|
const nextState = {
|
|
255
266
|
...state,
|
|
256
|
-
data
|
|
257
|
-
response:
|
|
267
|
+
data,
|
|
268
|
+
response: {
|
|
269
|
+
headers: response.headers,
|
|
270
|
+
body: data,
|
|
271
|
+
statusCode: response.statusCode
|
|
272
|
+
}
|
|
258
273
|
};
|
|
259
274
|
if (callback)
|
|
260
275
|
return callback(nextState);
|
|
@@ -285,6 +300,7 @@ export {
|
|
|
285
300
|
field,
|
|
286
301
|
fields,
|
|
287
302
|
fn,
|
|
303
|
+
fnIf,
|
|
288
304
|
get,
|
|
289
305
|
lastReferenceValue,
|
|
290
306
|
listAudienceInfo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-mailchimp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "An OpenFn adaptor for use with Mailchimp",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"author": "Open Function Group",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@mailchimp/mailchimp_marketing": "^3.0.80",
|
|
16
|
-
"@openfn/language-common": "^1.
|
|
16
|
+
"@openfn/language-common": "^1.14.0",
|
|
17
17
|
"axios": "^0.21.2",
|
|
18
18
|
"md5": "^2.3.0",
|
|
19
19
|
"undici": "^5.28.4"
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -173,4 +173,4 @@ export function get(path: string, query: object, callback?: Function): Operation
|
|
|
173
173
|
export function post(path: string, body: object, query: object, callback?: Function): Operation;
|
|
174
174
|
import axios from "axios";
|
|
175
175
|
export { axios, md5 };
|
|
176
|
-
export { fn, alterState, dataPath, dataValue, each, field, fields, lastReferenceValue, merge, chunk, sourceValue } from "@openfn/language-common";
|
|
176
|
+
export { fn, fnIf, alterState, dataPath, dataValue, each, field, fields, lastReferenceValue, merge, chunk, sourceValue } from "@openfn/language-common";
|