@internxt/sdk 1.4.77 → 1.5.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/auth/index.d.ts +122 -122
  2. package/dist/auth/index.js +310 -310
  3. package/dist/auth/types.d.ts +54 -54
  4. package/dist/auth/types.js +26 -26
  5. package/dist/drive/backups/index.d.ts +18 -18
  6. package/dist/drive/backups/index.js +40 -40
  7. package/dist/drive/backups/types.d.ts +27 -27
  8. package/dist/drive/backups/types.js +2 -2
  9. package/dist/drive/index.d.ts +7 -7
  10. package/dist/drive/index.js +19 -19
  11. package/dist/drive/payments/index.d.ts +71 -53
  12. package/dist/drive/payments/index.js +208 -153
  13. package/dist/drive/payments/types.d.ts +176 -114
  14. package/dist/drive/payments/types.js +37 -32
  15. package/dist/drive/referrals/index.d.ts +19 -19
  16. package/dist/drive/referrals/index.js +50 -50
  17. package/dist/drive/referrals/types.d.ts +21 -21
  18. package/dist/drive/referrals/types.js +18 -18
  19. package/dist/drive/share/index.d.ts +319 -319
  20. package/dist/drive/share/index.js +540 -539
  21. package/dist/drive/share/types.d.ts +360 -358
  22. package/dist/drive/share/types.js +2 -2
  23. package/dist/drive/storage/index.d.ts +315 -195
  24. package/dist/drive/storage/index.js +630 -434
  25. package/dist/drive/storage/types.d.ts +473 -394
  26. package/dist/drive/storage/types.js +13 -13
  27. package/dist/drive/trash/index.d.ts +75 -55
  28. package/dist/drive/trash/index.js +180 -149
  29. package/dist/drive/trash/types.d.ts +29 -20
  30. package/dist/drive/trash/types.js +2 -2
  31. package/dist/drive/users/index.d.ts +135 -108
  32. package/dist/drive/users/index.js +204 -174
  33. package/dist/drive/users/types.d.ts +51 -43
  34. package/dist/drive/users/types.js +2 -2
  35. package/dist/index.d.ts +6 -5
  36. package/dist/index.js +31 -30
  37. package/dist/network/download.d.ts +8 -8
  38. package/dist/network/download.js +123 -123
  39. package/dist/network/errors/codes.d.ts +24 -24
  40. package/dist/network/errors/codes.js +48 -48
  41. package/dist/network/errors/context.d.ts +35 -35
  42. package/dist/network/errors/context.js +39 -39
  43. package/dist/network/errors/download.d.ts +4 -4
  44. package/dist/network/errors/download.js +48 -48
  45. package/dist/network/errors/index.d.ts +3 -3
  46. package/dist/network/errors/index.js +15 -15
  47. package/dist/network/errors/upload.d.ts +13 -13
  48. package/dist/network/errors/upload.js +78 -78
  49. package/dist/network/index.d.ts +70 -71
  50. package/dist/network/index.js +311 -310
  51. package/dist/network/types.d.ts +102 -102
  52. package/dist/network/types.js +18 -18
  53. package/dist/network/upload.d.ts +4 -4
  54. package/dist/network/upload.js +159 -159
  55. package/dist/photos/devices/index.d.ts +10 -10
  56. package/dist/photos/devices/index.js +79 -79
  57. package/dist/photos/index.d.ts +17 -17
  58. package/dist/photos/index.js +52 -52
  59. package/dist/photos/photos/index.d.ts +60 -60
  60. package/dist/photos/photos/index.js +225 -225
  61. package/dist/photos/shares/index.d.ts +8 -8
  62. package/dist/photos/shares/index.js +34 -34
  63. package/dist/photos/types.d.ts +154 -154
  64. package/dist/photos/types.js +19 -19
  65. package/dist/photos/users/index.d.ts +7 -7
  66. package/dist/photos/users/index.js +46 -46
  67. package/dist/shared/headers/index.d.ts +21 -18
  68. package/dist/shared/headers/index.js +79 -69
  69. package/dist/shared/http/client.d.ts +85 -85
  70. package/dist/shared/http/client.js +172 -181
  71. package/dist/shared/http/types.d.ts +7 -7
  72. package/dist/shared/http/types.js +2 -2
  73. package/dist/shared/index.d.ts +1 -1
  74. package/dist/shared/index.js +13 -13
  75. package/dist/shared/types/apiConnection.d.ts +12 -11
  76. package/dist/shared/types/apiConnection.js +2 -2
  77. package/dist/shared/types/appsumo.d.ts +16 -16
  78. package/dist/shared/types/appsumo.js +12 -12
  79. package/dist/shared/types/errors.d.ts +5 -4
  80. package/dist/shared/types/errors.js +28 -27
  81. package/dist/shared/types/teams.d.ts +9 -9
  82. package/dist/shared/types/teams.js +2 -2
  83. package/dist/shared/types/userSettings.d.ts +29 -27
  84. package/dist/shared/types/userSettings.js +2 -2
  85. package/dist/utils.d.ts +3 -3
  86. package/dist/utils.js +25 -25
  87. package/dist/workspaces/index.d.ts +176 -0
  88. package/dist/workspaces/index.js +415 -0
  89. package/dist/workspaces/index.test.d.ts +1 -0
  90. package/dist/workspaces/index.test.js +903 -0
  91. package/dist/workspaces/types.d.ts +291 -0
  92. package/dist/workspaces/types.js +2 -0
  93. package/package.json +1 -1
