@internxt/sdk 1.13.1 → 1.14.2

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './auth';
2
+ export { AppError } from './shared';
2
3
  export * as Drive from './drive';
3
4
  export * as Network from './network';
4
5
  export * as Shared from './shared';
@@ -6,3 +7,4 @@ export * as Workspaces from './workspaces';
6
7
  export * from './meet';
7
8
  export * as Payments from './payments';
8
9
  export * from './misc';
10
+ export * from './mail';
package/dist/index.js CHANGED
@@ -36,8 +36,10 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Payments = exports.Workspaces = exports.Shared = exports.Network = exports.Drive = void 0;
39
+ exports.Payments = exports.Workspaces = exports.Shared = exports.Network = exports.Drive = exports.AppError = void 0;
40
40
  __exportStar(require("./auth"), exports);
41
+ var shared_1 = require("./shared");
42
+ Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return shared_1.AppError; } });
41
43
  exports.Drive = __importStar(require("./drive"));
42
44
  exports.Network = __importStar(require("./network"));
43
45
  exports.Shared = __importStar(require("./shared"));
@@ -45,3 +47,4 @@ exports.Workspaces = __importStar(require("./workspaces"));
45
47
  __exportStar(require("./meet"), exports);
46
48
  exports.Payments = __importStar(require("./payments"));
47
49
  __exportStar(require("./misc"), exports);
