@secrecy/lib 1.56.0 → 1.58.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 +24 -19
- package/dist/lib/client/SecrecyPayClient.js +9 -12
- package/dist/lib/client/SecrecyWalletClient.js +12 -17
- package/dist/lib/client/helpers.js +2 -19
- package/dist/lib/client/index.js +11 -8
- package/dist/lib/client.js +7 -17
- package/dist/types/base-client.d.ts +14 -6
- package/dist/types/client/helpers.d.ts +2 -5
- package/dist/types/client.d.ts +6 -2
- package/package.json +1 -1
package/dist/lib/base-client.js
CHANGED
|
@@ -15,21 +15,26 @@ 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
|
+
baseUrl;
|
|
20
21
|
sessionId;
|
|
21
|
-
constructor(
|
|
22
|
-
this.sessionId = session;
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
constructor(opts) {
|
|
23
|
+
this.sessionId = opts.session;
|
|
24
|
+
this.baseUrl = opts.baseUrl ?? 'https://www.secrecy.tech';
|
|
25
|
+
this.client = BaseClient.getBaseClient({
|
|
26
|
+
...opts,
|
|
27
|
+
onAccessDenied: async () => {
|
|
28
|
+
console.log('[BASE_CLIENT - BEFORE] - Access denied');
|
|
29
|
+
await opts.onAccessDenied?.();
|
|
30
|
+
console.log('[BASE_CLIENT - AFTER] - Access denied');
|
|
31
|
+
try {
|
|
32
|
+
await this.logout();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
location.reload();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
async logout(sessionId) {
|
|
@@ -43,8 +48,8 @@ export class BaseClient {
|
|
|
43
48
|
async me() {
|
|
44
49
|
return await this.client.user.self.query({});
|
|
45
50
|
}
|
|
46
|
-
static async getUser(userId,
|
|
47
|
-
const user = await getPublicUser(this.getBaseClient(
|
|
51
|
+
static async getUser(userId, opts) {
|
|
52
|
+
const user = await getPublicUser(this.getBaseClient(opts), userId);
|
|
48
53
|
return user;
|
|
49
54
|
}
|
|
50
55
|
async getUser(userId) {
|
|
@@ -61,8 +66,8 @@ export class BaseClient {
|
|
|
61
66
|
const updateProfile = await this.client.user.updateProfile.mutate(data);
|
|
62
67
|
return updateProfile;
|
|
63
68
|
}
|
|
64
|
-
static async isCryptoTransactionDone({ idOrHash, network = 'mainnet', }) {
|
|
65
|
-
const { isDone } = await this.getBaseClient().crypto.isTransactionDone.query({
|
|
69
|
+
static async isCryptoTransactionDone({ idOrHash, network = 'mainnet', opts, }) {
|
|
70
|
+
const { isDone } = await this.getBaseClient(opts).crypto.isTransactionDone.query({
|
|
66
71
|
idOrHash,
|
|
67
72
|
network,
|
|
68
73
|
});
|
|
@@ -78,8 +83,8 @@ export class BaseClient {
|
|
|
78
83
|
path: `/sign-up?gf=${btoa(getPreferedEmail(me.account.emails)?.email)}&au=${btoa(backUrl)}`,
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
|
-
static getPaymentRequest = async ({ paymentRequestId, secrecyIdSeller, }) => {
|
|
82
|
-
const getPaymentRequestToPay = await BaseClient.getBaseClient().stripe.paymentRequestToPay.query({
|
|
86
|
+
static getPaymentRequest = async ({ paymentRequestId, secrecyIdSeller, opts, }) => {
|
|
87
|
+
const getPaymentRequestToPay = await BaseClient.getBaseClient(opts).stripe.paymentRequestToPay.query({
|
|
83
88
|
paymentRequestId,
|
|
84
89
|
sellerId: secrecyIdSeller,
|
|
85
90
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getUrl } from '../index.js';
|
|
2
1
|
import { popup } from '../utils/popup-tools.js';
|
|
3
2
|
export class SecrecyPayClient {
|
|
4
3
|
#client;
|
|
@@ -10,17 +9,15 @@ export class SecrecyPayClient {
|
|
|
10
9
|
// this.#apiClient = apiClient
|
|
11
10
|
}
|
|
12
11
|
async confirmPaymentIntent({ paymentIntentId, secrecyIdWhoCreatedPaymentIntent, secrecyIdWhoNeedToConfirmPaymentIntent, amount, currency, }) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
path: '/account/iframe/pay-confirm',
|
|
23
|
-
});
|
|
12
|
+
const hash = Buffer.from(JSON.stringify({
|
|
13
|
+
appSession: this.#client.sessionId,
|
|
14
|
+
paymentIntentId,
|
|
15
|
+
secrecyIdWhoCreatedPaymentIntent,
|
|
16
|
+
secrecyIdWhoNeedToConfirmPaymentIntent,
|
|
17
|
+
amount,
|
|
18
|
+
currency,
|
|
19
|
+
})).toString('base64');
|
|
20
|
+
const url = `${this.#client.baseUrl}/auth/account/iframe/pay-confirm#${hash}`;
|
|
24
21
|
return await new Promise((resolve, reject) => popup(url, 'Secrecy Pay - Confirm Payment Intent', {
|
|
25
22
|
width: 500,
|
|
26
23
|
}, (err, data) => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getUrl } from '../index.js';
|
|
2
1
|
import { popup } from '../utils/popup-tools.js';
|
|
3
2
|
export class SecrecyWalletClient {
|
|
4
3
|
#client;
|
|
@@ -10,14 +9,12 @@ export class SecrecyWalletClient {
|
|
|
10
9
|
// this.#thunder = thunder;
|
|
11
10
|
}
|
|
12
11
|
async createTransaction({ network = 'mainnet', tx, }) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
path: '/account/iframe/wallet-transaction',
|
|
20
|
-
});
|
|
12
|
+
const hash = Buffer.from(JSON.stringify({
|
|
13
|
+
appSession: this.#client.sessionId,
|
|
14
|
+
network,
|
|
15
|
+
tx,
|
|
16
|
+
})).toString('base64');
|
|
17
|
+
const url = `${this.#client.baseUrl}/auth/account/iframe/wallet-transaction#${hash}`;
|
|
21
18
|
return await new Promise((resolve, reject) => popup(url, 'Secrecy Wallet - Transaction', {
|
|
22
19
|
width: 500,
|
|
23
20
|
}, (err, data) => {
|
|
@@ -29,14 +26,12 @@ export class SecrecyWalletClient {
|
|
|
29
26
|
}));
|
|
30
27
|
}
|
|
31
28
|
async createSignature({ network = 'mainnet', message, }) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
path: '/account/iframe/wallet-signature',
|
|
39
|
-
});
|
|
29
|
+
const hash = Buffer.from(JSON.stringify({
|
|
30
|
+
appSession: this.#client.sessionId,
|
|
31
|
+
network,
|
|
32
|
+
message,
|
|
33
|
+
})).toString('base64');
|
|
34
|
+
const url = `${this.#client.baseUrl}/auth/account/iframe/wallet-signature#${hash}`;
|
|
40
35
|
return await new Promise((resolve, reject) => popup(url, 'Secrecy Wallet - Signature', {
|
|
41
36
|
width: 500,
|
|
42
37
|
}, (err, data) => {
|
|
@@ -17,20 +17,6 @@ export function parseInfos() {
|
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export const getUrl = ({ hash, path, }) => {
|
|
21
|
-
const lang = document.documentElement.lang;
|
|
22
|
-
path = path.startsWith('/') ? path : `/${path}`;
|
|
23
|
-
if (process.env.NEXT_PUBLIC_SECRECY_URL) {
|
|
24
|
-
return `${process.env.NEXT_PUBLIC_SECRECY_URL}/${lang}/auth${path}#${hash}`;
|
|
25
|
-
}
|
|
26
|
-
const protocol = process.env.NEXT_PUBLIC_VERCEL_ENV !== 'development' ? 'https' : 'http';
|
|
27
|
-
const url = process.env.NEXT_PUBLIC_VERCEL_ENV &&
|
|
28
|
-
process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production' &&
|
|
29
|
-
process.env.NEXT_PUBLIC_IS_SECRECY_INTERNAL === 'true'
|
|
30
|
-
? `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_URL}/${lang}/auth`
|
|
31
|
-
: `https://www.secrecy.tech/${lang}/auth`;
|
|
32
|
-
return `${url}${path}#${hash}`;
|
|
33
|
-
};
|
|
34
20
|
export function getSecrecyClient(session) {
|
|
35
21
|
const storage = getStorage(session);
|
|
36
22
|
const uaSession = storage.userAppSession.load();
|
|
@@ -48,7 +34,7 @@ export function getSecrecyClient(session) {
|
|
|
48
34
|
}
|
|
49
35
|
return new SecrecyClient(uaSession, uaKeys, uaJwt);
|
|
50
36
|
}
|
|
51
|
-
export async function login({ appId, path, redirect, scopes, backPath, session, }) {
|
|
37
|
+
export async function login({ appId, path, redirect, scopes, backPath, session, authUrl = 'https://www.secrecy.tech/auth/login', }) {
|
|
52
38
|
return await new Promise((resolve, reject) => {
|
|
53
39
|
const appUrl = window.location.origin;
|
|
54
40
|
const client = getSecrecyClient();
|
|
@@ -62,10 +48,7 @@ export async function login({ appId, path, redirect, scopes, backPath, session,
|
|
|
62
48
|
backPath,
|
|
63
49
|
};
|
|
64
50
|
const data = btoa(JSON.stringify(infos)).replaceAll('=', '');
|
|
65
|
-
const url =
|
|
66
|
-
hash: data,
|
|
67
|
-
path: 'login',
|
|
68
|
-
});
|
|
51
|
+
const url = `${authUrl}#${data}`;
|
|
69
52
|
const validate = (infos) => {
|
|
70
53
|
const storage = getStorage(session);
|
|
71
54
|
storage.userAppSession.save(infos.uaSession);
|
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,16 @@ 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.baseUrl
|
|
28
|
+
? `${opts.baseUrl}/api/trpc`
|
|
29
|
+
: 'https://www.secrecy.tech/api/trpc',
|
|
40
30
|
maxURLLength: 2083,
|
|
41
31
|
fetch: async (input, init) => {
|
|
42
32
|
const controller = new AbortController();
|
|
@@ -45,8 +35,8 @@ export const createTRPCClient = (session, onAccessDenied) => createTRPCProxyClie
|
|
|
45
35
|
}, 20000);
|
|
46
36
|
const headers = new Headers(init?.headers);
|
|
47
37
|
headers.set('secrecy-lib-version', SECRECY_LIB_VERSION);
|
|
48
|
-
if (typeof session === 'string') {
|
|
49
|
-
headers.set('secrecy-session', session);
|
|
38
|
+
if (typeof opts.session === 'string') {
|
|
39
|
+
headers.set('secrecy-session', opts.session);
|
|
50
40
|
}
|
|
51
41
|
const call = fetch(input, {
|
|
52
42
|
...init,
|
|
@@ -1,28 +1,36 @@
|
|
|
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
|
+
baseUrl?: 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;
|
|
13
|
+
baseUrl: string;
|
|
8
14
|
sessionId: string;
|
|
9
|
-
constructor(
|
|
15
|
+
constructor(opts: BaseClientOptions);
|
|
10
16
|
logout(sessionId?: string | null | undefined): Promise<void>;
|
|
11
17
|
me(): Promise<SelfUser>;
|
|
12
|
-
static getUser(userId: string,
|
|
18
|
+
static getUser(userId: string, opts?: CreateTrpcClientOptions): Promise<PublicUser>;
|
|
13
19
|
getUser(userId: string): Promise<PublicUser>;
|
|
14
20
|
searchUsers(search: string): Promise<PublicUser[]>;
|
|
15
21
|
updateProfile(data: RouterInputs['user']['updateProfile']): Promise<Omit<SelfUser, 'account'>>;
|
|
16
|
-
static isCryptoTransactionDone({ idOrHash, network, }: {
|
|
22
|
+
static isCryptoTransactionDone({ idOrHash, network, opts, }: {
|
|
17
23
|
idOrHash: string;
|
|
18
24
|
network?: InfuraNetwork;
|
|
25
|
+
opts?: CreateTrpcClientOptions;
|
|
19
26
|
}): Promise<boolean>;
|
|
20
27
|
reportUser(data: RouterInputs['report']['create']): Promise<RouterOutputs['report']['create']>;
|
|
21
28
|
getSponsorshipLink({ backUrl, }: {
|
|
22
29
|
backUrl: string;
|
|
23
30
|
}): Promise<string | null>;
|
|
24
|
-
static getPaymentRequest: ({ paymentRequestId, secrecyIdSeller, }: {
|
|
31
|
+
static getPaymentRequest: ({ paymentRequestId, secrecyIdSeller, opts, }: {
|
|
25
32
|
paymentRequestId: string;
|
|
26
33
|
secrecyIdSeller: string;
|
|
34
|
+
opts?: CreateTrpcClientOptions;
|
|
27
35
|
}) => Promise<RouterOutputs["stripe"]["paymentRequestToPay"]>;
|
|
28
36
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { SecrecyClient } from './index.js';
|
|
2
2
|
import { type SecrecyUserApp } from './types/index.js';
|
|
3
3
|
export declare function parseInfos(): SecrecyUserApp | null;
|
|
4
|
-
export declare const getUrl: ({ hash, path, }: {
|
|
5
|
-
hash: string;
|
|
6
|
-
path: string;
|
|
7
|
-
}) => string;
|
|
8
4
|
export interface HashInfos {
|
|
9
5
|
appId: string;
|
|
10
6
|
appUrl: string;
|
|
7
|
+
authUrl?: string;
|
|
11
8
|
backPath?: string;
|
|
12
9
|
path?: string | null | undefined;
|
|
13
10
|
redirect?: boolean;
|
|
@@ -22,5 +19,5 @@ export declare function getSecrecyClient(session?: boolean): SecrecyClient | nul
|
|
|
22
19
|
type LoginResponse<Params extends UseSecrecyParams> = Params extends {
|
|
23
20
|
redirect: true;
|
|
24
21
|
} ? SecrecyClient | null : SecrecyClient;
|
|
25
|
-
export declare function login<Params extends UseSecrecyParams>({ appId, path, redirect, scopes, backPath, session, }: Params): Promise<LoginResponse<Params>>;
|
|
22
|
+
export declare function login<Params extends UseSecrecyParams>({ appId, path, redirect, scopes, backPath, session, authUrl, }: Params): Promise<LoginResponse<Params>>;
|
|
26
23
|
export {};
|
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
|
+
baseUrl?: 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", {
|
package/package.json
CHANGED