@internxt/sdk 1.5.25 → 1.6.3

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.
Files changed (93) hide show
  1. package/dist/auth/index.d.ts +127 -122
  2. package/dist/auth/index.js +378 -310
  3. package/dist/auth/types.d.ts +67 -54
  4. package/dist/auth/types.js +26 -26
  5. package/dist/drive/backups/index.d.ts +18 -18
  6. package/dist/drive/backups/index.js +40 -40
  7. package/dist/drive/backups/types.d.ts +27 -27
  8. package/dist/drive/backups/types.js +2 -2
  9. package/dist/drive/index.d.ts +7 -7
  10. package/dist/drive/index.js +23 -19
  11. package/dist/drive/payments/index.d.ts +66 -71
  12. package/dist/drive/payments/index.js +206 -208
  13. package/dist/drive/payments/types.d.ts +180 -176
  14. package/dist/drive/payments/types.js +37 -37
  15. package/dist/drive/referrals/index.d.ts +19 -19
  16. package/dist/drive/referrals/index.js +54 -50
  17. package/dist/drive/referrals/types.d.ts +21 -21
  18. package/dist/drive/referrals/types.js +18 -18
  19. package/dist/drive/share/index.d.ts +319 -319
  20. package/dist/drive/share/index.js +544 -540
  21. package/dist/drive/share/types.d.ts +360 -360
  22. package/dist/drive/share/types.js +2 -2
  23. package/dist/drive/storage/index.d.ts +315 -315
  24. package/dist/drive/storage/index.js +634 -630
  25. package/dist/drive/storage/types.d.ts +480 -473
  26. package/dist/drive/storage/types.js +13 -13
  27. package/dist/drive/trash/index.d.ts +75 -75
  28. package/dist/drive/trash/index.js +184 -180
  29. package/dist/drive/trash/types.d.ts +29 -29
  30. package/dist/drive/trash/types.js +2 -2
  31. package/dist/drive/users/index.d.ts +135 -135
  32. package/dist/drive/users/index.js +208 -204
  33. package/dist/drive/users/types.d.ts +53 -51
  34. package/dist/drive/users/types.js +2 -2
  35. package/dist/index.d.ts +6 -6
  36. package/dist/index.js +35 -31
  37. package/dist/network/download.d.ts +8 -8
  38. package/dist/network/download.js +123 -123
  39. package/dist/network/errors/codes.d.ts +24 -24
  40. package/dist/network/errors/codes.js +48 -48
  41. package/dist/network/errors/context.d.ts +35 -35
  42. package/dist/network/errors/context.js +39 -39
  43. package/dist/network/errors/download.d.ts +4 -4
  44. package/dist/network/errors/download.js +52 -48
  45. package/dist/network/errors/index.d.ts +3 -3
  46. package/dist/network/errors/index.js +19 -15
  47. package/dist/network/errors/upload.d.ts +13 -13
  48. package/dist/network/errors/upload.js +82 -78
  49. package/dist/network/index.d.ts +70 -70
  50. package/dist/network/index.js +315 -311
  51. package/dist/network/types.d.ts +102 -102
  52. package/dist/network/types.js +18 -18
  53. package/dist/network/upload.d.ts +4 -4
  54. package/dist/network/upload.js +158 -159
  55. package/dist/photos/devices/index.d.ts +10 -10
  56. package/dist/photos/devices/index.js +79 -79
  57. package/dist/photos/index.d.ts +17 -17
  58. package/dist/photos/index.js +56 -52
  59. package/dist/photos/photos/index.d.ts +60 -60
  60. package/dist/photos/photos/index.js +225 -225
  61. package/dist/photos/shares/index.d.ts +8 -8
  62. package/dist/photos/shares/index.js +34 -34
  63. package/dist/photos/types.d.ts +154 -154
  64. package/dist/photos/types.js +19 -19
  65. package/dist/photos/users/index.d.ts +7 -7
  66. package/dist/photos/users/index.js +46 -46
  67. package/dist/shared/headers/index.d.ts +21 -21
  68. package/dist/shared/headers/index.js +78 -79
  69. package/dist/shared/http/client.d.ts +85 -85
  70. package/dist/shared/http/client.js +172 -172
  71. package/dist/shared/http/types.d.ts +7 -7
  72. package/dist/shared/http/types.js +2 -2
  73. package/dist/shared/index.d.ts +1 -1
  74. package/dist/shared/index.js +17 -13
  75. package/dist/shared/types/apiConnection.d.ts +12 -12
  76. package/dist/shared/types/apiConnection.js +2 -2
  77. package/dist/shared/types/appsumo.d.ts +16 -16
  78. package/dist/shared/types/appsumo.js +12 -12
  79. package/dist/shared/types/errors.d.ts +5 -5
  80. package/dist/shared/types/errors.js +28 -28
  81. package/dist/shared/types/teams.d.ts +9 -9
  82. package/dist/shared/types/teams.js +2 -2
  83. package/dist/shared/types/userSettings.d.ts +43 -29
  84. package/dist/shared/types/userSettings.js +2 -2
  85. package/dist/utils.d.ts +3 -3
  86. package/dist/utils.js +24 -25
  87. package/dist/workspaces/index.d.ts +176 -176
  88. package/dist/workspaces/index.js +419 -415
  89. package/dist/workspaces/index.test.d.ts +1 -1
  90. package/dist/workspaces/index.test.js +908 -903
  91. package/dist/workspaces/types.d.ts +294 -291
  92. package/dist/workspaces/types.js +2 -2
  93. package/package.json +13 -13
