Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@automationcloud/client

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automationcloud/client - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

2

dist/automationcloud.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AutomationCloud=e():t.AutomationCloud=e()}(self,(function(){return t={739:t=>{self,t.exports=(()=>{"use strict";var t={300:(t,e)=>{var n=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==n)return n;throw new Error("unable to locate global object")}();t.exports=e=n.fetch,n.fetch&&(e.default=n.fetch.bind(n)),e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response},395:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AuthAgent=void 0,e.AuthAgent=class{}},614:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BasicAuthAgent=void 0;const s=n(395),r=n(20);class o extends s.AuthAgent{constructor(t){super(),this.params=t}async getHeader(){const{username:t,password:e}=this.params,n=`${t}:${e}`;return"Basic "+r.toBase64(n)}invalidate(){}}e.BasicAuthAgent=o},924:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BearerAuthAgent=void 0;const s=n(395);class r extends s.AuthAgent{constructor(t){super(),this.params=t}async getHeader(){const{prefix:t="Bearer",token:e}=this.params;return e?`${t} ${e}`:null}invalidate(){}}e.BearerAuthAgent=r},12:function(t,e,n){var s=this&&this.__createBinding||(Object.create?function(t,e,n,s){void 0===s&&(s=n),Object.defineProperty(t,s,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,s){void 0===s&&(s=n),t[s]=e[n]}),r=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||e.hasOwnProperty(n)||s(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),r(n(26),e),r(n(614),e),r(n(924),e),r(n(890),e),r(n(658),e)},26:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.NoAuthAgent=void 0;const s=n(395);class r extends s.AuthAgent{async getHeader(){return null}invalidate(){}}e.NoAuthAgent=r},890:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AuthNotSupportedError=e.OAuth1Agent=void 0;const s=n(395),r=n(222);class o extends s.AuthAgent{async getHeader(t){throw new i}invalidate(){}}e.OAuth1Agent=o;class i extends r.Exception{constructor(){super("This auth agent is not supported in browser environment.")}}e.AuthNotSupportedError=i},658:function(t,e,n){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.OAuth2Agent=e.OAuth2GrantType=void 0;const r=n(458),o=s(n(91)),i=n(395);var a;!function(t){t.CLIENT_CREDENTIALS="client_credentials",t.REFRESH_TOKEN="refresh_token",t.AUTHORIZATION_CODE="authorization_code",t.PASSWORD="password"}(a=e.OAuth2GrantType||(e.OAuth2GrantType={}));class c extends i.AuthAgent{constructor(t){super(),this.params=Object.assign({fetch:o.default},t)}async getHeader(){const t=await this.getAccessToken();return t?"Bearer "+t:null}async createToken(t){const{tokenUrl:e,fetch:n}=this.params,s=new r.Request({fetch:n}),o=Object.entries(t).filter((([t,e])=>null!=e)),i=await s.send("post",e,{body:new URLSearchParams(o)}),a=await i.json();return{accessToken:a.access_token,accessExpiresIn:a.expires_in,refreshToken:a.refresh_token}}setTokens(t){const{accessToken:e,accessExpiresIn:n,refreshToken:s}=t,r=n?Date.now()+1e3*n:null;this.params.accessToken=e,this.params.expiresAt=r,s&&(this.params.refreshToken=s)}invalidate(){this.params.accessToken=null,this.params.expiresAt=null}async getAccessToken(){const t=[this.tryCachedAccessToken,this.tryRefreshToken,this.tryClientSecret];for(const e of t)try{const t=await e.call(this);if(t)return t}catch(t){this.invalidate()}return null}async tryCachedAccessToken(){const{accessToken:t,expiresAt:e,minValiditySeconds:n=300}=this.params;return t&&(null==e||e-1e3*n>Date.now())?t:null}async tryRefreshToken(){const{refreshToken:t,clientId:e,clientSecret:n}=this.params;if(!t)return null;try{const s=await this.createToken({grant_type:a.REFRESH_TOKEN,client_id:e,client_secret:n,refresh_token:t});return this.setTokens(s),s.accessToken}catch(t){throw this.params.refreshToken=null,t}}async tryClientSecret(){const{clientId:t,clientSecret:e}=this.params;if(!e)return null;const n=await this.createToken({grant_type:a.CLIENT_CREDENTIALS,client_id:t,client_secret:e});return this.setTokens(n),n.accessToken}}e.OAuth2Agent=c},222:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Exception=void 0;class n extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500,this.details={}}}e.Exception=n},91:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default="undefined"!=typeof window&&window.fetch?fetch.bind(window):n(300)},863:function(t,e,n){var s=this&&this.__createBinding||(Object.create?function(t,e,n,s){void 0===s&&(s=n),Object.defineProperty(t,s,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,s){void 0===s&&(s=n),t[s]=e[n]}),r=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||e.hasOwnProperty(n)||s(e,t,n)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Response=void 0,r(n(458),e),r(n(395),e),r(n(12),e),r(n(157),e),r(n(687),e);const i=o(n(210));e.Response=i.default},458:function(t,e,n){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.RequestFailedError=e.Request=e.DEFAULT_REQUEST_CONFIG=e.NETWORK_ERRORS=void 0;const r=n(222),o=n(12),i=s(n(91));e.NETWORK_ERRORS=["EAI_AGAIN","EHOSTDOWN","EHOSTUNREACH","ECONNABORTED","ECONNREFUSED","ECONNRESET","EPIPE"],e.DEFAULT_REQUEST_CONFIG={baseUrl:"",auth:new o.NoAuthAgent,retryAttempts:4,retryDelay:500,retryDelayIncrement:500,retryStatusCodes:[429,502,503,504],authInvalidateStatusCodes:[401,403],authInvalidateInterval:6e4,headers:{},fetch:i.default},e.Request=class{constructor(t){this.authInvalidatedAt=0,this.config=Object.assign(Object.assign({},e.DEFAULT_REQUEST_CONFIG),t)}async get(t,e={}){return await this.sendJson("get",t,e)}async post(t,e={}){return await this.sendJson("post",t,e)}async put(t,e={}){return await this.sendJson("put",t,e)}async delete(t,e={}){return await this.sendJson("delete",t,e)}async sendJson(t,e,n={}){const{body:s,query:r,headers:o}=n,i=await this.send(t,e,{headers:Object.assign({"content-type":"application/json"},o),query:r,body:s?JSON.stringify(s):null}),{status:a}=i;return 204===a||"0"===i.headers.get("content-length")?null:await i.json()}async send(t,n,s={}){var r,o,i;const{fetch:a}=this.config,c=Math.max(this.config.retryAttempts+1,1);let u,l;for(let h=0;h<c;h++){let c=!1,d=this.config.retryDelay+this.config.retryDelayIncrement*h;try{const e=await this.prepareRequestSpec(t,n,s),r=await a(e.url,{method:e.method,headers:e.headers,body:e.body});if(!r.ok)throw this.config.authInvalidateStatusCodes.includes(r.status)?(c=Date.now()-this.authInvalidatedAt>this.config.authInvalidateInterval,this.authInvalidatedAt=Date.now(),d=0,this.config.auth.invalidate()):c=this.config.retryStatusCodes.includes(r.status),await this.createErrorFromResponse(e,r);return r}catch(a){const h=null===(r=a.details)||void 0===r?void 0:r.status,p=null===(o=a.details)||void 0===o?void 0:o.statusText,f={method:t,url:n,headers:null!==(i=s.headers)&&void 0!==i?i:{},status:h,statusText:p};if(c||e.NETWORK_ERRORS.includes(a.code)){u=a,l=f,this.onRetry(a,f),await new Promise((t=>setTimeout(t,d)));continue}throw this.onError(a,f),a}}throw this.onError(u,l),u}async sendRaw(t,e,n={}){const s=await this.prepareRequestSpec(t,e,n),{fetch:r}=this.config;return await r(s.url,{method:s.method,headers:s.headers,body:s.body})}async prepareRequestSpec(t,e,n={}){var s,r;const{auth:o}=this.config,{body:i}=n,a=this.prepareUrl(e,n),c=null!==(s=await o.getHeader({url:a,method:t,body:i}))&&void 0!==s?s:"";return{method:t,url:a,headers:this.mergeHeaders({"content-type":null!==(r=this.inferContentTypeFromBody(i))&&void 0!==r?r:""},this.config.headers||{},{authorization:c},n.headers||{}),body:i}}prepareUrl(t,e){var n;const{baseUrl:s}=this.config,r=s&&"/"!==s.slice(-1)?s+"/":s,o=new URL("/"===t[0]?t.slice(1):t,r||void 0);return o.search=new URLSearchParams(Object.entries(null!==(n=e.query)&&void 0!==n?n:{})).toString(),o.toString()}inferContentTypeFromBody(t){switch(!0){case null==t:return null;case t instanceof URLSearchParams:return"application/x-www-form-urlencoded";case"object"==typeof t:return"application/json";case"string"==typeof t:return"text/plain";default:return null}}mergeHeaders(...t){const e={};for(const n of t)for(const[t,s]of Object.entries(n))s&&(e[t.toLowerCase()]=s);return e}async createErrorFromResponse(t,e){return new a(t,e)}onRetry(t,e){}onError(t,e){}};class a extends r.Exception{constructor(t,e){super(`Request failed: ${e.status} ${e.statusText}`),this.details={method:t.method,url:t.url,requestHeaders:t.headers,status:e.status,statusText:e.statusText},Object.defineProperty(this,"requestSpec",{enumerable:!1,value:t}),Object.defineProperty(this,"response",{enumerable:!1,value:e})}}e.RequestFailedError=a},210:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default="undefined"==typeof Response?n(300).Response:Response},157:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},20:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.toBase64=void 0,e.toBase64=function(t){return btoa(t)}},687:function(t,e,n){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.fetchMock=void 0;const r=s(n(210));e.fetchMock=function(t,e={},n){const s={called:!1,calledCount:0,params:[]},o=(o,i)=>new Promise(((a,c)=>{const u=Object.assign({status:200},t);if(s.called=!0,s.calledCount+=1,s.params.push({fullUrl:o,fetchOptions:i}),n)return c(n);a(new r.default(JSON.stringify(e),u))}));return o.spy=s,o}}},e={};return function n(s){if(e[s])return e[s].exports;var r=e[s]={exports:{}};return t[s].call(r.exports,r,r.exports,n),r.exports}(863)})()},729:t=>{"use strict";var e=Object.prototype.hasOwnProperty,n="~";function s(){}function r(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function o(t,e,s,o,i){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new r(s,o||t,i),c=n?n+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],a]:t._events[c].push(a):(t._events[c]=a,t._eventsCount++),t}function i(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(n=!1)),a.prototype.eventNames=function(){var t,s,r=[];if(0===this._eventsCount)return r;for(s in t=this._events)e.call(t,s)&&r.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.prototype.listeners=function(t){var e=n?n+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,o=s.length,i=new Array(o);r<o;r++)i[r]=s[r].fn;return i},a.prototype.listenerCount=function(t){var e=n?n+t:t,s=this._events[e];return s?s.fn?1:s.length:0},a.prototype.emit=function(t,e,s,r,o,i){var a=n?n+t:t;if(!this._events[a])return!1;var c,u,l=this._events[a],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,s),!0;case 4:return l.fn.call(l.context,e,s,r),!0;case 5:return l.fn.call(l.context,e,s,r,o),!0;case 6:return l.fn.call(l.context,e,s,r,o,i),!0}for(u=1,c=new Array(h-1);u<h;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var d,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),h){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,s);break;case 4:l[u].fn.call(l[u].context,e,s,r);break;default:if(!c)for(d=1,c=new Array(h-1);d<h;d++)c[d-1]=arguments[d];l[u].fn.apply(l[u].context,c)}}return!0},a.prototype.on=function(t,e,n){return o(this,t,e,n,!1)},a.prototype.once=function(t,e,n){return o(this,t,e,n,!0)},a.prototype.removeListener=function(t,e,s,r){var o=n?n+t:t;if(!this._events[o])return this;if(!e)return i(this,o),this;var a=this._events[o];if(a.fn)a.fn!==e||r&&!a.once||s&&a.context!==s||i(this,o);else{for(var c=0,u=[],l=a.length;c<l;c++)(a[c].fn!==e||r&&!a[c].once||s&&a[c].context!==s)&&u.push(a[c]);u.length?this._events[o]=1===u.length?u[0]:u:i(this,o)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&i(this,e)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a},330:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AcApi=void 0;const s=n(31);e.AcApi=class{constructor(t){this.client=t;const e=this.client.config;this.request=s.AcRequest.create(e,e.apiUrl)}get logger(){return this.client.logger}async createJob(t){const{serviceId:e,category:n,input:s}=t;return await this.request.post("/jobs",{body:{serviceId:e,category:n,input:s}})}async getJob(t){return await this.request.get(`/jobs/${t}`)}async getJobAccessToken(t){return(await this.request.get(`/jobs/${t}/end-user`)).token}async getJobEvents(t,e){const{data:n}=await this.request.get(`/jobs/${t}/events`,{query:{offset:e}});return n}async getJobOutput(t,e){var n;try{return await this.request.get(`/jobs/${t}/outputs/${e}`)}catch(t){if(404===(null===(n=t.details)||void 0===n?void 0:n.status))return null;throw t}}async sendJobInput(t,e,n){return await this.request.post(`/jobs/${t}/inputs`,{body:{key:e,data:n}})}async cancelJob(t){await this.request.post(`/jobs/${t}/cancel`)}async queryPreviousOutputs(t,e,n=[]){const{data:s}=await this.request.post(`/services/${t}/previous-job-outputs`,{body:{inputs:n},query:{key:e}});return s}}},31:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AcRequest=void 0;const s=n(739);class r extends s.Request{static create(t,e){const n=this.createAuthAgent(t);return new r({baseUrl:e,auth:n,retryAttempts:t.requestRetryCount,retryDelay:t.requestRetryDelay,headers:t.additionalHeaders})}static createAuthAgent(t){const e=t.auth;return e?"string"==typeof e?new s.BasicAuthAgent({username:e}):new s.OAuth2Agent({clientId:e.clientId,clientSecret:e.clientSecret,tokenUrl:t.apiTokenUrl}):new s.NoAuthAgent}async createErrorFromResponse(t,e){var n;if(null===(n=e.headers.get("content-type"))||void 0===n?void 0:n.startsWith("application/json")){const t=await e.json();if(t.name&&t.message){const e=new Error(t.message);return e.name=t.name,e.code=t.code,e.details=t.details,e}}return super.createErrorFromResponse(t,e)}}e.AcRequest=r},396:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Vault=void 0;const s=n(31);function r(t){return"string"==typeof t?t:[t.name,t.label,t.placeholder].map((t=>t.replace(/_/g,""))).join("_")}e.Vault=class{constructor(t){this.client=t;const{config:e}=this.client;this.request=s.AcRequest.create(e,e.vaultUrl)}async createOtp(){const{id:t}=await this.request.post("/otp");return t}async createPanToken(t,e){const n=null!=e?e:await this.createOtp(),{panToken:s}=await this.request.post("/pan",{body:{otp:n,pan:t}});return s}getPaymentIframeUrl(t,e={}){var n,s,o;const i=[["otp",t],["css",e.cssUrl],["name",e.name],["fields",null===(n=e.fields)||void 0===n?void 0:n.map(r).join(",")],["brands",null===(s=e.brands)||void 0===s?void 0:s.join(",")],["validateOnInput",!0===e.validateOnInput?"on":void 0]].filter((t=>null!=t[1]));return(null!==(o=e.iframeUrl)&&void 0!==o?o:"https://vault.automationcloud.net/forms/index.html")+"?"+i.map((t=>{var e;return`${t[0]}=${encodeURIComponent(null!==(e=t[1])&&void 0!==e?e:"")}`})).join("&")}getSingleInputIframeUrl(t,e={}){var n;const s=[["otp",t],["css",e.cssUrl],["inputType",e.inputType],["pattern",e.pattern],["minlength",e.minlength],["maxlength",e.maxlength],["required",e.required],["validateOnInput",!0===e.validateOnInput?"on":void 0]].filter((t=>null!=t[1]));return(null!==(n=e.iframeUrl)&&void 0!==n?n:"https://vault.automationcloud.net/forms/single-input.html")+"?"+s.map((t=>{var e;return`${t[0]}=${encodeURIComponent(null!==(e=t[1])&&void 0!==e?e:"")}`})).join("&")}}},967:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Client=void 0;const s=n(330),r=n(396),o=n(313),i=n(909),a=n(157);e.Client=class{constructor(t={}){this.logger=console,this.config=Object.assign({serviceId:null,auth:null,apiUrl:"https://api.automationcloud.net",apiTokenUrl:"https://auth.automationcloud.net/auth/realms/automationcloud/protocol/openid-connect/token",vaultUrl:"https://vault.automationcloud.net",pollInterval:1e3,requestRetryCount:4,requestRetryDelay:500,autoTrack:!0,additionalHeaders:{}},t),this.api=new s.AcApi(this),this.vault=new r.Vault(this)}async getJob(t){const e=new i.Job(this);return await e.trackExisting(t),e}async queryPreviousOutput(t,e=[]){const{serviceId:n}=this.config;if(!n)throw new o.ClientConfigError("serviceId is required to query previous outputs");const s=await this.api.queryPreviousOutputs(n,t,e);return s.length?s[0]:null}async createJob(t={}){return await this._createJob(Object.assign({serviceId:this.config.serviceId,category:a.JobCategory.TEST,input:{}},t))}async _createJob(t){const e=new i.Job(this,t);return await e.start(),e}}},313:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.JobTrackError=e.JobFailedError=e.JobOutputWaitError=e.JobAlreadyStartedError=e.JobNotInitializedError=e.ClientConfigError=void 0;const s=n(222);class r extends s.Exception{}e.ClientConfigError=r;class o extends s.Exception{constructor(){super("Invalid state: job not yet initialized")}}e.JobNotInitializedError=o;class i extends s.Exception{constructor(t={}){super("Job is already initialized"),this.details=t}}e.JobAlreadyStartedError=i;class a extends s.Exception{constructor(t,e={}){super(t),this.message=t,this.details=e}}e.JobOutputWaitError=a;class c extends s.Exception{constructor(t){var e,n,s;super(null!==(e=null==t?void 0:t.message)&&void 0!==e?e:"Unknown error"),this.name=null!==(n=null==t?void 0:t.code)&&void 0!==n?n:"UnknownError",this.details=Object.assign({category:null!==(s=null==t?void 0:t.category)&&void 0!==s?s:"server"},null==t?void 0:t.details)}}e.JobFailedError=c;class u extends s.Exception{constructor(t){super(`Job tracking failed: ${t.message}`),this.details={cause:t}}}e.JobTrackError=u},222:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Exception=void 0;class n extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500,this.details={}}}e.Exception=n},863:function(t,e,n){"use strict";var s=this&&this.__createBinding||(Object.create?function(t,e,n,s){void 0===s&&(s=n),Object.defineProperty(t,s,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,s){void 0===s&&(s=n),t[s]=e[n]}),r=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||s(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),r(n(330),e),r(n(396),e),r(n(967),e),r(n(313),e),r(n(222),e),r(n(909),e),r(n(273),e),r(n(157),e)},909:function(t,e,n){"use strict";var s=this&&this.__createBinding||(Object.create?function(t,e,n,s){void 0===s&&(s=n),Object.defineProperty(t,s,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,s){void 0===s&&(s=n),t[s]=e[n]}),r=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&s(e,t,n);return r(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.Job=void 0;const i=n(729),a=o(n(313)),c=n(157);e.Job=class{constructor(t,e={}){var n;this.client=t,this._events=new i.EventEmitter,this._inputsMap=new Map,this._outputsMap=new Map,this._state=c.JobState.CREATED,this._error=null,this._awaitingInputKey=null,this._trackPromise=null,this._jobId=null,this._jobEventOffset=0,this._isTracking=!1,this._initParams=Object.assign({serviceId:null!==(n=e.serviceId)&&void 0!==n?n:null,category:c.JobCategory.TEST,input:{}},e)}get jobId(){if(!this._jobId)throw new a.JobNotInitializedError;return this._jobId}async start(){if(this._jobId)throw new a.JobAlreadyStartedError(this.jobId);const{category:t,input:e}=this._initParams,{serviceId:n}=this._initParams;if(!n)throw new a.ClientConfigError("serviceId is required to start the job");const{id:s,state:r}=await this.api.createJob({serviceId:n,category:t,input:e});this._jobId=s,this._setState(r);for(const[t,n]of Object.entries(e))this._inputsMap.set(t,{key:t,data:n});this.client.config.autoTrack&&this.startTracking()}async trackExisting(t){if(this._jobId)throw new a.JobAlreadyStartedError({jobId:this.jobId});const{state:e,category:n}=await this.api.getJob(t);this._jobId=t,this._initParams.category=n,this._setState(e),this.startTracking()}startTracking(){this._trackPromise||(this._isTracking=!0,this._trackPromise=this._track(),this._trackPromise.catch((t=>{})).then((()=>{this._isTracking=!1,this._trackPromise=null})))}stopTracking(){this._isTracking=!1}getState(){return this._state}_setState(t){const e=this._state;this._state=t,this._events.emit("stateChanged",t,e)}getErrorInfo(){return this._error}getAwaitingInputKey(){return this._awaitingInputKey}async getAccessToken(){return await this.api.getJobAccessToken(this.jobId)}async submitInput(t,e){await this.api.sendJobInput(this.jobId,t,e),this._inputsMap.set(t,{key:t,data:e})}async getOutput(t){var e;let n=null!==(e=this._outputsMap.get(t))&&void 0!==e?e:null;return n||(n=await this.api.getJobOutput(this.jobId,t),n&&this._outputsMap.set(t,n)),null==n?void 0:n.data}async waitForCompletion(){await this._trackPromise}async cancel(){await this.api.cancelJob(this.jobId)}async waitForOutputs(...t){return await this._waitFor((()=>{const e=this._checkOutputs(t);if(null!=e)return e;if(this.getState()===c.JobState.FAIL)throw new a.JobOutputWaitError("Job failed, and specified outputs were not emitted",{state:this.getState(),jobId:this.jobId});if(this.getState()===c.JobState.SUCCESS)throw new a.JobOutputWaitError("Job succeeded, but specified outputs were not emitted",{state:this.getState(),jobId:this.jobId})}))}async _waitFor(t){return new Promise(((e,n)=>{const s=()=>{try{const n=t();void 0!==n&&(o(),e(n))}catch(t){o(),n(t)}},r=t=>{o(),n(t)},o=()=>{this._events.off("trackTick",s),this._events.off("trackError",r)};this._events.on("trackTick",s),this._events.on("trackError",r),s()}))}onAwaitingInput(t,e){return this._createJobEventHandler("awaitingInput",(async n=>{if("*"===t||n===t){const s=await e(n);void 0!==s&&await this.submitInput(t,s)}}))}onOutput(t,e){return this._createJobEventHandler("output",(async n=>{this._matchKey(t,n.key)&&await e(n.data)}))}onDynamicOutput(t,e){return this._createJobEventHandler("output",(async n=>{(n.key.startsWith(t+":")||this._matchKey(t,n.key))&&await e(n.key,n.data)}))}onAnyOutput(t){return this._createJobEventHandler("output",(async e=>{await t(e.key,e.data)}))}onOutputEvent(t,e){return this.onDynamicOutput("events",(async(n,s)=>{s&&"object"==typeof s&&this._matchKey(t,s.type)&&await e(s)}))}onStateChanged(t){return this._createJobEventHandler("stateChanged",t)}onSuccess(t){return this._createJobEventHandler("success",t)}onFail(t){return this._createJobEventHandler("fail",t)}async _track(){for(;this._isTracking;){const{pollInterval:t}=this.client.config;try{const t=await this.api.getJobEvents(this.jobId,this._jobEventOffset);this._jobEventOffset+=t.length;for(const e of t)await this._processJobEvent(e);this._events.emit("trackTick")}catch(t){const e=new a.JobTrackError(t);throw this._events.emit("trackError",e),e}switch(this._state){case c.JobState.SUCCESS:return;case c.JobState.FAIL:throw new a.JobFailedError(this._error)}await new Promise((e=>setTimeout(e,t)))}}async _processJobEvent(t){const e=t.key;switch(t.name){case"awaitingInput":this._setState(c.JobState.AWAITING_INPUT),this._awaitingInputKey=e,this._events.emit("awaitingInput",e);break;case"createOutput":{const t=await this.api.getJobOutput(this.jobId,e);if(t){const n=t.data;this._outputsMap.set(e,{key:e,data:n}),this._events.emit("output",{key:e,data:n})}}break;case"processing":this._setState(c.JobState.PROCESSING);break;case"success":this._setState(c.JobState.SUCCESS),this._events.emit("success");break;case"fail":{const{error:t}=await this.api.getJob(this.jobId);this._setState(c.JobState.FAIL),this._error=Object.assign({category:"server",code:"UnknownError",message:"Unknown error"},t);const e=new a.JobFailedError(this._error);this._events.emit("fail",e)}}}_checkOutputs(t){const e=[];for(const n of t){const t=this._outputsMap.get(n);if(!t)break;e.push(t.data)}return e.length===t.length?e:null}get api(){return this.client.api}_createJobEventHandler(t,e){const n=async(...t)=>{await e(...t)};return this._events.on(t,n),()=>this._events.off(t,n)}_matchKey(t,e){if(t.endsWith(":*")){const n=t.split(":")[0];return e.startsWith(n+":")}return e===t}}},273:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},157:(t,e)=>{"use strict";var n,s;Object.defineProperty(e,"__esModule",{value:!0}),e.JobCategory=e.JobState=void 0,(s=e.JobState||(e.JobState={})).CREATED="created",s.SCHEDULED="scheduled",s.PROCESSING="processing",s.AWAITING_INPUT="awaitingInput",s.AWAITING_TDS="awaitingTds",s.PENDING="pending",s.SUCCESS="success",s.FAIL="fail",(n=e.JobCategory||(e.JobCategory={})).LIVE="live",n.TEST="test"}},e={},function n(s){if(e[s])return e[s].exports;var r=e[s]={exports:{}};return t[s].call(r.exports,r,r.exports,n),r.exports}(863);var t,e}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AutomationCloud=e():t.AutomationCloud=e()}(self,(function(){return t={739:t=>{self,t.exports=(()=>{"use strict";var t={300:(t,e)=>{var s=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==s)return s;throw new Error("unable to locate global object")}();t.exports=e=s.fetch,s.fetch&&(e.default=s.fetch.bind(s)),e.Headers=s.Headers,e.Request=s.Request,e.Response=s.Response},395:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AuthAgent=void 0,e.AuthAgent=class{}},614:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BasicAuthAgent=void 0;const n=s(395),r=s(20);class o extends n.AuthAgent{constructor(t){super(),this.params=t}async getHeader(){const{username:t,password:e}=this.params,s=`${t}:${e}`;return"Basic "+r.toBase64(s)}invalidate(){}}e.BasicAuthAgent=o},924:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BearerAuthAgent=void 0;const n=s(395);class r extends n.AuthAgent{constructor(t){super(),this.params=t}async getHeader(){const{prefix:t="Bearer",token:e}=this.params;return e?`${t} ${e}`:null}invalidate(){}}e.BearerAuthAgent=r},12:function(t,e,s){var n=this&&this.__createBinding||(Object.create?function(t,e,s,n){void 0===n&&(n=s),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[s]}})}:function(t,e,s,n){void 0===n&&(n=s),t[n]=e[s]}),r=this&&this.__exportStar||function(t,e){for(var s in t)"default"===s||e.hasOwnProperty(s)||n(e,t,s)};Object.defineProperty(e,"__esModule",{value:!0}),r(s(26),e),r(s(614),e),r(s(924),e),r(s(890),e),r(s(658),e)},26:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.NoAuthAgent=void 0;const n=s(395);class r extends n.AuthAgent{async getHeader(){return null}invalidate(){}}e.NoAuthAgent=r},890:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.AuthNotSupportedError=e.OAuth1Agent=void 0;const n=s(395),r=s(222);class o extends n.AuthAgent{async getHeader(t){throw new i}invalidate(){}}e.OAuth1Agent=o;class i extends r.Exception{constructor(){super("This auth agent is not supported in browser environment.")}}e.AuthNotSupportedError=i},658:function(t,e,s){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.OAuth2Agent=e.OAuth2GrantType=void 0;const r=s(458),o=n(s(91)),i=s(395);var a;!function(t){t.CLIENT_CREDENTIALS="client_credentials",t.REFRESH_TOKEN="refresh_token",t.AUTHORIZATION_CODE="authorization_code",t.PASSWORD="password"}(a=e.OAuth2GrantType||(e.OAuth2GrantType={}));class c extends i.AuthAgent{constructor(t){super(),this.params=Object.assign({fetch:o.default},t)}async getHeader(){const t=await this.getAccessToken();return t?"Bearer "+t:null}async createToken(t){const{tokenUrl:e,fetch:s}=this.params,n=new r.Request({fetch:s}),o=Object.entries(t).filter((([t,e])=>null!=e)),i=await n.send("post",e,{body:new URLSearchParams(o)}),a=await i.json();return{accessToken:a.access_token,accessExpiresIn:a.expires_in,refreshToken:a.refresh_token}}setTokens(t){const{accessToken:e,accessExpiresIn:s,refreshToken:n}=t,r=s?Date.now()+1e3*s:null;this.params.accessToken=e,this.params.expiresAt=r,n&&(this.params.refreshToken=n)}invalidate(){this.params.accessToken=null,this.params.expiresAt=null}async getAccessToken(){const t=[this.tryCachedAccessToken,this.tryRefreshToken,this.tryClientSecret];for(const e of t)try{const t=await e.call(this);if(t)return t}catch(t){this.invalidate()}return null}async tryCachedAccessToken(){const{accessToken:t,expiresAt:e,minValiditySeconds:s=300}=this.params;return t&&(null==e||e-1e3*s>Date.now())?t:null}async tryRefreshToken(){const{refreshToken:t,clientId:e,clientSecret:s}=this.params;if(!t)return null;try{const n=await this.createToken({grant_type:a.REFRESH_TOKEN,client_id:e,client_secret:s,refresh_token:t});return this.setTokens(n),n.accessToken}catch(t){throw this.params.refreshToken=null,t}}async tryClientSecret(){const{clientId:t,clientSecret:e}=this.params;if(!e)return null;const s=await this.createToken({grant_type:a.CLIENT_CREDENTIALS,client_id:t,client_secret:e});return this.setTokens(s),s.accessToken}}e.OAuth2Agent=c},222:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Exception=void 0;class s extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500,this.details={}}}e.Exception=s},91:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default="undefined"!=typeof window&&window.fetch?fetch.bind(window):s(300)},863:function(t,e,s){var n=this&&this.__createBinding||(Object.create?function(t,e,s,n){void 0===n&&(n=s),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[s]}})}:function(t,e,s,n){void 0===n&&(n=s),t[n]=e[s]}),r=this&&this.__exportStar||function(t,e){for(var s in t)"default"===s||e.hasOwnProperty(s)||n(e,t,s)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Response=void 0,r(s(458),e),r(s(395),e),r(s(12),e),r(s(157),e),r(s(687),e);const i=o(s(210));e.Response=i.default},458:function(t,e,s){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.RequestFailedError=e.Request=e.DEFAULT_REQUEST_CONFIG=e.NETWORK_ERRORS=void 0;const r=s(222),o=s(12),i=n(s(91));e.NETWORK_ERRORS=["EAI_AGAIN","EHOSTDOWN","EHOSTUNREACH","ECONNABORTED","ECONNREFUSED","ECONNRESET","EPIPE"],e.DEFAULT_REQUEST_CONFIG={baseUrl:"",auth:new o.NoAuthAgent,retryAttempts:4,retryDelay:500,retryDelayIncrement:500,retryStatusCodes:[429,502,503,504],authInvalidateStatusCodes:[401,403],authInvalidateInterval:6e4,headers:{},fetch:i.default},e.Request=class{constructor(t){this.authInvalidatedAt=0,this.config=Object.assign(Object.assign({},e.DEFAULT_REQUEST_CONFIG),t)}async get(t,e={}){return await this.sendJson("get",t,e)}async post(t,e={}){return await this.sendJson("post",t,e)}async put(t,e={}){return await this.sendJson("put",t,e)}async delete(t,e={}){return await this.sendJson("delete",t,e)}async sendJson(t,e,s={}){const{body:n,query:r,headers:o}=s,i=await this.send(t,e,{headers:Object.assign({"content-type":"application/json"},o),query:r,body:n?JSON.stringify(n):null}),{status:a}=i;return 204===a||"0"===i.headers.get("content-length")?null:await i.json()}async send(t,s,n={}){var r,o,i;const{fetch:a}=this.config,c=Math.max(this.config.retryAttempts+1,1);let u,l;for(let h=0;h<c;h++){let c=!1,d=this.config.retryDelay+this.config.retryDelayIncrement*h;try{const e=await this.prepareRequestSpec(t,s,n),r=await a(e.url,{method:e.method,headers:e.headers,body:e.body});if(!r.ok)throw this.config.authInvalidateStatusCodes.includes(r.status)?(c=Date.now()-this.authInvalidatedAt>this.config.authInvalidateInterval,this.authInvalidatedAt=Date.now(),d=0,this.config.auth.invalidate()):c=this.config.retryStatusCodes.includes(r.status),await this.createErrorFromResponse(e,r);return r}catch(a){const h=null===(r=a.details)||void 0===r?void 0:r.status,p=null===(o=a.details)||void 0===o?void 0:o.statusText,f={method:t,url:s,headers:null!==(i=n.headers)&&void 0!==i?i:{},status:h,statusText:p};if(c||e.NETWORK_ERRORS.includes(a.code)){u=a,l=f,this.onRetry(a,f),await new Promise((t=>setTimeout(t,d)));continue}throw this.onError(a,f),a}}throw this.onError(u,l),u}async sendRaw(t,e,s={}){const n=await this.prepareRequestSpec(t,e,s),{fetch:r}=this.config;return await r(n.url,{method:n.method,headers:n.headers,body:n.body})}async prepareRequestSpec(t,e,s={}){var n,r;const{auth:o}=this.config,{body:i}=s,a=this.prepareUrl(e,s),c=null!==(n=await o.getHeader({url:a,method:t,body:i}))&&void 0!==n?n:"";return{method:t,url:a,headers:this.mergeHeaders({"content-type":null!==(r=this.inferContentTypeFromBody(i))&&void 0!==r?r:""},this.config.headers||{},{authorization:c},s.headers||{}),body:i}}prepareUrl(t,e){var s;const{baseUrl:n}=this.config,r=n&&"/"!==n.slice(-1)?n+"/":n,o=new URL("/"===t[0]?t.slice(1):t,r||void 0);return o.search=new URLSearchParams(Object.entries(null!==(s=e.query)&&void 0!==s?s:{})).toString(),o.toString()}inferContentTypeFromBody(t){switch(!0){case null==t:return null;case t instanceof URLSearchParams:return"application/x-www-form-urlencoded";case"object"==typeof t:return"application/json";case"string"==typeof t:return"text/plain";default:return null}}mergeHeaders(...t){const e={};for(const s of t)for(const[t,n]of Object.entries(s))n&&(e[t.toLowerCase()]=n);return e}async createErrorFromResponse(t,e){return new a(t,e)}onRetry(t,e){}onError(t,e){}};class a extends r.Exception{constructor(t,e){super(`Request failed: ${e.status} ${e.statusText}`),this.details={method:t.method,url:t.url,requestHeaders:t.headers,status:e.status,statusText:e.statusText},Object.defineProperty(this,"requestSpec",{enumerable:!1,value:t}),Object.defineProperty(this,"response",{enumerable:!1,value:e})}}e.RequestFailedError=a},210:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default="undefined"==typeof Response?s(300).Response:Response},157:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},20:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.toBase64=void 0,e.toBase64=function(t){return btoa(t)}},687:function(t,e,s){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.fetchMock=void 0;const r=n(s(210));e.fetchMock=function(t,e={},s){const n={called:!1,calledCount:0,params:[]},o=(o,i)=>new Promise(((a,c)=>{const u=Object.assign({status:200},t);if(n.called=!0,n.calledCount+=1,n.params.push({fullUrl:o,fetchOptions:i}),s)return c(s);a(new r.default(JSON.stringify(e),u))}));return o.spy=n,o}}},e={};return function s(n){if(e[n])return e[n].exports;var r=e[n]={exports:{}};return t[n].call(r.exports,r,r.exports,s),r.exports}(863)})()},729:t=>{"use strict";var e=Object.prototype.hasOwnProperty,s="~";function n(){}function r(t,e,s){this.fn=t,this.context=e,this.once=s||!1}function o(t,e,n,o,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new r(n,o||t,i),c=s?s+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],a]:t._events[c].push(a):(t._events[c]=a,t._eventsCount++),t}function i(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(s=!1)),a.prototype.eventNames=function(){var t,n,r=[];if(0===this._eventsCount)return r;for(n in t=this._events)e.call(t,n)&&r.push(s?n.slice(1):n);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.prototype.listeners=function(t){var e=s?s+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,o=n.length,i=new Array(o);r<o;r++)i[r]=n[r].fn;return i},a.prototype.listenerCount=function(t){var e=s?s+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,r,o,i){var a=s?s+t:t;if(!this._events[a])return!1;var c,u,l=this._events[a],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,n),!0;case 4:return l.fn.call(l.context,e,n,r),!0;case 5:return l.fn.call(l.context,e,n,r,o),!0;case 6:return l.fn.call(l.context,e,n,r,o,i),!0}for(u=1,c=new Array(h-1);u<h;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var d,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),h){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,n);break;case 4:l[u].fn.call(l[u].context,e,n,r);break;default:if(!c)for(d=1,c=new Array(h-1);d<h;d++)c[d-1]=arguments[d];l[u].fn.apply(l[u].context,c)}}return!0},a.prototype.on=function(t,e,s){return o(this,t,e,s,!1)},a.prototype.once=function(t,e,s){return o(this,t,e,s,!0)},a.prototype.removeListener=function(t,e,n,r){var o=s?s+t:t;if(!this._events[o])return this;if(!e)return i(this,o),this;var a=this._events[o];if(a.fn)a.fn!==e||r&&!a.once||n&&a.context!==n||i(this,o);else{for(var c=0,u=[],l=a.length;c<l;c++)(a[c].fn!==e||r&&!a[c].once||n&&a[c].context!==n)&&u.push(a[c]);u.length?this._events[o]=1===u.length?u[0]:u:i(this,o)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=s?s+t:t,this._events[e]&&i(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=s,a.EventEmitter=a,t.exports=a},330:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AcApi=void 0;const n=s(31);e.AcApi=class{constructor(t){this.client=t;const e=this.client.config;this.request=n.AcRequest.create(e,e.apiUrl)}get logger(){return this.client.logger}async createJob(t){const{serviceId:e,category:s,input:n}=t;return await this.request.post("/jobs",{body:{serviceId:e,category:s,input:n}})}async getJob(t){return await this.request.get(`/jobs/${t}`)}async getJobAccessToken(t){return(await this.request.get(`/jobs/${t}/end-user`)).token}async getJobEvents(t,e){const{data:s}=await this.request.get(`/jobs/${t}/events`,{query:{offset:e}});return s}async getJobOutput(t,e){var s;try{return await this.request.get(`/jobs/${t}/outputs/${e}`)}catch(t){if(404===(null===(s=t.details)||void 0===s?void 0:s.status))return null;throw t}}async sendJobInput(t,e,s){return await this.request.post(`/jobs/${t}/inputs`,{body:{key:e,data:s}})}async cancelJob(t){await this.request.post(`/jobs/${t}/cancel`)}async queryPreviousOutputs(t,e,s=[]){const{data:n}=await this.request.post(`/services/${t}/previous-job-outputs`,{body:{inputs:s},query:{key:e}});return n}async getTdsForJob(t){const e=await this.getJob(t);return await this.request.get(`/3d-secure/${e.tdsId}`)}}},31:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AcRequest=void 0;const n=s(739);class r extends n.Request{static create(t,e){const s=this.createAuthAgent(t);return new r({baseUrl:e,auth:s,retryAttempts:t.requestRetryCount,retryDelay:t.requestRetryDelay,headers:t.additionalHeaders})}static createAuthAgent(t){const e=t.auth;return e?"string"==typeof e?new n.BasicAuthAgent({username:e}):new n.OAuth2Agent({clientId:e.clientId,clientSecret:e.clientSecret,tokenUrl:t.apiTokenUrl}):new n.NoAuthAgent}async createErrorFromResponse(t,e){var s;if(null===(s=e.headers.get("content-type"))||void 0===s?void 0:s.startsWith("application/json")){const t=await e.json();if(t.name&&t.message){const e=new Error(t.message);return e.name=t.name,e.code=t.code,e.details=t.details,e}}return super.createErrorFromResponse(t,e)}}e.AcRequest=r},396:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Vault=void 0;const n=s(31);function r(t){return"string"==typeof t?t:[t.name,t.label,t.placeholder].map((t=>t.replace(/_/g,""))).join("_")}e.Vault=class{constructor(t){this.client=t;const{config:e}=this.client;this.request=n.AcRequest.create(e,e.vaultUrl)}async createOtp(){const{id:t}=await this.request.post("/otp");return t}async createPanToken(t,e){const s=null!=e?e:await this.createOtp(),{panToken:n}=await this.request.post("/pan",{body:{otp:s,pan:t}});return n}getPaymentIframeUrl(t,e={}){var s,n,o;const i=[["otp",t],["css",e.cssUrl],["name",e.name],["fields",null===(s=e.fields)||void 0===s?void 0:s.map(r).join(",")],["brands",null===(n=e.brands)||void 0===n?void 0:n.join(",")],["validateOnInput",!0===e.validateOnInput?"on":void 0]].filter((t=>null!=t[1]));return(null!==(o=e.iframeUrl)&&void 0!==o?o:"https://vault.automationcloud.net/forms/index.html")+"?"+i.map((t=>{var e;return`${t[0]}=${encodeURIComponent(null!==(e=t[1])&&void 0!==e?e:"")}`})).join("&")}getSingleInputIframeUrl(t,e={}){var s;const n=[["otp",t],["css",e.cssUrl],["inputType",e.inputType],["pattern",e.pattern],["minlength",e.minlength],["maxlength",e.maxlength],["required",e.required],["validateOnInput",!0===e.validateOnInput?"on":void 0]].filter((t=>null!=t[1]));return(null!==(s=e.iframeUrl)&&void 0!==s?s:"https://vault.automationcloud.net/forms/single-input.html")+"?"+n.map((t=>{var e;return`${t[0]}=${encodeURIComponent(null!==(e=t[1])&&void 0!==e?e:"")}`})).join("&")}}},967:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Client=void 0;const n=s(330),r=s(396),o=s(313),i=s(909),a=s(157);e.Client=class{constructor(t={}){this.logger=console,this.config=Object.assign({serviceId:null,auth:null,apiUrl:"https://api.automationcloud.net",apiTokenUrl:"https://auth.automationcloud.net/auth/realms/automationcloud/protocol/openid-connect/token",vaultUrl:"https://vault.automationcloud.net",pollInterval:1e3,requestRetryCount:4,requestRetryDelay:500,autoTrack:!0,additionalHeaders:{}},t),this.api=new n.AcApi(this),this.vault=new r.Vault(this)}async getJob(t){const e=new i.Job(this);return await e.trackExisting(t),e}async queryPreviousOutput(t,e=[]){const{serviceId:s}=this.config;if(!s)throw new o.ClientConfigError("serviceId is required to query previous outputs");const n=await this.api.queryPreviousOutputs(s,t,e);return n.length?n[0]:null}async createJob(t={}){return await this._createJob(Object.assign({serviceId:this.config.serviceId,category:a.JobCategory.TEST,input:{}},t))}async _createJob(t){const e=new i.Job(this,t);return await e.start(),e}}},313:(t,e,s)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.JobTrackError=e.JobFailedError=e.JobOutputWaitError=e.JobAlreadyStartedError=e.JobNotInitializedError=e.ClientConfigError=void 0;const n=s(222);class r extends n.Exception{}e.ClientConfigError=r;class o extends n.Exception{constructor(){super("Invalid state: job not yet initialized")}}e.JobNotInitializedError=o;class i extends n.Exception{constructor(t={}){super("Job is already initialized"),this.details=t}}e.JobAlreadyStartedError=i;class a extends n.Exception{constructor(t,e={}){super(t),this.message=t,this.details=e}}e.JobOutputWaitError=a;class c extends n.Exception{constructor(t){var e,s,n;super(null!==(e=null==t?void 0:t.message)&&void 0!==e?e:"Unknown error"),this.name=null!==(s=null==t?void 0:t.code)&&void 0!==s?s:"UnknownError",this.details=Object.assign({category:null!==(n=null==t?void 0:t.category)&&void 0!==n?n:"server"},null==t?void 0:t.details)}}e.JobFailedError=c;class u extends n.Exception{constructor(t){super(`Job tracking failed: ${t.message}`),this.details={cause:t}}}e.JobTrackError=u},222:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Exception=void 0;class s extends Error{constructor(){super(...arguments),this.name=this.constructor.name,this.status=500,this.details={}}}e.Exception=s},863:function(t,e,s){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,s,n){void 0===n&&(n=s),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[s]}})}:function(t,e,s,n){void 0===n&&(n=s),t[n]=e[s]}),r=this&&this.__exportStar||function(t,e){for(var s in t)"default"===s||Object.prototype.hasOwnProperty.call(e,s)||n(e,t,s)};Object.defineProperty(e,"__esModule",{value:!0}),r(s(330),e),r(s(396),e),r(s(967),e),r(s(313),e),r(s(222),e),r(s(909),e),r(s(273),e),r(s(157),e)},909:function(t,e,s){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,s,n){void 0===n&&(n=s),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[s]}})}:function(t,e,s,n){void 0===n&&(n=s),t[n]=e[s]}),r=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var s in t)"default"!==s&&Object.prototype.hasOwnProperty.call(t,s)&&n(e,t,s);return r(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.Job=void 0;const i=s(729),a=o(s(313)),c=s(157);e.Job=class{constructor(t,e={}){var s;this.client=t,this._events=new i.EventEmitter,this._inputsMap=new Map,this._outputsMap=new Map,this._state=c.JobState.CREATED,this._error=null,this._awaitingInputKey=null,this._trackPromise=null,this._jobId=null,this._jobEventOffset=0,this._isTracking=!1,this._initParams=Object.assign({serviceId:null!==(s=e.serviceId)&&void 0!==s?s:null,category:c.JobCategory.TEST,input:{}},e)}get jobId(){if(!this._jobId)throw new a.JobNotInitializedError;return this._jobId}async start(){if(this._jobId)throw new a.JobAlreadyStartedError(this.jobId);const{category:t,input:e}=this._initParams,{serviceId:s}=this._initParams;if(!s)throw new a.ClientConfigError("serviceId is required to start the job");const{id:n,state:r}=await this.api.createJob({serviceId:s,category:t,input:e});this._jobId=n,this._setState(r);for(const[t,s]of Object.entries(e))this._inputsMap.set(t,{key:t,data:s});this.client.config.autoTrack&&this.startTracking()}async trackExisting(t){if(this._jobId)throw new a.JobAlreadyStartedError({jobId:this.jobId});const{state:e,category:s}=await this.api.getJob(t);this._jobId=t,this._initParams.category=s,this._setState(e),this.startTracking()}startTracking(){this._trackPromise||(this._isTracking=!0,this._trackPromise=this._track(),this._trackPromise.catch((t=>{})).then((()=>{this._isTracking=!1,this._trackPromise=null})))}stopTracking(){this._isTracking=!1}getState(){return this._state}_setState(t){const e=this._state;this._state=t,this._events.emit("stateChanged",t,e)}getErrorInfo(){return this._error}getAwaitingInputKey(){return this._awaitingInputKey}async getAccessToken(){return await this.api.getJobAccessToken(this.jobId)}async submitInput(t,e){await this.api.sendJobInput(this.jobId,t,e),this._inputsMap.set(t,{key:t,data:e})}async getOutput(t){var e;let s=null!==(e=this._outputsMap.get(t))&&void 0!==e?e:null;return s||(s=await this.api.getJobOutput(this.jobId,t),s&&this._outputsMap.set(t,s)),null==s?void 0:s.data}async getTds(){return await this.api.getTdsForJob(this.jobId)}async waitForCompletion(){await this._trackPromise}async cancel(){await this.api.cancelJob(this.jobId)}async waitForOutputs(...t){return await this._waitFor((()=>{const e=this._checkOutputs(t);if(null!=e)return e;if(this.getState()===c.JobState.FAIL)throw new a.JobOutputWaitError("Job failed, and specified outputs were not emitted",{state:this.getState(),jobId:this.jobId});if(this.getState()===c.JobState.SUCCESS)throw new a.JobOutputWaitError("Job succeeded, but specified outputs were not emitted",{state:this.getState(),jobId:this.jobId})}))}async _waitFor(t){return new Promise(((e,s)=>{const n=()=>{try{const s=t();void 0!==s&&(o(),e(s))}catch(t){o(),s(t)}},r=t=>{o(),s(t)},o=()=>{this._events.off("trackTick",n),this._events.off("trackError",r)};this._events.on("trackTick",n),this._events.on("trackError",r),n()}))}onAwaitingInput(t,e){return this._createJobEventHandler("awaitingInput",(async s=>{if("*"===t||s===t){const n=await e(s);void 0!==n&&await this.submitInput(t,n)}}))}onOutput(t,e){return this._createJobEventHandler("output",(async s=>{this._matchKey(t,s.key)&&await e(s.data)}))}onDynamicOutput(t,e){return this._createJobEventHandler("output",(async s=>{(s.key.startsWith(t+":")||this._matchKey(t,s.key))&&await e(s.key,s.data)}))}onAnyOutput(t){return this._createJobEventHandler("output",(async e=>{await t(e.key,e.data)}))}onOutputEvent(t,e){return this.onDynamicOutput("events",(async(s,n)=>{n&&"object"==typeof n&&this._matchKey(t,n.type)&&await e(n)}))}onStateChanged(t){return this._createJobEventHandler("stateChanged",t)}onSuccess(t){return this._createJobEventHandler("success",t)}onFail(t){return this._createJobEventHandler("fail",t)}async _track(){for(;this._isTracking;){const{pollInterval:t}=this.client.config;try{const t=await this.api.getJobEvents(this.jobId,this._jobEventOffset);this._jobEventOffset+=t.length;for(const e of t)await this._processJobEvent(e);this._events.emit("trackTick")}catch(t){const e=new a.JobTrackError(t);throw this._events.emit("trackError",e),e}switch(this._state){case c.JobState.SUCCESS:return;case c.JobState.FAIL:throw new a.JobFailedError(this._error)}await new Promise((e=>setTimeout(e,t)))}}async _processJobEvent(t){const e=t.key;switch(t.name){case"awaitingInput":this._setState(c.JobState.AWAITING_INPUT),this._awaitingInputKey=e,this._events.emit("awaitingInput",e);break;case"createOutput":{const t=await this.api.getJobOutput(this.jobId,e);if(t){const s=t.data;this._outputsMap.set(e,{key:e,data:s}),this._events.emit("output",{key:e,data:s})}}break;case"processing":this._setState(c.JobState.PROCESSING);break;case"success":this._setState(c.JobState.SUCCESS),this._events.emit("success");break;case"fail":{const{error:t}=await this.api.getJob(this.jobId);this._setState(c.JobState.FAIL),this._error=Object.assign({category:"server",code:"UnknownError",message:"Unknown error"},t);const e=new a.JobFailedError(this._error);this._events.emit("fail",e)}break;case"tdsStart":this._setState(c.JobState.AWAITING_TDS),this._events.emit("tdsStart");break;case"tdsFinish":this._setState(c.JobState.PROCESSING),this._events.emit("tdsFinish")}}_checkOutputs(t){const e=[];for(const s of t){const t=this._outputsMap.get(s);if(!t)break;e.push(t.data)}return e.length===t.length?e:null}get api(){return this.client.api}_createJobEventHandler(t,e){const s=async(...t)=>{await e(...t)};return this._events.on(t,s),()=>this._events.off(t,s)}_matchKey(t,e){if(t.endsWith(":*")){const s=t.split(":")[0];return e.startsWith(s+":")}return e===t}}},273:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},157:(t,e)=>{"use strict";var s,n;Object.defineProperty(e,"__esModule",{value:!0}),e.JobCategory=e.JobState=void 0,(n=e.JobState||(e.JobState={})).CREATED="created",n.SCHEDULED="scheduled",n.PROCESSING="processing",n.AWAITING_INPUT="awaitingInput",n.AWAITING_TDS="awaitingTds",n.PENDING="pending",n.SUCCESS="success",n.FAIL="fail",(s=e.JobCategory||(e.JobCategory={})).LIVE="live",s.TEST="test"}},e={},function s(n){if(e[n])return e[n].exports;var r=e[n]={exports:{}};return t[n].call(r.exports,r,r.exports,s),r.exports}(863);var t,e}));
import { Request } from '@automationcloud/request';
import { Client } from './client';
import { JobCategory, JobError, JobInputObject, JobState } from './types';
import { JobCategory, JobError, JobInputObject, JobState, Tds } from './types';
/**

@@ -26,2 +26,3 @@ * Automation Cloud HTTP client adapter.

queryPreviousOutputs(serviceId: string, key?: string, inputs?: JobInputObject[]): Promise<AcPreviousJobOutput[]>;
getTdsForJob(jobId: string): Promise<Tds>;
}

@@ -38,2 +39,3 @@ /**

error: JobError | null;
tdsId: string | null;
}

@@ -40,0 +42,0 @@ /**

@@ -90,4 +90,8 @@ "use strict";

}
async getTdsForJob(jobId) {
const job = await this.getJob(jobId);
return await this.request.get(`/3d-secure/${job.tdsId}`);
}
}
exports.AcApi = AcApi;
//# sourceMappingURL=ac-api.js.map
import { AcJobEvent } from './ac-api';
import { Client } from './client';
import { JobError, JobEventHandler, JobInitParams, JobInput, JobOutput, JobOutputEvent, JobState } from './types';
import { JobError, JobEventHandler, JobInitParams, JobInput, JobOutput, JobOutputEvent, JobState, Tds } from './types';
/**

@@ -127,2 +127,8 @@ * Job instance reflexts the Job created in Automation Cloud.

/**
* @returns Retrieves the active 3-D Secure challenge for this job.
*
* @public
*/
getTds(): Promise<Tds>;
/**
* Resolves whenever job finishes successfully or if the job tracking was stopped with `stopTracking()`.

@@ -268,2 +274,4 @@ * Rejects if job fails.

emit(event: 'trackError', error: Error): boolean;
emit(event: 'tdsStart'): boolean;
emit(event: 'tdsFinish'): boolean;
on(event: 'input', fn: (input: JobInput) => void): this;

@@ -270,0 +278,0 @@ on(event: 'output', fn: (output: JobOutput) => void): this;

@@ -236,2 +236,11 @@ "use strict";

/**
* @returns Retrieves the active 3-D Secure challenge for this job.
*
* @public
*/
async getTds() {
const tds = await this.api.getTdsForJob(this.jobId);
return tds;
}
/**
* Resolves whenever job finishes successfully or if the job tracking was stopped with `stopTracking()`.

@@ -502,6 +511,16 @@ * Rejects if job fails.

break;
case 'tdsStart':
{
this._setState(types_1.JobState.AWAITING_TDS);
this._events.emit('tdsStart');
}
break;
case 'tdsFinish':
{
this._setState(types_1.JobState.PROCESSING);
this._events.emit('tdsFinish');
}
break;
// TODO handle those
case 'restart':
case 'tdsStart':
case 'tdsFinish':
}

@@ -508,0 +527,0 @@ }

@@ -111,2 +111,9 @@ /**

/**
* 3-D Secure object produced by automation job.
*/
export declare type Tds = {
id: string;
url: string;
};
/**
* Automation Cloud authentication.

@@ -113,0 +120,0 @@ *

{
"name": "@automationcloud/client",
"version": "1.5.0",
"version": "1.6.0",
"description": "JavaScript/TypeScript Client Library for Automation Cloud API",

@@ -63,4 +63,4 @@ "main": "out/main/index.js",

"ts-loader": "^8.0.11",
"typedoc": "^0.19.2",
"typescript": "^4.1.2",
"typedoc": "^0.20.36",
"typescript": "^4.2.4",
"webpack": "^5.9.0",

@@ -67,0 +67,0 @@ "webpack-cli": "^4.2.0"

@@ -19,3 +19,3 @@ // Copyright 2020 UBIO Limited

import { Client } from './client';
import { JobCategory, JobError, JobInputObject, JobState } from './types';
import { JobCategory, JobError, JobInputObject, JobState, Tds } from './types';

@@ -109,2 +109,7 @@ /**

async getTdsForJob(jobId: string): Promise<Tds> {
const job = await this.getJob(jobId);
return await this.request.get(`/3d-secure/${job.tdsId}`);
}
}

@@ -122,2 +127,3 @@

error: JobError | null;
tdsId: string | null;
}

@@ -124,0 +130,0 @@

@@ -20,3 +20,3 @@ // Copyright 2020 UBIO Limited

import * as errors from './errors';
import { JobCategory, JobError, JobEventHandler, JobInitParams, JobInput, JobOutput, JobOutputEvent, JobState } from './types';
import { JobCategory, JobError, JobEventHandler, JobInitParams, JobInput, JobOutput, JobOutputEvent, JobState, Tds } from './types';

@@ -240,2 +240,12 @@ /**

/**
* @returns Retrieves the active 3-D Secure challenge for this job.
*
* @public
*/
async getTds(): Promise<Tds> {
const tds = await this.api.getTdsForJob(this.jobId);
return tds;
}
/**
* Resolves whenever job finishes successfully or if the job tracking was stopped with `stopTracking()`.

@@ -512,6 +522,12 @@ * Rejects if job fails.

} break;
case 'tdsStart': {
this._setState(JobState.AWAITING_TDS);
this._events.emit('tdsStart');
} break;
case 'tdsFinish': {
this._setState(JobState.PROCESSING);
this._events.emit('tdsFinish');
} break;
// TODO handle those
case 'restart':
case 'tdsStart':
case 'tdsFinish':
}

@@ -585,2 +601,4 @@ }

emit(event: 'trackError', error: Error): boolean;
emit(event: 'tdsStart'): boolean;
emit(event: 'tdsFinish'): boolean;

@@ -587,0 +605,0 @@ on(event: 'input', fn: (input: JobInput) => void): this;

@@ -137,2 +137,10 @@ // Copyright 2020 UBIO Limited

/**
* 3-D Secure object produced by automation job.
*/
export type Tds = {
id: string;
url: string;
}
/**
* Automation Cloud authentication.

@@ -139,0 +147,0 @@ *

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc