Skip to content

Commit

Permalink
Update request-metadata-credentials interaction for "Credentials" page (
Browse files Browse the repository at this point in the history
#36)

* update metadata interaction
  • Loading branch information
lukachi authored Feb 1, 2024
1 parent 915d626 commit 6e9c635
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 191 deletions.
93 changes: 21 additions & 72 deletions src/api/modules/orgs/helpers/org-groups-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { W3CCredential } from '@rarimo/rarime-connector'
import { api } from '@/api/clients'
import {
CredentialRequest,
GroupedCredentials,
OrgClaimIDMap,
OrgGroupCreatedRequest,
OrgGroupRequest,
OrgGroupRequestClaim,
OrgGroupRequestFilters,
OrgGroupRequestMetadata,
OrgGroupRequestPublishing,
OrgGroupRequestQueryParams,
OrgGroupRequestWithClaims,
OrgGroupVCMap,
OrgUserRoles,
} from '@/api/modules/orgs'
Expand Down Expand Up @@ -112,6 +110,14 @@ export const loadOrgGroupRequests = async (query?: OrgGroupRequestQueryParams) =
return fakeLoadRequestsAll(query)
}

export const loadRequestsByUserDid = async (did: string): Promise<OrgGroupRequestWithClaims[]> => {
const { data } = await api.get<OrgGroupRequestWithClaims[]>(
`${ApiServicePaths.Orgs}/v1/users/${did}/requests`,
)

return data
}

