windmill-cli 1.396.1 → 1.397.3

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.
Files changed (89) hide show
  1. package/esm/apps.js +6 -5
  2. package/esm/bootstrap/script_bootstrap.js +18 -0
  3. package/esm/context.js +4 -3
  4. package/esm/deps.js +19 -2
  5. package/esm/flow.js +9 -8
  6. package/esm/folder.js +6 -5
  7. package/esm/gen/core/ApiError.js +41 -0
  8. package/esm/gen/core/ApiRequestOptions.js +1 -0
  9. package/esm/gen/core/ApiResult.js +1 -0
  10. package/esm/gen/core/CancelablePromise.js +130 -0
  11. package/esm/gen/core/OpenAPI.js +41 -0
  12. package/esm/gen/core/request.js +305 -0
  13. package/esm/gen/index.js +6 -0
  14. package/esm/gen/services.gen.js +6782 -0
  15. package/esm/gen/types.gen.js +2 -0
  16. package/esm/hub.js +5 -4
  17. package/esm/instance.js +5 -4
  18. package/esm/main.js +5 -3
  19. package/esm/metadata.js +1 -1
  20. package/esm/resource-type.js +6 -5
  21. package/esm/resource.js +11 -5
  22. package/esm/schedule.js +6 -5
  23. package/esm/script.js +42 -10
  24. package/esm/script_common.js +6 -0
  25. package/esm/settings.js +28 -27
  26. package/esm/sync.js +89 -23
  27. package/esm/types.js +9 -3
  28. package/esm/user.js +27 -27
  29. package/esm/utils.js +7 -0
  30. package/esm/variable.js +7 -6
  31. package/esm/workspace.js +7 -6
  32. package/package.json +1 -2
  33. package/types/apps.d.ts +2 -1
  34. package/types/apps.d.ts.map +1 -1
  35. package/types/bootstrap/script_bootstrap.d.ts +2 -0
  36. package/types/bootstrap/script_bootstrap.d.ts.map +1 -1
  37. package/types/context.d.ts +1 -1
  38. package/types/context.d.ts.map +1 -1
  39. package/types/deps.d.ts +1 -1
  40. package/types/deps.d.ts.map +1 -1
  41. package/types/flow.d.ts +2 -1
  42. package/types/flow.d.ts.map +1 -1
  43. package/types/folder.d.ts +5 -2
  44. package/types/folder.d.ts.map +1 -1
  45. package/types/gen/core/ApiError.d.ts +11 -0
  46. package/types/gen/core/ApiError.d.ts.map +1 -0
  47. package/types/gen/core/ApiRequestOptions.d.ts +15 -0
  48. package/types/gen/core/ApiRequestOptions.d.ts.map +1 -0
  49. package/types/gen/core/ApiResult.d.ts +8 -0
  50. package/types/gen/core/ApiResult.d.ts.map +1 -0
  51. package/types/gen/core/CancelablePromise.d.ts +27 -0
  52. package/types/gen/core/CancelablePromise.d.ts.map +1 -0
  53. package/types/gen/core/OpenAPI.d.ts +28 -0
  54. package/types/gen/core/OpenAPI.d.ts.map +1 -0
  55. package/types/gen/core/request.d.ts +30 -0
  56. package/types/gen/core/request.d.ts.map +1 -0
  57. package/types/gen/index.d.ts +6 -0
  58. package/types/gen/index.d.ts.map +1 -0
  59. package/types/gen/services.gen.d.ts +3339 -0
  60. package/types/gen/services.gen.d.ts.map +1 -0
  61. package/types/gen/types.gen.d.ts +4831 -0
  62. package/types/gen/types.gen.d.ts.map +1 -0
  63. package/types/hub.d.ts.map +1 -1
  64. package/types/instance.d.ts.map +1 -1
  65. package/types/main.d.ts +1 -1
  66. package/types/main.d.ts.map +1 -1
  67. package/types/metadata.d.ts +1 -1
  68. package/types/metadata.d.ts.map +1 -1
  69. package/types/resource-type.d.ts +2 -1
  70. package/types/resource-type.d.ts.map +1 -1
  71. package/types/resource.d.ts +2 -1
  72. package/types/resource.d.ts.map +1 -1
  73. package/types/schedule.d.ts +2 -1
  74. package/types/schedule.d.ts.map +1 -1
  75. package/types/script.d.ts +1 -0
  76. package/types/script.d.ts.map +1 -1
  77. package/types/script_common.d.ts +1 -1
  78. package/types/script_common.d.ts.map +1 -1
  79. package/types/settings.d.ts.map +1 -1
  80. package/types/sync.d.ts +2 -1
  81. package/types/sync.d.ts.map +1 -1
  82. package/types/types.d.ts +1 -1
  83. package/types/types.d.ts.map +1 -1
  84. package/types/user.d.ts.map +1 -1
  85. package/types/utils.d.ts +1 -0
  86. package/types/utils.d.ts.map +1 -1
  87. package/types/variable.d.ts +2 -1
  88. package/types/variable.d.ts.map +1 -1
  89. package/types/workspace.d.ts.map +1 -1
