@sanity/runtime-cli 7.3.5 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/dist/actions/blueprints/index.d.ts +4 -1
- package/dist/actions/blueprints/index.js +4 -1
- package/dist/actions/sanity/index.d.ts +1 -0
- package/dist/actions/sanity/index.js +1 -0
- package/dist/actions/{blueprints → sanity}/projects.d.ts +18 -1
- package/dist/actions/sanity/projects.js +62 -0
- package/dist/cores/blueprints/add.js +2 -2
- package/dist/cores/blueprints/config.js +4 -26
- package/dist/cores/blueprints/init.js +6 -27
- package/dist/utils/display/prompt.d.ts +14 -0
- package/dist/utils/display/prompt.js +53 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/validated-token.d.ts +2 -2
- package/dist/utils/validated-token.js +4 -4
- package/oclif.manifest.json +1 -1
- package/package.json +5 -1
- package/dist/actions/blueprints/projects.js +0 -30
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/7.
|
|
23
|
+
@sanity/runtime-cli/7.4.0 linux-x64 node-v22.15.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -84,7 +84,7 @@ EXAMPLES
|
|
|
84
84
|
$ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
87
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/add.ts)_
|
|
88
88
|
|
|
89
89
|
## `sanity-run blueprints config`
|
|
90
90
|
|
|
@@ -112,7 +112,7 @@ EXAMPLES
|
|
|
112
112
|
$ sanity-run blueprints config --edit --project-id <projectId>
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
115
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/config.ts)_
|
|
116
116
|
|
|
117
117
|
## `sanity-run blueprints deploy`
|
|
118
118
|
|
|
@@ -134,7 +134,7 @@ EXAMPLES
|
|
|
134
134
|
$ sanity-run blueprints deploy --no-wait
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
137
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/deploy.ts)_
|
|
138
138
|
|
|
139
139
|
## `sanity-run blueprints destroy`
|
|
140
140
|
|
|
@@ -155,7 +155,7 @@ EXAMPLES
|
|
|
155
155
|
$ sanity-run blueprints destroy
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
158
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/destroy.ts)_
|
|
159
159
|
|
|
160
160
|
## `sanity-run blueprints info`
|
|
161
161
|
|
|
@@ -172,7 +172,7 @@ EXAMPLES
|
|
|
172
172
|
$ sanity-run blueprints info
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
175
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/info.ts)_
|
|
176
176
|
|
|
177
177
|
## `sanity-run blueprints init [DIR]`
|
|
178
178
|
|
|
@@ -204,7 +204,7 @@ EXAMPLES
|
|
|
204
204
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId>
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
207
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/init.ts)_
|
|
208
208
|
|
|
209
209
|
## `sanity-run blueprints logs`
|
|
210
210
|
|
|
@@ -226,7 +226,7 @@ EXAMPLES
|
|
|
226
226
|
$ sanity-run blueprints logs --watch
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
229
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/logs.ts)_
|
|
230
230
|
|
|
231
231
|
## `sanity-run blueprints plan`
|
|
232
232
|
|
|
@@ -243,7 +243,7 @@ EXAMPLES
|
|
|
243
243
|
$ sanity-run blueprints plan
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
246
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/blueprints/plan.ts)_
|
|
247
247
|
|
|
248
248
|
## `sanity-run functions dev`
|
|
249
249
|
|
|
@@ -263,7 +263,7 @@ EXAMPLES
|
|
|
263
263
|
$ sanity-run functions dev --port 8974
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
266
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/functions/dev.ts)_
|
|
267
267
|
|
|
268
268
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
269
269
|
|
|
@@ -285,7 +285,7 @@ EXAMPLES
|
|
|
285
285
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
288
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/functions/env/add.ts)_
|
|
289
289
|
|
|
290
290
|
## `sanity-run functions env list NAME`
|
|
291
291
|
|
|
@@ -305,7 +305,7 @@ EXAMPLES
|
|
|
305
305
|
$ sanity-run functions env list MyFunction
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
308
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/functions/env/list.ts)_
|
|
309
309
|
|
|
310
310
|
## `sanity-run functions env remove NAME KEY`
|
|
311
311
|
|
|
@@ -326,7 +326,7 @@ EXAMPLES
|
|
|
326
326
|
$ sanity-run functions env remove MyFunction API_URL
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
329
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/functions/env/remove.ts)_
|
|
330
330
|
|
|
331
331
|
## `sanity-run functions logs NAME`
|
|
332
332
|
|
|
@@ -360,7 +360,7 @@ EXAMPLES
|
|
|
360
360
|
$ sanity-run functions logs <name> --delete
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
363
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/functions/logs.ts)_
|
|
364
364
|
|
|
365
365
|
## `sanity-run functions test NAME`
|
|
366
366
|
|
|
@@ -393,7 +393,7 @@ EXAMPLES
|
|
|
393
393
|
$ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
|
|
394
394
|
```
|
|
395
395
|
|
|
396
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v7.
|
|
396
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v7.4.0/src/commands/functions/test.ts)_
|
|
397
397
|
|
|
398
398
|
## `sanity-run help [COMMAND]`
|
|
399
399
|
|
|
@@ -2,9 +2,12 @@ export * as assets from './assets.js';
|
|
|
2
2
|
export * as blueprint from './blueprint.js';
|
|
3
3
|
export * as logs from './logs.js';
|
|
4
4
|
export * as operations from './operations.js';
|
|
5
|
-
export * as projects from './projects.js';
|
|
6
5
|
export * as resources from './resources.js';
|
|
7
6
|
export * as stacks from './stacks.js';
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use actions/sanity/projects.js instead
|
|
9
|
+
*/
|
|
10
|
+
export * as projects from '../sanity/projects.js';
|
|
8
11
|
import type { Stack } from '../../utils/types.js';
|
|
9
12
|
import type { BlueprintParserError } from '../../utils/types.js';
|
|
10
13
|
import { readLocalBlueprint } from './blueprint.js';
|
|
@@ -2,9 +2,12 @@ export * as assets from './assets.js';
|
|
|
2
2
|
export * as blueprint from './blueprint.js';
|
|
3
3
|
export * as logs from './logs.js';
|
|
4
4
|
export * as operations from './operations.js';
|
|
5
|
-
export * as projects from './projects.js';
|
|
6
5
|
export * as resources from './resources.js';
|
|
7
6
|
export * as stacks from './stacks.js';
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use actions/sanity/projects.js instead
|
|
9
|
+
*/
|
|
10
|
+
export * as projects from '../sanity/projects.js';
|
|
8
11
|
import { readLocalBlueprint } from './blueprint.js';
|
|
9
12
|
import { getStack } from './stacks.js';
|
|
10
13
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as projects from './projects.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as projects from './projects.js';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export declare const projectsApiPath: string;
|
|
2
|
+
export declare const orgsApiPath: string;
|
|
3
|
+
export interface Project {
|
|
2
4
|
id: string;
|
|
3
5
|
displayName: string;
|
|
4
6
|
studioHost: string | null;
|
|
@@ -18,6 +20,21 @@ interface ListProjectsResponse {
|
|
|
18
20
|
export declare function listProjects({ token }: {
|
|
19
21
|
token: string;
|
|
20
22
|
}): Promise<ListProjectsResponse>;
|
|
23
|
+
interface GroupedProjectsByOrganizationResponse {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
error: string | null;
|
|
26
|
+
organizations: GroupedProjects[];
|
|
27
|
+
}
|
|
28
|
+
interface GroupedProjects {
|
|
29
|
+
organization: {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
projects?: Project[];
|
|
34
|
+
}
|
|
35
|
+
export declare function groupProjectsByOrganization({ token, }: {
|
|
36
|
+
token: string;
|
|
37
|
+
}): Promise<GroupedProjectsByOrganizationResponse>;
|
|
21
38
|
interface GetProjectResponse {
|
|
22
39
|
ok: boolean;
|
|
23
40
|
error: string | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import config from '../../config.js';
|
|
2
|
+
const { apiUrl } = config;
|
|
3
|
+
export const projectsApiPath = `${apiUrl}v2021-06-07/projects`;
|
|
4
|
+
export const orgsApiPath = `${apiUrl}v2021-06-07/organizations`;
|
|
5
|
+
export async function listProjects({ token }) {
|
|
6
|
+
const projectsFetch = await fetch(projectsApiPath, {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${token}`,
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
const projects = await projectsFetch.json();
|
|
14
|
+
return {
|
|
15
|
+
ok: projectsFetch.ok,
|
|
16
|
+
error: projectsFetch.ok ? null : projects.error?.message,
|
|
17
|
+
projects,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export async function groupProjectsByOrganization({ token, }) {
|
|
21
|
+
const projectsResponse = await listProjects({ token });
|
|
22
|
+
if (!projectsResponse.ok) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: projectsResponse.error,
|
|
26
|
+
organizations: [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const orgsFetch = await fetch(orgsApiPath, {
|
|
30
|
+
method: 'GET',
|
|
31
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
32
|
+
});
|
|
33
|
+
if (!orgsFetch.ok) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: orgsFetch.statusText,
|
|
37
|
+
organizations: [],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const organizations = await orgsFetch.json();
|
|
41
|
+
const orgsWithProjects = organizations.map(({ name, id }) => {
|
|
42
|
+
const projects = projectsResponse.projects.filter((project) => project.organizationId === id);
|
|
43
|
+
return { organization: { name, id }, projects };
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
ok: true,
|
|
47
|
+
error: null,
|
|
48
|
+
organizations: orgsWithProjects,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export async function getProject({ token, projectId, }) {
|
|
52
|
+
const response = await fetch(`${projectsApiPath}/${projectId}`, {
|
|
53
|
+
method: 'GET',
|
|
54
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
55
|
+
});
|
|
56
|
+
const project = await response.json();
|
|
57
|
+
return {
|
|
58
|
+
ok: response.ok,
|
|
59
|
+
error: response.ok ? null : project.error?.message,
|
|
60
|
+
project,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -130,8 +130,8 @@ async function promptForFunctionType() {
|
|
|
130
130
|
message: 'Choose function type:',
|
|
131
131
|
choices: [
|
|
132
132
|
{ name: 'Document Publish', value: 'document-publish' },
|
|
133
|
-
{ name: 'Document Create', value: 'document-create', disabled:
|
|
134
|
-
{ name: 'Document Delete', value: 'document-delete', disabled:
|
|
133
|
+
{ name: 'Document Create', value: 'document-create', disabled: '(Coming soon)' },
|
|
134
|
+
{ name: 'Document Delete', value: 'document-delete', disabled: '(Coming soon)' },
|
|
135
135
|
],
|
|
136
136
|
default: 'document-publish',
|
|
137
137
|
},
|
|
@@ -3,9 +3,10 @@ import highlight from 'color-json';
|
|
|
3
3
|
import inquirer from 'inquirer';
|
|
4
4
|
import ora from 'ora';
|
|
5
5
|
import { BLUEPRINT_CONFIG_FILE, BLUEPRINT_DIR, writeConfigFile, } from '../../actions/blueprints/blueprint.js';
|
|
6
|
-
import { getProject, listProjects } from '../../actions/blueprints/projects.js';
|
|
7
6
|
import { createStack, getStack, listStacks } from '../../actions/blueprints/stacks.js';
|
|
7
|
+
import { getProject } from '../../actions/sanity/projects.js';
|
|
8
8
|
import { niceId, warn } from '../../utils/display/presenters.js';
|
|
9
|
+
import { promptForProject } from '../../utils/display/prompt.js';
|
|
9
10
|
export async function blueprintConfigCore(options) {
|
|
10
11
|
const { bin = 'sanity', log, token, flags } = options;
|
|
11
12
|
const { edit: editConfig = false, 'test-config': testConfig = false, 'project-id': flagProjectId, 'stack-id': flagStackId, } = flags;
|
|
@@ -53,10 +54,10 @@ export async function blueprintConfigCore(options) {
|
|
|
53
54
|
// editing...
|
|
54
55
|
if (editConfig) {
|
|
55
56
|
const updatedProjectId = flagProjectId ||
|
|
56
|
-
(await
|
|
57
|
+
(await promptForProject({
|
|
57
58
|
token,
|
|
58
59
|
knownProjectId: configProjectId,
|
|
59
|
-
}));
|
|
60
|
+
})).projectId;
|
|
60
61
|
if (!updatedProjectId) {
|
|
61
62
|
return {
|
|
62
63
|
success: false,
|
|
@@ -134,29 +135,6 @@ export async function blueprintConfigCore(options) {
|
|
|
134
135
|
return { success: false, error: 'Unknown error' };
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
async function promptForProjectId({ token, knownProjectId, }) {
|
|
138
|
-
const { ok, projects, error } = await listProjects({ token });
|
|
139
|
-
if (!ok) {
|
|
140
|
-
throw new Error(error ?? 'Unknown error listing projects');
|
|
141
|
-
}
|
|
142
|
-
if (projects.length === 0) {
|
|
143
|
-
throw new Error('No Sanity projects found. Use `npx sanity init` to create one.');
|
|
144
|
-
}
|
|
145
|
-
const projectChoices = projects.map(({ displayName, id: projectId }) => ({
|
|
146
|
-
name: `"${displayName}" ${niceId(projectId)}`,
|
|
147
|
-
value: projectId,
|
|
148
|
-
}));
|
|
149
|
-
const { pickedProjectId } = await inquirer.prompt([
|
|
150
|
-
{
|
|
151
|
-
type: 'list',
|
|
152
|
-
name: 'pickedProjectId',
|
|
153
|
-
message: 'Select your Sanity project:',
|
|
154
|
-
choices: projectChoices,
|
|
155
|
-
default: knownProjectId,
|
|
156
|
-
},
|
|
157
|
-
]);
|
|
158
|
-
return pickedProjectId;
|
|
159
|
-
}
|
|
160
138
|
async function promptForStackId({ token, projectId, knownStackId, }) {
|
|
161
139
|
const auth = { token, projectId };
|
|
162
140
|
// get stacks for selected project
|
|
@@ -3,9 +3,10 @@ import { cwd } from 'node:process';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
5
|
import { BLUEPRINT_CONFIG_FILE, BLUEPRINT_DIR, findBlueprintFile, writeBlueprintToDisk, writeConfigFile, } from '../../actions/blueprints/blueprint.js';
|
|
6
|
-
import { getProject, listProjects } from '../../actions/blueprints/projects.js';
|
|
7
6
|
import { createStack, getStack, listStacks } from '../../actions/blueprints/stacks.js';
|
|
7
|
+
import { getProject } from '../../actions/sanity/projects.js';
|
|
8
8
|
import { niceId } from '../../utils/display/presenters.js';
|
|
9
|
+
import { promptForProject } from '../../utils/display/prompt.js';
|
|
9
10
|
const LAUNCH_LIMIT_STACK_PER_PROJECT = true;
|
|
10
11
|
export async function blueprintInitCore(options) {
|
|
11
12
|
const { log, token, args, flags } = options;
|
|
@@ -26,7 +27,7 @@ export async function blueprintInitCore(options) {
|
|
|
26
27
|
let projectId = flagProjectId;
|
|
27
28
|
let stackId = flagStackId;
|
|
28
29
|
if (!projectId) {
|
|
29
|
-
const pickedProject = await promptForProject(token);
|
|
30
|
+
const pickedProject = await promptForProject({ token });
|
|
30
31
|
projectId = pickedProject.projectId;
|
|
31
32
|
}
|
|
32
33
|
if (flagStackName) {
|
|
@@ -76,37 +77,15 @@ async function promptForBlueprintType() {
|
|
|
76
77
|
name: 'pickedBlueprintsType',
|
|
77
78
|
message: 'Choose a blueprint type:',
|
|
78
79
|
choices: [
|
|
79
|
-
{ name: 'JSON
|
|
80
|
-
{ name: '
|
|
81
|
-
{ name: '
|
|
80
|
+
{ name: 'JSON', value: 'json' },
|
|
81
|
+
{ name: 'TypeScript', value: 'ts', disabled: '(Coming soon)' },
|
|
82
|
+
{ name: 'JavaScript', value: 'js', disabled: '(Coming soon)' },
|
|
82
83
|
],
|
|
83
84
|
default: 'json',
|
|
84
85
|
},
|
|
85
86
|
]);
|
|
86
87
|
return pickedBlueprintsType;
|
|
87
88
|
}
|
|
88
|
-
async function promptForProject(token) {
|
|
89
|
-
const { ok: projectsOk, error: projectsErr, projects } = await listProjects({ token });
|
|
90
|
-
if (!projectsOk) {
|
|
91
|
-
throw new Error(projectsErr ?? 'Unknown error listing projects');
|
|
92
|
-
}
|
|
93
|
-
if (projects.length === 0) {
|
|
94
|
-
throw new Error('No Sanity projects found. Use `npx sanity init` to create one.');
|
|
95
|
-
}
|
|
96
|
-
const projectChoices = projects.map(({ displayName, id: projectId }) => ({
|
|
97
|
-
name: `"${displayName}" ${niceId(projectId)}`,
|
|
98
|
-
value: { projectId, displayName },
|
|
99
|
-
}));
|
|
100
|
-
const { pickedProject } = await inquirer.prompt([
|
|
101
|
-
{
|
|
102
|
-
type: 'list',
|
|
103
|
-
name: 'pickedProject',
|
|
104
|
-
message: 'Select your Sanity project:',
|
|
105
|
-
choices: projectChoices,
|
|
106
|
-
},
|
|
107
|
-
]);
|
|
108
|
-
return pickedProject;
|
|
109
|
-
}
|
|
110
89
|
async function promptForStackId({ projectId, token, }) {
|
|
111
90
|
const { ok: stacksOk, error: stacksErr, stacks } = await listStacks({ token, projectId });
|
|
112
91
|
if (!stacksOk) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt the user for a Project after selecting an Organization.
|
|
3
|
+
* @param token - The Sanity API token
|
|
4
|
+
* @returns The selected project, with the projectId and displayName
|
|
5
|
+
* @throws {Error} If the user does not have any projects or if the API call fails
|
|
6
|
+
*/
|
|
7
|
+
export declare function promptForProject({ token, knownOrganizationId, knownProjectId, }: {
|
|
8
|
+
token: string;
|
|
9
|
+
knownOrganizationId?: string;
|
|
10
|
+
knownProjectId?: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
projectId: string;
|
|
13
|
+
displayName: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import { groupProjectsByOrganization } from '../../actions/sanity/projects.js';
|
|
3
|
+
import { niceId } from './presenters.js';
|
|
4
|
+
/**
|
|
5
|
+
* Prompt the user for a Project after selecting an Organization.
|
|
6
|
+
* @param token - The Sanity API token
|
|
7
|
+
* @returns The selected project, with the projectId and displayName
|
|
8
|
+
* @throws {Error} If the user does not have any projects or if the API call fails
|
|
9
|
+
*/
|
|
10
|
+
export async function promptForProject({ token, knownOrganizationId, knownProjectId, }) {
|
|
11
|
+
const { ok, error, organizations } = await groupProjectsByOrganization({ token });
|
|
12
|
+
if (!ok) {
|
|
13
|
+
throw new Error(error ?? 'Unknown error listing projects');
|
|
14
|
+
}
|
|
15
|
+
if (organizations.length === 0) {
|
|
16
|
+
throw new Error('No Sanity projects found. Use `npx sanity init` to create one.');
|
|
17
|
+
}
|
|
18
|
+
let projects;
|
|
19
|
+
if (organizations.length > 1) {
|
|
20
|
+
const orgChoices = organizations.map(({ organization, projects }) => ({
|
|
21
|
+
name: `"${organization.name}" ${niceId(organization.id)}`,
|
|
22
|
+
value: { organization, projects },
|
|
23
|
+
disabled: !projects || projects.length === 0 ? '(0 Projects)' : false,
|
|
24
|
+
}));
|
|
25
|
+
const { pickedOrganization } = await inquirer.prompt([
|
|
26
|
+
{
|
|
27
|
+
type: 'list',
|
|
28
|
+
name: 'pickedOrganization',
|
|
29
|
+
message: 'Which Organization would you like to use?',
|
|
30
|
+
choices: orgChoices,
|
|
31
|
+
default: knownOrganizationId,
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
projects = pickedOrganization.projects;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
projects = organizations[0].projects;
|
|
38
|
+
}
|
|
39
|
+
const projectChoices = projects.map(({ displayName, id: projectId }) => ({
|
|
40
|
+
name: `"${displayName}" ${niceId(projectId)}`,
|
|
41
|
+
value: { projectId, displayName },
|
|
42
|
+
}));
|
|
43
|
+
const { pickedProject } = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
type: 'list',
|
|
46
|
+
name: 'pickedProject',
|
|
47
|
+
message: 'Which Project would you like to use?',
|
|
48
|
+
choices: projectChoices,
|
|
49
|
+
default: knownProjectId,
|
|
50
|
+
},
|
|
51
|
+
]);
|
|
52
|
+
return pickedProject;
|
|
53
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare function validToken(): Promise<string>;
|
|
2
|
-
export declare function validTokenOrErrorMessage(): Promise<{
|
|
1
|
+
export declare function validToken(maybeToken?: string): Promise<string>;
|
|
2
|
+
export declare function validTokenOrErrorMessage(maybeToken?: string): Promise<{
|
|
3
3
|
token: string;
|
|
4
4
|
error?: never;
|
|
5
5
|
} | {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import config from '../config.js';
|
|
2
|
-
export async function validToken() {
|
|
2
|
+
export async function validToken(maybeToken) {
|
|
3
3
|
if (config.isTest)
|
|
4
4
|
return 'token';
|
|
5
|
-
const token = config.token;
|
|
5
|
+
const token = maybeToken ?? config.token;
|
|
6
6
|
if (!token)
|
|
7
7
|
throw new Error('NO_TOKEN');
|
|
8
8
|
const url = `${config.apiUrl}v2025-04-23/users/me`;
|
|
@@ -21,9 +21,9 @@ export async function validToken() {
|
|
|
21
21
|
}
|
|
22
22
|
throw new Error('SERVER_ERROR', { cause: response.statusText });
|
|
23
23
|
}
|
|
24
|
-
export async function validTokenOrErrorMessage() {
|
|
24
|
+
export async function validTokenOrErrorMessage(maybeToken) {
|
|
25
25
|
try {
|
|
26
|
-
const token = await validToken();
|
|
26
|
+
const token = await validToken(maybeToken);
|
|
27
27
|
return { token };
|
|
28
28
|
}
|
|
29
29
|
catch (e) {
|
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": "7.
|
|
4
|
+
"version": "7.4.0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"types": "./dist/actions/functions/index.d.ts",
|
|
24
24
|
"import": "./dist/actions/functions/index.js"
|
|
25
25
|
},
|
|
26
|
+
"./actions/sanity": {
|
|
27
|
+
"types": "./dist/actions/sanity/index.d.ts",
|
|
28
|
+
"import": "./dist/actions/sanity/index.js"
|
|
29
|
+
},
|
|
26
30
|
"./cores": {
|
|
27
31
|
"types": "./dist/cores/index.d.ts",
|
|
28
32
|
"import": "./dist/cores/index.js"
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import config from '../../config.js';
|
|
2
|
-
const { apiUrl } = config;
|
|
3
|
-
const projectsUrl = `${apiUrl}v2021-06-07/projects`;
|
|
4
|
-
export async function listProjects({ token }) {
|
|
5
|
-
const response = await fetch(projectsUrl, {
|
|
6
|
-
method: 'GET',
|
|
7
|
-
headers: {
|
|
8
|
-
Authorization: `Bearer ${token}`,
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
const projects = await response.json();
|
|
13
|
-
return {
|
|
14
|
-
ok: response.ok,
|
|
15
|
-
error: response.ok ? null : projects.error?.message,
|
|
16
|
-
projects,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export async function getProject({ token, projectId, }) {
|
|
20
|
-
const response = await fetch(`${projectsUrl}/${projectId}`, {
|
|
21
|
-
method: 'GET',
|
|
22
|
-
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
23
|
-
});
|
|
24
|
-
const project = await response.json();
|
|
25
|
-
return {
|
|
26
|
-
ok: response.ok,
|
|
27
|
-
error: response.ok ? null : project.error?.message,
|
|
28
|
-
project,
|
|
29
|
-
};
|
|
30
|
-
}
|