@activepieces/piece-microsoft-outlook 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +3 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@activepieces/piece-microsoft-outlook",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "main": "./src/index.js",
5
5
  "dependencies": {
6
6
  "@microsoft/microsoft-graph-types": "2.40.0"
package/src/index.js CHANGED
@@ -18,16 +18,15 @@ This connection supports two access modes. Pick the matching **Grant Type** and
18
18
  - Mail.Send
19
19
 
20
20
  For app-only, Microsoft grants tenant-wide mailbox access by default \u2014 scope it to specific mailboxes with an [ApplicationAccessPolicy](https://learn.microsoft.com/en-us/graph/auth-limit-mailbox-access).
21
- `,J=Bo.OAuth2({description:Hv,grantType:"both_client_credentials_and_authorization_code",props:{cloud:ll,accessMode:pl,tenant:E.ShortText({displayName:"Tenant ID",description:'Use "common" for the default delegated multi-tenant flow. For app-only (Client Credentials), set this to your Directory (tenant) ID.',required:!0,defaultValue:"common"}),mailbox:E.ShortText({displayName:"Mailbox (App-only)",description:"Email/UPN or user object ID of the mailbox to act on. Required for app-only (Client Credentials). Leave blank for delegated access (acts as the signed-in user).",required:!1})},authUrl:"https://{cloud}/{tenant}/oauth2/v2.0/authorize",tokenUrl:"https://{cloud}/{tenant}/oauth2/v2.0/token",required:!0,scope:["{accessMode}"],prompt:"omit",validate:a(async({auth:e})=>{try{let t=e;return await $.createClient(t).api(`${$.mailboxPrefix(t)}/mailFolders/inbox`).get(),{valid:!0}}catch(t){return{valid:!1,error:Zv(t)}}},"validate")});function Zv(e){if(typeof e=="object"&&e!==null){let t=[];if("statusCode"in e&&e.statusCode&&t.push(`HTTP ${String(e.statusCode)}`),"code"in e&&e.code&&t.push(String(e.code)),"message"in e&&e.message&&t.push(String(e.message)),"body"in e&&e.body){let r=e.body;t.push(typeof r=="string"?r.slice(0,800):JSON.stringify(r).slice(0,800))}if(t.length>0)return t.join(" | ")}return e instanceof Error&&e.message?e.message:"Unknown error while validating the connection."}a(Zv,"describeGraphError");var ot=a(e=>E.Dropdown({auth:J,displayName:e.displayName,description:e.description,required:e.required,refreshers:[],options:a(async({auth:t})=>{if(!t)return{placeholder:"Please connect your account first.",disabled:!0,options:[]};let r=t,n=$.createClient(r);try{return{disabled:!1,options:(await n.api(`${$.mailboxPrefix(r)}/messages?$top=50&$select=id,subject,from,receivedDateTime`).orderby("receivedDateTime desc").get()).value.map(s=>({label:`${s.subject||"No Subject"}`,value:s.id}))}}catch{return{disabled:!0,options:[]}}},"options")}),"messageIdDropdown"),Op=a(e=>E.Dropdown({auth:J,displayName:e.displayName,description:e.description,required:e.required,refreshers:[],options:a(async({auth:t})=>{if(!t)return{placeholder:"Please connect your account first.",disabled:!0,options:[]};let r=t,n=$.createClient(r);try{return{disabled:!1,options:(await n.api(`${$.mailboxPrefix(r)}/mailFolders/drafts/messages?$top=50&$select=id,subject,from,receivedDateTime`).orderby("receivedDateTime desc").get()).value.map(s=>({label:`${s.subject||"No Subject"}`,value:s.id}))}}catch{return{disabled:!0,options:[]}}},"options")}),"draftMessageIdDropdown"),it=a(e=>E.Dropdown({auth:J,displayName:e.displayName,description:e.description,required:e.required,refreshers:[],options:a(async({auth:t})=>{if(!t)return{placeholder:"Please connect your account first.",disabled:!0,options:[]};let r=t,n=$.createClient(r);try{return{disabled:!1,options:(await n.api(`${$.mailboxPrefix(r)}/mailFolders`).get()).value.map(s=>({label:s.displayName||s.id||"Unknown",value:s.id||""}))}}catch{return{disabled:!0,options:[]}}},"options")}),"mailFolderIdDropdown");var zp=ne({auth:J,name:"addLabelToEmail",displayName:"Add Label to Email",description:"Adds a category (label) to an email message.",audience:"both",aiMetadata:{description:"Adds one or more Outlook categories (labels) to a specific message, merging them with any categories already present. Use this to tag or classify an email. Idempotent: re-adding the same categories leaves the message unchanged since duplicates are de-duplicated.",idempotent:!0},props:{messageId:ot({displayName:"Email",description:"Select the email message to add the label to.",required:!0}),categories:E.Array({displayName:"Categories",description:"Categories to add to the email.",required:!0})},async run(e){let{messageId:t,categories:r}=e.propsValue,n=$.createClient(e.auth),i=(await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).get()).categories||[],s=[...new Set([...i,...r])];return await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).patch({categories:s})}});var Rp=ne({auth:J,name:"createDraftEmail",displayName:"Create Draft Email",description:"Creates a draft email message.",audience:"both",aiMetadata:{description:"Creates a new unsent draft email in the Outlook mailbox with recipients, subject, body, and optional attachments. Use this to stage a message for later review or sending (pair with Send Draft Email). Not idempotent: each call creates a separate draft.",idempotent:!1},props:{recipients:E.Array({displayName:"To Email(s)",required:!0}),ccRecipients:E.Array({displayName:"CC Email(s)",required:!1,defaultValue:[]}),bccRecipients:E.Array({displayName:"BCC Email(s)",required:!1,defaultValue:[]}),subject:E.ShortText({displayName:"Subject",required:!0}),bodyFormat:E.StaticDropdown({displayName:"Body Format",required:!0,defaultValue:"text",options:{disabled:!1,options:[{label:"HTML",value:"html"},{label:"Text",value:"text"}]}}),body:E.LongText({displayName:"Body",required:!0}),attachments:E.Array({displayName:"Attachments",required:!1,defaultValue:[],properties:{file:E.File({displayName:"File",required:!0}),fileName:E.ShortText({displayName:"File Name",required:!1})}})},async run(e){let t=e.propsValue.recipients,r=e.propsValue.ccRecipients,n=e.propsValue.bccRecipients,o=e.propsValue.attachments,{subject:i,body:s,bodyFormat:u}=e.propsValue,p={subject:i,body:{content:s,contentType:u},toRecipients:t.map(v=>({emailAddress:{address:v}})),ccRecipients:r.map(v=>({emailAddress:{address:v}})),bccRecipients:n.map(v=>({emailAddress:{address:v}})),attachments:o.map(v=>({"@odata.type":"#microsoft.graph.fileAttachment",name:v.fileName||v.file.filename,contentBytes:v.file.base64}))};return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages`).post(p)}});var kp=ne({auth:J,name:"downloadAttachment",displayName:"Download Attachment",description:"Download attachments from a specific email message.",audience:"both",aiMetadata:{description:"Fetches all file attachments from a specific Outlook message (by message ID) and writes them to storage for downstream steps. Use this after locating a message to retrieve its attached files. Requires a valid message ID; idempotent since it only reads.",idempotent:!0},props:{messageId:E.ShortText({displayName:"Message ID",description:"The ID of the email message containing the attachment.",required:!0})},async run(e){let{messageId:t}=e.propsValue,n=await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages/${t}/attachments`).get(),o=[];for(let i of n.value)i.name&&i.contentBytes&&o.push({...i,file:await e.files.write({fileName:i.name||"test.png",data:Buffer.from(i.contentBytes,"base64")})});return o}});var ji=ze(br());var Dp=ne({auth:J,name:"findEmail",displayName:"Find Email",description:"Searches for emails using full-text search.",audience:"both",aiMetadata:{description:"Searches the Outlook mailbox for messages matching a full-text query (supports field syntax like from:, subject:, hasAttachments:), optionally scoped to one folder and capped by a max-results count. Use this to locate emails and obtain their message IDs for follow-up actions. Idempotent read-only lookup.",idempotent:!0},props:{searchQuery:E.ShortText({displayName:"Search Query",description:'Search terms to find emails (e.g., "from:john@example.com", "subject:urgent", "hasAttachments:true")',required:!0}),folderId:it({displayName:"Folder",description:"Search in a specific folder. Leave empty to search all folders.",required:!1}),top:E.Number({displayName:"Max Results",description:"Maximum number of results to return (1-1000).",required:!1,defaultValue:25})},async run(e){let{searchQuery:t,folderId:r,top:n}=e.propsValue,o=$.createClient(e.auth),i=r?`${$.mailboxPrefix(e.auth)}/mailFolders/${r}/messages`:`${$.mailboxPrefix(e.auth)}/messages`,s=`$search="${t}"`,u=n?`$top=${Math.min(Math.max(n,1),1e3)}`:"$top=25",p=["id","subject","from","toRecipients","receivedDateTime"].join(","),d=[s,u,p].filter(Boolean).join("&"),f=`${i}?${d}`,v={ConsistencyLevel:"eventual",Prefer:'outlook.body-content-type="text"'},y=await o.api(f).headers(v).get(),l=y.value,m=y["@odata.nextLink"];return t&&l.sort((_,h)=>(0,ji.default)(h.receivedDateTime).valueOf()-(0,ji.default)(_.receivedDateTime).valueOf()),{found:l.length>0,result:l,hasMore:!!m,nextPageUrl:m,totalCount:l.length}}});var Cp=ne({auth:J,name:"forwardEmail",displayName:"Forward Email",description:"Forwards an email message.",audience:"both",aiMetadata:{description:"Forwards an existing Outlook message (by message ID) to new recipients, preserving the original body and attachments and prepending an optional comment. Use this to pass an existing email along rather than composing a new one. Not idempotent: each call sends a new forwarded email.",idempotent:!1},props:{messageId:ot({displayName:"Email",description:"Select the email message to forward.",required:!0}),recipients:E.Array({displayName:"To Email(s)",required:!0}),comment:E.LongText({displayName:"Comment",description:"Optional comment to include with the forwarded message.",required:!1})},async run(e){let{messageId:t,comment:r}=e.propsValue,n=e.propsValue.recipients,o=$.createClient(e.auth),i=await o.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).get(),s={toRecipients:n.map(p=>({emailAddress:{address:p}})),body:{contentType:"html",content:(r??"")+"<br><br>"+i.body.content},attachments:i.attachments},u=await o.api(`${$.mailboxPrefix(e.auth)}/messages/${t}/forward`).post({message:s});return{success:!0,message:"Email forwarded successfully.",messageId:u.id,...u}}});var Np=ne({auth:J,name:"moveEmailToFolder",displayName:"Move Email to Folder",description:"Moves an email message to a specific folder.",audience:"both",aiMetadata:{description:"Moves a specific Outlook message into a chosen mail folder. Use this to organize, archive, or route an email after processing it. Note: the move assigns a new message ID, so re-running with the original ID will fail once moved.",idempotent:!1},props:{messageId:ot({displayName:"Email",description:"Select the email message to move.",required:!0}),destinationFolderId:it({displayName:"Destination Folder",description:"The folder to move the email to.",required:!0})},async run(e){let{messageId:t,destinationFolderId:r}=e.propsValue;return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages/${t}/move`).post({destinationId:r})}});var Mp=ne({auth:J,name:"removeLabelFromEmail",displayName:"Remove Label from Email",description:"Removes a category (label) from an email message.",audience:"both",aiMetadata:{description:"Removes one or more Outlook categories (labels) from a specific message, leaving any other categories intact. Use this to untag or reclassify an email. Idempotent: re-running with the same categories yields the same final label set.",idempotent:!0},props:{messageId:ot({displayName:"Email",description:"Select the email message to remove the label from.",required:!0}),categories:E.Array({displayName:"Categories to Remove",description:"Categories to remove from the email.",required:!0})},async run(e){let{messageId:t,categories:r}=e.propsValue,n=$.createClient(e.auth),s=((await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).get()).categories||[]).filter(p=>!r.includes(p));return await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).patch({categories:s})}});var Up=ne({auth:J,name:"reply-email",displayName:"Reply to Email",description:"Reply to an outlook email.",audience:"both",aiMetadata:{description:"Replies to an existing Outlook message (identified by message ID), supporting added CC/BCC recipients and attachments. Set the Create Draft flag to stage the reply without sending; otherwise it is sent immediately. Not idempotent when sending: each call creates and dispatches a new reply.",idempotent:!1},props:{messageId:E.Dropdown({auth:J,displayName:"Email",description:"Select the email message to reply to.",required:!0,refreshers:[],options:a(async({auth:e})=>{if(!e)return{disabled:!0,options:[]};let t=$.createClient(e);try{return{disabled:!1,options:(await t.api(`${$.mailboxPrefix(e)}/messages?$top=50&$select=id,subject,from,receivedDateTime`).orderby("receivedDateTime desc").get()).value.map(o=>({label:`${o.subject||"No Subject"} - ${o.from?.emailAddress?.name||o.from?.emailAddress?.address||"Unknown Sender"}`,value:o.id||""}))}}catch{return{disabled:!0,options:[]}}},"options")}),bodyFormat:E.StaticDropdown({displayName:"Body Format",required:!0,defaultValue:"text",options:{disabled:!1,options:[{label:"HTML",value:"html"},{label:"Text",value:"text"}]}}),replyBody:E.LongText({displayName:"Reply Body",required:!0}),ccRecipients:E.Array({displayName:"CC Recipients",required:!1}),bccRecipients:E.Array({displayName:"BCC Recipients",required:!1}),attachments:E.Array({displayName:"Attachments",required:!1,defaultValue:[],properties:{file:E.File({displayName:"File",required:!0}),fileName:E.ShortText({displayName:"File Name",required:!1})}}),draft:E.Checkbox({displayName:"Create Draft",description:"If enabled, creates draft without sending.",required:!0,defaultValue:!1})},async run(e){let{replyBody:t,bodyFormat:r,messageId:n,draft:o}=e.propsValue,i=e.propsValue.ccRecipients,s=e.propsValue.bccRecipients,u=e.propsValue.attachments,p={body:{content:t,contentType:r},ccRecipients:i.map(f=>({emailAddress:{address:f}})),bccRecipients:s.map(f=>({emailAddress:{address:f}})),attachments:u.map(f=>({"@odata.type":"#microsoft.graph.fileAttachment",name:f.fileName||f.file.filename,contentBytes:f.file.base64}))},d=$.createClient(e.auth);try{let v=(await d.api(`${$.mailboxPrefix(e.auth)}/messages/${n}/createReply`).post({message:p})).id;return o?{success:!0,message:"Draft created successfully.",draftId:v,draftLink:`https://outlook.office.com/mail/drafts/id/${v}`}:(await d.api(`${$.mailboxPrefix(e.auth)}/messages/${v}/send`).post({}),{success:!0,message:"Reply sent successfully.",draftId:v})}catch(f){console.error("Reply Email Error:",f);let v=f instanceof Error?f.message:"Unknown error";throw new Error(v)}}});var Lp=ne({auth:J,name:"sendDraftEmail",displayName:"Send Draft Email",description:"Sends a draft email message.",audience:"both",aiMetadata:{description:"Sends an existing draft email (identified by draft message ID) from the Outlook mailbox. Use this to dispatch a draft previously staged by Create Draft Email or a draft reply. Not idempotent: once sent the draft no longer exists, so re-running with the same ID will fail.",idempotent:!1},props:{messageId:Op({displayName:"Draft Email",description:"Select the draft email message to send.",required:!0})},async run(e){let{messageId:t}=e.propsValue;return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages/${t}/send`).post({}),{success:!0,message:"Draft sent successfully.",messageId:t}}});var jp=ne({auth:J,name:"send-email",displayName:"Send Email",description:"Sends an email using Microsoft Outlook.",audience:"both",aiMetadata:{description:"Composes and sends a new email from the authenticated Outlook mailbox to the given recipients, with optional CC/BCC and file attachments. Use this to send a fresh message (not a reply or forward). Not idempotent: each call dispatches a new email and saves a copy to Sent Items.",idempotent:!1},props:{recipients:E.Array({displayName:"To Email(s)",required:!0}),ccRecipients:E.Array({displayName:"CC Email(s)",required:!1,defaultValue:[]}),bccRecipients:E.Array({displayName:"BCC Email(s)",required:!1,defaultValue:[]}),subject:E.ShortText({displayName:"Subject",required:!0}),bodyFormat:E.StaticDropdown({displayName:"Body Format",required:!0,defaultValue:"text",options:{disabled:!1,options:[{label:"HTML",value:"html"},{label:"Text",value:"text"}]}}),body:E.LongText({displayName:"Body",required:!0}),attachments:E.Array({displayName:"Attachments",required:!1,defaultValue:[],properties:{file:E.File({displayName:"File",required:!0}),fileName:E.ShortText({displayName:"File Name",required:!1})}})},async run(e){let t=e.propsValue.recipients,r=e.propsValue.ccRecipients,n=e.propsValue.bccRecipients,o=e.propsValue.attachments,{subject:i,body:s,bodyFormat:u}=e.propsValue,p={subject:i,body:{content:s,contentType:u},toRecipients:t.map(v=>({emailAddress:{address:v}})),ccRecipients:r.map(v=>({emailAddress:{address:v}})),bccRecipients:n.map(v=>({emailAddress:{address:v}})),attachments:o.map(v=>({"@odata.type":"#microsoft.graph.fileAttachment",name:v.fileName||v.file.filename,contentBytes:v.file.base64}))};return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/sendMail`).post({message:p,saveToSentItems:"true"})}});var ro=ze(br());async function Fp(e,t,r,n,o,i){let s=[];for(let u of r){if(i&&u.sender?.emailAddress?.address&&!u.sender.emailAddress.address.toLowerCase().includes(i.toLowerCase()))continue;let p=await e.api(`${t}/messages/${u.id}/attachments`).get();for(let d of p.value){let{contentBytes:f,...v}=d;if(!(o&&d.name&&!d.name.toLowerCase().includes(o.toLowerCase()))&&d.name&&f){let y=await n.write({fileName:d.name,data:Buffer.from(f,"base64")});s.push({file:y,messageId:u.id,messageSubject:u.subject,messageSender:u.sender,messageReceivedDateTime:u.receivedDateTime,parentFolderId:u.parentFolderId,...v})}}}return s}a(Fp,"enrichAttachments");var Bp=St({auth:J,name:"newAttachment",displayName:"New Attachment",description:"Triggers when a new email containing one or more attachments arrives.",aiMetadata:{description:"Fires once per attachment when a new email carrying one or more file attachments arrives, optionally scoped to a folder, sender, or attachment-name filter. Each fire represents a single attachment from a newly received message."},props:{folderId:it({displayName:"Folder",description:"Monitor attachments in a specific folder. Leave empty to monitor all folders.",required:!1}),sender:E.ShortText({displayName:"From (Sender Email)",description:"Filter emails from a specific sender (optional). Leave empty to for all senders.",required:!1}),attachmentNameFilter:E.ShortText({displayName:"Attachment Name Filter",description:"Filter attachments by name (contains). Leave empty to include all attachments.",required:!1})},sampleData:{},type:"POLLING",async onEnable(e){await e.store.put("lastPoll",Date.now())},async onDisable(e){},async test(e){let{folderId:t,attachmentNameFilter:r,sender:n}=e.propsValue,o=$.createClient(e.auth),i=t?`${$.mailboxPrefix(e.auth)}/mailFolders/${t}/messages`:`${$.mailboxPrefix(e.auth)}/messages`,s=await o.api(`${i}?$filter=hasAttachments eq true`).top(10).get();return(await Fp(o,$.mailboxPrefix(e.auth),s.value,e.files,r,n)).map(d=>({epochMilliSeconds:(0,ro.default)(d.messageReceivedDateTime).valueOf(),data:d})).map(d=>d.data)},async run(e){let t=await e.store.get("lastPoll");if(he(t))throw new Error("lastPoll doesn't exist in the store.");let{folderId:r,attachmentNameFilter:n,sender:o}=e.propsValue,i=$.createClient(e.auth),s=r?`${$.mailboxPrefix(e.auth)}/mailFolders/${r}/messages`:`${$.mailboxPrefix(e.auth)}/messages`,u=await i.api(`${s}?$filter=receivedDateTime gt ${(0,ro.default)(t).toISOString()} and hasAttachments eq true`).orderby("receivedDateTime desc").get(),p=[];for(;u.value.length>0&&(p.push(...u.value),u["@odata.nextLink"]);)u=await i.api(u["@odata.nextLink"]).get();let f=(await Fp(i,$.mailboxPrefix(e.auth),p,e.files,n,o)).map(y=>({epochMilliSeconds:(0,ro.default)(y.messageReceivedDateTime).valueOf(),data:y})),v=f.reduce((y,l)=>Math.max(y,l.epochMilliSeconds),t);return await e.store.put("lastPoll",v),f.filter(y=>y.epochMilliSeconds>t).map(y=>y.data)}});var Fi=ze(br());var no={strategy:0,items:a(async({auth:e,lastFetchEpochMS:t,propsValue:r})=>{let n=$.createClient(e),o=[],i=r.folderId,s=t===0?"$top=10":`$filter=createdDateTime gt ${(0,Fi.default)(t).toISOString()}`,u=await n.api(`${$.mailboxPrefix(e)}/mailFolders/${i}/messages?${s}`).orderby("createdDateTime desc").get();if(t===0)for(let p of u.value)o.push(p);else for(;u.value.length>0;){for(let p of u.value)o.push(p);if(u["@odata.nextLink"])u=await n.api(u["@odata.nextLink"]).get();else break}return o.map(p=>({epochMilliSeconds:(0,Fi.default)(p.createdDateTime).valueOf(),data:p}))},"items")},Vp=St({auth:J,name:"newEmailInFolder",displayName:"New Email in Folder",description:"Triggers when a new email is delivered into the specified folder.",aiMetadata:{description:"Fires when a new message appears in the chosen Outlook mail folder. Each fire represents one new email added to that folder."},props:{folderId:it({displayName:"Folder",description:"",required:!0})},sampleData:{},type:"POLLING",async onEnable(e){await Ue.onEnable(no,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async onDisable(e){await Ue.onDisable(no,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async test(e){return await Ue.test(no,e)},async run(e){return await Ue.poll(no,e)}});var Bi=ze(br());var oo={strategy:0,items:a(async({auth:e,lastFetchEpochMS:t,propsValue:r})=>{let n=$.createClient(e),o=[],i=t===0?"$top=10":`$filter=receivedDateTime gt ${(0,Bi.default)(t).toISOString()}`,s=await n.api(`${$.mailboxPrefix(e)}/mailFolders/inbox/messages?${i}`).orderby("receivedDateTime desc").get();if(t===0)for(let p of s.value)o.push(p);else for(;s.value.length>0;){for(let p of s.value)o.push(p);if(s["@odata.nextLink"])s=await n.api(s["@odata.nextLink"]).get();else break}let u=o;return r?.sender&&(u=u.filter(p=>{let d=p.from?.emailAddress?.address?.toLowerCase(),f=r.sender?.toLowerCase();return d===f})),r?.recipient&&(u=u.filter(p=>p.toRecipients?.some(f=>{let v=f.emailAddress?.address?.toLowerCase(),y=r.recipient?.toLowerCase();return v===y}))),u.map(p=>({epochMilliSeconds:(0,Bi.default)(p.receivedDateTime).valueOf(),data:p}))},"items")},Hp=St({auth:J,name:"newEmail",displayName:"New Email",description:"Triggers when a new email is received in the inbox.",aiMetadata:{description:"Fires when a new message arrives in the mailbox Inbox, optionally narrowed to a specific sender and/or recipient address. Each fire represents one newly received email."},props:{sender:E.ShortText({displayName:"From (Sender Email)",description:"Filter emails from a specific sender (optional). Leave empty to for all senders.",required:!1}),recipient:E.ShortText({displayName:"To (Recipient Email)",description:"Filter emails to a specific recipient (optional). Leave empty to for all recipients.",required:!1})},sampleData:{},type:"POLLING",async onEnable(e){await Ue.onEnable(oo,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async onDisable(e){await Ue.onDisable(oo,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async test(e){return await Ue.test(oo,e)},async run(e){return await Ue.poll(oo,e)}});var Zp=ne({auth:J,name:"request_approval_in_mail",displayName:"Request Approval in Email",description:"Send approval request email and then wait until the email is approved or disapproved",audience:"both",aiMetadata:{description:"Sends an email containing Approve/Disapprove links to one recipient, then pauses the flow until they click one of the links, resuming with the decision. Use this as a human-in-the-loop approval gate before proceeding. Not idempotent: each call sends a new email and creates a new pending waitpoint.",idempotent:!1},props:{recipients:E.ShortText({displayName:"To Email Address",description:"The email address of the recipient who will receive the approval request.",required:!0}),subject:E.ShortText({displayName:"Subject",description:"The subject of the approval request email.",required:!0}),body:E.LongText({displayName:"Body",description:"The main content of the email. You can include details about the approval request here in the html format or plain text.",required:!0})},async run(e){if(e.executionType==="BEGIN")try{let t=e.auth.access_token,r=e.propsValue.recipients,{subject:n,body:o}=e.propsValue;He(t,"token"),He(r,"recipients"),He(n,"subject"),He(o,"body");let i=await e.run.createWaitpoint({type:"WEBHOOK"}),s=i.buildResumeUrl({queryParams:{action:"approve"}}),u=i.buildResumeUrl({queryParams:{action:"disapprove"}}),p=`
21
+ `,J=Bo.OAuth2({description:Hv,grantType:"both_client_credentials_and_authorization_code",props:{cloud:ll,accessMode:pl,tenant:E.ShortText({displayName:"Tenant ID",description:'Use "common" for the default delegated multi-tenant flow. For app-only (Client Credentials), set this to your Directory (tenant) ID.',required:!0,defaultValue:"common"}),mailbox:E.ShortText({displayName:"Mailbox (App-only)",description:"Email/UPN or user object ID of the mailbox to act on. Required for app-only (Client Credentials). Leave blank for delegated access (acts as the signed-in user).",required:!1})},authUrl:"https://{cloud}/{tenant}/oauth2/v2.0/authorize",tokenUrl:"https://{cloud}/{tenant}/oauth2/v2.0/token",required:!0,scope:["{accessMode}"],prompt:"omit",validate:a(async({auth:e})=>{try{let t=e;return await $.createClient(t).api(`${$.mailboxPrefix(t)}/mailFolders/inbox`).get(),{valid:!0}}catch(t){return{valid:!1,error:Zv(t)}}},"validate")});function Zv(e){if(typeof e=="object"&&e!==null){let t=[];if("statusCode"in e&&e.statusCode&&t.push(`HTTP ${String(e.statusCode)}`),"code"in e&&e.code&&t.push(String(e.code)),"message"in e&&e.message&&t.push(String(e.message)),"body"in e&&e.body){let r=e.body;t.push(typeof r=="string"?r.slice(0,800):JSON.stringify(r).slice(0,800))}if(t.length>0)return t.join(" | ")}return e instanceof Error&&e.message?e.message:"Unknown error while validating the connection."}a(Zv,"describeGraphError");var ot=a(e=>E.Dropdown({auth:J,displayName:e.displayName,description:e.description,required:e.required,refreshers:[],options:a(async({auth:t})=>{if(!t)return{placeholder:"Please connect your account first.",disabled:!0,options:[]};let r=t,n=$.createClient(r);try{return{disabled:!1,options:(await n.api(`${$.mailboxPrefix(r)}/messages?$top=50&$select=id,subject,from,receivedDateTime`).orderby("receivedDateTime desc").get()).value.map(s=>({label:`${s.subject||"No Subject"}`,value:s.id}))}}catch{return{disabled:!0,options:[]}}},"options")}),"messageIdDropdown"),Op=a(e=>E.Dropdown({auth:J,displayName:e.displayName,description:e.description,required:e.required,refreshers:[],options:a(async({auth:t})=>{if(!t)return{placeholder:"Please connect your account first.",disabled:!0,options:[]};let r=t,n=$.createClient(r);try{return{disabled:!1,options:(await n.api(`${$.mailboxPrefix(r)}/mailFolders/drafts/messages?$top=50&$select=id,subject,from,receivedDateTime`).orderby("receivedDateTime desc").get()).value.map(s=>({label:`${s.subject||"No Subject"}`,value:s.id}))}}catch{return{disabled:!0,options:[]}}},"options")}),"draftMessageIdDropdown"),it=a(e=>E.Dropdown({auth:J,displayName:e.displayName,description:e.description,required:e.required,refreshers:[],options:a(async({auth:t})=>{if(!t)return{placeholder:"Please connect your account first.",disabled:!0,options:[]};let r=t,n=$.createClient(r);try{return{disabled:!1,options:(await n.api(`${$.mailboxPrefix(r)}/mailFolders`).get()).value.map(s=>({label:s.displayName||s.id||"Unknown",value:s.id||""}))}}catch{return{disabled:!0,options:[]}}},"options")}),"mailFolderIdDropdown");var zp=ne({auth:J,name:"addLabelToEmail",displayName:"Add Label to Email",description:"Adds a category (label) to an email message.",audience:"both",aiMetadata:{description:"Adds one or more Outlook categories (labels) to a specific message, merging them with any categories already present. Use this to tag or classify an email. Idempotent: re-adding the same categories leaves the message unchanged since duplicates are de-duplicated.",idempotent:!0},props:{messageId:ot({displayName:"Email",description:"Select the email message to add the label to.",required:!0}),categories:E.Array({displayName:"Categories",description:"Categories to add to the email.",required:!0})},async run(e){let{messageId:t,categories:r}=e.propsValue,n=$.createClient(e.auth),i=(await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).get()).categories||[],s=[...new Set([...i,...r])];return await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).patch({categories:s})}});var Rp=ne({auth:J,name:"createDraftEmail",displayName:"Create Draft Email",description:"Creates a draft email message.",audience:"both",aiMetadata:{description:"Creates a new unsent draft email in the Outlook mailbox with recipients, subject, body, and optional attachments. Use this to stage a message for later review or sending (pair with Send Draft Email). Not idempotent: each call creates a separate draft.",idempotent:!1},props:{recipients:E.Array({displayName:"To Email(s)",required:!0}),ccRecipients:E.Array({displayName:"CC Email(s)",required:!1,defaultValue:[]}),bccRecipients:E.Array({displayName:"BCC Email(s)",required:!1,defaultValue:[]}),subject:E.ShortText({displayName:"Subject",required:!0}),bodyFormat:E.StaticDropdown({displayName:"Body Format",required:!0,defaultValue:"text",options:{disabled:!1,options:[{label:"HTML",value:"html"},{label:"Text",value:"text"}]}}),body:E.LongText({displayName:"Body",required:!0}),attachments:E.Array({displayName:"Attachments",required:!1,defaultValue:[],properties:{file:E.File({displayName:"File",required:!0}),fileName:E.ShortText({displayName:"File Name",required:!1})}})},async run(e){let t=e.propsValue.recipients,r=e.propsValue.ccRecipients,n=e.propsValue.bccRecipients,o=e.propsValue.attachments,{subject:i,body:s,bodyFormat:u}=e.propsValue,p={subject:i,body:{content:s,contentType:u},toRecipients:t.map(v=>({emailAddress:{address:v}})),ccRecipients:r.map(v=>({emailAddress:{address:v}})),bccRecipients:n.map(v=>({emailAddress:{address:v}})),attachments:o.map(v=>({"@odata.type":"#microsoft.graph.fileAttachment",name:v.fileName||v.file.filename,contentBytes:v.file.base64}))};return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages`).post(p)}});var kp=ne({auth:J,name:"downloadAttachment",displayName:"Download Attachment",description:"Download attachments from a specific email message.",audience:"both",aiMetadata:{description:"Fetches all file attachments from a specific Outlook message (by message ID) and writes them to storage for downstream steps. Use this after locating a message to retrieve its attached files. Requires a valid message ID; idempotent since it only reads.",idempotent:!0},props:{messageId:E.ShortText({displayName:"Message ID",description:"The ID of the email message containing the attachment.",required:!0})},async run(e){let{messageId:t}=e.propsValue,n=await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages/${t}/attachments`).get(),o=[];for(let i of n.value)i.name&&i.contentBytes&&o.push({...i,file:await e.files.write({fileName:i.name||"test.png",data:Buffer.from(i.contentBytes,"base64")})});return o}});var ji=ze(br());var Dp=ne({auth:J,name:"findEmail",displayName:"Find Email",description:"Searches for emails using full-text search.",audience:"both",aiMetadata:{description:"Searches the Outlook mailbox for messages matching a full-text query (supports field syntax like from:, subject:, hasAttachments:), optionally scoped to one folder and capped by a max-results count. Use this to locate emails and obtain their message IDs for follow-up actions. Idempotent read-only lookup.",idempotent:!0},props:{searchQuery:E.ShortText({displayName:"Search Query",description:'Search terms to find emails (e.g., "from:john@example.com", "subject:urgent", "hasAttachments:true")',required:!0}),folderId:it({displayName:"Folder",description:"Search in a specific folder. Leave empty to search all folders.",required:!1}),top:E.Number({displayName:"Max Results",description:"Maximum number of results to return (1-1000).",required:!1,defaultValue:25})},async run(e){let{searchQuery:t,folderId:r,top:n}=e.propsValue,o=$.createClient(e.auth),i=r?`${$.mailboxPrefix(e.auth)}/mailFolders/${r}/messages`:`${$.mailboxPrefix(e.auth)}/messages`,s=`$search="${t}"`,u=n?`$top=${Math.min(Math.max(n,1),1e3)}`:"$top=25",p=["id","subject","from","toRecipients","receivedDateTime"].join(","),d=[s,u,p].filter(Boolean).join("&"),f=`${i}?${d}`,v={ConsistencyLevel:"eventual",Prefer:'outlook.body-content-type="text"'},y=await o.api(f).headers(v).get(),l=y.value,m=y["@odata.nextLink"];return t&&l.sort((_,h)=>(0,ji.default)(h.receivedDateTime).valueOf()-(0,ji.default)(_.receivedDateTime).valueOf()),{found:l.length>0,result:l,hasMore:!!m,nextPageUrl:m,totalCount:l.length}}});var Cp=ne({auth:J,name:"forwardEmail",displayName:"Forward Email",description:"Forwards an email message.",audience:"both",aiMetadata:{description:"Forwards an existing Outlook message (by message ID) to new recipients, preserving the original body and attachments and prepending an optional comment. Use this to pass an existing email along rather than composing a new one. Not idempotent: each call sends a new forwarded email.",idempotent:!1},props:{messageId:ot({displayName:"Email",description:"Select the email message to forward.",required:!0}),recipients:E.Array({displayName:"To Email(s)",required:!0}),comment:E.LongText({displayName:"Comment",description:"Optional comment to include with the forwarded message.",required:!1})},async run(e){let{messageId:t,comment:r}=e.propsValue,n=e.propsValue.recipients,o=$.createClient(e.auth),i=await o.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).get(),s={toRecipients:n.map(p=>({emailAddress:{address:p}})),body:{contentType:"html",content:(r??"")+"<br><br>"+i.body.content},attachments:i.attachments},u=await o.api(`${$.mailboxPrefix(e.auth)}/messages/${t}/forward`).post({message:s});return{success:!0,message:"Email forwarded successfully.",messageId:u.id,...u}}});var Np=ne({auth:J,name:"moveEmailToFolder",displayName:"Move Email to Folder",description:"Moves an email message to a specific folder.",audience:"both",aiMetadata:{description:"Moves a specific Outlook message into a chosen mail folder. Use this to organize, archive, or route an email after processing it. Note: the move assigns a new message ID, so re-running with the original ID will fail once moved.",idempotent:!1},props:{messageId:ot({displayName:"Email",description:"Select the email message to move.",required:!0}),destinationFolderId:it({displayName:"Destination Folder",description:"The folder to move the email to.",required:!0})},async run(e){let{messageId:t,destinationFolderId:r}=e.propsValue;return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages/${t}/move`).post({destinationId:r})}});var Mp=ne({auth:J,name:"removeLabelFromEmail",displayName:"Remove Label from Email",description:"Removes a category (label) from an email message.",audience:"both",aiMetadata:{description:"Removes one or more Outlook categories (labels) from a specific message, leaving any other categories intact. Use this to untag or reclassify an email. Idempotent: re-running with the same categories yields the same final label set.",idempotent:!0},props:{messageId:ot({displayName:"Email",description:"Select the email message to remove the label from.",required:!0}),categories:E.Array({displayName:"Categories to Remove",description:"Categories to remove from the email.",required:!0})},async run(e){let{messageId:t,categories:r}=e.propsValue,n=$.createClient(e.auth),s=((await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).get()).categories||[]).filter(p=>!r.includes(p));return await n.api(`${$.mailboxPrefix(e.auth)}/messages/${t}`).patch({categories:s})}});var Up=ne({auth:J,name:"reply-email",displayName:"Reply to Email",description:"Reply to an outlook email.",audience:"both",aiMetadata:{description:"Replies to an existing Outlook message (identified by message ID), supporting added CC/BCC recipients and attachments. Set the Create Draft flag to stage the reply without sending; otherwise it is sent immediately. Not idempotent when sending: each call creates and dispatches a new reply.",idempotent:!1},props:{messageId:E.Dropdown({auth:J,displayName:"Email",description:"Select the email message to reply to.",required:!0,refreshers:[],options:a(async({auth:e})=>{if(!e)return{disabled:!0,options:[]};let t=$.createClient(e);try{return{disabled:!1,options:(await t.api(`${$.mailboxPrefix(e)}/messages?$top=50&$select=id,subject,from,receivedDateTime`).orderby("receivedDateTime desc").get()).value.map(o=>({label:`${o.subject||"No Subject"} - ${o.from?.emailAddress?.name||o.from?.emailAddress?.address||"Unknown Sender"}`,value:o.id||""}))}}catch{return{disabled:!0,options:[]}}},"options")}),bodyFormat:E.StaticDropdown({displayName:"Body Format",required:!0,defaultValue:"text",options:{disabled:!1,options:[{label:"HTML",value:"html"},{label:"Text",value:"text"}]}}),replyBody:E.LongText({displayName:"Reply Body",required:!0}),ccRecipients:E.Array({displayName:"CC Recipients",required:!1}),bccRecipients:E.Array({displayName:"BCC Recipients",required:!1}),attachments:E.Array({displayName:"Attachments",required:!1,defaultValue:[],properties:{file:E.File({displayName:"File",required:!0}),fileName:E.ShortText({displayName:"File Name",required:!1})}}),draft:E.Checkbox({displayName:"Create Draft",description:"If enabled, creates draft without sending.",required:!0,defaultValue:!1})},async run(e){let{replyBody:t,bodyFormat:r,messageId:n,draft:o}=e.propsValue,i=e.propsValue.ccRecipients,s=e.propsValue.bccRecipients,u=e.propsValue.attachments,p={body:{content:t,contentType:r},ccRecipients:i.map(f=>({emailAddress:{address:f}})),bccRecipients:s.map(f=>({emailAddress:{address:f}})),attachments:u.map(f=>({"@odata.type":"#microsoft.graph.fileAttachment",name:f.fileName||f.file.filename,contentBytes:f.file.base64}))},d=$.createClient(e.auth);try{let v=(await d.api(`${$.mailboxPrefix(e.auth)}/messages/${n}/createReply`).post({message:p})).id;return o?{success:!0,message:"Draft created successfully.",draftId:v,draftLink:`https://outlook.office.com/mail/drafts/id/${v}`}:(await d.api(`${$.mailboxPrefix(e.auth)}/messages/${v}/send`).post({}),{success:!0,message:"Reply sent successfully.",draftId:v})}catch(f){console.error("Reply Email Error:",f);let v=f instanceof Error?f.message:"Unknown error";throw new Error(v)}}});var Lp=ne({auth:J,name:"sendDraftEmail",displayName:"Send Draft Email",description:"Sends a draft email message.",audience:"both",aiMetadata:{description:"Sends an existing draft email (identified by draft message ID) from the Outlook mailbox. Use this to dispatch a draft previously staged by Create Draft Email or a draft reply. Not idempotent: once sent the draft no longer exists, so re-running with the same ID will fail.",idempotent:!1},props:{messageId:Op({displayName:"Draft Email",description:"Select the draft email message to send.",required:!0})},async run(e){let{messageId:t}=e.propsValue;return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/messages/${t}/send`).post({}),{success:!0,message:"Draft sent successfully.",messageId:t}}});var jp=ne({auth:J,name:"send-email",displayName:"Send Email",description:"Sends an email using Microsoft Outlook.",audience:"both",aiMetadata:{description:"Composes and sends a new email from the authenticated Outlook mailbox to the given recipients, with optional CC/BCC and file attachments. Use this to send a fresh message (not a reply or forward). Not idempotent: each call dispatches a new email and saves a copy to Sent Items.",idempotent:!1},props:{recipients:E.Array({displayName:"To Email(s)",required:!0}),ccRecipients:E.Array({displayName:"CC Email(s)",required:!1,defaultValue:[]}),bccRecipients:E.Array({displayName:"BCC Email(s)",required:!1,defaultValue:[]}),subject:E.ShortText({displayName:"Subject",required:!0}),bodyFormat:E.StaticDropdown({displayName:"Body Format",required:!0,defaultValue:"text",options:{disabled:!1,options:[{label:"HTML",value:"html"},{label:"Text",value:"text"}]}}),body:E.LongText({displayName:"Body",required:!0}),attachments:E.Array({displayName:"Attachments",required:!1,defaultValue:[],properties:{file:E.File({displayName:"File",required:!0}),fileName:E.ShortText({displayName:"File Name",required:!1})}})},async run(e){let t=e.propsValue.recipients,r=e.propsValue.ccRecipients,n=e.propsValue.bccRecipients,o=e.propsValue.attachments,{subject:i,body:s,bodyFormat:u}=e.propsValue,p={subject:i,body:{content:s,contentType:u},toRecipients:t.map(v=>({emailAddress:{address:v}})),ccRecipients:r.map(v=>({emailAddress:{address:v}})),bccRecipients:n.map(v=>({emailAddress:{address:v}})),attachments:o.map(v=>({"@odata.type":"#microsoft.graph.fileAttachment",name:v.fileName||v.file.filename,contentBytes:v.file.base64}))};return await $.createClient(e.auth).api(`${$.mailboxPrefix(e.auth)}/sendMail`).post({message:p,saveToSentItems:"true"})}});var ro=ze(br());async function Fp(e,t,r,n,o,i){let s=[];for(let u of r){if(i&&u.sender?.emailAddress?.address&&!u.sender.emailAddress.address.toLowerCase().includes(i.toLowerCase()))continue;let p=await e.api(`${t}/messages/${u.id}/attachments`).get();for(let d of p.value){let{contentBytes:f,...v}=d;if(!(o&&d.name&&!d.name.toLowerCase().includes(o.toLowerCase()))&&d.name&&f){let y=await n.write({fileName:d.name,data:Buffer.from(f,"base64")});s.push({file:y,messageId:u.id,messageSubject:u.subject,messageSender:u.sender,messageReceivedDateTime:u.receivedDateTime,parentFolderId:u.parentFolderId,...v})}}}return s}a(Fp,"enrichAttachments");var Bp=St({auth:J,name:"newAttachment",displayName:"New Attachment",description:"Triggers when a new email containing one or more attachments arrives.",aiMetadata:{description:"Fires once per attachment when a new email carrying one or more file attachments arrives, optionally scoped to a folder, sender, or attachment-name filter. Each fire represents a single attachment from a newly received message."},props:{folderId:it({displayName:"Folder",description:"Monitor attachments in a specific folder. Leave empty to monitor all folders.",required:!1}),sender:E.ShortText({displayName:"From (Sender Email)",description:"Filter emails from a specific sender (optional). Leave empty to for all senders.",required:!1}),attachmentNameFilter:E.ShortText({displayName:"Attachment Name Filter",description:"Filter attachments by name (contains). Leave empty to include all attachments.",required:!1})},sampleData:{},type:"POLLING",async onEnable(e){await e.store.put("lastPoll",Date.now())},async onDisable(e){},async test(e){let{folderId:t,attachmentNameFilter:r,sender:n}=e.propsValue,o=$.createClient(e.auth),i=t?`${$.mailboxPrefix(e.auth)}/mailFolders/${t}/messages`:`${$.mailboxPrefix(e.auth)}/messages`,s=await o.api(`${i}?$filter=hasAttachments eq true`).top(10).get();return(await Fp(o,$.mailboxPrefix(e.auth),s.value,e.files,r,n)).map(d=>({epochMilliSeconds:(0,ro.default)(d.messageReceivedDateTime).valueOf(),data:d})).map(d=>d.data)},async run(e){let t=await e.store.get("lastPoll");if(he(t))throw new Error("lastPoll doesn't exist in the store.");let{folderId:r,attachmentNameFilter:n,sender:o}=e.propsValue,i=$.createClient(e.auth),s=r?`${$.mailboxPrefix(e.auth)}/mailFolders/${r}/messages`:`${$.mailboxPrefix(e.auth)}/messages`,u=await i.api(`${s}?$filter=receivedDateTime gt ${(0,ro.default)(t).toISOString()} and hasAttachments eq true`).orderby("receivedDateTime desc").get(),p=[];for(;u.value.length>0&&(p.push(...u.value),u["@odata.nextLink"]);)u=await i.api(u["@odata.nextLink"]).get();let f=(await Fp(i,$.mailboxPrefix(e.auth),p,e.files,n,o)).map(y=>({epochMilliSeconds:(0,ro.default)(y.messageReceivedDateTime).valueOf(),data:y})),v=f.reduce((y,l)=>Math.max(y,l.epochMilliSeconds),t);return await e.store.put("lastPoll",v),f.filter(y=>y.epochMilliSeconds>t).map(y=>y.data)}});var Fi=ze(br());var no={strategy:0,items:a(async({auth:e,lastFetchEpochMS:t,propsValue:r})=>{let n=$.createClient(e),o=[],i=r.folderId,s=t===0?"$top=10":`$filter=createdDateTime gt ${(0,Fi.default)(t).toISOString()}`,u=await n.api(`${$.mailboxPrefix(e)}/mailFolders/${i}/messages?${s}`).orderby("createdDateTime desc").get();if(t===0)for(let p of u.value)o.push(p);else for(;u.value.length>0;){for(let p of u.value)o.push(p);if(u["@odata.nextLink"])u=await n.api(u["@odata.nextLink"]).get();else break}return o.map(p=>({epochMilliSeconds:(0,Fi.default)(p.createdDateTime).valueOf(),data:p}))},"items")},Vp=St({auth:J,name:"newEmailInFolder",displayName:"New Email in Folder",description:"Triggers when a new email is delivered into the specified folder.",aiMetadata:{description:"Fires when a new message appears in the chosen Outlook mail folder. Each fire represents one new email added to that folder."},props:{folderId:it({displayName:"Folder",description:"",required:!0})},sampleData:{},type:"POLLING",async onEnable(e){await Ue.onEnable(no,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async onDisable(e){await Ue.onDisable(no,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async test(e){return await Ue.test(no,e)},async run(e){return await Ue.poll(no,e)}});var Bi=ze(br());var oo={strategy:0,items:a(async({auth:e,lastFetchEpochMS:t,propsValue:r})=>{let n=$.createClient(e),o=[],i=t===0?"$top=10":`$filter=receivedDateTime gt ${(0,Bi.default)(t).toISOString()}`,s=await n.api(`${$.mailboxPrefix(e)}/mailFolders/inbox/messages?${i}`).orderby("receivedDateTime desc").get();if(t===0)for(let p of s.value)o.push(p);else for(;s.value.length>0;){for(let p of s.value)o.push(p);if(s["@odata.nextLink"])s=await n.api(s["@odata.nextLink"]).get();else break}let u=o;return r?.sender&&(u=u.filter(p=>{let d=p.from?.emailAddress?.address?.toLowerCase(),f=r.sender?.toLowerCase();return d===f})),r?.recipient&&(u=u.filter(p=>p.toRecipients?.some(f=>{let v=f.emailAddress?.address?.toLowerCase(),y=r.recipient?.toLowerCase();return v===y}))),u.map(p=>({epochMilliSeconds:(0,Bi.default)(p.receivedDateTime).valueOf(),data:p}))},"items")},Hp=St({auth:J,name:"newEmail",displayName:"New Email",description:"Triggers when a new email is received in the inbox.",aiMetadata:{description:"Fires when a new message arrives in the mailbox Inbox, optionally narrowed to a specific sender and/or recipient address. Each fire represents one newly received email."},props:{sender:E.ShortText({displayName:"From (Sender Email)",description:"Filter emails from a specific sender (optional). Leave empty to for all senders.",required:!1}),recipient:E.ShortText({displayName:"To (Recipient Email)",description:"Filter emails to a specific recipient (optional). Leave empty to for all recipients.",required:!1})},sampleData:{},type:"POLLING",async onEnable(e){await Ue.onEnable(oo,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async onDisable(e){await Ue.onDisable(oo,{auth:e.auth,store:e.store,propsValue:e.propsValue})},async test(e){return await Ue.test(oo,e)},async run(e){return await Ue.poll(oo,e)}});var Zp=ne({auth:J,name:"request_approval_in_mail",displayName:"Request Approval in Email",description:"Send approval request email and then wait until the email is approved or disapproved",audience:"both",aiMetadata:{description:"Sends an email with a single link to a confirmation page where the recipient chooses Approve or Disapprove, then pauses the flow until they respond, resuming with the decision. Use this as a human-in-the-loop approval gate before proceeding. Not idempotent: each call sends a new email and creates a new pending waitpoint.",idempotent:!1},props:{recipients:E.ShortText({displayName:"To Email Address",description:"The email address of the recipient who will receive the approval request.",required:!0}),subject:E.ShortText({displayName:"Subject",description:"The subject of the approval request email.",required:!0}),body:E.LongText({displayName:"Body",description:"The main content of the email. You can include details about the approval request here in the html format or plain text.",required:!0})},async run(e){if(e.executionType==="BEGIN")try{let t=e.auth.access_token,r=e.propsValue.recipients,{subject:n,body:o}=e.propsValue;He(t,"token"),He(r,"recipients"),He(n,"subject"),He(o,"body");let i=await e.run.createWaitpoint({type:"WEBHOOK"}),s=`${i.resumeUrl}/confirm`,u=`
22
22
  <div>
23
23
  <p>${o}</p>
24
24
  <br />
25
25
  <p>
26
- <a href="${s}" style="display: inline-block; padding: 10px 20px; margin-right: 10px; background-color: #28a745; color: white; text-decoration: none; border-radius: 4px;">Approve</a>
27
- <a href="${u}" style="display: inline-block; padding: 10px 20px; background-color: #dc3545; color: white; text-decoration: none; border-radius: 4px;">Disapprove</a>
26
+ <a href="${s}" style="display: inline-block; padding: 10px 20px; background-color: #6e41e2; color: white; text-decoration: none; border-radius: 4px;">Review &amp; Respond</a>
28
27
  </p>
29
28
  </div>
30
- `,d=$.createClient(e.auth),f={subject:n,body:{content:p,contentType:"html"},toRecipients:[{emailAddress:{address:r}}]},v=await d.api(`${$.mailboxPrefix(e.auth)}/sendMail`).post({message:f,saveToSentItems:!0});return e.run.waitForWaitpoint(i.id),{approved:!1}}catch(t){throw console.error("[RequestApprovalEmail] Error during BEGIN execution:",t),t}else return{approved:e.resumePayload.queryParams.action==="approve"}}});var Gv=Zs({displayName:"Microsoft Outlook",auth:J,minimumSupportedRelease:"0.82.0",logoUrl:"https://cdn.activepieces.com/pieces/microsoft-outlook.png",categories:["PRODUCTIVITY"],authors:["lucaslimasouza","kishanprmr","sanket-a11y"],actions:[jp,kp,Up,Rp,zp,Mp,Zp,Np,Lp,Cp,Dp,al({auth:J,baseUrl:a(e=>{let t=e.props?.cloud;return rn(t)+"/v1.0/"},"baseUrl"),authMapping:a(async e=>({Authorization:`Bearer ${e.access_token}`}),"authMapping")})],triggers:[Hp,Vp,Bp]});0&&(module.exports={microsoftOutlook});
29
+ `,p=$.createClient(e.auth),d={subject:n,body:{content:u,contentType:"html"},toRecipients:[{emailAddress:{address:r}}]},f=await p.api(`${$.mailboxPrefix(e.auth)}/sendMail`).post({message:d,saveToSentItems:!0});return e.run.waitForWaitpoint(i.id),{approved:!1}}catch(t){throw console.error("[RequestApprovalEmail] Error during BEGIN execution:",t),t}else return{approved:e.resumePayload.queryParams.action==="approve"}}});var Gv=Zs({displayName:"Microsoft Outlook",auth:J,minimumSupportedRelease:"0.87.0",logoUrl:"https://cdn.activepieces.com/pieces/microsoft-outlook.png",categories:["PRODUCTIVITY"],authors:["lucaslimasouza","kishanprmr","sanket-a11y"],actions:[jp,kp,Up,Rp,zp,Mp,Zp,Np,Lp,Cp,Dp,al({auth:J,baseUrl:a(e=>{let t=e.props?.cloud;return rn(t)+"/v1.0/"},"baseUrl"),authMapping:a(async e=>({Authorization:`Bearer ${e.access_token}`}),"authMapping")})],triggers:[Hp,Vp,Bp]});0&&(module.exports={microsoftOutlook});
31
30
  /*! Bundled license information:
32
31
 
33
32
  mime-types/index.js: