dataverse-utils 2.7.4 → 2.7.5

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.
@@ -1,87 +1,88 @@
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.retrieveAssembly = exports.deployAssembly = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const glob_1 = __importDefault(require("glob"));
9
- const node_1 = require("dataverse-webapi/lib/node");
10
- const pluginType_1 = require("./pluginType");
11
- const logger_1 = require("../logger");
12
- async function deployAssembly(config, apiConfig, solution) {
13
- const files = glob_1.default.sync(`**/${config.name}.dll`);
14
- if (files.length === 0) {
15
- logger_1.logger.warn(`assembly ${config.name}.dll not found`);
16
- return;
17
- }
18
- const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
19
- if (!config.pluginassemblyid) {
20
- config.pluginassemblyid = await retrieveAssembly(config.name, apiConfig);
21
- }
22
- if (config.pluginassemblyid) {
23
- try {
24
- await updateAssembly(config, content, apiConfig);
25
- }
26
- catch (error) {
27
- throw new Error(`failed to update assembly: ${error.message}`);
28
- }
29
- }
30
- else {
31
- try {
32
- config.pluginassemblyid = await createAssembly(config, content, apiConfig, solution);
33
- }
34
- catch (error) {
35
- throw new Error(`failed to create assembly: ${error.message}`);
36
- }
37
- }
38
- if (config.types != null) {
39
- try {
40
- const promises = config.types.map((type) => (0, pluginType_1.deployType)(type, config.pluginassemblyid, apiConfig, solution));
41
- await Promise.all(promises);
42
- }
43
- catch (error) {
44
- logger_1.logger.error(error.message);
45
- return;
46
- }
47
- }
48
- }
49
- exports.deployAssembly = deployAssembly;
50
- async function retrieveAssembly(name, apiConfig) {
51
- const options = `$select=pluginassemblyid&$filter=name eq '${name}'`;
52
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
53
- return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
54
- }
55
- exports.retrieveAssembly = retrieveAssembly;
56
- async function createAssembly(config, content, apiConfig, solution) {
57
- logger_1.logger.info(`create assembly ${config.name}`);
58
- const assembly = {
59
- name: config.name,
60
- content: content,
61
- isolationmode: config.isolationmode,
62
- version: config.version,
63
- publickeytoken: config.name,
64
- sourcetype: 0,
65
- culture: ''
66
- };
67
- const options = {};
68
- if (solution) {
69
- options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
70
- }
71
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid', options);
72
- if (result?.error) {
73
- throw new Error(result.error.message);
74
- }
75
- return result.pluginassemblyid;
76
- }
77
- async function updateAssembly(config, content, apiConfig) {
78
- logger_1.logger.info(`update assembly ${config.name}`);
79
- const assembly = {
80
- content: content,
81
- version: config.version
82
- };
83
- const result = await (0, node_1.update)(apiConfig, 'pluginassemblies', config.pluginassemblyid, assembly);
84
- if (result?.error) {
85
- throw new Error(result.error.message);
86
- }
87
- }
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.retrieveAssembly = exports.deployAssembly = void 0;
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const glob_1 = __importDefault(require("glob"));
10
+ const node_1 = require("dataverse-webapi/lib/node");
11
+ const pluginType_1 = require("./pluginType");
12
+ const logger_1 = require("../logger");
13
+ async function deployAssembly(config, apiConfig, solution) {
14
+ const files = glob_1.default.sync(`**/${config.name}.dll`);
15
+ if (files.length === 0) {
16
+ logger_1.logger.warn(`assembly ${config.name}.dll not found`);
17
+ return;
18
+ }
19
+ const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
20
+ if (!config.pluginassemblyid) {
21
+ config.pluginassemblyid = await retrieveAssembly(config.name, apiConfig);
22
+ }
23
+ if (config.pluginassemblyid) {
24
+ try {
25
+ await updateAssembly(config, content, apiConfig);
26
+ }
27
+ catch (error) {
28
+ throw new Error(`failed to update assembly: ${error.message}`);
29
+ }
30
+ }
31
+ else {
32
+ try {
33
+ config.pluginassemblyid = await createAssembly(config, content, apiConfig, solution);
34
+ }
35
+ catch (error) {
36
+ throw new Error(`failed to create assembly: ${error.message}`);
37
+ }
38
+ }
39
+ if (config.types != null) {
40
+ try {
41
+ const promises = config.types.map((type) => (0, pluginType_1.deployType)(type, config.pluginassemblyid, apiConfig, solution));
42
+ await Promise.all(promises);
43
+ }
44
+ catch (error) {
45
+ logger_1.logger.error(error.message);
46
+ return;
47
+ }
48
+ }
49
+ }
50
+ exports.deployAssembly = deployAssembly;
51
+ async function retrieveAssembly(name, apiConfig) {
52
+ const options = `$select=pluginassemblyid&$filter=name eq '${name}'`;
53
+ const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
54
+ return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
55
+ }
56
+ exports.retrieveAssembly = retrieveAssembly;
57
+ async function createAssembly(config, content, apiConfig, solution) {
58
+ logger_1.logger.info(`create assembly ${config.name}`);
59
+ const assembly = {
60
+ name: config.name,
61
+ content: content,
62
+ isolationmode: config.isolationmode,
63
+ version: config.version,
64
+ publickeytoken: config.name,
65
+ sourcetype: 0,
66
+ culture: ''
67
+ };
68
+ const options = {};
69
+ if (solution) {
70
+ options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
71
+ }
72
+ const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid', options);
73
+ if (result?.error) {
74
+ throw new Error(result.error.message);
75
+ }
76
+ return result.pluginassemblyid;
77
+ }
78
+ async function updateAssembly(config, content, apiConfig) {
79
+ logger_1.logger.info(`update assembly ${config.name}`);
80
+ const assembly = {
81
+ content: content,
82
+ version: config.version
83
+ };
84
+ const result = await (0, node_1.update)(apiConfig, 'pluginassemblies', config.pluginassemblyid, assembly);
85
+ if (result?.error) {
86
+ throw new Error(result.error.message);
87
+ }
88
+ }
@@ -1,66 +1,66 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deployImage = void 0;
4
- const logger_1 = require("../logger");
5
- const node_1 = require("dataverse-webapi/lib/node");
6
- async function deployImage(stepId, stepName, config, message, apiConfig) {
7
- const image = structuredClone(config);
8
- image['sdkmessageprocessingstepid@odata.bind'] = `/sdkmessageprocessingsteps(${stepId})`;
9
- switch (message) {
10
- case 'Create':
11
- image.messagepropertyname = 'Id';
12
- break;
13
- case 'SetState':
14
- case 'SetStateDynamicEntity':
15
- image.messagepropertyname = 'EntityMoniker';
16
- break;
17
- case 'Send':
18
- case 'DeliverIncoming':
19
- case 'DeliverPromote':
20
- image.messagepropertyname = 'EmailId';
21
- break;
22
- default:
23
- image.messagepropertyname = 'Target';
24
- break;
25
- }
26
- if (!config.sdkmessageprocessingstepimageid) {
27
- config.sdkmessageprocessingstepimageid = await retrieveImage(stepId, image, apiConfig);
28
- }
29
- if (config.sdkmessageprocessingstepimageid) {
30
- try {
31
- await updateImage(config.sdkmessageprocessingstepimageid, image, stepName, apiConfig);
32
- }
33
- catch (error) {
34
- throw new Error(`failed to update plugin image: ${error.message}`);
35
- }
36
- }
37
- else {
38
- try {
39
- config.sdkmessageprocessingstepimageid = await createImage(image, stepName, apiConfig);
40
- }
41
- catch (error) {
42
- throw new Error(`failed to create plugin image: ${error.message}`);
43
- }
44
- }
45
- }
46
- exports.deployImage = deployImage;
47
- async function retrieveImage(stepId, image, apiConfig) {
48
- const options = `$select=sdkmessageprocessingstepimageid&$filter=name eq '${image.name}' and _sdkmessageprocessingstepid_value eq ${stepId}`;
49
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingstepimages', options);
50
- return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepimageid : '';
51
- }
52
- async function createImage(image, stepName, apiConfig) {
53
- logger_1.logger.info(`create plugin image ${image.name} for step ${stepName}`);
54
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingstepimages', image, '$select=sdkmessageprocessingstepimageid');
55
- if (result?.error) {
56
- throw new Error(result.error.message);
57
- }
58
- return result.sdkmessageprocessingstepimageid;
59
- }
60
- async function updateImage(id, image, stepName, apiConfig) {
61
- logger_1.logger.info(`update plugin image ${image.name} for step ${stepName}`);
62
- const result = await (0, node_1.update)(apiConfig, 'sdkmessageprocessingstepimages', id, image);
63
- if (result?.error) {
64
- throw new Error(result.error.message);
65
- }
66
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deployImage = void 0;
4
+ const logger_1 = require("../logger");
5
+ const node_1 = require("dataverse-webapi/lib/node");
6
+ async function deployImage(stepId, stepName, config, message, apiConfig) {
7
+ const image = structuredClone(config);
8
+ image['sdkmessageprocessingstepid@odata.bind'] = `/sdkmessageprocessingsteps(${stepId})`;
9
+ switch (message) {
10
+ case 'Create':
11
+ image.messagepropertyname = 'Id';
12
+ break;
13
+ case 'SetState':
14
+ case 'SetStateDynamicEntity':
15
+ image.messagepropertyname = 'EntityMoniker';
16
+ break;
17
+ case 'Send':
18
+ case 'DeliverIncoming':
19
+ case 'DeliverPromote':
20
+ image.messagepropertyname = 'EmailId';
21
+ break;
22
+ default:
23
+ image.messagepropertyname = 'Target';
24
+ break;
25
+ }
26
+ if (!config.sdkmessageprocessingstepimageid) {
27
+ config.sdkmessageprocessingstepimageid = await retrieveImage(stepId, image, apiConfig);
28
+ }
29
+ if (config.sdkmessageprocessingstepimageid) {
30
+ try {
31
+ await updateImage(config.sdkmessageprocessingstepimageid, image, stepName, apiConfig);
32
+ }
33
+ catch (error) {
34
+ throw new Error(`failed to update plugin image: ${error.message}`);
35
+ }
36
+ }
37
+ else {
38
+ try {
39
+ config.sdkmessageprocessingstepimageid = await createImage(image, stepName, apiConfig);
40
+ }
41
+ catch (error) {
42
+ throw new Error(`failed to create plugin image: ${error.message}`);
43
+ }
44
+ }
45
+ }
46
+ exports.deployImage = deployImage;
47
+ async function retrieveImage(stepId, image, apiConfig) {
48
+ const options = `$select=sdkmessageprocessingstepimageid&$filter=name eq '${image.name}' and _sdkmessageprocessingstepid_value eq ${stepId}`;
49
+ const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingstepimages', options);
50
+ return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepimageid : '';
51
+ }
52
+ async function createImage(image, stepName, apiConfig) {
53
+ logger_1.logger.info(`create plugin image ${image.name} for step ${stepName}`);
54
+ const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingstepimages', image, '$select=sdkmessageprocessingstepimageid');
55
+ if (result?.error) {
56
+ throw new Error(result.error.message);
57
+ }
58
+ return result.sdkmessageprocessingstepimageid;
59
+ }
60
+ async function updateImage(id, image, stepName, apiConfig) {
61
+ logger_1.logger.info(`update plugin image ${image.name} for step ${stepName}`);
62
+ const result = await (0, node_1.update)(apiConfig, 'sdkmessageprocessingstepimages', id, image);
63
+ if (result?.error) {
64
+ throw new Error(result.error.message);
65
+ }
66
+ }
@@ -1,93 +1,93 @@
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.deployPluginPackage = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const glob_1 = __importDefault(require("glob"));
9
- const node_1 = require("dataverse-webapi/lib/node");
10
- const pluginAssembly_1 = require("./pluginAssembly");
11
- const logger_1 = require("../logger");
12
- const pluginType_1 = require("./pluginType");
13
- const pluginStep_1 = require("./pluginStep");
14
- async function deployPluginPackage(config, apiConfig, solution) {
15
- const files = glob_1.default.sync(`**/${config.name}.*.nupkg`);
16
- if (files.length === 0) {
17
- logger_1.logger.warn(`package ${config.name}.nupkg not found`);
18
- return;
19
- }
20
- const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
21
- if (!config.pluginpackageid) {
22
- config.pluginpackageid = await retrievePackage(config.prefix, config.name, apiConfig);
23
- }
24
- if (config.pluginpackageid) {
25
- try {
26
- await updatePackage(config, content, apiConfig);
27
- }
28
- catch (error) {
29
- throw new Error(`failed to update package: ${error.message}`);
30
- }
31
- }
32
- else {
33
- try {
34
- config.pluginpackageid = await createPackage(config, content, apiConfig, solution);
35
- }
36
- catch (error) {
37
- throw new Error(`failed to create package: ${error.message}`);
38
- }
39
- }
40
- if (config.assembly != null) {
41
- try {
42
- if (config.assembly.pluginassemblyid) {
43
- config.assembly.pluginassemblyid = await (0, pluginAssembly_1.retrieveAssembly)(config.assembly.name, apiConfig);
44
- }
45
- const promises = config.assembly.types?.map(async (t) => {
46
- if (!t.plugintypeid && config.assembly?.pluginassemblyid) {
47
- t.plugintypeid = await (0, pluginType_1.retrieveType)(t.typename, config.assembly.pluginassemblyid, apiConfig);
48
- }
49
- const stepPromises = t.steps?.map((s) => (0, pluginStep_1.deployStep)(s, t.plugintypeid, apiConfig, solution)) ?? [];
50
- await Promise.all(stepPromises);
51
- }) ?? [];
52
- await Promise.all(promises);
53
- }
54
- catch (error) {
55
- logger_1.logger.error(error.message);
56
- return;
57
- }
58
- }
59
- }
60
- exports.deployPluginPackage = deployPluginPackage;
61
- async function retrievePackage(prefix, name, apiConfig) {
62
- const options = `$select=pluginpackageid&$filter=contains(name, '${prefix}_${name}')`;
63
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginpackages', options);
64
- return result.value.length > 0 ? result.value[0].pluginpackageid : '';
65
- }
66
- async function createPackage(config, content, apiConfig, solution) {
67
- logger_1.logger.info(`create package ${config.name}`);
68
- const pluginPackage = {
69
- name: `${config.prefix}_${config.name}`,
70
- version: config.version,
71
- content: content
72
- };
73
- const options = {};
74
- if (solution) {
75
- options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
76
- }
77
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginpackages', pluginPackage, '$select=pluginpackageid', options);
78
- if (result?.error) {
79
- throw new Error(result.error.message);
80
- }
81
- return result.pluginpackageid;
82
- }
83
- async function updatePackage(config, content, apiConfig) {
84
- logger_1.logger.info(`update package ${config.name}`);
85
- const updated = {
86
- content: content,
87
- version: config.version
88
- };
89
- const result = await (0, node_1.update)(apiConfig, 'pluginpackages', config.pluginpackageid, updated);
90
- if (result?.error) {
91
- throw new Error(result.error.message);
92
- }
93
- }
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.deployPluginPackage = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const glob_1 = __importDefault(require("glob"));
9
+ const node_1 = require("dataverse-webapi/lib/node");
10
+ const pluginAssembly_1 = require("./pluginAssembly");
11
+ const logger_1 = require("../logger");
12
+ const pluginType_1 = require("./pluginType");
13
+ const pluginStep_1 = require("./pluginStep");
14
+ async function deployPluginPackage(config, apiConfig, solution) {
15
+ const files = glob_1.default.sync(`**/${config.name}.*.nupkg`);
16
+ if (files.length === 0) {
17
+ logger_1.logger.warn(`package ${config.name}.nupkg not found`);
18
+ return;
19
+ }
20
+ const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
21
+ if (!config.pluginpackageid) {
22
+ config.pluginpackageid = await retrievePackage(config.prefix, config.name, apiConfig);
23
+ }
24
+ if (config.pluginpackageid) {
25
+ try {
26
+ await updatePackage(config, content, apiConfig);
27
+ }
28
+ catch (error) {
29
+ throw new Error(`failed to update package: ${error.message}`);
30
+ }
31
+ }
32
+ else {
33
+ try {
34
+ config.pluginpackageid = await createPackage(config, content, apiConfig, solution);
35
+ }
36
+ catch (error) {
37
+ throw new Error(`failed to create package: ${error.message}`);
38
+ }
39
+ }
40
+ if (config.assembly != null) {
41
+ try {
42
+ if (!config.assembly.pluginassemblyid) {
43
+ config.assembly.pluginassemblyid = await (0, pluginAssembly_1.retrieveAssembly)(config.assembly.name, apiConfig);
44
+ }
45
+ const promises = config.assembly.types?.map(async (t) => {
46
+ if (!t.plugintypeid && config.assembly?.pluginassemblyid) {
47
+ t.plugintypeid = await (0, pluginType_1.retrieveType)(t.typename, config.assembly.pluginassemblyid, apiConfig);
48
+ }
49
+ const stepPromises = t.steps?.map((s) => (0, pluginStep_1.deployStep)(s, t.plugintypeid, apiConfig, solution)) ?? [];
50
+ await Promise.all(stepPromises);
51
+ }) ?? [];
52
+ await Promise.all(promises);
53
+ }
54
+ catch (error) {
55
+ logger_1.logger.error(error.message);
56
+ return;
57
+ }
58
+ }
59
+ }
60
+ exports.deployPluginPackage = deployPluginPackage;
61
+ async function retrievePackage(prefix, name, apiConfig) {
62
+ const options = `$select=pluginpackageid&$filter=contains(name, '${prefix}_${name}')`;
63
+ const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginpackages', options);
64
+ return result.value.length > 0 ? result.value[0].pluginpackageid : '';
65
+ }
66
+ async function createPackage(config, content, apiConfig, solution) {
67
+ logger_1.logger.info(`create package ${config.name}`);
68
+ const pluginPackage = {
69
+ name: `${config.prefix}_${config.name}`,
70
+ version: config.version,
71
+ content: content
72
+ };
73
+ const options = {};
74
+ if (solution) {
75
+ options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
76
+ }
77
+ const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginpackages', pluginPackage, '$select=pluginpackageid', options);
78
+ if (result?.error) {
79
+ throw new Error(result.error.message);
80
+ }
81
+ return result.pluginpackageid;
82
+ }
83
+ async function updatePackage(config, content, apiConfig) {
84
+ logger_1.logger.info(`update package ${config.name}`);
85
+ const updated = {
86
+ content: content,
87
+ version: config.version
88
+ };
89
+ const result = await (0, node_1.update)(apiConfig, 'pluginpackages', config.pluginpackageid, updated);
90
+ if (result?.error) {
91
+ throw new Error(result.error.message);
92
+ }
93
+ }