windmill-utils-internal 1.3.2 → 1.3.4
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/cjs/config/config.js +231 -0
- package/dist/cjs/config/index.js +17 -0
- package/dist/cjs/constants.js +44 -0
- package/dist/cjs/gen/core/ApiError.js +20 -0
- package/dist/cjs/gen/core/ApiRequestOptions.js +2 -0
- package/dist/cjs/gen/core/ApiResult.js +2 -0
- package/dist/cjs/gen/core/CancelablePromise.js +100 -0
- package/dist/cjs/gen/core/OpenAPI.js +39 -0
- package/dist/cjs/gen/core/request.js +323 -0
- package/dist/cjs/gen/index.js +27 -0
- package/dist/{gen → cjs/gen}/services.gen.d.ts +362 -52
- package/dist/cjs/gen/services.gen.js +13121 -0
- package/dist/{gen → cjs/gen}/types.gen.d.ts +1882 -172
- package/dist/cjs/gen/types.gen.js +3 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/inline-scripts/extractor.js +112 -0
- package/dist/cjs/inline-scripts/index.js +18 -0
- package/dist/cjs/inline-scripts/replacer.js +88 -0
- package/dist/cjs/parse/index.js +17 -0
- package/dist/cjs/parse/parse-schema.js +257 -0
- package/dist/cjs/path-utils/index.js +17 -0
- package/dist/cjs/path-utils/path-assigner.js +166 -0
- package/dist/esm/config/config.d.ts +11 -0
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/constants.d.ts +16 -0
- package/dist/esm/gen/core/ApiError.d.ts +10 -0
- package/dist/esm/gen/core/ApiRequestOptions.d.ts +14 -0
- package/dist/esm/gen/core/ApiResult.d.ts +7 -0
- package/dist/esm/gen/core/CancelablePromise.d.ts +26 -0
- package/dist/esm/gen/core/OpenAPI.d.ts +27 -0
- package/dist/{gen → esm/gen}/core/OpenAPI.js +1 -1
- package/dist/esm/gen/core/request.d.ts +29 -0
- package/dist/esm/gen/index.d.ts +5 -0
- package/dist/esm/gen/services.gen.d.ts +6126 -0
- package/dist/{gen → esm/gen}/services.gen.js +744 -131
- package/dist/esm/gen/types.gen.d.ts +11636 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/inline-scripts/extractor.d.ts +41 -0
- package/dist/{inline-scripts → esm/inline-scripts}/extractor.js +34 -12
- package/dist/esm/inline-scripts/index.js +2 -0
- package/dist/esm/inline-scripts/replacer.d.ts +16 -0
- package/dist/esm/inline-scripts/replacer.js +85 -0
- package/dist/esm/parse/index.js +1 -0
- package/dist/esm/parse/parse-schema.d.ts +98 -0
- package/dist/{parse → esm/parse}/parse-schema.js +4 -0
- package/dist/esm/path-utils/index.js +1 -0
- package/dist/esm/path-utils/path-assigner.d.ts +58 -0
- package/dist/{path-utils → esm/path-utils}/path-assigner.js +2 -0
- package/package.json +14 -4
- package/dist/inline-scripts/replacer.js +0 -93
- /package/dist/{config → cjs/config}/config.d.ts +0 -0
- /package/dist/{config → cjs/config}/index.d.ts +0 -0
- /package/dist/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/dist/{gen → cjs/gen}/core/ApiError.d.ts +0 -0
- /package/dist/{gen → cjs/gen}/core/ApiRequestOptions.d.ts +0 -0
- /package/dist/{gen → cjs/gen}/core/ApiResult.d.ts +0 -0
- /package/dist/{gen → cjs/gen}/core/CancelablePromise.d.ts +0 -0
- /package/dist/{gen → cjs/gen}/core/OpenAPI.d.ts +0 -0
- /package/dist/{gen → cjs/gen}/core/request.d.ts +0 -0
- /package/dist/{gen → cjs/gen}/index.d.ts +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{inline-scripts → cjs/inline-scripts}/extractor.d.ts +0 -0
- /package/dist/{inline-scripts → cjs/inline-scripts}/index.d.ts +0 -0
- /package/dist/{inline-scripts → cjs/inline-scripts}/replacer.d.ts +0 -0
- /package/dist/{parse → cjs/parse}/index.d.ts +0 -0
- /package/dist/{parse → cjs/parse}/parse-schema.d.ts +0 -0
- /package/dist/{path-utils → cjs/path-utils}/index.d.ts +0 -0
- /package/dist/{path-utils → cjs/path-utils}/path-assigner.d.ts +0 -0
- /package/dist/{config → esm/config}/config.js +0 -0
- /package/dist/{config/index.js → esm/config/index.d.ts} +0 -0
- /package/dist/{constants.js → esm/constants.js} +0 -0
- /package/dist/{gen → esm/gen}/core/ApiError.js +0 -0
- /package/dist/{gen → esm/gen}/core/ApiRequestOptions.js +0 -0
- /package/dist/{gen → esm/gen}/core/ApiResult.js +0 -0
- /package/dist/{gen → esm/gen}/core/CancelablePromise.js +0 -0
- /package/dist/{gen → esm/gen}/core/request.js +0 -0
- /package/dist/{gen → esm/gen}/index.js +0 -0
- /package/dist/{gen → esm/gen}/types.gen.js +0 -0
- /package/dist/{index.js → esm/index.d.ts} +0 -0
- /package/dist/{inline-scripts/index.js → esm/inline-scripts/index.d.ts} +0 -0
- /package/dist/{parse/index.js → esm/parse/index.d.ts} +0 -0
- /package/dist/{path-utils/index.js → esm/path-utils/index.d.ts} +0 -0
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
// Runtime detection
|
|
44
|
+
// @ts-ignore - Cross-platform runtime detection
|
|
45
|
+
const isDeno = typeof Deno !== "undefined";
|
|
46
|
+
// @ts-ignore - Cross-platform runtime detection
|
|
47
|
+
const isNode = typeof process !== "undefined" && process.versions?.node;
|
|
48
|
+
exports.WINDMILL_CONFIG_DIR = "windmill";
|
|
49
|
+
exports.WINDMILL_ACTIVE_WORKSPACE_FILE = "activeWorkspace";
|
|
50
|
+
exports.WINDMILL_WORKSPACE_CONFIG_FILE = "remotes.ndjson";
|
|
51
|
+
exports.INSTANCES_CONFIG_FILE = "instances.ndjson";
|
|
52
|
+
exports.WINDMILL_ACTIVE_INSTANCE_FILE = "activeInstance";
|
|
53
|
+
// Cross-platform environment variable access
|
|
54
|
+
function getEnv(key) {
|
|
55
|
+
if (isDeno) {
|
|
56
|
+
// @ts-ignore - Deno API
|
|
57
|
+
return Deno.env.get(key);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// @ts-ignore - Node API
|
|
61
|
+
return process.env[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Cross-platform OS detection with normalization
|
|
65
|
+
function getOS() {
|
|
66
|
+
if (isDeno) {
|
|
67
|
+
// @ts-ignore - Deno API
|
|
68
|
+
return Deno.build.os;
|
|
69
|
+
}
|
|
70
|
+
else if (isNode) {
|
|
71
|
+
// @ts-ignore - Node API
|
|
72
|
+
const platform = process.platform;
|
|
73
|
+
switch (platform) {
|
|
74
|
+
case "linux": return "linux";
|
|
75
|
+
case "darwin": return "darwin";
|
|
76
|
+
case "win32": return "windows"; // Normalize win32 to windows
|
|
77
|
+
default: return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
// Cross-platform file system operations
|
|
83
|
+
async function stat(path) {
|
|
84
|
+
if (isDeno) {
|
|
85
|
+
// @ts-ignore - Deno API
|
|
86
|
+
return await Deno.stat(path);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// @ts-ignore - Node API
|
|
90
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
91
|
+
return await fs.stat(path);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function mkdir(path, options) {
|
|
95
|
+
if (isDeno) {
|
|
96
|
+
// @ts-ignore - Deno API
|
|
97
|
+
await Deno.mkdir(path, options);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// @ts-ignore - Node API
|
|
101
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
102
|
+
await fs.mkdir(path, options);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function throwIfNotDirectory(fileInfo) {
|
|
106
|
+
if (!fileInfo.isDirectory) {
|
|
107
|
+
throw new Error("Path is not a directory");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function config_dir() {
|
|
111
|
+
const os = getOS();
|
|
112
|
+
switch (os) {
|
|
113
|
+
case "linux": {
|
|
114
|
+
const xdg = getEnv("XDG_CONFIG_HOME");
|
|
115
|
+
if (xdg)
|
|
116
|
+
return xdg;
|
|
117
|
+
const home = getEnv("HOME");
|
|
118
|
+
if (home)
|
|
119
|
+
return `${home}/.config`;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "darwin": {
|
|
123
|
+
const home = getEnv("HOME");
|
|
124
|
+
if (home)
|
|
125
|
+
return `${home}/Library/Preferences`;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "windows":
|
|
129
|
+
return getEnv("APPDATA") ?? null;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
function tmp_dir() {
|
|
134
|
+
const os = getOS();
|
|
135
|
+
switch (os) {
|
|
136
|
+
case "linux": {
|
|
137
|
+
const xdg = getEnv("XDG_RUNTIME_DIR");
|
|
138
|
+
if (xdg)
|
|
139
|
+
return `${xdg}-/tmp`;
|
|
140
|
+
const tmpDir = getEnv("TMPDIR");
|
|
141
|
+
if (tmpDir)
|
|
142
|
+
return tmpDir;
|
|
143
|
+
const tempDir = getEnv("TEMP");
|
|
144
|
+
if (tempDir)
|
|
145
|
+
return tempDir;
|
|
146
|
+
const tmp = getEnv("TMP");
|
|
147
|
+
if (tmp)
|
|
148
|
+
return tmp;
|
|
149
|
+
return "/var/tmp";
|
|
150
|
+
}
|
|
151
|
+
case "darwin":
|
|
152
|
+
return getEnv("TMPDIR") ?? null;
|
|
153
|
+
case "windows":
|
|
154
|
+
return getEnv("TMP") ?? getEnv("TEMP") ?? null;
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
async function ensureDir(dir) {
|
|
159
|
+
try {
|
|
160
|
+
const fileInfo = await stat(dir);
|
|
161
|
+
throwIfNotDirectory(fileInfo);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
// Check for file not found error in cross-platform way
|
|
166
|
+
if (isDeno) {
|
|
167
|
+
// @ts-ignore - Deno API
|
|
168
|
+
if (!(err instanceof Deno.errors.NotFound)) {
|
|
169
|
+
throw err;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Node.js error codes
|
|
174
|
+
if (err.code !== 'ENOENT') {
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// The dir doesn't exist. Create it.
|
|
180
|
+
// This can be racy. So we catch AlreadyExists and check stat again.
|
|
181
|
+
try {
|
|
182
|
+
await mkdir(dir, { recursive: true });
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
// Check for already exists error in cross-platform way
|
|
186
|
+
if (isDeno) {
|
|
187
|
+
// @ts-ignore - Deno API
|
|
188
|
+
if (!(err instanceof Deno.errors.AlreadyExists)) {
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Node.js error codes
|
|
194
|
+
if (err.code !== 'EEXIST') {
|
|
195
|
+
throw err;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const fileInfo = await stat(dir);
|
|
199
|
+
throwIfNotDirectory(fileInfo);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function getBaseConfigDir(configDirOverride) {
|
|
203
|
+
const baseDir = configDirOverride ??
|
|
204
|
+
getEnv("WMILL_CONFIG_DIR") ??
|
|
205
|
+
config_dir() ??
|
|
206
|
+
tmp_dir() ??
|
|
207
|
+
"/tmp/";
|
|
208
|
+
return baseDir;
|
|
209
|
+
}
|
|
210
|
+
async function getConfigDirPath(configDirOverride) {
|
|
211
|
+
const baseDir = await getBaseConfigDir(configDirOverride);
|
|
212
|
+
const store = baseDir + `/${exports.WINDMILL_CONFIG_DIR}/`;
|
|
213
|
+
await ensureDir(store);
|
|
214
|
+
return store;
|
|
215
|
+
}
|
|
216
|
+
async function getWorkspaceConfigFilePath(configDirOverride) {
|
|
217
|
+
const configDir = await getConfigDirPath(configDirOverride);
|
|
218
|
+
return `${configDir}/${exports.WINDMILL_WORKSPACE_CONFIG_FILE}`;
|
|
219
|
+
}
|
|
220
|
+
async function getActiveWorkspaceConfigFilePath(configDirOverride) {
|
|
221
|
+
const configDir = await getConfigDirPath(configDirOverride);
|
|
222
|
+
return `${configDir}/${exports.WINDMILL_ACTIVE_WORKSPACE_FILE}`;
|
|
223
|
+
}
|
|
224
|
+
async function getInstancesConfigFilePath(configDirOverride) {
|
|
225
|
+
const configDir = await getConfigDirPath(configDirOverride);
|
|
226
|
+
return `${configDir}/${exports.INSTANCES_CONFIG_FILE}`;
|
|
227
|
+
}
|
|
228
|
+
async function getActiveInstanceFilePath(configDirOverride) {
|
|
229
|
+
const configDir = await getConfigDirPath(configDirOverride);
|
|
230
|
+
return `${configDir}/${exports.WINDMILL_ACTIVE_INSTANCE_FILE}`;
|
|
231
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./config"), exports);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// constants.ts
|
|
3
|
+
/**
|
|
4
|
+
* Cross-platform path separator constants
|
|
5
|
+
* Compatible with both Node.js and Deno environments
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DELIMITER = exports.SEP = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Detects if the current platform is Windows by checking various environment indicators.
|
|
11
|
+
* Uses multiple fallback methods to ensure compatibility across Node.js, Deno, and browser environments.
|
|
12
|
+
*
|
|
13
|
+
* @returns True if running on Windows, false otherwise
|
|
14
|
+
*/
|
|
15
|
+
const isWindows = (() => {
|
|
16
|
+
// Try Node.js process.platform first (most reliable)
|
|
17
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
18
|
+
return process.platform === "win32";
|
|
19
|
+
}
|
|
20
|
+
// Try Deno specific detection via globalThis
|
|
21
|
+
if (typeof globalThis !== "undefined" && "Deno" in globalThis) {
|
|
22
|
+
return globalThis.Deno?.build?.os === "windows";
|
|
23
|
+
}
|
|
24
|
+
// Try navigator.platform (browser/some Deno contexts)
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return navigator.platform.toLowerCase().includes("win");
|
|
29
|
+
}
|
|
30
|
+
// Fallback - assume Unix-like (safest default)
|
|
31
|
+
return false;
|
|
32
|
+
})();
|
|
33
|
+
/**
|
|
34
|
+
* Path separator constant - equivalent to Deno's SEPARATOR or Node's path.sep
|
|
35
|
+
* On Windows: "\"
|
|
36
|
+
* On Unix-like systems: "/"
|
|
37
|
+
*/
|
|
38
|
+
exports.SEP = isWindows ? "\\" : "/";
|
|
39
|
+
/**
|
|
40
|
+
* Path delimiter constant for environment variables like PATH
|
|
41
|
+
* On Windows: ";"
|
|
42
|
+
* On Unix-like systems: ":"
|
|
43
|
+
*/
|
|
44
|
+
exports.DELIMITER = isWindows ? ";" : ":";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiError = void 0;
|
|
4
|
+
class ApiError extends Error {
|
|
5
|
+
url;
|
|
6
|
+
status;
|
|
7
|
+
statusText;
|
|
8
|
+
body;
|
|
9
|
+
request;
|
|
10
|
+
constructor(request, response, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'ApiError';
|
|
13
|
+
this.url = response.url;
|
|
14
|
+
this.status = response.status;
|
|
15
|
+
this.statusText = response.statusText;
|
|
16
|
+
this.body = response.body;
|
|
17
|
+
this.request = request;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ApiError = ApiError;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CancelablePromise = exports.CancelError = void 0;
|
|
4
|
+
class CancelError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'CancelError';
|
|
8
|
+
}
|
|
9
|
+
get isCancelled() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.CancelError = CancelError;
|
|
14
|
+
class CancelablePromise {
|
|
15
|
+
_isResolved;
|
|
16
|
+
_isRejected;
|
|
17
|
+
_isCancelled;
|
|
18
|
+
cancelHandlers;
|
|
19
|
+
promise;
|
|
20
|
+
_resolve;
|
|
21
|
+
_reject;
|
|
22
|
+
constructor(executor) {
|
|
23
|
+
this._isResolved = false;
|
|
24
|
+
this._isRejected = false;
|
|
25
|
+
this._isCancelled = false;
|
|
26
|
+
this.cancelHandlers = [];
|
|
27
|
+
this.promise = new Promise((resolve, reject) => {
|
|
28
|
+
this._resolve = resolve;
|
|
29
|
+
this._reject = reject;
|
|
30
|
+
const onResolve = (value) => {
|
|
31
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this._isResolved = true;
|
|
35
|
+
if (this._resolve)
|
|
36
|
+
this._resolve(value);
|
|
37
|
+
};
|
|
38
|
+
const onReject = (reason) => {
|
|
39
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this._isRejected = true;
|
|
43
|
+
if (this._reject)
|
|
44
|
+
this._reject(reason);
|
|
45
|
+
};
|
|
46
|
+
const onCancel = (cancelHandler) => {
|
|
47
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.cancelHandlers.push(cancelHandler);
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(onCancel, 'isResolved', {
|
|
53
|
+
get: () => this._isResolved,
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(onCancel, 'isRejected', {
|
|
56
|
+
get: () => this._isRejected,
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(onCancel, 'isCancelled', {
|
|
59
|
+
get: () => this._isCancelled,
|
|
60
|
+
});
|
|
61
|
+
return executor(onResolve, onReject, onCancel);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
get [Symbol.toStringTag]() {
|
|
65
|
+
return "Cancellable Promise";
|
|
66
|
+
}
|
|
67
|
+
then(onFulfilled, onRejected) {
|
|
68
|
+
return this.promise.then(onFulfilled, onRejected);
|
|
69
|
+
}
|
|
70
|
+
catch(onRejected) {
|
|
71
|
+
return this.promise.catch(onRejected);
|
|
72
|
+
}
|
|
73
|
+
finally(onFinally) {
|
|
74
|
+
return this.promise.finally(onFinally);
|
|
75
|
+
}
|
|
76
|
+
cancel() {
|
|
77
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._isCancelled = true;
|
|
81
|
+
if (this.cancelHandlers.length) {
|
|
82
|
+
try {
|
|
83
|
+
for (const cancelHandler of this.cancelHandlers) {
|
|
84
|
+
cancelHandler();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.warn('Cancellation threw an error', error);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.cancelHandlers.length = 0;
|
|
93
|
+
if (this._reject)
|
|
94
|
+
this._reject(new CancelError('Request aborted'));
|
|
95
|
+
}
|
|
96
|
+
get isCancelled() {
|
|
97
|
+
return this._isCancelled;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CancelablePromise = CancelablePromise;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAPI = exports.Interceptors = void 0;
|
|
4
|
+
const getEnv = (key) => {
|
|
5
|
+
return process.env[key];
|
|
6
|
+
};
|
|
7
|
+
const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000";
|
|
8
|
+
const baseUrlApi = (baseUrl ?? '') + "/api";
|
|
9
|
+
class Interceptors {
|
|
10
|
+
_fns;
|
|
11
|
+
constructor() {
|
|
12
|
+
this._fns = [];
|
|
13
|
+
}
|
|
14
|
+
eject(fn) {
|
|
15
|
+
const index = this._fns.indexOf(fn);
|
|
16
|
+
if (index !== -1) {
|
|
17
|
+
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
use(fn) {
|
|
21
|
+
this._fns = [...this._fns, fn];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Interceptors = Interceptors;
|
|
25
|
+
exports.OpenAPI = {
|
|
26
|
+
BASE: baseUrlApi,
|
|
27
|
+
CREDENTIALS: 'include',
|
|
28
|
+
ENCODE_PATH: undefined,
|
|
29
|
+
HEADERS: undefined,
|
|
30
|
+
PASSWORD: undefined,
|
|
31
|
+
TOKEN: getEnv("WM_TOKEN"),
|
|
32
|
+
USERNAME: undefined,
|
|
33
|
+
VERSION: '1.628.3',
|
|
34
|
+
WITH_CREDENTIALS: true,
|
|
35
|
+
interceptors: {
|
|
36
|
+
request: new Interceptors(),
|
|
37
|
+
response: new Interceptors(),
|
|
38
|
+
},
|
|
39
|
+
};
|