@cuenca-mx/cuenca-js 0.0.1-dev.2 → 0.0.1-dev.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -2
- package/build/{cjs/errors.js → errors/index.cjs} +0 -0
- package/build/{esm/errors.js → errors/index.mjs} +0 -0
- package/build/identities-7fc7251d.mjs +289 -0
- package/build/{cjs/queries-08df635b.js → identities-b7106a30.cjs} +20 -287
- package/build/{cjs/index.js → index.cjs} +169 -111
- package/build/{esm/index.js → index.mjs} +111 -19
- package/build/{cjs/jwt.js → jwt/index.cjs} +8 -3
- package/build/{esm/jwt.js → jwt/index.mjs} +3 -2
- package/build/queries-59c893b6.mjs +282 -0
- package/build/queries-bc02f9a8.cjs +296 -0
- package/build/{cjs/requests.js → requests/index.cjs} +4 -3
- package/build/{esm/requests.js → requests/index.mjs} +3 -3
- package/build/types/index.cjs +41 -0
- package/build/types/index.mjs +3 -0
- package/build/umd/cuenca.umd.js +1 -1
- package/build/{esm/walletTransactionRequest-18aad4dc.js → walletTransactionRequest-7334f8c5.mjs} +10 -3
- package/build/{cjs/walletTransactionRequest-82837ee6.js → walletTransactionRequest-a1851594.cjs} +28 -20
- package/package.json +28 -5
- package/build/cjs/data-c53f1052.js +0 -14
- package/build/cjs/types.js +0 -40
- package/build/esm/data-7d3d5fcc.js +0 -11
- package/build/esm/queries-716c6be4.js +0 -546
- package/build/esm/types.js +0 -3
|
@@ -3,18 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var axios = require('axios');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
6
|
+
var Buffer = require('buffer');
|
|
7
|
+
var errors_index = require('./errors/index.cjs');
|
|
8
|
+
var jwt_index = require('./jwt/index.cjs');
|
|
9
|
+
var identities = require('./identities-b7106a30.cjs');
|
|
10
|
+
var queries = require('./queries-bc02f9a8.cjs');
|
|
11
|
+
var walletTransactionRequest = require('./walletTransactionRequest-a1851594.cjs');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
14
15
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
16
|
+
var Buffer__default = /*#__PURE__*/_interopDefaultLegacy(Buffer);
|
|
17
|
+
|
|
18
|
+
/* global window */
|
|
19
|
+
|
|
20
|
+
const isBrowser =
|
|
21
|
+
typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
22
|
+
|
|
23
|
+
const isNode =
|
|
24
|
+
typeof process !== 'undefined' &&
|
|
25
|
+
Object.prototype.toString.call(process) === '[object process]';
|
|
26
|
+
|
|
27
|
+
const runtimeEnv = { isBrowser, isNode };
|
|
28
|
+
|
|
29
|
+
const name="@cuenca-mx/cuenca-js";const version="0.0.1-dev.22";const description="Cuenca client for JS";const main="./build/index.cjs";const module$1="./build/index.mjs";const browser="./build/umd/cuenca.umd.js";const files=["build/**/*"];const exports$1={".":{"import":"./build/index.mjs",require:"./build/index.cjs"},"./errors":{"import":"./build/errors/index.mjs",require:"./build/errors/index.cjs"},"./jwt":{"import":"./build/jwt/index.mjs",require:"./build/jwt/index.cjs"},"./requests":{"import":"./build/requests/index.mjs",require:"./build/requests/index.cjs"},"./types":{"import":"./build/types/index.mjs",require:"./build/types/index.cjs"}};const packageManager="yarn@3.0.2";const type="module";const repository={type:"git",url:"https://github.com/cuenca-mx/cuenca-js.git",directory:"packages/cuenca-js"};const keywords=["cuenca"];const license="MIT";const bugs={url:"https://github.com/cuenca-mx/cuenca-js/issues"};const homepage="https://cuenca.com";const scripts={build:"rm -rf build/ && yarn rollup --config",test:"yarn node --experimental-vm-modules $(yarn bin jest)",publish:"yarn build && yarn npm publish"};const devDependencies={"@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.1",jest:"^27.4.5",rollup:"^2.61.1","rollup-plugin-terser":"^7.0.2"};const dependencies={axios:"^0.24.0",buffer:"^6.0.3"};var pkg = {name:name,version:version,description:description,main:main,module:module$1,browser:browser,files:files,exports:exports$1,packageManager:packageManager,type:type,repository:repository,keywords:keywords,license:license,bugs:bugs,homepage:homepage,scripts:scripts,devDependencies:devDependencies,dependencies:dependencies};
|
|
15
30
|
|
|
16
31
|
class Client {
|
|
17
|
-
constructor({ apiKey, apiSecret, phase =
|
|
32
|
+
constructor({ apiKey, apiSecret, phase = identities.Phase.Sandbox } = {}) {
|
|
18
33
|
this.phase = phase;
|
|
19
34
|
this.basicAuth = { apiKey, apiSecret };
|
|
20
35
|
this.jwtToken = null;
|
|
@@ -32,8 +47,9 @@ class Client {
|
|
|
32
47
|
get authHeader() {
|
|
33
48
|
const { apiKey, apiSecret } = this.basicAuth;
|
|
34
49
|
if (!apiKey || !apiSecret) return '';
|
|
35
|
-
return `Basic ${Buffer.from(
|
|
36
|
-
|
|
50
|
+
return `Basic ${Buffer__default["default"].Buffer.from(
|
|
51
|
+
`${apiKey}:${apiSecret}`,
|
|
52
|
+
'utf-8',
|
|
37
53
|
).toString('base64')}`;
|
|
38
54
|
}
|
|
39
55
|
|
|
@@ -87,7 +103,7 @@ class Client {
|
|
|
87
103
|
|
|
88
104
|
if (phase) this.phase = phase;
|
|
89
105
|
|
|
90
|
-
if (useJwt) this.jwtToken = await
|
|
106
|
+
if (useJwt) this.jwtToken = await jwt_index.Jwt.create(this);
|
|
91
107
|
|
|
92
108
|
if (loginToken) {
|
|
93
109
|
this.addHeadersToRequest({ 'X-Cuenca-LoginToken': loginToken });
|
|
@@ -113,20 +129,27 @@ class Client {
|
|
|
113
129
|
async request({
|
|
114
130
|
endpoint,
|
|
115
131
|
data = null,
|
|
116
|
-
format =
|
|
132
|
+
format = identities.FileFormat.Json,
|
|
117
133
|
method = 'GET',
|
|
118
134
|
params = null,
|
|
119
135
|
}) {
|
|
120
136
|
const headers = {
|
|
121
137
|
Authorization: this.authHeader,
|
|
122
|
-
'X-User-Agent': `cuenca-js/0.0.1`, // TODO: Change for client version
|
|
123
138
|
'Content-Type': 'application/json',
|
|
124
139
|
Accept: `application/${format.value}`,
|
|
125
140
|
};
|
|
126
141
|
|
|
142
|
+
if (runtimeEnv.isNode) {
|
|
143
|
+
headers['User-Agent'] = `cuenca-js/${pkg.version}`;
|
|
144
|
+
} else if (runtimeEnv.isBrowser) {
|
|
145
|
+
// Cannot set User-Agent header on browsers
|
|
146
|
+
// https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
|
|
147
|
+
headers['X-User-Agent'] = `cuenca-js/${pkg.version}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
127
150
|
if (this.jwtToken) {
|
|
128
151
|
if (this.jwtToken.isExpired) {
|
|
129
|
-
this.jwtToken = await
|
|
152
|
+
this.jwtToken = await jwt_index.Jwt.create(this);
|
|
130
153
|
}
|
|
131
154
|
headers['X-Cuenca-Token'] = this.jwtToken.token;
|
|
132
155
|
}
|
|
@@ -154,16 +177,16 @@ class Client {
|
|
|
154
177
|
response = await this._session.request({ baseURL: this.origin });
|
|
155
178
|
} catch (error) {
|
|
156
179
|
if (error.response) {
|
|
157
|
-
throw new
|
|
180
|
+
throw new errors_index.CuencaResponseException(
|
|
158
181
|
error.response.data,
|
|
159
182
|
error.response.status,
|
|
160
183
|
);
|
|
161
184
|
} else if (error.request) {
|
|
162
|
-
throw new
|
|
185
|
+
throw new errors_index.CuencaException(
|
|
163
186
|
`No response received: ${error.errno}: ${error.code}`,
|
|
164
187
|
);
|
|
165
188
|
} else {
|
|
166
|
-
throw new
|
|
189
|
+
throw new errors_index.CuencaException(error.message);
|
|
167
190
|
}
|
|
168
191
|
} finally {
|
|
169
192
|
headersInterceptor.eject();
|
|
@@ -177,7 +200,7 @@ class Client {
|
|
|
177
200
|
class Account {
|
|
178
201
|
constructor({ accountNumber, createdAt, id, institutionName, name, userId }) {
|
|
179
202
|
this.accountNumber = accountNumber;
|
|
180
|
-
this.createdAt =
|
|
203
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
181
204
|
this.id = id;
|
|
182
205
|
this.institutionName = institutionName;
|
|
183
206
|
this.name = name;
|
|
@@ -197,12 +220,12 @@ class Account {
|
|
|
197
220
|
|
|
198
221
|
class ApiKey {
|
|
199
222
|
constructor({ createdAt, deactivatedAt, id, secret, userId, updatedAt }) {
|
|
200
|
-
this.createdAt =
|
|
201
|
-
this.deactivatedAt =
|
|
223
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
224
|
+
this.deactivatedAt = identities.dateToUTC(deactivatedAt);
|
|
202
225
|
this.id = id;
|
|
203
226
|
this.secret = secret;
|
|
204
227
|
this.userId = userId;
|
|
205
|
-
this.updatedAt =
|
|
228
|
+
this.updatedAt = identities.dateToUTC(updatedAt);
|
|
206
229
|
}
|
|
207
230
|
|
|
208
231
|
static fromObject = ({ id, secret, ...obj }) =>
|
|
@@ -216,7 +239,7 @@ class ApiKey {
|
|
|
216
239
|
});
|
|
217
240
|
|
|
218
241
|
get isActive() {
|
|
219
|
-
const todayUTC =
|
|
242
|
+
const todayUTC = identities.dateToUTC(Date.now());
|
|
220
243
|
return (
|
|
221
244
|
!this.deactivatedAt || this.deactivatedAt.getTime() > todayUTC.getTime()
|
|
222
245
|
);
|
|
@@ -226,7 +249,7 @@ class ApiKey {
|
|
|
226
249
|
class Arpc {
|
|
227
250
|
constructor({ arpc, createdAt, cardUri, isValidArqc }) {
|
|
228
251
|
this.arpc = arpc;
|
|
229
|
-
this.createdAt =
|
|
252
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
230
253
|
this.cardUri = cardUri;
|
|
231
254
|
this.isValidArqc = isValidArqc;
|
|
232
255
|
}
|
|
@@ -253,9 +276,9 @@ class BalanceEntry {
|
|
|
253
276
|
rollingBalance,
|
|
254
277
|
}) {
|
|
255
278
|
this.amount = amount;
|
|
256
|
-
this.createdAt =
|
|
279
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
257
280
|
this.descriptor = descriptor;
|
|
258
|
-
this.entryType =
|
|
281
|
+
this.entryType = identities.enumValueFromString(identities.EntryType, entryType);
|
|
259
282
|
this.fundingInstrumentUri = fundingInstrumentUri;
|
|
260
283
|
this.id = id;
|
|
261
284
|
this.name = name;
|
|
@@ -280,9 +303,9 @@ class BalanceEntry {
|
|
|
280
303
|
class Transaction {
|
|
281
304
|
constructor({ amount, createdAt, descriptor, status, userId }) {
|
|
282
305
|
this.amount = amount;
|
|
283
|
-
this.createdAt =
|
|
306
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
284
307
|
this.descriptor = descriptor;
|
|
285
|
-
this.status =
|
|
308
|
+
this.status = identities.enumValueFromString(identities.TransactionStatus, status);
|
|
286
309
|
this.userId = userId;
|
|
287
310
|
}
|
|
288
311
|
}
|
|
@@ -298,7 +321,13 @@ class BillPayment extends Transaction {
|
|
|
298
321
|
status,
|
|
299
322
|
userId,
|
|
300
323
|
}) {
|
|
301
|
-
super({
|
|
324
|
+
super({
|
|
325
|
+
amount,
|
|
326
|
+
createdAt,
|
|
327
|
+
descriptor,
|
|
328
|
+
status,
|
|
329
|
+
userId,
|
|
330
|
+
});
|
|
302
331
|
this.accountNumber = accountNumber;
|
|
303
332
|
this.id = id;
|
|
304
333
|
this.providerUri = providerUri;
|
|
@@ -333,18 +362,18 @@ class Card {
|
|
|
333
362
|
updatedAt,
|
|
334
363
|
userId,
|
|
335
364
|
}) {
|
|
336
|
-
this.createdAt =
|
|
365
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
337
366
|
this.cvv2 = cvv2;
|
|
338
367
|
this.expMonth = expMonth;
|
|
339
368
|
this.expYear = expYear;
|
|
340
|
-
this.fundingType =
|
|
369
|
+
this.fundingType = identities.enumValueFromString(identities.CardFundingType, fundingType);
|
|
341
370
|
this.id = id;
|
|
342
|
-
this.issuer =
|
|
371
|
+
this.issuer = identities.enumValueFromString(identities.CardIssuer, issuer);
|
|
343
372
|
this.number = number;
|
|
344
373
|
this.pin = pin;
|
|
345
|
-
this.status =
|
|
346
|
-
this.type =
|
|
347
|
-
this.updatedAt =
|
|
374
|
+
this.status = identities.enumValueFromString(identities.CardStatus, status);
|
|
375
|
+
this.type = identities.enumValueFromString(identities.CardType, type);
|
|
376
|
+
this.updatedAt = identities.dateToUTC(updatedAt);
|
|
348
377
|
this.userId = userId;
|
|
349
378
|
}
|
|
350
379
|
|
|
@@ -378,7 +407,7 @@ class Card {
|
|
|
378
407
|
class CardActivation {
|
|
379
408
|
constructor({ cardUri, createdAt, id, ipAddress, success, userId }) {
|
|
380
409
|
this.cardUri = cardUri;
|
|
381
|
-
this.createdAt =
|
|
410
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
382
411
|
this.id = id;
|
|
383
412
|
this.ipAddress = ipAddress;
|
|
384
413
|
this.success = success;
|
|
@@ -412,15 +441,21 @@ class CardTransaction extends Transaction {
|
|
|
412
441
|
type,
|
|
413
442
|
userId,
|
|
414
443
|
}) {
|
|
415
|
-
super({
|
|
416
|
-
|
|
444
|
+
super({
|
|
445
|
+
amount,
|
|
446
|
+
createdAt,
|
|
447
|
+
descriptor,
|
|
448
|
+
status,
|
|
449
|
+
userId,
|
|
450
|
+
});
|
|
451
|
+
this.cardErrorType = identities.enumValueFromString(identities.CardErrorType, cardErrorType);
|
|
417
452
|
this.cardLastFour = cardLastFour;
|
|
418
|
-
this.cardType =
|
|
453
|
+
this.cardType = identities.enumValueFromString(identities.CardType, cardType);
|
|
419
454
|
this.cardUri = cardUri;
|
|
420
455
|
this.metadata = metadata;
|
|
421
456
|
this.network = network;
|
|
422
457
|
this.relatedCardTransactionsUris = relatedCardTransactionsUris;
|
|
423
|
-
this.type =
|
|
458
|
+
this.type = identities.enumValueFromString(identities.CardTransactionType, type);
|
|
424
459
|
}
|
|
425
460
|
|
|
426
461
|
static fromObject = ({
|
|
@@ -464,10 +499,10 @@ class CardValidation {
|
|
|
464
499
|
isValidPinBlock,
|
|
465
500
|
userId,
|
|
466
501
|
}) {
|
|
467
|
-
this.cardStatus =
|
|
468
|
-
this.cardType =
|
|
502
|
+
this.cardStatus = identities.enumValueFromString(identities.CardStatus, cardStatus);
|
|
503
|
+
this.cardType = identities.enumValueFromString(identities.CardType, cardType);
|
|
469
504
|
this.cardUri = cardUri;
|
|
470
|
-
this.createdAt =
|
|
505
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
471
506
|
this.isExpired = isExpired;
|
|
472
507
|
this.isPinAttemptsExceeded = isPinAttemptsExceeded;
|
|
473
508
|
this.isValidCvv = isValidCvv;
|
|
@@ -495,7 +530,7 @@ class CardValidation {
|
|
|
495
530
|
});
|
|
496
531
|
|
|
497
532
|
get isActive() {
|
|
498
|
-
return this.cardStatus ===
|
|
533
|
+
return this.cardStatus === identities.CardStatus.Active;
|
|
499
534
|
}
|
|
500
535
|
}
|
|
501
536
|
|
|
@@ -509,9 +544,15 @@ class Commission extends Transaction {
|
|
|
509
544
|
type,
|
|
510
545
|
userId,
|
|
511
546
|
}) {
|
|
512
|
-
super({
|
|
547
|
+
super({
|
|
548
|
+
amount,
|
|
549
|
+
createdAt,
|
|
550
|
+
descriptor,
|
|
551
|
+
status,
|
|
552
|
+
userId,
|
|
553
|
+
});
|
|
513
554
|
this.relatedTransactionUri = relatedTransactionUri;
|
|
514
|
-
this.type =
|
|
555
|
+
this.type = identities.enumValueFromString(identities.CommissionType, type);
|
|
515
556
|
}
|
|
516
557
|
|
|
517
558
|
static fromObject = ({ amount, descriptor, status, type, ...obj }) =>
|
|
@@ -538,9 +579,15 @@ class Deposit extends Transaction {
|
|
|
538
579
|
trackingKey,
|
|
539
580
|
userId,
|
|
540
581
|
}) {
|
|
541
|
-
super({
|
|
582
|
+
super({
|
|
583
|
+
amount,
|
|
584
|
+
createdAt,
|
|
585
|
+
descriptor,
|
|
586
|
+
status,
|
|
587
|
+
userId,
|
|
588
|
+
});
|
|
542
589
|
this.id = id;
|
|
543
|
-
this.network =
|
|
590
|
+
this.network = identities.enumValueFromString(identities.DepositNetwork, network);
|
|
544
591
|
this.sourceUri = sourceUri;
|
|
545
592
|
this.trackingKey = trackingKey;
|
|
546
593
|
}
|
|
@@ -570,11 +617,11 @@ class LoginToken {
|
|
|
570
617
|
class Wallet {
|
|
571
618
|
constructor({ balance, createdAt, deactivatedAt, id, userId, updatedAt }) {
|
|
572
619
|
this.balance = balance;
|
|
573
|
-
this.createdAt =
|
|
574
|
-
this.deactivatedAt =
|
|
620
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
621
|
+
this.deactivatedAt = identities.dateToUTC(deactivatedAt);
|
|
575
622
|
this.id = id;
|
|
576
623
|
this.userId = userId;
|
|
577
|
-
this.updatedAt =
|
|
624
|
+
this.updatedAt = identities.dateToUTC(updatedAt);
|
|
578
625
|
}
|
|
579
626
|
}
|
|
580
627
|
|
|
@@ -591,10 +638,17 @@ class Saving extends Wallet {
|
|
|
591
638
|
userId,
|
|
592
639
|
updatedAt,
|
|
593
640
|
}) {
|
|
594
|
-
super({
|
|
595
|
-
|
|
641
|
+
super({
|
|
642
|
+
balance,
|
|
643
|
+
createdAt,
|
|
644
|
+
deactivatedAt,
|
|
645
|
+
id,
|
|
646
|
+
userId,
|
|
647
|
+
updatedAt,
|
|
648
|
+
});
|
|
649
|
+
this.category = identities.enumValueFromString(identities.SavingCategory, category);
|
|
596
650
|
this.goalAmount = goalAmount;
|
|
597
|
-
this.goalDate =
|
|
651
|
+
this.goalDate = identities.dateToUTC(goalDate);
|
|
598
652
|
this.name = name;
|
|
599
653
|
}
|
|
600
654
|
|
|
@@ -616,7 +670,7 @@ class Saving extends Wallet {
|
|
|
616
670
|
const categoriesFromString = (categoriesList) => {
|
|
617
671
|
if (categoriesList == null) return [];
|
|
618
672
|
return categoriesList.map((category) =>
|
|
619
|
-
|
|
673
|
+
identities.enumValueFromString(identities.ServiceProviderCategory, category),
|
|
620
674
|
);
|
|
621
675
|
};
|
|
622
676
|
|
|
@@ -639,7 +693,7 @@ class ServiceProvider {
|
|
|
639
693
|
|
|
640
694
|
class Statement {
|
|
641
695
|
constructor({ createdAt, id, month, year }) {
|
|
642
|
-
this.createdAt =
|
|
696
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
643
697
|
this.id = id;
|
|
644
698
|
this.month = month;
|
|
645
699
|
this.year = year;
|
|
@@ -670,15 +724,21 @@ class Transfer extends Transaction {
|
|
|
670
724
|
updatedAt,
|
|
671
725
|
userId,
|
|
672
726
|
}) {
|
|
673
|
-
super({
|
|
727
|
+
super({
|
|
728
|
+
amount,
|
|
729
|
+
createdAt,
|
|
730
|
+
descriptor,
|
|
731
|
+
status,
|
|
732
|
+
userId,
|
|
733
|
+
});
|
|
674
734
|
this.accountNumber = accountNumber;
|
|
675
735
|
this.destinationUri = destinationUri;
|
|
676
736
|
this.id = id;
|
|
677
737
|
this.idempotencyKey = idempotencyKey;
|
|
678
|
-
this.network =
|
|
738
|
+
this.network = identities.enumValueFromString(identities.TransferNetwork, network);
|
|
679
739
|
this.recipientName = recipientName;
|
|
680
740
|
this.trackingKey = trackingKey;
|
|
681
|
-
this.updatedAt =
|
|
741
|
+
this.updatedAt = identities.dateToUTC(updatedAt);
|
|
682
742
|
}
|
|
683
743
|
|
|
684
744
|
static fromObject = ({ amount, descriptor, id, network, status, ...obj }) =>
|
|
@@ -699,12 +759,23 @@ class Transfer extends Transaction {
|
|
|
699
759
|
});
|
|
700
760
|
}
|
|
701
761
|
|
|
762
|
+
class User {
|
|
763
|
+
constructor({ termsOfService }) {
|
|
764
|
+
this.termsOfService = identities.TOSAgreements.fromObject(termsOfService);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
static fromObject = ({ ...obj }) =>
|
|
768
|
+
new User({
|
|
769
|
+
termsOfService: obj.terms_of_service,
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
|
|
702
773
|
class UserCredential {
|
|
703
774
|
constructor({ createdAt, id, isActive, updatedAt }) {
|
|
704
|
-
this.createdAt =
|
|
775
|
+
this.createdAt = identities.dateToUTC(createdAt);
|
|
705
776
|
this.id = id;
|
|
706
777
|
this.isActive = isActive;
|
|
707
|
-
this.updatedAt =
|
|
778
|
+
this.updatedAt = identities.dateToUTC(updatedAt);
|
|
708
779
|
}
|
|
709
780
|
|
|
710
781
|
static fromObject = ({ id, ...obj }) =>
|
|
@@ -719,7 +790,7 @@ class UserCredential {
|
|
|
719
790
|
class UserLogin {
|
|
720
791
|
constructor({ id, lastLoginAt, success }) {
|
|
721
792
|
this.id = id;
|
|
722
|
-
this.lastLoginAt =
|
|
793
|
+
this.lastLoginAt = identities.dateToUTC(lastLoginAt);
|
|
723
794
|
this.success = success;
|
|
724
795
|
}
|
|
725
796
|
|
|
@@ -742,10 +813,16 @@ class WalletTransaction extends Transaction {
|
|
|
742
813
|
userId,
|
|
743
814
|
walletUri,
|
|
744
815
|
}) {
|
|
745
|
-
super({
|
|
816
|
+
super({
|
|
817
|
+
amount,
|
|
818
|
+
createdAt,
|
|
819
|
+
descriptor,
|
|
820
|
+
status,
|
|
821
|
+
userId,
|
|
822
|
+
});
|
|
746
823
|
this.id = id;
|
|
747
|
-
this.transactionType =
|
|
748
|
-
|
|
824
|
+
this.transactionType = identities.enumValueFromString(
|
|
825
|
+
identities.WalletTransactionType,
|
|
749
826
|
transactionType,
|
|
750
827
|
);
|
|
751
828
|
this.walletUri = walletUri;
|
|
@@ -781,16 +858,22 @@ class WhatsAppTransfer extends Transaction {
|
|
|
781
858
|
updatedAt,
|
|
782
859
|
userId,
|
|
783
860
|
}) {
|
|
784
|
-
super({
|
|
861
|
+
super({
|
|
862
|
+
amount,
|
|
863
|
+
createdAt,
|
|
864
|
+
descriptor,
|
|
865
|
+
status,
|
|
866
|
+
userId,
|
|
867
|
+
});
|
|
785
868
|
this.claimUrl = claimUrl;
|
|
786
869
|
this.destinationUri = destinationUri;
|
|
787
870
|
this.id = id;
|
|
788
|
-
this.expiresAt =
|
|
789
|
-
this.network =
|
|
871
|
+
this.expiresAt = identities.dateToUTC(expiresAt);
|
|
872
|
+
this.network = identities.enumValueFromString(identities.TransferNetwork, network);
|
|
790
873
|
this.phoneNumber = phoneNumber;
|
|
791
874
|
this.recipientName = recipientName;
|
|
792
875
|
this.trackingKey = trackingKey;
|
|
793
|
-
this.updatedAt =
|
|
876
|
+
this.updatedAt = identities.dateToUTC(updatedAt);
|
|
794
877
|
}
|
|
795
878
|
|
|
796
879
|
static fromObject = ({ amount, descriptor, id, network, status, ...obj }) =>
|
|
@@ -842,6 +925,7 @@ const getModelFromPath = (path, obj) => {
|
|
|
842
925
|
service_providers: () => ServiceProvider.fromObject(obj),
|
|
843
926
|
statements: () => Statement.fromObject(obj),
|
|
844
927
|
transfers: () => Transfer.fromObject(obj),
|
|
928
|
+
users: () => User.fromObject(obj),
|
|
845
929
|
user_credentials: () => UserCredential.fromObject(obj),
|
|
846
930
|
user_logins: () => UserLogin.fromObject(obj),
|
|
847
931
|
wallet_transactions: () => WalletTransaction.fromObject(obj),
|
|
@@ -931,8 +1015,8 @@ const Queryable = (SuperClass) =>
|
|
|
931
1015
|
params: queryParams.toParams(),
|
|
932
1016
|
});
|
|
933
1017
|
|
|
934
|
-
if (!items || !items.length) throw new
|
|
935
|
-
if (items.length > 1) throw new
|
|
1018
|
+
if (!items || !items.length) throw new errors_index.NoResultFound();
|
|
1019
|
+
if (items.length > 1) throw new errors_index.MultipleResultsFound();
|
|
936
1020
|
|
|
937
1021
|
const [item] = items;
|
|
938
1022
|
const model = getModelFromPath(this.path, item);
|
|
@@ -1267,12 +1351,12 @@ class StatementResource extends mix(Resource).with(Downlodable, Queryable) {
|
|
|
1267
1351
|
}
|
|
1268
1352
|
|
|
1269
1353
|
async pdf(id) {
|
|
1270
|
-
const byteString = await this._download(id,
|
|
1354
|
+
const byteString = await this._download(id, identities.FileFormat.Pdf);
|
|
1271
1355
|
return byteString;
|
|
1272
1356
|
}
|
|
1273
1357
|
|
|
1274
1358
|
async xml(id) {
|
|
1275
|
-
const byteString = await this._download(id,
|
|
1359
|
+
const byteString = await this._download(id, identities.FileFormat.Xml);
|
|
1276
1360
|
return byteString;
|
|
1277
1361
|
}
|
|
1278
1362
|
}
|
|
@@ -1351,7 +1435,7 @@ class TransferResource extends mix(Resource).with(
|
|
|
1351
1435
|
}
|
|
1352
1436
|
|
|
1353
1437
|
static _genIdempotencyKey(accountNumber, amount) {
|
|
1354
|
-
const [date] =
|
|
1438
|
+
const [date] = identities.dateToUTC(Date.now()).toISOString().split('T');
|
|
1355
1439
|
return `${date}:${accountNumber}:${amount}`;
|
|
1356
1440
|
}
|
|
1357
1441
|
}
|
|
@@ -1383,7 +1467,7 @@ class UserLoginResource extends mix(Resource).with(Creatable, Deactivable) {
|
|
|
1383
1467
|
async create(password, userId) {
|
|
1384
1468
|
const request = new walletTransactionRequest.UserLoginRequest(password, userId);
|
|
1385
1469
|
const userLogin = await this._create(request.toObject());
|
|
1386
|
-
if (!userLogin.success) throw new
|
|
1470
|
+
if (!userLogin.success) throw new errors_index.InvalidPassword();
|
|
1387
1471
|
|
|
1388
1472
|
// Set login id to headers
|
|
1389
1473
|
this.loginIdInHeaders = this.client.addHeadersToRequest({
|
|
@@ -1403,6 +1487,18 @@ class UserLoginResource extends mix(Resource).with(Creatable, Deactivable) {
|
|
|
1403
1487
|
}
|
|
1404
1488
|
}
|
|
1405
1489
|
|
|
1490
|
+
class UserResourse extends mix(Resource).with(Updateable) {
|
|
1491
|
+
constructor(client) {
|
|
1492
|
+
super('user', Object, client);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
async update({ termsOfService, userId = 'me' }) {
|
|
1496
|
+
const request = new walletTransactionRequest.UserUpdateRequest({ termsOfService });
|
|
1497
|
+
const user = await this._update(userId, request.toCleanObject());
|
|
1498
|
+
return user;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1406
1502
|
class WalletTransactionsResource extends mix(Resource).with(
|
|
1407
1503
|
Creatable,
|
|
1408
1504
|
Queryable,
|
|
@@ -1449,7 +1545,7 @@ class WhatsAppTransferResource extends mix(Resource).with(
|
|
|
1449
1545
|
}
|
|
1450
1546
|
|
|
1451
1547
|
class Cuenca {
|
|
1452
|
-
constructor(apiKey, apiSecret, phase =
|
|
1548
|
+
constructor(apiKey, apiSecret, phase = identities.Phase.Sandbox) {
|
|
1453
1549
|
this.client = new Client({ apiKey, apiSecret, phase });
|
|
1454
1550
|
this.withClient(this.client);
|
|
1455
1551
|
}
|
|
@@ -1477,42 +1573,4 @@ class Cuenca {
|
|
|
1477
1573
|
}
|
|
1478
1574
|
}
|
|
1479
1575
|
|
|
1480
|
-
exports.CuencaException = errors.CuencaException;
|
|
1481
|
-
exports.CuencaResponseException = errors.CuencaResponseException;
|
|
1482
|
-
exports.InvalidPassword = errors.InvalidPassword;
|
|
1483
|
-
exports.MalformedJwtToken = errors.MalformedJwtToken;
|
|
1484
|
-
exports.MultipleResultsFound = errors.MultipleResultsFound;
|
|
1485
|
-
exports.NoResultFound = errors.NoResultFound;
|
|
1486
|
-
exports.ValidationError = errors.ValidationError;
|
|
1487
|
-
exports.Jwt = jwt.Jwt;
|
|
1488
|
-
exports.AccountQuery = queries.AccountQuery;
|
|
1489
|
-
exports.ApiKeyQuery = queries.ApiKeyQuery;
|
|
1490
|
-
exports.BalanceEntryQuery = queries.BalanceEntryQuery;
|
|
1491
|
-
exports.BillPaymentQuery = queries.BillPaymentQuery;
|
|
1492
|
-
exports.CardErrorType = queries.CardErrorType;
|
|
1493
|
-
exports.CardFundingType = queries.CardFundingType;
|
|
1494
|
-
exports.CardIssuer = queries.CardIssuer;
|
|
1495
|
-
exports.CardStatus = queries.CardStatus;
|
|
1496
|
-
exports.CardTransactionQuery = queries.CardTransactionQuery;
|
|
1497
|
-
exports.CardTransactionType = queries.CardTransactionType;
|
|
1498
|
-
exports.CardType = queries.CardType;
|
|
1499
|
-
exports.CardsQuery = queries.CardsQuery;
|
|
1500
|
-
exports.CommissionType = queries.CommissionType;
|
|
1501
|
-
exports.DepositNetwork = queries.DepositNetwork;
|
|
1502
|
-
exports.DepositQuery = queries.DepositQuery;
|
|
1503
|
-
exports.EntryType = queries.EntryType;
|
|
1504
|
-
exports.FileFormat = queries.FileFormat;
|
|
1505
|
-
exports.PageSize = queries.PageSize;
|
|
1506
|
-
exports.Phase = queries.Phase;
|
|
1507
|
-
exports.QueryParams = queries.QueryParams;
|
|
1508
|
-
exports.SavingCategory = queries.SavingCategory;
|
|
1509
|
-
exports.ServiceProviderCategory = queries.ServiceProviderCategory;
|
|
1510
|
-
exports.StatementQuery = queries.StatementQuery;
|
|
1511
|
-
exports.TrackDataMethod = queries.TrackDataMethod;
|
|
1512
|
-
exports.TransactionStatus = queries.TransactionStatus;
|
|
1513
|
-
exports.TransferNetwork = queries.TransferNetwork;
|
|
1514
|
-
exports.TransferQuery = queries.TransferQuery;
|
|
1515
|
-
exports.WalletQuery = queries.WalletQuery;
|
|
1516
|
-
exports.WalletTransactionQuery = queries.WalletTransactionQuery;
|
|
1517
|
-
exports.WalletTransactionType = queries.WalletTransactionType;
|
|
1518
1576
|
exports.Cuenca = Cuenca;
|