dataverse-utils 2.0.10 → 2.0.11
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.
- package/lib/assemblyDeploy.js +18 -11
- package/lib/auth.js +11 -7
- package/lib/cachePlugin.js +23 -16
- package/lib/dataverse-utils.js +17 -12
- package/lib/dataverse.service.js +16 -10
- package/lib/deploy.js +24 -18
- package/lib/generate.js +28 -22
- package/lib/models/pluginAssembly.js +27 -20
- package/lib/models/pluginImage.js +12 -8
- package/lib/models/pluginStep.js +20 -16
- package/lib/models/pluginType.js +14 -10
- package/lib/models/webResource.js +26 -19
- package/lib/webResourceDeploy.js +18 -11
- package/package.json +3 -3
package/lib/assemblyDeploy.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.deployAssembly = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const pluginAssembly_1 = require("./models/pluginAssembly");
|
|
10
|
+
const just_scripts_utils_1 = require("just-scripts-utils");
|
|
11
|
+
async function deployAssembly(creds, apiConfig) {
|
|
6
12
|
const currentPath = '.';
|
|
7
|
-
const configFile =
|
|
13
|
+
const configFile = fs_1.default.readFileSync(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
8
14
|
if (configFile == null) {
|
|
9
|
-
logger.warn('unable to find dataverse.config.json file');
|
|
15
|
+
just_scripts_utils_1.logger.warn('unable to find dataverse.config.json file');
|
|
10
16
|
return;
|
|
11
17
|
}
|
|
12
18
|
const config = JSON.parse(configFile);
|
|
13
|
-
logger.info('deploy assembly');
|
|
19
|
+
just_scripts_utils_1.logger.info('deploy assembly');
|
|
14
20
|
try {
|
|
15
|
-
await deploy(config, apiConfig, creds.solution);
|
|
21
|
+
await (0, pluginAssembly_1.deploy)(config, apiConfig, creds.solution);
|
|
16
22
|
}
|
|
17
23
|
catch (error) {
|
|
18
|
-
logger.error(error.message);
|
|
24
|
+
just_scripts_utils_1.logger.error(error.message);
|
|
19
25
|
return;
|
|
20
26
|
}
|
|
21
|
-
logger.info(`deployed assembly ${config.name}\r\n`);
|
|
27
|
+
just_scripts_utils_1.logger.info(`deployed assembly ${config.name}\r\n`);
|
|
22
28
|
}
|
|
29
|
+
exports.deployAssembly = deployAssembly;
|
package/lib/auth.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAccessToken = void 0;
|
|
4
|
+
const cachePlugin_1 = require("./cachePlugin");
|
|
5
|
+
const msal_node_1 = require("@azure/msal-node");
|
|
6
|
+
const just_scripts_utils_1 = require("just-scripts-utils");
|
|
4
7
|
const clientId = '51f81489-12ee-4a9e-aaae-a2591f45987d';
|
|
5
|
-
|
|
8
|
+
const getAccessToken = async (tenant, url) => {
|
|
6
9
|
const config = {
|
|
7
10
|
auth: {
|
|
8
11
|
clientId: clientId,
|
|
9
12
|
authority: `https://login.microsoftonline.com/${tenant}/`
|
|
10
13
|
},
|
|
11
14
|
cache: {
|
|
12
|
-
cachePlugin: cachePlugin(url.replace('https://', '').split('.')[0])
|
|
15
|
+
cachePlugin: (0, cachePlugin_1.cachePlugin)(url.replace('https://', '').split('.')[0])
|
|
13
16
|
}
|
|
14
17
|
};
|
|
15
|
-
const pca = new PublicClientApplication(config);
|
|
18
|
+
const pca = new msal_node_1.PublicClientApplication(config);
|
|
16
19
|
const cache = pca.getTokenCache();
|
|
17
20
|
const accounts = await cache?.getAllAccounts().catch(ex => {
|
|
18
21
|
throw new Error(ex.message);
|
|
@@ -32,9 +35,10 @@ export const getAccessToken = async (tenant, url) => {
|
|
|
32
35
|
// Acquire token by device code
|
|
33
36
|
const token = await pca.acquireTokenByDeviceCode({
|
|
34
37
|
scopes: [`${url}/.default`],
|
|
35
|
-
deviceCodeCallback: (response) => logger.info(response.message)
|
|
38
|
+
deviceCodeCallback: (response) => just_scripts_utils_1.logger.info(response.message)
|
|
36
39
|
}).catch(ex => {
|
|
37
40
|
throw new Error(ex.message);
|
|
38
41
|
});
|
|
39
42
|
return token;
|
|
40
43
|
};
|
|
44
|
+
exports.getAccessToken = getAccessToken;
|
package/lib/cachePlugin.js
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.cachePlugin = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const cryptr_1 = __importDefault(require("cryptr"));
|
|
5
11
|
const encrypt = (text) => {
|
|
6
|
-
const user =
|
|
7
|
-
const cryptr = new
|
|
12
|
+
const user = os_1.default.userInfo().username;
|
|
13
|
+
const cryptr = new cryptr_1.default(user);
|
|
8
14
|
const encrypted = cryptr.encrypt(text);
|
|
9
15
|
return encrypted;
|
|
10
16
|
};
|
|
11
17
|
const decrypt = (text) => {
|
|
12
|
-
const user =
|
|
13
|
-
const cryptr = new
|
|
18
|
+
const user = os_1.default.userInfo().username;
|
|
19
|
+
const cryptr = new cryptr_1.default(user);
|
|
14
20
|
const decrypted = cryptr.decrypt(text);
|
|
15
21
|
return decrypted;
|
|
16
22
|
};
|
|
17
|
-
|
|
23
|
+
function cachePlugin(org) {
|
|
18
24
|
const getCachePath = () => {
|
|
19
|
-
if (!
|
|
20
|
-
|
|
25
|
+
if (!fs_1.default.existsSync(path_1.default.join(os_1.default.homedir(), './.dataverse-utils/'))) {
|
|
26
|
+
fs_1.default.mkdirSync(path_1.default.join(os_1.default.homedir(), './.dataverse-utils/'));
|
|
21
27
|
}
|
|
22
|
-
return
|
|
28
|
+
return path_1.default.join(os_1.default.homedir(), `./.dataverse-utils/${org}.json`);
|
|
23
29
|
};
|
|
24
30
|
const cacheLocation = getCachePath();
|
|
25
31
|
const beforeCacheAccess = (tokenCacheContext) => {
|
|
26
32
|
return new Promise((resolve, reject) => {
|
|
27
|
-
if (
|
|
28
|
-
|
|
33
|
+
if (fs_1.default.existsSync(cacheLocation)) {
|
|
34
|
+
fs_1.default.readFile(cacheLocation, 'utf-8', (err, data) => {
|
|
29
35
|
if (err) {
|
|
30
36
|
reject();
|
|
31
37
|
}
|
|
@@ -38,7 +44,7 @@ export function cachePlugin(org) {
|
|
|
38
44
|
}
|
|
39
45
|
else {
|
|
40
46
|
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
41
|
-
|
|
47
|
+
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
42
48
|
if (err) {
|
|
43
49
|
reject();
|
|
44
50
|
}
|
|
@@ -53,7 +59,7 @@ export function cachePlugin(org) {
|
|
|
53
59
|
return new Promise((resolve, reject) => {
|
|
54
60
|
if (tokenCacheContext.cacheHasChanged) {
|
|
55
61
|
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
56
|
-
|
|
62
|
+
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
57
63
|
if (err) {
|
|
58
64
|
reject(err);
|
|
59
65
|
}
|
|
@@ -70,3 +76,4 @@ export function cachePlugin(org) {
|
|
|
70
76
|
afterCacheAccess
|
|
71
77
|
};
|
|
72
78
|
}
|
|
79
|
+
exports.cachePlugin = cachePlugin;
|
package/lib/dataverse-utils.js
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const deploy_1 = __importDefault(require("./deploy"));
|
|
9
|
+
const generate_1 = __importDefault(require("./generate"));
|
|
10
|
+
commander_1.program
|
|
6
11
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
7
12
|
.version(require('../package').version)
|
|
8
13
|
.usage('<command> [options]');
|
|
9
14
|
// Deploy command
|
|
10
|
-
program
|
|
15
|
+
commander_1.program
|
|
11
16
|
.command('deploy')
|
|
12
17
|
.description('Deploy file(s) to dataverse (webresource, plugin, workflow)')
|
|
13
18
|
.argument('[type]', 'Type of project to deploy')
|
|
14
19
|
.argument('[files]', 'Comma separate list of files to deploy')
|
|
15
20
|
.action((type, files) => {
|
|
16
|
-
|
|
21
|
+
(0, deploy_1.default)(type, files);
|
|
17
22
|
});
|
|
18
23
|
// Generate command
|
|
19
|
-
program
|
|
24
|
+
commander_1.program
|
|
20
25
|
.command('generate')
|
|
21
26
|
.description('Generate early-bound TypeScript file for specified table')
|
|
22
27
|
.argument('[table]', 'Table to generate')
|
|
23
28
|
.action((table) => {
|
|
24
|
-
|
|
29
|
+
(0, generate_1.default)(table);
|
|
25
30
|
});
|
|
26
31
|
// Show help on unknown command
|
|
27
|
-
program
|
|
32
|
+
commander_1.program
|
|
28
33
|
.arguments('<command>')
|
|
29
34
|
.action((cmd) => {
|
|
30
|
-
program.outputHelp();
|
|
35
|
+
commander_1.program.outputHelp();
|
|
31
36
|
console.log();
|
|
32
37
|
console.log(`Unknown command ${cmd}.`);
|
|
33
38
|
console.log();
|
|
34
39
|
});
|
|
35
|
-
program.parse(process.argv);
|
|
40
|
+
commander_1.program.parse(process.argv);
|
|
36
41
|
if (!process.argv.slice(2).length) {
|
|
37
|
-
program.outputHelp();
|
|
42
|
+
commander_1.program.outputHelp();
|
|
38
43
|
}
|
package/lib/dataverse.service.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTableMetadata = exports.publish = exports.addToSolution = exports.ComponentType = void 0;
|
|
4
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
+
var ComponentType;
|
|
3
6
|
(function (ComponentType) {
|
|
4
7
|
ComponentType[ComponentType["WebResource"] = 61] = "WebResource";
|
|
5
8
|
ComponentType[ComponentType["PluginType"] = 90] = "PluginType";
|
|
6
9
|
ComponentType[ComponentType["PluginAssembly"] = 91] = "PluginAssembly";
|
|
7
10
|
ComponentType[ComponentType["SDKMessageProcessingStep"] = 92] = "SDKMessageProcessingStep";
|
|
8
11
|
ComponentType[ComponentType["SDKMessageProcessingStepImage"] = 93] = "SDKMessageProcessingStepImage";
|
|
9
|
-
})(ComponentType || (ComponentType = {}));
|
|
10
|
-
|
|
12
|
+
})(ComponentType = exports.ComponentType || (exports.ComponentType = {}));
|
|
13
|
+
async function addToSolution(id, solution, type, apiConfig) {
|
|
11
14
|
const data = {
|
|
12
15
|
ComponentId: id,
|
|
13
16
|
ComponentType: type,
|
|
@@ -15,20 +18,22 @@ export async function addToSolution(id, solution, type, apiConfig) {
|
|
|
15
18
|
AddRequiredComponents: false,
|
|
16
19
|
IncludedComponentSettingsValues: null
|
|
17
20
|
};
|
|
18
|
-
await unboundAction(apiConfig, 'AddSolutionComponent', data);
|
|
21
|
+
await (0, node_1.unboundAction)(apiConfig, 'AddSolutionComponent', data);
|
|
19
22
|
}
|
|
20
|
-
|
|
23
|
+
exports.addToSolution = addToSolution;
|
|
24
|
+
async function publish(publishXml, apiConfig) {
|
|
21
25
|
const data = {
|
|
22
26
|
ParameterXml: `<importexportxml><webresources>${publishXml}</webresources></importexportxml>`
|
|
23
27
|
};
|
|
24
|
-
await unboundAction(apiConfig, 'PublishXml', data);
|
|
28
|
+
await (0, node_1.unboundAction)(apiConfig, 'PublishXml', data);
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
exports.publish = publish;
|
|
31
|
+
async function getTableMetadata(table, apiConfig) {
|
|
27
32
|
const options = [
|
|
28
33
|
'?$select=DisplayName,LogicalName,EntitySetName,SchemaName',
|
|
29
34
|
'&$expand=Attributes($select=LogicalName,SchemaName)'
|
|
30
35
|
].join('');
|
|
31
|
-
const metadata = await retrieveMultiple(apiConfig, `EntityDefinitions(LogicalName='${table}')`, options);
|
|
36
|
+
const metadata = await (0, node_1.retrieveMultiple)(apiConfig, `EntityDefinitions(LogicalName='${table}')`, options);
|
|
32
37
|
if (metadata == null) {
|
|
33
38
|
throw Error(`Table ${table} not found in metadata cache`);
|
|
34
39
|
}
|
|
@@ -36,7 +41,7 @@ export async function getTableMetadata(table, apiConfig) {
|
|
|
36
41
|
'?$select=attributevalue,value,attributename',
|
|
37
42
|
`&$filter=objecttypecode eq '${table}'`
|
|
38
43
|
].join('');
|
|
39
|
-
const choiceMetadata = await retrieveMultiple(apiConfig, 'stringmaps', choiceOptions);
|
|
44
|
+
const choiceMetadata = await (0, node_1.retrieveMultiple)(apiConfig, 'stringmaps', choiceOptions);
|
|
40
45
|
const tableMetadata = {
|
|
41
46
|
logicalName: metadata.LogicalName,
|
|
42
47
|
schemaName: metadata.SchemaName,
|
|
@@ -60,3 +65,4 @@ export async function getTableMetadata(table, apiConfig) {
|
|
|
60
65
|
});
|
|
61
66
|
return tableMetadata;
|
|
62
67
|
}
|
|
68
|
+
exports.getTableMetadata = getTableMetadata;
|
package/lib/deploy.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const just_scripts_utils_1 = require("just-scripts-utils");
|
|
10
|
+
const assemblyDeploy_1 = require("./assemblyDeploy");
|
|
11
|
+
const webResourceDeploy_1 = require("./webResourceDeploy");
|
|
12
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
13
|
+
const auth_1 = require("./auth");
|
|
14
|
+
async function deploy(type, files) {
|
|
10
15
|
if (!type || (type !== 'webresource' && type !== 'assembly')) {
|
|
11
16
|
const invalid = type !== undefined && type !== 'webresource' && type !== 'assembly';
|
|
12
17
|
const invalidMessage = invalid ? `${type} is not a valid project type.` : '';
|
|
13
|
-
const { typePrompt } = await
|
|
18
|
+
const { typePrompt } = await (0, prompts_1.default)({
|
|
14
19
|
type: 'select',
|
|
15
20
|
name: 'typePrompt',
|
|
16
21
|
message: `${invalidMessage} select project type to deploy`,
|
|
@@ -22,33 +27,34 @@ export default async function deploy(type, files) {
|
|
|
22
27
|
type = typePrompt;
|
|
23
28
|
}
|
|
24
29
|
const currentPath = '.';
|
|
25
|
-
const credsFile =
|
|
30
|
+
const credsFile = fs_1.default.readFileSync(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
26
31
|
if (credsFile == null) {
|
|
27
|
-
logger.warn('unable to find dataverse.config.json file');
|
|
32
|
+
just_scripts_utils_1.logger.warn('unable to find dataverse.config.json file');
|
|
28
33
|
return;
|
|
29
34
|
}
|
|
30
35
|
const creds = JSON.parse(credsFile).connection;
|
|
31
36
|
let token = null;
|
|
32
37
|
try {
|
|
33
|
-
token = await getAccessToken(creds.tenant, creds.server);
|
|
38
|
+
token = await (0, auth_1.getAccessToken)(creds.tenant, creds.server);
|
|
34
39
|
}
|
|
35
40
|
catch (error) {
|
|
36
|
-
logger.error(`failed to acquire access token: ${error.message}`);
|
|
41
|
+
just_scripts_utils_1.logger.error(`failed to acquire access token: ${error.message}`);
|
|
37
42
|
return;
|
|
38
43
|
}
|
|
39
44
|
if (token == null || token.accessToken == null) {
|
|
40
|
-
logger.error('failed to acquire access token');
|
|
45
|
+
just_scripts_utils_1.logger.error('failed to acquire access token');
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
|
-
const apiConfig = new WebApiConfig('8.2', token.accessToken, creds.server);
|
|
48
|
+
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
|
44
49
|
switch (type) {
|
|
45
50
|
case 'webresource':
|
|
46
|
-
await deployWebResource(creds, apiConfig, files);
|
|
51
|
+
await (0, webResourceDeploy_1.deployWebResource)(creds, apiConfig, files);
|
|
47
52
|
break;
|
|
48
53
|
case 'assembly':
|
|
49
|
-
await deployAssembly(creds, apiConfig);
|
|
54
|
+
await (0, assemblyDeploy_1.deployAssembly)(creds, apiConfig);
|
|
50
55
|
break;
|
|
51
56
|
default:
|
|
52
57
|
break;
|
|
53
58
|
}
|
|
54
59
|
}
|
|
60
|
+
exports.default = deploy;
|
package/lib/generate.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const just_scripts_utils_1 = require("just-scripts-utils");
|
|
10
|
+
const dataverse_service_1 = require("./dataverse.service");
|
|
11
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
12
|
+
const auth_1 = require("./auth");
|
|
13
|
+
async function generate(table) {
|
|
9
14
|
while (!table) {
|
|
10
|
-
const { tablePrompt } = await
|
|
15
|
+
const { tablePrompt } = await (0, prompts_1.default)({
|
|
11
16
|
type: 'text',
|
|
12
17
|
name: 'tablePrompt',
|
|
13
18
|
message: `enter table to generate`
|
|
@@ -15,32 +20,32 @@ export default async function generate(table) {
|
|
|
15
20
|
table = tablePrompt;
|
|
16
21
|
}
|
|
17
22
|
const currentPath = '.';
|
|
18
|
-
const credsFile =
|
|
23
|
+
const credsFile = fs_1.default.readFileSync(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
19
24
|
if (credsFile == null) {
|
|
20
|
-
logger.warn('unable to find dataverse.config.json file');
|
|
25
|
+
just_scripts_utils_1.logger.warn('unable to find dataverse.config.json file');
|
|
21
26
|
return;
|
|
22
27
|
}
|
|
23
28
|
const creds = JSON.parse(credsFile).connection;
|
|
24
29
|
let token = null;
|
|
25
30
|
try {
|
|
26
|
-
token = await getAccessToken(creds.tenant, creds.server);
|
|
31
|
+
token = await (0, auth_1.getAccessToken)(creds.tenant, creds.server);
|
|
27
32
|
}
|
|
28
33
|
catch (error) {
|
|
29
|
-
logger.error(`failed to acquire access token: ${error.message}`);
|
|
34
|
+
just_scripts_utils_1.logger.error(`failed to acquire access token: ${error.message}`);
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
37
|
if (token == null || token.accessToken == null) {
|
|
33
|
-
logger.error('failed to acquire access token');
|
|
38
|
+
just_scripts_utils_1.logger.error('failed to acquire access token');
|
|
34
39
|
return;
|
|
35
40
|
}
|
|
36
|
-
const apiConfig = new WebApiConfig('8.2', token.accessToken, creds.server);
|
|
41
|
+
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
|
37
42
|
let metadata = {};
|
|
38
|
-
logger.info('Retrieve table metadata');
|
|
43
|
+
just_scripts_utils_1.logger.info('Retrieve table metadata');
|
|
39
44
|
try {
|
|
40
|
-
metadata = await getTableMetadata(table, apiConfig);
|
|
45
|
+
metadata = await (0, dataverse_service_1.getTableMetadata)(table, apiConfig);
|
|
41
46
|
}
|
|
42
47
|
catch (error) {
|
|
43
|
-
logger.error(error.message);
|
|
48
|
+
just_scripts_utils_1.logger.error(error.message);
|
|
44
49
|
return;
|
|
45
50
|
}
|
|
46
51
|
// Build code file from metadata
|
|
@@ -85,9 +90,10 @@ export default async function generate(table) {
|
|
|
85
90
|
'\r\n',
|
|
86
91
|
`export default new ${metadata.schemaName}();`
|
|
87
92
|
].join('');
|
|
88
|
-
if (!
|
|
89
|
-
|
|
93
|
+
if (!fs_1.default.existsSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models'))) {
|
|
94
|
+
fs_1.default.mkdirSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models'));
|
|
90
95
|
}
|
|
91
|
-
|
|
92
|
-
logger.info(`Table metadata output to models/${metadata.schemaName}.ts`);
|
|
96
|
+
fs_1.default.writeFileSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models', `${metadata.schemaName}.ts`), codeFile);
|
|
97
|
+
just_scripts_utils_1.logger.info(`Table metadata output to models/${metadata.schemaName}.ts`);
|
|
93
98
|
}
|
|
99
|
+
exports.default = generate;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 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 dataverse_service_1 = require("../dataverse.service");
|
|
12
|
+
const just_scripts_utils_1 = require("just-scripts-utils");
|
|
13
|
+
async function deploy(config, apiConfig, solution) {
|
|
14
|
+
const files = glob_1.default.sync(`**/${config.name}.dll`);
|
|
9
15
|
if (files.length === 0) {
|
|
10
|
-
logger.error(`assembly ${config.name}.dll not found`);
|
|
16
|
+
just_scripts_utils_1.logger.error(`assembly ${config.name}.dll not found`);
|
|
11
17
|
return;
|
|
12
18
|
}
|
|
13
|
-
const content =
|
|
19
|
+
const content = fs_1.default.readFileSync(files[0]).toString('base64');
|
|
14
20
|
let assemblyId = '';
|
|
15
21
|
try {
|
|
16
22
|
assemblyId = await retrieveAssembly(config.name, apiConfig);
|
|
17
23
|
}
|
|
18
24
|
catch (error) {
|
|
19
|
-
logger.error(`failed to retrieve assembly ${config.name}: ${error.message}`);
|
|
25
|
+
just_scripts_utils_1.logger.error(`failed to retrieve assembly ${config.name}: ${error.message}`);
|
|
20
26
|
return;
|
|
21
27
|
}
|
|
22
28
|
if (assemblyId != '') {
|
|
@@ -36,10 +42,10 @@ export async function deploy(config, apiConfig, solution) {
|
|
|
36
42
|
}
|
|
37
43
|
if (solution != undefined) {
|
|
38
44
|
try {
|
|
39
|
-
await addToSolution(assemblyId, solution, ComponentType.PluginAssembly, apiConfig);
|
|
45
|
+
await (0, dataverse_service_1.addToSolution)(assemblyId, solution, dataverse_service_1.ComponentType.PluginAssembly, apiConfig);
|
|
40
46
|
}
|
|
41
47
|
catch (error) {
|
|
42
|
-
logger.error(`failed to add to solution: ${error.message}`);
|
|
48
|
+
just_scripts_utils_1.logger.error(`failed to add to solution: ${error.message}`);
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
}
|
|
@@ -47,23 +53,24 @@ export async function deploy(config, apiConfig, solution) {
|
|
|
47
53
|
try {
|
|
48
54
|
const promises = config.types.map(async (type) => {
|
|
49
55
|
type['pluginassemblyid@odata.bind'] = `/pluginassemblies(${assemblyId})`;
|
|
50
|
-
await deployType(type, apiConfig, solution);
|
|
56
|
+
await (0, pluginType_1.deployType)(type, apiConfig, solution);
|
|
51
57
|
});
|
|
52
58
|
await Promise.all(promises);
|
|
53
59
|
}
|
|
54
60
|
catch (error) {
|
|
55
|
-
logger.error(error.message);
|
|
61
|
+
just_scripts_utils_1.logger.error(error.message);
|
|
56
62
|
return;
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
}
|
|
66
|
+
exports.deploy = deploy;
|
|
60
67
|
async function retrieveAssembly(name, apiConfig) {
|
|
61
68
|
const options = `$select=pluginassemblyid&$filter=name eq '${name}'`;
|
|
62
|
-
const result = await retrieveMultiple(apiConfig, 'pluginassemblies', options);
|
|
69
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
|
|
63
70
|
return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
|
|
64
71
|
}
|
|
65
72
|
async function createAssembly(config, content, apiConfig) {
|
|
66
|
-
logger.info(`create assembly ${config.name}`);
|
|
73
|
+
just_scripts_utils_1.logger.info(`create assembly ${config.name}`);
|
|
67
74
|
const assembly = {
|
|
68
75
|
name: config.name,
|
|
69
76
|
content: content,
|
|
@@ -73,17 +80,17 @@ async function createAssembly(config, content, apiConfig) {
|
|
|
73
80
|
sourcetype: 0,
|
|
74
81
|
culture: ''
|
|
75
82
|
};
|
|
76
|
-
const result = await createWithReturnData(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid');
|
|
83
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid');
|
|
77
84
|
if (result.error) {
|
|
78
85
|
throw new Error(result.error.message);
|
|
79
86
|
}
|
|
80
87
|
return result.pluginassemblyid;
|
|
81
88
|
}
|
|
82
89
|
async function updateAssembly(id, config, content, apiConfig) {
|
|
83
|
-
logger.info(`update assembly ${config.name}`);
|
|
90
|
+
just_scripts_utils_1.logger.info(`update assembly ${config.name}`);
|
|
84
91
|
const assembly = {
|
|
85
92
|
content: content,
|
|
86
93
|
version: config.version
|
|
87
94
|
};
|
|
88
|
-
return update(apiConfig, 'pluginassemblies', id, assembly);
|
|
95
|
+
return (0, node_1.update)(apiConfig, 'pluginassemblies', id, assembly);
|
|
89
96
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deployImage = void 0;
|
|
4
|
+
const just_scripts_utils_1 = require("just-scripts-utils");
|
|
5
|
+
const node_1 = require("dataverse-webapi/lib/node");
|
|
6
|
+
async function deployImage(stepId, image, message, apiConfig) {
|
|
4
7
|
image['sdkmessageprocessingstepid@odata.bind'] = `/sdkmessageprocessingsteps(${stepId})`;
|
|
5
8
|
switch (message) {
|
|
6
9
|
case 'Create':
|
|
@@ -38,20 +41,21 @@ export async function deployImage(stepId, image, message, apiConfig) {
|
|
|
38
41
|
}
|
|
39
42
|
return imageId;
|
|
40
43
|
}
|
|
44
|
+
exports.deployImage = deployImage;
|
|
41
45
|
async function retrieveImage(stepId, image, apiConfig) {
|
|
42
46
|
const options = `$select=sdkmessageprocessingstepimageid&$filter=name eq '${image.name}' and _sdkmessageprocessingstepid_value eq ${stepId}`;
|
|
43
|
-
const result = await retrieveMultiple(apiConfig, 'sdkmessageprocessingstepimages', options);
|
|
47
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingstepimages', options);
|
|
44
48
|
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepimageid : '';
|
|
45
49
|
}
|
|
46
50
|
async function createImage(image, apiConfig) {
|
|
47
|
-
logger.info(`create plugin image ${image.name}`);
|
|
48
|
-
const result = await createWithReturnData(apiConfig, 'sdkmessageprocessingstepimages', image, '$select=sdkmessageprocessingstepimageid');
|
|
51
|
+
just_scripts_utils_1.logger.info(`create plugin image ${image.name}`);
|
|
52
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingstepimages', image, '$select=sdkmessageprocessingstepimageid');
|
|
49
53
|
if (result.error) {
|
|
50
54
|
throw new Error(result.error.message);
|
|
51
55
|
}
|
|
52
56
|
return result.sdkmessageprocessingstepimageid;
|
|
53
57
|
}
|
|
54
58
|
async function updateImage(id, image, apiConfig) {
|
|
55
|
-
logger.info(`update plugin image ${image.name}`);
|
|
56
|
-
return update(apiConfig, 'sdkmessageprocessingstepimages', id, image);
|
|
59
|
+
just_scripts_utils_1.logger.info(`update plugin image ${image.name}`);
|
|
60
|
+
return (0, node_1.update)(apiConfig, 'sdkmessageprocessingstepimages', id, image);
|
|
57
61
|
}
|
package/lib/models/pluginStep.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 just_scripts_utils_1 = require("just-scripts-utils");
|
|
7
|
+
const pluginImage_1 = require("./pluginImage");
|
|
8
|
+
async function deployStep(step, apiConfig, solution) {
|
|
6
9
|
let stepId = await retrieveStep(step.name, apiConfig);
|
|
7
10
|
const messageId = await getSdkMessageId(step.message ?? '', apiConfig);
|
|
8
11
|
if (messageId == '') {
|
|
9
|
-
logger.error(`sdk message ${step.message} not found`);
|
|
12
|
+
just_scripts_utils_1.logger.error(`sdk message ${step.message} not found`);
|
|
10
13
|
return;
|
|
11
14
|
}
|
|
12
15
|
const filterId = await getSdkMessageFilterId(messageId, step.entity ?? '', apiConfig);
|
|
13
16
|
if (filterId == '') {
|
|
14
|
-
logger.error(`sdk message ${step.message} for entity ${step.entity} not found`);
|
|
17
|
+
just_scripts_utils_1.logger.error(`sdk message ${step.message} for entity ${step.entity} not found`);
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
17
20
|
step['sdkmessagefilterid@odata.bind'] = `/sdkmessagefilters(${filterId})`;
|
|
@@ -41,7 +44,7 @@ export async function deployStep(step, apiConfig, solution) {
|
|
|
41
44
|
}
|
|
42
45
|
if (solution != undefined) {
|
|
43
46
|
try {
|
|
44
|
-
await addToSolution(stepId, solution, ComponentType.SDKMessageProcessingStep, apiConfig);
|
|
47
|
+
await (0, dataverse_service_1.addToSolution)(stepId, solution, dataverse_service_1.ComponentType.SDKMessageProcessingStep, apiConfig);
|
|
45
48
|
}
|
|
46
49
|
catch (error) {
|
|
47
50
|
throw new Error(`failed to add to solution: ${error.message}`);
|
|
@@ -50,7 +53,7 @@ export async function deployStep(step, apiConfig, solution) {
|
|
|
50
53
|
}
|
|
51
54
|
if (images && images.length > 0) {
|
|
52
55
|
try {
|
|
53
|
-
const promises = images.map(image => deployImage(stepId, image, message, apiConfig));
|
|
56
|
+
const promises = images.map(image => (0, pluginImage_1.deployImage)(stepId, image, message, apiConfig));
|
|
54
57
|
await Promise.all(promises);
|
|
55
58
|
}
|
|
56
59
|
catch (error) {
|
|
@@ -59,9 +62,10 @@ export async function deployStep(step, apiConfig, solution) {
|
|
|
59
62
|
}
|
|
60
63
|
return stepId;
|
|
61
64
|
}
|
|
65
|
+
exports.deployStep = deployStep;
|
|
62
66
|
async function retrieveStep(name, apiConfig) {
|
|
63
67
|
const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}'`;
|
|
64
|
-
const result = await retrieveMultiple(apiConfig, 'sdkmessageprocessingsteps', options);
|
|
68
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
|
|
65
69
|
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
|
|
66
70
|
}
|
|
67
71
|
async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
|
|
@@ -69,7 +73,7 @@ async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
|
|
|
69
73
|
`?$filter=primaryobjecttypecode eq '${entityName}' and _sdkmessageid_value eq ${messageId}`,
|
|
70
74
|
'&$select=sdkmessagefilterid'
|
|
71
75
|
].join('');
|
|
72
|
-
const message = await retrieveMultiple(apiConfig, 'sdkmessagefilters', options);
|
|
76
|
+
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessagefilters', options);
|
|
73
77
|
return message.value.length > 0 ? message.value[0].sdkmessagefilterid : '';
|
|
74
78
|
}
|
|
75
79
|
async function getSdkMessageId(name, apiConfig) {
|
|
@@ -77,18 +81,18 @@ async function getSdkMessageId(name, apiConfig) {
|
|
|
77
81
|
`?$filter=name eq '${name}'`,
|
|
78
82
|
'&$select=sdkmessageid'
|
|
79
83
|
].join('');
|
|
80
|
-
const message = await retrieveMultiple(apiConfig, 'sdkmessages', options);
|
|
84
|
+
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
|
|
81
85
|
return message.value.length > 0 ? message.value[0].sdkmessageid : '';
|
|
82
86
|
}
|
|
83
87
|
async function createStep(step, apiConfig) {
|
|
84
|
-
logger.info(`create plugin step ${step.name}`);
|
|
85
|
-
const result = await createWithReturnData(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid');
|
|
88
|
+
just_scripts_utils_1.logger.info(`create plugin step ${step.name}`);
|
|
89
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid');
|
|
86
90
|
if (result.error) {
|
|
87
91
|
throw new Error(result.error.message);
|
|
88
92
|
}
|
|
89
93
|
return result.sdkmessageprocessingstepid;
|
|
90
94
|
}
|
|
91
95
|
async function updateStep(id, step, apiConfig) {
|
|
92
|
-
logger.info(`update plugin step ${step.name}`);
|
|
93
|
-
return update(apiConfig, 'sdkmessageprocessingsteps', id, step);
|
|
96
|
+
just_scripts_utils_1.logger.info(`update plugin step ${step.name}`);
|
|
97
|
+
return (0, node_1.update)(apiConfig, 'sdkmessageprocessingsteps', id, step);
|
|
94
98
|
}
|
package/lib/models/pluginType.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 just_scripts_utils_1 = require("just-scripts-utils");
|
|
7
|
+
async function deployType(type, apiConfig, solution) {
|
|
5
8
|
let typeId = await retrieveType(type.typename, apiConfig);
|
|
6
9
|
const record = {
|
|
7
10
|
name: type.name,
|
|
@@ -30,7 +33,7 @@ export async function deployType(type, apiConfig, solution) {
|
|
|
30
33
|
if (type.steps) {
|
|
31
34
|
const promises = type.steps.map(async (step) => {
|
|
32
35
|
step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
|
|
33
|
-
await deployStep(step, apiConfig, solution);
|
|
36
|
+
await (0, pluginStep_1.deployStep)(step, apiConfig, solution);
|
|
34
37
|
});
|
|
35
38
|
await Promise.all(promises);
|
|
36
39
|
}
|
|
@@ -40,20 +43,21 @@ export async function deployType(type, apiConfig, solution) {
|
|
|
40
43
|
}
|
|
41
44
|
return typeId;
|
|
42
45
|
}
|
|
46
|
+
exports.deployType = deployType;
|
|
43
47
|
async function retrieveType(name, apiConfig) {
|
|
44
48
|
const options = `$select=plugintypeid&$filter=typename eq '${name}'`;
|
|
45
|
-
const result = await retrieveMultiple(apiConfig, 'plugintypes', options);
|
|
49
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'plugintypes', options);
|
|
46
50
|
return result.value.length > 0 ? result.value[0].plugintypeid : '';
|
|
47
51
|
}
|
|
48
52
|
async function createType(type, apiConfig) {
|
|
49
|
-
logger.info(`create assembly type ${type.name}`);
|
|
50
|
-
const result = await createWithReturnData(apiConfig, 'plugintypes', type, '$select=plugintypeid');
|
|
53
|
+
just_scripts_utils_1.logger.info(`create assembly type ${type.name}`);
|
|
54
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', type, '$select=plugintypeid');
|
|
51
55
|
if (result.error) {
|
|
52
56
|
throw new Error(result.error.message);
|
|
53
57
|
}
|
|
54
58
|
return result.plugintypeid;
|
|
55
59
|
}
|
|
56
60
|
async function updateType(id, type, apiConfig) {
|
|
57
|
-
logger.info(`update assembly type ${type.name}`);
|
|
58
|
-
return update(apiConfig, 'plugintypes', id, type);
|
|
61
|
+
just_scripts_utils_1.logger.info(`update assembly type ${type.name}`);
|
|
62
|
+
return (0, node_1.update)(apiConfig, 'plugintypes', id, type);
|
|
59
63
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 just_scripts_utils_1 = require("just-scripts-utils");
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
5
11
|
function getWebResourceType(type) {
|
|
6
12
|
switch (type) {
|
|
7
13
|
case 'HTML':
|
|
@@ -32,7 +38,7 @@ function getWebResourceType(type) {
|
|
|
32
38
|
return 0;
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
|
-
|
|
41
|
+
async function deploy(webResources, apiConfig, solution, files) {
|
|
36
42
|
const publishXml = [];
|
|
37
43
|
let resources = webResources;
|
|
38
44
|
// Use list of files if provided
|
|
@@ -41,7 +47,7 @@ export async function deploy(webResources, apiConfig, solution, files) {
|
|
|
41
47
|
for (const file of files.split(',')) {
|
|
42
48
|
const resource = webResources.filter(r => r.path?.endsWith(file));
|
|
43
49
|
if (resource.length === 0) {
|
|
44
|
-
logger.error(`web resource ${file} not found in dataverse.config.json`);
|
|
50
|
+
just_scripts_utils_1.logger.error(`web resource ${file} not found in dataverse.config.json`);
|
|
45
51
|
continue;
|
|
46
52
|
}
|
|
47
53
|
resources.push(resource[0]);
|
|
@@ -53,10 +59,10 @@ export async function deploy(webResources, apiConfig, solution, files) {
|
|
|
53
59
|
resourceId = await retrieveResource(resource.name, apiConfig);
|
|
54
60
|
}
|
|
55
61
|
catch (error) {
|
|
56
|
-
logger.error(`failed to retrieve resource ${resource.name}: ${error.message}`);
|
|
62
|
+
just_scripts_utils_1.logger.error(`failed to retrieve resource ${resource.name}: ${error.message}`);
|
|
57
63
|
return;
|
|
58
64
|
}
|
|
59
|
-
const fileContent =
|
|
65
|
+
const fileContent = fs_1.default.readFileSync(resource.path, 'utf8');
|
|
60
66
|
const content = Buffer.from(fileContent).toString('base64');
|
|
61
67
|
if (resourceId != '') {
|
|
62
68
|
try {
|
|
@@ -64,7 +70,7 @@ export async function deploy(webResources, apiConfig, solution, files) {
|
|
|
64
70
|
publishXml.push(updated);
|
|
65
71
|
}
|
|
66
72
|
catch (error) {
|
|
67
|
-
logger.error(`failed to update resource: ${error.message}`);
|
|
73
|
+
just_scripts_utils_1.logger.error(`failed to update resource: ${error.message}`);
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
else {
|
|
@@ -72,14 +78,14 @@ export async function deploy(webResources, apiConfig, solution, files) {
|
|
|
72
78
|
resourceId = await createResource(resource, content, apiConfig);
|
|
73
79
|
}
|
|
74
80
|
catch (error) {
|
|
75
|
-
logger.error(`failed to create resource: ${error.message}`);
|
|
81
|
+
just_scripts_utils_1.logger.error(`failed to create resource: ${error.message}`);
|
|
76
82
|
}
|
|
77
83
|
if (solution != undefined) {
|
|
78
84
|
try {
|
|
79
|
-
await addToSolution(resourceId, solution, ComponentType.WebResource, apiConfig);
|
|
85
|
+
await (0, dataverse_service_1.addToSolution)(resourceId, solution, dataverse_service_1.ComponentType.WebResource, apiConfig);
|
|
80
86
|
}
|
|
81
87
|
catch (error) {
|
|
82
|
-
logger.error(`failed to add to solution: ${error.message}`);
|
|
88
|
+
just_scripts_utils_1.logger.error(`failed to add to solution: ${error.message}`);
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
}
|
|
@@ -88,37 +94,38 @@ export async function deploy(webResources, apiConfig, solution, files) {
|
|
|
88
94
|
// publish resources
|
|
89
95
|
if (publishXml.length > 0) {
|
|
90
96
|
try {
|
|
91
|
-
await publish(publishXml.join(''), apiConfig);
|
|
97
|
+
await (0, dataverse_service_1.publish)(publishXml.join(''), apiConfig);
|
|
92
98
|
}
|
|
93
99
|
catch (error) {
|
|
94
|
-
logger.error(error.message);
|
|
100
|
+
just_scripts_utils_1.logger.error(error.message);
|
|
95
101
|
}
|
|
96
102
|
}
|
|
97
103
|
}
|
|
104
|
+
exports.deploy = deploy;
|
|
98
105
|
async function retrieveResource(name, apiConfig) {
|
|
99
106
|
const options = `$select=webresourceid&$filter=name eq '${name}'`;
|
|
100
|
-
const result = await retrieveMultiple(apiConfig, 'webresourceset', options);
|
|
107
|
+
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'webresourceset', options);
|
|
101
108
|
return result.value.length > 0 ? result.value[0].webresourceid : '';
|
|
102
109
|
}
|
|
103
110
|
async function createResource(resource, content, apiConfig) {
|
|
104
|
-
logger.info(`create web resource ${resource.name}`);
|
|
111
|
+
just_scripts_utils_1.logger.info(`create web resource ${resource.name}`);
|
|
105
112
|
const webResource = {
|
|
106
113
|
webresourcetype: getWebResourceType(resource.type),
|
|
107
114
|
name: resource.name,
|
|
108
115
|
displayname: resource.displayname || resource.name,
|
|
109
116
|
content: content
|
|
110
117
|
};
|
|
111
|
-
const result = await createWithReturnData(apiConfig, 'webresourceset', webResource, '$select=webresourceid');
|
|
118
|
+
const result = await (0, node_1.createWithReturnData)(apiConfig, 'webresourceset', webResource, '$select=webresourceid');
|
|
112
119
|
if (result.error) {
|
|
113
120
|
throw new Error(result.error.message);
|
|
114
121
|
}
|
|
115
122
|
return result.webresourceid;
|
|
116
123
|
}
|
|
117
124
|
async function updateResource(id, resource, content, apiConfig) {
|
|
118
|
-
logger.info(`update web resource ${resource.name}`);
|
|
125
|
+
just_scripts_utils_1.logger.info(`update web resource ${resource.name}`);
|
|
119
126
|
const webResource = {
|
|
120
127
|
content: content
|
|
121
128
|
};
|
|
122
|
-
await update(apiConfig, 'webresourceset', id, webResource);
|
|
129
|
+
await (0, node_1.update)(apiConfig, 'webresourceset', id, webResource);
|
|
123
130
|
return `<webresource>{${id}}</webresource>`;
|
|
124
131
|
}
|
package/lib/webResourceDeploy.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 just_scripts_utils_1 = require("just-scripts-utils");
|
|
10
|
+
const webResource_1 = require("./models/webResource");
|
|
11
|
+
async function deployWebResource(creds, apiConfig, files) {
|
|
6
12
|
const currentPath = '.';
|
|
7
|
-
const configFile =
|
|
13
|
+
const configFile = fs_1.default.readFileSync(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
8
14
|
if (configFile == null) {
|
|
9
|
-
logger.warn('unable to find dataverse.config.json file');
|
|
15
|
+
just_scripts_utils_1.logger.warn('unable to find dataverse.config.json file');
|
|
10
16
|
return;
|
|
11
17
|
}
|
|
12
18
|
const config = JSON.parse(configFile).webResources;
|
|
13
|
-
logger.info('deploy web resources');
|
|
19
|
+
just_scripts_utils_1.logger.info('deploy web resources');
|
|
14
20
|
try {
|
|
15
|
-
await deploy(config, apiConfig, creds.solution, files);
|
|
21
|
+
await (0, webResource_1.deploy)(config, apiConfig, creds.solution, files);
|
|
16
22
|
}
|
|
17
23
|
catch (error) {
|
|
18
|
-
logger.error(error.message);
|
|
24
|
+
just_scripts_utils_1.logger.error(error.message);
|
|
19
25
|
return;
|
|
20
26
|
}
|
|
21
|
-
logger.info('deployed web resources');
|
|
27
|
+
just_scripts_utils_1.logger.info('deployed web resources');
|
|
22
28
|
}
|
|
29
|
+
exports.deployWebResource = deployWebResource;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataverse-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Utilities for interacting with Dataverse environments",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@azure/msal-node": "^1.3.1",
|
|
24
|
-
"commander": "^8.
|
|
24
|
+
"commander": "^8.3.0",
|
|
25
25
|
"glob": "^7.2.0",
|
|
26
26
|
"cryptr": "^6.0.2",
|
|
27
27
|
"dataverse-webapi": "^2.0.2",
|
|
28
28
|
"envinfo": "^7.8.1",
|
|
29
29
|
"just-scripts-utils": "^1.1.4",
|
|
30
|
-
"prompts": "^2.4.
|
|
30
|
+
"prompts": "^2.4.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^16.9.1",
|