@shapediver/sdk.geometry-api-sdk-v2 1.12.2 → 2.0.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/README.md +160 -60
- package/dist/UtilsApi.d.ts +20 -0
- package/dist/UtilsApi.d.ts.map +1 -0
- package/dist/UtilsApi.js +185 -0
- package/dist/UtilsApi.js.map +1 -0
- package/dist/client/api.d.ts +2117 -0
- package/dist/client/api.d.ts.map +1 -0
- package/dist/client/api.js +3473 -0
- package/dist/client/api.js.map +1 -0
- package/dist/client/base.d.ts +32 -0
- package/dist/client/base.d.ts.map +1 -0
- package/dist/client/base.js +37 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/common.d.ts +14 -0
- package/dist/client/common.d.ts.map +1 -0
- package/dist/client/common.js +108 -0
- package/dist/client/common.js.map +1 -0
- package/dist/client/configuration.d.ts +23 -0
- package/dist/client/configuration.d.ts.map +1 -0
- package/dist/client/configuration.js +21 -0
- package/dist/client/configuration.js.map +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +19 -0
- package/dist/client/index.js.map +1 -0
- package/dist/configuration.d.ts +8 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +22 -0
- package/dist/configuration.js.map +1 -0
- package/dist/error.d.ts +22 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +48 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -17
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +93 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -57
- package/src/UtilsApi.ts +393 -0
- package/src/client/api.ts +14084 -0
- package/src/client/base.ts +86 -0
- package/src/client/common.ts +150 -0
- package/src/client/configuration.ts +110 -0
- package/src/client/index.ts +18 -0
- package/src/configuration.ts +27 -0
- package/src/error.ts +92 -0
- package/src/index.ts +5 -17
- package/src/utils.ts +126 -0
- package/dist/ShapeDiverErrors.d.ts +0 -10
- package/dist/ShapeDiverErrors.d.ts.map +0 -1
- package/dist/ShapeDiverErrors.js +0 -18
- package/dist/ShapeDiverErrors.js.map +0 -1
- package/dist/ShapeDiverSdk.d.ts +0 -48
- package/dist/ShapeDiverSdk.d.ts.map +0 -1
- package/dist/ShapeDiverSdk.js +0 -87
- package/dist/ShapeDiverSdk.js.map +0 -1
- package/dist/resources/ShapeDiverAnalyticsApi.d.ts +0 -12
- package/dist/resources/ShapeDiverAnalyticsApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverAnalyticsApi.js +0 -63
- package/dist/resources/ShapeDiverAnalyticsApi.js.map +0 -1
- package/dist/resources/ShapeDiverArSceneApi.d.ts +0 -8
- package/dist/resources/ShapeDiverArSceneApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverArSceneApi.js +0 -63
- package/dist/resources/ShapeDiverArSceneApi.js.map +0 -1
- package/dist/resources/ShapeDiverAssetApi.d.ts +0 -13
- package/dist/resources/ShapeDiverAssetApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverAssetApi.js +0 -131
- package/dist/resources/ShapeDiverAssetApi.js.map +0 -1
- package/dist/resources/ShapeDiverExportApi.d.ts +0 -10
- package/dist/resources/ShapeDiverExportApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverExportApi.js +0 -49
- package/dist/resources/ShapeDiverExportApi.js.map +0 -1
- package/dist/resources/ShapeDiverFileApi.d.ts +0 -15
- package/dist/resources/ShapeDiverFileApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverFileApi.js +0 -67
- package/dist/resources/ShapeDiverFileApi.js.map +0 -1
- package/dist/resources/ShapeDiverGltfApi.d.ts +0 -7
- package/dist/resources/ShapeDiverGltfApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverGltfApi.js +0 -32
- package/dist/resources/ShapeDiverGltfApi.js.map +0 -1
- package/dist/resources/ShapeDiverModelApi.d.ts +0 -22
- package/dist/resources/ShapeDiverModelApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverModelApi.js +0 -156
- package/dist/resources/ShapeDiverModelApi.js.map +0 -1
- package/dist/resources/ShapeDiverModelStateApi.d.ts +0 -14
- package/dist/resources/ShapeDiverModelStateApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverModelStateApi.js +0 -104
- package/dist/resources/ShapeDiverModelStateApi.js.map +0 -1
- package/dist/resources/ShapeDiverOutputApi.d.ts +0 -10
- package/dist/resources/ShapeDiverOutputApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverOutputApi.js +0 -52
- package/dist/resources/ShapeDiverOutputApi.js.map +0 -1
- package/dist/resources/ShapeDiverSdtfApi.d.ts +0 -10
- package/dist/resources/ShapeDiverSdtfApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverSdtfApi.js +0 -52
- package/dist/resources/ShapeDiverSdtfApi.js.map +0 -1
- package/dist/resources/ShapeDiverSessionApi.d.ts +0 -11
- package/dist/resources/ShapeDiverSessionApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverSessionApi.js +0 -66
- package/dist/resources/ShapeDiverSessionApi.js.map +0 -1
- package/dist/resources/ShapeDiverSystemApi.d.ts +0 -12
- package/dist/resources/ShapeDiverSystemApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverSystemApi.js +0 -63
- package/dist/resources/ShapeDiverSystemApi.js.map +0 -1
- package/dist/resources/ShapeDiverTextureApi.d.ts +0 -7
- package/dist/resources/ShapeDiverTextureApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverTextureApi.js +0 -31
- package/dist/resources/ShapeDiverTextureApi.js.map +0 -1
- package/dist/resources/ShapeDiverUtilsApi.d.ts +0 -18
- package/dist/resources/ShapeDiverUtilsApi.d.ts.map +0 -1
- package/dist/resources/ShapeDiverUtilsApi.js +0 -146
- package/dist/resources/ShapeDiverUtilsApi.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -12
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js +0 -109
- package/dist/utils/utils.js.map +0 -1
- package/src/ShapeDiverErrors.ts +0 -34
- package/src/ShapeDiverSdk.ts +0 -121
- package/src/resources/ShapeDiverAnalyticsApi.ts +0 -108
- package/src/resources/ShapeDiverArSceneApi.ts +0 -77
- package/src/resources/ShapeDiverAssetApi.ts +0 -241
- package/src/resources/ShapeDiverExportApi.ts +0 -103
- package/src/resources/ShapeDiverFileApi.ts +0 -150
- package/src/resources/ShapeDiverGltfApi.ts +0 -46
- package/src/resources/ShapeDiverModelApi.ts +0 -374
- package/src/resources/ShapeDiverModelStateApi.ts +0 -163
- package/src/resources/ShapeDiverOutputApi.ts +0 -109
- package/src/resources/ShapeDiverSdtfApi.ts +0 -103
- package/src/resources/ShapeDiverSessionApi.ts +0 -142
- package/src/resources/ShapeDiverSystemApi.ts +0 -118
- package/src/resources/ShapeDiverTextureApi.ts +0 -36
- package/src/resources/ShapeDiverUtilsApi.ts +0 -318
- package/src/utils/utils.ts +0 -135
package/src/ShapeDiverSdk.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
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
|
-
import { ShapeDiverModelStateApi } from "./resources/ShapeDiverModelStateApi";
|
|
19
|
-
|
|
20
|
-
export function create(baseUrl: string, jwt?: string): ShapeDiverSdk {
|
|
21
|
-
return new ShapeDiverSdk(baseUrl, jwt);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class ShapeDiverSdk extends BaseShapeDiverSdk {
|
|
25
|
-
private readonly _analytics: ShapeDiverAnalyticsApi;
|
|
26
|
-
private readonly _arScene: ShapeDiverArSceneApi;
|
|
27
|
-
private readonly _asset: ShapeDiverAssetApi;
|
|
28
|
-
private readonly _export: ShapeDiverExportApi;
|
|
29
|
-
private readonly _file: ShapeDiverFileApi;
|
|
30
|
-
private readonly _gltf: ShapeDiverGltfApi;
|
|
31
|
-
private readonly _model: ShapeDiverModelApi;
|
|
32
|
-
private readonly _modelState: ShapeDiverModelStateApi;
|
|
33
|
-
private readonly _output: ShapeDiverOutputApi;
|
|
34
|
-
private readonly _sdtf: ShapeDiverSdtfApi;
|
|
35
|
-
private readonly _session: ShapeDiverSessionApi;
|
|
36
|
-
private readonly _system: ShapeDiverSystemApi;
|
|
37
|
-
private readonly _texture: ShapeDiverTextureApi;
|
|
38
|
-
private readonly _utils: ShapeDiverUtilsApi;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* ShapeDiverSDK constructor
|
|
42
|
-
*
|
|
43
|
-
* @param baseUrl - the URL of the target system
|
|
44
|
-
* @param jwt - the client's jwt
|
|
45
|
-
*/
|
|
46
|
-
constructor(baseUrl: string, jwt?: string) {
|
|
47
|
-
super(baseUrl);
|
|
48
|
-
if (jwt) this.setConfigurationValue(ShapeDiverSdkConfigType.JWT_TOKEN, jwt);
|
|
49
|
-
|
|
50
|
-
this._analytics = new ShapeDiverAnalyticsApi(this.sdkApi);
|
|
51
|
-
this._arScene = new ShapeDiverArSceneApi(this.sdkApi);
|
|
52
|
-
this._asset = new ShapeDiverAssetApi(this.sdkApi);
|
|
53
|
-
this._export = new ShapeDiverExportApi(this.sdkApi);
|
|
54
|
-
this._file = new ShapeDiverFileApi(this.sdkApi);
|
|
55
|
-
this._gltf = new ShapeDiverGltfApi(this.sdkApi);
|
|
56
|
-
this._model = new ShapeDiverModelApi(this.sdkApi);
|
|
57
|
-
this._modelState = new ShapeDiverModelStateApi(this.sdkApi);
|
|
58
|
-
this._output = new ShapeDiverOutputApi(this.sdkApi);
|
|
59
|
-
this._sdtf = new ShapeDiverSdtfApi(this.sdkApi);
|
|
60
|
-
this._session = new ShapeDiverSessionApi(this.sdkApi);
|
|
61
|
-
this._system = new ShapeDiverSystemApi(this.sdkApi);
|
|
62
|
-
this._texture = new ShapeDiverTextureApi(this.sdkApi);
|
|
63
|
-
this._utils = new ShapeDiverUtilsApi(this.sdkApi);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get analytics(): ShapeDiverAnalyticsApi {
|
|
67
|
-
return this._analytics;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get arScene(): ShapeDiverArSceneApi {
|
|
71
|
-
return this._arScene;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get asset(): ShapeDiverAssetApi {
|
|
75
|
-
return this._asset;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get export(): ShapeDiverExportApi {
|
|
79
|
-
return this._export;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
get file(): ShapeDiverFileApi {
|
|
83
|
-
return this._file;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
get gltf(): ShapeDiverGltfApi {
|
|
87
|
-
return this._gltf;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get model(): ShapeDiverModelApi {
|
|
91
|
-
return this._model;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get modelState(): ShapeDiverModelStateApi {
|
|
95
|
-
return this._modelState;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get output(): ShapeDiverOutputApi {
|
|
99
|
-
return this._output;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
get sdtf(): ShapeDiverSdtfApi {
|
|
103
|
-
return this._sdtf;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
get session(): ShapeDiverSessionApi {
|
|
107
|
-
return this._session;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
get system(): ShapeDiverSystemApi {
|
|
111
|
-
return this._system;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get texture(): ShapeDiverTextureApi {
|
|
115
|
-
return this._texture;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get utils(): ShapeDiverUtilsApi {
|
|
119
|
-
return this._utils;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ShapeDiverRequestAnalyticsCreditMetrics,
|
|
3
|
-
ShapeDiverRequestAnalyticsModel,
|
|
4
|
-
ShapeDiverResponseDto,
|
|
5
|
-
} from "@shapediver/api.geometry-api-dto-v2";
|
|
6
|
-
import {
|
|
7
|
-
BaseResourceApi,
|
|
8
|
-
ShapeDiverSdkApi,
|
|
9
|
-
} from "@shapediver/sdk.geometry-api-sdk-core";
|
|
10
|
-
import { sendRequest } from "../utils/utils";
|
|
11
|
-
|
|
12
|
-
export class ShapeDiverAnalyticsApi extends BaseResourceApi {
|
|
13
|
-
constructor(api: ShapeDiverSdkApi) {
|
|
14
|
-
super(api);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get model session analytics.
|
|
19
|
-
*
|
|
20
|
-
* @param body
|
|
21
|
-
*/
|
|
22
|
-
async modelSessionStatistics(
|
|
23
|
-
body: ShapeDiverRequestAnalyticsModel,
|
|
24
|
-
): Promise<ShapeDiverResponseDto> {
|
|
25
|
-
return await sendRequest(
|
|
26
|
-
async () =>
|
|
27
|
-
(
|
|
28
|
-
await this.api.put<ShapeDiverResponseDto>(
|
|
29
|
-
this.buildAnalyticsUri() + "/session/model",
|
|
30
|
-
undefined,
|
|
31
|
-
body,
|
|
32
|
-
)
|
|
33
|
-
)[1],
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Get credit metrics. */
|
|
38
|
-
async creditMetrics(
|
|
39
|
-
body: ShapeDiverRequestAnalyticsCreditMetrics,
|
|
40
|
-
): Promise<ShapeDiverResponseDto> {
|
|
41
|
-
return await sendRequest(
|
|
42
|
-
async () =>
|
|
43
|
-
(
|
|
44
|
-
await this.api.put<ShapeDiverResponseDto>(
|
|
45
|
-
this.buildAnalyticsUri() + "/credit-metrics",
|
|
46
|
-
undefined,
|
|
47
|
-
body,
|
|
48
|
-
)
|
|
49
|
-
)[1],
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Get credit metrics of all users active at timestamp. */
|
|
54
|
-
async userCreditMetrics(timestamp: string): Promise<ShapeDiverResponseDto> {
|
|
55
|
-
return await sendRequest(
|
|
56
|
-
async () =>
|
|
57
|
-
(
|
|
58
|
-
await this.api.get<ShapeDiverResponseDto>(
|
|
59
|
-
`${this.buildAnalyticsUri()}/credit-metrics/timestamp/${timestamp}/user`,
|
|
60
|
-
)
|
|
61
|
-
)[1],
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Get credit metrics of all organizations with users active at timestamp. */
|
|
66
|
-
async organizationCreditMetrics(
|
|
67
|
-
timestamp: string,
|
|
68
|
-
): Promise<ShapeDiverResponseDto> {
|
|
69
|
-
return await sendRequest(
|
|
70
|
-
async () =>
|
|
71
|
-
(
|
|
72
|
-
await this.api.get<ShapeDiverResponseDto>(
|
|
73
|
-
`${this.buildAnalyticsUri()}/credit-metrics/timestamp/${timestamp}/org`,
|
|
74
|
-
)
|
|
75
|
-
)[1],
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Get model credit metrics of the user at timestamp. */
|
|
80
|
-
async modelUserCreditMetrics(
|
|
81
|
-
userId: string,
|
|
82
|
-
timestamp: string,
|
|
83
|
-
): Promise<ShapeDiverResponseDto> {
|
|
84
|
-
return await sendRequest(
|
|
85
|
-
async () =>
|
|
86
|
-
(
|
|
87
|
-
await this.api.get<ShapeDiverResponseDto>(
|
|
88
|
-
`${this.buildAnalyticsUri()}/credit-metrics/timestamp/${timestamp}/user/${userId}`,
|
|
89
|
-
)
|
|
90
|
-
)[1],
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Get model credit metrics of the organization at timestamp. */
|
|
95
|
-
async modelOrganizationCreditMetrics(
|
|
96
|
-
orgId: string,
|
|
97
|
-
timestamp: string,
|
|
98
|
-
): Promise<ShapeDiverResponseDto> {
|
|
99
|
-
return await sendRequest(
|
|
100
|
-
async () =>
|
|
101
|
-
(
|
|
102
|
-
await this.api.get<ShapeDiverResponseDto>(
|
|
103
|
-
`${this.buildAnalyticsUri()}/credit-metrics/timestamp/${timestamp}/org/${orgId}`,
|
|
104
|
-
)
|
|
105
|
-
)[1],
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
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 id AR scene ID or Model-State ID.
|
|
17
|
-
* @returns `true` when the AR scene exists, otherwise `false`.
|
|
18
|
-
*/
|
|
19
|
-
async exists(id: string): Promise<boolean> {
|
|
20
|
-
return await sendRequest(async () => {
|
|
21
|
-
try {
|
|
22
|
-
const [_, status] = await this.api.head(
|
|
23
|
-
`${this.buildArSceneUri()}/${id}`,
|
|
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 id AR scene ID or Model-State ID.
|
|
40
|
-
* @returns Array of size 2: [0] = content data, [1] = content type
|
|
41
|
-
*/
|
|
42
|
-
async getGltf(id: string): Promise<[ArrayBuffer, string]> {
|
|
43
|
-
return await sendRequest(async () => {
|
|
44
|
-
const [header, data] = await this.api.get<ArrayBuffer>(
|
|
45
|
-
`${this.buildArSceneUri()}/${id}/gltf`,
|
|
46
|
-
undefined,
|
|
47
|
-
{
|
|
48
|
-
responseType: ShapeDiverSdkApiResponseType.DATA,
|
|
49
|
-
disableAuthorization: true,
|
|
50
|
-
},
|
|
51
|
-
);
|
|
52
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
53
|
-
return [data, contentType];
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Download the USDZ file of the specified AR scene.
|
|
59
|
-
*
|
|
60
|
-
* @param id AR scene ID or Model-State ID.
|
|
61
|
-
* @returns Array of size 2: [0] = content data, [1] = content type
|
|
62
|
-
*/
|
|
63
|
-
async getUsdz(id: string): Promise<[ArrayBuffer, string]> {
|
|
64
|
-
return await sendRequest(async () => {
|
|
65
|
-
const [header, data] = await this.api.get<ArrayBuffer>(
|
|
66
|
-
`${this.buildArSceneUri()}/${id}/usdz`,
|
|
67
|
-
undefined,
|
|
68
|
-
{
|
|
69
|
-
responseType: ShapeDiverSdkApiResponseType.DATA,
|
|
70
|
-
disableAuthorization: true,
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
74
|
-
return [data, contentType];
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
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
|
-
const directDownloadUri =
|
|
19
|
-
/^(http[s]?:\/\/)?(viewer|textures|downloads)\.shapediver\.com(\/.*)?$/;
|
|
20
|
-
|
|
21
|
-
export class ShapeDiverAssetApi extends BaseResourceApi {
|
|
22
|
-
constructor(api: ShapeDiverSdkApi) {
|
|
23
|
-
super(api);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Download an export.
|
|
28
|
-
*
|
|
29
|
-
* @param sessionId
|
|
30
|
-
* @param assetData
|
|
31
|
-
*/
|
|
32
|
-
async getExport(
|
|
33
|
-
sessionId: string,
|
|
34
|
-
assetData: string,
|
|
35
|
-
): Promise<[ArrayBuffer, string]> {
|
|
36
|
-
return await sendRequest(async () => {
|
|
37
|
-
const [header, data] = await this.api.get<ArrayBuffer>(
|
|
38
|
-
`${this.buildSessionUri(sessionId)}/export/${assetData}`,
|
|
39
|
-
undefined,
|
|
40
|
-
{ responseType: ShapeDiverSdkApiResponseType.DATA },
|
|
41
|
-
);
|
|
42
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
43
|
-
return [data, contentType];
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Download an output.
|
|
49
|
-
*
|
|
50
|
-
* @param sessionId
|
|
51
|
-
* @param assetData
|
|
52
|
-
*/
|
|
53
|
-
async getOutput(
|
|
54
|
-
sessionId: string,
|
|
55
|
-
assetData: string,
|
|
56
|
-
): Promise<[ArrayBuffer, string]> {
|
|
57
|
-
return await sendRequest(async () => {
|
|
58
|
-
const [header, data] = await this.api.get<ArrayBuffer>(
|
|
59
|
-
`${this.buildSessionUri(sessionId)}/output/${assetData}`,
|
|
60
|
-
undefined,
|
|
61
|
-
{ responseType: ShapeDiverSdkApiResponseType.DATA },
|
|
62
|
-
);
|
|
63
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
64
|
-
return [data, contentType];
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Downloads the JSON content part of a sdTF output.
|
|
70
|
-
*
|
|
71
|
-
* @param sessionId
|
|
72
|
-
* @param assetData
|
|
73
|
-
*/
|
|
74
|
-
async getSdtfJsonContent(
|
|
75
|
-
sessionId: string,
|
|
76
|
-
assetData: string,
|
|
77
|
-
): Promise<Record<string, any>> {
|
|
78
|
-
return await sendRequest(
|
|
79
|
-
async () =>
|
|
80
|
-
(
|
|
81
|
-
await this.api.get<ArrayBuffer>(
|
|
82
|
-
`${this.buildSessionUri(sessionId)}/output/${assetData}`,
|
|
83
|
-
undefined,
|
|
84
|
-
{
|
|
85
|
-
responseType: ShapeDiverSdkApiResponseType.JSON,
|
|
86
|
-
accept: "model/vnd.sdtf+json",
|
|
87
|
-
},
|
|
88
|
-
)
|
|
89
|
-
)[1],
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Download a texture file.
|
|
95
|
-
*
|
|
96
|
-
* @param sessionId
|
|
97
|
-
* @param assetData
|
|
98
|
-
*/
|
|
99
|
-
async getTexture(
|
|
100
|
-
sessionId: string,
|
|
101
|
-
assetData: string,
|
|
102
|
-
): Promise<[ArrayBuffer, string]> {
|
|
103
|
-
return await sendRequest(async () => {
|
|
104
|
-
const [header, data] = await this.api.get<ArrayBuffer>(
|
|
105
|
-
`${this.buildSessionUri(sessionId)}/texture/${assetData}`,
|
|
106
|
-
undefined,
|
|
107
|
-
{ responseType: ShapeDiverSdkApiResponseType.DATA },
|
|
108
|
-
);
|
|
109
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
110
|
-
return [data, contentType];
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Download a glTF file.
|
|
116
|
-
*
|
|
117
|
-
* @param sessionId
|
|
118
|
-
* @param assetData
|
|
119
|
-
*/
|
|
120
|
-
async getGltf(sessionId: string, assetData: string): Promise<ArrayBuffer> {
|
|
121
|
-
return await sendRequest(
|
|
122
|
-
async () =>
|
|
123
|
-
(
|
|
124
|
-
await this.api.get<ArrayBuffer>(
|
|
125
|
-
`${this.buildSessionUri(sessionId)}/gltf/${assetData}`,
|
|
126
|
-
undefined,
|
|
127
|
-
{ responseType: ShapeDiverSdkApiResponseType.DATA },
|
|
128
|
-
)
|
|
129
|
-
)[1],
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Download a USDZ file.
|
|
135
|
-
*
|
|
136
|
-
* @param sessionId
|
|
137
|
-
* @param assetData
|
|
138
|
-
*/
|
|
139
|
-
async getUsdz(sessionId: string, assetData: string): Promise<ArrayBuffer> {
|
|
140
|
-
return await sendRequest(
|
|
141
|
-
async () =>
|
|
142
|
-
(
|
|
143
|
-
await this.api.get<ArrayBuffer>(
|
|
144
|
-
`${this.buildSessionUri(sessionId)}/usdz/${assetData}`,
|
|
145
|
-
undefined,
|
|
146
|
-
{ responseType: ShapeDiverSdkApiResponseType.DATA },
|
|
147
|
-
)
|
|
148
|
-
)[1],
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Download an image.
|
|
154
|
-
*
|
|
155
|
-
* @param sessionId
|
|
156
|
-
* @param url - The URL of the image that should be downloaded.
|
|
157
|
-
* @returns Array of size 2: [0] = content data, [1] = content type.
|
|
158
|
-
*/
|
|
159
|
-
async downloadImage(
|
|
160
|
-
sessionId: string,
|
|
161
|
-
url: string,
|
|
162
|
-
): Promise<[ArrayBuffer, string]> {
|
|
163
|
-
let targetUrl: string, queries: string[];
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
apiAssetTextureUri.test(url) ||
|
|
167
|
-
cdnAssetTextureUri.test(url) ||
|
|
168
|
-
directDownloadUri.test(url)
|
|
169
|
-
) {
|
|
170
|
-
// Call ShapeDiver texture-asset URLs directly
|
|
171
|
-
targetUrl = url;
|
|
172
|
-
queries = [];
|
|
173
|
-
} else {
|
|
174
|
-
// All other source URLs are called via the download-image endpoint
|
|
175
|
-
targetUrl = `${this.buildSessionUri(sessionId)}/image`;
|
|
176
|
-
queries = [`url=${encodeBase64(url)}`];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return await sendRequest(async () => {
|
|
180
|
-
const [header, data] = await this.api.get<ArrayBuffer>(
|
|
181
|
-
targetUrl,
|
|
182
|
-
queries,
|
|
183
|
-
{
|
|
184
|
-
responseType: ShapeDiverSdkApiResponseType.DATA,
|
|
185
|
-
/*
|
|
186
|
-
* Disable authorization and custom headers for CDN and direct download URLs to preserve
|
|
187
|
-
* simple GETs whenever possible (do not require preflight requests).
|
|
188
|
-
*/
|
|
189
|
-
disableAuthorization:
|
|
190
|
-
cdnAssetUri.test(url) || directDownloadUri.test(url),
|
|
191
|
-
disableCustomHeaders:
|
|
192
|
-
cdnAssetUri.test(url) || directDownloadUri.test(url),
|
|
193
|
-
},
|
|
194
|
-
);
|
|
195
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
196
|
-
return [data, contentType];
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Fetches a ShapeDiver asset of the following types:
|
|
202
|
-
* * Output
|
|
203
|
-
* * Export
|
|
204
|
-
* * Texture
|
|
205
|
-
*
|
|
206
|
-
* This function works similar to {@link getOutput}, {@link getExport} and {@link getTexture}, but does not require
|
|
207
|
-
* extracted _session ID_ and _asset data_ parameters.
|
|
208
|
-
*
|
|
209
|
-
* @param url - The URL of the asset that should be fetched.
|
|
210
|
-
* @returns Array of size 3: [0] = content data, [1] = content type, [2] = asset type.
|
|
211
|
-
* @throws {@link ShapeDiverError} when the given URL is not a valid ShapeDiver asset URL.
|
|
212
|
-
*/
|
|
213
|
-
async getAsset(
|
|
214
|
-
url: string,
|
|
215
|
-
): Promise<[ArrayBuffer, string, "output" | "export" | "texture"]> {
|
|
216
|
-
let type: "output" | "export" | "texture";
|
|
217
|
-
|
|
218
|
-
// Check if the given URL is a valid API or CDN asset URL
|
|
219
|
-
if (apiAssetExportUri.test(url) || cdnAssetExportUri.test(url))
|
|
220
|
-
type = "export";
|
|
221
|
-
else if (apiAssetOutputUri.test(url) || cdnAssetOutputUri.test(url))
|
|
222
|
-
type = "output";
|
|
223
|
-
else if (apiAssetTextureUri.test(url) || cdnAssetTextureUri.test(url))
|
|
224
|
-
type = "texture";
|
|
225
|
-
else
|
|
226
|
-
throw new ShapeDiverError(
|
|
227
|
-
"Cannot fetch asset: Invalid URL (only ShapeDiver asset URLs are allowed).",
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
return await sendRequest(async () => {
|
|
231
|
-
const [header, data] = await this.api.get<ArrayBuffer>(url, undefined, {
|
|
232
|
-
responseType: ShapeDiverSdkApiResponseType.DATA,
|
|
233
|
-
/* Disable authorization and custom headers for CDN URLs to preserve simple GETs. */
|
|
234
|
-
disableAuthorization: cdnAssetUri.test(url),
|
|
235
|
-
disableCustomHeaders: cdnAssetUri.test(url),
|
|
236
|
-
});
|
|
237
|
-
const contentType = header["Content-Type"] ?? header["content-type"];
|
|
238
|
-
return [data, contentType, type];
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
undefined,
|
|
34
|
-
body,
|
|
35
|
-
)
|
|
36
|
-
)[1],
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Check if a specific version of a requested export has been computed yet.
|
|
42
|
-
*
|
|
43
|
-
* @param sessionId
|
|
44
|
-
* @param body
|
|
45
|
-
*/
|
|
46
|
-
async getCache(
|
|
47
|
-
sessionId: string,
|
|
48
|
-
body: ShapeDiverRequestCache | ShapeDiverRequestExport,
|
|
49
|
-
): Promise<ShapeDiverResponseDto> {
|
|
50
|
-
return await sendRequest(
|
|
51
|
-
async () =>
|
|
52
|
-
(
|
|
53
|
-
await this.api.put<ShapeDiverResponseDto>(
|
|
54
|
-
this.buildSessionUri(sessionId) + "/export/cache",
|
|
55
|
-
undefined,
|
|
56
|
-
body,
|
|
57
|
-
)
|
|
58
|
-
)[1],
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Updates the definitions of the given exports.
|
|
64
|
-
*
|
|
65
|
-
* @param modelId
|
|
66
|
-
* @param body
|
|
67
|
-
*/
|
|
68
|
-
async updateDefinitions(
|
|
69
|
-
modelId: string,
|
|
70
|
-
body: ShapeDiverRequestExportDefinition,
|
|
71
|
-
): Promise<ShapeDiverResponseDto> {
|
|
72
|
-
return await sendRequest(
|
|
73
|
-
async () =>
|
|
74
|
-
(
|
|
75
|
-
await this.api.patch<ShapeDiverResponseDto>(
|
|
76
|
-
this.buildModelUri(modelId) + "/export",
|
|
77
|
-
undefined,
|
|
78
|
-
body,
|
|
79
|
-
)
|
|
80
|
-
)[1],
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* List all cached versions of the specified export.
|
|
86
|
-
*
|
|
87
|
-
* @param sessionId
|
|
88
|
-
* @param exportId
|
|
89
|
-
*/
|
|
90
|
-
async listVersions(
|
|
91
|
-
sessionId: string,
|
|
92
|
-
exportId: string,
|
|
93
|
-
): Promise<ShapeDiverResponseDto> {
|
|
94
|
-
return await sendRequest(
|
|
95
|
-
async () =>
|
|
96
|
-
(
|
|
97
|
-
await this.api.get<ShapeDiverResponseDto>(
|
|
98
|
-
`${this.buildSessionUri(sessionId)}/export/${exportId}/list`,
|
|
99
|
-
)
|
|
100
|
-
)[1],
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|