export const loadOrgGroupRequestById = async (orgId: string, groupId: string, reqId: string) => {
const { data } = await api.get<OrgGroupRequest>(
`${ApiServicePaths.Orgs}/v1/orgs/${orgId}/groups/${groupId}/requests/${reqId}`,
Expand Down Expand Up @@ -229,25 +235,6 @@ export const getOrgGroupPublishingRequests = async ({
return data
}

export const loadOrgGroupReqMetadataById = async (
metadataId: string,
): Promise<OrgGroupRequestMetadata> => {
const { data } = await api.get<OrgGroupRequestMetadata>(
`${ApiServicePaths.Orgs}/v1/orgs/metadata/${metadataId}`,
)

return data

// TODO: remove once backend is ready
// return {
// title: 'title',
// subtitle: 'subtitle',
// appearance: {
// background: '#ffffff',
// },
// }
}

export const buildCredentialRequest = async (
schemeUrl: string,
propertyValue: string,
Expand All @@ -271,57 +258,19 @@ export const buildCredentialRequest = async (
}
}

export const getOrgGroupRequestClaims = async ({
orgId,
groupId,
reqId,
}: {
orgId: string
groupId: string
reqId: string
}): Promise<OrgGroupRequestClaim[]> => {
const { data } = await api.get<OrgGroupRequestClaim[]>(
`${ApiServicePaths.Orgs}/v1/orgs/${orgId}/groups/${groupId}/requests/${reqId}/publishing`,
)

return data
}

export const getMetadataBatch = async (vcs: W3CCredential[]): Promise<GroupedCredentials> => {
const orgsToClaimIdsMap = vcs.reduce((acc, vc) => {
const issuerDID = vc.issuer

if (!acc[issuerDID]) acc[issuerDID] = []

acc[issuerDID].push(getClaimIdFromVC(vc))

return acc
}, {} as OrgClaimIDMap)

const { data } = await api.get<GroupedCredentials>(`${ApiServicePaths.Orgs}/v1/orgs/metadata`, {
query: {
orgsToClaimIdsMap,
},
})

return data

// return DUMMY_ORG_GROUP_METADATAS // FIXME: remove
}

export const groupVCsToOrgGroups = (
groupedVCs: GroupedCredentials,
orgGroupRequests: OrgGroupRequestWithClaims[],
vcs: W3CCredential[],
): OrgGroupVCMap => {
return groupedVCs.grouped_credentials.map(org => ({
orgDID: org.org_did,
groups: org.groups.map(group => ({
groupID: group.group_id,
requests: group.requests.map(req => ({
reqID: req.req_id,
vcs: vcs.filter(vc => req.claim_ids.includes(getClaimIdFromVC(vc))),
metadata: req.metadata,
})),
})),
}))
return orgGroupRequests.map(orgGroupRequest => {
if (!orgGroupRequest.organization?.did) throw new TypeError('Organization DID is missing')

const orgRequestClaimIDs = orgGroupRequest.claims.map(claim => claim.id)

return {
orgDID: orgGroupRequest.organization.did,
groupID: orgGroupRequest.group_id,
vcs: vcs.filter(vc => orgRequestClaimIDs.includes(getClaimIdFromVC(vc))),
}
})
}
73 changes: 56 additions & 17 deletions src/api/modules/orgs/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { W3CCredential } from '@rarimo/rarime-connector'

import {
GroupedCredentials,
OrgGroupCreatedRequest,
OrgGroupRequest,
OrgGroupRequestMetadata,
Expand Down Expand Up @@ -39,6 +38,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
},
created_at: '2021-08-12T14:00:00Z',
updated_at: '2021-08-12T13:00:00Z',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
organization: {
id: '3a798290-caf1-496a-a7e5-4db32551b13d',
type: 'organizations',
Expand All @@ -65,6 +71,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -114,6 +127,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -163,6 +183,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -212,6 +239,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -261,6 +295,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -310,6 +351,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -359,6 +407,13 @@ export const DUMMY_ORG_GROUP_REQUESTS: OrgGroupRequest[] = [
type: 'requests',
org_id: '3a798290-caf1-496a-a7e5-4db32551b13d',
group_id: '6c8c1a69-177e-4754-a4e1-d4a7dbf561e8',
metadata: {
title: 'Civic',
subtitle: 'Civic',
appearance: {
background: '#000000',
},
},
user_did: 'did:iden3:readonly:tKRuUKu3feUEktA38mxN2jdEkbgSAHjq8fVqAGmkw',
credential_requests: [
{
Expand Down Expand Up @@ -635,19 +690,3 @@ const createFakeVCs = (org: FakeOrgSystem): W3CCredential[] => {
export const DUMMY_VCS: W3CCredential[] = [
...FAKE_ORG_DETAILS.reduce((acc, org) => [...acc, ...createFakeVCs(org)], [] as W3CCredential[]),
]

export const DUMMY_ORG_GROUP_METADATAS: GroupedCredentials = {
id: 'b0dc3814-e754-4596-a117-c4a07dfc65ef',
type: 'grouped_credentials',
grouped_credentials: FAKE_ORG_DETAILS.map(org => ({
org_did: org.did,
groups: org.groups.map(group => ({
group_id: group.id,
requests: group.requests.map(req => ({
req_id: req.id,
claim_ids: req.claim_ids,
metadata: req.metadata,
})),
})),
})),
}
8 changes: 0 additions & 8 deletions src/api/modules/orgs/types/org-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ export type OrgGroupMetadata = {
description: string
}

export type OrgGroupRequestMetadata = {
title: string
subtitle: string
appearance: {
background: string
}
}

export type OrgGroupRule = {
name: string
scheme: string
Expand Down
58 changes: 18 additions & 40 deletions src/api/modules/orgs/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
OrgGroup,
OrgGroupRequestFilters,
OrgGroupRequestIncludes,
OrgGroupRequestMetadata,
OrgGroupRequestPublishingStatuses,
OrgGroupRequestStatuses,
} from '@/api/modules/orgs'
Expand All @@ -20,6 +19,14 @@ export type CredentialRequest = {
signature_proof: boolean
}

export type OrgGroupRequestMetadata = {
title: string
subtitle: string
appearance: {
background: string
}
}

export type OrgGroupRequest = {
id: string
type: 'requests'
Expand All @@ -33,10 +40,18 @@ export type OrgGroupRequest = {
}
created_at: string
updated_at: string
metadata: OrgGroupRequestMetadata
organization?: Organization
group?: OrgGroup
}

export type OrgGroupRequestWithClaims = OrgGroupRequest & {
claims: {
id: string
type: 'claims'
}[]
}

export type OrgGroupCreatedRequest = {
id: string
type: 'invitations-email'
Expand Down Expand Up @@ -70,45 +85,8 @@ export type OrgGroupRequestPublishing = {
status: OrgGroupRequestPublishingStatuses
}

export type OrgGroupRequestClaim = {
id: string
type: 'claims'
claim_id: string
request_id: string
schema_url: string
status: string
created_at: string
updated_at: string
organization?: Organization
}

export type OrgClaimIDMap = Record<string, string[]>

export type GroupedCredentials = {
id: string
type: 'grouped_credentials'

grouped_credentials: {
org_did: string
groups: {
group_id: string
requests: {
req_id: string
claim_ids: string[]
metadata: OrgGroupRequestMetadata
}[]
}[]
}[]
}

export type OrgGroupVCMap = {
orgDID: string
groups: {
groupID: string
requests: {
reqID: string
vcs: W3CCredential[]
metadata: OrgGroupRequestMetadata
}[]
}[]
groupID: string
vcs: W3CCredential[]
}[]
Loading

0 comments on commit 6e9c635

Please sign in to comment.