@shapediver/sdk.geometry-api-sdk-v2 3.7.0 → 4.1.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 +19 -29
  3. package/dist/UtilsApi.d.ts.map +1 -1
  4. package/dist/UtilsApi.js +140 -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 +21 -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 +265 -318
  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 +31 -38
  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,90 @@ 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 and set response-type.
240
174
  */
241
175
  public downloadImage(
242
176
  sessionId: string,
243
177
  url: string,
244
- options: { responseType: 'arraybuffer' } & RawAxiosRequestConfig
245
- ): AxiosPromise<ArrayBuffer>;
178
+ options?: RequestInit
179
+ ): Promise<Blob>;
246
180
  public downloadImage(
247
181
  sessionId: string,
248
182
  url: string,
249
- options?: RawAxiosRequestConfig
250
- ): AxiosPromise<any>;
251
- public downloadImage(
183
+ options: RequestInit & { responseType: "arraybuffer" }
184
+ ): Promise<ArrayBuffer>;
185
+ public async downloadImage(
252
186
  sessionId: string,
253
187
  url: string,
254
- options?: RawAxiosRequestConfig
255
- ): AxiosPromise<any> {
188
+ options: RequestInit & { responseType?: 'arraybuffer' } = {}
189
+ ): Promise<Blob | ArrayBuffer> {
190
+ const responseType = options.responseType;
256
191
  if (
257
192
  apiAssetTextureUri.test(url) ||
258
193
  cdnAssetTextureUri.test(url) ||
259
194
  directDownloadUri.test(url)
260
195
  ) {
261
196
  // Call ShapeDiver texture-asset URLs directly
262
- return this.download(url, options) as any;
197
+ const response = await this.download(url, options);
198
+
199
+ return responseType === 'arraybuffer'
200
+ ? response.arrayBuffer()
201
+ : response.blob();
263
202
  } else {
264
203
  /* All other source URLs are called via the download-image endpoint */
265
204
 
266
- const localOptions: RawAxiosRequestConfig = options ?? {};
267
- this.disableAuthHeaderForShapeDiverUris(url, localOptions);
268
-
269
205
  // Use a universal base64 encoder for browser and Node.js environments
270
206
  const encodedUrl =
271
207
  typeof window !== 'undefined' && window.btoa
272
208
  ? window.btoa(
273
- encodeURIComponent(url).replace(/%([0-9A-F]{2})/g, (_, p1) =>
274
- String.fromCharCode(parseInt(p1, 16))
275
- )
276
- )
209
+ encodeURIComponent(url).replace(/%([0-9A-F]{2})/g, (_, p1) =>
210
+ String.fromCharCode(parseInt(p1, 16))
211
+ )
212
+ )
277
213
  : Buffer.from(url, 'utf-8').toString('base64');
278
214
 
279
- return new AssetsApi(this.configuration).downloadImage(
215
+ // Remove the authrization header from all configurations.
216
+ const config = new Configuration(this.configuration);
217
+ if (config.headers && config.headers['Authorization'])
218
+ delete config.headers!['Authrization'];
219
+
220
+ const image = await new AssetsApi(config).downloadImage(
280
221
  sessionId,
281
222
  encodedUrl,
282
- localOptions
223
+ options
283
224
  );
225
+
226
+ return responseType === 'arraybuffer'
227
+ ? await image.arrayBuffer()
228
+ : image;
284
229
  }
285
230
  }
286
231
 
287
232
  /**
288
233
  * 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.
234
+ * @param sessionId The session ID.
235
+ * @param body The body of the customization request.
236
+ * @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
237
+ * @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`.
238
+ * @param [options] Override http request option.
239
+ * @throws TimeoutError in case a maximum duration has been specified and is exceeded.
297
240
  */
