@fluidframework/odsp-driver 0.51.3 → 0.53.0-46105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/contractsPublic.d.ts +0 -4
  2. package/dist/contractsPublic.d.ts.map +1 -1
  3. package/dist/contractsPublic.js.map +1 -1
  4. package/dist/createFile.d.ts.map +1 -1
  5. package/dist/createFile.js +11 -9
  6. package/dist/createFile.js.map +1 -1
  7. package/dist/createNewUtils.js +5 -4
  8. package/dist/createNewUtils.js.map +1 -1
  9. package/dist/epochTracker.d.ts +2 -1
  10. package/dist/epochTracker.d.ts.map +1 -1
  11. package/dist/epochTracker.js +51 -25
  12. package/dist/epochTracker.js.map +1 -1
  13. package/dist/fetchSnapshot.d.ts.map +1 -1
  14. package/dist/fetchSnapshot.js +1 -1
  15. package/dist/fetchSnapshot.js.map +1 -1
  16. package/dist/getFileLink.d.ts +1 -1
  17. package/dist/getFileLink.d.ts.map +1 -1
  18. package/dist/getFileLink.js +32 -22
  19. package/dist/getFileLink.js.map +1 -1
  20. package/dist/odspDeltaStorageService.d.ts +3 -3
  21. package/dist/odspDeltaStorageService.d.ts.map +1 -1
  22. package/dist/odspDeltaStorageService.js +7 -4
  23. package/dist/odspDeltaStorageService.js.map +1 -1
  24. package/dist/odspDocumentDeltaConnection.d.ts.map +1 -1
  25. package/dist/odspDocumentDeltaConnection.js +2 -0
  26. package/dist/odspDocumentDeltaConnection.js.map +1 -1
  27. package/dist/odspDocumentService.d.ts.map +1 -1
  28. package/dist/odspDocumentService.js +3 -3
  29. package/dist/odspDocumentService.js.map +1 -1
  30. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  31. package/dist/odspDocumentStorageManager.js +30 -34
  32. package/dist/odspDocumentStorageManager.js.map +1 -1
  33. package/dist/odspDriverUrlResolver.d.ts +0 -4
  34. package/dist/odspDriverUrlResolver.d.ts.map +1 -1
  35. package/dist/odspDriverUrlResolver.js +0 -7
  36. package/dist/odspDriverUrlResolver.js.map +1 -1
  37. package/dist/odspDriverUrlResolverForShareLink.d.ts +2 -6
  38. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  39. package/dist/odspDriverUrlResolverForShareLink.js +4 -15
  40. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  41. package/dist/odspError.d.ts.map +1 -1
  42. package/dist/odspError.js +3 -1
  43. package/dist/odspError.js.map +1 -1
  44. package/dist/odspSummaryUploadManager.js +24 -4
  45. package/dist/odspSummaryUploadManager.js.map +1 -1
  46. package/dist/odspUtils.d.ts.map +1 -1
  47. package/dist/odspUtils.js +31 -23
  48. package/dist/odspUtils.js.map +1 -1
  49. package/dist/packageVersion.d.ts +1 -1
  50. package/dist/packageVersion.d.ts.map +1 -1
  51. package/dist/packageVersion.js +1 -1
  52. package/dist/packageVersion.js.map +1 -1
  53. package/dist/zipItDataRepresentationUtils.d.ts.map +1 -1
  54. package/dist/zipItDataRepresentationUtils.js +3 -4
  55. package/dist/zipItDataRepresentationUtils.js.map +1 -1
  56. package/lib/contractsPublic.d.ts +0 -4
  57. package/lib/contractsPublic.d.ts.map +1 -1
  58. package/lib/contractsPublic.js.map +1 -1
  59. package/lib/createFile.d.ts.map +1 -1
  60. package/lib/createFile.js +12 -10
  61. package/lib/createFile.js.map +1 -1
  62. package/lib/createNewUtils.js +5 -4
  63. package/lib/createNewUtils.js.map +1 -1
  64. package/lib/epochTracker.d.ts +2 -1
  65. package/lib/epochTracker.d.ts.map +1 -1
  66. package/lib/epochTracker.js +52 -26
  67. package/lib/epochTracker.js.map +1 -1
  68. package/lib/fetchSnapshot.d.ts.map +1 -1
  69. package/lib/fetchSnapshot.js +1 -1
  70. package/lib/fetchSnapshot.js.map +1 -1
  71. package/lib/getFileLink.d.ts +1 -1
  72. package/lib/getFileLink.d.ts.map +1 -1
  73. package/lib/getFileLink.js +34 -24
  74. package/lib/getFileLink.js.map +1 -1
  75. package/lib/odspDeltaStorageService.d.ts +3 -3
  76. package/lib/odspDeltaStorageService.d.ts.map +1 -1
  77. package/lib/odspDeltaStorageService.js +7 -4
  78. package/lib/odspDeltaStorageService.js.map +1 -1
  79. package/lib/odspDocumentDeltaConnection.d.ts.map +1 -1
  80. package/lib/odspDocumentDeltaConnection.js +2 -0
  81. package/lib/odspDocumentDeltaConnection.js.map +1 -1
  82. package/lib/odspDocumentService.d.ts.map +1 -1
  83. package/lib/odspDocumentService.js +4 -4
  84. package/lib/odspDocumentService.js.map +1 -1
  85. package/lib/odspDocumentStorageManager.d.ts.map +1 -1
  86. package/lib/odspDocumentStorageManager.js +33 -37
  87. package/lib/odspDocumentStorageManager.js.map +1 -1
  88. package/lib/odspDriverUrlResolver.d.ts +0 -4
  89. package/lib/odspDriverUrlResolver.d.ts.map +1 -1
  90. package/lib/odspDriverUrlResolver.js +0 -7
  91. package/lib/odspDriverUrlResolver.js.map +1 -1
  92. package/lib/odspDriverUrlResolverForShareLink.d.ts +2 -6
  93. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  94. package/lib/odspDriverUrlResolverForShareLink.js +5 -16
  95. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
  96. package/lib/odspError.d.ts.map +1 -1
  97. package/lib/odspError.js +3 -1
  98. package/lib/odspError.js.map +1 -1
  99. package/lib/odspSummaryUploadManager.js +5 -4
  100. package/lib/odspSummaryUploadManager.js.map +1 -1
  101. package/lib/odspUtils.d.ts.map +1 -1
  102. package/lib/odspUtils.js +33 -25
  103. package/lib/odspUtils.js.map +1 -1
  104. package/lib/packageVersion.d.ts +1 -1
  105. package/lib/packageVersion.d.ts.map +1 -1
  106. package/lib/packageVersion.js +1 -1
  107. package/lib/packageVersion.js.map +1 -1
  108. package/lib/zipItDataRepresentationUtils.d.ts.map +1 -1
  109. package/lib/zipItDataRepresentationUtils.js +3 -4
  110. package/lib/zipItDataRepresentationUtils.js.map +1 -1
  111. package/package.json +12 -12
  112. package/src/contractsPublic.ts +0 -5
  113. package/src/createFile.ts +13 -9
  114. package/src/epochTracker.ts +52 -25
  115. package/src/fetchSnapshot.ts +2 -1
  116. package/src/getFileLink.ts +47 -27
  117. package/src/odspDeltaStorageService.ts +10 -3
  118. package/src/odspDocumentDeltaConnection.ts +2 -0
  119. package/src/odspDocumentService.ts +8 -4
  120. package/src/odspDocumentStorageManager.ts +49 -38
  121. package/src/odspDriverUrlResolver.ts +0 -13
  122. package/src/odspDriverUrlResolverForShareLink.ts +10 -23
  123. package/src/odspError.ts +5 -1
  124. package/src/odspUtils.ts +43 -35
  125. package/src/packageVersion.ts +1 -1
  126. package/src/zipItDataRepresentationUtils.ts +4 -8
@@ -7,12 +7,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.OdspDriverUrlResolverForShareLink = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
9
  const core_interfaces_1 = require("@fluidframework/core-interfaces");
10
- const odsp_doclib_utils_1 = require("@fluidframework/odsp-doclib-utils");
10
+ const driver_utils_1 = require("@fluidframework/driver-utils");
11
11
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
12
12
  const odsp_driver_definitions_1 = require("@fluidframework/odsp-driver-definitions");
13
13
  const odspFluidFileLink_1 = require("./odspFluidFileLink");
14
14
  const contractsPublic_1 = require("./contractsPublic");
15
- const createOdspCreateContainerRequest_1 = require("./createOdspCreateContainerRequest");
16
15
  const createOdspUrl_1 = require("./createOdspUrl");
17
16
  const odspDriverUrlResolver_1 = require("./odspDriverUrlResolver");
18
17
  const odspUtils_1 = require("./odspUtils");
@@ -41,12 +40,6 @@ class OdspDriverUrlResolverForShareLink {
41
40
  this.shareLinkFetcherProps = Object.assign(Object.assign({}, shareLinkFetcherProps), { tokenFetcher: this.toInstrumentedTokenFetcher(this.logger, shareLinkFetcherProps.tokenFetcher) });
42
41
  }
43
42
  }
