auth_request.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.AuthRequest = void 0;
  4. const got = require("got");
  5. const pkg = require("../../package.json");
  6. class AuthRequest {
  7. static urlRoot = "https://app.lokalise.com/oauth2/";
  8. static async createPromise(uri, method, body, host) {
  9. const options = {
  10. method: method,
  11. prefixUrl: host ?? this.urlRoot,
  12. headers: {
  13. Accept: "application/json",
  14. "User-Agent": `node-lokalise-api/${pkg.version}`,
  15. },
  16. agent: false,
  17. throwHttpErrors: false,
  18. decompress: false,
  19. };
  20. options["body"] = JSON.stringify(body);
  21. try {
  22. const response = await got(uri, options);
  23. const responseJSON = JSON.parse(response.body);
  24. if (response.statusCode > 399) {
  25. return Promise.reject({
  26. ...{ code: response.statusCode },
  27. ...responseJSON,
  28. });
  29. }
  30. return Promise.resolve({ json: responseJSON, headers: response.headers });
  31. }
  32. catch (err) {
  33. /* istanbul ignore next */
  34. return Promise.reject(err);
  35. }
  36. }
  37. }
  38. exports.AuthRequest = AuthRequest;
  39. //# sourceMappingURL=auth_request.js.map