@innspel/core 0.3.0 → 0.5.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.
package/README.md CHANGED
@@ -97,6 +97,9 @@ innspel.knownIssues.confirm(id) // «Ja, jeg også»
97
97
  innspel.subjects.submissions() // «Mine innspill», inkl. det som venter på nett
98
98
  innspel.subjects.status(submissionId) // status for én egen innsending
99
99
  innspel.programs.list() // invitasjoner, deltakelser, oppfølginger
100
+ innspel.programs.accept(invitationToken) // ja til invitasjonen — tokenet kom i DIN kanal
101
+ innspel.programs.decline(invitationToken) // nei. Ingen årsak spørres
102
+ innspel.programs.withdraw(participationId) // «Gå ut» — umiddelbart, alltid tillatt
100
103
  innspel.attachments.upload(submissionId, attachment) // skjermbilde til en innsending som alt er lagret
101
104
  innspel.queue.pending() // det som ligger i offline-køen
102
105
  innspel.queue.flush() // sendes ellers automatisk
package/dist/index.cjs CHANGED
@@ -811,6 +811,37 @@ var configGet = (options) => (options?.client ?? client).get({
811
811
  url: "/v1/ingest/config",
812
812
  ...options
813
813
  });
814
+ var programsRespond = (options) => (options.client ?? client).post({
815
+ security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
816
+ key: "FeedbackTokenAuth",
817
+ scheme: "bearer",
818
+ type: "http"
819
+ }],
820
+ url: "/v1/ingest/follow-ups/{id}/respond",
821
+ ...options,
822
+ headers: {
823
+ "Content-Type": "application/json",
824
+ ...options.headers
825
+ }
826
+ });
827
+ var programsAccept = (options) => (options.client ?? client).post({
828
+ security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
829
+ key: "FeedbackTokenAuth",
830
+ scheme: "bearer",
831
+ type: "http"
832
+ }],
833
+ url: "/v1/ingest/invitations/{token}/accept",
834
+ ...options
835
+ });
836
+ var programsDecline = (options) => (options.client ?? client).post({
837
+ security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
838
+ key: "FeedbackTokenAuth",
839
+ scheme: "bearer",
840
+ type: "http"
841
+ }],
842
+ url: "/v1/ingest/invitations/{token}/decline",
843
+ ...options
844
+ });
814
845
  var knownIssuesList2 = (options) => (options?.client ?? client).get({
815
846
  security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
816
847
  key: "FeedbackTokenAuth",
@@ -833,6 +864,15 @@ var knownIssuesConfirm = (options) => (options.client ?? client).post({
833
864
  ...options.headers
834
865
  }
835
866
  });
867
+ var programsWithdraw = (options) => (options.client ?? client).post({
868
+ security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
869
+ key: "FeedbackTokenAuth",
870
+ scheme: "bearer",
871
+ type: "http"
872
+ }],
873
+ url: "/v1/ingest/participations/{id}/withdraw",
874
+ ...options
875
+ });
836
876
  var programsListMine = (options) => (options?.client ?? client).get({
837
877
  security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
838
878
  key: "FeedbackTokenAuth",
@@ -873,6 +913,19 @@ var submissionsStatus = (options) => (options.client ?? client).get({
873
913
  url: "/v1/ingest/submissions/{id}/status",
874
914
  ...options
875
915
  });
916
+ var programsCompleteTask = (options) => (options.client ?? client).post({
917
+ security: [{ name: "X-Innspel-Tenant-Key", type: "apiKey" }, {
918
+ key: "FeedbackTokenAuth",
919
+ scheme: "bearer",
920
+ type: "http"
921
+ }],
922
+ url: "/v1/ingest/tasks/{id}/complete",
923
+ ...options,
924
+ headers: {
925
+ "Content-Type": "application/json",
926
+ ...options.headers
927
+ }
928
+ });
876
929
 
877
930
  // src/feil.ts
878
931
  var PREFIKS = "[innspel]";
@@ -1219,11 +1272,21 @@ async function lastOppTilLagring(fetchImpl, presign, body, signal) {
1219
1272
  }
1220
1273
 
1221
1274
  // src/versjon.ts
1222
- var VERSJON = "0.3.0";
1275
+ var VERSJON = "0.5.0";
1223
1276
 
1224
1277
  // src/klient.ts
1225
1278
  var STANDARD_TIMEOUT_MS = 1e4;
1226
1279
  var noopTelemetri = { emit: () => void 0 };
1280
+ var UTFALL = ["fungerte", "delvis", "ikke"];
1281
+ var SETNING_MAKS = 140;
1282
+ function validerUtfall(input) {
1283
+ if (!UTFALL.includes(input.outcome)) {
1284
+ throw new InnspelConfigError("outcome", `m\xE5 v\xE6re ett av ${UTFALL.join(" \xB7 ")}`);
1285
+ }
1286
+ if (input.text !== void 0 && (typeof input.text !== "string" || input.text.length > SETNING_MAKS)) {
1287
+ throw new InnspelConfigError("text", `er valgfri, men aldri lengre enn ${SETNING_MAKS} tegn`);
1288
+ }
1289
+ }
1227
1290
  function krev(betingelse, felt, hva) {
1228
1291
  if (!betingelse) throw new InnspelConfigError(felt, hva);
1229
1292
  }
@@ -1329,6 +1392,14 @@ function init(options) {
1329
1392
  if (!res.response.ok) throw tilApiFeil(res.response.status, res.error, res.response);
1330
1393
  return res.data;
1331
1394
  }
1395
+ function krevInvitasjonstoken(token) {
1396
+ if (typeof token !== "string" || token.length === 0) {
1397
+ throw new InnspelConfigError(
1398
+ "invitationToken",
1399
+ "mangler \u2014 det er engangs-tokenet leietakeren sendte i sin egen kanal (dyplenke, varsel eller e-post)"
1400
+ );
1401
+ }
1402
+ }
1332
1403
  function krevToken() {
1333
1404
  if (anonym) {
1334
1405
  throw new InnspelApiError(
@@ -1542,6 +1613,82 @@ function init(options) {
1542
1613
  return medToken(
1543
1614
  (h) => programsListMine({ client: klient, headers: h, signal: signal() })
1544
1615
  );
1616
+ },
1617
+ async accept(invitationToken) {
1618
+ krevInvitasjonstoken(invitationToken);
1619
+ krevToken();
1620
+ const svar = await medToken(
1621
+ (h) => programsAccept({
1622
+ client: klient,
1623
+ headers: h,
1624
+ signal: signal(),
1625
+ path: { token: invitationToken }
1626
+ })
1627
+ );
1628
+ telemetri.emit({ name: "invitation_accepted" });
1629
+ return svar;
1630
+ },
1631
+ async decline(invitationToken) {
1632
+ krevInvitasjonstoken(invitationToken);
1633
+ krevToken();
1634
+ await medToken(
1635
+ (h) => programsDecline({
1636
+ client: klient,
1637
+ headers: h,
1638
+ signal: signal(),
1639
+ path: { token: invitationToken }
1640
+ })
1641
+ );
1642
+ telemetri.emit({ name: "invitation_declined" });
1643
+ },
1644
+ async withdraw(participationId) {
1645
+ if (typeof participationId !== "string" || participationId.length === 0) {
1646
+ throw new InnspelConfigError("participationId", "mangler \u2014 bruk id fra deltakelsen i programs.list()");
1647
+ }
1648
+ krevToken();
1649
+ return medToken(
1650
+ (h) => programsWithdraw({
1651
+ client: klient,
1652
+ headers: h,
1653
+ signal: signal(),
1654
+ path: { id: participationId }
1655
+ })
1656
+ );
1657
+ },
1658
+ async completeTask(taskId, completion) {
1659
+ if (typeof taskId !== "string" || taskId.length === 0) {
1660
+ throw new InnspelConfigError("taskId", "mangler \u2014 bruk id fra program.tasks i programs.list()");
1661
+ }
1662
+ validerUtfall(completion);
1663
+ krevToken();
1664
+ const svar = await medToken(
1665
+ (h) => programsCompleteTask({
1666
+ client: klient,
1667
+ headers: h,
1668
+ signal: signal(),
1669
+ path: { id: taskId },
1670
+ body: completion
1671
+ })
1672
+ );
1673
+ telemetri.emit({ name: "task_completed", outcome: completion.outcome });
1674
+ return svar;
1675
+ },
1676
+ async respond(followUpId, response) {
1677
+ if (typeof followUpId !== "string" || followUpId.length === 0) {
1678
+ throw new InnspelConfigError("followUpId", "mangler \u2014 bruk id fra pendingFollowUps i programs.list()");
1679
+ }
1680
+ validerUtfall(response);
1681
+ krevToken();
1682
+ await medToken(
1683
+ (h) => programsRespond({
1684
+ client: klient,
1685
+ headers: h,
1686
+ signal: signal(),
1687
+ path: { id: followUpId },
1688
+ body: response
1689
+ })
1690
+ );
1691
+ telemetri.emit({ name: "followup_answered" });
1545
1692
  }
1546
1693
  },
1547
1694
  attachments: {