prismic 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/{builders-hKD4IrLX-cdTCGdwG.mjs → builders-hKD4IrLX-CiOmsZQP.mjs} +1 -1
  2. package/dist/index.mjs +119 -58
  3. package/dist/nextjs-c8JOjFCt.mjs +413 -0
  4. package/dist/nuxt-BhwnOusi.mjs +90 -0
  5. package/dist/string-CFNpwnbk.mjs +7 -0
  6. package/dist/sveltekit-BW5_-HtZ.mjs +263 -0
  7. package/package.json +1 -1
  8. package/src/adapters/index.ts +6 -0
  9. package/src/adapters/nextjs.templates.ts +170 -38
  10. package/src/adapters/nextjs.ts +33 -3
  11. package/src/adapters/nuxt.templates.ts +48 -0
  12. package/src/adapters/nuxt.ts +42 -20
  13. package/src/adapters/sveltekit.templates.ts +92 -35
  14. package/src/adapters/sveltekit.ts +38 -3
  15. package/src/auth.ts +1 -2
  16. package/src/clients/locale.ts +64 -0
  17. package/src/clients/user.ts +1 -0
  18. package/src/clients/wroom.ts +212 -0
  19. package/src/commands/gen-setup.ts +38 -0
  20. package/src/commands/gen-types.ts +35 -0
  21. package/src/commands/gen.ts +18 -0
  22. package/src/commands/init.ts +7 -1
  23. package/src/commands/locale-add.ts +47 -0
  24. package/src/commands/locale-list.ts +43 -0
  25. package/src/commands/locale-remove.ts +45 -0
  26. package/src/commands/locale-set-master.ts +61 -0
  27. package/src/commands/locale.ts +28 -0
  28. package/src/commands/repo-create.ts +60 -0
  29. package/src/commands/repo-list.ts +58 -0
  30. package/src/commands/repo-set-api-access.ts +53 -0
  31. package/src/commands/repo-set-name.ts +46 -0
  32. package/src/commands/repo-view.ts +74 -0
  33. package/src/commands/repo.ts +33 -0
  34. package/src/commands/sync.ts +4 -2
  35. package/src/commands/token-create.ts +55 -0
  36. package/src/commands/token-delete.ts +61 -0
  37. package/src/commands/token-list.ts +67 -0
  38. package/src/commands/token.ts +23 -0
  39. package/src/config.ts +53 -0
  40. package/src/env.ts +2 -0
  41. package/src/index.ts +20 -0
  42. package/src/lib/codegen.ts +6 -5
  43. package/src/lib/url.ts +7 -0
  44. package/dist/nextjs-DrbOdw3q.mjs +0 -318
  45. package/dist/nuxt-DO5Kp4yy.mjs +0 -59
  46. package/dist/string-CnZrLYLV.mjs +0 -7
  47. package/dist/sveltekit-KHG7YUoX.mjs +0 -236
