@sanity/runtime-cli 12.3.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +190 -76
  2. package/dist/actions/blueprints/assets.d.ts +3 -1
  3. package/dist/actions/blueprints/assets.js +15 -5
  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 +47 -7
  33. package/dist/baseCommands.js +90 -12
  34. package/dist/commands/blueprints/add.d.ts +3 -2
  35. package/dist/commands/blueprints/add.js +14 -10
  36. package/dist/commands/blueprints/config.d.ts +3 -2
  37. package/dist/commands/blueprints/config.js +12 -6
  38. package/dist/commands/blueprints/deploy.d.ts +3 -2
  39. package/dist/commands/blueprints/deploy.js +10 -4
  40. package/dist/commands/blueprints/destroy.d.ts +3 -2
  41. package/dist/commands/blueprints/destroy.js +10 -4
  42. package/dist/commands/blueprints/doctor.d.ts +6 -4
  43. package/dist/commands/blueprints/doctor.js +17 -14
  44. package/dist/commands/blueprints/info.d.ts +3 -2
  45. package/dist/commands/blueprints/info.js +11 -5
  46. package/dist/commands/blueprints/init.d.ts +3 -2
  47. package/dist/commands/blueprints/init.js +26 -20
  48. package/dist/commands/blueprints/logs.d.ts +3 -2
  49. package/dist/commands/blueprints/logs.js +10 -4
  50. package/dist/commands/blueprints/plan.d.ts +3 -2
  51. package/dist/commands/blueprints/plan.js +8 -4
  52. package/dist/commands/blueprints/stacks.d.ts +3 -2
  53. package/dist/commands/blueprints/stacks.js +10 -6
  54. package/dist/commands/functions/add.d.ts +3 -2
  55. package/dist/commands/functions/add.js +10 -4
  56. package/dist/commands/functions/dev.d.ts +3 -2
  57. package/dist/commands/functions/dev.js +16 -5
  58. package/dist/commands/functions/env/add.d.ts +4 -3
  59. package/dist/commands/functions/env/add.js +8 -4
  60. package/dist/commands/functions/env/list.d.ts +4 -3
  61. package/dist/commands/functions/env/list.js +8 -4
  62. package/dist/commands/functions/env/remove.d.ts +4 -3
  63. package/dist/commands/functions/env/remove.js +8 -4
  64. package/dist/commands/functions/logs.d.ts +5 -4
  65. package/dist/commands/functions/logs.js +11 -5
  66. package/dist/commands/functions/test.d.ts +5 -4
  67. package/dist/commands/functions/test.js +13 -6
  68. package/dist/cores/blueprints/config.d.ts +2 -5
  69. package/dist/cores/blueprints/config.js +9 -9
  70. package/dist/cores/blueprints/deploy.js +14 -17
  71. package/dist/cores/blueprints/destroy.d.ts +2 -5
  72. package/dist/cores/blueprints/destroy.js +6 -6
  73. package/dist/cores/blueprints/doctor.js +32 -29
  74. package/dist/cores/blueprints/info.js +5 -5
  75. package/dist/cores/blueprints/init.d.ts +3 -3
  76. package/dist/cores/blueprints/init.js +15 -8
  77. package/dist/cores/blueprints/logs.js +6 -7
  78. package/dist/cores/blueprints/plan.js +1 -0
  79. package/dist/cores/blueprints/stacks.d.ts +2 -5
  80. package/dist/cores/blueprints/stacks.js +4 -4
  81. package/dist/cores/functions/add.js +8 -3
  82. package/dist/cores/functions/dev.js +2 -2
  83. package/dist/cores/functions/env/add.js +3 -4
  84. package/dist/cores/functions/env/list.js +3 -4
  85. package/dist/cores/functions/env/remove.js +3 -4
  86. package/dist/cores/functions/index.d.ts +3 -9
  87. package/dist/cores/functions/logs.d.ts +3 -1
  88. package/dist/cores/functions/logs.js +19 -11
  89. package/dist/cores/functions/test.d.ts +3 -1
  90. package/dist/cores/functions/test.js +18 -10
  91. package/dist/cores/index.d.ts +4 -7
  92. package/dist/cores/index.js +3 -3
  93. package/dist/index.d.ts +1 -2
  94. package/dist/index.js +1 -2
  95. package/dist/server/app.d.ts +2 -1
  96. package/dist/server/app.js +4 -4
  97. package/dist/server/handlers/invoke.d.ts +2 -1
  98. package/dist/server/handlers/invoke.js +2 -2
  99. package/dist/server/static/components/app.css +0 -116
  100. package/dist/server/static/components/clear-button.js +1 -1
  101. package/dist/server/static/components/console-panel.js +27 -6
  102. package/dist/server/static/components/fetch-button.js +1 -1
  103. package/dist/server/static/components/filter-api-version.js +39 -3
  104. package/dist/server/static/components/filter-document-id.js +39 -3
  105. package/dist/server/static/components/filter-with-token.js +27 -4
  106. package/dist/server/static/components/filters.js +127 -62
  107. package/dist/server/static/components/function-list.js +33 -13
  108. package/dist/server/static/components/network-spinner.js +6 -4
  109. package/dist/server/static/components/payload-panel.js +46 -24
  110. package/dist/server/static/components/response-panel.js +33 -6
  111. package/dist/server/static/components/rule-panel.js +13 -4
  112. package/dist/server/static/components/run-panel.js +14 -7
  113. package/dist/server/static/components/select-dropdown.js +34 -5
  114. package/dist/server/static/components/shared-styles.js +31 -0
  115. package/dist/server/static/components/toggle-switch.js +11 -2
  116. package/dist/utils/display/blueprints-formatting.d.ts +2 -2
  117. package/dist/utils/display/blueprints-formatting.js +31 -26
  118. package/dist/utils/display/prompt.d.ts +5 -2
  119. package/dist/utils/display/prompt.js +5 -4
  120. package/dist/utils/find-function.d.ts +4 -0
  121. package/dist/utils/find-function.js +6 -0
  122. package/dist/utils/functions/fetch-document.d.ts +3 -2
  123. package/dist/utils/functions/fetch-document.js +7 -6
  124. package/dist/utils/index.d.ts +2 -0
  125. package/dist/utils/index.js +2 -0
  126. package/dist/utils/logger.d.ts +13 -0
  127. package/dist/utils/logger.js +61 -0
  128. package/dist/utils/other/github.d.ts +2 -1
  129. package/dist/utils/other/github.js +4 -2
  130. package/dist/utils/other/npmjs.d.ts +2 -1
  131. package/dist/utils/other/npmjs.js +4 -2
  132. package/dist/utils/traced-fetch.d.ts +35 -0
  133. package/dist/utils/traced-fetch.js +238 -0
  134. package/dist/utils/validated-token.d.ts +3 -2
  135. package/dist/utils/validated-token.js +6 -4
  136. package/oclif.manifest.json +455 -75
  137. package/package.json +14 -6
