@nomalism-com/api 0.51.13 → 0.51.15

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/dist/index.cjs CHANGED
@@ -233,6 +233,22 @@ var ApiError = class _ApiError extends Error {
233
233
  function isApiError(error) {
234
234
  return error instanceof ApiError;
235
235
  }
236
+ var MENSAGEM_POR_ESTADO = {
237
+ 400: "Os dados enviados n\xE3o s\xE3o v\xE1lidos. Verifique-os e tente novamente.",
238
+ 401: "A sess\xE3o terminou. Inicie sess\xE3o novamente.",
239
+ 403: "N\xE3o tem permiss\xE3o para realizar esta opera\xE7\xE3o.",
240
+ 404: "O que pediu n\xE3o foi encontrado. Atualize a p\xE1gina e tente novamente.",
241
+ 409: "Esta opera\xE7\xE3o entra em conflito com dados j\xE1 existentes. Atualize a p\xE1gina e tente novamente.",
242
+ 413: "O pedido \xE9 demasiado grande. Reduza a quantidade de informa\xE7\xE3o ou o tamanho do ficheiro.",
243
+ 422: "Os dados enviados n\xE3o s\xE3o v\xE1lidos. Verifique-os e tente novamente.",
244
+ 429: "Foram feitos demasiados pedidos seguidos. Aguarde um momento e tente novamente.",
245
+ 502: "O servidor n\xE3o est\xE1 a responder neste momento. Tente novamente dentro de instantes.",
246
+ 503: "O servidor n\xE3o est\xE1 dispon\xEDvel neste momento. Tente novamente dentro de instantes.",
247
+ 504: "O servidor demorou demasiado a responder. Tente novamente dentro de instantes."
248
+ };
249
+ function messageForStatus(status) {
250
+ return MENSAGEM_POR_ESTADO[status] ?? (status >= 500 ? "O sistema teve um problema ao tratar o pedido. Tente novamente; se o problema continuar, contacte o suporte." : "N\xE3o foi poss\xEDvel concluir a opera\xE7\xE3o. Tente novamente.");
251
+ }
236
252
  function extractServerMessage(data, fallback) {
237
253
  if (typeof data === "string" && data.trim()) return data;
238
254
  if (isRecord(data)) {
@@ -254,21 +270,24 @@ function parseApiError(error) {
254
270
  const code = axiosError.code;
255
271
  if (axiosError.response) {
256
272
  const { status, data } = axiosError.response;
257
- const message = extractServerMessage(
258
- data,
259
- `Request failed with status ${status}`
260
- );
273
+ const message = extractServerMessage(data, messageForStatus(status));
261
274
  return new ApiError(
262
275
  { kind: "response", message, status, code, method, url, data },
263
276
  error
264
277
  );
265
278
  }
266
279
  if (axiosError.request) {
267
- const message = code === "ECONNABORTED" ? `Request timed out${url ? ` (${method} ${url})` : ""}` : `No response received${url ? ` from ${method} ${url}` : ""}`;
280
+ const message = code === "ECONNABORTED" ? "O servidor demorou demasiado a responder. Tente novamente dentro de instantes." : "N\xE3o foi poss\xEDvel comunicar com o servidor. Verifique a liga\xE7\xE3o \xE0 internet e tente novamente.";
268
281
  return new ApiError({ kind: "request", message, code, method, url }, error);
269
282
  }
270
283
  return new ApiError(
271
- { kind: "setup", message: axiosError.message, code, method, url },
284
+ {
285
+ kind: "setup",
286
+ message: "N\xE3o foi poss\xEDvel enviar o pedido. Atualize a p\xE1gina e tente novamente.",
287
+ code,
288
+ method,
289
+ url
290
+ },
272
291
  error
273
292
  );
274
293
  }
@@ -368,7 +387,8 @@ var Repository4 = class {
368
387
  prison,
369
388
  note,
370
389
  availableStock,
371
- token
390
+ token,
391
+ as
372
392
  }) {
373
393
  const qs = new URLSearchParams();
374
394
  qs.set("ef_name", ef_name);
@@ -381,7 +401,8 @@ var Repository4 = class {
381
401
  }
382
402
  qs.set("prison", prison.toString());
383
403
  qs.set("availableStock", availableStock.toString());
384
- qs.set("token", token);
404
+ if (token) qs.set("token", token);
405
+ if (as) qs.set("as", as);
385
406
  return `${this.route}print_label_pdf/${product_id}?${qs.toString()}`;
386
407
  }
387
408
  printBulkLabelToPdfUrl({
@@ -390,7 +411,8 @@ var Repository4 = class {
390
411
  notOk,
391
412
  clientOrders,
392
413
  saved_em_picking_ids,
393
- token
414
+ token,
415
+ as
394
416
  }) {
395
417
  const qs = new URLSearchParams();
396
418
  qs.set("groupLabel", groupLabel.toString());
@@ -398,7 +420,8 @@ var Repository4 = class {
398
420
  qs.set("notOk", notOk);
399
421
  qs.set("clientOrders", clientOrders);
400
422
  qs.set("saved_em_picking_ids", saved_em_picking_ids);
401
- qs.set("token", token);
423
+ if (token) qs.set("token", token);
424
+ if (as) qs.set("as", as);
402
425
  return `${this.route}print_bulk_label_pdf?${qs.toString()}`;
403
426
  }
404
427
  };
@@ -1265,13 +1288,6 @@ var Repository32 = class {
1265
1288
  this.api = api;
1266
1289
  this.route = route;
1267
1290
  }
1268
- async create(body) {
1269
- const response = await this.api.post(
1270
- `${this.route}`,
1271
- body
1272
- );
1273
- return response.data;
1274
- }
1275
1291
  async findByKey(params) {
1276
1292
  const response = await this.api.get(
1277
1293
  `${this.route}by_key`,
@@ -1459,6 +1475,10 @@ var Repository36 = class {
1459
1475
  );
1460
1476
  return response.data;
1461
1477
  }
1478
+ async findToday() {
1479
+ const response = await this.api.get(`${this.route}today`);
1480
+ return response.data;
1481
+ }
1462
1482
  async findByOwner(params) {
1463
1483
  const response = await this.api.get(
1464
1484
  `${this.route}by_owner`,
@@ -2126,7 +2146,7 @@ var Repository52 = class {
2126
2146
  }
2127
2147
  printLabelToPdfUrl({ id }, { token }) {
2128
2148
  const qs = new URLSearchParams();
2129
- qs.set("token", token);
2149
+ if (token) qs.set("token", token);
2130
2150
  return `${this.route}print_label_pdf/${id}?${qs.toString()}`;
2131
2151
  }
2132
2152
  printLabelToPdfBulk({
@@ -2134,7 +2154,7 @@ var Repository52 = class {
2134
2154
  token
2135
2155
  }) {
2136
2156
  const qs = new URLSearchParams();
2137
- qs.set("token", token);
2157
+ if (token) qs.set("token", token);
2138
2158
  qs.set("ids", ids);
2139
2159
  return `${this.route}print_label_pdf/bulk?${qs.toString()}`;
2140
2160
  }
@@ -2313,15 +2333,11 @@ var Repository57 = class {
2313
2333
  getQueryExecuteUrl({
2314
2334
  query_id,
2315
2335
  output,
2316
- token,
2317
2336
  ...data
2318
2337
  }) {
2319
2338
  const qs = new URLSearchParams();
2320
2339
  qs.set("query_id", query_id);
2321
2340
  qs.set("output", output);
2322
- if (token) {
2323
- qs.set("token", token);
2324
- }
2325
2341
  Object.entries(data).forEach(([key, value]) => {
2326
2342
  if (typeof value === "undefined") return;
2327
2343
  if (value === null) return;
@@ -2472,14 +2488,12 @@ var Repository63 = class {
2472
2488
  getStockCsvUrl({
2473
2489
  date,
2474
2490
  version,
2475
- format,
2476
- token
2491
+ format
2477
2492
  }) {
2478
2493
  const qs = new URLSearchParams();
2479
2494
  qs.set("date", date.toISOString());
2480
2495
  qs.set("version", version);
2481
2496
  qs.set("format", format);
2482
- qs.set("token", token);
2483
2497
  return `${this.route}csv?${qs.toString()}`;
2484
2498
  }
2485
2499
  };
@@ -2784,15 +2798,13 @@ var Repository70 = class {
2784
2798
  owner_id,
2785
2799
  start_date,
2786
2800
  end_date,
2787
- output,
2788
- token
2801
+ output
2789
2802
  }) {
2790
2803
  const qs = new URLSearchParams();
2791
2804
  qs.set("owner_id", owner_id);
2792
2805
  qs.set("output", output);
2793
2806
  if (start_date) qs.set("start_date", start_date.toISOString());
2794
2807
  if (end_date) qs.set("end_date", end_date.toISOString());
2795
- qs.set("token", token);
2796
2808
  return `${this.route}export?${qs.toString()}`;
2797
2809
  }
2798
2810
  };
@@ -2884,6 +2896,9 @@ var Repository71 = class {
2884
2896
  if (data?.token) {
2885
2897
  qs.set("token", data.token);
2886
2898
  }
2899
+ if (data?.as) {
2900
+ qs.set("as", data.as);
2901
+ }
2887
2902
  return `${this.route}document_pdf/${id}?${qs.toString()}`;
2888
2903
  }
2889
2904
  async documentThermalPrint({ id }, query) {
@@ -3039,12 +3054,12 @@ var Repository75 = class {
3039
3054
  }
3040
3055
  printLabelToPdfUrl({ document_line_ids }, { token }) {
3041
3056
  const qs = new URLSearchParams();
3042
- qs.set("token", token);
3057
+ if (token) qs.set("token", token);
3043
3058
  return `${this.route}print_label_pdf/${document_line_ids}?${qs.toString()}`;
3044
3059
  }
3045
3060
  printGroupLabelToPdfUrl({ document_line_ids }, { token }) {
3046
3061
  const qs = new URLSearchParams();
3047
- qs.set("token", token);
3062
+ if (token) qs.set("token", token);
3048
3063
  return `${this.route}print_group_label_pdf/${document_line_ids}?${qs.toString()}`;
3049
3064
  }
3050
3065
  };
@@ -3303,8 +3318,8 @@ var Repository84 = class {
3303
3318
  });
3304
3319
  return response.data;
3305
3320
  }
3306
- async findAllProviderProducts() {
3307
- const response = await this.api.get(`${this.route}all_provider_products`);
3321
+ async findAllProviderProducts(params) {
3322
+ const response = await this.api.get(`${this.route}all_provider_products`, { params });
3308
3323
  return response.data;
3309
3324
  }
3310
3325
  };
@@ -3383,7 +3398,7 @@ var Repository86 = class {
3383
3398
  year
3384
3399
  }) {
3385
3400
  const qs = new URLSearchParams();
3386
- qs.set("token", token);
3401
+ if (token) qs.set("token", token);
3387
3402
  if (ids) {
3388
3403
  qs.set("ids", ids);
3389
3404
  return `${this.route}create_batch_pdf?${qs.toString()}`;
@@ -3488,15 +3503,10 @@ var Repository89 = class {
3488
3503
  constructor({ route }) {
3489
3504
  this.route = route;
3490
3505
  }
3491
- getUrl({
3492
- date_start,
3493
- date_end,
3494
- token
3495
- }) {
3506
+ getUrl({ date_start, date_end }) {
3496
3507
  const qs = new URLSearchParams();
3497
3508
  qs.set("date_start", date_start);
3498
3509
  qs.set("date_end", date_end);
3499
- qs.set("token", token);
3500
3510
  return `${this.route}download?${qs.toString()}`;
3501
3511
  }
3502
3512
  };
@@ -3589,7 +3599,7 @@ var Repository92 = class {
3589
3599
  return response.data;
3590
3600
  }
3591
3601
  async update({ id }, body) {
3592
- await this.api.post(`${this.route}${id}`, body);
3602
+ await this.api.put(`${this.route}${id}`, body);
3593
3603
  }
3594
3604
  async deleteOne({
3595
3605
  id
@@ -3610,13 +3620,6 @@ var Repository93 = class {
3610
3620
  this.api = api;
3611
3621
  this.route = route;
3612
3622
  }
3613
- async create(body) {
3614
- const response = await this.api.post(
3615
- `${this.route}`,
3616
- body
3617
- );
3618
- return response.data;
3619
- }
3620
3623
  async find() {
3621
3624
  const response = await this.api.get(`${this.route}`);
3622
3625
  return response.data;
@@ -3639,12 +3642,7 @@ var Repository93 = class {
3639
3642
  return response.data;
3640
3643
  }
3641
3644
  async update({ id }, body) {
3642
- await this.api.post(`${this.route}${id}`, body);
3643
- }
3644
- async deleteOne({
3645
- id
3646
- }) {
3647
- await this.api.delete(`${this.route}${id}`);
3645
+ await this.api.put(`${this.route}${id}`, body);
3648
3646
  }
3649
3647
  };
3650
3648
 
@@ -3691,7 +3689,7 @@ var Repository94 = class {
3691
3689
  return response.data;
3692
3690
  }
3693
3691
  async update({ id }, body) {
3694
- await this.api.post(`${this.route}${id}`, body);
3692
+ await this.api.put(`${this.route}${id}`, body);
3695
3693
  }
3696
3694
  async deleteOne({
3697
3695
  id
@@ -4419,15 +4417,6 @@ var Repository114 = class {
4419
4417
  });
4420
4418
  return response.data;
4421
4419
  }
4422
- async findForBillOfLading(data) {
4423
- const response = await this.api.get(
4424
- `${this.route}`,
4425
- {
4426
- data
4427
- }
4428
- );
4429
- return response.data;
4430
- }
4431
4420
  async findByEmail(data) {
4432
4421
  const response = await this.api.get(`${this.route}by_email`, {
4433
4422
  data
@@ -5154,6 +5143,7 @@ var Repository132 = class {
5154
5143
  // src/modules/view/webSocket.ts
5155
5144
  var CLOSE_AUTH_REJECTED = 4401;
5156
5145
  var CLOSE_AUTH_UNAVAILABLE = 4503;
5146
+ var MAX_AUTH_RETRIES = 3;
5157
5147
  var PING_INTERVAL_MS = 25e3;
5158
5148
  var MAX_BACKOFF_MS = 3e4;
5159
5149
  var BASE_BACKOFF_MS = 1e3;
@@ -5167,6 +5157,7 @@ var Service = class {
5167
5157
  }
5168
5158
  openSocket({
5169
5159
  token,
5160
+ onAuthRejected,
5170
5161
  channel,
5171
5162
  onEvent,
5172
5163
  onOpen,
@@ -5176,11 +5167,15 @@ var Service = class {
5176
5167
  }) {
5177
5168
  let ws = null;
5178
5169
  let attempts = 0;
5170
+ let authRejections = 0;
5179
5171
  let opensSoFar = 0;
5180
5172
  let pingTimer = null;
5181
5173
  let reconnectTimer = null;
5182
5174
  let closedByCaller = false;
5183
- const subprotocols = channel ? [`bearer.${token}`, `channel.${channel}`] : [`bearer.${token}`];
5175
+ const subprotocols = () => {
5176
+ const current = typeof token === "function" ? token() : token;
5177
+ return channel ? [`bearer.${current}`, `channel.${channel}`] : [`bearer.${current}`];
5178
+ };
5184
5179
  const stopPing = () => {
5185
5180
  if (pingTimer !== null) {
5186
5181
  window.clearInterval(pingTimer);
@@ -5211,7 +5206,7 @@ var Service = class {
5211
5206
  const connect = () => {
5212
5207
  if (closedByCaller) return;
5213
5208
  try {
5214
- ws = new WebSocket(this.route, subprotocols);
5209
+ ws = new WebSocket(this.route, subprotocols());
5215
5210
  } catch (err) {
5216
5211
  console.error("WebSocket constructor threw", err);
5217
5212
  scheduleReconnect();
@@ -5219,6 +5214,7 @@ var Service = class {
5219
5214
  }
5220
5215
  ws.onopen = () => {
5221
5216
  attempts = 0;
5217
+ authRejections = 0;
5222
5218
  opensSoFar += 1;
5223
5219
  startPing();
5224
5220
  if (opensSoFar === 1) {
@@ -5255,6 +5251,13 @@ var Service = class {
5255
5251
  ws = null;
5256
5252
  onClose?.();
5257
5253
  if (e.code === CLOSE_AUTH_REJECTED) {
5254
+ if (typeof token === "function" && authRejections < MAX_AUTH_RETRIES) {
5255
+ authRejections += 1;
5256
+ void Promise.resolve().then(() => onAuthRejected?.()).catch((err) => {
5257
+ console.warn("WebSocket onAuthRejected failed", err);
5258
+ }).finally(scheduleReconnect);
5259
+ return;
5260
+ }
5258
5261
  console.error("WebSocket auth rejected by server, not reconnecting");
5259
5262
  closedByCaller = true;
5260
5263
  return;
package/dist/index.js CHANGED
@@ -200,6 +200,22 @@ var ApiError = class _ApiError extends Error {
200
200
  function isApiError(error) {
201
201
  return error instanceof ApiError;
202
202
  }
203
+ var MENSAGEM_POR_ESTADO = {
204
+ 400: "Os dados enviados n\xE3o s\xE3o v\xE1lidos. Verifique-os e tente novamente.",
205
+ 401: "A sess\xE3o terminou. Inicie sess\xE3o novamente.",
206
+ 403: "N\xE3o tem permiss\xE3o para realizar esta opera\xE7\xE3o.",
207
+ 404: "O que pediu n\xE3o foi encontrado. Atualize a p\xE1gina e tente novamente.",
208
+ 409: "Esta opera\xE7\xE3o entra em conflito com dados j\xE1 existentes. Atualize a p\xE1gina e tente novamente.",
209
+ 413: "O pedido \xE9 demasiado grande. Reduza a quantidade de informa\xE7\xE3o ou o tamanho do ficheiro.",
210
+ 422: "Os dados enviados n\xE3o s\xE3o v\xE1lidos. Verifique-os e tente novamente.",
211
+ 429: "Foram feitos demasiados pedidos seguidos. Aguarde um momento e tente novamente.",
212
+ 502: "O servidor n\xE3o est\xE1 a responder neste momento. Tente novamente dentro de instantes.",
213
+ 503: "O servidor n\xE3o est\xE1 dispon\xEDvel neste momento. Tente novamente dentro de instantes.",
214
+ 504: "O servidor demorou demasiado a responder. Tente novamente dentro de instantes."
215
+ };
216
+ function messageForStatus(status) {
217
+ return MENSAGEM_POR_ESTADO[status] ?? (status >= 500 ? "O sistema teve um problema ao tratar o pedido. Tente novamente; se o problema continuar, contacte o suporte." : "N\xE3o foi poss\xEDvel concluir a opera\xE7\xE3o. Tente novamente.");
218
+ }
203
219
  function extractServerMessage(data, fallback) {
204
220
  if (typeof data === "string" && data.trim()) return data;
205
221
  if (isRecord(data)) {
@@ -221,21 +237,24 @@ function parseApiError(error) {
221
237
  const code = axiosError.code;
222
238
  if (axiosError.response) {
223
239
  const { status, data } = axiosError.response;
224
- const message = extractServerMessage(
225
- data,
226
- `Request failed with status ${status}`
227
- );
240
+ const message = extractServerMessage(data, messageForStatus(status));
228
241
  return new ApiError(
229
242
  { kind: "response", message, status, code, method, url, data },
230
243
  error
231
244
  );
232
245
  }
233
246
  if (axiosError.request) {
234
- const message = code === "ECONNABORTED" ? `Request timed out${url ? ` (${method} ${url})` : ""}` : `No response received${url ? ` from ${method} ${url}` : ""}`;
247
+ const message = code === "ECONNABORTED" ? "O servidor demorou demasiado a responder. Tente novamente dentro de instantes." : "N\xE3o foi poss\xEDvel comunicar com o servidor. Verifique a liga\xE7\xE3o \xE0 internet e tente novamente.";
235
248
  return new ApiError({ kind: "request", message, code, method, url }, error);
236
249
  }
237
250
  return new ApiError(
238
- { kind: "setup", message: axiosError.message, code, method, url },
251
+ {
252
+ kind: "setup",
253
+ message: "N\xE3o foi poss\xEDvel enviar o pedido. Atualize a p\xE1gina e tente novamente.",
254
+ code,
255
+ method,
256
+ url
257
+ },
239
258
  error
240
259
  );
241
260
  }
@@ -335,7 +354,8 @@ var Repository4 = class {
335
354
  prison,
336
355
  note,
337
356
  availableStock,
338
- token
357
+ token,
358
+ as
339
359
  }) {
340
360
  const qs = new URLSearchParams();
341
361
  qs.set("ef_name", ef_name);
@@ -348,7 +368,8 @@ var Repository4 = class {
348
368
  }
349
369
  qs.set("prison", prison.toString());
350
370
  qs.set("availableStock", availableStock.toString());
351
- qs.set("token", token);
371
+ if (token) qs.set("token", token);
372
+ if (as) qs.set("as", as);
352
373
  return `${this.route}print_label_pdf/${product_id}?${qs.toString()}`;
353
374
  }
354
375
  printBulkLabelToPdfUrl({
@@ -357,7 +378,8 @@ var Repository4 = class {
357
378
  notOk,
358
379
  clientOrders,
359
380
  saved_em_picking_ids,
360
- token
381
+ token,
382
+ as
361
383
  }) {
362
384
  const qs = new URLSearchParams();
363
385
  qs.set("groupLabel", groupLabel.toString());
@@ -365,7 +387,8 @@ var Repository4 = class {
365
387
  qs.set("notOk", notOk);
366
388
  qs.set("clientOrders", clientOrders);
367
389
  qs.set("saved_em_picking_ids", saved_em_picking_ids);
368
- qs.set("token", token);
390
+ if (token) qs.set("token", token);
391
+ if (as) qs.set("as", as);
369
392
  return `${this.route}print_bulk_label_pdf?${qs.toString()}`;
370
393
  }
371
394
  };
@@ -1232,13 +1255,6 @@ var Repository32 = class {
1232
1255
  this.api = api;
1233
1256
  this.route = route;
1234
1257
  }
1235
- async create(body) {
1236
- const response = await this.api.post(
1237
- `${this.route}`,
1238
- body
1239
- );
1240
- return response.data;
1241
- }
1242
1258
  async findByKey(params) {
1243
1259
  const response = await this.api.get(
1244
1260
  `${this.route}by_key`,
@@ -1426,6 +1442,10 @@ var Repository36 = class {
1426
1442
  );
1427
1443
  return response.data;
1428
1444
  }
1445
+ async findToday() {
1446
+ const response = await this.api.get(`${this.route}today`);
1447
+ return response.data;
1448
+ }
1429
1449
  async findByOwner(params) {
1430
1450
  const response = await this.api.get(
1431
1451
  `${this.route}by_owner`,
@@ -2093,7 +2113,7 @@ var Repository52 = class {
2093
2113
  }
2094
2114
  printLabelToPdfUrl({ id }, { token }) {
2095
2115
  const qs = new URLSearchParams();
2096
- qs.set("token", token);
2116
+ if (token) qs.set("token", token);
2097
2117
  return `${this.route}print_label_pdf/${id}?${qs.toString()}`;
2098
2118
  }
2099
2119
  printLabelToPdfBulk({
@@ -2101,7 +2121,7 @@ var Repository52 = class {
2101
2121
  token
2102
2122
  }) {
2103
2123
  const qs = new URLSearchParams();
2104
- qs.set("token", token);
2124
+ if (token) qs.set("token", token);
2105
2125
  qs.set("ids", ids);
2106
2126
  return `${this.route}print_label_pdf/bulk?${qs.toString()}`;
2107
2127
  }
@@ -2280,15 +2300,11 @@ var Repository57 = class {
2280
2300
  getQueryExecuteUrl({
2281
2301
  query_id,
2282
2302
  output,
2283
- token,
2284
2303
  ...data
2285
2304
  }) {
2286
2305
  const qs = new URLSearchParams();
2287
2306
  qs.set("query_id", query_id);
2288
2307
  qs.set("output", output);
2289
- if (token) {
2290
- qs.set("token", token);
2291
- }
2292
2308
  Object.entries(data).forEach(([key, value]) => {
2293
2309
  if (typeof value === "undefined") return;
2294
2310
  if (value === null) return;
@@ -2439,14 +2455,12 @@ var Repository63 = class {
2439
2455
  getStockCsvUrl({
2440
2456
  date,
2441
2457
  version,
2442
- format,
2443
- token
2458
+ format
2444
2459
  }) {
2445
2460
  const qs = new URLSearchParams();
2446
2461
  qs.set("date", date.toISOString());
2447
2462
  qs.set("version", version);
2448
2463
  qs.set("format", format);
2449
- qs.set("token", token);
2450
2464
  return `${this.route}csv?${qs.toString()}`;
2451
2465
  }
2452
2466
  };
@@ -2751,15 +2765,13 @@ var Repository70 = class {
2751
2765
  owner_id,
2752
2766
  start_date,
2753
2767
  end_date,
2754
- output,
2755
- token
2768
+ output
2756
2769
  }) {
2757
2770
  const qs = new URLSearchParams();
2758
2771
  qs.set("owner_id", owner_id);
2759
2772
  qs.set("output", output);
2760
2773
  if (start_date) qs.set("start_date", start_date.toISOString());
2761
2774
  if (end_date) qs.set("end_date", end_date.toISOString());
2762
- qs.set("token", token);
2763
2775
  return `${this.route}export?${qs.toString()}`;
2764
2776
  }
2765
2777
  };
@@ -2851,6 +2863,9 @@ var Repository71 = class {
2851
2863
  if (data?.token) {
2852
2864
  qs.set("token", data.token);
2853
2865
  }
2866
+ if (data?.as) {
2867
+ qs.set("as", data.as);
2868
+ }
2854
2869
  return `${this.route}document_pdf/${id}?${qs.toString()}`;
2855
2870
  }
2856
2871
  async documentThermalPrint({ id }, query) {
@@ -3006,12 +3021,12 @@ var Repository75 = class {
3006
3021
  }
3007
3022
  printLabelToPdfUrl({ document_line_ids }, { token }) {
3008
3023
  const qs = new URLSearchParams();
3009
- qs.set("token", token);
3024
+ if (token) qs.set("token", token);
3010
3025
  return `${this.route}print_label_pdf/${document_line_ids}?${qs.toString()}`;
3011
3026
  }
3012
3027
  printGroupLabelToPdfUrl({ document_line_ids }, { token }) {
3013
3028
  const qs = new URLSearchParams();
3014
- qs.set("token", token);
3029
+ if (token) qs.set("token", token);
3015
3030
  return `${this.route}print_group_label_pdf/${document_line_ids}?${qs.toString()}`;
3016
3031
  }
3017
3032
  };
@@ -3270,8 +3285,8 @@ var Repository84 = class {
3270
3285
  });
3271
3286
  return response.data;
3272
3287
  }
3273
- async findAllProviderProducts() {
3274
- const response = await this.api.get(`${this.route}all_provider_products`);
3288
+ async findAllProviderProducts(params) {
3289
+ const response = await this.api.get(`${this.route}all_provider_products`, { params });
3275
3290
  return response.data;
3276
3291
  }
3277
3292
  };
@@ -3350,7 +3365,7 @@ var Repository86 = class {
3350
3365
  year
3351
3366
  }) {
3352
3367
  const qs = new URLSearchParams();
3353
- qs.set("token", token);
3368
+ if (token) qs.set("token", token);
3354
3369
  if (ids) {
3355
3370
  qs.set("ids", ids);
3356
3371
  return `${this.route}create_batch_pdf?${qs.toString()}`;
@@ -3455,15 +3470,10 @@ var Repository89 = class {
3455
3470
  constructor({ route }) {
3456
3471
  this.route = route;
3457
3472
  }
3458
- getUrl({
3459
- date_start,
3460
- date_end,
3461
- token
3462
- }) {
3473
+ getUrl({ date_start, date_end }) {
3463
3474
  const qs = new URLSearchParams();
3464
3475
  qs.set("date_start", date_start);
3465
3476
  qs.set("date_end", date_end);
3466
- qs.set("token", token);
3467
3477
  return `${this.route}download?${qs.toString()}`;
3468
3478
  }
3469
3479
  };
@@ -3556,7 +3566,7 @@ var Repository92 = class {
3556
3566
  return response.data;
3557
3567
  }
3558
3568
  async update({ id }, body) {
3559
- await this.api.post(`${this.route}${id}`, body);
3569
+ await this.api.put(`${this.route}${id}`, body);
3560
3570
  }
3561
3571
  async deleteOne({
3562
3572
  id
@@ -3577,13 +3587,6 @@ var Repository93 = class {
3577
3587
  this.api = api;
3578
3588
  this.route = route;
3579
3589
  }
3580
- async create(body) {
3581
- const response = await this.api.post(
3582
- `${this.route}`,
3583
- body
3584
- );
3585
- return response.data;
3586
- }
3587
3590
  async find() {
3588
3591
  const response = await this.api.get(`${this.route}`);
3589
3592
  return response.data;
@@ -3606,12 +3609,7 @@ var Repository93 = class {
3606
3609
  return response.data;
3607
3610
  }
3608
3611
  async update({ id }, body) {
3609
- await this.api.post(`${this.route}${id}`, body);
3610
- }
3611
- async deleteOne({
3612
- id
3613
- }) {
3614
- await this.api.delete(`${this.route}${id}`);
3612
+ await this.api.put(`${this.route}${id}`, body);
3615
3613
  }
3616
3614
  };
3617
3615
 
@@ -3658,7 +3656,7 @@ var Repository94 = class {
3658
3656
  return response.data;
3659
3657
  }
3660
3658
  async update({ id }, body) {
3661
- await this.api.post(`${this.route}${id}`, body);
3659
+ await this.api.put(`${this.route}${id}`, body);
3662
3660
  }
3663
3661
  async deleteOne({
3664
3662
  id
@@ -4386,15 +4384,6 @@ var Repository114 = class {
4386
4384
  });
4387
4385
  return response.data;
4388
4386
  }
4389
- async findForBillOfLading(data) {
4390
- const response = await this.api.get(
4391
- `${this.route}`,
4392
- {
4393
- data
4394
- }
4395
- );
4396
- return response.data;
4397
- }
4398
4387
  async findByEmail(data) {
4399
4388
  const response = await this.api.get(`${this.route}by_email`, {
4400
4389
  data
@@ -5121,6 +5110,7 @@ var Repository132 = class {
5121
5110
  // src/modules/view/webSocket.ts
5122
5111
  var CLOSE_AUTH_REJECTED = 4401;
5123
5112
  var CLOSE_AUTH_UNAVAILABLE = 4503;
5113
+ var MAX_AUTH_RETRIES = 3;
5124
5114
  var PING_INTERVAL_MS = 25e3;
5125
5115
  var MAX_BACKOFF_MS = 3e4;
5126
5116
  var BASE_BACKOFF_MS = 1e3;
@@ -5134,6 +5124,7 @@ var Service = class {
5134
5124
  }
5135
5125
  openSocket({
5136
5126
  token,
5127
+ onAuthRejected,
5137
5128
  channel,
5138
5129
  onEvent,
5139
5130
  onOpen,
@@ -5143,11 +5134,15 @@ var Service = class {
5143
5134
  }) {
5144
5135
  let ws = null;
5145
5136
  let attempts = 0;
5137
+ let authRejections = 0;
5146
5138
  let opensSoFar = 0;
5147
5139
  let pingTimer = null;
5148
5140
  let reconnectTimer = null;
5149
5141
  let closedByCaller = false;
5150
- const subprotocols = channel ? [`bearer.${token}`, `channel.${channel}`] : [`bearer.${token}`];
5142
+ const subprotocols = () => {
5143
+ const current = typeof token === "function" ? token() : token;
5144
+ return channel ? [`bearer.${current}`, `channel.${channel}`] : [`bearer.${current}`];
5145
+ };
5151
5146
  const stopPing = () => {
5152
5147
  if (pingTimer !== null) {
5153
5148
  window.clearInterval(pingTimer);
@@ -5178,7 +5173,7 @@ var Service = class {
5178
5173
  const connect = () => {
5179
5174
  if (closedByCaller) return;
5180
5175
  try {
5181
- ws = new WebSocket(this.route, subprotocols);
5176
+ ws = new WebSocket(this.route, subprotocols());
5182
5177
  } catch (err) {
5183
5178
  console.error("WebSocket constructor threw", err);
5184
5179
  scheduleReconnect();
@@ -5186,6 +5181,7 @@ var Service = class {
5186
5181
  }
5187
5182
  ws.onopen = () => {
5188
5183
  attempts = 0;
5184
+ authRejections = 0;
5189
5185
  opensSoFar += 1;
5190
5186
  startPing();
5191
5187
  if (opensSoFar === 1) {
@@ -5222,6 +5218,13 @@ var Service = class {
5222
5218
  ws = null;
5223
5219
  onClose?.();
5224
5220
  if (e.code === CLOSE_AUTH_REJECTED) {
5221
+ if (typeof token === "function" && authRejections < MAX_AUTH_RETRIES) {
5222
+ authRejections += 1;
5223
+ void Promise.resolve().then(() => onAuthRejected?.()).catch((err) => {
5224
+ console.warn("WebSocket onAuthRejected failed", err);
5225
+ }).finally(scheduleReconnect);
5226
+ return;
5227
+ }
5225
5228
  console.error("WebSocket auth rejected by server, not reconnecting");
5226
5229
  closedByCaller = true;
5227
5230
  return;
@@ -9,6 +9,6 @@ export default class Repository implements Nomalism.MaterialEntrance.IApi {
9
9
  finalizarEntradaMaterial(data: Nomalism.MaterialEntrance.IFinalizarEntradaDeMaterialRequest): Promise<Nomalism.MaterialEntrance.IFinalizarEntradaDeMaterialResponse>;
10
10
  undoEntradaMaterial(data: Nomalism.MaterialEntrance.IUndoEntradaDeMaterialRequest): Promise<void>;
11
11
  findDoneById({ id, }: Nomalism.shared.IFindByIdRequest): Promise<Nomalism.MaterialEntrance.IFindDoneByIdResponse[]>;
12
- printLabelToPdfUrl({ product_id }: Nomalism.MaterialEntrance.IPrintLabelParamsRequest, { quantity, ef_name, pc_document_number, prison, note, availableStock, token, }: Nomalism.MaterialEntrance.IPrintLabelQueryWithTokenRequest): string;
13
- printBulkLabelToPdfUrl({ groupLabel, stockOrders, notOk, clientOrders, saved_em_picking_ids, token, }: Nomalism.MaterialEntrance.IPrintBulkLabelRequest): string;
12
+ printLabelToPdfUrl({ product_id }: Nomalism.MaterialEntrance.IPrintLabelParamsRequest, { quantity, ef_name, pc_document_number, prison, note, availableStock, token, as, }: Nomalism.MaterialEntrance.IPrintLabelQueryWithTokenRequest): string;
13
+ printBulkLabelToPdfUrl({ groupLabel, stockOrders, notOk, clientOrders, saved_em_picking_ids, token, as, }: Nomalism.MaterialEntrance.IPrintBulkLabelRequest): string;
14
14
  }
@@ -4,7 +4,6 @@ export default class Repository implements Nomalism.Settings.IRepository {
4
4
  route: string;
5
5
  private api;
6
6
  constructor({ api, route }: IModuleConstructor);
7
- create(body: Nomalism.Settings.ICreateRequest): Promise<Nomalism.Settings.Entity>;
8
7
  findByKey(params: Nomalism.Settings.IFindByKeyRequest): Promise<Nomalism.Settings.Entity | null>;
9
8
  update(body: Nomalism.Settings.IUpdateRequest): Promise<Nomalism.Settings.Entity | null>;
10
9
  find(): Promise<Nomalism.Settings.Entity[]>;
@@ -8,5 +8,6 @@ export default class Repository implements Nomalism.SchedulePrintJob.IRepository
8
8
  createMany(body: Nomalism.SchedulePrintJob.ICreateManySchedulePrintJobRequest): Promise<void>;
9
9
  deleteOne(selector: Nomalism.shared.IFindByIdRequest): Promise<void>;
10
10
  dispatchSchedulePrintJob(body: Nomalism.SchedulePrintJob.IDispatchSchedulePrintJobRequest): Promise<Nomalism.SchedulePrintJob.IDispatchSchedulePrintJobResponse>;
11
+ findToday(): Promise<Nomalism.SchedulePrintJob.IFindTodayItem[]>;
11
12
  findByOwner(params: Nomalism.shared.IFindByOwnerIdRequest): Promise<Nomalism.SchedulePrintJob.Entity[]>;
12
13
  }
@@ -6,5 +6,5 @@ export default class Repository implements Nomalism.QueryList.IRepository {
6
6
  constructor({ api, route }: IModuleConstructor);
7
7
  find(): Promise<Nomalism.QueryList.IFindResponse[]>;
8
8
  execute(params: Nomalism.QueryList.IExecuteRequest): Promise<Nomalism.QueryList.IExecuteResponse>;
9
- getQueryExecuteUrl({ query_id, output, token, ...data }: Nomalism.QueryList.IExecuteRequest): string;
9
+ getQueryExecuteUrl({ query_id, output, ...data }: Nomalism.QueryList.IExecuteRequest): string;
10
10
  }
@@ -8,5 +8,5 @@ export default class Repository implements Nomalism.StockMovement.IRepository {
8
8
  findByOwnerId(params: Nomalism.shared.IFindByOwnerIdRequest): Promise<Nomalism.StockMovement.IFindByOwnerIdResponse[]>;
9
9
  exportCsv(params: Nomalism.StockMovement.IExportRequest): Promise<Nomalism.StockMovement.IExportCsvResponse[]>;
10
10
  findMonthlyConsumption(params: Nomalism.shared.IFindByOwnerIdRequest): Promise<Nomalism.StockMovement.IFindMonthlyConsumptionResponse[]>;
11
- getStockCsvUrl({ date, version, format, token, }: Nomalism.StockMovement.IExportRequest): string;
11
+ getStockCsvUrl({ date, version, format, }: Nomalism.StockMovement.IExportRequest): string;
12
12
  }
@@ -12,5 +12,5 @@ export default class Repository implements Nomalism.CurrentAccount.IRepository {
12
12
  findClientUnpaidDebit(params: Nomalism.shared.IFindByOwnerIdRequest): Promise<Nomalism.CurrentAccount.IDocumentResponse[]>;
13
13
  findAccountAdjustment(params: Nomalism.CurrentAccount.IAccountAdjustmentRequest): Promise<Nomalism.CurrentAccount.IAccountAdjustmentPreview>;
14
14
  createAccountAdjustment(data: Nomalism.CurrentAccount.ICreateAccountAdjustmentRequest): Promise<Nomalism.CurrentAccount.ICreateAccountAdjustmentResponse>;
15
- getExportCurrentAccountUrl({ owner_id, start_date, end_date, output, token, }: Nomalism.CurrentAccount.IExportCurrentAccountRequest): string;
15
+ getExportCurrentAccountUrl({ owner_id, start_date, end_date, output, }: Nomalism.CurrentAccount.IExportCurrentAccountRequest): string;
16
16
  }
@@ -7,7 +7,7 @@ export default class Repository implements Nomalism.DocumentHeader.IRepository {
7
7
  findOne(selector: Nomalism.shared.IFindByIdRequest): Promise<Nomalism.DocumentHeader.IFindOneBase | null>;
8
8
  findStartVirtual(selector: Nomalism.shared.IFindByIdRequest): Promise<Nomalism.DocumentHeader.IStartDocumentHeaderVirtuals | null>;
9
9
  findByBasicSearch(params: Nomalism.DocumentHeader.IBasicSearchRequest): Promise<Nomalism.shared.IPaginationResponse<Nomalism.DocumentHeader.IBasicSearchResponse>>;
10
- findByType(params: Nomalism.DocumentHeader.IFindByTypeRequest): Promise<Nomalism.DocumentHeader.IFindByTypeResponse[]>;
10
+ findByType(params: Nomalism.DocumentHeader.IFindByTypeRequest): Promise<Nomalism.shared.IPaginationResponse<Nomalism.DocumentHeader.IFindByTypeResponse>>;
11
11
  find(params: Nomalism.DocumentHeader.IFindRequest): Promise<Nomalism.DocumentHeader.IFindResponse[]>;
12
12
  create(body: Nomalism.DocumentHeader.ICreateRequest): Promise<Nomalism.DocumentHeader.ICreateResponse>;
13
13
  createFromHeader(body: Nomalism.DocumentHeader.ICreateFromHeaderRequest): Promise<void>;
@@ -5,5 +5,5 @@ export default class Repository implements Nomalism.OrderManagement.IRepository
5
5
  private api;
6
6
  constructor({ api, route }: IModuleConstructor);
7
7
  findProviderProducts(params: Nomalism.OrderManagement.IFindProviderProductsRequest): Promise<Nomalism.OrderManagement.IFindProviderProductsResponse[]>;
8
- findAllProviderProducts(): Promise<Nomalism.OrderManagement.IFindAllProviderProductsResponse[]>;
8
+ findAllProviderProducts(params: Nomalism.OrderManagement.IFindAllProviderProductsRequest): Promise<Nomalism.OrderManagement.IFindAllProviderProductsResponse[]>;
9
9
  }
@@ -3,5 +3,5 @@ import { IModuleConstructor } from "../../main";
3
3
  export default class Repository {
4
4
  route: string;
5
5
  constructor({ route }: IModuleConstructor);
6
- getUrl({ date_start, date_end, token, }: Nomalism.Saft.ISaftInvoiceRequest): string;
6
+ getUrl({ date_start, date_end }: Nomalism.Saft.ISaftInvoiceRequest): string;
7
7
  }
@@ -4,10 +4,8 @@ export default class Repository implements Nomalism.CLT.IRepository {
4
4
  route: string;
5
5
  private api;
6
6
  constructor({ api, route }: IModuleConstructor);
7
- create(body: Nomalism.CLT.ICreateRequest): Promise<Nomalism.CLT.Entity>;
8
7
  find(): Promise<Nomalism.CLT.Entity[]>;
9
8
  findMinified(params?: Nomalism.CLT.IFindMinifiedRequest): Promise<Nomalism.CLT.Entity[]>;
10
9
  findById({ id, }: Nomalism.shared.IFindByIdNumberRequest): Promise<Nomalism.CLT.Entity | null>;
11
10
  update({ id }: Nomalism.shared.IFindByIdNumberRequest, body: Nomalism.CLT.IUpdateRequest): Promise<void>;
12
- deleteOne({ id, }: Nomalism.shared.IFindByIdNumberRequest): Promise<void>;
13
11
  }
@@ -10,7 +10,6 @@ export default class Repository implements Nomalism.Persona.IRepository {
10
10
  update(selector: Nomalism.shared.IFindByIdRequest, body: Nomalism.Persona.IUpdateRequest): Promise<Nomalism.Persona.IEntityExtended | null>;
11
11
  deleteOne(params: Nomalism.Persona.IDeletePersonaRequest): Promise<Nomalism.Persona.IEntityExtended | null>;
12
12
  findByBasic(params: Nomalism.Persona.IBasicSearchRequest): Promise<Nomalism.shared.IPaginationResponse<Nomalism.Persona.IBasicSearchResponse>>;
13
- findForBillOfLading(data: Nomalism.Persona.IFindRequest): Promise<Nomalism.Persona.IFindResponse[]>;
14
13
  findByEmail(data: Nomalism.Persona.IFindByEmailRequest): Promise<Nomalism.Persona.IFindByEmailResponse[]>;
15
14
  findClientOrProvider(params: Nomalism.Persona.IFindClientOrProviderRequest): Promise<Nomalism.Persona.IFindClientOrProviderResponse[]>;
16
15
  findForGmail(params: Nomalism.Persona.IFindForGmailRequest): Promise<Nomalism.Persona.IFindForGmailResponse | null>;
@@ -6,7 +6,7 @@ export default class Repository implements Nomalism.ReasonForExemption.IReposito
6
6
  constructor({ api, route }: IModuleConstructor);
7
7
  find(params: Nomalism.ReasonForExemption.IFindRequest): Promise<Nomalism.ReasonForExemption.IFindResponse[]>;
8
8
  findPaginated(params: Nomalism.ReasonForExemption.IFindPaginatedRequest): Promise<Nomalism.shared.IPaginationResponse<Nomalism.ReasonForExemption.IFindResponse>>;
9
- findMinified(params?: Nomalism.shared.IFindMinifiedRequest): Promise<Nomalism.shared.IFindMinifiedResponse[]>;
9
+ findMinified(params?: Nomalism.ReasonForExemption.IFindMinifiedRequest): Promise<Nomalism.shared.IFindMinifiedResponse[]>;
10
10
  create(body: Nomalism.ReasonForExemption.ICreateRequest): Promise<Nomalism.ReasonForExemption.Entity>;
11
11
  update(selector: Nomalism.shared.IFindByIdRequest, body: Nomalism.ReasonForExemption.IUpdateRequest): Promise<Nomalism.ReasonForExemption.Entity | null>;
12
12
  deleteOne(selector: Nomalism.shared.IFindByIdRequest): Promise<Nomalism.ReasonForExemption.Entity | null>;
@@ -3,5 +3,5 @@ import type { IModuleConstructor } from "../../main";
3
3
  export default class Service implements Nomalism.WebSocket.IClient {
4
4
  route: string;
5
5
  constructor({ route }: IModuleConstructor);
6
- openSocket<T extends Nomalism.WebSocket.IEvent>({ token, channel, onEvent, onOpen, onReconnect, onClose, onAuthUnverified, }: Nomalism.WebSocket.SocketOptions<T>): Nomalism.WebSocket.SocketHandle;
6
+ openSocket<T extends Nomalism.WebSocket.IEvent>({ token, onAuthRejected, channel, onEvent, onOpen, onReconnect, onClose, onAuthUnverified, }: Nomalism.WebSocket.SocketOptions<T>): Nomalism.WebSocket.SocketHandle;
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nomalism-com/api",
3
3
  "description": "A nomalism API package for performing HTTP requests on API endpoints",
4
- "version": "0.51.13",
4
+ "version": "0.51.15",
5
5
  "author": "Nomalism <it.nomalism@gmail.com> (https://https://nomalism.com/)",
6
6
  "license": "UNLICENSED",
7
7
  "type": "module",
@@ -30,13 +30,13 @@
30
30
  "prepare": "husky"
31
31
  },
32
32
  "dependencies": {
33
- "@nomalism-com/types": "^0.51.13",
33
+ "@nomalism-com/types": "^0.51.15",
34
34
  "axios": "^1.21.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@eslint/js": "^10.0.1",
38
38
  "@swc/core": "^1.16.20",
39
- "@types/node": "^26.6.5",
39
+ "@types/node": "^26.6.6",
40
40
  "@typescript-eslint/eslint-plugin": "^8.62.0",
41
41
  "@typescript-eslint/parser": "^8.62.0",
42
42
  "eslint": "^10.13.0",