monime-package 0.0.1 → 1.0.2

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,163 +1,218 @@
1
1
 
2
2
  # monime-package
3
3
 
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.
5
+
4
6
  ![TypeScript](https://img.shields.io/badge/TypeScript-4.9-blue.svg)
5
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)
6
9
 
7
- 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.
8
-
9
- Package name: `monime-package`
10
+ Package: `monime-package`
10
11
 
11
- ## Table of contents
12
+ ---
12
13
 
13
- - [Description](#description)
14
- - [Features](#features)
15
- - [Installation](#installation)
16
- - [Quick start](#quick-start)
17
- - [API reference](#api-reference)
18
- - [Examples](#examples)
19
- - [Folder structure](#folder-structure)
20
- - [Configuration & env](#configuration--env)
21
- - [Troubleshooting](#troubleshooting)
22
- - [Contributing](#contributing)
23
- - [License](#license)
14
+ ## Table of Contents
24
15
 
25
- ## 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)
26
27
 
27
- 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
+ ---
28
29
 
29
30
  ## Features
30
31
 
31
- - Lightweight wrapper around Monime endpoints
32
- - TypeScript-first: exported types for request/response shapes
33
- - Predictable return shape: { success: boolean, data?, error? }
34
- - 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)
35
37
 
36
- ## Installation
38
+ ---
37
39
 
38
- Install with npm or pnpm:
40
+ ## Installation
39
41
 
40
42
  ```bash
41
43
  npm install monime-package
44
+ # or
45
+ pnpm add monime-package
42
46
  ```
43
47
 
44
- or
48
+ ---
49
+
50
+ ## Environment Variables
51
+
52
+ Recommended to store credentials in `.env`:
45
53
 
46
54
  ```bash
47
- pnpm add monime-package
55
+ MONIME_SPACE_ID=space_XXXXXXXX
56
+ MONIME_ACCESS_TOKEN=sk_live_xxx
48
57
  ```
49
58
 
50
- ## Quick start
59
+ You can also pass credentials directly when creating the client.
51
60
 
52
- 1. Add your credentials to environment variables (recommended) or pass them directly to the functions.
53
- 2. Import the helpers and call them.
61
+ ---
54
62
 
55
- Example (TypeScript):
63
+ ## Quick Start
64
+
65
+ ### Create a client
56
66
 
57
67
  ```ts
58
- import {
59
- createFinancialAccount,
60
- createPaymentCode,
61
- createInternalTransfer,
62
- getFinancialAccount,
63
- deletePaymentCode,
64
- CreatePayoutMobileMoney,
65
- } from 'monime-package'
66
-
67
- async function demo() {
68
- const MONIME_SPACE_ID = process.env.MONIME_SPACE_ID!
69
- const MONIME_ACCESS_TOKEN = process.env.MONIME_ACCESS_TOKEN!
70
-
71
- // Create a financial account
72
- const createRes = await createFinancialAccount('My App Account', MONIME_SPACE_ID, MONIME_ACCESS_TOKEN)
73
- if (!createRes.success) throw createRes.error
74
-
75
- const accountId = createRes.data?.result?.id
76
- console.log('Created account id', accountId)
77
- }
68
+ import { createClient } from 'monime-package'
78
69
 
79
- 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
+ })
80
74
  ```
81
75
 
82
- ## API reference
76
+ Now all methods automatically use the client’s credentials.
83
77
 
84
- All functions return a Promise resolving to an object with the following minimal shape:
78
+ ---
79
+
80
+ ## Client API
81
+
82
+ All methods return:
85
83
 
86
84
  ```ts
87
85
  type Result<T> = {
88
86
  success: boolean
89
87
  data?: T
90
- error?: any
88
+ error?: Error
91
89
  }
92
90
  ```
93
91
 
94
- Top-level exports (signatures simplified):
92
+ ### Financial Accounts
95
93
 
96
- - createFinancialAccount(accountName: string, monime_space_id: string, monime_access_token: string): Promise<Result<CreateFinancialAccount>>
97
- - getFinancialAccount(financialAccountId: string, monime_access_token: string, monime_space_id: string): Promise<Result<GetFinancialAccount>>
98
- - createInternalTransfer(sourceAccount: string, destinationAccount: string, monime_access_token: string, monime_space_id: string, value: number): Promise<Result<CreateInternalTransfer>>
99
- - createPaymentCode(paymentName: string, amount: number, financialAccountId: string | null, name: string, phoneNumber: string, monime_access_token: string, monime_space_id: string): Promise<Result<{ code?: string }>>
100
- - deletePaymentCode(paymentCodeId: string, monime_access_token: string, monime_space_id: string): Promise<Result<null>>
101
- - 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
+ ```
102
122
 
103
- Refer to `src/functions/*Types.ts` for full TypeScript interfaces.
123
+ ### Payouts
104
124
 
105
- ### Important behaviors
125
+ ```ts
126
+ client.createPayout(
127
+ amount: number,
128
+ phoneNumber: string,
129
+ sourceAccount: string
130
+ ): Promise<Result<CreatePayout>>
131
+ ```
106
132
 
107
- - createPaymentCode: input `amount` is multiplied by 100 before being sent (to match Monime's expected minor currency units).
108
- - createPaymentCode: passing `financialAccountId` as an empty string results in `financialAccountId` being omitted from the request body.
109
- - CreatePayoutMobileMoney: provider is inferred from phone number prefixes; check `src/functions/payout.ts` for the exact rules.
110
- - 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
+ ---
111
136
 
112
137
  ## Examples
113
138
 
114
- Create a payment code and handle errors gracefully:
139
+ ### Create a financial account
115
140
 
116
141
  ```ts
117
- import { createPaymentCode } from 'monime-package'
118
-
119
- async function createCode() {
120
- const res = await createPaymentCode('Order-001', 5, 'financial-account-id', 'Alice', '0771234567', process.env.MONIME_ACCESS_TOKEN!, process.env.MONIME_SPACE_ID!)
121
- if (!res.success) {
122
- console.error('Failed to create payment code', res.error)
123
- return
124
- }
125
- console.log('USSD code:', res.code)
126
- }
142
+ const account = await client.createFinancialAccount('App Wallet')
143
+ if (!account.success) throw account.error
144
+ console.log(account.data)
127
145
  ```
128
146
 
129
- Create an internal transfer:
147
+ ### Get account details
130
148
 
131
149
  ```ts
132
- import { createInternalTransfer } from 'monime-package'
150
+ const details = await client.getFinancialAccount(account.data!.result.id)
151
+ console.log(details)
152
+ ```
133
153
 
134
- const t = await createInternalTransfer('acc-src', 'acc-dest', process.env.MONIME_ACCESS_TOKEN!, process.env.MONIME_SPACE_ID!, 1500)
135
- if (!t.success) console.error('transfer error', t.error)
136
- 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)
137
183
  ```
138
184
 
139
- 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:
140
190
 
141
191
  ```ts
142
- import { CreatePayoutMobileMoney } from 'monime-package'
192
+ createFinancialAccount('name', MONIME_SPACE_ID, MONIME_ACCESS_TOKEN)
193
+ ```
194
+
195
+ Now, create a client once:
143
196
 
144
- const p = await CreatePayoutMobileMoney(1000, '0771234567', 'source-account-id', process.env.MONIME_ACCESS_TOKEN!, process.env.MONIME_SPACE_ID!)
145
- if (!p.success) console.error(p.error)
146
- else console.log('payout', p.data)
197
+ ```ts
198
+ const client = createClient({ monimeSpaceeId, accessToken })
199
+ client.createFinancialAccount('name') // credentials auto-applied
147
200
  ```
148
201
 
149
- ## Folder structure
202
+ ---
203
+
204
+ ## Folder Structure
150
205
 
151
206
  ```
152
- .
207
+ .
153
208
  ├── LICENSE
154
209
  ├── README.md
155
210
  ├── package.json
156
211
  ├── tsconfig.json
157
212
  ├── tsup.config.ts
158
213
  ├── src
159
- │ ├── index.ts # re-exports
160
- │ └── functions
214
+ │ ├── index.ts # entry point
215
+ │ └── modules
161
216
  │ ├── financialAccount.ts
162
217
  │ ├── financialAccountTypes.ts
163
218
  │ ├── internalTransfer.ts
@@ -168,31 +223,34 @@ else console.log('payout', p.data)
168
223
  │ └── payoutTypes.ts
169
224
  ```
170
225
 
171
- ## Configuration & env
172
-
173
- Recommended environment variables (you can store them in `.env` during development):
226
+ ---
174
227
 
175
- ```
176
- MONIME_SPACE_ID=space_XXXXXXXX
177
- MONIME_ACCESS_TOKEN=sk_live_xxx
178
- ```
228
+ ## Error Handling
179
229
 
180
- ## 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.
181
232
 
182
- - 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.
183
- - Network errors: axios errors are returned directly in some functions. Use `axios.isAxiosError` to inspect `error.response` and `error.response.data`.
184
- - Payouts: if payout calls fail unexpectedly, check `src/functions/payout.ts` — its `URL` constant is empty and must be configured.
233
+ ---
185
234
 
186
235
  ## Contributing
187
236
 
188
- Contributions appreciated. Suggested small first PRs:
189
237
 
190
- - Add an `examples/` folder with a safe demo script that reads env vars and shows each helper.
191
- - Add tests using `vitest` or `jest` with `nock` or axios mocking.
192
- - Normalize returned errors to a consistent shape.
238
+ We welcome contributions.
193
239
 
194
- 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
+ ---
195
251
 
196
252
  ## License
197
253
 
198
- 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 };