apacuana-sdk-core 1.2.0 → 1.6.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.
Files changed (30) hide show
  1. package/coverage/clover.xml +79 -78
  2. package/coverage/coverage-final.json +2 -2
  3. package/coverage/lcov-report/index.html +11 -11
  4. package/coverage/lcov-report/src/api/certs.js.html +16 -10
  5. package/coverage/lcov-report/src/api/faceLiveness.js.html +1 -1
  6. package/coverage/lcov-report/src/api/index.html +11 -11
  7. package/coverage/lcov-report/src/api/revocations.js.html +1 -1
  8. package/coverage/lcov-report/src/api/signatures.js.html +1 -1
  9. package/coverage/lcov-report/src/api/users.js.html +3 -3
  10. package/coverage/lcov-report/src/config/index.html +1 -1
  11. package/coverage/lcov-report/src/config/index.js.html +1 -1
  12. package/coverage/lcov-report/src/errors/index.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.js.html +1 -1
  14. package/coverage/lcov-report/src/index.html +1 -1
  15. package/coverage/lcov-report/src/index.js.html +1 -1
  16. package/coverage/lcov-report/src/success/index.html +1 -1
  17. package/coverage/lcov-report/src/success/index.js.html +1 -1
  18. package/coverage/lcov-report/src/utils/constant.js.html +2 -2
  19. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  21. package/coverage/lcov-report/src/utils/index.html +1 -1
  22. package/coverage/lcov.info +122 -121
  23. package/dist/index.js +225 -204
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +225 -204
  26. package/dist/index.mjs.map +1 -1
  27. package/package.json +1 -1
  28. package/src/api/certs.js +5 -3
  29. package/src/utils/constant.js +1 -1
  30. package/tests/api/certs.test.js +38 -14
