mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Added new linkProfileNode action to validate ceramic node on the backend
This commit is contained in:
committed by
Alec LaLonde
parent
28b1e36f62
commit
ff9959359b
@@ -19,6 +19,13 @@ type Mutation {
|
||||
}
|
||||
|
||||
|
||||
type Mutation {
|
||||
linkCeramicProfileNode (
|
||||
nodeId: String!
|
||||
): LinkCeramicProfileNodeResponse
|
||||
}
|
||||
|
||||
|
||||
type Mutation {
|
||||
saveGuildInformation (
|
||||
guildInformation: GuildInfoInput!
|
||||
@@ -205,3 +212,7 @@ type DiscordGuildsSyncOutput {
|
||||
numSkipped : Int
|
||||
}
|
||||
|
||||
type LinkCeramicProfileNodeResponse {
|
||||
verified : Boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@ actions:
|
||||
forward_client_headers: true
|
||||
permissions:
|
||||
- role: player
|
||||
- name: linkCeramicProfileNode
|
||||
definition:
|
||||
kind: synchronous
|
||||
handler: '{{ACTION_BASE_ENDPOINT}}/ceramic/linkProfileNode'
|
||||
forward_client_headers: true
|
||||
permissions:
|
||||
- role: player
|
||||
- name: saveGuildInformation
|
||||
definition:
|
||||
kind: synchronous
|
||||
@@ -143,4 +150,5 @@ custom_types:
|
||||
- name: SaveGuildLayoutResponse
|
||||
- name: SourceCredSyncOutput
|
||||
- name: DiscordGuildsSyncOutput
|
||||
- name: LinkCeramicProfileNodeResponse
|
||||
scalars: []
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
"release": "standard-version",
|
||||
"composedb:create-composite": "composedb composite:create packages/utils/schema/user-profile.graphql -o packages/utils/schema/user-profile-composite.json",
|
||||
"composedb:create-definition": "composedb composite:compile packages/utils/schema/user-profile-composite.json packages/utils/schema/user-profile-definition.json",
|
||||
"composedb:graphql-generate": "composedb composite:compile packages/utils/schema/user-profile-composite.json packages/utils/src/graphql/autogen/composeDBDefinition.ts",
|
||||
"composedb:graphql-server": "composedb graphql:server --graphiql packages/utils/schema/user-profile-definition.json"
|
||||
},
|
||||
"workspaces": [
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"@ceramicnetwork/common": "^2.18.0",
|
||||
"@ceramicnetwork/http-client": "^2.15.0",
|
||||
"@ceramicnetwork/stream-caip10-link": "^2.13.0",
|
||||
"@composedb/client": "^0.3.1",
|
||||
"@datamodels/identity-accounts-web": "^0.2.0",
|
||||
"@datamodels/identity-profile-basic": "^0.2.0",
|
||||
"@glazed/datamodel": "^0.3.1",
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { ComposeClient } from '@composedb/client';
|
||||
import { composeDBDefinition } from '@metafam/utils';
|
||||
import { CONFIG } from 'config';
|
||||
import { Request, Response } from 'express';
|
||||
import {
|
||||
LinkCeramicProfileNodeResponse,
|
||||
Mutation_RootLinkCeramicProfileNodeArgs,
|
||||
} from 'lib/autogen/hasura-sdk';
|
||||
import { client } from 'lib/hasuraClient';
|
||||
|
||||
export default async (req: Request, res: Response): Promise<void> => {
|
||||
const { input, session_variables: sessionVariables } = req.body;
|
||||
|
||||
const role = sessionVariables['x-hasura-role'];
|
||||
const playerId = sessionVariables['x-hasura-user-id'];
|
||||
|
||||
const { player_by_pk: player } = await client.GetPlayer({ playerId });
|
||||
const { ethereumAddress } = player ?? {};
|
||||
|
||||
try {
|
||||
if (role !== 'player') {
|
||||
throw new Error('Expected player role');
|
||||
}
|
||||
if (!ethereumAddress) {
|
||||
throw new Error(`Unknown Player: "${playerId}"`);
|
||||
}
|
||||
|
||||
const { nodeId } = input as Mutation_RootLinkCeramicProfileNodeArgs;
|
||||
|
||||
const composeDBClient = new ComposeClient({
|
||||
ceramic: CONFIG.ceramicURL,
|
||||
definition: composeDBDefinition,
|
||||
});
|
||||
const modelInstanceDoc = await composeDBClient.context.loadDoc(nodeId);
|
||||
console.log(
|
||||
'controller for ',
|
||||
nodeId,
|
||||
' is ',
|
||||
modelInstanceDoc.metadata.controller,
|
||||
);
|
||||
|
||||
// todo:
|
||||
// 1. hook up frontend to call this action
|
||||
// 2. determine the 'controller' from the console logs
|
||||
// 3. if the controller matches ETH address, update the player record accordingly
|
||||
|
||||
const responseJSON = {
|
||||
verified: false,
|
||||
} as LinkCeramicProfileNodeResponse;
|
||||
res.json(responseJSON);
|
||||
} catch (error) {
|
||||
res.json({
|
||||
success: false,
|
||||
error: (error as Error).message,
|
||||
});
|
||||
}
|
||||
};
|
||||
8
packages/backend/src/handlers/actions/ceramic/routes.ts
Normal file
8
packages/backend/src/handlers/actions/ceramic/routes.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import express from 'express';
|
||||
|
||||
import { asyncHandlerWrapper } from '../../../lib/apiHelpers.js';
|
||||
import linkProfileNode from './linkProfileNode.js';
|
||||
|
||||
export const cacheRoutes = express.Router();
|
||||
|
||||
cacheRoutes.post('/linkProfileNode', asyncHandlerWrapper(linkProfileNode));
|
||||
@@ -11,6 +11,7 @@ export * as did from './did/index.js';
|
||||
export * as DiscordUtil from './discordHelpers.js';
|
||||
export * as ethereumHelper from './ethereumHelper.js';
|
||||
export * from './extendedProfileTypes.js';
|
||||
export { definition as composeDBDefinition } from './graphql/autogen/composeDBDefinition';
|
||||
export * from './imageHelpers.js';
|
||||
export * from './linkHelpers.js';
|
||||
export * from './networkHelpers.js';
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { ComposeClient } from '@composedb/client';
|
||||
import { EthereumWebAuth, getAccountId } from '@didtools/pkh-ethereum';
|
||||
import { Web3Provider } from '@ethersproject/providers';
|
||||
import { Maybe } from '@metafam/utils';
|
||||
import { composeDBDefinition, Maybe } from '@metafam/utils';
|
||||
import { CONFIG } from 'config';
|
||||
import { DIDSession } from 'did-session';
|
||||
import { definition } from 'graphql/composeDB/autogen/definition';
|
||||
import { cacheDIDSession, getCachedDIDSession } from 'lib/auth';
|
||||
import { useWeb3 } from 'lib/hooks';
|
||||
import {
|
||||
@@ -34,7 +33,7 @@ export const ComposeDBContext = createContext<ComposeDBContextType>({
|
||||
|
||||
const composeDBClient = new ComposeClient({
|
||||
ceramic: CONFIG.ceramicURL,
|
||||
definition,
|
||||
definition: composeDBDefinition,
|
||||
});
|
||||
|
||||
export const ComposeDBContextProvider: React.FC<PropsWithChildren> = ({
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
"precommit": "yarn lint-staged",
|
||||
"generate": "yarn generate:graphql",
|
||||
"generate:graphql": "DEBUG=1 graphql-codegen --config=codegen.yml",
|
||||
"generate:composedb": "composedb composite:compile ../../packages/utils/schema/user-profile-composite.json ./graphql/composeDB/autogen/definition.ts",
|
||||
"prepare": "yarn generate"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -3009,6 +3009,10 @@ input jsonb_comparison_exp {
|
||||
_nin: [jsonb!]
|
||||
}
|
||||
|
||||
type LinkCeramicProfileNodeResponse {
|
||||
verified: Boolean
|
||||
}
|
||||
|
||||
"""
|
||||
columns and relationships of "me"
|
||||
"""
|
||||
@@ -4062,6 +4066,11 @@ type mutation_root {
|
||||
on_conflict: skill_on_conflict
|
||||
): skill
|
||||
|
||||
"""
|
||||
perform the action: "linkCeramicProfileNode"
|
||||
"""
|
||||
linkCeramicProfileNode(nodeId: String!): LinkCeramicProfileNodeResponse
|
||||
|
||||
"""
|
||||
perform the action: "saveGuildInformation"
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user