@ovok/core 0.4.36 → 0.4.38

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 (127) hide show
  1. package/dist/client/auth/account-storage.d.ts +1 -0
  2. package/dist/client/auth/account-storage.js +2 -1
  3. package/dist/{utils → client}/auth/exchange-code.d.ts +1 -1
  4. package/dist/{utils → client}/auth/generate-code-challenge-and-verifier.js +5 -17
  5. package/dist/{utils → client}/auth/handle-tenant-code.d.ts +1 -1
  6. package/dist/{utils → client}/auth/handle-tenant-code.js +1 -1
  7. package/dist/client/auth/methods/appleLogin.js +2 -6
  8. package/dist/client/auth/methods/changePassword.js +2 -1
  9. package/dist/client/auth/methods/getSessions.js +2 -1
  10. package/dist/client/auth/methods/googleLogin.js +2 -6
  11. package/dist/client/auth/methods/login.js +26 -44
  12. package/dist/client/auth/methods/logout.js +2 -1
  13. package/dist/client/auth/methods/requestDeleteUser.js +5 -4
  14. package/dist/client/auth/methods/revokeSessions.js +2 -1
  15. package/dist/client/auth/methods/socialLogin.d.ts +7 -0
  16. package/dist/client/auth/methods/socialLogin.js +11 -0
  17. package/dist/client/auth/session-fetch.d.ts +35 -0
  18. package/dist/client/auth/session-fetch.js +206 -0
  19. package/dist/client/auth/session-http.d.ts +11 -0
  20. package/dist/client/auth/session-http.js +169 -0
  21. package/dist/client/auth/sha256.d.ts +2 -0
  22. package/dist/client/auth/sha256.js +65 -0
  23. package/dist/{utils → client}/auth/start-login.d.ts +2 -2
  24. package/dist/client/change-history/methods.js +2 -1
  25. package/dist/client/cms/methods.js +16 -28
  26. package/dist/client/consent/methods.js +3 -2
  27. package/dist/client/email/methods.js +2 -1
  28. package/dist/client/errors/ovok-error-utils.d.ts +6 -0
  29. package/dist/client/errors/ovok-error-utils.js +10 -1
  30. package/dist/client/errors/ovok-error.js +6 -13
  31. package/dist/client/errors/rate-limit-error.js +2 -6
  32. package/dist/client/experience/methods.js +28 -37
  33. package/dist/client/invites/methods.js +8 -12
  34. package/dist/client/notifications/methods.js +5 -5
  35. package/dist/client/observation/fhir-systems.d.ts +4 -0
  36. package/dist/client/observation/fhir-systems.js +7 -0
  37. package/dist/client/observation/methods/generateObservationBodiesByMeasurement.js +23 -29
  38. package/dist/client/observation/methods/getLatestObservationsByCodes.js +6 -9
  39. package/dist/client/observation/methods/observationsToMeasurements.js +44 -91
  40. package/dist/client/observation/services/base-observation-service.js +4 -3
  41. package/dist/client/observation/services/blood-pressure.js +1 -4
  42. package/dist/client/observation/services/{baby-sleep.d.ts → component-observation-services.d.ts} +18 -13
  43. package/dist/client/observation/services/component-observation-services.js +69 -0
  44. package/dist/client/observation/services/creator.d.ts +1 -2
  45. package/dist/client/observation/services/creator.js +15 -33
  46. package/dist/client/observation/services/ecg-observation-fragments.js +5 -6
  47. package/dist/client/observation/services/ecg.js +3 -2
  48. package/dist/client/observation/services/lipid-panel.js +8 -12
  49. package/dist/client/observation/services/measurement-time.d.ts +4 -0
  50. package/dist/client/observation/services/measurement-time.js +6 -0
  51. package/dist/client/observation/services/single-value-services.d.ts +36 -0
  52. package/dist/client/observation/services/single-value-services.js +100 -0
  53. package/dist/client/observation/services/uric-acid-service.js +6 -7
  54. package/dist/client/observation/types/generate-measurement/HealthConnectTypes.d.ts +2 -458
  55. package/dist/client/observation/types/generate-measurement/HealthConnectTypes.js +0 -6
  56. package/dist/client/offline/offline-measurement-queue.js +31 -28
  57. package/dist/client/ovok-client.d.ts +7 -15
  58. package/dist/client/ovok-client.js +54 -398
  59. package/dist/client/patient/methods.js +27 -36
  60. package/dist/client/patient-sharing/methods.js +4 -4
  61. package/dist/client/platform/methods.js +21 -30
  62. package/dist/client/platform/types.d.ts +3 -6
  63. package/dist/client/query-string.d.ts +3 -0
  64. package/dist/client/query-string.js +15 -0
  65. package/dist/client/questionnaire-response/methods/createQuestionnaireResponseWithObservations.js +2 -1
  66. package/dist/client/questionnaire-response/methods/extractQuestionnaireObservations.js +1 -2
  67. package/dist/client/questionnaire-response/methods/populateQuestionnaire.js +1 -2
  68. package/dist/client/questionnaire-response/methods/submitQuestionnaireResponse.js +2 -1
  69. package/dist/client/request-options.d.ts +2 -0
  70. package/dist/client/request-options.js +6 -0
  71. package/dist/client/signals/errors.js +2 -6
  72. package/dist/client/signals/methods.js +22 -22
  73. package/dist/client/slim/live-read.d.ts +4 -0
  74. package/dist/client/slim/live-read.js +87 -0
  75. package/dist/client/slim/methods.d.ts +3 -0
  76. package/dist/client/slim/methods.js +73 -166
  77. package/dist/client/storage.js +3 -2
  78. package/dist/conformance/capability-requirements.js +1 -1
  79. package/dist/conformance/capability.js +8 -7
  80. package/dist/hooks/account-hooks.js +6 -68
  81. package/dist/hooks/api-hooks.d.ts +10 -6
  82. package/dist/hooks/api-hooks.js +29 -88
  83. package/dist/hooks/cms-hooks.js +8 -13
  84. package/dist/hooks/email-hooks.js +1 -40
  85. package/dist/hooks/experience-hooks.js +4 -60
  86. package/dist/hooks/index.d.ts +2 -2
  87. package/dist/hooks/index.js +4 -4
  88. package/dist/hooks/invites-hooks.js +0 -1
  89. package/dist/hooks/notification-hooks.d.ts +4 -1
  90. package/dist/hooks/notification-hooks.js +29 -86
  91. package/dist/hooks/notification-invalidation.d.ts +6 -0
  92. package/dist/hooks/notification-invalidation.js +52 -0
  93. package/dist/hooks/notification-note-hooks.js +13 -28
  94. package/dist/hooks/observation-hooks.js +2 -4
  95. package/dist/hooks/patient-hooks.js +13 -113
  96. package/dist/hooks/patient-sharing-hooks.js +2 -7
  97. package/dist/hooks/platform-hooks.js +3 -51
  98. package/dist/hooks/poll-hooks.js +10 -8
  99. package/dist/hooks/signals-alert-hooks.js +4 -6
  100. package/dist/hooks/signals-hooks.js +2 -45
  101. package/package.json +1 -1
  102. package/dist/client/observation/services/baby-sleep.js +0 -69
  103. package/dist/client/observation/services/blood-glucose.d.ts +0 -12
  104. package/dist/client/observation/services/blood-glucose.js +0 -36
  105. package/dist/client/observation/services/body-temperature.d.ts +0 -13
  106. package/dist/client/observation/services/body-temperature.js +0 -36
  107. package/dist/client/observation/services/body-weight.d.ts +0 -13
  108. package/dist/client/observation/services/body-weight.js +0 -36
  109. package/dist/client/observation/services/heart-rate-variability.d.ts +0 -13
  110. package/dist/client/observation/services/heart-rate-variability.js +0 -38
  111. package/dist/client/observation/services/heart-rate.d.ts +0 -13
  112. package/dist/client/observation/services/heart-rate.js +0 -39
  113. package/dist/client/observation/services/respiratory-rate.d.ts +0 -13
  114. package/dist/client/observation/services/respiratory-rate.js +0 -38
  115. package/dist/client/observation/services/respiratory-therapy.d.ts +0 -28
  116. package/dist/client/observation/services/respiratory-therapy.js +0 -69
  117. package/dist/client/observation/services/resting-heart-rate.d.ts +0 -13
  118. package/dist/client/observation/services/resting-heart-rate.js +0 -38
  119. package/dist/client/observation/services/vo2-max.d.ts +0 -13
  120. package/dist/client/observation/services/vo2-max.js +0 -38
  121. package/dist/client/observation/services/walking-heart-rate-average.d.ts +0 -12
  122. package/dist/client/observation/services/walking-heart-rate-average.js +0 -38
  123. package/dist/utils/auth/sha256.d.ts +0 -8
  124. package/dist/utils/auth/sha256.js +0 -300
  125. /package/dist/{utils → client}/auth/exchange-code.js +0 -0
  126. /package/dist/{utils → client}/auth/generate-code-challenge-and-verifier.d.ts +0 -0
  127. /package/dist/{utils → client}/auth/start-login.js +0 -0
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stableMeasurementId = exports.entryForObservation = exports.OFFLINE_MEASUREMENT_IDENTIFIER_SYSTEM = exports.DEFAULT_OFFLINE_MEASUREMENT_QUEUE_KEY = exports.OfflineMeasurementQueue = exports.OFFLINE_MEASUREMENT_QUEUE_STORAGE_KEY = void 0;
4
+ const fhir_systems_1 = require("../observation/fhir-systems");
5
+ const request_options_1 = require("../request-options");
4
6
  exports.OFFLINE_MEASUREMENT_QUEUE_STORAGE_KEY = "ovok.core.offline-measurements";
