dataverse-utils 2.7.4 → 2.7.6
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 +57 -56
- package/lib/auth.js +75 -75
- package/lib/cachePlugin.js +97 -97
- package/lib/dataverse.service.js +71 -71
- package/lib/deploy.js +64 -64
- package/lib/generate.js +99 -99
- package/lib/index.js +44 -44
- package/lib/logger.js +37 -37
- package/lib/models/customApi.js +77 -77
- package/lib/models/pluginAssembly.js +88 -87
- package/lib/models/pluginImage.js +66 -66
- package/lib/models/pluginPackage.js +93 -93
- package/lib/models/pluginStep.js +97 -97
- package/lib/models/pluginType.js +65 -65
- package/lib/models/webResource.js +130 -130
- package/lib/webResourceDeploy.js +29 -29
- package/package.json +1 -1
package/lib/assemblyDeploy.js
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
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.assemblyDeploy = 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 pluginPackage_1 = require("./models/pluginPackage");
|
|
11
|
-
const customApi_1 = require("./models/customApi");
|
|
12
|
-
const logger_1 = require("./logger");
|
|
13
|
-
async function assemblyDeploy(creds, apiConfig) {
|
|
14
|
-
const currentPath = '.';
|
|
15
|
-
const configFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
16
|
-
if (configFile == null) {
|
|
17
|
-
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const config = JSON.parse(configFile);
|
|
21
|
-
if (config.assembly) {
|
|
22
|
-
logger_1.logger.info('deploy plugin package');
|
|
23
|
-
try {
|
|
24
|
-
await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
logger_1.logger.error(error.message);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
logger_1.logger.done(`deployed plugin package ${config.prefix}_${config.name}\r\n`);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
logger_1.logger.info(`deploy assembly to ${creds.server}`);
|
|
34
|
-
try {
|
|
35
|
-
await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
logger_1.logger.error(error.message);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
logger_1.logger.done(`deployed assembly ${config.name}`);
|
|
42
|
-
}
|
|
43
|
-
if (config.customapis != null && config.pluginassemblyid) {
|
|
44
|
-
logger_1.logger.info('deploy custom api');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.assemblyDeploy = 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 pluginPackage_1 = require("./models/pluginPackage");
|
|
11
|
+
const customApi_1 = require("./models/customApi");
|
|
12
|
+
const logger_1 = require("./logger");
|
|
13
|
+
async function assemblyDeploy(creds, apiConfig) {
|
|
14
|
+
const currentPath = '.';
|
|
15
|
+
const configFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
16
|
+
if (configFile == null) {
|
|
17
|
+
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const config = JSON.parse(configFile);
|
|
21
|
+
if (config.assembly) {
|
|
22
|
+
logger_1.logger.info('deploy plugin package');
|
|
23
|
+
try {
|
|
24
|
+
await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
logger_1.logger.error(error.message);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
logger_1.logger.done(`deployed plugin package ${config.prefix}_${config.name}\r\n`);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
logger_1.logger.info(`deploy assembly to ${creds.server}`);
|
|
34
|
+
try {
|
|
35
|
+
await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
logger_1.logger.error(error.message);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
logger_1.logger.done(`deployed assembly ${config.name}`);
|
|
42
|
+
}
|
|
43
|
+
if ((config.customapis != null && config.pluginassemblyid) || config.assembly.pluginassemblyid) {
|
|
44
|
+
logger_1.logger.info('deploy custom api');
|
|
45
|
+
const assemblyId = config.pluginassemblyid ?? config.assembly.pluginassemblyid;
|
|
46
|
+
try {
|
|
47
|
+
const promises = config.customapis.map((a) => (0, customApi_1.deployApi)(a, assemblyId, apiConfig, creds.solution));
|
|
48
|
+
await Promise.all(promises);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
logger_1.logger.error(error.message);
|
|
52
|
+
}
|
|
53
|
+
logger_1.logger.done('deployed custom api');
|
|
54
|
+
}
|
|
55
|
+
await fs_1.default.promises.writeFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), JSON.stringify(config, null, 4), 'utf8');
|
|
56
|
+
}
|
|
57
|
+
exports.assemblyDeploy = assemblyDeploy;
|
package/lib/auth.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
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.getAccessToken = exports.onTokenFailure = void 0;
|
|
7
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
8
|
-
const cachePlugin_1 = require("./cachePlugin");
|
|
9
|
-
const msal_node_1 = require("@azure/msal-node");
|
|
10
|
-
const logger_1 = require("./logger");
|
|
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;
|
|
31
|
-
const getAccessToken = async (tenant, url) => {
|
|
32
|
-
const config = {
|
|
33
|
-
auth: {
|
|
34
|
-
clientId: clientId,
|
|
35
|
-
authority: `https://login.microsoftonline.com/${tenant}/`
|
|
36
|
-
},
|
|
37
|
-
cache: {
|
|
38
|
-
cachePlugin: (0, cachePlugin_1.cachePlugin)(url)
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const pca = new msal_node_1.PublicClientApplication(config);
|
|
42
|
-
const cache = pca.getTokenCache();
|
|
43
|
-
const accounts = await cache?.getAllAccounts().catch(ex => {
|
|
44
|
-
throw new Error(ex.message);
|
|
45
|
-
});
|
|
46
|
-
// Try to get token silently
|
|
47
|
-
if (accounts.length > 0) {
|
|
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
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Acquire token by device code
|
|
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) {
|
|
72
|
-
throw new Error(ex.message);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
exports.getAccessToken = getAccessToken;
|
|
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.getAccessToken = exports.onTokenFailure = void 0;
|
|
7
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
8
|
+
const cachePlugin_1 = require("./cachePlugin");
|
|
9
|
+
const msal_node_1 = require("@azure/msal-node");
|
|
10
|
+
const logger_1 = require("./logger");
|
|
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;
|
|
31
|
+
const getAccessToken = async (tenant, url) => {
|
|
32
|
+
const config = {
|
|
33
|
+
auth: {
|
|
34
|
+
clientId: clientId,
|
|
35
|
+
authority: `https://login.microsoftonline.com/${tenant}/`
|
|
36
|
+
},
|
|
37
|
+
cache: {
|
|
38
|
+
cachePlugin: (0, cachePlugin_1.cachePlugin)(url)
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const pca = new msal_node_1.PublicClientApplication(config);
|
|
42
|
+
const cache = pca.getTokenCache();
|
|
43
|
+
const accounts = await cache?.getAllAccounts().catch(ex => {
|
|
44
|
+
throw new Error(ex.message);
|
|
45
|
+
});
|
|
46
|
+
// Try to get token silently
|
|
47
|
+
if (accounts.length > 0) {
|
|
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
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Acquire token by device code
|
|
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) {
|
|
72
|
+
throw new Error(ex.message);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.getAccessToken = getAccessToken;
|
package/lib/cachePlugin.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
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 = exports.deleteCache = exports.cacheExists = exports.getCachePath = 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"));
|
|
11
|
-
const encrypt = (text) => {
|
|
12
|
-
const user = os_1.default.userInfo().username;
|
|
13
|
-
const cryptr = new cryptr_1.default(user);
|
|
14
|
-
const encrypted = cryptr.encrypt(text);
|
|
15
|
-
return encrypted;
|
|
16
|
-
};
|
|
17
|
-
const decrypt = (text) => {
|
|
18
|
-
const user = os_1.default.userInfo().username;
|
|
19
|
-
const cryptr = new cryptr_1.default(user);
|
|
20
|
-
const decrypted = cryptr.decrypt(text);
|
|
21
|
-
return decrypted;
|
|
22
|
-
};
|
|
23
|
-
const getCachePath = (url) => {
|
|
24
|
-
const org = new URL(url).hostname.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);
|
|
49
|
-
const beforeCacheAccess = (tokenCacheContext) => {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
if (fs_1.default.existsSync(cacheLocation)) {
|
|
52
|
-
fs_1.default.readFile(cacheLocation, 'utf-8', (err, data) => {
|
|
53
|
-
if (err) {
|
|
54
|
-
reject();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const decrypted = decrypt(data);
|
|
58
|
-
tokenCacheContext.tokenCache.deserialize(decrypted);
|
|
59
|
-
resolve();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
65
|
-
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
66
|
-
if (err) {
|
|
67
|
-
reject();
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
resolve();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
const afterCacheAccess = (tokenCacheContext) => {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
if (tokenCacheContext.cacheHasChanged) {
|
|
79
|
-
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
80
|
-
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
81
|
-
if (err) {
|
|
82
|
-
reject(err);
|
|
83
|
-
}
|
|
84
|
-
resolve();
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
resolve();
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
beforeCacheAccess,
|
|
94
|
-
afterCacheAccess
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
exports.cachePlugin = cachePlugin;
|
|
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 = exports.deleteCache = exports.cacheExists = exports.getCachePath = 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"));
|
|
11
|
+
const encrypt = (text) => {
|
|
12
|
+
const user = os_1.default.userInfo().username;
|
|
13
|
+
const cryptr = new cryptr_1.default(user);
|
|
14
|
+
const encrypted = cryptr.encrypt(text);
|
|
15
|
+
return encrypted;
|
|
16
|
+
};
|
|
17
|
+
const decrypt = (text) => {
|
|
18
|
+
const user = os_1.default.userInfo().username;
|
|
19
|
+
const cryptr = new cryptr_1.default(user);
|
|
20
|
+
const decrypted = cryptr.decrypt(text);
|
|
21
|
+
return decrypted;
|
|
22
|
+
};
|
|
23
|
+
const getCachePath = (url) => {
|
|
24
|
+
const org = new URL(url).hostname.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);
|
|
49
|
+
const beforeCacheAccess = (tokenCacheContext) => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
if (fs_1.default.existsSync(cacheLocation)) {
|
|
52
|
+
fs_1.default.readFile(cacheLocation, 'utf-8', (err, data) => {
|
|
53
|
+
if (err) {
|
|
54
|
+
reject();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const decrypted = decrypt(data);
|
|
58
|
+
tokenCacheContext.tokenCache.deserialize(decrypted);
|
|
59
|
+
resolve();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
65
|
+
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
66
|
+
if (err) {
|
|
67
|
+
reject();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
resolve();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const afterCacheAccess = (tokenCacheContext) => {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
if (tokenCacheContext.cacheHasChanged) {
|
|
79
|
+
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
80
|
+
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
81
|
+
if (err) {
|
|
82
|
+
reject(err);
|
|
83
|
+
}
|
|
84
|
+
resolve();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
resolve();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
beforeCacheAccess,
|
|
94
|
+
afterCacheAccess
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
exports.cachePlugin = cachePlugin;
|
package/lib/dataverse.service.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
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
|
-
const logger_1 = require("./logger");
|
|
6
|
-
var ComponentType;
|
|
7
|
-
(function (ComponentType) {
|
|
8
|
-
ComponentType[ComponentType["WebResource"] = 61] = "WebResource";
|
|
9
|
-
ComponentType[ComponentType["PluginType"] = 90] = "PluginType";
|
|
10
|
-
ComponentType[ComponentType["PluginAssembly"] = 91] = "PluginAssembly";
|
|
11
|
-
ComponentType[ComponentType["SDKMessageProcessingStep"] = 92] = "SDKMessageProcessingStep";
|
|
12
|
-
ComponentType[ComponentType["SDKMessageProcessingStepImage"] = 93] = "SDKMessageProcessingStepImage";
|
|
13
|
-
ComponentType[ComponentType["PluginPackage"] = 10865] = "PluginPackage";
|
|
14
|
-
})(ComponentType = exports.ComponentType || (exports.ComponentType = {}));
|
|
15
|
-
async function addToSolution(id, solution, type, apiConfig) {
|
|
16
|
-
const data = {
|
|
17
|
-
ComponentId: id,
|
|
18
|
-
ComponentType: type,
|
|
19
|
-
SolutionUniqueName: solution,
|
|
20
|
-
AddRequiredComponents: false,
|
|
21
|
-
IncludedComponentSettingsValues: null
|
|
22
|
-
};
|
|
23
|
-
logger_1.logger.info(`add component ${id} to solution ${solution}`);
|
|
24
|
-
await (0, node_1.unboundAction)(apiConfig, 'AddSolutionComponent', data);
|
|
25
|
-
}
|
|
26
|
-
exports.addToSolution = addToSolution;
|
|
27
|
-
async function publish(publishXml, apiConfig) {
|
|
28
|
-
const data = {
|
|
29
|
-
ParameterXml: `<importexportxml><webresources>${publishXml}</webresources></importexportxml>`
|
|
30
|
-
};
|
|
31
|
-
await (0, node_1.unboundAction)(apiConfig, 'PublishXml', data);
|
|
32
|
-
}
|
|
33
|
-
exports.publish = publish;
|
|
34
|
-
async function getTableMetadata(table, apiConfig) {
|
|
35
|
-
const options = [
|
|
36
|
-
'?$select=DisplayName,LogicalName,EntitySetName,SchemaName',
|
|
37
|
-
'&$expand=Attributes($select=LogicalName,SchemaName)'
|
|
38
|
-
].join('');
|
|
39
|
-
const metadata = await (0, node_1.retrieveMultiple)(apiConfig, `EntityDefinitions(LogicalName='${table}')`, options);
|
|
40
|
-
if (metadata == null) {
|
|
41
|
-
throw Error(`Table ${table} not found in metadata cache`);
|
|
42
|
-
}
|
|
43
|
-
const choiceOptions = [
|
|
44
|
-
'?$select=attributevalue,value,attributename',
|
|
45
|
-
`&$filter=objecttypecode eq '${table}'`
|
|
46
|
-
].join('');
|
|
47
|
-
const choiceMetadata = await (0, node_1.retrieveMultiple)(apiConfig, 'stringmaps', choiceOptions);
|
|
48
|
-
const tableMetadata = {
|
|
49
|
-
logicalName: metadata.LogicalName,
|
|
50
|
-
schemaName: metadata.SchemaName,
|
|
51
|
-
entitySetName: metadata.EntitySetName,
|
|
52
|
-
choices: [],
|
|
53
|
-
fields: metadata.Attributes.map((a) => {
|
|
54
|
-
return {
|
|
55
|
-
logicalName: a.LogicalName,
|
|
56
|
-
schemaName: a.SchemaName
|
|
57
|
-
};
|
|
58
|
-
})
|
|
59
|
-
};
|
|
60
|
-
choiceMetadata.value.forEach((c) => {
|
|
61
|
-
const index = tableMetadata.choices.findIndex(x => x.column === c.attributename);
|
|
62
|
-
if (index === -1) {
|
|
63
|
-
tableMetadata.choices.push({ column: c.attributename, options: [{ text: c.value, value: c.attributevalue }] });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
tableMetadata.choices[index].options.push({ text: c.value, value: c.attributevalue });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return tableMetadata;
|
|
70
|
-
}
|
|
71
|
-
exports.getTableMetadata = getTableMetadata;
|
|
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
|
+
const logger_1 = require("./logger");
|
|
6
|
+
var ComponentType;
|
|
7
|
+
(function (ComponentType) {
|
|
8
|
+
ComponentType[ComponentType["WebResource"] = 61] = "WebResource";
|
|
9
|
+
ComponentType[ComponentType["PluginType"] = 90] = "PluginType";
|
|
10
|
+
ComponentType[ComponentType["PluginAssembly"] = 91] = "PluginAssembly";
|
|
11
|
+
ComponentType[ComponentType["SDKMessageProcessingStep"] = 92] = "SDKMessageProcessingStep";
|
|
12
|
+
ComponentType[ComponentType["SDKMessageProcessingStepImage"] = 93] = "SDKMessageProcessingStepImage";
|
|
13
|
+
ComponentType[ComponentType["PluginPackage"] = 10865] = "PluginPackage";
|
|
14
|
+
})(ComponentType = exports.ComponentType || (exports.ComponentType = {}));
|
|
15
|
+
async function addToSolution(id, solution, type, apiConfig) {
|
|
16
|
+
const data = {
|
|
17
|
+
ComponentId: id,
|
|
18
|
+
ComponentType: type,
|
|
19
|
+
SolutionUniqueName: solution,
|
|
20
|
+
AddRequiredComponents: false,
|
|
21
|
+
IncludedComponentSettingsValues: null
|
|
22
|
+
};
|
|
23
|
+
logger_1.logger.info(`add component ${id} to solution ${solution}`);
|
|
24
|
+
await (0, node_1.unboundAction)(apiConfig, 'AddSolutionComponent', data);
|
|
25
|
+
}
|
|
26
|
+
exports.addToSolution = addToSolution;
|
|
27
|
+
async function publish(publishXml, apiConfig) {
|
|
28
|
+
const data = {
|
|
29
|
+
ParameterXml: `<importexportxml><webresources>${publishXml}</webresources></importexportxml>`
|
|
30
|
+
};
|
|
31
|
+
await (0, node_1.unboundAction)(apiConfig, 'PublishXml', data);
|
|
32
|
+
}
|
|
33
|
+
exports.publish = publish;
|
|
34
|
+
async function getTableMetadata(table, apiConfig) {
|
|
35
|
+
const options = [
|
|
36
|
+
'?$select=DisplayName,LogicalName,EntitySetName,SchemaName',
|
|
37
|
+
'&$expand=Attributes($select=LogicalName,SchemaName)'
|
|
38
|
+
].join('');
|
|
39
|
+
const metadata = await (0, node_1.retrieveMultiple)(apiConfig, `EntityDefinitions(LogicalName='${table}')`, options);
|
|
40
|
+
if (metadata == null) {
|
|
41
|
+
throw Error(`Table ${table} not found in metadata cache`);
|
|
42
|
+
}
|
|
43
|
+
const choiceOptions = [
|
|
44
|
+
'?$select=attributevalue,value,attributename',
|
|
45
|
+
`&$filter=objecttypecode eq '${table}'`
|
|
46
|
+
].join('');
|
|
47
|
+
const choiceMetadata = await (0, node_1.retrieveMultiple)(apiConfig, 'stringmaps', choiceOptions);
|
|
48
|
+
const tableMetadata = {
|
|
49
|
+
logicalName: metadata.LogicalName,
|
|
50
|
+
schemaName: metadata.SchemaName,
|
|
51
|
+
entitySetName: metadata.EntitySetName,
|
|
52
|
+
choices: [],
|
|
53
|
+
fields: metadata.Attributes.map((a) => {
|
|
54
|
+
return {
|
|
55
|
+
logicalName: a.LogicalName,
|
|
56
|
+
schemaName: a.SchemaName
|
|
57
|
+
};
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
choiceMetadata.value.forEach((c) => {
|
|
61
|
+
const index = tableMetadata.choices.findIndex(x => x.column === c.attributename);
|
|
62
|
+
if (index === -1) {
|
|
63
|
+
tableMetadata.choices.push({ column: c.attributename, options: [{ text: c.value, value: c.attributevalue }] });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
tableMetadata.choices[index].options.push({ text: c.value, value: c.attributevalue });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return tableMetadata;
|
|
70
|
+
}
|
|
71
|
+
exports.getTableMetadata = getTableMetadata;
|