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