@grtsnx/payba3 1.0.0 → 2.0.0
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/CHANGELOG.md +20 -1
- package/CONTRIBUTING.md +3 -3
- package/README.md +149 -40
- package/dist/index.d.ts +4 -3
- package/dist/index.js +7 -3
- package/dist/lib/monnify/config/monnify.helper.d.ts +2 -1
- package/dist/lib/monnify/config/monnify.helper.js +18 -18
- package/dist/lib/monnify/config/monnify.helper.js.map +1 -1
- package/dist/lib/monnify/config/monnify.types.d.ts +11 -2
- package/dist/lib/monnify/monnify.service.d.ts +2 -2
- package/dist/lib/monnify/monnify.service.js +17 -21
- package/dist/lib/monnify/monnify.service.js.map +1 -1
- package/dist/lib/mono/config/mono.helper.d.ts +2 -1
- package/dist/lib/mono/config/mono.helper.js +9 -9
- package/dist/lib/mono/config/mono.helper.js.map +1 -1
- package/dist/lib/mono/config/mono.types.d.ts +7 -1
- package/dist/lib/mono/mono.service.d.ts +2 -2
- package/dist/lib/mono/mono.service.js +8 -21
- package/dist/lib/mono/mono.service.js.map +1 -1
- package/dist/lib/opay/config/opay.helper.d.ts +2 -1
- package/dist/lib/opay/config/opay.helper.js +15 -15
- package/dist/lib/opay/config/opay.helper.js.map +1 -1
- package/dist/lib/opay/config/opay.types.d.ts +11 -2
- package/dist/lib/opay/opay.service.d.ts +2 -2
- package/dist/lib/opay/opay.service.js +19 -21
- package/dist/lib/opay/opay.service.js.map +1 -1
- package/dist/lib/payba3.service.d.ts +3 -9
- package/dist/lib/payba3.service.js +17 -32
- package/dist/lib/payba3.service.js.map +1 -1
- package/dist/lib/payba3.types.d.ts +17 -0
- package/dist/lib/payba3.types.js.map +1 -1
- package/dist/lib/paystack/config/paystack.helper.js +7 -9
- package/dist/lib/paystack/config/paystack.helper.js.map +1 -1
- package/dist/lib/paystack/config/paystack.types.d.ts +6 -0
- package/dist/lib/paystack/paystack.service.d.ts +2 -2
- package/dist/lib/paystack/paystack.service.js +19 -28
- package/dist/lib/paystack/paystack.service.js.map +1 -1
- package/dist/lib/qoreid/config/qoreid.helper.js +7 -9
- package/dist/lib/qoreid/config/qoreid.helper.js.map +1 -1
- package/dist/lib/qoreid/config/qoreid.types.d.ts +7 -0
- package/dist/lib/qoreid/qoreid.service.d.ts +2 -2
- package/dist/lib/qoreid/qoreid.service.js +11 -19
- package/dist/lib/qoreid/qoreid.service.js.map +1 -1
- package/dist/lib/safehaven/config/safe.helper.d.ts +3 -1
- package/dist/lib/safehaven/config/safe.helper.js +29 -19
- package/dist/lib/safehaven/config/safe.helper.js.map +1 -1
- package/dist/lib/safehaven/config/safe.types.d.ts +16 -2
- package/dist/lib/safehaven/safe.service.d.ts +2 -4
- package/dist/lib/safehaven/safe.service.js +20 -27
- package/dist/lib/safehaven/safe.service.js.map +1 -1
- package/dist/lib/seerbit/config/seerbit.helper.d.ts +2 -1
- package/dist/lib/seerbit/config/seerbit.helper.js +13 -12
- package/dist/lib/seerbit/config/seerbit.helper.js.map +1 -1
- package/dist/lib/seerbit/config/seerbit.types.d.ts +10 -2
- package/dist/lib/seerbit/seerbit.service.d.ts +2 -2
- package/dist/lib/seerbit/seerbit.service.js +17 -24
- package/dist/lib/seerbit/seerbit.service.js.map +1 -1
- package/dist/lib/shared/index.d.ts +1 -0
- package/dist/lib/shared/index.js +1 -0
- package/dist/lib/shared/index.js.map +1 -1
- package/dist/lib/shared/payba3-error.d.ts +37 -0
- package/dist/lib/shared/payba3-error.js +64 -0
- package/dist/lib/shared/payba3-error.js.map +1 -0
- package/dist/lib/shared/response.helper.d.ts +3 -10
- package/dist/lib/shared/response.helper.js +5 -24
- package/dist/lib/shared/response.helper.js.map +1 -1
- package/llms.txt +12 -9
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -6,9 +6,28 @@ This project follows a human-readable changelog style. Add new entries under `Un
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
- No unreleased changes.
|
|
10
|
+
|
|
11
|
+
## 2.0.0
|
|
12
|
+
|
|
13
|
+
- Made the root package framework-neutral with `createPayba3()` and plain provider clients.
|
|
14
|
+
- Removed Nest runtime peer dependencies from the package contract.
|
|
15
|
+
- Added typed constructor options for every provider so config can come from code, environment variables, or both.
|
|
16
|
+
- Replaced provider-facing Nest exceptions with `Payba3Error`.
|
|
17
|
+
- Preserved automatic access-token reuse and refresh for Safehaven, QoreID, and Monnify.
|
|
18
|
+
- Added package-boundary tests to prevent Nest imports from leaking into the public core.
|
|
19
|
+
- Updated package smoke tests to validate npm and Bun installs without Nest peer packages.
|
|
20
|
+
|
|
21
|
+
## 1.0.1
|
|
22
|
+
|
|
23
|
+
- Documented IDE and AI-agent integration flows.
|
|
24
|
+
- Exported provider LLM reference files through package subpaths.
|
|
25
|
+
- Clarified Nest peer dependency expectations for host applications.
|
|
26
|
+
|
|
27
|
+
## 1.0.0
|
|
28
|
+
|
|
9
29
|
- Added payba3 provider facade.
|
|
10
30
|
- Added OPay, Mono, and Monnify channel scaffolding.
|
|
11
31
|
- Added provider LLM reference files.
|
|
12
32
|
- Added contribution, security, support, and conduct documentation.
|
|
13
33
|
- Added payba3 logo assets.
|
|
14
|
-
|
package/CONTRIBUTING.md
CHANGED
|
@@ -58,9 +58,9 @@ payba3/
|
|
|
58
58
|
├── src/
|
|
59
59
|
│ ├── app/ # Minimal app shell and health endpoint
|
|
60
60
|
│ ├── lib/ # payba3 provider integrations
|
|
61
|
-
│ │ ├── payba3.service.ts #
|
|
61
|
+
│ │ ├── payba3.service.ts # Framework-neutral client/factory surface
|
|
62
62
|
│ │ ├── payba3.types.ts # Shared payba3 channel types
|
|
63
|
-
│ │ ├── lib.module.ts #
|
|
63
|
+
│ │ ├── lib.module.ts # Optional local Nest demo registration module
|
|
64
64
|
│ │ ├── shared/ # Provider-safe shared helpers
|
|
65
65
|
│ │ ├── paystack/ # Paystack channel
|
|
66
66
|
│ │ ├── safehaven/ # Safehaven channel
|
|
@@ -97,7 +97,7 @@ src/lib/<provider>/
|
|
|
97
97
|
├── config/
|
|
98
98
|
│ ├── <provider>.helper.ts # Auth, signing, token refresh, fetch, parsing
|
|
99
99
|
│ └── <provider>.types.ts # Provider payloads, responses, request context
|
|
100
|
-
├── <provider>.module.ts #
|
|
100
|
+
├── <provider>.module.ts # Optional local Nest demo registration
|
|
101
101
|
├── <provider>.service.ts # Developer-facing provider actions
|
|
102
102
|
└── <provider>_llm.txt # Provider docs for agents/LLMs
|
|
103
103
|
```
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
|
|
6
|
+
Framework-neutral payment integration surface for many payment channels.
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
# payba3
|
|
20
20
|
|
|
21
|
-
payba3 is an open-source collection of payment-channel integrations built for developers, teams, codebases, automations, and AI agents that need a simple way to plug into different payment providers.
|
|
21
|
+
payba3 is an open-source collection of payment-channel integrations built for developers, teams, codebases, automations, and AI agents that need a simple way to plug into different payment providers from server-side TypeScript or JavaScript.
|
|
22
22
|
|
|
23
23
|
Configure the provider you want, select it through payba3, and call the channel.
|
|
24
24
|
|
|
@@ -50,15 +50,15 @@ Use payba3 when you want:
|
|
|
50
50
|
|
|
51
51
|
## Supported Channels
|
|
52
52
|
|
|
53
|
-
| Channel
|
|
54
|
-
|
|
|
55
|
-
| Paystack
|
|
56
|
-
| Safehaven | Virtual accounts, subaccounts, banking APIs
|
|
57
|
-
| SeerBit
|
|
58
|
-
| OPay
|
|
59
|
-
| Mono
|
|
60
|
-
| Monnify
|
|
61
|
-
| QoreID
|
|
53
|
+
| Channel | Common use cases | Provider signup | Provider docs |
|
|
54
|
+
| --------- | ------------------------------------------------------ | -------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
55
|
+
| Paystack | Checkout, subscriptions, transfers, dedicated accounts | [Create account](https://paystack.com/developers) | [Docs](https://paystack.com/docs/api/) |
|
|
56
|
+
| Safehaven | Virtual accounts, subaccounts, banking APIs | [Sandbox](https://online.sandbox.safehavenmfb.com) | [Docs](https://safehavenmfb.readme.io/reference/introduction) |
|
|
57
|
+
| SeerBit | Collections, virtual accounts, online payments | [Create account](https://www.seerbit.com/developers) | [Docs](https://doc.seerbit.com/) |
|
|
58
|
+
| OPay | Checkout, signed payment APIs, refunds | [Merchant dashboard](https://merchant.opaycheckout.com) | [Docs](https://doc.opaycheckout.com/payment-authentication) |
|
|
59
|
+
| Mono | Open banking, account linking, DirectPay, lookup | [Create account](https://mono.co/signup) | [Docs](https://docs.mono.co/docs/quickstart) |
|
|
60
|
+
| Monnify | Checkout, reserved accounts, transfers, wallets | [Create account](https://app.monnify.com/create-account) | [Docs](https://developers.monnify.com/docs/collections/quickstart) |
|
|
61
|
+
| QoreID | KYC, CAC lookup, identity verification | [Create account](https://dashboard.qoreid.com/dashboard) | [Docs](https://docs.qoreid.com/) |
|
|
62
62
|
|
|
63
63
|
## Installation
|
|
64
64
|
|
|
@@ -80,11 +80,11 @@ bun add @grtsnx/payba3
|
|
|
80
80
|
|
|
81
81
|
payba3 ships compiled JavaScript, TypeScript declarations, and an npm exports map. It is tested with npm and Bun install smoke checks in CI. Yarn and pnpm can consume the same npm package metadata.
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
### Runtime Requirements
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
payba3 2.x is framework-neutral. It does not require Nest, Express, Fastify, Next.js, or any other framework package to import or use the provider clients.
|
|
86
|
+
|
|
87
|
+
Use it in server-side JavaScript or TypeScript with a runtime that provides `fetch`, `URLSearchParams`, and Node-compatible crypto APIs. Node.js 18+ and Bun are covered by package smoke tests.
|
|
88
88
|
|
|
89
89
|
If you are using the repository directly:
|
|
90
90
|
|
|
@@ -94,38 +94,43 @@ bun install
|
|
|
94
94
|
|
|
95
95
|
## Quick Usage
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
Create a payba3 client, configure the providers you want, then select a channel.
|
|
98
98
|
|
|
99
99
|
```ts
|
|
100
|
-
import {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
100
|
+
import { createPayba3 } from '@grtsnx/payba3';
|
|
101
|
+
|
|
102
|
+
const payba3 = createPayba3({
|
|
103
|
+
paystack: {
|
|
104
|
+
secretKey: process.env.PAYSTACK_SECRET_KEY,
|
|
105
|
+
},
|
|
106
|
+
safehaven: {
|
|
107
|
+
environment: 'sandbox',
|
|
108
|
+
clientId: process.env.SAFEHAVEN_CLIENT_ID,
|
|
109
|
+
clientAssertion: process.env.SAFEHAVEN_CLIENT_ASSERTION,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
const checkout = await payba3.use('paystack').initializeOneTimeCheckout({
|
|
114
|
+
email: 'customer@example.com',
|
|
115
|
+
amountInKobo: 250000,
|
|
116
|
+
currency: 'NGN',
|
|
117
|
+
reference: 'order_123',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const subAccount = await payba3.use('safehaven').createSubAccount({
|
|
121
|
+
phoneNumber: '08000000000',
|
|
122
|
+
identityType: 'vID',
|
|
123
|
+
identityId: 'identity-id',
|
|
124
|
+
emailAddress: 'customer@example.com',
|
|
125
|
+
externalReference: 'customer_123',
|
|
126
|
+
});
|
|
124
127
|
```
|
|
125
128
|
|
|
126
129
|
You can also use a channel directly when you want provider-specific methods:
|
|
127
130
|
|
|
128
131
|
```ts
|
|
132
|
+
const monnify = payba3.use('monnify');
|
|
133
|
+
|
|
129
134
|
await monnify.createReservedAccount({
|
|
130
135
|
accountReference: 'customer_123',
|
|
131
136
|
accountName: 'Jane Doe',
|
|
@@ -139,6 +144,23 @@ await monnify.createReservedAccount({
|
|
|
139
144
|
|
|
140
145
|
Only configure the providers you use. Missing credentials for unused providers should not block your application from starting.
|
|
141
146
|
|
|
147
|
+
You can configure providers through `createPayba3()` options, environment variables, or a mix of both. Explicit constructor options win over environment variables.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const payba3 = createPayba3({
|
|
151
|
+
monnify: {
|
|
152
|
+
environment: 'live',
|
|
153
|
+
apiKey: process.env.MONNIFY_LIVE_API_KEY,
|
|
154
|
+
secretKey: process.env.MONNIFY_LIVE_SECRET_KEY,
|
|
155
|
+
contractCode: process.env.MONNIFY_LIVE_CONTRACT_CODE,
|
|
156
|
+
},
|
|
157
|
+
qoreid: {
|
|
158
|
+
clientId: process.env.QOREID_CLIENT,
|
|
159
|
+
secret: process.env.QOREID_SECRET,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
142
164
|
### Paystack
|
|
143
165
|
|
|
144
166
|
```bash
|
|
@@ -153,6 +175,8 @@ PAYSTACK_SECRET_KEY_LIVE=
|
|
|
153
175
|
SAFEHAVEN_ENVIRONMENT=sandbox
|
|
154
176
|
SAFEHAVEN_CLIENT_ID=
|
|
155
177
|
SAFEHAVEN_CLIENT_ASSERTION=
|
|
178
|
+
SAFEHAVEN_LIVE_CLIENT_ID=
|
|
179
|
+
SAFEHAVEN_LIVE_CLIENT_ASSERTION=
|
|
156
180
|
SAFEHAVEN_TIMEOUT_MS=10000
|
|
157
181
|
```
|
|
158
182
|
|
|
@@ -245,13 +269,98 @@ payba3 refreshes expiring provider tokens before they become stale.
|
|
|
245
269
|
|
|
246
270
|
## For AI Agents And Automation
|
|
247
271
|
|
|
248
|
-
payba3 is intended to be easy for agents and automation workflows to reason about:
|
|
272
|
+
payba3 is intended to be easy for agents, IDE assistants, code generators, and automation workflows to reason about:
|
|
249
273
|
|
|
250
274
|
- Provider names are explicit.
|
|
251
275
|
- Configuration is environment based.
|
|
252
276
|
- Request signing and token refresh are handled by payba3.
|
|
253
277
|
- Provider-specific actions remain discoverable through named channels.
|
|
254
278
|
|
|
279
|
+
### Agent Documentation Files
|
|
280
|
+
|
|
281
|
+
The npm package includes an LLM index and provider-specific reference files. Agents and IDEs can read these files from an installed package instead of scraping source code.
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import { readFileSync } from 'node:fs';
|
|
285
|
+
import { createRequire } from 'node:module';
|
|
286
|
+
|
|
287
|
+
const require = createRequire(import.meta.url);
|
|
288
|
+
|
|
289
|
+
const indexPath = require.resolve('@grtsnx/payba3/llms.txt');
|
|
290
|
+
const paystackPath = require.resolve('@grtsnx/payba3/llms/paystack.txt');
|
|
291
|
+
|
|
292
|
+
const payba3Guide = readFileSync(indexPath, 'utf8');
|
|
293
|
+
const paystackGuide = readFileSync(paystackPath, 'utf8');
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Available provider docs:
|
|
297
|
+
|
|
298
|
+
```text
|
|
299
|
+
@grtsnx/payba3/llms.txt
|
|
300
|
+
@grtsnx/payba3/llms/paystack.txt
|
|
301
|
+
@grtsnx/payba3/llms/safehaven.txt
|
|
302
|
+
@grtsnx/payba3/llms/seerbit.txt
|
|
303
|
+
@grtsnx/payba3/llms/opay.txt
|
|
304
|
+
@grtsnx/payba3/llms/mono.txt
|
|
305
|
+
@grtsnx/payba3/llms/monnify.txt
|
|
306
|
+
@grtsnx/payba3/llms/qoreid.txt
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### IDE And Agent Workflow
|
|
310
|
+
|
|
311
|
+
For IDEs, coding agents, and internal app generators:
|
|
312
|
+
|
|
313
|
+
1. Install `@grtsnx/payba3`.
|
|
314
|
+
2. Read `@grtsnx/payba3/llms.txt`.
|
|
315
|
+
3. Read the provider file for the requested channel.
|
|
316
|
+
4. Generate server-side code that imports from `@grtsnx/payba3`.
|
|
317
|
+
5. Ask the developer for only the provider environment variables they need.
|
|
318
|
+
6. Keep secrets on the server and verify provider callbacks before delivering value.
|
|
319
|
+
|
|
320
|
+
Example prompt for an IDE agent:
|
|
321
|
+
|
|
322
|
+
```text
|
|
323
|
+
Use @grtsnx/payba3 to add Paystack checkout.
|
|
324
|
+
Read @grtsnx/payba3/llms.txt and @grtsnx/payba3/llms/paystack.txt first.
|
|
325
|
+
Only add server-side code.
|
|
326
|
+
Use PAYSTACK_SECRET_KEY from the environment.
|
|
327
|
+
Verify transactions server-side before marking an order paid.
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
For AI tool servers, expose small provider actions instead of exposing raw secrets:
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
import { createPayba3, type Payba3ChannelName } from '@grtsnx/payba3';
|
|
334
|
+
|
|
335
|
+
type PaymentToolInput = {
|
|
336
|
+
channel: Payba3ChannelName;
|
|
337
|
+
action: 'initializeCheckout' | 'verifyTransaction';
|
|
338
|
+
payload: Record<string, unknown>;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const payba3 = createPayba3({
|
|
342
|
+
paystack: {
|
|
343
|
+
secretKey: process.env.PAYSTACK_SECRET_KEY,
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
export class PaymentTool {
|
|
348
|
+
async run(input: PaymentToolInput) {
|
|
349
|
+
const provider = payba3.use(input.channel);
|
|
350
|
+
|
|
351
|
+
if (input.channel === 'paystack' && input.action === 'initializeCheckout') {
|
|
352
|
+
return provider.initializeOneTimeCheckout({
|
|
353
|
+
email: String(input.payload.email),
|
|
354
|
+
amountInKobo: Number(input.payload.amountInKobo),
|
|
355
|
+
reference: String(input.payload.reference),
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
throw new Error('Unsupported payment tool action');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
255
364
|
## Contributor Checks
|
|
256
365
|
|
|
257
366
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { Payba3Service } from './lib/payba3.service';
|
|
1
|
+
export { createPayba3, Payba3Service } from './lib/payba3.service';
|
|
3
2
|
export { PAYBA3_CHANNELS } from './lib/payba3.types';
|
|
4
|
-
export type { Payba3ChannelMap, Payba3ChannelName } from './lib/payba3.types';
|
|
3
|
+
export type { Payba3ChannelMap, Payba3ChannelName, Payba3Config, } from './lib/payba3.types';
|
|
4
|
+
export { Payba3Error, PAYBA3_HTTP_STATUS, getPayba3ErrorMessage, getPayba3StatusText, } from './lib/shared';
|
|
5
|
+
export type { HandleResponseBody, Payba3ErrorBody, Payba3ErrorOptions, Payba3HttpStatusCode, } from './lib/shared';
|
|
5
6
|
export { MonoService } from './lib/mono/mono.service';
|
|
6
7
|
export type * from './lib/mono/config/mono.types';
|
|
7
8
|
export { MonnifyService } from './lib/monnify/monnify.service';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SeerbitService = exports.SafehavenService = exports.QoreIDService = exports.PaystackService = exports.OPayService = exports.MonnifyService = exports.MonoService = exports.PAYBA3_CHANNELS = exports.Payba3Service = exports.
|
|
4
|
-
var lib_module_1 = require("./lib/lib.module");
|
|
5
|
-
Object.defineProperty(exports, "LibModule", { enumerable: true, get: function () { return lib_module_1.LibModule; } });
|
|
3
|
+
exports.SeerbitService = exports.SafehavenService = exports.QoreIDService = exports.PaystackService = exports.OPayService = exports.MonnifyService = exports.MonoService = exports.getPayba3StatusText = exports.getPayba3ErrorMessage = exports.PAYBA3_HTTP_STATUS = exports.Payba3Error = exports.PAYBA3_CHANNELS = exports.Payba3Service = exports.createPayba3 = void 0;
|
|
6
4
|
var payba3_service_1 = require("./lib/payba3.service");
|
|
5
|
+
Object.defineProperty(exports, "createPayba3", { enumerable: true, get: function () { return payba3_service_1.createPayba3; } });
|
|
7
6
|
Object.defineProperty(exports, "Payba3Service", { enumerable: true, get: function () { return payba3_service_1.Payba3Service; } });
|
|
8
7
|
var payba3_types_1 = require("./lib/payba3.types");
|
|
9
8
|
Object.defineProperty(exports, "PAYBA3_CHANNELS", { enumerable: true, get: function () { return payba3_types_1.PAYBA3_CHANNELS; } });
|
|
9
|
+
var shared_1 = require("./lib/shared");
|
|
10
|
+
Object.defineProperty(exports, "Payba3Error", { enumerable: true, get: function () { return shared_1.Payba3Error; } });
|
|
11
|
+
Object.defineProperty(exports, "PAYBA3_HTTP_STATUS", { enumerable: true, get: function () { return shared_1.PAYBA3_HTTP_STATUS; } });
|
|
12
|
+
Object.defineProperty(exports, "getPayba3ErrorMessage", { enumerable: true, get: function () { return shared_1.getPayba3ErrorMessage; } });
|
|
13
|
+
Object.defineProperty(exports, "getPayba3StatusText", { enumerable: true, get: function () { return shared_1.getPayba3StatusText; } });
|
|
10
14
|
var mono_service_1 = require("./lib/mono/mono.service");
|
|
11
15
|
Object.defineProperty(exports, "MonoService", { enumerable: true, get: function () { return mono_service_1.MonoService; } });
|
|
12
16
|
var monnify_service_1 = require("./lib/monnify/monnify.service");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { MonnifyBaseUrls, MonnifyCredentials, MonnifyEnvironment, MonnifyResponse, MonnifyRequestContext, MonnifyRequestOptions, MonnifyTokenCache } from './monnify.types';
|
|
1
|
+
import type { MonnifyBaseUrls, MonnifyCredentials, MonnifyEnvironment, NormalizedMonnifyEnvironment, MonnifyResponse, MonnifyRequestContext, MonnifyRequestOptions, MonnifyTokenCache } from './monnify.types';
|
|
2
2
|
export declare const MONNIFY_BASE_URLS: MonnifyBaseUrls;
|
|
3
|
+
export declare const normalizeMonnifyEnvironment: (environment?: string) => NormalizedMonnifyEnvironment;
|
|
3
4
|
export declare const getMonnifyBaseUrl: (environment: MonnifyEnvironment, baseUrlOverride?: string) => string;
|
|
4
5
|
export declare const getMonnifyCredentials: (environment: MonnifyEnvironment) => MonnifyCredentials;
|
|
5
6
|
export declare const assertMonnifyCredentials: (credentials: MonnifyCredentials) => void;
|
|
@@ -33,46 +33,48 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.verifyMonnifyWebhookSignature = exports.createMonnifyWebhookSignature = exports.stringifyMonnifyWebhookPayload = exports.getValidMonnifyAccessToken = exports.isMonnifyTokenFresh = exports.createMonnifyTokenCache = exports.decodeJwtPayload = exports.fetchMonnifyToken = exports.getMonnifyBasicAuth = exports.requestMonnify = exports.throwMonnifyResponseError = exports.isMonnifyResponse = exports.getMonnifyErrorMessage = exports.parseMonnifyResponse = exports.buildMonnifyQuery = exports.buildMonnifyRequestInit = exports.buildMonnifyHeaders = exports.assertMonnifyContractCode = exports.assertMonnifySecretKey = exports.assertMonnifyCredentials = exports.getMonnifyCredentials = exports.getMonnifyBaseUrl = exports.MONNIFY_BASE_URLS = void 0;
|
|
37
|
-
const common_1 = require("@nestjs/common");
|
|
36
|
+
exports.verifyMonnifyWebhookSignature = exports.createMonnifyWebhookSignature = exports.stringifyMonnifyWebhookPayload = exports.getValidMonnifyAccessToken = exports.isMonnifyTokenFresh = exports.createMonnifyTokenCache = exports.decodeJwtPayload = exports.fetchMonnifyToken = exports.getMonnifyBasicAuth = exports.requestMonnify = exports.throwMonnifyResponseError = exports.isMonnifyResponse = exports.getMonnifyErrorMessage = exports.parseMonnifyResponse = exports.buildMonnifyQuery = exports.buildMonnifyRequestInit = exports.buildMonnifyHeaders = exports.assertMonnifyContractCode = exports.assertMonnifySecretKey = exports.assertMonnifyCredentials = exports.getMonnifyCredentials = exports.getMonnifyBaseUrl = exports.normalizeMonnifyEnvironment = exports.MONNIFY_BASE_URLS = void 0;
|
|
38
37
|
const crypto = __importStar(require("crypto"));
|
|
39
|
-
const
|
|
38
|
+
const shared_1 = require("../../shared");
|
|
40
39
|
const TOKEN_REFRESH_BUFFER_MS = 60_000;
|
|
41
40
|
const DEFAULT_TOKEN_TTL_MS = 50 * 60 * 1000;
|
|
42
41
|
exports.MONNIFY_BASE_URLS = {
|
|
43
42
|
sandbox: 'https://sandbox.monnify.com',
|
|
44
43
|
live: 'https://api.monnify.com',
|
|
45
44
|
};
|
|
46
|
-
const
|
|
45
|
+
const normalizeMonnifyEnvironment = (environment) => environment === 'live' || environment === 'production' ? 'live' : 'sandbox';
|
|
46
|
+
exports.normalizeMonnifyEnvironment = normalizeMonnifyEnvironment;
|
|
47
|
+
const getMonnifyBaseUrl = (environment, baseUrlOverride) => (baseUrlOverride ??
|
|
48
|
+
exports.MONNIFY_BASE_URLS[(0, exports.normalizeMonnifyEnvironment)(environment)]).replace(/\/+$/, '');
|
|
47
49
|
exports.getMonnifyBaseUrl = getMonnifyBaseUrl;
|
|
48
50
|
const getMonnifyCredentials = (environment) => ({
|
|
49
|
-
apiKey: (environment === 'live'
|
|
51
|
+
apiKey: ((0, exports.normalizeMonnifyEnvironment)(environment) === 'live'
|
|
50
52
|
? process.env.MONNIFY_LIVE_API_KEY
|
|
51
53
|
: process.env.MONNIFY_API_KEY)?.trim() ?? '',
|
|
52
|
-
secretKey: (environment === 'live'
|
|
54
|
+
secretKey: ((0, exports.normalizeMonnifyEnvironment)(environment) === 'live'
|
|
53
55
|
? process.env.MONNIFY_LIVE_SECRET_KEY
|
|
54
56
|
: process.env.MONNIFY_SECRET_KEY)?.trim() ?? '',
|
|
55
|
-
contractCode: (environment === 'live'
|
|
57
|
+
contractCode: ((0, exports.normalizeMonnifyEnvironment)(environment) === 'live'
|
|
56
58
|
? process.env.MONNIFY_LIVE_CONTRACT_CODE
|
|
57
59
|
: process.env.MONNIFY_CONTRACT_CODE)?.trim() ?? '',
|
|
58
60
|
});
|
|
59
61
|
exports.getMonnifyCredentials = getMonnifyCredentials;
|
|
60
62
|
const assertMonnifyCredentials = (credentials) => {
|
|
61
63
|
if (!credentials.apiKey || !credentials.secretKey) {
|
|
62
|
-
throw new
|
|
64
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.INTERNAL_SERVER_ERROR, 'MONNIFY_API_KEY and MONNIFY_SECRET_KEY are required');
|
|
63
65
|
}
|
|
64
66
|
};
|
|
65
67
|
exports.assertMonnifyCredentials = assertMonnifyCredentials;
|
|
66
68
|
const assertMonnifySecretKey = (secretKey) => {
|
|
67
69
|
if (!secretKey) {
|
|
68
|
-
throw new
|
|
70
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.INTERNAL_SERVER_ERROR, 'MONNIFY_SECRET_KEY is not configured');
|
|
69
71
|
}
|
|
70
72
|
return secretKey;
|
|
71
73
|
};
|
|
72
74
|
exports.assertMonnifySecretKey = assertMonnifySecretKey;
|
|
73
75
|
const assertMonnifyContractCode = (contractCode) => {
|
|
74
76
|
if (!contractCode) {
|
|
75
|
-
throw new
|
|
77
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.INTERNAL_SERVER_ERROR, 'MONNIFY_CONTRACT_CODE is not configured');
|
|
76
78
|
}
|
|
77
79
|
return contractCode;
|
|
78
80
|
};
|
|
@@ -114,7 +116,7 @@ const parseMonnifyResponse = async (response) => {
|
|
|
114
116
|
}
|
|
115
117
|
};
|
|
116
118
|
exports.parseMonnifyResponse = parseMonnifyResponse;
|
|
117
|
-
const getMonnifyErrorMessage = (error) =>
|
|
119
|
+
const getMonnifyErrorMessage = (error) => (0, shared_1.getPayba3ErrorMessage)(error, 'Monnify request failed');
|
|
118
120
|
exports.getMonnifyErrorMessage = getMonnifyErrorMessage;
|
|
119
121
|
const isMonnifyResponse = (value) => typeof value === 'object' &&
|
|
120
122
|
value !== null &&
|
|
@@ -122,7 +124,7 @@ const isMonnifyResponse = (value) => typeof value === 'object' &&
|
|
|
122
124
|
'responseMessage' in value;
|
|
123
125
|
exports.isMonnifyResponse = isMonnifyResponse;
|
|
124
126
|
const throwMonnifyResponseError = (body) => {
|
|
125
|
-
throw new
|
|
127
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.BAD_REQUEST, body.responseMessage || 'Monnify request failed', body);
|
|
126
128
|
};
|
|
127
129
|
exports.throwMonnifyResponseError = throwMonnifyResponseError;
|
|
128
130
|
const requestMonnify = async ({ baseUrl, endpoint, options = {}, }) => {
|
|
@@ -131,14 +133,13 @@ const requestMonnify = async ({ baseUrl, endpoint, options = {}, }) => {
|
|
|
131
133
|
response = await fetch(`${baseUrl}${endpoint}`, (0, exports.buildMonnifyRequestInit)(options));
|
|
132
134
|
}
|
|
133
135
|
catch (error) {
|
|
134
|
-
throw new
|
|
135
|
-
message: 'Monnify request failed',
|
|
136
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.BAD_GATEWAY, 'Monnify request failed', {
|
|
136
137
|
data: (0, exports.getMonnifyErrorMessage)(error),
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
const body = await (0, exports.parseMonnifyResponse)(response);
|
|
140
141
|
if (!response.ok) {
|
|
141
|
-
throw new
|
|
142
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.BAD_REQUEST, 'Monnify request failed', body);
|
|
142
143
|
}
|
|
143
144
|
if ((0, exports.isMonnifyResponse)(body) && body.requestSuccessful === false) {
|
|
144
145
|
(0, exports.throwMonnifyResponseError)(body);
|
|
@@ -164,14 +165,13 @@ const fetchMonnifyToken = async (baseUrl, credentials) => {
|
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
catch (error) {
|
|
167
|
-
throw new
|
|
168
|
-
message: 'Monnify token request failed',
|
|
168
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.BAD_GATEWAY, 'Monnify token request failed', {
|
|
169
169
|
data: (0, exports.getMonnifyErrorMessage)(error),
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
const body = (await (0, exports.parseMonnifyResponse)(response));
|
|
173
173
|
if (!response.ok || !body.responseBody?.accessToken) {
|
|
174
|
-
throw new
|
|
174
|
+
throw new shared_1.handleResponse(shared_1.PAYBA3_HTTP_STATUS.BAD_REQUEST, 'Failed to obtain Monnify access token', body);
|
|
175
175
|
}
|
|
176
176
|
return (0, exports.createMonnifyTokenCache)(body.responseBody.accessToken);
|
|
177
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monnify.helper.js","sourceRoot":"","sources":["../../../../src/lib/monnify/config/monnify.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"monnify.helper.js","sourceRoot":"","sources":["../../../../src/lib/monnify/config/monnify.helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,yCAIsB;AAatB,MAAM,uBAAuB,GAAG,MAAM,CAAC;AACvC,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/B,QAAA,iBAAiB,GAAoB;IAChD,OAAO,EAAE,6BAA6B;IACtC,IAAI,EAAE,yBAAyB;CAChC,CAAC;AAEK,MAAM,2BAA2B,GAAG,CACzC,WAAoB,EACU,EAAE,CAChC,WAAW,KAAK,MAAM,IAAI,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAHjE,QAAA,2BAA2B,+BAGsC;AAEvE,MAAM,iBAAiB,GAAG,CAC/B,WAA+B,EAC/B,eAAwB,EAChB,EAAE,CACV,CACE,eAAe;IACf,yBAAiB,CAAC,IAAA,mCAA2B,EAAC,WAAW,CAAC,CAAC,CAC5D,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAPX,QAAA,iBAAiB,qBAON;AA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production' | 'test' | 'provision';
|
|
2
|
+
export type NormalizedMonnifyEnvironment = 'sandbox' | 'live';
|
|
2
3
|
export type MonnifyHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
3
4
|
export type MonnifyCredentials = {
|
|
4
5
|
apiKey: string;
|
|
5
6
|
secretKey: string;
|
|
6
7
|
contractCode: string;
|
|
7
8
|
};
|
|
8
|
-
export type
|
|
9
|
+
export type MonnifyServiceOptions = {
|
|
10
|
+
environment?: MonnifyEnvironment;
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
credentials?: Partial<MonnifyCredentials>;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
secretKey?: string;
|
|
15
|
+
contractCode?: string;
|
|
16
|
+
};
|
|
17
|
+
export type MonnifyBaseUrls = Record<NormalizedMonnifyEnvironment, string>;
|
|
9
18
|
export type MonnifyTokenCache = {
|
|
10
19
|
accessToken: string;
|
|
11
20
|
expiresAt: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { MonnifyInitializeTransactionInput, MonnifyRefundInput, MonnifyRequestOptions, MonnifyReservedAccountInput, MonnifyResponse, MonnifySubAccountInput, MonnifyTransactionStatusQuery, MonnifyTransferInput } from './config/monnify.types';
|
|
1
|
+
import type { MonnifyInitializeTransactionInput, MonnifyRefundInput, MonnifyRequestOptions, MonnifyReservedAccountInput, MonnifyResponse, MonnifyServiceOptions, MonnifySubAccountInput, MonnifyTransactionStatusQuery, MonnifyTransferInput } from './config/monnify.types';
|
|
2
2
|
export declare class MonnifyService {
|
|
3
3
|
private readonly baseUrl;
|
|
4
4
|
private readonly credentials;
|
|
5
5
|
private token?;
|
|
6
|
-
constructor();
|
|
6
|
+
constructor(options?: MonnifyServiceOptions);
|
|
7
7
|
getAccessToken(): Promise<string>;
|
|
8
8
|
request<T = unknown>(endpoint: string, options?: MonnifyRequestOptions): Promise<T>;
|
|
9
9
|
initializeTransaction(input: MonnifyInitializeTransactionInput): Promise<MonnifyResponse>;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.MonnifyService = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
4
|
const monnify_helper_1 = require("./config/monnify.helper");
|
|
15
|
-
|
|
5
|
+
class MonnifyService {
|
|
16
6
|
baseUrl;
|
|
17
7
|
credentials;
|
|
18
8
|
token;
|
|
19
|
-
constructor() {
|
|
20
|
-
const environment = (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
const environment = (0, monnify_helper_1.normalizeMonnifyEnvironment)(options.environment ??
|
|
11
|
+
process.env.MONNIFY_ENVIRONMENT ??
|
|
12
|
+
process.env.NODE_ENV);
|
|
13
|
+
const envCredentials = (0, monnify_helper_1.getMonnifyCredentials)(environment);
|
|
14
|
+
this.baseUrl = (0, monnify_helper_1.getMonnifyBaseUrl)(environment, options.baseUrl ?? process.env.MONNIFY_BASE_URL);
|
|
15
|
+
this.credentials = {
|
|
16
|
+
apiKey: options.apiKey ?? options.credentials?.apiKey ?? envCredentials.apiKey,
|
|
17
|
+
secretKey: options.secretKey ??
|
|
18
|
+
options.credentials?.secretKey ??
|
|
19
|
+
envCredentials.secretKey,
|
|
20
|
+
contractCode: options.contractCode ??
|
|
21
|
+
options.credentials?.contractCode ??
|
|
22
|
+
envCredentials.contractCode,
|
|
23
|
+
};
|
|
24
24
|
}
|
|
25
25
|
async getAccessToken() {
|
|
26
26
|
this.token = await (0, monnify_helper_1.getValidMonnifyAccessToken)(this.token, () => (0, monnify_helper_1.fetchMonnifyToken)(this.baseUrl, this.credentials));
|
|
@@ -104,10 +104,6 @@ let MonnifyService = class MonnifyService {
|
|
|
104
104
|
verifyWebhookSignature(body, signature) {
|
|
105
105
|
return (0, monnify_helper_1.verifyMonnifyWebhookSignature)(body, signature, this.credentials.secretKey);
|
|
106
106
|
}
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
exports.MonnifyService = MonnifyService;
|
|
109
|
-
exports.MonnifyService = MonnifyService = __decorate([
|
|
110
|
-
(0, common_1.Injectable)(),
|
|
111
|
-
__metadata("design:paramtypes", [])
|
|
112
|
-
], MonnifyService);
|
|
113
109
|
//# sourceMappingURL=monnify.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monnify.service.js","sourceRoot":"","sources":["../../../src/lib/monnify/monnify.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"monnify.service.js","sourceRoot":"","sources":["../../../src/lib/monnify/monnify.service.ts"],"names":[],"mappings":";;;AAAA,4DAUiC;AAgBjC,MAAa,cAAc;IACR,OAAO,CAAS;IAChB,WAAW,CAAqB;IACzC,KAAK,CAAqB;IAElC,YAAY,UAAiC,EAAE;QAC7C,MAAM,WAAW,GAAG,IAAA,4CAA2B,EAC7C,OAAO,CAAC,WAAW;YACjB,OAAO,CAAC,GAAG,CAAC,mBAAmB;YAC/B,OAAO,CAAC,GAAG,CAAC,QAAQ,CACD,CAAC;QACxB,MAAM,cAAc,GAAG,IAAA,sCAAqB,EAAC,WAA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gB,CAAC,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,sBAAsB,CAC1B,KAA2B;QAE3B,OAAO,IAAI,CAAC,OAAO,CAAC,8BAA8B,EAAE;YAClD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,QAAQ,EAAE,KAAK;gBACf,GAAG,KAAK;aACT;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,KAA+B;QAE/B,OAAO,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE;YAC1C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC5B,YAAY,EAAE,KAAK;gBACnB,GAAG,OAAO;aACX,CAAC,CAAC;SACJ,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,KAAyB;QAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,iCAAiC,EAAE;YACrD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;IACL,CAAC;IAED,sBAAsB,CAAC,IAAa,EAAE,SAAiB;QACrD,OAAO,IAAA,8CAA6B,EAClC,IAAI,EACJ,SAAS,EACT,IAAI,CAAC,WAAW,CAAC,SAAS,CAC3B,CAAC;IACJ,CAAC;CACF;AAnKD,wCAmKC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { MonoEnvironment, MonoRequestContext, MonoRequestOptions } from './mono.types';
|
|
1
|
+
import type { MonoEnvironment, NormalizedMonoEnvironment, MonoRequestContext, MonoRequestOptions } from './mono.types';
|
|
2
2
|
export declare const MONO_BASE_URL = "https://api.withmono.com";
|
|
3
|
+
export declare const normalizeMonoEnvironment: (environment?: string) => NormalizedMonoEnvironment;
|
|
3
4
|
export declare const getMonoBaseUrl: (baseUrlOverride?: string) => string;
|
|
4
5
|
export declare const getMonoSecretKey: (environment: MonoEnvironment) => string | undefined;
|
|
5
6
|
export declare const assertMonoSecretKey: (secretKey: string) => string;
|