@ref247/affiliate-sdk
Version:
Ref247.io Affiliate SDK - integrate with us from you backend or build your custom UI
102 lines (69 loc) • 3.22 kB
Markdown
# Ref247AffiliateSDK
The `Ref247AffiliateSDK` is a TypeScript-based SDK designed to interact with the Ref247 Affiliate API. It provides a comprehensive set of methods to manage authentication, users, organizations, affiliates, campaigns, commissions, and more.
## Features
- **User Management**: Retrieve and update user details.
- **Organization Management**: Manage organizations, users, roles, currencies, and event types.
- **Affiliate Management**: Handle affiliates, campaigns, referrals, and commissions.
- **Campaign Management**: Create, update, and delete campaigns.
- **Commission Management**: Manage commission structures, rules, and statuses.
- **File Management**: Generate signed URLs for file uploads.
- **Payment Management**: Handle Stripe configurations, billing, and subscriptions.
- **Audit Logs**: Retrieve audit logs for organizations.
## Installation
Install the SDK via npm:
```bash
npm install @ref247/affiliate-sdk
```
## Usage
### Initialization
To initialize the SDK, use the `init` method:
```typescript
import { Ref247AffiliateSDK } from '@ref247/affiliate-sdk';
// Enterprise customers can pass their whitelabel url in the init
// Generate your api key from Settings -> API Keys
const affiliateSdk = await Ref247AffiliateSDK.init(WHITELABEL_URL?, API_KEY?);
```
### User Management
```typescript
const user = await affiliateSdk.getMe();
await affiliateSdk.updateUser(user.id, { firstName: 'John', lastName: 'Doe' });
```
### Organization Management
```typescript
const organizations = await affiliateSdk.getOrganizations();
const newOrg = await affiliateSdk.createOrganization('New Organization', 'user-id');
```
### Affiliate Management
```typescript
const affiliates = await affiliateSdk.getAffiliates('organization-id');
const newAffiliate = await affiliateSdk.createAffiliate({ name: 'Affiliate Name', email: 'email@example.com' });
```
### Campaign Management
```typescript
const campaigns = await affiliateSdk.getAllCampaignsOfOrganization('organization-id');
const newCampaign = await affiliateSdk.createCampaign({ name: 'Campaign Name', budget: 1000 });
```
### Commission Management
```typescript
const commissionStructures = await affiliateSdk.getCommissionStructuresOfOrganization('organization-id');
const newStructure = await affiliateSdk.addCommissionStructure({ name: 'Structure Name', rules: [] });
```
### File Management
```typescript
const signedUrl = await affiliateSdk.getOrganizationSignedUrl('organization-id');
```
### Payment Management
```typescript
const stripeConfig = await affiliateSdk.getStripeConfig();
const billingSession = await affiliateSdk.createBillingSession({ planId: 'plan-id' });
```
### Audit Logs
```typescript
const auditLogs = await affiliateSdk.getAuditLogsByOrganizationId('organization-id');
```
## API Reference
For a detailed list of all available methods and their parameters, refer to the source code in `src/index.ts`.
## Contributing
Contributions are welcome! Please submit a pull request or open an issue for any bugs or feature requests.
## License
This project is licensed under the MIT License.