@shapediver/sdk.geometry-api-sdk-v2 2.0.1 → 2.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.
- package/dist/UtilsApi.d.ts +20 -5
- package/dist/UtilsApi.d.ts.map +1 -1
- package/dist/UtilsApi.js +4 -1
- package/dist/UtilsApi.js.map +1 -1
- package/dist/base.d.ts +9 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +56 -0
- package/dist/base.js.map +1 -0
- package/dist/client/api.d.ts +1 -1
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +18 -17
- package/dist/client/api.js.map +1 -1
- package/dist/configuration.d.ts +8 -2
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js +6 -4
- package/dist/configuration.js.map +1 -1
- package/package.json +1 -1
- package/src/UtilsApi.ts +53 -10
- package/src/base.ts +75 -0
- package/src/client/api.ts +2 -1
- package/src/configuration.ts +35 -2
package/dist/configuration.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { RawAxiosRequestConfig } from 'axios';
|
|
1
2
|
import { Configuration as ClientConfig, ConfigurationParameters as ClientConfigParams } from './client/configuration';
|
|
2
|
-
export interface ConfigurationParameters extends ClientConfigParams {
|
|
3
|
+
export interface ConfigurationParameters extends Pick<ClientConfigParams, 'accessToken' | 'basePath'> {
|
|
4
|
+
baseOptions?: RawAxiosRequestConfig;
|
|
5
|
+
useCustomAxios?: boolean;
|
|
6
|
+
maxRetries?: number;
|
|
3
7
|
}
|
|
4
8
|
export declare class Configuration extends ClientConfig {
|
|
5
|
-
protected readonly sdkVersion = "2.0
|
|
9
|
+
protected readonly sdkVersion = "2.1.0";
|
|
10
|
+
readonly useCustomAxios: boolean;
|
|
11
|
+
readonly maxRetries: number;
|
|
6
12
|
constructor(param?: ConfigurationParameters);
|
|
7
13
|
}
|
|
8
14
|
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,IAAI,YAAY,EAC7B,uBAAuB,IAAI,kBAAkB,EAChD,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EACH,aAAa,IAAI,YAAY,EAC7B,uBAAuB,IAAI,kBAAkB,EAChD,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,uBACb,SAAQ,IAAI,CAAC,kBAAkB,EAAE,aAAa,GAAG,UAAU,CAAC;IAO5D,WAAW,CAAC,EAAE,qBAAqB,CAAC;IASpC,cAAc,CAAC,EAAE,OAAO,CAAC;IASzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC3C,SAAS,CAAC,QAAQ,CAAC,UAAU,WAAW;IAExC,SAAgB,cAAc,EAAE,OAAO,CAAC;IACxC,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,KAAK,GAAE,uBAA4B;CAkBlD"}
|
package/dist/configuration.js
CHANGED
|
@@ -4,11 +4,13 @@ exports.Configuration = void 0;
|
|
|
4
4
|
const configuration_1 = require("./client/configuration");
|
|
5
5
|
class Configuration extends configuration_1.Configuration {
|
|
6
6
|
constructor(param = {}) {
|
|
7
|
-
var _a, _b;
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
8
|
super(param);
|
|
9
|
-
this.sdkVersion = '2.0
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
9
|
+
this.sdkVersion = '2.1.0';
|
|
10
|
+
this.useCustomAxios = (_a = param.useCustomAxios) !== null && _a !== void 0 ? _a : true;
|
|
11
|
+
this.maxRetries = (_b = param.maxRetries) !== null && _b !== void 0 ? _b : 5;
|
|
12
|
+
this.baseOptions = (_c = this.baseOptions) !== null && _c !== void 0 ? _c : {};
|
|
13
|
+
this.baseOptions.headers = (_d = this.baseOptions.headers) !== null && _d !== void 0 ? _d : {};
|
|
12
14
|
const userAgent = `sd-sdk/typescript/${this.sdkVersion}`;
|
|
13
15
|
if (typeof process === 'object' && !this.baseOptions.headers['User-Agent']) {
|
|
14
16
|
this.baseOptions.headers['User-Agent'] = userAgent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;AACA,0DAGgC;AA+BhC,MAAa,aAAc,SAAQ,6BAAY;IAM3C,YAAY,QAAiC,EAAE;;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC;QANE,eAAU,GAAG,OAAO,CAAC;QAOpC,IAAI,CAAC,cAAc,GAAG,MAAA,KAAK,CAAC,cAAc,mCAAI,IAAI,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,MAAA,KAAK,CAAC,UAAU,mCAAI,CAAC,CAAC;QAExC,IAAI,CAAC,WAAW,GAAG,MAAA,IAAI,CAAC,WAAW,mCAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,OAAO,GAAG,MAAA,IAAI,CAAC,WAAW,CAAC,OAAO,mCAAI,EAAE,CAAC;QAE1D,MAAM,SAAS,GAAG,qBAAqB,IAAI,CAAC,UAAU,EAAE,CAAC;QAEzD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YAEzE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;QACvD,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAE7D,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;QACnE,CAAC;IACL,CAAC;CACJ;AAxBD,sCAwBC"}
|
package/package.json
CHANGED
package/src/UtilsApi.ts
CHANGED
|
@@ -42,14 +42,14 @@ export class UtilsApi extends BaseAPI {
|
|
|
42
42
|
/**
|
|
43
43
|
* Upload the given file to the specified URL.
|
|
44
44
|
* @param {string} url The target URL of the upload request.
|
|
45
|
-
* @param {
|
|
45
|
+
* @param {*} data The data that should be uploaded.
|
|
46
46
|
* @param {string} contentType Indicate the original media type of the resource.
|
|
47
47
|
* @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.
|
|
48
48
|
* @param {*} [options] Override http request option.
|
|
49
49
|
*/
|
|
50
50
|
public upload(
|
|
51
51
|
url: string,
|
|
52
|
-
data:
|
|
52
|
+
data: any,
|
|
53
53
|
contentType: string,
|
|
54
54
|
filename?: string,
|
|
55
55
|
options?: RawAxiosRequestConfig
|
|
@@ -71,13 +71,13 @@ export class UtilsApi extends BaseAPI {
|
|
|
71
71
|
/**
|
|
72
72
|
* Upload the given asset to the specified ShapeDiver URL.
|
|
73
73
|
* @param {string} url The target URL of the upload request.
|
|
74
|
-
* @param {
|
|
74
|
+
* @param {*} data The data that should be uploaded.
|
|
75
75
|
* @param {ResAssetUploadHeaders} headers The headers object that was returned from the request-upload call.
|
|
76
76
|
* @param {*} [options] Override http request option.
|
|
77
77
|
*/
|
|
78
78
|
public uploadAsset(
|
|
79
79
|
url: string,
|
|
80
|
-
data:
|
|
80
|
+
data: any,
|
|
81
81
|
headers: ResAssetUploadHeaders,
|
|
82
82
|
options?: RawAxiosRequestConfig
|
|
83
83
|
): AxiosPromise<unknown> {
|
|
@@ -98,10 +98,25 @@ export class UtilsApi extends BaseAPI {
|
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Download from the specified URL.
|
|
101
|
+
*
|
|
102
|
+
* The response type can be controlled by setting the `responseType` in the `options` object.
|
|
101
103
|
* @param {string} url The target URL of the download request.
|
|
102
104
|
* @param {*} [options] Override http request option.
|
|
103
105
|
*/
|
|
104
|
-
public download(
|
|
106
|
+
public download(
|
|
107
|
+
url: string,
|
|
108
|
+
options: { responseType: 'arraybuffer' | 'blob' } & RawAxiosRequestConfig
|
|
109
|
+
): AxiosPromise<File>;
|
|
110
|
+
public download(
|
|
111
|
+
url: string,
|
|
112
|
+
options: { responseType: 'json' } & RawAxiosRequestConfig
|
|
113
|
+
): AxiosPromise<Record<string, unknown>>;
|
|
114
|
+
public download(
|
|
115
|
+
url: string,
|
|
116
|
+
options: { responseType: 'text' } & RawAxiosRequestConfig
|
|
117
|
+
): AxiosPromise<string>;
|
|
118
|
+
public download(url: string, options?: RawAxiosRequestConfig): AxiosPromise<unknown>;
|
|
119
|
+
public download(url: string, options?: RawAxiosRequestConfig): AxiosPromise<unknown> {
|
|
105
120
|
const request = this.buildRequest('GET', url, undefined, options)();
|
|
106
121
|
return request();
|
|
107
122
|
}
|
|
@@ -109,14 +124,24 @@ export class UtilsApi extends BaseAPI {
|
|
|
109
124
|
/**
|
|
110
125
|
* Downloads a ShapeDiver export, output, or texture asset from the specified URL. The type of
|
|
111
126
|
* the asset is determined by the URL and returned with the promise.
|
|
127
|
+
*
|
|
128
|
+
* The response type can be controlled by setting the `responseType` in the `options` object.
|
|
112
129
|
* @param {string} url The URL of the asset to download.
|
|
113
130
|
* @param {*} [options] Override http request option.
|
|
114
131
|
* @throws {IllegalArgumentError} in case the URL is not a valid ShapeDiver asset URL.
|
|
115
132
|
*/
|
|
133
|
+
public downloadAsset(
|
|
134
|
+
url: string,
|
|
135
|
+
options: { responseType: 'arraybuffer' | 'blob' } & RawAxiosRequestConfig
|
|
136
|
+
): [AxiosPromise<File>, 'export' | 'output' | 'texture'];
|
|
137
|
+
public downloadAsset(
|
|
138
|
+
url: string,
|
|
139
|
+
options?: RawAxiosRequestConfig
|
|
140
|
+
): [AxiosPromise<unknown>, 'export' | 'output' | 'texture'];
|
|
116
141
|
public downloadAsset(
|
|
117
142
|
url: string,
|
|
118
143
|
options?: RawAxiosRequestConfig
|
|
119
|
-
): [AxiosPromise<
|
|
144
|
+
): [AxiosPromise<unknown>, 'export' | 'output' | 'texture'] {
|
|
120
145
|
let type: 'output' | 'export' | 'texture';
|
|
121
146
|
this.disableAuthHeaderForShapeDiverUris(url, options);
|
|
122
147
|
|
|
@@ -130,21 +155,33 @@ export class UtilsApi extends BaseAPI {
|
|
|
130
155
|
);
|
|
131
156
|
}
|
|
132
157
|
|
|
133
|
-
return [this.download(url, options), type];
|
|
158
|
+
return [this.download(url, options) as any, type];
|
|
134
159
|
}
|
|
135
160
|
|
|
136
161
|
/**
|
|
137
162
|
* Helper function that downloads all ShapeDiver texture URLs directly, and redirects all other
|
|
138
163
|
* URLs to the `AssetsApi.downloadImage` endpoint to avoid CORS issues.
|
|
164
|
+
*
|
|
165
|
+
* The response type can be controlled by setting the `responseType` in the `options` object.
|
|
139
166
|
* @param {string} sessionId The session ID.
|
|
140
167
|
* @param {string} url The URL of the image to download.
|
|
141
168
|
* @param {*} [options] Override http request option.
|
|
142
169
|
*/
|
|
170
|
+
public downloadImage(
|
|
171
|
+
sessionId: string,
|
|
172
|
+
url: string,
|
|
173
|
+
options: { responseType: 'arraybuffer' | 'blob' } & RawAxiosRequestConfig
|
|
174
|
+
): AxiosPromise<File>;
|
|
143
175
|
public downloadImage(
|
|
144
176
|
sessionId: string,
|
|
145
177
|
url: string,
|
|
146
178
|
options?: RawAxiosRequestConfig
|
|
147
|
-
): AxiosPromise<
|
|
179
|
+
): AxiosPromise<unknown>;
|
|
180
|
+
public downloadImage(
|
|
181
|
+
sessionId: string,
|
|
182
|
+
url: string,
|
|
183
|
+
options?: RawAxiosRequestConfig
|
|
184
|
+
): AxiosPromise<unknown> {
|
|
148
185
|
this.disableAuthHeaderForShapeDiverUris(url, options);
|
|
149
186
|
|
|
150
187
|
if (
|
|
@@ -153,7 +190,7 @@ export class UtilsApi extends BaseAPI {
|
|
|
153
190
|
directDownloadUri.test(url)
|
|
154
191
|
) {
|
|
155
192
|
// Call ShapeDiver texture-asset URLs directly
|
|
156
|
-
return this.download(url, options);
|
|
193
|
+
return this.download(url, options) as any;
|
|
157
194
|
} else {
|
|
158
195
|
// All other source URLs are called via the download-image endpoint
|
|
159
196
|
return new AssetsApi(this.configuration).downloadImage(sessionId, url, options);
|
|
@@ -371,8 +408,14 @@ export class UtilsApi extends BaseAPI {
|
|
|
371
408
|
reqOptions.data = serializeDataIfNeeded(data, reqOptions, configuration);
|
|
372
409
|
}
|
|
373
410
|
|
|
411
|
+
// Remove the base path configuration if the URL is a full URL.
|
|
412
|
+
const configuration =
|
|
413
|
+
this.configuration && url.startsWith('http')
|
|
414
|
+
? new Configuration({ ...this.configuration, basePath: undefined })
|
|
415
|
+
: this.configuration;
|
|
416
|
+
|
|
374
417
|
const axiosArgs: RequestArgs = { url, options: reqOptions };
|
|
375
|
-
return createRequestFunction(axiosArgs, this.axios, basePath,
|
|
418
|
+
return createRequestFunction(axiosArgs, this.axios, basePath, configuration).bind(
|
|
376
419
|
this.axios
|
|
377
420
|
);
|
|
378
421
|
};
|
package/src/base.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Configuration as ClientConfig } from './client/configuration';
|
|
2
|
+
import { BaseAPI as ClientBaseAPI } from './client/base';
|
|
3
|
+
import { Configuration } from './configuration';
|
|
4
|
+
import globalAxios, { AxiosInstance } from 'axios';
|
|
5
|
+
|
|
6
|
+
/** Axios singleton instance used by all APIs by default. */
|
|
7
|
+
let AXIOS: AxiosInstance | undefined;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Overrides the `BaseAPI` class that is used by all resource APIs.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: The classes are swapped out in `client/base.ts` by a script during generation.
|
|
13
|
+
*
|
|
14
|
+
* Extensions:
|
|
15
|
+
* - Replace the global Axios instance with a custom instance.
|
|
16
|
+
* - Extend the Axios instance by an Interceptor to handle retries on 429 and 502 status codes.
|
|
17
|
+
*/
|
|
18
|
+
export class BaseAPI extends ClientBaseAPI {
|
|
19
|
+
// Exposed for testing purposes.
|
|
20
|
+
readonly defaultAxios: AxiosInstance | undefined;
|
|
21
|
+
|
|
22
|
+
constructor(config?: Configuration | ClientConfig, basePath?: string) {
|
|
23
|
+
let axios: AxiosInstance | undefined;
|
|
24
|
+
if (!config || !('useCustomAxios' in config) || config.useCustomAxios) {
|
|
25
|
+
if (AXIOS === undefined)
|
|
26
|
+
AXIOS = createCustomAxiosInstance((config as any)?.maxRetries);
|
|
27
|
+
axios = AXIOS;
|
|
28
|
+
}
|
|
29
|
+
super(config, basePath, axios);
|
|
30
|
+
this.defaultAxios = axios;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a custom Axios instance with a response interceptor to automatically retry requests on
|
|
36
|
+
* `429` and `502` status codes.
|
|
37
|
+
*
|
|
38
|
+
* @param {number} maxRetries - Maximum number of retry attempts before failing (default: 5).
|
|
39
|
+
* @returns A custom Axios instance with retry functionality.
|
|
40
|
+
*/
|
|
41
|
+
function createCustomAxiosInstance(maxRetries = 5): AxiosInstance {
|
|
42
|
+
const axios = globalAxios.create();
|
|
43
|
+
|
|
44
|
+
axios.interceptors.response.use(undefined, async (error) => {
|
|
45
|
+
const { config, response } = error;
|
|
46
|
+
|
|
47
|
+
// Exit early if no response or config is available
|
|
48
|
+
if (!response || !config) return Promise.reject(error);
|
|
49
|
+
|
|
50
|
+
// Check if retry limit is reached
|
|
51
|
+
config.retryCount = config.retryCount ?? 0;
|
|
52
|
+
if (config.retryCount >= maxRetries) return Promise.reject(error);
|
|
53
|
+
|
|
54
|
+
// Only retry for 429 or 502 status codes
|
|
55
|
+
if (response.status === 429 || response.status === 502) {
|
|
56
|
+
config.retryCount += 1;
|
|
57
|
+
|
|
58
|
+
const delay =
|
|
59
|
+
response.status === 429
|
|
60
|
+
? // use retry-after or default to 60s
|
|
61
|
+
(parseInt(response.headers['retry-after'], 10) || 60) * 1000
|
|
62
|
+
: // 1 second delay for 502 status
|
|
63
|
+
1000;
|
|
64
|
+
|
|
65
|
+
// Delay retry and send the request again
|
|
66
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
67
|
+
return axios.request(config);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Reject for all other error statuses
|
|
71
|
+
return Promise.reject(error);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return axios;
|
|
75
|
+
}
|
package/src/client/api.ts
CHANGED
|
@@ -21,7 +21,8 @@ import globalAxios from 'axios';
|
|
|
21
21
|
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
|
|
22
22
|
import type { RequestArgs } from './base';
|
|
23
23
|
// @ts-ignore
|
|
24
|
-
import { BASE_PATH, COLLECTION_FORMATS,
|
|
24
|
+
import { BASE_PATH, COLLECTION_FORMATS, RequiredError, operationServerMap } from './base';
|
|
25
|
+
import { BaseAPI } from '../base';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Reference to the s-type parameter asset to be used.
|
package/src/configuration.ts
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
|
+
import { RawAxiosRequestConfig } from 'axios';
|
|
1
2
|
import {
|
|
2
3
|
Configuration as ClientConfig,
|
|
3
4
|
ConfigurationParameters as ClientConfigParams,
|
|
4
5
|
} from './client/configuration';
|
|
5
6
|
|
|
6
|
-
export interface ConfigurationParameters
|
|
7
|
+
export interface ConfigurationParameters
|
|
8
|
+
extends Pick<ClientConfigParams, 'accessToken' | 'basePath'> {
|
|
9
|
+
/**
|
|
10
|
+
* Base options for Axios calls.
|
|
11
|
+
*
|
|
12
|
+
* @type {RawAxiosRequestConfig}
|
|
13
|
+
* @memberof ConfigurationParameters
|
|
14
|
+
*/
|
|
15
|
+
baseOptions?: RawAxiosRequestConfig;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Enables the use of a custom Axios instance for all API requests by default, instead of the
|
|
19
|
+
* global Axios instance. This custom instance includes additional functionality to
|
|
20
|
+
* automatically retry requests on `429` and `502` status codes.
|
|
21
|
+
*
|
|
22
|
+
* Default: `true`.
|
|
23
|
+
*/
|
|
24
|
+
useCustomAxios?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Specifies the maximum number of automatic HTTP retries for failed requests.
|
|
28
|
+
*
|
|
29
|
+
* **Note:** This setting is only applicable when using a custom Axios instance.
|
|
30
|
+
*
|
|
31
|
+
* Default: `5`
|
|
32
|
+
*/
|
|
33
|
+
maxRetries?: number;
|
|
34
|
+
}
|
|
7
35
|
|
|
8
36
|
export class Configuration extends ClientConfig {
|
|
9
|
-
protected readonly sdkVersion = '2.0
|
|
37
|
+
protected readonly sdkVersion = '2.1.0'; // WARNING: This value is updated automatically!
|
|
38
|
+
|
|
39
|
+
public readonly useCustomAxios: boolean;
|
|
40
|
+
public readonly maxRetries: number;
|
|
10
41
|
|
|
11
42
|
constructor(param: ConfigurationParameters = {}) {
|
|
12
43
|
super(param);
|
|
44
|
+
this.useCustomAxios = param.useCustomAxios ?? true;
|
|
45
|
+
this.maxRetries = param.maxRetries ?? 5;
|
|
13
46
|
|
|
14
47
|
this.baseOptions = this.baseOptions ?? {};
|
|
15
48
|
this.baseOptions.headers = this.baseOptions.headers ?? {};
|