dataverse-utils 2.6.10 → 2.7.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.
@@ -18,11 +18,10 @@ async function assemblyDeploy(creds, apiConfig) {
18
18
  return;
19
19
  }
20
20
  const config = JSON.parse(configFile);
21
- let assemblyId;
22
21
  if (config.assembly) {
23
22
  logger_1.logger.info('deploy plugin package');
24
23
  try {
25
- assemblyId = await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
24
+ await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
26
25
  }
27
26
  catch (error) {
28
27
  logger_1.logger.error(error.message);
@@ -33,7 +32,7 @@ async function assemblyDeploy(creds, apiConfig) {
33
32
  else {
34
33
  logger_1.logger.info(`deploy assembly to ${creds.server}`);
35
34
  try {
36
- assemblyId = await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
35
+ await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
37
36
  }
38
37
  catch (error) {
39
38
  logger_1.logger.error(error.message);
@@ -41,10 +40,10 @@ async function assemblyDeploy(creds, apiConfig) {
41
40
  }
42
41
  logger_1.logger.done(`deployed assembly ${config.name}`);
43
42
  }
44
- if (config.customapis != null && assemblyId) {
43
+ if (config.customapis != null && config.pluginassemblyid) {
45
44
  logger_1.logger.info('deploy custom api');
46
45
  try {
47
- const promises = config.customapis.map((a) => (0, customApi_1.deployApi)(a, assemblyId, apiConfig, creds.solution));
46
+ const promises = config.customapis.map((a) => (0, customApi_1.deployApi)(a, config.pluginassemblyid, apiConfig, creds.solution));
48
47
  await Promise.all(promises);
49
48
  }
50
49
  catch (error) {
@@ -52,5 +51,6 @@ async function assemblyDeploy(creds, apiConfig) {
52
51
  }
53
52
  logger_1.logger.done('deployed custom api');
54
53
  }
54
+ await fs_1.default.promises.writeFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), JSON.stringify(config, null, 4), 'utf8');
55
55
  }
56
56
  exports.assemblyDeploy = assemblyDeploy;
@@ -4,20 +4,25 @@ 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
- 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 === '') {
7
+ async function deployApi(config, assemblyId, apiConfig, solution) {
8
+ const api = structuredClone(config);
9
+ if (!config.customapiid) {
10
+ config.customapiid = await retrieveApi(api.name, apiConfig);
11
+ }
12
+ if (config.plugintype && !config.plugintypeid) {
13
+ config.plugintypeid = await (0, pluginType_1.retrieveType)(config.plugintype, assemblyId, apiConfig);
14
+ if (config.plugintypeid === '') {
12
15
  logger_1.logger.error(`unable to find plugin type ${api.plugintype}`);
13
16
  return;
14
17
  }
15
18
  delete api.plugintype;
16
- api['PluginTypeId@odata.bind'] = `plugintypes(${pluginTypeId})`;
19
+ delete api.customapiid;
20
+ delete api.plugintypeid;
21
+ api['PluginTypeId@odata.bind'] = `plugintypes(${config.plugintypeid})`;
17
22
  }
18
- if (apiId != '') {
23
+ if (config.customapiid) {
19
24
  try {
20
- await updateApi(apiId, api, apiConfig);
25
+ await updateApi(config.customapiid, api, apiConfig);
21
26
  }
22
27
  catch (error) {
23
28
  throw new Error(`failed to update custom api: ${error.message}`);
@@ -25,7 +30,7 @@ async function deployApi(api, assemblyId, apiConfig, solution) {
25
30
  }
26
31
  else {
27
32
  try {
28
- apiId = await createApi(api, apiConfig, solution);
33
+ config.customapiid = await createApi(api, apiConfig, solution);
29
34
  }
30
35
  catch (error) {
31
36
  throw new Error(`failed to create custom api: ${error.message}`);
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deployAssembly = void 0;
6
+ exports.retrieveAssembly = exports.deployAssembly = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const glob_1 = __importDefault(require("glob"));
9
9
  const node_1 = require("dataverse-webapi/lib/node");
@@ -16,17 +16,12 @@ async function deployAssembly(config, apiConfig, solution) {
16
16
  return;
17
17
  }
18
18
  const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
19
- let assemblyId = '';
20
- try {
21
- assemblyId = await retrieveAssembly(config.name, apiConfig);
19
+ if (!config.pluginassemblyid) {
20
+ config.pluginassemblyid = await retrieveAssembly(config.name, apiConfig);
22
21
  }
23
- catch (error) {
24
- logger_1.logger.error(`failed to retrieve assembly ${config.name}: ${error.message}`);
25
- return;
26
- }
27
- if (assemblyId != '') {
22
+ if (config.pluginassemblyid) {
28
23
  try {
29
- await updateAssembly(assemblyId, config, content, apiConfig);
24
+ await updateAssembly(config, content, apiConfig);
30
25
  }
31
26
  catch (error) {
32
27
  throw new Error(`failed to update assembly: ${error.message}`);
@@ -34,7 +29,7 @@ async function deployAssembly(config, apiConfig, solution) {
34
29
  }
35
30
  else {
36
31
  try {
37
- assemblyId = await createAssembly(config, content, apiConfig, solution);
32
+ config.pluginassemblyid = await createAssembly(config, content, apiConfig, solution);
38
33
  }
39
34
  catch (error) {
40
35
  throw new Error(`failed to create assembly: ${error.message}`);
@@ -42,10 +37,7 @@ async function deployAssembly(config, apiConfig, solution) {
42
37
  }
43
38
  if (config.types != null) {
44
39
  try {
45
- const promises = config.types.map((type) => {
46
- type['pluginassemblyid@odata.bind'] = `/pluginassemblies(${assemblyId})`;
47
- return (0, pluginType_1.deployType)(type, assemblyId, apiConfig, solution);
48
- });
40
+ const promises = config.types.map((type) => (0, pluginType_1.deployType)(type, config.pluginassemblyid, apiConfig, solution));
49
41
  await Promise.all(promises);
50
42
  }
51
43
  catch (error) {
@@ -53,7 +45,6 @@ async function deployAssembly(config, apiConfig, solution) {
53
45
  return;
54
46
  }
55
47
  }
56
- return assemblyId;
57
48
  }
58
49
  exports.deployAssembly = deployAssembly;
59
50
  async function retrieveAssembly(name, apiConfig) {
@@ -61,6 +52,7 @@ async function retrieveAssembly(name, apiConfig) {
61
52
  const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
62
53
  return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
63
54
  }
55
+ exports.retrieveAssembly = retrieveAssembly;
64
56
  async function createAssembly(config, content, apiConfig, solution) {
65
57
  logger_1.logger.info(`create assembly ${config.name}`);
66
58
  const assembly = {
@@ -82,13 +74,13 @@ async function createAssembly(config, content, apiConfig, solution) {
82
74
  }
83
75
  return result.pluginassemblyid;
84
76
  }
85
- async function updateAssembly(id, config, content, apiConfig) {
77
+ async function updateAssembly(config, content, apiConfig) {
86
78
  logger_1.logger.info(`update assembly ${config.name}`);
87
79
  const assembly = {
88
80
  content: content,
89
81
  version: config.version
90
82
  };
91
- const result = await (0, node_1.update)(apiConfig, 'pluginassemblies', id, assembly);
83
+ const result = await (0, node_1.update)(apiConfig, 'pluginassemblies', config.pluginassemblyid, assembly);
92
84
  if (result?.error) {
93
85
  throw new Error(result.error.message);
94
86
  }
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deployImage = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const node_1 = require("dataverse-webapi/lib/node");
6
- async function deployImage(stepId, stepName, image, message, apiConfig) {
6
+ async function deployImage(stepId, stepName, config, message, apiConfig) {
7
+ const image = structuredClone(config);
7
8
  image['sdkmessageprocessingstepid@odata.bind'] = `/sdkmessageprocessingsteps(${stepId})`;
8
9
  switch (message) {
9
10
  case 'Create':
@@ -22,10 +23,12 @@ async function deployImage(stepId, stepName, image, message, apiConfig) {
22
23
  image.messagepropertyname = 'Target';
23
24
  break;
24
25
  }
25
- let imageId = await retrieveImage(stepId, image, apiConfig);
26
- if (imageId != '') {
26
+ if (!config.sdkmessageprocessingstepimageid) {
27
+ config.sdkmessageprocessingstepimageid = await retrieveImage(stepId, image, apiConfig);
28
+ }
29
+ if (config.sdkmessageprocessingstepimageid) {
27
30
  try {
28
- await updateImage(imageId, image, stepName, apiConfig);
31
+ await updateImage(config.sdkmessageprocessingstepimageid, image, stepName, apiConfig);
29
32
  }
30
33
  catch (error) {
31
34
  throw new Error(`failed to update plugin image: ${error.message}`);
@@ -33,13 +36,12 @@ async function deployImage(stepId, stepName, image, message, apiConfig) {
33
36
  }
34
37
  else {
35
38
  try {
36
- imageId = await createImage(image, stepName, apiConfig);
39
+ config.sdkmessageprocessingstepimageid = await createImage(image, stepName, apiConfig);
37
40
  }
38
41
  catch (error) {
39
42
  throw new Error(`failed to create plugin image: ${error.message}`);
40
43
  }
41
44
  }
42
- return imageId;
43
45
  }
44
46
  exports.deployImage = deployImage;
45
47
  async function retrieveImage(stepId, image, apiConfig) {
@@ -9,6 +9,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
11
  const logger_1 = require("../logger");
12
+ const pluginType_1 = require("./pluginType");
13
+ const pluginStep_1 = require("./pluginStep");
12
14
  async function deployPluginPackage(config, apiConfig, solution) {
13
15
  const files = glob_1.default.sync(`**/${config.name}.*.nupkg`);
14
16
  if (files.length === 0) {
@@ -16,17 +18,12 @@ async function deployPluginPackage(config, apiConfig, solution) {
16
18
  return;
17
19
  }
18
20
  const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
19
- let packageId = '';
20
- try {
21
- packageId = await retrievePackage(config.prefix, config.name, apiConfig);
21
+ if (!config.pluginpackageid) {
22
+ config.pluginpackageid = await retrievePackage(config.prefix, config.name, apiConfig);
22
23
  }
23
- catch (error) {
24
- logger_1.logger.error(`failed to retrieve package ${config.name}: ${error.message}`);
25
- return;
26
- }
27
- if (packageId != '') {
24
+ if (config.pluginpackageid) {
28
25
  try {
29
- await updatePackage(packageId, config, content, apiConfig);
26
+ await updatePackage(config, content, apiConfig);
30
27
  }
31
28
  catch (error) {
32
29
  throw new Error(`failed to update package: ${error.message}`);
@@ -34,24 +31,31 @@ async function deployPluginPackage(config, apiConfig, solution) {
34
31
  }
35
32
  else {
36
33
  try {
37
- packageId = await createPackage(config, content, apiConfig, solution);
34
+ config.pluginpackageid = await createPackage(config, content, apiConfig, solution);
38
35
  }
39
36
  catch (error) {
40
37
  throw new Error(`failed to create package: ${error.message}`);
41
38
  }
42
39
  }
43
- let assemblyId;
44
40
  if (config.assembly != null) {
45
41
  try {
46
- config.assembly['packageid@odata.bind'] = `/pluginpackages(${packageId})`;
47
- assemblyId = await (0, pluginAssembly_1.deployAssembly)(config.assembly, apiConfig, solution);
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);
48
53
  }
49
54
  catch (error) {
50
55
  logger_1.logger.error(error.message);
51
56
  return;
52
57
  }
53
58
  }
54
- return assemblyId;
55
59
  }
56
60
  exports.deployPluginPackage = deployPluginPackage;
57
61
  async function retrievePackage(prefix, name, apiConfig) {
@@ -76,13 +80,13 @@ async function createPackage(config, content, apiConfig, solution) {
76
80
  }
77
81
  return result.pluginpackageid;
78
82
  }
79
- async function updatePackage(id, config, content, apiConfig) {
83
+ async function updatePackage(config, content, apiConfig) {
80
84
  logger_1.logger.info(`update package ${config.name}`);
81
85
  const updated = {
82
86
  content: content,
83
87
  version: config.version
84
88
  };
85
- const result = await (0, node_1.update)(apiConfig, 'pluginpackages', id, updated);
89
+ const result = await (0, node_1.update)(apiConfig, 'pluginpackages', config.pluginpackageid, updated);
86
90
  if (result?.error) {
87
91
  throw new Error(result.error.message);
88
92
  }
@@ -4,8 +4,9 @@ exports.deployStep = void 0;
4
4
  const node_1 = require("dataverse-webapi/lib/node");
5
5
  const logger_1 = require("../logger");
6
6
  const pluginImage_1 = require("./pluginImage");
7
- async function deployStep(step, typeId, apiConfig, solution) {
8
- let stepId = await retrieveStep(step.name, typeId, apiConfig);
7
+ async function deployStep(config, pluginTypeId, apiConfig, solution) {
8
+ const step = structuredClone(config);
9
+ step['plugintypeid@odata.bind'] = `/plugintypes(${pluginTypeId})`;
9
10
  const messageId = await getSdkMessageId(step.message ?? '', apiConfig);
10
11
  if (messageId == '') {
11
12
  logger_1.logger.warn(`sdk message ${step.message} not found`);
@@ -23,14 +24,16 @@ async function deployStep(step, typeId, apiConfig, solution) {
23
24
  if (step.mode === 1) {
24
25
  step.asyncautodelete = true;
25
26
  }
26
- const images = step.images;
27
- const message = step.message;
28
27
  delete step.images;
29
28
  delete step.message;
30
29
  delete step.entity;
31
- if (stepId != '') {
30
+ delete step.sdkmessageprocessingstepid;
31
+ if (!config.sdkmessageprocessingstepid) {
32
+ config.sdkmessageprocessingstepid = await retrieveStep(step.name, pluginTypeId, apiConfig);
33
+ }
34
+ if (config.sdkmessageprocessingstepid) {
32
35
  try {
33
- await updateStep(stepId, step, apiConfig);
36
+ await updateStep(config.sdkmessageprocessingstepid, step, apiConfig);
34
37
  }
35
38
  catch (error) {
36
39
  throw new Error(`failed to update plugin step: ${error.message}`);
@@ -38,29 +41,23 @@ async function deployStep(step, typeId, apiConfig, solution) {
38
41
  }
39
42
  else {
40
43
  try {
41
- stepId = await createStep(step, apiConfig, solution);
44
+ config.sdkmessageprocessingstepid = await createStep(step, apiConfig, solution);
42
45
  }
43
46
  catch (error) {
44
47
  throw new Error(`failed to create plugin step: ${error.message}`);
45
48
  }
46
49
  }
47
- if (images && images.length > 0) {
50
+ if (config.images && config.images.length > 0) {
48
51
  try {
49
- const promises = images.map((image) => (0, pluginImage_1.deployImage)(stepId, step.name, image, message, apiConfig));
52
+ const promises = config.images.map((image) => (0, pluginImage_1.deployImage)(config.sdkmessageprocessingstepid, step.name, image, config.message, apiConfig));
50
53
  await Promise.all(promises);
51
54
  }
52
55
  catch (error) {
53
56
  throw new Error(error.message);
54
57
  }
55
58
  }
56
- return stepId;
57
59
  }
58
60
  exports.deployStep = deployStep;
59
- async function retrieveStep(name, typeId, apiConfig) {
60
- const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}' and _plugintypeid_value eq ${typeId}`;
61
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
62
- return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
63
- }
64
61
  async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
65
62
  const options = [
66
63
  `?$filter=primaryobjecttypecode eq '${entityName}' and _sdkmessageid_value eq ${messageId}`,
@@ -74,6 +71,11 @@ async function getSdkMessageId(name, apiConfig) {
74
71
  const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
75
72
  return message.value.length > 0 ? message.value[0].sdkmessageid : '';
76
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
+ }
77
79
  async function createStep(step, apiConfig, solution) {
78
80
  logger_1.logger.info(`create plugin step ${step.name}`);
79
81
  const options = {};
@@ -5,7 +5,6 @@ const node_1 = require("dataverse-webapi/lib/node");
5
5
  const pluginStep_1 = require("./pluginStep");
6
6
  const logger_1 = require("../logger");
7
7
  async function deployType(config, assemblyId, apiConfig, solution) {
8
- let typeId = await retrieveType(config.typename, assemblyId, apiConfig);
9
8
  const type = {
10
9
  name: config.name,
11
10
  friendlyname: config.friendlyname,
@@ -13,9 +12,12 @@ async function deployType(config, assemblyId, apiConfig, solution) {
13
12
  'pluginassemblyid@odata.bind': config['pluginassemblyid@odata.bind'],
14
13
  workflowactivitygroupname: config.workflowactivitygroupname
15
14
  };
16
- if (typeId != '') {
15
+ if (!config.plugintypeid) {
16
+ config.plugintypeid = await retrieveType(config.name, assemblyId, apiConfig);
17
+ }
18
+ if (config.plugintypeid) {
17
19
  try {
18
- await updateType(typeId, type, apiConfig);
20
+ await updateType(config.plugintypeid, type, apiConfig);
19
21
  }
20
22
  catch (error) {
21
23
  throw new Error(`failed to update plugin type: ${error.message}`);
@@ -23,7 +25,7 @@ async function deployType(config, assemblyId, apiConfig, solution) {
23
25
  }
24
26
  else {
25
27
  try {
26
- typeId = await createType(type, apiConfig);
28
+ config.plugintypeid = await createType(type, apiConfig);
27
29
  }
28
30
  catch (error) {
29
31
  throw new Error(`failed to create plugin type: ${error.message}`);
@@ -31,17 +33,13 @@ async function deployType(config, assemblyId, apiConfig, solution) {
31
33
  }
32
34
  try {
33
35
  if (config.steps) {
34
- const promises = config.steps.map((step) => {
35
- step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
36
- return (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
37
- });
36
+ const promises = config.steps.map((step) => (0, pluginStep_1.deployStep)(step, config.plugintypeid, apiConfig, solution));
38
37
  await Promise.all(promises);
39
38
  }
40
39
  }
41
40
  catch (error) {
42
41
  throw new Error(error.message);
43
42
  }
44
- return typeId;
45
43
  }
46
44
  exports.deployType = deployType;
47
45
  async function retrieveType(name, assemblyId, apiConfig) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataverse-utils",
3
- "version": "2.6.10",
3
+ "version": "2.7.0",
4
4
  "license": "MIT",
5
5
  "description": "Utilities for interacting with Dataverse environments",
6
6
  "main": "lib/index.js",