@shapediver/sdk.geometry-api-sdk-v2 1.8.2 → 1.9.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 (68) 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 +2 -2
  6. package/dist/ShapeDiverSdk.js.map +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/resources/ShapeDiverAnalyticsApi.d.ts.map +1 -1
  11. package/dist/resources/ShapeDiverAnalyticsApi.js +3 -1
  12. package/dist/resources/ShapeDiverAnalyticsApi.js.map +1 -1
  13. package/dist/resources/ShapeDiverArSceneApi.d.ts.map +1 -1
  14. package/dist/resources/ShapeDiverArSceneApi.js.map +1 -1
  15. package/dist/resources/ShapeDiverAssetApi.d.ts.map +1 -1
  16. package/dist/resources/ShapeDiverAssetApi.js.map +1 -1
  17. package/dist/resources/ShapeDiverExportApi.d.ts.map +1 -1
  18. package/dist/resources/ShapeDiverExportApi.js.map +1 -1
  19. package/dist/resources/ShapeDiverFileApi.d.ts.map +1 -1
  20. package/dist/resources/ShapeDiverFileApi.js +10 -7
  21. package/dist/resources/ShapeDiverFileApi.js.map +1 -1
  22. package/dist/resources/ShapeDiverGltfApi.d.ts.map +1 -1
  23. package/dist/resources/ShapeDiverGltfApi.js +6 -3
  24. package/dist/resources/ShapeDiverGltfApi.js.map +1 -1
  25. package/dist/resources/ShapeDiverModelApi.d.ts.map +1 -1
  26. package/dist/resources/ShapeDiverModelApi.js +52 -15
  27. package/dist/resources/ShapeDiverModelApi.js.map +1 -1
  28. package/dist/resources/ShapeDiverOutputApi.d.ts.map +1 -1
  29. package/dist/resources/ShapeDiverOutputApi.js +12 -4
  30. package/dist/resources/ShapeDiverOutputApi.js.map +1 -1
  31. package/dist/resources/ShapeDiverSdtfApi.d.ts.map +1 -1
  32. package/dist/resources/ShapeDiverSdtfApi.js +9 -3
  33. package/dist/resources/ShapeDiverSdtfApi.js.map +1 -1
  34. package/dist/resources/ShapeDiverSessionApi.d.ts.map +1 -1
  35. package/dist/resources/ShapeDiverSessionApi.js +3 -1
  36. package/dist/resources/ShapeDiverSessionApi.js.map +1 -1
  37. package/dist/resources/ShapeDiverSystemApi.d.ts.map +1 -1
  38. package/dist/resources/ShapeDiverSystemApi.js +18 -6
  39. package/dist/resources/ShapeDiverSystemApi.js.map +1 -1
  40. package/dist/resources/ShapeDiverTextureApi.d.ts.map +1 -1
  41. package/dist/resources/ShapeDiverTextureApi.js +3 -1
  42. package/dist/resources/ShapeDiverTextureApi.js.map +1 -1
  43. package/dist/resources/ShapeDiverUtilsApi.d.ts +3 -5
  44. package/dist/resources/ShapeDiverUtilsApi.d.ts.map +1 -1
  45. package/dist/resources/ShapeDiverUtilsApi.js +39 -23
  46. package/dist/resources/ShapeDiverUtilsApi.js.map +1 -1
  47. package/dist/utils/utils.d.ts +1 -1
  48. package/dist/utils/utils.d.ts.map +1 -1
  49. package/dist/utils/utils.js +17 -18
  50. package/dist/utils/utils.js.map +1 -1
  51. package/package.json +11 -8
  52. package/src/ShapeDiverErrors.ts +34 -0
  53. package/src/ShapeDiverSdk.ts +114 -0
  54. package/src/index.ts +17 -0
  55. package/src/resources/ShapeDiverAnalyticsApi.ts +34 -0
  56. package/src/resources/ShapeDiverArSceneApi.ts +75 -0
  57. package/src/resources/ShapeDiverAssetApi.ts +213 -0
  58. package/src/resources/ShapeDiverExportApi.ts +100 -0
  59. package/src/resources/ShapeDiverFileApi.ts +151 -0
  60. package/src/resources/ShapeDiverGltfApi.ts +45 -0
  61. package/src/resources/ShapeDiverModelApi.ts +357 -0
  62. package/src/resources/ShapeDiverOutputApi.ts +100 -0
  63. package/src/resources/ShapeDiverSdtfApi.ts +95 -0
  64. package/src/resources/ShapeDiverSessionApi.ts +113 -0
  65. package/src/resources/ShapeDiverSystemApi.ts +116 -0
  66. package/src/resources/ShapeDiverTextureApi.ts +28 -0
  67. package/src/resources/ShapeDiverUtilsApi.ts +314 -0
  68. package/src/utils/utils.ts +97 -0
