@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,102 +1,102 @@
1
- import { AppDetails } from '../shared';
2
- import { HttpClient } from '../shared/http/client';
3
- import { BasicAuth } from '../auth/types';
4
- declare type Hash = string;
5
- export declare type BridgeUrl = string;
6
- export interface Shard {
7
- uuid: string;
8
- hash: Hash;
9
- }
10
- export interface ShardForMultipart extends Shard {
11
- UploadId: string;
12
- parts: {
13
- PartNumber: number;
14
- ETag: string;
15
- }[];
16
- }
17
- export interface StartUploadResponse {
18
- uploads: {
19
- index: number;
20
- uuid: Shard['uuid'];
21
- url: string | null;
22
- urls: string[] | null;
23
- UploadId?: string;
24
- }[];
25
- }
26
- export declare type FinishUploadResponse = BucketEntry;
27
- export interface BucketEntry {
28
- id: string;
29
- index: string;
30
- bucket: string;
31
- name: string;
32
- mimetype: string;
33
- created: Date;
34
- }
35
- export interface DownloadableShard {
36
- index: number;
37
- size: number;
38
- hash: Shard['hash'];
39
- url: string;
40
- }
41
- export interface GetDownloadLinksResponse {
42
- bucket: string;
43
- index: string;
44
- created: Date;
45
- shards: DownloadableShard[];
46
- version?: number;
47
- size: number;
48
- }
49
- export interface NetworkRequestConfig {
50
- client: HttpClient;
51
- appDetails: AppDetails;
52
- auth: BasicAuth;
53
- }
54
- declare type UploadPayload = {
55
- index: number;
56
- size: number;
57
- };
58
- export declare type StartUploadPayload = {
59
- uploads: UploadPayload[];
60
- };
61
- export declare type FinishUploadPayload = {
62
- index: string;
63
- shards: Shard[];
64
- };
65
- export declare type FinishMultipartUploadPayload = {
66
- index: string;
67
- shards: ShardForMultipart[];
68
- };
69
- export declare type UploadFileFunction = (url: string) => Promise<Hash>;
70
- export declare type UploadFileMultipartFunction = (urls: string[]) => Promise<{
71
- hash: Hash;
72
- parts: {
73
- PartNumber: number;
74
- ETag: string;
75
- }[];
76
- }>;
77
- export declare type DownloadFileFunction = (downloadables: DownloadableShard[], fileSize: number) => Promise<void>;
78
- export declare type BinaryData = {
79
- slice: (from: number, to: number) => BinaryData;
80
- toString(encoding: 'hex'): string;
81
- };
82
- export declare enum BinaryDataEncoding {
83
- HEX = "hex"
84
- }
85
- export declare type ToBinaryDataFunction = (input: string, encoding: BinaryDataEncoding) => BinaryData;
86
- export declare enum SymmetricCryptoAlgorithm {
87
- AES256CTR = "AES256CTR"
88
- }
89
- export declare type Algorithm = {
90
- type: SymmetricCryptoAlgorithm;
91
- ivSize: number;
92
- };
93
- export declare const ALGORITHMS: Record<SymmetricCryptoAlgorithm, Algorithm>;
94
- export declare type Crypto = {
95
- algorithm: Algorithm;
96
- validateMnemonic: (mnemonic: string) => boolean;
97
- randomBytes: (bytesLength: number) => BinaryData;
98
- generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
99
- };
100
- export declare type EncryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData) => Promise<void>;
101
- export declare type DecryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData, fileSize: number) => Promise<void>;
102
- export {};
1
+ import { AppDetails } from '../shared';
2
+ import { HttpClient } from '../shared/http/client';
3
+ import { BasicAuth } from '../auth/types';
4
+ declare type Hash = string;
5
+ export declare type BridgeUrl = string;
6
+ export interface Shard {
7
+ uuid: string;
8
+ hash: Hash;
9
+ }
10
+ export interface ShardForMultipart extends Shard {
11
+ UploadId: string;
12
+ parts: {
13
+ PartNumber: number;
14
+ ETag: string;
15
+ }[];
16
+ }
17
+ export interface StartUploadResponse {
18
+ uploads: {
19
+ index: number;
20
+ uuid: Shard['uuid'];
21
+ url: string | null;
22
+ urls: string[] | null;
23
+ UploadId?: string;
24
+ }[];
25
+ }
26
+ export declare type FinishUploadResponse = BucketEntry;
27
+ export interface BucketEntry {
28
+ id: string;
29
+ index: string;
30
+ bucket: string;
31
+ name: string;
32
+ mimetype: string;
33
+ created: Date;
34
+ }
35
+ export interface DownloadableShard {
36
+ index: number;
37
+ size: number;
38
+ hash: Shard['hash'];
39
+ url: string;
40
+ }
41
+ export interface GetDownloadLinksResponse {
42
+ bucket: string;
43
+ index: string;
44
+ created: Date;
45
+ shards: DownloadableShard[];
46
+ version?: number;
47
+ size: number;
48
+ }
49
+ export interface NetworkRequestConfig {
50
+ client: HttpClient;
51
+ appDetails: AppDetails;
52
+ auth: BasicAuth;
53
+ }
54
+ declare type UploadPayload = {
55
+ index: number;
56
+ size: number;
57
+ };
58
+ export declare type StartUploadPayload = {
59
+ uploads: UploadPayload[];
60
+ };
61
+ export declare type FinishUploadPayload = {
62
+ index: string;
63
+ shards: Shard[];
64
+ };
65
+ export declare type FinishMultipartUploadPayload = {
66
+ index: string;
67
+ shards: ShardForMultipart[];
68
+ };
69
+ export declare type UploadFileFunction = (url: string) => Promise<Hash>;
70
+ export declare type UploadFileMultipartFunction = (urls: string[]) => Promise<{
71
+ hash: Hash;
72
+ parts: {
73
+ PartNumber: number;
74
+ ETag: string;
75
+ }[];
76
+ }>;
77
+ export declare type DownloadFileFunction = (downloadables: DownloadableShard[], fileSize: number) => Promise<void>;
78
+ export declare type BinaryData = {
79
+ slice: (from: number, to: number) => BinaryData;
80
+ toString(encoding: 'hex'): string;
81
+ };
82
+ export declare enum BinaryDataEncoding {
83
+ HEX = "hex"
84
+ }
85
+ export declare type ToBinaryDataFunction = (input: string, encoding: BinaryDataEncoding) => BinaryData;
86
+ export declare enum SymmetricCryptoAlgorithm {
87
+ AES256CTR = "AES256CTR"
88
+ }
89
+ export declare type Algorithm = {
90
+ type: SymmetricCryptoAlgorithm;
91
+ ivSize: number;
92
+ };
93
+ export declare const ALGORITHMS: Record<SymmetricCryptoAlgorithm, Algorithm>;
94
+ export declare type Crypto = {
95
+ algorithm: Algorithm;
96
+ validateMnemonic: (mnemonic: string) => boolean;
97
+ randomBytes: (bytesLength: number) => BinaryData;
98
+ generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
99
+ };
100
+ export declare type EncryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData) => Promise<void>;
101
+ export declare type DecryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData, fileSize: number) => Promise<void>;
102
+ export {};
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ALGORITHMS = exports.SymmetricCryptoAlgorithm = exports.BinaryDataEncoding = void 0;
5
- var BinaryDataEncoding;
6
- (function (BinaryDataEncoding) {
7
- BinaryDataEncoding["HEX"] = "hex";
8
- })(BinaryDataEncoding = exports.BinaryDataEncoding || (exports.BinaryDataEncoding = {}));
9
- var SymmetricCryptoAlgorithm;
10
- (function (SymmetricCryptoAlgorithm) {
11
- SymmetricCryptoAlgorithm["AES256CTR"] = "AES256CTR";
12
- })(SymmetricCryptoAlgorithm = exports.SymmetricCryptoAlgorithm || (exports.SymmetricCryptoAlgorithm = {}));
13
- exports.ALGORITHMS = (_a = {},
14
- _a[SymmetricCryptoAlgorithm.AES256CTR] = {
15
- type: SymmetricCryptoAlgorithm.AES256CTR,
16
- ivSize: 32
17
- },
18
- _a);
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ALGORITHMS = exports.SymmetricCryptoAlgorithm = exports.BinaryDataEncoding = void 0;
5
+ var BinaryDataEncoding;
6
+ (function (BinaryDataEncoding) {
7
+ BinaryDataEncoding["HEX"] = "hex";
8
+ })(BinaryDataEncoding = exports.BinaryDataEncoding || (exports.BinaryDataEncoding = {}));
9
+ var SymmetricCryptoAlgorithm;
10
+ (function (SymmetricCryptoAlgorithm) {
11
+ SymmetricCryptoAlgorithm["AES256CTR"] = "AES256CTR";
12
+ })(SymmetricCryptoAlgorithm = exports.SymmetricCryptoAlgorithm || (exports.SymmetricCryptoAlgorithm = {}));
13
+ exports.ALGORITHMS = (_a = {},
14
+ _a[SymmetricCryptoAlgorithm.AES256CTR] = {
15
+ type: SymmetricCryptoAlgorithm.AES256CTR,
16
+ ivSize: 32
17
+ },
18
+ _a);
@@ -1,4 +1,4 @@
1
- import { Network } from '.';
2
- import { Crypto, EncryptFileFunction, UploadFileFunction, UploadFileMultipartFunction } from './types';
3
- export declare function uploadFile(network: Network, crypto: Crypto, bucketId: string, mnemonic: string, fileSize: number, encryptFile: EncryptFileFunction, uploadFile: UploadFileFunction): Promise<string>;
4
- export declare function uploadMultipartFile(network: Network, crypto: Crypto, bucketId: string, mnemonic: string, fileSize: number, encryptFile: EncryptFileFunction, uploadMultiparts: UploadFileMultipartFunction, parts?: number): Promise<string>;
1
+ import { Network } from '.';
2
+ import { Crypto, EncryptFileFunction, UploadFileFunction, UploadFileMultipartFunction } from './types';
3
+ export declare function uploadFile(network: Network, crypto: Crypto, bucketId: string, mnemonic: string, fileSize: number, encryptFile: EncryptFileFunction, uploadFile: UploadFileFunction): Promise<string>;
4
+ export declare function uploadMultipartFile(network: Network, crypto: Crypto, bucketId: string, mnemonic: string, fileSize: number, encryptFile: EncryptFileFunction, uploadMultiparts: UploadFileMultipartFunction, parts?: number): Promise<string>;
@@ -1,159 +1,159 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.uploadMultipartFile = exports.uploadFile = void 0;
40
- var errors_1 = require("./errors");
41
- function uploadFile(network, crypto, bucketId, mnemonic, fileSize, encryptFile, uploadFile) {
42
- return __awaiter(this, void 0, void 0, function () {
43
- var index, iv, key, mnemonicIsValid, uploads, _a, url, uuid, hash, finishUploadPayload, finishUploadResponse, err_1, context;
44
- return __generator(this, function (_b) {
45
- switch (_b.label) {
46
- case 0:
47
- _b.trys.push([0, 6, , 7]);
48
- mnemonicIsValid = crypto.validateMnemonic(mnemonic);
49
- if (!mnemonicIsValid) {
50
- throw new errors_1.UploadInvalidMnemonicError();
51
- }
52
- index = crypto.randomBytes(crypto.algorithm.ivSize);
53
- iv = index.slice(0, 16);
54
- return [4 /*yield*/, crypto.generateFileKey(mnemonic, bucketId, index)];
55
- case 1:
56
- key = _b.sent();
57
- return [4 /*yield*/, network.startUpload(bucketId, {
58
- uploads: [{
59
- index: 0,
60
- size: fileSize
61
- }]
62
- })];
63
- case 2:
64
- uploads = (_b.sent()).uploads;
65
- _a = uploads[0], url = _a.url, uuid = _a.uuid;
66
- if (!url) {
67
- throw new errors_1.UrlNotReceivedFromNetworkError();
68
- }
69
- return [4 /*yield*/, encryptFile(crypto.algorithm.type, key, iv)];
70
- case 3:
71
- _b.sent();
72
- return [4 /*yield*/, uploadFile(url)];
73
- case 4:
74
- hash = _b.sent();
75
- finishUploadPayload = {
76
- index: index.toString('hex'),
77
- shards: [{ hash: hash, uuid: uuid }]
78
- };
79
- return [4 /*yield*/, network.finishUpload(bucketId, finishUploadPayload)];
80
- case 5:
81
- finishUploadResponse = _b.sent();
82
- return [2 /*return*/, finishUploadResponse.id];
83
- case 6:
84
- err_1 = _b.sent();
85
- context = (0, errors_1.getNetworkErrorContext)({
86
- bucketId: bucketId,
87
- fileSize: fileSize,
88
- user: network.credentials.username,
89
- pass: network.credentials.password,
90
- crypto: {
91
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
- index: index ? index.toString('hex') : 'none',
93
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
94
- iv: iv ? iv.toString('hex') : 'none',
95
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
- key: key ? key.toString('hex') : 'none',
97
- mnemonic: mnemonic
98
- }
99
- }, err_1);
100
- err_1.context = context;
101
- throw err_1;
102
- case 7: return [2 /*return*/];
103
- }
104
- });
105
- });
106
- }
107
- exports.uploadFile = uploadFile;
108
- function uploadMultipartFile(network, crypto, bucketId, mnemonic, fileSize, encryptFile, uploadMultiparts, parts) {
109
- if (parts === void 0) { parts = 1; }
110
- return __awaiter(this, void 0, void 0, function () {
111
- var mnemonicIsValid, index, iv, key, uploads, _a, urls, uuid, UploadId, _b, hash, uploadedPartsReference, finishUploadPayload, finishUploadResponse;
112
- return __generator(this, function (_c) {
113
- switch (_c.label) {
114
- case 0:
115
- mnemonicIsValid = crypto.validateMnemonic(mnemonic);
116
- if (!mnemonicIsValid) {
117
- throw new errors_1.UploadInvalidMnemonicError();
118
- }
119
- index = crypto.randomBytes(crypto.algorithm.ivSize);
120
- iv = index.slice(0, 16);
121
- return [4 /*yield*/, crypto.generateFileKey(mnemonic, bucketId, index)];
122
- case 1:
123
- key = _c.sent();
124
- return [4 /*yield*/, network.startUpload(bucketId, {
125
- uploads: [
126
- {
127
- index: 0,
128
- size: fileSize,
129
- },
130
- ],
131
- }, parts)];
132
- case 2:
133
- uploads = (_c.sent()).uploads;
134
- _a = uploads[0], urls = _a.urls, uuid = _a.uuid, UploadId = _a.UploadId;
135
- if (!urls) {
136
- throw new errors_1.UrlsNotReceivedFromNetworkError();
137
- }
138
- if (!UploadId) {
139
- throw new errors_1.UploadIdNotReceivedFromNetworkError();
140
- }
141
- return [4 /*yield*/, encryptFile(crypto.algorithm.type, key, iv)];
142
- case 3:
143
- _c.sent();
144
- return [4 /*yield*/, uploadMultiparts(urls)];
145
- case 4:
146
- _b = _c.sent(), hash = _b.hash, uploadedPartsReference = _b.parts;
147
- finishUploadPayload = {
148
- index: index.toString('hex'),
149
- shards: [{ hash: hash, uuid: uuid, UploadId: UploadId, parts: uploadedPartsReference }],
150
- };
151
- return [4 /*yield*/, network.finishUpload(bucketId, finishUploadPayload)];
152
- case 5:
153
- finishUploadResponse = _c.sent();
154
- return [2 /*return*/, finishUploadResponse.id];
155
- }
156
- });
157
- });
158
- }
159
- exports.uploadMultipartFile = uploadMultipartFile;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.uploadMultipartFile = exports.uploadFile = void 0;
40
+ var errors_1 = require("./errors");
41
+ function uploadFile(network, crypto, bucketId, mnemonic, fileSize, encryptFile, uploadFile) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var index, iv, key, mnemonicIsValid, uploads, _a, url, uuid, hash, finishUploadPayload, finishUploadResponse, err_1, context;
44
+ return __generator(this, function (_b) {
45
+ switch (_b.label) {
46
+ case 0:
47
+ _b.trys.push([0, 6, , 7]);
48
+ mnemonicIsValid = crypto.validateMnemonic(mnemonic);
49
+ if (!mnemonicIsValid) {
50
+ throw new errors_1.UploadInvalidMnemonicError();
51
+ }
52
+ index = crypto.randomBytes(crypto.algorithm.ivSize);
53
+ iv = index.slice(0, 16);
54
+ return [4 /*yield*/, crypto.generateFileKey(mnemonic, bucketId, index)];
55
+ case 1:
56
+ key = _b.sent();
57
+ return [4 /*yield*/, network.startUpload(bucketId, {
58
+ uploads: [{
59
+ index: 0,
60
+ size: fileSize
61
+ }]
62
+ })];
63
+ case 2:
64
+ uploads = (_b.sent()).uploads;
65
+ _a = uploads[0], url = _a.url, uuid = _a.uuid;
66
+ if (!url) {
67
+ throw new errors_1.UrlNotReceivedFromNetworkError();
68
+ }
69
+ return [4 /*yield*/, encryptFile(crypto.algorithm.type, key, iv)];
70
+ case 3:
71
+ _b.sent();
72
+ return [4 /*yield*/, uploadFile(url)];
73
+ case 4:
74
+ hash = _b.sent();
75
+ finishUploadPayload = {
76
+ index: index.toString('hex'),
77
+ shards: [{ hash: hash, uuid: uuid }]
78
+ };
79
+ return [4 /*yield*/, network.finishUpload(bucketId, finishUploadPayload)];
80
+ case 5:
81
+ finishUploadResponse = _b.sent();
82
+ return [2 /*return*/, finishUploadResponse.id];
83
+ case 6:
84
+ err_1 = _b.sent();
85
+ context = (0, errors_1.getNetworkErrorContext)({
86
+ bucketId: bucketId,
87
+ fileSize: fileSize,
88
+ user: network.credentials.username,
89
+ pass: network.credentials.password,
90
+ crypto: {
91
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
+ index: index ? index.toString('hex') : 'none',
93
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
94
+ iv: iv ? iv.toString('hex') : 'none',
95
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
+ key: key ? key.toString('hex') : 'none',
97
+ mnemonic: mnemonic
98
+ }
99
+ }, err_1);
100
+ err_1.context = context;
101
+ throw err_1;
102
+ case 7: return [2 /*return*/];
103
+ }
104
+ });
105
+ });
106
+ }
107
+ exports.uploadFile = uploadFile;
108
+ function uploadMultipartFile(network, crypto, bucketId, mnemonic, fileSize, encryptFile, uploadMultiparts, parts) {
109
+ if (parts === void 0) { parts = 1; }
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var mnemonicIsValid, index, iv, key, uploads, _a, urls, uuid, UploadId, _b, hash, uploadedPartsReference, finishUploadPayload, finishUploadResponse;
112
+ return __generator(this, function (_c) {
113
+ switch (_c.label) {
114
+ case 0:
115
+ mnemonicIsValid = crypto.validateMnemonic(mnemonic);
116
+ if (!mnemonicIsValid) {
117
+ throw new errors_1.UploadInvalidMnemonicError();
118
+ }
119
+ index = crypto.randomBytes(crypto.algorithm.ivSize);
120
+ iv = index.slice(0, 16);
121
+ return [4 /*yield*/, crypto.generateFileKey(mnemonic, bucketId, index)];
122
+ case 1:
123
+ key = _c.sent();
124
+ return [4 /*yield*/, network.startUpload(bucketId, {
125
+ uploads: [
126
+ {
127
+ index: 0,
128
+ size: fileSize,
129
+ },
130
+ ],
131
+ }, parts)];
132
+ case 2:
133
+ uploads = (_c.sent()).uploads;
134
+ _a = uploads[0], urls = _a.urls, uuid = _a.uuid, UploadId = _a.UploadId;
135
+ if (!urls) {
136
+ throw new errors_1.UrlsNotReceivedFromNetworkError();
137
+ }
138
+ if (!UploadId) {
139
+ throw new errors_1.UploadIdNotReceivedFromNetworkError();
140
+ }
141
+ return [4 /*yield*/, encryptFile(crypto.algorithm.type, key, iv)];
142
+ case 3:
143
+ _c.sent();
144
+ return [4 /*yield*/, uploadMultiparts(urls)];
145
+ case 4:
146
+ _b = _c.sent(), hash = _b.hash, uploadedPartsReference = _b.parts;
147
+ finishUploadPayload = {
148
+ index: index.toString('hex'),
149
+ shards: [{ hash: hash, uuid: uuid, UploadId: UploadId, parts: uploadedPartsReference }],
150
+ };
151
+ return [4 /*yield*/, network.finishUpload(bucketId, finishUploadPayload)];
152
+ case 5:
153
+ finishUploadResponse = _c.sent();
154
+ return [2 /*return*/, finishUploadResponse.id];
155
+ }
156
+ });
157
+ });
158
+ }
159
+ exports.uploadMultipartFile = uploadMultipartFile;
@@ -1,10 +1,10 @@
1
- import { CreateDeviceData, Device, DeviceId, PhotosSdkModel } from '..';
2
- export default class DevicesSubmodule {
3
- private model;
4
- constructor(model: PhotosSdkModel);
5
- getDeviceById(deviceId: DeviceId): Promise<Device>;
6
- getDevices(): Promise<Device[]>;
7
- createDevice(data: CreateDeviceData): Promise<Device>;
8
- deleteDevice(deviceId: DeviceId): Promise<void>;
9
- private parse;
10
- }
1
+ import { CreateDeviceData, Device, DeviceId, PhotosSdkModel } from '..';
2
+ export default class DevicesSubmodule {
3
+ private model;
4
+ constructor(model: PhotosSdkModel);
5
+ getDeviceById(deviceId: DeviceId): Promise<Device>;
6
+ getDevices(): Promise<Device[]>;
7
+ createDevice(data: CreateDeviceData): Promise<Device>;
8
+ deleteDevice(deviceId: DeviceId): Promise<void>;
9
+ private parse;
10
+ }