@sanity/cli 6.0.0-alpha.3 → 6.0.0-alpha.4
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/dist/actions/auth/login/{index.js → login.js} +1 -1
- package/dist/actions/auth/login/{index.js.map → login.js.map} +1 -1
- package/dist/actions/organizations/getOrganizationChoices.d.ts +6 -0
- package/dist/actions/organizations/getOrganizationChoices.js +23 -0
- package/dist/actions/organizations/getOrganizationChoices.js.map +1 -0
- package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.d.ts +2 -0
- package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.js +9 -0
- package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.js.map +1 -0
- package/dist/actions/organizations/hasProjectAttachGrant.d.ts +1 -0
- package/dist/actions/organizations/hasProjectAttachGrant.js +24 -0
- package/dist/actions/organizations/hasProjectAttachGrant.js.map +1 -0
- package/dist/actions/schema/utils/schemaStoreValidation.js +2 -2
- package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
- package/dist/commands/__tests__/init/init.authentication.test.js +60 -0
- package/dist/commands/__tests__/init/init.authentication.test.js.map +1 -0
- package/dist/commands/__tests__/init/init.create-new-project.test.js +196 -0
- package/dist/commands/__tests__/init/init.create-new-project.test.js.map +1 -0
- package/dist/commands/__tests__/init/init.plan.test.js +220 -0
- package/dist/commands/__tests__/init/init.plan.test.js.map +1 -0
- package/dist/commands/__tests__/init/init.setup.test.js +279 -0
- package/dist/commands/__tests__/init/init.setup.test.js.map +1 -0
- package/dist/commands/__tests__/migration.test.js +119 -0
- package/dist/commands/__tests__/migration.test.js.map +1 -0
- package/dist/commands/backup/__tests__/download.test.js +3 -3
- package/dist/commands/backup/__tests__/download.test.js.map +1 -1
- package/dist/commands/dataset/__tests__/import.test.js +2 -2
- package/dist/commands/dataset/__tests__/import.test.js.map +1 -1
- package/dist/commands/documents/__tests__/query.test.js +3 -3
- package/dist/commands/documents/__tests__/query.test.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.js +151 -18
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +1 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/services/organizations.d.ts +40 -0
- package/dist/services/organizations.js +41 -0
- package/dist/services/organizations.js.map +1 -0
- package/dist/services/projects.d.ts +20 -0
- package/dist/services/projects.js +30 -1
- package/dist/services/projects.js.map +1 -1
- package/dist/services/user.d.ts +2 -0
- package/dist/services/user.js +11 -0
- package/dist/services/user.js.map +1 -0
- package/oclif.config.js +6 -1
- package/oclif.manifest.json +33 -184
- package/package.json +7 -7
- package/dist/actions/migration/getMigrationRootDirectory.d.ts +0 -2
- package/dist/actions/migration/getMigrationRootDirectory.js +0 -14
- package/dist/actions/migration/getMigrationRootDirectory.js.map +0 -1
- package/dist/actions/migration/resolveMigrations.d.ts +0 -19
- package/dist/actions/migration/resolveMigrations.js +0 -43
- package/dist/actions/migration/resolveMigrations.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/minimalAdvanced.test.js +0 -65
- package/dist/actions/migration/templates/__tests__/minimalAdvanced.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/minimalSimple.test.js +0 -145
- package/dist/actions/migration/templates/__tests__/minimalSimple.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/renameField.test.js +0 -63
- package/dist/actions/migration/templates/__tests__/renameField.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/renameType.test.js +0 -61
- package/dist/actions/migration/templates/__tests__/renameType.test.js.map +0 -1
- package/dist/actions/migration/templates/__tests__/stringToPTE.test.js +0 -87
- package/dist/actions/migration/templates/__tests__/stringToPTE.test.js.map +0 -1
- package/dist/actions/migration/templates/index.d.ts +0 -5
- package/dist/actions/migration/templates/index.js +0 -7
- package/dist/actions/migration/templates/index.js.map +0 -1
- package/dist/actions/migration/templates/minimalAdvanced.d.ts +0 -4
- package/dist/actions/migration/templates/minimalAdvanced.js +0 -21
- package/dist/actions/migration/templates/minimalAdvanced.js.map +0 -1
- package/dist/actions/migration/templates/minimalSimple.d.ts +0 -4
- package/dist/actions/migration/templates/minimalSimple.js +0 -61
- package/dist/actions/migration/templates/minimalSimple.js.map +0 -1
- package/dist/actions/migration/templates/renameField.d.ts +0 -4
- package/dist/actions/migration/templates/renameField.js +0 -20
- package/dist/actions/migration/templates/renameField.js.map +0 -1
- package/dist/actions/migration/templates/renameType.d.ts +0 -4
- package/dist/actions/migration/templates/renameType.js +0 -19
- package/dist/actions/migration/templates/renameType.js.map +0 -1
- package/dist/actions/migration/templates/stringToPTE.d.ts +0 -4
- package/dist/actions/migration/templates/stringToPTE.js +0 -32
- package/dist/actions/migration/templates/stringToPTE.js.map +0 -1
- package/dist/commands/__tests__/init.test.js +0 -411
- package/dist/commands/__tests__/init.test.js.map +0 -1
- package/dist/commands/migration/__tests__/create.test.js +0 -296
- package/dist/commands/migration/__tests__/create.test.js.map +0 -1
- package/dist/commands/migration/__tests__/list.test.js +0 -166
- package/dist/commands/migration/__tests__/list.test.js.map +0 -1
- package/dist/commands/migration/__tests__/run.test.js +0 -481
- package/dist/commands/migration/__tests__/run.test.js.map +0 -1
- package/dist/commands/migration/create.d.ts +0 -17
- package/dist/commands/migration/create.js +0 -143
- package/dist/commands/migration/create.js.map +0 -1
- package/dist/commands/migration/list.d.ts +0 -9
- package/dist/commands/migration/list.js +0 -61
- package/dist/commands/migration/list.js.map +0 -1
- package/dist/commands/migration/run.d.ts +0 -26
- package/dist/commands/migration/run.js +0 -271
- package/dist/commands/migration/run.js.map +0 -1
- package/dist/util/migration/constants.d.ts +0 -3
- package/dist/util/migration/constants.js +0 -10
- package/dist/util/migration/constants.js.map +0 -1
- package/dist/util/migration/ensureApiVersionFormat.d.ts +0 -9
- package/dist/util/migration/ensureApiVersionFormat.js +0 -16
- package/dist/util/migration/ensureApiVersionFormat.js.map +0 -1
- package/dist/util/migration/prettyMutationFormatter.d.ts +0 -8
- package/dist/util/migration/prettyMutationFormatter.js +0 -141
- package/dist/util/migration/prettyMutationFormatter.js.map +0 -1
- package/dist/utils/migration/resolveMigrationScript.d.ts +0 -44
- package/dist/utils/migration/resolveMigrationScript.js +0 -74
- package/dist/utils/migration/resolveMigrationScript.js.map +0 -1
- /package/dist/actions/auth/login/{index.d.ts → login.d.ts} +0 -0
package/dist/commands/init.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
// @Todo will remove by time migration of this command
|
|
1
|
+
// @Todo will remove by time migration of this command is complete
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */ import { Args, Flags } from '@oclif/core';
|
|
3
3
|
import { getCliToken, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
4
|
-
import { confirm } from '@sanity/cli-core/ux';
|
|
4
|
+
import { confirm, input, logSymbols, select, spinner } from '@sanity/cli-core/ux';
|
|
5
5
|
import { isHttpError } from '@sanity/client';
|
|
6
6
|
import { frameworks } from '@vercel/frameworks';
|
|
7
7
|
import { detectFrameworkRecord, LocalFileSystemDetector } from '@vercel/fs-detectors';
|
|
8
8
|
import { getProviderName } from '../actions/auth/getProviderName.js';
|
|
9
|
-
import { login } from '../actions/auth/login/
|
|
10
|
-
import {
|
|
9
|
+
import { login } from '../actions/auth/login/login.js';
|
|
10
|
+
import { determineAppTemplate } from '../actions/init/determineAppTemplate.js';
|
|
11
11
|
import { checkIsRemoteTemplate, getGitHubRepoInfo } from '../actions/init/remoteTemplate.js';
|
|
12
|
+
import { getOrganizationChoices } from '../actions/organizations/getOrganizationChoices.js';
|
|
13
|
+
import { getOrganizationsWithAttachGrantInfo } from '../actions/organizations/getOrganizationsWithAttachGrantInfo.js';
|
|
14
|
+
import { createDataset } from '../services/datasets.js';
|
|
15
|
+
import { createOrganization, listOrganizations } from '../services/organizations.js';
|
|
12
16
|
import { getPlanId, getPlanIdFromCoupon } from '../services/plans.js';
|
|
17
|
+
import { createProject } from '../services/projects.js';
|
|
18
|
+
import { getCliUser } from '../services/user.js';
|
|
13
19
|
const debug = subdebug('init');
|
|
14
20
|
export class InitCommand extends SanityCommand {
|
|
15
21
|
static args = {
|
|
@@ -159,7 +165,13 @@ export class InitCommand extends SanityCommand {
|
|
|
159
165
|
]
|
|
160
166
|
}),
|
|
161
167
|
project: Flags.string({
|
|
168
|
+
aliases: [
|
|
169
|
+
'project-id'
|
|
170
|
+
],
|
|
162
171
|
description: 'Project ID to use for the studio',
|
|
172
|
+
exclusive: [
|
|
173
|
+
'create-project'
|
|
174
|
+
],
|
|
163
175
|
helpValue: '<id>'
|
|
164
176
|
}),
|
|
165
177
|
'project-plan': Flags.string({
|
|
@@ -216,6 +228,7 @@ export class InitCommand extends SanityCommand {
|
|
|
216
228
|
};
|
|
217
229
|
async run() {
|
|
218
230
|
const { args, flags } = await this.parse(InitCommand);
|
|
231
|
+
const createProjectName = this.flags['create-project'];
|
|
219
232
|
// For backwards "compatibility" - we used to allow `sanity init plugin`,
|
|
220
233
|
// and no longer do - but instead of printing an error about an unknown
|
|
221
234
|
// _command_, we want to acknowledge that the user is trying to do something
|
|
@@ -234,10 +247,20 @@ export class InitCommand extends SanityCommand {
|
|
|
234
247
|
exit: 1
|
|
235
248
|
});
|
|
236
249
|
}
|
|
250
|
+
// Oclif doesn't support custom exclusive error messaging
|
|
251
|
+
if (this.flags.project && this.flags.organization) {
|
|
252
|
+
throw new Error('You have specified both a project and an organization. To move a project to an organization please visit https://www.sanity.io/manage');
|
|
253
|
+
}
|
|
254
|
+
const defaultConfig = this.flags['dataset-default'];
|
|
255
|
+
let _showDefaultConfigPrompt = !defaultConfig;
|
|
256
|
+
if (this.flags.dataset || this.flags.visibility || this.flags['dataset-default'] || this.isUnattended()) {
|
|
257
|
+
_showDefaultConfigPrompt = false;
|
|
258
|
+
}
|
|
237
259
|
const detectedFramework = await detectFrameworkRecord({
|
|
238
260
|
frameworkList: frameworks,
|
|
239
261
|
fs: new LocalFileSystemDetector(process.cwd())
|
|
240
262
|
});
|
|
263
|
+
const isNextJs = detectedFramework?.slug === 'nextjs';
|
|
241
264
|
let remoteTemplateInfo;
|
|
242
265
|
if (flags.template && checkIsRemoteTemplate(flags.template)) {
|
|
243
266
|
remoteTemplateInfo = await getGitHubRepoInfo(flags.template, flags['template-token']);
|
|
@@ -247,6 +270,13 @@ export class InitCommand extends SanityCommand {
|
|
|
247
270
|
exit: 1
|
|
248
271
|
});
|
|
249
272
|
}
|
|
273
|
+
// Checks flags are present when in unattended mode
|
|
274
|
+
if (this.isUnattended()) {
|
|
275
|
+
this.checkFlagsInUnattendedMode({
|
|
276
|
+
createProjectName,
|
|
277
|
+
isNextJs
|
|
278
|
+
});
|
|
279
|
+
}
|
|
250
280
|
// @todo
|
|
251
281
|
// trace.start()
|
|
252
282
|
// trace.log({
|
|
@@ -267,14 +297,78 @@ export class InitCommand extends SanityCommand {
|
|
|
267
297
|
// verify that the passed flags are valid. The complexity of this is hidden in the
|
|
268
298
|
// below plan methods, eventually returning a plan ID or undefined if we are told to
|
|
269
299
|
// use the default plan.
|
|
270
|
-
const
|
|
300
|
+
const planId = await this.getPlan();
|
|
271
301
|
let envFilenameDefault = '.env';
|
|
272
302
|
if (detectedFramework && detectedFramework.slug === 'nextjs') {
|
|
273
303
|
envFilenameDefault = '.env.local';
|
|
274
304
|
}
|
|
275
305
|
const _envFilename = typeof flags.env === 'string' ? flags.env : envFilenameDefault;
|
|
276
306
|
// If the user isn't already autenticated, make it so
|
|
277
|
-
await this.ensureAuthenticated();
|
|
307
|
+
const { user } = await this.ensureAuthenticated();
|
|
308
|
+
// skip project / dataset prompting
|
|
309
|
+
const template = this.flags.template;
|
|
310
|
+
const isAppTemplate = template ? determineAppTemplate(template) : false // Default to false
|
|
311
|
+
;
|
|
312
|
+
if (!isAppTemplate) {
|
|
313
|
+
this.log(`${logSymbols.success} Fetching existing projects`);
|
|
314
|
+
this.log('');
|
|
315
|
+
}
|
|
316
|
+
const _newProjectId = createProjectName && await this.createProject({
|
|
317
|
+
createProjectName,
|
|
318
|
+
planId,
|
|
319
|
+
user
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
checkFlagsInUnattendedMode({ createProjectName, isNextJs }) {
|
|
323
|
+
debug('Unattended mode, validating required options');
|
|
324
|
+
if (!this.flags['dataset']) {
|
|
325
|
+
throw new Error(`\`--dataset\` must be specified in unattended mode`);
|
|
326
|
+
}
|
|
327
|
+
// output-path is required in unattended mode when not using nextjs
|
|
328
|
+
if (!isNextJs && !this.flags['output-path']) {
|
|
329
|
+
throw new Error(`\`--output-path\` must be specified in unattended mode`);
|
|
330
|
+
}
|
|
331
|
+
if (!this.flags.project && !createProjectName) {
|
|
332
|
+
throw new Error('`--project <id>` or `--create-project <name>` must be specified in unattended mode');
|
|
333
|
+
}
|
|
334
|
+
if (createProjectName && !this.flags.organization) {
|
|
335
|
+
throw new Error('--create-project is not supported in unattended mode without an organization, please specify an organization with `--organization <id>`');
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async createProject({ createProjectName, planId, user }) {
|
|
339
|
+
debug('--create-project specified, creating a new project');
|
|
340
|
+
let orgForCreateProjectFlag = this.flags.organization;
|
|
341
|
+
if (!orgForCreateProjectFlag) {
|
|
342
|
+
debug('no organization specified, selecting one');
|
|
343
|
+
const organizations = await listOrganizations();
|
|
344
|
+
orgForCreateProjectFlag = await this.promptUserForOrganization({
|
|
345
|
+
organizations,
|
|
346
|
+
user
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
debug('creating a new project');
|
|
350
|
+
const createdProject = await createProject({
|
|
351
|
+
displayName: createProjectName.trim(),
|
|
352
|
+
metadata: {
|
|
353
|
+
coupon: this.flags.coupon
|
|
354
|
+
},
|
|
355
|
+
organizationId: orgForCreateProjectFlag,
|
|
356
|
+
subscription: planId ? {
|
|
357
|
+
planId
|
|
358
|
+
} : undefined
|
|
359
|
+
});
|
|
360
|
+
debug('Project with ID %s created', createdProject.projectId);
|
|
361
|
+
if (this.flags.dataset) {
|
|
362
|
+
debug('--dataset specified, creating dataset (%s)', this.flags.dataset);
|
|
363
|
+
const spin = spinner('Creating dataset').start();
|
|
364
|
+
await createDataset({
|
|
365
|
+
aclMode: this.flags.visibility,
|
|
366
|
+
datasetName: this.flags.dataset,
|
|
367
|
+
projectId: createdProject.projectId
|
|
368
|
+
});
|
|
369
|
+
spin.succeed();
|
|
370
|
+
}
|
|
371
|
+
return createdProject.projectId;
|
|
278
372
|
}
|
|
279
373
|
// @todo do we actually need to be authenticated for init? check flags and determine.
|
|
280
374
|
async ensureAuthenticated() {
|
|
@@ -284,12 +378,8 @@ export class InitCommand extends SanityCommand {
|
|
|
284
378
|
if (isAuthenticated) {
|
|
285
379
|
// It _appears_ we are authenticated, but the token might be invalid/expired,
|
|
286
380
|
// so we need to verify that we can actually make an authenticated request.
|
|
287
|
-
const client = await this.getGlobalApiClient({
|
|
288
|
-
apiVersion: INIT_API_VERSION,
|
|
289
|
-
requireUser: true
|
|
290
|
-
});
|
|
291
381
|
try {
|
|
292
|
-
user = await
|
|
382
|
+
user = await getCliUser();
|
|
293
383
|
} catch {
|
|
294
384
|
// assume that any error means that the token is invalid
|
|
295
385
|
isAuthenticated = false;
|
|
@@ -309,13 +399,8 @@ export class InitCommand extends SanityCommand {
|
|
|
309
399
|
output: this.output
|
|
310
400
|
});
|
|
311
401
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
apiVersion: INIT_API_VERSION,
|
|
315
|
-
requireUser: true
|
|
316
|
-
});
|
|
317
|
-
user = await client.users.getById('me');
|
|
318
|
-
this.log('You are logged in as %s using %s', user.email, getProviderName(user.provider));
|
|
402
|
+
user = await getCliUser();
|
|
403
|
+
this.log(`${logSymbols.success} You are logged in as ${user.email} using ${getProviderName(user.provider)}`);
|
|
319
404
|
return {
|
|
320
405
|
user
|
|
321
406
|
};
|
|
@@ -331,6 +416,54 @@ export class InitCommand extends SanityCommand {
|
|
|
331
416
|
return undefined;
|
|
332
417
|
}
|
|
333
418
|
}
|
|
419
|
+
async promptUserForNewOrganization(user) {
|
|
420
|
+
const name = await input({
|
|
421
|
+
default: user ? user.name : undefined,
|
|
422
|
+
message: 'Organization name:',
|
|
423
|
+
validate (input) {
|
|
424
|
+
if (input.length === 0) {
|
|
425
|
+
return 'Organization name cannot be empty';
|
|
426
|
+
} else if (input.length > 100) {
|
|
427
|
+
return 'Organization name cannot be longer than 100 characters';
|
|
428
|
+
}
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
const spin = spinner('Creating organization').start();
|
|
433
|
+
const organization = await createOrganization(name);
|
|
434
|
+
spin.succeed();
|
|
435
|
+
return organization;
|
|
436
|
+
}
|
|
437
|
+
async promptUserForOrganization({ organizations, user }) {
|
|
438
|
+
// If the user has no organizations, prompt them to create one with the same name as
|
|
439
|
+
// their user, but allow them to customize it if they want
|
|
440
|
+
if (organizations.length === 0) {
|
|
441
|
+
const newOrganization = await this.promptUserForNewOrganization(user);
|
|
442
|
+
return newOrganization.id;
|
|
443
|
+
}
|
|
444
|
+
// If the user has organizations, let them choose from them, but also allow them to
|
|
445
|
+
// create a new one in case they do not have access to any of them, or they want to
|
|
446
|
+
// create a personal/other organization.
|
|
447
|
+
debug(`User has ${organizations.length} organization(s), checking attach access`);
|
|
448
|
+
const withGrantInfo = await getOrganizationsWithAttachGrantInfo(organizations);
|
|
449
|
+
const withAttach = withGrantInfo.filter(({ hasAttachGrant })=>hasAttachGrant);
|
|
450
|
+
debug('User has attach access to %d organizations.', withAttach.length);
|
|
451
|
+
const organizationChoices = getOrganizationChoices(withAttach);
|
|
452
|
+
// If the user only has a single organization (and they have attach access to it),
|
|
453
|
+
// we'll default to that one. Otherwise, we'll default to the organization with the
|
|
454
|
+
// same name as the user if it exists.
|
|
455
|
+
const defaultOrganizationId = withAttach.length === 1 ? withAttach[0].organization.id : organizations.find((org)=>org.name === user?.name)?.id;
|
|
456
|
+
const chosenOrg = await select({
|
|
457
|
+
choices: organizationChoices,
|
|
458
|
+
default: defaultOrganizationId || undefined,
|
|
459
|
+
message: 'Select organization:'
|
|
460
|
+
});
|
|
461
|
+
if (chosenOrg === '-new-') {
|
|
462
|
+
const newOrganization = await this.promptUserForNewOrganization(user);
|
|
463
|
+
return newOrganization.id;
|
|
464
|
+
}
|
|
465
|
+
return chosenOrg || undefined;
|
|
466
|
+
}
|
|
334
467
|
async verifyCoupon(intendedCoupon) {
|
|
335
468
|
try {
|
|
336
469
|
const planId = await getPlanIdFromCoupon(intendedCoupon);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/init.ts"],"sourcesContent":["// @Todo will remove by time migration of this command si complete\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {Args, Command, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {getCliToken, SanityCommand, type SanityOrgUser, subdebug} from '@sanity/cli-core'\nimport {confirm} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\nimport {type Framework, frameworks} from '@vercel/frameworks'\nimport {detectFrameworkRecord, LocalFileSystemDetector} from '@vercel/fs-detectors'\n\nimport {getProviderName} from '../actions/auth/getProviderName.js'\nimport {login} from '../actions/auth/login/index.js'\nimport {INIT_API_VERSION} from '../actions/init/constants.js'\nimport {\n checkIsRemoteTemplate,\n getGitHubRepoInfo,\n type RepoInfo,\n} from '../actions/init/remoteTemplate.js'\nimport {getPlanId, getPlanIdFromCoupon} from '../services/plans.js'\n\nconst debug = subdebug('init')\n\nexport class InitCommand extends SanityCommand<typeof InitCommand> {\n static override args = {type: Args.string({hidden: true})}\n static override description = 'Initialize a new Sanity Studio, project and/or app'\n static override enableJsonFlag = true\n\n static override examples = [\n '<%= config.bin %> <%= command.id %>',\n {\n command: '<%= config.bin %> <%= command.id %> --dataset-default',\n description: 'Initialize a new project with a public dataset named \"production\"',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -y --project abc123 --dataset production --output-path ~/myproj',\n description: 'Initialize a project with the given project ID and dataset to the given path',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -y --project abc123 --dataset staging --template moviedb --output-path .',\n description:\n 'Initialize a project with the given project ID and dataset using the moviedb template to the given path',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -y --create-project \"Movies Unlimited\" --dataset moviedb --visibility private --template moviedb --output-path /Users/espenh/movies-unlimited',\n description: 'Create a brand new project with name \"Movies Unlimited\"',\n },\n ] satisfies Array<Command.Example>\n\n static override flags = {\n 'auto-updates': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable auto updates of studio versions',\n exclusive: ['bare'],\n }),\n bare: Flags.boolean({\n description:\n 'Skip the Studio initialization and only print the selected project ID and dataset name to stdout',\n }),\n coupon: Flags.string({\n description:\n 'Optionally select a coupon for a new project (cannot be used with --project-plan)',\n exclusive: ['project-plan'],\n helpValue: '<code>',\n }),\n 'create-project': Flags.string({\n description: 'Create a new project with the given name',\n helpValue: '<name>',\n }),\n dataset: Flags.string({\n description: 'Dataset name for the studio',\n exclusive: ['dataset-default'],\n helpValue: '<name>',\n }),\n 'dataset-default': Flags.boolean({\n description: 'Set up a project with a public dataset named \"production\"',\n }),\n env: Flags.string({\n description: 'Write environment variables to file',\n exclusive: ['bare'],\n helpValue: '<filename>',\n parse: async (input) => {\n if (!input.startsWith('.env')) {\n throw new Error('Env filename (`--env`) must start with `.env`')\n }\n return input\n },\n }),\n 'from-create': Flags.boolean({\n description: 'Internal flag to indicate that the command is run from create-sanity',\n hidden: true,\n }),\n git: Flags.string({\n default: undefined,\n description: 'Specify a commit message for initial commit, or disable git init',\n exclusive: ['bare'],\n // oclif doesn't indent correctly with custom help labels, thus leading space :/\n helpLabel: ' --[no-]git',\n helpValue: '<message>',\n }),\n mcp: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable AI editor integration (MCP) setup',\n }),\n 'nextjs-add-config-files': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Add config files to Next.js project',\n helpGroup: 'Next.js',\n }),\n 'nextjs-append-env': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Append project ID and dataset to .env file',\n helpGroup: 'Next.js',\n }),\n 'nextjs-embed-studio': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Embed the Studio in Next.js application',\n helpGroup: 'Next.js',\n }),\n // oclif doesn't support a boolean/string flag combination, but listing both a\n // `--git` and a `--no-git` flag in help breaks conventions, so we hide this one,\n // but use it to \"combine\" the two in the actual logic.\n 'no-git': Flags.boolean({\n description: 'Disable git initialization',\n exclusive: ['git'],\n hidden: true,\n }),\n organization: Flags.string({\n description: 'Organization ID to use for the project',\n helpValue: '<id>',\n }),\n 'output-path': Flags.string({\n description: 'Path to write studio project to',\n exclusive: ['bare'],\n helpValue: '<path>',\n }),\n 'overwrite-files': Flags.boolean({\n default: false,\n description: 'Overwrite existing files',\n }),\n 'package-manager': Flags.string({\n description: 'Specify which package manager to use [allowed: npm, yarn, pnpm]',\n exclusive: ['bare'],\n helpValue: '<manager>',\n options: ['npm', 'yarn', 'pnpm'],\n }),\n project: Flags.string({\n description: 'Project ID to use for the studio',\n helpValue: '<id>',\n }),\n 'project-plan': Flags.string({\n description: 'Optionally select a plan for a new project',\n helpValue: '<name>',\n }),\n provider: Flags.string({\n description: 'Login provider to use',\n helpValue: '<provider>',\n }),\n reconfigure: Flags.boolean({\n deprecated: {message: 'This flag is no longer supported', version: '3.0.0'},\n description: 'Reconfigure an existing project',\n hidden: true,\n }),\n template: Flags.string({\n default: 'clean',\n description: 'Project template to use [default: \"clean\"]',\n exclusive: ['bare'],\n helpValue: '<template>',\n }),\n // Porting over a beta flag\n // Oclif doesn't seem to support something in beta so hiding for now\n 'template-token': Flags.string({\n description: 'Used for accessing private GitHub repo templates',\n hidden: true,\n }),\n typescript: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable TypeScript support',\n exclusive: ['bare'],\n }),\n visibility: Flags.string({\n description: 'Visibility mode for dataset',\n helpValue: '<mode>',\n options: ['public', 'private'],\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Unattended mode, answers \"yes\" to any \"yes/no\" prompt and otherwise uses defaults',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(InitCommand)\n // For backwards \"compatibility\" - we used to allow `sanity init plugin`,\n // and no longer do - but instead of printing an error about an unknown\n // _command_, we want to acknowledge that the user is trying to do something\n // that no longer exists but might have at some point in the past.\n if (args.type) {\n this.error(\n args.type === 'plugin'\n ? 'Initializing plugins through the CLI is no longer supported'\n : `Unknown init type \"${args.type}\"`,\n {exit: 1},\n )\n }\n\n // @todo\n //const trace = telemetry.trace(CLIInitStepCompleted)\n\n // Slightly more helpful message for removed flags rather than just saying the flag\n // does not exist.\n if (this.flags.reconfigure) {\n this.error('--reconfigure is deprecated - manual configuration is now required', {exit: 1})\n }\n\n const detectedFramework: Framework | null = await detectFrameworkRecord({\n frameworkList: frameworks as readonly Framework[],\n fs: new LocalFileSystemDetector(process.cwd()),\n })\n\n let remoteTemplateInfo: RepoInfo | undefined\n if (flags.template && checkIsRemoteTemplate(flags.template)) {\n remoteTemplateInfo = await getGitHubRepoInfo(flags.template, flags['template-token'])\n }\n\n if (detectedFramework && detectedFramework.slug !== 'sanity' && remoteTemplateInfo) {\n this.error(\n `A remote template cannot be used with a detected framework. Detected: ${detectedFramework.name}`,\n {exit: 1},\n )\n }\n\n // @todo\n // trace.start()\n // trace.log({\n // step: 'start',\n // flags: {\n // defaultConfig,\n // unattended,\n // plan: intendedPlan,\n // coupon: intendedCoupon,\n // reconfigure,\n // git: commitMessage,\n // bare: bareOutput,\n // env,\n // },\n // })\n\n // Plan can be set through `--project-plan`, or implied through `--coupon`.\n // As coupons can expire and project plans might change/be removed, we need to\n // verify that the passed flags are valid. The complexity of this is hidden in the\n // below plan methods, eventually returning a plan ID or undefined if we are told to\n // use the default plan.\n\n const _plan = await this.getPlan()\n\n let envFilenameDefault = '.env'\n if (detectedFramework && detectedFramework.slug === 'nextjs') {\n envFilenameDefault = '.env.local'\n }\n const _envFilename = typeof flags.env === 'string' ? flags.env : envFilenameDefault\n\n // If the user isn't already autenticated, make it so\n await this.ensureAuthenticated()\n }\n\n // @todo do we actually need to be authenticated for init? check flags and determine.\n private async ensureAuthenticated(): Promise<{user: SanityOrgUser}> {\n let isAuthenticated = (await getCliToken()) !== undefined\n debug(isAuthenticated ? 'User already has a token' : 'User has no token')\n\n let user: SanityOrgUser | undefined\n if (isAuthenticated) {\n // It _appears_ we are authenticated, but the token might be invalid/expired,\n // so we need to verify that we can actually make an authenticated request.\n const client = await this.getGlobalApiClient({\n apiVersion: INIT_API_VERSION,\n requireUser: true,\n })\n\n try {\n user = (await client.users.getById('me')) as unknown as SanityOrgUser\n } catch {\n // assume that any error means that the token is invalid\n isAuthenticated = false\n }\n }\n\n if (isAuthenticated) {\n // @todo telemetry\n // trace.log({ step: 'login', alreadyLoggedIn: true })\n } else {\n if (this.isUnattended()) {\n throw new Error(\n 'Must be logged in to run this command in unattended mode, run `sanity login`',\n )\n }\n\n // @todo telemetry\n //trace.log({step: 'login'})\n\n // @todo trigger login action, then get and return user info\n await login({output: this.output})\n }\n\n // @todo\n const client = await this.getGlobalApiClient({apiVersion: INIT_API_VERSION, requireUser: true})\n user = (await client.users.getById('me')) as unknown as SanityOrgUser\n\n this.log('You are logged in as %s using %s', user.email, getProviderName(user.provider))\n return {user}\n }\n\n private async getPlan(): Promise<string | undefined> {\n const intendedPlan = this.flags['project-plan']\n const intendedCoupon = this.flags.coupon\n\n if (intendedCoupon) {\n return this.verifyCoupon(intendedCoupon)\n } else if (intendedPlan) {\n return this.verifyPlan(intendedPlan)\n } else {\n return undefined\n }\n }\n\n private async verifyCoupon(intendedCoupon: string): Promise<string | undefined> {\n try {\n const planId = await getPlanIdFromCoupon(intendedCoupon)\n this.log(`Coupon \"${intendedCoupon}\" validated!\\n`)\n return planId\n } catch (err: unknown) {\n if (!isHttpError(err) || err.statusCode !== 404) {\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Unable to validate coupon, please try again later:\\n\\n${message}`)\n }\n\n const useDefaultPlan =\n this.isUnattended() ||\n (await confirm({\n default: true,\n message: `Coupon \"${intendedCoupon}\" is not available, use default plan instead?`,\n }))\n\n if (this.isUnattended()) {\n this.warn(`Coupon \"${intendedCoupon}\" is not available - using default plan`)\n }\n\n // @todo\n // trace.log({\n // step: 'useDefaultPlanCoupon',\n // selectedOption: useDefaultPlan ? 'yes' : 'no',\n // coupon: intendedCoupon,\n // })\n\n if (useDefaultPlan) {\n this.log('Using default plan.')\n } else {\n throw new Error(`Coupon \"${intendedCoupon}\" does not exist`)\n }\n }\n }\n\n private async verifyPlan(intendedPlan: string): Promise<string | undefined> {\n try {\n const planId = await getPlanId(intendedPlan)\n return planId\n } catch (err: unknown) {\n if (!isHttpError(err) || err.statusCode !== 404) {\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Unable to validate plan, please try again later:\\n\\n${message}`, {\n cause: err,\n })\n }\n\n const useDefaultPlan =\n this.isUnattended() ||\n (await confirm({\n default: true,\n message: `Project plan \"${intendedPlan}\" does not exist, use default plan instead?`,\n }))\n\n if (this.isUnattended()) {\n this.warn(`Project plan \"${intendedPlan}\" does not exist - using default plan`)\n }\n\n // @todo\n // trace.log({\n // step: 'useDefaultPlanId',\n // selectedOption: useDefaultPlan ? 'yes' : 'no',\n // planId: intendedPlan,\n // })\n\n if (useDefaultPlan) {\n this.log('Using default plan.')\n } else {\n throw new Error(`Plan id \"${intendedPlan}\" does not exist`)\n }\n }\n }\n}\n"],"names":["Args","Flags","getCliToken","SanityCommand","subdebug","confirm","isHttpError","frameworks","detectFrameworkRecord","LocalFileSystemDetector","getProviderName","login","INIT_API_VERSION","checkIsRemoteTemplate","getGitHubRepoInfo","getPlanId","getPlanIdFromCoupon","debug","InitCommand","args","type","string","hidden","description","enableJsonFlag","examples","command","flags","boolean","allowNo","default","exclusive","bare","coupon","helpValue","dataset","env","parse","input","startsWith","Error","git","undefined","helpLabel","mcp","helpGroup","organization","options","project","provider","reconfigure","deprecated","message","version","template","typescript","visibility","yes","char","run","error","exit","detectedFramework","frameworkList","fs","process","cwd","remoteTemplateInfo","slug","name","_plan","getPlan","envFilenameDefault","_envFilename","ensureAuthenticated","isAuthenticated","user","client","getGlobalApiClient","apiVersion","requireUser","users","getById","isUnattended","output","log","email","intendedPlan","intendedCoupon","verifyCoupon","verifyPlan","planId","err","statusCode","useDefaultPlan","warn","cause"],"mappings":"AAAA,kEAAkE;AAClE,oDAAoD,GACpD,SAAQA,IAAI,EAAWC,KAAK,QAAO,cAAa;AAEhD,SAAQC,WAAW,EAAEC,aAAa,EAAsBC,QAAQ,QAAO,mBAAkB;AACzF,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAC1C,SAAwBC,UAAU,QAAO,qBAAoB;AAC7D,SAAQC,qBAAqB,EAAEC,uBAAuB,QAAO,uBAAsB;AAEnF,SAAQC,eAAe,QAAO,qCAAoC;AAClE,SAAQC,KAAK,QAAO,iCAAgC;AACpD,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SACEC,qBAAqB,EACrBC,iBAAiB,QAEZ,oCAAmC;AAC1C,SAAQC,SAAS,EAAEC,mBAAmB,QAAO,uBAAsB;AAEnE,MAAMC,QAAQb,SAAS;AAEvB,OAAO,MAAMc,oBAAoBf;IAC/B,OAAgBgB,OAAO;QAACC,MAAMpB,KAAKqB,MAAM,CAAC;YAACC,QAAQ;QAAI;IAAE,EAAC;IAC1D,OAAgBC,cAAc,qDAAoD;IAClF,OAAgBC,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;QACA;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aACE;QACJ;QACA;YACEG,SACE;YACFH,aAAa;QACf;KACD,CAAiC;IAElC,OAAgBI,QAAQ;QACtB,gBAAgB1B,MAAM2B,OAAO,CAAC;YAC5BC,SAAS;YACTC,SAAS;YACTP,aAAa;Y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AAc;YACrB,IAAI,CAACtF,YAAYsF,QAAQA,IAAIC,UAAU,KAAK,KAAK;gBAC/C,MAAMzC,UAAUwC,eAAepD,QAAQoD,IAAIxC,OAAO,GAAG,GAAGwC,KAAK;gBAC7D,MAAM,IAAIpD,MAAM,CAAC,oDAAoD,EAAEY,SAAS,EAAE;oBAChF4C,OAAOJ;gBACT;YACF;YAEA,MAAME,iBACJ,IAAI,CAACX,YAAY,MAChB,MAAM9E,QAAQ;gBACbyB,SAAS;gBACTsB,SAAS,CAAC,cAAc,EAAEmC,aAAa,2CAA2C,CAAC;YACrF;YAEF,IAAI,IAAI,CAACJ,YAAY,IAAI;gBACvB,IAAI,CAACY,IAAI,CAAC,CAAC,cAAc,EAAER,aAAa,qCAAqC,CAAC;YAChF;YAEA,QAAQ;YACR,cAAc;YACd,8BAA8B;YAC9B,mDAAmD;YACnD,0BAA0B;YAC1B,KAAK;YAEL,IAAIO,gBAAgB;gBAClB,IAAI,CAACT,GAAG,CAAC;YACX,OAAO;gBACL,MAAM,IAAI7C,MAAM,CAAC,SAAS,EAAE+C,aAAa,gBAAgB,CAAC;YAC5D;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/init.ts"],"sourcesContent":["// @Todo will remove by time migration of this command is complete\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {Args, Command, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {getCliToken, SanityCommand, type SanityOrgUser, subdebug} from '@sanity/cli-core'\nimport {confirm, input, logSymbols, select, spinner} from '@sanity/cli-core/ux'\nimport {type DatasetAclMode, isHttpError} from '@sanity/client'\nimport {type Framework, frameworks} from '@vercel/frameworks'\nimport {detectFrameworkRecord, LocalFileSystemDetector} from '@vercel/fs-detectors'\n\nimport {getProviderName} from '../actions/auth/getProviderName.js'\nimport {login} from '../actions/auth/login/login.js'\nimport {determineAppTemplate} from '../actions/init/determineAppTemplate.js'\nimport {\n checkIsRemoteTemplate,\n getGitHubRepoInfo,\n type RepoInfo,\n} from '../actions/init/remoteTemplate.js'\nimport {getOrganizationChoices} from '../actions/organizations/getOrganizationChoices.js'\nimport {getOrganizationsWithAttachGrantInfo} from '../actions/organizations/getOrganizationsWithAttachGrantInfo.js'\nimport {createDataset} from '../services/datasets.js'\nimport {\n createOrganization,\n listOrganizations,\n type OrganizationCreateResponse,\n type ProjectOrganization,\n} from '../services/organizations.js'\nimport {getPlanId, getPlanIdFromCoupon} from '../services/plans.js'\nimport {createProject} from '../services/projects.js'\nimport {getCliUser} from '../services/user.js'\n\nconst debug = subdebug('init')\n\nexport class InitCommand extends SanityCommand<typeof InitCommand> {\n static override args = {type: Args.string({hidden: true})}\n static override description = 'Initialize a new Sanity Studio, project and/or app'\n static override enableJsonFlag = true\n\n static override examples = [\n '<%= config.bin %> <%= command.id %>',\n {\n command: '<%= config.bin %> <%= command.id %> --dataset-default',\n description: 'Initialize a new project with a public dataset named \"production\"',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -y --project abc123 --dataset production --output-path ~/myproj',\n description: 'Initialize a project with the given project ID and dataset to the given path',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -y --project abc123 --dataset staging --template moviedb --output-path .',\n description:\n 'Initialize a project with the given project ID and dataset using the moviedb template to the given path',\n },\n {\n command:\n '<%= config.bin %> <%= command.id %> -y --create-project \"Movies Unlimited\" --dataset moviedb --visibility private --template moviedb --output-path /Users/espenh/movies-unlimited',\n description: 'Create a brand new project with name \"Movies Unlimited\"',\n },\n ] satisfies Array<Command.Example>\n\n static override flags = {\n 'auto-updates': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable auto updates of studio versions',\n exclusive: ['bare'],\n }),\n bare: Flags.boolean({\n description:\n 'Skip the Studio initialization and only print the selected project ID and dataset name to stdout',\n }),\n coupon: Flags.string({\n description:\n 'Optionally select a coupon for a new project (cannot be used with --project-plan)',\n exclusive: ['project-plan'],\n helpValue: '<code>',\n }),\n 'create-project': Flags.string({\n description: 'Create a new project with the given name',\n helpValue: '<name>',\n }),\n dataset: Flags.string({\n description: 'Dataset name for the studio',\n exclusive: ['dataset-default'],\n helpValue: '<name>',\n }),\n 'dataset-default': Flags.boolean({\n description: 'Set up a project with a public dataset named \"production\"',\n }),\n env: Flags.string({\n description: 'Write environment variables to file',\n exclusive: ['bare'],\n helpValue: '<filename>',\n parse: async (input) => {\n if (!input.startsWith('.env')) {\n throw new Error('Env filename (`--env`) must start with `.env`')\n }\n return input\n },\n }),\n 'from-create': Flags.boolean({\n description: 'Internal flag to indicate that the command is run from create-sanity',\n hidden: true,\n }),\n git: Flags.string({\n default: undefined,\n description: 'Specify a commit message for initial commit, or disable git init',\n exclusive: ['bare'],\n // oclif doesn't indent correctly with custom help labels, thus leading space :/\n helpLabel: ' --[no-]git',\n helpValue: '<message>',\n }),\n mcp: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable AI editor integration (MCP) setup',\n }),\n 'nextjs-add-config-files': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Add config files to Next.js project',\n helpGroup: 'Next.js',\n }),\n 'nextjs-append-env': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Append project ID and dataset to .env file',\n helpGroup: 'Next.js',\n }),\n 'nextjs-embed-studio': Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Embed the Studio in Next.js application',\n helpGroup: 'Next.js',\n }),\n // oclif doesn't support a boolean/string flag combination, but listing both a\n // `--git` and a `--no-git` flag in help breaks conventions, so we hide this one,\n // but use it to \"combine\" the two in the actual logic.\n 'no-git': Flags.boolean({\n description: 'Disable git initialization',\n exclusive: ['git'],\n hidden: true,\n }),\n organization: Flags.string({\n description: 'Organization ID to use for the project',\n helpValue: '<id>',\n }),\n 'output-path': Flags.string({\n description: 'Path to write studio project to',\n exclusive: ['bare'],\n helpValue: '<path>',\n }),\n 'overwrite-files': Flags.boolean({\n default: false,\n description: 'Overwrite existing files',\n }),\n 'package-manager': Flags.string({\n description: 'Specify which package manager to use [allowed: npm, yarn, pnpm]',\n exclusive: ['bare'],\n helpValue: '<manager>',\n options: ['npm', 'yarn', 'pnpm'],\n }),\n project: Flags.string({\n aliases: ['project-id'],\n description: 'Project ID to use for the studio',\n exclusive: ['create-project'],\n helpValue: '<id>',\n }),\n 'project-plan': Flags.string({\n description: 'Optionally select a plan for a new project',\n helpValue: '<name>',\n }),\n provider: Flags.string({\n description: 'Login provider to use',\n helpValue: '<provider>',\n }),\n reconfigure: Flags.boolean({\n deprecated: {message: 'This flag is no longer supported', version: '3.0.0'},\n description: 'Reconfigure an existing project',\n hidden: true,\n }),\n template: Flags.string({\n default: 'clean',\n description: 'Project template to use [default: \"clean\"]',\n exclusive: ['bare'],\n helpValue: '<template>',\n }),\n // Porting over a beta flag\n // Oclif doesn't seem to support something in beta so hiding for now\n 'template-token': Flags.string({\n description: 'Used for accessing private GitHub repo templates',\n hidden: true,\n }),\n typescript: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Enable TypeScript support',\n exclusive: ['bare'],\n }),\n visibility: Flags.string({\n description: 'Visibility mode for dataset',\n helpValue: '<mode>',\n options: ['public', 'private'],\n }),\n yes: Flags.boolean({\n char: 'y',\n default: false,\n description:\n 'Unattended mode, answers \"yes\" to any \"yes/no\" prompt and otherwise uses defaults',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {args, flags} = await this.parse(InitCommand)\n const createProjectName = this.flags['create-project']\n // For backwards \"compatibility\" - we used to allow `sanity init plugin`,\n // and no longer do - but instead of printing an error about an unknown\n // _command_, we want to acknowledge that the user is trying to do something\n // that no longer exists but might have at some point in the past.\n if (args.type) {\n this.error(\n args.type === 'plugin'\n ? 'Initializing plugins through the CLI is no longer supported'\n : `Unknown init type \"${args.type}\"`,\n {exit: 1},\n )\n }\n\n // @todo\n //const trace = telemetry.trace(CLIInitStepCompleted)\n\n // Slightly more helpful message for removed flags rather than just saying the flag\n // does not exist.\n if (this.flags.reconfigure) {\n this.error('--reconfigure is deprecated - manual configuration is now required', {exit: 1})\n }\n\n // Oclif doesn't support custom exclusive error messaging\n if (this.flags.project && this.flags.organization) {\n throw new Error(\n 'You have specified both a project and an organization. To move a project to an organization please visit https://www.sanity.io/manage',\n )\n }\n\n const defaultConfig = this.flags['dataset-default']\n let _showDefaultConfigPrompt = !defaultConfig\n if (\n this.flags.dataset ||\n this.flags.visibility ||\n this.flags['dataset-default'] ||\n this.isUnattended()\n ) {\n _showDefaultConfigPrompt = false\n }\n\n const detectedFramework: Framework | null = await detectFrameworkRecord({\n frameworkList: frameworks as readonly Framework[],\n fs: new LocalFileSystemDetector(process.cwd()),\n })\n const isNextJs = detectedFramework?.slug === 'nextjs'\n\n let remoteTemplateInfo: RepoInfo | undefined\n if (flags.template && checkIsRemoteTemplate(flags.template)) {\n remoteTemplateInfo = await getGitHubRepoInfo(flags.template, flags['template-token'])\n }\n\n if (detectedFramework && detectedFramework.slug !== 'sanity' && remoteTemplateInfo) {\n this.error(\n `A remote template cannot be used with a detected framework. Detected: ${detectedFramework.name}`,\n {exit: 1},\n )\n }\n\n // Checks flags are present when in unattended mode\n if (this.isUnattended()) {\n this.checkFlagsInUnattendedMode({createProjectName, isNextJs})\n }\n\n // @todo\n // trace.start()\n // trace.log({\n // step: 'start',\n // flags: {\n // defaultConfig,\n // unattended,\n // plan: intendedPlan,\n // coupon: intendedCoupon,\n // reconfigure,\n // git: commitMessage,\n // bare: bareOutput,\n // env,\n // },\n // })\n\n // Plan can be set through `--project-plan`, or implied through `--coupon`.\n // As coupons can expire and project plans might change/be removed, we need to\n // verify that the passed flags are valid. The complexity of this is hidden in the\n // below plan methods, eventually returning a plan ID or undefined if we are told to\n // use the default plan.\n\n const planId = await this.getPlan()\n\n let envFilenameDefault = '.env'\n if (detectedFramework && detectedFramework.slug === 'nextjs') {\n envFilenameDefault = '.env.local'\n }\n const _envFilename = typeof flags.env === 'string' ? flags.env : envFilenameDefault\n\n // If the user isn't already autenticated, make it so\n const {user} = await this.ensureAuthenticated()\n\n // skip project / dataset prompting\n const template = this.flags.template\n const isAppTemplate = template ? determineAppTemplate(template) : false // Default to false\n if (!isAppTemplate) {\n this.log(`${logSymbols.success} Fetching existing projects`)\n this.log('')\n }\n\n const _newProjectId =\n createProjectName && (await this.createProject({createProjectName, planId, user}))\n }\n\n private checkFlagsInUnattendedMode({\n createProjectName,\n isNextJs,\n }: {\n createProjectName: string | undefined\n isNextJs: boolean\n }) {\n debug('Unattended mode, validating required options')\n\n if (!this.flags['dataset']) {\n throw new Error(`\\`--dataset\\` must be specified in unattended mode`)\n }\n\n // output-path is required in unattended mode when not using nextjs\n if (!isNextJs && !this.flags['output-path']) {\n throw new Error(`\\`--output-path\\` must be specified in unattended mode`)\n }\n\n if (!this.flags.project && !createProjectName) {\n throw new Error(\n '`--project <id>` or `--create-project <name>` must be specified in unattended mode',\n )\n }\n\n if (createProjectName && !this.flags.organization) {\n throw new Error(\n '--create-project is not supported in unattended mode without an organization, please specify an organization with `--organization <id>`',\n )\n }\n }\n\n private async createProject({\n createProjectName,\n planId,\n user,\n }: {\n createProjectName: string\n planId: string | undefined\n user: SanityOrgUser\n }): Promise<string> {\n debug('--create-project specified, creating a new project')\n\n let orgForCreateProjectFlag = this.flags.organization\n\n if (!orgForCreateProjectFlag) {\n debug('no organization specified, selecting one')\n const organizations = await listOrganizations()\n orgForCreateProjectFlag = await this.promptUserForOrganization({organizations, user})\n }\n\n debug('creating a new project')\n const createdProject = await createProject({\n displayName: createProjectName.trim(),\n metadata: {coupon: this.flags.coupon},\n organizationId: orgForCreateProjectFlag,\n subscription: planId ? {planId} : undefined,\n })\n\n debug('Project with ID %s created', createdProject.projectId)\n if (this.flags.dataset) {\n debug('--dataset specified, creating dataset (%s)', this.flags.dataset)\n const spin = spinner('Creating dataset').start()\n await createDataset({\n aclMode: this.flags.visibility as DatasetAclMode,\n datasetName: this.flags.dataset,\n projectId: createdProject.projectId,\n })\n spin.succeed()\n }\n\n return createdProject.projectId\n }\n\n // @todo do we actually need to be authenticated for init? check flags and determine.\n private async ensureAuthenticated(): Promise<{user: SanityOrgUser}> {\n let isAuthenticated = (await getCliToken()) !== undefined\n debug(isAuthenticated ? 'User already has a token' : 'User has no token')\n\n let user: SanityOrgUser | undefined\n if (isAuthenticated) {\n // It _appears_ we are authenticated, but the token might be invalid/expired,\n // so we need to verify that we can actually make an authenticated request.\n try {\n user = await getCliUser()\n } catch {\n // assume that any error means that the token is invalid\n isAuthenticated = false\n }\n }\n\n if (isAuthenticated) {\n // @todo telemetry\n // trace.log({ step: 'login', alreadyLoggedIn: true })\n } else {\n if (this.isUnattended()) {\n throw new Error(\n 'Must be logged in to run this command in unattended mode, run `sanity login`',\n )\n }\n\n // @todo telemetry\n //trace.log({step: 'login'})\n\n // @todo trigger login action, then get and return user info\n await login({output: this.output})\n }\n\n user = await getCliUser()\n\n this.log(\n `${logSymbols.success} You are logged in as ${user.email} using ${getProviderName(user.provider)}`,\n )\n return {user}\n }\n\n private async getPlan(): Promise<string | undefined> {\n const intendedPlan = this.flags['project-plan']\n const intendedCoupon = this.flags.coupon\n\n if (intendedCoupon) {\n return this.verifyCoupon(intendedCoupon)\n } else if (intendedPlan) {\n return this.verifyPlan(intendedPlan)\n } else {\n return undefined\n }\n }\n\n private async promptUserForNewOrganization(\n user: SanityOrgUser,\n ): Promise<OrganizationCreateResponse> {\n const name = await input({\n default: user ? user.name : undefined,\n message: 'Organization name:',\n validate(input) {\n if (input.length === 0) {\n return 'Organization name cannot be empty'\n } else if (input.length > 100) {\n return 'Organization name cannot be longer than 100 characters'\n }\n return true\n },\n })\n\n const spin = spinner('Creating organization').start()\n const organization = await createOrganization(name)\n spin.succeed()\n\n return organization\n }\n\n private async promptUserForOrganization({\n organizations,\n user,\n }: {\n organizations: ProjectOrganization[]\n user: SanityOrgUser\n }) {\n // If the user has no organizations, prompt them to create one with the same name as\n // their user, but allow them to customize it if they want\n if (organizations.length === 0) {\n const newOrganization = await this.promptUserForNewOrganization(user)\n return newOrganization.id\n }\n\n // If the user has organizations, let them choose from them, but also allow them to\n // create a new one in case they do not have access to any of them, or they want to\n // create a personal/other organization.\n debug(`User has ${organizations.length} organization(s), checking attach access`)\n const withGrantInfo = await getOrganizationsWithAttachGrantInfo(organizations)\n const withAttach = withGrantInfo.filter(({hasAttachGrant}) => hasAttachGrant)\n\n debug('User has attach access to %d organizations.', withAttach.length)\n const organizationChoices = getOrganizationChoices(withAttach)\n\n // If the user only has a single organization (and they have attach access to it),\n // we'll default to that one. Otherwise, we'll default to the organization with the\n // same name as the user if it exists.\n const defaultOrganizationId =\n withAttach.length === 1\n ? withAttach[0].organization.id\n : organizations.find((org) => org.name === user?.name)?.id\n\n const chosenOrg = await select({\n choices: organizationChoices,\n default: defaultOrganizationId || undefined,\n message: 'Select organization:',\n })\n\n if (chosenOrg === '-new-') {\n const newOrganization = await this.promptUserForNewOrganization(user)\n return newOrganization.id\n }\n\n return chosenOrg || undefined\n }\n\n private async verifyCoupon(intendedCoupon: string): Promise<string | undefined> {\n try {\n const planId = await getPlanIdFromCoupon(intendedCoupon)\n this.log(`Coupon \"${intendedCoupon}\" validated!\\n`)\n return planId\n } catch (err: unknown) {\n if (!isHttpError(err) || err.statusCode !== 404) {\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Unable to validate coupon, please try again later:\\n\\n${message}`)\n }\n\n const useDefaultPlan =\n this.isUnattended() ||\n (await confirm({\n default: true,\n message: `Coupon \"${intendedCoupon}\" is not available, use default plan instead?`,\n }))\n\n if (this.isUnattended()) {\n this.warn(`Coupon \"${intendedCoupon}\" is not available - using default plan`)\n }\n\n // @todo\n // trace.log({\n // step: 'useDefaultPlanCoupon',\n // selectedOption: useDefaultPlan ? 'yes' : 'no',\n // coupon: intendedCoupon,\n // })\n\n if (useDefaultPlan) {\n this.log('Using default plan.')\n } else {\n throw new Error(`Coupon \"${intendedCoupon}\" does not exist`)\n }\n }\n }\n\n private async verifyPlan(intendedPlan: string): Promise<string | undefined> {\n try {\n const planId = await getPlanId(intendedPlan)\n return planId\n } catch (err: unknown) {\n if (!isHttpError(err) || err.statusCode !== 404) {\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Unable to validate plan, please try again later:\\n\\n${message}`, {\n cause: err,\n })\n }\n\n const useDefaultPlan =\n this.isUnattended() ||\n (await confirm({\n default: true,\n message: `Project plan \"${intendedPlan}\" does not exist, use default plan instead?`,\n }))\n\n if (this.isUnattended()) {\n this.warn(`Project plan \"${intendedPlan}\" does not exist - using default plan`)\n }\n\n // @todo\n // trace.log({\n // step: 'useDefaultPlanId',\n // selectedOption: useDefaultPlan ? 'yes' : 'no',\n // planId: intendedPlan,\n // })\n\n if (useDefaultPlan) {\n this.log('Using default plan.')\n } else {\n throw new Error(`Plan id \"${intendedPlan}\" does not exist`)\n }\n }\n }\n}\n"],"names":["Args","Flags","getCliToken","SanityCommand","subdebug","confirm","input","logSymbols","select","spinner","isHttpError","frameworks","detectFrameworkRecord","LocalFileSystemDetector","getProviderName","login","determineAppTemplate","checkIsRemoteTemplate","getGitHubRepoInfo","getOrganizationChoices","getOrganizationsWithAttachGrantInfo","createDataset","createOrganization","listOrganizations","getPlanId","getPlanIdFromCoupon","createProject","getCliUser","debug","InitCommand","args","type","string","hidden","description","enableJsonFlag","examples","command","flags","boolean","allowNo","default","exclusive","bare","coupon","helpValue","dataset","env","parse","startsWith","Error","git","undefined","helpLabel","mcp","helpGroup","organization","options","project","aliases","provider","reconfigure","deprecated","message","version","template","typescript","visibility","yes","char","run","createProjectName","error","exit","defaultConfig","_showDefaultConfigPrompt","isUnattended","detectedFramework","frameworkList","fs","process","cwd","isNextJs","slug","remoteTemplateInfo","name","checkFlagsInUnattendedMode","planId","getPlan","envFilenameDefault","_envFilename","user","ensureAuthenticated","isAppTemplate","log","success","_newProjectId","orgForCreateProjectFlag","organizations","promptUserForOrganization","createdProject","displayName","trim","metadata","organizationId","subscription","projectId","spin","start","aclMode","datasetName","succeed","isAuthenticated","output","email","intendedPlan","intendedCoupon","verifyCoupon","verifyPlan","promptUserForNewOrganization","validate","length","newOrganization","id","withGrantInfo","withAttach","filter","hasAttachGrant","organizationChoices","defaultOrganizationId","find","org","chosenOrg","choices","err","statusCode","useDefaultPlan","warn","cause"],"mappings":"AAAA,kEAAkE;AAClE,oDAAoD,GACpD,SAAQA,IAAI,EAAWC,KAAK,QAAO,cAAa;AAEhD,SAAQC,WAAW,EAAEC,aAAa,EAAsBC,QAAQ,QAAO,mBAAkB;AACzF,SAAQC,OAAO,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAAO,sBAAqB;AAC/E,SAA6BC,WAAW,QAAO,iBAAgB;AAC/D,SAAwBC,UAAU,QAAO,qBAAoB;AAC7D,SAAQC,qBAAqB,EAAEC,uBAAuB,QAAO,uBAAsB;AAEnF,SAAQC,eAAe,QAAO,qCAAoC;AAClE,SAAQC,KAAK,QAAO,iCAAgC;AACpD,SAAQC,oBAAoB,QAAO,0CAAyC;AAC5E,SACEC,qBAAqB,EACrBC,iBAAiB,QAEZ,oCAAmC;AAC1C,SAAQC,sBAAsB,QAAO,qDAAoD;AACzF,SAAQC,mCAAmC,QAAO,kEAAiE;AACnH,SAAQC,aAAa,QAAO,0BAAyB;AACrD,SACEC,kBAAkB,EAClBC,iBAAiB,QAGZ,+BAA8B;AACrC,SAAQC,SAAS,EAAEC,mBAAmB,QAAO,uBAAsB;AACnE,SAAQC,aAAa,QAAO,0BAAyB;AACrD,SAAQC,UAAU,QAAO,sBAAqB;AAE9C,MAAMC,QAAQxB,SAAS;AAEvB,OAAO,MAAMyB,oBAAoB1B;IAC/B,OAAgB2B,OAAO;QAACC,MAAM/B,KAAKgC,MAAM,CAAC;YAACC,QAAQ;QAAI;IAAE,EAAC;IAC1D,OAAgBC,cAAc,qDAAoD;IAClF,OAAgBC,iBAAiB,KAAI;IAErC,OAAgBC,WAAW;QACzB;QACA;YACEC,SAAS;YACTH,aAAa;QACf;QACA;YACEG,SACE;YACFH,aAAa;QACf;QACA;YACEG,SACE;YACFH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YACX,OAAO;gBACL,MAAM,IAAI5C,MAAM,CAAC,QAAQ,EAAEkE,eAAe,gBAAgB,CAAC;YAC7D;QACF;IACF;IAEA,MAAcE,WAAWH,YAAoB,EAA+B;QAC1E,IAAI;YACF,MAAM5B,SAAS,MAAM/D,UAAU2F;YAC/B,OAAO5B;QACT,EAAE,OAAO+C,KAAc;YACrB,IAAI,CAAC5H,YAAY4H,QAAQA,IAAIC,UAAU,KAAK,KAAK;gBAC/C,MAAMxE,UAAUuE,eAAepF,QAAQoF,IAAIvE,OAAO,GAAG,GAAGuE,KAAK;gBAC7D,MAAM,IAAIpF,MAAM,CAAC,oDAAoD,EAAEa,SAAS,EAAE;oBAChF2E,OAAOJ;gBACT;YACF;YAEA,MAAME,iBACJ,IAAI,CAAC5D,YAAY,MAChB,MAAMvE,QAAQ;gBACboC,SAAS;gBACTsB,SAAS,CAAC,cAAc,EAAEoD,aAAa,2CAA2C,CAAC;YACrF;YAEF,IAAI,IAAI,CAACvC,YAAY,IAAI;gBACvB,IAAI,CAAC6D,IAAI,CAAC,CAAC,cAAc,EAAEtB,aAAa,qCAAqC,CAAC;YAChF;YAEA,QAAQ;YACR,cAAc;YACd,8BAA8B;YAC9B,mDAAmD;YACnD,0BAA0B;YAC1B,KAAK;YAEL,IAAIqB,gBAAgB;gBAClB,IAAI,CAAC1C,GAAG,CAAC;YACX,OAAO;gBACL,MAAM,IAAI5C,MAAM,CAAC,SAAS,EAAEiE,aAAa,gBAAgB,CAAC;YAC5D;QACF;IACF;AACF"}
|
package/dist/commands/login.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
2
|
import { SanityCommand } from '@sanity/cli-core';
|
|
3
|
-
import { login } from '../actions/auth/login/
|
|
3
|
+
import { login } from '../actions/auth/login/login.js';
|
|
4
4
|
export class LoginCommand extends SanityCommand {
|
|
5
5
|
static description = 'Authenticates the CLI for access to Sanity projects';
|
|
6
6
|
static examples = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/login.ts"],"sourcesContent":["import {Command, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {SanityCommand} from '@sanity/cli-core'\n\nimport {login} from '../actions/auth/login/
|
|
1
|
+
{"version":3,"sources":["../../src/commands/login.ts"],"sourcesContent":["import {Command, Flags} from '@oclif/core'\nimport {type FlagInput} from '@oclif/core/interfaces'\nimport {SanityCommand} from '@sanity/cli-core'\n\nimport {login} from '../actions/auth/login/login.js'\n\nexport class LoginCommand extends SanityCommand<typeof LoginCommand> {\n static override description = 'Authenticates the CLI for access to Sanity projects'\n static override examples: Array<Command.Example> = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Log in using default settings',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --sso my-organization',\n description: 'Log in using Single Sign-On with the \"my-organization\" slug',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --provider github --no-open',\n description: 'Login with GitHub provider, but do not open a browser window automatically',\n },\n ]\n static override flags = {\n experimental: Flags.boolean({\n default: false,\n hidden: true,\n }),\n open: Flags.boolean({\n allowNo: true,\n default: true,\n description: 'Open a browser window to log in (`--no-open` only prints URL)',\n }),\n provider: Flags.string({\n description: 'Log in using the given provider',\n helpValue: '<providerId>',\n }),\n sso: Flags.string({\n description: 'Log in using Single Sign-On, using the given organization slug',\n helpValue: '<slug>',\n }),\n } satisfies FlagInput\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(LoginCommand)\n\n await login({...flags, output: this.output})\n\n this.log('Login successful')\n\n // @todo trace.complete()\n }\n}\n"],"names":["Flags","SanityCommand","login","LoginCommand","description","examples","command","flags","experimental","boolean","default","hidden","open","allowNo","provider","string","helpValue","sso","run","parse","output","log"],"mappings":"AAAA,SAAiBA,KAAK,QAAO,cAAa;AAE1C,SAAQC,aAAa,QAAO,mBAAkB;AAE9C,SAAQC,KAAK,QAAO,iCAAgC;AAEpD,OAAO,MAAMC,qBAAqBF;IAChC,OAAgBG,cAAc,sDAAqD;IACnF,OAAgBC,WAAmC;QACjD;YACEC,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;QACA;YACEE,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IACD,OAAgBG,QAAQ;QACtBC,cAAcR,MAAMS,OAAO,CAAC;YAC1BC,SAAS;YACTC,QAAQ;QACV;QACAC,MAAMZ,MAAMS,OAAO,CAAC;YAClBI,SAAS;YACTH,SAAS;YACTN,aAAa;QACf;QACAU,UAAUd,MAAMe,MAAM,CAAC;YACrBX,aAAa;YACbY,WAAW;QACb;QACAC,KAAKjB,MAAMe,MAAM,CAAC;YAChBX,aAAa;YACbY,WAAW;QACb;IACF,EAAqB;IAErB,MAAaE,MAAqB;QAChC,MAAM,EAACX,KAAK,EAAC,GAAG,MAAM,IAAI,CAACY,KAAK,CAAChB;QAEjC,MAAMD,MAAM;YAAC,GAAGK,KAAK;YAAEa,QAAQ,IAAI,CAACA,MAAM;QAAA;QAE1C,IAAI,CAACC,GAAG,CAAC;IAET,yBAAyB;IAC3B;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const ORGANIZATIONS_API_VERSION = "v2021-06-07";
|
|
2
|
+
export interface ProjectOrganization {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
}
|
|
7
|
+
export interface OrganizationCreateResponse {
|
|
8
|
+
createdByUserId: string;
|
|
9
|
+
defaultRoleName: string | null;
|
|
10
|
+
features: unknown[];
|
|
11
|
+
id: string;
|
|
12
|
+
members: unknown[];
|
|
13
|
+
name: string;
|
|
14
|
+
slug: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface OrganizationWithGrant {
|
|
17
|
+
hasAttachGrant: boolean;
|
|
18
|
+
organization: ProjectOrganization;
|
|
19
|
+
}
|
|
20
|
+
interface OrganizationGrant {
|
|
21
|
+
grants: {
|
|
22
|
+
name: string;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
interface OrganizationGrantsResponse {
|
|
26
|
+
[key: string]: OrganizationGrant[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* List all organizations the user has access to
|
|
30
|
+
*/
|
|
31
|
+
export declare function listOrganizations(): Promise<ProjectOrganization[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new organization
|
|
34
|
+
*/
|
|
35
|
+
export declare function createOrganization(name: string): Promise<OrganizationCreateResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Get organization grants for a specific organization
|
|
38
|
+
*/
|
|
39
|
+
export declare function getOrganizationGrants(organizationId: string): Promise<OrganizationGrantsResponse>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getGlobalCliClient } from '@sanity/cli-core';
|
|
2
|
+
export const ORGANIZATIONS_API_VERSION = 'v2021-06-07';
|
|
3
|
+
/**
|
|
4
|
+
* List all organizations the user has access to
|
|
5
|
+
*/ export async function listOrganizations() {
|
|
6
|
+
const client = await getGlobalCliClient({
|
|
7
|
+
apiVersion: ORGANIZATIONS_API_VERSION,
|
|
8
|
+
requireUser: true
|
|
9
|
+
});
|
|
10
|
+
return client.request({
|
|
11
|
+
uri: '/organizations'
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new organization
|
|
16
|
+
*/ export async function createOrganization(name) {
|
|
17
|
+
const client = await getGlobalCliClient({
|
|
18
|
+
apiVersion: ORGANIZATIONS_API_VERSION,
|
|
19
|
+
requireUser: true
|
|
20
|
+
});
|
|
21
|
+
return client.request({
|
|
22
|
+
body: {
|
|
23
|
+
name
|
|
24
|
+
},
|
|
25
|
+
method: 'post',
|
|
26
|
+
uri: '/organizations'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get organization grants for a specific organization
|
|
31
|
+
*/ export async function getOrganizationGrants(organizationId) {
|
|
32
|
+
const client = await getGlobalCliClient({
|
|
33
|
+
apiVersion: ORGANIZATIONS_API_VERSION,
|
|
34
|
+
requireUser: true
|
|
35
|
+
});
|
|
36
|
+
return client.request({
|
|
37
|
+
uri: `organizations/${organizationId}/grants`
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=organizations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/organizations.ts"],"sourcesContent":["import {getGlobalCliClient} from '@sanity/cli-core'\n\nexport const ORGANIZATIONS_API_VERSION = 'v2021-06-07'\n\nexport interface ProjectOrganization {\n id: string\n name: string\n slug: string\n}\n\nexport interface OrganizationCreateResponse {\n createdByUserId: string\n defaultRoleName: string | null\n features: unknown[]\n id: string\n members: unknown[]\n name: string\n slug: string | null\n}\n\nexport interface OrganizationWithGrant {\n hasAttachGrant: boolean\n organization: ProjectOrganization\n}\n\ninterface OrganizationGrant {\n grants: {name: string}[]\n}\n\ninterface OrganizationGrantsResponse {\n [key: string]: OrganizationGrant[]\n}\n\n/**\n * List all organizations the user has access to\n */\nexport async function listOrganizations(): Promise<ProjectOrganization[]> {\n const client = await getGlobalCliClient({\n apiVersion: ORGANIZATIONS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<ProjectOrganization[]>({\n uri: '/organizations',\n })\n}\n\n/**\n * Create a new organization\n */\nexport async function createOrganization(name: string): Promise<OrganizationCreateResponse> {\n const client = await getGlobalCliClient({\n apiVersion: ORGANIZATIONS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<OrganizationCreateResponse>({\n body: {name},\n method: 'post',\n uri: '/organizations',\n })\n}\n\n/**\n * Get organization grants for a specific organization\n */\nexport async function getOrganizationGrants(\n organizationId: string,\n): Promise<OrganizationGrantsResponse> {\n const client = await getGlobalCliClient({\n apiVersion: ORGANIZATIONS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<OrganizationGrantsResponse>({\n uri: `organizations/${organizationId}/grants`,\n })\n}\n"],"names":["getGlobalCliClient","ORGANIZATIONS_API_VERSION","listOrganizations","client","apiVersion","requireUser","request","uri","createOrganization","name","body","method","getOrganizationGrants","organizationId"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,mBAAkB;AAEnD,OAAO,MAAMC,4BAA4B,cAAa;AA+BtD;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAMC,SAAS,MAAMH,mBAAmB;QACtCI,YAAYH;QACZI,aAAa;IACf;IAEA,OAAOF,OAAOG,OAAO,CAAwB;QAC3CC,KAAK;IACP;AACF;AAEA;;CAEC,GACD,OAAO,eAAeC,mBAAmBC,IAAY;IACnD,MAAMN,SAAS,MAAMH,mBAAmB;QACtCI,YAAYH;QACZI,aAAa;IACf;IAEA,OAAOF,OAAOG,OAAO,CAA6B;QAChDI,MAAM;YAACD;QAAI;QACXE,QAAQ;QACRJ,KAAK;IACP;AACF;AAEA;;CAEC,GACD,OAAO,eAAeK,sBACpBC,cAAsB;IAEtB,MAAMV,SAAS,MAAMH,mBAAmB;QACtCI,YAAYH;QACZI,aAAa;IACf;IAEA,OAAOF,OAAOG,OAAO,CAA6B;QAChDC,KAAK,CAAC,cAAc,EAAEM,eAAe,OAAO,CAAC;IAC/C;AACF"}
|
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
export declare const PROJECTS_API_VERSION = "2025-09-22";
|
|
2
|
+
export declare const CREATE_PROJECT_API_VERSION = "v2025-05-14";
|
|
3
|
+
export interface CreateProjectOptions {
|
|
4
|
+
displayName: string;
|
|
5
|
+
metadata?: {
|
|
6
|
+
coupon?: string;
|
|
7
|
+
integration?: string;
|
|
8
|
+
};
|
|
9
|
+
organizationId?: string;
|
|
10
|
+
subscription?: {
|
|
11
|
+
planId: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface CreateProjectResult {
|
|
15
|
+
displayName: string;
|
|
16
|
+
projectId: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a new Sanity project
|
|
20
|
+
*/
|
|
21
|
+
export declare function createProject(options: CreateProjectOptions): Promise<CreateProjectResult>;
|
|
2
22
|
export declare function getProjectById(projectId: string): Promise<import("@sanity/client").SanityProject>;
|
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
import { getProjectCliClient } from '@sanity/cli-core';
|
|
1
|
+
import { debug, getGlobalCliClient, getProjectCliClient } from '@sanity/cli-core';
|
|
2
2
|
export const PROJECTS_API_VERSION = '2025-09-22';
|
|
3
|
+
export const CREATE_PROJECT_API_VERSION = 'v2025-05-14';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new Sanity project
|
|
6
|
+
*/ export async function createProject(options) {
|
|
7
|
+
const client = await getGlobalCliClient({
|
|
8
|
+
apiVersion: CREATE_PROJECT_API_VERSION,
|
|
9
|
+
requireUser: true
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
const response = await client.request({
|
|
13
|
+
body: {
|
|
14
|
+
...options,
|
|
15
|
+
metadata: {
|
|
16
|
+
...options?.metadata,
|
|
17
|
+
integration: 'cli'
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
method: 'POST',
|
|
21
|
+
uri: '/projects'
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
displayName: options.displayName || '',
|
|
25
|
+
projectId: response.projectId || response.id
|
|
26
|
+
};
|
|
27
|
+
} catch (err) {
|
|
28
|
+
debug('Error creating project', err);
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
3
32
|
export async function getProjectById(projectId) {
|
|
4
33
|
const client = await getProjectCliClient({
|
|
5
34
|
apiVersion: PROJECTS_API_VERSION,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/projects.ts"],"sourcesContent":["import {getProjectCliClient} from '@sanity/cli-core'\n\nexport const PROJECTS_API_VERSION = '2025-09-22'\n\nexport async function getProjectById(projectId: string) {\n const client = await getProjectCliClient({\n apiVersion: PROJECTS_API_VERSION,\n projectId,\n requireUser: true,\n })\n\n return client.projects.getById(projectId)\n}\n"],"names":["getProjectCliClient","PROJECTS_API_VERSION","
|
|
1
|
+
{"version":3,"sources":["../../src/services/projects.ts"],"sourcesContent":["import {debug, getGlobalCliClient, getProjectCliClient} from '@sanity/cli-core'\n\nexport const PROJECTS_API_VERSION = '2025-09-22'\n\nexport const CREATE_PROJECT_API_VERSION = 'v2025-05-14'\n\nexport interface CreateProjectOptions {\n displayName: string\n\n metadata?: {\n coupon?: string\n integration?: string\n }\n organizationId?: string\n subscription?: {planId: string}\n}\n\nexport interface CreateProjectResult {\n displayName: string\n projectId: string\n}\n\n/**\n * Create a new Sanity project\n */\nexport async function createProject(options: CreateProjectOptions): Promise<CreateProjectResult> {\n const client = await getGlobalCliClient({\n apiVersion: CREATE_PROJECT_API_VERSION,\n requireUser: true,\n })\n\n try {\n const response = await client.request({\n body: {\n ...options,\n metadata: {\n ...options?.metadata,\n integration: 'cli',\n },\n },\n method: 'POST',\n uri: '/projects',\n })\n\n return {\n displayName: options.displayName || '',\n projectId: response.projectId || response.id,\n }\n } catch (err) {\n debug('Error creating project', err)\n throw err\n }\n}\n\nexport async function getProjectById(projectId: string) {\n const client = await getProjectCliClient({\n apiVersion: PROJECTS_API_VERSION,\n projectId,\n requireUser: true,\n })\n\n return client.projects.getById(projectId)\n}\n"],"names":["debug","getGlobalCliClient","getProjectCliClient","PROJECTS_API_VERSION","CREATE_PROJECT_API_VERSION","createProject","options","client","apiVersion","requireUser","response","request","body","metadata","integration","method","uri","displayName","projectId","id","err","getProjectById","projects","getById"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAO,mBAAkB;AAE/E,OAAO,MAAMC,uBAAuB,aAAY;AAEhD,OAAO,MAAMC,6BAA6B,cAAa;AAkBvD;;CAEC,GACD,OAAO,eAAeC,cAAcC,OAA6B;IAC/D,MAAMC,SAAS,MAAMN,mBAAmB;QACtCO,YAAYJ;QACZK,aAAa;IACf;IAEA,IAAI;QACF,MAAMC,WAAW,MAAMH,OAAOI,OAAO,CAAC;YACpCC,MAAM;gBACJ,GAAGN,OAAO;gBACVO,UAAU;oBACR,GAAGP,SAASO,QAAQ;oBACpBC,aAAa;gBACf;YACF;YACAC,QAAQ;YACRC,KAAK;QACP;QAEA,OAAO;YACLC,aAAaX,QAAQW,WAAW,IAAI;YACpCC,WAAWR,SAASQ,SAAS,IAAIR,SAASS,EAAE;QAC9C;IACF,EAAE,OAAOC,KAAK;QACZpB,MAAM,0BAA0BoB;QAChC,MAAMA;IACR;AACF;AAEA,OAAO,eAAeC,eAAeH,SAAiB;IACpD,MAAMX,SAAS,MAAML,oBAAoB;QACvCM,YAAYL;QACZe;QACAT,aAAa;IACf;IAEA,OAAOF,OAAOe,QAAQ,CAACC,OAAO,CAACL;AACjC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getGlobalCliClient } from '@sanity/cli-core';
|
|
2
|
+
import { INIT_API_VERSION } from '../actions/init/constants.js';
|
|
3
|
+
export async function getCliUser() {
|
|
4
|
+
const client = await getGlobalCliClient({
|
|
5
|
+
apiVersion: INIT_API_VERSION,
|
|
6
|
+
requireUser: true
|
|
7
|
+
});
|
|
8
|
+
return client.users.getById('me');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/user.ts"],"sourcesContent":["import {getGlobalCliClient, type SanityOrgUser} from '@sanity/cli-core'\n\nimport {INIT_API_VERSION} from '../actions/init/constants.js'\n\nexport async function getCliUser() {\n const client = await getGlobalCliClient({\n apiVersion: INIT_API_VERSION,\n requireUser: true,\n })\n\n return client.users.getById('me') as unknown as SanityOrgUser\n}\n"],"names":["getGlobalCliClient","INIT_API_VERSION","getCliUser","client","apiVersion","requireUser","users","getById"],"mappings":"AAAA,SAAQA,kBAAkB,QAA2B,mBAAkB;AAEvE,SAAQC,gBAAgB,QAAO,+BAA8B;AAE7D,OAAO,eAAeC;IACpB,MAAMC,SAAS,MAAMH,mBAAmB;QACtCI,YAAYH;QACZI,aAAa;IACf;IAEA,OAAOF,OAAOG,KAAK,CAACC,OAAO,CAAC;AAC9B"}
|
package/oclif.config.js
CHANGED
|
@@ -6,6 +6,11 @@ export default {
|
|
|
6
6
|
hooks: {
|
|
7
7
|
prerun: ['./dist/hooks/prerun/setupTelemetry.js'],
|
|
8
8
|
},
|
|
9
|
-
plugins: [
|
|
9
|
+
plugins: [
|
|
10
|
+
'@oclif/plugin-help',
|
|
11
|
+
'@oclif/plugin-not-found',
|
|
12
|
+
'@sanity/runtime-cli',
|
|
13
|
+
'@sanity/migrate',
|
|
14
|
+
],
|
|
10
15
|
topicSeparator: ' ',
|
|
11
16
|
}
|