@@ -1,310 +1,378 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- 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;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- Object.defineProperty(exports, "__esModule", { value: true });
49
- exports.Auth = void 0;
50
- var headers_1 = require("../shared/headers");
51
- var client_1 = require("../shared/http/client");
52
- __exportStar(require("./types"), exports);
53
- var Auth = /** @class */ (function () {
54
- function Auth(apiUrl, appDetails, apiSecurity) {
55
- this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
56
- this.appDetails = appDetails;
57
- this.apiSecurity = apiSecurity;
58
- this.apiUrl = apiUrl;
59
- }
60
- Auth.client = function (apiUrl, appDetails, apiSecurity) {
61
- return new Auth(apiUrl, appDetails, apiSecurity);
62
- };
63
- /**
64
- * Tries to register a new user
65
- * @param registerDetails
66
- */
67
- Auth.prototype.register = function (registerDetails) {
68
- return this.client.post('/users', {
69
- name: registerDetails.name,
70
- captcha: registerDetails.captcha,
71
- lastname: registerDetails.lastname,
72
- email: registerDetails.email,
73
- password: registerDetails.password,
74
- mnemonic: registerDetails.mnemonic,
75
- salt: registerDetails.salt,
76
- privateKey: registerDetails.keys.privateKeyEncrypted,
77
- publicKey: registerDetails.keys.publicKey,
78
- revocationKey: registerDetails.keys.revocationCertificate,
79
- referral: registerDetails.referral,
80
- referrer: registerDetails.referrer,
81
- }, this.basicHeaders());
82
- };
83
- /**
84
- * Registers a precreated user
85
- * @param registerDetails
86
- * @returns {Promise<RegisterPreCreatedUserResponse>} Returns sign in token, user data and uuid.
87
- */
88
- Auth.prototype.registerPreCreatedUser = function (registerDetails) {
89
- return this.client.post('users/pre-created-users/register', {
90
- name: registerDetails.name,
91
- captcha: registerDetails.captcha,
92
- lastname: registerDetails.lastname,
93
- email: registerDetails.email,
94
- password: registerDetails.password,
95
- mnemonic: registerDetails.mnemonic,
96
- salt: registerDetails.salt,
97
- privateKey: registerDetails.keys.privateKeyEncrypted,
98
- publicKey: registerDetails.keys.publicKey,
99
- revocationKey: registerDetails.keys.revocationCertificate,
100
- referral: registerDetails.referral,
101
- referrer: registerDetails.referrer,
102
- invitationId: registerDetails.invitationId,
103
- }, this.basicHeaders());
104
- };
105
- /**
106
- * Requests account unblock email
107
- *
108
- * @param {string} email - The email address associated with the account.
109
- * @returns {Promise<void>} - Resolves when the email is sent.
110
- */
111
- Auth.prototype.requestUnblockAccount = function (email) {
112
- return this.client.post('users/unblock-account', {
113
- email: email,
114
- }, this.basicHeaders());
115
- };
116
- /**
117
- * Unblocks account with token
118
- *
119
- * @param {string} token - The token received via email to verify and unblock the account.
120
- * @returns {Promise<void>} - Resolves successfuly when account is unblocked
121
- */
122
- Auth.prototype.unblockAccount = function (token) {
123
- return this.client.put('users/unblock-account', { token: token }, this.basicHeaders());
124
- };
125
- /**
126
- * Tries to log in a user given its login details
127
- * @param details
128
- * @param cryptoProvider
129
- */
130
- Auth.prototype.login = function (details, cryptoProvider) {
131
- return __awaiter(this, void 0, void 0, function () {
132
- var securityDetails, encryptedSalt, encryptedPasswordHash, keys;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0: return [4 /*yield*/, this.securityDetails(details.email)];
136
- case 1:
137
- securityDetails = _a.sent();
138
- encryptedSalt = securityDetails.encryptedSalt;
139
- encryptedPasswordHash = cryptoProvider.encryptPasswordHash(details.password, encryptedSalt);
140
- return [4 /*yield*/, cryptoProvider.generateKeys(details.password)];
141
- case 2:
142
- keys = _a.sent();
143
- return [2 /*return*/, this.client
144
- .post('/access', {
145
- email: details.email,
146
- password: encryptedPasswordHash,
147
- tfa: details.tfaCode,
148
- privateKey: keys.privateKeyEncrypted,
149
- publicKey: keys.publicKey,
150
- revocateKey: keys.revocationCertificate,
151
- }, this.basicHeaders())
152
- .then(function (data) {
153
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
154
- // @ts-ignore
155
- data.user.revocationKey = data.user.revocateKey; // TODO : remove when all projects use SDK
156
- return data;
157
- })];
158
- }
159
- });
160
- });
161
- };
162
- /**
163
- * Updates the asymmetric keys
164
- * @param keys
165
- * @param token
166
- */
167
- Auth.prototype.updateKeys = function (keys, token) {
168
- return this.client.patch('/user/keys', {
169
- publicKey: keys.publicKey,
170
- privateKey: keys.privateKeyEncrypted,
171
- revocationKey: keys.revocationCertificate,
172
- }, this.headersWithToken(token));
173
- };
174
- /**
175
- * Returns general security details
176
- * @param email
177
- */
178
- Auth.prototype.securityDetails = function (email) {
179
- return this.client
180
- .post('/login', {
181
- email: email,
182
- }, this.basicHeaders())
183
- .then(function (data) {
184
- return {
185
- encryptedSalt: data.sKey,
186
- tfaEnabled: data.tfa === true,
187
- };
188
- });
189
- };
190
- /**
191
- * Generates a new TwoFactorAuth code
192
- */
193
- Auth.prototype.generateTwoFactorAuthQR = function () {
194
- var _a;
195
- return this.client
196
- .get('/tfa', this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token))
197
- .then(function (data) {
198
- return {
199
- qr: data.qr,
200
- backupKey: data.code,
201
- };
202
- });
203
- };
204
- /**
205
- * Disables TwoFactorAuthentication
206
- * @param pass
207
- * @param code
208
- */
209
- Auth.prototype.disableTwoFactorAuth = function (pass, code) {
210
- var _a;
211
- return this.client.delete('/tfa', this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token), {
212
- pass: pass,
213
- code: code,
214
- });
215
- };
216
- /**
217
- * Store TwoFactorAuthentication details
218
- * @param backupKey
219
- * @param code
220
- */
221
- Auth.prototype.storeTwoFactorAuthKey = function (backupKey, code) {
222
- var _a;
223
- return this.client.put('/tfa', {
224
- key: backupKey,
225
- code: code,
226
- }, this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token));
227
- };
228
- /**
229
- * Sends request to send the email to delete the account
230
- * @param email
231
- */
232
- Auth.prototype.sendDeactivationEmail = function (email) {
233
- return this.client.get("/deactivate/" + email, this.basicHeaders());
234
- };
235
- /**
236
- * Confirms the account deactivation
237
- * @param token
238
- */
239
- Auth.prototype.confirmDeactivation = function (token) {
240
- return this.client.get("/confirmDeactivation/" + token, this.basicHeaders());
241
- };
242
- /**
243
- * Checks if the password is correct for this email
244
- * @param email
245
- * @param hashedPassword
246
- * @returns
247
- */
248
- Auth.prototype.areCredentialsCorrect = function (email, hashedPassword) {
249
- var _a;
250
- // Uses fetch instead of httpClient since a 401 response
251
- // would log out the user
252
- return fetch(this.apiUrl + "/are-credentials-correct?email=" + email + "&hashedPassword=" + hashedPassword, {
253
- headers: this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token),
254
- }).then(function (res) {
255
- if (res.ok) {
256
- return true;
257
- }
258
- else if (res.status === 401) {
259
- return false;
260
- }
261
- else
262
- throw new Error("Request failed with error " + res.status);
263
- });
264
- };
265
- /**
266
- * Send email to change password
267
- * @param email
268
- */
269
- Auth.prototype.sendChangePasswordEmail = function (email) {
270
- return this.client.post('/users/recover-account', {
271
- email: email,
272
- }, this.basicHeaders());
273
- };
274
- /**
275
- * Restore password with email link
276
- * @param token
277
- * @param password
278
- * @param salt
279
- * @param mnemonic
280
- */
281
- Auth.prototype.changePasswordWithLink = function (token, password, salt, mnemonic) {
282
- return this.client.put("/users/recover-account?token=" + token + "&reset=false", {
283
- password: password,
284
- salt: salt,
285
- mnemonic: mnemonic,
286
- }, this.basicHeaders());
287
- };
288
- /**
289
- * Reset account with token
290
- * @param token
291
- * @param password
292
- * @param salt
293
- * @param mnemonic
294
- */
295
- Auth.prototype.resetAccountWithToken = function (token, password, salt, mnemonic) {
296
- return this.client.put("/users/recover-account?token=" + token + "&reset=true", {
297
- password: password,
298
- salt: salt,
299
- mnemonic: mnemonic,
300
- }, this.basicHeaders());
301
- };
302
- Auth.prototype.basicHeaders = function () {
303
- return (0, headers_1.basicHeaders)(this.appDetails.clientName, this.appDetails.clientVersion);
304
- };
305
- Auth.prototype.headersWithToken = function (token) {
306
- return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, token);
307
- };
308
- return Auth;
309
- }());
310
- exports.Auth = Auth;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ 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);
27
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ 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;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.Auth = void 0;
54
+ var headers_1 = require("../shared/headers");
55
+ var client_1 = require("../shared/http/client");
56
+ __exportStar(require("./types"), exports);
57
+ var Auth = /** @class */ (function () {
58
+ function Auth(apiUrl, appDetails, apiSecurity) {
59
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
60
+ this.appDetails = appDetails;
61
+ this.apiSecurity = apiSecurity;
62
+ this.apiUrl = apiUrl;
63
+ }
64
+ Auth.client = function (apiUrl, appDetails, apiSecurity) {
65
+ return new Auth(apiUrl, appDetails, apiSecurity);
66
+ };
67
+ /**
68
+ * Tries to register a new user
69
+ * @param registerDetails
70
+ */
71
+ Auth.prototype.register = function (registerDetails) {
72
+ return this.client.post('/users', {
73
+ name: registerDetails.name,
74
+ captcha: registerDetails.captcha,
75
+ lastname: registerDetails.lastname,
76
+ email: registerDetails.email,
77
+ password: registerDetails.password,
78
+ mnemonic: registerDetails.mnemonic,
79
+ salt: registerDetails.salt,
80
+ /**
81
+ / @deprecated The individual fields for keys should not be used
82
+ */
83
+ privateKey: registerDetails.keys.privateKeyEncrypted,
84
+ publicKey: registerDetails.keys.publicKey,
85
+ revocationKey: registerDetails.keys.revocationCertificate,
86
+ keys: {
87
+ ecc: {
88
+ privateKey: registerDetails.keys.keys.ecc.privateKeyEncrypted,
89
+ publicKey: registerDetails.keys.keys.ecc.publicKey,
90
+ },
91
+ kyber: {
92
+ privateKey: registerDetails.keys.keys.kyber.privateKeyEncrypted,
93
+ publicKey: registerDetails.keys.keys.kyber.publicKey,
94
+ }
95
+ },
96
+ referral: registerDetails.referral,
97
+ referrer: registerDetails.referrer,
98
+ }, this.basicHeaders());
99
+ };
100
+ /**
101
+ * Registers a precreated user
102
+ * @param registerDetails
103
+ * @returns {Promise<RegisterPreCreatedUserResponse>} Returns sign in token, user data and uuid.
104
+ */
105
+ Auth.prototype.registerPreCreatedUser = function (registerDetails) {
106
+ return this.client.post('users/pre-created-users/register', {
107
+ name: registerDetails.name,
108
+ captcha: registerDetails.captcha,
109
+ lastname: registerDetails.lastname,
110
+ email: registerDetails.email,
111
+ password: registerDetails.password,
112
+ mnemonic: registerDetails.mnemonic,
113
+ salt: registerDetails.salt,
114
+ /**
115
+ / @deprecated The individual fields for keys should not be used
116
+ */
117
+ privateKey: registerDetails.keys.privateKeyEncrypted,
118
+ publicKey: registerDetails.keys.publicKey,
119
+ revocationKey: registerDetails.keys.revocationCertificate,
120
+ keys: {
121
+ ecc: {
122
+ privateKey: registerDetails.keys.keys.ecc.privateKeyEncrypted,
123
+ publicKey: registerDetails.keys.keys.ecc.publicKey,
124
+ },
125
+ kyber: {
126
+ privateKey: registerDetails.keys.keys.kyber.privateKeyEncrypted,
127
+ publicKey: registerDetails.keys.keys.kyber.publicKey,
128
+ }
129
+ },
130
+ referral: registerDetails.referral,
131
+ referrer: registerDetails.referrer,
132
+ invitationId: registerDetails.invitationId,
133
+ }, this.basicHeaders());
134
+ };
135
+ /**
136
+ * Requests account unblock email
137
+ *
138
+ * @param {string} email - The email address associated with the account.
139
+ * @returns {Promise<void>} - Resolves when the email is sent.
140
+ */
141
+ Auth.prototype.requestUnblockAccount = function (email) {
142
+ return this.client.post('users/unblock-account', {
143
+ email: email,
144
+ }, this.basicHeaders());
145
+ };
146
+ /**
147
+ * Unblocks account with token
148
+ *
149
+ * @param {string} token - The token received via email to verify and unblock the account.
150
+ * @returns {Promise<void>} - Resolves successfuly when account is unblocked
151
+ */
152
+ Auth.prototype.unblockAccount = function (token) {
153
+ return this.client.put('users/unblock-account', { token: token }, this.basicHeaders());
154
+ };
155
+ /**
156
+ * Tries to log in a user given its login details
157
+ * @param details
158
+ * @param cryptoProvider
159
+ */
160
+ Auth.prototype.login = function (details, cryptoProvider) {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ var securityDetails, encryptedSalt, encryptedPasswordHash, keys;
163
+ return __generator(this, function (_a) {
164
+ switch (_a.label) {
165
+ case 0: return [4 /*yield*/, this.securityDetails(details.email)];
166
+ case 1:
167
+ securityDetails = _a.sent();
168
+ encryptedSalt = securityDetails.encryptedSalt;
169
+ return [4 /*yield*/, cryptoProvider.encryptPasswordHash(details.password, encryptedSalt)];
170
+ case 2:
171
+ encryptedPasswordHash = _a.sent();
172
+ return [4 /*yield*/, cryptoProvider.generateKeys(details.password)];
173
+ case 3:
174
+ keys = _a.sent();
175
+ return [2 /*return*/, this.client
176
+ .post('/access', {
177
+ email: details.email,
178
+ password: encryptedPasswordHash,
179
+ tfa: details.tfaCode,
180
+ /**
181
+ / @deprecated The individual fields for keys should not be used
182
+ */
183
+ privateKey: keys.privateKeyEncrypted,
184
+ publicKey: keys.publicKey,
185
+ revocateKey: keys.revocationCertificate,
186
+ keys: {
187
+ ecc: {
188
+ privateKey: keys.keys.ecc.privateKeyEncrypted,
189
+ publicKey: keys.keys.ecc.publicKey,
190
+ },
191
+ kyber: {
192
+ privateKey: keys.keys.kyber.privateKeyEncrypted,
193
+ publicKey: keys.keys.kyber.publicKey,
194
+ }
195
+ },
196
+ }, this.basicHeaders())
197
+ .then(function (data) {
198
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
199
+ // @ts-ignore
200
+ data.user.revocationKey = data.user.revocateKey; // TODO : remove when all projects use SDK
201
+ return data;
202
+ })];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ /**
208
+ * Updates the asymmetric keys
209
+ * @param keys
210
+ * @param token
211
+ */
212
+ Auth.prototype.updateKeys = function (keys, token) {
213
+ return this.client.patch('/user/keys', {
214
+ /**
215
+ / @deprecated The individual fields for keys should not be used
216
+ */
217
+ publicKey: keys.publicKey,
218
+ privateKey: keys.privateKeyEncrypted,
219
+ revocationKey: keys.revocationCertificate,
220
+ keys: {
221
+ ecc: {
222
+ privateKey: keys.keys.ecc.privateKeyEncrypted,
223
+ publicKey: keys.keys.ecc.publicKey,
224
+ },
225
+ kyber: {
226
+ privateKey: keys.keys.kyber.privateKeyEncrypted,
227
+ publicKey: keys.keys.kyber.publicKey,
228
+ }
229
+ },
230
+ }, this.headersWithToken(token));
231
+ };
232
+ /**
233
+ * Returns general security details
234
+ * @param email
235
+ */
236
+ Auth.prototype.securityDetails = function (email) {
237
+ return this.client
238
+ .post('/login', {
239
+ email: email,
240
+ }, this.basicHeaders())
241
+ .then(function (data) {
242
+ return {
243
+ encryptedSalt: data.sKey,
244
+ tfaEnabled: data.tfa === true,
245
+ };
246
+ });
247
+ };
248
+ /**
249
+ * Generates a new TwoFactorAuth code
250
+ */
251
+ Auth.prototype.generateTwoFactorAuthQR = function () {
252
+ var _a;
253
+ return this.client
254
+ .get('/tfa', this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token))
255
+ .then(function (data) {
256
+ return {
257
+ qr: data.qr,
258
+ backupKey: data.code,
259
+ };
260
+ });
261
+ };
262
+ /**
263
+ * Disables TwoFactorAuthentication
264
+ * @param pass
265
+ * @param code
266
+ */
267
+ Auth.prototype.disableTwoFactorAuth = function (pass, code) {
268
+ var _a;
269
+ return this.client.delete('/tfa', this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token), {
270
+ pass: pass,
271
+ code: code,
272
+ });
273
+ };
274
+ /**
275
+ * Store TwoFactorAuthentication details
276
+ * @param backupKey
277
+ * @param code
278
+ */
279
+ Auth.prototype.storeTwoFactorAuthKey = function (backupKey, code) {
280
+ var _a;
281
+ return this.client.put('/tfa', {
282
+ key: backupKey,
283
+ code: code,
284
+ }, this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token));
285
+ };
286
+ /**
287
+ * Sends request to send the email to delete the account
288
+ * @param email
289
+ */
290
+ Auth.prototype.sendDeactivationEmail = function (email) {
291
+ return this.client.get("/deactivate/".concat(email), this.basicHeaders());
292
+ };
293
+ /**
294
+ * Confirms the account deactivation
295
+ * @param token
296
+ */
297
+ Auth.prototype.confirmDeactivation = function (token) {
298
+ return this.client.get("/confirmDeactivation/".concat(token), this.basicHeaders());
299
+ };
300
+ /**
301
+ * Checks if the password is correct for this email
302
+ * @param email
303
+ * @param hashedPassword
304
+ * @returns
305
+ */
306
+ Auth.prototype.areCredentialsCorrect = function (email, hashedPassword) {
307
+ var _a;
308
+ // Uses fetch instead of httpClient since a 401 response
309
+ // would log out the user
310
+ return fetch("".concat(this.apiUrl, "/are-credentials-correct?email=").concat(email, "&hashedPassword=").concat(hashedPassword), {
311
+ headers: this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token),
312
+ }).then(function (res) {
313
+ if (res.ok) {
314
+ return true;
315
+ }
316
+ else if (res.status === 401) {
317
+ return false;
318
+ }
319
+ else
320
+ throw new Error("Request failed with error ".concat(res.status));
321
+ });
322
+ };
323
+ /**
324
+ * Send email to change password
325
+ * @param email
326
+ */
327
+ Auth.prototype.sendChangePasswordEmail = function (email) {
328
+ return this.client.post('/users/recover-account', {
329
+ email: email,
330
+ }, this.basicHeaders());
331
+ };
332
+ /**
333
+ * Upgrade hash in the database
334
+ * @param newHash
335
+ */
336
+ Auth.prototype.upgradeHash = function (newHash) {
337
+ return this.client.patch('/users/:id', {
338
+ newPassword: newHash,
339
+ newSalt: '',
340
+ }, this.basicHeaders());
341
+ };
342
+ /**
343
+ * Restore password with email link
344
+ * @param token
345
+ * @param password
346
+ * @param salt
347
+ * @param mnemonic
348
+ */
349
+ Auth.prototype.changePasswordWithLink = function (token, password, salt, mnemonic) {
350
+ return this.client.put("/users/recover-account?token=".concat(token, "&reset=false"), {
351
+ password: password,
352
+ salt: salt,
353
+ mnemonic: mnemonic,
354
+ }, this.basicHeaders());
355
+ };
356
+ /**
357
+ * Reset account with token
358
+ * @param token
359
+ * @param password
360
+ * @param salt
361
+ * @param mnemonic
362
+ */
363
+ Auth.prototype.resetAccountWithToken = function (token, password, salt, mnemonic) {
364
+ return this.client.put("/users/recover-account?token=".concat(token, "&reset=true"), {
365
+ password: password,
366
+ salt: salt,
367
+ mnemonic: mnemonic,
368
+ }, this.basicHeaders());
369
+ };
370
+ Auth.prototype.basicHeaders = function () {
371
+ return (0, headers_1.basicHeaders)(this.appDetails.clientName, this.appDetails.clientVersion);
372
+ };
373
+ Auth.prototype.headersWithToken = function (token) {
374
+ return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, token);
375
+ };
376
+ return Auth;
377
+ }());
378
+ exports.Auth = Auth;