@fluid-tools/fetch-tool 2.0.0-dev-rc.2.0.0.246488 → 2.0.0-dev-rc.3.0.0.253463

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 (58) hide show
  1. package/dist/fluidAnalyzeMessages.js +22 -19
  2. package/dist/fluidAnalyzeMessages.js.map +1 -1
  3. package/dist/fluidFetch.js +18 -18
  4. package/dist/fluidFetch.js.map +1 -1
  5. package/dist/fluidFetchInit.d.ts +1 -1
  6. package/dist/fluidFetchInit.d.ts.map +1 -1
  7. package/dist/fluidFetchInit.js +15 -15
  8. package/dist/fluidFetchInit.js.map +1 -1
  9. package/dist/fluidFetchMessages.d.ts +1 -1
  10. package/dist/fluidFetchMessages.d.ts.map +1 -1
  11. package/dist/fluidFetchMessages.js +13 -13
  12. package/dist/fluidFetchMessages.js.map +1 -1
  13. package/dist/fluidFetchSharePoint.d.ts +1 -1
  14. package/dist/fluidFetchSharePoint.d.ts.map +1 -1
  15. package/dist/fluidFetchSharePoint.js +6 -6
  16. package/dist/fluidFetchSharePoint.js.map +1 -1
  17. package/dist/fluidFetchSnapshot.d.ts +1 -1
  18. package/dist/fluidFetchSnapshot.d.ts.map +1 -1
  19. package/dist/fluidFetchSnapshot.js +20 -20
  20. package/dist/fluidFetchSnapshot.js.map +1 -1
  21. package/dist/package.json +3 -0
  22. package/lib/fluidAnalyzeMessages.d.ts +8 -0
  23. package/lib/fluidAnalyzeMessages.d.ts.map +1 -0
  24. package/lib/fluidAnalyzeMessages.js +629 -0
  25. package/lib/fluidAnalyzeMessages.js.map +1 -0
  26. package/lib/fluidFetch.d.ts +6 -0
  27. package/lib/fluidFetch.d.ts.map +1 -0
  28. package/lib/fluidFetch.js +120 -0
  29. package/lib/fluidFetch.js.map +1 -0
  30. package/lib/fluidFetchArgs.d.ts +31 -0
  31. package/lib/fluidFetchArgs.d.ts.map +1 -0
  32. package/lib/fluidFetchArgs.js +192 -0
  33. package/lib/fluidFetchArgs.js.map +1 -0
  34. package/lib/fluidFetchInit.d.ts +8 -0
  35. package/lib/fluidFetchInit.d.ts.map +1 -0
  36. package/lib/fluidFetchInit.js +117 -0
  37. package/lib/fluidFetchInit.js.map +1 -0
  38. package/lib/fluidFetchMessages.d.ts +7 -0
  39. package/lib/fluidFetchMessages.d.ts.map +1 -0
  40. package/lib/fluidFetchMessages.js +225 -0
  41. package/lib/fluidFetchMessages.js.map +1 -0
  42. package/lib/fluidFetchSharePoint.d.ts +9 -0
  43. package/lib/fluidFetchSharePoint.d.ts.map +1 -0
  44. package/lib/fluidFetchSharePoint.js +100 -0
  45. package/lib/fluidFetchSharePoint.js.map +1 -0
  46. package/lib/fluidFetchSnapshot.d.ts +7 -0
  47. package/lib/fluidFetchSnapshot.d.ts.map +1 -0
  48. package/lib/fluidFetchSnapshot.js +261 -0
  49. package/lib/fluidFetchSnapshot.js.map +1 -0
  50. package/package.json +26 -26
  51. package/src/fluidAnalyzeMessages.ts +13 -10
  52. package/src/fluidFetch.ts +8 -6
  53. package/src/fluidFetchInit.ts +13 -9
  54. package/src/fluidFetchMessages.ts +8 -6
  55. package/src/fluidFetchSharePoint.ts +10 -8
  56. package/src/fluidFetchSnapshot.ts +7 -4
  57. package/tsconfig.cjs.json +7 -0
  58. package/tsconfig.json +2 -5
