{"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n  EngineServerIpBlockResponse,\n  GetEngineIpBlockStatusResponse,\n  GetEngineTimeResponse,\n} from './types';\n\n/**\n * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough\n * use cases to justify a separate package\n */\nexport class EngineWebClient extends EngineBaseClient {\n  /**\n   * Determines the IP block status for the current client\n   */\n  async getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse> {\n    return (\n      this.axiosInstance\n        // Use the /time endpoint and listen to 403 responses\n        .get(`${this.opts.url}/ip`, {\n          // Allow all statuses\n          validateStatus: () => true,\n          // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false\n          withCredentials: false,\n        })\n        .then((res) => {\n          if (res.status !== 403) {\n            return null;\n          }\n          const resData = res.data as EngineServerIpBlockResponse;\n\n          if (!resData.blocked) {\n            return null;\n          }\n\n          return resData.reason === 'ip_query_only' ? 'query_only' : 'blocked';\n        })\n    );\n  }\n\n  /**\n   * Determines whether a client needs to complete the cloudflare JS challenge to interact with the API\n   *\n   * @return true if the client needs to complete the JS challenge at '/challenge', false otherwise\n   */\n  async getRequiresCloudflareAuth(): Promise<boolean> {\n    // We use a generic endpoint and check for the CF challenge header\n    // Note: this uses a CORS set to the relevant frontend endpoint (ex. testnet.vertexprotocol.com) so it will NOT\n    // work from other domains\n    return this.axiosInstance\n      .get(`${this.opts.url}/cf-check`, {\n        // Allow all statuses\n        validateStatus: () => true,\n      })\n      .then((res) => {\n        if (res.status !== 403) {\n          return false;\n        }\n\n        return res.headers['cf-mitigated'] === 'challenge';\n      });\n  }\n\n  /**\n   * Retrieves current server epoch in milliseconds\n   */\n  async getTime(): Promise<GetEngineTimeResponse> {\n    return this.axiosInstance\n      .get(`${this.opts.url}/time`)\n      .then((res) => res.data as GetEngineTimeResponse);\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiC;AAW1B,IAAM,kBAAN,cAA8B,yCAAiB;AAAA;AAAA;AAAA;AAAA,EAIpD,MAAM,mBAA4D;AAChE,WACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO;AAAA;AAAA,MAE1B,gBAAgB,MAAM;AAAA;AAAA,MAEtB,iBAAiB;AAAA,IACnB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AACA,YAAM,UAAU,IAAI;AAEpB,UAAI,CAAC,QAAQ,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,WAAW,kBAAkB,eAAe;AAAA,IAC7D,CAAC;AAAA,EAEP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,4BAA8C;AAIlD,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,aAAa;AAAA;AAAA,MAEhC,gBAAgB,MAAM;AAAA,IACxB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,cAAc,MAAM;AAAA,IACzC,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAA0C;AAC9C,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO,EAC3B,KAAK,CAAC,QAAQ,IAAI,IAA6B;AAAA,EACpD;AACF;","names":[]}