@internxt/sdk 1.15.6 → 1.15.7

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,379 +1,18 @@
1
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 };
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]; } };
47
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);
48
15
  };
49
16
  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;
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./mail"), exports);
@@ -0,0 +1,104 @@
1
+ import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
2
+ import { EncryptedKeystore, KeystoreType, HybridEncryptedEmail, PwdProtectedEmail, HybridKeyPair, Email, RecipientWithPublicKey, EmailPublicParameters } from 'internxt-crypto';
3
+ import { MailboxResponse, EmailListResponse, EmailResponse, EmailCreatedResponse, SendEmailRequest, DraftEmailRequest, UpdateEmailRequest, ListEmailsQuery } from './types';
4
+ export declare class Mail {
5
+ private readonly api;
6
+ static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): Mail;
7
+ private constructor();
8
+ /**
9
+ * Uploads encrypted keystore to the server
10
+ *
11
+ * @param encryptedKeystore - The encrypted keystore
12
+ * @returns Server response
13
+ */
14
+ uploadKeystoreToServer(encryptedKeystore: EncryptedKeystore): Promise<void>;
15
+ /**
16
+ * Creates recovery and encryption keystores and uploads them to the server
17
+ *
18
+ * @param userEmail - The email of the user
19
+ * @param baseKey - The secret key of the user
20
+ * @returns The recovery codes and keys of the user
21
+ */
22
+ createAndUploadKeystores(userEmail: string, baseKey: Uint8Array): Promise<{
23
+ recoveryCodes: string;
24
+ keys: HybridKeyPair;
25
+ }>;
26
+ /**
27
+ * Requests encrypted keystore from the server
28
+ *
29
+ * @param userEmail - The email of the user
30
+ * @param keystoreType - The type of the keystore
31
+ * @returns The encrypted keystore
32
+ */
33
+ downloadKeystoreFromServer(userEmail: string, keystoreType: KeystoreType): Promise<EncryptedKeystore>;
34
+ /**
35
+ * Requests encrypted keystore from the server and opens it
36
+ *
37
+ * @param userEmail - The email of the user
38
+ * @param baseKey - The secret key of the user
39
+ * @returns The hybrid keys of the user
40
+ */
41
+ getUserEmailKeys(userEmail: string, baseKey: Uint8Array): Promise<HybridKeyPair>;
42
+ /**
43
+ * Requests recovery keystore from the server and opens it
44
+ *
45
+ * @param userEmail - The email of the user
46
+ * @param recoveryCodes - The recovery codes of the user
47
+ * @returns The hybrid keys of the user
48
+ */
49
+ recoverUserEmailKeys(userEmail: string, recoveryCodes: string): Promise<HybridKeyPair>;
50
+ /**
51
+ * Request user with corresponding public keys from the server
52
+ *
53
+ * @param userEmail - The email of the user
54
+ * @returns User with corresponding public keys
55
+ */
56
+ getUserWithPublicKeys(userEmail: string): Promise<RecipientWithPublicKey>;
57
+ /**
58
+ * Request users with corresponding public keys from the server
59
+ *
60
+ * @param emails - The emails of the users
61
+ * @returns Users with corresponding public keys
62
+ */
63
+ getSeveralUsersWithPublicKeys(emails: string[]): Promise<RecipientWithPublicKey[]>;
64
+ /**
65
+ * Sends the encrypted emails to the server
66
+ *
67
+ * @param emails - The encrypted emails
68
+ * @param params - The public parameters of the email (sender, recipients, CCs, BCCs, etc.)
69
+ * @returns Server response
70
+ */
71
+ sendE2EEncryptedEmail(emails: HybridEncryptedEmail[], params: EmailPublicParameters): Promise<void>;
72
+ /**
73
+ * Encrypts and sends email(s) to the server
74
+ *
75
+ * @param email - The message to encrypt
76
+ * @param aux - The optional auxilary data to encrypt together with the email (e.g. email sender)
77
+ * @returns Server response
78
+ */
79
+ e2eEncryptAndSendEmail(email: Email, aux?: string): Promise<void>;
80
+ /**
81
+ * Sends the password-protected email to the server
82
+ *
83
+ * @param email - The password-protected email
84
+ * @param params - The public parameters of the email
85
+ * @returns Server response
86
+ */
87
+ sendE2EPasswordProtectedEmail(email: PwdProtectedEmail, params: EmailPublicParameters): Promise<void>;
88
+ /**
89
+ * Creates the password-protected E2E email and sends it to the server
90
+ *
91
+ * @param email - The email
92
+ * @param pwd - The password
93
+ * @param aux - The optional auxiliary data to encrypt together with the email (e.g. email sender)
94
+ * @returns Server response
95
+ */
96
+ e2ePasswordProtectAndSendEmail(email: Email, pwd: string, aux?: string): Promise<void>;
97
+ getMailboxes(): Promise<MailboxResponse[]>;
98
+ listEmails(query?: ListEmailsQuery): Promise<EmailListResponse>;
99
+ getEmail(id: string): Promise<EmailResponse>;
100
+ deleteEmail(id: string): Promise<void>;
101
+ updateEmail(id: string, body: UpdateEmailRequest): Promise<void>;
102
+ sendEmail(body: SendEmailRequest): Promise<EmailCreatedResponse>;
103
+ saveDraft(body: DraftEmailRequest): Promise<EmailCreatedResponse>;
104
+ }