@ovok/core 0.4.35 → 0.4.37

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 (54) hide show
  1. package/dist/client/auth/session-fetch.d.ts +35 -0
  2. package/dist/client/auth/session-fetch.js +207 -0
  3. package/dist/client/auth/session-http.d.ts +11 -0
  4. package/dist/client/auth/session-http.js +180 -0
  5. package/dist/client/experience/methods.js +27 -37
  6. package/dist/client/notifications/methods.js +4 -5
  7. package/dist/client/observation/services/creator.js +4 -18
  8. package/dist/client/observation/services/single-value-services.d.ts +31 -0
  9. package/dist/client/observation/services/single-value-services.js +95 -0
  10. package/dist/client/observation/types/measurement/MeasurementDevice.d.ts +9 -0
  11. package/dist/client/observation/utils/getDeviceObject.js +18 -4
  12. package/dist/client/ovok-client.d.ts +2 -13
  13. package/dist/client/ovok-client.js +8 -356
  14. package/dist/client/patient/methods.js +2 -11
  15. package/dist/client/patient-sharing/methods.js +1 -2
  16. package/dist/client/platform/methods.js +14 -24
  17. package/dist/client/query-string.d.ts +3 -0
  18. package/dist/client/query-string.js +15 -0
  19. package/dist/client/questionnaire-response/methods/extractQuestionnaireObservations.js +1 -2
  20. package/dist/client/questionnaire-response/methods/populateQuestionnaire.js +1 -2
  21. package/dist/client/signals/methods.js +16 -17
  22. package/dist/client/slim/methods.js +58 -68
  23. package/dist/conformance/capability-requirements.js +1 -1
  24. package/dist/hooks/account-hooks.js +6 -68
  25. package/dist/hooks/api-hooks.d.ts +5 -0
  26. package/dist/hooks/api-hooks.js +22 -67
  27. package/dist/hooks/email-hooks.js +1 -40
  28. package/dist/hooks/experience-hooks.js +4 -60
  29. package/dist/hooks/notification-hooks.js +5 -55
  30. package/dist/hooks/notification-invalidation.d.ts +6 -0
  31. package/dist/hooks/notification-invalidation.js +52 -0
  32. package/dist/hooks/patient-hooks.js +13 -113
  33. package/dist/hooks/patient-sharing-hooks.js +1 -5
  34. package/dist/hooks/platform-hooks.js +3 -51
  35. package/dist/hooks/signals-hooks.js +2 -45
  36. package/package.json +1 -1
  37. package/dist/client/observation/services/blood-glucose.d.ts +0 -12
  38. package/dist/client/observation/services/blood-glucose.js +0 -36
  39. package/dist/client/observation/services/body-temperature.d.ts +0 -13
  40. package/dist/client/observation/services/body-temperature.js +0 -36
  41. package/dist/client/observation/services/body-weight.d.ts +0 -13
  42. package/dist/client/observation/services/body-weight.js +0 -36
  43. package/dist/client/observation/services/heart-rate-variability.d.ts +0 -13
  44. package/dist/client/observation/services/heart-rate-variability.js +0 -38
  45. package/dist/client/observation/services/heart-rate.d.ts +0 -13
  46. package/dist/client/observation/services/heart-rate.js +0 -39
  47. package/dist/client/observation/services/respiratory-rate.d.ts +0 -13
  48. package/dist/client/observation/services/respiratory-rate.js +0 -38
  49. package/dist/client/observation/services/resting-heart-rate.d.ts +0 -13
  50. package/dist/client/observation/services/resting-heart-rate.js +0 -38
  51. package/dist/client/observation/services/vo2-max.d.ts +0 -13
  52. package/dist/client/observation/services/vo2-max.js +0 -38
  53. package/dist/client/observation/services/walking-heart-rate-average.d.ts +0 -12
  54. package/dist/client/observation/services/walking-heart-rate-average.js +0 -38
