@internxt/sdk 1.10.2 → 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;
@@ -34,6 +34,13 @@ export declare class HttpClient {
34
34
  * @param headers
35
35
  */
36
36
  post<Response>(url: URL, params: Parameters, headers: Headers): Promise<Response>;
37
+ /**
38
+ * Requests a POST FORM
39
+ * @param url
40
+ * @param params
41
+ * @param headers
42
+ */
43
+ postForm<Response>(url: URL, params: Parameters, headers: Headers): Promise<Response>;
37
44
  /**
38
45
  * Requests a POST with option to cancel
39
46
  * @param url
@@ -72,6 +72,17 @@ var HttpClient = /** @class */ (function () {
72
72
  headers: headers,
73
73
  });
74
74
  };
75
+ /**
76
+ * Requests a POST FORM
77
+ * @param url
78
+ * @param params
79
+ * @param headers
80
+ */
81
+ HttpClient.prototype.postForm = function (url, params, headers) {
82
+ return this.axios.postForm(url, params, {
83
+ headers: headers,
84
+ });
85
+ };
75
86
  /**
76
87
  * Requests a POST with option to cancel
77
88
  * @param url
@@ -84,9 +84,9 @@ var Workspaces = /** @class */ (function () {
84
84
  * @returns The response from the server.
85
85
  */
86
86
  Workspaces.prototype.uploadWorkspaceAvatar = function (workspaceId, avatar) {
87
- var formData = new FormData();
88
- formData.append('file', avatar);
89
- return this.client.post("workspaces/".concat(workspaceId, "/avatar"), formData, __assign(__assign({}, this.headers()), { 'content-type': 'multipart/form-data' }));
87
+ return this.client.postForm("workspaces/".concat(workspaceId, "/avatar"), {
88
+ file: avatar,
89
+ }, this.headers());
90
90
  };
91
91
  Workspaces.prototype.deleteWorkspaceAvatar = function (workspaceId) {
92
92
  return this.client.delete("workspaces/".concat(workspaceId, "/avatar"), this.headers());
@@ -102,9 +102,9 @@ var Workspaces = /** @class */ (function () {
102
102
  return this.client.patch("workspaces/".concat(workspaceId), details, this.headers());
103
103
  };
104
104
  Workspaces.prototype.updateAvatar = function (workspaceId, payload) {
105
- var formData = new FormData();
106
- formData.set('file', payload.avatar);
107
- return this.client.post("workspaces/".concat(workspaceId, "/avatar"), formData, this.headers());
105
+ return this.client.postForm("workspaces/".concat(workspaceId, "/avatar"), {
106
+ file: payload.avatar,
107
+ }, this.headers());
108
108
  };
109
109
  Workspaces.prototype.deleteAvatar = function (workspaceId) {
110
110
  return this.client.delete("workspaces/".concat(workspaceId, "/avatar"), this.headers());
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@internxt/sdk",
3
3
  "author": "Internxt <hello@internxt.com>",
4
- "version": "1.10.2",
4
+ "version": "1.10.4",
5
5
  "description": "An sdk for interacting with Internxt's services",
6
6
  "repository": {
7
7
  "type": "git",