npm package: @reepher/partner-sdk
Description: Reepher Partners SDK
Author: Reepher
Latest version: 0.7.0

# Reepher TypeScript SDK

The Reepher TypeScript SDK is an npm library that provides a convenient 
way for Reepher partners to interact with the Reepher Partners API.
This SDK is written in TypeScript and includes type safe definitions 
to help you seamlessly integrate Reepher services into your applications.

## Installation

You can install the Reepher SDK using npm:

```bash
npm install @reepher/partner-sdk
```

## Usage

Here's how you can set up and use the SDK:

```typescript
import { ReepherClient, TransactionsClient } from '@reepher/partner-sdk';

// Initialize the Reepher client
const reepherClient = new ReepherClient({
    auth: {
        // Specify your client ID.
        clientId: 'id',
        // And client secret.
        clientSecret: 'secret',
    },
});


// Define an incoming transaction
const incomingTransaction: IncomingTransaction = {
  // ... transaction details
};

// Process a single transaction
try {
  const result = await reepherClient.transactions.process(incomingTransaction);
  console.log('Transaction processed:', result);
} catch (error) {
  console.error('Error processing transaction:', error);
}

// Process a batch of transactions
const batchTransactions: IncomingTransaction[] = [
  // ... list of transactions
];

try {
  const batchResult = await reepherClient.transactions.processBatch(batchTransactions);
  console.log('Batch processed:', batchResult);
} catch (error) {
  console.error('Error processing batch:', error);
}
```


## Transactions API

A typical transaction is defined by the `IncomingTransaction` interface and has the following format:

```typescript
export interface IncomingTransaction {
    /**
     * Partner transaction id.
     * Specify your identifier to easily track the transaction status.
     */
    transactionId: string;

    /**
     * A policy type.
     */
    policyType: 'reepher48';

    /**
     * Email of a user which ordered a policy with the transaction.
     */
    email: string;

    /**
     * Transaction time in ISO 8601 format.
     */
    transactionTime: string;

    /**
     * Transaction flat amount.
     */
    transactionAmount: number;
}
```

The transactions API includes the following methods:

* `process(transaction: IncomingTransaction): Promise<TransactionImportSuccess>`: Sends a transaction to Reepher for processing. Returns a success response if the transaction is processed successfully.

* `processBatch(transactions: Array<IncomingTransaction>): Promise<TransactionBulkImportResult>`: Sends a batch of transactions to Reepher for processing. Returns a bulk import result containing the status of each transaction in the batch.

## Typical API errors

Every API related error is inherited from `ReepherError` class, there are
though some edge cases with more specific meaning:

* `ReepherUnauthorizedError` is raised upon any authorization related error (i.e. incorrect credentials).
* `ReepherValidationError` is raised upon any user input error and typically contains exact validation error message.