Skip to content

Commit 566c239

Browse files
feat: migrate token commands from auth: namespace to tokens: namespace
- Create new tokens: namespace with tokens:list, tokens:add, tokens:remove commands - Remove old auth:tokens, auth:tokens:add, auth:tokens:remove commands (breaking change) - Update package.json short command names from auth:tokens* to tokens:* - Update test imports to reference new command paths - All token storage and functionality remains unchanged
1 parent 1582788 commit 566c239

10 files changed

Lines changed: 497 additions & 2305 deletions

File tree

packages/contentstack-auth/README.md

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-auth/2.0.0-beta.10 darwin-arm64 node-v22.13.1
21+
@contentstack/cli-auth/2.0.0-beta.13 darwin-arm64 node-v22.23.1
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND
@@ -31,13 +31,13 @@ USAGE
3131
<!-- commands -->
3232
* [`csdx auth:login`](#csdx-authlogin)
3333
* [`csdx auth:logout`](#csdx-authlogout)
34-
* [`csdx auth:tokens`](#csdx-authtokens)
35-
* [`csdx auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]`](#csdx-authtokensadd--a-value---delivery---management--e-value--k-value--y---token-value)
36-
* [`csdx auth:tokens:remove`](#csdx-authtokensremove)
3734
* [`csdx auth:whoami`](#csdx-authwhoami)
3835
* [`csdx login`](#csdx-login)
3936
* [`csdx logout`](#csdx-logout)
4037
* [`csdx tokens`](#csdx-tokens)
38+
* [`csdx tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]`](#csdx-tokensadd--a-value---delivery---management--e-value--k-value--y---token-value)
39+
* [`csdx tokens:list`](#csdx-tokenslist)
40+
* [`csdx tokens:remove`](#csdx-tokensremove)
4141
* [`csdx whoami`](#csdx-whoami)
4242

4343
## `csdx auth:login`
@@ -100,106 +100,6 @@ EXAMPLES
100100

101101
_See code: [src/commands/auth/logout.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/auth/logout.ts)_
102102

103-
## `csdx auth:tokens`
104-
105-
Lists all existing tokens added to the session
106-
107-
```
108-
USAGE
109-
$ csdx auth:tokens [--columns <value>] [--sort <value>] [--filter <value>] [--csv] [--no-truncate]
110-
[--no-header] [--output csv|json|yaml]
111-
112-
TABLE FLAGS
113-
--columns=<value> Specify columns to display, comma-separated.
114-
--csv Output results in CSV format.
115-
--filter=<value> Filter rows by a column value (e.g., name=foo).
116-
--no-header Hide table headers in output.
117-
--no-truncate Prevent truncation of long text in columns.
118-
--output=<option> Specify output format: csv, json, or yaml.
119-
<options: csv|json|yaml>
120-
--sort=<value> Sort the table by a column. Use "-" for descending.
121-
122-
DESCRIPTION
123-
Lists all existing tokens added to the session
124-
125-
ALIASES
126-
$ csdx tokens
127-
128-
EXAMPLES
129-
$ csdx auth:tokens
130-
```
131-
132-
_See code: [src/commands/auth/tokens/index.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/auth/tokens/index.ts)_
133-
134-
## `csdx auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]`
135-
136-
Adds management/delivery tokens to your session to use it with other CLI commands
137-
138-
```
139-
USAGE
140-
$ csdx auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]
141-
142-
FLAGS
143-
-a, --alias=<value> Alias (name) you want to assign to the token
144-
-e, --environment=<value> Environment name for delivery token
145-
-k, --stack-api-key=<value> Stack API Key
146-
-y, --yes Use this flag to skip confirmation
147-
--delivery Set this flag to save delivery token
148-
--management Set this flag to save management token
149-
--token=<value> [env: TOKEN] Add the token name
150-
151-
DESCRIPTION
152-
Adds management/delivery tokens to your session to use it with other CLI commands
153-
154-
EXAMPLES
155-
$ csdx auth:tokens:add
156-
157-
$ csdx auth:tokens:add -a <alias>
158-
159-
$ csdx auth:tokens:add -k <stack api key>
160-
161-
$ csdx auth:tokens:add --delivery
162-
163-
$ csdx auth:tokens:add --management
164-
165-
$ csdx auth:tokens:add -e <environment>
166-
167-
$ csdx auth:tokens:add --token <token>
168-
169-
$ csdx auth:tokens:add -a <alias> -k <stack api key> --management --token <management token>
170-
171-
$ csdx auth:tokens:add -a <alias> -k <stack api key> --delivery -e <environment> --token <delivery token>
172-
173-
$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --management --token <management token>
174-
175-
$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --delivery -e <environment> --token <delivery token>
176-
```
177-
178-
_See code: [src/commands/auth/tokens/add.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/auth/tokens/add.ts)_
179-
180-
## `csdx auth:tokens:remove`
181-
182-
Removes selected tokens
183-
184-
```
185-
USAGE
186-
$ csdx auth:tokens:remove [-a <value>] [-i]
187-
188-
FLAGS
189-
-a, --alias=<value> Alias (name) of the token to delete.
190-
-i, --ignore Ignores if the token is not present.
191-
192-
DESCRIPTION
193-
Removes selected tokens
194-
195-
EXAMPLES
196-
$ csdx auth:tokens:remove
197-
198-
$ csdx auth:tokens:remove -a <alias>
199-
```
200-
201-
_See code: [src/commands/auth/tokens/remove.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/auth/tokens/remove.ts)_
202-
203103
## `csdx auth:whoami`
204104

205105
Display current users email address
@@ -278,7 +178,7 @@ EXAMPLES
278178

279179
## `csdx tokens`
280180

281-
Lists all existing tokens added to the session
181+
Manage authentication tokens for API access
282182

283183
```
284184
USAGE
@@ -295,16 +195,116 @@ TABLE FLAGS
295195
<options: csv|json|yaml>
296196
--sort=<value> Sort the table by a column. Use "-" for descending.
297197
198+
DESCRIPTION
199+
Manage authentication tokens for API access
200+
201+
EXAMPLES
202+
$ csdx tokens:list
203+
204+
$ csdx tokens:add --alias mytoken
205+
206+
$ csdx tokens:remove --alias mytoken
207+
```
208+
209+
_See code: [src/commands/tokens/index.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/tokens/index.ts)_
210+
211+
## `csdx tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]`
212+
213+
Adds management/delivery tokens to your session to use it with other CLI commands
214+
215+
```
216+
USAGE
217+
$ csdx tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]
218+
219+
FLAGS
220+
-a, --alias=<value> Alias (name) you want to assign to the token
221+
-e, --environment=<value> Environment name for delivery token
222+
-k, --stack-api-key=<value> Stack API Key
223+
-y, --yes Use this flag to skip confirmation
224+
--delivery Set this flag to save delivery token
225+
--management Set this flag to save management token
226+
--token=<value> [env: TOKEN] Add the token name
227+
228+
DESCRIPTION
229+
Adds management/delivery tokens to your session to use it with other CLI commands
230+
231+
EXAMPLES
232+
$ csdx tokens:add
233+
234+
$ csdx tokens:add -a <alias>
235+
236+
$ csdx tokens:add -k <stack api key>
237+
238+
$ csdx tokens:add --delivery
239+
240+
$ csdx tokens:add --management
241+
242+
$ csdx tokens:add -e <environment>
243+
244+
$ csdx tokens:add --token <token>
245+
246+
$ csdx tokens:add -a <alias> -k <stack api key> --management --token <management token>
247+
248+
$ csdx tokens:add -a <alias> -k <stack api key> --delivery -e <environment> --token <delivery token>
249+
250+
$ csdx tokens:add --alias <alias> --stack-api-key <stack api key> --management --token <management token>
251+
252+
$ csdx tokens:add --alias <alias> --stack-api-key <stack api key> --delivery -e <environment> --token <delivery token>
253+
```
254+
255+
_See code: [src/commands/tokens/add.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/tokens/add.ts)_
256+
257+
## `csdx tokens:list`
258+
259+
Lists all existing tokens added to the session
260+
261+
```
262+
USAGE
263+
$ csdx tokens:list [--columns <value>] [--sort <value>] [--filter <value>] [--csv] [--no-truncate]
264+
[--no-header] [--output csv|json|yaml]
265+
266+
TABLE FLAGS
267+
--columns=<value> Specify columns to display, comma-separated.
268+
--csv Output results in CSV format.
269+
--filter=<value> Filter rows by a column value (e.g., name=foo).
270+
--no-header Hide table headers in output.
271+
--no-truncate Prevent truncation of long text in columns.
272+
--output=<option> Specify output format: csv, json, or yaml.
273+
<options: csv|json|yaml>
274+
--sort=<value> Sort the table by a column. Use "-" for descending.
275+
298276
DESCRIPTION
299277
Lists all existing tokens added to the session
300278
301-
ALIASES
302-
$ csdx tokens
279+
EXAMPLES
280+
$ csdx tokens:list
281+
```
282+
283+
_See code: [src/commands/tokens/list.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/tokens/list.ts)_
284+
285+
## `csdx tokens:remove`
286+
287+
Removes selected tokens
288+
289+
```
290+
USAGE
291+
$ csdx tokens:remove [-a <value>] [-i]
292+
293+
FLAGS
294+
-a, --alias=<value> Alias (name) of the token to delete.
295+
-i, --ignore Ignores if the token is not present.
296+
297+
DESCRIPTION
298+
Removes selected tokens
303299
304300
EXAMPLES
305-
$ csdx auth:tokens
301+
$ csdx tokens:remove
302+
303+
$ csdx tokens:remove -a <alias>
306304
```
307305

306+
_See code: [src/commands/tokens/remove.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-auth/src/commands/tokens/remove.ts)_
307+
308308
## `csdx whoami`
309309

310310
Display current users email address

packages/contentstack-auth/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@
7070
"auth:login": "LOGIN",
7171
"auth:logout": "LOGOUT",
7272
"auth:whoami": "WHOMAI",
73-
"auth:tokens": "LSTTKN",
74-
"auth:tokens:add": "ADDTKN",
75-
"auth:tokens:remove": "RMVTKN"
73+
"tokens": "TKNS",
74+
"tokens:list": "LSTTKNS",
75+
"tokens:add": "ADDTKNS",
76+
"tokens:remove": "RMVTKNS"
7677
}
7778
},
7879
"repository": "contentstack/cli"

packages/contentstack-auth/src/commands/auth/tokens/add.ts renamed to packages/contentstack-auth/src/commands/tokens/add.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ import {
99
log,
1010
handleAndLogError,
1111
} from '@contentstack/cli-utilities';
12-
import { BaseCommand } from '../../../base-command';
13-
import { askTokenType } from '../../../utils/interactive';
12+
import { BaseCommand } from '../../base-command';
13+
import { askTokenType } from '../../utils/interactive';
1414

1515
export default class TokensAddCommand extends BaseCommand<typeof TokensAddCommand> {
1616
static description = 'Adds management/delivery tokens to your session to use it with other CLI commands';
1717

1818
static examples = [
19-
'$ csdx auth:tokens:add',
20-
'$ csdx auth:tokens:add -a <alias>',
21-
'$ csdx auth:tokens:add -k <stack api key>',
22-
'$ csdx auth:tokens:add --delivery',
23-
'$ csdx auth:tokens:add --management',
24-
'$ csdx auth:tokens:add -e <environment>',
25-
'$ csdx auth:tokens:add --token <token>',
26-
'$ csdx auth:tokens:add -a <alias> -k <stack api key> --management --token <management token>',
27-
'$ csdx auth:tokens:add -a <alias> -k <stack api key> --delivery -e <environment> --token <delivery token>',
28-
'$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --management --token <management token>',
29-
'$ csdx auth:tokens:add --alias <alias> --stack-api-key <stack api key> --delivery -e <environment> --token <delivery token>',
19+
'$ csdx tokens:add',
20+
'$ csdx tokens:add -a <alias>',
21+
'$ csdx tokens:add -k <stack api key>',
22+
'$ csdx tokens:add --delivery',
23+
'$ csdx tokens:add --management',
24+
'$ csdx tokens:add -e <environment>',
25+
'$ csdx tokens:add --token <token>',
26+
'$ csdx tokens:add -a <alias> -k <stack api key> --management --token <management token>',
27+
'$ csdx tokens:add -a <alias> -k <stack api key> --delivery -e <environment> --token <delivery token>',
28+
'$ csdx tokens:add --alias <alias> --stack-api-key <stack api key> --management --token <management token>',
29+
'$ csdx tokens:add --alias <alias> --stack-api-key <stack api key> --delivery -e <environment> --token <delivery token>',
3030
];
3131

3232
static flags: FlagInput = {
@@ -59,7 +59,7 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
5959
};
6060

6161
static usage =
62-
'auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]';
62+
'tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]';
6363

6464
async run(): Promise<any> {
6565
log.debug('TokensAddCommand run method started.', this.contextDetails);
@@ -107,7 +107,7 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
107107
log.debug(`Alias obtained: ${alias}`, this.contextDetails);
108108
}
109109

110-
isAliasExist = Boolean(configHandler.get(`${configKeyTokens}.${alias}`)); // get to Check if alias already present
110+
isAliasExist = Boolean(configHandler.get(`${configKeyTokens}.${alias}`));
111111
log.debug(`Checking if alias exists: ${isAliasExist}`, { ...this.contextDetails, alias });
112112

113113
if (isAliasExist && !skipAliasReplaceConfirmation) {

0 commit comments

Comments
 (0)