@openfn/language-asana 3.2.0 → 4.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 CHANGED
@@ -304,6 +304,143 @@
304
304
  ]
305
305
  },
306
306
  "valid": true
307
+ },
308
+ {
309
+ "name": "createTaskStory",
310
+ "params": [
311
+ "taskGid",
312
+ "params",
313
+ "callback"
314
+ ],
315
+ "docs": {
316
+ "description": "Options provided to the createTaskStory request",
317
+ "tags": [
318
+ {
319
+ "title": "typedef",
320
+ "description": null,
321
+ "type": {
322
+ "type": "NameExpression",
323
+ "name": "Object"
324
+ },
325
+ "name": "StoryOptions"
326
+ },
327
+ {
328
+ "title": "public",
329
+ "description": null,
330
+ "type": null
331
+ },
332
+ {
333
+ "title": "property",
334
+ "description": "The plain text of the comment to add. Cannot be used with html_text.",
335
+ "type": {
336
+ "type": "NameExpression",
337
+ "name": "string"
338
+ },
339
+ "name": "text"
340
+ },
341
+ {
342
+ "title": "property",
343
+ "description": "Opt In. HTML formatted text for a comment. This will not include the name of the creator.",
344
+ "type": {
345
+ "type": "NameExpression",
346
+ "name": "string"
347
+ },
348
+ "name": "html_text"
349
+ },
350
+ {
351
+ "title": "property",
352
+ "description": "Default to `false`. Whether the story should be pinned on the resource.",
353
+ "type": {
354
+ "type": "NameExpression",
355
+ "name": "boolean"
356
+ },
357
+ "name": "is_pinned"
358
+ },
359
+ {
360
+ "title": "property",
361
+ "description": "The name of the sticker in this story. `null` if there is no sticker.",
362
+ "type": {
363
+ "type": "NameExpression",
364
+ "name": "string"
365
+ },
366
+ "name": "sticker_name"
367
+ },
368
+ {
369
+ "title": "property",
370
+ "description": "Opt In. This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include.",
371
+ "type": {
372
+ "type": "NameExpression",
373
+ "name": "array"
374
+ },
375
+ "name": "opt_fields"
376
+ },
377
+ {
378
+ "title": "property",
379
+ "description": "Defaults to `false`. Provides the response in a “pretty” format. In the case of JSON this means doing proper line breaking and indentation to make it readable. This will take extra time and increase the response size so it is advisable only to use this during debugging.",
380
+ "type": {
381
+ "type": "NameExpression",
382
+ "name": "boolean"
383
+ },
384
+ "name": "opt_pretty"
385
+ }
386
+ ]
387
+ },
388
+ "valid": false
389
+ },
390
+ {
391
+ "name": "request",
392
+ "params": [
393
+ "path",
394
+ "params",
395
+ "callback"
396
+ ],
397
+ "docs": {
398
+ "description": "Options provided to the Asana API request",
399
+ "tags": [
400
+ {
401
+ "title": "typedef",
402
+ "description": null,
403
+ "type": {
404
+ "type": "NameExpression",
405
+ "name": "Object"
406
+ },
407
+ "name": "RequestOptions"
408
+ },
409
+ {
410
+ "title": "public",
411
+ "description": null,
412
+ "type": null
413
+ },
414
+ {
415
+ "title": "property",
416
+ "description": "Body data to append to the request.",
417
+ "type": {
418
+ "type": "NameExpression",
419
+ "name": "object"
420
+ },
421
+ "name": "body"
422
+ },
423
+ {
424
+ "title": "property",
425
+ "description": "An object of query parameters to be encoded into the URL.",
426
+ "type": {
427
+ "type": "NameExpression",
428
+ "name": "object"
429
+ },
430
+ "name": "query"
431
+ },
432
+ {
433
+ "title": "property",
434
+ "description": "The HTTP method to use. Defaults to `GET`",
435
+ "type": {
436
+ "type": "NameExpression",
437
+ "name": "string"
438
+ },
439
+ "name": "method"
440
+ }
441
+ ]
442
+ },
443
+ "valid": false
307
444
  }
