@trycourier/cli 2.7.1 → 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,6 +1,6 @@
1
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';
@@ -23,12 +23,25 @@ const UserToken = () => {
23
23
  const [jwt, setJWT] = useState();
24
24
  const [final_scopes, setFinalScopes] = useState([]);
25
25
  const [error, setError] = useState();
26
- const { expiration, scopes, all, _: [user_id], } = parsedParams;
26
+ let timeoutRef = useRef(null);
27
+ const { expires, scopes, all, quiet, _: [user_id], } = parsedParams;
27
28
  useEffect(() => {
28
29
  getUserJWT();
30
+ // @ts-ignore
31
+ timeoutRef.current = setTimeout(() => { }, 5000);
29
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]);
30
43
  const getUserJWT = async () => {
31
- const exp = Number(expiration);
44
+ const exp = Number(expires);
32
45
  const scope_input = scopes?.split(',') || [];
33
46
  const sc = [...new Set([...scope_input, ...(all ? ALL : [])])];
34
47
  const invalid_scopes = sc.filter(scope => !_.some(VALID_SCOPE_PREFIXES, val => scope.startsWith(val)));
@@ -60,19 +73,24 @@ const UserToken = () => {
60
73
  }
61
74
  running.setFalse();
62
75
  };
63
- if (error?.length) {
64
- return React.createElement(UhOh, { text: error });
65
- }
66
- else if (running.value) {
67
- return React.createElement(Spinner, { text: `Fetching JWT` });
76
+ if (quiet) {
77
+ return React.createElement(Text, null, jwt);
68
78
  }
69
79
  else {
70
- return (React.createElement(React.Fragment, null,
71
- React.createElement(Text, null, "Token has the following scopes:"),
72
- React.createElement(Text, null, final_scopes.join(' ')),
73
- React.createElement(Box, { flexDirection: "column", marginY: 1, borderColor: "gray", borderStyle: 'single', borderTop: false, borderLeft: false, borderRight: false }),
74
- React.createElement(Text, null, jwt),
75
- React.createElement(Box, { flexDirection: "column", marginY: 1, borderColor: "gray", borderStyle: 'single', borderBottom: false, borderLeft: false, borderRight: false })));
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
+ }
76
94
  }
77
95
  };
78
96
  export default UserToken;
package/dist/mappings.js CHANGED
@@ -538,19 +538,25 @@ mappings.set('users:jwt', {
538
538
  option: '--scopes',
539
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
+ {
542
+ option: '--expires',
543
+ value: 'How long in minutes this JWT is valid for? Default is 5 minutes',
544
+ },
541
545
  {
542
546
  option: '--all',
543
547
  value: 'Include all scopes besides brand scopes.',
544
548
  },
545
549
  {
546
- option: '--expiration',
547
- value: 'How long in minutes this JWT is valid for? Default is 5 minutes',
550
+ option: '--quiet',
551
+ value: 'Clear standard out and removing',
548
552
  },
549
553
  ],
550
554
  example: [
551
555
  'courier test-user123 --scopes=inbox:read:messages,inbox:write:events',
552
- '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',
553
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',
554
560
  ],
555
561
  component: () => {
556
562
  return React.createElement(UserToken, null);
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- let VERSION = '2.7.1';
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.1",
3
+ "version": "2.7.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"