blaaiz-nodejs-sdk 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Blaaiz
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,630 @@
1
+ # Blaaiz Node.js SDK
2
+
3
+ A comprehensive Node.js SDK for the Blaaiz RaaS (Remittance as a Service) API. This SDK provides easy-to-use methods for payment processing, collections, payouts, customer management, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install blaaiz-nodejs-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```javascript
14
+ const { Blaaiz } = require('blaaiz-nodejs-sdk');
15
+
16
+ // Initialize the SDK
17
+ const blaaiz = new Blaaiz('your-api-key-here', {
18
+ baseURL: 'https://api-dev.blaaiz.com', // Optional: defaults to dev environment
19
+ timeout: 30000 // Optional: request timeout in milliseconds
20
+ });
21
+
22
+ // Test the connection
23
+ const isConnected = await blaaiz.testConnection();
24
+ console.log('API Connected:', isConnected);
25
+ ```
26
+
27
+ ## Features
28
+
29
+ - **Customer Management**: Create, update, and manage customers with KYC verification
30
+ - **Collections**: Support for multiple collection methods (Open Banking, Card, Crypto, Bank Transfer)
31
+ - **Payouts**: Bank transfers and Interac payouts across multiple currencies
32
+ - **Virtual Bank Accounts**: Create and manage virtual accounts for NGN collections
33
+ - **Wallets**: Multi-currency wallet management
34
+ - **Transactions**: Transaction history and status tracking
35
+ - **Webhooks**: Webhook configuration and management
36
+ - **Files**: Document upload with pre-signed URLs
37
+ - **Fees**: Real-time fee calculations and breakdowns
38
+ - **Banks & Currencies**: Access to supported banks and currencies
39
+
40
+ ## Supported Currencies & Methods
41
+
42
+ ### Collections
43
+ - **CAD**: Interac (push mechanism)
44
+ - **NGN**: Bank Transfer (VBA) and Card Payment
45
+ - **USD**: Card Payment
46
+ - **EUR/GBP**: Open Banking
47
+
48
+ ### Payouts
49
+ - **Bank Transfer**: All supported currencies
50
+ - **Interac**: CAD transactions
51
+
52
+ ## API Reference
53
+
54
+ ### Customer Management
55
+
56
+ #### Create a Customer
57
+
58
+ ```javascript
59
+ const customer = await blaaiz.customers.create({
60
+ first_name: "John",
61
+ last_name: "Doe",
62
+ type: "individual", // or "business"
63
+ email: "john.doe@example.com",
64
+ country: "NG",
65
+ id_type: "passport", // drivers_license, passport, id_card, resident_permit
66
+ id_number: "A12345678",
67
+ // business_name: "Company Name" // Required if type is "business"
68
+ });
69
+
70
+ console.log('Customer ID:', customer.data.data.id);
71
+ ```
72
+
73
+ #### Get Customer
74
+
75
+ ```javascript
76
+ const customer = await blaaiz.customers.get('customer-id');
77
+ console.log('Customer:', customer.data);
78
+ ```
79
+
80
+ #### List All Customers
81
+
82
+ ```javascript
83
+ const customers = await blaaiz.customers.list();
84
+ console.log('Customers:', customers.data);
85
+ ```
86
+
87
+ #### Update Customer
88
+
89
+ ```javascript
90
+ const updatedCustomer = await blaaiz.customers.update('customer-id', {
91
+ first_name: "Jane",
92
+ email: "jane.doe@example.com"
93
+ });
94
+ ```
95
+
96
+ ### File Management & KYC
97
+
98
+ #### Upload Customer Documents
99
+
100
+ **Method 1: Complete File Upload (Recommended)**
101
+ ```javascript
102
+ // Option A: Upload from Buffer
103
+ const result = await blaaiz.customers.uploadFileComplete('customer-id', {
104
+ file: fileBuffer, // Buffer or Uint8Array
105
+ file_category: 'identity', // identity, proof_of_address, liveness_check
106
+ filename: 'passport.jpg', // Optional
107
+ contentType: 'image/jpeg' // Optional
108
+ });
109
+
110
+ // Option B: Upload from Base64 string
111
+ const result = await blaaiz.customers.uploadFileComplete('customer-id', {
112
+ file: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
113
+ file_category: 'identity'
114
+ });
115
+
116
+ // Option C: Upload from Data URL (with automatic content type detection)
117
+ const result = await blaaiz.customers.uploadFileComplete('customer-id', {
118
+ file: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
119
+ file_category: 'identity'
120
+ });
121
+
122
+ // Option D: Upload from Public URL (automatically downloads and uploads)
123
+ const result = await blaaiz.customers.uploadFileComplete('customer-id', {
124
+ file: 'https://example.com/documents/passport.jpg',
125
+ file_category: 'identity'
126
+ });
127
+
128
+ console.log('Upload complete:', result.data);
129
+ console.log('File ID:', result.file_id);
130
+ ```
131
+
132
+ **Method 2: Manual 3-Step Process**
133
+ ```javascript
134
+ // Step 1: Get pre-signed URL
135
+ const presignedUrl = await blaaiz.files.getPresignedUrl({
136
+ customer_id: 'customer-id',
137
+ file_category: 'identity' // identity, proof_of_address, liveness_check
138
+ });
139
+
140
+ // Step 2: Upload file to the pre-signed URL (implement your file upload logic)
141
+ // const uploadResponse = await uploadFileToUrl(presignedUrl.data.url, fileBuffer);
142
+
143
+ // Step 3: Associate file with customer
144
+ const fileAssociation = await blaaiz.customers.uploadFiles('customer-id', {
145
+ id_file: presignedUrl.data.file_id // Use the file_id from step 1
146
+ });
147
+ ```
148
+
149
+ > **Note**: The `uploadFileComplete` method is recommended as it handles all three steps automatically: getting the pre-signed URL, uploading the file to S3, and associating the file with the customer. It supports multiple file input formats:
150
+ > - **Buffer/Uint8Array**: Direct binary data
151
+ > - **Base64 string**: Plain base64 encoded data
152
+ > - **Data URL**: Complete data URL with mime type (e.g., `data:image/jpeg;base64,/9j/4AAQ...`)
153
+ > - **Public URL**: HTTP/HTTPS URL that will be downloaded automatically (supports redirects, content-type detection, and filename extraction)
154
+
155
+ ### Collections
156
+
157
+ #### Initiate Open Banking Collection (EUR/GBP)
158
+
159
+ ```javascript
160
+ const collection = await blaaiz.collections.initiate({
161
+ method: "open_banking",
162
+ amount: 100.00,
163
+ customer_id: "customer-id",
164
+ wallet_id: "wallet-id",
165
+ phone: "+1234567890" // Optional
166
+ });
167
+
168
+ console.log('Payment URL:', collection.data.url);
169
+ console.log('Transaction ID:', collection.data.transaction_id);
170
+ ```
171
+
172
+ #### Initiate Card Collection (NGN/USD)
173
+
174
+ ```javascript
175
+ const collection = await blaaiz.collections.initiate({
176
+ method: "card",
177
+ amount: 5000,
178
+ customer_id: "customer-id",
179
+ wallet_id: "wallet-id"
180
+ });
181
+
182
+ console.log('Payment URL:', collection.data.url);
183
+ ```
184
+
185
+ #### Crypto Collection
186
+
187
+ ```javascript
188
+ // Get available networks
189
+ const networks = await blaaiz.collections.getCryptoNetworks();
190
+ console.log('Available networks:', networks.data);
191
+
192
+ // Initiate crypto collection
193
+ const cryptoCollection = await blaaiz.collections.initiateCrypto({
194
+ amount: 100,
195
+ network: "ethereum",
196
+ token: "USDT",
197
+ wallet_id: "wallet-id"
198
+ });
199
+ ```
200
+
201
+ #### Attach Customer to Collection
202
+
203
+ ```javascript
204
+ const attachment = await blaaiz.collections.attachCustomer({
205
+ customer_id: "customer-id",
206
+ transaction_id: "transaction-id"
207
+ });
208
+ ```
209
+
210
+ ### Payouts
211
+
212
+ #### Bank Transfer Payout
213
+
214
+ ```javascript
215
+ const payout = await blaaiz.payouts.initiate({
216
+ wallet_id: "wallet-id",
217
+ customer_id: "customer-id",
218
+ method: "bank_transfer",
219
+ from_amount: 1000,
220
+ from_currency_id: "1", // NGN
221
+ to_currency_id: "1", // NGN
222
+ account_number: "0123456789",
223
+ bank_id: "1", // Required for NGN
224
+ phone_number: "+2348012345678"
225
+ });
226
+
227
+ console.log('Payout Status:', payout.data.transaction.status);
228
+ ```
229
+
230
+ #### Interac Payout (CAD)
231
+
232
+ ```javascript
233
+ const interacPayout = await blaaiz.payouts.initiate({
234
+ wallet_id: "wallet-id",
235
+ customer_id: "customer-id",
236
+ method: "interac",
237
+ from_amount: 100,
238
+ from_currency_id: "2", // CAD
239
+ to_currency_id: "2", // CAD
240
+ email: "recipient@example.com",
241
+ interac_first_name: "John",
242
+ interac_last_name: "Doe"
243
+ });
244
+ ```
245
+
246
+ ### Virtual Bank Accounts
247
+
248
+ #### Create Virtual Bank Account
249
+
250
+ ```javascript
251
+ const vba = await blaaiz.virtualBankAccounts.create({
252
+ wallet_id: "wallet-id",
253
+ account_name: "John Doe"
254
+ });
255
+
256
+ console.log('Account Number:', vba.data.account_number);
257
+ console.log('Bank Name:', vba.data.bank_name);
258
+ ```
259
+
260
+ #### List Virtual Bank Accounts
261
+
262
+ ```javascript
263
+ const vbas = await blaaiz.virtualBankAccounts.list("wallet-id");
264
+ console.log('Virtual Accounts:', vbas.data);
265
+ ```
266
+
267
+ ### Wallets
268
+
269
+ #### List All Wallets
270
+
271
+ ```javascript
272
+ const wallets = await blaaiz.wallets.list();
273
+ console.log('Wallets:', wallets.data);
274
+ ```
275
+
276
+ #### Get Specific Wallet
277
+
278
+ ```javascript
279
+ const wallet = await blaaiz.wallets.get("wallet-id");
280
+ console.log('Wallet Balance:', wallet.data.balance);
281
+ ```
282
+
283
+ ### Transactions
284
+
285
+ #### List Transactions
286
+
287
+ ```javascript
288
+ const transactions = await blaaiz.transactions.list({
289
+ page: 1,
290
+ limit: 10,
291
+ status: "SUCCESSFUL" // Optional filter
292
+ });
293
+
294
+ console.log('Transactions:', transactions.data);
295
+ ```
296
+
297
+ #### Get Transaction Details
298
+
299
+ ```javascript
300
+ const transaction = await blaaiz.transactions.get("transaction-id");
301
+ console.log('Transaction:', transaction.data);
302
+ ```
303
+
304
+ ### Banks & Currencies
305
+
306
+ #### List Banks
307
+
308
+ ```javascript
309
+ const banks = await blaaiz.banks.list();
310
+ console.log('Available Banks:', banks.data);
311
+ ```
312
+
313
+ #### Bank Account Lookup
314
+
315
+ ```javascript
316
+ const accountInfo = await blaaiz.banks.lookupAccount({
317
+ account_number: "0123456789",
318
+ bank_id: "1"
319
+ });
320
+
321
+ console.log('Account Name:', accountInfo.data.account_name);
322
+ ```
323
+
324
+ #### List Currencies
325
+
326
+ ```javascript
327
+ const currencies = await blaaiz.currencies.list();
328
+ console.log('Supported Currencies:', currencies.data);
329
+ ```
330
+
331
+ ### Fees
332
+
333
+ #### Get Fee Breakdown
334
+
335
+ ```javascript
336
+ const feeBreakdown = await blaaiz.fees.getBreakdown({
337
+ from_currency_id: "1", // NGN
338
+ to_currency_id: "2", // CAD
339
+ from_amount: 100000
340
+ });
341
+
342
+ console.log('You send:', feeBreakdown.data.you_send);
343
+ console.log('Recipient gets:', feeBreakdown.data.recipient_gets);
344
+ console.log('Total fees:', feeBreakdown.data.total_fees);
345
+ ```
346
+
347
+ ### Webhooks
348
+
349
+ #### Register Webhooks
350
+
351
+ ```javascript
352
+ const webhook = await blaaiz.webhooks.register({
353
+ collection_url: "https://your-domain.com/webhooks/collection",
354
+ payout_url: "https://your-domain.com/webhooks/payout"
355
+ });
356
+ ```
357
+
358
+ #### Get Webhook Configuration
359
+
360
+ ```javascript
361
+ const webhookConfig = await blaaiz.webhooks.get();
362
+ console.log('Webhook URLs:', webhookConfig.data);
363
+ ```
364
+
365
+ #### Replay Webhook
366
+
367
+ ```javascript
368
+ const replay = await blaaiz.webhooks.replay({
369
+ transaction_id: "transaction-id"
370
+ });
371
+ ```
372
+
373
+ ## Advanced Usage
374
+
375
+ ### Complete Payout Workflow
376
+
377
+ ```javascript
378
+ const completePayoutResult = await blaaiz.createCompleteePayout({
379
+ customerData: {
380
+ first_name: "John",
381
+ last_name: "Doe",
382
+ type: "individual",
383
+ email: "john@example.com",
384
+ country: "NG",
385
+ id_type: "passport",
386
+ id_number: "A12345678"
387
+ },
388
+ payoutData: {
389
+ wallet_id: "wallet-id",
390
+ method: "bank_transfer",
391
+ from_amount: 1000,
392
+ from_currency_id: "1",
393
+ to_currency_id: "1",
394
+ account_number: "0123456789",
395
+ bank_id: "1",
396
+ phone_number: "+2348012345678"
397
+ }
398
+ });
399
+
400
+ console.log('Customer ID:', completePayoutResult.customer_id);
401
+ console.log('Payout:', completePayoutResult.payout);
402
+ console.log('Fees:', completePayoutResult.fees);
403
+ ```
404
+
405
+ ### Complete Collection Workflow
406
+
407
+ ```javascript
408
+ const completeCollectionResult = await blaaiz.createCompleteCollection({
409
+ customerData: {
410
+ first_name: "Jane",
411
+ last_name: "Smith",
412
+ type: "individual",
413
+ email: "jane@example.com",
414
+ country: "NG",
415
+ id_type: "drivers_license",
416
+ id_number: "ABC123456"
417
+ },
418
+ collectionData: {
419
+ method: "card",
420
+ amount: 5000,
421
+ wallet_id: "wallet-id"
422
+ },
423
+ createVBA: true // Optionally create a virtual bank account
424
+ });
425
+
426
+ console.log('Customer ID:', completeCollectionResult.customer_id);
427
+ console.log('Collection:', completeCollectionResult.collection);
428
+ console.log('Virtual Account:', completeCollectionResult.virtual_account);
429
+ ```
430
+
431
+ ## Error Handling
432
+
433
+ The SDK uses a custom `BlaaizError` class that provides detailed error information:
434
+
435
+ ```javascript
436
+ try {
437
+ const customer = await blaaiz.customers.create(invalidData);
438
+ } catch (error) {
439
+ if (error instanceof BlaaizError) {
440
+ console.error('Blaaiz API Error:', error.message);
441
+ console.error('Status Code:', error.status);
442
+ console.error('Error Code:', error.code);
443
+ } else {
444
+ console.error('Unexpected Error:', error.message);
445
+ }
446
+ }
447
+ ```
448
+
449
+ ## Rate Limiting
450
+
451
+ The Blaaiz API has a rate limit of 100 requests per minute. The SDK automatically includes rate limit headers in responses:
452
+
453
+ - `X-RateLimit-Limit`: Maximum requests per minute
454
+ - `X-RateLimit-Remaining`: Remaining requests in current window
455
+ - `X-RateLimit-Reset`: When the rate limit resets
456
+
457
+ ## Webhook Handling
458
+
459
+ ### Webhook Signature Verification
460
+
461
+ The SDK provides built-in webhook signature verification to ensure webhook authenticity:
462
+
463
+ ```javascript
464
+ const { Blaaiz } = require('blaaiz-nodejs-sdk');
465
+
466
+ const blaaiz = new Blaaiz('your-api-key');
467
+
468
+ // Method 1: Verify signature manually
469
+ const isValid = blaaiz.webhooks.verifySignature(
470
+ payload, // Raw webhook payload (string or object)
471
+ signature, // Signature from webhook headers
472
+ webhookSecret // Your webhook secret key
473
+ );
474
+
475
+ if (isValid) {
476
+ console.log('Webhook signature is valid');
477
+ } else {
478
+ console.log('Invalid webhook signature');
479
+ }
480
+
481
+ // Method 2: Construct verified event (recommended)
482
+ try {
483
+ const event = blaaiz.webhooks.constructEvent(
484
+ payload, // Raw webhook payload
485
+ signature, // Signature from webhook headers
486
+ webhookSecret // Your webhook secret key
487
+ );
488
+
489
+ console.log('Verified event:', event);
490
+ // event.verified will be true
491
+ // event.timestamp will contain verification timestamp
492
+ } catch (error) {
493
+ console.error('Webhook verification failed:', error.message);
494
+ }
495
+ ```
496
+
497
+ ### Complete Express.js Webhook Handler
498
+
499
+ ```javascript
500
+ const express = require('express');
501
+ const { Blaaiz } = require('blaaiz-nodejs-sdk');
502
+
503
+ const app = express();
504
+ const blaaiz = new Blaaiz('your-api-key');
505
+
506
+ // Webhook secret (get this from your Blaaiz dashboard)
507
+ const WEBHOOK_SECRET = process.env.BLAAIZ_WEBHOOK_SECRET;
508
+
509
+ // Middleware to capture raw body for signature verification
510
+ app.use('/webhooks', express.raw({ type: 'application/json' }));
511
+
512
+ // Collection webhook with signature verification
513
+ app.post('/webhooks/collection', (req, res) => {
514
+ const signature = req.headers['x-blaaiz-signature'];
515
+ const payload = req.body.toString();
516
+
517
+ try {
518
+ // Verify webhook signature and construct event
519
+ const event = blaaiz.webhooks.constructEvent(payload, signature, WEBHOOK_SECRET);
520
+
521
+ console.log('Verified collection event:', {
522
+ transaction_id: event.transaction_id,
523
+ status: event.status,
524
+ amount: event.amount,
525
+ currency: event.currency,
526
+ verified: event.verified
527
+ });
528
+
529
+ // Process the collection
530
+ // Update your database, send notifications, etc.
531
+
532
+ res.status(200).json({ received: true });
533
+ } catch (error) {
534
+ console.error('Webhook verification failed:', error.message);
535
+ res.status(400).json({ error: 'Invalid signature' });
536
+ }
537
+ });
538
+
539
+ // Payout webhook with signature verification
540
+ app.post('/webhooks/payout', (req, res) => {
541
+ const signature = req.headers['x-blaaiz-signature'];
542
+ const payload = req.body.toString();
543
+
544
+ try {
545
+ // Verify webhook signature and construct event
546
+ const event = blaaiz.webhooks.constructEvent(payload, signature, WEBHOOK_SECRET);
547
+
548
+ console.log('Verified payout event:', {
549
+ transaction_id: event.transaction_id,
550
+ status: event.status,
551
+ recipient: event.recipient,
552
+ verified: event.verified
553
+ });
554
+
555
+ // Process the payout completion
556
+ // Update your database, send notifications, etc.
557
+
558
+ res.status(200).json({ received: true });
559
+ } catch (error) {
560
+ console.error('Webhook verification failed:', error.message);
561
+ res.status(400).json({ error: 'Invalid signature' });
562
+ }
563
+ });
564
+
565
+ app.listen(3000, () => {
566
+ console.log('Webhook server running on port 3000');
567
+ });
568
+ ```
569
+
570
+ ### Manual Signature Verification (Alternative)
571
+
572
+ If you prefer manual verification:
573
+
574
+ ```javascript
575
+ app.post('/webhooks/collection', (req, res) => {
576
+ const signature = req.headers['x-blaaiz-signature'];
577
+ const payload = req.body.toString();
578
+
579
+ // Verify signature manually
580
+ const isValid = blaaiz.webhooks.verifySignature(payload, signature, WEBHOOK_SECRET);
581
+
582
+ if (!isValid) {
583
+ console.error('Invalid webhook signature');
584
+ return res.status(400).json({ error: 'Invalid signature' });
585
+ }
586
+
587
+ // Parse payload manually
588
+ const event = JSON.parse(payload);
589
+ console.log('Collection received:', event);
590
+
591
+ res.status(200).json({ received: true });
592
+ });
593
+ ```
594
+
595
+ ## Environment Configuration
596
+
597
+ ```javascript
598
+ // Development
599
+ const blaaizDev = new Blaaiz('dev-api-key', {
600
+ baseURL: 'https://api-dev.blaaiz.com'
601
+ });
602
+
603
+ // Production (when available)
604
+ const blaaizProd = new Blaaiz('prod-api-key', {
605
+ baseURL: 'https://api.blaaiz.com'
606
+ });
607
+ ```
608
+
609
+ ## Best Practices
610
+
611
+ 1. **Always validate customer data before creating customers**
612
+ 2. **Use the fees API to calculate and display fees to users**
613
+ 3. **Always verify webhook signatures using the SDK's built-in methods**
614
+ 4. **Store customer IDs and transaction IDs for tracking**
615
+ 5. **Handle rate limiting gracefully with exponential backoff**
616
+ 6. **Use environment variables for API keys and webhook secrets**
617
+ 7. **Implement proper error handling and logging**
618
+ 8. **Test webhook endpoints thoroughly with signature verification**
619
+ 9. **Use raw body parsing for webhook endpoints to preserve signature integrity**
620
+ 10. **Return appropriate HTTP status codes from webhook handlers (200 for success, 400 for invalid signatures)**
621
+
622
+ ## Support
623
+
624
+ For support and additional documentation:
625
+ - Email: onboarding@blaaiz.com
626
+ - Documentation: https://docs.business.blaaiz.com
627
+
628
+ ## License
629
+
630
+ This SDK is provided under the MIT License
package/index.d.ts ADDED
@@ -0,0 +1,354 @@
1
+ // Type definitions for blaaiz-nodejs-sdk
2
+ // Project: https://github.com/blaaiz/nodejs-sdk
3
+ // Definitions by: Blaaiz Team
4
+
5
+ export interface BlaaizOptions {
6
+ baseURL?: string;
7
+ timeout?: number;
8
+ }
9
+
10
+ export interface BlaaizResponse<T = any> {
11
+ data: T;
12
+ status: number;
13
+ headers: { [key: string]: string };
14
+ }
15
+
16
+ export class BlaaizError extends Error {
17
+ public status: number | null;
18
+ public code: string;
19
+
20
+ constructor(message: string, status?: number | null, code?: string);
21
+ }
22
+
23
+ // Customer Types
24
+ export interface CustomerData {
25
+ first_name: string;
26
+ last_name: string;
27
+ business_name?: string;
28
+ type: 'individual' | 'business';
29
+ email: string;
30
+ country: string;
31
+ id_type: 'drivers_license' | 'passport' | 'id_card' | 'resident_permit' | 'certificate_of_incorporation';
32
+ id_number: string;
33
+ }
34
+
35
+ export interface Customer extends CustomerData {
36
+ id: string;
37
+ business_id: string;
38
+ verification_status: 'PENDING' | 'VERIFIED' | 'REJECTED';
39
+ }
40
+
41
+ export interface CustomerKYCData {
42
+ [key: string]: any;
43
+ }
44
+
45
+ export interface CustomerFileData {
46
+ id_file?: string;
47
+ proof_of_address_file?: string;
48
+ liveness_check_file?: string;
49
+ }
50
+
51
+ export interface FileUploadOptions {
52
+ file: Buffer | Uint8Array | string;
53
+ file_category: 'identity' | 'proof_of_address' | 'liveness_check';
54
+ filename?: string;
55
+ contentType?: string;
56
+ }
57
+
58
+ // Collection Types
59
+ export interface CollectionData {
60
+ method: 'open_banking' | 'card' | 'bank_transfer' | 'crypto';
61
+ amount: number;
62
+ customer_id?: string;
63
+ wallet_id: string;
64
+ phone?: string;
65
+ }
66
+
67
+ export interface CryptoCollectionData {
68
+ amount: number;
69
+ network: string;
70
+ token: string;
71
+ wallet_id: string;
72
+ customer_id?: string;
73
+ }
74
+
75
+ export interface CollectionResponse {
76
+ message: string;
77
+ transaction_id: string;
78
+ url?: string;
79
+ }
80
+
81
+ export interface AttachCustomerData {
82
+ customer_id: string;
83
+ transaction_id: string;
84
+ }
85
+
86
+ // Payout Types
87
+ export interface PayoutData {
88
+ wallet_id: string;
89
+ customer_id?: string;
90
+ method: 'bank_transfer' | 'interac';
91
+ from_amount: number;
92
+ to_amount?: number;
93
+ phone_number?: string;
94
+ from_currency_id: string;
95
+ to_currency_id: string;
96
+ account_number?: string;
97
+ bank_id?: string;
98
+ email?: string;
99
+ interac_first_name?: string;
100
+ interac_last_name?: string;
101
+ wallet_address?: string;
102
+ wallet_network?: string;
103
+ wallet_token?: string;
104
+ }
105
+
106
+ export interface PayoutResponse {
107
+ message: string;
108
+ transaction: Transaction;
109
+ }
110
+
111
+ // Transaction Types
112
+ export interface Transaction {
113
+ id: string;
114
+ business_id: string;
115
+ business_customer_id: string;
116
+ business_wallet_id: string;
117
+ status: 'PENDING' | 'SUCCESSFUL' | 'FAILED' | 'CANCELLED';
118
+ reference: string;
119
+ currency: string;
120
+ amount: number;
121
+ amount_without_fee: number;
122
+ fee: number;
123
+ rate: number;
124
+ date: string;
125
+ recipient?: {
126
+ id: string;
127
+ account_number: string;
128
+ account_name: string;
129
+ amount: number;
130
+ currency: string;
131
+ bank_name: string;
132
+ bank_code: string;
133
+ };
134
+ }
135
+
136
+ export interface TransactionFilters {
137
+ page?: number;
138
+ limit?: number;
139
+ status?: string;
140
+ currency?: string;
141
+ type?: 'COLLECTION' | 'PAYOUT';
142
+ }
143
+
144
+ // Wallet Types
145
+ export interface Wallet {
146
+ id: string;
147
+ currency: string;
148
+ balance: number;
149
+ status: string;
150
+ }
151
+
152
+ // Virtual Bank Account Types
153
+ export interface VirtualBankAccountData {
154
+ wallet_id: string;
155
+ account_name?: string;
156
+ }
157
+
158
+ export interface VirtualBankAccount {
159
+ id: string;
160
+ account_number: string;
161
+ account_name: string;
162
+ bank_name: string;
163
+ bank_code: string;
164
+ wallet_id: string;
165
+ }
166
+
167
+ // Bank Types
168
+ export interface Bank {
169
+ id: string;
170
+ name: string;
171
+ code: string;
172
+ country: string;
173
+ }
174
+
175
+ export interface BankAccountLookupData {
176
+ account_number: string;
177
+ bank_id: string;
178
+ }
179
+
180
+ export interface BankAccountInfo {
181
+ account_name: string;
182
+ account_number: string;
183
+ bank_name: string;
184
+ }
185
+
186
+ // Currency Types
187
+ export interface Currency {
188
+ id: string;
189
+ name: string;
190
+ code: string;
191
+ status: string;
192
+ }
193
+
194
+ // Fees Types
195
+ export interface FeeBreakdownData {
196
+ from_currency_id: string;
197
+ to_currency_id: string;
198
+ from_amount: number;
199
+ to_amount?: number;
200
+ }
201
+
202
+ export interface FeeBreakdown {
203
+ you_send: number;
204
+ total_amount_to_send: number;
205
+ recipient_gets: number;
206
+ total_fees: number;
207
+ exchange_rate?: number;
208
+ collection_fees?: any[];
209
+ payout_fees?: any[];
210
+ }
211
+
212
+ // File Types
213
+ export interface FileUploadData {
214
+ customer_id: string;
215
+ file_category: 'identity' | 'proof_of_address' | 'liveness_check';
216
+ }
217
+
218
+ export interface PreSignedUrlResponse {
219
+ url: string;
220
+ file_id: string;
221
+ headers: { [key: string]: string };
222
+ }
223
+
224
+ // Webhook Types
225
+ export interface WebhookData {
226
+ collection_url: string;
227
+ payout_url: string;
228
+ }
229
+
230
+ export interface WebhookReplayData {
231
+ transaction_id: string;
232
+ }
233
+
234
+ export interface WebhookEvent {
235
+ [key: string]: any;
236
+ verified: boolean;
237
+ timestamp: string;
238
+ }
239
+
240
+ // Service Classes
241
+ export declare class CustomerService {
242
+ constructor(client: any);
243
+ create(customerData: CustomerData): Promise<BlaaizResponse<{ data: Customer }>>;
244
+ list(): Promise<BlaaizResponse<Customer[]>>;
245
+ get(customerId: string): Promise<BlaaizResponse<Customer>>;
246
+ update(customerId: string, updateData: Partial<CustomerData>): Promise<BlaaizResponse<Customer>>;
247
+ addKYC(customerId: string, kycData: CustomerKYCData): Promise<BlaaizResponse<any>>;
248
+ uploadFiles(customerId: string, fileData: CustomerFileData): Promise<BlaaizResponse<any>>;
249
+ uploadFileComplete(customerId: string, fileOptions: FileUploadOptions): Promise<BlaaizResponse<any>>;
250
+ }
251
+
252
+ export declare class CollectionService {
253
+ constructor(client: any);
254
+ initiate(collectionData: CollectionData): Promise<BlaaizResponse<CollectionResponse>>;
255
+ initiateCrypto(cryptoData: CryptoCollectionData): Promise<BlaaizResponse<CollectionResponse>>;
256
+ attachCustomer(attachData: AttachCustomerData): Promise<BlaaizResponse<any>>;
257
+ getCryptoNetworks(): Promise<BlaaizResponse<any>>;
258
+ }
259
+
260
+ export declare class PayoutService {
261
+ constructor(client: any);
262
+ initiate(payoutData: PayoutData): Promise<BlaaizResponse<PayoutResponse>>;
263
+ }
264
+
265
+ export declare class WalletService {
266
+ constructor(client: any);
267
+ list(): Promise<BlaaizResponse<Wallet[]>>;
268
+ get(walletId: string): Promise<BlaaizResponse<Wallet>>;
269
+ }
270
+
271
+ export declare class VirtualBankAccountService {
272
+ constructor(client: any);
273
+ create(vbaData: VirtualBankAccountData): Promise<BlaaizResponse<VirtualBankAccount>>;
274
+ list(walletId?: string): Promise<BlaaizResponse<VirtualBankAccount[]>>;
275
+ get(vbaId: string): Promise<BlaaizResponse<VirtualBankAccount>>;
276
+ }
277
+
278
+ export declare class TransactionService {
279
+ constructor(client: any);
280
+ list(filters?: TransactionFilters): Promise<BlaaizResponse<Transaction[]>>;
281
+ get(transactionId: string): Promise<BlaaizResponse<Transaction>>;
282
+ }
283
+
284
+ export declare class BankService {
285
+ constructor(client: any);
286
+ list(): Promise<BlaaizResponse<Bank[]>>;
287
+ lookupAccount(lookupData: BankAccountLookupData): Promise<BlaaizResponse<BankAccountInfo>>;
288
+ }
289
+
290
+ export declare class CurrencyService {
291
+ constructor(client: any);
292
+ list(): Promise<BlaaizResponse<Currency[]>>;
293
+ }
294
+
295
+ export declare class FeesService {
296
+ constructor(client: any);
297
+ getBreakdown(feeData: FeeBreakdownData): Promise<BlaaizResponse<FeeBreakdown>>;
298
+ }
299
+
300
+ export declare class FileService {
301
+ constructor(client: any);
302
+ getPresignedUrl(fileData: FileUploadData): Promise<BlaaizResponse<PreSignedUrlResponse>>;
303
+ }
304
+
305
+ export declare class WebhookService {
306
+ constructor(client: any);
307
+ register(webhookData: WebhookData): Promise<BlaaizResponse<any>>;
308
+ get(): Promise<BlaaizResponse<WebhookData>>;
309
+ update(webhookData: Partial<WebhookData>): Promise<BlaaizResponse<any>>;
310
+ replay(replayData: WebhookReplayData): Promise<BlaaizResponse<any>>;
311
+ verifySignature(payload: string | object, signature: string, secret: string): boolean;
312
+ constructEvent(payload: string | object, signature: string, secret: string): WebhookEvent;
313
+ }
314
+
315
+ // Main SDK Class
316
+ export declare class Blaaiz {
317
+ public customers: CustomerService;
318
+ public collections: CollectionService;
319
+ public payouts: PayoutService;
320
+ public wallets: WalletService;
321
+ public virtualBankAccounts: VirtualBankAccountService;
322
+ public transactions: TransactionService;
323
+ public banks: BankService;
324
+ public currencies: CurrencyService;
325
+ public fees: FeesService;
326
+ public files: FileService;
327
+ public webhooks: WebhookService;
328
+
329
+ constructor(apiKey: string, options?: BlaaizOptions);
330
+
331
+ testConnection(): Promise<boolean>;
332
+
333
+ createCompleteePayout(payoutConfig: {
334
+ customerData?: CustomerData;
335
+ payoutData: PayoutData;
336
+ }): Promise<{
337
+ customer_id: string;
338
+ payout: PayoutResponse;
339
+ fees: FeeBreakdown;
340
+ }>;
341
+
342
+ createCompleteCollection(collectionConfig: {
343
+ customerData?: CustomerData;
344
+ collectionData: CollectionData;
345
+ createVBA?: boolean;
346
+ }): Promise<{
347
+ customer_id: string;
348
+ collection: CollectionResponse;
349
+ virtual_account?: VirtualBankAccount;
350
+ }>;
351
+ }
352
+
353
+ // Default export
354
+ export default Blaaiz;
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ module.exports = require('./src')
2
+ module.exports.default = module.exports.Blaaiz
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "blaaiz-nodejs-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official Node.js SDK for Blaaiz RaaS (Remittance as a Service) API",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "jest",
9
+ "test:watch": "jest --watch",
10
+ "test:coverage": "jest --coverage",
11
+ "lint": "eslint src/**/*.js",
12
+ "lint:fix": "eslint src/**/*.js --fix",
13
+ "docs": "jsdoc -d docs src/**/*.js",
14
+ "build": "npm run lint && npm test",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "blaaiz",
19
+ "payments",
20
+ "remittance",
21
+ "fintech",
22
+ "api",
23
+ "sdk",
24
+ "nodejs",
25
+ "payout",
26
+ "collection",
27
+ "raas",
28
+ "cryptocurrency",
29
+ "bank-transfer",
30
+ "interac",
31
+ "open-banking"
32
+ ],
33
+ "author": {
34
+ "name": "Blaaiz",
35
+ "email": "onboarding@blaaiz.com",
36
+ "url": "https://business.blaaiz.com"
37
+ },
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/blaaiz/nodejs-sdk.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/blaaiz/nodejs-sdk/issues"
45
+ },
46
+ "homepage": "https://docs.business.blaaiz.com",
47
+ "engines": {
48
+ "node": ">=12.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^18.19.119",
52
+ "eslint": "^8.40.0",
53
+ "eslint-config-standard": "^17.0.0",
54
+ "eslint-plugin-import": "^2.27.5",
55
+ "eslint-plugin-n": "^15.7.0",
56
+ "eslint-plugin-promise": "^6.1.1",
57
+ "jest": "^29.5.0",
58
+ "jsdoc": "^4.0.2"
59
+ },
60
+ "files": [
61
+ "index.js",
62
+ "index.d.ts",
63
+ "README.md",
64
+ "LICENSE"
65
+ ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ }
69
+ }