@internxt/sdk 1.10.3 → 1.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiSecurity, ApiUrl, AppDetails } from '../../shared';
|
|
2
2
|
import { UserSettings } from '../../shared/types/userSettings';
|
|
3
|
-
import { ChangePasswordPayload, ChangePasswordPayloadNew, CheckChangeEmailExpirationResponse, FriendInvite, InitializeUserResponse, PreCreateUserResponse, Token, UpdateProfilePayload, UserPublicKeyResponse, VerifyEmailChangeResponse } from './types';
|
|
3
|
+
import { ChangePasswordPayload, ChangePasswordPayloadNew, CheckChangeEmailExpirationResponse, FriendInvite, InitializeUserResponse, PreCreateUserResponse, Token, UpdateProfilePayload, UserPublicKeyResponse, UserPublicKeyWithCreationResponse, VerifyEmailChangeResponse } from './types';
|
|
4
4
|
export * as UserTypes from './types';
|
|
5
5
|
export declare class Users {
|
|
6
6
|
private readonly client;
|
|
@@ -152,6 +152,15 @@ export declare class Users {
|
|
|
152
152
|
getPublicKeyByEmail({ email }: {
|
|
153
153
|
email: string;
|
|
154
154
|
}): Promise<UserPublicKeyResponse>;
|
|
155
|
+
/**
|
|
156
|
+
* Get public key of given email, if not exists it pre-create user with this email
|
|
157
|
+
* and returns public key
|
|
158
|
+
* @param email
|
|
159
|
+
* @returns {Promise<UserPublicKeyWithCreationResponse>} A promise that returns the public keys of given user
|
|
160
|
+
*/
|
|
161
|
+
getPublicKeyWithPrecreation({ email }: {
|
|
162
|
+
email: string;
|
|
163
|
+
}): Promise<UserPublicKeyWithCreationResponse>;
|
|
155
164
|
/**
|
|
156
165
|
* Generate mnemonic
|
|
157
166
|
*/
|
|
@@ -280,6 +280,16 @@ var Users = /** @class */ (function () {
|
|
|
280
280
|
var email = _a.email;
|
|
281
281
|
return this.client.get("/users/public-key/".concat(email), this.headers());
|
|
282
282
|
};
|
|
283
|
+
/**
|
|
284
|
+
* Get public key of given email, if not exists it pre-create user with this email
|
|
285
|
+
* and returns public key
|
|
286
|
+
* @param email
|
|
287
|
+
* @returns {Promise<UserPublicKeyWithCreationResponse>} A promise that returns the public keys of given user
|
|
288
|
+
*/
|
|
289
|
+
Users.prototype.getPublicKeyWithPrecreation = function (_a) {
|
|
290
|
+
var email = _a.email;
|
|
291
|
+
return this.client.put("/users/public-key/".concat(email), {}, this.headers());
|
|
292
|
+
};
|
|
283
293
|
/**
|
|
284
294
|
* Generate mnemonic
|
|
285
295
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var sinon_1 = __importDefault(require("sinon"));
|
|
43
|
+
var _1 = require(".");
|
|
44
|
+
var headers_1 = require("../../shared/headers");
|
|
45
|
+
var client_1 = require("../../shared/http/client");
|
|
46
|
+
var httpClient = client_1.HttpClient.create('');
|
|
47
|
+
describe('Users service tests', function () {
|
|
48
|
+
beforeEach(function () {
|
|
49
|
+
sinon_1.default.stub(client_1.HttpClient, 'create').returns(httpClient);
|
|
50
|
+
});
|
|
51
|
+
afterEach(function () {
|
|
52
|
+
sinon_1.default.restore();
|
|
53
|
+
});
|
|
54
|
+
describe('Users methods', function () {
|
|
55
|
+
describe('getPublicKeyWithPrecreation', function () {
|
|
56
|
+
it('should call the correct endpoint and return the public key response', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
57
|
+
var email, publicKeyResponse, _a, client, headers, putCall, response;
|
|
58
|
+
return __generator(this, function (_b) {
|
|
59
|
+
switch (_b.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
email = 'test@example.com';
|
|
62
|
+
publicKeyResponse = {
|
|
63
|
+
publicKey: 'public_key_example_123',
|
|
64
|
+
publicKyberKey: 'kyber_key_example_123',
|
|
65
|
+
};
|
|
66
|
+
_a = clientAndHeaders(), client = _a.client, headers = _a.headers;
|
|
67
|
+
putCall = sinon_1.default.stub(httpClient, 'put').resolves(publicKeyResponse);
|
|
68
|
+
return [4 /*yield*/, client.getPublicKeyWithPrecreation({ email: email })];
|
|
69
|
+
case 1:
|
|
70
|
+
response = _b.sent();
|
|
71
|
+
expect(putCall.firstCall.args).toEqual(["/users/public-key/".concat(email), {}, headers]);
|
|
72
|
+
expect(response).toEqual(publicKeyResponse);
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}); });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
function clientAndHeaders(apiUrl, clientName, clientVersion, token) {
|
|
81
|
+
if (apiUrl === void 0) { apiUrl = ''; }
|
|
82
|
+
if (clientName === void 0) { clientName = 'c-name'; }
|
|
83
|
+
if (clientVersion === void 0) { clientVersion = '0.1'; }
|
|
84
|
+
if (token === void 0) { token = 'my-token'; }
|
|
85
|
+
var appDetails = {
|
|
86
|
+
clientName: clientName,
|
|
87
|
+
clientVersion: clientVersion,
|
|
88
|
+
};
|
|
89
|
+
var apiSecurity = {
|
|
90
|
+
token: token,
|
|
91
|
+
unauthorizedCallback: function () { },
|
|
92
|
+
};
|
|
93
|
+
var client = _1.Users.client(apiUrl, appDetails, apiSecurity);
|
|
94
|
+
var headers = (0, headers_1.headersWithToken)(clientName, clientVersion, token);
|
|
95
|
+
return { client: client, headers: headers };
|
|
96
|
+
}
|
|
@@ -60,6 +60,10 @@ export type UserPublicKeyResponse = {
|
|
|
60
60
|
kyber: string;
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
|
+
export type UserPublicKeyWithCreationResponse = {
|
|
64
|
+
publicKey: string;
|
|
65
|
+
publicKyberKey: string | undefined;
|
|
66
|
+
};
|
|
63
67
|
export type VerifyEmailChangeResponse = {
|
|
64
68
|
oldEmail: string;
|
|
65
69
|
newEmail: string;
|