diff --git a/LICENSE b/LICENSE index a861434..2880052 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Gateway-DAO +Copyright (c) 2024 Gateway-DAO Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f83306f..8434b75 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A TypeScript SDK for the Gateway API. This library is built with TypeScript developers in mind, but it also works with JavaScript. -**Note: Our latest version of sdk works without adding any extra configuration for frontend environments.** +**Note: Our latest version of sdk uses REST API instead of graphql one. And is a breaking change if you upgrade** ### Features @@ -43,69 +43,77 @@ yarn add @gateway-dao/sdk ## Gateway Client -To setup the gateway client we will authenticate with a bearer-token,api key and wallet private key as follows +To setup the gateway client we will authenticate with a bearer-token,or use wallet private key as follows ```typescript -import { Gateway } from '@gateway-dao/sdk'; +import { Gateway, WalletTypeEnum } from '@gateway-dao/sdk'; +// using jwt +// you need to manage jwt expration on your own. JWT expires after 5 days once issued const gateway = new Gateway({ - apiKey: 'your-api-key', - token: 'your-token', - url: 'https://sandbox.protocol.mygateway.xyz/graphql', - walletPrivateKey: 'your-private-key', // store this in env file! + jwt: 'your-jwt', // store in env file! +}); + +// using wallet private key +// here we manage jwt on your behalf thus providing better experience +const gateway = new Gateway({ + wallet: { + privateKey: 'your-private-key', // store in env file! + walletType: WalletTypeEnum.Ethereum, + }, }); ``` -**The wallet private key is not send anywhere and is just used to sign messages on behalf of developer/organization using it. This way we minimize signature errors on protocol and provide smoother developer experience** +**The wallet private key is not send anywhere and is just used to sign messages on behalf of developer using it to aviod to manage jwt token himself. This way we minimize jwt expiration errors on API and provide smoother developer experience** -**Make sure you add token without Bearer as we add Bearer automatically when you make request. Else it will give you Unauthorized error even if your token is correct** +**If you are using bearer token make sure you add token without Bearer as we add Bearer automatically when you make request. Else it will give you Unauthorized error even if your token is correct** For example ```typescript import { Gateway } from '@gateway-dao/sdk'; const gateway = new Gateway({ - apiKey: 'your-api-key', - token: 'Bearer your-token', - // wrong will not work just use token: 'your-token' - url: 'https://sandbox.protocol.mygateway.xyz/graphql', - walletPrivateKey: 'your-private-key', // store this in env file! + token: 'Bearer your-token', // this is wrong won't work }); ``` -This library supports Bearer Token along with Api Key. Do not share your authentication token with people you don’t trust. This gives the user control over your account and they will be able to manage PDAs (and more) with it. Use environment variables to keep it safe. +This library supports Bearer Token along. Do not share your authentication token with people you don’t trust. This gives the user control over your account and they will be able to manage Data Assets (and more) with it. Use environment variables to keep it safe. ## Examples -Make sure to add try catch blocks around methods to catch all the validation and protocol based errors. +Make sure to add try catch blocks around methods to catch all the validation and API based errors. ### Creating a PDA ```typescript -import { Gateway, UserIdentifierType } from '@gateway-dao/sdk'; +import { Gateway, AccessLevel, WalletTypeEnum } from '@gateway-dao/sdk'; const gateway = new Gateway({ - apiKey: 'your-api-key', - token: 'your-token', - url: 'https://sandbox.protocol.mygateway.xyz/graphql', - walletPrivateKey: 'your-private-key', // store this in env file! + wallet: { + privateKey: 'your-private-key', // store in env file! + walletType: WalletTypeEnum.Ethereum, // supported types are ethereum,solana,sui + }, }); async function main() { try { - let obj = { - dataModelId: 'uuid-here', - description: 'test', - title: 'test', - claim: { - gatewayUse: 'test', - }, - owner: { - type: UserIdentifierType.GATEWAY_ID, - value: 'test', - }, + const claim = { + firstName: 'Test', + age: 21, }; - const { createPDA } = await gateway.pda.createPDA(obj); + const id = await gateway.dataAsset.createStructured({ + name: 'THIS IS A TEST', + data_model_id: 508557480951911, + tags: ['football', 'sports'], + claim: claim, + acl: [ + { + address: 'another-user-did', + roles: [AccessLevel.VIEW, AccessLevel.SHARE], // assing roles + }, + ], + }); + console.log('\nData Asset created with ID:', id); } catch (error) { console.log(error); // Can log it for degugging } @@ -114,27 +122,38 @@ async function main() { main(); ``` -### Creating a Organization +### Creating a Data Model ```typescript -import { Gateway } from '@gateway-dao/sdk'; +import { Gateway, AccessLevel, WalletTypeEnum } from '@gateway-dao/sdk'; const gateway = new Gateway({ - apiKey: 'your-api-key', - token: 'your-token', - url: 'https://sandbox.protocol.mygateway.xyz/graphql', - walletPrivateKey: 'your-private-key', // store this in env file! + wallet: { + privateKey: 'your-private-key', // store in env file! + walletType: WalletTypeEnum.Ethereum, // supported types are ethereum,solana,sui + }, }); async function main() { try { - let obj = { - username: 'test_for_sdk_2', - name: 'test org sdk 2', - description: 'test organization', - }; - const { createOrganization } = - await gateway.organization.createOrganization(obj); + const dataModelBody = { + title: 'test sdk dm', + description: 'test sdk dm', + schema: { + type: 'object', + title: 'Gateway ID', + default: {}, + required: [], + properties: { + name: { + type: 'string', + title: 'Name', + }, + }, + additionalProperties: false, + }, + }; + result = await gateway.dataModel.create(dataModelBody); } catch (error) { console.log(error); // Can log it for degugging } @@ -148,8 +167,7 @@ We have created a separate repository which have more [examples you can access i ## Error Handling -All the methods throw a validation error if the validation does not match for example:- invalid wallet, invalid uuid for all ids, -Incase of any protocol errors we will throw a custom message which is a string which has all neccessary info regarding error. Make sure to use try catch blocks to handle those. +Incase of any API errors we will throw a custom message which is a string which has all neccessary info regarding error. Make sure to use try catch blocks to handle those. ## License diff --git a/docs/CODE_BASE_OVERVIEW.md b/docs/CODE_BASE_OVERVIEW.md index 74d8722..65f57ea 100644 --- a/docs/CODE_BASE_OVERVIEW.md +++ b/docs/CODE_BASE_OVERVIEW.md @@ -4,23 +4,20 @@ This section will give you an overview of the SDK codebase. We will also discuss - If you want to contribute to the SDK make sure you read this document and the [Contributing Guildelines](CONTRIBUTING.md) before proceeding. -### Custom Script to generate sdk from graphql end point +### Custom Script to types from our [swagger doc](https://api.gateway.tech/swagger/index.html) + +- We we have a [custom in-house script](../scripts/generate-types.js) which generates types for our SDK automatically. -- We don't use graphql mesh anymore instead we have a [custom in-house script](../scripts/generateSDK/generate.js)(heavily inspired from graphql mesh team) which generates a complete type-safe SDK using our graphql Schema. -- Using this script we are able to auto generate all of queries and mutations and also providing autocomplete feature for developing applications. ### Top Level Folder Structure -- The src folder has all the classes which a developer will use. The following are the classes which we are using:- +- The src folder has all the classes which a developer will use. The following are the classes which we are using inside modules folder:- -1. Auth Class:- Handles all Authentication related methods. +1. Account Class:- Handles all Authentication && wallet related methods. 2. Data Model:- Handles all Data Models related methods. -3. Organization:- Handles all Organization related methods. -4. PDA:- Handles all PDA related methods. -5. Proof:- Handles all Proof related methods. -6. Request:- Handles all Requests related methods. -7. User:- Handles all User related methods. -8. Transactions:- Handles all User related methods. +3. Auth:- Handles all Auth related methods. +4. Data Asset:- Handles all Data asset && Access Control List related methods. + - The services folder has all functions related to crypto,wallets, and validation related functions. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index c26a286..478852c 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -56,10 +56,10 @@ pnpm i ``` -3. Create the sdk using our custom script(it should give .gatewaySdk folder with sdk in it) +3. Create the sdk using our custom script(it should give .api.d.ts file inside src folder) ```sh - pnpm generate:sdk + pnpm generate ``` 4. Run test command to test sdk using jest diff --git a/docs/SECURITY.md b/docs/SECURITY.md index fb5c8ba..decbe72 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -4,8 +4,9 @@ | Version | Supported | | ------- | ------------------ | +| 3.x.x | :white_check_mark: | | 2.x.x | :white_check_mark: | -| 1.x.x | :white_check_mark: | +| 1.x.x | :x: | ## Reporting a Vulnerability diff --git a/package.json b/package.json index a4f2459..3e28778 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "@gateway-dao/sdk", "version": "0.0.0-semantic-release", "description": "A Typescript SDK for the Gateway API", - "main": "dist/src/index.js", - "types": "dist/src/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { "dev": "ts-node-dev src/testing.ts", "generate": "./scripts/generate-yml.sh",