@sanity/runtime-cli 12.4.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 (111) 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 +1 -2
  89. package/dist/index.js +1 -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/utils/display/prompt.d.ts +5 -2
  95. package/dist/utils/display/prompt.js +5 -4
  96. package/dist/utils/functions/fetch-document.d.ts +3 -2
  97. package/dist/utils/functions/fetch-document.js +7 -6
  98. package/dist/utils/index.d.ts +2 -0
  99. package/dist/utils/index.js +2 -0
  100. package/dist/utils/logger.d.ts +13 -0
  101. package/dist/utils/logger.js +61 -0
  102. package/dist/utils/other/github.d.ts +2 -1
  103. package/dist/utils/other/github.js +4 -2
  104. package/dist/utils/other/npmjs.d.ts +2 -1
  105. package/dist/utils/other/npmjs.js +4 -2
  106. package/dist/utils/traced-fetch.d.ts +35 -0
  107. package/dist/utils/traced-fetch.js +238 -0
  108. package/dist/utils/validated-token.d.ts +3 -2
  109. package/dist/utils/validated-token.js +6 -4
  110. package/oclif.manifest.json +175 -38
  111. package/package.json +13 -5
@@ -81,13 +81,13 @@ export function patchConfigFile(blueprintFilePath, updateableProperties) {
81
81
  * @throws {Error} if unable to fetch project
82
82
  * @returns {Promise<string>} the discovered organizationId
83
83
  */
84
- export async function backfillOrganizationId({ blueprintFilePath, projectId, }) {
84
+ export async function backfillOrganizationId({ blueprintFilePath, projectId, logger, }) {
85
85
  const token = config.token;
86
86
  if (!token)
87
87
  throw new Error('No token found');
88
88
  let organizationId;
89
89
  try {
90
- const response = await getProject({ token, scopeType: 'project', scopeId: projectId });
90
+ const response = await getProject({ token, scopeType: 'project', scopeId: projectId, logger });
91
91
  if (!response.ok)
92
92
  throw new Error('Failed to get project');
93
93
  if (!response.project)
@@ -102,7 +102,7 @@ export async function backfillOrganizationId({ blueprintFilePath, projectId, })
102
102
  patchConfigFile(blueprintFilePath, { organizationId });
103
103
  return organizationId;
104
104
  }
105
- export async function backfillProjectBasedStackId({ blueprintFilePath, projectId, }) {
105
+ export async function backfillProjectBasedStackId({ blueprintFilePath, projectId, logger, }) {
106
106
  const token = config.token;
107
107
  if (!token)
108
108
  throw new Error('No token found');
@@ -112,7 +112,7 @@ export async function backfillProjectBasedStackId({ blueprintFilePath, projectId
112
112
  token,
113
113
  scopeType: 'project',
114
114
  scopeId: projectId,
115
- });
115
+ }, logger);
116
116
  if (!ok)
117
117
  throw new Error(error || 'Failed to list stacks');
118
118
  if (stacks.length === 1 &&
@@ -1,10 +1,11 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { AuthParams, BlueprintLog } from '../../utils/types.js';
2
3
  export interface LogStreamingConfig {
3
4
  stackId: string;
4
5
  after?: string;
5
6
  auth: AuthParams;
6
7
  showBanner?: boolean;
7
- log: (message: string) => void;
8
+ log: ReturnType<typeof Logger>;
8
9
  }
9
10
  export interface StreamLogsOptions {
10
11
  stackId: string;
@@ -13,8 +14,9 @@ export interface StreamLogsOptions {
13
14
  onLog: (log: BlueprintLog) => void;
14
15
  onOpen: () => void;
15
16
  onError: (error: string) => void;
17
+ logger: ReturnType<typeof Logger>;
16
18
  }
17
- export declare function streamLogs({ stackId, after, auth, onLog, onOpen, onError, }: StreamLogsOptions): () => void;
19
+ export declare function streamLogs({ stackId, after, auth, onLog, onOpen, onError, logger, }: StreamLogsOptions): () => void;
18
20
  /** Check if a log is newer than a given timestamp */
19
21
  export declare function isNewerLog(log: BlueprintLog, timestamp: number): boolean;
20
22
  /**
@@ -2,15 +2,17 @@ import chalk from 'chalk';
2
2
  import { EventSource } from 'eventsource';
3
3
  import { formatLogEntry } from '../../utils/display/logs-formatting.js';
4
4
  import getHeaders from '../../utils/get-headers.js';
5
+ import { createTracedFetch } from '../../utils/traced-fetch.js';
5
6
  import { logsUrl } from './logs.js';
6
- export function streamLogs({ stackId, after, auth, onLog, onOpen, onError, }) {
7
+ export function streamLogs({ stackId, after, auth, onLog, onOpen, onError, logger, }) {
8
+ const fetchFn = createTracedFetch(logger);
7
9
  const url = new URL(`${logsUrl}/stream`);
8
10
  url.searchParams.append('stackId', stackId);
9
11
  if (after)
10
12
  url.searchParams.append('after', after);
11
13
  const headers = getHeaders(auth);
12
14
  const eventSource = new EventSource(url.toString(), {
13
- fetch: (input, init) => fetch(input, {
15
+ fetch: (input, init) => fetchFn(input, {
14
16
  ...init,
15
17
  headers: {
16
18
  ...init?.headers,
@@ -96,5 +98,6 @@ export async function setupLogStreaming(config) {
96
98
  onLog: onLogReceived,
97
99
  onOpen: onStreamOpen,
98
100
  onError: onStreamError,
101
+ logger: log,
99
102
  });
100
103
  }
@@ -1,6 +1,7 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { AuthParams, BlueprintLog } from '../../utils/types.js';
2
3
  export declare const logsUrl: string;
3
- export declare function getLogs(stackId: string, auth: AuthParams): Promise<{
4
+ export declare function getLogs(stackId: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
4
5
  logs: BlueprintLog[];
5
6
  ok: boolean;
6
7
  error: string | null;
@@ -1,11 +1,13 @@
1
1
  import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
+ import { createTracedFetch } from '../../utils/traced-fetch.js';
3
4
  const { apiUrl } = config;
4
5
  export const logsUrl = `${apiUrl}vX/blueprints/logs`;
5
- export async function getLogs(stackId, auth) {
6
+ export async function getLogs(stackId, auth, logger) {
7
+ const fetchFn = createTracedFetch(logger);
6
8
  const url = new URL(logsUrl);
7
9
  url.searchParams.append('stackId', stackId);
8
- const response = await fetch(url.toString(), {
10
+ const response = await fetchFn(url.toString(), {
9
11
  headers: getHeaders(auth),
10
12
  method: 'GET',
11
13
  });
@@ -1,3 +1,4 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { FunctionResourceBase } from '../../utils/types.js';
2
3
  interface FunctionResourceOptions {
3
4
  name: string;
@@ -10,7 +11,7 @@ interface FunctionResourceOptions {
10
11
  /**
11
12
  * Creates a new function resource file and adds it to the blueprint
12
13
  */
13
- export declare function createFunctionResource(options: FunctionResourceOptions): Promise<{
14
+ export declare function createFunctionResource(options: FunctionResourceOptions, logger: ReturnType<typeof Logger>): Promise<{
14
15
  filePath: string;
15
16
  resourceAdded: boolean;
16
17
  resource: FunctionResourceBase;
@@ -18,7 +18,7 @@ export const handler = documentEventHandler(async ({ context, event }) => {
18
18
  /**
19
19
  * Creates a new function resource file and adds it to the blueprint
20
20
  */
21
- export async function createFunctionResource(options) {
21
+ export async function createFunctionResource(options, logger) {
22
22
  const { name, type, lang, blueprintFilePath, addHelpers = false, installCommand } = options;
23
23
  let workingDir = cwd();
24
24
  if (blueprintFilePath) {
@@ -44,7 +44,7 @@ export async function createFunctionResource(options) {
44
44
  writeFileSync(indexPath, addHelpers ? DEFAULT_HELPER_FUNCTION_TEMPLATE : DEFAULT_FUNCTION_TEMPLATE);
45
45
  if (addHelpers && blueprintFilePath) {
46
46
  try {
47
- await writeOrUpdateNodeDependency(blueprintFilePath, '@sanity/functions');
47
+ await writeOrUpdateNodeDependency(blueprintFilePath, '@sanity/functions', logger);
48
48
  }
49
49
  catch (err) {
50
50
  throw new Error('Unable to add @sanity/functions to your project.', { cause: err });
@@ -1,3 +1,4 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { AuthParams, ScopeType, Stack, StackMutation } from '../../utils/types.js';
2
3
  export declare const stacksUrl: string;
3
4
  type ListStacksResponse = {
@@ -9,49 +10,54 @@ type ListStacksResponse = {
9
10
  error: string;
10
11
  stacks: unknown;
11
12
  };
12
- export declare function listStacks(auth: AuthParams): Promise<ListStacksResponse>;
13
+ export declare function listStacks(auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<ListStacksResponse>;
13
14
  interface GetStackResponse {
14
15
  ok: boolean;
15
16
  error: string | null;
16
17
  stack: Stack;
17
18
  response?: Response;
18
19
  }
19
- export declare function getStack({ stackId, auth, }: {
20
+ export declare function getStack({ stackId, auth, logger, }: {
20
21
  stackId: string;
21
22
  auth: AuthParams;
23
+ logger: ReturnType<typeof Logger>;
22
24
  }): Promise<GetStackResponse>;
23
25
  interface CreateStackResponse {
24
26
  ok: boolean;
25
27
  error: string | null;
26
28
  stack: Stack;
27
29
  }
28
- export declare function createStack({ stackMutation, auth, }: {
30
+ export declare function createStack({ stackMutation, auth, logger, }: {
29
31
  stackMutation: StackMutation;
30
32
  auth: AuthParams;
33
+ logger: ReturnType<typeof Logger>;
31
34
  }): Promise<CreateStackResponse>;
32
- export declare function createEmptyStack({ token, scopeType, scopeId, name, }: {
35
+ export declare function createEmptyStack({ token, scopeType, scopeId, name, logger, }: {
33
36
  token: string;
34
37
  scopeType: ScopeType;
35
38
  scopeId: string;
36
39
  name: string;
40
+ logger: ReturnType<typeof Logger>;
37
41
  }): Promise<Stack>;
38
42
  interface UpdateStackResponse {
39
43
  ok: boolean;
40
44
  error: string | null;
41
45
  stack: Stack;
42
46
  }
43
- export declare function updateStack({ stackId, stackMutation, auth, }: {
47
+ export declare function updateStack({ stackId, stackMutation, auth, logger, }: {
44
48
  stackId: string;
45
49
  stackMutation: StackMutation;
46
50
  auth: AuthParams;
51
+ logger: ReturnType<typeof Logger>;
47
52
  }): Promise<UpdateStackResponse>;
48
53
  interface DestroyStackResponse {
49
54
  ok: boolean;
50
55
  error: string | null;
51
56
  stack: Stack;
52
57
  }
53
- export declare function destroyStack({ stackId, auth, }: {
58
+ export declare function destroyStack({ stackId, auth, logger, }: {
54
59
  stackId: string;
55
60
  auth: AuthParams;
61
+ logger: ReturnType<typeof Logger>;
56
62
  }): Promise<DestroyStackResponse>;
57
63
  export {};
@@ -1,9 +1,11 @@
1
1
  import config from '../../config.js';
2
2
  import getHeaders from '../../utils/get-headers.js';
3
+ import { createTracedFetch } from '../../utils/traced-fetch.js';
3
4
  const { apiUrl } = config;
4
5
  export const stacksUrl = `${apiUrl}vX/blueprints/stacks`;
5
- export async function listStacks(auth) {
6
- const response = await fetch(stacksUrl, {
6
+ export async function listStacks(auth, logger) {
7
+ const fetchFn = createTracedFetch(logger);
8
+ const response = await fetchFn(stacksUrl, {
7
9
  method: 'GET',
8
10
  headers: getHeaders(auth),
9
11
  });
@@ -14,8 +16,9 @@ export async function listStacks(auth) {
14
16
  stacks: data,
15
17
  };
16
18
  }
17
- export async function getStack({ stackId, auth, }) {
18
- const response = await fetch(`${stacksUrl}/${stackId}`, {
19
+ export async function getStack({ stackId, auth, logger, }) {
20
+ const fetchFn = createTracedFetch(logger);
21
+ const response = await fetchFn(`${stacksUrl}/${stackId}`, {
19
22
  method: 'GET',
20
23
  headers: getHeaders(auth),
21
24
  });
@@ -27,8 +30,9 @@ export async function getStack({ stackId, auth, }) {
27
30
  response,
28
31
  };
29
32
  }
30
- export async function createStack({ stackMutation, auth, }) {
31
- const response = await fetch(stacksUrl, {
33
+ export async function createStack({ stackMutation, auth, logger, }) {
34
+ const fetchFn = createTracedFetch(logger);
35
+ const response = await fetchFn(stacksUrl, {
32
36
  method: 'POST',
33
37
  headers: getHeaders(auth),
34
38
  body: JSON.stringify({ ...stackMutation, useProjectBasedId: false }), // API defaults to true as of 2025-11-26
@@ -40,7 +44,7 @@ export async function createStack({ stackMutation, auth, }) {
40
44
  stack: data,
41
45
  };
42
46
  }
43
- export async function createEmptyStack({ token, scopeType, scopeId, name, }) {
47
+ export async function createEmptyStack({ token, scopeType, scopeId, name, logger, }) {
44
48
  const stackMutation = {
45
49
  name,
46
50
  scopeType,
@@ -50,14 +54,16 @@ export async function createEmptyStack({ token, scopeType, scopeId, name, }) {
50
54
  const response = await createStack({
51
55
  stackMutation,
52
56
  auth: { token, scopeType, scopeId },
57
+ logger,
53
58
  });
54
59
  if (!response.ok) {
55
60
  throw new Error(response.error || 'Failed to create new Stack');
56
61
  }
57
62
  return response.stack;
58
63
  }
59
- export async function updateStack({ stackId, stackMutation, auth, }) {
60
- const response = await fetch(`${stacksUrl}/${stackId}`, {
64
+ export async function updateStack({ stackId, stackMutation, auth, logger, }) {
65
+ const fetchFn = createTracedFetch(logger);
66
+ const response = await fetchFn(`${stacksUrl}/${stackId}`, {
61
67
  method: 'PUT',
62
68
  headers: getHeaders(auth),
63
69
  body: JSON.stringify(stackMutation),
@@ -69,8 +75,9 @@ export async function updateStack({ stackId, stackMutation, auth, }) {
69
75
  stack: data,
70
76
  };
71
77
  }
72
- export async function destroyStack({ stackId, auth, }) {
73
- const response = await fetch(`${stacksUrl}/${stackId}`, {
78
+ export async function destroyStack({ stackId, auth, logger, }) {
79
+ const fetchFn = createTracedFetch(logger);
80
+ const response = await fetchFn(`${stacksUrl}/${stackId}`, {
74
81
  method: 'DELETE',
75
82
  headers: getHeaders(auth),
76
83
  });
@@ -1,2 +1,3 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { InvokeExecutionOptions } from '../../utils/types.js';
2
- export declare function dev(host: string, port: number, executionOptions?: Partial<InvokeExecutionOptions>): Promise<void>;
3
+ export declare function dev(host: string, port: number, logger: ReturnType<typeof Logger>, executionOptions?: Partial<InvokeExecutionOptions>): Promise<void>;
@@ -1,4 +1,4 @@
1
1
  import { app } from '../../server/app.js';
2
- export async function dev(host, port, executionOptions) {
3
- app(host, Number(port), executionOptions);
2
+ export async function dev(host, port, logger, executionOptions) {
3
+ app(host, Number(port), logger, executionOptions);
4
4
  }
@@ -1,5 +1,6 @@
1
+ import type { Logger } from '../../../utils/logger.js';
1
2
  import type { AuthParams } from '../../../utils/types.js';
2
- export declare function list(id: string, auth: AuthParams): Promise<{
3
+ export declare function list(id: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
3
4
  ok: boolean;
4
5
  envvars: any;
5
6
  error: any;
@@ -1,8 +1,10 @@
1
1
  import config from '../../../config.js';
2
2
  import getHeaders from '../../../utils/get-headers.js';
3
+ import { createTracedFetch } from '../../../utils/traced-fetch.js';
3
4
  const { apiUrl } = config;
4
- export async function list(id, auth) {
5
- const response = await fetch(`${apiUrl}v2025-07-30/functions/${id}/envvars`, {
5
+ export async function list(id, auth, logger) {
6
+ const fetchFn = createTracedFetch(logger);
7
+ const response = await fetchFn(`${apiUrl}v2025-07-30/functions/${id}/envvars`, {
6
8
  headers: getHeaders(auth),
7
9
  method: 'GET',
8
10
  });
@@ -1,5 +1,6 @@
1
+ import type { Logger } from '../../../utils/logger.js';
1
2
  import type { AuthParams } from '../../../utils/types.js';
2
- export declare function remove(id: string, key: string, auth: AuthParams): Promise<{
3
+ export declare function remove(id: string, key: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
3
4
  ok: boolean;
4
5
  error: any;
5
6
  }>;
@@ -1,8 +1,10 @@
1
1
  import config from '../../../config.js';
2
2
  import getHeaders from '../../../utils/get-headers.js';
3
+ import { createTracedFetch } from '../../../utils/traced-fetch.js';
3
4
  const { apiUrl } = config;
4
- export async function remove(id, key, auth) {
5
- const response = await fetch(`${apiUrl}v2025-07-30/functions/${id}/envvars/${key}`, {
5
+ export async function remove(id, key, auth, logger) {
6
+ const fetchFn = createTracedFetch(logger);
7
+ const response = await fetchFn(`${apiUrl}v2025-07-30/functions/${id}/envvars/${key}`, {
6
8
  headers: getHeaders(auth),
7
9
  method: 'DELETE',
8
10
  });
@@ -1,5 +1,6 @@
1
+ import type { Logger } from '../../../utils/logger.js';
1
2
  import type { AuthParams } from '../../../utils/types.js';
2
- export declare function update(id: string, key: string, value: string, auth: AuthParams): Promise<{
3
+ export declare function update(id: string, key: string, value: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
3
4
  ok: boolean;
4
5
  error: any;
5
6
  }>;
@@ -1,8 +1,10 @@
1
1
  import config from '../../../config.js';
2
2
  import getHeaders from '../../../utils/get-headers.js';
3
+ import { createTracedFetch } from '../../../utils/traced-fetch.js';
3
4
  const { apiUrl } = config;
4
- export async function update(id, key, value, auth) {
5
- const response = await fetch(`${apiUrl}v2025-07-30/functions/${id}/envvars/${key}`, {
5
+ export async function update(id, key, value, auth, logger) {
6
+ const fetchFn = createTracedFetch(logger);
7
+ const response = await fetchFn(`${apiUrl}v2025-07-30/functions/${id}/envvars/${key}`, {
6
8
  body: JSON.stringify({ value }),
7
9
  headers: getHeaders(auth),
8
10
  method: 'PUT',
@@ -1,16 +1,17 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { AuthParams, FunctionLog } from '../../utils/types.js';
2
3
  /** @internal */
3
4
  export interface LoggingOptions {
4
5
  limit: number;
5
6
  }
6
- export declare function logs(id: string, options: LoggingOptions, auth: AuthParams): Promise<{
7
+ export declare function logs(id: string, options: LoggingOptions, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
7
8
  ok: boolean;
8
9
  error: any;
9
10
  logs: any;
10
11
  total: any;
11
12
  }>;
12
- export declare function deleteLogs(id: string, auth: AuthParams): Promise<{
13
+ export declare function deleteLogs(id: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
13
14
  ok: boolean;
14
15
  error: any;
15
16
  }>;
16
- export declare function streamLogs(id: string, auth: AuthParams, onLog: (log: FunctionLog) => void, onOpen: () => void, onError: (error: string) => void): () => void;
17
+ export declare function streamLogs(id: string, auth: AuthParams, onLog: (log: FunctionLog) => void, onOpen: () => void, onError: (error: string) => void, logger: ReturnType<typeof Logger>): () => void;
@@ -1,10 +1,12 @@
1
1
  import { EventSource } from 'eventsource';
2
2
  import config from '../../config.js';
3
3
  import getHeaders from '../../utils/get-headers.js';
4
+ import { createTracedFetch } from '../../utils/traced-fetch.js';
4
5
  const { apiUrl } = config;
5
- export async function logs(id, options, auth) {
6
+ export async function logs(id, options, auth, logger) {
6
7
  const { limit } = options;
7
- const response = await fetch(`${apiUrl}v2025-07-30/functions/${id}/logs?limit=${limit}`, {
8
+ const fetchFn = createTracedFetch(logger);
9
+ const response = await fetchFn(`${apiUrl}v2025-07-30/functions/${id}/logs?limit=${limit}`, {
8
10
  headers: getHeaders(auth),
9
11
  method: 'GET',
10
12
  });
@@ -16,8 +18,9 @@ export async function logs(id, options, auth) {
16
18
  total: response.ok ? json.total : 0,
17
19
  };
18
20
  }
19
- export async function deleteLogs(id, auth) {
20
- const response = await fetch(`${apiUrl}v2025-07-30/functions/${id}/logs`, {
21
+ export async function deleteLogs(id, auth, logger) {
22
+ const fetchFn = createTracedFetch(logger);
23
+ const response = await fetchFn(`${apiUrl}v2025-07-30/functions/${id}/logs`, {
21
24
  headers: getHeaders(auth),
22
25
  method: 'DELETE',
23
26
  });
@@ -28,11 +31,12 @@ export async function deleteLogs(id, auth) {
28
31
  };
29
32
  }
30
33
  // Create streaming logs connection
31
- export function streamLogs(id, auth, onLog, onOpen, onError) {
34
+ export function streamLogs(id, auth, onLog, onOpen, onError, logger) {
32
35
  const url = new URL(`${apiUrl}v2025-07-30/functions/${id}/logs/stream`);
33
36
  const headers = getHeaders(auth);
37
+ const fetchFn = createTracedFetch(logger);
34
38
  const eventSource = new EventSource(url.toString(), {
35
- fetch: (input, init) => fetch(input, {
39
+ fetch: (input, init) => fetchFn(input, {
36
40
  ...init,
37
41
  headers: {
38
42
  ...init?.headers,
@@ -1 +1,2 @@
1
- export declare function writeOrUpdateNodeDependency(nearFilePath: string, dependency: string): Promise<void>;
1
+ import type { Logger } from '../utils/logger.js';
2
+ export declare function writeOrUpdateNodeDependency(nearFilePath: string, dependency: string, logger: ReturnType<typeof Logger>): Promise<void>;
@@ -1,12 +1,12 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, extname, join } from 'node:path';
3
3
  import { getLatestNpmVersion } from '../utils/other/npmjs.js';
4
- export async function writeOrUpdateNodeDependency(nearFilePath, dependency) {
4
+ export async function writeOrUpdateNodeDependency(nearFilePath, dependency, logger) {
5
5
  const dir = dirname(nearFilePath);
6
6
  const extension = extname(nearFilePath);
7
7
  if (extension === '.json')
8
8
  return; // ? why do we bail out here?
9
- const version = await getLatestNpmVersion(dependency);
9
+ const version = await getLatestNpmVersion(dependency, logger);
10
10
  const packageJsonPath = join(dir, 'package.json');
11
11
  const packageExists = existsSync(packageJsonPath);
12
12
  if (!packageExists) {
@@ -1,22 +1,25 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  export declare const EXAMPLES_CACHE_DIR: string;
2
3
  declare const EXAMPLE_TYPES: {
3
4
  blueprint: string;
4
5
  function: string;
5
6
  };
6
- export declare function verifyExampleExists({ type, name, }: {
7
+ export declare function verifyExampleExists({ type, name, logger, }: {
7
8
  type: keyof typeof EXAMPLE_TYPES;
8
9
  name: string;
10
+ logger: ReturnType<typeof Logger>;
9
11
  }): Promise<boolean>;
10
12
  /**
11
13
  * Downloads an example from the examples repo and writes it to disk.
12
14
  * @sideEffect Creates the example directory and writes the example to disk.
13
15
  * @returns The example files and directory and the function config if it exists.
14
16
  */
15
- export declare function writeExample({ ownerRepo, exampleType, exampleName, dir, }: {
17
+ export declare function writeExample({ ownerRepo, exampleType, exampleName, dir, logger, }: {
16
18
  ownerRepo?: string;
17
19
  exampleType: keyof typeof EXAMPLE_TYPES;
18
20
  exampleName: string;
19
21
  dir?: string;
22
+ logger: ReturnType<typeof Logger>;
20
23
  }): Promise<false | {
21
24
  files: Record<string, string>;
22
25
  dir: string;
@@ -14,13 +14,13 @@ const EXAMPLE_TYPES = {
14
14
  blueprint: BLUEPRINTS_DIR,
15
15
  function: FUNCTIONS_DIR,
16
16
  };
17
- export async function verifyExampleExists({ type, name, }) {
17
+ export async function verifyExampleExists({ type, name, logger, }) {
18
18
  const examplePath = `${EXAMPLE_TYPES[type]}/${name}`;
19
19
  const path = `/repos/${EXAMPLES_REPO}/contents/${examplePath}`;
20
- const response = await gitHubRequest(path);
20
+ const response = await gitHubRequest(path, logger);
21
21
  return response.ok;
22
22
  }
23
- async function downloadRepoArchive(ownerRepo, ref = 'main') {
23
+ async function downloadRepoArchive(logger, ownerRepo, ref = 'main') {
24
24
  // cache the archive in a temp directory
25
25
  const cacheKey = `${ownerRepo.replace('/', '-')}-${ref}.tar.gz`;
26
26
  const cacheDir = EXAMPLES_CACHE_DIR;
@@ -33,7 +33,7 @@ async function downloadRepoArchive(ownerRepo, ref = 'main') {
33
33
  }
34
34
  const path = `/repos/${ownerRepo}/tarball/${ref}`;
35
35
  try {
36
- const response = await gitHubRequest(path);
36
+ const response = await gitHubRequest(path, logger);
37
37
  if (!response.ok)
38
38
  throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
39
39
  if (!response.body)
@@ -154,8 +154,8 @@ function extractInstructions(exampleFiles) {
154
154
  * @sideEffect Creates the example directory and writes the example to disk.
155
155
  * @returns The example files and directory and the function config if it exists.
156
156
  */
157
- export async function writeExample({ ownerRepo = EXAMPLES_REPO, exampleType, exampleName, dir = './tmp', }) {
158
- const archiveStream = await downloadRepoArchive(ownerRepo);
157
+ export async function writeExample({ ownerRepo = EXAMPLES_REPO, exampleType, exampleName, dir = './tmp', logger, }) {
158
+ const archiveStream = await downloadRepoArchive(logger, ownerRepo);
159
159
  if (!archiveStream)
160
160
  return false;
161
161
  const exampleFiles = await extractExampleFromArchive({
@@ -1,3 +1,4 @@
1
+ import type { Logger } from '../../utils/logger.js';
1
2
  import type { ScopeType } from '../../utils/types.js';
2
3
  export declare const projectsApiPath: string;
3
4
  export declare const orgsApiPath: string;
@@ -18,8 +19,9 @@ interface ListProjectsResponse {
18
19
  error: string | null;
19
20
  projects: Project[];
20
21
  }
21
- export declare function listProjects({ token }: {
22
+ export declare function listProjects({ token, logger, }: {
22
23
  token: string;
24
+ logger: ReturnType<typeof Logger>;
23
25
  }): Promise<ListProjectsResponse>;
24
26
  interface GroupedProjectsByOrganizationResponse {
25
27
  ok: boolean;
@@ -33,17 +35,19 @@ interface GroupedProjects {
33
35
  };
34
36
  projects?: Project[];
35
37
  }
36
- export declare function groupProjectsByOrganization({ token, }: {
38
+ export declare function groupProjectsByOrganization({ token, logger, }: {
37
39
  token: string;
40
+ logger: ReturnType<typeof Logger>;
38
41
  }): Promise<GroupedProjectsByOrganizationResponse>;
39
42
  interface GetProjectResponse {
40
43
  ok: boolean;
41
44
  error: string | null;
42
45
  project: Project;
43
46
  }
44
- export declare function getProject({ token, scopeId, scopeType, }: {
47
+ export declare function getProject({ token, scopeId, scopeType, logger, }: {
45
48
  token: string;
46
49
  scopeId: string;
47
50
  scopeType: ScopeType;
51
+ logger: ReturnType<typeof Logger>;
48
52
  }): Promise<GetProjectResponse>;
49
53
  export {};
@@ -1,9 +1,11 @@
1
1
  import config from '../../config.js';
2
+ import { createTracedFetch } from '../../utils/traced-fetch.js';
2
3
  const { apiUrl } = config;
3
4
  export const projectsApiPath = `${apiUrl}v2021-06-07/projects`;
4
5
  export const orgsApiPath = `${apiUrl}v2021-06-07/organizations`;
5
- export async function listProjects({ token }) {
6
- const projectsFetch = await fetch(projectsApiPath, {
6
+ export async function listProjects({ token, logger, }) {
7
+ const fetchFn = createTracedFetch(logger);
8
+ const projectsFetch = await fetchFn(projectsApiPath, {
7
9
  method: 'GET',
8
10
  headers: {
9
11
  Authorization: `Bearer ${token}`,
@@ -17,8 +19,9 @@ export async function listProjects({ token }) {
17
19
  projects,
18
20
  };
19
21
  }
20
- export async function groupProjectsByOrganization({ token, }) {
21
- const projectsResponse = await listProjects({ token });
22
+ export async function groupProjectsByOrganization({ token, logger, }) {
23
+ const fetchFn = createTracedFetch(logger);
24
+ const projectsResponse = await listProjects({ token, logger });
22
25
  if (!projectsResponse.ok) {
23
26
  return {
24
27
  ok: false,
@@ -26,7 +29,7 @@ export async function groupProjectsByOrganization({ token, }) {
26
29
  organizations: [],
27
30
  };
28
31
  }
29
- const orgsFetch = await fetch(orgsApiPath, {
32
+ const orgsFetch = await fetchFn(orgsApiPath, {
30
33
  method: 'GET',
31
34
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
32
35
  });
@@ -48,11 +51,12 @@ export async function groupProjectsByOrganization({ token, }) {
48
51
  organizations: orgsWithProjects,
49
52
  };
50
53
  }
51
- export async function getProject({ token, scopeId, scopeType, }) {
54
+ export async function getProject({ token, scopeId, scopeType, logger, }) {
52
55
  if (scopeType !== 'project') {
53
56
  throw new Error('Scope type must be project');
54
57
  }
55
- const response = await fetch(`${projectsApiPath}/${scopeId}`, {
58
+ const fetchFn = createTracedFetch(logger);
59
+ const response = await fetchFn(`${projectsApiPath}/${scopeId}`, {
56
60
  method: 'GET',
57
61
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
58
62
  });
@@ -7,6 +7,7 @@ export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
7
7
  export declare const baseFlags: {
8
8
  json: Interfaces.BooleanFlag<boolean>;
9
9
  path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
10
+ trace: Interfaces.BooleanFlag<boolean>;
10
11
  verbose: Interfaces.BooleanFlag<boolean>;
11
12
  };
12
13
  /**
@@ -25,6 +26,7 @@ export declare abstract class RuntimeCommand<T extends typeof Command> extends C
25
26
  static baseFlags: {
26
27
  json: Interfaces.BooleanFlag<boolean>;
27
28
  path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
29
+ trace: Interfaces.BooleanFlag<boolean>;
28
30
  verbose: Interfaces.BooleanFlag<boolean>;
29
31
  };
30
32
  static enableJsonFlag: boolean;
@@ -49,6 +51,7 @@ export declare abstract class LocalBlueprintCommand<T extends typeof Command> ex
49
51
  static baseFlags: {
50
52
  json: Interfaces.BooleanFlag<boolean>;
51
53
  path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
54
+ trace: Interfaces.BooleanFlag<boolean>;
52
55
  verbose: Interfaces.BooleanFlag<boolean>;
53
56
  };
54
57
  init(): Promise<void>;
@@ -71,6 +74,7 @@ export declare abstract class DeployedStackCommand<T extends typeof Command> ext
71
74
  static baseFlags: {
72
75
  json: Interfaces.BooleanFlag<boolean>;
73
76
  path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
77
+ trace: Interfaces.BooleanFlag<boolean>;
74
78
  verbose: Interfaces.BooleanFlag<boolean>;
75
79
  };
76
80
  init(): Promise<void>;