Skip to content

Commit

Permalink
New Components - taskade (#12646)
Browse files Browse the repository at this point in the history
* taskade init

* new-components

* pnpm-lock.yaml
  • Loading branch information
michelle0927 authored Jul 4, 2024
1 parent 572351b commit 8baf6c1
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 7 deletions.
75 changes: 75 additions & 0 deletions components/taskade/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import taskade from "../../taskade.app.mjs";

export default {
key: "taskade-create-task",
name: "Create Task",
description: "Creates a new task in Taskade. [See the documentation](https://developers.taskade.com/docs/api/tasks/create)",
version: "0.0.1",
type: "action",
props: {
taskade,
projectId: {
propDefinition: [
taskade,
"projectId",
],
},
content: {
type: "string",
label: "Content",
description: "Content of the task",
},
contentType: {
type: "string",
label: "Content Type",
description: "The type of content",
options: [
"text/markdown",
"text/plain",
],
},
placement: {
type: "string",
label: "Placement",
description: "Placement of the task",
options: [
"afterbegin",
"beforeend",
],
},
assignees: {
type: "string[]",
label: "Assignees",
description: "An array of user handles to assign to the task",
optional: true,
},
},
async run({ $ }) {
const task = await this.taskade.createTask({
$,
projectId: this.projectId,
data: {
tasks: [
{
content: this.content,
contentType: this.contentType,
placement: this.placement,
},
],
},
});
const taskId = task.item[0].id;
if (this.assignees?.length) {
await this.taskade.assignTask({
$,
projectId: this.projectId,
taskId,
data: {
handles: this.assignees,
},
});
}
$.export("$summary", `Successfully created task with ID ${taskId}`);
return task;
},
};
7 changes: 5 additions & 2 deletions components/taskade/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/taskade",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Taskade Components",
"main": "taskade.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
77 changes: 77 additions & 0 deletions components/taskade/sources/new-task-created/new-task-created.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import taskade from "../../taskade.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import sampleEmit from "./test-event.mjs";

export default {
key: "taskade-new-task-created",
name: "New Task Created",
description: "Emit new event when a new task is created in Taskade",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
taskade,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
projectId: {
propDefinition: [
taskade,
"projectId",
],
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
methods: {
_getPreviousIds() {
return this.db.get("previousIds") || {};
},
_setPreviousIds(previousIds) {
this.db.set("previousIds", previousIds);
},
emitEvent(task) {
const meta = this.generateMeta(task);
this.$emit(task, meta);
},
generateMeta(task) {
return {
id: task.id,
summary: `New Task ID: ${task.id}`,
ts: Date.now(),
};
},
async processEvent(max) {
const tasks = [];
const items = this.taskade.paginate({
resourceFn: this.taskade.listTasks,
args: {
projectId: this.projectId,
},
resourceType: "items",
});
for await (const item of items) {
tasks.push(item);
}
let previousIds = this._getPreviousIds();
let newTasks = tasks.filter(({ id }) => !previousIds[id]);
newTasks.forEach(({ id }) => previousIds[id] = true);
this._setPreviousIds(previousIds);
newTasks = max
? newTasks.slice(0, max)
: newTasks;
newTasks.forEach((task) => this.emitEvent(task));
},
},
async run() {
await this.processEvent();
},
sampleEmit,
};
5 changes: 5 additions & 0 deletions components/taskade/sources/new-task-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
"id": "85e89694-3ca9-49ac-8393-4595543d4643",
"text": "Getting Started",
"completed": false
}
115 changes: 111 additions & 4 deletions components/taskade/taskade.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,118 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "taskade",
propDefinitions: {},
propDefinitions: {
projectId: {
type: "string",
label: "Project ID",
description: "The identifier of a project",
async options({ page }) {
const { items } = await this.listProjects({
params: {
page: page + 1,
},
});
return items?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://www.taskade.com/api/v1";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
listProjects(opts = {}) {
return this._makeRequest({
path: "/me/projects",
...opts,
});
},
listTasks({
projectId, ...opts
}) {
return this._makeRequest({
path: `/projects/${projectId}/tasks`,
...opts,
});
},
createTask({
projectId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/projects/${projectId}/tasks`,
...opts,
});
},
assignTask({
projectId, taskId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/projects/${projectId}/tasks/${taskId}/assignees`,
...opts,
});
},
createOrUpdateDueDate({
projectId, taskId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/projects/${projectId}/tasks/${taskId}/date`,
...opts,
});
},
async *paginate({
resourceFn,
args,
resourceType,
max,
}) {
args = {
...args,
params: {
...args.params,
},
};
let count = 0;
do {
const results = await resourceFn(args);
const items = resourceType
? results[resourceType]
: results;
if (!items?.length) {
return;
}
for (const item of items) {
yield item;
count++;
if (max && max >= count) {
return;
}
}
args.params.after = items[items.length - 1].id;
} while (args.params.after);
},
},
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8baf6c1

Please sign in to comment.