@leapdev/app-platform 0.1.0-beta.26 → 0.1.0-beta.28
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/package.json +2 -2
- package/src/index.d.ts +9 -0
- package/src/index.js +12 -1
- package/src/lib/app-platform.d.ts +16 -0
- package/src/lib/app-platform.js +59 -38
- package/src/lib/domains/leap-document-data/index.d.ts +8 -0
- package/src/lib/domains/leap-document-data/index.js +11 -0
- package/src/lib/domains/leap-document-data/leap-document-data.model.d.ts +7 -0
- package/src/lib/domains/leap-document-data/leap-document-data.model.js +11 -0
- package/src/lib/domains/leap-document-data/leap-document-data.normalizer.d.ts +19 -0
- package/src/lib/domains/leap-document-data/leap-document-data.normalizer.js +101 -0
- package/src/lib/domains/leap-document-data/leap-document-data.service.d.ts +90 -0
- package/src/lib/domains/leap-document-data/leap-document-data.service.js +156 -0
- package/src/lib/ports/adapters/excel-custom-xml-part.adapter.d.ts +15 -0
- package/src/lib/ports/adapters/excel-custom-xml-part.adapter.js +113 -0
- package/src/lib/ports/adapters/in-memory-custom-xml-part.adapter.d.ts +22 -0
- package/src/lib/ports/adapters/in-memory-custom-xml-part.adapter.js +52 -0
- package/src/lib/ports/adapters/word-custom-xml-part.adapter.d.ts +16 -0
- package/src/lib/ports/adapters/word-custom-xml-part.adapter.js +118 -0
- package/src/lib/ports/custom-xml-part.port.d.ts +44 -0
- package/src/lib/ports/custom-xml-part.port.js +2 -0
- package/src/lib/ports/index.d.ts +7 -0
- package/src/lib/ports/index.js +10 -0
- package/src/lib/services/signalr/signalr.service.d.ts +7 -0
- package/src/lib/services/signalr/signalr.service.js +77 -76
- package/src/types.d.ts +3 -2
- package/src/types.js +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leapdev/app-platform",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.28",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.0",
|
|
6
6
|
"vkbeautify": "^0.99.3",
|
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
"type": "commonjs",
|
|
15
15
|
"main": "./src/index.js",
|
|
16
16
|
"typings": "./src/index.d.ts"
|
|
17
|
-
}
|
|
17
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { EvaluatePathsRequest } from './lib/models';
|
|
2
2
|
import { HostApplicationType, LeapDocumentData } from './lib/models/leap.model';
|
|
3
3
|
export * from './types';
|
|
4
|
+
export * from './lib/ports';
|
|
5
|
+
export * from './lib/domains/leap-document-data';
|
|
4
6
|
export declare const initAppPlatform: (hostApplicationType: HostApplicationType, skipLeapEventsSetup?: boolean) => Promise<{
|
|
5
7
|
done: boolean;
|
|
6
8
|
openViaLEAP: boolean;
|
|
@@ -39,6 +41,13 @@ export declare const openDocumentViaSignalR: (params: {
|
|
|
39
41
|
documentId: string;
|
|
40
42
|
matterId: string;
|
|
41
43
|
}) => Promise<boolean>;
|
|
44
|
+
export declare const openMatterViaSignalR: (params: {
|
|
45
|
+
matterId: string;
|
|
46
|
+
}) => Promise<boolean>;
|
|
47
|
+
export declare const setBookmarkViaSignalR: (params: {
|
|
48
|
+
matterId: string;
|
|
49
|
+
tables: unknown[];
|
|
50
|
+
}) => Promise<boolean>;
|
|
42
51
|
export declare const saveDocument: () => Promise<{
|
|
43
52
|
documentVersionId: string;
|
|
44
53
|
}>;
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.saveDocument = exports.openDocumentViaSignalR = exports.connectSignalR = exports.getInitDataViaSignalR = exports.getLEAPUserViaSignalR = exports.getLEAPTokenViaSignalR = exports.createDocument = exports.evaluatePaths = exports.getAddinData = exports.updateDocumentData = exports.getDocumentData = exports.getHostInfo = exports.setupLeapEventsAndSetToken = exports.initAppPlatform = void 0;
|
|
3
|
+
exports.saveDocument = exports.setBookmarkViaSignalR = exports.openMatterViaSignalR = exports.openDocumentViaSignalR = exports.connectSignalR = exports.getInitDataViaSignalR = exports.getLEAPUserViaSignalR = exports.getLEAPTokenViaSignalR = exports.createDocument = exports.evaluatePaths = exports.getAddinData = exports.updateDocumentData = exports.getDocumentData = exports.getHostInfo = exports.setupLeapEventsAndSetToken = exports.initAppPlatform = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const app_platform_1 = require("./lib/app-platform");
|
|
6
6
|
tslib_1.__exportStar(require("./types"), exports);
|
|
7
|
+
// Export domain pattern: ports, adapters, and domain services
|
|
8
|
+
tslib_1.__exportStar(require("./lib/ports"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/domains/leap-document-data"), exports);
|
|
7
10
|
const appPlatform = new app_platform_1.AppPlatform();
|
|
8
11
|
const initAppPlatform = (hostApplicationType, skipLeapEventsSetup = false) => {
|
|
9
12
|
return appPlatform.init(hostApplicationType, skipLeapEventsSetup);
|
|
@@ -57,6 +60,14 @@ const openDocumentViaSignalR = (params) => {
|
|
|
57
60
|
return appPlatform.openDocumentViaSignalR(params);
|
|
58
61
|
};
|
|
59
62
|
exports.openDocumentViaSignalR = openDocumentViaSignalR;
|
|
63
|
+
const openMatterViaSignalR = (params) => {
|
|
64
|
+
return appPlatform.openMatterViaSignalR(params);
|
|
65
|
+
};
|
|
66
|
+
exports.openMatterViaSignalR = openMatterViaSignalR;
|
|
67
|
+
const setBookmarkViaSignalR = (params) => {
|
|
68
|
+
return appPlatform.setBookmarkViaSignalR(params);
|
|
69
|
+
};
|
|
70
|
+
exports.setBookmarkViaSignalR = setBookmarkViaSignalR;
|
|
60
71
|
const saveDocument = () => {
|
|
61
72
|
return appPlatform.saveDocument();
|
|
62
73
|
};
|
|
@@ -10,6 +10,11 @@ export declare class AppPlatform {
|
|
|
10
10
|
private signalRService;
|
|
11
11
|
private _openViaLEAP;
|
|
12
12
|
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Get the session-scoped LeapDocumentDataService.
|
|
15
|
+
* Throws if init() was not called with a valid host.
|
|
16
|
+
*/
|
|
17
|
+
private getLeapDocumentDataService;
|
|
13
18
|
init(hostApplicationType: HostApplicationType, skipLeapEventsSetup: boolean, force?: boolean): Promise<{
|
|
14
19
|
done: boolean;
|
|
15
20
|
openViaLEAP: boolean;
|
|
@@ -32,7 +37,18 @@ export declare class AppPlatform {
|
|
|
32
37
|
matterId: string;
|
|
33
38
|
documentId: string;
|
|
34
39
|
}): Promise<boolean>;
|
|
40
|
+
openMatterViaSignalR(params: {
|
|
41
|
+
matterId: string;
|
|
42
|
+
}): Promise<boolean>;
|
|
43
|
+
setBookmarkViaSignalR(params: {
|
|
44
|
+
matterId: string;
|
|
45
|
+
tables: unknown[];
|
|
46
|
+
}): Promise<boolean>;
|
|
35
47
|
getDocumentData(): Promise<LeapDocumentData | null>;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use getDocumentData() instead. The host is now determined by init().
|
|
50
|
+
* This method will be removed in a future version.
|
|
51
|
+
*/
|
|
36
52
|
getExcelDocumentData(): Promise<LeapDocumentData | null>;
|
|
37
53
|
setDocumentData(params: {
|
|
38
54
|
documentData: LeapDocumentData;
|
package/src/lib/app-platform.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _AppPlatform_authService, _AppPlatform_signalRInitData, _AppPlatform_initialized, _AppPlatform_connectedToSignalR;
|
|
2
|
+
var _AppPlatform_leapDocumentDataService, _AppPlatform_authService, _AppPlatform_signalRInitData, _AppPlatform_initialized, _AppPlatform_connectedToSignalR, _AppPlatform_hostApplicationType;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.AppPlatform = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const helpers_1 = require("./functions/helpers");
|
|
7
|
+
const leap_document_data_1 = require("./domains/leap-document-data");
|
|
7
8
|
const constants_1 = require("./models/constants");
|
|
8
9
|
const leap_events_model_1 = require("./models/leap-events.model");
|
|
9
10
|
const leap_model_1 = require("./models/leap.model");
|
|
@@ -11,28 +12,45 @@ const services_1 = require("./services");
|
|
|
11
12
|
const auth_service_1 = require("./services/auth/auth.service");
|
|
12
13
|
const promise_helper_function_1 = require("./services/calc-api/promise-helper.function");
|
|
13
14
|
const custom_xml_part_service_1 = require("./services/custom-xml-part.service");
|
|
14
|
-
const excel_custom_xml_part_service_1 = require("./services/excel-custom-xml-part.service");
|
|
15
15
|
const leap_events_service_1 = require("./services/leap-events.service");
|
|
16
16
|
const signalr_service_1 = require("./services/signalr/signalr.service");
|
|
17
17
|
class AppPlatform {
|
|
18
18
|
constructor() {
|
|
19
|
+
_AppPlatform_leapDocumentDataService.set(this, null);
|
|
19
20
|
this._openViaLEAP = false;
|
|
20
21
|
_AppPlatform_authService.set(this, null);
|
|
21
22
|
_AppPlatform_signalRInitData.set(this, null);
|
|
22
23
|
_AppPlatform_initialized.set(this, false);
|
|
23
24
|
_AppPlatform_connectedToSignalR.set(this, false);
|
|
25
|
+
_AppPlatform_hostApplicationType.set(this, null);
|
|
24
26
|
this.loggerService = new services_1.LoggerService(false);
|
|
25
27
|
this.leapEventsService = new leap_events_service_1.LeapEventsService();
|
|
26
28
|
this.calcWordService = new services_1.CalcWordService(this.leapEventsService, this.loggerService);
|
|
27
29
|
this.documentService = new services_1.DocumentService(this.leapEventsService, this.loggerService);
|
|
28
30
|
this.signalRService = new signalr_service_1.SignalRService();
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Get the session-scoped LeapDocumentDataService.
|
|
34
|
+
* Throws if init() was not called with a valid host.
|
|
35
|
+
*/
|
|
36
|
+
getLeapDocumentDataService() {
|
|
37
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AppPlatform_hostApplicationType, "f")) {
|
|
38
|
+
throw new Error('AppPlatform.init() must be called with a valid host before accessing document data. ' +
|
|
39
|
+
'Call initAppPlatform(HostApplicationType) first.');
|
|
40
|
+
}
|
|
41
|
+
if (!tslib_1.__classPrivateFieldGet(this, _AppPlatform_leapDocumentDataService, "f")) {
|
|
42
|
+
tslib_1.__classPrivateFieldSet(this, _AppPlatform_leapDocumentDataService, new leap_document_data_1.LeapDocumentDataService(tslib_1.__classPrivateFieldGet(this, _AppPlatform_hostApplicationType, "f")), "f");
|
|
43
|
+
}
|
|
44
|
+
return tslib_1.__classPrivateFieldGet(this, _AppPlatform_leapDocumentDataService, "f");
|
|
45
|
+
}
|
|
30
46
|
init(hostApplicationType, skipLeapEventsSetup, force = false) {
|
|
31
47
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
48
|
try {
|
|
33
49
|
if (tslib_1.__classPrivateFieldGet(this, _AppPlatform_initialized, "f") && !force) {
|
|
34
50
|
return { done: true, openViaLEAP: this._openViaLEAP };
|
|
35
51
|
}
|
|
52
|
+
// Store host for session-scoped document data service
|
|
53
|
+
tslib_1.__classPrivateFieldSet(this, _AppPlatform_hostApplicationType, hostApplicationType, "f");
|
|
36
54
|
let openViaLEAP = false;
|
|
37
55
|
switch (hostApplicationType) {
|
|
38
56
|
case leap_model_1.HostApplicationType.MicrosoftWord:
|
|
@@ -112,17 +130,8 @@ class AppPlatform {
|
|
|
112
130
|
getHostInfo(params) {
|
|
113
131
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
114
132
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
case leap_model_1.HostApplicationType.MicrosoftWord: {
|
|
118
|
-
documentData = yield this.getDocumentData();
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
case leap_model_1.HostApplicationType.MicrosoftExcel: {
|
|
122
|
-
documentData = yield this.getExcelDocumentData();
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
133
|
+
// Use session-scoped document data service (host passed at init)
|
|
134
|
+
const documentData = yield this.getDocumentData();
|
|
126
135
|
if (documentData && documentData.hostType) {
|
|
127
136
|
return {
|
|
128
137
|
hostType: documentData.hostType,
|
|
@@ -213,14 +222,36 @@ class AppPlatform {
|
|
|
213
222
|
});
|
|
214
223
|
}
|
|
215
224
|
openDocumentViaSignalR(params) {
|
|
225
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
try {
|
|
227
|
+
const done = yield this.signalRService.openDocument(params);
|
|
228
|
+
return done;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
openMatterViaSignalR(params) {
|
|
236
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
try {
|
|
238
|
+
const done = yield this.signalRService.openMatter(params);
|
|
239
|
+
return done;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
setBookmarkViaSignalR(params) {
|
|
216
247
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
217
248
|
try {
|
|
218
249
|
if (!this._openViaLEAP) {
|
|
219
|
-
this.loggerService.log(`[
|
|
250
|
+
this.loggerService.log(`[setBookmarkViaSignalR] Document not open via LEAP`);
|
|
220
251
|
return false;
|
|
221
252
|
}
|
|
222
253
|
else {
|
|
223
|
-
const done = yield this.signalRService.
|
|
254
|
+
const done = yield this.signalRService.setBookmark(params);
|
|
224
255
|
return done;
|
|
225
256
|
}
|
|
226
257
|
}
|
|
@@ -232,11 +263,8 @@ class AppPlatform {
|
|
|
232
263
|
getDocumentData() {
|
|
233
264
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
234
265
|
try {
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
return data;
|
|
238
|
-
}
|
|
239
|
-
return null;
|
|
266
|
+
const service = this.getLeapDocumentDataService();
|
|
267
|
+
return yield service.get();
|
|
240
268
|
}
|
|
241
269
|
catch (error) {
|
|
242
270
|
this.loggerService.error(`[ERROR] Get Document Data: ${error}`);
|
|
@@ -244,16 +272,14 @@ class AppPlatform {
|
|
|
244
272
|
}
|
|
245
273
|
});
|
|
246
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* @deprecated Use getDocumentData() instead. The host is now determined by init().
|
|
277
|
+
* This method will be removed in a future version.
|
|
278
|
+
*/
|
|
247
279
|
getExcelDocumentData() {
|
|
248
280
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return data;
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
this.loggerService.error(`[ERROR] Get Excel Document Data: ${error}`);
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
281
|
+
this.loggerService.warn('[DEPRECATED] getExcelDocumentData() is deprecated. Use getDocumentData() instead.');
|
|
282
|
+
return this.getDocumentData();
|
|
257
283
|
});
|
|
258
284
|
}
|
|
259
285
|
setDocumentData(params) {
|
|
@@ -264,14 +290,9 @@ class AppPlatform {
|
|
|
264
290
|
this.loggerService.log(`[setDocumentData] Document not open via LEAP`);
|
|
265
291
|
return false;
|
|
266
292
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
.map(([key, value]) => ` <${key}>${value}</${key}>`)
|
|
271
|
-
.join('\n')}
|
|
272
|
-
</${constants_1.constants.LeapDocumentDataRootTagName}>`;
|
|
273
|
-
const data = yield (0, custom_xml_part_service_1.updateXmlDataByNamespace)(constants_1.constants.LeapDocumentDataNamespace, leapDocumentDataXml, constants_1.constants.LeapDocumentDataRootTagName);
|
|
274
|
-
return data;
|
|
293
|
+
const service = this.getLeapDocumentDataService();
|
|
294
|
+
yield service.set(documentData);
|
|
295
|
+
return true;
|
|
275
296
|
}
|
|
276
297
|
catch (error) {
|
|
277
298
|
this.loggerService.error(`[ERROR] Set Document Data: ${error}`);
|
|
@@ -283,7 +304,7 @@ class AppPlatform {
|
|
|
283
304
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
284
305
|
try {
|
|
285
306
|
if (!this._openViaLEAP) {
|
|
286
|
-
this.loggerService.log(`[
|
|
307
|
+
this.loggerService.log(`[getAddinData] Document not open via LEAP`);
|
|
287
308
|
return null;
|
|
288
309
|
}
|
|
289
310
|
const addInData = yield (0, custom_xml_part_service_1.getDataByNamespace)(constants_1.constants.LeapOfficeAddInDataNamespace);
|
|
@@ -442,4 +463,4 @@ class AppPlatform {
|
|
|
442
463
|
}
|
|
443
464
|
}
|
|
444
465
|
exports.AppPlatform = AppPlatform;
|
|
445
|
-
_AppPlatform_authService = new WeakMap(), _AppPlatform_signalRInitData = new WeakMap(), _AppPlatform_initialized = new WeakMap(), _AppPlatform_connectedToSignalR = new WeakMap();
|
|
466
|
+
_AppPlatform_leapDocumentDataService = new WeakMap(), _AppPlatform_authService = new WeakMap(), _AppPlatform_signalRInitData = new WeakMap(), _AppPlatform_initialized = new WeakMap(), _AppPlatform_connectedToSignalR = new WeakMap(), _AppPlatform_hostApplicationType = new WeakMap();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/**
|
|
5
|
+
* Barrel export for the LeapDocumentData domain.
|
|
6
|
+
*
|
|
7
|
+
* Domain pattern: model, normalizer, service
|
|
8
|
+
*/
|
|
9
|
+
tslib_1.__exportStar(require("./leap-document-data.model"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./leap-document-data.normalizer"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./leap-document-data.service"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export the LeapDocumentData model from the main models directory.
|
|
3
|
+
*
|
|
4
|
+
* This maintains backward compatibility while establishing the domain pattern.
|
|
5
|
+
* Future domains should define their models here directly.
|
|
6
|
+
*/
|
|
7
|
+
export { LeapDocumentData } from '../../models/leap.model';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LeapDocumentData = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Re-export the LeapDocumentData model from the main models directory.
|
|
6
|
+
*
|
|
7
|
+
* This maintains backward compatibility while establishing the domain pattern.
|
|
8
|
+
* Future domains should define their models here directly.
|
|
9
|
+
*/
|
|
10
|
+
var leap_model_1 = require("../../models/leap.model");
|
|
11
|
+
Object.defineProperty(exports, "LeapDocumentData", { enumerable: true, get: function () { return leap_model_1.LeapDocumentData; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizer for LeapDocumentData domain.
|
|
3
|
+
*
|
|
4
|
+
* Provides type coercion and serialization for LeapDocumentData custom XML.
|
|
5
|
+
*/
|
|
6
|
+
import { LeapDocumentData } from './leap-document-data.model';
|
|
7
|
+
/**
|
|
8
|
+
* Coerce raw LeapDocumentData XML (via xml2js) into typed LeapDocumentData.
|
|
9
|
+
* XML text nodes arrive as strings; only known fields are coerced.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeLeapDocumentData(raw: Record<string, unknown> | null | undefined): LeapDocumentData | null;
|
|
12
|
+
/**
|
|
13
|
+
* Serialize a LeapDocumentData field value for custom XML text content.
|
|
14
|
+
*/
|
|
15
|
+
export declare function serializeLeapDocumentDataValue(value: unknown): string;
|
|
16
|
+
/**
|
|
17
|
+
* Serialize LeapDocumentData to XML-ready entries.
|
|
18
|
+
*/
|
|
19
|
+
export declare function serializeLeapDocumentDataEntries(documentData: LeapDocumentData): Array<[string, string]>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizer for LeapDocumentData domain.
|
|
4
|
+
*
|
|
5
|
+
* Provides type coercion and serialization for LeapDocumentData custom XML.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.serializeLeapDocumentDataEntries = exports.serializeLeapDocumentDataValue = exports.normalizeLeapDocumentData = void 0;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const leap_document_data_model_1 = require("./leap-document-data.model");
|
|
11
|
+
/**
|
|
12
|
+
* Parse boolean values from XML strings.
|
|
13
|
+
* @param value - Raw value from XML parser
|
|
14
|
+
* @returns Boolean value
|
|
15
|
+
*/
|
|
16
|
+
function parseBoolean(value) {
|
|
17
|
+
switch (typeof value) {
|
|
18
|
+
case 'boolean':
|
|
19
|
+
return value;
|
|
20
|
+
case 'string':
|
|
21
|
+
return value.toLowerCase() === 'true';
|
|
22
|
+
default:
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse number values from XML strings.
|
|
28
|
+
* @param value - Raw value from XML parser
|
|
29
|
+
* @returns Parsed number or undefined
|
|
30
|
+
*/
|
|
31
|
+
function parseNumber(value) {
|
|
32
|
+
switch (typeof value) {
|
|
33
|
+
case 'number':
|
|
34
|
+
return Number.isNaN(value) ? undefined : value;
|
|
35
|
+
case 'string': {
|
|
36
|
+
if (value.trim() === '') {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const parsed = parseInt(value, 10);
|
|
40
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse array values from XML (handles both arrays and single values).
|
|
48
|
+
*/
|
|
49
|
+
function normalizeStates(value) {
|
|
50
|
+
if (value == null || value === '') {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
return value.map((item) => String(item));
|
|
55
|
+
}
|
|
56
|
+
return [String(value)];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Coerce raw LeapDocumentData XML (via xml2js) into typed LeapDocumentData.
|
|
60
|
+
* XML text nodes arrive as strings; only known fields are coerced.
|
|
61
|
+
*/
|
|
62
|
+
function normalizeLeapDocumentData(raw) {
|
|
63
|
+
if (!raw || typeof raw !== 'object') {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const { isCoauthoringDocument, requireLogout, states } = raw, rest = tslib_1.__rest(raw, ["isCoauthoringDocument", "requireLogout", "states"]);
|
|
67
|
+
return new leap_document_data_model_1.LeapDocumentData(Object.assign(Object.assign({}, rest), { isCoauthoringDocument: isCoauthoringDocument === undefined || isCoauthoringDocument === ''
|
|
68
|
+
? undefined
|
|
69
|
+
: parseBoolean(isCoauthoringDocument), requireLogout: requireLogout === undefined || requireLogout === ''
|
|
70
|
+
? undefined
|
|
71
|
+
: parseBoolean(requireLogout), states: normalizeStates(states) }));
|
|
72
|
+
}
|
|
73
|
+
exports.normalizeLeapDocumentData = normalizeLeapDocumentData;
|
|
74
|
+
/**
|
|
75
|
+
* Serialize a LeapDocumentData field value for custom XML text content.
|
|
76
|
+
*/
|
|
77
|
+
function serializeLeapDocumentDataValue(value) {
|
|
78
|
+
if (value == null) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
if (typeof value === 'boolean' || typeof value === 'number') {
|
|
82
|
+
return String(value);
|
|
83
|
+
}
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
return value.map((item) => String(item)).join(',');
|
|
86
|
+
}
|
|
87
|
+
if (typeof value === 'object') {
|
|
88
|
+
return JSON.stringify(value);
|
|
89
|
+
}
|
|
90
|
+
return String(value);
|
|
91
|
+
}
|
|
92
|
+
exports.serializeLeapDocumentDataValue = serializeLeapDocumentDataValue;
|
|
93
|
+
/**
|
|
94
|
+
* Serialize LeapDocumentData to XML-ready entries.
|
|
95
|
+
*/
|
|
96
|
+
function serializeLeapDocumentDataEntries(documentData) {
|
|
97
|
+
return Object.entries(documentData)
|
|
98
|
+
.filter(([, value]) => value !== undefined)
|
|
99
|
+
.map(([key, value]) => [key, serializeLeapDocumentDataValue(value)]);
|
|
100
|
+
}
|
|
101
|
+
exports.serializeLeapDocumentDataEntries = serializeLeapDocumentDataEntries;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { HostApplicationType } from '../../models/leap.model';
|
|
2
|
+
import { CustomXmlPartPort } from '../../ports/custom-xml-part.port';
|
|
3
|
+
import { LeapDocumentData } from './leap-document-data.model';
|
|
4
|
+
/**
|
|
5
|
+
* Domain service for LeapDocumentData custom XML operations.
|
|
6
|
+
*
|
|
7
|
+
* Primary usage (host-based):
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const service = new LeapDocumentDataService(HostApplicationType.Word);
|
|
10
|
+
* const data = await service.get();
|
|
11
|
+
* await service.upsert({ matterId: '12345' });
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Testing usage (inject custom port):
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const service = LeapDocumentDataService.forPort(new InMemoryCustomXmlPartAdapter());
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Implements item-level operations via: read → mutate → serialize → setXml.
|
|
20
|
+
*
|
|
21
|
+
* Strategy:
|
|
22
|
+
* - Read: getXml → parse → normalize
|
|
23
|
+
* - Update: getXml → parse → merge → serialize → setXml
|
|
24
|
+
* - Upsert: attempts update, preserves unknown nodes by merging
|
|
25
|
+
*
|
|
26
|
+
* Conflict resolution: last-write-wins at the field level.
|
|
27
|
+
* Unknown nodes (fields not in LeapDocumentData type) are preserved during updates.
|
|
28
|
+
*/
|
|
29
|
+
export declare class LeapDocumentDataService {
|
|
30
|
+
private readonly xmlPort;
|
|
31
|
+
private readonly namespace;
|
|
32
|
+
private readonly rootTagName;
|
|
33
|
+
/**
|
|
34
|
+
* Create a LeapDocumentDataService for a specific Office host.
|
|
35
|
+
*
|
|
36
|
+
* Automatically selects the appropriate adapter and uses standard LeapDocumentData namespace/root.
|
|
37
|
+
*
|
|
38
|
+
* @param hostType - The Office host application type (Word or Excel)
|
|
39
|
+
*/
|
|
40
|
+
constructor(hostType: HostApplicationType);
|
|
41
|
+
/**
|
|
42
|
+
* Create a LeapDocumentDataService with a custom port (for testing or advanced use cases).
|
|
43
|
+
*
|
|
44
|
+
* @param xmlPort - Custom XML part port implementation
|
|
45
|
+
* @param namespace - Custom XML namespace (defaults to LeapDocumentData namespace)
|
|
46
|
+
* @param rootTagName - Root XML tag name (defaults to LeapDocumentData root)
|
|
47
|
+
*/
|
|
48
|
+
constructor(xmlPort: CustomXmlPartPort, namespace?: string, rootTagName?: string);
|
|
49
|
+
/**
|
|
50
|
+
* Create a LeapDocumentDataService with a custom port.
|
|
51
|
+
*
|
|
52
|
+
* Use this for unit testing with InMemoryCustomXmlPartAdapter or for advanced scenarios
|
|
53
|
+
* where you need to provide a custom port implementation.
|
|
54
|
+
*
|
|
55
|
+
* @param xmlPort - Custom XML part port implementation
|
|
56
|
+
* @param namespace - Optional custom namespace (defaults to LeapDocumentData namespace)
|
|
57
|
+
* @param rootTagName - Optional custom root tag (defaults to LeapDocumentData root)
|
|
58
|
+
*/
|
|
59
|
+
static forPort(xmlPort: CustomXmlPartPort, namespace?: string, rootTagName?: string): LeapDocumentDataService;
|
|
60
|
+
private createAdapterForHost;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current LeapDocumentData from the custom XML part.
|
|
63
|
+
*/
|
|
64
|
+
get(): Promise<LeapDocumentData | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Set (replace) the LeapDocumentData in the custom XML part.
|
|
67
|
+
*
|
|
68
|
+
* This performs a full replacement. Use `upsert` to preserve unknown fields.
|
|
69
|
+
*/
|
|
70
|
+
set(documentData: LeapDocumentData): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Upsert (update or insert) LeapDocumentData fields.
|
|
73
|
+
*
|
|
74
|
+
* Preserves unknown fields present in the existing XML part.
|
|
75
|
+
* If no part exists, creates one with the provided data.
|
|
76
|
+
*/
|
|
77
|
+
upsert(documentData: Partial<LeapDocumentData>): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Delete the LeapDocumentData custom XML part.
|
|
80
|
+
*/
|
|
81
|
+
delete(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Ensure the custom XML part exists (create if missing).
|
|
84
|
+
*/
|
|
85
|
+
ensurePart(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Serialize LeapDocumentData to XML string.
|
|
88
|
+
*/
|
|
89
|
+
private serializeToXml;
|
|
90
|
+
}
|