@shapediver/sdk.geometry-api-sdk-v2 1.8.3 → 1.9.1
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/ShapeDiverErrors.d.ts.map +1 -1
- package/dist/ShapeDiverErrors.js +1 -1
- package/dist/ShapeDiverErrors.js.map +1 -1
- package/dist/ShapeDiverSdk.d.ts.map +1 -1
- package/dist/ShapeDiverSdk.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/ShapeDiverAnalyticsApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverAnalyticsApi.js +3 -1
- package/dist/resources/ShapeDiverAnalyticsApi.js.map +1 -1
- package/dist/resources/ShapeDiverArSceneApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverArSceneApi.js.map +1 -1
- package/dist/resources/ShapeDiverAssetApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverAssetApi.js.map +1 -1
- package/dist/resources/ShapeDiverExportApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverExportApi.js.map +1 -1
- package/dist/resources/ShapeDiverFileApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverFileApi.js +4 -8
- package/dist/resources/ShapeDiverFileApi.js.map +1 -1
- package/dist/resources/ShapeDiverGltfApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverGltfApi.js +4 -1
- package/dist/resources/ShapeDiverGltfApi.js.map +1 -1
- package/dist/resources/ShapeDiverModelApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverModelApi.js +52 -15
- package/dist/resources/ShapeDiverModelApi.js.map +1 -1
- package/dist/resources/ShapeDiverOutputApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverOutputApi.js +12 -4
- package/dist/resources/ShapeDiverOutputApi.js.map +1 -1
- package/dist/resources/ShapeDiverSdtfApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverSdtfApi.js +9 -3
- package/dist/resources/ShapeDiverSdtfApi.js.map +1 -1
- package/dist/resources/ShapeDiverSessionApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverSessionApi.js +3 -1
- package/dist/resources/ShapeDiverSessionApi.js.map +1 -1
- package/dist/resources/ShapeDiverSystemApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverSystemApi.js +18 -6
- package/dist/resources/ShapeDiverSystemApi.js.map +1 -1
- package/dist/resources/ShapeDiverTextureApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverTextureApi.js +3 -1
- package/dist/resources/ShapeDiverTextureApi.js.map +1 -1
- package/dist/resources/ShapeDiverUtilsApi.d.ts +3 -5
- package/dist/resources/ShapeDiverUtilsApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverUtilsApi.js +32 -15
- package/dist/resources/ShapeDiverUtilsApi.js.map +1 -1
- package/dist/utils/utils.d.ts +3 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +35 -9
- package/dist/utils/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/ShapeDiverErrors.ts +24 -23
- package/src/ShapeDiverSdk.ts +110 -109
- package/src/index.ts +15 -16
- package/src/resources/ShapeDiverAnalyticsApi.ts +30 -18
- package/src/resources/ShapeDiverArSceneApi.ts +68 -69
- package/src/resources/ShapeDiverAssetApi.ts +207 -183
- package/src/resources/ShapeDiverExportApi.ts +92 -77
- package/src/resources/ShapeDiverFileApi.ts +127 -108
- package/src/resources/ShapeDiverGltfApi.ts +41 -30
- package/src/resources/ShapeDiverModelApi.ts +351 -240
- package/src/resources/ShapeDiverOutputApi.ts +92 -56
- package/src/resources/ShapeDiverSdtfApi.ts +88 -54
- package/src/resources/ShapeDiverSessionApi.ts +104 -82
- package/src/resources/ShapeDiverSystemApi.ts +106 -70
- package/src/resources/ShapeDiverTextureApi.ts +24 -18
- package/src/resources/ShapeDiverUtilsApi.ts +294 -231
- package/src/utils/utils.ts +100 -54
package/src/utils/utils.ts
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@shapediver/sdk.geometry-api-sdk-core"
|
|
7
|
-
import { ShapeDiverResponseError } from "../ShapeDiverErrors"
|
|
2
|
+
ShapeDiverError,
|
|
3
|
+
ShapeDiverErrorType,
|
|
4
|
+
ShapeDiverRequestError as ShapeDiverRequestErrorCore,
|
|
5
|
+
ShapeDiverResponseError as ShapeDiverResponseErrorCore,
|
|
6
|
+
} from "@shapediver/sdk.geometry-api-sdk-core";
|
|
7
|
+
import { ShapeDiverResponseError } from "../ShapeDiverErrors";
|
|
8
8
|
|
|
9
9
|
/** Type guard for all error types of the Geometry Backend SDK package. */
|
|
10
|
-
export function isGBError(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export function isGBError(
|
|
11
|
+
e: any,
|
|
12
|
+
): e is ShapeDiverError & ShapeDiverRequestErrorCore & ShapeDiverResponseError {
|
|
13
|
+
return (
|
|
14
|
+
e instanceof Error &&
|
|
15
|
+
"errorType" in e &&
|
|
16
|
+
Object.values(ShapeDiverErrorType).includes(e.errorType as any)
|
|
17
|
+
);
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
/** Type guard for a Geometry Backend SDK generic error. */
|
|
18
21
|
export function isGBGenericError(e: any): e is ShapeDiverError {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
return (
|
|
23
|
+
e instanceof Error &&
|
|
24
|
+
"errorType" in e &&
|
|
25
|
+
e.errorType === ShapeDiverErrorType.Generic
|
|
26
|
+
);
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/** Type guard for a Geometry Backend SDK request error. */
|
|
25
30
|
export function isGBRequestError(e: any): e is ShapeDiverRequestErrorCore {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
return (
|
|
32
|
+
e instanceof Error &&
|
|
33
|
+
"errorType" in e &&
|
|
34
|
+
e.errorType === ShapeDiverErrorType.Request
|
|
35
|
+
);
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/** Type guard for a Geometry Backend SDK response error. */
|
|
32
39
|
export function isGBResponseError(e: any): e is ShapeDiverResponseError {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
return (
|
|
41
|
+
e instanceof Error &&
|
|
42
|
+
"errorType" in e &&
|
|
43
|
+
e.errorType === ShapeDiverErrorType.Response
|
|
44
|
+
);
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
/**
|
|
@@ -40,50 +49,87 @@ export function isGBResponseError(e: any): e is ShapeDiverResponseError {
|
|
|
40
49
|
* the response error object to its typed representation.
|
|
41
50
|
*/
|
|
42
51
|
export async function sendRequest<T>(call: () => Promise<T>): Promise<T> {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
continue
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Error mapping
|
|
66
|
-
throw new ShapeDiverResponseError(e)
|
|
67
|
-
} else {
|
|
68
|
-
// Not a response error -> something went wrong
|
|
69
|
-
throw e
|
|
70
|
-
}
|
|
52
|
+
const retryLimit = 5;
|
|
53
|
+
let retryCounter = 0;
|
|
54
|
+
|
|
55
|
+
while (retryCounter < retryLimit) {
|
|
56
|
+
try {
|
|
57
|
+
return await call();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
retryCounter++;
|
|
60
|
+
|
|
61
|
+
if (e instanceof ShapeDiverResponseErrorCore) {
|
|
62
|
+
/* Check for special response statuses */
|
|
63
|
+
if (e.status === 429) {
|
|
64
|
+
// 429 Too Many Requests - Extract waiting time from Retry-After header if existing.
|
|
65
|
+
const seconds = e.headers["retry-after"] ?? 60; // default is 1 minute
|
|
66
|
+
await sleep(Number(seconds) * 1000);
|
|
67
|
+
continue;
|
|
68
|
+
} else if (e.status === 502) {
|
|
69
|
+
await sleep(1000); // 1 second
|
|
70
|
+
continue;
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
// Error mapping
|
|
74
|
+
throw new ShapeDiverResponseError(e);
|
|
75
|
+
} else {
|
|
76
|
+
// Not a response error -> something went wrong
|
|
77
|
+
throw e;
|
|
78
|
+
}
|
|
72
79
|
}
|
|
80
|
+
}
|
|
73
81
|
|
|
74
|
-
|
|
82
|
+
throw new ShapeDiverError("Could not send request: Retry-limit reached");
|
|
75
83
|
}
|
|
76
84
|
|
|
77
85
|
/** Delays the response for the given number of milliseconds */
|
|
78
86
|
export function sleep(ms: number): Promise<void> {
|
|
79
|
-
|
|
87
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
/** Encode the given string to base64 */
|
|
83
91
|
export function encodeBase64(str: string): string {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
try {
|
|
93
|
+
return btoa(str);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
return Buffer.from(str).toString("base64");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Set content headers according to RFC 5987 */
|
|
100
|
+
export function contentDispositionFromFilename(filename: string): string {
|
|
101
|
+
const asciiName = filename.replace(/[^\x00-\x7F]/g, "");
|
|
102
|
+
let header = `attachment; filename="${asciiName}"`;
|
|
103
|
+
|
|
104
|
+
if (filename.length !== asciiName.length) {
|
|
105
|
+
header += `; filename*=UTF-8''${encodeURIComponent(filename)}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return header;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Extract and return the filename from a content-disposition HTTP header. Decodes the filename*
|
|
113
|
+
* property if set.
|
|
114
|
+
*/
|
|
115
|
+
export function filenameFromContentDisposition(
|
|
116
|
+
contentDisposition: string,
|
|
117
|
+
): string | undefined {
|
|
118
|
+
let filename, filenameStar;
|
|
119
|
+
|
|
120
|
+
// Search for filename
|
|
121
|
+
const match = contentDisposition.match(/filename="([^"]+)"/);
|
|
122
|
+
if (match) filename = match[1];
|
|
123
|
+
|
|
124
|
+
// Search for filename*
|
|
125
|
+
const matchStar = contentDisposition.match(/filename\*=([^\'\']+\'\')?(.+)/);
|
|
126
|
+
if (matchStar) {
|
|
127
|
+
const encoding = matchStar[1] ? matchStar[1] : "utf-8";
|
|
128
|
+
const encodedName = matchStar[2] ?? matchStar[1];
|
|
129
|
+
if (encoding.toLowerCase().startsWith("utf-8")) {
|
|
130
|
+
filenameStar = decodeURIComponent(encodedName);
|
|
88
131
|
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return filenameStar ?? filename;
|
|
89
135
|
}
|