@@ -0,0 +1,47 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { upsertLocale } from "../clients/locale";
3
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
4
+ import { UnknownRequestError } from "../lib/request";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const config = {
8
+ name: "prismic locale add",
9
+ description: `
10
+ Add a locale to a Prismic repository.
11
+
12
+ By default, this command reads the repository from prismic.config.json at the
13
+ project root.
14
+ `,
15
+ positionals: {
16
+ code: { description: "Locale code (e.g. fr-fr, es-es)" },
17
+ },
18
+ options: {
19
+ master: { type: "boolean", description: "Set as the master locale" },
20
+ name: { type: "string", short: "n", description: "Custom display name (for custom locales)" },
21
+ repo: { type: "string", short: "r", description: "Repository domain" },
22
+ },
23
+ } satisfies CommandConfig;
24
+
25
+ export default createCommand(config, async ({ positionals, values }) => {
26
+ const [code] = positionals;
27
+ const { repo = await getRepositoryName(), master = false, name } = values;
28
+
29
+ if (!code) {
30
+ throw new CommandError("Missing required argument: <code>");
31
+ }
32
+
33
+ const token = await getToken();
34
+ const host = await getHost();
35
+
36
+ try {
37
+ await upsertLocale({ id: code, isMaster: master, customName: name }, { repo, token, host });
38
+ } catch (error) {
39
+ if (error instanceof UnknownRequestError) {
40
+ const message = await error.text();
41
+ throw new CommandError(`Failed to add locale: ${message}`);
42
+ }
43
+ throw error;
44
+ }
45
+
46
+ console.info(`Locale added: ${code}`);
47
+ });
@@ -0,0 +1,43 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { getLocales } from "../clients/locale";
3
+ import { createCommand, type CommandConfig } from "../lib/command";
4
+ import { stringify } from "../lib/json";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const config = {
8
+ name: "prismic locale list",
9
+ description: `
10
+ List all locales in a Prismic repository.
11
+
12
+ By default, this command reads the repository from prismic.config.json at the
13
+ project root.
14
+ `,
15
+ options: {
16
+ json: { type: "boolean", description: "Output as JSON" },
17
+ repo: { type: "string", short: "r", description: "Repository domain" },
18
+ },
19
+ } satisfies CommandConfig;
20
+
21
+ export default createCommand(config, async ({ values }) => {
22
+ const { repo = await getRepositoryName(), json } = values;
23
+
24
+ const token = await getToken();
25
+ const host = await getHost();
26
+
27
+ const locales = await getLocales({ repo, token, host });
28
+
29
+ if (json) {
30
+ console.info(stringify(locales));
31
+ return;
32
+ }
33
+
34
+ if (locales.length === 0) {
35
+ console.info("No locales found.");
36
+ return;
37
+ }
38
+
39
+ for (const locale of locales) {
40
+ const masterLabel = locale.isMaster ? " (master)" : "";
41
+ console.info(`${locale.id} ${locale.label}${masterLabel}`);
42
+ }
43
+ });
@@ -0,0 +1,45 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { removeLocale } from "../clients/locale";
3
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
4
+ import { UnknownRequestError } from "../lib/request";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const config = {
8
+ name: "prismic locale remove",
9
+ description: `
10
+ Remove a locale from a Prismic repository.
11
+
12
+ By default, this command reads the repository from prismic.config.json at the
13
+ project root.
14
+ `,
15
+ positionals: {
16
+ code: { description: "Locale code (e.g. en-us, fr-fr)" },
17
+ },
18
+ options: {
19
+ repo: { type: "string", short: "r", description: "Repository domain" },
20
+ },
21
+ } satisfies CommandConfig;
22
+
23
+ export default createCommand(config, async ({ positionals, values }) => {
24
+ const [code] = positionals;
25
+ const { repo = await getRepositoryName() } = values;
26
+
27
+ if (!code) {
28
+ throw new CommandError("Missing required argument: <code>");
29
+ }
30
+
31
+ const token = await getToken();
32
+ const host = await getHost();
33
+
34
+ try {
35
+ await removeLocale(code, { repo, token, host });
36
+ } catch (error) {
37
+ if (error instanceof UnknownRequestError) {
38
+ const message = await error.text();
39
+ throw new CommandError(`Failed to remove locale: ${message}`);
40
+ }
41
+ throw error;
42
+ }
43
+
44
+ console.info(`Locale removed: ${code}`);
45
+ });
@@ -0,0 +1,61 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { getLocales, upsertLocale } from "../clients/locale";
3
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
4
+ import { UnknownRequestError } from "../lib/request";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const config = {
8
+ name: "prismic locale set-master",
9
+ description: `
10
+ Set the master locale for a Prismic repository.
11
+
12
+ By default, this command reads the repository from prismic.config.json at the
13
+ project root.
14
+ `,
15
+ positionals: {
16
+ code: { description: "Locale code (e.g. en-us, fr-fr)" },
17
+ },
18
+ options: {
19
+ repo: { type: "string", short: "r", description: "Repository domain" },
20
+ },
21
+ } satisfies CommandConfig;
22
+
23
+ export default createCommand(config, async ({ positionals, values }) => {
24
+ const [code] = positionals;
25
+ const { repo = await getRepositoryName() } = values;
26
+
27
+ if (!code) {
28
+ throw new CommandError("Missing required argument: <code>");
29
+ }
30
+
31
+ const token = await getToken();
32
+ const host = await getHost();
33
+
34
+ const locales = await getLocales({ repo, token, host });
35
+ const locale = locales.find((l) => l.id === code);
36
+
37
+ if (!locale) {
38
+ throw new CommandError(
39
+ `Locale "${code}" not found. Available locales: ${locales.map((l) => l.id).join(", ")}`,
40
+ );
41
+ }
42
+
43
+ if (locale.isMaster) {
44
+ throw new CommandError(`Locale "${code}" is already the master.`);
45
+ }
46
+
47
+ try {
48
+ await upsertLocale(
49
+ { id: locale.id, isMaster: true, customName: locale.customName ?? undefined },
50
+ { repo, token, host },
51
+ );
52
+ } catch (error) {
53
+ if (error instanceof UnknownRequestError) {
54
+ const message = await error.text();
55
+ throw new CommandError(`Failed to set master locale: ${message}`);
56
+ }
57
+ throw error;
58
+ }
59
+
60
+ console.info(`Master locale set: ${code}`);
61
+ });
@@ -0,0 +1,28 @@
1
+ import { createCommandRouter } from "../lib/command";
2
+ import localeAdd from "./locale-add";
3
+ import localeList from "./locale-list";
4
+ import localeRemove from "./locale-remove";
5
+ import localeSetMaster from "./locale-set-master";
6
+
7
+ export default createCommandRouter({
8
+ name: "prismic locale",
9
+ description: "Manage locales in a Prismic repository.",
10
+ commands: {
11
+ add: {
12
+ handler: localeAdd,
13
+ description: "Add a locale",
14
+ },
15
+ list: {
16
+ handler: localeList,
17
+ description: "List locales",
18
+ },
19
+ remove: {
20
+ handler: localeRemove,
21
+ description: "Remove a locale",
22
+ },
23
+ "set-master": {
24
+ handler: localeSetMaster,
25
+ description: "Set the master locale",
26
+ },
27
+ },
28
+ });
@@ -0,0 +1,60 @@
1
+ import { getAdapter } from "../adapters";
2
+ import { getHost, getToken } from "../auth";
3
+ import { checkIsDomainAvailable, createRepository } from "../clients/wroom";
4
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
5
+ import { UnknownRequestError } from "../lib/request";
6
+
7
+ const MAX_DOMAIN_TRIES = 5;
8
+
9
+ const config = {
10
+ name: "prismic repo create",
11
+ description: "Create a new Prismic repository.",
12
+ options: {
13
+ name: { type: "string", short: "n", description: "Display name for the repository" },
14
+ },
15
+ } satisfies CommandConfig;
16
+
17
+ export default createCommand(config, async ({ values }) => {
18
+ const { name } = values;
19
+
20
+ const token = await getToken();
21
+ const host = await getHost();
22
+
23
+ const domain = await findAvailableDomain({ token, host });
24
+ if (!domain) {
25
+ throw new CommandError("Failed to create a repository. Please try again.");
26
+ }
27
+
28
+ const adapter = await getAdapter().catch(() => undefined);
29
+ const framework = adapter?.id ?? "other";
30
+
31
+ try {
32
+ await createRepository({ domain, name: name ?? domain, framework, token, host });
33
+ } catch (error) {
34
+ if (error instanceof UnknownRequestError) {
35
+ const message = await error.text();
36
+ throw new CommandError(`Failed to create repository: ${message}`);
37
+ }
38
+ throw error;
39
+ }
40
+
41
+ console.info(`Repository created: ${domain}`);
42
+ console.info(`URL: https://${domain}.${host}/`);
43
+ });
44
+
45
+ async function findAvailableDomain(config: {
46
+ token: string | undefined;
47
+ host: string;
48
+ }): Promise<string | undefined> {
49
+ const { token, host } = config;
50
+ let domain;
51
+ for (let i = 0; i < MAX_DOMAIN_TRIES; i++) {
52
+ const candidate = crypto.randomUUID().replace(/-/g, "").slice(0, 8);
53
+ const available = await checkIsDomainAvailable({ domain: candidate, token, host });
54
+ if (available) {
55
+ domain = candidate;
56
+ break;
57
+ }
58
+ }
59
+ return domain;
60
+ }
@@ -0,0 +1,58 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { getProfile } from "../clients/user";
3
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
4
+ import { stringify } from "../lib/json";
5
+ import { UnknownRequestError } from "../lib/request";
6
+
7
+ const config = {
8
+ name: "prismic repo list",
9
+ description: "List all Prismic repositories associated with your account.",
10
+ options: {
11
+ json: { type: "boolean", description: "Output as JSON" },
12
+ },
13
+ } satisfies CommandConfig;
14
+
15
+ export default createCommand(config, async ({ values }) => {
16
+ const { json } = values;
17
+
18
+ const token = await getToken();
19
+ const host = await getHost();
20
+
21
+ let profile;
22
+ try {
23
+ profile = await getProfile({ token, host });
24
+ } catch (error) {
25
+ if (error instanceof UnknownRequestError) {
26
+ const message = await error.text();
27
+ throw new CommandError(`Failed to list repositories: ${message}`);
28
+ }
29
+ throw error;
30
+ }
31
+
32
+ const repos = profile.repositories;
33
+
34
+ if (json) {
35
+ console.info(
36
+ stringify(
37
+ repos.map((repo) => ({
38
+ domain: repo.domain,
39
+ name: repo.name ?? null,
40
+ role: repo.role ?? null,
41
+ url: `https://${repo.domain}.${host}/`,
42
+ })),
43
+ ),
44
+ );
45
+ return;
46
+ }
47
+
48
+ if (repos.length === 0) {
49
+ console.info("No repositories found.");
50
+ return;
51
+ }
52
+
53
+ for (const repo of repos) {
54
+ const name = repo.name || "(no name)";
55
+ const role = repo.role ? ` ${repo.role}` : "";
56
+ console.info(`${repo.domain} ${name}${role}`);
57
+ }
58
+ });
@@ -0,0 +1,53 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { type RepositoryAccessLevel, setRepositoryAccess } from "../clients/wroom";
3
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
4
+ import { UnknownRequestError } from "../lib/request";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const VALID_LEVELS: RepositoryAccessLevel[] = ["private", "public", "open"];
8
+
9
+ const config = {
10
+ name: "prismic repo set-api-access",
11
+ description: `
12
+ Set the Content API access level of a Prismic repository.
13
+
14
+ By default, this command reads the repository from prismic.config.json at the
15
+ project root.
16
+ `,
17
+ positionals: {
18
+ level: { description: `Access level (${VALID_LEVELS.join(", ")})` },
19
+ },
20
+ options: {
21
+ repo: { type: "string", short: "r", description: "Repository domain" },
22
+ },
23
+ } satisfies CommandConfig;
24
+
25
+ export default createCommand(config, async ({ positionals, values }) => {
26
+ const [level] = positionals;
27
+ const { repo = await getRepositoryName() } = values;
28
+
29
+ if (!level) {
30
+ throw new CommandError("Missing required argument: <level>");
31
+ }
32
+
33
+ if (!VALID_LEVELS.includes(level as RepositoryAccessLevel)) {
34
+ throw new CommandError(
35
+ `Invalid access level: ${level}. Must be one of: ${VALID_LEVELS.join(", ")}`,
36
+ );
37
+ }
38
+
39
+ const token = await getToken();
40
+ const host = await getHost();
41
+
42
+ try {
43
+ await setRepositoryAccess(level as RepositoryAccessLevel, { repo, token, host });
44
+ } catch (error) {
45
+ if (error instanceof UnknownRequestError) {
46
+ const message = await error.text();
47
+ throw new CommandError(`Failed to set repository access: ${message}`);
48
+ }
49
+ throw error;
50
+ }
51
+
52
+ console.info(`Repository access set to: ${level}`);
53
+ });
@@ -0,0 +1,46 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { setRepositoryName } from "../clients/wroom";
3
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
4
+ import { UnknownRequestError } from "../lib/request";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const config = {
8
+ name: "prismic repo set-name",
9
+ description: `
10
+ Set the display name of a Prismic repository.
11
+
12
+ By default, this command reads the repository from prismic.config.json at the
13
+ project root.
14
+ `,
15
+ positionals: {
16
+ name: { description: "Display name for the repository" },
17
+ },
18
+ options: {
19
+ repo: { type: "string", short: "r", description: "Repository domain" },
20
+ },
21
+ } satisfies CommandConfig;
22
+
23
+ export default createCommand(config, async ({ positionals, values }) => {
24
+ const [displayName] = positionals;
25
+ const { repo = await getRepositoryName() } = values;
26
+
27
+ if (!displayName) {
28
+ throw new CommandError("Missing required argument: <name>");
29
+ }
30
+
31
+ const token = await getToken();
32
+ const host = await getHost();
33
+
34
+ let confirmedName;
35
+ try {
36
+ confirmedName = await setRepositoryName(displayName, { repo, token, host });
37
+ } catch (error) {
38
+ if (error instanceof UnknownRequestError) {
39
+ const message = await error.text();
40
+ throw new CommandError(`Failed to set repository name: ${message}`);
41
+ }
42
+ throw error;
43
+ }
44
+
45
+ console.info(`Repository name set to: ${confirmedName}`);
46
+ });
@@ -0,0 +1,74 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { openBrowser } from "../lib/browser";
3
+ import { getProfile } from "../clients/user";
4
+ import { getRepositoryAccess } from "../clients/wroom";
5
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
6
+ import { stringify } from "../lib/json";
7
+ import { UnknownRequestError } from "../lib/request";
8
+ import { getRepositoryName } from "../project";
9
+
10
+ const config = {
11
+ name: "prismic repo view",
12
+ description: `
13
+ View details of a Prismic repository.
14
+
15
+ By default, this command reads the repository from prismic.config.json at the
16
+ project root.
17
+ `,
18
+ options: {
19
+ web: { type: "boolean", short: "w", description: "Open repository in browser" },
20
+ json: { type: "boolean", description: "Output as JSON" },
21
+ repo: { type: "string", short: "r", description: "Repository domain" },
22
+ },
23
+ } satisfies CommandConfig;
24
+
25
+ export default createCommand(config, async ({ values }) => {
26
+ const { repo = await getRepositoryName(), web, json } = values;
27
+
28
+ const token = await getToken();
29
+ const host = await getHost();
30
+ const url = `https://${repo}.${host}/`;
31
+
32
+ if (web) {
33
+ openBrowser(new URL(url));
34
+ console.info(`Opening ${url}`);
35
+ return;
36
+ }
37
+
38
+ let profile;
39
+ let access;
40
+ try {
41
+ [profile, access] = await Promise.all([
42
+ getProfile({ token, host }),
43
+ getRepositoryAccess({ repo, token, host }),
44
+ ]);
45
+ } catch (error) {
46
+ if (error instanceof UnknownRequestError) {
47
+ const message = await error.text();
48
+ throw new CommandError(`Failed to fetch repository details: ${message}`);
49
+ }
50
+ throw error;
51
+ }
52
+
53
+ const repoData = profile.repositories.find((r) => r.domain === repo);
54
+ if (!repoData) {
55
+ throw new CommandError(`Repository not found: ${repo}`);
56
+ }
57
+
58
+ if (json) {
59
+ console.info(
60
+ stringify({
61
+ domain: repoData.domain,
62
+ name: repoData.name ?? null,
63
+ url,
64
+ apiAccess: access,
65
+ }),
66
+ );
67
+ return;
68
+ }
69
+
70
+ const name = repoData.name || "(no name)";
71
+ console.info(`Name: ${name}`);
72
+ console.info(`URL: ${url}`);
73
+ console.info(`Content API: ${access}`);
74
+ });
@@ -0,0 +1,33 @@
1
+ import { createCommandRouter } from "../lib/command";
2
+ import repoCreate from "./repo-create";
3
+ import repoList from "./repo-list";
4
+ import repoSetApiAccess from "./repo-set-api-access";
5
+ import repoSetName from "./repo-set-name";
6
+ import repoView from "./repo-view";
7
+
8
+ export default createCommandRouter({
9
+ name: "prismic repo",
10
+ description: "Manage Prismic repositories.",
11
+ commands: {
12
+ create: {
13
+ handler: repoCreate,
14
+ description: "Create a new repository",
15
+ },
16
+ list: {
17
+ handler: repoList,
18
+ description: "List repositories",
19
+ },
20
+ view: {
21
+ handler: repoView,
22
+ description: "View repository details",
23
+ },
24
+ "set-name": {
25
+ handler: repoSetName,
26
+ description: "Set repository display name",
27
+ },
28
+ "set-api-access": {
29
+ handler: repoSetApiAccess,
30
+ description: "Set Content API access level",
31
+ },
32
+ },
33
+ });
@@ -4,6 +4,7 @@ import { setTimeout } from "node:timers/promises";
4
4
  import { getAdapter, type Adapter } from "../adapters";
