@oystehr/sdk 3.0.12 → 3.0.13

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.
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("uuid");class e extends Error{constructor({message:t,code:i,cause:s}){super(t,{cause:s}),Object.setPrototypeOf(this,e.prototype),this.code=i,this.name="OystehrSdkError"}toString(){return`${this.name}: ${this.message} (code: ${this.code})`}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function i(t){var e;const i=[];for(const s of null!==(e=t.issue)&&void 0!==e?e:[])s.details&&s.details.text&&i.push(s.details.text);return i.length||i.push("Unknown FHIR error"),i.join(",")}class s extends e{constructor({error:t,code:e}){super({message:i(t),code:e}),Object.setPrototypeOf(this,s.prototype),this.cause=t,this.name="OystehrFHIRError"}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function r(t,e,i,s){return new(i||(i=Promise))((function(r,n){function o(t){try{c(s.next(t))}catch(t){n(t)}}function u(t){try{c(s.throw(t))}catch(t){n(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,u)}c((s=s.apply(t,e||[])).next())}))}function n(t,e,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;const 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(t){this.config=t}request(t,i,s){return(n,o)=>r(this,void 0,void 0,(function*(){const r=()=>this.config;try{return yield a(s,r,t,i)(n,o)}catch(t){const i=t;throw new e({message:i.message,code:i.code,cause:i.cause})}}))}fhirRequest(t,i){return(n,o)=>r(this,void 0,void 0,(function*(){try{const e=()=>{var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.fhirApiUrl)&&void 0!==e?e:"https://fhir-api.zapehr.com"},s=()=>this.config;return yield a(e,s,t,i)(n,o)}catch(t){const i=t;if("string"==typeof i.message)throw new e({message:i.message,code:i.code,cause:i.cause});throw new s({error:i.message,code:i.code})}}))}}function h(t){return"accessToken"in t}function a(i,s,n,c){return(a,l)=>r(this,void 0,void 0,(function*(){var p,v,m,f,b,g,y,q,j,w,S,U,k,x,O;const T=a&&!l&&!Array.isArray(a)&&h(a)?{}:null!==(p=a)&&void 0!==p?p:{},E=a&&!l&&!Array.isArray(a)&&h(a)?a:l,z=c.toLowerCase(),A=s(),R=null!==(v=A.fetch)&&void 0!==v?v:fetch,P=null!==(m=null==E?void 0:E.accessToken)&&void 0!==m?m:A.accessToken,N=null!==(f=null==E?void 0:E.projectId)&&void 0!==f?f:s().projectId;let I=n,W=T;if(!Array.isArray(T)){const[t,i]=function(t,i){const s=Object.assign({},i),r=t.replace(/\{([^}]+)\}/g,((t,r)=>{if(delete s[r],r.match(/^.*\+$/))return i[r]+"";if(!i[r]||""===i[r])throw new e({message:`Required path parameter is an empty string: ${r}`,code:400});return i[r]?encodeURIComponent(i[r]+""):""})),n=Object.keys(s),o=n.length?n.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:s[e]})),{}):{};return[r,o]}(n,T);I=t,W=i}I=I.replace(/^\//,"");const $=i(),C=$.endsWith("/")?$:$+"/",_=new URL(I,C);let L;if(Array.isArray(W))L=JSON.stringify(W);else if(Object.keys(W).length)if("get"===z)d(W,_.searchParams);else if("application/x-www-form-urlencoded"===(null==E?void 0:E.contentType)){const t=new URLSearchParams;d(W,t),L=t.toString()}else L=JSON.stringify(W);else"application/x-www-form-urlencoded"!==(null==E?void 0:E.contentType)&&"post"===z&&(L="{}");const M=Object.assign(N?{"x-zapehr-project-id":N,"x-oystehr-project-id":N}:{},{"content-type":null!==(b=null==E?void 0:E.contentType)&&void 0!==b?b:"application/json"},P?{Authorization:`Bearer ${P}`}:{},(null==E?void 0:E.ifMatch)?{"If-Match":E.ifMatch}:{},{"x-oystehr-request-id":null!==(g=null==E?void 0:E.requestId)&&void 0!==g?g:t.v4()}),D={retries:null!==(q=null===(y=A.retry)||void 0===y?void 0:y.retries)&&void 0!==q?q:3,jitter:null!==(w=null===(j=A.retry)||void 0===j?void 0:j.jitter)&&void 0!==w?w:20,delay:null!==(U=null===(S=A.retry)||void 0===S?void 0:S.delay)&&void 0!==U?U:100,onRetry:null===(k=A.retry)||void 0===k?void 0:k.onRetry,retryOn:[...null!==(O=null===(x=A.retry)||void 0===x?void 0:x.retryOn)&&void 0!==O?O:[],...o]};return D.retryOn.push(...o),function(t,e){var i,s;return r(this,void 0,void 0,(function*(){let r;for(const n of Array.from({length:(null!==(i=e.retries)&&void 0!==i?i:0)+1},((t,e)=>e)))try{return yield t(n)}catch(t){let i=!1;if("response"in t){const s=t;i=e.retryOn.includes(s.code),r={message:t.message,code:t.code}}else if(r=t,"code"in t&&"string"==typeof t.code){const e=t;i=u.includes(e.code)}if(!i)break;const o=Math.floor(Math.random()*(e.jitter+1));yield new Promise((t=>setTimeout(t,e.delay+o))),e.onRetry&&n!==(null!==(s=e.retries)&&void 0!==s?s:0)&&e.onRetry(n+1)}throw r}))}((()=>r(this,void 0,void 0,(function*(){var t,e,i,s,r,n;const o=yield R(new Request(_,{method:z.toUpperCase(),body:L,headers:M})),u=o.body?yield o.text():null;let c;try{c=u&&((null===(t=o.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))||(null===(e=o.headers.get("content-type"))||void 0===e?void 0:e.includes("application/fhir+json")))?JSON.parse(u):null}catch(t){c=null}if(!o.ok||o.status>=400){throw{message:null!==(r=null!==(s=null!==(i=null==c?void 0:c.message)&&void 0!==i?i:c)&&void 0!==s?s:u)&&void 0!==r?r:o.statusText,code:null!==(n=null==c?void 0:c.code)&&void 0!==n?n:o.status,response:o}}return c}))),D)}))}function d(t,e){for(const[i,s]of Object.entries(t))Array.isArray(s)?s.forEach((t=>e.append(i,t))):e.append(i,s)}var l,p,v,m;class f extends c{constructor(t){super(t),l.add(this)}list(t){return this.request("/application","get",n(this,l,"m",p).bind(this))(t)}create(t,e){return this.request("/application","post",n(this,l,"m",p).bind(this))(t,e)}get(t,e){return this.request("/application/{id}","get",n(this,l,"m",p).bind(this))(t,e)}update(t,e){return this.request("/application/{id}","patch",n(this,l,"m",p).bind(this))(t,e)}delete(t,e){return this.request("/application/{id}","delete",n(this,l,"m",p).bind(this))(t,e)}rotateSecret(t,e){return this.request("/application/{id}/rotate-secret","post",n(this,l,"m",p).bind(this))(t,e)}revokeRefreshToken(t,e){return this.request("/application/{id}/revoke-refresh-token","post",n(this,l,"m",p).bind(this))(t,e)}revokeAccessToken(t,e){return this.request("/application/{id}/revoke-access-token","post",n(this,l,"m",p).bind(this))(t,e)}}l=new WeakSet,p=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class b extends c{constructor(t){super(t),v.add(this)}issue(t,e){return this.request("/payment/charge/issue","post",n(this,v,"m",m).bind(this))(t,e)}status(t,e){return this.request("/payment/charge/status","post",n(this,v,"m",m).bind(this))(t,e)}}v=new WeakSet,m=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};const g="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",y="addressString";function q(t){var e,i,s;if(function(t){return Object.hasOwn(t,"virtualService")}(t)){const i=null===(e=t.virtualService)||void 0===e?void 0:e.find((t=>{var e;return"https://fhir.zapehr.com/virtual-service-type"===(null===(e=t.channelType)||void 0===e?void 0:e.system)}));return null==i?void 0:i.addressString}if(!t.extension)return;const r=t.extension.find((t=>t.url===g));if(!(null==r?void 0:r.extension))return;return null===(s=null===(i=r.extension)||void 0===i?void 0:i.find((t=>t.url===y)))||void 0===s?void 0:s.valueString}var j,w,S,U,k,x,O,T;class E extends c{constructor(t){super(t),j.add(this),this.ENCOUNTER_VS_EXTENSION_URL=g,this.ENCOUNTER_VS_EXTENSION_RELATIVE_URL=y,this.getConversationIdFromEncounter=q}create(t,e){return this.request("/messaging/conversation","post",n(this,j,"m",w).bind(this))(t,e)}getToken(t){return this.request("/messaging/conversation/token","get",n(this,j,"m",w).bind(this))(t)}addParticipant(t,e){return this.request("/messaging/conversation/{conversationId}/participant","post",n(this,j,"m",w).bind(this))(t,e)}removeParticipant(t,e){return this.request("/messaging/conversation/{conversationId}/participant","delete",n(this,j,"m",w).bind(this))(t,e)}message(t,e){return this.request("/messaging/conversation/{conversationId}/message","post",n(this,j,"m",w).bind(this))(t,e)}}j=new WeakSet,w=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class z extends c{constructor(t){super(t),S.add(this)}get(t,e){return this.request("/developer/{id}","get",n(this,S,"m",U).bind(this))(t,e)}update(t,e){return this.request("/developer/{id}","patch",n(this,S,"m",U).bind(this))(t,e)}delete(t,e){return this.request("/developer/{id}","delete",n(this,S,"m",U).bind(this))(t,e)}invite(t,e){return this.request("/developer/invite","post",n(this,S,"m",U).bind(this))(t,e)}list(t){return this.request("/developer","get",n(this,S,"m",U).bind(this))(t)}listV2(t,e){return this.request("/developer/v2/list","get",n(this,S,"m",U).bind(this))(t,e)}}S=new WeakSet,U=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class A extends c{constructor(t){super(t),k.add(this)}syncPatient(t,e){return this.request("/erx/sync-patient/{patientId}","post",n(this,k,"m",x).bind(this))(t,e)}allergySearch(t,e){return this.request("/erx/allergy/search","get",n(this,k,"m",x).bind(this))(t,e)}cancelOrder(t,e){return this.request("/erx/cancel-order","post",n(this,k,"m",x).bind(this))(t,e)}cancelPrescription(t,e){return this.request("/erx/cancel-prescription","post",n(this,k,"m",x).bind(this))(t,e)}medicationSearch(t,e){return this.request("/erx/medication/search","get",n(this,k,"m",x).bind(this))(t,e)}medicationSearchV2(t,e){return this.request("/erx/v2/medication/search","get",n(this,k,"m",x).bind(this))(t,e)}}k=new WeakSet,x=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class R extends c{constructor(t){super(t),O.add(this)}offboard(t){return this.request("/offboard","post",n(this,O,"m",T).bind(this))(t)}onboard(t){return this.request("/onboard","post",n(this,O,"m",T).bind(this))(t)}send(t,e){return this.request("/send","post",n(this,O,"m",T).bind(this))(t,e)}}function P(t,e){return r(this,void 0,void 0,(function*(){const{resourceType:i,params:s}=t;let r;s&&(r=Object.entries(s).reduce(((t,[e,i])=>(t[i.name]||(t[i.name]=[]),t[i.name].push(i.value),t)),{}));const n=yield this.fhirRequest(`/${i}/_search`,"POST")(r,Object.assign(Object.assign({},e),{contentType:"application/x-www-form-urlencoded"}));return Object.assign(Object.assign({},n),{entry:n.entry,unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]}})}))}function N(t,e){return r(this,void 0,void 0,(function*(){const{resourceType:i}=t;return this.fhirRequest(`/${i}`,"POST")(t,e)}))}function I({resourceType:t,id:e},i){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}`,"GET")({},i)}))}function W(t,e){return r(this,void 0,void 0,(function*(){const{id:i,resourceType:s}=t;return this.fhirRequest(`/${s}/${i}`,"PUT")(t,Object.assign(Object.assign({},e),{ifMatch:(null==e?void 0:e.optimisticLockingVersionId)?`W/"${e.optimisticLockingVersionId}"`:void 0}))}))}function $({resourceType:t,id:e,operations:i},s){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}`,"PATCH")(i,Object.assign(Object.assign({},s),{contentType:"application/json-patch+json",ifMatch:(null==s?void 0:s.optimisticLockingVersionId)?`W/"${s.optimisticLockingVersionId}"`:void 0}))}))}function C({resourceType:t,id:e},i){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}`,"DELETE")({},i)}))}function _({resourceType:t,id:e,versionId:i},s){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}/_history${i?`/${i}`:""}`,"GET")({},s)}))}function L(t){const{method:e,url:i}=t,s={request:{method:e,url:i}};if(i.split("?").length>1){const[t,e]=i.split("?"),r=e.split("&").map((t=>{const[e,i]=t.split("=");return{name:e,value:i}})).reduce(((t,{name:e,value:i})=>e?(t[e]||(t[e]=[]),t[e].push(i),t):t),{}),n=new URLSearchParams;d(r,n),s.request.url=`${t}?${n.toString()}`}if(["GET","DELETE","HEAD"].includes(e))return s;if("PUT"===e){const{resource:e}=t;return Object.assign(Object.assign({},s),{resource:e})}if("PATCH"===e)return"resource"in t?Object.assign(Object.assign({},s),{resource:t.resource}):Object.assign(Object.assign({},s),{resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:Buffer.from(JSON.stringify(t.operations),"utf8").toString("base64")}});if("POST"===e){const{resource:e,fullUrl:i}=t;return Object.assign(Object.assign({},s),{resource:e,fullUrl:i})}throw new Error("Unrecognized method")}function M(t){return function(e,i){return r(this,void 0,void 0,(function*(){return this.fhirRequest("/","POST")({resourceType:"Bundle",type:t,entry:e.requests.map(L)},i)}))}}O=new WeakSet,T=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.faxApiUrl)&&void 0!==e?e:"https://fax-api.zapehr.com/v1"};const D=M("batch"),V=M("transaction");function F(t,e){const i=[];if(t.line&&i.push(...t.line),t.city||t.state||t.postalCode){const e=[];t.city&&e.push(t.city),t.state&&e.push(t.state),t.postalCode&&e.push(t.postalCode),i.push(e.join(", "))}return t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&i.push("["+t.use+"]"),i.join((null==e?void 0:e.lineSeparator)||", ").trim()}function H(t,e){const i=[];return t.prefix&&!1!==(null==e?void 0:e.prefix)&&i.push(...t.prefix),t.given&&i.push(...t.given),t.family&&i.push(t.family),t.suffix&&!1!==(null==e?void 0:e.suffix)&&i.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&i.push("["+t.use+"]"),i.join(" ").trim()}var B,G,J,X,Z,K,Q,Y,tt,et,it,st,rt,nt,ot,ut,ct,ht,at,dt,lt,pt,vt,mt,ft,bt,gt,yt,qt,jt,wt;class St extends c{constructor(t){super(t),B.add(this),this.search=P,this.create=N,this.get=I,this.update=W,this.patch=$,this.delete=C,this.history=_,this.batch=D,this.transaction=V,this.formatAddress=F,this.formatHumanName=H}}B=new WeakSet;class Ut extends c{constructor(t){super(t),G.add(this)}routeList(t){return this.request("/route","get",n(this,G,"m",J).bind(this))(t)}routeCreate(t,e){return this.request("/route","post",n(this,G,"m",J).bind(this))(t,e)}routeDelete(t,e){return this.request("/route/{routeGuid}","delete",n(this,G,"m",J).bind(this))(t,e)}orderableItemList(t,e){return this.request("/orderableItem","get",n(this,G,"m",J).bind(this))(t,e)}orderableItemQuestionnaireGet(t,e){return this.request("/canonical-questionnaire/lab/{labGuid}/compendium/{compendiumVersion}/item/{itemCode}/questionnaire","get",n(this,G,"m",J).bind(this))(t,e)}orderSubmit(t,e){return this.request("/submit","post",n(this,G,"m",J).bind(this))(t,e)}}G=new WeakSet,J=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.labApiUrl)&&void 0!==e?e:"https://labs-api.zapehr.com/v1"};class kt extends c{constructor(t){super(t),X.add(this)}list(t){return this.request("/m2m","get",n(this,X,"m",Z).bind(this))(t)}create(t,e){return this.request("/m2m","post",n(this,X,"m",Z).bind(this))(t,e)}get(t,e){return this.request("/m2m/{id}","get",n(this,X,"m",Z).bind(this))(t,e)}update(t,e){return this.request("/m2m/{id}","patch",n(this,X,"m",Z).bind(this))(t,e)}delete(t,e){return this.request("/m2m/{id}","delete",n(this,X,"m",Z).bind(this))(t,e)}rotateSecret(t,e){return this.request("/m2m/{id}/rotate-secret","post",n(this,X,"m",Z).bind(this))(t,e)}listV2(t,e){return this.request("/m2m/v2/list","get",n(this,X,"m",Z).bind(this))(t,e)}}X=new WeakSet,Z=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class xt extends c{constructor(t){super(t),K.add(this)}getMessagingConfig(t){return this.request("/messaging/config","get",n(this,K,"m",Q).bind(this))(t)}}K=new WeakSet,Q=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Ot extends c{constructor(t){super(t),Y.add(this)}setUp(t,e){return this.request("/payment/payment-method/setup","post",n(this,Y,"m",tt).bind(this))(t,e)}setDefault(t,e){return this.request("/payment/payment-method/set-default","post",n(this,Y,"m",tt).bind(this))(t,e)}delete(t,e){return this.request("/payment/payment-method","delete",n(this,Y,"m",tt).bind(this))(t,e)}list(t,e){return this.request("/payment/payment-method/list","post",n(this,Y,"m",tt).bind(this))(t,e)}}Y=new WeakSet,tt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Tt extends c{constructor(t){super(t),et.add(this)}get(t){return this.request("/project","get",n(this,et,"m",it).bind(this))(t)}update(t,e){return this.request("/project","patch",n(this,et,"m",it).bind(this))(t,e)}}et=new WeakSet,it=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Et extends c{constructor(t){super(t),st.add(this)}eligibilityCheck(t,e){return this.request("/rcm/eligibility-check","post",n(this,st,"m",rt).bind(this))(t,e)}validateProfessionalClaim(t,e){return this.request("/rcm/professional-claim/validate","post",n(this,st,"m",rt).bind(this))(t,e)}submitProfessionalClaim(t,e){return this.request("/rcm/professional-claim/submit","post",n(this,st,"m",rt).bind(this))(t,e)}}st=new WeakSet,rt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class zt extends c{constructor(t){super(t),nt.add(this)}list(t){return this.request("/iam/role","get",n(this,nt,"m",ot).bind(this))(t)}create(t,e){return this.request("/iam/role","post",n(this,nt,"m",ot).bind(this))(t,e)}get(t,e){return this.request("/iam/role/{roleId}","get",n(this,nt,"m",ot).bind(this))(t,e)}update(t,e){return this.request("/iam/role/{roleId}","patch",n(this,nt,"m",ot).bind(this))(t,e)}delete(t,e){return this.request("/iam/role/{roleId}","delete",n(this,nt,"m",ot).bind(this))(t,e)}}nt=new WeakSet,ot=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class At extends c{constructor(t){super(t),ut.add(this)}list(t){return this.request("/secret","get",n(this,ut,"m",ct).bind(this))(t)}set(t,e){return this.request("/secret","post",n(this,ut,"m",ct).bind(this))(t,e)}get(t,e){return this.request("/secret/{name}","get",n(this,ut,"m",ct).bind(this))(t,e)}delete(t,e){return this.request("/secret/{name}","delete",n(this,ut,"m",ct).bind(this))(t,e)}}ut=new WeakSet,ct=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Rt extends c{constructor(t){super(t),ht.add(this)}createMeeting(t,e){return this.request("/telemed/v2/meeting","post",n(this,ht,"m",at).bind(this))(t,e)}joinMeeting(t,e){return this.request("/telemed/v2/meeting/{encounterId}/join","get",n(this,ht,"m",at).bind(this))(t,e)}}ht=new WeakSet,at=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Pt extends c{constructor(t){super(t),dt.add(this)}send(t,e){return this.request("/messaging/transactional-sms/send","post",n(this,dt,"m",lt).bind(this))(t,e)}}dt=new WeakSet,lt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Nt extends c{constructor(t){super(t),pt.add(this)}me(t){return this.request("/user/me","get",n(this,pt,"m",vt).bind(this))(t)}get(t,e){return this.request("/user/{id}","get",n(this,pt,"m",vt).bind(this))(t,e)}update(t,e){return this.request("/user/{id}","patch",n(this,pt,"m",vt).bind(this))(t,e)}delete(t,e){return this.request("/user/{id}","delete",n(this,pt,"m",vt).bind(this))(t,e)}invite(t,e){return this.request("/user/invite","post",n(this,pt,"m",vt).bind(this))(t,e)}list(t){return this.request("/user","get",n(this,pt,"m",vt).bind(this))(t)}listV2(t,e){return this.request("/user/v2/list","get",n(this,pt,"m",vt).bind(this))(t,e)}}pt=new WeakSet,vt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class It extends c{constructor(t){super(t),mt.add(this)}get(t){return this.request("/version","get",n(this,mt,"m",ft).bind(this))(t)}}function Wt(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"}function $t({bucketName:t,"objectPath+":e,file:i}){return r(this,void 0,void 0,(function*(){const s=yield this.request("/z3/{bucketName}/{objectPath+}","post",Wt.bind(this))({action:"upload",bucketName:t,"objectPath+":e});yield fetch(s.signedUrl,{method:"PUT",body:i})}))}function Ct({bucketName:t,"objectPath+":e}){return r(this,void 0,void 0,(function*(){const i=yield this.request("/z3/{bucketName}/{objectPath+}","post",Wt.bind(this))({action:"download",bucketName:t,"objectPath+":e}),s=yield fetch(i.signedUrl,{method:"GET"});if(!s.ok)throw new Error("Failed to download file");return s.arrayBuffer()}))}function _t(t){var i,s;return r(this,void 0,void 0,(function*(){let r,n;const o=new URL(t.url);if("z3:"===o.protocol){const t=o.pathname.split("/").slice(1);r=o.hostname,n=t.join("/")}else{if(!o.href.startsWith(null!==(s=null===(i=this.config.services)||void 0===i?void 0:i.projectApiUrl)&&void 0!==s?s:"https://project-api.zapehr.com/v1"))throw new e({message:"Invalid Z3 URL",code:400});{const t=o.pathname.split("/").slice(3);r=t[0],n=t.slice(1).join("/")}}const u={action:"upload",bucketName:r,"objectPath+":n};return this.request("/z3/{bucketName}/{objectPath+}","post",Wt.bind(this))(u)}))}mt=new WeakSet,ft=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Lt extends c{constructor(t){super(t),bt.add(this),this.uploadFile=$t,this.downloadFile=Ct,this.getPresignedUrlForZ3Url=_t}listBuckets(t){return this.request("/z3","get",n(this,bt,"m",gt).bind(this))(t)}createBucket(t,e){return this.request("/z3/{bucketName}","put",n(this,bt,"m",gt).bind(this))(t,e)}deleteBucket(t,e){return this.request("/z3/{bucketName}","delete",n(this,bt,"m",gt).bind(this))(t,e)}listObjects(t,e){return this.request("/z3/{bucketName}/{objectPath+}","get",n(this,bt,"m",gt).bind(this))(t,e)}getPresignedUrl(t,e){return this.request("/z3/{bucketName}/{objectPath+}","post",n(this,bt,"m",gt).bind(this))(t,e)}deleteObject(t,e){return this.request("/z3/{bucketName}/{objectPath+}","delete",n(this,bt,"m",gt).bind(this))(t,e)}}function Mt(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"}function Dt({id:t,file:e,filename:i}){return r(this,void 0,void 0,(function*(){const s=yield this.request("/zambda/{id}/s3-upload","post",Mt.bind(this))({id:t,filename:i});yield fetch(s.signedUrl,{method:"PUT",body:e})}))}bt=new WeakSet,gt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Vt extends c{constructor(t){super(t),yt.add(this),this.uploadFile=Dt}list(t){return this.request("/zambda","get",n(this,yt,"m",qt).bind(this))(t)}create(t,e){return this.request("/zambda","post",n(this,yt,"m",qt).bind(this))(t,e)}get(t,e){return this.request("/zambda/{id}","get",n(this,yt,"m",qt).bind(this))(t,e)}update(t,e){return this.request("/zambda/{id}","patch",n(this,yt,"m",qt).bind(this))(t,e)}delete(t,e){return this.request("/zambda/{id}","delete",n(this,yt,"m",qt).bind(this))(t,e)}execute(t,e){return this.request("/zambda/{id}/execute","post",n(this,yt,"m",qt).bind(this))(t,e)}executePublic(t,e){return this.request("/zambda/{id}/execute-public","post",n(this,yt,"m",qt).bind(this))(t,e)}s3Upload(t,e){return this.request("/zambda/{id}/s3-upload","post",n(this,yt,"m",qt).bind(this))(t,e)}}yt=new WeakSet,qt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Ft extends c{constructor(t){super(t),jt.add(this)}list(t,e){return this.request("/zambda/{id}/logStream","post",n(this,jt,"m",wt).bind(this))(t,e)}search(t,e){return this.request("/zambda/{id}/logStream/search","post",n(this,jt,"m",wt).bind(this))(t,e)}get(t,e){return this.request("/zambda/{id}/logStream/{logStreamName}","post",n(this,jt,"m",wt).bind(this))(t,e)}}jt=new WeakSet,wt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};let Ht=class{constructor(t){var e,i,s,r,n,o;this.config=t,null!==(e=(r=this.config).services)&&void 0!==e||(r.services={}),null!==(i=(n=this.config.services).projectApiUrl)&&void 0!==i||(n.projectApiUrl=t.projectApiUrl),null!==(s=(o=this.config.services).fhirApiUrl)&&void 0!==s||(o.fhirApiUrl=t.fhirApiUrl),this.application=new f(t),this.developer=new z(t),this.m2m=new kt(t),this.messaging=new xt(t),this.conversation=new E(t),this.transactionalSMS=new Pt(t),this.paymentMethod=new Ot(t),this.charge=new b(t),this.project=new Tt(t),this.rcm=new Et(t),this.erx=new A(t),this.role=new zt(t),this.secret=new At(t),this.telemed=new Rt(t),this.user=new Nt(t),this.version=new It(t),this.z3=new Lt(t),this.zambda=new Vt(t),this.zambdaLogStream=new Ft(t),this.fax=new R(t),this.lab=new Ut(t),this.fhir=new St(t)}};class Bt extends Ht{}Bt.OystehrFHIRError=s,Bt.OystehrSdkError=e,module.exports=Bt;
1
+ "use strict";var t=require("uuid");class e extends Error{constructor({message:t,code:i,cause:s}){super(t,{cause:s}),Object.setPrototypeOf(this,e.prototype),this.code=i,this.name="OystehrSdkError"}toString(){return`${this.name}: ${this.message} (code: ${this.code})`}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function i(t){var e;const i=[];for(const s of null!==(e=t.issue)&&void 0!==e?e:[])s.details&&s.details.text&&i.push(s.details.text);return i.length||i.push("Unknown FHIR error"),i.join(",")}class s extends e{constructor({error:t,code:e}){super({message:i(t),code:e}),Object.setPrototypeOf(this,s.prototype),this.cause=t,this.name="OystehrFHIRError"}toJSON(){return{name:this.name,message:this.message,code:this.code,cause:this.cause}}}function r(t,e,i,s){return new(i||(i=Promise))((function(r,n){function o(t){try{c(s.next(t))}catch(t){n(t)}}function u(t){try{c(s.throw(t))}catch(t){n(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,u)}c((s=s.apply(t,e||[])).next())}))}function n(t,e,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)}"function"==typeof SuppressedError&&SuppressedError;const 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(t){this.config=t}request(t,i,s){return(n,o)=>r(this,void 0,void 0,(function*(){const r=()=>this.config;try{return yield a(s,r,t,i)(n,o)}catch(t){const i=t;throw new e({message:i.message,code:i.code,cause:i.cause})}}))}fhirRequest(t,i){return(n,o)=>r(this,void 0,void 0,(function*(){try{const e=()=>{var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.fhirApiUrl)&&void 0!==e?e:"https://fhir-api.zapehr.com"},s=()=>this.config;return yield a(e,s,t,i)(n,o)}catch(t){const i=t;if("string"==typeof i.message)throw new e({message:i.message,code:i.code,cause:i.cause});throw new s({error:i.message,code:i.code})}}))}}function h(t){return"accessToken"in t}function a(i,s,n,c){return(a,l)=>r(this,void 0,void 0,(function*(){var p,v,m,f,g,b,y,q,j,w,S,U,k,x,O;const T=a&&!l&&!Array.isArray(a)&&h(a)?{}:null!==(p=a)&&void 0!==p?p:{},E=a&&!l&&!Array.isArray(a)&&h(a)?a:l,z=c.toLowerCase(),A=s(),R=null!==(v=A.fetch)&&void 0!==v?v:fetch,P=null!==(m=null==E?void 0:E.accessToken)&&void 0!==m?m:A.accessToken,N=null!==(f=null==E?void 0:E.projectId)&&void 0!==f?f:s().projectId;let I=n,W=T;if(!Array.isArray(T)){const[t,i]=function(t,i){const s=Object.assign({},i),r=t.replace(/\{([^}]+)\}/g,((t,r)=>{if(delete s[r],r.match(/^.*\+$/))return i[r]+"";if(!i[r]||""===i[r])throw new e({message:`Required path parameter is an empty string: ${r}`,code:400});return i[r]?encodeURIComponent(i[r]+""):""})),n=Object.keys(s),o=n.length?n.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:s[e]})),{}):{};return[r,o]}(n,T);I=t,W=i}I=I.replace(/^\//,"");const $=i(),C=$.endsWith("/")?$:$+"/",_=new URL(I,C);let L;if(Array.isArray(W))L=JSON.stringify(W);else if(Object.keys(W).length)if("get"===z)d(W,_.searchParams);else if("application/x-www-form-urlencoded"===(null==E?void 0:E.contentType)){const t=new URLSearchParams;d(W,t),L=t.toString()}else L=JSON.stringify(W);else"application/x-www-form-urlencoded"!==(null==E?void 0:E.contentType)&&"post"===z&&(L="{}");const M=Object.assign(N?{"x-zapehr-project-id":N,"x-oystehr-project-id":N}:{},{"content-type":null!==(g=null==E?void 0:E.contentType)&&void 0!==g?g:"application/json"},P?{Authorization:`Bearer ${P}`}:{},(null==E?void 0:E.ifMatch)?{"If-Match":E.ifMatch}:{},{"x-oystehr-request-id":null!==(b=null==E?void 0:E.requestId)&&void 0!==b?b:t.v4()}),D={retries:null!==(q=null===(y=A.retry)||void 0===y?void 0:y.retries)&&void 0!==q?q:3,jitter:null!==(w=null===(j=A.retry)||void 0===j?void 0:j.jitter)&&void 0!==w?w:20,delay:null!==(U=null===(S=A.retry)||void 0===S?void 0:S.delay)&&void 0!==U?U:100,onRetry:null===(k=A.retry)||void 0===k?void 0:k.onRetry,retryOn:[...null!==(O=null===(x=A.retry)||void 0===x?void 0:x.retryOn)&&void 0!==O?O:[],...o]};return D.retryOn.push(...o),function(t,e){var i,s;return r(this,void 0,void 0,(function*(){let r;for(const n of Array.from({length:(null!==(i=e.retries)&&void 0!==i?i:0)+1},((t,e)=>e)))try{return yield t(n)}catch(t){let i=!1;if("response"in t){const s=t;i=e.retryOn.includes(s.code),r={message:t.message,code:t.code}}else if(r=t,"code"in t&&"string"==typeof t.code){const e=t;i=u.includes(e.code)}if(!i)break;const o=Math.floor(Math.random()*(e.jitter+1));yield new Promise((t=>setTimeout(t,e.delay+o))),e.onRetry&&n!==(null!==(s=e.retries)&&void 0!==s?s:0)&&e.onRetry(n+1)}throw r}))}((()=>r(this,void 0,void 0,(function*(){var t,e,i,s,r,n,o,u,c,h;const a=yield R(new Request(_,{method:z.toUpperCase(),body:L,headers:M})),d=a.body?yield a.text():null;let l;try{l=d&&((null===(t=a.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))||(null===(e=a.headers.get("content-type"))||void 0===e?void 0:e.includes("application/fhir+json")))?JSON.parse(d):null}catch(t){l=null}if(!a.ok||a.status>=400){throw{message:null!==(o=null!==(n=null!==(r=null!==(s=null===(i=null==l?void 0:l.output)||void 0===i?void 0:i.message)&&void 0!==s?s:null==l?void 0:l.message)&&void 0!==r?r:l)&&void 0!==n?n:d)&&void 0!==o?o:a.statusText,code:null!==(h=null!==(c=null===(u=null==l?void 0:l.output)||void 0===u?void 0:u.code)&&void 0!==c?c:null==l?void 0:l.code)&&void 0!==h?h:a.status,response:a}}return l}))),D)}))}function d(t,e){for(const[i,s]of Object.entries(t))Array.isArray(s)?s.forEach((t=>e.append(i,t))):e.append(i,s)}var l,p,v,m;class f extends c{constructor(t){super(t),l.add(this)}list(t){return this.request("/application","get",n(this,l,"m",p).bind(this))(t)}create(t,e){return this.request("/application","post",n(this,l,"m",p).bind(this))(t,e)}get(t,e){return this.request("/application/{id}","get",n(this,l,"m",p).bind(this))(t,e)}update(t,e){return this.request("/application/{id}","patch",n(this,l,"m",p).bind(this))(t,e)}delete(t,e){return this.request("/application/{id}","delete",n(this,l,"m",p).bind(this))(t,e)}rotateSecret(t,e){return this.request("/application/{id}/rotate-secret","post",n(this,l,"m",p).bind(this))(t,e)}revokeRefreshToken(t,e){return this.request("/application/{id}/revoke-refresh-token","post",n(this,l,"m",p).bind(this))(t,e)}revokeAccessToken(t,e){return this.request("/application/{id}/revoke-access-token","post",n(this,l,"m",p).bind(this))(t,e)}}l=new WeakSet,p=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class g extends c{constructor(t){super(t),v.add(this)}issue(t,e){return this.request("/payment/charge/issue","post",n(this,v,"m",m).bind(this))(t,e)}status(t,e){return this.request("/payment/charge/status","post",n(this,v,"m",m).bind(this))(t,e)}}v=new WeakSet,m=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};const b="https://extensions.fhir.zapehr.com/encounter-virtual-service-pre-release",y="addressString";function q(t){var e,i,s;if(function(t){return Object.hasOwn(t,"virtualService")}(t)){const i=null===(e=t.virtualService)||void 0===e?void 0:e.find((t=>{var e;return"https://fhir.zapehr.com/virtual-service-type"===(null===(e=t.channelType)||void 0===e?void 0:e.system)}));return null==i?void 0:i.addressString}if(!t.extension)return;const r=t.extension.find((t=>t.url===b));if(!(null==r?void 0:r.extension))return;return null===(s=null===(i=r.extension)||void 0===i?void 0:i.find((t=>t.url===y)))||void 0===s?void 0:s.valueString}var j,w,S,U,k,x,O,T;class E extends c{constructor(t){super(t),j.add(this),this.ENCOUNTER_VS_EXTENSION_URL=b,this.ENCOUNTER_VS_EXTENSION_RELATIVE_URL=y,this.getConversationIdFromEncounter=q}create(t,e){return this.request("/messaging/conversation","post",n(this,j,"m",w).bind(this))(t,e)}getToken(t){return this.request("/messaging/conversation/token","get",n(this,j,"m",w).bind(this))(t)}addParticipant(t,e){return this.request("/messaging/conversation/{conversationId}/participant","post",n(this,j,"m",w).bind(this))(t,e)}removeParticipant(t,e){return this.request("/messaging/conversation/{conversationId}/participant","delete",n(this,j,"m",w).bind(this))(t,e)}message(t,e){return this.request("/messaging/conversation/{conversationId}/message","post",n(this,j,"m",w).bind(this))(t,e)}}j=new WeakSet,w=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class z extends c{constructor(t){super(t),S.add(this)}get(t,e){return this.request("/developer/{id}","get",n(this,S,"m",U).bind(this))(t,e)}update(t,e){return this.request("/developer/{id}","patch",n(this,S,"m",U).bind(this))(t,e)}delete(t,e){return this.request("/developer/{id}","delete",n(this,S,"m",U).bind(this))(t,e)}invite(t,e){return this.request("/developer/invite","post",n(this,S,"m",U).bind(this))(t,e)}list(t){return this.request("/developer","get",n(this,S,"m",U).bind(this))(t)}listV2(t,e){return this.request("/developer/v2/list","get",n(this,S,"m",U).bind(this))(t,e)}}S=new WeakSet,U=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class A extends c{constructor(t){super(t),k.add(this)}syncPatient(t,e){return this.request("/erx/sync-patient/{patientId}","post",n(this,k,"m",x).bind(this))(t,e)}allergySearch(t,e){return this.request("/erx/allergy/search","get",n(this,k,"m",x).bind(this))(t,e)}cancelOrder(t,e){return this.request("/erx/cancel-order","post",n(this,k,"m",x).bind(this))(t,e)}cancelPrescription(t,e){return this.request("/erx/cancel-prescription","post",n(this,k,"m",x).bind(this))(t,e)}medicationSearch(t,e){return this.request("/erx/medication/search","get",n(this,k,"m",x).bind(this))(t,e)}medicationSearchV2(t,e){return this.request("/erx/v2/medication/search","get",n(this,k,"m",x).bind(this))(t,e)}}k=new WeakSet,x=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class R extends c{constructor(t){super(t),O.add(this)}offboard(t){return this.request("/offboard","post",n(this,O,"m",T).bind(this))(t)}onboard(t){return this.request("/onboard","post",n(this,O,"m",T).bind(this))(t)}send(t,e){return this.request("/send","post",n(this,O,"m",T).bind(this))(t,e)}}function P(t,e){return r(this,void 0,void 0,(function*(){const{resourceType:i,params:s}=t;let r;s&&(r=Object.entries(s).reduce(((t,[e,i])=>(t[i.name]||(t[i.name]=[]),t[i.name].push(i.value),t)),{}));const n=yield this.fhirRequest(`/${i}/_search`,"POST")(r,Object.assign(Object.assign({},e),{contentType:"application/x-www-form-urlencoded"}));return Object.assign(Object.assign({},n),{entry:n.entry,unbundle:function(){var t,e;return null!==(e=null===(t=this.entry)||void 0===t?void 0:t.map((t=>t.resource)).filter((t=>void 0!==t)))&&void 0!==e?e:[]}})}))}function N(t,e){return r(this,void 0,void 0,(function*(){const{resourceType:i}=t;return this.fhirRequest(`/${i}`,"POST")(t,e)}))}function I({resourceType:t,id:e},i){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}`,"GET")({},i)}))}function W(t,e){return r(this,void 0,void 0,(function*(){const{id:i,resourceType:s}=t;return this.fhirRequest(`/${s}/${i}`,"PUT")(t,Object.assign(Object.assign({},e),{ifMatch:(null==e?void 0:e.optimisticLockingVersionId)?`W/"${e.optimisticLockingVersionId}"`:void 0}))}))}function $({resourceType:t,id:e,operations:i},s){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}`,"PATCH")(i,Object.assign(Object.assign({},s),{contentType:"application/json-patch+json",ifMatch:(null==s?void 0:s.optimisticLockingVersionId)?`W/"${s.optimisticLockingVersionId}"`:void 0}))}))}function C({resourceType:t,id:e},i){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}`,"DELETE")({},i)}))}function _({resourceType:t,id:e,versionId:i},s){return r(this,void 0,void 0,(function*(){return this.fhirRequest(`/${t}/${e}/_history${i?`/${i}`:""}`,"GET")({},s)}))}function L(t){const{method:e,url:i}=t,s={request:{method:e,url:i}};if(i.split("?").length>1){const[t,e]=i.split("?"),r=e.split("&").map((t=>{const[e,i]=t.split("=");return{name:e,value:i}})).reduce(((t,{name:e,value:i})=>e?(t[e]||(t[e]=[]),t[e].push(i),t):t),{}),n=new URLSearchParams;d(r,n),s.request.url=`${t}?${n.toString()}`}if(["GET","DELETE","HEAD"].includes(e))return s;if("PUT"===e){const{resource:e}=t;return Object.assign(Object.assign({},s),{resource:e})}if("PATCH"===e)return"resource"in t?Object.assign(Object.assign({},s),{resource:t.resource}):Object.assign(Object.assign({},s),{resource:{resourceType:"Binary",contentType:"application/json-patch+json",data:Buffer.from(JSON.stringify(t.operations),"utf8").toString("base64")}});if("POST"===e){const{resource:e,fullUrl:i}=t;return Object.assign(Object.assign({},s),{resource:e,fullUrl:i})}throw new Error("Unrecognized method")}function M(t){return function(e,i){return r(this,void 0,void 0,(function*(){return this.fhirRequest("/","POST")({resourceType:"Bundle",type:t,entry:e.requests.map(L)},i)}))}}O=new WeakSet,T=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.faxApiUrl)&&void 0!==e?e:"https://fax-api.zapehr.com/v1"};const D=M("batch"),V=M("transaction");function F(t,e){const i=[];if(t.line&&i.push(...t.line),t.city||t.state||t.postalCode){const e=[];t.city&&e.push(t.city),t.state&&e.push(t.state),t.postalCode&&e.push(t.postalCode),i.push(e.join(", "))}return t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&i.push("["+t.use+"]"),i.join((null==e?void 0:e.lineSeparator)||", ").trim()}function H(t,e){const i=[];return t.prefix&&!1!==(null==e?void 0:e.prefix)&&i.push(...t.prefix),t.given&&i.push(...t.given),t.family&&i.push(t.family),t.suffix&&!1!==(null==e?void 0:e.suffix)&&i.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&i.push("["+t.use+"]"),i.join(" ").trim()}var B,G,J,X,Z,K,Q,Y,tt,et,it,st,rt,nt,ot,ut,ct,ht,at,dt,lt,pt,vt,mt,ft,gt,bt,yt,qt,jt,wt;class St extends c{constructor(t){super(t),B.add(this),this.search=P,this.create=N,this.get=I,this.update=W,this.patch=$,this.delete=C,this.history=_,this.batch=D,this.transaction=V,this.formatAddress=F,this.formatHumanName=H}}B=new WeakSet;class Ut extends c{constructor(t){super(t),G.add(this)}routeList(t){return this.request("/route","get",n(this,G,"m",J).bind(this))(t)}routeCreate(t,e){return this.request("/route","post",n(this,G,"m",J).bind(this))(t,e)}routeDelete(t,e){return this.request("/route/{routeGuid}","delete",n(this,G,"m",J).bind(this))(t,e)}orderableItemList(t,e){return this.request("/orderableItem","get",n(this,G,"m",J).bind(this))(t,e)}orderableItemQuestionnaireGet(t,e){return this.request("/canonical-questionnaire/lab/{labGuid}/compendium/{compendiumVersion}/item/{itemCode}/questionnaire","get",n(this,G,"m",J).bind(this))(t,e)}orderSubmit(t,e){return this.request("/submit","post",n(this,G,"m",J).bind(this))(t,e)}}G=new WeakSet,J=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.labApiUrl)&&void 0!==e?e:"https://labs-api.zapehr.com/v1"};class kt extends c{constructor(t){super(t),X.add(this)}list(t){return this.request("/m2m","get",n(this,X,"m",Z).bind(this))(t)}create(t,e){return this.request("/m2m","post",n(this,X,"m",Z).bind(this))(t,e)}get(t,e){return this.request("/m2m/{id}","get",n(this,X,"m",Z).bind(this))(t,e)}update(t,e){return this.request("/m2m/{id}","patch",n(this,X,"m",Z).bind(this))(t,e)}delete(t,e){return this.request("/m2m/{id}","delete",n(this,X,"m",Z).bind(this))(t,e)}rotateSecret(t,e){return this.request("/m2m/{id}/rotate-secret","post",n(this,X,"m",Z).bind(this))(t,e)}listV2(t,e){return this.request("/m2m/v2/list","get",n(this,X,"m",Z).bind(this))(t,e)}}X=new WeakSet,Z=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class xt extends c{constructor(t){super(t),K.add(this)}getMessagingConfig(t){return this.request("/messaging/config","get",n(this,K,"m",Q).bind(this))(t)}}K=new WeakSet,Q=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Ot extends c{constructor(t){super(t),Y.add(this)}setUp(t,e){return this.request("/payment/payment-method/setup","post",n(this,Y,"m",tt).bind(this))(t,e)}setDefault(t,e){return this.request("/payment/payment-method/set-default","post",n(this,Y,"m",tt).bind(this))(t,e)}delete(t,e){return this.request("/payment/payment-method","delete",n(this,Y,"m",tt).bind(this))(t,e)}list(t,e){return this.request("/payment/payment-method/list","post",n(this,Y,"m",tt).bind(this))(t,e)}}Y=new WeakSet,tt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Tt extends c{constructor(t){super(t),et.add(this)}get(t){return this.request("/project","get",n(this,et,"m",it).bind(this))(t)}update(t,e){return this.request("/project","patch",n(this,et,"m",it).bind(this))(t,e)}}et=new WeakSet,it=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Et extends c{constructor(t){super(t),st.add(this)}eligibilityCheck(t,e){return this.request("/rcm/eligibility-check","post",n(this,st,"m",rt).bind(this))(t,e)}validateProfessionalClaim(t,e){return this.request("/rcm/professional-claim/validate","post",n(this,st,"m",rt).bind(this))(t,e)}submitProfessionalClaim(t,e){return this.request("/rcm/professional-claim/submit","post",n(this,st,"m",rt).bind(this))(t,e)}}st=new WeakSet,rt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class zt extends c{constructor(t){super(t),nt.add(this)}list(t){return this.request("/iam/role","get",n(this,nt,"m",ot).bind(this))(t)}create(t,e){return this.request("/iam/role","post",n(this,nt,"m",ot).bind(this))(t,e)}get(t,e){return this.request("/iam/role/{roleId}","get",n(this,nt,"m",ot).bind(this))(t,e)}update(t,e){return this.request("/iam/role/{roleId}","patch",n(this,nt,"m",ot).bind(this))(t,e)}delete(t,e){return this.request("/iam/role/{roleId}","delete",n(this,nt,"m",ot).bind(this))(t,e)}}nt=new WeakSet,ot=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class At extends c{constructor(t){super(t),ut.add(this)}list(t){return this.request("/secret","get",n(this,ut,"m",ct).bind(this))(t)}set(t,e){return this.request("/secret","post",n(this,ut,"m",ct).bind(this))(t,e)}get(t,e){return this.request("/secret/{name}","get",n(this,ut,"m",ct).bind(this))(t,e)}delete(t,e){return this.request("/secret/{name}","delete",n(this,ut,"m",ct).bind(this))(t,e)}}ut=new WeakSet,ct=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Rt extends c{constructor(t){super(t),ht.add(this)}createMeeting(t,e){return this.request("/telemed/v2/meeting","post",n(this,ht,"m",at).bind(this))(t,e)}joinMeeting(t,e){return this.request("/telemed/v2/meeting/{encounterId}/join","get",n(this,ht,"m",at).bind(this))(t,e)}}ht=new WeakSet,at=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Pt extends c{constructor(t){super(t),dt.add(this)}send(t,e){return this.request("/messaging/transactional-sms/send","post",n(this,dt,"m",lt).bind(this))(t,e)}}dt=new WeakSet,lt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Nt extends c{constructor(t){super(t),pt.add(this)}me(t){return this.request("/user/me","get",n(this,pt,"m",vt).bind(this))(t)}get(t,e){return this.request("/user/{id}","get",n(this,pt,"m",vt).bind(this))(t,e)}update(t,e){return this.request("/user/{id}","patch",n(this,pt,"m",vt).bind(this))(t,e)}delete(t,e){return this.request("/user/{id}","delete",n(this,pt,"m",vt).bind(this))(t,e)}invite(t,e){return this.request("/user/invite","post",n(this,pt,"m",vt).bind(this))(t,e)}list(t){return this.request("/user","get",n(this,pt,"m",vt).bind(this))(t)}listV2(t,e){return this.request("/user/v2/list","get",n(this,pt,"m",vt).bind(this))(t,e)}}pt=new WeakSet,vt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class It extends c{constructor(t){super(t),mt.add(this)}get(t){return this.request("/version","get",n(this,mt,"m",ft).bind(this))(t)}}function Wt(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"}function $t({bucketName:t,"objectPath+":e,file:i}){return r(this,void 0,void 0,(function*(){const s=yield this.request("/z3/{bucketName}/{objectPath+}","post",Wt.bind(this))({action:"upload",bucketName:t,"objectPath+":e});yield fetch(s.signedUrl,{method:"PUT",body:i})}))}function Ct({bucketName:t,"objectPath+":e}){return r(this,void 0,void 0,(function*(){const i=yield this.request("/z3/{bucketName}/{objectPath+}","post",Wt.bind(this))({action:"download",bucketName:t,"objectPath+":e}),s=yield fetch(i.signedUrl,{method:"GET"});if(!s.ok)throw new Error("Failed to download file");return s.arrayBuffer()}))}function _t(t){var i,s;return r(this,void 0,void 0,(function*(){let r,n;const o=new URL(t.url);if("z3:"===o.protocol){const t=o.pathname.split("/").slice(1);r=o.hostname,n=t.join("/")}else{if(!o.href.startsWith(null!==(s=null===(i=this.config.services)||void 0===i?void 0:i.projectApiUrl)&&void 0!==s?s:"https://project-api.zapehr.com/v1"))throw new e({message:"Invalid Z3 URL",code:400});{const t=o.pathname.split("/").slice(3);r=t[0],n=t.slice(1).join("/")}}const u={action:"upload",bucketName:r,"objectPath+":n};return this.request("/z3/{bucketName}/{objectPath+}","post",Wt.bind(this))(u)}))}mt=new WeakSet,ft=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Lt extends c{constructor(t){super(t),gt.add(this),this.uploadFile=$t,this.downloadFile=Ct,this.getPresignedUrlForZ3Url=_t}listBuckets(t){return this.request("/z3","get",n(this,gt,"m",bt).bind(this))(t)}createBucket(t,e){return this.request("/z3/{bucketName}","put",n(this,gt,"m",bt).bind(this))(t,e)}deleteBucket(t,e){return this.request("/z3/{bucketName}","delete",n(this,gt,"m",bt).bind(this))(t,e)}listObjects(t,e){return this.request("/z3/{bucketName}/{objectPath+}","get",n(this,gt,"m",bt).bind(this))(t,e)}getPresignedUrl(t,e){return this.request("/z3/{bucketName}/{objectPath+}","post",n(this,gt,"m",bt).bind(this))(t,e)}deleteObject(t,e){return this.request("/z3/{bucketName}/{objectPath+}","delete",n(this,gt,"m",bt).bind(this))(t,e)}}function Mt(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"}function Dt({id:t,file:e,filename:i}){return r(this,void 0,void 0,(function*(){const s=yield this.request("/zambda/{id}/s3-upload","post",Mt.bind(this))({id:t,filename:i});yield fetch(s.signedUrl,{method:"PUT",body:e})}))}gt=new WeakSet,bt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Vt extends c{constructor(t){super(t),yt.add(this),this.uploadFile=Dt}list(t){return this.request("/zambda","get",n(this,yt,"m",qt).bind(this))(t)}create(t,e){return this.request("/zambda","post",n(this,yt,"m",qt).bind(this))(t,e)}get(t,e){return this.request("/zambda/{id}","get",n(this,yt,"m",qt).bind(this))(t,e)}update(t,e){return this.request("/zambda/{id}","patch",n(this,yt,"m",qt).bind(this))(t,e)}delete(t,e){return this.request("/zambda/{id}","delete",n(this,yt,"m",qt).bind(this))(t,e)}execute(t,e){return this.request("/zambda/{id}/execute","post",n(this,yt,"m",qt).bind(this))(t,e)}executePublic(t,e){return this.request("/zambda/{id}/execute-public","post",n(this,yt,"m",qt).bind(this))(t,e)}s3Upload(t,e){return this.request("/zambda/{id}/s3-upload","post",n(this,yt,"m",qt).bind(this))(t,e)}}yt=new WeakSet,qt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};class Ft extends c{constructor(t){super(t),jt.add(this)}list(t,e){return this.request("/zambda/{id}/logStream","post",n(this,jt,"m",wt).bind(this))(t,e)}search(t,e){return this.request("/zambda/{id}/logStream/search","post",n(this,jt,"m",wt).bind(this))(t,e)}get(t,e){return this.request("/zambda/{id}/logStream/{logStreamName}","post",n(this,jt,"m",wt).bind(this))(t,e)}}jt=new WeakSet,wt=function(){var t,e;return null!==(e=null===(t=this.config.services)||void 0===t?void 0:t.projectApiUrl)&&void 0!==e?e:"https://project-api.zapehr.com/v1"};let Ht=class{constructor(t){var e,i,s,r,n,o;this.config=t,null!==(e=(r=this.config).services)&&void 0!==e||(r.services={}),null!==(i=(n=this.config.services).projectApiUrl)&&void 0!==i||(n.projectApiUrl=t.projectApiUrl),null!==(s=(o=this.config.services).fhirApiUrl)&&void 0!==s||(o.fhirApiUrl=t.fhirApiUrl),this.application=new f(t),this.developer=new z(t),this.m2m=new kt(t),this.messaging=new xt(t),this.conversation=new E(t),this.transactionalSMS=new Pt(t),this.paymentMethod=new Ot(t),this.charge=new g(t),this.project=new Tt(t),this.rcm=new Et(t),this.erx=new A(t),this.role=new zt(t),this.secret=new At(t),this.telemed=new Rt(t),this.user=new Nt(t),this.version=new It(t),this.z3=new Lt(t),this.zambda=new Vt(t),this.zambdaLogStream=new Ft(t),this.fax=new R(t),this.lab=new Ut(t),this.fhir=new St(t)}};class Bt extends Ht{}Bt.OystehrFHIRError=s,Bt.OystehrSdkError=e,module.exports=Bt;
2
2
  //# sourceMappingURL=index.min.cjs.map