package/dist/index.js CHANGED
@@ -295,7 +295,7 @@ var PARSE_STATUS = _defineProperty(_defineProperty(_defineProperty(_defineProper
295
295
  text: "Por generar",
296
296
  descriptionText: "Tu solicitud fue aprobada. Solo falta que generes tu certificado para comenzar a usarlo."
297
297
  }), STATUS_CERTIFICATE.current, {
298
- text: " ",
298
+ text: "Verificado",
299
299
  descriptionText: undefined
300
300
  }), STATUS_CERTIFICATE.expire, "Certificado expirado."), STATUS_CERTIFICATE.request_revoque, {
301
301
  text: "Por revocar",
@@ -33050,6 +33050,141 @@ var helpers = {
33050
33050
  createPayloadGetDigest: createPayloadGetDigest
33051
33051
  };
33052
33052
 
33053
+ /**
33054
+ * @typedef {object} GetCustomerData
33055
+ * @property {string} token - El token de sesión del usuario.
33056
+ * @property {object} userData - Los datos del usuario obtenidos.
33057
+ */
33058
+
33059
+ /**
33060
+ * @typedef {object} GetCustomerResponse
33061
+ * @property {true} success - Indica que la operación fue exitosa.
33062
+ * @property {GetCustomerData} data - El payload de la respuesta.
33063
+ */
33064
+
33065
+ /**
33066
+ * Obtiene el token de un usuario a través de una petición POST.
33067
+ * Este método es útil para endpoints que requieren datos en el cuerpo de la petición
33068
+ * para buscar un usuario, como un ID de sesión o un token de acceso.
33069
+ *
33070
+ * @returns {Promise<GetCustomerResponse>} Una promesa que resuelve a un objeto con la respuesta exitosa.
33071
+ * @throws {Error} Si los parámetros de entrada son inválidos.
33072
+ * @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
33073
+ */
33074
+ var getCustomer = /*#__PURE__*/function () {
33075
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
33076
+ var _getConfig, verificationId, customerId, body, response, _t;
33077
+ return _regenerator().w(function (_context) {
33078
+ while (1) switch (_context.p = _context.n) {
33079
+ case 0:
33080
+ _getConfig = getConfig(), verificationId = _getConfig.verificationId, customerId = _getConfig.customerId;
33081
+ if (!(!verificationId || !customerId)) {
33082
+ _context.n = 1;
33083
+ break;
33084
+ }
33085
+ throw new ApacuanaAPIError("Both 'verificationId' and 'customerId' must be configured.", 400, "CONFIGURATION_ERROR");
33086
+ case 1:
33087
+ body = {
33088
+ verificationid: verificationId,
33089
+ customerid: customerId
33090
+ };
33091
+ _context.p = 2;
33092
+ _context.n = 3;
33093
+ return httpRequest("services/api/register/init", body, "POST");
33094
+ case 3:
33095
+ response = _context.v;
33096
+ if (!(!response.sessionid || !response.entry)) {
33097
+ _context.n = 4;
33098
+ break;
33099
+ }
33100
+ throw new ApacuanaAPIError("The API response does not contain the user.", 200, "INVALID_API_RESPONSE");
33101
+ case 4:
33102
+ return _context.a(2, new ApacuanaSuccess({
33103
+ token: response.sessionid,
33104
+ userData: response.entry
33105
+ }));
33106
+ case 5:
33107
+ _context.p = 5;
33108
+ _t = _context.v;
33109
+ if (!(_t instanceof ApacuanaAPIError)) {
33110
+ _context.n = 6;
33111
+ break;
33112
+ }
33113
+ throw _t;
33114
+ case 6:
33115
+ throw new ApacuanaAPIError("Unexpected failure getting token: ".concat(_t.message || "Unknown error"));
33116
+ case 7:
33117
+ return _context.a(2);
33118
+ }
33119
+ }, _callee, null, [[2, 5]]);
33120
+ }));
33121
+ return function getCustomer() {
33122
+ return _ref.apply(this, arguments);
33123
+ };
33124
+ }();
33125
+
33126
+ /**
33127
+ * @typedef {object} CreateUserPayload
33128
+ * @property {string} usr - Correo electrónico del usuario.
33129
+ * @property {string} pwd - Contraseña del usuario.
33130
+ * @property {string} kinddoc - Tipo de documento de identidad (ej. 'V', 'P', 'E').
33131
+ * @property {string} doc - Número de documento de identidad.
33132
+ */
33133
+
33134
+ /**
33135
+ * @typedef {object} CreateUserResponse
33136
+ * @property {string} message - Mensaje de confirmación de la creación del usuario.
33137
+ */
33138
+
33139
+ /**
33140
+ * Crea un nuevo usuario en la plataforma de Apacuana.
33141
+ * @param {CreateUserPayload} userData - Objeto con los datos del usuario a crear.
33142
+ * @returns {Promise<ApacuanaSuccess>} Una promesa que resuelve a un objeto con la respuesta exitosa.
33143
+ * @throws {ApacuanaAPIError} Si los datos de entrada son inválidos o si ocurre un error en la API.
33144
+ */
33145
+
33146
+ var createApacuanaUser = /*#__PURE__*/function () {
33147
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(userData) {
33148
+ var formData, response, _t2;
33149
+ return _regenerator().w(function (_context2) {
33150
+ while (1) switch (_context2.p = _context2.n) {
33151
+ case 0:
33152
+ _context2.p = 0;
33153
+ formData = new FormData();
33154
+ Object.keys(userData).forEach(function (key) {
33155
+ var value = userData[key];
33156
+ var isRNFile = value && _typeof(value) === "object" && value.uri && value.name && value.type;
33157
+ if (value instanceof File || isRNFile) {
33158
+ formData.append(key, value);
33159
+ } else if (value !== null && value !== undefined) {
33160
+ formData.append(key, String(value));
33161
+ }
33162
+ });
33163
+ _context2.n = 1;
33164
+ return httpRequest("services/api/register/initial", formData, "POST");
33165
+ case 1:
33166
+ response = _context2.v;
33167
+ return _context2.a(2, new ApacuanaSuccess(_objectSpread2({}, response)));
33168
+ case 2:
33169
+ _context2.p = 2;
33170
+ _t2 = _context2.v;
33171
+ if (!(_t2 instanceof ApacuanaAPIError)) {
33172
+ _context2.n = 3;
33173
+ break;
33174
+ }
33175
+ throw _t2;
33176
+ case 3:
33177
+ throw new ApacuanaAPIError("Unexpected failure creating user: ".concat(_t2.message || "Unknown error"));
33178
+ case 4:
33179
+ return _context2.a(2);
33180
+ }
33181
+ }, _callee2, null, [[0, 2]]);
33182
+ }));
33183
+ return function createApacuanaUser(_x) {
33184
+ return _ref2.apply(this, arguments);
33185
+ };
33186
+ }();
33187
+
33053
33188
  /**
33054
33189
  * @param {EncryptedCSRObject} encryptedCSR
33055
33190
  */