308
445
  ],
309
446
  "exports": [],
@@ -321,23 +458,76 @@
321
458
  "description": null,
322
459
  "type": null
323
460
  },
461
+ {
462
+ "title": "function",
463
+ "description": null,
464
+ "name": null
465
+ },
324
466
  {
325
467
  "title": "example",
326
468
  "description": "fn(state => {\n // do some things to state\n return state;\n});"
327
469
  },
470
+ {
471
+ "title": "param",
472
+ "description": "is the function",
473
+ "type": {
474
+ "type": "NameExpression",
475
+ "name": "Function"
476
+ },
477
+ "name": "func"
478
+ },
479
+ {
480
+ "title": "returns",
481
+ "description": null,
482
+ "type": {
483
+ "type": "NameExpression",
484
+ "name": "Operation"
485
+ }
486
+ }
487
+ ]
488
+ },
489
+ "valid": true
490
+ },
491
+ {
492
+ "name": "fnIf",
493
+ "params": [
494
+ "condition",
495
+ "operation"
496
+ ],
497
+ "docs": {
498
+ "description": "A custom operation that will only execute the function if the condition returns true",
499
+ "tags": [
500
+ {
501
+ "title": "public",
502
+ "description": null,
503
+ "type": null
504
+ },
328
505
  {
329
506
  "title": "function",
330
507
  "description": null,
331
508
  "name": null
332
509
  },
510
+ {
511
+ "title": "example",
512
+ "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
513
+ },
333
514
  {
334
515
  "title": "param",
335
- "description": "is the function",
516
+ "description": "The condition that returns true",
336
517
  "type": {
337
518
  "type": "NameExpression",
338
- "name": "Function"
519
+ "name": "Boolean"
339
520
  },
340
- "name": "func"
521
+ "name": "condition"
522
+ },
523
+ {
524
+ "title": "param",
525
+ "description": "The operation needed to be executed.",
526
+ "type": {
527
+ "type": "NameExpression",
528
+ "name": "Operation"
529
+ },
530
+ "name": "operation"
341
531
  },
342
532
  {
343
533
  "title": "returns",
@@ -364,15 +554,15 @@
364
554
  "description": null,
365
555
  "type": null
366
556
  },
367
- {
368
- "title": "example",
369
- "description": "sourceValue('$.key')"
370
- },
371
557
  {
372
558
  "title": "function",
373
559
  "description": null,
374
560
  "name": null
375
561
  },
562
+ {
563
+ "title": "example",
564
+ "description": "sourceValue('$.key')"
565
+ },
376
566
  {
377
567
  "title": "param",
378
568
  "description": "JSONPath referencing a point in `state`.",
@@ -407,15 +597,15 @@
407
597
  "description": null,
408
598
  "type": null
409
599
  },
410
- {
411
- "title": "example",
412
- "description": "dataPath('key')"
413
- },
414
600
  {
415
601
  "title": "function",
416
602
  "description": null,
417
603
  "name": null
418
604
  },
605
+ {
606
+ "title": "example",
607
+ "description": "dataPath('key')"
608
+ },
419
609
  {
420
610
  "title": "param",
421
611
  "description": "JSONPath referencing a point in `data`.",
@@ -450,15 +640,15 @@
450
640
  "description": null,
451
641
  "type": null
452
642
  },
453
- {
454
- "title": "example",
455
- "description": "dataValue('key')"
456
- },
457
643
  {
458
644
  "title": "function",
459
645
  "description": null,
460
646
  "name": null
461
647
  },
648
+ {
649
+ "title": "example",
650
+ "description": "dataValue('key')"
651
+ },
462
652
  {
463
653
  "title": "param",
464
654
  "description": "JSONPath referencing a point in `data`.",
@@ -493,15 +683,15 @@
493
683
  "description": null,
494
684
  "type": null
495
685
  },
496
- {
497
- "title": "example",
498
- "description": "lastReferenceValue('key')"
499
- },
500
686
  {
501
687
  "title": "function",
502
688
  "description": null,
503
689
  "name": null
504
690
  },
691
+ {
692
+ "title": "example",
693
+ "description": "lastReferenceValue('key')"
694
+ },
505
695
  {
506
696
  "title": "param",
507
697
  "description": "JSONPath referencing a point in `references`.",
@@ -537,15 +727,15 @@
537
727
  "description": null,
538
728
  "type": null
539
729
  },
540
- {
541
- "title": "example",
542
- "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
543
- },
544
730
  {
545
731
  "title": "function",
546
732
  "description": null,
547
733
  "name": null
548
734
  },
735
+ {
736
+ "title": "example",
737
+ "description": "each(\"$.[*]\",\n create(\"SObject\",\n field(\"FirstName\", sourceValue(\"$.firstName\"))\n )\n)"
738
+ },
549
739
  {
550
740
  "title": "param",
551
741
  "description": "JSONPath referencing a point in `state`.",
@@ -590,15 +780,15 @@
590
780
  "description": null,
591
781
  "type": null
592
782
  },
593
- {
594
- "title": "example",
595
- "description": "field('destination_field_name__c', 'value')"
596
- },
597
783
  {
598
784
  "title": "function",
599
785
  "description": null,
600
786
  "name": null
601
787
  },
788
+ {
789
+ "title": "example",
790
+ "description": "field('destination_field_name__c', 'value')"
791
+ },
602
792
  {
603
793
  "title": "param",
604
794
  "description": "Name of the field",
@@ -642,15 +832,15 @@
642
832
  "description": null,
643
833
  "type": null
644
834
  },
645
- {
646
- "title": "example",
647
- "description": "fields(list_of_fields)"
648
- },
649
835
  {
650
836
  "title": "function",
651
837
  "description": null,
652
838
  "name": null
653
839
  },
840
+ {
841
+ "title": "example",
842
+ "description": "fields(list_of_fields)"
843
+ },
654
844
  {
655
845
  "title": "param",
656
846
  "description": "a list of fields",
@@ -695,6 +885,11 @@
695
885
  "description": null,
696
886
  "name": null
697
887
  },
888
+ {
889
+ "title": "public",
890
+ "description": null,
891
+ "type": null
892
+ },
698
893
  {
699
894
  "title": "param",
700
895
  "description": null,
@@ -732,13 +927,18 @@
732
927
  "options"
733
928
  ],
734
929
  "docs": {
735
- "description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones \nare not yet supported.\nSee the usage guide at @{link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
930
+ "description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones\nare not yet supported.\nYou can provide a formatter to customise the final cursor value, which is useful for normalising\ndifferent inputs. The custom formatter runs after natural language date conversion.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
736
931
  "tags": [
737
932
  {
738
933
  "title": "public",
739
934
  "description": null,
740
935
  "type": null
741
936
  },
937
+ {
938
+ "title": "function",
939
+ "description": null,
940
+ "name": null
941
+ },
742
942
  {
743
943
  "title": "example",
744
944
  "description": "cursor($.cursor, { defaultValue: 'today' })",
@@ -749,11 +949,6 @@
749
949
  "description": "cursor(22)",
750
950
  "caption": "Use a pagination cursor"
751
951
  },
752
- {
753
- "title": "function",
754
- "description": null,
755
- "name": null
756
- },
757
952
  {
758
953
  "title": "param",
759
954
  "description": "the cursor value. Usually an ISO date, natural language date, or page number",
@@ -790,6 +985,15 @@
790
985
  },
791
986
  "name": "options.defaultValue"
792
987
  },
988
+ {
989
+ "title": "param",
990
+ "description": "custom formatter for the final cursor value",
991
+ "type": {
992
+ "type": "NameExpression",
993
+ "name": "Function"
994
+ },
995
+ "name": "options.format"
996
+ },
793
997
  {
794
998
  "title": "returns",
795
999
  "description": null,
package/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ __export(src_exports, {
32
32
  field: () => import_language_common3.field,
33
33
  fields: () => import_language_common3.fields,
34
34
  fn: () => import_language_common3.fn,
35
+ fnIf: () => import_language_common3.fnIf,
35
36
  getTask: () => getTask,
36
37
  getTasks: () => getTasks,
37
38
  http: () => import_language_common3.http,
@@ -59,6 +60,7 @@ __export(Adaptor_exports, {
59
60
  field: () => import_language_common3.field,
60
61
  fields: () => import_language_common3.fields,
61
62
  fn: () => import_language_common3.fn,
63
+ fnIf: () => import_language_common3.fnIf,
62
64
  getTask: () => getTask,
63
65
  getTasks: () => getTasks,
64
66
  http: () => import_language_common3.http,
@@ -100,8 +102,10 @@ function request(state, path, params, callback = (s) => s) {
100
102
  response: responseWithoutBody
101
103
  };
102
104
  }).then(callback).catch((err) => {
103
- console.log("Asana says:");
104
- (0, import_util.logResponse)(err);
105
+ if (err.code !== "BASE_URL_MISMATCH") {
106
+ console.log("Asana says:");
107
+ (0, import_util.logResponse)(err);
108
+ }
105
109
  throw err;
106
110
  });
107
111
  }
@@ -230,9 +234,14 @@ function createTaskStory(taskGid, params, callback) {
230
234
  );
231
235
  };
232
236
  }
233
- function request2(path, params, callback) {
237
+ function request2(path, params = {}, callback) {
234
238
  return (state) => {
235
- const [resolvedPath, { body = {}, query = {}, method = "GET" }] = (0, import_util2.expandReferences)(state, path, params);
239
+ const [resolvedPath, resolvedParams] = (0, import_util2.expandReferences)(
240
+ state,
241
+ path,
242
+ params
243
+ );
244
+ const { body = {}, query = {}, method = "GET" } = resolvedParams;
236
245
  return request(
237
246
  state,
238
247
  resolvedPath,
@@ -258,6 +267,7 @@ var src_default = Adaptor_exports;
258
267
  field,
259
268
  fields,
260
269
  fn,
270
+ fnIf,
261
271
  getTask,
262
272
  getTasks,
263
273
  http,
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ __export(Adaptor_exports, {
19
19
  field: () => field,
20
20
  fields: () => fields,
21
21
  fn: () => fn,
22
+ fnIf: () => fnIf,
22
23
  getTask: () => getTask,
23
24
  getTasks: () => getTasks,
24
25
  http: () => http,
@@ -63,8 +64,10 @@ function request(state, path, params, callback = (s) => s) {
63
64
  response: responseWithoutBody
64
65
  };
65
66
  }).then(callback).catch((err) => {
66
- console.log("Asana says:");
67
- logResponse(err);
67
+ if (err.code !== "BASE_URL_MISMATCH") {
68
+ console.log("Asana says:");
69
+ logResponse(err);
70
+ }
68
71
  throw err;
69
72
  });
70
73
  }
@@ -80,6 +83,7 @@ import {
80
83
  field,
81
84
  fields,
82
85
  fn,
86
+ fnIf,
83
87
  http,
84
88
  lastReferenceValue,
85
89
  merge,
@@ -207,9 +211,14 @@ function createTaskStory(taskGid, params, callback) {
207
211
  );
208
212
  };
209
213
  }
210
- function request2(path, params, callback) {
214
+ function request2(path, params = {}, callback) {
211
215
  return (state) => {
212
- const [resolvedPath, { body = {}, query = {}, method = "GET" }] = expandReferences(state, path, params);
216
+ const [resolvedPath, resolvedParams] = expandReferences(
217
+ state,
218
+ path,
219
+ params
220
+ );
221
+ const { body = {}, query = {}, method = "GET" } = resolvedParams;
213
222
  return request(
214
223
  state,
215
224
  resolvedPath,
@@ -235,6 +244,7 @@ export {
235
244
  field,
236
245
  fields,
237
246
  fn,
247
+ fnIf,
238
248
  getTask,
239
249
  getTasks,
240
250
  http,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-asana",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "description": "An adaptor to access objects in Asana",
5
5
  "homepage": "https://docs.openfn.org",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "configuration-schema.json"
24
24
  ],
25
25
  "dependencies": {
26
- "@openfn/language-common": "^1.13.0"
26
+ "@openfn/language-common": "2.0.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@openfn/simple-ast": "0.4.1",
@@ -94,6 +94,7 @@ export function upsertTask(projectGid: string, params: object, callback: Functio
94
94
  /**
95
95
  * Options provided to the createTaskStory request
96
96
  * @typedef {Object} StoryOptions
97
+ * @public
97
98
  * @property {string} text - The plain text of the comment to add. Cannot be used with html_text.
98
99
  * @property {string} html_text - Opt In. HTML formatted text for a comment. This will not include the name of the creator.
99
100
  * @property {boolean} is_pinned - Default to `false`. Whether the story should be pinned on the resource.
@@ -122,21 +123,28 @@ export function createTaskStory(taskGid: string, params: StoryOptions, callback:
122
123
  /**
123
124
  * Options provided to the Asana API request
124
125
  * @typedef {Object} RequestOptions
126
+ * @public
125
127
  * @property {object} body - Body data to append to the request.
126
128
  * @property {object} query - An object of query parameters to be encoded into the URL.
127
129
  * @property {string} method - The HTTP method to use. Defaults to `GET`
128
130
  */
129
131
  /**
130
- * Make a request in Asana API
132
+ * Make a HTTP request against the Asana API.
131
133
  * @public
132
- * @example
133
- * request("/asanaEndpoint", {
134
+ * @example Get a task by id
135
+ * request("/tasks/1234");
136
+ * @example Query for tasks in a given project
137
+ * request("/tasks", {
138
+ * query: { project: "abc" },
139
+ * });
140
+ * @example Create a new task
141
+ * request("/tasks", {
134
142
  * method: "POST",
135
- * query: { foo: "bar", a: 1 },
143
+ * body: { data: { name: "do the thing", completed: false } },
136
144
  * });
137
145
  * @function
138
- * @param {string} path - Path to resource
139
- * @param {RequestOptions} params - Query, body and method parameters
146
+ * @param {string} path - Path to resource (excluding api/version)
147
+ * @param {RequestOptions} params - (Optional) Query, body and method parameters
140
148
  * @param {function} callback - (Optional) Callback function
141
149
  * @returns {Operation}
142
150
  */
@@ -144,47 +152,9 @@ export function request(path: string, params: RequestOptions, callback: Function
144
152
  /**
145
153
  * Options provided to the createTaskStory request
146
154
  */
147
- export type StoryOptions = {
148
- /**
149
- * - The plain text of the comment to add. Cannot be used with html_text.
150
- */
151
- text: string;
152
- /**
153
- * - Opt In. HTML formatted text for a comment. This will not include the name of the creator.
154
- */
155
- html_text: string;
156
- /**
157
- * - Default to `false`. Whether the story should be pinned on the resource.
158
- */
159
- is_pinned: boolean;
160
- /**
161
- * - The name of the sticker in this story. `null` if there is no sticker.
162
- */
163
- sticker_name: string;
164
- /**
165
- * - Opt In. This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include.
166
- */
167
- opt_fields: any[];
168
- /**
169
- * - Defaults to `false`. Provides the response in a “pretty” format. In the case of JSON this means doing proper line breaking and indentation to make it readable. This will take extra time and increase the response size so it is advisable only to use this during debugging.
170
- */
171
- opt_pretty: boolean;
172
- };
155
+ export type StoryOptions = any;
173
156
  /**
174
157
  * Options provided to the Asana API request
175
158
  */
176
- export type RequestOptions = {
177
- /**
178
- * - Body data to append to the request.
179
- */
180
- body: object;
181
- /**
182
- * - An object of query parameters to be encoded into the URL.
183
- */
184
- query: object;
185
- /**
186
- * - The HTTP method to use. Defaults to `GET`
187
- */
188
- method: string;
189
- };
190
- export { alterState, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
159
+ export type RequestOptions = any;
160
+ export { alterState, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";