@nomalism-com/api 0.51.12 → 0.51.14

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`,
@@ -2126,7 +2142,7 @@ var Repository52 = class {
2126
2142
  }
2127
2143
  printLabelToPdfUrl({ id }, { token }) {
2128
2144
  const qs = new URLSearchParams();
2129
- qs.set("token", token);
2145
+ if (token) qs.set("token", token);
2130
2146
  return `${this.route}print_label_pdf/${id}?${qs.toString()}`;
2131
2147
  }
2132
2148
  printLabelToPdfBulk({
@@ -2134,7 +2150,7 @@ var Repository52 = class {
2134
2150
  token
2135
2151
  }) {
2136
2152
  const qs = new URLSearchParams();
2137
- qs.set("token", token);
2153
+ if (token) qs.set("token", token);
2138
2154
  qs.set("ids", ids);
2139
2155
  return `${this.route}print_label_pdf/bulk?${qs.toString()}`;
2140
2156
  }
@@ -2313,15 +2329,11 @@ var Repository57 = class {
2313
2329
  getQueryExecuteUrl({
2314
2330
  query_id,
2315
2331
  output,
2316
- token,
2317
2332
  ...data
2318
2333
  }) {
2319
2334
  const qs = new URLSearchParams();
2320
2335
  qs.set("query_id", query_id);
2321
2336
  qs.set("output", output);
2322
- if (token) {
2323
- qs.set("token", token);
2324
- }
2325
2337
  Object.entries(data).forEach(([key, value]) => {
2326
2338
  if (typeof value === "undefined") return;
2327
2339
  if (value === null) return;
@@ -2472,14 +2484,12 @@ var Repository63 = class {
2472
2484
  getStockCsvUrl({
2473
2485
  date,
2474
2486
  version,
2475
- format,
2476
- token
2487
+ format
2477
2488
  }) {
2478
2489
  const qs = new URLSearchParams();
2479
2490
  qs.set("date", date.toISOString());
2480
2491
  qs.set("version", version);
2481
2492
  qs.set("format", format);
2482
- qs.set("token", token);
2483
2493
  return `${this.route}csv?${qs.toString()}`;
2484
2494
  }
2485
2495
  };
@@ -2784,15 +2794,13 @@ var Repository70 = class {
2784
2794
  owner_id,
2785
2795
  start_date,
2786
2796
  end_date,
2787
- output,
2788
- token
2797
+ output
2789
2798
  }) {
2790
2799
  const qs = new URLSearchParams();
2791
2800
  qs.set("owner_id", owner_id);
2792
2801
  qs.set("output", output);
2793
2802
  if (start_date) qs.set("start_date", start_date.toISOString());
2794
2803
  if (end_date) qs.set("end_date", end_date.toISOString());
2795
- qs.set("token", token);
2796
2804
  return `${this.route}export?${qs.toString()}`;
2797
2805
  }
2798
2806
  };
@@ -2884,6 +2892,9 @@ var Repository71 = class {
2884
2892
  if (data?.token) {
2885
2893
  qs.set("token", data.token);
2886
2894
  }
2895
+ if (data?.as) {
2896
+ qs.set("as", data.as);
2897
+ }
2887
2898
  return `${this.route}document_pdf/${id}?${qs.toString()}`;
2888
2899
  }
2889
2900
  async documentThermalPrint({ id }, query) {
@@ -3039,12 +3050,12 @@ var Repository75 = class {
3039
3050
  }
3040
3051
  printLabelToPdfUrl({ document_line_ids }, { token }) {
3041
3052
  const qs = new URLSearchParams();
3042
- qs.set("token", token);
3053
+ if (token) qs.set("token", token);
3043
3054
  return `${this.route}print_label_pdf/${document_line_ids}?${qs.toString()}`;
3044
3055
  }
3045
3056
  printGroupLabelToPdfUrl({ document_line_ids }, { token }) {
3046
3057
  const qs = new URLSearchParams();
3047
- qs.set("token", token);
3058
+ if (token) qs.set("token", token);
3048
3059
  return `${this.route}print_group_label_pdf/${document_line_ids}?${qs.toString()}`;
3049
3060
  }
3050
3061
  };
@@ -3303,8 +3314,8 @@ var Repository84 = class {
3303
3314
  });
3304
3315
  return response.data;
3305
3316
  }
3306
- async findAllProviderProducts() {
3307
- const response = await this.api.get(`${this.route}all_provider_products`);
3317
+ async findAllProviderProducts(params) {
3318
+ const response = await this.api.get(`${this.route}all_provider_products`, { params });
3308
3319
  return response.data;
3309
3320
  }
3310
3321
  };
@@ -3383,7 +3394,7 @@ var Repository86 = class {
3383
3394
  year
3384
3395
  }) {
3385
3396
  const qs = new URLSearchParams();
3386
- qs.set("token", token);
3397
+ if (token) qs.set("token", token);
3387
3398
  if (ids) {
3388
3399
  qs.set("ids", ids);
3389
3400
  return `${this.route}create_batch_pdf?${qs.toString()}`;
@@ -3488,15 +3499,10 @@ var Repository89 = class {
3488
3499
  constructor({ route }) {
3489
3500
  this.route = route;
3490
3501
  }
3491
- getUrl({
3492
- date_start,
3493
- date_end,
3494
- token
3495
- }) {
3502
+ getUrl({ date_start, date_end }) {
3496
3503
  const qs = new URLSearchParams();
3497
3504
  qs.set("date_start", date_start);
3498
3505
  qs.set("date_end", date_end);
3499
- qs.set("token", token);
3500
3506
  return `${this.route}download?${qs.toString()}`;
3501
3507
  }
3502
3508
  };
@@ -4419,15 +4425,6 @@ var Repository114 = class {
4419
4425
  });
4420
4426
  return response.data;
4421
4427
  }
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
4428
  async findByEmail(data) {
4432
4429
  const response = await this.api.get(`${this.route}by_email`, {
4433
4430
  data
@@ -4847,6 +4844,13 @@ var Repository124 = class {
4847
4844
  async updatePassword(selector, body) {
4848
4845
  await this.api.put(`${this.route}password/${selector.id}`, body);
4849
4846
  }
4847
+ async validatePin(body) {
4848
+ const response = await this.api.post(
4849
+ `${this.route}validate_pin`,
4850
+ body
4851
+ );
4852
+ return response.data;
4853
+ }
4850
4854
  async updateOwnPin(body) {
4851
4855
  await this.api.put(`${this.route}pin`, body);
4852
4856
  }
@@ -5147,6 +5151,7 @@ var Repository132 = class {
5147
5151
  // src/modules/view/webSocket.ts
5148
5152
  var CLOSE_AUTH_REJECTED = 4401;
5149
5153
  var CLOSE_AUTH_UNAVAILABLE = 4503;
5154
+ var MAX_AUTH_RETRIES = 3;
5150
5155
  var PING_INTERVAL_MS = 25e3;
5151
5156
  var MAX_BACKOFF_MS = 3e4;
5152
5157
  var BASE_BACKOFF_MS = 1e3;
@@ -5160,6 +5165,7 @@ var Service = class {
5160
5165
  }
5161
5166
  openSocket({
5162
5167
  token,
5168
+ onAuthRejected,
5163
5169
  channel,
5164
5170
  onEvent,
5165
5171
  onOpen,
@@ -5169,11 +5175,15 @@ var Service = class {
5169
5175
  }) {
5170
5176
  let ws = null;
5171
5177
  let attempts = 0;
5178
+ let authRejections = 0;
5172
5179
  let opensSoFar = 0;
5173
5180
  let pingTimer = null;
5174
5181
  let reconnectTimer = null;
5175
5182
  let closedByCaller = false;
5176
- const subprotocols = channel ? [`bearer.${token}`, `channel.${channel}`] : [`bearer.${token}`];
5183
+ const subprotocols = () => {
5184
+ const current = typeof token === "function" ? token() : token;
5185
+ return channel ? [`bearer.${current}`, `channel.${channel}`] : [`bearer.${current}`];
5186
+ };
5177
5187
  const stopPing = () => {
5178
5188
  if (pingTimer !== null) {
5179
5189
  window.clearInterval(pingTimer);
@@ -5204,7 +5214,7 @@ var Service = class {
5204
5214
  const connect = () => {
5205
5215
  if (closedByCaller) return;
5206
5216
  try {
5207
- ws = new WebSocket(this.route, subprotocols);
5217
+ ws = new WebSocket(this.route, subprotocols());
5208
5218
  } catch (err) {
5209
5219
  console.error("WebSocket constructor threw", err);
5210
5220
  scheduleReconnect();
@@ -5212,6 +5222,7 @@ var Service = class {
5212
5222
  }
5213
5223
  ws.onopen = () => {
5214
5224
  attempts = 0;
5225
+ authRejections = 0;
5215
5226
  opensSoFar += 1;
5216
5227
  startPing();
5217
5228
  if (opensSoFar === 1) {
@@ -5248,6 +5259,13 @@ var Service = class {
5248
5259
  ws = null;
5249
5260
  onClose?.();
5250
5261
  if (e.code === CLOSE_AUTH_REJECTED) {
5262
+ if (typeof token === "function" && authRejections < MAX_AUTH_RETRIES) {
5263
+ authRejections += 1;
5264
+ void Promise.resolve().then(() => onAuthRejected?.()).catch((err) => {
5265
+ console.warn("WebSocket onAuthRejected failed", err);
5266
+ }).finally(scheduleReconnect);
5267
+ return;
5268
+ }
5251
5269
  console.error("WebSocket auth rejected by server, not reconnecting");
5252
5270
  closedByCaller = true;
5253
5271
  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`,
