@sanity/runtime-cli 4.3.2 → 4.3.4

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.
Files changed (42) hide show
  1. package/README.md +17 -17
  2. package/dist/actions/blueprints/assets.js +2 -2
  3. package/dist/actions/blueprints/logs.js +2 -2
  4. package/dist/actions/blueprints/operations.js +2 -2
  5. package/dist/actions/blueprints/projects.js +1 -1
  6. package/dist/actions/blueprints/stacks.js +2 -2
  7. package/dist/actions/functions/env/list.js +2 -2
  8. package/dist/actions/functions/env/remove.js +2 -2
  9. package/dist/actions/functions/env/update.js +2 -2
  10. package/dist/actions/functions/invoke.js +2 -2
  11. package/dist/actions/functions/logs.js +3 -3
  12. package/dist/commands/blueprints/config.d.ts +1 -0
  13. package/dist/commands/blueprints/config.js +15 -5
  14. package/dist/commands/blueprints/deploy.js +4 -2
  15. package/dist/commands/blueprints/destroy.js +4 -2
  16. package/dist/commands/blueprints/info.js +4 -2
  17. package/dist/commands/blueprints/init.d.ts +1 -0
  18. package/dist/commands/blueprints/init.js +14 -6
  19. package/dist/commands/blueprints/logs.js +4 -2
  20. package/dist/commands/blueprints/plan.js +8 -7
  21. package/dist/commands/blueprints/stacks.js +4 -2
  22. package/dist/commands/functions/env/add.js +6 -3
  23. package/dist/commands/functions/env/list.js +6 -3
  24. package/dist/commands/functions/env/remove.js +6 -3
  25. package/dist/commands/functions/invoke.js +6 -3
  26. package/dist/commands/functions/logs.d.ts +5 -0
  27. package/dist/commands/functions/logs.js +25 -17
  28. package/dist/config.d.ts +3 -6
  29. package/dist/config.js +34 -22
  30. package/dist/server/static/components/app.css +850 -40
  31. package/dist/server/static/components/dataset-dropdown.js +5 -3
  32. package/dist/server/static/components/filters.d.ts +1 -0
  33. package/dist/server/static/components/filters.js +20 -0
  34. package/dist/server/static/components/function-list.js +2 -2
  35. package/dist/server/static/components/payload-panel.js +17 -17
  36. package/dist/server/static/components/projects-dropdown.js +5 -3
  37. package/dist/server/static/components/response-panel.js +18 -10
  38. package/dist/server/static/index.html +8 -29
  39. package/dist/utils/validated-token.d.ts +11 -0
  40. package/dist/utils/validated-token.js +59 -0
  41. package/oclif.manifest.json +1 -1
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/4.3.2 linux-x64 node-v22.14.0
23
+ @sanity/runtime-cli/4.3.4 linux-x64 node-v22.14.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -74,7 +74,7 @@ EXAMPLES
74
74
  $ sanity-run blueprints add function --name my-function --function-type document-publish
75
75
  ```
76
76
 
77
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/add.ts)_
77
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/add.ts)_
78
78
 
79
79
  ## `sanity-run blueprints config`
80
80
 
@@ -103,7 +103,7 @@ EXAMPLES
103
103
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
104
104
  ```
105
105
 
106
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/config.ts)_
106
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/config.ts)_
107
107
 
108
108
  ## `sanity-run blueprints deploy`
109
109
 
@@ -123,7 +123,7 @@ EXAMPLES
123
123
  $ sanity-run blueprints deploy
124
124
  ```
125
125
 
126
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/deploy.ts)_
126
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/deploy.ts)_
127
127
 
128
128
  ## `sanity-run blueprints destroy`
129
129
 
@@ -146,7 +146,7 @@ EXAMPLES
146
146
  $ sanity-run blueprints destroy --id ST-a1b2c3
147
147
  ```
148
148
 
149
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/destroy.ts)_
149
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/destroy.ts)_
150
150
 
