1.7.4 • Published 11 days ago

@windingtree/sdk-node-api v1.7.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

@windingtree/sdk-node-api

The WindingTree market protocol node API server and client. This SDK provides a client and server implementation for communication with the WindingTree Market Protocol Node. This API allows to implement the protocol node management. For the implementation detail please see the node manager app example.

Installation

pnpm i @windingtree/sdk-node-api

Key concepts

This SDK is designed to work with the WindingTree Market Protocol and includes several core components:

  • Routers: These modules define the procedures for user management, admin management, and deal management. Procedures include registration, login, logout, delete, update, checkIn, and checkOut actions, among others.
  • Server: The server module sets up an API server that uses the defined routers to handle requests.
  • Client: The client module provides utilities for creating EIP-712 signatures for certain operations and middleware functions for tRPC link operations.
  • Constants: This module exports various constants used across the SDK, such as the access token name and the typed domain for admin signature.
  • Utils: This module exports a schema used for pagination in query inputs.

Usage

The package exports a NodeApiServer class that can be used to set up an API server that interacts with the WindingTree Market Protocol. The server uses tRPC, an end-to-end typesafe RPC framework, allowing for easy interaction with clients.

import { NodeApiServer } from '@windingtree/sdk-node-api/server';
import { appRouter } from '@windingtree/sdk-node-api/router';
import { ProtocolContracts } from '@windingtree/sdk-contracts-manager';
import { memoryStorage } from '@windingtree/sdk-storage';

// Initialize your ProtocolContracts, Node, and other components here...
const contractsManager = new ProtocolContracts({...});

const usersStorage = await memoryStorage.createInitializer({
  scope: 'users',
})();
const dealsStorage = await memoryStorage.createInitializer({
  scope: 'deals',
})();

const apiServer = new NodeApiServer({
  usersStorage,
  dealsStorage,
  prefix: 'my-prefix',
  port: 3000,
  secret: 'my-secret',
  ownerAccount: entityOwnerAddress,
  protocolContracts: contractsManager,
});

apiServer.start(appRouter);

// Handle incoming requests and perform necessary actions here...

Here's a simple example (React) of using the @windingtree/sdk-node-api/client:

import { createAdminSignature } from '@windingtree/sdk-node-api/client';
import { useNode, useWallet } from '@windingtree/sdk-react/providers';

// Your code to setup the WindingTree Wallet goes here. Assuming you have a `walletClient` object in the app component.
const { walletClient } = useWallet();
const { node } = useNode();

const handleAdminRegister = async (name: string) => {
  try {
    const signature = await createAdminSignature(walletClient);

    await node.admin.register.mutate({
      login: name,
      password: signature,
    });
  } catch (error) {
    console.error('Error admin register:', error);
  }
};

handleAdminRegister();

Documentation

For full documentation and examples, visit windingtree.github.io/sdk

Testing

pnpm test

Contributing

Contribution guidelines

1.7.4

11 days ago

1.7.3

2 months ago

1.7.2

2 months ago

1.7.1

2 months ago

1.7.0

3 months ago

1.6.1

3 months ago

1.6.0

3 months ago

1.5.7

3 months ago

1.5.6

3 months ago

1.5.5

3 months ago

1.5.4

3 months ago

1.5.3

3 months ago

1.5.2

4 months ago

1.5.1

4 months ago

1.5.1-beta.0

4 months ago

1.5.0

5 months ago

1.4.0

5 months ago

1.3.4

5 months ago

1.3.3

5 months ago

1.3.2

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.2.0

7 months ago

1.2.0-beta.0

7 months ago

1.1.1-beta.0

9 months ago

1.1.0

10 months ago

1.1.0-beta.3

10 months ago

1.1.0-beta.2

10 months ago

1.1.0-beta.1

10 months ago

1.1.0-beta.0

10 months ago