@fluidframework/odsp-driver 2.3.0 → 2.4.0-294316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/getFileLink.d.ts +2 -2
- package/dist/getFileLink.d.ts.map +1 -1
- package/dist/getFileLink.js +54 -28
- package/dist/getFileLink.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/getFileLink.d.ts +2 -2
- package/lib/getFileLink.d.ts.map +1 -1
- package/lib/getFileLink.js +48 -22
- package/lib/getFileLink.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +12 -12
- package/src/getFileLink.ts +54 -22
- package/src/packageVersion.ts +1 -1
package/dist/getFileLink.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { OdspResourceTokenFetchOptions, TokenFetcher, type IOdspResolvedUrl } from "@fluidframework/odsp-driver-definitions/internal";
|
|
6
6
|
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
7
7
|
/**
|
|
8
8
|
* Returns file link for a file with given drive and item ids.
|
|
@@ -15,5 +15,5 @@ import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
|
15
15
|
* @param logger - used to log results of operation, including any error
|
|
16
16
|
* @returns Promise which resolves to file link url when successful; otherwise, undefined.
|
|
17
17
|
*/
|
|
18
|
-
export declare function getFileLink(getToken: TokenFetcher<OdspResourceTokenFetchOptions>,
|
|
18
|
+
export declare function getFileLink(getToken: TokenFetcher<OdspResourceTokenFetchOptions>, resolvedUrl: IOdspResolvedUrl, logger: ITelemetryLoggerExt): Promise<string>;
|
|
19
19
|
//# sourceMappingURL=getFileLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileLink.d.ts","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"getFileLink.d.ts","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAGN,6BAA6B,EAC7B,YAAY,EACZ,KAAK,gBAAgB,EACrB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAGnB,MAAM,0CAA0C,CAAC;AAclD;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAChC,QAAQ,EAAE,YAAY,CAAC,6BAA6B,CAAC,EACrD,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,mBAAmB,GACzB,OAAO,CAAC,MAAM,CAAC,CAqDjB"}
|
package/dist/getFileLink.js
CHANGED
|
@@ -7,9 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.getFileLink = void 0;
|
|
8
8
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
9
|
const internal_2 = require("@fluidframework/driver-utils/internal");
|
|
10
|
-
const internal_3 = require("@fluidframework/odsp-
|
|
11
|
-
const internal_4 = require("@fluidframework/
|
|
12
|
-
const internal_5 = require("@fluidframework/telemetry-utils/internal");
|
|
10
|
+
const internal_3 = require("@fluidframework/odsp-driver-definitions/internal");
|
|
11
|
+
const internal_4 = require("@fluidframework/telemetry-utils/internal");
|
|
13
12
|
const getUrlAndHeadersWithAuth_js_1 = require("./getUrlAndHeadersWithAuth.js");
|
|
14
13
|
const odspUtils_js_1 = require("./odspUtils.js");
|
|
15
14
|
const packageVersion_js_1 = require("./packageVersion.js");
|
|
@@ -27,8 +26,8 @@ const fileLinkCache = new Map();
|
|
|
27
26
|
* @param logger - used to log results of operation, including any error
|
|
28
27
|
* @returns Promise which resolves to file link url when successful; otherwise, undefined.
|
|
29
28
|
*/
|
|
30
|
-
async function getFileLink(getToken,
|
|
31
|
-
const cacheKey = `${
|
|
29
|
+
async function getFileLink(getToken, resolvedUrl, logger) {
|
|
30
|
+
const cacheKey = `${resolvedUrl.siteUrl}_${resolvedUrl.driveId}_${resolvedUrl.itemId}`;
|
|
32
31
|
const maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);
|
|
33
32
|
if (maybeFileLinkCacheEntry !== undefined) {
|
|
34
33
|
return maybeFileLinkCacheEntry;
|
|
@@ -37,7 +36,7 @@ async function getFileLink(getToken, odspUrlParts, logger) {
|
|
|
37
36
|
let fileLinkCore;
|
|
38
37
|
try {
|
|
39
38
|
let retryCount = 0;
|
|
40
|
-
fileLinkCore = await (0, internal_2.runWithRetry)(async () => (0, retryUtils_js_1.runWithRetry)(async () => getFileLinkWithLocationRedirectionHandling(getToken,
|
|
39
|
+
fileLinkCore = await (0, internal_2.runWithRetry)(async () => (0, retryUtils_js_1.runWithRetry)(async () => getFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger), "getFileLinkCore", logger), "getShareLink", logger, {
|
|
41
40
|
// TODO: use a stronger type
|
|
42
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
42
|
onRetry(delayInMs, error) {
|
|
@@ -80,29 +79,38 @@ exports.getFileLink = getFileLink;
|
|
|
80
79
|
* @legacy
|
|
81
80
|
* @alpha
|
|
82
81
|
*/
|
|
83
|
-
async function getFileLinkWithLocationRedirectionHandling(getToken,
|
|
82
|
+
async function getFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger) {
|
|
84
83
|
// We can have chains of location redirection one after the other, so have a for loop
|
|
85
84
|
// so that we can keep handling the same type of error. Set max number of redirection to 5.
|
|
86
85
|
let lastError;
|
|
86
|
+
let locationRedirected = false;
|
|
87
87
|
for (let count = 1; count <= 5; count++) {
|
|
88
88
|
try {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const redirectLocation = error.redirectLocation;
|
|
89
|
+
const fileItem = await getFileItemLite(getToken, resolvedUrl, logger, true);
|
|
90
|
+
// Sometimes the siteUrl in the actual file is different from the siteUrl in the resolvedUrl due to location
|
|
91
|
+
// redirection. This creates issues in the getSharingInformation call. So we need to update the siteUrl in the
|
|
92
|
+
// resolvedUrl to the siteUrl in the fileItem which is the updated siteUrl.
|
|
93
|
+
const oldSiteDomain = new URL(resolvedUrl.siteUrl).origin;
|
|
94
|
+
const newSiteDomain = new URL(fileItem.sharepointIds.siteUrl).origin;
|
|
95
|
+
if (oldSiteDomain !== newSiteDomain) {
|
|
96
|
+
locationRedirected = true;
|
|
98
97
|
logger.sendTelemetryEvent({
|
|
99
98
|
eventName: "LocationRedirectionErrorForGetOdspFileLink",
|
|
100
99
|
retryCount: count,
|
|
101
100
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
renameTenantInOdspResolvedUrl(resolvedUrl, newSiteDomain);
|
|
102
|
+
}
|
|
103
|
+
return await getFileLinkCore(getToken, resolvedUrl, logger, fileItem);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
lastError = error;
|
|
107
|
+
// If the getSharingLink call fails with the 401/403/404 error, then it could be due to that the file has moved
|
|
108
|
+
// to another location. This could occur in case we have more than 1 tenant rename. In that case, we should retry
|
|
109
|
+
// the getFileItemLite call to get the updated fileItem.
|
|
110
|
+
if ((0, internal_4.isFluidError)(error) &&
|
|
111
|
+
locationRedirected &&
|
|
112
|
+
(error.errorType === internal_3.OdspErrorTypes.fileNotFoundOrAccessDeniedError ||
|
|
113
|
+
error.errorType === internal_3.OdspErrorTypes.authorizationError)) {
|
|
106
114
|
continue;
|
|
107
115
|
}
|
|
108
116
|
throw error;
|
|
@@ -110,10 +118,9 @@ async function getFileLinkWithLocationRedirectionHandling(getToken, odspUrlParts
|
|
|
110
118
|
}
|
|
111
119
|
throw lastError;
|
|
112
120
|
}
|
|
113
|
-
async function getFileLinkCore(getToken, odspUrlParts, logger) {
|
|
114
|
-
const fileItem = await getFileItemLite(getToken, odspUrlParts, logger, true);
|
|
121
|
+
async function getFileLinkCore(getToken, odspUrlParts, logger, fileItem) {
|
|
115
122
|
// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder
|
|
116
|
-
return
|
|
123
|
+
return internal_4.PerformanceEvent.timedExecAsync(logger, { eventName: "odspFileLink", requestName: "getSharingInformation" }, async (event) => {
|
|
117
124
|
let attempts = 0;
|
|
118
125
|
let additionalProps;
|
|
119
126
|
const fileLink = await (0, odspUtils_js_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
@@ -134,7 +141,6 @@ async function getFileLinkCore(getToken, odspUrlParts, logger) {
|
|
|
134
141
|
headers: {
|
|
135
142
|
"Content-Type": "application/json;odata=verbose",
|
|
136
143
|
"Accept": "application/json;odata=verbose",
|
|
137
|
-
"redirect": "manual",
|
|
138
144
|
...headers,
|
|
139
145
|
},
|
|
140
146
|
};
|
|
@@ -146,7 +152,7 @@ async function getFileLinkCore(getToken, odspUrlParts, logger) {
|
|
|
146
152
|
const directUrl = sharingInfo?.d?.directUrl;
|
|
147
153
|
if (typeof directUrl !== "string") {
|
|
148
154
|
// This will retry once in getWithRetryForTokenRefresh
|
|
149
|
-
throw new internal_2.NonRetryableError("Malformed GetSharingInformation response",
|
|
155
|
+
throw new internal_2.NonRetryableError("Malformed GetSharingInformation response", internal_3.OdspErrorTypes.incorrectServerResponse, { driverVersion: packageVersion_js_1.pkgVersion });
|
|
150
156
|
}
|
|
151
157
|
return directUrl;
|
|
152
158
|
});
|
|
@@ -160,7 +166,7 @@ const isFileItemLite = (maybeFileItemLite) => typeof maybeFileItemLite.webUrl ==
|
|
|
160
166
|
// TODO: stronger check
|
|
161
167
|
typeof maybeFileItemLite.sharepointIds === "object";
|
|
162
168
|
async function getFileItemLite(getToken, odspUrlParts, logger, forceAccessTokenViaAuthorizationHeader) {
|
|
163
|
-
return
|
|
169
|
+
return internal_4.PerformanceEvent.timedExecAsync(logger, { eventName: "odspFileLink", requestName: "getFileItemLite" }, async (event) => {
|
|
164
170
|
let attempts = 0;
|
|
165
171
|
let additionalProps;
|
|
166
172
|
const fileItem = await (0, odspUtils_js_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
@@ -172,14 +178,13 @@ async function getFileItemLite(getToken, odspUrlParts, logger, forceAccessTokenV
|
|
|
172
178
|
const authHeader = await getAuthHeader({ ...options, request: { url, method } }, "GetFileItemLite");
|
|
173
179
|
(0, internal_1.assert)(authHeader !== null, 0x2bc /* "Instrumented token fetcher with throwOnNullToken =true should never return null" */);
|
|
174
180
|
const headers = (0, getUrlAndHeadersWithAuth_js_1.getHeadersWithAuth)(authHeader);
|
|
175
|
-
headers.redirect = "manual";
|
|
176
181
|
const requestInit = { method, headers };
|
|
177
182
|
const response = await (0, odspUtils_js_1.fetchHelper)(url, requestInit);
|
|
178
183
|
additionalProps = response.propsToLog;
|
|
179
184
|
const responseJson = await response.content.json();
|
|
180
185
|
if (!isFileItemLite(responseJson)) {
|
|
181
186
|
// This will retry once in getWithRetryForTokenRefresh
|
|
182
|
-
throw new internal_2.NonRetryableError("Malformed getFileItemLite response",
|
|
187
|
+
throw new internal_2.NonRetryableError("Malformed getFileItemLite response", internal_3.OdspErrorTypes.incorrectServerResponse, { driverVersion: packageVersion_js_1.pkgVersion });
|
|
183
188
|
}
|
|
184
189
|
return responseJson;
|
|
185
190
|
});
|
|
@@ -187,4 +192,25 @@ async function getFileItemLite(getToken, odspUrlParts, logger, forceAccessTokenV
|
|
|
187
192
|
return fileItem;
|
|
188
193
|
});
|
|
189
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* It takes a resolved url with old siteUrl and patches resolved url with updated site url domain.
|
|
197
|
+
* @param odspResolvedUrl - Previous odsp resolved url with older site url.
|
|
198
|
+
* @param newSiteDomain - New site domain after the tenant rename.
|
|
199
|
+
*/
|
|
200
|
+
function renameTenantInOdspResolvedUrl(odspResolvedUrl, newSiteDomain) {
|
|
201
|
+
const newSiteUrl = `${newSiteDomain}${new URL(odspResolvedUrl.siteUrl).pathname}`;
|
|
202
|
+
odspResolvedUrl.siteUrl = newSiteUrl;
|
|
203
|
+
if (odspResolvedUrl.endpoints.attachmentGETStorageUrl) {
|
|
204
|
+
odspResolvedUrl.endpoints.attachmentGETStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentGETStorageUrl).pathname}`;
|
|
205
|
+
}
|
|
206
|
+
if (odspResolvedUrl.endpoints.attachmentPOSTStorageUrl) {
|
|
207
|
+
odspResolvedUrl.endpoints.attachmentPOSTStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentPOSTStorageUrl).pathname}`;
|
|
208
|
+
}
|
|
209
|
+
if (odspResolvedUrl.endpoints.deltaStorageUrl) {
|
|
210
|
+
odspResolvedUrl.endpoints.deltaStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.deltaStorageUrl).pathname}`;
|
|
211
|
+
}
|
|
212
|
+
if (odspResolvedUrl.endpoints.snapshotStorageUrl) {
|
|
213
|
+
odspResolvedUrl.endpoints.snapshotStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.snapshotStorageUrl).pathname}`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
190
216
|
//# sourceMappingURL=getFileLink.js.map
|
package/dist/getFileLink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileLink.js","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAC7D,oEAAwF;AACxF,yEAAoF;AACpF,+EAK0D;AAC1D,uEAIkD;AAElD,+EAAmE;AACnE,iDAIwB;AACxB,2DAAkE;AAClE,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ACpC,yBAAc,CAAC,uBAAuB,EACtC,EAAE,aAAa,EAAb,8BAAa,EAAE,CACjB,CAAC;YACH,CAAC;YACD,OAAO,YAAY,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5C,OAAO,QAAQ,CAAC;IACjB,CAAC,CACD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { NonRetryableError, runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport { hasRedirectionLocation } from \"@fluidframework/odsp-doclib-utils/internal\";\nimport {\n\tIOdspUrlParts,\n\tOdspErrorTypes,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\tisFluidError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { getHeadersWithAuth } from \"./getUrlAndHeadersWithAuth.js\";\nimport {\n\tfetchHelper,\n\tgetWithRetryForTokenRefresh,\n\ttoInstrumentedOdspStorageTokenFetcher,\n} from \"./odspUtils.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { runWithRetry as runWithRetryForCoherencyAndServiceReadOnlyErrors } from \"./retryUtils.js\";\n\n// Store cached responses for the lifetime of web session as file link remains the same for given file item\nconst fileLinkCache = new Map<string, Promise<string>>();\n\n/**\n * Returns file link for a file with given drive and item ids.\n * Scope needed: files.readwrite.all.\n * This function keeps retrying if it gets a retriable error or wait for some delay if it gets a\n * throttling error. In future, we are thinking of app allowing to pass some cancel token, with which\n * we would be able to stop retrying.\n * @param getToken - used to fetch access tokens needed to execute operation\n * @param odspUrlParts - object describing file storage identity\n * @param logger - used to log results of operation, including any error\n * @returns Promise which resolves to file link url when successful; otherwise, undefined.\n */\nexport async function getFileLink(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\tconst cacheKey = `${odspUrlParts.siteUrl}_${odspUrlParts.driveId}_${odspUrlParts.itemId}`;\n\tconst maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);\n\tif (maybeFileLinkCacheEntry !== undefined) {\n\t\treturn maybeFileLinkCacheEntry;\n\t}\n\n\tconst fileLinkGenerator = async function (): Promise<string> {\n\t\tlet fileLinkCore: string;\n\t\ttry {\n\t\t\tlet retryCount = 0;\n\t\t\tfileLinkCore = await runWithRetry(\n\t\t\t\tasync () =>\n\t\t\t\t\trunWithRetryForCoherencyAndServiceReadOnlyErrors(\n\t\t\t\t\t\tasync () =>\n\t\t\t\t\t\t\tgetFileLinkWithLocationRedirectionHandling(getToken, odspUrlParts, logger),\n\t\t\t\t\t\t\"getFileLinkCore\",\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t),\n\t\t\t\t\"getShareLink\",\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\t// TODO: use a stronger type\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\t\tonRetry(delayInMs: number, error: any) {\n\t\t\t\t\t\tretryCount++;\n\t\t\t\t\t\tif (retryCount === 5) {\n\t\t\t\t\t\t\tif (error !== undefined && typeof error === \"object\") {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\terror.canRetry = false;\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\t// Delete from the cache to permit retrying later.\n\t\t\tfileLinkCache.delete(cacheKey);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// We are guaranteed to run the getFileLinkCore at least once with successful result (which must be a string)\n\t\tassert(\n\t\t\tfileLinkCore !== undefined,\n\t\t\t0x292 /* \"Unexpected undefined result from getFileLinkCore\" */,\n\t\t);\n\t\treturn fileLinkCore;\n\t};\n\tconst fileLink = fileLinkGenerator();\n\tfileLinkCache.set(cacheKey, fileLink);\n\treturn fileLink;\n}\n\n/**\n * Handles location redirection while fulfilling the getFilelink call. We don't want browser to handle\n * the redirection as the browser will retry with same auth token which will not work as we need app\n * to regenerate tokens for the new site domain. So when we will make the network calls below we will set\n * the redirect:manual header to manually handle these redirects.\n * Refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308\n * @param getToken - token fetcher to fetch the token.\n * @param odspUrlParts - parts of odsp resolved url.\n * @param logger - logger to send events.\n * @returns Response from the API call.\n * @legacy\n * @alpha\n */\nasync function getFileLinkWithLocationRedirectionHandling(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\t// We can have chains of location redirection one after the other, so have a for loop\n\t// so that we can keep handling the same type of error. Set max number of redirection to 5.\n\tlet lastError: unknown;\n\tfor (let count = 1; count <= 5; count++) {\n\t\ttry {\n\t\t\treturn await getFileLinkCore(getToken, odspUrlParts, logger);\n\t\t} catch (error: unknown) {\n\t\t\tlastError = error;\n\t\t\tif (\n\t\t\t\tisFluidError(error) &&\n\t\t\t\terror.errorType === OdspErrorTypes.fileNotFoundOrAccessDeniedError &&\n\t\t\t\thasRedirectionLocation(error) &&\n\t\t\t\terror.redirectLocation !== undefined\n\t\t\t) {\n\t\t\t\tconst redirectLocation = error.redirectLocation;\n\t\t\t\tlogger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"LocationRedirectionErrorForGetOdspFileLink\",\n\t\t\t\t\tretryCount: count,\n\t\t\t\t});\n\t\t\t\t// Generate the new SiteUrl from the redirection location.\n\t\t\t\tconst newSiteDomain = new URL(redirectLocation).origin;\n\t\t\t\tconst newSiteUrl = `${newSiteDomain}${new URL(odspUrlParts.siteUrl).pathname}`;\n\t\t\t\todspUrlParts.siteUrl = newSiteUrl;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\tthrow lastError;\n}\n\nasync function getFileLinkCore(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\tconst fileItem = await getFileItemLite(getToken, odspUrlParts, logger, true);\n\n\t// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getSharingInformation\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps;\n\t\t\tconst fileLink = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\n\t\t\t\t// IMPORTANT: In past we were using GetFileByUrl() API to get to the list item that was corresponding\n\t\t\t\t// to the file. This was intentionally replaced with GetFileById() to solve the following issue:\n\t\t\t\t// GetFileByUrl() uses webDavUrl to locate list item. This API does not work for Consumer scenarios\n\t\t\t\t// where webDavUrl is constructed using legacy ODC format for backward compatibility reasons.\n\t\t\t\t// GetFileByUrl() does not understand that format and thus fails. GetFileById() relies on file item\n\t\t\t\t// unique guid (sharepointIds.listItemUniqueId) and it works uniformly across Consumer and Commercial.\n\t\t\t\tconst url = `${\n\t\t\t\t\todspUrlParts.siteUrl\n\t\t\t\t}/_api/web/GetFileById(@a1)/ListItemAllFields/GetSharingInformation?@a1=guid${encodeURIComponent(\n\t\t\t\t\t`'${fileItem.sharepointIds.listItemUniqueId}'`,\n\t\t\t\t)}`;\n\t\t\t\tconst method = \"POST\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileLinkCore\",\n\t\t\t\t);\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\tconst requestInit = {\n\t\t\t\t\tmethod,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t\"Accept\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t\"redirect\": \"manual\",\n\t\t\t\t\t\t...headers,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst sharingInfo = await response.content.json();\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tconst directUrl = sharingInfo?.d?.directUrl;\n\t\t\t\tif (typeof directUrl !== \"string\") {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed GetSharingInformation response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn directUrl;\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileLink;\n\t\t},\n\t);\n}\n\n/**\n * Sharepoint Ids Interface\n */\ninterface IGraphSharepointIds {\n\tlistId: string;\n\tlistItemId: string;\n\tlistItemUniqueId: string;\n\tsiteId: string;\n\tsiteUrl: string;\n\twebId: string;\n}\n\n/**\n * This represents a lite version of file item containing only select file properties\n */\ninterface FileItemLite {\n\twebUrl: string;\n\twebDavUrl: string;\n\tsharepointIds: IGraphSharepointIds;\n}\n\nconst isFileItemLite = (maybeFileItemLite: unknown): maybeFileItemLite is FileItemLite =>\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webUrl === \"string\" &&\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webDavUrl === \"string\" &&\n\t// TODO: stronger check\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).sharepointIds === \"object\";\n\nasync function getFileItemLite(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<FileItemLite> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getFileItemLite\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps: ITelemetryBaseProperties | undefined;\n\t\t\tconst fileItem = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst { siteUrl, driveId, itemId } = odspUrlParts;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\t\t\t\tconst url = `${siteUrl}/_api/v2.0/drives/${driveId}/items/${itemId}?select=webUrl,webDavUrl,sharepointIds`;\n\t\t\t\tconst method = \"GET\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileItemLite\",\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tauthHeader !== null,\n\t\t\t\t\t0x2bc /* \"Instrumented token fetcher with throwOnNullToken =true should never return null\" */,\n\t\t\t\t);\n\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\theaders.redirect = \"manual\";\n\t\t\t\tconst requestInit = { method, headers };\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\tconst responseJson: unknown = await response.content.json();\n\t\t\t\tif (!isFileItemLite(responseJson)) {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed getFileItemLite response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn responseJson;\n\t\t\t});\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileItem;\n\t\t},\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getFileLink.js","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAC7D,oEAAwF;AACxF,+EAM0D;AAC1D,uEAIkD;AAElD,+EAAmE;AACnE,iDAIwB;AACxB,2DAAkE;AAClE,mDAAmG;AAEnG,2GAA2G;AAC3G,MAAM,aAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEzD;;;;;;;;;;GAUG;AACI,KAAK,UAAU,WAAW,CAChC,QAAqD,EACrD,WAA6B,EAC7B,MAA2B;IAE3B,MAAM,QAAQ,GAAG,GAAG,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IACvF,MAAM,uBAAuB,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,uBAAuB,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,uBAAuB,CAAC;IAChC,CAAC;IAED,MAAM,iBAAiB,GAAG,KAAK;QAC9B,IAAI,YAAoB,CAAC;QACzB,IAAI,CAAC;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CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;IAClF,eAAe,CAAC,OAAO,GAAG,UAAU,CAAC;IAErC,IAAI,eAAe,CAAC,SAAS,CAAC,uBAAuB,EAAE,CAAC;QACvD,eAAe,CAAC,SAAS,CAAC,uBAAuB,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9I,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,CAAC,wBAAwB,EAAE,CAAC;QACxD,eAAe,CAAC,SAAS,CAAC,wBAAwB,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChJ,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC;QAC/C,eAAe,CAAC,SAAS,CAAC,eAAe,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9H,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC;QAClD,eAAe,CAAC,SAAS,CAAC,kBAAkB,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE,CAAC;IACpI,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { NonRetryableError, runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIOdspUrlParts,\n\tOdspErrorTypes,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n\ttype IOdspResolvedUrl,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\tisFluidError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { getHeadersWithAuth } from \"./getUrlAndHeadersWithAuth.js\";\nimport {\n\tfetchHelper,\n\tgetWithRetryForTokenRefresh,\n\ttoInstrumentedOdspStorageTokenFetcher,\n} from \"./odspUtils.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { runWithRetry as runWithRetryForCoherencyAndServiceReadOnlyErrors } from \"./retryUtils.js\";\n\n// Store cached responses for the lifetime of web session as file link remains the same for given file item\nconst fileLinkCache = new Map<string, Promise<string>>();\n\n/**\n * Returns file link for a file with given drive and item ids.\n * Scope needed: files.readwrite.all.\n * This function keeps retrying if it gets a retriable error or wait for some delay if it gets a\n * throttling error. In future, we are thinking of app allowing to pass some cancel token, with which\n * we would be able to stop retrying.\n * @param getToken - used to fetch access tokens needed to execute operation\n * @param odspUrlParts - object describing file storage identity\n * @param logger - used to log results of operation, including any error\n * @returns Promise which resolves to file link url when successful; otherwise, undefined.\n */\nexport async function getFileLink(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tresolvedUrl: IOdspResolvedUrl,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\tconst cacheKey = `${resolvedUrl.siteUrl}_${resolvedUrl.driveId}_${resolvedUrl.itemId}`;\n\tconst maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);\n\tif (maybeFileLinkCacheEntry !== undefined) {\n\t\treturn maybeFileLinkCacheEntry;\n\t}\n\n\tconst fileLinkGenerator = async function (): Promise<string> {\n\t\tlet fileLinkCore: string;\n\t\ttry {\n\t\t\tlet retryCount = 0;\n\t\t\tfileLinkCore = await runWithRetry(\n\t\t\t\tasync () =>\n\t\t\t\t\trunWithRetryForCoherencyAndServiceReadOnlyErrors(\n\t\t\t\t\t\tasync () =>\n\t\t\t\t\t\t\tgetFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger),\n\t\t\t\t\t\t\"getFileLinkCore\",\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t),\n\t\t\t\t\"getShareLink\",\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\t// TODO: use a stronger type\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\t\tonRetry(delayInMs: number, error: any) {\n\t\t\t\t\t\tretryCount++;\n\t\t\t\t\t\tif (retryCount === 5) {\n\t\t\t\t\t\t\tif (error !== undefined && typeof error === \"object\") {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\terror.canRetry = false;\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\t// Delete from the cache to permit retrying later.\n\t\t\tfileLinkCache.delete(cacheKey);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// We are guaranteed to run the getFileLinkCore at least once with successful result (which must be a string)\n\t\tassert(\n\t\t\tfileLinkCore !== undefined,\n\t\t\t0x292 /* \"Unexpected undefined result from getFileLinkCore\" */,\n\t\t);\n\t\treturn fileLinkCore;\n\t};\n\tconst fileLink = fileLinkGenerator();\n\tfileLinkCache.set(cacheKey, fileLink);\n\treturn fileLink;\n}\n\n/**\n * Handles location redirection while fulfilling the getFilelink call. We don't want browser to handle\n * the redirection as the browser will retry with same auth token which will not work as we need app\n * to regenerate tokens for the new site domain. So when we will make the network calls below we will set\n * the redirect:manual header to manually handle these redirects.\n * Refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308\n * @param getToken - token fetcher to fetch the token.\n * @param odspUrlParts - parts of odsp resolved url.\n * @param logger - logger to send events.\n * @returns Response from the API call.\n * @legacy\n * @alpha\n */\nasync function getFileLinkWithLocationRedirectionHandling(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tresolvedUrl: IOdspResolvedUrl,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\t// We can have chains of location redirection one after the other, so have a for loop\n\t// so that we can keep handling the same type of error. Set max number of redirection to 5.\n\tlet lastError: unknown;\n\tlet locationRedirected = false;\n\tfor (let count = 1; count <= 5; count++) {\n\t\ttry {\n\t\t\tconst fileItem = await getFileItemLite(getToken, resolvedUrl, logger, true);\n\t\t\t// Sometimes the siteUrl in the actual file is different from the siteUrl in the resolvedUrl due to location\n\t\t\t// redirection. This creates issues in the getSharingInformation call. So we need to update the siteUrl in the\n\t\t\t// resolvedUrl to the siteUrl in the fileItem which is the updated siteUrl.\n\t\t\tconst oldSiteDomain = new URL(resolvedUrl.siteUrl).origin;\n\t\t\tconst newSiteDomain = new URL(fileItem.sharepointIds.siteUrl).origin;\n\t\t\tif (oldSiteDomain !== newSiteDomain) {\n\t\t\t\tlocationRedirected = true;\n\t\t\t\tlogger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"LocationRedirectionErrorForGetOdspFileLink\",\n\t\t\t\t\tretryCount: count,\n\t\t\t\t});\n\t\t\t\trenameTenantInOdspResolvedUrl(resolvedUrl, newSiteDomain);\n\t\t\t}\n\t\t\treturn await getFileLinkCore(getToken, resolvedUrl, logger, fileItem);\n\t\t} catch (error: unknown) {\n\t\t\tlastError = error;\n\t\t\t// If the getSharingLink call fails with the 401/403/404 error, then it could be due to that the file has moved\n\t\t\t// to another location. This could occur in case we have more than 1 tenant rename. In that case, we should retry\n\t\t\t// the getFileItemLite call to get the updated fileItem.\n\t\t\tif (\n\t\t\t\tisFluidError(error) &&\n\t\t\t\tlocationRedirected &&\n\t\t\t\t(error.errorType === OdspErrorTypes.fileNotFoundOrAccessDeniedError ||\n\t\t\t\t\terror.errorType === OdspErrorTypes.authorizationError)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\tthrow lastError;\n}\n\nasync function getFileLinkCore(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n\tfileItem: FileItemLite,\n): Promise<string> {\n\t// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getSharingInformation\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps;\n\t\t\tconst fileLink = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\n\t\t\t\t// IMPORTANT: In past we were using GetFileByUrl() API to get to the list item that was corresponding\n\t\t\t\t// to the file. This was intentionally replaced with GetFileById() to solve the following issue:\n\t\t\t\t// GetFileByUrl() uses webDavUrl to locate list item. This API does not work for Consumer scenarios\n\t\t\t\t// where webDavUrl is constructed using legacy ODC format for backward compatibility reasons.\n\t\t\t\t// GetFileByUrl() does not understand that format and thus fails. GetFileById() relies on file item\n\t\t\t\t// unique guid (sharepointIds.listItemUniqueId) and it works uniformly across Consumer and Commercial.\n\t\t\t\tconst url = `${\n\t\t\t\t\todspUrlParts.siteUrl\n\t\t\t\t}/_api/web/GetFileById(@a1)/ListItemAllFields/GetSharingInformation?@a1=guid${encodeURIComponent(\n\t\t\t\t\t`'${fileItem.sharepointIds.listItemUniqueId}'`,\n\t\t\t\t)}`;\n\t\t\t\tconst method = \"POST\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileLinkCore\",\n\t\t\t\t);\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\tconst requestInit = {\n\t\t\t\t\tmethod,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t\"Accept\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t...headers,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst sharingInfo = await response.content.json();\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tconst directUrl = sharingInfo?.d?.directUrl;\n\t\t\t\tif (typeof directUrl !== \"string\") {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed GetSharingInformation response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn directUrl;\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileLink;\n\t\t},\n\t);\n}\n\n/**\n * Sharepoint Ids Interface\n */\ninterface IGraphSharepointIds {\n\tlistId: string;\n\tlistItemId: string;\n\tlistItemUniqueId: string;\n\tsiteId: string;\n\tsiteUrl: string;\n\twebId: string;\n}\n\n/**\n * This represents a lite version of file item containing only select file properties\n */\ninterface FileItemLite {\n\twebUrl: string;\n\twebDavUrl: string;\n\tsharepointIds: IGraphSharepointIds;\n}\n\nconst isFileItemLite = (maybeFileItemLite: unknown): maybeFileItemLite is FileItemLite =>\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webUrl === \"string\" &&\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webDavUrl === \"string\" &&\n\t// TODO: stronger check\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).sharepointIds === \"object\";\n\nasync function getFileItemLite(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<FileItemLite> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getFileItemLite\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps: ITelemetryBaseProperties | undefined;\n\t\t\tconst fileItem = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst { siteUrl, driveId, itemId } = odspUrlParts;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\t\t\t\tconst url = `${siteUrl}/_api/v2.0/drives/${driveId}/items/${itemId}?select=webUrl,webDavUrl,sharepointIds`;\n\t\t\t\tconst method = \"GET\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileItemLite\",\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tauthHeader !== null,\n\t\t\t\t\t0x2bc /* \"Instrumented token fetcher with throwOnNullToken =true should never return null\" */,\n\t\t\t\t);\n\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\tconst requestInit = { method, headers };\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\tconst responseJson: unknown = await response.content.json();\n\t\t\t\tif (!isFileItemLite(responseJson)) {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed getFileItemLite response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn responseJson;\n\t\t\t});\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileItem;\n\t\t},\n\t);\n}\n\n/**\n * It takes a resolved url with old siteUrl and patches resolved url with updated site url domain.\n * @param odspResolvedUrl - Previous odsp resolved url with older site url.\n * @param newSiteDomain - New site domain after the tenant rename.\n */\nfunction renameTenantInOdspResolvedUrl(\n\todspResolvedUrl: IOdspResolvedUrl,\n\tnewSiteDomain: string,\n): void {\n\tconst newSiteUrl = `${newSiteDomain}${new URL(odspResolvedUrl.siteUrl).pathname}`;\n\todspResolvedUrl.siteUrl = newSiteUrl;\n\n\tif (odspResolvedUrl.endpoints.attachmentGETStorageUrl) {\n\t\todspResolvedUrl.endpoints.attachmentGETStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentGETStorageUrl).pathname}`;\n\t}\n\tif (odspResolvedUrl.endpoints.attachmentPOSTStorageUrl) {\n\t\todspResolvedUrl.endpoints.attachmentPOSTStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentPOSTStorageUrl).pathname}`;\n\t}\n\tif (odspResolvedUrl.endpoints.deltaStorageUrl) {\n\t\todspResolvedUrl.endpoints.deltaStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.deltaStorageUrl).pathname}`;\n\t}\n\tif (odspResolvedUrl.endpoints.snapshotStorageUrl) {\n\t\todspResolvedUrl.endpoints.snapshotStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.snapshotStorageUrl).pathname}`;\n\t}\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/odsp-driver";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.4.0-294316";
|
|
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,
|
|
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"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/odsp-driver";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.4.0-294316";
|
|
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,
|
|
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 = \"2.4.0-294316\";\n"]}
|
package/lib/getFileLink.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { OdspResourceTokenFetchOptions, TokenFetcher, type IOdspResolvedUrl } from "@fluidframework/odsp-driver-definitions/internal";
|
|
6
6
|
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
7
7
|
/**
|
|
8
8
|
* Returns file link for a file with given drive and item ids.
|
|
@@ -15,5 +15,5 @@ import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
|
15
15
|
* @param logger - used to log results of operation, including any error
|
|
16
16
|
* @returns Promise which resolves to file link url when successful; otherwise, undefined.
|
|
17
17
|
*/
|
|
18
|
-
export declare function getFileLink(getToken: TokenFetcher<OdspResourceTokenFetchOptions>,
|
|
18
|
+
export declare function getFileLink(getToken: TokenFetcher<OdspResourceTokenFetchOptions>, resolvedUrl: IOdspResolvedUrl, logger: ITelemetryLoggerExt): Promise<string>;
|
|
19
19
|
//# sourceMappingURL=getFileLink.d.ts.map
|
package/lib/getFileLink.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileLink.d.ts","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"getFileLink.d.ts","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAGN,6BAA6B,EAC7B,YAAY,EACZ,KAAK,gBAAgB,EACrB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACN,mBAAmB,EAGnB,MAAM,0CAA0C,CAAC;AAclD;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAChC,QAAQ,EAAE,YAAY,CAAC,6BAA6B,CAAC,EACrD,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,mBAAmB,GACzB,OAAO,CAAC,MAAM,CAAC,CAqDjB"}
|
package/lib/getFileLink.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { NonRetryableError, runWithRetry } from "@fluidframework/driver-utils/internal";
|
|
7
|
-
import { hasRedirectionLocation } from "@fluidframework/odsp-doclib-utils/internal";
|
|
8
7
|
import { OdspErrorTypes, } from "@fluidframework/odsp-driver-definitions/internal";
|
|
9
8
|
import { PerformanceEvent, isFluidError, } from "@fluidframework/telemetry-utils/internal";
|
|
10
9
|
import { getHeadersWithAuth } from "./getUrlAndHeadersWithAuth.js";
|
|
@@ -24,8 +23,8 @@ const fileLinkCache = new Map();
|
|
|
24
23
|
* @param logger - used to log results of operation, including any error
|
|
25
24
|
* @returns Promise which resolves to file link url when successful; otherwise, undefined.
|
|
26
25
|
*/
|
|
27
|
-
export async function getFileLink(getToken,
|
|
28
|
-
const cacheKey = `${
|
|
26
|
+
export async function getFileLink(getToken, resolvedUrl, logger) {
|
|
27
|
+
const cacheKey = `${resolvedUrl.siteUrl}_${resolvedUrl.driveId}_${resolvedUrl.itemId}`;
|
|
29
28
|
const maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);
|
|
30
29
|
if (maybeFileLinkCacheEntry !== undefined) {
|
|
31
30
|
return maybeFileLinkCacheEntry;
|
|
@@ -34,7 +33,7 @@ export async function getFileLink(getToken, odspUrlParts, logger) {
|
|
|
34
33
|
let fileLinkCore;
|
|
35
34
|
try {
|
|
36
35
|
let retryCount = 0;
|
|
37
|
-
fileLinkCore = await runWithRetry(async () => runWithRetryForCoherencyAndServiceReadOnlyErrors(async () => getFileLinkWithLocationRedirectionHandling(getToken,
|
|
36
|
+
fileLinkCore = await runWithRetry(async () => runWithRetryForCoherencyAndServiceReadOnlyErrors(async () => getFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger), "getFileLinkCore", logger), "getShareLink", logger, {
|
|
38
37
|
// TODO: use a stronger type
|
|
39
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
39
|
onRetry(delayInMs, error) {
|
|
@@ -76,29 +75,38 @@ export async function getFileLink(getToken, odspUrlParts, logger) {
|
|
|
76
75
|
* @legacy
|
|
77
76
|
* @alpha
|
|
78
77
|
*/
|
|
79
|
-
async function getFileLinkWithLocationRedirectionHandling(getToken,
|
|
78
|
+
async function getFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger) {
|
|
80
79
|
// We can have chains of location redirection one after the other, so have a for loop
|
|
81
80
|
// so that we can keep handling the same type of error. Set max number of redirection to 5.
|
|
82
81
|
let lastError;
|
|
82
|
+
let locationRedirected = false;
|
|
83
83
|
for (let count = 1; count <= 5; count++) {
|
|
84
84
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const redirectLocation = error.redirectLocation;
|
|
85
|
+
const fileItem = await getFileItemLite(getToken, resolvedUrl, logger, true);
|
|
86
|
+
// Sometimes the siteUrl in the actual file is different from the siteUrl in the resolvedUrl due to location
|
|
87
|
+
// redirection. This creates issues in the getSharingInformation call. So we need to update the siteUrl in the
|
|
88
|
+
// resolvedUrl to the siteUrl in the fileItem which is the updated siteUrl.
|
|
89
|
+
const oldSiteDomain = new URL(resolvedUrl.siteUrl).origin;
|
|
90
|
+
const newSiteDomain = new URL(fileItem.sharepointIds.siteUrl).origin;
|
|
91
|
+
if (oldSiteDomain !== newSiteDomain) {
|
|
92
|
+
locationRedirected = true;
|
|
94
93
|
logger.sendTelemetryEvent({
|
|
95
94
|
eventName: "LocationRedirectionErrorForGetOdspFileLink",
|
|
96
95
|
retryCount: count,
|
|
97
96
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
renameTenantInOdspResolvedUrl(resolvedUrl, newSiteDomain);
|
|
98
|
+
}
|
|
99
|
+
return await getFileLinkCore(getToken, resolvedUrl, logger, fileItem);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
lastError = error;
|
|
103
|
+
// If the getSharingLink call fails with the 401/403/404 error, then it could be due to that the file has moved
|
|
104
|
+
// to another location. This could occur in case we have more than 1 tenant rename. In that case, we should retry
|
|
105
|
+
// the getFileItemLite call to get the updated fileItem.
|
|
106
|
+
if (isFluidError(error) &&
|
|
107
|
+
locationRedirected &&
|
|
108
|
+
(error.errorType === OdspErrorTypes.fileNotFoundOrAccessDeniedError ||
|
|
109
|
+
error.errorType === OdspErrorTypes.authorizationError)) {
|
|
102
110
|
continue;
|
|
103
111
|
}
|
|
104
112
|
throw error;
|
|
@@ -106,8 +114,7 @@ async function getFileLinkWithLocationRedirectionHandling(getToken, odspUrlParts
|
|
|
106
114
|
}
|
|
107
115
|
throw lastError;
|
|
108
116
|
}
|
|
109
|
-
async function getFileLinkCore(getToken, odspUrlParts, logger) {
|
|
110
|
-
const fileItem = await getFileItemLite(getToken, odspUrlParts, logger, true);
|
|
117
|
+
async function getFileLinkCore(getToken, odspUrlParts, logger, fileItem) {
|
|
111
118
|
// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder
|
|
112
119
|
return PerformanceEvent.timedExecAsync(logger, { eventName: "odspFileLink", requestName: "getSharingInformation" }, async (event) => {
|
|
113
120
|
let attempts = 0;
|
|
@@ -130,7 +137,6 @@ async function getFileLinkCore(getToken, odspUrlParts, logger) {
|
|
|
130
137
|
headers: {
|
|
131
138
|
"Content-Type": "application/json;odata=verbose",
|
|
132
139
|
"Accept": "application/json;odata=verbose",
|
|
133
|
-
"redirect": "manual",
|
|
134
140
|
...headers,
|
|
135
141
|
},
|
|
136
142
|
};
|
|
@@ -168,7 +174,6 @@ async function getFileItemLite(getToken, odspUrlParts, logger, forceAccessTokenV
|
|
|
168
174
|
const authHeader = await getAuthHeader({ ...options, request: { url, method } }, "GetFileItemLite");
|
|
169
175
|
assert(authHeader !== null, 0x2bc /* "Instrumented token fetcher with throwOnNullToken =true should never return null" */);
|
|
170
176
|
const headers = getHeadersWithAuth(authHeader);
|
|
171
|
-
headers.redirect = "manual";
|
|
172
177
|
const requestInit = { method, headers };
|
|
173
178
|
const response = await fetchHelper(url, requestInit);
|
|
174
179
|
additionalProps = response.propsToLog;
|
|
@@ -183,4 +188,25 @@ async function getFileItemLite(getToken, odspUrlParts, logger, forceAccessTokenV
|
|
|
183
188
|
return fileItem;
|
|
184
189
|
});
|
|
185
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* It takes a resolved url with old siteUrl and patches resolved url with updated site url domain.
|
|
193
|
+
* @param odspResolvedUrl - Previous odsp resolved url with older site url.
|
|
194
|
+
* @param newSiteDomain - New site domain after the tenant rename.
|
|
195
|
+
*/
|
|
196
|
+
function renameTenantInOdspResolvedUrl(odspResolvedUrl, newSiteDomain) {
|
|
197
|
+
const newSiteUrl = `${newSiteDomain}${new URL(odspResolvedUrl.siteUrl).pathname}`;
|
|
198
|
+
odspResolvedUrl.siteUrl = newSiteUrl;
|
|
199
|
+
if (odspResolvedUrl.endpoints.attachmentGETStorageUrl) {
|
|
200
|
+
odspResolvedUrl.endpoints.attachmentGETStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentGETStorageUrl).pathname}`;
|
|
201
|
+
}
|
|
202
|
+
if (odspResolvedUrl.endpoints.attachmentPOSTStorageUrl) {
|
|
203
|
+
odspResolvedUrl.endpoints.attachmentPOSTStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentPOSTStorageUrl).pathname}`;
|
|
204
|
+
}
|
|
205
|
+
if (odspResolvedUrl.endpoints.deltaStorageUrl) {
|
|
206
|
+
odspResolvedUrl.endpoints.deltaStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.deltaStorageUrl).pathname}`;
|
|
207
|
+
}
|
|
208
|
+
if (odspResolvedUrl.endpoints.snapshotStorageUrl) {
|
|
209
|
+
odspResolvedUrl.endpoints.snapshotStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.snapshotStorageUrl).pathname}`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
186
212
|
//# sourceMappingURL=getFileLink.js.map
|
package/lib/getFileLink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileLink.js","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAEN,cAAc,GAGd,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAEN,gBAAgB,EAChB,YAAY,GACZ,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACN,WAAW,EACX,2BAA2B,EAC3B,qCAAqC,GACrC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,YAAY,IAAI,gDAAgD,EAAE,MAAM,iBAAiB,CAAC;AAEnG,2GAA2G;AAC3G,MAAM,aAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,QAAqD,EACrD,YAA2B,EAC3B,MAA2B;IAE3B,MAAM,QAAQ,GAAG,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,OA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ClD,MAAM,aAAa,GAAG,qCAAqC,CAC1D,MAAM,EACN,YAAY,EACZ,QAAQ,CACR,CAAC;YACF,MAAM,GAAG,GAAG,GAAG,OAAO,qBAAqB,OAAO,UAAU,MAAM,wCAAwC,CAAC;YAC3G,MAAM,MAAM,GAAG,KAAK,CAAC;YACrB,MAAM,UAAU,GAAG,MAAM,aAAa,CACrC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EACxC,iBAAiB,CACjB,CAAC;YACF,MAAM,CACL,UAAU,KAAK,IAAI,EACnB,KAAK,CAAC,uFAAuF,CAC7F,CAAC;YAEF,MAAM,OAAO,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;YAC/C,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAC5B,MAAM,WAAW,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YACxC,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;YACrD,eAAe,GAAG,QAAQ,CAAC,UAAU,CAAC;YAEtC,MAAM,YAAY,GAAY,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAC5D,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC;gBACnC,sDAAsD;gBACtD,MAAM,IAAI,iBAAiB,CAC1B,oCAAoC,EACpC,cAAc,CAAC,uBAAuB,EACtC,EAAE,aAAa,EAAE,CACjB,CAAC;YACH,CAAC;YACD,OAAO,YAAY,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5C,OAAO,QAAQ,CAAC;IACjB,CAAC,CACD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { NonRetryableError, runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport { hasRedirectionLocation } from \"@fluidframework/odsp-doclib-utils/internal\";\nimport {\n\tIOdspUrlParts,\n\tOdspErrorTypes,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\tisFluidError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { getHeadersWithAuth } from \"./getUrlAndHeadersWithAuth.js\";\nimport {\n\tfetchHelper,\n\tgetWithRetryForTokenRefresh,\n\ttoInstrumentedOdspStorageTokenFetcher,\n} from \"./odspUtils.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { runWithRetry as runWithRetryForCoherencyAndServiceReadOnlyErrors } from \"./retryUtils.js\";\n\n// Store cached responses for the lifetime of web session as file link remains the same for given file item\nconst fileLinkCache = new Map<string, Promise<string>>();\n\n/**\n * Returns file link for a file with given drive and item ids.\n * Scope needed: files.readwrite.all.\n * This function keeps retrying if it gets a retriable error or wait for some delay if it gets a\n * throttling error. In future, we are thinking of app allowing to pass some cancel token, with which\n * we would be able to stop retrying.\n * @param getToken - used to fetch access tokens needed to execute operation\n * @param odspUrlParts - object describing file storage identity\n * @param logger - used to log results of operation, including any error\n * @returns Promise which resolves to file link url when successful; otherwise, undefined.\n */\nexport async function getFileLink(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\tconst cacheKey = `${odspUrlParts.siteUrl}_${odspUrlParts.driveId}_${odspUrlParts.itemId}`;\n\tconst maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);\n\tif (maybeFileLinkCacheEntry !== undefined) {\n\t\treturn maybeFileLinkCacheEntry;\n\t}\n\n\tconst fileLinkGenerator = async function (): Promise<string> {\n\t\tlet fileLinkCore: string;\n\t\ttry {\n\t\t\tlet retryCount = 0;\n\t\t\tfileLinkCore = await runWithRetry(\n\t\t\t\tasync () =>\n\t\t\t\t\trunWithRetryForCoherencyAndServiceReadOnlyErrors(\n\t\t\t\t\t\tasync () =>\n\t\t\t\t\t\t\tgetFileLinkWithLocationRedirectionHandling(getToken, odspUrlParts, logger),\n\t\t\t\t\t\t\"getFileLinkCore\",\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t),\n\t\t\t\t\"getShareLink\",\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\t// TODO: use a stronger type\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\t\tonRetry(delayInMs: number, error: any) {\n\t\t\t\t\t\tretryCount++;\n\t\t\t\t\t\tif (retryCount === 5) {\n\t\t\t\t\t\t\tif (error !== undefined && typeof error === \"object\") {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\terror.canRetry = false;\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\t// Delete from the cache to permit retrying later.\n\t\t\tfileLinkCache.delete(cacheKey);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// We are guaranteed to run the getFileLinkCore at least once with successful result (which must be a string)\n\t\tassert(\n\t\t\tfileLinkCore !== undefined,\n\t\t\t0x292 /* \"Unexpected undefined result from getFileLinkCore\" */,\n\t\t);\n\t\treturn fileLinkCore;\n\t};\n\tconst fileLink = fileLinkGenerator();\n\tfileLinkCache.set(cacheKey, fileLink);\n\treturn fileLink;\n}\n\n/**\n * Handles location redirection while fulfilling the getFilelink call. We don't want browser to handle\n * the redirection as the browser will retry with same auth token which will not work as we need app\n * to regenerate tokens for the new site domain. So when we will make the network calls below we will set\n * the redirect:manual header to manually handle these redirects.\n * Refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308\n * @param getToken - token fetcher to fetch the token.\n * @param odspUrlParts - parts of odsp resolved url.\n * @param logger - logger to send events.\n * @returns Response from the API call.\n * @legacy\n * @alpha\n */\nasync function getFileLinkWithLocationRedirectionHandling(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\t// We can have chains of location redirection one after the other, so have a for loop\n\t// so that we can keep handling the same type of error. Set max number of redirection to 5.\n\tlet lastError: unknown;\n\tfor (let count = 1; count <= 5; count++) {\n\t\ttry {\n\t\t\treturn await getFileLinkCore(getToken, odspUrlParts, logger);\n\t\t} catch (error: unknown) {\n\t\t\tlastError = error;\n\t\t\tif (\n\t\t\t\tisFluidError(error) &&\n\t\t\t\terror.errorType === OdspErrorTypes.fileNotFoundOrAccessDeniedError &&\n\t\t\t\thasRedirectionLocation(error) &&\n\t\t\t\terror.redirectLocation !== undefined\n\t\t\t) {\n\t\t\t\tconst redirectLocation = error.redirectLocation;\n\t\t\t\tlogger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"LocationRedirectionErrorForGetOdspFileLink\",\n\t\t\t\t\tretryCount: count,\n\t\t\t\t});\n\t\t\t\t// Generate the new SiteUrl from the redirection location.\n\t\t\t\tconst newSiteDomain = new URL(redirectLocation).origin;\n\t\t\t\tconst newSiteUrl = `${newSiteDomain}${new URL(odspUrlParts.siteUrl).pathname}`;\n\t\t\t\todspUrlParts.siteUrl = newSiteUrl;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\tthrow lastError;\n}\n\nasync function getFileLinkCore(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\tconst fileItem = await getFileItemLite(getToken, odspUrlParts, logger, true);\n\n\t// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getSharingInformation\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps;\n\t\t\tconst fileLink = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\n\t\t\t\t// IMPORTANT: In past we were using GetFileByUrl() API to get to the list item that was corresponding\n\t\t\t\t// to the file. This was intentionally replaced with GetFileById() to solve the following issue:\n\t\t\t\t// GetFileByUrl() uses webDavUrl to locate list item. This API does not work for Consumer scenarios\n\t\t\t\t// where webDavUrl is constructed using legacy ODC format for backward compatibility reasons.\n\t\t\t\t// GetFileByUrl() does not understand that format and thus fails. GetFileById() relies on file item\n\t\t\t\t// unique guid (sharepointIds.listItemUniqueId) and it works uniformly across Consumer and Commercial.\n\t\t\t\tconst url = `${\n\t\t\t\t\todspUrlParts.siteUrl\n\t\t\t\t}/_api/web/GetFileById(@a1)/ListItemAllFields/GetSharingInformation?@a1=guid${encodeURIComponent(\n\t\t\t\t\t`'${fileItem.sharepointIds.listItemUniqueId}'`,\n\t\t\t\t)}`;\n\t\t\t\tconst method = \"POST\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileLinkCore\",\n\t\t\t\t);\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\tconst requestInit = {\n\t\t\t\t\tmethod,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t\"Accept\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t\"redirect\": \"manual\",\n\t\t\t\t\t\t...headers,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst sharingInfo = await response.content.json();\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tconst directUrl = sharingInfo?.d?.directUrl;\n\t\t\t\tif (typeof directUrl !== \"string\") {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed GetSharingInformation response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn directUrl;\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileLink;\n\t\t},\n\t);\n}\n\n/**\n * Sharepoint Ids Interface\n */\ninterface IGraphSharepointIds {\n\tlistId: string;\n\tlistItemId: string;\n\tlistItemUniqueId: string;\n\tsiteId: string;\n\tsiteUrl: string;\n\twebId: string;\n}\n\n/**\n * This represents a lite version of file item containing only select file properties\n */\ninterface FileItemLite {\n\twebUrl: string;\n\twebDavUrl: string;\n\tsharepointIds: IGraphSharepointIds;\n}\n\nconst isFileItemLite = (maybeFileItemLite: unknown): maybeFileItemLite is FileItemLite =>\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webUrl === \"string\" &&\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webDavUrl === \"string\" &&\n\t// TODO: stronger check\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).sharepointIds === \"object\";\n\nasync function getFileItemLite(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<FileItemLite> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getFileItemLite\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps: ITelemetryBaseProperties | undefined;\n\t\t\tconst fileItem = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst { siteUrl, driveId, itemId } = odspUrlParts;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\t\t\t\tconst url = `${siteUrl}/_api/v2.0/drives/${driveId}/items/${itemId}?select=webUrl,webDavUrl,sharepointIds`;\n\t\t\t\tconst method = \"GET\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileItemLite\",\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tauthHeader !== null,\n\t\t\t\t\t0x2bc /* \"Instrumented token fetcher with throwOnNullToken =true should never return null\" */,\n\t\t\t\t);\n\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\theaders.redirect = \"manual\";\n\t\t\t\tconst requestInit = { method, headers };\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\tconst responseJson: unknown = await response.content.json();\n\t\t\t\tif (!isFileItemLite(responseJson)) {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed getFileItemLite response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn responseJson;\n\t\t\t});\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileItem;\n\t\t},\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getFileLink.js","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAEN,cAAc,GAId,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAEN,gBAAgB,EAChB,YAAY,GACZ,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACN,WAAW,EACX,2BAA2B,EAC3B,qCAAqC,GACrC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,YAAY,IAAI,gDAAgD,EAAE,MAAM,iBAAiB,CAAC;AAEnG,2GAA2G;AAC3G,MAAM,aAAa,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,QAAqD,EACrD,WAA6B,EAC7B,MAA2B;IAE3B,MAAM,QAAQ,GAAG,GAAG,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IACvF,MAAM,uBAAuB,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,uBAAuB,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,uBAAuB,CAAC;IAChC,CAAC;IAED,MAAM,iBAAiB,GAAG,KAAK;QAC9B,IAAI,YAAoB,CAAC;QACzB,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,uBAAuB,EAAE,CAAC;QACvD,eAAe,CAAC,SAAS,CAAC,uBAAuB,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9I,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,CAAC,wBAAwB,EAAE,CAAC;QACxD,eAAe,CAAC,SAAS,CAAC,wBAAwB,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChJ,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC;QAC/C,eAAe,CAAC,SAAS,CAAC,eAAe,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9H,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC;QAClD,eAAe,CAAC,SAAS,CAAC,kBAAkB,GAAG,GAAG,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE,CAAC;IACpI,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { NonRetryableError, runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIOdspUrlParts,\n\tOdspErrorTypes,\n\tOdspResourceTokenFetchOptions,\n\tTokenFetcher,\n\ttype IOdspResolvedUrl,\n} from \"@fluidframework/odsp-driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\tisFluidError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { getHeadersWithAuth } from \"./getUrlAndHeadersWithAuth.js\";\nimport {\n\tfetchHelper,\n\tgetWithRetryForTokenRefresh,\n\ttoInstrumentedOdspStorageTokenFetcher,\n} from \"./odspUtils.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { runWithRetry as runWithRetryForCoherencyAndServiceReadOnlyErrors } from \"./retryUtils.js\";\n\n// Store cached responses for the lifetime of web session as file link remains the same for given file item\nconst fileLinkCache = new Map<string, Promise<string>>();\n\n/**\n * Returns file link for a file with given drive and item ids.\n * Scope needed: files.readwrite.all.\n * This function keeps retrying if it gets a retriable error or wait for some delay if it gets a\n * throttling error. In future, we are thinking of app allowing to pass some cancel token, with which\n * we would be able to stop retrying.\n * @param getToken - used to fetch access tokens needed to execute operation\n * @param odspUrlParts - object describing file storage identity\n * @param logger - used to log results of operation, including any error\n * @returns Promise which resolves to file link url when successful; otherwise, undefined.\n */\nexport async function getFileLink(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tresolvedUrl: IOdspResolvedUrl,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\tconst cacheKey = `${resolvedUrl.siteUrl}_${resolvedUrl.driveId}_${resolvedUrl.itemId}`;\n\tconst maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);\n\tif (maybeFileLinkCacheEntry !== undefined) {\n\t\treturn maybeFileLinkCacheEntry;\n\t}\n\n\tconst fileLinkGenerator = async function (): Promise<string> {\n\t\tlet fileLinkCore: string;\n\t\ttry {\n\t\t\tlet retryCount = 0;\n\t\t\tfileLinkCore = await runWithRetry(\n\t\t\t\tasync () =>\n\t\t\t\t\trunWithRetryForCoherencyAndServiceReadOnlyErrors(\n\t\t\t\t\t\tasync () =>\n\t\t\t\t\t\t\tgetFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger),\n\t\t\t\t\t\t\"getFileLinkCore\",\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t),\n\t\t\t\t\"getShareLink\",\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\t// TODO: use a stronger type\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\t\tonRetry(delayInMs: number, error: any) {\n\t\t\t\t\t\tretryCount++;\n\t\t\t\t\t\tif (retryCount === 5) {\n\t\t\t\t\t\t\tif (error !== undefined && typeof error === \"object\") {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\terror.canRetry = false;\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (error) {\n\t\t\t// Delete from the cache to permit retrying later.\n\t\t\tfileLinkCache.delete(cacheKey);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// We are guaranteed to run the getFileLinkCore at least once with successful result (which must be a string)\n\t\tassert(\n\t\t\tfileLinkCore !== undefined,\n\t\t\t0x292 /* \"Unexpected undefined result from getFileLinkCore\" */,\n\t\t);\n\t\treturn fileLinkCore;\n\t};\n\tconst fileLink = fileLinkGenerator();\n\tfileLinkCache.set(cacheKey, fileLink);\n\treturn fileLink;\n}\n\n/**\n * Handles location redirection while fulfilling the getFilelink call. We don't want browser to handle\n * the redirection as the browser will retry with same auth token which will not work as we need app\n * to regenerate tokens for the new site domain. So when we will make the network calls below we will set\n * the redirect:manual header to manually handle these redirects.\n * Refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308\n * @param getToken - token fetcher to fetch the token.\n * @param odspUrlParts - parts of odsp resolved url.\n * @param logger - logger to send events.\n * @returns Response from the API call.\n * @legacy\n * @alpha\n */\nasync function getFileLinkWithLocationRedirectionHandling(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\tresolvedUrl: IOdspResolvedUrl,\n\tlogger: ITelemetryLoggerExt,\n): Promise<string> {\n\t// We can have chains of location redirection one after the other, so have a for loop\n\t// so that we can keep handling the same type of error. Set max number of redirection to 5.\n\tlet lastError: unknown;\n\tlet locationRedirected = false;\n\tfor (let count = 1; count <= 5; count++) {\n\t\ttry {\n\t\t\tconst fileItem = await getFileItemLite(getToken, resolvedUrl, logger, true);\n\t\t\t// Sometimes the siteUrl in the actual file is different from the siteUrl in the resolvedUrl due to location\n\t\t\t// redirection. This creates issues in the getSharingInformation call. So we need to update the siteUrl in the\n\t\t\t// resolvedUrl to the siteUrl in the fileItem which is the updated siteUrl.\n\t\t\tconst oldSiteDomain = new URL(resolvedUrl.siteUrl).origin;\n\t\t\tconst newSiteDomain = new URL(fileItem.sharepointIds.siteUrl).origin;\n\t\t\tif (oldSiteDomain !== newSiteDomain) {\n\t\t\t\tlocationRedirected = true;\n\t\t\t\tlogger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"LocationRedirectionErrorForGetOdspFileLink\",\n\t\t\t\t\tretryCount: count,\n\t\t\t\t});\n\t\t\t\trenameTenantInOdspResolvedUrl(resolvedUrl, newSiteDomain);\n\t\t\t}\n\t\t\treturn await getFileLinkCore(getToken, resolvedUrl, logger, fileItem);\n\t\t} catch (error: unknown) {\n\t\t\tlastError = error;\n\t\t\t// If the getSharingLink call fails with the 401/403/404 error, then it could be due to that the file has moved\n\t\t\t// to another location. This could occur in case we have more than 1 tenant rename. In that case, we should retry\n\t\t\t// the getFileItemLite call to get the updated fileItem.\n\t\t\tif (\n\t\t\t\tisFluidError(error) &&\n\t\t\t\tlocationRedirected &&\n\t\t\t\t(error.errorType === OdspErrorTypes.fileNotFoundOrAccessDeniedError ||\n\t\t\t\t\terror.errorType === OdspErrorTypes.authorizationError)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\tthrow lastError;\n}\n\nasync function getFileLinkCore(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n\tfileItem: FileItemLite,\n): Promise<string> {\n\t// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getSharingInformation\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps;\n\t\t\tconst fileLink = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\n\t\t\t\t// IMPORTANT: In past we were using GetFileByUrl() API to get to the list item that was corresponding\n\t\t\t\t// to the file. This was intentionally replaced with GetFileById() to solve the following issue:\n\t\t\t\t// GetFileByUrl() uses webDavUrl to locate list item. This API does not work for Consumer scenarios\n\t\t\t\t// where webDavUrl is constructed using legacy ODC format for backward compatibility reasons.\n\t\t\t\t// GetFileByUrl() does not understand that format and thus fails. GetFileById() relies on file item\n\t\t\t\t// unique guid (sharepointIds.listItemUniqueId) and it works uniformly across Consumer and Commercial.\n\t\t\t\tconst url = `${\n\t\t\t\t\todspUrlParts.siteUrl\n\t\t\t\t}/_api/web/GetFileById(@a1)/ListItemAllFields/GetSharingInformation?@a1=guid${encodeURIComponent(\n\t\t\t\t\t`'${fileItem.sharepointIds.listItemUniqueId}'`,\n\t\t\t\t)}`;\n\t\t\t\tconst method = \"POST\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileLinkCore\",\n\t\t\t\t);\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\tconst requestInit = {\n\t\t\t\t\tmethod,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t\"Accept\": \"application/json;odata=verbose\",\n\t\t\t\t\t\t...headers,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst sharingInfo = await response.content.json();\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tconst directUrl = sharingInfo?.d?.directUrl;\n\t\t\t\tif (typeof directUrl !== \"string\") {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed GetSharingInformation response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn directUrl;\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileLink;\n\t\t},\n\t);\n}\n\n/**\n * Sharepoint Ids Interface\n */\ninterface IGraphSharepointIds {\n\tlistId: string;\n\tlistItemId: string;\n\tlistItemUniqueId: string;\n\tsiteId: string;\n\tsiteUrl: string;\n\twebId: string;\n}\n\n/**\n * This represents a lite version of file item containing only select file properties\n */\ninterface FileItemLite {\n\twebUrl: string;\n\twebDavUrl: string;\n\tsharepointIds: IGraphSharepointIds;\n}\n\nconst isFileItemLite = (maybeFileItemLite: unknown): maybeFileItemLite is FileItemLite =>\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webUrl === \"string\" &&\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).webDavUrl === \"string\" &&\n\t// TODO: stronger check\n\ttypeof (maybeFileItemLite as Partial<FileItemLite>).sharepointIds === \"object\";\n\nasync function getFileItemLite(\n\tgetToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n\todspUrlParts: IOdspUrlParts,\n\tlogger: ITelemetryLoggerExt,\n\tforceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<FileItemLite> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tlogger,\n\t\t{ eventName: \"odspFileLink\", requestName: \"getFileItemLite\" },\n\t\tasync (event) => {\n\t\t\tlet attempts = 0;\n\t\t\tlet additionalProps: ITelemetryBaseProperties | undefined;\n\t\t\tconst fileItem = await getWithRetryForTokenRefresh(async (options) => {\n\t\t\t\tattempts++;\n\t\t\t\tconst { siteUrl, driveId, itemId } = odspUrlParts;\n\t\t\t\tconst getAuthHeader = toInstrumentedOdspStorageTokenFetcher(\n\t\t\t\t\tlogger,\n\t\t\t\t\todspUrlParts,\n\t\t\t\t\tgetToken,\n\t\t\t\t);\n\t\t\t\tconst url = `${siteUrl}/_api/v2.0/drives/${driveId}/items/${itemId}?select=webUrl,webDavUrl,sharepointIds`;\n\t\t\t\tconst method = \"GET\";\n\t\t\t\tconst authHeader = await getAuthHeader(\n\t\t\t\t\t{ ...options, request: { url, method } },\n\t\t\t\t\t\"GetFileItemLite\",\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tauthHeader !== null,\n\t\t\t\t\t0x2bc /* \"Instrumented token fetcher with throwOnNullToken =true should never return null\" */,\n\t\t\t\t);\n\n\t\t\t\tconst headers = getHeadersWithAuth(authHeader);\n\t\t\t\tconst requestInit = { method, headers };\n\t\t\t\tconst response = await fetchHelper(url, requestInit);\n\t\t\t\tadditionalProps = response.propsToLog;\n\n\t\t\t\tconst responseJson: unknown = await response.content.json();\n\t\t\t\tif (!isFileItemLite(responseJson)) {\n\t\t\t\t\t// This will retry once in getWithRetryForTokenRefresh\n\t\t\t\t\tthrow new NonRetryableError(\n\t\t\t\t\t\t\"Malformed getFileItemLite response\",\n\t\t\t\t\t\tOdspErrorTypes.incorrectServerResponse,\n\t\t\t\t\t\t{ driverVersion },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn responseJson;\n\t\t\t});\n\t\t\tevent.end({ ...additionalProps, attempts });\n\t\t\treturn fileItem;\n\t\t},\n\t);\n}\n\n/**\n * It takes a resolved url with old siteUrl and patches resolved url with updated site url domain.\n * @param odspResolvedUrl - Previous odsp resolved url with older site url.\n * @param newSiteDomain - New site domain after the tenant rename.\n */\nfunction renameTenantInOdspResolvedUrl(\n\todspResolvedUrl: IOdspResolvedUrl,\n\tnewSiteDomain: string,\n): void {\n\tconst newSiteUrl = `${newSiteDomain}${new URL(odspResolvedUrl.siteUrl).pathname}`;\n\todspResolvedUrl.siteUrl = newSiteUrl;\n\n\tif (odspResolvedUrl.endpoints.attachmentGETStorageUrl) {\n\t\todspResolvedUrl.endpoints.attachmentGETStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentGETStorageUrl).pathname}`;\n\t}\n\tif (odspResolvedUrl.endpoints.attachmentPOSTStorageUrl) {\n\t\todspResolvedUrl.endpoints.attachmentPOSTStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentPOSTStorageUrl).pathname}`;\n\t}\n\tif (odspResolvedUrl.endpoints.deltaStorageUrl) {\n\t\todspResolvedUrl.endpoints.deltaStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.deltaStorageUrl).pathname}`;\n\t}\n\tif (odspResolvedUrl.endpoints.snapshotStorageUrl) {\n\t\todspResolvedUrl.endpoints.snapshotStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.snapshotStorageUrl).pathname}`;\n\t}\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/odsp-driver";
|
|
8
|
-
export declare const pkgVersion = "2.
|
|
8
|
+
export declare const pkgVersion = "2.4.0-294316";
|
|
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,
|
|
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"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,6BAA6B,CAAC;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,6BAA6B,CAAC;AACrD,MAAM,CAAC,MAAM,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 = \"2.4.0-294316\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/odsp-driver",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-294316",
|
|
4
4
|
"description": "Socket storage implementation for SPO and ODC",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -67,15 +67,15 @@
|
|
|
67
67
|
"temp-directory": "nyc/.nyc_output"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@fluid-internal/client-utils": "
|
|
71
|
-
"@fluidframework/core-interfaces": "
|
|
72
|
-
"@fluidframework/core-utils": "
|
|
73
|
-
"@fluidframework/driver-base": "
|
|
74
|
-
"@fluidframework/driver-definitions": "
|
|
75
|
-
"@fluidframework/driver-utils": "
|
|
76
|
-
"@fluidframework/odsp-doclib-utils": "
|
|
77
|
-
"@fluidframework/odsp-driver-definitions": "
|
|
78
|
-
"@fluidframework/telemetry-utils": "
|
|
70
|
+
"@fluid-internal/client-utils": "2.4.0-294316",
|
|
71
|
+
"@fluidframework/core-interfaces": "2.4.0-294316",
|
|
72
|
+
"@fluidframework/core-utils": "2.4.0-294316",
|
|
73
|
+
"@fluidframework/driver-base": "2.4.0-294316",
|
|
74
|
+
"@fluidframework/driver-definitions": "2.4.0-294316",
|
|
75
|
+
"@fluidframework/driver-utils": "2.4.0-294316",
|
|
76
|
+
"@fluidframework/odsp-doclib-utils": "2.4.0-294316",
|
|
77
|
+
"@fluidframework/odsp-driver-definitions": "2.4.0-294316",
|
|
78
|
+
"@fluidframework/telemetry-utils": "2.4.0-294316",
|
|
79
79
|
"node-fetch": "^2.6.9",
|
|
80
80
|
"socket.io-client": "^4.7.3",
|
|
81
81
|
"uuid": "^9.0.0"
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
85
85
|
"@biomejs/biome": "~1.8.3",
|
|
86
|
-
"@fluid-internal/mocha-test-setup": "
|
|
86
|
+
"@fluid-internal/mocha-test-setup": "2.4.0-294316",
|
|
87
87
|
"@fluid-tools/build-cli": "^0.46.0",
|
|
88
88
|
"@fluidframework/build-common": "^2.0.3",
|
|
89
89
|
"@fluidframework/build-tools": "^0.46.0",
|
|
90
90
|
"@fluidframework/eslint-config-fluid": "^5.4.0",
|
|
91
|
-
"@fluidframework/odsp-driver-previous": "npm:@fluidframework/odsp-driver@2.
|
|
91
|
+
"@fluidframework/odsp-driver-previous": "npm:@fluidframework/odsp-driver@2.3.0",
|
|
92
92
|
"@microsoft/api-extractor": "7.47.8",
|
|
93
93
|
"@types/mocha": "^9.1.1",
|
|
94
94
|
"@types/node": "^18.19.0",
|
package/src/getFileLink.ts
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
import type { ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
|
|
7
7
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
8
8
|
import { NonRetryableError, runWithRetry } from "@fluidframework/driver-utils/internal";
|
|
9
|
-
import { hasRedirectionLocation } from "@fluidframework/odsp-doclib-utils/internal";
|
|
10
9
|
import {
|
|
11
10
|
IOdspUrlParts,
|
|
12
11
|
OdspErrorTypes,
|
|
13
12
|
OdspResourceTokenFetchOptions,
|
|
14
13
|
TokenFetcher,
|
|
14
|
+
type IOdspResolvedUrl,
|
|
15
15
|
} from "@fluidframework/odsp-driver-definitions/internal";
|
|
16
16
|
import {
|
|
17
17
|
ITelemetryLoggerExt,
|
|
@@ -44,10 +44,10 @@ const fileLinkCache = new Map<string, Promise<string>>();
|
|
|
44
44
|
*/
|
|
45
45
|
export async function getFileLink(
|
|
46
46
|
getToken: TokenFetcher<OdspResourceTokenFetchOptions>,
|
|
47
|
-
|
|
47
|
+
resolvedUrl: IOdspResolvedUrl,
|
|
48
48
|
logger: ITelemetryLoggerExt,
|
|
49
49
|
): Promise<string> {
|
|
50
|
-
const cacheKey = `${
|
|
50
|
+
const cacheKey = `${resolvedUrl.siteUrl}_${resolvedUrl.driveId}_${resolvedUrl.itemId}`;
|
|
51
51
|
const maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);
|
|
52
52
|
if (maybeFileLinkCacheEntry !== undefined) {
|
|
53
53
|
return maybeFileLinkCacheEntry;
|
|
@@ -61,7 +61,7 @@ export async function getFileLink(
|
|
|
61
61
|
async () =>
|
|
62
62
|
runWithRetryForCoherencyAndServiceReadOnlyErrors(
|
|
63
63
|
async () =>
|
|
64
|
-
getFileLinkWithLocationRedirectionHandling(getToken,
|
|
64
|
+
getFileLinkWithLocationRedirectionHandling(getToken, resolvedUrl, logger),
|
|
65
65
|
"getFileLinkCore",
|
|
66
66
|
logger,
|
|
67
67
|
),
|
|
@@ -116,32 +116,41 @@ export async function getFileLink(
|
|
|
116
116
|
*/
|
|
117
117
|
async function getFileLinkWithLocationRedirectionHandling(
|
|
118
118
|
getToken: TokenFetcher<OdspResourceTokenFetchOptions>,
|
|
119
|
-
|
|
119
|
+
resolvedUrl: IOdspResolvedUrl,
|
|
120
120
|
logger: ITelemetryLoggerExt,
|
|
121
121
|
): Promise<string> {
|
|
122
122
|
// We can have chains of location redirection one after the other, so have a for loop
|
|
123
123
|
// so that we can keep handling the same type of error. Set max number of redirection to 5.
|
|
124
124
|
let lastError: unknown;
|
|
125
|
+
let locationRedirected = false;
|
|
125
126
|
for (let count = 1; count <= 5; count++) {
|
|
126
127
|
try {
|
|
127
|
-
|
|
128
|
+
const fileItem = await getFileItemLite(getToken, resolvedUrl, logger, true);
|
|
129
|
+
// Sometimes the siteUrl in the actual file is different from the siteUrl in the resolvedUrl due to location
|
|
130
|
+
// redirection. This creates issues in the getSharingInformation call. So we need to update the siteUrl in the
|
|
131
|
+
// resolvedUrl to the siteUrl in the fileItem which is the updated siteUrl.
|
|
132
|
+
const oldSiteDomain = new URL(resolvedUrl.siteUrl).origin;
|
|
133
|
+
const newSiteDomain = new URL(fileItem.sharepointIds.siteUrl).origin;
|
|
134
|
+
if (oldSiteDomain !== newSiteDomain) {
|
|
135
|
+
locationRedirected = true;
|
|
136
|
+
logger.sendTelemetryEvent({
|
|
137
|
+
eventName: "LocationRedirectionErrorForGetOdspFileLink",
|
|
138
|
+
retryCount: count,
|
|
139
|
+
});
|
|
140
|
+
renameTenantInOdspResolvedUrl(resolvedUrl, newSiteDomain);
|
|
141
|
+
}
|
|
142
|
+
return await getFileLinkCore(getToken, resolvedUrl, logger, fileItem);
|
|
128
143
|
} catch (error: unknown) {
|
|
129
144
|
lastError = error;
|
|
145
|
+
// If the getSharingLink call fails with the 401/403/404 error, then it could be due to that the file has moved
|
|
146
|
+
// to another location. This could occur in case we have more than 1 tenant rename. In that case, we should retry
|
|
147
|
+
// the getFileItemLite call to get the updated fileItem.
|
|
130
148
|
if (
|
|
131
149
|
isFluidError(error) &&
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
locationRedirected &&
|
|
151
|
+
(error.errorType === OdspErrorTypes.fileNotFoundOrAccessDeniedError ||
|
|
152
|
+
error.errorType === OdspErrorTypes.authorizationError)
|
|
135
153
|
) {
|
|
136
|
-
const redirectLocation = error.redirectLocation;
|
|
137
|
-
logger.sendTelemetryEvent({
|
|
138
|
-
eventName: "LocationRedirectionErrorForGetOdspFileLink",
|
|
139
|
-
retryCount: count,
|
|
140
|
-
});
|
|
141
|
-
// Generate the new SiteUrl from the redirection location.
|
|
142
|
-
const newSiteDomain = new URL(redirectLocation).origin;
|
|
143
|
-
const newSiteUrl = `${newSiteDomain}${new URL(odspUrlParts.siteUrl).pathname}`;
|
|
144
|
-
odspUrlParts.siteUrl = newSiteUrl;
|
|
145
154
|
continue;
|
|
146
155
|
}
|
|
147
156
|
throw error;
|
|
@@ -154,9 +163,8 @@ async function getFileLinkCore(
|
|
|
154
163
|
getToken: TokenFetcher<OdspResourceTokenFetchOptions>,
|
|
155
164
|
odspUrlParts: IOdspUrlParts,
|
|
156
165
|
logger: ITelemetryLoggerExt,
|
|
166
|
+
fileItem: FileItemLite,
|
|
157
167
|
): Promise<string> {
|
|
158
|
-
const fileItem = await getFileItemLite(getToken, odspUrlParts, logger, true);
|
|
159
|
-
|
|
160
168
|
// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder
|
|
161
169
|
return PerformanceEvent.timedExecAsync(
|
|
162
170
|
logger,
|
|
@@ -194,7 +202,6 @@ async function getFileLinkCore(
|
|
|
194
202
|
headers: {
|
|
195
203
|
"Content-Type": "application/json;odata=verbose",
|
|
196
204
|
"Accept": "application/json;odata=verbose",
|
|
197
|
-
"redirect": "manual",
|
|
198
205
|
...headers,
|
|
199
206
|
},
|
|
200
207
|
};
|
|
@@ -281,7 +288,6 @@ async function getFileItemLite(
|
|
|
281
288
|
);
|
|
282
289
|
|
|
283
290
|
const headers = getHeadersWithAuth(authHeader);
|
|
284
|
-
headers.redirect = "manual";
|
|
285
291
|
const requestInit = { method, headers };
|
|
286
292
|
const response = await fetchHelper(url, requestInit);
|
|
287
293
|
additionalProps = response.propsToLog;
|
|
@@ -302,3 +308,29 @@ async function getFileItemLite(
|
|
|
302
308
|
},
|
|
303
309
|
);
|
|
304
310
|
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* It takes a resolved url with old siteUrl and patches resolved url with updated site url domain.
|
|
314
|
+
* @param odspResolvedUrl - Previous odsp resolved url with older site url.
|
|
315
|
+
* @param newSiteDomain - New site domain after the tenant rename.
|
|
316
|
+
*/
|
|
317
|
+
function renameTenantInOdspResolvedUrl(
|
|
318
|
+
odspResolvedUrl: IOdspResolvedUrl,
|
|
319
|
+
newSiteDomain: string,
|
|
320
|
+
): void {
|
|
321
|
+
const newSiteUrl = `${newSiteDomain}${new URL(odspResolvedUrl.siteUrl).pathname}`;
|
|
322
|
+
odspResolvedUrl.siteUrl = newSiteUrl;
|
|
323
|
+
|
|
324
|
+
if (odspResolvedUrl.endpoints.attachmentGETStorageUrl) {
|
|
325
|
+
odspResolvedUrl.endpoints.attachmentGETStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentGETStorageUrl).pathname}`;
|
|
326
|
+
}
|
|
327
|
+
if (odspResolvedUrl.endpoints.attachmentPOSTStorageUrl) {
|
|
328
|
+
odspResolvedUrl.endpoints.attachmentPOSTStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.attachmentPOSTStorageUrl).pathname}`;
|
|
329
|
+
}
|
|
330
|
+
if (odspResolvedUrl.endpoints.deltaStorageUrl) {
|
|
331
|
+
odspResolvedUrl.endpoints.deltaStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.deltaStorageUrl).pathname}`;
|
|
332
|
+
}
|
|
333
|
+
if (odspResolvedUrl.endpoints.snapshotStorageUrl) {
|
|
334
|
+
odspResolvedUrl.endpoints.snapshotStorageUrl = `${newSiteDomain}${new URL(odspResolvedUrl.endpoints.snapshotStorageUrl).pathname}`;
|
|
335
|
+
}
|
|
336
|
+
}
|
package/src/packageVersion.ts
CHANGED