From 9ed6cd9c8bb50c3e5118498328fd5f78bfbda64a Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 31 Oct 2024 16:22:24 -0300 Subject: [PATCH 1/3] checkvist init --- .../create-list-item/create-list-item.mjs | 33 ++++++ .../create-multiple-list-items.mjs | 35 ++++++ .../create-new-list/create-new-list.mjs | 27 +++++ components/checkvist/checkvist.app.mjs | 103 +++++++++++++++++- .../sources/new-list-item/new-list-item.mjs | 76 +++++++++++++ .../checkvist/sources/new-list/new-list.mjs | 61 +++++++++++ 6 files changed, 331 insertions(+), 4 deletions(-) create mode 100644 components/checkvist/actions/create-list-item/create-list-item.mjs create mode 100644 components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs create mode 100644 components/checkvist/actions/create-new-list/create-new-list.mjs create mode 100644 components/checkvist/sources/new-list-item/new-list-item.mjs create mode 100644 components/checkvist/sources/new-list/new-list.mjs diff --git a/components/checkvist/actions/create-list-item/create-list-item.mjs b/components/checkvist/actions/create-list-item/create-list-item.mjs new file mode 100644 index 0000000000000..230ea77a6cf6a --- /dev/null +++ b/components/checkvist/actions/create-list-item/create-list-item.mjs @@ -0,0 +1,33 @@ +import checkvist from "../../checkvist.app.mjs"; + +export default { + key: "checkvist-create-list-item", + name: "Create List Item", + description: "Creates a new list item within a specified list. [See the documentation](https://checkvist.com/auth/api)", + version: "0.0.{{ts}}", + type: "action", + props: { + checkvist, + listId: { + propDefinition: [ + checkvist, + "listId", + ], + }, + content: { + propDefinition: [ + checkvist, + "content", + ], + }, + }, + async run({ $ }) { + const response = await this.checkvist.createListItem({ + listId: this.listId, + content: this.content, + }); + + $.export("$summary", `Successfully created a new list item in list with ID ${this.listId}`); + return response; + }, +}; diff --git a/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs b/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs new file mode 100644 index 0000000000000..7b300da8be6c4 --- /dev/null +++ b/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs @@ -0,0 +1,35 @@ +import checkvist from "../../checkvist.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "checkvist-create-multiple-list-items", + name: "Create Multiple List Items", + 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)", + version: "0.0.{{ts}}", + type: "action", + props: { + checkvist, + content: { + propDefinition: [ + checkvist, + "content", + ], + }, + listId: { + propDefinition: [ + checkvist, + "listId", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.checkvist.createMultipleListItems({ + content: this.content, + listId: this.listId || "default", + }); + + $.export("$summary", "Successfully created multiple list items"); + return response; + }, +}; diff --git a/components/checkvist/actions/create-new-list/create-new-list.mjs b/components/checkvist/actions/create-new-list/create-new-list.mjs new file mode 100644 index 0000000000000..98ee01304dc07 --- /dev/null +++ b/components/checkvist/actions/create-new-list/create-new-list.mjs @@ -0,0 +1,27 @@ +import checkvist from "../../checkvist.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "checkvist-create-new-list", + name: "Create New List", + description: "Creates a new list in Checkvist. [See the documentation](https://checkvist.com/auth/api)", + version: "0.0.{{ts}}", + type: "action", + props: { + checkvist, + name: { + propDefinition: [ + checkvist, + "name", + ], + }, + }, + async run({ $ }) { + const response = await this.checkvist.createList({ + name: this.name, + }); + + $.export("$summary", `Successfully created a new list: ${this.name}`); + return response; + }, +}; diff --git a/components/checkvist/checkvist.app.mjs b/components/checkvist/checkvist.app.mjs index 58dca2a8a09c7..4155ac2f95f2b 100644 --- a/components/checkvist/checkvist.app.mjs +++ b/components/checkvist/checkvist.app.mjs @@ -1,11 +1,106 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "checkvist", - propDefinitions: {}, + propDefinitions: { + listId: { + type: "string", + label: "List ID", + description: "Select a list to monitor for new items", + async options() { + const lists = await this.getLists(); + return lists.map((list) => ({ + label: list.name, + value: list.id, + })); + }, + }, + content: { + type: "string", + label: "Content", + description: "Block of text containing items to add. Indentations indicate nested list items.", + }, + name: { + type: "string", + label: "List Name", + description: "Name of the new list to be created", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.checkvist.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "GET", path = "/", headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + async getLists(opts = {}) { + return this._makeRequest({ + path: "/checklists.json", + ...opts, + }); + }, + async createList({ + name, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: "/checklists.json", + data: { + checklist: { + name, + }, + }, + ...opts, + }); + }, + async createListItem({ + listId, content, ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/checklists/${listId}/tasks.json`, + data: { + task: { + content, + }, + }, + ...opts, + }); + }, + async createMultipleListItems({ + content, listId = "default", ...opts + }) { + return this._makeRequest({ + method: "POST", + path: `/checklists/${listId}/import.json`, + data: { + import_content: content, + separate_with_empty_line: false, + }, + ...opts, + }); + }, + async watchNewLists() { + const lists = await this.getLists(); + return lists; // Emit new event when lists change + }, + async watchNewListItems({ listId }) { + const items = await this._makeRequest({ + path: `/checklists/${listId}/tasks.json`, + }); + return items; // Emit new event when list items change }, }, }; diff --git a/components/checkvist/sources/new-list-item/new-list-item.mjs b/components/checkvist/sources/new-list-item/new-list-item.mjs new file mode 100644 index 0000000000000..5907b73122052 --- /dev/null +++ b/components/checkvist/sources/new-list-item/new-list-item.mjs @@ -0,0 +1,76 @@ +import { + axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, +} from "@pipedream/platform"; +import checkvist from "../../checkvist.app.mjs"; + +export default { + key: "checkvist-new-list-item", + name: "New List Item Added", + description: "Emit new event when a new list item is added in a selected list. [See the documentation](https://checkvist.com/auth/api)", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + checkvist, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + listId: { + propDefinition: [ + checkvist, + "listId", + ], + }, + }, + hooks: { + async deploy() { + await this.emitRecentItems(); + }, + }, + methods: { + async emitRecentItems() { + const items = await this.checkvist.watchNewListItems({ + listId: this.listId, + }); + items.slice(0, 50).forEach((item) => { + this.$emit(item, { + id: `${item.id}`, + summary: `New Item: ${item.content}`, + ts: Date.parse(item.created_at), + }); + }); + this._setLastItemId(items[0]?.id); + }, + _getLastItemId() { + return this.db.get("lastItemId"); + }, + _setLastItemId(id) { + this.db.set("lastItemId", id); + }, + }, + async run() { + const lastItemId = this._getLastItemId(); + + const items = await this.checkvist.watchNewListItems({ + listId: this.listId, + }); + + for (const item of items) { + if (!lastItemId || item.id > lastItemId) { + this.$emit(item, { + id: `${item.id}`, + summary: `New Item: ${item.content}`, + ts: Date.parse(item.created_at), + }); + } + } + + if (items.length > 0) { + this._setLastItemId(items[0].id); + } + }, +}; diff --git a/components/checkvist/sources/new-list/new-list.mjs b/components/checkvist/sources/new-list/new-list.mjs new file mode 100644 index 0000000000000..0f98b227d9297 --- /dev/null +++ b/components/checkvist/sources/new-list/new-list.mjs @@ -0,0 +1,61 @@ +import checkvist from "../../checkvist.app.mjs"; +import { + axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, +} from "@pipedream/platform"; + +export default { + key: "checkvist-new-list", + name: "New List Created", + description: "Emit new event when a new list is created in your Checkvist account. [See the documentation](https://checkvist.com/auth/api)", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + checkvist, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + hooks: { + async deploy() { + const lists = await this.checkvist.getLists(); + lists.slice(0, 50).forEach((list) => this.emitList(list)); + if (lists.length) this._setLastListId(lists[0].id); + }, + }, + methods: { + emitList(list) { + const ts = Date.parse(list.created_at) || Date.now(); + this.$emit(list, { + id: list.id, + summary: `New list: ${list.name}`, + ts, + }); + }, + _getLastListId() { + return this.db.get("lastListId"); + }, + _setLastListId(lastListId) { + this.db.set("lastListId", lastListId); + }, + }, + async run() { + const lastListId = this._getLastListId(); + const lists = await this.checkvist.getLists(); + const newLists = lastListId + ? lists.filter((list) => list.id > lastListId) + : lists; + + for (const list of newLists) { + this.emitList(list); + } + + if (newLists.length) { + this._setLastListId(newLists[0].id); + } + }, +}; From 824c7c089322cd9f8c22db9a8c1bf1429aa5d9c8 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 1 Nov 2024 12:43:02 -0300 Subject: [PATCH 2/3] [Components] checkvist #13230 Sources - New List - New List Item Actions - Create List Item - Create Multiple List Items - Create New List --- .../create-list-item/create-list-item.mjs | 52 ++++++++- .../create-multiple-list-items.mjs | 58 ++++++++-- .../create-new-list/create-new-list.mjs | 22 ++-- components/checkvist/checkvist.app.mjs | 103 +++++++++--------- components/checkvist/common/constants.mjs | 25 +++++ components/checkvist/common/utils.mjs | 24 ++++ components/checkvist/package.json | 19 ++++ components/checkvist/sources/common/base.mjs | 69 ++++++++++++ .../sources/new-list-item/new-list-item.mjs | 74 +++---------- .../sources/new-list-item/test-event.mjs | 21 ++++ .../checkvist/sources/new-list/new-list.mjs | 61 ++--------- .../checkvist/sources/new-list/test-event.mjs | 20 ++++ 12 files changed, 369 insertions(+), 179 deletions(-) create mode 100644 components/checkvist/common/constants.mjs create mode 100644 components/checkvist/common/utils.mjs create mode 100644 components/checkvist/package.json create mode 100644 components/checkvist/sources/common/base.mjs create mode 100644 components/checkvist/sources/new-list-item/test-event.mjs create mode 100644 components/checkvist/sources/new-list/test-event.mjs diff --git a/components/checkvist/actions/create-list-item/create-list-item.mjs b/components/checkvist/actions/create-list-item/create-list-item.mjs index 230ea77a6cf6a..766898d83d170 100644 --- a/components/checkvist/actions/create-list-item/create-list-item.mjs +++ b/components/checkvist/actions/create-list-item/create-list-item.mjs @@ -1,10 +1,12 @@ import checkvist from "../../checkvist.app.mjs"; +import { STATUS_OPTIONS } from "../../common/constants.mjs"; +import { parseObject } from "../../common/utils.mjs"; export default { key: "checkvist-create-list-item", name: "Create List Item", description: "Creates a new list item within a specified list. [See the documentation](https://checkvist.com/auth/api)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { checkvist, @@ -15,16 +17,60 @@ export default { ], }, content: { + type: "string", + label: "Content", + description: "Block of text containing items to add. Indentations indicate nested list items.", + }, + parentId: { propDefinition: [ checkvist, - "content", + "parentId", + ({ listId }) => ({ + listId, + }), ], + optional: true, + }, + tags: { + type: "string[]", + label: "Tags", + description: "An array of tags.", + optional: true, + }, + dueDate: { + type: "string", + label: "Due Date", + description: "Due for the task, in Checkvist's smart syntax format.", + optional: true, + }, + position: { + type: "integer", + label: "Position", + description: "1-based position of the task (omit to add to the end of the list).", + optional: true, + }, + status: { + type: "string", + label: "Status", + description: "Task status", + options: STATUS_OPTIONS, + optional: true, }, }, async run({ $ }) { const response = await this.checkvist.createListItem({ + $, listId: this.listId, - content: this.content, + data: { + task: { + content: this.content, + parent_id: this.parentId || 0, + tags: parseObject(this.tags)?.join(","), + due_date: this.dueDate, + position: this.position, + status: this.status, + }, + }, }); $.export("$summary", `Successfully created a new list item in list with ID ${this.listId}`); diff --git a/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs b/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs index 7b300da8be6c4..68d94932e3a69 100644 --- a/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs +++ b/components/checkvist/actions/create-multiple-list-items/create-multiple-list-items.mjs @@ -1,32 +1,74 @@ import checkvist from "../../checkvist.app.mjs"; -import { axios } from "@pipedream/platform"; +import { + SEPARATE_LINE_OPTIONS, STATUS_OPTIONS, +} from "../../common/constants.mjs"; export default { key: "checkvist-create-multiple-list-items", name: "Create Multiple List Items", 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)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { checkvist, - content: { + listId: { propDefinition: [ checkvist, - "content", + "listId", ], }, - listId: { + itemsContent: { + type: "string", + label: "Content Items", + description: "list items in the same format, as supported by [Checkvist's import function](https://checkvist.com/help#import).", + }, + parentId: { propDefinition: [ checkvist, - "listId", + "parentId", + ({ listId }) => ({ + listId, + }), ], optional: true, }, + position: { + type: "integer", + label: "Position", + description: "1-based position of the task (omit to add to the end of the list).", + optional: true, + }, + parseTasks: { + type: "boolean", + label: "Parse Tasks", + description: "If true, recognize **^due** and **#tags** syntax in imported list items", + }, + separateWithEmptyLine: { + type: "string", + label: "Separate With Empty Line", + description: "Select value for List items separator.", + options: SEPARATE_LINE_OPTIONS, + }, + status: { + type: "string", + label: "Status", + description: "Task status", + options: STATUS_OPTIONS, + optional: true, + }, }, async run({ $ }) { const response = await this.checkvist.createMultipleListItems({ - content: this.content, - listId: this.listId || "default", + $, + listId: this.listId, + data: { + import_content: this.itemsContent, + parent_id: this.parentId, + position: this.position, + parse_tasks: this.parseTasks, + separate_with_empty_line: this.separateWithEmptyLine, + status: this.status, + }, }); $.export("$summary", "Successfully created multiple list items"); diff --git a/components/checkvist/actions/create-new-list/create-new-list.mjs b/components/checkvist/actions/create-new-list/create-new-list.mjs index 98ee01304dc07..bf2cb176a63d1 100644 --- a/components/checkvist/actions/create-new-list/create-new-list.mjs +++ b/components/checkvist/actions/create-new-list/create-new-list.mjs @@ -1,24 +1,32 @@ import checkvist from "../../checkvist.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "checkvist-create-new-list", name: "Create New List", description: "Creates a new list in Checkvist. [See the documentation](https://checkvist.com/auth/api)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { checkvist, name: { - propDefinition: [ - checkvist, - "name", - ], + type: "string", + label: "List Name", + description: "Name of the new list to be created", + }, + public: { + type: "boolean", + label: "Public", + description: "true for checklist which can be accessed in read-only mode by anyone. Access to such checklists doesn't require authentication.", + optional: true, }, }, async run({ $ }) { const response = await this.checkvist.createList({ - name: this.name, + $, + data: { + name: this.name, + public: this.public, + }, }); $.export("$summary", `Successfully created a new list: ${this.name}`); diff --git a/components/checkvist/checkvist.app.mjs b/components/checkvist/checkvist.app.mjs index 4155ac2f95f2b..ec6fd50f67e55 100644 --- a/components/checkvist/checkvist.app.mjs +++ b/components/checkvist/checkvist.app.mjs @@ -9,98 +9,93 @@ export default { label: "List ID", description: "Select a list to monitor for new items", async options() { - const lists = await this.getLists(); - return lists.map((list) => ({ - label: list.name, - value: list.id, + const lists = await this.getLists({ + params: { + skip_stats: true, + }, + }); + return lists.map(({ + id: value, name: label, + }) => ({ + label, + value, })); }, }, - content: { - type: "string", - label: "Content", - description: "Block of text containing items to add. Indentations indicate nested list items.", - }, - name: { + parentId: { type: "string", - label: "List Name", - description: "Name of the new list to be created", + label: "Parent task ID", + description: "Empty for root-level tasks", + async options({ listId }) { + const items = await this.getListItems({ + listId, + }); + return items.map(({ + id: value, content: label, + }) => ({ + label, + value, + })); + }, }, }, methods: { _baseUrl() { - return "https://api.checkvist.com"; + return "https://checkvist.com"; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "GET", path = "/", headers, ...otherOpts - } = opts; + _auth() { + return { + username: `${this.$auth.username}`, + password: `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_key}`, - }, + auth: this._auth(), + ...opts, }); }, - async getLists(opts = {}) { + getLists(opts = {}) { return this._makeRequest({ path: "/checklists.json", ...opts, }); }, - async createList({ - name, ...opts + getListItems({ + listId, ...opts }) { + return this._makeRequest({ + path: `/checklists/${listId}/tasks.json`, + ...opts, + }); + }, + createList(opts = {}) { return this._makeRequest({ method: "POST", path: "/checklists.json", - data: { - checklist: { - name, - }, - }, ...opts, }); }, - async createListItem({ - listId, content, ...opts + createListItem({ + listId, ...opts }) { return this._makeRequest({ method: "POST", path: `/checklists/${listId}/tasks.json`, - data: { - task: { - content, - }, - }, ...opts, }); }, - async createMultipleListItems({ - content, listId = "default", ...opts + createMultipleListItems({ + listId, ...opts }) { return this._makeRequest({ method: "POST", path: `/checklists/${listId}/import.json`, - data: { - import_content: content, - separate_with_empty_line: false, - }, ...opts, }); }, - async watchNewLists() { - const lists = await this.getLists(); - return lists; // Emit new event when lists change - }, - async watchNewListItems({ listId }) { - const items = await this._makeRequest({ - path: `/checklists/${listId}/tasks.json`, - }); - return items; // Emit new event when list items change - }, }, }; diff --git a/components/checkvist/common/constants.mjs b/components/checkvist/common/constants.mjs new file mode 100644 index 0000000000000..406c51135bcf9 --- /dev/null +++ b/components/checkvist/common/constants.mjs @@ -0,0 +1,25 @@ +export const STATUS_OPTIONS = [ + { + label: "Open", + value: "0", + }, + { + label: "Closed", + value: "1", + }, + { + label: "Invalidated", + value: "2", + }, +]; + +export const SEPARATE_LINE_OPTIONS = [ + { + label: "Separate with empty line", + value: "singleItem", + }, + { + label: "One item per line", + value: "multipleItems", + }, +]; diff --git a/components/checkvist/common/utils.mjs b/components/checkvist/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/checkvist/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/checkvist/package.json b/components/checkvist/package.json new file mode 100644 index 0000000000000..11c99b63033b3 --- /dev/null +++ b/components/checkvist/package.json @@ -0,0 +1,19 @@ +{ + "name": "@pipedream/checkvist", + "version": "0.1.0", + "description": "Pipedream Checkvist Components", + "main": "checkvist.app.mjs", + "keywords": [ + "pipedream", + "checkvist" + ], + "homepage": "https://pipedream.com/apps/checkvist", + "author": "Pipedream (https://pipedream.com/)", + "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" + } +} diff --git a/components/checkvist/sources/common/base.mjs b/components/checkvist/sources/common/base.mjs new file mode 100644 index 0000000000000..70fe935687f2a --- /dev/null +++ b/components/checkvist/sources/common/base.mjs @@ -0,0 +1,69 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import checkvist from "../../checkvist.app.mjs"; + +export default { + props: { + checkvist, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getLastId() { + return this.db.get("lastId") || 0; + }, + _setLastId(lastId) { + this.db.set("lastId", lastId); + }, + getArgs() { + return {}; + }, + async emitEvent(maxResults = false) { + const lastId = this._getLastId(); + const fn = this.getFunction(); + + const response = await fn({ + ...this.getArgs(), + params: { + order: "id:desc", + }, + }); + + let responseArray = []; + for (const item of response) { + if (item.id <= lastId) break; + responseArray.push(item); + } + + if (responseArray.length) { + if (maxResults && (responseArray.length > maxResults)) { + responseArray.length = maxResults; + } + this._setLastId(responseArray[0].id); + } + + for (const item of responseArray.reverse()) { + const summary = this.getSummary(item); + this.$emit(item, { + id: item.id, + summary: summary.length > 40 + ? `${summary.slice(0, 39)}...` + : summary, + ts: Date.parse(item.created_at), + }); + } + }, + }, + hooks: { + async deploy() { + await this.emitEvent(25); + }, + }, + async run() { + await this.emitEvent(); + }, +}; diff --git a/components/checkvist/sources/new-list-item/new-list-item.mjs b/components/checkvist/sources/new-list-item/new-list-item.mjs index 5907b73122052..479fd1087ed01 100644 --- a/components/checkvist/sources/new-list-item/new-list-item.mjs +++ b/components/checkvist/sources/new-list-item/new-list-item.mjs @@ -1,76 +1,36 @@ -import { - axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, -} from "@pipedream/platform"; -import checkvist from "../../checkvist.app.mjs"; +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; export default { + ...common, key: "checkvist-new-list-item", name: "New List Item Added", - description: "Emit new event when a new list item is added in a selected list. [See the documentation](https://checkvist.com/auth/api)", - version: "0.0.{{ts}}", + description: "Emit new event when a new list item is added in a selected list.", + version: "0.0.1", type: "source", dedupe: "unique", props: { - checkvist, - db: "$.service.db", - timer: { - type: "$.interface.timer", - default: { - intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, - }, - }, + ...common.props, listId: { propDefinition: [ - checkvist, + common.props.checkvist, "listId", ], }, }, - hooks: { - async deploy() { - await this.emitRecentItems(); - }, - }, methods: { - async emitRecentItems() { - const items = await this.checkvist.watchNewListItems({ - listId: this.listId, - }); - items.slice(0, 50).forEach((item) => { - this.$emit(item, { - id: `${item.id}`, - summary: `New Item: ${item.content}`, - ts: Date.parse(item.created_at), - }); - }); - this._setLastItemId(items[0]?.id); + ...common.methods, + getFunction() { + return this.checkvist.getListItems; }, - _getLastItemId() { - return this.db.get("lastItemId"); + getArgs() { + return { + listId: this.listId, + }; }, - _setLastItemId(id) { - this.db.set("lastItemId", id); + getSummary(item) { + return `New Item: ${item.content}`; }, }, - async run() { - const lastItemId = this._getLastItemId(); - - const items = await this.checkvist.watchNewListItems({ - listId: this.listId, - }); - - for (const item of items) { - if (!lastItemId || item.id > lastItemId) { - this.$emit(item, { - id: `${item.id}`, - summary: `New Item: ${item.content}`, - ts: Date.parse(item.created_at), - }); - } - } - - if (items.length > 0) { - this._setLastItemId(items[0].id); - } - }, + sampleEmit, }; diff --git a/components/checkvist/sources/new-list-item/test-event.mjs b/components/checkvist/sources/new-list-item/test-event.mjs new file mode 100644 index 0000000000000..f9704b6259bcd --- /dev/null +++ b/components/checkvist/sources/new-list-item/test-event.mjs @@ -0,0 +1,21 @@ +export default { + "id": 66743402, + "parent_id": 0, + "checklist_id": 910790, + "status": 0, + "position": 9, + "tasks": [], + "update_line": "created by Username", + "updated_at": "2024/11/01 15:37:54 +0000", + "created_at": "2024/11/01 15:37:54 +0000", + "due": null, + "content": "Root task", + "collapsed": false, + "comments_count": 0, + "assignee_ids": [], + "details": {}, + "link_ids": [], + "backlink_ids": [], + "tags": {}, + "tags_as_text": "" +} \ No newline at end of file diff --git a/components/checkvist/sources/new-list/new-list.mjs b/components/checkvist/sources/new-list/new-list.mjs index 0f98b227d9297..04141a62cdc3a 100644 --- a/components/checkvist/sources/new-list/new-list.mjs +++ b/components/checkvist/sources/new-list/new-list.mjs @@ -1,61 +1,22 @@ -import checkvist from "../../checkvist.app.mjs"; -import { - axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, -} from "@pipedream/platform"; +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; export default { + ...common, key: "checkvist-new-list", name: "New List Created", - description: "Emit new event when a new list is created in your Checkvist account. [See the documentation](https://checkvist.com/auth/api)", - version: "0.0.{{ts}}", + description: "Emit new event when a new list is created in your Checkvist account.", + version: "0.0.1", type: "source", dedupe: "unique", - props: { - checkvist, - db: "$.service.db", - timer: { - type: "$.interface.timer", - default: { - intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, - }, - }, - }, - hooks: { - async deploy() { - const lists = await this.checkvist.getLists(); - lists.slice(0, 50).forEach((list) => this.emitList(list)); - if (lists.length) this._setLastListId(lists[0].id); - }, - }, methods: { - emitList(list) { - const ts = Date.parse(list.created_at) || Date.now(); - this.$emit(list, { - id: list.id, - summary: `New list: ${list.name}`, - ts, - }); + ...common.methods, + getFunction() { + return this.checkvist.getLists; }, - _getLastListId() { - return this.db.get("lastListId"); + getSummary(list) { + return `New list: ${list.name}`; }, - _setLastListId(lastListId) { - this.db.set("lastListId", lastListId); - }, - }, - async run() { - const lastListId = this._getLastListId(); - const lists = await this.checkvist.getLists(); - const newLists = lastListId - ? lists.filter((list) => list.id > lastListId) - : lists; - - for (const list of newLists) { - this.emitList(list); - } - - if (newLists.length) { - this._setLastListId(newLists[0].id); - } }, + sampleEmit, }; diff --git a/components/checkvist/sources/new-list/test-event.mjs b/components/checkvist/sources/new-list/test-event.mjs new file mode 100644 index 0000000000000..53ab1208d8ab0 --- /dev/null +++ b/components/checkvist/sources/new-list/test-event.mjs @@ -0,0 +1,20 @@ +export default { + "id": 910780, + "name": "Introduction to Checkvist", + "updated_at": "2024/10/31 18:49:45 +0000", + "public": false, + "options": 2, + "created_at": "2024/10/31 18:49:45 +0000", + "markdown?": true, + "archived": false, + "read_only": false, + "user_count": 1, + "user_updated_at": "2024/10/31 18:49:45 +0000", + "related_task_ids": null, + "percent_completed": 0, + "task_count": 44, + "task_completed": 0, + "item_count": 68, + "tags": {}, + "tags_as_text": "" +} \ No newline at end of file From eaedf5069ecfd8f6d10d98b7abe5105a1ba9e746 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 1 Nov 2024 12:44:43 -0300 Subject: [PATCH 3/3] pnpm update --- pnpm-lock.yaml | 128 ++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3679f5d4a618c..e06e46e3a7b40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1665,6 +1665,12 @@ importers: dependencies: '@pipedream/platform': 1.5.1 + components/checkvist: + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 + components/cheddar: specifiers: {} @@ -13224,55 +13230,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: - resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sts': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sts' - - aws-crt - dev: false - /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13508,7 +13465,55 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 + '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - aws-crt + dev: false + + /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: + resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sso-oidc': 3.600.0 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13547,6 +13552,7 @@ packages: '@smithy/util-utf8': 3.0.0 tslib: 2.6.3 transitivePeerDependencies: + - '@aws-sdk/client-sso-oidc' - aws-crt dev: false @@ -14615,7 +14621,7 @@ packages: '@azure/logger': 1.0.4 '@types/node-fetch': 2.6.6 '@types/tunnel': 0.0.3 - form-data: 4.0.0 + form-data: 4.0.1 node-fetch: 2.7.0 process: 0.11.10 tslib: 2.6.3 @@ -14652,7 +14658,7 @@ packages: '@azure/core-tracing': 1.0.1 '@azure/core-util': 1.5.0 '@azure/logger': 1.0.4 - form-data: 4.0.0 + form-data: 4.0.1 http-proxy-agent: 5.0.0 https-proxy-agent: 5.0.1 tslib: 2.6.3 @@ -17842,7 +17848,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6 @@ -21560,12 +21566,6 @@ packages: dependencies: undici-types: 5.26.5 - /@types/node/22.7.9: - resolution: {integrity: sha512-jrTfRC7FM6nChvU7X2KqcrgquofrWLFDeYC1hKfwNWomVvrn7JIksqf344WN2X/y8xrgqBd2dJATZV4GbatBfg==} - dependencies: - undici-types: 6.19.8 - dev: false - /@types/normalize-package-data/2.4.2: resolution: {integrity: sha512-lqa4UEhhv/2sjjIQgjX8B+RBjj47eo0mzGasklVJ78UKGQY1r0VpB9XHDaZZO9qzEFDdy4MrXLuEaSmPrPSe/A==} dev: true @@ -21699,7 +21699,7 @@ packages: /@types/ws/8.5.12: resolution: {integrity: sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==} dependencies: - '@types/node': 22.7.9 + '@types/node': 20.16.1 dev: false /@types/ws/8.5.3: @@ -22560,7 +22560,7 @@ packages: resolution: {integrity: sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==} dependencies: follow-redirects: 1.15.9 - form-data: 4.0.0 + form-data: 4.0.1 proxy-from-env: 1.1.0 transitivePeerDependencies: - debug @@ -22570,7 +22570,7 @@ packages: resolution: {integrity: sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==} dependencies: follow-redirects: 1.15.9 - form-data: 4.0.0 + form-data: 4.0.1 proxy-from-env: 1.1.0 transitivePeerDependencies: - debug @@ -22619,7 +22619,7 @@ packages: resolution: {integrity: sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==} dependencies: follow-redirects: 1.15.9_debug@3.2.7 - form-data: 4.0.0 + form-data: 4.0.1 proxy-from-env: 1.1.0 transitivePeerDependencies: - debug @@ -34412,7 +34412,7 @@ packages: cookiejar: 2.1.4 debug: 4.3.6 fast-safe-stringify: 2.1.1 - form-data: 4.0.0 + form-data: 4.0.1 formidable: 2.1.2 methods: 1.1.2 mime: 2.6.0