@@ -33153,60 +33288,81 @@ var generateCert = /*#__PURE__*/function () {
33153
33288
  * @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
33154
33289
  * @returns {GetCertStatusResponse} Object with the certificate status and a success indicator.
33155
33290
  */
33156
- var getCertStatus = function getCertStatus() {
33157
- var isCertificateInDevice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
33158
- var config = getConfig();
33159
- var status = helpers.getCertificateStatus(config.userData, isCertificateInDevice, config.integrationType);
33160
- console.log(status, "Core sdk");
33161
- var parseStatus = PARSE_STATUS[status];
33162
- return new ApacuanaSuccess({
33163
- status: parseStatus
33164
- });
33165
- };
33166
- var getCertTypesOnBoarding = /*#__PURE__*/function () {
33291
+ var getCertStatus = /*#__PURE__*/function () {
33167
33292
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
33168
- var response, _t2;
33293
+ var isCertificateInDevice,
33294
+ config,
33295
+ customer,
33296
+ userData,
33297
+ status,
33298
+ parseStatus,
33299
+ _args4 = arguments;
33169
33300
  return _regenerator().w(function (_context4) {
33170
- while (1) switch (_context4.p = _context4.n) {
33301
+ while (1) switch (_context4.n) {
33171
33302
  case 0:
33172
- _context4.p = 0;
33303
+ isCertificateInDevice = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : false;
33304
+ config = getConfig();
33173
33305
  _context4.n = 1;
33306
+ return getCustomer();
33307
+ case 1:
33308
+ customer = _context4.v;
33309
+ userData = customer.data.userData;
33310
+ status = helpers.getCertificateStatus(userData, isCertificateInDevice, config.integrationType);
33311
+ parseStatus = PARSE_STATUS[status];
33312
+ return _context4.a(2, new ApacuanaSuccess({
33313
+ status: parseStatus
33314
+ }));
33315
+ }
33316
+ }, _callee4);
33317
+ }));
33318
+ return function getCertStatus() {
33319
+ return _ref4.apply(this, arguments);
33320
+ };
33321
+ }();
33322
+ var getCertTypesOnBoarding = /*#__PURE__*/function () {
33323
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
33324
+ var response, _t2;
33325
+ return _regenerator().w(function (_context5) {
33326
+ while (1) switch (_context5.p = _context5.n) {
33327
+ case 0:
33328
+ _context5.p = 0;
33329
+ _context5.n = 1;
33174
33330
  return httpRequest("services/api/customer/typeusers", {}, "GET");
33175
33331
  case 1:
33176
- response = _context4.v;
33177
- return _context4.a(2, new ApacuanaSuccess(response));
33332
+ response = _context5.v;
33333
+ return _context5.a(2, new ApacuanaSuccess(response));
33178
33334
  case 2:
33179
- _context4.p = 2;
33180
- _t2 = _context4.v;
33335
+ _context5.p = 2;
33336
+ _t2 = _context5.v;
33181
33337
  if (!(_t2 instanceof ApacuanaAPIError)) {
33182
- _context4.n = 3;
33338
+ _context5.n = 3;
33183
33339
  break;
33184
33340
  }
33185
33341
  throw _t2;
33186
33342
  case 3:
33187
33343
  throw new Error("Failed to get certificate types: ".concat(_t2.message));
33188
33344
  case 4:
33189
- return _context4.a(2);
33345
+ return _context5.a(2);
33190
33346
  }
33191
- }, _callee4, null, [[0, 2]]);
33347
+ }, _callee5, null, [[0, 2]]);
33192
33348
  }));
33193
33349
  return function getCertTypesOnBoarding() {
33194
- return _ref4.apply(this, arguments);
33350
+ return _ref5.apply(this, arguments);
33195
33351
  };
33196
33352
  }();
33197
33353
  var getCertTypesOnPremise = /*#__PURE__*/function () {
33198
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
33199
- return _regenerator().w(function (_context5) {
33200
- while (1) switch (_context5.n) {
33354
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
33355
+ return _regenerator().w(function (_context6) {
33356
+ while (1) switch (_context6.n) {
33201
33357
  case 0:
33202
33358
  throw new ApacuanaAPIError("Getting certificate types is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
33203
33359
  case 1:
33204
- return _context5.a(2);
33360
+ return _context6.a(2);
33205
33361
  }
33206
- }, _callee5);
33362
+ }, _callee6);
33207
33363
  }));
33208
33364
  return function getCertTypesOnPremise() {
33209
- return _ref5.apply(this, arguments);
33365
+ return _ref6.apply(this, arguments);
33210
33366
  };
