@trycourier/cli 2.7.0 → 2.7.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.
package/README.md CHANGED
@@ -77,6 +77,9 @@ courier translations:download en-US --text > example.en-US.po
77
77
  courier config --apikey MY_API_KEY -P --override
78
78
  courier config --apikey MY_API_KEY --mock
79
79
  courier config --apikey MY_API_KEY --draft
80
+
81
+ courier test-user123 --scopes=read:user-tokens,write:user-tokens --expiration=60
82
+ courier test-user123 --all --quiet | pbcopy
80
83
  ```
81
84
 
82
85
  ## Common Flags
@@ -1,11 +1,10 @@
1
- import { Text } from 'ink';
1
+ import { Box, Text } from 'ink';
2
2
  import _ from 'lodash';
3
- import React, { useEffect, useState } from 'react';
3
+ import React, { useEffect, useRef, useState } from 'react';
4
4
  import { useBoolean } from 'usehooks-ts';
5
5
  import { useCliContext } from '../components/Context.js';
6
6
  import Spinner from '../components/Spinner.js';
7
7
  import UhOh from '../components/UhOh.js';
8
- import { stdout } from 'process';
9
8
  const VALID_SCOPE_PREFIXES = [
10
9
  'read:messages',
11
10
  'read:user-tokens',
@@ -17,19 +16,36 @@ const VALID_SCOPE_PREFIXES = [
17
16
  'read:preferences',
18
17
  'write:preferences',
19
18
  ];
19
+ const ALL = VALID_SCOPE_PREFIXES.filter(s => !s.endsWith('brand'));
20
20
  const UserToken = () => {
21
21
  const { parsedParams, getJWT } = useCliContext();
22
22
  const running = useBoolean(true);
23
23
  const [jwt, setJWT] = useState();
24
+ const [final_scopes, setFinalScopes] = useState([]);
24
25
  const [error, setError] = useState();
25
- const { expiration, scopes, _: [user_id], } = parsedParams;
26
+ let timeoutRef = useRef(null);
27
+ const { expires, scopes, all, quiet, _: [user_id], } = parsedParams;
26
28
  useEffect(() => {
27
29
  getUserJWT();
30
+ // @ts-ignore
31
+ timeoutRef.current = setTimeout(() => { }, 5000);
28
32
  }, []);
33
+ useEffect(() => {
34
+ if (jwt && timeoutRef.current) {
35
+ clearTimeout(timeoutRef.current);
36
+ }
37
+ return () => {
38
+ if (timeoutRef.current) {
39
+ clearTimeout(timeoutRef.current);
40
+ }
41
+ };
42
+ }, [jwt]);
29
43
  const getUserJWT = async () => {
30
- const exp = Number(expiration);
31
- const sc = (scopes?.split(',') || []).map(s => s.trim());
44
+ const exp = Number(expires);
45
+ const scope_input = scopes?.split(',') || [];
46
+ const sc = [...new Set([...scope_input, ...(all ? ALL : [])])];
32
47
  const invalid_scopes = sc.filter(scope => !_.some(VALID_SCOPE_PREFIXES, val => scope.startsWith(val)));
48
+ setFinalScopes([`user_id:${user_id}`, ...sc]);
33
49
  if (!user_id) {
34
50
  setError('No User Specified');
35
51
  }
@@ -57,15 +73,24 @@ const UserToken = () => {
57
73
  }
58
74
  running.setFalse();
59
75
  };
60
- if (error?.length) {
61
- return React.createElement(UhOh, { text: error });
62
- }
63
- else if (running.value) {
64
- return React.createElement(Spinner, { text: `Fetching JWT` });
76
+ if (quiet) {
77
+ return React.createElement(Text, null, jwt);
65
78
  }
66
79
  else {
67
- stdout.write(jwt ?? '');
68
- return React.createElement(Text, null, jwt);
80
+ if (error?.length) {
81
+ return React.createElement(UhOh, { text: error });
82
+ }
83
+ else if (running.value) {
84
+ return React.createElement(Spinner, { text: `Fetching JWT` });
85
+ }
86
+ else {
87
+ return (React.createElement(React.Fragment, null,
88
+ React.createElement(Text, null, "Token has the following scopes:"),
89
+ React.createElement(Text, null, final_scopes.join(' ')),
90
+ React.createElement(Box, { flexDirection: "column", marginY: 1, borderColor: "gray", borderStyle: 'single', borderTop: false, borderLeft: false, borderRight: false }),
91
+ React.createElement(Text, null, jwt),
92
+ React.createElement(Box, { flexDirection: "column", marginY: 1, borderColor: "gray", borderStyle: 'single', borderBottom: false, borderLeft: false, borderRight: false })));
93
+ }
69
94
  }
70
95
  };
71
96
  export default UserToken;
@@ -5,7 +5,7 @@ import React, { useEffect } from 'react';
5
5
  import { useCliContext } from './Context.js';
6
6
  import constants from '../constants.js';
7
7
  const Version = () => {
8
- const { version, setVersion, map } = useCliContext();
8
+ const { version, setVersion, map, parsedParams } = useCliContext();
9
9
  useEffect(() => {
10
10
  getVersion();
11
11
  }, []);
@@ -29,7 +29,7 @@ const Version = () => {
29
29
  ? `Upgrade available (${version.current} > ${version.latest}), run courier upgrade`
30
30
  : undefined;
31
31
  if (version_text?.length) {
32
- if (map === 'upgrade') {
32
+ if (map === 'upgrade' || _.get(parsedParams, ['quiet'], false)) {
33
33
  return React.createElement(React.Fragment, null);
34
34
  }
35
35
  else {
package/dist/mappings.js CHANGED
@@ -536,17 +536,27 @@ mappings.set('users:jwt', {
536
536
  options: [
537
537
  {
538
538
  option: '--scopes',
539
- value: 'Required. The scopes to attach to the JWT. We will provide the user_id scope automatically, all others will be comma seperated (https://www.courier.com/docs/reference/auth/issue-token/#available-scopes).',
539
+ value: 'Required if not using all. The scopes to attach to the JWT. We will provide the user_id scope automatically, all others will be comma seperated (https://www.courier.com/docs/reference/auth/issue-token/#available-scopes).',
540
540
  },
541
541
  {
542
- option: '--expiration',
542
+ option: '--expires',
543
543
  value: 'How long in minutes this JWT is valid for? Default is 5 minutes',
544
544
  },
545
+ {
546
+ option: '--all',
547
+ value: 'Include all scopes besides brand scopes.',
548
+ },
549
+ {
550
+ option: '--quiet',
551
+ value: 'Clear standard out and removing',
552
+ },
545
553
  ],
546
554
  example: [
547
555
  'courier test-user123 --scopes=inbox:read:messages,inbox:write:events',
548
- 'courier test-user123 --scopes=read:user-tokens,write:user-tokens --expiration=5',
556
+ 'courier test-user123 --scopes=read:user-tokens,write:user-tokens --expiration=60',
549
557
  'courier test-user123 --scopes=inbox:read:messages,inbox:write:events,read:preferences,write:preferences,read:user-tokens,write:user-tokens',
558
+ 'courier test-user123 --all',
559
+ 'courier test-user123 --all --quiet | pbcopy',
550
560
  ],
551
561
  component: () => {
552
562
  return React.createElement(UserToken, null);
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- let VERSION = '2.7.0';
1
+ let VERSION = '2.7.2';
2
2
  export default VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"