Discriminator in username
This commit is contained in:
parent
58f0012f14
commit
00f82a6d39
54 changed files with 2706 additions and 892 deletions
|
@ -185,44 +185,34 @@ type BytesWithDetailsType = {
|
|||
response: Response;
|
||||
};
|
||||
|
||||
export const multiRecipient200ResponseSchema = z
|
||||
.object({
|
||||
uuids404: z.array(z.string()).optional(),
|
||||
needsSync: z.boolean().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
export const multiRecipient200ResponseSchema = z.object({
|
||||
uuids404: z.array(z.string()).optional(),
|
||||
needsSync: z.boolean().optional(),
|
||||
});
|
||||
export type MultiRecipient200ResponseType = z.infer<
|
||||
typeof multiRecipient200ResponseSchema
|
||||
>;
|
||||
|
||||
export const multiRecipient409ResponseSchema = z.array(
|
||||
z
|
||||
.object({
|
||||
uuid: z.string(),
|
||||
devices: z
|
||||
.object({
|
||||
missingDevices: z.array(z.number()).optional(),
|
||||
extraDevices: z.array(z.number()).optional(),
|
||||
})
|
||||
.passthrough(),
|
||||
})
|
||||
.passthrough()
|
||||
z.object({
|
||||
uuid: z.string(),
|
||||
devices: z.object({
|
||||
missingDevices: z.array(z.number()).optional(),
|
||||
extraDevices: z.array(z.number()).optional(),
|
||||
}),
|
||||
})
|
||||
);
|
||||
export type MultiRecipient409ResponseType = z.infer<
|
||||
typeof multiRecipient409ResponseSchema
|
||||
>;
|
||||
|
||||
export const multiRecipient410ResponseSchema = z.array(
|
||||
z
|
||||
.object({
|
||||
uuid: z.string(),
|
||||
devices: z
|
||||
.object({
|
||||
staleDevices: z.array(z.number()).optional(),
|
||||
})
|
||||
.passthrough(),
|
||||
})
|
||||
.passthrough()
|
||||
z.object({
|
||||
uuid: z.string(),
|
||||
devices: z.object({
|
||||
staleDevices: z.array(z.number()).optional(),
|
||||
}),
|
||||
})
|
||||
);
|
||||
export type MultiRecipient410ResponseType = z.infer<
|
||||
typeof multiRecipient410ResponseSchema
|
||||
|
@ -524,6 +514,8 @@ const URL_CALLS = {
|
|||
supportUnauthenticatedDelivery: 'v1/devices/unauthenticated_delivery',
|
||||
updateDeviceName: 'v1/accounts/name',
|
||||
username: 'v1/accounts/username',
|
||||
reservedUsername: 'v1/accounts/username/reserved',
|
||||
confirmUsername: 'v1/accounts/username/confirm',
|
||||
whoami: 'v1/accounts/whoami',
|
||||
};
|
||||
|
||||
|
@ -599,6 +591,7 @@ type AjaxOptionsType = {
|
|||
username?: string;
|
||||
validateResponse?: any;
|
||||
isRegistration?: true;
|
||||
abortSignal?: AbortSignal;
|
||||
} & (
|
||||
| {
|
||||
unauthenticated?: false;
|
||||
|
@ -671,17 +664,15 @@ export type ProfileRequestDataType = {
|
|||
version: string;
|
||||
};
|
||||
|
||||
const uploadAvatarHeadersZod = z
|
||||
.object({
|
||||
acl: z.string(),
|
||||
algorithm: z.string(),
|
||||
credential: z.string(),
|
||||
date: z.string(),
|
||||
key: z.string(),
|
||||
policy: z.string(),
|
||||
signature: z.string(),
|
||||
})
|
||||
.passthrough();
|
||||
const uploadAvatarHeadersZod = z.object({
|
||||
acl: z.string(),
|
||||
algorithm: z.string(),
|
||||
credential: z.string(),
|
||||
date: z.string(),
|
||||
key: z.string(),
|
||||
policy: z.string(),
|
||||
signature: z.string(),
|
||||
});
|
||||
export type UploadAvatarHeadersType = z.infer<typeof uploadAvatarHeadersZod>;
|
||||
|
||||
export type ProfileType = Readonly<{
|
||||
|
@ -724,14 +715,12 @@ export type MakeProxiedRequestResultType =
|
|||
totalSize: number;
|
||||
};
|
||||
|
||||
const whoamiResultZod = z
|
||||
.object({
|
||||
uuid: z.string(),
|
||||
pni: z.string(),
|
||||
number: z.string(),
|
||||
username: z.string().or(z.null()).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
const whoamiResultZod = z.object({
|
||||
uuid: z.string(),
|
||||
pni: z.string(),
|
||||
number: z.string(),
|
||||
username: z.string().or(z.null()).optional(),
|
||||
});
|
||||
export type WhoamiResultType = z.infer<typeof whoamiResultZod>;
|
||||
|
||||
export type ConfirmCodeResultType = Readonly<{
|
||||
|
@ -784,20 +773,37 @@ export type GetGroupCredentialsResultType = Readonly<{
|
|||
credentials: ReadonlyArray<GroupCredentialType>;
|
||||
}>;
|
||||
|
||||
const verifyAciResponse = z
|
||||
.object({
|
||||
elements: z.array(
|
||||
z.object({
|
||||
aci: z.string(),
|
||||
identityKey: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.passthrough();
|
||||
const verifyAciResponse = z.object({
|
||||
elements: z.array(
|
||||
z.object({
|
||||
aci: z.string(),
|
||||
identityKey: z.string(),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
export type VerifyAciRequestType = Array<{ aci: string; fingerprint: string }>;
|
||||
export type VerifyAciResponseType = z.infer<typeof verifyAciResponse>;
|
||||
|
||||
export type ReserveUsernameOptionsType = Readonly<{
|
||||
nickname: string;
|
||||
abortSignal?: AbortSignal;
|
||||
}>;
|
||||
|
||||
export type ConfirmUsernameOptionsType = Readonly<{
|
||||
usernameToConfirm: string;
|
||||
reservationToken: string;
|
||||
abortSignal?: AbortSignal;
|
||||
}>;
|
||||
|
||||
const reserveUsernameResultZod = z.object({
|
||||
username: z.string(),
|
||||
reservationToken: z.string(),
|
||||
});
|
||||
export type ReserveUsernameResultType = z.infer<
|
||||
typeof reserveUsernameResultZod
|
||||
>;
|
||||
|
||||
export type ConfirmCodeOptionsType = Readonly<{
|
||||
number: string;
|
||||
code: string;
|
||||
|
@ -819,7 +825,7 @@ export type WebAPIType = {
|
|||
group: Proto.IGroup,
|
||||
options: GroupCredentialsType
|
||||
) => Promise<void>;
|
||||
deleteUsername: () => Promise<void>;
|
||||
deleteUsername: (abortSignal?: AbortSignal) => Promise<void>;
|
||||
getAttachment: (cdnKey: string, cdnNumber?: number) => Promise<Uint8Array>;
|
||||
getAvatar: (path: string) => Promise<Uint8Array>;
|
||||
getDevices: () => Promise<GetDevicesResultType>;
|
||||
|
@ -911,7 +917,10 @@ export type WebAPIType = {
|
|||
encryptedStickers: Array<Uint8Array>,
|
||||
onProgress?: () => void
|
||||
) => Promise<string>;
|
||||
putUsername: (newUsername: string) => Promise<void>;
|
||||
reserveUsername: (
|
||||
options: ReserveUsernameOptionsType
|
||||
) => Promise<ReserveUsernameResultType>;
|
||||
confirmUsername(options: ConfirmUsernameOptionsType): Promise<void>;
|
||||
registerCapabilities: (capabilities: CapabilitiesUploadType) => Promise<void>;
|
||||
registerKeys: (genKeys: KeysType, uuidKind: UUIDKind) => Promise<void>;
|
||||
registerSupportForUnauthenticatedDelivery: () => Promise<void>;
|
||||
|
@ -1288,7 +1297,8 @@ export function initialize({
|
|||
putAttachment,
|
||||
putProfile,
|
||||
putStickers,
|
||||
putUsername,
|
||||
reserveUsername,
|
||||
confirmUsername,
|
||||
registerCapabilities,
|
||||
registerKeys,
|
||||
registerSupportForUnauthenticatedDelivery,
|
||||
|
@ -1363,6 +1373,7 @@ export function initialize({
|
|||
version,
|
||||
unauthenticated: param.unauthenticated,
|
||||
accessKey: param.accessKey,
|
||||
abortSignal: param.abortSignal,
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -1654,7 +1665,7 @@ export function initialize({
|
|||
return (await _ajax({
|
||||
call: 'profile',
|
||||
httpType: 'GET',
|
||||
urlParameters: `/username/${usernameToFetch}`,
|
||||
urlParameters: `/username/${encodeURIComponent(usernameToFetch)}`,
|
||||
responseType: 'json',
|
||||
redactUrl: _createRedactor(usernameToFetch),
|
||||
})) as ProfileType;
|
||||
|
@ -1765,17 +1776,42 @@ export function initialize({
|
|||
});
|
||||
}
|
||||
|
||||
async function deleteUsername() {
|
||||
async function deleteUsername(abortSignal?: AbortSignal) {
|
||||
await _ajax({
|
||||
call: 'username',
|
||||
httpType: 'DELETE',
|
||||
abortSignal,
|
||||
});
|
||||
}
|
||||
async function putUsername(newUsername: string) {
|
||||
await _ajax({
|
||||
call: 'username',
|
||||
async function reserveUsername({
|
||||
nickname,
|
||||
abortSignal,
|
||||
}: ReserveUsernameOptionsType) {
|
||||
const response = await _ajax({
|
||||
call: 'reservedUsername',
|
||||
httpType: 'PUT',
|
||||
urlParameters: `/${newUsername}`,
|
||||
jsonData: {
|
||||
nickname,
|
||||
},
|
||||
responseType: 'json',
|
||||
abortSignal,
|
||||
});
|
||||
|
||||
return reserveUsernameResultZod.parse(response);
|
||||
}
|
||||
async function confirmUsername({
|
||||
usernameToConfirm,
|
||||
reservationToken,
|
||||
abortSignal,
|
||||
}: ConfirmUsernameOptionsType) {
|
||||
await _ajax({
|
||||
call: 'confirmUsername',
|
||||
httpType: 'PUT',
|
||||
jsonData: {
|
||||
usernameToConfirm,
|
||||
reservationToken,
|
||||
},
|
||||
abortSignal,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue