@fluidframework/routerlicious-driver 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1
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.map +1 -1
- package/dist/cache.js +2 -5
- 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.map +1 -1
- package/dist/documentService.js +13 -5
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +7 -4
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +7 -5
- package/dist/documentStorageService.js.map +1 -1
- package/dist/errorUtils.d.ts +9 -2
- package/dist/errorUtils.d.ts.map +1 -1
- package/dist/errorUtils.js +15 -8
- 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/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.map +1 -1
- package/dist/restWrapper.js +5 -6
- 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.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +8 -4
- 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/urlUtils.d.ts.map +1 -1
- package/dist/urlUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +25 -11
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/cache.d.ts.map +1 -1
- package/lib/cache.js +2 -5
- 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.map +1 -1
- package/lib/documentService.js +15 -7
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +7 -4
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +8 -6
- package/lib/documentStorageService.js.map +1 -1
- package/lib/errorUtils.d.ts +9 -2
- package/lib/errorUtils.d.ts.map +1 -1
- package/lib/errorUtils.js +14 -7
- 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/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.map +1 -1
- package/lib/restWrapper.js +5 -6
- 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.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +9 -5
- 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/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +27 -13
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +115 -114
- package/prettier.config.cjs +1 -1
- package/src/cache.ts +16 -19
- 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 -239
- package/src/documentServiceFactory.ts +263 -250
- package/src/documentStorageService.ts +87 -83
- package/src/errorUtils.ts +91 -81
- package/src/index.ts +7 -1
- package/src/nullBlobStorageService.ts +24 -21
- package/src/packageVersion.ts +1 -1
- package/src/policies.ts +44 -44
- package/src/restWrapper.ts +266 -216
- package/src/retriableGitManager.ts +152 -151
- package/src/shreddedSummaryDocumentStorageService.ts +202 -194
- package/src/tokens.ts +69 -44
- package/src/urlUtils.ts +26 -23
- package/src/wholeSummaryDocumentStorageService.ts +246 -228
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
|
@@ -4,27 +4,24 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
|
+
import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
IDocumentStorageService,
|
|
13
|
-
ISummaryContext,
|
|
14
|
-
IDocumentStorageServicePolicies,
|
|
9
|
+
IDocumentStorageService,
|
|
10
|
+
ISummaryContext,
|
|
11
|
+
IDocumentStorageServicePolicies,
|
|
15
12
|
} from "@fluidframework/driver-definitions";
|
|
16
13
|
import { buildHierarchy } from "@fluidframework/protocol-base";
|
|
17
14
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
ICreateBlobResponse,
|
|
16
|
+
ISnapshotTreeEx,
|
|
17
|
+
ISummaryHandle,
|
|
18
|
+
ISummaryTree,
|
|
19
|
+
IVersion,
|
|
23
20
|
} from "@fluidframework/protocol-definitions";
|
|
24
21
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
GitManager,
|
|
23
|
+
ISummaryUploadManager,
|
|
24
|
+
SummaryTreeUploadManager,
|
|
28
25
|
} from "@fluidframework/server-services-client";
|
|
29
26
|
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
30
27
|
import { IRouterliciousDriverPolicies } from "./policies";
|
|
@@ -40,183 +37,194 @@ const isNode = typeof window === "undefined";
|
|
|
40
37
|
* Downloads summaries piece-by-piece on-demand, or up-front when prefetch is enabled.
|
|
41
38
|
*/
|
|
42
39
|
export class ShreddedSummaryDocumentStorageService implements IDocumentStorageService {
|
|
43
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
40
|
+
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
41
|
+
// empty strings as values.
|
|
42
|
+
protected readonly blobsShaCache = new Map<string, string>();
|
|
43
|
+
private readonly blobCache: ICache<ArrayBufferLike> | undefined;
|
|
44
|
+
private readonly snapshotTreeCache: ICache<ISnapshotTreeVersion> | undefined;
|
|
45
|
+
|
|
46
|
+
public get repositoryUrl(): string {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private async getSummaryUploadManager(): Promise<ISummaryUploadManager> {
|
|
51
|
+
const manager = await this.getStorageManager();
|
|
52
|
+
return new SummaryTreeUploadManager(
|
|
53
|
+
new RetriableGitManager(manager, this.logger),
|
|
54
|
+
this.blobsShaCache,
|
|
55
|
+
this.getPreviousFullSnapshot.bind(this),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
protected readonly id: string,
|
|
61
|
+
protected readonly manager: GitManager,
|
|
62
|
+
protected readonly logger: ITelemetryLogger,
|
|
63
|
+
public readonly policies: IDocumentStorageServicePolicies,
|
|
64
|
+
driverPolicies?: IRouterliciousDriverPolicies,
|
|
65
|
+
blobCache?: ICache<ArrayBufferLike>,
|
|
66
|
+
snapshotTreeCache?: ICache<ISnapshotTreeVersion>,
|
|
67
|
+
private readonly getStorageManager: (
|
|
68
|
+
disableCache?: boolean,
|
|
69
|
+
) => Promise<GitManager> = async () => this.manager,
|
|
70
|
+
) {
|
|
71
|
+
if (driverPolicies?.enableRestLess === true || isNode) {
|
|
72
|
+
this.blobCache = blobCache ?? new InMemoryCache();
|
|
73
|
+
this.snapshotTreeCache = snapshotTreeCache ?? new InMemoryCache();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {
|
|
78
|
+
const id = versionId ? versionId : this.id;
|
|
79
|
+
const commits = await PerformanceEvent.timedExecAsync(
|
|
80
|
+
this.logger,
|
|
81
|
+
{
|
|
82
|
+
eventName: "getVersions",
|
|
83
|
+
versionId: id,
|
|
84
|
+
count,
|
|
85
|
+
},
|
|
86
|
+
async () => {
|
|
87
|
+
const manager = await this.getStorageManager();
|
|
88
|
+
return manager.getCommits(id, count);
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
return commits.map((commit) => ({
|
|
92
|
+
date: commit.commit.author.date,
|
|
93
|
+
id: commit.sha,
|
|
94
|
+
treeId: commit.commit.tree.sha,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {
|
|
99
|
+
let requestVersion = version;
|
|
100
|
+
if (!requestVersion) {
|
|
101
|
+
const versions = await this.getVersions(this.id, 1);
|
|
102
|
+
if (versions.length === 0) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
requestVersion = versions[0];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const cachedSnapshotTree = await this.snapshotTreeCache?.get(
|
|
110
|
+
this.getCacheKey(requestVersion.treeId),
|
|
111
|
+
);
|
|
112
|
+
if (cachedSnapshotTree) {
|
|
113
|
+
return cachedSnapshotTree.snapshotTree as ISnapshotTreeEx;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const rawTree = await PerformanceEvent.timedExecAsync(
|
|
117
|
+
this.logger,
|
|
118
|
+
{
|
|
119
|
+
eventName: "getSnapshotTree",
|
|
120
|
+
treeId: requestVersion.treeId,
|
|
121
|
+
},
|
|
122
|
+
async (event) => {
|
|
123
|
+
const manager = await this.getStorageManager();
|
|
124
|
+
const response = await manager.getTree(requestVersion!.treeId);
|
|
125
|
+
event.end({
|
|
126
|
+
size: response.tree.length,
|
|
127
|
+
});
|
|
128
|
+
return response;
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
const tree = buildHierarchy(rawTree, this.blobsShaCache, true);
|
|
132
|
+
await this.snapshotTreeCache?.put(this.getCacheKey(tree.id), {
|
|
133
|
+
id: requestVersion.id,
|
|
134
|
+
snapshotTree: tree,
|
|
135
|
+
});
|
|
136
|
+
return tree;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async readBlob(blobId: string): Promise<ArrayBufferLike> {
|
|
140
|
+
const cachedBlob = await this.blobCache?.get(this.getCacheKey(blobId));
|
|
141
|
+
if (cachedBlob) {
|
|
142
|
+
return cachedBlob;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const value = await PerformanceEvent.timedExecAsync(
|
|
146
|
+
this.logger,
|
|
147
|
+
{
|
|
148
|
+
eventName: "readBlob",
|
|
149
|
+
blobId,
|
|
150
|
+
},
|
|
151
|
+
async (event) => {
|
|
152
|
+
const manager = await this.getStorageManager();
|
|
153
|
+
const response = await manager.getBlob(blobId);
|
|
154
|
+
event.end({
|
|
155
|
+
size: response.size,
|
|
156
|
+
});
|
|
157
|
+
return response;
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
this.blobsShaCache.set(value.sha, "");
|
|
161
|
+
const bufferContent = stringToBuffer(value.content, value.encoding);
|
|
162
|
+
await this.blobCache?.put(this.getCacheKey(value.sha), bufferContent);
|
|
163
|
+
return bufferContent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public async uploadSummaryWithContext(
|
|
167
|
+
summary: ISummaryTree,
|
|
168
|
+
context: ISummaryContext,
|
|
169
|
+
): Promise<string> {
|
|
170
|
+
const summaryHandle = await PerformanceEvent.timedExecAsync(
|
|
171
|
+
this.logger,
|
|
172
|
+
{
|
|
173
|
+
eventName: "uploadSummaryWithContext",
|
|
174
|
+
proposalHandle: context.proposalHandle,
|
|
175
|
+
ackHandle: context.ackHandle,
|
|
176
|
+
referenceSequenceNumber: context.referenceSequenceNumber,
|
|
177
|
+
},
|
|
178
|
+
async () => {
|
|
179
|
+
const summaryUploadManager = await this.getSummaryUploadManager();
|
|
180
|
+
return summaryUploadManager.writeSummaryTree(
|
|
181
|
+
summary,
|
|
182
|
+
context.ackHandle ?? "",
|
|
183
|
+
"channel",
|
|
184
|
+
);
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
return summaryHandle;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
|
|
191
|
+
throw new Error("NOT IMPLEMENTED!");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
|
|
195
|
+
const uint8ArrayFile = new Uint8Array(file);
|
|
196
|
+
return PerformanceEvent.timedExecAsync(
|
|
197
|
+
this.logger,
|
|
198
|
+
{
|
|
199
|
+
eventName: "createBlob",
|
|
200
|
+
size: uint8ArrayFile.length,
|
|
201
|
+
},
|
|
202
|
+
async (event) => {
|
|
203
|
+
const manager = await this.getStorageManager();
|
|
204
|
+
const response = await manager
|
|
205
|
+
.createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
|
|
206
|
+
.then((r) => ({ id: r.sha, url: r.url }));
|
|
207
|
+
event.end({
|
|
208
|
+
blobId: response.id,
|
|
209
|
+
});
|
|
210
|
+
return response;
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private async getPreviousFullSnapshot(
|
|
216
|
+
parentHandle: string,
|
|
217
|
+
): Promise<ISnapshotTreeEx | null | undefined> {
|
|
218
|
+
return parentHandle
|
|
219
|
+
? this.getVersions(parentHandle, 1).then(async (versions) => {
|
|
220
|
+
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
221
|
+
this.blobsShaCache.clear();
|
|
222
|
+
return this.getSnapshotTree(versions[0]);
|
|
223
|
+
})
|
|
224
|
+
: undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private getCacheKey(blobId: string): string {
|
|
228
|
+
return `${this.id}:${blobId}`;
|
|
229
|
+
}
|
|
222
230
|
}
|
package/src/tokens.ts
CHANGED
|
@@ -6,23 +6,28 @@
|
|
|
6
6
|
import { ITokenClaims } from "@fluidframework/protocol-definitions";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Abstracts the discovery of claims contained within a token.
|
|
10
10
|
*/
|
|
11
11
|
export interface ITokenService {
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the {@link @fluidframework/protocol-definitions#ITokenClaims | token claims} from the provided
|
|
14
|
+
* {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} string representation.
|
|
15
|
+
*/
|
|
16
|
+
extractClaims(token: string): ITokenClaims;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export interface ITokenResponse {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* {@link https://jwt.io/introduction/ | JSON Web Token (JWT)} value.
|
|
22
|
+
*/
|
|
23
|
+
jwt: string;
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* A flag indicating whether token was obtained from local cache.
|
|
27
|
+
*
|
|
28
|
+
* @remarks `undefined` indicates that the source of the token could not be determined.
|
|
29
|
+
*/
|
|
30
|
+
fromCache?: boolean;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -30,39 +35,59 @@ export interface ITokenResponse {
|
|
|
30
35
|
* The hosting application is responsible for providing an implementation.
|
|
31
36
|
*/
|
|
32
37
|
export interface ITokenProvider {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Fetches the orderer token from host.
|
|
40
|
+
*
|
|
41
|
+
* @param tenantId - Tenant ID.
|
|
42
|
+
* @param documentId - Optional. Document ID is only required for document-scoped requests.
|
|
43
|
+
* @param refresh - Optional flag indicating whether token fetch must bypass local cache.
|
|
44
|
+
* This likely indicates that some previous request failed authorization due to an expired token,
|
|
45
|
+
* and so a fresh token is required.
|
|
46
|
+
*
|
|
47
|
+
* Default: `false`.
|
|
48
|
+
*
|
|
49
|
+
* NOTE: This parameter will be made required in the future.
|
|
50
|
+
*/
|
|
51
|
+
fetchOrdererToken(
|
|
52
|
+
tenantId: string,
|
|
53
|
+
documentId?: string,
|
|
54
|
+
refresh?: boolean,
|
|
55
|
+
): Promise<ITokenResponse>;
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Fetches the storage token from host.
|
|
59
|
+
*
|
|
60
|
+
* @param tenantId - Tenant ID.
|
|
61
|
+
* @param documentId - Document ID.
|
|
62
|
+
* @param refresh - Optional flag indicating whether token fetch must bypass local cache.
|
|
63
|
+
* This likely indicates that some previous request failed authorization due to an expired token,
|
|
64
|
+
* and so a fresh token is required.
|
|
65
|
+
*
|
|
66
|
+
* Default: `false`.
|
|
67
|
+
*
|
|
68
|
+
* NOTE: This parameter will be made required in the future.
|
|
69
|
+
*/
|
|
70
|
+
fetchStorageToken(
|
|
71
|
+
tenantId: string,
|
|
72
|
+
documentId: string,
|
|
73
|
+
refresh?: boolean,
|
|
74
|
+
): Promise<ITokenResponse>;
|
|
52
75
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
/**
|
|
77
|
+
* A callback triggered directly after creating the document. In this callback the client has the opportunity, to
|
|
78
|
+
* verify against an authorization service, if the user who claims to create the document is the same user who
|
|
79
|
+
* created it.
|
|
80
|
+
*
|
|
81
|
+
* @remarks Notes:
|
|
82
|
+
*
|
|
83
|
+
* * Using the callback may have performance impact on the document creation process.
|
|
84
|
+
*
|
|
85
|
+
* * Any exceptions thrown in the callback would fail the creation workflow
|
|
86
|
+
* (see {@link RouterliciousDocumentServiceFactory.createContainer} for more details).
|
|
87
|
+
*
|
|
88
|
+
* @param documentId - Document ID.
|
|
89
|
+
* @param creationToken - A special token that doesn't provide any kind of access, but it has the user's payload
|
|
90
|
+
* and document id. It can be used to validate the identity of the document creator.
|
|
91
|
+
*/
|
|
92
|
+
documentPostCreateCallback?(documentId: string, creationToken: string): Promise<void>;
|
|
68
93
|
}
|
package/src/urlUtils.ts
CHANGED
|
@@ -8,7 +8,7 @@ import URLParse from "url-parse";
|
|
|
8
8
|
import { ISession } from "@fluidframework/server-services-client";
|
|
9
9
|
|
|
10
10
|
export const parseFluidUrl = (fluidUrl: string): URLParse => {
|
|
11
|
-
|
|
11
|
+
return new URLParse(fluidUrl, true);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -18,29 +18,32 @@ export const parseFluidUrl = (fluidUrl: string): URLParse => {
|
|
|
18
18
|
* TODO: Ideally we would be able to regenerate the resolvedUrl, rather than patching the current one.
|
|
19
19
|
*/
|
|
20
20
|
export const replaceDocumentIdInPath = (urlPath: string, documentId: string): string =>
|
|
21
|
-
|
|
21
|
+
urlPath.split("/").slice(0, -1).concat([documentId]).join("/");
|
|
22
22
|
|
|
23
|
-
export const getDiscoveredFluidResolvedUrl = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
export const getDiscoveredFluidResolvedUrl = (
|
|
24
|
+
resolvedUrl: IFluidResolvedUrl,
|
|
25
|
+
session: ISession,
|
|
26
|
+
): IFluidResolvedUrl => {
|
|
27
|
+
const discoveredOrdererUrl = new URLParse(session.ordererUrl);
|
|
28
|
+
const deltaStorageUrl = new URLParse(resolvedUrl.endpoints.deltaStorageUrl);
|
|
29
|
+
deltaStorageUrl.set("host", discoveredOrdererUrl.host);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const discoveredStorageUrl = new URLParse(session.historianUrl);
|
|
32
|
+
const storageUrl = new URLParse(resolvedUrl.endpoints.storageUrl);
|
|
33
|
+
storageUrl.set("host", discoveredStorageUrl.host);
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
const parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
36
|
+
const discoveredResolvedUrl: IFluidResolvedUrl = {
|
|
37
|
+
endpoints: {
|
|
38
|
+
deltaStorageUrl: deltaStorageUrl.toString(),
|
|
39
|
+
ordererUrl: session.ordererUrl,
|
|
40
|
+
deltaStreamUrl: session.deltaStreamUrl,
|
|
41
|
+
storageUrl: storageUrl.toString(),
|
|
42
|
+
},
|
|
43
|
+
id: resolvedUrl.id,
|
|
44
|
+
tokens: resolvedUrl.tokens,
|
|
45
|
+
type: resolvedUrl.type,
|
|
46
|
+
url: new URLParse(`fluid://${discoveredOrdererUrl.host}${parsedUrl.pathname}`).toString(),
|
|
47
|
+
};
|
|
48
|
+
return discoveredResolvedUrl;
|
|
46
49
|
};
|