@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|`}var di=require("node:fs"),mi=require("node:os"),fi=require("node:path");var hi=new g("set"),gi=new g("remove"),yi=new g("list"),wi=new g("describe"),Ae=new g("profile");y(Ae,hi);y(Ae,gi);y(Ae,yi);y(Ae,wi);hi.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)=>{et(t,e)});gi.argument("<profileName>","Name of the profile").description("Remove a profile by name").action(async t=>{new j(t).setObject("options",void 0),console.log(`${t} profile removed`)});yi.description("List all profiles saved").action(async()=>{let t=(0,fi.resolve)((0,mi.homedir)(),".medplum"),e=(0,di.readdirSync)(t),r=[];e.forEach(o=>{let n=o.split(".")[0],i=new j(n).getObject("options");i&&r.push({profileName:n,profile:i})}),console.log(r)});wi.argument("<profileName>","Name of the profile").description("Describes a profile").action(async t=>{let e=go(t);console.log(e)});var Ei=require("commander");var Si=new g("list"),Ri=new g("current"),Ai=new g("switch"),Ii=new g("invite"),Ie=new g("project");y(Ie,Si);y(Ie,Ri);y(Ie,Ai);y(Ie,Ii);Si.description("List of current projects").action(async t=>{let e=await R(t);zu(e)});function zu(t){let r=t.getLogins().map(o=>`${o.project.display} (${o.project.reference})`).join(`
20
20
 
21
21
  `);console.log(r)}Ri.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})`)});Ai.description("Switching to another project from the current one").argument("<projectId>").action(async(t,e)=>{let r=await R(e);await Yu(r,t)});Ii.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 Ei.Option("-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 Zu(i,c,n)});async function Yu(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 Zu(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")}var bi=require("@medplum/core");var Or=new g("delete"),xr=new g("get"),$r=new g("patch"),Nr=new g("post"),Lr=new g("put");Or.argument("<url>","Resource/$id").action(async(t,e)=>{let r=await R(e);J(await r.delete(qe(r,t)))});xr.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(qe(r,t));e.asTransaction?J((0,bi.convertToTransactionBundle)(o)):J(o)});$r.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);J(await o.patch(qe(o,t),Dr(e)))});Nr.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);J(await o.post(qe(o,t),Dr(e)))});Lr.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);J(await o.put(qe(o,t),Dr(e)))});function Dr(t){if(t)try{return JSON.parse(t)}catch{return t}}function qe(t,e){return["admin/","auth/","fhir/R4"].some(o=>e.startsWith(o))?e:t.fhirUrl(e).toString()}async function Pi(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 He.Option("--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(be.MEDPLUM_VERSION),e.configureHelp({showGlobalOptions:!0}),y(e,Zt),y(e,Qt),y(e,er),y(e,xr),y(e,Nr),y(e,$r),y(e,Lr),y(e,Or),y(e,Ie),y(e,xt),y(e,Ke),y(e,ie),y(e,br),y(e,vr),y(e,Pr),y(e,Ae),y(e,Xs()),y(e,Lt);try{await e.parseAsync(t)}catch(r){Ci(r)}}function Ci(t){let e=1,r=!0;if(t instanceof He.CommanderError&&(process.env.VERBOSE||(r=!1),e=t.exitCode),e!==0&&r){kr(t,!!process.env.VERBOSE);let o=t.cause;if(process.env.VERBOSE)if(Array.isArray(o))for(let n of o)kr(n,!0);else o instanceof Error&&kr(o,!0)}process.exit(e)}function kr(t,e=!1){if(e){console.error(t);return}t instanceof He.CommanderError?process.stderr.write(`${(0,be.normalizeErrorString)(t)}
22
+ `)}async function Zu(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")}var bi=require("@medplum/core");var Or=new g("delete"),xr=new g("get"),$r=new g("patch"),Nr=new g("post"),Lr=new g("put");Or.argument("<url>","Resource/$id").action(async(t,e)=>{let r=await R(e);J(await r.delete(qe(r,t)))});xr.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(qe(r,t));e.asTransaction?J((0,bi.convertToTransactionBundle)(o)):J(o)});$r.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);J(await o.patch(qe(o,t),Dr(e)))});Nr.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;J(await o.post(qe(o,t),Dr(e),void 0,{headers:n}))});Lr.arguments("<url> <body>").action(async(t,e,r)=>{let o=await R(r);J(await o.put(qe(o,t),Dr(e)))});function Dr(t){if(t)try{return JSON.parse(t)}catch{return t}}function qe(t,e){return["admin/","auth/","fhir/R4"].some(o=>e.startsWith(o))?e:t.fhirUrl(e).toString()}async function Pi(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 He.Option("--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(be.MEDPLUM_VERSION),e.configureHelp({showGlobalOptions:!0}),y(e,Zt),y(e,Qt),y(e,er),y(e,xr),y(e,Nr),y(e,$r),y(e,Lr),y(e,Or),y(e,Ie),y(e,xt),y(e,Ke),y(e,ie),y(e,br),y(e,vr),y(e,Pr),y(e,Ae),y(e,Xs()),y(e,Lt);try{await e.parseAsync(t)}catch(r){Ci(r)}}function Ci(t){let e=1,r=!0;if(t instanceof He.CommanderError&&(process.env.VERBOSE||(r=!1),e=t.exitCode),e!==0&&r){kr(t,!!process.env.VERBOSE);let o=t.cause;if(process.env.VERBOSE)if(Array.isArray(o))for(let n of o)kr(n,!0);else o instanceof Error&&kr(o,!0)}process.exit(e)}function kr(t,e=!1){if(e){console.error(t);return}t instanceof He.CommanderError?process.stderr.write(`${(0,be.normalizeErrorString)(t)}
23
23
  `):process.stderr.write(`Error: ${(0,be.normalizeErrorString)(t)}
24
24
  `)}async function Ti(){vi.default.config(),await Pi(process.argv)}require.main===module&&Ti().catch(t=>{console.error("Unhandled error:",(0,be.normalizeErrorString)(t)),process.exit(1)});0&&(module.exports={handleError,main,run});
25
25
  //# sourceMappingURL=index.cjs.map