bkper-js 2.15.0 → 2.15.2
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/lib/index.d.ts +82 -320
- package/lib/model/Account.js +2 -70
- package/lib/model/Book.js +2 -60
- package/lib/model/Connection.js +2 -89
- package/lib/model/File.js +2 -71
- package/lib/model/Group.js +2 -71
- package/lib/model/Integration.js +2 -71
- package/lib/model/ResourceProperty.js +130 -0
- package/lib/model/Transaction.js +19 -98
- package/package.json +1 -1
package/lib/model/Transaction.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { File } from "./File.js";
|
|
11
11
|
import { Account } from "./Account.js";
|
|
12
|
-
import {
|
|
12
|
+
import { ResourceProperty } from "./ResourceProperty.js";
|
|
13
13
|
import * as TransactionService from "../service/transaction-service.js";
|
|
14
14
|
import * as Utils from "../utils.js";
|
|
15
15
|
import { Amount } from "./Amount.js";
|
|
@@ -22,7 +22,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
22
22
|
*
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
|
-
export class Transaction extends
|
|
25
|
+
export class Transaction extends ResourceProperty {
|
|
26
26
|
constructor(book, payload) {
|
|
27
27
|
super(payload || { createdAt: `${Date.now()}` });
|
|
28
28
|
/** @internal */
|
|
@@ -277,7 +277,7 @@ export class Transaction extends Resource {
|
|
|
277
277
|
// Create all pending files in parallel
|
|
278
278
|
const promises = Array.from(this.pendingFiles.entries()).map((_a) => __awaiter(this, [_a], void 0, function* ([fileId, file]) {
|
|
279
279
|
file.book = this.book;
|
|
280
|
-
file.setProperty('
|
|
280
|
+
file.setProperty('upload_method', 'attachment');
|
|
281
281
|
const createdFile = yield file.create();
|
|
282
282
|
return { fileId, createdFile };
|
|
283
283
|
}));
|
|
@@ -312,93 +312,6 @@ export class Transaction extends Resource {
|
|
|
312
312
|
}
|
|
313
313
|
return false;
|
|
314
314
|
}
|
|
315
|
-
/**
|
|
316
|
-
* Gets the custom properties stored in this Transaction.
|
|
317
|
-
*
|
|
318
|
-
* @returns Object with key/value pair properties
|
|
319
|
-
*/
|
|
320
|
-
getProperties() {
|
|
321
|
-
return this.payload.properties != null
|
|
322
|
-
? Object.assign({}, this.payload.properties) : {};
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Sets the custom properties of the Transaction
|
|
326
|
-
*
|
|
327
|
-
* @param properties - Object with key/value pair properties
|
|
328
|
-
*
|
|
329
|
-
* @returns This Transaction, for chaining
|
|
330
|
-
*/
|
|
331
|
-
setProperties(properties) {
|
|
332
|
-
this.payload.properties = Object.assign({}, properties);
|
|
333
|
-
return this;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Gets the property value for given keys. First property found will be retrieved
|
|
337
|
-
*
|
|
338
|
-
* @param keys - The property key
|
|
339
|
-
*
|
|
340
|
-
* @returns The property value or undefined if not found
|
|
341
|
-
*/
|
|
342
|
-
getProperty(...keys) {
|
|
343
|
-
for (let index = 0; index < keys.length; index++) {
|
|
344
|
-
const key = keys[index];
|
|
345
|
-
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
346
|
-
if (value != null && value.trim() != "") {
|
|
347
|
-
return value;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return undefined;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Gets the custom properties keys stored in this Transaction.
|
|
354
|
-
*
|
|
355
|
-
* @returns Array of property keys
|
|
356
|
-
*/
|
|
357
|
-
getPropertyKeys() {
|
|
358
|
-
let properties = this.getProperties();
|
|
359
|
-
let propertyKeys = [];
|
|
360
|
-
if (properties) {
|
|
361
|
-
for (var key in properties) {
|
|
362
|
-
if (Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
363
|
-
propertyKeys.push(key);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
propertyKeys = propertyKeys.sort();
|
|
368
|
-
return propertyKeys;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Sets a custom property in the Transaction.
|
|
372
|
-
*
|
|
373
|
-
* @param key - The property key
|
|
374
|
-
* @param value - The property value, or null/undefined to clean it
|
|
375
|
-
*
|
|
376
|
-
* @returns This Transaction, for chaining
|
|
377
|
-
*/
|
|
378
|
-
setProperty(key, value) {
|
|
379
|
-
if (key == null || key.trim() == "") {
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
if (this.payload.properties == null) {
|
|
383
|
-
this.payload.properties = {};
|
|
384
|
-
}
|
|
385
|
-
if (!value) {
|
|
386
|
-
value = "";
|
|
387
|
-
}
|
|
388
|
-
this.payload.properties[key] = value;
|
|
389
|
-
return this;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Delete a custom property
|
|
393
|
-
*
|
|
394
|
-
* @param key - The property key
|
|
395
|
-
*
|
|
396
|
-
* @returns This Transaction, for chaining
|
|
397
|
-
*/
|
|
398
|
-
deleteProperty(key) {
|
|
399
|
-
this.setProperty(key, null);
|
|
400
|
-
return this;
|
|
401
|
-
}
|
|
402
315
|
/**
|
|
403
316
|
* Gets the credit account associated with this Transaction. Same as origin account
|
|
404
317
|
*
|
|
@@ -431,18 +344,22 @@ export class Transaction extends Resource {
|
|
|
431
344
|
/**
|
|
432
345
|
* Sets the credit/origin [[Account]] of this Transaction. Same as from()
|
|
433
346
|
*
|
|
434
|
-
* @param account - The Account object
|
|
347
|
+
* @param account - The Account object, or null/undefined to clear
|
|
435
348
|
*
|
|
436
349
|
* @returns This Transaction, for chaining
|
|
437
350
|
*/
|
|
438
351
|
setCreditAccount(account) {
|
|
352
|
+
if (account == null) {
|
|
353
|
+
this.payload.creditAccount = undefined;
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
439
356
|
if (account instanceof Account) {
|
|
440
|
-
if (account
|
|
357
|
+
if (account.getId() != null) {
|
|
441
358
|
this.payload.creditAccount = account.json();
|
|
442
359
|
}
|
|
443
360
|
}
|
|
444
361
|
else {
|
|
445
|
-
if (account
|
|
362
|
+
if (account.id != null) {
|
|
446
363
|
this.payload.creditAccount = account;
|
|
447
364
|
}
|
|
448
365
|
}
|
|
@@ -451,7 +368,7 @@ export class Transaction extends Resource {
|
|
|
451
368
|
/**
|
|
452
369
|
* Sets the credit/origin [[Account]] of this Transaction. Same as setCreditAccount()
|
|
453
370
|
*
|
|
454
|
-
* @param account - The Account object
|
|
371
|
+
* @param account - The Account object, or null/undefined to clear
|
|
455
372
|
*
|
|
456
373
|
* @returns This Transaction, for chaining
|
|
457
374
|
*/
|
|
@@ -490,18 +407,22 @@ export class Transaction extends Resource {
|
|
|
490
407
|
/**
|
|
491
408
|
* Sets the debit/destination [[Account]] of this Transaction. Same as to()
|
|
492
409
|
*
|
|
493
|
-
* @param account - The Account object
|
|
410
|
+
* @param account - The Account object, or null/undefined to clear
|
|
494
411
|
*
|
|
495
412
|
* @returns This Transaction, for chaining
|
|
496
413
|
*/
|
|
497
414
|
setDebitAccount(account) {
|
|
415
|
+
if (account == null) {
|
|
416
|
+
this.payload.debitAccount = undefined;
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
498
419
|
if (account instanceof Account) {
|
|
499
|
-
if (account
|
|
420
|
+
if (account.getId() != null) {
|
|
500
421
|
this.payload.debitAccount = { id: account.getId(), name: account.getName() };
|
|
501
422
|
}
|
|
502
423
|
}
|
|
503
424
|
else {
|
|
504
|
-
if (account
|
|
425
|
+
if (account.id != null) {
|
|
505
426
|
this.payload.debitAccount = { id: account.id, name: account.name };
|
|
506
427
|
}
|
|
507
428
|
}
|
|
@@ -510,7 +431,7 @@ export class Transaction extends Resource {
|
|
|
510
431
|
/**
|
|
511
432
|
* Sets the debit/destination [[Account]] of this Transaction. Same as setDebitAccount()
|
|
512
433
|
*
|
|
513
|
-
* @param account - The Account object
|
|
434
|
+
* @param account - The Account object, or null/undefined to clear
|
|
514
435
|
*
|
|
515
436
|
* @returns This Transaction, for chaining
|
|
516
437
|
*/
|