5
5
  import { getHost, getToken } from "../auth";
6
6
  import { getCustomTypes, getSlices } from "../clients/custom-types";
7
+ import { env } from "../env";
7
8
  import { generateAndWriteTypes } from "../lib/codegen";
8
9
  import { createCommand, type CommandConfig } from "../lib/command";
9
10
  import { segmentTrackEnd, segmentTrackStart } from "../lib/segment";
@@ -11,7 +12,7 @@ import { dedent } from "../lib/string";
11
12
  import { findProjectRoot, getRepositoryName } from "../project";
12
13
 
13
14
  // 5 seconds balances responsiveness with API load
14
- const POLL_INTERVAL_MS = 5000;
15
+ const POLL_INTERVAL_MS = env.TEST ? 500 : 5000;
15
16
  const MAX_BACKOFF_MS = 60000; // Cap backoff at 1 minute
16
17
  const MAX_CONSECUTIVE_ERRORS = 10;
17
18
 
@@ -226,9 +227,10 @@ async function regenerateTypes(adapter: Adapter): Promise<void> {
226
227
  const slices = await adapter.getSlices();
227
228
  const customTypes = await adapter.getCustomTypes();
228
229
  const projectRoot = await findProjectRoot();
230
+ const output = new URL("prismicio-types.d.ts", projectRoot);
229
231
  await generateAndWriteTypes({
230
232
  customTypes: customTypes.map((customType) => customType.model),
231
233
  slices: slices.map((slice) => slice.model),
232
- projectRoot,
234
+ output,
233
235
  });
234
236
  }
