@internxt/sdk 1.4.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/auth/index.d.ts +81 -0
  4. package/dist/auth/index.js +233 -0
  5. package/dist/auth/types.d.ts +43 -0
  6. package/dist/auth/types.js +26 -0
  7. package/dist/drive/backups/index.d.ts +18 -0
  8. package/dist/drive/backups/index.js +40 -0
  9. package/dist/drive/backups/types.d.ts +27 -0
  10. package/dist/drive/backups/types.js +2 -0
  11. package/dist/drive/index.d.ts +7 -0
  12. package/dist/drive/index.js +19 -0
  13. package/dist/drive/payments/index.d.ts +40 -0
  14. package/dist/drive/payments/index.js +91 -0
  15. package/dist/drive/payments/types.d.ts +104 -0
  16. package/dist/drive/payments/types.js +32 -0
  17. package/dist/drive/referrals/index.d.ts +19 -0
  18. package/dist/drive/referrals/index.js +51 -0
  19. package/dist/drive/referrals/types.d.ts +21 -0
  20. package/dist/drive/referrals/types.js +18 -0
  21. package/dist/drive/share/index.d.ts +74 -0
  22. package/dist/drive/share/index.js +156 -0
  23. package/dist/drive/share/types.d.ts +78 -0
  24. package/dist/drive/share/types.js +2 -0
  25. package/dist/drive/storage/index.d.ts +93 -0
  26. package/dist/drive/storage/index.js +243 -0
  27. package/dist/drive/storage/types.d.ts +174 -0
  28. package/dist/drive/storage/types.js +7 -0
  29. package/dist/drive/trash/index.d.ts +44 -0
  30. package/dist/drive/trash/index.js +132 -0
  31. package/dist/drive/trash/types.d.ts +19 -0
  32. package/dist/drive/trash/types.js +2 -0
  33. package/dist/drive/users/index.d.ts +67 -0
  34. package/dist/drive/users/index.js +123 -0
  35. package/dist/drive/users/types.d.ts +21 -0
  36. package/dist/drive/users/types.js +2 -0
  37. package/dist/index.d.ts +5 -0
  38. package/dist/index.js +30 -0
  39. package/dist/network/download.d.ts +8 -0
  40. package/dist/network/download.js +123 -0
  41. package/dist/network/errors/codes.d.ts +24 -0
  42. package/dist/network/errors/codes.js +48 -0
  43. package/dist/network/errors/context.d.ts +35 -0
  44. package/dist/network/errors/context.js +39 -0
  45. package/dist/network/errors/download.d.ts +4 -0
  46. package/dist/network/errors/download.js +48 -0
  47. package/dist/network/errors/index.d.ts +3 -0
  48. package/dist/network/errors/index.js +15 -0
  49. package/dist/network/errors/upload.d.ts +13 -0
  50. package/dist/network/errors/upload.js +78 -0
  51. package/dist/network/index.d.ts +71 -0
  52. package/dist/network/index.js +310 -0
  53. package/dist/network/types.d.ts +102 -0
  54. package/dist/network/types.js +18 -0
  55. package/dist/network/upload.d.ts +4 -0
  56. package/dist/network/upload.js +159 -0
  57. package/dist/photos/devices/index.d.ts +10 -0
  58. package/dist/photos/devices/index.js +79 -0
  59. package/dist/photos/index.d.ts +17 -0
  60. package/dist/photos/index.js +52 -0
  61. package/dist/photos/photos/index.d.ts +60 -0
  62. package/dist/photos/photos/index.js +225 -0
  63. package/dist/photos/shares/index.d.ts +8 -0
  64. package/dist/photos/shares/index.js +34 -0
  65. package/dist/photos/types.d.ts +154 -0
  66. package/dist/photos/types.js +19 -0
  67. package/dist/photos/users/index.d.ts +7 -0
  68. package/dist/photos/users/index.js +46 -0
  69. package/dist/shared/headers/index.d.ts +45 -0
  70. package/dist/shared/headers/index.js +71 -0
  71. package/dist/shared/http/client.d.ts +78 -0
  72. package/dist/shared/http/client.js +166 -0
  73. package/dist/shared/http/types.d.ts +7 -0
  74. package/dist/shared/http/types.js +2 -0
  75. package/dist/shared/index.d.ts +1 -0
  76. package/dist/shared/index.js +13 -0
  77. package/dist/shared/types/apiConnection.d.ts +12 -0
  78. package/dist/shared/types/apiConnection.js +2 -0
  79. package/dist/shared/types/appsumo.d.ts +16 -0
  80. package/dist/shared/types/appsumo.js +12 -0
  81. package/dist/shared/types/errors.d.ts +4 -0
  82. package/dist/shared/types/errors.js +27 -0
  83. package/dist/shared/types/teams.d.ts +9 -0
  84. package/dist/shared/types/teams.js +2 -0
  85. package/dist/shared/types/userSettings.d.ts +27 -0
  86. package/dist/shared/types/userSettings.js +2 -0
  87. package/dist/utils.d.ts +3 -0
  88. package/dist/utils.js +25 -0
  89. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Internxt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Getting Started
