Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <[email protected]>",
"version": "1.10.3",
"version": "1.10.4",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
11 changes: 11 additions & 0 deletions src/drive/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Token,
UpdateProfilePayload,
UserPublicKeyResponse,
UserPublicKeyWithCreationResponse,
VerifyEmailChangeResponse,
} from './types';

Expand Down Expand Up @@ -294,6 +295,16 @@ export class Users {
return this.client.get<UserPublicKeyResponse>(`/users/public-key/${email}`, this.headers());
}

/**
* Get public key of given email, if not exists it pre-create user with this email
* and returns public key
* @param email
* @returns {Promise<UserPublicKeyWithCreationResponse>} A promise that returns the public keys of given user
*/
public getPublicKeyWithPrecreation({ email }: { email: string }): Promise<UserPublicKeyWithCreationResponse> {
return this.client.put<UserPublicKeyWithCreationResponse>(`/users/public-key/${email}`, {}, this.headers());
}

/**
* Generate mnemonic
*/
Expand Down
59 changes: 59 additions & 0 deletions src/drive/users/inext.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sinon from 'sinon';
import { Users } from '.';
import { headersWithToken } from '../../shared/headers';
import { HttpClient } from '../../shared/http/client';
import { UserPublicKeyWithCreationResponse } from './types';

const httpClient = HttpClient.create('');

describe('Users service tests', () => {
beforeEach(() => {
sinon.stub(HttpClient, 'create').returns(httpClient);
});

afterEach(() => {
sinon.restore();
});

describe('Users methods', () => {
describe('getPublicKeyWithPrecreation', () => {
it('should call the correct endpoint and return the public key response', async () => {
const email = '[email protected]';
const publicKeyResponse: UserPublicKeyWithCreationResponse = {
publicKey: 'public_key_example_123',
publicKyberKey: 'kyber_key_example_123',
};

const { client, headers } = clientAndHeaders();
const putCall = sinon.stub(httpClient, 'put').resolves(publicKeyResponse);

const response = await client.getPublicKeyWithPrecreation({ email });

expect(putCall.firstCall.args).toEqual([`/users/public-key/${email}`, {}, headers]);
expect(response).toEqual(publicKeyResponse);
});
});
});
});

function clientAndHeaders(
apiUrl = '',
clientName = 'c-name',
clientVersion = '0.1',
token = 'my-token',
): {
client: Users;
headers: object;
} {
const appDetails = {
clientName,
clientVersion,
};
const apiSecurity = {
token,
unauthorizedCallback: () => {},
};
const client = Users.client(apiUrl, appDetails, apiSecurity);
const headers = headersWithToken(clientName, clientVersion, token);
return { client, headers };
}
7 changes: 4 additions & 3 deletions src/drive/users/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export type UpdateProfilePayload = Partial<Pick<UserSettings, 'name' | 'lastname

export type PreCreateUserResponse = {
publicKey: string;
keys?:
{
keys?: {
ecc: string;
kyber: string;
};
Expand All @@ -55,7 +54,9 @@ export type PreCreateUserResponse = {

export type FriendInvite = { guestEmail: string; host: number; accepted: boolean; id: number };

export type UserPublicKeyResponse = { publicKey: string; keys?: { ecc:string; kyber: string}; };
export type UserPublicKeyResponse = { publicKey: string; keys?: { ecc: string; kyber: string } };

export type UserPublicKeyWithCreationResponse = { publicKey: string; publicKyberKey: string | undefined };

export type VerifyEmailChangeResponse = {
oldEmail: string;
Expand Down
Loading