-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathUser.js
More file actions
652 lines (586 loc) · 15.4 KB
/
Copy pathUser.js
File metadata and controls
652 lines (586 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
const {
addUserKyc,
deleteExistingDocument,
updateUser,
getUserDuplicates,
swapDuplicateUsers,
_grabRefreshToken,
_oauthUser,
createNode,
verifyAchMfa,
getAllUserNodes,
getNode,
getUserTransactions,
triggerDummyTransactions,
generateUboForm,
getStatementsByUser,
getStatementsByNode,
shipCardNode,
resetCardNode,
verifyMicroDeposits,
reinitiateMicroDeposits,
updateNode,
deleteNode,
generateApplePayToken,
generateECashBarcode,
createTransaction,
getTransaction,
getAllNodeTransactions,
deleteTransaction,
commentOnStatus,
disputeCardTransaction,
getAllSubnets,
getSubnet,
createSubnet,
updateSubnet,
shipCard,
registerNewFingerprint,
supplyDevice2FA,
verifyFingerprint2FA,
getUser,
updateIpAddress,
createBatchTransactions,
getAllCardShipments,
getCardShipment,
deleteCardShipment
} = require('../constants/apiReqNames');
const apiRequests = require('../apiReqs/apiRequests');
const buildHeaders = require('../helpers/buildHeaders');
class User {
constructor({
data,
headerObj,
client
}) {
this.id = data._id;
this.body = data;
this.host = client.host;
this.fingerprint = headerObj.fingerprint;
this.ip_address = headerObj.ip_address;
this.oauth_key = '';
this.client = client;
this.headers = buildHeaders({
client_id: client.client_id,
client_secret: client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key
});
}
// PATCH ADD USER KYC
addUserKyc(bodyParams = {}) {
return apiRequests.user[addUserKyc]({
bodyParams,
userInfo: this
});
}
// PATCH DELETE EXISTING DOCUMENT
deleteExistingDocument(bodyParams = {}) {
return apiRequests.user[deleteExistingDocument]({
bodyParams,
userInfo: this
});
}
// PATCH UPDATE USER
updateUser(bodyParams = {}) {
return apiRequests.user[updateUser]({
bodyParams,
userInfo: this
});
}
/**
* GET ALL USER DUPLICATES
*
* @returns Promise
*
* [Get User Duplicates Docs]{@link https://docs.synapsefi.com/api-references/users/manage-duplicates#example-request}
*/
getUserDuplicates() {
const { page, per_page } = queryParams
return apiRequests.user[getUserDuplicates]({
userInfo: this
})
}
/**
* SWAP DUPLICATE USER
* @param {String} swap_to_user_id required: User ID you'd like to swap the open status with
*
* @returns Promise
*
* [Swap Duplicate User Docs]{@link https://docs.synapsefi.com/api-references/users/manage-duplicates#example-request-1}
*/
swapDuplicateUsers(swap_to_user_id) {
bodyParams = {
"swap_to_user_id":swap_to_user_id
}
return apiRequests.user[swapDuplicateUsers]({
bodyParams,
userInfo: this
})
}
// RETRIEVE REFRESH TOKEN
_grabRefreshToken() {
return apiRequests.client[getUser]({
user_id: this.id,
full_dehydrate: 'no',
headers: this.headers,
clientInfo: this.client
})
.then(({ data }) => {
return data.refresh_token;
});
}
// POST OAUTH USER
_oauthUser(bodyParams = {}) {
return apiRequests.user[_oauthUser]({
bodyParams,
userInfo: this
})
.then(({ data }) => {
this.oauth_key = data.oauth_key;
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key
});
return data;
});
}
// POST CREATE NODE
createNode(bodyParams = {}, idempotency_key = null) {
if (idempotency_key) {
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key,
idempotency_key
});
}
return apiRequests.user[createNode]({
bodyParams,
userInfo: this
});
}
// POST ACH-US MFA
// submit answer to a mfa question from bank login attempt
verifyAchMfa(access_token, mfa_answer, idempotency_key = null) {
if (idempotency_key) {
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key,
idempotency_key
});
}
return apiRequests.user[verifyAchMfa]({
access_token,
mfa_answer,
userInfo: this
});
}
// GET ALL USER NODES
getAllUserNodes(queryParams = {}) {
const { page, per_page, type } = queryParams;
return apiRequests.user[getAllUserNodes]({
page,
per_page,
type,
userInfo: this
});
}
// GET NODE W/ NODE_ID
getNode(node_id, queryParams = {}) {
const { full_dehydrate, force_refresh } = queryParams;
return apiRequests.user[getNode]({
node_id,
full_dehydrate,
force_refresh,
userInfo: this
});
}
// GET ALL USER TRANSACTIONS
getUserTransactions(queryParams = {}) {
const { page, per_page, filter } = queryParams;
return apiRequests.user[getUserTransactions]({
page,
per_page,
filter,
userInfo: this
});
}
// GET TRIGGER DUMMY TRANSACTIONS
triggerDummyTransactions(node_id, queryParams = {}) {
const { amount, foreign_transaction, is_credit, subnet_id, type } = queryParams;
return apiRequests.user[triggerDummyTransactions]({
node_id,
amount,
foreign_transaction,
is_credit,
subnet_id,
type,
userInfo: this
});
}
// PATCH GENERATE UBO FORM
generateUboForm(bodyParams) {
return apiRequests.user[generateUboForm]({
bodyParams,
userInfo: this
});
}
// GET STATEMENTS BY USER
getStatementsByUser(queryParams = {}) {
const { page, per_page } = queryParams;
return apiRequests.user[getStatementsByUser]({
page,
per_page,
userInfo: this
});
}
// GET STATEMENTS BY NODE
getStatementsByNode(node_id, queryParams = {}) {
const { page, per_page } = queryParams;
return apiRequests.user[getStatementsByNode]({
node_id,
page,
per_page,
userInfo: this
});
}
// PATCH SHIP DEBIT CARD NODE
shipCardNode(node_id, bodyParams) {
return apiRequests.user[shipDebitCard]({
node_id,
bodyParams,
userInfo: this
});
}
// PATCH RESET DEBIT CARD NODE
resetCardNode(node_id) {
return apiRequests.user[resetDebitCard]({
node_id,
userInfo: this
});
}
// PATCH VERIFY MICRO-DEPOSITS
verifyMicroDeposits(node_id, bodyParams) {
return apiRequests.user[verifyMicroDeposits]({
node_id,
bodyParams,
userInfo: this
});
}
// PATCH REINITIATE MICRO-DEPOSITS
reinitiateMicroDeposits(node_id) {
return apiRequests.user[reinitiateMicroDeposits]({
node_id,
userInfo: this
});
}
// PATCH UPDATE NODE
updateNode(node_id, bodyParams) {
return apiRequests.user[updateNode]({
node_id,
bodyParams,
userInfo: this
});
}
// DELETE NODE
deleteNode(node_id) {
return apiRequests.user[deleteNode]({
node_id,
userInfo: this
});
}
// PATCH GENERATE APPLE PAY TOKEN
generateApplePayToken(node_id, bodyParams) {
return apiRequests.user[generateApplePayToken]({
node_id,
bodyParams,
userInfo: this
});
}
// POST GENERATE ECASH BARCODE
generateECashBarcode(node_id, amount, currency, retailer_id) {
return apiRequests.user[generateECashBarcode]({
node_id,
bodyParams: {
amount: {
amount,
currency,
},
retailer_id,
},
userInfo: this
});
}
// POST CREATE TRANSACTION
createTransaction(node_id, bodyParams, idempotency_key = null) {
if (idempotency_key) {
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key,
idempotency_key
});
}
return apiRequests.user[createTransaction]({
node_id,
bodyParams,
userInfo: this
});
}
/**
*
* @param {String} node_id required: id of node on which to create bulk transactions
* @param {Object} bodyParams required: body of post request, must have transactions key, which is an array of transaction objects
* @param {Array} bodyParams.transactions
*
* @returns Promise
*
* Idempotency keys can be provided for each transaction, inside each transaction object's `extra` key.
*
* e.g. `{ transactions: [{ extra: { idempotency_key: 'idemPotKeyStr' } }] }`
*
* [Batch Transaction Docs]{@link https://docs.synapsefi.com/api-references/transactions/create-batch-transactions}
* [Trans Object Details]{@link https://docs.synapsefi.com/api-references/transactions/transaction-object-details}
*/
createBatchTransactions(node_id, bodyParams) {
return apiRequests.user[createBatchTransactions]({
node_id,
bodyParams,
userInfo: this
});
}
// GET TRANSACTION W/ TRANSACTION_ID
getTransaction(node_id, trans_id) {
return apiRequests.user[getTransaction]({
node_id,
trans_id,
userInfo: this
});
}
// GET ALL NODE TRANSACTIONS
getAllNodeTransactions(node_id, queryParams = {}) {
const { page, per_page, filter } = queryParams;
return apiRequests.user[getAllNodeTransactions]({
node_id,
page,
per_page,
filter,
userInfo: this
});
}
// DELETE TRANSACTION
deleteTransaction(node_id, trans_id) {
return apiRequests.user[deleteTransaction]({
node_id,
trans_id,
userInfo: this
});
}
// PATCH COMMENT ON STATUS
commentOnStatus(node_id, trans_id, bodyParams) {
return apiRequests.user[commentOnStatus]({
node_id,
trans_id,
bodyParams,
userInfo: this
});
}
// PATCH DISPUTE CARD TRANSACTION
disputeCardTransaction(node_id, trans_id, bodyParams) {
return apiRequests.user[disputeCardTransaction]({
node_id,
trans_id,
bodyParams,
userInfo: this
});
}
// GET ALL SUBNETS
getAllSubnets(node_id, queryParams = {}) {
const { page, per_page } = queryParams;
return apiRequests.user[getAllSubnets]({
node_id,
page,
per_page,
userInfo: this
});
}
// GET SUBNET W/ SUBNET_ID
getSubnet(node_id, subnet_id, queryParams = {}) {
const { full_dehydrate } = queryParams;
return apiRequests.user[getSubnet]({
node_id,
subnet_id,
full_dehydrate,
userInfo: this
});
}
// POST CREATE SUBNET
createSubnet(node_id, bodyParams, idempotency_key = null) {
if (idempotency_key) {
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key,
idempotency_key
});
}
return apiRequests.user[createSubnet]({
node_id,
bodyParams,
userInfo: this
});
}
// PATCH UPDATE SUBNET
updateSubnet(node_id, subnet_id, bodyParams = {}) {
return apiRequests.user[updateSubnet]({
node_id,
subnet_id,
bodyParams,
userInfo: this
});
}
// PATCH SHIP CARD SUBNET
shipCard(node_id, subnet_id, bodyParams ={}) {
return apiRequests.user[shipCard]({
node_id,
subnet_id,
bodyParams,
userInfo: this
});
}
/**
* GET ALL CARD SHIPMENTS
* @param {String} node_id required: id of node belonging to the subnet
* @param {String} subnet_id required: id of card subnet for the card shipments
* @param {Object} queryParams optional: body of post request, can contain page and per_page keys indicating the amount of card shipments returned
*
* @returns Promise
*
*
* [Get Card Shipment Docs]{@link https://docs.synapsefi.com/api-references/shipments/view-all-subnet-shipments}
*/
getAllCardShipments(node_id, subnet_id, queryParams={}) {
const { page, per_page } = queryParams
return apiRequests.user[getAllCardShipments]({
node_id,
subnet_id,
page,
per_page,
userInfo: this
})
}
/**
* GET A SINGLE CARD SHIPMENT
* @param {String} node_id required: id of node belonging to the subnet
* @param {String} subnet_id required: id of card subnet for the card shipments
* @param {Object} shipment_id requred: id of card shipment
*
* @returns Promise
*
*
* [Get Card Shipment Docs]{@link https://docs.synapsefi.com/api-references/shipments/view-shipment}
*/
getCardShipment(node_id, subnet_id, shipment_id) {
return apiRequests.user[getCardShipment]({
node_id,
subnet_id,
shipment_id,
userInfo: this
})
}
/**
* DELETE A SINGLE CARD SHIPMENT
* @param {String} node_id required: id of node belonging to the subnet
* @param {String} subnet_id required: id of card subnet for the card shipments
* @param {Object} shipment_id requred: id of card shipment
*
* @returns Promise
*
*
* [Get Card Shipment Docs]{@link https://docs.synapsefi.com/api-references/shipments/cancel-shipment}
*/
deleteCardShipment(node_id, subnet_id, shipment_id) {
return apiRequests.user[deleteCardShipment]({
node_id,
subnet_id,
shipment_id,
userInfo: this
})
}
// POST First call for registering new fingerprint
async registerNewFingerprint(fp) {
const refresh_token = await this._grabRefreshToken();
this.fingerprint = fp;
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key
});
return apiRequests.user[registerNewFingerprint]({
refresh_token,
userInfo: this
});
}
// POST Second call for registering new fingerprint
async supplyDevice2FA(fp, device) {
const refresh_token = await this._grabRefreshToken();
this.fingerprint = fp;
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key
});
return apiRequests.user[supplyDevice2FA]({
device,
refresh_token,
userInfo: this
});
}
// POST Final call for registering new fingerprint
async verifyFingerprint2FA(fp, validation_pin) {
const refresh_token = await this._grabRefreshToken();
this.fingerprint = fp;
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key
});
return apiRequests.user[verifyFingerprint2FA]({
validation_pin,
refresh_token,
userInfo: this
});
}
// UPDATE USER IP ADDRESS
updateIpAddress(ip) {
this.ip_address = ip;
this.headers = buildHeaders({
client_id: this.client.client_id,
client_secret: this.client.client_secret,
fingerprint: this.fingerprint,
ip_address: this.ip_address,
oauth_key: this.oauth_key
});
return this.headers;
}
}
module.exports = User;