@procivis/one-react-native-components 0.3.47 → 0.3.50

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.
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CreateRemoteTrustEntityRequest,
3
+ IdentifierTypeEnum,
3
4
  ONECore,
4
5
  OneError,
5
6
  TrustAnchor,
@@ -58,20 +59,29 @@ export const useTrustEntity = (identifierId: string | undefined) => {
58
59
 
59
60
  return useQuery(
60
61
  [TRUST_ENTITY_DETAIL_QUERY_KEY, identifierId],
61
- () => identifierId && identifierDetail
62
- ? core.resolveTrustEntityByIdentifier({
63
- identifiers: [{
64
- certificateId: identifierDetail.type === 'CERTIFICATE' ? identifierDetail.certificates?.[0]?.id : undefined,
65
- id: identifierId,
66
- }],
67
- }).then((result) => {
68
- return result[identifierId];
69
- }).catch((e) => {
70
- if (e instanceof OneError && e.code === OneErrorCode.NoTrustEntityFound) {
71
- return null;
72
- }
73
- throw e;
74
- })
62
+ () =>
63
+ identifierId && identifierDetail
64
+ ? core
65
+ .resolveTrustEntityByIdentifier({
66
+ identifiers: [
67
+ {
68
+ certificateId:
69
+ identifierDetail?.type === IdentifierTypeEnum.CERTIFICATE
70
+ ? identifierDetail.certificates?.[0]?.id
71
+ : undefined,
72
+ id: identifierId,
73
+ },
74
+ ],
75
+ })
76
+ .then((result) => {
77
+ return result[identifierId]?.[0]?.trustEntity ?? null;
78
+ })
79
+ .catch((e) => {
80
+ if (e instanceof OneError && e.code === OneErrorCode.NoTrustEntityFound) {
81
+ return null;
82
+ }
83
+ throw e;
84
+ })
75
85
  : undefined,
76
86
  {
77
87
  enabled: Boolean(identifierDetail),
@@ -99,51 +109,57 @@ export const useCreateRemoteTrustEntity = () => {
99
109
  const queryClient = useQueryClient();
100
110
  const { core } = useONECore();
101
111
 
102
- return useMutation(async (request: Omit<CreateRemoteTrustEntityRequest, 'didId'> & { identifierId?: string, didId?: string }) => {
103
- const { identifierId, didId } = request
112
+ return useMutation(
113
+ async (request: Omit<CreateRemoteTrustEntityRequest, 'didId'> & { identifierId?: string; didId?: string }) => {
114
+ const { identifierId, didId } = request;
104
115
 
105
- let entityDidId = didId;
116
+ let entityDidId = didId;
106
117
 
107
- if (identifierId) {
108
- const identifierDetail = await core.getIdentifier(identifierId);
109
- entityDidId = identifierDetail?.did?.id;
110
- }
118
+ if (identifierId) {
119
+ const identifierDetail = await core.getIdentifier(identifierId);
120
+ entityDidId = identifierDetail?.did?.id;
121
+ }
111
122
 
112
- return core.createRemoteTrustEntity({
113
- ...request,
114
- didId: entityDidId!,
115
- })
116
- }, {
117
- onSuccess: async () => {
118
- await queryClient.invalidateQueries(REMOTE_TRUST_ENTITY_DETAIL_QUERY_KEY);
119
- await queryClient.invalidateQueries(HISTORY_LIST_QUERY_KEY);
123
+ return core.createRemoteTrustEntity({
124
+ ...request,
125
+ didId: entityDidId!,
126
+ });
120
127
  },
121
- });
128
+ {
129
+ onSuccess: async () => {
130
+ await queryClient.invalidateQueries(REMOTE_TRUST_ENTITY_DETAIL_QUERY_KEY);
131
+ await queryClient.invalidateQueries(HISTORY_LIST_QUERY_KEY);
132
+ },
133
+ },
134
+ );
122
135
  };
123
136
 
124
137
  export const useUpdateRemoteTrustEntity = () => {
125
138
  const queryClient = useQueryClient();
126
139
  const { core } = useONECore();
127
140
 
128
- return useMutation(async (request: Omit<UpdateRemoteTrustEntityRequest, 'didId'> & { identifierId?: string, didId?: string }) => {
129
- const { identifierId, didId } = request
130
-
131
- let entityDidId = didId;
132
- if (identifierId) {
133
- const identifierDetail = await core.getIdentifier(identifierId);
134
- entityDidId = identifierDetail?.did?.id;
135
- }
136
-
137
- return core.updateRemoteTrustEntity({
138
- ...request,
139
- didId: entityDidId!,
140
- })
141
- }, {
142
- onSuccess: async () => {
143
- await queryClient.invalidateQueries(REMOTE_TRUST_ENTITY_DETAIL_QUERY_KEY);
144
- await queryClient.invalidateQueries(HISTORY_LIST_QUERY_KEY);
141
+ return useMutation(
142
+ async (request: Omit<UpdateRemoteTrustEntityRequest, 'didId'> & { identifierId?: string; didId?: string }) => {
143
+ const { identifierId, didId } = request;
144
+
145
+ let entityDidId = didId;
146
+ if (identifierId) {
147
+ const identifierDetail = await core.getIdentifier(identifierId);
148
+ entityDidId = identifierDetail?.did?.id;
149
+ }
150
+
151
+ return core.updateRemoteTrustEntity({
152
+ ...request,
153
+ didId: entityDidId!,
154
+ });
145
155
  },
146
- });
156
+ {
157
+ onSuccess: async () => {
158
+ await queryClient.invalidateQueries(REMOTE_TRUST_ENTITY_DETAIL_QUERY_KEY);
159
+ await queryClient.invalidateQueries(HISTORY_LIST_QUERY_KEY);
160
+ },
161
+ },
162
+ );
147
163
  };
148
164
 
149
165
  export enum TrustManagementEnum {
@@ -91,7 +91,8 @@ export const cardHeaderFromCredential = (
91
91
  testID: string,
92
92
  labels: CardHeaderLabels,
93
93
  ): Omit<CredentialHeaderProps, 'style'> => {
94
- let credentialDetailPrimary = formatDateTimeLocalized(new Date(credential.issuanceDate)) ?? '';
94
+ let credentialDetailPrimary =
95
+ formatDateTimeLocalized(new Date(credential.issuanceDate ?? credential.createdDate)) ?? '';
95
96
 
96
97
  let credentialDetailSecondary: string | undefined;
97
98
  let credentialDetailErrorColor: boolean | undefined;
@@ -0,0 +1,149 @@
1
+ import {
2
+ CredentialListQuery,
3
+ CredentialSchemaListQuery,
4
+ DidListQuery,
5
+ HistoryListQuery,
6
+ IdentifierListQuery,
7
+ ProofListQuery,
8
+ ProofSchemaListQuery,
9
+ } from '@procivis/react-native-one-core';
10
+
11
+ type QueryKey<ListQuery, ParamList> = ParamList extends ReadonlyArray<keyof ListQuery> // all params are inside the ListQuery
12
+ ? keyof ListQuery extends ParamList[number] // all ListQuery fields are in the params
13
+ ? Array<ListQuery[keyof ListQuery]>
14
+ : void
15
+ : void; // otherwise produce a wrong return type which should trigger compilation error
16
+
17
+ /** Typecheck that all query params are included in the query key */
18
+ function getQueryKey<ListQuery extends {}, ParamList extends ReadonlyArray<keyof ListQuery>>(
19
+ queryParams: ListQuery,
20
+ params: ParamList,
21
+ ): QueryKey<ListQuery, ParamList> {
22
+ return params.map((param) => queryParams[param]) as QueryKey<ListQuery, ParamList>;
23
+ }
24
+
25
+ export const getQueryKeyFromCredentialListQueryParams = (queryParams: Partial<CredentialListQuery> = {}) => {
26
+ return getQueryKey(queryParams, [
27
+ 'page',
28
+ 'pageSize',
29
+ 'organisationId',
30
+ 'name',
31
+ 'searchText',
32
+ 'searchType',
33
+ 'sort',
34
+ 'sortDirection',
35
+ 'exact',
36
+ 'role',
37
+ 'ids',
38
+ 'status',
39
+ 'include',
40
+ 'profile',
41
+ ]);
42
+ };
43
+
44
+ export const getQueryKeyFromHistoryListQueryParams = (queryParams: Partial<HistoryListQuery> = {}) => {
45
+ return getQueryKey(queryParams, [
46
+ 'page',
47
+ 'pageSize',
48
+ 'organisationId',
49
+ 'entityId',
50
+ 'actions',
51
+ 'entityTypes',
52
+ 'createdDateFrom',
53
+ 'createdDateTo',
54
+ 'identifierId',
55
+ 'credentialId',
56
+ 'credentialSchemaId',
57
+ 'proofSchemaId',
58
+ 'searchText',
59
+ 'searchType',
60
+ ]);
61
+ };
62
+
63
+ export const getQueryKeyFromCredentialSchemaListQueryParams = (
64
+ queryParams: Partial<CredentialSchemaListQuery> = {},
65
+ ) => {
66
+ return getQueryKey(queryParams, [
67
+ 'page',
68
+ 'pageSize',
69
+ 'organisationId',
70
+ 'name',
71
+ 'sort',
72
+ 'sortDirection',
73
+ 'exact',
74
+ 'ids',
75
+ 'include',
76
+ 'schemaId',
77
+ 'formats',
78
+ ]);
79
+ };
80
+
81
+ export const getQueryKeyFromProofSchemaListQueryParams = (queryParams: Partial<ProofSchemaListQuery> = {}) => {
82
+ return getQueryKey(queryParams, [
83
+ 'page',
84
+ 'pageSize',
85
+ 'organisationId',
86
+ 'name',
87
+ 'sort',
88
+ 'sortDirection',
89
+ 'exact',
90
+ 'ids',
91
+ 'formats',
92
+ ]);
93
+ };
94
+
95
+ export const getQueryKeyFromProofListQueryParams = (queryParams: Partial<ProofListQuery> = {}) => {
96
+ return getQueryKey(queryParams, [
97
+ 'page',
98
+ 'pageSize',
99
+ 'organisationId',
100
+ 'sort',
101
+ 'sortDirection',
102
+ 'name',
103
+ 'ids',
104
+ 'proofStates',
105
+ 'proofRoles',
106
+ 'proofSchemaIds',
107
+ 'exact',
108
+ 'profile',
109
+ ]);
110
+ };
111
+
112
+ export const getQueryKeyFromDidListQueryParams = (queryParams: Partial<DidListQuery> = {}) => {
113
+ return getQueryKey(queryParams, [
114
+ 'page',
115
+ 'pageSize',
116
+ 'organisationId',
117
+ 'sort',
118
+ 'sortDirection',
119
+ 'name',
120
+ 'did',
121
+ 'type',
122
+ 'deactivated',
123
+ 'exact',
124
+ 'keyAlgorithms',
125
+ 'keyRoles',
126
+ 'keyStorages',
127
+ 'keyIds',
128
+ 'didMethods',
129
+ ]);
130
+ };
131
+
132
+ export const getQueryKeyFromIdentifierListQueryParams = (queryParams: Partial<IdentifierListQuery> = {}) => {
133
+ return getQueryKey(queryParams, [
134
+ 'page',
135
+ 'pageSize',
136
+ 'organisationId',
137
+ 'sort',
138
+ 'sortDirection',
139
+ 'name',
140
+ 'types',
141
+ 'state',
142
+ 'exact',
143
+ 'didMethods',
144
+ 'isRemote',
145
+ 'keyAlgorithms',
146
+ 'keyRoles',
147
+ 'keyStorages',
148
+ ]);
149
+ };
@@ -1,92 +0,0 @@
1
- import {
2
- CredentialListQuery,
3
- CredentialSchemaListQuery,
4
- DidListQuery,
5
- HistoryListQuery,
6
- IdentifierListQuery,
7
- ProofListQuery,
8
- ProofSchemaListQuery,
9
- } from '@procivis/react-native-one-core';
10
-
11
- export const getQueryKeyFromCredentialListQueryParams = (queryParams?: Partial<CredentialListQuery>) => {
12
- if (!queryParams) {
13
- return [];
14
- }
15
- const { name, sort, sortDirection, exact, role, ids, status, include } = queryParams;
16
- return [name, sort, sortDirection, exact, role, ids, status, include];
17
- };
18
-
19
- export const getQueryKeyFromHistoryListQueryParams = (queryParams?: Partial<HistoryListQuery>) => {
20
- if (!queryParams) {
21
- return [];
22
- }
23
-
24
- const {
25
- entityId,
26
- actions,
27
- entityTypes,
28
- createdDateFrom,
29
- createdDateTo,
30
- identifierId,
31
- credentialId,
32
- credentialSchemaId,
33
- searchText,
34
- searchType,
35
- proofSchemaId,
36
- } = queryParams;
37
- return [
38
- entityId,
39
- actions,
40
- entityTypes,
41
- createdDateFrom,
42
- createdDateTo,
43
- identifierId,
44
- credentialId,
45
- credentialSchemaId,
46
- searchText,
47
- searchType,
48
- proofSchemaId,
49
- ];
50
- };
51
-
52
- export const getQueryKeyFromCredentialSchemaListQueryParams = (queryParams?: Partial<CredentialSchemaListQuery>) => {
53
- if (!queryParams) {
54
- return [];
55
- }
56
- const { name, sort, sortDirection, exact, ids, include } = queryParams;
57
- return [name, sort, sortDirection, exact, ids, include];
58
- };
59
-
60
- export const getQueryKeyFromProofSchemaListQueryParams = (queryParams?: Partial<ProofSchemaListQuery>) => {
61
- if (!queryParams) {
62
- return [];
63
- }
64
- const { name, sort, sortDirection, exact, ids } = queryParams;
65
- return [name, sort, sortDirection, exact, ids];
66
- };
67
-
68
- export const getQueryKeyFromProofListQueryParams = (queryParams?: Partial<ProofListQuery>) => {
69
- if (!queryParams) {
70
- return [];
71
- }
72
- const { name, sort, sortDirection, exact, ids, proofStates, proofSchemaIds } = queryParams;
73
- return [name, sort, sortDirection, exact, ids, proofStates, proofSchemaIds];
74
- };
75
-
76
- export const getQueryKeyFromDidListQueryParams = (queryParams?: Partial<DidListQuery>) => {
77
- if (!queryParams) {
78
- return [];
79
- }
80
-
81
- const { name, did, type, deactivated, keyAlgorithms, keyRoles } = queryParams;
82
- return [name, did, type, deactivated, keyAlgorithms, keyRoles];
83
- };
84
-
85
- export const getQueryKeyFromIdentifierListQueryParams = (queryParams?: Partial<IdentifierListQuery>) => {
86
- if (!queryParams) {
87
- return [];
88
- }
89
-
90
- const { isRemote, didMethods, state, keyStorages, keyAlgorithms, exact, keyRoles, types, name } = queryParams;
91
- return [name, types, state, isRemote, didMethods, keyStorages, keyAlgorithms, exact, keyRoles];
92
- };