@ovok/core 0.4.49 → 0.4.51

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.
Files changed (79) hide show
  1. package/dist/client/cms/locale.d.ts +3 -3
  2. package/dist/client/cms/locale.js +14 -2
  3. package/dist/client/observation/fhir-systems.d.ts +12 -0
  4. package/dist/client/observation/fhir-systems.js +13 -1
  5. package/dist/client/observation/observation-groups.d.ts +4 -3
  6. package/dist/client/observation/observation-groups.js +8 -4
  7. package/dist/client/observation/series.d.ts +23 -3
  8. package/dist/client/observation/series.js +22 -4
  9. package/dist/client/observation/services/ecg-observation-fragments.js +1 -0
  10. package/dist/client/observation/types/generate-observation-body/GenerateObservationBodyParams.d.ts +2 -0
  11. package/dist/client/offline/offline-measurement-queue.d.ts +3 -1
  12. package/dist/client/offline/offline-measurement-queue.js +2 -1
  13. package/dist/conformance/capability-requirements.js +1 -1
  14. package/dist/next/config/ovok-config.d.ts +18 -0
  15. package/dist/next/config/settings.js +10 -1
  16. package/dist/next/errors/ovok-errors.d.ts +7 -0
  17. package/dist/next/errors/ovok-errors.js +9 -1
  18. package/dist/next/http/transmit.js +4 -2
  19. package/dist/next/index.d.ts +15 -1
  20. package/dist/next/index.js +18 -1
  21. package/dist/next/logging/ovok-logger.d.ts +26 -0
  22. package/dist/next/logging/ovok-logger.js +10 -0
  23. package/dist/next/outbox/entry-observation.d.ts +3 -0
  24. package/dist/next/outbox/entry-observation.js +6 -0
  25. package/dist/next/outbox/failure-policy.d.ts +45 -0
  26. package/dist/next/outbox/failure-policy.js +92 -0
  27. package/dist/next/outbox/group-links.d.ts +19 -0
  28. package/dist/next/outbox/group-links.js +65 -0
  29. package/dist/next/outbox/indexed-db-outbox-store.d.ts +38 -0
  30. package/dist/next/outbox/indexed-db-outbox-store.js +90 -0
  31. package/dist/next/outbox/item-settler.d.ts +37 -0
  32. package/dist/next/outbox/item-settler.js +49 -0
  33. package/dist/next/outbox/legacy-queue-import.d.ts +7 -0
  34. package/dist/next/outbox/legacy-queue-import.js +50 -0
  35. package/dist/next/outbox/memory-outbox-store.d.ts +22 -0
  36. package/dist/next/outbox/memory-outbox-store.js +40 -0
  37. package/dist/next/outbox/outbox-items.d.ts +17 -0
  38. package/dist/next/outbox/outbox-items.js +89 -0
  39. package/dist/next/outbox/outbox-queries.d.ts +4 -0
  40. package/dist/next/outbox/outbox-queries.js +9 -0
  41. package/dist/next/outbox/outbox-resource.d.ts +73 -0
  42. package/dist/next/outbox/outbox-resource.js +170 -0
  43. package/dist/next/outbox/outbox-runner.d.ts +56 -0
  44. package/dist/next/outbox/outbox-runner.js +179 -0
  45. package/dist/next/outbox/outbox-snapshot.d.ts +3 -0
  46. package/dist/next/outbox/outbox-snapshot.js +40 -0
  47. package/dist/next/outbox/outbox-store.d.ts +21 -0
  48. package/dist/next/outbox/outbox-store.js +2 -0
  49. package/dist/next/outbox/outbox-triggers.d.ts +30 -0
  50. package/dist/next/outbox/outbox-triggers.js +38 -0
  51. package/dist/next/outbox/outbox-types.d.ts +138 -0
  52. package/dist/next/outbox/outbox-types.js +2 -0
  53. package/dist/next/outbox/outcome-handlers.d.ts +30 -0
  54. package/dist/next/outbox/outcome-handlers.js +50 -0
  55. package/dist/next/outbox/pending-saves.d.ts +6 -0
  56. package/dist/next/outbox/pending-saves.js +18 -0
  57. package/dist/next/outbox/request-budget.d.ts +10 -0
  58. package/dist/next/outbox/request-budget.js +22 -0
  59. package/dist/next/outbox/request-planner.d.ts +5 -0
  60. package/dist/next/outbox/request-planner.js +39 -0
  61. package/dist/next/outbox/runner-state.d.ts +34 -0
  62. package/dist/next/outbox/runner-state.js +61 -0
  63. package/dist/next/outbox/store-contract.d.ts +19 -0
  64. package/dist/next/outbox/store-contract.js +108 -0
  65. package/dist/next/outbox/wakeup.d.ts +11 -0
  66. package/dist/next/outbox/wakeup.js +34 -0
  67. package/dist/next/ovok.d.ts +3 -0
  68. package/dist/next/ovok.js +13 -2
  69. package/dist/next/react/index.d.ts +11 -1
  70. package/dist/next/react/index.js +15 -1
  71. package/dist/next/resources/measurements/measurement-sender.d.ts +27 -0
  72. package/dist/next/resources/measurements/measurement-sender.js +66 -0
  73. package/dist/next/resources/measurements/measurements-resource.d.ts +36 -25
  74. package/dist/next/resources/measurements/measurements-resource.js +62 -65
  75. package/dist/next/resources/measurements/observation-builder.js +6 -3
  76. package/dist/next/resources/measurements/offline-measurement-queue-types.d.ts +12 -14
  77. package/dist/next/resources/measurements/offline-measurement-queue.d.ts +4 -23
  78. package/dist/next/resources/measurements/offline-measurement-queue.js +18 -143
  79. package/package.json +1 -1
