gipity 1.1.41 → 1.1.43

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.
@@ -16,7 +16,7 @@ import { resolveProjectContext, getConfigPath } from '../config.js';
16
16
  import { sync } from '../sync.js';
17
17
  import { createProgressReporter } from '../progress.js';
18
18
  import { bold, muted, success } from '../colors.js';
19
- import { run } from '../helpers/index.js';
19
+ import { run, PROJECT_OPTION } from '../helpers/index.js';
20
20
  const ACCENT_SOURCE_LABEL = {
21
21
  theme: " (from the app's own theme --primary)",
22
22
  derived: ' (derived from project)',
@@ -47,7 +47,7 @@ and are versioned like any other file - rollback restores previous ones.`);
47
47
  brandCommand
48
48
  .command('show', { isDefault: true })
49
49
  .description('Show the stored brand and the resolved render spec')
50
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
50
+ .option(...PROJECT_OPTION)
51
51
  .option('--json', 'Output raw JSON')
52
52
  .action((opts) => run('Brand', async () => {
53
53
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -70,7 +70,7 @@ brandCommand
70
70
  .option('--tagline <text>', 'One-line subtitle on the share card (max 120 chars)')
71
71
  .option('--fix-head', 'Also splice the share/SEO head block into src/index.html (for apps installed before templates shipped it)')
72
72
  .option('--no-regenerate', 'Store the fields without re-rendering assets')
73
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
73
+ .option(...PROJECT_OPTION)
74
74
  .option('--json', 'Output raw JSON')
75
75
  .action((opts) => run('Brand', async () => {
76
76
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -106,7 +106,7 @@ brandCommand
106
106
  .command('apply')
107
107
  .description('Re-render all brand assets from the stored brand (no field changes)')
108
108
  .option('--fix-head', 'Also splice the share/SEO head block into src/index.html (for apps installed before templates shipped it)')
109
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
109
+ .option(...PROJECT_OPTION)
110
110
  .option('--json', 'Output raw JSON')
111
111
  .action((opts) => run('Brand', async () => {
112
112
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -2,7 +2,7 @@ import { Command, Option } from 'commander';
2
2
  import { get, post } from '../api.js';
3
3
  import { resolveProjectContext } from '../config.js';
4
4
  import { success, bold, muted, warning } from '../colors.js';
5
- import { run } from '../helpers/index.js';
5
+ import { run, PROJECT_OPTION } from '../helpers/index.js';
6
6
  // `email` is a command GROUP for the deployed app's email() service:
7
7
  // `email test` sends through it, `email log` lists recent sends.
8
8
  export const emailCommand = new Command('email')
@@ -18,7 +18,7 @@ emailCommand
18
18
  .option('--text <text>', 'Body text', 'This is a test email sent through your app\'s email() service. ✉️')
19
19
  .option('--reply-to <email>', 'Reply-To address')
20
20
  .option('--from-name <name>', 'Sender display name (address stays gipity@gipity.ai)')
21
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
21
+ .option(...PROJECT_OPTION)
22
22
  .option('--json', 'Output raw JSON')
23
23
  .action((to, opts) => run('Email', async () => {
24
24
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -50,7 +50,7 @@ emailCommand
50
50
  .description('Recent email() sends and skipped attempts from your app')
51
51
  .addOption(new Option('--range <range>', 'Time range').choices(['1h', '24h', '7d', '30d', '1y']).default('7d'))
52
52
  .option('--limit <n>', 'Max rows', '50')
53
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
53
+ .option(...PROJECT_OPTION)
54
54
  .option('--json', 'Output raw JSON')
55
55
  .action((opts) => run('Email', async () => {
56
56
  const { config } = await resolveProjectContext({ projectOverride: opts.project });
@@ -1,8 +1,7 @@
1
1
  import { Command, Option } from 'commander';
2
2
  import { get, post, del } from '../api.js';
3
- import { resolveProjectContext } from '../config.js';
4
3
  import { bold, muted, success, warning } from '../colors.js';
5
- import { run, printList } from '../helpers/index.js';
4
+ import { run, printList, PROJECT_OPTION, projectGuidFor } from '../helpers/index.js';
6
5
  /**
7
6
  * Project API keys - the revocable secret a script, cron, or agent sends as
8
7
  * `X-Api-Key` (or `Authorization: Bearer`) to write to YOUR app without a
@@ -68,6 +67,8 @@ export function scopesFromFlags(opts) {
68
67
  }
69
68
  if (opts.files !== undefined)
70
69
  scopes.files = opts.files;
70
+ if (opts.approvals !== undefined)
71
+ scopes.approvals = opts.approvals;
71
72
  if (opts.ip !== undefined) {
72
73
  const ips = splitList(opts.ip);
73
74
  if (!ips.length)
@@ -87,15 +88,12 @@ export function describeScopes(scopes) {
87
88
  parts.push(`tables: ${Object.entries(scopes.tables).map(([t, a]) => `${t}:${a}`).join(',')}`);
88
89
  if (scopes.files)
89
90
  parts.push(`files: ${scopes.files}`);
91
+ if (scopes.approvals)
92
+ parts.push(`approvals: ${scopes.approvals}`);
90
93
  if (scopes.ip)
91
94
  parts.push(`ip: ${scopes.ip.join(',')}`);
92
95
  return parts.join(' ');
93
96
  }
94
- const projectOpt = ['--project <guid-or-slug>', 'Target a specific project instead of cwd / Home'];
95
- async function projectGuid(opts) {
96
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
97
- return config.projectGuid;
98
- }
99
97
  keyCommand
100
98
  .command('create <name>')
101
99
  .description('Mint a project API key (shown once). Give it a name you will recognize later')
@@ -104,8 +102,9 @@ keyCommand
104
102
  .option('--functions <names>', 'Scope: only these functions (comma-separated)')
105
103
  .option('--tables <list>', 'Scope: only these Records tables, e.g. commands:write,logs:read')
106
104
  .addOption(new Option('--files <access>', 'Scope: app files access').choices(['read', 'write']))
105
+ .addOption(new Option('--approvals <access>', 'Scope: read and consume passkey approvals').choices(['read']))
107
106
  .option('--ip <list>', 'Scope: only from these IPs / CIDR ranges (comma-separated)')
108
- .option(...projectOpt)
107
+ .option(...PROJECT_OPTION)
109
108
  .option('--json', 'Output as JSON')
110
109
  .action((name, opts) => run('Create', async () => {
111
110
  const body = { name, role: opts.role };
@@ -118,7 +117,7 @@ keyCommand
118
117
  throw new Error('--expires-days must be a positive number of days');
119
118
  body.expires_in_days = days;
120
119
  }
121
- const res = await post(`/projects/${await projectGuid(opts)}/api-keys`, body);
120
+ const res = await post(`/projects/${await projectGuidFor(opts)}/api-keys`, body);
122
121
  const k = res.data;
123
122
  if (opts.json) {
124
123
  console.log(JSON.stringify(k));
@@ -141,20 +140,20 @@ keyCommand
141
140
  .command('list')
142
141
  .alias('ls')
143
142
  .description('List this project\'s API keys (values are never shown again)')
144
- .option(...projectOpt)
143
+ .option(...PROJECT_OPTION)
145
144
  .option('--json', 'Output as JSON')
146
145
  .action((opts) => run('List', async () => {
147
- const res = await get(`/projects/${await projectGuid(opts)}/api-keys`);
146
+ const res = await get(`/projects/${await projectGuidFor(opts)}/api-keys`);
148
147
  printList(res.data, opts, 'No API keys. Mint one with: gipity key create "my script" --role editor', (k) => `${bold(k.short_guid)} ${k.name} ${muted(`${k.role} ${describeScopes(k.scopes)} ${k.prefix}... last used ${fmtDate(k.last_used_at)} expires ${fmtDate(k.expires_at)}`)}`);
149
148
  }));
150
149
  keyCommand
151
150
  .command('revoke <short_guid>')
152
151
  .alias('rm')
153
152
  .description('Revoke a project API key (instant, irreversible)')
154
- .option(...projectOpt)
153
+ .option(...PROJECT_OPTION)
155
154
  .option('--json', 'Output as JSON')
156
155
  .action((shortGuid, opts) => run('Revoke', async () => {
157
- await del(`/projects/${await projectGuid(opts)}/api-keys/${encodeURIComponent(shortGuid)}`);
156
+ await del(`/projects/${await projectGuidFor(opts)}/api-keys/${encodeURIComponent(shortGuid)}`);
158
157
  if (opts.json) {
159
158
  console.log(JSON.stringify({ short_guid: shortGuid, revoked: true }));
160
159
  return;
@@ -7,6 +7,11 @@
7
7
  * `--inspect` to peek inside a source - metadata, contents, deploy phases,
8
8
  * and each function's permission surface - without creating anything.
9
9
  *
10
+ * A bundle saved with `gipity save --with-data` also carries database rows:
11
+ * the server builds the new app's database from the bundle's migrations and
12
+ * loads them, and the summary lists each table's row count (`--inspect` shows
13
+ * the same counts without loading anything).
14
+ *
10
15
  * Sources:
11
16
  * - a local .gip file (from `gipity save`) - uploaded as raw zip bytes
12
17
  * - `github:owner/repo[/sub/path][@ref]` or a github.com URL - resolved
@@ -88,6 +93,13 @@ function printManifest(m) {
88
93
  }
89
94
  }
90
95
  }
96
+ /** One line per table: ` database.table N rows`. */
97
+ function printTableCounts(databases) {
98
+ const rows = databases.flatMap(db => db.tables.map(t => ({ name: `${db.database}.${t.table}`, rows: t.rows })));
99
+ const width = Math.max(0, ...rows.map(r => r.name.length));
100
+ for (const r of rows)
101
+ console.log(` ${r.name.padEnd(width)} ${muted(`${r.rows} row(s)`)}`);
102
+ }
91
103
  function printInspect(d, source) {
92
104
  if (d.meta) {
93
105
  console.log(bold(d.meta.name));
@@ -104,13 +116,22 @@ function printInspect(d, source) {
104
116
  console.log('');
105
117
  printManifest(d.manifest);
106
118
  console.log('');
119
+ if (d.data) {
120
+ const tables = d.data.databases.reduce((n, db) => n + db.tables.length, 0);
121
+ console.log(bold(`Data: ${d.data.rows} row(s) in ${tables} table(s), ${formatBytes(d.data.bytes)}`));
122
+ printTableCounts(d.data.databases);
123
+ }
124
+ else {
125
+ console.log(muted('Data: none (code, migrations and seeds only)'));
126
+ }
127
+ console.log('');
107
128
  console.log(muted('Load it with `gipity load ' + source + '` - always creates a NEW project.'));
108
129
  }
109
130
  export const loadCommand = new Command('load')
110
131
  .description('Create a new app from a .gip bundle or a GitHub repo')
111
132
  .argument('<source>', 'A .gip file (from `gipity save`), github:owner/repo[/sub/path][@ref], or a github.com URL')
112
133
  .option('--name <name>', 'Name for the new project (default: the source\'s saved name)')
113
- .option('--inspect', 'Peek inside the source - contents, deploy phases, function permissions - without creating anything')
134
+ .option('--inspect', 'Peek inside the source - contents, deploy phases, function permissions, saved data - without creating anything')
114
135
  .option('--json', 'Output as JSON')
115
136
  .addHelpText('after', '\nLoad always creates a NEW project - it never merges into an existing one.'
116
137
  + '\nGitHub sources need a one-time `gipity github connect` (re-run it to grant more repos).')
@@ -190,7 +211,10 @@ export const loadCommand = new Command('load')
190
211
  failed: data.failed,
191
212
  partial,
192
213
  applied,
214
+ ...(data.data ? { data: data.data } : {}),
193
215
  }));
216
+ if (data.data && !data.data.loaded)
217
+ process.exitCode = 1;
194
218
  return;
195
219
  }
196
220
  console.log(success(`Created "${project.name}" (${project.slug}) from ${sourceLabel}`));
@@ -205,7 +229,25 @@ export const loadCommand = new Command('load')
205
229
  console.warn(warning(` ! ${f.path}: ${f.error}`));
206
230
  console.warn(warning('The project was still created and linked; the files above are missing from it.'));
207
231
  }
232
+ if (data.data?.loaded) {
233
+ console.log('');
234
+ console.log(success(`Loaded ${data.data.rows} row(s) into the app's database:`));
235
+ printTableCounts(data.data.databases);
236
+ }
237
+ else if (data.data) {
238
+ console.log('');
239
+ console.warn(warning(`The bundle's rows were not loaded: ${data.data.error}`));
240
+ console.warn(warning('The project was still created and linked, with an empty database. Delete it with `gipity project delete` and load again once the problem is fixed.'));
241
+ process.exitCode = 1;
242
+ }
208
243
  console.log('');
