Skip to content

Commit e06598a

Browse files
New Components - nuclino (#16887)
* new components * updates * add test-event * updates * Update components/nuclino/sources/new-item-or-collection-created/new-item-or-collection-created.mjs Co-authored-by: Luan Cazarine <luanhc@gmail.com> --------- Co-authored-by: Luan Cazarine <luanhc@gmail.com>
1 parent ce38964 commit e06598a

File tree

11 files changed

+524
-8
lines changed

11 files changed

+524
-8
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import nuclino from "../../nuclino.app.mjs";
2+
3+
export default {
4+
key: "nuclino-create-item-or-collection",
5+
name: "Create Item or Collection",
6+
description: "Create a new item or collection in Nuclino. [See the documentation](https://help.nuclino.com/fa38d15f-items-and-collections)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
nuclino,
11+
workspaceId: {
12+
propDefinition: [
13+
nuclino,
14+
"workspaceId",
15+
],
16+
description: "The ID of the workspace to create the item in",
17+
},
18+
parentId: {
19+
propDefinition: [
20+
nuclino,
21+
"itemId",
22+
(c) => ({
23+
workspaceId: c.workspaceId,
24+
object: "collection",
25+
}),
26+
],
27+
label: "Parent ID",
28+
description: "The ID of the collection to create the item in",
29+
optional: true,
30+
},
31+
object: {
32+
propDefinition: [
33+
nuclino,
34+
"object",
35+
],
36+
optional: true,
37+
},
38+
title: {
39+
propDefinition: [
40+
nuclino,
41+
"title",
42+
],
43+
},
44+
content: {
45+
propDefinition: [
46+
nuclino,
47+
"content",
48+
],
49+
},
50+
index: {
51+
type: "integer",
52+
label: "Index",
53+
description: "The zero-based index at which to insert the item/collection in the parent. Defaults to the end of the parent.",
54+
optional: true,
55+
},
56+
},
57+
async run({ $ }) {
58+
const response = await this.nuclino.createItem({
59+
$,
60+
data: {
61+
workspaceId: this.parentId
62+
? undefined
63+
: this.workspaceId,
64+
parentId: this.parentId,
65+
object: this.object,
66+
title: this.title,
67+
content: this.content,
68+
index: this.index,
69+
},
70+
});
71+
$.export("$summary", `Successfully created ${this.object || "item"} with ID ${response.data.id}`);
72+
return response;
73+
},
74+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import nuclino from "../../nuclino.app.mjs";
2+
3+
export default {
4+
key: "nuclino-search-items-or-collections",
5+
name: "Search Items or Collections",
6+
description: "Search for items or collections in Nuclino. [See the documentation](https://help.nuclino.com/fa38d15f-items-and-collections)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
nuclino,
11+
workspaceId: {
12+
propDefinition: [
13+
nuclino,
14+
"workspaceId",
15+
],
16+
},
17+
query: {
18+
type: "string",
19+
label: "Query",
20+
description: "The search query used to search for items and collections",
21+
},
22+
maxResults: {
23+
type: "integer",
24+
label: "Max Results",
25+
description: "The maximum number of results to return",
26+
default: 100,
27+
optional: true,
28+
},
29+
},
30+
async run({ $ }) {
31+
const results = this.nuclino.paginate({
32+
fn: this.nuclino.listItems,
33+
params: {
34+
workspaceId: this.workspaceId,
35+
search: this.query,
36+
},
37+
max: this.maxResults,
38+
});
39+
40+
const items = [];
41+
for await (const item of results) {
42+
items.push(item);
43+
}
44+
45+
$.export("$summary", `Found ${items.length} item${items.length === 1
46+
? ""
47+
: "s"} matching query`);
48+
return items;
49+
},
50+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import nuclino from "../../nuclino.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "nuclino-update-item-or-collection",
6+
name: "Update Item or Collection",
7+
description: "Update an existing item or collection in Nuclino. [See the documentation](https://help.nuclino.com/fa38d15f-items-and-collections)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
nuclino,
12+
workspaceId: {
13+
propDefinition: [
14+
nuclino,
15+
"workspaceId",
16+
],
17+
description: "The ID of the workspace containing the item to update",
18+
},
19+
object: {
20+
propDefinition: [
21+
nuclino,
22+
"object",
23+
],
24+
},
25+
itemId: {
26+
propDefinition: [
27+
nuclino,
28+
"itemId",
29+
(c) => ({
30+
workspaceId: c.workspaceId,
31+
object: c.object,
32+
}),
33+
],
34+
label: "Object ID",
35+
description: "The ID of the object to update",
36+
},
37+
title: {
38+
propDefinition: [
39+
nuclino,
40+
"title",
41+
],
42+
},
43+
content: {
44+
propDefinition: [
45+
nuclino,
46+
"content",
47+
],
48+
},
49+
},
50+
async run({ $ }) {
51+
if (!this.title && !this.content) {
52+
throw new ConfigurationError("At least one of `title` or `content` must be provided");
53+
}
54+
const response = await this.nuclino.updateItem({
55+
$,
56+
itemId: this.itemId,
57+
data: {
58+
title: this.title,
59+
content: this.content,
60+
},
61+
});
62+
$.export("$summary", `Successfully updated object with ID ${response.data.id}`);
63+
return response;
64+
},
65+
};

