@sanity/runtime-cli 12.4.0 → 13.0.1

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 (113) hide show
  1. package/README.md +176 -63
  2. package/dist/actions/blueprints/assets.d.ts +3 -1
  3. package/dist/actions/blueprints/assets.js +8 -4
  4. package/dist/actions/blueprints/blueprint.d.ts +2 -1
  5. package/dist/actions/blueprints/blueprint.js +3 -1
  6. package/dist/actions/blueprints/config.d.ts +5 -2
  7. package/dist/actions/blueprints/config.js +4 -4
  8. package/dist/actions/blueprints/logs-streaming.d.ts +4 -2
  9. package/dist/actions/blueprints/logs-streaming.js +5 -2
  10. package/dist/actions/blueprints/logs.d.ts +2 -1
  11. package/dist/actions/blueprints/logs.js +4 -2
  12. package/dist/actions/blueprints/resources.d.ts +2 -1
  13. package/dist/actions/blueprints/resources.js +2 -2
  14. package/dist/actions/blueprints/stacks.d.ts +12 -6
  15. package/dist/actions/blueprints/stacks.js +18 -11
  16. package/dist/actions/functions/dev.d.ts +2 -1
  17. package/dist/actions/functions/dev.js +2 -2
  18. package/dist/actions/functions/env/list.d.ts +2 -1
  19. package/dist/actions/functions/env/list.js +4 -2
  20. package/dist/actions/functions/env/remove.d.ts +2 -1
  21. package/dist/actions/functions/env/remove.js +4 -2
  22. package/dist/actions/functions/env/update.d.ts +2 -1
  23. package/dist/actions/functions/env/update.js +4 -2
  24. package/dist/actions/functions/logs.d.ts +4 -3
  25. package/dist/actions/functions/logs.js +10 -6
  26. package/dist/actions/node.d.ts +2 -1
  27. package/dist/actions/node.js +2 -2
  28. package/dist/actions/sanity/examples.d.ts +5 -2
  29. package/dist/actions/sanity/examples.js +6 -6
  30. package/dist/actions/sanity/projects.d.ts +7 -3
  31. package/dist/actions/sanity/projects.js +11 -7
  32. package/dist/baseCommands.d.ts +4 -0
  33. package/dist/baseCommands.js +8 -2
  34. package/dist/commands/blueprints/add.d.ts +1 -0
  35. package/dist/commands/blueprints/add.js +12 -8
  36. package/dist/commands/blueprints/config.d.ts +1 -0
  37. package/dist/commands/blueprints/config.js +10 -4
  38. package/dist/commands/blueprints/deploy.d.ts +1 -0
  39. package/dist/commands/blueprints/deploy.js +8 -2
  40. package/dist/commands/blueprints/destroy.d.ts +1 -0
  41. package/dist/commands/blueprints/destroy.js +8 -2
  42. package/dist/commands/blueprints/doctor.d.ts +1 -0
  43. package/dist/commands/blueprints/doctor.js +7 -2
  44. package/dist/commands/blueprints/info.d.ts +1 -0
  45. package/dist/commands/blueprints/info.js +9 -3
  46. package/dist/commands/blueprints/init.d.ts +1 -0
  47. package/dist/commands/blueprints/init.js +20 -11
  48. package/dist/commands/blueprints/logs.d.ts +1 -0
  49. package/dist/commands/blueprints/logs.js +8 -2
  50. package/dist/commands/blueprints/plan.d.ts +1 -0
  51. package/dist/commands/blueprints/plan.js +6 -2
  52. package/dist/commands/blueprints/stacks.d.ts +1 -0
  53. package/dist/commands/blueprints/stacks.js +8 -4
  54. package/dist/commands/functions/add.d.ts +1 -0
  55. package/dist/commands/functions/add.js +8 -2
  56. package/dist/commands/functions/dev.d.ts +1 -0
  57. package/dist/commands/functions/dev.js +14 -3
  58. package/dist/commands/functions/env/add.d.ts +2 -1
  59. package/dist/commands/functions/env/add.js +6 -2
  60. package/dist/commands/functions/env/list.d.ts +2 -1
  61. package/dist/commands/functions/env/list.js +6 -2
  62. package/dist/commands/functions/env/remove.d.ts +2 -1
  63. package/dist/commands/functions/env/remove.js +6 -2
  64. package/dist/commands/functions/logs.d.ts +2 -1
  65. package/dist/commands/functions/logs.js +7 -4
  66. package/dist/commands/functions/test.d.ts +2 -1
  67. package/dist/commands/functions/test.js +6 -2
  68. package/dist/cores/blueprints/config.js +9 -9
  69. package/dist/cores/blueprints/deploy.js +14 -16
  70. package/dist/cores/blueprints/destroy.js +6 -6
  71. package/dist/cores/blueprints/doctor.js +20 -27
  72. package/dist/cores/blueprints/info.js +3 -3
  73. package/dist/cores/blueprints/init.d.ts +3 -3
  74. package/dist/cores/blueprints/init.js +15 -8
  75. package/dist/cores/blueprints/logs.js +6 -7
  76. package/dist/cores/blueprints/plan.js +1 -0
  77. package/dist/cores/blueprints/stacks.js +4 -4
  78. package/dist/cores/functions/add.js +8 -3
  79. package/dist/cores/functions/dev.js +2 -2
  80. package/dist/cores/functions/env/add.js +3 -4
  81. package/dist/cores/functions/env/list.js +3 -4
  82. package/dist/cores/functions/env/remove.js +3 -4
  83. package/dist/cores/functions/index.d.ts +3 -9
  84. package/dist/cores/functions/logs.js +8 -9
  85. package/dist/cores/functions/test.js +7 -8
  86. package/dist/cores/index.d.ts +4 -7
  87. package/dist/cores/index.js +3 -3
  88. package/dist/index.d.ts +18 -2
  89. package/dist/index.js +20 -2
  90. package/dist/server/app.d.ts +2 -1
  91. package/dist/server/app.js +4 -4
  92. package/dist/server/handlers/invoke.d.ts +2 -1
  93. package/dist/server/handlers/invoke.js +2 -2
  94. package/dist/server/static/components/response-panel.js +3 -0
  95. package/dist/server/static/components/rule-panel.js +9 -1
  96. package/dist/utils/display/prompt.d.ts +5 -2
  97. package/dist/utils/display/prompt.js +5 -4
  98. package/dist/utils/functions/fetch-document.d.ts +3 -2
  99. package/dist/utils/functions/fetch-document.js +7 -6
  100. package/dist/utils/index.d.ts +2 -0
  101. package/dist/utils/index.js +2 -0
  102. package/dist/utils/logger.d.ts +13 -0
  103. package/dist/utils/logger.js +61 -0
  104. package/dist/utils/other/github.d.ts +2 -1
  105. package/dist/utils/other/github.js +4 -2
  106. package/dist/utils/other/npmjs.d.ts +2 -1
  107. package/dist/utils/other/npmjs.js +4 -2
  108. package/dist/utils/traced-fetch.d.ts +35 -0
  109. package/dist/utils/traced-fetch.js +238 -0
  110. package/dist/utils/validated-token.d.ts +3 -2
  111. package/dist/utils/validated-token.js +6 -4
  112. package/oclif.manifest.json +175 -38
  113. package/package.json +13 -5
