@secrecy/lib 1.9.0-integration-database-api.1 → 1.9.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.
@@ -17,11 +17,16 @@ export class BaseClient {
17
17
  static getBaseClient = (session, onAccessDenied) => createTRPCClient(session, onAccessDenied);
18
18
  client;
19
19
  sessionId;
20
- constructor(session) {
20
+ constructor(session, onAccessDenied) {
21
21
  this.sessionId = session;
22
- this.client = BaseClient.getBaseClient(session, () => {
23
- this.#clean();
24
- location.reload();
22
+ this.client = BaseClient.getBaseClient(session, async () => {
23
+ await onAccessDenied?.();
24
+ try {
25
+ await this.logout();
26
+ }
27
+ finally {
28
+ location.reload();
29
+ }
25
30
  });
26
31
  }
27
32
  async logout(sessionId) {
@@ -10,10 +10,8 @@ export async function apiNodeToInternal(apiNode, keyPair) {
10
10
  access: apiNode.access,
11
11
  name: apiNode.name,
12
12
  isFavorite: apiNode.isFavorite,
13
+ breadcrumb: 'breadcrumb' in apiNode ? apiNode.breadcrumb : [],
13
14
  // TODO
14
- // breadcrumb: apiNode.breadcrumb,
15
- // createdBy: apiNode.createdBy.user,
16
- breadcrumb: [],
17
15
  createdBy: {
18
16
  firstname: apiNode.createdBy.userId,
19
17
  lastname: apiNode.createdBy.userId,
@@ -93,8 +91,10 @@ export function internalNodeFullToNodeFull(internal) {
93
91
  };
94
92
  }
95
93
  export async function apiNodeToExternalNodeFull(apiNodeFull, keyPair) {
96
- return internalNodeFullToNodeFull(await apiNodeFullToInternalFull(apiNodeFull, keyPair));
94
+ const apiNode = await apiNodeFullToInternalFull(apiNodeFull, keyPair);
95
+ return internalNodeFullToNodeFull(apiNode);
97
96
  }
98
97
  export async function apiNodeToExternal(apiNode, keyPair) {
99
- return internalNodeToNode(await apiNodeToInternal(apiNode, keyPair));
98
+ const internal = await apiNodeToInternal(apiNode, keyPair);
99
+ return internalNodeToNode(internal);
100
100
  }
@@ -26,7 +26,14 @@ export class SecrecyClient extends BaseClient {
26
26
  pay;
27
27
  user;
28
28
  constructor(uaSession, uaKeys, uaJwt) {
29
- super(uaSession);
29
+ super(uaSession, async () => {
30
+ try {
31
+ await this.logout();
32
+ }
33
+ catch {
34
+ // ignore
35
+ }
36
+ });
30
37
  this.#keys = uaKeys;
31
38
  this.care = new SecrecyCareClient(this, this.#keys, this.client);
32
39
  this.cloud = new SecrecyCloudClient(this, this.#keys, this.client);
@@ -11,7 +11,7 @@ export const createTRPCClient = (session, onAccessDenied) => createTRPCProxyClie
11
11
  if (op.direction === 'down' &&
12
12
  isTRPCClientError(op.result) &&
13
13
  op.result.data?.code === 'UNAUTHORIZED') {
14
- onAccessDenied?.();
14
+ void onAccessDenied?.();
15
15
  }
16
16
  return (process.env.NODE_ENV === 'development' ||
17
17
  (op.direction === 'down' && op.result instanceof Error));
@@ -3,10 +3,10 @@ import { type InfuraNetwork, type PublicUser } from './index.js';
3
3
  import { type SelfUser } from './client/types/user.js';
4
4
  export declare class BaseClient {
5
5
  #private;
6
- static readonly getBaseClient: (session?: string | null | undefined, onAccessDenied?: () => void) => ApiClient;
6
+ static readonly getBaseClient: (session?: string | null | undefined, onAccessDenied?: () => void | Promise<void>) => ApiClient;
7
7
  protected client: ApiClient;
8
8
  sessionId: string;
9
- constructor(session: string);
9
+ constructor(session: string, onAccessDenied?: () => void | Promise<void>);
10
10
  logout(sessionId?: string | null | undefined): Promise<void>;
11
11
  me(): Promise<SelfUser>;
12
12
  static getUser(userId: string, sessionId?: string | null | undefined): Promise<PublicUser>;