From 24dce18e8c0085d8c0f22fbc625ec98330473964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nmez=20Kartal?= Date: Thu, 8 Feb 2024 18:03:53 +0300 Subject: [PATCH] fix(urns): pass `NID` and `NSS` to base class type parameters (#2822) --- packages/urns/index.ts | 6 +++--- platform/core/src/index.ts | 6 ++++-- .../src/jsonrpc/methods/patchProfileFields.ts | 11 +++++++++++ .../src/jsonrpc/methods/resetProfileFields.ts | 6 ++++++ .../src/jsonrpc/methods/deleteSubscriptionPlans.ts | 10 ++++++++-- .../src/jsonrpc/methods/getAppContactAddress.ts | 6 ++++++ .../starbase/src/jsonrpc/methods/listGroupApps.ts | 7 +++++-- .../src/jsonrpc/methods/reconcileAppSubscriptions.ts | 1 + 8 files changed, 44 insertions(+), 9 deletions(-) diff --git a/packages/urns/index.ts b/packages/urns/index.ts index d742ba904b..155432f072 100644 --- a/packages/urns/index.ts +++ b/packages/urns/index.ts @@ -72,7 +72,7 @@ class TypedComponentsURNSpace< RCompType extends CompType = CompType, QCompType extends CompType = CompType, URNType extends BaseURN = BaseURN -> extends URNSpace { +> extends URNSpace { constructor(nid: NID, options?: Partial>) { super(nid, options) } @@ -100,7 +100,7 @@ class TypedComponentsURNSpace< } componentizedParse( - urn: `urn:${string}:${string}${string}` + urn: `urn:${NID}:${NSS}${string}` ): ParsedComponentizedURN { const s = super.parse(urn) let rcomps = null @@ -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 } diff --git a/platform/core/src/index.ts b/platform/core/src/index.ts index b3a00045bc..62d78048a9 100644 --- a/platform/core/src/index.ts +++ b/platform/core/src/index.ts @@ -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' @@ -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 + ), }, }, })) diff --git a/platform/identity/src/jsonrpc/methods/patchProfileFields.ts b/platform/identity/src/jsonrpc/methods/patchProfileFields.ts index c024f674d6..b320bb6413 100644 --- a/platform/identity/src/jsonrpc/methods/patchProfileFields.ts +++ b/platform/identity/src/jsonrpc/methods/patchProfileFields.ts @@ -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', @@ -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) !== diff --git a/platform/identity/src/jsonrpc/methods/resetProfileFields.ts b/platform/identity/src/jsonrpc/methods/resetProfileFields.ts index 5f00bf0b80..c215e8b1f0 100644 --- a/platform/identity/src/jsonrpc/methods/resetProfileFields.ts +++ b/platform/identity/src/jsonrpc/methods/resetProfileFields.ts @@ -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', diff --git a/platform/starbase/src/jsonrpc/methods/deleteSubscriptionPlans.ts b/platform/starbase/src/jsonrpc/methods/deleteSubscriptionPlans.ts index 32702cb5b7..7d919c0657 100644 --- a/platform/starbase/src/jsonrpc/methods/deleteSubscriptionPlans.ts +++ b/platform/starbase/src/jsonrpc/methods/deleteSubscriptionPlans.ts @@ -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' @@ -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([ diff --git a/platform/starbase/src/jsonrpc/methods/getAppContactAddress.ts b/platform/starbase/src/jsonrpc/methods/getAppContactAddress.ts index aff327ce2d..d7a754dda2 100644 --- a/platform/starbase/src/jsonrpc/methods/getAppContactAddress.ts +++ b/platform/starbase/src/jsonrpc/methods/getAppContactAddress.ts @@ -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 { @@ -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, diff --git a/platform/starbase/src/jsonrpc/methods/listGroupApps.ts b/platform/starbase/src/jsonrpc/methods/listGroupApps.ts index 4aed707f73..e079d3795a 100644 --- a/platform/starbase/src/jsonrpc/methods/listGroupApps.ts +++ b/platform/starbase/src/jsonrpc/methods/listGroupApps.ts @@ -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, @@ -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, })) diff --git a/platform/starbase/src/jsonrpc/methods/reconcileAppSubscriptions.ts b/platform/starbase/src/jsonrpc/methods/reconcileAppSubscriptions.ts index 717e19e09e..68a341504d 100644 --- a/platform/starbase/src/jsonrpc/methods/reconcileAppSubscriptions.ts +++ b/platform/starbase/src/jsonrpc/methods/reconcileAppSubscriptions.ts @@ -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,