@@ -1,79 +1,21 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.useRepushUnconfirmedLimits = exports.useUnconfirmedLimits = exports.useUpdateSlimPatientThresholdV2 = exports.useUpdateSlimThresholdV2 = exports.useSlimPatientThresholdV2 = exports.useSlimThresholdV2 = exports.useSetMedicalConsent = exports.useMedicalConsent = exports.useSetLegalConsent = exports.useLegalConsent = exports.useChangeHistory = void 0;
38
- const React = __importStar(require("react"));
39
5
  const api_hooks_1 = require("./api-hooks");
40
- const index_1 = require("./index");
41
- const useChangeHistory = (params = {}) => {
42
- const client = (0, index_1.useClient)();
43
- const serialized = JSON.stringify(params);
44
- const load = React.useCallback((signal) => client.listChangeHistory(params, { signal }), [client, serialized]);
45
- return (0, api_hooks_1.useOvokRequest)(load);
46
- };
6
+ const useChangeHistory = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listChangeHistory(params, { signal }), params);
47
7
  exports.useChangeHistory = useChangeHistory;
48
- const useLegalConsent = () => {
49
- const client = (0, index_1.useClient)();
50
- const load = React.useCallback((signal) => client.getLegalConsent({ signal }), [client]);
51
- return (0, api_hooks_1.useOvokRequest)(load);
52
- };
8
+ const useLegalConsent = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getLegalConsent({ signal }));
53
9
  exports.useLegalConsent = useLegalConsent;
54
10
  const useSetLegalConsent = () => (0, api_hooks_1.useOvokMutation)((client, accepted) => client.setLegalConsent(accepted));
55
11
  exports.useSetLegalConsent = useSetLegalConsent;
56
- const useMedicalConsent = () => {
57
- const client = (0, index_1.useClient)();
58
- const load = React.useCallback((signal) => client.getMedicalConsent({ signal }), [client]);
59
- return (0, api_hooks_1.useOvokRequest)(load);
60
- };
12
+ const useMedicalConsent = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getMedicalConsent({ signal }));
61
13
  exports.useMedicalConsent = useMedicalConsent;
62
14
  const useSetMedicalConsent = () => (0, api_hooks_1.useOvokMutation)((client, accepted) => client.setMedicalConsent(accepted));
63
15
  exports.useSetMedicalConsent = useSetMedicalConsent;
64
- const useSlimThresholdV2 = () => {
65
- const client = (0, index_1.useClient)();
66
- const load = React.useCallback((signal) => client.getSlimThresholdV2({ signal }), [client]);
67
- return (0, api_hooks_1.useOvokRequest)(load);
68
- };
16
+ const useSlimThresholdV2 = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getSlimThresholdV2({ signal }));
69
17
  exports.useSlimThresholdV2 = useSlimThresholdV2;
70
- const useSlimPatientThresholdV2 = (patientId) => {
71
- const client = (0, index_1.useClient)();
72
- const load = React.useCallback((signal) => patientId
73
- ? client.getSlimPatientThresholdV2(patientId, { signal })
74
- : Promise.reject(new Error("patientId is required")), [client, patientId]);
75
- return (0, api_hooks_1.useOvokRequest)(load, patientId !== undefined);
76
- };
18
+ const useSlimPatientThresholdV2 = (patientId) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => patientId ? client.getSlimPatientThresholdV2(patientId, { signal }) : Promise.reject(new Error("patientId is required")), patientId, patientId !== undefined);
77
19
  exports.useSlimPatientThresholdV2 = useSlimPatientThresholdV2;
78
20
  const useUpdateSlimThresholdV2 = () => (0, api_hooks_1.useOvokMutation)((client, body) => client.updateSlimThresholdV2(body));
79
21
  exports.useUpdateSlimThresholdV2 = useUpdateSlimThresholdV2;
@@ -82,11 +24,7 @@ const useUpdateSlimPatientThresholdV2 = () => (0, api_hooks_1.useOvokMutation)(a
82
24
  return client.getSlimPatientThresholdV2(params.patientId);
83
25
  });
