@trycourier/cli
Advanced tools
Comparing version 1.3.2 to 1.4.0
@@ -11,10 +11,3 @@ #!/usr/bin/env node | ||
const Router = (await import('./components/Router.js')).default; | ||
const UhOh = (await import('./components/UhOh.js')).default; | ||
const apiKey = process.env['COURIER_API_KEY']; | ||
if (apiKey && apiKey.length) { | ||
render(React.createElement(Router, { args: params, mappings: mappings })); | ||
} | ||
else { | ||
render(React.createElement(UhOh, { text: "No COURIER_API_KEY specified; add that to your environment or ~/.courier file" })); | ||
} | ||
render(React.createElement(Router, { args: params, mappings: mappings })); | ||
}; | ||
@@ -21,0 +14,0 @@ (async () => { |
@@ -5,2 +5,3 @@ import React, { useEffect, useState } from 'react'; | ||
import Request from '../components/Request.js'; | ||
import Response from '../components/Response.js'; | ||
import api from '../lib/api.js'; | ||
@@ -18,3 +19,3 @@ export default () => { | ||
React.createElement(Request, { request: request, response: resp }), | ||
resp && resp.json ? (React.createElement(React.Fragment, null, | ||
resp && resp.err ? (React.createElement(Response, { response: resp })) : resp && resp.json ? (React.createElement(React.Fragment, null, | ||
React.createElement(KVP, { width: 20, label: "Workspace Name", value: resp.json.tenantName }), | ||
@@ -21,0 +22,0 @@ React.createElement(KVP, { width: 20, label: "Workspace ID", value: resp.json.tenantId }), |
import React from 'react'; | ||
interface IMapping { | ||
instructions?: string; | ||
component: (params?: any) => React.ReactElement; | ||
noApiKeyRequired?: boolean; | ||
} | ||
@@ -6,0 +6,0 @@ type Props = { |
import React from 'react'; | ||
import yargs from 'yargs-parser'; | ||
import { Text } from 'ink'; | ||
import Help from '../commands/Help.js'; | ||
import yargs from 'yargs-parser'; | ||
export default ({ args, mappings }) => { | ||
@@ -12,3 +13,14 @@ if (!args.length || !args[0]) { | ||
if (mapping) { | ||
return mapping.component(parsedParams); | ||
const apiKey = process.env['COURIER_API_KEY']; | ||
if ((apiKey && apiKey.length) || mapping.noApiKeyRequired) { | ||
return mapping.component(parsedParams); | ||
} | ||
else { | ||
return React.createElement(React.Fragment, null, | ||
React.createElement(Text, { bold: true, color: "red" }, "No COURIER_API_KEY specified, please set via one of these options:"), | ||
React.createElement(Text, { bold: true, color: "red" }, "\u2022 running \"courier config --apikey <your-api-key>\""), | ||
React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in your shell via \"export COURIER_API_KEY=<your-api-key>\""), | ||
React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in a \".courier\" file in your current working directory"), | ||
React.createElement(Text, { bold: true, color: "red" }, "\u2022 setting COURIER_API_KEY in a \".courier\" file in your user's home directory")); | ||
} | ||
} | ||
@@ -15,0 +27,0 @@ else { |
import React from 'react'; | ||
interface IMapping { | ||
noApiKeyRequired?: boolean; | ||
params?: string; | ||
@@ -4,0 +5,0 @@ instructions?: string; |
import React from 'react'; | ||
import Help from './commands/Help.js'; | ||
import Config from './commands/Config.js'; | ||
import WhoAmI from './commands/WhoAmI.js'; | ||
@@ -14,3 +15,22 @@ import Track from './commands/Track.js'; | ||
}, | ||
noApiKeyRequired: true | ||
}); | ||
mappings.set('config', { | ||
instructions: 'Persist your Courier API key into a .courier file in your current working directory', | ||
component: params => { | ||
return React.createElement(Config, { params: params }); | ||
}, | ||
options: [ | ||
{ | ||
option: '--apikey <Courier API Key>', | ||
value: '', | ||
}, | ||
{ | ||
option: '--overwrite', | ||
value: 'overwrite an existing .courier file', | ||
}, | ||
], | ||
example: `courier config --apikey MY_API_KEY`, | ||
noApiKeyRequired: true | ||
}); | ||
mappings.set('whoami', { | ||
@@ -17,0 +37,0 @@ instructions: 'Display the currently authenticated workspace', |
{ | ||
"name": "@trycourier/cli", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -11,8 +11,9 @@ # Courier CLI | ||
## Install the Courier CLI | ||
## Installing the Courier CLI | ||
From the command-line, use the following command to install the Courier CLI: | ||
From the command-line, use the following command to install the Courier CLI and set your API key: | ||
```bash | ||
$ npm install -g @trycourier/cli | ||
$ courier config --apikey <your-api-key> | ||
``` | ||
@@ -26,2 +27,8 @@ | ||
The fastest way to get started is to run: | ||
``` | ||
$ courier config --apikey <your-api-key> | ||
``` | ||
Courier CLI looks for an environment variable named `COURIER_API_KEY`. It will load that key from the first location it finds in the following list: | ||
@@ -37,2 +44,3 @@ | ||
- `courier config` – Set your Courier API key in `~/.courier` | ||
- `courier whoami` – Display the currently authenticated workspace | ||
@@ -39,0 +47,0 @@ - `courier send` - Send a notification to a user, list, or audience |
47614
75
1237
59
8