monime-package 1.0.0 → 1.0.3

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 CHANGED
@@ -1,165 +1,218 @@
1
1
 
2
2
  # monime-package
3
3
 
4
- A focused TypeScript helper library for interacting with Monime's common endpoints. It provides small, typed helpers that handle request composition, headers, and basic response/error plumbing so your application code stays clean.
5
-
4
+ A **TypeScript SDK for Monime**, providing a lightweight, typed client for common Monime endpoints. Simplifies requests, headers, and error handling so your code stays clean and type-safe.
6
5
 
7
6
  ![TypeScript](https://img.shields.io/badge/TypeScript-4.9-blue.svg)
8
7
  ![Node.js](https://img.shields.io/badge/Node.js-%3E=14-green.svg)
8
+ ![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)
9
9
 
10
+ Package: `monime-package`
10
11
 
11
- Package name: `monime-package`
12
-
13
- ## Table of contents
12
+ ---
14
13
 
15
- - [Description](#description)
16
- - [Features](#features)
17
- - [Installation](#installation)
18
- - [Quick start](#quick-start)
19
- - [API reference](#api-reference)
20
- - [Examples](#examples)
21
- - [Folder structure](#folder-structure)
22
- - [Configuration & env](#configuration--env)
23
- - [Troubleshooting](#troubleshooting)
24
- - [Contributing](#contributing)
25
- - [License](#license)
14
+ ## Table of Contents
26
15
 
27
- ## Description
16
+ * [Features](#features)
17
+ * [Installation](#installation)
18
+ * [Environment Variables](#environment-variables)
19
+ * [Quick Start](#quick-start)
20
+ * [Client API](#client-api)
21
+ * [Examples](#examples)
22
+ * [Migration from Old Helpers](#migration-from-old-helpers)
23
+ * [Folder Structure](#folder-structure)
24
+ * [Error Handling](#error-handling)
25
+ * [Contributing](#contributing)
26
+ * [License](#license)
28
27
 
29
- monime-package wraps a subset of Monime endpoints into a tiny, typed client suitable for server-side Node.js use. It's intentionally small — the package focuses on convenience functions you can call directly from services, lambdas, or scripts.
28
+ ---
30
29
 
31
30
  ## Features
32
31
 
33
- - Lightweight wrapper around Monime endpoints
34
- - TypeScript-first: exported types for request/response shapes
35
- - Predictable return shape: { success: boolean, data?, error? }
36
- - Small dependency surface (axios)
32
+ * Full **TypeScript support** with typed request/response objects
33
+ * Lightweight client wrapper around Monime endpoints
34
+ * Predictable return shape: `{ success: boolean, data?, error? }`
35
+ * Single client instance handles credentials automatically
36
+ * Minimal dependencies (`axios` only)
37
37
 
38
- ## Installation
38
+ ---
39
39
 
40
- Install with npm or pnpm:
40
+ ## Installation
41
41
 
42
42
  ```bash
43
43
  npm install monime-package
44
+ # or
45
+ pnpm add monime-package
44
46
  ```
45
47
 
46
- or
48
+ ---
49
+
50
+ ## Environment Variables
51
+
52
+ Recommended to store credentials in `.env`:
47
53
 
48
54
  ```bash
49
- pnpm add monime-package
55
+ MONIME_SPACE_ID=space_XXXXXXXX
56
+ MONIME_ACCESS_TOKEN=sk_live_xxx
50
57
  ```
51
58
 
52
- ## Quick start
59
+ You can also pass credentials directly when creating the client.
53
60
 
54
- 1. Add your credentials to environment variables (recommended) or pass them directly to the functions.
55
- 2. Import the helpers and call them.
61
+ ---
56
62
 
57
- Example (TypeScript):
63
+ ## Quick Start
64
+
65
+ ### Create a client
58
66
 
59
67
  ```ts
60
- import {
61
- createFinancialAccount,
62
- createPaymentCode,
63
- createInternalTransfer,
64
- getFinancialAccount,
65
- deletePaymentCode,
66
- CreatePayoutMobileMoney,
67
- } from 'monime-package'
68
-
69
- async function demo() {
70
- const MONIME_SPACE_ID = process.env.MONIME_SPACE_ID!
71
- const MONIME_ACCESS_TOKEN = process.env.MONIME_ACCESS_TOKEN!
72
-
73
- // Create a financial account
74
- const createRes = await createFinancialAccount('My App Account', MONIME_SPACE_ID, MONIME_ACCESS_TOKEN)
75
- if (!createRes.success) throw createRes.error
76
-
77
- const accountId = createRes.data?.result?.id
78
- console.log('Created account id', accountId)
79
- }
68
+ import { createClient } from 'monime-package'
80
69
 
81
- demo().catch(err => console.error(err))
70
+ const client = createClient({
71
+ monimeSpaceeId: process.env.MONIME_SPACE_ID!,
72
+ accessToken: process.env.MONIME_ACCESS_TOKEN!,
73
+ })
82
74
  ```
83
75
 
84
- ## API reference
76
+ Now all methods automatically use the client’s credentials.
85
77
 
86
- All functions return a Promise resolving to an object with the following minimal shape:
78
+ ---
79
+
80
+ ## Client API
81
+
82
+ All methods return:
87
83
 
88
84
  ```ts
89
85
  type Result<T> = {
90
86
  success: boolean
91
87
  data?: T
92
- error?: any
88
+ error?: Error
93
89
  }
94
90
  ```
95
91
 
96
- Top-level exports (signatures simplified):
92
+ ### Financial Accounts
97
93
 
98
- - createFinancialAccount(accountName: string, monime_space_id: string, monime_access_token: string): Promise<Result<CreateFinancialAccount>>
99
- - getFinancialAccount(financialAccountId: string, monime_access_token: string, monime_space_id: string): Promise<Result<GetFinancialAccount>>
100
- - createInternalTransfer(sourceAccount: string, destinationAccount: string, monime_access_token: string, monime_space_id: string, value: number): Promise<Result<CreateInternalTransfer>>
101
- - createPaymentCode(paymentName: string, amount: number, financialAccountId: string | null, name: string, phoneNumber: string, monime_access_token: string, monime_space_id: string): Promise<Result<{ code?: string }>>
102
- - deletePaymentCode(paymentCodeId: string, monime_access_token: string, monime_space_id: string): Promise<Result<null>>
103
- - CreatePayoutMobileMoney(amount: number, phoneNumber: string, sourceAccount: string, monime_access_token: string, monime_space_id: string): Promise<Result<CreatePayout>>
94
+ ```ts
95
+ client.createFinancialAccount(name: string): Promise<Result<CreateFinancialAccount>>
96
+ client.getFinancialAccount(financialAccountId: string): Promise<Result<GetFinancialAccount>>
97
+ ```
98
+
99
+ ### Internal Transfers
100
+
101
+ ```ts
102
+ client.createInternalTransfer(
103
+ sourceAccount: string,
104
+ destinationAccount: string,
105
+ amount: number
106
+ ): Promise<Result<CreateInternalTransfer>>
107
+ ```
108
+
109
+ ### Payment Codes
110
+
111
+ ```ts
112
+ client.createPaymentCode(
113
+ paymentName: string,
114
+ amount: number,
115
+ financialAccount: string,
116
+ username: string,
117
+ phoneNumber: string
118
+ ): Promise<Result<CreatePaymentCode>>
119
+
120
+ client.deletePaymentCode(paymentCodeId: string): Promise<Result<DeletePaymentCode>>
121
+ ```
104
122
 
105
- Refer to `src/functions/*Types.ts` for full TypeScript interfaces.
123
+ ### Payouts
106
124
 
107
- ### Important behaviors
125
+ ```ts
126
+ client.createPayout(
127
+ amount: number,
128
+ phoneNumber: string,
129
+ sourceAccount: string
130
+ ): Promise<Result<CreatePayout>>
131
+ ```
108
132
 
109
- - createPaymentCode: input `amount` is multiplied by 100 before being sent (to match Monime's expected minor currency units).
110
- - createPaymentCode: passing `financialAccountId` as an empty string results in `financialAccountId` being omitted from the request body.
111
- - CreatePayoutMobileMoney: provider is inferred from phone number prefixes; check `src/functions/payout.ts` for the exact rules.
112
- - Error responses: network/API errors may come back as axios error objects or the remote response body — handle both.
133
+ > Provider is inferred automatically from the phone number prefix.
134
+
135
+ ---
113
136
 
114
137
  ## Examples
115
138
 
116
- Create a payment code and handle errors gracefully:
139
+ ### Create a financial account
117
140
 
118
141
  ```ts
119
- import { createPaymentCode } from 'monime-package'
120
-
121
- async function createCode() {
122
- const res = await createPaymentCode('Order-001', 5, 'financial-account-id', 'Alice', '0771234567', process.env.MONIME_ACCESS_TOKEN!, process.env.MONIME_SPACE_ID!)
123
- if (!res.success) {
124
- console.error('Failed to create payment code', res.error)
125
- return
126
- }
127
- console.log('USSD code:', res.code)
128
- }
142
+ const account = await client.createFinancialAccount('App Wallet')
143
+ if (!account.success) throw account.error
144
+ console.log(account.data)
129
145
  ```
130
146
 
131
- Create an internal transfer:
147
+ ### Get account details
132
148
 
133
149
  ```ts
134
- import { createInternalTransfer } from 'monime-package'
150
+ const details = await client.getFinancialAccount(account.data!.result.id)
151
+ console.log(details)
152
+ ```
135
153
 
136
- const t = await createInternalTransfer('acc-src', 'acc-dest', process.env.MONIME_ACCESS_TOKEN!, process.env.MONIME_SPACE_ID!, 1500)
137
- if (!t.success) console.error('transfer error', t.error)
138
- else console.log('transfer result', t.data)
154
+ ### Internal transfer
155
+
156
+ ```ts
157
+ const transfer = await client.createInternalTransfer('acc-src', 'acc-dest', 5000)
158
+ if (!transfer.success) console.error(transfer.error)
159
+ else console.log(transfer.data)
160
+ ```
161
+
162
+ ### Create payment code
163
+
164
+ ```ts
165
+ const code = await client.createPaymentCode('Order-001', 5, 'financial-account-id', 'Alice', '0771234567')
166
+ if (!code.success) console.error(code.error)
167
+ else console.log('Payment code:', code.data)
168
+ ```
169
+
170
+ ### Delete payment code
171
+
172
+ ```ts
173
+ const deleted = await client.deletePaymentCode('payment-code-id')
174
+ console.log(deleted.success)
175
+ ```
176
+
177
+ ### Payout (mobile money)
178
+
179
+ ```ts
180
+ const payout = await client.createPayout(1000, '0771234567', 'source-account-id')
181
+ if (!payout.success) console.error(payout.error)
182
+ else console.log('Payout:', payout.data)
139
183
  ```
140
184
 
141
- Payout (note: set `src/functions/payout.ts` URL before use):
185
+ ---
186
+
187
+ ## Migration from Old Helpers
188
+
189
+ Previously, you had to pass `monimeSpaceId` and `accessToken` into every function:
142
190
 
143
191
  ```ts
144
- import { CreatePayoutMobileMoney } from 'monime-package'
192
+ createFinancialAccount('name', MONIME_SPACE_ID, MONIME_ACCESS_TOKEN)
193
+ ```
194
+
195
+ Now, create a client once:
145
196
 
146
- const p = await CreatePayoutMobileMoney(1000, '0771234567', 'source-account-id', process.env.MONIME_ACCESS_TOKEN!, process.env.MONIME_SPACE_ID!)
147
- if (!p.success) console.error(p.error)
148
- else console.log('payout', p.data)
197
+ ```ts
198
+ const client = createClient({ monimeSpaceeId, accessToken })
199
+ client.createFinancialAccount('name') // credentials auto-applied
149
200
  ```
150
201
 
151
- ## Folder structure
202
+ ---
203
+
204
+ ## Folder Structure
152
205
 
153
206
  ```
154
- .
207
+ .
155
208
  ├── LICENSE
156
209
  ├── README.md
157
210
  ├── package.json
158
211
  ├── tsconfig.json
159
212
  ├── tsup.config.ts
160
213
  ├── src
161
- │ ├── index.ts # re-exports
162
- │ └── functions
214
+ │ ├── index.ts # entry point
215
+ │ └── modules
163
216
  │ ├── financialAccount.ts
164
217
  │ ├── financialAccountTypes.ts
165
218
  │ ├── internalTransfer.ts
@@ -170,31 +223,34 @@ else console.log('payout', p.data)
170
223
  │ └── payoutTypes.ts
171
224
  ```
172
225
 
173
- ## Configuration & env
174
-
175
- Recommended environment variables (you can store them in `.env` during development):
226
+ ---
176
227
 
177
- ```
178
- MONIME_SPACE_ID=space_XXXXXXXX
179
- MONIME_ACCESS_TOKEN=sk_live_xxx
180
- ```
228
+ ## Error Handling
181
229
 
182
- ## Troubleshooting
230
+ * Network/API errors are returned as `error` in the `{ success, data?, error? }` object.
231
+ * Use `axios.isAxiosError(error)` to inspect response details if needed.
183
232
 
184
- - Empty or invalid credentials: most functions will log or return an error if `monime_space_id` or `monime_access_token` are missing. Always validate env vars before calling the helpers.
185
- - Network errors: axios errors are returned directly in some functions. Use `axios.isAxiosError` to inspect `error.response` and `error.response.data`.
186
- - Payouts: if payout calls fail unexpectedly, check `src/functions/payout.ts` — its `URL` constant is empty and must be configured.
233
+ ---
187
234
 
188
235
  ## Contributing
189
236
 
190
- Contributions appreciated. Suggested small first PRs:
191
237
 
192
- - Add an `examples/` folder with a safe demo script that reads env vars and shows each helper.
193
- - Add tests using `vitest` or `jest` with `nock` or axios mocking.
194
- - Normalize returned errors to a consistent shape.
238
+ We welcome contributions.
195
239
 
196
- When opening a PR, include a short description and tests for new behavior.
240
+ ### Getting Started
241
+ 1. **Fork the repository** on GitHub
242
+ 2. **Clone your fork** locally
243
+ 3. **Create a feature branch** from `main`
244
+ 4. **Make your changes** following our coding conventions
245
+ 5. **Test your changes** thoroughly
246
+ 6. **Submit a pull request** with a clear description
247
+
248
+ For detailed contribution guidelines, see [CONTRIBUTING.md](./CONTRIBUTING.md)
249
+
250
+ ---
197
251
 
198
252
  ## License
199
253
 
200
- MIT — see `LICENSE`.
254
+ MIT — see [LICENSE](./LICENSE).
255
+
256
+ ---
package/dist/index.d.mts CHANGED
@@ -1,14 +1,14 @@
1
1
  interface CreateFinancialAccount {
2
2
  success: boolean;
3
3
  messages: string[];
4
- result: Result$2;
4
+ result: Result$3;
5
5
  }
6
6
  interface GetFinancialAccount {
7
7
  success: boolean;
8
8
  messages: string[];
9
- result: Result$2;
9
+ result: Result$3;
10
10
  }
11
- interface Result$2 {
11
+ interface Result$3 {
12
12
  id: string;
13
13
  uvan: string;
14
14
  name: string;
@@ -20,7 +20,7 @@ interface Result$2 {
20
20
  updateTime: string;
21
21
  metadata: Metadata$2;
22
22
  }
23
- interface Result$2 {
23
+ interface Result$3 {
24
24
  id: string;
25
25
  uvan: string;
26
26
  name: string;
@@ -51,25 +51,12 @@ interface Available {
51
51
  value: number;
52
52
  }
53
53
 
54
- interface createFinancialAccountReturn {
55
- data?: CreateFinancialAccount;
56
- error?: Error;
57
- success: boolean;
58
- }
59
- declare function createFinancialAccount(accountName: string, monime_space_id: string, monime_access_token: string): Promise<createFinancialAccountReturn>;
60
- interface GetFinancialAccountReturn {
61
- data?: GetFinancialAccount;
62
- error?: Error;
63
- success: boolean;
64
- }
65
- declare function getFinancialAccount(financialAccountId: string, monime_access_token: string, monime_space_id: string): Promise<GetFinancialAccountReturn>;
66
-
67
54
  interface CreateInternalTransfer {
68
55
  success: boolean;
69
56
  messages: string[];
70
- result: Result$1;
57
+ result: Result$2;
71
58
  }
72
- interface Result$1 {
59
+ interface Result$2 {
73
60
  id: string;
74
61
  status: string;
75
62
  amount: Amount$1;
@@ -78,12 +65,12 @@ interface Result$1 {
78
65
  financialTransactionReference: string;
79
66
  description: string;
80
67
  failureDetail: FailureDetail$1;
81
- ownershipGraph: OwnershipGraph$1;
68
+ ownershipGraph: OwnershipGraph$2;
82
69
  createTime: string;
83
70
  updateTime: string;
84
71
  metadata: Metadata$1;
85
72
  }
86
- interface OwnershipGraph$1 {
73
+ interface OwnershipGraph$2 {
87
74
  owner: Owner2$1;
88
75
  }
89
76
  interface Owner2$1 {
@@ -112,20 +99,72 @@ interface Amount$1 {
112
99
  value: number;
113
100
  }
114
101
 
115
- interface Return$2 {
116
- data?: CreateInternalTransfer;
117
- error?: Error;
102
+ interface CreatePaymentCode {
118
103
  success: boolean;
104
+ messages: string[];
105
+ result: Result$1;
119
106
  }
120
- declare function createInternalTransfer(sourceAccount: string, destinationAccount: string, monime_access_token: string, monime_space_id: string, value: number): Promise<Return$2>;
121
-
122
- interface Return$1 {
123
- code?: string;
124
- error?: Error;
125
- success: boolean;
107
+ interface Result$1 {
108
+ id: string;
109
+ mode: string;
110
+ status: string;
111
+ name: string;
112
+ amount: {
113
+ currency: string;
114
+ value: number;
115
+ };
116
+ enable: boolean;
117
+ expireTime: string;
118
+ customer: {
119
+ name: string;
120
+ };
121
+ ussdCode: string;
122
+ reference: string;
123
+ authorizedProviders: string[];
124
+ authorizedPhoneNumber: string;
125
+ recurrentPaymentTarget: {
126
+ expectedPaymentCount: number;
127
+ expectedPaymentTotal: {
128
+ currency: string;
129
+ value: number;
130
+ };
131
+ };
132
+ financialAccountId: string;
133
+ processedPaymentData: ProcessedPaymentData;
134
+ createTime: string;
135
+ updateTime: string;
136
+ ownershipGraph: OwnershipGraph$1;
137
+ metadata: {};
138
+ }
139
+ interface OwnershipGraph$1 {
140
+ owner: {
141
+ id: string;
142
+ type: string;
143
+ metadata: {};
144
+ owner: {
145
+ id: string;
146
+ type: string;
147
+ metadata: {};
148
+ owner: {};
149
+ };
150
+ };
151
+ }
152
+ interface ProcessedPaymentData {
153
+ amount: {
154
+ currency: string;
155
+ value: number;
156
+ };
157
+ orderId: string;
158
+ paymentId: string;
159
+ orderNumber: string;
160
+ channelData: {
161
+ providerId: string;
162
+ accountId: string;
163
+ reference: string;
164
+ };
165
+ financialTransactionReference: string;
166
+ metadata: {};
126
167
  }
127
- declare function createPaymentCode(paymentName: string, amount: number, financialAccountId: string | null, name: string, phoneNumber: string, monime_access_token: string, monime_space_id: string): Promise<Return$1>;
128
- declare function deletePaymentCode(paymentCodeId: string, monime_access_token: string, monime_space_id: string): Promise<Return$1>;
129
168
 
130
169
  interface CreatePayout {
131
170
  success: boolean;
@@ -186,11 +225,50 @@ interface Amount {
186
225
  value: number;
187
226
  }
188
227
 
189
- interface Return {
190
- data?: CreatePayout;
191
- error?: Error;
192
- success: boolean;
228
+ interface ClientOptions {
229
+ monimeSpaceeId: string;
230
+ accessToken: string;
231
+ }
232
+ declare class MonimeClient {
233
+ private monimeSpaceId;
234
+ private accessToken;
235
+ createFinancialAccount: (name: string) => Promise<{
236
+ success: boolean;
237
+ data?: CreateFinancialAccount;
238
+ error?: Error;
239
+ }>;
240
+ getFinancialAccount: (financialAccountId: string) => Promise<{
241
+ success: boolean;
242
+ data?: GetFinancialAccount;
243
+ error?: Error;
244
+ }>;
245
+ createInternalTransfer: (sourceAccount: string, destinationAccount: string, amount: number) => Promise<{
246
+ success: boolean;
247
+ data?: CreateInternalTransfer;
248
+ error?: Error;
249
+ }>;
250
+ createPaymentCode: (paymentName: string, amount: number, financialAccount: string, username: string, phoneNumber: string) => Promise<{
251
+ success: boolean;
252
+ error?: Error;
253
+ data?: CreatePaymentCode;
254
+ }>;
255
+ deletePaymentCode: (paymentCodeId: string) => Promise<{
256
+ success: boolean;
257
+ error?: Error;
258
+ data?: CreatePaymentCode;
259
+ }>;
260
+ createPayout: (amount: number, phoneNumber: string, sourceAccount: string) => Promise<{
261
+ success: boolean;
262
+ error?: Error;
263
+ data?: CreatePayout;
264
+ }>;
265
+ constructor(options: ClientOptions);
266
+ _getConfig(): {
267
+ monimeSpaceId: string;
268
+ accessToken: string;
269
+ };
193
270
  }
194
- declare function CreatePayoutMobileMoney(amount: number, phoneNumber: string, sourceAccount: string, monime_access_token: string, monime_space_id: string): Promise<Return>;
195
271
 
196
- export { CreatePayoutMobileMoney, createFinancialAccount, createInternalTransfer, createPaymentCode, deletePaymentCode, getFinancialAccount };
272
+ declare function createClient(options: ClientOptions): MonimeClient;
273
+
274
+ export { type ClientOptions, MonimeClient, createClient };