@fluidframework/routerlicious-driver 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229
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/.eslintrc.js +10 -12
- package/.mocharc.js +2 -2
- package/README.md +1 -1
- package/api-extractor.json +2 -2
- package/dist/cache.d.ts +3 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +6 -4
- package/dist/cache.js.map +1 -1
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +4 -2
- package/dist/createNewUtils.js.map +1 -1
- package/dist/defaultTokenProvider.d.ts.map +1 -1
- package/dist/defaultTokenProvider.js.map +1 -1
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js.map +1 -1
- package/dist/deltaStorageService.d.ts.map +1 -1
- package/dist/deltaStorageService.js +4 -1
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentDeltaConnection.d.ts.map +1 -1
- package/dist/documentDeltaConnection.js.map +1 -1
- package/dist/documentService.d.ts +4 -2
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +28 -41
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts +0 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +26 -13
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +1 -1
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +8 -6
- package/dist/documentStorageService.js.map +1 -1
- package/dist/errorUtils.d.ts +11 -3
- package/dist/errorUtils.d.ts.map +1 -1
- package/dist/errorUtils.js +19 -6
- package/dist/errorUtils.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/mapWithExpiration.d.ts +34 -0
- package/dist/mapWithExpiration.d.ts.map +1 -0
- package/dist/mapWithExpiration.js +105 -0
- package/dist/mapWithExpiration.js.map +1 -0
- package/dist/nullBlobStorageService.d.ts.map +1 -1
- package/dist/nullBlobStorageService.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/policies.d.ts.map +1 -1
- package/dist/policies.js.map +1 -1
- package/dist/restWrapper.d.ts +8 -5
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +38 -44
- package/dist/restWrapper.js.map +1 -1
- package/dist/retriableGitManager.d.ts.map +1 -1
- package/dist/retriableGitManager.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +9 -5
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/tokens.d.ts +24 -7
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js.map +1 -1
- package/dist/treeUtils.d.ts +51 -0
- package/dist/treeUtils.d.ts.map +1 -0
- package/dist/treeUtils.js +85 -0
- package/dist/treeUtils.js.map +1 -0
- package/dist/urlUtils.d.ts.map +1 -1
- package/dist/urlUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +30 -17
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/cache.d.ts +3 -0
- package/lib/cache.d.ts.map +1 -1
- package/lib/cache.js +6 -4
- package/lib/cache.js.map +1 -1
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +4 -2
- package/lib/createNewUtils.js.map +1 -1
- package/lib/defaultTokenProvider.d.ts.map +1 -1
- package/lib/defaultTokenProvider.js.map +1 -1
- package/lib/definitions.d.ts.map +1 -1
- package/lib/definitions.js.map +1 -1
- package/lib/deltaStorageService.d.ts.map +1 -1
- package/lib/deltaStorageService.js +4 -1
- package/lib/deltaStorageService.js.map +1 -1
- package/lib/documentDeltaConnection.d.ts.map +1 -1
- package/lib/documentDeltaConnection.js.map +1 -1
- package/lib/documentService.d.ts +4 -2
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +30 -24
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts +0 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +27 -14
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts +1 -1
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +9 -7
- package/lib/documentStorageService.js.map +1 -1
- package/lib/errorUtils.d.ts +11 -3
- package/lib/errorUtils.d.ts.map +1 -1
- package/lib/errorUtils.js +18 -5
- package/lib/errorUtils.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/mapWithExpiration.d.ts +34 -0
- package/lib/mapWithExpiration.d.ts.map +1 -0
- package/lib/mapWithExpiration.js +101 -0
- package/lib/mapWithExpiration.js.map +1 -0
- package/lib/nullBlobStorageService.d.ts.map +1 -1
- package/lib/nullBlobStorageService.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/policies.d.ts.map +1 -1
- package/lib/policies.js.map +1 -1
- package/lib/restWrapper.d.ts +8 -5
- package/lib/restWrapper.d.ts.map +1 -1
- package/lib/restWrapper.js +38 -44
- package/lib/restWrapper.js.map +1 -1
- package/lib/retriableGitManager.d.ts.map +1 -1
- package/lib/retriableGitManager.js.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +10 -6
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/tokens.d.ts +24 -7
- package/lib/tokens.d.ts.map +1 -1
- package/lib/tokens.js.map +1 -1
- package/lib/treeUtils.d.ts +51 -0
- package/lib/treeUtils.d.ts.map +1 -0
- package/lib/treeUtils.js +80 -0
- package/lib/treeUtils.js.map +1 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +30 -17
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +55 -52
- package/prettier.config.cjs +1 -1
- package/src/cache.ts +21 -14
- package/src/createNewUtils.ts +24 -22
- package/src/defaultTokenProvider.ts +13 -15
- package/src/definitions.ts +2 -2
- package/src/deltaStorageService.ts +99 -95
- package/src/documentDeltaConnection.ts +53 -47
- package/src/documentService.ts +260 -241
- package/src/documentServiceFactory.ts +268 -237
- package/src/documentStorageService.ts +87 -83
- package/src/errorUtils.ts +91 -76
- package/src/index.ts +7 -1
- package/src/mapWithExpiration.ts +124 -0
- package/src/nullBlobStorageService.ts +24 -21
- package/src/packageVersion.ts +1 -1
- package/src/policies.ts +44 -44
- package/src/restWrapper.ts +270 -208
- package/src/retriableGitManager.ts +152 -151
- package/src/shreddedSummaryDocumentStorageService.ts +202 -194
- package/src/tokens.ts +69 -44
- package/src/treeUtils.ts +107 -0
- package/src/urlUtils.ts +26 -23
- package/src/wholeSummaryDocumentStorageService.ts +248 -228
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
package/src/policies.ts
CHANGED
|
@@ -4,48 +4,48 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export interface IRouterliciousDriverPolicies {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Enable prefetching entire snapshot tree into memory before it is loaded by the runtime.
|
|
9
|
+
* Default: true
|
|
10
|
+
*/
|
|
11
|
+
enablePrefetch: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Rate limit concurrent storage requests.
|
|
14
|
+
* Default: 100
|
|
15
|
+
*/
|
|
16
|
+
maxConcurrentStorageRequests: number;
|
|
17
|
+
/**
|
|
18
|
+
* Rate limit concurrent orderer requests.
|
|
19
|
+
* Default: 100
|
|
20
|
+
*/
|
|
21
|
+
maxConcurrentOrdererRequests: number;
|
|
22
|
+
/**
|
|
23
|
+
* Give hosts the option to change blob aggregation behavior to suit their needs.
|
|
24
|
+
* Larger number means fewer blob individual requests, but less blob-deduping.
|
|
25
|
+
* Smaller number means more blob individual requests, but more blob-deduping.
|
|
26
|
+
* Setting to `undefined` disables blob aggregration.
|
|
27
|
+
* Default: undefined
|
|
28
|
+
*/
|
|
29
|
+
aggregateBlobsSmallerThanBytes: number | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Enable uploading entire summary tree as a IWholeSummaryPayload to storage.
|
|
32
|
+
* Default: false
|
|
33
|
+
*/
|
|
34
|
+
enableWholeSummaryUpload: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Enable service endpoint discovery when creating or joining a session.
|
|
37
|
+
* Default: false
|
|
38
|
+
*/
|
|
39
|
+
enableDiscovery?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Enable using RestLess which avoids CORS preflight requests.
|
|
42
|
+
* Default: true
|
|
43
|
+
*/
|
|
44
|
+
enableRestLess: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Enable internal cache of summaries/snapshots.
|
|
47
|
+
* Reduces Summarizer boot time and reduces server load in E2E tests.
|
|
48
|
+
* Default: true
|
|
49
|
+
*/
|
|
50
|
+
enableInternalSummaryCaching: boolean;
|
|
51
51
|
}
|
package/src/restWrapper.ts
CHANGED
|
@@ -11,9 +11,9 @@ import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
|
11
11
|
import { fromUtf8ToBase64 } from "@fluidframework/common-utils";
|
|
12
12
|
import { RateLimiter } from "@fluidframework/driver-utils";
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
getAuthorizationTokenFromCredentials,
|
|
15
|
+
RestLessClient,
|
|
16
|
+
RestWrapper,
|
|
17
17
|
} from "@fluidframework/server-services-client";
|
|
18
18
|
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
19
19
|
import fetch from "cross-fetch";
|
|
@@ -21,220 +21,282 @@ import type { AxiosRequestConfig, AxiosRequestHeaders } from "axios";
|
|
|
21
21
|
import safeStringify from "json-stringify-safe";
|
|
22
22
|
import { v4 as uuid } from "uuid";
|
|
23
23
|
import { throwR11sNetworkError } from "./errorUtils";
|
|
24
|
-
import { ITokenProvider } from "./tokens";
|
|
24
|
+
import { ITokenProvider, ITokenResponse } from "./tokens";
|
|
25
25
|
import { pkgVersion as driverVersion } from "./packageVersion";
|
|
26
26
|
|
|
27
|
-
type AuthorizationHeaderGetter = (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
type AuthorizationHeaderGetter = (token: ITokenResponse) => string;
|
|
28
|
+
type TokenFetcher = (refresh?: boolean) => Promise<ITokenResponse>;
|
|
29
|
+
|
|
30
|
+
const axiosRequestConfigToFetchRequestConfig = (
|
|
31
|
+
requestConfig: AxiosRequestConfig,
|
|
32
|
+
): [RequestInfo, RequestInit] => {
|
|
33
|
+
const requestInfo: string =
|
|
34
|
+
requestConfig.baseURL !== undefined
|
|
35
|
+
? `${requestConfig.baseURL}${requestConfig.url ?? ""}`
|
|
36
|
+
: requestConfig.url ?? "";
|
|
37
|
+
const requestInit: RequestInit = {
|
|
38
|
+
method: requestConfig.method,
|
|
39
|
+
// NOTE: I believe that although the Axios type permits non-string values in the header, here we are
|
|
40
|
+
// guaranteed the requestConfig only has string values in its header.
|
|
41
|
+
headers: requestConfig.headers as Record<string, string>,
|
|
42
|
+
body: requestConfig.data,
|
|
43
|
+
};
|
|
44
|
+
return [requestInfo, requestInit];
|
|
41
45
|
};
|
|
42
46
|
|
|
43
47
|
export class RouterliciousRestWrapper extends RestWrapper {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
48
|
+
private readonly restLess = new RestLessClient();
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
logger: ITelemetryLogger,
|
|
52
|
+
private readonly rateLimiter: RateLimiter,
|
|
53
|
+
private token: ITokenResponse,
|
|
54
|
+
private readonly fetchRefreshedToken: TokenFetcher,
|
|
55
|
+
private readonly getAuthorizationHeader: AuthorizationHeaderGetter,
|
|
56
|
+
private readonly useRestLess: boolean,
|
|
57
|
+
baseurl?: string,
|
|
58
|
+
defaultQueryString: ParsedUrlQueryInput = {},
|
|
59
|
+
) {
|
|
60
|
+
super(baseurl, defaultQueryString);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected async request<T>(
|
|
64
|
+
requestConfig: AxiosRequestConfig,
|
|
65
|
+
statusCode: number,
|
|
66
|
+
canRetry = true,
|
|
67
|
+
): Promise<T> {
|
|
68
|
+
const config = {
|
|
69
|
+
...requestConfig,
|
|
70
|
+
headers: this.generateHeaders(requestConfig.headers),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const translatedConfig = this.useRestLess ? this.restLess.translate(config) : config;
|
|
74
|
+
const fetchRequestConfig = axiosRequestConfigToFetchRequestConfig(translatedConfig);
|
|
75
|
+
|
|
76
|
+
const response: Response = await this.rateLimiter.schedule(async () =>
|
|
77
|
+
fetch(...fetchRequestConfig).catch(async (error) => {
|
|
78
|
+
// Browser Fetch throws a TypeError on network error, `node-fetch` throws a FetchError
|
|
79
|
+
const isNetworkError = ["TypeError", "FetchError"].includes(error?.name);
|
|
80
|
+
throwR11sNetworkError(
|
|
81
|
+
isNetworkError ? `NetworkError: ${error.message}` : safeStringify(error),
|
|
82
|
+
);
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const responseBody: any = response.headers.get("content-type")?.includes("application/json")
|
|
87
|
+
? await response.json()
|
|
88
|
+
: await response.text();
|
|
89
|
+
|
|
90
|
+
// Success
|
|
91
|
+
if (response.ok || response.status === statusCode) {
|
|
92
|
+
const result: T = responseBody;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
// Failure
|
|
96
|
+
if (response.status === 401 && canRetry) {
|
|
97
|
+
// Refresh Authorization header and retry once
|
|
98
|
+
this.token = await this.fetchRefreshedToken(true /* refreshToken */);
|
|
99
|
+
return this.request<T>(config, statusCode, false);
|
|
100
|
+
}
|
|
101
|
+
if (response.status === 429 && responseBody?.retryAfter > 0) {
|
|
102
|
+
// Retry based on retryAfter[Seconds]
|
|
103
|
+
return new Promise<T>((resolve, reject) =>
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
this.request<T>(config, statusCode).then(resolve).catch(reject);
|
|
106
|
+
}, responseBody.retryAfter * 1000),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const responseSummary =
|
|
111
|
+
responseBody !== undefined
|
|
112
|
+
? typeof responseBody === "string"
|
|
113
|
+
? responseBody
|
|
114
|
+
: safeStringify(responseBody)
|
|
115
|
+
: response.statusText;
|
|
116
|
+
throwR11sNetworkError(
|
|
117
|
+
`R11s fetch error: ${responseSummary}`,
|
|
118
|
+
response.status,
|
|
119
|
+
responseBody?.retryAfter,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private generateHeaders(
|
|
124
|
+
requestHeaders?: AxiosRequestHeaders | undefined,
|
|
125
|
+
): Record<string, string> {
|
|
126
|
+
const correlationId = requestHeaders?.["x-correlation-id"] ?? uuid();
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...requestHeaders,
|
|
130
|
+
// TODO: replace header names with CorrelationIdHeaderName and DriverVersionHeaderName from services-client
|
|
131
|
+
// NOTE: Can correlationId actually be number | true?
|
|
132
|
+
"x-correlation-id": correlationId as string,
|
|
133
|
+
"x-driver-version": driverVersion,
|
|
134
|
+
// NOTE: If this.authorizationHeader is undefined, should "Authorization" be removed entirely?
|
|
135
|
+
"Authorization": this.getAuthorizationHeader(this.token),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public getToken(): ITokenResponse {
|
|
140
|
+
return this.token;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public setToken(token: ITokenResponse) {
|
|
144
|
+
this.token = token;
|
|
145
|
+
}
|
|
126
146
|
}
|
|
127
147
|
|
|
128
148
|
export class RouterliciousStorageRestWrapper extends RouterliciousRestWrapper {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
149
|
+
private constructor(
|
|
150
|
+
logger: ITelemetryLogger,
|
|
151
|
+
rateLimiter: RateLimiter,
|
|
152
|
+
token: ITokenResponse,
|
|
153
|
+
fetchToken: TokenFetcher,
|
|
154
|
+
getAuthorizationHeader: AuthorizationHeaderGetter,
|
|
155
|
+
useRestLess: boolean,
|
|
156
|
+
baseurl?: string,
|
|
157
|
+
defaultQueryString: ParsedUrlQueryInput = {},
|
|
158
|
+
) {
|
|
159
|
+
super(
|
|
160
|
+
logger,
|
|
161
|
+
rateLimiter,
|
|
162
|
+
token,
|
|
163
|
+
fetchToken,
|
|
164
|
+
getAuthorizationHeader,
|
|
165
|
+
useRestLess,
|
|
166
|
+
baseurl,
|
|
167
|
+
defaultQueryString,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public static async load(
|
|
172
|
+
tenantId: string,
|
|
173
|
+
documentId: string,
|
|
174
|
+
tokenProvider: ITokenProvider,
|
|
175
|
+
logger: ITelemetryLogger,
|
|
176
|
+
rateLimiter: RateLimiter,
|
|
177
|
+
useRestLess: boolean,
|
|
178
|
+
baseurl?: string,
|
|
179
|
+
): Promise<RouterliciousStorageRestWrapper> {
|
|
180
|
+
const defaultQueryString = {
|
|
181
|
+
token: `${fromUtf8ToBase64(tenantId)}`,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const fetchStorageToken = async (refreshToken?: boolean): Promise<ITokenResponse> => {
|
|
185
|
+
return PerformanceEvent.timedExecAsync(
|
|
186
|
+
logger,
|
|
187
|
+
{
|
|
188
|
+
eventName: "FetchStorageToken",
|
|
189
|
+
docId: documentId,
|
|
190
|
+
},
|
|
191
|
+
async () => {
|
|
192
|
+
// Craft credentials using tenant id and token
|
|
193
|
+
const storageToken = await tokenProvider.fetchStorageToken(
|
|
194
|
+
tenantId,
|
|
195
|
+
documentId,
|
|
196
|
+
refreshToken,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
return storageToken;
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const getAuthorizationHeader: AuthorizationHeaderGetter = (
|
|
205
|
+
token: ITokenResponse,
|
|
206
|
+
): string => {
|
|
207
|
+
const credentials = {
|
|
208
|
+
password: token.jwt,
|
|
209
|
+
user: tenantId,
|
|
210
|
+
};
|
|
211
|
+
return getAuthorizationTokenFromCredentials(credentials);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const storagetoken = await fetchStorageToken();
|
|
215
|
+
|
|
216
|
+
const restWrapper = new RouterliciousStorageRestWrapper(
|
|
217
|
+
logger,
|
|
218
|
+
rateLimiter,
|
|
219
|
+
storagetoken,
|
|
220
|
+
fetchStorageToken,
|
|
221
|
+
getAuthorizationHeader,
|
|
222
|
+
useRestLess,
|
|
223
|
+
baseurl,
|
|
224
|
+
defaultQueryString,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return restWrapper;
|
|
228
|
+
}
|
|
187
229
|
}
|
|
188
230
|
|
|
189
231
|
export class RouterliciousOrdererRestWrapper extends RouterliciousRestWrapper {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
232
|
+
private constructor(
|
|
233
|
+
logger: ITelemetryLogger,
|
|
234
|
+
rateLimiter: RateLimiter,
|
|
235
|
+
token: ITokenResponse,
|
|
236
|
+
fetchToken: TokenFetcher,
|
|
237
|
+
getAuthorizationHeader: AuthorizationHeaderGetter,
|
|
238
|
+
useRestLess: boolean,
|
|
239
|
+
baseurl?: string,
|
|
240
|
+
defaultQueryString: ParsedUrlQueryInput = {},
|
|
241
|
+
) {
|
|
242
|
+
super(
|
|
243
|
+
logger,
|
|
244
|
+
rateLimiter,
|
|
245
|
+
token,
|
|
246
|
+
fetchToken,
|
|
247
|
+
getAuthorizationHeader,
|
|
248
|
+
useRestLess,
|
|
249
|
+
baseurl,
|
|
250
|
+
defaultQueryString,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public static async load(
|
|
255
|
+
tenantId: string,
|
|
256
|
+
documentId: string | undefined,
|
|
257
|
+
tokenProvider: ITokenProvider,
|
|
258
|
+
logger: ITelemetryLogger,
|
|
259
|
+
rateLimiter: RateLimiter,
|
|
260
|
+
useRestLess: boolean,
|
|
261
|
+
baseurl?: string,
|
|
262
|
+
): Promise<RouterliciousOrdererRestWrapper> {
|
|
263
|
+
const getAuthorizationHeader: AuthorizationHeaderGetter = (
|
|
264
|
+
token: ITokenResponse,
|
|
265
|
+
): string => {
|
|
266
|
+
return `Basic ${token.jwt}`;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const fetchOrdererToken = async (refreshToken?: boolean): Promise<ITokenResponse> => {
|
|
270
|
+
return PerformanceEvent.timedExecAsync(
|
|
271
|
+
logger,
|
|
272
|
+
{
|
|
273
|
+
eventName: "FetchOrdererToken",
|
|
274
|
+
docId: documentId,
|
|
275
|
+
},
|
|
276
|
+
async () => {
|
|
277
|
+
const ordererToken = await tokenProvider.fetchOrdererToken(
|
|
278
|
+
tenantId,
|
|
279
|
+
documentId,
|
|
280
|
+
refreshToken,
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
return ordererToken;
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const newtoken = await fetchOrdererToken();
|
|
289
|
+
|
|
290
|
+
const restWrapper = new RouterliciousOrdererRestWrapper(
|
|
291
|
+
logger,
|
|
292
|
+
rateLimiter,
|
|
293
|
+
newtoken,
|
|
294
|
+
fetchOrdererToken,
|
|
295
|
+
getAuthorizationHeader,
|
|
296
|
+
useRestLess,
|
|
297
|
+
baseurl,
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
return restWrapper;
|
|
301
|
+
}
|
|
240
302
|
}
|