@adobe/helix-onedrive-cli 1.11.88 → 1.11.90

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.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.11.90](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.89...v1.11.90) (2022-11-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * switch to support 9.0.0 ([#398](https://github.com/adobe/helix-onedrive-cli/issues/398)) ([db5bfdb](https://github.com/adobe/helix-onedrive-cli/commit/db5bfdb6e09bf96be123d31999e8cdedcdf2bd2e))
7
+
8
+ ## [1.11.89](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.88...v1.11.89) (2022-11-10)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency @adobe/helix-onedrive-support to v8.4.2 ([#396](https://github.com/adobe/helix-onedrive-cli/issues/396)) ([2019707](https://github.com/adobe/helix-onedrive-cli/commit/2019707fe8c2acf0cc1f6862447da5922ede5e31))
14
+
1
15
  ## [1.11.88](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.87...v1.11.88) (2022-11-07)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-onedrive-cli",
3
- "version": "1.11.88",
3
+ "version": "1.11.90",
4
4
  "description": "Helix OneDrive CLI",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -25,10 +25,9 @@
25
25
  },
26
26
  "homepage": "https://github.com/adobe/helix-onedrive-cli#readme",
27
27
  "dependencies": {
28
- "@adobe/helix-log": "6.0.0",
29
- "@adobe/helix-onedrive-support": "8.4.1",
30
- "chalk-template": "0.4.0",
28
+ "@adobe/helix-onedrive-support": "9.0.0",
31
29
  "@adobe/helix-shared-config": "9.1.1",
30
+ "chalk-template": "0.4.0",
32
31
  "cookie-parser": "1.4.6",
33
32
  "dotenv": "16.0.3",
34
33
  "express": "4.18.2",
@@ -46,7 +45,7 @@
46
45
  "eslint": "8.27.0",
47
46
  "eslint-plugin-header": "3.1.1",
48
47
  "eslint-plugin-import": "2.26.0",
49
- "husky": "8.0.1",
48
+ "husky": "8.0.2",
50
49
  "junit-report-builder": "3.0.1",
51
50
  "lint-staged": "13.0.3",
52
51
  "mocha": "10.1.0",
package/src/client.js CHANGED
@@ -10,9 +10,10 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  import fs from 'fs-extra';
13
+ import openBrowser from 'open';
13
14
  import chalk from 'chalk-template';
14
- import { OneDrive } from '@adobe/helix-onedrive-support';
15
- import { logger, debug, info } from './logging.js';
15
+ import { FSCachePlugin, OneDrive, OneDriveAuth } from '@adobe/helix-onedrive-support';
16
+ import { logger, info } from './logging.js';
16
17
 
17
18
  const STATE_FILE = '.hlx-1d.json';
18
19
  const AUTH_FILE = '.auth.json';
@@ -52,8 +53,6 @@ export async function getOneDriveClient() {
52
53
  AZURE_APP_CLIENT_ID: clientId = DEFAULT_CLIENT_ID,
53
54
  AZURE_APP_CLIENT_SECRET: clientSecret = '',
54
55
  AZURE_APP_TENANT: tenant = '',
55
- AZURE_APP_USER: username = '',
56
- AZURE_APP_PASS: password = '',
57
56
  } = process.env;
58
57
 
59
58
  if (!clientId) {
@@ -63,40 +62,20 @@ export async function getOneDriveClient() {
63
62
  info(chalk`AZURE_APP_CLIENT_SECRET={gray <client-secret of the app>}`);
64
63
  process.exit(-1);
65
64
  }
66
- let tokens = [];
67
- try {
68
- tokens = await fs.readJson(AUTH_FILE, 'utf-8');
69
- } catch (e) {
70
- // ignore
71
- }
72
-
73
- let {
74
- AZURE_APP_REFRESH_TOKEN: refreshToken = '',
75
- } = process.env;
76
-
77
- if (!refreshToken && tokens.length) {
78
- refreshToken = tokens[0].refreshToken;
79
- }
80
-
81
- client = new OneDrive({
65
+ const auth = new OneDriveAuth({
82
66
  clientId,
83
67
  clientSecret,
84
- refreshToken,
85
68
  tenant,
86
- username,
87
- password,
88
69
  localAuthCache: true,
70
+ cachePlugin: new FSCachePlugin({ log: logger, filePath: AUTH_FILE }),
71
+ onCode: async (code) => {
72
+ info(code.message);
73
+ await openBrowser(code.verificationUri);
74
+ },
89
75
  log: logger,
90
76
  });
77
+ await auth.authenticate();
91
78
 
92
- await client.loadTokenCache(tokens);
93
-
94
- // register event handle to write back tokens.
95
- client.on('tokens', (newTokens) => {
96
- // don't store the tokens w/o refresh token
97
- const validTokens = newTokens.filter((tok) => tok.refreshToken);
98
- fs.writeFileSync(AUTH_FILE, JSON.stringify(validTokens, null, 2), 'utf-8');
99
- debug(`updated ${AUTH_FILE} file.`);
100
- });
79
+ client = new OneDrive({ auth });
101
80
  return client;
102
81
  }
package/src/logging.js CHANGED
@@ -9,11 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- import { createDefaultLogger, SimpleInterface } from '@adobe/helix-log';
13
-
14
- const rootLogger = createDefaultLogger();
15
-
16
- export const logger = new SimpleInterface({ logger: rootLogger });
12
+ export const logger = console;
17
13
  export const debug = logger.debug.bind(logger);
18
14
  export const info = logger.info.bind(logger);
19
15
  export const warn = logger.warn.bind(logger);
@@ -23,18 +23,8 @@ export default async function install(yargs) {
23
23
  })
24
24
  .command({
25
25
  command: 'login',
26
- desc: 'Start the login interactive flow or ROPC flow with username / password.',
27
- builder: (y) => y
28
- .option('username', {
29
- alias: 'u',
30
- type: 'string',
31
- description: 'Username for ROPC flow.',
32
- }).option('password', {
33
- alias: 'p',
34
- type: 'string',
35
- description: 'Password for ROPC flow.',
36
- }),
37
- handler: (y) => onedrive.login(y.username, y.password),
26
+ desc: 'Start the login interactive flow',
27
+ handler: onedrive.login,
38
28
  })
39
29
  .command({
40
30
  command: 'logout',
package/src/onedrive.js CHANGED
@@ -12,8 +12,6 @@
12
12
  import fs from 'fs-extra';
13
13
  import path from 'path';
14
14
  import chalk from 'chalk-template';
15
- import openBrowser from 'open';
16
- import readline from 'readline';
17
15
  import { URLSearchParams } from 'url';
18
16
  import { MountConfig } from '@adobe/helix-shared-config';
19
17
  import { debug, error, info } from './logging.js';
@@ -23,57 +21,8 @@ import {
23
21
 
24
22
  const AUTH_FILE = '.auth.json';
25
23
 
26
- async function prompt(msg, hide = false) {
27
- return new Promise((res) => {
28
- const rl = readline.createInterface({
29
- input: process.stdin,
30
- output: process.stdout,
31
- });
32
- rl.question(msg, (value) => {
33
- rl.close();
34
- res(value);
35
- });
36
- // eslint-disable-next-line no-underscore-dangle
37
- rl._writeToOutput = function _writeToOutput(c) {
38
- if (!hide || c.trim() === '\n' || c === '\r' || c === '\r\n') {
39
- rl.output.write(c);
40
- } else {
41
- rl.output.write('*');
42
- }
43
- };
44
- });
45
- }
46
-
47
- async function login(username, password) {
24
+ async function login() {
48
25
  const od = await getOneDriveClient();
49
- if (od.refreshToken) {
50
- const tokenResponse = await od.getAccessToken();
51
- if (tokenResponse.refreshToken) {
52
- info('already logged in.');
53
- return;
54
- }
55
- }
56
- if (username !== undefined) {
57
- if (!username) {
58
- // eslint-disable-next-line no-param-reassign
59
- username = await prompt('username: ');
60
- } else {
61
- info(`username: ${username}`);
62
- }
63
- if (!password) {
64
- // eslint-disable-next-line no-param-reassign
65
- password = await prompt('password: ', true);
66
- } else {
67
- info('password: ***');
68
- }
69
- od.username = username;
70
- od.password = password;
71
- } else {
72
- await od.login(async (code) => {
73
- await openBrowser(code.verificationUrl);
74
- });
75
- }
76
-
77
26
  const result = await od.me();
78
27
  info(chalk`Logged in as: {yellow ${result.displayName}} {grey (${result.mail})}`);
79
28
  }