50
+ __exportStar(require("./mail"), exports);
@@ -0,0 +1,132 @@
1
+ import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
2
+ import { EncryptedKeystore, KeystoreType, PrivateKeys, HybridEncryptedEmail, PwdProtectedEmail, EmailKeys, Email, UserWithPublicKeys } from 'internxt-crypto';
3
+ export declare class Mail {
4
+ private readonly client;
5
+ private readonly appDetails;
6
+ private readonly apiSecurity;
7
+ private readonly apiUrl;
8
+ static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): Mail;
9
+ private constructor();
10
+ /**
11
+ * Uploads encrypted keystore to the server
12
+ *
13
+ * @param encryptedKeystore - The encrypted keystore
14
+ * @returns Server response
15
+ */
16
+ uploadKeystoreToServer(encryptedKeystore: EncryptedKeystore): Promise<void>;
17
+ /**
18
+ * Creates recovery and encryption keystores and uploads them to the server
19
+ *
20
+ * @param userEmail - The email of the user
21
+ * @param baseKey - The secret key of the user
22
+ * @returns The recovery codes for opening recovery keystore
23
+ */
24
+ createAndUploadKeystores(userEmail: string, baseKey: Uint8Array): Promise<string>;
25
+ /**
26
+ * Requests encrypted keystore from the server
27
+ *
28
+ * @param userEmail - The email of the user
29
+ * @param keystoreType - The type of the keystore
30
+ * @returns The encrypted keystore
31
+ */
32
+ downloadKeystoreFromServer(userEmail: string, keystoreType: KeystoreType): Promise<EncryptedKeystore>;
33
+ /**
34
+ * Requests encrypted keystore from the server and opens it
35
+ *
36
+ * @param userEmail - The email of the user
37
+ * @param baseKey - The secret key of the user
38
+ * @returns The email keys of the user
39
+ */
40
+ getUserEmailKeys(userEmail: string, baseKey: Uint8Array): Promise<EmailKeys>;
41
+ /**
42
+ * Requests recovery keystore from the server and opens it
43
+ *
44
+ * @param userEmail - The email of the user
45
+ * @param recoveryCodes - The recovery codes of the user
46
+ * @returns The email keys of the user
47
+ */
48
+ recoverUserEmailKeys(userEmail: string, recoveryCodes: string): Promise<EmailKeys>;
49
+ /**
50
+ * Request user with corresponding public keys from the server
51
+ *
52
+ * @param userEmail - The email of the user
53
+ * @returns User with corresponding public keys
54
+ */
55
+ getUserWithPublicKeys(userEmail: string): Promise<UserWithPublicKeys>;
56
+ /**
57
+ * Request users with corresponding public keys from the server
58
+ *
59
+ * @param emails - The emails of the users
60
+ * @returns Users with corresponding public keys
61
+ */
62
+ getSeveralUsersWithPublicKeys(emails: string[]): Promise<UserWithPublicKeys[]>;
63
+ /**
64
+ * Sends the encrypted email to the server
65
+ *
66
+ * @param email - The encrypted email
67
+ * @returns Server response
68
+ */
69
+ sendEncryptedEmail(email: HybridEncryptedEmail): Promise<void>;
70
+ /**
71
+ * Encrypts email and sends it to the server
72
+ *
73
+ * @param email - The message to encrypt
74
+ * @param senderPrivateKeys - The private keys of the sender
75
+ * @param isSubjectEncrypted - Indicates if the subject field should be encrypted
76
+ * @returns Server response
77
+ */
78
+ encryptAndSendEmail(email: Email, senderPrivateKeys: PrivateKeys, isSubjectEncrypted?: boolean): Promise<void>;
79
+ /**
80
+ * Sends the encrypted emails for multiple recipients to the server
81
+ *
82
+ * @param emails - The encrypted emails
83
+ * @returns Server response
84
+ */
85
+ sendEncryptedEmailToMultipleRecipients(emails: HybridEncryptedEmail[]): Promise<void>;
86
+ /**
87
+ * Encrypts emails for multiple recipients and sends emails to the server
88
+ *
89
+ * @param email - The message to encrypt
90
+ * @param senderPrivateKeys - The private keys of the sender
91
+ * @param isSubjectEncrypted - Indicates if the subject field should be encrypted
92
+ * @returns Server response
93
+ */
94
+ encryptAndSendEmailToMultipleRecipients(email: Email, senderPrivateKeys: PrivateKeys, isSubjectEncrypted?: boolean): Promise<void>;
95
+ /**
96
+ * Sends the password-protected email to the server
97
+ *
98
+ * @param email - The password-protected email
99
+ * @returns Server response
100
+ */
101
+ sendPasswordProtectedEmail(email: PwdProtectedEmail): Promise<void>;
102
+ /**
103
+ * Creates the password-protected email and sends it to the server
104
+ *
105
+ * @param email - The email
106
+ * @param pwd - The password
107
+ * @param isSubjectEncrypted - Indicates if the subject field should be encrypted
108
+ * @returns Server response
109
+ */
110
+ passwordProtectAndSendEmail(email: Email, pwd: string, isSubjectEncrypted?: boolean): Promise<void>;
111
+ /**
112
+ * Opens the password-protected email
113
+ *
114
+ * @param email - The password-protected email
115
+ * @param pwd - The shared password
116
+ * @returns The decrypted email
117
+ */
118
+ openPasswordProtectedEmail(email: PwdProtectedEmail, pwd: string): Promise<Email>;
119
+ /**
120
+ * Decrypt the email
121
+ *
122
+ * @param email - The encrypted email
123
+ * @param recipientPrivateKeys - The private keys of the email recipient
124
+ * @returns The decrypted email
125
+ */
126
+ decryptEmail(email: HybridEncryptedEmail, recipientPrivateKeys: PrivateKeys): Promise<Email>;
127
+ /**
128
+ * Returns the needed headers for the module requests
129
+ * @private
130
+ */
131
+ private headers;
132
+ }
@@ -0,0 +1,379 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ 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);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Mail = void 0;
51
+ var headers_1 = require("../shared/headers");
52
+ var client_1 = require("../shared/http/client");
53
+ var internxt_crypto_1 = require("internxt-crypto");
54
+ var Mail = /** @class */ (function () {
55
+ function Mail(apiUrl, appDetails, apiSecurity) {
56
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
57
+ this.appDetails = appDetails;
58
+ this.apiSecurity = apiSecurity;
59
+ this.apiUrl = apiUrl;
60
+ }
61
+ Mail.client = function (apiUrl, appDetails, apiSecurity) {
62
+ return new Mail(apiUrl, appDetails, apiSecurity);
63
+ };
64
+ /**
65
+ * Uploads encrypted keystore to the server
66
+ *
67
+ * @param encryptedKeystore - The encrypted keystore
68
+ * @returns Server response
69
+ */
70
+ Mail.prototype.uploadKeystoreToServer = function (encryptedKeystore) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ return __generator(this, function (_a) {
73
+ return [2 /*return*/, this.client.post("".concat(this.apiUrl, "/keystore"), { encryptedKeystore: encryptedKeystore }, this.headers())];
74
+ });
75
+ });
76
+ };
77
+ /**
78
+ * Creates recovery and encryption keystores and uploads them to the server
79
+ *
80
+ * @param userEmail - The email of the user
81
+ * @param baseKey - The secret key of the user
82
+ * @returns The recovery codes for opening recovery keystore
83
+ */
84
+ Mail.prototype.createAndUploadKeystores = function (userEmail, baseKey) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var _a, encryptionKeystore, recoveryKeystore, recoveryCodes;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
89
+ case 0: return [4 /*yield*/, (0, internxt_crypto_1.createEncryptionAndRecoveryKeystores)(userEmail, baseKey)];
90
+ case 1:
91
+ _a = _b.sent(), encryptionKeystore = _a.encryptionKeystore, recoveryKeystore = _a.recoveryKeystore, recoveryCodes = _a.recoveryCodes;
92
+ return [4 /*yield*/, Promise.all([this.uploadKeystoreToServer(encryptionKeystore), this.uploadKeystoreToServer(recoveryKeystore)])];
93
+ case 2:
94
+ _b.sent();
95
+ return [2 /*return*/, recoveryCodes];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ /**
101
+ * Requests encrypted keystore from the server
102
+ *
103
+ * @param userEmail - The email of the user
104
+ * @param keystoreType - The type of the keystore
105
+ * @returns The encrypted keystore
106
+ */
107
+ Mail.prototype.downloadKeystoreFromServer = function (userEmail, keystoreType) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ return __generator(this, function (_a) {
110
+ return [2 /*return*/, this.client.getWithParams("".concat(this.apiUrl, "/user/keystore"), { userEmail: userEmail, keystoreType: keystoreType }, this.headers())];
111
+ });
112
+ });
113
+ };
114
+ /**
115
+ * Requests encrypted keystore from the server and opens it
116
+ *
117
+ * @param userEmail - The email of the user
118
+ * @param baseKey - The secret key of the user
119
+ * @returns The email keys of the user
120
+ */
121
+ Mail.prototype.getUserEmailKeys = function (userEmail, baseKey) {
122
+ return __awaiter(this, void 0, void 0, function () {
123
+ var keystore;
124
+ return __generator(this, function (_a) {
125
+ switch (_a.label) {
126
+ case 0: return [4 /*yield*/, this.downloadKeystoreFromServer(userEmail, internxt_crypto_1.KeystoreType.ENCRYPTION)];
127
+ case 1:
128
+ keystore = _a.sent();
129
+ return [2 /*return*/, (0, internxt_crypto_1.openEncryptionKeystore)(keystore, baseKey)];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ /**
135
+ * Requests recovery keystore from the server and opens it
136
+ *
137
+ * @param userEmail - The email of the user
138
+ * @param recoveryCodes - The recovery codes of the user
139
+ * @returns The email keys of the user
140
+ */
141
+ Mail.prototype.recoverUserEmailKeys = function (userEmail, recoveryCodes) {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var keystore;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0: return [4 /*yield*/, this.downloadKeystoreFromServer(userEmail, internxt_crypto_1.KeystoreType.RECOVERY)];
147
+ case 1:
148
+ keystore = _a.sent();
149
+ return [2 /*return*/, (0, internxt_crypto_1.openRecoveryKeystore)(recoveryCodes, keystore)];
150
+ }
151
+ });
152
+ });
153
+ };
154
+ /**
155
+ * Request user with corresponding public keys from the server
156
+ *
157
+ * @param userEmail - The email of the user
158
+ * @returns User with corresponding public keys
159
+ */
160
+ Mail.prototype.getUserWithPublicKeys = function (userEmail) {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ var response, singleResponse, publicKeys, result;
163
+ return __generator(this, function (_a) {
164
+ switch (_a.label) {
165
+ case 0: return [4 /*yield*/, this.client.post("".concat(this.apiUrl, "/users/public-keys"), { emails: [userEmail] }, this.headers())];
166
+ case 1:
167
+ response = _a.sent();
168
+ if (!response[0])
169
+ throw new Error("No public keys found for ".concat(userEmail));
170
+ singleResponse = response[0];
171
+ return [4 /*yield*/, (0, internxt_crypto_1.base64ToPublicKey)(singleResponse.publicKeys)];
172
+ case 2:
173
+ publicKeys = _a.sent();
174
+ result = __assign(__assign({}, singleResponse.user), { publicKeys: publicKeys });
175
+ return [2 /*return*/, result];
176
+ }
177
+ });
178
+ });
179
+ };
180
+ /**
181
+ * Request users with corresponding public keys from the server
182
+ *
183
+ * @param emails - The emails of the users
184
+ * @returns Users with corresponding public keys
185
+ */
186
+ Mail.prototype.getSeveralUsersWithPublicKeys = function (emails) {
187
+ return __awaiter(this, void 0, void 0, function () {
188
+ var response, result;
189
+ var _this = this;
190
+ return __generator(this, function (_a) {
191
+ switch (_a.label) {
192
+ case 0: return [4 /*yield*/, this.client.post("".concat(this.apiUrl, "/users/public-keys"), { emails: emails }, this.headers())];
193
+ case 1:
194
+ response = _a.sent();
195
+ return [4 /*yield*/, Promise.all(response.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
196
+ var publicKeys;
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0: return [4 /*yield*/, (0, internxt_crypto_1.base64ToPublicKey)(item.publicKeys)];
200
+ case 1:
201
+ publicKeys = _a.sent();
202
+ return [2 /*return*/, __assign(__assign({}, item.user), { publicKeys: publicKeys })];
203
+ }
204
+ });
205
+ }); }))];
206
+ case 2:
207
+ result = _a.sent();
208
+ return [2 /*return*/, result];
209
+ }
210
+ });
211
+ });
212
+ };
213
+ /**
214
+ * Sends the encrypted email to the server
215
+ *
216
+ * @param email - The encrypted email
217
+ * @returns Server response
218
+ */
219
+ Mail.prototype.sendEncryptedEmail = function (email) {
220
+ return __awaiter(this, void 0, void 0, function () {
221
+ return __generator(this, function (_a) {
222
+ return [2 /*return*/, this.client.post("".concat(this.apiUrl, "/emails"), { emails: [email] }, this.headers())];
223
+ });
224
+ });
225
+ };
226
+ /**
227
+ * Encrypts email and sends it to the server
228
+ *
229
+ * @param email - The message to encrypt
230
+ * @param senderPrivateKeys - The private keys of the sender
231
+ * @param isSubjectEncrypted - Indicates if the subject field should be encrypted
232
+ * @returns Server response
233
+ */
234
+ Mail.prototype.encryptAndSendEmail = function (email_1, senderPrivateKeys_1) {
235
+ return __awaiter(this, arguments, void 0, function (email, senderPrivateKeys, isSubjectEncrypted) {
236
+ var recipient, encEmail;
237
+ if (isSubjectEncrypted === void 0) { isSubjectEncrypted = false; }
238
+ return __generator(this, function (_a) {
239
+ switch (_a.label) {
240
+ case 0: return [4 /*yield*/, this.getUserWithPublicKeys(email.params.recipient.email)];
241
+ case 1:
242
+ recipient = _a.sent();
243
+ return [4 /*yield*/, (0, internxt_crypto_1.encryptEmailHybrid)(email, recipient, senderPrivateKeys, isSubjectEncrypted)];
244
+ case 2:
245
+ encEmail = _a.sent();
246
+ return [2 /*return*/, this.sendEncryptedEmail(encEmail)];
247
+ }
248
+ });
249
+ });
250
+ };
251
+ /**
252
+ * Sends the encrypted emails for multiple recipients to the server
253
+ *
254
+ * @param emails - The encrypted emails
255
+ * @returns Server response
256
+ */
257
+ Mail.prototype.sendEncryptedEmailToMultipleRecipients = function (emails) {
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ return __generator(this, function (_a) {
260
+ return [2 /*return*/, this.client.post("".concat(this.apiUrl, "/emails"), { emails: emails }, this.headers())];
261
+ });
262
+ });
263
+ };
264
+ /**
265
+ * Encrypts emails for multiple recipients and sends emails to the server
266
+ *
267
+ * @param email - The message to encrypt
268
+ * @param senderPrivateKeys - The private keys of the sender
269
+ * @param isSubjectEncrypted - Indicates if the subject field should be encrypted
270
+ * @returns Server response
271
+ */
272
+ Mail.prototype.encryptAndSendEmailToMultipleRecipients = function (email_1, senderPrivateKeys_1) {
273
+ return __awaiter(this, arguments, void 0, function (email, senderPrivateKeys, isSubjectEncrypted) {
274
+ var recipientEmails, recipients, encEmails;
275
+ if (isSubjectEncrypted === void 0) { isSubjectEncrypted = false; }
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0:
279
+ recipientEmails = email.params.recipients
280
+ ? email.params.recipients.map(function (user) { return user.email; })
281
+ : [email.params.recipient.email];
282
+ return [4 /*yield*/, this.getSeveralUsersWithPublicKeys(recipientEmails)];
283
+ case 1:
284
+ recipients = _a.sent();
285
+ return [4 /*yield*/, (0, internxt_crypto_1.encryptEmailHybridForMultipleRecipients)(email, recipients, senderPrivateKeys, isSubjectEncrypted)];
286
+ case 2:
287
+ encEmails = _a.sent();
288
+ return [2 /*return*/, this.sendEncryptedEmailToMultipleRecipients(encEmails)];
289
+ }
290
+ });
291
+ });
292
+ };
293
+ /**
294
+ * Sends the password-protected email to the server
295
+ *
296
+ * @param email - The password-protected email
297
+ * @returns Server response
298
+ */
299
+ Mail.prototype.sendPasswordProtectedEmail = function (email) {
300
+ return __awaiter(this, void 0, void 0, function () {
301
+ return __generator(this, function (_a) {
302
+ return [2 /*return*/, this.client.post("".concat(this.apiUrl, "/emails"), { email: email }, this.headers())];
303
+ });
304
+ });
305
+ };
306
+ /**
307
+ * Creates the password-protected email and sends it to the server
308
+ *
309
+ * @param email - The email
310
+ * @param pwd - The password
311
+ * @param isSubjectEncrypted - Indicates if the subject field should be encrypted
312
+ * @returns Server response
313
+ */
314
+ Mail.prototype.passwordProtectAndSendEmail = function (email_1, pwd_1) {
315
+ return __awaiter(this, arguments, void 0, function (email, pwd, isSubjectEncrypted) {
316
+ var encEmail;
317
+ if (isSubjectEncrypted === void 0) { isSubjectEncrypted = false; }
318
+ return __generator(this, function (_a) {
319
+ switch (_a.label) {
320
+ case 0: return [4 /*yield*/, (0, internxt_crypto_1.createPwdProtectedEmail)(email, pwd, isSubjectEncrypted)];
321
+ case 1:
322
+ encEmail = _a.sent();
323
+ return [2 /*return*/, this.sendPasswordProtectedEmail(encEmail)];
324
+ }
325
+ });
326
+ });
327
+ };
328
+ /**
329
+ * Opens the password-protected email
330
+ *
331
+ * @param email - The password-protected email
332
+ * @param pwd - The shared password
333
+ * @returns The decrypted email
334
+ */
335
+ Mail.prototype.openPasswordProtectedEmail = function (email, pwd) {
336
+ return __awaiter(this, void 0, void 0, function () {
337
+ return __generator(this, function (_a) {
338
+ return [2 /*return*/, (0, internxt_crypto_1.decryptPwdProtectedEmail)(email, pwd)];
339
+ });
340
+ });
341
+ };
342
+ /**
343
+ * Decrypt the email
344
+ *
345
+ * @param email - The encrypted email
346
+ * @param recipientPrivateKeys - The private keys of the email recipient
347
+ * @returns The decrypted email
348
+ */
349
+ Mail.prototype.decryptEmail = function (email, recipientPrivateKeys) {
350
+ return __awaiter(this, void 0, void 0, function () {
351
+ var senderEmail, sender;
352
+ return __generator(this, function (_a) {
353
+ switch (_a.label) {
354
+ case 0:
355
+ senderEmail = email.params.sender.email;
356
+ return [4 /*yield*/, this.getUserWithPublicKeys(senderEmail)];
357
+ case 1:
358
+ sender = _a.sent();
359
+ return [2 /*return*/, (0, internxt_crypto_1.decryptEmailHybrid)(email, sender.publicKeys, recipientPrivateKeys)];
360
+ }
361
+ });
362
+ });
363
+ };
364
+ /**
365
+ * Returns the needed headers for the module requests
366
+ * @private
367
+ */
368
+ Mail.prototype.headers = function () {
369
+ return (0, headers_1.headersWithToken)({
370
+ clientName: this.appDetails.clientName,
371
+ clientVersion: this.appDetails.clientVersion,
372
+ token: this.apiSecurity.token,
373
+ desktopToken: this.appDetails.desktopHeader,
374
+ customHeaders: this.appDetails.customHeaders,
375
+ });
376
+ };
377
+ return Mail;
378
+ }());
379
+ exports.Mail = Mail;
@@ -1 +1,2 @@
1
1
  export * from './types/apiConnection';
