@corsair-dev/gmail 0.1.1 → 0.1.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EACZ,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,QAAQ,EAER,uBAAuB,EAGvB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAW7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,MAAM,YAAY,CAAC;AASpB;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;CAIS,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,oBAAoB,CAC9C,OAAO,WAAW,EAClB,kBAAkB,EAClB,SAAS,EACT,OAAO,eAAe,CACtB,CAAC;AAEF,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,oBAAoB,IAAI,eAAe,CACzE,YAAY,EACZ,mBAAmB,CAAC,CAAC,CAAC,EACtB,oBAAoB,CAAC,CAAC,CAAC,CACvB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC5C,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IAC1C,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC5C,cAAc,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAChD,cAAc,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC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B,YAAY,EACX,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAM3B,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,mBAAmB,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{request as xe}from"corsair/http";var j=class extends Error{constructor(a,o){super(a);this.code=o;this.name="GmailAPIError"}},Re="https://gmail.googleapis.com/gmail/v1";async function Ae(e,t,a){let o=await fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,refresh_token:a,grant_type:"refresh_token"})});if(!o.ok){let i=await o.text();throw new j(`Failed to refresh access token: ${i}`,o.status)}return await o.json()}async function B({accessToken:e,expiresAt:t,clientId:a,clientSecret:o,refreshToken:n,forceRefresh:i=!1}){let d=Math.floor(Date.now()/1e3);if(!i&&e&&t&&Number(t)>d+300)return{accessToken:e,expiresAt:Number(t),refreshed:!1};let p=await Ae(a,o,n);return{accessToken:p.access_token,expiresAt:d+p.expires_in,refreshed:!0}}async function y(e,t,a={}){let{method:o="GET",body:n,query:i}=a;return await xe({BASE:Re,VERSION:"1.0.0",WITH_CREDENTIALS:!1,CREDENTIALS:"omit",TOKEN:t,HEADERS:{"Content-Type":"application/json"}},{method:o,url:e,body:o==="POST"||o==="PUT"||o==="PATCH"?n:void 0,mediaType:"application/json",query:o==="GET"?i:void 0})}function Oe(e){return e instanceof Error&&"status"in e&&e.status===401}async function c(e,t,a={}){try{return await y(e,t.key,a)}catch(o){if(Oe(o)&&t._refreshAuth){let n=await t._refreshAuth();return await y(e,n,a)}throw o}}import{logEventFromContext as M}from"corsair/core";var z=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts`,e,{method:"GET",query:{maxResults:t.maxResults,pageToken:t.pageToken,q:t.q}});if(a.drafts&&e.db.drafts)try{for(let o of a.drafts)o.id&&await e.db.drafts.upsertByEntityId(o.id,{...o,id:o.id,messageId:o.message?.id,createdAt:new Date})}catch(o){console.warn("Failed to save drafts to database:",o)}return await M(e,"gmail.drafts.list",{...t},"completed"),a},F=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts/${t.id}`,e,{method:"GET",query:{format:t.format}});if(a.id&&e.db.drafts)try{await e.db.drafts.upsertByEntityId(a.id,{...a,id:a.id,messageId:a.message?.id,createdAt:new Date})}catch(o){console.warn("Failed to save draft to database:",o)}return await M(e,"gmail.drafts.get",{...t},"completed"),a},V=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts`,e,{method:"POST",body:t.draft});return a.id&&await e.endpoints.drafts.get({id:a.id,userId:t.userId}),await M(e,"gmail.drafts.create",{...t},"completed"),a},K=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts/${t.id}`,e,{method:"PUT",body:t.draft});return a.id&&await e.endpoints.drafts.get({id:a.id,userId:t.userId}),await M(e,"gmail.drafts.update",{...t},"completed"),a},Y=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/drafts/${t.id}`,e,{method:"DELETE"}),e.db.drafts)try{await e.db.drafts.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete draft from database:",a)}await M(e,"gmail.drafts.delete",{...t},"completed")},Z=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts/send`,e,{method:"POST",body:{id:t.id,message:t.message}});return await M(e,"gmail.drafts.send",{...t},"completed"),a};import{logEventFromContext as v}from"corsair/core";var J=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels`,e,{method:"GET"});if(a.labels&&e.db.labels)try{for(let o of a.labels)o.id&&await e.db.labels.upsertByEntityId(o.id,{...o,id:o.id,createdAt:new Date})}catch(o){console.warn("Failed to save labels to database:",o)}return await v(e,"gmail.labels.list",{...t},"completed"),a},X=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels/${t.id}`,e,{method:"GET"});if(a.id&&e.db.labels)try{await e.db.labels.upsertByEntityId(a.id,{id:a.id,name:a.name,messageListVisibility:a.messageListVisibility,labelListVisibility:a.labelListVisibility,type:a.type,messagesTotal:a.messagesTotal,messagesUnread:a.messagesUnread,threadsTotal:a.threadsTotal,threadsUnread:a.threadsUnread,createdAt:new Date})}catch(o){console.warn("Failed to save label to database:",o)}return await v(e,"gmail.labels.get",{...t},"completed"),a},Q=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels`,e,{method:"POST",body:t.label});return a.id&&await e.endpoints.labels.get({id:a.id,userId:t.userId}),await v(e,"gmail.labels.create",{...t},"completed"),a},ee=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels/${t.id}`,e,{method:"PUT",body:t.label});return a.id&&await e.endpoints.labels.get({id:a.id,userId:t.userId}),await v(e,"gmail.labels.update",{...t},"completed"),a},te=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/labels/${t.id}`,e,{method:"DELETE"}),e.db.labels)try{await e.db.labels.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete label from database:",a)}await v(e,"gmail.labels.delete",{...t},"completed")};import{logEventFromContext as I}from"corsair/core";function U(e,t){return e?.headers?e.headers.find(o=>o.name?.toLowerCase()===t.toLowerCase())?.value:void 0}function Ue(e){if(e.payload)return U(e.payload,"Subject")}function $e(e){if(e.payload)return U(e.payload,"From")}function _e(e){if(e.payload)return U(e.payload,"To")}function se(e){if(!e)return;let t,a;if(e.body?.data)try{let o=Buffer.from(e.body.data,"base64").toString("utf-8");e.mimeType==="text/plain"?t=o:e.mimeType==="text/html"&&(a=o)}catch{}if(e.parts&&e.parts.length>0)for(let o of e.parts){let n=se(o);n&&(o.mimeType==="text/plain"?t=n:o.mimeType==="text/html"&&!t&&(a=n))}return t||a}function Ne(e){if(e.payload)return se(e.payload)}var ae=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages`,e,{method:"GET",query:{q:t.q,maxResults:t.maxResults,pageToken:t.pageToken,labelIds:t.labelIds?.join(","),includeSpamTrash:t.includeSpamTrash}});if(a.messages&&e.db.messages)try{for(let o of a.messages)o.id&&await e.db.messages.upsertByEntityId(o.id,{...o,id:o.id,createdAt:new Date})}catch(o){console.warn("Failed to save messages to database:",o)}return await I(e,"gmail.messages.list",{...t},"completed"),a},oe=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/${t.id}`,e,{method:"GET",query:{format:t.format,metadataHeaders:t.metadataHeaders?.join(",")}});if(a.id&&e.db.messages)try{let o=Ue(a),n=Ne(a),i=$e(a),d=_e(a);await e.db.messages.upsertByEntityId(a.id,{...a,subject:o,body:n,from:i,to:d,id:a.id,createdAt:new Date})}catch(o){console.warn("Failed to save message to database:",o)}return await I(e,"gmail.messages.get",{...t},"completed"),a},ie=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/send`,e,{method:"POST",body:{raw:t.raw,threadId:t.threadId}});return a.id&&await e.endpoints.messages.get({id:a.id,userId:t.userId}),await I(e,"gmail.messages.send",{...t},"completed"),a},ne=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/messages/${t.id}`,e,{method:"DELETE"}),e.db.messages)try{await e.db.messages.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete message from database:",a)}await I(e,"gmail.messages.delete",{...t},"completed")},re=async(e,t)=>{let a={};t.addLabelIds&&t.addLabelIds.length>0&&(a.addLabelIds=t.addLabelIds),t.removeLabelIds&&t.removeLabelIds.length>0&&(a.removeLabelIds=t.removeLabelIds);let o=await c(`/users/${t.userId||"me"}/messages/${t.id}/modify`,e,{method:"POST",body:a});return o.id&&await e.endpoints.messages.get({id:o.id,userId:t.userId}),await I(e,"gmail.messages.modify",{...t},"completed"),o},de=async(e,t)=>{let a={ids:t.ids};t.addLabelIds&&t.addLabelIds.length>0&&(a.addLabelIds=t.addLabelIds),t.removeLabelIds&&t.removeLabelIds.length>0&&(a.removeLabelIds=t.removeLabelIds),await c(`/users/${t.userId||"me"}/messages/batchModify`,e,{method:"POST",body:a}),await I(e,"gmail.messages.batchModify",{...t},"completed")},le=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/${t.id}/trash`,e,{method:"POST"});return a.id&&await e.endpoints.messages.get({id:a.id,userId:t.userId}),await I(e,"gmail.messages.trash",{...t},"completed"),a},me=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/${t.id}/untrash`,e,{method:"POST"});return a.id&&await e.endpoints.messages.get({id:a.id,userId:t.userId}),await I(e,"gmail.messages.untrash",{...t},"completed"),a};import{logEventFromContext as L}from"corsair/core";var pe=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads`,e,{method:"GET",query:{q:t.q,maxResults:t.maxResults,pageToken:t.pageToken,labelIds:t.labelIds?.join(","),includeSpamTrash:t.includeSpamTrash}});if(a.threads&&e.db.threads)try{for(let o of a.threads)o.id&&await e.db.threads.upsertByEntityId(o.id,{...o,id:o.id,createdAt:new Date})}catch(o){console.warn("Failed to save threads to database:",o)}return await L(e,"gmail.threads.list",{...t},"completed"),a},ge=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads/${t.id}`,e,{method:"GET",query:{format:t.format,metadataHeaders:t.metadataHeaders?.join(",")}});if(a.id&&e.db.threads)try{await e.db.threads.upsertByEntityId(a.id,{...a,id:a.id,createdAt:new Date})}catch(o){console.warn("Failed to save thread to database:",o)}return await L(e,"gmail.threads.get",{...t},"completed"),a},ce=async(e,t)=>{let a={};t.addLabelIds&&t.addLabelIds.length>0&&(a.addLabelIds=t.addLabelIds),t.removeLabelIds&&t.removeLabelIds.length>0&&(a.removeLabelIds=t.removeLabelIds);let o=await c(`/users/${t.userId||"me"}/threads/${t.id}/modify`,e,{method:"POST",body:a});return o.id&&await e.endpoints.threads.get({id:o.id,userId:t.userId}),await L(e,"gmail.threads.modify",{...t},"completed"),o},ue=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/threads/${t.id}`,e,{method:"DELETE"}),e.db.threads)try{await e.db.threads.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete thread from database:",a)}await L(e,"gmail.threads.delete",{...t},"completed")},he=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads/${t.id}/trash`,e,{method:"POST"});return a.id&&await e.endpoints.threads.get({id:a.id,userId:t.userId}),await L(e,"gmail.threads.trash",{...t},"completed"),a},fe=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads/${t.id}/untrash`,e,{method:"POST"});return a.id&&await e.endpoints.threads.get({id:a.id,userId:t.userId}),await L(e,"gmail.threads.untrash",{...t},"completed"),a};import{z as s}from"zod";var He=s.object({userId:s.string().optional(),q:s.string().optional(),maxResults:s.number().optional(),pageToken:s.string().optional(),labelIds:s.array(s.string()).optional(),includeSpamTrash:s.boolean().optional()}),ze=s.object({userId:s.string().optional(),id:s.string(),format:s.enum(["minimal","full","raw","metadata"]).optional(),metadataHeaders:s.array(s.string()).optional()}),Fe=s.object({userId:s.string().optional(),raw:s.string(),threadId:s.string().optional()}),Ve=s.object({userId:s.string().optional(),id:s.string()}),Ke=s.object({userId:s.string().optional(),id:s.string(),addLabelIds:s.array(s.string()).optional(),removeLabelIds:s.array(s.string()).optional()}),Ye=s.object({userId:s.string().optional(),ids:s.array(s.string()).optional(),addLabelIds:s.array(s.string()).optional(),removeLabelIds:s.array(s.string()).optional()}),Ze=s.object({userId:s.string().optional(),id:s.string()}),Je=s.object({userId:s.string().optional(),id:s.string()}),Xe=s.object({userId:s.string().optional()}),Qe=s.object({userId:s.string().optional(),id:s.string()}),et=s.object({userId:s.string().optional(),label:s.object({name:s.string().optional(),messageListVisibility:s.enum(["show","hide"]).optional(),labelListVisibility:s.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),color:s.object({textColor:s.string().optional(),backgroundColor:s.string().optional()}).optional()})}),tt=s.object({userId:s.string().optional(),id:s.string(),label:s.object({name:s.string().optional(),messageListVisibility:s.enum(["show","hide"]).optional(),labelListVisibility:s.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),color:s.object({textColor:s.string().optional(),backgroundColor:s.string().optional()}).optional()})}),st=s.object({userId:s.string().optional(),id:s.string()}),at=s.object({userId:s.string().optional(),maxResults:s.number().optional(),pageToken:s.string().optional(),q:s.string().optional()}),ot=s.object({userId:s.string().optional(),id:s.string(),format:s.enum(["minimal","full","raw","metadata"]).optional()}),it=s.object({userId:s.string().optional(),draft:s.object({message:s.object({raw:s.string().optional(),threadId:s.string().optional()}).optional()})}),nt=s.object({userId:s.string().optional(),id:s.string(),draft:s.object({message:s.object({raw:s.string().optional(),threadId:s.string().optional()}).optional()})}),rt=s.object({userId:s.string().optional(),id:s.string()}),dt=s.object({userId:s.string().optional(),id:s.string().optional(),message:s.object({raw:s.string().optional(),threadId:s.string().optional()}).optional()}),lt=s.object({userId:s.string().optional(),q:s.string().optional(),maxResults:s.number().optional(),pageToken:s.string().optional(),labelIds:s.array(s.string()).optional(),includeSpamTrash:s.boolean().optional()}),mt=s.object({userId:s.string().optional(),id:s.string(),format:s.enum(["minimal","full","metadata"]).optional(),metadataHeaders:s.array(s.string()).optional()}),pt=s.object({userId:s.string().optional(),id:s.string(),addLabelIds:s.array(s.string()).optional(),removeLabelIds:s.array(s.string()).optional()}),gt=s.object({userId:s.string().optional(),id:s.string()}),ct=s.object({userId:s.string().optional(),id:s.string()}),ut=s.object({userId:s.string().optional(),id:s.string()}),ht=s.object({userId:s.string().optional()}),u={messagesList:He,messagesGet:ze,messagesSend:Fe,messagesDelete:Ve,messagesModify:Ke,messagesBatchModify:Ye,messagesTrash:Ze,messagesUntrash:Je,labelsList:Xe,labelsGet:Qe,labelsCreate:et,labelsUpdate:tt,labelsDelete:st,draftsList:at,draftsGet:ot,draftsCreate:it,draftsUpdate:nt,draftsDelete:rt,draftsSend:dt,threadsList:lt,threadsGet:mt,threadsModify:pt,threadsDelete:gt,threadsTrash:ct,threadsUntrash:ut,usersGetProfile:ht},ft=s.object({name:s.string().optional(),value:s.string().optional()}),bt=s.object({attachmentId:s.string().optional(),size:s.number().optional(),data:s.string().optional()}),yt=s.object({partId:s.string().optional(),mimeType:s.string().optional(),filename:s.string().optional(),headers:s.array(ft).optional(),body:bt.optional()}),be=yt.extend({parts:s.lazy(()=>s.array(be).optional())}),E=s.object({id:s.string().optional(),threadId:s.string().optional(),labelIds:s.array(s.string()).optional(),snippet:s.string().optional(),historyId:s.string().optional(),internalDate:s.union([s.string(),s.number(),s.date()]).transform(e=>{if(e instanceof Date)return e;if(typeof e=="number")return new Date(e);if(typeof e=="string"){let t=Number(e);return isNaN(t)?null:new Date(t)}return null}).nullable().optional(),sizeEstimate:s.number().optional(),payload:be.optional(),raw:s.string().optional()}),Et=s.object({messages:s.array(E).optional(),nextPageToken:s.string().optional(),resultSizeEstimate:s.number().optional()}),Gt=s.object({textColor:s.string().optional(),backgroundColor:s.string().optional()}),x=s.object({id:s.string().optional(),name:s.string().optional(),messageListVisibility:s.enum(["show","hide"]).optional(),labelListVisibility:s.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),type:s.enum(["system","user"]).optional(),messagesTotal:s.number().optional(),messagesUnread:s.number().optional(),threadsTotal:s.number().optional(),threadsUnread:s.number().optional(),color:Gt.optional()}),It=s.object({labels:s.array(x).optional()}),R=s.object({id:s.string().optional(),message:E.optional()}),wt=s.object({drafts:s.array(R).optional(),nextPageToken:s.string().optional(),resultSizeEstimate:s.number().optional()}),P=s.object({id:s.string().optional(),snippet:s.string().optional(),historyId:s.string().optional(),messages:s.array(E).optional()}),Tt=s.object({threads:s.array(P).optional(),nextPageToken:s.string().optional(),resultSizeEstimate:s.number().optional()}),Mt=s.object({emailAddress:s.string().optional(),messagesTotal:s.number().optional(),threadsTotal:s.number().optional(),historyId:s.string().optional()}),h={messagesList:Et,messagesGet:E,messagesSend:E,messagesDelete:s.void(),messagesModify:E,messagesBatchModify:s.void(),messagesTrash:E,messagesUntrash:E,labelsList:It,labelsGet:x,labelsCreate:x,labelsUpdate:x,labelsDelete:s.void(),draftsList:wt,draftsGet:R,draftsCreate:R,draftsUpdate:R,draftsDelete:s.void(),draftsSend:E,threadsList:Tt,threadsGet:P,threadsModify:P,threadsDelete:s.void(),threadsTrash:P,threadsUntrash:P,usersGetProfile:Mt};var G={list:ae,get:oe,send:ie,delete:ne,modify:re,batchModify:de,trash:le,untrash:me},S={list:J,get:X,create:Q,update:ee,delete:te},w={list:z,get:F,create:V,update:K,delete:Y,send:Z},T={list:pe,get:ge,modify:ce,delete:ue,trash:he,untrash:fe};import{z as C}from"zod";import{z as r}from"zod";var Lt=r.object({name:r.string().optional(),value:r.string().optional()}),St=r.object({attachmentId:r.string().optional(),size:r.number().optional(),data:r.string().optional()}),ye=r.lazy(()=>r.object({partId:r.string().optional(),mimeType:r.string().optional(),filename:r.string().optional(),headers:r.array(Lt).optional(),body:St.optional(),parts:r.array(ye).optional()})),Ee=r.object({id:r.string(),threadId:r.string().optional(),labelIds:r.array(r.string()).optional(),snippet:r.string().optional(),historyId:r.string().optional(),internalDate:r.string().optional(),sizeEstimate:r.number().optional(),payload:ye.optional(),raw:r.string().optional(),subject:r.string().optional(),body:r.string().optional(),from:r.string().optional(),to:r.string().optional(),createdAt:r.coerce.date().nullable().optional()}),Ge=r.object({id:r.string(),name:r.string().optional(),messageListVisibility:r.enum(["show","hide"]).optional(),labelListVisibility:r.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),type:r.enum(["system","user"]).optional(),messagesTotal:r.number().optional(),messagesUnread:r.number().optional(),threadsTotal:r.number().optional(),threadsUnread:r.number().optional(),createdAt:r.coerce.date().nullable().optional()}),Ie=r.object({id:r.string(),messageId:r.string().optional(),createdAt:r.coerce.date().nullable().optional()}),we=r.object({id:r.string(),snippet:r.string().optional(),historyId:r.string().optional(),createdAt:r.coerce.date().nullable().optional()});var us=C.object({clientId:C.string(),clientSecret:C.string(),accessToken:C.string(),refreshToken:C.string()}),$={version:"1.0.0",entities:{messages:Ee,labels:Ge,drafts:Ie,threads:we}};import{logEventFromContext as D}from"corsair/core";import{z as m}from"zod";var kt=m.object({data:m.string().optional(),attributes:m.record(m.string()).optional(),messageId:m.string().optional(),publishTime:m.string().optional()}),Te=m.object({message:kt.optional(),subscription:m.string().optional(),event:m.unknown().optional()}),bs=m.object({emailAddress:m.string().optional(),historyId:m.string().optional()}),vt=m.object({type:m.literal("messageReceived"),emailAddress:m.string(),historyId:m.string(),message:m.custom()}),Pt=m.object({type:m.literal("messageDeleted"),emailAddress:m.string(),historyId:m.string(),message:m.custom()}),Ct=m.object({type:m.literal("messageLabelChanged"),emailAddress:m.string(),historyId:m.string(),message:m.custom(),labelsAdded:m.array(m.string()).optional(),labelsRemoved:m.array(m.string()).optional()}),Me=m.union([vt,Pt,Ct]);function k(e){let t=Buffer.from(e,"base64").toString("utf-8");return JSON.parse(t)}function _(e){return t=>{let a=t.body;if(!a.message?.data)return!1;try{let o=k(a.message.data);return!!o.historyId&&!!o.emailAddress}catch{return!1}}}var Dt=100,xt=10,Rt=10;function N(e,t){return e?.headers?e.headers.find(o=>o.name?.toLowerCase()===t.toLowerCase())?.value:void 0}function At(e){if(e.payload)return N(e.payload,"Subject")}function Ot(e){if(e.payload)return N(e.payload,"From")}function jt(e){if(e.payload)return N(e.payload,"To")}function ke(e){if(!e)return;let t,a;if(e.body?.data)try{let o=Buffer.from(e.body.data,"base64").toString("utf-8");e.mimeType==="text/plain"?t=o:e.mimeType==="text/html"&&(a=o)}catch{}if(e.parts&&e.parts.length>0)for(let o of e.parts){let n=ke(o);n&&(o.mimeType==="text/plain"?t=n:o.mimeType==="text/html"&&!t&&(a=n))}return t||a}function Bt(e){if(e.payload)return ke(e.payload)}function Ut(e){let t=[],a=[],o=[];if(!e)return{added:t,deleted:a,modified:o};for(let n of e){if(n.messagesAdded)for(let i of n.messagesAdded)i.message?.id&&t.push(i.message.id);if(n.messagesDeleted)for(let i of n.messagesDeleted)i.message?.id&&a.push(i.message.id);if(n.labelsAdded||n.labelsRemoved){if(n.labelsAdded)for(let i of n.labelsAdded)i.message?.id&&o.push(i.message.id);if(n.labelsRemoved)for(let i of n.labelsRemoved)i.message?.id&&o.push(i.message.id)}}return{added:[...new Set(t)],deleted:[...new Set(a)],modified:[...new Set(o)]}}async function q(e,t,a){let[o,n]=await Promise.all([y(`/users/${t}/messages/${a}`,e,{method:"GET",query:{format:"full"}}),y(`/users/${t}/messages/${a}`,e,{method:"GET",query:{format:"raw"}}).catch(()=>null)]);return{...o,raw:n?.raw}}async function $t(e,t,a,o){return y(`/users/${t}/messages/${a}/attachments/${o}`,e,{method:"GET"})}async function ve(e,t,a){if(!a.payload)return a;let o=async i=>{if(!i)return i;if(i.body?.attachmentId)try{let d=await $t(e,t,a.id,i.body.attachmentId);return{...i,body:{...i.body,data:d.data,size:d.size}}}catch(d){return console.warn(`Failed to fetch attachment ${i.body.attachmentId} for message ${a.id}:`,d),i}if(i.parts&&i.parts.length>0){let d=await Promise.all(i.parts.map(o));return{...i,parts:d.filter(l=>l!==void 0)}}return i},n=await o(a.payload);return{...a,payload:n}}function _t(e){let t=Number(e);return t>1?String(t-1):e}async function Pe(e,t){return!e.db?.messages||!t.id?"":(await e.db.messages.upsertByEntityId(t.id,{...t,id:t.id,subject:At(t),body:Bt(t),from:Ot(t),to:jt(t),createdAt:new Date}))?.id??""}async function Nt(e,t,a,o){let n=await y(`/users/${a}/messages`,t,{method:"GET",query:{maxResults:xt}}),i=[],d=[];if(!n.messages?.length)return{added:i,modified:d};let l=Number(o);for(let p of n.messages)if(p.id)try{let g=await q(t,a,p.id);(g.historyId?Number(g.historyId):0)>=l-Rt&&(e.db?.messages&&await e.db.messages.findByEntityId(p.id)?d.push(p.id):i.push(p.id))}catch{}return{added:i,modified:d}}async function Le(e,t,a,o){let n=null,i="";for(let d of o)try{let l=await q(t,a,d),p=await ve(t,a,l);n||(n=p);try{let g=await Pe(e,p);!i&&g&&(i=g)}catch(g){throw console.error(`Failed to save message ${p.id} to database:`,g),g}}catch(l){console.warn(`Failed to process message ${d}:`,l)}return{message:n,corsairEntityId:i}}async function qt(e,t,a,o){let n=null,i="";if(!e.db?.messages)return{message:null,corsairEntityId:i};for(let d of o)try{let l=null;try{l=await y(`/users/${a}/messages/${d}`,t,{method:"GET",query:{format:"full"}})}catch(p){if(p?.statusCode===404)continue}if(!n&&l&&(n=l),!i){let p=await e.db.messages.findByEntityId(d);p&&(i=p.id)}await e.db.messages.deleteByEntityId(d)}catch(l){console.warn(`Failed to delete message ${d} from database:`,l)}return{message:n,corsairEntityId:i}}async function Se(e,t,a,o){let n=null,i="";if(!e.db?.messages)return{message:null,corsairEntityId:i};for(let d of o)try{let l=await q(t,a,d),p=await ve(t,a,l);n||(n=p);try{let g=await Pe(e,p);!i&&g&&(i=g)}catch(g){throw console.error(`Failed to update message ${p.id} in database:`,g),g}}catch(l){console.warn(`Failed to process message ${d}:`,l)}return{message:n,corsairEntityId:i}}var Ce={match:_("messageChanged"),handler:async(e,t)=>{let a=t.payload;if(!a.message?.data)return{success:!1,error:"No message data in notification"};let o=k(a.message.data);if(!o.historyId||!o.emailAddress)return{success:!1,error:"Invalid push notification format"};let n=e.key,i=o.emailAddress,d=o.historyId;try{let l=_t(d),p=await y(`/users/${i}/history`,n,{method:"GET",query:{startHistoryId:l,maxResults:Dt}}),{added:g,deleted:A,modified:O}=Ut(p.history);if(O.length>0){let f=await Se(e,n,i,O),b={type:"messageLabelChanged",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageLabelChanged",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}if(g.length>0){let f=await Le(e,n,i,g),b={type:"messageReceived",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageReceived",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}if(A.length>0){let f=await qt(e,n,i,A),b={type:"messageDeleted",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageDeleted",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}let{added:W,modified:H}=await Nt(e,n,i,d);if(H.length>0){let f=await Se(e,n,i,H),b={type:"messageLabelChanged",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageLabelChanged",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}if(W.length>0){let f=await Le(e,n,i,W),b={type:"messageReceived",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageReceived",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}return{success:!0,corsairEntityId:"",data:{type:"messageReceived",emailAddress:i,historyId:d,message:{}}}}catch(l){return console.error("Failed to process Gmail webhook:",l),{success:!1,error:`Failed to process message: ${l instanceof Error?l.message:"Unknown error"}`}}}};var De={messageChanged:Ce};var Wt={oauth_2:{integration:["topic_id"]}},Ht={messages:{list:G.list,get:G.get,send:G.send,delete:G.delete,modify:G.modify,batchModify:G.batchModify,trash:G.trash,untrash:G.untrash},labels:{list:S.list,get:S.get,create:S.create,update:S.update,delete:S.delete},drafts:{list:w.list,get:w.get,create:w.create,update:w.update,delete:w.delete,send:w.send},threads:{list:T.list,get:T.get,modify:T.modify,delete:T.delete,trash:T.trash,untrash:T.untrash}},zt={"messages.list":{input:u.messagesList,output:h.messagesList},"messages.get":{input:u.messagesGet,output:h.messagesGet},"messages.send":{input:u.messagesSend,output:h.messagesSend},"messages.delete":{input:u.messagesDelete,output:h.messagesDelete},"messages.modify":{input:u.messagesModify,output:h.messagesModify},"messages.batchModify":{input:u.messagesBatchModify,output:h.messagesBatchModify},"messages.trash":{input:u.messagesTrash,output:h.messagesTrash},"messages.untrash":{input:u.messagesUntrash,output:h.messagesUntrash},"labels.list":{input:u.labelsList,output:h.labelsList},"labels.get":{input:u.labelsGet,output:h.labelsGet},"labels.create":{input:u.labelsCreate,output:h.labelsCreate},"labels.update":{input:u.labelsUpdate,output:h.labelsUpdate},"labels.delete":{input:u.labelsDelete,output:h.labelsDelete},"drafts.list":{input:u.draftsList,output:h.draftsList},"drafts.get":{input:u.draftsGet,output:h.draftsGet},"drafts.create":{input:u.draftsCreate,output:h.draftsCreate},"drafts.update":{input:u.draftsUpdate,output:h.draftsUpdate},"drafts.delete":{input:u.draftsDelete,output:h.draftsDelete},"drafts.send":{input:u.draftsSend,output:h.draftsSend},"threads.list":{input:u.threadsList,output:h.threadsList},"threads.get":{input:u.threadsGet,output:h.threadsGet},"threads.modify":{input:u.threadsModify,output:h.threadsModify},"threads.delete":{input:u.threadsDelete,output:h.threadsDelete},"threads.trash":{input:u.threadsTrash,output:h.threadsTrash},"threads.untrash":{input:u.threadsUntrash,output:h.threadsUntrash}},Ft={messageChanged:De.messageChanged},Vt={messageChanged:{description:"A Gmail message was received, deleted, or had its labels changed",payload:Te,response:Me}},Kt="oauth_2",Yt={"messages.list":{riskLevel:"read",description:"List messages in a mailbox"},"messages.get":{riskLevel:"read",description:"Get a specific message"},"messages.send":{riskLevel:"write",description:"Send an email to one or more recipients"},"messages.delete":{riskLevel:"destructive",irreversible:!0,description:"Permanently delete a message [DESTRUCTIVE \xB7 IRREVERSIBLE]"},"messages.modify":{riskLevel:"write",description:"Add or remove labels from a message"},"messages.batchModify":{riskLevel:"write",description:"Add or remove labels from multiple messages in bulk"},"messages.trash":{riskLevel:"write",description:"Move a message to the trash"},"messages.untrash":{riskLevel:"write",description:"Restore a message from the trash"},"labels.list":{riskLevel:"read",description:"List all labels in the mailbox"},"labels.get":{riskLevel:"read",description:"Get a specific label"},"labels.create":{riskLevel:"write",description:"Create a new label"},"labels.update":{riskLevel:"write",description:"Update an existing label"},"labels.delete":{riskLevel:"destructive",description:"Delete a label [DESTRUCTIVE]"},"drafts.list":{riskLevel:"read",description:"List drafts in the mailbox"},"drafts.get":{riskLevel:"read",description:"Get a specific draft"},"drafts.create":{riskLevel:"write",description:"Create a new draft"},"drafts.update":{riskLevel:"write",description:"Update an existing draft"},"drafts.delete":{riskLevel:"destructive",description:"Delete a draft [DESTRUCTIVE]"},"drafts.send":{riskLevel:"write",description:"Send a draft as an email"},"threads.list":{riskLevel:"read",description:"List threads in the mailbox"},"threads.get":{riskLevel:"read",description:"Get a specific thread"},"threads.modify":{riskLevel:"write",description:"Add or remove labels from a thread"},"threads.delete":{riskLevel:"destructive",irreversible:!0,description:"Permanently delete a thread [DESTRUCTIVE \xB7 IRREVERSIBLE]"},"threads.trash":{riskLevel:"write",description:"Move a thread to the trash"},"threads.untrash":{riskLevel:"write",description:"Restore a thread from the trash"}};function xs(e={}){let t={...e,authType:e.authType??Kt};return{id:"gmail",schema:$,options:t,authConfig:Wt,oauthConfig:{providerName:"Google",authUrl:"https://accounts.google.com/o/oauth2/v2/auth",tokenUrl:"https://oauth2.googleapis.com/token",scopes:["https://www.googleapis.com/auth/gmail.modify","https://www.googleapis.com/auth/gmail.labels","https://www.googleapis.com/auth/gmail.send","https://www.googleapis.com/auth/gmail.compose"],authParams:{access_type:"offline",prompt:"consent"}},hooks:t.hooks,webhookHooks:t.webhookHooks,endpoints:Ht,webhooks:Ft,endpointMeta:Yt,endpointSchemas:zt,webhookSchemas:Vt,keyBuilder:async a=>{let o=a.authType;if(t.key)return t.key;if(a.authType==="oauth_2"){let[n,i,d]=await Promise.all([a.keys.get_access_token(),a.keys.get_expires_at(),a.keys.get_refresh_token()]);if(!d)throw new Error("[auth-missing:gmail:refresh_token]: Gmail refresh token is missing");let l=await a.keys.get_integration_credentials();if(!l.client_id||!l.client_secret)throw new Error("[auth-missing:gmail:client_credentials]: Gmail client credentials are missing");let p;try{p=await B({accessToken:n,expiresAt:i,refreshToken:d,clientId:l.client_id,clientSecret:l.client_secret})}catch(g){throw new Error(`[corsair:gmail] Failed to obtain valid access token: ${g instanceof Error?g.message:String(g)}`)}if(p.refreshed)try{await a.keys.set_access_token(p.accessToken),await a.keys.set_expires_at(String(p.expiresAt))}catch(g){throw new Error(`[corsair:gmail] Token was refreshed but failed to persist new credentials: ${g instanceof Error?g.message:String(g)}`)}return a._refreshAuth=async()=>{let g=await B({accessToken:null,expiresAt:null,refreshToken:d,clientId:l.client_id,clientSecret:l.client_secret,forceRefresh:!0});return await a.keys.set_access_token(g.accessToken),await a.keys.set_expires_at(String(g.expiresAt)),g.accessToken},p.accessToken}throw new Error(`[auth-missing:gmail:${o}]: Gmail key is missing`)},pluginWebhookMatcher:a=>{let o=a.headers;if(!(o.from==="noreply@google.com"||typeof o["user-agent"]=="string"&&o["user-agent"].includes("APIs-Google")))return!1;let i=a.body;if(!i?.message?.data)return!1;try{let d=k(i.message.data);return!!d.emailAddress&&!!d.historyId}catch{return!1}}}}export{$ as GmailSchema,_ as createGmailWebhookMatcher,k as decodePubSubMessage,xs as gmail,Wt as gmailAuthConfig,zt as gmailEndpointSchemas,Ht as gmailEndpointsNested,Ft as gmailWebhooksNested};
1
+ import{request as xe}from"corsair/http";var j=class extends Error{constructor(a,o){super(a);this.code=o;this.name="GmailAPIError"}},Re="https://gmail.googleapis.com/gmail/v1";async function Ae(e,t,a){let o=await fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,refresh_token:a,grant_type:"refresh_token"})});if(!o.ok){let i=await o.text();throw new j(`Failed to refresh access token: ${i}`,o.status)}return await o.json()}async function B({accessToken:e,expiresAt:t,clientId:a,clientSecret:o,refreshToken:n,forceRefresh:i=!1}){let d=Math.floor(Date.now()/1e3);if(!i&&e&&t&&Number(t)>d+300)return{accessToken:e,expiresAt:Number(t),refreshed:!1};let p=await Ae(a,o,n);return{accessToken:p.access_token,expiresAt:d+p.expires_in,refreshed:!0}}async function y(e,t,a={}){let{method:o="GET",body:n,query:i}=a;return await xe({BASE:Re,VERSION:"1.0.0",WITH_CREDENTIALS:!1,CREDENTIALS:"omit",TOKEN:t,HEADERS:{"Content-Type":"application/json"}},{method:o,url:e,body:o==="POST"||o==="PUT"||o==="PATCH"?n:void 0,mediaType:"application/json",query:o==="GET"?i:void 0})}function Oe(e){return e instanceof Error&&"status"in e&&e.status===401}async function c(e,t,a={}){try{return await y(e,t.key,a)}catch(o){if(Oe(o)&&t._refreshAuth){let n=await t._refreshAuth();return await y(e,n,a)}throw o}}import{logEventFromContext as M}from"corsair/core";var z=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts`,e,{method:"GET",query:{maxResults:t.maxResults,pageToken:t.pageToken,q:t.q}});if(a.drafts&&e.db.drafts)try{for(let o of a.drafts)o.id&&await e.db.drafts.upsertByEntityId(o.id,{...o,id:o.id,messageId:o.message?.id,createdAt:new Date})}catch(o){console.warn("Failed to save drafts to database:",o)}return await M(e,"gmail.drafts.list",{...t},"completed"),a},F=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts/${t.id}`,e,{method:"GET",query:{format:t.format}});if(a.id&&e.db.drafts)try{await e.db.drafts.upsertByEntityId(a.id,{...a,id:a.id,messageId:a.message?.id,createdAt:new Date})}catch(o){console.warn("Failed to save draft to database:",o)}return await M(e,"gmail.drafts.get",{...t},"completed"),a},V=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts`,e,{method:"POST",body:t.draft});return a.id&&await e.endpoints.drafts.get({id:a.id,userId:t.userId}),await M(e,"gmail.drafts.create",{...t},"completed"),a},K=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts/${t.id}`,e,{method:"PUT",body:t.draft});return a.id&&await e.endpoints.drafts.get({id:a.id,userId:t.userId}),await M(e,"gmail.drafts.update",{...t},"completed"),a},Y=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/drafts/${t.id}`,e,{method:"DELETE"}),e.db.drafts)try{await e.db.drafts.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete draft from database:",a)}await M(e,"gmail.drafts.delete",{...t},"completed")},Z=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/drafts/send`,e,{method:"POST",body:{id:t.id,message:t.message}});return await M(e,"gmail.drafts.send",{...t},"completed"),a};import{logEventFromContext as v}from"corsair/core";var J=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels`,e,{method:"GET"});if(a.labels&&e.db.labels)try{for(let o of a.labels)o.id&&await e.db.labels.upsertByEntityId(o.id,{...o,id:o.id,createdAt:new Date})}catch(o){console.warn("Failed to save labels to database:",o)}return await v(e,"gmail.labels.list",{...t},"completed"),a},X=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels/${t.id}`,e,{method:"GET"});if(a.id&&e.db.labels)try{await e.db.labels.upsertByEntityId(a.id,{id:a.id,name:a.name,messageListVisibility:a.messageListVisibility,labelListVisibility:a.labelListVisibility,type:a.type,messagesTotal:a.messagesTotal,messagesUnread:a.messagesUnread,threadsTotal:a.threadsTotal,threadsUnread:a.threadsUnread,createdAt:new Date})}catch(o){console.warn("Failed to save label to database:",o)}return await v(e,"gmail.labels.get",{...t},"completed"),a},Q=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels`,e,{method:"POST",body:t.label});return a.id&&await e.endpoints.labels.get({id:a.id,userId:t.userId}),await v(e,"gmail.labels.create",{...t},"completed"),a},ee=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/labels/${t.id}`,e,{method:"PUT",body:t.label});return a.id&&await e.endpoints.labels.get({id:a.id,userId:t.userId}),await v(e,"gmail.labels.update",{...t},"completed"),a},te=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/labels/${t.id}`,e,{method:"DELETE"}),e.db.labels)try{await e.db.labels.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete label from database:",a)}await v(e,"gmail.labels.delete",{...t},"completed")};import{logEventFromContext as I}from"corsair/core";function U(e,t){return e?.headers?e.headers.find(o=>o.name?.toLowerCase()===t.toLowerCase())?.value:void 0}function Ue(e){if(e.payload)return U(e.payload,"Subject")}function $e(e){if(e.payload)return U(e.payload,"From")}function _e(e){if(e.payload)return U(e.payload,"To")}function se(e){if(!e)return;let t,a;if(e.body?.data)try{let o=Buffer.from(e.body.data,"base64").toString("utf-8");e.mimeType==="text/plain"?t=o:e.mimeType==="text/html"&&(a=o)}catch{}if(e.parts&&e.parts.length>0)for(let o of e.parts){let n=se(o);n&&(o.mimeType==="text/plain"?t=n:o.mimeType==="text/html"&&!t&&(a=n))}return t||a}function Ne(e){if(e.payload)return se(e.payload)}var ae=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages`,e,{method:"GET",query:{q:t.q,maxResults:t.maxResults,pageToken:t.pageToken,labelIds:t.labelIds?.join(","),includeSpamTrash:t.includeSpamTrash}});if(a.messages&&e.db.messages)try{for(let o of a.messages)o.id&&await e.db.messages.upsertByEntityId(o.id,{...o,id:o.id,createdAt:new Date})}catch(o){console.warn("Failed to save messages to database:",o)}return await I(e,"gmail.messages.list",{...t},"completed"),a},oe=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/${t.id}`,e,{method:"GET",query:{format:t.format,metadataHeaders:t.metadataHeaders?.join(",")}});if(a.id&&e.db.messages)try{let o=Ue(a),n=Ne(a),i=$e(a),d=_e(a);await e.db.messages.upsertByEntityId(a.id,{...a,subject:o,body:n,from:i,to:d,id:a.id,createdAt:new Date})}catch(o){console.warn("Failed to save message to database:",o)}return await I(e,"gmail.messages.get",{...t},"completed"),a},ie=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/send`,e,{method:"POST",body:{raw:t.raw,threadId:t.threadId}});return a.id&&await e.endpoints.messages.get({id:a.id,userId:t.userId}),await I(e,"gmail.messages.send",{...t},"completed"),a},ne=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/messages/${t.id}`,e,{method:"DELETE"}),e.db.messages)try{await e.db.messages.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete message from database:",a)}await I(e,"gmail.messages.delete",{...t},"completed")},re=async(e,t)=>{let a={};t.addLabelIds&&t.addLabelIds.length>0&&(a.addLabelIds=t.addLabelIds),t.removeLabelIds&&t.removeLabelIds.length>0&&(a.removeLabelIds=t.removeLabelIds);let o=await c(`/users/${t.userId||"me"}/messages/${t.id}/modify`,e,{method:"POST",body:a});return o.id&&await e.endpoints.messages.get({id:o.id,userId:t.userId}),await I(e,"gmail.messages.modify",{...t},"completed"),o},de=async(e,t)=>{let a={ids:t.ids};t.addLabelIds&&t.addLabelIds.length>0&&(a.addLabelIds=t.addLabelIds),t.removeLabelIds&&t.removeLabelIds.length>0&&(a.removeLabelIds=t.removeLabelIds),await c(`/users/${t.userId||"me"}/messages/batchModify`,e,{method:"POST",body:a}),await I(e,"gmail.messages.batchModify",{...t},"completed")},le=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/${t.id}/trash`,e,{method:"POST"});return a.id&&await e.endpoints.messages.get({id:a.id,userId:t.userId}),await I(e,"gmail.messages.trash",{...t},"completed"),a},me=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/messages/${t.id}/untrash`,e,{method:"POST"});return a.id&&await e.endpoints.messages.get({id:a.id,userId:t.userId}),await I(e,"gmail.messages.untrash",{...t},"completed"),a};import{logEventFromContext as L}from"corsair/core";var pe=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads`,e,{method:"GET",query:{q:t.q,maxResults:t.maxResults,pageToken:t.pageToken,labelIds:t.labelIds?.join(","),includeSpamTrash:t.includeSpamTrash}});if(a.threads&&e.db.threads)try{for(let o of a.threads)o.id&&await e.db.threads.upsertByEntityId(o.id,{...o,id:o.id,createdAt:new Date})}catch(o){console.warn("Failed to save threads to database:",o)}return await L(e,"gmail.threads.list",{...t},"completed"),a},ge=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads/${t.id}`,e,{method:"GET",query:{format:t.format,metadataHeaders:t.metadataHeaders?.join(",")}});if(a.id&&e.db.threads)try{await e.db.threads.upsertByEntityId(a.id,{...a,id:a.id,createdAt:new Date})}catch(o){console.warn("Failed to save thread to database:",o)}return await L(e,"gmail.threads.get",{...t},"completed"),a},ce=async(e,t)=>{let a={};t.addLabelIds&&t.addLabelIds.length>0&&(a.addLabelIds=t.addLabelIds),t.removeLabelIds&&t.removeLabelIds.length>0&&(a.removeLabelIds=t.removeLabelIds);let o=await c(`/users/${t.userId||"me"}/threads/${t.id}/modify`,e,{method:"POST",body:a});return o.id&&await e.endpoints.threads.get({id:o.id,userId:t.userId}),await L(e,"gmail.threads.modify",{...t},"completed"),o},ue=async(e,t)=>{if(await c(`/users/${t.userId||"me"}/threads/${t.id}`,e,{method:"DELETE"}),e.db.threads)try{await e.db.threads.deleteByEntityId(t.id)}catch(a){console.warn("Failed to delete thread from database:",a)}await L(e,"gmail.threads.delete",{...t},"completed")},he=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads/${t.id}/trash`,e,{method:"POST"});return a.id&&await e.endpoints.threads.get({id:a.id,userId:t.userId}),await L(e,"gmail.threads.trash",{...t},"completed"),a},fe=async(e,t)=>{let a=await c(`/users/${t.userId||"me"}/threads/${t.id}/untrash`,e,{method:"POST"});return a.id&&await e.endpoints.threads.get({id:a.id,userId:t.userId}),await L(e,"gmail.threads.untrash",{...t},"completed"),a};import{z as s}from"zod";var He=s.object({userId:s.string().optional(),q:s.string().optional(),maxResults:s.number().optional(),pageToken:s.string().optional(),labelIds:s.array(s.string()).optional(),includeSpamTrash:s.boolean().optional()}),ze=s.object({userId:s.string().optional(),id:s.string(),format:s.enum(["minimal","full","raw","metadata"]).optional(),metadataHeaders:s.array(s.string()).optional()}),Fe=s.object({userId:s.string().optional(),raw:s.string(),threadId:s.string().optional()}),Ve=s.object({userId:s.string().optional(),id:s.string()}),Ke=s.object({userId:s.string().optional(),id:s.string(),addLabelIds:s.array(s.string()).optional(),removeLabelIds:s.array(s.string()).optional()}),Ye=s.object({userId:s.string().optional(),ids:s.array(s.string()).optional(),addLabelIds:s.array(s.string()).optional(),removeLabelIds:s.array(s.string()).optional()}),Ze=s.object({userId:s.string().optional(),id:s.string()}),Je=s.object({userId:s.string().optional(),id:s.string()}),Xe=s.object({userId:s.string().optional()}),Qe=s.object({userId:s.string().optional(),id:s.string()}),et=s.object({userId:s.string().optional(),label:s.object({name:s.string().optional(),messageListVisibility:s.enum(["show","hide"]).optional(),labelListVisibility:s.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),color:s.object({textColor:s.string().optional(),backgroundColor:s.string().optional()}).optional()})}),tt=s.object({userId:s.string().optional(),id:s.string(),label:s.object({name:s.string().optional(),messageListVisibility:s.enum(["show","hide"]).optional(),labelListVisibility:s.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),color:s.object({textColor:s.string().optional(),backgroundColor:s.string().optional()}).optional()})}),st=s.object({userId:s.string().optional(),id:s.string()}),at=s.object({userId:s.string().optional(),maxResults:s.number().optional(),pageToken:s.string().optional(),q:s.string().optional()}),ot=s.object({userId:s.string().optional(),id:s.string(),format:s.enum(["minimal","full","raw","metadata"]).optional()}),it=s.object({userId:s.string().optional(),draft:s.object({message:s.object({raw:s.string().optional(),threadId:s.string().optional()}).optional()})}),nt=s.object({userId:s.string().optional(),id:s.string(),draft:s.object({message:s.object({raw:s.string().optional(),threadId:s.string().optional()}).optional()})}),rt=s.object({userId:s.string().optional(),id:s.string()}),dt=s.object({userId:s.string().optional(),id:s.string().optional(),message:s.object({raw:s.string().optional(),threadId:s.string().optional()}).optional()}),lt=s.object({userId:s.string().optional(),q:s.string().optional(),maxResults:s.number().optional(),pageToken:s.string().optional(),labelIds:s.array(s.string()).optional(),includeSpamTrash:s.boolean().optional()}),mt=s.object({userId:s.string().optional(),id:s.string(),format:s.enum(["minimal","full","metadata"]).optional(),metadataHeaders:s.array(s.string()).optional()}),pt=s.object({userId:s.string().optional(),id:s.string(),addLabelIds:s.array(s.string()).optional(),removeLabelIds:s.array(s.string()).optional()}),gt=s.object({userId:s.string().optional(),id:s.string()}),ct=s.object({userId:s.string().optional(),id:s.string()}),ut=s.object({userId:s.string().optional(),id:s.string()}),ht=s.object({userId:s.string().optional()}),u={messagesList:He,messagesGet:ze,messagesSend:Fe,messagesDelete:Ve,messagesModify:Ke,messagesBatchModify:Ye,messagesTrash:Ze,messagesUntrash:Je,labelsList:Xe,labelsGet:Qe,labelsCreate:et,labelsUpdate:tt,labelsDelete:st,draftsList:at,draftsGet:ot,draftsCreate:it,draftsUpdate:nt,draftsDelete:rt,draftsSend:dt,threadsList:lt,threadsGet:mt,threadsModify:pt,threadsDelete:gt,threadsTrash:ct,threadsUntrash:ut,usersGetProfile:ht},ft=s.object({name:s.string().optional(),value:s.string().optional()}),bt=s.object({attachmentId:s.string().optional(),size:s.number().optional(),data:s.string().optional()}),yt=s.object({partId:s.string().optional(),mimeType:s.string().optional(),filename:s.string().optional(),headers:s.array(ft).optional(),body:bt.optional()}),be=yt.extend({parts:s.lazy(()=>s.array(be).optional())}),E=s.object({id:s.string().optional(),threadId:s.string().optional(),labelIds:s.array(s.string()).optional(),snippet:s.string().optional(),historyId:s.string().optional(),internalDate:s.union([s.string(),s.number(),s.date()]).transform(e=>{if(e instanceof Date)return e;if(typeof e=="number")return new Date(e);if(typeof e=="string"){let t=Number(e);return isNaN(t)?null:new Date(t)}return null}).nullable().optional(),sizeEstimate:s.number().optional(),payload:be.optional(),raw:s.string().optional()}),Et=s.object({messages:s.array(E).optional(),nextPageToken:s.string().optional(),resultSizeEstimate:s.number().optional()}),Gt=s.object({textColor:s.string().optional(),backgroundColor:s.string().optional()}),x=s.object({id:s.string().optional(),name:s.string().optional(),messageListVisibility:s.enum(["show","hide"]).optional(),labelListVisibility:s.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),type:s.enum(["system","user"]).optional(),messagesTotal:s.number().optional(),messagesUnread:s.number().optional(),threadsTotal:s.number().optional(),threadsUnread:s.number().optional(),color:Gt.optional()}),It=s.object({labels:s.array(x).optional()}),R=s.object({id:s.string().optional(),message:E.optional()}),wt=s.object({drafts:s.array(R).optional(),nextPageToken:s.string().optional(),resultSizeEstimate:s.number().optional()}),P=s.object({id:s.string().optional(),snippet:s.string().optional(),historyId:s.string().optional(),messages:s.array(E).optional()}),Tt=s.object({threads:s.array(P).optional(),nextPageToken:s.string().optional(),resultSizeEstimate:s.number().optional()}),Mt=s.object({emailAddress:s.string().optional(),messagesTotal:s.number().optional(),threadsTotal:s.number().optional(),historyId:s.string().optional()}),h={messagesList:Et,messagesGet:E,messagesSend:E,messagesDelete:s.void(),messagesModify:E,messagesBatchModify:s.void(),messagesTrash:E,messagesUntrash:E,labelsList:It,labelsGet:x,labelsCreate:x,labelsUpdate:x,labelsDelete:s.void(),draftsList:wt,draftsGet:R,draftsCreate:R,draftsUpdate:R,draftsDelete:s.void(),draftsSend:E,threadsList:Tt,threadsGet:P,threadsModify:P,threadsDelete:s.void(),threadsTrash:P,threadsUntrash:P,usersGetProfile:Mt};var G={list:ae,get:oe,send:ie,delete:ne,modify:re,batchModify:de,trash:le,untrash:me},S={list:J,get:X,create:Q,update:ee,delete:te},w={list:z,get:F,create:V,update:K,delete:Y,send:Z},T={list:pe,get:ge,modify:ce,delete:ue,trash:he,untrash:fe};import{z as C}from"zod";import{z as r}from"zod";var Lt=r.object({name:r.string().optional(),value:r.string().optional()}),St=r.object({attachmentId:r.string().optional(),size:r.number().optional(),data:r.string().optional()}),ye=r.lazy(()=>r.object({partId:r.string().optional(),mimeType:r.string().optional(),filename:r.string().optional(),headers:r.array(Lt).optional(),body:St.optional(),parts:r.array(ye).optional()})),Ee=r.object({id:r.string(),threadId:r.string().optional(),labelIds:r.array(r.string()).optional(),snippet:r.string().optional(),historyId:r.string().optional(),internalDate:r.string().optional(),sizeEstimate:r.number().optional(),payload:ye.optional(),raw:r.string().optional(),subject:r.string().optional(),body:r.string().optional(),from:r.string().optional(),to:r.string().optional(),createdAt:r.coerce.date().nullable().optional()}),Ge=r.object({id:r.string(),name:r.string().optional(),messageListVisibility:r.enum(["show","hide"]).optional(),labelListVisibility:r.enum(["labelShow","labelShowIfUnread","labelHide"]).optional(),type:r.enum(["system","user"]).optional(),messagesTotal:r.number().optional(),messagesUnread:r.number().optional(),threadsTotal:r.number().optional(),threadsUnread:r.number().optional(),createdAt:r.coerce.date().nullable().optional()}),Ie=r.object({id:r.string(),messageId:r.string().optional(),createdAt:r.coerce.date().nullable().optional()}),we=r.object({id:r.string(),snippet:r.string().optional(),historyId:r.string().optional(),createdAt:r.coerce.date().nullable().optional()});var us=C.object({clientId:C.string(),clientSecret:C.string(),accessToken:C.string(),refreshToken:C.string()}),$={version:"1.0.0",entities:{messages:Ee,labels:Ge,drafts:Ie,threads:we}};import{logEventFromContext as D}from"corsair/core";import{z as l}from"zod";var kt=l.object({data:l.string().optional(),attributes:l.record(l.string(),l.string()).optional(),messageId:l.string().optional(),publishTime:l.string().optional()}),Te=l.object({message:kt.optional(),subscription:l.string().optional(),event:l.unknown().optional()}),bs=l.object({emailAddress:l.string().optional(),historyId:l.string().optional()}),vt=l.object({type:l.literal("messageReceived"),emailAddress:l.string(),historyId:l.string(),message:l.custom()}),Pt=l.object({type:l.literal("messageDeleted"),emailAddress:l.string(),historyId:l.string(),message:l.custom()}),Ct=l.object({type:l.literal("messageLabelChanged"),emailAddress:l.string(),historyId:l.string(),message:l.custom(),labelsAdded:l.array(l.string()).optional(),labelsRemoved:l.array(l.string()).optional()}),Me=l.union([vt,Pt,Ct]);function k(e){let t=Buffer.from(e,"base64").toString("utf-8");return JSON.parse(t)}function _(e){return t=>{let a=t.body;if(!a.message?.data)return!1;try{let o=k(a.message.data);return!!o.historyId&&!!o.emailAddress}catch{return!1}}}var Dt=100,xt=10,Rt=10;function N(e,t){return e?.headers?e.headers.find(o=>o.name?.toLowerCase()===t.toLowerCase())?.value:void 0}function At(e){if(e.payload)return N(e.payload,"Subject")}function Ot(e){if(e.payload)return N(e.payload,"From")}function jt(e){if(e.payload)return N(e.payload,"To")}function ke(e){if(!e)return;let t,a;if(e.body?.data)try{let o=Buffer.from(e.body.data,"base64").toString("utf-8");e.mimeType==="text/plain"?t=o:e.mimeType==="text/html"&&(a=o)}catch{}if(e.parts&&e.parts.length>0)for(let o of e.parts){let n=ke(o);n&&(o.mimeType==="text/plain"?t=n:o.mimeType==="text/html"&&!t&&(a=n))}return t||a}function Bt(e){if(e.payload)return ke(e.payload)}function Ut(e){let t=[],a=[],o=[];if(!e)return{added:t,deleted:a,modified:o};for(let n of e){if(n.messagesAdded)for(let i of n.messagesAdded)i.message?.id&&t.push(i.message.id);if(n.messagesDeleted)for(let i of n.messagesDeleted)i.message?.id&&a.push(i.message.id);if(n.labelsAdded||n.labelsRemoved){if(n.labelsAdded)for(let i of n.labelsAdded)i.message?.id&&o.push(i.message.id);if(n.labelsRemoved)for(let i of n.labelsRemoved)i.message?.id&&o.push(i.message.id)}}return{added:[...new Set(t)],deleted:[...new Set(a)],modified:[...new Set(o)]}}async function q(e,t,a){let[o,n]=await Promise.all([y(`/users/${t}/messages/${a}`,e,{method:"GET",query:{format:"full"}}),y(`/users/${t}/messages/${a}`,e,{method:"GET",query:{format:"raw"}}).catch(()=>null)]);return{...o,raw:n?.raw}}async function $t(e,t,a,o){return y(`/users/${t}/messages/${a}/attachments/${o}`,e,{method:"GET"})}async function ve(e,t,a){if(!a.payload)return a;let o=async i=>{if(!i)return i;if(i.body?.attachmentId)try{let d=await $t(e,t,a.id,i.body.attachmentId);return{...i,body:{...i.body,data:d.data,size:d.size}}}catch(d){return console.warn(`Failed to fetch attachment ${i.body.attachmentId} for message ${a.id}:`,d),i}if(i.parts&&i.parts.length>0){let d=await Promise.all(i.parts.map(o));return{...i,parts:d.filter(m=>m!==void 0)}}return i},n=await o(a.payload);return{...a,payload:n}}function _t(e){let t=Number(e);return t>1?String(t-1):e}async function Pe(e,t){return!e.db?.messages||!t.id?"":(await e.db.messages.upsertByEntityId(t.id,{...t,id:t.id,subject:At(t),body:Bt(t),from:Ot(t),to:jt(t),createdAt:new Date}))?.id??""}async function Nt(e,t,a,o){let n=await y(`/users/${a}/messages`,t,{method:"GET",query:{maxResults:xt}}),i=[],d=[];if(!n.messages?.length)return{added:i,modified:d};let m=Number(o);for(let p of n.messages)if(p.id)try{let g=await q(t,a,p.id);(g.historyId?Number(g.historyId):0)>=m-Rt&&(e.db?.messages&&await e.db.messages.findByEntityId(p.id)?d.push(p.id):i.push(p.id))}catch{}return{added:i,modified:d}}async function Le(e,t,a,o){let n=null,i="";for(let d of o)try{let m=await q(t,a,d),p=await ve(t,a,m);n||(n=p);try{let g=await Pe(e,p);!i&&g&&(i=g)}catch(g){throw console.error(`Failed to save message ${p.id} to database:`,g),g}}catch(m){console.warn(`Failed to process message ${d}:`,m)}return{message:n,corsairEntityId:i}}async function qt(e,t,a,o){let n=null,i="";if(!e.db?.messages)return{message:null,corsairEntityId:i};for(let d of o)try{let m=null;try{m=await y(`/users/${a}/messages/${d}`,t,{method:"GET",query:{format:"full"}})}catch(p){if(p?.statusCode===404)continue}if(!n&&m&&(n=m),!i){let p=await e.db.messages.findByEntityId(d);p&&(i=p.id)}await e.db.messages.deleteByEntityId(d)}catch(m){console.warn(`Failed to delete message ${d} from database:`,m)}return{message:n,corsairEntityId:i}}async function Se(e,t,a,o){let n=null,i="";if(!e.db?.messages)return{message:null,corsairEntityId:i};for(let d of o)try{let m=await q(t,a,d),p=await ve(t,a,m);n||(n=p);try{let g=await Pe(e,p);!i&&g&&(i=g)}catch(g){throw console.error(`Failed to update message ${p.id} in database:`,g),g}}catch(m){console.warn(`Failed to process message ${d}:`,m)}return{message:n,corsairEntityId:i}}var Ce={match:_("messageChanged"),handler:async(e,t)=>{let a=t.payload;if(!a.message?.data)return{success:!1,error:"No message data in notification"};let o=k(a.message.data);if(!o.historyId||!o.emailAddress)return{success:!1,error:"Invalid push notification format"};let n=e.key,i=o.emailAddress,d=o.historyId;try{let m=_t(d),p=await y(`/users/${i}/history`,n,{method:"GET",query:{startHistoryId:m,maxResults:Dt}}),{added:g,deleted:A,modified:O}=Ut(p.history);if(O.length>0){let f=await Se(e,n,i,O),b={type:"messageLabelChanged",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageLabelChanged",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}if(g.length>0){let f=await Le(e,n,i,g),b={type:"messageReceived",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageReceived",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}if(A.length>0){let f=await qt(e,n,i,A),b={type:"messageDeleted",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageDeleted",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}let{added:W,modified:H}=await Nt(e,n,i,d);if(H.length>0){let f=await Se(e,n,i,H),b={type:"messageLabelChanged",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageLabelChanged",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}if(W.length>0){let f=await Le(e,n,i,W),b={type:"messageReceived",emailAddress:i,historyId:d,message:f.message??{}};return await D(e,"gmail.webhook.messageReceived",{...b},"completed"),{success:!0,corsairEntityId:f.corsairEntityId,data:b}}return{success:!0,corsairEntityId:"",data:{type:"messageReceived",emailAddress:i,historyId:d,message:{}}}}catch(m){return console.error("Failed to process Gmail webhook:",m),{success:!1,error:`Failed to process message: ${m instanceof Error?m.message:"Unknown error"}`}}}};var De={messageChanged:Ce};var Wt={oauth_2:{integration:["topic_id"]}},Ht={messages:{list:G.list,get:G.get,send:G.send,delete:G.delete,modify:G.modify,batchModify:G.batchModify,trash:G.trash,untrash:G.untrash},labels:{list:S.list,get:S.get,create:S.create,update:S.update,delete:S.delete},drafts:{list:w.list,get:w.get,create:w.create,update:w.update,delete:w.delete,send:w.send},threads:{list:T.list,get:T.get,modify:T.modify,delete:T.delete,trash:T.trash,untrash:T.untrash}},zt={"messages.list":{input:u.messagesList,output:h.messagesList},"messages.get":{input:u.messagesGet,output:h.messagesGet},"messages.send":{input:u.messagesSend,output:h.messagesSend},"messages.delete":{input:u.messagesDelete,output:h.messagesDelete},"messages.modify":{input:u.messagesModify,output:h.messagesModify},"messages.batchModify":{input:u.messagesBatchModify,output:h.messagesBatchModify},"messages.trash":{input:u.messagesTrash,output:h.messagesTrash},"messages.untrash":{input:u.messagesUntrash,output:h.messagesUntrash},"labels.list":{input:u.labelsList,output:h.labelsList},"labels.get":{input:u.labelsGet,output:h.labelsGet},"labels.create":{input:u.labelsCreate,output:h.labelsCreate},"labels.update":{input:u.labelsUpdate,output:h.labelsUpdate},"labels.delete":{input:u.labelsDelete,output:h.labelsDelete},"drafts.list":{input:u.draftsList,output:h.draftsList},"drafts.get":{input:u.draftsGet,output:h.draftsGet},"drafts.create":{input:u.draftsCreate,output:h.draftsCreate},"drafts.update":{input:u.draftsUpdate,output:h.draftsUpdate},"drafts.delete":{input:u.draftsDelete,output:h.draftsDelete},"drafts.send":{input:u.draftsSend,output:h.draftsSend},"threads.list":{input:u.threadsList,output:h.threadsList},"threads.get":{input:u.threadsGet,output:h.threadsGet},"threads.modify":{input:u.threadsModify,output:h.threadsModify},"threads.delete":{input:u.threadsDelete,output:h.threadsDelete},"threads.trash":{input:u.threadsTrash,output:h.threadsTrash},"threads.untrash":{input:u.threadsUntrash,output:h.threadsUntrash}},Ft={messageChanged:De.messageChanged},Vt={messageChanged:{description:"A Gmail message was received, deleted, or had its labels changed",payload:Te,response:Me}},Kt="oauth_2",Yt={"messages.list":{riskLevel:"read",description:"List messages in a mailbox"},"messages.get":{riskLevel:"read",description:"Get a specific message"},"messages.send":{riskLevel:"write",description:"Send an email to one or more recipients"},"messages.delete":{riskLevel:"destructive",irreversible:!0,description:"Permanently delete a message [DESTRUCTIVE \xB7 IRREVERSIBLE]"},"messages.modify":{riskLevel:"write",description:"Add or remove labels from a message"},"messages.batchModify":{riskLevel:"write",description:"Add or remove labels from multiple messages in bulk"},"messages.trash":{riskLevel:"write",description:"Move a message to the trash"},"messages.untrash":{riskLevel:"write",description:"Restore a message from the trash"},"labels.list":{riskLevel:"read",description:"List all labels in the mailbox"},"labels.get":{riskLevel:"read",description:"Get a specific label"},"labels.create":{riskLevel:"write",description:"Create a new label"},"labels.update":{riskLevel:"write",description:"Update an existing label"},"labels.delete":{riskLevel:"destructive",description:"Delete a label [DESTRUCTIVE]"},"drafts.list":{riskLevel:"read",description:"List drafts in the mailbox"},"drafts.get":{riskLevel:"read",description:"Get a specific draft"},"drafts.create":{riskLevel:"write",description:"Create a new draft"},"drafts.update":{riskLevel:"write",description:"Update an existing draft"},"drafts.delete":{riskLevel:"destructive",description:"Delete a draft [DESTRUCTIVE]"},"drafts.send":{riskLevel:"write",description:"Send a draft as an email"},"threads.list":{riskLevel:"read",description:"List threads in the mailbox"},"threads.get":{riskLevel:"read",description:"Get a specific thread"},"threads.modify":{riskLevel:"write",description:"Add or remove labels from a thread"},"threads.delete":{riskLevel:"destructive",irreversible:!0,description:"Permanently delete a thread [DESTRUCTIVE \xB7 IRREVERSIBLE]"},"threads.trash":{riskLevel:"write",description:"Move a thread to the trash"},"threads.untrash":{riskLevel:"write",description:"Restore a thread from the trash"}};function xs(e={}){let t={...e,authType:e.authType??Kt};return{id:"gmail",schema:$,options:t,authConfig:Wt,oauthConfig:{providerName:"Google",authUrl:"https://accounts.google.com/o/oauth2/v2/auth",tokenUrl:"https://oauth2.googleapis.com/token",scopes:["https://www.googleapis.com/auth/gmail.modify","https://www.googleapis.com/auth/gmail.labels","https://www.googleapis.com/auth/gmail.send","https://www.googleapis.com/auth/gmail.compose"],authParams:{access_type:"offline",prompt:"consent"}},hooks:t.hooks,webhookHooks:t.webhookHooks,endpoints:Ht,webhooks:Ft,endpointMeta:Yt,endpointSchemas:zt,webhookSchemas:Vt,keyBuilder:async a=>{let o=a.authType;if(t.key)return t.key;if(a.authType==="oauth_2"){let[n,i,d]=await Promise.all([a.keys.get_access_token(),a.keys.get_expires_at(),a.keys.get_refresh_token()]);if(!d)throw new Error("[auth-missing:gmail:refresh_token]: Gmail refresh token is missing");let m=await a.keys.get_integration_credentials();if(!m.client_id||!m.client_secret)throw new Error("[auth-missing:gmail:client_credentials]: Gmail client credentials are missing");let p;try{p=await B({accessToken:n,expiresAt:i,refreshToken:d,clientId:m.client_id,clientSecret:m.client_secret})}catch(g){throw new Error(`[corsair:gmail] Failed to obtain valid access token: ${g instanceof Error?g.message:String(g)}`)}if(p.refreshed)try{await a.keys.set_access_token(p.accessToken),await a.keys.set_expires_at(String(p.expiresAt))}catch(g){throw new Error(`[corsair:gmail] Token was refreshed but failed to persist new credentials: ${g instanceof Error?g.message:String(g)}`)}return a._refreshAuth=async()=>{let g=await B({accessToken:null,expiresAt:null,refreshToken:d,clientId:m.client_id,clientSecret:m.client_secret,forceRefresh:!0});return await a.keys.set_access_token(g.accessToken),await a.keys.set_expires_at(String(g.expiresAt)),g.accessToken},p.accessToken}throw new Error(`[auth-missing:gmail:${o}]: Gmail key is missing`)},pluginWebhookMatcher:a=>{let o=a.headers;if(!(o.from==="noreply@google.com"||typeof o["user-agent"]=="string"&&o["user-agent"].includes("APIs-Google")))return!1;let i=a.body;if(!i?.message?.data)return!1;try{let d=k(i.message.data);return!!d.emailAddress&&!!d.historyId}catch{return!1}}}}export{$ as GmailSchema,_ as createGmailWebhookMatcher,k as decodePubSubMessage,xs as gmail,Wt as gmailAuthConfig,zt as gmailEndpointSchemas,Ht as gmailEndpointsNested,Ft as gmailWebhooksNested};
@@ -2,112 +2,52 @@ import { z } from 'zod';
2
2
  export declare const GmailMessage: z.ZodObject<{
3
3
  id: z.ZodString;
4
4
  threadId: z.ZodOptional<z.ZodString>;
5
- labelIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
5
+ labelIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
6
6
  snippet: z.ZodOptional<z.ZodString>;
7
7
  historyId: z.ZodOptional<z.ZodString>;
8
8
  internalDate: z.ZodOptional<z.ZodString>;
9
9
  sizeEstimate: z.ZodOptional<z.ZodNumber>;
10
- payload: z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>;
10
+ payload: z.ZodOptional<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>;
11
11
  raw: z.ZodOptional<z.ZodString>;
12
12
  subject: z.ZodOptional<z.ZodString>;
13
13
  body: z.ZodOptional<z.ZodString>;
14
14
  from: z.ZodOptional<z.ZodString>;
15
15
  to: z.ZodOptional<z.ZodString>;
16
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
17
- }, "strip", z.ZodTypeAny, {
18
- id: string;
19
- from?: string | undefined;
20
- body?: string | undefined;
21
- labelIds?: string[] | undefined;
22
- raw?: string | undefined;
23
- threadId?: string | undefined;
24
- snippet?: string | undefined;
25
- historyId?: string | undefined;
26
- internalDate?: string | undefined;
27
- sizeEstimate?: number | undefined;
28
- payload?: any;
29
- subject?: string | undefined;
30
- to?: string | undefined;
31
- createdAt?: Date | null | undefined;
32
- }, {
33
- id: string;
34
- from?: string | undefined;
35
- body?: string | undefined;
36
- labelIds?: string[] | undefined;
37
- raw?: string | undefined;
38
- threadId?: string | undefined;
39
- snippet?: string | undefined;
40
- historyId?: string | undefined;
41
- internalDate?: string | undefined;
42
- sizeEstimate?: number | undefined;
43
- payload?: any;
44
- subject?: string | undefined;
45
- to?: string | undefined;
46
- createdAt?: Date | null | undefined;
47
- }>;
16
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
17
+ }, z.core.$strip>;
48
18
  export declare const GmailLabel: z.ZodObject<{
49
19
  id: z.ZodString;
50
20
  name: z.ZodOptional<z.ZodString>;
51
- messageListVisibility: z.ZodOptional<z.ZodEnum<["show", "hide"]>>;
52
- labelListVisibility: z.ZodOptional<z.ZodEnum<["labelShow", "labelShowIfUnread", "labelHide"]>>;
53
- type: z.ZodOptional<z.ZodEnum<["system", "user"]>>;
21
+ messageListVisibility: z.ZodOptional<z.ZodEnum<{
22
+ show: "show";
23
+ hide: "hide";
24
+ }>>;
25
+ labelListVisibility: z.ZodOptional<z.ZodEnum<{
26
+ labelShow: "labelShow";
27
+ labelShowIfUnread: "labelShowIfUnread";
28
+ labelHide: "labelHide";
29
+ }>>;
30
+ type: z.ZodOptional<z.ZodEnum<{
31
+ system: "system";
32
+ user: "user";
33
+ }>>;
54
34
  messagesTotal: z.ZodOptional<z.ZodNumber>;
55
35
  messagesUnread: z.ZodOptional<z.ZodNumber>;
56
36
  threadsTotal: z.ZodOptional<z.ZodNumber>;
57
37
  threadsUnread: z.ZodOptional<z.ZodNumber>;
58
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
59
- }, "strip", z.ZodTypeAny, {
60
- id: string;
61
- type?: "system" | "user" | undefined;
62
- name?: string | undefined;
63
- messageListVisibility?: "show" | "hide" | undefined;
64
- labelListVisibility?: "labelShow" | "labelShowIfUnread" | "labelHide" | undefined;
65
- messagesTotal?: number | undefined;
66
- messagesUnread?: number | undefined;
67
- threadsTotal?: number | undefined;
68
- threadsUnread?: number | undefined;
69
- createdAt?: Date | null | undefined;
70
- }, {
71
- id: string;
72
- type?: "system" | "user" | undefined;
73
- name?: string | undefined;
74
- messageListVisibility?: "show" | "hide" | undefined;
75
- labelListVisibility?: "labelShow" | "labelShowIfUnread" | "labelHide" | undefined;
76
- messagesTotal?: number | undefined;
77
- messagesUnread?: number | undefined;
78
- threadsTotal?: number | undefined;
79
- threadsUnread?: number | undefined;
80
- createdAt?: Date | null | undefined;
81
- }>;
38
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
39
+ }, z.core.$strip>;
82
40
  export declare const GmailDraft: z.ZodObject<{
83
41
  id: z.ZodString;
84
42
  messageId: z.ZodOptional<z.ZodString>;
85
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
86
- }, "strip", z.ZodTypeAny, {
87
- id: string;
88
- createdAt?: Date | null | undefined;
89
- messageId?: string | undefined;
90
- }, {
91
- id: string;
92
- createdAt?: Date | null | undefined;
93
- messageId?: string | undefined;
94
- }>;
43
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
44
+ }, z.core.$strip>;
95
45
  export declare const GmailThread: z.ZodObject<{
96
46
  id: z.ZodString;
97
47
  snippet: z.ZodOptional<z.ZodString>;
98
48
  historyId: z.ZodOptional<z.ZodString>;
99
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
100
- }, "strip", z.ZodTypeAny, {
101
- id: string;
102
- snippet?: string | undefined;
103
- historyId?: string | undefined;
104
- createdAt?: Date | null | undefined;
105
- }, {
106
- id: string;
107
- snippet?: string | undefined;
108
- historyId?: string | undefined;
109
- createdAt?: Date | null | undefined;
110
- }>;
49
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
50
+ }, z.core.$strip>;
111
51
  export type GmailMessage = z.infer<typeof GmailMessage>;