5
7
  exports.DEFAULT_OFFLINE_MEASUREMENT_QUEUE_KEY = exports.OFFLINE_MEASUREMENT_QUEUE_STORAGE_KEY;
6
8
  const DEFAULT_MAX_RETRIES = 8;
@@ -8,7 +10,6 @@ const DEFAULT_RETRY_BACKOFF_MS = 5000;
8
10
  const DEFAULT_MAX_RETRY_BACKOFF_MS = 60 * 60 * 1000;
9
11
  const IDENTIFIER_SYSTEM = "https://api.ovok.com/fhir/StructureDefinition/offline-measurement-id";
10
12
  exports.OFFLINE_MEASUREMENT_IDENTIFIER_SYSTEM = IDENTIFIER_SYSTEM;
11
- const DEVICE_READING_IDENTIFIER_SYSTEM = "https://api.ovok.com/fhir/StructureDefinition/device-reading-id";
12
13
  const canonicalize = (value) => {
13
14
  if (value instanceof Date) {
14
15
  return value.toISOString();
@@ -47,10 +48,10 @@ const stableValueId = (input) => {
47
48
  };
48
49
  const stableMeasurementId = (observation) => {
49
50
  const identifiers = observation.identifier;
50
- if (!(identifiers === null || identifiers === void 0 ? void 0 : identifiers.some((identifier) => identifier.system === DEVICE_READING_IDENTIFIER_SYSTEM))) {
51
+ if (!(identifiers === null || identifiers === void 0 ? void 0 : identifiers.some((identifier) => identifier.system === fhir_systems_1.DEVICE_READING_IDENTIFIER_SYSTEM))) {
51
52
  return stableValueId(observation);
52
53
  }
53
- const remainingIdentifiers = identifiers.filter((identifier) => identifier.system !== DEVICE_READING_IDENTIFIER_SYSTEM);
54
+ const remainingIdentifiers = identifiers.filter((identifier) => identifier.system !== fhir_systems_1.DEVICE_READING_IDENTIFIER_SYSTEM);
54
55
  const legacyObservation = { ...observation };
55
56
  if (remainingIdentifiers.length > 0) {
56
57
  legacyObservation.identifier = remainingIdentifiers;
@@ -68,9 +69,9 @@ const entryForObservation = (observation) => {
68
69
  system: IDENTIFIER_SYSTEM,
69
70
  value: id,
70
71
  };
71
- const sourceIdentifier = (_a = observation.identifier) === null || _a === void 0 ? void 0 : _a.find((item) => item.system === DEVICE_READING_IDENTIFIER_SYSTEM);
72
+ const sourceIdentifier = (_a = observation.identifier) === null || _a === void 0 ? void 0 : _a.find((item) => item.system === fhir_systems_1.DEVICE_READING_IDENTIFIER_SYSTEM);
72
73
  const ifNoneExist = sourceIdentifier
73
- ? `identifier=${encodeURIComponent(`${IDENTIFIER_SYSTEM}|${id}`)},${encodeURIComponent(`${DEVICE_READING_IDENTIFIER_SYSTEM}|${sourceIdentifier.value}`)}`
74
+ ? `identifier=${encodeURIComponent(`${IDENTIFIER_SYSTEM}|${id}`)},${encodeURIComponent(`${fhir_systems_1.DEVICE_READING_IDENTIFIER_SYSTEM}|${sourceIdentifier.value}`)}`
74
75
  : `identifier=${IDENTIFIER_SYSTEM}|${id}`;
75
76
  return {
76
77
  fullUrl: `urn:uuid:${id}`,
@@ -94,6 +95,24 @@ const isFailedResponse = (bundle) => {
94
95
  return status.startsWith("4") || status.startsWith("5");
95
96
  })) !== null && _b !== void 0 ? _b : false;
96
97
  };
98
+ /** The stored failure: name, and code/status when present; never the message or payload. */
99
+ const summarizeFailure = (error) => {
100
+ const failure = error;
101
+ return {
102
+ name: typeof (failure === null || failure === void 0 ? void 0 : failure.name) === "string" ? failure.name : "Error",
103
+ ...(typeof (failure === null || failure === void 0 ? void 0 : failure.code) === "string" ? { code: failure.code } : {}),
104
+ ...(typeof (failure === null || failure === void 0 ? void 0 : failure.status) === "number" ? { status: failure.status } : {}),
105
+ };
106
+ };
107
+ /** Counts an item that stays in the queue. */
108
+ const tally = (result, item) => {
109
+ if (item.exhausted) {
110
+ result.exhausted++;
111
+ }
112
+ else {
113
+ result.queued++;
114
+ }
115
+ };
97
116
  class OfflineMeasurementQueue {
98
117
  constructor(storage, transport, options = {}) {
99
118
  var _a, _b, _c, _d;
@@ -123,13 +142,13 @@ class OfflineMeasurementQueue {
123
142
  });
124
143
  this.writeQueue(queue);
125
144
  }
126
- return { id, flush: await this.flushQueue(queue, {}, ...(requestOptions === undefined ? [] : [requestOptions])) };
145
+ return { id, flush: await this.flushQueue(queue, {}, ...(0, request_options_1.optionalArg)(requestOptions)) };
127
146
  });
128
147
  };