33211
33367
  }();
33212
33368
 
@@ -33217,78 +33373,78 @@ var getCertTypesOnPremise = /*#__PURE__*/function () {
33217
33373
  * @throws {Error} If the request fails for another reason.
33218
33374
  */
33219
33375
  var getCertTypes = /*#__PURE__*/function () {
33220
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
33376
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
33221
33377
  var _getConfig2, integrationType;
33222
- return _regenerator().w(function (_context6) {
33223
- while (1) switch (_context6.n) {
33378
+ return _regenerator().w(function (_context7) {
33379
+ while (1) switch (_context7.n) {
33224
33380
  case 0:
33225
33381
  _getConfig2 = getConfig(), integrationType = _getConfig2.integrationType;
33226
33382
  if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33227
- _context6.n = 1;
33383
+ _context7.n = 1;
33228
33384
  break;
33229
33385
  }
33230
- return _context6.a(2, getCertTypesOnBoarding());
33386
+ return _context7.a(2, getCertTypesOnBoarding());
33231
33387
  case 1:
33232
33388
  if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33233
- _context6.n = 2;
33389
+ _context7.n = 2;
33234
33390
  break;
33235
33391
  }
33236
- return _context6.a(2, getCertTypesOnPremise());
33392
+ return _context7.a(2, getCertTypesOnPremise());
33237
33393
  case 2:
33238
33394
  throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33239
33395
  case 3:
33240
- return _context6.a(2);
33396
+ return _context7.a(2);
33241
33397
  }
33242
- }, _callee6);
33398
+ }, _callee7);
33243
33399
  }));
33244
33400
  return function getCertTypes() {
33245
- return _ref6.apply(this, arguments);
33401
+ return _ref7.apply(this, arguments);
33246
33402
  };
33247
33403
  }();
33248
33404
  var getRequerimentsByTypeUserOnBoarding = /*#__PURE__*/function () {
33249
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(type) {
33405
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(type) {
33250
33406
  var response, _t3;
33251
- return _regenerator().w(function (_context7) {
33252
- while (1) switch (_context7.p = _context7.n) {
33407
+ return _regenerator().w(function (_context8) {
33408
+ while (1) switch (_context8.p = _context8.n) {
33253
33409
  case 0:
33254
- _context7.p = 0;
33255
- _context7.n = 1;
33410
+ _context8.p = 0;
33411
+ _context8.n = 1;
33256
33412
  return httpRequest("services/api/customer/documentspref?typeuser=".concat(type), {}, "GET");
33257
33413
  case 1:
33258
- response = _context7.v;
33259
- return _context7.a(2, new ApacuanaSuccess(response));
33414
+ response = _context8.v;
33415
+ return _context8.a(2, new ApacuanaSuccess(response));
33260
33416
  case 2:
33261
- _context7.p = 2;
33262
- _t3 = _context7.v;
33417
+ _context8.p = 2;
33418
+ _t3 = _context8.v;
33263
33419
  if (!(_t3 instanceof ApacuanaAPIError)) {
33264
- _context7.n = 3;
33420
+ _context8.n = 3;
33265
33421
  break;
33266
33422
  }
33267
33423
  throw _t3;
33268
33424
  case 3:
33269
33425
  throw new Error("Failed to get requirements: ".concat(_t3.message));
33270
33426
  case 4:
33271
- return _context7.a(2);
33427
+ return _context8.a(2);
33272
33428
  }
33273
- }, _callee7, null, [[0, 2]]);
33429
+ }, _callee8, null, [[0, 2]]);
33274
33430
  }));
33275
33431
  return function getRequerimentsByTypeUserOnBoarding(_x3) {
33276
- return _ref7.apply(this, arguments);
33432
+ return _ref8.apply(this, arguments);
33277
33433
  };
33278
33434
  }();
33279
33435
  var getRequerimentsByTypeUserOnPremise = /*#__PURE__*/function () {
33280
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
33281
- return _regenerator().w(function (_context8) {
33282
- while (1) switch (_context8.n) {
33436
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
33437
+ return _regenerator().w(function (_context9) {
33438
+ while (1) switch (_context9.n) {
33283
33439
  case 0:
33284
33440
  throw new ApacuanaAPIError("Getting requirements by user type is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
33285
33441
  case 1:
33286
- return _context8.a(2);
33442
+ return _context9.a(2);
33287
33443
  }
33288
- }, _callee8);
33444
+ }, _callee9);
33289
33445
  }));
