@shapediver/sdk.geometry-api-sdk-v2 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -14
- 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/dist/error.d.ts +6 -6
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +12 -12
- package/dist/error.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +4 -4
- package/dist/utils.js.map +1 -1
- package/package.json +2 -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/src/error.ts +17 -17
- package/src/utils.ts +8 -9
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.2.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.2.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/dist/error.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { ResErrorType } from './client';
|
|
2
|
-
export declare class
|
|
3
|
-
constructor(message
|
|
2
|
+
export declare class SdGeometryError extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
4
|
}
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class RequestError extends SdGeometryError {
|
|
6
6
|
constructor(message: string);
|
|
7
7
|
}
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class ResponseError extends SdGeometryError {
|
|
9
9
|
readonly status: number;
|
|
10
10
|
readonly type: ResErrorType;
|
|
11
11
|
readonly description: string;
|
|
12
12
|
constructor(status: number, message: string, desc: string, type?: string);
|
|
13
13
|
}
|
|
14
|
-
export declare class IllegalArgumentError extends
|
|
14
|
+
export declare class IllegalArgumentError extends SdGeometryError {
|
|
15
15
|
field: string;
|
|
16
16
|
constructor(field: string, msg?: string);
|
|
17
17
|
}
|
|
18
|
-
export declare class TimeoutError extends
|
|
18
|
+
export declare class TimeoutError extends SdGeometryError {
|
|
19
19
|
field: string;
|
|
20
20
|
constructor(field: string, msg?: string);
|
|
21
21
|
}
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUxC,qBAAa,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUxC,qBAAa,eAAgB,SAAQ,KAAK;gBAC1B,OAAO,CAAC,EAAE,MAAM;CAI/B;AAUD,qBAAa,YAAa,SAAQ,eAAe;gBACjC,OAAO,EAAE,MAAM;CAI9B;AAWD,qBAAa,aAAc,SAAQ,eAAe;IAE9C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAG/B,SAAgB,IAAI,EAAE,YAAY,CAAC;IAGnC,SAAgB,WAAW,EAAE,MAAM,CAAC;gBAExB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAU3E;AAOD,qBAAa,oBAAqB,SAAQ,eAAe;IAE1C,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM;CAKnB;AAOD,qBAAa,YAAa,SAAQ,eAAe;IAElC,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM;CAKnB"}
|
package/dist/error.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TimeoutError = exports.IllegalArgumentError = exports.
|
|
3
|
+
exports.TimeoutError = exports.IllegalArgumentError = exports.ResponseError = exports.RequestError = exports.SdGeometryError = void 0;
|
|
4
4
|
const client_1 = require("./client");
|
|
5
|
-
class
|
|
5
|
+
class SdGeometryError extends Error {
|
|
6
6
|
constructor(message) {
|
|
7
7
|
super(message);
|
|
8
|
-
this.name = '
|
|
8
|
+
this.name = 'SdGeometryError';
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
12
|
-
class
|
|
11
|
+
exports.SdGeometryError = SdGeometryError;
|
|
12
|
+
class RequestError extends SdGeometryError {
|
|
13
13
|
constructor(message) {
|
|
14
14
|
super(message);
|
|
15
|
-
this.name = '
|
|
15
|
+
this.name = 'RequestError';
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
exports.
|
|
19
|
-
class
|
|
18
|
+
exports.RequestError = RequestError;
|
|
19
|
+
class ResponseError extends SdGeometryError {
|
|
20
20
|
constructor(status, message, desc, type) {
|
|
21
21
|
super(message);
|
|
22
|
-
this.name = '
|
|
22
|
+
this.name = 'ResponseError';
|
|
23
23
|
this.status = status;
|
|
24
24
|
this.description = desc;
|
|
25
25
|
this.type =
|
|
@@ -28,8 +28,8 @@ class SdResponseError extends Error {
|
|
|
28
28
|
: client_1.ResErrorType.UNKNOWN;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
exports.
|
|
32
|
-
class IllegalArgumentError extends
|
|
31
|
+
exports.ResponseError = ResponseError;
|
|
32
|
+
class IllegalArgumentError extends SdGeometryError {
|
|
33
33
|
constructor(field, msg) {
|
|
34
34
|
super(msg);
|
|
35
35
|
this.field = field;
|
|
@@ -37,7 +37,7 @@ class IllegalArgumentError extends Error {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.IllegalArgumentError = IllegalArgumentError;
|
|
40
|
-
class TimeoutError extends
|
|
40
|
+
class TimeoutError extends SdGeometryError {
|
|
41
41
|
constructor(field, msg) {
|
|
42
42
|
super(msg);
|
|
43
43
|
this.field = field;
|
package/dist/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAUxC,MAAa,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAUxC,MAAa,eAAgB,SAAQ,K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|
import { AxiosError, AxiosPromise } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { RequestError, ResponseError } from './error';
|
|
3
3
|
export declare function sleep(ms: number): Promise<void>;
|
|
4
4
|
export declare function extractFileInfo(headers: Record<string, any> | undefined): {
|
|
5
5
|
size: number | undefined;
|
|
@@ -8,5 +8,5 @@ export declare function extractFileInfo(headers: Record<string, any> | undefined
|
|
|
8
8
|
export declare function contentDispositionFromFilename(filename: string): string;
|
|
9
9
|
export declare function filenameFromContentDisposition(contentDisposition: string): string | undefined;
|
|
10
10
|
export declare function exists(apiCall: () => AxiosPromise<unknown>): Promise<boolean>;
|
|
11
|
-
export declare function processError(error: AxiosError | Error):
|
|
11
|
+
export declare function processError(error: AxiosError | Error): Error | RequestError | ResponseError;
|
|
12
12
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGtD,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAOD,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG;IACvE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAcA;AAOD,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWvE;AAQD,wBAAgB,8BAA8B,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAmB7F;AAUD,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnF;AAOD,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,YAAY,GAAG,aAAa,CAyB5F"}
|
package/dist/utils.js
CHANGED
|
@@ -77,17 +77,17 @@ function processError(error) {
|
|
|
77
77
|
typeof data.error === 'string' &&
|
|
78
78
|
'message' in data &&
|
|
79
79
|
typeof data.message === 'string') {
|
|
80
|
-
return new error_1.
|
|
80
|
+
return new error_1.ResponseError(status, data.message, data.desc, data.error);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
return new error_1.
|
|
83
|
+
return new error_1.ResponseError(status, err.message, 'No error description provided');
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
else if ('request' in error) {
|
|
87
|
-
return new error_1.
|
|
87
|
+
return new error_1.RequestError(error.message);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
return
|
|
90
|
+
return error;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,sBAEC;AAOD,0CAiBC;AAOD,wEAWC;AAQD,wEAmBC;AAUD,wBAOC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,sBAEC;AAOD,0CAiBC;AAOD,wEAWC;AAQD,wEAmBC;AAUD,wBAOC;AAOD,oCAyBC;AA3HD,mCAAsD;AAGtD,SAAgB,KA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OAAO,IAAI,IAAI;YACf,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YAC9B,SAAS,IAAI,IAAI;YACjB,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAClC,CAAC;YACC,OAAO,IAAI,qBAAa,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1E,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,qBAAa,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,+BAA+B,CAAC,CAAC;QACnF,CAAC;IACL,CAAC;SAAM,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QAC5B,OAAO,IAAI,oBAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACJ,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/sdk.geometry-api-sdk-v2",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "SDK to communicate with the Geometry API version 2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shapediver",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"axios": "~1.7.7"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"axios-mock-adapter": "~2.1.0",
|
|
49
50
|
"jest": "~29.7.0",
|
|
50
51
|
"lerna": "8.1.8",
|
|
51
52
|
"typescript": "~5.5.4",
|
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.2.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 ?? {};
|
package/src/error.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ResErrorType } from './client';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Represents a generic
|
|
4
|
+
* Represents a generic ShapeDiver error.
|
|
5
5
|
*
|
|
6
6
|
* Something happened in setting up the request that triggered an Error.
|
|
7
7
|
* @export
|
|
8
|
-
* @class
|
|
8
|
+
* @class SdGeometryError
|
|
9
9
|
* @extends {Error}
|
|
10
10
|
*/
|
|
11
|
-
export class
|
|
12
|
-
constructor(message
|
|
11
|
+
export class SdGeometryError extends Error {
|
|
12
|
+
constructor(message?: string) {
|
|
13
13
|
super(message);
|
|
14
|
-
this.name = '
|
|
14
|
+
this.name = 'SdGeometryError';
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -20,13 +20,13 @@ export class SdError extends Error {
|
|
|
20
20
|
*
|
|
21
21
|
* The request was made but no response was received.
|
|
22
22
|
* @export
|
|
23
|
-
* @class
|
|
24
|
-
* @extends {
|
|
23
|
+
* @class RequestError
|
|
24
|
+
* @extends {SdGeometryError}
|
|
25
25
|
*/
|
|
26
|
-
export class
|
|
26
|
+
export class RequestError extends SdGeometryError {
|
|
27
27
|
constructor(message: string) {
|
|
28
28
|
super(message);
|
|
29
|
-
this.name = '
|
|
29
|
+
this.name = 'RequestError';
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -36,10 +36,10 @@ export class SdRequestError extends Error {
|
|
|
36
36
|
* The request was made and the server responded with a status code that falls out of the range of
|
|
37
37
|
* 2xx.
|
|
38
38
|
* @export
|
|
39
|
-
* @class
|
|
40
|
-
* @extends {
|
|
39
|
+
* @class ResponseError
|
|
40
|
+
* @extends {SdGeometryError}
|
|
41
41
|
*/
|
|
42
|
-
export class
|
|
42
|
+
export class ResponseError extends SdGeometryError {
|
|
43
43
|
/** The HTTP status code from the server response. */
|
|
44
44
|
public readonly status: number;
|
|
45
45
|
|
|
@@ -51,7 +51,7 @@ export class SdResponseError extends Error {
|
|
|
51
51
|
|
|
52
52
|
constructor(status: number, message: string, desc: string, type?: string) {
|
|
53
53
|
super(message);
|
|
54
|
-
this.name = '
|
|
54
|
+
this.name = 'ResponseError';
|
|
55
55
|
this.status = status;
|
|
56
56
|
this.description = desc;
|
|
57
57
|
this.type =
|
|
@@ -64,9 +64,9 @@ export class SdResponseError extends Error {
|
|
|
64
64
|
/**
|
|
65
65
|
* @export
|
|
66
66
|
* @class IllegalArgumentError
|
|
67
|
-
* @extends {
|
|
67
|
+
* @extends {SdGeometryError}
|
|
68
68
|
*/
|
|
69
|
-
export class IllegalArgumentError extends
|
|
69
|
+
export class IllegalArgumentError extends SdGeometryError {
|
|
70
70
|
constructor(
|
|
71
71
|
public field: string,
|
|
72
72
|
msg?: string
|
|
@@ -79,9 +79,9 @@ export class IllegalArgumentError extends Error {
|
|
|
79
79
|
/**
|
|
80
80
|
* @export
|
|
81
81
|
* @class TimeoutError
|
|
82
|
-
* @extends {
|
|
82
|
+
* @extends {SdGeometryError}
|
|
83
83
|
*/
|
|
84
|
-
export class TimeoutError extends
|
|
84
|
+
export class TimeoutError extends SdGeometryError {
|
|
85
85
|
constructor(
|
|
86
86
|
public field: string,
|
|
87
87
|
msg?: string
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosError, AxiosPromise } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { RequestError, ResponseError } from './error';
|
|
3
3
|
|
|
4
4
|
/** Delays the response for the given number of milliseconds */
|
|
5
5
|
export function sleep(ms: number): Promise<void> {
|
|
@@ -93,12 +93,11 @@ export async function exists(apiCall: () => AxiosPromise<unknown>): Promise<bool
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* Tries to convert a generic Axios error into a more specific ShapeDiver error. When no match is
|
|
97
|
+
* found, the original error is returned instead.
|
|
97
98
|
* @param error The Axios error to convert.
|
|
98
99
|
*/
|
|
99
|
-
export function processError(
|
|
100
|
-
error: AxiosError | Error
|
|
101
|
-
): SdError | SdRequestError | SdResponseError {
|
|
100
|
+
export function processError(error: AxiosError | Error): Error | RequestError | ResponseError {
|
|
102
101
|
if ('response' in error) {
|
|
103
102
|
const err = error as AxiosError,
|
|
104
103
|
status = err.response!.status,
|
|
@@ -114,13 +113,13 @@ export function processError(
|
|
|
114
113
|
'message' in data &&
|
|
115
114
|
typeof data.message === 'string'
|
|
116
115
|
) {
|
|
117
|
-
return new
|
|
116
|
+
return new ResponseError(status, data.message, data.desc, data.error);
|
|
118
117
|
} else {
|
|
119
|
-
return new
|
|
118
|
+
return new ResponseError(status, err.message, 'No error description provided');
|
|
120
119
|
}
|
|
121
120
|
} else if ('request' in error) {
|
|
122
|
-
return new
|
|
121
|
+
return new RequestError(error.message);
|
|
123
122
|
} else {
|
|
124
|
-
return
|
|
123
|
+
return error;
|
|
125
124
|
}
|
|
126
125
|
}
|