@shapediver/sdk.geometry-api-sdk-v2 3.6.0 → 4.0.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/README.md +5 -5
- package/dist/UtilsApi.d.ts +16 -29
- package/dist/UtilsApi.d.ts.map +1 -1
- package/dist/UtilsApi.js +133 -135
- package/dist/UtilsApi.js.map +1 -1
- package/dist/base.d.ts +2 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +30 -36
- package/dist/base.js.map +1 -1
- package/dist/client/apis/AnalyticsApi.d.ts +38 -0
- package/dist/client/apis/AnalyticsApi.d.ts.map +1 -0
- package/dist/client/apis/AnalyticsApi.js +245 -0
- package/dist/client/apis/AnalyticsApi.js.map +1 -0
- package/dist/client/apis/ArSceneApi.d.ts +23 -0
- package/dist/client/apis/ArSceneApi.d.ts.map +1 -0
- package/dist/client/apis/ArSceneApi.js +140 -0
- package/dist/client/apis/ArSceneApi.js.map +1 -0
- package/dist/client/apis/AssetsApi.d.ts +54 -0
- package/dist/client/apis/AssetsApi.d.ts.map +1 -0
- package/dist/client/apis/AssetsApi.js +329 -0
- package/dist/client/apis/AssetsApi.js.map +1 -0
- package/dist/client/apis/AuthApi.d.ts +8 -0
- package/dist/client/apis/AuthApi.d.ts.map +1 -0
- package/dist/client/apis/AuthApi.js +77 -0
- package/dist/client/apis/AuthApi.js.map +1 -0
- package/dist/client/apis/AuthGroupApi.d.ts +12 -0
- package/dist/client/apis/AuthGroupApi.d.ts.map +1 -0
- package/dist/client/apis/AuthGroupApi.js +89 -0
- package/dist/client/apis/AuthGroupApi.js.map +1 -0
- package/dist/client/apis/ExportApi.d.ts +38 -0
- package/dist/client/apis/ExportApi.d.ts.map +1 -0
- package/dist/client/apis/ExportApi.js +230 -0
- package/dist/client/apis/ExportApi.js.map +1 -0
- package/dist/client/apis/FileApi.d.ts +45 -0
- package/dist/client/apis/FileApi.d.ts.map +1 -0
- package/dist/client/apis/FileApi.js +271 -0
- package/dist/client/apis/FileApi.js.map +1 -0
- package/dist/client/apis/GltfApi.d.ts +14 -0
- package/dist/client/apis/GltfApi.d.ts.map +1 -0
- package/dist/client/apis/GltfApi.js +96 -0
- package/dist/client/apis/GltfApi.js.map +1 -0
- package/dist/client/apis/LogApi.d.ts +13 -0
- package/dist/client/apis/LogApi.d.ts.map +1 -0
- package/dist/client/apis/LogApi.js +93 -0
- package/dist/client/apis/LogApi.js.map +1 -0
- package/dist/client/apis/ModelApi.d.ts +129 -0
- package/dist/client/apis/ModelApi.d.ts.map +1 -0
- package/dist/client/apis/ModelApi.js +762 -0
- package/dist/client/apis/ModelApi.js.map +1 -0
- package/dist/client/apis/ModelStateApi.d.ts +57 -0
- package/dist/client/apis/ModelStateApi.d.ts.map +1 -0
- package/dist/client/apis/ModelStateApi.js +328 -0
- package/dist/client/apis/ModelStateApi.js.map +1 -0
- package/dist/client/apis/OutputApi.d.ts +38 -0
- package/dist/client/apis/OutputApi.d.ts.map +1 -0
- package/dist/client/apis/OutputApi.js +230 -0
- package/dist/client/apis/OutputApi.js.map +1 -0
- package/dist/client/apis/ScriptApi.d.ts +17 -0
- package/dist/client/apis/ScriptApi.d.ts.map +1 -0
- package/dist/client/apis/ScriptApi.js +127 -0
- package/dist/client/apis/ScriptApi.js.map +1 -0
- package/dist/client/apis/SdtfApi.d.ts +37 -0
- package/dist/client/apis/SdtfApi.d.ts.map +1 -0
- package/dist/client/apis/SdtfApi.js +227 -0
- package/dist/client/apis/SdtfApi.js.map +1 -0
- package/dist/client/apis/SessionApi.d.ts +51 -0
- package/dist/client/apis/SessionApi.d.ts.map +1 -0
- package/dist/client/apis/SessionApi.js +300 -0
- package/dist/client/apis/SessionApi.js.map +1 -0
- package/dist/client/apis/SystemApi.d.ts +28 -0
- package/dist/client/apis/SystemApi.d.ts.map +1 -0
- package/dist/client/apis/SystemApi.js +235 -0
- package/dist/client/apis/SystemApi.js.map +1 -0
- package/dist/client/apis/TextureApi.d.ts +13 -0
- package/dist/client/apis/TextureApi.d.ts.map +1 -0
- package/dist/client/apis/TextureApi.js +91 -0
- package/dist/client/apis/TextureApi.js.map +1 -0
- package/dist/client/apis/index.d.ts +18 -0
- package/dist/client/apis/index.d.ts.map +1 -0
- package/dist/client/apis/index.js +34 -0
- package/dist/client/apis/index.js.map +1 -0
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/models/index.d.ts +1671 -0
- package/dist/client/models/index.d.ts.map +1 -0
- package/dist/client/models/index.js +239 -0
- package/dist/client/models/index.js.map +1 -0
- package/dist/client/runtime.d.ts +154 -0
- package/dist/client/runtime.d.ts.map +1 -0
- package/dist/client/runtime.js +323 -0
- package/dist/client/runtime.js.map +1 -0
- package/dist/configuration.d.ts +2 -7
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js +36 -16
- package/dist/configuration.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +2 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -13
- package/dist/utils.js.map +1 -1
- package/package.json +3 -9
- package/src/UtilsApi.ts +252 -324
- package/src/base.ts +48 -46
- package/src/client/apis/AnalyticsApi.ts +347 -0
- package/src/client/apis/ArSceneApi.ts +172 -0
- package/src/client/apis/AssetsApi.ts +474 -0
- package/src/client/apis/AuthApi.ts +63 -0
- package/src/client/apis/AuthGroupApi.ts +89 -0
- package/src/client/apis/ExportApi.ts +332 -0
- package/src/client/apis/FileApi.ts +401 -0
- package/src/client/apis/GltfApi.ts +101 -0
- package/src/client/apis/LogApi.ts +96 -0
- package/src/client/apis/ModelApi.ts +1206 -0
- package/src/client/apis/ModelStateApi.ts +479 -0
- package/src/client/apis/OutputApi.ts +333 -0
- package/src/client/apis/ScriptApi.ts +142 -0
- package/src/client/apis/SdtfApi.ts +327 -0
- package/src/client/apis/SessionApi.ts +435 -0
- package/src/client/apis/SystemApi.ts +301 -0
- package/src/client/apis/TextureApi.ts +91 -0
- package/src/client/apis/index.ts +19 -0
- package/src/client/index.ts +3 -16
- package/src/client/models/index.ts +7367 -0
- package/src/client/runtime.ts +442 -0
- package/src/configuration.ts +62 -37
- package/src/error.ts +2 -2
- package/src/index.ts +2 -1
- package/src/utils.ts +53 -25
- package/dist/client/api.d.ts +0 -2111
- package/dist/client/api.d.ts.map +0 -1
- package/dist/client/api.js +0 -3576
- package/dist/client/api.js.map +0 -1
- package/dist/client/base.d.ts +0 -32
- package/dist/client/base.d.ts.map +0 -1
- package/dist/client/base.js +0 -37
- package/dist/client/base.js.map +0 -1
- package/dist/client/common.d.ts +0 -15
- package/dist/client/common.d.ts.map +0 -1
- package/dist/client/common.js +0 -117
- package/dist/client/common.js.map +0 -1
- package/dist/client/configuration.d.ts +0 -37
- package/dist/client/configuration.d.ts.map +0 -1
- package/dist/client/configuration.js +0 -23
- package/dist/client/configuration.js.map +0 -1
- package/src/client/api.ts +0 -11052
- package/src/client/base.ts +0 -62
- package/src/client/common.ts +0 -127
- package/src/client/configuration.ts +0 -121
package/src/UtilsApi.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseAPI } from './base';
|
|
2
2
|
import {
|
|
3
3
|
AssetsApi,
|
|
4
|
-
Configuration,
|
|
5
4
|
ExportApi,
|
|
6
5
|
OutputApi,
|
|
7
6
|
ReqCache,
|
|
@@ -14,14 +13,13 @@ import {
|
|
|
14
13
|
ResGetCachedExports,
|
|
15
14
|
ResGetCachedOutputs,
|
|
16
15
|
ResOutput,
|
|
17
|
-
} from './client';
|
|
18
|
-
import { BaseAPI, RequestArgs } from './client/base';
|
|
16
|
+
} from './client/index';
|
|
19
17
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from './
|
|
24
|
-
import { IllegalArgumentError,
|
|
18
|
+
Configuration as ClientConfig,
|
|
19
|
+
ResponseError as ClientResponseError,
|
|
20
|
+
} from './client/runtime';
|
|
21
|
+
import { Configuration } from './configuration';
|
|
22
|
+
import { IllegalArgumentError, TimeoutError } from './error';
|
|
25
23
|
import { contentDispositionFromFilename, sleep } from './utils';
|
|
26
24
|
|
|
27
25
|
/* Regex patterns for different asset types targeting the ShapeDiver API. */
|
|
@@ -41,156 +39,100 @@ const directDownloadUri = /^(http[s]?:\/\/)?(viewer|textures|downloads)\.shapedi
|
|
|
41
39
|
/* Regex pattern for ShapeDiver no-CDN servers. */
|
|
42
40
|
const sdNoCdnOrigin = /-nocdn.[\w-]+.shapediver.com$/;
|
|
43
41
|
|
|
42
|
+
/** List of headers to remove before sending the request. */
|
|
43
|
+
type DisableHeaders = string[];
|
|
44
|
+
|
|
44
45
|
export class UtilsApi extends BaseAPI {
|
|
45
|
-
constructor(
|
|
46
|
-
super(
|
|
46
|
+
constructor(config?: Configuration | ClientConfig) {
|
|
47
|
+
super(config);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* Upload the given file to the specified URL.
|
|
51
52
|
*
|
|
52
53
|
* _Note: This method does not use the `UtilsApi`'s base configuration._
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
54
|
+
* @param url The target URL of the upload request.
|
|
55
|
+
* @param data The data that should be uploaded.
|
|
56
|
+
* @param contentType Indicate the original media type of the resource.
|
|
57
|
+
* @param [filename] The name of the file to be uploaded. When a filename has been specified in the request-upload call, then the same filename has to be specified for the upload as well.
|
|
58
|
+
* @param [options] Override http request option.
|
|
58
59
|
*/
|
|
59
60
|
public upload(
|
|
60
61
|
url: string,
|
|
61
62
|
data: any,
|
|
62
63
|
contentType: string,
|
|
63
64
|
filename?: string,
|
|
64
|
-
options
|
|
65
|
-
):
|
|
65
|
+
options: RequestInit = {}
|
|
66
|
+
): Promise<Response> {
|
|
66
67
|
// Prepare headers for the upload.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'X-ShapeDiver-Origin': undefined,
|
|
72
|
-
'X-ShapeDiver-SessionEngineId': undefined,
|
|
73
|
-
'X-ShapeDiver-BuildVersion': undefined,
|
|
74
|
-
'X-ShapeDiver-BuildDate': undefined,
|
|
75
|
-
'X-ShapeDiver-UserAgent': undefined,
|
|
76
|
-
};
|
|
77
|
-
if (filename) reqHeaders['Content-Disposition'] = contentDispositionFromFilename(filename);
|
|
68
|
+
options.headers = new Headers(options.headers);
|
|
69
|
+
options.headers.set('Content-Type', contentType);
|
|
70
|
+
if (filename)
|
|
71
|
+
options.headers.set('Content-Disposition', contentDispositionFromFilename(filename));
|
|
78
72
|
|
|
79
|
-
const
|
|
80
|
-
|
|
73
|
+
const disableHeaders: DisableHeaders = [
|
|
74
|
+
'Authorization', // Disable by default to avoid accidental token exposure.
|
|
81
75
|
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
/* Override custom ShapeDiver headers to avoid CORS issues. */
|
|
77
|
+
'X-ShapeDiver-Origin',
|
|
78
|
+
'X-ShapeDiver-SessionEngineId',
|
|
79
|
+
'X-ShapeDiver-BuildVersion',
|
|
80
|
+
'X-ShapeDiver-BuildDate',
|
|
81
|
+
'X-ShapeDiver-UserAgent',
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
return this.fetchRequest("PUT", url, data, options, disableHeaders);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* Upload the given asset to the specified ShapeDiver URL.
|
|
88
89
|
*
|
|
89
90
|
* _Note: This method does not use the `UtilsApi`'s base configuration._
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
92
|
-
* @param
|
|
93
|
-
* @param
|
|
91
|
+
* @param url The target URL of the upload request.
|
|
92
|
+
* @param data The data that should be uploaded.
|
|
93
|
+
* @param headers The headers object that was returned from the request-upload call.
|
|
94
|
+
* @param [options] Override http request option.
|
|
94
95
|
*/
|
|
95
96
|
public uploadAsset(
|
|
96
97
|
url: string,
|
|
97
98
|
data: any,
|
|
98
99
|
headers: ResAssetUploadHeaders,
|
|
99
|
-
options
|
|
100
|
-
):
|
|
100
|
+
options: RequestInit = {}
|
|
101
|
+
): Promise<Response> {
|
|
101
102
|
// Prepare headers for the upload.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
'X-ShapeDiver-SessionEngineId': undefined,
|
|
108
|
-
'X-ShapeDiver-BuildVersion': undefined,
|
|
109
|
-
'X-ShapeDiver-BuildDate': undefined,
|
|
110
|
-
'X-ShapeDiver-UserAgent': undefined,
|
|
111
|
-
};
|
|
112
|
-
if (headers.contentDisposition)
|
|
113
|
-
reqHeaders['Content-Disposition'] = headers.contentDisposition;
|
|
103
|
+
options.headers = new Headers(options.headers);
|
|
104
|
+
options.headers.set('Content-Type', headers.contentType);
|
|
105
|
+
if (headers.contentDisposition) {
|
|
106
|
+
options.headers.set('Content-Disposition', headers.contentDisposition);
|
|
107
|
+
}
|
|
114
108
|
|
|
115
|
-
const
|
|
116
|
-
|
|
109
|
+
const disableHeaders: DisableHeaders = [
|
|
110
|
+
'Authorization', // Disable by default to avoid accidental token exposure.
|
|
117
111
|
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
/* Override custom ShapeDiver headers to avoid CORS issues. */
|
|
113
|
+
'X-ShapeDiver-Origin',
|
|
114
|
+
'X-ShapeDiver-SessionEngineId',
|
|
115
|
+
'X-ShapeDiver-BuildVersion',
|
|
116
|
+
'X-ShapeDiver-BuildDate',
|
|
117
|
+
'X-ShapeDiver-UserAgent',
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
return this.fetchRequest("PUT", url, data, options, disableHeaders);
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* Downloads data from the specified URL.
|
|
124
125
|
*
|
|
125
|
-
*
|
|
126
|
-
* @param
|
|
127
|
-
* @
|
|
128
|
-
* @throws {ResponseError} if the response type cannot be handled, such as when JSON parsing
|
|
126
|
+
* @param url The URL to download from.
|
|
127
|
+
* @param [options] Optional HTTP request overrides.
|
|
128
|
+
* @throws ResponseError if the response type cannot be handled, such as when JSON parsing
|
|
129
129
|
* fails.
|
|
130
130
|
*/
|
|
131
|
-
public download(
|
|
132
|
-
|
|
133
|
-
options
|
|
134
|
-
): AxiosPromise<ArrayBuffer>;
|
|
135
|
-
public download(
|
|
136
|
-
url: string,
|
|
137
|
-
options: { responseType: 'json' } & RawAxiosRequestConfig
|
|
138
|
-
): AxiosPromise<Record<string, any>>;
|
|
139
|
-
public download(
|
|
140
|
-
url: string,
|
|
141
|
-
options: { responseType: 'text' } & RawAxiosRequestConfig
|
|
142
|
-
): AxiosPromise<string>;
|
|
143
|
-
public download(url: string, options?: RawAxiosRequestConfig): AxiosPromise<any>;
|
|
144
|
-
public async download(url: string, options?: RawAxiosRequestConfig): AxiosPromise<any> {
|
|
145
|
-
const localRequestOptions = await this.buildRequestOptions(url, options ?? {});
|
|
146
|
-
this.disableAuthHeaderForShapeDiverUris(url, localRequestOptions);
|
|
147
|
-
|
|
148
|
-
const request = this.buildRequest('GET', url, undefined, localRequestOptions)();
|
|
149
|
-
const res = request();
|
|
150
|
-
|
|
151
|
-
// Convert Buffer to ArrayBuffer in Node.js when responseType is 'arraybuffer'
|
|
152
|
-
if (options?.responseType === 'arraybuffer') {
|
|
153
|
-
return res.then((response) => {
|
|
154
|
-
const data = response.data;
|
|
155
|
-
|
|
156
|
-
// In Node.js, Axios returns a Buffer for arraybuffer responseType
|
|
157
|
-
// Convert it to ArrayBuffer for consistency with browser behavior
|
|
158
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
|
|
159
|
-
// Convert Buffer to ArrayBuffer by copying to a new Uint8Array
|
|
160
|
-
const uint8Array = new Uint8Array(data);
|
|
161
|
-
response.data = uint8Array.buffer;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return response;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
131
|
+
public async download(url: string, options: RequestInit = {}): Promise<Response> {
|
|
132
|
+
const disableHeaders: DisableHeaders = [];
|
|
133
|
+
this.disableAuthHeaderForShapeDiverUris(url, options, disableHeaders);
|
|
167
134
|
|
|
168
|
-
|
|
169
|
-
if (options?.responseType === 'json') {
|
|
170
|
-
return res.then((response) => {
|
|
171
|
-
const data = response.data;
|
|
172
|
-
|
|
173
|
-
// Throw a single error if the response is not valid JSON (object or array)
|
|
174
|
-
if (
|
|
175
|
-
data === null ||
|
|
176
|
-
data === undefined ||
|
|
177
|
-
typeof data === 'string' ||
|
|
178
|
-
data instanceof ArrayBuffer ||
|
|
179
|
-
(typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) ||
|
|
180
|
-
(typeof Blob !== 'undefined' && data instanceof Blob)
|
|
181
|
-
) {
|
|
182
|
-
throw new ResponseError(
|
|
183
|
-
response.status,
|
|
184
|
-
'Invalid JSON response: Could not parse response as JSON',
|
|
185
|
-
'Expected valid JSON but received incompatible response'
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return response;
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return res;
|
|
135
|
+
return await this.fetchRequest("GET", url, undefined, options, disableHeaders);
|
|
194
136
|
}
|
|
195
137
|
|
|
196
138
|
/**
|
|
@@ -198,22 +140,14 @@ export class UtilsApi extends BaseAPI {
|
|
|
198
140
|
* the asset is determined by the URL and returned with the promise.
|
|
199
141
|
*
|
|
200
142
|
* The response type can be controlled by setting the `responseType` in the `options` object.
|
|
201
|
-
* @param
|
|
202
|
-
* @param
|
|
203
|
-
* @throws
|
|
143
|
+
* @param url The URL of the asset to download.
|
|
144
|
+
* @param [options] Override http request option.
|
|
145
|
+
* @throws IllegalArgumentError in case the URL is not a valid ShapeDiver asset URL.
|
|
204
146
|
*/
|
|
205
147
|
public downloadAsset(
|
|
206
148
|
url: string,
|
|
207
|
-
options
|
|
208
|
-
): [
|
|
209
|
-
public downloadAsset(
|
|
210
|
-
url: string,
|
|
211
|
-
options?: RawAxiosRequestConfig
|
|
212
|
-
): [AxiosPromise<any>, 'export' | 'output' | 'texture'];
|
|
213
|
-
public downloadAsset(
|
|
214
|
-
url: string,
|
|
215
|
-
options?: RawAxiosRequestConfig
|
|
216
|
-
): [AxiosPromise<any>, 'export' | 'output' | 'texture'] {
|
|
149
|
+
options?: RequestInit
|
|
150
|
+
): [Promise<Response>, 'export' | 'output' | 'texture'] {
|
|
217
151
|
let type: 'output' | 'export' | 'texture';
|
|
218
152
|
|
|
219
153
|
// Check if the given URL is a valid API or CDN asset URL
|
|
@@ -226,7 +160,7 @@ export class UtilsApi extends BaseAPI {
|
|
|
226
160
|
);
|
|
227
161
|
}
|
|
228
162
|
|
|
229
|
-
return [this.download(url, options)
|
|
163
|
+
return [this.download(url, options), type];
|
|
230
164
|
}
|
|
231
165
|
|
|
232
166
|
/**
|
|
@@ -234,83 +168,71 @@ export class UtilsApi extends BaseAPI {
|
|
|
234
168
|
* URLs to the `AssetsApi.downloadImage` endpoint to avoid CORS issues.
|
|
235
169
|
*
|
|
236
170
|
* The response type can be controlled by setting the `responseType` in the `options` object.
|
|
237
|
-
* @param
|
|
238
|
-
* @param
|
|
239
|
-
* @param
|
|
171
|
+
* @param sessionId The session ID.
|
|
172
|
+
* @param url The URL of the image to download.
|
|
173
|
+
* @param [options] Override http request option.
|
|
240
174
|
*/
|
|
241
|
-
public downloadImage(
|
|
175
|
+
public async downloadImage(
|
|
242
176
|
sessionId: string,
|
|
243
177
|
url: string,
|
|
244
|
-
options:
|
|
245
|
-
):
|
|
246
|
-
public downloadImage(
|
|
247
|
-
sessionId: string,
|
|
248
|
-
url: string,
|
|
249
|
-
options?: RawAxiosRequestConfig
|
|
250
|
-
): AxiosPromise<any>;
|
|
251
|
-
public downloadImage(
|
|
252
|
-
sessionId: string,
|
|
253
|
-
url: string,
|
|
254
|
-
options?: RawAxiosRequestConfig
|
|
255
|
-
): AxiosPromise<any> {
|
|
178
|
+
options: RequestInit = {}
|
|
179
|
+
): Promise<Blob> {
|
|
256
180
|
if (
|
|
257
181
|
apiAssetTextureUri.test(url) ||
|
|
258
182
|
cdnAssetTextureUri.test(url) ||
|
|
259
183
|
directDownloadUri.test(url)
|
|
260
184
|
) {
|
|
261
185
|
// Call ShapeDiver texture-asset URLs directly
|
|
262
|
-
return this.download(url, options)
|
|
186
|
+
return this.download(url, options).then((response) => response.blob());
|
|
263
187
|
} else {
|
|
264
188
|
/* All other source URLs are called via the download-image endpoint */
|
|
265
189
|
|
|
266
|
-
const localOptions: RawAxiosRequestConfig = options ?? {};
|
|
267
|
-
this.disableAuthHeaderForShapeDiverUris(url, localOptions);
|
|
268
|
-
|
|
269
190
|
// Use a universal base64 encoder for browser and Node.js environments
|
|
270
191
|
const encodedUrl =
|
|
271
192
|
typeof window !== 'undefined' && window.btoa
|
|
272
193
|
? window.btoa(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
194
|
+
encodeURIComponent(url).replace(/%([0-9A-F]{2})/g, (_, p1) =>
|
|
195
|
+
String.fromCharCode(parseInt(p1, 16))
|
|
196
|
+
)
|
|
197
|
+
)
|
|
277
198
|
: Buffer.from(url, 'utf-8').toString('base64');
|
|
278
199
|
|
|
279
|
-
|
|
200
|
+
// Remove the authrization header from all configurations.
|
|
201
|
+
const config = new Configuration(this.configuration);
|
|
202
|
+
if (config.headers && config.headers['Authorization'])
|
|
203
|
+
delete config.headers!['Authrization'];
|
|
204
|
+
|
|
205
|
+
return new AssetsApi(config).downloadImage(
|
|
280
206
|
sessionId,
|
|
281
207
|
encodedUrl,
|
|
282
|
-
|
|
208
|
+
options
|
|
283
209
|
);
|
|
284
210
|
}
|
|
285
211
|
}
|
|
286
212
|
|
|
287
213
|
/**
|
|
288
214
|
* Submit a customization request and wait for the result to be finished.
|
|
289
|
-
* @param
|
|
290
|
-
* @param
|
|
291
|
-
* @param
|
|
292
|
-
* @param
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* @param {*} [options] Override http request option.
|
|
296
|
-
* @throws {TimeoutError} in case a maximum duration has been specified and is exceeded.
|
|
215
|
+
* @param sessionId The session ID.
|
|
216
|
+
* @param body The body of the customization request.
|
|
217
|
+
* @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
218
|
+
* @param [ignoreUnknownParams=false] Allow relaxed validation of parameter identifiers. When set to `true`, unrecognized parameters will be ignored rather than causing an error. Defaults to `false`.
|
|
219
|
+
* @param [options] Override http request option.
|
|
220
|
+
* @throws TimeoutError in case a maximum duration has been specified and is exceeded.
|
|
297
221
|
*/
|
|
298
222
|
public async submitAndWaitForOutput(
|
|
299
223
|
sessionId: string,
|
|
300
224
|
body: ReqCustomization,
|
|
301
225
|
maxWaitMsec = -1,
|
|
302
226
|
ignoreUnknownParams?: boolean,
|
|
303
|
-
options?:
|
|
227
|
+
options?: RequestInit
|
|
304
228
|
): Promise<ResComputeOutputs> {
|
|
305
229
|
const startMsec = Date.now();
|
|
306
|
-
const dto = (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
)
|
|
313
|
-
).data;
|
|
230
|
+
const dto = await new OutputApi(this.configuration).computeOutputs(
|
|
231
|
+
sessionId,
|
|
232
|
+
body,
|
|
233
|
+
ignoreUnknownParams,
|
|
234
|
+
options
|
|
235
|
+
);
|
|
314
236
|
const waitMsec = Date.now() - startMsec;
|
|
315
237
|
|
|
316
238
|
// Reduce the total max waiting time by the amount the customization-request took
|
|
@@ -321,31 +243,27 @@ export class UtilsApi extends BaseAPI {
|
|
|
321
243
|
|
|
322
244
|
/**
|
|
323
245
|
* Submit an export request and wait for the result to be finished.
|
|
324
|
-
* @param
|
|
325
|
-
* @param
|
|
326
|
-
* @param
|
|
327
|
-
* @param
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* @param {*} [options] Override http request option.
|
|
331
|
-
* @throws {TimeoutError} in case a maximum duration has been specified and is exceeded.
|
|
246
|
+
* @param sessionId The session ID.
|
|
247
|
+
* @param body The body of the export request.
|
|
248
|
+
* @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
249
|
+
* @param [ignoreUnknownParams=false] Allow relaxed validation of parameter identifiers. When set to `true`, unrecognized parameters will be ignored rather than causing an error. Defaults to `false`.
|
|
250
|
+
* @param [options] Override http request option.
|
|
251
|
+
* @throws TimeoutError in case a maximum duration has been specified and is exceeded.
|
|
332
252
|
*/
|
|
333
253
|
public async submitAndWaitForExport(
|
|
334
254
|
sessionId: string,
|
|
335
255
|
body: ReqExport,
|
|
336
256
|
maxWaitMsec = -1,
|
|
337
257
|
ignoreUnknownParams?: boolean,
|
|
338
|
-
options?:
|
|
258
|
+
options?: RequestInit
|
|
339
259
|
): Promise<ResComputeExports> {
|
|
340
260
|
const startMsec = Date.now();
|
|
341
|
-
const dto = (
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
)
|
|
348
|
-
).data;
|
|
261
|
+
const dto = await new ExportApi(this.configuration).computeExports(
|
|
262
|
+
sessionId,
|
|
263
|
+
body,
|
|
264
|
+
ignoreUnknownParams,
|
|
265
|
+
options
|
|
266
|
+
);
|
|
349
267
|
const waitMsec = Date.now() - startMsec;
|
|
350
268
|
|
|
351
269
|
// Reduce the total max waiting time by the amount the compute-request took
|
|
@@ -356,17 +274,17 @@ export class UtilsApi extends BaseAPI {
|
|
|
356
274
|
|
|
357
275
|
/**
|
|
358
276
|
* Given a DTO resulting from a customization request, wait for the results to be finished.
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
361
|
-
* @param
|
|
362
|
-
* @param
|
|
363
|
-
* @throws
|
|
277
|
+
* @param sessionId The session ID.
|
|
278
|
+
* @param dto The DTO resulting from a customization request.
|
|
279
|
+
* @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
280
|
+
* @param [options] Override http request option.
|
|
281
|
+
* @throws TimeoutError in case a maximum duration has been specified and is exceeded.
|
|
364
282
|
*/
|
|
365
283
|
private async waitForOutputResult(
|
|
366
284
|
sessionId: string,
|
|
367
285
|
dto: ResComputeOutputs,
|
|
368
286
|
maxWaitMsec: number,
|
|
369
|
-
options?:
|
|
287
|
+
options?: RequestInit
|
|
370
288
|
): Promise<ResComputeOutputs> {
|
|
371
289
|
if (!dto.outputs) return dto;
|
|
372
290
|
|
|
@@ -394,13 +312,11 @@ export class UtilsApi extends BaseAPI {
|
|
|
394
312
|
await sleep(delay);
|
|
395
313
|
|
|
396
314
|
// Send cache request
|
|
397
|
-
dto = (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
)
|
|
403
|
-
).data;
|
|
315
|
+
dto = await new OutputApi(this.configuration).getCachedOutputs(
|
|
316
|
+
sessionId,
|
|
317
|
+
outputVersions,
|
|
318
|
+
options
|
|
319
|
+
)
|
|
404
320
|
delay = this.getMaxOutputDelay(dto);
|
|
405
321
|
}
|
|
406
322
|
|
|
@@ -409,19 +325,19 @@ export class UtilsApi extends BaseAPI {
|
|
|
409
325
|
|
|
410
326
|
/**
|
|
411
327
|
* Given a DTO resulting from an export request, wait for the result to be finished.
|
|
412
|
-
* @param
|
|
413
|
-
* @param
|
|
414
|
-
* @param
|
|
415
|
-
* @param
|
|
416
|
-
* @param
|
|
417
|
-
* @throws
|
|
328
|
+
* @param sessionId The session ID.
|
|
329
|
+
* @param body The body of the export request.
|
|
330
|
+
* @param dto The DTO resulting from an export request.
|
|
331
|
+
* @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
332
|
+
* @param [options] Override http request option.
|
|
333
|
+
* @throws TimeoutError in case a maximum duration has been specified and is exceeded.
|
|
418
334
|
*/
|
|
419
335
|
private async waitForExportResult(
|
|
420
336
|
sessionId: string,
|
|
421
337
|
body: ReqExport,
|
|
422
338
|
dto: ResComputeExports,
|
|
423
339
|
maxWaitMsec: number,
|
|
424
|
-
options?:
|
|
340
|
+
options?: RequestInit
|
|
425
341
|
): Promise<ResComputeExports> {
|
|
426
342
|
let delay = this.getMaxExportDelay(body, dto);
|
|
427
343
|
const startMsec = Date.now();
|
|
@@ -441,9 +357,7 @@ export class UtilsApi extends BaseAPI {
|
|
|
441
357
|
await sleep(delay);
|
|
442
358
|
|
|
443
359
|
// Send cache request
|
|
444
|
-
dto = (
|
|
445
|
-
await new ExportApi(this.configuration).getCachedExports(sessionId, body, options)
|
|
446
|
-
).data;
|
|
360
|
+
dto = await new ExportApi(this.configuration).getCachedExports(sessionId, body, options);
|
|
447
361
|
delay = this.getMaxExportDelay(body, dto);
|
|
448
362
|
}
|
|
449
363
|
|
|
@@ -452,7 +366,7 @@ export class UtilsApi extends BaseAPI {
|
|
|
452
366
|
|
|
453
367
|
/**
|
|
454
368
|
* Get the maximum delay that was reported for output versions.
|
|
455
|
-
* @param
|
|
369
|
+
* @param dto The DTO resulting from a customization request.
|
|
456
370
|
* @returns maximum delay, -1 in case no delay was reported
|
|
457
371
|
*/
|
|
458
372
|
private getMaxOutputDelay(dto: ResComputeOutputs | ResGetCachedOutputs): number {
|
|
@@ -465,7 +379,7 @@ export class UtilsApi extends BaseAPI {
|
|
|
465
379
|
/**
|
|
466
380
|
* Get the maximum delay that was reported for the exports. If outputs have been reported as
|
|
467
381
|
* well, their delay time is included too.
|
|
468
|
-
* @param
|
|
382
|
+
* @param dto The DTO resulting from an export request.
|
|
469
383
|
* @returns delay, -1 in case no delay was reported
|
|
470
384
|
*/
|
|
471
385
|
private getMaxExportDelay(
|
|
@@ -487,77 +401,121 @@ export class UtilsApi extends BaseAPI {
|
|
|
487
401
|
}
|
|
488
402
|
|
|
489
403
|
/**
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
* @param {*} data The data to send with the request.
|
|
495
|
-
* @param {*} [options={}] Optional http request options.
|
|
496
|
-
*/
|
|
497
|
-
private buildRequest(
|
|
404
|
+
* Replacement for `runtime.BaseAPI.request`.
|
|
405
|
+
* Needed to call `createFetchParameters`.
|
|
406
|
+
*/
|
|
407
|
+
private async fetchRequest(
|
|
498
408
|
method: string,
|
|
499
409
|
url: string,
|
|
500
|
-
data:
|
|
501
|
-
options:
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
// in the serialization process.
|
|
512
|
-
const configuration = this.configuration ?? new Configuration();
|
|
513
|
-
reqOptions.data = this.serializeDataSafely(data, reqOptions, configuration);
|
|
514
|
-
}
|
|
410
|
+
data: unknown,
|
|
411
|
+
options: RequestInit = {},
|
|
412
|
+
disableHeaders: DisableHeaders = []
|
|
413
|
+
): Promise<Response> {
|
|
414
|
+
const { url: requestUrl, init } = await this.createFetchParameters(
|
|
415
|
+
method,
|
|
416
|
+
url,
|
|
417
|
+
data,
|
|
418
|
+
options,
|
|
419
|
+
disableHeaders
|
|
420
|
+
);
|
|
515
421
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
this.configuration && url.startsWith('http')
|
|
519
|
-
? new Configuration({ ...this.configuration, basePath: undefined })
|
|
520
|
-
: this.configuration;
|
|
422
|
+
const response = await this.fetchApi(requestUrl, init);
|
|
423
|
+
if (response.ok) return response;
|
|
521
424
|
|
|
522
|
-
|
|
523
|
-
return createRequestFunction(axiosArgs, this.axios, basePath, configuration).bind(
|
|
524
|
-
this.axios
|
|
525
|
-
);
|
|
526
|
-
};
|
|
425
|
+
throw new ClientResponseError(response, 'Response returned an error code');
|
|
527
426
|
}
|
|
528
427
|
|
|
529
428
|
/**
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
* this case, the Bearer token from the API configuration will be used.
|
|
536
|
-
* @param url The URL to send the request to.
|
|
537
|
-
* @param options The Axios request options.
|
|
538
|
-
* @returns The merged Axios request options.
|
|
539
|
-
*/
|
|
540
|
-
private async buildRequestOptions(
|
|
429
|
+
* Replacement for `runtime.BaseAPI.createFetchParams`.
|
|
430
|
+
* Needed to allow dynamic basePath handling and proper header manipulation.
|
|
431
|
+
*/
|
|
432
|
+
private async createFetchParameters(
|
|
433
|
+
method: string,
|
|
541
434
|
url: string,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
if (
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
435
|
+
data: unknown,
|
|
436
|
+
options: RequestInit,
|
|
437
|
+
disableHeaders: DisableHeaders
|
|
438
|
+
): Promise<{ url: string; init: RequestInit }> {
|
|
439
|
+
const configuration = this.configuration ?? new Configuration();
|
|
440
|
+
|
|
441
|
+
// Add authorization if applicable.
|
|
442
|
+
const authHeaders: Record<string, string> = {};
|
|
443
|
+
if (
|
|
444
|
+
this.isTargetingInternalOrNoCdnServer(url) &&
|
|
445
|
+
this.configuration &&
|
|
446
|
+
this.configuration.accessToken
|
|
447
|
+
) {
|
|
448
|
+
const token = this.configuration.accessToken;
|
|
449
|
+
const tokenString = await token("JwtAuth", []);
|
|
450
|
+
|
|
451
|
+
if (tokenString) authHeaders["Authorization"] = `Bearer ${tokenString}`;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const headers = new Headers(configuration.headers);
|
|
455
|
+
for (const source of [
|
|
456
|
+
authHeaders,
|
|
457
|
+
options.headers,
|
|
458
|
+
]) {
|
|
459
|
+
if (!source) continue;
|
|
460
|
+
new Headers(source).forEach((value, name) => headers.set(name, value));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Remove all disabled headers.
|
|
464
|
+
disableHeaders.forEach(header => headers.delete(header));
|
|
465
|
+
|
|
466
|
+
const init: RequestInit = {
|
|
467
|
+
...options,
|
|
468
|
+
method,
|
|
469
|
+
headers,
|
|
470
|
+
body: this.serializeDataForFetch(data, headers),
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
url: this.createFetchUrl(url),
|
|
475
|
+
init
|
|
558
476
|
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Prepends the base-path to `url` when the URL is relative. */
|
|
480
|
+
private createFetchUrl(url: string): string {
|
|
481
|
+
if (url.startsWith("http")) return url;
|
|
482
|
+
|
|
483
|
+
const basePath = this.configuration.basePath.replace(/\/+$/, "");
|
|
484
|
+
const path = url.replace(/^\/+/, "");
|
|
485
|
+
|
|
486
|
+
return `${basePath}/${path}`;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Passes `BodyInit` types through, stringifies JSON bodies and throws for invalid types. */
|
|
490
|
+
private serializeDataForFetch(data: unknown, headers: Headers): BodyInit | undefined {
|
|
491
|
+
if (data === undefined || data === null) return undefined;
|
|
492
|
+
|
|
493
|
+
if (
|
|
494
|
+
typeof data === 'string' ||
|
|
495
|
+
data instanceof ArrayBuffer ||
|
|
496
|
+
ArrayBuffer.isView(data) ||
|
|
497
|
+
(typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
498
|
+
(typeof FormData !== 'undefined' && data instanceof FormData) ||
|
|
499
|
+
(typeof URLSearchParams !== 'undefined' && data instanceof URLSearchParams) ||
|
|
500
|
+
(typeof ReadableStream !== 'undefined' && data instanceof ReadableStream)
|
|
501
|
+
) {
|
|
502
|
+
return data as BodyInit;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (!this.isJsonMime(headers.get('content-type') ?? '')) {
|
|
506
|
+
throw new TypeError(
|
|
507
|
+
'Request body must be a Fetch BodyInit value or use a JSON Content-Type.'
|
|
508
|
+
);
|
|
509
|
+
}
|
|
559
510
|
|
|
560
|
-
|
|
511
|
+
const body = JSON.stringify(data);
|
|
512
|
+
|
|
513
|
+
// JSON.stringify(undefined), functions, and symbols returns undefined.
|
|
514
|
+
if (body === undefined) {
|
|
515
|
+
throw new TypeError('Request body cannot be serialized as JSON.');
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return body;
|
|
561
519
|
}
|
|
562
520
|
|
|
563
521
|
/**
|
|
@@ -578,57 +536,27 @@ export class UtilsApi extends BaseAPI {
|
|
|
578
536
|
}
|
|
579
537
|
}
|
|
580
538
|
|
|
581
|
-
/**
|
|
582
|
-
* A wrapper around the auto-generated `serializeDataIfNeeded` that safely serializes data for
|
|
583
|
-
* Axios. The idea of the base function is to stringify objects for application-json requests.
|
|
584
|
-
* However, this does not work on all data types. Thus, this wrapper passes through all data
|
|
585
|
-
* types that can be handled natively by Axios, and only calls the base function for the rest.
|
|
586
|
-
* @param value The data to serialize.
|
|
587
|
-
* @param requestOptions The request options.
|
|
588
|
-
* @param configuration The API configuration.
|
|
589
|
-
* @returns The serialized data.
|
|
590
|
-
*/
|
|
591
|
-
private serializeDataSafely(
|
|
592
|
-
value: any,
|
|
593
|
-
requestOptions: any,
|
|
594
|
-
configuration?: Configuration
|
|
595
|
-
): any {
|
|
596
|
-
// Helper: detect Node.js stream
|
|
597
|
-
function isStream(val: any): boolean {
|
|
598
|
-
return val !== null && typeof val === 'object' && typeof val.pipe === 'function';
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// Pass through raw binary types that Axios can handle
|
|
602
|
-
if (
|
|
603
|
-
value instanceof ArrayBuffer ||
|
|
604
|
-
ArrayBuffer.isView(value) || // TypedArray (Uint8Array, Int16Array, etc.) and DataView
|
|
605
|
-
isStream(value) ||
|
|
606
|
-
(typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) ||
|
|
607
|
-
(typeof Blob !== 'undefined' && value instanceof Blob) ||
|
|
608
|
-
(typeof File !== 'undefined' && value instanceof File) ||
|
|
609
|
-
(typeof FormData !== 'undefined' && value instanceof FormData) ||
|
|
610
|
-
(typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams)
|
|
611
|
-
) {
|
|
612
|
-
return value;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// Fallback to the generated serializer
|
|
616
|
-
return serializeDataIfNeeded(value, requestOptions, configuration);
|
|
617
|
-
}
|
|
618
|
-
|
|
619
539
|
/** Disable the Authorization header for ShapeDiver URIs if not explicitly set. */
|
|
620
|
-
private disableAuthHeaderForShapeDiverUris(
|
|
540
|
+
private disableAuthHeaderForShapeDiverUris(
|
|
541
|
+
url: string,
|
|
542
|
+
options: RequestInit,
|
|
543
|
+
disableHeaders: DisableHeaders,
|
|
544
|
+
): void {
|
|
545
|
+
const headers = new Headers(options.headers);
|
|
546
|
+
|
|
621
547
|
// When an authorization header is set, it will override anything that is set later
|
|
622
|
-
if (
|
|
548
|
+
if (headers.has('Authorization')) return;
|
|
549
|
+
|
|
550
|
+
const fetchUrl = this.createFetchUrl(url);
|
|
623
551
|
|
|
624
552
|
let targetUrl: URL;
|
|
625
553
|
try {
|
|
626
|
-
targetUrl = new URL(
|
|
554
|
+
targetUrl = new URL(fetchUrl);
|
|
627
555
|
} catch {
|
|
628
556
|
return;
|
|
629
557
|
}
|
|
630
558
|
|
|
631
|
-
if (directDownloadUri.test(targetUrl.origin) || cdnAssetUri.test(
|
|
632
|
-
|
|
559
|
+
if (directDownloadUri.test(targetUrl.origin) || cdnAssetUri.test(targetUrl.pathname))
|
|
560
|
+
disableHeaders.push('Authorization');
|
|
633
561
|
}
|
|
634
562
|
}
|