Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "microsoft_dynamics_365_sales-create-custom-entity",
name: "Create Custom Entity",
description: "Create a custom entity. [See the documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/create-update-entity-definitions-using-web-api)",
version: "0.0.3",
version: "0.0.4",
annotations: {
destructiveHint: true,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_dynamics_365_sales-find-contact",
name: "Find Contact",
description: "Search for a contact by id, name, or using a custom filter. [See the documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query/overview)",
version: "0.0.3",
version: "0.0.4",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export default {
_makeRequest({
$ = this,
path,
url,
headers,
...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
url: url || `${this._baseUrl()}${path}`,
headers: {
...headers,
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
Expand Down Expand Up @@ -85,6 +86,12 @@ export default {
...opts,
});
},
listOpportunities(opts = {}) {
return this._makeRequest({
path: "/opportunities",
...opts,
});
},
getEntity({
entityId, ...opts
}) {
Expand All @@ -100,5 +107,27 @@ export default {
...opts,
});
},
async *paginate({
fn, args = {}, max,
}) {
let count = 0;
let nextLink = null;

do {
const response = await fn(args);
const items = response.value;
if (!items?.length) {
return;
}
for (const item of items) {
yield item;
if (max && ++count >= max) {
return;
}
}
nextLink = response["@odata.nextLink"];
args.url = nextLink;
} while (nextLink);
},
},
};
4 changes: 2 additions & 2 deletions components/microsoft_dynamics_365_sales/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/microsoft_dynamics_365_sales",
"version": "0.1.1",
"version": "0.2.0",
"description": "Pipedream Microsoft Dynamics 365 Sales Components",
"main": "microsoft_dynamics_365_sales.app.mjs",
"keywords": [
Expand All @@ -13,7 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"@pipedream/platform": "^3.1.0",
"pluralize": "^8.0.0"
}
}
79 changes: 79 additions & 0 deletions components/microsoft_dynamics_365_sales/sources/common/common.mjs
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

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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;
}
}
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

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
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,
};
},
},
};
Loading
Loading