Skip to content

Commit baaf485

Browse files
authored
Welcome: Added new action components. (#13770)
1 parent c73c341 commit baaf485

File tree

10 files changed

+835
-7
lines changed

10 files changed

+835
-7
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const BASE_URL = "https://app.experiencewelcome.com";
2+
const VERSION_PATH = "/api/v1";
3+
const LAST_DATE_AT = "lastDateAt";
4+
const IS_FIRST_RUN = "isFirstRun";
5+
const DEFAULT_MAX = 100;
6+
const DEFAULT_LIMIT = 25;
7+
8+
export default {
9+
BASE_URL,
10+
VERSION_PATH,
11+
DEFAULT_MAX,
12+
DEFAULT_LIMIT,
13+
LAST_DATE_AT,
14+
IS_FIRST_RUN,
15+
};

components/welcome/common/utils.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
async function iterate(iterations) {
2+
const items = [];
3+
for await (const item of iterations) {
4+
items.push(item);
5+
}
6+
return items;
7+
}
8+
9+
function getNestedProperty(obj, propertyString) {
10+
const properties = propertyString.split(".");
11+
return properties.reduce((prev, curr) => prev?.[curr], obj);
12+
}
13+
14+
export default {
15+
iterate,
16+
getNestedProperty,
17+
};

components/welcome/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/welcome",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Welcome Components",
55
"main": "welcome.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.0"
1417
}
15-
}
18+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import {
2+
ConfigurationError,
3+
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
import app from "../../welcome.app.mjs";
6+
import constants from "../../common/constants.mjs";
7+
8+
export default {
9+
props: {
10+
app,
11+
db: "$.service.db",
12+
timer: {
13+
type: "$.interface.timer",
14+
label: "Polling Schedule",
15+
description: "How often to poll the API",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
},
21+
hooks: {
22+
async deploy() {
23+
this.setIsFirstRun(true);
24+
},
25+
},
26+
methods: {
27+
setIsFirstRun(value) {
28+
this.db.set(constants.IS_FIRST_RUN, value);
29+
},
30+
getIsFirstRun() {
31+
return this.db.get(constants.IS_FIRST_RUN);
32+
},
33+
generateMeta() {
34+
throw new ConfigurationError("generateMeta is not implemented");
35+
},
36+
setLastDateAt(value) {
37+
this.db.set(constants.LAST_DATE_AT, value);
38+
},
39+
getLastDateAt() {
40+
return this.db.get(constants.LAST_DATE_AT);
41+
},
42+
getDateField() {
43+
throw new ConfigurationError("getDateField is not implemented");
44+
},
45+
getResourceName() {
46+
throw new ConfigurationError("getResourceName is not implemented");
47+
},
48+
getResourcesFn() {
49+
throw new ConfigurationError("getResourcesFn is not implemented");
50+
},
51+
getResourcesFnArgs() {
52+
throw new ConfigurationError("getResourcesFnArgs is not implemented");
53+
},
54+
processResource(resource) {
55+
const meta = this.generateMeta(resource);
56+
this.$emit(resource, meta);
57+
},
58+
processResources(resources) {
59+
Array.from(resources)
60+
.forEach(this.processResource);
61+
},
62+
},
63+
async run() {
64+
const {
65+
app,
66+
getDateField,
67+
getLastDateAt,
68+
getResourcesFn,
69+
getResourcesFnArgs,
70+
getResourceName,
71+
processResources,
72+
getIsFirstRun,
73+
setIsFirstRun,
74+
setLastDateAt,
75+
} = this;
76+
77+
const isFirstRun = getIsFirstRun();
78+
const dateField = getDateField();
79+
const lastDateAt = getLastDateAt();
80+
81+
const otherArgs = isFirstRun
82+
? {
83+
max: constants.DEFAULT_LIMIT,
84+
}
85+
: {
86+
dateField,
87+
lastDateAt,
88+
};
89+
90+
const resources = await app.paginate({
91+
resourcesFn: getResourcesFn(),
92+
resourcesFnArgs: getResourcesFnArgs(),
93+
resourceName: getResourceName(),
94+
...otherArgs,
95+
});
96+
97+
if (isFirstRun && resources.length) {
98+
const [
99+
firstResource,
100+
] = Array.from(resources).reverse();
101+
if (firstResource) {
102+
setLastDateAt(firstResource[dateField]);
103+
}
104+
}
105+
106+
processResources(resources);
107+
108+
if (isFirstRun) {
109+
setIsFirstRun(false);
110+
}
111+
},
112+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import common from "../common/polling.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "welcome-event-created",
7+
name: "New Event Created",
8+
description: "Emit new event when a new event is created in Welcome. [See the documentation](https://app.experiencewelcome.com/api-docs/index.html)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getDateField() {
15+
return "updatedAt";
16+
},
17+
getResourceName() {
18+
return "events";
19+
},
20+
getResourcesFn() {
21+
return this.app.listEvents;
22+
},
23+
getResourcesFnArgs() {
24+
return {
25+
debug: true,
26+
};
27+
},
28+
generateMeta(resource) {
29+
return {
30+
id: resource.id,
31+
summary: `New Event: ${resource.name}`,
32+
ts: Date.parse(resource.updatedAt),
33+
};
34+
},
35+
},
36+
sampleEmit,
37+
};

0 commit comments

Comments
 (0)