@@ -0,0 +1,55 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import {
3
+ createOAuthAuthorization,
4
+ createOAuthApp,
5
+ createWriteToken,
6
+ getOAuthApps,
7
+ } from "../clients/wroom";
8
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
9
+ import { getRepositoryName } from "../project";
10
+
11
+ const CLI_APP_NAME = "Prismic CLI";
12
+
13
+ const config = {
14
+ name: "prismic token create",
15
+ description: `
16
+ Create a new API token for a Prismic repository.
17
+
18
+ By default, this command reads the repository from prismic.config.json at the
19
+ project root.
20
+ `,
21
+ options: {
22
+ write: { type: "boolean", description: "Create a write token" },
23
+ "allow-releases": {
24
+ type: "boolean",
25
+ description: "Allow access to releases (read tokens only)",
26
+ },
27
+ repo: { type: "string", short: "r", description: "Repository domain" },
28
+ },
29
+ } satisfies CommandConfig;
30
+
31
+ export default createCommand(config, async ({ values }) => {
32
+ const { repo = await getRepositoryName(), write, "allow-releases": allowReleases } = values;
33
+
34
+ if (write && allowReleases) {
35
+ throw new CommandError("--allow-releases is only valid for access tokens (not with --write)");
36
+ }
37
+
38
+ const token = await getToken();
39
+ const host = await getHost();
40
+
41
+ if (write) {
42
+ const writeToken = await createWriteToken(CLI_APP_NAME, { repo, token, host });
43
+ console.info(`Token created: ${writeToken.token}`);
44
+ } else {
45
+ const scope = allowReleases ? "master+releases" : "master";
46
+
47
+ // Find or create the CLI OAuth app.
48
+ const apps = await getOAuthApps({ repo, token, host });
49
+ let app = apps.find((a) => a.name === CLI_APP_NAME);
50
+ if (!app) app = await createOAuthApp(CLI_APP_NAME, { repo, token, host });
51
+
52
+ const accessToken = await createOAuthAuthorization(app.id, scope, { repo, token, host });
53
+ console.info(`Token created: ${accessToken.token}`);
54
+ }
55
+ });