Skip to content
Merged
2 changes: 1 addition & 1 deletion components/charthop/charthop.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/clear_books/clear_books.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/dixa/dixa.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/linkup/linkup.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
3 changes: 2 additions & 1 deletion components/microsoft_outlook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/microsoft_outlook",
"version": "1.0.3",
"version": "1.0.4",
"description": "Pipedream Microsoft Outlook Components",
"main": "microsoft_outlook.app.mjs",
"keywords": [
Expand All @@ -14,6 +14,7 @@
"dependencies": {
"axios": "^0.21.1",
"js-base64": "^3.7.2",
"md5": "^2.3.0",
"mime-types": "^2.1.35"
},
"publishConfig": {
Expand Down
127 changes: 105 additions & 22 deletions components/microsoft_outlook/sources/new-email/new-email.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
import common from "../common.mjs";
import md5 from "md5";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "microsoft_outlook-new-email",
name: "New Email Event (Instant)",
description: "Emit new event when an email received",
version: "0.0.9",
description: "Emit new event when an email is received in specified folders.",
version: "0.0.10",
type: "source",
dedupe: "unique",
props: {
...common.props,
folderIds: {
type: "string[]",
label: "Folder IDs to Monitor",
description: "Specify the folder IDs or names in Outlook that you want to monitor for new emails. Leave empty to monitor all folders (excluding \"Sent Items\" and \"Drafts\").",
optional: true,
async options() {
const { value: folders } = await this.listFolders();
return folders?.map(({
id: value, displayName: label,
}) => ({
value,
label,
})) || [];
},
},
},
hooks: {
...common.hooks,
async deploy() {
this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items"));
this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts"));

const events = await this.getSampleEvents({
pageSize: 25,
});
if (!events || events.length == 0) {
return;
}
for (const item of events) {
this.emitEvent(item);
}
},
async activate() {
await this.activate({
changeType: "created",
resource: "/me/mailfolders('inbox')/messages",
resource: "/me/messages",
});
},
async deactivate() {
Expand All @@ -22,37 +56,86 @@ export default {
},
methods: {
...common.methods,
async getSampleEvents({ pageSize }) {
return this.microsoftOutlook.listMessages({
params: {
$top: pageSize,
$orderby: "createdDateTime desc",
},
listFolders() {
return this.microsoftOutlook._makeRequest({
path: "/me/mailFolders",
});
},
async getFolderIdByName(name) {
const { value: folders } = await this.listFolders();
const { id } = folders.find(({ displayName }) => displayName === name);
return id;
},
async getSampleEvents({ pageSize }) {
const folders = this.folderIds?.length
? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
: [
"/me/messages",
];

const results = [];
for (const folder of folders) {
const { value: messages } = await this.microsoftOutlook.listMessages({
resource: folder,
params: {
$top: pageSize,
$orderby: "createdDateTime desc",
},
});
results.push(...messages);
}
return results;
},
isRelevant(item) {
if (this.folderIds?.length) {
return this.folderIds.includes(item.parentFolderId);
}
// if no folderIds are specified, filter out items in Sent Items & Drafts
const sentItemFolderId = this.db.get("sentItemFolderId");
const draftsFolderId = this.db.get("draftsFolderId");
return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
},
emitEvent(item) {
this.$emit({
email: item,
}, this.generateMeta(item));
if (this.isRelevant(item)) {
this.$emit(
{
email: item,
},
this.generateMeta(item),
);
}
},
generateMeta(item) {
return {
id: item.id,
id: md5(item.id), // id > 64 characters, so dedupe on hash of id
summary: `New email (ID:${item.id})`,
ts: Date.parse(item.createdDateTime),
};
},
},
async run(event) {
await this.run({
event,
emitFn: async ({ resourceId } = {}) => {
const item = await this.microsoftOutlook.getMessage({
messageId: resourceId,
});
this.emitEvent(item);
},
});
const folders = this.folderIds?.length
? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
: [
"/me/messages",
];

for (const folder of folders) {
await this.run({
event,
emitFn: async ({ resourceId } = {}) => {
try {
const item = await this.microsoftOutlook.getMessage({
resource: folder,
messageId: resourceId,
});
this.emitEvent(item);
} catch {
console.log(`Could not fetch message with ID: ${resourceId}`);
}
},
});
}
},
sampleEmit,
};
2 changes: 1 addition & 1 deletion components/nextdoor/nextdoor.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/opensrs/opensrs.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/xverify/xverify.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Loading
Loading