@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.
Files changed (153) hide show
  1. package/README.md +5 -5
  2. package/dist/UtilsApi.d.ts +16 -29
  3. package/dist/UtilsApi.d.ts.map +1 -1
  4. package/dist/UtilsApi.js +133 -135
  5. package/dist/UtilsApi.js.map +1 -1
  6. package/dist/base.d.ts +2 -5
  7. package/dist/base.d.ts.map +1 -1
  8. package/dist/base.js +30 -36
  9. package/dist/base.js.map +1 -1
  10. package/dist/client/apis/AnalyticsApi.d.ts +38 -0
  11. package/dist/client/apis/AnalyticsApi.d.ts.map +1 -0
  12. package/dist/client/apis/AnalyticsApi.js +245 -0
  13. package/dist/client/apis/AnalyticsApi.js.map +1 -0
  14. package/dist/client/apis/ArSceneApi.d.ts +23 -0
  15. package/dist/client/apis/ArSceneApi.d.ts.map +1 -0
  16. package/dist/client/apis/ArSceneApi.js +140 -0
  17. package/dist/client/apis/ArSceneApi.js.map +1 -0
  18. package/dist/client/apis/AssetsApi.d.ts +54 -0
  19. package/dist/client/apis/AssetsApi.d.ts.map +1 -0
  20. package/dist/client/apis/AssetsApi.js +329 -0
  21. package/dist/client/apis/AssetsApi.js.map +1 -0
  22. package/dist/client/apis/AuthApi.d.ts +8 -0
  23. package/dist/client/apis/AuthApi.d.ts.map +1 -0
  24. package/dist/client/apis/AuthApi.js +77 -0
  25. package/dist/client/apis/AuthApi.js.map +1 -0
  26. package/dist/client/apis/AuthGroupApi.d.ts +12 -0
  27. package/dist/client/apis/AuthGroupApi.d.ts.map +1 -0
  28. package/dist/client/apis/AuthGroupApi.js +89 -0
  29. package/dist/client/apis/AuthGroupApi.js.map +1 -0
  30. package/dist/client/apis/ExportApi.d.ts +38 -0
  31. package/dist/client/apis/ExportApi.d.ts.map +1 -0
  32. package/dist/client/apis/ExportApi.js +230 -0
  33. package/dist/client/apis/ExportApi.js.map +1 -0
  34. package/dist/client/apis/FileApi.d.ts +45 -0
  35. package/dist/client/apis/FileApi.d.ts.map +1 -0
  36. package/dist/client/apis/FileApi.js +271 -0
  37. package/dist/client/apis/FileApi.js.map +1 -0
  38. package/dist/client/apis/GltfApi.d.ts +14 -0
  39. package/dist/client/apis/GltfApi.d.ts.map +1 -0
  40. package/dist/client/apis/GltfApi.js +96 -0
  41. package/dist/client/apis/GltfApi.js.map +1 -0
  42. package/dist/client/apis/LogApi.d.ts +13 -0
  43. package/dist/client/apis/LogApi.d.ts.map +1 -0
  44. package/dist/client/apis/LogApi.js +93 -0
  45. package/dist/client/apis/LogApi.js.map +1 -0
  46. package/dist/client/apis/ModelApi.d.ts +129 -0
  47. package/dist/client/apis/ModelApi.d.ts.map +1 -0
  48. package/dist/client/apis/ModelApi.js +762 -0
  49. package/dist/client/apis/ModelApi.js.map +1 -0
  50. package/dist/client/apis/ModelStateApi.d.ts +57 -0
  51. package/dist/client/apis/ModelStateApi.d.ts.map +1 -0
  52. package/dist/client/apis/ModelStateApi.js +328 -0
  53. package/dist/client/apis/ModelStateApi.js.map +1 -0
  54. package/dist/client/apis/OutputApi.d.ts +38 -0
  55. package/dist/client/apis/OutputApi.d.ts.map +1 -0
  56. package/dist/client/apis/OutputApi.js +230 -0
  57. package/dist/client/apis/OutputApi.js.map +1 -0
  58. package/dist/client/apis/ScriptApi.d.ts +17 -0
  59. package/dist/client/apis/ScriptApi.d.ts.map +1 -0
  60. package/dist/client/apis/ScriptApi.js +127 -0
  61. package/dist/client/apis/ScriptApi.js.map +1 -0
  62. package/dist/client/apis/SdtfApi.d.ts +37 -0
  63. package/dist/client/apis/SdtfApi.d.ts.map +1 -0
  64. package/dist/client/apis/SdtfApi.js +227 -0
  65. package/dist/client/apis/SdtfApi.js.map +1 -0
  66. package/dist/client/apis/SessionApi.d.ts +51 -0
  67. package/dist/client/apis/SessionApi.d.ts.map +1 -0
  68. package/dist/client/apis/SessionApi.js +300 -0
  69. package/dist/client/apis/SessionApi.js.map +1 -0
  70. package/dist/client/apis/SystemApi.d.ts +28 -0
  71. package/dist/client/apis/SystemApi.d.ts.map +1 -0
  72. package/dist/client/apis/SystemApi.js +235 -0
  73. package/dist/client/apis/SystemApi.js.map +1 -0
  74. package/dist/client/apis/TextureApi.d.ts +13 -0
  75. package/dist/client/apis/TextureApi.d.ts.map +1 -0
  76. package/dist/client/apis/TextureApi.js +91 -0
  77. package/dist/client/apis/TextureApi.js.map +1 -0
  78. package/dist/client/apis/index.d.ts +18 -0
  79. package/dist/client/apis/index.d.ts.map +1 -0
  80. package/dist/client/apis/index.js +34 -0
  81. package/dist/client/apis/index.js.map +1 -0
  82. package/dist/client/index.d.ts +3 -2
  83. package/dist/client/index.d.ts.map +1 -1
  84. package/dist/client/index.js +3 -2
  85. package/dist/client/index.js.map +1 -1
  86. package/dist/client/models/index.d.ts +1671 -0
  87. package/dist/client/models/index.d.ts.map +1 -0
  88. package/dist/client/models/index.js +239 -0
  89. package/dist/client/models/index.js.map +1 -0
  90. package/dist/client/runtime.d.ts +154 -0
  91. package/dist/client/runtime.d.ts.map +1 -0
  92. package/dist/client/runtime.js +323 -0
  93. package/dist/client/runtime.js.map +1 -0
  94. package/dist/configuration.d.ts +2 -7
  95. package/dist/configuration.d.ts.map +1 -1
  96. package/dist/configuration.js +36 -16
  97. package/dist/configuration.js.map +1 -1
  98. package/dist/index.d.ts +2 -1
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +2 -1
  101. package/dist/index.js.map +1 -1
  102. package/dist/utils.d.ts +2 -3
  103. package/dist/utils.d.ts.map +1 -1
  104. package/dist/utils.js +16 -13
  105. package/dist/utils.js.map +1 -1
  106. package/package.json +3 -9
  107. package/src/UtilsApi.ts +252 -324
  108. package/src/base.ts +48 -46
  109. package/src/client/apis/AnalyticsApi.ts +347 -0
  110. package/src/client/apis/ArSceneApi.ts +172 -0
  111. package/src/client/apis/AssetsApi.ts +474 -0
  112. package/src/client/apis/AuthApi.ts +63 -0
  113. package/src/client/apis/AuthGroupApi.ts +89 -0
  114. package/src/client/apis/ExportApi.ts +332 -0
  115. package/src/client/apis/FileApi.ts +401 -0
  116. package/src/client/apis/GltfApi.ts +101 -0
  117. package/src/client/apis/LogApi.ts +96 -0
  118. package/src/client/apis/ModelApi.ts +1206 -0
  119. package/src/client/apis/ModelStateApi.ts +479 -0
  120. package/src/client/apis/OutputApi.ts +333 -0
  121. package/src/client/apis/ScriptApi.ts +142 -0
  122. package/src/client/apis/SdtfApi.ts +327 -0
  123. package/src/client/apis/SessionApi.ts +435 -0
  124. package/src/client/apis/SystemApi.ts +301 -0
  125. package/src/client/apis/TextureApi.ts +91 -0
  126. package/src/client/apis/index.ts +19 -0
  127. package/src/client/index.ts +3 -16
  128. package/src/client/models/index.ts +7367 -0
  129. package/src/client/runtime.ts +442 -0
  130. package/src/configuration.ts +62 -37
  131. package/src/error.ts +2 -2
  132. package/src/index.ts +2 -1
  133. package/src/utils.ts +53 -25
  134. package/dist/client/api.d.ts +0 -2111
  135. package/dist/client/api.d.ts.map +0 -1
  136. package/dist/client/api.js +0 -3576
  137. package/dist/client/api.js.map +0 -1
  138. package/dist/client/base.d.ts +0 -32
  139. package/dist/client/base.d.ts.map +0 -1
  140. package/dist/client/base.js +0 -37
  141. package/dist/client/base.js.map +0 -1
  142. package/dist/client/common.d.ts +0 -15
  143. package/dist/client/common.d.ts.map +0 -1
  144. package/dist/client/common.js +0 -117
  145. package/dist/client/common.js.map +0 -1
  146. package/dist/client/configuration.d.ts +0 -37
  147. package/dist/client/configuration.d.ts.map +0 -1
  148. package/dist/client/configuration.js +0 -23
  149. package/dist/client/configuration.js.map +0 -1
  150. package/src/client/api.ts +0 -11052
  151. package/src/client/base.ts +0 -62
  152. package/src/client/common.ts +0 -127
  153. package/src/client/configuration.ts +0 -121