84
26
  exports.useUpdateSlimPatientThresholdV2 = useUpdateSlimPatientThresholdV2;
85
- const useUnconfirmedLimits = () => {
86
- const client = (0, index_1.useClient)();
87
- const load = React.useCallback((signal) => client.listUnconfirmedLimits({ signal }), [client]);
88
- return (0, api_hooks_1.useOvokRequest)(load);
89
- };
27
+ const useUnconfirmedLimits = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listUnconfirmedLimits({ signal }));
90
28
  exports.useUnconfirmedLimits = useUnconfirmedLimits;
91
29
  const useRepushUnconfirmedLimits = () => (0, api_hooks_1.useOvokMutation)((client) => client.repushUnconfirmedLimits());
92
30
  exports.useRepushUnconfirmedLimits = useRepushUnconfirmedLimits;
@@ -29,6 +29,11 @@ export declare function useOvokRequest<T>(load: (signal?: AbortSignal) => Promis
29
29
  export declare function useOvokRequestWithUpdater<T>(load: (signal?: AbortSignal) => Promise<T>, enabled?: boolean): OvokRequestState<T> & {
30
30
  updateData(update: (current: T | undefined) => T | undefined): void;
31
31
  };
32
+ /**
33
+ * Reads through the active client. `inputs` holds every value the request depends on and is
34
+ * compared by value, so callers can pass a fresh params object each render.
35
+ */
36
+ export declare function useOvokClientRequest<T>(request: (client: OvokClient, signal?: AbortSignal) => Promise<T>, inputs?: unknown, enabled?: boolean): OvokRequestState<T>;
32
37
  /** Generic mutation hook for any typed OvokClient method. */
33
38
  export declare function useOvokMutation<TParams, TData>(mutateRequest: (client: OvokClient, params: TParams) => Promise<TData>): OvokMutationState<TParams, TData>;
34
39
  export declare const useCapabilityStatement: (version?: OvokFhirVersion) => OvokRequestState<CapabilityStatement>;
@@ -37,6 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.useRecentSlimNotifications = exports.useSlimNotifications = exports.useSlimDeviceTelemetry = exports.useSlimDevices = exports.useSlimPatients = exports.useProjectFeatures = exports.useProjectSettings = exports.useAdministeredProjects = exports.usePublicApiEndpoints = exports.useCapabilityStatement = void 0;
38
38
  exports.useOvokRequest = useOvokRequest;
39
39
  exports.useOvokRequestWithUpdater = useOvokRequestWithUpdater;
40
+ exports.useOvokClientRequest = useOvokClientRequest;
40
41
  exports.useOvokMutation = useOvokMutation;
41
42
  const React = __importStar(require("react"));
42
43
  const notification_invalidation_1 = require("./notification-invalidation");
@@ -112,6 +113,17 @@ function useOvokRequestWithUpdater(load, enabled = true) {
112
113
  updateData,
113
114
  };
114
115
  }
116
+ /**
117
+ * Reads through the active client. `inputs` holds every value the request depends on and is
118
+ * compared by value, so callers can pass a fresh params object each render.
119
+ */
120
+ function useOvokClientRequest(request, inputs, enabled = true) {
121
+ const client = (0, index_1.useClient)();
122
+ const key = JSON.stringify(inputs);
123
+ // `inputs` is compared by value through `key`, so the request closure isn't a dependency.
124
+ const load = React.useCallback((signal) => request(client, signal), [client, key]);
125
+ return useOvokRequest(load, enabled);
126
+ }
115
127
  /** Generic mutation hook for any typed OvokClient method. */
116
128
  function useOvokMutation(mutateRequest) {
117
129
  const client = (0, index_1.useClient)();
@@ -142,58 +154,21 @@ function useOvokMutation(mutateRequest) {
142
154
  }, []);
143
155
  return { data, loading, error, mutate, reset };
144
156
  }