components/nuclino/nuclino.app.mjs

Lines changed: 157 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,163 @@
1+
import { axios } from "@pipedream/platform";
2+
const DEFAULT_LIMIT = 100;
3+
14
export default {
25
type: "app",
36
app: "nuclino",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
workspaceId: {
9+
type: "string",
10+
label: "Workspace ID",
11+
description: "The ID of a workspace",
12+
async options({ prevContext }) {
13+
const params = {
14+
limit: DEFAULT_LIMIT,
15+
};
16+
if (prevContext?.after) {
17+
params.after = prevContext.after;
18+
}
19+
const { data: { results } } = await this.listWorkspaces({
20+
params,
21+
});
22+
if (!results?.length) {
23+
return [];
24+
}
25+
return {
26+
options: results.map((workspace) => ({
27+
label: workspace.name,
28+
value: workspace.id,
29+
})),
30+
context: {
31+
after: results[results.length - 1].id,
32+
},
33+
};
34+
},
35+
},
36+
itemId: {
37+
type: "string",
38+
label: "Item ID",
39+
description: "The ID of an item",
40+
async options({
41+
workspaceId, object, prevContext,
42+
}) {
43+
const params = {
44+
workspaceId,
45+
limit: DEFAULT_LIMIT,
46+
};
47+
if (prevContext?.after) {
48+
params.after = prevContext.after;
49+
}
50+
const { data: { results } } = await this.listItems({
51+
params,
52+
});
53+
const items = object
54+
? results?.filter((item) => item.object === object)
55+
: results;
56+
if (!items?.length) {
57+
return [];
58+
}
59+
return {
60+
options: items.map((item) => ({
61+
label: item.title,
62+
value: item.id,
63+
})),
64+
context: {
65+
after: items[items.length - 1].id,
66+
},
67+
};
68+
},
69+
},
70+
object: {
71+
type: "string",
72+
label: "Object",
73+
description: "The object type. Either `item` or `collection`.",
74+
async options() {
75+
return [
76+
"item",
77+
"collection",
78+
];
79+
},
80+
},
81+
title: {
82+
type: "string",
83+
label: "Title",
84+
description: "The title of the item or collection",
85+
optional: true,
86+
},
87+
content: {
88+
type: "string",
89+
label: "Content",
90+
description: "Content formatted as Markdown. See [Item Content Format](https://help.nuclino.com/4adea846-item-content-format)",
91+
optional: true,
92+
},
93+
},
594
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
95+
_baseUrl() {
96+
return "https://api.nuclino.com/v0";
97+
},
98+
_makeRequest({
99+
$ = this, path, ...opts
100+
}) {
101+
return axios($, {
102+
url: `${this._baseUrl()}${path}`,
103+
headers: {
104+
"authorization": `${this.$auth.api_key}`,
105+
},
106+
...opts,
107+
});
108+
},
109+
listWorkspaces(opts = {}) {
110+
return this._makeRequest({
111+
path: "/workspaces",
112+
...opts,
113+
});
114+
},
115+
listItems(opts = {}) {
116+
return this._makeRequest({
117+
path: "/items",
118+
...opts,
119+
});
120+
},
121+
createItem(opts = {}) {
122+
return this._makeRequest({
123+
path: "/items",
124+
method: "POST",
125+
...opts,
126+
});
127+
},
128+
updateItem({
129+
itemId, ...opts
130+
}) {
131+
return this._makeRequest({
132+
path: `/items/${itemId}`,
133+
method: "PUT",
134+
...opts,
135+
});
136+
},
137+
async *paginate({
138+
fn, params, max,
139+
}) {
140+
params = {
141+
...params,
142+
limit: DEFAULT_LIMIT,
143+
};
144+
let total, count = 0;
145+
do {
146+
const { data: { results } } = await fn({
147+
params,
148+
});
149+
for (const result of results) {
150+
yield result;
151+
if (max && ++count >= max) {
152+
return;
153+
}
154+
}
155+
if (!results?.length) {
156+
return;
157+
}
158+
total = results.length;
159+
params.after = results[results.length - 1].id;
160+
} while (total === params.limit);
9161
},
10162
},
11-
};
163+
};

components/nuclino/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/nuclino",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Nuclino Components",
55
"main": "nuclino.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)