# @windingtree/sdk-node-api

> The WindingTree market protocol node API server and client

Latest version **1.7.4** (published 2024-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @windingtree/sdk-node-api
pnpm add @windingtree/sdk-node-api
yarn add @windingtree/sdk-node-api
bun add @windingtree/sdk-node-api
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.4 |
| Published | 2024-04-29 |
| First published | 2023-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 13 |
| Unpacked size | 264.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Kostiantyn Smyrnov |
| Maintainers | kostysh, kvakes, tomashq |

## Links

- npm: https://www.npmjs.com/package/@windingtree/sdk-node-api
- Repository: https://github.com/windingtree/sdk.git#readme
- Homepage: https://github.com/windingtree/sdk/tree/readme#readme
- Issues: https://github.com/windingtree/sdk/issues
- npm.io page: https://npm.io/package/@windingtree/sdk-node-api

## Dependencies (13)

- [zod](https://npm.io/package/zod.md) ^3.22.4
- [jose](https://npm.io/package/jose.md) ^4.14.4
- [viem](https://npm.io/package/viem.md) ^1.19.3
- [abitype](https://npm.io/package/abitype.md) ^0.10.3
- [superjson](https://npm.io/package/superjson.md) ^2.2.1
- [@trpc/client](https://npm.io/package/@trpc/client.md) ^10.44.1
- [@trpc/server](https://npm.io/package/@trpc/server.md) ^10.44.1
- [@windingtree/sdk-db](https://npm.io/package/@windingtree/sdk-db.md) 1.3.3
- [@windingtree/sdk-types](https://npm.io/package/@windingtree/sdk-types.md) 1.1.4
- [@windingtree/sdk-logger](https://npm.io/package/@windingtree/sdk-logger.md) 1.1.4
- [@windingtree/sdk-storage](https://npm.io/package/@windingtree/sdk-storage.md) 1.5.0
- [@windingtree/sdk-messages](https://npm.io/package/@windingtree/sdk-messages.md) 1.2.3
- [@windingtree/sdk-contracts-manager](https://npm.io/package/@windingtree/sdk-contracts-manager.md) 1.5.2

## Recent versions

- 1.7.4 (latest) — 2024-04-29
- 1.5.1-beta.0 (beta) — 2024-01-17
- 1.7.3 — 2024-03-11
- 1.7.2 — 2024-03-08
- 1.7.1 — 2024-03-08
- 1.7.0 — 2024-02-19
- 1.6.1 — 2024-02-19
- 1.6.0 — 2024-02-16
- 1.5.7 — 2024-02-15
- 1.5.6 — 2024-02-13
- 1.5.5 — 2024-02-13
- 1.5.4 — 2024-02-12
- 1.5.3 — 2024-01-26
- 1.5.2 — 2024-01-22
- 1.5.1 — 2024-01-17
- … 17 more at https://npm.io/package/@windingtree/sdk-node-api/versions

## README

# @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](../../examples/manager/).

## Installation

```bash
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.

```typescript
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`:

```typescript
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](https://windingtree.github.io/sdk)

## Testing

```bash
pnpm test
```

## Contributing

[Contribution guidelines](https://windingtree.github.io/sdk/#/docs/contribution)

---
_Source: https://npm.io/package/@windingtree/sdk-node-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
