dataverse-utils 2.7.4 → 2.7.6
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 +57 -56
- package/lib/auth.js +75 -75
- package/lib/cachePlugin.js +97 -97
- package/lib/dataverse.service.js +71 -71
- package/lib/deploy.js +64 -64
- package/lib/generate.js +99 -99
- package/lib/index.js +44 -44
- package/lib/logger.js +37 -37
- package/lib/models/customApi.js +77 -77
- package/lib/models/pluginAssembly.js +88 -87
- package/lib/models/pluginImage.js +66 -66
- package/lib/models/pluginPackage.js +93 -93
- package/lib/models/pluginStep.js +97 -97
- package/lib/models/pluginType.js +65 -65
- package/lib/models/webResource.js +130 -130
- package/lib/webResourceDeploy.js +29 -29
- package/package.json +1 -1
package/lib/models/pluginStep.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deployStep = void 0;
|
|
4
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const logger_1 = require("../logger");
|
|
6
|
-
const pluginImage_1 = require("./pluginImage");
|
|
7
|
-
async function deployStep(config, pluginTypeId, apiConfig, solution) {
|
|
8
|
-
const step = structuredClone(config);
|
|
9
|
-
step['plugintypeid@odata.bind'] = `/plugintypes(${pluginTypeId})`;
|
|
10
|
-
const messageId = await getSdkMessageId(step.message ?? '', apiConfig);
|
|
11
|
-
if (messageId == '') {
|
|
12
|
-
logger_1.logger.warn(`sdk message ${step.message} not found`);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (step.entity !== '' && step.entity !== 'none') {
|
|
16
|
-
const filterId = await getSdkMessageFilterId(messageId, step.entity ?? '', apiConfig);
|
|
17
|
-
if (filterId == '') {
|
|
18
|
-
logger_1.logger.warn(`sdk message ${step.message} for entity ${step.entity} not found`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
step['sdkmessagefilterid@odata.bind'] = `/sdkmessagefilters(${filterId})`;
|
|
22
|
-
}
|
|
23
|
-
step['sdkmessageid@odata.bind'] = `/sdkmessages(${messageId})`;
|
|
24
|
-
if (step.mode === 1) {
|
|
25
|
-
step.asyncautodelete = true;
|
|
26
|
-
}
|
|
27
|
-
delete step.images;
|
|
28
|
-
delete step.message;
|
|
29
|
-
delete step.entity;
|
|
30
|
-
delete step.sdkmessageprocessingstepid;
|
|
31
|
-
if (!config.sdkmessageprocessingstepid) {
|
|
32
|
-
config.sdkmessageprocessingstepid = await retrieveStep(step.name, pluginTypeId, apiConfig);
|
|
33
|
-
}
|
|
34
|
-
if (config.sdkmessageprocessingstepid) {
|
|
35
|
-
try {
|
|
36
|
-
await updateStep(config.sdkmessageprocessingstepid, step, apiConfig);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
throw new Error(`failed to update plugin step: ${error.message}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
try {
|
|
44
|
-
config.sdkmessageprocessingstepid = await createStep(step, apiConfig, solution);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw new Error(`failed to create plugin step: ${error.message}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (config.images && config.images.length > 0) {
|
|
51
|
-
try {
|
|
52
|
-
const promises = config.images.map((image) => (0, pluginImage_1.deployImage)(config.sdkmessageprocessingstepid, step.name, image, config.message, apiConfig));
|
|
53
|
-
await Promise.all(promises);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
throw new Error(error.message);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.deployStep = deployStep;
|
|
61
|
-
async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
|
|
62
|
-
const options = [
|
|
63
|
-
`?$filter=primaryobjecttypecode eq '${entityName}' and _sdkmessageid_value eq ${messageId}`,
|
|
64
|
-
'&$select=sdkmessagefilterid'
|
|
65
|
-
].join('');
|
|
66
|
-
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessagefilters', options);
|
|
67
|
-
return message.value.length > 0 ? message.value[0].sdkmessagefilterid : '';
|
|
68
|
-
}
|
|
69
|
-
async function getSdkMessageId(name, apiConfig) {
|
|
70
|
-
const options = [`?$filter=name eq '${name}'`, '&$select=sdkmessageid'].join('');
|
|
71
|
-
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
|
|
72
|
-
return message.value.length > 0 ? message.value[0].sdkmessageid : '';
|
|
73
|
-
}
|
|
74
|
-
async function retrieveStep(name, typeId, apiConfig) {
|
|
75
|
-
const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}' and _plugintypeid_value eq ${typeId}`;
|
|
76
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
|
|
77
|
-
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
|
|
78
|
-
}
|
|
79
|
-
async function createStep(step, apiConfig, solution) {
|
|
80
|
-
logger_1.logger.info(`create plugin step ${step.name}`);
|
|
81
|
-
const options = {};
|
|
82
|
-
if (solution) {
|
|
83
|
-
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
84
|
-
}
|
|
85
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid', options);
|
|
86
|
-
if (result?.error) {
|
|
87
|
-
throw new Error(result.error.message);
|
|
88
|
-
}
|
|
89
|
-
return result.sdkmessageprocessingstepid;
|
|
90
|
-
}
|
|
91
|
-
async function updateStep(id, step, apiConfig) {
|
|
92
|
-
logger_1.logger.info(`update plugin step ${step.name}`);
|
|
93
|
-
const result = await (0, node_1.update)(apiConfig, 'sdkmessageprocessingsteps', id, step);
|
|
94
|
-
if (result?.error) {
|
|
95
|
-
throw new Error(result.error.message);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deployStep = void 0;
|
|
4
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
const pluginImage_1 = require("./pluginImage");
|
|
7
|
+
async function deployStep(config, pluginTypeId, apiConfig, solution) {
|
|
8
|
+
const step = structuredClone(config);
|
|
9
|
+
step['plugintypeid@odata.bind'] = `/plugintypes(${pluginTypeId})`;
|
|
10
|
+
const messageId = await getSdkMessageId(step.message ?? '', apiConfig);
|
|
11
|
+
if (messageId == '') {
|
|
12
|
+
logger_1.logger.warn(`sdk message ${step.message} not found`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (step.entity !== '' && step.entity !== 'none') {
|
|
16
|
+
const filterId = await getSdkMessageFilterId(messageId, step.entity ?? '', apiConfig);
|
|
17
|
+
if (filterId == '') {
|
|
18
|
+
logger_1.logger.warn(`sdk message ${step.message} for entity ${step.entity} not found`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
step['sdkmessagefilterid@odata.bind'] = `/sdkmessagefilters(${filterId})`;
|
|
22
|
+
}
|
|
23
|
+
step['sdkmessageid@odata.bind'] = `/sdkmessages(${messageId})`;
|
|
24
|
+
if (step.mode === 1) {
|
|
25
|
+
step.asyncautodelete = true;
|
|
26
|
+
}
|
|
27
|
+
delete step.images;
|
|
28
|
+
delete step.message;
|
|
29
|
+
delete step.entity;
|
|
30
|
+
delete step.sdkmessageprocessingstepid;
|
|
31
|
+
if (!config.sdkmessageprocessingstepid) {
|
|
32
|
+
config.sdkmessageprocessingstepid = await retrieveStep(step.name, pluginTypeId, apiConfig);
|
|
33
|
+
}
|
|
34
|
+
if (config.sdkmessageprocessingstepid) {
|
|
35
|
+
try {
|
|
36
|
+
await updateStep(config.sdkmessageprocessingstepid, step, apiConfig);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new Error(`failed to update plugin step: ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
try {
|
|
44
|
+
config.sdkmessageprocessingstepid = await createStep(step, apiConfig, solution);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error(`failed to create plugin step: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (config.images && config.images.length > 0) {
|
|
51
|
+
try {
|
|
52
|
+
const promises = config.images.map((image) => (0, pluginImage_1.deployImage)(config.sdkmessageprocessingstepid, step.name, image, config.message, apiConfig));
|
|
53
|
+
await Promise.all(promises);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(error.message);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.deployStep = deployStep;
|
|
61
|
+
async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
|
|
62
|
+
const options = [
|
|
63
|
+
`?$filter=primaryobjecttypecode eq '${entityName}' and _sdkmessageid_value eq ${messageId}`,
|
|
64
|
+
'&$select=sdkmessagefilterid'
|
|
65
|
+
].join('');
|
|
66
|
+
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessagefilters', options);
|
|
67
|
+
return message.value.length > 0 ? message.value[0].sdkmessagefilterid : '';
|
|
68
|
+
}
|
|
69
|
+
async function getSdkMessageId(name, apiConfig) {
|
|
70
|
+
const options = [`?$filter=name eq '${name}'`, '&$select=sdkmessageid'].join('');
|
|
71
|
+
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
|
|
72
|
+
return message.value.length > 0 ? message.value[0].sdkmessageid : '';
|
|
73
|
+
}
|
|
74
|
+
async function retrieveStep(name, typeId, apiConfig) {
|
|
75
|
+
const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}' and _plugintypeid_value eq ${typeId}`;
|
|
76
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
|
|
77
|
+
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
|
|
78
|
+
}
|
|
79
|
+
async function createStep(step, apiConfig, solution) {
|
|
80
|
+
logger_1.logger.info(`create plugin step ${step.name}`);
|
|
81
|
+
const options = {};
|
|
82
|
+
if (solution) {
|
|
83
|
+
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
84
|
+
}
|
|
85
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid', options);
|
|
86
|
+
if (result?.error) {
|
|
87
|
+
throw new Error(result.error.message);
|
|
88
|
+
}
|
|
89
|
+
return result.sdkmessageprocessingstepid;
|
|
90
|
+
}
|
|
91
|
+
async function updateStep(id, step, apiConfig) {
|
|
92
|
+
logger_1.logger.info(`update plugin step ${step.name}`);
|
|
93
|
+
const result = await (0, node_1.update)(apiConfig, 'sdkmessageprocessingsteps', id, step);
|
|
94
|
+
if (result?.error) {
|
|
95
|
+
throw new Error(result.error.message);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/lib/models/pluginType.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retrieveType = exports.deployType = void 0;
|
|
4
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const pluginStep_1 = require("./pluginStep");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
async function deployType(config, assemblyId, apiConfig, solution) {
|
|
8
|
-
const type = {
|
|
9
|
-
name: config.name,
|
|
10
|
-
friendlyname: config.friendlyname,
|
|
11
|
-
typename: config.typename,
|
|
12
|
-
'pluginassemblyid@odata.bind':
|
|
13
|
-
workflowactivitygroupname: config.workflowactivitygroupname
|
|
14
|
-
};
|
|
15
|
-
if (!config.plugintypeid) {
|
|
16
|
-
config.plugintypeid = await retrieveType(config.name, assemblyId, apiConfig);
|
|
17
|
-
}
|
|
18
|
-
if (config.plugintypeid) {
|
|
19
|
-
try {
|
|
20
|
-
await updateType(config.plugintypeid, type, apiConfig);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
throw new Error(`failed to update plugin type: ${error.message}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
try {
|
|
28
|
-
config.plugintypeid = await createType(type, apiConfig);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
throw new Error(`failed to create plugin type: ${error.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
if (config.steps) {
|
|
36
|
-
const promises = config.steps.map((step) => (0, pluginStep_1.deployStep)(step, config.plugintypeid, apiConfig, solution));
|
|
37
|
-
await Promise.all(promises);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
throw new Error(error.message);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.deployType = deployType;
|
|
45
|
-
async function retrieveType(name, assemblyId, apiConfig) {
|
|
46
|
-
const options = `$select=plugintypeid&$filter=typename eq '${name}' and _pluginassemblyid_value eq ${assemblyId}`;
|
|
47
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'plugintypes', options);
|
|
48
|
-
return result.value.length > 0 ? result.value[0].plugintypeid : '';
|
|
49
|
-
}
|
|
50
|
-
exports.retrieveType = retrieveType;
|
|
51
|
-
async function createType(type, apiConfig) {
|
|
52
|
-
logger_1.logger.info(`create assembly type ${type.name}`);
|
|
53
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', type, '$select=plugintypeid');
|
|
54
|
-
if (result?.error) {
|
|
55
|
-
throw new Error(result.error.message);
|
|
56
|
-
}
|
|
57
|
-
return result.plugintypeid;
|
|
58
|
-
}
|
|
59
|
-
async function updateType(id, type, apiConfig) {
|
|
60
|
-
logger_1.logger.info(`update assembly type ${type.name}`);
|
|
61
|
-
const result = await (0, node_1.update)(apiConfig, 'plugintypes', id, type);
|
|
62
|
-
if (result?.error) {
|
|
63
|
-
throw new Error(result.error.message);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retrieveType = exports.deployType = void 0;
|
|
4
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
+
const pluginStep_1 = require("./pluginStep");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
async function deployType(config, assemblyId, apiConfig, solution) {
|
|
8
|
+
const type = {
|
|
9
|
+
name: config.name,
|
|
10
|
+
friendlyname: config.friendlyname,
|
|
11
|
+
typename: config.typename,
|
|
12
|
+
'pluginassemblyid@odata.bind': `pluginassemblies(${assemblyId})`,
|
|
13
|
+
workflowactivitygroupname: config.workflowactivitygroupname
|
|
14
|
+
};
|
|
15
|
+
if (!config.plugintypeid) {
|
|
16
|
+
config.plugintypeid = await retrieveType(config.name, assemblyId, apiConfig);
|
|
17
|
+
}
|
|
18
|
+
if (config.plugintypeid) {
|
|
19
|
+
try {
|
|
20
|
+
await updateType(config.plugintypeid, type, apiConfig);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new Error(`failed to update plugin type: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
try {
|
|
28
|
+
config.plugintypeid = await createType(type, apiConfig);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(`failed to create plugin type: ${error.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
if (config.steps) {
|
|
36
|
+
const promises = config.steps.map((step) => (0, pluginStep_1.deployStep)(step, config.plugintypeid, apiConfig, solution));
|
|
37
|
+
await Promise.all(promises);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new Error(error.message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.deployType = deployType;
|
|
45
|
+
async function retrieveType(name, assemblyId, apiConfig) {
|
|
46
|
+
const options = `$select=plugintypeid&$filter=typename eq '${name}' and _pluginassemblyid_value eq ${assemblyId}`;
|
|
47
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'plugintypes', options);
|
|
48
|
+
return result.value.length > 0 ? result.value[0].plugintypeid : '';
|
|
49
|
+
}
|
|
50
|
+
exports.retrieveType = retrieveType;
|
|
51
|
+
async function createType(type, apiConfig) {
|
|
52
|
+
logger_1.logger.info(`create assembly type ${type.name}`);
|
|
53
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', type, '$select=plugintypeid');
|
|
54
|
+
if (result?.error) {
|
|
55
|
+
throw new Error(result.error.message);
|
|
56
|
+
}
|
|
57
|
+
return result.plugintypeid;
|
|
58
|
+
}
|
|
59
|
+
async function updateType(id, type, apiConfig) {
|
|
60
|
+
logger_1.logger.info(`update assembly type ${type.name}`);
|
|
61
|
+
const result = await (0, node_1.update)(apiConfig, 'plugintypes', id, type);
|
|
62
|
+
if (result?.error) {
|
|
63
|
+
throw new Error(result.error.message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deploy = void 0;
|
|
7
|
-
const dataverse_service_1 = require("../dataverse.service");
|
|
8
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
9
|
-
const logger_1 = require("../logger");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
function getWebResourceType(type) {
|
|
12
|
-
switch (type) {
|
|
13
|
-
case 'HTML':
|
|
14
|
-
return 1;
|
|
15
|
-
case 'CSS':
|
|
16
|
-
return 2;
|
|
17
|
-
case 'JavaScript':
|
|
18
|
-
return 3;
|
|
19
|
-
case 'XML':
|
|
20
|
-
return 4;
|
|
21
|
-
case 'PNG':
|
|
22
|
-
return 5;
|
|
23
|
-
case 'JPG':
|
|
24
|
-
return 6;
|
|
25
|
-
case 'GIF':
|
|
26
|
-
return 7;
|
|
27
|
-
case 'XAP':
|
|
28
|
-
return 8;
|
|
29
|
-
case 'XSL':
|
|
30
|
-
return 9;
|
|
31
|
-
case 'ICO':
|
|
32
|
-
return 10;
|
|
33
|
-
case 'SVG':
|
|
34
|
-
return 11;
|
|
35
|
-
case 'RESX':
|
|
36
|
-
return 12;
|
|
37
|
-
default:
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async function deploy(webResources, apiConfig, solution, files) {
|
|
42
|
-
const publishXml = [];
|
|
43
|
-
let resources = webResources;
|
|
44
|
-
// Use list of files if provided
|
|
45
|
-
if (files) {
|
|
46
|
-
resources = [];
|
|
47
|
-
for (const file of files.split(',')) {
|
|
48
|
-
const resource = webResources.filter((r) => r.path?.endsWith(file));
|
|
49
|
-
if (resource.length === 0) {
|
|
50
|
-
logger_1.logger.warn(`web resource ${file} not found in dataverse.config.json`);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
resources.push(resource[0]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const promises = resources.map(async (resource) => {
|
|
57
|
-
let resourceId = '';
|
|
58
|
-
try {
|
|
59
|
-
resourceId = await retrieveResource(resource.name, apiConfig);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
logger_1.logger.error(`failed to retrieve resource ${resource.name}: ${error.message}`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const fileContent = await fs_1.default.promises.readFile(resource.path, 'utf8');
|
|
66
|
-
const content = Buffer.from(fileContent).toString('base64');
|
|
67
|
-
if (resourceId != '') {
|
|
68
|
-
try {
|
|
69
|
-
const updated = await updateResource(resourceId, resource, content, apiConfig);
|
|
70
|
-
publishXml.push(updated);
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
logger_1.logger.error(`failed to update resource: ${error.message}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
try {
|
|
78
|
-
resourceId = await createResource(resource, content, apiConfig, solution);
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
logger_1.logger.error(`failed to create resource: ${error.message}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
await Promise.all(promises);
|
|
86
|
-
// publish resources
|
|
87
|
-
if (publishXml.length > 0) {
|
|
88
|
-
try {
|
|
89
|
-
await (0, dataverse_service_1.publish)(publishXml.join(''), apiConfig);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
logger_1.logger.error(error.message);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.deploy = deploy;
|
|
97
|
-
async function retrieveResource(name, apiConfig) {
|
|
98
|
-
const options = `$select=webresourceid&$filter=name eq '${name}'`;
|
|
99
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'webresourceset', options);
|
|
100
|
-
return result.value.length > 0 ? result.value[0].webresourceid : '';
|
|
101
|
-
}
|
|
102
|
-
async function createResource(resource, content, apiConfig, solution) {
|
|
103
|
-
logger_1.logger.info(`create web resource ${resource.name}`);
|
|
104
|
-
const webResource = {
|
|
105
|
-
webresourcetype: getWebResourceType(resource.type),
|
|
106
|
-
name: resource.name,
|
|
107
|
-
displayname: resource.displayname || resource.name,
|
|
108
|
-
content: content
|
|
109
|
-
};
|
|
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);
|
|
115
|
-
if (result?.error) {
|
|
116
|
-
throw new Error(result.error.message);
|
|
117
|
-
}
|
|
118
|
-
return result.webresourceid;
|
|
119
|
-
}
|
|
120
|
-
async function updateResource(id, resource, content, apiConfig) {
|
|
121
|
-
logger_1.logger.info(`update web resource ${resource.name}`);
|
|
122
|
-
const webResource = {
|
|
123
|
-
content: content
|
|
124
|
-
};
|
|
125
|
-
const result = await (0, node_1.update)(apiConfig, 'webresourceset', id, webResource);
|
|
126
|
-
if (result?.error) {
|
|
127
|
-
throw new Error(result.error.message);
|
|
128
|
-
}
|
|
129
|
-
return `<webresource>{${id}}</webresource>`;
|
|
130
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deploy = void 0;
|
|
7
|
+
const dataverse_service_1 = require("../dataverse.service");
|
|
8
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
9
|
+
const logger_1 = require("../logger");
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
function getWebResourceType(type) {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'HTML':
|
|
14
|
+
return 1;
|
|
15
|
+
case 'CSS':
|
|
16
|
+
return 2;
|
|
17
|
+
case 'JavaScript':
|
|
18
|
+
return 3;
|
|
19
|
+
case 'XML':
|
|
20
|
+
return 4;
|
|
21
|
+
case 'PNG':
|
|
22
|
+
return 5;
|
|
23
|
+
case 'JPG':
|
|
24
|
+
return 6;
|
|
25
|
+
case 'GIF':
|
|
26
|
+
return 7;
|
|
27
|
+
case 'XAP':
|
|
28
|
+
return 8;
|
|
29
|
+
case 'XSL':
|
|
30
|
+
return 9;
|
|
31
|
+
case 'ICO':
|
|
32
|
+
return 10;
|
|
33
|
+
case 'SVG':
|
|
34
|
+
return 11;
|
|
35
|
+
case 'RESX':
|
|
36
|
+
return 12;
|
|
37
|
+
default:
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function deploy(webResources, apiConfig, solution, files) {
|
|
42
|
+
const publishXml = [];
|
|
43
|
+
let resources = webResources;
|
|
44
|
+
// Use list of files if provided
|
|
45
|
+
if (files) {
|
|
46
|
+
resources = [];
|
|
47
|
+
for (const file of files.split(',')) {
|
|
48
|
+
const resource = webResources.filter((r) => r.path?.endsWith(file));
|
|
49
|
+
if (resource.length === 0) {
|
|
50
|
+
logger_1.logger.warn(`web resource ${file} not found in dataverse.config.json`);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
resources.push(resource[0]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const promises = resources.map(async (resource) => {
|
|
57
|
+
let resourceId = '';
|
|
58
|
+
try {
|
|
59
|
+
resourceId = await retrieveResource(resource.name, apiConfig);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
logger_1.logger.error(`failed to retrieve resource ${resource.name}: ${error.message}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const fileContent = await fs_1.default.promises.readFile(resource.path, 'utf8');
|
|
66
|
+
const content = Buffer.from(fileContent).toString('base64');
|
|
67
|
+
if (resourceId != '') {
|
|
68
|
+
try {
|
|
69
|
+
const updated = await updateResource(resourceId, resource, content, apiConfig);
|
|
70
|
+
publishXml.push(updated);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger_1.logger.error(`failed to update resource: ${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
try {
|
|
78
|
+
resourceId = await createResource(resource, content, apiConfig, solution);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
logger_1.logger.error(`failed to create resource: ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
await Promise.all(promises);
|
|
86
|
+
// publish resources
|
|
87
|
+
if (publishXml.length > 0) {
|
|
88
|
+
try {
|
|
89
|
+
await (0, dataverse_service_1.publish)(publishXml.join(''), apiConfig);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
logger_1.logger.error(error.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.deploy = deploy;
|
|
97
|
+
async function retrieveResource(name, apiConfig) {
|
|
98
|
+
const options = `$select=webresourceid&$filter=name eq '${name}'`;
|
|
99
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'webresourceset', options);
|
|
100
|
+
return result.value.length > 0 ? result.value[0].webresourceid : '';
|
|
101
|
+
}
|
|
102
|
+
async function createResource(resource, content, apiConfig, solution) {
|
|
103
|
+
logger_1.logger.info(`create web resource ${resource.name}`);
|
|
104
|
+
const webResource = {
|
|
105
|
+
webresourcetype: getWebResourceType(resource.type),
|
|
106
|
+
name: resource.name,
|
|
107
|
+
displayname: resource.displayname || resource.name,
|
|
108
|
+
content: content
|
|
109
|
+
};
|
|
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);
|
|
115
|
+
if (result?.error) {
|
|
116
|
+
throw new Error(result.error.message);
|
|
117
|
+
}
|
|
118
|
+
return result.webresourceid;
|
|
119
|
+
}
|
|
120
|
+
async function updateResource(id, resource, content, apiConfig) {
|
|
121
|
+
logger_1.logger.info(`update web resource ${resource.name}`);
|
|
122
|
+
const webResource = {
|
|
123
|
+
content: content
|
|
124
|
+
};
|
|
125
|
+
const result = await (0, node_1.update)(apiConfig, 'webresourceset', id, webResource);
|
|
126
|
+
if (result?.error) {
|
|
127
|
+
throw new Error(result.error.message);
|
|
128
|
+
}
|
|
129
|
+
return `<webresource>{${id}}</webresource>`;
|
|
130
|
+
}
|
package/lib/webResourceDeploy.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.webResourceDeploy = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const logger_1 = require("./logger");
|
|
10
|
-
const webResource_1 = require("./models/webResource");
|
|
11
|
-
async function webResourceDeploy(creds, apiConfig, files) {
|
|
12
|
-
const currentPath = '.';
|
|
13
|
-
const configFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
14
|
-
if (configFile == null) {
|
|
15
|
-
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const config = JSON.parse(configFile).webResources;
|
|
19
|
-
logger_1.logger.info('deploy web resources');
|
|
20
|
-
try {
|
|
21
|
-
await (0, webResource_1.deploy)(config, apiConfig, creds.solution, files);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
logger_1.logger.error(error.message);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
logger_1.logger.done('deployed web resources');
|
|
28
|
-
}
|
|
29
|
-
exports.webResourceDeploy = webResourceDeploy;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.webResourceDeploy = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
const webResource_1 = require("./models/webResource");
|
|
11
|
+
async function webResourceDeploy(creds, apiConfig, files) {
|
|
12
|
+
const currentPath = '.';
|
|
13
|
+
const configFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
14
|
+
if (configFile == null) {
|
|
15
|
+
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const config = JSON.parse(configFile).webResources;
|
|
19
|
+
logger_1.logger.info('deploy web resources');
|
|
20
|
+
try {
|
|
21
|
+
await (0, webResource_1.deploy)(config, apiConfig, creds.solution, files);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
logger_1.logger.error(error.message);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
logger_1.logger.done('deployed web resources');
|
|
28
|
+
}
|
|
29
|
+
exports.webResourceDeploy = webResourceDeploy;
|