@jokoor/sdk
Version:
Official Jokoor API SDK for JavaScript/TypeScript - SMS, Payments, and more
1,940 lines (1,906 loc) • 76.2 kB
TypeScript
import { AxiosRequestConfig } from 'axios';
/**
* Core SDK Types
*/
type PaymentMode = "test" | "live";
type APIKeyType = "secret" | "publishable";
interface JokoorConfig {
/**
* API base URL (default: https://api.jokoor.com/v1)
*/
baseURL?: string;
/**
* Request timeout in milliseconds (default: 30000)
*/
timeout?: number;
/**
* Maximum number of retry attempts (default: 3)
*/
maxRetries?: number;
/**
* Enable debug logging (default: false)
*/
debug?: boolean;
}
/**
* Pagination parameters
*/
interface PaginationParams {
offset?: number;
limit?: number;
}
/**
* Paginated response
*/
interface PaginatedResponse<T> {
items: T[];
count: number;
offset: number;
limit: number;
}
/**
* Common timestamp fields
*/
interface Timestamps {
createdAt: string;
updatedAt?: string;
}
/**
* SMS Types
*/
interface SMSMessage extends Timestamps {
id: string;
organizationId: string;
recipientPhone: string;
messageBody: string;
senderId?: string;
status: "draft" | "queued" | "sending" | "sent" | "delivered" | "failed" | "cancelled";
segments: number;
scheduledAt?: string;
contactId?: string;
templateId?: string;
campaignId?: string;
errorMessage?: string;
}
interface SendSMSParams {
recipientPhone?: string;
messageBody?: string;
senderId?: string;
templateId?: string;
templateParams?: Record<string, string>;
scheduledAt?: string;
contactId?: string;
isDraft?: boolean;
}
interface SMSTemplate extends Timestamps {
id: string;
organizationId: string;
name: string;
body: string;
description?: string;
}
interface CreateSMSTemplateParams {
name: string;
body: string;
description?: string;
}
interface UpdateSMSTemplateParams {
name?: string;
body?: string;
description?: string;
}
interface SMSContact extends Timestamps {
id: string;
organizationId: string;
phoneNumber: string;
firstName?: string;
lastName?: string;
email?: string;
customFields?: Record<string, string>;
}
interface CreateSMSContactParams {
phoneNumber: string;
firstName?: string;
lastName?: string;
email?: string;
customFields?: Record<string, string>;
}
interface UpdateSMSContactParams {
phoneNumber?: string;
firstName?: string;
lastName?: string;
email?: string;
customFields?: Record<string, string>;
}
interface SMSContactGroup extends Timestamps {
id: string;
organizationId: string;
name: string;
description?: string;
contactCount: number;
}
interface CreateSMSContactGroupParams {
name: string;
description?: string;
}
interface UpdateSMSContactGroupParams {
name?: string;
description?: string;
}
interface SMSSenderID extends Timestamps {
id: string;
organizationId: string;
senderId: string;
status: "pending" | "approved" | "rejected";
purpose?: string;
useCase?: string;
isDefault: boolean;
}
interface CreateSenderIDParams {
senderId: string;
purpose?: string;
useCase?: string;
}
interface UpdateSenderIDParams {
purpose?: string;
useCase?: string;
}
interface CampaignDetails {
totalMessageCount: number;
totalSentMessages: number;
totalFailedMessages: number;
totalPendingMessages: number;
totalSegmentsUsed: number;
deliveryRate: number;
failureRate: number;
pendingRate: number;
statusBreakdown: Record<string, number>;
}
interface SMSCampaign extends Timestamps {
id: string;
organizationId: string;
name: string;
messageTemplateId?: string;
senderIdConfigId?: string;
status: "draft" | "scheduled" | "sending" | "completed" | "failed" | "cancelled";
scheduledAt?: string;
startedAt?: string;
completedAt?: string;
createdBy?: string;
details?: CampaignDetails;
metadata?: Record<string, unknown>;
}
interface CreateSMSCampaignParams {
name: string;
messageBody?: string;
templateId?: string;
templateParams?: Record<string, string>;
senderId?: string;
contactIds?: string[];
groupIds?: string[];
scheduledAt?: string;
isDraft?: boolean;
}
interface UpdateSMSCampaignParams {
name?: string;
messageBody?: string;
templateId?: string;
templateParams?: Record<string, string>;
senderId?: string;
contactIds?: string[];
groupIds?: string[];
}
/**
* Payment Types
*/
type PaymentMethod = "wave" | "afrimoney" | "card";
type Currency = "GMD";
type PaymentStatus = "pending" | "processing" | "succeeded" | "failed" | "cancelled";
interface PaymentLink extends Timestamps {
id: string;
organizationId: string;
title: string;
description?: string;
amount: string;
currency: Currency;
isVariableAmount: boolean;
minAmount?: string;
maxAmount?: string;
expirationDate?: string;
maxUsageCount?: number;
usageCount: number;
paymentUrl: string;
successUrl?: string;
failureUrl?: string;
status: "active" | "inactive";
collectCustomerInfo: boolean;
customFields?: Array<{
name: string;
type: string;
label: string;
required: boolean;
options?: string[];
}>;
metadata?: Record<string, unknown>;
livemode: boolean;
organization?: {
id: string;
name: string;
logo?: string;
};
products?: Array<{
productId: string;
name: string;
description: string;
price: string;
quantity: number;
total: string;
}>;
}
interface CreatePaymentLinkParams {
title: string;
description?: string;
amount: string;
currency?: Currency;
isVariableAmount?: boolean;
minAmount?: string;
maxAmount?: string;
expirationDate?: string;
maxUsageCount?: number;
successUrl?: string;
failureUrl?: string;
collectCustomerInfo?: boolean;
customFields?: Array<{
name: string;
type: "text" | "number" | "email" | "phone" | "select";
label?: string;
required?: boolean;
options?: string[];
}>;
metadata?: Record<string, string>;
}
interface UpdatePaymentLinkParams {
title?: string;
description?: string;
expirationDate?: string;
maxUsageCount?: number;
successUrl?: string;
failureUrl?: string;
status?: "active" | "inactive";
collectCustomerInfo?: boolean;
customFields?: Array<{
name: string;
type: "text" | "number" | "email" | "phone" | "select";
label?: string;
required?: boolean;
options?: string[];
}>;
metadata?: Record<string, string>;
}
interface Checkout extends Timestamps {
id: string;
organizationId: string;
amount: string;
currency: Currency;
paymentUrl: string;
clientSecret: string;
status: PaymentStatus;
availablePaymentMethods?: string[];
automaticPaymentMethods: boolean;
customerId?: string;
customerPhone: string;
customerEmail?: string;
customerName?: string;
expiresAt: string;
description?: string;
reference?: string;
items?: Array<{
productId?: string;
description: string;
quantity: number;
unitPrice: string;
total: string;
}>;
metadata?: Record<string, unknown>;
livemode: boolean;
transaction?: {
id: string;
status: string;
amount: string;
fee: string;
netAmount: string;
};
}
interface CreateCheckoutParams {
amount?: string;
currency?: Currency;
items?: Array<{
productId?: string;
name?: string;
description?: string;
unitPrice?: string;
quantity: number;
}>;
paymentMethodTypes?: string[];
automaticPaymentMethods?: boolean;
paymentMethod?: "card" | "wave" | "afrimoney";
customerId?: string;
customerPhone?: string;
customerEmail?: string;
customerName?: string;
expiresIn?: number;
metadata?: Record<string, unknown>;
description?: string;
reference?: string;
idempotencyKey?: string;
successUrl?: string;
failureUrl?: string;
}
interface Invoice extends Timestamps {
id: string;
organizationId: string;
invoiceNumber: string;
customerId?: string;
customerEmail?: string;
customerName?: string;
customerPhone?: string;
customerAddress?: string;
amount: string;
taxRate: number;
taxAmount: string;
totalAmount: string;
paidAmount: string;
remainingAmount: string;
currency: Currency;
status: "draft" | "pending" | "paid" | "partially_paid" | "overdue" | "cancelled";
dueDate?: string;
issuedDate: string;
paidDate?: string;
sentAt?: string;
sentCount: number;
notes?: string;
items: InvoiceItem[];
paymentUrl?: string;
pdfUrl?: string;
receipts?: Array<{
id: string;
receiptNumber: string;
amount: string;
paymentMethod: string;
issuedDate: string;
}>;
subscriptionId?: string;
livemode: boolean;
metadata?: Record<string, unknown>;
organization?: {
id: string;
name: string;
logoUrl?: string;
};
}
interface InvoiceItem {
description: string;
quantity: number;
unitPrice: string;
amount: string;
}
interface CreateInvoiceParams {
items: Array<{
productId?: string;
description?: string;
unitPrice?: string;
quantity: number;
}>;
currency: string;
dueDate: string;
customerId?: string;
customerEmail?: string;
customerName?: string;
customerAddress?: string;
customerPhone?: string;
taxRate?: number;
notes?: string;
isDraft?: boolean;
metadata?: Record<string, unknown>;
}
interface UpdateInvoiceParams {
items?: Array<{
productId?: string;
description?: string;
unitPrice?: string;
quantity: number;
}>;
dueDate?: string;
customerEmail?: string;
customerName?: string;
customerAddress?: string;
customerPhone?: string;
taxRate?: number;
notes?: string;
metadata?: Record<string, unknown>;
}
interface Product extends Timestamps {
id: string;
organizationId: string;
name: string;
description?: string;
price: string;
currency: Currency;
active: boolean;
mode: "test" | "live";
}
interface CreateProductParams {
name: string;
description?: string;
price: string;
currency?: Currency;
images?: string[];
metadata?: Record<string, unknown>;
}
interface UpdateProductParams {
name?: string;
description?: string;
price?: string;
isActive?: boolean;
images?: string[];
metadata?: Record<string, unknown>;
}
interface Customer extends Timestamps {
id: string;
organizationId: string;
email?: string;
phone?: string;
name?: string;
mode: "test" | "live";
}
interface CreateCustomerParams {
email: string;
phone?: string;
name?: string;
metadata?: Record<string, unknown>;
}
interface UpdateCustomerParams {
email?: string;
phone?: string;
name?: string;
metadata?: Record<string, unknown>;
}
interface Transaction extends Timestamps {
id: string;
paymentSessionId: string;
objectType: "payment_link" | "invoice" | "donation" | "checkout" | "subscription";
objectId: string;
organizationId: string;
customerId?: string;
amount: string;
fee: string;
netAmount: string;
currency: Currency;
status: "pending" | "processing" | "completed" | "failed" | "cancelled" | "expired" | "refunded" | "partially_refunded";
paymentMethod: PaymentMethod;
paymentMethodTransactionId?: string;
customerEmail?: string;
customerPhone?: string;
customerName?: string;
paymentPhone?: string;
paymentDetails?: Record<string, unknown>;
mode: "test" | "live";
livemode: boolean;
initiatedAt: string;
processingAt?: string;
completedAt?: string;
failedAt?: string;
refundedAmount?: string;
failureReason?: string;
stateTransitions?: Array<{
status: string;
timestamp: string;
}>;
paymentMethodResponse?: Record<string, unknown>;
attemptCount: number;
metadata?: Record<string, unknown>;
processingType?: string;
recordingSource?: string;
recordedBy?: string;
}
interface Refund extends Timestamps {
id: string;
organizationId: string;
transactionId: string;
amount: string;
reason?: string;
status: "pending" | "succeeded" | "failed";
mode: "test" | "live";
}
interface CreateRefundParams {
amount?: string;
reason?: string;
}
interface Subscription extends Timestamps {
id: string;
organizationId: string;
customerId?: string;
customerEmail: string;
customerName: string;
amount: string;
currency: Currency;
taxRate: number;
status: "active" | "paused" | "cancelled" | "completed";
interval: "day" | "week" | "month" | "year";
intervalCount: number;
dayOfMonth?: number;
dayOfWeek?: number;
startDate: string;
endDate?: string;
nextInvoiceDate: string;
lastInvoiceDate?: string;
items: InvoiceItem[];
notes?: string;
mode: "test" | "live";
version: number;
metadata?: Record<string, unknown>;
}
interface CreateSubscriptionParams {
customerId?: string;
customerEmail?: string;
customerName?: string;
customerAddress?: string;
customerPhone?: string;
currency: string;
interval: "day" | "week" | "month" | "year";
intervalCount: number;
startDate: string;
items: Array<{
productId?: string;
description?: string;
unitPrice?: string;
quantity: number;
}>;
taxRate?: number;
dayOfMonth?: number;
dayOfWeek?: number;
endDate?: string;
notes?: string;
metadata?: Record<string, unknown>;
}
interface UpdateSubscriptionParams {
interval?: "day" | "week" | "month" | "year";
intervalCount?: number;
dayOfMonth?: number;
dayOfWeek?: number;
endDate?: string;
status?: "active" | "paused" | "cancelled";
notes?: string;
metadata?: Record<string, unknown>;
}
interface DonationCampaign extends Timestamps {
id: string;
organizationId: string;
title: string;
slug: string;
description?: string;
targetAmount?: string;
currentAmount: string;
currency: Currency;
tags: string[] | null;
isRecurring: boolean;
recurringInterval?: string;
donationUrl: string;
imageUrl?: string;
endDate?: string;
status: "active" | "inactive" | "completed";
mode: "test" | "live";
livemode: boolean;
donorCount: number;
viewCount: number;
lastDonationAt?: string;
progressPercentage: number;
metadata?: Record<string, unknown>;
organization?: {
id: string;
name: string;
logo?: string;
};
organizerDetails?: {
name: string;
description?: string;
website?: string;
logoUrl?: string;
};
recentUpdates?: Array<{
id: string;
title: string;
description: string;
images: Array<{
id: string;
url: string;
thumbnailUrl?: string;
width?: number;
height?: number;
}>;
createdAt: string;
}>;
}
interface CreateDonationCampaignParams {
title: string;
description?: string;
targetAmount?: string;
currency?: Currency;
tags?: string[];
isRecurring?: boolean;
recurringInterval?: string;
endDate?: string;
slug?: string;
imageUrl?: string;
metadata?: Record<string, unknown>;
}
interface UpdateDonationCampaignParams {
title?: string;
description?: string;
targetAmount?: string;
tags?: string[];
endDate?: string;
status?: "active" | "inactive" | "completed";
slug?: string;
imageUrl?: string;
metadata?: Record<string, unknown>;
}
/**
* Payout Types
*/
interface PayoutBalance {
availableBalance: string;
pendingBalance: string;
currency: Currency;
}
interface BankAccount extends Timestamps {
id: string;
organizationId: string;
bankName: string;
accountNumber: string;
accountName: string;
isDefault: boolean;
}
interface CreateBankAccountParams {
bankName: string;
accountNumber: string;
accountName: string;
otpCode: string;
}
interface PayoutRequest extends Timestamps {
id: string;
organizationId: string;
amount: string;
bankAccountId: string;
status: "pending" | "processing" | "completed" | "failed" | "cancelled";
}
interface CreatePayoutRequestParams {
amount: string;
bankAccountId: string;
otpCode: string;
}
interface PayoutRecipient extends Timestamps {
id: string;
organizationId: string;
name: string;
phone: string;
email?: string;
}
interface CreatePayoutRecipientParams {
name: string;
payoutPhone: string;
email?: string;
payoutMethod?: "wave" | "afrimoney" | "qmoney";
recipientType?: "employee" | "contractor" | "member" | "vendor" | "other";
internalReference?: string;
notes?: string;
metadata?: Record<string, any>;
}
interface UpdatePayoutRecipientParams {
name?: string;
payoutPhone?: string;
email?: string;
payoutMethod?: "wave" | "afrimoney" | "qmoney";
recipientType?: "employee" | "contractor" | "member" | "vendor" | "other";
internalReference?: string;
notes?: string;
isActive?: boolean;
metadata?: Record<string, any>;
}
interface RecipientPayout extends Timestamps {
id: string;
organizationId: string;
recipientId: string;
amount: string;
status: "pending" | "completed" | "failed" | "cancelled";
reference?: string;
}
interface SendRecipientPayoutParams {
recipientId: string;
amount: string;
description?: string;
verificationId?: string;
otp?: string;
}
/**
* Deposit Transaction Types
*/
interface DepositTransaction extends Timestamps {
id: string;
amount: string;
currency: Currency;
source: string;
sourceId: string;
description?: string;
status: "pending" | "completed" | "failed";
completedAt?: string;
}
interface ListDepositsParams {
offset?: number;
limit?: number;
startDate?: string;
endDate?: string;
}
/**
* Bulk Payout Types
*/
interface BulkPayoutItem {
recipientId: string;
amount: string;
description?: string;
}
interface BulkRecipientPayoutParams {
payouts: BulkPayoutItem[];
}
interface ProcessCSVPayoutParams {
uploadId: string;
}
interface BulkPayoutByTypeParams {
recipientType: string;
amountPerRecipient: string;
description?: string;
}
interface BulkPayoutStatus {
id: string;
recipientId: string;
amount: string;
status: "pending" | "completed" | "failed" | "cancelled";
errorMessage?: string;
}
interface BulkPayoutBatch extends Timestamps {
id: string;
organizationId: string;
totalAmount: string;
totalCount: number;
successfulCount: number;
failedCount: number;
pendingCount: number;
status: "pending" | "processing" | "completed" | "partially_completed" | "failed";
payouts: BulkPayoutStatus[];
completedAt?: string;
}
interface CSVUploadResult {
uploadId: string;
rowsCount: number;
totalAmount: string;
validationErrors?: Array<{
row: number;
field: string;
error: string;
}>;
expiresAt: string;
}
/**
* Webhook Types
*/
type WebhookEventType = "sms.sent" | "sms.delivered" | "sms.failed" | "payment.succeeded" | "payment.failed" | "refund.created" | "refund.succeeded" | "refund.failed" | "invoice.paid" | "invoice.payment_failed" | "subscription.created" | "subscription.cancelled" | "payout.succeeded" | "payout.failed";
interface WebhookEndpoint extends Timestamps {
id: string;
organizationId: string;
url: string;
description?: string;
apiVersion: string;
enabledEvents: WebhookEventType[];
status: "active" | "inactive";
secret?: string;
metadata?: Record<string, unknown>;
consecutiveFailures: number;
lastSuccessAt?: string;
lastFailureAt?: string;
disabledAt?: string;
disableReason?: string;
created: string;
}
interface CreateWebhookEndpointParams {
url: string;
enabledEvents: WebhookEventType[];
}
interface UpdateWebhookEndpointParams {
url?: string;
enabledEvents?: WebhookEventType[];
status?: "active" | "inactive";
}
interface WebhookEvent extends Timestamps {
id: string;
type: WebhookEventType;
data: unknown;
delivered: boolean;
deliveryAttempts: number;
nextRetryAt?: string;
}
/**
* Payment Initialization Types
*/
interface InitializePaymentParams {
objectType?: "payment_link" | "invoice" | "donation" | "checkout" | "topup";
objectId?: string;
clientSecret?: string;
sessionId?: string;
paymentMethod?: PaymentMethod;
customerEmail?: string;
customerPhone?: string;
customerName?: string;
}
interface PaymentSession {
sessionId: string;
paymentMethod: PaymentMethod;
status: PaymentStatus;
amount: string;
currency: Currency;
customerEmail?: string;
customerPhone?: string;
customerName?: string;
redirectUrl?: string;
providerSessionId?: string;
}
interface PaymentStatusResponse {
sessionId: string;
status: PaymentStatus;
paymentMethod: PaymentMethod;
amount: string;
currency: Currency;
}
/**
* Receipt Types
*/
interface Receipt extends Timestamps {
id: string;
receiptNumber: string;
invoiceId?: string;
invoicePaymentId?: string;
organizationId: string;
amount: string;
currency: Currency;
paymentMethod: PaymentMethod;
paymentDate: string;
transactionId?: string;
receiptUrl?: string;
validationCode: string;
customerName?: string;
customerEmail?: string;
customerPhone?: string;
customerAddress?: string;
orgName: string;
orgAddress?: string;
orgPhone?: string;
orgEmail?: string;
status: "pending" | "completed" | "failed";
mode: "test" | "live";
livemode: boolean;
}
/**
* Result type for API responses following the {data, error} pattern
* Similar to Go's error handling approach - no exceptions thrown
*/
/**
* Result type that represents either successful data or an error
* Only one of data or error will be present at a time
*/
type Result<T> = {
data: T;
error: null;
} | {
data: null;
error: string;
};
/**
* Helper function to create a successful result
*/
declare function ok<T>(data: T): Result<T>;
/**
* Helper function to create an error result
*/
declare function err<T>(error: string): Result<T>;
/**
* Type guard to check if a result is successful
*/
declare function isOk<T>(result: Result<T>): result is {
data: T;
error: null;
};
/**
* Type guard to check if a result is an error
*/
declare function isErr<T>(result: Result<T>): result is {
data: null;
error: string;
};
/**
* Extract data from a result or throw if it's an error
* Useful for migrating from throw-based code
*/
declare function unwrap<T>(result: Result<T>): T;
/**
* Extract data from a result or return a default value
*/
declare function unwrapOr<T>(result: Result<T>, defaultValue: T): T;
/**
* Map a successful result to a new value
*/
declare function map<T, U>(result: Result<T>, fn: (value: T) => U): Result<U>;
/**
* Chain results together - useful for sequential operations
*/
declare function chain<T, U>(result: Result<T>, fn: (value: T) => Result<U>): Result<U>;
/**
* Convert a Promise that might throw into a Result
*/
declare function fromPromise<T>(promise: Promise<T>): Promise<Result<T>>;
/**
* Convert multiple Results into a single Result containing an array
* If any result is an error, returns that error
*/
declare function all<T>(results: Result<T>[]): Result<T[]>;
/**
* HTTP client with retry logic and proper error handling
*/
interface HttpClientConfig {
apiKey: string;
baseURL?: string;
timeout?: number;
maxRetries?: number;
debug?: boolean;
}
declare class HttpClient {
private client;
private debug;
constructor(config: HttpClientConfig);
/**
* Make a GET request
*/
get<T>(url: string, config?: AxiosRequestConfig): Promise<Result<T>>;
/**
* Make a POST request
*/
post<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<Result<T>>;
/**
* Make a PUT request
*/
put<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<Result<T>>;
/**
* Make a DELETE request
*/
delete<T>(url: string, config?: AxiosRequestConfig): Promise<Result<T>>;
/**
* Generic request method with error handling
*/
private request;
/**
* Extract error message from axios error
*/
private extractErrorMessage;
}
/**
* Base resource class for all API resources
*/
declare abstract class BaseResource {
protected client: HttpClient;
constructor(client: HttpClient);
/**
* Extract paginated data from API response
*/
protected extractPaginatedData<T>(result: Result<unknown>): Result<PaginatedResponse<T>>;
}
/**
* SMS Resource
*/
declare class SMS extends BaseResource {
/**
* Send an SMS message
*
* @param params - SMS parameters
* @returns SMS message details
*
* @example
* ```typescript
* const { data, error } = await jokoor.sms.send({
* recipientPhone: '+2207123456',
* messageBody: 'Hello from Jokoor!'
* });
* ```
*/
send(params: SendSMSParams): Promise<Result<SMSMessage>>;
/**
* Get SMS message details
*
* @param id - SMS message ID
* @returns SMS message details
*/
get(id: string): Promise<Result<SMSMessage>>;
/**
* List SMS messages
*
* @param options - List options
* @returns Paginated list of SMS messages
*/
list(options?: {
offset?: number;
limit?: number;
status?: "draft" | "queued" | "sending" | "sent" | "delivered" | "failed" | "cancelled";
contactId?: string;
startDate?: string;
endDate?: string;
}): Promise<Result<PaginatedResponse<SMSMessage>>>;
/**
* Resend a failed SMS message
*
* @param id - SMS message ID
* @returns Updated SMS message
*/
resend(id: string): Promise<Result<SMSMessage>>;
/**
* Send a draft SMS message
*
* @param id - Draft SMS message ID
* @param scheduledAt - Optional scheduled time
* @returns SMS message details
*/
sendDraft(id: string, scheduledAt?: string): Promise<Result<SMSMessage>>;
/**
* Batch resend failed messages
*
* @param messageIds - Array of message IDs to resend
* @returns Batch resend results
*/
resendBatch(messageIds: string[]): Promise<Result<{
totalRequested: number;
totalSuccess: number;
totalFailed: number;
totalSkipped: number;
results: Array<{
originalMessageId: string;
newMessageId: string;
success: boolean;
status: string;
error?: string;
}>;
}>>;
}
/**
* SMS Templates Resource
*/
declare class SMSTemplates extends BaseResource {
/**
* Create a new SMS template
*
* @param params - Template parameters
* @returns Created template
*
* @example
* ```typescript
* const { data, error } = await jokoor.smsTemplates.create({
* name: 'Welcome Message',
* body: 'Hello {{name}}, welcome to our service!',
* description: 'Welcome message for new users'
* });
* ```
*/
create(params: CreateSMSTemplateParams): Promise<Result<SMSTemplate>>;
/**
* Get template details
*
* @param id - Template ID
* @returns Template details
*/
get(id: string): Promise<Result<SMSTemplate>>;
/**
* List SMS templates
*
* @param options - List options
* @returns Paginated list of templates
*/
list(options?: {
offset?: number;
limit?: number;
}): Promise<Result<PaginatedResponse<SMSTemplate>>>;
/**
* Update a template
*
* @param id - Template ID
* @param params - Update parameters
* @returns Updated template
*/
update(id: string, params: UpdateSMSTemplateParams): Promise<Result<SMSTemplate>>;
/**
* Delete a template
*
* @param id - Template ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
}
/**
* SMS Contacts Resource
*/
declare class SMSContacts extends BaseResource {
/**
* Create a new contact
*
* @param params - Contact parameters
* @returns Created contact
*
* @example
* ```typescript
* const { data, error } = await jokoor.smsContacts.create({
* phoneNumber: '+2207123456',
* firstName: 'John',
* lastName: 'Doe',
* email: 'john@example.com'
* });
* ```
*/
create(params: CreateSMSContactParams): Promise<Result<SMSContact>>;
/**
* Get contact details
*
* @param id - Contact ID
* @returns Contact details
*/
get(id: string): Promise<Result<SMSContact>>;
/**
* List contacts
*
* @param options - List options
* @returns Paginated list of contacts
*/
list(options?: {
offset?: number;
limit?: number;
groupId?: string;
}): Promise<Result<PaginatedResponse<SMSContact>>>;
/**
* Update a contact
*
* @param id - Contact ID
* @param params - Update parameters
* @returns Updated contact
*/
update(id: string, params: UpdateSMSContactParams): Promise<Result<SMSContact>>;
/**
* Delete a contact
*
* @param id - Contact ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
}
/**
* SMS Contact Groups Resource
*/
declare class SMSContactGroups extends BaseResource {
/**
* Create a new contact group
*
* @param params - Group parameters
* @returns Created group
*
* @example
* ```typescript
* const { data, error } = await jokoor.smsContactGroups.create({
* name: 'VIP Customers',
* description: 'High-value customers'
* });
* ```
*/
create(params: CreateSMSContactGroupParams): Promise<Result<SMSContactGroup>>;
/**
* Get group details
*
* @param id - Group ID
* @returns Group details
*/
get(id: string): Promise<Result<SMSContactGroup>>;
/**
* List contact groups
*
* @param options - List options
* @returns Paginated list of groups
*/
list(options?: {
offset?: number;
limit?: number;
}): Promise<Result<PaginatedResponse<SMSContactGroup>>>;
/**
* Update a group
*
* @param id - Group ID
* @param params - Update parameters
* @returns Updated group
*/
update(id: string, params: UpdateSMSContactGroupParams): Promise<Result<SMSContactGroup>>;
/**
* Delete a group
*
* @param id - Group ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
/**
* Add contacts to a group
*
* @param groupId - Group ID
* @param contactIds - Array of contact IDs to add
* @returns Success result
*/
addContacts(groupId: string, contactIds: string[]): Promise<Result<void>>;
/**
* Remove contacts from a group
*
* @param groupId - Group ID
* @param contactIds - Array of contact IDs to remove
* @returns Success result
*/
removeContacts(groupId: string, contactIds: string[]): Promise<Result<void>>;
}
/**
* SMS Sender IDs Resource
*/
declare class SMSSenderIDs extends BaseResource {
/**
* Apply for a custom sender ID
*
* @param params - Sender ID parameters
* @returns Created sender ID application
*
* @example
* ```typescript
* const { data, error } = await jokoor.smsSenderIds.create({
* senderId: 'MYCOMPANY',
* purpose: 'Business notifications',
* useCase: 'Sending transaction alerts to customers'
* });
* ```
*/
create(params: CreateSenderIDParams): Promise<Result<SMSSenderID>>;
/**
* Get sender ID details
*
* @param id - Sender ID record ID
* @returns Sender ID details
*/
get(id: string): Promise<Result<SMSSenderID>>;
/**
* List sender IDs
*
* @param options - List options
* @returns Paginated list of sender IDs
*/
list(options?: {
offset?: number;
limit?: number;
status?: "pending" | "approved" | "rejected";
}): Promise<Result<PaginatedResponse<SMSSenderID>>>;
/**
* Update a sender ID application
*
* @param id - Sender ID record ID
* @param params - Update parameters
* @returns Updated sender ID
*/
update(id: string, params: UpdateSenderIDParams): Promise<Result<SMSSenderID>>;
/**
* Delete a sender ID
*
* @param id - Sender ID record ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
/**
* Set a sender ID as default
*
* @param id - Sender ID record ID
* @returns Success result
*/
setDefault(id: string): Promise<Result<void>>;
}
/**
* SMS Campaigns Resource
*/
declare class SMSCampaigns extends BaseResource {
/**
* Create a new SMS campaign
*
* @param params - Campaign parameters
* @returns Created campaign
*
* @example
* ```typescript
* const { data, error } = await jokoor.smsCampaigns.create({
* name: 'Flash Sale Alert',
* messageBody: 'Flash sale! 50% off everything today only!',
* groupIds: ['grp_123', 'grp_456']
* });
* ```
*/
create(params: CreateSMSCampaignParams): Promise<Result<SMSCampaign>>;
/**
* Get campaign details
*
* @param id - Campaign ID
* @returns Campaign details
*/
get(id: string): Promise<Result<SMSCampaign>>;
/**
* List campaigns
*
* @param options - List options
* @returns Paginated list of campaigns
*/
list(options?: {
offset?: number;
limit?: number;
status?: "draft" | "scheduled" | "sending" | "completed" | "failed" | "cancelled";
}): Promise<Result<PaginatedResponse<SMSCampaign>>>;
/**
* Update a campaign (only draft campaigns can be updated)
*
* @param id - Campaign ID
* @param params - Update parameters
* @returns Updated campaign
*/
update(id: string, params: UpdateSMSCampaignParams): Promise<Result<SMSCampaign>>;
/**
* Delete a campaign (only draft campaigns can be deleted)
*
* @param id - Campaign ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
/**
* Send a campaign immediately or schedule it
*
* @param id - Campaign ID
* @param scheduledAt - Optional scheduled time
* @returns Updated campaign
*/
send(id: string, scheduledAt?: string): Promise<Result<SMSCampaign>>;
/**
* Send a draft campaign
*
* @param id - Campaign ID
* @param scheduledAt - Optional scheduled time
* @returns Updated campaign
*/
sendDraft(id: string, scheduledAt?: string): Promise<Result<SMSCampaign>>;
/**
* Send campaign asynchronously (for large campaigns)
*
* @param id - Campaign ID
* @param scheduledAt - Optional scheduled time
* @returns Accepted response
*/
sendAsync(id: string, scheduledAt?: string): Promise<Result<{
campaignId: string;
status: string;
message: string;
}>>;
/**
* Get campaign messages
*
* @param id - Campaign ID
* @param options - List options
* @returns Paginated list of campaign messages
*/
getMessages(id: string, options?: {
offset?: number;
limit?: number;
status?: "queued" | "sending" | "sent" | "delivered" | "failed";
}): Promise<Result<PaginatedResponse<SMSMessage>>>;
/**
* Get campaign statistics
*
* @param id - Campaign ID
* @returns Campaign statistics
*/
getStatistics(id: string): Promise<Result<{
campaignId: string;
totalMessages: number;
sent: number;
delivered: number;
failed: number;
pending: number;
totalCost: string;
}>>;
/**
* Resend failed campaign messages
*
* @param id - Campaign ID
* @returns Batch resend results
*/
resendFailed(id: string): Promise<Result<{
totalRequested: number;
totalSuccess: number;
totalFailed: number;
totalSkipped: number;
}>>;
}
/**
* Payment Links Resource
*/
declare class PaymentLinks extends BaseResource {
/**
* Create a new payment link
*
* @param params - Payment link parameters
* @returns Created payment link
*
* @example
* ```typescript
* const { data, error } = await jokoor.paymentLinks.create({
* title: 'Product Purchase',
* description: 'Premium subscription',
* amount: '50.00',
* currency: 'GMD',
* paymentMethods: ['wave', 'card']
* });
* ```
*/
create(params: CreatePaymentLinkParams): Promise<Result<PaymentLink>>;
/**
* Get payment link details
*
* @param id - Payment link ID
* @returns Payment link details
*/
get(id: string): Promise<Result<PaymentLink>>;
/**
* List payment links
*
* @param options - List options
* @returns Paginated list of payment links
*/
list(options?: {
offset?: number;
limit?: number;
status?: "active" | "inactive";
}): Promise<Result<PaginatedResponse<PaymentLink>>>;
/**
* Update a payment link
*
* @param id - Payment link ID
* @param params - Update parameters
* @returns Updated payment link
*/
update(id: string, params: UpdatePaymentLinkParams): Promise<Result<PaymentLink>>;
/**
* Delete a payment link
*
* @param id - Payment link ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
}
/**
* Invoices Resource
*/
declare class Invoices extends BaseResource {
/**
* Create a new invoice
*
* @param params - Invoice parameters
* @returns Created invoice
*
* @example
* ```typescript
* const { data, error } = await jokoor.invoices.create({
* customerEmail: 'customer@example.com',
* customerName: 'John Doe',
* items: [
* { description: 'Consulting Services', quantity: 10, unitPrice: '50.00', amount: '500.00' },
* { description: 'Setup Fee', quantity: 1, unitPrice: '100.00', amount: '100.00' }
* ],
* currency: 'GMD',
* dueDate: '2024-12-31'
* });
* ```
*/
create(params: CreateInvoiceParams): Promise<Result<Invoice>>;
/**
* Get invoice details
*
* @param id - Invoice ID
* @returns Invoice details
*/
get(id: string): Promise<Result<Invoice>>;
/**
* List invoices
*
* @param options - List options
* @returns Paginated list of invoices
*/
list(options?: {
offset?: number;
limit?: number;
status?: "draft" | "open" | "paid" | "cancelled" | "uncollectible";
}): Promise<Result<PaginatedResponse<Invoice>>>;
/**
* Update an invoice (only draft invoices can be updated)
*
* @param id - Invoice ID
* @param params - Update parameters
* @returns Updated invoice
*/
update(id: string, params: UpdateInvoiceParams): Promise<Result<Invoice>>;
/**
* Finalize an invoice (makes it ready to send)
*
* @param id - Invoice ID
* @returns Finalized invoice
*/
finalize(id: string): Promise<Result<Invoice>>;
/**
* Send an invoice to the customer
*
* @param id - Invoice ID
* @returns Success result
*/
send(id: string): Promise<Result<void>>;
/**
* Cancel an invoice
*
* @param id - Invoice ID
* @returns Cancelled invoice
*/
cancel(id: string): Promise<Result<Invoice>>;
/**
* Download invoice PDF
*
* @param id - Invoice ID
* @returns PDF binary data
*/
downloadPDF(id: string): Promise<Result<Blob>>;
/**
* Record a payment against an invoice
*
* @param id - Invoice ID
* @param params - Payment recording parameters
* @returns Updated invoice with payment recorded
*
* @example
* ```typescript
* const { data, error } = await jokoor.invoices.recordPayment('inv_123', {
* amount: '500.00',
* paymentMethod: 'bank_transfer',
* transactionId: 'TXN123456',
* notes: 'Payment received via bank transfer'
* });
* ```
*/
recordPayment(id: string, params: {
amount: string;
paymentMethod: string;
transactionId?: string;
notes?: string;
}): Promise<Result<Invoice>>;
/**
* List all payments recorded against an invoice
*
* @param id - Invoice ID
* @returns List of invoice payments
*
* @example
* ```typescript
* const { data, error } = await jokoor.invoices.listPayments('inv_123');
* ```
*/
listPayments(id: string): Promise<Result<any[]>>;
/**
* Get all payment receipts associated with an invoice
*
* @param id - Invoice ID
* @returns List of receipts for the invoice
*
* @example
* ```typescript
* const { data, error } = await jokoor.invoices.getReceipts('inv_123');
* ```
*/
getReceipts(id: string): Promise<Result<any[]>>;
}
/**
* Checkouts Resource
*/
declare class Checkouts extends BaseResource {
/**
* Create a new checkout session
*
* @param params - Checkout parameters
* @returns Created checkout session
*
* @example
* ```typescript
* // Basic checkout (customer selects payment method)
* const { data, error } = await jokoor.checkouts.create({
* amount: '100.00',
* currency: 'GMD',
* metadata: { orderId: '12345' }
* });
*
* // Checkout with pre-selected payment method (one-step flow)
* const { data, error } = await jokoor.checkouts.create({
* amount: '100.00',
* payment_method: 'wave',
* customer_phone: '+2207654321'
* });
* // data.payment_url will be ready for payment immediately
* ```
*/
create(params: CreateCheckoutParams): Promise<Result<Checkout>>;
/**
* Get checkout session details
*
* @param id - Checkout session ID
* @returns Checkout details
*/
get(id: string): Promise<Result<Checkout>>;
/**
* Cancel a checkout session
*
* @param id - Checkout session ID
* @returns Success result
*/
cancel(id: string): Promise<Result<void>>;
}
/**
* Products Resource
*/
declare class Products extends BaseResource {
/**
* Create a new product
*
* @param params - Product parameters
* @returns Created product
*
* @example
* ```typescript
* const { data, error } = await jokoor.products.create({
* name: 'Premium Subscription',
* description: 'Monthly premium features',
* price: '29.99',
* currency: 'GMD',
* active: true
* });
* ```
*/
create(params: CreateProductParams): Promise<Result<Product>>;
/**
* Get product details
*
* @param id - Product ID
* @returns Product details
*/
get(id: string): Promise<Result<Product>>;
/**
* List products
*
* @param options - List options
* @returns Paginated list of products
*/
list(options?: {
offset?: number;
limit?: number;
active?: boolean;
}): Promise<Result<PaginatedResponse<Product>>>;
/**
* Update a product
*
* @param id - Product ID
* @param params - Update parameters
* @returns Updated product
*/
update(id: string, params: UpdateProductParams): Promise<Result<Product>>;
/**
* Delete a product
*
* @param id - Product ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
}
/**
* Customers Resource
*/
declare class Customers extends BaseResource {
/**
* Create or retrieve a customer
*
* @param params - Customer parameters
* @returns Customer details
*
* @example
* ```typescript
* const { data, error } = await jokoor.customers.create({
* email: 'customer@example.com',
* phone: '+2207123456',
* name: 'John Doe'
* });
* ```
*/
create(params: CreateCustomerParams): Promise<Result<Customer>>;
/**
* Get customer details
*
* @param id - Customer ID
* @returns Customer details
*/
get(id: string): Promise<Result<Customer>>;
/**
* List customers
*
* @param options - List options
* @returns Paginated list of customers
*/
list(options?: {
offset?: number;
limit?: number;
}): Promise<Result<PaginatedResponse<Customer>>>;
/**
* Update a customer
*
* @param id - Customer ID
* @param params - Update parameters
* @returns Updated customer
*/
update(id: string, params: UpdateCustomerParams): Promise<Result<Customer>>;
/**
* Delete a customer
*
* @param id - Customer ID
* @returns Success result
*/
delete(id: string): Promise<Result<void>>;
}
/**
* Transactions Resource
*/
declare class Transactions extends BaseResource {
/**
* Get transaction details
*
* @param id - Transaction ID
* @returns Transaction details
*/
get(id: string): Promise<Result<Transaction>>;
/**
* List transactions
*
* @param options - List options
* @returns Paginated list of transactions
*/
list(options?: {
offset?: number;
limit?: number;
status?: "pending" | "processing" | "completed" | "failed" | "refunded";
startDate?: string;
endDate?: string;
}): Promise<Result<PaginatedResponse<Transaction>>>;
}
/**
* Refunds Resource
*/
declare class Refunds extends BaseResource {
/**
* Create a refund for a transaction
*
* @param transactionId - Transaction ID to refund
* @param params - Refund parameters
* @returns Created refund
*
* @example
* ```typescript
* const { data, error } = await jokoor.refunds.create('txn_123', {
* amount: '50.00', // Optional, defaults to full refund
* reason: 'Customer request'
* });
* ```
*/
create(transactionId: string, params?: CreateRefundParams): Promise<Result<Refund>>;
/**
* Get refund details
*
* @param id - Refund ID
* @returns Refund details
*/
get(id: string): Promise<Result<Refund>>;
/**
* List refunds
*
* @param options - List options
* @returns Paginated list of refunds
*/
list(options?: {
offset?: number;
limit?: number;
}): Promise<Result<PaginatedResponse<Refund>>>;
}
/**
* Subscriptions Resource
*/
declare class Subscriptions extends BaseResource {
/**
* Create a new subscription
*
* @param params - Subscription parameters
* @returns Created subscription
*
* @example
* ```typescript
* const { data, error } = await jokoor.subscriptions.create({
* customerId: 'cus_123',
* currency: 'GMD',
* interval: 'month',
* intervalCount: 1,
* startDate: '2024-12-01',
* items: [{
* description: 'Premium Subscription',
* quantity: 1,
* unitPrice: '29.99'
* }]
* });
* ```
*/
create(params: CreateSubscriptionParams): Promise<Result<Subscription>>;
/**
* Get subscription details
*
* @param id - Subscription ID
* @returns Subscription details
*/
get(id: string): Promise<Result<Subscription>>;
/**
* List subscriptions
*
* @param options - List options
* @returns Paginated list of subscriptions
*/
list(options?: {
offset?: number;
limit?: number;
status?: "active" | "cancelled" | "expired" | "past_due";
}): Promise<Result<PaginatedResponse<Subscription>>>;
/**
* Update a subscription
*
* @param id - Subscription ID
* @param params - Update parameters
* @returns Updated subscription
*/
update(id: string, params: UpdateSubscriptionParams): Promise<Result<Subscription>>;
/**
* Cancel a subscription
*
* @param id - Subscription ID
* @param cancelAtPeriodEnd - If true, subscription remains active until end of current period
* @returns Cancelled subscription
*/
cancel(id: string, cancelAtPeriodEnd?: boolean): Promise<Result<Subscription>>;
/**
* List all invoices generated by a subscription
*
* @param id - Subscription ID
* @param options - List options
* @returns Paginated list of invoices
*
* @example
* ```typescript
* const { data, error } = await jokoor.subscriptions.l