dataverse-utils 2.3.0 → 2.4.1
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/auth.js +46 -15
- package/lib/deploy.js +2 -21
- package/lib/generate.js +2 -2
- package/lib/models/pluginImage.js +7 -7
- package/lib/models/pluginStep.js +1 -1
- package/package.json +1 -1
package/lib/auth.js
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAccessToken = void 0;
|
|
6
|
+
exports.getAccessToken = exports.onTokenFailure = void 0;
|
|
7
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
4
8
|
const cachePlugin_1 = require("./cachePlugin");
|
|
5
9
|
const msal_node_1 = require("@azure/msal-node");
|
|
6
10
|
const logger_1 = require("./logger");
|
|
7
11
|
const clientId = '51f81489-12ee-4a9e-aaae-a2591f45987d';
|
|
12
|
+
const onTokenFailure = async (url, error) => {
|
|
13
|
+
if (error) {
|
|
14
|
+
logger_1.logger.error(`failed to acquire access token: ${error}`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
logger_1.logger.error('failed to acquire access token');
|
|
18
|
+
}
|
|
19
|
+
if ((0, cachePlugin_1.cacheExists)(url)) {
|
|
20
|
+
const { deleteToken } = await (0, prompts_1.default)({
|
|
21
|
+
type: 'confirm',
|
|
22
|
+
name: 'deleteToken',
|
|
23
|
+
message: `delete current token cache for ${url}?`
|
|
24
|
+
});
|
|
25
|
+
if (deleteToken) {
|
|
26
|
+
(0, cachePlugin_1.deleteCache)(url);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.onTokenFailure = onTokenFailure;
|
|
8
31
|
const getAccessToken = async (tenant, url) => {
|
|
9
32
|
const config = {
|
|
10
33
|
auth: {
|
|
@@ -22,23 +45,31 @@ const getAccessToken = async (tenant, url) => {
|
|
|
22
45
|
});
|
|
23
46
|
// Try to get token silently
|
|
24
47
|
if (accounts.length > 0) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
try {
|
|
49
|
+
const silentToken = await pca.acquireTokenSilent({
|
|
50
|
+
account: accounts[0],
|
|
51
|
+
scopes: [`${url}/.default`]
|
|
52
|
+
});
|
|
53
|
+
if (silentToken) {
|
|
54
|
+
return silentToken;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (ex) {
|
|
58
|
+
if (ex.message.indexOf('The refresh token has expired due to inactivity') === -1) {
|
|
59
|
+
throw new Error(ex.message);
|
|
60
|
+
}
|
|
33
61
|
}
|
|
34
62
|
}
|
|
35
63
|
// Acquire token by device code
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
try {
|
|
65
|
+
const token = await pca.acquireTokenByDeviceCode({
|
|
66
|
+
scopes: [`${url}/.default`],
|
|
67
|
+
deviceCodeCallback: (response) => logger_1.logger.info(response.message)
|
|
68
|
+
});
|
|
69
|
+
return token;
|
|
70
|
+
}
|
|
71
|
+
catch (ex) {
|
|
40
72
|
throw new Error(ex.message);
|
|
41
|
-
}
|
|
42
|
-
return token;
|
|
73
|
+
}
|
|
43
74
|
};
|
|
44
75
|
exports.getAccessToken = getAccessToken;
|
package/lib/deploy.js
CHANGED
|
@@ -11,25 +11,6 @@ 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
|
-
};
|
|
33
14
|
async function deploy(type, files) {
|
|
34
15
|
if (!type || (type !== 'webresource' && type !== 'assembly')) {
|
|
35
16
|
const invalid = type !== undefined && type !== 'webresource' && type !== 'assembly';
|
|
@@ -57,11 +38,11 @@ async function deploy(type, files) {
|
|
|
57
38
|
token = await (0, auth_1.getAccessToken)(creds.tenant, creds.server);
|
|
58
39
|
}
|
|
59
40
|
catch (error) {
|
|
60
|
-
onTokenFailure(creds.server, error.message);
|
|
41
|
+
(0, auth_1.onTokenFailure)(creds.server, error.message);
|
|
61
42
|
return;
|
|
62
43
|
}
|
|
63
44
|
if (token == null || token.accessToken == null) {
|
|
64
|
-
onTokenFailure(creds.server);
|
|
45
|
+
(0, auth_1.onTokenFailure)(creds.server);
|
|
65
46
|
return;
|
|
66
47
|
}
|
|
67
48
|
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
package/lib/generate.js
CHANGED
|
@@ -31,11 +31,11 @@ async function generate(table) {
|
|
|
31
31
|
token = await (0, auth_1.getAccessToken)(creds.tenant, creds.server);
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
|
|
34
|
+
(0, auth_1.onTokenFailure)(creds.server, error.message);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
if (token == null || token.accessToken == null) {
|
|
38
|
-
|
|
38
|
+
(0, auth_1.onTokenFailure)(creds.server);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
|
@@ -3,7 +3,7 @@ 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, image, message, apiConfig) {
|
|
6
|
+
async function deployImage(stepId, stepName, image, message, apiConfig) {
|
|
7
7
|
image['sdkmessageprocessingstepid@odata.bind'] = `/sdkmessageprocessingsteps(${stepId})`;
|
|
8
8
|
switch (message) {
|
|
9
9
|
case 'Create':
|
|
@@ -25,7 +25,7 @@ async function deployImage(stepId, image, message, apiConfig) {
|
|
|
25
25
|
let imageId = await retrieveImage(stepId, image, apiConfig);
|
|
26
26
|
if (imageId != '') {
|
|
27
27
|
try {
|
|
28
|
-
await updateImage(imageId, image, apiConfig);
|
|
28
|
+
await updateImage(imageId, image, stepName, apiConfig);
|
|
29
29
|
}
|
|
30
30
|
catch (error) {
|
|
31
31
|
throw new Error(`failed to update plugin image: ${error.message}`);
|
|
@@ -33,7 +33,7 @@ async function deployImage(stepId, image, message, apiConfig) {
|
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
try {
|
|
36
|
-
imageId = await createImage(image, apiConfig);
|
|
36
|
+
imageId = await createImage(image, stepName, apiConfig);
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
39
|
throw new Error(`failed to create plugin image: ${error.message}`);
|
|
@@ -47,15 +47,15 @@ async function retrieveImage(stepId, image, apiConfig) {
|
|
|
47
47
|
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingstepimages', options);
|
|
48
48
|
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepimageid : '';
|
|
49
49
|
}
|
|
50
|
-
async function createImage(image, apiConfig) {
|
|
51
|
-
logger_1.logger.info(`create plugin image ${image.name}`);
|
|
50
|
+
async function createImage(image, stepName, apiConfig) {
|
|
51
|
+
logger_1.logger.info(`create plugin image ${image.name} for step ${stepName}`);
|
|
52
52
|
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingstepimages', image, '$select=sdkmessageprocessingstepimageid');
|
|
53
53
|
if (result.error) {
|
|
54
54
|
throw new Error(result.error.message);
|
|
55
55
|
}
|
|
56
56
|
return result.sdkmessageprocessingstepimageid;
|
|
57
57
|
}
|
|
58
|
-
async function updateImage(id, image, apiConfig) {
|
|
59
|
-
logger_1.logger.info(`update plugin image ${image.name}`);
|
|
58
|
+
async function updateImage(id, image, stepName, apiConfig) {
|
|
59
|
+
logger_1.logger.info(`update plugin image ${image.name} for step ${stepName}`);
|
|
60
60
|
return (0, node_1.update)(apiConfig, 'sdkmessageprocessingstepimages', id, image);
|
|
61
61
|
}
|
package/lib/models/pluginStep.js
CHANGED
|
@@ -53,7 +53,7 @@ async function deployStep(step, typeId, apiConfig, solution) {
|
|
|
53
53
|
}
|
|
54
54
|
if (images && images.length > 0) {
|
|
55
55
|
try {
|
|
56
|
-
const promises = images.map(image => (0, pluginImage_1.deployImage)(stepId, image, message, apiConfig));
|
|
56
|
+
const promises = images.map(image => (0, pluginImage_1.deployImage)(stepId, step.name, image, message, apiConfig));
|
|
57
57
|
await Promise.all(promises);
|
|
58
58
|
}
|
|
59
59
|
catch (error) {
|