@fluid-tools/fetch-tool 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419
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/.eslintrc.js +6 -8
- package/CHANGELOG.md +117 -0
- package/README.md +38 -7
- package/bin/fluid-fetch +0 -0
- package/dist/fluidAnalyzeMessages.d.ts.map +1 -1
- package/dist/fluidAnalyzeMessages.js +106 -116
- package/dist/fluidAnalyzeMessages.js.map +1 -1
- package/dist/fluidFetch.js +5 -3
- package/dist/fluidFetch.js.map +1 -1
- package/dist/fluidFetchArgs.d.ts +0 -3
- package/dist/fluidFetchArgs.d.ts.map +1 -1
- package/dist/fluidFetchArgs.js +10 -14
- package/dist/fluidFetchArgs.js.map +1 -1
- package/dist/fluidFetchInit.d.ts +0 -1
- package/dist/fluidFetchInit.d.ts.map +1 -1
- package/dist/fluidFetchInit.js +41 -34
- package/dist/fluidFetchInit.js.map +1 -1
- package/dist/fluidFetchMessages.d.ts.map +1 -1
- package/dist/fluidFetchMessages.js +168 -200
- package/dist/fluidFetchMessages.js.map +1 -1
- package/dist/fluidFetchSharePoint.d.ts +0 -1
- package/dist/fluidFetchSharePoint.d.ts.map +1 -1
- package/dist/fluidFetchSharePoint.js +20 -6
- package/dist/fluidFetchSharePoint.js.map +1 -1
- package/dist/fluidFetchSnapshot.d.ts.map +1 -1
- package/dist/fluidFetchSnapshot.js +18 -20
- package/dist/fluidFetchSnapshot.js.map +1 -1
- package/package.json +47 -42
- package/prettier.config.cjs +8 -0
- package/src/fluidAnalyzeMessages.ts +701 -630
- package/src/fluidFetch.ts +93 -88
- package/src/fluidFetchArgs.ts +167 -168
- package/src/fluidFetchInit.ts +133 -104
- package/src/fluidFetchMessages.ts +253 -232
- package/src/fluidFetchSharePoint.ts +130 -112
- package/src/fluidFetchSnapshot.ts +313 -295
- package/tsconfig.json +8 -15
|
@@ -3,139 +3,157 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import child_process from "child_process";
|
|
7
|
+
import { DriverErrorTypes } from "@fluidframework/driver-definitions";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
getChildrenByDriveItem,
|
|
10
|
+
getDriveItemByServerRelativePath,
|
|
11
|
+
getDriveItemFromDriveAndItem,
|
|
12
|
+
IClientConfig,
|
|
13
|
+
IOdspDriveItem,
|
|
14
|
+
getOdspRefreshTokenFn,
|
|
15
|
+
IOdspAuthRequestInfo,
|
|
15
16
|
} from "@fluidframework/odsp-doclib-utils";
|
|
16
17
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
getMicrosoftConfiguration,
|
|
19
|
+
OdspTokenManager,
|
|
20
|
+
odspTokensCache,
|
|
21
|
+
OdspTokenConfig,
|
|
22
|
+
IOdspTokenManagerCacheKey,
|
|
22
23
|
} from "@fluidframework/tool-utils";
|
|
23
|
-
import { fluidFetchWebNavigator } from "./fluidFetchInit";
|
|
24
24
|
import { getForceTokenReauth } from "./fluidFetchArgs";
|
|
25
25
|
|
|
26
26
|
export async function resolveWrapper<T>(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
callback: (authRequestInfo: IOdspAuthRequestInfo) => Promise<T>,
|
|
28
|
+
server: string,
|
|
29
|
+
clientConfig: IClientConfig,
|
|
30
|
+
forceTokenReauth = false,
|
|
31
|
+
forToken = false,
|
|
32
32
|
): Promise<T> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
try {
|
|
34
|
+
const odspTokenManager = new OdspTokenManager(odspTokensCache);
|
|
35
|
+
const tokenConfig: OdspTokenConfig = {
|
|
36
|
+
type: "browserLogin",
|
|
37
|
+
navigator: fluidFetchWebNavigator,
|
|
38
|
+
};
|
|
39
|
+
const tokens = await odspTokenManager.getOdspTokens(
|
|
40
|
+
server,
|
|
41
|
+
clientConfig,
|
|
42
|
+
tokenConfig,
|
|
43
|
+
undefined /* forceRefresh */,
|
|
44
|
+
forceTokenReauth || getForceTokenReauth(),
|
|
45
|
+
);
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
const result = await callback({
|
|
48
|
+
accessToken: tokens.accessToken,
|
|
49
|
+
refreshTokenFn: getOdspRefreshTokenFn(server, clientConfig, tokens),
|
|
50
|
+
});
|
|
51
|
+
// If this is used for getting a token, then refresh the cache with new token.
|
|
52
|
+
if (forToken) {
|
|
53
|
+
const key: IOdspTokenManagerCacheKey = { isPush: false, userOrServer: server };
|
|
54
|
+
await odspTokenManager.updateTokensCache(key, {
|
|
55
|
+
accessToken: result as any as string,
|
|
56
|
+
refreshToken: tokens.refreshToken,
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
} catch (e: any) {
|
|
62
|
+
if (e.errorType === DriverErrorTypes.authorizationError && !forceTokenReauth) {
|
|
63
|
+
// Re-auth
|
|
64
|
+
return resolveWrapper<T>(callback, server, clientConfig, true, forToken);
|
|
65
|
+
}
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
async function resolveDriveItemByServerRelativePath(
|
|
71
|
+
server: string,
|
|
72
|
+
serverRelativePath: string,
|
|
73
|
+
clientConfig: IClientConfig,
|
|
72
74
|
) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
),
|
|
81
|
-
server, clientConfig);
|
|
75
|
+
return resolveWrapper<IOdspDriveItem>(
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
77
|
+
(authRequestInfo) =>
|
|
78
|
+
getDriveItemByServerRelativePath(server, serverRelativePath, authRequestInfo, false),
|
|
79
|
+
server,
|
|
80
|
+
clientConfig,
|
|
81
|
+
);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
async function resolveChildrenByDriveItem(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
server: string,
|
|
86
|
+
folderDriveItem: IOdspDriveItem,
|
|
87
|
+
clientConfig: IClientConfig,
|
|
88
88
|
) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
return resolveWrapper<IOdspDriveItem[]>(
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
91
|
+
(authRequestInfo) => getChildrenByDriveItem(folderDriveItem, server, authRequestInfo),
|
|
92
|
+
server,
|
|
93
|
+
clientConfig,
|
|
94
|
+
);
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
export async function getSharepointFiles(
|
|
96
|
-
|
|
97
|
+
export async function getSharepointFiles(
|
|
98
|
+
server: string,
|
|
99
|
+
serverRelativePath: string,
|
|
100
|
+
recurse: boolean,
|
|
101
|
+
) {
|
|
102
|
+
const clientConfig = getMicrosoftConfiguration();
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const fileInfo = await resolveDriveItemByServerRelativePath(
|
|
105
|
+
server,
|
|
106
|
+
serverRelativePath,
|
|
107
|
+
clientConfig,
|
|
108
|
+
);
|
|
109
|
+
console.log(fileInfo);
|
|
110
|
+
const pendingFolder: { path: string; folder: IOdspDriveItem }[] = [];
|
|
111
|
+
const files: IOdspDriveItem[] = [];
|
|
112
|
+
if (fileInfo.isFolder) {
|
|
113
|
+
pendingFolder.push({ path: serverRelativePath, folder: fileInfo });
|
|
114
|
+
} else {
|
|
115
|
+
files.push(fileInfo);
|
|
116
|
+
}
|
|
107
117
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
// eslint-disable-next-line no-constant-condition
|
|
119
|
+
while (true) {
|
|
120
|
+
const folderInfo = pendingFolder.shift();
|
|
121
|
+
if (!folderInfo) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
const { path, folder } = folderInfo;
|
|
125
|
+
const children = await resolveChildrenByDriveItem(server, folder, clientConfig);
|
|
126
|
+
for (const child of children) {
|
|
127
|
+
const childPath = `${path}/${child.name}`;
|
|
128
|
+
if (child.isFolder) {
|
|
129
|
+
if (recurse) {
|
|
130
|
+
pendingFolder.push({ path: childPath, folder: child });
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
files.push(child);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return files;
|
|
126
138
|
}
|
|
127
139
|
|
|
128
|
-
export async function getSingleSharePointFile(
|
|
129
|
-
|
|
130
|
-
drive: string,
|
|
131
|
-
item: string,
|
|
132
|
-
) {
|
|
133
|
-
const clientConfig = getMicrosoftConfiguration();
|
|
140
|
+
export async function getSingleSharePointFile(server: string, drive: string, item: string) {
|
|
141
|
+
const clientConfig = getMicrosoftConfiguration();
|
|
134
142
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
return resolveWrapper<IOdspDriveItem>(
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
145
|
+
(authRequestInfo) => getDriveItemFromDriveAndItem(server, drive, item, authRequestInfo),
|
|
146
|
+
server,
|
|
147
|
+
clientConfig,
|
|
148
|
+
);
|
|
141
149
|
}
|
|
150
|
+
|
|
151
|
+
const fluidFetchWebNavigator = (url: string) => {
|
|
152
|
+
let message = "Please open browser and navigate to this URL:";
|
|
153
|
+
if (process.platform === "win32") {
|
|
154
|
+
child_process.exec(`start "fluid-fetch" /B "${url}"`);
|
|
155
|
+
message =
|
|
156
|
+
"Opening browser to get authorization code. If that doesn't open, please go to this URL manually";
|
|
157
|
+
}
|
|
158
|
+
console.log(`${message}\n ${url}`);
|
|
159
|
+
};
|