@internxt/sdk 1.13.2 → 1.15.0
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/auth/index.js +1 -1
- package/dist/drive/backups/index.js +1 -1
- package/dist/drive/payments/index.js +1 -1
- package/dist/drive/referrals/index.js +1 -1
- package/dist/drive/share/index.js +1 -1
- package/dist/drive/storage/index.js +1 -1
- package/dist/drive/trash/index.js +1 -1
- package/dist/drive/users/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mail/index.d.ts +132 -0
- package/dist/mail/index.js +379 -0
- package/dist/meet/index.js +1 -1
- package/dist/payments/checkout.js +1 -1
- package/dist/shared/http/client.d.ts +17 -1
- package/dist/shared/http/client.js +57 -53
- package/dist/shared/http/retryWithBackoff.d.ts +18 -0
- package/dist/shared/http/retryWithBackoff.js +143 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +5 -1
- package/dist/shared/types/apiConnection.d.ts +2 -0
- package/dist/workspaces/index.js +1 -1
- package/package.json +4 -2
package/dist/auth/index.js
CHANGED
|
@@ -56,7 +56,7 @@ var client_1 = require("../shared/http/client");
|
|
|
56
56
|
__exportStar(require("./types"), exports);
|
|
57
57
|
var Auth = /** @class */ (function () {
|
|
58
58
|
function Auth(apiUrl, appDetails, apiSecurity) {
|
|
59
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
59
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.retryOptions);
|
|
60
60
|
this.appDetails = appDetails;
|
|
61
61
|
this.apiSecurity = apiSecurity;
|
|
62
62
|
this.apiUrl = apiUrl;
|
|
@@ -5,7 +5,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
5
5
|
var headers_1 = require("../../shared/headers");
|
|
6
6
|
var Backups = /** @class */ (function () {
|
|
7
7
|
function Backups(apiUrl, appDetails, apiSecurity) {
|
|
8
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
8
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
9
9
|
this.appDetails = appDetails;
|
|
10
10
|
this.apiSecurity = apiSecurity;
|
|
11
11
|
}
|
|
@@ -53,7 +53,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
53
53
|
var types_1 = require("./types/types");
|
|
54
54
|
var Payments = /** @class */ (function () {
|
|
55
55
|
function Payments(apiUrl, appDetails, apiSecurity) {
|
|
56
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
56
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
57
57
|
this.appDetails = appDetails;
|
|
58
58
|
this.apiSecurity = apiSecurity;
|
|
59
59
|
}
|
|
@@ -39,7 +39,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
39
39
|
exports.ReferralTypes = __importStar(require("./types"));
|
|
40
40
|
var Referrals = /** @class */ (function () {
|
|
41
41
|
function Referrals(apiUrl, appDetails, apiSecurity) {
|
|
42
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
42
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
43
43
|
this.appDetails = appDetails;
|
|
44
44
|
this.apiSecurity = apiSecurity;
|
|
45
45
|
}
|
|
@@ -86,7 +86,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
86
86
|
exports.ShareTypes = __importStar(require("./types"));
|
|
87
87
|
var Share = /** @class */ (function () {
|
|
88
88
|
function Share(apiUrl, appDetails, apiSecurity) {
|
|
89
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
89
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
90
90
|
this.appDetails = appDetails;
|
|
91
91
|
this.apiSecurity = apiSecurity;
|
|
92
92
|
}
|
|
@@ -86,7 +86,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
86
86
|
exports.StorageTypes = __importStar(require("./types"));
|
|
87
87
|
var Storage = /** @class */ (function () {
|
|
88
88
|
function Storage(apiUrl, appDetails, apiSecurity) {
|
|
89
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
89
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
90
90
|
this.appDetails = appDetails;
|
|
91
91
|
this.apiSecurity = apiSecurity;
|
|
92
92
|
}
|
|
@@ -75,7 +75,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
75
75
|
exports.TrashTypes = __importStar(require("./types"));
|
|
76
76
|
var Trash = /** @class */ (function () {
|
|
77
77
|
function Trash(apiUrl, appDetails, apiSecurity) {
|
|
78
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
78
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
79
79
|
this.appDetails = appDetails;
|
|
80
80
|
this.apiSecurity = apiSecurity;
|
|
81
81
|
}
|
|
@@ -75,7 +75,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
75
75
|
exports.UserTypes = __importStar(require("./types"));
|
|
76
76
|
var Users = /** @class */ (function () {
|
|
77
77
|
function Users(apiUrl, appDetails, apiSecurity) {
|
|
78
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
78
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.retryOptions);
|
|
79
79
|
this.appDetails = appDetails;
|
|
80
80
|
this.apiSecurity = apiSecurity;
|
|
81
81
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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;
|
package/dist/meet/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var headers_1 = require("../shared/headers");
|
|
|
52
52
|
var client_1 = require("../shared/http/client");
|
|
53
53
|
var Meet = /** @class */ (function () {
|
|
54
54
|
function Meet(apiUrl, appDetails, apiSecurity) {
|
|
55
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
55
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.retryOptions);
|
|
56
56
|
this.appDetails = appDetails;
|
|
57
57
|
this.apiSecurity = apiSecurity;
|
|
58
58
|
}
|
|
@@ -16,7 +16,7 @@ var headers_1 = require("../shared/headers");
|
|
|
16
16
|
var client_1 = require("../shared/http/client");
|
|
17
17
|
var Checkout = /** @class */ (function () {
|
|
18
18
|
function Checkout(apiUrl, appDetails, apiSecurity) {
|
|
19
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
19
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
20
20
|
this.appDetails = appDetails;
|
|
21
21
|
this.apiSecurity = apiSecurity;
|
|
22
22
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Headers, Parameters, RequestCanceler, URL, UnauthorizedCallback } from './types';
|
|
3
|
+
import { RetryOptions } from './retryWithBackoff';
|
|
3
4
|
export { RequestCanceler } from './types';
|
|
4
5
|
export interface CustomInterceptor {
|
|
5
6
|
request?: {
|
|
@@ -11,13 +12,28 @@ export interface CustomInterceptor {
|
|
|
11
12
|
onRejected?: (error: unknown) => unknown;
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
type NonZero<N extends number> = N extends 0 ? never : N;
|
|
16
|
+
type GlobalRetryOptions<M extends number = number> = Omit<RetryOptions, 'maxRetries'> & {
|
|
17
|
+
maxRetries?: NonZero<M>;
|
|
18
|
+
};
|
|
14
19
|
export declare class HttpClient {
|
|
15
20
|
private readonly axios;
|
|
16
21
|
private readonly unauthorizedCallback;
|
|
22
|
+
private retryOptions?;
|
|
17
23
|
static globalInterceptors: CustomInterceptor[];
|
|
24
|
+
static globalRetryOptions?: RetryOptions;
|
|
18
25
|
static setGlobalInterceptors(interceptors: CustomInterceptor[]): void;
|
|
19
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Enables global retry with backoff for rate limit errors (429) across every HttpClient instance.
|
|
28
|
+
* @param [options] - Optional retry configuration options
|
|
29
|
+
* @param [options.maxRetries] - Maximum number of retry attempts (default: 5)
|
|
30
|
+
* @param [options.maxRetryAfter] - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
31
|
+
* @param [options.onRetry] - Callback invoked before each retry with the attempt number and delay in ms
|
|
32
|
+
*/
|
|
33
|
+
static enableGlobalRetry<M extends number = number>(options?: GlobalRetryOptions<M>): void;
|
|
34
|
+
static create(baseURL: URL, unauthorizedCallback?: UnauthorizedCallback, retryOptions?: RetryOptions): HttpClient;
|
|
20
35
|
private constructor();
|
|
36
|
+
private execute;
|
|
21
37
|
/**
|
|
22
38
|
* Requests a GET
|
|
23
39
|
* @param url
|
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.HttpClient = void 0;
|
|
7
7
|
var axios_1 = __importDefault(require("axios"));
|
|
8
8
|
var errors_1 = __importDefault(require("../types/errors"));
|
|
9
|
+
var retryWithBackoff_1 = require("./retryWithBackoff");
|
|
9
10
|
var HttpClient = /** @class */ (function () {
|
|
10
|
-
function HttpClient(baseURL, unauthorizedCallback) {
|
|
11
|
+
function HttpClient(baseURL, unauthorizedCallback, retryOptions) {
|
|
11
12
|
var _this = this;
|
|
12
13
|
this.axios = axios_1.default.create({
|
|
13
14
|
baseURL: baseURL,
|
|
14
15
|
});
|
|
15
16
|
this.unauthorizedCallback = unauthorizedCallback;
|
|
17
|
+
this.retryOptions = retryOptions;
|
|
16
18
|
HttpClient.globalInterceptors.forEach(function (interceptor) {
|
|
17
19
|
if (interceptor.request) {
|
|
18
20
|
_this.axios.interceptors.request.use(interceptor.request.onFulfilled, interceptor.request.onRejected);
|
|
@@ -26,11 +28,29 @@ var HttpClient = /** @class */ (function () {
|
|
|
26
28
|
HttpClient.setGlobalInterceptors = function (interceptors) {
|
|
27
29
|
HttpClient.globalInterceptors = interceptors;
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Enables global retry with backoff for rate limit errors (429) across every HttpClient instance.
|
|
33
|
+
* @param [options] - Optional retry configuration options
|
|
34
|
+
* @param [options.maxRetries] - Maximum number of retry attempts (default: 5)
|
|
35
|
+
* @param [options.maxRetryAfter] - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
36
|
+
* @param [options.onRetry] - Callback invoked before each retry with the attempt number and delay in ms
|
|
37
|
+
*/
|
|
38
|
+
HttpClient.enableGlobalRetry = function (options) {
|
|
39
|
+
HttpClient.globalRetryOptions = (options !== null && options !== void 0 ? options : {});
|
|
40
|
+
};
|
|
41
|
+
HttpClient.create = function (baseURL, unauthorizedCallback, retryOptions) {
|
|
30
42
|
if (unauthorizedCallback === undefined) {
|
|
31
43
|
unauthorizedCallback = function () { return null; };
|
|
32
44
|
}
|
|
33
|
-
return new HttpClient(baseURL, unauthorizedCallback);
|
|
45
|
+
return new HttpClient(baseURL, unauthorizedCallback, retryOptions);
|
|
46
|
+
};
|
|
47
|
+
HttpClient.prototype.execute = function (fn) {
|
|
48
|
+
var _a;
|
|
49
|
+
var options = (_a = this.retryOptions) !== null && _a !== void 0 ? _a : HttpClient.globalRetryOptions;
|
|
50
|
+
if (!options) {
|
|
51
|
+
return fn();
|
|
52
|
+
}
|
|
53
|
+
return (0, retryWithBackoff_1.retryWithBackoff)(fn, options);
|
|
34
54
|
};
|
|
35
55
|
/**
|
|
36
56
|
* Requests a GET
|
|
@@ -38,9 +58,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
38
58
|
* @param headers
|
|
39
59
|
*/
|
|
40
60
|
HttpClient.prototype.get = function (url, headers) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
61
|
+
var _this = this;
|
|
62
|
+
return this.execute(function () { return _this.axios.get(url, { headers: headers }); });
|
|
44
63
|
};
|
|
45
64
|
/**
|
|
46
65
|
* Requests a GET
|
|
@@ -49,10 +68,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
49
68
|
* @param headers
|
|
50
69
|
*/
|
|
51
70
|
HttpClient.prototype.getWithParams = function (url, params, headers) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
headers: headers,
|
|
55
|
-
});
|
|
71
|
+
var _this = this;
|
|
72
|
+
return this.execute(function () { return _this.axios.get(url, { params: params, headers: headers }); });
|
|
56
73
|
};
|
|
57
74
|
/**
|
|
58
75
|
* Requests a GET with option to cancel
|
|
@@ -60,18 +77,15 @@ var HttpClient = /** @class */ (function () {
|
|
|
60
77
|
* @param headers
|
|
61
78
|
*/
|
|
62
79
|
HttpClient.prototype.getCancellable = function (url, headers) {
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
cancel: cancelTokenSource.cancel,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
80
|
+
var _this = this;
|
|
81
|
+
var currentCancel = function () { };
|
|
82
|
+
var requestCanceler = { cancel: function (message) { return currentCancel(message); } };
|
|
83
|
+
var promise = this.execute(function () {
|
|
84
|
+
var source = axios_1.default.CancelToken.source();
|
|
85
|
+
currentCancel = source.cancel;
|
|
86
|
+
return _this.axios.get(url, { headers: headers, cancelToken: source.token });
|
|
87
|
+
});
|
|
88
|
+
return { promise: promise, requestCanceler: requestCanceler };
|
|
75
89
|
};
|
|
76
90
|
/**
|
|
77
91
|
* Requests a POST
|
|
@@ -80,9 +94,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
80
94
|
* @param headers
|
|
81
95
|
*/
|
|
82
96
|
HttpClient.prototype.post = function (url, params, headers) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
97
|
+
var _this = this;
|
|
98
|
+
return this.execute(function () { return _this.axios.post(url, params, { headers: headers }); });
|
|
86
99
|
};
|
|
87
100
|
/**
|
|
88
101
|
* Requests a POST FORM
|
|
@@ -91,9 +104,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
91
104
|
* @param headers
|
|
92
105
|
*/
|
|
93
106
|
HttpClient.prototype.postForm = function (url, params, headers) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
107
|
+
var _this = this;
|
|
108
|
+
return this.execute(function () { return _this.axios.postForm(url, params, { headers: headers }); });
|
|
97
109
|
};
|
|
98
110
|
/**
|
|
99
111
|
* Requests a POST with option to cancel
|
|
@@ -102,18 +114,15 @@ var HttpClient = /** @class */ (function () {
|
|
|
102
114
|
* @param headers
|
|
103
115
|
*/
|
|
104
116
|
HttpClient.prototype.postCancellable = function (url, params, headers) {
|
|
105
|
-
var
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
cancel: cancelTokenSource.cancel,
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
+
var _this = this;
|
|
118
|
+
var currentCancel = function () { };
|
|
119
|
+
var requestCanceler = { cancel: function (message) { return currentCancel(message); } };
|
|
120
|
+
var promise = this.execute(function () {
|
|
121
|
+
var source = axios_1.default.CancelToken.source();
|
|
122
|
+
currentCancel = source.cancel;
|
|
123
|
+
return _this.axios.post(url, params, { headers: headers, cancelToken: source.token });
|
|
124
|
+
});
|
|
125
|
+
return { promise: promise, requestCanceler: requestCanceler };
|
|
117
126
|
};
|
|
118
127
|
/**
|
|
119
128
|
* Requests PATCH
|
|
@@ -122,9 +131,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
122
131
|
* @param headers
|
|
123
132
|
*/
|
|
124
133
|
HttpClient.prototype.patch = function (url, params, headers) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
134
|
+
var _this = this;
|
|
135
|
+
return this.execute(function () { return _this.axios.patch(url, params, { headers: headers }); });
|
|
128
136
|
};
|
|
129
137
|
/**
|
|
130
138
|
* Requests a PUT
|
|
@@ -133,9 +141,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
133
141
|
* @param headers
|
|
134
142
|
*/
|
|
135
143
|
HttpClient.prototype.put = function (url, params, headers) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
144
|
+
var _this = this;
|
|
145
|
+
return this.execute(function () { return _this.axios.put(url, params, { headers: headers }); });
|
|
139
146
|
};
|
|
140
147
|
/**
|
|
141
148
|
* Requests a PUT FORM
|
|
@@ -144,9 +151,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
144
151
|
* @param headers
|
|
145
152
|
*/
|
|
146
153
|
HttpClient.prototype.putForm = function (url, params, headers) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
154
|
+
var _this = this;
|
|
155
|
+
return this.execute(function () { return _this.axios.putForm(url, params, { headers: headers }); });
|
|
150
156
|
};
|
|
151
157
|
/**
|
|
152
158
|
* Requests a DELETE
|
|
@@ -155,10 +161,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
155
161
|
* @param params
|
|
156
162
|
*/
|
|
157
163
|
HttpClient.prototype.delete = function (url, headers, params) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
data: params,
|
|
161
|
-
});
|
|
164
|
+
var _this = this;
|
|
165
|
+
return this.execute(function () { return _this.axios.delete(url, { headers: headers, data: params }); });
|
|
162
166
|
};
|
|
163
167
|
/**
|
|
164
168
|
* Sets middlewares into the client for common behaviour managing
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
maxRetries?: number;
|
|
3
|
+
maxRetryAfter?: number;
|
|
4
|
+
onRetry?: (attempt: number, delay: number) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Retries a function when it encounters a rate limit error (429).
|
|
8
|
+
* Uses the retry-after header to determine how long to wait before retrying.
|
|
9
|
+
*
|
|
10
|
+
* @param fn - The async function to execute with retry logic
|
|
11
|
+
* @param options - Configuration options for retry behavior
|
|
12
|
+
* @param options.maxRetries - Maximum number of retry attempts (default: 5)
|
|
13
|
+
* @param options.maxRetryAfter - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
14
|
+
* @param options.onRetry - Optional callback invoked before each retry with attempt number and delay in ms
|
|
15
|
+
* @returns The result of the function if successful
|
|
16
|
+
* @throws The original error if it's not a rate limit error, if max retries exceeded, or if retry-after header is missing
|
|
17
|
+
*/
|
|
18
|
+
export declare const retryWithBackoff: <T>(fn: () => Promise<T>, options?: RetryOptions) => Promise<T>;
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.retryWithBackoff = void 0;
|
|
60
|
+
var HTTP_STATUS_TOO_MANY_REQUESTS = 429;
|
|
61
|
+
var wait = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
|
|
62
|
+
var isErrorWithStatus = function (error) {
|
|
63
|
+
return typeof error === 'object' && error !== null;
|
|
64
|
+
};
|
|
65
|
+
var isRateLimitError = function (error) {
|
|
66
|
+
if (!isErrorWithStatus(error)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return error.status === HTTP_STATUS_TOO_MANY_REQUESTS;
|
|
70
|
+
};
|
|
71
|
+
var extractRetryAfter = function (error) {
|
|
72
|
+
var headers = error.headers;
|
|
73
|
+
var resetHeader = headers === null || headers === void 0 ? void 0 : headers['retry-after'];
|
|
74
|
+
if (!resetHeader) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
var resetValueInSeconds = Number.parseInt(resetHeader, 10);
|
|
78
|
+
if (Number.isNaN(resetValueInSeconds)) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return resetValueInSeconds * 1000;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Retries a function when it encounters a rate limit error (429).
|
|
85
|
+
* Uses the retry-after header to determine how long to wait before retrying.
|
|
86
|
+
*
|
|
87
|
+
* @param fn - The async function to execute with retry logic
|
|
88
|
+
* @param options - Configuration options for retry behavior
|
|
89
|
+
* @param options.maxRetries - Maximum number of retry attempts (default: 5)
|
|
90
|
+
* @param options.maxRetryAfter - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
91
|
+
* @param options.onRetry - Optional callback invoked before each retry with attempt number and delay in ms
|
|
92
|
+
* @returns The result of the function if successful
|
|
93
|
+
* @throws The original error if it's not a rate limit error, if max retries exceeded, or if retry-after header is missing
|
|
94
|
+
*/
|
|
95
|
+
var retryWithBackoff = function (fn_1) {
|
|
96
|
+
var args_1 = [];
|
|
97
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
98
|
+
args_1[_i - 1] = arguments[_i];
|
|
99
|
+
}
|
|
100
|
+
return __awaiter(void 0, __spreadArray([fn_1], args_1, true), void 0, function (fn, options) {
|
|
101
|
+
var opts, lastError, attempt, error_1, retryAfter, delay, err;
|
|
102
|
+
if (options === void 0) { options = {}; }
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
opts = __assign({ maxRetries: 5, maxRetryAfter: 70000, onRetry: function () { } }, options);
|
|
107
|
+
attempt = 1;
|
|
108
|
+
_a.label = 1;
|
|
109
|
+
case 1:
|
|
110
|
+
if (!(attempt <= opts.maxRetries)) return [3 /*break*/, 7];
|
|
111
|
+
_a.label = 2;
|
|
112
|
+
case 2:
|
|
113
|
+
_a.trys.push([2, 4, , 6]);
|
|
114
|
+
return [4 /*yield*/, fn()];
|
|
115
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
116
|
+
case 4:
|
|
117
|
+
error_1 = _a.sent();
|
|
118
|
+
if (!isRateLimitError(error_1)) {
|
|
119
|
+
throw error_1;
|
|
120
|
+
}
|
|
121
|
+
retryAfter = extractRetryAfter(error_1);
|
|
122
|
+
if (!retryAfter) {
|
|
123
|
+
throw error_1;
|
|
124
|
+
}
|
|
125
|
+
delay = Math.min(retryAfter, opts.maxRetryAfter);
|
|
126
|
+
opts.onRetry(attempt, delay);
|
|
127
|
+
lastError = error_1;
|
|
128
|
+
return [4 /*yield*/, wait(delay)];
|
|
129
|
+
case 5:
|
|
130
|
+
_a.sent();
|
|
131
|
+
return [3 /*break*/, 6];
|
|
132
|
+
case 6:
|
|
133
|
+
attempt++;
|
|
134
|
+
return [3 /*break*/, 1];
|
|
135
|
+
case 7:
|
|
136
|
+
err = lastError;
|
|
137
|
+
err.message = "Max retries exceeded: ".concat(err.message);
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
exports.retryWithBackoff = retryWithBackoff;
|
package/dist/shared/index.d.ts
CHANGED
package/dist/shared/index.js
CHANGED
|
@@ -17,7 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AppError = void 0;
|
|
20
|
+
exports.retryWithBackoff = exports.HttpClient = exports.AppError = void 0;
|
|
21
21
|
__exportStar(require("./types/apiConnection"), exports);
|
|
22
22
|
var errors_1 = require("./types/errors");
|
|
23
23
|
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return __importDefault(errors_1).default; } });
|
|
24
|
+
var client_1 = require("./http/client");
|
|
25
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return client_1.HttpClient; } });
|
|
26
|
+
var retryWithBackoff_1 = require("./http/retryWithBackoff");
|
|
27
|
+
Object.defineProperty(exports, "retryWithBackoff", { enumerable: true, get: function () { return retryWithBackoff_1.retryWithBackoff; } });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Token } from '../../auth';
|
|
2
|
+
import { RetryOptions } from '../http/retryWithBackoff';
|
|
2
3
|
import { UnauthorizedCallback } from '../http/types';
|
|
3
4
|
export type ApiUrl = string;
|
|
4
5
|
export interface AppDetails {
|
|
@@ -11,4 +12,5 @@ export interface ApiSecurity {
|
|
|
11
12
|
token: Token;
|
|
12
13
|
workspaceToken?: Token;
|
|
13
14
|
unauthorizedCallback?: UnauthorizedCallback;
|
|
15
|
+
retryOptions?: RetryOptions;
|
|
14
16
|
}
|
package/dist/workspaces/index.js
CHANGED
|
@@ -41,7 +41,7 @@ var headers_1 = require("../shared/headers");
|
|
|
41
41
|
var client_1 = require("../shared/http/client");
|
|
42
42
|
var Workspaces = /** @class */ (function () {
|
|
43
43
|
function Workspaces(apiUrl, appDetails, apiSecurity) {
|
|
44
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
44
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
45
45
|
this.appDetails = appDetails;
|
|
46
46
|
this.apiSecurity = apiSecurity;
|
|
47
47
|
}
|
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.
|
|
4
|
+
"version": "1.15.0",
|
|
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}": [
|