@shapediver/viewer.session-engine.session-engine 3.14.7 → 3.14.9

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 (47) hide show
  1. package/dist/implementation/OutputLoader.d.ts.map +1 -1
  2. package/dist/implementation/OutputLoader.js +19 -0
  3. package/dist/implementation/OutputLoader.js.map +1 -1
  4. package/dist/implementation/SessionEngine.d.ts.map +1 -1
  5. package/dist/implementation/SessionEngine.js +5 -8
  6. package/dist/implementation/SessionEngine.js.map +1 -1
  7. package/dist/implementation/SessionEngineCore.d.ts +119 -0
  8. package/dist/implementation/SessionEngineCore.d.ts.map +1 -0
  9. package/dist/implementation/SessionEngineCore.js +367 -0
  10. package/dist/implementation/SessionEngineCore.js.map +1 -0
  11. package/dist/implementation/SessionEngineFacade.d.ts +106 -0
  12. package/dist/implementation/SessionEngineFacade.d.ts.map +1 -0
  13. package/dist/implementation/SessionEngineFacade.js +191 -0
  14. package/dist/implementation/SessionEngineFacade.js.map +1 -0
  15. package/dist/implementation/managers/CustomizationManager.d.ts +67 -0
  16. package/dist/implementation/managers/CustomizationManager.d.ts.map +1 -0
  17. package/dist/implementation/managers/CustomizationManager.js +324 -0
  18. package/dist/implementation/managers/CustomizationManager.js.map +1 -0
  19. package/dist/implementation/managers/ExportManager.d.ts +75 -0
  20. package/dist/implementation/managers/ExportManager.d.ts.map +1 -0
  21. package/dist/implementation/managers/ExportManager.js +213 -0
  22. package/dist/implementation/managers/ExportManager.js.map +1 -0
  23. package/dist/implementation/managers/FileUploadManager.d.ts +74 -0
  24. package/dist/implementation/managers/FileUploadManager.d.ts.map +1 -0
  25. package/dist/implementation/managers/FileUploadManager.js +221 -0
  26. package/dist/implementation/managers/FileUploadManager.js.map +1 -0
  27. package/dist/implementation/managers/ModelStateManager.d.ts +54 -0
  28. package/dist/implementation/managers/ModelStateManager.d.ts.map +1 -0
  29. package/dist/implementation/managers/ModelStateManager.js +177 -0
  30. package/dist/implementation/managers/ModelStateManager.js.map +1 -0
  31. package/dist/implementation/managers/OutputManager.d.ts +99 -0
  32. package/dist/implementation/managers/OutputManager.d.ts.map +1 -0
  33. package/dist/implementation/managers/OutputManager.js +418 -0
  34. package/dist/implementation/managers/OutputManager.js.map +1 -0
  35. package/dist/implementation/managers/ParameterManager.d.ts +75 -0
  36. package/dist/implementation/managers/ParameterManager.d.ts.map +1 -0
  37. package/dist/implementation/managers/ParameterManager.js +235 -0
  38. package/dist/implementation/managers/ParameterManager.js.map +1 -0
  39. package/dist/implementation/managers/SettingsManager.d.ts +80 -0
  40. package/dist/implementation/managers/SettingsManager.d.ts.map +1 -0
  41. package/dist/implementation/managers/SettingsManager.js +502 -0
  42. package/dist/implementation/managers/SettingsManager.js.map +1 -0
  43. package/dist/implementation/managers/UtilsManager.d.ts +127 -0
  44. package/dist/implementation/managers/UtilsManager.d.ts.map +1 -0
  45. package/dist/implementation/managers/UtilsManager.js +410 -0
  46. package/dist/implementation/managers/UtilsManager.js.map +1 -0
  47. package/package.json +8 -8