package/src/UtilsApi.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { AxiosInstance, AxiosPromise, RawAxiosRequestConfig, RawAxiosRequestHeaders } from 'axios';
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
- createRequestFunction,
21
- serializeDataIfNeeded,
22
- setBearerAuthToObject,
23
- } from './client/common';
24
- import { IllegalArgumentError, ResponseError, TimeoutError } from './error';
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(configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
46
- super(configuration, basePath, axios);
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 {string} url The target URL of the upload request.
54
- * @param {*} data The data that should be uploaded.
55
- * @param {string} contentType Indicate the original media type of the resource.
56
- * @param {string} [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.
57
- * @param {*} [options] Override http request option.
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?: RawAxiosRequestConfig
65
- ): AxiosPromise<any> {
65
+ options: RequestInit = {}
66
+ ): Promise<Response> {
66
67
  // Prepare headers for the upload.
67
- const reqHeaders: RawAxiosRequestHeaders = {
68
- Authorization: undefined, // Disable by default to avoid accidental token exposure.
69
- 'Content-Type': contentType,
70
- /* Override custom ShapeDiver headers to avoid CORS issues. */
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 reqOptions: RawAxiosRequestConfig = { ...options };
80
- reqOptions.headers = { ...reqHeaders, ...options?.headers };
73
+ const disableHeaders: DisableHeaders = [
74
+ 'Authorization', // Disable by default to avoid accidental token exposure.
81
75
 
82
- const request = this.buildRequest('PUT', url, data, reqOptions)();
83
- return request();
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 {string} url The target URL of the upload request.
91
- * @param {*} data The data that should be uploaded.
92
- * @param {ResAssetUploadHeaders} headers The headers object that was returned from the request-upload call.
93
- * @param {*} [options] Override http request option.
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?: RawAxiosRequestConfig
100
- ): AxiosPromise<any> {
100
+ options: RequestInit = {}
101
+ ): Promise<Response> {
101
102
  // Prepare headers for the upload.
102
- const reqHeaders: RawAxiosRequestHeaders = {
103
- Authorization: undefined, // Disable by default to avoid accidental token exposure.
104
- 'Content-Type': headers.contentType,
105
- /* Override custom ShapeDiver headers to avoid CORS issues. */
106
- 'X-ShapeDiver-Origin': undefined,
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 reqOptions: RawAxiosRequestConfig = { ...options };
116
- reqOptions.headers = { ...reqHeaders, ...options?.headers };
109
+ const disableHeaders: DisableHeaders = [
110
+ 'Authorization', // Disable by default to avoid accidental token exposure.
117
111
 
118
- const request = this.buildRequest('PUT', url, data, reqOptions)();
119
- return request();
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
- * You can set the response type using the `responseType` property in the `options` object.
126
- * @param {string} 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
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
- url: string,
133
- options: { responseType: 'arraybuffer' } & RawAxiosRequestConfig
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
- // Validate JSON responses when responseType is 'json'
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 {string} url The URL of the asset to download.
202
- * @param {*} [options] Override http request option.
203
- * @throws {IllegalArgumentError} in case the URL is not a valid ShapeDiver asset URL.
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: { responseType: 'arraybuffer' } & RawAxiosRequestConfig
208
- ): [AxiosPromise<ArrayBuffer>, 'export' | 'output' | 'texture'];
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) as any, type];
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 {string} sessionId The session ID.
238
- * @param {string} url The URL of the image to download.
239
- * @param {*} [options] Override http request option.
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: { responseType: 'arraybuffer' } & RawAxiosRequestConfig
245
- ): AxiosPromise<ArrayBuffer>;
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) as any;
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
- encodeURIComponent(url).replace(/%([0-9A-F]{2})/g, (_, p1) =>
274
- String.fromCharCode(parseInt(p1, 16))
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
- return new AssetsApi(this.configuration).downloadImage(
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
- localOptions
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 {string} sessionId The session ID.
290
- * @param {ReqCustomization} body The body of the customization request.
291
- * @param {number} [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
292
- * @param {boolean} [ignoreUnknownParams=false] Allow relaxed validation of parameter
293
- * identifiers. When set to `true`, unrecognized parameters will be ignored rather than causing
294
- * an error. Defaults to `false`.
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?: RawAxiosRequestConfig
227
+ options?: RequestInit
304
228
  ): Promise<ResComputeOutputs> {
305
229
  const startMsec = Date.now();
306
- const dto = (
307
- await new OutputApi(this.configuration).computeOutputs(
308
- sessionId,
309
- body,
310
- ignoreUnknownParams,
311
- options
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 {string} sessionId The session ID.
325
- * @param {ReqExport} body The body of the export request.
326
- * @param {number} [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
327
- * @param {boolean} [ignoreUnknownParams=false] Allow relaxed validation of parameter
328
- * identifiers. When set to `true`, unrecognized parameters will be ignored rather than causing
329
- * an error. Defaults to `false`.
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?: RawAxiosRequestConfig
258
+ options?: RequestInit
339
259
  ): Promise<ResComputeExports> {
340
260
  const startMsec = Date.now();
341
- const dto = (
342
- await new ExportApi(this.configuration).computeExports(
343
- sessionId,
344
- body,
345
- ignoreUnknownParams,
346
- options
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 {string} sessionId The session ID.
360
- * @param {ResComputeOutputs} dto The DTO resulting from a customization request.
361
- * @param {number} [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
362
- * @param {*} [options] Override http request option.
363
- * @throws {TimeoutError} in case a maximum duration has been specified and is exceeded.
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?: RawAxiosRequestConfig
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
- await new OutputApi(this.configuration).getCachedOutputs(
399
- sessionId,
400
- outputVersions,
401
- options
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 {string} sessionId The session ID.
413
- * @param {ReqExport} body The body of the export request.
414
- * @param {ResComputeExports} dto The DTO resulting from an export request.
415
- * @param {number} [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
416
- * @param {*} [options] Override http request option.
417
- * @throws {TimeoutError} in case a maximum duration has been specified and is exceeded.
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?: RawAxiosRequestConfig
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 {ResComputeOutputs | ResGetCachedOutputs} dto The DTO resulting from a customization request.
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 {ResComputeExports | ResGetCachedExports} dto The DTO resulting from an export request.
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
- * Builds an Axios request from the given configuration, the API's base configuration, and the
491
- * optional http request option.
492
- * @param {string} method The HTTP method to use.
493
- * @param {string} url The URL to send the request to.
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: any,
501
- options: RawAxiosRequestConfig = {}
502
- ) {
503
- return (basePath: string = '') => {
504
- const baseOptions = this.configuration?.baseOptions ?? {};
505
- const baseHeaders = baseOptions && baseOptions.headers ? baseOptions.headers : {};
506
-
507
- const reqOptions = { method, ...baseOptions, ...options };
508
- reqOptions.headers = { ...baseHeaders, ...options.headers };
509
- if (!reqOptions.data && data) {
510
- // Create a new configuration object if necessary to enable mime type detection
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
- // Remove the base path configuration if the URL is a full URL.
517
- const configuration =
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
- const axiosArgs: RequestArgs = { url, options: reqOptions };
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
- * Builds the Axios request options by merging the API's base configuration with the given
531
- * options, and conditionally setting or overrides the Authorization header.
532
- *
533
- * The authorization header is set, when the URL is targeting the same server as the one
534
- * specified in the API's base path configuration, or if it is a ShapeDiver no-CDN server. In
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
- options: RawAxiosRequestConfig
543
- ): Promise<RawAxiosRequestConfig> {
544
- let baseOptions;
545
- if (this.configuration) baseOptions = this.configuration.baseOptions;
546
-
547
- const localRequestOptions = { ...baseOptions, ...options },
548
- localHeaderParameter = {} as any;
549
-
550
- if (this.isTargetingInternalOrNoCdnServer(url))
551
- await setBearerAuthToObject(localHeaderParameter, this.configuration);
552
-
553
- let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
554
- localRequestOptions.headers = {
555
- ...localHeaderParameter,
556
- ...headersFromBaseOptions,
557
- ...options.headers,
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
- return localRequestOptions;
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(url: string, options: RawAxiosRequestConfig): void {
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 (options.headers?.Authorization) return;
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(url);
554
+ targetUrl = new URL(fetchUrl);
627
555
  } catch {
628
556
  return;
629
557
  }
630
558
 
631
- if (directDownloadUri.test(targetUrl.origin) || cdnAssetUri.test(url))
632
- options.headers = { Authorization: undefined, ...options.headers };
559
+ if (directDownloadUri.test(targetUrl.origin) || cdnAssetUri.test(targetUrl.pathname))
560
+ disableHeaders.push('Authorization');
633
561
  }
634
562
  }