112
52
  export type GmailLabel = z.infer<typeof GmailLabel>;
113
53
  export type GmailDraft = z.infer<typeof GmailDraft>;
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../schema/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwBxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAevB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAarB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;EAIrB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;EAKtB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../schema/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwBxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;iBAevB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;iBAarB,CAAC;AAEH,eAAO,MAAM,UAAU;;;;iBAIrB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;iBAKtB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -4,17 +4,7 @@ export declare const GmailCredentials: z.ZodObject<{
4
4
  clientSecret: z.ZodString;
5
5
  accessToken: z.ZodString;
6
6
  refreshToken: z.ZodString;
7
- }, "strip", z.ZodTypeAny, {
8
- accessToken: string;
9
- clientId: string;
10
- clientSecret: string;
11
- refreshToken: string;
12
- }, {
13
- accessToken: string;
14
- clientId: string;
15
- clientSecret: string;
16
- refreshToken: string;
17
- }>;
7
+ }, z.core.$strip>;
18
8
  export type GmailCredentials = z.infer<typeof GmailCredentials>;
19
9
  export declare const GmailSchema: {
20
10
  readonly version: "1.0.0";
@@ -22,112 +12,52 @@ export declare const GmailSchema: {
22
12
  readonly messages: z.ZodObject<{
23
13
  id: z.ZodString;
24
14
  threadId: z.ZodOptional<z.ZodString>;
25
- labelIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
15
+ labelIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
26
16
  snippet: z.ZodOptional<z.ZodString>;
27
17
  historyId: z.ZodOptional<z.ZodString>;
28
18
  internalDate: z.ZodOptional<z.ZodString>;
29
19
  sizeEstimate: z.ZodOptional<z.ZodNumber>;
30
- payload: z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>;
20
+ payload: z.ZodOptional<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>;
31
21
  raw: z.ZodOptional<z.ZodString>;
32
22
  subject: z.ZodOptional<z.ZodString>;
33
23
  body: z.ZodOptional<z.ZodString>;
34
24
  from: z.ZodOptional<z.ZodString>;
35
25
  to: z.ZodOptional<z.ZodString>;
36
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
37
- }, "strip", z.ZodTypeAny, {
38
- id: string;
39
- from?: string | undefined;
40
- body?: string | undefined;
41
- labelIds?: string[] | undefined;
42
- raw?: string | undefined;
43
- threadId?: string | undefined;
44
- snippet?: string | undefined;
45
- historyId?: string | undefined;
46
- internalDate?: string | undefined;
47
- sizeEstimate?: number | undefined;
48
- payload?: any;
49
- subject?: string | undefined;
50
- to?: string | undefined;
51
- createdAt?: Date | null | undefined;
52
- }, {
53
- id: string;
54
- from?: string | undefined;
55
- body?: string | undefined;
56
- labelIds?: string[] | undefined;
57
- raw?: string | undefined;
58
- threadId?: string | undefined;
59
- snippet?: string | undefined;
60
- historyId?: string | undefined;
61
- internalDate?: string | undefined;
62
- sizeEstimate?: number | undefined;
63
- payload?: any;
64
- subject?: string | undefined;
65
- to?: string | undefined;
66
- createdAt?: Date | null | undefined;
67
- }>;
26
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
27
+ }, z.core.$strip>;
68
28
  readonly labels: z.ZodObject<{
69
29
  id: z.ZodString;
70
30
  name: z.ZodOptional<z.ZodString>;
71
- messageListVisibility: z.ZodOptional<z.ZodEnum<["show", "hide"]>>;
72
- labelListVisibility: z.ZodOptional<z.ZodEnum<["labelShow", "labelShowIfUnread", "labelHide"]>>;
73
- type: z.ZodOptional<z.ZodEnum<["system", "user"]>>;
31
+ messageListVisibility: z.ZodOptional<z.ZodEnum<{
32
+ show: "show";
33
+ hide: "hide";
34
+ }>>;
35
+ labelListVisibility: z.ZodOptional<z.ZodEnum<{
36
+ labelShow: "labelShow";
37
+ labelShowIfUnread: "labelShowIfUnread";
38
+ labelHide: "labelHide";
39
+ }>>;
40
+ type: z.ZodOptional<z.ZodEnum<{
41
+ system: "system";
42
+ user: "user";
43
+ }>>;
74
44
  messagesTotal: z.ZodOptional<z.ZodNumber>;
75
45
  messagesUnread: z.ZodOptional<z.ZodNumber>;
76
46
  threadsTotal: z.ZodOptional<z.ZodNumber>;
77
47
  threadsUnread: z.ZodOptional<z.ZodNumber>;
78
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
79
- }, "strip", z.ZodTypeAny, {
80
- id: string;
81
- type?: "system" | "user" | undefined;
82
- name?: string | undefined;
83
- messageListVisibility?: "show" | "hide" | undefined;
84
- labelListVisibility?: "labelShow" | "labelShowIfUnread" | "labelHide" | undefined;
85
- messagesTotal?: number | undefined;
86
- messagesUnread?: number | undefined;
87
- threadsTotal?: number | undefined;
88
- threadsUnread?: number | undefined;
89
- createdAt?: Date | null | undefined;
90
- }, {
91
- id: string;
92
- type?: "system" | "user" | undefined;
93
- name?: string | undefined;
94
- messageListVisibility?: "show" | "hide" | undefined;
95
- labelListVisibility?: "labelShow" | "labelShowIfUnread" | "labelHide" | undefined;
96
- messagesTotal?: number | undefined;
97
- messagesUnread?: number | undefined;
98
- threadsTotal?: number | undefined;
99
- threadsUnread?: number | undefined;
100
- createdAt?: Date | null | undefined;
101
- }>;
48
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
49
+ }, z.core.$strip>;
102
50
  readonly drafts: z.ZodObject<{
103
51
  id: z.ZodString;
104
52
  messageId: z.ZodOptional<z.ZodString>;
105
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
106
- }, "strip", z.ZodTypeAny, {
107
- id: string;
108
- createdAt?: Date | null | undefined;
109
- messageId?: string | undefined;
110
- }, {
111
- id: string;
112
- createdAt?: Date | null | undefined;
113
- messageId?: string | undefined;
114
- }>;
53
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
54
+ }, z.core.$strip>;
115
55
  readonly threads: z.ZodObject<{
116
56
  id: z.ZodString;
117
57
  snippet: z.ZodOptional<z.ZodString>;
118
58
  historyId: z.ZodOptional<z.ZodString>;
119
- createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
120
- }, "strip", z.ZodTypeAny, {
121
- id: string;
122
- snippet?: string | undefined;
123
- historyId?: string | undefined;
124
- createdAt?: Date | null | undefined;
125
- }, {
126
- id: string;
127
- snippet?: string | undefined;
128
- historyId?: string | undefined;
129
- createdAt?: Date | null | undefined;
130
- }>;
59
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
60
+ }, z.core.$strip>;
131
61
  };
