From 2cc363d8246c2989e53bfe254534595357c956cd Mon Sep 17 00:00:00 2001 From: Siddharth9890 Date: Mon, 30 Oct 2023 19:36:45 +0530 Subject: [PATCH] feat: working on adding types everywhere possible --- custom-fetch.ts | 27 +++++++++++++++++++-------- index.ts | 27 ++++++++++++++++++++++----- package.json | 1 + pnpm-lock.yaml | 39 +++++++++++++++++++++++++++++++++++---- src/Auth.ts | 15 +++++++++++++++ src/Gateway.ts | 19 +++++++++++++++++++ src/PDA.ts | 14 ++++++++++++++ types.ts | 7 +++++++ 8 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 src/Auth.ts create mode 100644 src/Gateway.ts create mode 100644 src/PDA.ts create mode 100644 types.ts diff --git a/custom-fetch.ts b/custom-fetch.ts index 27d331e..493d084 100644 --- a/custom-fetch.ts +++ b/custom-fetch.ts @@ -1,14 +1,25 @@ -import { MeshContext } from "@graphql-mesh/runtime"; -import { fetch } from "@whatwg-node/fetch"; +import { Headers, fetch } from "@whatwg-node/fetch"; +import { MeshContext } from "./.mesh"; + +type ContextModified = MeshContext & { + token: string; + apiKey: string; +}; export default function patchedFetch( url: string, - init: any, - context: MeshContext + init: RequestInit, + context: ContextModified ) { - console.debug(url, init.headers); - init.headers["Authorization"] = - "Bearer your-token"; - + const headers = new Headers(); + headers.set( + "accept", + "application/graphql-response+json application/json multipart/mixed" + ); + headers.set("content-type", "application/json"); + headers.set("Authorization", `Bearer ${context.token}`); + headers.set("X-Api-Key", context.apiKey); + init.headers = headers; + console.log(url, init); return fetch(url, init); } diff --git a/index.ts b/index.ts index 37f11a2..fce08e1 100644 --- a/index.ts +++ b/index.ts @@ -1,12 +1,29 @@ -import { getMeshSDK } from "./.mesh/index"; +import { Gateway } from "./src/Gateway"; +import { UserIdentifierType } from "./types"; async function test() { - const sdk = getMeshSDK(); + const api = new Gateway({ + apiKey: "m9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q", + token: + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ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DFSdXU0OGxCVXliU0R4Y3Z5RXR5TU94N0ErY0dQcy93MGg5aUtZZy9OVnEvTFdwWjEzYmVzcS9QanpWXHJcbjR5ZnZaTkpyT3VxMXpkc29MdlVaUTVuMHJ1c21PekMyNlhMb3BpVlpUSWk3U1k4QzAvNFNlaVVvaU8vaVBFbnhcclxuOW5nL0RUMEsvQXlLbTBZQ1oxU2pwZ1VDQXdFQUFRPT1cclxuLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tXHJcbiJ9LCJ0eXBlIjoiYXV0aF90b2tlbiIsImlhdCI6MTY5ODIxMTg0N30.zUxmPhnrQlIEZ5pMzHBMFkcqPvjsIfs0er9Dylw5olE", + }); + let obj = { + dataModelId: "f4014d53-b30f-4490-9812-cea379a1b398", + description: "test", + title: "test", + claim: { + gatewayUse: "test", + }, + owner: { + type: UserIdentifierType.EMAIL, + value: "sid", + }, + }; try { - const { me } = await sdk.me_query(); - console.log(me.createdAt); - } catch (error) { + const { createPDA } = await api.pda.createPDA(obj); + console.log(createPDA.id, createPDA.issuerHash); + } catch (error: any) { console.log(error); } } diff --git a/package.json b/package.json index 3294bde..026882d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@graphql-mesh/cli": "^0.87.14", "@graphql-mesh/graphql": "^0.95.7", "@graphql-mesh/runtime": "^0.96.11", + "@graphql-mesh/transform-naming-convention": "^0.95.8", "@types/node": "^20.8.4", "@whatwg-node/fetch": "^0.9.13", "graphql": "^16.8.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 15b0ae8..bbd1ad2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,7 @@ specifiers: '@graphql-mesh/cli': ^0.87.14 '@graphql-mesh/graphql': ^0.95.7 '@graphql-mesh/runtime': ^0.96.11 + '@graphql-mesh/transform-naming-convention': ^0.95.8 '@types/node': ^20.8.4 '@whatwg-node/fetch': ^0.9.13 graphql: ^16.8.1 @@ -14,6 +15,7 @@ dependencies: '@graphql-mesh/cli': 0.87.14_gfkpsopqhnihhlgdygsd6kqyri '@graphql-mesh/graphql': 0.95.7_gfkpsopqhnihhlgdygsd6kqyri '@graphql-mesh/runtime': 0.96.11_graphql@16.8.1 + '@graphql-mesh/transform-naming-convention': 0.95.8_graphql@16.8.1 '@types/node': 20.8.6 '@whatwg-node/fetch': 0.9.13 graphql: 16.8.1 @@ -969,7 +971,7 @@ packages: tsconfig-paths: 4.2.0 tslib: 2.6.2 typescript: 5.2.2 - uWebSockets.js: github.com/uNetworking/uWebSockets.js/21c0e41a662c27bcc29b64f3e9d7f0bdaa6d7ee7 + uWebSockets.js: github.com/uNetworking/uWebSockets.js/c10b47c350cc97c299c6b4a07a98abb628704c71 yargs: 17.7.2 transitivePeerDependencies: - '@swc/core' @@ -1225,6 +1227,25 @@ packages: tslib: 2.6.2 dev: false + /@graphql-mesh/transform-naming-convention/0.95.8_graphql@16.8.1: + resolution: {integrity: sha512-7i1Vb8RsPybWgLd8goIBab2DmEMFr7rFtSKGPnIDUGLmoRXGeOYg7SkP9C5hJS5/ii1BkGCnLQVVWMr+fdOBUw==} + engines: {node: '>=16.0.0'} + peerDependencies: + '@graphql-mesh/types': ^0.95.7 + '@graphql-mesh/utils': ^0.95.7 + '@graphql-tools/utils': ^9.2.1 || ^10.0.0 + graphql: '*' + tslib: ^2.5.0 + dependencies: + '@graphql-tools/delegate': 10.0.3_graphql@16.8.1 + '@graphql-tools/wrap': 10.0.1_graphql@16.8.1 + change-case: 4.1.2 + graphql: 16.8.1 + graphql-scalars: 1.22.4_graphql@16.8.1 + lower-case: 2.0.2 + upper-case: 2.0.2 + dev: false + /@graphql-mesh/types/0.95.7_mmfugwwqfkiqifkhy5nd4jdmqq: resolution: {integrity: sha512-afM2uuGR//lBoDrQvyfDmCcPwObpouRauahKVrXGyxkWe9LuIBG+scBZcynSbKotO1SgFcbJtToafMAIk5CefQ==} engines: {node: '>=16.0.0'} @@ -2692,6 +2713,16 @@ packages: lodash.mergewith: 4.6.2 dev: false + /graphql-scalars/1.22.4_graphql@16.8.1: + resolution: {integrity: sha512-ILnv7jq5VKHLUyoaTFX7lgYrjCd6vTee9i8/B+D4zJKJT5TguOl0KkpPEbXHjmeor8AZYrVsrYUHdqRBMX1pjA==} + engines: {node: '>=10'} + peerDependencies: + graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 + dependencies: + graphql: 16.8.1 + tslib: 2.6.2 + dev: false + /graphql-tag/2.12.6_graphql@16.8.1: resolution: {integrity: sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==} engines: {node: '>=10'} @@ -4240,8 +4271,8 @@ packages: dev: false optional: true - github.com/uNetworking/uWebSockets.js/21c0e41a662c27bcc29b64f3e9d7f0bdaa6d7ee7: - resolution: {tarball: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/21c0e41a662c27bcc29b64f3e9d7f0bdaa6d7ee7} + github.com/uNetworking/uWebSockets.js/c10b47c350cc97c299c6b4a07a98abb628704c71: + resolution: {tarball: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/c10b47c350cc97c299c6b4a07a98abb628704c71} name: uWebSockets.js - version: 20.32.0 + version: 20.33.0 dev: false diff --git a/src/Auth.ts b/src/Auth.ts new file mode 100644 index 0000000..56fe52f --- /dev/null +++ b/src/Auth.ts @@ -0,0 +1,15 @@ +import { createWalletNonce_mutationMutation } from "../.mesh"; + +export class Auth { + private sdk: any; + + constructor(sdk: any) { + this.sdk = sdk; + } + + async createWalletNounce( + wallet: string + ): Promise { + return await this.sdk.createWalletNonce_mutation({ input: { wallet } }); + } +} diff --git a/src/Gateway.ts b/src/Gateway.ts new file mode 100644 index 0000000..60cb2d7 --- /dev/null +++ b/src/Gateway.ts @@ -0,0 +1,19 @@ +import { Auth } from "./Auth"; +import { PDA } from "./PDA"; +import { getMeshSDK, MeshContext } from "../.mesh"; + +export class Gateway { + // public auth: Auth; + public pda: PDA; + private sdk: any; + + constructor({ apiKey, token }: { apiKey: string; token: string }) { + if (!apiKey && !token) throw new Error("No token found"); + this.sdk = getMeshSDK({ + apiKey, + token, + }); + // this.auth = new Auth(); + this.pda = new PDA(this.sdk); + } +} diff --git a/src/PDA.ts b/src/PDA.ts new file mode 100644 index 0000000..2574750 --- /dev/null +++ b/src/PDA.ts @@ -0,0 +1,14 @@ +import { CreatePDAInput, createPDA_mutationMutation } from "../.mesh"; + +export class PDA { + private sdk: any; + + constructor(sdk: any) { + this.sdk = sdk; + } + async createPDA( + pdaInput: CreatePDAInput + ): Promise { + return await this.sdk.createPDA_mutation({ input: pdaInput }); + } +} diff --git a/types.ts b/types.ts new file mode 100644 index 0000000..10a6ece --- /dev/null +++ b/types.ts @@ -0,0 +1,7 @@ +export enum UserIdentifierType { + EMAIL, + EVM, + GATEWAY_ID, + SOLANA, + USER_ID, +}