@bitblit/ratchet-misc 4.0.415-alpha → 4.0.416-alpha
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.
- package/lib/index.mjs +1 -1
- package/package.json +3 -3
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ErrorRatchet as e,Logger as t,NumberRatchet as n,StringRatchet as a,MapRatchet as i,TimeoutToken as s}from"@bitblit/ratchet-common";import r from"handlebars";import o from"cross-fetch";import c from"handlebars-layouts";import u from"swagger-model-validator";import l from"js-yaml";import{race as d,Observable as m}from"rxjs";class p{brevo;constructor(e){this.brevo=e}async sendEmail(n){try{const t=await this.brevo.smtpApi();if(n?.attachments?.length)throw e.fErr("Cannot send email with attachments yet, not supported");const a={subject:n.subject,htmlContent:n.htmlMessage,sender:{name:n.fromName,email:n.fromAddress||"a@a.com"},to:(n.destinationAddresses||[]).map((e=>({email:e}))),bcc:n?.bccAddresses?.length?n.bccAddresses.map((e=>({email:e}))):void 0};return await t.sendTransacEmail({sendSmtpEmail:a})}catch(e){throw t.error("Failed to send email: %s",e,e),e}}}const f="https://api.sendinblue.com/v3".replace(/\/+$/,"");class h{configuration;constructor(e={}){this.configuration=e}set config(e){this.configuration=e}get basePath(){return null!=this.configuration.basePath?this.configuration.basePath:f}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||q}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const e=this.configuration.apiKey;if(e)return"function"==typeof e?e:()=>e}get accessToken(){const e=this.configuration.accessToken;if(e)return"function"==typeof e?e:async()=>e}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const g=new h;class w{configuration;static jsonRegex=new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$","i");middleware;constructor(e=g){this.configuration=e,this.middleware=e.middleware}withMiddleware(...e){const t=this.clone();return t.middleware=t.middleware.concat(...e),t}withPreMiddleware(...e){const t=e.map((e=>({pre:e})));return this.withMiddleware(...t)}withPostMiddleware(...e){const t=e.map((e=>({post:e})));return this.withMiddleware(...t)}isJsonMime(e){return!!e&&w.jsonRegex.test(e)}async request(e,t){const{url:n,init:a}=await this.createFetchParams(e,t),i=await this.fetchApi(n,a);if(i&&i.status>=200&&i.status<300)return i;throw new y(i,"Response returned an error code")}async createFetchParams(e,t){let n=this.configuration.basePath+e.path;void 0!==e.query&&0!==Object.keys(e.query).length&&(n+="?"+this.configuration.queryParamsStringify(e.query));const a=Object.assign({},this.configuration.headers,e.headers);Object.keys(a).forEach((e=>void 0===a[e]?delete a[e]:{}));const i="function"==typeof t?t:async()=>t,s={method:e.method,headers:a,body:e.body,credentials:this.configuration.credentials},r={...s,...await i({init:s,context:e})};let o;var c;c=r.body,o="undefined"!=typeof FormData&&c instanceof FormData||r.body instanceof URLSearchParams||function(e){return"undefined"!=typeof Blob&&e instanceof Blob}(r.body)?r.body:this.isJsonMime(a["Content-Type"])?JSON.stringify(r.body):r.body;return{url:n,init:{...r,body:o}}}fetchApi=async(e,t)=>{let n,a={url:e,init:t};for(const e of this.middleware)e.pre&&(a=await e.pre({fetch:this.fetchApi,...a})||a);try{n=await(this.configuration.fetchApi||fetch)(a.url,a.init)}catch(e){for(const t of this.middleware)t.onError&&(n=await t.onError({fetch:this.fetchApi,url:a.url,init:a.init,error:e,response:n?n.clone():void 0})||n);if(void 0===n)throw e instanceof Error?new b(e,"The request failed and the interceptors did not return an alternative response"):e}for(const e of this.middleware)e.post&&(n=await e.post({fetch:this.fetchApi,url:a.url,init:a.init,response:n.clone()})||n);return n};clone(){const e=new(0,this.constructor)(this.configuration);return e.middleware=this.middleware.slice(),e}}class y extends Error{response;name="ResponseError";constructor(e,t){super(t),this.response=e}}class b extends Error{cause;name="FetchError";constructor(e,t){super(t),this.cause=e}}class v extends Error{field;name="RequiredError";constructor(e,t){super(t),this.field=e}}const T=",";function k(e,t){const n=e[t];return null!=n}function q(e,t=""){return Object.keys(e).map((n=>D(n,e[n],t))).filter((e=>e.length>0)).join("&")}function D(e,t,n=""){const a=n+(n.length?`[${e}]`:e);if(t instanceof Array){const e=t.map((e=>encodeURIComponent(String(e)))).join(`&${encodeURIComponent(a)}=`);return`${encodeURIComponent(a)}=${e}`}if(t instanceof Set){return D(e,Array.from(t),n)}return t instanceof Date?`${encodeURIComponent(a)}=${encodeURIComponent(t.toISOString())}`:t instanceof Object?q(t,a):`${encodeURIComponent(a)}=${encodeURIComponent(String(t))}`}class S{raw;transformer;constructor(e,t=(e=>e)){this.raw=e,this.transformer=t}async value(){return this.transformer(await this.raw.json())}}class C{raw;constructor(e){this.raw=e}async value(){}}var I,R,E,A,B,P,O,j,N,U,K,x,M,L,F,_,H,G,V,$,Q,z,J,Y,W,X,Z,ee,te,ne,ae,ie,se,re,oe,ce,ue,le,de,me,pe;function fe(e){if(void 0!==e)return null===e?null:{domain:e.domain}}function he(e){return function(e,t){if(null==e)return e;return{id:e.id}}(e)}function ge(e){return function(e,t){if(null==e)return e;return{messageId:e.messageId}}(e)}function we(e){if(void 0!==e)return null===e?null:{name:e.name,email:e.email,id:e.id}}function ye(e){if(void 0!==e)return null===e?null:{tag:e.tag,sender:we(e.sender),templateName:e.templateName,htmlContent:e.htmlContent,htmlUrl:e.htmlUrl,subject:e.subject,replyTo:e.replyTo,toField:e.toField,attachmentUrl:e.attachmentUrl,isActive:e.isActive}}function be(e){if(void 0!==e)return null===e?null:{startDate:e.startDate,endDate:e.endDate,contactEmail:e.contactEmail}}function ve(e){return function(e,t){if(null==e)return e;return{key:k(e,"key")?e.key:void 0,enabled:e.enabled}}(e)}function Te(e){return function(e,t){if(null==e)return e;return{type:e.type,creditsType:e.creditsType,credits:e.credits,startDate:k(e,"startDate")?new Date(e.startDate):void 0,endDate:k(e,"endDate")?new Date(e.endDate):void 0,userLimit:k(e,"userLimit")?e.userLimit:void 0}}(e)}function ke(e){return function(e,t){if(null==e)return e;return{userName:e.userName,relay:e.relay,port:e.port}}(e)}function qe(e){return function(e,t){if(null==e)return e;return{enabled:e.enabled,data:ke(e.data)}}(e)}function De(e){return function(e,t){if(null==e)return e;return{street:e.street,city:e.city,zipCode:e.zipCode,country:e.country}}(e)}function Se(e){return function(e,t){if(null==e)return e;return{email:e.email,firstName:e.firstName,lastName:e.lastName,companyName:e.companyName,address:De(e.address),plan:e.plan.map(Te),relay:qe(e.relay),marketingAutomation:k(e,"marketingAutomation")?ve(e.marketingAutomation):void 0}}(e)}function Ce(e){return function(e,t){if(null==e)return e;return{range:e.range,requests:e.requests,delivered:e.delivered,hardBounces:e.hardBounces,softBounces:e.softBounces,clicks:e.clicks,uniqueClicks:e.uniqueClicks,opens:e.opens,uniqueOpens:e.uniqueOpens,spamReports:e.spamReports,blocked:e.blocked,invalid:e.invalid,unsubscribed:e.unsubscribed}}(e)}function Ie(e){return function(e,t){if(null==e)return e;return{domains:e.domains}}(e)}function Re(e){return function(e,t){if(null==e)return e;return{email:e.email,date:new Date(e.date),subject:k(e,"subject")?e.subject:void 0,messageId:e.messageId,event:e.event,reason:k(e,"reason")?e.reason:void 0,tag:k(e,"tag")?e.tag:void 0,ip:k(e,"ip")?e.ip:void 0,link:k(e,"link")?e.link:void 0,from:k(e,"from")?e.from:void 0}}(e)}function Ee(e){return function(e,t){if(null==e)return e;return{events:k(e,"events")?e.events.map(Re):void 0}}(e)}function Ae(e){return function(e,t){if(null==e)return e;return{date:new Date(e.date),requests:e.requests,delivered:e.delivered,hardBounces:e.hardBounces,softBounces:e.softBounces,clicks:e.clicks,uniqueClicks:e.uniqueClicks,opens:e.opens,uniqueOpens:e.uniqueOpens,spamReports:e.spamReports,blocked:e.blocked,invalid:e.invalid,unsubscribed:e.unsubscribed}}(e)}function Be(e){return function(e,t){if(null==e)return e;return{reports:k(e,"reports")?e.reports.map(Ae):void 0}}(e)}function Pe(e){return function(e,t){if(null==e)return e;return{name:k(e,"name")?e.name:void 0,email:k(e,"email")?e.email:void 0,id:k(e,"id")?e.id:void 0}}(e)}function Oe(e){return function(e,t){if(null==e)return e;return{id:e.id,name:e.name,subject:e.subject,isActive:e.isActive,testSent:e.testSent,sender:Pe(e.sender),replyTo:e.replyTo,toField:e.toField,tag:e.tag,htmlContent:e.htmlContent,createdAt:new Date(e.createdAt),modifiedAt:new Date(e.modifiedAt),doiTemplate:k(e,"doiTemplate")?e.doiTemplate:void 0}}(e)}function je(e){return function(e,t){if(null==e)return e;return{count:k(e,"count")?e.count:void 0,templates:k(e,"templates")?e.templates.map(Oe):void 0}}(e)}function Ne(e){return function(e,t){if(null==e)return e;return{code:k(e,"code")?e.code:void 0,message:k(e,"message")?e.message:void 0}}(e)}function Ue(e){return function(e,t){if(null==e)return e;return{email:e.email,senderEmail:e.senderEmail,reason:Ne(e.reason),blockedAt:new Date(e.blockedAt)}}(e)}function Ke(e){return function(e,t){if(null==e)return e;return{count:k(e,"count")?e.count:void 0,contacts:k(e,"contacts")?e.contacts.map(Ue):void 0}}(e)}function xe(e){return function(e,t){if(null==e)return e;return{name:e.name,time:new Date(e.time)}}(e)}function Me(e){return function(e,t){if(null==e)return e;return{email:e.email,subject:e.subject,templateId:k(e,"templateId")?e.templateId:void 0,date:new Date(e.date),events:e.events.map(xe),body:e.body,attachmentCount:e.attachmentCount}}(e)}function Le(e){return function(e,t){if(null==e)return e;return{email:e.email,subject:e.subject,templateId:k(e,"templateId")?e.templateId:void 0,messageId:e.messageId,uuid:e.uuid,date:new Date(e.date),from:k(e,"from")?e.from:void 0,tags:k(e,"tags")?e.tags:void 0}}(e)}function Fe(e){return function(e,t){if(null==e)return e;return{transactionalEmails:k(e,"transactionalEmails")?e.transactionalEmails.map(Le):void 0}}(e)}function _e(e){if(void 0!==e)return null===e?null:{content:e.content,name:e.name}}function He(e){if(void 0!==e)return null===e?null:{emailTo:e.emailTo,emailBcc:e.emailBcc,emailCc:e.emailCc,replyTo:e.replyTo,attachmentUrl:e.attachmentUrl,attachment:void 0===e.attachment?void 0:e.attachment.map(_e),headers:e.headers,attributes:e.attributes,tags:e.tags}}function Ge(e){if(void 0!==e)return null===e?null:{url:e.url,content:e.content,name:e.name}}function Ve(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function $e(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function Qe(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function ze(e){if(void 0!==e)return null===e?null:{name:e.name,email:e.email}}function Je(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function Ye(e){if(void 0!==e)return null===e?null:{sender:ze(e.sender),to:e.to.map(Je),bcc:void 0===e.bcc?void 0:e.bcc.map(Ve),cc:void 0===e.cc?void 0:e.cc.map($e),htmlContent:e.htmlContent,textContent:e.textContent,subject:e.subject,replyTo:Qe(e.replyTo),attachment:void 0===e.attachment?void 0:e.attachment.map(Ge),headers:e.headers,templateId:e.templateId,params:e.params,tags:e.tags}}function We(e){return function(e,t){if(null==e)return e;return{messageId:e.messageId}}(e)}function Xe(e){if(void 0!==e)return null===e?null:{emailTo:e.emailTo}}function Ze(e){if(void 0!==e)return null===e?null:{name:e.name,email:e.email,id:e.id}}function et(e){if(void 0!==e)return null===e?null:{tag:e.tag,sender:Ze(e.sender),templateName:e.templateName,htmlContent:e.htmlContent,htmlUrl:e.htmlUrl,subject:e.subject,replyTo:e.replyTo,toField:e.toField,attachmentUrl:e.attachmentUrl,isActive:e.isActive}}!function(e){e.NotAvailable="notAvailable",e.Pending="pending",e.Tie="tie",e.A="A",e.B="B"}(I||(I={})),function(e){e.Open="Open",e.Click="Click"}(R||(R={})),function(e){e.Text="text",e.Date="date",e.Float="float",e.Boolean="boolean",e.Id="id",e.Category="category"}(E||(E={})),function(e){e.Fr="fr",e.Es="es",e.Pt="pt",e.It="it",e.De="de",e.En="en"}(A||(A={})),function(e){e.Open="open",e.Click="click"}(B||(B={})),function(e){e.Sent="sent",e.HardBounce="hardBounce",e.SoftBounce="softBounce",e.Blocked="blocked",e.Spam="spam",e.Delivered="delivered",e.Request="request",e.Click="click",e.Invalid="invalid",e.Deferred="deferred",e.Opened="opened",e.UniqueOpened="uniqueOpened",e.Unsubscribed="unsubscribed",e.ListAddition="listAddition",e.ContactUpdated="contactUpdated",e.ContactDeleted="contactDeleted"}(P||(P={})),function(e){e.Transactional="transactional",e.Marketing="marketing"}(O||(O={})),function(e){e.All="all",e.NonClickers="nonClickers",e.NonOpeners="nonOpeners",e.Clickers="clickers",e.Openers="openers",e.SoftBounces="softBounces",e.HardBounces="hardBounces",e.Unsubscribed="unsubscribed"}(j||(j={})),function(e){e.InvalidParameter="invalid_parameter",e.MissingParameter="missing_parameter",e.OutOfRange="out_of_range",e.CampaignProcessing="campaign_processing",e.CampaignSent="campaign_sent",e.DocumentNotFound="document_not_found",e.ResellerPermissionDenied="reseller_permission_denied",e.NotEnoughCredits="not_enough_credits",e.PermissionDenied="permission_denied",e.DuplicateParameter="duplicate_parameter",e.DuplicateRequest="duplicate_request",e.MethodNotAllowed="method_not_allowed",e.Unauthorized="unauthorized",e.AccountUnderValidation="account_under_validation",e.NotAcceptable="not_acceptable"}(N||(N={})),function(e){e.PayAsYouGo="payAsYouGo",e.Free="free",e.Subscription="subscription",e.Sms="sms",e.Reseller="reseller"}(U||(U={})),function(e){e.SendLimit="sendLimit"}(K||(K={})),function(e){e.Normal="normal",e.Transactional="transactional",e.Category="category",e.Calculated="calculated",e.Global="global"}(x||(x={})),function(e){e.Text="text",e.Date="date",e.Float="float",e.Id="id",e.Boolean="boolean"}(M||(M={})),function(e){e.Classic="classic",e.Trigger="trigger"}(L||(L={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(F||(F={})),function(e){e.Classic="classic",e.Trigger="trigger"}(_||(_={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(H||(H={})),function(e){e.Classic="classic",e.Trigger="trigger"}(G||(G={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(V||(V={})),function(e){e.Bounces="bounces",e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Delivered="delivered",e.Spam="spam",e.Requests="requests",e.Opened="opened",e.Clicks="clicks",e.Invalid="invalid",e.Deferred="deferred",e.Blocked="blocked",e.Unsubscribed="unsubscribed"}($||($={})),function(e){e.Classic="classic",e.Trigger="trigger"}(Q||(Q={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(z||(z={})),function(e){e.Queued="queued",e.InProcess="in_process",e.Completed="completed"}(J||(J={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="inProcess"}(Y||(Y={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="inProcess"}(W||(W={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="inProcess"}(X||(X={})),function(e){e.Bounces="bounces",e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Delivered="delivered",e.Sent="sent",e.Accepted="accepted",e.Unsubscription="unsubscription",e.Replies="replies",e.Blocked="blocked",e.Rejected="rejected"}(Z||(Z={})),function(e){e.UnsubscribedViaMa="unsubscribedViaMA",e.UnsubscribedViaEmail="unsubscribedViaEmail",e.AdminBlocked="adminBlocked",e.UnsubscribedViaApi="unsubscribedViaApi",e.HardBounce="hardBounce",e.ContactFlaggedAsSpam="contactFlaggedAsSpam"}(ee||(ee={})),function(e){e.Marketing="marketing",e.Transac="transac"}(te||(te={})),function(e){e.Draft="draft",e.Scheduled="scheduled",e.Pending="pending",e.Approved="approved",e.Running="running",e.Suspended="suspended",e.Rejected="rejected",e.Sent="sent"}(ne||(ne={})),function(e){e.Draft="draft",e.Scheduled="scheduled",e.Pending="pending",e.Approved="approved",e.Running="running",e.Suspended="suspended",e.Rejected="rejected",e.Sent="sent"}(ae||(ae={})),function(e){e.AllContacts="allContacts",e.Subscribed="subscribed",e.Unsubscribed="unsubscribed",e.UnsubscribedPerList="unsubscribedPerList"}(ie||(ie={})),function(e){e.Openers="openers",e.NonOpeners="nonOpeners",e.Clickers="clickers",e.NonClickers="nonClickers",e.Unsubscribed="unsubscribed",e.HardBounces="hardBounces",e.SoftBounces="softBounces"}(se||(se={})),function(e){e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Unsubscribed="unsubscribed"}(re||(re={})),function(e){e.All="all",e.Delivered="delivered",e.Answered="answered",e.SoftBounces="softBounces",e.HardBounces="hardBounces",e.Unsubscribed="unsubscribed"}(oe||(oe={})),function(e){e.Fr="fr",e.Es="es",e.Pt="pt",e.It="it",e.De="de",e.En="en"}(ce||(ce={})),function(e){e.Transactional="transactional",e.Marketing="marketing"}(ue||(ue={})),function(e){e.Suspended="suspended",e.Archive="archive",e.Darchive="darchive",e.Sent="sent",e.Queued="queued",e.Replicate="replicate",e.ReplicateTemplate="replicateTemplate",e.Draft="draft"}(le||(le={})),function(e){e.Open="open",e.Click="click"}(de||(de={})),function(e){e.HardBounce="hardBounce",e.SoftBounce="softBounce",e.Blocked="blocked",e.Spam="spam",e.Delivered="delivered",e.Request="request",e.Click="click",e.Invalid="invalid",e.Deferred="deferred",e.Opened="opened",e.UniqueOpened="uniqueOpened",e.Unsubscribed="unsubscribed",e.ListAddition="listAddition",e.ContactUpdated="contactUpdated",e.ContactDeleted="contactDeleted"}(me||(me={}));class tt extends w{async getAccountRaw(e){const t={};this.configuration&&this.configuration.apiKey&&(t["api-key"]=await this.configuration.apiKey("api-key"));const n=await this.request({path:"/account",method:"GET",headers:t,query:{}},e);return new S(n,(e=>Se(e)))}async getAccount(e){const t=await this.getAccountRaw(e);return await t.value()}}class nt extends w{async blockNewDomainRaw(e,t){if(null===e.blockDomain||void 0===e.blockDomain)throw new v("blockDomain","Required parameter requestParameters.blockDomain was null or undefined when calling blockNewDomain.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/blockedDomains",method:"POST",headers:n,query:{},body:fe(e.blockDomain)},t);return new C(a)}async blockNewDomain(e,t){await this.blockNewDomainRaw(e,t)}async createSmtpTemplateRaw(e,t){if(null===e.smtpTemplate||void 0===e.smtpTemplate)throw new v("smtpTemplate","Required parameter requestParameters.smtpTemplate was null or undefined when calling createSmtpTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates",method:"POST",headers:n,query:{},body:ye(e.smtpTemplate)},t);return new S(a,(e=>he(e)))}async createSmtpTemplate(e,t){const n=await this.createSmtpTemplateRaw(e,t);return await n.value()}async deleteBlockedDomainRaw(e,t){if(null===e.domain||void 0===e.domain)throw new v("domain","Required parameter requestParameters.domain was null or undefined when calling deleteBlockedDomain.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/blockedDomains/{domain}".replace("{domain}",encodeURIComponent(String(e.domain))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async deleteBlockedDomain(e,t){await this.deleteBlockedDomainRaw(e,t)}async deleteHardbouncesRaw(e,t){const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/deleteHardbounces",method:"POST",headers:n,query:{},body:be(e.deleteHardbounces)},t);return new C(a)}async deleteHardbounces(e={},t){await this.deleteHardbouncesRaw(e,t)}async deleteSmtpTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling deleteSmtpTemplate.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async deleteSmtpTemplate(e,t){await this.deleteSmtpTemplateRaw(e,t)}async getAggregatedSmtpReportRaw(e,t){const n={};void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.days&&(n.days=e.days),void 0!==e.tag&&(n.tag=e.tag);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/statistics/aggregatedReport",method:"GET",headers:a,query:n},t);return new S(i,(e=>Ce(e)))}async getAggregatedSmtpReport(e={},t){const n=await this.getAggregatedSmtpReportRaw(e,t);return await n.value()}async getBlockedDomainsRaw(e){const t={};this.configuration&&this.configuration.apiKey&&(t["api-key"]=await this.configuration.apiKey("api-key"));const n=await this.request({path:"/smtp/blockedDomains",method:"GET",headers:t,query:{}},e);return new S(n,(e=>Ie(e)))}async getBlockedDomains(e){const t=await this.getBlockedDomainsRaw(e);return await t.value()}async getEmailEventReportRaw(e,t){const n={};void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.days&&(n.days=e.days),void 0!==e.email&&(n.email=e.email),void 0!==e.event&&(n.event=e.event),void 0!==e.tags&&(n.tags=e.tags),void 0!==e.messageId&&(n.messageId=e.messageId),void 0!==e.templateId&&(n.templateId=e.templateId);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/statistics/events",method:"GET",headers:a,query:n},t);return new S(i,(e=>Ee(e)))}async getEmailEventReport(e={},t){const n=await this.getEmailEventReportRaw(e,t);return await n.value()}async getSmtpReportRaw(e,t){const n={};void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.days&&(n.days=e.days),void 0!==e.tag&&(n.tag=e.tag);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/statistics/reports",method:"GET",headers:a,query:n},t);return new S(i,(e=>Be(e)))}async getSmtpReport(e={},t){const n=await this.getSmtpReportRaw(e,t);return await n.value()}async getSmtpTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling getSmtpTemplate.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"GET",headers:n,query:{}},t);return new S(a,(e=>Oe(e)))}async getSmtpTemplate(e,t){const n=await this.getSmtpTemplateRaw(e,t);return await n.value()}async getSmtpTemplatesRaw(e,t){const n={};void 0!==e.templateStatus&&(n.templateStatus=e.templateStatus),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/templates",method:"GET",headers:a,query:n},t);return new S(i,(e=>je(e)))}async getSmtpTemplates(e={},t){const n=await this.getSmtpTemplatesRaw(e,t);return await n.value()}async getTransacBlockedContactsRaw(e,t){const n={};void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),e.senders&&(n.senders=e.senders.join(T));const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/blockedContacts",method:"GET",headers:a,query:n},t);return new S(i,(e=>Ke(e)))}async getTransacBlockedContacts(e={},t){const n=await this.getTransacBlockedContactsRaw(e,t);return await n.value()}async getTransacEmailContentRaw(e,t){if(null===e.uuid||void 0===e.uuid)throw new v("uuid","Required parameter requestParameters.uuid was null or undefined when calling getTransacEmailContent.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/emails/{uuid}".replace("{uuid}",encodeURIComponent(String(e.uuid))),method:"GET",headers:n,query:{}},t);return new S(a,(e=>Me(e)))}async getTransacEmailContent(e,t){const n=await this.getTransacEmailContentRaw(e,t);return await n.value()}async getTransacEmailsListRaw(e,t){const n={};void 0!==e.email&&(n.email=e.email),void 0!==e.templateId&&(n.templateId=e.templateId),void 0!==e.messageId&&(n.messageId=e.messageId),void 0!==e.startDate&&(n.startDate=e.startDate.toISOString().substring(0,10)),void 0!==e.endDate&&(n.endDate=e.endDate.toISOString().substring(0,10));const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/emails",method:"GET",headers:a,query:n},t);return new S(i,(e=>Fe(e)))}async getTransacEmailsList(e={},t){const n=await this.getTransacEmailsListRaw(e,t);return await n.value()}async sendTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling sendTemplate.");if(null===e.sendEmail||void 0===e.sendEmail)throw new v("sendEmail","Required parameter requestParameters.sendEmail was null or undefined when calling sendTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}/send".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"POST",headers:n,query:{},body:He(e.sendEmail)},t);return new S(a,(e=>We(e)))}async sendTemplate(e,t){const n=await this.sendTemplateRaw(e,t);return await n.value()}async sendTestTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling sendTestTemplate.");if(null===e.sendTestEmail||void 0===e.sendTestEmail)throw new v("sendTestEmail","Required parameter requestParameters.sendTestEmail was null or undefined when calling sendTestTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}/sendTest".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"POST",headers:n,query:{},body:Xe(e.sendTestEmail)},t);return new C(a)}async sendTestTemplate(e,t){await this.sendTestTemplateRaw(e,t)}async sendTransacEmailRaw(e,t){if(null===e.sendSmtpEmail||void 0===e.sendSmtpEmail)throw new v("sendSmtpEmail","Required parameter requestParameters.sendSmtpEmail was null or undefined when calling sendTransacEmail.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/email",method:"POST",headers:n,query:{},body:Ye(e.sendSmtpEmail)},t);return new S(a,(e=>ge(e)))}async sendTransacEmail(e,t){const n=await this.sendTransacEmailRaw(e,t);return await n.value()}async smtpBlockedContactsEmailDeleteRaw(e,t){if(null===e.email||void 0===e.email)throw new v("email","Required parameter requestParameters.email was null or undefined when calling smtpBlockedContactsEmailDelete.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/blockedContacts/{email}".replace("{email}",encodeURIComponent(String(e.email))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async smtpBlockedContactsEmailDelete(e,t){await this.smtpBlockedContactsEmailDeleteRaw(e,t)}async smtpLogMessageIdDeleteRaw(e,t){if(null===e.messageId||void 0===e.messageId)throw new v("messageId","Required parameter requestParameters.messageId was null or undefined when calling smtpLogMessageIdDelete.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/log/{messageId}".replace("{messageId}",encodeURIComponent(String(e.messageId))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async smtpLogMessageIdDelete(e,t){await this.smtpLogMessageIdDeleteRaw(e,t)}async updateSmtpTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling updateSmtpTemplate.");if(null===e.smtpTemplate||void 0===e.smtpTemplate)throw new v("smtpTemplate","Required parameter requestParameters.smtpTemplate was null or undefined when calling updateSmtpTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"PUT",headers:n,query:{},body:et(e.smtpTemplate)},t);return new C(a)}async updateSmtpTemplate(e,t){await this.updateSmtpTemplateRaw(e,t)}}!function(e){e.Bounces="bounces",e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Delivered="delivered",e.Spam="spam",e.Requests="requests",e.Opened="opened",e.Clicks="clicks",e.Invalid="invalid",e.Deferred="deferred",e.Blocked="blocked",e.Unsubscribed="unsubscribed"}(pe||(pe={}));class at{keys;configParamTemplate;constructor(e,t){this.keys=e,this.configParamTemplate=t}async buildConfig(){const e=await this.keys,n=this.configParamTemplate?Object.assign({},this.configParamTemplate):{},a={pre:async e=>{t.silly("Context: %j",e)}};return n.apiKey=e.apiKey,n.middleware=[a],n}async accountApi(){const e=await this.buildConfig();return new tt(new h(e))}async smtpApi(){const e=await this.buildConfig();return new nt(new h(e))}async fetchAccountData(){const e=await this.accountApi();return await e.getAccount()}}class it{constructor(){}static buildInformation(){return{version:"415",hash:"43b8898fca427e6952399e7dfd5c58cf8e8177c0",branch:"alpha-2024-07-12-1",tag:"alpha-2024-07-12-1",timeBuiltISO:"2024-07-12T16:42:20-0700",notes:"No notes"}}}class st{constructor(){}static functionMap(){return{eq:st.equal,ne:st.notEqual,lt:st.lessThan,gt:st.greaterThan,lte:st.lessThanEqual,gte:st.greaterThanEqual,and:st.and,or:st.or,formatBytes:st.formatBytes,rpn:st.reversePolishNotation,add:st.add,sub:st.sub,mul:st.mul,div:st.div,mod:st.mod,maxNum:st.maxNum,minNum:st.minNum}}static registerAll(e){e.registerHelper(st.functionMap())}static add(e,t){return n.safeNumber(e)+n.safeNumber(t)}static sub(e,t){return n.safeNumber(e)-n.safeNumber(t)}static mul(e,t){return n.safeNumber(e)*n.safeNumber(t)}static div(e,t){return n.safeNumber(e)/n.safeNumber(t)}static mod(e,t){return n.safeNumber(e)%n.safeNumber(t)}static equal(e,t){return e===t}static notEqual(e,t){return e!==t}static lessThan(e,t){return e<t}static lessThanEqual(e,t){return e<=t}static greaterThan(e,t){return e>t}static greaterThanEqual(e,t){return e>=t}static maxNum(...e){return Math.max(...e.slice(0,-1))}static minNum(...e){return Math.min(...e.slice(0,-1))}static and(...e){return Array.prototype.every.call(e,Boolean)}static or(...e){return Array.prototype.slice.call(e,0,-1).some(Boolean)}static formatBytes(e){return a.formatBytes(e)}static reversePolishNotation(...n){let a=null;try{const t=Object.assign({},st.functionMap());delete t.formatBytes;const i=[];for(let a=0;a<n.length-1;a++){const s=n[a];if(t[s])if(i.length>1){const e=i.pop(),n=i.pop(),a=t[s](n,e,{});i.push(a)}else e.throwFormattedErr("Cannot execute operation %s - not enough args",s);else i.push(s)}a=i.pop()}catch(n){t.error("Failed to execute RPN: %s",n,n),a=e.asErr(n)?.message||"Failure"}return a}}class rt{prefix;suffix;maxCacheTemplates;cache;constructor(e="",t="",n=10){this.prefix=e,this.suffix=t,this.maxCacheTemplates=n,this.maxCacheTemplates>0&&(this.cache=new Map)}async renderTemplate(e,t,n=null){return this.renderRemoteTemplate(e,t,n)}async renderRemoteTemplate(e,t,n=null){const a=await this.fetchTemplate(e),i=n?await this.fetchTemplateText(n):null;i&&(await c.register(r),r.registerPartial(n,i));return a?a(t||{}):null}async renderTemplateDirect(e,t,n=null){return r.compile(e)(t)}async fetchTemplate(e){let n=null;try{if(this.cache&&this.cache.has(e))t.silly("Cache hit for template : %s",e),n=this.cache.get(e);else{t.debug("Cache miss for template : %s",e);const a=await this.fetchTemplateText(e);a&&(n=r.compile(a),this.cache&&n&&(this.cache.set(e,n),this.cache.size>this.maxCacheTemplates&&this.cache.delete(Array.from(this.cache.keys())[0])))}}catch(a){t.warn("Could not fetch and compile template : %s : %s",e,a,a),n=null}return n}async fetchTemplateText(e){let n=null;const i=a.trimToEmpty(this.prefix)+e+a.trimToEmpty(this.suffix);try{const e=await o(i);n=await e.text()}catch(e){t.warn("Could not fetch url : %s : %s",i,e,e),n=null}return n}}class ot{allModels;constructor(t){this.allModels=t,t&&0!=Object.keys(t).length||e.throwFormattedErr("Cannot create model validator, passed models was null/empty : %j",t)}static createFromYamlString(e,t){const n=l.load(e),a=t&&t.length>0?i.findValue(n,t):n;return ot.createFromParsedObject(a)}static createFromParsedObject(e){return new ot(e)}get modelNames(){return Object.keys(this.allModels)}addModel(e,t){this.allModels[e]=t}fetchModel(e){return this.allModels[e]}validate(e,n,a=!1,i=!0){let s=[];t.silly("Validating model %s all definitions are : %j",e,this.allModels);if(!n||0===Object.keys(n).length)a||s.push("Empty / null object sent, but empty not allowed here");else if(this.allModels&&e&&this.allModels[e]){const t=(new u).validate(n,this.allModels[e],this.allModels,a,i);t.errorCount>0&&(s=t.errors.map((e=>e.message)))}else s=['Model named "'+e+'" not present in schema'];return s}}class ct{static timeout(e,t,n){return d(e,this.createTimeoutObservable(t,n))}static createTimeoutObservable(e,t){return m.create((n=>{const a=setTimeout((()=>{clearTimeout(a),n.next(new s(e,t))}),t)}))}}class ut{static safeUnsubscribe(e){return i.safeCallFunction(e,"unsubscribe")}static async waitForNonNullOnSubject(e){return e.value?e.value:new Promise(((t,n)=>{const a=e.subscribe((e=>{e&&(ut.safeUnsubscribe(a),t(e))}))}))}static async waitForTargetValueOnSubject(e,t){return e.value===t?e.value:new Promise(((n,a)=>{const i=e.subscribe((e=>{e===t&&(ut.safeUnsubscribe(i),n(e))}))}))}}export{p as BrevoMailSendingProvider,at as BrevoRatchet,st as HandlebarsRatchet,ot as ModelValidator,ct as ObservableRatchet,it as RatchetMiscInfo,rt as RemoteHandlebarsTemplateRenderer,ut as RxjsRatchet};
|
|
1
|
+
import{ErrorRatchet as e,Logger as t,NumberRatchet as n,StringRatchet as a,MapRatchet as i,TimeoutToken as s}from"@bitblit/ratchet-common";import r from"handlebars";import o from"cross-fetch";import c from"handlebars-layouts";import u from"swagger-model-validator";import l from"js-yaml";import{race as d,Observable as m}from"rxjs";class p{brevo;constructor(e){this.brevo=e}async sendEmail(n){try{const t=await this.brevo.smtpApi();if(n?.attachments?.length)throw e.fErr("Cannot send email with attachments yet, not supported");const a={subject:n.subject,htmlContent:n.htmlMessage,sender:{name:n.fromName,email:n.fromAddress||"a@a.com"},to:(n.destinationAddresses||[]).map((e=>({email:e}))),bcc:n?.bccAddresses?.length?n.bccAddresses.map((e=>({email:e}))):void 0};return await t.sendTransacEmail({sendSmtpEmail:a})}catch(e){throw t.error("Failed to send email: %s",e,e),e}}}const f="https://api.sendinblue.com/v3".replace(/\/+$/,"");class h{configuration;constructor(e={}){this.configuration=e}set config(e){this.configuration=e}get basePath(){return null!=this.configuration.basePath?this.configuration.basePath:f}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||q}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){const e=this.configuration.apiKey;if(e)return"function"==typeof e?e:()=>e}get accessToken(){const e=this.configuration.accessToken;if(e)return"function"==typeof e?e:async()=>e}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}}const g=new h;class w{configuration;static jsonRegex=new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$","i");middleware;constructor(e=g){this.configuration=e,this.middleware=e.middleware}withMiddleware(...e){const t=this.clone();return t.middleware=t.middleware.concat(...e),t}withPreMiddleware(...e){const t=e.map((e=>({pre:e})));return this.withMiddleware(...t)}withPostMiddleware(...e){const t=e.map((e=>({post:e})));return this.withMiddleware(...t)}isJsonMime(e){return!!e&&w.jsonRegex.test(e)}async request(e,t){const{url:n,init:a}=await this.createFetchParams(e,t),i=await this.fetchApi(n,a);if(i&&i.status>=200&&i.status<300)return i;throw new y(i,"Response returned an error code")}async createFetchParams(e,t){let n=this.configuration.basePath+e.path;void 0!==e.query&&0!==Object.keys(e.query).length&&(n+="?"+this.configuration.queryParamsStringify(e.query));const a=Object.assign({},this.configuration.headers,e.headers);Object.keys(a).forEach((e=>void 0===a[e]?delete a[e]:{}));const i="function"==typeof t?t:async()=>t,s={method:e.method,headers:a,body:e.body,credentials:this.configuration.credentials},r={...s,...await i({init:s,context:e})};let o;var c;c=r.body,o="undefined"!=typeof FormData&&c instanceof FormData||r.body instanceof URLSearchParams||function(e){return"undefined"!=typeof Blob&&e instanceof Blob}(r.body)?r.body:this.isJsonMime(a["Content-Type"])?JSON.stringify(r.body):r.body;return{url:n,init:{...r,body:o}}}fetchApi=async(e,t)=>{let n,a={url:e,init:t};for(const e of this.middleware)e.pre&&(a=await e.pre({fetch:this.fetchApi,...a})||a);try{n=await(this.configuration.fetchApi||fetch)(a.url,a.init)}catch(e){for(const t of this.middleware)t.onError&&(n=await t.onError({fetch:this.fetchApi,url:a.url,init:a.init,error:e,response:n?n.clone():void 0})||n);if(void 0===n)throw e instanceof Error?new b(e,"The request failed and the interceptors did not return an alternative response"):e}for(const e of this.middleware)e.post&&(n=await e.post({fetch:this.fetchApi,url:a.url,init:a.init,response:n.clone()})||n);return n};clone(){const e=new(0,this.constructor)(this.configuration);return e.middleware=this.middleware.slice(),e}}class y extends Error{response;name="ResponseError";constructor(e,t){super(t),this.response=e}}class b extends Error{cause;name="FetchError";constructor(e,t){super(t),this.cause=e}}class v extends Error{field;name="RequiredError";constructor(e,t){super(t),this.field=e}}const T=",";function k(e,t){const n=e[t];return null!=n}function q(e,t=""){return Object.keys(e).map((n=>D(n,e[n],t))).filter((e=>e.length>0)).join("&")}function D(e,t,n=""){const a=n+(n.length?`[${e}]`:e);if(t instanceof Array){const e=t.map((e=>encodeURIComponent(String(e)))).join(`&${encodeURIComponent(a)}=`);return`${encodeURIComponent(a)}=${e}`}if(t instanceof Set){return D(e,Array.from(t),n)}return t instanceof Date?`${encodeURIComponent(a)}=${encodeURIComponent(t.toISOString())}`:t instanceof Object?q(t,a):`${encodeURIComponent(a)}=${encodeURIComponent(String(t))}`}class S{raw;transformer;constructor(e,t=(e=>e)){this.raw=e,this.transformer=t}async value(){return this.transformer(await this.raw.json())}}class C{raw;constructor(e){this.raw=e}async value(){}}var I,R,E,A,B,P,O,j,N,U,K,x,M,L,F,_,H,G,V,$,Q,z,J,Y,W,X,Z,ee,te,ne,ae,ie,se,re,oe,ce,ue,le,de,me,pe;function fe(e){if(void 0!==e)return null===e?null:{domain:e.domain}}function he(e){return function(e,t){if(null==e)return e;return{id:e.id}}(e)}function ge(e){return function(e,t){if(null==e)return e;return{messageId:e.messageId}}(e)}function we(e){if(void 0!==e)return null===e?null:{name:e.name,email:e.email,id:e.id}}function ye(e){if(void 0!==e)return null===e?null:{tag:e.tag,sender:we(e.sender),templateName:e.templateName,htmlContent:e.htmlContent,htmlUrl:e.htmlUrl,subject:e.subject,replyTo:e.replyTo,toField:e.toField,attachmentUrl:e.attachmentUrl,isActive:e.isActive}}function be(e){if(void 0!==e)return null===e?null:{startDate:e.startDate,endDate:e.endDate,contactEmail:e.contactEmail}}function ve(e){return function(e,t){if(null==e)return e;return{key:k(e,"key")?e.key:void 0,enabled:e.enabled}}(e)}function Te(e){return function(e,t){if(null==e)return e;return{type:e.type,creditsType:e.creditsType,credits:e.credits,startDate:k(e,"startDate")?new Date(e.startDate):void 0,endDate:k(e,"endDate")?new Date(e.endDate):void 0,userLimit:k(e,"userLimit")?e.userLimit:void 0}}(e)}function ke(e){return function(e,t){if(null==e)return e;return{userName:e.userName,relay:e.relay,port:e.port}}(e)}function qe(e){return function(e,t){if(null==e)return e;return{enabled:e.enabled,data:ke(e.data)}}(e)}function De(e){return function(e,t){if(null==e)return e;return{street:e.street,city:e.city,zipCode:e.zipCode,country:e.country}}(e)}function Se(e){return function(e,t){if(null==e)return e;return{email:e.email,firstName:e.firstName,lastName:e.lastName,companyName:e.companyName,address:De(e.address),plan:e.plan.map(Te),relay:qe(e.relay),marketingAutomation:k(e,"marketingAutomation")?ve(e.marketingAutomation):void 0}}(e)}function Ce(e){return function(e,t){if(null==e)return e;return{range:e.range,requests:e.requests,delivered:e.delivered,hardBounces:e.hardBounces,softBounces:e.softBounces,clicks:e.clicks,uniqueClicks:e.uniqueClicks,opens:e.opens,uniqueOpens:e.uniqueOpens,spamReports:e.spamReports,blocked:e.blocked,invalid:e.invalid,unsubscribed:e.unsubscribed}}(e)}function Ie(e){return function(e,t){if(null==e)return e;return{domains:e.domains}}(e)}function Re(e){return function(e,t){if(null==e)return e;return{email:e.email,date:new Date(e.date),subject:k(e,"subject")?e.subject:void 0,messageId:e.messageId,event:e.event,reason:k(e,"reason")?e.reason:void 0,tag:k(e,"tag")?e.tag:void 0,ip:k(e,"ip")?e.ip:void 0,link:k(e,"link")?e.link:void 0,from:k(e,"from")?e.from:void 0}}(e)}function Ee(e){return function(e,t){if(null==e)return e;return{events:k(e,"events")?e.events.map(Re):void 0}}(e)}function Ae(e){return function(e,t){if(null==e)return e;return{date:new Date(e.date),requests:e.requests,delivered:e.delivered,hardBounces:e.hardBounces,softBounces:e.softBounces,clicks:e.clicks,uniqueClicks:e.uniqueClicks,opens:e.opens,uniqueOpens:e.uniqueOpens,spamReports:e.spamReports,blocked:e.blocked,invalid:e.invalid,unsubscribed:e.unsubscribed}}(e)}function Be(e){return function(e,t){if(null==e)return e;return{reports:k(e,"reports")?e.reports.map(Ae):void 0}}(e)}function Pe(e){return function(e,t){if(null==e)return e;return{name:k(e,"name")?e.name:void 0,email:k(e,"email")?e.email:void 0,id:k(e,"id")?e.id:void 0}}(e)}function Oe(e){return function(e,t){if(null==e)return e;return{id:e.id,name:e.name,subject:e.subject,isActive:e.isActive,testSent:e.testSent,sender:Pe(e.sender),replyTo:e.replyTo,toField:e.toField,tag:e.tag,htmlContent:e.htmlContent,createdAt:new Date(e.createdAt),modifiedAt:new Date(e.modifiedAt),doiTemplate:k(e,"doiTemplate")?e.doiTemplate:void 0}}(e)}function je(e){return function(e,t){if(null==e)return e;return{count:k(e,"count")?e.count:void 0,templates:k(e,"templates")?e.templates.map(Oe):void 0}}(e)}function Ne(e){return function(e,t){if(null==e)return e;return{code:k(e,"code")?e.code:void 0,message:k(e,"message")?e.message:void 0}}(e)}function Ue(e){return function(e,t){if(null==e)return e;return{email:e.email,senderEmail:e.senderEmail,reason:Ne(e.reason),blockedAt:new Date(e.blockedAt)}}(e)}function Ke(e){return function(e,t){if(null==e)return e;return{count:k(e,"count")?e.count:void 0,contacts:k(e,"contacts")?e.contacts.map(Ue):void 0}}(e)}function xe(e){return function(e,t){if(null==e)return e;return{name:e.name,time:new Date(e.time)}}(e)}function Me(e){return function(e,t){if(null==e)return e;return{email:e.email,subject:e.subject,templateId:k(e,"templateId")?e.templateId:void 0,date:new Date(e.date),events:e.events.map(xe),body:e.body,attachmentCount:e.attachmentCount}}(e)}function Le(e){return function(e,t){if(null==e)return e;return{email:e.email,subject:e.subject,templateId:k(e,"templateId")?e.templateId:void 0,messageId:e.messageId,uuid:e.uuid,date:new Date(e.date),from:k(e,"from")?e.from:void 0,tags:k(e,"tags")?e.tags:void 0}}(e)}function Fe(e){return function(e,t){if(null==e)return e;return{transactionalEmails:k(e,"transactionalEmails")?e.transactionalEmails.map(Le):void 0}}(e)}function _e(e){if(void 0!==e)return null===e?null:{content:e.content,name:e.name}}function He(e){if(void 0!==e)return null===e?null:{emailTo:e.emailTo,emailBcc:e.emailBcc,emailCc:e.emailCc,replyTo:e.replyTo,attachmentUrl:e.attachmentUrl,attachment:void 0===e.attachment?void 0:e.attachment.map(_e),headers:e.headers,attributes:e.attributes,tags:e.tags}}function Ge(e){if(void 0!==e)return null===e?null:{url:e.url,content:e.content,name:e.name}}function Ve(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function $e(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function Qe(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function ze(e){if(void 0!==e)return null===e?null:{name:e.name,email:e.email}}function Je(e){if(void 0!==e)return null===e?null:{email:e.email,name:e.name}}function Ye(e){if(void 0!==e)return null===e?null:{sender:ze(e.sender),to:e.to.map(Je),bcc:void 0===e.bcc?void 0:e.bcc.map(Ve),cc:void 0===e.cc?void 0:e.cc.map($e),htmlContent:e.htmlContent,textContent:e.textContent,subject:e.subject,replyTo:Qe(e.replyTo),attachment:void 0===e.attachment?void 0:e.attachment.map(Ge),headers:e.headers,templateId:e.templateId,params:e.params,tags:e.tags}}function We(e){return function(e,t){if(null==e)return e;return{messageId:e.messageId}}(e)}function Xe(e){if(void 0!==e)return null===e?null:{emailTo:e.emailTo}}function Ze(e){if(void 0!==e)return null===e?null:{name:e.name,email:e.email,id:e.id}}function et(e){if(void 0!==e)return null===e?null:{tag:e.tag,sender:Ze(e.sender),templateName:e.templateName,htmlContent:e.htmlContent,htmlUrl:e.htmlUrl,subject:e.subject,replyTo:e.replyTo,toField:e.toField,attachmentUrl:e.attachmentUrl,isActive:e.isActive}}!function(e){e.NotAvailable="notAvailable",e.Pending="pending",e.Tie="tie",e.A="A",e.B="B"}(I||(I={})),function(e){e.Open="Open",e.Click="Click"}(R||(R={})),function(e){e.Text="text",e.Date="date",e.Float="float",e.Boolean="boolean",e.Id="id",e.Category="category"}(E||(E={})),function(e){e.Fr="fr",e.Es="es",e.Pt="pt",e.It="it",e.De="de",e.En="en"}(A||(A={})),function(e){e.Open="open",e.Click="click"}(B||(B={})),function(e){e.Sent="sent",e.HardBounce="hardBounce",e.SoftBounce="softBounce",e.Blocked="blocked",e.Spam="spam",e.Delivered="delivered",e.Request="request",e.Click="click",e.Invalid="invalid",e.Deferred="deferred",e.Opened="opened",e.UniqueOpened="uniqueOpened",e.Unsubscribed="unsubscribed",e.ListAddition="listAddition",e.ContactUpdated="contactUpdated",e.ContactDeleted="contactDeleted"}(P||(P={})),function(e){e.Transactional="transactional",e.Marketing="marketing"}(O||(O={})),function(e){e.All="all",e.NonClickers="nonClickers",e.NonOpeners="nonOpeners",e.Clickers="clickers",e.Openers="openers",e.SoftBounces="softBounces",e.HardBounces="hardBounces",e.Unsubscribed="unsubscribed"}(j||(j={})),function(e){e.InvalidParameter="invalid_parameter",e.MissingParameter="missing_parameter",e.OutOfRange="out_of_range",e.CampaignProcessing="campaign_processing",e.CampaignSent="campaign_sent",e.DocumentNotFound="document_not_found",e.ResellerPermissionDenied="reseller_permission_denied",e.NotEnoughCredits="not_enough_credits",e.PermissionDenied="permission_denied",e.DuplicateParameter="duplicate_parameter",e.DuplicateRequest="duplicate_request",e.MethodNotAllowed="method_not_allowed",e.Unauthorized="unauthorized",e.AccountUnderValidation="account_under_validation",e.NotAcceptable="not_acceptable"}(N||(N={})),function(e){e.PayAsYouGo="payAsYouGo",e.Free="free",e.Subscription="subscription",e.Sms="sms",e.Reseller="reseller"}(U||(U={})),function(e){e.SendLimit="sendLimit"}(K||(K={})),function(e){e.Normal="normal",e.Transactional="transactional",e.Category="category",e.Calculated="calculated",e.Global="global"}(x||(x={})),function(e){e.Text="text",e.Date="date",e.Float="float",e.Id="id",e.Boolean="boolean"}(M||(M={})),function(e){e.Classic="classic",e.Trigger="trigger"}(L||(L={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(F||(F={})),function(e){e.Classic="classic",e.Trigger="trigger"}(_||(_={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(H||(H={})),function(e){e.Classic="classic",e.Trigger="trigger"}(G||(G={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(V||(V={})),function(e){e.Bounces="bounces",e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Delivered="delivered",e.Spam="spam",e.Requests="requests",e.Opened="opened",e.Clicks="clicks",e.Invalid="invalid",e.Deferred="deferred",e.Blocked="blocked",e.Unsubscribed="unsubscribed"}($||($={})),function(e){e.Classic="classic",e.Trigger="trigger"}(Q||(Q={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="in_process"}(z||(z={})),function(e){e.Queued="queued",e.InProcess="in_process",e.Completed="completed"}(J||(J={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="inProcess"}(Y||(Y={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="inProcess"}(W||(W={})),function(e){e.Draft="draft",e.Sent="sent",e.Archive="archive",e.Queued="queued",e.Suspended="suspended",e.InProcess="inProcess"}(X||(X={})),function(e){e.Bounces="bounces",e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Delivered="delivered",e.Sent="sent",e.Accepted="accepted",e.Unsubscription="unsubscription",e.Replies="replies",e.Blocked="blocked",e.Rejected="rejected"}(Z||(Z={})),function(e){e.UnsubscribedViaMa="unsubscribedViaMA",e.UnsubscribedViaEmail="unsubscribedViaEmail",e.AdminBlocked="adminBlocked",e.UnsubscribedViaApi="unsubscribedViaApi",e.HardBounce="hardBounce",e.ContactFlaggedAsSpam="contactFlaggedAsSpam"}(ee||(ee={})),function(e){e.Marketing="marketing",e.Transac="transac"}(te||(te={})),function(e){e.Draft="draft",e.Scheduled="scheduled",e.Pending="pending",e.Approved="approved",e.Running="running",e.Suspended="suspended",e.Rejected="rejected",e.Sent="sent"}(ne||(ne={})),function(e){e.Draft="draft",e.Scheduled="scheduled",e.Pending="pending",e.Approved="approved",e.Running="running",e.Suspended="suspended",e.Rejected="rejected",e.Sent="sent"}(ae||(ae={})),function(e){e.AllContacts="allContacts",e.Subscribed="subscribed",e.Unsubscribed="unsubscribed",e.UnsubscribedPerList="unsubscribedPerList"}(ie||(ie={})),function(e){e.Openers="openers",e.NonOpeners="nonOpeners",e.Clickers="clickers",e.NonClickers="nonClickers",e.Unsubscribed="unsubscribed",e.HardBounces="hardBounces",e.SoftBounces="softBounces"}(se||(se={})),function(e){e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Unsubscribed="unsubscribed"}(re||(re={})),function(e){e.All="all",e.Delivered="delivered",e.Answered="answered",e.SoftBounces="softBounces",e.HardBounces="hardBounces",e.Unsubscribed="unsubscribed"}(oe||(oe={})),function(e){e.Fr="fr",e.Es="es",e.Pt="pt",e.It="it",e.De="de",e.En="en"}(ce||(ce={})),function(e){e.Transactional="transactional",e.Marketing="marketing"}(ue||(ue={})),function(e){e.Suspended="suspended",e.Archive="archive",e.Darchive="darchive",e.Sent="sent",e.Queued="queued",e.Replicate="replicate",e.ReplicateTemplate="replicateTemplate",e.Draft="draft"}(le||(le={})),function(e){e.Open="open",e.Click="click"}(de||(de={})),function(e){e.HardBounce="hardBounce",e.SoftBounce="softBounce",e.Blocked="blocked",e.Spam="spam",e.Delivered="delivered",e.Request="request",e.Click="click",e.Invalid="invalid",e.Deferred="deferred",e.Opened="opened",e.UniqueOpened="uniqueOpened",e.Unsubscribed="unsubscribed",e.ListAddition="listAddition",e.ContactUpdated="contactUpdated",e.ContactDeleted="contactDeleted"}(me||(me={}));class tt extends w{async getAccountRaw(e){const t={};this.configuration&&this.configuration.apiKey&&(t["api-key"]=await this.configuration.apiKey("api-key"));const n=await this.request({path:"/account",method:"GET",headers:t,query:{}},e);return new S(n,(e=>Se(e)))}async getAccount(e){const t=await this.getAccountRaw(e);return await t.value()}}class nt extends w{async blockNewDomainRaw(e,t){if(null===e.blockDomain||void 0===e.blockDomain)throw new v("blockDomain","Required parameter requestParameters.blockDomain was null or undefined when calling blockNewDomain.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/blockedDomains",method:"POST",headers:n,query:{},body:fe(e.blockDomain)},t);return new C(a)}async blockNewDomain(e,t){await this.blockNewDomainRaw(e,t)}async createSmtpTemplateRaw(e,t){if(null===e.smtpTemplate||void 0===e.smtpTemplate)throw new v("smtpTemplate","Required parameter requestParameters.smtpTemplate was null or undefined when calling createSmtpTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates",method:"POST",headers:n,query:{},body:ye(e.smtpTemplate)},t);return new S(a,(e=>he(e)))}async createSmtpTemplate(e,t){const n=await this.createSmtpTemplateRaw(e,t);return await n.value()}async deleteBlockedDomainRaw(e,t){if(null===e.domain||void 0===e.domain)throw new v("domain","Required parameter requestParameters.domain was null or undefined when calling deleteBlockedDomain.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/blockedDomains/{domain}".replace("{domain}",encodeURIComponent(String(e.domain))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async deleteBlockedDomain(e,t){await this.deleteBlockedDomainRaw(e,t)}async deleteHardbouncesRaw(e,t){const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/deleteHardbounces",method:"POST",headers:n,query:{},body:be(e.deleteHardbounces)},t);return new C(a)}async deleteHardbounces(e={},t){await this.deleteHardbouncesRaw(e,t)}async deleteSmtpTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling deleteSmtpTemplate.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async deleteSmtpTemplate(e,t){await this.deleteSmtpTemplateRaw(e,t)}async getAggregatedSmtpReportRaw(e,t){const n={};void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.days&&(n.days=e.days),void 0!==e.tag&&(n.tag=e.tag);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/statistics/aggregatedReport",method:"GET",headers:a,query:n},t);return new S(i,(e=>Ce(e)))}async getAggregatedSmtpReport(e={},t){const n=await this.getAggregatedSmtpReportRaw(e,t);return await n.value()}async getBlockedDomainsRaw(e){const t={};this.configuration&&this.configuration.apiKey&&(t["api-key"]=await this.configuration.apiKey("api-key"));const n=await this.request({path:"/smtp/blockedDomains",method:"GET",headers:t,query:{}},e);return new S(n,(e=>Ie(e)))}async getBlockedDomains(e){const t=await this.getBlockedDomainsRaw(e);return await t.value()}async getEmailEventReportRaw(e,t){const n={};void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.days&&(n.days=e.days),void 0!==e.email&&(n.email=e.email),void 0!==e.event&&(n.event=e.event),void 0!==e.tags&&(n.tags=e.tags),void 0!==e.messageId&&(n.messageId=e.messageId),void 0!==e.templateId&&(n.templateId=e.templateId);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/statistics/events",method:"GET",headers:a,query:n},t);return new S(i,(e=>Ee(e)))}async getEmailEventReport(e={},t){const n=await this.getEmailEventReportRaw(e,t);return await n.value()}async getSmtpReportRaw(e,t){const n={};void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.days&&(n.days=e.days),void 0!==e.tag&&(n.tag=e.tag);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/statistics/reports",method:"GET",headers:a,query:n},t);return new S(i,(e=>Be(e)))}async getSmtpReport(e={},t){const n=await this.getSmtpReportRaw(e,t);return await n.value()}async getSmtpTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling getSmtpTemplate.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"GET",headers:n,query:{}},t);return new S(a,(e=>Oe(e)))}async getSmtpTemplate(e,t){const n=await this.getSmtpTemplateRaw(e,t);return await n.value()}async getSmtpTemplatesRaw(e,t){const n={};void 0!==e.templateStatus&&(n.templateStatus=e.templateStatus),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset);const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/templates",method:"GET",headers:a,query:n},t);return new S(i,(e=>je(e)))}async getSmtpTemplates(e={},t){const n=await this.getSmtpTemplatesRaw(e,t);return await n.value()}async getTransacBlockedContactsRaw(e,t){const n={};void 0!==e.startDate&&(n.startDate=e.startDate),void 0!==e.endDate&&(n.endDate=e.endDate),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),e.senders&&(n.senders=e.senders.join(T));const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/blockedContacts",method:"GET",headers:a,query:n},t);return new S(i,(e=>Ke(e)))}async getTransacBlockedContacts(e={},t){const n=await this.getTransacBlockedContactsRaw(e,t);return await n.value()}async getTransacEmailContentRaw(e,t){if(null===e.uuid||void 0===e.uuid)throw new v("uuid","Required parameter requestParameters.uuid was null or undefined when calling getTransacEmailContent.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/emails/{uuid}".replace("{uuid}",encodeURIComponent(String(e.uuid))),method:"GET",headers:n,query:{}},t);return new S(a,(e=>Me(e)))}async getTransacEmailContent(e,t){const n=await this.getTransacEmailContentRaw(e,t);return await n.value()}async getTransacEmailsListRaw(e,t){const n={};void 0!==e.email&&(n.email=e.email),void 0!==e.templateId&&(n.templateId=e.templateId),void 0!==e.messageId&&(n.messageId=e.messageId),void 0!==e.startDate&&(n.startDate=e.startDate.toISOString().substring(0,10)),void 0!==e.endDate&&(n.endDate=e.endDate.toISOString().substring(0,10));const a={};this.configuration&&this.configuration.apiKey&&(a["api-key"]=await this.configuration.apiKey("api-key"));const i=await this.request({path:"/smtp/emails",method:"GET",headers:a,query:n},t);return new S(i,(e=>Fe(e)))}async getTransacEmailsList(e={},t){const n=await this.getTransacEmailsListRaw(e,t);return await n.value()}async sendTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling sendTemplate.");if(null===e.sendEmail||void 0===e.sendEmail)throw new v("sendEmail","Required parameter requestParameters.sendEmail was null or undefined when calling sendTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}/send".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"POST",headers:n,query:{},body:He(e.sendEmail)},t);return new S(a,(e=>We(e)))}async sendTemplate(e,t){const n=await this.sendTemplateRaw(e,t);return await n.value()}async sendTestTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling sendTestTemplate.");if(null===e.sendTestEmail||void 0===e.sendTestEmail)throw new v("sendTestEmail","Required parameter requestParameters.sendTestEmail was null or undefined when calling sendTestTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}/sendTest".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"POST",headers:n,query:{},body:Xe(e.sendTestEmail)},t);return new C(a)}async sendTestTemplate(e,t){await this.sendTestTemplateRaw(e,t)}async sendTransacEmailRaw(e,t){if(null===e.sendSmtpEmail||void 0===e.sendSmtpEmail)throw new v("sendSmtpEmail","Required parameter requestParameters.sendSmtpEmail was null or undefined when calling sendTransacEmail.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/email",method:"POST",headers:n,query:{},body:Ye(e.sendSmtpEmail)},t);return new S(a,(e=>ge(e)))}async sendTransacEmail(e,t){const n=await this.sendTransacEmailRaw(e,t);return await n.value()}async smtpBlockedContactsEmailDeleteRaw(e,t){if(null===e.email||void 0===e.email)throw new v("email","Required parameter requestParameters.email was null or undefined when calling smtpBlockedContactsEmailDelete.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/blockedContacts/{email}".replace("{email}",encodeURIComponent(String(e.email))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async smtpBlockedContactsEmailDelete(e,t){await this.smtpBlockedContactsEmailDeleteRaw(e,t)}async smtpLogMessageIdDeleteRaw(e,t){if(null===e.messageId||void 0===e.messageId)throw new v("messageId","Required parameter requestParameters.messageId was null or undefined when calling smtpLogMessageIdDelete.");const n={};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/log/{messageId}".replace("{messageId}",encodeURIComponent(String(e.messageId))),method:"DELETE",headers:n,query:{}},t);return new C(a)}async smtpLogMessageIdDelete(e,t){await this.smtpLogMessageIdDeleteRaw(e,t)}async updateSmtpTemplateRaw(e,t){if(null===e.templateId||void 0===e.templateId)throw new v("templateId","Required parameter requestParameters.templateId was null or undefined when calling updateSmtpTemplate.");if(null===e.smtpTemplate||void 0===e.smtpTemplate)throw new v("smtpTemplate","Required parameter requestParameters.smtpTemplate was null or undefined when calling updateSmtpTemplate.");const n={"Content-Type":"application/json"};this.configuration&&this.configuration.apiKey&&(n["api-key"]=await this.configuration.apiKey("api-key"));const a=await this.request({path:"/smtp/templates/{templateId}".replace("{templateId}",encodeURIComponent(String(e.templateId))),method:"PUT",headers:n,query:{},body:et(e.smtpTemplate)},t);return new C(a)}async updateSmtpTemplate(e,t){await this.updateSmtpTemplateRaw(e,t)}}!function(e){e.Bounces="bounces",e.HardBounces="hardBounces",e.SoftBounces="softBounces",e.Delivered="delivered",e.Spam="spam",e.Requests="requests",e.Opened="opened",e.Clicks="clicks",e.Invalid="invalid",e.Deferred="deferred",e.Blocked="blocked",e.Unsubscribed="unsubscribed"}(pe||(pe={}));class at{keys;configParamTemplate;constructor(e,t){this.keys=e,this.configParamTemplate=t}async buildConfig(){const e=await this.keys,n=this.configParamTemplate?Object.assign({},this.configParamTemplate):{},a={pre:async e=>{t.silly("Context: %j",e)}};return n.apiKey=e.apiKey,n.middleware=[a],n}async accountApi(){const e=await this.buildConfig();return new tt(new h(e))}async smtpApi(){const e=await this.buildConfig();return new nt(new h(e))}async fetchAccountData(){const e=await this.accountApi();return await e.getAccount()}}class it{constructor(){}static buildInformation(){return{version:"416",hash:"e7c8727b07eba28014e4ed789357dce00144456f",branch:"alpha-2024-07-12-2",tag:"alpha-2024-07-12-2",timeBuiltISO:"2024-07-12T17:24:10-0700",notes:"No notes"}}}class st{constructor(){}static functionMap(){return{eq:st.equal,ne:st.notEqual,lt:st.lessThan,gt:st.greaterThan,lte:st.lessThanEqual,gte:st.greaterThanEqual,and:st.and,or:st.or,formatBytes:st.formatBytes,rpn:st.reversePolishNotation,add:st.add,sub:st.sub,mul:st.mul,div:st.div,mod:st.mod,maxNum:st.maxNum,minNum:st.minNum}}static registerAll(e){e.registerHelper(st.functionMap())}static add(e,t){return n.safeNumber(e)+n.safeNumber(t)}static sub(e,t){return n.safeNumber(e)-n.safeNumber(t)}static mul(e,t){return n.safeNumber(e)*n.safeNumber(t)}static div(e,t){return n.safeNumber(e)/n.safeNumber(t)}static mod(e,t){return n.safeNumber(e)%n.safeNumber(t)}static equal(e,t){return e===t}static notEqual(e,t){return e!==t}static lessThan(e,t){return e<t}static lessThanEqual(e,t){return e<=t}static greaterThan(e,t){return e>t}static greaterThanEqual(e,t){return e>=t}static maxNum(...e){return Math.max(...e.slice(0,-1))}static minNum(...e){return Math.min(...e.slice(0,-1))}static and(...e){return Array.prototype.every.call(e,Boolean)}static or(...e){return Array.prototype.slice.call(e,0,-1).some(Boolean)}static formatBytes(e){return a.formatBytes(e)}static reversePolishNotation(...n){let a=null;try{const t=Object.assign({},st.functionMap());delete t.formatBytes;const i=[];for(let a=0;a<n.length-1;a++){const s=n[a];if(t[s])if(i.length>1){const e=i.pop(),n=i.pop(),a=t[s](n,e,{});i.push(a)}else e.throwFormattedErr("Cannot execute operation %s - not enough args",s);else i.push(s)}a=i.pop()}catch(n){t.error("Failed to execute RPN: %s",n,n),a=e.asErr(n)?.message||"Failure"}return a}}class rt{prefix;suffix;maxCacheTemplates;cache;constructor(e="",t="",n=10){this.prefix=e,this.suffix=t,this.maxCacheTemplates=n,this.maxCacheTemplates>0&&(this.cache=new Map)}async renderTemplate(e,t,n=null){return this.renderRemoteTemplate(e,t,n)}async renderRemoteTemplate(e,t,n=null){const a=await this.fetchTemplate(e),i=n?await this.fetchTemplateText(n):null;i&&(await c.register(r),r.registerPartial(n,i));return a?a(t||{}):null}async renderTemplateDirect(e,t,n=null){return r.compile(e)(t)}async fetchTemplate(e){let n=null;try{if(this.cache&&this.cache.has(e))t.silly("Cache hit for template : %s",e),n=this.cache.get(e);else{t.debug("Cache miss for template : %s",e);const a=await this.fetchTemplateText(e);a&&(n=r.compile(a),this.cache&&n&&(this.cache.set(e,n),this.cache.size>this.maxCacheTemplates&&this.cache.delete(Array.from(this.cache.keys())[0])))}}catch(a){t.warn("Could not fetch and compile template : %s : %s",e,a,a),n=null}return n}async fetchTemplateText(e){let n=null;const i=a.trimToEmpty(this.prefix)+e+a.trimToEmpty(this.suffix);try{const e=await o(i);n=await e.text()}catch(e){t.warn("Could not fetch url : %s : %s",i,e,e),n=null}return n}}class ot{allModels;constructor(t){this.allModels=t,t&&0!=Object.keys(t).length||e.throwFormattedErr("Cannot create model validator, passed models was null/empty : %j",t)}static createFromYamlString(e,t){const n=l.load(e),a=t&&t.length>0?i.findValue(n,t):n;return ot.createFromParsedObject(a)}static createFromParsedObject(e){return new ot(e)}get modelNames(){return Object.keys(this.allModels)}addModel(e,t){this.allModels[e]=t}fetchModel(e){return this.allModels[e]}validate(e,n,a=!1,i=!0){let s=[];t.silly("Validating model %s all definitions are : %j",e,this.allModels);if(!n||0===Object.keys(n).length)a||s.push("Empty / null object sent, but empty not allowed here");else if(this.allModels&&e&&this.allModels[e]){const t=(new u).validate(n,this.allModels[e],this.allModels,a,i);t.errorCount>0&&(s=t.errors.map((e=>e.message)))}else s=['Model named "'+e+'" not present in schema'];return s}}class ct{static timeout(e,t,n){return d(e,this.createTimeoutObservable(t,n))}static createTimeoutObservable(e,t){return m.create((n=>{const a=setTimeout((()=>{clearTimeout(a),n.next(new s(e,t))}),t)}))}}class ut{static safeUnsubscribe(e){return i.safeCallFunction(e,"unsubscribe")}static async waitForNonNullOnSubject(e){return e.value?e.value:new Promise(((t,n)=>{const a=e.subscribe((e=>{e&&(ut.safeUnsubscribe(a),t(e))}))}))}static async waitForTargetValueOnSubject(e,t){return e.value===t?e.value:new Promise(((n,a)=>{const i=e.subscribe((e=>{e===t&&(ut.safeUnsubscribe(i),n(e))}))}))}}export{p as BrevoMailSendingProvider,at as BrevoRatchet,st as HandlebarsRatchet,ot as ModelValidator,ct as ObservableRatchet,it as RatchetMiscInfo,rt as RemoteHandlebarsTemplateRenderer,ut as RxjsRatchet};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitblit/ratchet-misc",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.416-alpha",
|
|
4
4
|
"description": "Ratchet miscellaneous tooling that requires smallish dependant libraries",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"license": "Apache-2.0",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@bitblit/ratchet-common": "4.0.
|
|
57
|
+
"@bitblit/ratchet-common": "4.0.416-alpha"
|
|
58
58
|
},
|
|
59
59
|
"optionalDependencies": {
|
|
60
60
|
"handlebars": "4.7.8",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"swagger-model-validator": "3.0.21"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@bitblit/ratchet-common": "4.0.
|
|
67
|
+
"@bitblit/ratchet-common": "4.0.416-alpha",
|
|
68
68
|
"handlebars": "^4.7.8",
|
|
69
69
|
"handlebars-layouts": "^3.1.4",
|
|
70
70
|
"js-yaml": "^4.1.0",
|