132
62
  };
133
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;EAK3B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQd,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,gBAAgB;;;;;iBAK3B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQd,CAAC"}
@@ -2,37 +2,37 @@ export declare const MessageWebhooks: {
2
2
  messageChanged: {
3
3
  match: import("corsair/core").CorsairWebhookMatcher;
4
4
  handler: import("corsair/core").CorsairWebhookHandler<import("..").GmailContext, import("./types").GmailWebhookPayload<{
5
- message: import("..").Message;
6
5
  type: "messageReceived";
7
- historyId: string;
8
6
  emailAddress: string;
9
- } | {
7
+ historyId: string;
10
8
  message: import("..").Message;
9
+ } | {
11
10
  type: "messageDeleted";
12
- historyId: string;
13
11
  emailAddress: string;
14
- } | {
12
+ historyId: string;
15
13
  message: import("..").Message;
14
+ } | {
16
15
  type: "messageLabelChanged";
17
- historyId: string;
18
16
  emailAddress: string;
17
+ historyId: string;
18
+ message: import("..").Message;
19
19
  labelsAdded?: string[] | undefined;
20
20
  labelsRemoved?: string[] | undefined;
21
21
  }>, {
22
- message: import("..").Message;
23
22
  type: "messageReceived";
24
- historyId: string;
25
23
  emailAddress: string;
26
- } | {
24
+ historyId: string;
27
25
  message: import("..").Message;
26
+ } | {
28
27
  type: "messageDeleted";
29
- historyId: string;
30
28
  emailAddress: string;
31
- } | {
29
+ historyId: string;
32
30
  message: import("..").Message;
31
+ } | {
33
32
  type: "messageLabelChanged";
34
- historyId: string;
35
33
  emailAddress: string;
34
+ historyId: string;
35
+ message: import("..").Message;
36
36
  labelsAdded?: string[] | undefined;
37
37
  labelsRemoved?: string[] | undefined;
38
38
  }>;