@pipedream/pushcut 0.0.1 → 0.1.0

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.
@@ -0,0 +1,44 @@
1
+ import pushcut from "../../pushcut.app.mjs";
2
+
3
+ export default {
4
+ key: "pushcut-execute-homekit-scene",
5
+ name: "Execute Homekit Scene",
6
+ description: "Schedules an Automation Server action request for a homekit scene. [See the documentation](https://www.pushcut.io/webapi)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ pushcut,
11
+ homekit: {
12
+ propDefinition: [
13
+ pushcut,
14
+ "homekitScene",
15
+ ],
16
+ },
17
+ timeout: {
18
+ propDefinition: [
19
+ pushcut,
20
+ "timeout",
21
+ ],
22
+ },
23
+ delay: {
24
+ propDefinition: [
25
+ pushcut,
26
+ "delay",
27
+ ],
28
+ },
29
+ },
30
+ async run({ $ }) {
31
+ const response = await this.pushcut.executeAction({
32
+ data: {
33
+ homekit: this.homekit,
34
+ timeout: this.timeout,
35
+ delay: this.delay,
36
+ },
37
+ $,
38
+ });
39
+
40
+ $.export("$summary", `Successfully executed homekit ${this.homekit}.`);
41
+
42
+ return response;
43
+ },
44
+ };
@@ -0,0 +1,44 @@
1
+ import pushcut from "../../pushcut.app.mjs";
2
+
3
+ export default {
4
+ key: "pushcut-execute-shortcut",
5
+ name: "Execute Shortcut",
6
+ description: "Schedules an Automation Server action request for a shortcut. [See the documentation](https://www.pushcut.io/webapi)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ pushcut,
11
+ shortcut: {
12
+ propDefinition: [
13
+ pushcut,
14
+ "shortcut",
15
+ ],
16
+ },
17
+ timeout: {
18
+ propDefinition: [
19
+ pushcut,
20
+ "timeout",
21
+ ],
22
+ },
23
+ delay: {
24
+ propDefinition: [
25
+ pushcut,
26
+ "delay",
27
+ ],
28
+ },
29
+ },
30
+ async run({ $ }) {
31
+ const response = await this.pushcut.executeAction({
32
+ data: {
33
+ shortcut: this.shortcut,
34
+ timeout: this.timeout,
35
+ delay: this.delay,
36
+ },
37
+ $,
38
+ });
39
+
40
+ $.export("$summary", `Successfully executed shortcut ${this.shortcut}.`);
41
+
42
+ return response;
43
+ },
44
+ };
@@ -0,0 +1,30 @@
1
+ import pushcut from "../../pushcut.app.mjs";
2
+
3
+ export default {
4
+ key: "pushcut-send-notification",
5
+ name: "Send Notification",
6
+ description: "Sends a smart notification to your devices. [See the documentation](https://www.pushcut.io/webapi)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ pushcut,
11
+ notification: {
12
+ propDefinition: [
13
+ pushcut,
14
+ "notification",
15
+ ],
16
+ },
17
+ },
18
+ async run({ $ }) {
19
+ const response = await this.pushcut.sendNotification({
20
+ notification: this.notification,
21
+ $,
22
+ });
23
+
24
+ if (response.id) {
25
+ $.export("$summary", `Successfully sent notification with ID ${response.id}.`);
26
+ }
27
+
28
+ return response;
29
+ },
30
+ };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@pipedream/pushcut",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Pushcut Components",
5
- "main": "dist/app/pushcut.app.mjs",
5
+ "main": "pushcut.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "pushcut"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/pushcut",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
16
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1"
17
17
  }
18
18
  }