2
+ export { default as AppError } from './types/errors';
@@ -13,5 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.AppError = void 0;
17
21
  __exportStar(require("./types/apiConnection"), exports);
22
+ var errors_1 = require("./types/errors");
23
+ Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return __importDefault(errors_1).default; } });
@@ -2,5 +2,6 @@ export default class AppError extends Error {
2
2
  readonly status?: number;
3
3
  readonly code?: string;
4
4
  readonly headers?: Record<string, string>;
5
+ readonly requestId?: string;
5
6
  constructor(message: string, status?: number, code?: string, headers?: Record<string, string>);
6
7
  }
@@ -22,6 +22,7 @@ var AppError = /** @class */ (function (_super) {
22
22
  _this.status = status;
23
23
  _this.code = code;
24
24
  _this.headers = headers;
25
+ _this.requestId = headers === null || headers === void 0 ? void 0 : headers['x-request-id'];
25
26
  return _this;
26
27
  }
27
28
  return AppError;
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.13.1",
4
+ "version": "1.14.2",
5
5
  "description": "An sdk for interacting with Internxt's services",
6
6
  "repository": {
7
7
  "type": "git",
@@ -44,7 +44,9 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "axios": "1.13.5",
47
- "uuid": "13.0.0"
47
+ "uuid": "13.0.0",
48
+ "internxt-crypto": "0.0.13"
49
+
48
50
  },
49
51
  "lint-staged": {
50
52
  "*.{js,jsx,tsx,ts}": [