@sanity/runtime-cli 1.3.1 → 1.4.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 (59) hide show
  1. package/README.md +11 -14
  2. package/dist/actions/blueprints/logs.d.ts +1 -0
  3. package/dist/actions/blueprints/logs.js +3 -2
  4. package/dist/actions/blueprints/operations.d.ts +1 -0
  5. package/dist/actions/blueprints/operations.js +3 -2
  6. package/dist/actions/blueprints/read-blueprint.d.ts +16 -7
  7. package/dist/actions/blueprints/read-blueprint.js +56 -10
  8. package/dist/actions/blueprints/stacks.d.ts +6 -6
  9. package/dist/actions/blueprints/stacks.js +10 -14
  10. package/dist/actions/blueprints/stash-asset.d.ts +1 -0
  11. package/dist/actions/blueprints/stash-asset.js +2 -5
  12. package/dist/actions/functions/invoke.d.ts +6 -2
  13. package/dist/actions/functions/invoke.js +9 -11
  14. package/dist/actions/functions/logs.d.ts +6 -1
  15. package/dist/actions/functions/logs.js +10 -10
  16. package/dist/commands/blueprints/deploy.js +19 -18
  17. package/dist/commands/blueprints/info.js +18 -38
  18. package/dist/commands/blueprints/logs.d.ts +0 -1
  19. package/dist/commands/blueprints/logs.js +12 -41
  20. package/dist/commands/blueprints/plan.js +14 -4
  21. package/dist/commands/functions/invoke.js +19 -2
  22. package/dist/commands/functions/logs.js +26 -2
  23. package/dist/config.js +6 -5
  24. package/dist/server/static/api.d.ts +10 -0
  25. package/dist/server/static/api.js +38 -43
  26. package/dist/server/static/components/api-base.d.ts +9 -0
  27. package/dist/server/static/components/api-base.js +6 -7
  28. package/dist/server/static/components/function-list.d.ts +1 -0
  29. package/dist/server/static/components/function-list.js +44 -48
  30. package/dist/server/static/components/network-spinner.d.ts +1 -0
  31. package/dist/server/static/components/network-spinner.js +6 -7
  32. package/dist/server/static/components/payload-panel.d.ts +1 -0
  33. package/dist/server/static/components/payload-panel.js +32 -36
  34. package/dist/server/static/components/response-panel.d.ts +1 -0
  35. package/dist/server/static/components/response-panel.js +50 -64
  36. package/dist/server/static/static/api.js +53 -0
  37. package/dist/server/static/static/components/api-base.js +10 -0
  38. package/dist/server/static/static/components/function-list.js +54 -0
  39. package/dist/server/static/static/components/network-spinner.js +71 -0
  40. package/dist/server/static/static/components/payload-panel.js +45 -0
  41. package/dist/server/static/static/components/response-panel.js +83 -0
  42. package/dist/server/static/static/vendor/vendor.bundle.js +26879 -0
  43. package/dist/server/static/vendor/vendor.bundle.d.ts +1815 -0
  44. package/dist/server/static/vendor/vendor.bundle.js +913 -1029
  45. package/dist/utils/child-process-wrapper.d.ts +1 -0
  46. package/dist/utils/display/blueprints-formatting.js +2 -2
  47. package/dist/utils/get-headers.d.ts +8 -0
  48. package/dist/utils/get-headers.js +9 -0
  49. package/dist/utils/get-token.d.ts +3 -1
  50. package/dist/utils/get-token.js +2 -2
  51. package/dist/utils/types.d.ts +44 -30
  52. package/dist/utils/types.js +8 -1
  53. package/dist/utils/vendor/parser-validator.d.ts +8 -0
  54. package/dist/utils/vendor/parser-validator.js +514 -0
  55. package/oclif.manifest.json +1 -11
  56. package/package.json +10 -11
  57. /package/dist/server/static/{components → static/components}/app.css +0 -0
  58. /package/dist/server/static/{index.html → static/index.html} +0 -0
  59. /package/dist/server/static/{sanity-logo-sm.svg → static/sanity-logo-sm.svg} +0 -0
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity COMMAND
21
21
  running command...
22
22
  $ sanity (--version)
23
- @sanity/runtime-cli/1.3.1 linux-x64 node-v22.14.0
23
+ @sanity/runtime-cli/1.4.0 linux-x64 node-v22.14.0
24
24
  $ sanity --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity COMMAND
