UNPKG

13 kBJavaScriptView Raw
1import { Resources } from '@gitbeaker/core';
2export { Types } from '@gitbeaker/core';
3import { createRequesterFn, defaultOptionsHandler as defaultOptionsHandler$1, presetResourceArguments } from '@gitbeaker/requester-utils';
4import Got from 'got';
5import { decamelizeKeys } from 'xcase';
6import delay from 'delay';
7
8/*! *****************************************************************************
9Copyright (c) Microsoft Corporation.
10
11Permission to use, copy, modify, and/or distribute this software for any
12purpose with or without fee is hereby granted.
13
14THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20PERFORMANCE OF THIS SOFTWARE.
21***************************************************************************** */
22
23var __assign = function() {
24 __assign = Object.assign || function __assign(t) {
25 for (var s, i = 1, n = arguments.length; i < n; i++) {
26 s = arguments[i];
27 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28 }
29 return t;
30 };
31 return __assign.apply(this, arguments);
32};
33
34function __awaiter(thisArg, _arguments, P, generator) {
35 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36 return new (P || (P = Promise))(function (resolve, reject) {
37 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40 step((generator = generator.apply(thisArg, _arguments || [])).next());
41 });
42}
43
44function __generator(thisArg, body) {
45 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
46 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47 function verb(n) { return function (v) { return step([n, v]); }; }
48 function step(op) {
49 if (f) throw new TypeError("Generator is already executing.");
50 while (_) try {
51 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;
52 if (y = 0, t) op = [op[0] & 2, t.value];
53 switch (op[0]) {
54 case 0: case 1: t = op; break;
55 case 4: _.label++; return { value: op[1], done: false };
56 case 5: _.label++; y = op[1]; op = [0]; continue;
57 case 7: op = _.ops.pop(); _.trys.pop(); continue;
58 default:
59 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63 if (t[2]) _.ops.pop();
64 _.trys.pop(); continue;
65 }
66 op = body.call(thisArg, _);
67 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69 }
70}
71
72function defaultOptionsHandler(resourceOptions, _a) {
73 var _b = _a === void 0 ? {} : _a, body = _b.body, query = _b.query, sudo = _b.sudo, method = _b.method;
74 var options = defaultOptionsHandler$1(resourceOptions, { body: body, query: query, sudo: sudo, method: method });
75 // FIXME: Not the best comparison, but...it will have to do for now.
76 if (typeof body === 'object' && body.constructor.name !== 'FormData') {
77 options.json = decamelizeKeys(body);
78 delete options.body;
79 }
80 if (resourceOptions.url.includes('https') &&
81 resourceOptions.rejectUnauthorized != null &&
82 resourceOptions.rejectUnauthorized === false) {
83 options.https = {
84 rejectUnauthorized: resourceOptions.rejectUnauthorized,
85 };
86 }
87 return options;
88}
89function processBody(_a) {
90 var rawBody = _a.rawBody, headers = _a.headers;
91 // Split to remove potential charset info from the content type
92 var contentType = (headers['content-type'] || '').split(';')[0].trim();
93 if (contentType === 'application/json') {
94 return rawBody.length === 0 ? {} : JSON.parse(rawBody.toString());
95 }
96 if (contentType.startsWith('text/')) {
97 return rawBody.toString();
98 }
99 return Buffer.from(rawBody);
100}
101function handler(endpoint, options) {
102 return __awaiter(this, void 0, void 0, function () {
103 var retryCodes, maxRetries, response, i, waitTime, e_1, output, statusCode, headers, body;
104 return __generator(this, function (_a) {
105 switch (_a.label) {
106 case 0:
107 retryCodes = [429, 502];
108 maxRetries = 10;
109 i = 0;
110 _a.label = 1;
111 case 1:
112 if (!(i < maxRetries)) return [3 /*break*/, 9];
113 waitTime = Math.pow(2, i) * 0.1;
114 _a.label = 2;
115 case 2:
116 _a.trys.push([2, 4, , 8]);
117 if (options.method === 'stream') {
118 return [2 /*return*/, Got(endpoint, __assign(__assign({}, options), { method: 'get', isStream: true }))];
119 }
120 return [4 /*yield*/, Got(endpoint, options)];
121 case 3:
122 response = _a.sent(); // eslint-disable-line
123 return [3 /*break*/, 9];
124 case 4:
125 e_1 = _a.sent();
126 if (!e_1.response) return [3 /*break*/, 7];
127 if (!retryCodes.includes(e_1.response.statusCode)) return [3 /*break*/, 6];
128 return [4 /*yield*/, delay(waitTime)];
129 case 5:
130 _a.sent(); // eslint-disable-line
131 return [3 /*break*/, 8]; // eslint-disable-line
132 case 6:
133 if (typeof e_1.response.body === 'string' && e_1.response.body.length > 0) {
134 try {
135 output = JSON.parse(e_1.response.body);
136 e_1.description = output.error || output.message;
137 }
138 catch (err) {
139 e_1.description = e_1.response.body;
140 }
141 }
142 _a.label = 7;
143 case 7: throw e_1;
144 case 8:
145 i += 1;
146 return [3 /*break*/, 1];
147 case 9:
148 statusCode = response.statusCode, headers = response.headers;
149 body = processBody(response);
150 return [2 /*return*/, { body: body, headers: headers, status: statusCode }];
151 }
152 });
153 });
154}
155var requesterFn = createRequesterFn(defaultOptionsHandler, handler);
156
157var API = presetResourceArguments(Resources, { requesterFn: requesterFn });
158var // Groups
159Groups = API.Groups, GroupAccessRequests = API.GroupAccessRequests, GroupBadges = API.GroupBadges, GroupCustomAttributes = API.GroupCustomAttributes, GroupIssueBoards = API.GroupIssueBoards, GroupMembers = API.GroupMembers, GroupMilestones = API.GroupMilestones, GroupRunners = API.GroupRunners, GroupVariables = API.GroupVariables, GroupLabels = API.GroupLabels, GroupDeployTokens = API.GroupDeployTokens, Epics = API.Epics, EpicIssues = API.EpicIssues, EpicNotes = API.EpicNotes, EpicDiscussions = API.EpicDiscussions,
160// Users
161Users = API.Users, UserCustomAttributes = API.UserCustomAttributes, UserEmails = API.UserEmails, UserImpersonationTokens = API.UserImpersonationTokens, UserSSHKeys = API.UserSSHKeys, UserGPGKeys = API.UserGPGKeys,
162// Projects
163Branches = API.Branches, Commits = API.Commits, CommitDiscussions = API.CommitDiscussions, ContainerRegistry = API.ContainerRegistry, Deployments = API.Deployments, DeployKeys = API.DeployKeys, Environments = API.Environments, FreezePeriods = API.FreezePeriods, Issues = API.Issues, IssuesStatistics = API.IssuesStatistics, IssueNotes = API.IssueNotes, IssueNoteAwardEmojis = API.IssueNoteAwardEmojis, IssueDiscussions = API.IssueDiscussions, IssueAwardEmojis = API.IssueAwardEmojis, Jobs = API.Jobs, Labels = API.Labels, MergeRequests = API.MergeRequests, MergeRequestApprovals = API.MergeRequestApprovals, MergeRequestAwardEmojis = API.MergeRequestAwardEmojis, MergeRequestDiscussions = API.MergeRequestDiscussions, MergeRequestNotes = API.MergeRequestNotes, Packages = API.Packages, PackageRegistry = API.PackageRegistry, Pipelines = API.Pipelines, PipelineSchedules = API.PipelineSchedules, PipelineScheduleVariables = API.PipelineScheduleVariables, Projects = API.Projects, ProjectAccessRequests = API.ProjectAccessRequests, ProjectBadges = API.ProjectBadges, ProjectCustomAttributes = API.ProjectCustomAttributes, ProjectImportExport = API.ProjectImportExport, ProjectIssueBoards = API.ProjectIssueBoards, ProjectHooks = API.ProjectHooks, ProjectMembers = API.ProjectMembers, ProjectMilestones = API.ProjectMilestones, ProjectSnippets = API.ProjectSnippets, ProjectSnippetNotes = API.ProjectSnippetNotes, ProjectSnippetDiscussions = API.ProjectSnippetDiscussions, ProjectSnippetAwardEmojis = API.ProjectSnippetAwardEmojis, ProtectedBranches = API.ProtectedBranches, ProtectedTags = API.ProtectedTags, ProjectVariables = API.ProjectVariables, ProjectDeployTokens = API.ProjectDeployTokens, PushRules = API.PushRules, Releases = API.Releases, ReleaseLinks = API.ReleaseLinks, Repositories = API.Repositories, RepositoryFiles = API.RepositoryFiles, RepositorySubmodules = API.RepositorySubmodules, Runners = API.Runners, Services = API.Services, Tags = API.Tags, Todos = API.Todos, Triggers = API.Triggers, VulnerabilityFindings = API.VulnerabilityFindings,
164// Genral
165ApplicationSettings = API.ApplicationSettings, BroadcastMessages = API.BroadcastMessages, Events = API.Events, FeatureFlags = API.FeatureFlags, GeoNodes = API.GeoNodes, GitignoreTemplates = API.GitignoreTemplates, GitLabCIYMLTemplates = API.GitLabCIYMLTemplates, Keys = API.Keys, License = API.License, LicenseTemplates = API.LicenseTemplates, Lint = API.Lint, Namespaces = API.Namespaces, NotificationSettings = API.NotificationSettings, Markdown = API.Markdown, PagesDomains = API.PagesDomains, Search = API.Search, SidekiqMetrics = API.SidekiqMetrics, Snippets = API.Snippets, SystemHooks = API.SystemHooks, Version = API.Version, Wikis = API.Wikis, Gitlab = API.Gitlab;
166
167export { ApplicationSettings, Branches, BroadcastMessages, CommitDiscussions, Commits, ContainerRegistry, DeployKeys, Deployments, Environments, EpicDiscussions, EpicIssues, EpicNotes, Epics, Events, FeatureFlags, FreezePeriods, GeoNodes, GitLabCIYMLTemplates, GitignoreTemplates, Gitlab, GroupAccessRequests, GroupBadges, GroupCustomAttributes, GroupDeployTokens, GroupIssueBoards, GroupLabels, GroupMembers, GroupMilestones, GroupRunners, GroupVariables, Groups, IssueAwardEmojis, IssueDiscussions, IssueNoteAwardEmojis, IssueNotes, Issues, IssuesStatistics, Jobs, Keys, Labels, License, LicenseTemplates, Lint, Markdown, MergeRequestApprovals, MergeRequestAwardEmojis, MergeRequestDiscussions, MergeRequestNotes, MergeRequests, Namespaces, NotificationSettings, PackageRegistry, Packages, PagesDomains, PipelineScheduleVariables, PipelineSchedules, Pipelines, ProjectAccessRequests, ProjectBadges, ProjectCustomAttributes, ProjectDeployTokens, ProjectHooks, ProjectImportExport, ProjectIssueBoards, ProjectMembers, ProjectMilestones, ProjectSnippetAwardEmojis, ProjectSnippetDiscussions, ProjectSnippetNotes, ProjectSnippets, ProjectVariables, Projects, ProtectedBranches, ProtectedTags, PushRules, ReleaseLinks, Releases, Repositories, RepositoryFiles, RepositorySubmodules, Runners, Search, Services, SidekiqMetrics, Snippets, SystemHooks, Tags, Todos, Triggers, UserCustomAttributes, UserEmails, UserGPGKeys, UserImpersonationTokens, UserSSHKeys, Users, Version, VulnerabilityFindings, Wikis };
168//# sourceMappingURL=index.es.js.map