'use strict'; var crypto = require('crypto'); var C=Object.defineProperty;var r=(n,a)=>C(n,"name",{value:a,configurable:!0});var A="mailvideo_secret";var d=class{static{r(this,"Timer");}_start;constructor(){this._start=process.hrtime.bigint();}finish(){return (process.hrtime.bigint()-this._start)/BigInt(1e6)}getTimeInMS(){return (process.hrtime.bigint()-this._start)/BigInt(1e6)}};var N=[["Afghanistan (\u202B\u0627\u0641\u063A\u0627\u0646\u0633\u062A\u0627\u0646\u202C\u200E)","af","93"],["Albania (Shqip\xEBri)","al","355"],["Algeria (\u202B\u0627\u0644\u062C\u0632\u0627\u0626\u0631\u202C\u200E)","dz","213"],["American Samoa","as","1",5,["684"]],["Andorra","ad","376"],["Angola","ao","244"],["Anguilla","ai","1",6,["264"]],["Antigua and Barbuda","ag","1",7,["268"]],["Argentina","ar","54"],["Armenia (\u0540\u0561\u0575\u0561\u057D\u057F\u0561\u0576)","am","374"],["Aruba","aw","297"],["Ascension Island","ac","247"],["Australia","au","61",0],["Austria (\xD6sterreich)","at","43"],["Azerbaijan (Az\u0259rbaycan)","az","994"],["Bahamas","bs","1",8,["242"]],["Bahrain (\u202B\u0627\u0644\u0628\u062D\u0631\u064A\u0646\u202C\u200E)","bh","973"],["Bangladesh (\u09AC\u09BE\u0982\u09B2\u09BE\u09A6\u09C7\u09B6)","bd","880"],["Barbados","bb","1",9,["246"]],["Belarus (\u0411\u0435\u043B\u0430\u0440\u0443\u0441\u044C)","by","375"],["Belgium (Belgi\xEB)","be","32"],["Belize","bz","501"],["Benin (B\xE9nin)","bj","229"],["Bermuda","bm","1",10,["441"]],["Bhutan (\u0F60\u0F56\u0FB2\u0F74\u0F42)","bt","975"],["Bolivia","bo","591"],["Bosnia and Herzegovina (\u0411\u043E\u0441\u043D\u0430 \u0438 \u0425\u0435\u0440\u0446\u0435\u0433\u043E\u0432\u0438\u043D\u0430)","ba","387"],["Botswana","bw","267"],["Brazil (Brasil)","br","55"],["British Indian Ocean Territory","io","246"],["British Virgin Islands","vg","1",11,["284"]],["Brunei","bn","673"],["Bulgaria (\u0411\u044A\u043B\u0433\u0430\u0440\u0438\u044F)","bg","359"],["Burkina Faso","bf","226"],["Burundi (Uburundi)","bi","257"],["Cambodia (\u1780\u1798\u17D2\u1796\u17BB\u1787\u17B6)","kh","855"],["Cameroon (Cameroun)","cm","237"],["Canada","ca","1",1,["204","226","236","249","250","289","306","343","365","387","403","416","418","431","437","438","450","506","514","519","548","579","581","587","604","613","639","647","672","705","709","742","778","780","782","807","819","825","867","873","902","905"]],["Cape Verde (Kabu Verdi)","cv","238"],["Caribbean Netherlands","bq","599",1,["3","4","7"]],["Cayman Islands","ky","1",12,["345"]],["Central African Republic (R\xE9publique centrafricaine)","cf","236"],["Chad (Tchad)","td","235"],["Chile","cl","56"],["China (\u4E2D\u56FD)","cn","86"],["Christmas Island","cx","61",2,["89164"]],["Cocos (Keeling) Islands","cc","61",1,["89162"]],["Colombia","co","57"],["Comoros (\u202B\u062C\u0632\u0631 \u0627\u0644\u0642\u0645\u0631\u202C\u200E)","km","269"],["Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)","cd","243"],["Congo (Republic) (Congo-Brazzaville)","cg","242"],["Cook Islands","ck","682"],["Costa Rica","cr","506"],["C\xF4te d\u2019Ivoire","ci","225"],["Croatia (Hrvatska)","hr","385"],["Cuba","cu","53"],["Cura\xE7ao","cw","599",0],["Cyprus (\u039A\u03CD\u03C0\u03C1\u03BF\u03C2)","cy","357"],["Czech Republic (\u010Cesk\xE1 republika)","cz","420"],["Denmark (Danmark)","dk","45"],["Djibouti","dj","253"],["Dominica","dm","1",13,["767"]],["Dominican Republic (Rep\xFAblica Dominicana)","do","1",2,["809","829","849"]],["Ecuador","ec","593"],["Egypt (\u202B\u0645\u0635\u0631\u202C\u200E)","eg","20"],["El Salvador","sv","503"],["Equatorial Guinea (Guinea Ecuatorial)","gq","240"],["Eritrea","er","291"],["Estonia (Eesti)","ee","372"],["Eswatini","sz","268"],["Ethiopia","et","251"],["Falkland Islands (Islas Malvinas)","fk","500"],["Faroe Islands (F\xF8royar)","fo","298"],["Fiji","fj","679"],["Finland (Suomi)","fi","358",0],["France","fr","33"],["French Guiana (Guyane fran\xE7aise)","gf","594"],["French Polynesia (Polyn\xE9sie fran\xE7aise)","pf","689"],["Gabon","ga","241"],["Gambia","gm","220"],["Georgia (\u10E1\u10D0\u10E5\u10D0\u10E0\u10D7\u10D5\u10D4\u10DA\u10DD)","ge","995"],["Germany (Deutschland)","de","49"],["Ghana (Gaana)","gh","233"],["Gibraltar","gi","350"],["Greece (\u0395\u03BB\u03BB\u03AC\u03B4\u03B1)","gr","30"],["Greenland (Kalaallit Nunaat)","gl","299"],["Grenada","gd","1",14,["473"]],["Guadeloupe","gp","590",0],["Guam","gu","1",15,["671"]],["Guatemala","gt","502"],["Guernsey","gg","44",1,["1481","7781","7839","7911"]],["Guinea (Guin\xE9e)","gn","224"],["Guinea-Bissau (Guin\xE9 Bissau)","gw","245"],["Guyana","gy","592"],["Haiti","ht","509"],["Honduras","hn","504"],["Hong Kong (\u9999\u6E2F)","hk","852"],["Hungary (Magyarorsz\xE1g)","hu","36"],["Iceland (\xCDsland)","is","354"],["India (\u092D\u093E\u0930\u0924)","in","91"],["Indonesia","id","62"],["Iran (\u202B\u0627\u06CC\u0631\u0627\u0646\u202C\u200E)","ir","98"],["Iraq (\u202B\u0627\u0644\u0639\u0631\u0627\u0642\u202C\u200E)","iq","964"],["Ireland","ie","353"],["Isle of Man","im","44",2,["1624","74576","7524","7924","7624"]],["Israel (\u202B\u05D9\u05E9\u05E8\u05D0\u05DC\u202C\u200E)","il","972"],["Italy (Italia)","it","39",0],["Jamaica","jm","1",4,["876","658"]],["Japan (\u65E5\u672C)","jp","81"],["Jersey","je","44",3,["1534","7509","7700","7797","7829","7937"]],["Jordan (\u202B\u0627\u0644\u0623\u0631\u062F\u0646\u202C\u200E)","jo","962"],["Kazakhstan (\u041A\u0430\u0437\u0430\u0445\u0441\u0442\u0430\u043D)","kz","7",1,["33","7"]],["Kenya","ke","254"],["Kiribati","ki","686"],["Kosovo","xk","383"],["Kuwait (\u202B\u0627\u0644\u0643\u0648\u064A\u062A\u202C\u200E)","kw","965"],["Kyrgyzstan (\u041A\u044B\u0440\u0433\u044B\u0437\u0441\u0442\u0430\u043D)","kg","996"],["Laos (\u0EA5\u0EB2\u0EA7)","la","856"],["Latvia (Latvija)","lv","371"],["Lebanon (\u202B\u0644\u0628\u0646\u0627\u0646\u202C\u200E)","lb","961"],["Lesotho","ls","266"],["Liberia","lr","231"],["Libya (\u202B\u0644\u064A\u0628\u064A\u0627\u202C\u200E)","ly","218"],["Liechtenstein","li","423"],["Lithuania (Lietuva)","lt","370"],["Luxembourg","lu","352"],["Macau (\u6FB3\u9580)","mo","853"],["North Macedonia (\u041C\u0430\u043A\u0435\u0434\u043E\u043D\u0438\u0458\u0430)","mk","389"],["Madagascar (Madagasikara)","mg","261"],["Malawi","mw","265"],["Malaysia","my","60"],["Maldives","mv","960"],["Mali","ml","223"],["Malta","mt","356"],["Marshall Islands","mh","692"],["Martinique","mq","596"],["Mauritania (\u202B\u0645\u0648\u0631\u064A\u062A\u0627\u0646\u064A\u0627\u202C\u200E)","mr","222"],["Mauritius (Moris)","mu","230"],["Mayotte","yt","262",1,["269","639"]],["Mexico (M\xE9xico)","mx","52"],["Micronesia","fm","691"],["Moldova (Republica Moldova)","md","373"],["Monaco","mc","377"],["Mongolia (\u041C\u043E\u043D\u0433\u043E\u043B)","mn","976"],["Montenegro (Crna Gora)","me","382"],["Montserrat","ms","1",16,["664"]],["Morocco (\u202B\u0627\u0644\u0645\u063A\u0631\u0628\u202C\u200E)","ma","212",0],["Mozambique (Mo\xE7ambique)","mz","258"],["Myanmar (Burma) (\u1019\u103C\u1014\u103A\u1019\u102C)","mm","95"],["Namibia (Namibi\xEB)","na","264"],["Nauru","nr","674"],["Nepal (\u0928\u0947\u092A\u093E\u0932)","np","977"],["Netherlands (Nederland)","nl","31"],["New Caledonia (Nouvelle-Cal\xE9donie)","nc","687"],["New Zealand","nz","64"],["Nicaragua","ni","505"],["Niger (Nijar)","ne","227"],["Nigeria","ng","234"],["Niue","nu","683"],["Norfolk Island","nf","672"],["North Korea (\uC870\uC120 \uBBFC\uC8FC\uC8FC\uC758 \uC778\uBBFC \uACF5\uD654\uAD6D)","kp","850"],["Northern Mariana Islands","mp","1",17,["670"]],["Norway (Norge)","no","47",0],["Oman (\u202B\u0639\u064F\u0645\u0627\u0646\u202C\u200E)","om","968"],["Pakistan (\u202B\u067E\u0627\u06A9\u0633\u062A\u0627\u0646\u202C\u200E)","pk","92"],["Palau","pw","680"],["Palestine (\u202B\u0641\u0644\u0633\u0637\u064A\u0646\u202C\u200E)","ps","970"],["Panama (Panam\xE1)","pa","507"],["Papua New Guinea","pg","675"],["Paraguay","py","595"],["Peru (Per\xFA)","pe","51"],["Philippines","ph","63"],["Poland (Polska)","pl","48"],["Portugal","pt","351"],["Puerto Rico","pr","1",3,["787","939"]],["Qatar (\u202B\u0642\u0637\u0631\u202C\u200E)","qa","974"],["R\xE9union (La R\xE9union)","re","262",0],["Romania (Rom\xE2nia)","ro","40"],["Russia (\u0420\u043E\u0441\u0441\u0438\u044F)","ru","7",0],["Rwanda","rw","250"],["Saint Barth\xE9lemy","bl","590",1],["Saint Helena","sh","290"],["Saint Kitts and Nevis","kn","1",18,["869"]],["Saint Lucia","lc","1",19,["758"]],["Saint Martin (Saint-Martin (partie fran\xE7aise))","mf","590",2],["Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)","pm","508"],["Saint Vincent and the Grenadines","vc","1",20,["784"]],["Samoa","ws","685"],["San Marino","sm","378"],["S\xE3o Tom\xE9 and Pr\xEDncipe (S\xE3o Tom\xE9 e Pr\xEDncipe)","st","239"],["Saudi Arabia (\u202B\u0627\u0644\u0645\u0645\u0644\u0643\u0629 \u0627\u0644\u0639\u0631\u0628\u064A\u0629 \u0627\u0644\u0633\u0639\u0648\u062F\u064A\u0629\u202C\u200E)","sa","966"],["Senegal (S\xE9n\xE9gal)","sn","221"],["Serbia (\u0421\u0440\u0431\u0438\u0458\u0430)","rs","381"],["Seychelles","sc","248"],["Sierra Leone","sl","232"],["Singapore","sg","65"],["Sint Maarten","sx","1",21,["721"]],["Slovakia (Slovensko)","sk","421"],["Slovenia (Slovenija)","si","386"],["Solomon Islands","sb","677"],["Somalia (Soomaaliya)","so","252"],["South Africa","za","27"],["South Korea (\uB300\uD55C\uBBFC\uAD6D)","kr","82"],["South Sudan (\u202B\u062C\u0646\u0648\u0628 \u0627\u0644\u0633\u0648\u062F\u0627\u0646\u202C\u200E)","ss","211"],["Spain (Espa\xF1a)","es","34"],["Sri Lanka (\u0DC1\u0DCA\u200D\u0DBB\u0DD3 \u0DBD\u0D82\u0D9A\u0DCF\u0DC0)","lk","94"],["Sudan (\u202B\u0627\u0644\u0633\u0648\u062F\u0627\u0646\u202C\u200E)","sd","249"],["Suriname","sr","597"],["Svalbard and Jan Mayen","sj","47",1,["79"]],["Sweden (Sverige)","se","46"],["Switzerland (Schweiz)","ch","41"],["Syria (\u202B\u0633\u0648\u0631\u064A\u0627\u202C\u200E)","sy","963"],["Taiwan (\u53F0\u7063)","tw","886"],["Tajikistan","tj","992"],["Tanzania","tz","255"],["Thailand (\u0E44\u0E17\u0E22)","th","66"],["Timor-Leste","tl","670"],["Togo","tg","228"],["Tokelau","tk","690"],["Tonga","to","676"],["Trinidad and Tobago","tt","1",22,["868"]],["Tristan da Cunha","ta","290"],["Tunisia (\u202B\u062A\u0648\u0646\u0633\u202C\u200E)","tn","216"],["Turkey (T\xFCrkiye)","tr","90"],["Turkmenistan","tm","993"],["Turks and Caicos Islands","tc","1",23,["649"]],["Tuvalu","tv","688"],["U.S. Virgin Islands","vi","1",24,["340"]],["Uganda","ug","256"],["Ukraine (\u0423\u043A\u0440\u0430\u0457\u043D\u0430)","ua","380"],["United Arab Emirates (\u202B\u0627\u0644\u0625\u0645\u0627\u0631\u0627\u062A \u0627\u0644\u0639\u0631\u0628\u064A\u0629 \u0627\u0644\u0645\u062A\u062D\u062F\u0629\u202C\u200E)","ae","971"],["United Kingdom","gb","44",0],["United States","us","1",0],["Uruguay","uy","598"],["Uzbekistan (O\u02BBzbekiston)","uz","998"],["Vanuatu","vu","678"],["Vatican City (Citt\xE0 del Vaticano)","va","39",1,["06698"]],["Venezuela","ve","58"],["Vietnam (Vi\u1EC7t Nam)","vn","84"],["Wallis and Futuna (Wallis-et-Futuna)","wf","681"],["Western Sahara (\u202B\u0627\u0644\u0635\u062D\u0631\u0627\u0621 \u0627\u0644\u063A\u0631\u0628\u064A\u0629\u202C\u200E)","eh","212",1,["5288","5289"]],["Yemen (\u202B\u0627\u0644\u064A\u0645\u0646\u202C\u200E)","ye","967"],["Zambia","zm","260"],["Zimbabwe","zw","263"],["\xC5land Islands","ax","358",1,["18"]]];N.map(n=>({areaCodes:n[4]||null,dialCode:n[2],id:n[1].toUpperCase(),iso2:n[1].toUpperCase(),label:`${n[0]} +${n[2]}`,name:n[0],priority:n[3]||0}));var s;(function(n){n[n.NONE=0]="NONE",n[n.DEBUG=1]="DEBUG",n[n.INFO=2]="INFO",n[n.NOTICE=3]="NOTICE",n[n.WARNING=4]="WARNING",n[n.ERROR=5]="ERROR",n[n.CRITICAL=6]="CRITICAL",n[n.ALERT=7]="ALERT",n[n.EMERGENCY=8]="EMERGENCY";})(s||(s={}));var B=r(n=>!!n&&n in s,"isValidLogLevel"),c=class{static{r(this,"BaseLoggerService");}logLevel;constructor(a){let e=a?.logLevel;this.logLevel=B(e)?e:"INFO";}setLogLevel(a){if(!B(a)){this.warn(`Invalid log level "${a}". Valid levels are: ${Object.keys(s).join(", ")}`);return}this.logLevel=a;}shouldSkipLog(a){if(this.logLevel==="NONE")return !0;let e=this.toLogLevelPriority(this.logLevel),i=this.toLogLevelPriority(a.logLevel??"INFO");return e>i}toLogLevelPriority(a){return s[a]}error(...a){return this.write({logLevel:"ERROR",logType:"error"},...a)}log(...a){return this.write({logLevel:"INFO",logType:"log"},...a)}info(...a){return this.write({logLevel:"INFO",logType:"info"},...a)}warn(...a){return this.write({logLevel:"WARNING",logType:"warn"},...a)}debug(...a){return this.write({logLevel:"DEBUG",logType:"debug"},...a)}getMessage(a){return typeof a=="string"?a:(typeof a=="object"&&a!==null&&!(a instanceof Error)&&(a=this._limitObjectOrArray(a)),JSON.stringify(a,k,2))}_limitObjectOrArray(a){if(a===null)return null;if(typeof a=="string")return a;if(Array.isArray(a))return a.map(i=>this._limitObjectOrArray(i));if(typeof a!="object")return a;let e={};for(let i in a){if(!Object.hasOwn(a,i))continue;let o=a[i],u=["thumbnailImageBase64","password","token","secret"];if(this.logLevel!=="DEBUG"&&u.includes(i)){e[i]=o?"...":void 0;continue}o===null?e[i]=null:typeof o=="string"?e[i]=o:o instanceof Error?e[i]={...o,message:o.message,name:o.name,stack:o.stack}:typeof o=="object"&&!(o instanceof Error)?e[i]=this._limitObjectOrArray(o):e[i]=JSON.stringify(o,k,2);}return e}},k=r((n,a)=>a instanceof Error?{...a,message:a.message,name:a.name,stack:a.stack}:a,"stringyReplacer");var y=class extends d{static{r(this,"BasicTimer");}},v=class extends c{static{r(this,"BasicLoggerService");}write(a,...e){try{if(this.shouldSkipLog(a))return;let{logType:i,message:o}=a,u=console[i??"log"];u(i,o);for(let T of e)u(this.getMessage(T));u(` `);}catch{}}createTimer(){return new y}},t=new v;var h=class n{static{r(this,"BaseClass");}_className;static _logger=t;constructor({className:a}){this._className=a;}async dispose(){return this.debug("dispose"),Promise.resolve()}debug(...a){this._write({logLevel:"DEBUG",logType:"debug"},...a);}info(...a){this._write({logLevel:"INFO",logType:"info"},...a);}warn(...a){this._write({logLevel:"WARNING",logType:"warn"},...a);}error(...a){this._write({logLevel:"ERROR",logType:"error"},...a);}log(...a){this._write({logLevel:"INFO",logType:"log"},...a);}createObserver(){let a=[];return {publish:e=>{for(let i of a)i(e);},subscribe:e=>(a.push(e),()=>{a=a.filter(i=>i!==e);})}}createLiteObserver(){let a;return {publish:e=>{a&&a(e);},subscribe:e=>{a=e;}}}_write(a,...e){let o=`${new Date().toLocaleTimeString("en-US",{hour:"numeric",hour12:!1,minute:"numeric"})} [${this._className}] `;a.message?o+=a.message:typeof e[0]=="string"&&(o+=e.shift()),n._logger.write({...a,message:o},...e);}};var l=class extends Error{static{r(this,"MailVideoError");}type;message;constructor(a,e){super(e),this.type=a,this.message=e,this.name="MailVideoError";}};var M=r(n=>{let{body:a,secret:e,signature:i}=n,o=crypto.createHmac("sha256",e).update(JSON.stringify(a)).digest("hex");return i===`sha256=${o}`},"verifySignature");var p=r(n=>typeof n=="string"?JSON.parse(n):n instanceof Buffer?JSON.parse(n.toString("utf8")):n,"convertPayload"),P=r(n=>{let{type:a}=n;return typeof a=="string"},"isMailVideoEvent"),m=r(n=>{let a=p(n.payload);if(!M({body:a,secret:n.secret,signature:n.signature}))throw new Error("Invalid signature");if(!P(a))throw new Error("Invalid payload");return a},"constructMailVideoEvent"),S=r(async(n,a)=>{let{payload:e,type:i}=n,o=a[i];if(!o)throw new Error(`No action found for event type: ${i}`);await o(e);},"handleMailVideoEvent"),g=r(async n=>{let a=m(n);await S(a,n.actions);},"constructAndHandleMailVideoEvent");var b=class extends h{static{r(this,"MailVideo");}_secret;_verbose;constructor(a){super({...a,className:"MailVideoService"}),this._secret=a.secret,this._verbose=a.verbose??!1,this._verbose?t.setLogLevel("INFO"):this._flavor==="production"&&t.setLogLevel("NONE");}async fetchVideo(a){return this._callMailVideoBackendPackageEndpoint({payload:a,type:"fetchVideo"})}async createJWT(a){return this._callMailVideoBackendPackageEndpoint({payload:a,type:"createJWT"})}constructAndHandleEvent(a){return g(a)}startVideoProcess(a){return this._callMailVideoBackendPackageEndpoint({payload:a,type:"startVideoProcess"})}constructEvent(a){return m(a)}handleEvent(a,e){return S(a,e)}constructAndHandleMailVideoEvent(a){return g(a)}get _flavor(){let a=this._secret;switch(!0){case a.startsWith("sk_dev"):return "development";case a.startsWith("sk_stage"):return "staging";case a.startsWith("sk_local"):return "local";default:return "production"}}get _mailvideoBackendPackageEndpointURL(){switch(this._flavor){case"development":return "https://backend-package-yu5dxvsfeq-ew.a.run.app";case"staging":return "https://backend-package-sfpefafcha-ew.a.run.app";case"local":return "https://backend-package-yu5dxvsfeq-ew.a.run.app";default:return "https://backend-package-jr2ohcgt7a-ew.a.run.app"}}async _callMailVideoBackendPackageEndpoint(a){try{this.debug("_callMailVideoBackendPackageEndpoint:options",a);let e=await fetch(this._mailvideoBackendPackageEndpointURL,{body:JSON.stringify(a),headers:{"Content-Type":"application/json",[A]:this._secret},method:"POST"});if(this.debug("_callMailVideoBackendPackageEndpoint:response",e),!e.ok)throw e.status===401?new l("invalid-secret","Invalid secret key"):e.status===404||e.status===500?new l("connection-failed","Connection failed"):new l("unknown",e.statusText);let i=e.headers.get("Content-Type");return i&&i.includes("application/json")?await e.json():await e.text()}catch(e){throw this.error("_callMailVideoBackendPackageEndpoint:error",e),e instanceof l?e:new l("unknown","An unexpected error occurred")}}}; exports.MailVideo = b; exports.constructAndHandleMailVideoEvent = g; exports.constructMailVideoEvent = m; exports.handleMailVideoEvent = S; //# sourceMappingURL=out.js.map //# sourceMappingURL=index.cjs.map