@adobe/helix-onedrive-cli 1.11.167 → 1.11.168
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 +7 -0
- package/package.json +4 -4
- package/src/client.js +22 -3
- package/src/onedrive.js +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.11.168](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.167...v1.11.168) (2023-07-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update adobe fixes ([#523](https://github.com/adobe/helix-onedrive-cli/issues/523)) ([8501bc7](https://github.com/adobe/helix-onedrive-cli/commit/8501bc7e3b4445599448ae1a29623646a20fc6c1))
|
|
7
|
+
|
|
1
8
|
## [1.11.167](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.166...v1.11.167) (2023-07-16)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-onedrive-cli",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.168",
|
|
4
4
|
"description": "Helix OneDrive CLI",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/adobe/helix-onedrive-cli#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@adobe/helix-onedrive-support": "10.
|
|
29
|
-
"@adobe/helix-shared-config": "10.3.
|
|
30
|
-
"@adobe/helix-shared-tokencache": "1.
|
|
28
|
+
"@adobe/helix-onedrive-support": "10.3.0",
|
|
29
|
+
"@adobe/helix-shared-config": "10.3.2",
|
|
30
|
+
"@adobe/helix-shared-tokencache": "1.3.0",
|
|
31
31
|
"chalk-template": "1.1.0",
|
|
32
32
|
"cookie-parser": "1.4.6",
|
|
33
33
|
"dotenv": "16.3.1",
|
package/src/client.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import fs from 'fs-extra';
|
|
13
13
|
import openBrowser from 'open';
|
|
14
14
|
import chalk from 'chalk-template';
|
|
15
|
-
import { OneDrive, OneDriveAuth } from '@adobe/helix-onedrive-support';
|
|
15
|
+
import { OneDrive, OneDriveAuth, AcquireMethod } from '@adobe/helix-onedrive-support';
|
|
16
16
|
import { FSCachePlugin } from '@adobe/helix-shared-tokencache';
|
|
17
17
|
import { logger, info } from './logging.js';
|
|
18
18
|
|
|
@@ -46,14 +46,14 @@ let client = null;
|
|
|
46
46
|
*
|
|
47
47
|
* @returns {OneDrive} OneDrive client
|
|
48
48
|
*/
|
|
49
|
-
export async function getOneDriveClient() {
|
|
49
|
+
export async function getOneDriveClient(shareUrl) {
|
|
50
50
|
if (client) {
|
|
51
51
|
return client;
|
|
52
52
|
}
|
|
53
53
|
const {
|
|
54
54
|
AZURE_APP_CLIENT_ID: clientId = DEFAULT_CLIENT_ID,
|
|
55
55
|
AZURE_APP_CLIENT_SECRET: clientSecret = '',
|
|
56
|
-
AZURE_APP_TENANT: tenant = '',
|
|
56
|
+
AZURE_APP_TENANT: tenant = state.tenant || '',
|
|
57
57
|
} = process.env;
|
|
58
58
|
|
|
59
59
|
if (!clientId) {
|
|
@@ -63,6 +63,14 @@ export async function getOneDriveClient() {
|
|
|
63
63
|
info(chalk`AZURE_APP_CLIENT_SECRET={gray <client-secret of the app>}`);
|
|
64
64
|
process.exit(-1);
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
if (!tenant && !shareUrl) {
|
|
68
|
+
info(chalk`{red error:} Missing tenant environment. run 1d resolve to set one.`);
|
|
69
|
+
info(chalk`Suggest to create a {yellow .env} file with:\n`);
|
|
70
|
+
info(chalk`AZURE_APP_TENANT={gray <sharepoint tenant>}`);
|
|
71
|
+
process.exit(-1);
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
const auth = new OneDriveAuth({
|
|
67
75
|
clientId,
|
|
68
76
|
clientSecret,
|
|
@@ -73,10 +81,21 @@ export async function getOneDriveClient() {
|
|
|
73
81
|
info(code.message);
|
|
74
82
|
await openBrowser(code.verificationUri);
|
|
75
83
|
},
|
|
84
|
+
acquireMethod: state.delegated
|
|
85
|
+
? AcquireMethod.BY_DEVICE_CODE
|
|
86
|
+
: AcquireMethod.BY_CLIENT_CREDENTIAL,
|
|
76
87
|
log: logger,
|
|
77
88
|
});
|
|
89
|
+
|
|
90
|
+
if (!tenant) {
|
|
91
|
+
await auth.initTenantFromUrl(shareUrl);
|
|
92
|
+
}
|
|
93
|
+
|
|
78
94
|
await auth.authenticate();
|
|
79
95
|
|
|
96
|
+
state.tenant = auth.tenant;
|
|
97
|
+
await saveState();
|
|
98
|
+
|
|
80
99
|
client = new OneDrive({ auth });
|
|
81
100
|
return client;
|
|
82
101
|
}
|
package/src/onedrive.js
CHANGED
|
@@ -16,12 +16,14 @@ import { URLSearchParams } from 'url';
|
|
|
16
16
|
import { MountConfig } from '@adobe/helix-shared-config';
|
|
17
17
|
import { debug, error, info } from './logging.js';
|
|
18
18
|
import {
|
|
19
|
-
getOneDriveClient,
|
|
19
|
+
getOneDriveClient, loadState, saveState,
|
|
20
20
|
} from './client.js';
|
|
21
21
|
|
|
22
22
|
const AUTH_FILE = '.auth.json';
|
|
23
23
|
|
|
24
24
|
async function login() {
|
|
25
|
+
const state = await loadState();
|
|
26
|
+
state.delegated = true;
|
|
25
27
|
const od = await getOneDriveClient();
|
|
26
28
|
const result = await od.me();
|
|
27
29
|
info(chalk`Logged in as: {yellow ${result.displayName}} {grey (${result.mail})}`);
|
|
@@ -30,9 +32,13 @@ async function login() {
|
|
|
30
32
|
async function logout() {
|
|
31
33
|
// for now, we just delete the .auth.json
|
|
32
34
|
await fs.remove(AUTH_FILE);
|
|
35
|
+
const state = await loadState();
|
|
36
|
+
state.delegated = false;
|
|
37
|
+
await saveState();
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
async function me() {
|
|
41
|
+
await loadState();
|
|
36
42
|
const od = await getOneDriveClient();
|
|
37
43
|
await od.me();
|
|
38
44
|
const result = await od.me();
|
|
@@ -40,8 +46,9 @@ async function me() {
|
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
async function resolve(args) {
|
|
43
|
-
const
|
|
49
|
+
const state = await loadState();
|
|
44
50
|
const { link } = args;
|
|
51
|
+
const od = await getOneDriveClient(link);
|
|
45
52
|
const result = link.startsWith('/drives/')
|
|
46
53
|
? await od.getDriveRootItem(link.split('/')[2])
|
|
47
54
|
: await od.getDriveItemFromShareLink(link);
|
|
@@ -52,7 +59,8 @@ async function resolve(args) {
|
|
|
52
59
|
info(chalk` Id: {yellow ${id}}`);
|
|
53
60
|
info(chalk` URL: {yellow ${webUrl}}`);
|
|
54
61
|
info(chalk`DriveId: {yellow ${driveId}}`);
|
|
55
|
-
|
|
62
|
+
info(chalk` Tenant: {yellow ${state.tenant}}`);
|
|
63
|
+
|
|
56
64
|
state.link = link;
|
|
57
65
|
state.root = canonicalPath;
|
|
58
66
|
state.cwd = '/';
|
|
@@ -81,7 +89,7 @@ function dateFormat(s) {
|
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
function graphApiFormatter(item) {
|
|
84
|
-
const user = item.lastModifiedBy.user.email;
|
|
92
|
+
const user = item.lastModifiedBy.user.email || item.lastModifiedBy.user.displayName || 'unknown';
|
|
85
93
|
const date = item.lastModifiedDateTime;
|
|
86
94
|
const size = item.folder?.childCount ?? item.size;
|
|
87
95
|
let { name } = item;
|