dataverse-utils 2.5.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assemblyDeploy.js +2 -3
- package/lib/models/customApi.js +35 -25
- package/lib/models/pluginAssembly.js +8 -16
- package/lib/models/pluginPackage.js +8 -13
- package/lib/models/pluginStep.js +7 -12
- package/lib/models/pluginType.js +2 -2
- package/lib/models/webResource.js +7 -11
- package/package.json +3 -3
package/lib/assemblyDeploy.js
CHANGED
|
@@ -41,14 +41,13 @@ async function assemblyDeploy(creds, apiConfig) {
|
|
|
41
41
|
}
|
|
42
42
|
logger_1.logger.done(`deployed assembly ${config.name}\r\n`);
|
|
43
43
|
}
|
|
44
|
-
if (config.
|
|
44
|
+
if (config.customapis != null && assemblyId) {
|
|
45
45
|
try {
|
|
46
|
-
const promises = config.
|
|
46
|
+
const promises = config.customapis.map((a) => (0, customApi_1.deployApi)(a, assemblyId, apiConfig, creds.solution));
|
|
47
47
|
await Promise.all(promises);
|
|
48
48
|
}
|
|
49
49
|
catch (error) {
|
|
50
50
|
logger_1.logger.error(error.message);
|
|
51
|
-
return;
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
}
|
package/lib/models/customApi.js
CHANGED
|
@@ -1,38 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.retrieveApi = exports.deployApi = void 0;
|
|
4
4
|
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
5
|
const pluginType_1 = require("./pluginType");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
|
-
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const apiId = await retrieveApi(config.name, apiConfig);
|
|
18
|
-
const pluginTypeId = await (0, pluginType_1.retrieveType)(config.pluginType ?? '', assemblyId, apiConfig);
|
|
19
|
-
if (pluginTypeId === '') {
|
|
20
|
-
logger_1.logger.error(`Unable to retrieve plugin type ${config.pluginType}`);
|
|
21
|
-
return;
|
|
7
|
+
async function deployApi(api, assemblyId, apiConfig, solution) {
|
|
8
|
+
let apiId = await retrieveApi(api.name, apiConfig);
|
|
9
|
+
if (api.plugintype) {
|
|
10
|
+
const pluginTypeId = await (0, pluginType_1.retrieveType)(api.plugintype ?? '', assemblyId, apiConfig);
|
|
11
|
+
if (pluginTypeId === '') {
|
|
12
|
+
logger_1.logger.error(`unable to find plugin type ${api.plugintype}`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
delete api.plugintype;
|
|
16
|
+
api['PluginTypeId@odata.bind'] = `plugintypes(${pluginTypeId})`;
|
|
22
17
|
}
|
|
23
|
-
delete config.pluginType;
|
|
24
|
-
config['PluginTypeId@odata.bind'] = `plugintypes(${pluginTypeId})`;
|
|
25
18
|
if (apiId != '') {
|
|
26
19
|
try {
|
|
27
|
-
await updateApi(apiId,
|
|
20
|
+
await updateApi(apiId, api, apiConfig);
|
|
28
21
|
}
|
|
29
22
|
catch (error) {
|
|
30
|
-
throw new Error(`failed to update
|
|
23
|
+
throw new Error(`failed to update custom api: ${error.message}`);
|
|
31
24
|
}
|
|
32
25
|
}
|
|
33
26
|
else {
|
|
34
27
|
try {
|
|
35
|
-
await createApi(
|
|
28
|
+
apiId = await createApi(api, apiConfig, solution);
|
|
36
29
|
}
|
|
37
30
|
catch (error) {
|
|
38
31
|
throw new Error(`failed to create custom api: ${error.message}`);
|
|
@@ -45,15 +38,32 @@ async function retrieveApi(name, apiConfig) {
|
|
|
45
38
|
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'customapis', options);
|
|
46
39
|
return result.value.length > 0 ? result.value[0].customapiid : '';
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
exports.retrieveApi = retrieveApi;
|
|
42
|
+
async function createApi(api, apiConfig, solution) {
|
|
43
|
+
logger_1.logger.info(`create custom api ${api.name}`);
|
|
44
|
+
const options = {};
|
|
45
|
+
if (solution) {
|
|
46
|
+
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
47
|
+
}
|
|
48
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', api, '$select=plugintypeid', options);
|
|
51
49
|
if (result.error) {
|
|
52
50
|
throw new Error(result.error.message);
|
|
53
51
|
}
|
|
54
52
|
return result.customapiid;
|
|
55
53
|
}
|
|
56
54
|
async function updateApi(id, api, apiConfig) {
|
|
57
|
-
logger_1.logger.info(`update custom api ${api.
|
|
55
|
+
logger_1.logger.info(`update custom api ${api.name}`);
|
|
56
|
+
const record = {
|
|
57
|
+
displayname: api.displayname,
|
|
58
|
+
description: api.description,
|
|
59
|
+
name: api.name,
|
|
60
|
+
executeprivilegename: api.executeprivilegename
|
|
61
|
+
};
|
|
62
|
+
if (api['PluginTypeId@odata.bind']) {
|
|
63
|
+
record['PluginTypeId@odata.bind'] = api['PluginTypeId@odata.bind'];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
record['PluginTypeId@odata.bind'] = null;
|
|
67
|
+
}
|
|
58
68
|
return (0, node_1.update)(apiConfig, 'customapis', id, api);
|
|
59
69
|
}
|
|
@@ -8,7 +8,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const glob_1 = __importDefault(require("glob"));
|
|
9
9
|
const node_1 = require("dataverse-webapi/lib/node");
|
|
10
10
|
const pluginType_1 = require("./pluginType");
|
|
11
|
-
const dataverse_service_1 = require("../dataverse.service");
|
|
12
11
|
const logger_1 = require("../logger");
|
|
13
12
|
async function deployAssembly(config, apiConfig, solution) {
|
|
14
13
|
const files = glob_1.default.sync(`**/${config.name}.dll`);
|
|
@@ -35,25 +34,17 @@ async function deployAssembly(config, apiConfig, solution) {
|
|
|
35
34
|
}
|
|
36
35
|
else {
|
|
37
36
|
try {
|
|
38
|
-
assemblyId = await createAssembly(config, content, apiConfig);
|
|
37
|
+
assemblyId = await createAssembly(config, content, apiConfig, solution);
|
|
39
38
|
}
|
|
40
39
|
catch (error) {
|
|
41
40
|
throw new Error(`failed to create assembly: ${error.message}`);
|
|
42
41
|
}
|
|
43
|
-
if (solution != undefined) {
|
|
44
|
-
try {
|
|
45
|
-
await (0, dataverse_service_1.addToSolution)(assemblyId, solution, dataverse_service_1.ComponentType.PluginAssembly, apiConfig);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
logger_1.logger.error(`failed to add to solution: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
42
|
}
|
|
52
43
|
if (config.types != null) {
|
|
53
44
|
try {
|
|
54
|
-
const promises = config.types.map(
|
|
45
|
+
const promises = config.types.map((type) => {
|
|
55
46
|
type['pluginassemblyid@odata.bind'] = `/pluginassemblies(${assemblyId})`;
|
|
56
|
-
|
|
47
|
+
return (0, pluginType_1.deployType)(type, assemblyId, apiConfig, solution);
|
|
57
48
|
});
|
|
58
49
|
await Promise.all(promises);
|
|
59
50
|
}
|
|
@@ -70,7 +61,7 @@ async function retrieveAssembly(name, apiConfig) {
|
|
|
70
61
|
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
|
|
71
62
|
return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
|
|
72
63
|
}
|
|
73
|
-
async function createAssembly(config, content, apiConfig) {
|
|
64
|
+
async function createAssembly(config, content, apiConfig, solution) {
|
|
74
65
|
logger_1.logger.info(`create assembly ${config.name}`);
|
|
75
66
|
const assembly = {
|
|
76
67
|
name: config.name,
|
|
@@ -81,10 +72,11 @@ async function createAssembly(config, content, apiConfig) {
|
|
|
81
72
|
sourcetype: 0,
|
|
82
73
|
culture: ''
|
|
83
74
|
};
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
const options = {};
|
|
76
|
+
if (solution) {
|
|
77
|
+
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
86
78
|
}
|
|
87
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid');
|
|
79
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid', options);
|
|
88
80
|
if (result.error) {
|
|
89
81
|
throw new Error(result.error.message);
|
|
90
82
|
}
|
|
@@ -8,7 +8,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const glob_1 = __importDefault(require("glob"));
|
|
9
9
|
const node_1 = require("dataverse-webapi/lib/node");
|
|
10
10
|
const pluginAssembly_1 = require("./pluginAssembly");
|
|
11
|
-
const dataverse_service_1 = require("../dataverse.service");
|
|
12
11
|
const logger_1 = require("../logger");
|
|
13
12
|
async function deployPluginPackage(config, apiConfig, solution) {
|
|
14
13
|
const files = glob_1.default.sync(`**/${config.name}.*.nupkg`);
|
|
@@ -18,7 +17,6 @@ async function deployPluginPackage(config, apiConfig, solution) {
|
|
|
18
17
|
}
|
|
19
18
|
const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
|
|
20
19
|
let packageId = '';
|
|
21
|
-
let assemblyId;
|
|
22
20
|
try {
|
|
23
21
|
packageId = await retrievePackage(config.prefix, config.name, apiConfig);
|
|
24
22
|
}
|
|
@@ -36,20 +34,13 @@ async function deployPluginPackage(config, apiConfig, solution) {
|
|
|
36
34
|
}
|
|
37
35
|
else {
|
|
38
36
|
try {
|
|
39
|
-
packageId = await createPackage(config, content, apiConfig);
|
|
37
|
+
packageId = await createPackage(config, content, apiConfig, solution);
|
|
40
38
|
}
|
|
41
39
|
catch (error) {
|
|
42
40
|
throw new Error(`failed to create package: ${error.message}`);
|
|
43
41
|
}
|
|
44
|
-
if (solution != undefined) {
|
|
45
|
-
try {
|
|
46
|
-
await (0, dataverse_service_1.addToSolution)(packageId, solution, dataverse_service_1.ComponentType.PluginPackage, apiConfig);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
logger_1.logger.error(`failed to add package to solution: ${error.message}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
42
|
}
|
|
43
|
+
let assemblyId;
|
|
53
44
|
if (config.assembly != null) {
|
|
54
45
|
try {
|
|
55
46
|
config.assembly['packageid@odata.bind'] = `/pluginpackages(${packageId})`;
|
|
@@ -68,14 +59,18 @@ async function retrievePackage(prefix, name, apiConfig) {
|
|
|
68
59
|
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginpackages', options);
|
|
69
60
|
return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
|
|
70
61
|
}
|
|
71
|
-
async function createPackage(config, content, apiConfig) {
|
|
62
|
+
async function createPackage(config, content, apiConfig, solution) {
|
|
72
63
|
logger_1.logger.info(`create package ${config.name}`);
|
|
73
64
|
const pluginPackage = {
|
|
74
65
|
name: `${config.prefix}_${config.name}`,
|
|
75
66
|
version: config.version,
|
|
76
67
|
content: content
|
|
77
68
|
};
|
|
78
|
-
const
|
|
69
|
+
const options = {};
|
|
70
|
+
if (solution) {
|
|
71
|
+
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
72
|
+
}
|
|
73
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginpackages', pluginPackage, '$select=pluginpackageid', options);
|
|
79
74
|
if (result.error) {
|
|
80
75
|
throw new Error(result.error.message);
|
|
81
76
|
}
|
package/lib/models/pluginStep.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deployStep = void 0;
|
|
4
4
|
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const dataverse_service_1 = require("../dataverse.service");
|
|
6
5
|
const logger_1 = require("../logger");
|
|
7
6
|
const pluginImage_1 = require("./pluginImage");
|
|
8
7
|
async function deployStep(step, typeId, apiConfig, solution) {
|
|
@@ -39,19 +38,11 @@ async function deployStep(step, typeId, apiConfig, solution) {
|
|
|
39
38
|
}
|
|
40
39
|
else {
|
|
41
40
|
try {
|
|
42
|
-
stepId = await createStep(step, apiConfig);
|
|
41
|
+
stepId = await createStep(step, apiConfig, solution);
|
|
43
42
|
}
|
|
44
43
|
catch (error) {
|
|
45
44
|
throw new Error(`failed to create plugin step: ${error.message}`);
|
|
46
45
|
}
|
|
47
|
-
if (solution != undefined) {
|
|
48
|
-
try {
|
|
49
|
-
await (0, dataverse_service_1.addToSolution)(stepId, solution, dataverse_service_1.ComponentType.SDKMessageProcessingStep, apiConfig);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
throw new Error(`failed to add to solution: ${error.message}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
46
|
}
|
|
56
47
|
if (images && images.length > 0) {
|
|
57
48
|
try {
|
|
@@ -83,9 +74,13 @@ async function getSdkMessageId(name, apiConfig) {
|
|
|
83
74
|
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
|
|
84
75
|
return message.value.length > 0 ? message.value[0].sdkmessageid : '';
|
|
85
76
|
}
|
|
86
|
-
async function createStep(step, apiConfig) {
|
|
77
|
+
async function createStep(step, apiConfig, solution) {
|
|
87
78
|
logger_1.logger.info(`create plugin step ${step.name}`);
|
|
88
|
-
const
|
|
79
|
+
const options = {};
|
|
80
|
+
if (solution) {
|
|
81
|
+
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
82
|
+
}
|
|
83
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid', options);
|
|
89
84
|
if (result.error) {
|
|
90
85
|
throw new Error(result.error.message);
|
|
91
86
|
}
|
package/lib/models/pluginType.js
CHANGED
|
@@ -31,9 +31,9 @@ async function deployType(config, assemblyId, apiConfig, solution) {
|
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
33
|
if (config.steps) {
|
|
34
|
-
const promises = config.steps.map(
|
|
34
|
+
const promises = config.steps.map((step) => {
|
|
35
35
|
step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
|
|
36
|
-
|
|
36
|
+
return (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
|
|
37
37
|
});
|
|
38
38
|
await Promise.all(promises);
|
|
39
39
|
}
|
|
@@ -75,19 +75,11 @@ async function deploy(webResources, apiConfig, solution, files) {
|
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
try {
|
|
78
|
-
resourceId = await createResource(resource, content, apiConfig);
|
|
78
|
+
resourceId = await createResource(resource, content, apiConfig, solution);
|
|
79
79
|
}
|
|
80
80
|
catch (error) {
|
|
81
81
|
logger_1.logger.error(`failed to create resource: ${error.message}`);
|
|
82
82
|
}
|
|
83
|
-
if (solution != undefined) {
|
|
84
|
-
try {
|
|
85
|
-
await (0, dataverse_service_1.addToSolution)(resourceId, solution, dataverse_service_1.ComponentType.WebResource, apiConfig);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
logger_1.logger.error(`failed to add to solution: ${error.message}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
83
|
}
|
|
92
84
|
});
|
|
93
85
|
await Promise.all(promises);
|
|
@@ -107,7 +99,7 @@ async function retrieveResource(name, apiConfig) {
|
|
|
107
99
|
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'webresourceset', options);
|
|
108
100
|
return result.value.length > 0 ? result.value[0].webresourceid : '';
|
|
109
101
|
}
|
|
110
|
-
async function createResource(resource, content, apiConfig) {
|
|
102
|
+
async function createResource(resource, content, apiConfig, solution) {
|
|
111
103
|
logger_1.logger.info(`create web resource ${resource.name}`);
|
|
112
104
|
const webResource = {
|
|
113
105
|
webresourcetype: getWebResourceType(resource.type),
|
|
@@ -115,7 +107,11 @@ async function createResource(resource, content, apiConfig) {
|
|
|
115
107
|
displayname: resource.displayname || resource.name,
|
|
116
108
|
content: content
|
|
117
109
|
};
|
|
118
|
-
const
|
|
110
|
+
const options = {};
|
|
111
|
+
if (solution) {
|
|
112
|
+
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
113
|
+
}
|
|
114
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'webresourceset', webResource, '$select=webresourceid', options);
|
|
119
115
|
if (result.error) {
|
|
120
116
|
throw new Error(result.error.message);
|
|
121
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataverse-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Utilities for interacting with Dataverse environments",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"clean": "rimraf lib"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@azure/msal-node": "^1.
|
|
23
|
+
"@azure/msal-node": "^1.14.5",
|
|
24
24
|
"commander": "^8.3.0",
|
|
25
25
|
"cryptr": "^6.0.3",
|
|
26
|
-
"dataverse-webapi": "^2.
|
|
26
|
+
"dataverse-webapi": "^2.3.0",
|
|
27
27
|
"envinfo": "^7.8.1",
|
|
28
28
|
"figures": "^3.2.0",
|
|
29
29
|
"glob": "^7.2.0",
|