@sanity/cli 3.75.1 → 3.76.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/lib/index.d.mts CHANGED
@@ -120,6 +120,7 @@ export declare interface CliConfig {
120
120
  * @internal
121
121
  */
122
122
  __experimental_coreAppConfiguration?: {
123
+ organizationId?: string
123
124
  appLocation?: string
124
125
  }
125
126
  }
package/lib/index.d.ts CHANGED
@@ -120,6 +120,7 @@ export declare interface CliConfig {
120
120
  * @internal
121
121
  */
122
122
  __experimental_coreAppConfiguration?: {
123
+ organizationId?: string
123
124
  appLocation?: string
124
125
  }
125
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli",
3
- "version": "3.75.1",
3
+ "version": "3.76.0",
4
4
  "description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
5
5
  "keywords": [
6
6
  "sanity",
@@ -57,11 +57,11 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@babel/traverse": "^7.23.5",
60
- "@sanity/client": "^6.27.2",
61
- "@sanity/codegen": "3.75.1",
60
+ "@sanity/client": "^6.28.0",
61
+ "@sanity/codegen": "3.76.0",
62
62
  "@sanity/telemetry": "^0.7.7",
63
63
  "@sanity/template-validator": "^2.4.0",
64
- "@sanity/util": "3.75.1",
64
+ "@sanity/util": "3.76.0",
65
65
  "chalk": "^4.1.2",
66
66
  "debug": "^4.3.4",
67
67
  "decompress": "^4.2.0",
@@ -75,13 +75,13 @@
75
75
  "validate-npm-package-name": "^3.0.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@repo/package.config": "3.75.1",
79
- "@repo/test-config": "3.75.1",
78
+ "@repo/package.config": "3.76.0",
79
+ "@repo/test-config": "3.76.0",
80
80
  "@rexxars/gitconfiglocal": "^3.0.1",
81
81
  "@rollup/plugin-node-resolve": "^15.2.3",
82
82
  "@sanity/eslint-config-studio": "^4.0.0",
83
83
  "@sanity/generate-help-url": "^3.0.0",
84
- "@sanity/types": "3.75.1",
84
+ "@sanity/types": "3.76.0",
85
85
  "@types/babel__traverse": "^7.20.5",
86
86
  "@types/configstore": "^5.0.1",
87
87
  "@types/cpx": "^1.5.2",
@@ -133,5 +133,5 @@
133
133
  "engines": {
134
134
  "node": ">=18"
135
135
  },
136
- "gitHead": "3eacacacc54c31f8f8a0036170a0e578d816ddbe"
136
+ "gitHead": "36701303cc8e245860ad2da5457c5ad227e07f42"
137
137
  }
@@ -130,7 +130,10 @@ export async function bootstrapLocalTemplate(
130
130
 
131
131
  // ...and a CLI config (`sanity.cli.[ts|js]`)
132
132
  const cliConfig = isCoreAppTemplate
133
- ? createCoreAppCliConfig({appLocation: template.appLocation!})
133
+ ? createCoreAppCliConfig({
134
+ appLocation: template.appLocation!,
135
+ organizationId: variables.organizationId,
136
+ })
134
137
  : createCliConfig({
135
138
  projectId: variables.projectId,
136
139
  dataset: variables.dataset,
@@ -5,7 +5,8 @@ import {defineCliConfig} from 'sanity/cli'
5
5
 
6
6
  export default defineCliConfig({
7
7
  __experimental_coreAppConfiguration: {
8
- appLocation: '%appLocation%'
8
+ organizationId: '%organizationId%',
9
+ appLocation: '%appLocation%',
9
10
  },
10
11
  })
11
12
  `
@@ -36,6 +36,7 @@ export interface GenerateConfigOptions {
36
36
  projectName?: string
37
37
  sourceName?: string
38
38
  sourceTitle?: string
39
+ organizationId?: string
39
40
  }
40
41
  }
41
42
 
@@ -277,8 +277,9 @@ export default async function initSanity(
277
277
  // skip project / dataset prompting
278
278
  const isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : false // Default to false
279
279
 
280
- // We're authenticated, now lets select or create a project
281
- const {projectId, displayName, isFirstProject, datasetName, schemaUrl} = await getProjectDetails()
280
+ // We're authenticated, now lets select or create a project (for studios) or org (for core apps)
281
+ const {projectId, displayName, isFirstProject, datasetName, schemaUrl, organizationId} =
282
+ await getProjectDetails()
282
283
 
283
284
  const sluggedName = deburr(displayName.toLowerCase())
284
285
  .replace(/\s+/g, '-')
@@ -715,6 +716,7 @@ export default async function initSanity(
715
716
  displayName: string
716
717
  isFirstProject: boolean
717
718
  schemaUrl?: string
719
+ organizationId?: string
718
720
  }> {
719
721
  // If we're doing a quickstart, we don't need to prompt for project details
720
722
  if (flags.quickstart) {
@@ -731,11 +733,17 @@ export default async function initSanity(
731
733
  }
732
734
 
733
735
  if (isCoreAppTemplate) {
736
+ const client = apiClient({requireUser: true, requireProject: false})
737
+ const organizations = await client.request({uri: '/organizations'})
738
+
739
+ const coreAppOrganizationId = await getOrganizationId(organizations)
740
+
734
741
  return {
735
742
  projectId: '',
736
743
  displayName: '',
737
- isFirstProject: false,
738
744
  datasetName: '',
745
+ isFirstProject: false,
746
+ organizationId: coreAppOrganizationId,
739
747
  }
740
748
  }
741
749
 
@@ -1091,6 +1099,7 @@ export default async function initSanity(
1091
1099
  dataset: datasetName,
1092
1100
  projectId,
1093
1101
  projectName: displayName || answers.projectName,
1102
+ organizationId,
1094
1103
  }
1095
1104
 
1096
1105
  if (remoteTemplateInfo) {
@@ -1230,12 +1239,12 @@ export default async function initSanity(
1230
1239
  }
1231
1240
 
1232
1241
  async function getOrganizationId(organizations: ProjectOrganization[]) {
1233
- let organizationId = flags.organization
1242
+ let orgId = flags.organization
1234
1243
  if (unattended) {
1235
- return organizationId || undefined
1244
+ return orgId || undefined
1236
1245
  }
1237
1246
 
1238
- const shouldPrompt = organizations.length > 0 && !organizationId
1247
+ const shouldPrompt = organizations.length > 0 && !orgId
1239
1248
  if (shouldPrompt) {
1240
1249
  debug(`User has ${organizations.length} organization(s), checking attach access`)
1241
1250
  const withGrant = await getOrganizationsWithAttachGrant(organizations)
@@ -1261,18 +1270,18 @@ export default async function initSanity(
1261
1270
  })
1262
1271
 
1263
1272
  if (chosenOrg && chosenOrg !== 'none') {
1264
- organizationId = chosenOrg
1273
+ orgId = chosenOrg
1265
1274
  }
1266
- } else if (organizationId) {
1267
- debug(`User has defined organization flag explicitly (%s)`, organizationId)
1275
+ } else if (orgId) {
1276
+ debug(`User has defined organization flag explicitly (%s)`, orgId)
1268
1277
  } else if (organizations.length === 0) {
1269
1278
  debug('User has no organizations, skipping selection prompt')
1270
1279
  }
1271
1280
 
1272
- return organizationId || undefined
1281
+ return orgId || undefined
1273
1282
  }
1274
1283
 
1275
- async function hasProjectAttachGrant(organizationId: string) {
1284
+ async function hasProjectAttachGrant(orgId: string) {
1276
1285
  const requiredGrantGroup = 'sanity.organization.projects'
1277
1286
  const requiredGrant = 'attach'
1278
1287
 
@@ -1280,7 +1289,7 @@ export default async function initSanity(
1280
1289
  .clone()
1281
1290
  .config({apiVersion: 'v2021-06-07'})
1282
1291
 
1283
- const grants = await client.request({uri: `organizations/${organizationId}/grants`})
1292
+ const grants = await client.request({uri: `organizations/${orgId}/grants`})
1284
1293
  const group: {grants: {name: string}[]}[] = grants[requiredGrantGroup] || []
1285
1294
  return group.some(
1286
1295
  (resource) =>
package/src/types.ts CHANGED
@@ -352,6 +352,7 @@ export interface CliConfig {
352
352
  * @internal
353
353
  */
354
354
  __experimental_coreAppConfiguration?: {
355
+ organizationId?: string
355
356
  appLocation?: string
356
357
  }
357
358
  }