@alviere/core 0.10.0 → 0.11.1
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/dist/entities/constants/error-codes.d.ts +1 -0
- package/dist/entities/constants/error-codes.d.ts.map +1 -1
- package/dist/entities/interfaces/gateways/legal-texts.interface.d.ts +5 -0
- package/dist/entities/interfaces/gateways/legal-texts.interface.d.ts.map +1 -0
- package/dist/entities/interfaces/gateways/payments.interface.d.ts +2 -1
- package/dist/entities/interfaces/gateways/payments.interface.d.ts.map +1 -1
- package/dist/entities/requests/accounts/accounts.d.ts +1 -0
- package/dist/entities/requests/accounts/accounts.d.ts.map +1 -1
- package/dist/entities/requests/payments/bank-accounts.d.ts +8 -0
- package/dist/entities/requests/payments/bank-accounts.d.ts.map +1 -1
- package/dist/entities/responses/legal-texts/legal-texts.d.ts +13 -0
- package/dist/entities/responses/legal-texts/legal-texts.d.ts.map +1 -0
- package/dist/entities/responses/payments/bank_accounts.d.ts +1 -0
- package/dist/entities/responses/payments/bank_accounts.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -12
- package/dist/index.mjs.map +1 -1
- package/dist/infrastructure/gateways/alcore-base.gateway.d.ts.map +1 -1
- package/dist/infrastructure/gateways/legal-texts.gateway.d.ts +10 -0
- package/dist/infrastructure/gateways/legal-texts.gateway.d.ts.map +1 -0
- package/dist/infrastructure/gateways/payments.gateway.d.ts +2 -1
- package/dist/infrastructure/gateways/payments.gateway.d.ts.map +1 -1
- package/dist/services/legal-texts-api.service.d.ts +8 -0
- package/dist/services/legal-texts-api.service.d.ts.map +1 -0
- package/dist/services/payment-processor.service.d.ts +2 -1
- package/dist/services/payment-processor.service.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -658,7 +658,8 @@ const AlcoreErrorCodes = {
|
|
|
658
658
|
UNDERLYING_API_ERROR: "115000",
|
|
659
659
|
ACCOUNT_STATUS_NOT_ACTIVE: "115001",
|
|
660
660
|
ACCOUNT_CHILD_FORBIDDEN: "320129",
|
|
661
|
-
PARENT_ACCOUNT_NOT_ALLOWED: "320104"
|
|
661
|
+
PARENT_ACCOUNT_NOT_ALLOWED: "320104",
|
|
662
|
+
BANK_ACCOUNT_PRIMARY_REQUIRES_ACTIVE_STATUS: "340028"
|
|
662
663
|
// Add more error codes as you discover them from the API
|
|
663
664
|
};
|
|
664
665
|
const AlcoreErrorMessages = {
|
|
@@ -683,7 +684,8 @@ const AlcoreErrorMessages = {
|
|
|
683
684
|
[AlcoreErrorCodes.UNDERLYING_API_ERROR]: "Underlying API Error. ",
|
|
684
685
|
[AlcoreErrorCodes.ACCOUNT_STATUS_NOT_ACTIVE]: "Account status not active. Please check your request and try again.",
|
|
685
686
|
[AlcoreErrorCodes.ACCOUNT_CHILD_FORBIDDEN]: "Used Account can't be used to create a child account.",
|
|
686
|
-
[AlcoreErrorCodes.PARENT_ACCOUNT_NOT_ALLOWED]: "Parent account not allowed. Please check your request and try again."
|
|
687
|
+
[AlcoreErrorCodes.PARENT_ACCOUNT_NOT_ALLOWED]: "Parent account not allowed. Please check your request and try again.",
|
|
688
|
+
[AlcoreErrorCodes.BANK_ACCOUNT_PRIMARY_REQUIRES_ACTIVE_STATUS]: "Only ACTIVE bank accounts can be set as primary."
|
|
687
689
|
};
|
|
688
690
|
function getErrorMessage(errorCode) {
|
|
689
691
|
return AlcoreErrorMessages[errorCode] || "An unexpected error occurred. Please try again.";
|
|
@@ -771,14 +773,10 @@ class AlcoreBase {
|
|
|
771
773
|
if (error.p) {
|
|
772
774
|
error = await this.decrypt(error);
|
|
773
775
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
);
|
|
777
|
-
throw new AlcoreApiError(
|
|
778
|
-
response.status === 500 ? AlcoreErrorCodes.UNDERLYING_API_ERROR : error.error_code,
|
|
779
|
-
AlcoreErrorMessages[error.error_code],
|
|
780
|
-
response.status
|
|
781
|
-
);
|
|
776
|
+
const errorCode = response.status === 500 ? AlcoreErrorCodes.UNDERLYING_API_ERROR : error.error_code;
|
|
777
|
+
const errorDescription = error.error_description || getErrorMessage(errorCode);
|
|
778
|
+
this.logger.debug(`❌ API Error - Code: ${errorCode}, Description: ${errorDescription}`);
|
|
779
|
+
throw new AlcoreApiError(errorCode, errorDescription, response.status);
|
|
782
780
|
}
|
|
783
781
|
return response;
|
|
784
782
|
} catch (fetchError) {
|
|
@@ -896,6 +894,13 @@ class PaymentsGateway extends AlcoreBase {
|
|
|
896
894
|
const response = await this.send("DELETE", endpoint, {});
|
|
897
895
|
return throwIfApiError(response);
|
|
898
896
|
}
|
|
897
|
+
async update_bank_account(accountUuid, uuid, data) {
|
|
898
|
+
const endpoint = `/payment-methods/bank-accounts/${uuid}`;
|
|
899
|
+
const response = await this.send("PATCH", endpoint, data);
|
|
900
|
+
const encrypted = await response.json();
|
|
901
|
+
const decrypted = await this.decrypt(encrypted);
|
|
902
|
+
return throwIfApiError(decrypted);
|
|
903
|
+
}
|
|
899
904
|
}
|
|
900
905
|
class WalletsGateway extends AlcoreBase {
|
|
901
906
|
constructor(jwt, cryptor, logger) {
|
|
@@ -1028,7 +1033,7 @@ class AccountsGateway extends AlcoreBase {
|
|
|
1028
1033
|
}
|
|
1029
1034
|
async manageOnboarding(accountUuid, action) {
|
|
1030
1035
|
const endpoint = `/accounts/${accountUuid}/onboarding`;
|
|
1031
|
-
await this.send("
|
|
1036
|
+
await this.send("PUT", endpoint, { action });
|
|
1032
1037
|
}
|
|
1033
1038
|
async createAddress(accountUuid, data) {
|
|
1034
1039
|
const endpoint = `/accounts/${accountUuid}/addresses`;
|
|
@@ -1330,6 +1335,19 @@ class PaymentProcessor {
|
|
|
1330
1335
|
throw error;
|
|
1331
1336
|
}
|
|
1332
1337
|
}
|
|
1338
|
+
async processUpdateBankAccount(accountUuid, uuid, request) {
|
|
1339
|
+
this.logger.debug("PaymentProcessor: Starting update bank account processing");
|
|
1340
|
+
this.logger.debug("PaymentProcessor: Request data: " + JSON.stringify(request, null, 2));
|
|
1341
|
+
try {
|
|
1342
|
+
const result = await this.gateway.update_bank_account(accountUuid, uuid, request);
|
|
1343
|
+
this.logger.debug("PaymentProcessor: Update bank account processing completed successfully");
|
|
1344
|
+
return result;
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
this.logger.debug("PaymentProcessor: Update bank account processing failed");
|
|
1347
|
+
this.logger.debug("PaymentProcessor: Error details: " + JSON.stringify(error));
|
|
1348
|
+
throw error;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1333
1351
|
}
|
|
1334
1352
|
class BankInfoApiService {
|
|
1335
1353
|
constructor(gateway) {
|
|
@@ -1339,6 +1357,14 @@ class BankInfoApiService {
|
|
|
1339
1357
|
return this.gateway.getBankInfo(routingNumber);
|
|
1340
1358
|
}
|
|
1341
1359
|
}
|
|
1360
|
+
class LegalTextsApiService {
|
|
1361
|
+
constructor(gateway) {
|
|
1362
|
+
this.gateway = gateway;
|
|
1363
|
+
}
|
|
1364
|
+
async getLegalTexts(type, version) {
|
|
1365
|
+
return this.gateway.getLegalTexts(type, version);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1342
1368
|
class BankInfoGateway extends AlcoreBase {
|
|
1343
1369
|
constructor(jwt, cryptor, logger) {
|
|
1344
1370
|
super(jwt, cryptor, logger);
|
|
@@ -1352,6 +1378,24 @@ class BankInfoGateway extends AlcoreBase {
|
|
|
1352
1378
|
return throwIfApiError(decrypted);
|
|
1353
1379
|
}
|
|
1354
1380
|
}
|
|
1381
|
+
class LegalTextsGateway extends AlcoreBase {
|
|
1382
|
+
constructor(jwt, cryptor, logger) {
|
|
1383
|
+
super(jwt, cryptor, logger);
|
|
1384
|
+
this.logger.debug("🔐 LegalTextsGateway initialized");
|
|
1385
|
+
}
|
|
1386
|
+
async getLegalTexts(type, version) {
|
|
1387
|
+
const queryParams = new URLSearchParams({ type });
|
|
1388
|
+
if (version) {
|
|
1389
|
+
queryParams.set("version", version);
|
|
1390
|
+
}
|
|
1391
|
+
const endpoint = `/v3/legal-texts?${queryParams.toString()}`;
|
|
1392
|
+
this.logger.debug(`endpoint -> ${endpoint}`);
|
|
1393
|
+
const response = await this.send("GET", endpoint, {});
|
|
1394
|
+
const encrypted = await response.json();
|
|
1395
|
+
const decrypted = await this.decrypt(encrypted);
|
|
1396
|
+
return throwIfApiError(decrypted);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1355
1399
|
function NewAddCardRequest(params) {
|
|
1356
1400
|
const { external_id, name, pan, expiry, code, zip } = params;
|
|
1357
1401
|
const expiryParts = expiry.split("/");
|
|
@@ -1425,12 +1469,13 @@ function createDefaultMerchantDetails() {
|
|
|
1425
1469
|
};
|
|
1426
1470
|
}
|
|
1427
1471
|
function NewAddBankAccountRequest(params) {
|
|
1428
|
-
const { external_id, country, currency, bank_account_details, metadata } = params;
|
|
1472
|
+
const { external_id, country, currency, bank_account_details, primary, metadata } = params;
|
|
1429
1473
|
let data = {
|
|
1430
1474
|
external_id,
|
|
1431
1475
|
country,
|
|
1432
1476
|
currency,
|
|
1433
1477
|
bank_account_details,
|
|
1478
|
+
primary,
|
|
1434
1479
|
metadata
|
|
1435
1480
|
};
|
|
1436
1481
|
data = getSanitizedBody(data);
|
|
@@ -2327,6 +2372,16 @@ class AlviereCore {
|
|
|
2327
2372
|
}
|
|
2328
2373
|
return new BankInfoApiService(this.gateways.get("bankInfo"));
|
|
2329
2374
|
}
|
|
2375
|
+
// Create legal texts service
|
|
2376
|
+
createLegalTextsService() {
|
|
2377
|
+
if (!this.gateways.has("legalTexts")) {
|
|
2378
|
+
this.gateways.set(
|
|
2379
|
+
"legalTexts",
|
|
2380
|
+
new LegalTextsGateway(this.authToken, this.getOrCreateCryptor(), this.logger)
|
|
2381
|
+
);
|
|
2382
|
+
}
|
|
2383
|
+
return new LegalTextsApiService(this.gateways.get("legalTexts"));
|
|
2384
|
+
}
|
|
2330
2385
|
/**
|
|
2331
2386
|
* Generate scoped JWT for specific account (JWT downgrade)
|
|
2332
2387
|
* Exchanges the current business-level JWT for a consumer-level JWT
|