@gitbeaker/requester-utils
Advanced tools
Comparing version 23.5.0 to 23.6.0
@@ -0,1 +1,30 @@ | ||
# v24.0.0 (Mon Sep 28 2020) | ||
#### 💥 Breaking Change | ||
- update rollup for requester utils [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Merge branch 'restructure' into backitup [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Restructing the requester utils and update the related typings [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Updating requester-utils deps [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Merge branch 'ts-node' into backitup [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Update ts-node [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Updating terser usage to be only on the browser release [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@jdalrymple](https://github.com/jdalrymple)) | ||
- chore(deps-dev): bump typescript from 3.9.7 to 4.0.3 [#1163](https://github.com/jdalrymple/gitbeaker/pull/1163) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot])) | ||
#### ⚠️ Pushed to `master` | ||
- feat: apply exponental backoff for 429 errors ([@max-wittig](https://github.com/max-wittig)) | ||
#### 🔩 Dependency Updates | ||
- chore(deps-dev): bump rollup-plugin-terser from 6.1.0 to 7.0.0 [#1058](https://github.com/jdalrymple/gitbeaker/pull/1058) ([@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]) [@jdalrymple](https://github.com/jdalrymple)) | ||
#### Authors: 3 | ||
- [@dependabot-preview[bot]](https://github.com/dependabot-preview[bot]) | ||
- Justin Dalrymple ([@jdalrymple](https://github.com/jdalrymple)) | ||
- Max Wittig ([@max-wittig](https://github.com/max-wittig)) | ||
--- | ||
# v23.5.0 (Sun Aug 09 2020) | ||
@@ -2,0 +31,0 @@ |
@@ -1,2 +0,4 @@ | ||
import{decamelizeKeys as t}from"xcase";import{stringify as r}from"query-string"; | ||
import { decamelizeKeys } from 'xcase'; | ||
import { stringify } from 'query-string'; | ||
/*! ***************************************************************************** | ||
@@ -15,2 +17,196 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var o=function(t,r){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])})(t,r)};var n=function(){return(n=Object.assign||function(t){for(var r,o=1,n=arguments.length;o<n;o++)for(var e in r=arguments[o])Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e]);return t}).apply(this,arguments)};function e(t,r){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var n,e,a=o.call(t),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(t){e={error:t}}finally{try{n&&!n.done&&(o=a.return)&&o.call(a)}finally{if(e)throw e.error}}return i}function a(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(e(arguments[r]));return t}function i(o){return r(t(o||{}),{arrayFormat:"bracket"})}function c(r,o){var n,e=void 0===o?{}:o,a=e.body,c=e.query,u=e.sudo,f=e.method,p=void 0===f?"get":f,s=r.headers;return u&&(s.sudo=u),"object"==typeof a&&"FormData"!==a.constructor.name?(n=JSON.stringify(t(a)),s["content-type"]="application/json"):n=a,{agent:void 0,headers:s,timeout:r.requestTimeout,method:p,searchParams:i(c),prefixUrl:r.url,body:n}}function u(t,r){var o={};return["get","post","put","delete","stream"].forEach((function(e){o[e]=function(o,a,i){var c=t(o,n(n({},i),{method:e}));return r(a,c)}})),o}function f(t,r){return function(t){function i(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];var c=e(o),u=c[0],f=c.slice(1);return t.apply(this,a([n(n({},r),u)],f))||this}return function(t,r){function n(){this.constructor=t}o(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(i,t),i}(t)}function p(t,r){void 0===r&&(r={});var o={};return Object.entries(t).forEach((function(t){var n=e(t,2),a=n[0],i=n[1];o[a]=f(i,r)})),o}export{u as createInstance,c as defaultRequest,i as formatQuery,p as modifyServices}; | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
} | ||
// Utility methods | ||
function formatQuery(options) { | ||
return stringify(decamelizeKeys(options || {}), { | ||
arrayFormat: 'bracket', | ||
}); | ||
} | ||
function defaultRequest(service, _a) { | ||
var _b = _a === void 0 ? {} : _a, body = _b.body, query = _b.query, sudo = _b.sudo, _c = _b.method, method = _c === void 0 ? 'get' : _c; | ||
var headers = service.headers; | ||
var bod; | ||
if (sudo) | ||
headers.sudo = sudo; | ||
// FIXME: Not the best comparison, but...it will have to do for now. | ||
if (typeof body === 'object' && body.constructor.name !== 'FormData') { | ||
bod = JSON.stringify(decamelizeKeys(body)); | ||
headers['content-type'] = 'application/json'; | ||
} | ||
else { | ||
bod = body; | ||
} | ||
return { | ||
headers: headers, | ||
timeout: service.requestTimeout, | ||
method: method, | ||
searchParams: formatQuery(query), | ||
prefixUrl: service.url, | ||
body: bod, | ||
}; | ||
} | ||
function createInstance(optionsHandler, requestHandler) { | ||
var requester = {}; | ||
var methods = ['get', 'post', 'put', 'delete', 'stream']; | ||
methods.forEach(function (m) { | ||
/* eslint func-names:0 */ | ||
requester[m] = function (service, endpoint, options) { | ||
var requestOptions = optionsHandler(service, __assign(__assign({}, options), { method: m })); | ||
return requestHandler(endpoint, requestOptions); | ||
}; | ||
}); | ||
return requester; | ||
} | ||
function extendClass(Base, customConfig) { | ||
return /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
var options = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
options[_i] = arguments[_i]; | ||
} | ||
var _this = this; | ||
var _a = __read(options), config = _a[0], opts = _a.slice(1); | ||
_this = _super.apply(this, __spread([__assign(__assign({}, customConfig), config)], opts)) || this; | ||
return _this; | ||
} | ||
return class_1; | ||
}(Base)); | ||
} | ||
function modifyServices(services, customConfig) { | ||
if (customConfig === void 0) { customConfig = {}; } | ||
var updated = {}; | ||
Object.entries(services).forEach(function (_a) { | ||
var _b = __read(_a, 2), k = _b[0], s = _b[1]; | ||
updated[k] = extendClass(s, customConfig); | ||
}); | ||
return updated; | ||
} | ||
function wait(ms) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })]; | ||
}); | ||
}); | ||
} | ||
var BaseService = /** @class */ (function () { | ||
function BaseService(_a) { | ||
var _b = _a === void 0 ? {} : _a, token = _b.token, jobToken = _b.jobToken, oauthToken = _b.oauthToken, sudo = _b.sudo, profileToken = _b.profileToken, requester = _b.requester, _c = _b.profileMode, profileMode = _c === void 0 ? 'execution' : _c, _d = _b.host, host = _d === void 0 ? 'https://gitlab.com' : _d, _e = _b.url, url = _e === void 0 ? '' : _e, _f = _b.version, version = _f === void 0 ? 4 : _f, _g = _b.camelize, camelize = _g === void 0 ? false : _g, _h = _b.rejectUnauthorized, rejectUnauthorized = _h === void 0 ? true : _h, _j = _b.requestTimeout, requestTimeout = _j === void 0 ? 300000 : _j; | ||
if (!requester) | ||
throw new ReferenceError('Requester must be passed'); | ||
this.url = [host, 'api', "v" + version, url].join('/'); | ||
this.headers = { | ||
'user-agent': 'gitbeaker', | ||
}; | ||
this.rejectUnauthorized = rejectUnauthorized; | ||
this.camelize = camelize; | ||
this.requester = requester; | ||
this.requestTimeout = requestTimeout; | ||
// Handle auth tokens | ||
if (oauthToken) | ||
this.headers.authorization = "Bearer " + oauthToken; | ||
else if (jobToken) | ||
this.headers['job-token'] = jobToken; | ||
else if (token) | ||
this.headers['private-token'] = token; | ||
// Profiling | ||
if (profileToken) { | ||
this.headers['X-Profile-Token'] = profileToken; | ||
this.headers['X-Profile-Mode'] = profileMode; | ||
} | ||
// Set sudo | ||
if (sudo) | ||
this.headers.Sudo = "" + sudo; | ||
} | ||
return BaseService; | ||
}()); | ||
export { BaseService, createInstance, defaultRequest, formatQuery, modifyServices, wait }; |
@@ -1,1 +0,220 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("xcase"),r=require("query-string"),e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(t,r)};var o=function(){return(o=Object.assign||function(t){for(var r,e=1,o=arguments.length;e<o;e++)for(var n in r=arguments[e])Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}).apply(this,arguments)};function n(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var o,n,a=e.call(t),i=[];try{for(;(void 0===r||r-- >0)&&!(o=a.next()).done;)i.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(e=a.return)&&e.call(a)}finally{if(n)throw n.error}}return i}function a(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(n(arguments[r]));return t}function i(e){return r.stringify(t.decamelizeKeys(e||{}),{arrayFormat:"bracket"})}function u(t,r){return function(t){function i(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];var u=n(e),c=u[0],f=u.slice(1);return t.apply(this,a([o(o({},r),c)],f))||this}return function(t,r){function o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}(i,t),i}(t)}exports.createInstance=function(t,r){var e={};return["get","post","put","delete","stream"].forEach((function(n){e[n]=function(e,a,i){var u=t(e,o(o({},i),{method:n}));return r(a,u)}})),e},exports.defaultRequest=function(r,e){var o,n=void 0===e?{}:e,a=n.body,u=n.query,c=n.sudo,f=n.method,s=void 0===f?"get":f,p=r.headers;return c&&(p.sudo=c),"object"==typeof a&&"FormData"!==a.constructor.name?(o=JSON.stringify(t.decamelizeKeys(a)),p["content-type"]="application/json"):o=a,{agent:void 0,headers:p,timeout:r.requestTimeout,method:s,searchParams:i(u),prefixUrl:r.url,body:o}},exports.formatQuery=i,exports.modifyServices=function(t,r){void 0===r&&(r={});var e={};return Object.entries(t).forEach((function(t){var o=n(t,2),a=o[0],i=o[1];e[a]=u(i,r)})),e}; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var xcase = require('xcase'); | ||
var queryString = require('query-string'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
} | ||
// Utility methods | ||
function formatQuery(options) { | ||
return queryString.stringify(xcase.decamelizeKeys(options || {}), { | ||
arrayFormat: 'bracket', | ||
}); | ||
} | ||
function defaultRequest(service, _a) { | ||
var _b = _a === void 0 ? {} : _a, body = _b.body, query = _b.query, sudo = _b.sudo, _c = _b.method, method = _c === void 0 ? 'get' : _c; | ||
var headers = service.headers; | ||
var bod; | ||
if (sudo) | ||
headers.sudo = sudo; | ||
// FIXME: Not the best comparison, but...it will have to do for now. | ||
if (typeof body === 'object' && body.constructor.name !== 'FormData') { | ||
bod = JSON.stringify(xcase.decamelizeKeys(body)); | ||
headers['content-type'] = 'application/json'; | ||
} | ||
else { | ||
bod = body; | ||
} | ||
return { | ||
headers: headers, | ||
timeout: service.requestTimeout, | ||
method: method, | ||
searchParams: formatQuery(query), | ||
prefixUrl: service.url, | ||
body: bod, | ||
}; | ||
} | ||
function createInstance(optionsHandler, requestHandler) { | ||
var requester = {}; | ||
var methods = ['get', 'post', 'put', 'delete', 'stream']; | ||
methods.forEach(function (m) { | ||
/* eslint func-names:0 */ | ||
requester[m] = function (service, endpoint, options) { | ||
var requestOptions = optionsHandler(service, __assign(__assign({}, options), { method: m })); | ||
return requestHandler(endpoint, requestOptions); | ||
}; | ||
}); | ||
return requester; | ||
} | ||
function extendClass(Base, customConfig) { | ||
return /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
var options = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
options[_i] = arguments[_i]; | ||
} | ||
var _this = this; | ||
var _a = __read(options), config = _a[0], opts = _a.slice(1); | ||
_this = _super.apply(this, __spread([__assign(__assign({}, customConfig), config)], opts)) || this; | ||
return _this; | ||
} | ||
return class_1; | ||
}(Base)); | ||
} | ||
function modifyServices(services, customConfig) { | ||
if (customConfig === void 0) { customConfig = {}; } | ||
var updated = {}; | ||
Object.entries(services).forEach(function (_a) { | ||
var _b = __read(_a, 2), k = _b[0], s = _b[1]; | ||
updated[k] = extendClass(s, customConfig); | ||
}); | ||
return updated; | ||
} | ||
function wait(ms) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })]; | ||
}); | ||
}); | ||
} | ||
var BaseService = /** @class */ (function () { | ||
function BaseService(_a) { | ||
var _b = _a === void 0 ? {} : _a, token = _b.token, jobToken = _b.jobToken, oauthToken = _b.oauthToken, sudo = _b.sudo, profileToken = _b.profileToken, requester = _b.requester, _c = _b.profileMode, profileMode = _c === void 0 ? 'execution' : _c, _d = _b.host, host = _d === void 0 ? 'https://gitlab.com' : _d, _e = _b.url, url = _e === void 0 ? '' : _e, _f = _b.version, version = _f === void 0 ? 4 : _f, _g = _b.camelize, camelize = _g === void 0 ? false : _g, _h = _b.rejectUnauthorized, rejectUnauthorized = _h === void 0 ? true : _h, _j = _b.requestTimeout, requestTimeout = _j === void 0 ? 300000 : _j; | ||
if (!requester) | ||
throw new ReferenceError('Requester must be passed'); | ||
this.url = [host, 'api', "v" + version, url].join('/'); | ||
this.headers = { | ||
'user-agent': 'gitbeaker', | ||
}; | ||
this.rejectUnauthorized = rejectUnauthorized; | ||
this.camelize = camelize; | ||
this.requester = requester; | ||
this.requestTimeout = requestTimeout; | ||
// Handle auth tokens | ||
if (oauthToken) | ||
this.headers.authorization = "Bearer " + oauthToken; | ||
else if (jobToken) | ||
this.headers['job-token'] = jobToken; | ||
else if (token) | ||
this.headers['private-token'] = token; | ||
// Profiling | ||
if (profileToken) { | ||
this.headers['X-Profile-Token'] = profileToken; | ||
this.headers['X-Profile-Mode'] = profileMode; | ||
} | ||
// Set sudo | ||
if (sudo) | ||
this.headers.Sudo = "" + sudo; | ||
} | ||
return BaseService; | ||
}()); | ||
exports.BaseService = BaseService; | ||
exports.createInstance = createInstance; | ||
exports.defaultRequest = defaultRequest; | ||
exports.formatQuery = formatQuery; | ||
exports.modifyServices = modifyServices; | ||
exports.wait = wait; |
export * from './RequesterUtils'; | ||
export * from './BaseService'; |
/// <reference types="node" /> | ||
import { Agent } from 'https'; | ||
import * as FormData from 'form-data'; | ||
import { BaseService } from './BaseService'; | ||
export interface RequesterType { | ||
get(service: object, endpoint: string, options?: object): Promise<any>; | ||
post(service: object, endpoint: string, options?: object): Promise<any>; | ||
put(service: object, endpoint: string, options?: object): Promise<any>; | ||
delete(service: object, endpoint: string, options?: object): Promise<any>; | ||
stream?(service: object, endpoint: string, options?: object): Promise<any>; | ||
get(service: BaseService, endpoint: string, options?: Record<string, unknown>): Promise<any>; | ||
post(service: BaseService, endpoint: string, options?: Record<string, unknown>): Promise<any>; | ||
put(service: BaseService, endpoint: string, options?: Record<string, unknown>): Promise<any>; | ||
delete(service: BaseService, endpoint: string, options?: Record<string, unknown>): Promise<any>; | ||
stream?(service: BaseService, endpoint: string, options?: Record<string, unknown>): NodeJS.ReadableStream; | ||
} | ||
export interface Service { | ||
headers: Record<string, string | string[]>; | ||
requestTimeout: number; | ||
url: string; | ||
rejectUnauthorized?: boolean; | ||
} | ||
export declare type DefaultRequestService = Pick<BaseService, 'headers' | 'requestTimeout' | 'url' | 'rejectUnauthorized'>; | ||
export declare type DefaultRequestOptions = { | ||
body?: FormData | object; | ||
query?: object; | ||
body?: FormData | Record<string, unknown>; | ||
query?: Record<string, unknown>; | ||
sudo?: string; | ||
method?: string; | ||
}; | ||
export declare function formatQuery(options: any): string; | ||
export declare function defaultRequest(service: Service, { body, query, sudo, method }?: DefaultRequestOptions): Record<string, string | number | FormData | Agent | Record<string, string | string[] | Agent>>; | ||
export declare type DefaultRequestReturn = { | ||
headers: Record<string, string> | Headers; | ||
timeout?: number; | ||
method: string; | ||
searchParams?: string; | ||
prefixUrl?: string; | ||
body?: string | FormData; | ||
}; | ||
export declare function formatQuery(options?: Record<string, unknown>): string; | ||
export declare function defaultRequest(service: DefaultRequestService, { body, query, sudo, method }?: DefaultRequestOptions): DefaultRequestReturn; | ||
export declare function createInstance(optionsHandler: any, requestHandler: any): RequesterType; | ||
export interface Constructable<T = {}> { | ||
export interface Constructable<T = any> { | ||
new (...args: any[]): T; | ||
@@ -30,2 +34,3 @@ } | ||
[name: string]: Constructable; | ||
}>(services: T, customConfig?: object): T; | ||
}>(services: T, customConfig?: Record<string, unknown>): T; | ||
export declare function wait(ms: number): Promise<void>; |
{ | ||
"name": "@gitbeaker/requester-utils", | ||
"description": "Utility functions for requester implementatons used in @gitbeaker", | ||
"version": "23.5.0", | ||
"version": "23.6.0", | ||
"author": { | ||
@@ -12,13 +12,12 @@ "name": "Justin Dalrymple" | ||
"dependencies": { | ||
"query-string": "^6.12.1", | ||
"form-data": "^3.0.0", | ||
"query-string": "^6.13.3", | ||
"xcase": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.0.6", | ||
"form-data": "^3.0.0", | ||
"rollup": "^2.12.0", | ||
"rollup-plugin-terser": "^6.1.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.3" | ||
"@types/node": "^14.11.2", | ||
"rollup": "^2.28.2", | ||
"rollup-plugin-typescript2": "^0.27.3", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.3" | ||
}, | ||
@@ -50,3 +49,3 @@ "engines": { | ||
}, | ||
"gitHead": "b57b8b5e43349bfa5103348c0bda40c40aa0a439" | ||
"gitHead": "0848ab55245a258701fe9b9c6f79bc6812390d59" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
32688
5
9
469
0
3
1
+ Addedform-data@^3.0.0
+ Addedasynckit@0.4.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@3.0.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
Updatedquery-string@^6.13.3