dataverse-utils 2.1.2 → 2.2.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/CHANGELOG.json CHANGED
@@ -2,7 +2,73 @@
2
2
  "name": "dataverse-utils",
3
3
  "entries": [
4
4
  {
5
- "date": "Sun, 16 Jan 2022 22:56:55 GMT",
5
+ "date": "Tue, 08 Feb 2022 18:13:39 GMT",
6
+ "tag": "dataverse-utils_v2.2.1",
7
+ "version": "2.2.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "derek.finlinson@journeyteam.com",
12
+ "package": "dataverse-utils",
13
+ "commit": "cfa9121f50ea731b9ef639154153b01dc81fff85",
14
+ "comment": "Fix logger and file paths"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 07 Feb 2022 22:02:33 GMT",
21
+ "tag": "dataverse-utils_v2.2.0",
22
+ "version": "2.2.0",
23
+ "comments": {
24
+ "minor": [
25
+ {
26
+ "author": "derek.finlinson@journeyteam.com",
27
+ "package": "dataverse-utils",
28
+ "commit": "55d633b2c3064bbdce48c5d314d8e7572a015882",
29
+ "comment": "Switch to combined logger"
30
+ },
31
+ {
32
+ "author": "beachball",
33
+ "package": "dataverse-utils",
34
+ "comment": "Bump dataverse-webapi to v2.0.4",
35
+ "commit": "83b50fd1a35a0645f279e60b8ca0eb2ace5c0ad3"
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ {
41
+ "date": "Fri, 28 Jan 2022 23:11:16 GMT",
42
+ "tag": "dataverse-utils_v2.1.4",
43
+ "version": "2.1.4",
44
+ "comments": {
45
+ "patch": [
46
+ {
47
+ "author": "derek.finlinson@journeyteam.com",
48
+ "package": "dataverse-utils",
49
+ "commit": "fb9365e3fcd8ada0b97dfc4e86661c67332734bf",
50
+ "comment": "Prompt to delete cache on error"
51
+ }
52
+ ]
53
+ }
54
+ },
55
+ {
56
+ "date": "Sun, 16 Jan 2022 23:22:22 GMT",
57
+ "tag": "dataverse-utils_v2.1.3",
58
+ "version": "2.1.3",
59
+ "comments": {
60
+ "patch": [
61
+ {
62
+ "author": "derek.finlinson@journeyteam.com",
63
+ "package": "dataverse-utils",
64
+ "commit": "928a436f3d6627765a329ee4cb31d83cab714b1d",
65
+ "comment": "Switch symbols"
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ "date": "Sun, 16 Jan 2022 22:57:20 GMT",
6
72
  "tag": "dataverse-utils_v2.1.2",
7
73
  "version": "2.1.2",
8
74
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,17 +1,50 @@
1
1
  # Change Log - dataverse-utils
2
2
 
3
- This log was last generated on Sun, 16 Jan 2022 22:56:55 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 08 Feb 2022 18:13:39 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 2.1.2
7
+ ## 2.2.1
8
8
 
9
- Sun, 16 Jan 2022 22:56:55 GMT
9
+ Tue, 08 Feb 2022 18:13:39 GMT
10
10
 
11
11
  ### Patches
12
12
 
13
- - Fix logging for real (derek.finlinson@journeyteam.com)
13
+ - Fix logger and file paths (derek.finlinson@journeyteam.com)
14
14
 
15
+ ## 2.2.0
16
+
17
+ Mon, 07 Feb 2022 22:02:33 GMT
18
+
19
+ ### Minor changes
20
+
21
+ - Switch to combined logger (derek.finlinson@journeyteam.com)
22
+ - Bump dataverse-webapi to v2.0.4
23
+
24
+ ## 2.1.4
25
+
26
+ Fri, 28 Jan 2022 23:11:16 GMT
27
+
28
+ ### Patches
29
+
30
+ - Prompt to delete cache on error (derek.finlinson@journeyteam.com)
31
+
32
+ ## 2.1.3
33
+
34
+ Sun, 16 Jan 2022 23:22:22 GMT
35
+
36
+ ### Patches
37
+
38
+ - Switch symbols (derek.finlinson@journeyteam.com)
39
+
40
+ ## 2.1.2
41
+
42
+ Sun, 16 Jan 2022 22:57:20 GMT
43
+
44
+ ### Patches
45
+
46
+ - Fix logging for real (derek.finlinson@journeyteam.com)
47
+
15
48
  ## 2.1.1
16
49
 
17
50
  Sun, 16 Jan 2022 22:41:55 GMT
@@ -24,6 +24,6 @@ async function deployAssembly(creds, apiConfig) {
24
24
  logger_1.logger.error(error.message);
25
25
  return;
26
26
  }
27
- logger_1.logger.info(`deployed assembly ${config.name}\r\n`);
27
+ logger_1.logger.done(`deployed assembly ${config.name}\r\n`);
28
28
  }
29
29
  exports.deployAssembly = deployAssembly;
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.replace('https://', '').split('.')[0])
15
+ cachePlugin: (0, cachePlugin_1.cachePlugin)(url)
16
16
  }
17
17
  };
18
18
  const pca = new msal_node_1.PublicClientApplication(config);
@@ -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
- function cachePlugin(org) {
24
- const getCachePath = () => {
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
- const cacheLocation = getCachePath();
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
- logger_1.logger.error(`failed to acquire access token: ${error.message}`);
60
+ onTokenFailure(creds.server, error.message);
42
61
  return;
43
62
  }
44
63
  if (token == null || token.accessToken == null) {
45
- logger_1.logger.error('failed to acquire access token');
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/generate.js CHANGED
@@ -94,6 +94,6 @@ async function generate(table) {
94
94
  fs_1.default.mkdirSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models'));
95
95
  }
96
96
  fs_1.default.writeFileSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models', `${metadata.schemaName}.ts`), codeFile);
97
- logger_1.logger.info(`Table metadata output to models/${metadata.schemaName}.ts`);
97
+ logger_1.logger.done(`Table metadata output to models/${metadata.schemaName}.ts`);
98
98
  }
99
99
  exports.default = generate;
package/lib/logger.js CHANGED
@@ -3,24 +3,34 @@ 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.logger = void 0;
6
+ exports.logger = exports.icons = void 0;
7
7
  const kleur_1 = __importDefault(require("kleur"));
8
- const square = '\u25a0';
9
- const triangle = '\u25b2';
10
- const emptySquare = '\u25a1';
11
- const log = (method, symbol, ...args) => {
12
- const now = new Date();
13
- const timestamp = kleur_1.default.gray(`[${now.toLocaleTimeString()}]`);
14
- console[method](timestamp, symbol, ...args);
8
+ const isTest = process.env.JEST_WORKER_ID !== undefined;
9
+ exports.icons = {
10
+ done: kleur_1.default.green(''),
11
+ info: kleur_1.default.cyan('!'),
12
+ error: kleur_1.default.red('⨂'),
13
+ warn: kleur_1.default.yellow('‼')
15
14
  };
16
15
  exports.logger = {
17
16
  info(...args) {
18
- log('info', kleur_1.default.green(square), ...args);
17
+ if (!isTest) {
18
+ console.info(exports.icons.info, ...args);
19
+ }
19
20
  },
20
21
  warn(...args) {
21
- log('warn', kleur_1.default.yellow(triangle), ...args);
22
+ if (!isTest) {
23
+ console.warn(exports.icons.warn, ...args);
24
+ }
22
25
  },
23
26
  error(...args) {
24
- log('error', kleur_1.default.red(emptySquare), ...args);
25
- }
27
+ if (!isTest) {
28
+ console.error(exports.icons.error, ...args);
29
+ }
30
+ },
31
+ done(...args) {
32
+ if (!isTest) {
33
+ console.info(exports.icons.info, ...args);
34
+ }
35
+ },
26
36
  };
@@ -13,7 +13,7 @@ const logger_1 = require("../logger");
13
13
  async function deploy(config, apiConfig, solution) {
14
14
  const files = glob_1.default.sync(`**/${config.name}.dll`);
15
15
  if (files.length === 0) {
16
- logger_1.logger.error(`assembly ${config.name}.dll not found`);
16
+ logger_1.logger.warn(`assembly ${config.name}.dll not found`);
17
17
  return;
18
18
  }
19
19
  const content = fs_1.default.readFileSync(files[0]).toString('base64');
@@ -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
  }
@@ -5,16 +5,16 @@ 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
- logger_1.logger.error(`sdk message ${step.message} not found`);
12
+ logger_1.logger.warn(`sdk message ${step.message} not found`);
13
13
  return;
14
14
  }
15
15
  const filterId = await getSdkMessageFilterId(messageId, step.entity ?? '', apiConfig);
16
16
  if (filterId == '') {
17
- logger_1.logger.error(`sdk message ${step.message} for entity ${step.entity} not found`);
17
+ logger_1.logger.warn(`sdk message ${step.message} for entity ${step.entity} not found`);
18
18
  return;
19
19
  }
20
20
  step['sdkmessagefilterid@odata.bind'] = `/sdkmessagefilters(${filterId})`;
@@ -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
  }
@@ -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
  }
@@ -47,7 +47,7 @@ async function deploy(webResources, apiConfig, solution, files) {
47
47
  for (const file of files.split(',')) {
48
48
  const resource = webResources.filter(r => r.path?.endsWith(file));
49
49
  if (resource.length === 0) {
50
- logger_1.logger.error(`web resource ${file} not found in dataverse.config.json`);
50
+ logger_1.logger.warn(`web resource ${file} not found in dataverse.config.json`);
51
51
  continue;
52
52
  }
53
53
  resources.push(resource[0]);
@@ -24,6 +24,6 @@ async function deployWebResource(creds, apiConfig, files) {
24
24
  logger_1.logger.error(error.message);
25
25
  return;
26
26
  }
27
- logger_1.logger.info('deployed web resources');
27
+ logger_1.logger.done('deployed web resources');
28
28
  }
29
29
  exports.deployWebResource = deployWebResource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataverse-utils",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
4
4
  "license": "MIT",
5
5
  "description": "Utilities for interacting with Dataverse environments",
6
6
  "main": "lib/index.js",
@@ -17,21 +17,22 @@
17
17
  "scripts": {
18
18
  "build": "tsc -p .",
19
19
  "lint": "eslint",
20
- "prebuild": "rimraf lib"
20
+ "clean": "rimraf lib"
21
21
  },
22
22
  "dependencies": {
23
23
  "@azure/msal-node": "^1.3.1",
24
24
  "commander": "^8.3.0",
25
- "glob": "^7.2.0",
26
25
  "cryptr": "^6.0.2",
27
- "dataverse-webapi": "^2.0.3",
26
+ "dataverse-webapi": "^2.0.4",
28
27
  "envinfo": "^7.8.1",
28
+ "glob": "^7.2.0",
29
29
  "kleur": "^4.1.4",
30
30
  "prompts": "^2.4.2"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/node": "^16.9.1",
33
+ "@types/cryptr": "^4.0.1",
34
34
  "@types/glob": "^7.2.0",
35
+ "@types/node": "^16.9.1",
35
36
  "@types/prompts": "^2.0.14"
36
37
  }
37
38
  }