@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.
Files changed (37) hide show
  1. package/.eslintrc.js +6 -8
  2. package/CHANGELOG.md +117 -0
  3. package/README.md +38 -7
  4. package/bin/fluid-fetch +0 -0
  5. package/dist/fluidAnalyzeMessages.d.ts.map +1 -1
  6. package/dist/fluidAnalyzeMessages.js +106 -116
  7. package/dist/fluidAnalyzeMessages.js.map +1 -1
  8. package/dist/fluidFetch.js +5 -3
  9. package/dist/fluidFetch.js.map +1 -1
  10. package/dist/fluidFetchArgs.d.ts +0 -3
  11. package/dist/fluidFetchArgs.d.ts.map +1 -1
  12. package/dist/fluidFetchArgs.js +10 -14
  13. package/dist/fluidFetchArgs.js.map +1 -1
  14. package/dist/fluidFetchInit.d.ts +0 -1
  15. package/dist/fluidFetchInit.d.ts.map +1 -1
  16. package/dist/fluidFetchInit.js +41 -34
  17. package/dist/fluidFetchInit.js.map +1 -1
  18. package/dist/fluidFetchMessages.d.ts.map +1 -1
  19. package/dist/fluidFetchMessages.js +168 -200
  20. package/dist/fluidFetchMessages.js.map +1 -1
  21. package/dist/fluidFetchSharePoint.d.ts +0 -1
  22. package/dist/fluidFetchSharePoint.d.ts.map +1 -1
  23. package/dist/fluidFetchSharePoint.js +20 -6
  24. package/dist/fluidFetchSharePoint.js.map +1 -1
  25. package/dist/fluidFetchSnapshot.d.ts.map +1 -1
  26. package/dist/fluidFetchSnapshot.js +18 -20
  27. package/dist/fluidFetchSnapshot.js.map +1 -1
  28. package/package.json +47 -42
  29. package/prettier.config.cjs +8 -0
  30. package/src/fluidAnalyzeMessages.ts +701 -630
  31. package/src/fluidFetch.ts +93 -88
  32. package/src/fluidFetchArgs.ts +167 -168
  33. package/src/fluidFetchInit.ts +133 -104
  34. package/src/fluidFetchMessages.ts +253 -232
  35. package/src/fluidFetchSharePoint.ts +130 -112
  36. package/src/fluidFetchSnapshot.ts +313 -295
  37. package/tsconfig.json +8 -15
@@ -4,13 +4,15 @@
4
4
  */
5
5
 
6
6
  import { URL } from "url";
7
- import child_process from "child_process";
8
- import { IFluidResolvedUrl, IResolvedUrl, IUrlResolver } from "@fluidframework/driver-definitions";
9
- import { configurableUrlResolver } from "@fluidframework/driver-utils";
7
+ import { IRequest } from "@fluidframework/core-interfaces";
8
+ import { IResolvedUrl } from "@fluidframework/driver-definitions";
10
9
  import { FluidAppOdspUrlResolver } from "@fluid-tools/fluidapp-odsp-urlresolver";
11
10
  import { IClientConfig, IOdspAuthRequestInfo } from "@fluidframework/odsp-doclib-utils";
12
11
  import * as odsp from "@fluidframework/odsp-driver";
13
- import { IOdspResolvedUrl, OdspResourceTokenFetchOptions } from "@fluidframework/odsp-driver-definitions";
12
+ import {
13
+ IOdspResolvedUrl,
14
+ OdspResourceTokenFetchOptions,
15
+ } from "@fluidframework/odsp-driver-definitions";
14
16
  import { OdspUrlResolver } from "@fluidframework/odsp-urlresolver";
15
17
  import * as r11s from "@fluidframework/routerlicious-driver";
16
18
  import { RouterliciousUrlResolver } from "@fluidframework/routerlicious-urlresolver";
@@ -21,122 +23,149 @@ import { resolveWrapper } from "./fluidFetchSharePoint";
21
23
  export let latestVersionsId: string = "";
22
24
  export let connectionInfo: any;
23
25
 
