-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Welcome: Added new action components. (#13770)
- Loading branch information
Showing
10 changed files
with
835 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
components/welcome/sources/event-created/event-created.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.