33290
33446
  return function getRequerimentsByTypeUserOnPremise() {
33291
- return _ref8.apply(this, arguments);
33447
+ return _ref9.apply(this, arguments);
33292
33448
  };
33293
33449
  }();
33294
33450
 
@@ -33301,13 +33457,13 @@ var getRequerimentsByTypeUserOnPremise = /*#__PURE__*/function () {
33301
33457
  * @throws {Error} If the request fails for another reason or the type is invalid.
33302
33458
  */
33303
33459
  var getRequerimentsByTypeUser = /*#__PURE__*/function () {
33304
- var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(params) {
33460
+ var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(params) {
33305
33461
  var type, _getConfig3, integrationType;
33306
- return _regenerator().w(function (_context9) {
33307
- while (1) switch (_context9.n) {
33462
+ return _regenerator().w(function (_context0) {
33463
+ while (1) switch (_context0.n) {
33308
33464
  case 0:
33309
33465
  if (!(!params || typeof params.type !== "number")) {
33310
- _context9.n = 1;
33466
+ _context0.n = 1;
33311
33467
  break;
33312
33468
  }
33313
33469
  throw new Error('The "params" object with a numeric "type" property is required.');
@@ -33315,25 +33471,25 @@ var getRequerimentsByTypeUser = /*#__PURE__*/function () {
33315
33471
  type = params.type;
33316
33472
  _getConfig3 = getConfig(), integrationType = _getConfig3.integrationType;
33317
33473
  if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33318
- _context9.n = 2;
33474
+ _context0.n = 2;
33319
33475
  break;
33320
33476
  }
33321
- return _context9.a(2, getRequerimentsByTypeUserOnBoarding(type));
33477
+ return _context0.a(2, getRequerimentsByTypeUserOnBoarding(type));
33322
33478
  case 2:
33323
33479
  if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33324
- _context9.n = 3;
33480
+ _context0.n = 3;
33325
33481
  break;
33326
33482
  }
33327
- return _context9.a(2, getRequerimentsByTypeUserOnPremise());
33483
+ return _context0.a(2, getRequerimentsByTypeUserOnPremise());
33328
33484
  case 3:
33329
33485
  throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33330
33486
  case 4:
33331
- return _context9.a(2);
33487
+ return _context0.a(2);
33332
33488
  }
33333
- }, _callee9);
33489
+ }, _callee0);
33334
33490
  }));
33335
33491
  return function getRequerimentsByTypeUser(_x4) {
33336
- return _ref9.apply(this, arguments);
33492
+ return _ref0.apply(this, arguments);
33337
33493
  };
33338
33494
  }();
33339
33495
 
@@ -34204,141 +34360,6 @@ var validateFaceLiveness = /*#__PURE__*/function () {
34204
34360
  };
34205
34361
  }();
34206
34362
 