145
- const useCapabilityStatement = (version = "R4") => {
146
- const client = (0, index_1.useClient)();
147
- const load = React.useCallback((signal) => client.getCapabilityStatement(version, { signal }), [client, version]);
148
- return useOvokRequest(load);
149
- };
157
+ const useCapabilityStatement = (version = "R4") => useOvokClientRequest((client, signal) => client.getCapabilityStatement(version, { signal }), version);
150
158
  exports.useCapabilityStatement = useCapabilityStatement;
151
- const usePublicApiEndpoints = (version = "R4") => {
152
- const client = (0, index_1.useClient)();
153
- const load = React.useCallback((signal) => client.getPublicApiEndpoints(version, { signal }), [client, version]);
154
- return useOvokRequest(load);
155
- };
159
+ const usePublicApiEndpoints = (version = "R4") => useOvokClientRequest((client, signal) => client.getPublicApiEndpoints(version, { signal }), version);
156
160
  exports.usePublicApiEndpoints = usePublicApiEndpoints;
157
- const useAdministeredProjects = (params = {}) => {
158
- const client = (0, index_1.useClient)();
159
- const serialized = JSON.stringify(params);
160
- const load = React.useCallback((signal) => client.listAdministeredProjects(params, { signal }), [client, serialized]);
161
- return useOvokRequest(load);
162
- };
161
+ const useAdministeredProjects = (params = {}) => useOvokClientRequest((client, signal) => client.listAdministeredProjects(params, { signal }), params);
163
162
  exports.useAdministeredProjects = useAdministeredProjects;
164
- const useProjectSettings = () => {
165
- const client = (0, index_1.useClient)();
166
- const load = React.useCallback((signal) => client.getProjectSettings({ signal }), [client]);
167
- return useOvokRequest(load);
168
- };
163
+ const useProjectSettings = () => useOvokClientRequest((client, signal) => client.getProjectSettings({ signal }));
169
164
  exports.useProjectSettings = useProjectSettings;
170
- const useProjectFeatures = () => {
171
- const client = (0, index_1.useClient)();
172
- const load = React.useCallback((signal) => client.getProjectFeatures({ signal }), [client]);
173
- return useOvokRequest(load);
174
- };
165
+ const useProjectFeatures = () => useOvokClientRequest((client, signal) => client.getProjectFeatures({ signal }));
175
166
  exports.useProjectFeatures = useProjectFeatures;
176
- const useSlimPatients = (params = {}) => {
177
- const client = (0, index_1.useClient)();
178
- const serialized = JSON.stringify(params);
179
- const load = React.useCallback((signal) => client.listSlimPatients(params, { signal }), [client, serialized]);
180
- return useOvokRequest(load);
181
- };
167
+ const useSlimPatients = (params = {}) => useOvokClientRequest((client, signal) => client.listSlimPatients(params, { signal }), params);
182
168
  exports.useSlimPatients = useSlimPatients;
183
- const useSlimDevices = (params = {}) => {
184
- const client = (0, index_1.useClient)();
185
- const serialized = JSON.stringify(params);
186
- const load = React.useCallback((signal) => client.listSlimDevices(params, { signal }), [client, serialized]);
187
- return useOvokRequest(load);
188
- };
169
+ const useSlimDevices = (params = {}) => useOvokClientRequest((client, signal) => client.listSlimDevices(params, { signal }), params);
189
170
  exports.useSlimDevices = useSlimDevices;
190
- const useSlimDeviceTelemetry = (deviceId) => {
191
- const client = (0, index_1.useClient)();
192
- const load = React.useCallback((signal) => deviceId
193
- ? client.getSlimDeviceTelemetry(deviceId, { signal })
194
- : Promise.reject(new Error("deviceId is required")), [client, deviceId]);
195
- return useOvokRequest(load, deviceId !== undefined);
196
- };
171
+ const useSlimDeviceTelemetry = (deviceId) => useOvokClientRequest((client, signal) => deviceId ? client.getSlimDeviceTelemetry(deviceId, { signal }) : Promise.reject(new Error("deviceId is required")), deviceId, deviceId !== undefined);
197
172
  exports.useSlimDeviceTelemetry = useSlimDeviceTelemetry;
