Skip to content

Commit 824c7c0

Browse files
committed
[Components] checkvist #13230
Sources - New List - New List Item Actions - Create List Item - Create Multiple List Items - Create New List
1 parent 9ed6cd9 commit 824c7c0

File tree

12 files changed

+369
-179
lines changed

12 files changed

+369
-179
lines changed

components/checkvist/actions/create-list-item/create-list-item.mjs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import checkvist from "../../checkvist.app.mjs";
2+
import { STATUS_OPTIONS } from "../../common/constants.mjs";
3+
import { parseObject } from "../../common/utils.mjs";
24

35
export default {
46
key: "checkvist-create-list-item",
57
name: "Create List Item",
68
description: "Creates a new list item within a specified list. [See the documentation](https://checkvist.com/auth/api)",
7-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
810
type: "action",
911
props: {
1012
checkvist,
@@ -15,16 +17,60 @@ export default {
1517
],
1618
},
1719
content: {
20+
type: "string",
21+
label: "Content",
22+
description: "Block of text containing items to add. Indentations indicate nested list items.",
23+
},
24+
parentId: {
1825
propDefinition: [
1926
checkvist,
20-
"content",
27+
"parentId",
28+
({ listId }) => ({
29+
listId,
30+
}),
2131
],
32+
optional: true,
33+
},
34+
tags: {
35+
type: "string[]",
36+
label: "Tags",
37+
description: "An array of tags.",
38+
optional: true,
39+
},
40+
dueDate: {
41+
type: "string",
42+
label: "Due Date",
43+
description: "Due for the task, in Checkvist's smart syntax format.",
44+
optional: true,
45+
},
46+
position: {
47+
type: "integer",
48+
label: "Position",
49+
description: "1-based position of the task (omit to add to the end of the list).",
50+
optional: true,
51+
},
52+
status: {
53+
type: "string",
54+
label: "Status",
55+
description: "Task status",
56+
options: STATUS_OPTIONS,
57+
optional: true,
2258
},
2359
},
2460
async run({ $ }) {
2561
const response = await this.checkvist.createListItem({
62+
$,
2663
listId: this.listId,
27-
content: this.content,
64+
data: {
65+
task: {
66+
content: this.content,
67+
parent_id: this.parentId || 0,
68+
tags: parseObject(this.tags)?.join(","),
69+
due_date: this.dueDate,
70+
position: this.position,
71+
status: this.status,
72+
},
73+
},
2874
});
2975

3076
$.export("$summary", `Successfully created a new list item in list with ID ${this.listId}`);

components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,74 @@
11
import checkvist from "../../checkvist.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import {
3+
SEPARATE_LINE_OPTIONS, STATUS_OPTIONS,
4+
} from "../../common/constants.mjs";
35