@@ -1,43 +1,51 @@
1
- import { UUID, UserSettings } from '../../shared/types/userSettings';
2
- export interface InitializeUserResponse {
3
- email: string;
4
- bucket: string;
5
- mnemonic: string;
6
- root_folder_id: number;
7
- }
8
- export interface ChangePasswordPayload {
9
- currentEncryptedPassword: string;
10
- newEncryptedPassword: string;
11
- newEncryptedSalt: string;
12
- encryptedMnemonic: string;
13
- encryptedPrivateKey: string;
14
- }
15
- export declare type UpdateProfilePayload = Partial<Pick<UserSettings, 'name' | 'lastname'>>;
16
- export declare type PreCreateUserResponse = {
17
- publicKey: string;
18
- user: {
19
- uuid: UUID;
20
- email: string;
21
- };
22
- };
23
- export declare type FriendInvite = {
24
- guestEmail: string;
25
- host: number;
26
- accepted: boolean;
27
- id: number;
28
- };
29
- export declare type UserPublicKeyResponse = {
30
- publicKey: string;
31
- };
32
- export declare type VerifyEmailChangeResponse = {
33
- oldEmail: string;
34
- newEmail: string;
35
- newAuthentication: {
36
- user: UserSettings;
37
- token: string;
38
- newToken: string;
39
- };
40
- };
41
- export declare type CheckChangeEmailExpirationResponse = {
42
- isExpired: boolean;
43
- };
1
+ import { UUID, UserSettings } from '../../shared/types/userSettings';
2
+ export interface InitializeUserResponse {
3
+ email: string;
4
+ bucket: string;
5
+ mnemonic: string;
6
+ root_folder_id: number;
7
+ }
8
+ export interface ChangePasswordPayload {
9
+ currentEncryptedPassword: string;
10
+ newEncryptedPassword: string;
11
+ newEncryptedSalt: string;
12
+ encryptedMnemonic: string;
13
+ encryptedPrivateKey: string;
14
+ }
15
+ export interface ChangePasswordPayloadNew {
16
+ currentEncryptedPassword: string;
17
+ newEncryptedPassword: string;
18
+ newEncryptedSalt: string;
19
+ encryptedMnemonic: string;
20
+ encryptedPrivateKey: string;
21
+ encryptVersion: string;
22
+ }
23
+ export declare type UpdateProfilePayload = Partial<Pick<UserSettings, 'name' | 'lastname'>>;
24
+ export declare type PreCreateUserResponse = {
25
+ publicKey: string;
26
+ user: {
27
+ uuid: UUID;
28
+ email: string;
29
+ };
30
+ };
31
+ export declare type FriendInvite = {
32
+ guestEmail: string;
33
+ host: number;
34
+ accepted: boolean;
35
+ id: number;
36
+ };
37
+ export declare type UserPublicKeyResponse = {
38
+ publicKey: string;
39
+ };
40
+ export declare type VerifyEmailChangeResponse = {
41
+ oldEmail: string;
42
+ newEmail: string;
43
+ newAuthentication: {
44
+ user: UserSettings;
45
+ token: string;
46
+ newToken: string;
47
+ };
48
+ };
49
+ export declare type CheckChangeEmailExpirationResponse = {
50
+ isExpired: boolean;
51
+ };
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * as photos from './photos';
2
- export * from './auth';
3
- export * as Drive from './drive';
4
- export * as Shared from './shared';
5
- export * as Network from './network';
1
+ export * from './auth';
2
+ export * as Drive from './drive';
3
+ export * as Network from './network';
4
+ export * as photos from './photos';
5
+ export * as Shared from './shared';
6
+ export * as Workspaces from './workspaces';
package/dist/index.js CHANGED
@@ -1,30 +1,31 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Network = exports.Shared = exports.Drive = exports.photos = void 0;
26
- exports.photos = __importStar(require("./photos"));
27
- __exportStar(require("./auth"), exports);
28
- exports.Drive = __importStar(require("./drive"));
29
- exports.Shared = __importStar(require("./shared"));
30
- exports.Network = __importStar(require("./network"));
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.Workspaces = exports.Shared = exports.photos = exports.Network = exports.Drive = void 0;
26
+ __exportStar(require("./auth"), exports);
27
+ exports.Drive = __importStar(require("./drive"));
28
+ exports.Network = __importStar(require("./network"));
29
+ exports.photos = __importStar(require("./photos"));
30
+ exports.Shared = __importStar(require("./shared"));
31
+ exports.Workspaces = __importStar(require("./workspaces"));
@@ -1,8 +1,8 @@
1
- import { Network } from '.';
2
- import { Crypto, DecryptFileFunction, DownloadFileFunction, ToBinaryDataFunction } from './types';
3
- export declare class FileVersionOneError extends Error {
4
- constructor();
5
- }
6
- export declare function downloadFile(fileId: string, bucketId: string, mnemonic: string, network: Network, crypto: Crypto, toBinaryData: ToBinaryDataFunction, downloadFile: DownloadFileFunction, decryptFile: DecryptFileFunction, opts?: {
7
- token: string;
8
- }): Promise<void>;
1
+ import { Network } from '.';
2
+ import { Crypto, DecryptFileFunction, DownloadFileFunction, ToBinaryDataFunction } from './types';
3
+ export declare class FileVersionOneError extends Error {
4
+ constructor();
5
+ }
6
+ export declare function downloadFile(fileId: string, bucketId: string, mnemonic: string, network: Network, crypto: Crypto, toBinaryData: ToBinaryDataFunction, downloadFile: DownloadFileFunction, decryptFile: DecryptFileFunction, opts?: {
7
+ token: string;
8
+ }): Promise<void>;
@@ -1,123 +1,123 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- 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;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.downloadFile = exports.FileVersionOneError = void 0;
55
- var errors_1 = require("./errors");
56
- var types_1 = require("./types");
57
- var FileVersionOneError = /** @class */ (function (_super) {
58
- __extends(FileVersionOneError, _super);
59
- function FileVersionOneError() {
60
- var _this = _super.call(this, 'File version 1') || this;
61
- Object.setPrototypeOf(_this, FileVersionOneError.prototype);
62
- return _this;
63
- }
64
- return FileVersionOneError;
65
- }(Error));
66
- exports.FileVersionOneError = FileVersionOneError;
67
- function downloadFile(fileId, bucketId, mnemonic, network, crypto, toBinaryData, downloadFile, decryptFile, opts) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- var iv, indexHex, key, mnemonicIsValid, _a, index, shards, version, size, downloadables, err_1, context;
70
- return __generator(this, function (_b) {
71
- switch (_b.label) {
72
- case 0:
73
- _b.trys.push([0, 5, , 6]);
74
- if (!(opts === null || opts === void 0 ? void 0 : opts.token)) {
75
- mnemonicIsValid = crypto.validateMnemonic(mnemonic);
76
- if (!mnemonicIsValid) {
77
- throw new errors_1.DownloadInvalidMnemonicError();
78
- }
79
- }
80
- return [4 /*yield*/, network.getDownloadLinks(bucketId, fileId, opts === null || opts === void 0 ? void 0 : opts.token)];
81
- case 1:
82
- _a = _b.sent(), index = _a.index, shards = _a.shards, version = _a.version, size = _a.size;
83
- if (!version || version === 1) {
84
- throw new FileVersionOneError();
85
- }
86
- iv = toBinaryData(index, types_1.BinaryDataEncoding.HEX).slice(0, 16);
87
- return [4 /*yield*/, crypto.generateFileKey(mnemonic, bucketId, toBinaryData(index, types_1.BinaryDataEncoding.HEX))];
88
- case 2:
89
- key = _b.sent();
90
- downloadables = shards.sort(function (sA, sB) { return sA.index - sB.index; });
91
- return [4 /*yield*/, downloadFile(downloadables, size)];
92
- case 3:
93
- _b.sent();
94
- return [4 /*yield*/, decryptFile(crypto.algorithm.type, key, iv, size)];
95
- case 4:
96
- _b.sent();
97
- return [3 /*break*/, 6];
98
- case 5:
99
- err_1 = _b.sent();
100
- context = (0, errors_1.getNetworkErrorContext)({
101
- bucketId: bucketId,
102
- fileId: fileId,
103
- user: network.credentials.username,
104
- pass: network.credentials.password,
105
- token: (opts === null || opts === void 0 ? void 0 : opts.token) || 'none',
106
- crypto: {
107
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
108
- index: indexHex ? indexHex.toString('hex') : 'none',
109
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
110
- iv: iv ? iv.toString('hex') : 'none',
111
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
112
- key: key ? key.toString('hex') : 'none',
113
- mnemonic: mnemonic
114
- }
115
- }, err_1);
116
- err_1.context = context;
117
- throw err_1;
118
- case 6: return [2 /*return*/];
119
- }
120
- });
121
- });
122
- }
123
- exports.downloadFile = downloadFile;
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.downloadFile = exports.FileVersionOneError = void 0;
55
+ var errors_1 = require("./errors");
56
+ var types_1 = require("./types");
57
+ var FileVersionOneError = /** @class */ (function (_super) {
58
+ __extends(FileVersionOneError, _super);
59
+ function FileVersionOneError() {
60
+ var _this = _super.call(this, 'File version 1') || this;
61
+ Object.setPrototypeOf(_this, FileVersionOneError.prototype);
62
+ return _this;
63
+ }
64
+ return FileVersionOneError;
65
+ }(Error));
66
+ exports.FileVersionOneError = FileVersionOneError;
67
+ function downloadFile(fileId, bucketId, mnemonic, network, crypto, toBinaryData, downloadFile, decryptFile, opts) {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ var iv, indexHex, key, mnemonicIsValid, _a, index, shards, version, size, downloadables, err_1, context;
70
+ return __generator(this, function (_b) {
71
+ switch (_b.label) {
72
+ case 0:
73
+ _b.trys.push([0, 5, , 6]);
74
+ if (!(opts === null || opts === void 0 ? void 0 : opts.token)) {
75
+ mnemonicIsValid = crypto.validateMnemonic(mnemonic);
76
+ if (!mnemonicIsValid) {
77
+ throw new errors_1.DownloadInvalidMnemonicError();
78
+ }
79
+ }
80
+ return [4 /*yield*/, network.getDownloadLinks(bucketId, fileId, opts === null || opts === void 0 ? void 0 : opts.token)];
81
+ case 1:
82
+ _a = _b.sent(), index = _a.index, shards = _a.shards, version = _a.version, size = _a.size;
83
+ if (!version || version === 1) {
84
+ throw new FileVersionOneError();
85
+ }
86
+ iv = toBinaryData(index, types_1.BinaryDataEncoding.HEX).slice(0, 16);
87
+ return [4 /*yield*/, crypto.generateFileKey(mnemonic, bucketId, toBinaryData(index, types_1.BinaryDataEncoding.HEX))];
88
+ case 2:
89
+ key = _b.sent();
90
+ downloadables = shards.sort(function (sA, sB) { return sA.index - sB.index; });
91
+ return [4 /*yield*/, downloadFile(downloadables, size)];
92
+ case 3:
93
+ _b.sent();
94
+ return [4 /*yield*/, decryptFile(crypto.algorithm.type, key, iv, size)];
95
+ case 4:
96
+ _b.sent();
97
+ return [3 /*break*/, 6];
98
+ case 5:
99
+ err_1 = _b.sent();
100
+ context = (0, errors_1.getNetworkErrorContext)({
101
+ bucketId: bucketId,
102
+ fileId: fileId,
103
+ user: network.credentials.username,
104
+ pass: network.credentials.password,
105
+ token: (opts === null || opts === void 0 ? void 0 : opts.token) || 'none',
106
+ crypto: {
107
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
108
+ index: indexHex ? indexHex.toString('hex') : 'none',
109
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
110
+ iv: iv ? iv.toString('hex') : 'none',
111
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
112
+ key: key ? key.toString('hex') : 'none',
113
+ mnemonic: mnemonic
114
+ }
115
+ }, err_1);
116
+ err_1.context = context;
117
+ throw err_1;
118
+ case 6: return [2 /*return*/];
119
+ }
120
+ });
121
+ });
122
+ }
123
+ exports.downloadFile = downloadFile;
@@ -1,24 +1,24 @@
1
- /**
2
- * NETWORK ERROR CODES FORMAT: 1****
3
- * -UPLOAD ERRORS: 1***
4
- * -DOWNLOAD ERRORS: 2***
5
- * -CRYPTOGRAPHIC ERRORS: 1**
6
- *
7
- */
8
- declare enum UploadErrorCode {
9
- InvalidMnemonic = 11100
10
- }
11
- declare enum DownloadErrorCode {
12
- InvalidMnemonic = 12100
13
- }
14
- declare type NetworkErrorCode = UploadErrorCode | DownloadErrorCode;
15
- export declare class CodeError extends Error {
16
- code: NetworkErrorCode;
17
- message: string;
18
- constructor(code: NetworkErrorCode, message: string);
19
- }
20
- declare const _default: {
21
- Upload: typeof UploadErrorCode;
22
- Download: typeof DownloadErrorCode;
23
- };
24
- export default _default;
1
+ /**
2
+ * NETWORK ERROR CODES FORMAT: 1****
3
+ * -UPLOAD ERRORS: 1***
4
+ * -DOWNLOAD ERRORS: 2***
5
+ * -CRYPTOGRAPHIC ERRORS: 1**
6
+ *
7
+ */
8
+ declare enum UploadErrorCode {
9
+ InvalidMnemonic = 11100
10
+ }
11
+ declare enum DownloadErrorCode {
12
+ InvalidMnemonic = 12100
13
+ }
14
+ declare type NetworkErrorCode = UploadErrorCode | DownloadErrorCode;
15
+ export declare class CodeError extends Error {
16
+ code: NetworkErrorCode;
17
+ message: string;
18
+ constructor(code: NetworkErrorCode, message: string);
19
+ }
20
+ declare const _default: {
21
+ Upload: typeof UploadErrorCode;
22
+ Download: typeof DownloadErrorCode;
23
+ };
24
+ export default _default;
@@ -1,48 +1,48 @@
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.CodeError = void 0;
19
- /**
20
- * NETWORK ERROR CODES FORMAT: 1****
21
- * -UPLOAD ERRORS: 1***
22
- * -DOWNLOAD ERRORS: 2***
23
- * -CRYPTOGRAPHIC ERRORS: 1**
24
- *
25
- */
26
- var UploadErrorCode;
27
- (function (UploadErrorCode) {
28
- UploadErrorCode[UploadErrorCode["InvalidMnemonic"] = 11100] = "InvalidMnemonic";
29
- })(UploadErrorCode || (UploadErrorCode = {}));
30
- var DownloadErrorCode;
31
- (function (DownloadErrorCode) {
32
- DownloadErrorCode[DownloadErrorCode["InvalidMnemonic"] = 12100] = "InvalidMnemonic";
33
- })(DownloadErrorCode || (DownloadErrorCode = {}));
34
- var CodeError = /** @class */ (function (_super) {
35
- __extends(CodeError, _super);
36
- function CodeError(code, message) {
37
- var _this = _super.call(this, message) || this;
38
- _this.code = code;
39
- _this.message = message;
40
- return _this;
41
- }
42
- return CodeError;
43
- }(Error));
44
- exports.CodeError = CodeError;
45
- exports.default = {
46
- Upload: UploadErrorCode,
47
- Download: DownloadErrorCode
48
- };
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.CodeError = void 0;
19
+ /**
20
+ * NETWORK ERROR CODES FORMAT: 1****
21
+ * -UPLOAD ERRORS: 1***
22
+ * -DOWNLOAD ERRORS: 2***
23
+ * -CRYPTOGRAPHIC ERRORS: 1**
24
+ *
25
+ */
26
+ var UploadErrorCode;
27
+ (function (UploadErrorCode) {
28
+ UploadErrorCode[UploadErrorCode["InvalidMnemonic"] = 11100] = "InvalidMnemonic";
29
+ })(UploadErrorCode || (UploadErrorCode = {}));
30
+ var DownloadErrorCode;
31
+ (function (DownloadErrorCode) {
32
+ DownloadErrorCode[DownloadErrorCode["InvalidMnemonic"] = 12100] = "InvalidMnemonic";
33
+ })(DownloadErrorCode || (DownloadErrorCode = {}));
34
+ var CodeError = /** @class */ (function (_super) {
35
+ __extends(CodeError, _super);
36
+ function CodeError(code, message) {
37
+ var _this = _super.call(this, message) || this;
38
+ _this.code = code;
39
+ _this.message = message;
40
+ return _this;
41
+ }
42
+ return CodeError;
43
+ }(Error));
44
+ exports.CodeError = CodeError;
45
+ exports.default = {
46
+ Upload: UploadErrorCode,
47
+ Download: DownloadErrorCode
48
+ };