209
- console.log(`${muted('Next:')} cd ${dir} && ${brand('gipity deploy dev')}`);
244
+ if (data.data?.loaded) {
245
+ // The rows went into prod (where a new app lives); a dev environment starts empty.
246
+ console.log(`${muted('Next:')} cd ${dir} && ${brand('gipity deploy prod')}`);
247
+ console.log(muted('The rows are in the prod database. `gipity env create dev --data` gives you a dev copy with them.'));
248
+ }
249
+ else {
250
+ console.log(`${muted('Next:')} cd ${dir} && ${brand('gipity deploy dev')}`);
251
+ }
210
252
  }));
211
253
  //# sourceMappingURL=load.js.map
@@ -1,9 +1,8 @@
1
1
  import { Command } from 'commander';
2
2
  import { readFileSync } from 'fs';
3
3
  import { get, post, put, del } from '../api.js';
4
- import { resolveProjectContext } from '../config.js';
5
4
  import { bold, muted, success, warning } from '../colors.js';
6
- import { run } from '../helpers/index.js';
5
+ import { run, PROJECT_OPTION, projectGuidFor } from '../helpers/index.js';
7
6
  export const notifyCommand = new Command('notify')
8
7
  .description('Push notifications (web and native iOS)')
9
8
  .addHelpText('after', '\nGipity Notify: send a test notification, inspect subscriptions, or set up iOS push (notify apns).');
