@credithub/harlan-components 1.115.2 → 1.116.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.
@@ -34,9 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ import { parseBpqlResponse } from '../../utils/bpqlResponse';
37
38
  export function sendInstrumentoManualEmail(client, payload) {
38
39
  return __awaiter(this, void 0, void 0, function () {
39
- var response, json;
40
+ var response, parsed;
40
41
  return __generator(this, function (_a) {
41
42
  switch (_a.label) {
42
43
  case 0: return [4 /*yield*/, client.request("INSERT INTO 'IEPTB'.'InstrumentoManualSendmail'", {
@@ -47,20 +48,21 @@ export function sendInstrumentoManualEmail(client, payload) {
47
48
  })];
48
49
  case 1:
49
50
  response = _a.sent();
50
- return [4 /*yield*/, response
51
- .clone()
52
- .json()
53
- .catch(function () { return null; })];
51
+ return [4 /*yield*/, parseBpqlResponse(response)];
54
52
  case 2:
55
- json = _a.sent();
56
- return [2 /*return*/, (json !== null && json !== void 0 ? json : {})];
53
+ parsed = _a.sent();
54
+ return [2 /*return*/, {
55
+ message: parsed.message,
56
+ _warning: parsed.warning,
57
+ jobId: parsed.jobId
58
+ }];
57
59
  }
58
60
  });
59
61
  });
60
62
  }
61
63
  export function sendInstrumentoDiscoveryEmail(client, payload) {
62
64
  return __awaiter(this, void 0, void 0, function () {
63
- var response, json;
65
+ var response, parsed;
64
66
  return __generator(this, function (_a) {
65
67
  switch (_a.label) {
66
68
  case 0: return [4 /*yield*/, client.request("INSERT INTO 'IEPTB'.'InstrumentoDiscoverySendmail'", {
@@ -69,13 +71,14 @@ export function sendInstrumentoDiscoveryEmail(client, payload) {
69
71
  })];
70
72
  case 1:
71
73
  response = _a.sent();
72
- return [4 /*yield*/, response
73
- .clone()
74
- .json()
75
- .catch(function () { return null; })];
74
+ return [4 /*yield*/, parseBpqlResponse(response)];
76
75
  case 2:
77
- json = _a.sent();
78
- return [2 /*return*/, (json !== null && json !== void 0 ? json : {})];
76
+ parsed = _a.sent();
77
+ return [2 /*return*/, {
78
+ message: parsed.message,
79
+ _warning: parsed.warning,
80
+ jobId: parsed.jobId
81
+ }];
79
82
  }
80
83
  });
81
84
  });
@@ -0,0 +1,6 @@
1
+ export type BpqlParsedResponse = {
2
+ message?: string;
3
+ warning?: string;
4
+ jobId?: string;
5
+ };
6
+ export declare const parseBpqlResponse: (response: Response) => Promise<BpqlParsedResponse>;
@@ -0,0 +1,82 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ export var parseBpqlResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
38
+ var text, json, parser, xml, rawDescription, description, warning, id;
39
+ var _a, _b, _c, _d, _e, _f;
40
+ return __generator(this, function (_g) {
41
+ switch (_g.label) {
42
+ case 0: return [4 /*yield*/, response.text()];
43
+ case 1:
44
+ text = _g.sent();
45
+ // Tenta JSON se o backend devolver nesse formato
46
+ try {
47
+ json = JSON.parse(text);
48
+ return [2 /*return*/, {
49
+ message: json === null || json === void 0 ? void 0 : json.message,
50
+ warning: json === null || json === void 0 ? void 0 : json._warning,
51
+ jobId: json === null || json === void 0 ? void 0 : json.jobId
52
+ }];
53
+ }
54
+ catch (_h) {
55
+ // segue para XML
56
+ }
57
+ // XML BPQL (padrão atual)
58
+ if (typeof DOMParser !== 'undefined') {
59
+ try {
60
+ parser = new DOMParser();
61
+ xml = parser.parseFromString(text, 'application/xml');
62
+ rawDescription = ((_b = (_a = xml.querySelector('header > description')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '';
63
+ description = rawDescription && rawDescription !== 'PUSH ID Created'
64
+ ? rawDescription
65
+ : '';
66
+ warning = ((_d = (_c = xml.querySelector('header > warning, header > Warning')) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.trim()) ||
67
+ '';
68
+ id = ((_f = (_e = xml.querySelector('body > id')) === null || _e === void 0 ? void 0 : _e.textContent) === null || _f === void 0 ? void 0 : _f.trim()) || '';
69
+ return [2 /*return*/, {
70
+ message: description || undefined,
71
+ warning: warning || undefined,
72
+ jobId: id || undefined
73
+ }];
74
+ }
75
+ catch (_j) {
76
+ return [2 /*return*/, {}];
77
+ }
78
+ }
79
+ return [2 /*return*/, {}];
80
+ }
81
+ });
82
+ }); };