Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(urns): pass NID and NSS to base class type parameters #2822

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/urns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TypedComponentsURNSpace<
RCompType extends CompType = CompType,
QCompType extends CompType = CompType,
URNType extends BaseURN<NID, NSS> = BaseURN<NID, NSS>
> extends URNSpace<string, string, string> {
> extends URNSpace<NID, NSS, string> {
constructor(nid: NID, options?: Partial<SpaceOptions<NSS, string>>) {
super(nid, options)
}
Expand Down Expand Up @@ -100,7 +100,7 @@ class TypedComponentsURNSpace<
}

componentizedParse(
urn: `urn:${string}:${string}${string}`
urn: `urn:${NID}:${NSS}${string}`
): ParsedComponentizedURN<string, string, RCompType, QCompType> {
const s = super.parse(urn)
let rcomps = null
Expand Down Expand Up @@ -128,7 +128,7 @@ class TypedComponentsURNSpace<
return result
}

getBaseURN(urn: `urn:${string}:${string}${string}`): URNType {
getBaseURN(urn: `urn:${NID}:${NSS}${string}`): URNType {
const s = super.parse(urn)
return `urn:${s.nid}:${s.nss}` as URNType
}
Expand Down
6 changes: 4 additions & 2 deletions platform/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { initAuthorizationNodeByName } from '@proofzero/platform.authorization/s
import { getApplicationNodeByClientId } from '@proofzero/platform.starbase/src/nodes/application'
import { ExternalAppDataPackageStatus } from '@proofzero/platform.starbase/src/jsonrpc/validators/externalAppDataPackageDefinition'
import { EDGE_AUTHORIZES } from '@proofzero/platform.authorization/src/constants'
import { IdentityURNSpace } from '@proofzero/urns/identity'
import { IdentityURNSpace, type IdentityURN } from '@proofzero/urns/identity'

export { Account } from '@proofzero/platform.account'
export { Identity, IdentityGroup } from '@proofzero/platform.identity'
Expand Down Expand Up @@ -111,7 +111,9 @@ export default {
type: CoreQueueMessageType.ExternalAppDataDelReq,
data: {
appID: clientID,
athID: IdentityURNSpace.decode(edge.src.baseUrn),
athID: IdentityURNSpace.decode(
edge.src.baseUrn as IdentityURN
),
},
},
}))
Expand Down
11 changes: 11 additions & 0 deletions platform/identity/src/jsonrpc/methods/patchProfileFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export const patchProfileFieldsMethod = async ({
})
}

if (!IdentityURNSpace.is(identityGraphNode.baseUrn)) {
throw new InternalServerError({
message: 'Identity graph node URN is invalid',
})
}

if (!profile.primaryAccountURN) {
throw new InternalServerError({
message: 'Primary account URN not found',
Expand All @@ -53,6 +59,11 @@ export const patchProfileFieldsMethod = async ({
message: 'Identity graph node primary account URN not found',
})
}
if (!AccountURNSpace.is(identityGraphNode.qc.primaryAccountURN)) {
throw new InternalServerError({
message: 'Identity graph node primary account URN is invalid',
})
}

if (
AccountURNSpace.getBaseURN(profile.primaryAccountURN) !==
Expand Down
6 changes: 6 additions & 0 deletions platform/identity/src/jsonrpc/methods/resetProfileFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const resetProfileFieldsMethod = async ({
})
}

if (!IdentityURNSpace.is(identityGraphNode.baseUrn)) {
throw new InternalServerError({
message: 'Identity graph node URN is invalid',
})
}

if (!profile.primaryAccountURN) {
throw new InternalServerError({
message: 'Primary account URN not found',
Expand Down
10 changes: 8 additions & 2 deletions platform/starbase/src/jsonrpc/methods/deleteSubscriptionPlans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { z } from 'zod'
import { router } from '@proofzero/platform.core'
import { Context } from '../context'
import { getApplicationNodeByClientId } from '../../nodes/application'
import { ApplicationURNSpace } from '@proofzero/urns/application'
import {
type ApplicationURN,
ApplicationURNSpace,
} from '@proofzero/urns/application'
import { EDGE_PAYS_APP } from '@proofzero/types/graph'
import { IdentityRefURNValidator } from '@proofzero/platform-middleware/inputValidators'

Expand Down Expand Up @@ -32,7 +35,10 @@ export const deleteSubscriptionPlans = async ({
})

const appURNs = edges.map((edge) => edge.dst.baseUrn)
const clientIds = appURNs.map((appURN) => ApplicationURNSpace.decode(appURN))

const clientIds = appURNs.map((appURN) =>
ApplicationURNSpace.decode(appURN as ApplicationURN)
)

if (appURNs.length !== 0) {
await Promise.all([
Expand Down
6 changes: 6 additions & 0 deletions platform/starbase/src/jsonrpc/methods/getAppContactAddress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from 'zod'

import { router } from '@proofzero/platform.core'
import { InternalServerError } from '@proofzero/errors'
import { ApplicationURNSpace } from '@proofzero/urns/application'
import { AccountURNInput } from '@proofzero/platform-middleware/inputValidators'
import {
Expand Down Expand Up @@ -48,6 +49,11 @@ export const getAppContactAddress = async ({
return undefined
}

if (!AccountURNSpace.is(edges[0].dst.baseUrn))
throw new InternalServerError({
message: 'invalid account URN',
})

const accountURN = AccountURNSpace.componentizedUrn(
AccountURNSpace.parse(edges[0].dst.baseUrn).decoded,
edges[0].dst.rc as AccountRComp,
Expand Down
7 changes: 5 additions & 2 deletions platform/starbase/src/jsonrpc/methods/listGroupApps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { z } from 'zod'
import { Context } from '../context'
import { getApplicationNodeByClientId } from '../../nodes/application'
import { ApplicationURNSpace } from '@proofzero/urns/application'
import {
type ApplicationURN,
ApplicationURNSpace,
} from '@proofzero/urns/application'
import {
AppReadableFieldsSchema,
AppUpdateableFieldsSchema,
Expand Down Expand Up @@ -56,7 +59,7 @@ export const listGroupApps = async ({
})

return appEdges.map((edge) => ({
urn: edge.dst.baseUrn,
urn: edge.dst.baseUrn as ApplicationURN,
groupName: igm.name,
groupURN: igm.urn as IdentityGroupURN,
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const reconcileAppSubscriptions = async ({
const reconciledApps = []
const apps = []
for (const edge of edges) {
if (!ApplicationURNSpace.is(edge.dst.baseUrn)) continue
const clientID = ApplicationURNSpace.decode(edge.dst.baseUrn)
const appDO = await getApplicationNodeByClientId(
clientID,
Expand Down
Loading