@@ -14,15 +13,15 @@ notifyCommand
14
13
  .option('--title <text>', 'Notification title', 'Test notification')
15
14
  .option('--body <text>', 'Notification body', 'Hello from Gipity Notify 👋')
16
15
  .option('--url <url>', 'URL to open when the notification is clicked')
17
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
16
+ .option(...PROJECT_OPTION)
18
17
  .option('--json', 'Output raw JSON')
19
18
  .action((opts) => run('Notify', async () => {
20
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
19
+ const projectGuid = await projectGuidFor(opts);
21
20
  const to = opts.to === 'all' ? 'all' : (opts.to.includes(',') ? opts.to.split(',').map((s) => s.trim()) : opts.to);
22
21
  const notification = { title: opts.title, body: opts.body };
23
22
  if (opts.url)
24
23
  notification.url = opts.url;
25
- const res = await post(`/api/${config.projectGuid}/services/notify/send`, { to, notification });
24
+ const res = await post(`/api/${projectGuid}/services/notify/send`, { to, notification });
26
25
  if (opts.json) {
27
26
  console.log(JSON.stringify(res.data));
28
27
  return;
@@ -50,11 +49,11 @@ notifyCommand
50
49
  notifyCommand
51
50
  .command('subs')
52
51
  .description('Show how many push subscriptions this app has, per user')
53
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
52
+ .option(...PROJECT_OPTION)
54
53
  .option('--json', 'Output raw JSON')
55
54
  .action((opts) => run('Notify', async () => {
56
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
57
- const res = await get(`/api/${config.projectGuid}/services/notify/subs`);
55
+ const projectGuid = await projectGuidFor(opts);
56
+ const res = await get(`/api/${projectGuid}/services/notify/subs`);
58
57
  if (opts.json) {
59
58
  console.log(JSON.stringify(res.data));
60
59
  return;
@@ -70,11 +69,11 @@ notifyCommand
70
69
  .command('rm')
71
70
  .description("Remove a user's push subscriptions and iOS devices (e.g. on account deletion)")
72
71
  .requiredOption('--user <guid>', 'User guid whose subscriptions to remove')
73
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
72
+ .option(...PROJECT_OPTION)
74
73
  .option('--json', 'Output raw JSON')
75
74
  .action((opts) => run('Notify', async () => {
76
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
77
- const res = await post(`/api/${config.projectGuid}/services/notify/remove`, { user_guid: opts.user });
75
+ const projectGuid = await projectGuidFor(opts);
76
+ const res = await post(`/api/${projectGuid}/services/notify/remove`, { user_guid: opts.user });
78
77
  if (opts.json) {
79
78
  console.log(JSON.stringify(res.data));
80
79
  return;
@@ -111,10 +110,10 @@ apnsCommand
111
110
  .requiredOption('--p8 <file>', 'Path to the AuthKey_<KEYID>.p8 file')
112
111
  .requiredOption('--bundle-id <id>', 'Your app bundle id, e.g. com.example.myapp')
113
112
  .option('--sandbox', 'Devices that register without an environment use the sandbox (development builds)')
114
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
113
+ .option(...PROJECT_OPTION)
115
114
  .option('--json', 'Output raw JSON')
116
115
  .action((opts) => run('Notify', async () => {
117
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
116
+ const projectGuid = await projectGuidFor(opts);
118
117
  let p8;
119
118
  try {
120
119
  p8 = readFileSync(opts.p8, 'utf-8');
@@ -122,7 +121,7 @@ apnsCommand
122
121
  catch {
123
122
  throw new Error(`Can't read ${opts.p8}. Pass the path to the AuthKey_<KEYID>.p8 file from Apple.`);
124
123
  }
125
- const res = await put(`/api/${config.projectGuid}/services/notify/apns`, {
124
+ const res = await put(`/api/${projectGuid}/services/notify/apns`, {
126
125
  team_id: opts.teamId, key_id: opts.keyId, bundle_id: opts.bundleId, p8, sandbox: !!opts.sandbox,
127
126
  });
128
127
  if (opts.json) {
@@ -135,11 +134,11 @@ apnsCommand
135
134
  apnsCommand
136
135
  .command('show')
137
136
  .description('Show the APNs setup for this app (never the key itself)')
138
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
137
+ .option(...PROJECT_OPTION)
139
138
  .option('--json', 'Output raw JSON')
140
139
  .action((opts) => run('Notify', async () => {
141
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
142
- const res = await get(`/api/${config.projectGuid}/services/notify/apns`);
140
+ const projectGuid = await projectGuidFor(opts);
141
+ const res = await get(`/api/${projectGuid}/services/notify/apns`);
143
142
  if (opts.json) {
144
143
  console.log(JSON.stringify(res.data));
145
144
  return;
@@ -149,11 +148,11 @@ apnsCommand
149
148
  apnsCommand
150
149
  .command('rm')
151
150
  .description('Remove the APNs key (iOS devices stop receiving notifications)')
152
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
151
+ .option(...PROJECT_OPTION)
153
152
  .option('--json', 'Output raw JSON')
154
153
  .action((opts) => run('Notify', async () => {
155
- const { config } = await resolveProjectContext({ projectOverride: opts.project });
156
- const res = await del(`/api/${config.projectGuid}/services/notify/apns`);
154
+ const projectGuid = await projectGuidFor(opts);
155
+ const res = await del(`/api/${projectGuid}/services/notify/apns`);
157
156
  if (opts.json) {
158
157
  console.log(JSON.stringify(res.data));
159
158
  return;
@@ -3,8 +3,10 @@
3
3
  *
4
4
  * A .gip is a zip of the project's file tree plus a reserved
5
5
  * `_gip/manifest.json` metadata entry. It pairs with `gipity load`, which
6
- * creates a brand-new project from a bundle. Code-only: secrets, custom
7
- * domains, chats, and database rows are never in a .gip.
6
+ * creates a brand-new project from a bundle. Secrets, custom domains, chats
7
+ * and app runtime uploads are never in a .gip. Database rows are left out
8
+ * unless the owner passes `--with-data` (every table's rows, up to the
9
+ * server's size cap); the schema always comes from the bundle's migrations.
8
10
  */
9
11
  import fs from 'fs';
10
12
  import path from 'path';
@@ -45,11 +47,14 @@ function dispositionFilename(headers) {
45
47
  export const saveCommand = new Command('save')
46
48
  .description('Save this app as a portable .gip bundle')
47
49
  .argument('[output]', 'Output .gip path, or a directory to write <slug>.gip into (default: ./<slug>.gip)')
50
+ .option('--with-data', 'Also save every table\'s rows from the app\'s database (owner only)')
48
51
  .option('--json', 'Output as JSON')
49
- .addHelpText('after', '\nRestore anywhere with `gipity load <file>.gip` - it always creates a NEW project.')
52
+ .addHelpText('after', '\nRestore anywhere with `gipity load <file>.gip` - it always creates a NEW project.'
53
+ + '\nWith --with-data, load also builds the database from the migrations and loads the rows.')
50
54
  .action((output, opts) => run('Save', async () => {
51
55
  const config = requireConfig();
52
- const doExport = () => downloadWithHeaders(`/projects/${config.projectGuid}/export`);
56
+ const query = opts.withData ? '?with_data=1' : '';
57
+ const doExport = () => downloadWithHeaders(`/projects/${config.projectGuid}/export${query}`);
53
58
  const { buffer, headers } = opts.json
54
59
  ? await doExport()
55
60
  : await withSpinner('Exporting...', doExport, { done: null });
@@ -63,6 +68,9 @@ export const saveCommand = new Command('save')
63
68
  const sha256 = createHash('sha256').update(buffer).digest('hex');
64
69
  const skipped = Number(headers.get('x-gip-skipped') ?? 0);
65
70
  const entries = zipEntryCount(buffer);
71
+ const data = opts.withData
72
+ ? { tables: Number(headers.get('x-gip-data-tables') ?? 0), rows: Number(headers.get('x-gip-data-rows') ?? 0) }
73
+ : null;
66
74
  if (opts.json) {
67
75
  console.log(JSON.stringify({
68
76
  path: dest,
@@ -70,6 +78,7 @@ export const saveCommand = new Command('save')
70
78
  sha256,
71
79
  ...(entries !== null ? { entries } : {}),
72
80
  skipped,
81
+ ...(data ? { data } : {}),
73
82
  }));
74
83
  return;
75
84
  }
@@ -78,12 +87,18 @@ export const saveCommand = new Command('save')
78
87
  console.log(` Size: ${formatBytes(buffer.length)}`);
79
88
  if (entries !== null)
80
89
  console.log(` Entries: ${entries} (including the bundle manifest)`);
90
+ if (data)
91
+ console.log(` Data: ${data.rows} row(s) from ${data.tables} table(s)`);
81
92
  console.log(` SHA-256: ${sha256}`);
82
93
  if (skipped > 0) {
83
94
  console.log('');
84
95
  console.warn(warning(`${skipped} file(s) were skipped (unreadable or over 100 MB) - this bundle is partial.`));
85
96
  console.warn(warning('Large assets belong in Gipity Storage, not in a code bundle.'));
86
97
  }
98
+ if (data) {
99
+ console.log('');
100
+ console.warn(warning('This bundle holds the app\'s data. Share it only with people allowed to see that data.'));
101
+ }
87
102
  console.log('');
88
103
  console.log(muted('Restore anywhere with `gipity load ' + path.basename(dest) + '` (creates a new project).'));
89
104
  }));
@@ -2,7 +2,7 @@ import { Command } from 'commander';
2
2
  import { get, put, del } from '../api.js';
3
3
  import { resolveProjectContext } from '../config.js';
4
4
  import { bold, muted, success } from '../colors.js';
5
- import { run } from '../helpers/index.js';
5
+ import { run, PROJECT_OPTION } from '../helpers/index.js';
6
6
  /** Build the query string for a scope. Account scope is project-independent;
7
7
  * project scope needs the linked app's guid. */
8
8
  async function scopeQuery(opts) {
@@ -19,7 +19,7 @@ secretsCommand
19
19
  .alias('ls')
20
20
  .description('List secret names (never values). Project secrets by default; --account for account-wide')
21
21
  .option('--account', 'Account-wide secrets shared across all your projects')
22
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
22
+ .option(...PROJECT_OPTION)
23
23
  .option('--json', 'Output raw JSON')
24
24
  .action((opts) => run('Secrets', async () => {
25
25
  const res = await get(`/secrets?${await scopeQuery(opts)}`);
@@ -46,7 +46,7 @@ secretsCommand
46
46
  .command('get <name>')
47
47
  .description('Secret values are write-only: confirms the secret exists, never prints its value')
48
48
  .option('--account', 'Look in account-wide secrets')
49
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
49
+ .option(...PROJECT_OPTION)
50
50
  .option('--json', 'Output raw JSON')
51
51
  .action((name, opts) => run('Secrets', async () => {
52
52
  const res = await get(`/secrets?${await scopeQuery(opts)}`);
@@ -63,7 +63,7 @@ secretsCommand
63
63
  .command('set <name> <value>')
64
64
  .description('Create or update a secret (UPPER_SNAKE_CASE name). Encrypted at rest; never echoed back')
65
65
  .option('--account', 'Store account-wide (shared across all your projects)')
66
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
66
+ .option(...PROJECT_OPTION)
67
67
  .option('--json', 'Output raw JSON')
68
68
  .action((name, value, opts) => run('Secrets', async () => {
69
69
  const res = await put(`/secrets?${await scopeQuery(opts)}`, { name, value });
@@ -79,7 +79,7 @@ secretsCommand
79
79
  .alias('delete')
80
80
  .description('Delete a secret')
81
81
  .option('--account', 'Delete from account-wide secrets')
82
- .option('--project <guid-or-slug>', 'Target a specific project instead of cwd / Home')
82
+ .option(...PROJECT_OPTION)
83
83
  .option('--json', 'Output raw JSON')
84
84
  .action((name, opts) => run('Secrets', async () => {
85
85
  const res = await del(`/secrets/${encodeURIComponent(name)}?${await scopeQuery(opts)}`);
@@ -6,4 +6,5 @@ export { printOutput, printList, printResult, pluckField, emitField } from './ou
6
6
  export { syncBeforeAction, syncAfterAction } from './sync.js';
7
7
  export { resolveJsonBody, resolveBody, resolveFormBody } from './body.js';
8
8
  export { parseDuration } from './duration.js';
9
+ export { PROJECT_OPTION, projectGuidFor } from './project.js';
9
10
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ import { resolveProjectContext } from '../config.js';
2
+ /** The `--project` option every project-scoped command takes: `.option(...PROJECT_OPTION)`. */
3
+ export const PROJECT_OPTION = ['--project <guid-or-slug>', 'Target a specific project instead of cwd / Home'];
4
+ /** The project guid a command acts on: `--project`, else the linked cwd / Home. */
5
+ export async function projectGuidFor(opts) {
6
+ const { config } = await resolveProjectContext({ projectOverride: opts.project });
7
+ return config.projectGuid;
8
+ }
9
+ //# sourceMappingURL=project.js.map