diff --git a/components/roamresearch/actions/add-content-to-daily-note-page/add-content-to-daily-note-page.mjs b/components/roamresearch/actions/add-content-to-daily-note-page/add-content-to-daily-note-page.mjs new file mode 100644 index 0000000000000..1e896512c4df1 --- /dev/null +++ b/components/roamresearch/actions/add-content-to-daily-note-page/add-content-to-daily-note-page.mjs @@ -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.", + }, + 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, + }, + ], + }, + }); + + $.export("$summary", "Succesfully added content to daily note page."); + return response; + }, +}; diff --git a/components/roamresearch/actions/add-content-to-page/add-content-to-page.mjs b/components/roamresearch/actions/add-content-to-page/add-content-to-page.mjs new file mode 100644 index 0000000000000..bbf4fa000c582 --- /dev/null +++ b/components/roamresearch/actions/add-content-to-page/add-content-to-page.mjs @@ -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; + }, +}; diff --git a/components/roamresearch/actions/add-content-underneath-block/add-content-underneath-block.mjs b/components/roamresearch/actions/add-content-underneath-block/add-content-underneath-block.mjs new file mode 100644 index 0000000000000..afc652916a26d --- /dev/null +++ b/components/roamresearch/actions/add-content-underneath-block/add-content-underneath-block.mjs @@ -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.", + }, + 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, + }, + ], + }, + }); + + $.export("$summary", "Succesfully added content underneath block."); + return response; + }, +}; diff --git a/components/roamresearch/actions/get-page-or-block-data/get-page-or-block-data.mjs b/components/roamresearch/actions/get-page-or-block-data/get-page-or-block-data.mjs new file mode 100644 index 0000000000000..6f2f3362bb46a --- /dev/null +++ b/components/roamresearch/actions/get-page-or-block-data/get-page-or-block-data.mjs @@ -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`.", + }, + }, + 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}"]`, + }, + }); + + if (!response.result) { + $.export("$summary", `Failed to get data for ${resourceType}: \`${pageOrBlock}\`.`); + return response; + } + + $.export("$summary", `Succesfully got data for ${resourceType}: \`${pageOrBlock}\`.`); + return response; + }, +}; diff --git a/components/roamresearch/actions/search-title/search-title.mjs b/components/roamresearch/actions/search-title/search-title.mjs new file mode 100644 index 0000000000000..7d22344be6607 --- /dev/null +++ b/components/roamresearch/actions/search-title/search-title.mjs @@ -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).", + 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}\`.`); + return response; + }, +}; diff --git a/components/roamresearch/common/constants.mjs b/components/roamresearch/common/constants.mjs new file mode 100644 index 0000000000000..e65123a69c092 --- /dev/null +++ b/components/roamresearch/common/constants.mjs @@ -0,0 +1,15 @@ +const SUBDOMAIN_PLACEHOLDER = "{subdomain}"; +const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.roamresearch.com`; +const VERSION_PATH = "/api/graph"; + +const API = { + DEFAULT: "api", + APPEND: "append-api", +}; + +export default { + SUBDOMAIN_PLACEHOLDER, + BASE_URL, + VERSION_PATH, + API, +}; diff --git a/components/roamresearch/package.json b/components/roamresearch/package.json index 2ba776959e91a..76ce74990ec36 100644 --- a/components/roamresearch/package.json +++ b/components/roamresearch/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/roamresearch", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream roamresearch Components", "main": "roamresearch.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "3.0.3" } -} \ No newline at end of file +} diff --git a/components/roamresearch/roamresearch.app.mjs b/components/roamresearch/roamresearch.app.mjs index 5d9f7f5184551..16e77448428c1 100644 --- a/components/roamresearch/roamresearch.app.mjs +++ b/components/roamresearch/roamresearch.app.mjs @@ -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.", + }, + 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), + }); + }, + 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, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4368b2010047d..977238067ae2b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8409,7 +8409,10 @@ importers: specifiers: {} components/roamresearch: - specifiers: {} + specifiers: + '@pipedream/platform': 3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/robocorp: specifiers: {}