@secrecy/lib 1.48.0-feat-update-typedoc.1 → 1.49.0-feat-report-data.1
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/lib/base-client.js
CHANGED
|
@@ -14,25 +14,10 @@ async function getPublicUser(client, id) {
|
|
|
14
14
|
usersCache.set(user.id, user);
|
|
15
15
|
return user;
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* The `BaseClient` class provides methods for interacting with API clients, handling sessions,
|
|
19
|
-
* and managing users.
|
|
20
|
-
*/
|
|
21
17
|
export class BaseClient {
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new instance of the API client.
|
|
24
|
-
* @param session - The session ID, which can be null or undefined.
|
|
25
|
-
* @param onAccessDenied - Callback function to execute when access is denied.
|
|
26
|
-
* @returns The API client.
|
|
27
|
-
*/
|
|
28
18
|
static getBaseClient = (session, onAccessDenied) => createTRPCClient(session, onAccessDenied);
|
|
29
19
|
client;
|
|
30
20
|
sessionId;
|
|
31
|
-
/**
|
|
32
|
-
* Initializes the `BaseClient` with a session ID and access denied handler.
|
|
33
|
-
* @param session - The session ID.
|
|
34
|
-
* @param onAccessDenied - A callback function when access is denied.
|
|
35
|
-
*/
|
|
36
21
|
constructor(session, onAccessDenied) {
|
|
37
22
|
this.sessionId = session;
|
|
38
23
|
this.client = BaseClient.getBaseClient(session, async () => {
|
|
@@ -47,14 +32,9 @@ export class BaseClient {
|
|
|
47
32
|
}
|
|
48
33
|
});
|
|
49
34
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Logs out the current session by clearing session data and calling the API logout method.
|
|
52
|
-
* @param sessionId - The session ID to log out from (optional).
|
|
53
|
-
* @returns A promise that resolves when the operation is complete.
|
|
54
|
-
*/
|
|
55
35
|
async logout(sessionId) {
|
|
56
36
|
if (sessionId === null || sessionId === undefined) {
|
|
57
|
-
this
|
|
37
|
+
this.#clean();
|
|
58
38
|
}
|
|
59
39
|
await this.client.auth.logout.mutate({
|
|
60
40
|
sessionId: sessionId ?? null,
|
|
@@ -105,11 +85,7 @@ export class BaseClient {
|
|
|
105
85
|
});
|
|
106
86
|
return getPaymentRequestToPay;
|
|
107
87
|
};
|
|
108
|
-
|
|
109
|
-
* Clears stored session and user data.
|
|
110
|
-
* @private
|
|
111
|
-
*/
|
|
112
|
-
clean = () => {
|
|
88
|
+
#clean = () => {
|
|
113
89
|
const local = getStorage(false);
|
|
114
90
|
const session = getStorage(true);
|
|
115
91
|
local.jwt.clear();
|
|
@@ -137,18 +137,11 @@ export class SecrecyCloudClient {
|
|
|
137
137
|
return uploadData.id;
|
|
138
138
|
}
|
|
139
139
|
const uploadDataPartEnd = async (md5, order) => {
|
|
140
|
-
|
|
140
|
+
return this.#apiClient.cloud.uploadDataPartEnd.mutate({
|
|
141
141
|
dataId: uploadData.id,
|
|
142
142
|
md5,
|
|
143
143
|
order,
|
|
144
144
|
}, { signal });
|
|
145
|
-
return isUploadPartEnded;
|
|
146
|
-
};
|
|
147
|
-
const uploadEnded = async () => {
|
|
148
|
-
const { isUploadEnded } = await this.#apiClient.cloud.uploadDataEnd.mutate({
|
|
149
|
-
dataId: uploadData.id,
|
|
150
|
-
}, { signal });
|
|
151
|
-
return isUploadEnded;
|
|
152
145
|
};
|
|
153
146
|
const chunkParts = new Array();
|
|
154
147
|
for (const [index, chunk] of enumerate(chunks(encryptedData, Number(uploadData.partSize)))) {
|
|
@@ -184,12 +177,11 @@ export class SecrecyCloudClient {
|
|
|
184
177
|
},
|
|
185
178
|
signal,
|
|
186
179
|
});
|
|
187
|
-
|
|
180
|
+
return uploadDataPartEnd(chunk.md5, chunk.order);
|
|
188
181
|
};
|
|
189
182
|
await promiseAllLimit(3, uploadData.parts.map((p) => async () => {
|
|
190
183
|
await byPart(p);
|
|
191
184
|
}));
|
|
192
|
-
await uploadEnded();
|
|
193
185
|
dataContentCache.set(uploadData.id, dataBuffer);
|
|
194
186
|
return uploadData.id;
|
|
195
187
|
}
|
|
@@ -557,4 +549,20 @@ export class SecrecyCloudClient {
|
|
|
557
549
|
: [],
|
|
558
550
|
};
|
|
559
551
|
};
|
|
552
|
+
async reportData({ id, reasons, }) {
|
|
553
|
+
const [data, secrecy] = await Promise.all([
|
|
554
|
+
this.#apiClient.cloud.dataById.query({ id }),
|
|
555
|
+
this.#apiClient.misc.publicKey.query(),
|
|
556
|
+
]);
|
|
557
|
+
if (!data.access.key) {
|
|
558
|
+
throw new Error('Unable to retreive data key!');
|
|
559
|
+
}
|
|
560
|
+
const decryptedDataKey = decryptCryptoBox(sodium.from_hex(data.access.key), this.#keys.publicKey, this.#keys.privateKey);
|
|
561
|
+
const encryptedDataKey = sodium.to_hex(encryptCryptoBox(decryptedDataKey, secrecy.publicKey, this.#keys.privateKey));
|
|
562
|
+
return this.#apiClient.cloud.reportData.mutate({
|
|
563
|
+
id,
|
|
564
|
+
reasons,
|
|
565
|
+
encryptedDataKey,
|
|
566
|
+
});
|
|
567
|
+
}
|
|
560
568
|
}
|
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
import { type ApiClient, type RouterOutputs, type RouterInputs } from './client.js';
|
|
2
2
|
import { type InfuraNetwork, type PublicUser } from './index.js';
|
|
3
3
|
import { type SelfUser } from './client/types/user.js';
|
|
4
|
-
/**
|
|
5
|
-
* The `BaseClient` class provides methods for interacting with API clients, handling sessions,
|
|
6
|
-
* and managing users.
|
|
7
|
-
*/
|
|
8
4
|
export declare class BaseClient {
|
|
9
|
-
|
|
10
|
-
* Creates a new instance of the API client.
|
|
11
|
-
* @param session - The session ID, which can be null or undefined.
|
|
12
|
-
* @param onAccessDenied - Callback function to execute when access is denied.
|
|
13
|
-
* @returns The API client.
|
|
14
|
-
*/
|
|
5
|
+
#private;
|
|
15
6
|
static readonly getBaseClient: (session?: string | null | undefined, onAccessDenied?: () => void | Promise<void>) => ApiClient;
|
|
16
7
|
protected client: ApiClient;
|
|
17
8
|
sessionId: string;
|
|
18
|
-
/**
|
|
19
|
-
* Initializes the `BaseClient` with a session ID and access denied handler.
|
|
20
|
-
* @param session - The session ID.
|
|
21
|
-
* @param onAccessDenied - A callback function when access is denied.
|
|
22
|
-
*/
|
|
23
9
|
constructor(session: string, onAccessDenied?: () => void | Promise<void>);
|
|
24
|
-
/**
|
|
25
|
-
* Logs out the current session by clearing session data and calling the API logout method.
|
|
26
|
-
* @param sessionId - The session ID to log out from (optional).
|
|
27
|
-
* @returns A promise that resolves when the operation is complete.
|
|
28
|
-
*/
|
|
29
10
|
logout(sessionId?: string | null | undefined): Promise<void>;
|
|
30
11
|
me(): Promise<SelfUser>;
|
|
31
12
|
static getUser(userId: string, sessionId?: string | null | undefined): Promise<PublicUser>;
|
|
@@ -44,9 +25,4 @@ export declare class BaseClient {
|
|
|
44
25
|
paymentRequestId: string;
|
|
45
26
|
secrecyIdSeller: string;
|
|
46
27
|
}) => Promise<RouterOutputs["stripe"]["paymentRequestToPay"]>;
|
|
47
|
-
/**
|
|
48
|
-
* Clears stored session and user data.
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
private readonly clean;
|
|
52
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProgressCallback, SecrecyClient } from '../index.js';
|
|
2
2
|
import type { DataMetadata, KeyPair, Node, NodeFull, NodeType, Rights } from './types/index.js';
|
|
3
|
-
import { type ApiClient } from '../client.js';
|
|
3
|
+
import { type RouterInputs, type ApiClient, type RouterOutputs } from '../client.js';
|
|
4
4
|
import { type DownloadProgress } from '../types.js';
|
|
5
5
|
export declare class SecrecyCloudClient {
|
|
6
6
|
#private;
|
|
@@ -94,4 +94,5 @@ export declare class SecrecyCloudClient {
|
|
|
94
94
|
nodeId?: string;
|
|
95
95
|
}): Promise<NodeFull>;
|
|
96
96
|
private readonly perNode;
|
|
97
|
+
reportData({ id, reasons, }: Omit<RouterInputs['cloud']['reportData'], 'encryptedDataKey'>): Promise<RouterOutputs['cloud']['reportData']>;
|
|
97
98
|
}
|