@@ -0,0 +1,103 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "pushcut",
6
+ propDefinitions: {
7
+ notification: {
8
+ type: "string",
9
+ label: "Notification",
10
+ description: "Name of the notification",
11
+ async options() {
12
+ const notifications = await this.listNotifications();
13
+ return notifications?.map(({ id }) => id ) || [];
14
+ },
15
+ },
16
+ shortcut: {
17
+ type: "string",
18
+ label: "Shortcut",
19
+ description: "Name of the shortcut",
20
+ async options() {
21
+ const shortcuts = await this.listShortcuts();
22
+ return shortcuts?.map(({ id }) => id ) || [];
23
+ },
24
+ },
25
+ homekitScene: {
26
+ type: "string",
27
+ label: "Homekit Scene",
28
+ description: "Name of the homekit scene",
29
+ async options() {
30
+ const scenes = await this.listHomekitScenes();
31
+ return scenes?.map(({ id }) => id ) || [];
32
+ },
33
+ },
34
+ timeout: {
35
+ type: "string",
36
+ label: "Timeout",
37
+ description: "Timeout in seconds, or 'nowait'",
38
+ optional: true,
39
+ default: "nowait",
40
+ },
41
+ delay: {
42
+ type: "string",
43
+ label: "Delay",
44
+ description: "Duration in which this request should be executed. Eg: 10s, 15m, 6h",
45
+ optional: true,
46
+ },
47
+ },
48
+ methods: {
49
+ _baseUrl() {
50
+ return "https://api.pushcut.io/v1";
51
+ },
52
+ _headers() {
53
+ return {
54
+ "API-Key": `${this.$auth.api_key}`,
55
+ };
56
+ },
57
+ _makeRequest({
58
+ $ = this,
59
+ path,
60
+ ...args
61
+ }) {
62
+ return axios($, {
63
+ url: `${this._baseUrl()}${path}`,
64
+ headers: this._headers(),
65
+ ...args,
66
+ });
67
+ },
68
+ listNotifications(args = {}) {
69
+ return this._makeRequest({
70
+ path: "/notifications",
71
+ ...args,
72
+ });
73
+ },
74
+ listShortcuts(args = {}) {
75
+ return this._makeRequest({
76
+ path: "/shortcuts",
77
+ ...args,
78
+ });
79
+ },
80
+ listHomekitScenes(args = {}) {
81
+ return this._makeRequest({
82
+ path: "/scenes",
83
+ ...args,
84
+ });
85
+ },
86
+ executeAction(args = {}) {
87
+ return this._makeRequest({
88
+ path: "/execute",
89
+ method: "POST",
90
+ ...args,
91
+ });
92
+ },
93
+ sendNotification({
94
+ notification, ...args
95
+ }) {
96
+ return this._makeRequest({
97
+ path: `/notifications/${notification}`,
98
+ method: "POST",
99
+ ...args,
100
+ });
101
+ },
102
+ },
103
+ };
@@ -0,0 +1,47 @@
1
+ import pushcut from "../../pushcut.app.mjs";
2
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "pushcut-action-created",
6
+ name: "New Action Created",
7
+ description: "Emit new event when a new action is created.",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ pushcut,
13
+ timer: {
14
+ type: "$.interface.timer",
15
+ default: {
16
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
17
+ },
18
+ },
19
+ actionType: {
20
+ type: "string",
21
+ label: "Type",
22
+ description: "Type of new action to watch for",
23
+ options: [
24
+ "shortcut",
25
+ "homekit",
26
+ ],
27
+ },
28
+ },
29
+ methods: {
30
+ generateMeta(action) {
31
+ return {
32
+ id: action.id,
33
+ summary: `${action.id}`,
34
+ ts: Date.now(),
35
+ };
36
+ },
37
+ },
38
+ async run() {
39
+ const actions = this.actionType === "shortcut"
40
+ ? await this.pushcut.listShortcuts()
41
+ : await this.pushcut.listHomekitScenes();
42
+ for (const action of actions) {
43
+ const meta = this.generateMeta(action);
44
+ this.$emit(action, meta);
45
+ }
46
+ },
47
+ };