129
148
  this.flush = (options = {}, requestOptions) => this.runExclusive(async () => {
130
149
  var _a, _b;
131
150
  await ((_b = (_a = this.storage).getInitPromise) === null || _b === void 0 ? void 0 : _b.call(_a));
132
- return this.flushQueue(this.readQueue(), options, ...(requestOptions === undefined ? [] : [requestOptions]));
151
+ return this.flushQueue(this.readQueue(), options, ...(0, request_options_1.optionalArg)(requestOptions));
133
152
  });
134
153
  this.runExclusive = (operation) => {
135
154
  const next = this.operation.then(operation, operation);
@@ -180,12 +199,7 @@ class OfflineMeasurementQueue {
180
199
  }
181
200
  if ((item.exhausted && !options.includeExhausted) ||
182
201
  item.nextAttemptAt > now) {
183
- if (item.exhausted) {
184
- result.exhausted++;
185
- }
186
- else {
187
- result.queued++;
188
- }
202
+ tally(result, item);
189
203
  continue;
190
204
  }
191
205
  const ownerKey = (_a = this.getOwnerKey) === null || _a === void 0 ? void 0 : _a.call(this);
@@ -200,7 +214,7 @@ class OfflineMeasurementQueue {
200
214
  resourceType: "Bundle",
201
215
  type: "transaction",
202
216
  entry: item.entries,
203
- }, ...(requestOptions === undefined ? [] : [requestOptions]));
217
+ }, ...(0, request_options_1.optionalArg)(requestOptions));
204
218
  if (isFailedResponse(response)) {
205
219
  throw response;
206
220
  }