198
173
  /** @deprecated Use useSlimOutOfBedNotifications, useSlimAlarms, or useSlimMedicalNotifications. */
199
174
  const useSlimNotifications = (params = {}) => {
@@ -201,17 +176,7 @@ const useSlimNotifications = (params = {}) => {
201
176
  const serialized = JSON.stringify(params);
202
177
  const load = React.useCallback((signal) => client.listSlimNotifications(params, { signal }), [client, serialized]);
203
178
  const { updateData, ...state } = useOvokRequestWithUpdater(load);
204
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
205
- if (!change) {
206
- state.reload();
207
- }
208
- else if (change.type === "slim") {
209
- updateData((current) => current && ({
210
- ...current,
211
- resources: current.resources.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
212
- }));
213
- }
214
- }), [client, state.reload, updateData]);
179
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "resources");
215
180
  return state;
216
181
  };
217
182
  exports.useSlimNotifications = useSlimNotifications;
@@ -219,17 +184,7 @@ const useRecentSlimNotifications = (count) => {
219
184
  const client = (0, index_1.useClient)();
220
185
  const load = React.useCallback((signal) => client.getRecentSlimNotifications(count, { signal }), [client, count]);
221
186
  const { updateData, ...state } = useOvokRequestWithUpdater(load);
222
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
223
- if (!change) {
224
- state.reload();
225
- }
226
- else if (change.type === "slim") {
227
- updateData((current) => current && ({
228
- ...current,
229
- recent: current.recent.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
230
- }));
231
- }
232
- }), [client, state.reload, updateData]);
187
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "recent");
233
188
  return state;
234
189
  };
235
190
  exports.useRecentSlimNotifications = useRecentSlimNotifications;
@@ -1,46 +1,7 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.useEmailTemplates = void 0;
38
- const React = __importStar(require("react"));
39
5
  const api_hooks_1 = require("./api-hooks");
40
- const index_1 = require("./index");
41
- const useEmailTemplates = () => {
42
- const client = (0, index_1.useClient)();
43
- const load = React.useCallback((signal) => client.getEmailTemplates({ signal }), [client]);
44
- return (0, api_hooks_1.useOvokRequest)(load);
45
- };
6
+ const useEmailTemplates = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getEmailTemplates({ signal }));
46
7
  exports.useEmailTemplates = useEmailTemplates;
@@ -1,73 +1,17 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.useCreateVideoCallUserAccess = exports.useCreateVideoCallAppointment = exports.useVideoCallAccess = exports.useVideoCallAppointments = exports.useContent = exports.useDocuments = exports.useConsentSignature = void 0;
38
- const React = __importStar(require("react"));
39
5
  const api_hooks_1 = require("./api-hooks");
40
- const index_1 = require("./index");
41
6
  const useConsentSignature = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.requestConsentSignature(params.consentId));
42
7
  exports.useConsentSignature = useConsentSignature;
43
- const useDocuments = (params = {}) => {
44
- const client = (0, index_1.useClient)();
45
- const serialized = JSON.stringify(params);
46
- const load = React.useCallback((signal) => client.listDocuments(params, { signal }), [client, serialized]);
47
- return (0, api_hooks_1.useOvokRequest)(load);
48
- };
8
+ const useDocuments = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listDocuments(params, { signal }), params);
49
9
  exports.useDocuments = useDocuments;
50
- const useContent = (type, language, params = {}) => {
51
- const client = (0, index_1.useClient)();
52
- const serialized = JSON.stringify(params);
53
- const load = React.useCallback((signal) => client.searchContent(type, language, params, { signal }), [client, language, serialized, type]);
54
- return (0, api_hooks_1.useOvokRequest)(load, type.length > 0 && language.length > 0);
55
- };
10
+ const useContent = (type, language, params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.searchContent(type, language, params, { signal }), [language, params, type], type.length > 0 && language.length > 0);
56
11
  exports.useContent = useContent;