151
151
  ## `sanity-run blueprints info`
152
152
 
@@ -168,7 +168,7 @@ EXAMPLES
168
168
  $ sanity-run blueprints info --id ST-a1b2c3
169
169
  ```
170
170
 
171
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/info.ts)_
171
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/info.ts)_
172
172
 
173
173
  ## `sanity-run blueprints init`
174
174
 
@@ -198,7 +198,7 @@ EXAMPLES
198
198
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId> --stack-name <stackName>
199
199
  ```
200
200
 
201
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/init.ts)_
201
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/init.ts)_
202
202
 
203
203
  ## `sanity-run blueprints logs`
204
204
 
@@ -220,7 +220,7 @@ EXAMPLES
220
220
  $ sanity-run blueprints logs --watch
221
221
  ```
222
222
 
223
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/logs.ts)_
223
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/logs.ts)_
224
224
 
225
225
  ## `sanity-run blueprints plan`
226
226
 
@@ -237,7 +237,7 @@ EXAMPLES
237
237
  $ sanity-run blueprints plan
238
238
  ```
239
239
 
240
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/plan.ts)_
240
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/plan.ts)_
241
241
 
242
242
  ## `sanity-run blueprints stacks`
243
243
 
@@ -259,7 +259,7 @@ EXAMPLES
259
259
  $ sanity-run blueprints stacks --projectId a1b2c3
260
260
  ```
261
261
 
262
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/blueprints/stacks.ts)_
262
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/blueprints/stacks.ts)_
263
263
 
264
264
  ## `sanity-run functions dev`
265
265
 
@@ -279,7 +279,7 @@ EXAMPLES
279
279
  $ sanity-run functions dev --port 8974
280
280
  ```
281
281
 
282
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/dev.ts)_
282
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/dev.ts)_
283
283
 
284
284
  ## `sanity-run functions env add NAME KEY VALUE`
285
285
 
@@ -301,7 +301,7 @@ EXAMPLES
301
301
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
302
302
  ```
303
303
 
304
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/env/add.ts)_
304
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/env/add.ts)_
305
305
 
306
306
  ## `sanity-run functions env list NAME`
307
307
 
@@ -321,7 +321,7 @@ EXAMPLES
321
321
  $ sanity-run functions env list MyFunction
322
322
  ```
323
323
 
324
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/env/list.ts)_
324
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/env/list.ts)_
325
325
 
326
326
  ## `sanity-run functions env remove NAME KEY`
327
327
 
@@ -342,7 +342,7 @@ EXAMPLES
342
342
  $ sanity-run functions env remove MyFunction API_URL
343
343
  ```
344
344
 
345
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/env/remove.ts)_
345
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/env/remove.ts)_
346
346
 
347
347
  ## `sanity-run functions invoke NAME`
348
348
 
@@ -368,7 +368,7 @@ EXAMPLES
368
368
  $ sanity-run functions invoke <name> --file 'payload.json'
369
369
  ```
370
370
 
371
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/invoke.ts)_
371
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/invoke.ts)_
372
372
 
373
373
  ## `sanity-run functions logs NAME`
374
374
 
@@ -400,7 +400,7 @@ EXAMPLES
400
400
  $ sanity-run functions logs <name> --delete
401
401
  ```
402
402
 
403
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/logs.ts)_
403
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/logs.ts)_
404
404
 
405
405
  ## `sanity-run functions test NAME`
406
406
 
@@ -433,7 +433,7 @@ EXAMPLES
433
433
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
434
434
  ```
435
435
 
436
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.2/src/commands/functions/test.ts)_
436
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.3.4/src/commands/functions/test.ts)_
437
437
 
438
438
  ## `sanity-run help [COMMAND]`
439
439
 
@@ -4,8 +4,8 @@ import { cwd } from 'node:process';
4
4
  import AdmZip from 'adm-zip';
5
5
  import config from '../../config.js';
6
6
  import getHeaders from '../../utils/get-headers.js';
