New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.7.1 to 1.8.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 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 d=0;d<c;d++){let c=!1,h=this.config.retryDelay+this.config.retryDelayIncrement*d;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(),h=0,this.config.auth.invalidate()):c=this.config.retryStatusCodes.includes(r.status),await this.createErrorFromResponse(e,r);return r}catch(a){const d=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:d,statusText:p};if(c||e.NETWORK_ERRORS.includes(a.code)){u=a,l=f,this.onRetry(a,f),await new Promise((t=>setTimeout(t,h)));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],d=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),d){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(d-1);u<d;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var h,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),d){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(h=1,c=new Array(d-1);h<d;h++)c[h-1]=arguments[h];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}async createDataToken(t,e){const s=null!=e?e:await this.createOtp(),{token:n}=await this.request.post("/data",{body:{otp:s,data:t}});return{$token: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}));
!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 getJobOutputs(t){return(await this.request.get(`/jobs/${t}/outputs`)).data}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}async createDataToken(t,e){const s=null!=e?e:await this.createOtp(),{token:n}=await this.request.post("/data",{body:{otp:s,data:t}});return{$token: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 getOutputs(){return await this.api.getJobOutputs(this.jobId)}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}));

@@ -23,2 +23,3 @@ import { Request } from '@automationcloud/request';

getJobOutput(jobId: string, key: string): Promise<AcJobOutput | null>;
getJobOutputs(jobId: string): Promise<AcJobOutput[]>;
sendJobInput(jobId: string, key: string, data: any): Promise<AcJobInput>;

@@ -25,0 +26,0 @@ cancelJob(jobId: string): Promise<void>;

@@ -70,2 +70,6 @@ "use strict";

}
async getJobOutputs(jobId) {
const body = await this.request.get(`/jobs/${jobId}/outputs`);
return body.data;
}
async sendJobInput(jobId, key, data) {

@@ -72,0 +76,0 @@ const body = await this.request.post(`/jobs/${jobId}/inputs`, {

@@ -127,2 +127,8 @@ import { AcJobEvent } from './ac-api';

/**
* Retrieves job outputs.
*
* @public
*/
getOutputs(): Promise<any>;
/**
* @returns Retrieves the active 3-D Secure challenge for this job.

@@ -129,0 +135,0 @@ *

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

/**
* Retrieves job outputs.
*
* @public
*/
async getOutputs() {
return await this.api.getJobOutputs(this.jobId);
}
/**
* @returns Retrieves the active 3-D Secure challenge for this job.

@@ -238,0 +246,0 @@ *

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

@@ -5,0 +5,0 @@ "main": "out/main/index.js",

@@ -85,2 +85,7 @@ // Copyright 2020 UBIO Limited

async getJobOutputs(jobId: string): Promise<AcJobOutput[]> {
const body = await this.request.get(`/jobs/${jobId}/outputs`);
return body.data;
}
async sendJobInput(jobId: string, key: string, data: any): Promise<AcJobInput> {

@@ -87,0 +92,0 @@ const body = await this.request.post(`/jobs/${jobId}/inputs`, {

@@ -239,2 +239,11 @@ // Copyright 2020 UBIO Limited

/**
* Retrieves job outputs.
*
* @public
*/
async getOutputs(): Promise<any> {
return await this.api.getJobOutputs(this.jobId);
}
/**
* @returns Retrieves the active 3-D Secure challenge for this job.

@@ -241,0 +250,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

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