407
408
async manifest(oldValue: IUserDataManifest | null, headers: IHeaders = {}): Promise<IUserDataManifest | null> {
410
throw new Error('No settings sync store url configured.');
411
}
413
>
const url = joinPath(this.userDataSyncStoreUrl, 'manifest').toString();
414
>
headers = { ...headers };
415
>
headers['Content-Type'] = 'application/json';
416
>
if (oldValue) {
417
headers['If-None-Match'] = oldValue.ref;
418
}
420
>
const context = await this.request(url, { type: 'GET', headers, callSite: 'userDataSync.manifest' }, [304], CancellationToken.None);
421
>
422
>
let manifest: IUserDataManifest | null = null;
423
>
if (context.res.statusCode === 304) {
424
manifest = oldValue;
425
}
427
>
if (!manifest) {
428
>
const ref = context.res.headers['etag'];
429
>
if (!ref) {
430
throw new UserDataSyncStoreError('Server did not return the ref', url, UserDataSyncErrorCode.NoRef, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
431
}
433
>
const content = await asTextOrError(context);
434
>
if (!content && context.res.statusCode === 304) {
435
throw new UserDataSyncStoreError('Empty response', url, UserDataSyncErrorCode.EmptyResponse, context.res.statusCode, context.res.headers[HEADER_OPERATION_ID]);
436
}
438
>
if (content) {
439
manifest = { ...JSON.parse(content), ref };
440
}
442
>
443
>
const currentSessionId = this.storageService.get(USER_SESSION_ID_KEY, StorageScope.APPLICATION);
444
>
445
>
if (currentSessionId && manifest && currentSessionId !== manifest.session) {
446
// Server session is different from client session so clear cached session.
447
this.clearSession();
448
}
450
>
if (manifest === null && currentSessionId) {
451
// server session is cleared so clear cached session.
452
this.clearSession();
453
}
455
>
if (manifest) {
456
// update session
457
this.storageService.store(USER_SESSION_ID_KEY, manifest.session, StorageScope.APPLICATION, StorageTarget.MACHINE);
458
}
460
>
return manifest;
461
>
}
462
463
async clear(): Promise<void> {