Skip to content

Commit a22d530

Browse files
committed
[Components] offlight #14052
Sources - New Task Done (Instant) Actions - Create Task
1 parent 3041269 commit a22d530

File tree

5 files changed

+109
-139
lines changed

5 files changed

+109
-139
lines changed

components/offlight/actions/create-task/create-task.mjs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,60 @@
11
import offlight from "../../offlight.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "offlight-create-task",
65
name: "Create Task",
76
description: "Initiates the creation of a new task in Offlight. [See the documentation](https://www.offlight.work/docs/zapeir-api)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
offlight,
1211
taskName: {
13-
propDefinition: [
14-
offlight,
15-
"taskName",
16-
],
12+
type: "string",
13+
label: "Task Name",
14+
description: "The name of the task.",
1715
},
1816
taskNote: {
19-
propDefinition: [
20-
offlight,
21-
"taskNote",
22-
],
17+
type: "string",
18+
label: "Task Note",
19+
description: "A note about the task.",
2320
optional: true,
2421
},
2522
taskDeadline: {
26-
propDefinition: [
27-
offlight,
28-
"taskDeadline",
29-
],
23+
type: "string",
24+
label: "Task Deadline",
25+
description: "The deadline of the task. **In ISO 8601 format (YYY-MM-DD)**.",
3026
optional: true,
3127
},
3228
identifier: {
33-
propDefinition: [
34-
offlight,
35-
"identifier",
36-
],
29+
type: "string",
30+
label: "Identifier",
31+
description: "A unique identifier for the task.",
3732
optional: true,
3833
},
3934
sourceName: {
40-
propDefinition: [
41-
offlight,
42-
"sourceName",
43-
],
35+
type: "string",
36+
label: "Source Name",
37+
description: "The source name of the task.",
4438
optional: true,
4539
},
4640
sourceLink: {
47-
propDefinition: [
48-
offlight,
49-
"sourceLink",
50-
],
41+
type: "string",
42+
label: "Source Link",
43+
description: "The source link of the task.",
5144
optional: true,
5245
},
5346
},
5447
async run({ $ }) {
5548
const response = await this.offlight.createTask({
56-
taskName: this.taskName,
57-
taskNote: this.taskNote,
58-
taskDeadline: this.taskDeadline,
59-
identifier: this.identifier,
60-
sourceName: this.sourceName,
61-
sourceLink: this.sourceLink,
49+
$,
50+
data: {
51+
task_name: this.taskName,
52+
task_note: this.taskNote,
53+
task_deadline: this.taskDeadline,
54+
identifier: this.identifier,
55+
source_name: this.sourceName,
56+
source_link: this.sourceLink,
57+
},
6258
});
6359

6460
$.export("$summary", `Task successfully created with ID: ${response.id}`);

components/offlight/offlight.app.mjs

Lines changed: 27 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,104 +3,51 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "offlight",
6-
propDefinitions: {
7-
taskName: {
8-
type: "string",
9-
label: "Task Name",
10-
description: "The name of the task.",
11-
},
12-
taskNote: {
13-
type: "string",
14-
label: "Task Note",
15-
description: "A note about the task.",
16-
optional: true,
17-
},
18-
taskDeadline: {
19-
type: "string",
20-
label: "Task Deadline",
21-
description: "The deadline of the task (in ISO 8601 format).",
22-
optional: true,
23-
},
24-
identifier: {
25-
type: "string",
26-
label: "Identifier",
27-
description: "A unique identifier for the task.",
28-
optional: true,
29-
},
30-
sourceName: {
31-
type: "string",
32-
label: "Source Name",
33-
description: "The source name of the task.",
34-
optional: true,
35-
},
36-
sourceLink: {
37-
type: "string",
38-
label: "Source Link",
39-
description: "The source link of the task.",
40-
optional: true,
41-
},
42-
},
436
methods: {
44-
authKeys() {
45-
console.log(Object.keys(this.$auth));
46-
},
477
_baseUrl() {
48-
return "https://www.offlight.work";
8+
return "https://api.offlight.work";
9+
},
10+
_headers() {
11+
return {
12+
"x-api-key": `${this.$auth.api_token}`,
13+
};
4914
},
50-
async _makeRequest(opts = {}) {
51-
const {
52-
$ = this,
53-
method = "GET",
54-
path = "/",
55-
headers,
56-
...otherOpts
57-
} = opts;
15+
_makeRequest({
16+
$ = this, path, ...opts
17+
}) {
5818
return axios($, {
59-
...otherOpts,
60-
method,
6119
url: this._baseUrl() + path,
62-
headers: {
63-
...headers,
64-
"X-API-KEY": this.$auth.api_key,
65-
},
20+
headers: this._headers(),
21+
...opts,
6622
});
6723
},
68-
async createTask({
69-
taskName,
70-
taskNote,
71-
taskDeadline,
72-
identifier,
73-
sourceName,
74-
sourceLink,
75-
}) {
24+
createTask(opts = {}) {
7625
return this._makeRequest({
7726
method: "POST",
7827
path: "/zapier/task",
79-
data: {
80-
task_name: taskName,
81-
task_note: taskNote,
82-
task_deadline: taskDeadline,
83-
identifier: identifier,
84-
source_name: sourceName,
85-
source_link: sourceLink,
86-
},
28+
...opts,
8729
});
8830
},
89-
async getDoneTasks(opts = {}) {
31+
getDoneTasks(opts = {}) {
9032
return this._makeRequest({
9133
...opts,
9234
method: "GET",
9335
path: "/zapier/doneTasks",
9436
});
9537
},
96-
async paginate(fn, ...opts) {
97-
let results = [];
98-
let response;
99-
do {
100-
response = await fn(...opts);
101-
results = results.concat(response);
102-
} while (response.length);
103-
return results;
38+
createWebhook(opts = {}) {
39+
return this._makeRequest({
40+
method: "POST",
41+
path: "/zapier/webhook",
42+
...opts,
43+
});
44+
},
45+
deleteWebhook(opts = {}) {
46+
return this._makeRequest({
47+
method: "DELETE",
48+
path: "/zapier/webhook",
49+
...opts,
50+
});
10451
},
10552
},
10653
};

components/offlight/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/offlight",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream OFFLIGHT Components",
55
"main": "offlight.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
1518
}
19+
Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
11
import offlight from "../../offlight.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import sampleEmit from "./test-event.mjs";
33

44
export default {
55
key: "offlight-new-task-done-instant",
6-
name: "New Task Done Instant",
7-
description: "Emit new event when a task is marked as complete. [See the documentation](https://www.offlight.work/docs/zapeir-api)",
8-
version: "0.0.{{ts}}",
6+
name: "New Task Done (Instant)",
7+
description: "Emit new event when a task is marked as complete.",
8+
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
1111
props: {
12-
offlight: {
13-
type: "app",
14-
app: "offlight",
15-
},
12+
offlight,
1613
http: {
1714
type: "$.interface.http",
18-
customResponse: false,
1915
},
2016
db: "$.service.db",
2117
},
18+
methods: {
19+
emitTask(task) {
20+
this.$emit(task, {
21+
id: task.id,
22+
summary: `Task ${task.name} marked as done`,
23+
ts: Date.parse(task.doneAt),
24+
});
25+
},
26+
},
2227
hooks: {
2328
async deploy() {
24-
const tasks = await this.offlight.getDoneTasks({
25-
max: 50,
26-
});
29+
const tasks = await this.offlight.getDoneTasks();
2730
for (const task of tasks) {
28-
this.$emit(task, {
29-
id: task.id,
30-
summary: `Task ${task.name} marked as done`,
31-
ts: Date.parse(task.doneAt),
32-
});
31+
this.emitTask(task);
3332
}
3433
},
3534
async activate() {
36-
// No specific activation for this component
35+
await this.offlight.createWebhook({
36+
data: {
37+
purpose: "doneTask",
38+
hookUrl: this.http.endpoint,
39+
},
40+
});
3741
},
3842
async deactivate() {
39-
// No specific deactivation for this component
43+
await this.offlight.deleteWebhook({
44+
data: {
45+
purpose: "doneTask",
46+
hookUrl: this.http.endpoint,
47+
},
48+
});
4049
},
4150
},
42-
async run(event) {
43-
const { body: task } = event;
44-
this.$emit(task, {
45-
id: task.id,
46-
summary: `Task ${task.name} marked as done`,
47-
ts: Date.parse(task.doneAt),
48-
});
51+
async run({ body }) {
52+
this.emitTask(body);
4953
},
54+
sampleEmit,
5055
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default {
2+
"createdAt": "2024-09-23T19:18:54.995Z",
3+
"updatedAt": "2024-09-23T20:10:26.000Z",
4+
"plannedDate": null,
5+
"doneAt": "2024-09-23T20:10:25.136Z",
6+
"deletedAt": null,
7+
"id": "4e73c28d-0e2f-4352-9c86-62048255e1b8",
8+
"name": "🤵 Welcome to OFFLIGHT",
9+
"note": null,
10+
"status": "done",
11+
"deadline": null,
12+
"goal": null,
13+
"source": "admin",
14+
"identifier": null,
15+
"sourceName": null,
16+
"link": null,
17+
"creator": null
18+
}

0 commit comments

Comments
 (0)