appwrite
Version:
Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API
1,188 lines (1,037 loc) • 150 kB
text/typescript
import { Service } from '../service';
import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
import { AuthenticatorType } from '../enums/authenticator-type';
import { AuthenticationFactor } from '../enums/authentication-factor';
import { OAuthProvider } from '../enums/o-auth-provider';
export class Account {
client: Client;
constructor(client: Client) {
this.client = client;
}
/**
* Get the currently logged in user.
*
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
*/
get<Preferences extends Models.Preferences = Models.DefaultPreferences>(): Promise<Models.User<Preferences>> {
const apiPath = '/account';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
*
* @param {string} params.userId - User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
* @param {string} params.email - User email.
* @param {string} params.password - New user password. Must be between 8 and 256 chars.
* @param {string} params.name - User name. Max length: 128 chars.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
*/
create<Preferences extends Models.Preferences = Models.DefaultPreferences>(params: { userId: string, email: string, password: string, name?: string }): Promise<Models.User<Preferences>>;
/**
* Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
*
* @param {string} userId - User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
* @param {string} email - User email.
* @param {string} password - New user password. Must be between 8 and 256 chars.
* @param {string} name - User name. Max length: 128 chars.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
create<Preferences extends Models.Preferences = Models.DefaultPreferences>(userId: string, email: string, password: string, name?: string): Promise<Models.User<Preferences>>;
create<Preferences extends Models.Preferences = Models.DefaultPreferences>(
paramsOrFirst: { userId: string, email: string, password: string, name?: string } | string,
...rest: [(string)?, (string)?, (string)?]
): Promise<Models.User<Preferences>> {
let params: { userId: string, email: string, password: string, name?: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { userId: string, email: string, password: string, name?: string };
} else {
params = {
userId: paramsOrFirst as string,
email: rest[0] as string,
password: rest[1] as string,
name: rest[2] as string
};
}
const userId = params.userId;
const email = params.email;
const password = params.password;
const name = params.name;
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
const apiPath = '/account';
const payload: Payload = {};
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
if (typeof email !== 'undefined') {
payload['email'] = email;
}
if (typeof password !== 'undefined') {
payload['password'] = password;
}
if (typeof name !== 'undefined') {
payload['name'] = name;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Update currently logged in user account email address. After changing user address, the user confirmation status will get reset. A new confirmation email is not sent automatically however you can use the send confirmation email endpoint again to send the confirmation email. For security measures, user password is required to complete this request.
* This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password.
*
*
* @param {string} params.email - User email.
* @param {string} params.password - User password. Must be at least 8 chars.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
*/
updateEmail<Preferences extends Models.Preferences = Models.DefaultPreferences>(params: { email: string, password: string }): Promise<Models.User<Preferences>>;
/**
* Update currently logged in user account email address. After changing user address, the user confirmation status will get reset. A new confirmation email is not sent automatically however you can use the send confirmation email endpoint again to send the confirmation email. For security measures, user password is required to complete this request.
* This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password.
*
*
* @param {string} email - User email.
* @param {string} password - User password. Must be at least 8 chars.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateEmail<Preferences extends Models.Preferences = Models.DefaultPreferences>(email: string, password: string): Promise<Models.User<Preferences>>;
updateEmail<Preferences extends Models.Preferences = Models.DefaultPreferences>(
paramsOrFirst: { email: string, password: string } | string,
...rest: [(string)?]
): Promise<Models.User<Preferences>> {
let params: { email: string, password: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { email: string, password: string };
} else {
params = {
email: paramsOrFirst as string,
password: rest[0] as string
};
}
const email = params.email;
const password = params.password;
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
const apiPath = '/account/email';
const payload: Payload = {};
if (typeof email !== 'undefined') {
payload['email'] = email;
}
if (typeof password !== 'undefined') {
payload['password'] = password;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'patch',
uri,
apiHeaders,
payload
);
}
/**
* Get the list of identities for the currently logged in user.
*
* @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
* @throws {AppwriteException}
* @returns {Promise<Models.IdentityList>}
*/
listIdentities(params?: { queries?: string[], total?: boolean }): Promise<Models.IdentityList>;
/**
* Get the list of identities for the currently logged in user.
*
* @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
* @throws {AppwriteException}
* @returns {Promise<Models.IdentityList>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
listIdentities(queries?: string[], total?: boolean): Promise<Models.IdentityList>;
listIdentities(
paramsOrFirst?: { queries?: string[], total?: boolean } | string[],
...rest: [(boolean)?]
): Promise<Models.IdentityList> {
let params: { queries?: string[], total?: boolean };
if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean };
} else {
params = {
queries: paramsOrFirst as string[],
total: rest[0] as boolean
};
}
const queries = params.queries;
const total = params.total;
const apiPath = '/account/identities';
const payload: Payload = {};
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
if (typeof total !== 'undefined') {
payload['total'] = total;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Delete an identity by its unique ID.
*
* @param {string} params.identityId - Identity ID.
* @throws {AppwriteException}
* @returns {Promise<{}>}
*/
deleteIdentity(params: { identityId: string }): Promise<{}>;
/**
* Delete an identity by its unique ID.
*
* @param {string} identityId - Identity ID.
* @throws {AppwriteException}
* @returns {Promise<{}>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
deleteIdentity(identityId: string): Promise<{}>;
deleteIdentity(
paramsOrFirst: { identityId: string } | string
): Promise<{}> {
let params: { identityId: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { identityId: string };
} else {
params = {
identityId: paramsOrFirst as string
};
}
const identityId = params.identityId;
if (typeof identityId === 'undefined') {
throw new AppwriteException('Missing required parameter: "identityId"');
}
const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'delete',
uri,
apiHeaders,
payload
);
}
/**
* Use this endpoint to create a JSON Web Token. You can use the resulting JWT to authenticate on behalf of the current user when working with the Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes from its creation and will be invalid if the user will logout in that time frame.
*
* @param {number} params.duration - Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.
* @throws {AppwriteException}
* @returns {Promise<Models.Jwt>}
*/
createJWT(params?: { duration?: number }): Promise<Models.Jwt>;
/**
* Use this endpoint to create a JSON Web Token. You can use the resulting JWT to authenticate on behalf of the current user when working with the Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes from its creation and will be invalid if the user will logout in that time frame.
*
* @param {number} duration - Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.
* @throws {AppwriteException}
* @returns {Promise<Models.Jwt>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createJWT(duration?: number): Promise<Models.Jwt>;
createJWT(
paramsOrFirst?: { duration?: number } | number
): Promise<Models.Jwt> {
let params: { duration?: number };
if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { duration?: number };
} else {
params = {
duration: paramsOrFirst as number
};
}
const duration = params.duration;
const apiPath = '/account/jwts';
const payload: Payload = {};
if (typeof duration !== 'undefined') {
payload['duration'] = duration;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.
*
* @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
* @throws {AppwriteException}
* @returns {Promise<Models.LogList>}
*/
listLogs(params?: { queries?: string[], total?: boolean }): Promise<Models.LogList>;
/**
* Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.
*
* @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
* @throws {AppwriteException}
* @returns {Promise<Models.LogList>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
listLogs(queries?: string[], total?: boolean): Promise<Models.LogList>;
listLogs(
paramsOrFirst?: { queries?: string[], total?: boolean } | string[],
...rest: [(boolean)?]
): Promise<Models.LogList> {
let params: { queries?: string[], total?: boolean };
if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean };
} else {
params = {
queries: paramsOrFirst as string[],
total: rest[0] as boolean
};
}
const queries = params.queries;
const total = params.total;
const apiPath = '/account/logs';
const payload: Payload = {};
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
if (typeof total !== 'undefined') {
payload['total'] = total;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Enable or disable MFA on an account.
*
* @param {boolean} params.mfa - Enable or disable MFA.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
*/
updateMFA<Preferences extends Models.Preferences = Models.DefaultPreferences>(params: { mfa: boolean }): Promise<Models.User<Preferences>>;
/**
* Enable or disable MFA on an account.
*
* @param {boolean} mfa - Enable or disable MFA.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateMFA<Preferences extends Models.Preferences = Models.DefaultPreferences>(mfa: boolean): Promise<Models.User<Preferences>>;
updateMFA<Preferences extends Models.Preferences = Models.DefaultPreferences>(
paramsOrFirst: { mfa: boolean } | boolean
): Promise<Models.User<Preferences>> {
let params: { mfa: boolean };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { mfa: boolean };
} else {
params = {
mfa: paramsOrFirst as boolean
};
}
const mfa = params.mfa;
if (typeof mfa === 'undefined') {
throw new AppwriteException('Missing required parameter: "mfa"');
}
const apiPath = '/account/mfa';
const payload: Payload = {};
if (typeof mfa !== 'undefined') {
payload['mfa'] = mfa;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'patch',
uri,
apiHeaders,
payload
);
}
/**
* Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
* @param {AuthenticatorType} params.type - Type of authenticator. Must be `totp`
* @throws {AppwriteException}
* @returns {Promise<Models.MfaType>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.createMFAAuthenticator` instead.
*/
createMfaAuthenticator(params: { type: AuthenticatorType }): Promise<Models.MfaType>;
/**
* Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
* @param {AuthenticatorType} type - Type of authenticator. Must be `totp`
* @throws {AppwriteException}
* @returns {Promise<Models.MfaType>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createMfaAuthenticator(type: AuthenticatorType): Promise<Models.MfaType>;
createMfaAuthenticator(
paramsOrFirst: { type: AuthenticatorType } | AuthenticatorType
): Promise<Models.MfaType> {
let params: { type: AuthenticatorType };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { type: AuthenticatorType };
} else {
params = {
type: paramsOrFirst as AuthenticatorType
};
}
const type = params.type;
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
* @param {AuthenticatorType} params.type - Type of authenticator. Must be `totp`
* @throws {AppwriteException}
* @returns {Promise<Models.MfaType>}
*/
createMFAAuthenticator(params: { type: AuthenticatorType }): Promise<Models.MfaType>;
/**
* Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
* @param {AuthenticatorType} type - Type of authenticator. Must be `totp`
* @throws {AppwriteException}
* @returns {Promise<Models.MfaType>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createMFAAuthenticator(type: AuthenticatorType): Promise<Models.MfaType>;
createMFAAuthenticator(
paramsOrFirst: { type: AuthenticatorType } | AuthenticatorType
): Promise<Models.MfaType> {
let params: { type: AuthenticatorType };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { type: AuthenticatorType };
} else {
params = {
type: paramsOrFirst as AuthenticatorType
};
}
const type = params.type;
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
* @param {AuthenticatorType} params.type - Type of authenticator.
* @param {string} params.otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.updateMFAAuthenticator` instead.
*/
updateMfaAuthenticator<Preferences extends Models.Preferences = Models.DefaultPreferences>(params: { type: AuthenticatorType, otp: string }): Promise<Models.User<Preferences>>;
/**
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
* @param {AuthenticatorType} type - Type of authenticator.
* @param {string} otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateMfaAuthenticator<Preferences extends Models.Preferences = Models.DefaultPreferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>>;
updateMfaAuthenticator<Preferences extends Models.Preferences = Models.DefaultPreferences>(
paramsOrFirst: { type: AuthenticatorType, otp: string } | AuthenticatorType,
...rest: [(string)?]
): Promise<Models.User<Preferences>> {
let params: { type: AuthenticatorType, otp: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst || 'otp' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { type: AuthenticatorType, otp: string };
} else {
params = {
type: paramsOrFirst as AuthenticatorType,
otp: rest[0] as string
};
}
const type = params.type;
const otp = params.otp;
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
if (typeof otp === 'undefined') {
throw new AppwriteException('Missing required parameter: "otp"');
}
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
if (typeof otp !== 'undefined') {
payload['otp'] = otp;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'put',
uri,
apiHeaders,
payload
);
}
/**
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
* @param {AuthenticatorType} params.type - Type of authenticator.
* @param {string} params.otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
*/
updateMFAAuthenticator<Preferences extends Models.Preferences = Models.DefaultPreferences>(params: { type: AuthenticatorType, otp: string }): Promise<Models.User<Preferences>>;
/**
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
* @param {AuthenticatorType} type - Type of authenticator.
* @param {string} otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.User<Preferences>>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateMFAAuthenticator<Preferences extends Models.Preferences = Models.DefaultPreferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>>;
updateMFAAuthenticator<Preferences extends Models.Preferences = Models.DefaultPreferences>(
paramsOrFirst: { type: AuthenticatorType, otp: string } | AuthenticatorType,
...rest: [(string)?]
): Promise<Models.User<Preferences>> {
let params: { type: AuthenticatorType, otp: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst || 'otp' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { type: AuthenticatorType, otp: string };
} else {
params = {
type: paramsOrFirst as AuthenticatorType,
otp: rest[0] as string
};
}
const type = params.type;
const otp = params.otp;
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
if (typeof otp === 'undefined') {
throw new AppwriteException('Missing required parameter: "otp"');
}
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
if (typeof otp !== 'undefined') {
payload['otp'] = otp;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'put',
uri,
apiHeaders,
payload
);
}
/**
* Delete an authenticator for a user by ID.
*
* @param {AuthenticatorType} params.type - Type of authenticator.
* @throws {AppwriteException}
* @returns {Promise<{}>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.deleteMFAAuthenticator` instead.
*/
deleteMfaAuthenticator(params: { type: AuthenticatorType }): Promise<{}>;
/**
* Delete an authenticator for a user by ID.
*
* @param {AuthenticatorType} type - Type of authenticator.
* @throws {AppwriteException}
* @returns {Promise<{}>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
deleteMfaAuthenticator(type: AuthenticatorType): Promise<{}>;
deleteMfaAuthenticator(
paramsOrFirst: { type: AuthenticatorType } | AuthenticatorType
): Promise<{}> {
let params: { type: AuthenticatorType };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { type: AuthenticatorType };
} else {
params = {
type: paramsOrFirst as AuthenticatorType
};
}
const type = params.type;
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'delete',
uri,
apiHeaders,
payload
);
}
/**
* Delete an authenticator for a user by ID.
*
* @param {AuthenticatorType} params.type - Type of authenticator.
* @throws {AppwriteException}
* @returns {Promise<{}>}
*/
deleteMFAAuthenticator(params: { type: AuthenticatorType }): Promise<{}>;
/**
* Delete an authenticator for a user by ID.
*
* @param {AuthenticatorType} type - Type of authenticator.
* @throws {AppwriteException}
* @returns {Promise<{}>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
deleteMFAAuthenticator(type: AuthenticatorType): Promise<{}>;
deleteMFAAuthenticator(
paramsOrFirst: { type: AuthenticatorType } | AuthenticatorType
): Promise<{}> {
let params: { type: AuthenticatorType };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { type: AuthenticatorType };
} else {
params = {
type: paramsOrFirst as AuthenticatorType
};
}
const type = params.type;
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'delete',
uri,
apiHeaders,
payload
);
}
/**
* Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
* @param {AuthenticationFactor} params.factor - Factor used for verification. Must be one of following: `email`, `phone`, `totp`, `recoveryCode`.
* @throws {AppwriteException}
* @returns {Promise<Models.MfaChallenge>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.createMFAChallenge` instead.
*/
createMfaChallenge(params: { factor: AuthenticationFactor }): Promise<Models.MfaChallenge>;
/**
* Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
* @param {AuthenticationFactor} factor - Factor used for verification. Must be one of following: `email`, `phone`, `totp`, `recoveryCode`.
* @throws {AppwriteException}
* @returns {Promise<Models.MfaChallenge>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createMfaChallenge(factor: AuthenticationFactor): Promise<Models.MfaChallenge>;
createMfaChallenge(
paramsOrFirst: { factor: AuthenticationFactor } | AuthenticationFactor
): Promise<Models.MfaChallenge> {
let params: { factor: AuthenticationFactor };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('factor' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { factor: AuthenticationFactor };
} else {
params = {
factor: paramsOrFirst as AuthenticationFactor
};
}
const factor = params.factor;
if (typeof factor === 'undefined') {
throw new AppwriteException('Missing required parameter: "factor"');
}
const apiPath = '/account/mfa/challenges';
const payload: Payload = {};
if (typeof factor !== 'undefined') {
payload['factor'] = factor;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
* @param {AuthenticationFactor} params.factor - Factor used for verification. Must be one of following: `email`, `phone`, `totp`, `recoveryCode`.
* @throws {AppwriteException}
* @returns {Promise<Models.MfaChallenge>}
*/
createMFAChallenge(params: { factor: AuthenticationFactor }): Promise<Models.MfaChallenge>;
/**
* Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
* @param {AuthenticationFactor} factor - Factor used for verification. Must be one of following: `email`, `phone`, `totp`, `recoveryCode`.
* @throws {AppwriteException}
* @returns {Promise<Models.MfaChallenge>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
createMFAChallenge(factor: AuthenticationFactor): Promise<Models.MfaChallenge>;
createMFAChallenge(
paramsOrFirst: { factor: AuthenticationFactor } | AuthenticationFactor
): Promise<Models.MfaChallenge> {
let params: { factor: AuthenticationFactor };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('factor' in paramsOrFirst))) {
params = (paramsOrFirst || {}) as { factor: AuthenticationFactor };
} else {
params = {
factor: paramsOrFirst as AuthenticationFactor
};
}
const factor = params.factor;
if (typeof factor === 'undefined') {
throw new AppwriteException('Missing required parameter: "factor"');
}
const apiPath = '/account/mfa/challenges';
const payload: Payload = {};
if (typeof factor !== 'undefined') {
payload['factor'] = factor;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @param {string} params.challengeId - ID of the challenge.
* @param {string} params.otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.Session>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.updateMFAChallenge` instead.
*/
updateMfaChallenge(params: { challengeId: string, otp: string }): Promise<Models.Session>;
/**
* Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @param {string} challengeId - ID of the challenge.
* @param {string} otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.Session>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateMfaChallenge(challengeId: string, otp: string): Promise<Models.Session>;
updateMfaChallenge(
paramsOrFirst: { challengeId: string, otp: string } | string,
...rest: [(string)?]
): Promise<Models.Session> {
let params: { challengeId: string, otp: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { challengeId: string, otp: string };
} else {
params = {
challengeId: paramsOrFirst as string,
otp: rest[0] as string
};
}
const challengeId = params.challengeId;
const otp = params.otp;
if (typeof challengeId === 'undefined') {
throw new AppwriteException('Missing required parameter: "challengeId"');
}
if (typeof otp === 'undefined') {
throw new AppwriteException('Missing required parameter: "otp"');
}
const apiPath = '/account/mfa/challenges';
const payload: Payload = {};
if (typeof challengeId !== 'undefined') {
payload['challengeId'] = challengeId;
}
if (typeof otp !== 'undefined') {
payload['otp'] = otp;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'put',
uri,
apiHeaders,
payload
);
}
/**
* Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @param {string} params.challengeId - ID of the challenge.
* @param {string} params.otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.Session>}
*/
updateMFAChallenge(params: { challengeId: string, otp: string }): Promise<Models.Session>;
/**
* Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @param {string} challengeId - ID of the challenge.
* @param {string} otp - Valid verification token.
* @throws {AppwriteException}
* @returns {Promise<Models.Session>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateMFAChallenge(challengeId: string, otp: string): Promise<Models.Session>;
updateMFAChallenge(
paramsOrFirst: { challengeId: string, otp: string } | string,
...rest: [(string)?]
): Promise<Models.Session> {
let params: { challengeId: string, otp: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { challengeId: string, otp: string };
} else {
params = {
challengeId: paramsOrFirst as string,
otp: rest[0] as string
};
}
const challengeId = params.challengeId;
const otp = params.otp;
if (typeof challengeId === 'undefined') {
throw new AppwriteException('Missing required parameter: "challengeId"');
}
if (typeof otp === 'undefined') {
throw new AppwriteException('Missing required parameter: "otp"');
}
const apiPath = '/account/mfa/challenges';
const payload: Payload = {};
if (typeof challengeId !== 'undefined') {
payload['challengeId'] = challengeId;
}
if (typeof otp !== 'undefined') {
payload['otp'] = otp;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'put',
uri,
apiHeaders,
payload
);
}
/**
* List the factors available on the account to be used as a MFA challange.
*
* @throws {AppwriteException}
* @returns {Promise<Models.MfaFactors>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.listMFAFactors` instead.
*/
listMfaFactors(): Promise<Models.MfaFactors> {
const apiPath = '/account/mfa/factors';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* List the factors available on the account to be used as a MFA challange.
*
* @throws {AppwriteException}
* @returns {Promise<Models.MfaFactors>}
*/
listMFAFactors(): Promise<Models.MfaFactors> {
const apiPath = '/account/mfa/factors';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes.
*
* @throws {AppwriteException}
* @returns {Promise<Models.MfaRecoveryCodes>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.getMFARecoveryCodes` instead.
*/
getMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes.
*
* @throws {AppwriteException}
* @returns {Promise<Models.MfaRecoveryCodes>}
*/
getMFARecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @throws {AppwriteException}
* @returns {Promise<Models.MfaRecoveryCodes>}
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.createMFARecoveryCodes` instead.
*/
createMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @throws {AppwriteException}
* @returns {Promise<Models.MfaRecoveryCodes>}
*/
createMFARecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,