@pipedream/proofly 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,41 @@
1
+ import app from "../../proofly.app.mjs";
2
+
3
+ export default {
4
+ key: "proofly-get-notification-data",
5
+ name: "Get Notification Data",
6
+ description: "Get data for a notification. [See the documentation here](https://proofly.io/developers)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ app,
11
+ campaignId: {
12
+ propDefinition: [
13
+ app,
14
+ "campaignId",
15
+ ],
16
+ },
17
+ notificationId: {
18
+ propDefinition: [
19
+ app,
20
+ "notificationId",
21
+ ({ campaignId }) => ({
22
+ campaignId,
23
+ }),
24
+ ],
25
+ },
26
+ },
27
+ async run({ $ }) {
28
+ const {
29
+ app,
30
+ notificationId,
31
+ } = this;
32
+
33
+ const response = await app.listData({
34
+ $,
35
+ notificationId,
36
+ });
37
+
38
+ $.export("$summary", `Successfully retrieved notification with status \`${response.status}\``);
39
+ return response;
40
+ },
41
+ };
@@ -0,0 +1,43 @@
1
+ import app from "../../proofly.app.mjs";
2
+
3
+ export default {
4
+ key: "proofly-toggle-campaign",
5
+ name: "Toggle Campaign Status",
6
+ description: "Switch a campaign's status between active and inactive. [See the documentation](https://proofly.io/developers)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ app,
11
+ campaignId: {
12
+ propDefinition: [
13
+ app,
14
+ "campaignId",
15
+ ],
16
+ },
17
+ },
18
+ methods: {
19
+ switchCampaignStatus({
20
+ campaignId, ...args
21
+ }) {
22
+ return this.app.put({
23
+ path: `/campaign/${campaignId}`,
24
+ ...args,
25
+ });
26
+ },
27
+ },
28
+ async run({ $ }) {
29
+ const {
30
+ campaignId,
31
+ switchCampaignStatus,
32
+ } = this;
33
+
34
+ const response = await switchCampaignStatus({
35
+ $,
36
+ campaignId,
37
+ });
38
+
39
+ $.export("$summary", `Successfully toggled campaign with status \`${response.status}\` and message \`${response.data}\``);
40
+
41
+ return response;
42
+ },
43
+ };
@@ -0,0 +1,7 @@
1
+ const BASE_URL = "https://proofly.io";
2
+ const VERSION_PATH = "/api";
3
+
4
+ export default {
5
+ BASE_URL,
6
+ VERSION_PATH,
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/proofly",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Proofly Components",
5
5
  "main": "proofly.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.6.0"
14
17
  }
15
18
  }
package/proofly.app.mjs CHANGED
@@ -1,11 +1,95 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import constants from "./common/constants.mjs";
3
+
1
4
  export default {
2
5
  type: "app",
3
6
  app: "proofly",
4
- propDefinitions: {},
7
+ propDefinitions: {
8
+ campaignId: {
9
+ type: "string",
10
+ label: "Campaign ID",
11
+ description: "The unique identifier for the campaign",
12
+ async options() {
13
+ const { data } = await this.listCampaigns();
14
+ return data.map(({
15
+ id: value, name: label,
16
+ }) => ({
17
+ label,
18
+ value,
19
+ }));
20
+ },
21
+ },
22
+ notificationId: {
23
+ type: "string",
24
+ label: "Notification ID",
25
+ description: "The unique identifier for the notification",
26
+ async options({ campaignId }) {
27
+ const { data } = await this.listNotifications({
28
+ campaignId,
29
+ });
30
+ return data.map(({
31
+ id: value, name: label,
32
+ }) => ({
33
+ label,
34
+ value,
35
+ }));
36
+ },
37
+ },
38
+ },
5
39
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
40
+ getUrl(path) {
41
+ return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
42
+ },
43
+ getHeaders(headers) {
44
+ return {
45
+ ...headers,
46
+ "X-Api-Key": this.$auth.api_key,
47
+ };
48
+ },
49
+ async _makeRequest({
50
+ $ = this, path, headers, ...args
51
+ } = {}) {
52
+ const config = {
53
+ ...args,
54
+ url: this.getUrl(path),
55
+ headers: this.getHeaders(headers),
56
+ };
57
+
58
+ const response = await axios($, config);
59
+
60
+ if (response?.ok !== true) {
61
+ throw new Error(`Response Error: ${JSON.stringify(response)}`);
62
+ }
63
+
64
+ return response;
65
+ },
66
+ put(args = {}) {
67
+ return this._makeRequest({
68
+ method: "put",
69
+ ...args,
70
+ });
71
+ },
72
+ listCampaigns(args = {}) {
73
+ return this._makeRequest({
74
+ path: "/campaigns",
75
+ ...args,
76
+ });
77
+ },
78
+ listNotifications({
79
+ campaignId, ...args
80
+ }) {
81
+ return this._makeRequest({
82
+ path: `/campaign/${campaignId}`,
83
+ ...args,
84
+ });
85
+ },
86
+ listData({
87
+ notificationId, ...args
88
+ }) {
89
+ return this._makeRequest({
90
+ path: `/data/${notificationId}`,
91
+ ...args,
92
+ });
9
93
  },
10
94
  },
