# @moonpay/platform-sdk-node

Server-side SDK for the [MoonPay Developer Platform](https://dev.moonpay.com). Creates and revokes customer sessions using your secret API key — the first step of every Platform integration. The resulting session token is what you pass to the browser ([`@moonpay/platform-sdk-web`](https://www.npmjs.com/package/@moonpay/platform-sdk-web)) or React Native ([`@moonpay/platform-sdk-react-native`](https://www.npmjs.com/package/@moonpay/platform-sdk-react-native)) SDK.

Your secret API key must never reach the client — use this package only in server-side environments (Node.js, edge functions).

## Installation

```bash
npm install @moonpay/platform-sdk-node
```

## Quick start

```typescript
import { createServerClient } from '@moonpay/platform-sdk-node';

const client = createServerClient({ apiKey: process.env.MOONPAY_API_KEY });

const result = await client.createSession({
  externalCustomerId: 'customer-123', // optional — omit for anonymous sessions
  deviceIp: request.ip,               // the customer's device IP
  // termsAcceptedAt: '2026-01-15T12:00:00.000Z', // when you capture ToU in your UI
});

if (!result.ok) {
  console.error(result.error);
  return;
}

// Send to your frontend — single-use, expires after 24 hours
const { sessionToken } = result.value;
```

All methods return a `Result<T, E>` discriminated union instead of throwing — check `result.ok` before using `result.value`.

## What the client provides

- **`createSession()`** — issue a session token for a customer. `email` and `phoneNumber` are independently optional; pass `termsAcceptedAt` when you capture Terms of Use acceptance in your own UI ([terms acceptance guide](https://dev.moonpay.com/platform/guides/terms-acceptance)).
- **`revokeSession()`** — revoke a previously issued session token.
- **`exportCustomer()`** — exchange a one-time consent token (captured client-side via `setupCustomerExport()` in the web/RN SDK) for the customer's verified MoonPay identity.

## Related packages

| Package | Use it for |
|---------|------------|
| `@moonpay/platform-sdk-web` | Browser integrations |
| `@moonpay/platform-sdk-react-native` | React Native apps |
| `@moonpay/platform-protocol` | Shared protocol and API types |

## Documentation

Full guides and API reference: [dev.moonpay.com](https://dev.moonpay.com)

- [Introduction](https://dev.moonpay.com/platform/overview/introduction)
- [API & SDK credentials](https://dev.moonpay.com/platform/guides/api-and-sdk-credentials)
- [Connect a customer](https://dev.moonpay.com/platform/guides/connect-a-customer)

## License

MIT
