Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions components/welcome/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const BASE_URL = "https://app.experiencewelcome.com";
const VERSION_PATH = "/api/v1";
const LAST_DATE_AT = "lastDateAt";
const IS_FIRST_RUN = "isFirstRun";
const DEFAULT_MAX = 100;
const DEFAULT_LIMIT = 25;

export default {
BASE_URL,
VERSION_PATH,
DEFAULT_MAX,
DEFAULT_LIMIT,
LAST_DATE_AT,
IS_FIRST_RUN,
};
17 changes: 17 additions & 0 deletions components/welcome/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
async function iterate(iterations) {
const items = [];
for await (const item of iterations) {
items.push(item);
}
return items;
}

function getNestedProperty(obj, propertyString) {
const properties = propertyString.split(".");
return properties.reduce((prev, curr) => prev?.[curr], obj);
}

export default {
iterate,
getNestedProperty,
};
7 changes: 5 additions & 2 deletions components/welcome/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/welcome",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Welcome Components",
"main": "welcome.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
112 changes: 112 additions & 0 deletions components/welcome/sources/common/polling.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {
ConfigurationError,
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
} from "@pipedream/platform";
import app from "../../welcome.app.mjs";
import constants from "../../common/constants.mjs";

export default {
props: {
app,
db: "$.service.db",
timer: {
type: "$.interface.timer",
label: "Polling Schedule",
description: "How often to poll the API",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
hooks: {
async deploy() {
this.setIsFirstRun(true);
},
},
methods: {
setIsFirstRun(value) {
this.db.set(constants.IS_FIRST_RUN, value);
},
getIsFirstRun() {
return this.db.get(constants.IS_FIRST_RUN);
},
generateMeta() {
throw new ConfigurationError("generateMeta is not implemented");
},
setLastDateAt(value) {
this.db.set(constants.LAST_DATE_AT, value);
},
getLastDateAt() {
return this.db.get(constants.LAST_DATE_AT);
},
getDateField() {
throw new ConfigurationError("getDateField is not implemented");
},
getResourceName() {
throw new ConfigurationError("getResourceName is not implemented");
},
getResourcesFn() {
throw new ConfigurationError("getResourcesFn is not implemented");
},
getResourcesFnArgs() {
throw new ConfigurationError("getResourcesFnArgs is not implemented");
},
processResource(resource) {
const meta = this.generateMeta(resource);
this.$emit(resource, meta);
},
processResources(resources) {
Array.from(resources)
.forEach(this.processResource);
},
},
async run() {
const {
app,
getDateField,
getLastDateAt,
getResourcesFn,
getResourcesFnArgs,
getResourceName,
processResources,
getIsFirstRun,
setIsFirstRun,
setLastDateAt,
} = this;

const isFirstRun = getIsFirstRun();
const dateField = getDateField();
const lastDateAt = getLastDateAt();

const otherArgs = isFirstRun
? {
max: constants.DEFAULT_LIMIT,
}
: {
dateField,
lastDateAt,
};

const resources = await app.paginate({
resourcesFn: getResourcesFn(),
resourcesFnArgs: getResourcesFnArgs(),
resourceName: getResourceName(),
...otherArgs,
});

if (isFirstRun && resources.length) {
const [
firstResource,
] = Array.from(resources).reverse();
if (firstResource) {
setLastDateAt(firstResource[dateField]);
}
}

processResources(resources);

if (isFirstRun) {
setIsFirstRun(false);
}
},
};
37 changes: 37 additions & 0 deletions components/welcome/sources/event-created/event-created.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import common from "../common/polling.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "welcome-event-created",
name: "New Event Created",
description: "Emit new event when a new event is created in Welcome. [See the documentation](https://app.experiencewelcome.com/api-docs/index.html)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getDateField() {
return "updatedAt";
},
getResourceName() {
return "events";
},
getResourcesFn() {
return this.app.listEvents;
},
getResourcesFnArgs() {
return {
debug: true,
};
},
generateMeta(resource) {
return {
id: resource.id,
summary: `New Event: ${resource.name}`,
ts: Date.parse(resource.updatedAt),
};
},
},
sampleEmit,
};
Loading