@innspel/core 0.6.0 → 0.6.1

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
@@ -954,6 +954,8 @@ var InnspelApiError = class extends Error {
954
954
  this.retryAfter = retryAfter;
955
955
  }
956
956
  };
957
+ var NettverksFeil = class extends Error {
958
+ };
957
959
  var InnspelQueueFullError = class extends Error {
958
960
  name = "InnspelQueueFullError";
959
961
  code = "queue_full";
@@ -1272,7 +1274,7 @@ async function lastOppTilLagring(fetchImpl, presign, body, signal) {
1272
1274
  }
1273
1275
 
1274
1276
  // src/versjon.ts
1275
- var VERSJON = "0.6.0";
1277
+ var VERSJON = "0.6.1";
1276
1278
 
1277
1279
  // src/klient.ts
1278
1280
  var STANDARD_TIMEOUT_MS = 1e4;
@@ -1365,12 +1367,10 @@ function init(options) {
1365
1367
  const telemetri = options.telemetry ?? noopTelemetri;
1366
1368
  const k\u00F8 = new Ko(options.storage);
1367
1369
  const anonym = options.identityProvider === null;
1368
- const klient = createClient(
1369
- createConfig({
1370
- baseUrl: options.baseUrl,
1371
- ...options.fetch ? { fetch: options.fetch } : {}
1372
- })
1373
- );
1370
+ const nett = ((input) => (options.fetch ?? fetch)(input).catch((e) => {
1371
+ throw new NettverksFeil(String(e));
1372
+ }));
1373
+ const klient = createClient(createConfig({ baseUrl: options.baseUrl, fetch: nett }));
1374
1374
  let presenter = null;
1375
1375
  async function headere() {
1376
1376
  const h = { "X-Innspel-Tenant-Key": options.tenantKey };
@@ -1378,15 +1378,29 @@ function init(options) {
1378
1378
  if (token) h["Authorization"] = `Bearer ${token}`;
1379
1379
  return h;
1380
1380
  }
1381
- function signal() {
1382
- return AbortSignal.timeout(options.timeoutMs ?? STANDARD_TIMEOUT_MS);
1381
+ async function medTidsgrense(kall) {
1382
+ const ms = options.timeoutMs ?? STANDARD_TIMEOUT_MS;
1383
+ if (typeof AbortSignal.timeout == "function") return kall(AbortSignal.timeout(ms));
1384
+ const kontroll = new AbortController();
1385
+ const timer = setTimeout(() => kontroll.abort(), ms);
1386
+ try {
1387
+ return await kall(kontroll.signal);
1388
+ } finally {
1389
+ clearTimeout(timer);
1390
+ }
1383
1391
  }
1384
1392
  async function medToken(kall) {
1385
- let res = await kall(await headere());
1393
+ const fors\u00F8k = async () => {
1394
+ const h = await headere();
1395
+ const r = await medTidsgrense((s) => kall(h, s));
1396
+ if (!r.response) throw r.error;
1397
+ return r;
1398
+ };
1399
+ let res = await fors\u00F8k();
1386
1400
  if (res.response.status === 401) {
1387
1401
  const feil = tilApiFeil(401, res.error, res.response);
1388
1402
  if (feil.code === "feedback_token_expired" && !anonym) {
1389
- res = await kall(await headere());
1403
+ res = await fors\u00F8k();
1390
1404
  }
1391
1405
  }
1392
1406
  if (!res.response.ok) throw tilApiFeil(res.response.status, res.error, res.response);
@@ -1425,20 +1439,20 @@ function init(options) {
1425
1439
  }
1426
1440
  }
1427
1441
  return medToken(
1428
- (h) => submissionsCreate({
1442
+ (h, s) => submissionsCreate({
1429
1443
  client: klient,
1430
1444
  headers: h,
1431
- signal: signal(),
1445
+ signal: s,
1432
1446
  body
1433
1447
  })
1434
1448
  );
1435
1449
  }
1436
1450
  async function lastOppVedlegg(submissionId, vedlegg) {
1437
1451
  const presign = await medToken(
1438
- (h) => attachmentsPresign({
1452
+ (h, s) => attachmentsPresign({
1439
1453
  client: klient,
1440
1454
  headers: h,
1441
- signal: signal(),
1455
+ signal: s,
1442
1456
  body: {
1443
1457
  submissionId,
1444
1458
  mime: vedlegg.mime,
@@ -1448,12 +1462,12 @@ function init(options) {
1448
1462
  }
1449
1463
  })
1450
1464
  );
1451
- await lastOppTilLagring(options.fetch ?? fetch, presign, vedlegg.body, signal());
1465
+ await medTidsgrense((s) => lastOppTilLagring(nett, presign, vedlegg.body, s));
1452
1466
  return medToken(
1453
- (h) => attachmentsComplete({
1467
+ (h, s) => attachmentsComplete({
1454
1468
  client: klient,
1455
1469
  headers: h,
1456
- signal: signal(),
1470
+ signal: s,
1457
1471
  path: { id: presign.attachmentId }
1458
1472
  })
1459
1473
  );
@@ -1471,7 +1485,7 @@ function init(options) {
1471
1485
  async loadSettings() {
1472
1486
  try {
1473
1487
  const cfg = await medToken(
1474
- (h) => configGet({ client: klient, headers: h, signal: signal() })
1488
+ (h, s) => configGet({ client: klient, headers: h, signal: s })
1475
1489
  );
1476
1490
  if (cfg?.textMaxLength === 140 || cfg?.textMaxLength === 280) settings.textMaxLength = cfg.textMaxLength;
1477
1491
  if (typeof cfg?.minTextLength === "number" && cfg.minTextLength >= 1) settings.minTextLength = cfg.minTextLength;
@@ -1507,6 +1521,7 @@ function init(options) {
1507
1521
  telemetri.emit({ name: "submission_failed", reason: e.code });
1508
1522
  throw e;
1509
1523
  }
1524
+ if (!(e instanceof NettverksFeil)) throw e;
1510
1525
  await k\u00F8.leggTil({
1511
1526
  clientRef,
1512
1527
  type: input.type,
@@ -1541,10 +1556,10 @@ function init(options) {
1541
1556
  async for(query = {}) {
1542
1557
  try {
1543
1558
  const kort = await medToken(
1544
- (h) => knownIssuesList2({
1559
+ (h, s) => knownIssuesList2({
1545
1560
  client: klient,
1546
1561
  headers: h,
1547
- signal: signal(),
1562
+ signal: s,
1548
1563
  query: {
1549
1564
  ...query.screen !== void 0 ? { screen: query.screen } : {},
1550
1565
  ...query.version !== void 0 ? { version: query.version } : {},
@@ -1561,10 +1576,10 @@ function init(options) {
1561
1576
  },
1562
1577
  async confirm(knownIssueId) {
1563
1578
  const res = await medToken(
1564
- (h) => knownIssuesConfirm({
1579
+ (h, s) => knownIssuesConfirm({
1565
1580
  client: klient,
1566
1581
  headers: h,
1567
- signal: signal(),
1582
+ signal: s,
1568
1583
  path: { id: knownIssueId },
1569
1584
  body: { context: kontekst }
1570
1585
  })
@@ -1586,10 +1601,10 @@ function init(options) {
1586
1601
  let sendte;
1587
1602
  try {
1588
1603
  sendte = await medToken(
1589
- (h) => submissionsListMine({ client: klient, headers: h, signal: signal() })
1604
+ (h, s) => submissionsListMine({ client: klient, headers: h, signal: s })
1590
1605
  );
1591
1606
  } catch (e) {
1592
- if (e instanceof InnspelApiError) throw e;
1607
+ if (!(e instanceof NettverksFeil)) throw e;
1593
1608
  return ventende;
1594
1609
  }
1595
1610
  telemetri.emit({ name: "status_viewed" });
@@ -1598,10 +1613,10 @@ function init(options) {
1598
1613
  async status(submissionId) {
1599
1614
  krevToken();
1600
1615
  return medToken(
1601
- (h) => submissionsStatus({
1616
+ (h, s) => submissionsStatus({
1602
1617
  client: klient,
1603
1618
  headers: h,
1604
- signal: signal(),
1619
+ signal: s,
1605
1620
  path: { id: submissionId }
1606
1621
  })
1607
1622
  );
@@ -1611,17 +1626,17 @@ function init(options) {
1611
1626
  async list() {
1612
1627
  krevToken();
1613
1628
  return medToken(
1614
- (h) => programsListMine({ client: klient, headers: h, signal: signal() })
1629
+ (h, s) => programsListMine({ client: klient, headers: h, signal: s })
1615
1630
  );
1616
1631
  },
1617
1632
  async accept(invitationToken) {
1618
1633
  krevInvitasjonstoken(invitationToken);
1619
1634
  krevToken();
1620
1635
  const svar = await medToken(
1621
- (h) => programsAccept({
1636
+ (h, s) => programsAccept({
1622
1637
  client: klient,
1623
1638
  headers: h,
1624
- signal: signal(),
1639
+ signal: s,
1625
1640
  path: { token: invitationToken }
1626
1641
  })
1627
1642
  );
@@ -1632,10 +1647,10 @@ function init(options) {
1632
1647
  krevInvitasjonstoken(invitationToken);
1633
1648
  krevToken();
1634
1649
  await medToken(
1635
- (h) => programsDecline({
1650
+ (h, s) => programsDecline({
1636
1651
  client: klient,
1637
1652
  headers: h,
1638
- signal: signal(),
1653
+ signal: s,
1639
1654
  path: { token: invitationToken }
1640
1655
  })
1641
1656
  );
@@ -1647,10 +1662,10 @@ function init(options) {
1647
1662
  }
1648
1663
  krevToken();
1649
1664
  return medToken(
1650
- (h) => programsWithdraw({
1665
+ (h, s) => programsWithdraw({
1651
1666
  client: klient,
1652
1667
  headers: h,
1653
- signal: signal(),
1668
+ signal: s,
1654
1669
  path: { id: participationId }
1655
1670
  })
1656
1671
  );
@@ -1662,10 +1677,10 @@ function init(options) {
1662
1677
  validerUtfall(completion);
1663
1678
  krevToken();
1664
1679
  const svar = await medToken(
1665
- (h) => programsCompleteTask({
1680
+ (h, s) => programsCompleteTask({
1666
1681
  client: klient,
1667
1682
  headers: h,
1668
- signal: signal(),
1683
+ signal: s,
1669
1684
  path: { id: taskId },
1670
1685
  body: completion
1671
1686
  })
@@ -1680,10 +1695,10 @@ function init(options) {
1680
1695
  validerUtfall(response);
1681
1696
  krevToken();
1682
1697
  await medToken(
1683
- (h) => programsRespond({
1698
+ (h, s) => programsRespond({
1684
1699
  client: klient,
1685
1700
  headers: h,
1686
- signal: signal(),
1701
+ signal: s,
1687
1702
  path: { id: followUpId },
1688
1703
  body: response
1689
1704
  })