@sanity/runtime-cli 2.1.1 → 2.3.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.
- package/README.md +30 -22
- package/dist/actions/blueprints/assets.d.ts +3 -3
- package/dist/actions/blueprints/assets.js +3 -10
- package/dist/actions/blueprints/blueprint.d.ts +3 -2
- package/dist/actions/blueprints/blueprint.js +3 -3
- package/dist/actions/blueprints/logs.d.ts +3 -3
- package/dist/actions/blueprints/logs.js +5 -14
- package/dist/actions/blueprints/operations.d.ts +5 -5
- package/dist/actions/blueprints/operations.js +5 -12
- package/dist/actions/blueprints/projects.d.ts +3 -1
- package/dist/actions/blueprints/projects.js +6 -9
- package/dist/actions/blueprints/stacks.d.ts +11 -12
- package/dist/actions/blueprints/stacks.js +13 -19
- package/dist/actions/functions/logs.d.ts +6 -1
- package/dist/actions/functions/logs.js +4 -2
- package/dist/commands/blueprints/add.js +1 -1
- package/dist/commands/blueprints/config.js +5 -2
- package/dist/commands/blueprints/deploy.js +7 -4
- package/dist/commands/blueprints/info.js +5 -2
- package/dist/commands/blueprints/init.js +3 -1
- package/dist/commands/blueprints/logs.js +6 -4
- package/dist/commands/blueprints/plan.js +3 -2
- package/dist/commands/blueprints/stacks.js +4 -1
- package/dist/commands/functions/env/add.js +1 -1
- package/dist/commands/functions/env/remove.js +1 -1
- package/dist/commands/functions/invoke.js +3 -3
- package/dist/commands/functions/logs.d.ts +4 -0
- package/dist/commands/functions/logs.js +38 -12
- package/dist/commands/functions/test.js +3 -3
- package/dist/config.js +2 -1
- package/dist/server/static/vendor/vendor.bundle.js +13 -12
- package/dist/utils/format-error.d.ts +4 -0
- package/dist/utils/format-error.js +9 -0
- package/oclif.manifest.json +29 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
|
|
|
20
20
|
$ sanity-run COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ sanity-run (--version)
|
|
23
|
-
@sanity/runtime-cli/2.
|
|
23
|
+
@sanity/runtime-cli/2.3.0 linux-x64 node-v22.14.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -63,7 +63,7 @@ EXAMPLES
|
|
|
63
63
|
$ sanity-run blueprints add function
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
66
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/add.ts)_
|
|
67
67
|
|
|
68
68
|
## `sanity-run blueprints config`
|
|
69
69
|
|
|
@@ -85,7 +85,7 @@ EXAMPLES
|
|
|
85
85
|
$ sanity-run blueprints config --edit
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
88
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/config.ts)_
|
|
89
89
|
|
|
90
90
|
## `sanity-run blueprints deploy`
|
|
91
91
|
|
|
@@ -102,7 +102,7 @@ EXAMPLES
|
|
|
102
102
|
$ sanity-run blueprints deploy
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
105
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/deploy.ts)_
|
|
106
106
|
|
|
107
107
|
## `sanity-run blueprints info`
|
|
108
108
|
|
|
@@ -124,7 +124,7 @@ EXAMPLES
|
|
|
124
124
|
$ sanity-run blueprints info --id abc123
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
127
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/info.ts)_
|
|
128
128
|
|
|
129
129
|
## `sanity-run blueprints init`
|
|
130
130
|
|
|
@@ -141,7 +141,7 @@ EXAMPLES
|
|
|
141
141
|
$ sanity-run blueprints init
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
144
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/init.ts)_
|
|
145
145
|
|
|
146
146
|
## `sanity-run blueprints logs`
|
|
147
147
|
|
|
@@ -163,7 +163,7 @@ EXAMPLES
|
|
|
163
163
|
$ sanity-run blueprints logs --watch
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
166
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/logs.ts)_
|
|
167
167
|
|
|
168
168
|
## `sanity-run blueprints plan`
|
|
169
169
|
|
|
@@ -180,7 +180,7 @@ EXAMPLES
|
|
|
180
180
|
$ sanity-run blueprints plan
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
183
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/plan.ts)_
|
|
184
184
|
|
|
185
185
|
## `sanity-run blueprints stacks`
|
|
186
186
|
|
|
@@ -197,7 +197,7 @@ EXAMPLES
|
|
|
197
197
|
$ sanity-run blueprints stacks
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
200
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/blueprints/stacks.ts)_
|
|
201
201
|
|
|
202
202
|
## `sanity-run functions dev`
|
|
203
203
|
|
|
@@ -217,7 +217,7 @@ EXAMPLES
|
|
|
217
217
|
$ sanity-run functions dev --port 8974
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
220
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/dev.ts)_
|
|
221
221
|
|
|
222
222
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
223
223
|
|
|
@@ -239,7 +239,7 @@ EXAMPLES
|
|
|
239
239
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
242
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/env/add.ts)_
|
|
243
243
|
|
|
244
244
|
## `sanity-run functions env remove NAME KEY`
|
|
245
245
|
|
|
@@ -260,7 +260,7 @@ EXAMPLES
|
|
|
260
260
|
$ sanity-run functions env remove MyFunction API_URL
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
263
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/env/remove.ts)_
|
|
264
264
|
|
|
265
265
|
## `sanity-run functions invoke NAME`
|
|
266
266
|
|
|
@@ -281,12 +281,12 @@ DESCRIPTION
|
|
|
281
281
|
Invoke a remote Sanity Function
|
|
282
282
|
|
|
283
283
|
EXAMPLES
|
|
284
|
-
$ sanity-run functions invoke <
|
|
284
|
+
$ sanity-run functions invoke <name> --data '{ "id": 1 }'
|
|
285
285
|
|
|
286
|
-
$ sanity-run functions invoke <
|
|
286
|
+
$ sanity-run functions invoke <name> --file 'payload.json'
|
|
287
287
|
```
|
|
288
288
|
|
|
289
|
-
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
289
|
+
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/invoke.ts)_
|
|
290
290
|
|
|
291
291
|
## `sanity-run functions logs NAME`
|
|
292
292
|
|
|
@@ -294,19 +294,27 @@ Retrieve logs for a Sanity Function
|
|
|
294
294
|
|
|
295
295
|
```
|
|
296
296
|
USAGE
|
|
297
|
-
$ sanity-run functions logs NAME
|
|
297
|
+
$ sanity-run functions logs NAME [-l <value>] [-j]
|
|
298
298
|
|
|
299
299
|
ARGUMENTS
|
|
300
300
|
NAME The name of the Sanity Function
|
|
301
301
|
|
|
302
|
+
FLAGS
|
|
303
|
+
-j, --json Return logs in JSON format
|
|
304
|
+
-l, --limit=<value> [default: 50] Total number of log entries to retrieve
|
|
305
|
+
|
|
302
306
|
DESCRIPTION
|
|
303
307
|
Retrieve logs for a Sanity Function
|
|
304
308
|
|
|
305
309
|
EXAMPLES
|
|
306
|
-
$ sanity-run functions logs <
|
|
310
|
+
$ sanity-run functions logs <name>
|
|
311
|
+
|
|
312
|
+
$ sanity-run functions logs <name> --json
|
|
313
|
+
|
|
314
|
+
$ sanity-run functions logs <name> --limit 100
|
|
307
315
|
```
|
|
308
316
|
|
|
309
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
317
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/logs.ts)_
|
|
310
318
|
|
|
311
319
|
## `sanity-run functions test NAME`
|
|
312
320
|
|
|
@@ -328,14 +336,14 @@ DESCRIPTION
|
|
|
328
336
|
Invoke a local Sanity Function
|
|
329
337
|
|
|
330
338
|
EXAMPLES
|
|
331
|
-
$ sanity-run functions test
|
|
339
|
+
$ sanity-run functions test <name> --data '{ "id": 1 }'
|
|
332
340
|
|
|
333
|
-
$ sanity-run functions test
|
|
341
|
+
$ sanity-run functions test <name> --file 'payload.json'
|
|
334
342
|
|
|
335
|
-
$ sanity-run functions test
|
|
343
|
+
$ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
|
|
336
344
|
```
|
|
337
345
|
|
|
338
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
346
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.3.0/src/commands/functions/test.ts)_
|
|
339
347
|
|
|
340
348
|
## `sanity-run help [COMMAND]`
|
|
341
349
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { BlueprintResource } from '../../utils/types.js';
|
|
1
|
+
import type { AuthParams, BlueprintResource } from '../../utils/types.js';
|
|
2
2
|
export declare const stashUrl: string;
|
|
3
|
-
export declare function stashAsset({ resource,
|
|
3
|
+
export declare function stashAsset({ resource, auth, }: {
|
|
4
4
|
resource: BlueprintResource;
|
|
5
|
-
|
|
5
|
+
auth: AuthParams;
|
|
6
6
|
}): Promise<{
|
|
7
7
|
success: boolean;
|
|
8
8
|
assetId: any;
|
|
@@ -3,17 +3,10 @@ import path from 'node:path';
|
|
|
3
3
|
import { cwd } from 'node:process';
|
|
4
4
|
import JSZip from 'jszip';
|
|
5
5
|
import config from '../../config.js';
|
|
6
|
+
import getHeaders from '../../utils/get-headers.js';
|
|
6
7
|
const { blueprints } = config.server;
|
|
7
8
|
export const stashUrl = `${blueprints}vX/blueprints/assets/stash`;
|
|
8
|
-
function
|
|
9
|
-
return {
|
|
10
|
-
Authorization: `Bearer ${config.token}`,
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
|
-
'X-Sanity-Scope-Type': 'project',
|
|
13
|
-
'X-Sanity-Scope-Id': projectId,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export async function stashAsset({ resource, projectId, }) {
|
|
9
|
+
export async function stashAsset({ resource, auth, }) {
|
|
17
10
|
try {
|
|
18
11
|
const source = await fs.readFileSync(path.join(cwd(), resource.src), 'utf8');
|
|
19
12
|
const zip = new JSZip();
|
|
@@ -22,7 +15,7 @@ export async function stashAsset({ resource, projectId, }) {
|
|
|
22
15
|
const base64Zip = zipBuffer.toString('base64');
|
|
23
16
|
const assetResponse = await fetch(stashUrl, {
|
|
24
17
|
method: 'POST',
|
|
25
|
-
headers: getHeaders(
|
|
18
|
+
headers: getHeaders(auth),
|
|
26
19
|
body: JSON.stringify({
|
|
27
20
|
file: base64Zip,
|
|
28
21
|
filename: `${resource.name}.zip`,
|
|
@@ -3,14 +3,15 @@ export declare const DEFAULT_BLUEPRINT_CONTENT: {
|
|
|
3
3
|
blueprintVersion: string;
|
|
4
4
|
resources: never[];
|
|
5
5
|
};
|
|
6
|
-
export declare function findBlueprintFile(blueprintPath
|
|
6
|
+
export declare function findBlueprintFile(blueprintPath?: string): {
|
|
7
7
|
path: string;
|
|
8
8
|
fileName: string;
|
|
9
9
|
extension: string;
|
|
10
10
|
} | null;
|
|
11
|
-
export declare function readBlueprintOnDisk({ blueprintPath, getStack, }?: {
|
|
11
|
+
export declare function readBlueprintOnDisk({ blueprintPath, getStack, token, }?: {
|
|
12
12
|
blueprintPath?: string;
|
|
13
13
|
getStack?: boolean;
|
|
14
|
+
token?: string;
|
|
14
15
|
}): Promise<{
|
|
15
16
|
fileInfo: {
|
|
16
17
|
path: string;
|
|
@@ -31,7 +31,7 @@ export function findBlueprintFile(blueprintPath) {
|
|
|
31
31
|
}
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
|
-
export async function readBlueprintOnDisk({ blueprintPath, getStack, } = {}) {
|
|
34
|
+
export async function readBlueprintOnDisk({ blueprintPath, getStack, token, } = {}) {
|
|
35
35
|
try {
|
|
36
36
|
const blueprintFile = findBlueprintFile(blueprintPath);
|
|
37
37
|
if (!blueprintFile)
|
|
@@ -115,8 +115,8 @@ export async function readBlueprintOnDisk({ blueprintPath, getStack, } = {}) {
|
|
|
115
115
|
stackId = stackResource.id;
|
|
116
116
|
}
|
|
117
117
|
let deployedStack;
|
|
118
|
-
if (getStack &&
|
|
119
|
-
const { stack } = await getStackById({ stackId, projectId });
|
|
118
|
+
if (getStack && token && stackId && projectId) {
|
|
119
|
+
const { stack } = await getStackById({ stackId, auth: { token, projectId } });
|
|
120
120
|
if (!stack) {
|
|
121
121
|
errors.push({
|
|
122
122
|
message: 'Stack not found',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BlueprintLog } from '../../utils/types.js';
|
|
1
|
+
import type { AuthParams, BlueprintLog } from '../../utils/types.js';
|
|
2
2
|
export declare const logsUrl: string;
|
|
3
|
-
export declare function getLogs(stackId: string,
|
|
3
|
+
export declare function getLogs(stackId: string, auth: AuthParams): Promise<{
|
|
4
4
|
logs: BlueprintLog[];
|
|
5
5
|
ok: boolean;
|
|
6
6
|
error: string | null;
|
|
@@ -8,4 +8,4 @@ export declare function getLogs(stackId: string, projectId: string, token: strin
|
|
|
8
8
|
export declare function findNewestLogTimestamp(logs: BlueprintLog[]): number;
|
|
9
9
|
export declare function isNewerLog(log: BlueprintLog, timestamp: number): boolean;
|
|
10
10
|
export declare function getRecentLogs(logs: BlueprintLog[], limit?: number): BlueprintLog[];
|
|
11
|
-
export declare function streamLogs(stackId: string,
|
|
11
|
+
export declare function streamLogs(stackId: string, auth: AuthParams, onLog: (log: BlueprintLog) => void, onOpen: () => void, onError: (error: string) => void): () => void;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { EventSource } from 'eventsource';
|
|
2
2
|
import config from '../../config.js';
|
|
3
|
+
import getHeaders from '../../utils/get-headers.js';
|
|
3
4
|
const { blueprints } = config.server;
|
|
4
5
|
export const logsUrl = `${blueprints}vX/blueprints/logs`;
|
|
5
|
-
export async function getLogs(stackId,
|
|
6
|
+
export async function getLogs(stackId, auth) {
|
|
6
7
|
const url = new URL(logsUrl);
|
|
7
8
|
url.searchParams.append('stackId', stackId);
|
|
8
9
|
const response = await fetch(url.toString(), {
|
|
9
|
-
headers:
|
|
10
|
-
Accept: 'application/json',
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
|
-
Authorization: `Bearer ${token}`,
|
|
13
|
-
'X-Sanity-Scope-Type': 'project',
|
|
14
|
-
'X-Sanity-Scope-Id': projectId,
|
|
15
|
-
},
|
|
10
|
+
headers: getHeaders(auth),
|
|
16
11
|
method: 'GET',
|
|
17
12
|
});
|
|
18
13
|
const result = await response.json();
|
|
@@ -46,14 +41,10 @@ export function getRecentLogs(logs, limit = 10) {
|
|
|
46
41
|
return sortedLogs.slice(-limit);
|
|
47
42
|
}
|
|
48
43
|
// Create streaming logs connection
|
|
49
|
-
export function streamLogs(stackId,
|
|
44
|
+
export function streamLogs(stackId, auth, onLog, onOpen, onError) {
|
|
50
45
|
const url = new URL(`${logsUrl}/stream`);
|
|
51
46
|
url.searchParams.append('stackId', stackId);
|
|
52
|
-
const headers =
|
|
53
|
-
Authorization: `Bearer ${token}`,
|
|
54
|
-
'X-Sanity-Scope-Type': 'project',
|
|
55
|
-
'X-Sanity-Scope-Id': projectId,
|
|
56
|
-
};
|
|
47
|
+
const headers = getHeaders(auth);
|
|
57
48
|
const eventSource = new EventSource(url.toString(), {
|
|
58
49
|
fetch: (input, init) => fetch(input, {
|
|
59
50
|
...init,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { BlueprintOperation } from '../../utils/types.js';
|
|
1
|
+
import type { AuthParams, BlueprintOperation } from '../../utils/types.js';
|
|
2
2
|
export declare const stacksUrl: string;
|
|
3
|
-
export declare function getOperation({ stackId, operationId,
|
|
3
|
+
export declare function getOperation({ stackId, operationId, auth, }: {
|
|
4
4
|
stackId: string;
|
|
5
5
|
operationId: string;
|
|
6
|
-
|
|
6
|
+
auth: AuthParams;
|
|
7
7
|
}): Promise<{
|
|
8
8
|
ok: boolean;
|
|
9
9
|
error: string | null;
|
|
10
10
|
operation: BlueprintOperation | null;
|
|
11
11
|
}>;
|
|
12
|
-
export declare function listOperations({ stackId,
|
|
12
|
+
export declare function listOperations({ stackId, auth, }: {
|
|
13
13
|
stackId: string;
|
|
14
|
-
|
|
14
|
+
auth: AuthParams;
|
|
15
15
|
}): Promise<{
|
|
16
16
|
ok: boolean;
|
|
17
17
|
error: string | null;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import config from '../../config.js';
|
|
2
|
+
import getHeaders from '../../utils/get-headers.js';
|
|
2
3
|
const { blueprints } = config.server;
|
|
3
4
|
export const stacksUrl = `${blueprints}vX/blueprints/stacks`;
|
|
4
|
-
function
|
|
5
|
-
return {
|
|
6
|
-
Authorization: `Bearer ${config.token}`,
|
|
7
|
-
'Content-Type': 'application/json',
|
|
8
|
-
'X-Sanity-Scope-Type': 'project',
|
|
9
|
-
'X-Sanity-Scope-Id': projectId,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export async function getOperation({ stackId, operationId, projectId, }) {
|
|
5
|
+
export async function getOperation({ stackId, operationId, auth, }) {
|
|
13
6
|
const path = `${stacksUrl}/${stackId}/operations/${operationId}`;
|
|
14
7
|
const response = await fetch(path, {
|
|
15
8
|
method: 'GET',
|
|
16
|
-
headers: getHeaders(
|
|
9
|
+
headers: getHeaders(auth),
|
|
17
10
|
});
|
|
18
11
|
if (!response.ok) {
|
|
19
12
|
const errorText = await response.text();
|
|
@@ -30,11 +23,11 @@ export async function getOperation({ stackId, operationId, projectId, }) {
|
|
|
30
23
|
operation,
|
|
31
24
|
};
|
|
32
25
|
}
|
|
33
|
-
export async function listOperations({ stackId,
|
|
26
|
+
export async function listOperations({ stackId, auth, }) {
|
|
34
27
|
const path = `${stacksUrl}/${stackId}/operations`;
|
|
35
28
|
const response = await fetch(path, {
|
|
36
29
|
method: 'GET',
|
|
37
|
-
headers: getHeaders(
|
|
30
|
+
headers: getHeaders(auth),
|
|
38
31
|
});
|
|
39
32
|
if (!response.ok) {
|
|
40
33
|
const errorText = await response.text();
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import config from '../../config.js';
|
|
2
|
-
const { apiUrl
|
|
3
|
-
function getHeaders() {
|
|
4
|
-
return {
|
|
5
|
-
Authorization: `Bearer ${token}`,
|
|
6
|
-
'Content-Type': 'application/json',
|
|
7
|
-
};
|
|
8
|
-
}
|
|
2
|
+
const { apiUrl } = config;
|
|
9
3
|
const projectsUrl = `${apiUrl.toString()}v2021-06-07/projects`;
|
|
10
|
-
export async function listProjects() {
|
|
4
|
+
export async function listProjects({ token }) {
|
|
11
5
|
const response = await fetch(projectsUrl, {
|
|
12
6
|
method: 'GET',
|
|
13
|
-
headers:
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${token}`,
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
},
|
|
14
11
|
});
|
|
15
12
|
const projects = await response.json();
|
|
16
13
|
return {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type { BlueprintJob } from '../../utils/types.js';
|
|
1
|
+
import type { AuthParams, BlueprintJob } from '../../utils/types.js';
|
|
2
2
|
export declare const stacksUrl: string;
|
|
3
|
-
export declare function listStacks(
|
|
4
|
-
projectId: string;
|
|
5
|
-
}): Promise<{
|
|
3
|
+
export declare function listStacks(auth: AuthParams): Promise<{
|
|
6
4
|
ok: boolean;
|
|
7
5
|
error: any;
|
|
8
6
|
stacks: any;
|
|
9
7
|
}>;
|
|
10
|
-
|
|
8
|
+
/** @deprecated Use getStack instead */
|
|
9
|
+
export declare function getStackByName({ name, auth }: {
|
|
11
10
|
name: string;
|
|
12
|
-
|
|
11
|
+
auth: AuthParams;
|
|
13
12
|
}): Promise<{
|
|
14
13
|
ok: boolean;
|
|
15
14
|
error: null;
|
|
@@ -23,26 +22,26 @@ export declare function getStackByName({ name, projectId }: {
|
|
|
23
22
|
stackId: any;
|
|
24
23
|
availableStacks?: undefined;
|
|
25
24
|
}>;
|
|
26
|
-
export declare function getStack({ stackId,
|
|
25
|
+
export declare function getStack({ stackId, auth }: {
|
|
27
26
|
stackId: string;
|
|
28
|
-
|
|
27
|
+
auth: AuthParams;
|
|
29
28
|
}): Promise<{
|
|
30
29
|
ok: boolean;
|
|
31
30
|
error: any;
|
|
32
31
|
stack: any;
|
|
33
32
|
}>;
|
|
34
|
-
export declare function createStack({ blueprint,
|
|
33
|
+
export declare function createStack({ blueprint, auth }: {
|
|
35
34
|
blueprint: BlueprintJob;
|
|
36
|
-
|
|
35
|
+
auth: AuthParams;
|
|
37
36
|
}): Promise<{
|
|
38
37
|
ok: boolean;
|
|
39
38
|
error: any;
|
|
40
39
|
stack: any;
|
|
41
40
|
}>;
|
|
42
|
-
export declare function updateStack({ stackId, blueprint,
|
|
41
|
+
export declare function updateStack({ stackId, blueprint, auth, }: {
|
|
43
42
|
stackId: string;
|
|
44
43
|
blueprint: BlueprintJob;
|
|
45
|
-
|
|
44
|
+
auth: AuthParams;
|
|
46
45
|
}): Promise<{
|
|
47
46
|
ok: boolean;
|
|
48
47
|
error: any;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import config from '../../config.js';
|
|
2
|
+
import getHeaders from '../../utils/get-headers.js';
|
|
2
3
|
const { blueprints } = config.server;
|
|
3
4
|
export const stacksUrl = `${blueprints}vX/blueprints/stacks`;
|
|
4
|
-
function
|
|
5
|
-
return {
|
|
6
|
-
Authorization: `Bearer ${config.token}`,
|
|
7
|
-
'Content-Type': 'application/json',
|
|
8
|
-
'X-Sanity-Scope-Type': 'project',
|
|
9
|
-
'X-Sanity-Scope-Id': projectId,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export async function listStacks({ projectId }) {
|
|
5
|
+
export async function listStacks(auth) {
|
|
13
6
|
const response = await fetch(stacksUrl, {
|
|
14
7
|
method: 'GET',
|
|
15
|
-
headers: getHeaders(
|
|
8
|
+
headers: getHeaders(auth),
|
|
16
9
|
});
|
|
17
10
|
const stacks = await response.json();
|
|
18
11
|
return {
|
|
@@ -21,8 +14,9 @@ export async function listStacks({ projectId }) {
|
|
|
21
14
|
stacks,
|
|
22
15
|
};
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
/** @deprecated Use getStack instead */
|
|
18
|
+
export async function getStackByName({ name, auth }) {
|
|
19
|
+
const { ok, stacks, error } = await listStacks(auth);
|
|
26
20
|
if (!ok || !stacks) {
|
|
27
21
|
return {
|
|
28
22
|
ok: false,
|
|
@@ -41,7 +35,7 @@ export async function getStackByName({ name, projectId }) {
|
|
|
41
35
|
availableStacks: stacks.map((s) => s.name),
|
|
42
36
|
};
|
|
43
37
|
}
|
|
44
|
-
const stackResult = await getStack({ stackId: foundStack.id,
|
|
38
|
+
const stackResult = await getStack({ stackId: foundStack.id, auth });
|
|
45
39
|
return {
|
|
46
40
|
ok: stackResult.ok,
|
|
47
41
|
error: stackResult.error,
|
|
@@ -49,10 +43,10 @@ export async function getStackByName({ name, projectId }) {
|
|
|
49
43
|
stackId: foundStack.id,
|
|
50
44
|
};
|
|
51
45
|
}
|
|
52
|
-
export async function getStack({ stackId,
|
|
46
|
+
export async function getStack({ stackId, auth }) {
|
|
53
47
|
const response = await fetch(`${stacksUrl}/${stackId}`, {
|
|
54
48
|
method: 'GET',
|
|
55
|
-
headers: getHeaders(
|
|
49
|
+
headers: getHeaders(auth),
|
|
56
50
|
});
|
|
57
51
|
const stack = await response.json();
|
|
58
52
|
return {
|
|
@@ -61,10 +55,10 @@ export async function getStack({ stackId, projectId }) {
|
|
|
61
55
|
stack,
|
|
62
56
|
};
|
|
63
57
|
}
|
|
64
|
-
export async function createStack({ blueprint,
|
|
58
|
+
export async function createStack({ blueprint, auth }) {
|
|
65
59
|
const response = await fetch(stacksUrl, {
|
|
66
60
|
method: 'POST',
|
|
67
|
-
headers: getHeaders(
|
|
61
|
+
headers: getHeaders(auth),
|
|
68
62
|
body: JSON.stringify(blueprint),
|
|
69
63
|
});
|
|
70
64
|
const stack = await response.json();
|
|
@@ -74,10 +68,10 @@ export async function createStack({ blueprint, projectId, }) {
|
|
|
74
68
|
stack,
|
|
75
69
|
};
|
|
76
70
|
}
|
|
77
|
-
export async function updateStack({ stackId, blueprint,
|
|
71
|
+
export async function updateStack({ stackId, blueprint, auth, }) {
|
|
78
72
|
const response = await fetch(`${stacksUrl}/${stackId}`, {
|
|
79
73
|
method: 'PUT',
|
|
80
|
-
headers: getHeaders(
|
|
74
|
+
headers: getHeaders(auth),
|
|
81
75
|
body: JSON.stringify(blueprint),
|
|
82
76
|
});
|
|
83
77
|
const stack = await response.json();
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { AuthParams } from '../../utils/types.js';
|
|
2
|
-
|
|
2
|
+
/** internal */
|
|
3
|
+
export interface LoggingOptions {
|
|
4
|
+
limit: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function logs(id: string, options: LoggingOptions, auth: AuthParams): Promise<{
|
|
3
7
|
ok: boolean;
|
|
4
8
|
error: any;
|
|
5
9
|
logs: any;
|
|
10
|
+
total: any;
|
|
6
11
|
}>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import config from '../../config.js';
|
|
2
2
|
import getHeaders from '../../utils/get-headers.js';
|
|
3
3
|
const { functions } = config.server;
|
|
4
|
-
export async function logs(id, auth) {
|
|
5
|
-
const
|
|
4
|
+
export async function logs(id, options, auth) {
|
|
5
|
+
const { limit } = options;
|
|
6
|
+
const response = await fetch(`${functions}vX/functions/${id}/logs?limit=${limit}`, {
|
|
6
7
|
headers: getHeaders(auth),
|
|
7
8
|
method: 'GET',
|
|
8
9
|
});
|
|
@@ -11,5 +12,6 @@ export async function logs(id, auth) {
|
|
|
11
12
|
ok: response.ok,
|
|
12
13
|
error: response.ok ? null : json?.error?.message,
|
|
13
14
|
logs: response.ok ? json.logs : [],
|
|
15
|
+
total: response.ok ? json.total : 0,
|
|
14
16
|
};
|
|
15
17
|
}
|
|
@@ -15,7 +15,7 @@ export default class Add extends Command {
|
|
|
15
15
|
};
|
|
16
16
|
async run() {
|
|
17
17
|
const { args } = await this.parse(Add);
|
|
18
|
-
const existingBlueprint = findBlueprintFile(
|
|
18
|
+
const existingBlueprint = findBlueprintFile();
|
|
19
19
|
if (!existingBlueprint) {
|
|
20
20
|
this.error('No blueprint file found. Run `sanity blueprints init` first.');
|
|
21
21
|
}
|
|
@@ -4,6 +4,8 @@ import inquirer from 'inquirer';
|
|
|
4
4
|
import { readConfigFile, writeConfigFile } from '../../actions/blueprints/blueprint.js';
|
|
5
5
|
import { listProjects } from '../../actions/blueprints/projects.js';
|
|
6
6
|
import { listStacks } from '../../actions/blueprints/stacks.js';
|
|
7
|
+
import config from '../../config.js';
|
|
8
|
+
const { token } = config;
|
|
7
9
|
export default class Config extends Command {
|
|
8
10
|
static description = 'View or edit Blueprint configuration';
|
|
9
11
|
static examples = [
|
|
@@ -26,7 +28,7 @@ export default class Config extends Command {
|
|
|
26
28
|
this.log(highlight(JSON.stringify(config, null, 2)));
|
|
27
29
|
if (!flags.edit)
|
|
28
30
|
return;
|
|
29
|
-
const { ok, projects, error } = await listProjects();
|
|
31
|
+
const { ok, projects, error } = await listProjects({ token });
|
|
30
32
|
if (!ok)
|
|
31
33
|
this.error(error);
|
|
32
34
|
if (projects.length === 0) {
|
|
@@ -45,8 +47,9 @@ export default class Config extends Command {
|
|
|
45
47
|
default: config.projectId,
|
|
46
48
|
},
|
|
47
49
|
]);
|
|
50
|
+
const auth = { token, projectId };
|
|
48
51
|
// get stacks for selected project
|
|
49
|
-
const { ok: stacksOk, stacks, error: stacksError } = await listStacks(
|
|
52
|
+
const { ok: stacksOk, stacks, error: stacksError } = await listStacks(auth);
|
|
50
53
|
if (!stacksOk)
|
|
51
54
|
this.error(stacksError);
|
|
52
55
|
let stackId;
|
|
@@ -4,12 +4,14 @@ import Spinner from 'yocto-spinner';
|
|
|
4
4
|
import { stashAsset } from '../../actions/blueprints/assets.js';
|
|
5
5
|
import { readBlueprintOnDisk, writeConfigFile } from '../../actions/blueprints/blueprint.js';
|
|
6
6
|
import { createStack, updateStack } from '../../actions/blueprints/stacks.js';
|
|
7
|
+
import config from '../../config.js';
|
|
7
8
|
import { bold, green, red, yellow } from '../../utils/display/colors.js';
|
|
9
|
+
const { token } = config;
|
|
8
10
|
export default class Deploy extends Command {
|
|
9
11
|
static description = 'Deploy a Blueprint';
|
|
10
12
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
11
13
|
async run() {
|
|
12
|
-
const { errors, projectId: configuredProjectId, stackId, parsedBlueprint: { resources }, deployedStack, } = await readBlueprintOnDisk({ getStack: true });
|
|
14
|
+
const { errors, projectId: configuredProjectId, stackId, parsedBlueprint: { resources }, deployedStack, } = await readBlueprintOnDisk({ getStack: true, token });
|
|
13
15
|
if (errors.length > 0) {
|
|
14
16
|
// printErrors(errors) // TODO: error printer in formatting
|
|
15
17
|
this.log('Blueprint parse errors:');
|
|
@@ -32,6 +34,7 @@ export default class Deploy extends Command {
|
|
|
32
34
|
}
|
|
33
35
|
if (!projectId)
|
|
34
36
|
this.error('Sanity Project context is required');
|
|
37
|
+
const auth = { token, projectId };
|
|
35
38
|
let name = deployedStack?.name;
|
|
36
39
|
if (!name) {
|
|
37
40
|
const { stackName } = await inquirer.prompt([
|
|
@@ -52,7 +55,7 @@ export default class Deploy extends Command {
|
|
|
52
55
|
if (functionResources.length > 0) {
|
|
53
56
|
for (const resource of functionResources) {
|
|
54
57
|
const fnSpinner = Spinner({ text: `Processing ${resource.name}...` }).start();
|
|
55
|
-
const result = await stashAsset({ resource,
|
|
58
|
+
const result = await stashAsset({ resource, auth });
|
|
56
59
|
if (result.success) {
|
|
57
60
|
const src = resource.src;
|
|
58
61
|
resource.src = result.assetId; // TODO: properly reference asset - for now, the API expects the assetId
|
|
@@ -74,8 +77,8 @@ export default class Deploy extends Command {
|
|
|
74
77
|
this.debug('BLUEPRINT DOCUMENT:', blueprint);
|
|
75
78
|
const spinner = Spinner({ text: 'Deploying stack...' }).start();
|
|
76
79
|
const { ok: deployOk, stack, error: deployError, } = deployedStack
|
|
77
|
-
? await updateStack({ stackId: deployedStack.id, blueprint,
|
|
78
|
-
: await createStack({ blueprint,
|
|
80
|
+
? await updateStack({ stackId: deployedStack.id, blueprint, auth })
|
|
81
|
+
: await createStack({ blueprint, auth });
|
|
79
82
|
this.debug('STACK RESPONSE:', stack);
|
|
80
83
|
if (deployOk) {
|
|
81
84
|
spinner.success(`${green('Success!')} Stack "${bold(stack.name)}" ${deployedStack ? 'updated' : 'created'} <${yellow(stack.id)}>`);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
2
|
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
3
3
|
import { getStack } from '../../actions/blueprints/stacks.js';
|
|
4
|
+
import config from '../../config.js';
|
|
4
5
|
import { formatResourceTree, formatStackInfo } from '../../utils/display/blueprints-formatting.js';
|
|
6
|
+
const { token } = config;
|
|
5
7
|
export default class Info extends Command {
|
|
6
8
|
static description = 'Show information about a Blueprint';
|
|
7
9
|
static examples = [
|
|
@@ -16,7 +18,7 @@ export default class Info extends Command {
|
|
|
16
18
|
};
|
|
17
19
|
async run() {
|
|
18
20
|
const { flags } = await this.parse(Info);
|
|
19
|
-
const { errors, deployedStack, projectId } = await readBlueprintOnDisk({ getStack: true });
|
|
21
|
+
const { errors, deployedStack, projectId } = await readBlueprintOnDisk({ getStack: true, token });
|
|
20
22
|
if (errors.length > 0) {
|
|
21
23
|
// printErrors(errors)
|
|
22
24
|
this.warn('Blueprint parse errors:');
|
|
@@ -25,9 +27,10 @@ export default class Info extends Command {
|
|
|
25
27
|
}
|
|
26
28
|
if (!projectId)
|
|
27
29
|
this.error('Project resource not found in blueprint');
|
|
30
|
+
const auth = { token, projectId };
|
|
28
31
|
let stack = deployedStack;
|
|
29
32
|
if (flags.id) {
|
|
30
|
-
const { ok, stack: foundStack, error } = await getStack({ stackId: flags.id,
|
|
33
|
+
const { ok, stack: foundStack, error } = await getStack({ stackId: flags.id, auth });
|
|
31
34
|
if (!ok)
|
|
32
35
|
this.error(error || 'Failed to get stack');
|
|
33
36
|
stack = foundStack;
|
|
@@ -4,6 +4,8 @@ import { Command } from '@oclif/core';
|
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
5
|
import { findBlueprintFile, writeBlueprintToDisk, writeConfigFile, } from '../../actions/blueprints/blueprint.js';
|
|
6
6
|
import { listProjects } from '../../actions/blueprints/projects.js';
|
|
7
|
+
import config from '../../config.js';
|
|
8
|
+
const { token } = config;
|
|
7
9
|
export default class Init extends Command {
|
|
8
10
|
static description = 'Initialize a new Blueprint';
|
|
9
11
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
@@ -25,7 +27,7 @@ export default class Init extends Command {
|
|
|
25
27
|
default: 'json',
|
|
26
28
|
},
|
|
27
29
|
]);
|
|
28
|
-
const { ok, projects, error } = await listProjects();
|
|
30
|
+
const { ok, projects, error } = await listProjects({ token });
|
|
29
31
|
if (!ok)
|
|
30
32
|
this.error(error);
|
|
31
33
|
if (projects.length === 0) {
|
|
@@ -6,6 +6,7 @@ import config from '../../config.js';
|
|
|
6
6
|
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
7
7
|
import { bold, red, yellow } from '../../utils/display/colors.js';
|
|
8
8
|
import { formatLogEntry, formatLogsByDay, organizeLogsByDay, } from '../../utils/display/logs-formatting.js';
|
|
9
|
+
const { token } = config;
|
|
9
10
|
export default class Logs extends Command {
|
|
10
11
|
static description = 'Display logs for a Blueprint stack';
|
|
11
12
|
static examples = [
|
|
@@ -24,7 +25,7 @@ export default class Logs extends Command {
|
|
|
24
25
|
const { flags } = await this.parse(Logs);
|
|
25
26
|
const watchMode = flags.watch;
|
|
26
27
|
try {
|
|
27
|
-
const { errors, deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
28
|
+
const { errors, deployedStack } = await readBlueprintOnDisk({ getStack: true, token });
|
|
28
29
|
if (errors.length > 0) {
|
|
29
30
|
this.log('Blueprint parse errors:');
|
|
30
31
|
console.dir(errors, { depth: null });
|
|
@@ -33,9 +34,10 @@ export default class Logs extends Command {
|
|
|
33
34
|
if (!deployedStack)
|
|
34
35
|
this.error('Stack not found'); // returns
|
|
35
36
|
const { id: stackId, projectId, name } = deployedStack;
|
|
37
|
+
const auth = { token, projectId };
|
|
36
38
|
const spinner = Spinner({ text: `Fetching logs for stack ${yellow(`<${stackId}>`)}` }).start();
|
|
37
39
|
if (watchMode) {
|
|
38
|
-
const { ok, logs, error } = await getLogs(stackId,
|
|
40
|
+
const { ok, logs, error } = await getLogs(stackId, auth);
|
|
39
41
|
if (!ok) {
|
|
40
42
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
41
43
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
@@ -64,12 +66,12 @@ export default class Logs extends Command {
|
|
|
64
66
|
this.log(formatLogEntry(log, true));
|
|
65
67
|
};
|
|
66
68
|
this.debug(`${yellow('Debug:')} Connecting to streaming endpoint for stack ${stackId}...`);
|
|
67
|
-
streamLogs(stackId,
|
|
69
|
+
streamLogs(stackId, auth, renderLog, onOpen, (error) => this.log(`${red('Error:')} ${error}`));
|
|
68
70
|
return new Promise(() => {
|
|
69
71
|
// hold the line until the user terminates with Ctrl+C
|
|
70
72
|
});
|
|
71
73
|
}
|
|
72
|
-
const { ok, logs, error } = await getLogs(stackId,
|
|
74
|
+
const { ok, logs, error } = await getLogs(stackId, auth);
|
|
73
75
|
if (!ok) {
|
|
74
76
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
75
77
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
3
|
+
import config from '../../config.js';
|
|
3
4
|
import { formatResourceTree, formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
5
|
+
const { token } = config;
|
|
4
6
|
export default class Plan extends Command {
|
|
5
7
|
static description = 'Enumerate resources to be deployed - will not modify any resources';
|
|
6
8
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
7
9
|
async run() {
|
|
8
|
-
const { errors, projectId, stackId, parsedBlueprint: { resources }, fileInfo, } = await readBlueprintOnDisk();
|
|
10
|
+
const { errors, projectId, stackId, parsedBlueprint: { resources }, fileInfo, } = await readBlueprintOnDisk({ token });
|
|
9
11
|
if (errors.length > 0) {
|
|
10
12
|
// printErrors(errors)
|
|
11
13
|
this.log('Blueprint parse errors:');
|
|
12
14
|
console.dir(errors, { depth: null });
|
|
13
|
-
// return // don't return, show the plan
|
|
14
15
|
}
|
|
15
16
|
if (!projectId)
|
|
16
17
|
this.log('Blueprint must contain a project resource');
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
3
3
|
import { listStacks } from '../../actions/blueprints/stacks.js';
|
|
4
|
+
import config from '../../config.js';
|
|
4
5
|
import { formatStacksListing } from '../../utils/display/blueprints-formatting.js';
|
|
5
6
|
import { bold, yellow } from '../../utils/display/colors.js';
|
|
7
|
+
const { token } = config;
|
|
6
8
|
export default class Stacks extends Command {
|
|
7
9
|
static description = 'List all Blueprint stacks';
|
|
8
10
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
@@ -15,7 +17,8 @@ export default class Stacks extends Command {
|
|
|
15
17
|
}
|
|
16
18
|
if (!projectId)
|
|
17
19
|
this.error('Project resource not found in blueprint');
|
|
18
|
-
const
|
|
20
|
+
const auth = { token, projectId };
|
|
21
|
+
const { ok, stacks, error } = await listStacks(auth);
|
|
19
22
|
if (!ok)
|
|
20
23
|
this.error(error || 'Failed to list stacks');
|
|
21
24
|
if (!stacks || stacks.length === 0) {
|
|
@@ -20,7 +20,7 @@ export default class Add extends Command {
|
|
|
20
20
|
const spinner = Spinner({
|
|
21
21
|
text: `Updating "${args.key}" environment variable in "${args.name}"`,
|
|
22
22
|
}).start();
|
|
23
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
23
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
|
|
24
24
|
if (!deployedStack)
|
|
25
25
|
this.error('Stack not found'); // returns
|
|
26
26
|
const { projectId } = deployedStack;
|
|
@@ -17,7 +17,7 @@ export default class Remove extends Command {
|
|
|
17
17
|
const spinner = Spinner({
|
|
18
18
|
text: `Removing "${args.key}" environment variable in "${args.name}"`,
|
|
19
19
|
}).start();
|
|
20
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
20
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
|
|
21
21
|
if (!deployedStack)
|
|
22
22
|
this.error('Stack not found'); // returns
|
|
23
23
|
const { projectId } = deployedStack;
|
|
@@ -11,8 +11,8 @@ export default class Invoke extends Command {
|
|
|
11
11
|
};
|
|
12
12
|
static description = 'Invoke a remote Sanity Function';
|
|
13
13
|
static examples = [
|
|
14
|
-
`<%= config.bin %> <%= command.id %> <
|
|
15
|
-
`<%= config.bin %> <%= command.id %> <
|
|
14
|
+
`<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }'`,
|
|
15
|
+
`<%= config.bin %> <%= command.id %> <name> --file 'payload.json'`,
|
|
16
16
|
];
|
|
17
17
|
static flags = {
|
|
18
18
|
data: Flags.string({ char: 'd', description: 'Data to send to the function', required: false }),
|
|
@@ -25,7 +25,7 @@ export default class Invoke extends Command {
|
|
|
25
25
|
async run() {
|
|
26
26
|
const { args, flags } = await this.parse(Invoke);
|
|
27
27
|
const spinner = Spinner({ text: `Invoking function "${args.name}"` }).start();
|
|
28
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
28
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
|
|
29
29
|
if (!deployedStack)
|
|
30
30
|
this.error('Stack not found'); // returns
|
|
31
31
|
const { projectId } = deployedStack;
|
|
@@ -5,5 +5,9 @@ export default class Logs extends Command {
|
|
|
5
5
|
};
|
|
6
6
|
static description: string;
|
|
7
7
|
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
8
12
|
run(): Promise<void>;
|
|
9
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Args, Command } from '@oclif/core';
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
3
|
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
4
4
|
import { logs as logsAction } from '../../actions/functions/logs.js';
|
|
@@ -10,7 +10,7 @@ function logLevel(level) {
|
|
|
10
10
|
if (level === 'ERROR') {
|
|
11
11
|
return red(level);
|
|
12
12
|
}
|
|
13
|
-
if (level === '
|
|
13
|
+
if (level === 'WARN') {
|
|
14
14
|
return yellow(level);
|
|
15
15
|
}
|
|
16
16
|
return green(level);
|
|
@@ -20,16 +20,33 @@ export default class Logs extends Command {
|
|
|
20
20
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
21
21
|
};
|
|
22
22
|
static description = 'Retrieve logs for a Sanity Function';
|
|
23
|
-
static examples = [
|
|
23
|
+
static examples = [
|
|
24
|
+
'<%= config.bin %> <%= command.id %> <name>',
|
|
25
|
+
'<%= config.bin %> <%= command.id %> <name> --json',
|
|
26
|
+
'<%= config.bin %> <%= command.id %> <name> --limit 100',
|
|
27
|
+
];
|
|
28
|
+
static flags = {
|
|
29
|
+
limit: Flags.integer({
|
|
30
|
+
char: 'l',
|
|
31
|
+
description: 'Total number of log entries to retrieve',
|
|
32
|
+
required: false,
|
|
33
|
+
default: 50,
|
|
34
|
+
}),
|
|
35
|
+
json: Flags.boolean({
|
|
36
|
+
char: 'j',
|
|
37
|
+
description: 'Return logs in JSON format',
|
|
38
|
+
required: false,
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
24
41
|
async run() {
|
|
25
|
-
const { args } = await this.parse(Logs);
|
|
42
|
+
const { args, flags } = await this.parse(Logs);
|
|
26
43
|
const spinner = Spinner({ text: `Finding logs for function "${args.name}"` }).start();
|
|
27
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
44
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
|
|
28
45
|
if (!deployedStack)
|
|
29
46
|
this.error('Stack not found'); // returns
|
|
30
|
-
const {
|
|
47
|
+
const { projectId } = deployedStack;
|
|
31
48
|
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
32
|
-
const { ok, error, logs } = await logsAction(externalId, { token: config.token, projectId });
|
|
49
|
+
const { ok, error, logs, total } = await logsAction(externalId, { limit: flags.limit }, { token: config.token, projectId });
|
|
33
50
|
if (!ok) {
|
|
34
51
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
35
52
|
this.log(`Error: ${error || 'Unknown error'}`);
|
|
@@ -41,11 +58,20 @@ export default class Logs extends Command {
|
|
|
41
58
|
return;
|
|
42
59
|
}
|
|
43
60
|
spinner.success(`${formatTitle('Function', args.name)} Logs`);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
if (!flags.json) {
|
|
62
|
+
this.log(`Found ${bold(total)} log entries for function ${yellow(args.name)}`);
|
|
63
|
+
if (logs.length < total) {
|
|
64
|
+
this.log(`Here are the last ${bold(filteredLogs.length.toString())} entries`);
|
|
65
|
+
}
|
|
66
|
+
this.log('\n');
|
|
67
|
+
for (const log of filteredLogs) {
|
|
68
|
+
const { time, level, message } = log;
|
|
69
|
+
const date = new Date(time);
|
|
70
|
+
this.log(`${bold(date.toLocaleDateString())} ${bold(blue(date.toLocaleTimeString()))} ${logLevel(level)} ${message}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.log(JSON.stringify(filteredLogs, null, 2));
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
77
|
}
|
|
@@ -8,9 +8,9 @@ export default class Test extends Command {
|
|
|
8
8
|
};
|
|
9
9
|
static description = 'Invoke a local Sanity Function';
|
|
10
10
|
static examples = [
|
|
11
|
-
`<%= config.bin %> <%= command.id %>
|
|
12
|
-
`<%= config.bin %> <%= command.id %>
|
|
13
|
-
`<%= config.bin %> <%= command.id %>
|
|
11
|
+
`<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }'`,
|
|
12
|
+
`<%= config.bin %> <%= command.id %> <name> --file 'payload.json'`,
|
|
13
|
+
`<%= config.bin %> <%= command.id %> <name> --data '{ "id": 1 }' --timeout 60`,
|
|
14
14
|
];
|
|
15
15
|
static flags = {
|
|
16
16
|
data: Flags.string({ char: 'd', description: 'Data to send to the function', required: false }),
|
package/dist/config.js
CHANGED
|
@@ -22,8 +22,9 @@ const blueprintsUrls = {
|
|
|
22
22
|
};
|
|
23
23
|
const functionsUrl = new URL(functionsUrls[nodeEnv] ?? functionsUrls.default);
|
|
24
24
|
const blueprintsUrl = new URL(blueprintsUrls[nodeEnv] ?? blueprintsUrls.default);
|
|
25
|
+
const token = isDev || isTest || isPublishing ? 'token' : getToken({ prod: useProd });
|
|
25
26
|
export default {
|
|
26
|
-
token
|
|
27
|
+
token,
|
|
27
28
|
apiUrl,
|
|
28
29
|
server: {
|
|
29
30
|
functions: functionsUrl,
|
|
@@ -9400,7 +9400,6 @@ var browser = {
|
|
|
9400
9400
|
chrome_version: chrome ? +chrome[1] : 0,
|
|
9401
9401
|
ios,
|
|
9402
9402
|
android: /*@__PURE__*//Android\b/.test(nav.userAgent),
|
|
9403
|
-
webkit,
|
|
9404
9403
|
safari,
|
|
9405
9404
|
webkit_version: webkit ? +(/*@__PURE__*//\bAppleWebKit\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
9406
9405
|
tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
|
|
@@ -9726,7 +9725,7 @@ function coordsInChildren(view, pos, side) {
|
|
|
9726
9725
|
if (child.children.length) {
|
|
9727
9726
|
scan(child, pos - off);
|
|
9728
9727
|
}
|
|
9729
|
-
else if ((!after || after.isHidden && side > 0) &&
|
|
9728
|
+
else if ((!after || after.isHidden && (side > 0 || onSameLine(after, child))) &&
|
|
9730
9729
|
(end > pos || off == end && child.getSide() > 0)) {
|
|
9731
9730
|
after = child;
|
|
9732
9731
|
afterPos = pos - off;
|
|
@@ -9752,6 +9751,10 @@ function fallbackRect(view) {
|
|
|
9752
9751
|
let rects = clientRectsFor(last);
|
|
9753
9752
|
return rects[rects.length - 1] || null;
|
|
9754
9753
|
}
|
|
9754
|
+
function onSameLine(a, b) {
|
|
9755
|
+
let posA = a.coordsAt(0, 1), posB = b.coordsAt(0, 1);
|
|
9756
|
+
return posA && posB && posB.top < posA.bottom;
|
|
9757
|
+
}
|
|
9755
9758
|
|
|
9756
9759
|
function combineAttrs(source, target) {
|
|
9757
9760
|
for (let name in source) {
|
|
@@ -15270,6 +15273,7 @@ const baseTheme$1$3 = /*@__PURE__*/buildTheme("." + baseThemeID, {
|
|
|
15270
15273
|
color: "#888",
|
|
15271
15274
|
display: "inline-block",
|
|
15272
15275
|
verticalAlign: "top",
|
|
15276
|
+
userSelect: "none"
|
|
15273
15277
|
},
|
|
15274
15278
|
".cm-highlightSpace": {
|
|
15275
15279
|
backgroundImage: "radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",
|
|
@@ -17684,7 +17688,6 @@ function layer(config) {
|
|
|
17684
17688
|
];
|
|
17685
17689
|
}
|
|
17686
17690
|
|
|
17687
|
-
const CanHidePrimary = !(browser.ios && browser.webkit && browser.webkit_version < 534);
|
|
17688
17691
|
const selectionConfig = /*@__PURE__*/Facet.define({
|
|
17689
17692
|
combine(configs) {
|
|
17690
17693
|
return combineConfig(configs, {
|
|
@@ -17733,7 +17736,7 @@ const cursorLayer = /*@__PURE__*/layer({
|
|
|
17733
17736
|
let cursors = [];
|
|
17734
17737
|
for (let r of state.selection.ranges) {
|
|
17735
17738
|
let prim = r == state.selection.main;
|
|
17736
|
-
if (r.empty
|
|
17739
|
+
if (r.empty || conf.drawRangeCursor) {
|
|
17737
17740
|
let className = prim ? "cm-cursor cm-cursor-primary" : "cm-cursor cm-cursor-secondary";
|
|
17738
17741
|
let cursor = r.empty ? r : EditorSelection.cursor(r.head, r.head > r.anchor ? -1 : 1);
|
|
17739
17742
|
for (let piece of RectangleMarker.forRange(view, className, cursor))
|
|
@@ -17769,11 +17772,13 @@ const selectionLayer = /*@__PURE__*/layer({
|
|
|
17769
17772
|
},
|
|
17770
17773
|
class: "cm-selectionLayer"
|
|
17771
17774
|
});
|
|
17772
|
-
const
|
|
17775
|
+
const hideNativeSelection = /*@__PURE__*/Prec.highest(/*@__PURE__*/EditorView.theme({
|
|
17773
17776
|
".cm-line": {
|
|
17774
17777
|
"& ::selection, &::selection": { backgroundColor: "transparent !important" },
|
|
17778
|
+
caretColor: "transparent !important"
|
|
17775
17779
|
},
|
|
17776
17780
|
".cm-content": {
|
|
17781
|
+
caretColor: "transparent !important",
|
|
17777
17782
|
"& :focus": {
|
|
17778
17783
|
caretColor: "initial !important",
|
|
17779
17784
|
"&::selection, & ::selection": {
|
|
@@ -17781,10 +17786,7 @@ const themeSpec = {
|
|
|
17781
17786
|
}
|
|
17782
17787
|
}
|
|
17783
17788
|
}
|
|
17784
|
-
};
|
|
17785
|
-
if (CanHidePrimary)
|
|
17786
|
-
themeSpec[".cm-line"].caretColor = themeSpec[".cm-content"].caretColor = "transparent !important";
|
|
17787
|
-
const hideNativeSelection = /*@__PURE__*/Prec.highest(/*@__PURE__*/EditorView.theme(themeSpec));
|
|
17789
|
+
}));
|
|
17788
17790
|
|
|
17789
17791
|
const setDropCursorPos = /*@__PURE__*/StateEffect.define({
|
|
17790
17792
|
map(pos, mapping) { return pos == null ? null : mapping.mapPos(pos); }
|
|
@@ -21621,7 +21623,7 @@ block comments.
|
|
|
21621
21623
|
*/
|
|
21622
21624
|
const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
|
|
21623
21625
|
function getConfig(state, pos) {
|
|
21624
|
-
let data = state.languageDataAt("commentTokens", pos);
|
|
21626
|
+
let data = state.languageDataAt("commentTokens", pos, 1);
|
|
21625
21627
|
return data.length ? data[0] : {};
|
|
21626
21628
|
}
|
|
21627
21629
|
const SearchMargin = 50;
|
|
@@ -25922,10 +25924,9 @@ class LintState {
|
|
|
25922
25924
|
}
|
|
25923
25925
|
static init(diagnostics, panel, state) {
|
|
25924
25926
|
// Filter the list of diagnostics for which to create markers
|
|
25925
|
-
let markedDiagnostics = diagnostics;
|
|
25926
25927
|
let diagnosticFilter = state.facet(lintConfig).markerFilter;
|
|
25927
25928
|
if (diagnosticFilter)
|
|
25928
|
-
|
|
25929
|
+
diagnostics = diagnosticFilter(diagnostics, state);
|
|
25929
25930
|
let sorted = diagnostics.slice().sort((a, b) => a.from - b.from || a.to - b.to);
|
|
25930
25931
|
let deco = new RangeSetBuilder(), active = [], pos = 0;
|
|
25931
25932
|
for (let i = 0;;) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function formatError(response, json) {
|
|
2
|
+
if (response.ok) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
if (response.status === 401 || response.status === 403) {
|
|
6
|
+
return 'Please login to the Sanity CLI to run this command';
|
|
7
|
+
}
|
|
8
|
+
return json?.error?.message || 'Unknown Error';
|
|
9
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -274,8 +274,8 @@
|
|
|
274
274
|
},
|
|
275
275
|
"description": "Invoke a remote Sanity Function",
|
|
276
276
|
"examples": [
|
|
277
|
-
"<%= config.bin %> <%= command.id %> <
|
|
278
|
-
"<%= config.bin %> <%= command.id %> <
|
|
277
|
+
"<%= config.bin %> <%= command.id %> <name> --data '{ \"id\": 1 }'",
|
|
278
|
+
"<%= config.bin %> <%= command.id %> <name> --file 'payload.json'"
|
|
279
279
|
],
|
|
280
280
|
"flags": {
|
|
281
281
|
"data": {
|
|
@@ -324,9 +324,30 @@
|
|
|
324
324
|
},
|
|
325
325
|
"description": "Retrieve logs for a Sanity Function",
|
|
326
326
|
"examples": [
|
|
327
|
-
"<%= config.bin %> <%= command.id %> <
|
|
327
|
+
"<%= config.bin %> <%= command.id %> <name>",
|
|
328
|
+
"<%= config.bin %> <%= command.id %> <name> --json",
|
|
329
|
+
"<%= config.bin %> <%= command.id %> <name> --limit 100"
|
|
328
330
|
],
|
|
329
|
-
"flags": {
|
|
331
|
+
"flags": {
|
|
332
|
+
"limit": {
|
|
333
|
+
"char": "l",
|
|
334
|
+
"description": "Total number of log entries to retrieve",
|
|
335
|
+
"name": "limit",
|
|
336
|
+
"required": false,
|
|
337
|
+
"default": 50,
|
|
338
|
+
"hasDynamicHelp": false,
|
|
339
|
+
"multiple": false,
|
|
340
|
+
"type": "option"
|
|
341
|
+
},
|
|
342
|
+
"json": {
|
|
343
|
+
"char": "j",
|
|
344
|
+
"description": "Return logs in JSON format",
|
|
345
|
+
"name": "json",
|
|
346
|
+
"required": false,
|
|
347
|
+
"allowNo": false,
|
|
348
|
+
"type": "boolean"
|
|
349
|
+
}
|
|
350
|
+
},
|
|
330
351
|
"hasDynamicHelp": false,
|
|
331
352
|
"hiddenAliases": [],
|
|
332
353
|
"id": "functions:logs",
|
|
@@ -354,9 +375,9 @@
|
|
|
354
375
|
},
|
|
355
376
|
"description": "Invoke a local Sanity Function",
|
|
356
377
|
"examples": [
|
|
357
|
-
"<%= config.bin %> <%= command.id %>
|
|
358
|
-
"<%= config.bin %> <%= command.id %>
|
|
359
|
-
"<%= config.bin %> <%= command.id %>
|
|
378
|
+
"<%= config.bin %> <%= command.id %> <name> --data '{ \"id\": 1 }'",
|
|
379
|
+
"<%= config.bin %> <%= command.id %> <name> --file 'payload.json'",
|
|
380
|
+
"<%= config.bin %> <%= command.id %> <name> --data '{ \"id\": 1 }' --timeout 60"
|
|
360
381
|
],
|
|
361
382
|
"flags": {
|
|
362
383
|
"data": {
|
|
@@ -481,5 +502,5 @@
|
|
|
481
502
|
]
|
|
482
503
|
}
|
|
483
504
|
},
|
|
484
|
-
"version": "2.
|
|
505
|
+
"version": "2.3.0"
|
|
485
506
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/runtime-cli",
|
|
3
3
|
"description": "Sanity's Runtime CLI for Blueprints and Functions",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"array-treeify": "^0.1.3",
|
|
46
46
|
"color-json": "^3.0.5",
|
|
47
47
|
"eventsource": "^3.0.6",
|
|
48
|
-
"inquirer": "^12.5.
|
|
48
|
+
"inquirer": "^12.5.2",
|
|
49
49
|
"jszip": "^3.10.1",
|
|
50
50
|
"mime-types": "^3.0.1",
|
|
51
51
|
"xdg-basedir": "^5.1.0",
|
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
"@types/node": "18",
|
|
64
64
|
"codemirror": "^6.0.1",
|
|
65
65
|
"mentoss": "^0.9.1",
|
|
66
|
-
"oclif": "^4.17.
|
|
66
|
+
"oclif": "^4.17.42",
|
|
67
67
|
"pretty-bytes": "^6.1.1",
|
|
68
68
|
"pretty-ms": "^9.2.0",
|
|
69
|
-
"rollup": "^4.
|
|
69
|
+
"rollup": "^4.39.0",
|
|
70
70
|
"shx": "^0.4.0",
|
|
71
71
|
"ts-node": "^10.9.2",
|
|
72
72
|
"tsx": "^4.19.3",
|
|
73
73
|
"typescript": "^5.8.2",
|
|
74
|
-
"vitest": "3.
|
|
74
|
+
"vitest": "3.1.1"
|
|
75
75
|
},
|
|
76
76
|
"oclif": {
|
|
77
77
|
"bin": "sanity-run",
|