From 86182577f9c8acd4a9f8cdb6f18e1021a317b8c1 Mon Sep 17 00:00:00 2001 From: Ramon Candel Date: Thu, 14 Dec 2023 09:05:18 +0100 Subject: [PATCH] Added calls required for the email change process --- package.json | 2 +- src/drive/users/index.ts | 48 +++++++++++++++++++++++++++++++++++++++- src/drive/users/types.ts | 8 +++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 776a51c3..6b9cc734 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/sdk", - "version": "1.4.59", + "version": "1.4.60", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/drive/users/index.ts b/src/drive/users/index.ts index be0c52e4..83a1bb53 100644 --- a/src/drive/users/index.ts +++ b/src/drive/users/index.ts @@ -2,13 +2,15 @@ import { ApiSecurity, ApiUrl, AppDetails } from '../../shared'; import { headersWithToken } from '../../shared/headers'; import { ChangePasswordPayload, + CheckChangeEmailExpirationResponse, FriendInvite, InitializeUserResponse, PreCreateUserResponse, UpdateProfilePayload, UserPublicKeyResponse, + VerifyEmailChangeResponse, } from './types'; -import { UUID, UserSettings } from '../../shared/types/userSettings'; +import { UserSettings } from '../../shared/types/userSettings'; import { HttpClient } from '../../shared/http/client'; export * as UserTypes from './types'; @@ -153,6 +155,50 @@ export class Users { return this.client.post('/user/verifyEmail', payload, this.headers()); } + /** + * Change user email by new email + * + * @param {string} newEmail + * + * @returns {Promise} + */ + public changeUserEmail(newEmail: string): Promise { + return this.client.post( + 'users/attempt-change-email', + { + newEmail, + }, + this.headers(), + ); + } + + /** + * Verify user email change + * + * @param {string} encryptedAttemptChangeEmailId + * + * @returns {Promise} + */ + public verifyEmailChange(encryptedAttemptChangeEmailId: string): Promise { + return this.client.post(`users/attempt-change-email/${encryptedAttemptChangeEmailId}/accept`, {}, this.headers()); + } + + /** + * Check if user email change verification link is expired + * + * @param {string} encryptedAttemptChangeEmailId + * + * @returns {Promise} + */ + public checkChangeEmailExpiration( + encryptedAttemptChangeEmailId: string, + ): Promise { + return this.client.get( + `users/attempt-change-email/${encryptedAttemptChangeEmailId}/verify-expiration`, + this.headers(), + ); + } + /** * Get public key of given email */ diff --git a/src/drive/users/types.ts b/src/drive/users/types.ts index 522232f9..9a3507c9 100644 --- a/src/drive/users/types.ts +++ b/src/drive/users/types.ts @@ -25,3 +25,11 @@ export type PreCreateUserResponse = { export type FriendInvite = { guestEmail: string; host: number; accepted: boolean; id: number }; export type UserPublicKeyResponse = { publicKey: string }; + + +export type VerifyEmailChangeResponse = { + oldEmail: string; + newEmail: string; +}; + +export type CheckChangeEmailExpirationResponse = { isExpired: boolean }; \ No newline at end of file