dataverse-utils 2.2.5 → 2.2.8

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,98 +0,0 @@
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 dataverse_service_1 = require("../dataverse.service");
6
- const logger_1 = require("../logger");
7
- const pluginImage_1 = require("./pluginImage");
8
- async function deployStep(step, typeId, apiConfig, solution) {
9
- let stepId = await retrieveStep(step.name, typeId, apiConfig);
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
- const filterId = await getSdkMessageFilterId(messageId, step.entity ?? '', apiConfig);
16
- if (filterId == '') {
17
- logger_1.logger.warn(`sdk message ${step.message} for entity ${step.entity} not found`);
18
- return;
19
- }
20
- step['sdkmessagefilterid@odata.bind'] = `/sdkmessagefilters(${filterId})`;
21
- step['sdkmessageid@odata.bind'] = `/sdkmessages(${messageId})`;
22
- if (step.mode === 1) {
23
- step.asyncautodelete = true;
24
- }
25
- const images = step.images;
26
- const message = step.message;
27
- delete step.images;
28
- delete step.message;
29
- delete step.entity;
30
- if (stepId != '') {
31
- try {
32
- await updateStep(stepId, step, apiConfig);
33
- }
34
- catch (error) {
35
- throw new Error(`failed to update plugin step: ${error.message}`);
36
- }
37
- }
38
- else {
39
- try {
40
- stepId = await createStep(step, apiConfig);
41
- }
42
- catch (error) {
43
- throw new Error(`failed to create plugin step: ${error.message}`);
44
- }
45
- if (solution != undefined) {
46
- try {
47
- await (0, dataverse_service_1.addToSolution)(stepId, solution, dataverse_service_1.ComponentType.SDKMessageProcessingStep, apiConfig);
48
- }
49
- catch (error) {
50
- throw new Error(`failed to add to solution: ${error.message}`);
51
- }
52
- }
53
- }
54
- if (images && images.length > 0) {
55
- try {
56
- const promises = images.map(image => (0, pluginImage_1.deployImage)(stepId, image, message, apiConfig));
57
- await Promise.all(promises);
58
- }
59
- catch (error) {
60
- throw new Error(error.message);
61
- }
62
- }
63
- return stepId;
64
- }
65
- exports.deployStep = deployStep;
66
- async function retrieveStep(name, typeId, apiConfig) {
67
- const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}' and _plugintypeid_value eq ${typeId}`;
68
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
69
- return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
70
- }
71
- async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
72
- const options = [
73
- `?$filter=primaryobjecttypecode eq '${entityName}' and _sdkmessageid_value eq ${messageId}`,
74
- '&$select=sdkmessagefilterid'
75
- ].join('');
76
- const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessagefilters', options);
77
- return message.value.length > 0 ? message.value[0].sdkmessagefilterid : '';
78
- }
79
- async function getSdkMessageId(name, apiConfig) {
80
- const options = [
81
- `?$filter=name eq '${name}'`,
82
- '&$select=sdkmessageid'
83
- ].join('');
84
- const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
85
- return message.value.length > 0 ? message.value[0].sdkmessageid : '';
86
- }
87
- async function createStep(step, apiConfig) {
88
- logger_1.logger.info(`create plugin step ${step.name}`);
89
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid');
90
- if (result.error) {
91
- throw new Error(result.error.message);
92
- }
93
- return result.sdkmessageprocessingstepid;
94
- }
95
- async function updateStep(id, step, apiConfig) {
96
- logger_1.logger.info(`update plugin step ${step.name}`);
97
- return (0, node_1.update)(apiConfig, 'sdkmessageprocessingsteps', id, step);
98
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- 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(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
15
- };
16
- if (typeId != '') {
17
- try {
18
- await updateType(typeId, record, apiConfig);
19
- }
20
- catch (error) {
21
- throw new Error(`failed to update plugin type: ${error.message}`);
22
- }
23
- }
24
- else {
25
- try {
26
- typeId = await createType(record, apiConfig);
27
- }
28
- catch (error) {
29
- throw new Error(`failed to create plugin type: ${error.message}`);
30
- }
31
- }
32
- try {
33
- if (type.steps) {
34
- const promises = type.steps.map(async (step) => {
35
- step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
36
- await (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
37
- });
38
- await Promise.all(promises);
39
- }
40
- }
41
- catch (error) {
42
- throw new Error(error.message);
43
- }
44
- return typeId;
45
- }
46
- exports.deployType = deployType;
47
- async function retrieveType(name, assemblyId, apiConfig) {
48
- const options = `$select=plugintypeid&$filter=typename eq '${name}' and _pluginassemblyid_value eq ${assemblyId}`;
49
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'plugintypes', options);
50
- return result.value.length > 0 ? result.value[0].plugintypeid : '';
51
- }
52
- async function createType(type, apiConfig) {
53
- logger_1.logger.info(`create assembly type ${type.name}`);
54
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', type, '$select=plugintypeid');
55
- if (result.error) {
56
- throw new Error(result.error.message);
57
- }
58
- return result.plugintypeid;
59
- }
60
- async function updateType(id, type, apiConfig) {
61
- logger_1.logger.info(`update assembly type ${type.name}`);
62
- return (0, node_1.update)(apiConfig, 'plugintypes', id, type);
63
- }
@@ -1,131 +0,0 @@
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);
79
- }
80
- catch (error) {
81
- logger_1.logger.error(`failed to create resource: ${error.message}`);
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
- }
92
- });
93
- await Promise.all(promises);
94
- // publish resources
95
- if (publishXml.length > 0) {
96
- try {
97
- await (0, dataverse_service_1.publish)(publishXml.join(''), apiConfig);
98
- }
99
- catch (error) {
100
- logger_1.logger.error(error.message);
101
- }
102
- }
103
- }
104
- exports.deploy = deploy;
105
- async function retrieveResource(name, apiConfig) {
106
- const options = `$select=webresourceid&$filter=name eq '${name}'`;
107
- const result = await (0, node_1.retrieveMultiple)(apiConfig, 'webresourceset', options);
108
- return result.value.length > 0 ? result.value[0].webresourceid : '';
109
- }
110
- async function createResource(resource, content, apiConfig) {
111
- logger_1.logger.info(`create web resource ${resource.name}`);
112
- const webResource = {
113
- webresourcetype: getWebResourceType(resource.type),
114
- name: resource.name,
115
- displayname: resource.displayname || resource.name,
116
- content: content
117
- };
118
- const result = await (0, node_1.createWithReturnData)(apiConfig, 'webresourceset', webResource, '$select=webresourceid');
119
- if (result.error) {
120
- throw new Error(result.error.message);
121
- }
122
- return result.webresourceid;
123
- }
124
- async function updateResource(id, resource, content, apiConfig) {
125
- logger_1.logger.info(`update web resource ${resource.name}`);
126
- const webResource = {
127
- content: content
128
- };
129
- await (0, node_1.update)(apiConfig, 'webresourceset', id, webResource);
130
- return `<webresource>{${id}}</webresource>`;
131
- }
@@ -1,29 +0,0 @@
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.deployWebResource = 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 deployWebResource(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.deployWebResource = deployWebResource;
package/license DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Derek Finlinson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.