@@ -1,6 +1,5 @@
1
1
  import { setTimeout } from 'node:timers/promises';
2
2
  import chalk from 'chalk';
3
- import ora from 'ora';
4
3
  import { stashAsset } from '../../actions/blueprints/assets.js';
5
4
  import { setupLogStreaming } from '../../actions/blueprints/logs-streaming.js';
6
5
  import { getStack, updateStack } from '../../actions/blueprints/stacks.js';
@@ -8,7 +7,7 @@ import { niceId } from '../../utils/display/presenters.js';
8
7
  import { isLocalFunctionCollection, isLocalFunctionResource } from '../../utils/types.js';
9
8
  export async function blueprintDeployCore(options) {
10
9
  const { bin = 'sanity', log, auth, stackId, scopeType, scopeId, deployedStack, blueprint, flags, } = options;
11
- const { verbose } = flags;
10
+ const { verbose: _verbose } = flags;
12
11
  const noWait = flags['no-wait'] || false;
13
12
  log(`Deploying "${deployedStack.name}" ${niceId(deployedStack.id)}...`);
14
13
  try {
@@ -21,8 +20,8 @@ export async function blueprintDeployCore(options) {
21
20
  if (allFunctionResources.length > 0) {
22
21
  log('Processing function assets...');
23
22
  for (const resource of allFunctionResources) {
24
- const fnSpinner = ora({ text: `Processing ${resource.name}...`, prefixText: ' ' }).start();
25
- const result = await stashAsset({ resource, auth });
23
+ const fnSpinner = log.ora({ text: `Processing ${resource.name}...`, prefixText: ' ' }).start();
24
+ const result = await stashAsset({ resource, auth, logger: log });
26
25
  if (result.success && result.assetId) {
27
26
  resource.src = result.assetId;
28
27
  if (isLocalFunctionCollection(resource)) {
@@ -45,30 +44,27 @@ export async function blueprintDeployCore(options) {
45
44
  fnSpinner.succeed(`${resource.name} ${niceId(result.assetId)}`);
46
45
  log(` Source: ${resource.src}`);
47
46
  }
48
- if (verbose) {
49
- if (result.hash) {
50
- if (result.hash.length > 24) {
51
- log(` Hash: ${result.hash.slice(0, 8)}...${result.hash.slice(-12)}`);
52
- }
53
- else {
54
- log(` Hash: ${result.hash}`);
55
- }
47
+ if (result.hash) {
48
+ if (result.hash.length > 24) {
49
+ log.verbose(` Hash: ${result.hash.slice(0, 8)}...${result.hash.slice(-12)}`);
50
+ }
51
+ else {
52
+ log.verbose(` Hash: ${result.hash}`);
56
53
  }
57
- if (result.exists)
58
- log(' Asset unchanged');
59
54
  }
55
+ if (result.exists)
56
+ log.verbose(' Asset unchanged');
60
57
  }
61
58
  else {
62
59
  const errorMsg = isLocalFunctionCollection(resource)
63
60
  ? `Failed uploading function collection ${resource.name} (${resource.functions?.length || 0} functions), deploy has stopped`
64
61
  : `Failed uploading ${resource.name} asset, deploy has stopped`;
65
62
  fnSpinner.fail(errorMsg);
66
- log(` Error: ${result.error}`);
67
63
  return { success: false, error: result.error || 'Failed to process function resource' };
68
64
  }
69
65
  }
70
66
  }
71
- const spinner = ora('Deploying...').start();
67
+ const spinner = log.ora('Deploying...').start();
72
68
  const isoNow = new Date().toISOString();
73
69
  const { ok: deployOk, stack, error: deployError, } = await updateStack({
74
70
  stackId,
@@ -79,6 +75,7 @@ export async function blueprintDeployCore(options) {
79
75
  document: { resources: validResources },
80
76
  },
81
77
  auth,
78
+ logger: log,
82
79
  });
83
80
  if (!deployOk) {
84
81
  spinner.fail(`${chalk.red('Failed')} to update Stack deployment`);
@@ -100,7 +97,7 @@ export async function blueprintDeployCore(options) {
100
97
  log,
101
98
  });
102
99
  while (true) {
103
- const { ok, stack: currentStack } = await getStack({ stackId: stack.id, auth });
100
+ const { ok, stack: currentStack } = await getStack({ stackId: stack.id, auth, logger: log });
104
101
  if (!ok) {
105
102
  if (logStreamCleanup)
106
103
  logStreamCleanup();
@@ -1,8 +1,5 @@
1
- import type { ReadBlueprintResult } from '../../actions/blueprints/blueprint.js';
2
- import type { CoreConfig, CoreResult } from '../index.js';
3
- export interface BlueprintDestroyOptions extends CoreConfig {
4
- token: string;
5
- blueprint: ReadBlueprintResult;
1
+ import type { BlueprintConfig, CoreResult } from '../index.js';
2
+ export interface BlueprintDestroyOptions extends BlueprintConfig {
6
3
  flags: {
7
4
  force?: boolean;
8
5
  'project-id'?: string;
@@ -1,7 +1,6 @@
1
1
  import { setTimeout } from 'node:timers/promises';
2
2
  import { confirm } from '@inquirer/prompts';
3
3
  import chalk from 'chalk';
4
- import ora from 'ora';
5
4
  import { setupLogStreaming } from '../../actions/blueprints/logs-streaming.js';
6
5
  import { destroyStack, getStack } from '../../actions/blueprints/stacks.js';
7
6
  import { niceId } from '../../utils/display/presenters.js';
@@ -26,6 +25,7 @@ export async function blueprintDestroyCore(options) {
26
25
  const { ok, error, stack } = await destroyStack({
27
26
  stackId: flagStackId,
28
27
  auth: { token, scopeType, scopeId },
28
+ logger: log,
29
29
  });
30
30
  if (!ok)
31
31
  return { success: false, error: error || 'Failed to destroy Stack deployment' };
@@ -39,20 +39,20 @@ export async function blueprintDestroyCore(options) {
39
39
  let stack;
40
40
  try {
41
41
  if (flagStackId) {
42
- const flagStack = await getStack({ stackId: flagStackId, auth });
42
+ const flagStack = await getStack({ stackId: flagStackId, auth, logger: log });
43
43
  if (!flagStack.ok)
44
44
  return { success: false, error: flagStack.error || 'Failed to get Stack' };
45
45
  stack = flagStack.stack;
46
46
  }
47
47
  else if (stackId) {
48
- const blueprintStack = await getStack({ stackId, auth });
48
+ const blueprintStack = await getStack({ stackId, auth, logger: log });
49
49
  if (!blueprintStack.ok)
50
50
  return { success: false, error: blueprintStack.error || 'Failed to get Stack' };
51
51
  stack = blueprintStack.stack;
52
52
  }
53
53
  if (!stack)
54
54
  return { success: false, error: 'Stack deployment not found' };
55
- const destroySpinner = ora({
55
+ const destroySpinner = log.ora({
56
56
  text: `Destroying Stack deployment "${chalk.bold(stack.name)}" ${niceId(stack.id)}...`,
57
57
  color: 'red',
58
58
  });
@@ -79,7 +79,7 @@ export async function blueprintDestroyCore(options) {
79
79
  destroySpinner.start();
80
80
  }
81
81
  const isoNow = new Date().toISOString();
82
- const { ok, error } = await destroyStack({ stackId: stack.id, auth });
82
+ const { ok, error } = await destroyStack({ stackId: stack.id, auth, logger: log });
83
83
  if (!ok) {
84
84
  destroySpinner.fail('Failed to destroy Stack deployment');
85
85
  return { success: false, error: error || 'Failed to destroy Stack deployment' };
@@ -99,7 +99,7 @@ export async function blueprintDestroyCore(options) {
99
99
  log,
100
100
  });
101
101
  while (true) {
102
- const { ok, stack: currentStack } = await getStack({ stackId: stack.id, auth });
102
+ const { ok, stack: currentStack } = await getStack({ stackId: stack.id, auth, logger: log });
103
103
  const operation = currentStack?.recentOperation;
104
104
  if (!ok || !operation || operation?.status === 'COMPLETED') {
105
105
  // Operation is also marked destroyed when stack is deleted;
@@ -4,6 +4,7 @@ import { findBlueprintFile, readLocalBlueprint, } from '../../actions/blueprints
4
4
  import { getStack } from '../../actions/blueprints/stacks.js';
5
5
  import config from '../../config.js';
6
6
  import { capitalize, check, filePathRelativeToCwd, indent, niceId, severe, unsure, } from '../../utils/display/presenters.js';
7
+ import { createTracedFetch } from '../../utils/traced-fetch.js';
7
8
  import { validTokenOrErrorMessage } from '../../utils/validated-token.js';
8
9
  import { blueprintConfigCore } from './config.js';
9
10
  const diagLookup = {
@@ -20,24 +21,23 @@ const diagLookup = {
20
21
  export async function blueprintDoctorCore(options) {
21
22
  const { bin, log, token, flags: { verbose: v, path: p, fix }, } = options;
22
23
  const yikes = (s) => {
23
- log(chalk.bgRedBright.whiteBright.bold(` ${s} `));
24
+ log.error(chalk.bgRedBright.whiteBright.bold(` ${s} `));
24
25
  };
25
26
  const here = cwd();
26
27
  const path = p || here;
27
28
  let tokenOrError;
28
- if (v)
29
- log(`Checking ${filePathRelativeToCwd(path)}`);
29
+ log.verbose(`Checking ${filePathRelativeToCwd(path)}`);
30
30
  // 3 states: null == unknown, true == good, false == bad
31
31
  const diagnostics = {};
32
32
  for (const key in diagLookup) {
33
33
  diagnostics[key] = null;
34
34
  }
35
35
  // ONLINE
36
+ const fetchFn = createTracedFetch(log);
36
37
  try {
37
- const res = await fetch(config.apiUrl);
38
+ const res = await fetchFn(config.apiUrl);
38
39
  if (res.ok) {
39
- if (v)
40
- log(`Successfully pinged ${config.apiUrl}`);
40
+ log.verbose(`Successfully pinged ${config.apiUrl}`);
41
41
  diagnostics.online = res.ok;
42
42
  }
43
43
  else {
@@ -51,7 +51,7 @@ export async function blueprintDoctorCore(options) {
51
51
  // TOKEN
52
52
  if (token) {
53
53
  diagnostics.tokenPresent = true;
54
- tokenOrError = await validTokenOrErrorMessage(token);
54
+ tokenOrError = await validTokenOrErrorMessage(log, token);
55
55
  if (tokenOrError.ok) {
56
56
  diagnostics.tokenValid = true;
57
57
  }
@@ -66,8 +66,7 @@ export async function blueprintDoctorCore(options) {
66
66
  // BLUEPRINT file
67
67
  const blueprintFile = findBlueprintFile(path);
68
68
  if (blueprintFile?.blueprintFilePath) {
69
- if (v)
70
- log(`Found blueprint file at ${blueprintFile.blueprintFilePath.replace(here, '.')}`);
69
+ log.verbose(`Found blueprint file at ${blueprintFile.blueprintFilePath.replace(here, '.')}`);
71
70
  diagnostics.blueprintPresent = true;
72
71
  }
73
72
  else {
@@ -75,21 +74,18 @@ export async function blueprintDoctorCore(options) {
75
74
  }
76
75
  let blueprint;
77
76
  try {
78
- blueprint = await readLocalBlueprint(path);
77
+ blueprint = await readLocalBlueprint(log, path);
79
78
  if (blueprint.errors.length === 0) {
80
- if (v)
81
- log(`Blueprint has no errors`);
79
+ log.verbose(`Blueprint has no errors`);
82
80
  diagnostics.blueprintValid = true;
83
81
  }
84
82
  else {
85
- if (v)
86
- log(`Blueprint errors: \n${blueprint.errors.join('\n ')}`);
83
+ log.verbose(`Blueprint errors: \n${blueprint.errors.join('\n ')}`);
87
84
  diagnostics.blueprintValid = false;
88
85
  }
89
86
  }
90
87
  catch {
91
- if (v)
92
- yikes(`Unable to read blueprint`);
88
+ yikes(`Unable to read blueprint`);
93
89
  diagnostics.blueprintValid = false;
94
90
  }
95
91
  if (blueprint) {
@@ -97,18 +93,15 @@ export async function blueprintDoctorCore(options) {
97
93
  const configPath = blueprintConfig?.configPath;
98
94
  // CONFIG file
99
95
  if (configPath) {
100
- if (v)
101
- log(`Found config file at ${configPath.replace(here, '.')}`);
96
+ log.verbose(`Found config file at ${configPath.replace(here, '.')}`);
102
97
  diagnostics.configFilePresent = true;
103
98
  if (scopeType && scopeId && stackId) {
104
99
  diagnostics.configFileValid = true;
105
- if (v) {
106
- const configOutput = [
107
- `${capitalize(scopeType)}: ${niceId(scopeId)}`,
108
- `Deployment: ${niceId(stackId)}`,
109
- ].join('\n');
110
- log(indent(configOutput));
111
- }
100
+ const configOutput = [
101
+ `${capitalize(scopeType)}: ${niceId(scopeId)}`,
102
+ `Deployment: ${niceId(stackId)}`,
103
+ ].join('\n');
104
+ log.verbose(indent(configOutput));
112
105
  }
113
106
  else {
114
107
  diagnostics.configFileValid = false;
@@ -122,10 +115,10 @@ export async function blueprintDoctorCore(options) {
122
115
  const stackResponse = await getStack({
123
116
  auth: { token, scopeType: 'project', scopeId: projectId },
124
117
  stackId,
118
+ logger: log,
125
119
  });
126
120
  if (stackResponse.ok) {
127
- if (v)
128
- log(`Deployment "Stack" ${niceId(stackId)} ready`);
121
+ log.verbose(`Deployment "Stack" ${niceId(stackId)} ready`);
129
122
  diagnostics.stackReady = true;
130
123
  diagnostics.userHasAccess = true;
131
124
  }
@@ -181,21 +174,31 @@ export async function blueprintDoctorCore(options) {
181
174
  }
182
175
  else if (fix) {
183
176
  if (p) {
184
- return { success: false, error: `${errorMessage}. --fix cannot be used with --path` };
177
+ return {
178
+ success: false,
179
+ error: `${errorMessage}. --fix cannot be used with --path`,
180
+ data: { diagnostics },
181
+ };
185
182
  }
186
183
  if (!tokenOrError) {
187
- return { success: false, error: `${errorMessage}. Unable to fix: Missing authentication token` };
184
+ return {
185
+ success: false,
186
+ error: `${errorMessage}. Unable to fix: Missing authentication token`,
187
+ data: { diagnostics },
188
+ };
188
189
  }
189
190
  if (tokenOrError?.ok === false) {
190
191
  return {
191
192
  success: false,
192
193
  error: `${errorMessage}. Unable to fix: ${tokenOrError.error.message}`,
194
+ data: { diagnostics },
193
195
  };
194
196
  }
195
197
  if (!blueprint) {
196
198
  return {
197
199
  success: false,
198
200
  error: `${errorMessage}. Unable to fix: Blueprint is missing or invalid`,
201
+ data: { diagnostics },
199
202
  };
200
203
  }
201
204
  return blueprintConfigCore({
@@ -3,14 +3,14 @@ import { formatDeployedResourceTree, formatStackInfo, } from '../../utils/displa
3
3
  import { niceId } from '../../utils/display/presenters.js';
4
4
  export async function blueprintInfoCore(options) {
5
5
  const { log, auth, stackId, flags, deployedStack } = options;
6
- const { id: flagStackId, verbose: _verbose = false } = flags;
6
+ const { id: flagStackId, verbose = false } = flags;
7
7
  try {
8
8
  const targetStackId = flagStackId || stackId;
9
9
  let stack = deployedStack;
10
10
  if (flagStackId) {
11
- const existingStackResponse = await getStack({ stackId: targetStackId, auth });
11
+ const existingStackResponse = await getStack({ stackId: targetStackId, auth, logger: log });
12
12
  if (!existingStackResponse.ok) {
13
- log(`Could not retrieve Stack deployment info for ${niceId(targetStackId)}`);
13
+ log.error(`Could not retrieve Stack deployment info for ${niceId(targetStackId)}`);
14
14
  return {
15
15
  success: false,
16
16
  error: existingStackResponse.error || 'Failed to retrieve Stack deployment',
@@ -20,12 +20,12 @@ export async function blueprintInfoCore(options) {
20
20
  }
21
21
  log(formatStackInfo(stack, true));
22
22
  if (stack.resources)
23
- log(formatDeployedResourceTree(stack.resources));
23
+ log(formatDeployedResourceTree(stack.resources, verbose));
24
24
  return { success: true };
25
25
  }
26
26
  catch (error) {
27
27
  const errorMessage = error instanceof Error ? error.message : String(error);
28
- log(`Error: ${errorMessage}`);
28
+ log.error(`Error: ${errorMessage}`);
29
29
  return {
30
30
  success: false,
31
31
  error: errorMessage,
@@ -33,13 +33,13 @@ export declare function resolveScopeAndStack(params: {
33
33
  organizationId: string | undefined;
34
34
  stackId: string | undefined;
35
35
  stackName: string | undefined;
36
- log: (message: string) => void;
36
+ log: CoreConfig['log'];
37
37
  token: string;
38
38
  }): Promise<ResolvedScope>;
39
39
  export declare function determineBlueprintExtension(params: {
40
40
  requestedType: string | undefined;
41
41
  blueprintDir: string;
42
- log: (message: string) => void;
42
+ log: CoreConfig['log'];
43
43
  }): Promise<string>;
44
44
  export declare function createBlueprintFiles(params: {
45
45
  blueprintDir: string;
@@ -49,6 +49,6 @@ export declare function createBlueprintFiles(params: {
49
49
  scopeId: string;
50
50
  stackId: string | undefined;
51
51
  bin: string;
52
- log: (message: string) => void;
52
+ log: CoreConfig['log'];
53
53
  }): Promise<CoreResult>;
54
54
  export {};
@@ -33,7 +33,7 @@ export async function blueprintInitCore(options) {
33
33
  // look for existing blueprint file and maybe re-configure it
34
34
  const existingBlueprintFile = findBlueprintFile(blueprintDir);
35
35
  if (existingBlueprintFile) {
36
- log(warn(`Existing Blueprint found: ${filePathRelativeToCwd(existingBlueprintFile.blueprintFilePath)}`));
36
+ log.warn(warn(`Existing Blueprint found: ${filePathRelativeToCwd(existingBlueprintFile.blueprintFilePath)}`));
37
37
  if (flagExample) {
38
38
  return {
39
39
  success: false,
@@ -54,7 +54,7 @@ export async function blueprintInitCore(options) {
54
54
  if (!overwrite)
55
55
  return { success: false, error: 'Initialization cancelled.' };
56
56
  }
57
- const existingBlueprint = await readLocalBlueprint(existingBlueprintFile.blueprintFilePath);
57
+ const existingBlueprint = await readLocalBlueprint(log, existingBlueprintFile.blueprintFilePath);
58
58
  return blueprintConfigCore({
59
59
  blueprint: existingBlueprint,
60
60
  bin,
@@ -121,16 +121,21 @@ export function validateFlags(flags) {
121
121
  async function handleExampleInitialization(options) {
122
122
  const { exampleName, blueprintDir, userProvidedDirName, projectId, token, log } = options;
123
123
  log(warn(`Example feature is experimental. Setting up "${exampleName}"...`));
124
- const exampleExists = await verifyExampleExists({ type: 'blueprint', name: exampleName });
124
+ const exampleExists = await verifyExampleExists({
125
+ type: 'blueprint',
126
+ name: exampleName,
127
+ logger: log,
128
+ });
125
129
  if (!exampleExists) {
126
130
  return { success: false, error: `Blueprint example "${exampleName}" does not exist.` };
127
131
  }
128
- const resolvedProjectId = projectId || (await promptForProject({ token })).projectId;
132
+ const resolvedProjectId = projectId || (await promptForProject({ token, logger: log })).projectId;
129
133
  const stack = await createEmptyStack({
130
134
  token,
131
135
  scopeType: SCOPE_PROJECT,
132
136
  scopeId: resolvedProjectId,
133
137
  name: `example-${exampleName}`,
138
+ logger: log,
134
139
  });
135
140
  const exampleDir = userProvidedDirName || join(blueprintDir, exampleName);
136
141
  if (existsSync(exampleDir)) {
@@ -140,6 +145,7 @@ async function handleExampleInitialization(options) {
140
145
  exampleType: 'blueprint',
141
146
  exampleName,
142
147
  dir: exampleDir,
148
+ logger: log,
143
149
  });
144
150
  if (!addedExample) {
145
151
  return { success: false, error: `Unable to download example "${exampleName}"` };
@@ -184,18 +190,19 @@ export async function resolveScopeAndStack(params) {
184
190
  scopeType,
185
191
  scopeId,
186
192
  name: stackName,
193
+ logger: log,
187
194
  });
188
195
  resolvedStackId = stack.id;
189
196
  }
190
197
  if (!scopeId) {
191
198
  log('\nBlueprints are associated with a Sanity Project. Please select one:');
192
- const pickedProject = await promptForProject({ token });
199
+ const pickedProject = await promptForProject({ token, logger: log });
193
200
  scopeType = SCOPE_PROJECT;
194
201
  scopeId = pickedProject.projectId;
195
202
  }
196
203
  if (!resolvedStackId) {
197
204
  log('\nBlueprints are deployed to a "Stack".');
198
- const { stackId } = await promptForStack({ projectId: scopeId, token });
205
+ const { stackId } = await promptForStack({ projectId: scopeId, token, logger: log });
199
206
  resolvedStackId = stackId;
200
207
  }
201
208
  return {
@@ -252,11 +259,11 @@ export async function createBlueprintFiles(params) {
252
259
  if (blueprintExtension !== 'json') {
253
260
  const blueprintsPackage = '@sanity/blueprints';
254
261
  try {
255
- await writeOrUpdateNodeDependency(blueprintFilePath, blueprintsPackage);
262
+ await writeOrUpdateNodeDependency(blueprintFilePath, blueprintsPackage, log);
256
263
  log(check(`${chalk.bold('Added dependency:')} ${blueprintsPackage}`));
257
264
  }
258
265
  catch {
259
- log(warn(`Unable to add ${blueprintsPackage} to your project.`));
266
+ log.warn(warn(`Unable to add ${blueprintsPackage} to your project.`));
260
267
  }
261
268
  }
262
269
  const nextStepParts = [];
@@ -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'));
@@ -1,8 +1,5 @@
1
- import type { ReadBlueprintResult } from '../../actions/blueprints/blueprint.js';
2
- import type { CoreConfig, CoreResult } from '../index.js';
3
- export interface BlueprintStacksOptions extends CoreConfig {
4
- token: string;
5
- blueprint: ReadBlueprintResult;
1
+ import type { BlueprintConfig, CoreResult } from '../index.js';
2
+ export interface BlueprintStacksOptions extends BlueprintConfig {
6
3
  flags: {
7
4
  'project-id'?: string;
8
5
  'organization-id'?: string;
@@ -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' };