api 6.1.1 → 7.0.0-alpha.0
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 +1 -1
- package/README.md +0 -12
- package/package.json +14 -32
- package/src/bin.ts +1 -1
- package/src/{cli/codegen → codegen}/language.ts +3 -2
- package/src/{cli/codegen → codegen}/languages/typescript/util.ts +1 -1
- package/src/{cli/codegen → codegen}/languages/typescript.ts +31 -32
- package/src/{cli/commands → commands}/install.ts +1 -1
- package/src/fetcher.ts +4 -5
- package/src/packageInfo.ts +1 -1
- package/src/{cli/storage.ts → storage.ts} +13 -9
- package/tsconfig.json +3 -13
- package/dist/bin.d.ts +0 -1
- package/dist/bin.js +0 -91
- package/dist/cache.d.ts +0 -68
- package/dist/cache.js +0 -198
- package/dist/cli/codegen/index.d.ts +0 -4
- package/dist/cli/codegen/index.js +0 -23
- package/dist/cli/codegen/language.d.ts +0 -27
- package/dist/cli/codegen/language.js +0 -32
- package/dist/cli/codegen/languages/typescript/util.d.ts +0 -20
- package/dist/cli/codegen/languages/typescript/util.js +0 -176
- package/dist/cli/codegen/languages/typescript.d.ts +0 -111
- package/dist/cli/codegen/languages/typescript.js +0 -821
- package/dist/cli/commands/index.d.ts +0 -4
- package/dist/cli/commands/index.js +0 -9
- package/dist/cli/commands/install.d.ts +0 -3
- package/dist/cli/commands/install.js +0 -236
- package/dist/cli/lib/prompt.d.ts +0 -9
- package/dist/cli/lib/prompt.js +0 -81
- package/dist/cli/logger.d.ts +0 -1
- package/dist/cli/logger.js +0 -16
- package/dist/cli/storage.d.ts +0 -105
- package/dist/cli/storage.js +0 -277
- package/dist/core/errors/fetchError.d.ts +0 -12
- package/dist/core/errors/fetchError.js +0 -36
- package/dist/core/getJSONSchemaDefaults.d.ts +0 -14
- package/dist/core/getJSONSchemaDefaults.js +0 -61
- package/dist/core/index.d.ts +0 -40
- package/dist/core/index.js +0 -168
- package/dist/core/parseResponse.d.ts +0 -6
- package/dist/core/parseResponse.js +0 -71
- package/dist/core/prepareAuth.d.ts +0 -5
- package/dist/core/prepareAuth.js +0 -84
- package/dist/core/prepareParams.d.ts +0 -21
- package/dist/core/prepareParams.js +0 -425
- package/dist/core/prepareServer.d.ts +0 -10
- package/dist/core/prepareServer.js +0 -47
- package/dist/fetcher.d.ts +0 -54
- package/dist/fetcher.js +0 -164
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -259
- package/dist/packageInfo.d.ts +0 -2
- package/dist/packageInfo.js +0 -6
- package/src/.sink.d.ts +0 -1
- package/src/cache.ts +0 -193
- package/src/core/errors/fetchError.ts +0 -31
- package/src/core/getJSONSchemaDefaults.ts +0 -74
- package/src/core/index.ts +0 -148
- package/src/core/parseResponse.ts +0 -26
- package/src/core/prepareAuth.ts +0 -109
- package/src/core/prepareParams.ts +0 -415
- package/src/core/prepareServer.ts +0 -48
- package/src/index.ts +0 -203
- package/src/typings.d.ts +0 -2
- /package/src/{cli/codegen → codegen}/index.ts +0 -0
- /package/src/{cli/commands → commands}/index.ts +0 -0
- /package/src/{cli/lib → lib}/prompt.ts +0 -0
- /package/src/{cli/logger.ts → logger.ts} +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
function stripTrailingSlash(url) {
|
|
4
|
-
if (url[url.length - 1] === '/') {
|
|
5
|
-
return url.slice(0, -1);
|
|
6
|
-
}
|
|
7
|
-
return url;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* With an SDK server config and an instance of OAS we should extract and prepare the server and
|
|
11
|
-
* any server variables to be supplied to `@readme/oas-to-har`.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
function prepareServer(spec, url, variables) {
|
|
15
|
-
if (variables === void 0) { variables = {}; }
|
|
16
|
-
var serverIdx;
|
|
17
|
-
var sanitizedUrl = stripTrailingSlash(url);
|
|
18
|
-
(spec.api.servers || []).forEach(function (server, i) {
|
|
19
|
-
if (server.url === sanitizedUrl) {
|
|
20
|
-
serverIdx = i;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
// If we were able to find the passed in server in the OAS servers, we should use that! If we
|
|
24
|
-
// couldn't and server variables were passed in we should try our best to handle that, otherwise
|
|
25
|
-
// we should ignore the passed in server and use whever the default from the OAS is.
|
|
26
|
-
if (serverIdx) {
|
|
27
|
-
return {
|
|
28
|
-
selected: serverIdx,
|
|
29
|
-
variables: variables
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
else if (Object.keys(variables).length) {
|
|
33
|
-
// @todo we should run `oas.replaceUrl(url)` and pass that unto `@readme/oas-to-har`
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
var server = spec.splitVariables(url);
|
|
37
|
-
if (server) {
|
|
38
|
-
return {
|
|
39
|
-
selected: server.selected,
|
|
40
|
-
variables: server.variables
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
// @todo we should pass `url` directly into `@readme/oas-to-har` as the base URL
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
exports["default"] = prepareServer;
|
package/dist/fetcher.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { OASDocument } from 'oas/dist/rmoas.types';
|
|
2
|
-
import 'isomorphic-fetch';
|
|
3
|
-
export default class Fetcher {
|
|
4
|
-
uri: string | OASDocument;
|
|
5
|
-
/**
|
|
6
|
-
* @example @petstore/v1.0#n6kvf10vakpemvplx
|
|
7
|
-
* @example @petstore#n6kvf10vakpemvplx
|
|
8
|
-
*/
|
|
9
|
-
static registryUUIDRegex: RegExp;
|
|
10
|
-
constructor(uri: string | OASDocument);
|
|
11
|
-
static isAPIRegistryUUID(uri: string): boolean;
|
|
12
|
-
static isGitHubBlobURL(uri: string): boolean;
|
|
13
|
-
static getProjectPrefixFromRegistryUUID(uri: string): string;
|
|
14
|
-
load(): Promise<(Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
15
|
-
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
16
|
-
jsonSchemaDialect?: string;
|
|
17
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
18
|
-
} & Pick<{
|
|
19
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
20
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
21
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
22
|
-
}, "paths"> & Omit<Partial<{
|
|
23
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
24
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
25
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
26
|
-
}>, "paths"> & Record<string, unknown>) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
27
|
-
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
28
|
-
jsonSchemaDialect?: string;
|
|
29
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
30
|
-
} & Pick<{
|
|
31
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
32
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
33
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
34
|
-
}, "webhooks"> & Omit<Partial<{
|
|
35
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
36
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
37
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
38
|
-
}>, "webhooks"> & Record<string, unknown>) | (Omit<Omit<import("openapi-types").OpenAPIV3.Document<{}>, "paths" | "components">, "paths" | "components" | "info" | "servers" | "webhooks" | "jsonSchemaDialect"> & {
|
|
39
|
-
info: import("openapi-types").OpenAPIV3_1.InfoObject;
|
|
40
|
-
jsonSchemaDialect?: string;
|
|
41
|
-
servers?: import("openapi-types").OpenAPIV3_1.ServerObject[];
|
|
42
|
-
} & Pick<{
|
|
43
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
44
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
45
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
46
|
-
}, "components"> & Omit<Partial<{
|
|
47
|
-
paths: import("openapi-types").OpenAPIV3_1.PathsObject<{}, {}>;
|
|
48
|
-
webhooks: Record<string, import("openapi-types").OpenAPIV3_1.ReferenceObject | import("openapi-types").OpenAPIV3_1.PathItemObject<{}>>;
|
|
49
|
-
components: import("openapi-types").OpenAPIV3_1.ComponentsObject;
|
|
50
|
-
}>, "components"> & Record<string, unknown>) | (import("openapi-types").OpenAPIV3.Document<{}> & Record<string, unknown>)>;
|
|
51
|
-
static getURL(url: string): Promise<any>;
|
|
52
|
-
static getFile(uri: string): Promise<any>;
|
|
53
|
-
static validate(json: any): Promise<import("openapi-types").OpenAPI.Document<{}>>;
|
|
54
|
-
}
|
package/dist/fetcher.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
exports.__esModule = true;
|
|
42
|
-
var fs_1 = __importDefault(require("fs"));
|
|
43
|
-
var path_1 = __importDefault(require("path"));
|
|
44
|
-
var openapi_parser_1 = __importDefault(require("@readme/openapi-parser"));
|
|
45
|
-
require("isomorphic-fetch");
|
|
46
|
-
var js_yaml_1 = __importDefault(require("js-yaml"));
|
|
47
|
-
var Fetcher = /** @class */ (function () {
|
|
48
|
-
function Fetcher(uri) {
|
|
49
|
-
if (typeof uri === 'string') {
|
|
50
|
-
if (Fetcher.isAPIRegistryUUID(uri)) {
|
|
51
|
-
// Resolve OpenAPI definition shorthand accessors from within the ReadMe API Registry.
|
|
52
|
-
this.uri = uri.replace(Fetcher.registryUUIDRegex, 'https://dash.readme.com/api/v1/api-registry/$4');
|
|
53
|
-
}
|
|
54
|
-
else if (Fetcher.isGitHubBlobURL(uri)) {
|
|
55
|
-
/**
|
|
56
|
-
* People may try to use a public repository URL to the source viewer on GitHub not knowing
|
|
57
|
-
* that this page actually serves HTML. In this case we want to rewrite these to the "raw"
|
|
58
|
-
* version of this page that'll allow us to access the API definition.
|
|
59
|
-
*
|
|
60
|
-
* @example https://github.com/readmeio/oas-examples/blob/main/3.1/json/petstore.json
|
|
61
|
-
*/
|
|
62
|
-
this.uri = uri.replace(/\/\/github.com/, '//raw.githubusercontent.com').replace(/\/blob\//, '/');
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
this.uri = uri;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
this.uri = uri;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
Fetcher.isAPIRegistryUUID = function (uri) {
|
|
73
|
-
return Fetcher.registryUUIDRegex.test(uri);
|
|
74
|
-
};
|
|
75
|
-
Fetcher.isGitHubBlobURL = function (uri) {
|
|
76
|
-
return /\/\/github.com\/[-_a-zA-Z0-9]+\/[-_a-zA-Z0-9]+\/blob\/(.*).(yaml|json|yml)/.test(uri);
|
|
77
|
-
};
|
|
78
|
-
Fetcher.getProjectPrefixFromRegistryUUID = function (uri) {
|
|
79
|
-
var matches = uri.match(Fetcher.registryUUIDRegex);
|
|
80
|
-
if (!matches) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
return matches.groups.project;
|
|
84
|
-
};
|
|
85
|
-
Fetcher.prototype.load = function () {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
if (typeof this.uri !== 'string') {
|
|
89
|
-
throw new TypeError("Something disastrous occurred and a non-string URI was supplied to the Fetcher library. This shouldn't have happened!");
|
|
90
|
-
}
|
|
91
|
-
return [2 /*return*/, Promise.resolve(this.uri)
|
|
92
|
-
.then(function (uri) {
|
|
93
|
-
var url;
|
|
94
|
-
try {
|
|
95
|
-
url = new URL(uri);
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
// If that try fails for whatever reason than the URI that we have isn't a real URL and
|
|
99
|
-
// we can safely attempt to look for it on the filesystem.
|
|
100
|
-
return Fetcher.getFile(uri);
|
|
101
|
-
}
|
|
102
|
-
return Fetcher.getURL(url.href);
|
|
103
|
-
})
|
|
104
|
-
.then(function (res) { return Fetcher.validate(res); })
|
|
105
|
-
.then(function (res) { return res; })];
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
Fetcher.getURL = function (url) {
|
|
110
|
-
// @todo maybe include our user-agent here to identify our request
|
|
111
|
-
return fetch(url).then(function (res) {
|
|
112
|
-
if (!res.ok) {
|
|
113
|
-
throw new Error("Unable to retrieve URL (".concat(url, "). Reason: ").concat(res.statusText));
|
|
114
|
-
}
|
|
115
|
-
if (res.headers.get('content-type') === 'application/yaml' || /\.(yaml|yml)/.test(url)) {
|
|
116
|
-
return res.text().then(function (text) {
|
|
117
|
-
return js_yaml_1["default"].load(text);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return res.json();
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
Fetcher.getFile = function (uri) {
|
|
124
|
-
// Support relative paths by resolving them against the cwd.
|
|
125
|
-
var file = path_1["default"].resolve(process.cwd(), uri);
|
|
126
|
-
if (!fs_1["default"].existsSync(file)) {
|
|
127
|
-
throw new Error("Sorry, we were unable to load an API definition from ".concat(file, ". Please either supply a URL or a path on your filesystem."));
|
|
128
|
-
}
|
|
129
|
-
return Promise.resolve(fs_1["default"].readFileSync(file, 'utf8')).then(function (res) {
|
|
130
|
-
if (/\.(yaml|yml)/.test(file)) {
|
|
131
|
-
return js_yaml_1["default"].load(res);
|
|
132
|
-
}
|
|
133
|
-
return JSON.parse(res);
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
Fetcher.validate = function (json) {
|
|
137
|
-
if (json.swagger) {
|
|
138
|
-
throw new Error('Sorry, this module only supports OpenAPI definitions.');
|
|
139
|
-
}
|
|
140
|
-
// The `validate` method handles dereferencing for us.
|
|
141
|
-
return openapi_parser_1["default"].validate(json, {
|
|
142
|
-
dereference: {
|
|
143
|
-
/**
|
|
144
|
-
* If circular `$refs` are ignored they'll remain in the API definition as `$ref: String`.
|
|
145
|
-
* This allows us to not only do easy circular reference detection but also stringify and
|
|
146
|
-
* save dereferenced API definitions back into the cache directory.
|
|
147
|
-
*/
|
|
148
|
-
circular: 'ignore'
|
|
149
|
-
}
|
|
150
|
-
})["catch"](function (err) {
|
|
151
|
-
if (/is not a valid openapi definition/i.test(err.message)) {
|
|
152
|
-
throw new Error("Sorry, that doesn't look like a valid OpenAPI definition.");
|
|
153
|
-
}
|
|
154
|
-
throw err;
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
* @example @petstore/v1.0#n6kvf10vakpemvplx
|
|
159
|
-
* @example @petstore#n6kvf10vakpemvplx
|
|
160
|
-
*/
|
|
161
|
-
Fetcher.registryUUIDRegex = /^@(?<project>[a-zA-Z0-9-_]+)(\/?(?<version>.+))?#(?<uuid>[a-z0-9]+)$/;
|
|
162
|
-
return Fetcher;
|
|
163
|
-
}());
|
|
164
|
-
exports["default"] = Fetcher;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
-
};
|
|
50
|
-
var oas_1 = __importDefault(require("oas"));
|
|
51
|
-
var cache_1 = __importDefault(require("./cache"));
|
|
52
|
-
var core_1 = __importDefault(require("./core"));
|
|
53
|
-
var packageInfo_1 = require("./packageInfo");
|
|
54
|
-
var Sdk = /** @class */ (function () {
|
|
55
|
-
function Sdk(uri, opts) {
|
|
56
|
-
if (opts === void 0) { opts = {}; }
|
|
57
|
-
this.uri = uri;
|
|
58
|
-
this.userAgent = "".concat(packageInfo_1.PACKAGE_NAME, " (node)/").concat(packageInfo_1.PACKAGE_VERSION);
|
|
59
|
-
this.cacheDir = opts.cacheDir ? opts.cacheDir : false;
|
|
60
|
-
}
|
|
61
|
-
Sdk.prototype.load = function () {
|
|
62
|
-
var cache = new cache_1["default"](this.uri, this.cacheDir);
|
|
63
|
-
var userAgent = this.userAgent;
|
|
64
|
-
var core = new core_1["default"]();
|
|
65
|
-
core.setUserAgent(userAgent);
|
|
66
|
-
var isLoaded = false;
|
|
67
|
-
var isCached = cache.isCached();
|
|
68
|
-
var sdk = {};
|
|
69
|
-
/**
|
|
70
|
-
* Create dynamic accessors for every operation with a defined operation ID. If an operation
|
|
71
|
-
* does not have an operation ID it can be accessed by its `.method('/path')` accessor instead.
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
function loadOperations(spec) {
|
|
75
|
-
return Object.entries(spec.getPaths())
|
|
76
|
-
.map(function (_a) {
|
|
77
|
-
var operations = _a[1];
|
|
78
|
-
return Object.values(operations);
|
|
79
|
-
})
|
|
80
|
-
.reduce(function (prev, next) { return prev.concat(next); }, [])
|
|
81
|
-
.reduce(function (prev, next) {
|
|
82
|
-
var _a;
|
|
83
|
-
// `getOperationId()` creates dynamic operation IDs when one isn't available but we need
|
|
84
|
-
// to know here if we actually have one present or not. The `camelCase` option here also
|
|
85
|
-
// cleans up any `operationId` that we might have into something that can be used as a
|
|
86
|
-
// valid JS method.
|
|
87
|
-
var originalOperationId = next.getOperationId();
|
|
88
|
-
var operationId = next.getOperationId({ camelCase: true });
|
|
89
|
-
var op = (_a = {},
|
|
90
|
-
_a[operationId] = (function (operation) {
|
|
91
|
-
var args = [];
|
|
92
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
93
|
-
args[_i - 1] = arguments[_i];
|
|
94
|
-
}
|
|
95
|
-
return core.fetchOperation.apply(core, __spreadArray([operation], args, false));
|
|
96
|
-
}).bind(null, next),
|
|
97
|
-
_a);
|
|
98
|
-
if (operationId !== originalOperationId) {
|
|
99
|
-
// If we cleaned up their operation ID into a friendly method accessor (`findPetById`
|
|
100
|
-
// versus `find pet by id`) we should still let them use the non-friendly version if
|
|
101
|
-
// they want.
|
|
102
|
-
//
|
|
103
|
-
// This work is to maintain backwards compatibility with `api@4` and does not exist
|
|
104
|
-
// within our code generated SDKs -- those only allow the cleaner camelCase
|
|
105
|
-
// `operationId` to be used.
|
|
106
|
-
op[originalOperationId] = (function (operation) {
|
|
107
|
-
var args = [];
|
|
108
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
109
|
-
args[_i - 1] = arguments[_i];
|
|
110
|
-
}
|
|
111
|
-
return core.fetchOperation.apply(core, __spreadArray([operation], args, false));
|
|
112
|
-
}).bind(null, next);
|
|
113
|
-
}
|
|
114
|
-
return Object.assign(prev, op);
|
|
115
|
-
}, {});
|
|
116
|
-
}
|
|
117
|
-
function loadFromCache() {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var cachedSpec, spec;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0:
|
|
123
|
-
if (!isCached) return [3 /*break*/, 2];
|
|
124
|
-
return [4 /*yield*/, cache.get()];
|
|
125
|
-
case 1:
|
|
126
|
-
cachedSpec = _a.sent();
|
|
127
|
-
return [3 /*break*/, 4];
|
|
128
|
-
case 2: return [4 /*yield*/, cache.load()];
|
|
129
|
-
case 3:
|
|
130
|
-
cachedSpec = _a.sent();
|
|
131
|
-
isCached = true;
|
|
132
|
-
_a.label = 4;
|
|
133
|
-
case 4:
|
|
134
|
-
spec = new oas_1["default"](cachedSpec);
|
|
135
|
-
core.setSpec(spec);
|
|
136
|
-
sdk = Object.assign(sdk, loadOperations(spec));
|
|
137
|
-
isLoaded = true;
|
|
138
|
-
return [2 /*return*/];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
var sdkProxy = {
|
|
144
|
-
// @give this a better type than any
|
|
145
|
-
get: function (target, method) {
|
|
146
|
-
// Since auth returns a self-proxy, we **do not** want it to fall through into the async
|
|
147
|
-
// function below as when that'll happen, instead of returning a self-proxy, it'll end up
|
|
148
|
-
// returning a Promise. When that happens, chaining `sdk.auth().operationId()` will fail.
|
|
149
|
-
if (['auth', 'config'].includes(method)) {
|
|
150
|
-
// @todo split this up so we have better types for `auth` and `config`
|
|
151
|
-
return function authAndConfigHandler() {
|
|
152
|
-
var args = [];
|
|
153
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
154
|
-
args[_i] = arguments[_i];
|
|
155
|
-
}
|
|
156
|
-
return target[method].apply(this, args);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
return function accessorHandler() {
|
|
160
|
-
var args = [];
|
|
161
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
162
|
-
args[_i] = arguments[_i];
|
|
163
|
-
}
|
|
164
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
-
return __generator(this, function (_a) {
|
|
166
|
-
switch (_a.label) {
|
|
167
|
-
case 0:
|
|
168
|
-
if (!!(method in target)) return [3 /*break*/, 2];
|
|
169
|
-
// If this method doesn't exist on the proxy, have we loaded the SDK? If we have, then
|
|
170
|
-
// this method isn't valid.
|
|
171
|
-
if (isLoaded) {
|
|
172
|
-
throw new Error("Sorry, `".concat(method, "` does not appear to be a valid operation on this API."));
|
|
173
|
-
}
|
|
174
|
-
return [4 /*yield*/, loadFromCache()];
|
|
175
|
-
case 1:
|
|
176
|
-
_a.sent();
|
|
177
|
-
// If after loading the SDK and this method still doesn't exist, then it's not real!
|
|
178
|
-
if (!(method in sdk)) {
|
|
179
|
-
throw new Error("Sorry, `".concat(method, "` does not appear to be a valid operation on this API."));
|
|
180
|
-
}
|
|
181
|
-
// @todo give sdk a better type
|
|
182
|
-
return [2 /*return*/, sdk[method].apply(this, args)];
|
|
183
|
-
case 2: return [2 /*return*/, target[method].apply(this, args)];
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
sdk = {
|
|
191
|
-
/**
|
|
192
|
-
* If the API you're using requires authentication you can supply the required credentials
|
|
193
|
-
* through this method and the library will magically determine how they should be used
|
|
194
|
-
* within your API request.
|
|
195
|
-
*
|
|
196
|
-
* With the exception of OpenID and MutualTLS, it supports all forms of authentication
|
|
197
|
-
* supported by the OpenAPI specification.
|
|
198
|
-
*
|
|
199
|
-
* @example <caption>HTTP Basic auth</caption>
|
|
200
|
-
* sdk.auth('username', 'password');
|
|
201
|
-
*
|
|
202
|
-
* @example <caption>Bearer tokens (HTTP or OAuth 2)</caption>
|
|
203
|
-
* sdk.auth('myBearerToken');
|
|
204
|
-
*
|
|
205
|
-
* @example <caption>API Keys</caption>
|
|
206
|
-
* sdk.auth('myApiKey');
|
|
207
|
-
*
|
|
208
|
-
* @see {@link https://spec.openapis.org/oas/v3.0.3#fixed-fields-22}
|
|
209
|
-
* @see {@link https://spec.openapis.org/oas/v3.1.0#fixed-fields-22}
|
|
210
|
-
* @param values Your auth credentials for the API. Can specify up to two strings or numbers.
|
|
211
|
-
*/
|
|
212
|
-
auth: function () {
|
|
213
|
-
var values = [];
|
|
214
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
215
|
-
values[_i] = arguments[_i];
|
|
216
|
-
}
|
|
217
|
-
core.setAuth.apply(core, values);
|
|
218
|
-
},
|
|
219
|
-
/**
|
|
220
|
-
* Optionally configure various options that the SDK allows.
|
|
221
|
-
*
|
|
222
|
-
* @param config Object of supported SDK options and toggles.
|
|
223
|
-
* @param config.timeout Override the default `fetch` request timeout of 30 seconds (30000ms).
|
|
224
|
-
*/
|
|
225
|
-
config: function (config) {
|
|
226
|
-
core.setConfig(config);
|
|
227
|
-
},
|
|
228
|
-
/**
|
|
229
|
-
* If the API you're using offers alternate server URLs, and server variables, you can tell
|
|
230
|
-
* the SDK which one to use with this method. To use it you can supply either one of the
|
|
231
|
-
* server URLs that are contained within the OpenAPI definition (along with any server
|
|
232
|
-
* variables), or you can pass it a fully qualified URL to use (that may or may not exist
|
|
233
|
-
* within the OpenAPI definition).
|
|
234
|
-
*
|
|
235
|
-
* @example <caption>Server URL with server variables</caption>
|
|
236
|
-
* sdk.server('https://{region}.api.example.com/{basePath}', {
|
|
237
|
-
* name: 'eu',
|
|
238
|
-
* basePath: 'v14',
|
|
239
|
-
* });
|
|
240
|
-
*
|
|
241
|
-
* @example <caption>Fully qualified server URL</caption>
|
|
242
|
-
* sdk.server('https://eu.api.example.com/v14');
|
|
243
|
-
*
|
|
244
|
-
* @param url Server URL
|
|
245
|
-
* @param variables An object of variables to replace into the server URL.
|
|
246
|
-
*/
|
|
247
|
-
server: function (url, variables) {
|
|
248
|
-
if (variables === void 0) { variables = {}; }
|
|
249
|
-
core.setServer(url, variables);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
return new Proxy(sdk, sdkProxy);
|
|
253
|
-
};
|
|
254
|
-
return Sdk;
|
|
255
|
-
}());
|
|
256
|
-
module.exports = function (uri, opts) {
|
|
257
|
-
if (opts === void 0) { opts = {}; }
|
|
258
|
-
return new Sdk(uri, opts).load();
|
|
259
|
-
};
|
package/dist/packageInfo.d.ts
DELETED
package/dist/packageInfo.js
DELETED
package/src/.sink.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'form-data-encoder';
|