import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource.js'; import type * as ApiTypes from '../ApiTypes.js'; import type * as RawApiTypes from '../RawApiTypes.js'; export default class Account extends BaseResource { static readonly TYPE = 'account' as const; /** * Create a new account * * @throws {ApiError} * @throws {TimeoutError} */ create(body: ApiTypes.AccountCreateSchema) { return this.rawCreate( Utils.serializeRequestBody(body, { type: 'account', attributes: [ 'email', 'first_name', 'last_name', 'company', 'password', 'captcha_token', 'signup_to_newsletter', 'role_description', 'role_context', 'acquisition_method', 'latest_acquisition_method', ], relationships: [], }), ).then((body) => Utils.deserializeResponseBody(body), ); } /** * Create a new account * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate( body: RawApiTypes.AccountCreateSchema, ): Promise { return this.client.request({ method: 'POST', url: '/account', body, }); } /** * Update a account * * @throws {ApiError} * @throws {TimeoutError} */ update(body: ApiTypes.AccountUpdateSchema) { return this.rawUpdate( Utils.serializeRequestBody(body, { type: 'account', attributes: [ 'email', 'first_name', 'last_name', 'company', 'password', 'current_password', 'otp_code', ], relationships: ['default_organization'], }), ).then((body) => Utils.deserializeResponseBody(body), ); } /** * Update a account * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate( body: RawApiTypes.AccountUpdateSchema, ): Promise { return this.client.request({ method: 'PUT', url: '/account', body, }); } /** * Delete a account * * @throws {ApiError} * @throws {TimeoutError} */ destroy(body: ApiTypes.AccountDestroySchema) { return this.rawDestroy( Utils.serializeRequestBody(body, { type: 'account_destroy_request', attributes: ['otp_code', 'password'], relationships: [], }), ).then((body) => Utils.deserializeResponseBody(body), ); } /** * Delete a account * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy( body: RawApiTypes.AccountDestroySchema, ): Promise { return this.client.request({ method: 'POST', url: '/account/destroy', body, }); } /** * Retrieve a account * * @throws {ApiError} * @throws {TimeoutError} */ find(queryParams?: ApiTypes.AccountSelfHrefSchema) { return this.rawFind(queryParams).then((body) => Utils.deserializeResponseBody(body), ); } /** * Retrieve a account * * @throws {ApiError} * @throws {TimeoutError} */ rawFind( queryParams?: RawApiTypes.AccountSelfHrefSchema, ): Promise { return this.client.request({ method: 'GET', url: '/account', queryParams, }); } /** * Request a password reset * * @throws {ApiError} * @throws {TimeoutError} */ resetPassword(body: ApiTypes.AccountResetPasswordSchema) { return this.rawResetPassword( Utils.serializeRequestBody(body, { type: 'password_reset', attributes: ['email'], relationships: [], }), ); } /** * Request a password reset * * @throws {ApiError} * @throws {TimeoutError} */ rawResetPassword( body: RawApiTypes.AccountResetPasswordSchema, ): Promise { return this.client.request({ method: 'POST', url: '/account/reset_password', body, }); } /** * Activates 2-factor authorization * * @throws {ApiError} * @throws {TimeoutError} */ activate_2Fa(body: ApiTypes.AccountActivate_2FaSchema) { return this.rawActivate_2Fa( Utils.serializeRequestBody(body, { type: '2fa_activation', attributes: ['otp_code', 'password'], relationships: [], }), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Activates 2-factor authorization * * @throws {ApiError} * @throws {TimeoutError} */ rawActivate_2Fa( body: RawApiTypes.AccountActivate_2FaSchema, ): Promise { return this.client.request({ method: 'PUT', url: '/account/activate-2fa', body, }); } /** * Generates 2-factor authorization secrets * * @throws {ApiError} * @throws {TimeoutError} */ reset_2Fa() { return this.rawReset_2Fa().then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Generates 2-factor authorization secrets * * @throws {ApiError} * @throws {TimeoutError} */ rawReset_2Fa(): Promise { return this.client.request({ method: 'PUT', url: '/account/reset-2fa', }); } /** * De-activates 2-factor authorization * * @throws {ApiError} * @throws {TimeoutError} */ deactivate_2Fa(body: ApiTypes.AccountDeactivate_2FaSchema) { return this.rawDeactivate_2Fa( Utils.serializeRequestBody( body, { type: '2fa_deactivation', attributes: ['otp_code', 'password'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * De-activates 2-factor authorization * * @throws {ApiError} * @throws {TimeoutError} */ rawDeactivate_2Fa( body: RawApiTypes.AccountDeactivate_2FaSchema, ): Promise { return this.client.request({ method: 'PUT', url: '/account/deactivate-2fa', body, }); } /** * Convert to organization * * @throws {ApiError} * @throws {TimeoutError} */ convertToOrganization(body: ApiTypes.AccountConvertToOrganizationSchema) { return this.rawConvertToOrganization( Utils.serializeRequestBody( body, { type: 'organization_conversion', attributes: ['name'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Convert to organization * * @throws {ApiError} * @throws {TimeoutError} */ rawConvertToOrganization( body: RawApiTypes.AccountConvertToOrganizationSchema, ): Promise { return this.client.request( { method: 'POST', url: '/account/convert-to-organization', body, }, ); } /** * Confirm email change * * @throws {ApiError} * @throws {TimeoutError} */ confirmEmailChange(body: ApiTypes.AccountConfirmEmailChangeSchema) { return this.rawConfirmEmailChange( Utils.serializeRequestBody( body, { type: 'email_change_confirmation', attributes: ['token', 'account_id'], relationships: [], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Confirm email change * * @throws {ApiError} * @throws {TimeoutError} */ rawConfirmEmailChange( body: RawApiTypes.AccountConfirmEmailChangeSchema, ): Promise { return this.client.request( { method: 'POST', url: '/account/confirm-email-change', body, }, ); } /** * Complete email verification * * @throws {ApiError} * @throws {TimeoutError} */ completeEmailVerification( body: ApiTypes.AccountCompleteEmailVerificationSchema, ) { return this.rawCompleteEmailVerification( Utils.serializeRequestBody( body, { type: 'email_verification', attributes: ['token', 'account_id'], relationships: [], }, ), ); } /** * Complete email verification * * @throws {ApiError} * @throws {TimeoutError} */ rawCompleteEmailVerification( body: RawApiTypes.AccountCompleteEmailVerificationSchema, ): Promise { return this.client.request({ method: 'POST', url: '/account/complete-email-verification', body, }); } /** * Request email verification * * @throws {ApiError} * @throws {TimeoutError} */ requestEmailVerification() { return this.rawRequestEmailVerification(); } /** * Request email verification * * @throws {ApiError} * @throws {TimeoutError} */ rawRequestEmailVerification(): Promise { return this.client.request({ method: 'POST', url: '/account/request-email-verification', }); } }