@@ -1,154 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OfflineMeasurementQueue = exports.offlineMeasurementStorageKey = void 0;
4
- const ovok_errors_1 = require("../../errors/ovok-errors");
5
- const MAX_RETRIES = 8;
6
- const RETRY_BACKOFF_MS = 5000;
7
- const MAX_RETRY_BACKOFF_MS = 60 * 60 * 1000;
3
+ exports.offlineQueueFor = exports.offlineMeasurementStorageKey = void 0;
8
4
  const offlineMeasurementStorageKey = (tenantCode, baseUrl) => {
9
5
  const base = new URL(baseUrl);
10
6
  const path = base.pathname.replace(/\/+$/g, "");
11
7
  return `ovok:${tenantCode}:${base.origin}${path}:offline-measurements`;
12
8
  };
13
9
  exports.offlineMeasurementStorageKey = offlineMeasurementStorageKey;
14
- const queueItemId = (entries) => entries.map(({ fullUrl }) => fullUrl !== null && fullUrl !== void 0 ? fullUrl : "").join("|");
15
- const retryable = (error) => error instanceof ovok_errors_1.OvokConnectionError ||
16
- error instanceof ovok_errors_1.OvokRateLimitError ||
17
- error instanceof ovok_errors_1.OvokServiceError;
18
- const summarizeFailure = (error) => {
19
- const failure = error;
10
+ const flushOutbox = async (outbox, options, requestOptions) => {
11
+ if (options.includeExhausted || options.resetExhausted) {
12
+ await outbox.resend();
13
+ }
14
+ const report = await outbox.flushReport(requestOptions);
15
+ const items = await outbox.items();
20
16
  return {
21
- name: typeof (failure === null || failure === void 0 ? void 0 : failure.name) === "string" ? failure.name : "Error",
22
- ...(typeof (failure === null || failure === void 0 ? void 0 : failure.code) === "string" ? { code: failure.code } : {}),
23
- ...(typeof (failure === null || failure === void 0 ? void 0 : failure.status) === "number" ? { status: failure.status } : {}),
17
+ attempted: report.attempted,
18
+ saved: report.sent,
19
+ queued: items.filter(({ state }) => state === "pending").length,
20
+ exhausted: items.filter(({ state }) => state === "rejected").length,
21
+ responses: Object.fromEntries(report.responses),
22
+ failures: Object.fromEntries(items.flatMap(({ id, lastFailure }) => (lastFailure ? [[id, lastFailure]] : []))),
24
23
  };
25
24
  };
26
- class OfflineMeasurementQueue {
27
- constructor(storage, storageKey, getOwnerKey, transport) {
28
- this.storage = storage;
29
- this.storageKey = storageKey;
30
- this.getOwnerKey = getOwnerKey;
31
- this.transport = transport;
32
- this.operation = Promise.resolve();
33
- this.enqueueAndFlush = (entries, ownerKey, requestOptions) => this.runExclusive(async () => {
34
- const queue = await this.readQueue();
35
- const id = queueItemId(entries);
36
- const exists = queue.some((item) => item.id === id && item.ownerKey === ownerKey);
37
- if (!exists) {
38
- queue.push({
39
- id,
40
- ownerKey,
41
- queuedAt: new Date().toISOString(),
42
- attempt: 0,
43
- nextAttemptAt: 0,
44
- entries,
45
- });
46
- await this.writeQueue(queue);
47
- }
48
- return {
49
- id,
50
- flush: await this.flushQueue(queue, {}, requestOptions, true),
51
- };
52
- });
53
- this.flush = (options = {}, requestOptions) => this.runExclusive(async () => this.flushQueue(await this.readQueue(), options, requestOptions, false));
54
- this.runExclusive = (operation) => {
55
- const next = this.operation.then(operation, operation);
56
- this.operation = next.catch(() => undefined);
57
- return next;
58
- };
59
- this.readQueue = async () => {
60
- const serialized = await this.storage.getItem(this.storageKey);
61
- if (serialized === null || serialized === "") {
62
- return [];
63
- }
64
- const queue = JSON.parse(serialized);
65
- if (!Array.isArray(queue)) {
66
- throw new Error("Offline measurement queue is not an array.");
67
- }
68
- return queue;
69
- };
70
- this.writeQueue = async (queue) => {
71
- if (queue.length === 0) {
72
- await this.storage.removeItem(this.storageKey);
73
- return;
74
- }
75
- const serialized = JSON.stringify(queue);
76
- await this.storage.setItem(this.storageKey, serialized);
77
- if ((await this.storage.getItem(this.storageKey)) !== serialized) {
78
- throw new Error("Offline measurement queue could not be persisted.");
79
- }
80
- };
81
- this.flushQueue = async (queue, options, requestOptions, throwNonRetryable) => {
82
- const result = {
83
- attempted: 0,
84
- saved: 0,
85
- queued: 0,
86
- exhausted: 0,
87
- responses: {},
88
- failures: {},
89
- };
90
- let changed = false;
91
- const now = Date.now();
92
- for (const item of [...queue]) {
93
- const ownerKey = await this.getOwnerKey();
94
- if (!ownerKey || item.ownerKey !== ownerKey) {
95
- result.queued++;
96
- continue;
97
- }
98
- if (item.lastFailure) {
99
- result.failures[item.id] = item.lastFailure;
100
- }
101
- if (item.exhausted && options.resetExhausted) {
102
- item.attempt = 0;
103
- item.exhausted = false;
104
- item.nextAttemptAt = 0;
105
- changed = true;
106
- }
107
- if ((item.exhausted && !options.includeExhausted) || item.nextAttemptAt > now) {
108
- if (item.exhausted) {
109
- result.exhausted++;
110
- }
111
- else {
112
- result.queued++;
113
- }
114
- continue;
115
- }
116
- result.attempted++;
117
- try {
118
- const response = await this.transport({ resourceType: "Bundle", type: "transaction", entry: item.entries }, item.ownerKey, requestOptions);
119
- queue.splice(queue.indexOf(item), 1);
120
- result.saved++;
121
- result.responses[item.id] = response;
122
- delete result.failures[item.id];
123
- changed = true;
124
- }
125
- catch (error) {
126
- if (throwNonRetryable && !retryable(error)) {
127
- queue.splice(queue.indexOf(item), 1);
128
- await this.writeQueue(queue);
129
- throw error;
130
- }
131
- item.attempt++;
132
- item.exhausted = item.attempt >= MAX_RETRIES;
133
- item.nextAttemptAt = item.exhausted
134
- ? Number.MAX_SAFE_INTEGER
135
- : Date.now() + Math.min(MAX_RETRY_BACKOFF_MS, RETRY_BACKOFF_MS * 2 ** (item.attempt - 1));
136
- item.lastFailure = summarizeFailure(error);
137
- result.failures[item.id] = item.lastFailure;
138
- if (item.exhausted) {
139
- result.exhausted++;
140
- }
141
- else {
142
- result.queued++;
143
- }
144
- changed = true;
145
- }
146
- }
147
- if (changed) {
148
- await this.writeQueue(queue);
149
- }
150
- return result;
151
- };
152
- }
153
- }
154
- exports.OfflineMeasurementQueue = OfflineMeasurementQueue;
25
+ /** The old queue's `flush`, answered by the outbox. */
26
+ const offlineQueueFor = (outbox) => ({
27
+ flush: (options = {}, requestOptions) => flushOutbox(outbox, options, requestOptions),
28
+ });
29
+ exports.offlineQueueFor = offlineQueueFor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.49",
3
+ "version": "0.4.51",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",