11
- };
95
+ };
@@ -0,0 +1,53 @@
1
+ import {
2
+ ConfigurationError,
3
+ DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4
+ } from "@pipedream/platform";
5
+ import app from "../../proofly.app.mjs";
6
+
7
+ export default {
8
+ props: {
9
+ app,
10
+ timer: {
11
+ type: "$.interface.timer",
12
+ label: "Polling Schedule",
13
+ description: "How often to poll the API",
14
+ default: {
15
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
16
+ },
17
+ },
18
+ },
19
+ methods: {
20
+ generateMeta() {
21
+ throw new ConfigurationError("generateMeta is not implemented");
22
+ },
23
+ getResourceName() {
24
+ throw new ConfigurationError("getResourceName is not implemented");
25
+ },
26
+ getResourcesFn() {
27
+ throw new ConfigurationError("getResourcesFn is not implemented");
28
+ },
29
+ getResourcesFnArgs() {
30
+ throw new ConfigurationError("getResourcesFnArgs is not implemented");
31
+ },
32
+ processResource(resource) {
33
+ const meta = this.generateMeta(resource);
34
+ this.$emit(resource, meta);
35
+ },
36
+ },
37
+ async run() {
38
+ const {
39
+ getResourcesFn,
40
+ getResourceName,
41
+ getResourcesFnArgs,
42
+ processResource,
43
+ } = this;
44
+
45
+ const resourcesFn = getResourcesFn();
46
+ const { [getResourceName()]: resources } =
47
+ await resourcesFn(getResourcesFnArgs());
48
+
49
+ Array.from(resources)
50
+ .reverse()
51
+ .forEach(processResource);
52
+ },
53
+ };
@@ -0,0 +1,52 @@
1
+ import common from "../common/polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "proofly-new-notification-data-created",
6
+ name: "New Notification Data Created",
7
+ description: "Emit new event when notification data is received. [See the documentation](https://proofly.io/developers)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ ...common.props,
13
+ campaignId: {
14
+ propDefinition: [
15
+ common.props.app,
16
+ "campaignId",
17
+ ],
18
+ },
19
+ notificationId: {
20
+ propDefinition: [
21
+ common.props.app,
22
+ "notificationId",
23
+ ({ campaignId }) => ({
24
+ campaignId,
25
+ }),
26
+ ],
27
+ },
28
+ },
29
+ methods: {
30
+ ...common.methods,
31
+ getResourceName() {
32
+ return "data";
33
+ },
34
+ getResourcesFn() {
35
+ return this.app.listData;
36
+ },
37
+ getResourcesFnArgs() {
38
+ return {
39
+ debug: true,
40
+ notificationId: this.notificationId,
41
+ };
42
+ },
43
+ generateMeta(resource) {
44
+ const ts = Date.parse(resource.date);
45
+ return {
46
+ id: ts,
47
+ summary: "New Notification Data",
48
+ ts,
49
+ };
50
+ },
51
+ },
52
+ };