@@ -217,20 +231,9 @@ class OfflineMeasurementQueue {
217
231
  : Date.now() +
218
232
  Math.min(this.maxRetryBackoffMs, this.retryBackoffMs * 2 ** (attempt - 1));
219
233
  changed = true;
220
- const failure = error;
221
- const lastFailure = {
222
- name: typeof (failure === null || failure === void 0 ? void 0 : failure.name) === "string" ? failure.name : "Error",
223
- ...(typeof (failure === null || failure === void 0 ? void 0 : failure.code) === "string" ? { code: failure.code } : {}),
224
- ...(typeof (failure === null || failure === void 0 ? void 0 : failure.status) === "number" ? { status: failure.status } : {}),
225
- };
226
- item.lastFailure = lastFailure;
227
- result.failures[item.id] = lastFailure;
228
- if (item.exhausted) {
229
- result.exhausted++;
230
- }
231
- else {
232
- result.queued++;
233
- }
234
+ item.lastFailure = summarizeFailure(error);
235
+ result.failures[item.id] = item.lastFailure;
236
+ tally(result, item);
234
237
  }
235
238
  }
236
239
  if (changed) {
@@ -3,6 +3,7 @@ import { Bundle, CapabilityStatement, Observation } from "@medplum/fhirtypes";
3
3
  import { OvokPublicApiEndpoint } from "../conformance/capability";
4
4
  import * as aiFhirMethods from "./ai-fhir/methods";
5
5
  import * as authMethods from "./auth/methods";
6
+ import { OvokUnauthenticatedReason } from "./auth/session-fetch";
6
7
  import { OvokSavedAccount } from "./auth/types/Account";
7
8
  import * as botMethods from "./bot/methods";
8
9
  import * as changeHistoryMethods from "./change-history/methods";
@@ -22,8 +23,8 @@ import * as platformMethods from "./platform/methods";
22
23
  import * as questionnaireResponseMethods from "./questionnaire-response/methods";
23
24
  import * as signalsMethods from "./signals/methods";
24
25
  import * as slimMethods from "./slim/methods";
25
- export declare const MAX_CONDITIONAL_OBSERVATION_ENTRIES = 8;
26
- export { MAX_OBSERVATION_BUNDLE_BYTES } from "./observation/observation-bundle-utils";
26
+ export { MAX_CONDITIONAL_OBSERVATION_ENTRIES, MAX_OBSERVATION_BUNDLE_BYTES, } from "./observation/observation-bundle-utils";
27
+ export type { OvokUnauthenticatedReason } from "./auth/session-fetch";
27
28
  export type SaveObservationsResult = {
28
29
  status: "saved";
29
30
  response: Bundle;
@@ -32,19 +33,6 @@ export type SaveObservationsResult = {
32
33
  queueId: string;
33
34
  };
34
35
  export type OvokFhirVersion = "R4" | "R5";
35
- export type OvokUnauthenticatedReason = {
36
- type: "refresh-rejected";
37
- status: 400 | 401 | 403;
38
- } | {
39
- type: "refresh-unavailable";
40
- status?: number;
41
- } | {
42
- type: "authentication-rejected";
43
- status: number;
44
- } | {
45
- type: "request-unauthorized";
46
- status: 401;
47
- };
48
36
  export type OvokClientOptions = Omit<MedplumClientOptions, "onUnauthenticated"> & {
49
37
  onUnauthenticated?: (reason: OvokUnauthenticatedReason) => void;
50
38
  socialLoginClientId?: string;
@@ -95,12 +83,16 @@ export declare class OvokClient extends MedplumClient {
95
83
  /** Flushes measurements queued while offline. Call this on connectivity/app-resume events. */
96
84
  flushOfflineMeasurementQueue(options?: OfflineMeasurementFlushOptions, requestOptions?: MedplumRequestOptions): Promise<OfflineMeasurementFlushResult>;
97
85
  private getOfflineMeasurementQueue;
86
+ /** Queued measurements belong to one account on one server and project. */
87
+ private offlineOwnerKey;
98
88
  /**
99
89
  * Medplum clears its entire client storage after an unrecoverable 401. Keep
100
90
  * saved accounts (marking only the active one expired) and queued measurements.
101
91
  * Use clearAllAccounts() when the caller intends to remove all saved accounts.
102
92
  */
103
93
  clear(): void;
94
+ /** Runs Medplum's storage clear but keeps queued offline measurements; `restore` runs in between. */
95
+ private clearKeepingQueue;
104
96
  private getLogin;
105
97
  private getExpiredAccountIds;
106
98
  private createAccountSessionClient;