powersync 0.4.1 → 0.5.0

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
@@ -44,6 +44,7 @@ Example:
44
44
  * [`powersync instance create`](#powersync-instance-create)
45
45
  * [`powersync instance deploy`](#powersync-instance-deploy)
46
46
  * [`powersync instance destroy`](#powersync-instance-destroy)
47
+ * [`powersync instance generate-dev-token`](#powersync-instance-generate-dev-token)
47
48
  * [`powersync instance schema`](#powersync-instance-schema)
48
49
  * [`powersync instance set`](#powersync-instance-set)
49
50
  * [`powersync instance status`](#powersync-instance-status)
@@ -71,7 +72,7 @@ DESCRIPTION
71
72
  Display help for powersync.
72
73
  ```
73
74
 
74
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.21/src/commands/help.ts)_
75
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.8/src/commands/help.ts)_
75
76
 
76
77
  ## `powersync init`
77
78
 
@@ -89,7 +90,7 @@ EXAMPLES
89
90
  $ npx powersync init
90
91
  ```
91
92
 
92
- _See code: [src/commands/init.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/init.ts)_
93
+ _See code: [src/commands/init.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/init.ts)_
93
94
 
94
95
  ## `powersync instance config`
95
96
 
@@ -106,7 +107,7 @@ EXAMPLES
106
107
  $ npx powersync instance config
107
108
  ```
108
109
 
109
- _See code: [src/commands/instance/config.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/config.ts)_
110
+ _See code: [src/commands/instance/config.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/config.ts)_
110
111
 
111
112
  ## `powersync instance create`
112
113
 
@@ -114,16 +115,19 @@ Create a new instance.
114
115
 
115
116
  ```
116
117
  USAGE
117
- $ npx powersync instance create [--databaseName <value>] [--hostname <value>] [--name <value>] [--port <value>]
118
- [--region <value>] [--useSupabaseAuth]
118
+ $ npx powersync instance create [-n <value>] [-h <value>] [-a <value>] [-w <value>] [-i <value>] [-o <value>] [-r
119
+ <value>] [-s] [-a]
119
120
 
120
121
  FLAGS
121
- --databaseName=<value> Name of the database.
122
- --hostname=<value> Hostname to connect to database.
123
- --name=<value> Name of the instance.
124
- --port=<value> Port number to connect to database.
125
- --region=<value> Region to deploy instance to.
126
- --useSupabaseAuth Use Supabase for auth.
122
+ -a, --jwksAudiences=<value> JWKS audiences (comma separated).
123
+ -a, --[no-]useSupabaseAuth Use Supabase auth.
124
+ -h, --hostname=<value> Hostname to connect to database.
125
+ -i, --name=<value> Name of the instance.
126
+ -n, --databaseName=<value> Name of the database.
127
+ -o, --port=<value> Port number to connect to database.
128
+ -r, --region=<value> Region to deploy instance to.
129
+ -s, --skipInteraction Skip interactivity.
130
+ -w, --jwksUri=<value> JWKS URL (must include https://).
127
131
 
128
132
  DESCRIPTION
129
133
  Create a new instance.
@@ -132,7 +136,7 @@ EXAMPLES
132
136
  $ npx powersync instance create
133
137
  ```
134
138
 
135
- _See code: [src/commands/instance/create.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/create.ts)_
139
+ _See code: [src/commands/instance/create.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/create.ts)_
136
140
 
137
141
  ## `powersync instance deploy`
138
142
 
@@ -140,15 +144,16 @@ Deploy changes to an existing instance.
140
144
 
141
145
  ```
142
146
  USAGE
143
- $ npx powersync instance deploy [--databaseName <value>] [--hostname <value>] [--name <value>] [--port <value>]
144
- [--useSupabaseAuth]
147
+ $ npx powersync instance deploy [-n <value>] [-h <value>] [-a <value>] [-w <value>] [-o <value>] [-s] [-a]
145
148
 
146
149
  FLAGS
147
- --databaseName=<value> Name of the database.
148
- --hostname=<value> Hostname to connect to database.
149
- --name=<value> Name of the instance.
150
- --port=<value> Port number to connect to database.
151
- --useSupabaseAuth Use Supabase auth.
150
+ -a, --jwksAudiences=<value> JWKS audiences (comma separated).
151
+ -a, --[no-]useSupabaseAuth Use Supabase auth.
152
+ -h, --hostname=<value> Hostname to connect to database.
153
+ -n, --databaseName=<value> Name of the database.
154
+ -o, --port=<value> Port number to connect to database.
155
+ -s, --skipInteraction Skip interactivity.
156
+ -w, --jwksUri=<value> JWKS URL (must include https://).
152
157
 
153
158
  DESCRIPTION
154
159
  Deploy changes to an existing instance.
@@ -157,7 +162,7 @@ EXAMPLES
157
162
  $ npx powersync instance deploy
158
163
  ```
159
164
 
160
- _See code: [src/commands/instance/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/deploy.ts)_
165
+ _See code: [src/commands/instance/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/deploy.ts)_
161
166
 
162
167
  ## `powersync instance destroy`
163
168
 
@@ -177,7 +182,28 @@ EXAMPLES
177
182
  $ npx powersync instance destroy
178
183
  ```
179
184
 
180
- _See code: [src/commands/instance/destroy.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/destroy.ts)_
185
+ _See code: [src/commands/instance/destroy.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/destroy.ts)_
186
+
187
+ ## `powersync instance generate-dev-token`
188
+
189
+ Generate a developer token using the Token subject/ User ID.
190
+
191
+ ```
192
+ USAGE
193
+ $ npx powersync instance generate-dev-token [-e <value>] [-u <value>]
194
+
195
+ FLAGS
196
+ -e, --expiresInSeconds=<value> The token expiry in seconds.
197
+ -u, --userId=<value> The Token subject/User ID for the developer token
198
+
199
+ DESCRIPTION
200
+ Generate a developer token using the Token subject/ User ID.
201
+
202
+ EXAMPLES
203
+ $ npx powersync instance generate-dev-token
204
+ ```
205
+
206
+ _See code: [src/commands/instance/generate-dev-token.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/generate-dev-token.ts)_
181
207
 
182
208
  ## `powersync instance schema`
183
209
 
@@ -194,7 +220,7 @@ EXAMPLES
194
220
  $ npx powersync instance schema
195
221
  ```
196
222
 
197
- _See code: [src/commands/instance/schema.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/schema.ts)_
223
+ _See code: [src/commands/instance/schema.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/schema.ts)_
198
224
 
199
225
  ## `powersync instance set`
200
226
 
@@ -216,7 +242,7 @@ EXAMPLES
216
242
  $ npx powersync instance set --instanceId=1234
217
243
  ```
218
244
 
219
- _See code: [src/commands/instance/set.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/set.ts)_
245
+ _See code: [src/commands/instance/set.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/set.ts)_
220
246
 
221
247
  ## `powersync instance status`
222
248
 
@@ -241,7 +267,7 @@ EXAMPLES
241
267
  $ npx powersync instance status --orgId=1234 --projectId=1234 --instanceId=1234 --authToken=1234
242
268
  ```
243
269
 
244
- _See code: [src/commands/instance/status.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/status.ts)_
270
+ _See code: [src/commands/instance/status.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/status.ts)_
245
271
 
246
272
  ## `powersync instance stop`
247
273
 
@@ -261,7 +287,7 @@ EXAMPLES
261
287
  $ npx powersync instance stop
262
288
  ```
263
289
 
264
- _See code: [src/commands/instance/stop.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/stop.ts)_
290
+ _See code: [src/commands/instance/stop.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/stop.ts)_
265
291
 
266
292
  ## `powersync instance sync-rules deploy`
267
293
 
@@ -286,7 +312,7 @@ EXAMPLES
286
312
  $ npx powersync instance sync-rules deploy -f path/to/file
287
313
  ```
288
314
 
289
- _See code: [src/commands/instance/sync-rules/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/sync-rules/deploy.ts)_
315
+ _See code: [src/commands/instance/sync-rules/deploy.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/sync-rules/deploy.ts)_
290
316
 
291
317
  ## `powersync instance sync-rules generate-schema`
292
318
 
@@ -312,7 +338,7 @@ EXAMPLES
312
338
  $ npx powersync instance sync-rules generate-schema -f path/to/file
313
339
  ```
314
340
 
315
- _See code: [src/commands/instance/sync-rules/generate-schema.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/sync-rules/generate-schema.ts)_
341
+ _See code: [src/commands/instance/sync-rules/generate-schema.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/sync-rules/generate-schema.ts)_
316
342
 
317
343
  ## `powersync instance sync-rules validate`
318
344
 
@@ -336,7 +362,7 @@ EXAMPLES
336
362
  $ npx powersync instance sync-rules validate -f path/to/file
337
363
  ```
338
364
 
339
- _See code: [src/commands/instance/sync-rules/validate.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instance/sync-rules/validate.ts)_
365
+ _See code: [src/commands/instance/sync-rules/validate.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instance/sync-rules/validate.ts)_
340
366
 
341
367
  ## `powersync instances`
342
368
 
@@ -353,5 +379,5 @@ EXAMPLES
353
379
  $ npx powersync instances
354
380
  ```
355
381
 
356
- _See code: [src/commands/instances.ts](https://github.com/powersync-ja/cli/blob/v0.4.1/src/commands/instances.ts)_
382
+ _See code: [src/commands/instances.ts](https://github.com/powersync-ja/cli/blob/v0.5.0/src/commands/instances.ts)_
357
383
  <!-- commandsstop -->
@@ -2,5 +2,6 @@ import { Command } from '@oclif/core';
2
2
  export default class Init extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
+ catch(error: any): Promise<never>;
5
6
  run(): Promise<void>;
6
7
  }
@@ -7,6 +7,13 @@ import { green, red } from '../utils.js';
7
7
  export default class Init extends Command {
8
8
  static description = 'Initialize the CLI.';
9
9
  static examples = ['<%= config.bin %> <%= command.id %>'];
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ async catch(error) {
12
+ if ('errorData' in error && error.errorData.status === 401) {
13
+ return ux.error(red(`You are using an invalid API token. Please double-check your token.`), { exit: 1 });
14
+ }
15
+ throw error;
16
+ }
10
17
  async run() {
11
18
  const authTokenQuestions = [
12
19
  {
@@ -7,9 +7,12 @@ export default class InstanceCreate extends Command {
7
7
  databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
8
  databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
9
  hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ jwksAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
12
  name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
13
  port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
14
  region: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
15
+ skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
13
16
  useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
14
17
  };
15
18
  run(): Promise<void>;
@@ -2,121 +2,75 @@
2
2
  import { Command, Flags, ux } from '@oclif/core';
3
3
  import inquirer from 'inquirer';
4
4
  import ora from 'ora';
5
+ import { generateCommonDeployQuestions } from '../../commands.utils.js';
5
6
  import * as PowerSyncClient from '../../service/powersync.client.js';
6
7
  import { bold, checkForValidEnvFile, green, red, updateEnvFileVariableValue } from '../../utils.js';
7
8
  export default class InstanceCreate extends Command {
8
9
  static description = 'Create a new instance.';
9
10
  static examples = ['<%= config.bin %> <%= command.id %>'];
10
11
  static flags = {
11
- databaseName: Flags.string({ description: 'Name of the database.' }),
12
- databasePassword: Flags.string({ description: 'Password of the database.', hidden: true }),
13
- databaseUsername: Flags.string({ description: 'Username of the database.', hidden: true }),
14
- hostname: Flags.string({ description: 'Hostname to connect to database.' }),
15
- name: Flags.string({ description: 'Name of the instance.' }),
16
- port: Flags.integer({ description: 'Port number to connect to database.' }),
17
- region: Flags.string({ description: 'Region to deploy instance to.' }),
18
- useSupabaseAuth: Flags.boolean({ description: 'Use Supabase for auth.' })
12
+ databaseName: Flags.string({ char: 'n', description: 'Name of the database.' }),
13
+ databasePassword: Flags.string({ char: 'p', description: 'Password of the database.', hidden: true }),
14
+ databaseUsername: Flags.string({ char: 'u', description: 'Username of the database.', hidden: true }),
15
+ hostname: Flags.string({ char: 'h', description: 'Hostname to connect to database.' }),
16
+ jwksAudiences: Flags.string({ char: 'a', default: '', description: 'JWKS audiences (comma separated).' }),
17
+ jwksUri: Flags.string({ char: 'w', description: 'JWKS URL (must include https://).' }),
18
+ name: Flags.string({ char: 'i', description: 'Name of the instance.' }),
19
+ port: Flags.integer({ char: 'o', description: 'Port number to connect to database.' }),
20
+ region: Flags.string({ char: 'r', description: 'Region to deploy instance to.' }),
21
+ skipInteraction: Flags.boolean({ char: 's', description: 'Skip interactivity.' }),
22
+ useSupabaseAuth: Flags.boolean({ allowNo: true, char: 'a', description: 'Use Supabase auth.' })
19
23
  };
20
24
  async run() {
21
25
  checkForValidEnvFile(this.config.bin);
22
26
  const { flags } = await this.parse(InstanceCreate);
23
27
  const regions = await PowerSyncClient.getRegions();
24
- const questions = [
25
- {
26
- message: 'What do you want to name your instance?',
27
- name: 'name',
28
- type: 'input',
29
- validate(value) {
30
- return value.length > 3 ? true : 'Please enter a name with at least 3 characters.';
31
- },
32
- when: !flags.name
33
- },
34
- {
35
- choices: regions.map((region) => region.toUpperCase()),
36
- message: 'What region do you want to use?',
37
- name: 'region',
38
- type: 'list',
39
- when: !flags.region
40
- },
41
- {
42
- message: 'What is your database hostname?',
43
- name: 'hostname',
44
- type: 'input',
45
- validate(value) {
46
- return value.length > 0 ? true : 'Please enter your hostname.';
47
- },
48
- when: !flags.hostname
49
- },
50
- {
51
- default: 5432,
52
- message: 'What is the port number of your database?',
53
- name: 'port',
54
- type: 'input',
55
- validate(value) {
56
- const number = Number.parseFloat(value);
57
- if (Number.isNaN(number)) {
58
- return 'Please enter a valid port number.';
59
- }
60
- return String(value).length > 0 ? true : 'Please enter your port number.';
61
- },
62
- when: !flags.port
63
- },
64
- {
65
- default: 'postgres',
66
- message: 'What is your database name?',
67
- name: 'databaseName',
68
- type: 'input',
69
- validate(value) {
70
- return value.length > 0 ? true : 'Please enter your database name.';
71
- },
72
- when: !flags.databaseName
73
- },
74
- {
75
- default: 'postgres',
76
- message: 'What is your database username?',
77
- name: 'databaseUsername',
78
- type: 'input',
79
- validate(value) {
80
- return value.length > 0 ? true : 'Please enter your database username.';
81
- },
82
- when: !flags.databaseUsername
83
- },
84
- {
85
- message: 'What is your database password?',
86
- name: 'databasePassword',
87
- type: 'password',
88
- validate(value) {
89
- return value.length > 0 ? true : 'Please enter your password.';
28
+ let answers = {
29
+ databaseName: undefined,
30
+ databasePassword: undefined,
31
+ databaseUsername: undefined,
32
+ hostname: undefined,
33
+ jwksAudiences: undefined,
34
+ jwksUri: undefined,
35
+ name: undefined,
36
+ port: undefined,
37
+ region: undefined,
38
+ useSupabaseAuth: undefined
39
+ };
40
+ if (!flags.skipInteraction) {
41
+ const questions = [
42
+ {
43
+ message: 'What do you want to name your instance?',
44
+ name: 'name',
45
+ type: 'input',
46
+ validate(value) {
47
+ return value.length > 3 ? true : 'Please enter a name with at least 3 characters.';
48
+ },
49
+ when: !flags.name
90
50
  },
91
- when: !flags.databasePassword
92
- },
93
- {
94
- default: false,
95
- message: 'Are you using Supabase auth?',
96
- name: 'useSupabaseAuth',
97
- type: 'confirm',
98
- when: !flags.useSupabaseAuth
99
- },
100
- {
101
- message: 'Enter your JWKS URL?',
102
- name: 'jwtServerUrl',
103
- type: 'input',
104
- validate(value) {
105
- const urlRegex = /^(https?|ftp):\/\/[^\s#$./?].\S*$/i;
106
- return urlRegex.test(value) ? true : 'Please enter a valid URL.';
51
+ {
52
+ choices: regions.map((region) => region.toUpperCase()),
53
+ message: 'What region do you want to use?',
54
+ name: 'region',
55
+ type: 'list',
56
+ when: !flags.region
107
57
  },
108
- when: (answers) => !answers.useSupabaseAuth
109
- }
110
- ];
111
- const answers = await inquirer.prompt(questions);
58
+ ...generateCommonDeployQuestions(flags)
59
+ ];
60
+ answers = await inquirer.prompt(questions);
61
+ }
112
62
  const instanceName = flags.name || answers.name;
113
63
  const port = flags.port || answers.port;
114
64
  const password = flags.databasePassword || answers.databasePassword;
115
65
  const hostname = flags.hostname || answers.hostname;
116
66
  const databaseName = flags.databaseName || answers.databaseName;
117
67
  const databaseUsername = flags.databaseUsername || answers.databaseUsername;
118
- const region = flags.region || answers.region;
68
+ const region = flags.region?.toLowerCase() || answers.region?.toLowerCase();
119
69
  const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
70
+ const jwksUri = flags.jwksUri || answers.jwksUri;
71
+ const answerAudiences = answers.jwksAudiences ? answers.jwksAudiences.split(',') : [];
72
+ const flagsAudiences = flags.jwksAudiences ? flags.jwksAudiences.split(',') : [];
73
+ const audiences = flagsAudiences || answerAudiences;
120
74
  const connection = {
121
75
  database: databaseName,
122
76
  debug_api: false,
@@ -133,10 +87,11 @@ export default class InstanceCreate extends Command {
133
87
  };
134
88
  const config = {
135
89
  client_auth: {
136
- jwks_uri: answers.jwksUri || undefined,
90
+ additional_audiences: audiences || undefined,
91
+ jwks_uri: jwksUri || undefined,
137
92
  supabase: useSupabaseAuth
138
93
  },
139
- region: region.toLowerCase(),
94
+ region,
140
95
  replication: {
141
96
  connections: [connection]
142
97
  }
@@ -7,8 +7,10 @@ export default class InstanceDeploy extends Command {
7
7
  databasePassword: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
8
  databaseUsername: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
9
  hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- name: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ jwksAudiences: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ jwksUri: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
12
  port: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
+ skipInteraction: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
12
14
  useSupabaseAuth: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
13
15
  };
14
16
  run(): Promise<void>;
@@ -2,106 +2,56 @@
2
2
  import { Command, Flags, ux } from '@oclif/core';
3
3
  import inquirer from 'inquirer';
4
4
  import ora from 'ora';
5
+ import { generateCommonDeployQuestions } from '../../commands.utils.js';
5
6
  import * as PowerSyncClient from '../../service/powersync.client.js';
6
7
  import { bold, checkForValidEnvFile, green, red } from '../../utils.js';
7
8
  export default class InstanceDeploy extends Command {
8
9
  static description = 'Deploy changes to an existing instance.';
9
10
  static examples = ['<%= config.bin %> <%= command.id %>'];
10
11
  static flags = {
11
- databaseName: Flags.string({ description: 'Name of the database.' }),
12
- databasePassword: Flags.string({ description: 'Password of the database.', hidden: true }),
13
- databaseUsername: Flags.string({ description: 'Username of the database.', hidden: true }),
14
- hostname: Flags.string({ description: 'Hostname to connect to database.' }),
15
- name: Flags.string({ description: 'Name of the instance.' }),
16
- port: Flags.integer({ description: 'Port number to connect to database.' }),
17
- useSupabaseAuth: Flags.boolean({ description: 'Use Supabase auth.' })
12
+ databaseName: Flags.string({ char: 'n', description: 'Name of the database.' }),
13
+ databasePassword: Flags.string({ char: 'p', description: 'Password of the database.', hidden: true }),
14
+ databaseUsername: Flags.string({ char: 'u', description: 'Username of the database.', hidden: true }),
15
+ hostname: Flags.string({ char: 'h', description: 'Hostname to connect to database.' }),
16
+ jwksAudiences: Flags.string({ char: 'a', description: 'JWKS audiences (comma separated).' }),
17
+ jwksUri: Flags.string({ char: 'w', description: 'JWKS URL (must include https://).' }),
18
+ port: Flags.integer({ char: 'o', description: 'Port number to connect to database.' }),
19
+ skipInteraction: Flags.boolean({ char: 's', description: 'Skip interactivity.' }),
20
+ useSupabaseAuth: Flags.boolean({ allowNo: true, char: 'a', description: 'Use Supabase auth.' })
18
21
  };
19
22
  async run() {
20
23
  checkForValidEnvFile(this.config.bin, true);
21
24
  const { flags } = await this.parse(InstanceDeploy);
22
- const questions = [
23
- {
24
- message: 'What is your database hostname?',
25
- name: 'hostname',
26
- type: 'input',
27
- validate(value) {
28
- return value.length > 0 ? true : 'Please enter your hostname.';
29
- },
30
- when: !flags.hostname
31
- },
32
- {
33
- default: 5432,
34
- message: 'What is the port number of your database?',
35
- name: 'port',
36
- type: 'input',
37
- validate(value) {
38
- const number = Number.parseFloat(value);
39
- if (Number.isNaN(number)) {
40
- return 'Please enter a valid port number.';
41
- }
42
- return String(value).length > 0 ? true : 'Please enter your port number.';
43
- },
44
- when: !flags.port
45
- },
46
- {
47
- default: 'postgres',
48
- message: 'What is your database name?',
49
- name: 'databaseName',
50
- type: 'input',
51
- validate(value) {
52
- return value.length > 0 ? true : 'Please enter your database name.';
53
- },
54
- when: !flags.databaseName
55
- },
56
- {
57
- default: 'postgres',
58
- message: 'What is your database username?',
59
- name: 'databaseUsername',
60
- type: 'input',
61
- validate(value) {
62
- return value.length > 0 ? true : 'Please enter your database username.';
63
- },
64
- when: !flags.databaseUsername
65
- },
66
- {
67
- message: 'What is your database password?',
68
- name: 'databasePassword',
69
- type: 'password',
70
- validate(value) {
71
- return value.length > 0 ? true : 'Please enter your password.';
72
- },
73
- when: !flags.databasePassword
74
- },
75
- {
76
- default: false,
77
- message: 'Are you using Supabase auth?',
78
- name: 'useSupabaseAuth',
79
- type: 'confirm',
80
- when: !flags.useSupabaseAuth
81
- },
82
- {
83
- message: 'Enter your JWKS URL?',
84
- name: 'jwtServerUrl',
85
- type: 'input',
86
- validate(value) {
87
- const urlRegex = /^(https?|ftp):\/\/[^\s#$./?].\S*$/i;
88
- return urlRegex.test(value) ? true : 'Please enter a valid URL.';
89
- },
90
- when: (answers) => !answers.useSupabaseAuth
91
- }
92
- ];
93
- const answers = await inquirer.prompt(questions);
25
+ let answers = {
26
+ databaseName: undefined,
27
+ databasePassword: undefined,
28
+ databaseUsername: undefined,
29
+ hostname: undefined,
30
+ jwksAudiences: undefined,
31
+ jwksUri: undefined,
32
+ port: undefined,
33
+ useSupabaseAuth: undefined
34
+ };
35
+ if (!flags.skipInteraction) {
36
+ const questions = generateCommonDeployQuestions(flags);
37
+ answers = await inquirer.prompt(questions);
38
+ }
94
39
  const port = flags.port || answers.port;
95
40
  const password = flags.databasePassword || answers.databasePassword;
96
41
  const hostname = flags.hostname || answers.hostname;
97
42
  const databaseName = flags.databaseName || answers.databaseName;
98
43
  const databaseUsername = flags.databaseUsername || answers.databaseUsername;
99
44
  const useSupabaseAuth = flags.useSupabaseAuth || answers.useSupabaseAuth;
45
+ const jwksUri = flags.jwksUri || answers.jwksUri;
46
+ const answerAudiences = answers.jwksAudiences ? answers.jwksAudiences.split(',') : [];
47
+ const flagsAudiences = flags.jwksAudiences ? flags.jwksAudiences.split(',') : [];
48
+ const audiences = flagsAudiences || answerAudiences;
100
49
  const instanceConfig = await PowerSyncClient.getInstanceConfig();
101
50
  const { region } = instanceConfig.config;
102
51
  const config = {
103
52
  client_auth: {
104
- jwks_uri: answers.jwksUri || undefined,
53
+ additional_audiences: audiences || undefined,
54
+ jwks_uri: jwksUri || undefined,
105
55
  supabase: useSupabaseAuth
106
56
  },
107
57
  region,
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class InstanceGenerateDevToken extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ expiresInSeconds: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
+ userId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
+ };
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,54 @@
1
+ import { Command, Flags, ux } from '@oclif/core';
2
+ import clipboard from 'clipboardy';
3
+ import inquirer from 'inquirer';
4
+ import * as PowerSyncClient from '../../service/powersync.client.js';
5
+ import { bold, checkForValidEnvFile, convertSeconds, green } from '../../utils.js';
6
+ export default class InstanceGenerateDevToken extends Command {
7
+ static description = 'Generate a developer token using the Token subject/ User ID.';
8
+ static examples = ['<%= config.bin %> <%= command.id %>'];
9
+ static flags = {
10
+ expiresInSeconds: Flags.string({
11
+ char: 'e',
12
+ description: 'The token expiry in seconds.'
13
+ }),
14
+ userId: Flags.string({ char: 'u', description: 'The Token subject/User ID for the developer token' })
15
+ };
16
+ async run() {
17
+ checkForValidEnvFile(this.config.bin, true);
18
+ const { flags } = await this.parse(InstanceGenerateDevToken);
19
+ const questions = [
20
+ {
21
+ message: 'Please enter the Token subject/ User ID to use for the developer token.',
22
+ name: 'userId',
23
+ type: 'input',
24
+ when: !flags.userId
25
+ },
26
+ {
27
+ default: 43_200,
28
+ message: 'Please enter the token expiry in seconds (Defaults to 12 hours).',
29
+ name: 'expiresInSeconds',
30
+ type: 'input',
31
+ validate(value) {
32
+ const number = Number.parseFloat(value);
33
+ if (Number.isNaN(number)) {
34
+ return 'Please enter a valid number.';
35
+ }
36
+ return String(value).length > 0 ? true : 'Please enter a valid number.';
37
+ },
38
+ when: !flags.expiresInSeconds
39
+ }
40
+ ];
41
+ const answers = await inquirer.prompt(questions);
42
+ const userId = flags.userId || answers.userId;
43
+ const expiresInSeconds = Number(flags.expiresInSeconds) || answers.expiresInSeconds;
44
+ const developerToken = await PowerSyncClient.generateDevToken(userId, expiresInSeconds);
45
+ clipboard.writeSync(developerToken);
46
+ clipboard.readSync();
47
+ ux.log(green(`Developer token generated successfully.
48
+ Token has been copied to your clipboard.
49
+ Token details:
50
+ Expires in: ${bold(convertSeconds(expiresInSeconds))}
51
+ JWT:
52
+ ${bold(developerToken)}`));
53
+ }
54
+ }