@@ -0,0 +1,305 @@
1
+ import { ApiError } from './ApiError.js';
2
+ import { CancelablePromise } from './CancelablePromise.js';
3
+ export const isString = (value) => {
4
+ return typeof value === 'string';
5
+ };
6
+ export const isStringWithValue = (value) => {
7
+ return isString(value) && value !== '';
8
+ };
9
+ export const isBlob = (value) => {
10
+ return value instanceof Blob;
11
+ };
12
+ export const isFormData = (value) => {
13
+ return value instanceof FormData;
14
+ };
15
+ export const base64 = (str) => {
16
+ try {
17
+ return btoa(str);
18
+ }
19
+ catch (err) {
20
+ // @ts-ignore
21
+ return Buffer.from(str).toString('base64');
22
+ }
23
+ };
24
+ export const getQueryString = (params) => {
25
+ const qs = [];
26
+ const append = (key, value) => {
27
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
28
+ };
29
+ const encodePair = (key, value) => {
30
+ if (value === undefined || value === null) {
31
+ return;
32
+ }
33
+ if (value instanceof Date) {
34
+ append(key, value.toISOString());
35
+ }
36
+ else if (Array.isArray(value)) {
37
+ value.forEach(v => encodePair(key, v));
38
+ }
39
+ else if (typeof value === 'object') {
40
+ Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v));
41
+ }
42
+ else {
43
+ append(key, value);
44
+ }
45
+ };
46
+ Object.entries(params).forEach(([key, value]) => encodePair(key, value));
47
+ return qs.length ? `?${qs.join('&')}` : '';
48
+ };
49
+ const getUrl = (config, options) => {
50
+ const encoder = config.ENCODE_PATH || encodeURI;
51
+ const path = options.url
52
+ .replace('{api-version}', config.VERSION)
53
+ .replace(/{(.*?)}/g, (substring, group) => {
54
+ if (options.path?.hasOwnProperty(group)) {
55
+ return encoder(String(options.path[group]));
56
+ }
57
+ return substring;
58
+ });
59
+ const url = config.BASE + path;
60
+ return options.query ? url + getQueryString(options.query) : url;
61
+ };
62
+ export const getFormData = (options) => {
63
+ if (options.formData) {
64
+ const formData = new FormData();
65
+ const process = (key, value) => {
66
+ if (isString(value) || isBlob(value)) {
67
+ formData.append(key, value);
68
+ }
69
+ else {
70
+ formData.append(key, JSON.stringify(value));
71
+ }
72
+ };
73
+ Object.entries(options.formData)
74
+ .filter(([, value]) => value !== undefined && value !== null)
75
+ .forEach(([key, value]) => {
76
+ if (Array.isArray(value)) {
77
+ value.forEach(v => process(key, v));
78
+ }
79
+ else {
80
+ process(key, value);
81
+ }
82
+ });
83
+ return formData;
84
+ }
85
+ return undefined;
86
+ };
87
+ export const resolve = async (options, resolver) => {
88
+ if (typeof resolver === 'function') {
89
+ return resolver(options);
90
+ }
91
+ return resolver;
92
+ };
93
+ export const getHeaders = async (config, options) => {
94
+ const [token, username, password, additionalHeaders] = await Promise.all([
95
+ // @ts-ignore
96
+ resolve(options, config.TOKEN),
97
+ // @ts-ignore
98
+ resolve(options, config.USERNAME),
99
+ // @ts-ignore
100
+ resolve(options, config.PASSWORD),
101
+ // @ts-ignore
102
+ resolve(options, config.HEADERS),
103
+ ]);
104
+ const headers = Object.entries({
105
+ Accept: 'application/json',
106
+ ...additionalHeaders,
107
+ ...options.headers,
108
+ })
109
+ .filter(([, value]) => value !== undefined && value !== null)
110
+ .reduce((headers, [key, value]) => ({
111
+ ...headers,
112
+ [key]: String(value),
113
+ }), {});
114
+ if (isStringWithValue(token)) {
115
+ headers['Authorization'] = `Bearer ${token}`;
116
+ }
117
+ if (isStringWithValue(username) && isStringWithValue(password)) {
118
+ const credentials = base64(`${username}:${password}`);
119
+ headers['Authorization'] = `Basic ${credentials}`;
120
+ }
121
+ if (options.body !== undefined) {
122
+ if (options.mediaType) {
123
+ headers['Content-Type'] = options.mediaType;
124
+ }
125
+ else if (isBlob(options.body)) {
126
+ headers['Content-Type'] = options.body.type || 'application/octet-stream';
127
+ }
128
+ else if (isString(options.body)) {
129
+ headers['Content-Type'] = 'text/plain';
130
+ }
131
+ else if (!isFormData(options.body)) {
132
+ headers['Content-Type'] = 'application/json';
133
+ }
134
+ }
135
+ return new Headers(headers);
136
+ };
137
+ export const getRequestBody = (options) => {
138
+ if (options.body !== undefined) {
139
+ if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
140
+ return JSON.stringify(options.body);
141
+ }
142
+ else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
143
+ return options.body;
144
+ }
145
+ else {
146
+ return JSON.stringify(options.body);
147
+ }
148
+ }
149
+ return undefined;
150
+ };
151
+ export const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
152
+ const controller = new AbortController();
153
+ let request = {
154
+ headers,
155
+ body: body ?? formData,
156
+ method: options.method,
157
+ signal: controller.signal,
158
+ };
159
+ if (config.WITH_CREDENTIALS) {
160
+ request.credentials = config.CREDENTIALS;
161
+ }
162
+ for (const fn of config.interceptors.request._fns) {
163
+ request = await fn(request);
164
+ }
165
+ onCancel(() => controller.abort());
166
+ return await fetch(url, request);
167
+ };
168
+ export const getResponseHeader = (response, responseHeader) => {
169
+ if (responseHeader) {
170
+ const content = response.headers.get(responseHeader);
171
+ if (isString(content)) {
172
+ return content;
173
+ }
174
+ }
175
+ return undefined;
176
+ };
177
+ export const getResponseBody = async (response) => {
178
+ if (response.status !== 204) {
179
+ try {
180
+ const contentType = response.headers.get('Content-Type');
181
+ if (contentType) {
182
+ const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/'];
183
+ if (contentType.includes('application/json') || contentType.includes('+json')) {
184
+ return await response.json();
185
+ }
186
+ else if (binaryTypes.some(type => contentType.includes(type))) {
187
+ return await response.blob();
188
+ }
189
+ else if (contentType.includes('multipart/form-data')) {
190
+ return await response.formData();
191
+ }
192
+ else if (contentType.includes('text/')) {
193
+ return await response.text();
194
+ }
195
+ }
196
+ }
197
+ catch (error) {
198
+ console.error(error);
199
+ }
200
+ }
201
+ return undefined;
202
+ };
203
+ export const catchErrorCodes = (options, result) => {
204
+ const errors = {
205
+ 400: 'Bad Request',
206
+ 401: 'Unauthorized',
207
+ 402: 'Payment Required',
208
+ 403: 'Forbidden',
209
+ 404: 'Not Found',
210
+ 405: 'Method Not Allowed',
211
+ 406: 'Not Acceptable',
212
+ 407: 'Proxy Authentication Required',
213
+ 408: 'Request Timeout',
214
+ 409: 'Conflict',
215
+ 410: 'Gone',
216
+ 411: 'Length Required',
217
+ 412: 'Precondition Failed',
218
+ 413: 'Payload Too Large',
219
+ 414: 'URI Too Long',
220
+ 415: 'Unsupported Media Type',
221
+ 416: 'Range Not Satisfiable',
222
+ 417: 'Expectation Failed',
223
+ 418: 'Im a teapot',
224
+ 421: 'Misdirected Request',
225
+ 422: 'Unprocessable Content',
226
+ 423: 'Locked',
227
+ 424: 'Failed Dependency',
228
+ 425: 'Too Early',
229
+ 426: 'Upgrade Required',
230
+ 428: 'Precondition Required',
231
+ 429: 'Too Many Requests',
232
+ 431: 'Request Header Fields Too Large',
233
+ 451: 'Unavailable For Legal Reasons',
234
+ 500: 'Internal Server Error',
235
+ 501: 'Not Implemented',
236
+ 502: 'Bad Gateway',
237
+ 503: 'Service Unavailable',
238
+ 504: 'Gateway Timeout',
239
+ 505: 'HTTP Version Not Supported',
240
+ 506: 'Variant Also Negotiates',
241
+ 507: 'Insufficient Storage',
242
+ 508: 'Loop Detected',
243
+ 510: 'Not Extended',
244
+ 511: 'Network Authentication Required',
245
+ ...options.errors,
246
+ };
247
+ const error = errors[result.status];
248
+ if (error) {
249
+ throw new ApiError(options, result, error);
250
+ }
251
+ if (!result.ok) {
252
+ const errorStatus = result.status ?? 'unknown';
253
+ const errorStatusText = result.statusText ?? 'unknown';
254
+ const errorBody = (() => {
255
+ try {
256
+ return JSON.stringify(result.body, null, 2);
257
+ }
258
+ catch (e) {
259
+ return undefined;
260
+ }
261
+ })();
262
+ throw new ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
263
+ }
264
+ };
265
+ /**
266
+ * Request method
267
+ * @param config The OpenAPI configuration object
268
+ * @param options The request options from the service
269
+ * @returns CancelablePromise<T>
270
+ * @throws ApiError
271
+ */
272
+ export const request = (config, options) => {
273
+ return new CancelablePromise(async (resolve, reject, onCancel) => {
274
+ try {
275
+ const url = getUrl(config, options);
276
+ const formData = getFormData(options);
277
+ const body = getRequestBody(options);
278
+ const headers = await getHeaders(config, options);
279
+ if (!onCancel.isCancelled) {
280
+ let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
281
+ for (const fn of config.interceptors.response._fns) {
282
+ response = await fn(response);
283
+ }
284
+ const responseBody = await getResponseBody(response);
285
+ const responseHeader = getResponseHeader(response, options.responseHeader);
286
+ let transformedBody = responseBody;
287
+ if (options.responseTransformer && response.ok) {
288
+ transformedBody = await options.responseTransformer(responseBody);
289
+ }
290
+ const result = {
291
+ url,
292
+ ok: response.ok,
293
+ status: response.status,
294
+ statusText: response.statusText,
295
+ body: responseHeader ?? transformedBody,
296
+ };
297
+ catchErrorCodes(options, result);
298
+ resolve(result.body);
299
+ }
300
+ }
301
+ catch (error) {
302
+ reject(error);
303
+ }
304
+ });
305
+ };
@@ -0,0 +1,6 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export { ApiError } from './core/ApiError.js';
3
+ export { CancelablePromise, CancelError } from './core/CancelablePromise.js';
4
+ export { OpenAPI } from './core/OpenAPI.js';
5
+ export * from './services.gen.js';
6
+ export * from './types.gen.js';