@@ -64,7 +64,7 @@ EXAMPLES
64
64
  $ sanity blueprints deploy
65
65
  ```
66
66
 
67
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/blueprints/deploy.ts)_
67
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/blueprints/deploy.ts)_
68
68
 
69
69
  ## `sanity blueprints info`
70
70
 
@@ -81,7 +81,7 @@ EXAMPLES
81
81
  $ sanity blueprints info
82
82
  ```
83
83
 
84
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/blueprints/info.ts)_
84
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/blueprints/info.ts)_
85
85
 
86
86
  ## `sanity blueprints logs`
87
87
 
@@ -89,11 +89,10 @@ Display logs for a Blueprint stack
89
89
 
90
90
  ```
91
91
  USAGE
92
- $ sanity blueprints logs [-s <value>] [-w]
92
+ $ sanity blueprints logs [-w]
93
93
 
94
94
  FLAGS
95
- -s, --stack-id=<value> Stack ID to fetch logs for (optional if running in a blueprint directory)
96
- -w, --watch Watch for new logs (streaming mode)
95
+ -w, --watch Watch for new logs (streaming mode)
97
96
 
98
97
  DESCRIPTION
99
98
  Display logs for a Blueprint stack
@@ -101,12 +100,10 @@ DESCRIPTION
101
100
  EXAMPLES
102
101
  $ sanity blueprints logs
103
102
 
104
- $ sanity blueprints logs --stack-id <stack-id>
105
-
106
103
  $ sanity blueprints logs --watch
107
104
  ```
108
105
 
109
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/blueprints/logs.ts)_
106
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/blueprints/logs.ts)_
110
107
 
111
108
  ## `sanity blueprints plan`
112
109
 
@@ -123,7 +120,7 @@ EXAMPLES
123
120
  $ sanity blueprints plan
124
121
  ```
125
122
 
126
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/blueprints/plan.ts)_
123
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/blueprints/plan.ts)_
127
124
 
128
125
  ## `sanity functions dev`
129
126
 
@@ -143,7 +140,7 @@ EXAMPLES
143
140
  $ sanity functions dev --port 8974
144
141
  ```
145
142
 
146
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/functions/dev.ts)_
143
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/functions/dev.ts)_
147
144
 
148
145
  ## `sanity functions invoke ID`
149
146
 
@@ -169,7 +166,7 @@ EXAMPLES
169
166
  $ sanity functions invoke <ID> --file 'payload.json'
170
167
  ```
171
168
 
172
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/functions/invoke.ts)_
169
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/functions/invoke.ts)_
173
170
 
174
171
  ## `sanity functions logs ID`
175
172
 
@@ -189,7 +186,7 @@ EXAMPLES
189
186
  $ sanity functions logs <ID>
190
187
  ```
191
188
 
192
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/functions/logs.ts)_
189
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/functions/logs.ts)_
193
190
 
194
191
  ## `sanity functions test PATH`
195
192
 
@@ -218,7 +215,7 @@ EXAMPLES
218
215
  $ sanity functions test ./test.ts --data '{ "id": 1 }' --timeout 60
