@trycourier/cli 2.6.1 → 2.7.1
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/dist/commands/UserToken.d.ts +3 -0
- package/dist/commands/UserToken.js +78 -0
- package/dist/components/Version.js +2 -2
- package/dist/mappings.js +27 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Box, Text } from 'ink';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { useBoolean } from 'usehooks-ts';
|
|
5
|
+
import { useCliContext } from '../components/Context.js';
|
|
6
|
+
import Spinner from '../components/Spinner.js';
|
|
7
|
+
import UhOh from '../components/UhOh.js';
|
|
8
|
+
const VALID_SCOPE_PREFIXES = [
|
|
9
|
+
'read:messages',
|
|
10
|
+
'read:user-tokens',
|
|
11
|
+
'write:user-tokens',
|
|
12
|
+
'read:brands',
|
|
13
|
+
'write:brands',
|
|
14
|
+
'inbox:read:messages',
|
|
15
|
+
'inbox:write:events',
|
|
16
|
+
'read:preferences',
|
|
17
|
+
'write:preferences',
|
|
18
|
+
];
|
|
19
|
+
const ALL = VALID_SCOPE_PREFIXES.filter(s => !s.endsWith('brand'));
|
|
20
|
+
const UserToken = () => {
|
|
21
|
+
const { parsedParams, getJWT } = useCliContext();
|
|
22
|
+
const running = useBoolean(true);
|
|
23
|
+
const [jwt, setJWT] = useState();
|
|
24
|
+
const [final_scopes, setFinalScopes] = useState([]);
|
|
25
|
+
const [error, setError] = useState();
|
|
26
|
+
const { expiration, scopes, all, _: [user_id], } = parsedParams;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
getUserJWT();
|
|
29
|
+
}, []);
|
|
30
|
+
const getUserJWT = async () => {
|
|
31
|
+
const exp = Number(expiration);
|
|
32
|
+
const scope_input = scopes?.split(',') || [];
|
|
33
|
+
const sc = [...new Set([...scope_input, ...(all ? ALL : [])])];
|
|
34
|
+
const invalid_scopes = sc.filter(scope => !_.some(VALID_SCOPE_PREFIXES, val => scope.startsWith(val)));
|
|
35
|
+
setFinalScopes([`user_id:${user_id}`, ...sc]);
|
|
36
|
+
if (!user_id) {
|
|
37
|
+
setError('No User Specified');
|
|
38
|
+
}
|
|
39
|
+
else if (!(sc && sc.length)) {
|
|
40
|
+
setError('No scopes provided. They are required');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
else if (invalid_scopes.length) {
|
|
44
|
+
setError(`Found invalid scopes (${invalid_scopes.join(', ')})`);
|
|
45
|
+
}
|
|
46
|
+
else if (exp && Number.isNaN(exp)) {
|
|
47
|
+
setError('Not a valid number');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
try {
|
|
51
|
+
const r = await getJWT(user_id, sc, {
|
|
52
|
+
expires_in: `${exp || 5} mins`,
|
|
53
|
+
write_brands: [],
|
|
54
|
+
});
|
|
55
|
+
setJWT(r.token);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
setError(String(e));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
running.setFalse();
|
|
62
|
+
};
|
|
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` });
|
|
68
|
+
}
|
|
69
|
+
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 })));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
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
|
@@ -23,6 +23,7 @@ import TenantsMembershipBulk from './commands/TenantsMembershipBulk.js';
|
|
|
23
23
|
import AudienceSearch from './commands/AudienceSearch.js';
|
|
24
24
|
import UsersTokensBulk from './commands/UsersTokensBulk.js';
|
|
25
25
|
import TenantsGetMembership from './commands/TenantsGetMembership.js';
|
|
26
|
+
import UserToken from './commands/UserToken.js';
|
|
26
27
|
const mappings = new Map();
|
|
27
28
|
export const COMMON_OPTIONS = [
|
|
28
29
|
{
|
|
@@ -529,4 +530,30 @@ mappings.set('audiences:search', {
|
|
|
529
530
|
'courier audiences:search --id 1234 --json --filename=audience1234.json',
|
|
530
531
|
],
|
|
531
532
|
});
|
|
533
|
+
mappings.set('users:jwt', {
|
|
534
|
+
params: '<user_id>',
|
|
535
|
+
instructions: 'Create a JWT for a user',
|
|
536
|
+
options: [
|
|
537
|
+
{
|
|
538
|
+
option: '--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
|
+
},
|
|
541
|
+
{
|
|
542
|
+
option: '--all',
|
|
543
|
+
value: 'Include all scopes besides brand scopes.',
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
option: '--expiration',
|
|
547
|
+
value: 'How long in minutes this JWT is valid for? Default is 5 minutes',
|
|
548
|
+
},
|
|
549
|
+
],
|
|
550
|
+
example: [
|
|
551
|
+
'courier test-user123 --scopes=inbox:read:messages,inbox:write:events',
|
|
552
|
+
'courier test-user123 --scopes=read:user-tokens,write:user-tokens --expiration=5',
|
|
553
|
+
'courier test-user123 --scopes=inbox:read:messages,inbox:write:events,read:preferences,write:preferences,read:user-tokens,write:user-tokens',
|
|
554
|
+
],
|
|
555
|
+
component: () => {
|
|
556
|
+
return React.createElement(UserToken, null);
|
|
557
|
+
},
|
|
558
|
+
});
|
|
532
559
|
export default mappings;
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let VERSION = '2.
|
|
1
|
+
let VERSION = '2.7.1';
|
|
2
2
|
export default VERSION;
|