@secrecy/lib 1.57.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 +8 -6
- 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.js +3 -1
- package/dist/types/base-client.d.ts +7 -4
- package/dist/types/client/helpers.d.ts +2 -5
- package/dist/types/client.d.ts +1 -1
- package/package.json +1 -1
package/dist/lib/base-client.js
CHANGED
|
@@ -17,9 +17,11 @@ async function getPublicUser(client, id) {
|
|
|
17
17
|
export class BaseClient {
|
|
18
18
|
static getBaseClient = (opts = {}) => createTRPCClient(opts);
|
|
19
19
|
client;
|
|
20
|
+
baseUrl;
|
|
20
21
|
sessionId;
|
|
21
22
|
constructor(opts) {
|
|
22
23
|
this.sessionId = opts.session;
|
|
24
|
+
this.baseUrl = opts.baseUrl ?? 'https://www.secrecy.tech';
|
|
23
25
|
this.client = BaseClient.getBaseClient({
|
|
24
26
|
...opts,
|
|
25
27
|
onAccessDenied: async () => {
|
|
@@ -46,8 +48,8 @@ export class BaseClient {
|
|
|
46
48
|
async me() {
|
|
47
49
|
return await this.client.user.self.query({});
|
|
48
50
|
}
|
|
49
|
-
static async getUser(userId,
|
|
50
|
-
const user = await getPublicUser(this.getBaseClient(
|
|
51
|
+
static async getUser(userId, opts) {
|
|
52
|
+
const user = await getPublicUser(this.getBaseClient(opts), userId);
|
|
51
53
|
return user;
|
|
52
54
|
}
|
|
53
55
|
async getUser(userId) {
|
|
@@ -64,8 +66,8 @@ export class BaseClient {
|
|
|
64
66
|
const updateProfile = await this.client.user.updateProfile.mutate(data);
|
|
65
67
|
return updateProfile;
|
|
66
68
|
}
|
|
67
|
-
static async isCryptoTransactionDone({ idOrHash, network = 'mainnet', }) {
|
|
68
|
-
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({
|
|
69
71
|
idOrHash,
|
|
70
72
|
network,
|
|
71
73
|
});
|
|
@@ -81,8 +83,8 @@ export class BaseClient {
|
|
|
81
83
|
path: `/sign-up?gf=${btoa(getPreferedEmail(me.account.emails)?.email)}&au=${btoa(backUrl)}`,
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
|
-
static getPaymentRequest = async ({ paymentRequestId, secrecyIdSeller, }) => {
|
|
85
|
-
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({
|
|
86
88
|
paymentRequestId,
|
|
87
89
|
sellerId: secrecyIdSeller,
|
|
88
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.js
CHANGED
|
@@ -24,7 +24,9 @@ export const createTRPCClient = (opts) => createTRPCProxyClient({
|
|
|
24
24
|
},
|
|
25
25
|
}),
|
|
26
26
|
httpBatchLink({
|
|
27
|
-
url: opts.
|
|
27
|
+
url: opts.baseUrl
|
|
28
|
+
? `${opts.baseUrl}/api/trpc`
|
|
29
|
+
: 'https://www.secrecy.tech/api/trpc',
|
|
28
30
|
maxURLLength: 2083,
|
|
29
31
|
fetch: async (input, init) => {
|
|
30
32
|
const controller = new AbortController();
|
|
@@ -3,31 +3,34 @@ import { type InfuraNetwork, type PublicUser } from './index.js';
|
|
|
3
3
|
import { type SelfUser } from './client/types/user.js';
|
|
4
4
|
export type BaseClientOptions = {
|
|
5
5
|
session: string;
|
|
6
|
-
|
|
6
|
+
baseUrl?: string | null | undefined;
|
|
7
7
|
onAccessDenied?: () => void | Promise<void>;
|
|
8
8
|
};
|
|
9
9
|
export declare class BaseClient {
|
|
10
10
|
#private;
|
|
11
11
|
static readonly getBaseClient: (opts?: CreateTrpcClientOptions) => ApiClient;
|
|
12
12
|
protected client: ApiClient;
|
|
13
|
+
baseUrl: string;
|
|
13
14
|
sessionId: string;
|
|
14
15
|
constructor(opts: BaseClientOptions);
|
|
15
16
|
logout(sessionId?: string | null | undefined): Promise<void>;
|
|
16
17
|
me(): Promise<SelfUser>;
|
|
17
|
-
static getUser(userId: string,
|
|
18
|
+
static getUser(userId: string, opts?: CreateTrpcClientOptions): Promise<PublicUser>;
|
|
18
19
|
getUser(userId: string): Promise<PublicUser>;
|
|
19
20
|
searchUsers(search: string): Promise<PublicUser[]>;
|
|
20
21
|
updateProfile(data: RouterInputs['user']['updateProfile']): Promise<Omit<SelfUser, 'account'>>;
|
|
21
|
-
static isCryptoTransactionDone({ idOrHash, network, }: {
|
|
22
|
+
static isCryptoTransactionDone({ idOrHash, network, opts, }: {
|
|
22
23
|
idOrHash: string;
|
|
23
24
|
network?: InfuraNetwork;
|
|
25
|
+
opts?: CreateTrpcClientOptions;
|
|
24
26
|
}): Promise<boolean>;
|
|
25
27
|
reportUser(data: RouterInputs['report']['create']): Promise<RouterOutputs['report']['create']>;
|
|
26
28
|
getSponsorshipLink({ backUrl, }: {
|
|
27
29
|
backUrl: string;
|
|
28
30
|
}): Promise<string | null>;
|
|
29
|
-
static getPaymentRequest: ({ paymentRequestId, secrecyIdSeller, }: {
|
|
31
|
+
static getPaymentRequest: ({ paymentRequestId, secrecyIdSeller, opts, }: {
|
|
30
32
|
paymentRequestId: string;
|
|
31
33
|
secrecyIdSeller: string;
|
|
34
|
+
opts?: CreateTrpcClientOptions;
|
|
32
35
|
}) => Promise<RouterOutputs["stripe"]["paymentRequestToPay"]>;
|
|
33
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
|
@@ -7,7 +7,7 @@ export type RouterOutputs = inferRouterOutputs<AppRouter>;
|
|
|
7
7
|
export declare function isTRPCClientError(cause: unknown): cause is TRPCClientError<AppRouter>;
|
|
8
8
|
export interface CreateTrpcClientOptions {
|
|
9
9
|
session?: string | null | undefined;
|
|
10
|
-
|
|
10
|
+
baseUrl?: string | null | undefined;
|
|
11
11
|
onAccessDenied?: () => void | Promise<void> | null | undefined;
|
|
12
12
|
}
|
|
13
13
|
export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => {
|
package/package.json
CHANGED