@fluidframework/odsp-driver 1.1.0 → 1.2.0
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/checkUrl.d.ts +1 -1
- package/dist/checkUrl.js +1 -1
- package/dist/checkUrl.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/contractsPublic.d.ts +1 -0
- package/dist/contractsPublic.d.ts.map +1 -1
- package/dist/contractsPublic.js.map +1 -1
- package/dist/getFileLink.js +0 -4
- package/dist/getFileLink.js.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentService.d.ts +26 -0
- package/dist/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentService.js +39 -0
- package/dist/localOdspDriver/localOdspDocumentService.js.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +45 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
- package/dist/odspDeltaStorageService.js.map +1 -1
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactory.d.ts +2 -1
- package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactory.js +7 -1
- package/dist/odspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts +3 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +5 -23
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +52 -245
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDocumentStorageServiceBase.d.ts +58 -0
- package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -0
- package/dist/odspDocumentStorageServiceBase.js +216 -0
- package/dist/odspDocumentStorageServiceBase.js.map +1 -0
- package/dist/odspDriverUrlResolver.js +1 -1
- package/dist/odspDriverUrlResolver.js.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.d.ts +8 -2
- package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.js +11 -3
- package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/dist/odspFluidFileLink.d.ts.map +1 -1
- package/dist/odspFluidFileLink.js +27 -21
- package/dist/odspFluidFileLink.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/checkUrl.d.ts +1 -1
- package/lib/checkUrl.js +1 -1
- package/lib/checkUrl.js.map +1 -1
- package/lib/constants.d.ts +1 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/constants.js.map +1 -1
- package/lib/contractsPublic.d.ts +1 -0
- package/lib/contractsPublic.d.ts.map +1 -1
- package/lib/contractsPublic.js.map +1 -1
- package/lib/getFileLink.js +0 -4
- package/lib/getFileLink.js.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentService.d.ts +26 -0
- package/lib/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentService.js +35 -0
- package/lib/localOdspDriver/localOdspDocumentService.js.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +41 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.js +62 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
- package/lib/odspDeltaStorageService.js.map +1 -1
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +1 -1
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactory.d.ts +2 -1
- package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactory.js +5 -0
- package/lib/odspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts +3 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +5 -23
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +53 -246
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDocumentStorageServiceBase.d.ts +58 -0
- package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -0
- package/lib/odspDocumentStorageServiceBase.js +212 -0
- package/lib/odspDocumentStorageServiceBase.js.map +1 -0
- package/lib/odspDriverUrlResolver.js +1 -1
- package/lib/odspDriverUrlResolver.js.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.d.ts +8 -2
- package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.js +11 -3
- package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/lib/odspFluidFileLink.d.ts.map +1 -1
- package/lib/odspFluidFileLink.js +27 -21
- package/lib/odspFluidFileLink.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +17 -12
- package/src/checkUrl.ts +1 -1
- package/src/constants.ts +1 -1
- package/src/contractsPublic.ts +1 -0
- package/src/getFileLink.ts +0 -5
- package/src/localOdspDriver/localOdspDocumentService.ts +54 -0
- package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +67 -0
- package/src/localOdspDriver/localOdspDocumentStorageManager.ts +83 -0
- package/src/odspDeltaStorageService.ts +1 -1
- package/src/odspDocumentService.ts +5 -1
- package/src/odspDocumentServiceFactory.ts +7 -3
- package/src/odspDocumentServiceFactoryCore.ts +1 -1
- package/src/odspDocumentStorageManager.ts +81 -312
- package/src/odspDocumentStorageServiceBase.ts +268 -0
- package/src/odspDriverUrlResolver.ts +1 -1
- package/src/odspDriverUrlResolverForShareLink.ts +13 -1
- package/src/odspFluidFileLink.ts +26 -22
- package/src/packageVersion.ts +1 -1
|
@@ -9,13 +9,14 @@ const common_utils_1 = require("@fluidframework/common-utils");
|
|
|
9
9
|
const constants_1 = require("./constants");
|
|
10
10
|
const fluidSignature = "1";
|
|
11
11
|
const fluidSignatureParamName = "fluid";
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
12
|
+
const sitePathParamName = "s";
|
|
13
|
+
const driveIdParamName = "d";
|
|
14
|
+
const itemIdParamName = "f";
|
|
15
|
+
const dataStorePathParamName = "c";
|
|
16
|
+
const appNameParamName = "a";
|
|
17
|
+
const containerPackageNameParamName = "p";
|
|
18
|
+
const fileVersionParamName = "v";
|
|
19
|
+
const additionalContextParamName = "x";
|
|
19
20
|
/**
|
|
20
21
|
* Transforms given Fluid data store locator into string that can be embedded into url
|
|
21
22
|
* @param locator - describes Fluid data store locator info to be encoded
|
|
@@ -27,15 +28,18 @@ function encodeOdspFluidDataStoreLocator(locator) {
|
|
|
27
28
|
const driveId = encodeURIComponent(locator.driveId);
|
|
28
29
|
const itemId = encodeURIComponent(locator.itemId);
|
|
29
30
|
const dataStorePath = encodeURIComponent(locator.dataStorePath);
|
|
30
|
-
let locatorSerialized = `${
|
|
31
|
+
let locatorSerialized = `${sitePathParamName}=${sitePath}&${driveIdParamName}=${driveId}&${itemIdParamName}=${itemId}&${dataStorePathParamName}=${dataStorePath}&${fluidSignatureParamName}=${fluidSignature}`;
|
|
31
32
|
if (locator.appName) {
|
|
32
|
-
locatorSerialized += `&${
|
|
33
|
+
locatorSerialized += `&${appNameParamName}=${encodeURIComponent(locator.appName)}`;
|
|
33
34
|
}
|
|
34
35
|
if (locator.containerPackageName) {
|
|
35
|
-
locatorSerialized += `&${
|
|
36
|
+
locatorSerialized += `&${containerPackageNameParamName}=${encodeURIComponent(locator.containerPackageName)}`;
|
|
36
37
|
}
|
|
37
38
|
if (locator.fileVersion) {
|
|
38
|
-
locatorSerialized += `&${
|
|
39
|
+
locatorSerialized += `&${fileVersionParamName}=${encodeURIComponent(locator.fileVersion)}`;
|
|
40
|
+
}
|
|
41
|
+
if (locator.context) {
|
|
42
|
+
locatorSerialized += `&${additionalContextParamName}=${encodeURIComponent(locator.context)}`;
|
|
39
43
|
}
|
|
40
44
|
return (0, common_utils_1.fromUtf8ToBase64)(locatorSerialized);
|
|
41
45
|
}
|
|
@@ -48,21 +52,22 @@ exports.encodeOdspFluidDataStoreLocator = encodeOdspFluidDataStoreLocator;
|
|
|
48
52
|
* @returns object representing Fluid data store location in ODSP terms
|
|
49
53
|
*/
|
|
50
54
|
function decodeOdspFluidDataStoreLocator(encodedLocatorValue, siteOriginUrl) {
|
|
51
|
-
var _a, _b, _c;
|
|
55
|
+
var _a, _b, _c, _d;
|
|
52
56
|
const locatorInfo = new URLSearchParams((0, common_utils_1.fromBase64ToUtf8)(encodedLocatorValue));
|
|
53
57
|
const signatureValue = locatorInfo.get(fluidSignatureParamName);
|
|
54
58
|
if (signatureValue !== "1") {
|
|
55
59
|
return undefined;
|
|
56
60
|
}
|
|
57
|
-
const sitePath = locatorInfo.get(
|
|
58
|
-
const driveId = locatorInfo.get(
|
|
59
|
-
const itemId = locatorInfo.get(
|
|
60
|
-
const dataStorePath = locatorInfo.get(
|
|
61
|
-
const appName = (_a = locatorInfo.get(
|
|
62
|
-
const containerPackageName = (_b = locatorInfo.get(
|
|
63
|
-
const fileVersion = (_c = locatorInfo.get(
|
|
61
|
+
const sitePath = locatorInfo.get(sitePathParamName);
|
|
62
|
+
const driveId = locatorInfo.get(driveIdParamName);
|
|
63
|
+
const itemId = locatorInfo.get(itemIdParamName);
|
|
64
|
+
const dataStorePath = locatorInfo.get(dataStorePathParamName);
|
|
65
|
+
const appName = (_a = locatorInfo.get(appNameParamName)) !== null && _a !== void 0 ? _a : undefined;
|
|
66
|
+
const containerPackageName = (_b = locatorInfo.get(containerPackageNameParamName)) !== null && _b !== void 0 ? _b : undefined;
|
|
67
|
+
const fileVersion = (_c = locatorInfo.get(fileVersionParamName)) !== null && _c !== void 0 ? _c : undefined;
|
|
68
|
+
const context = (_d = locatorInfo.get(additionalContextParamName)) !== null && _d !== void 0 ? _d : undefined;
|
|
64
69
|
// "" is a valid value for dataStorePath so simply check for absence of the param;
|
|
65
|
-
//
|
|
70
|
+
// file storage locator params must be present and non-empty
|
|
66
71
|
if (!sitePath || !driveId || !itemId || dataStorePath === null) {
|
|
67
72
|
return undefined;
|
|
68
73
|
}
|
|
@@ -70,7 +75,7 @@ function decodeOdspFluidDataStoreLocator(encodedLocatorValue, siteOriginUrl) {
|
|
|
70
75
|
try {
|
|
71
76
|
siteUrl = new URL(sitePath, siteOriginUrl);
|
|
72
77
|
}
|
|
73
|
-
catch (
|
|
78
|
+
catch (_e) {
|
|
74
79
|
// Ignore failure to parse url as input might be malformed
|
|
75
80
|
}
|
|
76
81
|
if (!siteUrl) {
|
|
@@ -84,6 +89,7 @@ function decodeOdspFluidDataStoreLocator(encodedLocatorValue, siteOriginUrl) {
|
|
|
84
89
|
appName,
|
|
85
90
|
containerPackageName,
|
|
86
91
|
fileVersion,
|
|
92
|
+
context,
|
|
87
93
|
};
|
|
88
94
|
}
|
|
89
95
|
// This parameter is provided by host in the resolve request and it contains information about the file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspFluidFileLink.js","sourceRoot":"","sources":["../src/odspFluidFileLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkF;AAElF,2CAAkE;AAElE,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,uBAAuB,GAAG,OAAO,CAAC;AACxC,MAAM,
|
|
1
|
+
{"version":3,"file":"odspFluidFileLink.js","sourceRoot":"","sources":["../src/odspFluidFileLink.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAkF;AAElF,2CAAkE;AAElE,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,uBAAuB,GAAG,OAAO,CAAC;AACxC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAC1C,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC;;;;GAIG;AACH,SAAgB,+BAA+B,CAAC,OAAkC;IAC9E,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,kBA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mBAAmB,GAAG,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACrE,0GAA0G;IAC1G,qCAAqC;IACrC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,6BAAqB,EAAE,mBAAmB,CAAC,CAAC;AACrE,CAAC;AALD,sDAKC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,GAAQ;IAC1C,mGAAmG;IACnG,MAAM,mBAAmB,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,6BAAqB,CAAC,CAAC;IACxE,IAAI,CAAC,mBAAmB,EAAE;QACtB,OAAO,SAAS,CAAC;KACpB;IAED,qGAAqG;IACrG,oFAAoF;IACpF,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,6BAAiB,CAAC,CAAC,CAAC,4BAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;IAErG,OAAO,+BAA+B,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;AAC/E,CAAC;AAZD,sDAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fromBase64ToUtf8, fromUtf8ToBase64 } from \"@fluidframework/common-utils\";\nimport { OdspFluidDataStoreLocator } from \"./contractsPublic\";\nimport { OdcFileSiteOrigin, OdcApiSiteOrigin } from \"./constants\";\n\nconst fluidSignature = \"1\";\nconst fluidSignatureParamName = \"fluid\";\nconst sitePathParamName = \"s\";\nconst driveIdParamName = \"d\";\nconst itemIdParamName = \"f\";\nconst dataStorePathParamName = \"c\";\nconst appNameParamName = \"a\";\nconst containerPackageNameParamName = \"p\";\nconst fileVersionParamName = \"v\";\nconst additionalContextParamName = \"x\";\n\n/**\n * Transforms given Fluid data store locator into string that can be embedded into url\n * @param locator - describes Fluid data store locator info to be encoded\n * @returns string representing encoded Fluid data store locator info\n */\nexport function encodeOdspFluidDataStoreLocator(locator: OdspFluidDataStoreLocator): string {\n const siteUrl = new URL(locator.siteUrl);\n const sitePath = encodeURIComponent(siteUrl.pathname);\n const driveId = encodeURIComponent(locator.driveId);\n const itemId = encodeURIComponent(locator.itemId);\n const dataStorePath = encodeURIComponent(locator.dataStorePath);\n\n let locatorSerialized = `${sitePathParamName}=${sitePath}&${driveIdParamName}=${driveId}&${\n itemIdParamName}=${itemId}&${dataStorePathParamName}=${dataStorePath}&${\n fluidSignatureParamName}=${fluidSignature}`;\n if (locator.appName) {\n locatorSerialized += `&${appNameParamName}=${encodeURIComponent(locator.appName)}`;\n }\n if (locator.containerPackageName) {\n locatorSerialized += `&${containerPackageNameParamName}=${encodeURIComponent(locator.containerPackageName)}`;\n }\n if (locator.fileVersion) {\n locatorSerialized += `&${fileVersionParamName}=${encodeURIComponent(locator.fileVersion)}`;\n }\n if (locator.context) {\n locatorSerialized += `&${additionalContextParamName}=${encodeURIComponent(locator.context)}`;\n }\n\n return fromUtf8ToBase64(locatorSerialized);\n}\n\n/**\n * Decodes given encoded value representing Fluid data store locator extracted from ODSP Fluid file link\n * @param encodedLocatorValue - encoded Fluid data store locator value which was produced by\n * encodeOdspFluidDataStoreLocator method\n * @param siteOriginUrl - site origin that will be appended to encoded relative path to form absolute file url\n * @returns object representing Fluid data store location in ODSP terms\n */\nfunction decodeOdspFluidDataStoreLocator(\n encodedLocatorValue: string,\n siteOriginUrl: string,\n): OdspFluidDataStoreLocator | undefined {\n const locatorInfo = new URLSearchParams(fromBase64ToUtf8(encodedLocatorValue));\n\n const signatureValue = locatorInfo.get(fluidSignatureParamName);\n if (signatureValue !== \"1\") {\n return undefined;\n }\n\n const sitePath = locatorInfo.get(sitePathParamName);\n const driveId = locatorInfo.get(driveIdParamName);\n const itemId = locatorInfo.get(itemIdParamName);\n const dataStorePath = locatorInfo.get(dataStorePathParamName);\n const appName = locatorInfo.get(appNameParamName) ?? undefined;\n const containerPackageName = locatorInfo.get(containerPackageNameParamName) ?? undefined;\n const fileVersion = locatorInfo.get(fileVersionParamName) ?? undefined;\n const context = locatorInfo.get(additionalContextParamName) ?? undefined;\n // \"\" is a valid value for dataStorePath so simply check for absence of the param;\n // file storage locator params must be present and non-empty\n if (!sitePath || !driveId || !itemId || dataStorePath === null) {\n return undefined;\n }\n\n let siteUrl: URL | undefined;\n try {\n siteUrl = new URL(sitePath, siteOriginUrl);\n } catch {\n // Ignore failure to parse url as input might be malformed\n }\n\n if (!siteUrl) {\n return undefined;\n }\n\n return {\n siteUrl: siteUrl.href,\n driveId,\n itemId,\n dataStorePath,\n appName,\n containerPackageName,\n fileVersion,\n context,\n };\n}\n\n// This parameter is provided by host in the resolve request and it contains information about the file\n// like driveId, itemId, siteUrl, datastorePath, packageName etc.\nexport const locatorQueryParamName = \"nav\";\n\n/**\n * Embeds Fluid data store locator data into given ODSP url\n * @param url - file url in ODSP format (can be either canonical or share link)\n * @param locator - object representing Fluid data store location in ODSP terms\n */\nexport function storeLocatorInOdspUrl(url: URL, locator: OdspFluidDataStoreLocator) {\n const encodedLocatorValue = encodeOdspFluidDataStoreLocator(locator);\n // IMPORTANT: Do not apply encodeURIComponent to encodedLocatorValue, param value is automatically encoded\n // when set via URLSearchParams class\n url.searchParams.set(locatorQueryParamName, encodedLocatorValue);\n}\n\n/**\n * Extract ODSP Fluid data store locator object from given ODSP url. This extracts things like\n * driveId, ItemId, siteUrl etc from a url where these are encoded in nav query param.\n * @param url - ODSP url representing Fluid file link\n * @returns object representing Fluid data store location in ODSP terms\n */\nexport function getLocatorFromOdspUrl(url: URL): OdspFluidDataStoreLocator | undefined {\n // NOTE: No need to apply decodeURIComponent when accessing query params via URLSearchParams class.\n const encodedLocatorValue = url.searchParams.get(locatorQueryParamName);\n if (!encodedLocatorValue) {\n return undefined;\n }\n\n // IMPORTANT: ODC deviates from ODSP in that its file link origin is different from vroom api origin.\n // The following code passes vroom api origin as site origin instead of file origin.\n const siteOriginUrl = url.origin.toLowerCase() === OdcFileSiteOrigin ? OdcApiSiteOrigin : url.origin;\n\n return decodeOdspFluidDataStoreLocator(encodedLocatorValue, siteOriginUrl);\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/odsp-driver";
|
|
11
|
-
exports.pkgVersion = "1.
|
|
11
|
+
exports.pkgVersion = "1.2.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"1.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/odsp-driver\";\nexport const pkgVersion = \"1.2.0\";\n"]}
|
package/lib/checkUrl.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { DriverPreCheckInfo } from "@fluidframework/driver-definitions";
|
|
6
6
|
/**
|
|
7
7
|
* A check that returns DriverPreCheckInfo if the URL format is likely supported by this driver.
|
|
8
|
-
* Note that returning information here is NOT a full
|
|
8
|
+
* Note that returning information here is NOT a full guarantee that resolve will ultimately be successful.
|
|
9
9
|
* Instead, this should be used as a lightweight check that can filter out easily detectable unsupported URLs
|
|
10
10
|
* before the entire Fluid loading process needs to be kicked off.
|
|
11
11
|
*/
|
package/lib/checkUrl.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { getLocatorFromOdspUrl } from "./odspFluidFileLink";
|
|
6
6
|
/**
|
|
7
7
|
* A check that returns DriverPreCheckInfo if the URL format is likely supported by this driver.
|
|
8
|
-
* Note that returning information here is NOT a full
|
|
8
|
+
* Note that returning information here is NOT a full guarantee that resolve will ultimately be successful.
|
|
9
9
|
* Instead, this should be used as a lightweight check that can filter out easily detectable unsupported URLs
|
|
10
10
|
* before the entire Fluid loading process needs to be kicked off.
|
|
11
11
|
*/
|
package/lib/checkUrl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkUrl.js","sourceRoot":"","sources":["../src/checkUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAgB;IACvC,MAAM,OAAO,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,UAA8B,CAAC;IACnC,IAAI;QACF,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE;YACpB,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC,MAAM,CAAC;SAC/C;KACF;IAAC,WAAM,GAAE;IAEV,OAAO;QACL,eAAe,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB;QAC9C,uEAAuE;QACvE,mBAAmB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;KAC3D,CAAC;AACJ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { DriverPreCheckInfo } from \"@fluidframework/driver-definitions\";\nimport { getLocatorFromOdspUrl } from \"./odspFluidFileLink\";\n\n/**\n * A check that returns DriverPreCheckInfo if the URL format is likely supported by this driver.\n * Note that returning information here is NOT a full
|
|
1
|
+
{"version":3,"file":"checkUrl.js","sourceRoot":"","sources":["../src/checkUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAgB;IACvC,MAAM,OAAO,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,UAA8B,CAAC;IACnC,IAAI;QACF,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE;YACpB,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC,MAAM,CAAC;SAC/C;KACF;IAAC,WAAM,GAAE;IAEV,OAAO;QACL,eAAe,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB;QAC9C,uEAAuE;QACvE,mBAAmB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;KAC3D,CAAC;AACJ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { DriverPreCheckInfo } from \"@fluidframework/driver-definitions\";\nimport { getLocatorFromOdspUrl } from \"./odspFluidFileLink\";\n\n/**\n * A check that returns DriverPreCheckInfo if the URL format is likely supported by this driver.\n * Note that returning information here is NOT a full guarantee that resolve will ultimately be successful.\n * Instead, this should be used as a lightweight check that can filter out easily detectable unsupported URLs\n * before the entire Fluid loading process needs to be kicked off.\n */\nexport function checkUrl(documentUrl: URL): DriverPreCheckInfo | undefined {\n const locator = getLocatorFromOdspUrl(documentUrl);\n\n if (!locator) {\n return undefined;\n }\n\n let siteOrigin: string | undefined;\n try {\n if (locator?.siteUrl) {\n siteOrigin = new URL(locator?.siteUrl).origin;\n }\n } catch {}\n\n return {\n codeDetailsHint: locator?.containerPackageName,\n // Add the snapshot endpoint, which has the same domain as the site URL\n criticalBootDomains: siteOrigin ? [siteOrigin] : undefined,\n };\n}\n"]}
|
package/lib/constants.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export declare const OdcApiSiteOrigin = "https://
|
|
5
|
+
export declare const OdcApiSiteOrigin = "https://my.microsoftpersonalcontent.com";
|
|
6
6
|
export declare const OdcFileSiteOrigin = "https://1drv.ms";
|
|
7
7
|
//# sourceMappingURL=constants.d.ts.map
|
package/lib/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,gBAAgB,4CAA4C,CAAC;AAC1E,eAAO,MAAM,iBAAiB,oBAAoB,CAAC"}
|
package/lib/constants.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export const OdcApiSiteOrigin = "https://
|
|
5
|
+
export const OdcApiSiteOrigin = "https://my.microsoftpersonalcontent.com";
|
|
6
6
|
export const OdcFileSiteOrigin = "https://1drv.ms";
|
|
7
7
|
//# sourceMappingURL=constants.js.map
|
package/lib/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,yCAAyC,CAAC;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const OdcApiSiteOrigin = \"https://my.microsoftpersonalcontent.com\";\nexport const OdcFileSiteOrigin = \"https://1drv.ms\";\n"]}
|
package/lib/contractsPublic.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractsPublic.d.ts","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"contractsPublic.d.ts","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,iBAAiB;IAGzB,qBAAqB,0BAA0B;CAClD;AAED,MAAM,WAAW,kBAAkB;IAC/B,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,oBAAY,qBAAqB;IAG7B,iBAAiB,wBAAwB;CAC5C;AAED,MAAM,WAAW,sBAAsB;IACnC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtD;AAED,OAAO,QAAQ,iCAAiC,CAAC;IAE7C,UAAiB,cAAe,SAAQ,OAAO,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC;KAAI;CAC3G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractsPublic.js","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"contractsPublic.js","sourceRoot":"","sources":["../src/contractsPublic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,yGAAyG;IACzG,sDAAsD;IACtD,oEAA+C,CAAA;AACnD,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B;AAMD,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC7B,oGAAoG;IACpG,wGAAwG;IACxG,kEAAyC,CAAA;AAC7C,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IOdspUrlParts } from \"@fluidframework/odsp-driver-definitions\";\n\nexport interface OdspFluidDataStoreLocator extends IOdspUrlParts {\n dataStorePath: string;\n appName?: string;\n containerPackageName?: string;\n fileVersion?: string;\n context?: string;\n}\n\nexport enum SharingLinkHeader {\n // Can be used in request made to resolver, to tell the resolver that the passed in URL is a sharing link\n // which can be redeemed at server to get permissions.\n isSharingLinkToRedeem = \"isSharingLinkToRedeem\",\n}\n\nexport interface ISharingLinkHeader {\n [SharingLinkHeader.isSharingLinkToRedeem]: boolean;\n}\n\nexport enum ClpCompliantAppHeader {\n // Can be used in request made to resolver, to tell the resolver that the host app is CLP compliant.\n // Odsp will not return Classified, labeled, or protected documents if the host app cannot support them.\n isClpCompliantApp = \"X-CLP-Compliant-App\",\n}\n\nexport interface IClpCompliantAppHeader {\n [ClpCompliantAppHeader.isClpCompliantApp]: boolean;\n}\n\ndeclare module \"@fluidframework/core-interfaces\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n export interface IRequestHeader extends Partial<ISharingLinkHeader>, Partial<IClpCompliantAppHeader> { }\n}\n"]}
|
package/lib/getFileLink.js
CHANGED
|
@@ -64,10 +64,6 @@ export async function getFileLink(getToken, odspUrlParts, identityType, logger)
|
|
|
64
64
|
}
|
|
65
65
|
async function getFileLinkCore(getToken, odspUrlParts, identityType, logger) {
|
|
66
66
|
const fileItem = await getFileItemLite(getToken, odspUrlParts, logger, identityType === "Consumer");
|
|
67
|
-
// ODC canonical link does not require any additional processing
|
|
68
|
-
if (identityType === "Consumer") {
|
|
69
|
-
return fileItem.webUrl;
|
|
70
|
-
}
|
|
71
67
|
// ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder
|
|
72
68
|
return PerformanceEvent.timedExecAsync(logger, { eventName: "odspFileLink", requestName: "getSharingLink" }, async (event) => {
|
|
73
69
|
let attempts = 0;
|
package/lib/getFileLink.js.map
CHANGED
|
@@ -1 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MAAM,WAAW,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAC/C,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;YACrD,eAAe,GAAG,QAAQ,CAAC,UAAU,CAAC;YAEtC,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACnD,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE;gBAC/B,sDAAsD;gBACtD,MAAM,IAAI,iBAAiB,CACvB,oCAAoC,EACpC,eAAe,CAAC,uBAAuB,EACvC,EAAE,aAAa,EAAE,CAAC,CAAC;aAC1B;YACD,OAAO,YAAY,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,GAAG,iCAAM,eAAe,KAAE,QAAQ,IAAG,CAAC;QAC5C,OAAO,QAAQ,CAAC;IACpB,CAAC,CACJ,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, delay } from \"@fluidframework/common-utils\";\nimport { canRetryOnError, getRetryDelayFromError, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n IOdspUrlParts,\n OdspResourceTokenFetchOptions,\n IdentityType,\n TokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { fetchHelper, getWithRetryForTokenRefresh, toInstrumentedOdspTokenFetcher } from \"./odspUtils\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\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 siteUrl - url of the site that contains the file\n * @param driveId - drive where file is stored\n * @param itemId - file id\n * @param identityType - type of client account\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 getToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n odspUrlParts: IOdspUrlParts,\n identityType: IdentityType,\n logger: ITelemetryLogger,\n): Promise<string> {\n const cacheKey = `${odspUrlParts.siteUrl}_${odspUrlParts.driveId}_${odspUrlParts.itemId}`;\n const maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);\n if (maybeFileLinkCacheEntry !== undefined) {\n return maybeFileLinkCacheEntry;\n }\n\n const valueGenerator = async function() {\n let result: string | undefined;\n let success = false;\n let retryAfterMs = 1000;\n do {\n try {\n result = await getFileLinkCore(getToken, odspUrlParts, identityType, logger);\n success = true;\n } catch (err) {\n // If it is not retriable, then just throw\n if (!canRetryOnError(err)) {\n // Delete from the cache to permit retrying later.\n fileLinkCache.delete(cacheKey);\n throw err;\n }\n // If the error is throttling error, then wait for the specified time before retrying.\n // If the waitTime is not specified, then we start with retrying immediately to max of 8s.\n retryAfterMs = getRetryDelayFromError(err) ?? Math.min(retryAfterMs * 2, 8000);\n await delay(retryAfterMs);\n }\n } while (!success);\n\n // We are guaranteed to run the getFileLinkCore at least once with successful result (which must be a string)\n assert(result !== undefined, 0x292 /* \"Unexpected undefined result from getFileLinkCore\" */);\n return result;\n };\n const fileLink = valueGenerator();\n fileLinkCache.set(cacheKey, fileLink);\n return fileLink;\n}\n\nasync function getFileLinkCore(\n getToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n odspUrlParts: IOdspUrlParts,\n identityType: IdentityType,\n logger: ITelemetryLogger,\n): Promise<string> {\n const fileItem = await getFileItemLite(getToken, odspUrlParts, logger, identityType === \"Consumer\");\n\n // ODC canonical link does not require any additional processing\n if (identityType === \"Consumer\") {\n return fileItem.webUrl;\n }\n\n // ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"odspFileLink\", requestName: \"getSharingLink\" },\n async (event) => {\n let attempts = 0;\n let additionalProps;\n const fileLink = await getWithRetryForTokenRefresh(async (options) => {\n attempts++;\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n logger,\n odspUrlParts,\n getToken,\n true /* throwOnNullToken */,\n );\n const storageToken = await storageTokenFetcher(options, \"GetFileLinkCore\");\n assert(storageToken !== null,\n 0x2bb /* \"Instrumented token fetcher with throwOnNullToken = true should never return null\" */);\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${odspUrlParts.siteUrl}/_api/web/GetFileByServerRelativeUrl(@a1)/Linkingurl?@a1=${\n encodeURIComponent(`'${new URL(fileItem.webDavUrl).pathname}'`)\n }`,\n storageToken,\n false,\n );\n const requestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json;odata=verbose\",\n \"Accept\": \"application/json;odata=verbose\",\n ...headers,\n },\n };\n const response = await fetchHelper(url, requestInit);\n additionalProps = response.propsToLog;\n\n const sharingInfo = await response.content.json();\n const linkingUrl = sharingInfo?.d?.LinkingUrl;\n if (typeof linkingUrl !== \"string\") {\n // This will retry once in getWithRetryForTokenRefresh\n throw new NonRetryableError(\n \"Malformed GetSharingLink response\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n return linkingUrl;\n });\n event.end({ ...additionalProps, attempts });\n return fileLink;\n },\n );\n}\n\n/**\n * This represents a lite version of file item containing only the webUrl and webDavUrl properties\n */\ninterface FileItemLite {\n webUrl: string;\n webDavUrl: string;\n}\n\nconst isFileItemLite = (maybeFileItemLite: any): maybeFileItemLite is FileItemLite => {\n if (typeof maybeFileItemLite.webUrl !== \"string\" || typeof maybeFileItemLite.webDavUrl !== \"string\") {\n return false;\n }\n return true;\n};\n\nasync function getFileItemLite(\n getToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n odspUrlParts: IOdspUrlParts,\n logger: ITelemetryLogger,\n forceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<FileItemLite> {\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"odspFileLink\", requestName: \"getFileItemLite\" },\n async (event) => {\n let attempts = 0;\n let additionalProps;\n const fileItem = await getWithRetryForTokenRefresh(async (options) => {\n attempts++;\n const { siteUrl, driveId, itemId } = odspUrlParts;\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n logger,\n odspUrlParts,\n getToken,\n true /* throwOnNullToken */,\n );\n const storageToken = await storageTokenFetcher(options, \"GetFileItemLite\");\n assert(storageToken !== null,\n 0x2bc /* \"Instrumented token fetcher with throwOnNullToken =true should never return null\" */);\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${siteUrl}/_api/v2.0/drives/${driveId}/items/${itemId}?select=webUrl,webDavUrl`,\n storageToken,\n forceAccessTokenViaAuthorizationHeader,\n );\n const requestInit = { method: \"GET\", headers };\n const response = await fetchHelper(url, requestInit);\n additionalProps = response.propsToLog;\n\n const responseJson = await response.content.json();\n if (!isFileItemLite(responseJson)) {\n // This will retry once in getWithRetryForTokenRefresh\n throw new NonRetryableError(\n \"Malformed getFileItemLite response\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n return responseJson;\n });\n event.end({ ...additionalProps, attempts });\n return fileItem;\n },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getFileLink.js","sourceRoot":"","sources":["../src/getFileLink.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC1G,OAAO,EAAE,g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AoC,EACpC,eAAe,CAAC,uBAAuB,EACvC,EAAE,aAAa,EAAE,CAAC,CAAC;aAC1B;YACD,OAAO,YAAY,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,GAAG,iCAAM,eAAe,KAAE,QAAQ,IAAG,CAAC;QAC5C,OAAO,QAAQ,CAAC;IACpB,CAAC,CACJ,CAAC;AACN,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, delay } from \"@fluidframework/common-utils\";\nimport { canRetryOnError, getRetryDelayFromError, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n IOdspUrlParts,\n OdspResourceTokenFetchOptions,\n IdentityType,\n TokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { fetchHelper, getWithRetryForTokenRefresh, toInstrumentedOdspTokenFetcher } from \"./odspUtils\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\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 siteUrl - url of the site that contains the file\n * @param driveId - drive where file is stored\n * @param itemId - file id\n * @param identityType - type of client account\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 getToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n odspUrlParts: IOdspUrlParts,\n identityType: IdentityType,\n logger: ITelemetryLogger,\n): Promise<string> {\n const cacheKey = `${odspUrlParts.siteUrl}_${odspUrlParts.driveId}_${odspUrlParts.itemId}`;\n const maybeFileLinkCacheEntry = fileLinkCache.get(cacheKey);\n if (maybeFileLinkCacheEntry !== undefined) {\n return maybeFileLinkCacheEntry;\n }\n\n const valueGenerator = async function() {\n let result: string | undefined;\n let success = false;\n let retryAfterMs = 1000;\n do {\n try {\n result = await getFileLinkCore(getToken, odspUrlParts, identityType, logger);\n success = true;\n } catch (err) {\n // If it is not retriable, then just throw\n if (!canRetryOnError(err)) {\n // Delete from the cache to permit retrying later.\n fileLinkCache.delete(cacheKey);\n throw err;\n }\n // If the error is throttling error, then wait for the specified time before retrying.\n // If the waitTime is not specified, then we start with retrying immediately to max of 8s.\n retryAfterMs = getRetryDelayFromError(err) ?? Math.min(retryAfterMs * 2, 8000);\n await delay(retryAfterMs);\n }\n } while (!success);\n\n // We are guaranteed to run the getFileLinkCore at least once with successful result (which must be a string)\n assert(result !== undefined, 0x292 /* \"Unexpected undefined result from getFileLinkCore\" */);\n return result;\n };\n const fileLink = valueGenerator();\n fileLinkCache.set(cacheKey, fileLink);\n return fileLink;\n}\n\nasync function getFileLinkCore(\n getToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n odspUrlParts: IOdspUrlParts,\n identityType: IdentityType,\n logger: ITelemetryLogger,\n): Promise<string> {\n const fileItem = await getFileItemLite(getToken, odspUrlParts, logger, identityType === \"Consumer\");\n\n // ODSP link requires extra call to return link that is resistant to file being renamed or moved to different folder\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"odspFileLink\", requestName: \"getSharingLink\" },\n async (event) => {\n let attempts = 0;\n let additionalProps;\n const fileLink = await getWithRetryForTokenRefresh(async (options) => {\n attempts++;\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n logger,\n odspUrlParts,\n getToken,\n true /* throwOnNullToken */,\n );\n const storageToken = await storageTokenFetcher(options, \"GetFileLinkCore\");\n assert(storageToken !== null,\n 0x2bb /* \"Instrumented token fetcher with throwOnNullToken = true should never return null\" */);\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${odspUrlParts.siteUrl}/_api/web/GetFileByServerRelativeUrl(@a1)/Linkingurl?@a1=${\n encodeURIComponent(`'${new URL(fileItem.webDavUrl).pathname}'`)\n }`,\n storageToken,\n false,\n );\n const requestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json;odata=verbose\",\n \"Accept\": \"application/json;odata=verbose\",\n ...headers,\n },\n };\n const response = await fetchHelper(url, requestInit);\n additionalProps = response.propsToLog;\n\n const sharingInfo = await response.content.json();\n const linkingUrl = sharingInfo?.d?.LinkingUrl;\n if (typeof linkingUrl !== \"string\") {\n // This will retry once in getWithRetryForTokenRefresh\n throw new NonRetryableError(\n \"Malformed GetSharingLink response\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n return linkingUrl;\n });\n event.end({ ...additionalProps, attempts });\n return fileLink;\n },\n );\n}\n\n/**\n * This represents a lite version of file item containing only the webUrl and webDavUrl properties\n */\ninterface FileItemLite {\n webUrl: string;\n webDavUrl: string;\n}\n\nconst isFileItemLite = (maybeFileItemLite: any): maybeFileItemLite is FileItemLite => {\n if (typeof maybeFileItemLite.webUrl !== \"string\" || typeof maybeFileItemLite.webDavUrl !== \"string\") {\n return false;\n }\n return true;\n};\n\nasync function getFileItemLite(\n getToken: TokenFetcher<OdspResourceTokenFetchOptions>,\n odspUrlParts: IOdspUrlParts,\n logger: ITelemetryLogger,\n forceAccessTokenViaAuthorizationHeader: boolean,\n): Promise<FileItemLite> {\n return PerformanceEvent.timedExecAsync(\n logger,\n { eventName: \"odspFileLink\", requestName: \"getFileItemLite\" },\n async (event) => {\n let attempts = 0;\n let additionalProps;\n const fileItem = await getWithRetryForTokenRefresh(async (options) => {\n attempts++;\n const { siteUrl, driveId, itemId } = odspUrlParts;\n const storageTokenFetcher = toInstrumentedOdspTokenFetcher(\n logger,\n odspUrlParts,\n getToken,\n true /* throwOnNullToken */,\n );\n const storageToken = await storageTokenFetcher(options, \"GetFileItemLite\");\n assert(storageToken !== null,\n 0x2bc /* \"Instrumented token fetcher with throwOnNullToken =true should never return null\" */);\n\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${siteUrl}/_api/v2.0/drives/${driveId}/items/${itemId}?select=webUrl,webDavUrl`,\n storageToken,\n forceAccessTokenViaAuthorizationHeader,\n );\n const requestInit = { method: \"GET\", headers };\n const response = await fetchHelper(url, requestInit);\n additionalProps = response.propsToLog;\n\n const responseJson = await response.content.json();\n if (!isFileItemLite(responseJson)) {\n // This will retry once in getWithRetryForTokenRefresh\n throw new NonRetryableError(\n \"Malformed getFileItemLite response\",\n DriverErrorType.incorrectServerResponse,\n { driverVersion });\n }\n return responseJson;\n });\n event.end({ ...additionalProps, attempts });\n return fileItem;\n },\n );\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
6
|
+
import { IDocumentDeltaStorageService, IDocumentService, IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
|
|
7
|
+
import { IOdspResolvedUrl } from "@fluidframework/odsp-driver-definitions";
|
|
8
|
+
import { IClient } from "@fluidframework/protocol-definitions";
|
|
9
|
+
/**
|
|
10
|
+
* IDocumentService implementation that provides explicit snapshot to the document storage service.
|
|
11
|
+
*/
|
|
12
|
+
export declare class LocalOdspDocumentService implements IDocumentService {
|
|
13
|
+
private readonly odspResolvedUrl;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
private readonly localSnapshot;
|
|
16
|
+
policies: {
|
|
17
|
+
storageOnly: boolean;
|
|
18
|
+
};
|
|
19
|
+
constructor(odspResolvedUrl: IOdspResolvedUrl, logger: ITelemetryLogger, localSnapshot: Uint8Array | string);
|
|
20
|
+
get resolvedUrl(): IResolvedUrl;
|
|
21
|
+
connectToStorage(): Promise<IDocumentStorageService>;
|
|
22
|
+
connectToDeltaStorage(): Promise<IDocumentDeltaStorageService>;
|
|
23
|
+
connectToDeltaStream(_client: IClient): never;
|
|
24
|
+
dispose(_error?: any): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=localOdspDocumentService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localOdspDocumentService.d.ts","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EACH,4BAA4B,EAC5B,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAG/D;;GAEG;AACH,qBAAa,wBAAyB,YAAW,gBAAgB;IAIzD,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAL3B,QAAQ;;MAAyB;gBAGnB,eAAe,EAAE,gBAAgB,EACjC,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,UAAU,GAAG,MAAM;IAGvD,IAAW,WAAW,IAAI,YAAY,CAErC;IAEY,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAOpD,qBAAqB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAIpE,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK;IAM7C,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,IAAI;CAGrC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { UsageError, EmptyDocumentDeltaStorageService } from "@fluidframework/driver-utils";
|
|
6
|
+
import { LocalOdspDocumentStorageService } from "./localOdspDocumentStorageManager";
|
|
7
|
+
/**
|
|
8
|
+
* IDocumentService implementation that provides explicit snapshot to the document storage service.
|
|
9
|
+
*/
|
|
10
|
+
export class LocalOdspDocumentService {
|
|
11
|
+
constructor(odspResolvedUrl, logger, localSnapshot) {
|
|
12
|
+
this.odspResolvedUrl = odspResolvedUrl;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.localSnapshot = localSnapshot;
|
|
15
|
+
this.policies = { storageOnly: true };
|
|
16
|
+
}
|
|
17
|
+
get resolvedUrl() {
|
|
18
|
+
return this.odspResolvedUrl;
|
|
19
|
+
}
|
|
20
|
+
async connectToStorage() {
|
|
21
|
+
return new LocalOdspDocumentStorageService(this.logger, this.localSnapshot);
|
|
22
|
+
}
|
|
23
|
+
async connectToDeltaStorage() {
|
|
24
|
+
return new EmptyDocumentDeltaStorageService();
|
|
25
|
+
}
|
|
26
|
+
connectToDeltaStream(_client) {
|
|
27
|
+
const toThrow = new UsageError("\"connectToDeltaStream\" is not supported by LocalOdspDocumentService");
|
|
28
|
+
this.logger.sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
|
|
29
|
+
throw toThrow;
|
|
30
|
+
}
|
|
31
|
+
dispose(_error) {
|
|
32
|
+
// Do nothing
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=localOdspDocumentService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localOdspDocumentService.js","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,UAAU,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAG5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAEpF;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAGjC,YACqB,eAAiC,EACjC,MAAwB,EACxB,aAAkC;QAFlC,oBAAe,GAAf,eAAe,CAAkB;QACjC,WAAM,GAAN,MAAM,CAAkB;QACxB,kBAAa,GAAb,aAAa,CAAqB;QALhD,aAAQ,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAMpC,CAAC;IAEL,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,gBAAgB;QACzB,OAAO,IAAI,+BAA+B,CACtC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,CACrB,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAC9B,OAAO,IAAI,gCAAgC,EAAE,CAAC;IAClD,CAAC;IAEM,oBAAoB,CAAC,OAAgB;QACxC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,uEAAuE,CAAC,CAAC;QACxG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,OAAO,CAAC;IAClB,CAAC;IAEM,OAAO,CAAC,MAAY;QACvB,aAAa;IACjB,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n IDocumentDeltaStorageService,\n IDocumentService,\n IDocumentStorageService,\n IResolvedUrl,\n} from \"@fluidframework/driver-definitions\";\nimport { UsageError, EmptyDocumentDeltaStorageService } from \"@fluidframework/driver-utils\";\nimport { IOdspResolvedUrl } from \"@fluidframework/odsp-driver-definitions\";\nimport { IClient } from \"@fluidframework/protocol-definitions\";\nimport { LocalOdspDocumentStorageService } from \"./localOdspDocumentStorageManager\";\n\n/**\n * IDocumentService implementation that provides explicit snapshot to the document storage service.\n */\nexport class LocalOdspDocumentService implements IDocumentService {\n public policies = { storageOnly: true };\n\n constructor(\n private readonly odspResolvedUrl: IOdspResolvedUrl,\n private readonly logger: ITelemetryLogger,\n private readonly localSnapshot: Uint8Array | string,\n ) { }\n\n public get resolvedUrl(): IResolvedUrl {\n return this.odspResolvedUrl;\n }\n\n public async connectToStorage(): Promise<IDocumentStorageService> {\n return new LocalOdspDocumentStorageService(\n this.logger,\n this.localSnapshot,\n );\n }\n\n public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n return new EmptyDocumentDeltaStorageService();\n }\n\n public connectToDeltaStream(_client: IClient): never {\n const toThrow = new UsageError(\"\\\"connectToDeltaStream\\\" is not supported by LocalOdspDocumentService\");\n this.logger.sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n\n public dispose(_error?: any): void {\n // Do nothing\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDocumentService, IResolvedUrl } from "@fluidframework/driver-definitions";
|
|
6
|
+
import { TelemetryLogger } from "@fluidframework/telemetry-utils";
|
|
7
|
+
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
8
|
+
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
|
|
9
|
+
import { ICacheAndTracker } from "../epochTracker";
|
|
10
|
+
import { OdspDocumentServiceFactoryCore } from "../odspDocumentServiceFactoryCore";
|
|
11
|
+
/**
|
|
12
|
+
* Factory for creating sharepoint document service with a provided snapshot.
|
|
13
|
+
* Use if you don't want to connect to any kind of external/internal storages and want to provide
|
|
14
|
+
* content directly.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LocalOdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore {
|
|
17
|
+
private readonly localSnapshot;
|
|
18
|
+
private logger;
|
|
19
|
+
constructor(localSnapshot: Uint8Array | string);
|
|
20
|
+
private throwUnsupportedUsageError;
|
|
21
|
+
createContainer(_createNewSummary: ISummaryTree | undefined, _createNewResolvedUrl: IResolvedUrl, logger?: ITelemetryBaseLogger, _clientIsSummarizer?: boolean): never;
|
|
22
|
+
protected createDocumentServiceCore(resolvedUrl: IResolvedUrl, odspLogger: TelemetryLogger, _cacheAndTrackerArg?: ICacheAndTracker, _clientIsSummarizer?: boolean): Promise<IDocumentService>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=localOdspDocumentServiceFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localOdspDocumentServiceFactory.d.ts","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAGnF;;;;GAIG;AACH,qBAAa,+BAAgC,SAAQ,8BAA8B;IAI3E,OAAO,CAAC,QAAQ,CAAC,aAAa;IAHlC,OAAO,CAAC,MAAM,CAA8B;gBAGvB,aAAa,EAAE,UAAU,GAAG,MAAM;IASvD,OAAO,CAAC,0BAA0B;IAO3B,eAAe,CAClB,iBAAiB,EAAE,YAAY,GAAG,SAAS,EAC3C,qBAAqB,EAAE,YAAY,EACnC,MAAM,CAAC,EAAE,oBAAoB,EAC7B,mBAAmB,CAAC,EAAE,OAAO,GAC9B,KAAK;cAMQ,yBAAyB,CACrC,WAAW,EAAE,YAAY,EACzB,UAAU,EAAE,eAAe,EAC3B,mBAAmB,CAAC,EAAE,gBAAgB,EACtC,mBAAmB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,gBAAgB,CAAC;CAU/B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { UsageError } from "@fluidframework/driver-utils";
|
|
6
|
+
import { createOdspLogger, getOdspResolvedUrl } from "../odspUtils";
|
|
7
|
+
import { OdspDocumentServiceFactoryCore } from "../odspDocumentServiceFactoryCore";
|
|
8
|
+
import { LocalOdspDocumentService } from "./localOdspDocumentService";
|
|
9
|
+
/**
|
|
10
|
+
* Factory for creating sharepoint document service with a provided snapshot.
|
|
11
|
+
* Use if you don't want to connect to any kind of external/internal storages and want to provide
|
|
12
|
+
* content directly.
|
|
13
|
+
*/
|
|
14
|
+
export class LocalOdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore {
|
|
15
|
+
constructor(localSnapshot) {
|
|
16
|
+
super((_options) => this.throwUnsupportedUsageError("Getting storage token"), (_options) => this.throwUnsupportedUsageError("Getting websocket token"), () => this.throwUnsupportedUsageError("Getting SocketIO Client"));
|
|
17
|
+
this.localSnapshot = localSnapshot;
|
|
18
|
+
}
|
|
19
|
+
throwUnsupportedUsageError(unsupportedFuncName) {
|
|
20
|
+
var _a;
|
|
21
|
+
const toThrow = new UsageError(`${unsupportedFuncName} is not supported by LocalOdspDocumentServiceFactory`);
|
|
22
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
|
|
23
|
+
throw toThrow;
|
|
24
|
+
}
|
|
25
|
+
createContainer(_createNewSummary, _createNewResolvedUrl, logger, _clientIsSummarizer) {
|
|
26
|
+
const toThrow = new UsageError("\"createContainer\" is not supported by LocalOdspDocumentServiceFactory");
|
|
27
|
+
createOdspLogger(logger).sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
|
|
28
|
+
throw toThrow;
|
|
29
|
+
}
|
|
30
|
+
async createDocumentServiceCore(resolvedUrl, odspLogger, _cacheAndTrackerArg, _clientIsSummarizer) {
|
|
31
|
+
if (_cacheAndTrackerArg !== undefined) {
|
|
32
|
+
throw new UsageError("Invalid usage. \"_cacheAndTrackerArg\" should not be provided");
|
|
33
|
+
}
|
|
34
|
+
if (_clientIsSummarizer) {
|
|
35
|
+
throw new UsageError("Invalid usage. \"_clientIsSummarizer\" should not be provided");
|
|
36
|
+
}
|
|
37
|
+
this.logger = odspLogger;
|
|
38
|
+
return new LocalOdspDocumentService(getOdspResolvedUrl(resolvedUrl), odspLogger, this.localSnapshot);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=localOdspDocumentServiceFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localOdspDocumentServiceFactory.js","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAI1D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;GAIG;AACH,MAAM,OAAO,+BAAgC,SAAQ,8BAA8B;IAG/E,YACqB,aAAkC;QAEnD,KAAK,CACD,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,uBAAuB,CAAC,EACtE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EACxE,GAAG,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,CACnE,CAAC;QANe,kBAAa,GAAb,aAAa,CAAqB;IAOvD,CAAC;IAEO,0BAA0B,CAAC,mBAA2B;;QAC1D,MAAM,OAAO,GAAG,IAAI,UAAU,CAC1B,GAAG,mBAAmB,sDAAsD,CAAC,CAAC;QAClF,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACxE,MAAM,OAAO,CAAC;IAClB,CAAC;IAEM,eAAe,CAClB,iBAA2C,EAC3C,qBAAmC,EACnC,MAA6B,EAC7B,mBAA6B;QAE7B,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,yEAAyE,CAAC,CAAC;QAC1G,gBAAgB,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,OAAO,CAAC,CAAC;QACpF,MAAM,OAAO,CAAC;IAClB,CAAC;IAES,KAAK,CAAC,yBAAyB,CACrC,WAAyB,EACzB,UAA2B,EAC3B,mBAAsC,EACtC,mBAA6B;QAE7B,IAAI,mBAAmB,KAAK,SAAS,EAAE;YACnC,MAAM,IAAI,UAAU,CAAC,+DAA+D,CAAC,CAAC;SACzF;QACD,IAAI,mBAAmB,EAAE;YACrB,MAAM,IAAI,UAAU,CAAC,+DAA+D,CAAC,CAAC;SACzF;QACD,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;QACzB,OAAO,IAAI,wBAAwB,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACzG,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDocumentService, IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport { UsageError } from \"@fluidframework/driver-utils\";\nimport { TelemetryLogger } from \"@fluidframework/telemetry-utils\";\nimport { ISummaryTree } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport { createOdspLogger, getOdspResolvedUrl } from \"../odspUtils\";\nimport { ICacheAndTracker } from \"../epochTracker\";\nimport { OdspDocumentServiceFactoryCore } from \"../odspDocumentServiceFactoryCore\";\nimport { LocalOdspDocumentService } from \"./localOdspDocumentService\";\n\n/**\n * Factory for creating sharepoint document service with a provided snapshot.\n * Use if you don't want to connect to any kind of external/internal storages and want to provide\n * content directly.\n */\nexport class LocalOdspDocumentServiceFactory extends OdspDocumentServiceFactoryCore {\n private logger: TelemetryLogger | undefined;\n\n constructor(\n private readonly localSnapshot: Uint8Array | string,\n ) {\n super(\n (_options) => this.throwUnsupportedUsageError(\"Getting storage token\"),\n (_options) => this.throwUnsupportedUsageError(\"Getting websocket token\"),\n () => this.throwUnsupportedUsageError(\"Getting SocketIO Client\"),\n );\n }\n\n private throwUnsupportedUsageError(unsupportedFuncName: string): never {\n const toThrow = new UsageError(\n `${unsupportedFuncName} is not supported by LocalOdspDocumentServiceFactory`);\n this.logger?.sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n\n public createContainer(\n _createNewSummary: ISummaryTree | undefined,\n _createNewResolvedUrl: IResolvedUrl,\n logger?: ITelemetryBaseLogger,\n _clientIsSummarizer?: boolean,\n ): never {\n const toThrow = new UsageError(\"\\\"createContainer\\\" is not supported by LocalOdspDocumentServiceFactory\");\n createOdspLogger(logger).sendErrorEvent({ eventName: \"UnsupportedUsage\" }, toThrow);\n throw toThrow;\n }\n\n protected async createDocumentServiceCore(\n resolvedUrl: IResolvedUrl,\n odspLogger: TelemetryLogger,\n _cacheAndTrackerArg?: ICacheAndTracker,\n _clientIsSummarizer?: boolean,\n ): Promise<IDocumentService> {\n if (_cacheAndTrackerArg !== undefined) {\n throw new UsageError(\"Invalid usage. \\\"_cacheAndTrackerArg\\\" should not be provided\");\n }\n if (_clientIsSummarizer) {\n throw new UsageError(\"Invalid usage. \\\"_clientIsSummarizer\\\" should not be provided\");\n }\n this.logger = odspLogger;\n return new LocalOdspDocumentService(getOdspResolvedUrl(resolvedUrl), odspLogger, this.localSnapshot);\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
6
|
+
import { ISummaryContext } from "@fluidframework/driver-definitions";
|
|
7
|
+
import * as api from "@fluidframework/protocol-definitions";
|
|
8
|
+
import { OdspDocumentStorageServiceBase } from "../odspDocumentStorageServiceBase";
|
|
9
|
+
/**
|
|
10
|
+
* ODSP document storage service that works on a provided snapshot for all its processing.
|
|
11
|
+
* Attempting to use unsupported actions/methods will result in errors being thrown.
|
|
12
|
+
*/
|
|
13
|
+
export declare class LocalOdspDocumentStorageService extends OdspDocumentStorageServiceBase {
|
|
14
|
+
private readonly logger;
|
|
15
|
+
private readonly localSnapshot;
|
|
16
|
+
private snapshotTreeId;
|
|
17
|
+
constructor(logger: ITelemetryLogger, localSnapshot: Uint8Array | string);
|
|
18
|
+
private calledGetVersions;
|
|
19
|
+
getVersions(blobid: string | null, count: number, _scenarioName?: string): Promise<api.IVersion[]>;
|
|
20
|
+
private getSnapshotVersion;
|
|
21
|
+
protected fetchTreeFromSnapshot(_id: string, _scenarioName?: string): never;
|
|
22
|
+
protected fetchBlobFromStorage(_blobId: string, _evicted: boolean): never;
|
|
23
|
+
uploadSummaryWithContext(_summary: api.ISummaryTree, _context: ISummaryContext): never;
|
|
24
|
+
createBlob(_file: ArrayBufferLike): never;
|
|
25
|
+
private throwUsageError;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=localOdspDocumentStorageManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localOdspDocumentStorageManager.d.ts","sourceRoot":"","sources":["../../src/localOdspDriver/localOdspDocumentStorageManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AAOnF;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,8BAA8B;IAI3E,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAJlC,OAAO,CAAC,cAAc,CAAqB;gBAGtB,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,UAAU,GAAG,MAAM;IAKvD,OAAO,CAAC,iBAAiB,CAAS;IAErB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAwB/G,OAAO,CAAC,kBAAkB;IAI1B,SAAS,CAAC,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK;IAI3E,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,KAAK;IAIlE,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,QAAQ,EAAE,eAAe,GAAG,KAAK;IAItF,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK;IAIhD,OAAO,CAAC,eAAe;CAK1B"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { assert } from "@fluidframework/common-utils";
|
|
6
|
+
import { UsageError } from "@fluidframework/driver-utils";
|
|
7
|
+
import { OdspDocumentStorageServiceBase } from "../odspDocumentStorageServiceBase";
|
|
8
|
+
import { convertOdspSnapshotToSnapshotTreeAndBlobs } from "../odspSnapshotParser";
|
|
9
|
+
import { parseCompactSnapshotResponse } from "../compactSnapshotParser";
|
|
10
|
+
import { ReadBuffer } from "../ReadBufferUtils";
|
|
11
|
+
/**
|
|
12
|
+
* ODSP document storage service that works on a provided snapshot for all its processing.
|
|
13
|
+
* Attempting to use unsupported actions/methods will result in errors being thrown.
|
|
14
|
+
*/
|
|
15
|
+
export class LocalOdspDocumentStorageService extends OdspDocumentStorageServiceBase {
|
|
16
|
+
constructor(logger, localSnapshot) {
|
|
17
|
+
super();
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
this.localSnapshot = localSnapshot;
|
|
20
|
+
this.calledGetVersions = false;
|
|
21
|
+
}
|
|
22
|
+
async getVersions(blobid, count, _scenarioName) {
|
|
23
|
+
assert(blobid === null, 0x342 /* Invalid usage. "blobid" should always be null */);
|
|
24
|
+
assert(count === 1, 0x343 /* Invalid usage. "count" should always be 1 */);
|
|
25
|
+
// No reason to re-parse the data since it will never change
|
|
26
|
+
if (this.calledGetVersions) {
|
|
27
|
+
return this.getSnapshotVersion();
|
|
28
|
+
}
|
|
29
|
+
this.calledGetVersions = true;
|
|
30
|
+
let snapshotContents;
|
|
31
|
+
if (typeof this.localSnapshot === "string") {
|
|
32
|
+
const content = JSON.parse(this.localSnapshot);
|
|
33
|
+
snapshotContents = convertOdspSnapshotToSnapshotTreeAndBlobs(content);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
snapshotContents = parseCompactSnapshotResponse(new ReadBuffer(this.localSnapshot));
|
|
37
|
+
}
|
|
38
|
+
this.snapshotTreeId = this.initializeFromSnapshot(snapshotContents);
|
|
39
|
+
return this.getSnapshotVersion();
|
|
40
|
+
}
|
|
41
|
+
getSnapshotVersion() {
|
|
42
|
+
return this.snapshotTreeId ? [{ id: this.snapshotTreeId, treeId: undefined }] : [];
|
|
43
|
+
}
|
|
44
|
+
fetchTreeFromSnapshot(_id, _scenarioName) {
|
|
45
|
+
this.throwUsageError("fetchTreeFromSnapshot");
|
|
46
|
+
}
|
|
47
|
+
fetchBlobFromStorage(_blobId, _evicted) {
|
|
48
|
+
this.throwUsageError("fetchBlobFromStorage");
|
|
49
|
+
}
|
|
50
|
+
uploadSummaryWithContext(_summary, _context) {
|
|
51
|
+
this.throwUsageError("uploadSummaryWithContext");
|
|
52
|
+
}
|
|
53
|
+
createBlob(_file) {
|
|
54
|
+
this.throwUsageError("createBlob");
|
|
55
|
+
}
|
|
56
|
+
throwUsageError(methodName) {
|
|
57
|
+
const toThrow = new UsageError(`"${methodName}" is not supported by LocalOdspDocumentStorageService`);
|
|
58
|
+
this.logger.sendErrorEvent({ eventName: "UnsupportedUsage" }, toThrow);
|
|
59
|
+
throw toThrow;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=localOdspDocumentStorageManager.js.map
|