34207
- /**
34208
- * @typedef {object} GetCustomerData
34209
- * @property {string} token - El token de sesión del usuario.
34210
- * @property {object} userData - Los datos del usuario obtenidos.
34211
- */
34212
-
34213
- /**
34214
- * @typedef {object} GetCustomerResponse
34215
- * @property {true} success - Indica que la operación fue exitosa.
34216
- * @property {GetCustomerData} data - El payload de la respuesta.
34217
- */
34218
-
34219
- /**
34220
- * Obtiene el token de un usuario a través de una petición POST.
34221
- * Este método es útil para endpoints que requieren datos en el cuerpo de la petición
34222
- * para buscar un usuario, como un ID de sesión o un token de acceso.
34223
- *
34224
- * @returns {Promise<GetCustomerResponse>} Una promesa que resuelve a un objeto con la respuesta exitosa.
34225
- * @throws {Error} Si los parámetros de entrada son inválidos.
34226
- * @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
34227
- */
34228
- var getCustomer = /*#__PURE__*/function () {
34229
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
34230
- var _getConfig, verificationId, customerId, body, response, _t;
34231
- return _regenerator().w(function (_context) {
34232
- while (1) switch (_context.p = _context.n) {
34233
- case 0:
34234
- _getConfig = getConfig(), verificationId = _getConfig.verificationId, customerId = _getConfig.customerId;
34235
- if (!(!verificationId || !customerId)) {
34236
- _context.n = 1;
34237
- break;
34238
- }
34239
- throw new ApacuanaAPIError("Both 'verificationId' and 'customerId' must be configured.", 400, "CONFIGURATION_ERROR");
34240
- case 1:
34241
- body = {
34242
- verificationid: verificationId,
34243
- customerid: customerId
34244
- };
34245
- _context.p = 2;
34246
- _context.n = 3;
34247
- return httpRequest("services/api/register/init", body, "POST");
34248
- case 3:
34249
- response = _context.v;
34250
- if (!(!response.sessionid || !response.entry)) {
34251
- _context.n = 4;
34252
- break;
34253
- }
34254
- throw new ApacuanaAPIError("The API response does not contain the user.", 200, "INVALID_API_RESPONSE");
34255
- case 4:
34256
- return _context.a(2, new ApacuanaSuccess({
34257
- token: response.sessionid,
34258
- userData: response.entry
34259
- }));
34260
- case 5:
34261
- _context.p = 5;
34262
- _t = _context.v;
34263
- if (!(_t instanceof ApacuanaAPIError)) {
34264
- _context.n = 6;
34265
- break;
34266
- }
34267
- throw _t;
34268
- case 6:
34269
- throw new ApacuanaAPIError("Unexpected failure getting token: ".concat(_t.message || "Unknown error"));
34270
- case 7:
34271
- return _context.a(2);
34272
- }
34273
- }, _callee, null, [[2, 5]]);
34274
- }));
34275
- return function getCustomer() {
34276
- return _ref.apply(this, arguments);
34277
- };
34278
- }();
34279
-
34280
- /**
34281
- * @typedef {object} CreateUserPayload
34282
- * @property {string} usr - Correo electrónico del usuario.
34283
- * @property {string} pwd - Contraseña del usuario.
34284
- * @property {string} kinddoc - Tipo de documento de identidad (ej. 'V', 'P', 'E').
34285
- * @property {string} doc - Número de documento de identidad.
34286
- */
34287
-
34288
- /**
34289
- * @typedef {object} CreateUserResponse
34290
- * @property {string} message - Mensaje de confirmación de la creación del usuario.
34291
- */
34292
-
34293
- /**
34294
- * Crea un nuevo usuario en la plataforma de Apacuana.
34295
- * @param {CreateUserPayload} userData - Objeto con los datos del usuario a crear.
34296
- * @returns {Promise<ApacuanaSuccess>} Una promesa que resuelve a un objeto con la respuesta exitosa.
34297
- * @throws {ApacuanaAPIError} Si los datos de entrada son inválidos o si ocurre un error en la API.
34298
- */
34299
-
34300
- var createApacuanaUser = /*#__PURE__*/function () {
34301
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(userData) {
34302
- var formData, response, _t2;
34303
- return _regenerator().w(function (_context2) {
34304
- while (1) switch (_context2.p = _context2.n) {
34305
- case 0:
34306
- _context2.p = 0;
34307
- formData = new FormData();
34308
- Object.keys(userData).forEach(function (key) {
34309
- var value = userData[key];
34310
- var isRNFile = value && _typeof(value) === "object" && value.uri && value.name && value.type;
34311
- if (value instanceof File || isRNFile) {
34312
- formData.append(key, value);
34313
- } else if (value !== null && value !== undefined) {
34314
- formData.append(key, String(value));
34315
- }
34316
- });
34317
- _context2.n = 1;
34318
- return httpRequest("services/api/register/initial", formData, "POST");
34319
- case 1:
34320
- response = _context2.v;
34321
- return _context2.a(2, new ApacuanaSuccess(_objectSpread2({}, response)));
34322
- case 2:
34323
- _context2.p = 2;
34324
- _t2 = _context2.v;
34325
- if (!(_t2 instanceof ApacuanaAPIError)) {
34326
- _context2.n = 3;
34327
- break;
34328
- }
34329
- throw _t2;
34330
- case 3:
34331
- throw new ApacuanaAPIError("Unexpected failure creating user: ".concat(_t2.message || "Unknown error"));
34332
- case 4:
34333
- return _context2.a(2);
34334
- }
34335
- }, _callee2, null, [[0, 2]]);
34336
- }));
34337
- return function createApacuanaUser(_x) {
34338
- return _ref2.apply(this, arguments);
34339
- };
34340
- }();
34341
-
34342
34363
  /**
34343
34364
  * Valida si el SDK está inicializado y si se dispone de un customerId.
34344
34365
  * @param {boolean} requiresCustomerId - Indica si la operación necesita un customerId.