@@ -0,0 +1,75 @@
1
+ import { ReqCustomization, ReqExport, ResBase, ResExport } from "@shapediver/sdk.geometry-api-sdk-v2";
2
+ import { IExport } from "../../interfaces/dto/IExport";
3
+ import { SessionEngineCore } from "../SessionEngineCore";
4
+ /**
5
+ * Manager for exports and export related operations.
6
+ *
7
+ * The manager is created by the SessionEngineCore and can be accessed
8
+ * via the `exportManager` property.
9
+ */
10
+ export declare class ExportManager {
11
+ private readonly _eventEngine;
12
+ private readonly _exports;
13
+ private readonly _sessionEngineCore;
14
+ private readonly _uuidGenerator;
15
+ constructor(sessionEngineCore: SessionEngineCore);
16
+ get exports(): {
17
+ [key: string]: IExport;
18
+ };
19
+ /**
20
+ * Cleans the provided export parameters by converting names/displaynames to ids
21
+ * and filling in missing parameters with current session values.
22
+ *
23
+ * @param parameters The provided export parameters
24
+ * @returns The cleaned export parameters
25
+ */
26
+ cleanExportParameters(parameters: {
27
+ [key: string]: unknown;
28
+ }): ReqCustomization;
29
+ /**
30
+ * Creates export objects from the current response DTO.
31
+ *
32
+ * Called internally after each customization or export request to update the exports.
33
+ * Exports of type EMAIL and DOWNLOAD are created.
34
+ *
35
+ * Called by SessionEngineCore.updateResponseDto.
36
+ */
37
+ createExportsFromDto(): void;
38
+ /**
39
+ * Requests an export.
40
+ *
41
+ * @param exportId The id of the export to request
42
+ * @param parameters The parameters to use for the export
43
+ * @param maxWaitTime The maximum time to wait for the export to complete
44
+ * @param retry Whether to retry the request in case of failure
45
+ * @returns Promise with the requested export
46
+ */
47
+ requestExport(exportId: string, parameters: {
48
+ [key: string]: unknown;
49
+ }, maxWaitTime: number, retry?: boolean): Promise<ResExport>;
50
+ /**
51
+ * Requests multiple exports.
52
+ *
53
+ * @param body The export request body
54
+ * @param loadOutputs Whether to load outputs as part of the export request
55
+ * @param maxWaitMsec The maximum time to wait for the export to complete
56
+ * @param retry Whether to retry the request in case of failure
57
+ * @returns Promise with the response DTO
58
+ */
59
+ requestExports(body: ReqExport, loadOutputs?: boolean, maxWaitMsec?: number, retry?: boolean): Promise<ResBase>;
60
+ /**
61
+ * Save the export properties for displayname, order, tooltip and hidden
62
+ *
63
+ * @param exports
64
+ * @returns
65
+ */
66
+ saveExportProperties(exports: {
67
+ [key: string]: {
68
+ displayname: string;
69
+ hidden: boolean;
70
+ order: number;
71
+ tooltip: string;
72
+ };
73
+ }, retry?: boolean): Promise<boolean>;
74
+ }
75
+ //# sourceMappingURL=ExportManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExportManager.d.ts","sourceRoot":"","sources":["../../../src/implementation/managers/ExportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,SAAS,EAGT,MAAM,qCAAqC,CAAC;AAQ7C,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAErD,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD;;;;;GAKG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwB;IACrD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IACvD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0B;gBAE7C,iBAAiB,EAAE,iBAAiB;IAIhD,IAAW,OAAO,IAAI;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAE7C;IAED;;;;;;OAMG;IACI,qBAAqB,CAAC,UAAU,EAAE;QACxC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,GAAG,gBAAgB;IAyCpB;;;;;;;OAOG;IACI,oBAAoB,IAAI,IAAI;IA+BnC;;;;;;;;OAQG;IACU,aAAa,CACzB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,EACpC,WAAW,EAAE,MAAM,EACnB,KAAK,UAAQ,GACX,OAAO,CAAC,SAAS,CAAC;IA4BrB;;;;;;;;OAQG;IACU,cAAc,CAC1B,IAAI,EAAE,SAAS,EACf,WAAW,GAAE,OAAe,EAC5B,WAAW,CAAC,EAAE,MAAM,EACpB,KAAK,UAAQ,GACX,OAAO,CAAC,OAAO,CAAC;IAuHnB;;;;;OAKG;IACU,oBAAoB,CAChC,OAAO,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG;YACd,WAAW,EAAE,MAAM,CAAC;YACpB,MAAM,EAAE,OAAO,CAAC;YAChB,KAAK,EAAE,MAAM,CAAC;YACd,OAAO,EAAE,MAAM,CAAC;SAChB,CAAC;KACF,EACD,KAAK,UAAQ,GACX,OAAO,CAAC,OAAO,CAAC;CAkBnB"}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ExportManager = void 0;
13
+ const sdk_geometry_api_sdk_v2_1 = require("@shapediver/sdk.geometry-api-sdk-v2");
14
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
15
+ const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
16
+ const Export_1 = require("../dto/Export");
17
+ /**
18
+ * Manager for exports and export related operations.
19
+ *
20
+ * The manager is created by the SessionEngineCore and can be accessed
21
+ * via the `exportManager` property.
22
+ */
23
+ class ExportManager {
24
+ constructor(sessionEngineCore) {
25
+ this._eventEngine = viewer_shared_services_1.EventEngine.instance;
26
+ this._exports = {};
27
+ this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
28
+ this._sessionEngineCore = sessionEngineCore;
29
+ }
30
+ get exports() {
31
+ return this._exports;
32
+ }
33
+ /**
34
+ * Cleans the provided export parameters by converting names/displaynames to ids
35
+ * and filling in missing parameters with current session values.
36
+ *
37
+ * @param parameters The provided export parameters
38
+ * @returns The cleaned export parameters
39
+ */
40
+ cleanExportParameters(parameters) {
41
+ const requestParameterSet = {};
42
+ // first step, we convert all our names and displaynames to ids
43
+ for (const parameterIdOrName in parameters) {
44
+ // we prioritize id, then name and then displayname
45
+ // if there are two parameters with the same name or displayname, we take the one that is found first (no way for us to evaluate which one the user meant)
46
+ const parameterObject = Object.values(this._sessionEngineCore.parameterManager.parameters).find((p) => p.id === parameterIdOrName ||
47
+ p.name === parameterIdOrName ||
48
+ p.displayname === parameterIdOrName);
49
+ // in case the key of the key value pair was neither the id, name or displayname, skip
50
+ if (!parameterObject)
51
+ continue;
52
+ // copy into new dictionary
53
+ requestParameterSet[parameterObject.id] = (" " + parameterObject.stringify(parameters[parameterIdOrName])).slice(1);
54
+ }
55
+ // seconds step, fill all other parameter values that are currently not set
56
+ const currentParameters = this._sessionEngineCore.parameterManager.parameterValues;
57
+ for (const parameterId in currentParameters) {
58
+ // if already set by input values, skip
59
+ if (requestParameterSet[parameterId] !== undefined)
60
+ continue;
61
+ // deep copy into new dictionary
62
+ requestParameterSet[parameterId] = (" " + currentParameters[parameterId]).slice(1);
63
+ }
64
+ return requestParameterSet;
65
+ }
66
+ /**
67
+ * Creates export objects from the current response DTO.
68
+ *
69
+ * Called internally after each customization or export request to update the exports.
70
+ * Exports of type EMAIL and DOWNLOAD are created.
71
+ *
72
+ * Called by SessionEngineCore.updateResponseDto.
73
+ */
74
+ createExportsFromDto() {
75
+ if (!this._sessionEngineCore.responseDto)
76
+ return;
77
+ for (const exportId in this._sessionEngineCore.responseDto.exports) {
78
+ if (this._sessionEngineCore.responseDto.exports[exportId].type ===
79
+ sdk_geometry_api_sdk_v2_1.ResExportDefinitionType.EMAIL ||
80
+ this._sessionEngineCore.responseDto.exports[exportId].type ===
81
+ sdk_geometry_api_sdk_v2_1.ResExportDefinitionType.DOWNLOAD) {
82
+ if (!this.exports[exportId]) {
83
+ this._sessionEngineCore.responseDto.exports[exportId].id =
84
+ exportId;
85
+ this.exports[exportId] = new Export_1.Export(this._sessionEngineCore.responseDto.exports[exportId], this._sessionEngineCore, this);
86
+ }
87
+ else {
88
+ this.exports[exportId].updateExport(this._sessionEngineCore.responseDto.exports[exportId]);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * Requests an export.
95
+ *
96
+ * @param exportId The id of the export to request
97
+ * @param parameters The parameters to use for the export
98
+ * @param maxWaitTime The maximum time to wait for the export to complete
99
+ * @param retry Whether to retry the request in case of failure
100
+ * @returns Promise with the requested export
101
+ */
102
+ requestExport(exportId, parameters, maxWaitTime, retry = false) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ this._sessionEngineCore.utilsManager.checkAvailability("export");
105
+ try {
106
+ yield this._sessionEngineCore.fileUploadManager.uploadFileParameters(parameters);
107
+ const requestParameterSet = this.cleanExportParameters(parameters);
108
+ const responseDto = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sessionEngineCore.sdkConfig).submitAndWaitForExport(this._sessionEngineCore.sessionId, { exports: [exportId], parameters: requestParameterSet }, maxWaitTime, this._sessionEngineCore.parameterManager.ignoreUnknownParams);
109
+ this._sessionEngineCore.updateResponseDto(responseDto);
110
+ return this.exports[exportId];
111
+ }
112
+ catch (e) {
113
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
114
+ return yield this.requestExport(exportId, parameters, maxWaitTime, true);
115
+ }
116
+ });
117
+ }
118
+ /**
119
+ * Requests multiple exports.
120
+ *
121
+ * @param body The export request body
122
+ * @param loadOutputs Whether to load outputs as part of the export request
123
+ * @param maxWaitMsec The maximum time to wait for the export to complete
124
+ * @param retry Whether to retry the request in case of failure
125
+ * @returns Promise with the response DTO
126
+ */
127
+ requestExports(body, loadOutputs = false, maxWaitMsec, retry = false) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ let processId;
130
+ const eventId = this._uuidGenerator.create();
131
+ // if the outputs are loaded, we treat this as a customization by sending the same events
132
+ const treatInternallyAsCustomization = loadOutputs === true &&
133
+ this._sessionEngineCore.outputManager.allowOutputLoading === true;
134
+ const eventInfo = {
135
+ type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
136
+ category: viewer_shared_types_1.TASK_CATEGORY.SESSION_CUSTOMIZATION.CUSTOMIZE_VIA_EXPORTS,
137
+ id: eventId,
138
+ data: { sessionId: this._sessionEngineCore.id },
139
+ };
140
+ this._sessionEngineCore.utilsManager.checkAvailability("export");
141
+ try {
142
+ if (treatInternallyAsCustomization) {
143
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, Object.assign(Object.assign({}, eventInfo), { progress: 0, status: "Customizing session" }));
144
+ }
145
+ // activate the busy mode if outputs are loaded
146
+ if (loadOutputs === true &&
147
+ this._sessionEngineCore.outputManager.allowOutputLoading ===
148
+ true &&
149
+ body.outputs &&
150
+ Object.keys(body.outputs).length > 0) {
151
+ processId = this._uuidGenerator.create();
152
+ this._sessionEngineCore.utilsManager.addBusyMode(processId);
153
+ }
154
+ if (treatInternallyAsCustomization) {
155
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, Object.assign(Object.assign({}, eventInfo), { progress: 0.1, status: "Uploading file parameters" }));
156
+ }
157
+ yield this._sessionEngineCore.fileUploadManager.uploadFileParameters(body.parameters);
158
+ const requestParameterSet = this.cleanExportParameters(body.parameters);
159
+ if (treatInternallyAsCustomization) {
160
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, Object.assign(Object.assign({}, eventInfo), { progress: 0.1, status: "Sending customization request" }));
161
+ }
162
+ const responseDto = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sessionEngineCore.sdkConfig).submitAndWaitForExport(this._sessionEngineCore.sessionId, {
163
+ exports: body.exports,
164
+ parameters: requestParameterSet,
165
+ outputs: body.outputs,
166
+ max_wait_time: body.max_wait_time,
167
+ }, maxWaitMsec, this._sessionEngineCore.parameterManager.ignoreUnknownParams);
168
+ this._sessionEngineCore.updateResponseDto(responseDto);
169
+ if (treatInternallyAsCustomization) {
170
+ yield this._sessionEngineCore.outputManager.updateOutputs(Object.assign(Object.assign({}, eventInfo), { progressRange: {
171
+ min: 0.1,
172
+ max: 0.9,
173
+ } }));
174
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, { sessionId: this._sessionEngineCore.id });
175
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, Object.assign(Object.assign({}, eventInfo), { progress: 1, status: "Session customized" }));
176
+ }
177
+ if (processId)
178
+ this._sessionEngineCore.utilsManager.removeBusyMode(processId);
179
+ return responseDto;
180
+ }
181
+ catch (e) {
182
+ if (treatInternallyAsCustomization) {
183
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, Object.assign(Object.assign({}, eventInfo), { progress: 1, status: "Session customization failed" }));
184
+ }
185
+ if (processId)
186
+ this._sessionEngineCore.utilsManager.removeBusyMode(processId);
187
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
188
+ return yield this.requestExports(body, loadOutputs, maxWaitMsec, true);
189
+ }
190
+ });
191
+ }
192
+ /**
193
+ * Save the export properties for displayname, order, tooltip and hidden
194
+ *
195
+ * @param exports
196
+ * @returns
197
+ */
198
+ saveExportProperties(exports, retry = false) {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ this._sessionEngineCore.utilsManager.checkAvailability("export-definition", true);
201
+ try {
202
+ yield new sdk_geometry_api_sdk_v2_1.ExportApi(this._sessionEngineCore.sdkConfig).updateExportDefinitions(this._sessionEngineCore.modelId, exports);
203
+ return true;
204
+ }
205
+ catch (e) {
206
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
207
+ return yield this.saveExportProperties(exports, true);
208
+ }
209
+ });
210
+ }
211
+ }
212
+ exports.ExportManager = ExportManager;
213
+ //# sourceMappingURL=ExportManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExportManager.js","sourceRoot":"","sources":["../../../src/implementation/managers/ExportManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iFAQ6C;AAC7C,+EAI4C;AAC5C,yEAAyE;AAGzE,0CAAqC;AAGrC;;;;;GAKG;AACH,MAAa,aAAa;IAMzB,YAAY,iBAAoC;QAL/B,iBAAY,GAAG,oCAAW,CAAC,QAAQ,CAAC;QACpC,aAAQ,GAA6B,EAAE,CAAC;QAExC,mBAAc,GAAG,sCAAa,CAAC,QAAQ,C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CAAC;iBACH;gBAED,IAAI,SAAS;oBACZ,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;gBAChE,MAAM,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACjE,OAAO,MAAM,IAAI,CAAC,cAAc,CAC/B,IAAI,EACJ,WAAW,EACX,WAAW,EACX,IAAI,CACJ,CAAC;aACF;QACF,CAAC;KAAA;IAED;;;;;OAKG;IACU,oBAAoB,CAChC,OAOC,EACD,KAAK,GAAG,KAAK;;YAEb,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,iBAAiB,CACrD,mBAAmB,EACnB,IAAI,CACJ,CAAC;YACF,IAAI;gBACH,MAAM,IAAI,mCAAS,CAClB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CACjC,CAAC,uBAAuB,CACxB,IAAI,CAAC,kBAAkB,CAAC,OAAQ,EAChC,OAAO,CACP,CAAC;gBACF,OAAO,IAAI,CAAC;aACZ;YAAC,OAAO,CAAC,EAAE;gBACX,MAAM,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACjE,OAAO,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;aACtD;QACF,CAAC;KAAA;CACD;AAxTD,sCAwTC"}
@@ -0,0 +1,74 @@
1
+ import { QueryGltfConversion, ResAssetDefinition, ResBase, ResFileInfo } from "@shapediver/sdk.geometry-api-sdk-v2";
2
+ import { SessionEngineCore } from "../SessionEngineCore";
3
+ /**
4
+ * Manager responsible for file uploads.
5
+ *
6
+ * The manager is created by the SessionEngineCore and can be accessed
7
+ * via the `fileUploadManager` property.
8
+ */
9
+ export declare class FileUploadManager {
10
+ private readonly _sessionEngineCore;
11
+ constructor(sessionEngineCore: SessionEngineCore);
12
+ get canUploadGLTF(): boolean;
13
+ /**
14
+ * Retrieves file information for a given parameter and file ID.
15
+ *
16
+ * @param parameterId The ID of the parameter
17
+ * @param fileId The ID of the file
18
+ * @param retry Whether to retry the request in case of failure
19
+ * @returns Promise with the file information
20
+ */
21
+ getFileInfo(parameterId: string, fileId: string, retry?: boolean): Promise<ResFileInfo>;
22
+ /**
23
+ * Get all file parameters from the parameter set.
24
+ * If the parameter is not set in the parameter set, the value from the parameter object is used.
25
+ *
26
+ * @param parameters
27
+ * @returns
28
+ */
29
+ getFileParameterSet(parameters: {
30
+ [key: string]: unknown;
31
+ }): {
32
+ [key: string]: string | File | Blob;
33
+ };
34
+ /**
35
+ * Uploads a file for a given parameter.
36
+ *
37
+ * @param parameterId The ID of the parameter
38
+ * @param data The file to upload
39
+ * @param type The MIME type of the file
40
+ * @param retry Whether to retry the request in case of failure
41
+ * @returns Promise with the file ID
42
+ */
43
+ uploadFile(parameterId: string, data: File, type: string, retry?: boolean): Promise<string>;
44
+ /**
45
+ * Uploads all file parameters and returns the file parameter values.
46
+ * If parameterValues is provided, the file parameter values are added to it.
47
+ *
48
+ * @param parameterValues
49
+ * @returns
50
+ */
51
+ uploadFileParameters(parameterValues?: {
52
+ [key: string]: unknown;
53
+ }): Promise<{
54
+ [key: string]: string;
55
+ }>;
56
+ /**
57
+ * Uploads a GLTF file to the session.
58
+ *
59
+ * @param blob The GLTF file as a Blob
60
+ * @param conversion The type of conversion to apply
61
+ * @param retry Whether to retry the request in case of failure
62
+ * @returns Promise with the response data
63
+ */
64
+ uploadGLTF(blob: Blob, conversion?: QueryGltfConversion, retry?: boolean): Promise<ResBase>;
65
+ /**
66
+ * Uploads SDTF files to the session.
67
+ *
68
+ * @param arrayBuffers The SDTF files as ArrayBuffers
69
+ * @param retry Whether to retry the request in case of failure
70
+ * @returns Promise with the response data
71
+ */
72
+ uploadSDTF(arrayBuffers: ArrayBuffer[], retry?: boolean): Promise<ResAssetDefinition[]>;
73
+ }
74
+ //# sourceMappingURL=FileUploadManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileUploadManager.d.ts","sourceRoot":"","sources":["../../../src/implementation/managers/FileUploadManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,mBAAmB,EAEnB,kBAAkB,EAClB,OAAO,EACP,WAAW,EAGX,MAAM,qCAAqC,CAAC;AAK7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;gBAE3C,iBAAiB,EAAE,iBAAiB;IAIhD,IAAW,aAAa,IAAI,OAAO,CASlC;IAED;;;;;;;OAOG;IACU,WAAW,CACvB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,UAAQ,GACX,OAAO,CAAC,WAAW,CAAC;IAwBvB;;;;;;OAMG;IACI,mBAAmB,CAAC,UAAU,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,GAAG;QACjE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;KACpC;IAqBD;;;;;;;;OAQG;IACU,UAAU,CACtB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,KAAK,UAAQ,GACX,OAAO,CAAC,MAAM,CAAC;IA0ClB;;;;;;OAMG;IACU,oBAAoB,CAAC,eAAe,CAAC,EAAE;QACnD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAwDpC;;;;;;;OAOG;IACU,UAAU,CACtB,IAAI,EAAE,IAAI,EACV,UAAU,GAAE,mBAA8C,EAC1D,KAAK,UAAQ,GACX,OAAO,CAAC,OAAO,CAAC;IAuBnB;;;;;;OAMG;IACU,UAAU,CACtB,YAAY,EAAE,WAAW,EAAE,EAC3B,KAAK,UAAQ,GACX,OAAO,CAAC,kBAAkB,EAAE,CAAC;CA0ChC"}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FileUploadManager = void 0;
13
+ const sdk_geometry_api_sdk_v2_1 = require("@shapediver/sdk.geometry-api-sdk-v2");
14
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
15
+ const FileParameter_1 = require("../dto/FileParameter");
16
+ /**
17
+ * Manager responsible for file uploads.
18
+ *
19
+ * The manager is created by the SessionEngineCore and can be accessed
20
+ * via the `fileUploadManager` property.
21
+ */
22
+ class FileUploadManager {
23
+ constructor(sessionEngineCore) {
24
+ this._sessionEngineCore = sessionEngineCore;
25
+ }
26
+ get canUploadGLTF() {
27
+ try {
28
+ this._sessionEngineCore.utilsManager.checkAvailability("gltf-upload");
29
+ return true;
30
+ }
31
+ catch (e) {
32
+ return false;
33
+ }
34
+ }
35
+ /**
36
+ * Retrieves file information for a given parameter and file ID.
37
+ *
38
+ * @param parameterId The ID of the parameter
39
+ * @param fileId The ID of the file
40
+ * @param retry Whether to retry the request in case of failure
41
+ * @returns Promise with the file information
42
+ */
43
+ getFileInfo(parameterId, fileId, retry = false) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ this._sessionEngineCore.utilsManager.checkAvailability();
46
+ try {
47
+ const response = yield new sdk_geometry_api_sdk_v2_1.FileApi(this._sessionEngineCore.sdkConfig).getFileMetadata(this._sessionEngineCore.sessionId, parameterId, fileId);
48
+ const { size, filename } = (0, sdk_geometry_api_sdk_v2_1.extractFileInfo)(response.headers);
49
+ return {
50
+ parameterId: parameterId,
51
+ id: fileId,
52
+ size: size,
53
+ filename: filename,
54
+ };
55
+ }
56
+ catch (e) {
57
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
58
+ return yield this.getFileInfo(parameterId, fileId, true);
59
+ }
60
+ });
61
+ }
62
+ /**
63
+ * Get all file parameters from the parameter set.
64
+ * If the parameter is not set in the parameter set, the value from the parameter object is used.
65
+ *
66
+ * @param parameters
67
+ * @returns
68
+ */
69
+ getFileParameterSet(parameters) {
70
+ const fileParameterSet = {};
71
+ for (const parameterId in this._sessionEngineCore.parameterManager
72
+ .parameters) {
73
+ if (this._sessionEngineCore.parameterManager.parameters[parameterId] instanceof FileParameter_1.FileParameter) {
74
+ fileParameterSet[parameterId] =
75
+ parameters[parameterId] !== undefined
76
+ ? parameters[parameterId]
77
+ : this._sessionEngineCore.parameterManager
78
+ .parameters[parameterId].value;
79
+ }
80
+ }
81
+ return fileParameterSet;
82
+ }
83
+ /**
84
+ * Uploads a file for a given parameter.
85
+ *
86
+ * @param parameterId The ID of the parameter
87
+ * @param data The file to upload
88
+ * @param type The MIME type of the file
89
+ * @param retry Whether to retry the request in case of failure
90
+ * @returns Promise with the file ID
91
+ */
92
+ uploadFile(parameterId, data, type, retry = false) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ this._sessionEngineCore.utilsManager.checkAvailability("file-upload");
95
+ try {
96
+ const result = (yield new sdk_geometry_api_sdk_v2_1.FileApi(this._sessionEngineCore.sdkConfig).uploadFile(this._sessionEngineCore.sessionId, {
97
+ [parameterId]: {
98
+ size: data.size,
99
+ format: type,
100
+ filename: data.name === "" ? undefined : data.name,
101
+ },
102
+ })).data;
103
+ if (result &&
104
+ result.asset &&
105
+ result.asset.file &&
106
+ result.asset.file[parameterId]) {
107
+ const fileAsset = result.asset.file[parameterId];
108
+ yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sessionEngineCore.sdkConfig).uploadAsset(fileAsset.href, yield data.arrayBuffer(), fileAsset.headers);
109
+ return fileAsset.id;
110
+ }
111
+ else {
112
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.uploadFile: Upload reply has not the required format.");
113
+ }
114
+ }
115
+ catch (e) {
116
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
117
+ return yield this.uploadFile(parameterId, data, type, true);
118
+ }
119
+ });
120
+ }
121
+ /**
122
+ * Uploads all file parameters and returns the file parameter values.
123
+ * If parameterValues is provided, the file parameter values are added to it.
124
+ *
125
+ * @param parameterValues
126
+ * @returns
127
+ */
128
+ uploadFileParameters(parameterValues) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const parameterValueSet = parameterValues !== undefined
131
+ ? this.getFileParameterSet(parameterValues)
132
+ : undefined;
133
+ const fileParameterValues = {};
134
+ // load file parameter first
135
+ for (const parameterId in this._sessionEngineCore.parameterManager
136
+ .parameters) {
137
+ if (this._sessionEngineCore.parameterManager.parameters[parameterId] instanceof FileParameter_1.FileParameter) {
138
+ fileParameterValues[parameterId] = yield (this._sessionEngineCore.parameterManager.parameters[parameterId]).upload(parameterValueSet
139
+ ? parameterValueSet[parameterId]
140
+ : undefined);
141
+ if (parameterValues &&
142
+ parameterValues[parameterId] !== undefined) {
143
+ // if a value was provided, we replace it with the returned id
144
+ parameterValues[parameterId] =
145
+ fileParameterValues[parameterId];
146
+ // if the parameter value of the file parameter was used, set the value to the parameter
147
+ if (this._sessionEngineCore.parameterManager.parameters[parameterId].value !== fileParameterValues[parameterId])
148
+ this._sessionEngineCore.parameterManager.parameters[parameterId].value = fileParameterValues[parameterId];
149
+ }
150
+ else if (this._sessionEngineCore.parameterManager.parameters[parameterId].value !== fileParameterValues[parameterId]) {
151
+ this._sessionEngineCore.parameterManager.parameters[parameterId].value = fileParameterValues[parameterId];
152
+ }
153
+ }
154
+ }
155
+ return fileParameterValues;
156
+ });
157
+ }
158
+ /**
159
+ * Uploads a GLTF file to the session.
160
+ *
161
+ * @param blob The GLTF file as a Blob
162
+ * @param conversion The type of conversion to apply
163
+ * @param retry Whether to retry the request in case of failure
164
+ * @returns Promise with the response data
165
+ */
166
+ uploadGLTF(blob, conversion = sdk_geometry_api_sdk_v2_1.QueryGltfConversion.NONE, retry = false) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ this._sessionEngineCore.utilsManager.checkAvailability("gltf-upload");
169
+ try {
170
+ const responseDto = (yield new sdk_geometry_api_sdk_v2_1.GltfApi(this._sessionEngineCore.sdkConfig).uploadGltf(this._sessionEngineCore.sessionId, new File([blob], "model.gltf", {
171
+ type: "model/gltf-binary",
172
+ }), conversion)).data;
173
+ if (!responseDto || !responseDto.gltf || !responseDto.gltf.href)
174
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.uploadGLTF: Upload reply has not the required format.");
175
+ return responseDto;
176
+ }
177
+ catch (e) {
178
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
179
+ return yield this.uploadGLTF(blob, conversion, true);
180
+ }
181
+ });
182
+ }
183
+ /**
184
+ * Uploads SDTF files to the session.
185
+ *
186
+ * @param arrayBuffers The SDTF files as ArrayBuffers
187
+ * @param retry Whether to retry the request in case of failure
188
+ * @returns Promise with the response data
189
+ */
190
+ uploadSDTF(arrayBuffers, retry = false) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ this._sessionEngineCore.utilsManager.checkAvailability("file-upload");
193
+ try {
194
+ const responseDto = (yield new sdk_geometry_api_sdk_v2_1.SdtfApi(this._sessionEngineCore.sdkConfig).uploadSdtf(this._sessionEngineCore.sessionId, arrayBuffers.map((arrayBuffer) => {
195
+ return {
196
+ namespace: "pub",
197
+ content_length: arrayBuffer.byteLength,
198
+ content_type: sdk_geometry_api_sdk_v2_1.ReqSdtfType.MODEL_SDTF,
199
+ };
200
+ }))).data;
201
+ if (!responseDto ||
202
+ !responseDto.asset ||
203
+ !responseDto.asset.sdtf ||
204
+ responseDto.asset.sdtf.length !== arrayBuffers.length)
205
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.uploadSDTF: Upload reply has not the required format.");
206
+ const promises = arrayBuffers.map((buffer, index) => {
207
+ const url = responseDto.asset.sdtf[index].href;
208
+ return new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sessionEngineCore.sdkConfig).upload(url, buffer, sdk_geometry_api_sdk_v2_1.ReqSdtfType.MODEL_SDTF);
209
+ });
210
+ yield Promise.all(promises);
211
+ return responseDto.asset.sdtf;
212
+ }
213
+ catch (e) {
214
+ yield this._sessionEngineCore.utilsManager.handleError(e, retry);
215
+ return yield this.uploadSDTF(arrayBuffers, true);
216
+ }
217
+ });
218
+ }
219
+ }
220
+ exports.FileUploadManager = FileUploadManager;
221
+ //# sourceMappingURL=FileUploadManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileUploadManager.js","sourceRoot":"","sources":["../../../src/implementation/managers/FileUploadManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iFAW6C;AAC7C,+EAAgF;AAGhF,wDAAmD;AAGnD;;;;;GAKG;AACH,MAAa,iBAAiB;IAG7B,YAAY,iBAAoC;QAC/C,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,IAAW,aAAa;QACvB,IAAI;YACH,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,iBAAiB,CACrD,aAAa,CACb,CAAC;YACF,OAAO,IAAI,CAAC;SACZ;QAAC,OAAO,CAAC,EAAE;YACX,OAAO,KAAK,CAAC;SACb;IACF,CAAC;IAED;;;;;;;OAOG;IACU,WAAW,CACvB,WAAmB,EACnB,MAAc,EACd,KAAK,GAAG,KAAK;;YAEb,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,iBAAiB,EAAE,CAAC;YACzD,IAA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