Skip to content

Commit 3041269

Browse files
committed
offlight init
1 parent 6a7ab4f commit 3041269

File tree

4 files changed

+216
-4
lines changed

4 files changed

+216
-4
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import offlight from "../../offlight.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "offlight-create-task",
6+
name: "Create Task",
7+
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}}",
9+
type: "action",
10+
props: {
11+
offlight,
12+
taskName: {
13+
propDefinition: [
14+
offlight,
15+
"taskName",
16+
],
17+
},
18+
taskNote: {
19+
propDefinition: [
20+
offlight,
21+
"taskNote",
22+
],
23+
optional: true,
24+
},
25+
taskDeadline: {
26+
propDefinition: [
27+
offlight,
28+
"taskDeadline",
29+
],
30+
optional: true,
31+
},
32+
identifier: {
33+
propDefinition: [
34+
offlight,
35+
"identifier",
36+
],
37+
optional: true,
38+
},
39+
sourceName: {
40+
propDefinition: [
41+
offlight,
42+
"sourceName",
43+
],
44+
optional: true,
45+
},
46+
sourceLink: {
47+
propDefinition: [
48+
offlight,
49+
"sourceLink",
50+
],
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
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,
62+
});
63+
64+
$.export("$summary", `Task successfully created with ID: ${response.id}`);
65+
return response;
66+
},
67+
};
Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,106 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "offlight",
4-
propDefinitions: {},
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+
},
543
methods: {
6-
// this.$auth contains connected account data
744
authKeys() {
845
console.log(Object.keys(this.$auth));
946
},
47+
_baseUrl() {
48+
return "https://www.offlight.work";
49+
},
50+
async _makeRequest(opts = {}) {
51+
const {
52+
$ = this,
53+
method = "GET",
54+
path = "/",
55+
headers,
56+
...otherOpts
57+
} = opts;
58+
return axios($, {
59+
...otherOpts,
60+
method,
61+
url: this._baseUrl() + path,
62+
headers: {
63+
...headers,
64+
"X-API-KEY": this.$auth.api_key,
65+
},
66+
});
67+
},
68+
async createTask({
69+
taskName,
70+
taskNote,
71+
taskDeadline,
72+
identifier,
73+
sourceName,
74+
sourceLink,
75+
}) {
76+
return this._makeRequest({
77+
method: "POST",
78+
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+
},
87+
});
88+
},
89+
async getDoneTasks(opts = {}) {
90+
return this._makeRequest({
91+
...opts,
92+
method: "GET",
93+
path: "/zapier/doneTasks",
94+
});
95+
},
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;
104+
},
10105
},
11-
};
106+
};

components/offlight/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import offlight from "../../offlight.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
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}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
offlight: {
13+
type: "app",
14+
app: "offlight",
15+
},
16+
http: {
17+
type: "$.interface.http",
18+
customResponse: false,
19+
},
20+
db: "$.service.db",
21+
},
22+
hooks: {
23+
async deploy() {
24+
const tasks = await this.offlight.getDoneTasks({
25+
max: 50,
26+
});
27+
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+
});
33+
}
34+
},
35+
async activate() {
36+
// No specific activation for this component
37+
},
38+
async deactivate() {
39+
// No specific deactivation for this component
40+
},
41+
},
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+
});
49+
},
50+
};

0 commit comments

Comments
 (0)