@applite/duticotac 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -0
- package/dist/index.d.mts +291 -0
- package/dist/index.d.ts +291 -0
- package/dist/index.js +347 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +308 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @applite/duticotac
|
|
2
|
+
|
|
3
|
+
A lightweight JavaScript SDK for interacting with Duticotac platform APIs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @applite/duticotac
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Each method accepts a **single object** that always includes `apiKey`, plus fields required by the specific route.
|
|
14
|
+
|
|
15
|
+
### Instantiate the client
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { DuticotacSDK } from "@applite/duticotac";
|
|
19
|
+
|
|
20
|
+
const duticotac = new DuticotacSDK({
|
|
21
|
+
baseUrl: "https://api.example.com", // optional, defaults to relative paths
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Get balance
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
await duticotac.balance.balance({
|
|
29
|
+
apiKey: "api_key_abc",
|
|
30
|
+
appId: "app_123", // optional
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Manage offers
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
// Create an offer
|
|
38
|
+
await duticotac.offer.create({
|
|
39
|
+
apiKey: "api_key_abc",
|
|
40
|
+
appId: "app_123", // optional
|
|
41
|
+
name: "Offer Name",
|
|
42
|
+
ref: "offer-ref",
|
|
43
|
+
price: 1000,
|
|
44
|
+
platform: "DUTICOTAC",
|
|
45
|
+
type: "STATIC", // optional
|
|
46
|
+
description: "Offer description", // optional
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// List offers
|
|
50
|
+
await duticotac.offer.list({
|
|
51
|
+
apiKey: "api_key_abc",
|
|
52
|
+
appId: "app_123", // optional
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Get offer by reference
|
|
56
|
+
await duticotac.offer.get({
|
|
57
|
+
apiKey: "api_key_abc",
|
|
58
|
+
ref: "offer-ref",
|
|
59
|
+
appId: "app_123", // optional
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Update offer
|
|
63
|
+
await duticotac.offer.update({
|
|
64
|
+
apiKey: "api_key_abc",
|
|
65
|
+
ref: "offer-ref",
|
|
66
|
+
appId: "app_123", // optional
|
|
67
|
+
name: "Updated Name", // optional
|
|
68
|
+
price: 1500, // optional
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Delete offer
|
|
72
|
+
await duticotac.offer.delete({
|
|
73
|
+
apiKey: "api_key_abc",
|
|
74
|
+
ref: "offer-ref",
|
|
75
|
+
appId: "app_123", // optional
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Mobile money operations
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
// Cash in
|
|
83
|
+
await duticotac.mobileMoney.cashin({
|
|
84
|
+
apiKey: "api_key_abc",
|
|
85
|
+
appId: "app_123", // optional
|
|
86
|
+
amount: 1000,
|
|
87
|
+
phone: "+2250700000000",
|
|
88
|
+
paymentMethod: "OM_CI",
|
|
89
|
+
password: "password123",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Cash out
|
|
93
|
+
await duticotac.mobileMoney.cashout({
|
|
94
|
+
apiKey: "api_key_abc",
|
|
95
|
+
appId: "app_123", // optional
|
|
96
|
+
transactionId: "txn_123",
|
|
97
|
+
ref: "ref_123",
|
|
98
|
+
phone: "+2250700000000",
|
|
99
|
+
name: "John Doe",
|
|
100
|
+
email: "john@example.com",
|
|
101
|
+
paymentMethod: "OM_CI",
|
|
102
|
+
amount: 1000, // optional
|
|
103
|
+
otp: "1234", // optional
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Payment methods
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// Get payment methods
|
|
111
|
+
await duticotac.paymentMethod.get({
|
|
112
|
+
apiKey: "api_key_abc",
|
|
113
|
+
appId: "app_123", // optional
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Set payment methods
|
|
117
|
+
await duticotac.paymentMethod.set({
|
|
118
|
+
apiKey: "api_key_abc",
|
|
119
|
+
appId: "app_123", // optional
|
|
120
|
+
providers: ["OM_CI", "MTN_CI"],
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Webhooks
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
// Get webhook URL
|
|
128
|
+
await duticotac.webhook.get({
|
|
129
|
+
apiKey: "api_key_abc",
|
|
130
|
+
appId: "app_123", // optional
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Set webhook URL
|
|
134
|
+
await duticotac.webhook.set({
|
|
135
|
+
apiKey: "api_key_abc",
|
|
136
|
+
appId: "app_123", // optional
|
|
137
|
+
url: "https://example.com/webhook",
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Transactions
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
// Get transaction
|
|
145
|
+
await duticotac.transaction.get({
|
|
146
|
+
id: "transaction_id",
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Scripts
|
|
151
|
+
|
|
152
|
+
- `pnpm build` – build CJS/ESM bundles with type declarations.
|
|
153
|
+
- `pnpm dev` – watch mode for development.
|
|
154
|
+
- `pnpm test` – run the build with declaration output to validate types.
|
|
155
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
interface HttpClientConfig {
|
|
2
|
+
/**
|
|
3
|
+
* Base URL used for every request.
|
|
4
|
+
* Defaults to `https://api.applite.freddydro.dev`.
|
|
5
|
+
*/
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Optional headers that should be sent with every request.
|
|
9
|
+
*/
|
|
10
|
+
headers?: HeadersInit;
|
|
11
|
+
/**
|
|
12
|
+
* Custom fetch implementation for environments where the global fetch is
|
|
13
|
+
* not available or needs to be mocked during testing.
|
|
14
|
+
*/
|
|
15
|
+
fetchFn?: typeof fetch;
|
|
16
|
+
/**
|
|
17
|
+
* API key injected into every request body automatically.
|
|
18
|
+
*/
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional app ID injected into every request body automatically.
|
|
22
|
+
*/
|
|
23
|
+
appId?: string | null;
|
|
24
|
+
}
|
|
25
|
+
interface ApiSuccessResponse<T> {
|
|
26
|
+
success: true;
|
|
27
|
+
data: T;
|
|
28
|
+
error?: unknown;
|
|
29
|
+
}
|
|
30
|
+
interface ApiErrorResponse {
|
|
31
|
+
success: false;
|
|
32
|
+
error?: unknown;
|
|
33
|
+
}
|
|
34
|
+
type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|
|
35
|
+
declare class HttpClient {
|
|
36
|
+
private readonly baseUrl;
|
|
37
|
+
private readonly headers;
|
|
38
|
+
private readonly fetchImpl;
|
|
39
|
+
private readonly apiKey?;
|
|
40
|
+
private readonly appId?;
|
|
41
|
+
constructor(config?: HttpClientConfig);
|
|
42
|
+
post<T>(path: string, body: Record<string, unknown> | object): Promise<ApiSuccessResponse<T>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface GetBalanceParams {
|
|
46
|
+
apiKey?: string;
|
|
47
|
+
appId?: string | null;
|
|
48
|
+
}
|
|
49
|
+
declare class BalanceModule {
|
|
50
|
+
private readonly http;
|
|
51
|
+
constructor(http: HttpClient);
|
|
52
|
+
balance(params?: GetBalanceParams): Promise<ApiSuccessResponse<number | null>>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type TransactionStatus = "PENDING" | "CONFIRMED" | "CANCELLED" | "FAILED";
|
|
56
|
+
type PlatformType = "STORE" | "TRANSPORT" | "RESTAURATION" | "MULTI_SERVICE" | "E_LEARNING" | "DUTICOTAC";
|
|
57
|
+
type PaymentProvider = "CASH" | "OM_CI" | "MTN_CI" | "MOOV_CI" | "WAVE_CI" | "CREDIT_CARD" | "IAP";
|
|
58
|
+
type Currency = "USD" | "EUR" | "XOF" | "XAF";
|
|
59
|
+
type CoreApp = "XORAIA" | "MONSMSPRO" | "FREE";
|
|
60
|
+
type DuTicOTacOfferType = "STATIC" | "DYNAMIC";
|
|
61
|
+
/** @deprecated Use `PaymentProvider` instead */
|
|
62
|
+
type PaymentMethod = PaymentProvider;
|
|
63
|
+
/** @deprecated Use `PaymentProvider` instead */
|
|
64
|
+
type TransactionProvider = PaymentProvider;
|
|
65
|
+
/** @deprecated Use `PlatformType` instead */
|
|
66
|
+
type PlateformType = PlatformType;
|
|
67
|
+
|
|
68
|
+
interface OfferModel {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
ref: string;
|
|
72
|
+
price: number;
|
|
73
|
+
description: string;
|
|
74
|
+
platform: string;
|
|
75
|
+
createdAt: string;
|
|
76
|
+
app: OfferAppModel;
|
|
77
|
+
_count: PaymentLinksCountModel;
|
|
78
|
+
}
|
|
79
|
+
interface OfferAppModel {
|
|
80
|
+
id: string;
|
|
81
|
+
duticotacSettings: DuticotacSettingModel[];
|
|
82
|
+
}
|
|
83
|
+
interface DuticotacSettingModel {
|
|
84
|
+
id: string;
|
|
85
|
+
providers: PaymentProvider[];
|
|
86
|
+
}
|
|
87
|
+
interface PaymentLinksCountModel {
|
|
88
|
+
paymentLinks: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface CreateOfferParams {
|
|
92
|
+
apiKey?: string;
|
|
93
|
+
appId?: string | null;
|
|
94
|
+
name: string;
|
|
95
|
+
ref: string;
|
|
96
|
+
price: number;
|
|
97
|
+
platform: PlatformType;
|
|
98
|
+
type?: DuTicOTacOfferType;
|
|
99
|
+
description?: string | null;
|
|
100
|
+
}
|
|
101
|
+
interface ListOffersParams {
|
|
102
|
+
apiKey?: string;
|
|
103
|
+
appId?: string | null;
|
|
104
|
+
}
|
|
105
|
+
interface GetOfferByRefParams {
|
|
106
|
+
apiKey?: string;
|
|
107
|
+
ref: string;
|
|
108
|
+
appId?: string | null;
|
|
109
|
+
}
|
|
110
|
+
interface UpdateOfferParams {
|
|
111
|
+
apiKey?: string;
|
|
112
|
+
ref: string;
|
|
113
|
+
appId?: string | null;
|
|
114
|
+
name?: string | null;
|
|
115
|
+
price?: number | null;
|
|
116
|
+
type?: DuTicOTacOfferType | null;
|
|
117
|
+
description?: string | null;
|
|
118
|
+
platform?: PlatformType | null;
|
|
119
|
+
}
|
|
120
|
+
interface DeleteOfferParams {
|
|
121
|
+
apiKey?: string;
|
|
122
|
+
ref: string;
|
|
123
|
+
appId?: string | null;
|
|
124
|
+
}
|
|
125
|
+
declare class OfferModule {
|
|
126
|
+
private readonly http;
|
|
127
|
+
constructor(http: HttpClient);
|
|
128
|
+
create(params: CreateOfferParams): Promise<ApiSuccessResponse<OfferModel>>;
|
|
129
|
+
list(params?: ListOffersParams): Promise<ApiSuccessResponse<OfferModel[]>>;
|
|
130
|
+
get(params: GetOfferByRefParams): Promise<ApiSuccessResponse<OfferModel>>;
|
|
131
|
+
update(params: UpdateOfferParams): Promise<ApiSuccessResponse<OfferModel>>;
|
|
132
|
+
delete(params: DeleteOfferParams): Promise<ApiSuccessResponse<unknown>>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface TransactionModel {
|
|
136
|
+
id: string;
|
|
137
|
+
ref: string;
|
|
138
|
+
productId?: string | null;
|
|
139
|
+
offerId?: string | null;
|
|
140
|
+
idFromClient?: string | null;
|
|
141
|
+
token: string;
|
|
142
|
+
provider: PaymentProvider;
|
|
143
|
+
amount: number;
|
|
144
|
+
fees: number;
|
|
145
|
+
platform: PlatformType;
|
|
146
|
+
status: TransactionStatus;
|
|
147
|
+
appId: string;
|
|
148
|
+
customerId: string;
|
|
149
|
+
currency: string;
|
|
150
|
+
createdAt: string;
|
|
151
|
+
updatedAt: string;
|
|
152
|
+
paymentUrl?: string | null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface CashInParams {
|
|
156
|
+
apiKey?: string;
|
|
157
|
+
appId?: string | null;
|
|
158
|
+
amount: number;
|
|
159
|
+
phone: string;
|
|
160
|
+
paymentMethod: PaymentProvider;
|
|
161
|
+
password: string;
|
|
162
|
+
country?: string;
|
|
163
|
+
currency?: string;
|
|
164
|
+
}
|
|
165
|
+
interface CashOutParams {
|
|
166
|
+
apiKey?: string;
|
|
167
|
+
appId?: string | null;
|
|
168
|
+
transactionId: string;
|
|
169
|
+
amount?: number | null;
|
|
170
|
+
ref?: string;
|
|
171
|
+
phone: string;
|
|
172
|
+
name: string;
|
|
173
|
+
email: string;
|
|
174
|
+
otp?: string | null;
|
|
175
|
+
paymentMethod: PaymentProvider;
|
|
176
|
+
plateform?: PlatformType;
|
|
177
|
+
customerId?: string | null;
|
|
178
|
+
kolaboReference?: string | null;
|
|
179
|
+
idFromClient?: string | null;
|
|
180
|
+
app?: CoreApp;
|
|
181
|
+
country?: string;
|
|
182
|
+
currency?: string;
|
|
183
|
+
}
|
|
184
|
+
interface CashInWebhookParams {
|
|
185
|
+
apiKey?: string;
|
|
186
|
+
appId?: string | null;
|
|
187
|
+
service_id: string;
|
|
188
|
+
gu_transaction_id: string;
|
|
189
|
+
status: "FAILED" | "SUCCESSFUL";
|
|
190
|
+
partner_transaction_id: string;
|
|
191
|
+
call_back_url: string;
|
|
192
|
+
commission?: number | null;
|
|
193
|
+
message?: string | null;
|
|
194
|
+
}
|
|
195
|
+
interface CashOutWebhookParams {
|
|
196
|
+
apiKey?: string;
|
|
197
|
+
appId?: string | null;
|
|
198
|
+
service_id: string;
|
|
199
|
+
gu_transaction_id: string;
|
|
200
|
+
status: "FAILED" | "SUCCESSFUL";
|
|
201
|
+
partner_transaction_id: string;
|
|
202
|
+
call_back_url: string;
|
|
203
|
+
commission?: number | null;
|
|
204
|
+
message?: string | null;
|
|
205
|
+
}
|
|
206
|
+
declare class MobileMoneyModule {
|
|
207
|
+
private readonly http;
|
|
208
|
+
constructor(http: HttpClient);
|
|
209
|
+
cashin(params: CashInParams): Promise<ApiSuccessResponse<TransactionModel>>;
|
|
210
|
+
cashout(params: CashOutParams): Promise<ApiSuccessResponse<TransactionModel>>;
|
|
211
|
+
handleCashinWebhook(params: CashInWebhookParams): Promise<ApiSuccessResponse<unknown>>;
|
|
212
|
+
handleCashoutWebhook(params: CashOutWebhookParams): Promise<ApiSuccessResponse<unknown>>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface GetPaymentMethodsParams {
|
|
216
|
+
apiKey?: string;
|
|
217
|
+
appId?: string | null;
|
|
218
|
+
}
|
|
219
|
+
interface SetPaymentMethodsParams {
|
|
220
|
+
apiKey?: string;
|
|
221
|
+
appId?: string | null;
|
|
222
|
+
providers: PaymentProvider[];
|
|
223
|
+
}
|
|
224
|
+
declare class PaymentMethodModule {
|
|
225
|
+
private readonly http;
|
|
226
|
+
constructor(http: HttpClient);
|
|
227
|
+
get(params?: GetPaymentMethodsParams): Promise<ApiSuccessResponse<PaymentProvider[]>>;
|
|
228
|
+
set(params: SetPaymentMethodsParams): Promise<ApiSuccessResponse<PaymentProvider[]>>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
interface GetWebhookParams {
|
|
232
|
+
apiKey?: string;
|
|
233
|
+
appId?: string | null;
|
|
234
|
+
}
|
|
235
|
+
interface SetWebhookParams {
|
|
236
|
+
apiKey?: string;
|
|
237
|
+
appId?: string | null;
|
|
238
|
+
url: string;
|
|
239
|
+
}
|
|
240
|
+
declare class WebhookModule {
|
|
241
|
+
private readonly http;
|
|
242
|
+
constructor(http: HttpClient);
|
|
243
|
+
get(params?: GetWebhookParams): Promise<ApiSuccessResponse<string>>;
|
|
244
|
+
set(params: SetWebhookParams): Promise<ApiSuccessResponse<unknown>>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface GetTransactionParams {
|
|
248
|
+
id: string;
|
|
249
|
+
}
|
|
250
|
+
interface PollOptions {
|
|
251
|
+
/** Minimum interval between polls in ms. Default: 2000 */
|
|
252
|
+
intervalMs?: number;
|
|
253
|
+
/** Total timeout in ms. Default: 90000 (90s) */
|
|
254
|
+
timeoutMs?: number;
|
|
255
|
+
/** Called on each poll attempt */
|
|
256
|
+
onPoll?: (attempt: number, elapsedMs: number) => void;
|
|
257
|
+
/** AbortSignal to cancel polling externally */
|
|
258
|
+
signal?: AbortSignal;
|
|
259
|
+
}
|
|
260
|
+
declare class TransactionModule {
|
|
261
|
+
private readonly http;
|
|
262
|
+
constructor(http: HttpClient);
|
|
263
|
+
get(params: GetTransactionParams): Promise<ApiSuccessResponse<TransactionModel>>;
|
|
264
|
+
poll(id: string, options?: PollOptions): Promise<ApiSuccessResponse<TransactionModel>>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare class DuticotacError extends Error {
|
|
268
|
+
readonly code: string;
|
|
269
|
+
constructor(code: string, message?: string);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare const ERROR_MESSAGES: Record<string, string>;
|
|
273
|
+
declare function getErrorMessage(code: string): string;
|
|
274
|
+
|
|
275
|
+
declare function getProviderName(provider: PaymentProvider): string;
|
|
276
|
+
declare function getProviderLogo(provider: PaymentProvider): string;
|
|
277
|
+
|
|
278
|
+
interface DuticotacSDKConfig extends HttpClientConfig {
|
|
279
|
+
}
|
|
280
|
+
declare class DuticotacSDK {
|
|
281
|
+
readonly http: HttpClient;
|
|
282
|
+
readonly balance: BalanceModule;
|
|
283
|
+
readonly offer: OfferModule;
|
|
284
|
+
readonly mobileMoney: MobileMoneyModule;
|
|
285
|
+
readonly paymentMethod: PaymentMethodModule;
|
|
286
|
+
readonly webhook: WebhookModule;
|
|
287
|
+
readonly transaction: TransactionModule;
|
|
288
|
+
constructor(config?: DuticotacSDKConfig);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export { type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, BalanceModule, type CashInParams, type CashInWebhookParams, type CashOutParams, type CashOutWebhookParams, type CoreApp, type CreateOfferParams, type Currency, type DeleteOfferParams, type DuTicOTacOfferType, DuticotacError, DuticotacSDK, type DuticotacSDKConfig, type DuticotacSettingModel, ERROR_MESSAGES, type GetBalanceParams, type GetOfferByRefParams, type GetPaymentMethodsParams, type GetTransactionParams, type GetWebhookParams, HttpClient, type HttpClientConfig, type ListOffersParams, MobileMoneyModule, type OfferAppModel, type OfferModel, OfferModule, type PaymentLinksCountModel, type PaymentMethod, PaymentMethodModule, type PaymentProvider, type PlateformType, type PlatformType, type PollOptions, type SetPaymentMethodsParams, type SetWebhookParams, type TransactionModel, TransactionModule, type TransactionProvider, type TransactionStatus, type UpdateOfferParams, WebhookModule, getErrorMessage, getProviderLogo, getProviderName };
|