@ovok/core 0.4.49-dev.501 → 0.4.49-dev.502

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
@@ -17,7 +17,7 @@ Core TypeScript SDK for healthcare applications. Provides authentication, AI-FHI
17
17
  - 🧭 Runtime discovery of the backend FHIR and public API capabilities
18
18
  - 🧩 Typed accounts, projects, localization, and patient-observation APIs
19
19
  - 🏥 Typed Slim patient, device, telemetry, notification, and monitoring APIs
20
- - 🚨 Typed Signals thresholds, alerts, and project settings APIs
20
+ - 🚨 Typed Signals enrollment and delivery-repair APIs
21
21
  - ⌚ Typed cloud wearable-provider configuration and patient connections
22
22
 
23
23
  ## Installation
@@ -220,95 +220,33 @@ const slots = await client.listPatientSlots({
220
220
 
221
221
  ## Signals APIs
222
222
 
223
- The Signals client methods and hooks cover enrolling an existing patient, resident thresholds, the
224
- project's alert feed, and Signals tenant settings. Ovok forwards observations for enabled residents
225
- to Signals on the backend; continue saving readings through the existing Observation APIs and do not
226
- submit the same readings to Signals separately.
223
+ The Signals client methods and hooks cover patient enrollment and delivery repair. Ovok forwards
224
+ eligible observations for enabled patients; continue saving readings through the existing
225
+ Observation APIs and do not submit the same readings to Signals separately.
227
226
 
228
227
  ```ts
229
- const thresholds = await client.getSignalsThresholds(patientId);
230
228
  const enrollment = await client.enableSignalsForPatient(patientId);
231
- const updated = await client.setSignalsThreshold(patientId, "8867-4", {
232
- low: 50,
233
- high: 120,
234
- reason: "Updated after review",
235
- });
236
- const alerts = await client.listSignalsAlerts({
237
- status: "OPEN",
238
- codes: ["8867-4"],
239
- limit: 25,
240
- });
241
- await client.acknowledgeSignalsAlert(alerts.items[0].id);
242
- const settings = await client.getSignalsSettings();
229
+ const undeliverable = await client.listUnconfirmedLimits();
230
+ const repair = await client.repushUnconfirmedLimits();
243
231
  ```
244
232
 
245
- Use `editable` and `source` from threshold rows to present the available controls, but let the
246
- backend enforce permissions. When lowering alert sensitivity or removing a bound, provide a
247
- non-empty `reason`; the backend decides whether the caller has the required capability. A
248
- `shared` settings tenant is read-only. Signal errors are exposed as `SignalsError` values and can
249
- be checked with `isSignalsError`.
233
+ `listUnconfirmedLimits` reads `/signals/config/undeliverable`; `repushUnconfirmedLimits` posts to
234
+ `/signals/config/undeliverable/repair`. The response reports attempted, repaired,
235
+ still-undeliverable, skipped, and not-reached counts. React applications can use
236
+ `useUnconfirmedLimits()` and `useRepushUnconfirmedLimits()` for these operations.
250
237
 
251
238
  Use `enableSignalsForPatient` to enroll an existing patient. It is idempotent, always returns
252
239
  `enabled: true` on success, and requires the caller to have `signals_config:update` and update
253
240
  access to that patient. A 409 conflict and 503 failures (including `signals_mint_failed`) are
254
241
  retryable; use a bounded retry with backoff and do not retry other statuses automatically. The
255
242
  SDK maps backend responses to `SignalsError`; read the `code`, `status`, `fieldErrors`, and
256
- `message` properties rather than trying to infer a code from a reason phrase. React applications
257
- can call `useEnableSignalsForPatient().mutate(patientId)`; the hook exposes the standard mutation
258
- `loading`, `error`, and `data` state.
259
-
260
- `useSignalsAlerts` accumulates pages through `loadMore`. Check `hasMore` rather than the current
261
- item count: access filtering can produce a short or empty page with another cursor. Query changes
262
- and `reload` start again at the first page. The hook exposes `reload` so a screen can refresh its
263
- alert list after `useAcknowledgeSignalsAlert` succeeds.
264
-
265
- ### Raw Signals alerts
266
-
267
- `listSignalsAlerts` reads episodes and needs the project's `episodicAlerts` (409
268
- `signals_episodes_disabled` otherwise). To work with individual alerts instead, whether or not
269
- `episodicAlerts` is on, use the raw alert methods:
270
-
271
- ```ts
272
- const open = await client.listSignalsRawAlerts({
273
- acknowledged: false,
274
- codes: ["8867-4", "9279-1"],
275
- since: "2026-10-01T00:00:00Z",
276
- limit: 50,
277
- });
278
- const alert = await client.getSignalsRawAlert(open.items[0].id);
279
- const acked = await client.acknowledgeSignalsRawAlert(alert.id);
280
- // acked.acknowledgedAt and acked.acknowledgedActor record when and by whom.
281
- ```
282
-
283
- The alert hooks take the same switch: `episodes` is optional and defaults to episodes, so existing
284
- calls are unchanged; `episodes: false` reads and acknowledges raw alerts, typed as `SignalsRawAlert`.
285
-
286
- ```tsx
287
- const worklist = useSignalsAlerts({ episodes: false, acknowledged: false, codes: ["8867-4"] });
288
- const one = useSignalsAlert(alertId, { episodes: false });
289
- const { mutate: acknowledge } = useAcknowledgeSignalsAlert({ episodes: false });
290
- ```
243
+ `message` properties. React applications can call
244
+ `useEnableSignalsForPatient().mutate(patientId)`.
291
245
 
292
- Each `SignalsRawAlert` carries Signals' own `id`, `createdAt` and `resolvedAt`. `status` is Signals'
293
- state of the reading: `ACTIVE` while it breaches, `RESOLVED` once it recovered or the alert was
294
- acknowledged. An alert stays open for the practitioner until it is acknowledged, so list the
295
- worklist with `acknowledged: false` rather than `status: "ACTIVE"`. Acknowledging resolves the
296
- alert, and the next breaching reading opens a new one. It is idempotent: an acknowledged alert keeps
297
- its first `acknowledgedAt` and `acknowledgedActor`.
298
-
299
- Filters: `status`, `acknowledged`, `patientId` (a FHIR Patient id), `codes` (LOINC codes), and
300
- `since` (inclusive) and `until` (exclusive) on `createdAt`, as date-times with `Z` or an offset.
301
- Pages hold at most 50 alerts. As with episodes, a page can be short or empty and still have a
302
- `nextCursor`, because alerts of residents the caller can't read are left out; page until
303
- `nextCursor` is null, and pass it back unchanged: it is sealed to the project.
304
-
305
- Alerts raised before a project starts acknowledging are unacknowledged too, so a new worklist
306
- should bound its history with `since`. Each row also carries the breaching reading (`valueNumber`
307
- or `valueString`), the rule's `message` and the alert's `reason`. Acknowledging a raw alert does not
308
- acknowledge an episode: with `episodicAlerts` on, keep a screen to one of the two. Every request is scoped to the
309
- caller's project and the residents their access policy allows: an alert outside that scope answers
310
- 404, and acknowledging needs `signals_alerts:update` and update access to the resident (403 when the
311
- caller can only read them).
246
+ Use `listNotificationNotes`, `createNotificationNote`, `updateNotificationNote`,
247
+ `patchNotificationNote`, and `deleteNotificationNote` for notification notes. The `alarm` target
248
+ represents an alert episode, and `alert` represents an individual raw alert. These methods use the
249
+ `/v1/slim/notifications` routes.
312
250
 
313
251
  ## Slim APIs
314
252
 
@@ -522,7 +460,7 @@ create a second copy of the same observation. The queue is opt-in and requires d
522
460
  Ovok-defined methods, including measurement saves, reject with `RateLimitError` when the server
523
461
  returns 429. A 429 or 503 with a retry delay is returned without an automatic retry; wait for
524
462
  `retryAfterMs` before trying again. Use `isRateLimitError(error)` and `retryAfterMs` to show a
525
- translated wait message without parsing backend text. Inherited Medplum FHIR methods keep their
463
+ translated wait message without parsing backend text. Inherited FHIR methods keep their
526
464
  `OperationOutcomeError`; use `readOvokError(error)` to read their status and delay.
527
465
 
528
466
  ## Session management
@@ -1,22 +1,15 @@
1
+ import type { NotificationNote, NotificationNotes, UpdateNotificationNote } from "../notifications/types";
1
2
  import type { MedplumRequestOptions } from "@medplum/core";
2
- import { NotificationNote, NotificationNotes, UpdateNotificationNote } from "../notifications/types";
3
3
  import { OvokClient } from "../ovok-client";
4
- import { EnableSignalsResponse, SetSignalsThresholdBody, SignalsAlert, SignalsAlertsPage, SignalsAlertsQuery, SignalsRawAlert, SignalsRawAlertsPage, SignalsRawAlertsQuery, SignalsSettingsPatch, SignalsSettingsResponse, SignalsThreshold, SignalsThresholds, UnconfirmedLimits, RepushUnconfirmedLimitsResult } from "./types";
4
+ import { EnableSignalsResponse, RepushUnconfirmedLimitsResult, UnconfirmedLimits } from "./types";
5
5
  /**
6
6
  * Enables Signals for an existing patient. The operation is idempotent; retry after 409 or 503.
7
7
  * Observations saved through Ovok are forwarded by the backend, so callers should not submit
8
8
  * the same readings to Signals separately.
9
9
  */
10
10
  export declare function enableSignalsForPatient(this: OvokClient, patientId: string, requestOptions?: MedplumRequestOptions): Promise<EnableSignalsResponse>;
11
- export declare function getSignalsThresholds(this: OvokClient, patientId: string, requestOptions?: MedplumRequestOptions): Promise<SignalsThresholds>;
12
11
  export declare function listUnconfirmedLimits(this: OvokClient, requestOptions?: MedplumRequestOptions): Promise<UnconfirmedLimits>;
13
12
  export declare function repushUnconfirmedLimits(this: OvokClient, requestOptions?: MedplumRequestOptions): Promise<RepushUnconfirmedLimitsResult>;
14
- export declare function setSignalsThreshold(this: OvokClient, patientId: string, code: string, body: SetSignalsThresholdBody, requestOptions?: MedplumRequestOptions): Promise<SignalsThreshold>;
15
- export declare function removeSignalsThreshold(this: OvokClient, patientId: string, code: string, reason: string, requestOptions?: MedplumRequestOptions): Promise<void>;
16
- export declare function serializeSignalsAlertsQuery(query?: SignalsAlertsQuery | SignalsRawAlertsQuery, keys?: readonly string[]): string;
17
- export declare function listSignalsAlerts(this: OvokClient, query?: SignalsAlertsQuery, requestOptions?: MedplumRequestOptions): Promise<SignalsAlertsPage>;
18
- export declare function getSignalsAlert(this: OvokClient, episodeId: string, requestOptions?: MedplumRequestOptions): Promise<SignalsAlert>;
19
- export declare function acknowledgeSignalsAlert(this: OvokClient, episodeId: string, requestOptions?: MedplumRequestOptions): Promise<SignalsAlert>;
20
13
  export declare function listSignalsAlertNotes(this: OvokClient, episodeId: string, requestOptions?: MedplumRequestOptions): Promise<NotificationNotes>;
21
14
  export declare function createSignalsAlertNote(this: OvokClient, episodeId: string, body: {
22
15
  text: string;
@@ -28,17 +21,3 @@ export declare function createSignalsRawAlertNote(this: OvokClient, alertId: str
28
21
  export declare function updateSignalsNote(this: OvokClient, noteId: string, body: UpdateNotificationNote, requestOptions?: MedplumRequestOptions): Promise<NotificationNote>;
29
22
  export declare function patchSignalsNote(this: OvokClient, noteId: string, body: UpdateNotificationNote, requestOptions?: MedplumRequestOptions): Promise<NotificationNote>;
30
23
  export declare function deleteSignalsNote(this: OvokClient, noteId: string, requestOptions?: MedplumRequestOptions): Promise<void>;
31
- /**
32
- * The project's individual Signals alerts, not episodes: works whether or not the project's
33
- * `episodicAlerts` is on. `acknowledged: false` lists what is still open for the practitioner.
34
- */
35
- export declare function listSignalsRawAlerts(this: OvokClient, query?: SignalsRawAlertsQuery, requestOptions?: MedplumRequestOptions): Promise<SignalsRawAlertsPage>;
36
- export declare function getSignalsRawAlert(this: OvokClient, alertId: string, requestOptions?: MedplumRequestOptions): Promise<SignalsRawAlert>;
37
- /**
38
- * Acknowledges one alert: it resolves, and `acknowledgedAt` and `acknowledgedActor` record when
39
- * and by whom. Idempotent: an acknowledged alert keeps its first acknowledgement. Needs
40
- * `signals_alerts:update` and update access to the resident.
41
- */
42
- export declare function acknowledgeSignalsRawAlert(this: OvokClient, alertId: string, requestOptions?: MedplumRequestOptions): Promise<SignalsRawAlert>;
43
- export declare function getSignalsSettings(this: OvokClient, requestOptions?: MedplumRequestOptions): Promise<SignalsSettingsResponse>;
44
- export declare function updateSignalsSettings(this: OvokClient, patch: SignalsSettingsPatch, reason?: string | null, requestOptions?: MedplumRequestOptions): Promise<SignalsSettingsResponse>;
@@ -1,15 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.enableSignalsForPatient = enableSignalsForPatient;
4
- exports.getSignalsThresholds = getSignalsThresholds;
5
4
  exports.listUnconfirmedLimits = listUnconfirmedLimits;
6
5
  exports.repushUnconfirmedLimits = repushUnconfirmedLimits;
7
- exports.setSignalsThreshold = setSignalsThreshold;
8
- exports.removeSignalsThreshold = removeSignalsThreshold;
9
- exports.serializeSignalsAlertsQuery = serializeSignalsAlertsQuery;
10
- exports.listSignalsAlerts = listSignalsAlerts;
11
- exports.getSignalsAlert = getSignalsAlert;
12
- exports.acknowledgeSignalsAlert = acknowledgeSignalsAlert;
13
6
  exports.listSignalsAlertNotes = listSignalsAlertNotes;
14
7
  exports.createSignalsAlertNote = createSignalsAlertNote;
15
8
  exports.listSignalsRawAlertNotes = listSignalsRawAlertNotes;
@@ -17,11 +10,6 @@ exports.createSignalsRawAlertNote = createSignalsRawAlertNote;
17
10
  exports.updateSignalsNote = updateSignalsNote;
18
11
  exports.patchSignalsNote = patchSignalsNote;
19
12
  exports.deleteSignalsNote = deleteSignalsNote;
20
- exports.listSignalsRawAlerts = listSignalsRawAlerts;
21
- exports.getSignalsRawAlert = getSignalsRawAlert;
22
- exports.acknowledgeSignalsRawAlert = acknowledgeSignalsRawAlert;
23
- exports.getSignalsSettings = getSignalsSettings;
24
- exports.updateSignalsSettings = updateSignalsSettings;
25
13
  const request_options_1 = require("../request-options");
26
14
  /**
27
15
  * Enables Signals for an existing patient. The operation is idempotent; retry after 409 or 503.
@@ -31,101 +19,30 @@ const request_options_1 = require("../request-options");
31
19
  function enableSignalsForPatient(patientId, requestOptions) {
32
20
  return this.post(`/fhir/Patient/${encodeURIComponent(patientId)}/$enable-signals`, undefined, undefined, requestOptions);
33
21
  }
34
- function getSignalsThresholds(patientId, requestOptions) {
35
- return this.get(`/v1/signals/patients/${encodeURIComponent(patientId)}/thresholds`, ...(0, request_options_1.optionalArg)(requestOptions));
36
- }
37
22
  function listUnconfirmedLimits(requestOptions) {
38
- return this.get("/signals/config/unconfirmed", ...(0, request_options_1.optionalArg)(requestOptions));
23
+ return this.get("/signals/config/undeliverable", ...(0, request_options_1.optionalArg)(requestOptions));
39
24
  }
40
25
  function repushUnconfirmedLimits(requestOptions) {
41
- return this.post("/signals/config/unconfirmed/repush", undefined, undefined, requestOptions);
42
- }
43
- function setSignalsThreshold(patientId, code, body, requestOptions) {
44
- return this.put(`/v1/signals/patients/${encodeURIComponent(patientId)}/thresholds/${encodeURIComponent(code)}`, body, undefined, requestOptions);
45
- }
46
- function removeSignalsThreshold(patientId, code, reason, requestOptions) {
47
- return this.delete(`/v1/signals/patients/${encodeURIComponent(patientId)}/thresholds/${encodeURIComponent(code)}?reason=${encodeURIComponent(reason)}`, ...(0, request_options_1.optionalArg)(requestOptions));
48
- }
49
- // Each route's own filters, in the order they are sent: a key outside the list is never sent, so
50
- // a wider object passed as an episode query can't turn into a refused request.
51
- const EPISODE_QUERY_KEYS = ["status", "since", "acknowledged", "codes", "limit", "cursor"];
52
- const RAW_ALERT_QUERY_KEYS = [
53
- "status",
54
- "patientId",
55
- "since",
56
- "until",
57
- "acknowledged",
58
- "codes",
59
- "limit",
60
- "cursor",
61
- ];
62
- function serializeSignalsAlertsQuery(query = {}, keys = EPISODE_QUERY_KEYS) {
63
- const values = query;
64
- return keys
65
- .filter((key) => values[key] !== undefined)
66
- .map((key) => {
67
- const value = values[key];
68
- const text = Array.isArray(value) ? value.join(",") : String(value);
69
- return `${encodeURIComponent(key)}=${encodeURIComponent(text)}`;
70
- })
71
- .join("&");
72
- }
73
- function listSignalsAlerts(query = {}, requestOptions) {
74
- const serialized = serializeSignalsAlertsQuery(query);
75
- return this.get(`/v1/signals/alerts${serialized ? `?${serialized}` : ""}`, { cache: "reload", ...requestOptions });
76
- }
77
- function getSignalsAlert(episodeId, requestOptions) {
78
- return this.get(`/v1/signals/alerts/${encodeURIComponent(episodeId)}`, { cache: "reload", ...requestOptions });
79
- }
80
- function acknowledgeSignalsAlert(episodeId, requestOptions) {
81
- return this.post(`/v1/signals/alerts/${encodeURIComponent(episodeId)}/ack`, undefined, undefined, requestOptions);
26
+ return this.post("/signals/config/undeliverable/repair", {}, undefined, requestOptions);
82
27
  }
83
28
  function listSignalsAlertNotes(episodeId, requestOptions) {
84
- return this.get(`/v1/signals/alerts/${encodeURIComponent(episodeId)}/notes`, { cache: "reload", ...requestOptions });
29
+ return this.listNotificationNotes("alarm", episodeId, requestOptions);
85
30
  }
86
31
  function createSignalsAlertNote(episodeId, body, requestOptions) {
87
- return this.post(`/v1/signals/alerts/${encodeURIComponent(episodeId)}/notes`, body, undefined, requestOptions);
32
+ return this.createNotificationNote({ kind: "alarm", id: episodeId, text: body.text }, requestOptions);
88
33
  }
89
34
  function listSignalsRawAlertNotes(alertId, requestOptions) {
90
- return this.get(`/v1/signals/raw-alerts/${encodeURIComponent(alertId)}/notes`, { cache: "reload", ...requestOptions });
35
+ return this.listNotificationNotes("alert", alertId, requestOptions);
91
36
  }
92
37
  function createSignalsRawAlertNote(alertId, body, requestOptions) {
93
- return this.post(`/v1/signals/raw-alerts/${encodeURIComponent(alertId)}/notes`, body, undefined, requestOptions);
38
+ return this.createNotificationNote({ kind: "alert", id: alertId, text: body.text }, requestOptions);
94
39
  }
95
40
  function updateSignalsNote(noteId, body, requestOptions) {
96
- return this.put(`/v1/signals/notes/${encodeURIComponent(noteId)}`, body, undefined, requestOptions);
41
+ return this.updateNotificationNote(noteId, body, requestOptions);
97
42
  }
98
43
  function patchSignalsNote(noteId, body, requestOptions) {
99
- return this.patch(`/v1/signals/notes/${encodeURIComponent(noteId)}`, body, ...(0, request_options_1.optionalArg)(requestOptions));
100
- }
101
- async function deleteSignalsNote(noteId, requestOptions) {
102
- await this.delete(`/v1/signals/notes/${encodeURIComponent(noteId)}`, ...(0, request_options_1.optionalArg)(requestOptions));
103
- }
104
- /**
105
- * The project's individual Signals alerts, not episodes: works whether or not the project's
106
- * `episodicAlerts` is on. `acknowledged: false` lists what is still open for the practitioner.
107
- */
108
- function listSignalsRawAlerts(query = {}, requestOptions) {
109
- const serialized = serializeSignalsAlertsQuery(query, RAW_ALERT_QUERY_KEYS);
110
- return this.get(`/v1/signals/raw-alerts${serialized ? `?${serialized}` : ""}`, { cache: "reload", ...requestOptions });
111
- }
112
- function getSignalsRawAlert(alertId, requestOptions) {
113
- return this.get(`/v1/signals/raw-alerts/${encodeURIComponent(alertId)}`, { cache: "reload", ...requestOptions });
114
- }
115
- /**
116
- * Acknowledges one alert: it resolves, and `acknowledgedAt` and `acknowledgedActor` record when
117
- * and by whom. Idempotent: an acknowledged alert keeps its first acknowledgement. Needs
118
- * `signals_alerts:update` and update access to the resident.
119
- */
120
- function acknowledgeSignalsRawAlert(alertId, requestOptions) {
121
- return this.post(`/v1/signals/raw-alerts/${encodeURIComponent(alertId)}/ack`, undefined, undefined, requestOptions);
122
- }
123
- function getSignalsSettings(requestOptions) {
124
- return this.get("/v1/signals/settings", ...(0, request_options_1.optionalArg)(requestOptions));
44
+ return this.patchNotificationNote(noteId, body, requestOptions);
125
45
  }
126
- function updateSignalsSettings(patch, reason, requestOptions) {
127
- return this.patch("/v1/signals/settings", {
128
- ...patch,
129
- ...(reason !== undefined ? { reason } : {}),
130
- }, ...(0, request_options_1.optionalArg)(requestOptions));
46
+ function deleteSignalsNote(noteId, requestOptions) {
47
+ return this.deleteNotificationNote(noteId, requestOptions);
131
48
  }
@@ -1,144 +1,18 @@
1
- import { ValidationError } from "../../types/ValidationError";
2
- export type SignalsThresholdSource = "organization" | "individual" | "auto" | "unknown";
3
- export type SignalsThreshold = {
4
- code: string;
5
- low: number | null;
6
- high: number | null;
7
- editable: boolean;
8
- version: number;
9
- updatedAt: string;
10
- source: SignalsThresholdSource;
11
- };
12
- export type SignalsThresholds = {
13
- patientId: string;
14
- thresholds: SignalsThreshold[];
15
- };
16
- export type SetSignalsThresholdBody = {
17
- low: number | null;
18
- high: number | null;
19
- reason?: string | null;
20
- };
21
- export type SignalsAlertStatus = "OPEN" | "CLOSED";
22
- export type SignalsAlert = {
23
- id: string;
24
- patientId: string;
25
- signalsPatientId: string;
26
- code: string;
27
- status: SignalsAlertStatus;
28
- noteCount: number | null;
29
- [key: string]: unknown;
30
- };
31
- export type SignalsAlertsQuery = {
32
- status?: SignalsAlertStatus;
33
- since?: string;
34
- acknowledged?: boolean;
35
- codes?: readonly string[];
36
- limit?: number;
37
- cursor?: string;
38
- };
39
- export type SignalsAlertsPage = {
40
- items: SignalsAlert[];
41
- nextCursor: string | null;
42
- };
43
- /** Signals' own state of a raw alert: ACTIVE while breaching, RESOLVED once recovered or acknowledged. */
44
- export type SignalsRawAlertStatus = "ACTIVE" | "RESOLVED";
45
- /** The person who acknowledged an alert. */
46
- export type SignalsAcknowledgedActor = {
47
- /** A FHIR reference, e.g. `Practitioner/<id>`. */
48
- reference: string;
49
- display: string | null;
50
- };
51
- /**
52
- * One individual Signals alert, not an episode: available whether or not the project's
53
- * `episodicAlerts` is on. `id`, `createdAt` and `resolvedAt` are Signals' own.
54
- *
55
- * An alert stays open for the practitioner until it is acknowledged: `acknowledgedAt` is null until
56
- * then, even when `status` is already RESOLVED because the reading recovered. Acknowledging
57
- * resolves it, and the next breaching reading opens a new alert.
58
- */
59
- export type SignalsRawAlert = {
60
- id: string;
61
- /** The resident's Medplum Patient id. */
62
- patientId: string;
63
- signalsPatientId: string;
64
- /** The LOINC code that breached; null when no reading's code raised it. */
65
- code: string | null;
66
- /**
67
- * TRIGGER is a threshold breach; EMPTY a reading with no value; NOTE a note; INACTIVE a resident
68
- * who stopped reporting.
69
- */
70
- reason: "TRIGGER" | "EMPTY" | "NOTE" | "INACTIVE";
71
- /** The latest breaching reading, as a number or as text. */
72
- valueNumber: number | null;
73
- valueString: string | null;
74
- /** The rule's own payload; it names the bound that was crossed. */
75
- message: string | null;
76
- observationId: string | null;
77
- triggerCode: string | null;
78
- triggerVersion: number | null;
79
- status: SignalsRawAlertStatus;
80
- createdAt: string;
81
- resolvedAt: string | null;
82
- acknowledgedAt: string | null;
83
- /** The Signals client that acknowledged it (Ovok's), not a person: use `acknowledgedActor`. */
84
- acknowledgedBy: string | null;
85
- acknowledgedActor: SignalsAcknowledgedActor | null;
86
- noteCount: number | null;
87
- [key: string]: unknown;
88
- };
89
- export type SignalsRawAlertsQuery = {
90
- status?: SignalsRawAlertStatus;
91
- /** `false` for the alerts still open for the practitioner, whatever their `status`. */
92
- acknowledged?: boolean;
93
- /**
94
- * One resident's alerts, by Medplum Patient id. 404 when the caller can't read the resident,
95
- * 409 `signals_patient_not_enrolled` when they aren't in Signals yet.
96
- */
97
- patientId?: string;
98
- /** LOINC codes, e.g. `["8867-4", "9279-1"]`. Omitted or empty, every alert. */
99
- codes?: readonly string[];
100
- /** Alerts created at or after this date-time, with `Z` or an offset. */
101
- since?: string;
102
- /** Alerts created before this date-time, with `Z` or an offset. */
103
- until?: string;
104
- /** 1 to 50; 50 when omitted. */
105
- limit?: number;
106
- /** The previous page's `nextCursor`, passed back unchanged. */
107
- cursor?: string;
108
- };
109
- /**
110
- * Newest first. A page can be shorter than `limit`, even empty, and still have a next one: alerts
111
- * of residents the caller can't read are left out. Page until `nextCursor` is null.
112
- */
113
- export type SignalsRawAlertsPage = {
114
- items: SignalsRawAlert[];
115
- nextCursor: string | null;
116
- };
117
- export type SignalsSettings = {
118
- episodicAlerts: boolean;
119
- synchronousMode: boolean;
120
- throttleLimit: number | null;
121
- };
122
- export type SignalsTenantKind = "project" | "shared";
1
+ import type { ValidationError } from "../../types/ValidationError";
123
2
  export type UnconfirmedLimitResident = {
124
3
  patientId: string;
125
- since: string | null;
126
- reason: string | null;
127
4
  };
128
5
  export type UnconfirmedLimits = {
129
6
  count: number;
130
7
  residents: UnconfirmedLimitResident[];
131
8
  };
132
9
  export type RepushUnconfirmedLimitsResult = {
133
- patients: number;
134
- unconfirmed: number;
135
- reason: string | null;
136
- };
137
- export type SignalsSettingsResponse = {
138
- tenant: SignalsTenantKind;
139
- settings: SignalsSettings;
10
+ attempted: number;
11
+ repaired: number;
12
+ stillUndeliverable: number;
13
+ skipped: number;
14
+ notReached: number;
140
15
  };
141
- export type SignalsSettingsPatch = Partial<SignalsSettings>;
142
16
  export type EnableSignalsResponse = {
143
17
  patientId: string;
144
18
  signalsPatientId: string;
@@ -155,15 +155,8 @@ exports.OVOK_CORE_API_REQUIREMENTS = {
155
155
  { method: "POST", path: "/v1/slim/notifications/medical/:episodeId/ack", group: "Slim/Notifications" },
156
156
  { method: "PATCH", path: "/v1/slim/notifications/:id/ack", group: "Slim/Notifications" },
157
157
  { method: "GET", path: "/v1/slim/change-history", group: "Slim/ChangeHistory" },
158
- { method: "GET", path: "/v1/signals/alerts/:episodeId/notes", group: "Signals/Notes" },
159
- { method: "POST", path: "/v1/signals/alerts/:episodeId/notes", group: "Signals/Notes" },
160
- { method: "GET", path: "/v1/signals/raw-alerts/:alertId/notes", group: "Signals/Notes" },
161
- { method: "POST", path: "/v1/signals/raw-alerts/:alertId/notes", group: "Signals/Notes" },
162
- { method: "PUT", path: "/v1/signals/notes/:noteId", group: "Signals/Notes" },
163
- { method: "PATCH", path: "/v1/signals/notes/:noteId", group: "Signals/Notes" },
164
- { method: "DELETE", path: "/v1/signals/notes/:noteId", group: "Signals/Notes" },
165
- { method: "GET", path: "/signals/config/unconfirmed", group: "Signals/Thresholds" },
166
- { method: "POST", path: "/signals/config/unconfirmed/repush", group: "Signals/Thresholds" },
158
+ { method: "GET", path: "/signals/config/undeliverable", group: "Signals/Delivery" },
159
+ { method: "POST", path: "/signals/config/undeliverable/repair", group: "Signals/Delivery" },
167
160
  { method: "GET", path: "/v1/slim/threshold", group: "Slim/Threshold" },
168
161
  { method: "PUT", path: "/v1/slim/threshold", group: "Slim/Threshold" },
169
162
  { method: "GET", path: "/v1/slim/threshold/patient/:patientId", group: "Slim/Threshold" },
@@ -48,7 +48,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
48
48
  description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
49
49
  software: {
50
50
  name: "@ovok/core",
51
- version: "0.4.49-dev.501+330a19b",
51
+ version: "0.4.49-dev.502+7d53087",
52
52
  },
53
53
  fhirVersion: "4.0.1",
54
54
  format: ["json"],
@@ -22,4 +22,4 @@ export { useAcceptCareInvite, useAcceptInvite, useAcceptRecordShare, useInvitePa
22
22
  export { useCurrentPatientProfile, useExtractQuestionnaireObservations, usePatientAppointments, usePatientCarePlans, usePatientDevices, usePatientMeasurement, usePatientMeasurementHistory, usePatientDashboard, usePatientLatestObservations, usePatientNotifications, usePatientQuestionnaireResponses, usePatientQuestionnaires, usePatientSchedules, usePatientSlots, usePopulateQuestionnaire, useSubmitQuestionnaireResponse, } from "./patient-hooks";
23
23
  export { useCreatePatientSharingInvite, usePatientSharing, usePatientSharingSettings, useRedeemPatientSharingInvite, useRevokePatientSharing, useUpdatePatientSharingSettings, } from "./patient-sharing-hooks";
24
24
  export { useAuthorizeWearableConnection, useCreateWearableProvider, useDeleteWearableConnection, useDeleteWearableProvider, useUpdateWearableProvider, useWearableConnections, useWearableProviders, } from "./wearables-hooks";
25
- export { useAcknowledgeSignalsAlert, useEnableSignalsForPatient, useRemoveSignalsThreshold, useSetSignalsThreshold, useSignalsAlert, useSignalsAlerts, useSignalsSettings, useSignalsThresholds, useUpdateSignalsSettings, } from "./signals-hooks";
25
+ export { useEnableSignalsForPatient, } from "./signals-hooks";
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.useSlimPatientThresholdV2 = exports.useSetMedicalConsent = exports.useSetLegalConsent = exports.useRepushUnconfirmedLimits = exports.useMedicalConsent = exports.useLegalConsent = exports.useChangeHistory = exports.useEmailTemplates = exports.useUpdateProjectTextSetting = exports.useUpdateLocalization = exports.useUpdateI18nextDocument = exports.useLocalizations = exports.useLocales = exports.useI18nextDocument = exports.useVideoCallAppointments = exports.useVideoCallAccess = exports.useDocuments = exports.useCreateVideoCallUserAccess = exports.useCreateVideoCallAppointment = exports.useContent = exports.useConsentSignature = exports.useOvokPoll = exports.usePublicApiEndpoints = exports.useProjectSettings = exports.useProjectFeatures = exports.useOvokRequest = exports.useOvokMutation = exports.useCapabilityStatement = exports.useSlimPatients = exports.useSlimDevices = exports.useSlimDeviceTelemetry = exports.useAdministeredProjects = exports.useUrineTests = exports.useSaveMeasurement = exports.useObservations = exports.useEcgRecording = exports.observationsToMeasurements = exports.OvokProvider = exports.useClient = exports.useCachedBinaryUrl = exports.reactContext = exports.useSubscription = exports.useSearchResources = exports.useSearchOne = exports.useSearch = exports.useResource = exports.usePrevious = exports.useMedplumProfile = exports.useMedplumNavigate = exports.useMedplumContext = void 0;
38
38
  exports.usePopulateQuestionnaire = exports.usePatientSlots = exports.usePatientSchedules = exports.usePatientQuestionnaires = exports.usePatientQuestionnaireResponses = exports.usePatientNotifications = exports.usePatientLatestObservations = exports.usePatientDashboard = exports.usePatientMeasurementHistory = exports.usePatientMeasurement = exports.usePatientDevices = exports.usePatientCarePlans = exports.usePatientAppointments = exports.useExtractQuestionnaireObservations = exports.useCurrentPatientProfile = exports.useShareRecord = exports.useInviteToCare = exports.useInvitePractitioner = exports.useInvitePatient = exports.useAcceptRecordShare = exports.useAcceptInvite = exports.useAcceptCareInvite = exports.useTranslations = exports.useReleaseNotes = exports.useLegalPage = exports.useCmsDocuments = exports.useCmsDocument = exports.useAcknowledgeSlimMedicalNotification = exports.useAcknowledgeSlimAlarm = exports.useUpdateSignalsNote = exports.useUpdateNotificationNote = exports.useSignalsRawAlertNotes = exports.useSignalsAlertNotes = exports.useNotificationNotes = exports.useDeleteSignalsNote = exports.useDeleteNotificationNote = exports.useCreateSignalsRawAlertNote = exports.useCreateSignalsAlertNote = exports.useCreateNotificationNote = exports.useSlimOutOfBedNotifications = exports.useSlimNotifications = exports.useSlimMedicalNotifications = exports.useSlimAlarms = exports.useRecentSlimNotifications = exports.useRecentOutOfBed = exports.useRecentAlarms = exports.useUpdateSlimThresholdV2 = exports.useUpdateSlimPatientThresholdV2 = exports.useUnconfirmedLimits = exports.useSlimThresholdV2 = void 0;
39
- exports.useUpdateSignalsSettings = exports.useSignalsThresholds = exports.useSignalsSettings = exports.useSignalsAlerts = exports.useSignalsAlert = exports.useSetSignalsThreshold = exports.useRemoveSignalsThreshold = exports.useEnableSignalsForPatient = exports.useAcknowledgeSignalsAlert = exports.useWearableProviders = exports.useWearableConnections = exports.useUpdateWearableProvider = exports.useDeleteWearableProvider = exports.useDeleteWearableConnection = exports.useCreateWearableProvider = exports.useAuthorizeWearableConnection = exports.useUpdatePatientSharingSettings = exports.useRevokePatientSharing = exports.useRedeemPatientSharingInvite = exports.usePatientSharingSettings = exports.usePatientSharing = exports.useCreatePatientSharingInvite = exports.useSubmitQuestionnaireResponse = void 0;
39
+ exports.useEnableSignalsForPatient = exports.useWearableProviders = exports.useWearableConnections = exports.useUpdateWearableProvider = exports.useDeleteWearableProvider = exports.useDeleteWearableConnection = exports.useCreateWearableProvider = exports.useAuthorizeWearableConnection = exports.useUpdatePatientSharingSettings = exports.useRevokePatientSharing = exports.useRedeemPatientSharingInvite = exports.usePatientSharingSettings = exports.usePatientSharing = exports.useCreatePatientSharingInvite = exports.useSubmitQuestionnaireResponse = void 0;
40
40
  /*
41
41
  * The only React-dependent module in the package.
42
42
  *
@@ -189,12 +189,4 @@ Object.defineProperty(exports, "useUpdateWearableProvider", { enumerable: true,
189
189
  Object.defineProperty(exports, "useWearableConnections", { enumerable: true, get: function () { return wearables_hooks_1.useWearableConnections; } });
190
190
  Object.defineProperty(exports, "useWearableProviders", { enumerable: true, get: function () { return wearables_hooks_1.useWearableProviders; } });
191
191
  var signals_hooks_1 = require("./signals-hooks");
192
- Object.defineProperty(exports, "useAcknowledgeSignalsAlert", { enumerable: true, get: function () { return signals_hooks_1.useAcknowledgeSignalsAlert; } });
193
192
  Object.defineProperty(exports, "useEnableSignalsForPatient", { enumerable: true, get: function () { return signals_hooks_1.useEnableSignalsForPatient; } });
194
- Object.defineProperty(exports, "useRemoveSignalsThreshold", { enumerable: true, get: function () { return signals_hooks_1.useRemoveSignalsThreshold; } });
195
- Object.defineProperty(exports, "useSetSignalsThreshold", { enumerable: true, get: function () { return signals_hooks_1.useSetSignalsThreshold; } });
196
- Object.defineProperty(exports, "useSignalsAlert", { enumerable: true, get: function () { return signals_hooks_1.useSignalsAlert; } });
197
- Object.defineProperty(exports, "useSignalsAlerts", { enumerable: true, get: function () { return signals_hooks_1.useSignalsAlerts; } });
198
- Object.defineProperty(exports, "useSignalsSettings", { enumerable: true, get: function () { return signals_hooks_1.useSignalsSettings; } });
199
- Object.defineProperty(exports, "useSignalsThresholds", { enumerable: true, get: function () { return signals_hooks_1.useSignalsThresholds; } });
200
- Object.defineProperty(exports, "useUpdateSignalsSettings", { enumerable: true, get: function () { return signals_hooks_1.useUpdateSignalsSettings; } });
@@ -1,18 +1,11 @@
1
1
  import { SlimMedicalNotificationRow } from "../client/notifications/types";
2
2
  import { OvokClient } from "../client/ovok-client";
3
- import { SignalsAlert, SignalsRawAlert } from "../client/signals/types";
4
3
  import { SlimNotification } from "../client/slim/types";
5
4
  export type NotificationChange = {
6
5
  type: "patient-sharing";
7
6
  } | {
8
7
  type: "slim";
9
8
  notification: SlimNotification | SlimMedicalNotificationRow;
10
- } | {
11
- type: "signals-alert";
12
- alert: SignalsAlert;
13
- } | {
14
- type: "signals-raw-alert";
15
- alert: SignalsRawAlert;
16
9
  };
17
10
  type NotificationChangeListener = (change?: NotificationChange) => void;
18
11
  export declare function subscribeToNotificationChanges(client: OvokClient, listener: NotificationChangeListener): () => void;
@@ -1,24 +1,3 @@
1
- import { EnableSignalsResponse, SetSignalsThresholdBody, SignalsSettingsPatch, SignalsSettingsResponse, SignalsThreshold, SignalsThresholds } from "../client/signals";
2
- import { OvokMutationState, OvokRequestState } from "./api-hooks";
3
- export { useAcknowledgeSignalsAlert, useSignalsAlert, useSignalsAlerts, } from "./signals-alert-hooks";
4
- export type { SignalsAlertGrain, SignalsAlertsHookState } from "./signals-alert-hooks";
5
- type SetSignalsThresholdParams = {
6
- patientId: string;
7
- code: string;
8
- body: SetSignalsThresholdBody;
9
- };
10
- type RemoveSignalsThresholdParams = {
11
- patientId: string;
12
- code: string;
13
- reason: string;
14
- };
15
- type UpdateSignalsSettingsParams = {
16
- patch: SignalsSettingsPatch;
17
- reason?: string | null;
18
- };
1
+ import type { EnableSignalsResponse } from "../client/signals";
2
+ import { OvokMutationState } from "./api-hooks";
19
3
  export declare const useEnableSignalsForPatient: () => OvokMutationState<string, EnableSignalsResponse>;
20
- export declare const useSignalsThresholds: (patientId?: string) => OvokRequestState<SignalsThresholds>;
21
- export declare const useSetSignalsThreshold: () => OvokMutationState<SetSignalsThresholdParams, SignalsThreshold>;
22
- export declare const useRemoveSignalsThreshold: () => OvokMutationState<RemoveSignalsThresholdParams, void>;
23
- export declare const useSignalsSettings: () => OvokRequestState<SignalsSettingsResponse>;
24
- export declare const useUpdateSignalsSettings: () => OvokMutationState<UpdateSignalsSettingsParams, SignalsSettingsResponse>;
@@ -1,21 +1,7 @@
1
1
  "use strict";
2
2
  "use client";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useUpdateSignalsSettings = exports.useSignalsSettings = exports.useRemoveSignalsThreshold = exports.useSetSignalsThreshold = exports.useSignalsThresholds = exports.useEnableSignalsForPatient = exports.useSignalsAlerts = exports.useSignalsAlert = exports.useAcknowledgeSignalsAlert = void 0;
4
+ exports.useEnableSignalsForPatient = void 0;
5
5
  const api_hooks_1 = require("./api-hooks");
6
- var signals_alert_hooks_1 = require("./signals-alert-hooks");
7
- Object.defineProperty(exports, "useAcknowledgeSignalsAlert", { enumerable: true, get: function () { return signals_alert_hooks_1.useAcknowledgeSignalsAlert; } });
8
- Object.defineProperty(exports, "useSignalsAlert", { enumerable: true, get: function () { return signals_alert_hooks_1.useSignalsAlert; } });
9
- Object.defineProperty(exports, "useSignalsAlerts", { enumerable: true, get: function () { return signals_alert_hooks_1.useSignalsAlerts; } });
10
6
  const useEnableSignalsForPatient = () => (0, api_hooks_1.useOvokMutation)((client, patientId) => client.enableSignalsForPatient(patientId));
11
7
  exports.useEnableSignalsForPatient = useEnableSignalsForPatient;
12
- const useSignalsThresholds = (patientId) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getSignalsThresholds(patientId, { signal }), patientId, patientId !== undefined);
13
- exports.useSignalsThresholds = useSignalsThresholds;
14
- const useSetSignalsThreshold = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.setSignalsThreshold(params.patientId, params.code, params.body));
15
- exports.useSetSignalsThreshold = useSetSignalsThreshold;
16
- const useRemoveSignalsThreshold = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.removeSignalsThreshold(params.patientId, params.code, params.reason));
17
- exports.useRemoveSignalsThreshold = useRemoveSignalsThreshold;
18
- const useSignalsSettings = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getSignalsSettings({ signal }));
19
- exports.useSignalsSettings = useSignalsSettings;
20
- const useUpdateSignalsSettings = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.updateSignalsSettings(params.patch, params.reason));
21
- exports.useUpdateSignalsSettings = useUpdateSignalsSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.49-dev.501+330a19b",
3
+ "version": "0.4.49-dev.502+7d53087",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,22 +0,0 @@
1
- import { SignalsAlert, SignalsAlertsQuery, SignalsRawAlert, SignalsRawAlertsQuery } from "../client/signals";
2
- export { useAcknowledgeSignalsAlert, useSignalsAlert } from "./signals-alert-item-hooks";
3
- export type { SignalsAlertGrain } from "./signals-alert-item-hooks";
4
- type SignalsAlertsHookQuery = Omit<SignalsAlertsQuery, "cursor"> & {
5
- episodes?: true;
6
- };
7
- type SignalsRawAlertsHookQuery = Omit<SignalsRawAlertsQuery, "cursor"> & {
8
- episodes: false;
9
- };
10
- export type SignalsAlertsHookState<TAlert = SignalsAlert> = {
11
- items: TAlert[];
12
- dataUpdatedAt: number | undefined;
13
- loading: boolean;
14
- isRefreshing: boolean;
15
- isStale: boolean;
16
- error: Error | undefined;
17
- reload: () => void;
18
- hasMore: boolean;
19
- loadMore: () => Promise<void>;
20
- };
21
- export declare function useSignalsAlerts(query: SignalsRawAlertsHookQuery): SignalsAlertsHookState<SignalsRawAlert>;
22
- export declare function useSignalsAlerts(query?: SignalsAlertsHookQuery): SignalsAlertsHookState<SignalsAlert>;
@@ -1,166 +0,0 @@
1
- "use strict";
2
- "use client";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.useSignalsAlert = exports.useAcknowledgeSignalsAlert = void 0;
38
- exports.useSignalsAlerts = useSignalsAlerts;
39
- const React = __importStar(require("react"));
40
- const ovok_error_utils_1 = require("../client/errors/ovok-error-utils");
41
- const notification_invalidation_1 = require("./notification-invalidation");
42
- const index_1 = require("./index");
43
- var signals_alert_item_hooks_1 = require("./signals-alert-item-hooks");
44
- Object.defineProperty(exports, "useAcknowledgeSignalsAlert", { enumerable: true, get: function () { return signals_alert_item_hooks_1.useAcknowledgeSignalsAlert; } });
45
- Object.defineProperty(exports, "useSignalsAlert", { enumerable: true, get: function () { return signals_alert_item_hooks_1.useSignalsAlert; } });
46
- function useSignalsAlerts(query = {}) {
47
- const client = (0, index_1.useClient)();
48
- const queryKey = JSON.stringify(query);
49
- const querySnapshot = React.useMemo(() => JSON.parse(queryKey), [queryKey]);
50
- const listPage = React.useCallback((cursor, signal) => {
51
- const at = cursor === undefined ? {} : { cursor };
52
- if (querySnapshot.episodes === false) {
53
- const { episodes: _grain, ...filters } = querySnapshot;
54
- return client.listSignalsRawAlerts({ ...filters, ...at }, { signal });
55
- }
56
- const { episodes: _grain, ...filters } = querySnapshot;
57
- return client.listSignalsAlerts({ ...filters, ...at }, { signal });
58
- }, [client, querySnapshot]);
59
- const [items, setItems] = React.useState([]);
60
- const [nextCursor, setNextCursor] = React.useState(null);
61
- const [loading, setLoading] = React.useState(true);
62
- const [error, setError] = React.useState();
63
- const [dataUpdatedAt, setDataUpdatedAt] = React.useState();
64
- const [revision, setRevision] = React.useState(0);
65
- const generation = React.useRef(0);
66
- const loadMoreController = React.useRef();
67
- const loadingRef = React.useRef(false);
68
- const previousQueryKey = React.useRef(queryKey);
69
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
70
- if (!change) {
71
- setRevision((value) => value + 1);
72
- }
73
- else if (change.type === (querySnapshot.episodes === false ? "signals-raw-alert" : "signals-alert")) {
74
- setItems((current) => current.map((item) => item.id === change.alert.id ? { ...item, ...change.alert } : item));
75
- }
76
- }), [client, querySnapshot.episodes]);
77
- React.useEffect(() => {
78
- const requestGeneration = generation.current + 1;
79
- const controller = new AbortController();
80
- const queryChanged = previousQueryKey.current !== queryKey;
81
- generation.current = requestGeneration;
82
- previousQueryKey.current = queryKey;
83
- loadingRef.current = true;
84
- if (queryChanged) {
85
- setItems([]);
86
- setNextCursor(null);
87
- setDataUpdatedAt(undefined);
88
- }
89
- setError(undefined);
90
- setLoading(true);
91
- listPage(undefined, controller.signal)
92
- .then((page) => {
93
- if (generation.current === requestGeneration) {
94
- setItems(page.items);
95
- setNextCursor(page.nextCursor);
96
- setDataUpdatedAt(Date.now());
97
- }
98
- })
99
- .catch((reason) => {
100
- if (generation.current === requestGeneration) {
101
- setError((0, ovok_error_utils_1.toError)(reason));
102
- }
103
- })
104
- .finally(() => {
105
- if (generation.current === requestGeneration) {
106
- loadingRef.current = false;
107
- setLoading(false);
108
- }
109
- });
110
- return () => {
111
- var _a;
112
- controller.abort();
113
- (_a = loadMoreController.current) === null || _a === void 0 ? void 0 : _a.abort();
114
- generation.current += 1;
115
- };
116
- }, [listPage, queryKey, revision]);
117
- const loadMore = React.useCallback(async () => {
118
- var _a;
119
- if (nextCursor === null || loadingRef.current) {
120
- return;
121
- }
122
- const requestGeneration = generation.current;
123
- const controller = new AbortController();
124
- (_a = loadMoreController.current) === null || _a === void 0 ? void 0 : _a.abort();
125
- loadMoreController.current = controller;
126
- loadingRef.current = true;
127
- setLoading(true);
128
- setError(undefined);
129
- try {
130
- const page = await listPage(nextCursor, controller.signal);
131
- if (generation.current === requestGeneration) {
132
- setItems((current) => [...current, ...page.items]);
133
- setNextCursor(page.nextCursor);
134
- setDataUpdatedAt(Date.now());
135
- }
136
- }
137
- catch (reason) {
138
- if (generation.current === requestGeneration) {
139
- setError((0, ovok_error_utils_1.toError)(reason));
140
- }
141
- }
142
- finally {
143
- if (generation.current === requestGeneration) {
144
- loadingRef.current = false;
145
- setLoading(false);
146
- }
147
- if (loadMoreController.current === controller) {
148
- loadMoreController.current = undefined;
149
- }
150
- }
151
- }, [listPage, nextCursor]);
152
- const reload = React.useCallback(() => {
153
- setRevision((current) => current + 1);
154
- }, []);
155
- return {
156
- items,
157
- dataUpdatedAt,
158
- loading,
159
- isRefreshing: items.length > 0 && loading,
160
- isStale: items.length > 0 && (loading || error !== undefined),
161
- error,
162
- reload,
163
- hasMore: nextCursor !== null,
164
- loadMore,
165
- };
166
- }
@@ -1,19 +0,0 @@
1
- import { SignalsAlert, SignalsRawAlert } from "../client/signals";
2
- import { OvokMutationState, OvokRequestState } from "./api-hooks";
3
- export type SignalsAlertGrain = {
4
- episodes?: boolean;
5
- };
6
- /** One episode by id, or one raw alert with `{ episodes: false }`. */
7
- export declare function useSignalsAlert(id: string | undefined, grain: {
8
- episodes: false;
9
- }): OvokRequestState<SignalsRawAlert>;
10
- export declare function useSignalsAlert(id?: string, grain?: {
11
- episodes?: true;
12
- }): OvokRequestState<SignalsAlert>;
13
- /** Acknowledges an episode, or a raw alert with `{ episodes: false }`. */
14
- export declare function useAcknowledgeSignalsAlert(grain: {
15
- episodes: false;
16
- }): OvokMutationState<string, SignalsRawAlert>;
17
- export declare function useAcknowledgeSignalsAlert(grain?: {
18
- episodes?: true;
19
- }): OvokMutationState<string, SignalsAlert>;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- "use client";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.useSignalsAlert = useSignalsAlert;
38
- exports.useAcknowledgeSignalsAlert = useAcknowledgeSignalsAlert;
39
- const React = __importStar(require("react"));
40
- const api_hooks_1 = require("./api-hooks");
41
- const notification_invalidation_1 = require("./notification-invalidation");
42
- const index_1 = require("./index");
43
- function useSignalsAlert(id, grain = {}) {
44
- const client = (0, index_1.useClient)();
45
- const episodes = grain.episodes !== false;
46
- const load = React.useCallback((signal) => episodes
47
- ? client.getSignalsAlert(id, { signal })
48
- : client.getSignalsRawAlert(id, { signal }), [client, id, episodes]);
49
- return (0, api_hooks_1.useOvokRequest)(load, id !== undefined);
50
- }
51
- function useAcknowledgeSignalsAlert(grain = {}) {
52
- const episodes = grain.episodes !== false;
53
- return (0, api_hooks_1.useOvokMutation)(async (client, id) => {
54
- const result = episodes
55
- ? await client.acknowledgeSignalsAlert(id)
56
- : await client.acknowledgeSignalsRawAlert(id);
57
- (0, notification_invalidation_1.notifyNotificationChanges)(client, episodes
58
- ? { type: "signals-alert", alert: result }
59
- : { type: "signals-raw-alert", alert: result });
60
- return result;
61
- });
62
- }