diff --git a/.eslintignore b/.eslintignore index e45dca4..362f0a2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,4 +7,5 @@ coverage/* custom-fetch.js commitlint.config.js release.config.js -.husky/* \ No newline at end of file +.husky/* +scripts/* \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 2f1df7b..a024c43 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve sdk -title: "[BUG]" +title: '[BUG]' labels: bug assignees: '' - --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Which class are you using? '...' 2. Which method are you using? '....' @@ -22,10 +22,11 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Environment Setup (please complete the following information):** - - OS: [e.g.Windows, Mac, Linux] - - Sdk version [e.g. 1.0.0] - - Node.js Version [e.g. 16.20.2] - - Package Manager [e.g. pnpm,npm,yarn] + +- OS: [e.g.Windows, Mac, Linux] +- Sdk version [e.g. 1.0.0] +- Node.js Version [e.g. 16.20.2] +- Package Manager [e.g. pnpm,npm,yarn] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 7f1babd..8d9db06 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea to improve sdk -title: "[Feat]" +title: '[Feat]' labels: enhancement assignees: '' - --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1d6b9d7..70469b6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,7 +2,7 @@ name: Release on: push: - branches: [ develop ] + branches: [develop] jobs: release: diff --git a/CHANGELOG.md b/CHANGELOG.md index 711aacd..0db9061 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,8 @@ # [1.0.0-develop.6](https://github.com/Gateway-DAO/gateway-js-sdk/compare/v1.0.0-develop.5...v1.0.0-develop.6) (2024-01-23) - ### Bug Fixes -* **tracking:** refresh .gitignore ([03317a8](https://github.com/Gateway-DAO/gateway-js-sdk/commit/03317a8bc497d119c3232e5ca59f35882d37f289)) +- **tracking:** refresh .gitignore ([03317a8](https://github.com/Gateway-DAO/gateway-js-sdk/commit/03317a8bc497d119c3232e5ca59f35882d37f289)) # [1.0.0-develop.5](https://github.com/Gateway-DAO/gateway-js-sdk/compare/v1.0.0-develop.4...v1.0.0-develop.5) (2024-01-23) diff --git a/CODE_BASE_OVERVIEW.md b/CODE_BASE_OVERVIEW.md index d29abf7..b482134 100644 --- a/CODE_BASE_OVERVIEW.md +++ b/CODE_BASE_OVERVIEW.md @@ -2,27 +2,29 @@ This section will give you an overview of the SDK codebase. We will also discuss in short the tools we use and the implementation. -* If you want to contribute to the SDK make sure you read this document and the [Contributing Guildelines](https://github.com/Gateway-DAO/javascript-sdk/blob/main/CONTRIBUTING.md) before proceeding. +- If you want to contribute to the SDK make sure you read this document and the [Contributing Guildelines](https://github.com/Gateway-DAO/javascript-sdk/blob/main/CONTRIBUTING.md) before proceeding. ### Graphql Mesh -* We are using graphql mesh which generates a complete type-safe SDK using our graphql Schema. -* Using this tool we are able to auto generate all of queries and mutations and also providing autocomplete feature for developing applications. + +- We are using graphql mesh which generates a complete type-safe SDK using our graphql Schema. +- Using this tool 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:- -1) Auth Class:- Handles all Authentication related methods. -2) Data Model:- Handles all Data Models related methods. -3) Data Request Templates:- Handles all Data Request Template related methods. -4) Organization:- Handles all Organization related methods. -5) PDA:- Handles all PDA related methods. -6) Proof:- Handles all Proof related methods. -7) Request:- Handles all Requests related methods. -8) User:- Handles all User related methods. -9) Transactions:- Handles all User related methods. -* The utils folder has basic utilities functions like validations to validate all user input. +- The src folder has all the classes which a developer will use. The following are the classes which we are using:- + +1. Auth Class:- Handles all Authentication related methods. +2. Data Model:- Handles all Data Models related methods. +3. Data Request Templates:- Handles all Data Request Template related methods. +4. Organization:- Handles all Organization related methods. +5. PDA:- Handles all PDA related methods. +6. Proof:- Handles all Proof related methods. +7. Request:- Handles all Requests related methods. +8. User:- Handles all User related methods. +9. Transactions:- Handles all User related methods. -* The tests folder has all the unit test for the above classes. We are using mocking to mock the SDK. +- The utils folder has basic utilities functions like validations to validate all user input. -* We are using prettier and eslint to make sure that code format is maintained. Across all the files. +- The tests folder has all the unit test for the above classes. We are using mocking to mock the SDK. +- We are using prettier and eslint to make sure that code format is maintained. Across all the files. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f272c9b..7659f75 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,47 +1,48 @@ - ## How to contribute on SDK ### Open Development -* All work on the SDK happens directly on GitHub. Both core team members and external contributors send pull requests which go through the same review process. + +- All work on the SDK happens directly on GitHub. Both core team members and external contributors send pull requests which go through the same review process. ### Semantic Versioning -* The SDK follows [semantic versioning](https://semver.org/). We release patch versions for critical bugfixes, minor versions for new features or non-essential changes, and major versions for any breaking changes. -* When we make breaking changes, we also introduce deprecation warnings in a minor version so that our users learn about the upcoming changes and migrate their code in advance. +- The SDK follows [semantic versioning](https://semver.org/). We release patch versions for critical bugfixes, minor versions for new features or non-essential changes, and major versions for any breaking changes. -* Every significant change is documented in the [changelog file](https://github.com/Gateway-DAO/javascript-sdk/blob/main/CHANGELOG.md). +- When we make breaking changes, we also introduce deprecation warnings in a minor version so that our users learn about the upcoming changes and migrate their code in advance. + +- Every significant change is documented in the [changelog file](https://github.com/Gateway-DAO/javascript-sdk/blob/main/CHANGELOG.md). ### Branch Organization -* Submit all changes directly to the ```develop``` branch. We use separate branches for development or for upcoming releases. And then after the bug/feature is working we release in main branch. -* Code that lands in ```develop``` must be compatible with the latest stable release. It may contain additional features, but no breaking changes. We should be able to release a new minor version from the tip of develop at any time. +- Submit all changes directly to the `develop` branch. We use separate branches for development or for upcoming releases. And then after the bug/feature is working we release in main branch. - -### Bugs +- Code that lands in `develop` must be compatible with the latest stable release. It may contain additional features, but no breaking changes. We should be able to release a new minor version from the tip of develop at any time. -* **Do not open up a GitHub issue if the bug is a security vulnerability**, and instead refer our [security policy](https://github.com/Gateway-DAO/javascript-sdk/blob/main/SECURITY.md). +### Bugs -* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/Gateway-dao/javascript-sdk/issues). +- **Do not open up a GitHub issue if the bug is a security vulnerability**, and instead refer our [security policy](https://github.com/Gateway-DAO/javascript-sdk/blob/main/SECURITY.md). -* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/Gateway-dao/javascript-sdk/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** demonstrating the expected behavior that is not occurring. +- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/Gateway-dao/javascript-sdk/issues). -* Once the issue is created you can follow the contributing steps below to start contributing +- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/Gateway-dao/javascript-sdk/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** demonstrating the expected behavior that is not occurring. +- Once the issue is created you can follow the contributing steps below to start contributing ### **Add a new Feature** -* If you intend to change/add a new feature to the sdk please discuss with us first on [Discord](https://discord.gg/tgt3KjcHGs) before creating a new issue. This lets us reach an agreement on your proposal before you put significant effort into it. +- If you intend to change/add a new feature to the sdk please discuss with us first on [Discord](https://discord.gg/tgt3KjcHGs) before creating a new issue. This lets us reach an agreement on your proposal before you put significant effort into it. -* Do not open an issue on GitHub until you have collected positive feedback about the feature from us. +- Do not open an issue on GitHub until you have collected positive feedback about the feature from us. -* We will reject issues which are not discussed with us regarding feature development. +- We will reject issues which are not discussed with us regarding feature development. -* Once the issue is created you can follow the contributing steps below to start contributing. +- Once the issue is created you can follow the contributing steps below to start contributing. ### Contributing Guildeline -* You have Node.js installed at LTS with version 16+ and using pnpm as package manager. -* You have knowldge of git. -* Read the [code base overview](https://github.com/Gateway-DAO/javascript-sdk/blob/main/CODE_BASE_OVERVIEW.md) to have a short introduction about how we manage/write code. + +- You have Node.js installed at LTS with version 16+ and using pnpm as package manager. +- You have knowldge of git. +- Read the [code base overview](https://github.com/Gateway-DAO/javascript-sdk/blob/main/CODE_BASE_OVERVIEW.md) to have a short introduction about how we manage/write code. ### Development Workflow @@ -64,8 +65,9 @@ ```sh pnpm test ``` -* We recommend to keep test coverage above 90% this way we make sure that the feature/bug you add don't reduce the test coverage. Also make sure that there are no linting errors as we use prettier and eslint to maintain proper code structure. + +- We recommend to keep test coverage above 90% this way we make sure that the feature/bug you add don't reduce the test coverage. Also make sure that there are no linting errors as we use prettier and eslint to maintain proper code structure. Thanks! -@Gateway-DAO Team \ No newline at end of file +@Gateway-DAO Team diff --git a/README.md b/README.md index e6a9f38..bf0ba50 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,23 @@ A TypeScript SDK for the Gateway API. This library is built with TypeScript deve ## Installation ### Using npm + ``` npm install @gateway-dao/sdk ``` ### Using pnpm + ``` pnpm add @gateway-dao/sdk ``` ### Using yarn + ``` yarn install @gateway-dao/sdk ``` - ## Gateway Client To setup the gateway client we will authenticate with a bearer-token and a Api key as follows @@ -51,14 +53,16 @@ const gateway = new Gateway({ url: '', }); ``` + **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', + token: 'Bearer your-token', // wrong will not work just use token: 'your-token' url: '', }); @@ -174,7 +178,6 @@ The Gateway Javascript SDK is licensed under the [MIT License](https://github.co If you want to support the active development of the SDK. [Please go through our Contribution guide](https://github.com/Gateway-DAO/gateway-js-sdk/blob/main/CONTRIBUTING.md) - [npm-image]: https://img.shields.io/npm/v/%40gateway-dao%2Fsdk.svg?style=flat [npm-url]: https://www.npmjs.com/package/@gateway-dao/sdk [downloads-image]: https://img.shields.io/npm/dm/%40gateway-dao%2Fsdk @@ -183,4 +186,3 @@ If you want to support the active development of the SDK. [Please go through our [codecov-url]: https://codecov.io/gh/Gateway-DAO/gateway-js-sdk [discord-image]: https://img.shields.io/discord/733027681184251937.svg?style=flat&label=Join%20Community&color=7289DA [discord-url]: https://discord.gg/tgt3KjcHGs - diff --git a/SECURITY.md b/SECURITY.md index 8d86682..ce7552b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,11 +2,10 @@ ## Supported Versions - | Version | Supported | | ------- | ------------------ | | 1.x.x | :white_check_mark: | - ## Reporting a Vulnerability -***Do not open up a GitHub issue if the bug is a security vulnerability in SDK***. Instead, [please talk to us on Discord](https://discord.gg/tgt3KjcHGs) + +**_Do not open up a GitHub issue if the bug is a security vulnerability in SDK_**. Instead, [please talk to us on Discord](https://discord.gg/tgt3KjcHGs) diff --git a/package.json b/package.json index 94fc2fc..362dbad 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "lint:fix": "eslint . --fix", "format": "prettier --write .", "prepare": "husky install", - "build": "tsc" + "build": "rm -rf dist && tsc && scripts/compress.sh && node scripts/compress.js" }, "lint-staged": { "*.ts": [ @@ -43,6 +43,7 @@ "@types/jest": "^29.5.11", "@types/node": "^20.10.4", "@typescript-eslint/eslint-plugin": "^6.13.2", + "dts-minify": "^0.3.2", "eslint": "^8.55.0", "eslint-config-prettier": "^9.1.0", "eslint-config-standard-with-typescript": "^39.1.1", @@ -55,7 +56,8 @@ "lint-staged": "^15.2.0", "prettier": "^3.1.1", "ts-jest": "^29.1.1", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "uglify-js": "^3.17.4" }, "repository": { "type": "git", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b1d150..5c32437 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -46,6 +46,9 @@ devDependencies: '@typescript-eslint/eslint-plugin': specifier: ^6.13.2 version: 6.19.0(eslint@8.56.0)(typescript@5.3.3) + dts-minify: + specifier: ^0.3.2 + version: 0.3.2 eslint: specifier: ^8.55.0 version: 8.56.0 @@ -85,6 +88,9 @@ devDependencies: typescript: specifier: ^5.3.3 version: 5.3.3 + uglify-js: + specifier: ^3.17.4 + version: 3.17.4 packages: @@ -1633,7 +1639,7 @@ packages: tsconfig-paths: 4.2.0 tslib: 2.6.2 typescript: 5.3.3 - uWebSockets.js: github.com/uNetworking/uWebSockets.js/f97da56fe535bb6d318c62ed31e0f44cef104f05 + uWebSockets.js: github.com/uNetworking/uWebSockets.js/105d9ec47126cb82e4a6f3a08aa2ac78b4bb14f1 yargs: 17.7.2 transitivePeerDependencies: - '@swc/core' @@ -4174,6 +4180,10 @@ packages: engines: {node: '>=4'} dev: false + /dts-minify@0.3.2: + resolution: {integrity: sha512-X7SlplQ8TjJMNWwbPfD6Q0s+y2EZqImsrQDEvZcFc3QYy9vdwdUpZi+jos0BBT6c8EJn33F+uePHuofwkRCToA==} + dev: true + /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: false @@ -8049,6 +8059,12 @@ packages: resolution: {integrity: sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ==} dev: false + /uglify-js@3.17.4: + resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==} + engines: {node: '>=0.8.0'} + hasBin: true + dev: true + /unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} dependencies: @@ -8403,8 +8419,8 @@ packages: dev: false optional: true - github.com/uNetworking/uWebSockets.js/f97da56fe535bb6d318c62ed31e0f44cef104f05: - resolution: {tarball: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/f97da56fe535bb6d318c62ed31e0f44cef104f05} + github.com/uNetworking/uWebSockets.js/105d9ec47126cb82e4a6f3a08aa2ac78b4bb14f1: + resolution: {tarball: https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/105d9ec47126cb82e4a6f3a08aa2ac78b4bb14f1} name: uWebSockets.js - version: 20.40.0 + version: 20.41.0 dev: false diff --git a/release.config.js b/release.config.js index 1663e01..53fbb8e 100644 --- a/release.config.js +++ b/release.config.js @@ -3,8 +3,8 @@ module.exports = { 'main', { name: 'develop', - prerelease: true - } + prerelease: true, + }, ], plugins: [ '@semantic-release/commit-analyzer', diff --git a/scripts/compress.js b/scripts/compress.js new file mode 100644 index 0000000..3abbf07 --- /dev/null +++ b/scripts/compress.js @@ -0,0 +1,38 @@ +const fs = require('fs'); +const { createMinifier } = require('dts-minify'); +const ts = require('typescript'); + +const minifier = createMinifier(ts); + +function processFile(inputFile, outputFile) { + fs.readFile(inputFile, 'utf8', (err, data) => { + if (err) { + console.error(`Error reading ${inputFile}: ${err.message}`); + return; + } + + const minifiedText = minifier.minify(data); + + fs.writeFile(outputFile, minifiedText, 'utf8', (writeErr) => { + if (writeErr) { + console.error(`Error writing to ${outputFile}: ${writeErr.message}`); + } else { + console.log( + `File successfully processed. Modified content written to ${outputFile}`, + ); + } + }); + }); +} + +const filesToProcess = [ + { + input: 'dist/.mesh/sources/GatewaySDK/types.d.ts', + output: 'dist/.mesh/sources/GatewaySDK/types.d.ts', + }, + { input: 'dist/.mesh/index.d.ts', output: 'dist/.mesh/index.d.ts' }, +]; + +filesToProcess.forEach((file) => { + processFile(file.input, file.output); +}); diff --git a/scripts/compress.sh b/scripts/compress.sh new file mode 100755 index 0000000..bbecb8b --- /dev/null +++ b/scripts/compress.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +files="dist/.mesh/sources/GatewaySDK/introspectionSchema.js dist/.mesh/index.js dist/src/auth/auth.js dist/src/data-model/data-model.js dist/src/dataRequestsTemplate/dataRequestsTemplate.js dist/src/organization/organization.js dist/src/pda/pda.js dist/src/proof/proof.js dist/src/request/request.js dist/src/user/user.js" + +for file in $files; do + uglifyjs "$file" -o "$file" +done + +echo "Compression completed successfully." diff --git a/src/pda/pda.ts b/src/pda/pda.ts index 0e264e3..3b28aed 100644 --- a/src/pda/pda.ts +++ b/src/pda/pda.ts @@ -5,6 +5,7 @@ import { UpdatePDAInput, PDAs_queryQueryVariables, issuedPDAs_queryQueryVariables, + PDACount_queryQueryVariables, } from '../../.mesh'; import { PDAStatus } from '../types'; import { errorHandler } from '../utils/errorHandler'; @@ -41,9 +42,9 @@ export class PDA { * of type `FilterPDAInput`. * @returns a Promise that resolves to a number. */ - async getPDACount(filter?: FilterPDAInput) { + async getPDACount(filter?: PDACount_queryQueryVariables) { try { - return (await this.sdk.PDACount_query({ filter })).PDACount; + return (await this.sdk.PDACount_query(filter)).PDACount; } catch (error) { throw new Error(errorHandler(error)); } diff --git a/src/user/user.ts b/src/user/user.ts index fc1cca0..eedf561 100644 --- a/src/user/user.ts +++ b/src/user/user.ts @@ -1,11 +1,11 @@ import { FilterDataModelInput, FilterDataRequestTemplateInput, - FilterPDAInput, Sdk, UpdateUserInput, myFinancialTransactionsCount_queryQueryVariables, myFinancialTransactions_queryQueryVariables, + myPDACount_queryQueryVariables, myPDAs_queryQueryVariables, myTransactions_queryQueryVariables, } from '../../.mesh'; @@ -69,9 +69,9 @@ export class User { * of type `FilterPDAInput`. * @returns a Promise that resolves to a number. */ - async myPDACount(filter: FilterPDAInput = {}) { + async myPDACount(filter?: myPDACount_queryQueryVariables) { try { - return (await this.sdk.myPDACount_query({ filter })).myPDACount; + return (await this.sdk.myPDACount_query(filter)).myPDACount; } catch (error) { throw new Error(errorHandler(error)); }