Skip to content

Commit

Permalink
fix: fixed all possible bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Jun 27, 2024
1 parent d9dbc4e commit 6496637
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 74 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
"@solana/web3.js": "^1.87.6",
"axios": "^1.7.2",
"canonicalize": "^2.0.0",
"encoding": "^0.1.13",
"ethers": "^5.7.2",
"form-data": "^4.0.0",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"node-forge": "^1.3.1"
Expand Down
103 changes: 103 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions scripts/generateSDK/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function fetchAndGetUnifiedSchema({ url }) {
}
}

async function generateSdk({ url, sdkName }) {
async function generateSdk({ url, sdkName, regexs }) {
try {
fs.access(join(__dirname, '..', '..', 'gatewaySdk'), (err) => {
if (err) {
Expand All @@ -67,6 +67,7 @@ async function generateSdk({ url, sdkName }) {
setDepth: 2,
unifiedSchema,
sdkName,
regexs,
});
console.log(`Done Generating ${sdkName}`);
} catch (error) {
Expand All @@ -82,13 +83,17 @@ const generateSdkInBatch = () => {
},
{
sdkName: 'GatewayV3',
url: 'http://127.0.0.1:3000/graphql',
url: 'https://v3-dev.protocol.mygateway.xyz/graphql',
regexs: [/dataAsset\s*{[^}]*}/g, /data\s*{\s*dataUse\s*}/g],
},
];
// url: 'https://v3-dev.protocol.mygateway.xyz/graphql',
configs.forEach(
async (config) =>
await generateSdk({ url: config.url, sdkName: config.sdkName }),
await generateSdk({
url: config.url,
sdkName: config.sdkName,
regexs: config.regexs,
}),
);
};

Expand Down
10 changes: 9 additions & 1 deletion scripts/generateSDK/generateArtificats.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async function generateTsArtifacts({
setDepth,
fileType,
sdkName,
regexs,
}) {
const artifactsDir = join(baseDir, artifactsDirectory);
console.log('Generating index file in TypeScript');
Expand Down Expand Up @@ -115,7 +116,7 @@ async function generateTsArtifacts({
JSON.stringify(documentHashMap, null, 2),
);
}
const codegenOutput =
let codegenOutput =
'// @ts-nocheck\n' +
'/* This file is auto generated \n' +
'Do not make changes to this file */\n' +
Expand Down Expand Up @@ -191,6 +192,13 @@ async function generateTsArtifacts({
.replace('testing-1', '')
.replace(/Operations./g, '');

if (regexs) {
codegenOutput = regexs.reduce(
(str, regex) => str.replace(regex, ''),
codegenOutput,
);
}

const endpointAssignmentCJS = `const baseDir = join(typeof __dirname === 'string' ? __dirname : '/', '${relative(
artifactsDir,
baseDir,
Expand Down
8 changes: 1 addition & 7 deletions src/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { Request } from './v2/request/request';
import { DataModel } from './v2/data-model/data-model';
import { User } from './v2/user/user';
import { Transaction } from './v2/transaction/transaction';
import {
checkVersion,
clientTimingWrapper,
parameterChecker,
} from './utils/helper';
import { clientTimingWrapper, parameterChecker } from './utils/helper';

export {
AuthType,
Expand Down Expand Up @@ -49,8 +45,6 @@ export class Gateway {
}) {
parameterChecker(apiKey, token, url);

checkVersion();

const client = new GraphQLClient(url, {
headers: {
Authorization: `Bearer ${token}`,
Expand Down
14 changes: 7 additions & 7 deletions src/GatewayV3.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { GraphQLClient } from 'graphql-request';
import { Sdk, getSdk } from '../gatewaySdk/sources/GatewayV3';
import {
checkVersion,
clientTimingWrapper,
parameterChecker,
} from './utils/helper';
import { clientTimingWrapper, parameterChecker } from './utils/helper';
import { PDA } from './v3/pda/pda';
import { Auth } from './v3/auth/auth';
import { DataModel } from './v3/data-model/data-model';
import { Organization } from './v3/organization/organization';
import { Proof } from './v3/proof/proof';
import { Request } from './v3/request/request';
import { User } from './v3/user/user';
import { Wallet } from 'ethers';
import { generateNewEtherumWallet } from './utils/v3-crypto-helper';

export class GatewayV3 {
private sdk: Sdk;
Expand All @@ -22,29 +20,31 @@ export class GatewayV3 {
public proof: Proof;
public request: Request;
public user: User;
public wallet: Wallet;

constructor({
apiKey,
token,
url,
walletPrivateKey,
logging = false,
}: {
apiKey: string;
token: string;
url: string;
walletPrivateKey: string;
logging?: boolean;
}) {
parameterChecker(apiKey, token, url);

checkVersion();

const client = new GraphQLClient(url, {
headers: {
Authorization: `Bearer ${token}`,
'x-api-key': apiKey,
'user-agent': `GATEWAY_SDK/v3`,
},
});
this.wallet = generateNewEtherumWallet(walletPrivateKey);

this.sdk = getSdk(client, logging ? clientTimingWrapper : undefined);
this.pda = new PDA(this.sdk, url, apiKey, token);
Expand Down
Loading

0 comments on commit 6496637

Please sign in to comment.