windmill-utils-internal 1.3.0 → 1.3.2
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/dist/config/config.js +18 -60
- package/dist/config/index.js +1 -17
- package/dist/constants.js +2 -5
- package/dist/gen/core/ApiError.js +1 -5
- package/dist/gen/core/ApiRequestOptions.js +1 -2
- package/dist/gen/core/ApiResult.js +1 -2
- package/dist/gen/core/CancelablePromise.js +2 -7
- package/dist/gen/core/OpenAPI.js +3 -7
- package/dist/gen/core/request.js +42 -60
- package/dist/gen/index.js +5 -26
- package/dist/gen/services.gen.d.ts +875 -57
- package/dist/gen/services.gen.js +2876 -1708
- package/dist/gen/types.gen.d.ts +2363 -197
- package/dist/gen/types.gen.js +1 -2
- package/dist/index.js +5 -24
- package/dist/inline-scripts/extractor.d.ts +12 -1
- package/dist/inline-scripts/extractor.js +14 -15
- package/dist/inline-scripts/index.js +2 -18
- package/dist/inline-scripts/replacer.d.ts +1 -1
- package/dist/inline-scripts/replacer.js +5 -7
- package/dist/parse/index.js +1 -17
- package/dist/parse/parse-schema.d.ts +5 -2
- package/dist/parse/parse-schema.js +30 -7
- package/dist/path-utils/index.js +1 -17
- package/dist/path-utils/path-assigner.d.ts +31 -1
- package/dist/path-utils/path-assigner.js +91 -10
- package/package.json +1 -1
package/dist/config/config.js
CHANGED
|
@@ -1,55 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.WINDMILL_ACTIVE_INSTANCE_FILE = exports.INSTANCES_CONFIG_FILE = exports.WINDMILL_WORKSPACE_CONFIG_FILE = exports.WINDMILL_ACTIVE_WORKSPACE_FILE = exports.WINDMILL_CONFIG_DIR = void 0;
|
|
37
|
-
exports.getBaseConfigDir = getBaseConfigDir;
|
|
38
|
-
exports.getConfigDirPath = getConfigDirPath;
|
|
39
|
-
exports.getWorkspaceConfigFilePath = getWorkspaceConfigFilePath;
|
|
40
|
-
exports.getActiveWorkspaceConfigFilePath = getActiveWorkspaceConfigFilePath;
|
|
41
|
-
exports.getInstancesConfigFilePath = getInstancesConfigFilePath;
|
|
42
|
-
exports.getActiveInstanceFilePath = getActiveInstanceFilePath;
|
|
43
1
|
// Runtime detection
|
|
44
2
|
// @ts-ignore - Cross-platform runtime detection
|
|
45
3
|
const isDeno = typeof Deno !== "undefined";
|
|
46
4
|
// @ts-ignore - Cross-platform runtime detection
|
|
47
5
|
const isNode = typeof process !== "undefined" && process.versions?.node;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
6
|
+
export const WINDMILL_CONFIG_DIR = "windmill";
|
|
7
|
+
export const WINDMILL_ACTIVE_WORKSPACE_FILE = "activeWorkspace";
|
|
8
|
+
export const WINDMILL_WORKSPACE_CONFIG_FILE = "remotes.ndjson";
|
|
9
|
+
export const INSTANCES_CONFIG_FILE = "instances.ndjson";
|
|
10
|
+
export const WINDMILL_ACTIVE_INSTANCE_FILE = "activeInstance";
|
|
53
11
|
// Cross-platform environment variable access
|
|
54
12
|
function getEnv(key) {
|
|
55
13
|
if (isDeno) {
|
|
@@ -87,7 +45,7 @@ async function stat(path) {
|
|
|
87
45
|
}
|
|
88
46
|
else {
|
|
89
47
|
// @ts-ignore - Node API
|
|
90
|
-
const fs = await
|
|
48
|
+
const fs = await import('fs/promises');
|
|
91
49
|
return await fs.stat(path);
|
|
92
50
|
}
|
|
93
51
|
}
|
|
@@ -98,7 +56,7 @@ async function mkdir(path, options) {
|
|
|
98
56
|
}
|
|
99
57
|
else {
|
|
100
58
|
// @ts-ignore - Node API
|
|
101
|
-
const fs = await
|
|
59
|
+
const fs = await import('fs/promises');
|
|
102
60
|
await fs.mkdir(path, options);
|
|
103
61
|
}
|
|
104
62
|
}
|
|
@@ -199,7 +157,7 @@ async function ensureDir(dir) {
|
|
|
199
157
|
throwIfNotDirectory(fileInfo);
|
|
200
158
|
}
|
|
201
159
|
}
|
|
202
|
-
async function getBaseConfigDir(configDirOverride) {
|
|
160
|
+
export async function getBaseConfigDir(configDirOverride) {
|
|
203
161
|
const baseDir = configDirOverride ??
|
|
204
162
|
getEnv("WMILL_CONFIG_DIR") ??
|
|
205
163
|
config_dir() ??
|
|
@@ -207,25 +165,25 @@ async function getBaseConfigDir(configDirOverride) {
|
|
|
207
165
|
"/tmp/";
|
|
208
166
|
return baseDir;
|
|
209
167
|
}
|
|
210
|
-
async function getConfigDirPath(configDirOverride) {
|
|
168
|
+
export async function getConfigDirPath(configDirOverride) {
|
|
211
169
|
const baseDir = await getBaseConfigDir(configDirOverride);
|
|
212
|
-
const store = baseDir + `/${
|
|
170
|
+
const store = baseDir + `/${WINDMILL_CONFIG_DIR}/`;
|
|
213
171
|
await ensureDir(store);
|
|
214
172
|
return store;
|
|
215
173
|
}
|
|
216
|
-
async function getWorkspaceConfigFilePath(configDirOverride) {
|
|
174
|
+
export async function getWorkspaceConfigFilePath(configDirOverride) {
|
|
217
175
|
const configDir = await getConfigDirPath(configDirOverride);
|
|
218
|
-
return `${configDir}/${
|
|
176
|
+
return `${configDir}/${WINDMILL_WORKSPACE_CONFIG_FILE}`;
|
|
219
177
|
}
|
|
220
|
-
async function getActiveWorkspaceConfigFilePath(configDirOverride) {
|
|
178
|
+
export async function getActiveWorkspaceConfigFilePath(configDirOverride) {
|
|
221
179
|
const configDir = await getConfigDirPath(configDirOverride);
|
|
222
|
-
return `${configDir}/${
|
|
180
|
+
return `${configDir}/${WINDMILL_ACTIVE_WORKSPACE_FILE}`;
|
|
223
181
|
}
|
|
224
|
-
async function getInstancesConfigFilePath(configDirOverride) {
|
|
182
|
+
export async function getInstancesConfigFilePath(configDirOverride) {
|
|
225
183
|
const configDir = await getConfigDirPath(configDirOverride);
|
|
226
|
-
return `${configDir}/${
|
|
184
|
+
return `${configDir}/${INSTANCES_CONFIG_FILE}`;
|
|
227
185
|
}
|
|
228
|
-
async function getActiveInstanceFilePath(configDirOverride) {
|
|
186
|
+
export async function getActiveInstanceFilePath(configDirOverride) {
|
|
229
187
|
const configDir = await getConfigDirPath(configDirOverride);
|
|
230
|
-
return `${configDir}/${
|
|
188
|
+
return `${configDir}/${WINDMILL_ACTIVE_INSTANCE_FILE}`;
|
|
231
189
|
}
|
package/dist/config/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./config"), exports);
|
|
1
|
+
export * from "./config";
|
package/dist/constants.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// constants.ts
|
|
3
2
|
/**
|
|
4
3
|
* Cross-platform path separator constants
|
|
5
4
|
* Compatible with both Node.js and Deno environments
|
|
6
5
|
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.DELIMITER = exports.SEP = void 0;
|
|
9
6
|
/**
|
|
10
7
|
* Detects if the current platform is Windows by checking various environment indicators.
|
|
11
8
|
* Uses multiple fallback methods to ensure compatibility across Node.js, Deno, and browser environments.
|
|
@@ -35,10 +32,10 @@ const isWindows = (() => {
|
|
|
35
32
|
* On Windows: "\"
|
|
36
33
|
* On Unix-like systems: "/"
|
|
37
34
|
*/
|
|
38
|
-
|
|
35
|
+
export const SEP = isWindows ? "\\" : "/";
|
|
39
36
|
/**
|
|
40
37
|
* Path delimiter constant for environment variables like PATH
|
|
41
38
|
* On Windows: ";"
|
|
42
39
|
* On Unix-like systems: ":"
|
|
43
40
|
*/
|
|
44
|
-
|
|
41
|
+
export const DELIMITER = isWindows ? ";" : ":";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiError = void 0;
|
|
4
|
-
class ApiError extends Error {
|
|
1
|
+
export class ApiError extends Error {
|
|
5
2
|
url;
|
|
6
3
|
status;
|
|
7
4
|
statusText;
|
|
@@ -17,4 +14,3 @@ class ApiError extends Error {
|
|
|
17
14
|
this.request = request;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.ApiError = ApiError;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CancelablePromise = exports.CancelError = void 0;
|
|
4
|
-
class CancelError extends Error {
|
|
1
|
+
export class CancelError extends Error {
|
|
5
2
|
constructor(message) {
|
|
6
3
|
super(message);
|
|
7
4
|
this.name = 'CancelError';
|
|
@@ -10,8 +7,7 @@ class CancelError extends Error {
|
|
|
10
7
|
return true;
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
class CancelablePromise {
|
|
10
|
+
export class CancelablePromise {
|
|
15
11
|
_isResolved;
|
|
16
12
|
_isRejected;
|
|
17
13
|
_isCancelled;
|
|
@@ -97,4 +93,3 @@ class CancelablePromise {
|
|
|
97
93
|
return this._isCancelled;
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
|
-
exports.CancelablePromise = CancelablePromise;
|
package/dist/gen/core/OpenAPI.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAPI = exports.Interceptors = void 0;
|
|
4
1
|
const getEnv = (key) => {
|
|
5
2
|
return process.env[key];
|
|
6
3
|
};
|
|
7
4
|
const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000";
|
|
8
5
|
const baseUrlApi = (baseUrl ?? '') + "/api";
|
|
9
|
-
class Interceptors {
|
|
6
|
+
export class Interceptors {
|
|
10
7
|
_fns;
|
|
11
8
|
constructor() {
|
|
12
9
|
this._fns = [];
|
|
@@ -21,8 +18,7 @@ class Interceptors {
|
|
|
21
18
|
this._fns = [...this._fns, fn];
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
exports.OpenAPI = {
|
|
21
|
+
export const OpenAPI = {
|
|
26
22
|
BASE: baseUrlApi,
|
|
27
23
|
CREDENTIALS: 'include',
|
|
28
24
|
ENCODE_PATH: undefined,
|
|
@@ -30,7 +26,7 @@ exports.OpenAPI = {
|
|
|
30
26
|
PASSWORD: undefined,
|
|
31
27
|
TOKEN: getEnv("WM_TOKEN"),
|
|
32
28
|
USERNAME: undefined,
|
|
33
|
-
VERSION: '1.
|
|
29
|
+
VERSION: '1.601.1',
|
|
34
30
|
WITH_CREDENTIALS: true,
|
|
35
31
|
interceptors: {
|
|
36
32
|
request: new Interceptors(),
|
package/dist/gen/core/request.js
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ApiError_1 = require("./ApiError");
|
|
5
|
-
const CancelablePromise_1 = require("./CancelablePromise");
|
|
6
|
-
const isString = (value) => {
|
|
1
|
+
import { ApiError } from './ApiError';
|
|
2
|
+
import { CancelablePromise } from './CancelablePromise';
|
|
3
|
+
export const isString = (value) => {
|
|
7
4
|
return typeof value === 'string';
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return (0, exports.isString)(value) && value !== '';
|
|
6
|
+
export const isStringWithValue = (value) => {
|
|
7
|
+
return isString(value) && value !== '';
|
|
12
8
|
};
|
|
13
|
-
|
|
14
|
-
const isBlob = (value) => {
|
|
9
|
+
export const isBlob = (value) => {
|
|
15
10
|
return value instanceof Blob;
|
|
16
11
|
};
|
|
17
|
-
|
|
18
|
-
const isFormData = (value) => {
|
|
12
|
+
export const isFormData = (value) => {
|
|
19
13
|
return value instanceof FormData;
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
const base64 = (str) => {
|
|
15
|
+
export const base64 = (str) => {
|
|
23
16
|
try {
|
|
24
17
|
return btoa(str);
|
|
25
18
|
}
|
|
@@ -28,8 +21,7 @@ const base64 = (str) => {
|
|
|
28
21
|
return Buffer.from(str).toString('base64');
|
|
29
22
|
}
|
|
30
23
|
};
|
|
31
|
-
|
|
32
|
-
const getQueryString = (params) => {
|
|
24
|
+
export const getQueryString = (params) => {
|
|
33
25
|
const qs = [];
|
|
34
26
|
const append = (key, value) => {
|
|
35
27
|
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
@@ -54,7 +46,6 @@ const getQueryString = (params) => {
|
|
|
54
46
|
Object.entries(params).forEach(([key, value]) => encodePair(key, value));
|
|
55
47
|
return qs.length ? `?${qs.join('&')}` : '';
|
|
56
48
|
};
|
|
57
|
-
exports.getQueryString = getQueryString;
|
|
58
49
|
const getUrl = (config, options) => {
|
|
59
50
|
const encoder = config.ENCODE_PATH || encodeURI;
|
|
60
51
|
const path = options.url
|
|
@@ -66,13 +57,13 @@ const getUrl = (config, options) => {
|
|
|
66
57
|
return substring;
|
|
67
58
|
});
|
|
68
59
|
const url = config.BASE + path;
|
|
69
|
-
return options.query ? url +
|
|
60
|
+
return options.query ? url + getQueryString(options.query) : url;
|
|
70
61
|
};
|
|
71
|
-
const getFormData = (options) => {
|
|
62
|
+
export const getFormData = (options) => {
|
|
72
63
|
if (options.formData) {
|
|
73
64
|
const formData = new FormData();
|
|
74
65
|
const process = (key, value) => {
|
|
75
|
-
if (
|
|
66
|
+
if (isString(value) || isBlob(value)) {
|
|
76
67
|
formData.append(key, value);
|
|
77
68
|
}
|
|
78
69
|
else {
|
|
@@ -93,24 +84,22 @@ const getFormData = (options) => {
|
|
|
93
84
|
}
|
|
94
85
|
return undefined;
|
|
95
86
|
};
|
|
96
|
-
|
|
97
|
-
const resolve = async (options, resolver) => {
|
|
87
|
+
export const resolve = async (options, resolver) => {
|
|
98
88
|
if (typeof resolver === 'function') {
|
|
99
89
|
return resolver(options);
|
|
100
90
|
}
|
|
101
91
|
return resolver;
|
|
102
92
|
};
|
|
103
|
-
|
|
104
|
-
const getHeaders = async (config, options) => {
|
|
93
|
+
export const getHeaders = async (config, options) => {
|
|
105
94
|
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
106
95
|
// @ts-ignore
|
|
107
|
-
|
|
96
|
+
resolve(options, config.TOKEN),
|
|
108
97
|
// @ts-ignore
|
|
109
|
-
|
|
98
|
+
resolve(options, config.USERNAME),
|
|
110
99
|
// @ts-ignore
|
|
111
|
-
|
|
100
|
+
resolve(options, config.PASSWORD),
|
|
112
101
|
// @ts-ignore
|
|
113
|
-
|
|
102
|
+
resolve(options, config.HEADERS),
|
|
114
103
|
]);
|
|
115
104
|
const headers = Object.entries({
|
|
116
105
|
Accept: 'application/json',
|
|
@@ -122,36 +111,35 @@ const getHeaders = async (config, options) => {
|
|
|
122
111
|
...headers,
|
|
123
112
|
[key]: String(value),
|
|
124
113
|
}), {});
|
|
125
|
-
if (
|
|
114
|
+
if (isStringWithValue(token)) {
|
|
126
115
|
headers['Authorization'] = `Bearer ${token}`;
|
|
127
116
|
}
|
|
128
|
-
if (
|
|
129
|
-
const credentials =
|
|
117
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
118
|
+
const credentials = base64(`${username}:${password}`);
|
|
130
119
|
headers['Authorization'] = `Basic ${credentials}`;
|
|
131
120
|
}
|
|
132
121
|
if (options.body !== undefined) {
|
|
133
122
|
if (options.mediaType) {
|
|
134
123
|
headers['Content-Type'] = options.mediaType;
|
|
135
124
|
}
|
|
136
|
-
else if (
|
|
125
|
+
else if (isBlob(options.body)) {
|
|
137
126
|
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
138
127
|
}
|
|
139
|
-
else if (
|
|
128
|
+
else if (isString(options.body)) {
|
|
140
129
|
headers['Content-Type'] = 'text/plain';
|
|
141
130
|
}
|
|
142
|
-
else if (!
|
|
131
|
+
else if (!isFormData(options.body)) {
|
|
143
132
|
headers['Content-Type'] = 'application/json';
|
|
144
133
|
}
|
|
145
134
|
}
|
|
146
135
|
return new Headers(headers);
|
|
147
136
|
};
|
|
148
|
-
|
|
149
|
-
const getRequestBody = (options) => {
|
|
137
|
+
export const getRequestBody = (options) => {
|
|
150
138
|
if (options.body !== undefined) {
|
|
151
139
|
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
|
|
152
140
|
return JSON.stringify(options.body);
|
|
153
141
|
}
|
|
154
|
-
else if (
|
|
142
|
+
else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
155
143
|
return options.body;
|
|
156
144
|
}
|
|
157
145
|
else {
|
|
@@ -160,8 +148,7 @@ const getRequestBody = (options) => {
|
|
|
160
148
|
}
|
|
161
149
|
return undefined;
|
|
162
150
|
};
|
|
163
|
-
|
|
164
|
-
const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
|
|
151
|
+
export const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
|
|
165
152
|
const controller = new AbortController();
|
|
166
153
|
let request = {
|
|
167
154
|
headers,
|
|
@@ -178,18 +165,16 @@ const sendRequest = async (config, options, url, body, formData, headers, onCanc
|
|
|
178
165
|
onCancel(() => controller.abort());
|
|
179
166
|
return await fetch(url, request);
|
|
180
167
|
};
|
|
181
|
-
|
|
182
|
-
const getResponseHeader = (response, responseHeader) => {
|
|
168
|
+
export const getResponseHeader = (response, responseHeader) => {
|
|
183
169
|
if (responseHeader) {
|
|
184
170
|
const content = response.headers.get(responseHeader);
|
|
185
|
-
if (
|
|
171
|
+
if (isString(content)) {
|
|
186
172
|
return content;
|
|
187
173
|
}
|
|
188
174
|
}
|
|
189
175
|
return undefined;
|
|
190
176
|
};
|
|
191
|
-
|
|
192
|
-
const getResponseBody = async (response) => {
|
|
177
|
+
export const getResponseBody = async (response) => {
|
|
193
178
|
if (response.status !== 204) {
|
|
194
179
|
try {
|
|
195
180
|
const contentType = response.headers.get('Content-Type');
|
|
@@ -215,8 +200,7 @@ const getResponseBody = async (response) => {
|
|
|
215
200
|
}
|
|
216
201
|
return undefined;
|
|
217
202
|
};
|
|
218
|
-
|
|
219
|
-
const catchErrorCodes = (options, result) => {
|
|
203
|
+
export const catchErrorCodes = (options, result) => {
|
|
220
204
|
const errors = {
|
|
221
205
|
400: 'Bad Request',
|
|
222
206
|
401: 'Unauthorized',
|
|
@@ -262,7 +246,7 @@ const catchErrorCodes = (options, result) => {
|
|
|
262
246
|
};
|
|
263
247
|
const error = errors[result.status];
|
|
264
248
|
if (error) {
|
|
265
|
-
throw new
|
|
249
|
+
throw new ApiError(options, result, error);
|
|
266
250
|
}
|
|
267
251
|
if (!result.ok) {
|
|
268
252
|
const errorStatus = result.status ?? 'unknown';
|
|
@@ -275,10 +259,9 @@ const catchErrorCodes = (options, result) => {
|
|
|
275
259
|
return undefined;
|
|
276
260
|
}
|
|
277
261
|
})();
|
|
278
|
-
throw new
|
|
262
|
+
throw new ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
|
|
279
263
|
}
|
|
280
264
|
};
|
|
281
|
-
exports.catchErrorCodes = catchErrorCodes;
|
|
282
265
|
/**
|
|
283
266
|
* Request method
|
|
284
267
|
* @param config The OpenAPI configuration object
|
|
@@ -286,20 +269,20 @@ exports.catchErrorCodes = catchErrorCodes;
|
|
|
286
269
|
* @returns CancelablePromise<T>
|
|
287
270
|
* @throws ApiError
|
|
288
271
|
*/
|
|
289
|
-
const request = (config, options) => {
|
|
290
|
-
return new
|
|
272
|
+
export const request = (config, options) => {
|
|
273
|
+
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
291
274
|
try {
|
|
292
275
|
const url = getUrl(config, options);
|
|
293
|
-
const formData =
|
|
294
|
-
const body =
|
|
295
|
-
const headers = await
|
|
276
|
+
const formData = getFormData(options);
|
|
277
|
+
const body = getRequestBody(options);
|
|
278
|
+
const headers = await getHeaders(config, options);
|
|
296
279
|
if (!onCancel.isCancelled) {
|
|
297
|
-
let response = await
|
|
280
|
+
let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
298
281
|
for (const fn of config.interceptors.response._fns) {
|
|
299
282
|
response = await fn(response);
|
|
300
283
|
}
|
|
301
|
-
const responseBody = await
|
|
302
|
-
const responseHeader =
|
|
284
|
+
const responseBody = await getResponseBody(response);
|
|
285
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
303
286
|
let transformedBody = responseBody;
|
|
304
287
|
if (options.responseTransformer && response.ok) {
|
|
305
288
|
transformedBody = await options.responseTransformer(responseBody);
|
|
@@ -311,7 +294,7 @@ const request = (config, options) => {
|
|
|
311
294
|
statusText: response.statusText,
|
|
312
295
|
body: responseHeader ?? transformedBody,
|
|
313
296
|
};
|
|
314
|
-
|
|
297
|
+
catchErrorCodes(options, result);
|
|
315
298
|
resolve(result.body);
|
|
316
299
|
}
|
|
317
300
|
}
|
|
@@ -320,4 +303,3 @@ const request = (config, options) => {
|
|
|
320
303
|
}
|
|
321
304
|
});
|
|
322
305
|
};
|
|
323
|
-
exports.request = request;
|
package/dist/gen/index.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.OpenAPI = exports.CancelError = exports.CancelablePromise = exports.ApiError = void 0;
|
|
18
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var OpenAPI_1 = require("./core/OpenAPI");
|
|
25
|
-
Object.defineProperty(exports, "OpenAPI", { enumerable: true, get: function () { return OpenAPI_1.OpenAPI; } });
|
|
26
|
-
__exportStar(require("./services.gen"), exports);
|
|
27
|
-
__exportStar(require("./types.gen"), exports);
|
|
2
|
+
export { ApiError } from './core/ApiError';
|
|
3
|
+
export { CancelablePromise, CancelError } from './core/CancelablePromise';
|
|
4
|
+
export { OpenAPI } from './core/OpenAPI';
|
|
5
|
+
export * from './services.gen';
|
|
6
|
+
export * from './types.gen';
|