monime-package 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/LICENSE +21 -0
- package/README.md +198 -0
- package/dist/index.d.mts +196 -0
- package/dist/index.d.ts +196 -0
- package/dist/index.js +264 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +222 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Walon-Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
|
|
2
|
+
# monime-package
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
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
|
+
|
|
11
|
+
## Table of contents
|
|
12
|
+
|
|
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)
|
|
24
|
+
|
|
25
|
+
## Description
|
|
26
|
+
|
|
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
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
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)
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
Install with npm or pnpm:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install monime-package
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
or
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm add monime-package
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
1. Add your credentials to environment variables (recommended) or pass them directly to the functions.
|
|
53
|
+
2. Import the helpers and call them.
|
|
54
|
+
|
|
55
|
+
Example (TypeScript):
|
|
56
|
+
|
|
57
|
+
```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
|
+
}
|
|
78
|
+
|
|
79
|
+
demo().catch(err => console.error(err))
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API reference
|
|
83
|
+
|
|
84
|
+
All functions return a Promise resolving to an object with the following minimal shape:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
type Result<T> = {
|
|
88
|
+
success: boolean
|
|
89
|
+
data?: T
|
|
90
|
+
error?: any
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Top-level exports (signatures simplified):
|
|
95
|
+
|
|
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>>
|
|
102
|
+
|
|
103
|
+
Refer to `src/functions/*Types.ts` for full TypeScript interfaces.
|
|
104
|
+
|
|
105
|
+
### Important behaviors
|
|
106
|
+
|
|
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.
|
|
111
|
+
|
|
112
|
+
## Examples
|
|
113
|
+
|
|
114
|
+
Create a payment code and handle errors gracefully:
|
|
115
|
+
|
|
116
|
+
```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
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Create an internal transfer:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { createInternalTransfer } from 'monime-package'
|
|
133
|
+
|
|
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)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Payout (note: set `src/functions/payout.ts` URL before use):
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { CreatePayoutMobileMoney } from 'monime-package'
|
|
143
|
+
|
|
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)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Folder structure
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
.
|
|
153
|
+
├── LICENSE
|
|
154
|
+
├── README.md
|
|
155
|
+
├── package.json
|
|
156
|
+
├── tsconfig.json
|
|
157
|
+
├── tsup.config.ts
|
|
158
|
+
├── src
|
|
159
|
+
│ ├── index.ts # re-exports
|
|
160
|
+
│ └── functions
|
|
161
|
+
│ ├── financialAccount.ts
|
|
162
|
+
│ ├── financialAccountTypes.ts
|
|
163
|
+
│ ├── internalTransfer.ts
|
|
164
|
+
│ ├── internalTransferTypes.ts
|
|
165
|
+
│ ├── paymentCode.ts
|
|
166
|
+
│ ├── paymentCodeTypes.ts
|
|
167
|
+
│ ├── payout.ts
|
|
168
|
+
│ └── payoutTypes.ts
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Configuration & env
|
|
172
|
+
|
|
173
|
+
Recommended environment variables (you can store them in `.env` during development):
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
MONIME_SPACE_ID=space_XXXXXXXX
|
|
177
|
+
MONIME_ACCESS_TOKEN=sk_live_xxx
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Troubleshooting
|
|
181
|
+
|
|
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.
|
|
185
|
+
|
|
186
|
+
## Contributing
|
|
187
|
+
|
|
188
|
+
Contributions appreciated. Suggested small first PRs:
|
|
189
|
+
|
|
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.
|
|
193
|
+
|
|
194
|
+
When opening a PR, include a short description and tests for new behavior.
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT — see `LICENSE`.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
interface CreateFinancialAccount {
|
|
2
|
+
success: boolean;
|
|
3
|
+
messages: string[];
|
|
4
|
+
result: Result$2;
|
|
5
|
+
}
|
|
6
|
+
interface GetFinancialAccount {
|
|
7
|
+
success: boolean;
|
|
8
|
+
messages: string[];
|
|
9
|
+
result: Result$2;
|
|
10
|
+
}
|
|
11
|
+
interface Result$2 {
|
|
12
|
+
id: string;
|
|
13
|
+
uvan: string;
|
|
14
|
+
name: string;
|
|
15
|
+
currency: string;
|
|
16
|
+
reference: string;
|
|
17
|
+
description: string;
|
|
18
|
+
balance: Balance;
|
|
19
|
+
createTime: string;
|
|
20
|
+
updateTime: string;
|
|
21
|
+
metadata: Metadata$2;
|
|
22
|
+
}
|
|
23
|
+
interface Result$2 {
|
|
24
|
+
id: string;
|
|
25
|
+
uvan: string;
|
|
26
|
+
name: string;
|
|
27
|
+
currency: string;
|
|
28
|
+
reference: string;
|
|
29
|
+
description: string;
|
|
30
|
+
balance: Balance;
|
|
31
|
+
createTime: string;
|
|
32
|
+
updateTime: string;
|
|
33
|
+
metadata: Metadata$2;
|
|
34
|
+
}
|
|
35
|
+
interface Metadata$2 {
|
|
36
|
+
}
|
|
37
|
+
interface Metadata$2 {
|
|
38
|
+
}
|
|
39
|
+
interface Balance {
|
|
40
|
+
available: Available;
|
|
41
|
+
}
|
|
42
|
+
interface Balance {
|
|
43
|
+
available: Available;
|
|
44
|
+
}
|
|
45
|
+
interface Available {
|
|
46
|
+
currency: string;
|
|
47
|
+
value: number;
|
|
48
|
+
}
|
|
49
|
+
interface Available {
|
|
50
|
+
currency: string;
|
|
51
|
+
value: number;
|
|
52
|
+
}
|
|
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
|
+
interface CreateInternalTransfer {
|
|
68
|
+
success: boolean;
|
|
69
|
+
messages: string[];
|
|
70
|
+
result: Result$1;
|
|
71
|
+
}
|
|
72
|
+
interface Result$1 {
|
|
73
|
+
id: string;
|
|
74
|
+
status: string;
|
|
75
|
+
amount: Amount$1;
|
|
76
|
+
sourceFinancialAccount: SourceFinancialAccount;
|
|
77
|
+
destinationFinancialAccount: SourceFinancialAccount;
|
|
78
|
+
financialTransactionReference: string;
|
|
79
|
+
description: string;
|
|
80
|
+
failureDetail: FailureDetail$1;
|
|
81
|
+
ownershipGraph: OwnershipGraph$1;
|
|
82
|
+
createTime: string;
|
|
83
|
+
updateTime: string;
|
|
84
|
+
metadata: Metadata$1;
|
|
85
|
+
}
|
|
86
|
+
interface OwnershipGraph$1 {
|
|
87
|
+
owner: Owner2$1;
|
|
88
|
+
}
|
|
89
|
+
interface Owner2$1 {
|
|
90
|
+
id: string;
|
|
91
|
+
type: string;
|
|
92
|
+
metadata: Metadata$1;
|
|
93
|
+
owner: Owner$1;
|
|
94
|
+
}
|
|
95
|
+
interface Owner$1 {
|
|
96
|
+
id: string;
|
|
97
|
+
type: string;
|
|
98
|
+
metadata: Metadata$1;
|
|
99
|
+
owner: Metadata$1;
|
|
100
|
+
}
|
|
101
|
+
interface Metadata$1 {
|
|
102
|
+
}
|
|
103
|
+
interface FailureDetail$1 {
|
|
104
|
+
code: string;
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
interface SourceFinancialAccount {
|
|
108
|
+
id: string;
|
|
109
|
+
}
|
|
110
|
+
interface Amount$1 {
|
|
111
|
+
currency: string;
|
|
112
|
+
value: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface Return$2 {
|
|
116
|
+
data?: CreateInternalTransfer;
|
|
117
|
+
error?: Error;
|
|
118
|
+
success: boolean;
|
|
119
|
+
}
|
|
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;
|
|
126
|
+
}
|
|
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
|
+
|
|
130
|
+
interface CreatePayout {
|
|
131
|
+
success: boolean;
|
|
132
|
+
messages: string[];
|
|
133
|
+
result: Result;
|
|
134
|
+
}
|
|
135
|
+
interface Result {
|
|
136
|
+
id: string;
|
|
137
|
+
status: string;
|
|
138
|
+
amount: Amount;
|
|
139
|
+
source: Source;
|
|
140
|
+
destination: Destination;
|
|
141
|
+
fees: Fee[];
|
|
142
|
+
failureDetail: FailureDetail;
|
|
143
|
+
createTime: string;
|
|
144
|
+
updateTime: string;
|
|
145
|
+
ownershipGraph: OwnershipGraph;
|
|
146
|
+
metadata: Metadata;
|
|
147
|
+
}
|
|
148
|
+
interface OwnershipGraph {
|
|
149
|
+
owner: Owner2;
|
|
150
|
+
}
|
|
151
|
+
interface Owner2 {
|
|
152
|
+
id: string;
|
|
153
|
+
type: string;
|
|
154
|
+
metadata: Metadata;
|
|
155
|
+
owner: Owner;
|
|
156
|
+
}
|
|
157
|
+
interface Owner {
|
|
158
|
+
id: string;
|
|
159
|
+
type: string;
|
|
160
|
+
metadata: Metadata;
|
|
161
|
+
owner: Metadata;
|
|
162
|
+
}
|
|
163
|
+
interface FailureDetail {
|
|
164
|
+
code: string;
|
|
165
|
+
message: string;
|
|
166
|
+
}
|
|
167
|
+
interface Fee {
|
|
168
|
+
code: string;
|
|
169
|
+
amount: Amount;
|
|
170
|
+
metadata: Metadata;
|
|
171
|
+
}
|
|
172
|
+
interface Metadata {
|
|
173
|
+
}
|
|
174
|
+
interface Destination {
|
|
175
|
+
type: string;
|
|
176
|
+
providerId: string;
|
|
177
|
+
accountNumber: string;
|
|
178
|
+
transactionReference: string;
|
|
179
|
+
}
|
|
180
|
+
interface Source {
|
|
181
|
+
financialAccountId: string;
|
|
182
|
+
transactionReference: string;
|
|
183
|
+
}
|
|
184
|
+
interface Amount {
|
|
185
|
+
currency: string;
|
|
186
|
+
value: number;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface Return {
|
|
190
|
+
data?: CreatePayout;
|
|
191
|
+
error?: Error;
|
|
192
|
+
success: boolean;
|
|
193
|
+
}
|
|
194
|
+
declare function CreatePayoutMobileMoney(amount: number, phoneNumber: string, sourceAccount: string, monime_access_token: string, monime_space_id: string): Promise<Return>;
|
|
195
|
+
|
|
196
|
+
export { CreatePayoutMobileMoney, createFinancialAccount, createInternalTransfer, createPaymentCode, deletePaymentCode, getFinancialAccount };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
interface CreateFinancialAccount {
|
|
2
|
+
success: boolean;
|
|
3
|
+
messages: string[];
|
|
4
|
+
result: Result$2;
|
|
5
|
+
}
|
|
6
|
+
interface GetFinancialAccount {
|
|
7
|
+
success: boolean;
|
|
8
|
+
messages: string[];
|
|
9
|
+
result: Result$2;
|
|
10
|
+
}
|
|
11
|
+
interface Result$2 {
|
|
12
|
+
id: string;
|
|
13
|
+
uvan: string;
|
|
14
|
+
name: string;
|
|
15
|
+
currency: string;
|
|
16
|
+
reference: string;
|
|
17
|
+
description: string;
|
|
18
|
+
balance: Balance;
|
|
19
|
+
createTime: string;
|
|
20
|
+
updateTime: string;
|
|
21
|
+
metadata: Metadata$2;
|
|
22
|
+
}
|
|
23
|
+
interface Result$2 {
|
|
24
|
+
id: string;
|
|
25
|
+
uvan: string;
|
|
26
|
+
name: string;
|
|
27
|
+
currency: string;
|
|
28
|
+
reference: string;
|
|
29
|
+
description: string;
|
|
30
|
+
balance: Balance;
|
|
31
|
+
createTime: string;
|
|
32
|
+
updateTime: string;
|
|
33
|
+
metadata: Metadata$2;
|
|
34
|
+
}
|
|
35
|
+
interface Metadata$2 {
|
|
36
|
+
}
|
|
37
|
+
interface Metadata$2 {
|
|
38
|
+
}
|
|
39
|
+
interface Balance {
|
|
40
|
+
available: Available;
|
|
41
|
+
}
|
|
42
|
+
interface Balance {
|
|
43
|
+
available: Available;
|
|
44
|
+
}
|
|
45
|
+
interface Available {
|
|
46
|
+
currency: string;
|
|
47
|
+
value: number;
|
|
48
|
+
}
|
|
49
|
+
interface Available {
|
|
50
|
+
currency: string;
|
|
51
|
+
value: number;
|
|
52
|
+
}
|
|
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
|
+
interface CreateInternalTransfer {
|
|
68
|
+
success: boolean;
|
|
69
|
+
messages: string[];
|
|
70
|
+
result: Result$1;
|
|
71
|
+
}
|
|
72
|
+
interface Result$1 {
|
|
73
|
+
id: string;
|
|
74
|
+
status: string;
|
|
75
|
+
amount: Amount$1;
|
|
76
|
+
sourceFinancialAccount: SourceFinancialAccount;
|
|
77
|
+
destinationFinancialAccount: SourceFinancialAccount;
|
|
78
|
+
financialTransactionReference: string;
|
|
79
|
+
description: string;
|
|
80
|
+
failureDetail: FailureDetail$1;
|
|
81
|
+
ownershipGraph: OwnershipGraph$1;
|
|
82
|
+
createTime: string;
|
|
83
|
+
updateTime: string;
|
|
84
|
+
metadata: Metadata$1;
|
|
85
|
+
}
|
|
86
|
+
interface OwnershipGraph$1 {
|
|
87
|
+
owner: Owner2$1;
|
|
88
|
+
}
|
|
89
|
+
interface Owner2$1 {
|
|
90
|
+
id: string;
|
|
91
|
+
type: string;
|
|
92
|
+
metadata: Metadata$1;
|
|
93
|
+
owner: Owner$1;
|
|
94
|
+
}
|
|
95
|
+
interface Owner$1 {
|
|
96
|
+
id: string;
|
|
97
|
+
type: string;
|
|
98
|
+
metadata: Metadata$1;
|
|
99
|
+
owner: Metadata$1;
|
|
100
|
+
}
|
|
101
|
+
interface Metadata$1 {
|
|
102
|
+
}
|
|
103
|
+
interface FailureDetail$1 {
|
|
104
|
+
code: string;
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
interface SourceFinancialAccount {
|
|
108
|
+
id: string;
|
|
109
|
+
}
|
|
110
|
+
interface Amount$1 {
|
|
111
|
+
currency: string;
|
|
112
|
+
value: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface Return$2 {
|
|
116
|
+
data?: CreateInternalTransfer;
|
|
117
|
+
error?: Error;
|
|
118
|
+
success: boolean;
|
|
119
|
+
}
|
|
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;
|
|
126
|
+
}
|
|
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
|
+
|
|
130
|
+
interface CreatePayout {
|
|
131
|
+
success: boolean;
|
|
132
|
+
messages: string[];
|
|
133
|
+
result: Result;
|
|
134
|
+
}
|
|
135
|
+
interface Result {
|
|
136
|
+
id: string;
|
|
137
|
+
status: string;
|
|
138
|
+
amount: Amount;
|
|
139
|
+
source: Source;
|
|
140
|
+
destination: Destination;
|
|
141
|
+
fees: Fee[];
|
|
142
|
+
failureDetail: FailureDetail;
|
|
143
|
+
createTime: string;
|
|
144
|
+
updateTime: string;
|
|
145
|
+
ownershipGraph: OwnershipGraph;
|
|
146
|
+
metadata: Metadata;
|
|
147
|
+
}
|
|
148
|
+
interface OwnershipGraph {
|
|
149
|
+
owner: Owner2;
|
|
150
|
+
}
|
|
151
|
+
interface Owner2 {
|
|
152
|
+
id: string;
|
|
153
|
+
type: string;
|
|
154
|
+
metadata: Metadata;
|
|
155
|
+
owner: Owner;
|
|
156
|
+
}
|
|
157
|
+
interface Owner {
|
|
158
|
+
id: string;
|
|
159
|
+
type: string;
|
|
160
|
+
metadata: Metadata;
|
|
161
|
+
owner: Metadata;
|
|
162
|
+
}
|
|
163
|
+
interface FailureDetail {
|
|
164
|
+
code: string;
|
|
165
|
+
message: string;
|
|
166
|
+
}
|
|
167
|
+
interface Fee {
|
|
168
|
+
code: string;
|
|
169
|
+
amount: Amount;
|
|
170
|
+
metadata: Metadata;
|
|
171
|
+
}
|
|
172
|
+
interface Metadata {
|
|
173
|
+
}
|
|
174
|
+
interface Destination {
|
|
175
|
+
type: string;
|
|
176
|
+
providerId: string;
|
|
177
|
+
accountNumber: string;
|
|
178
|
+
transactionReference: string;
|
|
179
|
+
}
|
|
180
|
+
interface Source {
|
|
181
|
+
financialAccountId: string;
|
|
182
|
+
transactionReference: string;
|
|
183
|
+
}
|
|
184
|
+
interface Amount {
|
|
185
|
+
currency: string;
|
|
186
|
+
value: number;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface Return {
|
|
190
|
+
data?: CreatePayout;
|
|
191
|
+
error?: Error;
|
|
192
|
+
success: boolean;
|
|
193
|
+
}
|
|
194
|
+
declare function CreatePayoutMobileMoney(amount: number, phoneNumber: string, sourceAccount: string, monime_access_token: string, monime_space_id: string): Promise<Return>;
|
|
195
|
+
|
|
196
|
+
export { CreatePayoutMobileMoney, createFinancialAccount, createInternalTransfer, createPaymentCode, deletePaymentCode, getFinancialAccount };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
CreatePayoutMobileMoney: () => CreatePayoutMobileMoney,
|
|
34
|
+
createFinancialAccount: () => createFinancialAccount,
|
|
35
|
+
createInternalTransfer: () => createInternalTransfer,
|
|
36
|
+
createPaymentCode: () => createPaymentCode,
|
|
37
|
+
deletePaymentCode: () => deletePaymentCode,
|
|
38
|
+
getFinancialAccount: () => getFinancialAccount
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
|
|
42
|
+
// src/functions/financialAccount.ts
|
|
43
|
+
var import_axios = __toESM(require("axios"));
|
|
44
|
+
var import_crypto = require("crypto");
|
|
45
|
+
var URL = "https://api.monime.io/v1/financial-accounts";
|
|
46
|
+
var value = (0, import_crypto.randomBytes)(20).toString("hex");
|
|
47
|
+
async function createFinancialAccount(accountName, monime_space_id, monime_access_token) {
|
|
48
|
+
const body = {
|
|
49
|
+
name: accountName,
|
|
50
|
+
currency: "SLE",
|
|
51
|
+
description: "",
|
|
52
|
+
metadata: {}
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const res = await import_axios.default.post(URL, body, {
|
|
56
|
+
headers: {
|
|
57
|
+
"Idempotency-Key": `${value}`,
|
|
58
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
59
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
60
|
+
"Content-Type": "application/json"
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const data = res.data;
|
|
64
|
+
return { success: true, data };
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
67
|
+
return { error, success: false };
|
|
68
|
+
}
|
|
69
|
+
return { error: new Error("unknown error"), success: false };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function getFinancialAccount(financialAccountId, monime_access_token, monime_space_id) {
|
|
73
|
+
try {
|
|
74
|
+
const res = await import_axios.default.get(`${URL}/${financialAccountId}`, {
|
|
75
|
+
headers: {
|
|
76
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
77
|
+
Authorization: `Bearer ${monime_access_token}`
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const data = res.data;
|
|
81
|
+
return { success: true, data };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
84
|
+
return { error, success: false };
|
|
85
|
+
}
|
|
86
|
+
return { error: new Error("unknown error"), success: false };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/functions/internalTransfer.ts
|
|
91
|
+
var import_axios2 = __toESM(require("axios"));
|
|
92
|
+
var import_crypto2 = require("crypto");
|
|
93
|
+
var URL2 = "https://api.monime.io/v1/internal-transfers";
|
|
94
|
+
var value2 = (0, import_crypto2.randomBytes)(20).toString("hex");
|
|
95
|
+
async function createInternalTransfer(sourceAccount, destinationAccount, monime_access_token, monime_space_id, value5) {
|
|
96
|
+
const body = {
|
|
97
|
+
amount: {
|
|
98
|
+
currency: "SLE",
|
|
99
|
+
value: value5
|
|
100
|
+
},
|
|
101
|
+
sourceFinancialAccount: {
|
|
102
|
+
id: sourceAccount
|
|
103
|
+
},
|
|
104
|
+
destinationFinancialAccount: {
|
|
105
|
+
id: destinationAccount
|
|
106
|
+
},
|
|
107
|
+
metadata: {}
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
const res = await import_axios2.default.post(URL2, body, {
|
|
111
|
+
headers: {
|
|
112
|
+
"Idempotency-Key": `${value5}`,
|
|
113
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
114
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
115
|
+
"Content-Type": "application/json"
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const data = res.data;
|
|
119
|
+
return { success: true, data };
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (import_axios2.default.isAxiosError(error)) {
|
|
122
|
+
return { error, success: false };
|
|
123
|
+
}
|
|
124
|
+
return { error: new Error("unkknown error"), success: false };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/functions/paymentCode.ts
|
|
129
|
+
var import_axios3 = __toESM(require("axios"));
|
|
130
|
+
var import_crypto3 = require("crypto");
|
|
131
|
+
var value3 = (0, import_crypto3.randomBytes)(20).toString("hex");
|
|
132
|
+
var URL3 = "https://api.monime.io/v1/payment-codes";
|
|
133
|
+
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, monime_access_token, monime_space_id) {
|
|
134
|
+
let financialAccount = null;
|
|
135
|
+
if (financialAccountId !== "") {
|
|
136
|
+
financialAccount = financialAccountId;
|
|
137
|
+
}
|
|
138
|
+
if (monime_access_token === "" || monime_space_id === "") {
|
|
139
|
+
console.log("monime_access_token or monime_space_id is required");
|
|
140
|
+
return { error: new Error("monime_access_token and monime_space_id is required"), success: false };
|
|
141
|
+
}
|
|
142
|
+
const bodyData = {
|
|
143
|
+
name: `${paymentName}`,
|
|
144
|
+
mode: "recurrent",
|
|
145
|
+
enable: true,
|
|
146
|
+
amount: {
|
|
147
|
+
currency: "SLE",
|
|
148
|
+
value: amount * 100
|
|
149
|
+
},
|
|
150
|
+
duration: "1h30m",
|
|
151
|
+
customer: {
|
|
152
|
+
name: `${name}`
|
|
153
|
+
},
|
|
154
|
+
reference: "",
|
|
155
|
+
authorizedPhoneNumber: phoneNumber,
|
|
156
|
+
// authorizedProviders: ["m17", "m18"],
|
|
157
|
+
recurrentPaymentTarget: {
|
|
158
|
+
expectedPaymentCount: 1,
|
|
159
|
+
expectedPaymentTotal: {
|
|
160
|
+
currency: "SLE",
|
|
161
|
+
value: amount * 100
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
financialAccountId: financialAccount,
|
|
165
|
+
metadata: {}
|
|
166
|
+
};
|
|
167
|
+
try {
|
|
168
|
+
const res = await import_axios3.default.post(URL3, bodyData, {
|
|
169
|
+
headers: {
|
|
170
|
+
"Idempotency-Key": `${value3}`,
|
|
171
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
172
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
173
|
+
"Content-Type": "application/json"
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const data = res.data;
|
|
177
|
+
return { code: data.result.ussdCode, success: true };
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (import_axios3.default.isAxiosError(error)) {
|
|
180
|
+
return { error: error.response?.data, success: false };
|
|
181
|
+
}
|
|
182
|
+
return { error: new Error("unknown error"), success: false };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function deletePaymentCode(paymentCodeId, monime_access_token, monime_space_id) {
|
|
186
|
+
try {
|
|
187
|
+
const res = await import_axios3.default.delete(`${URL3}/${paymentCodeId}`, {
|
|
188
|
+
headers: {
|
|
189
|
+
"Idempotency-Key": `${value3}`,
|
|
190
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
191
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
192
|
+
"Content-Type": "application/json"
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
const data = res.data;
|
|
196
|
+
if (!data.success) {
|
|
197
|
+
return { error: new Error("delete failed"), success: false };
|
|
198
|
+
}
|
|
199
|
+
return { success: true };
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (import_axios3.default.isAxiosError(error)) {
|
|
202
|
+
return { error, success: false };
|
|
203
|
+
}
|
|
204
|
+
return { error: new Error("unknown error"), success: false };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/functions/payout.ts
|
|
209
|
+
var import_axios4 = __toESM(require("axios"));
|
|
210
|
+
var import_crypto4 = require("crypto");
|
|
211
|
+
var URL4 = "";
|
|
212
|
+
var value4 = (0, import_crypto4.randomBytes)(20).toString("hex");
|
|
213
|
+
async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, monime_access_token, monime_space_id) {
|
|
214
|
+
let provider = "m17";
|
|
215
|
+
const africell = ["077", "033", "088", "080", "090", "030"];
|
|
216
|
+
for (let value5 of africell) {
|
|
217
|
+
if (phoneNumber.startsWith(value5)) {
|
|
218
|
+
provider = "m18";
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const body = {
|
|
223
|
+
amount: {
|
|
224
|
+
currency: "SLE",
|
|
225
|
+
value: amount
|
|
226
|
+
},
|
|
227
|
+
source: {
|
|
228
|
+
financialAccountId: sourceAccount
|
|
229
|
+
},
|
|
230
|
+
destination: {
|
|
231
|
+
type: "momo",
|
|
232
|
+
provider,
|
|
233
|
+
phoneNumber
|
|
234
|
+
},
|
|
235
|
+
metadata: {}
|
|
236
|
+
};
|
|
237
|
+
try {
|
|
238
|
+
const res = await import_axios4.default.post(URL4, body, {
|
|
239
|
+
headers: {
|
|
240
|
+
"Idempotency-Key": `${value4}`,
|
|
241
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
242
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
243
|
+
"Content-Type": "application/json"
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const data = res.data;
|
|
247
|
+
return { success: true, data };
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (import_axios4.default.isAxiosError(error)) {
|
|
250
|
+
return { success: false, error };
|
|
251
|
+
}
|
|
252
|
+
return { success: false, error: new Error("unknown error") };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
256
|
+
0 && (module.exports = {
|
|
257
|
+
CreatePayoutMobileMoney,
|
|
258
|
+
createFinancialAccount,
|
|
259
|
+
createInternalTransfer,
|
|
260
|
+
createPaymentCode,
|
|
261
|
+
deletePaymentCode,
|
|
262
|
+
getFinancialAccount
|
|
263
|
+
});
|
|
264
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/functions/financialAccount.ts","../src/functions/internalTransfer.ts","../src/functions/paymentCode.ts","../src/functions/payout.ts"],"sourcesContent":["export * from \"./functions\"","import axios from \"axios\";\nimport { randomBytes } from \"crypto\"\nimport { CreateFinancialAccount, GetFinancialAccount } from \"./financialAccountTypes\";\n\nconst URL = 'https://api.monime.io/v1/financial-accounts'\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface createFinancialAccountReturn {\n data?:CreateFinancialAccount,\n error?:Error\n success:boolean\n}\n\nexport async function createFinancialAccount(accountName:string, monime_space_id:string, monime_access_token:string):Promise<createFinancialAccountReturn>{\n const body = {\n name:accountName,\n currency:'SLE',\n description:\"\",\n metadata:{}\n }\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreateFinancialAccount\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n\n return { error:new Error(\"unknown error\"), success:false}\n }\n}\n\n\n\ninterface GetFinancialAccountReturn {\n data?:GetFinancialAccount\n error?:Error\n success:boolean\n}\n\nexport async function getFinancialAccount(financialAccountId:string, monime_access_token:string, monime_space_id:string):Promise<GetFinancialAccountReturn>{\n try{\n const res = await axios.get(`${URL}/${financialAccountId}`, {\n headers:{\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`, \n }\n })\n\n const data = res.data as GetFinancialAccount\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n\n return { error:new Error(\"unknown error\"), success:false}\n }\n}\n\n","import axios from \"axios\";\nimport { randomBytes } from \"crypto\";\nimport { CreateInternalTransfer } from \"./internalTransferTypes\";\n\nconst URL = 'https://api.monime.io/v1/internal-transfers';\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface Return {\n data?:CreateInternalTransfer,\n error?:Error\n success:boolean\n}\n\nexport async function createInternalTransfer(sourceAccount:string, destinationAccount:string, monime_access_token:string, monime_space_id:string, value:number):Promise<Return>{\n const body = {\n amount :{\n currency:\"SLE\",\n value:value\n },\n sourceFinancialAccount:{\n id:sourceAccount\n },\n destinationFinancialAccount:{\n id:destinationAccount,\n },\n metadata:{}\n }\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreateInternalTransfer\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return {error:error, success:false}\n }\n\n return {error:new Error(\"unkknown error\"), success:false}\n }\n}","import axios from \"axios\";\nimport { randomBytes } from \"crypto\"\nimport { CreatePaymentCode, DeletePaymentCode } from \"./paymentCodeTypes\";\n\nconst value = randomBytes(20).toString(\"hex\")\nconst URL = \"https://api.monime.io/v1/payment-codes\"\n\ninterface Return {\n code?:string,\n error?:Error\n success:boolean\n}\n\nexport async function createPaymentCode(paymentName:string, amount:number, financialAccountId:string |null, name:string, phoneNumber:string, monime_access_token:string, monime_space_id:string):Promise<Return>{\n let financialAccount = null\n if(financialAccountId !== \"\"){\n financialAccount = financialAccountId\n }\n\n if(monime_access_token === \"\" || monime_space_id === \"\"){\n console.log(\"monime_access_token or monime_space_id is required\")\n return {error:new Error(\"monime_access_token and monime_space_id is required\"), success:false}\n }\n\n\n const bodyData = {\n name: `${paymentName}`,\n mode: \"recurrent\",\n enable:true,\n amount: {\n currency: \"SLE\",\n value:(amount) * 100\n },\n duration: \"1h30m\",\n customer: {\n name: `${name}`,\n },\n reference:\"\",\n authorizedPhoneNumber:phoneNumber,\n // authorizedProviders: [\"m17\", \"m18\"],\n recurrentPaymentTarget:{\n expectedPaymentCount: 1,\n expectedPaymentTotal:{\n currency:\"SLE\",\n value:(amount) * 100\n }\n },\n financialAccountId:financialAccount,\n metadata: {}\n };\n\n try{\n const res = await axios.post(URL, bodyData, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreatePaymentCode\n return { code:data.result.ussdCode, success:true}\n }catch(error){\n if(axios.isAxiosError(error)){\n return {error:error.response?.data, success:false}\n }\n return {error:new Error(\"unknown error\"), success:false}\n }\n}\n\n\nexport async function deletePaymentCode(paymentCodeId:string, monime_access_token:string, monime_space_id:string):Promise<Return>{\n try{\n const res = await axios.delete(`${URL}/${paymentCodeId}`, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as DeletePaymentCode\n if(!data.success){\n return { error:new Error(\"delete failed\"), success:false}\n }\n\n return { success:true }\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n return { error:new Error(\"unknown error\"), success:false}\n }\n}","import axios from \"axios\"\nimport { randomBytes } from \"crypto\"\nimport { CreatePayout } from \"./payoutTypes\"\n\nconst URL = \"\"\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface Return {\n data?:CreatePayout,\n error?:Error,\n success:boolean\n}\n\nexport async function CreatePayoutMobileMoney(amount:number,phoneNumber:string, sourceAccount:string, monime_access_token:string, monime_space_id:string):Promise<Return> {\n let provider = \"m17\"\n const africell = [\"077\", \"033\", \"088\", \"080\",\"090\",\"030\"]\n for (let value of africell){\n if(phoneNumber.startsWith(value)){\n provider = 'm18'\n break;\n }\n }\n const body = {\n amount:{\n currency:'SLE',\n value:amount\n },\n source:{\n financialAccountId:sourceAccount\n },\n destination:{\n type:\"momo\",\n provider:provider,\n phoneNumber:phoneNumber\n },\n metadata:{}\n }\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreatePayout\n\n return {success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { success:false, error:error}\n }\n\n return { success:false, error: new Error(\"unknown error\")}\n } \n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAmB;AACnB,oBAA4B;AAG5B,IAAM,MAAM;AACZ,IAAM,YAAQ,2BAAY,EAAE,EAAE,SAAS,KAAK;AAQ5C,eAAsB,uBAAuB,aAAoB,iBAAwB,qBAAiE;AACtJ,QAAM,OAAO;AAAA,IACT,MAAK;AAAA,IACL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AG,cAAAC,QAAM,aAAa,KAAK,GAAE;AACzB,aAAO,EAAE,SAAQ,OAAO,MAAW;AAAA,IACvC;AAEA,WAAO,EAAE,SAAQ,OAAO,OAAO,IAAI,MAAM,eAAe,EAAC;AAAA,EAC7D;AACJ;","names":["axios","import_axios","import_crypto","URL","value","axios","import_axios","import_crypto","value","URL","axios","import_axios","import_crypto","URL","value","axios"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// src/functions/financialAccount.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { randomBytes } from "crypto";
|
|
4
|
+
var URL = "https://api.monime.io/v1/financial-accounts";
|
|
5
|
+
var value = randomBytes(20).toString("hex");
|
|
6
|
+
async function createFinancialAccount(accountName, monime_space_id, monime_access_token) {
|
|
7
|
+
const body = {
|
|
8
|
+
name: accountName,
|
|
9
|
+
currency: "SLE",
|
|
10
|
+
description: "",
|
|
11
|
+
metadata: {}
|
|
12
|
+
};
|
|
13
|
+
try {
|
|
14
|
+
const res = await axios.post(URL, body, {
|
|
15
|
+
headers: {
|
|
16
|
+
"Idempotency-Key": `${value}`,
|
|
17
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
18
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const data = res.data;
|
|
23
|
+
return { success: true, data };
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (axios.isAxiosError(error)) {
|
|
26
|
+
return { error, success: false };
|
|
27
|
+
}
|
|
28
|
+
return { error: new Error("unknown error"), success: false };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function getFinancialAccount(financialAccountId, monime_access_token, monime_space_id) {
|
|
32
|
+
try {
|
|
33
|
+
const res = await axios.get(`${URL}/${financialAccountId}`, {
|
|
34
|
+
headers: {
|
|
35
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
36
|
+
Authorization: `Bearer ${monime_access_token}`
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const data = res.data;
|
|
40
|
+
return { success: true, data };
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (axios.isAxiosError(error)) {
|
|
43
|
+
return { error, success: false };
|
|
44
|
+
}
|
|
45
|
+
return { error: new Error("unknown error"), success: false };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/functions/internalTransfer.ts
|
|
50
|
+
import axios2 from "axios";
|
|
51
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
52
|
+
var URL2 = "https://api.monime.io/v1/internal-transfers";
|
|
53
|
+
var value2 = randomBytes2(20).toString("hex");
|
|
54
|
+
async function createInternalTransfer(sourceAccount, destinationAccount, monime_access_token, monime_space_id, value5) {
|
|
55
|
+
const body = {
|
|
56
|
+
amount: {
|
|
57
|
+
currency: "SLE",
|
|
58
|
+
value: value5
|
|
59
|
+
},
|
|
60
|
+
sourceFinancialAccount: {
|
|
61
|
+
id: sourceAccount
|
|
62
|
+
},
|
|
63
|
+
destinationFinancialAccount: {
|
|
64
|
+
id: destinationAccount
|
|
65
|
+
},
|
|
66
|
+
metadata: {}
|
|
67
|
+
};
|
|
68
|
+
try {
|
|
69
|
+
const res = await axios2.post(URL2, body, {
|
|
70
|
+
headers: {
|
|
71
|
+
"Idempotency-Key": `${value5}`,
|
|
72
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
73
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
74
|
+
"Content-Type": "application/json"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const data = res.data;
|
|
78
|
+
return { success: true, data };
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (axios2.isAxiosError(error)) {
|
|
81
|
+
return { error, success: false };
|
|
82
|
+
}
|
|
83
|
+
return { error: new Error("unkknown error"), success: false };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/functions/paymentCode.ts
|
|
88
|
+
import axios3 from "axios";
|
|
89
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
90
|
+
var value3 = randomBytes3(20).toString("hex");
|
|
91
|
+
var URL3 = "https://api.monime.io/v1/payment-codes";
|
|
92
|
+
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, monime_access_token, monime_space_id) {
|
|
93
|
+
let financialAccount = null;
|
|
94
|
+
if (financialAccountId !== "") {
|
|
95
|
+
financialAccount = financialAccountId;
|
|
96
|
+
}
|
|
97
|
+
if (monime_access_token === "" || monime_space_id === "") {
|
|
98
|
+
console.log("monime_access_token or monime_space_id is required");
|
|
99
|
+
return { error: new Error("monime_access_token and monime_space_id is required"), success: false };
|
|
100
|
+
}
|
|
101
|
+
const bodyData = {
|
|
102
|
+
name: `${paymentName}`,
|
|
103
|
+
mode: "recurrent",
|
|
104
|
+
enable: true,
|
|
105
|
+
amount: {
|
|
106
|
+
currency: "SLE",
|
|
107
|
+
value: amount * 100
|
|
108
|
+
},
|
|
109
|
+
duration: "1h30m",
|
|
110
|
+
customer: {
|
|
111
|
+
name: `${name}`
|
|
112
|
+
},
|
|
113
|
+
reference: "",
|
|
114
|
+
authorizedPhoneNumber: phoneNumber,
|
|
115
|
+
// authorizedProviders: ["m17", "m18"],
|
|
116
|
+
recurrentPaymentTarget: {
|
|
117
|
+
expectedPaymentCount: 1,
|
|
118
|
+
expectedPaymentTotal: {
|
|
119
|
+
currency: "SLE",
|
|
120
|
+
value: amount * 100
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
financialAccountId: financialAccount,
|
|
124
|
+
metadata: {}
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const res = await axios3.post(URL3, bodyData, {
|
|
128
|
+
headers: {
|
|
129
|
+
"Idempotency-Key": `${value3}`,
|
|
130
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
131
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
132
|
+
"Content-Type": "application/json"
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const data = res.data;
|
|
136
|
+
return { code: data.result.ussdCode, success: true };
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (axios3.isAxiosError(error)) {
|
|
139
|
+
return { error: error.response?.data, success: false };
|
|
140
|
+
}
|
|
141
|
+
return { error: new Error("unknown error"), success: false };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function deletePaymentCode(paymentCodeId, monime_access_token, monime_space_id) {
|
|
145
|
+
try {
|
|
146
|
+
const res = await axios3.delete(`${URL3}/${paymentCodeId}`, {
|
|
147
|
+
headers: {
|
|
148
|
+
"Idempotency-Key": `${value3}`,
|
|
149
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
150
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
151
|
+
"Content-Type": "application/json"
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const data = res.data;
|
|
155
|
+
if (!data.success) {
|
|
156
|
+
return { error: new Error("delete failed"), success: false };
|
|
157
|
+
}
|
|
158
|
+
return { success: true };
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (axios3.isAxiosError(error)) {
|
|
161
|
+
return { error, success: false };
|
|
162
|
+
}
|
|
163
|
+
return { error: new Error("unknown error"), success: false };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/functions/payout.ts
|
|
168
|
+
import axios4 from "axios";
|
|
169
|
+
import { randomBytes as randomBytes4 } from "crypto";
|
|
170
|
+
var URL4 = "";
|
|
171
|
+
var value4 = randomBytes4(20).toString("hex");
|
|
172
|
+
async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, monime_access_token, monime_space_id) {
|
|
173
|
+
let provider = "m17";
|
|
174
|
+
const africell = ["077", "033", "088", "080", "090", "030"];
|
|
175
|
+
for (let value5 of africell) {
|
|
176
|
+
if (phoneNumber.startsWith(value5)) {
|
|
177
|
+
provider = "m18";
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const body = {
|
|
182
|
+
amount: {
|
|
183
|
+
currency: "SLE",
|
|
184
|
+
value: amount
|
|
185
|
+
},
|
|
186
|
+
source: {
|
|
187
|
+
financialAccountId: sourceAccount
|
|
188
|
+
},
|
|
189
|
+
destination: {
|
|
190
|
+
type: "momo",
|
|
191
|
+
provider,
|
|
192
|
+
phoneNumber
|
|
193
|
+
},
|
|
194
|
+
metadata: {}
|
|
195
|
+
};
|
|
196
|
+
try {
|
|
197
|
+
const res = await axios4.post(URL4, body, {
|
|
198
|
+
headers: {
|
|
199
|
+
"Idempotency-Key": `${value4}`,
|
|
200
|
+
"Monime-Space-Id": `${monime_space_id}`,
|
|
201
|
+
Authorization: `Bearer ${monime_access_token}`,
|
|
202
|
+
"Content-Type": "application/json"
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
const data = res.data;
|
|
206
|
+
return { success: true, data };
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (axios4.isAxiosError(error)) {
|
|
209
|
+
return { success: false, error };
|
|
210
|
+
}
|
|
211
|
+
return { success: false, error: new Error("unknown error") };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
CreatePayoutMobileMoney,
|
|
216
|
+
createFinancialAccount,
|
|
217
|
+
createInternalTransfer,
|
|
218
|
+
createPaymentCode,
|
|
219
|
+
deletePaymentCode,
|
|
220
|
+
getFinancialAccount
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/functions/financialAccount.ts","../src/functions/internalTransfer.ts","../src/functions/paymentCode.ts","../src/functions/payout.ts"],"sourcesContent":["import axios from \"axios\";\nimport { randomBytes } from \"crypto\"\nimport { CreateFinancialAccount, GetFinancialAccount } from \"./financialAccountTypes\";\n\nconst URL = 'https://api.monime.io/v1/financial-accounts'\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface createFinancialAccountReturn {\n data?:CreateFinancialAccount,\n error?:Error\n success:boolean\n}\n\nexport async function createFinancialAccount(accountName:string, monime_space_id:string, monime_access_token:string):Promise<createFinancialAccountReturn>{\n const body = {\n name:accountName,\n currency:'SLE',\n description:\"\",\n metadata:{}\n }\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreateFinancialAccount\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n\n return { error:new Error(\"unknown error\"), success:false}\n }\n}\n\n\n\ninterface GetFinancialAccountReturn {\n data?:GetFinancialAccount\n error?:Error\n success:boolean\n}\n\nexport async function getFinancialAccount(financialAccountId:string, monime_access_token:string, monime_space_id:string):Promise<GetFinancialAccountReturn>{\n try{\n const res = await axios.get(`${URL}/${financialAccountId}`, {\n headers:{\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`, \n }\n })\n\n const data = res.data as GetFinancialAccount\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n\n return { error:new Error(\"unknown error\"), success:false}\n }\n}\n\n","import axios from \"axios\";\nimport { randomBytes } from \"crypto\";\nimport { CreateInternalTransfer } from \"./internalTransferTypes\";\n\nconst URL = 'https://api.monime.io/v1/internal-transfers';\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface Return {\n data?:CreateInternalTransfer,\n error?:Error\n success:boolean\n}\n\nexport async function createInternalTransfer(sourceAccount:string, destinationAccount:string, monime_access_token:string, monime_space_id:string, value:number):Promise<Return>{\n const body = {\n amount :{\n currency:\"SLE\",\n value:value\n },\n sourceFinancialAccount:{\n id:sourceAccount\n },\n destinationFinancialAccount:{\n id:destinationAccount,\n },\n metadata:{}\n }\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreateInternalTransfer\n\n return { success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return {error:error, success:false}\n }\n\n return {error:new Error(\"unkknown error\"), success:false}\n }\n}","import axios from \"axios\";\nimport { randomBytes } from \"crypto\"\nimport { CreatePaymentCode, DeletePaymentCode } from \"./paymentCodeTypes\";\n\nconst value = randomBytes(20).toString(\"hex\")\nconst URL = \"https://api.monime.io/v1/payment-codes\"\n\ninterface Return {\n code?:string,\n error?:Error\n success:boolean\n}\n\nexport async function createPaymentCode(paymentName:string, amount:number, financialAccountId:string |null, name:string, phoneNumber:string, monime_access_token:string, monime_space_id:string):Promise<Return>{\n let financialAccount = null\n if(financialAccountId !== \"\"){\n financialAccount = financialAccountId\n }\n\n if(monime_access_token === \"\" || monime_space_id === \"\"){\n console.log(\"monime_access_token or monime_space_id is required\")\n return {error:new Error(\"monime_access_token and monime_space_id is required\"), success:false}\n }\n\n\n const bodyData = {\n name: `${paymentName}`,\n mode: \"recurrent\",\n enable:true,\n amount: {\n currency: \"SLE\",\n value:(amount) * 100\n },\n duration: \"1h30m\",\n customer: {\n name: `${name}`,\n },\n reference:\"\",\n authorizedPhoneNumber:phoneNumber,\n // authorizedProviders: [\"m17\", \"m18\"],\n recurrentPaymentTarget:{\n expectedPaymentCount: 1,\n expectedPaymentTotal:{\n currency:\"SLE\",\n value:(amount) * 100\n }\n },\n financialAccountId:financialAccount,\n metadata: {}\n };\n\n try{\n const res = await axios.post(URL, bodyData, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreatePaymentCode\n return { code:data.result.ussdCode, success:true}\n }catch(error){\n if(axios.isAxiosError(error)){\n return {error:error.response?.data, success:false}\n }\n return {error:new Error(\"unknown error\"), success:false}\n }\n}\n\n\nexport async function deletePaymentCode(paymentCodeId:string, monime_access_token:string, monime_space_id:string):Promise<Return>{\n try{\n const res = await axios.delete(`${URL}/${paymentCodeId}`, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as DeletePaymentCode\n if(!data.success){\n return { error:new Error(\"delete failed\"), success:false}\n }\n\n return { success:true }\n }catch(error){\n if(axios.isAxiosError(error)){\n return { error:error, success:false}\n }\n return { error:new Error(\"unknown error\"), success:false}\n }\n}","import axios from \"axios\"\nimport { randomBytes } from \"crypto\"\nimport { CreatePayout } from \"./payoutTypes\"\n\nconst URL = \"\"\nconst value = randomBytes(20).toString(\"hex\")\n\ninterface Return {\n data?:CreatePayout,\n error?:Error,\n success:boolean\n}\n\nexport async function CreatePayoutMobileMoney(amount:number,phoneNumber:string, sourceAccount:string, monime_access_token:string, monime_space_id:string):Promise<Return> {\n let provider = \"m17\"\n const africell = [\"077\", \"033\", \"088\", \"080\",\"090\",\"030\"]\n for (let value of africell){\n if(phoneNumber.startsWith(value)){\n provider = 'm18'\n break;\n }\n }\n const body = {\n amount:{\n currency:'SLE',\n value:amount\n },\n source:{\n financialAccountId:sourceAccount\n },\n destination:{\n type:\"momo\",\n provider:provider,\n phoneNumber:phoneNumber\n },\n metadata:{}\n }\n\n try{\n const res = await axios.post(URL, body, {\n headers:{\n 'Idempotency-Key': `${value}`,\n 'Monime-Space-Id': `${monime_space_id}`,\n Authorization: `Bearer ${monime_access_token}`,\n 'Content-Type': 'application/json' \n }\n })\n\n const data = res.data as CreatePayout\n\n return {success:true, data}\n }catch(error){\n if(axios.isAxiosError(error)){\n return { success:false, error:error}\n }\n\n return { success:false, error: new Error(\"unknown error\")}\n } \n}"],"mappings":";AAAA,OAAO,WAAY;AACnB,SA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AA,IACJ,CAAC;AAED,UAAM,OAAO,IAAI;AAEjB,WAAO,EAAC,SAAQ,MAAM,KAAI;AAAA,EAC9B,SAAO,OAAM;AACT,QAAGH,OAAM,aAAa,KAAK,GAAE;AACzB,aAAO,EAAE,SAAQ,OAAO,MAAW;AAAA,IACvC;AAEA,WAAO,EAAE,SAAQ,OAAO,OAAO,IAAI,MAAM,eAAe,EAAC;AAAA,EAC7D;AACJ;","names":["axios","randomBytes","URL","value","axios","randomBytes","value","URL","axios","randomBytes","URL","value"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "monime-package",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "vitest",
|
|
10
|
+
"build": "tsup"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"monime",
|
|
19
|
+
"payment"
|
|
20
|
+
],
|
|
21
|
+
"author": "Mohamed Lamin Walon-Jalloh",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"packageManager": "pnpm@10.17.1",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^24.6.2",
|
|
26
|
+
"tsup": "^8.5.0",
|
|
27
|
+
"typescript": "^5.9.3",
|
|
28
|
+
"vitest": "^3.2.4"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/Walon-Foundation/monime-package"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"axios": "^1.12.2"
|
|
36
|
+
}
|
|
37
|
+
}
|