dataverse-utils 2.5.2 → 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.
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const pluginAssembly_1 = require("./models/pluginAssembly");
10
10
  const pluginPackage_1 = require("./models/pluginPackage");
11
+ const customApi_1 = require("./models/customApi");
11
12
  const logger_1 = require("./logger");
12
13
  async function assemblyDeploy(creds, apiConfig) {
13
14
  const currentPath = '.';
@@ -17,10 +18,11 @@ async function assemblyDeploy(creds, apiConfig) {
17
18
  return;
18
19
  }
19
20
  const config = JSON.parse(configFile);
20
- if (config.prefix) {
21
+ let assemblyId;
22
+ if (config.assembly) {
21
23
  logger_1.logger.info('deploy plugin package');
22
24
  try {
23
- await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
25
+ assemblyId = await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
24
26
  }
25
27
  catch (error) {
26
28
  logger_1.logger.error(error.message);
@@ -31,7 +33,7 @@ async function assemblyDeploy(creds, apiConfig) {
31
33
  else {
32
34
  logger_1.logger.info('deploy assembly');
33
35
  try {
34
- await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
36
+ assemblyId = await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
35
37
  }
36
38
  catch (error) {
37
39
  logger_1.logger.error(error.message);
@@ -39,5 +41,14 @@ async function assemblyDeploy(creds, apiConfig) {
39
41
  }
40
42
  logger_1.logger.done(`deployed assembly ${config.name}\r\n`);
41
43
  }
44
+ if (config.customapis != null && assemblyId) {
45
+ try {
46
+ const promises = config.customapis.map((a) => (0, customApi_1.deployApi)(a, assemblyId, apiConfig, creds.solution));
47
+ await Promise.all(promises);
48
+ }
49
+ catch (error) {
50
+ logger_1.logger.error(error.message);
51
+ }
52
+ }
42
53
  }
43
54
  exports.assemblyDeploy = assemblyDeploy;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveApi = exports.deployApi = void 0;
4
+ const node_1 = require("dataverse-webapi/lib/node");
5
+ const pluginType_1 = require("./pluginType");
6
+ const logger_1 = require("../logger");
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})`;
17
+ }
18
+ if (apiId != '') {
19
+ try {
20
+ await updateApi(apiId, api, apiConfig);
21
+ }
22
+ catch (error) {
23
+ throw new Error(`failed to update custom api: ${error.message}`);
24
+ }
25
+ }
26
+ else {
27
+ try {
28
+ apiId = await createApi(api, apiConfig, solution);
29
+ }
30
+ catch (error) {
31
+ throw new Error(`failed to create custom api: ${error.message}`);
32
+ }
33
+ }
34
+ }
35
+ exports.deployApi = deployApi;
36
+ async function retrieveApi(name, apiConfig) {
37
+ const options = `$select=customapiid&$filter=name eq '${name}'`;
38
+ const result = await (0, node_1.retrieveMultiple)(apiConfig, 'customapis', options);
39
+ return result.value.length > 0 ? result.value[0].customapiid : '';
40
+ }
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);
49
+ if (result.error) {
50
+ throw new Error(result.error.message);
51
+ }
52
+ return result.customapiid;
53
+ }
54
+ async function updateApi(id, api, apiConfig) {
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
+ }
68
+ return (0, node_1.update)(apiConfig, 'customapis', id, api);
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(async (type) => {
45
+ const promises = config.types.map((type) => {
55
46
  type['pluginassemblyid@odata.bind'] = `/pluginassemblies(${assemblyId})`;
56
- await (0, pluginType_1.deployType)(type, assemblyId, apiConfig, solution);
47
+ return (0, pluginType_1.deployType)(type, assemblyId, apiConfig, solution);
57
48
  });
58
49
  await Promise.all(promises);
59
50
  }
@@ -62,6 +53,7 @@ async function deployAssembly(config, apiConfig, solution) {
62
53
  return;
63
54
  }
64
55
  }
56
+ return assemblyId;
65
57
  }
66
58
  exports.deployAssembly = deployAssembly;
67
59
  async function retrieveAssembly(name, apiConfig) {
@@ -69,7 +61,7 @@ async function retrieveAssembly(name, apiConfig) {
69
61
  const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
70
62
  return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
71
63
  }
72
- async function createAssembly(config, content, apiConfig) {
64
+ async function createAssembly(config, content, apiConfig, solution) {
73
65
  logger_1.logger.info(`create assembly ${config.name}`);
74
66
  const assembly = {
75
67
  name: config.name,
@@ -80,7 +72,11 @@ async function createAssembly(config, content, apiConfig) {
80
72
  sourcetype: 0,
81
73
  culture: ''
82
74
  };
83
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid');
75
+ const options = {};
76
+ if (solution) {
77
+ options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
78
+ }
79
+ const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid', options);
84
80
  if (result.error) {
85
81
  throw new Error(result.error.message);
86
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`);
@@ -35,30 +34,24 @@ async function deployPluginPackage(config, apiConfig, solution) {
35
34
  }
36
35
  else {
37
36
  try {
38
- packageId = await createPackage(config, content, apiConfig);
37
+ packageId = await createPackage(config, content, apiConfig, solution);
39
38
  }
40
39
  catch (error) {
41
40
  throw new Error(`failed to create package: ${error.message}`);
42
41
  }
43
- if (solution != undefined) {
44
- try {
45
- await (0, dataverse_service_1.addToSolution)(packageId, solution, dataverse_service_1.ComponentType.PluginPackage, apiConfig);
46
- }
47
- catch (error) {
48
- logger_1.logger.error(`failed to add package to solution: ${error.message}`);
49
- }
50
- }
51
42
  }
43
+ let assemblyId;
52
44
  if (config.assembly != null) {
53
45
  try {
54
46
  config.assembly['packageid@odata.bind'] = `/pluginpackages(${packageId})`;
55
- await (0, pluginAssembly_1.deployAssembly)(config.assembly, apiConfig, solution);
47
+ assemblyId = await (0, pluginAssembly_1.deployAssembly)(config.assembly, apiConfig, solution);
56
48
  }
57
49
  catch (error) {
58
50
  logger_1.logger.error(error.message);
59
51
  return;
60
52
  }
61
53
  }
54
+ return assemblyId;
62
55
  }
63
56
  exports.deployPluginPackage = deployPluginPackage;
64
57
  async function retrievePackage(prefix, name, apiConfig) {
@@ -66,14 +59,18 @@ async function retrievePackage(prefix, name, apiConfig) {
66
59
  const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginpackages', options);
67
60
  return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
68
61
  }
69
- async function createPackage(config, content, apiConfig) {
62
+ async function createPackage(config, content, apiConfig, solution) {
70
63
  logger_1.logger.info(`create package ${config.name}`);
71
64
  const pluginPackage = {
72
65
  name: `${config.prefix}_${config.name}`,
73
66
  version: config.version,
74
67
  content: content
75
68
  };
76
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginpackages', pluginPackage, '$select=pluginpackageid');
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);
77
74
  if (result.error) {
78
75
  throw new Error(result.error.message);
79
76
  }
@@ -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 result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid');
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
  }
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deployType = void 0;
3
+ exports.retrieveType = exports.deployType = void 0;
4
4
  const node_1 = require("dataverse-webapi/lib/node");
5
5
  const pluginStep_1 = require("./pluginStep");
6
6
  const logger_1 = require("../logger");
7
- async function deployType(type, assemblyId, apiConfig, solution) {
8
- let typeId = await retrieveType(type.typename, assemblyId, apiConfig);
9
- const record = {
10
- name: type.name,
11
- friendlyname: type.friendlyname,
12
- typename: type.typename,
13
- 'pluginassemblyid@odata.bind': type['pluginassemblyid@odata.bind'],
14
- workflowactivitygroupname: type.workflowactivitygroupname
7
+ async function deployType(config, assemblyId, apiConfig, solution) {
8
+ let typeId = await retrieveType(config.typename, assemblyId, apiConfig);
9
+ const type = {
10
+ name: config.name,
11
+ friendlyname: config.friendlyname,
12
+ typename: config.typename,
13
+ 'pluginassemblyid@odata.bind': config['pluginassemblyid@odata.bind'],
14
+ workflowactivitygroupname: config.workflowactivitygroupname
15
15
  };
16
16
  if (typeId != '') {
17
17
  try {
18
- await updateType(typeId, record, apiConfig);
18
+ await updateType(typeId, type, apiConfig);
19
19
  }
20
20
  catch (error) {
21
21
  throw new Error(`failed to update plugin type: ${error.message}`);
@@ -23,17 +23,17 @@ async function deployType(type, assemblyId, apiConfig, solution) {
23
23
  }
24
24
  else {
25
25
  try {
26
- typeId = await createType(record, apiConfig);
26
+ typeId = await createType(type, apiConfig);
27
27
  }
28
28
  catch (error) {
29
29
  throw new Error(`failed to create plugin type: ${error.message}`);
30
30
  }
31
31
  }
32
32
  try {
33
- if (type.steps) {
34
- const promises = type.steps.map(async (step) => {
33
+ if (config.steps) {
34
+ const promises = config.steps.map((step) => {
35
35
  step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
36
- await (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
36
+ return (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
37
37
  });
38
38
  await Promise.all(promises);
39
39
  }
@@ -49,6 +49,7 @@ async function retrieveType(name, assemblyId, apiConfig) {
49
49
  const result = await (0, node_1.retrieveMultiple)(apiConfig, 'plugintypes', options);
50
50
  return result.value.length > 0 ? result.value[0].plugintypeid : '';
51
51
  }
52
+ exports.retrieveType = retrieveType;
52
53
  async function createType(type, apiConfig) {
53
54
  logger_1.logger.info(`create assembly type ${type.name}`);
54
55
  const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', type, '$select=plugintypeid');
@@ -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 result = await (0, node_1.createWithReturnData)(apiConfig, 'webresourceset', webResource, '$select=webresourceid');
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.5.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.12.0",
23
+ "@azure/msal-node": "^1.14.5",
24
24
  "commander": "^8.3.0",
25
25
  "cryptr": "^6.0.3",
26
- "dataverse-webapi": "^2.2.0",
26
+ "dataverse-webapi": "^2.3.0",
27
27
  "envinfo": "^7.8.1",
28
28
  "figures": "^3.2.0",
29
29
  "glob": "^7.2.0",