@internxt/sdk 1.17.11 → 1.17.13
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/drive/payments/index.d.ts +1 -0
- package/dist/drive/payments/index.js +3 -0
- package/dist/drive/payments/types/types.d.ts +9 -5
- package/dist/network/download.d.ts +4 -1
- package/dist/network/download.js +29 -0
- package/dist/network/errors/context.d.ts +2 -0
- package/dist/network/errors/context.js +2 -0
- package/dist/network/types.d.ts +8 -3
- package/package.json +1 -1
|
@@ -30,6 +30,7 @@ export declare class Payments {
|
|
|
30
30
|
clientSecret: string;
|
|
31
31
|
}>;
|
|
32
32
|
updateWorkspaceMembers(workspaceId: string, subscriptionId: string, updatedSeats: number): Promise<unknown>;
|
|
33
|
+
applyCancellationTrial(subscriptionId: string): Promise<void>;
|
|
33
34
|
cancelSubscription(userType?: UserType): Promise<void>;
|
|
34
35
|
updateCustomerBillingInfo(payload: CustomerBillingInfo): Promise<void>;
|
|
35
36
|
/**
|
|
@@ -88,6 +88,9 @@ class Payments {
|
|
|
88
88
|
workspaceUpdatedSeats: updatedSeats,
|
|
89
89
|
}, this.headers());
|
|
90
90
|
}
|
|
91
|
+
applyCancellationTrial(subscriptionId) {
|
|
92
|
+
return this.client.post('/customer/cancellation-trial', { subscriptionId }, this.headers());
|
|
93
|
+
}
|
|
91
94
|
cancelSubscription(userType) {
|
|
92
95
|
const query = new URLSearchParams();
|
|
93
96
|
if (userType)
|
|
@@ -59,6 +59,12 @@ export declare enum UserType {
|
|
|
59
59
|
Individual = "individual",
|
|
60
60
|
Business = "business"
|
|
61
61
|
}
|
|
62
|
+
export type Commitment = {
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
remainingMonths?: number;
|
|
65
|
+
cancellationDate?: string;
|
|
66
|
+
isElegibleForCancellation?: boolean;
|
|
67
|
+
};
|
|
62
68
|
export type StoragePlan = {
|
|
63
69
|
planId: string;
|
|
64
70
|
productId: string;
|
|
@@ -71,11 +77,9 @@ export type StoragePlan = {
|
|
|
71
77
|
isTeam: boolean;
|
|
72
78
|
isLifetime: boolean;
|
|
73
79
|
renewalPeriod: RenewalPeriod;
|
|
74
|
-
commitment:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
remainingMonths?: number;
|
|
78
|
-
cancellationDate?: string | null;
|
|
80
|
+
commitment: Commitment;
|
|
81
|
+
cancellationTrial: {
|
|
82
|
+
redeemed: boolean;
|
|
79
83
|
};
|
|
80
84
|
storageLimit: number;
|
|
81
85
|
amountOfSeats: number;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Network } from '.';
|
|
2
|
-
import { Crypto, DecryptFileFunction, DownloadFileFunction, ToBinaryDataFunction } from './types';
|
|
2
|
+
import { Crypto, DecryptFileFunction, DownloadFileFunction, ToBinaryDataFunction, CryptoWithBucketKey } from './types';
|
|
3
3
|
export declare class FileVersionOneError extends Error {
|
|
4
4
|
constructor();
|
|
5
5
|
}
|
|
6
6
|
export declare function downloadFile(fileId: string, bucketId: string, mnemonic: string, network: Network, crypto: Crypto, toBinaryData: ToBinaryDataFunction, downloadFile: DownloadFileFunction, decryptFile: DecryptFileFunction, opts?: {
|
|
7
7
|
token: string;
|
|
8
8
|
}): Promise<void>;
|
|
9
|
+
export declare function downloadFileWithBucketKey(fileId: string, bucketId: string, bucketKey: Buffer, network: Network, crypto: CryptoWithBucketKey, toBinaryData: ToBinaryDataFunction, downloadFile: DownloadFileFunction, decryptFile: DecryptFileFunction, opts?: {
|
|
10
|
+
token: string;
|
|
11
|
+
}): Promise<void>;
|
package/dist/network/download.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FileVersionOneError = void 0;
|
|
4
4
|
exports.downloadFile = downloadFile;
|
|
5
|
+
exports.downloadFileWithBucketKey = downloadFileWithBucketKey;
|
|
5
6
|
const errors_1 = require("./errors");
|
|
6
7
|
const types_1 = require("./types");
|
|
7
8
|
class FileVersionOneError extends Error {
|
|
@@ -45,3 +46,31 @@ async function downloadFile(fileId, bucketId, mnemonic, network, crypto, toBinar
|
|
|
45
46
|
throw err;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
49
|
+
async function downloadFileWithBucketKey(fileId, bucketId, bucketKey, network, crypto, toBinaryData, downloadFile, decryptFile, opts) {
|
|
50
|
+
let iv;
|
|
51
|
+
let key;
|
|
52
|
+
try {
|
|
53
|
+
const fileInfo = await network.getDownloadLinks(bucketId, fileId, opts?.token);
|
|
54
|
+
const { index, shards, version, size } = fileInfo;
|
|
55
|
+
if (!version || version === 1) {
|
|
56
|
+
throw new FileVersionOneError();
|
|
57
|
+
}
|
|
58
|
+
iv = toBinaryData(index, types_1.BinaryDataEncoding.HEX).slice(0, 16);
|
|
59
|
+
key = await crypto.generateFileKeyFromBucketKey(bucketKey, toBinaryData(index, types_1.BinaryDataEncoding.HEX));
|
|
60
|
+
const downloadables = shards.sort((sA, sB) => sA.index - sB.index);
|
|
61
|
+
await downloadFile(downloadables, fileInfo);
|
|
62
|
+
await decryptFile(crypto.algorithm.type, key, iv, size);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
const context = (0, errors_1.getNetworkErrorContext)({
|
|
66
|
+
bucketId,
|
|
67
|
+
fileId,
|
|
68
|
+
user: network.credentials.username,
|
|
69
|
+
crypto: {
|
|
70
|
+
bucketKey,
|
|
71
|
+
},
|
|
72
|
+
}, err);
|
|
73
|
+
err.context = context;
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -4,6 +4,7 @@ export type NetworkUploadContext = {
|
|
|
4
4
|
user: string;
|
|
5
5
|
crypto: {
|
|
6
6
|
mnemonic?: string;
|
|
7
|
+
bucketKey?: Buffer;
|
|
7
8
|
};
|
|
8
9
|
};
|
|
9
10
|
export type NetworkDownloadContext = {
|
|
@@ -12,6 +13,7 @@ export type NetworkDownloadContext = {
|
|
|
12
13
|
user: string;
|
|
13
14
|
crypto: {
|
|
14
15
|
mnemonic?: string;
|
|
16
|
+
bucketKey?: Buffer;
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
19
|
export type NetworkContext = NetworkUploadContext | NetworkDownloadContext;
|
|
@@ -15,8 +15,10 @@ exports.ErrorWithContext = ErrorWithContext;
|
|
|
15
15
|
function getNetworkErrorContext(input, err) {
|
|
16
16
|
const output = Object.assign({}, input);
|
|
17
17
|
delete output.crypto.mnemonic;
|
|
18
|
+
delete output.crypto.bucketKey;
|
|
18
19
|
if (err instanceof upload_1.UploadInvalidMnemonicError || err instanceof download_1.DownloadInvalidMnemonicError) {
|
|
19
20
|
output.crypto.mnemonic = input.crypto.mnemonic;
|
|
21
|
+
output.crypto.bucketKey = input.crypto.bucketKey;
|
|
20
22
|
}
|
|
21
23
|
return output;
|
|
22
24
|
}
|
package/dist/network/types.d.ts
CHANGED
|
@@ -101,13 +101,18 @@ export type Algorithm = {
|
|
|
101
101
|
ivSize: number;
|
|
102
102
|
};
|
|
103
103
|
export declare const ALGORITHMS: Record<SymmetricCryptoAlgorithm, Algorithm>;
|
|
104
|
-
|
|
104
|
+
type CryptoBase = {
|
|
105
105
|
algorithm: Algorithm;
|
|
106
|
-
validateMnemonic: (mnemonic: string) => boolean;
|
|
107
106
|
randomBytes: (bytesLength: number) => BinaryData;
|
|
108
|
-
generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
|
|
109
107
|
computeHmac?: (key: BinaryData, shardHashes: string[]) => Promise<HmacPayload>;
|
|
110
108
|
};
|
|
109
|
+
export type Crypto = CryptoBase & {
|
|
110
|
+
validateMnemonic: (mnemonic: string) => boolean;
|
|
111
|
+
generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
|
|
112
|
+
};
|
|
113
|
+
export type CryptoWithBucketKey = CryptoBase & {
|
|
114
|
+
generateFileKeyFromBucketKey: (bucketKey: Buffer, index: BinaryData) => Promise<BinaryData>;
|
|
115
|
+
};
|
|
111
116
|
export type EncryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData) => Promise<void>;
|
|
112
117
|
export type DecryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData, fileSize: number) => Promise<void>;
|
|
113
118
|
export {};
|