@openfn/language-mailchimp 0.6.0 → 0.7.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.
package/ast.json CHANGED
@@ -418,6 +418,59 @@
418
418
  ]
419
419
  },
420
420
  "valid": true
421
+ },
422
+ {
423
+ "name": "chunk",
424
+ "params": [
425
+ "array",
426
+ "chunkSize"
427
+ ],
428
+ "docs": {
429
+ "description": "Chunks an array into an array of arrays, each with no more than a certain size.",
430
+ "tags": [
431
+ {
432
+ "title": "public",
433
+ "description": null,
434
+ "type": null
435
+ },
436
+ {
437
+ "title": "example",
438
+ "description": "chunk([1,2,3,4,5], 2)"
439
+ },
440
+ {
441
+ "title": "function",
442
+ "description": null,
443
+ "name": null
444
+ },
445
+ {
446
+ "title": "param",
447
+ "description": "Array to be chunked",
448
+ "type": {
449
+ "type": "NameExpression",
450
+ "name": "Object"
451
+ },
452
+ "name": "array"
453
+ },
454
+ {
455
+ "title": "param",
456
+ "description": "The maxiumum size of each chunks",
457
+ "type": {
458
+ "type": "NameExpression",
459
+ "name": "Integer"
460
+ },
461
+ "name": "chunkSize"
462
+ },
463
+ {
464
+ "title": "returns",
465
+ "description": null,
466
+ "type": {
467
+ "type": "NameExpression",
468
+ "name": "Object"
469
+ }
470
+ }
471
+ ]
472
+ },
473
+ "valid": true
421
474
  }
422
475
  ]
423
476
  }
@@ -2,24 +2,26 @@
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "properties": {
4
4
  "server": {
5
- "title": "Server URL",
5
+ "title": "Data Center",
6
6
  "type": "string",
7
- "description": "Mailchimp API domain URL",
8
- "format": "uri",
9
- "minLength": 1,
7
+ "description": "Mailchimp Data Center for your account",
8
+ "minLength": 3,
10
9
  "examples": [
11
- "https://mailchimp.com/api"
12
- ]
10
+ "us11",
11
+ "uk8",
12
+ "in10"
13
+ ],
14
+ "pattern": "^[a-zA-Z]{2}\\d{1,2}$"
13
15
  },
14
16
  "apiKey": {
15
17
  "title": "API Key",
16
18
  "type": "string",
17
19
  "description": "Mailchimp API Key",
18
- "writeOnly": true,
19
- "minLength": 1,
20
+ "minLength": 32,
20
21
  "examples": [
21
- "somEThINGkeyish"
22
- ]
22
+ "0eb22c7b4a1c5bcd789379bf8a92902d-us13"
23
+ ],
24
+ "pattern": "^[a-zA-Z0-9]{20}-[a-zA-Z]{2}\\d{1,2}$"
23
25
  }
24
26
  },
25
27
  "type": "object",
