@sanity/runtime-cli 2.1.0 → 2.2.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 +15 -15
- 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.js +3 -3
- 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 +1 -1
- package/dist/commands/functions/logs.js +29 -25
- package/dist/config.js +2 -1
- package/dist/server/static/vendor/vendor.bundle.js +13 -12
- package/dist/utils/types.d.ts +3 -9
- package/oclif.manifest.json +1 -1
- 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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.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.2.0/src/commands/functions/env/remove.ts)_
|
|
264
264
|
|
|
265
265
|
## `sanity-run functions invoke NAME`
|
|
266
266
|
|
|
@@ -286,7 +286,7 @@ EXAMPLES
|
|
|
286
286
|
$ sanity-run functions invoke <ID> --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.2.0/src/commands/functions/invoke.ts)_
|
|
290
290
|
|
|
291
291
|
## `sanity-run functions logs NAME`
|
|
292
292
|
|
|
@@ -306,7 +306,7 @@ EXAMPLES
|
|
|
306
306
|
$ sanity-run functions logs <ID>
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
309
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/logs.ts)_
|
|
310
310
|
|
|
311
311
|
## `sanity-run functions test NAME`
|
|
312
312
|
|
|
@@ -335,7 +335,7 @@ EXAMPLES
|
|
|
335
335
|
$ sanity-run functions test echo-fn --data '{ "id": 1 }' --timeout 60
|
|
336
336
|
```
|
|
337
337
|
|
|
338
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.
|
|
338
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v2.2.0/src/commands/functions/test.ts)_
|
|
339
339
|
|
|
340
340
|
## `sanity-run help [COMMAND]`
|
|
341
341
|
|
|
@@ -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();
|
|
@@ -6,10 +6,10 @@ export async function logs(id, auth) {
|
|
|
6
6
|
headers: getHeaders(auth),
|
|
7
7
|
method: 'GET',
|
|
8
8
|
});
|
|
9
|
-
const
|
|
9
|
+
const json = await response.json();
|
|
10
10
|
return {
|
|
11
11
|
ok: response.ok,
|
|
12
|
-
error: response.ok ? null :
|
|
13
|
-
logs: response.ok ? logs : [],
|
|
12
|
+
error: response.ok ? null : json?.error?.message,
|
|
13
|
+
logs: response.ok ? json.logs : [],
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { Args, Command } from '@oclif/core';
|
|
2
2
|
import Spinner from 'yocto-spinner';
|
|
3
3
|
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
4
|
-
import { logs } from '../../actions/functions/logs.js';
|
|
4
|
+
import { logs as logsAction } from '../../actions/functions/logs.js';
|
|
5
5
|
import config from '../../config.js';
|
|
6
|
-
import {
|
|
6
|
+
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
7
|
+
import { blue, bold, green, red, yellow } from '../../utils/display/colors.js';
|
|
7
8
|
import { findFunctionByName } from '../../utils/find-function.js';
|
|
9
|
+
function logLevel(level) {
|
|
10
|
+
if (level === 'ERROR') {
|
|
11
|
+
return red(level);
|
|
12
|
+
}
|
|
13
|
+
if (level === 'ERROR') {
|
|
14
|
+
return yellow(level);
|
|
15
|
+
}
|
|
16
|
+
return green(level);
|
|
17
|
+
}
|
|
8
18
|
export default class Logs extends Command {
|
|
9
19
|
static args = {
|
|
10
20
|
name: Args.string({ description: 'The name of the Sanity Function', required: true }),
|
|
@@ -14,34 +24,28 @@ export default class Logs extends Command {
|
|
|
14
24
|
async run() {
|
|
15
25
|
const { args } = await this.parse(Logs);
|
|
16
26
|
const spinner = Spinner({ text: `Finding logs for function "${args.name}"` }).start();
|
|
17
|
-
const { deployedStack } = await readBlueprintOnDisk({ getStack: true });
|
|
27
|
+
const { deployedStack } = await readBlueprintOnDisk({ getStack: true, token: config.token });
|
|
18
28
|
if (!deployedStack)
|
|
19
29
|
this.error('Stack not found'); // returns
|
|
20
30
|
const { name, projectId } = deployedStack;
|
|
21
31
|
const { externalId } = findFunctionByName(deployedStack, args.name);
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
spinner.success(`Found logs ${args.name} for blueprint "${name}"`);
|
|
25
|
-
for (const logGroup of result.logs) {
|
|
26
|
-
for (const log of logGroup.events) {
|
|
27
|
-
const { message, timestamp } = log;
|
|
28
|
-
// INFO log format: year month date hr min sec ms req uuid
|
|
29
|
-
const logPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\s+[0-9a-f-]+/;
|
|
30
|
-
if (logPattern.test(message)) {
|
|
31
|
-
const content = message.replace(logPattern, '').trim().replace(/^INFO/, '').trim();
|
|
32
|
-
if (content) {
|
|
33
|
-
const date = new Date(timestamp);
|
|
34
|
-
const time = date.toLocaleTimeString();
|
|
35
|
-
const day = date.toLocaleDateString();
|
|
36
|
-
this.log(` ${bold(day)} ${yellow(time)} ${content}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
32
|
+
const { ok, error, logs } = await logsAction(externalId, { token: config.token, projectId });
|
|
33
|
+
if (!ok) {
|
|
43
34
|
spinner.error(`${red('Failed')} to retrieve logs`);
|
|
44
|
-
this.log(`Error: ${
|
|
35
|
+
this.log(`Error: ${error || 'Unknown error'}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const filteredLogs = logs.filter((entry) => entry.level && entry.message);
|
|
39
|
+
if (filteredLogs.length === 0) {
|
|
40
|
+
spinner.info(`No logs found for function ${args.name}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
spinner.success(`${formatTitle('Function', args.name)} Logs`);
|
|
44
|
+
this.log(`Found ${bold(filteredLogs.length.toString())} log entries for function ${yellow(args.name)}\n`);
|
|
45
|
+
for (const log of filteredLogs) {
|
|
46
|
+
const { time, level, message } = log;
|
|
47
|
+
const date = new Date(time);
|
|
48
|
+
this.log(`${bold(date.toLocaleDateString())} ${bold(blue(date.toLocaleTimeString()))} ${logLevel(level)} ${message}`);
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
}
|
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;;) {
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -84,15 +84,9 @@ export interface AuthParams {
|
|
|
84
84
|
}
|
|
85
85
|
/** @internal */
|
|
86
86
|
export interface FunctionLog {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
time: string;
|
|
88
|
+
requestId: string;
|
|
89
|
+
level: string;
|
|
90
90
|
message: string;
|
|
91
91
|
}
|
|
92
|
-
/** @internal */
|
|
93
|
-
export interface FunctionLogGroup {
|
|
94
|
-
events: Array<FunctionLog>;
|
|
95
|
-
nextBackwardToken: string;
|
|
96
|
-
nextForwardToken: string;
|
|
97
|
-
}
|
|
98
92
|
export {};
|
package/oclif.manifest.json
CHANGED
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.2.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",
|