Code Monkey home page Code Monkey logo

safe-gateway-typescript-sdk's Introduction

Safe Gateway TypeScript SDK

npm

A TypeScript SDK for the Safe Client Gateway

๐Ÿ“– Type referenceย  ย |ย  ย Swagger CGW Swagger

Usage policy

NB: Safe Client Gateway isn't meant for public use. Please do not use this SDK if you're building, e.g., a Safe App.

Using the SDK

Install:

yarn add @safe-global/safe-gateway-typescript-sdk

Import:

import { getChainsConfig, type ChainListResponse } from '@safe-global/safe-gateway-typescript-sdk'

Use:

const chains = await getChainsConfig()

The SDK needs no initialization unless you want to override the base URL. You can set an alternative base URL like so:

import { setBaseUrl } from '@safe-global/safe-gateway-typescript-sdk'

// Switch the SDK to dev mode
setBaseUrl('https://safe-client.staging.5afe.dev')

The full SDK reference can be found here.

Adding an endpoint

Endpoint types are defined in src/types/gateway.ts.

Each endpoint consists of:

  • a function defined in src/index.ts (e.g. getBalances)
  • a path definition (e.g. '/chains/{chainId}/safes/{address}/balances/{currency}/')
  • operation definition (e.g. safes_balances_list)
  • response definition

To add a new endpoint, follow the pattern set by the existing endpoints.

Eslint & prettier

This command will run before every commit:

yarn eslint:fix

Tests

To run the unit and e2e tests locally:

yarn test

N.B.: the e2e tests make actual API calls on staging.

safe-gateway-typescript-sdk's People

Contributors

compojoom avatar danisomoza avatar diogosoaress avatar fubhy avatar germartinez avatar iamacook avatar jmealy avatar juampibermani avatar katspaugh avatar mmv08 avatar schmanu avatar usame-algan avatar yagopv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

safe-gateway-typescript-sdk's Issues

Incorrect Option<Struct> type generation

A lot of the gateway structs are have optional keys, i.e. when no value is present, the key is not returned. Throughout the types, they have been generated as returning the value, or null. They should instead return the value or undefined.

A good example of this is the AddressEx (struct can be found here). If there is no name or logoUri, the keys are not returned. This has caused a lot of issues when using the types, requiring some fallbacks that aren't necessary. useKnownAddress is a good example.

This is likely an SDK-wide issue. I'm not sure what we used for type generation, if we did, but it may be worthwhile looking into ts-rs.

Add safe apps endpoint

Overview

Currently the web app is using the config service directly to fetch the Safe Apps list. This is the only dependency that we still have with the config service directly. Currently the client gateway already exposes the Safe Apps list endpoint so we can just rely also in the gateway to handle this

https://gnosis.github.io/safe-client-gateway/docs/routes/safe_apps/routes/index.html

Goals

  • Add the safe apps list route to the gateway-sdk
  • Use this version of the gateway-sdk to fetch the safe apps list
  • Remove the dependency with config service in web app

Add /owners/{address}/safes

Gateway is now proxying/caching the tx-service endpoint that gets the safes you own.
We need to add this endpoint to the SDK and replace the call in safe-react.

Invalid references to the documentation of the service

Since the service was migrated to Node.js, the documentation that was available under https://safe.global/safe-client-gateway ceased to exist.

The documentation that was available there was generated by Rust's doc tool. Since this no longer applies to the new project an alternative needs to be considered.

As for what is available right now: Swagger already provides the types being used on each endpoint as well as the respective structure. The OpenAPI specification in JSON format can be found under: https://safe-client.safe.global/-json

Migrate to the "unified" API (5 points)

The new "unified" API puts the chainId into the path (it used to be a network name in the host).
We need to migrate to this new format.

E.g. instead of this URL

https://safe-client.{network}.gnosis.io/v1 + /safes/{address}/

the new URL will look like this:

https://safe-client.gnosis.io/v1 + /{chainId}/safes/{address}/

Requirements

Each path should start with a {chainId} parameter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.