@pipedream/harvest 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import harvest from "../../harvest.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "harvest-new-timeentry-entry",
|
|
5
|
+
name: "New Time Entry",
|
|
6
|
+
description: "Emit new notifications when a new time entry is created",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "source",
|
|
9
|
+
props: {
|
|
10
|
+
harvest,
|
|
11
|
+
timer: {
|
|
12
|
+
label: "Polling interval",
|
|
13
|
+
description: "Pipedream will poll Harvest API on this schedule",
|
|
14
|
+
type: "$.interface.timer",
|
|
15
|
+
default: {
|
|
16
|
+
intervalSeconds: 60 * 15, // 15 minutes
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
db: "$.service.db",
|
|
20
|
+
},
|
|
21
|
+
dedupe: "unique",
|
|
22
|
+
async run() {
|
|
23
|
+
const data = [];
|
|
24
|
+
let lastDateChecked = this.harvest.getLastDateChecked(this.db);
|
|
25
|
+
if (!lastDateChecked) {
|
|
26
|
+
lastDateChecked = new Date().toISOString();
|
|
27
|
+
this.harvest.setLastDateChecked(this.db, lastDateChecked);
|
|
28
|
+
}
|
|
29
|
+
const time_entries = await this.harvest.listTimeEntriesPaginated({
|
|
30
|
+
page: 1,
|
|
31
|
+
updatedSince: lastDateChecked,
|
|
32
|
+
});
|
|
33
|
+
for await (const time_entry of time_entries) {
|
|
34
|
+
data.push(time_entry);
|
|
35
|
+
}
|
|
36
|
+
data && data.reverse().forEach((time_entry) => {
|
|
37
|
+
this.harvest.setLastDateChecked(this.db, time_entry.updated_at);
|
|
38
|
+
this.$emit(time_entry,
|
|
39
|
+
{
|
|
40
|
+
id: time_entry.id,
|
|
41
|
+
summary: `Time Entry id: ${time_entry.id}`,
|
|
42
|
+
ts: Date.parse(time_entry.updated_at),
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|