@medplum/cli 4.1.0 → 4.1.2

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.
@@ -19,7 +19,7 @@ PID|1|12345|12345^^^HOSP^MR|123456|DOE^JOHN^MIDDLE^SUFFIX|19800101|M|||123 STREE
19
19
  PV1|1|I|2000^2012^01||||12345^DOCTOR^DOC||||||||||1234567^DOCTOR^DOC||AMB|||||||||||||||||||||||||202309280900|`}import{readdirSync as bp}from"node:fs";import{homedir as vp}from"node:os";import{resolve as Pp}from"node:path";var Ts=new g("set"),Os=new g("remove"),xs=new g("list"),$s=new g("describe"),ce=new g("profile");y(ce,Ts);y(ce,Os);y(ce,xs);y(ce,$s);Ts.argument("<profileName>","Name of the profile").description("Create a new profile or replace it with the given name and its associated properties").action(async(t,e)=>{ke(t,e)});Os.argument("<profileName>","Name of the profile").description("Remove a profile by name").action(async t=>{new k(t).setObject("options",void 0),console.log(`${t} profile removed`)});xs.description("List all profiles saved").action(async()=>{let t=Pp(vp(),".medplum"),e=bp(t),r=[];e.forEach(o=>{let n=o.split(".")[0],i=new k(n).getObject("options");i&&r.push({profileName:n,profile:i})}),console.log(r)});$s.argument("<profileName>","Name of the profile").description("Describes a profile").action(async t=>{let e=Hr(t);console.log(e)});import{Option as Cp}from"commander";var Ns=new g("list"),Ls=new g("current"),Ds=new g("switch"),ks=new g("invite"),le=new g("project");y(le,Ns);y(le,Ls);y(le,Ds);y(le,ks);Ns.description("List of current projects").action(async t=>{let e=await R(t);Tp(e)});function Tp(t){let r=t.getLogins().map(o=>`${o.project.display} (${o.project.reference})`).join(`
20
20
 
21
21
  `);console.log(r)}Ls.description("Project you are currently on").action(async t=>{let r=(await R(t)).getActiveLogin();if(!r)throw new Error("Unauthenticated: run `npx medplum login` to login");console.log(`${r.project.display} (${r.project.reference})`)});Ds.description("Switching to another project from the current one").argument("<projectId>").action(async(t,e)=>{let r=await R(e);await Op(r,t)});ks.description("Invite a member to your current project (run npx medplum project current to confirm)").arguments("<firstName> <lastName> <email>").option("--send-email","If you want to send the email when inviting the user").option("--admin","If the user you are inviting is an admin").addOption(new Cp("-r, --role <role>","Role of user").choices(["Practitioner","Patient","RelatedPerson"]).default("Practitioner")).action(async(t,e,r,o)=>{let n=await R(o),s=n.getActiveLogin();if(!s)throw new Error("Unauthenticated: run `npx medplum login` to login");if(!s?.project?.reference)throw new Error("No current project to invite user to");let i=s.project.reference.split("/")[1],c={resourceType:o.role,firstName:t,lastName:e,email:r,sendEmail:!!o.sendEmail,admin:!!o.admin};await xp(i,c,n)});async function Op(t,e){let o=t.getLogins().find(n=>n.project.reference?.includes(e));if(!o)throw new Error(`Project ${e} not found. Make sure you are added as a user to this project`);await t.setActiveLogin(o),console.log(`Switched to project ${e}