2
+
3
+ ## Installation
4
+
5
+ - Create a `.npmrc` file from the `.npmrc.template` example provided in the repo.
6
+ - Replace `TOKEN` with your own [Github Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) with `read:packages` permission **ONLY**
7
+ - Use `yarn` to install project dependencies.
@@ -0,0 +1,81 @@
1
+ import { Token, CryptoProvider, Keys, LoginDetails, RegisterDetails, SecurityDetails, TwoFactorAuthQR } from './types';
2
+ import { UserSettings, UUID } from '../shared/types/userSettings';
3
+ import { TeamsSettings } from '../shared/types/teams';
4
+ import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
5
+ export * from './types';
6
+ export declare class Auth {
7
+ private readonly client;
8
+ private readonly appDetails;
9
+ private readonly apiSecurity?;
10
+ private readonly apiUrl;
11
+ static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity?: ApiSecurity): Auth;
12
+ private constructor();
13
+ /**
14
+ * Tries to register a new user
15
+ * @param registerDetails
16
+ */
17
+ register(registerDetails: RegisterDetails): Promise<{
18
+ token: Token;
19
+ user: Omit<UserSettings, 'bucket'> & {
20
+ referralCode: string;
21
+ };
22
+ uuid: UUID;
23
+ }>;
24
+ /**
25
+ * Tries to log in a user given its login details
26
+ * @param details
27
+ * @param cryptoProvider
28
+ */
29
+ login(details: LoginDetails, cryptoProvider: CryptoProvider): Promise<{
30
+ token: Token;
31
+ newToken: Token;
32
+ user: UserSettings;
33
+ userTeam: TeamsSettings | null;
34
+ }>;
35
+ /**
36
+ * Updates the asymmetric keys
37
+ * @param keys
38
+ * @param token
39
+ */
40
+ updateKeys(keys: Keys, token: Token): Promise<unknown>;
41
+ /**
42
+ * Returns general security details
43
+ * @param email
44
+ */
45
+ securityDetails(email: string): Promise<SecurityDetails>;
46
+ /**
47
+ * Generates a new TwoFactorAuth code
48
+ */
49
+ generateTwoFactorAuthQR(): Promise<TwoFactorAuthQR>;
50
+ /**
51
+ * Disables TwoFactorAuthentication
52
+ * @param pass
53
+ * @param code
54
+ */
55
+ disableTwoFactorAuth(pass: string, code: string): Promise<void>;
56
+ /**
57
+ * Store TwoFactorAuthentication details
58
+ * @param backupKey
59
+ * @param code
60
+ */
61
+ storeTwoFactorAuthKey(backupKey: string, code: string): Promise<void>;
62
+ /**
63
+ * Sends request to send the email to delete the account
64
+ * @param email
65
+ */
66
+ sendDeactivationEmail(email: string): Promise<void>;
67
+ /**
68
+ * Confirms the account deactivation
69
+ * @param token
70
+ */
71
+ confirmDeactivation(token: string): Promise<void>;
72
+ /**
73
+ * Checks if the password is correct for this email
74
+ * @param email
75
+ * @param hashedPassword
76
+ * @returns
77
+ */
78
+ areCredentialsCorrect(email: string, hashedPassword: string): Promise<boolean>;
79
+ private basicHeaders;
80
+ private headersWithToken;
81
+ }
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.Auth = void 0;
50
+ var types_1 = require("./types");
51
+ var headers_1 = require("../shared/headers");
52
+ var client_1 = require("../shared/http/client");
53
+ __exportStar(require("./types"), exports);
54
+ var Auth = /** @class */ (function () {
55
+ function Auth(apiUrl, appDetails, apiSecurity) {
56
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
57
+ this.appDetails = appDetails;
58
+ this.apiSecurity = apiSecurity;
59
+ this.apiUrl = apiUrl;
60
+ }
61
+ Auth.client = function (apiUrl, appDetails, apiSecurity) {
62
+ return new Auth(apiUrl, appDetails, apiSecurity);
63
+ };
64
+ /**
65
+ * Tries to register a new user
66
+ * @param registerDetails
67
+ */
68
+ Auth.prototype.register = function (registerDetails) {
69
+ return this.client.post('/users', {
70
+ name: registerDetails.name,
71
+ captcha: registerDetails.captcha,
72
+ lastname: registerDetails.lastname,
73
+ email: registerDetails.email,
74
+ password: registerDetails.password,
75
+ mnemonic: registerDetails.mnemonic,
76
+ salt: registerDetails.salt,
77
+ privateKey: registerDetails.keys.privateKeyEncrypted,
78
+ publicKey: registerDetails.keys.publicKey,
79
+ revocationKey: registerDetails.keys.revocationCertificate,
80
+ referral: registerDetails.referral,
81
+ referrer: registerDetails.referrer,
82
+ }, this.basicHeaders());
83
+ };
84
+ /**
85
+ * Tries to log in a user given its login details
86
+ * @param details
87
+ * @param cryptoProvider
88
+ */
89
+ Auth.prototype.login = function (details, cryptoProvider) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var securityDetails, encryptedSalt, encryptedPasswordHash, keys;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0: return [4 /*yield*/, this.securityDetails(details.email)];
95
+ case 1:
96
+ securityDetails = _a.sent();
97
+ encryptedSalt = securityDetails.encryptedSalt;
98
+ encryptedPasswordHash = cryptoProvider.encryptPasswordHash(details.password, encryptedSalt);
99
+ return [4 /*yield*/, cryptoProvider.generateKeys(details.password)];
100
+ case 2:
101
+ keys = _a.sent();
102
+ return [2 /*return*/, this.client
103
+ .post('/access', {
104
+ email: details.email,
105
+ password: encryptedPasswordHash,
106
+ tfa: details.tfaCode,
107
+ privateKey: keys.privateKeyEncrypted,
108
+ publicKey: keys.publicKey,
109
+ revocateKey: keys.revocationCertificate,
110
+ }, this.basicHeaders())
111
+ .then(function (data) {
112
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
113
+ // @ts-ignore
114
+ data.user.revocationKey = data.user.revocateKey; // TODO : remove when all projects use SDK
115
+ return data;
116
+ })
117
+ .catch(function (error) {
118
+ throw new types_1.UserAccessError(error.message);
119
+ })];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ /**
125
+ * Updates the asymmetric keys
126
+ * @param keys
127
+ * @param token
128
+ */
129
+ Auth.prototype.updateKeys = function (keys, token) {
130
+ return this.client.patch('/user/keys', {
131
+ publicKey: keys.publicKey,
132
+ privateKey: keys.privateKeyEncrypted,
133
+ revocationKey: keys.revocationCertificate,
134
+ }, this.headersWithToken(token));
135
+ };
136
+ /**
137
+ * Returns general security details
138
+ * @param email
139
+ */
140
+ Auth.prototype.securityDetails = function (email) {
141
+ return this.client
142
+ .post('/login', {
143
+ email: email,
144
+ }, this.basicHeaders())
145
+ .then(function (data) {
146
+ return {
147
+ encryptedSalt: data.sKey,
148
+ tfaEnabled: data.tfa === true,
149
+ };
150
+ });
151
+ };
152
+ /**
153
+ * Generates a new TwoFactorAuth code
154
+ */
155
+ Auth.prototype.generateTwoFactorAuthQR = function () {
156
+ var _a;
157
+ return this.client
158
+ .get('/tfa', this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token))
159
+ .then(function (data) {
160
+ return {
161
+ qr: data.qr,
162
+ backupKey: data.code,
163
+ };
164
+ });
165
+ };
166
+ /**
167
+ * Disables TwoFactorAuthentication
168
+ * @param pass
169
+ * @param code
170
+ */
171
+ Auth.prototype.disableTwoFactorAuth = function (pass, code) {
172
+ var _a;
173
+ return this.client.delete('/tfa', this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token), {
174
+ pass: pass,
175
+ code: code,
176
+ });
177
+ };
178
+ /**
179
+ * Store TwoFactorAuthentication details
180
+ * @param backupKey
181
+ * @param code
182
+ */
183
+ Auth.prototype.storeTwoFactorAuthKey = function (backupKey, code) {
184
+ var _a;
185
+ return this.client.put('/tfa', {
186
+ key: backupKey,
187
+ code: code,
188
+ }, this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token));
189
+ };
190
+ /**
191
+ * Sends request to send the email to delete the account
192
+ * @param email
193
+ */
194
+ Auth.prototype.sendDeactivationEmail = function (email) {
195
+ return this.client.get("/deactivate/" + email, this.basicHeaders());
196
+ };
197
+ /**
198
+ * Confirms the account deactivation
199
+ * @param token
200
+ */
201
+ Auth.prototype.confirmDeactivation = function (token) {
202
+ return this.client.get("/confirmDeactivation/" + token, this.basicHeaders());
203
+ };
204
+ /**
205
+ * Checks if the password is correct for this email
206
+ * @param email
207
+ * @param hashedPassword
208
+ * @returns
209
+ */
210
+ Auth.prototype.areCredentialsCorrect = function (email, hashedPassword) {
211
+ var _a;
212
+ // Uses fetch instead of httpClient since a 401 response
213
+ // would log out the user
214
+ return fetch(this.apiUrl + "/are-credentials-correct?email=" + email + "&hashedPassword=" + hashedPassword, { headers: this.headersWithToken((_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.token) }).then(function (res) {
215
+ if (res.ok) {
216
+ return true;
217
+ }
218
+ else if (res.status === 401) {
219
+ return false;
220
+ }
221
+ else
222
+ throw new Error("Request failed with error " + res.status);
223
+ });
224
+ };
225
+ Auth.prototype.basicHeaders = function () {
226
+ return (0, headers_1.basicHeaders)(this.appDetails.clientName, this.appDetails.clientVersion);
227
+ };
228
+ Auth.prototype.headersWithToken = function (token) {
229
+ return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, token);
230
+ };
231
+ return Auth;
232
+ }());
233
+ exports.Auth = Auth;
@@ -0,0 +1,43 @@
1
+ export declare type Password = string;
2
+ export declare type Email = string;
3
+ export declare type Token = string;
4
+ export interface LoginDetails {
5
+ email: Email;
6
+ password: Password;
7
+ tfaCode: string | undefined;
8
+ }
9
+ export interface RegisterDetails {
10
+ name: string;
11
+ lastname: string;
12
+ email: Email;
13
+ password: Password;
14
+ mnemonic: string;
15
+ salt: string;
16
+ keys: Keys;
17
+ captcha: string;
18
+ referrer?: string;
19
+ referral?: string;
20
+ }
21
+ export interface Keys {
22
+ privateKeyEncrypted: string;
23
+ publicKey: string;
24
+ revocationCertificate: string;
25
+ }
26
+ export interface CryptoProvider {
27
+ encryptPasswordHash: (password: Password, encryptedSalt: string) => string;
28
+ generateKeys: (password: Password) => Promise<Keys>;
29
+ }
30
+ export declare class UserAccessError extends Error {
31
+ }
32
+ export interface SecurityDetails {
33
+ encryptedSalt: string;
34
+ tfaEnabled: boolean;
35
+ }
36
+ export interface TwoFactorAuthQR {
37
+ qr: string;
38
+ backupKey: string;
39
+ }
40
+ export interface BasicAuth {
41
+ username: string;
42
+ password: string;
43
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.UserAccessError = void 0;
19
+ var UserAccessError = /** @class */ (function (_super) {
20
+ __extends(UserAccessError, _super);
21
+ function UserAccessError() {
22
+ return _super !== null && _super.apply(this, arguments) || this;
23
+ }
24
+ return UserAccessError;
25
+ }(Error));
26
+ exports.UserAccessError = UserAccessError;
@@ -0,0 +1,18 @@
1
+ import { ApiSecurity, ApiUrl, AppDetails } from '../../shared';
2
+ import { Device, DeviceBackup } from './types';
3
+ export declare class Backups {
4
+ private readonly client;
5
+ private readonly appDetails;
6
+ private readonly apiSecurity;
7
+ static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): Backups;
8
+ private constructor();
9
+ getAllDevices(): Promise<Device[]>;
10
+ getAllBackups(mac: string): Promise<DeviceBackup[]>;
11
+ deleteBackup(backupId: number): Promise<void>;
12
+ deleteDevice(deviceId: number): Promise<void>;
13
+ /**
14
+ * Returns the needed headers for the module requests
15
+ * @private
16
+ */
17
+ private headers;
18
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Backups = void 0;
4
+ var client_1 = require("../../shared/http/client");
5
+ var headers_1 = require("../../shared/headers");
6
+ var Backups = /** @class */ (function () {
7
+ function Backups(apiUrl, appDetails, apiSecurity) {
8
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
9
+ this.appDetails = appDetails;
10
+ this.apiSecurity = apiSecurity;
11
+ }
12
+ Backups.client = function (apiUrl, appDetails, apiSecurity) {
13
+ return new Backups(apiUrl, appDetails, apiSecurity);
14
+ };
15
+ Backups.prototype.getAllDevices = function () {
16
+ return this.client
17
+ .get('/backup/device', this.headers());
18
+ };
19
+ Backups.prototype.getAllBackups = function (mac) {
20
+ return this.client
21
+ .get("/backup/" + mac, this.headers());
22
+ };
23
+ Backups.prototype.deleteBackup = function (backupId) {
24
+ return this.client
25
+ .delete("/backup/" + backupId, this.headers());
26
+ };
27
+ Backups.prototype.deleteDevice = function (deviceId) {
28
+ return this.client
29
+ .delete("/backup/device/" + deviceId, this.headers());
30
+ };
31
+ /**
32
+ * Returns the needed headers for the module requests
33
+ * @private
34
+ */
35
+ Backups.prototype.headers = function () {
36
+ return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, this.apiSecurity.token);
37
+ };
38
+ return Backups;
39
+ }());
40
+ exports.Backups = Backups;
@@ -0,0 +1,27 @@
1
+ export interface Device {
2
+ id: number;
3
+ name: string;
4
+ mac: string;
5
+ userId: number;
6
+ createdAt: string;
7
+ updatedAt: string;
8
+ size: number;
9
+ platform: string | null;
10
+ }
11
+ export interface DeviceBackup {
12
+ id: number;
13
+ path: string;
14
+ name: string;
15
+ fileId?: string;
16
+ deviceId: number;
17
+ userId: number;
18
+ interval: number;
19
+ size?: number;
20
+ bucket: string;
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ encrypt_version: string;
24
+ hash?: string;
25
+ enabled: boolean;
26
+ lastBackupAt?: string;
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export * from './storage';
2
+ export * from './share';
3
+ export * from './users';
4
+ export * from './referrals';
5
+ export * from './payments';
6
+ export * from './backups';
7
+ export * from './trash';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./storage"), exports);
14
+ __exportStar(require("./share"), exports);
15
+ __exportStar(require("./users"), exports);
16
+ __exportStar(require("./referrals"), exports);
17
+ __exportStar(require("./payments"), exports);
18
+ __exportStar(require("./backups"), exports);
19
+ __exportStar(require("./trash"), exports);
@@ -0,0 +1,40 @@
1
+ import { ApiSecurity, ApiUrl, AppDetails } from '../../shared';
2
+ import { CreateCheckoutSessionPayload, CreatePaymentSessionPayload, DisplayPrice, Invoice, PaymentMethod, ProductData, UserSubscription } from './types';
3
+ export declare class Payments {
4
+ private readonly client;
5
+ private readonly appDetails;
6
+ private readonly apiSecurity;
7
+ static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): Payments;
8
+ private constructor();
9
+ /**
10
+ * Fetches the existing products and its details
11
+ */
12
+ getProducts(): Promise<ProductData[]>;
13
+ /**
14
+ * Creates and returns a new session identifier for the client to go to payment platform
15
+ * @param payload
16
+ */
17
+ createSession(payload: CreatePaymentSessionPayload): Promise<{
18
+ id: string;
19
+ }>;
20
+ getSetupIntent(): Promise<{
21
+ clientSecret: string;
22
+ }>;
23
+ getDefaultPaymentMethod(): Promise<PaymentMethod>;
24
+ getInvoices({ startingAfter, limit }: {
25
+ startingAfter?: string;
26
+ limit?: number;
27
+ }): Promise<Invoice[]>;
28
+ getUserSubscription(): Promise<UserSubscription>;
29
+ getPrices(): Promise<DisplayPrice[]>;
30
+ updateSubscriptionPrice(priceId: string): Promise<UserSubscription>;
31
+ cancelSubscription(): Promise<void>;
32
+ createCheckoutSession(payload: CreateCheckoutSessionPayload): Promise<{
33
+ sessionId: string;
34
+ }>;
35
+ /**
36
+ * Returns the needed headers for the module requests
37
+ * @private
38
+ */
39
+ private headers;
40
+ }
@@ -0,0 +1,91 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Payments = void 0;
15
+ var headers_1 = require("../../shared/headers");
16
+ var client_1 = require("../../shared/http/client");
17
+ var Payments = /** @class */ (function () {
18
+ function Payments(apiUrl, appDetails, apiSecurity) {
19
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
20
+ this.appDetails = appDetails;
21
+ this.apiSecurity = apiSecurity;
22
+ }
23
+ Payments.client = function (apiUrl, appDetails, apiSecurity) {
24
+ return new Payments(apiUrl, appDetails, apiSecurity);
25
+ };
26
+ /**
27
+ * Fetches the existing products and its details
28
+ */
29
+ Payments.prototype.getProducts = function () {
30
+ return this.client.get('/v3/stripe/products', this.headers());
31
+ };
32
+ /**
33
+ * Creates and returns a new session identifier for the client to go to payment platform
34
+ * @param payload
35
+ */
36
+ Payments.prototype.createSession = function (payload) {
37
+ return this.client.post('/v2/stripe/session', {
38
+ test: payload.test,
39
+ lifetime_tier: payload.lifetime_tier,
40
+ mode: payload.mode,
41
+ priceId: payload.priceId,
42
+ successUrl: payload.successUrl,
43
+ canceledUrl: payload.canceledUrl,
44
+ }, this.headers());
45
+ };
46
+ Payments.prototype.getSetupIntent = function () {
47
+ return this.client.get('/setup-intent', this.headers());
48
+ };
49
+ Payments.prototype.getDefaultPaymentMethod = function () {
50
+ return this.client.get('/default-payment-method', this.headers());
51
+ };
52
+ Payments.prototype.getInvoices = function (_a) {
53
+ var startingAfter = _a.startingAfter, limit = _a.limit;
54
+ var query = new URLSearchParams();
55
+ if (startingAfter !== undefined)
56
+ query.set('starting_after', startingAfter);
57
+ if (limit !== undefined)
58
+ query.set('limit', limit.toString());
59
+ return this.client.get("/invoices?" + query.toString(), this.headers());
60
+ };
61
+ Payments.prototype.getUserSubscription = function () {
62
+ return this.client.get('/subscriptions', this.headers()).catch(function (err) {
63
+ var error = err;
64
+ if (error.status === 404)
65
+ return { type: 'free' };
66
+ else
67
+ throw err;
68
+ });
69
+ };
70
+ Payments.prototype.getPrices = function () {
71
+ return this.client.get('/prices', this.headers());
72
+ };
73
+ Payments.prototype.updateSubscriptionPrice = function (priceId) {
74
+ return this.client.put('/subscriptions', { price_id: priceId }, this.headers());
75
+ };
76
+ Payments.prototype.cancelSubscription = function () {
77
+ return this.client.delete('/subscriptions', this.headers());
78
+ };
79
+ Payments.prototype.createCheckoutSession = function (payload) {
80
+ return this.client.post('/checkout-session', __assign({}, payload), this.headers());
81
+ };
82
+ /**
83
+ * Returns the needed headers for the module requests
84
+ * @private
85
+ */
86
+ Payments.prototype.headers = function () {
87
+ return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, this.apiSecurity.token);
88
+ };
89
+ return Payments;
90
+ }());
91
+ exports.Payments = Payments;