{"version":3,"file":"client.cjs","sources":["../../../src/client/client.ts"],"sourcesContent":["import { v4 as uuidv4 } from 'uuid';\nimport { OystehrConfig } from '../config';\nimport { OystehrFHIRError, OystehrSdkError } from '../errors';\nimport { FhirBundle, FhirResource, OperationOutcome } from '../resources/types';\n\ntype HttpMethod = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';\nexport const defaultProjectApiUrl = 'https://project-api.zapehr.com/v1';\nconst defaultFhirApiUrl = 'https://fhir-api.zapehr.com';\nconst STATUS_CODES_TO_RETRY = [408, 429, 500, 502, 503, 504];\nconst ERROR_CODES_TO_RETRY = [\n  'ECONNRESET',\n  'ECONNREFUSED',\n  'EPIPE',\n  'ETIMEDOUT',\n  'UND_ERR_CONNECT_TIMEOUT',\n  'UND_ERR_HEADERS_TIMEOUT',\n  'UND_ERR_HEADERS_TIMEOUT',\n  'UND_ERR_SOCKET',\n];\n\n/**\n * Optional parameter that can be passed to the client methods. It allows\n * overriding the access token or project ID, and setting various headers,\n * such as 'Content-Type'.\n */\nexport interface OystehrClientRequest {\n  /**\n   * The access token to use for the request. If not provided, the access token from `oystehr.init()` will be used.\n   */\n  accessToken?: string;\n  /**\n   * The project ID to use for the request. If not provided, the project ID from `oystehr.init()` will be used.\n   */\n  projectId?: string;\n  /**\n   * The value of the 'Content-Type' header to use for the request.\n   */\n  contentType?: string;\n  /**\n   * Unique identifier for this request.\n   */\n  requestId?: string;\n}\n\ninterface InternalClientRequest extends OystehrClientRequest {\n  ifMatch?: string;\n}\n\ntype FhirData<T extends FhirResource> = T | T[] | FhirBundle<T>;\nexport type FhirFetcherResponse<T extends FhirData<FhirResource> = any> = T;\n\nexport class SDKResource {\n  protected readonly config: OystehrConfig;\n  constructor(config: OystehrConfig) {\n    this.config = config;\n  }\n\n  protected request(path: string, method: string, baseUrlThunk: () => string): FetcherFunction {\n    return async (params: any, request?: InternalClientRequest): Promise<FetcherResponse> => {\n      const configThunk = (): OystehrConfig => this.config;\n      try {\n        return await fetcher(baseUrlThunk, configThunk, path, method)(params, request);\n      } catch (err: any) {\n        const error = err as { message: string; code: number; cause?: unknown };\n        throw new OystehrSdkError({ message: error.message, code: error.code, cause: error.cause });\n      }\n    };\n  }\n\n  protected fhirRequest<T extends FhirResource = any>(path: string, method: string) {\n    return async (params: any, request?: InternalClientRequest): Promise<FhirFetcherResponse<T>> => {\n      try {\n        const baseUrlThunk = (): string => this.config.services?.fhirApiUrl ?? defaultFhirApiUrl;\n        const configThunk = (): OystehrConfig => this.config;\n        // must await here to catch\n        return await fetcher(baseUrlThunk, configThunk, path, method)(params, request);\n      } catch (err: unknown) {\n        // FHIR API error messages are JSON strings\n        const fullError = err as { message: string | Record<string, any>; code: number; cause?: unknown };\n        if (typeof fullError.message === 'string') {\n          throw new OystehrSdkError({\n            message: fullError.message,\n            code: fullError.code,\n            cause: fullError.cause,\n          });\n        }\n        throw new OystehrFHIRError({\n          error: fullError.message as OperationOutcome,\n          code: fullError.code,\n        });\n      }\n    };\n  }\n}\n\nexport type FetcherError = { message: string; code: number };\nexport type FetcherResponse = any;\nexport type FetcherFunction = (\n  params?: Record<string, any> | [any] | InternalClientRequest,\n  request?: InternalClientRequest\n) => Promise<FetcherResponse>;\n\nfunction isInternalClientRequest(request: Record<string, any>): request is InternalClientRequest {\n  return 'accessToken' in request;\n}\n\nfunction fetcher(\n  baseUrlThunk: () => string,\n  configThunk: () => OystehrConfig,\n  path: string,\n  methodParam: string\n): FetcherFunction {\n  return async (\n    params?: Record<string, unknown> | [any] | InternalClientRequest,\n    request?: InternalClientRequest\n  ): Promise<FetcherResponse> => {\n    // this function supports multiple signatures. fetcher(baseUrl, path, method)(params, request) or fetcher(baseUrl, path, method)(request)\n    // or fetcher(baseUrl, path, method)(params) or fetcher(baseUrl, path, method)(). the types for this are handled by Client<Path, Methods>\n    // and this is the backend implementation behind it. the heuristic we're using is that if the first param is an object with an accessToken\n    // and there is no second param, assume the first one is the request object instead\n    const providedParams: Record<string, unknown> | [any] =\n      !!params && !request && !Array.isArray(params) && isInternalClientRequest(params)\n        ? {}\n        : (params as Record<string, unknown>) ?? {};\n    const requestCtx =\n      !!params && !request && !Array.isArray(params) && isInternalClientRequest(params)\n        ? (params as InternalClientRequest)\n        : request;\n    const method = methodParam.toLowerCase() as HttpMethod;\n    const config = configThunk();\n    const fetchImpl = config.fetch ?? fetch;\n    const accessToken = requestCtx?.accessToken ?? config.accessToken;\n    const projectId = requestCtx?.projectId ?? configThunk().projectId;\n    let finalPath = path;\n    let finalParams = providedParams;\n    if (!Array.isArray(providedParams)) {\n      const [subbedPath, addlParams] = subParamsInPath(path, providedParams);\n      finalPath = subbedPath;\n      finalParams = addlParams;\n    }\n    finalPath = finalPath.replace(/^\\//, ''); // remove leading slash\n    const baseUrlEvaluated = baseUrlThunk();\n    const fullBaseUrl = baseUrlEvaluated.endsWith('/') ? baseUrlEvaluated : baseUrlEvaluated + '/';\n    const url = new URL(finalPath, fullBaseUrl);\n    let body: any;\n\n    if (Array.isArray(finalParams)) {\n      body = JSON.stringify(finalParams);\n    } else if (Object.keys(finalParams).length) {\n      if (method === 'get') {\n        addParamsToSearch(finalParams, url.searchParams);\n      } else if (requestCtx?.contentType === 'application/x-www-form-urlencoded') {\n        const search = new URLSearchParams();\n        addParamsToSearch(finalParams, search);\n        body = search.toString();\n      } else {\n        body = JSON.stringify(finalParams);\n      }\n    } else {\n      // override for rpc call\n      if (requestCtx?.contentType !== 'application/x-www-form-urlencoded' && method === 'post') {\n        body = '{}';\n      }\n    }\n\n    const headers: Record<string, string> = Object.assign(\n      projectId\n        ? {\n            'x-zapehr-project-id': projectId,\n            'x-oystehr-project-id': projectId,\n          }\n        : {},\n      {\n        'content-type': requestCtx?.contentType ?? 'application/json',\n      },\n      accessToken ? { Authorization: `Bearer ${accessToken}` } : {},\n      requestCtx?.ifMatch ? { 'If-Match': requestCtx.ifMatch } : {},\n      { 'x-oystehr-request-id': requestCtx?.requestId ?? uuidv4() }\n    );\n    const retryConfig: ConstructedRetryConfig = {\n      retries: config.retry?.retries ?? 3,\n      jitter: config.retry?.jitter ?? 20,\n      delay: config.retry?.delay ?? 100,\n      onRetry: config.retry?.onRetry,\n      // Using array instead of set because the length is too short for uniqueness to be important\n      retryOn: [...(config.retry?.retryOn ?? []), ...STATUS_CODES_TO_RETRY],\n    };\n    retryConfig.retryOn.push(...STATUS_CODES_TO_RETRY);\n    return retry(async () => {\n      const response = await fetchImpl(\n        new Request(url, {\n          method: method.toUpperCase(),\n          body,\n          headers,\n        })\n      );\n      const responseBody = response.body ? await response.text() : null;\n      let responseJson: Record<string, unknown> | null;\n      try {\n        responseJson =\n          responseBody &&\n          (response.headers.get('content-type')?.includes('application/json') ||\n            response.headers.get('content-type')?.includes('application/fhir+json'))\n            ? JSON.parse(responseBody)\n            : null;\n      } catch (_err) {\n        // ignore JSON.parse errors\n        responseJson = null;\n      }\n      const isError = !response.ok || response.status >= 400;\n      if (isError) {\n        const errObj = {\n          message:\n            (responseJson?.output as Record<string, unknown>)?.message ?? // official zambda output format\n            responseJson?.message ?? // normal endpoint output format\n            responseJson ?? // parsable json\n            responseBody ?? // raw response\n            response.statusText, // fallback to status text\n          code:\n            (responseJson?.output as Record<string, unknown>)?.code ?? // official zambda output format\n            responseJson?.code ?? // normal endpoint output format\n            response.status, // fallback to status code\n          response,\n        };\n        throw errObj;\n      }\n      return responseJson;\n    }, retryConfig);\n  };\n}\n\ntype ConstructedRetryConfig = Omit<NonNullable<OystehrConfig['retry']>, 'retryOn'> & {\n  jitter: NonNullable<NonNullable<OystehrConfig['retry']>['jitter']>;\n  delay: NonNullable<NonNullable<OystehrConfig['retry']>['delay']>;\n  retryOn: NonNullable<NonNullable<OystehrConfig['retry']>['retryOn']>;\n};\nasync function retry<T>(work: (attempt: number) => Promise<T>, config: ConstructedRetryConfig): Promise<T> {\n  let lastErr;\n  for (const attempt of Array.from({ length: (config.retries ?? 0) + 1 }, (_, index) => index)) {\n    try {\n      return await work(attempt);\n    } catch (e: any) {\n      let isRetryable = false;\n      if ('response' in e) {\n        // error from API\n        const err = e as FetcherError;\n        isRetryable = config.retryOn.includes(err.code);\n        // Removes response\n        lastErr = { message: e.message, code: e.code };\n      } else {\n        lastErr = e;\n        // error from fetch\n        if ('code' in e && typeof e.code === 'string') {\n          const err = e as { code: string };\n          isRetryable = ERROR_CODES_TO_RETRY.includes(err.code);\n        }\n      }\n      if (!isRetryable) {\n        break;\n      }\n      const jitter = Math.floor(Math.random() * (config.jitter + 1));\n      await new Promise((resolve) => setTimeout(resolve, config.delay + jitter));\n      if (config.onRetry && attempt !== (config.retries ?? 0)) {\n        config.onRetry(attempt + 1);\n      }\n    }\n  }\n  throw lastErr;\n}\n\n/**\n * Substitutes params in a path and returns the path with params substituted and any unused params.\n *\n * Uses the property names in the params object to determine the param to substitute in the path.\n *\n * @param path JSON API resource URI\n * @param params all params provided to the client method\n * @returns resource URI with params substituted and any unused params\n */\nfunction subParamsInPath(path: string, params: Record<string, unknown>): [string, Record<string, string>] {\n  const unusedParams = { ...params };\n  // capture everything of the form `{paramName}` and replace with the value of `params[paramName]`\n  const subbedPath = path.replace(/\\{([^}]+)\\}/g, (_, paramName) => {\n    delete unusedParams[paramName];\n    // override for path params that are paths, indicated by a `+` at the end\n    if (paramName.match(/^.*\\+$/)) {\n      return params[paramName] + '';\n    }\n    // error if param value is empty\n    if (!params[paramName] || params[paramName] === '') {\n      throw new OystehrSdkError({ message: `Required path parameter is an empty string: ${paramName}`, code: 400 });\n    }\n    // encode search params\n    if (params[paramName]) {\n      return encodeURIComponent(params[paramName] + ''); // coerce to string\n    }\n    return '';\n  });\n\n  const unusedKeys = Object.keys(unusedParams);\n  const addlParams = unusedKeys.length\n    ? unusedKeys.reduce((acc, key) => ({ ...acc, [key]: unusedParams[key] }), {})\n    : {};\n  return [subbedPath, addlParams];\n}\n\n/**\n * Adds params to a URLSearchParams object in such a way as to preserve array values.\n * @param params params\n * @param search URLSearchParams object\n */\nexport function addParamsToSearch(params: Record<string, unknown>, search: URLSearchParams): void {\n  for (const [key, value] of Object.entries(params)) {\n    if (Array.isArray(value)) {\n      value.forEach((v) => search.append(key, v as string));\n      continue;\n    }\n    search.append(key, value as string);\n  }\n}\n"],"names":["OystehrSdkError","OystehrFHIRError","uuidv4"],"mappings":";;;;;AAMO,MAAM,oBAAoB,GAAG,oCAAoC;AACxE,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AACxD,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC7D,MAAM,oBAAoB,GAAG;IAC3B,YAAY;IACZ,cAAc;IACd,OAAO;IACP,WAAW;IACX,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,gBAAgB;CACjB,CAAC;MAiCW,WAAW,CAAA;AACH,IAAA,MAAM,CAAgB;AACzC,IAAA,WAAA,CAAY,MAAqB,EAAA;AAC/B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;KACtB;AAES,IAAA,OAAO,CAAC,IAAY,EAAE,MAAc,EAAE,YAA0B,EAAA;AACxE,QAAA,OAAO,OAAO,MAAW,EAAE,OAA+B,KAA8B;YACtF,MAAM,WAAW,GAAG,MAAqB,IAAI,CAAC,MAAM,CAAC;AACrD,YAAA,IAAI;AACF,gBAAA,OAAO,MAAM,OAAO,CAAC,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;aAChF;YAAC,OAAO,GAAQ,EAAE;gBACjB,MAAM,KAAK,GAAG,GAAyD,CAAC;gBACxE,MAAM,IAAIA,qBAAe,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;aAC7F;AACH,SAAC,CAAC;KACH;IAES,WAAW,CAA+B,IAAY,EAAE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