Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Components] roamresearch #14385

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import app from "../../roamresearch.app.mjs";

export default {
key: "roamresearch-add-content-to-daily-note-page",
name: "Add Content To Daily Note Page",
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).",
version: "0.0.1",
type: "action",
props: {
app,
dailyNoteTitle: {
type: "string",
label: "Date For Daily Note",
description: "The date for the daily note page title, formatted as `MM-DD-YYYY`. Keep in mind the Daily Note page should exist.",
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
content: {
propDefinition: [
app,
"content",
],
},
nestUnder: {
propDefinition: [
app,
"nestUnder",
],
},
},
async run({ $ }) {
const {
app,
dailyNoteTitle,
content,
nestUnder,
} = this;

const response = app.appendBlocks({
$,
data: {
"location": {
page: {
title: {
"daily-note-page": dailyNoteTitle,
},
},
...(nestUnder && {
"nest-under": {
string: nestUnder,
},
}),
},
"append-data": [
{
string: content,
},
],
},
});
jcortes marked this conversation as resolved.
Show resolved Hide resolved

$.export("$summary", "Succesfully added content to daily note page.");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import app from "../../roamresearch.app.mjs";

export default {
key: "roamresearch-add-content-to-page",
name: "Add Content To Page",
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).",
version: "0.0.1",
type: "action",
props: {
app,
title: {
type: "string",
label: "Page Title",
description: "Title of the page to add content to.",
},
content: {
propDefinition: [
app,
"content",
],
},
nestUnder: {
propDefinition: [
app,
"nestUnder",
],
},
},
async run({ $ }) {
const {
app,
title,
content,
nestUnder,
} = this;

const response = app.appendBlocks({
$,
data: {
"location": {
page: {
title,
},
...(nestUnder && {
"nest-under": {
string: nestUnder,
},
}),
},
"append-data": [
{
string: content,
},
],
},
});

$.export("$summary", "Succesfully added content to page.");
return response;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import app from "../../roamresearch.app.mjs";

export default {
key: "roamresearch-add-content-underneath-block",
name: "Add Content Underneath Block",
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/)",
version: "0.0.1",
type: "action",
props: {
app,
blockUid: {
type: "string",
label: "Block UID",
description: "The block UID in the Roam graph you want to append content to.",
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
content: {
type: "string",
label: "Content",
description: "The content of the block to be added.",
},
nestUnder: {
type: "string",
label: "Nest Under",
description: "Title of the block to nest the new block under.",
optional: true,
},
},
async run({ $ }) {
const {
app,
blockUid,
content,
nestUnder,
} = this;

const response = app.appendBlocks({
$,
data: {
"location": {
block: {
uid: blockUid,
},
...(nestUnder && {
"nest-under": {
string: nestUnder,
},
}),
},
"append-data": [
{
string: content,
},
],
},
});
jcortes marked this conversation as resolved.
Show resolved Hide resolved

$.export("$summary", "Succesfully added content underneath block.");
jcortes marked this conversation as resolved.
Show resolved Hide resolved
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import app from "../../roamresearch.app.mjs";

export default {
key: "roamresearch-get-page-or-block-data",
name: "Get Page Or Block Data",
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).",
version: "0.0.1",
type: "action",
props: {
app,
resourceType: {
type: "string",
label: "Resource Type",
description: "The type of resource to get data for.",
options: [
"page",
"block",
],
},
pageOrBlock: {
type: "string",
label: "Page Title Or Block UID",
description: "The page title of the block uid to get data for. Page title example: `My Page` and Block UID example: `ideWWvTgI`.",
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
},
async run({ $ }) {
const {
app,
resourceType,
pageOrBlock,
} = this;

const attribute = resourceType === "page"
? ":node/title"
: ":block/uid";

const response = await app.pull({
$,
data: {
selector: `[${attribute} :block/string :block/order {:block/children ...}]`,
eid: `[${attribute} "${pageOrBlock}"]`,
},
});
jcortes marked this conversation as resolved.
Show resolved Hide resolved

if (!response.result) {
$.export("$summary", `Failed to get data for ${resourceType}: \`${pageOrBlock}\`.`);
return response;
}
jcortes marked this conversation as resolved.
Show resolved Hide resolved

$.export("$summary", `Succesfully got data for ${resourceType}: \`${pageOrBlock}\`.`);
jcortes marked this conversation as resolved.
Show resolved Hide resolved
return response;
},
};
41 changes: 41 additions & 0 deletions components/roamresearch/actions/search-title/search-title.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import app from "../../roamresearch.app.mjs";

export default {
key: "roamresearch-search-title",
name: "Search Title",
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).",
jcortes marked this conversation as resolved.
Show resolved Hide resolved
version: "0.0.1",
type: "action",
props: {
app,
title: {
type: "string",
label: "Search Title",
description: "The title to search for.",
},
},
async run({ $ }) {
const {
app,
title,
} = this;
const response = await app.query({
$,
data: {
query: `[
:find (pull ?b [:block/uid :node/title])
:in $ ?search-string
:where [?b :node/title ?page-title] [
(clojure.string/includes? ?page-title ?search-string)
]
]`,
args: [
title,
],
},
});

$.export("$summary", `Succesfully searched for title: \`${title}\`.`);
jcortes marked this conversation as resolved.
Show resolved Hide resolved
return response;
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
};
15 changes: 15 additions & 0 deletions components/roamresearch/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const SUBDOMAIN_PLACEHOLDER = "{subdomain}";
const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.roamresearch.com`;
const VERSION_PATH = "/api/graph";
jcortes marked this conversation as resolved.
Show resolved Hide resolved

const API = {
DEFAULT: "api",
APPEND: "append-api",
};

export default {
SUBDOMAIN_PLACEHOLDER,
BASE_URL,
VERSION_PATH,
API,
};
jcortes marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions components/roamresearch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/roamresearch",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream roamresearch Components",
"main": "roamresearch.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "3.0.3"
}
}
}
66 changes: 61 additions & 5 deletions components/roamresearch/roamresearch.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,67 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "roamresearch",
propDefinitions: {},
propDefinitions: {
content: {
type: "string",
label: "Content",
description: "The content of the block to be added.",
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
nestUnder: {
type: "string",
label: "Nest Under",
description: "Title of the block to nest the new block under.",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getUrl(path, api = constants.API.DEFAULT) {
const { graph_name: graphName } = this.$auth;
const baseUrl = constants.BASE_URL.replace(constants.SUBDOMAIN_PLACEHOLDER, api);
return `${baseUrl}${constants.VERSION_PATH}/${graphName}${path}`;
},
getHeaders(headers) {
return {
...headers,
"X-Authorization": `Bearer ${this.$auth.api_token}`,
};
},
_makeRequest({
$ = this, path, headers, api, ...args
} = {}) {
return axios($, {
...args,
url: this.getUrl(path, api),
headers: this.getHeaders(headers),
});
},
jcortes marked this conversation as resolved.
Show resolved Hide resolved
post(args = {}) {
return this._makeRequest({
method: "POST",
...args,
});
},
appendBlocks(args = {}) {
return this.post({
api: constants.API.APPEND,
path: "/append-blocks",
...args,
});
},
query(args = {}) {
return this.post({
path: "/q",
...args,
});
},
pull(args = {}) {
return this.post({
path: "/pull",
...args,
});
},
},
};
};
Loading
Loading