@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.
- package/dist/client/cms/locale.d.ts +3 -3
- package/dist/client/cms/locale.js +14 -2
- package/dist/client/observation/fhir-systems.d.ts +12 -0
- package/dist/client/observation/fhir-systems.js +13 -1
- package/dist/client/observation/observation-groups.d.ts +4 -3
- package/dist/client/observation/observation-groups.js +8 -4
- package/dist/client/observation/series.d.ts +23 -3
- package/dist/client/observation/series.js +22 -4
- package/dist/client/observation/services/ecg-observation-fragments.js +1 -0
- package/dist/client/observation/types/generate-observation-body/GenerateObservationBodyParams.d.ts +2 -0
- package/dist/client/offline/offline-measurement-queue.d.ts +3 -1
- package/dist/client/offline/offline-measurement-queue.js +2 -1
- package/dist/conformance/capability-requirements.js +1 -1
- package/dist/next/config/ovok-config.d.ts +18 -0
- package/dist/next/config/settings.js +10 -1
- package/dist/next/errors/ovok-errors.d.ts +7 -0
- package/dist/next/errors/ovok-errors.js +9 -1
- package/dist/next/http/transmit.js +4 -2
- package/dist/next/index.d.ts +15 -1
- package/dist/next/index.js +18 -1
- package/dist/next/logging/ovok-logger.d.ts +26 -0
- package/dist/next/logging/ovok-logger.js +10 -0
- package/dist/next/outbox/entry-observation.d.ts +3 -0
- package/dist/next/outbox/entry-observation.js +6 -0
- package/dist/next/outbox/failure-policy.d.ts +45 -0
- package/dist/next/outbox/failure-policy.js +92 -0
- package/dist/next/outbox/group-links.d.ts +19 -0
- package/dist/next/outbox/group-links.js +65 -0
- package/dist/next/outbox/indexed-db-outbox-store.d.ts +38 -0
- package/dist/next/outbox/indexed-db-outbox-store.js +90 -0
- package/dist/next/outbox/item-settler.d.ts +37 -0
- package/dist/next/outbox/item-settler.js +49 -0
- package/dist/next/outbox/legacy-queue-import.d.ts +7 -0
- package/dist/next/outbox/legacy-queue-import.js +50 -0
- package/dist/next/outbox/memory-outbox-store.d.ts +22 -0
- package/dist/next/outbox/memory-outbox-store.js +40 -0
- package/dist/next/outbox/outbox-items.d.ts +17 -0
- package/dist/next/outbox/outbox-items.js +89 -0
- package/dist/next/outbox/outbox-queries.d.ts +4 -0
- package/dist/next/outbox/outbox-queries.js +9 -0
- package/dist/next/outbox/outbox-resource.d.ts +73 -0
- package/dist/next/outbox/outbox-resource.js +170 -0
- package/dist/next/outbox/outbox-runner.d.ts +56 -0
- package/dist/next/outbox/outbox-runner.js +179 -0
- package/dist/next/outbox/outbox-snapshot.d.ts +3 -0
- package/dist/next/outbox/outbox-snapshot.js +40 -0
- package/dist/next/outbox/outbox-store.d.ts +21 -0
- package/dist/next/outbox/outbox-store.js +2 -0
- package/dist/next/outbox/outbox-triggers.d.ts +30 -0
- package/dist/next/outbox/outbox-triggers.js +38 -0
- package/dist/next/outbox/outbox-types.d.ts +138 -0
- package/dist/next/outbox/outbox-types.js +2 -0
- package/dist/next/outbox/outcome-handlers.d.ts +30 -0
- package/dist/next/outbox/outcome-handlers.js +50 -0
- package/dist/next/outbox/pending-saves.d.ts +6 -0
- package/dist/next/outbox/pending-saves.js +18 -0
- package/dist/next/outbox/request-budget.d.ts +10 -0
- package/dist/next/outbox/request-budget.js +22 -0
- package/dist/next/outbox/request-planner.d.ts +5 -0
- package/dist/next/outbox/request-planner.js +39 -0
- package/dist/next/outbox/runner-state.d.ts +34 -0
- package/dist/next/outbox/runner-state.js +61 -0
- package/dist/next/outbox/store-contract.d.ts +19 -0
- package/dist/next/outbox/store-contract.js +108 -0
- package/dist/next/outbox/wakeup.d.ts +11 -0
- package/dist/next/outbox/wakeup.js +34 -0
- package/dist/next/ovok.d.ts +3 -0
- package/dist/next/ovok.js +13 -2
- package/dist/next/react/index.d.ts +11 -1
- package/dist/next/react/index.js +15 -1
- package/dist/next/resources/measurements/measurement-sender.d.ts +27 -0
- package/dist/next/resources/measurements/measurement-sender.js +66 -0
- package/dist/next/resources/measurements/measurements-resource.d.ts +36 -25
- package/dist/next/resources/measurements/measurements-resource.js +62 -65
- package/dist/next/resources/measurements/observation-builder.js +6 -3
- package/dist/next/resources/measurements/offline-measurement-queue-types.d.ts +12 -14
- package/dist/next/resources/measurements/offline-measurement-queue.d.ts +4 -23
- package/dist/next/resources/measurements/offline-measurement-queue.js +18 -143
- package/package.json +1 -1
|
@@ -1,154 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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;
|