@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.
Files changed (67) hide show
  1. package/dist/ShapeDiverErrors.d.ts.map +1 -1
  2. package/dist/ShapeDiverErrors.js +1 -1
  3. package/dist/ShapeDiverErrors.js.map +1 -1
  4. package/dist/ShapeDiverSdk.d.ts.map +1 -1
  5. package/dist/ShapeDiverSdk.js.map +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/resources/ShapeDiverAnalyticsApi.d.ts.map +1 -1
  10. package/dist/resources/ShapeDiverAnalyticsApi.js +3 -1
  11. package/dist/resources/ShapeDiverAnalyticsApi.js.map +1 -1
  12. package/dist/resources/ShapeDiverArSceneApi.d.ts.map +1 -1
  13. package/dist/resources/ShapeDiverArSceneApi.js.map +1 -1
  14. package/dist/resources/ShapeDiverAssetApi.d.ts.map +1 -1
  15. package/dist/resources/ShapeDiverAssetApi.js.map +1 -1
  16. package/dist/resources/ShapeDiverExportApi.d.ts.map +1 -1
  17. package/dist/resources/ShapeDiverExportApi.js.map +1 -1
  18. package/dist/resources/ShapeDiverFileApi.d.ts.map +1 -1
  19. package/dist/resources/ShapeDiverFileApi.js +4 -8
  20. package/dist/resources/ShapeDiverFileApi.js.map +1 -1
  21. package/dist/resources/ShapeDiverGltfApi.d.ts.map +1 -1
  22. package/dist/resources/ShapeDiverGltfApi.js +4 -1
  23. package/dist/resources/ShapeDiverGltfApi.js.map +1 -1
  24. package/dist/resources/ShapeDiverModelApi.d.ts.map +1 -1
  25. package/dist/resources/ShapeDiverModelApi.js +52 -15
  26. package/dist/resources/ShapeDiverModelApi.js.map +1 -1
  27. package/dist/resources/ShapeDiverOutputApi.d.ts.map +1 -1
  28. package/dist/resources/ShapeDiverOutputApi.js +12 -4
  29. package/dist/resources/ShapeDiverOutputApi.js.map +1 -1
  30. package/dist/resources/ShapeDiverSdtfApi.d.ts.map +1 -1
  31. package/dist/resources/ShapeDiverSdtfApi.js +9 -3
  32. package/dist/resources/ShapeDiverSdtfApi.js.map +1 -1
  33. package/dist/resources/ShapeDiverSessionApi.d.ts.map +1 -1
  34. package/dist/resources/ShapeDiverSessionApi.js +3 -1
  35. package/dist/resources/ShapeDiverSessionApi.js.map +1 -1
  36. package/dist/resources/ShapeDiverSystemApi.d.ts.map +1 -1
  37. package/dist/resources/ShapeDiverSystemApi.js +18 -6
  38. package/dist/resources/ShapeDiverSystemApi.js.map +1 -1
  39. package/dist/resources/ShapeDiverTextureApi.d.ts.map +1 -1
  40. package/dist/resources/ShapeDiverTextureApi.js +3 -1
  41. package/dist/resources/ShapeDiverTextureApi.js.map +1 -1
  42. package/dist/resources/ShapeDiverUtilsApi.d.ts +3 -5
  43. package/dist/resources/ShapeDiverUtilsApi.d.ts.map +1 -1
  44. package/dist/resources/ShapeDiverUtilsApi.js +32 -15
  45. package/dist/resources/ShapeDiverUtilsApi.js.map +1 -1
  46. package/dist/utils/utils.d.ts +3 -1
  47. package/dist/utils/utils.d.ts.map +1 -1
  48. package/dist/utils/utils.js +35 -9
  49. package/dist/utils/utils.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/ShapeDiverErrors.ts +24 -23
  52. package/src/ShapeDiverSdk.ts +110 -109
  53. package/src/index.ts +15 -16
  54. package/src/resources/ShapeDiverAnalyticsApi.ts +30 -18
  55. package/src/resources/ShapeDiverArSceneApi.ts +68 -69
  56. package/src/resources/ShapeDiverAssetApi.ts +207 -183
  57. package/src/resources/ShapeDiverExportApi.ts +92 -77
  58. package/src/resources/ShapeDiverFileApi.ts +127 -108
  59. package/src/resources/ShapeDiverGltfApi.ts +41 -30
  60. package/src/resources/ShapeDiverModelApi.ts +351 -240
  61. package/src/resources/ShapeDiverOutputApi.ts +92 -56
  62. package/src/resources/ShapeDiverSdtfApi.ts +88 -54
  63. package/src/resources/ShapeDiverSessionApi.ts +104 -82
  64. package/src/resources/ShapeDiverSystemApi.ts +106 -70
  65. package/src/resources/ShapeDiverTextureApi.ts +24 -18
  66. package/src/resources/ShapeDiverUtilsApi.ts +294 -231
  67. package/src/utils/utils.ts +100 -54
@@ -1,38 +1,47 @@
1
1
  import {
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"
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(e: any): e is
11
- (ShapeDiverError & ShapeDiverRequestErrorCore & ShapeDiverResponseError) {
12
- return e instanceof Error &&
13
- "errorType" in e &&
14
- Object.values(ShapeDiverErrorType).includes(e.errorType as any)
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
- return e instanceof Error &&
20
- "errorType" in e &&
21
- e.errorType === ShapeDiverErrorType.Generic
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
- return e instanceof Error &&
27
- "errorType" in e &&
28
- e.errorType === ShapeDiverErrorType.Request
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
- return e instanceof Error &&
34
- "errorType" in e &&
35
- e.errorType === ShapeDiverErrorType.Response
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
- const retryLimit = 5
44
- let retryCounter = 0
45
-
46
- while (retryCounter < retryLimit) {
47
- try {
48
- return await call()
49
- } catch (e) {
50
- retryCounter++
51
-
52
- if (e instanceof ShapeDiverResponseErrorCore) {
53
- /* Check for special response statuses */
54
- if (e.status === 429) {
55
- // 429 Too Many Requests - Extract waiting time from Retry-After header if existing.
56
- const seconds = e.headers["retry-after"] ?? 60 // default is 1 minute
57
- await sleep(Number(seconds) * 1000)
58
- continue
59
-
60
- } else if (e.status === 502) {
61
- await sleep(1000) // 1 second
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
- throw new ShapeDiverError("Could not send request: Retry-limit reached")
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
- return new Promise(resolve => setTimeout(resolve, ms))
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
- try {
85
- return btoa(str)
86
- } catch (err) {
87
- return Buffer.from(str).toString("base64")
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
  }