46
export default {
57
key: "checkvist-create-multiple-list-items",
68
name: "Create Multiple List Items",
79
description: "Enables creation of several list items at once from a block of text. Indentations in the text indicate nested list items. [See the documentation](https://checkvist.com/auth/api)",
8-
version: "0.0.{{ts}}",
10+
version: "0.0.1",
911
type: "action",
1012
props: {
1113
checkvist,
12-
content: {
14+
listId: {
1315
propDefinition: [
1416
checkvist,
15-
"content",
17+
"listId",
1618
],
1719
},
18-
listId: {
20+
itemsContent: {
21+
type: "string",
22+
label: "Content Items",
23+
description: "list items in the same format, as supported by [Checkvist's import function](https://checkvist.com/help#import).",
24+
},
25+
parentId: {
1926
propDefinition: [
2027
checkvist,
21-
"listId",
28+
"parentId",
29+
({ listId }) => ({
30+
listId,
31+
}),
2232
],
2333
optional: true,
2434
},
35+
position: {
36+
type: "integer",
37+
label: "Position",
38+
description: "1-based position of the task (omit to add to the end of the list).",
39+
optional: true,
40+
},
41+
parseTasks: {
42+
type: "boolean",
43+
label: "Parse Tasks",
44+
description: "If true, recognize **^due** and **#tags** syntax in imported list items",
45+
},
46+
separateWithEmptyLine: {
47+
type: "string",
48+
label: "Separate With Empty Line",
49+
description: "Select value for List items separator.",
50+
options: SEPARATE_LINE_OPTIONS,
51+
},
52+
status: {
53+
type: "string",
54+
label: "Status",
55+
description: "Task status",
56+
options: STATUS_OPTIONS,
57+
optional: true,
58+
},
2559
},
2660
async run({ $ }) {
2761
const response = await this.checkvist.createMultipleListItems({
28-
content: this.content,
29-
listId: this.listId || "default",
62+
$,
63+
listId: this.listId,
64+
data: {
65+
import_content: this.itemsContent,
66+
parent_id: this.parentId,
67+
position: this.position,
68+
parse_tasks: this.parseTasks,
69+
separate_with_empty_line: this.separateWithEmptyLine,
70+
status: this.status,
71+
},
3072
});
3173

3274
$.export("$summary", "Successfully created multiple list items");

components/checkvist/actions/create-new-list/create-new-list.mjs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import checkvist from "../../checkvist.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "checkvist-create-new-list",
65
name: "Create New List",
76
description: "Creates a new list in Checkvist. [See the documentation](https://checkvist.com/auth/api)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
checkvist,
1211
name: {
13-
propDefinition: [
14-
checkvist,
15-
"name",
16-
],
12+
type: "string",
13+
label: "List Name",
14+
description: "Name of the new list to be created",
15+
},
16+
public: {
17+
type: "boolean",
18+
label: "Public",
19+
description: "true for checklist which can be accessed in read-only mode by anyone. Access to such checklists doesn't require authentication.",
20+
optional: true,
1721
},
1822
},
1923
async run({ $ }) {
2024
const response = await this.checkvist.createList({
21-
name: this.name,
25+
$,
26+
data: {
27+
name: this.name,
28+
public: this.public,
29+
},
2230
});
2331

2432
$.export("$summary", `Successfully created a new list: ${this.name}`);

components/checkvist/checkvist.app.mjs

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,98 +9,93 @@ export default {
99
label: "List ID",
1010
description: "Select a list to monitor for new items",
1111
async options() {
12-
const lists = await this.getLists();
13-
return lists.map((list) => ({
14-
label: list.name,
15-
value: list.id,
12+
const lists = await this.getLists({
13+
params: {
14+
skip_stats: true,
15+
},
16+
});
17+
return lists.map(({
18+
id: value, name: label,
19+
}) => ({
20+
label,
21+
value,
1622
}));
1723
},
1824
},
19-
content: {
20-
type: "string",
21-
label: "Content",
22-
description: "Block of text containing items to add. Indentations indicate nested list items.",
23-
},
24-
name: {
25+
parentId: {
2526
type: "string",
26-
label: "List Name",
27-
description: "Name of the new list to be created",
27+
label: "Parent task ID",
28+
description: "Empty for root-level tasks",
29+
async options({ listId }) {
30+
const items = await this.getListItems({
31+
listId,
32+
});
33+
return items.map(({
34+
id: value, content: label,
35+
}) => ({
36+
label,
37+
value,
38+
}));
39+
},
2840
},
2941
},
3042
methods: {
3143
_baseUrl() {
32-
return "https://api.checkvist.com";
44+
return "https://checkvist.com";
3345
},
34-
async _makeRequest(opts = {}) {
35-
const {
36-
$ = this, method = "GET", path = "/", headers, ...otherOpts
37-
} = opts;
46+
_auth() {
47+
return {
48+
username: `${this.$auth.username}`,
49+
password: `${this.$auth.api_key}`,
50+
};
51+
},
52+
_makeRequest({
53+
$ = this, path, ...opts
54+
}) {
3855
return axios($, {
39-
...otherOpts,
40-
method,
4156
url: this._baseUrl() + path,
42-
headers: {
43-
...headers,
44-
Authorization: `Bearer ${this.$auth.api_key}`,
45-
},
57+
auth: this._auth(),
58+
...opts,
4659
});
4760
},
48-
async getLists(opts = {}) {
61+
getLists(opts = {}) {
4962
return this._makeRequest({
5063
path: "/checklists.json",
5164
...opts,
5265
});
5366
},
54-
async createList({
55-
name, ...opts
67+
getListItems({
68+
listId, ...opts
5669
}) {
70+
return this._makeRequest({
71+
path: `/checklists/${listId}/tasks.json`,
72+
...opts,
73+
});
74+
},
75+
createList(opts = {}) {
5776
return this._makeRequest({
5877
method: "POST",
5978
path: "/checklists.json",
60-
data: {
61-
checklist: {
62-
name,
63-
},
64-
},
6579
...opts,
6680
});
6781
},
68-
async createListItem({
69-
listId, content, ...opts
82+
createListItem({
83+
listId, ...opts
7084
}) {
7185
return this._makeRequest({
7286
method: "POST",
7387
path: `/checklists/${listId}/tasks.json`,
74-
data: {
75-
task: {
76-
content,
77-
},
78-
},
7988
...opts,
8089
});
8190
},
82-
async createMultipleListItems({
83-
content, listId = "default", ...opts
91+
createMultipleListItems({
92+
listId, ...opts
8493
}) {
8594
return this._makeRequest({
8695
method: "POST",
8796
path: `/checklists/${listId}/import.json`,
88-
data: {
89-
import_content: content,
90-
separate_with_empty_line: false,
91-
},
9297
...opts,
9398
});
9499
},
95-
async watchNewLists() {
96-
const lists = await this.getLists();
97-
return lists; // Emit new event when lists change
98-
},
99-
async watchNewListItems({ listId }) {
100-
const items = await this._makeRequest({
101-
path: `/checklists/${listId}/tasks.json`,
102-
});
103-
return items; // Emit new event when list items change
104-
},
105100
},
106101
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const STATUS_OPTIONS = [
2+
{
3+
label: "Open",
4+
value: "0",
5+
},
6+
{
7+
label: "Closed",
8+
value: "1",
9+
},
10+
{
11+
label: "Invalidated",
12+
value: "2",
13+
},
14+
];
15+
16+
export const SEPARATE_LINE_OPTIONS = [
17+
{
18+
label: "Separate with empty line",
19+
value: "singleItem",
20+
},
21+
{
22+
label: "One item per line",
23+
value: "multipleItems",
24+
},
25+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)