@@ -0,0 +1,114 @@
1
+ import {
2
+ BaseShapeDiverSdk,
3
+ ShapeDiverSdkConfigType,
4
+ } from "@shapediver/sdk.geometry-api-sdk-core";
5
+ import { ShapeDiverAnalyticsApi } from "./resources/ShapeDiverAnalyticsApi";
6
+ import { ShapeDiverArSceneApi } from "./resources/ShapeDiverArSceneApi";
7
+ import { ShapeDiverAssetApi } from "./resources/ShapeDiverAssetApi";
8
+ import { ShapeDiverExportApi } from "./resources/ShapeDiverExportApi";
9
+ import { ShapeDiverFileApi } from "./resources/ShapeDiverFileApi";
10
+ import { ShapeDiverGltfApi } from "./resources/ShapeDiverGltfApi";
11
+ import { ShapeDiverModelApi } from "./resources/ShapeDiverModelApi";
12
+ import { ShapeDiverOutputApi } from "./resources/ShapeDiverOutputApi";
13
+ import { ShapeDiverSdtfApi } from "./resources/ShapeDiverSdtfApi";
14
+ import { ShapeDiverSessionApi } from "./resources/ShapeDiverSessionApi";
15
+ import { ShapeDiverSystemApi } from "./resources/ShapeDiverSystemApi";
16
+ import { ShapeDiverTextureApi } from "./resources/ShapeDiverTextureApi";
17
+ import { ShapeDiverUtilsApi } from "./resources/ShapeDiverUtilsApi";
18
+
19
+ export function create(baseUrl: string, jwt?: string): ShapeDiverSdk {
20
+ return new ShapeDiverSdk(baseUrl, jwt);
21
+ }
22
+
23
+ export class ShapeDiverSdk extends BaseShapeDiverSdk {
24
+ private readonly _analytics: ShapeDiverAnalyticsApi;
25
+ private readonly _arScene: ShapeDiverArSceneApi;
26
+ private readonly _asset: ShapeDiverAssetApi;
27
+ private readonly _export: ShapeDiverExportApi;
28
+ private readonly _file: ShapeDiverFileApi;
29
+ private readonly _gltf: ShapeDiverGltfApi;
30
+ private readonly _model: ShapeDiverModelApi;
31
+ private readonly _output: ShapeDiverOutputApi;
32
+ private readonly _sdtf: ShapeDiverSdtfApi;
33
+ private readonly _session: ShapeDiverSessionApi;
34
+ private readonly _system: ShapeDiverSystemApi;
35
+ private readonly _texture: ShapeDiverTextureApi;
36
+ private readonly _utils: ShapeDiverUtilsApi;
37
+
38
+ /**
39
+ * ShapeDiverSDK constructor
40
+ *
41
+ * @param baseUrl - the URL of the target system
42
+ * @param jwt - the client's jwt
43
+ */
44
+ constructor(baseUrl: string, jwt?: string) {
45
+ super(baseUrl);
46
+ if (jwt) this.setConfigurationValue(ShapeDiverSdkConfigType.JWT_TOKEN, jwt);
47
+
48
+ this._analytics = new ShapeDiverAnalyticsApi(this.sdkApi);
49
+ this._arScene = new ShapeDiverArSceneApi(this.sdkApi);
50
+ this._asset = new ShapeDiverAssetApi(this.sdkApi);
51
+ this._export = new ShapeDiverExportApi(this.sdkApi);
52
+ this._file = new ShapeDiverFileApi(this.sdkApi);
53
+ this._gltf = new ShapeDiverGltfApi(this.sdkApi);
54
+ this._model = new ShapeDiverModelApi(this.sdkApi);
55
+ this._output = new ShapeDiverOutputApi(this.sdkApi);
56
+ this._sdtf = new ShapeDiverSdtfApi(this.sdkApi);
57
+ this._session = new ShapeDiverSessionApi(this.sdkApi);
58
+ this._system = new ShapeDiverSystemApi(this.sdkApi);
59
+ this._texture = new ShapeDiverTextureApi(this.sdkApi);
60
+ this._utils = new ShapeDiverUtilsApi(this.sdkApi);
61
+ }
62
+
63
+ get analytics(): ShapeDiverAnalyticsApi {
64
+ return this._analytics;
65
+ }
66
+
67
+ get arScene(): ShapeDiverArSceneApi {
68
+ return this._arScene;
69
+ }
70
+
71
+ get asset(): ShapeDiverAssetApi {
72
+ return this._asset;
73
+ }
74
+
75
+ get export(): ShapeDiverExportApi {
76
+ return this._export;
77
+ }
78
+
79
+ get file(): ShapeDiverFileApi {
80
+ return this._file;
81
+ }
82
+
83
+ get gltf(): ShapeDiverGltfApi {
84
+ return this._gltf;
85
+ }
86
+
87
+ get model(): ShapeDiverModelApi {
88
+ return this._model;
89
+ }
90
+
91
+ get output(): ShapeDiverOutputApi {
92
+ return this._output;
93
+ }
94
+
95
+ get sdtf(): ShapeDiverSdtfApi {
96
+ return this._sdtf;
97
+ }
98
+
99
+ get session(): ShapeDiverSessionApi {
100
+ return this._session;
101
+ }
102
+
103
+ get system(): ShapeDiverSystemApi {
104
+ return this._system;
105
+ }
106
+
107
+ get texture(): ShapeDiverTextureApi {
108
+ return this._texture;
109
+ }
110
+
111
+ get utils(): ShapeDiverUtilsApi {
112
+ return this._utils;
113
+ }
114
+ }
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ export * from "@shapediver/api.geometry-api-dto-v2";
2
+ export {
3
+ ShapeDiverError,
4
+ ShapeDiverRequestError,
5
+ ShapeDiverSdkApiResponseType,
6
+ ShapeDiverSdkConfig,
7
+ ShapeDiverSdkConfigType,
8
+ } from "@shapediver/sdk.geometry-api-sdk-core";
9
+ export { ShapeDiverResponseError } from "./ShapeDiverErrors";
10
+ export { ShapeDiverSdk, create } from "./ShapeDiverSdk";
11
+ export { ShapeDiverResponseFileInfo } from "./resources/ShapeDiverFileApi";
12
+ export {
13
+ isGBError,
14
+ isGBGenericError,
15
+ isGBRequestError,
16
+ isGBResponseError,
17
+ } from "./utils/utils";
@@ -0,0 +1,34 @@
1
+ import {
2
+ ShapeDiverRequestAnalyticsModel,
3
+ ShapeDiverResponseDto,
4
+ } from "@shapediver/api.geometry-api-dto-v2";
5
+ import {
6
+ BaseResourceApi,
7
+ ShapeDiverSdkApi,
8
+ } from "@shapediver/sdk.geometry-api-sdk-core";
9
+ import { sendRequest } from "../utils/utils";
10
+
11
+ export class ShapeDiverAnalyticsApi extends BaseResourceApi {
12
+ constructor(api: ShapeDiverSdkApi) {
13
+ super(api);
14
+ }
15
+
16
+ /**
17
+ * Get model session analytics.
18
+ *
19
+ * @param body
20
+ */
21
+ async modelSessionStatistics(
22
+ body: ShapeDiverRequestAnalyticsModel,
23
+ ): Promise<ShapeDiverResponseDto> {
24
+ return await sendRequest(
25
+ async () =>
26
+ (
27
+ await this.api.put<ShapeDiverResponseDto>(
28
+ this.buildAnalyticsUri() + "/session/model",
29
+ body,
30
+ )
31
+ )[1],
32
+ );
33
+ }
34
+ }
@@ -0,0 +1,75 @@
1
+ import {
2
+ BaseResourceApi,
3
+ ShapeDiverResponseError,
4
+ ShapeDiverSdkApi,
5
+ ShapeDiverSdkApiResponseType,
6
+ } from "@shapediver/sdk.geometry-api-sdk-core";
7
+ import { sendRequest } from "../utils/utils";
8
+
9
+ export class ShapeDiverArSceneApi extends BaseResourceApi {
10
+ constructor(api: ShapeDiverSdkApi) {
11
+ super(api);
12
+ }
13
+
14
+ /**
15
+ * Checks the existence of the specific AR scene.
16
+ * @param sceneId
17
+ * @returns `true` when the AR scene exists, otherwise `false`.
18
+ */
19
+ async exists(sceneId: string): Promise<boolean> {
20
+ return await sendRequest(async () => {
21
+ try {
22
+ const [_, status] = await this.api.head(
23
+ `${this.buildArSceneUri()}/${sceneId}`,
24
+ { disableAuthorization: true },
25
+ );
26
+ return status === 200;
27
+ } catch (e) {
28
+ // A 404 HTTP status is returned when the AR scene was not found.
29
+ if (e instanceof ShapeDiverResponseError && e.status === 404)
30
+ return false;
31
+ else throw e;
32
+ }
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Download the glTF file of the specified AR scene.
38
+ *
39
+ * @param sceneId - The ID of the AR scene.
40
+ * @returns Array of size 2: [0] = content data, [1] = content type
41
+ */
42
+ async getGltf(sceneId: string): Promise<[ArrayBuffer, string]> {
43
+ return await sendRequest(async () => {
44
+ const [header, data] = await this.api.get<ArrayBuffer>(
45
+ `${this.buildArSceneUri()}/${sceneId}/gltf`,
46
+ {
47
+ responseType: ShapeDiverSdkApiResponseType.DATA,
48
+ disableAuthorization: true,
49
+ },
50
+ );
51
+ const contentType = header["Content-Type"] ?? header["content-type"];
52
+ return [data, contentType];
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Download the USDZ file of the specified AR scene.
58
+ *
59
+ * @param sceneId - The ID of the AR scene.
60
+ * @returns Array of size 2: [0] = content data, [1] = content type
61
+ */
62
+ async getUsdz(sceneId: string): Promise<[ArrayBuffer, string]> {
63
+ return await sendRequest(async () => {
64
+ const [header, data] = await this.api.get<ArrayBuffer>(
65
+ `${this.buildArSceneUri()}/${sceneId}/usdz`,
66
+ {
67
+ responseType: ShapeDiverSdkApiResponseType.DATA,
68
+ disableAuthorization: true,
69
+ },
70
+ );
71
+ const contentType = header["Content-Type"] ?? header["content-type"];
72
+ return [data, contentType];
73
+ });
74
+ }
75
+ }
@@ -0,0 +1,213 @@
1
+ import {
2
+ BaseResourceApi,
3
+ ShapeDiverError,
4
+ ShapeDiverSdkApi,
5
+ ShapeDiverSdkApiResponseType,
6
+ } from "@shapediver/sdk.geometry-api-sdk-core";
7
+ import { encodeBase64, sendRequest } from "../utils/utils";
8
+
9
+ const apiAssetExportUri = /.+\/session\/.+\/export\/.+/;
10
+ const apiAssetOutputUri = /.+\/session\/.+\/output\/.+/;
11
+ const apiAssetTextureUri = /.+\/session\/.+\/texture\/.+/;
12
+
13
+ const cdnAssetUri = /.+\/cdn-asset-(exports|outputs|textures)\/.+/;
14
+ const cdnAssetExportUri = /.+\/cdn-asset-exports\/.+/;
15
+ const cdnAssetOutputUri = /.+\/cdn-asset-outputs\/.+/;
16
+ const cdnAssetTextureUri = /.+\/cdn-asset-textures\/.+/;
17
+
18
+ export class ShapeDiverAssetApi extends BaseResourceApi {
19
+ constructor(api: ShapeDiverSdkApi) {
20
+ super(api);
21
+ }
22
+
23
+ /**
24
+ * Download an export.
25
+ *
26
+ * @param sessionId
27
+ * @param assetData
28
+ */
29
+ async getExport(
30
+ sessionId: string,
31
+ assetData: string,
32
+ ): Promise<[ArrayBuffer, string]> {
33
+ return await sendRequest(async () => {
34
+ const [header, data] = await this.api.get<ArrayBuffer>(
35
+ `${this.buildSessionUri(sessionId)}/export/${assetData}`,
36
+ { responseType: ShapeDiverSdkApiResponseType.DATA },
37
+ );
38
+ const contentType = header["Content-Type"] ?? header["content-type"];
39
+ return [data, contentType];
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Download an output.
45
+ *
46
+ * @param sessionId
47
+ * @param assetData
48
+ */
49
+ async getOutput(
50
+ sessionId: string,
51
+ assetData: string,
52
+ ): Promise<[ArrayBuffer, string]> {
53
+ return await sendRequest(async () => {
54
+ const [header, data] = await this.api.get<ArrayBuffer>(
55
+ `${this.buildSessionUri(sessionId)}/output/${assetData}`,
56
+ { responseType: ShapeDiverSdkApiResponseType.DATA },
57
+ );
58
+ const contentType = header["Content-Type"] ?? header["content-type"];
59
+ return [data, contentType];
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Downloads the JSON content part of a sdTF output.
65
+ *
66
+ * @param sessionId
67
+ * @param assetData
68
+ */
69
+ async getSdtfJsonContent(
70
+ sessionId: string,
71
+ assetData: string,
72
+ ): Promise<Record<string, any>> {
73
+ return await sendRequest(
74
+ async () =>
75
+ (
76
+ await this.api.get<ArrayBuffer>(
77
+ `${this.buildSessionUri(sessionId)}/output/${assetData}`,
78
+ {
79
+ responseType: ShapeDiverSdkApiResponseType.JSON,
80
+ accept: "model/vnd.sdtf+json",
81
+ },
82
+ )
83
+ )[1],
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Download a texture file.
89
+ *
90
+ * @param sessionId
91
+ * @param assetData
92
+ */
93
+ async getTexture(
94
+ sessionId: string,
95
+ assetData: string,
96
+ ): Promise<[ArrayBuffer, string]> {
97
+ return await sendRequest(async () => {
98
+ const [header, data] = await this.api.get<ArrayBuffer>(
99
+ `${this.buildSessionUri(sessionId)}/texture/${assetData}`,
100
+ { responseType: ShapeDiverSdkApiResponseType.DATA },
101
+ );
102
+ const contentType = header["Content-Type"] ?? header["content-type"];
103
+ return [data, contentType];
104
+ });
105
+ }
106
+
107
+ /**
108
+ * Download a glTF file.
109
+ *
110
+ * @param sessionId
111
+ * @param assetData
112
+ */
113
+ async getGltf(sessionId: string, assetData: string): Promise<ArrayBuffer> {
114
+ return await sendRequest(
115
+ async () =>
116
+ (
117
+ await this.api.get<ArrayBuffer>(
118
+ `${this.buildSessionUri(sessionId)}/gltf/${assetData}`,
119
+ { responseType: ShapeDiverSdkApiResponseType.DATA },
120
+ )
121
+ )[1],
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Download a USDZ file.
127
+ *
128
+ * @param sessionId
129
+ * @param assetData
130
+ */
131
+ async getUsdz(sessionId: string, assetData: string): Promise<ArrayBuffer> {
132
+ return await sendRequest(
133
+ async () =>
134
+ (
135
+ await this.api.get<ArrayBuffer>(
136
+ `${this.buildSessionUri(sessionId)}/usdz/${assetData}`,
137
+ { responseType: ShapeDiverSdkApiResponseType.DATA },
138
+ )
139
+ )[1],
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Download an image.
145
+ *
146
+ * @param sessionId
147
+ * @param url - The URL of the image that should be downloaded.
148
+ * @returns Array of size 2: [0] = content data, [1] = content type.
149
+ */
150
+ async downloadImage(
151
+ sessionId: string,
152
+ url: string,
153
+ ): Promise<[ArrayBuffer, string]> {
154
+ let targetUrl: string;
155
+
156
+ if (apiAssetTextureUri.test(url) || cdnAssetTextureUri.test(url)) {
157
+ // Call ShapeDiver texture-asset URLs directly
158
+ targetUrl = url;
159
+ } else {
160
+ // All other source URLs are called via the download-image endpoint
161
+ targetUrl = `${this.buildSessionUri(sessionId)}/image?url=${encodeBase64(url)}`;
162
+ }
163
+
164
+ return await sendRequest(async () => {
165
+ const [header, data] = await this.api.get<ArrayBuffer>(targetUrl, {
166
+ responseType: ShapeDiverSdkApiResponseType.DATA,
167
+ disableAuthorization: cdnAssetUri.test(url), // disable for CDN URLs
168
+ });
169
+ const contentType = header["Content-Type"] ?? header["content-type"];
170
+ return [data, contentType];
171
+ });
172
+ }
173
+
174
+ /**
175
+ * Fetches a ShapeDiver asset of the following types:
176
+ * * Output
177
+ * * Export
178
+ * * Texture
179
+ *
180
+ * This function works similar to {@link getOutput}, {@link getExport} and {@link getTexture}, but does not require
181
+ * extracted _session ID_ and _asset data_ parameters.
182
+ *
183
+ * @param url - The URL of the asset that should be fetched.
184
+ * @returns Array of size 3: [0] = content data, [1] = content type, [2] = asset type.
185
+ * @throws {@link ShapeDiverError} when the given URL is not a valid ShapeDiver asset URL.
186
+ */
187
+ async getAsset(
188
+ url: string,
189
+ ): Promise<[ArrayBuffer, string, "output" | "export" | "texture"]> {
190
+ let type: "output" | "export" | "texture";
191
+
192
+ // Check if the given URL is a valid API or CDN asset URL
193
+ if (apiAssetExportUri.test(url) || cdnAssetExportUri.test(url))
194
+ type = "export";
195
+ else if (apiAssetOutputUri.test(url) || cdnAssetOutputUri.test(url))
196
+ type = "output";
197
+ else if (apiAssetTextureUri.test(url) || cdnAssetTextureUri.test(url))
198
+ type = "texture";
199
+ else
200
+ throw new ShapeDiverError(
201
+ "Cannot fetch asset: Invalid URL (only ShapeDiver asset URLs are allowed).",
202
+ );
203
+
204
+ return await sendRequest(async () => {
205
+ const [header, data] = await this.api.get<ArrayBuffer>(url, {
206
+ responseType: ShapeDiverSdkApiResponseType.DATA,
207
+ disableAuthorization: cdnAssetUri.test(url), // disable for CDN URLs
208
+ });
209
+ const contentType = header["Content-Type"] ?? header["content-type"];
210
+ return [data, contentType, type];
211
+ });
212
+ }
213
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ ShapeDiverRequestCache,
3
+ ShapeDiverRequestExport,
4
+ ShapeDiverRequestExportDefinition,
5
+ ShapeDiverResponseDto,
6
+ } from "@shapediver/api.geometry-api-dto-v2";
7
+ import {
8
+ BaseResourceApi,
9
+ ShapeDiverSdkApi,
10
+ } from "@shapediver/sdk.geometry-api-sdk-core";
11
+ import { sendRequest } from "../utils/utils";
12
+
13
+ export class ShapeDiverExportApi extends BaseResourceApi {
14
+ constructor(api: ShapeDiverSdkApi) {
15
+ super(api);
16
+ }
17
+
18
+ /**
19
+ * Request a specific version of an export.
20
+ *
21
+ * @param sessionId
22
+ * @param body
23
+ */
24
+ async compute(
25
+ sessionId: string,
26
+ body: ShapeDiverRequestExport,
27
+ ): Promise<ShapeDiverResponseDto> {
28
+ return await sendRequest(
29
+ async () =>
30
+ (
31
+ await this.api.put<ShapeDiverResponseDto>(
32
+ this.buildSessionUri(sessionId) + "/export",
33
+ body,
34
+ )
35
+ )[1],
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Check if a specific version of a requested export has been computed yet.
41
+ *
42
+ * @param sessionId
43
+ * @param body
44
+ */
45
+ async getCache(
46
+ sessionId: string,
47
+ body: ShapeDiverRequestCache | ShapeDiverRequestExport,
48
+ ): Promise<ShapeDiverResponseDto> {
49
+ return await sendRequest(
50
+ async () =>
51
+ (
52
+ await this.api.put<ShapeDiverResponseDto>(
53
+ this.buildSessionUri(sessionId) + "/export/cache",
54
+ body,
55
+ )
56
+ )[1],
57
+ );
58
+ }
59
+
60
+ /**
61
+ * Updates the definitions of the given exports.
62
+ *
63
+ * @param modelId
64
+ * @param body
65
+ */
66
+ async updateDefinitions(
67
+ modelId: string,
68
+ body: ShapeDiverRequestExportDefinition,
69
+ ): Promise<ShapeDiverResponseDto> {
70
+ return await sendRequest(
71
+ async () =>
72
+ (
73
+ await this.api.patch<ShapeDiverResponseDto>(
74
+ this.buildModelUri(modelId) + "/export",
75
+ body,
76
+ )
77
+ )[1],
78
+ );
79
+ }
80
+
81
+ /**
82
+ * List all cached versions of the specified export.
83
+ *
84
+ * @param sessionId
85
+ * @param exportId
86
+ */
87
+ async listVersions(
88
+ sessionId: string,
89
+ exportId: string,
90
+ ): Promise<ShapeDiverResponseDto> {
91
+ return await sendRequest(
92
+ async () =>
93
+ (
94
+ await this.api.get<ShapeDiverResponseDto>(
95
+ this.buildSessionUri(sessionId) + "/export/" + exportId + "/list",
96
+ )
97
+ )[1],
98
+ );
99
+ }
100
+ }
@@ -0,0 +1,151 @@
1
+ import {
2
+ ShapeDiverRequestFileUpload,
3
+ ShapeDiverResponseDto,
4
+ } from "@shapediver/api.geometry-api-dto-v2";
5
+ import {
6
+ BaseResourceApi,
7
+ ShapeDiverSdkApi,
8
+ ShapeDiverSdkApiResponseType,
9
+ } from "@shapediver/sdk.geometry-api-sdk-core";
10
+ import { sendRequest } from "../utils/utils";
11
+
12
+ const contentDisposition = require("content-disposition");
13
+
14
+ export interface ShapeDiverResponseFileInfo {
15
+ filename?: string;
16
+ size?: number;
17
+ }
18
+
19
+ export class ShapeDiverFileApi extends BaseResourceApi {
20
+ constructor(api: ShapeDiverSdkApi) {
21
+ super(api);
22
+ }
23
+
24
+ /**
25
+ * List all file-assets of the given parameter.
26
+ *
27
+ * @param sessionId
28
+ * @param paramId
29
+ */
30
+ async list(
31
+ sessionId: string,
32
+ paramId: string,
33
+ ): Promise<ShapeDiverResponseDto> {
34
+ return await sendRequest(
35
+ async () =>
36
+ (
37
+ await this.api.get<ShapeDiverResponseDto>(
38
+ `${this.buildSessionUri(sessionId)}/file/${paramId}/list`,
39
+ )
40
+ )[1],
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Get information about a file-asset of a parameter.
46
+ *
47
+ * @param sessionId
48
+ * @param paramId
49
+ */
50
+ async info(
51
+ sessionId: string,
52
+ paramId: string,
53
+ fileId: string,
54
+ ): Promise<ShapeDiverResponseFileInfo> {
55
+ return await sendRequest(async () => {
56
+ const headers = (
57
+ await this.api.head(
58
+ `${this.buildSessionUri(sessionId)}/file/${paramId}/${fileId}`,
59
+ )
60
+ )[0];
61
+
62
+ const res: ShapeDiverResponseFileInfo = {
63
+ size: Number(
64
+ headers.get("Content-Length") || headers.get("content-length"),
65
+ ),
66
+ };
67
+
68
+ // Extract filename from Content-Disposition header if available
69
+ const contentDispositionHeader =
70
+ headers.get("Content-Disposition") ||
71
+ headers.get("content-disposition");
72
+ if (typeof contentDispositionHeader === "string") {
73
+ try {
74
+ res.filename = contentDisposition.parse(
75
+ contentDispositionHeader,
76
+ ).parameters.filename;
77
+ } catch (_) {
78
+ res.filename = undefined;
79
+ }
80
+ }
81
+
82
+ return res;
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Download a file-asset.
88
+ *
89
+ * @param sessionId
90
+ * @param paramId
91
+ * @param fileId
92
+ */
93
+ async get(
94
+ sessionId: string,
95
+ paramId: string,
96
+ fileId: string,
97
+ ): Promise<ArrayBuffer> {
98
+ return await sendRequest(
99
+ async () =>
100
+ (
101
+ await this.api.get<ArrayBuffer>(
102
+ `${this.buildSessionUri(sessionId)}/file/${paramId}/${fileId}`,
103
+ { responseType: ShapeDiverSdkApiResponseType.DATA },
104
+ )
105
+ )[1],
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Delete a file-asset.
111
+ *
112
+ * @param sessionId
113
+ * @param paramId
114
+ * @param fileId
115
+ */
116
+ async delete(
117
+ sessionId: string,
118
+ paramId: string,
119
+ fileId: string,
120
+ ): Promise<ShapeDiverResponseDto> {
121
+ return await sendRequest(
122
+ async () =>
123
+ (
124
+ await this.api.delete<ShapeDiverResponseDto>(
125
+ `${this.buildSessionUri(sessionId)}/file/${paramId}/${fileId}`,
126
+ )
127
+ )[1],
128
+ );
129
+ }
130
+
131
+ /**
132
+ * Request an Upload-URL for a file.
133
+ *
134
+ * @param sessionId
135
+ * @param body
136
+ */
137
+ async requestUpload(
138
+ sessionId: string,
139
+ body: ShapeDiverRequestFileUpload,
140
+ ): Promise<ShapeDiverResponseDto> {
141
+ return await sendRequest(
142
+ async () =>
143
+ (
144
+ await this.api.post<ShapeDiverResponseDto>(
145
+ this.buildSessionUri(sessionId) + "/file/upload",
146
+ body,
147
+ )
148
+ )[1],
149
+ );
150
+ }
151
+ }