apacuana-sdk-core 0.2.0 → 0.4.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/README.md +64 -15
- package/coverage/clover.xml +155 -121
- package/coverage/coverage-final.json +8 -8
- package/coverage/lcov-report/block-navigation.js +1 -1
- package/coverage/lcov-report/index.html +30 -30
- package/coverage/lcov-report/sorter.js +21 -7
- package/coverage/lcov-report/src/api/certs.js.html +73 -28
- package/coverage/lcov-report/src/api/index.html +31 -31
- package/coverage/lcov-report/src/api/revocations.js.html +12 -15
- package/coverage/lcov-report/src/api/signatures.js.html +186 -159
- package/coverage/lcov-report/src/api/users.js.html +24 -63
- package/coverage/lcov-report/src/config/index.html +1 -1
- package/coverage/lcov-report/src/config/index.js.html +1 -1
- package/coverage/lcov-report/src/errors/index.html +1 -1
- package/coverage/lcov-report/src/errors/index.js.html +8 -8
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.js.html +6 -3
- package/coverage/lcov-report/src/utils/constant.js.html +4 -4
- package/coverage/lcov-report/src/utils/helpers.js.html +101 -50
- package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +19 -19
- package/coverage/lcov.info +293 -221
- package/dist/api/certs.d.ts +8 -0
- package/dist/api/revocations.d.ts +7 -0
- package/dist/api/signatures.d.ts +16 -0
- package/dist/api/users.d.ts +15 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/errors/index.d.ts +10 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +252 -251
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +252 -251
- package/dist/index.mjs.map +1 -1
- package/dist/utils/constant.d.ts +18 -0
- package/dist/utils/helpers.d.ts +21 -0
- package/dist/utils/httpClient.d.ts +3 -0
- package/package.json +9 -4
- package/src/api/certs.js +25 -10
- package/src/api/revocations.js +10 -11
- package/src/api/signatures.js +106 -97
- package/src/api/users.js +16 -29
- package/src/index.js +2 -1
- package/src/utils/helpers.js +17 -0
- package/tests/api/certs.test.js +58 -74
- package/tests/api/signatures.test.js +18 -73
- package/tests/api/users.test.js +10 -10
- package/tsconfig.json +15 -0
package/dist/index.js
CHANGED
|
@@ -522,7 +522,7 @@ var httpRequest = /*#__PURE__*/function () {
|
|
|
522
522
|
* Este método es útil para endpoints que requieren datos en el cuerpo de la petición
|
|
523
523
|
* para buscar un usuario, como un ID de sesión o un token de acceso.
|
|
524
524
|
*
|
|
525
|
-
* @returns {Promise<object>} Objeto con los
|
|
525
|
+
* @returns {Promise<{token: string, userData: object, success: boolean}>} Objeto con el token de sesión, los datos del usuario y un indicador de éxito.
|
|
526
526
|
* @throws {Error} Si los parámetros de entrada son inválidos.
|
|
527
527
|
* @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
|
|
528
528
|
*/
|
|
@@ -533,62 +533,46 @@ var getCustomer = /*#__PURE__*/function () {
|
|
|
533
533
|
while (1) switch (_context.p = _context.n) {
|
|
534
534
|
case 0:
|
|
535
535
|
_getConfig = getConfig(), verificationId = _getConfig.verificationId, customerId = _getConfig.customerId;
|
|
536
|
-
|
|
537
|
-
verificationid: verificationId,
|
|
538
|
-
customerid: customerId
|
|
539
|
-
}; // eslint-disable-next-line no-console
|
|
540
|
-
console.log("-> Función 'getCustomer' ejecutada.");
|
|
541
|
-
// eslint-disable-next-line no-console
|
|
542
|
-
console.log("Parámetros recibidos para buscar usuario:", body);
|
|
543
|
-
|
|
544
|
-
// 1. Validación de Parámetros de Entrada (Lado del SDK)
|
|
545
|
-
if (!(!body || !body.verificationid || !body.customerid)) {
|
|
536
|
+
if (!(!verificationId || !customerId)) {
|
|
546
537
|
_context.n = 1;
|
|
547
538
|
break;
|
|
548
539
|
}
|
|
549
|
-
throw new
|
|
540
|
+
throw new ApacuanaAPIError("Both 'verificationId' and 'customerId' must be configured.", 400, "CONFIGURATION_ERROR");
|
|
550
541
|
case 1:
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
"POST");
|
|
558
|
-
case
|
|
542
|
+
body = {
|
|
543
|
+
verificationid: verificationId,
|
|
544
|
+
customerid: customerId
|
|
545
|
+
};
|
|
546
|
+
_context.p = 2;
|
|
547
|
+
_context.n = 3;
|
|
548
|
+
return httpRequest("services/api/register/init", body, "POST");
|
|
549
|
+
case 3:
|
|
559
550
|
response = _context.v;
|
|
560
|
-
// 3. Procesar la Respuesta del Backend
|
|
561
|
-
// Asumiendo que la respuesta exitosa del backend incluye un objeto 'user'
|
|
562
|
-
// eslint-disable-next-line no-console
|
|
563
|
-
console.log("Respuesta del servidor para el token:", response);
|
|
564
551
|
if (!(!response.sessionid || !response.entry)) {
|
|
565
|
-
_context.n =
|
|
552
|
+
_context.n = 4;
|
|
566
553
|
break;
|
|
567
554
|
}
|
|
568
|
-
throw new ApacuanaAPIError("
|
|
569
|
-
case
|
|
555
|
+
throw new ApacuanaAPIError("The API response does not contain the user.", 200, "INVALID_API_RESPONSE");
|
|
556
|
+
case 4:
|
|
570
557
|
return _context.a(2, {
|
|
571
558
|
token: response.sessionid,
|
|
572
559
|
userData: response.entry,
|
|
573
560
|
success: true
|
|
574
561
|
});
|
|
575
|
-
case
|
|
576
|
-
_context.p =
|
|
562
|
+
case 5:
|
|
563
|
+
_context.p = 5;
|
|
577
564
|
_t = _context.v;
|
|
578
|
-
// 4. Manejo de Errores
|
|
579
|
-
// eslint-disable-next-line no-console
|
|
580
|
-
console.error("Error en getCustomer:", _t);
|
|
581
565
|
if (!(_t instanceof ApacuanaAPIError)) {
|
|
582
|
-
_context.n =
|
|
566
|
+
_context.n = 6;
|
|
583
567
|
break;
|
|
584
568
|
}
|
|
585
569
|
throw _t;
|
|
586
|
-
case 5:
|
|
587
|
-
throw new ApacuanaAPIError("Fallo inesperado al obtener el token: ".concat(_t.message || "Error desconocido"));
|
|
588
570
|
case 6:
|
|
571
|
+
throw new ApacuanaAPIError("Unexpected failure getting token: ".concat(_t.message || "Unknown error"));
|
|
572
|
+
case 7:
|
|
589
573
|
return _context.a(2);
|
|
590
574
|
}
|
|
591
|
-
}, _callee, null, [[
|
|
575
|
+
}, _callee, null, [[2, 5]]);
|
|
592
576
|
}));
|
|
593
577
|
return function getCustomer() {
|
|
594
578
|
return _ref.apply(this, arguments);
|
|
@@ -606,32 +590,32 @@ var requestRevocation = /*#__PURE__*/function () {
|
|
|
606
590
|
return _regenerator().w(function (_context) {
|
|
607
591
|
while (1) switch (_context.p = _context.n) {
|
|
608
592
|
case 0:
|
|
609
|
-
console.log(
|
|
610
|
-
console.log(
|
|
593
|
+
console.log("-> Función 'requestRevocation' ejecutada.");
|
|
594
|
+
console.log("Parámetros recibidos para solicitud de revocación:", {
|
|
611
595
|
reasonCode: reasonCode
|
|
612
596
|
});
|
|
613
597
|
if (reasonCode) {
|
|
614
598
|
_context.n = 1;
|
|
615
599
|
break;
|
|
616
600
|
}
|
|
617
|
-
throw new Error(
|
|
601
|
+
throw new Error("ID de certificado y motivo son requeridos para requestRevocation.");
|
|
618
602
|
case 1:
|
|
619
603
|
_context.p = 1;
|
|
620
604
|
_context.n = 2;
|
|
621
|
-
return httpRequest(
|
|
605
|
+
return httpRequest("users/api/customers/requestcert", {
|
|
622
606
|
reason: reasonCode
|
|
623
|
-
},
|
|
607
|
+
}, "POST");
|
|
624
608
|
case 2:
|
|
625
609
|
response = _context.v;
|
|
626
|
-
console.log(
|
|
610
|
+
console.log("Respuesta del servidor", response);
|
|
627
611
|
if (response.success) {
|
|
628
612
|
_context.n = 3;
|
|
629
613
|
break;
|
|
630
614
|
}
|
|
631
|
-
throw new ApacuanaAPIError(response.message ||
|
|
615
|
+
throw new ApacuanaAPIError(response.message || "Error desconocido al solicitar revocación.");
|
|
632
616
|
case 3:
|
|
633
617
|
return _context.a(2, {
|
|
634
|
-
revocationStatus: response.status ||
|
|
618
|
+
revocationStatus: response.status || "pending",
|
|
635
619
|
requestId: response.id
|
|
636
620
|
});
|
|
637
621
|
case 4:
|
|
@@ -32771,6 +32755,11 @@ var validateGetDocsData = function validateGetDocsData(data) {
|
|
|
32771
32755
|
throw new ApacuanaAPIError("El parámetro 'status' no es válido. Los valores permitidos son: -1, 0, 1, 2.", 400, "INVALID_PARAMETER");
|
|
32772
32756
|
}
|
|
32773
32757
|
};
|
|
32758
|
+
var validateGetDigestData = function validateGetDigestData(signData) {
|
|
32759
|
+
if (!signData || !signData.cert || typeof signData.cert !== "string" || !signData.signatureId || typeof signData.signatureId !== "string") {
|
|
32760
|
+
throw new ApacuanaAPIError("Los parámetros 'cert' y 'signatureId' son requeridos y deben ser cadenas de texto.", 400, "INVALID_PARAMETER");
|
|
32761
|
+
}
|
|
32762
|
+
};
|
|
32774
32763
|
var helpers = {
|
|
32775
32764
|
getCertificateStatus: getCertificateStatus,
|
|
32776
32765
|
exportPrivateKey: exportPrivateKey,
|
|
@@ -32778,9 +32767,121 @@ var helpers = {
|
|
|
32778
32767
|
encryptedCsr: encryptedCsr,
|
|
32779
32768
|
validateOnBoardingSignerData: validateOnBoardingSignerData,
|
|
32780
32769
|
validateCsr: validateCsr,
|
|
32781
|
-
validateGetDocsData: validateGetDocsData
|
|
32770
|
+
validateGetDocsData: validateGetDocsData,
|
|
32771
|
+
validateGetDigestData: validateGetDigestData
|
|
32782
32772
|
};
|
|
32783
32773
|
|
|
32774
|
+
var generateCertOnBoarding = /*#__PURE__*/function () {
|
|
32775
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
32776
|
+
var csr,
|
|
32777
|
+
encryptedCSR,
|
|
32778
|
+
response,
|
|
32779
|
+
cert,
|
|
32780
|
+
_args = arguments,
|
|
32781
|
+
_t;
|
|
32782
|
+
return _regenerator().w(function (_context) {
|
|
32783
|
+
while (1) switch (_context.p = _context.n) {
|
|
32784
|
+
case 0:
|
|
32785
|
+
csr = _args.length > 0 && _args[0] !== undefined ? _args[0] : undefined;
|
|
32786
|
+
_context.p = 1;
|
|
32787
|
+
encryptedCSR = helpers.encryptedCsr(csr);
|
|
32788
|
+
_context.n = 2;
|
|
32789
|
+
return httpRequest("services/api/register/certificate", encryptedCSR, "POST");
|
|
32790
|
+
case 2:
|
|
32791
|
+
response = _context.v;
|
|
32792
|
+
cert = response.cert;
|
|
32793
|
+
if (cert) {
|
|
32794
|
+
_context.n = 3;
|
|
32795
|
+
break;
|
|
32796
|
+
}
|
|
32797
|
+
throw new ApacuanaAPIError("The API response does not contain the certificate.", response.status, "INVALID_API_RESPONSE");
|
|
32798
|
+
case 3:
|
|
32799
|
+
return _context.a(2, {
|
|
32800
|
+
cert: cert,
|
|
32801
|
+
success: true
|
|
32802
|
+
});
|
|
32803
|
+
case 4:
|
|
32804
|
+
_context.p = 4;
|
|
32805
|
+
_t = _context.v;
|
|
32806
|
+
if (!(_t instanceof ApacuanaAPIError)) {
|
|
32807
|
+
_context.n = 5;
|
|
32808
|
+
break;
|
|
32809
|
+
}
|
|
32810
|
+
throw _t;
|
|
32811
|
+
case 5:
|
|
32812
|
+
throw new Error("Certificate generation failed: ".concat(_t.message));
|
|
32813
|
+
case 6:
|
|
32814
|
+
return _context.a(2);
|
|
32815
|
+
}
|
|
32816
|
+
}, _callee, null, [[1, 4]]);
|
|
32817
|
+
}));
|
|
32818
|
+
return function generateCertOnBoarding() {
|
|
32819
|
+
return _ref.apply(this, arguments);
|
|
32820
|
+
};
|
|
32821
|
+
}();
|
|
32822
|
+
var generateCertOnPremise = /*#__PURE__*/function () {
|
|
32823
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
32824
|
+
return _regenerator().w(function (_context2) {
|
|
32825
|
+
while (1) switch (_context2.n) {
|
|
32826
|
+
case 0:
|
|
32827
|
+
throw new ApacuanaAPIError("Certificate generation is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
|
|
32828
|
+
case 1:
|
|
32829
|
+
return _context2.a(2);
|
|
32830
|
+
}
|
|
32831
|
+
}, _callee2);
|
|
32832
|
+
}));
|
|
32833
|
+
return function generateCertOnPremise() {
|
|
32834
|
+
return _ref2.apply(this, arguments);
|
|
32835
|
+
};
|
|
32836
|
+
}();
|
|
32837
|
+
|
|
32838
|
+
/**
|
|
32839
|
+
* Generates a digital certificate.
|
|
32840
|
+
* @param {string} [csr] - Certificate Signing Request (CSR).
|
|
32841
|
+
* @returns {Promise<{cert: string, success: boolean}>} Object with the generated certificate and a success indicator.
|
|
32842
|
+
* @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
|
|
32843
|
+
* @throws {Error} If certificate generation fails for another reason.
|
|
32844
|
+
*/
|
|
32845
|
+
var generateCert = /*#__PURE__*/function () {
|
|
32846
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
32847
|
+
var csr,
|
|
32848
|
+
_getConfig,
|
|
32849
|
+
integrationType,
|
|
32850
|
+
_args3 = arguments;
|
|
32851
|
+
return _regenerator().w(function (_context3) {
|
|
32852
|
+
while (1) switch (_context3.n) {
|
|
32853
|
+
case 0:
|
|
32854
|
+
csr = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : undefined;
|
|
32855
|
+
_getConfig = getConfig(), integrationType = _getConfig.integrationType;
|
|
32856
|
+
helpers.validateCsr(csr);
|
|
32857
|
+
if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
|
|
32858
|
+
_context3.n = 1;
|
|
32859
|
+
break;
|
|
32860
|
+
}
|
|
32861
|
+
return _context3.a(2, generateCertOnBoarding(csr));
|
|
32862
|
+
case 1:
|
|
32863
|
+
if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
|
|
32864
|
+
_context3.n = 2;
|
|
32865
|
+
break;
|
|
32866
|
+
}
|
|
32867
|
+
return _context3.a(2, generateCertOnPremise());
|
|
32868
|
+
case 2:
|
|
32869
|
+
throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
|
|
32870
|
+
case 3:
|
|
32871
|
+
return _context3.a(2);
|
|
32872
|
+
}
|
|
32873
|
+
}, _callee3);
|
|
32874
|
+
}));
|
|
32875
|
+
return function generateCert() {
|
|
32876
|
+
return _ref3.apply(this, arguments);
|
|
32877
|
+
};
|
|
32878
|
+
}();
|
|
32879
|
+
|
|
32880
|
+
/**
|
|
32881
|
+
* Gets the user's certificate status.
|
|
32882
|
+
* @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
|
|
32883
|
+
* @returns {{status: string, success: boolean}} Object with the certificate status and a success indicator.
|
|
32884
|
+
*/
|
|
32784
32885
|
var getCertStatus = function getCertStatus() {
|
|
32785
32886
|
var isCertificateInDevice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
32786
32887
|
var config = getConfig();
|
|
@@ -32791,299 +32892,198 @@ var getCertStatus = function getCertStatus() {
|
|
|
32791
32892
|
};
|
|
32792
32893
|
};
|
|
32793
32894
|
|
|
32794
|
-
/*
|
|
32795
|
-
const signDocumentOnBoarding = async (documentData, signatureData) => {
|
|
32796
|
-
try {
|
|
32797
|
-
const response = await httpRequest(
|
|
32798
|
-
"/docs/sign",
|
|
32799
|
-
{ documentData, signatureData },
|
|
32800
|
-
"POST"
|
|
32801
|
-
);
|
|
32802
|
-
if (!response.success) {
|
|
32803
|
-
throw new ApacuanaAPIError(
|
|
32804
|
-
response.message || "Error desconocido al firmar documento."
|
|
32805
|
-
);
|
|
32806
|
-
}
|
|
32807
|
-
return { signedDocId: response.id, status: response.message };
|
|
32808
|
-
} catch (error) {
|
|
32809
|
-
if (error.name === "ApacuanaAPIError") {
|
|
32810
|
-
throw error;
|
|
32811
|
-
}
|
|
32812
|
-
throw new ApacuanaAPIError(
|
|
32813
|
-
`Fallo en la firma del documento (on-boarding): ${error.message}`
|
|
32814
|
-
);
|
|
32815
|
-
}
|
|
32816
|
-
};
|
|
32817
|
-
|
|
32818
|
-
const signDocumentOnPremise = async (signature, cert, privateKey) => {
|
|
32819
|
-
helpers.validateSignOnPremiseData({ signature, cert, privateKey });
|
|
32820
|
-
try {
|
|
32821
|
-
const digestBody = {
|
|
32822
|
-
publickey: cert,
|
|
32823
|
-
};
|
|
32824
|
-
|
|
32825
|
-
const digestResponse = await httpRequest(
|
|
32826
|
-
`services/api/documents/getdigest/${signature.id}`,
|
|
32827
|
-
digestBody,
|
|
32828
|
-
"POST"
|
|
32829
|
-
);
|
|
32830
|
-
|
|
32831
|
-
const digest = digestResponse.data?.digest || digestResponse.digest;
|
|
32832
|
-
if (!digest) {
|
|
32833
|
-
throw new ApacuanaAPIError(
|
|
32834
|
-
"La generación de firma ha fallado: no se pudo obtener el digest del documento."
|
|
32835
|
-
);
|
|
32836
|
-
}
|
|
32837
|
-
|
|
32838
|
-
const signedDigest = await helpers.signDigest(digest, privateKey);
|
|
32839
|
-
|
|
32840
|
-
const signBody = {
|
|
32841
|
-
positions: JSON.stringify(
|
|
32842
|
-
signature.positions.map((p) => ({
|
|
32843
|
-
x: p.x,
|
|
32844
|
-
y: p.y,
|
|
32845
|
-
page: p.page,
|
|
32846
|
-
status: 1,
|
|
32847
|
-
}))
|
|
32848
|
-
),
|
|
32849
|
-
publickey: cert,
|
|
32850
|
-
signeddigest: signedDigest,
|
|
32851
|
-
};
|
|
32852
|
-
|
|
32853
|
-
const signResponse = await httpRequest(
|
|
32854
|
-
`services/api/documents/sign/${signature.id}`,
|
|
32855
|
-
signBody,
|
|
32856
|
-
"PUT"
|
|
32857
|
-
);
|
|
32858
|
-
|
|
32859
|
-
return signResponse;
|
|
32860
|
-
} catch (error) {
|
|
32861
|
-
if (error.name === "ApacuanaAPIError") {
|
|
32862
|
-
throw error;
|
|
32863
|
-
}
|
|
32864
|
-
throw new ApacuanaAPIError(
|
|
32865
|
-
`Fallo en la firma del documento (on-premise): ${error.message}`
|
|
32866
|
-
);
|
|
32867
|
-
}
|
|
32868
|
-
};
|
|
32869
|
-
*/
|
|
32870
|
-
|
|
32871
|
-
/**
|
|
32872
|
-
* Firma un documento PDF con un certificado digital.
|
|
32873
|
-
* @param {object} data - Datos para la firma. Para 'on-boarding', debe contener {documentData, signatureData}. Para 'on-premise', debe contener {signature, cert, privateKey}.
|
|
32874
|
-
* @returns {Promise<object>} Objeto con el resultado de la firma.
|
|
32875
|
-
*/
|
|
32876
|
-
/*
|
|
32877
|
-
export const signDocument = async (signData) => {
|
|
32878
|
-
if (
|
|
32879
|
-
!signData ||
|
|
32880
|
-
typeof signData !== "object" ||
|
|
32881
|
-
Object.keys(signData).length === 0
|
|
32882
|
-
) {
|
|
32883
|
-
throw new ApacuanaAPIError(
|
|
32884
|
-
"El parámetro 'data' es requerido y debe ser un objeto no vacío.",
|
|
32885
|
-
400,
|
|
32886
|
-
"INVALID_PARAMETER"
|
|
32887
|
-
);
|
|
32888
|
-
}
|
|
32889
|
-
|
|
32890
|
-
const { integrationType } = getConfig();
|
|
32891
|
-
|
|
32892
|
-
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
32893
|
-
return signDocumentOnBoarding(signData);
|
|
32894
|
-
}
|
|
32895
|
-
|
|
32896
|
-
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
32897
|
-
return signDocumentOnPremise(signData);
|
|
32898
|
-
}
|
|
32899
|
-
|
|
32900
|
-
throw new ApacuanaAPIError(
|
|
32901
|
-
`Tipo de integración no soportado: ${integrationType}`,
|
|
32902
|
-
400,
|
|
32903
|
-
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
32904
|
-
);
|
|
32905
|
-
};
|
|
32906
|
-
*/
|
|
32907
|
-
|
|
32908
32895
|
var addSignerOnBoarding = /*#__PURE__*/function () {
|
|
32909
|
-
var
|
|
32910
|
-
var
|
|
32911
|
-
return _regenerator().w(function (
|
|
32912
|
-
while (1) switch (
|
|
32896
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(signerData) {
|
|
32897
|
+
var _t2;
|
|
32898
|
+
return _regenerator().w(function (_context7) {
|
|
32899
|
+
while (1) switch (_context7.p = _context7.n) {
|
|
32913
32900
|
case 0:
|
|
32914
32901
|
helpers.validateOnBoardingSignerData(signerData);
|
|
32915
|
-
|
|
32916
|
-
|
|
32902
|
+
_context7.p = 1;
|
|
32903
|
+
_context7.n = 2;
|
|
32917
32904
|
return httpRequest("services/api/documents/signing", signerData, "POST");
|
|
32918
32905
|
case 2:
|
|
32919
|
-
return
|
|
32906
|
+
return _context7.a(2, {
|
|
32920
32907
|
signer: signerData.typedoc + signerData.doc,
|
|
32921
32908
|
success: true
|
|
32922
32909
|
});
|
|
32923
32910
|
case 3:
|
|
32924
|
-
|
|
32925
|
-
|
|
32926
|
-
if (!(
|
|
32927
|
-
|
|
32911
|
+
_context7.p = 3;
|
|
32912
|
+
_t2 = _context7.v;
|
|
32913
|
+
if (!(_t2 instanceof ApacuanaAPIError)) {
|
|
32914
|
+
_context7.n = 4;
|
|
32928
32915
|
break;
|
|
32929
32916
|
}
|
|
32930
|
-
throw
|
|
32917
|
+
throw _t2;
|
|
32931
32918
|
case 4:
|
|
32932
|
-
throw new Error("
|
|
32919
|
+
throw new Error("Failed to add signer in On-Boarding: ".concat(_t2.message));
|
|
32933
32920
|
case 5:
|
|
32934
|
-
return
|
|
32921
|
+
return _context7.a(2);
|
|
32935
32922
|
}
|
|
32936
|
-
},
|
|
32923
|
+
}, _callee7, null, [[1, 3]]);
|
|
32937
32924
|
}));
|
|
32938
|
-
return function addSignerOnBoarding(
|
|
32939
|
-
return
|
|
32925
|
+
return function addSignerOnBoarding(_x3) {
|
|
32926
|
+
return _ref7.apply(this, arguments);
|
|
32940
32927
|
};
|
|
32941
32928
|
}();
|
|
32942
32929
|
var addSignerOnPremise = /*#__PURE__*/function () {
|
|
32943
|
-
var
|
|
32944
|
-
return _regenerator().w(function (
|
|
32945
|
-
while (1) switch (
|
|
32930
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
32931
|
+
return _regenerator().w(function (_context8) {
|
|
32932
|
+
while (1) switch (_context8.n) {
|
|
32946
32933
|
case 0:
|
|
32947
|
-
|
|
32948
|
-
|
|
32949
|
-
|
|
32950
|
-
}));
|
|
32934
|
+
throw new ApacuanaAPIError("Adding signers is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
|
|
32935
|
+
case 1:
|
|
32936
|
+
return _context8.a(2);
|
|
32951
32937
|
}
|
|
32952
|
-
},
|
|
32938
|
+
}, _callee8);
|
|
32953
32939
|
}));
|
|
32954
32940
|
return function addSignerOnPremise() {
|
|
32955
|
-
return
|
|
32941
|
+
return _ref8.apply(this, arguments);
|
|
32956
32942
|
};
|
|
32957
32943
|
}();
|
|
32958
32944
|
|
|
32959
32945
|
/**
|
|
32960
|
-
*
|
|
32961
|
-
* @param {object} signerData -
|
|
32962
|
-
* @returns {Promise<
|
|
32946
|
+
* Adds a signer to a document, handling different integration types.
|
|
32947
|
+
* @param {object} signerData - Data of the signer to be added.
|
|
32948
|
+
* @returns {Promise<{signer: string, success: boolean}>} Object with the result of adding the signer.
|
|
32949
|
+
* @throws {ApacuanaAPIError} If the signer data is invalid, if the API call fails, or if the integration type is not supported.
|
|
32963
32950
|
*/
|
|
32964
32951
|
var addSigner = /*#__PURE__*/function () {
|
|
32965
|
-
var
|
|
32966
|
-
var
|
|
32967
|
-
return _regenerator().w(function (
|
|
32968
|
-
while (1) switch (
|
|
32952
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(signerData) {
|
|
32953
|
+
var _getConfig3, integrationType;
|
|
32954
|
+
return _regenerator().w(function (_context9) {
|
|
32955
|
+
while (1) switch (_context9.n) {
|
|
32969
32956
|
case 0:
|
|
32970
32957
|
if (!(!signerData || _typeof(signerData) !== "object" || Object.keys(signerData).length === 0)) {
|
|
32971
|
-
|
|
32958
|
+
_context9.n = 1;
|
|
32972
32959
|
break;
|
|
32973
32960
|
}
|
|
32974
|
-
throw new ApacuanaAPIError("
|
|
32961
|
+
throw new ApacuanaAPIError("Signer data (signerData) is required and must be a non-empty object.", 400, "INVALID_PARAMETER");
|
|
32975
32962
|
case 1:
|
|
32976
|
-
|
|
32963
|
+
_getConfig3 = getConfig(), integrationType = _getConfig3.integrationType;
|
|
32977
32964
|
if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
|
|
32978
|
-
|
|
32965
|
+
_context9.n = 2;
|
|
32979
32966
|
break;
|
|
32980
32967
|
}
|
|
32981
|
-
return
|
|
32968
|
+
return _context9.a(2, addSignerOnBoarding(signerData));
|
|
32982
32969
|
case 2:
|
|
32983
32970
|
if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
|
|
32984
|
-
|
|
32971
|
+
_context9.n = 3;
|
|
32985
32972
|
break;
|
|
32986
32973
|
}
|
|
32987
|
-
return
|
|
32974
|
+
return _context9.a(2, addSignerOnPremise(signerData));
|
|
32988
32975
|
case 3:
|
|
32989
|
-
throw new ApacuanaAPIError("
|
|
32976
|
+
throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
|
|
32990
32977
|
case 4:
|
|
32991
|
-
return
|
|
32978
|
+
return _context9.a(2);
|
|
32992
32979
|
}
|
|
32993
|
-
},
|
|
32980
|
+
}, _callee9);
|
|
32994
32981
|
}));
|
|
32995
|
-
return function addSigner(
|
|
32996
|
-
return
|
|
32982
|
+
return function addSigner(_x4) {
|
|
32983
|
+
return _ref9.apply(this, arguments);
|
|
32997
32984
|
};
|
|
32998
32985
|
}();
|
|
32999
32986
|
var getDocsOnPremise = /*#__PURE__*/function () {
|
|
33000
|
-
var
|
|
33001
|
-
return _regenerator().w(function (
|
|
33002
|
-
while (1) switch (
|
|
32987
|
+
var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
32988
|
+
return _regenerator().w(function (_context0) {
|
|
32989
|
+
while (1) switch (_context0.n) {
|
|
33003
32990
|
case 0:
|
|
33004
|
-
throw new ApacuanaAPIError("
|
|
32991
|
+
throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONBOARDING", 501, "NOT_IMPLEMENTED");
|
|
33005
32992
|
case 1:
|
|
33006
|
-
return
|
|
32993
|
+
return _context0.a(2);
|
|
33007
32994
|
}
|
|
33008
|
-
},
|
|
32995
|
+
}, _callee0);
|
|
33009
32996
|
}));
|
|
33010
32997
|
return function getDocsOnPremise() {
|
|
33011
|
-
return
|
|
32998
|
+
return _ref0.apply(this, arguments);
|
|
33012
32999
|
};
|
|
33013
33000
|
}();
|
|
33014
33001
|
var getDocsOnBoarding = /*#__PURE__*/function () {
|
|
33015
|
-
var
|
|
33016
|
-
var
|
|
33017
|
-
return _regenerator().w(function (
|
|
33018
|
-
while (1) switch (
|
|
33002
|
+
var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(data) {
|
|
33003
|
+
var _getConfig4, customerId, params, apiUrl, response, _t3;
|
|
33004
|
+
return _regenerator().w(function (_context1) {
|
|
33005
|
+
while (1) switch (_context1.p = _context1.n) {
|
|
33019
33006
|
case 0:
|
|
33020
|
-
|
|
33007
|
+
_getConfig4 = getConfig(), customerId = _getConfig4.customerId;
|
|
33021
33008
|
if (customerId) {
|
|
33022
|
-
|
|
33009
|
+
_context1.n = 1;
|
|
33023
33010
|
break;
|
|
33024
33011
|
}
|
|
33025
|
-
throw new ApacuanaAPIError("
|
|
33012
|
+
throw new ApacuanaAPIError("'customerId' is not configured. Please configure the SDK.", 400, "CONFIGURATION_ERROR");
|
|
33026
33013
|
case 1:
|
|
33027
|
-
|
|
33028
|
-
|
|
33029
|
-
|
|
33014
|
+
_context1.p = 1;
|
|
33015
|
+
params = new URLSearchParams({
|
|
33016
|
+
page: data.page,
|
|
33017
|
+
customerid: customerId,
|
|
33018
|
+
size: data.size
|
|
33019
|
+
});
|
|
33020
|
+
if (typeof data.status !== "undefined") {
|
|
33021
|
+
params.append("status", data.status);
|
|
33022
|
+
}
|
|
33023
|
+
apiUrl = "services/api/documents/listcustomer?".concat(params.toString());
|
|
33024
|
+
_context1.n = 2;
|
|
33030
33025
|
return httpRequest(apiUrl, {}, "GET");
|
|
33031
33026
|
case 2:
|
|
33032
|
-
response =
|
|
33033
|
-
return
|
|
33027
|
+
response = _context1.v;
|
|
33028
|
+
return _context1.a(2, {
|
|
33029
|
+
totalRecords: response.numofrecords,
|
|
33030
|
+
records: response.records,
|
|
33031
|
+
success: true
|
|
33032
|
+
});
|
|
33034
33033
|
case 3:
|
|
33035
|
-
|
|
33036
|
-
|
|
33037
|
-
if (!(
|
|
33038
|
-
|
|
33034
|
+
_context1.p = 3;
|
|
33035
|
+
_t3 = _context1.v;
|
|
33036
|
+
if (!(_t3.name === "ApacuanaAPIError")) {
|
|
33037
|
+
_context1.n = 4;
|
|
33039
33038
|
break;
|
|
33040
33039
|
}
|
|
33041
|
-
throw
|
|
33040
|
+
throw _t3;
|
|
33042
33041
|
case 4:
|
|
33043
|
-
throw new ApacuanaAPIError("
|
|
33042
|
+
throw new ApacuanaAPIError("Failed to get document list (on-premise): ".concat(_t3.message));
|
|
33044
33043
|
case 5:
|
|
33045
|
-
return
|
|
33044
|
+
return _context1.a(2);
|
|
33046
33045
|
}
|
|
33047
|
-
},
|
|
33046
|
+
}, _callee1, null, [[1, 3]]);
|
|
33048
33047
|
}));
|
|
33049
|
-
return function getDocsOnBoarding(
|
|
33050
|
-
return
|
|
33048
|
+
return function getDocsOnBoarding(_x5) {
|
|
33049
|
+
return _ref1.apply(this, arguments);
|
|
33051
33050
|
};
|
|
33052
33051
|
}();
|
|
33053
33052
|
|
|
33054
33053
|
/**
|
|
33055
|
-
*
|
|
33056
|
-
* @param {object} data -
|
|
33057
|
-
* @returns {Promise<
|
|
33054
|
+
* Gets a list of documents.
|
|
33055
|
+
* @param {object} data - Object with pagination parameters. Must contain {page, size}.
|
|
33056
|
+
* @returns {Promise<{totalRecords: number, records:any[], success: boolean}>} Object with the list of documents.
|
|
33057
|
+
* @throws {ApacuanaAPIError} If pagination parameters are invalid, if 'customerId' is not configured, if the API call fails, or if the integration type is not supported.
|
|
33058
33058
|
*/
|
|
33059
33059
|
var getDocs = /*#__PURE__*/function () {
|
|
33060
|
-
var
|
|
33061
|
-
var
|
|
33062
|
-
return _regenerator().w(function (
|
|
33063
|
-
while (1) switch (
|
|
33060
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(data) {
|
|
33061
|
+
var _getConfig5, integrationType;
|
|
33062
|
+
return _regenerator().w(function (_context10) {
|
|
33063
|
+
while (1) switch (_context10.n) {
|
|
33064
33064
|
case 0:
|
|
33065
33065
|
helpers.validateGetDocsData(data);
|
|
33066
|
-
|
|
33066
|
+
_getConfig5 = getConfig(), integrationType = _getConfig5.integrationType;
|
|
33067
33067
|
if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
|
|
33068
|
-
|
|
33068
|
+
_context10.n = 1;
|
|
33069
33069
|
break;
|
|
33070
33070
|
}
|
|
33071
|
-
return
|
|
33071
|
+
return _context10.a(2, getDocsOnBoarding(data));
|
|
33072
33072
|
case 1:
|
|
33073
33073
|
if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
|
|
33074
|
-
|
|
33074
|
+
_context10.n = 2;
|
|
33075
33075
|
break;
|
|
33076
33076
|
}
|
|
33077
|
-
return
|
|
33077
|
+
return _context10.a(2, getDocsOnPremise());
|
|
33078
33078
|
case 2:
|
|
33079
|
-
throw new ApacuanaAPIError("
|
|
33079
|
+
throw new ApacuanaAPIError("Document retrieval is not supported for an unknown integration type: ".concat(integrationType), 501, "NOT_IMPLEMENTED");
|
|
33080
33080
|
case 3:
|
|
33081
|
-
return
|
|
33081
|
+
return _context10.a(2);
|
|
33082
33082
|
}
|
|
33083
|
-
},
|
|
33083
|
+
}, _callee10);
|
|
33084
33084
|
}));
|
|
33085
|
-
return function getDocs(
|
|
33086
|
-
return
|
|
33085
|
+
return function getDocs(_x6) {
|
|
33086
|
+
return _ref10.apply(this, arguments);
|
|
33087
33087
|
};
|
|
33088
33088
|
}();
|
|
33089
33089
|
|
|
@@ -33160,7 +33160,8 @@ var apacuana = {
|
|
|
33160
33160
|
getCertStatus: getCertStatus,
|
|
33161
33161
|
getCustomer: getCustomer,
|
|
33162
33162
|
addSigner: addSigner,
|
|
33163
|
-
getDocs: getDocs
|
|
33163
|
+
getDocs: getDocs,
|
|
33164
|
+
generateCert: generateCert
|
|
33164
33165
|
};
|
|
33165
33166
|
|
|
33166
33167
|
module.exports = apacuana;
|