24
- export const fluidFetchWebNavigator = (url: string) => {
25
- let message = "Please open browser and navigate to this URL:";
26
- if (process.platform === "win32") {
27
- child_process.exec(`start "fluid-fetch" /B "${url}"`);
28
- message = "Opening browser to get authorization code. If that doesn't open, please go to this URL manually";
29
- }
30
- console.log(`${message}\n ${url}`);
31
- };
32
-
33
26
  async function initializeODSPCore(
34
- odspResolvedUrl: IOdspResolvedUrl,
35
- server: string,
36
- clientConfig: IClientConfig,
27
+ odspResolvedUrl: IOdspResolvedUrl,
28
+ server: string,
29
+ clientConfig: IClientConfig,
37
30
  ) {
38
- const { driveId, itemId } = odspResolvedUrl;
31
+ const { driveId, itemId } = odspResolvedUrl;
39
32
 
40
- connectionInfo = {
41
- server,
42
- drive: driveId,
43
- item: itemId,
44
- };
33
+ connectionInfo = {
34
+ server,
35
+ drive: driveId,
36
+ item: itemId,
37
+ };
45
38
 
46
- if (localDataOnly) {
47
- return;
48
- }
39
+ if (localDataOnly) {
40
+ return;
41
+ }
49
42
 
50
- const docId = await odsp.getHashedDocumentId(driveId, itemId);
43
+ const docId = await odsp.getHashedDocumentId(driveId, itemId);
51
44
 
52
- console.log(`Connecting to ODSP:
45
+ console.log(`Connecting to ODSP:
53
46
  server: ${server}
54
47
  drive: ${driveId}
55
48
  item: ${itemId}
56
49
  docId: ${docId}`);
57
50
 
58
- const getStorageTokenStub = async (options: OdspResourceTokenFetchOptions) => {
59
- return resolveWrapper(
60
- async (authRequestInfo: IOdspAuthRequestInfo) => {
61
- if ((options.refresh || !authRequestInfo.accessToken) && authRequestInfo.refreshTokenFn) {
62
- return authRequestInfo.refreshTokenFn();
63
- }
64
- return authRequestInfo.accessToken;
65
- },
66
- server,
67
- clientConfig,
68
- undefined,
69
- true,
70
- );
71
- };
72
- // eslint-disable-next-line @typescript-eslint/promise-function-async
73
- const getWebsocketTokenStub = (_options: OdspResourceTokenFetchOptions) => Promise.resolve("");
74
- const odspDocumentServiceFactory = new odsp.OdspDocumentServiceFactory(
75
- getStorageTokenStub,
76
- getWebsocketTokenStub,
77
- undefined,
78
- {
79
- opsBatchSize: 20000,
80
- concurrentOpsBatches: 4,
81
- });
82
- return odspDocumentServiceFactory.createDocumentService(odspResolvedUrl);
51
+ const getStorageTokenStub = async (options: OdspResourceTokenFetchOptions) => {
52
+ return resolveWrapper(
53
+ async (authRequestInfo: IOdspAuthRequestInfo) => {
54
+ if (
55
+ (options.refresh || !authRequestInfo.accessToken) &&
56
+ authRequestInfo.refreshTokenFn
57
+ ) {
58
+ return authRequestInfo.refreshTokenFn();
59
+ }
60
+ return authRequestInfo.accessToken;
61
+ },
62
+ server,
63
+ clientConfig,
64
+ undefined,
65
+ true,
66
+ );
67
+ };
68
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
69
+ const getWebsocketTokenStub = (_options: OdspResourceTokenFetchOptions) => Promise.resolve("");
70
+ const odspDocumentServiceFactory = new odsp.OdspDocumentServiceFactory(
71
+ getStorageTokenStub,
72
+ getWebsocketTokenStub,
73
+ undefined,
74
+ {
75
+ opsBatchSize: 20000,
76
+ concurrentOpsBatches: 4,
77
+ },
78
+ );
79
+ return odspDocumentServiceFactory.createDocumentService(odspResolvedUrl);
83
80
  }
84
81
 
85
- async function initializeR11s(server: string, pathname: string, r11sResolvedUrl: IFluidResolvedUrl) {
86
- const path = pathname.split("/");
87
- let tenantId: string;
88
- let documentId: string;
89
- if (server === "localhost" && path.length < 4) {
90
- tenantId = "fluid";
91
- documentId = path[2];
92
- } else {
93
- tenantId = path[2];
94
- documentId = path[3];
95
- }
96
-
97
- // Latest version id is the documentId for r11s
98
- latestVersionsId = documentId;
99
-
100
- connectionInfo = {
101
- server,
102
- tenantId,
103
- id: documentId,
104
- };
105
-
106
- if (localDataOnly) {
107
- return;
108
- }
109
-
110
- console.log(`Connecting to r11s: tenantId=${tenantId} id:${documentId}`);
111
- const tokenProvider = new r11s.DefaultTokenProvider(paramJWT);
112
- const r11sDocumentServiceFactory = new r11s.RouterliciousDocumentServiceFactory(tokenProvider);
113
- return r11sDocumentServiceFactory.createDocumentService(r11sResolvedUrl);
82
+ async function initializeR11s(server: string, pathname: string, r11sResolvedUrl: IResolvedUrl) {
83
+ const path = pathname.split("/");
84
+ let tenantId: string;
85
+ let documentId: string;
86
+ if (server === "localhost" && path.length < 4) {
87
+ tenantId = "fluid";
88
+ documentId = path[2];
89
+ } else {
90
+ tenantId = path[2];
91
+ documentId = path[3];
92
+ }
93
+
94
+ // Latest version id is the documentId for r11s
95
+ latestVersionsId = documentId;
96
+
97
+ connectionInfo = {
98
+ server,
99
+ tenantId,
100
+ id: documentId,
101
+ };
102
+
103
+ if (localDataOnly) {
104
+ return;
105
+ }
106
+
107
+ console.log(`Connecting to r11s: tenantId=${tenantId} id:${documentId}`);
108
+ const tokenProvider = new r11s.DefaultTokenProvider(paramJWT);
109
+ const r11sDocumentServiceFactory = new r11s.RouterliciousDocumentServiceFactory(tokenProvider);
110
+ return r11sDocumentServiceFactory.createDocumentService(r11sResolvedUrl);
114
111
  }
115
112
 
116
- async function resolveUrl(url: string): Promise<IResolvedUrl | undefined> {
117
- const resolversList: IUrlResolver[] = [
118
- new OdspUrlResolver(),
119
- new FluidAppOdspUrlResolver(),
120
- // eslint-disable-next-line @typescript-eslint/promise-function-async
121
- new RouterliciousUrlResolver(undefined, () => Promise.resolve(paramJWT), ""),
122
- ];
123
- const resolved = await configurableUrlResolver(resolversList, { url });
124
- return resolved;
113
+ interface IResolvedInfo {
114
+ resolvedUrl: IResolvedUrl;
115
+ serviceType: "odsp" | "r11s";
116
+ }
117
+ async function resolveUrl(url: string): Promise<IResolvedInfo | undefined> {
118
+ const request: IRequest = { url };
119
+ let maybeResolvedUrl: IResolvedUrl | undefined;
120
+
121
+ // Try each url resolver in turn to figure out which one the request is compatible with.
122
+ maybeResolvedUrl = await new OdspUrlResolver().resolve(request);
123
+ if (maybeResolvedUrl !== undefined) {
124
+ return {
125
+ resolvedUrl: maybeResolvedUrl,
126
+ serviceType: "odsp",
127
+ };
128
+ }
129
+
130
+ maybeResolvedUrl = await new FluidAppOdspUrlResolver().resolve(request);
131
+ if (maybeResolvedUrl !== undefined) {
132
+ return {
133
+ resolvedUrl: maybeResolvedUrl,
134
+ serviceType: "odsp",
135
+ };
136
+ }
137
+
138
+ maybeResolvedUrl = await new RouterliciousUrlResolver(
139
+ undefined,
140
+ async () => Promise.resolve(paramJWT),
141
+ "",
142
+ ).resolve(request);
143
+ if (maybeResolvedUrl !== undefined) {
144
+ return {
145
+ resolvedUrl: maybeResolvedUrl,
146
+ serviceType: "r11s",
147
+ };
148
+ }
149
+
150
+ return undefined;
125
151
  }
126
152
 
127
153
  export async function fluidFetchInit(urlStr: string) {
128
- const resolvedUrl = await resolveUrl(urlStr) as IFluidResolvedUrl;
129
- if (resolvedUrl === undefined) {
130
- return Promise.reject(new Error(`Unknown URL ${urlStr}`));
131
- }
132
- const protocol = new URL(resolvedUrl.url).protocol;
133
- if (protocol === "fluid-odsp:") {
134
- const odspResolvedUrl = resolvedUrl as IOdspResolvedUrl;
135
- return initializeODSPCore(odspResolvedUrl, new URL(odspResolvedUrl.siteUrl).host, getMicrosoftConfiguration());
136
- } else if (protocol === "fluid:") {
137
- const url = new URL(urlStr);
138
- const server = url.hostname.toLowerCase();
139
- return initializeR11s(server, url.pathname, resolvedUrl);
140
- }
141
- return Promise.reject(new Error(`Unknown resolved protocol ${protocol}`));
154
+ const resolvedInfo = await resolveUrl(urlStr);
155
+ if (resolvedInfo === undefined) {
156
+ throw new Error(`Unknown URL ${urlStr}`);
157
+ }
158
+ const fluidResolvedUrl = resolvedInfo.resolvedUrl;
159
+ if (resolvedInfo.serviceType === "odsp") {
160
+ const odspResolvedUrl = fluidResolvedUrl as IOdspResolvedUrl;
161
+ return initializeODSPCore(
162
+ odspResolvedUrl,
163
+ new URL(odspResolvedUrl.siteUrl).host,
164
+ getMicrosoftConfiguration(),
165
+ );
166
+ } else if (resolvedInfo.serviceType === "r11s") {
167
+ const url = new URL(urlStr);
168
+ const server = url.hostname.toLowerCase();
169
+ return initializeR11s(server, url.pathname, fluidResolvedUrl);
170
+ }
142
171
  }