57
- const useVideoCallAppointments = (params = {}) => {
58
- const client = (0, index_1.useClient)();
59
- const serialized = JSON.stringify(params);
60
- const load = React.useCallback((signal) => client.listVideoCallAppointments(params, { signal }), [client, serialized]);
61
- return (0, api_hooks_1.useOvokRequest)(load);
62
- };
12
+ const useVideoCallAppointments = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listVideoCallAppointments(params, { signal }), params);
63
13
  exports.useVideoCallAppointments = useVideoCallAppointments;
64
- const useVideoCallAccess = (appointmentId) => {
65
- const client = (0, index_1.useClient)();
66
- const load = React.useCallback((signal) => appointmentId
67
- ? client.getVideoCallAccessPermission(appointmentId, { signal })
68
- : Promise.reject(new Error("appointmentId is required")), [appointmentId, client]);
69
- return (0, api_hooks_1.useOvokRequest)(load, appointmentId !== undefined);
70
- };
14
+ const useVideoCallAccess = (appointmentId) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => appointmentId ? client.getVideoCallAccessPermission(appointmentId, { signal }) : Promise.reject(new Error("appointmentId is required")), appointmentId, appointmentId !== undefined);
71
15
  exports.useVideoCallAccess = useVideoCallAccess;
72
16
  const useCreateVideoCallAppointment = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.createVideoCallAppointment(params));
73
17
  exports.useCreateVideoCallAppointment = useCreateVideoCallAppointment;
@@ -46,17 +46,7 @@ const useSlimAlarms = (params = {}) => {
46
46
  const [revision, setRevision] = React.useState(0);
47
47
  const load = React.useCallback((signal) => client.listSlimAlarms(params, { signal }), [client, serialized, revision]);
48
48
  const { updateData, ...state } = (0, api_hooks_1.useOvokRequestWithUpdater)(load);
49
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
50
- if (!change) {
51
- state.reload();
52
- }
53
- else if (change.type === "slim") {
54
- updateData((current) => current && ({
55
- ...current,
56
- resources: current.resources.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
57
- }));
58
- }
59
- }), [client, state.reload, updateData]);
49
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "resources");
60
50
  return { ...state, reload: () => setRevision((value) => value + 1) };
61
51
  };
62
52
  exports.useSlimAlarms = useSlimAlarms;
@@ -64,17 +54,7 @@ const useRecentAlarms = (count) => {
64
54
  const client = (0, index_1.useClient)();
65
55
  const load = React.useCallback((signal) => client.getRecentAlarms(count, { signal }), [client, count]);
66
56
  const { updateData, ...state } = (0, api_hooks_1.useOvokRequestWithUpdater)(load);
67
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
68
- if (!change) {
69
- state.reload();
70
- }
71
- else if (change.type === "slim") {
72
- updateData((current) => current && ({
73
- ...current,
74
- recent: current.recent.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
75
- }));
76
- }
77
- }), [client, state.reload, updateData]);
57
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "recent");
78
58
  return state;
79
59
  };
80
60
  exports.useRecentAlarms = useRecentAlarms;
@@ -82,17 +62,7 @@ const useRecentOutOfBed = (count) => {
82
62
  const client = (0, index_1.useClient)();
83
63
  const load = React.useCallback((signal) => client.getRecentOutOfBed(count, { signal }), [client, count]);
84
64
  const { updateData, ...state } = (0, api_hooks_1.useOvokRequestWithUpdater)(load);
85
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
86
- if (!change) {
87
- state.reload();
88
- }
89
- else if (change.type === "slim") {
90
- updateData((current) => current && ({
91
- ...current,
92
- recent: current.recent.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
93
- }));
94
- }
95
- }), [client, state.reload, updateData]);
65
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "recent");
96
66
  return state;
97
67
  };
98
68
  exports.useRecentOutOfBed = useRecentOutOfBed;