7
- const { blueprints } = config.server;
8
- export const stashUrl = `${blueprints}vX/blueprints/assets/stash`;
7
+ const { apiUrl } = config;
8
+ export const stashUrl = `${apiUrl}vX/blueprints/assets/stash`;
9
9
  export async function stashAsset({ resource, auth, }) {
10
10
  if (!resource.src)
11
11
  throw new Error('Resource src is required');
@@ -1,8 +1,8 @@
1
1
  import { EventSource } from 'eventsource';
2
2
  import config from '../../config.js';
3
3
  import getHeaders from '../../utils/get-headers.js';
4
- const { blueprints } = config.server;
5
- export const logsUrl = `${blueprints}vX/blueprints/logs`;
4
+ const { apiUrl } = config;
5
+ export const logsUrl = `${apiUrl}vX/blueprints/logs`;
6
6
  export async function getLogs(stackId, auth) {
7
7
  const url = new URL(logsUrl);
8
8
  url.searchParams.append('stackId', stackId);
@@ -1,7 +1,7 @@
1
1
  import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
- const { blueprints } = config.server;
4
- export const stacksUrl = `${blueprints}vX/blueprints/stacks`;
3
+ const { apiUrl } = config;
4
+ export const stacksUrl = `${apiUrl}vX/blueprints/stacks`;
5
5
  export async function getOperation({ stackId, operationId, auth, }) {
6
6
  const path = `${stacksUrl}/${stackId}/operations/${operationId}`;
7
7
  const response = await fetch(path, {
@@ -1,6 +1,6 @@
1
1
  import config from '../../config.js';
2
2
  const { apiUrl } = config;
3
- const projectsUrl = `${apiUrl.toString()}v2021-06-07/projects`;
3
+ const projectsUrl = `${apiUrl}v2021-06-07/projects`;
4
4
  export async function listProjects({ token }) {
5
5
  const response = await fetch(projectsUrl, {
6
6
  method: 'GET',
@@ -1,7 +1,7 @@
1
1
  import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
- const { blueprints } = config.server;
4
- export const stacksUrl = `${blueprints}vX/blueprints/stacks`;
3
+ const { apiUrl } = config;
4
+ export const stacksUrl = `${apiUrl}vX/blueprints/stacks`;
5
5
  export async function listStacks(auth) {
6
6
  const response = await fetch(stacksUrl, {
7
7
  method: 'GET',
@@ -1,8 +1,8 @@
1
1
  import config from '../../../config.js';
2
2
  import getHeaders from '../../../utils/get-headers.js';
3
- const { functions } = config.server;
3
+ const { apiUrl } = config;
4
4
  export async function list(id, auth) {
5
- const response = await fetch(`${functions}vX/functions/${id}/envvars`, {
5
+ const response = await fetch(`${apiUrl}vX/functions/${id}/envvars`, {
6
6
  headers: getHeaders(auth),
7
7
  method: 'GET',
8
8
  });
@@ -1,8 +1,8 @@
1
1
  import config from '../../../config.js';
2
2
  import getHeaders from '../../../utils/get-headers.js';
3
- const { functions } = config.server;
3
+ const { apiUrl } = config;
4
4
  export async function remove(id, key, auth) {
5
- const response = await fetch(`${functions}vX/functions/${id}/envvars/${key}`, {
5
+ const response = await fetch(`${apiUrl}vX/functions/${id}/envvars/${key}`, {
6
6
  headers: getHeaders(auth),
7
7
  method: 'DELETE',
8
8
  });
@@ -1,8 +1,8 @@
1
1
  import config from '../../../config.js';
2
2
  import getHeaders from '../../../utils/get-headers.js';
3
- const { functions } = config.server;
3
+ const { apiUrl } = config;
4
4
  export async function update(id, key, value, auth) {
5
- const response = await fetch(`${functions}vX/functions/${id}/envvars/${key}`, {
5
+ const response = await fetch(`${apiUrl}vX/functions/${id}/envvars/${key}`, {
6
6
  body: JSON.stringify({ value }),
7
7
  headers: getHeaders(auth),
8
8
  method: 'PUT',
@@ -1,10 +1,10 @@
1
1
  import config from '../../config.js';
2
2
  import buildPayload from '../../utils/build-payload.js';
3
3
  import getHeaders from '../../utils/get-headers.js';
4
- const { functions } = config.server;
4
+ const { apiUrl } = config;
5
5
  export async function invoke(id, options, auth) {
6
6
  const payload = buildPayload(options);
7
- const response = await fetch(`${functions}vX/functions/${id}/invoke`, {
7
+ const response = await fetch(`${apiUrl}vX/functions/${id}/invoke`, {
8
8
  body: JSON.stringify({ data: payload }),
9
9
  headers: getHeaders(auth),
10
10
  method: 'POST',
@@ -1,9 +1,9 @@
1
1
  import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
- const { functions } = config.server;
3
+ const { apiUrl } = config;
4
4
  export async function logs(id, options, auth) {
5
5
  const { limit } = options;
6
- const response = await fetch(`${functions}vX/functions/${id}/logs?limit=${limit}`, {
6
+ const response = await fetch(`${apiUrl}vX/functions/${id}/logs?limit=${limit}`, {
7
7
  headers: getHeaders(auth),
8
8
  method: 'GET',
9
9
  });
@@ -16,7 +16,7 @@ export async function logs(id, options, auth) {
16
16
  };
17
17
  }
18
18
  export async function deleteLogs(id, auth) {
19
- const response = await fetch(`${functions}vX/functions/${id}/logs`, {
19
+ const response = await fetch(`${apiUrl}vX/functions/${id}/logs`, {
20
20
  headers: getHeaders(auth),
21
21
  method: 'DELETE',
22
22
  });
@@ -8,6 +8,7 @@ export default class Config extends Command {
8
8
  'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  'stack-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  };
11
+ sanityToken: string | undefined;
11
12
  run(): Promise<void>;
12
13
  promptForProjectId({ knownProjectId }: {
13
14
  knownProjectId?: string;
@@ -5,9 +5,8 @@ import Spinner from 'yocto-spinner';
5
5
  import { readBlueprintOnDisk, writeConfigFile } from '../../actions/blueprints/blueprint.js';
6
6
  import { listProjects } from '../../actions/blueprints/projects.js';
7
7
  import { getStack, listStacks } from '../../actions/blueprints/stacks.js';
8
- import config from '../../config.js';
9
8
  import { bold, dim, niceId } from '../../utils/display/colors.js';
10
- const { token } = config;
9
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
11
10
  export default class Config extends Command {
12
11
  static description = 'View or edit Blueprint configuration';
13
12
  static examples = [
@@ -39,6 +38,7 @@ export default class Config extends Command {
39
38
  dependsOn: ['edit'],
40
39
  }),
41
40
  };
41
+ sanityToken;
42
42
  async run() {
43
43
  const { flags } = await this.parse(Config);
44
44
  const { edit: editConfig, 'project-id': editProjectId, 'stack-id': editStackId, 'test-config': testConfig, } = flags;
@@ -56,6 +56,10 @@ export default class Config extends Command {
56
56
  }
57
57
  if (!editConfig && !testConfig)
58
58
  return;
59
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
60
+ if (tokenErr)
61
+ this.error(tokenErr.message);
62
+ this.sanityToken = token;
59
63
  if (testConfig && !editConfig) {
60
64
  if (configStackId && configProjectId) {
61
65
  await this.testConfigAndReport({ stackId: configStackId, projectId: configProjectId });
@@ -92,7 +96,9 @@ export default class Config extends Command {
92
96
  }
93
97
  }
94
98
  async promptForProjectId({ knownProjectId }) {
95
- const { ok, projects, error } = await listProjects({ token });
99
+ if (!this.sanityToken)
100
+ this.error('Unable to list projects. Missing API token.');
101
+ const { ok, projects, error } = await listProjects({ token: this.sanityToken });
96
102
  if (!ok)
97
103
  this.error(error ?? 'Unknown error listing projects');
98
104
  if (projects.length === 0) {
@@ -114,7 +120,9 @@ export default class Config extends Command {
114
120
  return pickedProjectId;
115
121
  }
116
122
  async promptForStackId({ projectId, knownStackId, }) {
117
- const auth = { token, projectId };
123
+ if (!this.sanityToken)
124
+ this.error('Unable to list Stacks. Missing API token.');
125
+ const auth = { token: this.sanityToken, projectId };
118
126
  // get stacks for selected project
119
127
  const { ok: stacksOk, stacks, error: stacksError } = await listStacks(auth);
120
128
  if (!stacksOk)
@@ -139,10 +147,12 @@ export default class Config extends Command {
139
147
  return undefined;
140
148
  }
141
149
  async testConfigAndReport({ stackId, projectId }) {
150
+ if (!this.sanityToken)
151
+ this.error('Unable to test the configuration. Missing API token.');
142
152
  const spinner = Spinner({ text: 'Testing the configuration...' }).start();
143
153
  const { ok, error } = await getStack({
144
154
  stackId,
145
- auth: { token, projectId },
155
+ auth: { token: this.sanityToken, projectId },
146
156
  });
147
157
  if (!ok) {
148
158
  spinner.error(error ?? 'Unknown error testing the configuration');
@@ -4,10 +4,9 @@ import Spinner from 'yocto-spinner';
4
4
  import { stashAsset } from '../../actions/blueprints/assets.js';
5
5
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
6
6
  import { getStack, updateStack } from '../../actions/blueprints/stacks.js';
7
- import config from '../../config.js';
8
7
  import { bold, niceId, red } from '../../utils/display/colors.js';
9
8
  import { isLocalFunctionResource } from '../../utils/types.js';
10
- const { token } = config;
9
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
11
10
  export default class Deploy extends Command {
12
11
  static description = 'Deploy a Blueprint';
13
12
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -18,6 +17,9 @@ export default class Deploy extends Command {
18
17
  }),
19
18
  };
20
19
  async run() {
20
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
21
+ if (tokenErr)
22
+ this.error(tokenErr.message);
21
23
  const { flags } = await this.parse(Deploy);
22
24
  const { errors, projectId, stackId, parsedBlueprint: { resources }, deployedStack, } = await readBlueprintOnDisk({ getStack: true, token });
23
25
  if (errors.length > 0) {
@@ -4,9 +4,8 @@ import inquirer from 'inquirer';
4
4
  import Spinner from 'yocto-spinner';
5
5
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
6
6
  import { destroyStack, getStack } from '../../actions/blueprints/stacks.js';
7
- import config from '../../config.js';
8
7
  import { bold, niceId } from '../../utils/display/colors.js';
9
- const { token } = config;
8
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
10
9
  export default class Destroy extends Command {
11
10
  static description = 'Destroy a deployed Blueprint Stack';
12
11
  static examples = [
@@ -24,6 +23,9 @@ export default class Destroy extends Command {
24
23
  }),
25
24
  };
26
25
  async run() {
26
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
27
+ if (tokenErr)
28
+ this.error(tokenErr.message);
27
29
  const { flags } = await this.parse(Destroy);
28
30
  const { errors, deployedStack, projectId } = await readBlueprintOnDisk({ getStack: true, token });
29
31
  if (errors.length > 0) {
@@ -1,10 +1,9 @@
1
1
  import { Command, Flags } from '@oclif/core';
2
2
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
3
3
  import { getStack } from '../../actions/blueprints/stacks.js';
4
- import config from '../../config.js';
5
4
  import { formatResourceTree, formatStackInfo } from '../../utils/display/blueprints-formatting.js';
6
5
  import { niceId } from '../../utils/display/colors.js';
7
- const { token } = config;
6
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
8
7
  export default class Info extends Command {
9
8
  static description = 'Show information about a deployed Blueprint Stack';
10
9
  static examples = [
@@ -18,6 +17,9 @@ export default class Info extends Command {
18
17
  }),
19
18
  };
20
19
  async run() {
20
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
21
+ if (tokenErr)
22
+ this.error(tokenErr.message);
21
23
  const { flags } = await this.parse(Info);
22
24
  const { errors, deployedStack, projectId, stackId } = await readBlueprintOnDisk({
23
25
  getStack: true,
@@ -9,6 +9,7 @@ export default class Init extends Command {
9
9
  'stack-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  'stack-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
11
  };
12
+ sanityToken: string | undefined;
12
13
  run(): Promise<void>;
13
14
  promptForBlueprintType(): Promise<string>;
14
15
  promptForProjectId(): Promise<string>;
@@ -5,9 +5,8 @@ import inquirer from 'inquirer';
5
5
  import { findBlueprintFile, writeBlueprintToDisk, writeConfigFile, } from '../../actions/blueprints/blueprint.js';
6
6
  import { listProjects } from '../../actions/blueprints/projects.js';
7
7
  import { createStack, listStacks } from '../../actions/blueprints/stacks.js';
8
- import config from '../../config.js';
9
8
  import { bold, dim, niceId, underline } from '../../utils/display/colors.js';
10
- const { token } = config;
9
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
11
10
  export default class Init extends Command {
12
11
  static description = 'Initialize a new Blueprint';
13
12
  static examples = [
@@ -40,6 +39,7 @@ export default class Init extends Command {
40
39
  exclusive: ['stack-id'],
41
40
  }),
42
41
  };
42
+ sanityToken;
43
43
  async run() {
44
44
  const { flags } = await this.parse(Init);
45
45
  const { 'blueprint-type': flagBlueprintType, 'project-id': flagProjectId, 'stack-id': flagStackId, 'stack-name': flagStackName, } = flags;
@@ -47,6 +47,10 @@ export default class Init extends Command {
47
47
  if (existingBlueprint) {
48
48
  this.error(`A blueprint file already exists: ${existingBlueprint.fileName}`);
49
49
  }
50
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
51
+ if (tokenErr)
52
+ this.error(tokenErr.message);
53
+ this.sanityToken = token;
50
54
  const blueprintExtension = flagBlueprintType || (await this.promptForBlueprintType());
51
55
  if (!blueprintExtension)
52
56
  this.error('Blueprint type is required.');
@@ -58,7 +62,7 @@ export default class Init extends Command {
58
62
  if (flagStackName) {
59
63
  const stack = await this.createEmptyStack({
60
64
  stackPayload: { name: flagStackName, projectId, document: { resources: [] } },
61
- auth: { token, projectId },
65
+ auth: { token: this.sanityToken, projectId },
62
66
  });
63
67
  stackId = stack.id;
64
68
  }
@@ -93,7 +97,9 @@ export default class Init extends Command {
93
97
  return pickedBlueprintsType;
94
98
  }
95
99
  async promptForProjectId() {
96
- const { ok: projectsOk, error: projectsErr, projects } = await listProjects({ token });
100
+ if (!this.sanityToken)
101
+ this.error('Unable to list projects. Missing API token.');
102
+ const { ok: projectsOk, error: projectsErr, projects, } = await listProjects({ token: this.sanityToken });
97
103
  if (!projectsOk)
98
104
  this.error(projectsErr ?? 'Unknown error listing projects');
99
105
  if (projects.length === 0) {
@@ -114,7 +120,9 @@ export default class Init extends Command {
114
120
  return pickedProjectId;
115
121
  }
116
122
  async promptForStackId({ projectId }) {
117
- const { ok: stacksOk, error: stacksErr, stacks } = await listStacks({ token, projectId });
123
+ if (!this.sanityToken)
124
+ this.error('Unable to list Stacks. Missing API token.');
125
+ const { ok: stacksOk, error: stacksErr, stacks, } = await listStacks({ token: this.sanityToken, projectId });
118
126
  if (!stacksOk)
119
127
  this.error(stacksErr || 'Failed to list Stacks');
120
128
  const stackChoices = [{ name: bold('✨ Create a new Stack'), value: 'new' }];
@@ -144,7 +152,7 @@ export default class Init extends Command {
144
152
  ]);
145
153
  const stack = await this.createEmptyStack({
146
154
  stackPayload: { name: stackName, projectId, document: { resources: [] } },
147
- auth: { token, projectId },
155
+ auth: { token: this.sanityToken, projectId },
148
156
  });
149
157
  return stack.id;
150
158
  }
@@ -2,11 +2,10 @@ import { Command, Flags } from '@oclif/core';
2
2
  import Spinner from 'yocto-spinner';
3
3
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
4
4
  import { findNewestLogTimestamp, getLogs, getRecentLogs, isNewerLog, streamLogs, } from '../../actions/blueprints/logs.js';
5
- import config from '../../config.js';
6
5
  import { formatTitle } from '../../utils/display/blueprints-formatting.js';
7
6
  import { bold, niceId, red } from '../../utils/display/colors.js';
8
7
  import { formatLogEntry, formatLogsByDay, organizeLogsByDay, } from '../../utils/display/logs-formatting.js';
9
- const { token } = config;
8
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
10
9
  export default class Logs extends Command {
11
10
  static description = 'Display logs for a Blueprint stack';
12
11
  static examples = [
@@ -22,6 +21,9 @@ export default class Logs extends Command {
22
21
  }),
23
22
  };
24
23
  async run() {
24
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
25
+ if (tokenErr)
26
+ this.error(tokenErr.message);
25
27
  const { flags } = await this.parse(Logs);
26
28
  const watchMode = flags.watch;
27
29
  try {
@@ -1,13 +1,15 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
3
- import config from '../../config.js';
4
3
  import { formatResourceTree, formatTitle } from '../../utils/display/blueprints-formatting.js';
5
- const { token } = config;
4
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
6
5
  export default class Plan extends Command {
7
6
  static description = 'Enumerate resources to be deployed - will not modify any resources';
8
7
  static examples = ['<%= config.bin %> <%= command.id %>'];
9
8
  async run() {
10
- const { errors, projectId, stackId, parsedBlueprint: { resources }, fileInfo, } = await readBlueprintOnDisk({ token });
9
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
10
+ if (tokenErr)
11
+ this.error(tokenErr.message);
12
+ const { errors, projectId, stackId, parsedBlueprint: { resources }, fileInfo, deployedStack, } = await readBlueprintOnDisk({ getStack: true, token });
11
13
  if (errors.length > 0) {
12
14
  // printErrors(errors)
13
15
  this.log('Blueprint parse errors:');
@@ -15,10 +17,9 @@ export default class Plan extends Command {
15
17
  }
16
18
  if (!projectId)
17
19
  this.log('Blueprint must contain a project resource');
18
- const name = stackId || 'Unknown'; // TODO: what is a name, really?
19
- this.log(`${formatTitle('Blueprint', name)} Plan\n`);
20
- this.log(`Blueprint document: (${fileInfo.fileName})`);
21
- this.log('');
20
+ const name = deployedStack?.name ?? stackId ?? 'Unknown';
21
+ this.log(`${formatTitle('Stack', name)} Plan`);
22
+ this.log(`(${fileInfo.fileName})\n`);
22
23
  this.log(formatResourceTree(resources));
23
24
  this.log('\nRun `sanity blueprints deploy` to deploy these changes');
24
25
  }
@@ -1,10 +1,9 @@
1
1
  import { Command, Flags } from '@oclif/core';
2
2
  import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
3
3
  import { listStacks } from '../../actions/blueprints/stacks.js';
4
- import config from '../../config.js';
5
4
  import { formatStacksListing } from '../../utils/display/blueprints-formatting.js';
6
5
  import { bold, niceId } from '../../utils/display/colors.js';
7
- const { token } = config;
6
+ import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
8
7
  export default class Stacks extends Command {
9
8
  static description = 'List all Blueprint stacks';
10
9
  static examples = [
@@ -18,6 +17,9 @@ export default class Stacks extends Command {
18
17
  }),
19
18
  };
20
19
  async run() {
20
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
21
+ if (tokenErr)
22
+ this.error(tokenErr.message);
21
23
  const { flags } = await this.parse(Stacks);
22
24
  let { projectId } = flags;
23
25
  let stackId;
@@ -2,9 +2,9 @@ import { Args, Command } from '@oclif/core';
2
2
  import Spinner from 'yocto-spinner';
3
3
  import { readBlueprintOnDisk } from '../../../actions/blueprints/blueprint.js';
4
4
  import { update } from '../../../actions/functions/env/update.js';
5
- import config from '../../../config.js';
6
5
  import { red } from '../../../utils/display/colors.js';
7
6
  import { findFunctionByName } from '../../../utils/find-function.js';
7
+ import { validTokenOrErrorMessage } from '../../../utils/validated-token.js';
8
8
  export default class Add extends Command {
9
9
  static args = {
10
10
  name: Args.string({ description: 'The name of the Sanity Function', required: true }),
@@ -16,17 +16,20 @@ export default class Add extends Command {
16
16
  '<%= config.bin %> <%= command.id %> MyFunction API_URL https://api.example.com/',
17
17
  ];
18
18
  async run() {
19
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
20
+ if (tokenErr)
21
+ this.error(tokenErr.message);
19
22
  const { args } = await this.parse(Add);
20
23
  const spinner = Spinner({
21
24
  text: `Updating "${args.key}" environment variable in "${args.name}"`,
22
25
  }).start();
23
- const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
26
+ const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token });
24
27
  if (!deployedStack)
25
28
  this.error('Stack not found'); // returns
26
29
  const { projectId } = deployedStack;
27
30
  const { externalId } = findFunctionByName(deployedStack, args.name);
28
31
  const result = await update(externalId, args.key, args.value, {
29
- token: config.token,
32
+ token,
30
33
  projectId,
31
34
  });
32
35
  if (result.ok) {
@@ -1,8 +1,8 @@
1
1
  import { Args, Command } from '@oclif/core';
2
2
  import { readBlueprintOnDisk } from '../../../actions/blueprints/blueprint.js';
3
3
  import { list } from '../../../actions/functions/env/list.js';
4
- import config from '../../../config.js';
5
4
  import { findFunctionByName } from '../../../utils/find-function.js';
5
+ import { validTokenOrErrorMessage } from '../../../utils/validated-token.js';
6
6
  export default class List extends Command {
7
7
  static args = {
8
8
  name: Args.string({ description: 'The name of the Sanity Function', required: true }),
@@ -10,14 +10,17 @@ export default class List extends Command {
10
10
  static description = 'List the environment variables for a Sanity function';
11
11
  static examples = ['<%= config.bin %> <%= command.id %> MyFunction'];
12
12
  async run() {
13
+ const { token, error: tokenErr } = await validTokenOrErrorMessage();
14
+ if (tokenErr)
15
+ this.error(tokenErr.message);
13
16
  const { args } = await this.parse(List);
14
- const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
17
+ const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token });
15
18
  if (!deployedStack)
16
19
  this.error('Stack not found. Is it deployed?'); // returns
17
20
  const { projectId } = deployedStack;
18
21
  const { externalId } = findFunctionByName(deployedStack, args.name);
19
22
  const result = await list(externalId, {
20
- token: config.token,
23
+ token,
21
24
  projectId,
22
25
  });
23
26
  if (!result.ok) {