aziendasanitaria-utils 1.2.75 → 1.2.76

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "engines": {
4
4
  "node": ">=14.0.0"
5
5
  },
6
- "version": "1.2.75",
6
+ "version": "1.2.76",
7
7
  "repository": "deduzzo/aziendasanitaria-utils",
8
8
  "description": "Un utility per gestire i flussi sanitari Siciliani e non solo..",
9
9
  "main": "index.js",
@@ -475,7 +475,7 @@ export class Nar2 {
475
475
  // Dropdown non critico: l'endpoint motiviOperazioneFiltered è spesso lento/intermittente.
476
476
  // Timeout breve e pochi retry → se non risponde fallisce in fretta e il chiamante usa il
477
477
  // default, invece di restare appeso (prima fino a ~4×10 tentativi senza timeout).
478
- const {soloScelta = true, semplifica = false, retryVuoto = 0, timeout = 20000, maxRetry = 2} = config;
478
+ const {soloScelta = true, semplifica = false, retryVuoto = 0, timeout = 30000, maxRetry = 3} = config;
479
479
  let data = null;
480
480
  let lastRes = null;
481
481
  for (let i = 0; i <= retryVuoto; i++) {
@@ -830,7 +830,9 @@ export class Nar2 {
830
830
  }
831
831
 
832
832
  // 7) Submit
833
- const result = await this.#postDataToUrl(Nar2.SCELTA_MEDICO_URL, payload);
833
+ const result = await this.#postDataToUrl(Nar2.SCELTA_MEDICO_URL, payload, {
834
+ referer: `https://nar2.regione.sicilia.it/operatore/pazienti/${pzId}/medico/scelta-medico`,
835
+ });
834
836
  return {
835
837
  ok: result.ok,
836
838
  dryRun: false,
@@ -2173,7 +2175,7 @@ export class Nar2 {
2173
2175
  }
2174
2176
 
2175
2177
  async #postDataToUrl(url, body, config = {}) {
2176
- const {replaceFromUrl = null, getParams = null, method = "post"} = config;
2178
+ const {replaceFromUrl = null, getParams = null, method = "post", referer = null} = config;
2177
2179
  const httpMethod = method.toLowerCase();
2178
2180
 
2179
2181
  let finalUrl = url;
@@ -2200,6 +2202,10 @@ export class Nar2 {
2200
2202
  Authorization: `Bearer ${Nar2.#token}`,
2201
2203
  'Content-Type': 'application/json',
2202
2204
  'Origin': new URL(finalUrl).origin,
2205
+ // NAR2 controlla lo User-Agent per distinguere client browser da bot/script.
2206
+ // Senza questo header risponde 403 "Client non autorizzato".
2207
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
2208
+ ...(referer ? { 'Referer': referer } : {}),
2203
2209
  ...(Nar2.#csrfCookies ? {
2204
2210
  'Cookie': Nar2.#csrfCookies.cookieHeader,
2205
2211
  'X-XSRF-TOKEN': Nar2.#csrfCookies.xsrfDecoded,