@@ -2093,7 +2109,7 @@ var Repository52 = class {
2093
2109
  }
2094
2110
  printLabelToPdfUrl({ id }, { token }) {
2095
2111
  const qs = new URLSearchParams();
2096
- qs.set("token", token);
2112
+ if (token) qs.set("token", token);
2097
2113
  return `${this.route}print_label_pdf/${id}?${qs.toString()}`;
2098
2114
  }
2099
2115
  printLabelToPdfBulk({
@@ -2101,7 +2117,7 @@ var Repository52 = class {
2101
2117
  token
2102
2118
  }) {
2103
2119
  const qs = new URLSearchParams();
2104
- qs.set("token", token);
2120
+ if (token) qs.set("token", token);
2105
2121
  qs.set("ids", ids);
2106
2122
  return `${this.route}print_label_pdf/bulk?${qs.toString()}`;
2107
2123
  }
@@ -2280,15 +2296,11 @@ var Repository57 = class {
2280
2296
  getQueryExecuteUrl({
2281
2297
  query_id,
2282
2298
  output,
2283
- token,
2284
2299
  ...data
2285
2300
  }) {
2286
2301
  const qs = new URLSearchParams();
2287
2302
  qs.set("query_id", query_id);
2288
2303
  qs.set("output", output);
2289
- if (token) {
2290
- qs.set("token", token);
2291
- }
2292
2304
  Object.entries(data).forEach(([key, value]) => {
2293
2305
  if (typeof value === "undefined") return;
2294
2306
  if (value === null) return;
@@ -2439,14 +2451,12 @@ var Repository63 = class {
2439
2451
  getStockCsvUrl({
2440
2452
  date,
2441
2453
  version,
2442
- format,
2443
- token
2454
+ format
2444
2455
  }) {
2445
2456
  const qs = new URLSearchParams();
2446
2457
  qs.set("date", date.toISOString());
2447
2458
  qs.set("version", version);
2448
2459
  qs.set("format", format);
2449
- qs.set("token", token);
2450
2460
  return `${this.route}csv?${qs.toString()}`;
2451
2461
  }
2452
2462
  };
@@ -2751,15 +2761,13 @@ var Repository70 = class {
2751
2761
  owner_id,
2752
2762
  start_date,
2753
2763
  end_date,
2754
- output,
2755
- token
2764
+ output
2756
2765
  }) {
2757
2766
  const qs = new URLSearchParams();
2758
2767
  qs.set("owner_id", owner_id);
2759
2768
  qs.set("output", output);
2760
2769
  if (start_date) qs.set("start_date", start_date.toISOString());
2761
2770
  if (end_date) qs.set("end_date", end_date.toISOString());
2762
- qs.set("token", token);
2763
2771
  return `${this.route}export?${qs.toString()}`;
2764
2772
  }
2765
2773
  };
@@ -2851,6 +2859,9 @@ var Repository71 = class {
2851
2859
  if (data?.token) {
2852
2860
  qs.set("token", data.token);
2853
2861
  }
2862
+ if (data?.as) {
2863
+ qs.set("as", data.as);
2864
+ }
2854
2865
  return `${this.route}document_pdf/${id}?${qs.toString()}`;
2855
2866
  }
2856
2867
  async documentThermalPrint({ id }, query) {
@@ -3006,12 +3017,12 @@ var Repository75 = class {
3006
3017
  }
3007
3018
  printLabelToPdfUrl({ document_line_ids }, { token }) {
3008
3019
  const qs = new URLSearchParams();
3009
- qs.set("token", token);
3020
+ if (token) qs.set("token", token);
3010
3021
  return `${this.route}print_label_pdf/${document_line_ids}?${qs.toString()}`;
3011
3022
  }
3012
3023
  printGroupLabelToPdfUrl({ document_line_ids }, { token }) {
3013
3024
  const qs = new URLSearchParams();
3014
- qs.set("token", token);
3025
+ if (token) qs.set("token", token);
3015
3026
  return `${this.route}print_group_label_pdf/${document_line_ids}?${qs.toString()}`;
3016
3027
  }
3017
3028
  };
@@ -3270,8 +3281,8 @@ var Repository84 = class {
3270
3281
  });
3271
3282
  return response.data;
3272
3283
  }
3273
- async findAllProviderProducts() {
3274
- const response = await this.api.get(`${this.route}all_provider_products`);
3284
+ async findAllProviderProducts(params) {
3285
+ const response = await this.api.get(`${this.route}all_provider_products`, { params });
3275
3286
  return response.data;
3276
3287
  }
3277
3288
  };
@@ -3350,7 +3361,7 @@ var Repository86 = class {
3350
3361
  year
3351
3362
  }) {
3352
3363
  const qs = new URLSearchParams();
3353
- qs.set("token", token);
3364
+ if (token) qs.set("token", token);
3354
3365
  if (ids) {
3355
3366
  qs.set("ids", ids);
3356
3367
  return `${this.route}create_batch_pdf?${qs.toString()}`;
@@ -3455,15 +3466,10 @@ var Repository89 = class {
3455
3466
  constructor({ route }) {
3456
3467
  this.route = route;
3457
3468
  }
3458
- getUrl({
3459
- date_start,
3460
- date_end,
3461
- token
3462
- }) {
3469
+ getUrl({ date_start, date_end }) {
3463
3470
  const qs = new URLSearchParams();
3464
3471
  qs.set("date_start", date_start);
3465
3472
  qs.set("date_end", date_end);
3466
- qs.set("token", token);
3467
3473
  return `${this.route}download?${qs.toString()}`;
3468
3474
  }
3469
3475
  };
@@ -4386,15 +4392,6 @@ var Repository114 = class {
4386
4392
  });
4387
4393
  return response.data;
4388
4394
  }
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
4395
  async findByEmail(data) {
4399
4396
  const response = await this.api.get(`${this.route}by_email`, {
4400
4397
  data
@@ -4814,6 +4811,13 @@ var Repository124 = class {
4814
4811
  async updatePassword(selector, body) {
4815
4812
  await this.api.put(`${this.route}password/${selector.id}`, body);
4816
4813
  }
4814
+ async validatePin(body) {
4815
+ const response = await this.api.post(
4816
+ `${this.route}validate_pin`,
4817
+ body
4818
+ );
4819
+ return response.data;
4820
+ }
4817
4821
  async updateOwnPin(body) {
4818
4822
  await this.api.put(`${this.route}pin`, body);
4819
4823
  }
@@ -5114,6 +5118,7 @@ var Repository132 = class {
5114
5118
  // src/modules/view/webSocket.ts
5115
5119
  var CLOSE_AUTH_REJECTED = 4401;
5116
5120
  var CLOSE_AUTH_UNAVAILABLE = 4503;
5121
+ var MAX_AUTH_RETRIES = 3;
5117
5122
  var PING_INTERVAL_MS = 25e3;
5118
5123
  var MAX_BACKOFF_MS = 3e4;
5119
5124
  var BASE_BACKOFF_MS = 1e3;
@@ -5127,6 +5132,7 @@ var Service = class {
5127
5132
  }
5128
5133
  openSocket({
5129
5134
  token,
5135
+ onAuthRejected,
5130
5136
  channel,
5131
5137
  onEvent,
5132
5138
  onOpen,
@@ -5136,11 +5142,15 @@ var Service = class {
5136
5142
  }) {
5137
5143
  let ws = null;
5138
5144
  let attempts = 0;
5145
+ let authRejections = 0;
5139
5146
  let opensSoFar = 0;
5140
5147
  let pingTimer = null;
5141
5148
  let reconnectTimer = null;
5142
5149
  let closedByCaller = false;
5143
- const subprotocols = channel ? [`bearer.${token}`, `channel.${channel}`] : [`bearer.${token}`];
5150
+ const subprotocols = () => {
5151
+ const current = typeof token === "function" ? token() : token;
5152
+ return channel ? [`bearer.${current}`, `channel.${channel}`] : [`bearer.${current}`];
5153
+ };
5144
5154
  const stopPing = () => {
5145
5155
  if (pingTimer !== null) {
5146
5156
  window.clearInterval(pingTimer);
@@ -5171,7 +5181,7 @@ var Service = class {
5171
5181
  const connect = () => {
5172
5182
  if (closedByCaller) return;
5173
5183
  try {
5174
- ws = new WebSocket(this.route, subprotocols);
5184
+ ws = new WebSocket(this.route, subprotocols());
5175
5185
  } catch (err) {
5176
5186
  console.error("WebSocket constructor threw", err);
5177
5187
  scheduleReconnect();
@@ -5179,6 +5189,7 @@ var Service = class {
5179
5189
  }
5180
5190
  ws.onopen = () => {
5181
5191
  attempts = 0;
5192
+ authRejections = 0;
5182
5193
  opensSoFar += 1;
5183
5194
  startPing();
5184
5195
  if (opensSoFar === 1) {
@@ -5215,6 +5226,13 @@ var Service = class {
5215
5226
  ws = null;
5216
5227
  onClose?.();
5217
5228
  if (e.code === CLOSE_AUTH_REJECTED) {
5229
+ if (typeof token === "function" && authRejections < MAX_AUTH_RETRIES) {
5230
+ authRejections += 1;
5231
+ void Promise.resolve().then(() => onAuthRejected?.()).catch((err) => {
5232
+ console.warn("WebSocket onAuthRejected failed", err);
5233
+ }).finally(scheduleReconnect);
5234
+ return;
5235
+ }
5218
5236
  console.error("WebSocket auth rejected by server, not reconnecting");
5219
5237
  closedByCaller = true;
5220
5238
  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[]>;
@@ -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
  }
@@ -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>;
@@ -9,5 +9,6 @@ export default class Repository implements Nomalism.StoreOperator.IRepository {
9
9
  create(body: Nomalism.StoreOperator.ICreateRequest): Promise<string>;
10
10
  update(selector: Nomalism.shared.IFindByIdRequest, body: Nomalism.StoreOperator.IUpdateRequest): Promise<void>;
11
11
  updatePassword(selector: Nomalism.shared.IFindByIdRequest, body: Nomalism.StoreOperator.IUpdatePasswordRequest): Promise<void>;
12
+ validatePin(body: Nomalism.StoreOperator.IValidatePinRequest): Promise<Nomalism.StoreOperator.IFindResponse>;
12
13
  updateOwnPin(body: Nomalism.StoreOperator.IUpdateOwnPinRequest): Promise<void>;
13
14
  }
@@ -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.12",
4
+ "version": "0.51.14",
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.11",
33
+ "@nomalism-com/types": "^0.51.14",
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",