Skip to content

Commit 6ba807f

Browse files
committed
roamresearch: new action components
1 parent 7fb6211 commit 6ba807f

File tree

9 files changed

+363
-8
lines changed

9 files changed

+363
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../roamresearch.app.mjs";
2+
3+
export default {
4+
key: "roamresearch-add-content-to-daily-note-page",
5+
name: "Add Content To Daily Note Page",
6+
description: "Adds content as a child block to a daily note page in Roam Research (access to encrypted and non encrypted graphs). [See the documentation](https://roamresearch.com/#/app/developer-documentation/page/eb8OVhaFC).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
dailyNoteTitle: {
12+
type: "string",
13+
label: "Date For Daily Note",
14+
description: "The date for the daily note page title, formatted as `MM-DD-YYYY`. Keep in mind the Daily Note page should exist.",
15+
},
16+
content: {
17+
propDefinition: [
18+
app,
19+
"content",
20+
],
21+
},
22+
nestUnder: {
23+
propDefinition: [
24+
app,
25+
"nestUnder",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const {
31+
app,
32+
dailyNoteTitle,
33+
content,
34+
nestUnder,
35+
} = this;
36+
37+
const response = app.appendBlocks({
38+
$,
39+
data: {
40+
"location": {
41+
page: {
42+
title: {
43+
"daily-note-page": dailyNoteTitle,
44+
},
45+
},
46+
...(nestUnder && {
47+
"nest-under": {
48+
string: nestUnder,
49+
},
50+
}),
51+
},
52+
"append-data": [
53+
{
54+
string: content,
55+
},
56+
],
57+
},
58+
});
59+
60+
$.export("$summary", "Succesfully added content to daily note page.");
61+
return response;
62+
},
63+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import app from "../../roamresearch.app.mjs";
2+
3+
export default {
4+
key: "roamresearch-add-content-to-page",
5+
name: "Add Content To Page",
6+
description: "Add content as a child block to an existing or new page in Roam Research (access to encrypted and non encrypted graphs). [See the documentation](https://roamresearch.com/#/app/developer-documentation/page/eb8OVhaFC).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
title: {
12+
type: "string",
13+
label: "Page Title",
14+
description: "Title of the page to add content to.",
15+
},
16+
content: {
17+
propDefinition: [
18+
app,
19+
"content",
20+
],
21+
},
22+
nestUnder: {
23+
propDefinition: [
24+
app,
25+
"nestUnder",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const {
31+
app,
32+
title,
33+
content,
34+
nestUnder,
35+
} = this;
36+
37+
const response = app.appendBlocks({
38+
$,
39+
data: {
40+
"location": {
41+
page: {
42+
title,
43+
},
44+
...(nestUnder && {
45+
"nest-under": {
46+
string: nestUnder,
47+
},
48+
}),
49+
},
50+
"append-data": [
51+
{
52+
string: content,
53+
},
54+
],
55+
},
56+
});
57+
58+
$.export("$summary", "Succesfully added content to page.");
59+
return response;
60+
},
61+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import app from "../../roamresearch.app.mjs";
2+
3+
export default {
4+
key: "roamresearch-add-content-underneath-block",
5+
name: "Add Content Underneath Block",
6+
description: "Add content underneath an existing block in your Roam Research graph (access to encrypted and non encrypted graphs). [See the documentation](https://roamresearch.com/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
blockUid: {
12+
type: "string",
13+
label: "Block UID",
14+
description: "The block UID in the Roam graph you want to append content to.",
15+
},
16+
content: {
17+
type: "string",
18+
label: "Content",
19+
description: "The content of the block to be added.",
20+
},
21+
nestUnder: {
22+
type: "string",
23+
label: "Nest Under",
24+
description: "Title of the block to nest the new block under.",
25+
optional: true,
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
app,
31+
blockUid,
32+
content,
33+
nestUnder,
34+
} = this;
35+
36+
const response = app.appendBlocks({
37+
$,
38+
data: {
39+
"location": {
40+
block: {
41+
uid: blockUid,
42+
},
43+
...(nestUnder && {
44+
"nest-under": {
45+
string: nestUnder,
46+
},
47+
}),
48+
},
49+
"append-data": [
50+
{
51+
string: content,
52+
},
53+
],
54+
},
55+
});
56+
57+
$.export("$summary", "Succesfully added content underneath block.");
58+
return response;
59+
},
60+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import app from "../../roamresearch.app.mjs";
2+
3+
export default {
4+
key: "roamresearch-get-page-or-block-data",
5+
name: "Get Page Or Block Data",
6+
description: "Get the data for a page or block in Roam Research (access only to non ecrypted graphs). [See the documentation](https://roamresearch.com/#/app/developer-documentation/page/eb8OVhaFC).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
resourceType: {
12+
type: "string",
13+
label: "Resource Type",
14+
description: "The type of resource to get data for.",
15+
options: [
16+
"page",
17+
"block",
18+
],
19+
},
20+
pageOrBlock: {
21+
type: "string",
22+
label: "Page Title Or Block UID",
23+
description: "The page title of the block uid to get data for. Page title example: `My Page` and Block UID example: `ideWWvTgI`.",
24+
},
25+
},
26+
async run({ $ }) {
27+
const {
28+
app,
29+
resourceType,
30+
pageOrBlock,
31+
} = this;
32+
33+
const attribute = resourceType === "page"
34+
? ":node/title"
35+
: ":block/uid";
36+
37+
const response = await app.pull({
38+
$,
39+
data: {
40+
selector: `[${attribute} :block/string :block/order {:block/children ...}]`,
41+
eid: `[${attribute} "${pageOrBlock}"]`,
42+
},
43+
});
44+
45+
if (!response.result) {
46+
$.export("$summary", `Failed to get data for ${resourceType}: \`${pageOrBlock}\`.`);
47+
return response;
48+
}
49+
50+
$.export("$summary", `Succesfully got data for ${resourceType}: \`${pageOrBlock}\`.`);
51+
return response;
52+
},
53+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import app from "../../roamresearch.app.mjs";
2+
3+
export default {
4+
key: "roamresearch-search-title",
5+
name: "Search Title",
6+
description: "Search for a title in Roam Research pages (access only to non ecrypted graphs). [See the documentation](https://roamresearch.com/#/app/developer-documentation/page/eb8OVhaFC).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
title: {
12+
type: "string",
13+
label: "Search Title",
14+
description: "The title to search for.",
15+
},
16+
},
17+
async run({ $ }) {
18+
const {
19+
app,
20+
title,
21+
} = this;
22+
const response = await app.query({
23+
$,
24+
data: {
25+
query: `[
26+
:find (pull ?b [:block/uid :node/title])
27+
:in $ ?search-string
28+
:where [?b :node/title ?page-title] [
29+
(clojure.string/includes? ?page-title ?search-string)
30+
]
31+
]`,
32+
args: [
33+
title,
34+
],
35+
},
36+
});
37+
38+
$.export("$summary", `Succesfully searched for title: \`${title}\`.`);
39+
return response;
40+
},
41+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const SUBDOMAIN_PLACEHOLDER = "{subdomain}";
2+
const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.roamresearch.com`;
3+
const VERSION_PATH = "/api/graph";
4+
5+
const API = {
6+
DEFAULT: "api",
7+
APPEND: "append-api",
8+
};
9+
10+
export default {
11+
SUBDOMAIN_PLACEHOLDER,
12+
BASE_URL,
13+
VERSION_PATH,
14+
API,
15+
};

components/roamresearch/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/roamresearch",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream roamresearch Components",
55
"main": "roamresearch.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+
}
+61-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "roamresearch",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
content: {
9+
type: "string",
10+
label: "Content",
11+
description: "The content of the block to be added.",
12+
},
13+
nestUnder: {
14+
type: "string",
15+
label: "Nest Under",
16+
description: "Title of the block to nest the new block under.",
17+
optional: true,
18+
},
19+
},
520
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
21+
getUrl(path, api = constants.API.DEFAULT) {
22+
const { graph_name: graphName } = this.$auth;
23+
const baseUrl = constants.BASE_URL.replace(constants.SUBDOMAIN_PLACEHOLDER, api);
24+
return `${baseUrl}${constants.VERSION_PATH}/${graphName}${path}`;
25+
},
26+
getHeaders(headers) {
27+
return {
28+
...headers,
29+
"X-Authorization": `Bearer ${this.$auth.api_token}`,
30+
};
31+
},
32+
_makeRequest({
33+
$ = this, path, headers, api, ...args
34+
} = {}) {
35+
return axios($, {
36+
...args,
37+
url: this.getUrl(path, api),
38+
headers: this.getHeaders(headers),
39+
});
40+
},
41+
post(args = {}) {
42+
return this._makeRequest({
43+
method: "POST",
44+
...args,
45+
});
46+
},
47+
appendBlocks(args = {}) {
48+
return this.post({
49+
api: constants.API.APPEND,
50+
path: "/append-blocks",
51+
...args,
52+
});
53+
},
54+
query(args = {}) {
55+
return this.post({
56+
path: "/q",
57+
...args,
58+
});
59+
},
60+
pull(args = {}) {
61+
return this.post({
62+
path: "/pull",
63+
...args,
64+
});
965
},
1066
},
11-
};
67+
};

0 commit comments

Comments
 (0)