@fluidframework/odsp-driver 0.59.3003 → 0.59.4000
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/dist/WriteBufferUtils.js +1 -1
- package/dist/WriteBufferUtils.js.map +1 -1
- package/dist/createFile.d.ts +1 -1
- package/dist/createFile.d.ts.map +1 -1
- package/dist/createFile.js +36 -6
- package/dist/createFile.js.map +1 -1
- package/dist/fetchSnapshot.d.ts.map +1 -1
- package/dist/fetchSnapshot.js +2 -4
- package/dist/fetchSnapshot.js.map +1 -1
- package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/odspDocumentDeltaConnection.js +15 -2
- package/dist/odspDocumentDeltaConnection.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js +5 -1
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspSnapshotParser.js +1 -1
- package/dist/odspSnapshotParser.js.map +1 -1
- package/dist/odspUtils.d.ts +1 -0
- package/dist/odspUtils.d.ts.map +1 -1
- package/dist/odspUtils.js +8 -9
- 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.map +1 -1
- package/dist/prefetchLatestSnapshot.js +1 -1
- package/dist/prefetchLatestSnapshot.js.map +1 -1
- package/dist/zipItDataRepresentationUtils.js +2 -2
- package/dist/zipItDataRepresentationUtils.js.map +1 -1
- package/lib/WriteBufferUtils.js +1 -1
- package/lib/WriteBufferUtils.js.map +1 -1
- package/lib/createFile.d.ts +1 -1
- package/lib/createFile.d.ts.map +1 -1
- package/lib/createFile.js +37 -7
- package/lib/createFile.js.map +1 -1
- package/lib/fetchSnapshot.d.ts.map +1 -1
- package/lib/fetchSnapshot.js +2 -4
- package/lib/fetchSnapshot.js.map +1 -1
- package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
- package/lib/odspDocumentDeltaConnection.js +15 -2
- package/lib/odspDocumentDeltaConnection.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js +5 -1
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspSnapshotParser.js +1 -1
- package/lib/odspSnapshotParser.js.map +1 -1
- package/lib/odspUtils.d.ts +1 -0
- package/lib/odspUtils.d.ts.map +1 -1
- package/lib/odspUtils.js +7 -8
- 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.map +1 -1
- package/lib/prefetchLatestSnapshot.js +1 -1
- package/lib/prefetchLatestSnapshot.js.map +1 -1
- package/lib/zipItDataRepresentationUtils.js +2 -2
- package/lib/zipItDataRepresentationUtils.js.map +1 -1
- package/package.json +17 -15
- package/src/WriteBufferUtils.ts +1 -1
- package/src/createFile.ts +41 -5
- package/src/fetchSnapshot.ts +2 -4
- package/src/odspDocumentDeltaConnection.ts +14 -2
- package/src/odspDocumentServiceFactoryCore.ts +7 -0
- package/src/odspSnapshotParser.ts +1 -1
- package/src/odspUtils.ts +9 -8
- package/src/packageVersion.ts +1 -1
- package/src/prefetchLatestSnapshot.ts +1 -1
- package/src/zipItDataRepresentationUtils.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDocumentDeltaConnection.js","sourceRoot":"","sources":["../src/odspDocumentDeltaConnection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAgG;AAChG,6DAAsE;AAGtE,qEAA6F;AAS7F,+BAAkC;AAGlC,2CAAyD;AACzD,qDAA8C;AAE9C,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAClE,M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CAAC;QAEjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAEnE,IAAI,CAAC,mBAAmB,IAAI,IAAI,CAAC,UAAU,EAAE;YACzC,qEAAqE;YACrE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;SAC3E;QAED,MAAM,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;CACJ;AAtZD,kEAsZC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger, IEvent } from \"@fluidframework/common-definitions\";\nimport { assert, performance, Deferred, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { DocumentDeltaConnection } from \"@fluidframework/driver-base\";\nimport { OdspError } from \"@fluidframework/odsp-driver-definitions\";\nimport { IAnyDriverError } from \"@fluidframework/driver-utils\";\nimport { IFluidErrorBase, loggerToMonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport {\n IClient,\n IConnect,\n INack,\n ISequencedDocumentMessage,\n ISignalMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport type { Socket, io as SocketIOClientStatic } from \"socket.io-client\";\nimport { v4 as uuid } from \"uuid\";\nimport { IOdspSocketError, IGetOpsResponse, IFlushOpsResponse } from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { errorObjectFromSocketError } from \"./odspError\";\nimport { pkgVersion } from \"./packageVersion\";\n\nconst protocolVersions = [\"^0.4.0\", \"^0.3.0\", \"^0.2.0\", \"^0.1.0\"];\nconst feature_get_ops = \"api_get_ops\";\nconst feature_flush_ops = \"api_flush_ops\";\n\nexport interface FlushResult {\n lastPersistedSequenceNumber?: number;\n retryAfter?: number;\n}\n\n// How long to wait before disconnecting the socket after the last reference is removed\n// This allows reconnection after receiving a nack to be smooth\nconst socketReferenceBufferTime = 2000;\n\nexport interface ISocketEvents extends IEvent {\n (event: \"server_disconnect\", listener: (error: IFluidErrorBase & OdspError) => void);\n}\n\nclass SocketReference extends TypedEventEmitter<ISocketEvents> {\n private references: number = 1;\n private delayDeleteTimeout: ReturnType<typeof setTimeout> | undefined;\n private _socket: Socket | undefined;\n\n // When making decisions about socket reuse, we do not reuse disconnected socket.\n // But we want to differentiate the following case from disconnected case:\n // Socket that never connected and never failed, it's in \"attempting to connect\" mode\n // such sockets should be reused, despite socket.disconnected === true\n private isPendingInitialConnection = true;\n\n // Map of all existing socket io sockets. [url, tenantId, documentId] -> socket\n private static readonly socketIoSockets: Map<string, SocketReference> = new Map();\n\n public static find(key: string, logger: ITelemetryLogger) {\n const socketReference = SocketReference.socketIoSockets.get(key);\n\n // Verify the socket is healthy before reusing it\n if (socketReference?.disconnected) {\n // The socket is in a bad state. fully remove the reference\n socketReference.closeSocket();\n return undefined;\n }\n\n if (socketReference) {\n // Clear the pending deletion if there is one\n socketReference.clearTimer();\n socketReference.references++;\n }\n\n return socketReference;\n }\n\n /**\n * Removes a reference for the given key\n * Once the ref count hits 0, the socket is disconnected and removed\n * @param key - socket reference key\n * @param isFatalError - true if the socket reference should be removed immediately due to a fatal error\n */\n public removeSocketIoReference(isFatalError: boolean) {\n assert(this.references > 0, 0x09f /* \"No more socketIO refs to remove!\" */);\n this.references--;\n\n // see comment in disconnected() getter\n this.isPendingInitialConnection = false;\n\n if (isFatalError || this.disconnected) {\n this.closeSocket();\n return;\n }\n\n if (this.references === 0 && this.delayDeleteTimeout === undefined) {\n this.delayDeleteTimeout = setTimeout(() => {\n // We should not get here with active users.\n assert(this.references === 0, 0x0a0 /* \"Unexpected socketIO references on timeout\" */);\n this.closeSocket();\n }, socketReferenceBufferTime);\n }\n }\n\n public get socket() {\n if (!this._socket) {\n throw new Error(`Invalid socket for key \"${this.key}`);\n }\n return this._socket;\n }\n\n public constructor(public readonly key: string, socket: Socket) {\n super();\n\n this._socket = socket;\n assert(!SocketReference.socketIoSockets.has(key), 0x220 /* \"socket key collision\" */);\n SocketReference.socketIoSockets.set(key, this);\n\n // The server always closes the socket after sending this message\n // fully remove the socket reference now\n socket.on(\"server_disconnect\", (socketError: IOdspSocketError) => {\n // Treat all errors as recoverable, and rely on joinSession / reconnection flow to\n // filter out retryable vs. non-retryable cases.\n const error = errorObjectFromSocketError(socketError, \"server_disconnect\");\n error.canRetry = true;\n\n // see comment in disconnected() getter\n // Setting it here to ensure socket reuse does not happen if new request to connect\n // comes in from \"disconnect\" listener below, before we close socket.\n this.isPendingInitialConnection = false;\n\n // Explicitly cast error to the specified event args type to ensure type compatibility\n this.emit(\"server_disconnect\", error as IFluidErrorBase & OdspError);\n this.closeSocket();\n });\n }\n\n private clearTimer() {\n if (this.delayDeleteTimeout !== undefined) {\n clearTimeout(this.delayDeleteTimeout);\n this.delayDeleteTimeout = undefined;\n }\n }\n\n private closeSocket() {\n if (!this._socket) { return; }\n\n this.clearTimer();\n\n assert(SocketReference.socketIoSockets.get(this.key) === this,\n 0x0a1 /* \"Socket reference set unexpectedly does not point to this socket!\" */);\n SocketReference.socketIoSockets.delete(this.key);\n\n const socket = this._socket;\n this._socket = undefined;\n\n // Delay closing socket, to make sure all users of socket observe the same event that causes\n // this instance to close, and thus properly record reason for closure.\n // All event raising is synchronous, so clients will have a chance to react before socket is\n // closed without any extra data on why it was closed.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => { socket.disconnect(); });\n }\n\n private get disconnected() {\n if (this._socket === undefined) { return true; }\n if (this.socket.connected) { return false; }\n\n // We have a socket that is not connected. Possible cases:\n // 1) It was connected some time ago and lost connection. We do not want to reuse it.\n // 2) It failed to connect (was never connected).\n // 3) It was just created and never had a chance to connect - connection is in process.\n // We have to differentiate 1 from 2-3 (specifically 1 & 3) in order to be able to reuse socket in #3.\n // We will use the fact that socket had some activity. I.e. if socket disconnected, or client stopped using\n // socket, then removeSocketIoReference() will be called for it, and it will be the indiction that it's not #3.\n return !this.isPendingInitialConnection;\n }\n}\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class OdspDocumentDeltaConnection extends DocumentDeltaConnection {\n /**\n * Create a OdspDocumentDeltaConnection\n * If url #1 fails to connect, will try url #2 if applicable.\n *\n * @param tenantId - the ID of the tenant\n * @param documentId - document ID\n * @param token - authorization token for storage service\n * @param io - websocket library\n * @param client - information about the client\n * @param mode - mode of the client\n * @param url - websocket URL\n * @param telemetryLogger - optional telemetry logger\n * @param timeoutMs - time limit on making the connection\n * @param epochTracker - track epoch changes\n * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n */\n public static async create(\n tenantId: string,\n documentId: string,\n token: string | null,\n io: typeof SocketIOClientStatic,\n client: IClient,\n url: string,\n telemetryLogger: ITelemetryLogger,\n timeoutMs: number,\n epochTracker: EpochTracker,\n socketReferenceKeyPrefix: string | undefined): Promise<OdspDocumentDeltaConnection> {\n const mc = loggerToMonitoringContext(telemetryLogger);\n\n // enable multiplexing when the websocket url does not include the tenant/document id\n const parsedUrl = new URL(url);\n const enableMultiplexing = !parsedUrl.searchParams.has(\"documentId\") && !parsedUrl.searchParams.has(\"tenantId\");\n\n // do not include the specific tenant/doc id in the ref key when multiplexing\n // this will allow multiple documents to share the same websocket connection\n const key = socketReferenceKeyPrefix ? `${socketReferenceKeyPrefix},${url}` : url;\n const socketReferenceKey = enableMultiplexing ? key : `${key},${tenantId},${documentId}`;\n\n const socketReference = OdspDocumentDeltaConnection.getOrCreateSocketIoReference(\n io, timeoutMs, socketReferenceKey, url, enableMultiplexing, tenantId, documentId, telemetryLogger);\n\n const socket = socketReference.socket;\n\n const connectMessage: IConnect = {\n client,\n id: documentId,\n mode: client.mode,\n tenantId,\n token, // Token is going to indicate tenant level information, etc...\n versions: protocolVersions,\n nonce: uuid(),\n epoch: epochTracker.fluidEpoch,\n relayUserAgent: [client.details.environment, ` driverVersion:${pkgVersion}`].join(\";\"),\n };\n\n // Reference to this client supporting get_ops flow.\n connectMessage.supportedFeatures = { };\n if (mc.config.getBoolean(\"Fluid.Driver.Odsp.GetOpsEnabled\") !== false) {\n connectMessage.supportedFeatures[feature_get_ops] = true;\n }\n\n const deltaConnection = new OdspDocumentDeltaConnection(\n socket,\n documentId,\n socketReference,\n telemetryLogger,\n enableMultiplexing);\n\n try {\n await deltaConnection.initialize(connectMessage, timeoutMs);\n await epochTracker.validateEpochFromPush(deltaConnection.details);\n } catch (errorObject: any) {\n if (errorObject !== null && typeof errorObject === \"object\") {\n // We have to special-case error types here in terms of what is re-triable.\n // These errors have to re-retried, we just need new joinSession result to connect to right server:\n // 400: Invalid tenant or document id. The WebSocket is connected to a different document\n // Document is full (with retryAfter)\n // 404: Invalid document. The document \\\"local/w1-...\\\" does not exist\n // But this has to stay not-retriable:\n // 406: Unsupported client protocol. This path is the only gatekeeper, have to fail!\n // 409: Epoch Version Mismatch. Client epoch and server epoch does not match, so app needs\n // to be refreshed.\n // This one is fine either way\n // 401/403: Code will retry once with new token either way, then it becomes fatal - on this path\n // and on join Session path.\n // 501: (Fluid not enabled): this is fine either way, as joinSession is gatekeeper\n if (errorObject.statusCode === 400 || errorObject.statusCode === 404) {\n errorObject.canRetry = true;\n }\n }\n throw errorObject;\n }\n\n return deltaConnection;\n }\n\n private socketReference: SocketReference | undefined;\n\n private readonly requestOpsNoncePrefix: string;\n private pushCallCounter = 0;\n private readonly getOpsMap: Map<string, { start: number; from: number; to: number; }> = new Map();\n private flushOpNonce: string | undefined;\n private flushDeferred: Deferred<FlushResult> | undefined;\n\n /**\n * Error raising for socket.io issues\n */\n protected createErrorObject(handler: string, error?: any, canRetry = true): IAnyDriverError {\n // Note: we suspect the incoming error object is either:\n // - a socketError: add it to the OdspError object for driver to be able to parse it and reason over it.\n // - anything else: let base class handle it\n if (canRetry && Number.isInteger(error?.code) && typeof error?.message === \"string\") {\n return errorObjectFromSocketError(error as IOdspSocketError, handler);\n } else {\n return super.createErrorObject(handler, error, canRetry);\n }\n }\n\n /**\n * Gets or create a socket io connection for the given key\n */\n private static getOrCreateSocketIoReference(\n io: typeof SocketIOClientStatic,\n timeoutMs: number,\n key: string,\n url: string,\n enableMultiplexing: boolean,\n tenantId: string,\n documentId: string,\n logger: ITelemetryLogger,\n ): SocketReference {\n const existingSocketReference = SocketReference.find(key, logger);\n if (existingSocketReference) {\n return existingSocketReference;\n }\n\n const query = enableMultiplexing ? undefined : { documentId, tenantId };\n\n const socket = io(\n url,\n {\n multiplex: false, // Don't rely on socket.io built-in multiplexing\n query,\n reconnection: false,\n transports: [\"websocket\"],\n timeout: timeoutMs,\n });\n\n return new SocketReference(key, socket);\n }\n\n /**\n * @param socket - websocket to be used\n * @param documentId - ID of the document\n * @param details - details of the websocket connection\n * @param socketReferenceKey - socket reference key\n * @param enableMultiplexing - If the websocket is multiplexing multiple documents\n */\n private constructor(\n socket: Socket,\n documentId: string,\n socketReference: SocketReference,\n logger: ITelemetryLogger,\n private readonly enableMultiplexing?: boolean,\n ) {\n super(socket, documentId, logger);\n this.socketReference = socketReference;\n this.requestOpsNoncePrefix = `${uuid()}-`;\n }\n\n /**\n * Retrieves ops from PUSH\n * @param from - inclusive\n * @param to - exclusive\n * @returns ops retrieved\n */\n public requestOps(from: number, to: number) {\n // Given that to is exclusive, we should be asking for at least something!\n assert(to > from, 0x272 /* \"empty request\" */);\n\n // PUSH may disable this functionality\n // back-compat: remove cast to any once latest version of IConnected is consumed\n if ((this.details as any).supportedFeatures?.[feature_get_ops] !== true) {\n return;\n }\n\n this.pushCallCounter++;\n const nonce = `${this.requestOpsNoncePrefix}${this.pushCallCounter}`;\n const start = performance.now();\n\n // We may keep keep accumulating memory for nothing, if we are not getting responses.\n // Note that we should not have overlapping requests, as DeltaManager allows only one\n // outstanding request to storage, and that's the only way to get here.\n // But requests could be cancelled, and thus overlapping requests might be in the picture\n // If it happens, we do not care about stale requests.\n // So track some number of requests, but log if we get too many in flight - that likely\n // indicates an error somewhere.\n if (this.getOpsMap.size >= 5) {\n let time = start;\n let key: string | undefined;\n for (const [keyCandidate, value] of this.getOpsMap.entries()) {\n if (value.start <= time || key === undefined) {\n time = value.start;\n key = keyCandidate;\n }\n }\n const payloadToDelete = this.getOpsMap.get(key!)!;\n this.logger.sendErrorEvent({\n eventName: \"GetOpsTooMany\",\n nonce,\n from: payloadToDelete.from,\n to: payloadToDelete.to,\n length: payloadToDelete.to - payloadToDelete.from,\n duration: performance.now() - payloadToDelete.start,\n });\n this.getOpsMap.delete(key!);\n }\n this.getOpsMap.set(\n nonce,\n {\n start,\n from,\n to,\n },\n );\n this.socket.emit(\"get_ops\", this.clientId, {\n nonce,\n from,\n to: to - 1,\n });\n }\n\n public async flush(): Promise<FlushResult> {\n // back-compat: remove cast to any once latest version of IConnected is consumed\n if ((this.details as any).supportedFeatures?.[feature_flush_ops] !== true) {\n // Once single-commit summary is enabled end-to-end, flush support is a must!\n // The only alternative is change in design where SPO fetches ops from PUSH OR\n // summary includes required ops and SPO has some validation mechanism to ensure\n // they are not forged by client.\n // If design changes, we can reconsider it, but right now it's non-recoverable failure.\n this.logger.sendErrorEvent({ eventName: \"FlushOpsNotSupported\" });\n throw new Error(\"flush() API is not supported by PUSH, required for single-commit summaries\");\n }\n\n this.pushCallCounter++;\n const nonce = `${this.requestOpsNoncePrefix}${this.pushCallCounter}`;\n // There should be only one flush ops in flight, kicked out by upload summary workflow\n // That said, it could timeout and request could be repeated, so theoretically we can\n // get overlapping requests, but it should be very rare\n if (this.flushDeferred !== undefined) {\n this.logger.sendErrorEvent({ eventName: \"FlushOpsTooMany\" });\n this.flushDeferred.reject(\"process involving flush() was cancelled OR unsupported concurrency\");\n }\n this.socket.emit(\"flush_ops\", this.clientId, { nonce });\n\n this.flushOpNonce = nonce;\n this.flushDeferred = new Deferred<FlushResult>();\n return this.flushDeferred.promise;\n }\n\n protected serverDisconnectHandler = (error: IFluidErrorBase & OdspError) => {\n this.disposeCore(true, error);\n };\n\n protected async initialize(connectMessage: IConnect, timeout: number) {\n if (this.enableMultiplexing) {\n // multiplex compatible early handlers\n this.earlyOpHandler = (messageDocumentId: string, msgs: ISequencedDocumentMessage[]) => {\n if (this.documentId === messageDocumentId) {\n this.queuedMessages.push(...msgs);\n }\n };\n\n this.earlySignalHandler = (msg: ISignalMessage, messageDocumentId?: string) => {\n if (messageDocumentId === undefined || messageDocumentId === this.documentId) {\n this.queuedSignals.push(msg);\n }\n };\n }\n\n this.socketReference!.once(\"server_disconnect\", this.serverDisconnectHandler);\n\n this.socket.on(\"get_ops_response\", (result: IGetOpsResponse) => {\n const messages = result.messages;\n const data = this.getOpsMap.get(result.nonce);\n // Due to socket multiplexing, this client may not have asked for any data\n // If so, there it most likely does not need these ops (otherwise it already asked for them)\n // Also we may have deleted entry in this.getOpsMap due to too many requests and too slow response.\n // But not processing such result may push us into infinite loop of fast requests and dropping all responses\n if (data !== undefined || result.nonce.indexOf(this.requestOpsNoncePrefix) === 0) {\n this.getOpsMap.delete(result.nonce);\n const common = {\n eventName: \"GetOps\",\n // We need nonce only to pair with GetOpsTooMany events, i.e. when record was deleted\n nonce: data === undefined ? result.nonce : undefined,\n code: result.code,\n from: data?.from,\n to: data?.to,\n duration: data === undefined ? undefined : performance.now() - data.start,\n };\n if (messages !== undefined && messages.length > 0) {\n this.logger.sendPerformanceEvent({\n ...common,\n first: messages[0].sequenceNumber,\n last: messages[messages.length - 1].sequenceNumber,\n length: messages.length,\n });\n this.emit(\"op\", this.documentId, messages);\n } else {\n this.logger.sendPerformanceEvent({\n ...common,\n length: 0,\n });\n }\n }\n });\n\n this.socket.on(\"flush_ops_response\", (result: IFlushOpsResponse) => {\n if (this.flushOpNonce === result.nonce) {\n const seq = result.lastPersistedSequenceNumber;\n let category: \"generic\" | \"error\" = \"generic\";\n if (result.lastPersistedSequenceNumber === undefined || result.code !== 200) {\n switch (result.code) {\n case 409:\n case 429:\n category = \"error\";\n break;\n case 204:\n break;\n default:\n category = \"error\";\n break;\n }\n }\n this.logger.sendTelemetryEvent({\n eventName: \"FlushResult\",\n code: result.code,\n sequenceNumber: seq,\n category,\n });\n this.flushDeferred!.resolve(result);\n this.flushDeferred = undefined;\n this.flushOpNonce = undefined;\n }\n });\n\n await super.initialize(connectMessage, timeout);\n }\n\n protected addTrackedListener(event: string, listener: (...args: any[]) => void) {\n // override some event listeners in order to support multiple documents/clients over the same websocket\n switch (event) {\n case \"op\":\n // per document op handling\n super.addTrackedListener(event, (documentId: string, msgs: ISequencedDocumentMessage[]) => {\n if (!this.enableMultiplexing || this.documentId === documentId) {\n listener(documentId, msgs);\n }\n });\n break;\n\n case \"signal\":\n // per document signal handling\n super.addTrackedListener(event, (msg: ISignalMessage, documentId?: string) => {\n if (!this.enableMultiplexing || !documentId || documentId === this.documentId) {\n listener(msg, documentId);\n }\n });\n break;\n\n case \"nack\":\n // per client / document nack handling\n super.addTrackedListener(event, (clientIdOrDocumentId: string, message: INack[]) => {\n if (clientIdOrDocumentId.length === 0 ||\n clientIdOrDocumentId === this.documentId ||\n (this.hasDetails && clientIdOrDocumentId === this.clientId)) {\n this.emit(\"nack\", clientIdOrDocumentId, message);\n }\n });\n break;\n\n default:\n super.addTrackedListener(event, listener);\n break;\n }\n }\n\n /**\n * Disconnect from the websocket\n */\n protected disconnect(socketProtocolError: boolean, reason: IAnyDriverError) {\n const socket = this.socketReference;\n assert(socket !== undefined, 0x0a2 /* \"reentrancy not supported!\" */);\n this.socketReference = undefined;\n\n this.socket.off(\"server_disconnect\", this.serverDisconnectHandler);\n\n if (!socketProtocolError && this.hasDetails) {\n // tell the server we are disconnecting this client from the document\n this.socket.emit(\"disconnect_document\", this.clientId, this.documentId);\n }\n\n socket.removeSocketIoReference(socketProtocolError);\n this.emit(\"disconnect\", reason);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspDocumentDeltaConnection.js","sourceRoot":"","sources":["../src/odspDocumentDeltaConnection.ts"],"names":[],"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AAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;4BACxD,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;gCAC3B,SAAS,EAAE,YAAY;gCACvB,IAAI;gCACJ,IAAI;gCACJ,OAAO;gCACP,iBAAiB,EAAE,UAAU;6BAChC,CAAC,CAAC;yBACN;wBACD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;qBAClD;gBACL,CAAC,CAAC,CAAC;gBACH,MAAM;YAEV;gBACI,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAC1C,MAAM;SACb;IACL,CAAC;IAED;;OAEG;IACO,UAAU,CAAC,mBAA4B,EAAE,MAAuB;QACtE,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC;QACpC,IAAA,qBAAM,EAAC,MAAM,KAAK,SAAS,EAAE,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACtE,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QAEjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAEnE,IAAI,CAAC,mBAAmB,IAAI,IAAI,CAAC,UAAU,EAAE;YACzC,qEAAqE;YACrE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;SAC3E;QAED,MAAM,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;CACJ;AAlaD,kEAkaC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger, IEvent } from \"@fluidframework/common-definitions\";\nimport { assert, performance, Deferred, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { DocumentDeltaConnection } from \"@fluidframework/driver-base\";\nimport { OdspError } from \"@fluidframework/odsp-driver-definitions\";\nimport { IAnyDriverError } from \"@fluidframework/driver-utils\";\nimport { IFluidErrorBase, loggerToMonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport {\n IClient,\n IConnect,\n INack,\n ISequencedDocumentMessage,\n ISignalMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport type { Socket, io as SocketIOClientStatic } from \"socket.io-client\";\nimport { v4 as uuid } from \"uuid\";\nimport { IOdspSocketError, IGetOpsResponse, IFlushOpsResponse } from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { errorObjectFromSocketError } from \"./odspError\";\nimport { pkgVersion } from \"./packageVersion\";\n\nconst protocolVersions = [\"^0.4.0\", \"^0.3.0\", \"^0.2.0\", \"^0.1.0\"];\nconst feature_get_ops = \"api_get_ops\";\nconst feature_flush_ops = \"api_flush_ops\";\n\nexport interface FlushResult {\n lastPersistedSequenceNumber?: number;\n retryAfter?: number;\n}\n\n// How long to wait before disconnecting the socket after the last reference is removed\n// This allows reconnection after receiving a nack to be smooth\nconst socketReferenceBufferTime = 2000;\n\nexport interface ISocketEvents extends IEvent {\n (event: \"server_disconnect\", listener: (error: IFluidErrorBase & OdspError) => void);\n}\n\nclass SocketReference extends TypedEventEmitter<ISocketEvents> {\n private references: number = 1;\n private delayDeleteTimeout: ReturnType<typeof setTimeout> | undefined;\n private _socket: Socket | undefined;\n\n // When making decisions about socket reuse, we do not reuse disconnected socket.\n // But we want to differentiate the following case from disconnected case:\n // Socket that never connected and never failed, it's in \"attempting to connect\" mode\n // such sockets should be reused, despite socket.disconnected === true\n private isPendingInitialConnection = true;\n\n // Map of all existing socket io sockets. [url, tenantId, documentId] -> socket\n private static readonly socketIoSockets: Map<string, SocketReference> = new Map();\n\n public static find(key: string, logger: ITelemetryLogger) {\n const socketReference = SocketReference.socketIoSockets.get(key);\n\n // Verify the socket is healthy before reusing it\n if (socketReference?.disconnected) {\n // The socket is in a bad state. fully remove the reference\n socketReference.closeSocket();\n return undefined;\n }\n\n if (socketReference) {\n // Clear the pending deletion if there is one\n socketReference.clearTimer();\n socketReference.references++;\n }\n\n return socketReference;\n }\n\n /**\n * Removes a reference for the given key\n * Once the ref count hits 0, the socket is disconnected and removed\n * @param key - socket reference key\n * @param isFatalError - true if the socket reference should be removed immediately due to a fatal error\n */\n public removeSocketIoReference(isFatalError: boolean) {\n assert(this.references > 0, 0x09f /* \"No more socketIO refs to remove!\" */);\n this.references--;\n\n // see comment in disconnected() getter\n this.isPendingInitialConnection = false;\n\n if (isFatalError || this.disconnected) {\n this.closeSocket();\n return;\n }\n\n if (this.references === 0 && this.delayDeleteTimeout === undefined) {\n this.delayDeleteTimeout = setTimeout(() => {\n // We should not get here with active users.\n assert(this.references === 0, 0x0a0 /* \"Unexpected socketIO references on timeout\" */);\n this.closeSocket();\n }, socketReferenceBufferTime);\n }\n }\n\n public get socket() {\n if (!this._socket) {\n throw new Error(`Invalid socket for key \"${this.key}`);\n }\n return this._socket;\n }\n\n public constructor(public readonly key: string, socket: Socket) {\n super();\n\n this._socket = socket;\n assert(!SocketReference.socketIoSockets.has(key), 0x220 /* \"socket key collision\" */);\n SocketReference.socketIoSockets.set(key, this);\n\n // The server always closes the socket after sending this message\n // fully remove the socket reference now\n socket.on(\"server_disconnect\", (socketError: IOdspSocketError) => {\n // Treat all errors as recoverable, and rely on joinSession / reconnection flow to\n // filter out retryable vs. non-retryable cases.\n const error = errorObjectFromSocketError(socketError, \"server_disconnect\");\n error.canRetry = true;\n\n // see comment in disconnected() getter\n // Setting it here to ensure socket reuse does not happen if new request to connect\n // comes in from \"disconnect\" listener below, before we close socket.\n this.isPendingInitialConnection = false;\n\n // Explicitly cast error to the specified event args type to ensure type compatibility\n this.emit(\"server_disconnect\", error as IFluidErrorBase & OdspError);\n this.closeSocket();\n });\n }\n\n private clearTimer() {\n if (this.delayDeleteTimeout !== undefined) {\n clearTimeout(this.delayDeleteTimeout);\n this.delayDeleteTimeout = undefined;\n }\n }\n\n private closeSocket() {\n if (!this._socket) { return; }\n\n this.clearTimer();\n\n assert(SocketReference.socketIoSockets.get(this.key) === this,\n 0x0a1 /* \"Socket reference set unexpectedly does not point to this socket!\" */);\n SocketReference.socketIoSockets.delete(this.key);\n\n const socket = this._socket;\n this._socket = undefined;\n\n // Delay closing socket, to make sure all users of socket observe the same event that causes\n // this instance to close, and thus properly record reason for closure.\n // All event raising is synchronous, so clients will have a chance to react before socket is\n // closed without any extra data on why it was closed.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => { socket.disconnect(); });\n }\n\n private get disconnected() {\n if (this._socket === undefined) { return true; }\n if (this.socket.connected) { return false; }\n\n // We have a socket that is not connected. Possible cases:\n // 1) It was connected some time ago and lost connection. We do not want to reuse it.\n // 2) It failed to connect (was never connected).\n // 3) It was just created and never had a chance to connect - connection is in process.\n // We have to differentiate 1 from 2-3 (specifically 1 & 3) in order to be able to reuse socket in #3.\n // We will use the fact that socket had some activity. I.e. if socket disconnected, or client stopped using\n // socket, then removeSocketIoReference() will be called for it, and it will be the indiction that it's not #3.\n return !this.isPendingInitialConnection;\n }\n}\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class OdspDocumentDeltaConnection extends DocumentDeltaConnection {\n /**\n * Create a OdspDocumentDeltaConnection\n * If url #1 fails to connect, will try url #2 if applicable.\n *\n * @param tenantId - the ID of the tenant\n * @param documentId - document ID\n * @param token - authorization token for storage service\n * @param io - websocket library\n * @param client - information about the client\n * @param mode - mode of the client\n * @param url - websocket URL\n * @param telemetryLogger - optional telemetry logger\n * @param timeoutMs - time limit on making the connection\n * @param epochTracker - track epoch changes\n * @param socketReferenceKeyPrefix - (optional) prefix to isolate socket reuse cache\n */\n public static async create(\n tenantId: string,\n documentId: string,\n token: string | null,\n io: typeof SocketIOClientStatic,\n client: IClient,\n url: string,\n telemetryLogger: ITelemetryLogger,\n timeoutMs: number,\n epochTracker: EpochTracker,\n socketReferenceKeyPrefix: string | undefined): Promise<OdspDocumentDeltaConnection> {\n const mc = loggerToMonitoringContext(telemetryLogger);\n\n // enable multiplexing when the websocket url does not include the tenant/document id\n const parsedUrl = new URL(url);\n const enableMultiplexing = !parsedUrl.searchParams.has(\"documentId\") && !parsedUrl.searchParams.has(\"tenantId\");\n\n // do not include the specific tenant/doc id in the ref key when multiplexing\n // this will allow multiple documents to share the same websocket connection\n const key = socketReferenceKeyPrefix ? `${socketReferenceKeyPrefix},${url}` : url;\n const socketReferenceKey = enableMultiplexing ? key : `${key},${tenantId},${documentId}`;\n\n const socketReference = OdspDocumentDeltaConnection.getOrCreateSocketIoReference(\n io, timeoutMs, socketReferenceKey, url, enableMultiplexing, tenantId, documentId, telemetryLogger);\n\n const socket = socketReference.socket;\n\n const connectMessage: IConnect = {\n client,\n id: documentId,\n mode: client.mode,\n tenantId,\n token, // Token is going to indicate tenant level information, etc...\n versions: protocolVersions,\n nonce: uuid(),\n epoch: epochTracker.fluidEpoch,\n relayUserAgent: [client.details.environment, ` driverVersion:${pkgVersion}`].join(\";\"),\n };\n\n // Reference to this client supporting get_ops flow.\n connectMessage.supportedFeatures = { };\n if (mc.config.getBoolean(\"Fluid.Driver.Odsp.GetOpsEnabled\") !== false) {\n connectMessage.supportedFeatures[feature_get_ops] = true;\n }\n\n const deltaConnection = new OdspDocumentDeltaConnection(\n socket,\n documentId,\n socketReference,\n telemetryLogger,\n enableMultiplexing);\n\n try {\n await deltaConnection.initialize(connectMessage, timeoutMs);\n await epochTracker.validateEpochFromPush(deltaConnection.details);\n } catch (errorObject: any) {\n if (errorObject !== null && typeof errorObject === \"object\") {\n // We have to special-case error types here in terms of what is re-triable.\n // These errors have to re-retried, we just need new joinSession result to connect to right server:\n // 400: Invalid tenant or document id. The WebSocket is connected to a different document\n // Document is full (with retryAfter)\n // 404: Invalid document. The document \\\"local/w1-...\\\" does not exist\n // But this has to stay not-retriable:\n // 406: Unsupported client protocol. This path is the only gatekeeper, have to fail!\n // 409: Epoch Version Mismatch. Client epoch and server epoch does not match, so app needs\n // to be refreshed.\n // This one is fine either way\n // 401/403: Code will retry once with new token either way, then it becomes fatal - on this path\n // and on join Session path.\n // 501: (Fluid not enabled): this is fine either way, as joinSession is gatekeeper\n if (errorObject.statusCode === 400 || errorObject.statusCode === 404) {\n errorObject.canRetry = true;\n }\n }\n throw errorObject;\n }\n\n return deltaConnection;\n }\n\n private socketReference: SocketReference | undefined;\n\n private readonly requestOpsNoncePrefix: string;\n private pushCallCounter = 0;\n private readonly getOpsMap: Map<string, { start: number; from: number; to: number; }> = new Map();\n private flushOpNonce: string | undefined;\n private flushDeferred: Deferred<FlushResult> | undefined;\n\n /**\n * Error raising for socket.io issues\n */\n protected createErrorObject(handler: string, error?: any, canRetry = true): IAnyDriverError {\n // Note: we suspect the incoming error object is either:\n // - a socketError: add it to the OdspError object for driver to be able to parse it and reason over it.\n // - anything else: let base class handle it\n if (canRetry && Number.isInteger(error?.code) && typeof error?.message === \"string\") {\n return errorObjectFromSocketError(error as IOdspSocketError, handler);\n } else {\n return super.createErrorObject(handler, error, canRetry);\n }\n }\n\n /**\n * Gets or create a socket io connection for the given key\n */\n private static getOrCreateSocketIoReference(\n io: typeof SocketIOClientStatic,\n timeoutMs: number,\n key: string,\n url: string,\n enableMultiplexing: boolean,\n tenantId: string,\n documentId: string,\n logger: ITelemetryLogger,\n ): SocketReference {\n const existingSocketReference = SocketReference.find(key, logger);\n if (existingSocketReference) {\n return existingSocketReference;\n }\n\n const query = enableMultiplexing ? undefined : { documentId, tenantId };\n\n const socket = io(\n url,\n {\n multiplex: false, // Don't rely on socket.io built-in multiplexing\n query,\n reconnection: false,\n transports: [\"websocket\"],\n timeout: timeoutMs,\n });\n\n return new SocketReference(key, socket);\n }\n\n /**\n * @param socket - websocket to be used\n * @param documentId - ID of the document\n * @param details - details of the websocket connection\n * @param socketReferenceKey - socket reference key\n * @param enableMultiplexing - If the websocket is multiplexing multiple documents\n */\n private constructor(\n socket: Socket,\n documentId: string,\n socketReference: SocketReference,\n logger: ITelemetryLogger,\n private readonly enableMultiplexing?: boolean,\n ) {\n super(socket, documentId, logger);\n this.socketReference = socketReference;\n this.requestOpsNoncePrefix = `${uuid()}-`;\n }\n\n /**\n * Retrieves ops from PUSH\n * @param from - inclusive\n * @param to - exclusive\n * @returns ops retrieved\n */\n public requestOps(from: number, to: number) {\n // Given that to is exclusive, we should be asking for at least something!\n assert(to > from, 0x272 /* \"empty request\" */);\n\n // PUSH may disable this functionality\n // back-compat: remove cast to any once latest version of IConnected is consumed\n if ((this.details as any).supportedFeatures?.[feature_get_ops] !== true) {\n return;\n }\n\n this.pushCallCounter++;\n const nonce = `${this.requestOpsNoncePrefix}${this.pushCallCounter}`;\n const start = performance.now();\n\n // We may keep keep accumulating memory for nothing, if we are not getting responses.\n // Note that we should not have overlapping requests, as DeltaManager allows only one\n // outstanding request to storage, and that's the only way to get here.\n // But requests could be cancelled, and thus overlapping requests might be in the picture\n // If it happens, we do not care about stale requests.\n // So track some number of requests, but log if we get too many in flight - that likely\n // indicates an error somewhere.\n if (this.getOpsMap.size >= 5) {\n let time = start;\n let key: string | undefined;\n for (const [keyCandidate, value] of this.getOpsMap.entries()) {\n if (value.start <= time || key === undefined) {\n time = value.start;\n key = keyCandidate;\n }\n }\n const payloadToDelete = this.getOpsMap.get(key!)!;\n this.logger.sendErrorEvent({\n eventName: \"GetOpsTooMany\",\n nonce,\n from: payloadToDelete.from,\n to: payloadToDelete.to,\n length: payloadToDelete.to - payloadToDelete.from,\n duration: performance.now() - payloadToDelete.start,\n });\n this.getOpsMap.delete(key!);\n }\n this.getOpsMap.set(\n nonce,\n {\n start,\n from,\n to,\n },\n );\n this.socket.emit(\"get_ops\", this.clientId, {\n nonce,\n from,\n to: to - 1,\n });\n }\n\n public async flush(): Promise<FlushResult> {\n // back-compat: remove cast to any once latest version of IConnected is consumed\n if ((this.details as any).supportedFeatures?.[feature_flush_ops] !== true) {\n // Once single-commit summary is enabled end-to-end, flush support is a must!\n // The only alternative is change in design where SPO fetches ops from PUSH OR\n // summary includes required ops and SPO has some validation mechanism to ensure\n // they are not forged by client.\n // If design changes, we can reconsider it, but right now it's non-recoverable failure.\n this.logger.sendErrorEvent({ eventName: \"FlushOpsNotSupported\" });\n throw new Error(\"flush() API is not supported by PUSH, required for single-commit summaries\");\n }\n\n this.pushCallCounter++;\n const nonce = `${this.requestOpsNoncePrefix}${this.pushCallCounter}`;\n // There should be only one flush ops in flight, kicked out by upload summary workflow\n // That said, it could timeout and request could be repeated, so theoretically we can\n // get overlapping requests, but it should be very rare\n if (this.flushDeferred !== undefined) {\n this.logger.sendErrorEvent({ eventName: \"FlushOpsTooMany\" });\n this.flushDeferred.reject(\"process involving flush() was cancelled OR unsupported concurrency\");\n }\n this.socket.emit(\"flush_ops\", this.clientId, { nonce });\n\n this.flushOpNonce = nonce;\n this.flushDeferred = new Deferred<FlushResult>();\n return this.flushDeferred.promise;\n }\n\n protected serverDisconnectHandler = (error: IFluidErrorBase & OdspError) => {\n this.logger.sendTelemetryEvent({ eventName: \"ServerDisconnect\" }, error);\n this.disposeCore(true, error);\n };\n\n protected async initialize(connectMessage: IConnect, timeout: number) {\n if (this.enableMultiplexing) {\n // multiplex compatible early handlers\n this.earlyOpHandler = (messageDocumentId: string, msgs: ISequencedDocumentMessage[]) => {\n if (this.documentId === messageDocumentId) {\n this.queuedMessages.push(...msgs);\n }\n };\n\n this.earlySignalHandler = (msg: ISignalMessage, messageDocumentId?: string) => {\n if (messageDocumentId === undefined || messageDocumentId === this.documentId) {\n this.queuedSignals.push(msg);\n }\n };\n }\n\n this.socketReference!.once(\"server_disconnect\", this.serverDisconnectHandler);\n\n this.socket.on(\"get_ops_response\", (result: IGetOpsResponse) => {\n const messages = result.messages;\n const data = this.getOpsMap.get(result.nonce);\n // Due to socket multiplexing, this client may not have asked for any data\n // If so, there it most likely does not need these ops (otherwise it already asked for them)\n // Also we may have deleted entry in this.getOpsMap due to too many requests and too slow response.\n // But not processing such result may push us into infinite loop of fast requests and dropping all responses\n if (data !== undefined || result.nonce.indexOf(this.requestOpsNoncePrefix) === 0) {\n this.getOpsMap.delete(result.nonce);\n const common = {\n eventName: \"GetOps\",\n // We need nonce only to pair with GetOpsTooMany events, i.e. when record was deleted\n nonce: data === undefined ? result.nonce : undefined,\n code: result.code,\n from: data?.from,\n to: data?.to,\n duration: data === undefined ? undefined : performance.now() - data.start,\n };\n if (messages !== undefined && messages.length > 0) {\n this.logger.sendPerformanceEvent({\n ...common,\n first: messages[0].sequenceNumber,\n last: messages[messages.length - 1].sequenceNumber,\n length: messages.length,\n });\n this.emit(\"op\", this.documentId, messages);\n } else {\n this.logger.sendPerformanceEvent({\n ...common,\n length: 0,\n });\n }\n }\n });\n\n this.socket.on(\"flush_ops_response\", (result: IFlushOpsResponse) => {\n if (this.flushOpNonce === result.nonce) {\n const seq = result.lastPersistedSequenceNumber;\n let category: \"generic\" | \"error\" = \"generic\";\n if (result.lastPersistedSequenceNumber === undefined || result.code !== 200) {\n switch (result.code) {\n case 409:\n case 429:\n category = \"error\";\n break;\n case 204:\n break;\n default:\n category = \"error\";\n break;\n }\n }\n this.logger.sendTelemetryEvent({\n eventName: \"FlushResult\",\n code: result.code,\n sequenceNumber: seq,\n category,\n });\n this.flushDeferred!.resolve(result);\n this.flushDeferred = undefined;\n this.flushOpNonce = undefined;\n }\n });\n\n await super.initialize(connectMessage, timeout);\n }\n\n protected addTrackedListener(event: string, listener: (...args: any[]) => void) {\n // override some event listeners in order to support multiple documents/clients over the same websocket\n switch (event) {\n case \"op\":\n // per document op handling\n super.addTrackedListener(event, (documentId: string, msgs: ISequencedDocumentMessage[]) => {\n if (!this.enableMultiplexing || this.documentId === documentId) {\n listener(documentId, msgs);\n }\n });\n break;\n\n case \"signal\":\n // per document signal handling\n super.addTrackedListener(event, (msg: ISignalMessage, documentId?: string) => {\n if (!this.enableMultiplexing || !documentId || documentId === this.documentId) {\n listener(msg, documentId);\n }\n });\n break;\n\n case \"nack\":\n // per client / document nack handling\n super.addTrackedListener(event, (clientIdOrDocumentId: string, nacks: INack[]) => {\n if (clientIdOrDocumentId.length === 0 ||\n clientIdOrDocumentId === this.documentId ||\n (this.hasDetails && clientIdOrDocumentId === this.clientId)) {\n const nackContent = nacks[0]?.content;\n if (nackContent !== undefined) {\n const { code, type, message, retryAfter } = nackContent;\n this.logger.sendTelemetryEvent({\n eventName: \"ServerNack\",\n code,\n type,\n message,\n retryAfterSeconds: retryAfter,\n });\n }\n this.emit(\"nack\", clientIdOrDocumentId, nacks);\n }\n });\n break;\n\n default:\n super.addTrackedListener(event, listener);\n break;\n }\n }\n\n /**\n * Disconnect from the websocket\n */\n protected disconnect(socketProtocolError: boolean, reason: IAnyDriverError) {\n const socket = this.socketReference;\n assert(socket !== undefined, 0x0a2 /* \"reentrancy not supported!\" */);\n this.socketReference = undefined;\n\n this.socket.off(\"server_disconnect\", this.serverDisconnectHandler);\n\n if (!socketProtocolError && this.hasDetails) {\n // tell the server we are disconnecting this client from the document\n this.socket.emit(\"disconnect_document\", this.clientId, this.documentId);\n }\n\n socket.removeSocketIoReference(socketProtocolError);\n this.emit(\"disconnect\", reason);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDocumentServiceFactoryCore.d.ts","sourceRoot":"","sources":["../src/odspDocumentServiceFactoryCore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EACH,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AASpE,OAAO,EAEH,6BAA6B,EAC7B,YAAY,EACZ,eAAe,EACf,iBAAiB,EAGpB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,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CAAC,GAAG,SAAS,EAC1E,iBAAiB,EAAE,MAAM,OAAO,CAAC,OAAO,oBAAoB,CAAC,EACpE,cAAc,GAAE,eAA4C,EACrD,UAAU,GAAE,iBAAsB;IAc1C,qBAAqB,CAC9B,WAAW,EAAE,YAAY,EACzB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,kBAAkB,CAAC,EAAE,OAAO,GAC7B,OAAO,CAAC,gBAAgB,CAAC;YAId,yBAAyB;CA+C1C"}
|
|
@@ -32,6 +32,7 @@ class OdspDocumentServiceFactoryCore {
|
|
|
32
32
|
* @param persistedCache - PersistedCache provided by host for use in this session.
|
|
33
33
|
*/
|
|
34
34
|
constructor(getStorageToken, getWebsocketToken, getSocketIOClient, persistedCache = new odspCache_1.LocalPersistentCache(), hostPolicy = {}) {
|
|
35
|
+
var _a;
|
|
35
36
|
this.getStorageToken = getStorageToken;
|
|
36
37
|
this.getWebsocketToken = getWebsocketToken;
|
|
37
38
|
this.getSocketIOClient = getSocketIOClient;
|
|
@@ -43,6 +44,9 @@ class OdspDocumentServiceFactoryCore {
|
|
|
43
44
|
// create the key to separate the socket reuse cache
|
|
44
45
|
this.socketReferenceKeyPrefix = (0, uuid_1.v4)();
|
|
45
46
|
}
|
|
47
|
+
// Set enableRedeemFallback by default as true.
|
|
48
|
+
this.hostPolicy.enableRedeemFallback = (_a = this.hostPolicy.enableRedeemFallback) !== null && _a !== void 0 ? _a : true;
|
|
49
|
+
this.hostPolicy.sessionOptions = Object.assign({ forceAccessTokenViaAuthorizationHeader: true }, this.hostPolicy.sessionOptions);
|
|
46
50
|
}
|
|
47
51
|
async createContainer(createNewSummary, createNewResolvedUrl, logger, clientIsSummarizer) {
|
|
48
52
|
var _a, _b;
|
|
@@ -84,7 +88,7 @@ class OdspDocumentServiceFactoryCore {
|
|
|
84
88
|
isWithSummaryUpload: true,
|
|
85
89
|
}, async (event) => {
|
|
86
90
|
var _a, _b;
|
|
87
|
-
odspResolvedUrl = await (0, createFile_1.createNewFluidFile)((0, odspUtils_1.toInstrumentedOdspTokenFetcher)(odspLogger, resolvedUrlData, this.getStorageToken, true /* throwOnNullToken */), newFileInfo, odspLogger, createNewSummary, cacheAndTracker.epochTracker, fileEntry, (_a = this.hostPolicy.cacheCreateNewSummary) !== null && _a !== void 0 ? _a : true, !!((_b = this.hostPolicy.sessionOptions) === null || _b === void 0 ? void 0 : _b.forceAccessTokenViaAuthorizationHeader));
|
|
91
|
+
odspResolvedUrl = await (0, createFile_1.createNewFluidFile)((0, odspUtils_1.toInstrumentedOdspTokenFetcher)(odspLogger, resolvedUrlData, this.getStorageToken, true /* throwOnNullToken */), newFileInfo, odspLogger, createNewSummary, cacheAndTracker.epochTracker, fileEntry, (_a = this.hostPolicy.cacheCreateNewSummary) !== null && _a !== void 0 ? _a : true, !!((_b = this.hostPolicy.sessionOptions) === null || _b === void 0 ? void 0 : _b.forceAccessTokenViaAuthorizationHeader), odspResolvedUrl.isClpCompliantApp);
|
|
88
92
|
const docService = this.createDocumentServiceCore(odspResolvedUrl, odspLogger, cacheAndTracker, clientIsSummarizer);
|
|
89
93
|
event.end({
|
|
90
94
|
docId: odspResolvedUrl.hashedDocumentId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDocumentServiceFactoryCore.js","sourceRoot":"","sources":["../src/odspDocumentServiceFactoryCore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,qEAGyC;AACzC,+DAGsC;AAWtC,+BAAkC;AAClC,2CAGqB;AACrB,iDAGwB;AACxB,+DAA4D;AAC5D,2CAAiH;AACjH,6CAAkD;AAElD;;;;;;GAMG;AACH,MAAa,8BAA8B;IAuFvC;;;;;;;;;OASG;IACH,YACqB,eAA4D,EAC5D,iBAA0E,EAC1E,iBAA6D,EACpE,iBAAkC,IAAI,gCAAoB,EAAE,EACrD,aAAgC,EAAE;QAJlC,oBAAe,GAAf,eAAe,CAA6C;QAC5D,sBAAiB,GAAjB,iBAAiB,CAAyD;QAC1E,sBAAi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X,CAAC,CAAC,KAAK,EAAE,OAA0B,EAAE,EAAE,CAAC,IAAA,0CAA8B,EAClE,UAAU,EACV,eAAe,EACf,IAAI,CAAC,iBAAkB,EACvB,KAAK,CAAC,sBAAsB,CAC/B,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QAEpC,OAAO,yCAAmB,CAAC,MAAM,CAC7B,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EACV,IAAI,CAAC,iBAAiB,EACtB,eAAe,CAAC,KAAK,EACrB,IAAI,CAAC,UAAU,EACf,eAAe,CAAC,YAAY,EAC5B,IAAI,CAAC,wBAAwB,EAC7B,kBAAkB,CACrB,CAAC;IACN,CAAC;CACJ;AArKD,wEAqKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n IDocumentService,\n IDocumentServiceFactory,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport {\n TelemetryLogger,\n PerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n getDocAttributesFromProtocolSummary,\n ensureFluidResolvedUrl,\n} from \"@fluidframework/driver-utils\";\nimport {\n TokenFetchOptions,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n IPersistedCache,\n HostStoragePolicy,\n IFileEntry,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport type { io as SocketIOClientStatic } from \"socket.io-client\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n LocalPersistentCache,\n NonPersistentCache,\n} from \"./odspCache\";\nimport {\n createOdspCacheAndTracker,\n ICacheAndTracker,\n} from \"./epochTracker\";\nimport { OdspDocumentService } from \"./odspDocumentService\";\nimport { INewFileInfo, getOdspResolvedUrl, createOdspLogger, toInstrumentedOdspTokenFetcher } from \"./odspUtils\";\nimport { createNewFluidFile } from \"./createFile\";\n\n/**\n * Factory for creating the sharepoint document service. Use this if you want to\n * use the sharepoint implementation.\n *\n * This constructor should be used by environments that support dynamic imports and that wish\n * to leverage code splitting as a means to keep bundles as small as possible.\n */\nexport class OdspDocumentServiceFactoryCore implements IDocumentServiceFactory {\n public readonly protocolName = \"fluid-odsp:\";\n\n private readonly nonPersistentCache = new NonPersistentCache();\n private readonly socketReferenceKeyPrefix?: string;\n\n public async createContainer(\n createNewSummary: ISummaryTree | undefined,\n createNewResolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(createNewResolvedUrl);\n\n let odspResolvedUrl = getOdspResolvedUrl(createNewResolvedUrl);\n const resolvedUrlData: IOdspUrlParts = {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n };\n const [, queryString] = odspResolvedUrl.url.split(\"?\");\n\n const searchParams = new URLSearchParams(queryString);\n const filePath = searchParams.get(\"path\");\n if (filePath === undefined || filePath === null) {\n throw new Error(\"File path should be provided!!\");\n }\n\n const protocolSummary = createNewSummary?.tree[\".protocol\"];\n if (protocolSummary) {\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary as ISummaryTree);\n if (documentAttributes?.sequenceNumber !== 0) {\n throw new Error(\"Seq number in detached ODSP container should be 0\");\n }\n }\n\n const newFileInfo: INewFileInfo = {\n driveId: odspResolvedUrl.driveId,\n siteUrl: odspResolvedUrl.siteUrl,\n filePath,\n filename: odspResolvedUrl.fileName,\n // set createLinkType to undefined if enableShareLinkWithCreate is set to false,\n // so that share link creation with create file can be enabled\n createLinkType: this.hostPolicy.enableShareLinkWithCreate ?\n odspResolvedUrl.shareLinkInfo?.createLink?.type : undefined,\n };\n\n const odspLogger = createOdspLogger(logger);\n\n const fileEntry: IFileEntry = { resolvedUrl: odspResolvedUrl, docId: odspResolvedUrl.hashedDocumentId };\n const cacheAndTracker = createOdspCacheAndTracker(\n this.persistedCache,\n this.nonPersistentCache,\n fileEntry,\n odspLogger);\n\n return PerformanceEvent.timedExecAsync(\n odspLogger,\n {\n eventName: \"CreateNew\",\n isWithSummaryUpload: true,\n },\n async (event) => {\n odspResolvedUrl = await createNewFluidFile(\n toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n this.getStorageToken,\n true /* throwOnNullToken */,\n ),\n newFileInfo,\n odspLogger,\n createNewSummary,\n cacheAndTracker.epochTracker,\n fileEntry,\n this.hostPolicy.cacheCreateNewSummary ?? true,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n const docService = this.createDocumentServiceCore(odspResolvedUrl, odspLogger,\n cacheAndTracker, clientIsSummarizer);\n event.end({\n docId: odspResolvedUrl.hashedDocumentId,\n });\n return docService;\n });\n }\n\n /**\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 getWebsocketToken - function that can provide a token for accessing the web socket. This is also\n * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n * response payload.\n * @param storageFetchWrapper - if not provided FetchWrapper will be used\n * @param deltasFetchWrapper - if not provided FetchWrapper will be used\n * @param persistedCache - PersistedCache provided by host for use in this session.\n */\n constructor(\n private readonly getStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n private readonly getWebsocketToken: TokenFetcher<OdspResourceTokenFetchOptions> | undefined,\n private readonly getSocketIOClient: () => Promise<typeof SocketIOClientStatic>,\n protected persistedCache: IPersistedCache = new LocalPersistentCache(),\n private readonly hostPolicy: HostStoragePolicy = {},\n ) {\n if (this.hostPolicy.isolateSocketCache === true) {\n // create the key to separate the socket reuse cache\n this.socketReferenceKeyPrefix = uuid();\n }\n }\n\n public async createDocumentService(\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n return this.createDocumentServiceCore(resolvedUrl, createOdspLogger(logger), undefined, clientIsSummarizer);\n }\n\n private async createDocumentServiceCore(\n resolvedUrl: IResolvedUrl,\n odspLogger: TelemetryLogger,\n cacheAndTrackerArg?: ICacheAndTracker,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n const resolvedUrlData: IOdspUrlParts = {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n };\n const cacheAndTracker = cacheAndTrackerArg ?? createOdspCacheAndTracker(\n this.persistedCache,\n this.nonPersistentCache,\n { resolvedUrl: odspResolvedUrl, docId: odspResolvedUrl.hashedDocumentId },\n odspLogger);\n\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n this.getStorageToken,\n true /* throwOnNullToken */,\n );\n\n const webSocketTokenFetcher = this.getWebsocketToken === undefined\n ? undefined\n : async (options: TokenFetchOptions) => toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n this.getWebsocketToken!,\n false /* throwOnNullToken */,\n )(options, \"GetWebsocketToken\");\n\n return OdspDocumentService.create(\n resolvedUrl,\n storageTokenFetcher,\n webSocketTokenFetcher,\n odspLogger,\n this.getSocketIOClient,\n cacheAndTracker.cache,\n this.hostPolicy,\n cacheAndTracker.epochTracker,\n this.socketReferenceKeyPrefix,\n clientIsSummarizer,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"odspDocumentServiceFactoryCore.js","sourceRoot":"","sources":["../src/odspDocumentServiceFactoryCore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,qEAGyC;AACzC,+DAGsC;AAWtC,+BAAkC;AAClC,2CAGqB;AACrB,iDAGwB;AACxB,+DAA4D;AAC5D,2CAAiH;AACjH,6CAAkD;AAElD;;;;;;GAMG;AACH,MAAa,8BAA8B;IAwFvC;;;;;;;;;OASG;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QACF,MAAM,eAAe,GAAG,kBAAkB,aAAlB,kBAAkB,cAAlB,kBAAkB,GAAI,IAAA,wCAAyB,EACnE,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,kBAAkB,EACvB,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,CAAC,gBAAgB,EAAE,EACzE,UAAU,CAAC,CAAC;QAEhB,MAAM,mBAAmB,GAAG,IAAA,0CAA8B,EACtD,UAAU,EACV,eAAe,EACf,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,sBAAsB,CAC9B,CAAC;QAEF,MAAM,qBAAqB,GAAG,IAAI,CAAC,iBAAiB,KAAK,SAAS;YAC9D,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,KAAK,EAAE,OAA0B,EAAE,EAAE,CAAC,IAAA,0CAA8B,EAClE,UAAU,EACV,eAAe,EACf,IAAI,CAAC,iBAAkB,EACvB,KAAK,CAAC,sBAAsB,CAC/B,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QAEpC,OAAO,yCAAmB,CAAC,MAAM,CAC7B,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EACV,IAAI,CAAC,iBAAiB,EACtB,eAAe,CAAC,KAAK,EACrB,IAAI,CAAC,UAAU,EACf,eAAe,CAAC,YAAY,EAC5B,IAAI,CAAC,wBAAwB,EAC7B,kBAAkB,CACrB,CAAC;IACN,CAAC;CACJ;AA5KD,wEA4KC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n IDocumentService,\n IDocumentServiceFactory,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport {\n TelemetryLogger,\n PerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n getDocAttributesFromProtocolSummary,\n ensureFluidResolvedUrl,\n} from \"@fluidframework/driver-utils\";\nimport {\n TokenFetchOptions,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n IPersistedCache,\n HostStoragePolicy,\n IFileEntry,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport type { io as SocketIOClientStatic } from \"socket.io-client\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n LocalPersistentCache,\n NonPersistentCache,\n} from \"./odspCache\";\nimport {\n createOdspCacheAndTracker,\n ICacheAndTracker,\n} from \"./epochTracker\";\nimport { OdspDocumentService } from \"./odspDocumentService\";\nimport { INewFileInfo, getOdspResolvedUrl, createOdspLogger, toInstrumentedOdspTokenFetcher } from \"./odspUtils\";\nimport { createNewFluidFile } from \"./createFile\";\n\n/**\n * Factory for creating the sharepoint document service. Use this if you want to\n * use the sharepoint implementation.\n *\n * This constructor should be used by environments that support dynamic imports and that wish\n * to leverage code splitting as a means to keep bundles as small as possible.\n */\nexport class OdspDocumentServiceFactoryCore implements IDocumentServiceFactory {\n public readonly protocolName = \"fluid-odsp:\";\n\n private readonly nonPersistentCache = new NonPersistentCache();\n private readonly socketReferenceKeyPrefix?: string;\n\n public async createContainer(\n createNewSummary: ISummaryTree | undefined,\n createNewResolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n ensureFluidResolvedUrl(createNewResolvedUrl);\n\n let odspResolvedUrl = getOdspResolvedUrl(createNewResolvedUrl);\n const resolvedUrlData: IOdspUrlParts = {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n };\n const [, queryString] = odspResolvedUrl.url.split(\"?\");\n\n const searchParams = new URLSearchParams(queryString);\n const filePath = searchParams.get(\"path\");\n if (filePath === undefined || filePath === null) {\n throw new Error(\"File path should be provided!!\");\n }\n\n const protocolSummary = createNewSummary?.tree[\".protocol\"];\n if (protocolSummary) {\n const documentAttributes = getDocAttributesFromProtocolSummary(protocolSummary as ISummaryTree);\n if (documentAttributes?.sequenceNumber !== 0) {\n throw new Error(\"Seq number in detached ODSP container should be 0\");\n }\n }\n\n const newFileInfo: INewFileInfo = {\n driveId: odspResolvedUrl.driveId,\n siteUrl: odspResolvedUrl.siteUrl,\n filePath,\n filename: odspResolvedUrl.fileName,\n // set createLinkType to undefined if enableShareLinkWithCreate is set to false,\n // so that share link creation with create file can be enabled\n createLinkType: this.hostPolicy.enableShareLinkWithCreate ?\n odspResolvedUrl.shareLinkInfo?.createLink?.type : undefined,\n };\n\n const odspLogger = createOdspLogger(logger);\n\n const fileEntry: IFileEntry = { resolvedUrl: odspResolvedUrl, docId: odspResolvedUrl.hashedDocumentId };\n const cacheAndTracker = createOdspCacheAndTracker(\n this.persistedCache,\n this.nonPersistentCache,\n fileEntry,\n odspLogger);\n\n return PerformanceEvent.timedExecAsync(\n odspLogger,\n {\n eventName: \"CreateNew\",\n isWithSummaryUpload: true,\n },\n async (event) => {\n odspResolvedUrl = await createNewFluidFile(\n toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n this.getStorageToken,\n true /* throwOnNullToken */,\n ),\n newFileInfo,\n odspLogger,\n createNewSummary,\n cacheAndTracker.epochTracker,\n fileEntry,\n this.hostPolicy.cacheCreateNewSummary ?? true,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n odspResolvedUrl.isClpCompliantApp,\n );\n const docService = this.createDocumentServiceCore(odspResolvedUrl, odspLogger,\n cacheAndTracker, clientIsSummarizer);\n event.end({\n docId: odspResolvedUrl.hashedDocumentId,\n });\n return docService;\n });\n }\n\n /**\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 getWebsocketToken - function that can provide a token for accessing the web socket. This is also\n * to as the \"Push\" token in SPO. If undefined then websocket token is expected to be returned with joinSession\n * response payload.\n * @param storageFetchWrapper - if not provided FetchWrapper will be used\n * @param deltasFetchWrapper - if not provided FetchWrapper will be used\n * @param persistedCache - PersistedCache provided by host for use in this session.\n */\n constructor(\n private readonly getStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n private readonly getWebsocketToken: TokenFetcher<OdspResourceTokenFetchOptions> | undefined,\n private readonly getSocketIOClient: () => Promise<typeof SocketIOClientStatic>,\n protected persistedCache: IPersistedCache = new LocalPersistentCache(),\n private readonly hostPolicy: HostStoragePolicy = {},\n ) {\n if (this.hostPolicy.isolateSocketCache === true) {\n // create the key to separate the socket reuse cache\n this.socketReferenceKeyPrefix = uuid();\n }\n // Set enableRedeemFallback by default as true.\n this.hostPolicy.enableRedeemFallback = this.hostPolicy.enableRedeemFallback ?? true;\n this.hostPolicy.sessionOptions = {\n forceAccessTokenViaAuthorizationHeader: true,\n ...this.hostPolicy.sessionOptions,\n };\n }\n\n public async createDocumentService(\n resolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n return this.createDocumentServiceCore(resolvedUrl, createOdspLogger(logger), undefined, clientIsSummarizer);\n }\n\n private async createDocumentServiceCore(\n resolvedUrl: IResolvedUrl,\n odspLogger: TelemetryLogger,\n cacheAndTrackerArg?: ICacheAndTracker,\n clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n const resolvedUrlData: IOdspUrlParts = {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n };\n const cacheAndTracker = cacheAndTrackerArg ?? createOdspCacheAndTracker(\n this.persistedCache,\n this.nonPersistentCache,\n { resolvedUrl: odspResolvedUrl, docId: odspResolvedUrl.hashedDocumentId },\n odspLogger);\n\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n this.getStorageToken,\n true /* throwOnNullToken */,\n );\n\n const webSocketTokenFetcher = this.getWebsocketToken === undefined\n ? undefined\n : async (options: TokenFetchOptions) => toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n this.getWebsocketToken!,\n false /* throwOnNullToken */,\n )(options, \"GetWebsocketToken\");\n\n return OdspDocumentService.create(\n resolvedUrl,\n storageTokenFetcher,\n webSocketTokenFetcher,\n odspLogger,\n this.getSocketIOClient,\n cacheAndTracker.cache,\n this.hostPolicy,\n cacheAndTracker.epochTracker,\n this.socketReferenceKeyPrefix,\n clientIsSummarizer,\n );\n }\n}\n"]}
|
|
@@ -51,7 +51,7 @@ function convertOdspSnapshotToSnapsohtTreeAndBlobs(odspSnapshot) {
|
|
|
51
51
|
if (odspSnapshot.blobs) {
|
|
52
52
|
odspSnapshot.blobs.forEach((blob) => {
|
|
53
53
|
var _a;
|
|
54
|
-
(0, common_utils_1.assert)(blob.encoding === "base64" || blob.encoding === undefined, 0x0a4 /*
|
|
54
|
+
(0, common_utils_1.assert)(blob.encoding === "base64" || blob.encoding === undefined, 0x0a4 /* Unexpected blob encoding type */);
|
|
55
55
|
blobsWithBufferContent.set(blob.id, (0, common_utils_1.stringToBuffer)(blob.content, (_a = blob.encoding) !== null && _a !== void 0 ? _a : "utf8"));
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspSnapshotParser.js","sourceRoot":"","sources":["../src/odspSnapshotParser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsE;AAKtE;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,QAA6B;IACjD,MAAM,MAAM,GAA2C,EAAE,CAAC;IAC1D,2FAA2F;IAC3F,MAAM,IAAI,GAAoB,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACrF,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAElB,KAAK,M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OAAO,CAAC;SAChC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;YAC9B,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;SAC5D;KACJ;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAgB,yCAAyC,CACrD,YAA2B;;IAE3B,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC9D,IAAI,YAAY,CAAC,KAAK,EAAE;QACpB,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;;YAChC,IAAA,qBAAM,EAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAC5D,KAAK,CAAC,mCAAmC,CAAC,CAAC;YAC/C,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAA,6BAAc,EAAC,IAAI,CAAC,OAAO,EAAE,MAAA,IAAI,CAAC,QAAQ,mCAAI,MAAM,CAAC,CAAC,CAAC;QAC/F,CAAC,CAAC,CAAC;KACN;IACD,MAAM,GAAG,GAAsB;QAC3B,KAAK,EAAE,sBAAsB;QAC7B,GAAG,EAAE,MAAA,MAAA,YAAY,CAAC,GAAG,0CAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,mCAAI,EAAE;QAC/C,cAAc,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,CAAC,CAAC,EAAE,cAAc;QACrD,YAAY,EAAE,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtD,CAAC;IACF,OAAO,GAAG,CAAC;AACf,CAAC;AAlBD,8FAkBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, stringToBuffer } from \"@fluidframework/common-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { IOdspSnapshot, IOdspSnapshotCommit, ISnapshotTreeEx } from \"./contracts\";\nimport { ISnapshotContents } from \"./odspUtils\";\n\n/**\n * Build a tree hierarchy base on a flat tree\n *\n * @param flatTree - a flat tree\n * @param blobsShaToPathCache - Map with blobs sha as keys and values as path of the blob.\n * @returns the hierarchical tree\n */\nfunction buildHierarchy(flatTree: IOdspSnapshotCommit): api.ISnapshotTree {\n const lookup: { [path: string]: api.ISnapshotTree; } = {};\n // id is required for root tree as it will be used to determine the version we loaded from.\n const root: ISnapshotTreeEx = { id: flatTree.id, blobs: {}, commits: {}, trees: {} };\n lookup[\"\"] = root;\n\n for (const entry of flatTree.entries) {\n const lastIndex = entry.path.lastIndexOf(\"/\");\n const entryPathDir = entry.path.slice(0, Math.max(0, lastIndex));\n const entryPathBase = entry.path.slice(lastIndex + 1);\n\n // ODSP snapshots are created breadth-first so we can assume we see tree nodes prior to their contents\n const node = lookup[entryPathDir];\n\n // Add in either the blob or tree\n if (entry.type === \"tree\") {\n const newTree: ISnapshotTreeEx = {\n blobs: {},\n trees: {},\n commits: {},\n unreferenced: entry.unreferenced,\n };\n node.trees[decodeURIComponent(entryPathBase)] = newTree;\n lookup[entry.path] = newTree;\n } else if (entry.type === \"blob\") {\n node.blobs[decodeURIComponent(entryPathBase)] = entry.id;\n }\n }\n\n return root;\n}\n\n/**\n * Converts existing IOdspSnapshot to snapshot tree, blob array and ops\n * @param odspSnapshot - snapshot\n */\nexport function convertOdspSnapshotToSnapsohtTreeAndBlobs(\n odspSnapshot: IOdspSnapshot,\n): ISnapshotContents {\n const blobsWithBufferContent = new Map<string, ArrayBuffer>();\n if (odspSnapshot.blobs) {\n odspSnapshot.blobs.forEach((blob) => {\n assert(blob.encoding === \"base64\" || blob.encoding === undefined,\n 0x0a4 /* Unexpected blob encoding type */);\n blobsWithBufferContent.set(blob.id, stringToBuffer(blob.content, blob.encoding ?? \"utf8\"));\n });\n }\n const val: ISnapshotContents = {\n blobs: blobsWithBufferContent,\n ops: odspSnapshot.ops?.map((op) => op.op) ?? [],\n sequenceNumber: odspSnapshot?.trees[0].sequenceNumber,\n snapshotTree: buildHierarchy(odspSnapshot.trees[0]),\n };\n return val;\n}\n"]}
|
package/dist/odspUtils.d.ts
CHANGED
|
@@ -68,4 +68,5 @@ export declare function evalBlobsAndTrees(snapshot: IOdspSnapshot): {
|
|
|
68
68
|
};
|
|
69
69
|
export declare function toInstrumentedOdspTokenFetcher(logger: ITelemetryLogger, resolvedUrlParts: IOdspUrlParts, tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>, throwOnNullToken: boolean): InstrumentedStorageTokenFetcher;
|
|
70
70
|
export declare function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry;
|
|
71
|
+
export declare const maxUmpPostBodySize = 79872;
|
|
71
72
|
//# sourceMappingURL=odspUtils.d.ts.map
|
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;AAEH,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAClH,OAAO,EAAE,YAAY,EAAmB,MAAM,oCAAoC,CAAC;AASnF,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAOhG,OAAO,EACH,gBAAgB,EAChB,iBAAiB,EAIjB,6BAA6B,EAC7B,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,+BAA+B,EAC/B,aAAa,EAChB,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAO,MAAM,iCAAiC,sCAAsC,CAAC;AAErF,4DAA4D;AAC5D,eAAO,MAAM,SAAS,QAAS,MA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,CA4B3B;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACnC;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,gBAAgB,CAG9E;AAED,eAAO,MAAM,gBAAgB,0GAQnB,CAAC;AAEX,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa;;;;;EAqBxD;AAED,wBAAgB,8BAA8B,CAC1C,MAAM,EAAE,gBAAgB,EACxB,gBAAgB,EAAE,aAAa,EAC/B,YAAY,EAAE,YAAY,CAAC,6BAA6B,CAAC,EACzD,gBAAgB,EAAE,OAAO,GAC1B,+BAA+B,CAkDjC;AAED,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,gBAAgB,GAAG,WAAW,CAUrF;AAID,eAAO,MAAM,kBAAkB,QAAQ,CAAC"}
|
package/dist/odspUtils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createCacheSnapshotKey = exports.toInstrumentedOdspTokenFetcher = exports.evalBlobsAndTrees = exports.createOdspLogger = exports.getOdspResolvedUrl = exports.fetchAndParseAsJSONHelper = exports.fetchArray = exports.fetchHelper = exports.getWithRetryForTokenRefresh = exports.getOrigin = exports.getWithRetryForTokenRefreshRepeat = void 0;
|
|
7
|
+
exports.maxUmpPostBodySize = exports.createCacheSnapshotKey = exports.toInstrumentedOdspTokenFetcher = exports.evalBlobsAndTrees = exports.createOdspLogger = exports.getOdspResolvedUrl = exports.fetchAndParseAsJSONHelper = exports.fetchArray = exports.fetchHelper = exports.getWithRetryForTokenRefresh = exports.getOrigin = exports.getWithRetryForTokenRefreshRepeat = void 0;
|
|
8
8
|
const driver_definitions_1 = require("@fluidframework/driver-definitions");
|
|
9
9
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
10
10
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
@@ -74,20 +74,14 @@ async function fetchHelper(requestInfo, requestInit) {
|
|
|
74
74
|
duration: common_utils_1.performance.now() - start,
|
|
75
75
|
};
|
|
76
76
|
}, (error) => {
|
|
77
|
-
|
|
78
|
-
// is pretty good indicator we are offline. Treating it as offline scenario will make it
|
|
79
|
-
// easier to see other errors in telemetry.
|
|
80
|
-
let online = (0, driver_utils_1.isOnline)();
|
|
77
|
+
const online = (0, driver_utils_1.isOnline)();
|
|
81
78
|
const errorText = `${error}`;
|
|
82
|
-
if (errorText === "TypeError: Failed to fetch") {
|
|
83
|
-
online = driver_utils_1.OnlineStatus.Offline;
|
|
84
|
-
}
|
|
85
79
|
// This error is thrown by fetch() when AbortSignal is provided and it gets cancelled
|
|
86
80
|
if (error.name === "AbortError") {
|
|
87
81
|
throw new driver_utils_1.RetryableError("Fetch Timeout (AbortError)", odsp_driver_definitions_1.OdspErrorType.fetchTimeout, { driverVersion: packageVersion_1.pkgVersion });
|
|
88
82
|
}
|
|
89
83
|
// TCP/IP timeout
|
|
90
|
-
if (errorText.
|
|
84
|
+
if (errorText.includes("ETIMEDOUT")) {
|
|
91
85
|
throw new driver_utils_1.RetryableError("Fetch Timeout (ETIMEDOUT)", odsp_driver_definitions_1.OdspErrorType.fetchTimeout, { driverVersion: packageVersion_1.pkgVersion });
|
|
92
86
|
}
|
|
93
87
|
//
|
|
@@ -101,6 +95,8 @@ async function fetchHelper(requestInfo, requestInit) {
|
|
|
101
95
|
`ODSP fetch failure (Offline): ${errorText}`, driver_definitions_1.DriverErrorType.offlineError, { driverVersion: packageVersion_1.pkgVersion });
|
|
102
96
|
}
|
|
103
97
|
else {
|
|
98
|
+
// It is perhaps still possible that this is due to being offline, the error does not reveal enough
|
|
99
|
+
// information to conclude. Could also be DNS errors, malformed fetch request, CSP violation, etc.
|
|
104
100
|
throw new driver_utils_1.RetryableError(
|
|
105
101
|
// pre-0.58 error message prefix: Fetch error
|
|
106
102
|
`ODSP fetch failure: ${errorText}`, driver_definitions_1.DriverErrorType.fetchFailure, { driverVersion: packageVersion_1.pkgVersion });
|
|
@@ -240,4 +236,7 @@ function createCacheSnapshotKey(odspResolvedUrl) {
|
|
|
240
236
|
return cacheEntry;
|
|
241
237
|
}
|
|
242
238
|
exports.createCacheSnapshotKey = createCacheSnapshotKey;
|
|
239
|
+
// 80KB is the max body size that we can put in ump post body for server to be able to accept it.
|
|
240
|
+
// Keeping it 78KB to be a little cautious. As per the telemetry 99p is less than 78KB.
|
|
241
|
+
exports.maxUmpPostBodySize = 79872;
|
|
243
242
|
//# sourceMappingURL=odspUtils.js.map
|
package/dist/odspUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspUtils.js","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2EAAmF;AACnF,+DAMsC;AACtC,+DAAmE;AAEnE,qEAA2F;AAC3F,yEAI2C;AAC3C,qFAaiD;AACjD,mCAAgC;AAChC,qDAA+D;AAGlD,QAAA,iCAAiC,GAAG,mCAAmC,CAAC;AAErF,4DAA4D;AACrD,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;AAAjD,QAAA,SAAS,aAAwC;AAqB9D,SAAS,YAAY,CAAC,OAAgB;IAClC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE;QAC1C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;KAC9B;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAED;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AC;aACrF;YACD,IAAI,KAAK,KAAK,IAAI,IAAI,gBAAgB,EAAE;gBACpC,MAAM,IAAI,gCAAiB;gBACvB,yDAAyD;gBACzD,uCAAuC,IAAI,qBAAqB,EAChE,uCAAa,CAAC,eAAe,EAC7B,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAb,2BAAa,EAAE,CAAC,CAAC;aACxC;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACT,kGAAkG;YAClG,2FAA2F;YAC3F,MAAM,WAAW,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAC;YACpC,MAAM,UAAU,GAAG,IAAA,2BAAS,EACxB,KAAK,EACL,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,gCAAiB,CACnC,uCAAuC,IAAI,yBAAyB,YAAY,EAAE,EAClF,uCAAa,CAAC,eAAe,EAC7B,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,EACrE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAb,2BAAa,EAAE,CAAC,CAAC,CAAC;YAC1C,MAAM,UAAU,CAAC;QACrB,CAAC,CAAC,EACF,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC;AAvDD,wEAuDC;AAED,SAAgB,sBAAsB,CAAC,eAAiC;IACpE,MAAM,UAAU,GAAgB;QAC5B,IAAI,EAAE,qCAAW;QACjB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,KAAK,EAAE,eAAe,CAAC,gBAAgB;SAC1C;KACJ,CAAC;IACF,OAAO,UAAU,CAAC;AACtB,CAAC;AAVD,wDAUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties, ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IResolvedUrl, DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n isOnline,\n OnlineStatus,\n RetryableError,\n NonRetryableError,\n NetworkErrorBasic,\n} from \"@fluidframework/driver-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger, PerformanceEvent, wrapError } from \"@fluidframework/telemetry-utils\";\nimport {\n fetchIncorrectResponse,\n throwOdspNetworkError,\n getSPOAndGraphRequestIdsFromResponse,\n} from \"@fluidframework/odsp-doclib-utils\";\nimport {\n IOdspResolvedUrl,\n TokenFetchOptions,\n OdspErrorType,\n tokenFromResponse,\n isTokenFromCache,\n OdspResourceTokenFetchOptions,\n ShareLinkTypes,\n TokenFetcher,\n ICacheEntry,\n snapshotKey,\n InstrumentedStorageTokenFetcher,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { fetch } from \"./fetch\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { IOdspSnapshot } from \"./contracts\";\n\nexport const getWithRetryForTokenRefreshRepeat = \"getWithRetryForTokenRefreshRepeat\";\n\n/** Parse the given url and return the origin (host name) */\nexport const getOrigin = (url: string) => new URL(url).origin;\n\nexport interface ISnapshotContents {\n snapshotTree: ISnapshotTree;\n blobs: Map<string, ArrayBuffer>;\n ops: ISequencedDocumentMessage[];\n sequenceNumber: number | undefined;\n}\n\nexport interface IOdspResponse<T> {\n content: T;\n headers: Map<string, string>;\n propsToLog: ITelemetryProperties;\n duration: number;\n}\n\nexport interface TokenFetchOptionsEx extends TokenFetchOptions {\n /** previous error we hit in getWithRetryForTokenRefresh */\n previousError?: any;\n}\n\nfunction headersToMap(headers: Headers) {\n const newHeaders = new Map<string, string>();\n for (const [key, value] of headers.entries()) {\n newHeaders.set(key, value);\n }\n return 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>(get: (options: TokenFetchOptionsEx) => Promise<T>) {\n return get({ refresh: false }).catch(async (e) => {\n const options: TokenFetchOptionsEx = { refresh: true, previousError: e };\n switch (e.errorType) {\n // If the error is 401 or 403 refresh the token and try once more.\n case DriverErrorType.authorizationError:\n return get({ ...options, claims: e.claims, tenantId: e.tenantId });\n\n case DriverErrorType.incorrectServerResponse: // some error on the wire, retry once\n case OdspErrorType.fetchTokenError: // If the token was null, then retry once.\n return get(options);\n\n default:\n // Caller may determine that it wants one retry\n if (e[getWithRetryForTokenRefreshRepeat] === true) {\n return get(options);\n }\n throw e;\n }\n });\n}\n\nexport async function fetchHelper(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<Response>> {\n const start = performance.now();\n\n // Node-fetch and dom have conflicting typing, force them to work by casting for now\n return fetch(requestInfo, requestInit).then(async (fetchResponse) => {\n const response = fetchResponse as any as Response;\n // Let's assume we can retry.\n if (!response) {\n throw new NonRetryableError(\n // pre-0.58 error message: No response from fetch call\n \"No response from ODSP fetch call\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n if (!response.ok || response.status < 200 || response.status >= 300) {\n throwOdspNetworkError(\n // pre-0.58 error message prefix: odspFetchError\n `ODSP fetch error [${response.status}]`, response.status, response, await response.text());\n }\n\n const headers = headersToMap(response.headers);\n return {\n content: response,\n headers,\n propsToLog: getSPOAndGraphRequestIdsFromResponse(headers),\n duration: performance.now() - start,\n };\n }, (error) => {\n // While we do not know for sure whether computer is offline, this error is not actionable and\n // is pretty good indicator we are offline. Treating it as offline scenario will make it\n // easier to see other errors in telemetry.\n let online = isOnline();\n const errorText = `${error}`;\n if (errorText === \"TypeError: Failed to fetch\") {\n online = OnlineStatus.Offline;\n }\n // This error is thrown by fetch() when AbortSignal is provided and it gets cancelled\n if (error.name === \"AbortError\") {\n throw new RetryableError(\n \"Fetch Timeout (AbortError)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n // TCP/IP timeout\n if (errorText.indexOf(\"ETIMEDOUT\") !== -1) {\n throw new RetryableError(\n \"Fetch Timeout (ETIMEDOUT)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n\n //\n // WARNING: Do not log error object itself or any of its properties!\n // It could contain PII, like URI in message itself, or token in properties.\n // It is also non-serializable object due to circular references.\n //\n if (online === OnlineStatus.Offline) {\n throw new RetryableError(\n // pre-0.58 error message prefix: Offline\n `ODSP fetch failure (Offline): ${errorText}`, DriverErrorType.offlineError, { driverVersion });\n } else {\n throw new RetryableError(\n // pre-0.58 error message prefix: Fetch error\n `ODSP fetch failure: ${errorText}`, DriverErrorType.fetchFailure, { driverVersion });\n }\n });\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 requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<ArrayBuffer>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n\n const arrayBuffer = await content.arrayBuffer();\n propsToLog.bodySize = arrayBuffer.byteLength;\n return {\n headers,\n content: arrayBuffer,\n propsToLog,\n duration,\n };\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 requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<T>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n let text: string | undefined;\n try {\n text = await content.text();\n } catch (e) {\n // JSON.parse() can fail and message would container full request URI, including\n // tokens... It fails for me with \"Unexpected end of JSON input\" quite often - an attempt to download big file\n // (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always\n // succeeds on retry.\n // So do not log error object itself.\n throwOdspNetworkError(\n // pre-0.58 error message: errorWhileParsingFetchResponse\n \"Error while parsing fetch response\",\n fetchIncorrectResponse,\n content, // response\n text,\n );\n }\n\n propsToLog.bodySize = text.length;\n const res = {\n headers,\n content: JSON.parse(text),\n propsToLog,\n duration,\n };\n return res;\n}\n\nexport interface INewFileInfo {\n siteUrl: string;\n driveId: string;\n filename: string;\n filePath: string;\n /**\n * application can request creation of a share link along with the creation of a new file\n * by passing in an optional param to specify the kind of sharing link\n * (at the time of adding this comment Sept/2021), odsp only supports csl\n */\n createLinkType?: ShareLinkTypes;\n}\n\nexport function getOdspResolvedUrl(resolvedUrl: IResolvedUrl): IOdspResolvedUrl {\n assert((resolvedUrl as IOdspResolvedUrl).odspResolvedUrl === true, 0x1de /* \"Not an ODSP resolved url\" */);\n return resolvedUrl as IOdspResolvedUrl;\n}\n\nexport const createOdspLogger = (logger?: ITelemetryBaseLogger) =>\n ChildLogger.create(\n logger,\n \"OdspDriver\",\n { all:\n {\n driverVersion,\n },\n });\n\nexport function evalBlobsAndTrees(snapshot: IOdspSnapshot) {\n let numTrees = 0;\n let numBlobs = 0;\n let encodedBlobsSize = 0;\n let decodedBlobsSize = 0;\n for (const tree of snapshot.trees) {\n for (const treeEntry of tree.entries) {\n if (treeEntry.type === \"blob\") {\n numBlobs++;\n } else if (treeEntry.type === \"tree\") {\n numTrees++;\n }\n }\n }\n if (snapshot.blobs !== undefined) {\n for (const blob of snapshot.blobs) {\n decodedBlobsSize += blob.size;\n encodedBlobsSize += blob.content.length;\n }\n }\n return { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize };\n}\n\nexport function toInstrumentedOdspTokenFetcher(\n logger: ITelemetryLogger,\n resolvedUrlParts: IOdspUrlParts,\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n throwOnNullToken: boolean,\n): InstrumentedStorageTokenFetcher {\n return async (options: TokenFetchOptions, name: string, alwaysRecordTokenFetchTelemetry: boolean = false) => {\n // Telemetry note: if options.refresh is true, there is a potential perf issue:\n // Host should optimize and provide non-expired tokens on all critical paths.\n // Exceptions: race conditions around expiration, revoked tokens, host that does not care\n // (fluid-fetcher)\n return PerformanceEvent.timedExecAsync(\n logger,\n {\n eventName: `${name}_GetToken`,\n attempts: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n },\n async (event) => tokenFetcher({\n ...options,\n ...resolvedUrlParts,\n }).then((tokenResponse) => {\n const token = tokenFromResponse(tokenResponse);\n // This event alone generates so many events that is materially impacts cost of telemetry\n // Thus do not report end event when it comes back quickly.\n // Note that most of the hosts do not report if result is comming from cache or not,\n // so we can't rely on that here. But always record if specified explicitly for cases such as\n // calling trees/latest during load.\n if (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {\n event.end({ fromCache: isTokenFromCache(tokenResponse), isNull: token === null });\n }\n if (token === null && throwOnNullToken) {\n throw new NonRetryableError(\n // pre-0.58 error message: Token is null for ${name} call\n `The Host-provided token fetcher for ${name} call returned null`,\n OdspErrorType.fetchTokenError,\n { method: name, driverVersion });\n }\n return token;\n }, (error) => {\n // There is an important but unofficial contract here where token providers can set canRetry: true\n // to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)\n const rawCanRetry = error?.canRetry;\n const tokenError = wrapError(\n error,\n (errorMessage) => new NetworkErrorBasic(\n `The Host-provided token fetcher for ${name} call threw an error: ${errorMessage}`,\n OdspErrorType.fetchTokenError,\n typeof rawCanRetry === \"boolean\" ? rawCanRetry : false /* canRetry */,\n { method: name, driverVersion }));\n throw tokenError;\n }),\n { cancel: \"generic\" });\n };\n}\n\nexport function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry {\n const cacheEntry: ICacheEntry = {\n type: snapshotKey,\n key: \"\",\n file: {\n resolvedUrl: odspResolvedUrl,\n docId: odspResolvedUrl.hashedDocumentId,\n },\n };\n return c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cAAc,EACrE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAb,2BAAa,EAAE,CAAC,CAAC,CAAC;YAC1C,MAAM,UAAU,CAAC;QACrB,CAAC,CAAC,EACF,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC;AAvDD,wEAuDC;AAED,SAAgB,sBAAsB,CAAC,eAAiC;IACpE,MAAM,UAAU,GAAgB;QAC5B,IAAI,EAAE,qCAAW;QACjB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE;YACF,WAAW,EAAE,eAAe;YAC5B,KAAK,EAAE,eAAe,CAAC,gBAAgB;SAC1C;KACJ,CAAC;IACF,OAAO,UAAU,CAAC;AACtB,CAAC;AAVD,wDAUC;AAED,iGAAiG;AACjG,uFAAuF;AAC1E,QAAA,kBAAkB,GAAG,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties, ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IResolvedUrl, DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n isOnline,\n OnlineStatus,\n RetryableError,\n NonRetryableError,\n NetworkErrorBasic,\n} from \"@fluidframework/driver-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger, PerformanceEvent, wrapError } from \"@fluidframework/telemetry-utils\";\nimport {\n fetchIncorrectResponse,\n throwOdspNetworkError,\n getSPOAndGraphRequestIdsFromResponse,\n} from \"@fluidframework/odsp-doclib-utils\";\nimport {\n IOdspResolvedUrl,\n TokenFetchOptions,\n OdspErrorType,\n tokenFromResponse,\n isTokenFromCache,\n OdspResourceTokenFetchOptions,\n ShareLinkTypes,\n TokenFetcher,\n ICacheEntry,\n snapshotKey,\n InstrumentedStorageTokenFetcher,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { fetch } from \"./fetch\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { IOdspSnapshot } from \"./contracts\";\n\nexport const getWithRetryForTokenRefreshRepeat = \"getWithRetryForTokenRefreshRepeat\";\n\n/** Parse the given url and return the origin (host name) */\nexport const getOrigin = (url: string) => new URL(url).origin;\n\nexport interface ISnapshotContents {\n snapshotTree: ISnapshotTree;\n blobs: Map<string, ArrayBuffer>;\n ops: ISequencedDocumentMessage[];\n sequenceNumber: number | undefined;\n}\n\nexport interface IOdspResponse<T> {\n content: T;\n headers: Map<string, string>;\n propsToLog: ITelemetryProperties;\n duration: number;\n}\n\nexport interface TokenFetchOptionsEx extends TokenFetchOptions {\n /** previous error we hit in getWithRetryForTokenRefresh */\n previousError?: any;\n}\n\nfunction headersToMap(headers: Headers) {\n const newHeaders = new Map<string, string>();\n for (const [key, value] of headers.entries()) {\n newHeaders.set(key, value);\n }\n return 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>(get: (options: TokenFetchOptionsEx) => Promise<T>) {\n return get({ refresh: false }).catch(async (e) => {\n const options: TokenFetchOptionsEx = { refresh: true, previousError: e };\n switch (e.errorType) {\n // If the error is 401 or 403 refresh the token and try once more.\n case DriverErrorType.authorizationError:\n return get({ ...options, claims: e.claims, tenantId: e.tenantId });\n\n case DriverErrorType.incorrectServerResponse: // some error on the wire, retry once\n case OdspErrorType.fetchTokenError: // If the token was null, then retry once.\n return get(options);\n\n default:\n // Caller may determine that it wants one retry\n if (e[getWithRetryForTokenRefreshRepeat] === true) {\n return get(options);\n }\n throw e;\n }\n });\n}\n\nexport async function fetchHelper(\n requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<Response>> {\n const start = performance.now();\n\n // Node-fetch and dom have conflicting typing, force them to work by casting for now\n return fetch(requestInfo, requestInit).then(async (fetchResponse) => {\n const response = fetchResponse as any as Response;\n // Let's assume we can retry.\n if (!response) {\n throw new NonRetryableError(\n // pre-0.58 error message: No response from fetch call\n \"No response from ODSP fetch call\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n if (!response.ok || response.status < 200 || response.status >= 300) {\n throwOdspNetworkError(\n // pre-0.58 error message prefix: odspFetchError\n `ODSP fetch error [${response.status}]`, response.status, response, await response.text());\n }\n\n const headers = headersToMap(response.headers);\n return {\n content: response,\n headers,\n propsToLog: getSPOAndGraphRequestIdsFromResponse(headers),\n duration: performance.now() - start,\n };\n }, (error) => {\n const online = isOnline();\n const errorText = `${error}`;\n\n // This error is thrown by fetch() when AbortSignal is provided and it gets cancelled\n if (error.name === \"AbortError\") {\n throw new RetryableError(\n \"Fetch Timeout (AbortError)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n // TCP/IP timeout\n if (errorText.includes(\"ETIMEDOUT\")) {\n throw new RetryableError(\n \"Fetch Timeout (ETIMEDOUT)\", OdspErrorType.fetchTimeout, { driverVersion });\n }\n\n //\n // WARNING: Do not log error object itself or any of its properties!\n // It could contain PII, like URI in message itself, or token in properties.\n // It is also non-serializable object due to circular references.\n //\n if (online === OnlineStatus.Offline) {\n throw new RetryableError(\n // pre-0.58 error message prefix: Offline\n `ODSP fetch failure (Offline): ${errorText}`, DriverErrorType.offlineError, { driverVersion });\n } else {\n // It is perhaps still possible that this is due to being offline, the error does not reveal enough\n // information to conclude. Could also be DNS errors, malformed fetch request, CSP violation, etc.\n throw new RetryableError(\n // pre-0.58 error message prefix: Fetch error\n `ODSP fetch failure: ${errorText}`, DriverErrorType.fetchFailure, { driverVersion });\n }\n });\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 requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<ArrayBuffer>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n\n const arrayBuffer = await content.arrayBuffer();\n propsToLog.bodySize = arrayBuffer.byteLength;\n return {\n headers,\n content: arrayBuffer,\n propsToLog,\n duration,\n };\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 requestInfo: RequestInfo,\n requestInit: RequestInit | undefined,\n): Promise<IOdspResponse<T>> {\n const { content, headers, propsToLog, duration } = await fetchHelper(requestInfo, requestInit);\n let text: string | undefined;\n try {\n text = await content.text();\n } catch (e) {\n // JSON.parse() can fail and message would container full request URI, including\n // tokens... It fails for me with \"Unexpected end of JSON input\" quite often - an attempt to download big file\n // (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always\n // succeeds on retry.\n // So do not log error object itself.\n throwOdspNetworkError(\n // pre-0.58 error message: errorWhileParsingFetchResponse\n \"Error while parsing fetch response\",\n fetchIncorrectResponse,\n content, // response\n text,\n );\n }\n\n propsToLog.bodySize = text.length;\n const res = {\n headers,\n content: JSON.parse(text),\n propsToLog,\n duration,\n };\n return res;\n}\n\nexport interface INewFileInfo {\n siteUrl: string;\n driveId: string;\n filename: string;\n filePath: string;\n /**\n * application can request creation of a share link along with the creation of a new file\n * by passing in an optional param to specify the kind of sharing link\n * (at the time of adding this comment Sept/2021), odsp only supports csl\n */\n createLinkType?: ShareLinkTypes;\n}\n\nexport function getOdspResolvedUrl(resolvedUrl: IResolvedUrl): IOdspResolvedUrl {\n assert((resolvedUrl as IOdspResolvedUrl).odspResolvedUrl === true, 0x1de /* \"Not an ODSP resolved url\" */);\n return resolvedUrl as IOdspResolvedUrl;\n}\n\nexport const createOdspLogger = (logger?: ITelemetryBaseLogger) =>\n ChildLogger.create(\n logger,\n \"OdspDriver\",\n { all:\n {\n driverVersion,\n },\n });\n\nexport function evalBlobsAndTrees(snapshot: IOdspSnapshot) {\n let numTrees = 0;\n let numBlobs = 0;\n let encodedBlobsSize = 0;\n let decodedBlobsSize = 0;\n for (const tree of snapshot.trees) {\n for (const treeEntry of tree.entries) {\n if (treeEntry.type === \"blob\") {\n numBlobs++;\n } else if (treeEntry.type === \"tree\") {\n numTrees++;\n }\n }\n }\n if (snapshot.blobs !== undefined) {\n for (const blob of snapshot.blobs) {\n decodedBlobsSize += blob.size;\n encodedBlobsSize += blob.content.length;\n }\n }\n return { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize };\n}\n\nexport function toInstrumentedOdspTokenFetcher(\n logger: ITelemetryLogger,\n resolvedUrlParts: IOdspUrlParts,\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n throwOnNullToken: boolean,\n): InstrumentedStorageTokenFetcher {\n return async (options: TokenFetchOptions, name: string, alwaysRecordTokenFetchTelemetry: boolean = false) => {\n // Telemetry note: if options.refresh is true, there is a potential perf issue:\n // Host should optimize and provide non-expired tokens on all critical paths.\n // Exceptions: race conditions around expiration, revoked tokens, host that does not care\n // (fluid-fetcher)\n return PerformanceEvent.timedExecAsync(\n logger,\n {\n eventName: `${name}_GetToken`,\n attempts: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n },\n async (event) => tokenFetcher({\n ...options,\n ...resolvedUrlParts,\n }).then((tokenResponse) => {\n const token = tokenFromResponse(tokenResponse);\n // This event alone generates so many events that is materially impacts cost of telemetry\n // Thus do not report end event when it comes back quickly.\n // Note that most of the hosts do not report if result is comming from cache or not,\n // so we can't rely on that here. But always record if specified explicitly for cases such as\n // calling trees/latest during load.\n if (alwaysRecordTokenFetchTelemetry || event.duration >= 32) {\n event.end({ fromCache: isTokenFromCache(tokenResponse), isNull: token === null });\n }\n if (token === null && throwOnNullToken) {\n throw new NonRetryableError(\n // pre-0.58 error message: Token is null for ${name} call\n `The Host-provided token fetcher for ${name} call returned null`,\n OdspErrorType.fetchTokenError,\n { method: name, driverVersion });\n }\n return token;\n }, (error) => {\n // There is an important but unofficial contract here where token providers can set canRetry: true\n // to hook into the driver's retry logic (e.g. the retry loop when initiating a connection)\n const rawCanRetry = error?.canRetry;\n const tokenError = wrapError(\n error,\n (errorMessage) => new NetworkErrorBasic(\n `The Host-provided token fetcher for ${name} call threw an error: ${errorMessage}`,\n OdspErrorType.fetchTokenError,\n typeof rawCanRetry === \"boolean\" ? rawCanRetry : false /* canRetry */,\n { method: name, driverVersion }));\n throw tokenError;\n }),\n { cancel: \"generic\" });\n };\n}\n\nexport function createCacheSnapshotKey(odspResolvedUrl: IOdspResolvedUrl): ICacheEntry {\n const cacheEntry: ICacheEntry = {\n type: snapshotKey,\n key: \"\",\n file: {\n resolvedUrl: odspResolvedUrl,\n docId: odspResolvedUrl.hashedDocumentId,\n },\n };\n return 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"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/odsp-driver";
|
|
8
|
-
export declare const pkgVersion = "0.59.
|
|
8
|
+
export declare const pkgVersion = "0.59.4000";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
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 = "0.59.
|
|
11
|
+
exports.pkgVersion = "0.59.4000";
|
|
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,WAAW,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 = \"0.59.
|
|
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,WAAW,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 = \"0.59.4000\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefetchLatestSnapshot.d.ts","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAEH,eAAe,EACf,gBAAgB,EAChB,6BAA6B,EAC7B,YAAY,EAEf,MAAM,yCAAyC,CAAC;AAQjD,OAAO,EAA6C,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGvG;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,sBAAsB,CACxC,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,
|
|
1
|
+
{"version":3,"file":"prefetchLatestSnapshot.d.ts","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAEH,eAAe,EACf,gBAAgB,EAChB,6BAA6B,EAC7B,YAAY,EAEf,MAAM,yCAAyC,CAAC;AAQjD,OAAO,EAA6C,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGvG;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,sBAAsB,CACxC,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,GACpD,OAAO,CAAC,OAAO,CAAC,CAsDlB"}
|
|
@@ -27,7 +27,7 @@ const fetchSnapshot_1 = require("./fetchSnapshot");
|
|
|
27
27
|
* @param snapshotFormatFetchType - Snapshot format to fetch.
|
|
28
28
|
* @returns - True if the snapshot is cached, false otherwise.
|
|
29
29
|
*/
|
|
30
|
-
async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCache, forceAccessTokenViaAuthorizationHeader, logger, hostSnapshotFetchOptions, enableRedeemFallback, fetchBinarySnapshotFormat, snapshotFormatFetchType) {
|
|
30
|
+
async function prefetchLatestSnapshot(resolvedUrl, getStorageToken, persistedCache, forceAccessTokenViaAuthorizationHeader, logger, hostSnapshotFetchOptions, enableRedeemFallback = true, fetchBinarySnapshotFormat, snapshotFormatFetchType) {
|
|
31
31
|
const odspLogger = (0, odspUtils_1.createOdspLogger)(telemetry_utils_1.ChildLogger.create(logger, "PrefetchSnapshot"));
|
|
32
32
|
const odspResolvedUrl = (0, odspUtils_1.getOdspResolvedUrl)(resolvedUrl);
|
|
33
33
|
const resolvedUrlData = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefetchLatestSnapshot.js","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAAsD;AAUtD,qEAAgF;AAChF,2CAKqB;AACrB,mDAAuG;AAGvG;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,sBAAsB,CACxC,WAAyB,EACzB,eAA4D,EAC5D,cAA+B,EAC/B,sCAA+C,EAC/C,MAA4B,EAC5B,wBAAsD,EACtD,
|
|
1
|
+
{"version":3,"file":"prefetchLatestSnapshot.js","sourceRoot":"","sources":["../src/prefetchLatestSnapshot.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAAsD;AAUtD,qEAAgF;AAChF,2CAKqB;AACrB,mDAAuG;AAGvG;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,sBAAsB,CACxC,WAAyB,EACzB,eAA4D,EAC5D,cAA+B,EAC/B,sCAA+C,EAC/C,MAA4B,EAC5B,wBAAsD,EACtD,uBAAgC,IAAI,EACpC,yBAAmC,EACnC,uBAAmD;IAEnD,MAAM,UAAU,GAAG,IAAA,4BAAgB,EAAC,6BAAW,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACpF,MAAM,eAAe,GAAG,IAAA,8BAAkB,EAAC,WAAW,CAAC,CAAC;IA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;IACpB,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAhED,wDAgEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport {\n IOdspResolvedUrl,\n IPersistedCache,\n ISnapshotOptions,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n IOdspUrlParts,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n createCacheSnapshotKey,\n createOdspLogger,\n getOdspResolvedUrl,\n toInstrumentedOdspTokenFetcher,\n} from \"./odspUtils\";\nimport { downloadSnapshot, fetchSnapshotWithRedeem, SnapshotFormatSupportType } from \"./fetchSnapshot\";\nimport { IVersionedValueWithEpoch } from \"./contracts\";\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 * @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 * @deprecated - This 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 * @returns - True if the snapshot is cached, false otherwise.\n */\nexport async function prefetchLatestSnapshot(\n resolvedUrl: IResolvedUrl,\n getStorageToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n persistedCache: IPersistedCache,\n forceAccessTokenViaAuthorizationHeader: boolean,\n logger: ITelemetryBaseLogger,\n hostSnapshotFetchOptions: ISnapshotOptions | undefined,\n enableRedeemFallback: boolean = true,\n fetchBinarySnapshotFormat?: boolean,\n snapshotFormatFetchType?: SnapshotFormatSupportType,\n): Promise<boolean> {\n const odspLogger = createOdspLogger(ChildLogger.create(logger, \"PrefetchSnapshot\"));\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n const resolvedUrlData: IOdspUrlParts = {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n };\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n odspLogger,\n resolvedUrlData,\n getStorageToken,\n true /* throwOnNullToken */,\n );\n\n const snapshotDownloader = async (\n finalOdspResolvedUrl: IOdspResolvedUrl,\n storageToken: string,\n snapshotOptions: ISnapshotOptions | undefined,\n controller?: AbortController,\n ) => {\n return downloadSnapshot(\n finalOdspResolvedUrl, storageToken, odspLogger, snapshotOptions, snapshotFormatFetchType, controller);\n };\n const snapshotKey = createCacheSnapshotKey(odspResolvedUrl);\n let cacheP: Promise<void> | undefined;\n const putInCache = async (valueWithEpoch: IVersionedValueWithEpoch) => {\n cacheP = persistedCache.put(\n snapshotKey,\n valueWithEpoch,\n );\n return cacheP;\n };\n const removeEntries = async () => persistedCache.removeEntries(snapshotKey.file);\n return PerformanceEvent.timedExecAsync(\n odspLogger,\n { eventName: \"PrefetchLatestSnapshot\" },\n async () => {\n await fetchSnapshotWithRedeem(\n odspResolvedUrl,\n storageTokenFetcher,\n hostSnapshotFetchOptions,\n forceAccessTokenViaAuthorizationHeader,\n odspLogger,\n snapshotDownloader,\n putInCache,\n removeEntries,\n enableRedeemFallback,\n );\n assert(cacheP !== undefined, 0x1e7 /* \"caching was not performed!\" */);\n await cacheP;\n return true;\n }).catch(async (error) => false);\n}\n"]}
|