|
1 | 1 | import { program } from 'commander';
|
2 | 2 | import { getCheckpointData } from './client.js';
|
| 3 | +import { getCredentials } from './auth.js'; |
| 4 | +import * as jose from 'jose'; |
3 | 5 |
|
4 | 6 | program
|
5 | 7 | .command('fetch-operations')
|
6 |
| - .option('-t, --token [token]') |
7 |
| - .option('-e, --endpoint [endpoint]') |
8 |
| - .option('--raw') |
| 8 | + .option('-t, --token [token]', 'JWT to use for authentication') |
| 9 | + .option('-e, --endpoint [endpoint]', 'endpoint URI') |
| 10 | + .option('-c, --config [config]', 'path to powersync.yaml, to auto-generate a token from a HS256 key') |
| 11 | + .option('-u, --sub [sub]', 'sub field for auto-generated token') |
| 12 | + .option('--raw', 'output operations as received, without normalizing') |
9 | 13 | .action(async (options) => {
|
10 |
| - const data = await getCheckpointData({ endpoint: options.endpoint, token: options.token, raw: options.raw }); |
| 14 | + const credentials = await getCredentials(options); |
| 15 | + const data = await getCheckpointData({ ...credentials, raw: options.raw }); |
11 | 16 | console.log(JSON.stringify(data, null, 2));
|
12 | 17 | });
|
13 | 18 |
|
| 19 | +program |
| 20 | + .command('generate-token') |
| 21 | + .description('Generate a JWT from for a given powersync.yaml config file') |
| 22 | + .option('-c, --config [config]', 'path to powersync.yaml') |
| 23 | + .option('-u, --sub [sub]', 'sub field for auto-generated token') |
| 24 | + .action(async (options) => { |
| 25 | + const credentials = await getCredentials(options); |
| 26 | + const decoded = await jose.decodeJwt(credentials.token); |
| 27 | + |
| 28 | + console.error(`Payload:\n${JSON.stringify(decoded, null, 2)}\nToken:`); |
| 29 | + console.log(credentials.token); |
| 30 | + }); |
| 31 | + |
14 | 32 | await program.parseAsync();
|
0 commit comments