Skip to content

Commit 45a84c5

Browse files
authored
Merge pull request #308 from internxt/feature/PB-4498-securitum-invite-users-to-shared-item
[PB-4498] feature/Add new get public key call
2 parents 7aa6220 + a17fe64 commit 45a84c5

4 files changed

Lines changed: 75 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@internxt/sdk",
33
"author": "Internxt <hello@internxt.com>",
4-
"version": "1.10.3",
4+
"version": "1.10.4",
55
"description": "An sdk for interacting with Internxt's services",
66
"repository": {
77
"type": "git",

src/drive/users/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Token,
1313
UpdateProfilePayload,
1414
UserPublicKeyResponse,
15+
UserPublicKeyWithCreationResponse,
1516
VerifyEmailChangeResponse,
1617
} from './types';
1718

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

298+
/**
299+
* Get public key of given email, if not exists it pre-create user with this email
300+
* and returns public key
301+
* @param email
302+
* @returns {Promise<UserPublicKeyWithCreationResponse>} A promise that returns the public keys of given user
303+
*/
304+
public getPublicKeyWithPrecreation({ email }: { email: string }): Promise<UserPublicKeyWithCreationResponse> {
305+
return this.client.put<UserPublicKeyWithCreationResponse>(`/users/public-key/${email}`, {}, this.headers());
306+
}
307+
297308
/**
298309
* Generate mnemonic
299310
*/

src/drive/users/inext.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import sinon from 'sinon';
2+
import { Users } from '.';
3+
import { headersWithToken } from '../../shared/headers';
4+
import { HttpClient } from '../../shared/http/client';
5+
import { UserPublicKeyWithCreationResponse } from './types';
6+
7+
const httpClient = HttpClient.create('');
8+
9+
describe('Users service tests', () => {
10+
beforeEach(() => {
11+
sinon.stub(HttpClient, 'create').returns(httpClient);
12+
});
13+
14+
afterEach(() => {
15+
sinon.restore();
16+
});
17+
18+
describe('Users methods', () => {
19+
describe('getPublicKeyWithPrecreation', () => {
20+
it('should call the correct endpoint and return the public key response', async () => {
21+
const email = 'test@example.com';
22+
const publicKeyResponse: UserPublicKeyWithCreationResponse = {
23+
publicKey: 'public_key_example_123',
24+
publicKyberKey: 'kyber_key_example_123',
25+
};
26+
27+
const { client, headers } = clientAndHeaders();
28+
const putCall = sinon.stub(httpClient, 'put').resolves(publicKeyResponse);
29+
30+
const response = await client.getPublicKeyWithPrecreation({ email });
31+
32+
expect(putCall.firstCall.args).toEqual([`/users/public-key/${email}`, {}, headers]);
33+
expect(response).toEqual(publicKeyResponse);
34+
});
35+
});
36+
});
37+
});
38+
39+
function clientAndHeaders(
40+
apiUrl = '',
41+
clientName = 'c-name',
42+
clientVersion = '0.1',
43+
token = 'my-token',
44+
): {
45+
client: Users;
46+
headers: object;
47+
} {
48+
const appDetails = {
49+
clientName,
50+
clientVersion,
51+
};
52+
const apiSecurity = {
53+
token,
54+
unauthorizedCallback: () => {},
55+
};
56+
const client = Users.client(apiUrl, appDetails, apiSecurity);
57+
const headers = headersWithToken(clientName, clientVersion, token);
58+
return { client, headers };
59+
}

src/drive/users/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export type UpdateProfilePayload = Partial<Pick<UserSettings, 'name' | 'lastname
4545

4646
export type PreCreateUserResponse = {
4747
publicKey: string;
48-
keys?:
49-
{
48+
keys?: {
5049
ecc: string;
5150
kyber: string;
5251
};
@@ -55,7 +54,9 @@ export type PreCreateUserResponse = {
5554

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

58-
export type UserPublicKeyResponse = { publicKey: string; keys?: { ecc:string; kyber: string}; };
57+
export type UserPublicKeyResponse = { publicKey: string; keys?: { ecc: string; kyber: string } };
58+
59+
export type UserPublicKeyWithCreationResponse = { publicKey: string; publicKyberKey: string | undefined };
5960

6061
export type VerifyEmailChangeResponse = {
6162
oldEmail: string;

0 commit comments

Comments
 (0)