dataverse-utils 2.5.2 → 2.5.3

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,15 @@ 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 && config.customApis.length > 0 && assemblyId) {
45
+ try {
46
+ const promises = config.customApis.map(a => (0, customApi_1.deployApi)(a, apiConfig, creds.solution, assemblyId ?? ''));
47
+ await Promise.all(promises);
48
+ }
49
+ catch (error) {
50
+ logger_1.logger.error(error.message);
51
+ return;
52
+ }
53
+ }
42
54
  }
43
55
  exports.assemblyDeploy = assemblyDeploy;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deployApi = exports.ParameterType = exports.BindingType = exports.CustomProcessingStepType = void 0;
4
+ const node_1 = require("dataverse-webapi/lib/node");
5
+ const pluginType_1 = require("./pluginType");
6
+ const logger_1 = require("../logger");
7
+ var CustomProcessingStepType;
8
+ (function (CustomProcessingStepType) {
9
+ })(CustomProcessingStepType = exports.CustomProcessingStepType || (exports.CustomProcessingStepType = {}));
10
+ var BindingType;
11
+ (function (BindingType) {
12
+ })(BindingType = exports.BindingType || (exports.BindingType = {}));
13
+ var ParameterType;
14
+ (function (ParameterType) {
15
+ })(ParameterType = exports.ParameterType || (exports.ParameterType = {}));
16
+ async function deployApi(config, apiConfig, solution, assemblyId) {
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;
22
+ }
23
+ delete config.pluginType;
24
+ config['PluginTypeId@odata.bind'] = `plugintypes(${pluginTypeId})`;
25
+ if (apiId != '') {
26
+ try {
27
+ await updateApi(apiId, config, apiConfig);
28
+ }
29
+ catch (error) {
30
+ throw new Error(`failed to update customa api: ${error.message}`);
31
+ }
32
+ }
33
+ else {
34
+ try {
35
+ await createApi(config, solution, apiConfig);
36
+ }
37
+ catch (error) {
38
+ throw new Error(`failed to create custom api: ${error.message}`);
39
+ }
40
+ }
41
+ }
42
+ exports.deployApi = deployApi;
43
+ async function retrieveApi(name, apiConfig) {
44
+ const options = `$select=customapiid&$filter=name eq '${name}'`;
45
+ const result = await (0, node_1.retrieveMultiple)(apiConfig, 'customapis', options);
46
+ return result.value.length > 0 ? result.value[0].customapiid : '';
47
+ }
48
+ async function createApi(api, solution, apiConfig) {
49
+ logger_1.logger.info(`create custom api ${api.displayname}`);
50
+ const result = await (0, node_1.createWithReturnData)(apiConfig, 'customapis', api, '$select=customapiid');
51
+ if (result.error) {
52
+ throw new Error(result.error.message);
53
+ }
54
+ return result.customapiid;
55
+ }
56
+ async function updateApi(id, api, apiConfig) {
57
+ logger_1.logger.info(`update custom api ${api.displayname}`);
58
+ return (0, node_1.update)(apiConfig, 'customapis', id, api);
59
+ }
@@ -62,6 +62,7 @@ async function deployAssembly(config, apiConfig, solution) {
62
62
  return;
63
63
  }
64
64
  }
65
+ return assemblyId;
65
66
  }
66
67
  exports.deployAssembly = deployAssembly;
67
68
  async function retrieveAssembly(name, apiConfig) {
@@ -80,6 +81,9 @@ async function createAssembly(config, content, apiConfig) {
80
81
  sourcetype: 0,
81
82
  culture: ''
82
83
  };
84
+ if (config['packageid@odata.bind']) {
85
+ assembly['packageid@odata.bind'] = config['packageid@odata.bind'];
86
+ }
83
87
  const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid');
84
88
  if (result.error) {
85
89
  throw new Error(result.error.message);
@@ -18,6 +18,7 @@ async function deployPluginPackage(config, apiConfig, solution) {
18
18
  }
19
19
  const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
20
20
  let packageId = '';
21
+ let assemblyId;
21
22
  try {
22
23
  packageId = await retrievePackage(config.prefix, config.name, apiConfig);
23
24
  }
@@ -52,13 +53,14 @@ async function deployPluginPackage(config, apiConfig, solution) {
52
53
  if (config.assembly != null) {
53
54
  try {
54
55
  config.assembly['packageid@odata.bind'] = `/pluginpackages(${packageId})`;
55
- await (0, pluginAssembly_1.deployAssembly)(config.assembly, apiConfig, solution);
56
+ assemblyId = await (0, pluginAssembly_1.deployAssembly)(config.assembly, apiConfig, solution);
56
57
  }
57
58
  catch (error) {
58
59
  logger_1.logger.error(error.message);
59
60
  return;
60
61
  }
61
62
  }
63
+ return assemblyId;
62
64
  }
63
65
  exports.deployPluginPackage = deployPluginPackage;
64
66
  async function retrievePackage(prefix, name, apiConfig) {
@@ -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,15 +23,15 @@ 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(async (step) => {
35
35
  step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
36
36
  await (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
37
37
  });
@@ -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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataverse-utils",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "license": "MIT",
5
5
  "description": "Utilities for interacting with Dataverse environments",
6
6
  "main": "lib/index.js",
@@ -23,7 +23,7 @@
23
23
  "@azure/msal-node": "^1.12.0",
24
24
  "commander": "^8.3.0",
25
25
  "cryptr": "^6.0.3",
26
- "dataverse-webapi": "^2.2.0",
26
+ "dataverse-webapi": "^2.2.1",
27
27
  "envinfo": "^7.8.1",
28
28
  "figures": "^3.2.0",
29
29
  "glob": "^7.2.0",