Use X-Signal-Timestamp header

This commit is contained in:
Fedor Indutny
2025-01-16 20:17:04 -08:00
committed by GitHub
parent dfeb54f898
commit 47cf3266f2
5 changed files with 27 additions and 18 deletions

View File

@@ -829,9 +829,11 @@ const remoteConfigResponseZod = z.object({
value: z.string().or(z.null()).optional(),
})
.array(),
serverEpochTime: z.number(),
});
export type RemoteConfigResponseType = z.infer<typeof remoteConfigResponseZod>;
export type RemoteConfigResponseType = z.infer<typeof remoteConfigResponseZod> &
Readonly<{
serverTimestamp: number;
}>;
export type ProfileType = Readonly<{
identityKey?: string;
@@ -2130,16 +2132,24 @@ export function initialize({
}
async function getConfig() {
const rawRes = await _ajax({
const { data, response } = await _ajax({
call: 'config',
httpType: 'GET',
responseType: 'json',
responseType: 'jsonwithdetails',
});
const res = parseUnknown(remoteConfigResponseZod, rawRes);
const json = parseUnknown(remoteConfigResponseZod, data);
const serverTimestamp = safeParseNumber(
response.headers.get('x-signal-timestamp') || ''
);
if (serverTimestamp == null) {
throw new Error('Missing required x-signal-timestamp header');
}
return {
...res,
config: res.config.filter(
...json,
serverTimestamp,
config: json.config.filter(
({ name }: { name: string }) =>
name.startsWith('desktop.') ||
name.startsWith('global.') ||