@fluidframework/odsp-driver 2.0.1 → 2.0.3
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/api-report/odsp-driver.alpha.api.md +1 -1
- package/dist/createFile.d.ts +3 -3
- package/dist/createFile.d.ts.map +1 -1
- package/dist/createFile.js +11 -9
- package/dist/createFile.js.map +1 -1
- package/dist/createNewContainerOnExistingFile.d.ts +1 -1
- package/dist/createNewContainerOnExistingFile.d.ts.map +1 -1
- package/dist/createNewContainerOnExistingFile.js +2 -2
- package/dist/createNewContainerOnExistingFile.js.map +1 -1
- package/dist/createNewUtils.d.ts +1 -1
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +22 -17
- package/dist/createNewUtils.js.map +1 -1
- package/dist/fetchSnapshot.d.ts +6 -9
- package/dist/fetchSnapshot.d.ts.map +1 -1
- package/dist/fetchSnapshot.js +22 -21
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/getFileLink.js +13 -8
- package/dist/getFileLink.js.map +1 -1
- package/dist/getUrlAndHeadersWithAuth.d.ts +2 -5
- package/dist/getUrlAndHeadersWithAuth.d.ts.map +1 -1
- package/dist/getUrlAndHeadersWithAuth.js +7 -28
- package/dist/getUrlAndHeadersWithAuth.js.map +1 -1
- package/dist/odspDelayLoadedDeltaStream.d.ts +3 -4
- package/dist/odspDelayLoadedDeltaStream.d.ts.map +1 -1
- package/dist/odspDelayLoadedDeltaStream.js +4 -5
- package/dist/odspDelayLoadedDeltaStream.js.map +1 -1
- package/dist/odspDeltaStorageService.d.ts +2 -2
- package/dist/odspDeltaStorageService.d.ts.map +1 -1
- package/dist/odspDeltaStorageService.js +9 -8
- package/dist/odspDeltaStorageService.js.map +1 -1
- package/dist/odspDocumentService.d.ts +4 -4
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js +9 -9
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +6 -4
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +2 -2
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +25 -19
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspSummaryUploadManager.d.ts +2 -3
- package/dist/odspSummaryUploadManager.d.ts.map +1 -1
- package/dist/odspSummaryUploadManager.js +6 -5
- package/dist/odspSummaryUploadManager.js.map +1 -1
- package/dist/odspUtils.d.ts +11 -3
- package/dist/odspUtils.d.ts.map +1 -1
- package/dist/odspUtils.js +10 -6
- package/dist/odspUtils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/prefetchLatestSnapshot.d.ts +1 -1
- package/dist/prefetchLatestSnapshot.d.ts.map +1 -1
- package/dist/prefetchLatestSnapshot.js +5 -5
- package/dist/prefetchLatestSnapshot.js.map +1 -1
- package/dist/vroom.d.ts +2 -2
- package/dist/vroom.d.ts.map +1 -1
- package/dist/vroom.js +7 -9
- package/dist/vroom.js.map +1 -1
- package/lib/createFile.d.ts +3 -3
- package/lib/createFile.d.ts.map +1 -1
- package/lib/createFile.js +12 -10
- package/lib/createFile.js.map +1 -1
- package/lib/createNewContainerOnExistingFile.d.ts +1 -1
- package/lib/createNewContainerOnExistingFile.d.ts.map +1 -1
- package/lib/createNewContainerOnExistingFile.js +2 -2
- package/lib/createNewContainerOnExistingFile.js.map +1 -1
- package/lib/createNewUtils.d.ts +1 -1
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +23 -18
- package/lib/createNewUtils.js.map +1 -1
- package/lib/fetchSnapshot.d.ts +6 -9
- package/lib/fetchSnapshot.d.ts.map +1 -1
- package/lib/fetchSnapshot.js +23 -22
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/getFileLink.js +14 -9
- package/lib/getFileLink.js.map +1 -1
- package/lib/getUrlAndHeadersWithAuth.d.ts +2 -5
- package/lib/getUrlAndHeadersWithAuth.d.ts.map +1 -1
- package/lib/getUrlAndHeadersWithAuth.js +5 -26
- package/lib/getUrlAndHeadersWithAuth.js.map +1 -1
- package/lib/odspDelayLoadedDeltaStream.d.ts +3 -4
- package/lib/odspDelayLoadedDeltaStream.d.ts.map +1 -1
- package/lib/odspDelayLoadedDeltaStream.js +4 -5
- package/lib/odspDelayLoadedDeltaStream.js.map +1 -1
- package/lib/odspDeltaStorageService.d.ts +2 -2
- package/lib/odspDeltaStorageService.d.ts.map +1 -1
- package/lib/odspDeltaStorageService.js +9 -8
- package/lib/odspDeltaStorageService.js.map +1 -1
- package/lib/odspDocumentService.d.ts +4 -4
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +9 -9
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +6 -4
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +2 -2
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +26 -20
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspSummaryUploadManager.d.ts +2 -3
- package/lib/odspSummaryUploadManager.d.ts.map +1 -1
- package/lib/odspSummaryUploadManager.js +7 -6
- package/lib/odspSummaryUploadManager.js.map +1 -1
- package/lib/odspUtils.d.ts +11 -3
- package/lib/odspUtils.d.ts.map +1 -1
- package/lib/odspUtils.js +11 -7
- package/lib/odspUtils.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/prefetchLatestSnapshot.d.ts +1 -1
- package/lib/prefetchLatestSnapshot.d.ts.map +1 -1
- package/lib/prefetchLatestSnapshot.js +5 -5
- package/lib/prefetchLatestSnapshot.js.map +1 -1
- package/lib/vroom.d.ts +2 -2
- package/lib/vroom.d.ts.map +1 -1
- package/lib/vroom.js +7 -9
- package/lib/vroom.js.map +1 -1
- package/package.json +11 -11
- package/src/createFile.ts +15 -21
- package/src/createNewContainerOnExistingFile.ts +2 -2
- package/src/createNewUtils.ts +32 -24
- package/src/fetchSnapshot.ts +35 -34
- package/src/getFileLink.ts +26 -20
- package/src/getUrlAndHeadersWithAuth.ts +6 -31
- package/src/odspDelayLoadedDeltaStream.ts +4 -5
- package/src/odspDeltaStorageService.ts +11 -7
- package/src/odspDocumentService.ts +8 -8
- package/src/odspDocumentServiceFactoryCore.ts +5 -3
- package/src/odspDocumentStorageManager.ts +36 -33
- package/src/odspSummaryUploadManager.ts +9 -9
- package/src/odspUtils.ts +19 -6
- package/src/packageVersion.ts +1 -1
- package/src/prefetchLatestSnapshot.ts +9 -5
- package/src/vroom.ts +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkE;AAClE,kEAA8E;AAC9E,2EAA8F;AAE9F,oEAG+C;AAE/C,uEAKkD;AAWlD,+EAAyE;AACzE,iDAA6D;AAE7D;;;GAGG;AACH,MAAa,wBAAwB;IAKpC,YACkB,WAAmB,EACnB,eAAgD,EACjE,MAA2B,EACV,YAA0B,EAC1B,sCAA+C,EAC/C,8BAAwD;QALxD,gBAAW,GAAX,WAAW,CAAQ;QACnB,oBAAe,GAAf,eAAe,CAAiC;QAEhD,iBAAY,GAAZ,YAAY,CAAc;QAC1B,2CAAsC,GAAtC,sCAAsC,CAAS;QAC/C,mCAA8B,GAA9B,8BAA8B,CAA0B;QAEzE,IAAI,CAAC,EAAE,GAAG,IAAA,oCAAyB,EAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,gBAA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I,EAAE,CACxD,CAAC;gBACH,CAAC;YACF,CAAC;YAED,MAAM,SAAS,GAA8B;gBAC5C,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;gBAC7B,IAAI,EAAE,IAAA,qBAAU,EAAC,aAAa,CAAC;aAC/B,CAAC;YAEF,IAAI,KAA2B,CAAC;YAEhC,IAAI,KAAK,EAAE,CAAC;gBACX,IAAA,iBAAM,EACL,EAAE,KAAK,SAAS,EAChB,KAAK,CAAC,iEAAiE,CACvE,CAAC;gBACF,KAAK,GAAG;oBACP,KAAK;oBACL,GAAG,SAAS;oBACZ,YAAY;oBACZ,OAAO;iBACP,CAAC;YACH,CAAC;iBAAM,IAAI,EAAE,EAAE,CAAC;gBACf,KAAK,GAAG;oBACP,GAAG,SAAS;oBACZ,EAAE;iBACF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;YACjE,CAAC;YAED,YAAY,CAAC,OAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACD;AA/OD,4DA+OC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryTree, SummaryType, SummaryObject } from \"@fluidframework/driver-definitions\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tgetGitType,\n\tisCombinedAppAndProtocolSummary,\n} from \"@fluidframework/driver-utils/internal\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tIOdspSummaryPayload,\n\tIOdspSummaryTree,\n\tIOdspSummaryTreeBaseEntry,\n\tIWriteSummaryResponse,\n\tOdspSummaryTreeEntry,\n\tOdspSummaryTreeValue,\n} from \"./contracts.js\";\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth.js\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils.js\";\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n\t// Last proposed handle of the uploaded app summary.\n\tprivate lastSummaryProposalHandle: string | undefined;\n\tprivate readonly mc: MonitoringContext;\n\n\tconstructor(\n\t\tprivate readonly snapshotUrl: string,\n\t\tprivate readonly getStorageToken: InstrumentedStorageTokenFetcher,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly epochTracker: EpochTracker,\n\t\tprivate readonly forceAccessTokenViaAuthorizationHeader: boolean,\n\t\tprivate readonly relayServiceTenantAndSessionId: () => string | undefined,\n\t) {\n\t\tthis.mc = loggerToMonitoringContext(logger);\n\t}\n\n\tpublic async writeSummaryTree(\n\t\ttree: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\t// If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n\t\t// then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n\t\t// Don't bother logging if lastSummaryProposalHandle hasn't been set before; only log on a positive mismatch.\n\t\tif (\n\t\t\tthis.lastSummaryProposalHandle !== undefined &&\n\t\t\tthis.lastSummaryProposalHandle !== context.proposalHandle\n\t\t) {\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"LastSummaryProposedHandleMismatch\",\n\t\t\t\tackedSummaryProposedHandle: context.proposalHandle,\n\t\t\t\tlastSummaryProposalHandle: this.lastSummaryProposalHandle,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.writeSummaryTreeCore(\n\t\t\tcontext.ackHandle,\n\t\t\tcontext.referenceSequenceNumber,\n\t\t\ttree,\n\t\t);\n\t\tconst id = result ? result.id : undefined;\n\t\tif (!result || !id) {\n\t\t\tthrow new Error(`Failed to write summary tree`);\n\t\t}\n\t\tthis.lastSummaryProposalHandle = id;\n\t\treturn id;\n\t}\n\n\tprivate async writeSummaryTreeCore(\n\t\tparentHandle: string | undefined,\n\t\treferenceSequenceNumber: number,\n\t\ttree: ISummaryTree,\n\t): Promise<IWriteSummaryResponse> {\n\t\tconst containsProtocolTree = isCombinedAppAndProtocolSummary(tree);\n\t\tconst { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n\t\t\tparentHandle,\n\t\t\ttree,\n\t\t\t\".app\",\n\t\t);\n\t\tconst snapshot: IOdspSummaryPayload = {\n\t\t\tentries: snapshotTree.entries!,\n\t\t\tmessage: \"app\",\n\t\t\tsequenceNumber: referenceSequenceNumber,\n\t\t\t// no ack handle implies this is initial summary after empty file creation.\n\t\t\t// send container payload so server will use it without a summary op\n\t\t\ttype: containsProtocolTree || parentHandle === undefined ? \"container\" : \"channel\",\n\t\t};\n\n\t\treturn getWithRetryForTokenRefresh(async (options) => {\n\t\t\tconst storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n\t\t\tconst { url, headers } = getUrlAndHeadersWithAuth(\n\t\t\t\t`${this.snapshotUrl}/snapshot`,\n\t\t\t\tstorageToken,\n\t\t\t\tthis.forceAccessTokenViaAuthorizationHeader,\n\t\t\t);\n\t\t\theaders[\"Content-Type\"] = \"application/json\";\n\t\t\tconst relayServiceTenantAndSessionId = this.relayServiceTenantAndSessionId();\n\t\t\t// This would be undefined in case of summary is uploaded in detached container with attachment\n\t\t\t// blobs flow where summary is uploaded without connecting to push.\n\t\t\tif (relayServiceTenantAndSessionId !== undefined) {\n\t\t\t\theaders[\"If-Match\"] = `fluid:sessionid=${relayServiceTenantAndSessionId}${\n\t\t\t\t\tparentHandle ? `;containerid=${parentHandle}` : \"\"\n\t\t\t\t}`;\n\t\t\t}\n\n\t\t\tconst postBody = JSON.stringify(snapshot);\n\n\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.mc.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"uploadSummary\",\n\t\t\t\t\tattempt: options.refresh ? 2 : 1,\n\t\t\t\t\thasClaims: !!options.claims,\n\t\t\t\t\thasTenantId: !!options.tenantId,\n\t\t\t\t\tblobs,\n\t\t\t\t\tsize: postBody.length,\n\t\t\t\t\treferenceSequenceNumber,\n\t\t\t\t\ttype: snapshot.type,\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\tconst response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n\t\t\t\t\t\turl,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbody: postBody,\n\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"uploadSummary\",\n\t\t\t\t\t);\n\t\t\t\t\treturn response.content;\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * Following are the goals of this function:\n\t *\n\t * a. Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n\t *\n\t * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n\t * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n\t * @param rootNodeName - Root node name of the summary tree.\n\t * @param path - Current path of node which is getting evaluated.\n\t * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n\t */\n\tprivate async convertSummaryToSnapshotTree(\n\t\tparentHandle: string | undefined,\n\t\ttree: ISummaryTree,\n\t\trootNodeName: string,\n\t\tmarkUnreferencedNodes: boolean = this.mc.config.getBoolean(\n\t\t\t\"Fluid.Driver.Odsp.MarkUnreferencedNodes\",\n\t\t) ?? true,\n\t): Promise<{\n\t\tsnapshotTree: IOdspSummaryTree;\n\t\tblobs: number;\n\t}> {\n\t\tconst snapshotTree: IOdspSummaryTree = {\n\t\t\ttype: \"tree\",\n\t\t\tentries: [] as OdspSummaryTreeEntry[],\n\t\t};\n\n\t\tlet blobs = 0;\n\t\tconst keys = Object.keys(tree.tree);\n\t\tfor (const key of keys) {\n\t\t\tconst summaryObject = tree.tree[key];\n\n\t\t\tlet id: string | undefined;\n\t\t\tlet value: OdspSummaryTreeValue | undefined;\n\n\t\t\t// Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n\t\t\t// property is not present, the tree entry is considered referenced. If the property is present and is\n\t\t\t// true (which is the only value it can have), the tree entry is considered unreferenced.\n\t\t\tlet unreferenced: true | undefined;\n\t\t\tlet groupId: string | undefined;\n\t\t\tswitch (summaryObject.type) {\n\t\t\t\tcase SummaryType.Tree: {\n\t\t\t\t\tconst result = await this.convertSummaryToSnapshotTree(\n\t\t\t\t\t\tparentHandle,\n\t\t\t\t\t\tsummaryObject,\n\t\t\t\t\t\trootNodeName,\n\t\t\t\t\t);\n\t\t\t\t\tvalue = result.snapshotTree;\n\t\t\t\t\tunreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n\t\t\t\t\tgroupId = summaryObject.groupId;\n\t\t\t\t\tblobs += result.blobs;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Blob: {\n\t\t\t\t\tvalue =\n\t\t\t\t\t\ttypeof summaryObject.content === \"string\"\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\ttype: \"blob\",\n\t\t\t\t\t\t\t\t\tcontent: summaryObject.content,\n\t\t\t\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\ttype: \"blob\",\n\t\t\t\t\t\t\t\t\tcontent: Uint8ArrayToString(summaryObject.content, \"base64\"),\n\t\t\t\t\t\t\t\t\tencoding: \"base64\",\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\tblobs++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Handle: {\n\t\t\t\t\tif (!parentHandle) {\n\t\t\t\t\t\tthrow new Error(\"Parent summary does not exist to reference by handle.\");\n\t\t\t\t\t}\n\t\t\t\t\tlet handlePath = summaryObject.handle;\n\t\t\t\t\tif (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n\t\t\t\t\t\thandlePath = `/${handlePath}`;\n\t\t\t\t\t}\n\t\t\t\t\tconst pathKey = `${rootNodeName}${handlePath}`;\n\t\t\t\t\tid = `${parentHandle}/${pathKey}`;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Attachment: {\n\t\t\t\t\tid = summaryObject.id;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(\n\t\t\t\t\t\tsummaryObject,\n\t\t\t\t\t\t`Unknown type: ${(summaryObject as SummaryObject).type}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst baseEntry: IOdspSummaryTreeBaseEntry = {\n\t\t\t\tpath: encodeURIComponent(key),\n\t\t\t\ttype: getGitType(summaryObject),\n\t\t\t};\n\n\t\t\tlet entry: OdspSummaryTreeEntry;\n\n\t\t\tif (value) {\n\t\t\t\tassert(\n\t\t\t\t\tid === undefined,\n\t\t\t\t\t0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */,\n\t\t\t\t);\n\t\t\t\tentry = {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...baseEntry,\n\t\t\t\t\tunreferenced,\n\t\t\t\t\tgroupId,\n\t\t\t\t};\n\t\t\t} else if (id) {\n\t\t\t\tentry = {\n\t\t\t\t\t...baseEntry,\n\t\t\t\t\tid,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Invalid tree entry for ${summaryObject.type}`);\n\t\t\t}\n\n\t\t\tsnapshotTree.entries!.push(entry);\n\t\t}\n\n\t\treturn { snapshotTree, blobs };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkE;AAClE,kEAA8E;AAC9E,2EAA8F;AAE9F,oEAG+C;AAE/C,uEAKkD;AAWlD,+EAAmE;AACnE,iDAA6D;AAE7D;;;GAGG;AACH,MAAa,wBAAwB;IAKpC,YACkB,WAAmB,EACnB,aAA8C,EAC/D,MAA2B,EACV,YAA0B,EAC1B,8BAAwD;QAJxD,gBAAW,GAAX,WAAW,CAAQ;QACnB,kBAAa,GAAb,aAAa,CAAiC;QAE9C,iBAAY,GAAZ,YAAY,CAAc;QAC1B,mCAA8B,GAA9B,8BAA8B,CAA0B;QAEzE,IAAI,CAAC,EAAE,GAAG,IAAA,oCAAyB,EAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAC5B,IAAkB,EAClB,OAAwB;QAExB,8HAA8H;QAC9H,gIAAgI;QAChI,6GAA6G;QAC7G,IACC,IAAI,CAAC,yBAAyB,KAAK,SAAS;YAC5C,IAAI,CAAC,yBAAyB,KAAK,OAAO,CAAC,cAAc,EACxD,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC;gBACjC,SAAS,EAAE,mCAAmC;gBAC9C,0BAA0B,EAAE,OAAO,CAAC,cAAc;gBAClD,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;aACzD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAC7C,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,uBAAuB,EAC/B,IAAI,CACJ,CAAC;QACF,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,C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BACF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;YACjE,CAAC;YAED,YAAY,CAAC,OAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACD;AA/OD,4DA+OC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryTree, SummaryType, SummaryObject } from \"@fluidframework/driver-definitions\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tgetGitType,\n\tisCombinedAppAndProtocolSummary,\n} from \"@fluidframework/driver-utils/internal\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tIOdspSummaryPayload,\n\tIOdspSummaryTree,\n\tIOdspSummaryTreeBaseEntry,\n\tIWriteSummaryResponse,\n\tOdspSummaryTreeEntry,\n\tOdspSummaryTreeValue,\n} from \"./contracts.js\";\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { getHeadersWithAuth } from \"./getUrlAndHeadersWithAuth.js\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils.js\";\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n\t// Last proposed handle of the uploaded app summary.\n\tprivate lastSummaryProposalHandle: string | undefined;\n\tprivate readonly mc: MonitoringContext;\n\n\tconstructor(\n\t\tprivate readonly snapshotUrl: string,\n\t\tprivate readonly getAuthHeader: InstrumentedStorageTokenFetcher,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly epochTracker: EpochTracker,\n\t\tprivate readonly relayServiceTenantAndSessionId: () => string | undefined,\n\t) {\n\t\tthis.mc = loggerToMonitoringContext(logger);\n\t}\n\n\tpublic async writeSummaryTree(\n\t\ttree: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\t// If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n\t\t// then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n\t\t// Don't bother logging if lastSummaryProposalHandle hasn't been set before; only log on a positive mismatch.\n\t\tif (\n\t\t\tthis.lastSummaryProposalHandle !== undefined &&\n\t\t\tthis.lastSummaryProposalHandle !== context.proposalHandle\n\t\t) {\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"LastSummaryProposedHandleMismatch\",\n\t\t\t\tackedSummaryProposedHandle: context.proposalHandle,\n\t\t\t\tlastSummaryProposalHandle: this.lastSummaryProposalHandle,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.writeSummaryTreeCore(\n\t\t\tcontext.ackHandle,\n\t\t\tcontext.referenceSequenceNumber,\n\t\t\ttree,\n\t\t);\n\t\tconst id = result ? result.id : undefined;\n\t\tif (!result || !id) {\n\t\t\tthrow new Error(`Failed to write summary tree`);\n\t\t}\n\t\tthis.lastSummaryProposalHandle = id;\n\t\treturn id;\n\t}\n\n\tprivate async writeSummaryTreeCore(\n\t\tparentHandle: string | undefined,\n\t\treferenceSequenceNumber: number,\n\t\ttree: ISummaryTree,\n\t): Promise<IWriteSummaryResponse> {\n\t\tconst containsProtocolTree = isCombinedAppAndProtocolSummary(tree);\n\t\tconst { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n\t\t\tparentHandle,\n\t\t\ttree,\n\t\t\t\".app\",\n\t\t);\n\t\tconst snapshot: IOdspSummaryPayload = {\n\t\t\tentries: snapshotTree.entries!,\n\t\t\tmessage: \"app\",\n\t\t\tsequenceNumber: referenceSequenceNumber,\n\t\t\t// no ack handle implies this is initial summary after empty file creation.\n\t\t\t// send container payload so server will use it without a summary op\n\t\t\ttype: containsProtocolTree || parentHandle === undefined ? \"container\" : \"channel\",\n\t\t};\n\n\t\treturn getWithRetryForTokenRefresh(async (options) => {\n\t\t\tconst url = `${this.snapshotUrl}/snapshot`;\n\t\t\tconst method = \"POST\";\n\t\t\tconst authHeader = await this.getAuthHeader(\n\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\"WriteSummaryTree\",\n\t\t\t);\n\n\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\theaders[\"Content-Type\"] = \"application/json\";\n\t\t\tconst relayServiceTenantAndSessionId = this.relayServiceTenantAndSessionId();\n\t\t\t// This would be undefined in case of summary is uploaded in detached container with attachment\n\t\t\t// blobs flow where summary is uploaded without connecting to push.\n\t\t\tif (relayServiceTenantAndSessionId !== undefined) {\n\t\t\t\theaders[\"If-Match\"] = `fluid:sessionid=${relayServiceTenantAndSessionId}${\n\t\t\t\t\tparentHandle ? `;containerid=${parentHandle}` : \"\"\n\t\t\t\t}`;\n\t\t\t}\n\n\t\t\tconst postBody = JSON.stringify(snapshot);\n\n\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.mc.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"uploadSummary\",\n\t\t\t\t\tattempt: options.refresh ? 2 : 1,\n\t\t\t\t\thasClaims: !!options.claims,\n\t\t\t\t\thasTenantId: !!options.tenantId,\n\t\t\t\t\tblobs,\n\t\t\t\t\tsize: postBody.length,\n\t\t\t\t\treferenceSequenceNumber,\n\t\t\t\t\ttype: snapshot.type,\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\tconst response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n\t\t\t\t\t\turl,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbody: postBody,\n\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"uploadSummary\",\n\t\t\t\t\t);\n\t\t\t\t\treturn response.content;\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * Following are the goals of this function:\n\t *\n\t * a. Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n\t *\n\t * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n\t * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n\t * @param rootNodeName - Root node name of the summary tree.\n\t * @param path - Current path of node which is getting evaluated.\n\t * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n\t */\n\tprivate async convertSummaryToSnapshotTree(\n\t\tparentHandle: string | undefined,\n\t\ttree: ISummaryTree,\n\t\trootNodeName: string,\n\t\tmarkUnreferencedNodes: boolean = this.mc.config.getBoolean(\n\t\t\t\"Fluid.Driver.Odsp.MarkUnreferencedNodes\",\n\t\t) ?? true,\n\t): Promise<{\n\t\tsnapshotTree: IOdspSummaryTree;\n\t\tblobs: number;\n\t}> {\n\t\tconst snapshotTree: IOdspSummaryTree = {\n\t\t\ttype: \"tree\",\n\t\t\tentries: [] as OdspSummaryTreeEntry[],\n\t\t};\n\n\t\tlet blobs = 0;\n\t\tconst keys = Object.keys(tree.tree);\n\t\tfor (const key of keys) {\n\t\t\tconst summaryObject = tree.tree[key];\n\n\t\t\tlet id: string | undefined;\n\t\t\tlet value: OdspSummaryTreeValue | undefined;\n\n\t\t\t// Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n\t\t\t// property is not present, the tree entry is considered referenced. If the property is present and is\n\t\t\t// true (which is the only value it can have), the tree entry is considered unreferenced.\n\t\t\tlet unreferenced: true | undefined;\n\t\t\tlet groupId: string | undefined;\n\t\t\tswitch (summaryObject.type) {\n\t\t\t\tcase SummaryType.Tree: {\n\t\t\t\t\tconst result = await this.convertSummaryToSnapshotTree(\n\t\t\t\t\t\tparentHandle,\n\t\t\t\t\t\tsummaryObject,\n\t\t\t\t\t\trootNodeName,\n\t\t\t\t\t);\n\t\t\t\t\tvalue = result.snapshotTree;\n\t\t\t\t\tunreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n\t\t\t\t\tgroupId = summaryObject.groupId;\n\t\t\t\t\tblobs += result.blobs;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Blob: {\n\t\t\t\t\tvalue =\n\t\t\t\t\t\ttypeof summaryObject.content === \"string\"\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\ttype: \"blob\",\n\t\t\t\t\t\t\t\t\tcontent: summaryObject.content,\n\t\t\t\t\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\ttype: \"blob\",\n\t\t\t\t\t\t\t\t\tcontent: Uint8ArrayToString(summaryObject.content, \"base64\"),\n\t\t\t\t\t\t\t\t\tencoding: \"base64\",\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\tblobs++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Handle: {\n\t\t\t\t\tif (!parentHandle) {\n\t\t\t\t\t\tthrow new Error(\"Parent summary does not exist to reference by handle.\");\n\t\t\t\t\t}\n\t\t\t\t\tlet handlePath = summaryObject.handle;\n\t\t\t\t\tif (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n\t\t\t\t\t\thandlePath = `/${handlePath}`;\n\t\t\t\t\t}\n\t\t\t\t\tconst pathKey = `${rootNodeName}${handlePath}`;\n\t\t\t\t\tid = `${parentHandle}/${pathKey}`;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase SummaryType.Attachment: {\n\t\t\t\t\tid = summaryObject.id;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(\n\t\t\t\t\t\tsummaryObject,\n\t\t\t\t\t\t`Unknown type: ${(summaryObject as SummaryObject).type}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst baseEntry: IOdspSummaryTreeBaseEntry = {\n\t\t\t\tpath: encodeURIComponent(key),\n\t\t\t\ttype: getGitType(summaryObject),\n\t\t\t};\n\n\t\t\tlet entry: OdspSummaryTreeEntry;\n\n\t\t\tif (value) {\n\t\t\t\tassert(\n\t\t\t\t\tid === undefined,\n\t\t\t\t\t0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */,\n\t\t\t\t);\n\t\t\t\tentry = {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...baseEntry,\n\t\t\t\t\tunreferenced,\n\t\t\t\t\tgroupId,\n\t\t\t\t};\n\t\t\t} else if (id) {\n\t\t\t\tentry = {\n\t\t\t\t\t...baseEntry,\n\t\t\t\t\tid,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Invalid tree entry for ${summaryObject.type}`);\n\t\t\t}\n\n\t\t\tsnapshotTree.entries!.push(entry);\n\t\t}\n\n\t\treturn { snapshotTree, blobs };\n\t}\n}\n"]}
|
package/dist/odspUtils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ITelemetryBaseLogger, ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { IResolvedUrl, ISnapshot } from "@fluidframework/driver-definitions/internal";
|
|
7
|
-
import { ICacheEntry, IOdspResolvedUrl, IOdspUrlParts, ISharingLinkKind, InstrumentedStorageTokenFetcher, InstrumentedTokenFetcher, OdspResourceTokenFetchOptions,
|
|
7
|
+
import { ICacheEntry, IOdspResolvedUrl, IOdspUrlParts, ISharingLinkKind, InstrumentedStorageTokenFetcher, InstrumentedTokenFetcher, OdspResourceTokenFetchOptions, TokenFetcher } from "@fluidframework/odsp-driver-definitions/internal";
|
|
8
8
|
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
9
9
|
import { ISnapshotContents } from "./odspPublicUtils.js";
|
|
10
10
|
export declare const getWithRetryForTokenRefreshRepeat = "getWithRetryForTokenRefreshRepeat";
|
|
@@ -17,7 +17,14 @@ export interface IOdspResponse<T> {
|
|
|
17
17
|
propsToLog: ITelemetryBaseProperties;
|
|
18
18
|
duration: number;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* This interface captures the portion of TokenFetchOptions required for refreshing tokens
|
|
22
|
+
* It is controlled by logic in getWithRetryForTokenRefresh to specify what is the required refresh behavior
|
|
23
|
+
*/
|
|
24
|
+
export interface TokenFetchOptionsEx {
|
|
25
|
+
refresh: boolean;
|
|
26
|
+
claims?: string;
|
|
27
|
+
tenantId?: string;
|
|
21
28
|
/**
|
|
22
29
|
* The previous error we hit in {@link getWithRetryForTokenRefresh}.
|
|
23
30
|
*/
|
|
@@ -80,8 +87,9 @@ export declare function toInstrumentedOdspStorageTokenFetcher(logger: ITelemetry
|
|
|
80
87
|
* Returns a function that can be used to fetch storage or websocket token.
|
|
81
88
|
* There are scenarios where websocket token is not required / present (consumer stack and ordering service token),
|
|
82
89
|
* thus it could return null. Use toInstrumentedOdspStorageTokenFetcher if you deal with storage token.
|
|
90
|
+
* @param returnPlainToken - When true, tokenResponse.token is returned. When false, tokenResponse.authorizationHeader is returned or an authorization header value is created based on tokenResponse.token
|
|
83
91
|
*/
|
|
84
|
-
export declare function toInstrumentedOdspTokenFetcher(logger: ITelemetryLoggerExt, resolvedUrlParts: IOdspUrlParts, tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>, throwOnNullToken: boolean): InstrumentedTokenFetcher;
|
|
92
|
+
export declare function toInstrumentedOdspTokenFetcher(logger: ITelemetryLoggerExt, resolvedUrlParts: IOdspUrlParts, tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>, throwOnNullToken: boolean, returnPlainToken: boolean): InstrumentedTokenFetcher;
|
|
85
93
|
export declare function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry;
|
|
86
94
|
export declare const maxUmpPostBodySize = 79872;
|
|
87
95
|
/**
|
package/dist/odspUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspUtils.d.ts","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,oBAAoB,EACpB,wBAAwB,EACxB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AActF,OAAO,EACN,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,+BAA+B,EAC/B,wBAAwB,
|
|
1
|
+
{"version":3,"file":"odspUtils.d.ts","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,oBAAoB,EACpB,wBAAwB,EACxB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AActF,OAAO,EACN,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,+BAA+B,EAC/B,wBAAwB,EAGxB,6BAA6B,EAE7B,YAAY,EAIZ,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAEN,mBAAmB,EAKnB,MAAM,0CAA0C,CAAC;AAIlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD,eAAO,MAAM,iCAAiC,sCAAsC,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC/B,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,EAAE,wBAAwB,CAAC;IACrC,QAA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GAAG,MAAM,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAEpC,GAAG,EAAE,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAC5C,GAAG,IAAI,SAAS,CAElB;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC7C,eAAe,EAAE,MAAM,EAAE,GAAG,SAAS,GACnC,OAAO,CAET;AAMD,wBAAgB,0CAA0C,CACzD,eAAe,EAAE,MAAM,EAAE,GAAG,SAAS,GACnC,OAAO,CAET"}
|
package/dist/odspUtils.js
CHANGED
|
@@ -213,7 +213,8 @@ exports.createOdspLogger = createOdspLogger;
|
|
|
213
213
|
* Storage token can not be empty - if original delegate (tokenFetcher argument) returns null result, exception will be thrown
|
|
214
214
|
*/
|
|
215
215
|
function toInstrumentedOdspStorageTokenFetcher(logger, resolvedUrlParts, tokenFetcher) {
|
|
216
|
-
const res = toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher, true
|
|
216
|
+
const res = toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher, true, // throwOnNullToken
|
|
217
|
+
false);
|
|
217
218
|
// Drop undefined from signature - we can do it safely due to throwOnNullToken == true above
|
|
218
219
|
return res;
|
|
219
220
|
}
|
|
@@ -222,8 +223,9 @@ exports.toInstrumentedOdspStorageTokenFetcher = toInstrumentedOdspStorageTokenFe
|
|
|
222
223
|
* Returns a function that can be used to fetch storage or websocket token.
|
|
223
224
|
* There are scenarios where websocket token is not required / present (consumer stack and ordering service token),
|
|
224
225
|
* thus it could return null. Use toInstrumentedOdspStorageTokenFetcher if you deal with storage token.
|
|
226
|
+
* @param returnPlainToken - When true, tokenResponse.token is returned. When false, tokenResponse.authorizationHeader is returned or an authorization header value is created based on tokenResponse.token
|
|
225
227
|
*/
|
|
226
|
-
function toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher, throwOnNullToken) {
|
|
228
|
+
function toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher, throwOnNullToken, returnPlainToken) {
|
|
227
229
|
return async (options, name, alwaysRecordTokenFetchTelemetry = false) => {
|
|
228
230
|
// Telemetry note: if options.refresh is true, there is a potential perf issue:
|
|
229
231
|
// Host should optimize and provide non-expired tokens on all critical paths.
|
|
@@ -238,7 +240,9 @@ function toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher,
|
|
|
238
240
|
...options,
|
|
239
241
|
...resolvedUrlParts,
|
|
240
242
|
}).then((tokenResponse) => {
|
|
241
|
-
const
|
|
243
|
+
const returnVal = returnPlainToken
|
|
244
|
+
? (0, internal_4.tokenFromResponse)(tokenResponse)
|
|
245
|
+
: (0, internal_4.authHeaderFromTokenResponse)(tokenResponse);
|
|
242
246
|
// This event alone generates so many events that is materially impacts cost of telemetry
|
|
243
247
|
// Thus do not report end event when it comes back quickly.
|
|
244
248
|
// Note that most of the hosts do not report if result is comming from cache or not,
|
|
@@ -247,15 +251,15 @@ function toInstrumentedOdspTokenFetcher(logger, resolvedUrlParts, tokenFetcher,
|
|
|
247
251
|
if (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {
|
|
248
252
|
event.end({
|
|
249
253
|
fromCache: (0, internal_4.isTokenFromCache)(tokenResponse),
|
|
250
|
-
isNull:
|
|
254
|
+
isNull: returnVal === null,
|
|
251
255
|
});
|
|
252
256
|
}
|
|
253
|
-
if (
|
|
257
|
+
if (returnVal === null && throwOnNullToken) {
|
|
254
258
|
throw new internal_2.NonRetryableError(
|
|
255
259
|
// pre-0.58 error message: Token is null for ${name} call
|
|
256
260
|
`The Host-provided token fetcher returned null`, internal_4.OdspErrorTypes.fetchTokenError, { method: name, driverVersion: packageVersion_js_1.pkgVersion });
|
|
257
261
|
}
|
|
258
|
-
return
|
|
262
|
+
return returnVal;
|
|
259
263
|
}, (error) => {
|
|
260
264
|
// There is an important but unofficial contract here where token providers can set canRetry: true
|
|
261
265
|
// to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)
|
package/dist/od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AACH,SAAgB,0CAA0C,CACzD,eAAqC;IAErC,OAAO,eAAe,KAAK,SAAS,CAAC;AACtC,CAAC;AAJD,gGAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport {\n\tITelemetryBaseLogger,\n\tITelemetryBaseProperties,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IResolvedUrl, ISnapshot } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype AuthorizationError,\n\tNetworkErrorBasic,\n\tNonRetryableError,\n\tOnlineStatus,\n\tRetryableError,\n\tisOnline,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tfetchIncorrectResponse,\n\tgetSPOAndGraphRequestIdsFromResponse,\n\tthrowOdspNetworkError,\n} from \"@fluidframework/odsp-doclib-utils/internal\";\nimport {\n\tICacheEntry,\n\tIOdspResolvedUrl,\n\tIOdspUrlParts,\n\tISharingLinkKind,\n\tInstrumentedStorageTokenFetcher,\n\tInstrumentedTokenFetcher,\n\tOdspErrorTypes,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetchOptions,\n\tTokenFetcher,\n\tisTokenFromCache,\n\tsnapshotKey,\n\ttokenFromResponse,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\ttype IFluidErrorBase,\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\tTelemetryDataTag,\n\tcreateChildLogger,\n\twrapError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { fetch } from \"./fetch.js\";\n// eslint-disable-next-line import/no-deprecated\nimport { ISnapshotContents } from \"./odspPublicUtils.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\n\nexport const getWithRetryForTokenRefreshRepeat = \"getWithRetryForTokenRefreshRepeat\";\n\n/**\n * @alpha\n */\nexport interface IOdspResponse<T> {\n\tcontent: T;\n\theaders: Map<string, string>;\n\tpropsToLog: ITelemetryBaseProperties;\n\tduration: number;\n}\n\nexport interface TokenFetchOptionsEx extends TokenFetchOptions {\n\t/**\n\t * The previous error we hit in {@link getWithRetryForTokenRefresh}.\n\t */\n\tpreviousError?: unknown;\n}\n\nfunction headersToMap(headers: Headers): Map<string, string> {\n\tconst newHeaders = new Map<string, string>();\n\tfor (const [key, value] of headers.entries()) {\n\t\tnewHeaders.set(key, value);\n\t}\n\treturn newHeaders;\n}\n\n/**\n * This API should be used with pretty much all network calls (fetch, webSocket connection) in order\n * to correctly handle expired tokens. It relies on callback fetching token, and be able to refetch\n * token on failure. Only specific cases get retry call with refresh = true, all other / unknown errors\n * simply propagate to caller\n */\nexport async function getWithRetryForTokenRefresh<T>(\n\tget: (options: TokenFetchOptionsEx) => Promise<T>,\n): Promise<T> {\n\treturn get({ refresh: false }).catch(async (error) => {\n\t\tconst options: TokenFetchOptionsEx = { refresh: true, previousError: error };\n\t\tswitch ((error as Partial<IFluidErrorBase>).errorType) {\n\t\t\t// If the error is 401 or 403 refresh the token and try once more.\n\t\t\tcase OdspErrorTypes.authorizationError: {\n\t\t\t\tconst authError = error as AuthorizationError;\n\t\t\t\treturn get({ ...options, claims: authError.claims, tenantId: authError.tenantId });\n\t\t\t}\n\n\t\t\tcase OdspErrorTypes.incorrectServerResponse: // some error on the wire, retry once\n\t\t\tcase OdspErrorTypes.fetchTokenError: {\n\t\t\t\t// If the token was null, then retry once.\n\t\t\t\treturn get(options);\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\t// Caller may determine that it wants one retry\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-explicit-any\n\t\t\t\tif ((error as any)[getWithRetryForTokenRefreshRepeat] === true) {\n\t\t\t\t\treturn get(options);\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t});\n}\n\nexport async function fetchHelper(\n\trequestInfo: RequestInfo,\n\trequestInit: RequestInit | undefined,\n): Promise<IOdspResponse<Response>> {\n\tconst start = performance.now();\n\n\t// Node-fetch and dom have conflicting typing, force them to work by casting for now\n\treturn fetch(requestInfo, requestInit).then(\n\t\tasync (fetchResponse) => {\n\t\t\tconst response = fetchResponse as unknown as Response;\n\t\t\t// Let's assume we can retry.\n\t\t\tif (!response) {\n\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t// pre-0.58 error message: No response from fetch call\n\t\t\t\t\t\"No response from ODSP fetch call\",\n\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t{ driverVersion },\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!response.ok || response.status < 200 || response.status >= 300) {\n\t\t\t\tthrowOdspNetworkError(\n\t\t\t\t\t// pre-0.58 error message prefix: odspFetchError\n\t\t\t\t\t`ODSP fetch error [${response.status}]`,\n\t\t\t\t\tresponse.status,\n\t\t\t\t\tresponse,\n\t\t\t\t\tawait response.text(),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst headers = headersToMap(response.headers);\n\t\t\treturn {\n\t\t\t\tcontent: response,\n\t\t\t\theaders,\n\t\t\t\tpropsToLog: getSPOAndGraphRequestIdsFromResponse(headers),\n\t\t\t\tduration: performance.now() - start,\n\t\t\t};\n\t\t},\n\t\t(error) => {\n\t\t\tconst online = isOnline();\n\n\t\t\t// The error message may not be suitable to log for privacy reasons, so tag it as such\n\t\t\tconst taggedErrorMessage = {\n\t\t\t\tvalue: `${error}`, // This uses toString for objects, which often results in `${error.name}: ${error.message}`\n\t\t\t\ttag: TelemetryDataTag.UserData,\n\t\t\t};\n\t\t\t// After redacting URLs we believe the error message is safe to log\n\t\t\tconst urlRegex = /((http|https):\\/\\/(\\S*))/i;\n\t\t\tconst redactedErrorText = taggedErrorMessage.value.replace(urlRegex, \"REDACTED_URL\");\n\n\t\t\t// This error is thrown by fetch() when AbortSignal is provided and it gets cancelled\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tif (error.name === \"AbortError\") {\n\t\t\t\tthrow new RetryableError(\"Fetch Timeout (AbortError)\", OdspErrorTypes.fetchTimeout, {\n\t\t\t\t\tdriverVersion,\n\t\t\t\t});\n\t\t\t}\n\t\t\t// TCP/IP timeout\n\t\t\tif (redactedErrorText.includes(\"ETIMEDOUT\")) {\n\t\t\t\tthrow new RetryableError(\"Fetch Timeout (ETIMEDOUT)\", OdspErrorTypes.fetchTimeout, {\n\t\t\t\t\tdriverVersion,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (online === OnlineStatus.Offline) {\n\t\t\t\tthrow new RetryableError(\n\t\t\t\t\t// pre-0.58 error message prefix: Offline\n\t\t\t\t\t`ODSP fetch failure (Offline): ${redactedErrorText}`,\n\t\t\t\t\tOdspErrorTypes.offlineError,\n\t\t\t\t\t{\n\t\t\t\t\t\tdriverVersion,\n\t\t\t\t\t\trawErrorMessage: taggedErrorMessage,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// It is perhaps still possible that this is due to being offline, the error does not reveal enough\n\t\t\t\t// information to conclude. Could also be DNS errors, malformed fetch request, CSP violation, etc.\n\t\t\t\tthrow new RetryableError(\n\t\t\t\t\t// pre-0.58 error message prefix: Fetch error\n\t\t\t\t\t`ODSP fetch failure: ${redactedErrorText}`,\n\t\t\t\t\tOdspErrorTypes.fetchFailure,\n\t\t\t\t\t{\n\t\t\t\t\t\tdriverVersion,\n\t\t\t\t\t\trawErrorMessage: taggedErrorMessage,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t);\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchArray(\n\trequestInfo: RequestInfo,\n\trequestInit: RequestInit | undefined,\n): Promise<IOdspResponse<ArrayBuffer>> {\n\tconst { content, headers, propsToLog, duration } = await fetchHelper(\n\t\trequestInfo,\n\t\trequestInit,\n\t);\n\tlet arrayBuffer: ArrayBuffer;\n\ttry {\n\t\tarrayBuffer = await content.arrayBuffer();\n\t} catch {\n\t\t// Parsing can fail and message could contain full request URI, including\n\t\t// tokens, etc. So do not log error object itself.\n\t\tthrowOdspNetworkError(\n\t\t\t\"Error while parsing fetch response\",\n\t\t\tfetchIncorrectResponse,\n\t\t\tcontent, // response\n\t\t\tundefined, // response text\n\t\t\tpropsToLog,\n\t\t);\n\t}\n\n\tpropsToLog.bodySize = arrayBuffer.byteLength;\n\treturn {\n\t\theaders,\n\t\tcontent: arrayBuffer,\n\t\tpropsToLog,\n\t\tduration,\n\t};\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchAndParseAsJSONHelper<T>(\n\trequestInfo: RequestInfo,\n\trequestInit: RequestInit | undefined,\n): Promise<IOdspResponse<T>> {\n\tconst { content, headers, propsToLog, duration } = await fetchHelper(\n\t\trequestInfo,\n\t\trequestInit,\n\t);\n\tlet text: string | undefined;\n\ttry {\n\t\ttext = await content.text();\n\t} catch {\n\t\t// JSON.parse() can fail and message would container full request URI, including\n\t\t// tokens... It fails for me with \"Unexpected end of JSON input\" quite often - an attempt to download big file\n\t\t// (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always\n\t\t// succeeds on retry.\n\t\t// So do not log error object itself.\n\t\tthrowOdspNetworkError(\n\t\t\t// pre-0.58 error message: errorWhileParsingFetchResponse\n\t\t\t\"Error while parsing fetch response\",\n\t\t\tfetchIncorrectResponse,\n\t\t\tcontent, // response\n\t\t\ttext,\n\t\t\tpropsToLog,\n\t\t);\n\t}\n\n\tpropsToLog.bodySize = text.length;\n\tconst res = {\n\t\theaders,\n\t\tcontent: JSON.parse(text) as T,\n\t\tpropsToLog,\n\t\tduration,\n\t};\n\treturn res;\n}\n\nexport interface IFileInfoBase {\n\ttype: \"New\" | \"Existing\";\n\tsiteUrl: string;\n\tdriveId: string;\n}\n\nexport interface INewFileInfo extends IFileInfoBase {\n\ttype: \"New\";\n\tfilename: string;\n\tfilePath: string;\n\t/**\n\t * application can request creation of a share link along with the creation of a new file\n\t * by passing in an optional param to specify the kind of sharing link\n\t */\n\tcreateLinkType?: ISharingLinkKind;\n}\n\nexport interface IExistingFileInfo extends IFileInfoBase {\n\ttype: \"Existing\";\n\titemId: string;\n}\n\nexport function isNewFileInfo(\n\tfileInfo: INewFileInfo | IExistingFileInfo,\n): fileInfo is INewFileInfo {\n\treturn fileInfo.type === undefined || fileInfo.type === \"New\";\n}\n\nexport function getOdspResolvedUrl(resolvedUrl: IResolvedUrl): IOdspResolvedUrl {\n\tassert(\n\t\t(resolvedUrl as IOdspResolvedUrl).odspResolvedUrl === true,\n\t\t0x1de /* \"Not an ODSP resolved url\" */,\n\t);\n\treturn resolvedUrl as IOdspResolvedUrl;\n}\n\n/**\n * Type narrowing utility to determine if the provided {@link @fluidframework/driver-definitions#IResolvedUrl}\n * is an {@link @fluidframework/odsp-driver-definitions#IOdspResolvedUrl}.\n * @internal\n */\nexport function isOdspResolvedUrl(resolvedUrl: IResolvedUrl): resolvedUrl is IOdspResolvedUrl {\n\treturn \"odspResolvedUrl\" in resolvedUrl && resolvedUrl.odspResolvedUrl === true;\n}\n\nexport const createOdspLogger = (logger?: ITelemetryBaseLogger): ITelemetryLoggerExt =>\n\tcreateChildLogger({\n\t\tlogger,\n\t\tnamespace: \"OdspDriver\",\n\t\tproperties: {\n\t\t\tall: {\n\t\t\t\tdriverVersion,\n\t\t\t},\n\t\t},\n\t});\n\n/**\n * Returns a function that can be used to fetch storage token.\n * Storage token can not be empty - if original delegate (tokenFetcher argument) returns null result, exception will be thrown\n */\nexport function toInstrumentedOdspStorageTokenFetcher(\n\tlogger: ITelemetryLoggerExt,\n\tresolvedUrlParts: IOdspUrlParts,\n\ttokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n): InstrumentedStorageTokenFetcher {\n\tconst res = toInstrumentedOdspTokenFetcher(\n\t\tlogger,\n\t\tresolvedUrlParts,\n\t\ttokenFetcher,\n\t\ttrue, // throwOnNullToken,\n\t);\n\t// Drop undefined from signature - we can do it safely due to throwOnNullToken == true above\n\treturn res as InstrumentedStorageTokenFetcher;\n}\n\n/**\n * Returns a function that can be used to fetch storage or websocket token.\n * There are scenarios where websocket token is not required / present (consumer stack and ordering service token),\n * thus it could return null. Use toInstrumentedOdspStorageTokenFetcher if you deal with storage token.\n */\nexport function toInstrumentedOdspTokenFetcher(\n\tlogger: ITelemetryLoggerExt,\n\tresolvedUrlParts: IOdspUrlParts,\n\ttokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tthrowOnNullToken: boolean,\n): InstrumentedTokenFetcher {\n\treturn async (\n\t\toptions: TokenFetchOptions,\n\t\tname: string,\n\t\talwaysRecordTokenFetchTelemetry: boolean = false,\n\t) => {\n\t\t// Telemetry note: if options.refresh is true, there is a potential perf issue:\n\t\t// Host should optimize and provide non-expired tokens on all critical paths.\n\t\t// Exceptions: race conditions around expiration, revoked tokens, host that does not care\n\t\t// (fluid-fetcher)\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tlogger,\n\t\t\t{\n\t\t\t\teventName: `${name}_GetToken`,\n\t\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\t\thasClaims: !!options.claims,\n\t\t\t\thasTenantId: !!options.tenantId,\n\t\t\t},\n\t\t\tasync (event) =>\n\t\t\t\ttokenFetcher({\n\t\t\t\t\t...options,\n\t\t\t\t\t...resolvedUrlParts,\n\t\t\t\t}).then(\n\t\t\t\t\t(tokenResponse) => {\n\t\t\t\t\t\tconst token = tokenFromResponse(tokenResponse);\n\t\t\t\t\t\t// This event alone generates so many events that is materially impacts cost of telemetry\n\t\t\t\t\t\t// Thus do not report end event when it comes back quickly.\n\t\t\t\t\t\t// Note that most of the hosts do not report if result is comming from cache or not,\n\t\t\t\t\t\t// so we can't rely on that here. But always record if specified explicitly for cases such as\n\t\t\t\t\t\t// calling trees/latest during load.\n\t\t\t\t\t\tif (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {\n\t\t\t\t\t\t\tevent.end({\n\t\t\t\t\t\t\t\tfromCache: isTokenFromCache(tokenResponse),\n\t\t\t\t\t\t\t\tisNull: token === null,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (token === null && throwOnNullToken) {\n\t\t\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\t\t// pre-0.58 error message: Token is null for ${name} call\n\t\t\t\t\t\t\t\t`The Host-provided token fetcher returned null`,\n\t\t\t\t\t\t\t\tOdspErrorTypes.fetchTokenError,\n\t\t\t\t\t\t\t\t{ method: name, driverVersion },\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn token;\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\t// There is an important but unofficial contract here where token providers can set canRetry: true\n\t\t\t\t\t\t// to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\tconst rawCanRetry = error?.canRetry;\n\t\t\t\t\t\tconst tokenError = wrapError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t(errorMessage) =>\n\t\t\t\t\t\t\t\tnew NetworkErrorBasic(\n\t\t\t\t\t\t\t\t\t`The Host-provided token fetcher threw an error`,\n\t\t\t\t\t\t\t\t\tOdspErrorTypes.fetchTokenError,\n\t\t\t\t\t\t\t\t\ttypeof rawCanRetry === \"boolean\" ? rawCanRetry : false /* canRetry */,\n\t\t\t\t\t\t\t\t\t{ method: name, errorMessage, driverVersion },\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthrow tokenError;\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t{ cancel: \"generic\" },\n\t\t);\n\t};\n}\n\nexport function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry {\n\tconst cacheEntry: ICacheEntry = {\n\t\ttype: snapshotKey,\n\t\tkey: odspResolvedUrl.fileVersion ?? \"\",\n\t\tfile: {\n\t\t\tresolvedUrl: odspResolvedUrl,\n\t\t\tdocId: odspResolvedUrl.hashedDocumentId,\n\t\t},\n\t};\n\treturn cacheEntry;\n}\n\n// 80KB is the max body size that we can put in ump post body for server to be able to accept it.\n// Keeping it 78KB to be a little cautious. As per the telemetry 99p is less than 78KB.\nexport const maxUmpPostBodySize = 79872;\n\n/**\n * Build request parameters to request for the creation of a sharing link along with the creation of the file\n * through the /snapshot api call.\n * @param shareLinkType - Kind of sharing link requested\n * @returns A string of request parameters that can be concatenated with the base URI\n */\nexport function buildOdspShareLinkReqParams(\n\tshareLinkType: ISharingLinkKind | undefined,\n): string | undefined {\n\tif (!shareLinkType) {\n\t\treturn;\n\t}\n\tconst scope = shareLinkType.scope;\n\tlet shareLinkRequestParams = `createLinkScope=${scope}`;\n\tconst role = shareLinkType.role;\n\tshareLinkRequestParams = role\n\t\t? `${shareLinkRequestParams}&createLinkRole=${role}`\n\t\t: shareLinkRequestParams;\n\treturn shareLinkRequestParams;\n}\n\nexport function measure<T>(callback: () => T): [T, number] {\n\tconst start = performance.now();\n\tconst result = callback();\n\tconst time = performance.now() - start;\n\treturn [result, time];\n}\n\nexport async function measureP<T>(callback: () => Promise<T>): Promise<[T, number]> {\n\tconst start = performance.now();\n\tconst result = await callback();\n\tconst time = performance.now() - start;\n\treturn [result, time];\n}\n\nexport function getJoinSessionCacheKey(odspResolvedUrl: IOdspResolvedUrl): string {\n\treturn `${odspResolvedUrl.hashedDocumentId}/joinsession`;\n}\n\n/**\n * Utility API to check if the type of snapshot contents is `ISnapshot`.\n * @internal\n * @param obj - obj whose type needs to be identified.\n */\nexport function isInstanceOfISnapshot(\n\t// eslint-disable-next-line import/no-deprecated\n\tobj: ISnapshotContents | ISnapshot | undefined,\n): obj is ISnapshot {\n\treturn obj !== undefined && \"snapshotFormatV\" in obj && obj.snapshotFormatV === 1;\n}\n\n/**\n * This tells whether request if for a specific loading group or not. The snapshot which\n * we fetch on initial load, fetches all ungrouped content.\n */\nexport function isSnapshotFetchForLoadingGroup(\n\tloadingGroupIds: string[] | undefined,\n): boolean {\n\treturn loadingGroupIds !== undefined && loadingGroupIds.length > 0;\n}\n\n/*\n * This tells whether we are using legacy flow for fetching snapshot where we don't use\n * groupId query param in the trees latest network call.\n */\nexport function useLegacyFlowWithoutGroupsForSnapshotFetch(\n\tloadingGroupIds: string[] | undefined,\n): boolean {\n\treturn loadingGroupIds === undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspUtils.js","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAK3D,kEAA6D;AAE7D,oEAO+C;AAC/C,yEAIoD;AACpD,+EAe0D;AAC1D,uEAOkD;AAElD,yCAAmC;AAGnC,2DAAkE;AAErD,QAAA,iCAAiC,GAAG,mCAAmC,CAAC;AA0BrF,SAAS,YAAY,CAAC,OAAgB;IACrC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC9C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,UAAU,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAChD,GAAiD;IAEjD,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACpD,MAAM,OAAO,GAAwB,EAAE,OAAO,EAAE,IAAI,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,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IACvC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACvB,CAAC;AALD,4BAKC;AAED,SAAgB,sBAAsB,CAAC,eAAiC;IACvE,OAAO,GAAG,eAAe,CAAC,gBAAgB,cAAc,CAAC;AAC1D,CAAC;AAFD,wDAEC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB;AACpC,gDAAgD;AAChD,GAA8C;IAE9C,OAAO,GAAG,KAAK,SAAS,IAAI,iBAAiB,IAAI,GAAG,IAAI,GAAG,CAAC,eAAe,KAAK,CAAC,CAAC;AACnF,CAAC;AALD,sDAKC;AAED;;;GAGG;AACH,SAAgB,8BAA8B,CAC7C,eAAqC;IAErC,OAAO,eAAe,KAAK,SAAS,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC;AACpE,CAAC;AAJD,wEAIC;AAED;;;GAGG;AACH,SAAgB,0CAA0C,CACzD,eAAqC;IAErC,OAAO,eAAe,KAAK,SAAS,CAAC;AACtC,CAAC;AAJD,gGAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport {\n\tITelemetryBaseLogger,\n\tITelemetryBaseProperties,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IResolvedUrl, ISnapshot } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype AuthorizationError,\n\tNetworkErrorBasic,\n\tNonRetryableError,\n\tOnlineStatus,\n\tRetryableError,\n\tisOnline,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tfetchIncorrectResponse,\n\tgetSPOAndGraphRequestIdsFromResponse,\n\tthrowOdspNetworkError,\n} from \"@fluidframework/odsp-doclib-utils/internal\";\nimport {\n\tICacheEntry,\n\tIOdspResolvedUrl,\n\tIOdspUrlParts,\n\tISharingLinkKind,\n\tInstrumentedStorageTokenFetcher,\n\tInstrumentedTokenFetcher,\n\tOdspErrorTypes,\n\tauthHeaderFromTokenResponse,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetchOptions,\n\tTokenFetcher,\n\tisTokenFromCache,\n\tsnapshotKey,\n\ttokenFromResponse,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\ttype IFluidErrorBase,\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\tTelemetryDataTag,\n\tcreateChildLogger,\n\twrapError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { fetch } from \"./fetch.js\";\n// eslint-disable-next-line import/no-deprecated\nimport { ISnapshotContents } from \"./odspPublicUtils.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\n\nexport const getWithRetryForTokenRefreshRepeat = \"getWithRetryForTokenRefreshRepeat\";\n\n/**\n * @alpha\n */\nexport interface IOdspResponse<T> {\n\tcontent: T;\n\theaders: Map<string, string>;\n\tpropsToLog: ITelemetryBaseProperties;\n\tduration: number;\n}\n\n/**\n * This interface captures the portion of TokenFetchOptions required for refreshing tokens\n * It is controlled by logic in getWithRetryForTokenRefresh to specify what is the required refresh behavior\n */\nexport interface TokenFetchOptionsEx {\n\trefresh: boolean;\n\tclaims?: string;\n\ttenantId?: string;\n\t/**\n\t * The previous error we hit in {@link getWithRetryForTokenRefresh}.\n\t */\n\tpreviousError?: unknown;\n}\n\nfunction headersToMap(headers: Headers): Map<string, string> {\n\tconst newHeaders = new Map<string, string>();\n\tfor (const [key, value] of headers.entries()) {\n\t\tnewHeaders.set(key, value);\n\t}\n\treturn newHeaders;\n}\n\n/**\n * This API should be used with pretty much all network calls (fetch, webSocket connection) in order\n * to correctly handle expired tokens. It relies on callback fetching token, and be able to refetch\n * token on failure. Only specific cases get retry call with refresh = true, all other / unknown errors\n * simply propagate to caller\n */\nexport async function getWithRetryForTokenRefresh<T>(\n\tget: (options: TokenFetchOptionsEx) => Promise<T>,\n): Promise<T> {\n\treturn get({ refresh: false }).catch(async (error) => {\n\t\tconst options: TokenFetchOptionsEx = { refresh: true, previousError: error };\n\t\tswitch ((error as Partial<IFluidErrorBase>).errorType) {\n\t\t\t// If the error is 401 or 403 refresh the token and try once more.\n\t\t\tcase OdspErrorTypes.authorizationError: {\n\t\t\t\tconst authError = error as AuthorizationError;\n\t\t\t\treturn get({ ...options, claims: authError.claims, tenantId: authError.tenantId });\n\t\t\t}\n\n\t\t\tcase OdspErrorTypes.incorrectServerResponse: // some error on the wire, retry once\n\t\t\tcase OdspErrorTypes.fetchTokenError: {\n\t\t\t\t// If the token was null, then retry once.\n\t\t\t\treturn get(options);\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\t// Caller may determine that it wants one retry\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-explicit-any\n\t\t\t\tif ((error as any)[getWithRetryForTokenRefreshRepeat] === true) {\n\t\t\t\t\treturn get(options);\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t});\n}\n\nexport async function fetchHelper(\n\trequestInfo: RequestInfo,\n\trequestInit: RequestInit | undefined,\n): Promise<IOdspResponse<Response>> {\n\tconst start = performance.now();\n\n\t// Node-fetch and dom have conflicting typing, force them to work by casting for now\n\treturn fetch(requestInfo, requestInit).then(\n\t\tasync (fetchResponse) => {\n\t\t\tconst response = fetchResponse as unknown as Response;\n\t\t\t// Let's assume we can retry.\n\t\t\tif (!response) {\n\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t// pre-0.58 error message: No response from fetch call\n\t\t\t\t\t\"No response from ODSP fetch call\",\n\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t{ driverVersion },\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!response.ok || response.status < 200 || response.status >= 300) {\n\t\t\t\tthrowOdspNetworkError(\n\t\t\t\t\t// pre-0.58 error message prefix: odspFetchError\n\t\t\t\t\t`ODSP fetch error [${response.status}]`,\n\t\t\t\t\tresponse.status,\n\t\t\t\t\tresponse,\n\t\t\t\t\tawait response.text(),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst headers = headersToMap(response.headers);\n\t\t\treturn {\n\t\t\t\tcontent: response,\n\t\t\t\theaders,\n\t\t\t\tpropsToLog: getSPOAndGraphRequestIdsFromResponse(headers),\n\t\t\t\tduration: performance.now() - start,\n\t\t\t};\n\t\t},\n\t\t(error) => {\n\t\t\tconst online = isOnline();\n\n\t\t\t// The error message may not be suitable to log for privacy reasons, so tag it as such\n\t\t\tconst taggedErrorMessage = {\n\t\t\t\tvalue: `${error}`, // This uses toString for objects, which often results in `${error.name}: ${error.message}`\n\t\t\t\ttag: TelemetryDataTag.UserData,\n\t\t\t};\n\t\t\t// After redacting URLs we believe the error message is safe to log\n\t\t\tconst urlRegex = /((http|https):\\/\\/(\\S*))/i;\n\t\t\tconst redactedErrorText = taggedErrorMessage.value.replace(urlRegex, \"REDACTED_URL\");\n\n\t\t\t// This error is thrown by fetch() when AbortSignal is provided and it gets cancelled\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\tif (error.name === \"AbortError\") {\n\t\t\t\tthrow new RetryableError(\"Fetch Timeout (AbortError)\", OdspErrorTypes.fetchTimeout, {\n\t\t\t\t\tdriverVersion,\n\t\t\t\t});\n\t\t\t}\n\t\t\t// TCP/IP timeout\n\t\t\tif (redactedErrorText.includes(\"ETIMEDOUT\")) {\n\t\t\t\tthrow new RetryableError(\"Fetch Timeout (ETIMEDOUT)\", OdspErrorTypes.fetchTimeout, {\n\t\t\t\t\tdriverVersion,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (online === OnlineStatus.Offline) {\n\t\t\t\tthrow new RetryableError(\n\t\t\t\t\t// pre-0.58 error message prefix: Offline\n\t\t\t\t\t`ODSP fetch failure (Offline): ${redactedErrorText}`,\n\t\t\t\t\tOdspErrorTypes.offlineError,\n\t\t\t\t\t{\n\t\t\t\t\t\tdriverVersion,\n\t\t\t\t\t\trawErrorMessage: taggedErrorMessage,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// It is perhaps still possible that this is due to being offline, the error does not reveal enough\n\t\t\t\t// information to conclude. Could also be DNS errors, malformed fetch request, CSP violation, etc.\n\t\t\t\tthrow new RetryableError(\n\t\t\t\t\t// pre-0.58 error message prefix: Fetch error\n\t\t\t\t\t`ODSP fetch failure: ${redactedErrorText}`,\n\t\t\t\t\tOdspErrorTypes.fetchFailure,\n\t\t\t\t\t{\n\t\t\t\t\t\tdriverVersion,\n\t\t\t\t\t\trawErrorMessage: taggedErrorMessage,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t);\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchArray(\n\trequestInfo: RequestInfo,\n\trequestInit: RequestInit | undefined,\n): Promise<IOdspResponse<ArrayBuffer>> {\n\tconst { content, headers, propsToLog, duration } = await fetchHelper(\n\t\trequestInfo,\n\t\trequestInit,\n\t);\n\tlet arrayBuffer: ArrayBuffer;\n\ttry {\n\t\tarrayBuffer = await content.arrayBuffer();\n\t} catch {\n\t\t// Parsing can fail and message could contain full request URI, including\n\t\t// tokens, etc. So do not log error object itself.\n\t\tthrowOdspNetworkError(\n\t\t\t\"Error while parsing fetch response\",\n\t\t\tfetchIncorrectResponse,\n\t\t\tcontent, // response\n\t\t\tundefined, // response text\n\t\t\tpropsToLog,\n\t\t);\n\t}\n\n\tpropsToLog.bodySize = arrayBuffer.byteLength;\n\treturn {\n\t\theaders,\n\t\tcontent: arrayBuffer,\n\t\tpropsToLog,\n\t\tduration,\n\t};\n}\n\n/**\n * A utility function to fetch and parse as JSON with support for retries\n * @param requestInfo - fetch requestInfo, can be a string\n * @param requestInit - fetch requestInit\n */\nexport async function fetchAndParseAsJSONHelper<T>(\n\trequestInfo: RequestInfo,\n\trequestInit: RequestInit | undefined,\n): Promise<IOdspResponse<T>> {\n\tconst { content, headers, propsToLog, duration } = await fetchHelper(\n\t\trequestInfo,\n\t\trequestInit,\n\t);\n\tlet text: string | undefined;\n\ttry {\n\t\ttext = await content.text();\n\t} catch {\n\t\t// JSON.parse() can fail and message would container full request URI, including\n\t\t// tokens... It fails for me with \"Unexpected end of JSON input\" quite often - an attempt to download big file\n\t\t// (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always\n\t\t// succeeds on retry.\n\t\t// So do not log error object itself.\n\t\tthrowOdspNetworkError(\n\t\t\t// pre-0.58 error message: errorWhileParsingFetchResponse\n\t\t\t\"Error while parsing fetch response\",\n\t\t\tfetchIncorrectResponse,\n\t\t\tcontent, // response\n\t\t\ttext,\n\t\t\tpropsToLog,\n\t\t);\n\t}\n\n\tpropsToLog.bodySize = text.length;\n\tconst res = {\n\t\theaders,\n\t\tcontent: JSON.parse(text) as T,\n\t\tpropsToLog,\n\t\tduration,\n\t};\n\treturn res;\n}\n\nexport interface IFileInfoBase {\n\ttype: \"New\" | \"Existing\";\n\tsiteUrl: string;\n\tdriveId: string;\n}\n\nexport interface INewFileInfo extends IFileInfoBase {\n\ttype: \"New\";\n\tfilename: string;\n\tfilePath: string;\n\t/**\n\t * application can request creation of a share link along with the creation of a new file\n\t * by passing in an optional param to specify the kind of sharing link\n\t */\n\tcreateLinkType?: ISharingLinkKind;\n}\n\nexport interface IExistingFileInfo extends IFileInfoBase {\n\ttype: \"Existing\";\n\titemId: string;\n}\n\nexport function isNewFileInfo(\n\tfileInfo: INewFileInfo | IExistingFileInfo,\n): fileInfo is INewFileInfo {\n\treturn fileInfo.type === undefined || fileInfo.type === \"New\";\n}\n\nexport function getOdspResolvedUrl(resolvedUrl: IResolvedUrl): IOdspResolvedUrl {\n\tassert(\n\t\t(resolvedUrl as IOdspResolvedUrl).odspResolvedUrl === true,\n\t\t0x1de /* \"Not an ODSP resolved url\" */,\n\t);\n\treturn resolvedUrl as IOdspResolvedUrl;\n}\n\n/**\n * Type narrowing utility to determine if the provided {@link @fluidframework/driver-definitions#IResolvedUrl}\n * is an {@link @fluidframework/odsp-driver-definitions#IOdspResolvedUrl}.\n * @internal\n */\nexport function isOdspResolvedUrl(resolvedUrl: IResolvedUrl): resolvedUrl is IOdspResolvedUrl {\n\treturn \"odspResolvedUrl\" in resolvedUrl && resolvedUrl.odspResolvedUrl === true;\n}\n\nexport const createOdspLogger = (logger?: ITelemetryBaseLogger): ITelemetryLoggerExt =>\n\tcreateChildLogger({\n\t\tlogger,\n\t\tnamespace: \"OdspDriver\",\n\t\tproperties: {\n\t\t\tall: {\n\t\t\t\tdriverVersion,\n\t\t\t},\n\t\t},\n\t});\n\n/**\n * Returns a function that can be used to fetch storage token.\n * Storage token can not be empty - if original delegate (tokenFetcher argument) returns null result, exception will be thrown\n */\nexport function toInstrumentedOdspStorageTokenFetcher(\n\tlogger: ITelemetryLoggerExt,\n\tresolvedUrlParts: IOdspUrlParts,\n\ttokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n): InstrumentedStorageTokenFetcher {\n\tconst res = toInstrumentedOdspTokenFetcher(\n\t\tlogger,\n\t\tresolvedUrlParts,\n\t\ttokenFetcher,\n\t\ttrue, // throwOnNullToken\n\t\tfalse, // returnPlainToken\n\t);\n\t// Drop undefined from signature - we can do it safely due to throwOnNullToken == true above\n\treturn res as InstrumentedStorageTokenFetcher;\n}\n\n/**\n * Returns a function that can be used to fetch storage or websocket token.\n * There are scenarios where websocket token is not required / present (consumer stack and ordering service token),\n * thus it could return null. Use toInstrumentedOdspStorageTokenFetcher if you deal with storage token.\n * @param returnPlainToken - When true, tokenResponse.token is returned. When false, tokenResponse.authorizationHeader is returned or an authorization header value is created based on tokenResponse.token\n */\nexport function toInstrumentedOdspTokenFetcher(\n\tlogger: ITelemetryLoggerExt,\n\tresolvedUrlParts: IOdspUrlParts,\n\ttokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tthrowOnNullToken: boolean,\n\treturnPlainToken: boolean,\n): InstrumentedTokenFetcher {\n\treturn async (\n\t\toptions: TokenFetchOptions,\n\t\tname: string,\n\t\talwaysRecordTokenFetchTelemetry: boolean = false,\n\t) => {\n\t\t// Telemetry note: if options.refresh is true, there is a potential perf issue:\n\t\t// Host should optimize and provide non-expired tokens on all critical paths.\n\t\t// Exceptions: race conditions around expiration, revoked tokens, host that does not care\n\t\t// (fluid-fetcher)\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tlogger,\n\t\t\t{\n\t\t\t\teventName: `${name}_GetToken`,\n\t\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\t\thasClaims: !!options.claims,\n\t\t\t\thasTenantId: !!options.tenantId,\n\t\t\t},\n\t\t\tasync (event) =>\n\t\t\t\ttokenFetcher({\n\t\t\t\t\t...options,\n\t\t\t\t\t...resolvedUrlParts,\n\t\t\t\t}).then(\n\t\t\t\t\t(tokenResponse) => {\n\t\t\t\t\t\tconst returnVal = returnPlainToken\n\t\t\t\t\t\t\t? tokenFromResponse(tokenResponse)\n\t\t\t\t\t\t\t: authHeaderFromTokenResponse(tokenResponse);\n\t\t\t\t\t\t// This event alone generates so many events that is materially impacts cost of telemetry\n\t\t\t\t\t\t// Thus do not report end event when it comes back quickly.\n\t\t\t\t\t\t// Note that most of the hosts do not report if result is comming from cache or not,\n\t\t\t\t\t\t// so we can't rely on that here. But always record if specified explicitly for cases such as\n\t\t\t\t\t\t// calling trees/latest during load.\n\t\t\t\t\t\tif (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {\n\t\t\t\t\t\t\tevent.end({\n\t\t\t\t\t\t\t\tfromCache: isTokenFromCache(tokenResponse),\n\t\t\t\t\t\t\t\tisNull: returnVal === null,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (returnVal === null && throwOnNullToken) {\n\t\t\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\t\t// pre-0.58 error message: Token is null for ${name} call\n\t\t\t\t\t\t\t\t`The Host-provided token fetcher returned null`,\n\t\t\t\t\t\t\t\tOdspErrorTypes.fetchTokenError,\n\t\t\t\t\t\t\t\t{ method: name, driverVersion },\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn returnVal;\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\t// There is an important but unofficial contract here where token providers can set canRetry: true\n\t\t\t\t\t\t// to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\tconst rawCanRetry = error?.canRetry;\n\t\t\t\t\t\tconst tokenError = wrapError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t(errorMessage) =>\n\t\t\t\t\t\t\t\tnew NetworkErrorBasic(\n\t\t\t\t\t\t\t\t\t`The Host-provided token fetcher threw an error`,\n\t\t\t\t\t\t\t\t\tOdspErrorTypes.fetchTokenError,\n\t\t\t\t\t\t\t\t\ttypeof rawCanRetry === \"boolean\" ? rawCanRetry : false /* canRetry */,\n\t\t\t\t\t\t\t\t\t{ method: name, errorMessage, driverVersion },\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthrow tokenError;\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t{ cancel: \"generic\" },\n\t\t);\n\t};\n}\n\nexport function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry {\n\tconst cacheEntry: ICacheEntry = {\n\t\ttype: snapshotKey,\n\t\tkey: odspResolvedUrl.fileVersion ?? \"\",\n\t\tfile: {\n\t\t\tresolvedUrl: odspResolvedUrl,\n\t\t\tdocId: odspResolvedUrl.hashedDocumentId,\n\t\t},\n\t};\n\treturn cacheEntry;\n}\n\n// 80KB is the max body size that we can put in ump post body for server to be able to accept it.\n// Keeping it 78KB to be a little cautious. As per the telemetry 99p is less than 78KB.\nexport const maxUmpPostBodySize = 79872;\n\n/**\n * Build request parameters to request for the creation of a sharing link along with the creation of the file\n * through the /snapshot api call.\n * @param shareLinkType - Kind of sharing link requested\n * @returns A string of request parameters that can be concatenated with the base URI\n */\nexport function buildOdspShareLinkReqParams(\n\tshareLinkType: ISharingLinkKind | undefined,\n): string | undefined {\n\tif (!shareLinkType) {\n\t\treturn;\n\t}\n\tconst scope = shareLinkType.scope;\n\tlet shareLinkRequestParams = `createLinkScope=${scope}`;\n\tconst role = shareLinkType.role;\n\tshareLinkRequestParams = role\n\t\t? `${shareLinkRequestParams}&createLinkRole=${role}`\n\t\t: shareLinkRequestParams;\n\treturn shareLinkRequestParams;\n}\n\nexport function measure<T>(callback: () => T): [T, number] {\n\tconst start = performance.now();\n\tconst result = callback();\n\tconst time = performance.now() - start;\n\treturn [result, time];\n}\n\nexport async function measureP<T>(callback: () => Promise<T>): Promise<[T, number]> {\n\tconst start = performance.now();\n\tconst result = await callback();\n\tconst time = performance.now() - start;\n\treturn [result, time];\n}\n\nexport function getJoinSessionCacheKey(odspResolvedUrl: IOdspResolvedUrl): string {\n\treturn `${odspResolvedUrl.hashedDocumentId}/joinsession`;\n}\n\n/**\n * Utility API to check if the type of snapshot contents is `ISnapshot`.\n * @internal\n * @param obj - obj whose type needs to be identified.\n */\nexport function isInstanceOfISnapshot(\n\t// eslint-disable-next-line import/no-deprecated\n\tobj: ISnapshotContents | ISnapshot | undefined,\n): obj is ISnapshot {\n\treturn obj !== undefined && \"snapshotFormatV\" in obj && obj.snapshotFormatV === 1;\n}\n\n/**\n * This tells whether request if for a specific loading group or not. The snapshot which\n * we fetch on initial load, fetches all ungrouped content.\n */\nexport function isSnapshotFetchForLoadingGroup(\n\tloadingGroupIds: string[] | undefined,\n): boolean {\n\treturn loadingGroupIds !== undefined && loadingGroupIds.length > 0;\n}\n\n/*\n * This tells whether we are using legacy flow for fetching snapshot where we don't use\n * groupId query param in the trees latest network call.\n */\nexport function useLegacyFlowWithoutGroupsForSnapshotFetch(\n\tloadingGroupIds: string[] | undefined,\n): boolean {\n\treturn loadingGroupIds === undefined;\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/odsp-driver";
|
|
11
|
-
exports.pkgVersion = "2.0.
|
|
11
|
+
exports.pkgVersion = "2.0.3";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"2.0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"2.0.3\";\n"]}
|
|
@@ -15,7 +15,7 @@ import { OdspDocumentServiceFactory } from "./odspDocumentServiceFactory.js";
|
|
|
15
15
|
* @param getStorageToken - function that can provide the storage token for a given site. This is
|
|
16
16
|
* is also referred to as the "VROOM" token in SPO.
|
|
17
17
|
* @param persistedCache - Cache to store the fetched snapshot.
|
|
18
|
-
* @param forceAccessTokenViaAuthorizationHeader -
|
|
18
|
+
* @param forceAccessTokenViaAuthorizationHeader - @deprecated Not used, true value always used instead. Whether to force passing given token via authorization header.
|
|
19
19
|
* @param logger - Logger to have telemetry events.
|
|
20
20
|
* @param hostSnapshotFetchOptions - Options to fetch the snapshot if any. Otherwise default will be used.
|
|
21
21
|
* @param enableRedeemFallback - True to have the sharing link redeem fallback in case the Trees Latest/Redeem
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefetchLatestSnapshot.d.ts","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAC3E,OAAO,EAGN,eAAe,EACf,gBAAgB,EAChB,6BAA6B,EAC7B,YAAY,
|
|
1
|
+
{"version":3,"file":"prefetchLatestSnapshot.d.ts","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAC3E,OAAO,EAGN,eAAe,EACf,gBAAgB,EAChB,6BAA6B,EAC7B,YAAY,EAGZ,MAAM,kDAAkD,CAAC;AAO1D,OAAO,EAEN,yBAAyB,EAGzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAS7E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,sBAAsB,CAC3C,WAAW,EAAE,YAAY,EACzB,eAAe,EAAE,YAAY,CAAC,6BAA6B,CAAC,EAC5D,cAAc,EAAE,eAAe,EAC/B,sCAAsC,EAAE,OAAO,EAC/C,MAAM,EAAE,oBAAoB,EAC5B,wBAAwB,EAAE,gBAAgB,GAAG,SAAS,EACtD,oBAAoB,GAAE,OAAc,EACpC,yBAAyB,CAAC,EAAE,OAAO,EACnC,uBAAuB,CAAC,EAAE,yBAAyB,EACnD,0BAA0B,CAAC,EAAE,0BAA0B,GACrD,OAAO,CAAC,OAAO,CAAC,CA+GlB"}
|
|
@@ -19,7 +19,7 @@ const odspUtils_js_1 = require("./odspUtils.js");
|
|
|
19
19
|
* @param getStorageToken - function that can provide the storage token for a given site. This is
|
|
20
20
|
* is also referred to as the "VROOM" token in SPO.
|
|
21
21
|
* @param persistedCache - Cache to store the fetched snapshot.
|
|
22
|
-
* @param forceAccessTokenViaAuthorizationHeader -
|
|
22
|
+
* @param forceAccessTokenViaAuthorizationHeader - @deprecated Not used, true value always used instead. Whether to force passing given token via authorization header.
|
|
23
23
|
* @param logger - Logger to have telemetry events.
|
|
24
24
|
* @param hostSnapshotFetchOptions - Options to fetch the snapshot if any. Otherwise default will be used.
|
|
25
25
|
* @param enableRedeemFallback - True to have the sharing link redeem fallback in case the Trees Latest/Redeem
|
|
@@ -46,9 +46,9 @@ async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCac
|
|
|
46
46
|
driveId: odspResolvedUrl.driveId,
|
|
47
47
|
itemId: odspResolvedUrl.itemId,
|
|
48
48
|
};
|
|
49
|
-
const
|
|
50
|
-
const snapshotDownloader = async (finalOdspResolvedUrl,
|
|
51
|
-
return (0, fetchSnapshot_js_1.downloadSnapshot)(finalOdspResolvedUrl,
|
|
49
|
+
const getAuthHeader = (0, odspUtils_js_1.toInstrumentedOdspStorageTokenFetcher)(odspLogger, resolvedUrlData, getStorageToken);
|
|
50
|
+
const snapshotDownloader = async (finalOdspResolvedUrl, storageTokenFetcher, tokenFetchOptions, loadingGroupId, snapshotOptions, controller) => {
|
|
51
|
+
return (0, fetchSnapshot_js_1.downloadSnapshot)(finalOdspResolvedUrl, storageTokenFetcher, tokenFetchOptions, loadingGroupId, snapshotOptions, undefined, controller);
|
|
52
52
|
};
|
|
53
53
|
const snapshotKey = (0, odspUtils_js_1.createCacheSnapshotKey)(odspResolvedUrl);
|
|
54
54
|
let cacheP;
|
|
@@ -66,7 +66,7 @@ async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCac
|
|
|
66
66
|
const nonPersistentCacheKey = (0, internal_2.getKeyForCacheEntry)(snapshotKey);
|
|
67
67
|
const snapshotNonPersistentCache = odspDocumentServiceFactory?.snapshotPrefetchResultCache;
|
|
68
68
|
snapshotNonPersistentCache?.add(nonPersistentCacheKey, async () => snapshotContentsWithEpochP.promise);
|
|
69
|
-
await (0, fetchSnapshot_js_1.fetchSnapshotWithRedeem)(odspResolvedUrl,
|
|
69
|
+
await (0, fetchSnapshot_js_1.fetchSnapshotWithRedeem)(odspResolvedUrl, getAuthHeader, hostSnapshotFetchOptions, forceAccessTokenViaAuthorizationHeader, odspLogger, snapshotDownloader, putInCache, removeEntries, loadingGroupIds, enableRedeemFallback)
|
|
70
70
|
.then(async (value) => {
|
|
71
71
|
(0, internal_1.assert)(!!snapshotEpoch, 0x585 /* prefetched snapshot should have a valid epoch */);
|
|
72
72
|
snapshotContentsWithEpochP.resolve({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefetchLatestSnapshot.js","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAE3D,kEAAuE;AAEvE,+EAQ0D;AAC1D,uEAGkD;AAGlD,yDAK4B;AAG5B,iDAKwB;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,sBAAsB,CAC3C,WAAyB,EACzB,eAA4D,EAC5D,cAA+B,EAC/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mG;YACnG,kGAAkG;YAClG,mGAAmG;YACnG,2FAA2F;YAC3F,+FAA+F;YAC/F,qCAAqC;YACrC,UAAU,CAAC,GAAG,EAAE;gBACf,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC3D,CAAC,EAAE,IAAI,CAAC,CAAC;QACV,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,+DAA+D;YAC/D,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC1D,0BAA0B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,KAAK,CAAC;QACb,CAAC,CAAC,CAAC;QACJ,OAAO,IAAI,CAAC;IACb,CAAC,CACD,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACvB,UAAU,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,6BAA6B,EAAE,EAAE,KAAK,CAAC,CAAC;QAC/E,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC;AAxHD,wDAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIOdspResolvedUrl,\n\tIOdspUrlParts,\n\tIPersistedCache,\n\tISnapshotOptions,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n\tgetKeyForCacheEntry,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IVersionedValueWithEpoch } from \"./contracts.js\";\nimport {\n\tISnapshotRequestAndResponseOptions,\n\tSnapshotFormatSupportType,\n\tdownloadSnapshot,\n\tfetchSnapshotWithRedeem,\n} from \"./fetchSnapshot.js\";\nimport { IPrefetchSnapshotContents } from \"./odspCache.js\";\nimport { OdspDocumentServiceFactory } from \"./odspDocumentServiceFactory.js\";\nimport {\n\tcreateCacheSnapshotKey,\n\tcreateOdspLogger,\n\tgetOdspResolvedUrl,\n\ttoInstrumentedOdspStorageTokenFetcher,\n} from \"./odspUtils.js\";\n\n/**\n * Function to prefetch the snapshot and cached it in the persistant cache, so that when the container is loaded\n * the cached latest snapshot could be used and removes the network call from the critical path.\n *\n * @param resolvedUrl - Resolved url to fetch the snapshot.\n * @param getStorageToken - function that can provide the storage token for a given site. This is\n * is also referred to as the \"VROOM\" token in SPO.\n * @param persistedCache - Cache to store the fetched snapshot.\n * @param forceAccessTokenViaAuthorizationHeader - whether to force passing given token via authorization header.\n * @param logger - Logger to have telemetry events.\n * @param hostSnapshotFetchOptions - Options to fetch the snapshot if any. Otherwise default will be used.\n * @param enableRedeemFallback - True to have the sharing link redeem fallback in case the Trees Latest/Redeem\n * 1RT call fails with redeem error. During fallback it will first redeem the sharing link and then make\n * the Trees latest call.\n * Note: this can be considered deprecated - it will be replaced with `snapshotFormatFetchType`.\n * @param fetchBinarySnapshotFormat - Control if we want to fetch binary format snapshot.\n * @param snapshotFormatFetchType - Snapshot format to fetch.\n * @param odspDocumentServiceFactory - factory to access the non persistent cache and store the prefetch promise.\n *\n * @returns `true` if the snapshot is cached, `false` otherwise.\n * @alpha\n */\nexport async function prefetchLatestSnapshot(\n\tresolvedUrl: IResolvedUrl,\n\tgetStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tpersistedCache: IPersistedCache,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n\tlogger: ITelemetryBaseLogger,\n\thostSnapshotFetchOptions: ISnapshotOptions | undefined,\n\tenableRedeemFallback: boolean = true,\n\tfetchBinarySnapshotFormat?: boolean,\n\tsnapshotFormatFetchType?: SnapshotFormatSupportType,\n\todspDocumentServiceFactory?: OdspDocumentServiceFactory,\n): Promise<boolean> {\n\tconst mc = createChildMonitoringContext({ logger, namespace: \"PrefetchSnapshot\" });\n\tconst odspLogger = createOdspLogger(mc.logger);\n\tconst useGroupIdsForSnapshotFetch = mc.config.getBoolean(\n\t\t\"Fluid.Container.UseLoadingGroupIdForSnapshotFetch2\",\n\t);\n\t// For prefetch, we just want to fetch the ungrouped data and want to use the new API if the\n\t// feature gate is set, so provide an empty array.\n\tconst loadingGroupIds = useGroupIdsForSnapshotFetch ? [] : undefined;\n\tconst odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n\tconst resolvedUrlData: IOdspUrlParts = {\n\t\tsiteUrl: odspResolvedUrl.siteUrl,\n\t\tdriveId: odspResolvedUrl.driveId,\n\t\titemId: odspResolvedUrl.itemId,\n\t};\n\tconst storageTokenFetcher = toInstrumentedOdspStorageTokenFetcher(\n\t\todspLogger,\n\t\tresolvedUrlData,\n\t\tgetStorageToken,\n\t);\n\n\tconst snapshotDownloader = async (\n\t\tfinalOdspResolvedUrl: IOdspResolvedUrl,\n\t\tstorageToken: string,\n\t\tloadingGroupId: string[] | undefined,\n\t\tsnapshotOptions: ISnapshotOptions | undefined,\n\t\tcontroller?: AbortController,\n\t): Promise<ISnapshotRequestAndResponseOptions> => {\n\t\treturn downloadSnapshot(\n\t\t\tfinalOdspResolvedUrl,\n\t\t\tstorageToken,\n\t\t\tloadingGroupId,\n\t\t\tsnapshotOptions,\n\t\t\tundefined,\n\t\t\tcontroller,\n\t\t);\n\t};\n\tconst snapshotKey = createCacheSnapshotKey(odspResolvedUrl);\n\tlet cacheP: Promise<void> | undefined;\n\tlet snapshotEpoch: string | undefined;\n\tconst putInCache = async (valueWithEpoch: IVersionedValueWithEpoch): Promise<void> => {\n\t\tsnapshotEpoch = valueWithEpoch.fluidEpoch;\n\t\tcacheP = persistedCache.put(snapshotKey, valueWithEpoch);\n\t\treturn cacheP;\n\t};\n\n\tconst removeEntries = async (): Promise<void> =>\n\t\tpersistedCache.removeEntries(snapshotKey.file);\n\treturn PerformanceEvent.timedExecAsync(\n\t\todspLogger,\n\t\t{ eventName: \"PrefetchLatestSnapshot\" },\n\t\tasync () => {\n\t\t\tconst prefetchStartTime = performance.now();\n\t\t\t// Add the deferred promise to the cache, so that it can be leveraged while loading the container.\n\t\t\tconst snapshotContentsWithEpochP = new Deferred<IPrefetchSnapshotContents>();\n\t\t\tconst nonPersistentCacheKey = getKeyForCacheEntry(snapshotKey);\n\t\t\tconst snapshotNonPersistentCache =\n\t\t\t\todspDocumentServiceFactory?.snapshotPrefetchResultCache;\n\t\t\tsnapshotNonPersistentCache?.add(\n\t\t\t\tnonPersistentCacheKey,\n\t\t\t\tasync () => snapshotContentsWithEpochP.promise,\n\t\t\t);\n\t\t\tawait fetchSnapshotWithRedeem(\n\t\t\t\todspResolvedUrl,\n\t\t\t\tstorageTokenFetcher,\n\t\t\t\thostSnapshotFetchOptions,\n\t\t\t\tforceAccessTokenViaAuthorizationHeader,\n\t\t\t\todspLogger,\n\t\t\t\tsnapshotDownloader,\n\t\t\t\tputInCache,\n\t\t\t\tremoveEntries,\n\t\t\t\tloadingGroupIds,\n\t\t\t\tenableRedeemFallback,\n\t\t\t)\n\t\t\t\t.then(async (value) => {\n\t\t\t\t\tassert(!!snapshotEpoch, 0x585 /* prefetched snapshot should have a valid epoch */);\n\t\t\t\t\tsnapshotContentsWithEpochP.resolve({\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tfluidEpoch: snapshotEpoch,\n\t\t\t\t\t\tprefetchStartTime,\n\t\t\t\t\t});\n\t\t\t\t\tassert(cacheP !== undefined, 0x1e7 /* \"caching was not performed!\" */);\n\t\t\t\t\tawait cacheP;\n\t\t\t\t\t// Schedule it to remove from cache after 5s.\n\t\t\t\t\t// 1. While it's in snapshotNonPersistentCache: Load flow will use this value and will not attempt\n\t\t\t\t\t// to fetch snapshot from network again. That's the best from perf POV, but cache will not be\n\t\t\t\t\t// updated if we keep it in this cache, thus we want to eventually remove snapshot from this cache.\n\t\t\t\t\t// 2. After it's removed from snapshotNonPersistentCache: snapshot is present in persistent cache,\n\t\t\t\t\t// so we sill still use it (in accordance with cache policy controlled by host). But load flow will\n\t\t\t\t\t// also fetch snapshot (in parallel) from storage and update cache. This is fine long term,\n\t\t\t\t\t// but is an extra cost (unneeded network call). However since it is 5s older, new network call\n\t\t\t\t\t// will update the snapshot in cache.\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\t}, 5000);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\t// Remove it from the non persistent cache if an error occured.\n\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\tsnapshotContentsWithEpochP.reject(error);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\treturn true;\n\t\t},\n\t).catch(async (error) => {\n\t\todspLogger.sendErrorEvent({ eventName: \"PrefetchLatestSnapshotError\" }, error);\n\t\treturn false;\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prefetchLatestSnapshot.js","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAE3D,kEAAuE;AAEvE,+EAS0D;AAC1D,uEAGkD;AAGlD,yDAK4B;AAG5B,iDAMwB;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,sBAAsB,CAC3C,WAAyB,EACzB,eAA4D,EAC5D,cAA+B,EAC/B,sCAA+C,EAC/C,MAA4B,EAC5B,wBAAsD,EACtD,uBAAgC,IAAI,EACpC,yBAAmC,EACnC,uBAAmD,EACnD,0BAAuD;IAEvD,MAAM,EAAE,GAAG,IAAA,uCAA4B,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACnF,MAAM,UAAU,GAAG,IAAA,+BAAgB,E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,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,+DAA+D;YAC/D,0BAA0B,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC1D,0BAA0B,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,KAAK,CAAC;QACb,CAAC,CAAC,CAAC;QACJ,OAAO,IAAI,CAAC;IACb,CAAC,CACD,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACvB,UAAU,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,6BAA6B,EAAE,EAAE,KAAK,CAAC,CAAC;QAC/E,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC;AA1HD,wDA0HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIOdspResolvedUrl,\n\tIOdspUrlParts,\n\tIPersistedCache,\n\tISnapshotOptions,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n\tgetKeyForCacheEntry,\n\ttype InstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IVersionedValueWithEpoch } from \"./contracts.js\";\nimport {\n\tISnapshotRequestAndResponseOptions,\n\tSnapshotFormatSupportType,\n\tdownloadSnapshot,\n\tfetchSnapshotWithRedeem,\n} from \"./fetchSnapshot.js\";\nimport { IPrefetchSnapshotContents } from \"./odspCache.js\";\nimport { OdspDocumentServiceFactory } from \"./odspDocumentServiceFactory.js\";\nimport {\n\tcreateCacheSnapshotKey,\n\tcreateOdspLogger,\n\tgetOdspResolvedUrl,\n\ttoInstrumentedOdspStorageTokenFetcher,\n\ttype TokenFetchOptionsEx,\n} from \"./odspUtils.js\";\n\n/**\n * Function to prefetch the snapshot and cached it in the persistant cache, so that when the container is loaded\n * the cached latest snapshot could be used and removes the network call from the critical path.\n *\n * @param resolvedUrl - Resolved url to fetch the snapshot.\n * @param getStorageToken - function that can provide the storage token for a given site. This is\n * is also referred to as the \"VROOM\" token in SPO.\n * @param persistedCache - Cache to store the fetched snapshot.\n * @param forceAccessTokenViaAuthorizationHeader - @deprecated Not used, true value always used instead. Whether to force passing given token via authorization header.\n * @param logger - Logger to have telemetry events.\n * @param hostSnapshotFetchOptions - Options to fetch the snapshot if any. Otherwise default will be used.\n * @param enableRedeemFallback - True to have the sharing link redeem fallback in case the Trees Latest/Redeem\n * 1RT call fails with redeem error. During fallback it will first redeem the sharing link and then make\n * the Trees latest call.\n * Note: this can be considered deprecated - it will be replaced with `snapshotFormatFetchType`.\n * @param fetchBinarySnapshotFormat - Control if we want to fetch binary format snapshot.\n * @param snapshotFormatFetchType - Snapshot format to fetch.\n * @param odspDocumentServiceFactory - factory to access the non persistent cache and store the prefetch promise.\n *\n * @returns `true` if the snapshot is cached, `false` otherwise.\n * @alpha\n */\nexport async function prefetchLatestSnapshot(\n\tresolvedUrl: IResolvedUrl,\n\tgetStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tpersistedCache: IPersistedCache,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n\tlogger: ITelemetryBaseLogger,\n\thostSnapshotFetchOptions: ISnapshotOptions | undefined,\n\tenableRedeemFallback: boolean = true,\n\tfetchBinarySnapshotFormat?: boolean,\n\tsnapshotFormatFetchType?: SnapshotFormatSupportType,\n\todspDocumentServiceFactory?: OdspDocumentServiceFactory,\n): Promise<boolean> {\n\tconst mc = createChildMonitoringContext({ logger, namespace: \"PrefetchSnapshot\" });\n\tconst odspLogger = createOdspLogger(mc.logger);\n\tconst useGroupIdsForSnapshotFetch = mc.config.getBoolean(\n\t\t\"Fluid.Container.UseLoadingGroupIdForSnapshotFetch2\",\n\t);\n\t// For prefetch, we just want to fetch the ungrouped data and want to use the new API if the\n\t// feature gate is set, so provide an empty array.\n\tconst loadingGroupIds = useGroupIdsForSnapshotFetch ? [] : undefined;\n\tconst odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n\tconst resolvedUrlData: IOdspUrlParts = {\n\t\tsiteUrl: odspResolvedUrl.siteUrl,\n\t\tdriveId: odspResolvedUrl.driveId,\n\t\titemId: odspResolvedUrl.itemId,\n\t};\n\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\todspLogger,\n\t\tresolvedUrlData,\n\t\tgetStorageToken,\n\t);\n\n\tconst snapshotDownloader = async (\n\t\tfinalOdspResolvedUrl: IOdspResolvedUrl,\n\t\tstorageTokenFetcher: InstrumentedStorageTokenFetcher,\n\t\ttokenFetchOptions: TokenFetchOptionsEx,\n\t\tloadingGroupId: string[] | undefined,\n\t\tsnapshotOptions: ISnapshotOptions | undefined,\n\t\tcontroller?: AbortController,\n\t): Promise<ISnapshotRequestAndResponseOptions> => {\n\t\treturn downloadSnapshot(\n\t\t\tfinalOdspResolvedUrl,\n\t\t\tstorageTokenFetcher,\n\t\t\ttokenFetchOptions,\n\t\t\tloadingGroupId,\n\t\t\tsnapshotOptions,\n\t\t\tundefined,\n\t\t\tcontroller,\n\t\t);\n\t};\n\tconst snapshotKey = createCacheSnapshotKey(odspResolvedUrl);\n\tlet cacheP: Promise<void> | undefined;\n\tlet snapshotEpoch: string | undefined;\n\tconst putInCache = async (valueWithEpoch: IVersionedValueWithEpoch): Promise<void> => {\n\t\tsnapshotEpoch = valueWithEpoch.fluidEpoch;\n\t\tcacheP = persistedCache.put(snapshotKey, valueWithEpoch);\n\t\treturn cacheP;\n\t};\n\n\tconst removeEntries = async (): Promise<void> =>\n\t\tpersistedCache.removeEntries(snapshotKey.file);\n\treturn PerformanceEvent.timedExecAsync(\n\t\todspLogger,\n\t\t{ eventName: \"PrefetchLatestSnapshot\" },\n\t\tasync () => {\n\t\t\tconst prefetchStartTime = performance.now();\n\t\t\t// Add the deferred promise to the cache, so that it can be leveraged while loading the container.\n\t\t\tconst snapshotContentsWithEpochP = new Deferred<IPrefetchSnapshotContents>();\n\t\t\tconst nonPersistentCacheKey = getKeyForCacheEntry(snapshotKey);\n\t\t\tconst snapshotNonPersistentCache =\n\t\t\t\todspDocumentServiceFactory?.snapshotPrefetchResultCache;\n\t\t\tsnapshotNonPersistentCache?.add(\n\t\t\t\tnonPersistentCacheKey,\n\t\t\t\tasync () => snapshotContentsWithEpochP.promise,\n\t\t\t);\n\t\t\tawait fetchSnapshotWithRedeem(\n\t\t\t\todspResolvedUrl,\n\t\t\t\tgetAuthHeader,\n\t\t\t\thostSnapshotFetchOptions,\n\t\t\t\tforceAccessTokenViaAuthorizationHeader,\n\t\t\t\todspLogger,\n\t\t\t\tsnapshotDownloader,\n\t\t\t\tputInCache,\n\t\t\t\tremoveEntries,\n\t\t\t\tloadingGroupIds,\n\t\t\t\tenableRedeemFallback,\n\t\t\t)\n\t\t\t\t.then(async (value) => {\n\t\t\t\t\tassert(!!snapshotEpoch, 0x585 /* prefetched snapshot should have a valid epoch */);\n\t\t\t\t\tsnapshotContentsWithEpochP.resolve({\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tfluidEpoch: snapshotEpoch,\n\t\t\t\t\t\tprefetchStartTime,\n\t\t\t\t\t});\n\t\t\t\t\tassert(cacheP !== undefined, 0x1e7 /* \"caching was not performed!\" */);\n\t\t\t\t\tawait cacheP;\n\t\t\t\t\t// Schedule it to remove from cache after 5s.\n\t\t\t\t\t// 1. While it's in snapshotNonPersistentCache: Load flow will use this value and will not attempt\n\t\t\t\t\t// to fetch snapshot from network again. That's the best from perf POV, but cache will not be\n\t\t\t\t\t// updated if we keep it in this cache, thus we want to eventually remove snapshot from this cache.\n\t\t\t\t\t// 2. After it's removed from snapshotNonPersistentCache: snapshot is present in persistent cache,\n\t\t\t\t\t// so we sill still use it (in accordance with cache policy controlled by host). But load flow will\n\t\t\t\t\t// also fetch snapshot (in parallel) from storage and update cache. This is fine long term,\n\t\t\t\t\t// but is an extra cost (unneeded network call). However since it is 5s older, new network call\n\t\t\t\t\t// will update the snapshot in cache.\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\t}, 5000);\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\t// Remove it from the non persistent cache if an error occured.\n\t\t\t\t\tsnapshotNonPersistentCache?.remove(nonPersistentCacheKey);\n\t\t\t\t\tsnapshotContentsWithEpochP.reject(error);\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\treturn true;\n\t\t},\n\t).catch(async (error) => {\n\t\todspLogger.sendErrorEvent({ eventName: \"PrefetchLatestSnapshotError\" }, error);\n\t\treturn false;\n\t});\n}\n"]}
|
package/dist/vroom.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { TokenFetchOptionsEx } from "./odspUtils.js";
|
|
|
12
12
|
* @param path - The API path that is relevant to this request
|
|
13
13
|
* @param method - The type of request, such as GET or POST
|
|
14
14
|
* @param logger - A logger to use for this request
|
|
15
|
-
* @param
|
|
15
|
+
* @param getAuthHeader - A function that is able to provide the access token for this request
|
|
16
16
|
* @param epochTracker - fetch wrapper which incorporates epoch logic around joinSession call
|
|
17
17
|
* @param requestSocketToken - flag indicating whether joinSession is expected to return access token
|
|
18
18
|
* which is used when establishing websocket connection with collab session backend service.
|
|
@@ -22,5 +22,5 @@ import { TokenFetchOptionsEx } from "./odspUtils.js";
|
|
|
22
22
|
* @param guestDisplayName - display name used to identify guest user joining a session.
|
|
23
23
|
* This is optional and used only when collab session is being joined via invite.
|
|
24
24
|
*/
|
|
25
|
-
export declare function fetchJoinSession(urlParts: IOdspUrlParts, path: string, method:
|
|
25
|
+
export declare function fetchJoinSession(urlParts: IOdspUrlParts, path: string, method: "GET" | "POST", logger: ITelemetryLoggerExt, getAuthHeader: InstrumentedStorageTokenFetcher, epochTracker: EpochTracker, requestSocketToken: boolean, options: TokenFetchOptionsEx, disableJoinSessionRefresh: boolean | undefined, isRefreshingJoinSession: boolean): Promise<ISocketStorageDiscovery>;
|
|
26
26
|
//# sourceMappingURL=vroom.d.ts.map
|
package/dist/vroom.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vroom.d.ts","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,aAAa,EACb,uBAAuB,EACvB,+BAA+B,EAC/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CACrC,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"vroom.d.ts","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,aAAa,EACb,uBAAuB,EACvB,+BAA+B,EAC/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CACrC,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,GAAG,MAAM,EACtB,MAAM,EAAE,mBAAmB,EAC3B,aAAa,EAAE,+BAA+B,EAC9C,YAAY,EAAE,YAAY,EAC1B,kBAAkB,EAAE,OAAO,EAC3B,OAAO,EAAE,mBAAmB,EAC5B,yBAAyB,EAAE,OAAO,GAAG,SAAS,EAC9C,uBAAuB,EAAE,OAAO,GAC9B,OAAO,CAAC,uBAAuB,CAAC,CAgFlC"}
|
package/dist/vroom.js
CHANGED
|
@@ -15,7 +15,7 @@ const retryUtils_js_1 = require("./retryUtils.js");
|
|
|
15
15
|
* @param path - The API path that is relevant to this request
|
|
16
16
|
* @param method - The type of request, such as GET or POST
|
|
17
17
|
* @param logger - A logger to use for this request
|
|
18
|
-
* @param
|
|
18
|
+
* @param getAuthHeader - A function that is able to provide the access token for this request
|
|
19
19
|
* @param epochTracker - fetch wrapper which incorporates epoch logic around joinSession call
|
|
20
20
|
* @param requestSocketToken - flag indicating whether joinSession is expected to return access token
|
|
21
21
|
* which is used when establishing websocket connection with collab session backend service.
|
|
@@ -25,8 +25,10 @@ const retryUtils_js_1 = require("./retryUtils.js");
|
|
|
25
25
|
* @param guestDisplayName - display name used to identify guest user joining a session.
|
|
26
26
|
* This is optional and used only when collab session is being joined via invite.
|
|
27
27
|
*/
|
|
28
|
-
async function fetchJoinSession(urlParts, path, method, logger,
|
|
29
|
-
const
|
|
28
|
+
async function fetchJoinSession(urlParts, path, method, logger, getAuthHeader, epochTracker, requestSocketToken, options, disableJoinSessionRefresh, isRefreshingJoinSession) {
|
|
29
|
+
const apiRoot = (0, odspUrlHelper_js_1.getApiRoot)(new URL(urlParts.siteUrl));
|
|
30
|
+
const url = `${apiRoot}/drives/${urlParts.driveId}/items/${urlParts.itemId}/${path}?ump=1`;
|
|
31
|
+
const authHeader = await getAuthHeader({ ...options, request: { url, method } }, "JoinSession");
|
|
30
32
|
const tokenRefreshProps = options.refresh
|
|
31
33
|
? { hasClaims: !!options.claims, hasTenantId: !!options.tenantId }
|
|
32
34
|
: {};
|
|
@@ -42,10 +44,9 @@ async function fetchJoinSession(urlParts, path, method, logger, getStorageToken,
|
|
|
42
44
|
details: JSON.stringify(details),
|
|
43
45
|
...tokenRefreshProps,
|
|
44
46
|
}, async (event) => {
|
|
45
|
-
const apiRoot = (0, odspUrlHelper_js_1.getApiRoot)(new URL(urlParts.siteUrl));
|
|
46
47
|
const formBoundary = (0, uuid_1.v4)();
|
|
47
48
|
let postBody = `--${formBoundary}\r\n`;
|
|
48
|
-
postBody += `Authorization:
|
|
49
|
+
postBody += `Authorization: ${authHeader}\r\n`;
|
|
49
50
|
postBody += `X-HTTP-Method-Override: POST\r\n`;
|
|
50
51
|
postBody += `Content-Type: application/json\r\n`;
|
|
51
52
|
if (!disableJoinSessionRefresh) {
|
|
@@ -56,16 +57,13 @@ async function fetchJoinSession(urlParts, path, method, logger, getStorageToken,
|
|
|
56
57
|
const body = {
|
|
57
58
|
requestSocketToken: true,
|
|
58
59
|
};
|
|
59
|
-
if (guestDisplayName !== undefined) {
|
|
60
|
-
body.guestDisplayName = guestDisplayName;
|
|
61
|
-
}
|
|
62
60
|
postBody += `\r\n${JSON.stringify(body)}\r\n`;
|
|
63
61
|
}
|
|
64
62
|
postBody += `\r\n--${formBoundary}--`;
|
|
65
63
|
const headers = {
|
|
66
64
|
"Content-Type": `multipart/form-data;boundary=${formBoundary}`,
|
|
67
65
|
};
|
|
68
|
-
const response = await (0, retryUtils_js_1.runWithRetry)(async () => epochTracker.fetchAndParseAsJSON(
|
|
66
|
+
const response = await (0, retryUtils_js_1.runWithRetry)(async () => epochTracker.fetchAndParseAsJSON(url, { method, headers, body: postBody }, "joinSession", true), "joinSession", logger);
|
|
69
67
|
const socketUrl = response.content.deltaStreamSocketUrl;
|
|
70
68
|
// expecting socketUrl to be something like https://{hostName}/...
|
|
71
69
|
const webSocketHostName = socketUrl.split("/")[2];
|
package/dist/vroom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vroom.js","sourceRoot":"","sources":["../src/vroom.ts"],"names":[],"mappings":";AAAA;;;G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AAC,CAAC,CAAC,CAAC;QAElD,8BAA8B;QAC9B,KAAK,CAAC,GAAG,CAAC;YACT,GAAG,QAAQ,CAAC,UAAU;YACtB,2CAA2C;YAC3C,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;YACnC,iBAAiB;YACjB,6BAA6B,EAAE,QAAQ,CAAC,OAAO,CAAC,6BAA6B;SAC7E,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACpE,QAAQ,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC;QAC9D,CAAC;QAED,OAAO,QAAQ,CAAC,OAAO,CAAC;IACzB,CAAC,CACD,CAAC;AACH,CAAC;AA3FD,4CA2FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport {\n\tIOdspUrlParts,\n\tISocketStorageDiscovery,\n\tInstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { EpochTracker } from \"./epochTracker.js\";\nimport { getApiRoot } from \"./odspUrlHelper.js\";\nimport { TokenFetchOptionsEx } from \"./odspUtils.js\";\nimport { runWithRetry } from \"./retryUtils.js\";\n\ninterface IJoinSessionBody {\n\trequestSocketToken: boolean;\n\tguestDisplayName?: string;\n}\n\n/**\n * Makes join session call on SPO to get information about the web socket for a document\n * @param urlParts - The SPO drive id, itemId, siteUrl that this request should be made against\n * @param path - The API path that is relevant to this request\n * @param method - The type of request, such as GET or POST\n * @param logger - A logger to use for this request\n * @param getAuthHeader - A function that is able to provide the access token for this request\n * @param epochTracker - fetch wrapper which incorporates epoch logic around joinSession call\n * @param requestSocketToken - flag indicating whether joinSession is expected to return access token\n * which is used when establishing websocket connection with collab session backend service.\n * @param options - Options to fetch the token.\n * @param disableJoinSessionRefresh - Whether the caller wants to disable refreshing join session periodically.\n * @param isRefreshingJoinSession - whether call is to refresh the session before expiry.\n * @param guestDisplayName - display name used to identify guest user joining a session.\n * This is optional and used only when collab session is being joined via invite.\n */\nexport async function fetchJoinSession(\n\turlParts: IOdspUrlParts,\n\tpath: string,\n\tmethod: \"GET\" | \"POST\",\n\tlogger: ITelemetryLoggerExt,\n\tgetAuthHeader: InstrumentedStorageTokenFetcher,\n\tepochTracker: EpochTracker,\n\trequestSocketToken: boolean,\n\toptions: TokenFetchOptionsEx,\n\tdisableJoinSessionRefresh: boolean | undefined,\n\tisRefreshingJoinSession: boolean,\n): Promise<ISocketStorageDiscovery> {\n\tconst apiRoot = getApiRoot(new URL(urlParts.siteUrl));\n\tconst url = `${apiRoot}/drives/${urlParts.driveId}/items/${urlParts.itemId}/${path}?ump=1`;\n\tconst authHeader = await getAuthHeader(\n\t\t{ ...options, request: { url, method } },\n\t\t\"JoinSession\",\n\t);\n\n\tconst tokenRefreshProps = options.refresh\n\t\t? { hasClaims: !!options.claims, hasTenantId: !!options.tenantId }\n\t\t: {};\n\tconst details: ITelemetryBaseProperties = {\n\t\trefreshedToken: options.refresh,\n\t\trequestSocketToken,\n\t\t...tokenRefreshProps,\n\t\trefreshingSession: isRefreshingJoinSession,\n\t};\n\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{\n\t\t\teventName: \"JoinSession\",\n\t\t\tattempts: options.refresh ? 2 : 1,\n\t\t\tdetails: JSON.stringify(details),\n\t\t\t...tokenRefreshProps,\n\t\t},\n\t\tasync (event) => {\n\t\t\tconst formBoundary = uuid();\n\t\t\tlet postBody = `--${formBoundary}\\r\\n`;\n\t\t\tpostBody += `Authorization: ${authHeader}\\r\\n`;\n\t\t\tpostBody += `X-HTTP-Method-Override: POST\\r\\n`;\n\t\t\tpostBody += `Content-Type: application/json\\r\\n`;\n\t\t\tif (!disableJoinSessionRefresh) {\n\t\t\t\tpostBody += `prefer: FluidRemoveCheckAccess\\r\\n`;\n\t\t\t}\n\t\t\tpostBody += `_post: 1\\r\\n`;\n\n\t\t\tif (requestSocketToken) {\n\t\t\t\tconst body: IJoinSessionBody = {\n\t\t\t\t\trequestSocketToken: true,\n\t\t\t\t};\n\t\t\t\tpostBody += `\\r\\n${JSON.stringify(body)}\\r\\n`;\n\t\t\t}\n\t\t\tpostBody += `\\r\\n--${formBoundary}--`;\n\t\t\tconst headers: { [index: string]: string } = {\n\t\t\t\t\"Content-Type\": `multipart/form-data;boundary=${formBoundary}`,\n\t\t\t};\n\n\t\t\tconst response = await runWithRetry(\n\t\t\t\tasync () =>\n\t\t\t\t\tepochTracker.fetchAndParseAsJSON<ISocketStorageDiscovery>(\n\t\t\t\t\t\turl,\n\t\t\t\t\t\t{ method, headers, body: postBody },\n\t\t\t\t\t\t\"joinSession\",\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t),\n\t\t\t\t\"joinSession\",\n\t\t\t\tlogger,\n\t\t\t);\n\n\t\t\tconst socketUrl = response.content.deltaStreamSocketUrl;\n\t\t\t// expecting socketUrl to be something like https://{hostName}/...\n\t\t\tconst webSocketHostName = socketUrl.split(\"/\")[2];\n\n\t\t\t// TODO SPO-specific telemetry\n\t\t\tevent.end({\n\t\t\t\t...response.propsToLog,\n\t\t\t\t// pushV2 websocket urls will contain pushf\n\t\t\t\tpushv2: socketUrl.includes(\"pushf\"),\n\t\t\t\twebSocketHostName,\n\t\t\t\trefreshSessionDurationSeconds: response.content.refreshSessionDurationSeconds,\n\t\t\t});\n\n\t\t\tif (response.content.runtimeTenantId && !response.content.tenantId) {\n\t\t\t\tresponse.content.tenantId = response.content.runtimeTenantId;\n\t\t\t}\n\n\t\t\treturn response.content;\n\t\t},\n\t);\n}\n"]}
|
package/lib/createFile.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { INewFileInfo } from "./odspUtils.js";
|
|
|
12
12
|
* Creates a new Fluid file.
|
|
13
13
|
* Returns resolved url
|
|
14
14
|
*/
|
|
15
|
-
export declare function createNewFluidFile(
|
|
16
|
-
export declare function createNewEmptyFluidFile(
|
|
17
|
-
export declare function createNewFluidFileFromSummary(
|
|
15
|
+
export declare function createNewFluidFile(getAuthHeader: InstrumentedStorageTokenFetcher, newFileInfo: INewFileInfo, logger: ITelemetryLoggerExt, createNewSummary: ISummaryTree | undefined, epochTracker: EpochTracker, fileEntry: IFileEntry, createNewCaching: boolean, forceAccessTokenViaAuthorizationHeader: boolean, isClpCompliantApp?: boolean, enableSingleRequestForShareLinkWithCreate?: boolean): Promise<IOdspResolvedUrl>;
|
|
16
|
+
export declare function createNewEmptyFluidFile(getAuthHeader: InstrumentedStorageTokenFetcher, newFileInfo: INewFileInfo, logger: ITelemetryLoggerExt, epochTracker: EpochTracker): Promise<string>;
|
|
17
|
+
export declare function createNewFluidFileFromSummary(getAuthHeader: InstrumentedStorageTokenFetcher, newFileInfo: INewFileInfo, logger: ITelemetryLoggerExt, createNewSummary: ISummaryTree, epochTracker: EpochTracker, forceAccessTokenViaAuthorizationHeader: boolean): Promise<ICreateFileResponse>;
|
|
18
18
|
//# sourceMappingURL=createFile.d.ts.map
|
package/lib/createFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFile.d.ts","sourceRoot":"","sources":["../src/createFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGlE,OAAO,EACN,UAAU,EACV,gBAAgB,EAChB,+BAA+B,EAG/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQrD,OAAO,EAAE,YAAY,EAAE,M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