diff --git a/lib/api/contacts.js b/lib/api/contacts.js deleted file mode 100644 index 239476ea..00000000 --- a/lib/api/contacts.js +++ /dev/null @@ -1,70 +0,0 @@ -export const queryContacts = ({ Page = 0, PageSize = 1000, LabelID } = {}) => ({ - url: 'contacts', - method: 'get', - params: { Page, PageSize, LabelID } -}); - -export const queryContactExport = ({ Page = 0, PageSize = 50, LabelID } = {}) => ({ - url: 'contacts/export', - method: 'get', - params: { Page, PageSize, LabelID } -}); - -export const getContact = (contactID) => ({ - url: `contacts/${contactID}`, - method: 'get' -}); - -export const addContacts = ({ Contacts, Overwrite, Labels, timeout } = {}) => ({ - url: 'contacts', - method: 'post', - data: { Contacts, Overwrite, Labels }, - timeout -}); - -export const updateContact = (contactID, { Cards } = {}) => ({ - url: `contacts/${contactID}`, - method: 'put', - data: { Cards } -}); - -export const labelContacts = ({ LabelID, ContactIDs } = {}) => ({ - url: 'contacts/label', - method: 'put', - data: { LabelID, ContactIDs } -}); - -export const unLabelContacts = ({ LabelID, ContactIDs } = {}) => ({ - url: 'contacts/unlabel', - method: 'put', - data: { LabelID, ContactIDs } -}); - -export const deleteContacts = (IDs) => ({ - url: 'contacts/delete', - method: 'put', - data: { IDs } -}); - -export const clearContacts = () => ({ - url: 'contacts', - method: 'delete' -}); - -export const queryContactEmails = ({ Page, PageSize, Email, LabelID } = {}) => ({ - url: 'contacts/emails', - method: 'get', - params: { Page, PageSize, Email, LabelID } -}); - -export const labelContactEmails = ({ LabelID, ContactEmailIDs } = {}) => ({ - url: 'contacts/emails/label', - method: 'put', - data: { LabelID, ContactEmailIDs } -}); - -export const unLabelContactEmails = ({ LabelID, ContactEmailIDs } = {}) => ({ - url: 'contacts/emails/unlabel', - method: 'put', - data: { LabelID, ContactEmailIDs } -}); diff --git a/lib/api/contacts.ts b/lib/api/contacts.ts new file mode 100644 index 00000000..a1c834a2 --- /dev/null +++ b/lib/api/contacts.ts @@ -0,0 +1,118 @@ +export const queryContacts = ({ + Page = 0, + PageSize = 1000, + LabelID +}: { + Page?: number; + PageSize?: number; + LabelID?: string; +} = {}) => ({ + url: 'contacts', + method: 'get', + params: { Page, PageSize, LabelID } +}); + +export const queryContactExport = ({ + Page = 0, + PageSize = 50, + LabelID +}: { + Page?: number; + PageSize?: number; + LabelID?: string; +} = {}) => ({ + url: 'contacts/export', + method: 'get', + params: { Page, PageSize, LabelID } +}); + +export const getContact = (contactID: string) => ({ + url: `contacts/${contactID}`, + method: 'get' +}); + +interface Card { + Type: number; + Data: string; + Signature: string | null; +} + +export const addContacts = ({ + Contacts, + Overwrite, + Labels, + timeout +}: { + Contacts: { + Cards: Card[]; + }[]; + Overwrite: 0 | 1; + Labels?: number; + timeout?: number; +}) => ({ + url: 'contacts', + method: 'post', + data: { Contacts, Overwrite, Labels }, + timeout +}); + +export const updateContact = (contactID: string, { Cards }: { Cards: Card[] }) => ({ + url: `contacts/${contactID}`, + method: 'put', + data: { Cards } +}); + +export const labelContacts = ({ LabelID, ContactIDs }: { LabelID: string; ContactIDs: string[] }) => ({ + url: 'contacts/label', + method: 'put', + data: { LabelID, ContactIDs } +}); + +export const unLabelContacts = ({ LabelID, ContactIDs }: { LabelID: string; ContactIDs: string[] }) => ({ + url: 'contacts/unlabel', + method: 'put', + data: { LabelID, ContactIDs } +}); + +export const deleteContacts = (IDs: string[]) => ({ + url: 'contacts/delete', + method: 'put', + data: { IDs } +}); + +export const clearContacts = () => ({ + url: 'contacts', + method: 'delete' +}); + +export const queryContactEmails = ({ + Page, + PageSize, + Email, + LabelID +}: { + Page?: number; + PageSize?: number; +} & ({ + Email?: string; + LabelID?: never; +} | { + Email?: never; + LabelID?: string; +}) = {}) => ({ + url: 'contacts/emails', + method: 'get', + params: { Page, PageSize, Email, LabelID } +}); + +export const labelContactEmails = ({ LabelID, ContactEmailIDs }: { LabelID: string; ContactEmailIDs: string[] }) => ({ + url: 'contacts/emails/label', + method: 'put', + data: { LabelID, ContactEmailIDs } +}); + +export const unLabelContactEmails = ({ LabelID, ContactEmailIDs }: { LabelID: string; ContactEmailIDs: string[] }) => ({ + url: 'contacts/emails/unlabel', + method: 'put', + data: { LabelID, ContactEmailIDs } +}); diff --git a/lib/api/user.js b/lib/api/user.js deleted file mode 100644 index 73abef11..00000000 --- a/lib/api/user.js +++ /dev/null @@ -1,68 +0,0 @@ -export const getUser = () => ({ - url: 'users', - method: 'get' -}); - -export const queryCreateUser = ({ Auth, Email, Token, TokenType, Type, Username }) => ({ - url: 'users', - method: 'post', - data: { Auth, Email, Token, TokenType, Type, Username } -}); - -export const queryUnlock = () => ({ - url: 'users/unlock', - method: 'put' -}); - -export const deleteUser = (data) => ({ - url: 'users/delete', - method: 'put', - data -}); - -export const unlockPasswordChanges = () => ({ - url: 'users/password', - method: 'put' -}); - -export const lockSensitiveSettings = () => ({ - url: 'users/lock', - method: 'put' -}); - -export const getHumanVerificationMethods = () => ({ - url: 'users/human', - method: 'get' -}); - -export const queryVerificationCode = (Type, Destination) => ({ - url: 'users/code', - method: 'post', - data: { Type, Destination } -}); - -export const queryCheckUsernameAvailability = (Name) => ({ - url: 'users/available', - method: 'get', - params: { Name } -}); - -/** - * @param {1 | 2} Type 1 = mail, 2 = VPN - */ -export const queryDirectSignupStatus = (Type) => ({ - url: 'users/direct', - method: 'get', - params: { Type } -}); - -/** - * @param {string} Token - * @param {'email'|'sms'|'invite'|'coupon'|'payment'} TokenType - * @param {1 | 2} Type 1 = mail, 2 = VPN - */ -export const queryCheckVerificationCode = (Token, TokenType, Type) => ({ - url: 'users/check', - method: 'put', - data: { Token, TokenType, Type } -}); diff --git a/lib/api/user.ts b/lib/api/user.ts new file mode 100644 index 00000000..77db5625 --- /dev/null +++ b/lib/api/user.ts @@ -0,0 +1,97 @@ +export const getUser = () => ({ + url: 'users', + method: 'get' +}); + +export const queryCreateUser = (data: { + Username: string; + Email: string; + Token: string; + TokenType: 'captcha' | 'email' | 'sms' | 'invite' | 'payment'; + Type: 1 | 2; // 1 = mail, 2 = VPN + Auth: { + Version: number; + ModulusID: string; + Salt: string; + Verifier: string; + }; + Referrer?: string; + Payload?: { + [key: string]: string; + }; + Salt?: string; +}) => ({ + url: 'users', + method: 'post', + data +}); + +export const queryUnlock = () => ({ + url: 'users/unlock', + method: 'put' +}); + +export const deleteUser = (data: { + ClientEphemeral: string; + ClientProof: string; + SRPSession: string; + TwoFactorCode: number; +}) => ({ + url: 'users/delete', + method: 'put', + data +}); + +export const unlockPasswordChanges = () => ({ + url: 'users/password', + method: 'put' +}); + +export const lockSensitiveSettings = () => ({ + url: 'users/lock', + method: 'put' +}); + +export const getHumanVerificationMethods = () => ({ + url: 'users/human', + method: 'get' +}); + +export const queryVerificationCode = ( + Type: 'email' | 'sms', + Destination: { + Address: string; + Phone?: never; + } | { + Address?: never; + Phone: string; + } +) => ({ + url: 'users/code', + method: 'post', + data: { Type, Destination } +}); + +export const queryCheckUsernameAvailability = (Name: string) => ({ + url: 'users/available', + method: 'get', + params: { Name } +}); + +export const queryDirectSignupStatus = ( + Type: 1 | 2 // 1 = mail, 2 = VPN +) => ({ + url: 'users/direct', + method: 'get', + params: { Type } +}); + +export const queryCheckVerificationCode = ( + Token: string, + TokenType: 'email' | 'sms' | 'invite' | 'coupon' | 'payment', + Type: 1 | 2 // 1 = mail, 2 = VPN +) => ({ + url: 'users/check', + method: 'put', + data: { Token, TokenType, Type } +});