@ovok/core 0.3.2 → 0.3.3

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.
@@ -12,18 +12,21 @@ async function login(body) {
12
12
  body,
13
13
  codeChallenge,
14
14
  });
15
- const tenantCode = (0, handle_tenant_code_1.handleTenantCode)({
16
- profiles: startResponse.profiles,
17
- tenantCode: body.tenantCode,
18
- type: body.type,
19
- });
20
- if (!tenantCode) {
21
- throw new Error("No tenant code found");
22
- }
23
15
  if (startResponse.nextStep === "mfa") {
24
16
  return {
25
17
  nextStep: "mfa",
26
18
  verify: async (code) => {
19
+ const tenantCode = body.type === "Practitioner" && !startResponse.profiles
20
+ ? body.tenantCode
21
+ : (0, handle_tenant_code_1.handleTenantCode)({
22
+ profiles: startResponse.profiles,
23
+ tenantCode: body.tenantCode,
24
+ type: body.type,
25
+ });
26
+ const practitionerTenantCode = tenantCode;
27
+ if (body.type === "Practitioner" && !practitionerTenantCode) {
28
+ throw new Error("No tenant code found");
29
+ }
27
30
  const mfaResponse = await this.post(`auth/tenant/${body.type}/login/mfa`, {
28
31
  loginId: startResponse.loginId,
29
32
  mfaToken: code,
@@ -34,7 +37,7 @@ async function login(body) {
34
37
  type: "Practitioner",
35
38
  sessionCode: mfaResponse.sessionCode,
36
39
  codeVerifier,
37
- tenantCode,
40
+ tenantCode: practitionerTenantCode,
38
41
  });
39
42
  }
40
43
  return (0, exchange_code_1.exchangeCode)({
@@ -46,6 +49,14 @@ async function login(body) {
46
49
  },
47
50
  };
48
51
  }
52
+ const tenantCode = (0, handle_tenant_code_1.handleTenantCode)({
53
+ profiles: startResponse.profiles,
54
+ tenantCode: body.tenantCode,
55
+ type: body.type,
56
+ });
57
+ if (!tenantCode) {
58
+ throw new Error("No tenant code found");
59
+ }
49
60
  const exchangeCodeProps = body.type === "Practitioner"
50
61
  ? {
51
62
  client: this,
@@ -2,11 +2,8 @@
2
2
  export interface OvokSession {
3
3
  id: string;
4
4
  authMethod?: string;
5
- ip?: string;
6
- browser?: string;
7
- os?: string;
8
- createdAt?: string;
9
- lastActiveAt?: string;
5
+ remoteAddress?: string;
6
+ lastUpdated?: string;
10
7
  }
11
8
  /** Session selector accepted by the session revocation endpoint. */
12
9
  export type SessionRevokeOption = "current" | "other" | "all" | (string & {});
@@ -4,6 +4,7 @@ exports.RateLimitError = void 0;
4
4
  exports.isRateLimitError = isRateLimitError;
5
5
  exports.mapRateLimitError = mapRateLimitError;
6
6
  const core_1 = require("@medplum/core");
7
+ const RATE_LIMIT_RESET_EXTENSION_URL = "https://medplum.com/fhir/StructureDefinition/rate-limit-reset";
7
8
  /** A typed error returned when the server asks the client to slow down. */
8
9
  class RateLimitError extends Error {
9
10
  constructor(retryAfterMs, options) {
@@ -31,10 +32,33 @@ function mapRateLimitError(error) {
31
32
  return error;
32
33
  }
33
34
  if (error instanceof core_1.OperationOutcomeError && isRateLimitOutcome(error.outcome)) {
34
- return new RateLimitError((0, core_1.getRateLimitReset)(error.outcome), { cause: error });
35
+ return new RateLimitError(rateLimitResetFromOutcome(error.outcome), { cause: error });
35
36
  }
36
37
  return error;
37
38
  }
39
+ function rateLimitResetFromOutcome(outcome) {
40
+ var _a, _b, _c;
41
+ if (!outcome || typeof outcome !== "object") {
42
+ return undefined;
43
+ }
44
+ const record = outcome;
45
+ const extension = (_a = record.extension) === null || _a === void 0 ? void 0 : _a.find((candidate) => candidate.url === RATE_LIMIT_RESET_EXTENSION_URL);
46
+ if (typeof (extension === null || extension === void 0 ? void 0 : extension.valueUnsignedInt) === "number") {
47
+ return extension.valueUnsignedInt * 1000;
48
+ }
49
+ for (const issue of (_b = record.issue) !== null && _b !== void 0 ? _b : []) {
50
+ try {
51
+ const diagnostics = JSON.parse((_c = issue.diagnostics) !== null && _c !== void 0 ? _c : "");
52
+ if (typeof diagnostics.msBeforeNext === "number") {
53
+ return diagnostics.msBeforeNext;
54
+ }
55
+ }
56
+ catch (_d) {
57
+ // Diagnostics are optional and may be ordinary human-readable text.
58
+ }
59
+ }
60
+ return undefined;
61
+ }
38
62
  function isRateLimitOutcome(outcome) {
39
63
  if (!(0, core_1.isOperationOutcome)(outcome)) {
40
64
  return false;
@@ -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.3.1",
51
+ version: "0.3.2",
52
52
  },
53
53
  fhirVersion: "4.0.1",
54
54
  format: ["json"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",