@@ -0,0 +1,117 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as odsp from "@fluidframework/odsp-driver/internal";
6
+ import { FluidAppOdspUrlResolver, OdspUrlResolver, } from "@fluidframework/odsp-urlresolver/internal";
7
+ import * as r11s from "@fluidframework/routerlicious-driver/internal";
8
+ import { RouterliciousUrlResolver } from "@fluidframework/routerlicious-urlresolver/internal";
9
+ import { getMicrosoftConfiguration } from "@fluidframework/tool-utils/internal";
10
+ import { localDataOnly, paramJWT } from "./fluidFetchArgs.js";
11
+ import { resolveWrapper } from "./fluidFetchSharePoint.js";
12
+ export let latestVersionsId = "";
13
+ export let connectionInfo;
14
+ async function initializeODSPCore(odspResolvedUrl, server, clientConfig) {
15
+ const { driveId, itemId } = odspResolvedUrl;
16
+ connectionInfo = {
17
+ server,
18
+ drive: driveId,
19
+ item: itemId,
20
+ };
21
+ if (localDataOnly) {
22
+ return;
23
+ }
24
+ const docId = await odsp.getHashedDocumentId(driveId, itemId);
25
+ console.log(`Connecting to ODSP:
26
+ server: ${server}
27
+ drive: ${driveId}
28
+ item: ${itemId}
29
+ docId: ${docId}`);
30
+ const getStorageTokenStub = async (options) => {
31
+ return resolveWrapper(async (authRequestInfo) => {
32
+ if ((options.refresh || !authRequestInfo.accessToken) &&
33
+ authRequestInfo.refreshTokenFn) {
34
+ return authRequestInfo.refreshTokenFn();
35
+ }
36
+ return authRequestInfo.accessToken;
37
+ }, server, clientConfig, undefined, true);
38
+ };
39
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
40
+ const getWebsocketTokenStub = (_options) => Promise.resolve("");
41
+ const odspDocumentServiceFactory = new odsp.OdspDocumentServiceFactory(getStorageTokenStub, getWebsocketTokenStub, undefined, {
42
+ opsBatchSize: 20000,
43
+ concurrentOpsBatches: 4,
44
+ });
45
+ return odspDocumentServiceFactory.createDocumentService(odspResolvedUrl);
46
+ }
47
+ async function initializeR11s(server, pathname, r11sResolvedUrl) {
48
+ const path = pathname.split("/");
49
+ let tenantId;
50
+ let documentId;
51
+ if (server === "localhost" && path.length < 4) {
52
+ tenantId = "fluid";
53
+ documentId = path[2];
54
+ }
55
+ else {
56
+ tenantId = path[2];
57
+ documentId = path[3];
58
+ }
59
+ // Latest version id is the documentId for r11s
60
+ latestVersionsId = documentId;
61
+ connectionInfo = {
62
+ server,
63
+ tenantId,
64
+ id: documentId,
65
+ };
66
+ if (localDataOnly) {
67
+ return;
68
+ }
69
+ console.log(`Connecting to r11s: tenantId=${tenantId} id:${documentId}`);
70
+ const tokenProvider = new r11s.DefaultTokenProvider(paramJWT);
71
+ const r11sDocumentServiceFactory = new r11s.RouterliciousDocumentServiceFactory(tokenProvider);
72
+ return r11sDocumentServiceFactory.createDocumentService(r11sResolvedUrl);
73
+ }
74
+ async function resolveUrl(url) {
75
+ const request = { url };
76
+ let maybeResolvedUrl;
77
+ // Try each url resolver in turn to figure out which one the request is compatible with.
78
+ maybeResolvedUrl = await new OdspUrlResolver().resolve(request);
79
+ if (maybeResolvedUrl !== undefined) {
80
+ return {
81
+ resolvedUrl: maybeResolvedUrl,
82
+ serviceType: "odsp",
83
+ };
84
+ }
85
+ maybeResolvedUrl = await new FluidAppOdspUrlResolver().resolve(request);
86
+ if (maybeResolvedUrl !== undefined) {
87
+ return {
88
+ resolvedUrl: maybeResolvedUrl,
89
+ serviceType: "odsp",
90
+ };
91
+ }
92
+ maybeResolvedUrl = await new RouterliciousUrlResolver(undefined, async () => Promise.resolve(paramJWT), "").resolve(request);
93
+ if (maybeResolvedUrl !== undefined) {
94
+ return {
95
+ resolvedUrl: maybeResolvedUrl,
96
+ serviceType: "r11s",
97
+ };
98
+ }
99
+ return undefined;
100
+ }
101
+ export async function fluidFetchInit(urlStr) {
102
+ const resolvedInfo = await resolveUrl(urlStr);
103
+ if (resolvedInfo === undefined) {
104
+ throw new Error(`Unknown URL ${urlStr}`);
105
+ }
106
+ const fluidResolvedUrl = resolvedInfo.resolvedUrl;
107
+ if (resolvedInfo.serviceType === "odsp") {
108
+ const odspResolvedUrl = fluidResolvedUrl;
109
+ return initializeODSPCore(odspResolvedUrl, new URL(odspResolvedUrl.siteUrl).host, getMicrosoftConfiguration());
110
+ }
111
+ else if (resolvedInfo.serviceType === "r11s") {
112
+ const url = new URL(urlStr);
113
+ const server = url.hostname.toLowerCase();
114
+ return initializeR11s(server, url.pathname, fluidResolvedUrl);
115
+ }
116
+ }
117
+ //# sourceMappingURL=fluidFetchInit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluidFetchInit.js","sourceRoot":"","sources":["../src/fluidFetchInit.ts"],"names":[],"mappings":"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AAC,WAAW,KAAK,MAAM,EAAE;QACxC,MAAM,eAAe,GAAG,gBAAoC,CAAC;QAC7D,OAAO,kBAAkB,CACxB,eAAe,EACf,IAAI,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,EACrC,yBAAyB,EAAE,CAC3B,CAAC;KACF;SAAM,IAAI,YAAY,CAAC,WAAW,KAAK,MAAM,EAAE;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC1C,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;KAC9D;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions/internal\";\nimport { IClientConfig, IOdspAuthRequestInfo } from \"@fluidframework/odsp-doclib-utils/internal\";\nimport * as odsp from \"@fluidframework/odsp-driver/internal\";\nimport {\n\tIOdspResolvedUrl,\n\tOdspResourceTokenFetchOptions,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tFluidAppOdspUrlResolver,\n\tOdspUrlResolver,\n} from \"@fluidframework/odsp-urlresolver/internal\";\nimport * as r11s from \"@fluidframework/routerlicious-driver/internal\";\nimport { RouterliciousUrlResolver } from \"@fluidframework/routerlicious-urlresolver/internal\";\nimport { getMicrosoftConfiguration } from \"@fluidframework/tool-utils/internal\";\n\nimport { localDataOnly, paramJWT } from \"./fluidFetchArgs.js\";\nimport { resolveWrapper } from \"./fluidFetchSharePoint.js\";\n\nexport let latestVersionsId: string = \"\";\nexport let connectionInfo: any;\n\nasync function initializeODSPCore(\n\todspResolvedUrl: IOdspResolvedUrl,\n\tserver: string,\n\tclientConfig: IClientConfig,\n) {\n\tconst { driveId, itemId } = odspResolvedUrl;\n\n\tconnectionInfo = {\n\t\tserver,\n\t\tdrive: driveId,\n\t\titem: itemId,\n\t};\n\n\tif (localDataOnly) {\n\t\treturn;\n\t}\n\n\tconst docId = await odsp.getHashedDocumentId(driveId, itemId);\n\n\tconsole.log(`Connecting to ODSP:\n server: ${server}\n drive: ${driveId}\n item: ${itemId}\n docId: ${docId}`);\n\n\tconst getStorageTokenStub = async (options: OdspResourceTokenFetchOptions) => {\n\t\treturn resolveWrapper(\n\t\t\tasync (authRequestInfo: IOdspAuthRequestInfo) => {\n\t\t\t\tif (\n\t\t\t\t\t(options.refresh || !authRequestInfo.accessToken) &&\n\t\t\t\t\tauthRequestInfo.refreshTokenFn\n\t\t\t\t) {\n\t\t\t\t\treturn authRequestInfo.refreshTokenFn();\n\t\t\t\t}\n\t\t\t\treturn authRequestInfo.accessToken;\n\t\t\t},\n\t\t\tserver,\n\t\t\tclientConfig,\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t);\n\t};\n\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\tconst getWebsocketTokenStub = (_options: OdspResourceTokenFetchOptions) => Promise.resolve(\"\");\n\tconst odspDocumentServiceFactory = new odsp.OdspDocumentServiceFactory(\n\t\tgetStorageTokenStub,\n\t\tgetWebsocketTokenStub,\n\t\tundefined,\n\t\t{\n\t\t\topsBatchSize: 20000,\n\t\t\tconcurrentOpsBatches: 4,\n\t\t},\n\t);\n\treturn odspDocumentServiceFactory.createDocumentService(odspResolvedUrl);\n}\n\nasync function initializeR11s(server: string, pathname: string, r11sResolvedUrl: IResolvedUrl) {\n\tconst path = pathname.split(\"/\");\n\tlet tenantId: string;\n\tlet documentId: string;\n\tif (server === \"localhost\" && path.length < 4) {\n\t\ttenantId = \"fluid\";\n\t\tdocumentId = path[2];\n\t} else {\n\t\ttenantId = path[2];\n\t\tdocumentId = path[3];\n\t}\n\n\t// Latest version id is the documentId for r11s\n\tlatestVersionsId = documentId;\n\n\tconnectionInfo = {\n\t\tserver,\n\t\ttenantId,\n\t\tid: documentId,\n\t};\n\n\tif (localDataOnly) {\n\t\treturn;\n\t}\n\n\tconsole.log(`Connecting to r11s: tenantId=${tenantId} id:${documentId}`);\n\tconst tokenProvider = new r11s.DefaultTokenProvider(paramJWT);\n\tconst r11sDocumentServiceFactory = new r11s.RouterliciousDocumentServiceFactory(tokenProvider);\n\treturn r11sDocumentServiceFactory.createDocumentService(r11sResolvedUrl);\n}\n\ninterface IResolvedInfo {\n\tresolvedUrl: IResolvedUrl;\n\tserviceType: \"odsp\" | \"r11s\";\n}\nasync function resolveUrl(url: string): Promise<IResolvedInfo | undefined> {\n\tconst request: IRequest = { url };\n\tlet maybeResolvedUrl: IResolvedUrl | undefined;\n\n\t// Try each url resolver in turn to figure out which one the request is compatible with.\n\tmaybeResolvedUrl = await new OdspUrlResolver().resolve(request);\n\tif (maybeResolvedUrl !== undefined) {\n\t\treturn {\n\t\t\tresolvedUrl: maybeResolvedUrl,\n\t\t\tserviceType: \"odsp\",\n\t\t};\n\t}\n\n\tmaybeResolvedUrl = await new FluidAppOdspUrlResolver().resolve(request);\n\tif (maybeResolvedUrl !== undefined) {\n\t\treturn {\n\t\t\tresolvedUrl: maybeResolvedUrl,\n\t\t\tserviceType: \"odsp\",\n\t\t};\n\t}\n\n\tmaybeResolvedUrl = await new RouterliciousUrlResolver(\n\t\tundefined,\n\t\tasync () => Promise.resolve(paramJWT),\n\t\t\"\",\n\t).resolve(request);\n\tif (maybeResolvedUrl !== undefined) {\n\t\treturn {\n\t\t\tresolvedUrl: maybeResolvedUrl,\n\t\t\tserviceType: \"r11s\",\n\t\t};\n\t}\n\n\treturn undefined;\n}\n\nexport async function fluidFetchInit(urlStr: string) {\n\tconst resolvedInfo = await resolveUrl(urlStr);\n\tif (resolvedInfo === undefined) {\n\t\tthrow new Error(`Unknown URL ${urlStr}`);\n\t}\n\tconst fluidResolvedUrl = resolvedInfo.resolvedUrl;\n\tif (resolvedInfo.serviceType === \"odsp\") {\n\t\tconst odspResolvedUrl = fluidResolvedUrl as IOdspResolvedUrl;\n\t\treturn initializeODSPCore(\n\t\t\todspResolvedUrl,\n\t\t\tnew URL(odspResolvedUrl.siteUrl).host,\n\t\t\tgetMicrosoftConfiguration(),\n\t\t);\n\t} else if (resolvedInfo.serviceType === \"r11s\") {\n\t\tconst url = new URL(urlStr);\n\t\tconst server = url.hostname.toLowerCase();\n\t\treturn initializeR11s(server, url.pathname, fluidResolvedUrl);\n\t}\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentService } from "@fluidframework/driver-definitions/internal";
6
+ export declare function fluidFetchMessages(documentService?: IDocumentService, saveDir?: string): Promise<void>;
7
+ //# sourceMappingURL=fluidFetchMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluidFetchMessages.d.ts","sourceRoot":"","sources":["../src/fluidFetchMessages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAsQ/E,wBAAsB,kBAAkB,CAAC,eAAe,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,MAAM,iBAgC5F"}
@@ -0,0 +1,225 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import fs from "fs";
6
+ import { assert } from "@fluidframework/core-utils/internal";
7
+ import { MessageType, ScopeType, } from "@fluidframework/protocol-definitions";
8
+ import { printMessageStats } from "./fluidAnalyzeMessages.js";
9
+ import { connectToWebSocket, dumpMessageStats, dumpMessages, messageTypeFilter, overWrite, paramActualFormatting, } from "./fluidFetchArgs.js";
10
+ function filenameFromIndex(index) {
11
+ return index === 0 ? "" : index.toString(); // support old tools...
12
+ }
13
+ let firstAvailableDelta = 1;
14
+ async function* loadAllSequencedMessages(documentService, dir, files) {
15
+ let lastSeq = 0;
16
+ // flag for mismatch between last sequence number read and new one to be read
17
+ let seqNumMismatch = false;
18
+ // If we have local save, read ops from there first
19
+ if (files !== undefined) {
20
+ for (let i = 0; i < files.length; i++) {
21
+ const file = filenameFromIndex(i);
22
+ try {
23
+ console.log(`reading messages${file}.json`);
24
+ const fileContent = fs.readFileSync(`${dir}/messages${file}.json`, {
25
+ encoding: "utf-8",
26
+ });
27
+ const messages = JSON.parse(fileContent);
28
+ // check if there is mismatch
29
+ seqNumMismatch = messages[0].sequenceNumber !== lastSeq + 1;
30
+ assert(!seqNumMismatch, 0x1b9 /* "Unexpected value for sequence number of first message in file" */);
31
+ lastSeq = messages[messages.length - 1].sequenceNumber;
32
+ yield messages;
33
+ }
34
+ catch (e) {
35
+ if (seqNumMismatch) {
36
+ if (overWrite) {
37
+ // with overWrite option on, we will delete all exisintg message.json files
38
+ for (let index = 0; index < files.length; index++) {
39
+ const name = filenameFromIndex(index);
40
+ fs.unlinkSync(`${dir}/messages${name}.json`);
41
+ }
42
+ break;
43
+ }
44
+ // prompt user to back up and delete existing files
45
+ console.error("There are deleted ops in the document being requested," +
46
+ " please back up the existing messages.json file and delete it from its directory." +
47
+ " Then try fetch tool again.");
48
+ console.error(e);
49
+ return;
50
+ }
51
+ else {
52
+ console.error(`Error reading / parsing messages from ${files}`);
53
+ console.error(e);
54
+ return;
55
+ }
56
+ }
57
+ }
58
+ if (lastSeq !== 0) {
59
+ console.log(`Read ${lastSeq} ops from local cache`);
60
+ }
61
+ }
62
+ if (!documentService) {
63
+ return;
64
+ }
65
+ const deltaStorage = await documentService.connectToDeltaStorage();
66
+ let timeStart = Date.now();
67
+ let requests = 0;
68
+ let opsStorage = 0;
69
+ // reading only 1 op to test if there is mismatch
70
+ const teststream = deltaStorage.fetchMessages(lastSeq + 1, lastSeq + 2);
71
+ let statusCode;
72
+ let innerMostErrorCode;
73
+ let response;
74
+ try {
75
+ await teststream.read();
76
+ }
77
+ catch (error) {
78
+ statusCode = error.getTelemetryProperties().statusCode;
79
+ innerMostErrorCode = error.getTelemetryProperties().innerMostErrorCode;
80
+ // if there is gap between ops, catch the error and check it is the error we need
81
+ if (statusCode !== 410 || innerMostErrorCode !== "fluidDeltaDataNotAvailable") {
82
+ throw error;
83
+ }
84
+ // get firstAvailableDelta from the error response, and set current sequence number to that
85
+ response = JSON.parse(error.getTelemetryProperties().response);
86
+ firstAvailableDelta = response.error.firstAvailableDelta;
87
+ lastSeq = firstAvailableDelta - 1;
88
+ }
89
+ // continue reading rest of the ops
90
+ const stream = deltaStorage.fetchMessages(lastSeq + 1, // inclusive left
91
+ undefined);
92
+ while (true) {
93
+ const result = await stream.read();
94
+ if (result.done) {
95
+ break;
96
+ }
97
+ requests++;
98
+ const messages = result.value;
99
+ // Empty buckets should never be returned
100
+ assert(messages.length !== 0, 0x1ba /* "should not return empty buckets" */);
101
+ // console.log(`Loaded ops at ${messages[0].sequenceNumber}`);
102
+ // This parsing of message contents happens in delta manager. But when we analyze messages
103
+ // for message stats, we skip that path. So parsing of json contents needs to happen here.
104
+ for (const message of messages) {
105
+ if (typeof message.contents === "string" &&
106
+ message.contents !== "" &&
107
+ message.type !== MessageType.ClientLeave) {
108
+ message.contents = JSON.parse(message.contents);
109
+ }
110
+ }
111
+ opsStorage += messages.length;
112
+ lastSeq = messages[messages.length - 1].sequenceNumber;
113
+ yield messages;
114
+ }
115
+ console.log(`\n${Math.floor((Date.now() - timeStart) / 1000)} seconds to retrieve ${opsStorage} ops in ${requests} requests`);
116
+ if (connectToWebSocket) {
117
+ let logMsg = "";
118
+ const client = {
119
+ mode: "write",
120
+ permission: [],
121
+ scopes: [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite],
122
+ details: {
123
+ capabilities: { interactive: true },
124
+ },
125
+ user: { id: "blah" },
126
+ };
127
+ console.log("Retrieving messages from web socket");
128
+ timeStart = Date.now();
129
+ const deltaStream = await documentService.connectToDeltaStream(client);
130
+ const initialMessages = deltaStream.initialMessages;
131
+ deltaStream.dispose();
132
+ console.log(`${Math.floor((Date.now() - timeStart) / 1000)} seconds to connect to web socket`);
133
+ if (initialMessages !== undefined) {
134
+ const lastSequenceNumber = lastSeq;
135
+ const filtered = initialMessages.filter((a) => a.sequenceNumber > lastSequenceNumber);
136
+ const sorted = filtered.sort((a, b) => a.sequenceNumber - b.sequenceNumber);
137
+ lastSeq = sorted[sorted.length - 1].sequenceNumber;
138
+ logMsg = ` (${opsStorage} delta storage, ${initialMessages.length} initial ws messages, ${initialMessages.length - sorted.length} dup)`;
139
+ yield sorted;
140
+ }
141
+ console.log(`${lastSeq} total messages${logMsg}`);
142
+ }
143
+ }
144
+ async function* saveOps(gen, // AsyncGenerator<ISequencedDocumentMessage[]>,
145
+ dir, files) {
146
+ // Split into 100K ops
147
+ const chunk = 100 * 1000;
148
+ let sequencedMessages = [];
149
+ // Figure out first file we want to write to
150
+ let index = 0;
151
+ let curr = 1;
152
+ if (files.length !== 0) {
153
+ index = files.length - 1;
154
+ const name = filenameFromIndex(index);
155
+ const fileContent = fs.readFileSync(`${dir}/messages${name}.json`, { encoding: "utf-8" });
156
+ const messages = JSON.parse(fileContent);
157
+ curr = messages[0].sequenceNumber;
158
+ }
159
+ while (true) {
160
+ const result = await gen.next();
161
+ if (files.length === 0) {
162
+ curr = firstAvailableDelta;
163
+ }
164
+ if (result.done !== true) {
165
+ let messages = result.value;
166
+ yield messages;
167
+ if (messages[messages.length - 1].sequenceNumber < curr) {
168
+ // Nothing interesting.
169
+ continue;
170
+ }
171
+ if (messages[0].sequenceNumber < curr) {
172
+ messages = messages.filter((msg) => msg.sequenceNumber >= curr);
173
+ }
174
+ sequencedMessages = sequencedMessages.concat(messages);
175
+ assert(sequencedMessages[0].sequenceNumber === curr, 0x1bb /* "Unexpected sequence number on first of messages to save" */);
176
+ assert(sequencedMessages[sequencedMessages.length - 1].sequenceNumber ===
177
+ curr + sequencedMessages.length - 1, 0x1bc /* "Unexpected sequence number on last of messages to save" */);
178
+ }
179
+ // Time to write it out?
180
+ while (sequencedMessages.length >= chunk ||
181
+ (result.done === true && sequencedMessages.length !== 0)) {
182
+ const name = filenameFromIndex(index);
183
+ const write = sequencedMessages.splice(0, chunk);
184
+ console.log(`writing messages${name}.json`);
185
+ fs.writeFileSync(`${dir}/messages${name}.json`, JSON.stringify(write, undefined, paramActualFormatting ? 0 : 2));
186
+ // increment curr by chunk
187
+ curr += chunk;
188
+ assert(sequencedMessages.length === 0 || sequencedMessages[0].sequenceNumber === curr, 0x1bd /* "Stopped writing at unexpected sequence number" */);
189
+ index++;
190
+ }
191
+ if (result.done === true) {
192
+ break;
193
+ }
194
+ }
195
+ }
196
+ export async function fluidFetchMessages(documentService, saveDir) {
197
+ const messageStats = dumpMessageStats || dumpMessages;
198
+ if (!messageStats && (saveDir === undefined || documentService === undefined)) {
199
+ return;
200
+ }
201
+ const files = saveDir === undefined
202
+ ? undefined
203
+ : fs
204
+ .readdirSync(saveDir)
205
+ .filter((file) => {
206
+ if (!file.startsWith("messages")) {
207
+ return false;
208
+ }
209
+ return true;
210
+ })
211
+ .sort((a, b) => a.localeCompare(b));
212
+ let generator = loadAllSequencedMessages(documentService, saveDir, files);
213
+ if (saveDir !== undefined && files !== undefined && documentService) {
214
+ generator = saveOps(generator, saveDir, files);
215
+ }
216
+ if (messageStats) {
217
+ return printMessageStats(generator, dumpMessageStats, dumpMessages, messageTypeFilter);
218
+ }
219
+ else {
220
+ let item;
221
+ for await (item of generator) {
222
+ }
223
+ }
224
+ }
225
+ //# sourceMappingURL=fluidFetchMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluidFetchMessages.js","sourceRoot":"","sources":["../src/fluidFetchMessages.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAGN,WAAW,EACX,SAAS,GACT,MAAM,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C,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAExC,IAAI,SAAS,GAAG,wBAAwB,CAAC,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAE1E,IAAI,OAAO,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,eAAe,EAAE;QACpE,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;KAC/C;IAED,IAAI,YAAY,EAAE;QACjB,OAAO,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC;KACvF;SAAM;QACN,IAAI,IAAI,CAAC;QACT,IAAI,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE;SAC7B;KACD;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IDocumentService } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIClient,\n\tISequencedDocumentMessage,\n\tMessageType,\n\tScopeType,\n} from \"@fluidframework/protocol-definitions\";\n\nimport { printMessageStats } from \"./fluidAnalyzeMessages.js\";\nimport {\n\tconnectToWebSocket,\n\tdumpMessageStats,\n\tdumpMessages,\n\tmessageTypeFilter,\n\toverWrite,\n\tparamActualFormatting,\n} from \"./fluidFetchArgs.js\";\n\nfunction filenameFromIndex(index: number): string {\n\treturn index === 0 ? \"\" : index.toString(); // support old tools...\n}\n\nlet firstAvailableDelta = 1;\nasync function* loadAllSequencedMessages(\n\tdocumentService?: IDocumentService,\n\tdir?: string,\n\tfiles?: string[],\n) {\n\tlet lastSeq = 0;\n\t// flag for mismatch between last sequence number read and new one to be read\n\tlet seqNumMismatch = false;\n\n\t// If we have local save, read ops from there first\n\tif (files !== undefined) {\n\t\tfor (let i = 0; i < files.length; i++) {\n\t\t\tconst file = filenameFromIndex(i);\n\t\t\ttry {\n\t\t\t\tconsole.log(`reading messages${file}.json`);\n\t\t\t\tconst fileContent = fs.readFileSync(`${dir}/messages${file}.json`, {\n\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t});\n\t\t\t\tconst messages: ISequencedDocumentMessage[] = JSON.parse(fileContent);\n\t\t\t\t// check if there is mismatch\n\t\t\t\tseqNumMismatch = messages[0].sequenceNumber !== lastSeq + 1;\n\t\t\t\tassert(\n\t\t\t\t\t!seqNumMismatch,\n\t\t\t\t\t0x1b9 /* \"Unexpected value for sequence number of first message in file\" */,\n\t\t\t\t);\n\t\t\t\tlastSeq = messages[messages.length - 1].sequenceNumber;\n\t\t\t\tyield messages;\n\t\t\t} catch (e) {\n\t\t\t\tif (seqNumMismatch) {\n\t\t\t\t\tif (overWrite) {\n\t\t\t\t\t\t// with overWrite option on, we will delete all exisintg message.json files\n\t\t\t\t\t\tfor (let index = 0; index < files.length; index++) {\n\t\t\t\t\t\t\tconst name = filenameFromIndex(index);\n\t\t\t\t\t\t\tfs.unlinkSync(`${dir}/messages${name}.json`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// prompt user to back up and delete existing files\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\"There are deleted ops in the document being requested,\" +\n\t\t\t\t\t\t\t\" please back up the existing messages.json file and delete it from its directory.\" +\n\t\t\t\t\t\t\t\" Then try fetch tool again.\",\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\tconsole.error(`Error reading / parsing messages from ${files}`);\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (lastSeq !== 0) {\n\t\t\tconsole.log(`Read ${lastSeq} ops from local cache`);\n\t\t}\n\t}\n\n\tif (!documentService) {\n\t\treturn;\n\t}\n\n\tconst deltaStorage = await documentService.connectToDeltaStorage();\n\n\tlet timeStart = Date.now();\n\tlet requests = 0;\n\tlet opsStorage = 0;\n\n\t// reading only 1 op to test if there is mismatch\n\tconst teststream = deltaStorage.fetchMessages(lastSeq + 1, lastSeq + 2);\n\n\tlet statusCode;\n\tlet innerMostErrorCode;\n\tlet response;\n\n\ttry {\n\t\tawait teststream.read();\n\t} catch (error: any) {\n\t\tstatusCode = error.getTelemetryProperties().statusCode;\n\t\tinnerMostErrorCode = error.getTelemetryProperties().innerMostErrorCode;\n\t\t// if there is gap between ops, catch the error and check it is the error we need\n\t\tif (statusCode !== 410 || innerMostErrorCode !== \"fluidDeltaDataNotAvailable\") {\n\t\t\tthrow error;\n\t\t}\n\t\t// get firstAvailableDelta from the error response, and set current sequence number to that\n\t\tresponse = JSON.parse(error.getTelemetryProperties().response);\n\t\tfirstAvailableDelta = response.error.firstAvailableDelta;\n\t\tlastSeq = firstAvailableDelta - 1;\n\t}\n\n\t// continue reading rest of the ops\n\tconst stream = deltaStorage.fetchMessages(\n\t\tlastSeq + 1, // inclusive left\n\t\tundefined, // to\n\t);\n\n\twhile (true) {\n\t\tconst result = await stream.read();\n\t\tif (result.done) {\n\t\t\tbreak;\n\t\t}\n\t\trequests++;\n\t\tconst messages = result.value;\n\n\t\t// Empty buckets should never be returned\n\t\tassert(messages.length !== 0, 0x1ba /* \"should not return empty buckets\" */);\n\t\t// console.log(`Loaded ops at ${messages[0].sequenceNumber}`);\n\n\t\t// This parsing of message contents happens in delta manager. But when we analyze messages\n\t\t// for message stats, we skip that path. So parsing of json contents needs to happen here.\n\t\tfor (const message of messages) {\n\t\t\tif (\n\t\t\t\ttypeof message.contents === \"string\" &&\n\t\t\t\tmessage.contents !== \"\" &&\n\t\t\t\tmessage.type !== MessageType.ClientLeave\n\t\t\t) {\n\t\t\t\tmessage.contents = JSON.parse(message.contents);\n\t\t\t}\n\t\t}\n\n\t\topsStorage += messages.length;\n\t\tlastSeq = messages[messages.length - 1].sequenceNumber;\n\t\tyield messages;\n\t}\n\n\tconsole.log(\n\t\t`\\n${Math.floor(\n\t\t\t(Date.now() - timeStart) / 1000,\n\t\t)} seconds to retrieve ${opsStorage} ops in ${requests} requests`,\n\t);\n\n\tif (connectToWebSocket) {\n\t\tlet logMsg = \"\";\n\t\tconst client: IClient = {\n\t\t\tmode: \"write\",\n\t\t\tpermission: [],\n\t\t\tscopes: [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite],\n\t\t\tdetails: {\n\t\t\t\tcapabilities: { interactive: true },\n\t\t\t},\n\t\t\tuser: { id: \"blah\" },\n\t\t};\n\t\tconsole.log(\"Retrieving messages from web socket\");\n\t\ttimeStart = Date.now();\n\t\tconst deltaStream = await documentService.connectToDeltaStream(client);\n\t\tconst initialMessages = deltaStream.initialMessages;\n\t\tdeltaStream.dispose();\n\t\tconsole.log(\n\t\t\t`${Math.floor((Date.now() - timeStart) / 1000)} seconds to connect to web socket`,\n\t\t);\n\n\t\tif (initialMessages !== undefined) {\n\t\t\tconst lastSequenceNumber = lastSeq;\n\t\t\tconst filtered = initialMessages.filter((a) => a.sequenceNumber > lastSequenceNumber);\n\t\t\tconst sorted = filtered.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n\t\t\tlastSeq = sorted[sorted.length - 1].sequenceNumber;\n\t\t\tlogMsg = ` (${opsStorage} delta storage, ${\n\t\t\t\tinitialMessages.length\n\t\t\t} initial ws messages, ${initialMessages.length - sorted.length} dup)`;\n\t\t\tyield sorted;\n\t\t}\n\t\tconsole.log(`${lastSeq} total messages${logMsg}`);\n\t}\n}\n\nasync function* saveOps(\n\tgen, // AsyncGenerator<ISequencedDocumentMessage[]>,\n\tdir: string,\n\tfiles: string[],\n) {\n\t// Split into 100K ops\n\tconst chunk = 100 * 1000;\n\n\tlet sequencedMessages: ISequencedDocumentMessage[] = [];\n\n\t// Figure out first file we want to write to\n\tlet index = 0;\n\tlet curr: number = 1;\n\tif (files.length !== 0) {\n\t\tindex = files.length - 1;\n\t\tconst name = filenameFromIndex(index);\n\t\tconst fileContent = fs.readFileSync(`${dir}/messages${name}.json`, { encoding: \"utf-8\" });\n\t\tconst messages: ISequencedDocumentMessage[] = JSON.parse(fileContent);\n\t\tcurr = messages[0].sequenceNumber;\n\t}\n\n\twhile (true) {\n\t\tconst result: IteratorResult<ISequencedDocumentMessage[]> = await gen.next();\n\t\tif (files.length === 0) {\n\t\t\tcurr = firstAvailableDelta;\n\t\t}\n\t\tif (result.done !== true) {\n\t\t\tlet messages = result.value;\n\t\t\tyield messages;\n\t\t\tif (messages[messages.length - 1].sequenceNumber < curr) {\n\t\t\t\t// Nothing interesting.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (messages[0].sequenceNumber < curr) {\n\t\t\t\tmessages = messages.filter((msg) => msg.sequenceNumber >= curr);\n\t\t\t}\n\t\t\tsequencedMessages = sequencedMessages.concat(messages);\n\t\t\tassert(\n\t\t\t\tsequencedMessages[0].sequenceNumber === curr,\n\t\t\t\t0x1bb /* \"Unexpected sequence number on first of messages to save\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tsequencedMessages[sequencedMessages.length - 1].sequenceNumber ===\n\t\t\t\t\tcurr + sequencedMessages.length - 1,\n\t\t\t\t0x1bc /* \"Unexpected sequence number on last of messages to save\" */,\n\t\t\t);\n\t\t}\n\n\t\t// Time to write it out?\n\t\twhile (\n\t\t\tsequencedMessages.length >= chunk ||\n\t\t\t(result.done === true && sequencedMessages.length !== 0)\n\t\t) {\n\t\t\tconst name = filenameFromIndex(index);\n\t\t\tconst write = sequencedMessages.splice(0, chunk);\n\t\t\tconsole.log(`writing messages${name}.json`);\n\t\t\tfs.writeFileSync(\n\t\t\t\t`${dir}/messages${name}.json`,\n\t\t\t\tJSON.stringify(write, undefined, paramActualFormatting ? 0 : 2),\n\t\t\t);\n\t\t\t// increment curr by chunk\n\t\t\tcurr += chunk;\n\t\t\tassert(\n\t\t\t\tsequencedMessages.length === 0 || sequencedMessages[0].sequenceNumber === curr,\n\t\t\t\t0x1bd /* \"Stopped writing at unexpected sequence number\" */,\n\t\t\t);\n\t\t\tindex++;\n\t\t}\n\n\t\tif (result.done === true) {\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nexport async function fluidFetchMessages(documentService?: IDocumentService, saveDir?: string) {\n\tconst messageStats = dumpMessageStats || dumpMessages;\n\tif (!messageStats && (saveDir === undefined || documentService === undefined)) {\n\t\treturn;\n\t}\n\n\tconst files =\n\t\tsaveDir === undefined\n\t\t\t? undefined\n\t\t\t: fs\n\t\t\t\t\t.readdirSync(saveDir)\n\t\t\t\t\t.filter((file) => {\n\t\t\t\t\t\tif (!file.startsWith(\"messages\")) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t})\n\t\t\t\t\t.sort((a, b) => a.localeCompare(b));\n\n\tlet generator = loadAllSequencedMessages(documentService, saveDir, files);\n\n\tif (saveDir !== undefined && files !== undefined && documentService) {\n\t\tgenerator = saveOps(generator, saveDir, files);\n\t}\n\n\tif (messageStats) {\n\t\treturn printMessageStats(generator, dumpMessageStats, dumpMessages, messageTypeFilter);\n\t} else {\n\t\tlet item;\n\t\tfor await (item of generator) {\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IClientConfig, IOdspAuthRequestInfo, IOdspDriveItem } from "@fluidframework/odsp-doclib-utils/internal";
6
+ export declare function resolveWrapper<T>(callback: (authRequestInfo: IOdspAuthRequestInfo) => Promise<T>, server: string, clientConfig: IClientConfig, forceTokenReauth?: boolean, forToken?: boolean): Promise<T>;
7
+ export declare function getSharepointFiles(server: string, serverRelativePath: string, recurse: boolean): Promise<IOdspDriveItem[]>;
8
+ export declare function getSingleSharePointFile(server: string, drive: string, item: string): Promise<IOdspDriveItem>;
9
+ //# sourceMappingURL=fluidFetchSharePoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluidFetchSharePoint.d.ts","sourceRoot":"","sources":["../src/fluidFetchSharePoint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,cAAc,EAKd,MAAM,4CAA4C,CAAC;AAWpD,wBAAsB,cAAc,CAAC,CAAC,EACrC,QAAQ,EAAE,CAAC,eAAe,EAAE,oBAAoB,KAAK,OAAO,CAAC,CAAC,CAAC,EAC/D,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,aAAa,EAC3B,gBAAgB,UAAQ,EACxB,QAAQ,UAAQ,GACd,OAAO,CAAC,CAAC,CAAC,CAoCZ;AA6BD,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,MAAM,EAC1B,OAAO,EAAE,OAAO,6BAsChB;AAED,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,2BASxF"}
@@ -0,0 +1,100 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import child_process from "child_process";
6
+ import { DriverErrorTypes } from "@fluidframework/driver-definitions";
7
+ import { getChildrenByDriveItem, getDriveItemByServerRelativePath, getDriveItemFromDriveAndItem, getOdspRefreshTokenFn, } from "@fluidframework/odsp-doclib-utils/internal";
8
+ import { OdspTokenManager, getMicrosoftConfiguration, odspTokensCache, } from "@fluidframework/tool-utils/internal";
9
+ import { getForceTokenReauth } from "./fluidFetchArgs.js";
10
+ export async function resolveWrapper(callback, server, clientConfig, forceTokenReauth = false, forToken = false) {
11
+ try {
12
+ const odspTokenManager = new OdspTokenManager(odspTokensCache);
13
+ const tokenConfig = {
14
+ type: "browserLogin",
15
+ navigator: fluidFetchWebNavigator,
16
+ };
17
+ const tokens = await odspTokenManager.getOdspTokens(server, clientConfig, tokenConfig, undefined /* forceRefresh */, forceTokenReauth || getForceTokenReauth());
18
+ const result = await callback({
19
+ accessToken: tokens.accessToken,
20
+ refreshTokenFn: getOdspRefreshTokenFn(server, clientConfig, tokens),
21
+ });
22
+ // If this is used for getting a token, then refresh the cache with new token.
23
+ if (forToken) {
24
+ const key = { isPush: false, userOrServer: server };
25
+ await odspTokenManager.updateTokensCache(key, {
26
+ accessToken: result,
27
+ refreshToken: tokens.refreshToken,
28
+ });
29
+ return result;
30
+ }
31
+ return result;
32
+ }
33
+ catch (e) {
34
+ if (e.errorType === DriverErrorTypes.authorizationError && !forceTokenReauth) {
35
+ // Re-auth
36
+ return resolveWrapper(callback, server, clientConfig, true, forToken);
37
+ }
38
+ throw e;
39
+ }
40
+ }
41
+ async function resolveDriveItemByServerRelativePath(server, serverRelativePath, clientConfig) {
42
+ return resolveWrapper(
43
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
44
+ (authRequestInfo) => getDriveItemByServerRelativePath(server, serverRelativePath, authRequestInfo, false), server, clientConfig);
45
+ }
46
+ async function resolveChildrenByDriveItem(server, folderDriveItem, clientConfig) {
47
+ return resolveWrapper(
48
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
49
+ (authRequestInfo) => getChildrenByDriveItem(folderDriveItem, server, authRequestInfo), server, clientConfig);
50
+ }
51
+ export async function getSharepointFiles(server, serverRelativePath, recurse) {
52
+ const clientConfig = getMicrosoftConfiguration();
53
+ const fileInfo = await resolveDriveItemByServerRelativePath(server, serverRelativePath, clientConfig);
54
+ console.log(fileInfo);
55
+ const pendingFolder = [];
56
+ const files = [];
57
+ if (fileInfo.isFolder) {
58
+ pendingFolder.push({ path: serverRelativePath, folder: fileInfo });
59
+ }
60
+ else {
61
+ files.push(fileInfo);
62
+ }
63
+ // eslint-disable-next-line no-constant-condition
64
+ while (true) {
65
+ const folderInfo = pendingFolder.shift();
66
+ if (!folderInfo) {
67
+ break;
68
+ }
69
+ const { path, folder } = folderInfo;
70
+ const children = await resolveChildrenByDriveItem(server, folder, clientConfig);
71
+ for (const child of children) {
72
+ const childPath = `${path}/${child.name}`;
73
+ if (child.isFolder) {
74
+ if (recurse) {
75
+ pendingFolder.push({ path: childPath, folder: child });
76
+ }
77
+ }
78
+ else {
79
+ files.push(child);
80
+ }
81
+ }
82
+ }
83
+ return files;
84
+ }
85
+ export async function getSingleSharePointFile(server, drive, item) {
86
+ const clientConfig = getMicrosoftConfiguration();
87
+ return resolveWrapper(
88
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
89
+ (authRequestInfo) => getDriveItemFromDriveAndItem(server, drive, item, authRequestInfo), server, clientConfig);
90
+ }
91
+ const fluidFetchWebNavigator = (url) => {
92
+ let message = "Please open browser and navigate to this URL:";
93
+ if (process.platform === "win32") {
94
+ child_process.exec(`start "fluid-fetch" /B "${url}"`);
95
+ message =
96
+ "Opening browser to get authorization code. If that doesn't open, please go to this URL manually";
97
+ }
98
+ console.log(`${message}\n ${url}`);
99
+ };
100
+ //# sourceMappingURL=fluidFetchSharePoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluidFetchSharePoint.js","sourceRoot":"","sources":["../src/fluidFetchSharePoint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAIN,sBAAsB,EACtB,gCAAgC,EAChC,4BAA4B,EAC5B,qBAAqB,GACrB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAGN,gBAAgB,EAChB,yBAAyB,EACzB,eAAe,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,QAA+D,EAC/D,MAAc,EACd,YAA2B,EAC3B,gBAAgB,GAAG,KAAK,EACxB,QAAQ,GAAG,KAAK;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AC,IAAI,EAAE,CAAC;YAC1C,IAAI,KAAK,CAAC,QAAQ,EAAE;gBACnB,IAAI,OAAO,EAAE;oBACZ,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;iBACvD;aACD;iBAAM;gBACN,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAClB;SACD;KACD;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,MAAc,EAAE,KAAa,EAAE,IAAY;IACxF,MAAM,YAAY,GAAG,yBAAyB,EAAE,CAAC;IAEjD,OAAO,cAAc;IACpB,qEAAqE;IACrE,CAAC,eAAe,EAAE,EAAE,CAAC,4BAA4B,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,CAAC,EACvF,MAAM,EACN,YAAY,CACZ,CAAC;AACH,CAAC;AAED,MAAM,sBAAsB,GAAG,CAAC,GAAW,EAAE,EAAE;IAC9C,IAAI,OAAO,GAAG,+CAA+C,CAAC;IAC9D,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QACjC,aAAa,CAAC,IAAI,CAAC,2BAA2B,GAAG,GAAG,CAAC,CAAC;QACtD,OAAO;YACN,kGAAkG,CAAC;KACpG;IACD,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,OAAO,GAAG,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport child_process from \"child_process\";\n\nimport { DriverErrorTypes } from \"@fluidframework/driver-definitions\";\nimport {\n\tIClientConfig,\n\tIOdspAuthRequestInfo,\n\tIOdspDriveItem,\n\tgetChildrenByDriveItem,\n\tgetDriveItemByServerRelativePath,\n\tgetDriveItemFromDriveAndItem,\n\tgetOdspRefreshTokenFn,\n} from \"@fluidframework/odsp-doclib-utils/internal\";\nimport {\n\tIOdspTokenManagerCacheKey,\n\tOdspTokenConfig,\n\tOdspTokenManager,\n\tgetMicrosoftConfiguration,\n\todspTokensCache,\n} from \"@fluidframework/tool-utils/internal\";\n\nimport { getForceTokenReauth } from \"./fluidFetchArgs.js\";\n\nexport async function resolveWrapper<T>(\n\tcallback: (authRequestInfo: IOdspAuthRequestInfo) => Promise<T>,\n\tserver: string,\n\tclientConfig: IClientConfig,\n\tforceTokenReauth = false,\n\tforToken = false,\n): Promise<T> {\n\ttry {\n\t\tconst odspTokenManager = new OdspTokenManager(odspTokensCache);\n\t\tconst tokenConfig: OdspTokenConfig = {\n\t\t\ttype: \"browserLogin\",\n\t\t\tnavigator: fluidFetchWebNavigator,\n\t\t};\n\t\tconst tokens = await odspTokenManager.getOdspTokens(\n\t\t\tserver,\n\t\t\tclientConfig,\n\t\t\ttokenConfig,\n\t\t\tundefined /* forceRefresh */,\n\t\t\tforceTokenReauth || getForceTokenReauth(),\n\t\t);\n\n\t\tconst result = await callback({\n\t\t\taccessToken: tokens.accessToken,\n\t\t\trefreshTokenFn: getOdspRefreshTokenFn(server, clientConfig, tokens),\n\t\t});\n\t\t// If this is used for getting a token, then refresh the cache with new token.\n\t\tif (forToken) {\n\t\t\tconst key: IOdspTokenManagerCacheKey = { isPush: false, userOrServer: server };\n\t\t\tawait odspTokenManager.updateTokensCache(key, {\n\t\t\t\taccessToken: result as any as string,\n\t\t\t\trefreshToken: tokens.refreshToken,\n\t\t\t});\n\t\t\treturn result;\n\t\t}\n\t\treturn result;\n\t} catch (e: any) {\n\t\tif (e.errorType === DriverErrorTypes.authorizationError && !forceTokenReauth) {\n\t\t\t// Re-auth\n\t\t\treturn resolveWrapper<T>(callback, server, clientConfig, true, forToken);\n\t\t}\n\t\tthrow e;\n\t}\n}\n\nasync function resolveDriveItemByServerRelativePath(\n\tserver: string,\n\tserverRelativePath: string,\n\tclientConfig: IClientConfig,\n) {\n\treturn resolveWrapper<IOdspDriveItem>(\n\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t(authRequestInfo) =>\n\t\t\tgetDriveItemByServerRelativePath(server, serverRelativePath, authRequestInfo, false),\n\t\tserver,\n\t\tclientConfig,\n\t);\n}\n\nasync function resolveChildrenByDriveItem(\n\tserver: string,\n\tfolderDriveItem: IOdspDriveItem,\n\tclientConfig: IClientConfig,\n) {\n\treturn resolveWrapper<IOdspDriveItem[]>(\n\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t(authRequestInfo) => getChildrenByDriveItem(folderDriveItem, server, authRequestInfo),\n\t\tserver,\n\t\tclientConfig,\n\t);\n}\n\nexport async function getSharepointFiles(\n\tserver: string,\n\tserverRelativePath: string,\n\trecurse: boolean,\n) {\n\tconst clientConfig = getMicrosoftConfiguration();\n\n\tconst fileInfo = await resolveDriveItemByServerRelativePath(\n\t\tserver,\n\t\tserverRelativePath,\n\t\tclientConfig,\n\t);\n\tconsole.log(fileInfo);\n\tconst pendingFolder: { path: string; folder: IOdspDriveItem }[] = [];\n\tconst files: IOdspDriveItem[] = [];\n\tif (fileInfo.isFolder) {\n\t\tpendingFolder.push({ path: serverRelativePath, folder: fileInfo });\n\t} else {\n\t\tfiles.push(fileInfo);\n\t}\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst folderInfo = pendingFolder.shift();\n\t\tif (!folderInfo) {\n\t\t\tbreak;\n\t\t}\n\t\tconst { path, folder } = folderInfo;\n\t\tconst children = await resolveChildrenByDriveItem(server, folder, clientConfig);\n\t\tfor (const child of children) {\n\t\t\tconst childPath = `${path}/${child.name}`;\n\t\t\tif (child.isFolder) {\n\t\t\t\tif (recurse) {\n\t\t\t\t\tpendingFolder.push({ path: childPath, folder: child });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfiles.push(child);\n\t\t\t}\n\t\t}\n\t}\n\treturn files;\n}\n\nexport async function getSingleSharePointFile(server: string, drive: string, item: string) {\n\tconst clientConfig = getMicrosoftConfiguration();\n\n\treturn resolveWrapper<IOdspDriveItem>(\n\t\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\t\t(authRequestInfo) => getDriveItemFromDriveAndItem(server, drive, item, authRequestInfo),\n\t\tserver,\n\t\tclientConfig,\n\t);\n}\n\nconst fluidFetchWebNavigator = (url: string) => {\n\tlet message = \"Please open browser and navigate to this URL:\";\n\tif (process.platform === \"win32\") {\n\t\tchild_process.exec(`start \"fluid-fetch\" /B \"${url}\"`);\n\t\tmessage =\n\t\t\t\"Opening browser to get authorization code. If that doesn't open, please go to this URL manually\";\n\t}\n\tconsole.log(`${message}\\n ${url}`);\n};\n"]}
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDocumentService } from "@fluidframework/driver-definitions/internal";
6
+ export declare function fluidFetchSnapshot(documentService?: IDocumentService, saveDir?: string): Promise<void>;
7
+ //# sourceMappingURL=fluidFetchSnapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluidFetchSnapshot.d.ts","sourceRoot":"","sources":["../src/fluidFetchSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EACN,gBAAgB,EAEhB,MAAM,6CAA6C,CAAC;AAqQrD,wBAAsB,kBAAkB,CAAC,eAAe,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,MAAM,iBAsG5F"}