@@ -1,5 +1,4 @@
1
1
  import chalk from 'chalk';
2
- import ora from 'ora';
3
2
  import { getLogs, getRecentLogs } from '../../actions/blueprints/logs.js';
4
3
  import { setupLogStreaming } from '../../actions/blueprints/logs-streaming.js';
5
4
  import { formatTitle } from '../../utils/display/blueprints-formatting.js';
@@ -8,13 +7,13 @@ import { niceId } from '../../utils/display/presenters.js';
8
7
  export async function blueprintLogsCore(options) {
9
8
  const { log, auth, stackId, deployedStack, flags } = options;
10
9
  const { watch = false, verbose: _verbose = false } = flags;
11
- const spinner = ora(`Fetching recent logs for Stack deployment ${niceId(stackId)}`).start();
10
+ const spinner = log.ora(`Fetching recent logs for Stack deployment ${niceId(stackId)}`).start();
12
11
  try {
13
12
  if (watch) {
14
- const { ok, logs, error } = await getLogs(stackId, auth);
13
+ const { ok, logs, error } = await getLogs(stackId, auth, log);
15
14
  if (!ok) {
16
15
  spinner.fail(`${chalk.red('Failed')} to retrieve logs`);
17
- log(`Error: ${error || 'Unknown error'}`);
16
+ log.error(`Error: ${error || 'Unknown error'}`);
18
17
  return { success: false, error: error || 'Failed to retrieve logs' };
19
18
  }
20
19
  spinner.stop();
@@ -43,10 +42,10 @@ export async function blueprintLogsCore(options) {
43
42
  };
44
43
  }
45
44
  // Regular non-streaming logs
46
- const { ok, logs, error } = await getLogs(stackId, auth);
45
+ const { ok, logs, error } = await getLogs(stackId, auth, log);
47
46
  if (!ok) {
48
47
  spinner.fail(`${chalk.red('Failed')} to retrieve Stack deployment logs`);
49
- log(`Error: ${error || 'Unknown error'}`);
48
+ log.error(`Error: ${error || 'Unknown error'}`);
50
49
  return { success: false, error: error || 'Failed to retrieve logs' };
51
50
  }
52
51
  if (logs.length === 0) {
@@ -63,7 +62,7 @@ export async function blueprintLogsCore(options) {
63
62
  catch (err) {
64
63
  spinner.fail('Failed to retrieve Stack deployment logs');
65
64
  const errorMessage = err instanceof Error ? err.message : String(err);
66
- log(`Error: ${errorMessage}`);
65
+ log.error(`Error: ${errorMessage}`);
67
66
  return { success: false, error: errorMessage };
68
67
  }
69
68
  }
@@ -11,6 +11,7 @@ export async function blueprintPlanCore(options) {
11
11
  const stackResponse = await getStack({
12
12
  auth: { token, scopeType, scopeId },
13
13
  stackId,
14
+ logger: log,
14
15
  });
15
16
  if (!stackResponse.ok) {
16
17
  log(chalk.dim('Unable to retrieve live Stack deployment for comparison'));
@@ -7,7 +7,7 @@ export async function blueprintStacksCore(options) {
7
7
  const { scopeType: blueprintScopeType, scopeId: blueprintScopeId, stackId: blueprintStackId, } = blueprint;
8
8
  const { 'project-id': flagProjectId, 'organization-id': flagOrganizationId, verbose: _verbose = false, } = flags;
9
9
  if (flagOrganizationId && flagProjectId) {
10
- log('Cannot specify both --organization-id and --project-id');
10
+ log.error('Cannot specify both --organization-id and --project-id');
11
11
  return { success: false, error: 'Cannot specify both --organization-id and --project-id' };
12
12
  }
13
13
  let scopeType = blueprintScopeType;
@@ -21,11 +21,11 @@ export async function blueprintStacksCore(options) {
21
21
  scopeId = flagProjectId;
22
22
  }
23
23
  if (!scopeType || !scopeId) {
24
- log('Run in a Blueprint directory or provide a Project with --project-id');
24
+ log.error('Run in a Blueprint directory or provide a Project with --project-id');
25
25
  return { success: false, error: 'Unable to determine scope for Blueprint Stacks' };
26
26
  }
27
27
  try {
28
- const { ok, stacks, error } = await listStacks({ token, scopeType, scopeId });
28
+ const { ok, stacks, error } = await listStacks({ token, scopeType, scopeId }, log);
29
29
  if (!ok)
30
30
  return { success: false, error: error || 'Failed to list stacks' };
31
31
  if (!stacks || stacks.length === 0) {
@@ -38,7 +38,7 @@ export async function blueprintStacksCore(options) {
38
38
  }
39
39
  catch (error) {
40
40
  const errorMessage = error instanceof Error ? error.message : String(error);
41
- log(`Error: ${errorMessage}`);
41
+ log.error(`Error: ${errorMessage}`);
42
42
  return { success: false, error: errorMessage };
43
43
  }
44
44
  }
@@ -33,7 +33,11 @@ export async function functionAddCore(options) {
33
33
  if (flagExample) {
34
34
  // short circuit whole command for example flag
35
35
  log(`Setting up "${flagExample}"...`);
36
- const exampleExists = await verifyExampleExists({ type: 'function', name: flagExample });
36
+ const exampleExists = await verifyExampleExists({
37
+ type: 'function',
38
+ name: flagExample,
39
+ logger: log,
40
+ });
37
41
  if (!exampleExists) {
38
42
  return { success: false, error: `Function example "${flagExample}" does not exist.` };
39
43
  }
@@ -48,6 +52,7 @@ export async function functionAddCore(options) {
48
52
  exampleType: 'function',
49
53
  exampleName: flagExample,
50
54
  dir: exampleDir,
55
+ logger: log,
51
56
  });
52
57
  if (!addedExample) {
53
58
  return { success: false, error: `Unable to download example "${flagExample}"` };
@@ -70,7 +75,7 @@ export async function functionAddCore(options) {
70
75
  }
71
76
  }
72
77
  else {
73
- log(warn('No Function config found in example.'));
78
+ log.warn(warn('No Function config found in example.'));
74
79
  }
75
80
  if (instructions) {
76
81
  log('');
@@ -168,7 +173,7 @@ export async function functionAddCore(options) {
168
173
  lang: fnLang,
169
174
  addHelpers,
170
175
  installCommand,
171
- });
176
+ }, log);
172
177
  log(`\nCreated function: ${filePath.replace(root, '')}`);
173
178
  if (!resourceAdded) {
174
179
  log(`\n${chalk.bold('Add the Resource to your Blueprint:')}`);
@@ -7,7 +7,7 @@ export async function functionDevCore(options) {
7
7
  ? { timeout }
8
8
  : undefined;
9
9
  try {
10
- await dev(host, Number(port), executionOptions);
10
+ await dev(host, Number(port), log, executionOptions);
11
11
  log(`Server is running on http://${host}:${port}\n`);
12
12
  return {
13
13
  success: true,
@@ -17,7 +17,7 @@ export async function functionDevCore(options) {
17
17
  }
18
18
  catch (error) {
19
19
  const errorMessage = error instanceof Error ? error.message : String(error);
20
- log(`Error starting server: ${errorMessage}`);
20
+ log.error(`Error starting server: ${errorMessage}`);
21
21
  return {
22
22
  success: false,
23
23
  error: errorMessage,
@@ -1,12 +1,11 @@
1
1
  import chalk from 'chalk';
2
- import ora from 'ora';
3
2
  import { update } from '../../../actions/functions/env/update.js';
4
3
  import { findFunctionInStack } from '../../../utils/find-function.js';
5
4
  export async function functionEnvAddCore(options) {
6
- const args = options.args;
7
- const spinner = ora(`Updating "${args.key}" environment variable in "${args.name}"`).start();
5
+ const { args, log } = options;
6
+ const spinner = log.ora(`Updating "${args.key}" environment variable in "${args.name}"`).start();
8
7
  const { externalId } = findFunctionInStack(options.deployedStack, args.name);
9
- const result = await update(externalId, args.key, args.value, options.auth);
8
+ const result = await update(externalId, args.key, args.value, options.auth, options.log);
10
9
  if (!result.ok) {
11
10
  spinner.fail(`${chalk.red('Failed')} to update ${args.key}`);
12
11
  return {
@@ -1,11 +1,10 @@
1
- import ora from 'ora';
2
1
  import { list } from '../../../actions/functions/env/list.js';
3
2
  import { findFunctionInStack } from '../../../utils/find-function.js';
4
3
  export async function functionEnvListCore(options) {
5
- const args = options.args;
6
- const spinner = ora(`Listing environment variables for "${args.name}"`).start();
4
+ const { args, log } = options;
5
+ const spinner = log.ora(`Listing environment variables for "${args.name}"`).start();
7
6
  const { externalId } = findFunctionInStack(options.deployedStack, args.name);
8
- const result = await list(externalId, options.auth);
7
+ const result = await list(externalId, options.auth, options.log);
9
8
  if (!result.ok) {
10
9
  spinner.stop();
11
10
  return { success: false, error: result.error || 'Unknown error' };
@@ -1,12 +1,11 @@
1
1
  import chalk from 'chalk';
2
- import ora from 'ora';
3
2
  import { remove } from '../../../actions/functions/env/remove.js';
4
3
  import { findFunctionInStack } from '../../../utils/find-function.js';
5
4
  export async function functionEnvRemoveCore(options) {
6
- const args = options.args;
7
- const spinner = ora(`Removing "${args.key}" environment variable in "${args.name}"`).start();
5
+ const { args, log } = options;
6
+ const spinner = log.ora(`Removing "${args.key}" environment variable in "${args.name}"`).start();
8
7
  const { externalId } = findFunctionInStack(options.deployedStack, args.name);
9
- const result = await remove(externalId, args.key, options.auth);
8
+ const result = await remove(externalId, args.key, options.auth, options.log);
10
9
  if (!result.ok) {
11
10
  spinner.fail(`${chalk.red('Failed')} to remove ${args.key}`);
12
11
  return { success: false, error: result.error || 'Unknown error' };
@@ -2,17 +2,11 @@ export type { FunctionAddOptions } from './add.js';
2
2
  export { functionAddCore } from './add.js';
3
3
  export type { FunctionDevOptions } from './dev.js';
4
4
  export { functionDevCore } from './dev.js';
5
- export type { FunctionEnvAddOptions,
6
- /** @deprecated Use `FunctionEnvAddOptions` instead. */
7
- FunctionEnvAddOptions as EnvAddOptions, } from './env/add.js';
5
+ export type { FunctionEnvAddOptions } from './env/add.js';
8
6
  export { functionEnvAddCore } from './env/add.js';
9
- export type { FunctionEnvListOptions,
10
- /** @deprecated Use `FunctionEnvListOptions` instead. */
11
- FunctionEnvListOptions as EnvListOptions, } from './env/list.js';
7
+ export type { FunctionEnvListOptions } from './env/list.js';
12
8
  export { functionEnvListCore } from './env/list.js';
13
- export type { FunctionEnvRemoveOptions,
14
- /** @deprecated Use `FunctionEnvRemoveOptions` instead. */
15
- FunctionEnvRemoveOptions as EnvRemoveOptions, } from './env/remove.js';
9
+ export type { FunctionEnvRemoveOptions } from './env/remove.js';
16
10
  export { functionEnvRemoveCore } from './env/remove.js';
17
11
  export type { FunctionLogsOptions } from './logs.js';
18
12
  export { functionLogsCore } from './logs.js';
@@ -1,6 +1,5 @@
1
1
  import { confirm } from '@inquirer/prompts';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
3
  import { deleteLogs as deleteLogsAction, logs as getLogsAction, streamLogs as streamLogsAction, } from '../../actions/functions/logs.js';
5
4
  import { formatTitle } from '../../utils/display/blueprints-formatting.js';
6
5
  import { niceId } from '../../utils/display/presenters.js';
@@ -25,7 +24,7 @@ export async function functionLogsCore(options) {
25
24
  return streamLogs({ name, externalId, auth, json, utc, log });
26
25
  return getLogs({ name, externalId, auth, limit, json, utc, log });
27
26
  }
28
- async function deleteLogs({ name, externalId, auth, force, }) {
27
+ async function deleteLogs({ name, externalId, auth, force, log, }) {
29
28
  if (!force) {
30
29
  const certain = await confirm({
31
30
  message: `Are you sure you want to delete ${chalk.bold('all')} logs for function ${chalk.yellow(name)}?`,
@@ -34,8 +33,8 @@ async function deleteLogs({ name, externalId, auth, force, }) {
34
33
  if (!certain)
35
34
  return { success: true };
36
35
  }
37
- const spinner = ora(`Deleting logs for function ${chalk.yellow(name)}`).start();
38
- const { ok, error } = await deleteLogsAction(externalId, auth);
36
+ const spinner = log.ora(`Deleting logs for function ${chalk.yellow(name)}`).start();
37
+ const { ok, error } = await deleteLogsAction(externalId, auth, log);
39
38
  if (!ok) {
40
39
  spinner.fail(`${chalk.red('Failed')} to delete logs`);
41
40
  return { success: false, error: error || 'Unknown error' };
@@ -44,7 +43,7 @@ async function deleteLogs({ name, externalId, auth, force, }) {
44
43
  return { success: true };
45
44
  }
46
45
  async function streamLogs({ name, externalId, auth, log, }) {
47
- const spinner = ora(`Setting up streaming logs session for function ${niceId(name)}`).start();
46
+ const spinner = log.ora(`Setting up streaming logs session for function ${niceId(name)}`).start();
48
47
  try {
49
48
  spinner.stop();
50
49
  log(`Streaming log session for function ${niceId(name)}`);
@@ -59,7 +58,7 @@ async function streamLogs({ name, externalId, auth, log, }) {
59
58
  const { time, level, message } = logEntry;
60
59
  log(formatLog(time, level, message, true));
61
60
  };
62
- streamLogsAction(externalId, auth, renderLog, onOpen, (error) => log(`${chalk.red('Error:')} ${error}`));
61
+ streamLogsAction(externalId, auth, renderLog, onOpen, (error) => log.error(`${chalk.red('Error:')} ${error}`), log);
63
62
  // Return a special key for streaming mode
64
63
  return {
65
64
  success: true,
@@ -69,13 +68,13 @@ async function streamLogs({ name, externalId, auth, log, }) {
69
68
  catch (err) {
70
69
  spinner.fail('Failed to retrieve logs');
71
70
  const errorMessage = err instanceof Error ? err.message : String(err);
72
- log(`Error: ${errorMessage}`);
71
+ log.error(`Error: ${errorMessage}`);
73
72
  return { success: false, error: errorMessage };
74
73
  }
75
74
  }
76
75
  async function getLogs({ name, externalId, auth, limit, json, utc, log, }) {
77
- const spinner = ora(`Finding logs for function "${name}"`).start();
78
- const { ok, error, logs, total } = await getLogsAction(externalId, { limit }, auth);
76
+ const spinner = log.ora(`Finding logs for function "${name}"`).start();
77
+ const { ok, error, logs, total } = await getLogsAction(externalId, { limit }, auth, log);
79
78
  if (!ok) {
80
79
  spinner.fail(`${chalk.red('Failed')} to retrieve logs`);
81
80
  return { success: false, error: error || 'Unknown error' };
@@ -1,7 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
- import ora from 'ora';
5
4
  import { testAction } from '../../actions/functions/test.js';
6
5
  import config from '../../config.js';
7
6
  import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET } from '../../constants.js';
@@ -79,14 +78,14 @@ export async function functionTestCore(options) {
79
78
  apiVersion: api,
80
79
  apiHost: config.apiUrl,
81
80
  token: config.token || undefined,
82
- });
81
+ }, log);
83
82
  after = await fetchDocument(documentIdAfter, {
84
83
  projectId,
85
84
  dataset,
86
85
  apiVersion: api,
87
86
  apiHost: config.apiUrl,
88
87
  token: config.token || undefined,
89
- });
88
+ }, log);
90
89
  }
91
90
  else if (documentIdBefore && documentIdAfter) {
92
91
  before = await fetchAsset(documentIdBefore, {
@@ -94,13 +93,13 @@ export async function functionTestCore(options) {
94
93
  apiVersion: api,
95
94
  apiHost: config.apiUrl,
96
95
  token: config.token || undefined,
97
- });
96
+ }, log);
98
97
  after = await fetchAsset(documentIdAfter, {
99
98
  mediaLibraryId,
100
99
  apiVersion: api,
101
100
  apiHost: config.apiUrl,
102
101
  token: config.token || undefined,
103
- });
102
+ }, log);
104
103
  }
105
104
  let payload;
106
105
  if (after) {
@@ -114,7 +113,7 @@ export async function functionTestCore(options) {
114
113
  apiVersion: api,
115
114
  apiHost: config.apiUrl,
116
115
  token: config.token || undefined,
117
- });
116
+ }, log);
118
117
  }
119
118
  else if (documentId) {
120
119
  payload = await fetchAsset(documentId, {
@@ -122,7 +121,7 @@ export async function functionTestCore(options) {
122
121
  apiVersion: api,
123
122
  apiHost: config.apiUrl,
124
123
  token: config.token || undefined,
125
- });
124
+ }, log);
126
125
  }
127
126
  else {
128
127
  payload = buildPayload({ data, file });
@@ -138,7 +137,7 @@ export async function functionTestCore(options) {
138
137
  : {
139
138
  event: 'schedule',
140
139
  };
141
- const spinner = ora('Executing function...').start();
140
+ const spinner = log.ora('Executing function...').start();
142
141
  const { json, logs, error } = await testAction(resource, invokeOptions, contextOptions, {
143
142
  timeout: timeout ? timeout : resource.timeout,
144
143
  });
@@ -1,4 +1,5 @@
1
1
  import { type ReadBlueprintResult } from '../actions/blueprints/blueprint.js';
2
+ import type { Logger } from '../utils/logger.js';
2
3
  import type { AuthParams, Result, ScopeType, Stack } from '../utils/types.js';
3
4
  export * as blueprintsCores from './blueprints/index.js';
4
5
  export * as functionsCores from './functions/index.js';
@@ -6,7 +7,7 @@ export interface CoreConfig {
6
7
  /** The CLI binary name. */
7
8
  bin: string;
8
9
  /** The log output function. */
9
- log: (message: string) => void;
10
+ log: ReturnType<typeof Logger>;
10
11
  }
11
12
  export interface BlueprintConfig extends CoreConfig {
12
13
  token: string;
@@ -35,17 +36,13 @@ export type CoreResult = {
35
36
  streaming?: Promise<void>;
36
37
  error?: never;
37
38
  });
38
- type InitBlueprintConfigParams = {
39
- bin: string;
40
- log: (msg: string) => void;
39
+ type InitBlueprintConfigParams = CoreConfig & ({
41
40
  validateToken: true;
42
41
  token: string;
43
42
  } | {
44
- bin: string;
45
- log: (msg: string) => void;
46
43
  validateToken?: false;
47
44
  token?: string;
48
- };
45
+ });
49
46
  export declare function initBlueprintConfig({ bin, log, token, validateToken, }: InitBlueprintConfigParams): Promise<Result<BlueprintConfig>>;
50
47
  export declare function initDeployedBlueprintConfig(config: Partial<BlueprintConfig> & Pick<BlueprintConfig, 'bin' | 'log' | 'token'> & {
51
48
  validateToken?: boolean;
@@ -8,7 +8,7 @@ export * as functionsCores from './functions/index.js';
8
8
  export async function initBlueprintConfig({ bin, log, token, validateToken = true, }) {
9
9
  let checkedToken = token;
10
10
  if (!token || (token && validateToken)) {
11
- const tokenCheck = await validTokenOrErrorMessage(token);
11
+ const tokenCheck = await validTokenOrErrorMessage(log, token);
12
12
  if (!tokenCheck.ok) {
13
13
  return { ok: false, error: tokenCheck.error.message };
14
14
  }
@@ -17,7 +17,7 @@ export async function initBlueprintConfig({ bin, log, token, validateToken = tru
17
17
  if (!checkedToken) {
18
18
  return { ok: false, error: 'A valid token is required but was not provided.' };
19
19
  }
20
- const blueprint = await readLocalBlueprint();
20
+ const blueprint = await readLocalBlueprint(log);
21
21
  if (blueprint.errors.length > 0) {
22
22
  log(presentBlueprintParserErrors(blueprint.errors));
23
23
  return { ok: false, error: 'Blueprint file contains errors.' };
@@ -49,7 +49,7 @@ export async function initDeployedBlueprintConfig(config) {
49
49
  return { ok: false, error: 'Missing Stack deployment configuration for Blueprint' };
50
50
  }
51
51
  const auth = { token: config.token, scopeType, scopeId };
52
- const stackResponse = await getStack({ stackId, auth });
52
+ const stackResponse = await getStack({ stackId, auth, logger: config.log });
53
53
  if (!stackResponse.ok) {
54
54
  config.log(`Could not retrieve Stack deployment info for ${niceId(stackId)}.`);
55
55
  config.log(`Run \`${config.bin} blueprints doctor\` for diagnostics.`);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,18 @@
1
- import { run } from '@oclif/core';
2
- export { run };
1
+ export { run } from '@oclif/core';
2
+ export { default as BlueprintsAddCommand } from './commands/blueprints/add.js';
3
+ export { default as BlueprintsConfigCommand } from './commands/blueprints/config.js';
4
+ export { default as BlueprintsDeployCommand } from './commands/blueprints/deploy.js';
5
+ export { default as BlueprintsDestroyCommand } from './commands/blueprints/destroy.js';
6
+ export { default as BlueprintsDoctorCommand } from './commands/blueprints/doctor.js';
7
+ export { default as BlueprintsInfoCommand } from './commands/blueprints/info.js';
8
+ export { default as BlueprintsInitCommand } from './commands/blueprints/init.js';
9
+ export { default as BlueprintsLogsCommand } from './commands/blueprints/logs.js';
10
+ export { default as BlueprintsPlanCommand } from './commands/blueprints/plan.js';
11
+ export { default as BlueprintsStacksCommand } from './commands/blueprints/stacks.js';
12
+ export { default as FunctionsAddCommand } from './commands/functions/add.js';
13
+ export { default as FunctionsDevCommand } from './commands/functions/dev.js';
14
+ export { default as FunctionsEnvAddCommand } from './commands/functions/env/add.js';
15
+ export { default as FunctionsEnvListCommand } from './commands/functions/env/list.js';
16
+ export { default as FunctionsEnvRemoveCommand } from './commands/functions/env/remove.js';
17
+ export { default as FunctionsLogsCommand } from './commands/functions/logs.js';
18
+ export { default as FunctionsTestCommand } from './commands/functions/test.js';
package/dist/index.js CHANGED
@@ -1,2 +1,20 @@
1
- import { run } from '@oclif/core';
2
- export { run };
1
+ export { run } from '@oclif/core';
2
+ // Blueprints command classes
3
+ export { default as BlueprintsAddCommand } from './commands/blueprints/add.js';
4
+ export { default as BlueprintsConfigCommand } from './commands/blueprints/config.js';
5
+ export { default as BlueprintsDeployCommand } from './commands/blueprints/deploy.js';
6
+ export { default as BlueprintsDestroyCommand } from './commands/blueprints/destroy.js';
7
+ export { default as BlueprintsDoctorCommand } from './commands/blueprints/doctor.js';
8
+ export { default as BlueprintsInfoCommand } from './commands/blueprints/info.js';
9
+ export { default as BlueprintsInitCommand } from './commands/blueprints/init.js';
10
+ export { default as BlueprintsLogsCommand } from './commands/blueprints/logs.js';
11
+ export { default as BlueprintsPlanCommand } from './commands/blueprints/plan.js';
12
+ export { default as BlueprintsStacksCommand } from './commands/blueprints/stacks.js';
13
+ // Functions command classes
14
+ export { default as FunctionsAddCommand } from './commands/functions/add.js';
15
+ export { default as FunctionsDevCommand } from './commands/functions/dev.js';
16
+ export { default as FunctionsEnvAddCommand } from './commands/functions/env/add.js';
17
+ export { default as FunctionsEnvListCommand } from './commands/functions/env/list.js';
18
+ export { default as FunctionsEnvRemoveCommand } from './commands/functions/env/remove.js';
19
+ export { default as FunctionsLogsCommand } from './commands/functions/logs.js';
20
+ export { default as FunctionsTestCommand } from './commands/functions/test.js';
@@ -1,5 +1,6 @@
1
+ import type { Logger } from '../utils/logger.js';
1
2
  import { type InvokeExecutionOptions } from '../utils/types.js';
2
- declare const app: (host: string, port: number, executionOptions?: Partial<InvokeExecutionOptions>) => void;
3
+ declare const app: (host: string, port: number, logger: ReturnType<typeof Logger>, executionOptions?: Partial<InvokeExecutionOptions>) => void;
3
4
  declare function parseDocumentUrl(url: string): {
4
5
  projectId: string;
5
6
  dataset: string;
@@ -7,13 +7,13 @@ import config from '../config.js';
7
7
  import { isRecord } from '../utils/is-record.js';
8
8
  import { isEventType, isGroqContextOptions, } from '../utils/types.js';
9
9
  import { handleInvokeRequest } from './handlers/invoke.js';
10
- const app = (host, port, executionOptions) => {
10
+ const app = (host, port, logger, executionOptions) => {
11
11
  const requestListener = async (req, res) => {
12
12
  res.setHeader('Content-Type', 'application/json');
13
13
  switch (true) {
14
14
  case req.url === '/blueprint': {
15
15
  try {
16
- const { parsedBlueprint, projectId, organizationId } = await readLocalBlueprint();
16
+ const { parsedBlueprint, projectId, organizationId } = await readLocalBlueprint(logger);
17
17
  res.setHeader('Content-Type', 'application/json');
18
18
  res.writeHead(200);
19
19
  res.end(JSON.stringify({ parsedBlueprint, projectId, organizationId })); // Use blueprint directly
@@ -42,7 +42,7 @@ const app = (host, port, executionOptions) => {
42
42
  delete context.clientOptions.token;
43
43
  }
44
44
  }
45
- const result = await handleInvokeRequest(functionName, event, metadata, context, executionOptions);
45
+ const result = await handleInvokeRequest(functionName, event, metadata, context, logger, executionOptions);
46
46
  // Add Server-Timing header
47
47
  const timingHeaders = [];
48
48
  for (const [key, value] of Object.entries(result.timings)) {
@@ -230,7 +230,7 @@ const app = (host, port, executionOptions) => {
230
230
  const wss = new WebSocketServer({ port: 8974 });
231
231
  wss.on('connection', async function connection(ws) {
232
232
  ws.on('error', console.error);
233
- const { fileInfo } = await readLocalBlueprint();
233
+ const { fileInfo } = await readLocalBlueprint(logger);
234
234
  watchFile(fileInfo.blueprintFilePath, { interval: 2007 }, async () => {
235
235
  ws.send('reload-blueprint');
236
236
  });
@@ -1,4 +1,5 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { InvocationResponse, InvokeContextOptions, InvokeExecutionOptions, InvokePayloadMetadata } from '../../utils/types.js';
2
- export declare function handleInvokeRequest(functionName: string, event: Record<string, unknown>, metadata: InvokePayloadMetadata, context: InvokeContextOptions, executionOptions?: Partial<InvokeExecutionOptions>): Promise<InvocationResponse & {
3
+ export declare function handleInvokeRequest(functionName: string, event: Record<string, unknown>, metadata: InvokePayloadMetadata, context: InvokeContextOptions, logger: ReturnType<typeof Logger>, executionOptions?: Partial<InvokeExecutionOptions>): Promise<InvocationResponse & {
3
4
  timings: Record<string, number>;
4
5
  }>;
@@ -1,9 +1,9 @@
1
1
  import { readLocalBlueprint } from '../../actions/blueprints/blueprint.js';
2
2
  import { findFunctionInBlueprint } from '../../utils/find-function.js';
3
3
  import invoke from '../../utils/invoke-local.js';
4
- export async function handleInvokeRequest(functionName, event, metadata, context, executionOptions) {
4
+ export async function handleInvokeRequest(functionName, event, metadata, context, logger, executionOptions) {
5
5
  const start = performance.now();
6
- const { parsedBlueprint } = await readLocalBlueprint();
6
+ const { parsedBlueprint } = await readLocalBlueprint(logger);
7
7
  const resource = findFunctionInBlueprint(parsedBlueprint, functionName);
8
8
  const readBlueprintTime = performance.now() - start;
9
9
  const payload = {
@@ -13,6 +13,8 @@ import {ApiBaseElement} from './api-base.js'
13
13
  import {sanityCodeMirrorTheme} from './codemirror-theme.js'
14
14
  import {getSharedStyleSheets} from './shared-styles.js'
15
15
 
16
+ const {lineWrapping} = EditorView
17
+
16
18
  const template = document.createElement('template')
17
19
  template.innerHTML = `
18
20
  <style>
@@ -117,6 +119,7 @@ class ResponsePanel extends ApiBaseElement {
117
119
  doc: '\n\n\n\n',
118
120
  extensions: [basicSetup, json(), sanityCodeMirrorTheme, EditorState.readOnly.of(true)],
119
121
  parent: this.response,
122
+ lineWrapping,
120
123
  })
121
124
  }
122
125
 
@@ -6,6 +6,8 @@ import {ApiBaseElement} from './api-base.js'
6
6
  import {sanityCodeMirrorTheme} from './codemirror-theme.js'
7
7
  import {getSharedStyleSheets} from './shared-styles.js'
8
8
 
9
+ const {lineWrapping} = EditorView
10
+
9
11
  const template = document.createElement('template')
10
12
  template.innerHTML = `<div class="border-left y-scroll min-h-0">
11
13
  <div>
@@ -56,7 +58,13 @@ class RulePanel extends ApiBaseElement {
56
58
 
57
59
  this.api.store.rule = new EditorView({
58
60
  doc: '\n\n\n\n',
59
- extensions: [basicSetup, json(), sanityCodeMirrorTheme, EditorState.readOnly.of(true)],
61
+ extensions: [
62
+ basicSetup,
63
+ json(),
64
+ sanityCodeMirrorTheme,
65
+ EditorState.readOnly.of(true),
66
+ lineWrapping,
67
+ ],
60
68
  parent: this.rule,
61
69
  })
62
70
  }
@@ -1,3 +1,4 @@
1
+ import type { Logger } from '../logger.js';
1
2
  export declare function promptForBlueprintType(): Promise<string>;
2
3
  /**
3
4
  * Prompt the user for a Project after selecting an Organization.
@@ -5,10 +6,11 @@ export declare function promptForBlueprintType(): Promise<string>;
5
6
  * @returns The selected project, with the projectId and displayName
6
7
  * @throws {Error} If the user does not have any projects or if the API call fails
7
8
  */
8
- export declare function promptForProject({ token, knownOrganizationId, knownProjectId, }: {
9
+ export declare function promptForProject({ token, knownOrganizationId, knownProjectId, logger, }: {
9
10
  token: string;
10
11
  knownOrganizationId?: string;
11
12
  knownProjectId?: string;
13
+ logger: ReturnType<typeof Logger>;
12
14
  }): Promise<{
13
15
  projectId: string;
14
16
  displayName: string;
@@ -21,9 +23,10 @@ export declare function promptForProject({ token, knownOrganizationId, knownProj
21
23
  * @returns The selected Stack ID
22
24
  * @throws {Error} If the user does not have any Stacks or if the API call fails
23
25
  */
24
- export declare function promptForStack({ projectId, token, }: {
26
+ export declare function promptForStack({ projectId, token, logger, }: {
25
27
  projectId: string;
26
28
  token: string;
29
+ logger: ReturnType<typeof Logger>;
27
30
  }): Promise<{
28
31
  stackId: string;
29
32
  name: string;
@@ -20,8 +20,8 @@ export async function promptForBlueprintType() {
20
20
  * @returns The selected project, with the projectId and displayName
21
21
  * @throws {Error} If the user does not have any projects or if the API call fails
22
22
  */
23
- export async function promptForProject({ token, knownOrganizationId, knownProjectId, }) {
24
- const { ok, error, organizations } = await groupProjectsByOrganization({ token });
23
+ export async function promptForProject({ token, knownOrganizationId, knownProjectId, logger, }) {
24
+ const { ok, error, organizations } = await groupProjectsByOrganization({ token, logger });
25
25
  if (!ok) {
26
26
  throw new Error(error ?? 'Unknown error listing projects');
27
27
  }
@@ -78,8 +78,8 @@ export async function promptForProject({ token, knownOrganizationId, knownProjec
78
78
  * @returns The selected Stack ID
79
79
  * @throws {Error} If the user does not have any Stacks or if the API call fails
80
80
  */
81
- export async function promptForStack({ projectId, token, }) {
82
- const { ok: stacksOk, error: stacksErr, stacks, } = await listStacks({ token, scopeType: 'project', scopeId: projectId });
81
+ export async function promptForStack({ projectId, token, logger, }) {
82
+ const { ok: stacksOk, error: stacksErr, stacks, } = await listStacks({ token, scopeType: 'project', scopeId: projectId }, logger);
83
83
  if (!stacksOk) {
84
84
  throw new Error(stacksErr || 'Failed to list Stacks');
85
85
  }
@@ -110,6 +110,7 @@ export async function promptForStack({ projectId, token, }) {
110
110
  scopeType: 'project',
111
111
  scopeId: projectId,
112
112
  name: stackName,
113
+ logger,
113
114
  });
114
115
  return { stackId: stack.id, name: stackName };
115
116
  }
@@ -1,4 +1,5 @@
1
1
  import { type ClientConfig } from '@sanity/client';
2
+ import type { Logger } from '../logger.js';
2
3
  import type { FetchConfig } from '../types.js';
3
- export declare function fetchDocument(documentId: string, { projectId, dataset, useCdn, apiVersion, apiHost, token }: ClientConfig): Promise<Record<string, unknown>>;
4
- export declare function fetchAsset(documentId: string, { mediaLibraryId, apiVersion, apiHost, token }: FetchConfig): Promise<Record<string, unknown>>;
4
+ export declare function fetchDocument(documentId: string, { projectId, dataset, useCdn, apiVersion, apiHost, token }: ClientConfig, logger: ReturnType<typeof Logger>): Promise<Record<string, unknown>>;
5
+ export declare function fetchAsset(documentId: string, { mediaLibraryId, apiVersion, apiHost, token }: FetchConfig, logger: ReturnType<typeof Logger>): Promise<Record<string, unknown>>;