-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Microsoft Dynamics - new sources #18849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import microsoftDynamics365Sales from "../../microsoft_dynamics_365_sales.app.mjs"; | ||
| import { | ||
| DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError, | ||
| } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| props: { | ||
| microsoftDynamics365Sales, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastTs() { | ||
| return this.db.get("lastTs") || 0; | ||
| }, | ||
| _setLastTs(lastTs) { | ||
| this.db.set("lastTs", lastTs); | ||
| }, | ||
| getArgs() { | ||
| return {}; | ||
| }, | ||
| getRelevantResults(results) { | ||
| return results; | ||
| }, | ||
| getResourceFn() { | ||
| throw new ConfigurationError("getResourceFn is not implemented"); | ||
| }, | ||
| getTsField() { | ||
| throw new ConfigurationError("getTsField is not implemented"); | ||
| }, | ||
| generateMeta() { | ||
| throw new ConfigurationError("generateMeta is not implemented"); | ||
| }, | ||
| async processEvent(max) { | ||
| const lastTs = this._getLastTs(); | ||
| let maxTs = lastTs; | ||
|
|
||
| const resourceFn = this.getResourceFn(); | ||
| const args = this.getArgs(); | ||
| const tsField = this.getTsField(); | ||
|
|
||
| const items = this.microsoftDynamics365Sales.paginate({ | ||
| fn: resourceFn, | ||
| args, | ||
| max, | ||
| }); | ||
|
|
||
| const results = []; | ||
| for await (const item of items) { | ||
| const ts = Date.parse(item[tsField]); | ||
| if (ts >= lastTs) { | ||
| results.push(item); | ||
| maxTs = Math.max(ts, maxTs); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| this._setLastTs(maxTs); | ||
|
|
||
| const relevantResults = this.getRelevantResults(results); | ||
| if (!relevantResults.length) { | ||
| return; | ||
| } | ||
|
|
||
| relevantResults.forEach((item) => { | ||
| const meta = this.generateMeta(item); | ||
| this.$emit(item, meta); | ||
| }); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.processEvent(); | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import common from "../common/common.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "microsoft_dynamics_365_sales-new-opportunity-created", | ||
| name: "New Opportunity Created", | ||
| description: "Emit new event when a new opportunity is created.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| hooks: { | ||
| async deploy() { | ||
| await this.processEvent(10); | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| getResourceFn() { | ||
| return this.microsoftDynamics365Sales.listOpportunities; | ||
| }, | ||
| getArgs() { | ||
| return { | ||
| params: { | ||
| "$orderby": "createdon desc", | ||
| }, | ||
| }; | ||
| }, | ||
| getTsField() { | ||
| return "createdon"; | ||
| }, | ||
| generateMeta(opportunity) { | ||
| return { | ||
| id: opportunity.opportunityid, | ||
| summary: `New Opportunity: ${opportunity.name}`, | ||
| ts: Date.parse(opportunity.createdon), | ||
| }; | ||
| }, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import common from "../common/common.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "microsoft_dynamics_365_sales-opportunity-close-date-updated", | ||
| name: "Opportunity Close Date Updated", | ||
|
Check warning on line 6 in components/microsoft_dynamics_365_sales/sources/opportunity-close-date-updated/opportunity-close-date-updated.mjs
|
||
| description: "Emit new event when the estimated close date of an opportunity is updated.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| _getCloseDates() { | ||
| return this.db.get("closeDates") || {}; | ||
| }, | ||
| _setCloseDates(closeDates) { | ||
| this.db.set("closeDates", closeDates); | ||
| }, | ||
| getResourceFn() { | ||
| return this.microsoftDynamics365Sales.listOpportunities; | ||
| }, | ||
| getArgs() { | ||
| return { | ||
| params: { | ||
| "$orderby": "modifiedon desc", | ||
| }, | ||
| }; | ||
| }, | ||
| getTsField() { | ||
| return "modifiedon"; | ||
| }, | ||
| getRelevantResults(results) { | ||
| const closeDates = this._getCloseDates(); | ||
| const relevantResults = []; | ||
| for (const result of results) { | ||
| if (closeDates[result.opportunityid] !== result.estimatedclosedate) { | ||
| if (closeDates[result.opportunityid]) { | ||
| relevantResults.push(result); | ||
| } | ||
| closeDates[result.opportunityid] = result.estimatedclosedate; | ||
| } | ||
| } | ||
| this._setCloseDates(closeDates); | ||
| return relevantResults; | ||
| }, | ||
| generateMeta(opportunity) { | ||
| const ts = Date.parse(opportunity.modifiedon); | ||
| return { | ||
| id: `${opportunity.opportunityid}${ts}`, | ||
| summary: `Opportunity Close Date Updated: ${opportunity.name}`, | ||
| ts, | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import common from "../common/common.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "microsoft_dynamics_365_sales-opportunity-close-probability-updated", | ||
| name: "Opportunity Close Probability Updated", | ||
|
Check warning on line 6 in components/microsoft_dynamics_365_sales/sources/opportunity-close-probability-updated/opportunity-close-probability-updated.mjs
|
||
| description: "Emit new event when the close probability of an opportunity is updated.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| _getCloseProbabilities() { | ||
| return this.db.get("closeProbabilities") || {}; | ||
| }, | ||
| _setCloseProbabilities(closeProbabilities) { | ||
| this.db.set("closeProbabilities", closeProbabilities); | ||
| }, | ||
| getResourceFn() { | ||
| return this.microsoftDynamics365Sales.listOpportunities; | ||
| }, | ||
| getArgs() { | ||
| return { | ||
| params: { | ||
| "$orderby": "modifiedon desc", | ||
| }, | ||
| }; | ||
| }, | ||
| getTsField() { | ||
| return "modifiedon"; | ||
| }, | ||
| getRelevantResults(results) { | ||
| const closeProbabilities = this._getCloseProbabilities(); | ||
| const relevantResults = []; | ||
| for (const result of results) { | ||
| if (closeProbabilities[result.opportunityid] !== result.closeprobability) { | ||
| if (closeProbabilities[result.opportunityid]) { | ||
| relevantResults.push(result); | ||
| } | ||
| closeProbabilities[result.opportunityid] = result.closeprobability; | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| this._setCloseProbabilities(closeProbabilities); | ||
| return relevantResults; | ||
| }, | ||
| generateMeta(opportunity) { | ||
| const ts = Date.parse(opportunity.modifiedon); | ||
| return { | ||
| id: `${opportunity.opportunityid}${ts}`, | ||
| summary: `Opportunity Close Probability Updated: ${opportunity.name}`, | ||
| ts, | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import common from "../common/common.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "microsoft_dynamics_365_sales-opportunity-estimated-value-updated", | ||
| name: "Opportunity Estimated Value Updated", | ||
|
Check warning on line 6 in components/microsoft_dynamics_365_sales/sources/opportunity-estimated-value-updated/opportunity-estimated-value-updated.mjs
|
||
| description: "Emit new event when the estimated value of an opportunity is updated.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| _getEstimatedValues() { | ||
| return this.db.get("estimatedValues") || {}; | ||
| }, | ||
| _setEstimatedValues(estimatedValues) { | ||
| this.db.set("estimatedValues", estimatedValues); | ||
| }, | ||
| getResourceFn() { | ||
| return this.microsoftDynamics365Sales.listOpportunities; | ||
| }, | ||
| getArgs() { | ||
| return { | ||
| params: { | ||
| "$orderby": "modifiedon desc", | ||
| }, | ||
| }; | ||
| }, | ||
| getTsField() { | ||
| return "modifiedon"; | ||
| }, | ||
| getRelevantResults(results) { | ||
| const estimatedValues = this._getEstimatedValues(); | ||
| const relevantResults = []; | ||
| for (const result of results) { | ||
| if (estimatedValues[result.opportunityid] !== result.estimatedvalue) { | ||
| if (estimatedValues[result.opportunityid]) { | ||
| relevantResults.push(result); | ||
| } | ||
| estimatedValues[result.opportunityid] = result.estimatedvalue; | ||
| } | ||
| } | ||
| this._setEstimatedValues(estimatedValues); | ||
| return relevantResults; | ||
| }, | ||
| generateMeta(opportunity) { | ||
| const ts = Date.parse(opportunity.modifiedon); | ||
| return { | ||
| id: `${opportunity.opportunityid}${ts}`, | ||
| summary: `Opportunity Estimated Value Updated: ${opportunity.name}`, | ||
| ts, | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.