@@ -100,17 +70,7 @@ const useSlimOutOfBedNotifications = (params = {}) => {
100
70
  const client = (0, index_1.useClient)();
101
71
  const serialized = JSON.stringify(params);
102
72
  const { updateData, ...state } = (0, api_hooks_1.useOvokRequestWithUpdater)(React.useCallback((signal) => client.listSlimOutOfBedNotifications(params, { signal }), [client, serialized]));
103
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
104
- if (!change) {
105
- state.reload();
106
- }
107
- else if (change.type === "slim") {
108
- updateData((current) => current && ({
109
- ...current,
110
- resources: current.resources.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
111
- }));
112
- }
113
- }), [client, state.reload, updateData]);
73
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "resources");
114
74
  return state;
115
75
  };
116
76
  exports.useSlimOutOfBedNotifications = useSlimOutOfBedNotifications;
@@ -124,17 +84,7 @@ const useSlimMedicalNotifications = (params = {}, options = {}) => {
124
84
  return { items: result.rows, nextCursor: null, total: result.total, truncated: result.truncated };
125
85
  }, [client, serialized, serializedOptions]);
126
86
  const { updateData, ...state } = (0, api_hooks_1.useOvokRequestWithUpdater)(load);
127
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
128
- if (!change) {
129
- state.reload();
130
- }
131
- else if (change.type === "slim") {
132
- updateData((current) => current && ({
133
- ...current,
134
- items: current.items.map((item) => (0, notification_invalidation_1.mergeSlimNotification)(item, change.notification)),
135
- }));
136
- }
137
- }), [client, state.reload, updateData]);
87
+ (0, notification_invalidation_1.useSlimNotificationSync)(client, state.reload, updateData, "items");
138
88
  return state;
139
89
  };
140
90
  exports.useSlimMedicalNotifications = useSlimMedicalNotifications;
@@ -18,4 +18,10 @@ type NotificationChangeListener = (change?: NotificationChange) => void;
18
18
  export declare function subscribeToNotificationChanges(client: OvokClient, listener: NotificationChangeListener): () => void;
19
19
  export declare function notifyNotificationChanges(client: OvokClient, change?: NotificationChange): void;
20
20
  export declare function mergeSlimNotification<T extends object>(item: T, notification: SlimNotification | SlimMedicalNotificationRow): T;
21
+ type SlimListField = "resources" | "recent" | "items";
22
+ /**
23
+ * Keeps a mounted Slim notification list current: a full invalidation reloads it, a single
24
+ * Slim change is merged into the matching rows of `field`.
25
+ */
26
+ export declare function useSlimNotificationSync<K extends SlimListField, T extends Record<K, readonly object[]>>(client: OvokClient, reload: () => void, updateData: (update: (current: T | undefined) => T | undefined) => void, field: K): void;
21
27
  export {};
@@ -1,8 +1,43 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.subscribeToNotificationChanges = subscribeToNotificationChanges;
4
37
  exports.notifyNotificationChanges = notifyNotificationChanges;
5
38
  exports.mergeSlimNotification = mergeSlimNotification;
39
+ exports.useSlimNotificationSync = useSlimNotificationSync;
40
+ const React = __importStar(require("react"));
6
41
  const listeners = new WeakMap();
7
42
  function subscribeToNotificationChanges(client, listener) {
8
43
  var _a;
@@ -35,3 +70,20 @@ function mergeSlimNotification(item, notification) {
35
70
  ? { ...item, ...notification }
36
71
  : item;
37
72
  }
73
+ /**
74
+ * Keeps a mounted Slim notification list current: a full invalidation reloads it, a single
75
+ * Slim change is merged into the matching rows of `field`.
76
+ */
77
+ function useSlimNotificationSync(client, reload, updateData, field) {
78
+ React.useEffect(() => subscribeToNotificationChanges(client, (change) => {
79
+ if (!change) {
80
+ reload();
81
+ }
82
+ else if (change.type === "slim") {
83
+ updateData((current) => current && {
84
+ ...current,
85
+ [field]: current[field].map((item) => mergeSlimNotification(item, change.notification)),
86
+ });
87
+ }
88
+ }), [client, reload, updateData, field]);
89
+ }