dataverse-utils 2.1.0 → 2.1.4
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/CHANGELOG.json +61 -1
- package/CHANGELOG.md +37 -5
- package/lib/auth.js +1 -1
- package/lib/cachePlugin.js +28 -10
- package/lib/deploy.js +21 -2
- package/lib/logger.js +5 -9
- package/lib/models/pluginAssembly.js +1 -1
- package/lib/models/pluginStep.js +4 -4
- package/lib/models/pluginType.js +5 -5
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,67 @@
|
|
|
2
2
|
"name": "dataverse-utils",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Fri, 28 Jan 2022 23:10:57 GMT",
|
|
6
|
+
"tag": "dataverse-utils_v2.1.4",
|
|
7
|
+
"version": "2.1.4",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "derek.finlinson@journeyteam.com",
|
|
12
|
+
"package": "dataverse-utils",
|
|
13
|
+
"commit": "fb9365e3fcd8ada0b97dfc4e86661c67332734bf",
|
|
14
|
+
"comment": "Prompt to delete cache on error"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Sun, 16 Jan 2022 23:22:22 GMT",
|
|
21
|
+
"tag": "dataverse-utils_v2.1.3",
|
|
22
|
+
"version": "2.1.3",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "derek.finlinson@journeyteam.com",
|
|
27
|
+
"package": "dataverse-utils",
|
|
28
|
+
"commit": "928a436f3d6627765a329ee4cb31d83cab714b1d",
|
|
29
|
+
"comment": "Switch symbols"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Sun, 16 Jan 2022 22:57:20 GMT",
|
|
36
|
+
"tag": "dataverse-utils_v2.1.2",
|
|
37
|
+
"version": "2.1.2",
|
|
38
|
+
"comments": {
|
|
39
|
+
"patch": [
|
|
40
|
+
{
|
|
41
|
+
"author": "derek.finlinson@journeyteam.com",
|
|
42
|
+
"package": "dataverse-utils",
|
|
43
|
+
"commit": "acf6ca4763a9d98fa7683fe517deb872f12f4c42",
|
|
44
|
+
"comment": "Fix logging for real"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Sun, 16 Jan 2022 22:41:55 GMT",
|
|
51
|
+
"tag": "dataverse-utils_v2.1.1",
|
|
52
|
+
"version": "2.1.1",
|
|
53
|
+
"comments": {
|
|
54
|
+
"patch": [
|
|
55
|
+
{
|
|
56
|
+
"author": "derek.finlinson@journeyteam.com",
|
|
57
|
+
"package": "dataverse-utils",
|
|
58
|
+
"commit": "b1658649d8258e68522e6eadd79a2bbf3a4733d8",
|
|
59
|
+
"comment": "Fix logging"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"date": "Sun, 16 Jan 2022 21:30:27 GMT",
|
|
6
66
|
"tag": "dataverse-utils_v2.1.0",
|
|
7
67
|
"version": "2.1.0",
|
|
8
68
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,49 @@
|
|
|
1
1
|
# Change Log - dataverse-utils
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 28 Jan 2022 23:10:57 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 2.1.
|
|
7
|
+
## 2.1.4
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Fri, 28 Jan 2022 23:10:57 GMT
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Patches
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- Prompt to delete cache on error (derek.finlinson@journeyteam.com)
|
|
14
14
|
|
|
15
|
+
## 2.1.3
|
|
16
|
+
|
|
17
|
+
Sun, 16 Jan 2022 23:22:22 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Switch symbols (derek.finlinson@journeyteam.com)
|
|
22
|
+
|
|
23
|
+
## 2.1.2
|
|
24
|
+
|
|
25
|
+
Sun, 16 Jan 2022 22:57:20 GMT
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Fix logging for real (derek.finlinson@journeyteam.com)
|
|
30
|
+
|
|
31
|
+
## 2.1.1
|
|
32
|
+
|
|
33
|
+
Sun, 16 Jan 2022 22:41:55 GMT
|
|
34
|
+
|
|
35
|
+
### Patches
|
|
36
|
+
|
|
37
|
+
- Fix logging (derek.finlinson@journeyteam.com)
|
|
38
|
+
|
|
39
|
+
## 2.1.0
|
|
40
|
+
|
|
41
|
+
Sun, 16 Jan 2022 21:30:27 GMT
|
|
42
|
+
|
|
43
|
+
### Minor changes
|
|
44
|
+
|
|
45
|
+
- Remove dependencies; Fix plop dependency (derek.finlinson@journeyteam.com)
|
|
46
|
+
|
|
15
47
|
## 2.0.12
|
|
16
48
|
|
|
17
49
|
Tue, 07 Dec 2021 20:03:45 GMT
|
package/lib/auth.js
CHANGED
|
@@ -12,7 +12,7 @@ const getAccessToken = async (tenant, url) => {
|
|
|
12
12
|
authority: `https://login.microsoftonline.com/${tenant}/`
|
|
13
13
|
},
|
|
14
14
|
cache: {
|
|
15
|
-
cachePlugin: (0, cachePlugin_1.cachePlugin)(url
|
|
15
|
+
cachePlugin: (0, cachePlugin_1.cachePlugin)(url)
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
const pca = new msal_node_1.PublicClientApplication(config);
|
package/lib/cachePlugin.js
CHANGED
|
@@ -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.cachePlugin = void 0;
|
|
6
|
+
exports.cachePlugin = exports.deleteCache = exports.cacheExists = exports.getCachePath = void 0;
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -20,14 +20,32 @@ const decrypt = (text) => {
|
|
|
20
20
|
const decrypted = cryptr.decrypt(text);
|
|
21
21
|
return decrypted;
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const getCachePath = (url) => {
|
|
24
|
+
const org = url.replace('https://', '').split('.')[0];
|
|
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/'));
|
|
27
|
+
}
|
|
28
|
+
return path_1.default.join(os_1.default.homedir(), `./.dataverse-utils/${org}.json`);
|
|
29
|
+
};
|
|
30
|
+
exports.getCachePath = getCachePath;
|
|
31
|
+
const cacheExists = (url) => {
|
|
32
|
+
const cacheLocation = (0, exports.getCachePath)(url);
|
|
33
|
+
return fs_1.default.existsSync(cacheLocation);
|
|
34
|
+
};
|
|
35
|
+
exports.cacheExists = cacheExists;
|
|
36
|
+
const deleteCache = (url) => {
|
|
37
|
+
const cacheLocation = (0, exports.getCachePath)(url);
|
|
38
|
+
if (fs_1.default.existsSync(cacheLocation)) {
|
|
39
|
+
fs_1.default.unlinkSync(cacheLocation);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.deleteCache = deleteCache;
|
|
47
|
+
const cachePlugin = (url) => {
|
|
48
|
+
const cacheLocation = (0, exports.getCachePath)(url);
|
|
31
49
|
const beforeCacheAccess = (tokenCacheContext) => {
|
|
32
50
|
return new Promise((resolve, reject) => {
|
|
33
51
|
if (fs_1.default.existsSync(cacheLocation)) {
|
|
@@ -75,5 +93,5 @@ function cachePlugin(org) {
|
|
|
75
93
|
beforeCacheAccess,
|
|
76
94
|
afterCacheAccess
|
|
77
95
|
};
|
|
78
|
-
}
|
|
96
|
+
};
|
|
79
97
|
exports.cachePlugin = cachePlugin;
|
package/lib/deploy.js
CHANGED
|
@@ -11,6 +11,25 @@ const assemblyDeploy_1 = require("./assemblyDeploy");
|
|
|
11
11
|
const webResourceDeploy_1 = require("./webResourceDeploy");
|
|
12
12
|
const node_1 = require("dataverse-webapi/lib/node");
|
|
13
13
|
const auth_1 = require("./auth");
|
|
14
|
+
const cachePlugin_1 = require("./cachePlugin");
|
|
15
|
+
const onTokenFailure = async (url, error) => {
|
|
16
|
+
if (error) {
|
|
17
|
+
logger_1.logger.error(`failed to acquire access token: ${error}`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
logger_1.logger.error('failed to acquire access token');
|
|
21
|
+
}
|
|
22
|
+
if ((0, cachePlugin_1.cacheExists)(url)) {
|
|
23
|
+
const { deleteToken } = await (0, prompts_1.default)({
|
|
24
|
+
type: 'confirm',
|
|
25
|
+
name: 'deleteToken',
|
|
26
|
+
message: `delete current token cache for ${url}?`
|
|
27
|
+
});
|
|
28
|
+
if (deleteToken) {
|
|
29
|
+
(0, cachePlugin_1.deleteCache)(url);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
14
33
|
async function deploy(type, files) {
|
|
15
34
|
if (!type || (type !== 'webresource' && type !== 'assembly')) {
|
|
16
35
|
const invalid = type !== undefined && type !== 'webresource' && type !== 'assembly';
|
|
@@ -38,11 +57,11 @@ async function deploy(type, files) {
|
|
|
38
57
|
token = await (0, auth_1.getAccessToken)(creds.tenant, creds.server);
|
|
39
58
|
}
|
|
40
59
|
catch (error) {
|
|
41
|
-
|
|
60
|
+
onTokenFailure(creds.server, error.message);
|
|
42
61
|
return;
|
|
43
62
|
}
|
|
44
63
|
if (token == null || token.accessToken == null) {
|
|
45
|
-
|
|
64
|
+
onTokenFailure(creds.server);
|
|
46
65
|
return;
|
|
47
66
|
}
|
|
48
67
|
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
package/lib/logger.js
CHANGED
|
@@ -5,22 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.logger = void 0;
|
|
7
7
|
const kleur_1 = __importDefault(require("kleur"));
|
|
8
|
-
const
|
|
9
|
-
const triangle = '\u25b2';
|
|
10
|
-
const emptySquare = '\u25a1';
|
|
8
|
+
const tick = '√', cross = '×';
|
|
11
9
|
const log = (method, symbol, ...args) => {
|
|
12
|
-
|
|
13
|
-
const timestamp = kleur_1.default.gray(`[${now.toLocaleTimeString()}]`);
|
|
14
|
-
console[method](timestamp, symbol, args);
|
|
10
|
+
console[method](symbol, ...args);
|
|
15
11
|
};
|
|
16
12
|
exports.logger = {
|
|
17
13
|
info(...args) {
|
|
18
|
-
log('info', kleur_1.default.green(
|
|
14
|
+
log('info', kleur_1.default.green(tick), ...args);
|
|
19
15
|
},
|
|
20
16
|
warn(...args) {
|
|
21
|
-
log('warn', kleur_1.default.yellow(
|
|
17
|
+
log('warn', kleur_1.default.yellow(cross), ...args);
|
|
22
18
|
},
|
|
23
19
|
error(...args) {
|
|
24
|
-
log('error', kleur_1.default.red(
|
|
20
|
+
log('error', kleur_1.default.red(cross), ...args);
|
|
25
21
|
}
|
|
26
22
|
};
|
|
@@ -53,7 +53,7 @@ async function deploy(config, apiConfig, solution) {
|
|
|
53
53
|
try {
|
|
54
54
|
const promises = config.types.map(async (type) => {
|
|
55
55
|
type['pluginassemblyid@odata.bind'] = `/pluginassemblies(${assemblyId})`;
|
|
56
|
-
await (0, pluginType_1.deployType)(type, apiConfig, solution);
|
|
56
|
+
await (0, pluginType_1.deployType)(type, assemblyId, apiConfig, solution);
|
|
57
57
|
});
|
|
58
58
|
await Promise.all(promises);
|
|
59
59
|
}
|
package/lib/models/pluginStep.js
CHANGED
|
@@ -5,8 +5,8 @@ const node_1 = require("dataverse-webapi/lib/node");
|
|
|
5
5
|
const dataverse_service_1 = require("../dataverse.service");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
7
|
const pluginImage_1 = require("./pluginImage");
|
|
8
|
-
async function deployStep(step, apiConfig, solution) {
|
|
9
|
-
let stepId = await retrieveStep(step.name, apiConfig);
|
|
8
|
+
async function deployStep(step, typeId, apiConfig, solution) {
|
|
9
|
+
let stepId = await retrieveStep(step.name, typeId, apiConfig);
|
|
10
10
|
const messageId = await getSdkMessageId(step.message ?? '', apiConfig);
|
|
11
11
|
if (messageId == '') {
|
|
12
12
|
logger_1.logger.error(`sdk message ${step.message} not found`);
|
|
@@ -63,8 +63,8 @@ async function deployStep(step, apiConfig, solution) {
|
|
|
63
63
|
return stepId;
|
|
64
64
|
}
|
|
65
65
|
exports.deployStep = deployStep;
|
|
66
|
-
async function retrieveStep(name, apiConfig) {
|
|
67
|
-
const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}'`;
|
|
66
|
+
async function retrieveStep(name, typeId, apiConfig) {
|
|
67
|
+
const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}' and _plugintypeid_value eq ${typeId}`;
|
|
68
68
|
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
|
|
69
69
|
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
|
|
70
70
|
}
|
package/lib/models/pluginType.js
CHANGED
|
@@ -4,8 +4,8 @@ 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, apiConfig, solution) {
|
|
8
|
-
let typeId = await retrieveType(type.typename, apiConfig);
|
|
7
|
+
async function deployType(type, assemblyId, apiConfig, solution) {
|
|
8
|
+
let typeId = await retrieveType(type.typename, assemblyId, apiConfig);
|
|
9
9
|
const record = {
|
|
10
10
|
name: type.name,
|
|
11
11
|
friendlyname: type.friendlyname,
|
|
@@ -33,7 +33,7 @@ async function deployType(type, apiConfig, solution) {
|
|
|
33
33
|
if (type.steps) {
|
|
34
34
|
const promises = type.steps.map(async (step) => {
|
|
35
35
|
step['plugintypeid@odata.bind'] = `/plugintypes(${typeId})`;
|
|
36
|
-
await (0, pluginStep_1.deployStep)(step, apiConfig, solution);
|
|
36
|
+
await (0, pluginStep_1.deployStep)(step, typeId, apiConfig, solution);
|
|
37
37
|
});
|
|
38
38
|
await Promise.all(promises);
|
|
39
39
|
}
|
|
@@ -44,8 +44,8 @@ async function deployType(type, apiConfig, solution) {
|
|
|
44
44
|
return typeId;
|
|
45
45
|
}
|
|
46
46
|
exports.deployType = deployType;
|
|
47
|
-
async function retrieveType(name, apiConfig) {
|
|
48
|
-
const options = `$select=plugintypeid&$filter=typename eq '${name}'`;
|
|
47
|
+
async function retrieveType(name, assemblyId, apiConfig) {
|
|
48
|
+
const options = `$select=plugintypeid&$filter=typename eq '${name}' and _pluginassemblyid_value eq ${assemblyId}`;
|
|
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
|
}
|