@oystehr/sdk 3.0.5 → 3.0.6
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/dist/cjs/index.cjs +51 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/cjs/index.min.cjs.map +1 -1
- package/dist/cjs/resources/classes/erx.d.ts +9 -1
- package/dist/cjs/resources/classes/fax.d.ts +30 -0
- package/dist/cjs/resources/classes/index.d.ts +2 -0
- package/dist/cjs/resources/classes/rcm.d.ts +1 -1
- package/dist/cjs/resources/types/ErxCancelOrderParams.d.ts +6 -0
- package/dist/cjs/resources/types/ErxCancelOrderResponse.d.ts +6 -0
- package/dist/cjs/resources/types/ErxCancelPrescriptionParams.d.ts +6 -0
- package/dist/cjs/resources/types/ErxCancelPrescriptionResponse.d.ts +6 -0
- package/dist/cjs/resources/types/FaxSendParams.d.ts +18 -0
- package/dist/cjs/resources/types/FaxSendResponse.d.ts +10 -0
- package/dist/cjs/resources/types/index.d.ts +6 -0
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/resources/classes/erx.d.ts +9 -1
- package/dist/esm/resources/classes/erx.js +12 -0
- package/dist/esm/resources/classes/erx.js.map +1 -1
- package/dist/esm/resources/classes/fax.d.ts +30 -0
- package/dist/esm/resources/classes/fax.js +41 -0
- package/dist/esm/resources/classes/fax.js.map +1 -0
- package/dist/esm/resources/classes/index.d.ts +2 -0
- package/dist/esm/resources/classes/index.js +2 -0
- package/dist/esm/resources/classes/index.js.map +1 -1
- package/dist/esm/resources/classes/rcm.d.ts +1 -1
- package/dist/esm/resources/classes/rcm.js +1 -1
- package/dist/esm/resources/classes/rcm.js.map +1 -1
- package/dist/esm/resources/types/ErxCancelOrderParams.d.ts +6 -0
- package/dist/esm/resources/types/ErxCancelOrderResponse.d.ts +6 -0
- package/dist/esm/resources/types/ErxCancelPrescriptionParams.d.ts +6 -0
- package/dist/esm/resources/types/ErxCancelPrescriptionResponse.d.ts +6 -0
- package/dist/esm/resources/types/FaxSendParams.d.ts +18 -0
- package/dist/esm/resources/types/FaxSendResponse.d.ts +10 -0
- package/dist/esm/resources/types/index.d.ts +6 -0
- package/package.json +2 -2
- package/src/resources/classes/erx.ts +19 -0
- package/src/resources/classes/fax.ts +41 -0
- package/src/resources/classes/index.ts +3 -0
- package/src/resources/classes/rcm.ts +1 -1
- package/src/resources/types/ErxCancelOrderParams.ts +8 -0
- package/src/resources/types/ErxCancelOrderResponse.ts +8 -0
- package/src/resources/types/ErxCancelPrescriptionParams.ts +8 -0
- package/src/resources/types/ErxCancelPrescriptionResponse.ts +8 -0
- package/src/resources/types/FaxSendParams.ts +20 -0
- package/src/resources/types/FaxSendResponse.ts +12 -0
- package/src/resources/types/index.ts +6 -0
- /package/dist/cjs/tests/{common.d.ts → integrational/common.d.ts} +0 -0
- /package/dist/esm/tests/{common.d.ts → integrational/common.d.ts} +0 -0
package/dist/cjs/index.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("uuid");class t extends Error{constructor({message:e,code:r}){super(e),Object.setPrototypeOf(this,t.prototype),this.code=r,this.name="OystehrSdkError"}toString(){return`${this.name}: ${this.message} (code: ${this.code})`}}function r(e){var t;const r=[];for(const s of null!==(t=e.issue)&&void 0!==t?t:[])s.details&&s.details.text&&r.push(s.details.text);return r.length||r.push("Unknown FHIR error"),r.join(",")}class s extends t{constructor({error:e,code:t}){super({message:r(e),code:t}),Object.setPrototypeOf(this,s.prototype),this.cause=e,this.name="OystehrFHIRError"}}function i(e,t,r,s){return new(r||(r=Promise))((function(i,n){function o(e){try{c(s.next(e))}catch(e){n(e)}}function u(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,u)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n="https://project-api.zapehr.com/v1",o=[408,429,500,502,503,504],u=["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"];class c{constructor(e){this.config=e}request(e,r){return(s,o)=>i(this,void 0,void 0,(function*(){const i=()=>{var e;return null!==(e=this.config.projectApiUrl)&&void 0!==e?e:n},u=()=>this.config;try{return yield l(i,u,e,r)(s,o)}catch(e){const r=e;throw new t({message:r.message,code:r.code})}}))}fhirRequest(e,r){return(n,o)=>i(this,void 0,void 0,(function*(){try{const t=()=>{var e;return null!==(e=this.config.fhirApiUrl)&&void 0!==e?e:"https://fhir-api.zapehr.com"},s=()=>this.config;return yield l(t,s,e,r)(n,o)}catch(e){const r=e;if("string"==typeof r.message)throw new t({message:r.message,code:r.code});throw new s({error:r.message,code:r.code})}}))}}function a(e){return"accessToken"in e}function l(r,s,n,c){return(l,h)=>i(this,void 0,void 0,(function*(){var p,m,v,f,g,y,q,b,j,w,O,x,T,E,S;const k=l&&!h&&!Array.isArray(l)&&a(l)?{}:null!==(p=l)&&void 0!==p?p:{},R=l&&!h&&!Array.isArray(l)&&a(l)?l:h,U=c.toLowerCase(),P=s(),N=null!==(m=P.fetch)&&void 0!==m?m:fetch,z=null!==(v=null==R?void 0:R.accessToken)&&void 0!==v?v:P.accessToken,I=null!==(f=null==R?void 0:R.projectId)&&void 0!==f?f:s().projectId;let $=n,A=k;if(!Array.isArray(k)){const[e,r]=function(e,r){const s=Object.assign({},r),i=e.replace(/\{([^}]+)\}/g,((e,i)=>{if(delete s[i],i.match(/^.*\+$/))return r[i]+"";if(!r[i]||""===r[i])throw new t({message:`Required path parameter is an empty string: ${i}`,code:400});return r[i]?encodeURIComponent(r[i]+""):""})),n=Object.keys(s),o=n.length?n.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t]:s[t]})),{}):{};return[i,o]}(n,k);$=e,A=r}$=$.replace(/^\//,"");const C=r(),_=C.endsWith("/")?C:C+"/",L=new URL($,_);let M;if(Array.isArray(A))M=JSON.stringify(A);else if(Object.keys(A).length)if("get"===U)d(A,L.searchParams);else if("application/x-www-form-urlencoded"===(null==R?void 0:R.contentType)){const e=new URLSearchParams;d(A,e),M=e.toString()}else M=JSON.stringify(A);else"application/x-www-form-urlencoded"!==(null==R?void 0:R.contentType)&&"post"===U&&(M="{}");const D=Object.assign(I?{"x-zapehr-project-id":I,"x-oystehr-project-id":I}:{},{"content-type":null!==(g=null==R?void 0:R.contentType)&&void 0!==g?g:"application/json"},z?{Authorization:`Bearer ${z}`}:{},(null==R?void 0:R.ifMatch)?{"If-Match":R.ifMatch}:{},{"x-oystehr-request-id":null!==(y=null==R?void 0:R.requestId)&&void 0!==y?y:e.v4()}),V={retries:null!==(b=null===(q=P.retry)||void 0===q?void 0:q.retries)&&void 0!==b?b:3,jitter:null!==(w=null===(j=P.retry)||void 0===j?void 0:j.jitter)&&void 0!==w?w:20,delay:null!==(x=null===(O=P.retry)||void 0===O?void 0:O.delay)&&void 0!==x?x:100,onRetry:null===(T=P.retry)||void 0===T?void 0:T.onRetry,retryOn:[...null!==(S=null===(E=P.retry)||void 0===E?void 0:E.retryOn)&&void 0!==S?S:[],...o]};return V.retryOn.push(...o),function(e,t){var r,s;return i(this,void 0,void 0,(function*(){let i;for(const n of Array.from({length:(null!==(r=t.retries)&&void 0!==r?r:0)+1},((e,t)=>t)))try{return yield e(n)}catch(e){let r=!1;if("response"in e){const s=e;r=t.retryOn.includes(s.code),i={message:e.message,code:e.code}}else if(i=e,"code"in e&&"string"==typeof e.code){const t=e;r=u.includes(t.code)}if(!r)break;const o=Math.floor(Math.random()*(t.jitter+1));yield new Promise((e=>setTimeout(e,t.delay+o))),t.onRetry&&n!==(null!==(s=t.retries)&&void 0!==s?s:0)&&t.onRetry(n+1)}throw i}))}((()=>i(this,void 0,void 0,(function*(){var e,t,r,s,i,n;const o=yield N(new Request(L,{method:U.toUpperCase(),body:M,headers:D})),u=o.body?yield o.text():null;let c;try{c=u&&((null===(e=o.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))||(null===(t=o.headers.get("content-type"))||void 0===t?void 0:t.includes("application/fhir+json")))?JSON.parse(u):null}catch(e){c=null}if(!o.ok||o.status>=400){throw{message:null!==(i=null!==(s=null!==(r=null==c?void 0:c.message)&&void 0!==r?r:c)&&void 0!==s?s:u)&&void 0!==i?i:o.statusText,code:null!==(n=null==c?void 0:c.code)&&void 0!==n?n:o.status,response:o}}return c}))),V)}))}function d(e,t){for(const[r,s]of Object.entries(e))Array.isArray(s)?s.forEach((e=>t.append(r,e))):t.append(r,s)}class h extends c{constructor(e){super(e)}list(e){return this.request("/application","get")(e)}create(e,t){return this.request("/application","post")(e,t)}get(e,t){return this.request("/application/{id}","get")(e,t)}update(e,t){return this.request("/application/{id}","patch")(e,t)}delete(e,t){return this.request("/application/{id}","delete")(e,t)}rotateSecret(e,t){return this.request("/application/{id}/rotate-secret","post")(e,t)}revokeRefreshToken(e,t){return this.request("/application/{id}/revoke-refresh-token","post")(e,t)}revokeAccessToken(e,t){return this.request("/application/{id}/revoke-access-token","post")(e,t)}}class p extends c{constructor(e){super(e)}issue(e,t){return this.request("/payment/charge/issue","post")(e,t)}status(e,t){return this.request("/payment/charge/status","post")(e,t)}}const m="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",v="addressString";function f(e){var t,r,s;if(function(e){return Object.hasOwn(e,"virtualService")}(e)){const r=null===(t=e.virtualService)||void 0===t?void 0:t.find((e=>{var t;return"https://fhir.zapehr.com/virtual-service-type"===(null===(t=e.channelType)||void 0===t?void 0:t.system)}));return null==r?void 0:r.addressString}if(!e.extension)return;const i=e.extension.find((e=>e.url===m));if(!(null==i?void 0:i.extension))return;return null===(s=null===(r=i.extension)||void 0===r?void 0:r.find((e=>e.url===v)))||void 0===s?void 0:s.valueString}class g extends c{constructor(e){super(e),this.ENCOUNTER_VS_EXTENSION_URL=m,this.ENCOUNTER_VS_EXTENSION_RELATIVE_URL=v,this.getConversationIdFromEncounter=f}create(e,t){return this.request("/messaging/conversation","post")(e,t)}getToken(e){return this.request("/messaging/conversation/token","get")(e)}addParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","post")(e,t)}removeParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","delete")(e,t)}message(e,t){return this.request("/messaging/conversation/{conversationId}/message","post")(e,t)}}class y extends c{constructor(e){super(e)}get(e,t){return this.request("/developer/{id}","get")(e,t)}update(e,t){return this.request("/developer/{id}","patch")(e,t)}delete(e,t){return this.request("/developer/{id}","delete")(e,t)}invite(e,t){return this.request("/developer/invite","post")(e,t)}list(e){return this.request("/developer","get")(e)}listV2(e,t){return this.request("/developer/v2/list","get")(e,t)}}class q extends c{constructor(e){super(e)}syncPatient(e,t){return this.request("/erx/sync-patient/{patientId}","post")(e,t)}allergySearch(e,t){return this.request("/erx/allergy/search","get")(e,t)}medicationSearch(e,t){return this.request("/erx/medication/search","get")(e,t)}medicationSearchV2(e,t){return this.request("/erx/v2/medication/search","get")(e,t)}}function b(e,t){return i(this,void 0,void 0,(function*(){const{resourceType:r,params:s}=e;let i;s&&(i=Object.entries(s).reduce(((e,[t,r])=>(e[r.name]||(e[r.name]=[]),e[r.name].push(r.value),e)),{}));const n=yield this.fhirRequest(`/${r}/_search`,"POST")(i,Object.assign(Object.assign({},t),{contentType:"application/x-www-form-urlencoded"}));return Object.assign(Object.assign({},n),{entry:n.entry,unbundle:function(){var e,t;return null!==(t=null===(e=this.entry)||void 0===e?void 0:e.map((e=>e.resource)).filter((e=>void 0!==e)))&&void 0!==t?t:[]}})}))}function j(e,t){return i(this,void 0,void 0,(function*(){const{resourceType:r}=e;return this.fhirRequest(`/${r}`,"POST")(e,t)}))}function w({resourceType:e,id:t},r){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}`,"GET")({},r)}))}function O(e,t){return i(this,void 0,void 0,(function*(){const{id:r,resourceType:s}=e;return this.fhirRequest(`/${s}/${r}`,"PUT")(e,Object.assign(Object.assign({},t),{ifMatch:(null==t?void 0:t.optimisticLockingVersionId)?`W/"${t.optimisticLockingVersionId}"`:void 0}))}))}function x({resourceType:e,id:t,operations:r},s){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}`,"PATCH")(r,Object.assign(Object.assign({},s),{contentType:"application/json-patch+json",ifMatch:(null==s?void 0:s.optimisticLockingVersionId)?`W/"${s.optimisticLockingVersionId}"`:void 0}))}))}function T({resourceType:e,id:t},r){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}`,"DELETE")({},r)}))}function E({resourceType:e,id:t,versionId:r},s){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}/_history${r?`/${r}`:""}`,"GET")({},s)}))}function S(e){const{method:t,url:r}=e,s={request:{method:t,url:r}};if(r.split("?").length>1){const[e,t]=r.split("?"),i=t.split("&").map((e=>{const[t,r]=e.split("=");return{name:t,value:r}})).reduce(((e,{name:t,value:r})=>t?(e[t]||(e[t]=[]),e[t].push(r),e):e),{}),n=new URLSearchParams;d(i,n),s.request.url=`${e}?${n.toString()}`}if(["GET","DELETE","HEAD"].includes(t))return s;if("PUT"===t){const{resource:t}=e;return Object.assign(Object.assign({},s),{resource:t})}if("PATCH"===t)return"resource"in e?Object.assign(Object.assign({},s),{resource:e.resource}):Object.assign(Object.assign({},s),{resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:Buffer.from(JSON.stringify(e.operations),"utf8").toString("base64")}});if("POST"===t){const{resource:t,fullUrl:r}=e;return Object.assign(Object.assign({},s),{resource:t,fullUrl:r})}throw new Error("Unrecognized method")}function k(e){return function(t,r){return i(this,void 0,void 0,(function*(){return this.fhirRequest("/","POST")({resourceType:"Bundle",type:e,entry:t.requests.map(S)},r)}))}}const R=k("batch"),U=k("transaction");function P(e,t){const r=[];if(e.line&&r.push(...e.line),e.city||e.state||e.postalCode){const t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),r.push(t.join(", "))}return e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&r.push("["+e.use+"]"),r.join((null==t?void 0:t.lineSeparator)||", ").trim()}function N(e,t){const r=[];return e.prefix&&!1!==(null==t?void 0:t.prefix)&&r.push(...e.prefix),e.given&&r.push(...e.given),e.family&&r.push(e.family),e.suffix&&!1!==(null==t?void 0:t.suffix)&&r.push(...e.suffix),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&r.push("["+e.use+"]"),r.join(" ").trim()}class z extends c{constructor(e){super(e),this.search=b,this.create=j,this.get=w,this.update=O,this.patch=x,this.delete=T,this.history=E,this.batch=R,this.transaction=U,this.formatAddress=P,this.formatHumanName=N}}class I extends c{constructor(e){super(e)}list(e){return this.request("/m2m","get")(e)}create(e,t){return this.request("/m2m","post")(e,t)}get(e,t){return this.request("/m2m/{id}","get")(e,t)}update(e,t){return this.request("/m2m/{id}","patch")(e,t)}delete(e,t){return this.request("/m2m/{id}","delete")(e,t)}rotateSecret(e,t){return this.request("/m2m/{id}/rotate-secret","post")(e,t)}listV2(e,t){return this.request("/m2m/v2/list","get")(e,t)}}class $ extends c{constructor(e){super(e)}getMessagingConfig(e){return this.request("/messaging/config","get")(e)}}class A extends c{constructor(e){super(e)}setUp(e,t){return this.request("/payment/payment-method/setup","post")(e,t)}setDefault(e,t){return this.request("/payment/payment-method/set-default","post")(e,t)}delete(e,t){return this.request("/payment/payment-method","delete")(e,t)}list(e,t){return this.request("/payment/payment-method/list","post")(e,t)}}class C extends c{constructor(e){super(e)}get(e){return this.request("/project","get")(e)}update(e,t){return this.request("/project","patch")(e,t)}}class _ extends c{constructor(e){super(e)}eligibilityCheck(e,t){return this.request("/rcm/eligibility-check","post")(e,t)}validateProfessionalClaim(e,t){return this.request("/rcm/professional-claim/validate","post")(e,t)}submitProfessionalClaim(e,t){return this.request("/rcm/professional-claim/submit","post")(e,t)}}class L extends c{constructor(e){super(e)}list(e){return this.request("/iam/role","get")(e)}create(e,t){return this.request("/iam/role","post")(e,t)}get(e,t){return this.request("/iam/role/{roleId}","get")(e,t)}update(e,t){return this.request("/iam/role/{roleId}","patch")(e,t)}delete(e,t){return this.request("/iam/role/{roleId}","delete")(e,t)}}class M extends c{constructor(e){super(e)}list(e){return this.request("/secret","get")(e)}set(e,t){return this.request("/secret","post")(e,t)}get(e,t){return this.request("/secret/{name}","get")(e,t)}delete(e,t){return this.request("/secret/{name}","delete")(e,t)}}class D extends c{constructor(e){super(e)}createMeeting(e,t){return this.request("/telemed/v2/meeting","post")(e,t)}joinMeeting(e,t){return this.request("/telemed/v2/meeting/{encounterId}/join","get")(e,t)}}class V extends c{constructor(e){super(e)}send(e,t){return this.request("/messaging/transactional-sms/send","post")(e,t)}}class F extends c{constructor(e){super(e)}me(e){return this.request("/user/me","get")(e)}get(e,t){return this.request("/user/{id}","get")(e,t)}update(e,t){return this.request("/user/{id}","patch")(e,t)}delete(e,t){return this.request("/user/{id}","delete")(e,t)}invite(e,t){return this.request("/user/invite","post")(e,t)}list(e){return this.request("/user","get")(e)}listV2(e,t){return this.request("/user/v2/list","get")(e,t)}}class H extends c{constructor(e){super(e)}get(e){return this.request("/version","get")(e)}}function B({bucketName:e,"objectPath+":t,file:r}){return i(this,void 0,void 0,(function*(){const s=yield this.request("/z3/{bucketName}/{objectPath+}","post")({action:"upload",bucketName:e,"objectPath+":t});yield fetch(s.signedUrl,{method:"PUT",body:r})}))}function G({bucketName:e,"objectPath+":t}){return i(this,void 0,void 0,(function*(){const r=yield this.request("/z3/{bucketName}/{objectPath+}","post")({action:"download",bucketName:e,"objectPath+":t}),s=yield fetch(r.signedUrl,{method:"GET"});if(!s.ok)throw new Error("Failed to download file");return s.arrayBuffer()}))}function J(e){var r;return i(this,void 0,void 0,(function*(){let s,i;const o=new URL(e.url);if("z3:"===o.protocol){const e=o.pathname.split("/").slice(1);s=o.hostname,i=e.join("/")}else{if(!o.href.startsWith(null!==(r=this.config.projectApiUrl)&&void 0!==r?r:n))throw new t({message:"Invalid Z3 URL",code:400});{const e=o.pathname.split("/").slice(3);s=e[0],i=e.slice(1).join("/")}}const u={action:"upload",bucketName:s,"objectPath+":i};return this.request("/z3/{bucketName}/{objectPath+}","post")(u)}))}class W extends c{constructor(e){super(e),this.uploadFile=B,this.downloadFile=G,this.getPresignedUrlForZ3Url=J}listBuckets(e){return this.request("/z3","get")(e)}createBucket(e,t){return this.request("/z3/{bucketName}","put")(e,t)}deleteBucket(e,t){return this.request("/z3/{bucketName}","delete")(e,t)}listObjects(e,t){return this.request("/z3/{bucketName}/{objectPath+}","get")(e,t)}getPresignedUrl(e,t){return this.request("/z3/{bucketName}/{objectPath+}","post")(e,t)}deleteObject(e,t){return this.request("/z3/{bucketName}/{objectPath+}","delete")(e,t)}}function X({id:e,file:t,filename:r}){return i(this,void 0,void 0,(function*(){const s=yield this.request("/zambda/{id}/s3-upload","post")({id:e,filename:r});yield fetch(s.signedUrl,{method:"PUT",body:t})}))}class Z extends c{constructor(e){super(e),this.uploadFile=X}list(e){return this.request("/zambda","get")(e)}create(e,t){return this.request("/zambda","post")(e,t)}get(e,t){return this.request("/zambda/{id}","get")(e,t)}update(e,t){return this.request("/zambda/{id}","patch")(e,t)}delete(e,t){return this.request("/zambda/{id}","delete")(e,t)}execute(e,t){return this.request("/zambda/{id}/execute","post")(e,t)}executePublic(e,t){return this.request("/zambda/{id}/execute-public","post")(e,t)}s3Upload(e,t){return this.request("/zambda/{id}/s3-upload","post")(e,t)}}class K extends c{constructor(e){super(e)}list(e,t){return this.request("/zambda/{id}/logStream","post")(e,t)}search(e,t){return this.request("/zambda/{id}/logStream/search","post")(e,t)}get(e,t){return this.request("/zambda/{id}/logStream/{logStreamName}","post")(e,t)}}let Q=class{constructor(e){this.config=e,this.application=new h(e),this.developer=new y(e),this.m2m=new I(e),this.messaging=new $(e),this.conversation=new g(e),this.transactionalSMS=new V(e),this.paymentMethod=new A(e),this.charge=new p(e),this.project=new C(e),this.rcm=new _(e),this.erx=new q(e),this.role=new L(e),this.secret=new M(e),this.telemed=new D(e),this.user=new F(e),this.version=new H(e),this.z3=new W(e),this.zambda=new Z(e),this.zambdaLogStream=new K(e),this.fhir=new z(e)}};class Y extends Q{}Y.OystehrFHIRError=s,Y.OystehrSdkError=t,module.exports=Y;
|
|
1
|
+
"use strict";var e=require("uuid");class t extends Error{constructor({message:e,code:r}){super(e),Object.setPrototypeOf(this,t.prototype),this.code=r,this.name="OystehrSdkError"}toString(){return`${this.name}: ${this.message} (code: ${this.code})`}}function r(e){var t;const r=[];for(const s of null!==(t=e.issue)&&void 0!==t?t:[])s.details&&s.details.text&&r.push(s.details.text);return r.length||r.push("Unknown FHIR error"),r.join(",")}class s extends t{constructor({error:e,code:t}){super({message:r(e),code:t}),Object.setPrototypeOf(this,s.prototype),this.cause=e,this.name="OystehrFHIRError"}}function i(e,t,r,s){return new(r||(r=Promise))((function(i,n){function o(e){try{c(s.next(e))}catch(e){n(e)}}function u(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,u)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n="https://project-api.zapehr.com/v1",o=[408,429,500,502,503,504],u=["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"];class c{constructor(e){this.config=e}request(e,r){return(s,o)=>i(this,void 0,void 0,(function*(){const i=()=>{var e;return null!==(e=this.config.projectApiUrl)&&void 0!==e?e:n},u=()=>this.config;try{return yield d(i,u,e,r)(s,o)}catch(e){const r=e;throw new t({message:r.message,code:r.code})}}))}fhirRequest(e,r){return(n,o)=>i(this,void 0,void 0,(function*(){try{const t=()=>{var e;return null!==(e=this.config.fhirApiUrl)&&void 0!==e?e:"https://fhir-api.zapehr.com"},s=()=>this.config;return yield d(t,s,e,r)(n,o)}catch(e){const r=e;if("string"==typeof r.message)throw new t({message:r.message,code:r.code});throw new s({error:r.message,code:r.code})}}))}}function a(e){return"accessToken"in e}function d(r,s,n,c){return(d,h)=>i(this,void 0,void 0,(function*(){var p,m,f,v,g,y,q,b,j,x,w,O,T,E,S;const k=d&&!h&&!Array.isArray(d)&&a(d)?{}:null!==(p=d)&&void 0!==p?p:{},R=d&&!h&&!Array.isArray(d)&&a(d)?d:h,P=c.toLowerCase(),U=s(),N=null!==(m=U.fetch)&&void 0!==m?m:fetch,z=null!==(f=null==R?void 0:R.accessToken)&&void 0!==f?f:U.accessToken,I=null!==(v=null==R?void 0:R.projectId)&&void 0!==v?v:s().projectId;let $=n,A=k;if(!Array.isArray(k)){const[e,r]=function(e,r){const s=Object.assign({},r),i=e.replace(/\{([^}]+)\}/g,((e,i)=>{if(delete s[i],i.match(/^.*\+$/))return r[i]+"";if(!r[i]||""===r[i])throw new t({message:`Required path parameter is an empty string: ${i}`,code:400});return r[i]?encodeURIComponent(r[i]+""):""})),n=Object.keys(s),o=n.length?n.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t]:s[t]})),{}):{};return[i,o]}(n,k);$=e,A=r}$=$.replace(/^\//,"");const C=r(),_=C.endsWith("/")?C:C+"/",L=new URL($,_);let M;if(Array.isArray(A))M=JSON.stringify(A);else if(Object.keys(A).length)if("get"===P)l(A,L.searchParams);else if("application/x-www-form-urlencoded"===(null==R?void 0:R.contentType)){const e=new URLSearchParams;l(A,e),M=e.toString()}else M=JSON.stringify(A);else"application/x-www-form-urlencoded"!==(null==R?void 0:R.contentType)&&"post"===P&&(M="{}");const D=Object.assign(I?{"x-zapehr-project-id":I,"x-oystehr-project-id":I}:{},{"content-type":null!==(g=null==R?void 0:R.contentType)&&void 0!==g?g:"application/json"},z?{Authorization:`Bearer ${z}`}:{},(null==R?void 0:R.ifMatch)?{"If-Match":R.ifMatch}:{},{"x-oystehr-request-id":null!==(y=null==R?void 0:R.requestId)&&void 0!==y?y:e.v4()}),V={retries:null!==(b=null===(q=U.retry)||void 0===q?void 0:q.retries)&&void 0!==b?b:3,jitter:null!==(x=null===(j=U.retry)||void 0===j?void 0:j.jitter)&&void 0!==x?x:20,delay:null!==(O=null===(w=U.retry)||void 0===w?void 0:w.delay)&&void 0!==O?O:100,onRetry:null===(T=U.retry)||void 0===T?void 0:T.onRetry,retryOn:[...null!==(S=null===(E=U.retry)||void 0===E?void 0:E.retryOn)&&void 0!==S?S:[],...o]};return V.retryOn.push(...o),function(e,t){var r,s;return i(this,void 0,void 0,(function*(){let i;for(const n of Array.from({length:(null!==(r=t.retries)&&void 0!==r?r:0)+1},((e,t)=>t)))try{return yield e(n)}catch(e){let r=!1;if("response"in e){const s=e;r=t.retryOn.includes(s.code),i={message:e.message,code:e.code}}else if(i=e,"code"in e&&"string"==typeof e.code){const t=e;r=u.includes(t.code)}if(!r)break;const o=Math.floor(Math.random()*(t.jitter+1));yield new Promise((e=>setTimeout(e,t.delay+o))),t.onRetry&&n!==(null!==(s=t.retries)&&void 0!==s?s:0)&&t.onRetry(n+1)}throw i}))}((()=>i(this,void 0,void 0,(function*(){var e,t,r,s,i,n;const o=yield N(new Request(L,{method:P.toUpperCase(),body:M,headers:D})),u=o.body?yield o.text():null;let c;try{c=u&&((null===(e=o.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))||(null===(t=o.headers.get("content-type"))||void 0===t?void 0:t.includes("application/fhir+json")))?JSON.parse(u):null}catch(e){c=null}if(!o.ok||o.status>=400){throw{message:null!==(i=null!==(s=null!==(r=null==c?void 0:c.message)&&void 0!==r?r:c)&&void 0!==s?s:u)&&void 0!==i?i:o.statusText,code:null!==(n=null==c?void 0:c.code)&&void 0!==n?n:o.status,response:o}}return c}))),V)}))}function l(e,t){for(const[r,s]of Object.entries(e))Array.isArray(s)?s.forEach((e=>t.append(r,e))):t.append(r,s)}class h extends c{constructor(e){super(e)}list(e){return this.request("/application","get")(e)}create(e,t){return this.request("/application","post")(e,t)}get(e,t){return this.request("/application/{id}","get")(e,t)}update(e,t){return this.request("/application/{id}","patch")(e,t)}delete(e,t){return this.request("/application/{id}","delete")(e,t)}rotateSecret(e,t){return this.request("/application/{id}/rotate-secret","post")(e,t)}revokeRefreshToken(e,t){return this.request("/application/{id}/revoke-refresh-token","post")(e,t)}revokeAccessToken(e,t){return this.request("/application/{id}/revoke-access-token","post")(e,t)}}class p extends c{constructor(e){super(e)}issue(e,t){return this.request("/payment/charge/issue","post")(e,t)}status(e,t){return this.request("/payment/charge/status","post")(e,t)}}const m="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",f="addressString";function v(e){var t,r,s;if(function(e){return Object.hasOwn(e,"virtualService")}(e)){const r=null===(t=e.virtualService)||void 0===t?void 0:t.find((e=>{var t;return"https://fhir.zapehr.com/virtual-service-type"===(null===(t=e.channelType)||void 0===t?void 0:t.system)}));return null==r?void 0:r.addressString}if(!e.extension)return;const i=e.extension.find((e=>e.url===m));if(!(null==i?void 0:i.extension))return;return null===(s=null===(r=i.extension)||void 0===r?void 0:r.find((e=>e.url===f)))||void 0===s?void 0:s.valueString}class g extends c{constructor(e){super(e),this.ENCOUNTER_VS_EXTENSION_URL=m,this.ENCOUNTER_VS_EXTENSION_RELATIVE_URL=f,this.getConversationIdFromEncounter=v}create(e,t){return this.request("/messaging/conversation","post")(e,t)}getToken(e){return this.request("/messaging/conversation/token","get")(e)}addParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","post")(e,t)}removeParticipant(e,t){return this.request("/messaging/conversation/{conversationId}/participant","delete")(e,t)}message(e,t){return this.request("/messaging/conversation/{conversationId}/message","post")(e,t)}}class y extends c{constructor(e){super(e)}get(e,t){return this.request("/developer/{id}","get")(e,t)}update(e,t){return this.request("/developer/{id}","patch")(e,t)}delete(e,t){return this.request("/developer/{id}","delete")(e,t)}invite(e,t){return this.request("/developer/invite","post")(e,t)}list(e){return this.request("/developer","get")(e)}listV2(e,t){return this.request("/developer/v2/list","get")(e,t)}}class q extends c{constructor(e){super(e)}syncPatient(e,t){return this.request("/erx/sync-patient/{patientId}","post")(e,t)}allergySearch(e,t){return this.request("/erx/allergy/search","get")(e,t)}cancelOrder(e,t){return this.request("/erx/cancel-order","post")(e,t)}cancelPrescription(e,t){return this.request("/erx/cancel-prescription","post")(e,t)}medicationSearch(e,t){return this.request("/erx/medication/search","get")(e,t)}medicationSearchV2(e,t){return this.request("/erx/v2/medication/search","get")(e,t)}}class b extends c{constructor(e){super(e)}offboard(e){return this.request("/fax/offboard","post")(e)}onboard(e){return this.request("/fax/onboard","post")(e)}send(e,t){return this.request("/fax/send","post")(e,t)}}function j(e,t){return i(this,void 0,void 0,(function*(){const{resourceType:r,params:s}=e;let i;s&&(i=Object.entries(s).reduce(((e,[t,r])=>(e[r.name]||(e[r.name]=[]),e[r.name].push(r.value),e)),{}));const n=yield this.fhirRequest(`/${r}/_search`,"POST")(i,Object.assign(Object.assign({},t),{contentType:"application/x-www-form-urlencoded"}));return Object.assign(Object.assign({},n),{entry:n.entry,unbundle:function(){var e,t;return null!==(t=null===(e=this.entry)||void 0===e?void 0:e.map((e=>e.resource)).filter((e=>void 0!==e)))&&void 0!==t?t:[]}})}))}function x(e,t){return i(this,void 0,void 0,(function*(){const{resourceType:r}=e;return this.fhirRequest(`/${r}`,"POST")(e,t)}))}function w({resourceType:e,id:t},r){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}`,"GET")({},r)}))}function O(e,t){return i(this,void 0,void 0,(function*(){const{id:r,resourceType:s}=e;return this.fhirRequest(`/${s}/${r}`,"PUT")(e,Object.assign(Object.assign({},t),{ifMatch:(null==t?void 0:t.optimisticLockingVersionId)?`W/"${t.optimisticLockingVersionId}"`:void 0}))}))}function T({resourceType:e,id:t,operations:r},s){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}`,"PATCH")(r,Object.assign(Object.assign({},s),{contentType:"application/json-patch+json",ifMatch:(null==s?void 0:s.optimisticLockingVersionId)?`W/"${s.optimisticLockingVersionId}"`:void 0}))}))}function E({resourceType:e,id:t},r){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}`,"DELETE")({},r)}))}function S({resourceType:e,id:t,versionId:r},s){return i(this,void 0,void 0,(function*(){return this.fhirRequest(`/${e}/${t}/_history${r?`/${r}`:""}`,"GET")({},s)}))}function k(e){const{method:t,url:r}=e,s={request:{method:t,url:r}};if(r.split("?").length>1){const[e,t]=r.split("?"),i=t.split("&").map((e=>{const[t,r]=e.split("=");return{name:t,value:r}})).reduce(((e,{name:t,value:r})=>t?(e[t]||(e[t]=[]),e[t].push(r),e):e),{}),n=new URLSearchParams;l(i,n),s.request.url=`${e}?${n.toString()}`}if(["GET","DELETE","HEAD"].includes(t))return s;if("PUT"===t){const{resource:t}=e;return Object.assign(Object.assign({},s),{resource:t})}if("PATCH"===t)return"resource"in e?Object.assign(Object.assign({},s),{resource:e.resource}):Object.assign(Object.assign({},s),{resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:Buffer.from(JSON.stringify(e.operations),"utf8").toString("base64")}});if("POST"===t){const{resource:t,fullUrl:r}=e;return Object.assign(Object.assign({},s),{resource:t,fullUrl:r})}throw new Error("Unrecognized method")}function R(e){return function(t,r){return i(this,void 0,void 0,(function*(){return this.fhirRequest("/","POST")({resourceType:"Bundle",type:e,entry:t.requests.map(k)},r)}))}}const P=R("batch"),U=R("transaction");function N(e,t){const r=[];if(e.line&&r.push(...e.line),e.city||e.state||e.postalCode){const t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),r.push(t.join(", "))}return e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&r.push("["+e.use+"]"),r.join((null==t?void 0:t.lineSeparator)||", ").trim()}function z(e,t){const r=[];return e.prefix&&!1!==(null==t?void 0:t.prefix)&&r.push(...e.prefix),e.given&&r.push(...e.given),e.family&&r.push(e.family),e.suffix&&!1!==(null==t?void 0:t.suffix)&&r.push(...e.suffix),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&r.push("["+e.use+"]"),r.join(" ").trim()}class I extends c{constructor(e){super(e),this.search=j,this.create=x,this.get=w,this.update=O,this.patch=T,this.delete=E,this.history=S,this.batch=P,this.transaction=U,this.formatAddress=N,this.formatHumanName=z}}class $ extends c{constructor(e){super(e)}list(e){return this.request("/m2m","get")(e)}create(e,t){return this.request("/m2m","post")(e,t)}get(e,t){return this.request("/m2m/{id}","get")(e,t)}update(e,t){return this.request("/m2m/{id}","patch")(e,t)}delete(e,t){return this.request("/m2m/{id}","delete")(e,t)}rotateSecret(e,t){return this.request("/m2m/{id}/rotate-secret","post")(e,t)}listV2(e,t){return this.request("/m2m/v2/list","get")(e,t)}}class A extends c{constructor(e){super(e)}getMessagingConfig(e){return this.request("/messaging/config","get")(e)}}class C extends c{constructor(e){super(e)}setUp(e,t){return this.request("/payment/payment-method/setup","post")(e,t)}setDefault(e,t){return this.request("/payment/payment-method/set-default","post")(e,t)}delete(e,t){return this.request("/payment/payment-method","delete")(e,t)}list(e,t){return this.request("/payment/payment-method/list","post")(e,t)}}class _ extends c{constructor(e){super(e)}get(e){return this.request("/project","get")(e)}update(e,t){return this.request("/project","patch")(e,t)}}class L extends c{constructor(e){super(e)}eligibilityCheck(e,t){return this.request("/rcm/eligibility-check","post")(e,t)}validateProfessionalClaim(e,t){return this.request("/rcm/professional-claim/validate","post")(e,t)}submitProfessionalClaim(e,t){return this.request("/rcm/professional-claim/submit","post")(e,t)}}class M extends c{constructor(e){super(e)}list(e){return this.request("/iam/role","get")(e)}create(e,t){return this.request("/iam/role","post")(e,t)}get(e,t){return this.request("/iam/role/{roleId}","get")(e,t)}update(e,t){return this.request("/iam/role/{roleId}","patch")(e,t)}delete(e,t){return this.request("/iam/role/{roleId}","delete")(e,t)}}class D extends c{constructor(e){super(e)}list(e){return this.request("/secret","get")(e)}set(e,t){return this.request("/secret","post")(e,t)}get(e,t){return this.request("/secret/{name}","get")(e,t)}delete(e,t){return this.request("/secret/{name}","delete")(e,t)}}class V extends c{constructor(e){super(e)}createMeeting(e,t){return this.request("/telemed/v2/meeting","post")(e,t)}joinMeeting(e,t){return this.request("/telemed/v2/meeting/{encounterId}/join","get")(e,t)}}class F extends c{constructor(e){super(e)}send(e,t){return this.request("/messaging/transactional-sms/send","post")(e,t)}}class H extends c{constructor(e){super(e)}me(e){return this.request("/user/me","get")(e)}get(e,t){return this.request("/user/{id}","get")(e,t)}update(e,t){return this.request("/user/{id}","patch")(e,t)}delete(e,t){return this.request("/user/{id}","delete")(e,t)}invite(e,t){return this.request("/user/invite","post")(e,t)}list(e){return this.request("/user","get")(e)}listV2(e,t){return this.request("/user/v2/list","get")(e,t)}}class B extends c{constructor(e){super(e)}get(e){return this.request("/version","get")(e)}}function G({bucketName:e,"objectPath+":t,file:r}){return i(this,void 0,void 0,(function*(){const s=yield this.request("/z3/{bucketName}/{objectPath+}","post")({action:"upload",bucketName:e,"objectPath+":t});yield fetch(s.signedUrl,{method:"PUT",body:r})}))}function J({bucketName:e,"objectPath+":t}){return i(this,void 0,void 0,(function*(){const r=yield this.request("/z3/{bucketName}/{objectPath+}","post")({action:"download",bucketName:e,"objectPath+":t}),s=yield fetch(r.signedUrl,{method:"GET"});if(!s.ok)throw new Error("Failed to download file");return s.arrayBuffer()}))}function W(e){var r;return i(this,void 0,void 0,(function*(){let s,i;const o=new URL(e.url);if("z3:"===o.protocol){const e=o.pathname.split("/").slice(1);s=o.hostname,i=e.join("/")}else{if(!o.href.startsWith(null!==(r=this.config.projectApiUrl)&&void 0!==r?r:n))throw new t({message:"Invalid Z3 URL",code:400});{const e=o.pathname.split("/").slice(3);s=e[0],i=e.slice(1).join("/")}}const u={action:"upload",bucketName:s,"objectPath+":i};return this.request("/z3/{bucketName}/{objectPath+}","post")(u)}))}class X extends c{constructor(e){super(e),this.uploadFile=G,this.downloadFile=J,this.getPresignedUrlForZ3Url=W}listBuckets(e){return this.request("/z3","get")(e)}createBucket(e,t){return this.request("/z3/{bucketName}","put")(e,t)}deleteBucket(e,t){return this.request("/z3/{bucketName}","delete")(e,t)}listObjects(e,t){return this.request("/z3/{bucketName}/{objectPath+}","get")(e,t)}getPresignedUrl(e,t){return this.request("/z3/{bucketName}/{objectPath+}","post")(e,t)}deleteObject(e,t){return this.request("/z3/{bucketName}/{objectPath+}","delete")(e,t)}}function Z({id:e,file:t,filename:r}){return i(this,void 0,void 0,(function*(){const s=yield this.request("/zambda/{id}/s3-upload","post")({id:e,filename:r});yield fetch(s.signedUrl,{method:"PUT",body:t})}))}class K extends c{constructor(e){super(e),this.uploadFile=Z}list(e){return this.request("/zambda","get")(e)}create(e,t){return this.request("/zambda","post")(e,t)}get(e,t){return this.request("/zambda/{id}","get")(e,t)}update(e,t){return this.request("/zambda/{id}","patch")(e,t)}delete(e,t){return this.request("/zambda/{id}","delete")(e,t)}execute(e,t){return this.request("/zambda/{id}/execute","post")(e,t)}executePublic(e,t){return this.request("/zambda/{id}/execute-public","post")(e,t)}s3Upload(e,t){return this.request("/zambda/{id}/s3-upload","post")(e,t)}}class Q extends c{constructor(e){super(e)}list(e,t){return this.request("/zambda/{id}/logStream","post")(e,t)}search(e,t){return this.request("/zambda/{id}/logStream/search","post")(e,t)}get(e,t){return this.request("/zambda/{id}/logStream/{logStreamName}","post")(e,t)}}let Y=class{constructor(e){this.config=e,this.application=new h(e),this.developer=new y(e),this.m2m=new $(e),this.messaging=new A(e),this.conversation=new g(e),this.transactionalSMS=new F(e),this.paymentMethod=new C(e),this.charge=new p(e),this.project=new _(e),this.rcm=new L(e),this.erx=new q(e),this.fax=new b(e),this.role=new M(e),this.secret=new D(e),this.telemed=new V(e),this.user=new H(e),this.version=new B(e),this.z3=new X(e),this.zambda=new K(e),this.zambdaLogStream=new Q(e),this.fhir=new I(e)}};class ee extends Y{}ee.OystehrFHIRError=s,ee.OystehrSdkError=t,module.exports=ee;
|
|
2
2
|
//# sourceMappingURL=index.min.cjs.map
|