@leonardo-ai/sdk 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +98 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/internal/utils/contenttype.d.ts +1 -0
- package/dist/internal/utils/contenttype.js +30 -0
- package/dist/internal/utils/headers.d.ts +4 -0
- package/dist/internal/utils/headers.js +85 -0
- package/dist/internal/utils/index.d.ts +8 -0
- package/dist/internal/utils/index.js +24 -0
- package/dist/internal/utils/pathparams.d.ts +9 -0
- package/dist/internal/utils/pathparams.js +58 -0
- package/dist/internal/utils/queryparams.d.ts +3 -0
- package/dist/internal/utils/queryparams.js +104 -0
- package/dist/internal/utils/requestbody.d.ts +1 -0
- package/dist/internal/utils/requestbody.js +266 -0
- package/dist/internal/utils/retries.d.ts +20 -0
- package/dist/internal/utils/retries.js +223 -0
- package/dist/internal/utils/security.d.ts +2 -0
- package/dist/internal/utils/security.js +156 -0
- package/dist/internal/utils/utils.d.ts +19 -0
- package/dist/internal/utils/utils.js +202 -0
- package/dist/sdk/creatingdatasets.d.ts +41 -0
- package/dist/sdk/creatingdatasets.js +235 -0
- package/dist/sdk/generatingimages.d.ts +35 -0
- package/dist/sdk/generatingimages.js +182 -0
- package/dist/sdk/imagevariations.d.ts +23 -0
- package/dist/sdk/imagevariations.js +120 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +17 -0
- package/dist/sdk/initimages.d.ts +29 -0
- package/dist/sdk/initimages.js +151 -0
- package/dist/sdk/models/operations/deletedatasetsid.d.ts +12 -0
- package/dist/sdk/models/operations/deletedatasetsid.js +72 -0
- package/dist/sdk/models/operations/deletegenerationsid.d.ts +12 -0
- package/dist/sdk/models/operations/deletegenerationsid.js +72 -0
- package/dist/sdk/models/operations/deleteinitimageid.d.ts +12 -0
- package/dist/sdk/models/operations/deleteinitimageid.js +72 -0
- package/dist/sdk/models/operations/deletemodelsid.d.ts +12 -0
- package/dist/sdk/models/operations/deletemodelsid.js +72 -0
- package/dist/sdk/models/operations/getdatasetsid.d.ts +12 -0
- package/dist/sdk/models/operations/getdatasetsid.js +72 -0
- package/dist/sdk/models/operations/getgenerationsid.d.ts +12 -0
- package/dist/sdk/models/operations/getgenerationsid.js +72 -0
- package/dist/sdk/models/operations/getgenerationsuseruserid.d.ts +17 -0
- package/dist/sdk/models/operations/getgenerationsuseruserid.js +92 -0
- package/dist/sdk/models/operations/getinitimageid.d.ts +12 -0
- package/dist/sdk/models/operations/getinitimageid.js +72 -0
- package/dist/sdk/models/operations/getme.d.ts +6 -0
- package/dist/sdk/models/operations/getme.js +48 -0
- package/dist/sdk/models/operations/getmodelsid.d.ts +12 -0
- package/dist/sdk/models/operations/getmodelsid.js +72 -0
- package/dist/sdk/models/operations/getvariationsid.d.ts +12 -0
- package/dist/sdk/models/operations/getvariationsid.js +72 -0
- package/dist/sdk/models/operations/index.d.ts +18 -0
- package/dist/sdk/models/operations/index.js +34 -0
- package/dist/sdk/models/operations/postdatasets.d.ts +13 -0
- package/dist/sdk/models/operations/postdatasets.js +76 -0
- package/dist/sdk/models/operations/postdatasetsdatasetidupload.d.ts +16 -0
- package/dist/sdk/models/operations/postdatasetsdatasetidupload.js +88 -0
- package/dist/sdk/models/operations/postdatasetsdatasetiduploadgen.d.ts +16 -0
- package/dist/sdk/models/operations/postdatasetsdatasetiduploadgen.js +88 -0
- package/dist/sdk/models/operations/postgenerations.d.ts +27 -0
- package/dist/sdk/models/operations/postgenerations.js +132 -0
- package/dist/sdk/models/operations/postinitimage.d.ts +12 -0
- package/dist/sdk/models/operations/postinitimage.js +72 -0
- package/dist/sdk/models/operations/postmodels.d.ts +20 -0
- package/dist/sdk/models/operations/postmodels.js +104 -0
- package/dist/sdk/models/operations/postvariationsupscale.d.ts +12 -0
- package/dist/sdk/models/operations/postvariationsupscale.js +72 -0
- package/dist/sdk/models/shared/index.d.ts +1 -0
- package/dist/sdk/models/shared/index.js +17 -0
- package/dist/sdk/models/shared/security.d.ts +7 -0
- package/dist/sdk/models/shared/security.js +52 -0
- package/dist/sdk/sdk.d.ts +29 -0
- package/dist/sdk/sdk.js +68 -0
- package/dist/sdk/trainingmodels.d.ts +29 -0
- package/dist/sdk/trainingmodels.js +151 -0
- package/dist/sdk/userinformation.d.ts +17 -0
- package/dist/sdk/userinformation.js +76 -0
- package/package.json +41 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.serializeRequestBody = void 0;
|
|
18
|
+
var form_data_1 = __importDefault(require("form-data"));
|
|
19
|
+
var requestMetadataKey = "request";
|
|
20
|
+
var mpFormMetadataKey = "multipart_form";
|
|
21
|
+
function serializeRequestBody(request) {
|
|
22
|
+
if (!request.hasOwnProperty(requestMetadataKey)) {
|
|
23
|
+
throw new Error("request body not found");
|
|
24
|
+
}
|
|
25
|
+
var requestBodyObj = request;
|
|
26
|
+
var firstLevelRequestAnn = Reflect.getMetadata(requestMetadataKey, request, requestMetadataKey);
|
|
27
|
+
if (firstLevelRequestAnn == null)
|
|
28
|
+
requestBodyObj = request[requestMetadataKey];
|
|
29
|
+
var fieldNames = Object.getOwnPropertyNames(requestBodyObj);
|
|
30
|
+
var _a = [{}, {}], requestHeaders = _a[0], requestBody = _a[1];
|
|
31
|
+
fieldNames.forEach(function (fname) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
var requestAnn = Reflect.getMetadata(requestMetadataKey, requestBodyObj, fname);
|
|
34
|
+
if (requestAnn == null)
|
|
35
|
+
return;
|
|
36
|
+
var requestDecorator = parseRequestDecorator(requestAnn);
|
|
37
|
+
switch (requestDecorator.MediaType) {
|
|
38
|
+
case "multipart/form-data":
|
|
39
|
+
case "multipart/mixed":
|
|
40
|
+
requestBody = encodeMultipartFormData(requestBodyObj[fname]);
|
|
41
|
+
requestHeaders = requestBody.getHeaders();
|
|
42
|
+
break;
|
|
43
|
+
case "application/x-www-form-urlencoded":
|
|
44
|
+
_a = [
|
|
45
|
+
{ "Content-Type": "".concat(requestDecorator.MediaType) },
|
|
46
|
+
encodeFormUrlEncodeData(requestBodyObj[fname])
|
|
47
|
+
], requestHeaders = _a[0], requestBody = _a[1];
|
|
48
|
+
break;
|
|
49
|
+
case "application/json":
|
|
50
|
+
case "text/json":
|
|
51
|
+
_b = [
|
|
52
|
+
{ "Content-Type": "".concat(requestDecorator.MediaType) },
|
|
53
|
+
__assign({}, requestBodyObj[fname]),
|
|
54
|
+
], requestHeaders = _b[0], requestBody = _b[1];
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
requestBody = requestBodyObj[fname];
|
|
58
|
+
var requestBodyType = typeof requestBody;
|
|
59
|
+
if (requestBodyType === "string" ||
|
|
60
|
+
requestBody instanceof String ||
|
|
61
|
+
requestBody instanceof Uint8Array)
|
|
62
|
+
requestHeaders = { "Content-Type": "".concat(requestDecorator.MediaType) };
|
|
63
|
+
else
|
|
64
|
+
throw new Error("invalid request body type ".concat(requestBodyType, " for mediaType ").concat(requestDecorator.MediaType));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return [requestHeaders, requestBody];
|
|
68
|
+
}
|
|
69
|
+
exports.serializeRequestBody = serializeRequestBody;
|
|
70
|
+
var encodeFormUrlEncodeData = function (data) {
|
|
71
|
+
var formData = new form_data_1.default();
|
|
72
|
+
var fieldNames = Object.getOwnPropertyNames(data);
|
|
73
|
+
fieldNames.forEach(function (fname) {
|
|
74
|
+
var _a;
|
|
75
|
+
var formAnn = Reflect.getMetadata("form", data, fname);
|
|
76
|
+
if (formAnn === null) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var annotation = parseFormMetadata(formAnn);
|
|
80
|
+
if (annotation.json) {
|
|
81
|
+
formData.append((_a = annotation.name) !== null && _a !== void 0 ? _a : fname, JSON.stringify(data[fname]));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (annotation.style === "form") {
|
|
85
|
+
var parsed_1;
|
|
86
|
+
if (annotation.explode === true) {
|
|
87
|
+
parsed_1 = formExplode(fname, data[fname]);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
parsed_1 = formNotExplode(fname, data[fname]);
|
|
91
|
+
}
|
|
92
|
+
Object.keys(parsed_1).forEach(function (key) {
|
|
93
|
+
parsed_1[key].forEach(function (v) {
|
|
94
|
+
return formData.append(key, v);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return formData;
|
|
101
|
+
};
|
|
102
|
+
var formExplode = function (fname, data) {
|
|
103
|
+
var exploded = {};
|
|
104
|
+
if (Array.isArray(data)) {
|
|
105
|
+
data.forEach(function (value) {
|
|
106
|
+
if (!exploded[fname]) {
|
|
107
|
+
exploded[fname] = [];
|
|
108
|
+
}
|
|
109
|
+
exploded[fname].push(value);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (typeof data === "object") {
|
|
114
|
+
Object.keys(data).forEach(function (key) {
|
|
115
|
+
if (!exploded[key]) {
|
|
116
|
+
exploded[key] = [];
|
|
117
|
+
}
|
|
118
|
+
exploded[key].push(data[key]);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (!exploded[fname]) {
|
|
123
|
+
exploded[fname] = [];
|
|
124
|
+
}
|
|
125
|
+
exploded[fname].push(data.toString());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return exploded;
|
|
129
|
+
};
|
|
130
|
+
var formNotExplode = function (fname, data) {
|
|
131
|
+
var notExploded = {};
|
|
132
|
+
if (Array.isArray(data)) {
|
|
133
|
+
if (!notExploded[fname]) {
|
|
134
|
+
notExploded[fname] = [];
|
|
135
|
+
}
|
|
136
|
+
notExploded[fname].push(data
|
|
137
|
+
.map(function (item) { return item.toString(); })
|
|
138
|
+
.join(","));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
if (typeof data === "object") {
|
|
142
|
+
Object.keys(data).forEach(function (key) {
|
|
143
|
+
if (!notExploded[key]) {
|
|
144
|
+
notExploded[key] = [];
|
|
145
|
+
}
|
|
146
|
+
notExploded[fname].push("".concat(key, "=").concat(data[key]));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
if (!notExploded[fname]) {
|
|
151
|
+
notExploded[fname] = [];
|
|
152
|
+
}
|
|
153
|
+
notExploded[fname].push(data.toString());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return notExploded;
|
|
157
|
+
};
|
|
158
|
+
var parseFormMetadata = function (formAnn) {
|
|
159
|
+
return formAnn.split(";").map(function (keyValue) {
|
|
160
|
+
var split = keyValue.split("=");
|
|
161
|
+
if (split.length !== 2) {
|
|
162
|
+
throw new Error("Unable to parse form metadata \"".concat(keyValue, "\""));
|
|
163
|
+
}
|
|
164
|
+
var obj = {};
|
|
165
|
+
obj[split[0]] = split[0] === "explode" || split[0] === "json" ? split[1] === "true" : split[1];
|
|
166
|
+
return obj;
|
|
167
|
+
}).reduce(function (accum, cur) { return (__assign(__assign({}, accum), cur)); });
|
|
168
|
+
};
|
|
169
|
+
function encodeMultipartFormData(form) {
|
|
170
|
+
var formData = new form_data_1.default();
|
|
171
|
+
var fieldNames = Object.getOwnPropertyNames(form);
|
|
172
|
+
fieldNames.forEach(function (fname) {
|
|
173
|
+
var mpFormAnn = Reflect.getMetadata(mpFormMetadataKey, form, fname);
|
|
174
|
+
if (mpFormAnn == null)
|
|
175
|
+
return;
|
|
176
|
+
var mpFormDecorator = parseMultipartFormDecorator(mpFormAnn);
|
|
177
|
+
if (mpFormDecorator.File)
|
|
178
|
+
return encodeMultipartFormDataFile(formData, form[fname]);
|
|
179
|
+
else if (mpFormDecorator.JSON) {
|
|
180
|
+
formData.append(mpFormDecorator.Name, JSON.stringify(form[fname]));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
if (Array.isArray(form[fname])) {
|
|
184
|
+
form[fname].forEach(function (val) {
|
|
185
|
+
formData.append(mpFormDecorator.Name + "[]", String(val));
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
formData.append(mpFormDecorator.Name, String(form[fname]));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return formData;
|
|
194
|
+
}
|
|
195
|
+
function encodeMultipartFormDataFile(formData, file) {
|
|
196
|
+
if (typeof file !== "object" || Array.isArray(file) || file == null) {
|
|
197
|
+
throw new Error("invalid type for multipart/form-data file");
|
|
198
|
+
}
|
|
199
|
+
var fieldNames = Object.getOwnPropertyNames(file);
|
|
200
|
+
var content = null;
|
|
201
|
+
var fileName = "";
|
|
202
|
+
var mpFormDecoratorName = "";
|
|
203
|
+
fieldNames.forEach(function (fname) {
|
|
204
|
+
var mpFormAnn = Reflect.getMetadata(mpFormMetadataKey, file, fname);
|
|
205
|
+
if (mpFormAnn == null)
|
|
206
|
+
return;
|
|
207
|
+
var mpFormDecorator = parseMultipartFormDecorator(mpFormAnn);
|
|
208
|
+
if (!mpFormDecorator.Content && mpFormDecorator.Name == "")
|
|
209
|
+
return;
|
|
210
|
+
if (mpFormDecorator.Content)
|
|
211
|
+
content = file[fname];
|
|
212
|
+
else {
|
|
213
|
+
mpFormDecoratorName = mpFormDecorator.Name;
|
|
214
|
+
fileName = file[fname];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
if (mpFormDecoratorName === "" || fileName === "" || content == null) {
|
|
218
|
+
throw new Error("invalid multipart/form-data file");
|
|
219
|
+
}
|
|
220
|
+
formData.append("file", Buffer.from(content), fileName);
|
|
221
|
+
return formData;
|
|
222
|
+
}
|
|
223
|
+
function parseMultipartFormDecorator(mpFormAnn) {
|
|
224
|
+
// example "name=file"
|
|
225
|
+
var mpFormDecorator = new MultipartFormDecorator(false, false, false, "");
|
|
226
|
+
mpFormAnn.split(";").forEach(function (mpFormAnnPart) {
|
|
227
|
+
var _a = mpFormAnnPart.split("="), mpFormKey = _a[0], mpFormVal = _a[1];
|
|
228
|
+
switch (mpFormKey) {
|
|
229
|
+
case "file":
|
|
230
|
+
mpFormDecorator.File = mpFormVal == "true";
|
|
231
|
+
break;
|
|
232
|
+
case "content":
|
|
233
|
+
mpFormDecorator.Content = mpFormVal == "true";
|
|
234
|
+
break;
|
|
235
|
+
case "name":
|
|
236
|
+
mpFormDecorator.Name = mpFormVal;
|
|
237
|
+
break;
|
|
238
|
+
case "json":
|
|
239
|
+
mpFormDecorator.JSON = mpFormVal == "true";
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return mpFormDecorator;
|
|
243
|
+
}
|
|
244
|
+
var MultipartFormDecorator = /** @class */ (function () {
|
|
245
|
+
function MultipartFormDecorator(File, Content, JSON, Name) {
|
|
246
|
+
this.File = File;
|
|
247
|
+
this.Content = Content;
|
|
248
|
+
this.JSON = JSON;
|
|
249
|
+
this.Name = Name;
|
|
250
|
+
}
|
|
251
|
+
return MultipartFormDecorator;
|
|
252
|
+
}());
|
|
253
|
+
function parseRequestDecorator(requestAnn) {
|
|
254
|
+
// example "media_type=multipart/form-data"
|
|
255
|
+
var requestDecorator = new RequestDecorator("application/octet-stream");
|
|
256
|
+
var _a = requestAnn.split("="), mediaTypeKey = _a[0], mediaTypeVal = _a[1];
|
|
257
|
+
if (mediaTypeKey === "media_type")
|
|
258
|
+
requestDecorator.MediaType = mediaTypeVal;
|
|
259
|
+
return requestDecorator;
|
|
260
|
+
}
|
|
261
|
+
var RequestDecorator = /** @class */ (function () {
|
|
262
|
+
function RequestDecorator(MediaType) {
|
|
263
|
+
this.MediaType = MediaType;
|
|
264
|
+
}
|
|
265
|
+
return RequestDecorator;
|
|
266
|
+
}());
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
export declare class BackoffStrategy {
|
|
3
|
+
initialInterval: number;
|
|
4
|
+
maxInterval: number;
|
|
5
|
+
exponent: number;
|
|
6
|
+
maxElapsedTime: number;
|
|
7
|
+
constructor(initialInterval: number, maxInterval: number, exponent: number, maxElapsedTime: number);
|
|
8
|
+
}
|
|
9
|
+
export declare class RetryConfig {
|
|
10
|
+
strategy: string;
|
|
11
|
+
backoff?: BackoffStrategy;
|
|
12
|
+
retryConnectionErrors: boolean;
|
|
13
|
+
constructor(strategy: string, retryConnectionErrors?: boolean);
|
|
14
|
+
}
|
|
15
|
+
export declare class Retries {
|
|
16
|
+
config: RetryConfig;
|
|
17
|
+
statusCodes: string[];
|
|
18
|
+
constructor(config: RetryConfig, statusCodes: string[]);
|
|
19
|
+
}
|
|
20
|
+
export declare function Retry(fn: () => Promise<AxiosResponse<any, any>>, retries: Retries): Promise<AxiosResponse<any, any>>;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.Retry = exports.Retries = exports.RetryConfig = exports.BackoffStrategy = void 0;
|
|
55
|
+
var axios_1 = require("axios");
|
|
56
|
+
var BackoffStrategy = /** @class */ (function () {
|
|
57
|
+
function BackoffStrategy(initialInterval, maxInterval, exponent, maxElapsedTime) {
|
|
58
|
+
this.initialInterval = initialInterval;
|
|
59
|
+
this.maxInterval = maxInterval;
|
|
60
|
+
this.exponent = exponent;
|
|
61
|
+
this.maxElapsedTime = maxElapsedTime;
|
|
62
|
+
}
|
|
63
|
+
return BackoffStrategy;
|
|
64
|
+
}());
|
|
65
|
+
exports.BackoffStrategy = BackoffStrategy;
|
|
66
|
+
var RetryConfig = /** @class */ (function () {
|
|
67
|
+
function RetryConfig(strategy, retryConnectionErrors) {
|
|
68
|
+
if (retryConnectionErrors === void 0) { retryConnectionErrors = true; }
|
|
69
|
+
this.strategy = strategy;
|
|
70
|
+
this.retryConnectionErrors = retryConnectionErrors;
|
|
71
|
+
}
|
|
72
|
+
return RetryConfig;
|
|
73
|
+
}());
|
|
74
|
+
exports.RetryConfig = RetryConfig;
|
|
75
|
+
var Retries = /** @class */ (function () {
|
|
76
|
+
function Retries(config, statusCodes) {
|
|
77
|
+
this.config = config;
|
|
78
|
+
this.statusCodes = statusCodes;
|
|
79
|
+
}
|
|
80
|
+
return Retries;
|
|
81
|
+
}());
|
|
82
|
+
exports.Retries = Retries;
|
|
83
|
+
var PermanentError = /** @class */ (function (_super) {
|
|
84
|
+
__extends(PermanentError, _super);
|
|
85
|
+
function PermanentError(inner) {
|
|
86
|
+
var _this = _super.call(this, "Permanent error") || this;
|
|
87
|
+
_this.inner = inner;
|
|
88
|
+
return _this;
|
|
89
|
+
}
|
|
90
|
+
return PermanentError;
|
|
91
|
+
}(Error));
|
|
92
|
+
var TemporaryError = /** @class */ (function (_super) {
|
|
93
|
+
__extends(TemporaryError, _super);
|
|
94
|
+
function TemporaryError(res) {
|
|
95
|
+
var _this = _super.call(this, "Temporary error") || this;
|
|
96
|
+
_this.res = res;
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
return TemporaryError;
|
|
100
|
+
}(Error));
|
|
101
|
+
function Retry(fn, retries) {
|
|
102
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var _j;
|
|
105
|
+
var _this = this;
|
|
106
|
+
return __generator(this, function (_k) {
|
|
107
|
+
switch (_k.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
_j = retries.config.strategy;
|
|
110
|
+
switch (_j) {
|
|
111
|
+
case "backoff": return [3 /*break*/, 1];
|
|
112
|
+
}
|
|
113
|
+
return [3 /*break*/, 2];
|
|
114
|
+
case 1: return [2 /*return*/, retryBackoff(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
115
|
+
var res, err_1;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
_a.trys.push([0, 2, , 3]);
|
|
120
|
+
return [4 /*yield*/, fn()];
|
|
121
|
+
case 1:
|
|
122
|
+
res = _a.sent();
|
|
123
|
+
if (isRetryableResponse(res, retries.statusCodes)) {
|
|
124
|
+
throw new TemporaryError(res);
|
|
125
|
+
}
|
|
126
|
+
return [2 /*return*/, res];
|
|
127
|
+
case 2:
|
|
128
|
+
err_1 = _a.sent();
|
|
129
|
+
if (err_1 instanceof axios_1.AxiosError) {
|
|
130
|
+
if (err_1.response) {
|
|
131
|
+
if (isRetryableResponse(err_1.response, retries.statusCodes)) {
|
|
132
|
+
throw err_1;
|
|
133
|
+
}
|
|
134
|
+
throw new PermanentError(err_1);
|
|
135
|
+
}
|
|
136
|
+
else if (err_1.request) {
|
|
137
|
+
throw err_1;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
throw new PermanentError(err_1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (err_1 instanceof TemporaryError) {
|
|
144
|
+
throw err_1;
|
|
145
|
+
}
|
|
146
|
+
throw new PermanentError(err_1);
|
|
147
|
+
case 3: return [2 /*return*/];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}); }, (_b = (_a = retries.config.backoff) === null || _a === void 0 ? void 0 : _a.initialInterval) !== null && _b !== void 0 ? _b : 500, (_d = (_c = retries.config.backoff) === null || _c === void 0 ? void 0 : _c.maxInterval) !== null && _d !== void 0 ? _d : 60000, (_f = (_e = retries.config.backoff) === null || _e === void 0 ? void 0 : _e.exponent) !== null && _f !== void 0 ? _f : 1.5, (_h = (_g = retries.config.backoff) === null || _g === void 0 ? void 0 : _g.maxElapsedTime) !== null && _h !== void 0 ? _h : 3600000)];
|
|
151
|
+
case 2: return [4 /*yield*/, fn()];
|
|
152
|
+
case 3: return [2 /*return*/, _k.sent()];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
exports.Retry = Retry;
|
|
158
|
+
function isRetryableResponse(res, statusCodes) {
|
|
159
|
+
for (var _i = 0, statusCodes_1 = statusCodes; _i < statusCodes_1.length; _i++) {
|
|
160
|
+
var code = statusCodes_1[_i];
|
|
161
|
+
if (code.toUpperCase().includes("X")) {
|
|
162
|
+
var codeRange = parseInt(code[0]);
|
|
163
|
+
if (isNaN(codeRange)) {
|
|
164
|
+
throw new Error("Invalid status code range");
|
|
165
|
+
}
|
|
166
|
+
var s = res.status / 100;
|
|
167
|
+
if (s >= codeRange && s < codeRange + 1) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else if (res.status == parseInt(code)) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
function retryBackoff(fn, initialInterval, maxInterval, exponent, maxElapsedTime) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
var start, x, err_2, now, d;
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
start = Date.now();
|
|
184
|
+
x = 0;
|
|
185
|
+
_a.label = 1;
|
|
186
|
+
case 1:
|
|
187
|
+
if (!true) return [3 /*break*/, 7];
|
|
188
|
+
_a.label = 2;
|
|
189
|
+
case 2:
|
|
190
|
+
_a.trys.push([2, 4, , 6]);
|
|
191
|
+
return [4 /*yield*/, fn()];
|
|
192
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
193
|
+
case 4:
|
|
194
|
+
err_2 = _a.sent();
|
|
195
|
+
if (err_2 instanceof PermanentError) {
|
|
196
|
+
throw err_2.inner;
|
|
197
|
+
}
|
|
198
|
+
now = Date.now();
|
|
199
|
+
if (now - start > maxElapsedTime) {
|
|
200
|
+
if (err_2 instanceof TemporaryError) {
|
|
201
|
+
return [2 /*return*/, err_2.res];
|
|
202
|
+
}
|
|
203
|
+
throw err_2;
|
|
204
|
+
}
|
|
205
|
+
d = Math.min(initialInterval * Math.pow(x, exponent) + Math.random() * 1000, maxInterval);
|
|
206
|
+
return [4 /*yield*/, delay(d)];
|
|
207
|
+
case 5:
|
|
208
|
+
_a.sent();
|
|
209
|
+
x++;
|
|
210
|
+
return [3 /*break*/, 6];
|
|
211
|
+
case 6: return [3 /*break*/, 1];
|
|
212
|
+
case 7: return [2 /*return*/];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function delay(delay) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, delay); })];
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSecurityClient = void 0;
|
|
4
|
+
var securityMetadataKey = "security";
|
|
5
|
+
function createSecurityClient(client, security) {
|
|
6
|
+
return parseSecurityClass(client, security);
|
|
7
|
+
}
|
|
8
|
+
exports.createSecurityClient = createSecurityClient;
|
|
9
|
+
function parseSecurityDecorator(securityAnn) {
|
|
10
|
+
// scheme=true;type=apiKey;subtype=header"
|
|
11
|
+
var option = false;
|
|
12
|
+
var scheme = false;
|
|
13
|
+
var name = "";
|
|
14
|
+
var securityType = "";
|
|
15
|
+
var securitySubType = "";
|
|
16
|
+
securityAnn.split(";").forEach(function (securityAnnPart) {
|
|
17
|
+
var _a = securityAnnPart.split("="), sKey = _a[0], sVal = _a[1];
|
|
18
|
+
switch (sKey) {
|
|
19
|
+
case "name":
|
|
20
|
+
name = sVal;
|
|
21
|
+
break;
|
|
22
|
+
case "type":
|
|
23
|
+
securityType = sVal;
|
|
24
|
+
break;
|
|
25
|
+
case "subtype":
|
|
26
|
+
securitySubType = sVal;
|
|
27
|
+
break;
|
|
28
|
+
case "option":
|
|
29
|
+
option = sVal == "true";
|
|
30
|
+
break;
|
|
31
|
+
case "scheme":
|
|
32
|
+
scheme = sVal == "true";
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return new SecurityDecorator(name, securityType, option, scheme, securitySubType);
|
|
36
|
+
}
|
|
37
|
+
function parseSecurityClass(client, security) {
|
|
38
|
+
var fieldNames = Object.getOwnPropertyNames(security);
|
|
39
|
+
fieldNames.forEach(function (fname) {
|
|
40
|
+
var securityAnn = Reflect.getMetadata(securityMetadataKey, security, fname);
|
|
41
|
+
if (securityAnn == null)
|
|
42
|
+
return;
|
|
43
|
+
var securityDecorator = parseSecurityDecorator(securityAnn);
|
|
44
|
+
if (securityDecorator == null)
|
|
45
|
+
return;
|
|
46
|
+
if (securityDecorator.Option) {
|
|
47
|
+
return parseSecurityOption(client, security[fname]);
|
|
48
|
+
}
|
|
49
|
+
else if (securityDecorator.Scheme) {
|
|
50
|
+
return parseSecurityScheme(client, securityDecorator, security[fname]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return client;
|
|
54
|
+
}
|
|
55
|
+
function parseSecurityOption(client, optionType) {
|
|
56
|
+
var fieldNames = Object.getOwnPropertyNames(optionType);
|
|
57
|
+
fieldNames.forEach(function (fname) {
|
|
58
|
+
var securityAnn = Reflect.getMetadata(securityMetadataKey, optionType, fname);
|
|
59
|
+
if (securityAnn == null)
|
|
60
|
+
return;
|
|
61
|
+
var securityDecorator = parseSecurityDecorator(securityAnn);
|
|
62
|
+
if (securityDecorator != null && securityDecorator.Scheme)
|
|
63
|
+
return;
|
|
64
|
+
if (securityDecorator.Scheme) {
|
|
65
|
+
return parseSecurityScheme(client, securityDecorator, optionType[fname]);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return client;
|
|
69
|
+
}
|
|
70
|
+
function parseSecurityScheme(client, schemeDecorator, scheme) {
|
|
71
|
+
if (schemeDecorator.Type === "http" && schemeDecorator.SubType === "basic") {
|
|
72
|
+
return parseBasicAuthScheme(client, scheme);
|
|
73
|
+
}
|
|
74
|
+
var fieldNames = Object.getOwnPropertyNames(scheme);
|
|
75
|
+
fieldNames.forEach(function (fname) {
|
|
76
|
+
var securityAnn = Reflect.getMetadata(securityMetadataKey, scheme, fname);
|
|
77
|
+
if (securityAnn == null)
|
|
78
|
+
return;
|
|
79
|
+
var securityDecorator = parseSecurityDecorator(securityAnn);
|
|
80
|
+
if (securityDecorator == null || securityDecorator.Name === "")
|
|
81
|
+
return;
|
|
82
|
+
switch (schemeDecorator.Type) {
|
|
83
|
+
case "apiKey":
|
|
84
|
+
switch (schemeDecorator.SubType) {
|
|
85
|
+
case "header":
|
|
86
|
+
client.defaults.headers.common[securityDecorator.Name] =
|
|
87
|
+
scheme[fname];
|
|
88
|
+
break;
|
|
89
|
+
case "query":
|
|
90
|
+
client.defaults.params[securityDecorator.Name] = scheme[fname];
|
|
91
|
+
break;
|
|
92
|
+
case "cookie":
|
|
93
|
+
var securityDecoratorName = securityDecorator.Name;
|
|
94
|
+
var val = scheme[fname];
|
|
95
|
+
client.defaults.headers.common["Cookie"] = "".concat(securityDecoratorName, "=").concat(val);
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
throw new Error("not supported");
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case "openIdConnect":
|
|
102
|
+
client.defaults.headers.common[securityDecorator.Name] = scheme[fname];
|
|
103
|
+
break;
|
|
104
|
+
case "oauth2":
|
|
105
|
+
client.defaults.headers.common[securityDecorator.Name] = scheme[fname];
|
|
106
|
+
break;
|
|
107
|
+
case "http":
|
|
108
|
+
switch (schemeDecorator.SubType) {
|
|
109
|
+
case "basic":
|
|
110
|
+
break;
|
|
111
|
+
case "bearer":
|
|
112
|
+
client.defaults.headers.common[securityDecorator.Name] =
|
|
113
|
+
scheme[fname];
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
throw new Error("not supported");
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
throw new Error("not supported");
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return client;
|
|
124
|
+
}
|
|
125
|
+
function parseBasicAuthScheme(client, scheme) {
|
|
126
|
+
var username, password = "";
|
|
127
|
+
var fieldNames = Object.getOwnPropertyNames(scheme);
|
|
128
|
+
fieldNames.forEach(function (fname) {
|
|
129
|
+
var securityAnn = Reflect.getMetadata(securityMetadataKey, scheme, fname);
|
|
130
|
+
if (securityAnn == null)
|
|
131
|
+
return;
|
|
132
|
+
var securityDecorator = parseSecurityDecorator(securityAnn);
|
|
133
|
+
if (securityDecorator == null || securityDecorator.Name === "")
|
|
134
|
+
return;
|
|
135
|
+
switch (securityDecorator.Name) {
|
|
136
|
+
case "username":
|
|
137
|
+
username = scheme[fname];
|
|
138
|
+
break;
|
|
139
|
+
case "password":
|
|
140
|
+
password = scheme[fname];
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
client.defaults.headers.common["Authorization"] = "Basic ".concat(Buffer.from("".concat(username, ":").concat(password)).toString("base64"));
|
|
145
|
+
return client;
|
|
146
|
+
}
|
|
147
|
+
var SecurityDecorator = /** @class */ (function () {
|
|
148
|
+
function SecurityDecorator(Name, Type, Option, Scheme, SubType) {
|
|
149
|
+
this.Name = Name;
|
|
150
|
+
this.Type = Type;
|
|
151
|
+
this.Option = Option;
|
|
152
|
+
this.Scheme = Scheme;
|
|
153
|
+
this.SubType = SubType;
|
|
154
|
+
}
|
|
155
|
+
return SecurityDecorator;
|
|
156
|
+
}());
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { ParamDecorator } from "./pathparams";
|
|
3
|
+
export declare class SpeakeasyBase {
|
|
4
|
+
constructor(payload?: Record<string | symbol, unknown>);
|
|
5
|
+
}
|
|
6
|
+
export declare function SpeakeasyMetadata<T extends SpeakeasyBase = Record<string | symbol, unknown>>(params?: {
|
|
7
|
+
data?: string;
|
|
8
|
+
elemType?: {
|
|
9
|
+
new (): T;
|
|
10
|
+
};
|
|
11
|
+
elemDepth?: number;
|
|
12
|
+
}): PropertyDecorator;
|
|
13
|
+
export declare function replaceParameters(stringWithParams: string, params: Map<string, string>): string;
|
|
14
|
+
export declare function generateURL(serverURL: string, path: string, pathParams: any): string;
|
|
15
|
+
export declare function parseParamDecorator(ann: string, fName: string, defaultStyle: string, defaultExplode: boolean): ParamDecorator;
|
|
16
|
+
export declare function isStringRecord(obj: any): obj is Record<string, string>;
|
|
17
|
+
export declare function isNumberRecord(obj: any): obj is Record<string, number>;
|
|
18
|
+
export declare function isBooleanRecord(obj: any): obj is Record<string, boolean>;
|
|
19
|
+
export declare function isEmpty(value: any): boolean;
|