@secrecy/lib 1.55.3 → 1.57.0
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 +18 -15
- package/dist/lib/client/index.js +11 -8
- package/dist/lib/client.js +5 -17
- package/dist/types/base-client.d.ts +9 -4
- package/dist/types/client.d.ts +10 -4
- package/package.json +2 -2
package/dist/lib/base-client.js
CHANGED
|
@@ -15,21 +15,24 @@ async function getPublicUser(client, id) {
|
|
|
15
15
|
return user;
|
|
16
16
|
}
|
|
17
17
|
export class BaseClient {
|
|
18
|
-
static getBaseClient = (
|
|
18
|
+
static getBaseClient = (opts = {}) => createTRPCClient(opts);
|
|
19
19
|
client;
|
|
20
20
|
sessionId;
|
|
21
|
-
constructor(
|
|
22
|
-
this.sessionId = session;
|
|
23
|
-
this.client = BaseClient.getBaseClient(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
constructor(opts) {
|
|
22
|
+
this.sessionId = opts.session;
|
|
23
|
+
this.client = BaseClient.getBaseClient({
|
|
24
|
+
...opts,
|
|
25
|
+
onAccessDenied: async () => {
|
|
26
|
+
console.log('[BASE_CLIENT - BEFORE] - Access denied');
|
|
27
|
+
await opts.onAccessDenied?.();
|
|
28
|
+
console.log('[BASE_CLIENT - AFTER] - Access denied');
|
|
29
|
+
try {
|
|
30
|
+
await this.logout();
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
location.reload();
|
|
34
|
+
}
|
|
35
|
+
},
|
|
33
36
|
});
|
|
34
37
|
}
|
|
35
38
|
async logout(sessionId) {
|
|
@@ -43,8 +46,8 @@ export class BaseClient {
|
|
|
43
46
|
async me() {
|
|
44
47
|
return await this.client.user.self.query({});
|
|
45
48
|
}
|
|
46
|
-
static async getUser(userId,
|
|
47
|
-
const user = await getPublicUser(this.getBaseClient(
|
|
49
|
+
static async getUser(userId, session) {
|
|
50
|
+
const user = await getPublicUser(this.getBaseClient({ session }), userId);
|
|
48
51
|
return user;
|
|
49
52
|
}
|
|
50
53
|
async getUser(userId) {
|
package/dist/lib/client/index.js
CHANGED
|
@@ -27,14 +27,17 @@ export class SecrecyClient extends BaseClient {
|
|
|
27
27
|
user;
|
|
28
28
|
pseudonym;
|
|
29
29
|
constructor(uaSession, uaKeys, uaJwt) {
|
|
30
|
-
super(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
super({
|
|
31
|
+
session: uaSession,
|
|
32
|
+
onAccessDenied: async () => {
|
|
33
|
+
console.log('[CLIENT] - Access denied');
|
|
34
|
+
try {
|
|
35
|
+
await this.logout();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// ignore
|
|
39
|
+
}
|
|
40
|
+
},
|
|
38
41
|
});
|
|
39
42
|
this.#keys = uaKeys;
|
|
40
43
|
this.cloud = new SecrecyCloudClient(this, this.#keys, this.client);
|
package/dist/lib/client.js
CHANGED
|
@@ -9,19 +9,7 @@ superjson.registerCustom({
|
|
|
9
9
|
serialize: (v) => [...v],
|
|
10
10
|
deserialize: (v) => Buffer.from(v),
|
|
11
11
|
}, 'buffer');
|
|
12
|
-
export const
|
|
13
|
-
if (process.env.NEXT_PUBLIC_SECRECY_URL) {
|
|
14
|
-
return `${process.env.NEXT_PUBLIC_SECRECY_URL}/api/trpc`;
|
|
15
|
-
}
|
|
16
|
-
const protocol = process.env.NEXT_PUBLIC_VERCEL_ENV !== 'development' ? 'https' : 'http';
|
|
17
|
-
const url = process.env.NEXT_PUBLIC_VERCEL_ENV &&
|
|
18
|
-
process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production' &&
|
|
19
|
-
process.env.NEXT_PUBLIC_IS_SECRECY_INTERNAL === 'true'
|
|
20
|
-
? `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_URL}/api/trpc`
|
|
21
|
-
: `https://www.secrecy.tech/api/trpc`;
|
|
22
|
-
return url;
|
|
23
|
-
};
|
|
24
|
-
export const createTRPCClient = (session, onAccessDenied) => createTRPCProxyClient({
|
|
12
|
+
export const createTRPCClient = (opts) => createTRPCProxyClient({
|
|
25
13
|
transformer: superjson,
|
|
26
14
|
links: [
|
|
27
15
|
loggerLink({
|
|
@@ -29,14 +17,14 @@ export const createTRPCClient = (session, onAccessDenied) => createTRPCProxyClie
|
|
|
29
17
|
if (op.direction === 'down' &&
|
|
30
18
|
isTRPCClientError(op.result) &&
|
|
31
19
|
op.result.data?.code === 'UNAUTHORIZED') {
|
|
32
|
-
void onAccessDenied?.();
|
|
20
|
+
void opts.onAccessDenied?.();
|
|
33
21
|
}
|
|
34
22
|
return (process.env.NODE_ENV === 'development' ||
|
|
35
23
|
(op.direction === 'down' && op.result instanceof Error));
|
|
36
24
|
},
|
|
37
25
|
}),
|
|
38
26
|
httpBatchLink({
|
|
39
|
-
url:
|
|
27
|
+
url: opts.apiUrl ?? 'https://secrecy.tech/api/trpc',
|
|
40
28
|
maxURLLength: 2083,
|
|
41
29
|
fetch: async (input, init) => {
|
|
42
30
|
const controller = new AbortController();
|
|
@@ -45,8 +33,8 @@ export const createTRPCClient = (session, onAccessDenied) => createTRPCProxyClie
|
|
|
45
33
|
}, 20000);
|
|
46
34
|
const headers = new Headers(init?.headers);
|
|
47
35
|
headers.set('secrecy-lib-version', SECRECY_LIB_VERSION);
|
|
48
|
-
if (typeof session === 'string') {
|
|
49
|
-
headers.set('secrecy-session', session);
|
|
36
|
+
if (typeof opts.session === 'string') {
|
|
37
|
+
headers.set('secrecy-session', opts.session);
|
|
50
38
|
}
|
|
51
39
|
const call = fetch(input, {
|
|
52
40
|
...init,
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { type ApiClient, type RouterOutputs, type RouterInputs } from './client.js';
|
|
1
|
+
import { type ApiClient, type RouterOutputs, type RouterInputs, CreateTrpcClientOptions } from './client.js';
|
|
2
2
|
import { type InfuraNetwork, type PublicUser } from './index.js';
|
|
3
3
|
import { type SelfUser } from './client/types/user.js';
|
|
4
|
+
export type BaseClientOptions = {
|
|
5
|
+
session: string;
|
|
6
|
+
apiUrl?: string | null | undefined;
|
|
7
|
+
onAccessDenied?: () => void | Promise<void>;
|
|
8
|
+
};
|
|
4
9
|
export declare class BaseClient {
|
|
5
10
|
#private;
|
|
6
|
-
static readonly getBaseClient: (
|
|
11
|
+
static readonly getBaseClient: (opts?: CreateTrpcClientOptions) => ApiClient;
|
|
7
12
|
protected client: ApiClient;
|
|
8
13
|
sessionId: string;
|
|
9
|
-
constructor(
|
|
14
|
+
constructor(opts: BaseClientOptions);
|
|
10
15
|
logout(sessionId?: string | null | undefined): Promise<void>;
|
|
11
16
|
me(): Promise<SelfUser>;
|
|
12
|
-
static getUser(userId: string,
|
|
17
|
+
static getUser(userId: string, session?: string | undefined): Promise<PublicUser>;
|
|
13
18
|
getUser(userId: string): Promise<PublicUser>;
|
|
14
19
|
searchUsers(search: string): Promise<PublicUser[]>;
|
|
15
20
|
updateProfile(data: RouterInputs['user']['updateProfile']): Promise<Omit<SelfUser, 'account'>>;
|
package/dist/types/client.d.ts
CHANGED
|
@@ -5,8 +5,12 @@ import superjson from 'superjson';
|
|
|
5
5
|
export type RouterInputs = inferRouterInputs<AppRouter>;
|
|
6
6
|
export type RouterOutputs = inferRouterOutputs<AppRouter>;
|
|
7
7
|
export declare function isTRPCClientError(cause: unknown): cause is TRPCClientError<AppRouter>;
|
|
8
|
-
export
|
|
9
|
-
|
|
8
|
+
export interface CreateTrpcClientOptions {
|
|
9
|
+
session?: string | null | undefined;
|
|
10
|
+
apiUrl?: string | null | undefined;
|
|
11
|
+
onAccessDenied?: () => void | Promise<void> | null | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => {
|
|
10
14
|
account: {
|
|
11
15
|
createUser: {
|
|
12
16
|
mutate: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"mutation", {
|
|
@@ -3878,13 +3882,15 @@ export declare const createTRPCClient: (session?: string | null | undefined, onA
|
|
|
3878
3882
|
name: string;
|
|
3879
3883
|
dataId: string;
|
|
3880
3884
|
expireAt: Date | null;
|
|
3881
|
-
|
|
3885
|
+
} & {
|
|
3886
|
+
slug?: string | undefined;
|
|
3882
3887
|
};
|
|
3883
3888
|
_input_out: {
|
|
3884
3889
|
name: string;
|
|
3885
3890
|
dataId: string;
|
|
3886
3891
|
expireAt: Date | null;
|
|
3887
|
-
|
|
3892
|
+
} & {
|
|
3893
|
+
slug?: string | undefined;
|
|
3888
3894
|
};
|
|
3889
3895
|
_output_in: {
|
|
3890
3896
|
name: string;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@secrecy/lib",
|
|
3
3
|
"author": "Anonymize <anonymize@gmail.com>",
|
|
4
4
|
"description": "Anonymize Secrecy Library",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.57.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/anonymize-org/lib.git"
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typescript": "^5.6.2"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@secrecy/trpc-api-types": "1.33.0-dev.
|
|
77
|
+
"@secrecy/trpc-api-types": "1.33.0-dev.48",
|
|
78
78
|
"@trpc/client": "10.45.2",
|
|
79
79
|
"@trpc/server": "10.45.2",
|
|
80
80
|
"@types/libsodium-wrappers-sumo": "^0.7.8",
|