dataverse-utils 2.3.0 → 2.3.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 +24 -1
- package/lib/deploy.js +2 -21
- package/lib/generate.js +2 -2
- 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: {
|
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);
|