219
216
  ```
220
217
 
221
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v1.3.1/src/commands/functions/test.ts)_
218
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v1.4.0/src/commands/functions/test.ts)_
222
219
 
223
220
  ## `sanity help [COMMAND]`
224
221
 
@@ -1,4 +1,5 @@
1
1
  import type { BlueprintLog } from '../../utils/types.js';
2
+ export declare const logsUrl: string;
2
3
  export declare function getLogs(stackId: string, projectId: string, token: string): Promise<{
3
4
  logs: BlueprintLog[];
4
5
  ok: boolean;
@@ -1,8 +1,9 @@
1
1
  import { EventSource } from 'eventsource';
2
2
  import config from '../../config.js';
3
3
  const { blueprints } = config.server;
4
+ export const logsUrl = `${blueprints}vX/blueprints/logs`;
4
5
  export async function getLogs(stackId, projectId, token) {
5
- const response = await fetch(`${blueprints}/vX/blueprints/logs?stackId=${stackId}`, {
6
+ const response = await fetch(`${logsUrl}?stackId=${stackId}`, {
6
7
  headers: {
7
8
  Accept: 'application/json',
8
9
  'Content-Type': 'application/json',
@@ -20,7 +21,7 @@ export async function getLogs(stackId, projectId, token) {
20
21
  };
21
22
  }
22
23
  export function streamLogs(stackId, projectId, token, onLog, onOpen, onError) {
23
- const url = new URL(`${blueprints}/vX/blueprints/logs/stream`);
24
+ const url = new URL(`${logsUrl}/stream`);
24
25
  url.searchParams.append('stackId', stackId);
25
26
  const headers = {
26
27
  Authorization: `Bearer ${token}`,
@@ -1,4 +1,5 @@
1
1
  import type { BlueprintOperation } from '../../utils/types.js';
2
+ export declare const stacksUrl: string;
2
3
  export declare function getOperation({ stackId, operationId, projectId, }: {
3
4
  stackId: string;
4
5
  operationId: string;
@@ -1,5 +1,6 @@
1
1
  import config from '../../config.js';
2
2
  const { blueprints } = config.server;
3
+ export const stacksUrl = `${blueprints}vX/blueprints/stacks`;
3
4
  function getHeaders(projectId) {
4
5
  return {
5
6
  Authorization: `Bearer ${config.token}`,
@@ -9,7 +10,7 @@ function getHeaders(projectId) {
9
10
  };
10
11
  }
11
12
  export async function getOperation({ stackId, operationId, projectId, }) {
12
- const path = `${blueprints}/vX/blueprints/stacks/${stackId}/operations/${operationId}`;
13
+ const path = `${stacksUrl}/${stackId}/operations/${operationId}`;
13
14
  const response = await fetch(path, {
14
15
  method: 'GET',
15
16
  headers: getHeaders(projectId),
@@ -30,7 +31,7 @@ export async function getOperation({ stackId, operationId, projectId, }) {
30
31
  };
31
32
  }
32
33
  export async function listOperations({ stackId, projectId, }) {
33
- const path = `${blueprints}/vX/blueprints/stacks/${stackId}/operations`;
34
+ const path = `${stacksUrl}/${stackId}/operations`;
34
35
  const response = await fetch(path, {
35
36
  method: 'GET',
36
37
  headers: getHeaders(projectId),
@@ -1,7 +1,16 @@
1
- import type { Blueprint } from '../../utils/types.js';
2
- export default function readBlueprintOnDisk(): {
3
- document: Blueprint;
4
- path: string;
5
- fileName: string;
6
- extension: string;
7
- };
1
+ import type { Blueprint, BlueprintError, BlueprintResource, BlueprintStack } from '../../utils/types.js';
2
+ export default function readBlueprintOnDisk({ blueprintPath, getStack, }?: {
3
+ blueprintPath?: string;
4
+ getStack?: boolean;
5
+ }): Promise<{
6
+ fileInfo: {
7
+ path: string;
8
+ fileName: string;
9
+ extension: string;
10
+ };
11
+ parsedBlueprint: Blueprint;
12
+ errors: BlueprintError[];
13
+ projectResource?: BlueprintResource;
14
+ stackResource?: BlueprintResource;
15
+ deployedStack?: BlueprintStack;
16
+ }>;
@@ -1,6 +1,10 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { extname, join } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
+ import { getStackByName } from '../../actions/blueprints/stacks.js';
5
+ import { BlueprintErrorType } from '../../utils/types.js';
6
+ // @ts-ignore - this is currently untyped
7
+ import blueprintParserValidator from '../../utils/vendor/parser-validator.js';
4
8
  const SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER = [
5
9
  'blueprint.json',
6
10
  // 'blueprint.js',
@@ -8,7 +12,13 @@ const SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER = [
8
12
  // 'blueprint.cjs',
9
13
  // 'blueprint.ts',
10
14
  ];
11
- function findBlueprintFile() {
15
+ function findBlueprintFile(blueprintPath) {
16
+ if (blueprintPath) {
17
+ if (existsSync(blueprintPath)) {
18
+ return { path: blueprintPath, fileName: blueprintPath, extension: extname(blueprintPath) };
19
+ }
20
+ throw Error(`Blueprint file not found: ${blueprintPath}`);
21
+ }
12
22
  for (const fileName of SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER) {
13
23
  const filePath = join(cwd(), fileName);
14
24
  if (existsSync(filePath)) {
@@ -17,17 +27,15 @@ function findBlueprintFile() {
17
27
  }
18
28
  return null;
19
29
  }
20
- export default function readBlueprintOnDisk() {
30
+ export default async function readBlueprintOnDisk({ blueprintPath, getStack, } = {}) {
21
31
  try {
22
- const blueprintPath = findBlueprintFile();
23
- if (!blueprintPath)
32
+ const blueprintFile = findBlueprintFile(blueprintPath);
33
+ if (!blueprintFile)
24
34
  throw Error('Could not find Blueprint file');
25
- const { path, fileName, extension } = blueprintPath;
26
- let readBlueprint;
27
- let blueprintJson;
35
+ const { path, fileName, extension } = blueprintFile;
36
+ let blueprintString;
28
37
  if (extension === '.json') {
29
- readBlueprint = readFileSync(path, 'utf8').toString();
30
- blueprintJson = JSON.parse(readBlueprint);
38
+ blueprintString = readFileSync(path, 'utf8').toString();
31
39
  // } else if (extension === '.js' || extension === '.mjs') {
32
40
  // const blueprintModule = require(path)
33
41
  // blueprintJson = blueprintModule.default
@@ -35,7 +43,45 @@ export default function readBlueprintOnDisk() {
35
43
  else {
36
44
  throw Error(`Unsupported blueprint file extension: ${extension}`);
37
45
  }
38
- return { document: blueprintJson, path, fileName, extension };
46
+ const parsed = blueprintParserValidator(JSON.parse(blueprintString));
47
+ const { blueprint: parsedBlueprint } = parsed;
48
+ const errors = parsed.errors || [];
49
+ const projectResource = parsedBlueprint.resources.find((r) => r.type === 'sanity.project');
50
+ const stackResource = parsedBlueprint.resources.find((r) => r.type === 'sanity.blueprints.stack');
51
+ if (!projectResource) {
52
+ errors.push({
53
+ message: 'Blueprint is missing a project resource',
54
+ type: BlueprintErrorType.MissingProject,
55
+ });
56
+ }
57
+ if (!stackResource) {
58
+ errors.push({
59
+ message: 'Blueprint is missing a stack resource',
60
+ type: BlueprintErrorType.MissingStack,
61
+ });
62
+ }
63
+ let deployedStack;
64
+ if (getStack && projectResource && stackResource) {
65
+ const { stack } = await getStackByName({
66
+ name: stackResource.name,
67
+ projectId: projectResource.id,
68
+ });
69
+ if (!stack) {
70
+ errors.push({
71
+ message: 'Stack not found',
72
+ type: BlueprintErrorType.InvalidStack,
73
+ });
74
+ }
75
+ deployedStack = stack;
76
+ }
77
+ return {
78
+ fileInfo: { path, fileName, extension },
79
+ errors,
80
+ projectResource,
81
+ stackResource,
82
+ deployedStack,
83
+ parsedBlueprint,
84
+ };
39
85
  }
40
86
  catch (err) {
41
87
  throw Error(`Unable to parse Blueprint file: ${err}`);
@@ -1,12 +1,13 @@
1
1
  import type { BlueprintJob } from '../../utils/types.js';
2
- declare function listStacks({ projectId }: {
2
+ export declare const stacksUrl: string;
3
+ export declare function listStacks({ projectId }: {
3
4
  projectId: string;
4
5
  }): Promise<{
5
6
  ok: boolean;
6
7
  error: any;
7
8
  stacks: any;
8
9
  }>;
9
- declare function getStackByName({ name, projectId }: {
10
+ export declare function getStackByName({ name, projectId }: {
10
11
  name: string;
11
12
  projectId: string;
12
13
  }): Promise<{
@@ -22,7 +23,7 @@ declare function getStackByName({ name, projectId }: {
22
23
  stackId: any;
23
24
  availableStacks?: undefined;
24
25
  }>;
25
- declare function getStack({ stackId, projectId }: {
26
+ export declare function getStack({ stackId, projectId }: {
26
27
  stackId: string;
27
28
  projectId: string;
28
29
  }): Promise<{
@@ -30,7 +31,7 @@ declare function getStack({ stackId, projectId }: {
30
31
  error: any;
31
32
  stack: any;
32
33
  }>;
33
- declare function createStack({ blueprint, projectId }: {
34
+ export declare function createStack({ blueprint, projectId, }: {
34
35
  blueprint: BlueprintJob;
35
36
  projectId: string;
36
37
  }): Promise<{
@@ -38,7 +39,7 @@ declare function createStack({ blueprint, projectId }: {
38
39
  error: any;
39
40
  stack: any;
40
41
  }>;
41
- declare function updateStack({ stackId, blueprint, projectId, }: {
42
+ export declare function updateStack({ stackId, blueprint, projectId, }: {
42
43
  stackId: string;
43
44
  blueprint: BlueprintJob;
44
45
  projectId: string;
@@ -47,4 +48,3 @@ declare function updateStack({ stackId, blueprint, projectId, }: {
47
48
  error: any;
48
49
  stack: any;
49
50
  }>;
50
- export { listStacks, getStack, createStack, updateStack, getStackByName };
@@ -1,5 +1,6 @@
1
1
  import config from '../../config.js';
2
2
  const { blueprints } = config.server;
3
+ export const stacksUrl = `${blueprints}vX/blueprints/stacks`;
3
4
  function getHeaders(projectId) {
4
5
  return {
5
6
  Authorization: `Bearer ${config.token}`,
@@ -8,9 +9,8 @@ function getHeaders(projectId) {
8
9
  'X-Sanity-Scope-Id': projectId,
9
10
  };
10
11
  }
11
- async function listStacks({ projectId }) {
12
- const path = `${blueprints}/vX/blueprints/stacks`;
13
- const response = await fetch(path, {
12
+ export async function listStacks({ projectId }) {
13
+ const response = await fetch(stacksUrl, {
14
14
  method: 'GET',
15
15
  headers: getHeaders(projectId),
16
16
  });
@@ -21,7 +21,7 @@ async function listStacks({ projectId }) {
21
21
  stacks,
22
22
  };
23
23
  }
24
- async function getStackByName({ name, projectId }) {
24
+ export async function getStackByName({ name, projectId }) {
25
25
  const { ok, stacks, error } = await listStacks({ projectId });
26
26
  if (!ok || !stacks) {
27
27
  return {
@@ -49,9 +49,8 @@ async function getStackByName({ name, projectId }) {
49
49
  stackId: foundStack.id,
50
50
  };
51
51
  }
52
- async function getStack({ stackId, projectId }) {
53
- const path = `${blueprints}/vX/blueprints/stacks/${stackId}`;
54
- const response = await fetch(path, {
52
+ export async function getStack({ stackId, projectId }) {
53
+ const response = await fetch(`${stacksUrl}/${stackId}`, {
55
54
  method: 'GET',
56
55
  headers: getHeaders(projectId),
57
56
  });
@@ -62,9 +61,8 @@ async function getStack({ stackId, projectId }) {
62
61
  stack,
63
62
  };
64
63
  }
65
- async function createStack({ blueprint, projectId }) {
66
- const path = `${blueprints}/vX/blueprints/stacks`;
67
- const response = await fetch(path, {
64
+ export async function createStack({ blueprint, projectId, }) {
65
+ const response = await fetch(stacksUrl, {
68
66
  method: 'POST',
69
67
  headers: getHeaders(projectId),
70
68
  body: JSON.stringify(blueprint),
@@ -76,9 +74,8 @@ async function createStack({ blueprint, projectId }) {
76
74
  stack,
77
75
  };
78
76
  }
79
- async function updateStack({ stackId, blueprint, projectId, }) {
80
- const path = `${blueprints}/vX/blueprints/stacks/${stackId}`;
81
- const response = await fetch(path, {
77
+ export async function updateStack({ stackId, blueprint, projectId, }) {
78
+ const response = await fetch(`${stacksUrl}/${stackId}`, {
82
79
  method: 'PUT',
83
80
  headers: getHeaders(projectId),
84
81
  body: JSON.stringify(blueprint),
@@ -90,4 +87,3 @@ async function updateStack({ stackId, blueprint, projectId, }) {
90
87
  stack,
91
88
  };
92
89
  }
93
- export { listStacks, getStack, createStack, updateStack, getStackByName };
@@ -1,4 +1,5 @@
1
1
  import type { BlueprintResource } from '../../utils/types.js';
2
+ export declare const stashUrl: string;
2
3
  export declare function stashAsset({ resource, projectId, }: {
3
4
  resource: BlueprintResource;
4
5
  projectId: string;
@@ -4,6 +4,7 @@ import { cwd } from 'node:process';
4
4
  import JSZip from 'jszip';
5
5
  import config from '../../config.js';
6
6
  const { blueprints } = config.server;
7
+ export const stashUrl = `${blueprints}vX/blueprints/assets/stash`;
7
8
  function getHeaders(projectId) {
8
9
  return {
9
10
  Authorization: `Bearer ${config.token}`,
@@ -14,15 +15,12 @@ function getHeaders(projectId) {
14
15
  }
15
16
  export async function stashAsset({ resource, projectId, }) {
16
17
  try {
17
- // Read the function source
18
18
  const source = await fs.readFileSync(path.join(cwd(), resource.src), 'utf8');
19
- // Create zip with function source
20
19
  const zip = new JSZip();
21
20
  zip.file('index.js', source);
22
21
  const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' });
23
22
  const base64Zip = zipBuffer.toString('base64');
24
- // Stash the asset
25
- const assetResponse = await fetch(`${blueprints}/vX/blueprints/assets/stash`, {
23
+ const assetResponse = await fetch(stashUrl, {
26
24
  method: 'POST',
27
25
  headers: getHeaders(projectId),
28
26
  body: JSON.stringify({
@@ -31,7 +29,6 @@ export async function stashAsset({ resource, projectId, }) {
31
29
  }),
32
30
  });
33
31
  const assetJson = await assetResponse.json();
34
- // console.debug('ASSET RESPONSE:', assetJson)
35
32
  if (assetResponse.ok) {
36
33
  return { success: true, assetId: assetJson.id };
37
34
  }
@@ -1,2 +1,6 @@
1
- import type { PayloadOptions } from '../../utils/types.js';
2
- export declare function invoke(id: string, options: PayloadOptions): Promise<object>;
1
+ import type { AuthParams, PayloadOptions } from '../../utils/types.js';
2
+ export declare function invoke(id: string, options: PayloadOptions, auth: AuthParams): Promise<{
3
+ ok: boolean;
4
+ error: any;
5
+ json: any;
6
+ }>;
@@ -1,20 +1,18 @@
1
1
  import config from '../../config.js';
2
2
  import buildPayload from '../../utils/build-payload.js';
3
+ import getHeaders from '../../utils/get-headers.js';
3
4
  const { functions } = config.server;
4
- function getHeaders() {
5
- return {
6
- Authorization: `Bearer ${config.token}`,
7
- 'Content-Type': 'application/json',
8
- Accept: 'application/json',
9
- };
10
- }
11
- export async function invoke(id, options) {
5
+ export async function invoke(id, options, auth) {
12
6
  const payload = buildPayload(options);
13
- const response = await fetch(`${functions}/vX/functions/${id}/invoke`, {
7
+ const response = await fetch(`${functions}vX/functions/${id}/invoke`, {
14
8
  body: JSON.stringify({ data: payload }),
15
- headers: getHeaders(),
9
+ headers: getHeaders(auth),
16
10
  method: 'POST',
17
11
  });
18
12
  const json = await response.json();
19
- return json;
13
+ return {
14
+ ok: response.ok,
15
+ error: response.ok ? null : json?.error?.message,
16
+ json: response.ok ? json : undefined,
17
+ };
20
18
  }
@@ -1 +1,6 @@
1
- export declare function logs(id: string, token: string): Promise<object>;
1
+ import type { AuthParams } from '../../utils/types.js';
2
+ export declare function logs(id: string, auth: AuthParams): Promise<{
3
+ ok: boolean;
4
+ error: any;
5
+ logs: any;
6
+ }>;
@@ -1,15 +1,15 @@
1
1
  import config from '../../config.js';
2
+ import getHeaders from '../../utils/get-headers.js';
2
3
  const { functions } = config.server;
3
- export async function logs(id, token) {
4
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
5
- const response = await fetch(`${functions}/vX/functions/${id}/logs`, {
6
- headers: {
7
- Accept: 'application/json',
8
- 'Content-Type': 'application/json',
9
- Authorization: `Bearer ${token}`,
10
- },
4
+ export async function logs(id, auth) {
5
+ const response = await fetch(`${functions}vX/functions/${id}/logs`, {
6
+ headers: getHeaders(auth),
11
7
  method: 'GET',
12
8
  });
13
- const json = await response.json();
14
- return json;
9
+ const logs = await response.json();
10
+ return {
11
+ ok: response.ok,
12
+ error: response.ok ? null : logs?.error?.message,
13
+ logs: response.ok ? logs : [],
14
+ };
15
15
  }
@@ -1,6 +1,6 @@
1
1
  import { Command } from '@oclif/core';
2
2
  import readBlueprintOnDisk from '../../actions/blueprints/read-blueprint.js';
3
- import { createStack, getStackByName, updateStack } from '../../actions/blueprints/stacks.js';
3
+ import { createStack, updateStack } from '../../actions/blueprints/stacks.js';
4
4
  import { stashAsset } from '../../actions/blueprints/stash-asset.js';
5
5
  import { green, red, yellow } from '../../utils/display/colors.js';
6
6
  import Spinner from '../../utils/spinner.js';
@@ -8,10 +8,21 @@ export default class Deploy extends Command {
8
8
  static description = 'Deploy a Blueprint';
9
9
  static examples = ['<%= config.bin %> <%= command.id %>'];
10
10
  async run() {
11
- const { document } = readBlueprintOnDisk();
12
- const { displayName, name, projectId, resources } = document;
11
+ const { errors, projectResource, stackResource, parsedBlueprint: { resources }, deployedStack, } = await readBlueprintOnDisk({ getStack: true });
12
+ if (errors.length > 0) {
13
+ // printErrors(errors) // TODO: error printer in formatting
14
+ this.log('Blueprint parse errors:');
15
+ console.dir(errors, { depth: null });
16
+ return;
17
+ }
18
+ if (!projectResource)
19
+ this.error('Blueprint must contain a project resource'); // returns
20
+ if (!stackResource)
21
+ this.error('Blueprint must contain a stack resource'); // returns
22
+ const { id: projectId } = projectResource;
23
+ const { name } = stackResource;
13
24
  const s = new Spinner();
14
- const functionResources = resources.filter((r) => r.kind === 'function');
25
+ const functionResources = resources.filter((r) => r.type === 'function');
15
26
  // First stash all function assets
16
27
  if (functionResources.length > 0) {
17
28
  for (const resource of functionResources) {
@@ -31,33 +42,23 @@ export default class Deploy extends Command {
31
42
  }
32
43
  }
33
44
  }
34
- s.start('Looking for existing stack...');
35
- const { ok, error, stackId: existingStackId, } = await getStackByName({
36
- name,
37
- projectId,
38
- });
39
- if (!ok) {
40
- s.stop(`${red('Failed')} to list stacks`);
41
- this.log(`Error: ${error || 'Unknown error'}`);
42
- return;
43
- }
44
45
  const blueprint = {
45
46
  name,
46
47
  projectId,
47
48
  document: { resources },
48
49
  };
49
50
  this.debug('BLUEPRINT DOCUMENT:', blueprint);
50
- const { ok: deployOk, stack, error: deployError, } = existingStackId
51
- ? await updateStack({ stackId: existingStackId, blueprint, projectId })
51
+ const { ok: deployOk, stack, error: deployError, } = deployedStack
52
+ ? await updateStack({ stackId: deployedStack.id, blueprint, projectId })
52
53
  : await createStack({ blueprint, projectId });
53
54
  this.debug('STACK RESPONSE:', stack);
54
55
  if (deployOk) {
55
- s.stop(`${green('Success!')} Stack ${existingStackId ? 'updated' : 'created'} <${yellow(stack.id)}>`);
56
+ s.stop(`${green('Success!')} Stack ${deployedStack ? 'updated' : 'created'} <${yellow(stack.id)}>`);
56
57
  this.log('\nUse `sanity blueprints info` to check deployment status');
57
58
  }
58
59
  else {
59
60
  this.debug('STACK ERROR RESPONSE:', stack);
60
- s.stop(`${red('Failed')} to ${existingStackId ? 'update' : 'create'} stack`);
61
+ s.stop(`${red('Failed')} to ${deployedStack ? 'update' : 'create'} stack`);
61
62
  this.log(`Error: ${deployError || 'Unknown error'}`);
62
63
  }
63
64
  }