22
- `)}async function xp(t,e,r){await r.invite(t,e),e.sendEmail&&console.log("Email sent"),console.log("See your users at https://app.medplum.com/admin/users")}import{convertToTransactionBundle as $p}from"@medplum/core";var nr=new g("delete"),sr=new g("get"),ir=new g("patch"),ar=new g("post"),cr=new g("put");nr.argument("<url>","Resource/$id").action(async(t,e)=>{let r=await R(e);K(await r.delete(Pe(r,t)))});sr.argument("<url>","Resource/$id").option("--as-transaction","Print out the bundle as a transaction type").action(async(t,e)=>{let r=await R(e),o=await r.get(Pe(r,t));e.asTransaction?K($p(o)):K(o)});ir.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);K(await o.patch(Pe(o,t),lr(e)))});ar.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);K(await o.post(Pe(o,t),lr(e)))});cr.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);K(await o.put(Pe(o,t),lr(e)))});function lr(t){if(t)try{return JSON.parse(t)}catch{return t}}function Pe(t,e){return["admin/","auth/","fhir/R4"].some(o=>e.startsWith(o))?e:t.fhirUrl(e).toString()}async function kp(t){let e=new g("medplum").description("Command to access Medplum CLI").option("--client-id <clientId>","FHIR server client id").option("--client-secret <clientSecret>","FHIR server client secret").option("--base-url <baseUrl>","FHIR server base URL, must be absolute").option("--token-url <tokenUrl>","FHIR server token URL, absolute or relative to base URL").option("--authorize-url <authorizeUrl>","FHIR server authorize URL, absolute or relative to base URL").option("--fhir-url, --fhir-url-path <fhirUrlPath>","FHIR server URL, absolute or relative to base URL").option("--scope <scope>","JWT scope").option("--access-token <accessToken>","Access token for token exchange authentication").option("--callback-url <callbackUrl>","Callback URL for authorization code flow").option("--subject <subject>","Subject for JWT authentication").option("--audience <audience>","Audience for JWT authentication").option("--issuer <issuer>","Issuer for JWT authentication").option("--private-key-path <privateKeyPath>","Private key path for JWT assertion").option("-p, --profile <profile>","Profile name").option("-v --verbose","Verbose output").addOption(new Lp("--auth-type <authType>","Type of authentication").choices(["basic","client-credentials","authorization-code","jwt-bearer","token-exchange","jwt-assertion"])).on("option:verbose",()=>{process.env.VERBOSE="1"});e.exitOverride(),e.version(Np),e.configureHelp({showGlobalOptions:!0}),y(e,xt),y(e,$t),y(e,Nt),y(e,sr),y(e,ar),y(e,ir),y(e,cr),y(e,nr),y(e,le),y(e,it),y(e,ve),y(e,Y),y(e,tr),y(e,rr),y(e,or),y(e,ce),y(e,fs()),y(e,ct);try{await e.parseAsync(t)}catch(r){Mp(r)}}function Mp(t){let e=1,r=!0;if(t instanceof Ms&&(process.env.VERBOSE||(r=!1),e=t.exitCode),e!==0&&r){ur(t,!!process.env.VERBOSE);let o=t.cause;if(process.env.VERBOSE)if(Array.isArray(o))for(let n of o)ur(n,!0);else o instanceof Error&&ur(o,!0)}process.exit(e)}function ur(t,e=!1){if(e){console.error(t);return}t instanceof Ms?process.stderr.write(`${pr(t)}
22
+ `)}async function xp(t,e,r){await r.invite(t,e),e.sendEmail&&console.log("Email sent"),console.log("See your users at https://app.medplum.com/admin/users")}import{convertToTransactionBundle as $p}from"@medplum/core";var nr=new g("delete"),sr=new g("get"),ir=new g("patch"),ar=new g("post"),cr=new g("put");nr.argument("<url>","Resource/$id").action(async(t,e)=>{let r=await R(e);K(await r.delete(Pe(r,t)))});sr.argument("<url>","Resource/$id").option("--as-transaction","Print out the bundle as a transaction type").action(async(t,e)=>{let r=await R(e),o=await r.get(Pe(r,t));e.asTransaction?K($p(o)):K(o)});ir.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);K(await o.patch(Pe(o,t),lr(e)))});ar.arguments("<url> <body>").option("--prefer-async",'Sets the Prefer header to "respond-async"').action(async(t,e,r)=>{let o=await R(r),n=r.preferAsync?{Prefer:"respond-async"}:void 0;K(await o.post(Pe(o,t),lr(e),void 0,{headers:n}))});cr.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);K(await o.put(Pe(o,t),lr(e)))});function lr(t){if(t)try{return JSON.parse(t)}catch{return t}}function Pe(t,e){return["admin/","auth/","fhir/R4"].some(o=>e.startsWith(o))?e:t.fhirUrl(e).toString()}async function kp(t){let e=new g("medplum").description("Command to access Medplum CLI").option("--client-id <clientId>","FHIR server client id").option("--client-secret <clientSecret>","FHIR server client secret").option("--base-url <baseUrl>","FHIR server base URL, must be absolute").option("--token-url <tokenUrl>","FHIR server token URL, absolute or relative to base URL").option("--authorize-url <authorizeUrl>","FHIR server authorize URL, absolute or relative to base URL").option("--fhir-url, --fhir-url-path <fhirUrlPath>","FHIR server URL, absolute or relative to base URL").option("--scope <scope>","JWT scope").option("--access-token <accessToken>","Access token for token exchange authentication").option("--callback-url <callbackUrl>","Callback URL for authorization code flow").option("--subject <subject>","Subject for JWT authentication").option("--audience <audience>","Audience for JWT authentication").option("--issuer <issuer>","Issuer for JWT authentication").option("--private-key-path <privateKeyPath>","Private key path for JWT assertion").option("-p, --profile <profile>","Profile name").option("-v --verbose","Verbose output").addOption(new Lp("--auth-type <authType>","Type of authentication").choices(["basic","client-credentials","authorization-code","jwt-bearer","token-exchange","jwt-assertion"])).on("option:verbose",()=>{process.env.VERBOSE="1"});e.exitOverride(),e.version(Np),e.configureHelp({showGlobalOptions:!0}),y(e,xt),y(e,$t),y(e,Nt),y(e,sr),y(e,ar),y(e,ir),y(e,cr),y(e,nr),y(e,le),y(e,it),y(e,ve),y(e,Y),y(e,tr),y(e,rr),y(e,or),y(e,ce),y(e,fs()),y(e,ct);try{await e.parseAsync(t)}catch(r){Mp(r)}}function Mp(t){let e=1,r=!0;if(t instanceof Ms&&(process.env.VERBOSE||(r=!1),e=t.exitCode),e!==0&&r){ur(t,!!process.env.VERBOSE);let o=t.cause;if(process.env.VERBOSE)if(Array.isArray(o))for(let n of o)ur(n,!0);else o instanceof Error&&ur(o,!0)}process.exit(e)}function ur(t,e=!1){if(e){console.error(t);return}t instanceof Ms?process.stderr.write(`${pr(t)}
23
23
  `):process.stderr.write(`Error: ${pr(t)}
24
24
  `)}async function _p(){Dp.config(),await kp(process.argv)}dr.main===module&&_p().catch(t=>{console.error("Unhandled error:",pr(t)),process.exit(1)});export{Mp as handleError,kp as main,_p as run};
25
25
  //# sourceMappingURL=index.mjs.map