298
241
  public async submitAndWaitForOutput(
299
242
  sessionId: string,
300
243
  body: ReqCustomization,
301
244
  maxWaitMsec = -1,
302
245
  ignoreUnknownParams?: boolean,
303
- options?: RawAxiosRequestConfig
246
+ options?: RequestInit
304
247
  ): Promise<ResComputeOutputs> {
305
248
  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;
249
+ const dto = await new OutputApi(this.configuration).computeOutputs(
250
+ sessionId,
251
+ body,
252
+ ignoreUnknownParams,
253
+ options
254
+ );
314
255
  const waitMsec = Date.now() - startMsec;
315
256
 
316
257
  // Reduce the total max waiting time by the amount the customization-request took
@@ -321,31 +262,27 @@ export class UtilsApi extends BaseAPI {
321
262
 
322
263
  /**
323
264
  * 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.
265
+ * @param sessionId The session ID.
266
+ * @param body The body of the export request.
267
+ * @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
268
+ * @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`.
269
+ * @param [options] Override http request option.
270
+ * @throws TimeoutError in case a maximum duration has been specified and is exceeded.
332
271
  */
333
272
  public async submitAndWaitForExport(
334
273
  sessionId: string,
335
274
  body: ReqExport,
336
275
  maxWaitMsec = -1,
337
276
  ignoreUnknownParams?: boolean,
338
- options?: RawAxiosRequestConfig
277
+ options?: RequestInit
339
278
  ): Promise<ResComputeExports> {
340
279
  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;
280
+ const dto = await new ExportApi(this.configuration).computeExports(
281
+ sessionId,
282
+ body,
283
+ ignoreUnknownParams,
284
+ options
285
+ );
349
286
  const waitMsec = Date.now() - startMsec;
350
287
 
351
288
  // Reduce the total max waiting time by the amount the compute-request took
@@ -356,17 +293,17 @@ export class UtilsApi extends BaseAPI {
356
293
 
357
294
  /**
358
295
  * 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.
296
+ * @param sessionId The session ID.
297
+ * @param dto The DTO resulting from a customization request.
298
+ * @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
299
+ * @param [options] Override http request option.
300
+ * @throws TimeoutError in case a maximum duration has been specified and is exceeded.
364
301
  */
365
302
  private async waitForOutputResult(
366
303
  sessionId: string,
367
304
  dto: ResComputeOutputs,
368
305
  maxWaitMsec: number,
369
- options?: RawAxiosRequestConfig
306
+ options?: RequestInit
370
307
  ): Promise<ResComputeOutputs> {
371
308
  if (!dto.outputs) return dto;
372
309
 
@@ -394,13 +331,11 @@ export class UtilsApi extends BaseAPI {
394
331
  await sleep(delay);
395
332
 
396
333
  // Send cache request
397
- dto = (
398
- await new OutputApi(this.configuration).getCachedOutputs(
399
- sessionId,
400
- outputVersions,
401
- options
402
- )
403
- ).data;
334
+ dto = await new OutputApi(this.configuration).getCachedOutputs(
335
+ sessionId,
336
+ outputVersions,
337
+ options
338
+ )
404
339
  delay = this.getMaxOutputDelay(dto);
405
340
  }
406
341
 
@@ -409,19 +344,19 @@ export class UtilsApi extends BaseAPI {
409
344
 
410
345
  /**
411
346
  * 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.
347
+ * @param sessionId The session ID.
348
+ * @param body The body of the export request.
349
+ * @param dto The DTO resulting from an export request.
350
+ * @param [maxWaitMsec=-1] Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
351
+ * @param [options] Override http request option.
352
+ * @throws TimeoutError in case a maximum duration has been specified and is exceeded.
418
353
  */
419
354
  private async waitForExportResult(
420
355
  sessionId: string,
421
356
  body: ReqExport,
422
357
  dto: ResComputeExports,
423
358
  maxWaitMsec: number,
424
- options?: RawAxiosRequestConfig
359
+ options?: RequestInit
425
360
  ): Promise<ResComputeExports> {
426
361
  let delay = this.getMaxExportDelay(body, dto);
427
362
  const startMsec = Date.now();
@@ -441,9 +376,7 @@ export class UtilsApi extends BaseAPI {
441
376
  await sleep(delay);
442
377
 
443
378
  // Send cache request
444
- dto = (
445
- await new ExportApi(this.configuration).getCachedExports(sessionId, body, options)
446
- ).data;
379
+ dto = await new ExportApi(this.configuration).getCachedExports(sessionId, body, options);
447
380
  delay = this.getMaxExportDelay(body, dto);
448
381
  }
449
382
 
@@ -452,7 +385,7 @@ export class UtilsApi extends BaseAPI {
452
385
 
453
386
  /**
454
387
  * Get the maximum delay that was reported for output versions.
455
- * @param {ResComputeOutputs | ResGetCachedOutputs} dto The DTO resulting from a customization request.
388
+ * @param dto The DTO resulting from a customization request.
456
389
  * @returns maximum delay, -1 in case no delay was reported
457
390
  */
458
391
  private getMaxOutputDelay(dto: ResComputeOutputs | ResGetCachedOutputs): number {
@@ -465,7 +398,7 @@ export class UtilsApi extends BaseAPI {
465
398
  /**
466
399
  * Get the maximum delay that was reported for the exports. If outputs have been reported as
467
400
  * well, their delay time is included too.
468
- * @param {ResComputeExports | ResGetCachedExports} dto The DTO resulting from an export request.
401
+ * @param dto The DTO resulting from an export request.
469
402
  * @returns delay, -1 in case no delay was reported
470
403
  */
471
404
  private getMaxExportDelay(
@@ -487,77 +420,121 @@ export class UtilsApi extends BaseAPI {
487
420
  }
488
421
 
489
422
  /**
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(
423
+ * Replacement for `runtime.BaseAPI.request`.
424
+ * Needed to call `createFetchParameters`.
425
+ */
426
+ private async fetchRequest(
498
427
  method: string,
499
428
  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
- }
429
+ data: unknown,
430
+ options: RequestInit = {},
431
+ disableHeaders: DisableHeaders = []
432
+ ): Promise<Response> {
433
+ const { url: requestUrl, init } = await this.createFetchParameters(
434
+ method,
435
+ url,
436
+ data,
437
+ options,
438
+ disableHeaders
439
+ );
515
440
 
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;
441
+ const response = await this.fetchApi(requestUrl, init);
442
+ if (response.ok) return response;
521
443
 
522
- const axiosArgs: RequestArgs = { url, options: reqOptions };
523
- return createRequestFunction(axiosArgs, this.axios, basePath, configuration).bind(
524
- this.axios
525
- );
526
- };
444
+ throw new ClientResponseError(response, 'Response returned an error code');
527
445
  }
528
446
 
529
447
  /**
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(
448
+ * Replacement for `runtime.BaseAPI.createFetchParams`.
449
+ * Needed to allow dynamic basePath handling and proper header manipulation.
450
+ */
451
+ private async createFetchParameters(
452
+ method: string,
541
453
  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,
454
+ data: unknown,
455
+ options: RequestInit,
456
+ disableHeaders: DisableHeaders
457
+ ): Promise<{ url: string; init: RequestInit }> {
458
+ const configuration = this.configuration ?? new Configuration();
459
+
460
+ // Add authorization if applicable.
461
+ const authHeaders: Record<string, string> = {};
462
+ if (
463
+ this.isTargetingInternalOrNoCdnServer(url) &&
464
+ this.configuration &&
465
+ this.configuration.accessToken
466
+ ) {
467
+ const token = this.configuration.accessToken;
468
+ const tokenString = await token("JwtAuth", []);
469
+
470
+ if (tokenString) authHeaders["Authorization"] = `Bearer ${tokenString}`;
471
+ }
472
+
473
+ const headers = new Headers(configuration.headers);
474
+ for (const source of [
475
+ authHeaders,
476
+ options.headers,
477
+ ]) {
478
+ if (!source) continue;
479
+ new Headers(source).forEach((value, name) => headers.set(name, value));
480
+ }
481
+
482
+ // Remove all disabled headers.
483
+ disableHeaders.forEach(header => headers.delete(header));
484
+
485
+ const init: RequestInit = {
486
+ ...options,
487
+ method,
488
+ headers,
489
+ body: this.serializeDataForFetch(data, headers),
490
+ };
491
+
492
+ return {
493
+ url: this.createFetchUrl(url),
494
+ init
558
495
  };
496
+ }
497
+
498
+ /** Prepends the base-path to `url` when the URL is relative. */
499
+ private createFetchUrl(url: string): string {
500
+ if (url.startsWith("http")) return url;
501
+
502
+ const basePath = this.configuration.basePath.replace(/\/+$/, "");
503
+ const path = url.replace(/^\/+/, "");
559
504
 
560
- return localRequestOptions;
505
+ return `${basePath}/${path}`;
506
+ }
507
+
508
+ /** Passes `BodyInit` types through, stringifies JSON bodies and throws for invalid types. */
509
+ private serializeDataForFetch(data: unknown, headers: Headers): BodyInit | undefined {
510
+ if (data === undefined || data === null) return undefined;
511
+
512
+ if (
513
+ typeof data === 'string' ||
514
+ data instanceof ArrayBuffer ||
515
+ ArrayBuffer.isView(data) ||
516
+ (typeof Blob !== 'undefined' && data instanceof Blob) ||
517
+ (typeof FormData !== 'undefined' && data instanceof FormData) ||
518
+ (typeof URLSearchParams !== 'undefined' && data instanceof URLSearchParams) ||
519
+ (typeof ReadableStream !== 'undefined' && data instanceof ReadableStream)
520
+ ) {
521
+ return data as BodyInit;
522
+ }
523
+
524
+ if (!this.isJsonMime(headers.get('content-type') ?? '')) {
525
+ throw new TypeError(
526
+ 'Request body must be a Fetch BodyInit value or use a JSON Content-Type.'
527
+ );
528
+ }
529
+
530
+ const body = JSON.stringify(data);
531
+
532
+ // JSON.stringify(undefined), functions, and symbols returns undefined.
533
+ if (body === undefined) {
534
+ throw new TypeError('Request body cannot be serialized as JSON.');
535
+ }
536
+
537
+ return body;
561
538
  }
562
539
 
563
540
  /**
@@ -578,57 +555,27 @@ export class UtilsApi extends BaseAPI {
578
555
  }
579
556
  }
580
557
 
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
558
  /** Disable the Authorization header for ShapeDiver URIs if not explicitly set. */
620
- private disableAuthHeaderForShapeDiverUris(url: string, options: RawAxiosRequestConfig): void {
559
+ private disableAuthHeaderForShapeDiverUris(
560
+ url: string,
561
+ options: RequestInit,
562
+ disableHeaders: DisableHeaders,
563
+ ): void {
564
+ const headers = new Headers(options.headers);
565
+
621
566
  // When an authorization header is set, it will override anything that is set later
622
- if (options.headers?.Authorization) return;
567
+ if (headers.has('Authorization')) return;
568
+
569
+ const fetchUrl = this.createFetchUrl(url);
623
570
 
624
571
  let targetUrl: URL;
625
572
  try {
626
- targetUrl = new URL(url);
573
+ targetUrl = new URL(fetchUrl);
627
574
  } catch {
628
575
  return;
629
576
  }
630
577
 
631
- if (directDownloadUri.test(targetUrl.origin) || cdnAssetUri.test(url))
632
- options.headers = { Authorization: undefined, ...options.headers };
578
+ if (directDownloadUri.test(targetUrl.origin) || cdnAssetUri.test(targetUrl.pathname))
579
+ disableHeaders.push('Authorization');
633
580
  }
634
581
  }