@medplum/cli 2.0.14 → 2.0.16

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,145 +1,223 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ var commander = require('commander');
4
5
  var core = require('@medplum/core');
5
- var child_process = require('child_process');
6
- var dotenv = require('dotenv');
7
6
  var fs = require('fs');
8
- var http = require('http');
9
- var fetch = require('node-fetch');
10
7
  var os = require('os');
11
8
  var path = require('path');
9
+ var dotenv = require('dotenv');
10
+ var child_process = require('child_process');
11
+ var http = require('http');
12
12
 
13
- /******************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
-
28
- function __classPrivateFieldGet(receiver, state, kind, f) {
29
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
30
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
31
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
32
- }
33
-
34
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
35
- if (kind === "m") throw new TypeError("Private method is not writable");
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
38
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
39
- }
40
-
41
- var _FileSystemStorage_instances, _FileSystemStorage_dirName, _FileSystemStorage_fileName, _FileSystemStorage_readFile, _FileSystemStorage_writeFile;
42
13
  class FileSystemStorage extends core.ClientStorage {
43
14
  constructor() {
44
15
  super();
45
- _FileSystemStorage_instances.add(this);
46
- _FileSystemStorage_dirName.set(this, void 0);
47
- _FileSystemStorage_fileName.set(this, void 0);
48
- __classPrivateFieldSet(this, _FileSystemStorage_dirName, path.resolve(os.homedir(), '.medplum'), "f");
49
- __classPrivateFieldSet(this, _FileSystemStorage_fileName, path.resolve(__classPrivateFieldGet(this, _FileSystemStorage_dirName, "f"), 'credentials'), "f");
16
+ this.dirName = path.resolve(os.homedir(), '.medplum');
17
+ this.fileName = path.resolve(this.dirName, 'credentials');
50
18
  }
51
19
  clear() {
52
- __classPrivateFieldGet(this, _FileSystemStorage_instances, "m", _FileSystemStorage_writeFile).call(this, {});
20
+ this.writeFile({});
53
21
  }
54
22
  getString(key) {
55
- return __classPrivateFieldGet(this, _FileSystemStorage_instances, "m", _FileSystemStorage_readFile).call(this)?.[key];
23
+ return this.readFile()?.[key];
56
24
  }
57
25
  setString(key, value) {
58
- const data = __classPrivateFieldGet(this, _FileSystemStorage_instances, "m", _FileSystemStorage_readFile).call(this) || {};
26
+ const data = this.readFile() || {};
59
27
  if (value) {
60
28
  data[key] = value;
61
29
  }
62
30
  else {
63
31
  delete data[key];
64
32
  }
65
- __classPrivateFieldGet(this, _FileSystemStorage_instances, "m", _FileSystemStorage_writeFile).call(this, data);
33
+ this.writeFile(data);
66
34
  }
67
- }
68
- _FileSystemStorage_dirName = new WeakMap(), _FileSystemStorage_fileName = new WeakMap(), _FileSystemStorage_instances = new WeakSet(), _FileSystemStorage_readFile = function _FileSystemStorage_readFile() {
69
- if (fs.existsSync(__classPrivateFieldGet(this, _FileSystemStorage_fileName, "f"))) {
70
- return JSON.parse(fs.readFileSync(__classPrivateFieldGet(this, _FileSystemStorage_fileName, "f"), 'utf8'));
35
+ readFile() {
36
+ if (fs.existsSync(this.fileName)) {
37
+ return JSON.parse(fs.readFileSync(this.fileName, 'utf8'));
38
+ }
39
+ return undefined;
71
40
  }
72
- return undefined;
73
- }, _FileSystemStorage_writeFile = function _FileSystemStorage_writeFile(data) {
74
- if (!fs.existsSync(__classPrivateFieldGet(this, _FileSystemStorage_dirName, "f"))) {
75
- fs.mkdirSync(__classPrivateFieldGet(this, _FileSystemStorage_dirName, "f"));
41
+ writeFile(data) {
42
+ if (!fs.existsSync(this.dirName)) {
43
+ fs.mkdirSync(this.dirName);
44
+ }
45
+ fs.writeFileSync(this.fileName, JSON.stringify(data, null, 2), 'utf8');
76
46
  }
77
- fs.writeFileSync(__classPrivateFieldGet(this, _FileSystemStorage_fileName, "f"), JSON.stringify(data, null, 2), 'utf8');
78
- };
47
+ }
79
48
 
80
- const clientId = 'medplum-cli';
81
- const redirectUri = 'http://localhost:9615';
82
- async function main(medplum, argv) {
83
- if (argv.length < 3) {
84
- console.log('Usage: medplum <command>');
49
+ function prettyPrint(input) {
50
+ console.log(JSON.stringify(input, null, 2));
51
+ }
52
+ async function saveBot(medplum, botConfig, bot) {
53
+ const code = readFileContents(botConfig.source);
54
+ if (!code) {
85
55
  return;
86
56
  }
87
- // Legacy support for MEDPLUM_CLIENT_ID and MEDPLUM_CLIENT_SECRET environment variables
88
- const clientId = process.env['MEDPLUM_CLIENT_ID'];
89
- const clientSecret = process.env['MEDPLUM_CLIENT_SECRET'];
90
- if (clientId && clientSecret) {
91
- await medplum.startClientLogin(clientId, clientSecret);
92
- }
93
57
  try {
94
- const command = argv[2].toLowerCase();
95
- switch (command) {
96
- //
97
- // Auth commands
98
- //
99
- case 'login':
100
- await startLogin(medplum);
101
- break;
102
- case 'whoami':
103
- printMe(medplum);
104
- break;
105
- //
106
- // REST commands
107
- //
108
- case 'delete':
109
- prettyPrint(await medplum.delete(cleanUrl(argv[3])));
110
- break;
111
- case 'get':
112
- prettyPrint(await medplum.get(cleanUrl(argv[3])));
113
- break;
114
- case 'patch':
115
- prettyPrint(await medplum.patch(cleanUrl(argv[3]), parseBody(argv[4])));
116
- break;
117
- case 'post':
118
- prettyPrint(await medplum.post(cleanUrl(argv[3]), parseBody(argv[4])));
119
- break;
120
- case 'put':
121
- prettyPrint(await medplum.put(cleanUrl(argv[3]), parseBody(argv[4])));
122
- break;
123
- //
124
- // Bot commands
125
- //
126
- case 'save-bot':
127
- await runBotCommands(medplum, argv, ['save']);
128
- break;
129
- case 'deploy-bot':
130
- await runBotCommands(medplum, argv, ['save', 'deploy']);
131
- break;
132
- case 'create-bot':
133
- await createBot(medplum, argv);
134
- break;
135
- default:
136
- console.log(`Unknown command: ${command}`);
58
+ console.log('Update bot code.....');
59
+ const updateResult = await medplum.updateResource({
60
+ ...bot,
61
+ code,
62
+ });
63
+ if (!updateResult) {
64
+ console.log('Bot not modified');
65
+ }
66
+ else {
67
+ console.log('Success! New bot version: ' + updateResult.meta?.versionId);
137
68
  }
138
69
  }
139
70
  catch (err) {
140
- console.error('Error: ' + core.normalizeErrorString(err));
71
+ console.log('Update error: ', err);
72
+ }
73
+ }
74
+ async function deployBot(medplum, botConfig, bot) {
75
+ const code = readFileContents(botConfig.dist ?? botConfig.source);
76
+ if (!code) {
77
+ return;
78
+ }
79
+ try {
80
+ console.log('Deploying bot...');
81
+ const deployResult = (await medplum.post(medplum.fhirUrl('Bot', bot.id, '$deploy'), {
82
+ code,
83
+ }));
84
+ console.log('Deploy result: ' + deployResult.issue?.[0]?.details?.text);
85
+ }
86
+ catch (err) {
87
+ console.log('Deploy error: ', err);
141
88
  }
142
89
  }
90
+ async function createBot(medplum, argv) {
91
+ if (argv.length < 4) {
92
+ console.log(`Error: command needs to be npx medplum <new-bot-name> <project-id> <source-file> <dist-file>`);
93
+ return;
94
+ }
95
+ const botName = argv[0];
96
+ const projectId = argv[1];
97
+ const sourceFile = argv[2];
98
+ const distFile = argv[3];
99
+ try {
100
+ const body = {
101
+ name: botName,
102
+ description: '',
103
+ };
104
+ const newBot = await medplum.post('admin/projects/' + projectId + '/bot', body);
105
+ const bot = await medplum.readResource('Bot', newBot.id);
106
+ const botConfig = {
107
+ name: botName,
108
+ id: newBot.id,
109
+ source: sourceFile,
110
+ dist: distFile,
111
+ };
112
+ await saveBot(medplum, botConfig, bot);
113
+ console.log(`Success! Bot created: ${bot.id}`);
114
+ addBotToConfig(botConfig);
115
+ }
116
+ catch (err) {
117
+ console.log('Error while creating new bot: ' + err);
118
+ }
119
+ }
120
+ function readBotConfigs(botName) {
121
+ const regExBotName = new RegExp('^' + escapeRegex(botName).replace(/\\\*/g, '.*') + '$');
122
+ const botConfigs = readConfig()?.bots?.filter((b) => regExBotName.test(b.name));
123
+ if (!botConfigs) {
124
+ return [];
125
+ }
126
+ return botConfigs;
127
+ }
128
+ function readConfig() {
129
+ const content = readFileContents('medplum.config.json');
130
+ if (!content) {
131
+ return undefined;
132
+ }
133
+ return JSON.parse(content);
134
+ }
135
+ function readFileContents(fileName) {
136
+ const path$1 = path.resolve(process.cwd(), fileName);
137
+ if (!fs.existsSync(path$1)) {
138
+ console.log('Error: File does not exist: ' + path$1);
139
+ return '';
140
+ }
141
+ return fs.readFileSync(path$1, 'utf8');
142
+ }
143
+ function addBotToConfig(botConfig) {
144
+ const config = readConfig();
145
+ config?.bots?.push(botConfig);
146
+ fs.writeFile('medplum.config.json', JSON.stringify(config), () => {
147
+ console.log(`Bot added to config: ${botConfig.id}`);
148
+ });
149
+ }
150
+ function escapeRegex(str) {
151
+ return str.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
152
+ }
153
+
154
+ const bot = new commander.Command('bot');
155
+ // Commands to deprecate
156
+ const saveBotDeprecate = new commander.Command('save-bot');
157
+ const deployBotDeprecate = new commander.Command('deploy-bot');
158
+ const createBotDeprecate = new commander.Command('create-bot');
159
+ bot
160
+ .command('save')
161
+ .description('Saving the bot')
162
+ .argument('<botName>')
163
+ .action(async (botName) => {
164
+ await botWrapper(exports.medplum, botName);
165
+ });
166
+ bot
167
+ .command('deploy')
168
+ .description('Deploy the app to AWS')
169
+ .argument('<botName>')
170
+ .action(async (botName) => {
171
+ await botWrapper(exports.medplum, botName, true);
172
+ });
173
+ bot
174
+ .command('create')
175
+ .arguments('<botName> <projectId> <sourceFile> <distFile>')
176
+ .description('Creating a bot')
177
+ .action(async (botName, projectId, sourceFile, distFile) => {
178
+ await createBot(exports.medplum, [botName, projectId, sourceFile, distFile]);
179
+ });
180
+ async function botWrapper(medplum, botName, deploy = false) {
181
+ const botConfigs = readBotConfigs(botName);
182
+ for (const botConfig of botConfigs) {
183
+ const bot = await medplum.readResource('Bot', botConfig.id);
184
+ await saveBot(medplum, botConfig, bot);
185
+ if (deploy) {
186
+ await deployBot(medplum, botConfig, bot);
187
+ }
188
+ }
189
+ console.log(`Number of bots deployed: ${botConfigs.length}`);
190
+ }
191
+ // Deprecate bot commands
192
+ saveBotDeprecate
193
+ .description('Saves the bot')
194
+ .argument('<botName>')
195
+ .action(async (botName) => {
196
+ await botWrapper(exports.medplum, botName);
197
+ });
198
+ deployBotDeprecate
199
+ .description('Deploy the bot to AWS')
200
+ .argument('<botName>')
201
+ .action(async (botName) => {
202
+ await botWrapper(exports.medplum, botName, true);
203
+ });
204
+ createBotDeprecate
205
+ .arguments('<botName> <projectId> <sourceFile> <distFile>')
206
+ .description('Creates and saves the bot')
207
+ .action(async (botName, projectId, sourceFile, distFile) => {
208
+ await createBot(exports.medplum, [botName, projectId, sourceFile, distFile]);
209
+ });
210
+
211
+ const clientId = 'medplum-cli';
212
+ const redirectUri = 'http://localhost:9615';
213
+ const login = new commander.Command('login');
214
+ const whoami = new commander.Command('whoami');
215
+ login.action(async () => {
216
+ await startLogin(exports.medplum);
217
+ });
218
+ whoami.action(() => {
219
+ printMe(exports.medplum);
220
+ });
143
221
  async function startLogin(medplum) {
144
222
  await startWebServer(medplum);
145
223
  const loginUrl = new URL('/oauth2/authorize', medplum.getBaseUrl());
@@ -204,6 +282,7 @@ async function openBrowser(url) {
204
282
  function printMe(medplum) {
205
283
  const loginState = medplum.getActiveLogin();
206
284
  if (loginState) {
285
+ console.log(`Server: ${medplum.getBaseUrl()}`);
207
286
  console.log(`Profile: ${loginState.profile?.display} (${loginState.profile?.reference})`);
208
287
  console.log(`Project: ${loginState.project?.display} (${loginState.project?.reference})`);
209
288
  }
@@ -211,15 +290,41 @@ function printMe(medplum) {
211
290
  console.log('Not logged in');
212
291
  }
213
292
  }
214
- function cleanUrl(input) {
215
- const knownPrefixes = ['admin/', 'auth/', 'fhir/R4'];
216
- if (knownPrefixes.some((p) => input.startsWith(p))) {
217
- // If the URL starts with a known prefix, return it as-is
218
- return input;
293
+
294
+ const deleteObject = new commander.Command('delete');
295
+ const get = new commander.Command('get');
296
+ const patch = new commander.Command('patch');
297
+ const post = new commander.Command('post');
298
+ const put = new commander.Command('put');
299
+ deleteObject.argument('<url>', 'Resource/$id').action(async (url) => {
300
+ prettyPrint(await exports.medplum.delete(cleanUrl(url)));
301
+ });
302
+ get
303
+ .argument('<url>', 'Resource/$id')
304
+ .option('--as-transaction', 'Print out the bundle as a transaction type')
305
+ .action(async (url, options) => {
306
+ try {
307
+ const response = await exports.medplum.get(cleanUrl(url));
308
+ if (options.asTransaction) {
309
+ prettyPrint(core.convertToTransactionBundle(response));
310
+ }
311
+ else {
312
+ prettyPrint(response);
313
+ }
219
314
  }
220
- // Otherwise, default to FHIR
221
- return 'fhir/R4/' + input;
222
- }
315
+ catch (err) {
316
+ console.log(err);
317
+ }
318
+ });
319
+ patch.arguments('<url> <body>').action(async (url, body) => {
320
+ prettyPrint(await exports.medplum.patch(cleanUrl(url), parseBody(body)));
321
+ });
322
+ post.arguments('<url> <body>').action(async (url, body) => {
323
+ prettyPrint(await exports.medplum.post(cleanUrl(url), parseBody(body)));
324
+ });
325
+ put.arguments('<url> <body>').action(async (url, body) => {
326
+ prettyPrint(await exports.medplum.put(cleanUrl(url), parseBody(body)));
327
+ });
223
328
  function parseBody(input) {
224
329
  if (!input) {
225
330
  return undefined;
@@ -231,148 +336,99 @@ function parseBody(input) {
231
336
  return input;
232
337
  }
233
338
  }
234
- function prettyPrint(input) {
235
- console.log(JSON.stringify(input, null, 2));
236
- }
237
- async function runBotCommands(medplum, argv, commands) {
238
- if (argv.length < 4) {
239
- console.log(`Usage: medplum ${argv[2]} <bot-name>`);
240
- return;
241
- }
242
- const botName = argv[3];
243
- const botConfigs = readBotConfigs(botName);
244
- if (botConfigs.length === 0) {
245
- console.log(`Error: ${botName} not found`);
246
- return;
247
- }
248
- for (const botConfig of botConfigs) {
249
- await runBotConfig(botConfig, medplum, argv, commands);
250
- }
251
- console.log(`Number of bots deployed: ${botConfigs.length}`);
252
- }
253
- async function runBotConfig(botConfig, medplum, argv, commands) {
254
- let bot;
255
- try {
256
- bot = await medplum.readResource('Bot', botConfig.id);
257
- console.log(`Initialized Bot -> ${bot.name}...`);
258
- }
259
- catch (err) {
260
- console.log('Error: ' + core.normalizeErrorString(err));
261
- return;
262
- }
263
- if (commands.includes('save')) {
264
- await saveBot(medplum, botConfig, bot);
265
- }
266
- if (commands.includes('deploy')) {
267
- await deployBot(medplum, botConfig, bot);
339
+ function cleanUrl(input) {
340
+ const knownPrefixes = ['admin/', 'auth/', 'fhir/R4'];
341
+ if (knownPrefixes.some((p) => input.startsWith(p))) {
342
+ // If the URL starts with a known prefix, return it as-is
343
+ return input;
268
344
  }
345
+ // Otherwise, default to FHIR
346
+ return 'fhir/R4/' + input;
269
347
  }
270
- async function createBot(medplum, argv) {
271
- if (argv.length < 7) {
272
- console.log(`Error: command needs to be npx medplum <new-bot-name> <project-id> <source-file> <dist-file>`);
273
- return;
274
- }
275
- const botName = argv[3];
276
- const projectId = argv[4];
277
- const sourceFile = argv[5];
278
- const distFile = argv[6];
279
- try {
280
- const body = {
281
- name: botName,
282
- description: '',
283
- };
284
- const newBot = await medplum.post('admin/projects/' + projectId + '/bot', body);
285
- const bot = await medplum.readResource('Bot', newBot.id);
286
- const botConfig = {
287
- name: botName,
288
- id: newBot.id,
289
- source: sourceFile,
290
- dist: distFile,
291
- };
292
- await saveBot(medplum, botConfig, bot);
293
- console.log(`Success! Bot created: ${bot.id}`);
294
- addBotToConfig(botConfig);
295
- }
296
- catch (err) {
297
- console.log('Error while creating new bot ', err);
298
- }
348
+
349
+ const project = new commander.Command('project');
350
+ project
351
+ .command('list')
352
+ .description('List of current projects')
353
+ .action(async () => {
354
+ projectList(exports.medplum);
355
+ });
356
+ function projectList(medplum) {
357
+ const logins = medplum.getLogins();
358
+ const projects = logins
359
+ .map((login) => `${login.project.display} (${login.project.reference})`)
360
+ .join('\n\n');
361
+ console.log(projects);
299
362
  }
300
- async function saveBot(medplum, botConfig, bot) {
301
- const code = readFileContents(botConfig.source);
302
- if (!code) {
303
- return;
304
- }
305
- try {
306
- console.log('Update bot code.....');
307
- const updateResult = await medplum.updateResource({
308
- ...bot,
309
- code,
310
- });
311
- if (!updateResult) {
312
- console.log('Bot not modified');
313
- }
314
- else {
315
- console.log('Success! New bot version: ' + updateResult.meta?.versionId);
316
- }
363
+ project
364
+ .command('current')
365
+ .description('Project you are currently on')
366
+ .action(() => {
367
+ const login = exports.medplum.getActiveLogin();
368
+ if (!login) {
369
+ throw new Error('Unauthenticated: run `npx medplum login` to login');
370
+ }
371
+ console.log(`${login.project.display} (${login.project.reference})`);
372
+ });
373
+ project
374
+ .command('switch')
375
+ .description('Switching to another project from the current one')
376
+ .argument('<projectId>')
377
+ .action(async (projectId) => {
378
+ await switchProject(exports.medplum, projectId);
379
+ });
380
+ async function switchProject(medplum, projectId) {
381
+ const logins = medplum.getLogins();
382
+ const login = logins.find((login) => login.project?.reference?.includes(projectId));
383
+ if (!login) {
384
+ console.log(`Error: project ${projectId} not found. Make sure you are added as a user to this project`);
317
385
  }
318
- catch (err) {
319
- console.log('Update error: ', err);
386
+ else {
387
+ await medplum.setActiveLogin(login);
388
+ console.log(`Switched to project ${projectId}\n`);
320
389
  }
321
390
  }
322
- async function deployBot(medplum, botConfig, bot) {
323
- const code = readFileContents(botConfig.dist ?? botConfig.source);
324
- if (!code) {
325
- return;
391
+
392
+ exports.medplum = void 0;
393
+ async function main(medplumClient, argv) {
394
+ exports.medplum = medplumClient;
395
+ // Legacy support for MEDPLUM_CLIENT_ID and MEDPLUM_CLIENT_SECRET environment variables
396
+ const clientId = process.env['MEDPLUM_CLIENT_ID'];
397
+ const clientSecret = process.env['MEDPLUM_CLIENT_SECRET'];
398
+ if (clientId && clientSecret) {
399
+ await exports.medplum.startClientLogin(clientId, clientSecret);
326
400
  }
327
401
  try {
328
- console.log('Deploying bot...');
329
- const deployResult = (await medplum.post(medplum.fhirUrl('Bot', bot.id, '$deploy'), {
330
- code,
331
- }));
332
- console.log('Deploy result: ' + deployResult.issue?.[0]?.details?.text);
402
+ const index = new commander.Command('medplum').description('Command to access Medplum CLI');
403
+ index.version('0.1.0');
404
+ // Auth commands
405
+ index.addCommand(login);
406
+ index.addCommand(whoami);
407
+ // REST commands
408
+ index.addCommand(get);
409
+ index.addCommand(post);
410
+ index.addCommand(patch);
411
+ index.addCommand(put);
412
+ index.addCommand(deleteObject);
413
+ // Project
414
+ index.addCommand(project);
415
+ // Bot Commands
416
+ index.addCommand(bot);
417
+ // Deprecated Bot Commands
418
+ index.addCommand(saveBotDeprecate);
419
+ index.addCommand(deployBotDeprecate);
420
+ index.addCommand(createBotDeprecate);
421
+ await index.parseAsync(argv);
333
422
  }
334
423
  catch (err) {
335
- console.log('Deploy error: ', err);
336
- }
337
- }
338
- function escapeRegex(str) {
339
- return str.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
340
- }
341
- function readBotConfigs(botName) {
342
- const regExBotName = new RegExp('^' + escapeRegex(botName).replace(/\\\*/g, '.*') + '$');
343
- const botConfigs = readConfig()?.bots?.filter((b) => regExBotName.test(b.name));
344
- if (!botConfigs) {
345
- return [];
346
- }
347
- return botConfigs;
348
- }
349
- function readConfig() {
350
- const content = readFileContents('medplum.config.json');
351
- if (!content) {
352
- return undefined;
353
- }
354
- return JSON.parse(content);
355
- }
356
- function readFileContents(fileName) {
357
- const path$1 = path.resolve(process.cwd(), fileName);
358
- if (!fs.existsSync(path$1)) {
359
- console.log('Error: File does not exist: ' + path$1);
360
- return '';
424
+ console.error('Error: ' + core.normalizeErrorString(err));
361
425
  }
362
- return fs.readFileSync(path$1, 'utf8');
363
- }
364
- function addBotToConfig(botConfig) {
365
- const config = readConfig();
366
- config?.bots?.push(botConfig);
367
- fs.writeFile('medplum.config.json', JSON.stringify(config), () => {
368
- console.log(`Bot added to config: ${botConfig.id}`);
369
- });
370
426
  }
371
427
  if (require.main === module) {
372
428
  dotenv.config();
373
429
  const baseUrl = process.env['MEDPLUM_BASE_URL'] || 'https://api.medplum.com/';
374
- const medplum = new core.MedplumClient({ fetch, baseUrl, storage: new FileSystemStorage() });
375
- main(medplum, process.argv).catch((err) => console.error('Unhandled error:', err));
430
+ const medplumClient = new core.MedplumClient({ fetch, baseUrl, storage: new FileSystemStorage() });
431
+ main(medplumClient, process.argv).catch((err) => console.error('Unhandled error:', err));
376
432
  }
377
433
 
378
434
  exports.main = main;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../../node_modules/tslib/tslib.es6.js","../../../src/storage.ts","../../../src/index.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.push(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.push(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n","import { ClientStorage } from '@medplum/core';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { homedir } from 'os';\nimport { resolve } from 'path';\n\nexport class FileSystemStorage extends ClientStorage {\n readonly #dirName: string;\n readonly #fileName: string;\n\n constructor() {\n super();\n this.#dirName = resolve(homedir(), '.medplum');\n this.#fileName = resolve(this.#dirName, 'credentials');\n }\n\n clear(): void {\n this.#writeFile({});\n }\n\n getString(key: string): string | undefined {\n return this.#readFile()?.[key];\n }\n\n setString(key: string, value: string | undefined): void {\n const data = this.#readFile() || {};\n if (value) {\n data[key] = value;\n } else {\n delete data[key];\n }\n this.#writeFile(data);\n }\n\n #readFile(): Record<string, string> | undefined {\n if (existsSync(this.#fileName)) {\n return JSON.parse(readFileSync(this.#fileName, 'utf8'));\n }\n return undefined;\n }\n\n #writeFile(data: Record<string, string>): void {\n if (!existsSync(this.#dirName)) {\n mkdirSync(this.#dirName);\n }\n writeFileSync(this.#fileName, JSON.stringify(data, null, 2), 'utf8');\n }\n}\n","import { getDisplayString, MedplumClient, normalizeErrorString } from '@medplum/core';\nimport { Bot, OperationOutcome } from '@medplum/fhirtypes';\nimport { exec } from 'child_process';\nimport dotenv from 'dotenv';\nimport { existsSync, readFileSync, writeFile } from 'fs';\nimport { createServer } from 'http';\nimport fetch from 'node-fetch';\nimport { platform } from 'os';\nimport { resolve } from 'path';\nimport { FileSystemStorage } from './storage';\n\ninterface MedplumConfig {\n readonly bots?: MedplumBotConfig[];\n}\n\ninterface MedplumBotConfig {\n readonly name: string;\n readonly id: string;\n readonly source: string;\n readonly dist?: string;\n}\n\nconst clientId = 'medplum-cli';\nconst redirectUri = 'http://localhost:9615';\n\nexport async function main(medplum: MedplumClient, argv: string[]): Promise<void> {\n if (argv.length < 3) {\n console.log('Usage: medplum <command>');\n return;\n }\n\n // Legacy support for MEDPLUM_CLIENT_ID and MEDPLUM_CLIENT_SECRET environment variables\n const clientId = process.env['MEDPLUM_CLIENT_ID'];\n const clientSecret = process.env['MEDPLUM_CLIENT_SECRET'];\n if (clientId && clientSecret) {\n await medplum.startClientLogin(clientId, clientSecret);\n }\n\n try {\n const command = argv[2].toLowerCase();\n switch (command) {\n //\n // Auth commands\n //\n case 'login':\n await startLogin(medplum);\n break;\n case 'whoami':\n printMe(medplum);\n break;\n //\n // REST commands\n //\n case 'delete':\n prettyPrint(await medplum.delete(cleanUrl(argv[3])));\n break;\n case 'get':\n prettyPrint(await medplum.get(cleanUrl(argv[3])));\n break;\n case 'patch':\n prettyPrint(await medplum.patch(cleanUrl(argv[3]), parseBody(argv[4])));\n break;\n case 'post':\n prettyPrint(await medplum.post(cleanUrl(argv[3]), parseBody(argv[4])));\n break;\n case 'put':\n prettyPrint(await medplum.put(cleanUrl(argv[3]), parseBody(argv[4])));\n break;\n //\n // Bot commands\n //\n case 'save-bot':\n await runBotCommands(medplum, argv, ['save']);\n break;\n case 'deploy-bot':\n await runBotCommands(medplum, argv, ['save', 'deploy']);\n break;\n case 'create-bot':\n await createBot(medplum, argv);\n break;\n default:\n console.log(`Unknown command: ${command}`);\n }\n } catch (err) {\n console.error('Error: ' + normalizeErrorString(err));\n }\n}\n\nasync function startLogin(medplum: MedplumClient): Promise<void> {\n await startWebServer(medplum);\n\n const loginUrl = new URL('/oauth2/authorize', medplum.getBaseUrl());\n loginUrl.searchParams.set('client_id', clientId);\n loginUrl.searchParams.set('redirect_uri', redirectUri);\n loginUrl.searchParams.set('scope', 'openid');\n loginUrl.searchParams.set('response_type', 'code');\n await openBrowser(loginUrl.toString());\n}\n\nasync function startWebServer(medplum: MedplumClient): Promise<void> {\n const server = createServer(async (req, res) => {\n const url = new URL(req.url as string, 'http://localhost:9615');\n const code = url.searchParams.get('code');\n if (url.pathname === '/' && code) {\n try {\n const profile = await medplum.processCode(code, { clientId, redirectUri });\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end(`Signed in as ${getDisplayString(profile)}. You may close this window.`);\n } catch (err) {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end(`Error: ${normalizeErrorString(err)}`);\n } finally {\n server.close();\n }\n } else {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n }\n }).listen(9615);\n}\n\n/**\n * Opens a web browser to the specified URL.\n * See: https://hasinthaindrajee.medium.com/browser-sso-for-cli-applications-b0be743fa656\n * @param url The URL to open.\n */\nasync function openBrowser(url: string): Promise<void> {\n const os = platform();\n let cmd = undefined;\n switch (os) {\n case 'openbsd':\n case 'linux':\n cmd = `xdg-open '${url}'`;\n break;\n case 'darwin':\n cmd = `open '${url}'`;\n break;\n case 'win32':\n cmd = `cmd /c start \"\" \"${url}\"`;\n break;\n default:\n throw new Error('Unsupported platform: ' + os);\n }\n exec(cmd);\n}\n\n/**\n * Prints the current user and project.\n * @param medplum The Medplum client.\n */\nfunction printMe(medplum: MedplumClient): void {\n const loginState = medplum.getActiveLogin();\n if (loginState) {\n console.log(`Profile: ${loginState.profile?.display} (${loginState.profile?.reference})`);\n console.log(`Project: ${loginState.project?.display} (${loginState.project?.reference})`);\n } else {\n console.log('Not logged in');\n }\n}\n\nfunction cleanUrl(input: string): string {\n const knownPrefixes = ['admin/', 'auth/', 'fhir/R4'];\n if (knownPrefixes.some((p) => input.startsWith(p))) {\n // If the URL starts with a known prefix, return it as-is\n return input;\n }\n // Otherwise, default to FHIR\n return 'fhir/R4/' + input;\n}\n\nfunction parseBody(input: string | undefined): any {\n if (!input) {\n return undefined;\n }\n try {\n return JSON.parse(input);\n } catch (err) {\n return input;\n }\n}\n\nfunction prettyPrint(input: unknown): void {\n console.log(JSON.stringify(input, null, 2));\n}\n\nasync function runBotCommands(medplum: MedplumClient, argv: string[], commands: string[]): Promise<void> {\n if (argv.length < 4) {\n console.log(`Usage: medplum ${argv[2]} <bot-name>`);\n return;\n }\n\n const botName = argv[3];\n\n const botConfigs = readBotConfigs(botName);\n if (botConfigs.length === 0) {\n console.log(`Error: ${botName} not found`);\n return;\n }\n\n for (const botConfig of botConfigs) {\n await runBotConfig(botConfig, medplum, argv, commands);\n }\n\n console.log(`Number of bots deployed: ${botConfigs.length}`);\n}\n\nasync function runBotConfig(\n botConfig: MedplumBotConfig,\n medplum: MedplumClient,\n argv: string[],\n commands: string[]\n): Promise<void> {\n let bot;\n try {\n bot = await medplum.readResource('Bot', botConfig.id);\n console.log(`Initialized Bot -> ${bot.name}...`);\n } catch (err) {\n console.log('Error: ' + normalizeErrorString(err));\n return;\n }\n\n if (commands.includes('save')) {\n await saveBot(medplum, botConfig, bot);\n }\n\n if (commands.includes('deploy')) {\n await deployBot(medplum, botConfig, bot);\n }\n}\n\nasync function createBot(medplum: MedplumClient, argv: string[]): Promise<void> {\n if (argv.length < 7) {\n console.log(`Error: command needs to be npx medplum <new-bot-name> <project-id> <source-file> <dist-file>`);\n return;\n }\n const botName = argv[3];\n const projectId = argv[4];\n const sourceFile = argv[5];\n const distFile = argv[6];\n\n try {\n const body = {\n name: botName,\n description: '',\n };\n const newBot = await medplum.post('admin/projects/' + projectId + '/bot', body);\n const bot = await medplum.readResource('Bot', newBot.id);\n\n const botConfig = {\n name: botName,\n id: newBot.id,\n source: sourceFile,\n dist: distFile,\n };\n await saveBot(medplum, botConfig as MedplumBotConfig, bot);\n console.log(`Success! Bot created: ${bot.id}`);\n\n addBotToConfig(botConfig);\n } catch (err) {\n console.log('Error while creating new bot ', err);\n }\n}\n\nasync function saveBot(medplum: MedplumClient, botConfig: MedplumBotConfig, bot: Bot): Promise<void> {\n const code = readFileContents(botConfig.source);\n if (!code) {\n return;\n }\n\n try {\n console.log('Update bot code.....');\n const updateResult = await medplum.updateResource({\n ...bot,\n code,\n });\n if (!updateResult) {\n console.log('Bot not modified');\n } else {\n console.log('Success! New bot version: ' + updateResult.meta?.versionId);\n }\n } catch (err) {\n console.log('Update error: ', err);\n }\n}\n\nasync function deployBot(medplum: MedplumClient, botConfig: MedplumBotConfig, bot: Bot): Promise<void> {\n const code = readFileContents(botConfig.dist ?? botConfig.source);\n if (!code) {\n return;\n }\n\n try {\n console.log('Deploying bot...');\n const deployResult = (await medplum.post(medplum.fhirUrl('Bot', bot.id as string, '$deploy'), {\n code,\n })) as OperationOutcome;\n console.log('Deploy result: ' + deployResult.issue?.[0]?.details?.text);\n } catch (err) {\n console.log('Deploy error: ', err);\n }\n}\n\nfunction escapeRegex(str: string): string {\n return str.replace(/[/\\-\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n}\n\nfunction readBotConfigs(botName: string): MedplumBotConfig[] {\n const regExBotName = new RegExp('^' + escapeRegex(botName).replace(/\\\\\\*/g, '.*') + '$');\n const botConfigs = readConfig()?.bots?.filter((b) => regExBotName.test(b.name));\n if (!botConfigs) {\n return [];\n }\n return botConfigs;\n}\n\nfunction readConfig(): MedplumConfig | undefined {\n const content = readFileContents('medplum.config.json');\n if (!content) {\n return undefined;\n }\n return JSON.parse(content);\n}\n\nfunction readFileContents(fileName: string): string | undefined {\n const path = resolve(process.cwd(), fileName);\n if (!existsSync(path)) {\n console.log('Error: File does not exist: ' + path);\n return '';\n }\n return readFileSync(path, 'utf8');\n}\n\nfunction addBotToConfig(botConfig: MedplumBotConfig): void {\n const config = readConfig();\n config?.bots?.push(botConfig);\n writeFile('medplum.config.json', JSON.stringify(config), () => {\n console.log(`Bot added to config: ${botConfig.id}`);\n });\n}\n\nif (require.main === module) {\n dotenv.config();\n const baseUrl = process.env['MEDPLUM_BASE_URL'] || 'https://api.medplum.com/';\n const medplum = new MedplumClient({ fetch, baseUrl, storage: new FileSystemStorage() });\n main(medplum, process.argv).catch((err) => console.error('Unhandled error:', err));\n}\n"],"names":["ClientStorage","resolve","homedir","existsSync","readFileSync","mkdirSync","writeFileSync","normalizeErrorString","createServer","getDisplayString","os","platform","exec","path","writeFile","MedplumClient"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAsQA;AACO,SAAS,sBAAsB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE;AACjE,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;AACjG,IAAI,IAAI,OAAO,KAAK,KAAK,UAAU,GAAG,QAAQ,KAAK,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,SAAS,CAAC,0EAA0E,CAAC,CAAC;AACvL,IAAI,OAAO,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,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,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC;AACpF;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/storage.ts","../../../src/utils.ts","../../../src/bots.ts","../../../src/auth.ts","../../../src/rest.ts","../../../src/projects.ts","../../../src/index.ts"],"sourcesContent":["import { ClientStorage } from '@medplum/core';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { homedir } from 'os';\nimport { resolve } from 'path';\n\nexport class FileSystemStorage extends ClientStorage {\n private readonly dirName: string;\n private readonly fileName: string;\n\n constructor() {\n super();\n this.dirName = resolve(homedir(), '.medplum');\n this.fileName = resolve(this.dirName, 'credentials');\n }\n\n clear(): void {\n this.writeFile({});\n }\n\n getString(key: string): string | undefined {\n return this.readFile()?.[key];\n }\n\n setString(key: string, value: string | undefined): void {\n const data = this.readFile() || {};\n if (value) {\n data[key] = value;\n } else {\n delete data[key];\n }\n this.writeFile(data);\n }\n\n private readFile(): Record<string, string> | undefined {\n if (existsSync(this.fileName)) {\n return JSON.parse(readFileSync(this.fileName, 'utf8'));\n }\n return undefined;\n }\n\n private writeFile(data: Record<string, string>): void {\n if (!existsSync(this.dirName)) {\n mkdirSync(this.dirName);\n }\n writeFileSync(this.fileName, JSON.stringify(data, null, 2), 'utf8');\n }\n}\n","import { MedplumClient } from '@medplum/core';\nimport { resolve } from 'path';\nimport { existsSync, readFileSync, writeFile } from 'fs';\nimport { Bot, OperationOutcome } from '@medplum/fhirtypes';\n\ninterface MedplumConfig {\n readonly bots?: MedplumBotConfig[];\n}\n\ninterface MedplumBotConfig {\n readonly name: string;\n readonly id: string;\n readonly source: string;\n readonly dist?: string;\n}\n\nexport function prettyPrint(input: unknown): void {\n console.log(JSON.stringify(input, null, 2));\n}\n\nexport async function saveBot(medplum: MedplumClient, botConfig: MedplumBotConfig, bot: Bot): Promise<void> {\n const code = readFileContents(botConfig.source);\n if (!code) {\n return;\n }\n\n try {\n console.log('Update bot code.....');\n const updateResult = await medplum.updateResource({\n ...bot,\n code,\n });\n if (!updateResult) {\n console.log('Bot not modified');\n } else {\n console.log('Success! New bot version: ' + updateResult.meta?.versionId);\n }\n } catch (err) {\n console.log('Update error: ', err);\n }\n}\n\nexport async function deployBot(medplum: MedplumClient, botConfig: MedplumBotConfig, bot: Bot): Promise<void> {\n const code = readFileContents(botConfig.dist ?? botConfig.source);\n if (!code) {\n return;\n }\n\n try {\n console.log('Deploying bot...');\n const deployResult = (await medplum.post(medplum.fhirUrl('Bot', bot.id as string, '$deploy'), {\n code,\n })) as OperationOutcome;\n console.log('Deploy result: ' + deployResult.issue?.[0]?.details?.text);\n } catch (err) {\n console.log('Deploy error: ', err);\n }\n}\n\nexport async function createBot(medplum: MedplumClient, argv: string[]): Promise<void> {\n if (argv.length < 4) {\n console.log(`Error: command needs to be npx medplum <new-bot-name> <project-id> <source-file> <dist-file>`);\n return;\n }\n const botName = argv[0];\n const projectId = argv[1];\n const sourceFile = argv[2];\n const distFile = argv[3];\n\n try {\n const body = {\n name: botName,\n description: '',\n };\n const newBot = await medplum.post('admin/projects/' + projectId + '/bot', body);\n const bot = await medplum.readResource('Bot', newBot.id);\n\n const botConfig = {\n name: botName,\n id: newBot.id,\n source: sourceFile,\n dist: distFile,\n };\n await saveBot(medplum, botConfig as MedplumBotConfig, bot);\n console.log(`Success! Bot created: ${bot.id}`);\n\n addBotToConfig(botConfig);\n } catch (err) {\n console.log('Error while creating new bot: ' + err);\n }\n}\n\nexport function readBotConfigs(botName: string): MedplumBotConfig[] {\n const regExBotName = new RegExp('^' + escapeRegex(botName).replace(/\\\\\\*/g, '.*') + '$');\n const botConfigs = readConfig()?.bots?.filter((b) => regExBotName.test(b.name));\n if (!botConfigs) {\n return [];\n }\n return botConfigs;\n}\n\nfunction readConfig(): MedplumConfig | undefined {\n const content = readFileContents('medplum.config.json');\n if (!content) {\n return undefined;\n }\n return JSON.parse(content);\n}\n\nfunction readFileContents(fileName: string): string | undefined {\n const path = resolve(process.cwd(), fileName);\n if (!existsSync(path)) {\n console.log('Error: File does not exist: ' + path);\n return '';\n }\n return readFileSync(path, 'utf8');\n}\n\nfunction addBotToConfig(botConfig: MedplumBotConfig): void {\n const config = readConfig();\n config?.bots?.push(botConfig);\n writeFile('medplum.config.json', JSON.stringify(config), () => {\n console.log(`Bot added to config: ${botConfig.id}`);\n });\n}\n\nfunction escapeRegex(str: string): string {\n return str.replace(/[/\\-\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n}\n","import { Command } from 'commander';\nimport { medplum } from '.';\nimport { createBot, deployBot, readBotConfigs, saveBot } from './utils';\nimport { MedplumClient } from '@medplum/core';\n\nexport const bot = new Command('bot');\n\n// Commands to deprecate\nexport const saveBotDeprecate = new Command('save-bot');\nexport const deployBotDeprecate = new Command('deploy-bot');\nexport const createBotDeprecate = new Command('create-bot');\n\nbot\n .command('save')\n .description('Saving the bot')\n .argument('<botName>')\n .action(async (botName) => {\n await botWrapper(medplum, botName);\n });\n\nbot\n .command('deploy')\n .description('Deploy the app to AWS')\n .argument('<botName>')\n .action(async (botName) => {\n await botWrapper(medplum, botName, true);\n });\n\nbot\n .command('create')\n .arguments('<botName> <projectId> <sourceFile> <distFile>')\n .description('Creating a bot')\n .action(async (botName, projectId, sourceFile, distFile) => {\n await createBot(medplum, [botName, projectId, sourceFile, distFile]);\n });\n\nexport async function botWrapper(medplum: MedplumClient, botName: string, deploy = false): Promise<void> {\n const botConfigs = readBotConfigs(botName);\n for (const botConfig of botConfigs) {\n const bot = await medplum.readResource('Bot', botConfig.id);\n await saveBot(medplum, botConfig, bot);\n if (deploy) {\n await deployBot(medplum, botConfig, bot);\n }\n }\n console.log(`Number of bots deployed: ${botConfigs.length}`);\n}\n\n// Deprecate bot commands\nsaveBotDeprecate\n .description('Saves the bot')\n .argument('<botName>')\n .action(async (botName) => {\n await botWrapper(medplum, botName);\n });\n\ndeployBotDeprecate\n .description('Deploy the bot to AWS')\n .argument('<botName>')\n .action(async (botName) => {\n await botWrapper(medplum, botName, true);\n });\n\ncreateBotDeprecate\n .arguments('<botName> <projectId> <sourceFile> <distFile>')\n .description('Creates and saves the bot')\n .action(async (botName, projectId, sourceFile, distFile) => {\n await createBot(medplum, [botName, projectId, sourceFile, distFile]);\n });\n","import { Command } from 'commander';\nimport { medplum } from '.';\nimport { MedplumClient, getDisplayString, normalizeErrorString } from '@medplum/core';\nimport { platform } from 'os';\nimport { exec } from 'child_process';\nimport { createServer } from 'http';\n\nconst clientId = 'medplum-cli';\nconst redirectUri = 'http://localhost:9615';\n\nexport const login = new Command('login');\nexport const whoami = new Command('whoami');\n\nlogin.action(async () => {\n await startLogin(medplum);\n});\n\nwhoami.action(() => {\n printMe(medplum);\n});\n\nasync function startLogin(medplum: MedplumClient): Promise<void> {\n await startWebServer(medplum);\n\n const loginUrl = new URL('/oauth2/authorize', medplum.getBaseUrl());\n loginUrl.searchParams.set('client_id', clientId);\n loginUrl.searchParams.set('redirect_uri', redirectUri);\n loginUrl.searchParams.set('scope', 'openid');\n loginUrl.searchParams.set('response_type', 'code');\n await openBrowser(loginUrl.toString());\n}\n\nasync function startWebServer(medplum: MedplumClient): Promise<void> {\n const server = createServer(async (req, res) => {\n const url = new URL(req.url as string, 'http://localhost:9615');\n const code = url.searchParams.get('code');\n if (url.pathname === '/' && code) {\n try {\n const profile = await medplum.processCode(code, { clientId, redirectUri });\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end(`Signed in as ${getDisplayString(profile)}. You may close this window.`);\n } catch (err) {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end(`Error: ${normalizeErrorString(err)}`);\n } finally {\n server.close();\n }\n } else {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n }\n }).listen(9615);\n}\n\n/**\n * Opens a web browser to the specified URL.\n * See: https://hasinthaindrajee.medium.com/browser-sso-for-cli-applications-b0be743fa656\n * @param url The URL to open.\n */\nasync function openBrowser(url: string): Promise<void> {\n const os = platform();\n let cmd = undefined;\n switch (os) {\n case 'openbsd':\n case 'linux':\n cmd = `xdg-open '${url}'`;\n break;\n case 'darwin':\n cmd = `open '${url}'`;\n break;\n case 'win32':\n cmd = `cmd /c start \"\" \"${url}\"`;\n break;\n default:\n throw new Error('Unsupported platform: ' + os);\n }\n exec(cmd);\n}\n\n/**\n * Prints the current user and project.\n * @param medplum The Medplum client.\n */\nfunction printMe(medplum: MedplumClient): void {\n const loginState = medplum.getActiveLogin();\n if (loginState) {\n console.log(`Server: ${medplum.getBaseUrl()}`);\n console.log(`Profile: ${loginState.profile?.display} (${loginState.profile?.reference})`);\n console.log(`Project: ${loginState.project?.display} (${loginState.project?.reference})`);\n } else {\n console.log('Not logged in');\n }\n}\n","import { convertToTransactionBundle } from '@medplum/core';\nimport { Command } from 'commander';\nimport { medplum } from '.';\nimport { prettyPrint } from './utils';\n\nexport const deleteObject = new Command('delete');\nexport const get = new Command('get');\nexport const patch = new Command('patch');\nexport const post = new Command('post');\nexport const put = new Command('put');\n\ndeleteObject.argument('<url>', 'Resource/$id').action(async (url) => {\n prettyPrint(await medplum.delete(cleanUrl(url)));\n});\n\nget\n .argument('<url>', 'Resource/$id')\n .option('--as-transaction', 'Print out the bundle as a transaction type')\n .action(async (url, options) => {\n try {\n const response = await medplum.get(cleanUrl(url));\n if (options.asTransaction) {\n prettyPrint(convertToTransactionBundle(response));\n } else {\n prettyPrint(response);\n }\n } catch (err) {\n console.log(err);\n }\n });\n\npatch.arguments('<url> <body>').action(async (url, body) => {\n prettyPrint(await medplum.patch(cleanUrl(url), parseBody(body)));\n});\n\npost.arguments('<url> <body>').action(async (url, body) => {\n prettyPrint(await medplum.post(cleanUrl(url), parseBody(body)));\n});\n\nput.arguments('<url> <body>').action(async (url, body) => {\n prettyPrint(await medplum.put(cleanUrl(url), parseBody(body)));\n});\n\nfunction parseBody(input: string | undefined): any {\n if (!input) {\n return undefined;\n }\n try {\n return JSON.parse(input);\n } catch (err) {\n return input;\n }\n}\n\nexport function cleanUrl(input: string): string {\n const knownPrefixes = ['admin/', 'auth/', 'fhir/R4'];\n if (knownPrefixes.some((p) => input.startsWith(p))) {\n // If the URL starts with a known prefix, return it as-is\n return input;\n }\n // Otherwise, default to FHIR\n return 'fhir/R4/' + input;\n}\n","import { Command } from 'commander';\nimport { medplum } from '.';\nimport { MedplumClient, LoginState } from '@medplum/core';\n\nexport const project = new Command('project');\n\nproject\n .command('list')\n .description('List of current projects')\n .action(async () => {\n projectList(medplum);\n });\n\nfunction projectList(medplum: MedplumClient): void {\n const logins = medplum.getLogins();\n\n const projects = logins\n .map((login: LoginState) => `${login.project.display} (${login.project.reference})`)\n .join('\\n\\n');\n\n console.log(projects);\n}\n\nproject\n .command('current')\n .description('Project you are currently on')\n .action(() => {\n const login = medplum.getActiveLogin();\n if (!login) {\n throw new Error('Unauthenticated: run `npx medplum login` to login');\n }\n console.log(`${login.project.display} (${login.project.reference})`);\n });\n\nproject\n .command('switch')\n .description('Switching to another project from the current one')\n .argument('<projectId>')\n .action(async (projectId) => {\n await switchProject(medplum, projectId);\n });\n\nasync function switchProject(medplum: MedplumClient, projectId: string): Promise<void> {\n const logins = medplum.getLogins();\n const login = logins.find((login: LoginState) => login.project?.reference?.includes(projectId));\n if (!login) {\n console.log(`Error: project ${projectId} not found. Make sure you are added as a user to this project`);\n } else {\n await medplum.setActiveLogin(login);\n console.log(`Switched to project ${projectId}\\n`);\n }\n}\n","import { Command } from 'commander';\nimport { FileSystemStorage } from './storage';\nimport { MedplumClient, normalizeErrorString } from '@medplum/core';\nimport dotenv from 'dotenv';\nimport { bot, createBotDeprecate, deployBotDeprecate, saveBotDeprecate } from './bots';\nimport { login, whoami } from './auth';\nimport { deleteObject, get, patch, post, put } from './rest';\nimport { project } from './projects';\n\nexport let medplum: MedplumClient;\n\nexport async function main(medplumClient: MedplumClient, argv: string[]): Promise<void> {\n medplum = medplumClient;\n\n // Legacy support for MEDPLUM_CLIENT_ID and MEDPLUM_CLIENT_SECRET environment variables\n const clientId = process.env['MEDPLUM_CLIENT_ID'];\n const clientSecret = process.env['MEDPLUM_CLIENT_SECRET'];\n if (clientId && clientSecret) {\n await medplum.startClientLogin(clientId, clientSecret);\n }\n try {\n const index = new Command('medplum').description('Command to access Medplum CLI');\n index.version('0.1.0');\n\n // Auth commands\n index.addCommand(login);\n index.addCommand(whoami);\n\n // REST commands\n index.addCommand(get);\n index.addCommand(post);\n index.addCommand(patch);\n index.addCommand(put);\n index.addCommand(deleteObject);\n\n // Project\n index.addCommand(project);\n\n // Bot Commands\n index.addCommand(bot);\n\n // Deprecated Bot Commands\n index.addCommand(saveBotDeprecate);\n index.addCommand(deployBotDeprecate);\n index.addCommand(createBotDeprecate);\n\n await index.parseAsync(argv);\n } catch (err) {\n console.error('Error: ' + normalizeErrorString(err));\n }\n}\n\nif (require.main === module) {\n dotenv.config();\n const baseUrl = process.env['MEDPLUM_BASE_URL'] || 'https://api.medplum.com/';\n const medplumClient = new MedplumClient({ fetch, baseUrl, storage: new FileSystemStorage() });\n main(medplumClient, process.argv).catch((err) => console.error('Unhandled error:', err));\n}\n"],"names":["ClientStorage","resolve","homedir","existsSync","readFileSync","mkdirSync","writeFileSync","path","writeFile","Command","medplum","createServer","getDisplayString","normalizeErrorString","os","platform","exec","convertToTransactionBundle","MedplumClient"],"mappings":";;;;;;;;;;;;AAKM,MAAO,iBAAkB,SAAQA,kBAAa,CAAA;AAIlD,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAGC,YAAO,CAACC,UAAO,EAAE,EAAE,UAAU,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAGD,YAAO,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;KACtD;IAED,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;KAC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AAC;AAC1F;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/cli",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "Medplum Command Line Interface",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@medplum/core": "*",
21
+ "commander": "10.0.1",
21
22
  "dotenv": "16.0.3",
22
23
  "node-fetch": "2.6.9"
23
24
  },