package/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ __export(src_exports, {
29
29
  alterState: () => import_language_common3.alterState,
30
30
  archiveMember: () => archiveMember,
31
31
  axios: () => import_axios.default,
32
+ chunk: () => import_language_common3.chunk,
32
33
  dataPath: () => import_language_common3.dataPath,
33
34
  dataValue: () => import_language_common3.dataValue,
34
35
  default: () => src_default,
@@ -64,6 +65,7 @@ __export(Adaptor_exports, {
64
65
  alterState: () => import_language_common3.alterState,
65
66
  archiveMember: () => archiveMember,
66
67
  axios: () => import_axios.default,
68
+ chunk: () => import_language_common3.chunk,
67
69
  dataPath: () => import_language_common3.dataPath,
68
70
  dataValue: () => import_language_common3.dataValue,
69
71
  deleteMember: () => deleteMember,
@@ -250,15 +252,20 @@ var defaultOptions = {
250
252
  body: void 0
251
253
  };
252
254
  var assertOK = (response, fullUrl) => {
253
- if (response.statusCode >= 400) {
254
- const defaultErrorMesssage = `Request to ${fullUrl} failed with status: ${response.statusCode}`;
255
+ if (response.status >= 400) {
256
+ const defaultErrorMesssage = `Request to ${fullUrl} failed with status: ${response.status}`;
255
257
  const error = new Error(defaultErrorMesssage);
256
- error.code = response.statusCode;
257
258
  error.url = fullUrl;
259
+ error.type = response.type;
260
+ error.title = response.title;
261
+ error.status = response.status;
262
+ error.detail = response.detail;
263
+ error.instance = response.instance;
264
+ error.errors = response.errors;
258
265
  throw error;
259
266
  }
260
267
  };
261
- var request = (method, path, options, callback) => {
268
+ function request(method, path, options, callback) {
262
269
  return async (state) => {
263
270
  const apiVersion = "3.0";
264
271
  const { apiKey, server } = state.configuration;
@@ -284,9 +291,11 @@ var request = (method, path, options, callback) => {
284
291
  query,
285
292
  body: body ? JSON.stringify(body) : void 0
286
293
  });
287
- assertOK(response, `https://${server}.api.mailchimp.com${urlPath}`);
294
+ console.log("Mailchimp says", response.statusCode);
288
295
  const responseBody = await response.body.json();
296
+ assertOK(responseBody, `https://${server}.api.mailchimp.com${urlPath}`);
289
297
  const nextState = {
298
+ ...state,
290
299
  data: responseBody,
291
300
  response: responseBody
292
301
  };
@@ -294,9 +303,13 @@ var request = (method, path, options, callback) => {
294
303
  return callback(nextState);
295
304
  return nextState;
296
305
  };
297
- };
298
- var get = (path, query, callback) => request("GET", path, { query }, callback);
299
- var post = (path, body, query, callback) => request("POST", path, { body, query }, callback);
306
+ }
307
+ function get(path, query, callback) {
308
+ return request("GET", path, { query }, callback);
309
+ }
310
+ function post(path, body, query, callback) {
311
+ return request("POST", path, { body, query }, callback);
312
+ }
300
313
 
301
314
  // src/index.js
302
315
  var src_default = Adaptor_exports;
@@ -306,6 +319,7 @@ var src_default = Adaptor_exports;
306
319
  alterState,
307
320
  archiveMember,
308
321
  axios,
322
+ chunk,
309
323
  dataPath,
310
324
  dataValue,
311
325
  deleteMember,
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ __export(Adaptor_exports, {
11
11
  alterState: () => alterState,
12
12
  archiveMember: () => archiveMember,
13
13
  axios: () => axios,
14
+ chunk: () => chunk,
14
15
  dataPath: () => dataPath,
15
16
  dataValue: () => dataValue,
16
17
  deleteMember: () => deleteMember,
@@ -73,6 +74,7 @@ import {
73
74
  fields,
74
75
  lastReferenceValue,
75
76
  merge,
77
+ chunk,
76
78
  sourceValue
77
79
  } from "@openfn/language-common";
78
80
  function execute(...operations) {
@@ -208,15 +210,20 @@ var defaultOptions = {
208
210
  body: void 0
209
211
  };
210
212
  var assertOK = (response, fullUrl) => {
211
- if (response.statusCode >= 400) {
212
- const defaultErrorMesssage = `Request to ${fullUrl} failed with status: ${response.statusCode}`;
213
+ if (response.status >= 400) {
214
+ const defaultErrorMesssage = `Request to ${fullUrl} failed with status: ${response.status}`;
213
215
  const error = new Error(defaultErrorMesssage);
214
- error.code = response.statusCode;
215
216
  error.url = fullUrl;
217
+ error.type = response.type;
218
+ error.title = response.title;
219
+ error.status = response.status;
220
+ error.detail = response.detail;
221
+ error.instance = response.instance;
222
+ error.errors = response.errors;
216
223
  throw error;
217
224
  }
218
225
  };
219
- var request = (method, path, options, callback) => {
226
+ function request(method, path, options, callback) {
220
227
  return async (state) => {
221
228
  const apiVersion = "3.0";
222
229
  const { apiKey, server } = state.configuration;
@@ -242,9 +249,11 @@ var request = (method, path, options, callback) => {
242
249
  query,
243
250
  body: body ? JSON.stringify(body) : void 0
244
251
  });
245
- assertOK(response, `https://${server}.api.mailchimp.com${urlPath}`);
252
+ console.log("Mailchimp says", response.statusCode);
246
253
  const responseBody = await response.body.json();
254
+ assertOK(responseBody, `https://${server}.api.mailchimp.com${urlPath}`);
247
255
  const nextState = {
256
+ ...state,
248
257
  data: responseBody,
249
258
  response: responseBody
250
259
  };
@@ -252,9 +261,13 @@ var request = (method, path, options, callback) => {
252
261
  return callback(nextState);
253
262
  return nextState;
254
263
  };
255
- };
256
- var get = (path, query, callback) => request("GET", path, { query }, callback);
257
- var post = (path, body, query, callback) => request("POST", path, { body, query }, callback);
264
+ }
265
+ function get(path, query, callback) {
266
+ return request("GET", path, { query }, callback);
267
+ }
268
+ function post(path, body, query, callback) {
269
+ return request("POST", path, { body, query }, callback);
270
+ }
258
271
 
259
272
  // src/index.js
260
273
  var src_default = Adaptor_exports;
@@ -263,6 +276,7 @@ export {
263
276
  alterState,
264
277
  archiveMember,
265
278
  axios,
279
+ chunk,
266
280
  dataPath,
267
281
  dataValue,
268
282
  src_default as default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-mailchimp",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "An OpenFn adaptor for use with Mailchimp",
5
5
  "main": "dist/index.cjs",
6
6
  "author": "Open Function Group",
@@ -133,9 +133,44 @@ export function listAudiences(query: object, callback?: Function): Operation;
133
133
  * @returns {Operation}
134
134
  */
135
135
  export function listAudienceInfo(query: object, callback?: Function): Operation;
136
+ /**
137
+ * Make an HTTP request to Mailchimp API
138
+ * @example <caption>Get list to all other resources available in the API</caption>
139
+ * request('GET','/');
140
+ * @example <caption>Create a new account export in your Mailchimp account</caption>
141
+ * request('POST','/accounts-export', {include_stages:[]});
142
+ * @function
143
+ * @param {string} method - The HTTP method for the request (e.g., 'GET', 'POST', 'PUT', 'DELETE').
144
+ * @param {string} path - The endpoint of the api to which the request should be made.
145
+ * @param {Object} options - Additional options for the request (query, body only).
146
+ * @param {function} [callback] - (Optional) callback function to handle the response.
147
+ * @returns {Operation}
148
+ */
136
149
  export function request(method: string, path: string, options: any, callback?: Function): Operation;
150
+ /**
151
+ * The get function is used to make a GET request to the Mailchimp API.
152
+ * @example <caption>Get a list of account exports for a given account</caption>
153
+ * get('/account-exports');
154
+ * @function
155
+ * @param {string} path - The endpoint of the api to which the request should be made
156
+ * @param {object} query - An object containing query parameters to be included in the request
157
+ * @param {function} [callback] - (Optional) callback to handle the response
158
+ * @returns {Operation}
159
+ */
137
160
  export function get(path: string, query: object, callback?: Function): Operation;
161
+ /**
162
+ * The post function is used to make a POST request to the Mailchimp API.
163
+ *
164
+ * @example <caption>Create a new account export in your Mailchimp account</caption>
165
+ * post('/accounts-export', {include_stages:[]});
166
+ * @function
167
+ * @param {string} path - The endpoint of the api to which the request should be made.
168
+ * @param {object} body - The data to be sent in the body of the request
169
+ * @param {object} query - An object containing query parameters to be included in the request
170
+ * @param {function} [callback] - (Optional) callback to handle the response
171
+ * @returns {Operation}
172
+ */
138
173
  export function post(path: string, body: object, query: object, callback?: Function): Operation;
139
174
  import axios from "axios";
140
175
  export { axios, md5 };
141
- export { fn, alterState, dataPath, dataValue, each, field, fields, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
176
+ export { fn, alterState, dataPath, dataValue, each, field, fields, lastReferenceValue, merge, chunk, sourceValue } from "@openfn/language-common";