@internxt/sdk 1.4.77 → 1.5.25

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 +122 -122
  2. package/dist/auth/index.js +310 -310
  3. package/dist/auth/types.d.ts +54 -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 +19 -19
  11. package/dist/drive/payments/index.d.ts +71 -53
  12. package/dist/drive/payments/index.js +208 -153
  13. package/dist/drive/payments/types.d.ts +176 -114
  14. package/dist/drive/payments/types.js +37 -32
  15. package/dist/drive/referrals/index.d.ts +19 -19
  16. package/dist/drive/referrals/index.js +50 -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 +540 -539
  21. package/dist/drive/share/types.d.ts +360 -358
  22. package/dist/drive/share/types.js +2 -2
  23. package/dist/drive/storage/index.d.ts +315 -195
  24. package/dist/drive/storage/index.js +630 -434
  25. package/dist/drive/storage/types.d.ts +473 -394
  26. package/dist/drive/storage/types.js +13 -13
  27. package/dist/drive/trash/index.d.ts +75 -55
  28. package/dist/drive/trash/index.js +180 -149
  29. package/dist/drive/trash/types.d.ts +29 -20
  30. package/dist/drive/trash/types.js +2 -2
  31. package/dist/drive/users/index.d.ts +135 -108
  32. package/dist/drive/users/index.js +204 -174
  33. package/dist/drive/users/types.d.ts +51 -43
  34. package/dist/drive/users/types.js +2 -2
  35. package/dist/index.d.ts +6 -5
  36. package/dist/index.js +31 -30
  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 +48 -48
  45. package/dist/network/errors/index.d.ts +3 -3
  46. package/dist/network/errors/index.js +15 -15
  47. package/dist/network/errors/upload.d.ts +13 -13
  48. package/dist/network/errors/upload.js +78 -78
  49. package/dist/network/index.d.ts +70 -71
  50. package/dist/network/index.js +311 -310
  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 +159 -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 +52 -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 -18
  68. package/dist/shared/headers/index.js +79 -69
  69. package/dist/shared/http/client.d.ts +85 -85
  70. package/dist/shared/http/client.js +172 -181
  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 +13 -13
  75. package/dist/shared/types/apiConnection.d.ts +12 -11
  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 -4
  80. package/dist/shared/types/errors.js +28 -27
  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 +29 -27
  84. package/dist/shared/types/userSettings.js +2 -2
  85. package/dist/utils.d.ts +3 -3
  86. package/dist/utils.js +25 -25
  87. package/dist/workspaces/index.d.ts +176 -0
  88. package/dist/workspaces/index.js +415 -0
  89. package/dist/workspaces/index.test.d.ts +1 -0
  90. package/dist/workspaces/index.test.js +903 -0
  91. package/dist/workspaces/types.d.ts +291 -0
  92. package/dist/workspaces/types.js +2 -0
  93. package/package.json +1 -1
@@ -1,310 +1,310 @@
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
+ 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;