index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __exportStar = (this && this.__exportStar) || function(m, exports) {
  10. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  11. };
  12. Object.defineProperty(exports, "__esModule", { value: true });
  13. const url_1 = require("url");
  14. const create_1 = require("./create");
  15. const defaults = {
  16. options: {
  17. method: 'GET',
  18. retry: {
  19. limit: 2,
  20. methods: [
  21. 'GET',
  22. 'PUT',
  23. 'HEAD',
  24. 'DELETE',
  25. 'OPTIONS',
  26. 'TRACE'
  27. ],
  28. statusCodes: [
  29. 408,
  30. 413,
  31. 429,
  32. 500,
  33. 502,
  34. 503,
  35. 504,
  36. 521,
  37. 522,
  38. 524
  39. ],
  40. errorCodes: [
  41. 'ETIMEDOUT',
  42. 'ECONNRESET',
  43. 'EADDRINUSE',
  44. 'ECONNREFUSED',
  45. 'EPIPE',
  46. 'ENOTFOUND',
  47. 'ENETUNREACH',
  48. 'EAI_AGAIN'
  49. ],
  50. maxRetryAfter: undefined,
  51. calculateDelay: ({ computedValue }) => computedValue
  52. },
  53. timeout: {},
  54. headers: {
  55. 'user-agent': 'got (https://github.com/sindresorhus/got)'
  56. },
  57. hooks: {
  58. init: [],
  59. beforeRequest: [],
  60. beforeRedirect: [],
  61. beforeRetry: [],
  62. beforeError: [],
  63. afterResponse: []
  64. },
  65. cache: undefined,
  66. dnsCache: undefined,
  67. decompress: true,
  68. throwHttpErrors: true,
  69. followRedirect: true,
  70. isStream: false,
  71. responseType: 'text',
  72. resolveBodyOnly: false,
  73. maxRedirects: 10,
  74. prefixUrl: '',
  75. methodRewriting: true,
  76. ignoreInvalidCookies: false,
  77. context: {},
  78. // TODO: Set this to `true` when Got 12 gets released
  79. http2: false,
  80. allowGetBody: false,
  81. https: undefined,
  82. pagination: {
  83. transform: (response) => {
  84. if (response.request.options.responseType === 'json') {
  85. return response.body;
  86. }
  87. return JSON.parse(response.body);
  88. },
  89. paginate: response => {
  90. if (!Reflect.has(response.headers, 'link')) {
  91. return false;
  92. }
  93. const items = response.headers.link.split(',');
  94. let next;
  95. for (const item of items) {
  96. const parsed = item.split(';');
  97. if (parsed[1].includes('next')) {
  98. next = parsed[0].trimStart().trim();
  99. next = next.slice(1, -1);
  100. break;
  101. }
  102. }
  103. if (next) {
  104. const options = {
  105. url: new url_1.URL(next)
  106. };
  107. return options;
  108. }
  109. return false;
  110. },
  111. filter: () => true,
  112. shouldContinue: () => true,
  113. countLimit: Infinity,
  114. backoff: 0,
  115. requestLimit: 10000,
  116. stackAllItems: true
  117. },
  118. parseJson: (text) => JSON.parse(text),
  119. stringifyJson: (object) => JSON.stringify(object),
  120. cacheOptions: {}
  121. },
  122. handlers: [create_1.defaultHandler],
  123. mutableDefaults: false
  124. };
  125. const got = create_1.default(defaults);
  126. exports.default = got;
  127. // For CommonJS default export support
  128. module.exports = got;
  129. module.exports.default = got;
  130. module.exports.__esModule = true; // Workaround for TS issue: https://github.com/sindresorhus/got/pull/1267
  131. __exportStar(require("./create"), exports);
  132. __exportStar(require("./as-promise"), exports);