44
- /**
45
- * @deprecated - use createOdspCreateContainerRequest
46
- */
47
- createCreateNewRequest(siteUrl, driveId, filePath, fileName) {
48
- return createOdspCreateContainerRequest_1.createOdspCreateContainerRequest(siteUrl, driveId, filePath, fileName);
49
- }
50
43
  /**
51
44
  * Takes an already generated data store url (from requestUrl) and appends a path to the
52
45
  * existing data store information.
@@ -117,7 +110,7 @@ class OdspDriverUrlResolverForShareLink {
117
110
  return async (options) => {
118
111
  return telemetry_utils_1.PerformanceEvent.timedExecAsync(logger, { eventName: "GetSharingLinkToken" }, async (event) => tokenFetcher(options).then((tokenResponse) => {
119
112
  if (tokenResponse === null) {
120
- odsp_doclib_utils_1.throwOdspNetworkError("shareLinkTokenIsNull", odsp_doclib_utils_1.fetchTokenErrorCode);
113
+ throw new driver_utils_1.NonRetryableError("shareLinkTokenIsNull", "Token callback returned null", odsp_driver_definitions_1.OdspErrorType.fetchTokenError);
121
114
  }
122
115
  event.end({ fromCache: odsp_driver_definitions_1.isTokenFromCache(tokenResponse) });
123
116
  return tokenResponse;
@@ -137,12 +130,8 @@ class OdspDriverUrlResolverForShareLink {
137
130
  if (cachedLinkPromise) {
138
131
  return cachedLinkPromise;
139
132
  }
140
- const newLinkPromise = getFileLink_1.getFileLink(this.shareLinkFetcherProps.tokenFetcher, resolvedUrl, this.shareLinkFetcherProps.identityType, this.logger).then((fileLink) => {
141
- if (!fileLink) {
142
- throw new Error("Failed to get share link");
143
- }
144
- return fileLink;
145
- }).catch((error) => {
133
+ const newLinkPromise = getFileLink_1.getFileLink(this.shareLinkFetcherProps.tokenFetcher, resolvedUrl, this.shareLinkFetcherProps.identityType, this.logger).catch((error) => {
134
+ // This should imply that error is a non-retriable error.
146
135
  this.logger.sendErrorEvent({ eventName: "FluidFileUrlError" }, error);
147
136
  this.sharingLinkCache.remove(key);
148
137
  throw error;
@@ -1 +1 @@
1
- {"version":3,"file":"odspDriverUrlResolverForShareLink.js","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAC5D,qEAA8F;AAG9F,yEAA+F;AAC/F,qEAAm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AAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,yCAAqB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,OAAkC;QAC3D,OAAO,mDAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ;AA5ND,8EA4NC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { PromiseCache } from \"@fluidframework/common-utils\";\nimport { IFluidCodeDetails, IRequest, isFluidPackage } from \"@fluidframework/core-interfaces\";\nimport { IResolvedUrl, IUrlResolver } from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { fetchTokenErrorCode, throwOdspNetworkError } from \"@fluidframework/odsp-doclib-utils\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspResolvedUrl,\n IdentityType,\n isTokenFromCache,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n getLocatorFromOdspUrl,\n storeLocatorInOdspUrl,\n encodeOdspFluidDataStoreLocator,\n locatorQueryParamName,\n} from \"./odspFluidFileLink\";\nimport { OdspDocumentInfo, OdspFluidDataStoreLocator, SharingLinkHeader } from \"./contractsPublic\";\nimport { createOdspCreateContainerRequest } from \"./createOdspCreateContainerRequest\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { getOdspResolvedUrl, createOdspLogger } from \"./odspUtils\";\nimport { getFileLink } from \"./getFileLink\";\n\n/**\n * Properties passed to the code responsible for fetching share link for a file.\n */\nexport interface ShareLinkFetcherProps {\n /**\n * Callback method that is used to fetch access token necessary to call API that produces share link\n */\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>;\n /**\n * Identity type determining the shape of share link as it differs for Enterprise and Consumer users.\n */\n identityType: IdentityType;\n}\n\n/**\n * Resolver to resolve urls like the ones created by createOdspUrl which is driver inner\n * url format and the ones which have things like driveId, siteId, itemId etc encoded in nav param.\n * This resolver also handles share links and try to generate one for the use by the app.\n */\nexport class OdspDriverUrlResolverForShareLink implements IUrlResolver {\n private readonly logger: ITelemetryLogger;\n private readonly sharingLinkCache = new PromiseCache<string, string>();\n private readonly shareLinkFetcherProps: ShareLinkFetcherProps | undefined;\n\n /**\n * Creates url resolver instance\n * @param shareLinkFetcherProps - properties used when fetching share link.\n * Can be set as 'undefined' for cases where share link is not needed. Currently, only\n * getAbsoluteUrl() method requires share link.\n * @param logger - logger object that is used as telemetry sink\n * @param appName - application name hint that is encoded with url produced by getAbsoluteUrl() method.\n * This hint is used by link handling logic which determines which app to redirect to when user\n * navigates directly to the link.\n */\n public constructor(\n shareLinkFetcherProps?: ShareLinkFetcherProps | undefined,\n logger?: ITelemetryBaseLogger,\n private readonly appName?: string,\n ) {\n this.logger = createOdspLogger(logger);\n if (shareLinkFetcherProps) {\n this.shareLinkFetcherProps = {\n ...shareLinkFetcherProps,\n tokenFetcher: this.toInstrumentedTokenFetcher(this.logger, shareLinkFetcherProps.tokenFetcher),\n };\n }\n }\n\n /**\n * @deprecated - use createOdspCreateContainerRequest\n */\n public createCreateNewRequest(\n siteUrl: string,\n driveId: string,\n filePath: string,\n fileName: string,\n ) {\n return createOdspCreateContainerRequest(siteUrl, driveId, filePath, fileName);\n }\n\n /**\n * Takes an already generated data store url (from requestUrl) and appends a path to the\n * existing data store information.\n */\n public appendDataStorePath(requestUrl: URL, pathToAppend: string): string | undefined {\n const fluidInfo = getLocatorFromOdspUrl(requestUrl);\n\n if (!fluidInfo) {\n return undefined;\n }\n\n const parsingUrl = new URL(fluidInfo.dataStorePath, `${requestUrl.protocol}//${requestUrl.hostname}`);\n // Determine if the caller is passing a query parameter or path since processing will be different.\n if (pathToAppend.startsWith(\"/?\") || pathToAppend.startsWith(\"?\")) {\n const queryParams = new URLSearchParams(pathToAppend);\n queryParams.forEach((value: string, key: string) => {\n parsingUrl.searchParams.append(key, value);\n });\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${parsingUrl.search}`;\n } else {\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${\n parsingUrl.pathname.endsWith(\"/\") || pathToAppend.startsWith(\"/\") ? \"\" : \"/\"\n }${pathToAppend}/${parsingUrl.search}`;\n }\n storeLocatorInOdspUrl(requestUrl, fluidInfo);\n\n return requestUrl.href;\n }\n\n private getKey(resolvedUrl: IOdspResolvedUrl): string {\n return `${resolvedUrl.siteUrl},${resolvedUrl.driveId},${resolvedUrl.itemId}`;\n }\n\n /**\n * Resolves request URL into driver details\n */\n public async resolve(request: IRequest): Promise<IOdspResolvedUrl> {\n const requestToBeResolved = { headers: request.headers, url: request.url };\n const isSharingLinkToRedeem = requestToBeResolved.headers?.[SharingLinkHeader.isSharingLinkToRedeem];\n try {\n const url = new URL(request.url);\n\n const odspFluidInfo = getLocatorFromOdspUrl(url);\n if (odspFluidInfo) {\n requestToBeResolved.url = createOdspUrl(odspFluidInfo);\n }\n } catch {\n // If the locator throws some error, then try to resolve the request as it is.\n }\n\n const odspResolvedUrl = await new OdspDriverUrlResolver().resolve(requestToBeResolved);\n\n if (isSharingLinkToRedeem) {\n // We need to remove the nav param if set by host when setting the sharelink as otherwise the shareLinkId\n // when redeeming the share link during the redeem fallback for trees latest call becomes greater than\n // the eligible length.\n odspResolvedUrl.sharingLinkToRedeem = this.removeNavParam(request.url);\n odspResolvedUrl.shareLinkInfo = Object.assign(odspResolvedUrl.shareLinkInfo || {},\n {sharingLinkToRedeem: odspResolvedUrl.sharingLinkToRedeem});\n }\n if (odspResolvedUrl.itemId) {\n // Kick start the sharing link request if we don't have it already as a performance optimization.\n // For detached create new, we don't have an item id yet and therefore cannot generate a share link\n this.getShareLinkPromise(odspResolvedUrl).catch(() => {});\n }\n return odspResolvedUrl;\n }\n\n private removeNavParam(link: string): string {\n const url = new URL(link);\n const params = new URLSearchParams(url.search);\n params.delete(locatorQueryParamName);\n url.search = params.toString();\n return url.href;\n }\n\n private toInstrumentedTokenFetcher(\n logger: ITelemetryLogger,\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n ): TokenFetcher<OdspResourceTokenFetchOptions> {\n return async (options: OdspResourceTokenFetchOptions) => {\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"GetSharingLinkToken\" },\n async (event) => tokenFetcher(options).then((tokenResponse) => {\n if (tokenResponse === null) {\n throwOdspNetworkError(\"shareLinkTokenIsNull\", fetchTokenErrorCode);\n }\n event.end({ fromCache: isTokenFromCache(tokenResponse) });\n return tokenResponse;\n }));\n };\n }\n\n private async getShareLinkPromise(resolvedUrl: IOdspResolvedUrl): Promise<string> {\n if (this.shareLinkFetcherProps === undefined) {\n throw new Error(\"Failed to get share link because share link fetcher props are missing\");\n }\n\n if (!(resolvedUrl.siteUrl && resolvedUrl.driveId && resolvedUrl.itemId)) {\n throw new Error(\"Failed to get share link because necessary information is missing \" +\n \"(e.g. siteUrl, driveId or itemId)\");\n }\n\n const key = this.getKey(resolvedUrl);\n const cachedLinkPromise = this.sharingLinkCache.get(key);\n if (cachedLinkPromise) {\n return cachedLinkPromise;\n }\n const newLinkPromise = getFileLink(\n this.shareLinkFetcherProps.tokenFetcher,\n resolvedUrl,\n this.shareLinkFetcherProps.identityType,\n this.logger,\n ).then((fileLink) => {\n if (!fileLink) {\n throw new Error(\"Failed to get share link\");\n }\n return fileLink;\n }).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"FluidFileUrlError\" }, error);\n this.sharingLinkCache.remove(key);\n throw error;\n });\n this.sharingLinkCache.add(key, async () => newLinkPromise);\n return newLinkPromise;\n }\n\n /**\n * Requests a driver + data store storage URL. Note that this method requires share link to be fetched\n * and it will throw in case share link fetcher props were not specified when instance was created.\n * @param resolvedUrl - The driver resolved URL\n * @param request - The relative data store path URL. For requesting a driver URL, this value should always be '/'\n */\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n dataStorePath: string,\n codeDetails?: IFluidCodeDetails,\n ): Promise<string> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n const shareLink = await this.getShareLinkPromise(odspResolvedUrl);\n\n const shareLinkUrl = new URL(shareLink);\n\n const containerPackageName =\n isFluidPackage(codeDetails?.package) ? codeDetails?.package.name : codeDetails?.package ??\n odspResolvedUrl.codeHint?.containerPackageName;\n\n storeLocatorInOdspUrl(shareLinkUrl, {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n dataStorePath,\n appName: this.appName,\n containerPackageName,\n fileVersion: odspResolvedUrl.fileVersion,\n });\n\n return shareLinkUrl.href;\n }\n\n /**\n * Crafts a supported document/driver URL\n */\n public static createDocumentUrl(baseUrl: string, driverInfo: OdspDocumentInfo) {\n const url = new URL(baseUrl);\n\n storeLocatorInOdspUrl(url, driverInfo);\n\n return url.href;\n }\n\n /**\n * Crafts a supported data store nav param\n */\n public static createNavParam(locator: OdspFluidDataStoreLocator) {\n return encodeOdspFluidDataStoreLocator(locator);\n }\n}\n"]}
1
+ {"version":3,"file":"odspDriverUrlResolverForShareLink.js","sourceRoot":"","sources":["../src/odspDriverUrlResolverForShareLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA4D;AAC5D,qEAA8F;AAG9F,+DAAiE;AACjE,qEAAmE;AACnE,qFAOiD;AACjD,2DAK6B;AAC7B,uDAAiF;AACjF,mDAAgD;AAChD,mEAAgE;AAChE,2CAAmE;AACnE,+CAA4C;AAgB5C;;;;GAIG;AACH,MAAa,iCAAiC;IAK1C;;;;;;;;;OASG;IACH,YACI,qBAAyD,EACzD,MAA6B,EACZ,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;QAhBpB,qBAAgB,GAAG,IAAI,2BAAY,EAA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ACtB,gCAAc,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,IAAI,CAAC,CAAC,OAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,yCACvF,eAAe,CAAC,QAAQ,0CAAE,oBAAoB,CAAC;QAEnD,yCAAqB,CAAC,YAAY,EAAE;YAChC,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,MAAM,EAAE,eAAe,CAAC,MAAM;YAC9B,aAAa;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,oBAAoB;YACpB,WAAW,EAAE,eAAe,CAAC,WAAW;SAC3C,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,iBAAiB,CAAC,OAAe,EAAE,UAAqC;QAClF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,yCAAqB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEvC,OAAO,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,OAAkC;QAC3D,OAAO,mDAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ;AA/MD,8EA+MC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { PromiseCache } from \"@fluidframework/common-utils\";\nimport { IFluidCodeDetails, IRequest, isFluidPackage } from \"@fluidframework/core-interfaces\";\nimport { IResolvedUrl, IUrlResolver } from \"@fluidframework/driver-definitions\";\nimport { ITelemetryBaseLogger, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspResolvedUrl,\n IdentityType,\n isTokenFromCache,\n OdspResourceTokenFetchOptions,\n TokenFetcher,\n OdspErrorType,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n getLocatorFromOdspUrl,\n storeLocatorInOdspUrl,\n encodeOdspFluidDataStoreLocator,\n locatorQueryParamName,\n} from \"./odspFluidFileLink\";\nimport { OdspFluidDataStoreLocator, SharingLinkHeader } from \"./contractsPublic\";\nimport { createOdspUrl } from \"./createOdspUrl\";\nimport { OdspDriverUrlResolver } from \"./odspDriverUrlResolver\";\nimport { getOdspResolvedUrl, createOdspLogger } from \"./odspUtils\";\nimport { getFileLink } from \"./getFileLink\";\n\n/**\n * Properties passed to the code responsible for fetching share link for a file.\n */\nexport interface ShareLinkFetcherProps {\n /**\n * Callback method that is used to fetch access token necessary to call API that produces share link\n */\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>;\n /**\n * Identity type determining the shape of share link as it differs for Enterprise and Consumer users.\n */\n identityType: IdentityType;\n}\n\n/**\n * Resolver to resolve urls like the ones created by createOdspUrl which is driver inner\n * url format and the ones which have things like driveId, siteId, itemId etc encoded in nav param.\n * This resolver also handles share links and try to generate one for the use by the app.\n */\nexport class OdspDriverUrlResolverForShareLink implements IUrlResolver {\n private readonly logger: ITelemetryLogger;\n private readonly sharingLinkCache = new PromiseCache<string, string>();\n private readonly shareLinkFetcherProps: ShareLinkFetcherProps | undefined;\n\n /**\n * Creates url resolver instance\n * @param shareLinkFetcherProps - properties used when fetching share link.\n * Can be set as 'undefined' for cases where share link is not needed. Currently, only\n * getAbsoluteUrl() method requires share link.\n * @param logger - logger object that is used as telemetry sink\n * @param appName - application name hint that is encoded with url produced by getAbsoluteUrl() method.\n * This hint is used by link handling logic which determines which app to redirect to when user\n * navigates directly to the link.\n */\n public constructor(\n shareLinkFetcherProps?: ShareLinkFetcherProps | undefined,\n logger?: ITelemetryBaseLogger,\n private readonly appName?: string,\n ) {\n this.logger = createOdspLogger(logger);\n if (shareLinkFetcherProps) {\n this.shareLinkFetcherProps = {\n ...shareLinkFetcherProps,\n tokenFetcher: this.toInstrumentedTokenFetcher(this.logger, shareLinkFetcherProps.tokenFetcher),\n };\n }\n }\n\n /**\n * Takes an already generated data store url (from requestUrl) and appends a path to the\n * existing data store information.\n */\n public appendDataStorePath(requestUrl: URL, pathToAppend: string): string | undefined {\n const fluidInfo = getLocatorFromOdspUrl(requestUrl);\n\n if (!fluidInfo) {\n return undefined;\n }\n\n const parsingUrl = new URL(fluidInfo.dataStorePath, `${requestUrl.protocol}//${requestUrl.hostname}`);\n // Determine if the caller is passing a query parameter or path since processing will be different.\n if (pathToAppend.startsWith(\"/?\") || pathToAppend.startsWith(\"?\")) {\n const queryParams = new URLSearchParams(pathToAppend);\n queryParams.forEach((value: string, key: string) => {\n parsingUrl.searchParams.append(key, value);\n });\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${parsingUrl.search}`;\n } else {\n fluidInfo.dataStorePath = `${parsingUrl.pathname}${\n parsingUrl.pathname.endsWith(\"/\") || pathToAppend.startsWith(\"/\") ? \"\" : \"/\"\n }${pathToAppend}/${parsingUrl.search}`;\n }\n storeLocatorInOdspUrl(requestUrl, fluidInfo);\n\n return requestUrl.href;\n }\n\n private getKey(resolvedUrl: IOdspResolvedUrl): string {\n return `${resolvedUrl.siteUrl},${resolvedUrl.driveId},${resolvedUrl.itemId}`;\n }\n\n /**\n * Resolves request URL into driver details\n */\n public async resolve(request: IRequest): Promise<IOdspResolvedUrl> {\n const requestToBeResolved = { headers: request.headers, url: request.url };\n const isSharingLinkToRedeem = requestToBeResolved.headers?.[SharingLinkHeader.isSharingLinkToRedeem];\n try {\n const url = new URL(request.url);\n\n const odspFluidInfo = getLocatorFromOdspUrl(url);\n if (odspFluidInfo) {\n requestToBeResolved.url = createOdspUrl(odspFluidInfo);\n }\n } catch {\n // If the locator throws some error, then try to resolve the request as it is.\n }\n\n const odspResolvedUrl = await new OdspDriverUrlResolver().resolve(requestToBeResolved);\n\n if (isSharingLinkToRedeem) {\n // We need to remove the nav param if set by host when setting the sharelink as otherwise the shareLinkId\n // when redeeming the share link during the redeem fallback for trees latest call becomes greater than\n // the eligible length.\n odspResolvedUrl.sharingLinkToRedeem = this.removeNavParam(request.url);\n odspResolvedUrl.shareLinkInfo = Object.assign(odspResolvedUrl.shareLinkInfo || {},\n {sharingLinkToRedeem: odspResolvedUrl.sharingLinkToRedeem});\n }\n if (odspResolvedUrl.itemId) {\n // Kick start the sharing link request if we don't have it already as a performance optimization.\n // For detached create new, we don't have an item id yet and therefore cannot generate a share link\n this.getShareLinkPromise(odspResolvedUrl).catch(() => {});\n }\n return odspResolvedUrl;\n }\n\n private removeNavParam(link: string): string {\n const url = new URL(link);\n const params = new URLSearchParams(url.search);\n params.delete(locatorQueryParamName);\n url.search = params.toString();\n return url.href;\n }\n\n private toInstrumentedTokenFetcher(\n logger: ITelemetryLogger,\n tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>,\n ): TokenFetcher<OdspResourceTokenFetchOptions> {\n return async (options: OdspResourceTokenFetchOptions) => {\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"GetSharingLinkToken\" },\n async (event) => tokenFetcher(options).then((tokenResponse) => {\n if (tokenResponse === null) {\n throw new NonRetryableError(\n \"shareLinkTokenIsNull\",\n \"Token callback returned null\",\n OdspErrorType.fetchTokenError);\n }\n event.end({ fromCache: isTokenFromCache(tokenResponse) });\n return tokenResponse;\n }));\n };\n }\n\n private async getShareLinkPromise(resolvedUrl: IOdspResolvedUrl): Promise<string> {\n if (this.shareLinkFetcherProps === undefined) {\n throw new Error(\"Failed to get share link because share link fetcher props are missing\");\n }\n\n if (!(resolvedUrl.siteUrl && resolvedUrl.driveId && resolvedUrl.itemId)) {\n throw new Error(\"Failed to get share link because necessary information is missing \" +\n \"(e.g. siteUrl, driveId or itemId)\");\n }\n\n const key = this.getKey(resolvedUrl);\n const cachedLinkPromise = this.sharingLinkCache.get(key);\n if (cachedLinkPromise) {\n return cachedLinkPromise;\n }\n const newLinkPromise = getFileLink(\n this.shareLinkFetcherProps.tokenFetcher,\n resolvedUrl,\n this.shareLinkFetcherProps.identityType,\n this.logger,\n ).catch((error) => {\n // This should imply that error is a non-retriable error.\n this.logger.sendErrorEvent({ eventName: \"FluidFileUrlError\" }, error);\n this.sharingLinkCache.remove(key);\n throw error;\n });\n this.sharingLinkCache.add(key, async () => newLinkPromise);\n return newLinkPromise;\n }\n\n /**\n * Requests a driver + data store storage URL. Note that this method requires share link to be fetched\n * and it will throw in case share link fetcher props were not specified when instance was created.\n * @param resolvedUrl - The driver resolved URL\n * @param request - The relative data store path URL. For requesting a driver URL, this value should always be '/'\n */\n public async getAbsoluteUrl(\n resolvedUrl: IResolvedUrl,\n dataStorePath: string,\n codeDetails?: IFluidCodeDetails,\n ): Promise<string> {\n const odspResolvedUrl = getOdspResolvedUrl(resolvedUrl);\n\n const shareLink = await this.getShareLinkPromise(odspResolvedUrl);\n\n const shareLinkUrl = new URL(shareLink);\n\n const containerPackageName =\n isFluidPackage(codeDetails?.package) ? codeDetails?.package.name : codeDetails?.package ??\n odspResolvedUrl.codeHint?.containerPackageName;\n\n storeLocatorInOdspUrl(shareLinkUrl, {\n siteUrl: odspResolvedUrl.siteUrl,\n driveId: odspResolvedUrl.driveId,\n itemId: odspResolvedUrl.itemId,\n dataStorePath,\n appName: this.appName,\n containerPackageName,\n fileVersion: odspResolvedUrl.fileVersion,\n });\n\n return shareLinkUrl.href;\n }\n\n /**\n * Crafts a supported document/driver URL\n */\n public static createDocumentUrl(baseUrl: string, driverInfo: OdspFluidDataStoreLocator) {\n const url = new URL(baseUrl);\n\n storeLocatorInOdspUrl(url, driverInfo);\n\n return url.href;\n }\n\n /**\n * Crafts a supported data store nav param\n */\n public static createNavParam(locator: OdspFluidDataStoreLocator) {\n return encodeOdspFluidDataStoreLocator(locator);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"odspError.d.ts","sourceRoot":"","sources":["../src/odspError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,k6BAOxF"}
1
+ {"version":3,"file":"odspError.d.ts","sourceRoot":"","sources":["../src/odspError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,k6BAWxF"}
package/dist/odspError.js CHANGED
@@ -11,7 +11,9 @@ const odsp_doclib_utils_1 = require("@fluidframework/odsp-doclib-utils");
11
11
  */
12
12
  function errorObjectFromSocketError(socketError, handler) {
13
13
  const message = `OdspSocketError (${handler}): ${socketError.message}`;
14
- return odsp_doclib_utils_1.createOdspNetworkError(`odspSocketError [${handler}]`, message, socketError.code, socketError.retryAfter);
14
+ const error = odsp_doclib_utils_1.createOdspNetworkError(`odspSocketError [${handler}]`, message, socketError.code, socketError.retryAfter);
15
+ error.addTelemetryProperties({ odspError: true, relayServiceError: true });
16
+ return error;
15
17
  }
16
18
  exports.errorObjectFromSocketError = errorObjectFromSocketError;
17
19
  //# sourceMappingURL=odspError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"odspError.js","sourceRoot":"","sources":["../src/odspError.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAA2E;AAG3E;;GAEG;AACH,SAAgB,0BAA0B,CAAC,WAA6B,EAAE,OAAe;IACrF,MAAM,OAAO,GAAG,oBAAoB,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IACvE,OAAO,0CAAsB,CACzB,oBAAoB,OAAO,GAAG,EAC9B,OAAO,EACP,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAPD,gEAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createOdspNetworkError } from \"@fluidframework/odsp-doclib-utils\";\nimport { IOdspSocketError } from \"./contracts\";\n\n/**\n * Returns network error based on error object from ODSP socket (IOdspSocketError)\n */\nexport function errorObjectFromSocketError(socketError: IOdspSocketError, handler: string) {\n const message = `OdspSocketError (${handler}): ${socketError.message}`;\n return createOdspNetworkError(\n `odspSocketError [${handler}]`,\n message,\n socketError.code,\n socketError.retryAfter);\n}\n"]}
1
+ {"version":3,"file":"odspError.js","sourceRoot":"","sources":["../src/odspError.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAA2E;AAG3E;;GAEG;AACH,SAAgB,0BAA0B,CAAC,WAA6B,EAAE,OAAe;IACrF,MAAM,OAAO,GAAG,oBAAoB,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IACvE,MAAM,KAAK,GAAG,0CAAsB,CAChC,oBAAoB,OAAO,GAAG,EAC9B,OAAO,EACP,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5B,KAAK,CAAC,sBAAsB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IAE3E,OAAO,KAAK,CAAC;AACjB,CAAC;AAXD,gEAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createOdspNetworkError } from \"@fluidframework/odsp-doclib-utils\";\nimport { IOdspSocketError } from \"./contracts\";\n\n/**\n * Returns network error based on error object from ODSP socket (IOdspSocketError)\n */\nexport function errorObjectFromSocketError(socketError: IOdspSocketError, handler: string) {\n const message = `OdspSocketError (${handler}): ${socketError.message}`;\n const error = createOdspNetworkError(\n `odspSocketError [${handler}]`,\n message,\n socketError.code,\n socketError.retryAfter);\n\n error.addTelemetryProperties({ odspError: true, relayServiceError: true });\n\n return error;\n}\n"]}
@@ -3,10 +3,30 @@
3
3
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
4
  * Licensed under the MIT License.
5
5
  */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
6
25
  Object.defineProperty(exports, "__esModule", { value: true });
7
26
  exports.OdspSummaryUploadManager = void 0;
8
27
  const common_utils_1 = require("@fluidframework/common-utils");
9
28
  const protocol_base_1 = require("@fluidframework/protocol-base");
29
+ const api = __importStar(require("@fluidframework/protocol-definitions"));
10
30
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
11
31
  const getUrlAndHeadersWithAuth_1 = require("./getUrlAndHeadersWithAuth");
12
32
  const odspUtils_1 = require("./odspUtils");
@@ -118,14 +138,14 @@ class OdspSummaryUploadManager {
118
138
  let unreferenced;
119
139
  const currentPath = path === "" ? `${rootNodeName}/${key}` : `${path}/${key}`;
120
140
  switch (summaryObject.type) {
121
- case 1 /* Tree */: {
141
+ case api.SummaryType.Tree: {
122
142
  const result = await this.convertSummaryToSnapshotTree(parentHandle, summaryObject, rootNodeName, currentPath);
123
143
  value = result.snapshotTree;
124
144
  unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;
125
145
  blobs += result.blobs;
126
146
  break;
127
147
  }
128
- case 2 /* Blob */: {
148
+ case api.SummaryType.Blob: {
129
149
  if (typeof summaryObject.content === "string") {
130
150
  value = {
131
151
  type: "blob",
@@ -143,7 +163,7 @@ class OdspSummaryUploadManager {
143
163
  blobs++;
144
164
  break;
145
165
  }
146
- case 3 /* Handle */: {
166
+ case api.SummaryType.Handle: {
147
167
  if (!parentHandle) {
148
168
  throw Error("Parent summary does not exist to reference by handle.");
149
169
  }
@@ -155,7 +175,7 @@ class OdspSummaryUploadManager {
155
175
  id = `${parentHandle}/${pathKey}`;
156
176
  break;
157
177
  }
158
- case 4 /* Attachment */: {
178
+ case api.SummaryType.Attachment: {
159
179
  id = summaryObject.id;
160
180
  break;
161
181
  }
@@ -1 +1 @@
1
- {"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA2F;AAE3F,iEAA2D;AAG3D,qEAAmE;AAUnE,yEAAsE;AACtE,2CAA0D;AAE1D,4BAA4B;AAE5B,mGAAmG;AACnG,SAAS,0BAA0B;IAC/B,IAAI;QACA,sCAAsC;QACtC,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,IAAI,EAAE;YAC3D,IAAK,YAAY,CAAC,0BAA0B,KAAK,GAAG,EAAE;gBAClD,OAAO,IAAI,CAAC;aACf;YACD,IAAK,YAAY,CAAC,0BAA0B,KAAK,GAAG,EAAE;gBAClD,OAAO,KAAK,CAAC;aAChB;SACJ;KACJ;IAAC,OAAO,CAAC,EAAE,GAAE;IAEd,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAa,wBAAwB;IAIjC,YACqB,WAAmB,EACnB,eAAgD,EAChD,MAAwB,EACxB,YAA0B;QAH1B,gBAAW,GAAX,WAAW,CAAQ;QACn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,KAAK,iCACD,KAAK,IACF,SAAS,KACZ,YAAY,GACf,CAAC;aACL;iBAAM,IAAI,EAAE,EAAE;gBACX,KAAK,mCACE,SAAS,KACZ,EAAE,GACL,CAAC;aACL;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aACnE;YAED,YAAY,CAAC,OAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACrC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;CACJ;AAtMD,4DAsMC;AAED,2BAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Uint8ArrayToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspSummaryPayload,\n IWriteSummaryResponse,\n IOdspSummaryTree,\n IOdspSummaryTreeBaseEntry,\n OdspSummaryTreeEntry,\n OdspSummaryTreeValue,\n} from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/* eslint-disable max-len */\n\n// Gate that when flipped, instructs to mark unreferenced nodes as such in the summary sent to SPO.\nfunction gatesMarkUnreferencedNodes() {\n try {\n // Leave override for testing purposes\n if (typeof localStorage === \"object\" && localStorage !== null) {\n if (localStorage.FluidMarkUnreferencedNodes === \"1\") {\n return true;\n }\n if (localStorage.FluidMarkUnreferencedNodes === \"0\") {\n return false;\n }\n }\n } catch (e) {}\n\n return true;\n}\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n // Last proposed handle of the uploaded app summary.\n private lastSummaryProposalHandle: string | undefined;\n\n constructor(\n private readonly snapshotUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly logger: ITelemetryLogger,\n private readonly epochTracker: EpochTracker,\n ) {\n }\n\n public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {\n // If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n // then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n if (context.proposalHandle !== this.lastSummaryProposalHandle) {\n this.logger.sendTelemetryEvent({\n eventName: \"LastSummaryProposedHandleMismatch\",\n ackedSummaryProposedHandle: context.proposalHandle,\n lastSummaryProposalHandle: this.lastSummaryProposalHandle,\n });\n }\n const result = await this.writeSummaryTreeCore(context.ackHandle, context.referenceSequenceNumber, tree);\n const id = result ? result.id : undefined;\n if (!result || !id) {\n throw new Error(`Failed to write summary tree`);\n }\n this.lastSummaryProposalHandle = id;\n return id;\n }\n\n private async writeSummaryTreeCore(\n parentHandle: string | undefined,\n referenceSequenceNumber: number,\n tree: api.ISummaryTree,\n ): Promise<IWriteSummaryResponse> {\n const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n parentHandle,\n tree,\n \".app\",\n \"\",\n );\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries!,\n message: \"app\",\n sequenceNumber: referenceSequenceNumber,\n // no ack handle implies this is initial summary after empty file creation.\n // send container payload so server will use it without a summary op\n type: parentHandle === undefined ? \"container\" : \"channel\",\n };\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n const { url, headers } = getUrlAndHeadersWithAuth(`${this.snapshotUrl}/snapshot`, storageToken);\n headers[\"Content-Type\"] = \"application/json\";\n if (parentHandle) {\n headers[\"If-Match\"] = `fluid:containerid=${parentHandle}`;\n }\n\n const postBody = JSON.stringify(snapshot);\n\n return PerformanceEvent.timedExecAsync(this.logger,\n {\n eventName: \"uploadSummary\",\n attempt: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n blobs,\n size: postBody.length,\n },\n async () => {\n const response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"uploadSummary\");\n return response.content;\n });\n });\n }\n\n /**\n * Following are the goals of this function.\n * a.) Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n * @param rootNodeName - Root node name of the summary tree.\n * @param path - Current path of node which is getting evaluated.\n * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n */\n private async convertSummaryToSnapshotTree(\n parentHandle: string | undefined,\n tree: api.ISummaryTree,\n rootNodeName: string,\n path: string = \"\",\n markUnreferencedNodes: boolean = gatesMarkUnreferencedNodes(),\n ) {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [] as OdspSummaryTreeEntry[],\n };\n\n let blobs = 0;\n const keys = Object.keys(tree.tree);\n for (const key of keys) {\n const summaryObject = tree.tree[key];\n\n let id: string | undefined;\n let value: OdspSummaryTreeValue | undefined;\n\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is\n // true (which is the only value it can have), the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n const currentPath = path === \"\" ? `${rootNodeName}/${key}` : `${path}/${key}`;\n switch (summaryObject.type) {\n case api.SummaryType.Tree: {\n const result = await this.convertSummaryToSnapshotTree(\n parentHandle,\n summaryObject,\n rootNodeName,\n currentPath);\n value = result.snapshotTree;\n unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n blobs += result.blobs;\n break;\n }\n case api.SummaryType.Blob: {\n if (typeof summaryObject.content === \"string\") {\n value = {\n type: \"blob\",\n content: summaryObject.content,\n encoding: \"utf-8\",\n };\n } else {\n value = {\n type: \"blob\",\n content: Uint8ArrayToString(summaryObject.content, \"base64\"),\n encoding: \"base64\",\n };\n }\n blobs++;\n break;\n }\n case api.SummaryType.Handle: {\n if (!parentHandle) {\n throw Error(\"Parent summary does not exist to reference by handle.\");\n }\n let handlePath = summaryObject.handle;\n if (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n handlePath = `/${handlePath}`;\n }\n const pathKey = `${rootNodeName}${handlePath}`;\n id = `${parentHandle}/${pathKey}`;\n break;\n }\n case api.SummaryType.Attachment: {\n id = summaryObject.id;\n break;\n }\n default: {\n unreachableCase(summaryObject, `Unknown type: ${(summaryObject as any).type}`);\n }\n }\n\n const baseEntry: IOdspSummaryTreeBaseEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n };\n\n let entry: OdspSummaryTreeEntry;\n\n if (value) {\n assert(id === undefined, 0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */);\n entry = {\n value,\n ...baseEntry,\n unreferenced,\n };\n } else if (id) {\n entry = {\n ...baseEntry,\n id,\n };\n } else {\n throw new Error(`Invalid tree entry for ${summaryObject.type}`);\n }\n\n snapshotTree.entries!.push(entry);\n }\n\n return { snapshotTree, blobs };\n }\n}\n\n/* eslint-enable max-len */\n"]}
1
+ {"version":3,"file":"odspSummaryUploadManager.js","sourceRoot":"","sources":["../src/odspSummaryUploadManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAGH,+DAA2F;AAE3F,iEAA2D;AAC3D,0EAA4D;AAE5D,qEAAmE;AAUnE,yEAAsE;AACtE,2CAA0D;AAE1D,4BAA4B;AAE5B,mGAAmG;AACnG,SAAS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AAU,EAAE,CAAC;oBAC/C,EAAE,GAAG,GAAG,YAAY,IAAI,OAAO,EAAE,CAAC;oBAClC,MAAM;iBACT;gBACD,KAAK,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;oBAC7B,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;oBACtB,MAAM;iBACT;gBACD,OAAO,CAAC,CAAC;oBACL,8BAAe,CAAC,aAAa,EAAE,iBAAkB,aAAqB,CAAC,IAAI,EAAE,CAAC,CAAC;iBAClF;aACJ;YAED,MAAM,SAAS,GAA8B;gBACzC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;gBAC7B,IAAI,EAAE,0BAAU,CAAC,aAAa,CAAC;aAClC,CAAC;YAEF,IAAI,KAA2B,CAAC;YAEhC,IAAI,KAAK,EAAE;gBACP,qBAAM,CAAC,EAAE,KAAK,SAAS,EAAE,KAAK,CAAC,iEAAiE,CAAC,CAAC;gBAClG,KAAK,iCACD,KAAK,IACF,SAAS,KACZ,YAAY,GACf,CAAC;aACL;iBAAM,IAAI,EAAE,EAAE;gBACX,KAAK,mCACE,SAAS,KACZ,EAAE,GACL,CAAC;aACL;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,0BAA0B,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;aACnE;YAED,YAAY,CAAC,OAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACrC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;CACJ;AAtMD,4DAsMC;AAED,2BAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Uint8ArrayToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISummaryContext } from \"@fluidframework/driver-definitions\";\nimport { getGitType } from \"@fluidframework/protocol-base\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { InstrumentedStorageTokenFetcher } from \"@fluidframework/odsp-driver-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IOdspSummaryPayload,\n IWriteSummaryResponse,\n IOdspSummaryTree,\n IOdspSummaryTreeBaseEntry,\n OdspSummaryTreeEntry,\n OdspSummaryTreeValue,\n} from \"./contracts\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { getWithRetryForTokenRefresh } from \"./odspUtils\";\n\n/* eslint-disable max-len */\n\n// Gate that when flipped, instructs to mark unreferenced nodes as such in the summary sent to SPO.\nfunction gatesMarkUnreferencedNodes() {\n try {\n // Leave override for testing purposes\n if (typeof localStorage === \"object\" && localStorage !== null) {\n if (localStorage.FluidMarkUnreferencedNodes === \"1\") {\n return true;\n }\n if (localStorage.FluidMarkUnreferencedNodes === \"0\") {\n return false;\n }\n }\n } catch (e) {}\n\n return true;\n}\n\n/**\n * This class manages a summary upload. When it receives a call to upload summary, it converts the summary tree into\n * a snapshot tree and then uploads that to the server.\n */\nexport class OdspSummaryUploadManager {\n // Last proposed handle of the uploaded app summary.\n private lastSummaryProposalHandle: string | undefined;\n\n constructor(\n private readonly snapshotUrl: string,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly logger: ITelemetryLogger,\n private readonly epochTracker: EpochTracker,\n ) {\n }\n\n public async writeSummaryTree(tree: api.ISummaryTree, context: ISummaryContext) {\n // If the last proposed handle is not the proposed handle of the acked summary(could happen when the last summary get nacked),\n // then re-initialize the caches with the previous ones else just update the previous caches with the caches from acked summary.\n if (context.proposalHandle !== this.lastSummaryProposalHandle) {\n this.logger.sendTelemetryEvent({\n eventName: \"LastSummaryProposedHandleMismatch\",\n ackedSummaryProposedHandle: context.proposalHandle,\n lastSummaryProposalHandle: this.lastSummaryProposalHandle,\n });\n }\n const result = await this.writeSummaryTreeCore(context.ackHandle, context.referenceSequenceNumber, tree);\n const id = result ? result.id : undefined;\n if (!result || !id) {\n throw new Error(`Failed to write summary tree`);\n }\n this.lastSummaryProposalHandle = id;\n return id;\n }\n\n private async writeSummaryTreeCore(\n parentHandle: string | undefined,\n referenceSequenceNumber: number,\n tree: api.ISummaryTree,\n ): Promise<IWriteSummaryResponse> {\n const { snapshotTree, blobs } = await this.convertSummaryToSnapshotTree(\n parentHandle,\n tree,\n \".app\",\n \"\",\n );\n const snapshot: IOdspSummaryPayload = {\n entries: snapshotTree.entries!,\n message: \"app\",\n sequenceNumber: referenceSequenceNumber,\n // no ack handle implies this is initial summary after empty file creation.\n // send container payload so server will use it without a summary op\n type: parentHandle === undefined ? \"container\" : \"channel\",\n };\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"WriteSummaryTree\");\n\n const { url, headers } = getUrlAndHeadersWithAuth(`${this.snapshotUrl}/snapshot`, storageToken);\n headers[\"Content-Type\"] = \"application/json\";\n if (parentHandle) {\n headers[\"If-Match\"] = `fluid:containerid=${parentHandle}`;\n }\n\n const postBody = JSON.stringify(snapshot);\n\n return PerformanceEvent.timedExecAsync(this.logger,\n {\n eventName: \"uploadSummary\",\n attempt: options.refresh ? 2 : 1,\n hasClaims: !!options.claims,\n hasTenantId: !!options.tenantId,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n blobs,\n size: postBody.length,\n },\n async () => {\n const response = await this.epochTracker.fetchAndParseAsJSON<IWriteSummaryResponse>(\n url,\n {\n body: postBody,\n headers,\n method: \"POST\",\n },\n \"uploadSummary\");\n return response.content;\n });\n });\n }\n\n /**\n * Following are the goals of this function.\n * a.) Converts the summary tree to a snapshot/odsp tree to be uploaded. Always upload full snapshot tree.\n * @param parentHandle - Handle of the last uploaded summary or detach new summary.\n * @param tree - Summary Tree which will be converted to snapshot tree to be uploaded.\n * @param rootNodeName - Root node name of the summary tree.\n * @param path - Current path of node which is getting evaluated.\n * @param markUnreferencedNodes - True if we should mark unreferenced nodes.\n */\n private async convertSummaryToSnapshotTree(\n parentHandle: string | undefined,\n tree: api.ISummaryTree,\n rootNodeName: string,\n path: string = \"\",\n markUnreferencedNodes: boolean = gatesMarkUnreferencedNodes(),\n ) {\n const snapshotTree: IOdspSummaryTree = {\n type: \"tree\",\n entries: [] as OdspSummaryTreeEntry[],\n };\n\n let blobs = 0;\n const keys = Object.keys(tree.tree);\n for (const key of keys) {\n const summaryObject = tree.tree[key];\n\n let id: string | undefined;\n let value: OdspSummaryTreeValue | undefined;\n\n // Tracks if an entry is unreferenced. Currently, only tree entries can be marked as unreferenced. If the\n // property is not present, the tree entry is considered referenced. If the property is present and is\n // true (which is the only value it can have), the tree entry is considered unreferenced.\n let unreferenced: true | undefined;\n const currentPath = path === \"\" ? `${rootNodeName}/${key}` : `${path}/${key}`;\n switch (summaryObject.type) {\n case api.SummaryType.Tree: {\n const result = await this.convertSummaryToSnapshotTree(\n parentHandle,\n summaryObject,\n rootNodeName,\n currentPath);\n value = result.snapshotTree;\n unreferenced = markUnreferencedNodes ? summaryObject.unreferenced : undefined;\n blobs += result.blobs;\n break;\n }\n case api.SummaryType.Blob: {\n if (typeof summaryObject.content === \"string\") {\n value = {\n type: \"blob\",\n content: summaryObject.content,\n encoding: \"utf-8\",\n };\n } else {\n value = {\n type: \"blob\",\n content: Uint8ArrayToString(summaryObject.content, \"base64\"),\n encoding: \"base64\",\n };\n }\n blobs++;\n break;\n }\n case api.SummaryType.Handle: {\n if (!parentHandle) {\n throw Error(\"Parent summary does not exist to reference by handle.\");\n }\n let handlePath = summaryObject.handle;\n if (handlePath.length > 0 && !handlePath.startsWith(\"/\")) {\n handlePath = `/${handlePath}`;\n }\n const pathKey = `${rootNodeName}${handlePath}`;\n id = `${parentHandle}/${pathKey}`;\n break;\n }\n case api.SummaryType.Attachment: {\n id = summaryObject.id;\n break;\n }\n default: {\n unreachableCase(summaryObject, `Unknown type: ${(summaryObject as any).type}`);\n }\n }\n\n const baseEntry: IOdspSummaryTreeBaseEntry = {\n path: encodeURIComponent(key),\n type: getGitType(summaryObject),\n };\n\n let entry: OdspSummaryTreeEntry;\n\n if (value) {\n assert(id === undefined, 0x0ad /* \"Snapshot entry has both a tree value and a referenced id!\" */);\n entry = {\n value,\n ...baseEntry,\n unreferenced,\n };\n } else if (id) {\n entry = {\n ...baseEntry,\n id,\n };\n } else {\n throw new Error(`Invalid tree entry for ${summaryObject.type}`);\n }\n\n snapshotTree.entries!.push(entry);\n }\n\n return { snapshotTree, blobs };\n }\n}\n\n/* eslint-enable max-len */\n"]}
@@ -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;AAGnF,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAYhG,OAAO,EACH,gBAAgB,EAChB,iBAAiB,EAIjB,6BAA6B,EAC7B,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,+BAA+B,EAClC,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAO,MAAM,iCAAiC,sCAAsC,CAAC;AAErF,4DAA4D;AAC5D,eAAO,MAAM,SAAS,QAAS,MAAM,WAAwB,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAC9B,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChC,GAAG,EAAE,yBAAyB,EAAE,CAAC;IACjC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC5B,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,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ED
@@ -37,7 +37,7 @@ async function getWithRetryForTokenRefresh(get) {
37
37
  // If the error is 401 or 403 refresh the token and try once more.
38
38
  case driver_definitions_1.DriverErrorType.authorizationError:
39
39
  return get(Object.assign(Object.assign({}, options), { claims: e.claims, tenantId: e.tenantId }));
40
- case driver_definitions_1.DriverErrorType.incorrectServerResponse: // fetchIncorrectResponse - some error on the wire, retry once
40
+ case driver_definitions_1.DriverErrorType.incorrectServerResponse: // some error on the wire, retry once
41
41
  case odsp_driver_definitions_1.OdspErrorType.fetchTokenError: // If the token was null, then retry once.
42
42
  return get(options);
43
43
  default:
@@ -57,7 +57,7 @@ async function fetchHelper(requestInfo, requestInit) {
57
57
  const response = fetchResponse;
58
58
  // Let's assume we can retry.
59
59
  if (!response) {
60
- odsp_doclib_utils_1.throwOdspNetworkError("odspFetchErrorNoResponse", odsp_doclib_utils_1.fetchIncorrectResponse);
60
+ throw new driver_utils_1.NonRetryableError("odspFetchErrorNoResponse", "No response from fetch call", driver_definitions_1.DriverErrorType.incorrectServerResponse);
61
61
  }
62
62
  if (!response.ok || response.status < 200 || response.status >= 300) {
63
63
  odsp_doclib_utils_1.throwOdspNetworkError(`odspFetchError [${response.status}]`, response.status, response, await response.text());
@@ -78,19 +78,25 @@ async function fetchHelper(requestInfo, requestInit) {
78
78
  if (errorText === "TypeError: Failed to fetch") {
79
79
  online = driver_utils_1.OnlineStatus.Offline;
80
80
  }
81
+ // This error is thrown by fetch() when AbortSignal is provided and it gets cancelled
81
82
  if (error.name === "AbortError") {
82
- odsp_doclib_utils_1.throwOdspNetworkError("timeoutDuringFetch", odsp_doclib_utils_1.fetchTimeoutStatusCode);
83
+ throw new driver_utils_1.RetryableError("fetchAbort", "Fetch Timeout (AbortError)", odsp_driver_definitions_1.OdspErrorType.fetchTimeout);
83
84
  }
85
+ // TCP/IP timeout
84
86
  if (errorText.indexOf("ETIMEDOUT") !== -1) {
85
- odsp_doclib_utils_1.throwOdspNetworkError("timeoutDuringFetch(ETIMEDOUT)", odsp_doclib_utils_1.fetchTimeoutStatusCode);
87
+ throw new driver_utils_1.RetryableError("fetchETimedout", "Fetch Timeout (ETIMEDOUT)", odsp_driver_definitions_1.OdspErrorType.fetchTimeout);
86
88
  }
87
89
  //
88
90
  // WARNING: Do not log error object itself or any of its properties!
89
91
  // It could container PII, like URI in message itself, or token in properties.
90
92
  // It is also non-serializable object due to circular references.
91
93
  //
92
- const failureCode = online === driver_utils_1.OnlineStatus.Offline ? odsp_doclib_utils_1.offlineFetchFailureStatusCode : odsp_doclib_utils_1.fetchFailureStatusCode;
93
- odsp_doclib_utils_1.throwOdspNetworkError(`odspFetchThrewError [${failureCode}]`, failureCode);
94
+ if (online === driver_utils_1.OnlineStatus.Offline) {
95
+ throw new driver_utils_1.RetryableError("OdspFetchOffline", `Offline: ${errorText}`, driver_definitions_1.DriverErrorType.offlineError);
96
+ }
97
+ else {
98
+ throw new driver_utils_1.RetryableError("OdspFetchError", `Fetch error: ${errorText}`, driver_definitions_1.DriverErrorType.fetchFailure);
99
+ }
94
100
  });
95
101
  }
96
102
  exports.fetchHelper = fetchHelper;
@@ -118,24 +124,27 @@ exports.fetchArray = fetchArray;
118
124
  */
119
125
  async function fetchAndParseAsJSONHelper(requestInfo, requestInit) {
120
126
  const { content, headers, commonSpoHeaders, duration } = await fetchHelper(requestInfo, requestInit);
121
- // JSON.parse() can fail and message (that goes into telemetry) would container full request URI, including
122
- // tokens... It fails for me with "Unexpected end of JSON input" quite often - an attempt to download big file
123
- // (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always
124
- // succeeds on retry.
127
+ let text;
125
128
  try {
126
- const text = await content.text();
127
- commonSpoHeaders.bodySize = text.length;
128
- const res = {
129
- headers,
130
- content: JSON.parse(text),
131
- commonSpoHeaders,
132
- duration,
133
- };
134
- return res;
129
+ text = await content.text();
135
130
  }
136
131
  catch (e) {
137
- odsp_doclib_utils_1.throwOdspNetworkError("errorWhileParsingFetchResponse", odsp_doclib_utils_1.fetchIncorrectResponse, content, undefined, { error: Object(e) });
132
+ // JSON.parse() can fail and message would container full request URI, including
133
+ // tokens... It fails for me with "Unexpected end of JSON input" quite often - an attempt to download big file
134
+ // (many ops) almost always ends up with this error - I'd guess 1% of op request end up here... It always
135
+ // succeeds on retry.
136
+ // So do not log error object itself.
137
+ odsp_doclib_utils_1.throwOdspNetworkError("errorWhileParsingFetchResponse", odsp_doclib_utils_1.fetchIncorrectResponse, content, // response
138
+ text);
138
139
  }
140
+ commonSpoHeaders.bodySize = text.length;
141
+ const res = {
142
+ headers,
143
+ content: JSON.parse(text),
144
+ commonSpoHeaders,
145
+ duration,
146
+ };
147
+ return res;
139
148
  }
140
149
  exports.fetchAndParseAsJSONHelper = fetchAndParseAsJSONHelper;
141
150
  function getOdspResolvedUrl(resolvedUrl) {
@@ -194,12 +203,11 @@ function toInstrumentedOdspTokenFetcher(logger, resolvedUrl, tokenFetcher, throw
194
203
  event.end({ fromCache: odsp_driver_definitions_1.isTokenFromCache(tokenResponse), isNull: token === null });
195
204
  }
196
205
  if (token === null && throwOnNullToken) {
197
- odsp_doclib_utils_1.throwOdspNetworkError("tokenIsNull", odsp_doclib_utils_1.fetchTokenErrorCode, undefined, undefined, { method: name });
206
+ throw new driver_utils_1.NonRetryableError("storageTokenIsNull", `Token is null for ${name} call`, odsp_driver_definitions_1.OdspErrorType.fetchTokenError, { method: name });
198
207
  }
199
208
  return token;
200
209
  }, (error) => {
201
- const tokenError = telemetry_utils_1.wrapError(error, (errorMessage) => odsp_doclib_utils_1.createOdspNetworkError("tokenFetcherFailed", errorMessage, odsp_doclib_utils_1.fetchTokenErrorCode));
202
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
210
+ const tokenError = telemetry_utils_1.wrapError(error, (errorMessage) => new driver_utils_1.NonRetryableError("tokenFetcherFailed", errorMessage, odsp_driver_definitions_1.OdspErrorType.fetchTokenError, { method: name }));
203
211
  throw tokenError;
204
212
  }), { cancel: "generic" });
205
213
  };
@@ -1 +1 @@
1
- {"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,KAAK,GAAG,2CAAiB,CAAC,aAAa,CAAC,CAAC;YAC/C,yFAAyF;YACzF,2DAA2D;YAC3D,oFAAoF;YACpF,6FAA6F;YAC7F,oCAAoC;YACpC,IAAI,+BAA+B,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE;gBACzD,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,0CAAgB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,KAAK,IAAI,EAAE,CAAC,CAAC;aACrF;YACD,IAAI,KAAK,KAAK,IAAI,IAAI,gBAAgB,EAAE;gBACpC,yCAAqB,CAAC,aAAa,EAAE,uCAAmB,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aACrG;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACT,MAAM,UAAU,GAAG,2BAAS,CACxB,KAAK,EACL,CAAC,YAAY,EAAE,EAAE,CAAC,0CAAsB,CAAC,oBAAoB,EAAE,YAAY,EAAE,uCAAmB,CAAC,CAAC,CAAC;YACvG,+DAA+D;YAC/D,MAAM,UAAU,CAAC;QACrB,CAAC,CAAC,EACF,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC;AA/CD,wEA+CC;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 { isOnline, OnlineStatus } 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 offlineFetchFailureStatusCode,\n fetchFailureStatusCode,\n fetchTimeoutStatusCode,\n throwOdspNetworkError,\n getSPOAndGraphRequestIdsFromResponse,\n fetchTokenErrorCode,\n createOdspNetworkError,\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} from \"@fluidframework/odsp-driver-definitions\";\nimport { fetch } from \"./fetch\";\nimport { pkgVersion } 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 commonSpoHeaders: 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: // fetchIncorrectResponse - 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 throwOdspNetworkError(\"odspFetchErrorNoResponse\", fetchIncorrectResponse);\n }\n if (!response.ok || response.status < 200 || response.status >= 300) {\n throwOdspNetworkError(\n `odspFetchError [${response.status}]`, response.status, response, await response.text());\n }\n\n const headers = headersToMap(response.headers);\n return {\n content: response,\n headers,\n commonSpoHeaders: 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 if (error.name === \"AbortError\") {\n throwOdspNetworkError(\"timeoutDuringFetch\", fetchTimeoutStatusCode);\n }\n if (errorText.indexOf(\"ETIMEDOUT\") !== -1) {\n throwOdspNetworkError(\"timeoutDuringFetch(ETIMEDOUT)\", fetchTimeoutStatusCode);\n }\n\n //\n // WARNING: Do not log error object itself or any of its properties!\n // It could container PII, like URI in message itself, or token in properties.\n // It is also non-serializable object due to circular references.\n //\n const failureCode = online === OnlineStatus.Offline ? offlineFetchFailureStatusCode : fetchFailureStatusCode;\n throwOdspNetworkError(\n `odspFetchThrewError [${failureCode}]`,\n failureCode,\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, commonSpoHeaders, duration } = await fetchHelper(requestInfo, requestInit);\n\n const arrayBuffer = await content.arrayBuffer();\n commonSpoHeaders.bodySize = arrayBuffer.byteLength;\n return {\n headers,\n content: arrayBuffer,\n commonSpoHeaders,\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, commonSpoHeaders, duration } = await fetchHelper(requestInfo, requestInit);\n // JSON.parse() can fail and message (that goes into telemetry) 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 try {\n const text = await content.text();\n\n commonSpoHeaders.bodySize = text.length;\n const res = {\n headers,\n content: JSON.parse(text),\n commonSpoHeaders,\n duration,\n };\n return res;\n } catch (e) {\n throwOdspNetworkError(\n \"errorWhileParsingFetchResponse\",\n fetchIncorrectResponse,\n content,\n undefined,\n { error: Object(e) },\n );\n }\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: pkgVersion,\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 resolvedUrl: IOdspResolvedUrl,\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 siteUrl: resolvedUrl.siteUrl,\n driveId: resolvedUrl.driveId,\n itemId: resolvedUrl.itemId,\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 throwOdspNetworkError(\"tokenIsNull\", fetchTokenErrorCode, undefined, undefined, { method: name });\n }\n return token;\n }, (error) => {\n const tokenError = wrapError(\n error,\n (errorMessage) => createOdspNetworkError(\"tokenFetcherFailed\", errorMessage, fetchTokenErrorCode));\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\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"]}
1
+ {"version":3,"file":"odspUtils.js","sourceRoot":"","sources":["../src/odspUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2EAAmF;AACnF,+DAAyG;AACzG,+DAAmE;AAEnE,qEAA2F;AAC3F,yEAI2C;AAC3C,qFAYiD;AACjD,mCAAgC;AAChC,qDAA8C;AAGjC,QAAA,iCAAiC,GAAG,mCAAmC,CAAC;AAErF,4DAA4D;AACrD,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAA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C,IAAI,+BAA+B,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE;gBACzD,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,0CAAgB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,KAAK,IAAI,EAAE,CAAC,CAAC;aACrF;YACD,IAAI,KAAK,KAAK,IAAI,IAAI,gBAAgB,EAAE;gBACpC,MAAM,IAAI,gCAAiB,CACvB,oBAAoB,EACpB,qBAAqB,IAAI,OAAO,EAChC,uCAAa,CAAC,eAAe,EAC7B,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aACzB;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACT,MAAM,UAAU,GAAG,2BAAS,CACxB,KAAK,EACL,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,gCAAiB,CACnC,oBAAoB,EACpB,YAAY,EACZ,uCAAa,CAAC,eAAe,EAC7B,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3B,MAAM,UAAU,CAAC;QACrB,CAAC,CAAC,EACF,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC;AAtDD,wEAsDC;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 { isOnline, OnlineStatus, RetryableError, NonRetryableError } 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} from \"@fluidframework/odsp-driver-definitions\";\nimport { fetch } from \"./fetch\";\nimport { pkgVersion } 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 commonSpoHeaders: 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 \"odspFetchErrorNoResponse\",\n \"No response from fetch call\",\n DriverErrorType.incorrectServerResponse);\n }\n if (!response.ok || response.status < 200 || response.status >= 300) {\n throwOdspNetworkError(\n `odspFetchError [${response.status}]`, response.status, response, await response.text());\n }\n\n const headers = headersToMap(response.headers);\n return {\n content: response,\n headers,\n commonSpoHeaders: 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(\"fetchAbort\", \"Fetch Timeout (AbortError)\", OdspErrorType.fetchTimeout);\n }\n // TCP/IP timeout\n if (errorText.indexOf(\"ETIMEDOUT\") !== -1) {\n throw new RetryableError(\"fetchETimedout\", \"Fetch Timeout (ETIMEDOUT)\", OdspErrorType.fetchTimeout);\n }\n\n //\n // WARNING: Do not log error object itself or any of its properties!\n // It could container 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(\"OdspFetchOffline\", `Offline: ${errorText}`, DriverErrorType.offlineError);\n } else {\n throw new RetryableError(\"OdspFetchError\", `Fetch error: ${errorText}`, DriverErrorType.fetchFailure);\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, commonSpoHeaders, duration } = await fetchHelper(requestInfo, requestInit);\n\n const arrayBuffer = await content.arrayBuffer();\n commonSpoHeaders.bodySize = arrayBuffer.byteLength;\n return {\n headers,\n content: arrayBuffer,\n commonSpoHeaders,\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, commonSpoHeaders, 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 \"errorWhileParsingFetchResponse\",\n fetchIncorrectResponse,\n content, // response\n text,\n );\n }\n\n commonSpoHeaders.bodySize = text.length;\n const res = {\n headers,\n content: JSON.parse(text),\n commonSpoHeaders,\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: pkgVersion,\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 resolvedUrl: IOdspResolvedUrl,\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 siteUrl: resolvedUrl.siteUrl,\n driveId: resolvedUrl.driveId,\n itemId: resolvedUrl.itemId,\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 \"storageTokenIsNull\",\n `Token is null for ${name} call`,\n OdspErrorType.fetchTokenError,\n { method: name });\n }\n return token;\n }, (error) => {\n const tokenError = wrapError(\n error,\n (errorMessage) => new NonRetryableError(\n \"tokenFetcherFailed\",\n errorMessage,\n OdspErrorType.fetchTokenError,\n { method: name }));\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"]}
@@ -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.51.3";
8
+ export declare const pkgVersion = "0.53.0-46105";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,gCAAgC,CAAC;AACrD,eAAO,MAAM,UAAU,WAAW,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,gCAAgC,CAAC;AACrD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
@@ -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.51.3";
11
+ exports.pkgVersion = "0.53.0-46105";
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,QAAQ,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.51.3\";\n"]}
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,cAAc,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.53.0-46105\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"zipItDataRepresentationUtils.d.ts","sour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ED,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,IAAI,OAAO,CAKzB"}
1
+ {"version":3,"file":"zipItDataRepresentationUtils.d.ts","sourceRoot":"","sources":["../src/zipItDataRepresentationUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C;;;GAGG;AACH,oBAAY,WAAW;IACnB,QAAQ,KAAK;IACb,SAAS,KAAK;IAEd,WAAW,KAAK;IAChB,aAAa,KAAK;IAClB,cAAc,KAAK;IACnB,cAAc,KAAK;IAEnB,cAAc,KAAK;IACnB,eAAe,KAAK;IACpB,eAAe,KAAK;IACpB,kBAAkB,KAAK;IACvB,qBAAqB,KAAK;IAE1B,IAAI,IAAI;IACR,KAAK,IAAI;IACT,MAAM,IAAI;IACV,MAAM,IAAI;IACV,MAAM,IAAI;IACV,IAAI,IAAI;IACR,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;IAET,WAAW,KAAK;IAChB,aAAa,KAAK;IAClB,cAAc,KAAK;IACnB,cAAc,KAAK;IACnB,cAAc,KAAK;CACtB;AAED;;GAEG;AACH,oBAAY,gBAAgB;IACxB,MAAM,KAAK;IACX,KAAK,KAAK;CACb;AAED;;GAEG;AACH,oBAAY,cAAc;IACtB,MAAM,KAAK;IACX,KAAK,KAAK;CACb;AAED;;;EAGE;AACF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;CA+B1B,CAAC;AAEF,wBAAgB,cAAc,CAAC,GAAG,EAAE;IAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,EAAE,GAAG,EAAE,MAAM,UAIzE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,eAAe,UAAO,6BAe9F;AAED,wBAAgB,YAAY,CAAC,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ChB,OAAO,CAAC,IAAI,IAAI,QAAQ,CAK1B;AAED,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,IAAI,MAAM,CAKxB;AAED,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,IAAI,OAAO,CAKzB"}
@@ -10,7 +10,8 @@ exports.assertBoolInstance = exports.assertNumberInstance = exports.assertNodeCo
10
10
  * https://microsoft.sharepoint-df.com/:w:/t/ODSPFileStore/ER06b64K_XdDjEyAKl-UT60BJiId39SCVkYSyo_2pvH9gQ?e=KYQ0c5
11
11
  */
12
12
  const common_utils_1 = require("@fluidframework/common-utils");
13
- const odsp_doclib_utils_1 = require("@fluidframework/odsp-doclib-utils");
13
+ const driver_utils_1 = require("@fluidframework/driver-utils");
14
+ const driver_definitions_1 = require("@fluidframework/driver-definitions");
14
15
  // eslint-disable-next-line max-len
15
16
  // https://onedrive.visualstudio.com/SharePoint%20Online/_git/SPO?path=/cobalt/Base/Property/BinaryEncodedPropertyReader.cs&version=GBmaster&_a=contents
16
17
  /**
@@ -417,12 +418,10 @@ function assertBoolInstance(node, message) {
417
418
  }
418
419
  exports.assertBoolInstance = assertBoolInstance;
419
420
  function throwBufferParseException(node, expectedNodeType, message) {
420
- const error = odsp_doclib_utils_1.createOdspNetworkError("bufferParsingException", message, odsp_doclib_utils_1.fetchIncorrectResponse, undefined, undefined, undefined, {
421
+ throw new driver_utils_1.NonRetryableError("bufferParsingException", message, driver_definitions_1.DriverErrorType.incorrectServerResponse, {
421
422
  nodeType: getNodeType(node),
422
423
  expectedNodeType,
423
424
  });
424
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
425
- throw error;
426
425
  }
427
426
  function getNodeType(value) {
428
427
  if (typeof value === "number") {