@angeloashmore/prismic-cli-poc 0.0.0-canary.1143872

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 (139) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +98 -0
  3. package/dist/index.mjs +2508 -0
  4. package/package.json +53 -0
  5. package/src/codegen-types.ts +82 -0
  6. package/src/codegen.ts +45 -0
  7. package/src/custom-type-add-field-boolean.ts +222 -0
  8. package/src/custom-type-add-field-color.ts +205 -0
  9. package/src/custom-type-add-field-date.ts +208 -0
  10. package/src/custom-type-add-field-embed.ts +205 -0
  11. package/src/custom-type-add-field-geo-point.ts +202 -0
  12. package/src/custom-type-add-field-group.ts +179 -0
  13. package/src/custom-type-add-field-image.ts +205 -0
  14. package/src/custom-type-add-field-key-text.ts +205 -0
  15. package/src/custom-type-add-field-link.ts +228 -0
  16. package/src/custom-type-add-field-number.ts +237 -0
  17. package/src/custom-type-add-field-rich-text.ts +229 -0
  18. package/src/custom-type-add-field-select.ts +211 -0
  19. package/src/custom-type-add-field-timestamp.ts +208 -0
  20. package/src/custom-type-add-field-uid.ts +188 -0
  21. package/src/custom-type-add-field.ts +116 -0
  22. package/src/custom-type-connect-slice.ts +214 -0
  23. package/src/custom-type-create.ts +112 -0
  24. package/src/custom-type-disconnect-slice.ts +171 -0
  25. package/src/custom-type-list.ts +110 -0
  26. package/src/custom-type-remove-field.ts +171 -0
  27. package/src/custom-type-remove.ts +138 -0
  28. package/src/custom-type-set-name.ts +138 -0
  29. package/src/custom-type-view.ts +118 -0
  30. package/src/custom-type.ts +85 -0
  31. package/src/docs-fetch.ts +146 -0
  32. package/src/docs-list.ts +131 -0
  33. package/src/docs.ts +54 -0
  34. package/src/index.ts +132 -0
  35. package/src/init.ts +64 -0
  36. package/src/lib/auth.ts +83 -0
  37. package/src/lib/config.ts +111 -0
  38. package/src/lib/custom-types-api.ts +438 -0
  39. package/src/lib/field-path.ts +81 -0
  40. package/src/lib/file.ts +49 -0
  41. package/src/lib/framework.ts +143 -0
  42. package/src/lib/json.ts +3 -0
  43. package/src/lib/request.ts +116 -0
  44. package/src/lib/slice.ts +115 -0
  45. package/src/lib/string.ts +6 -0
  46. package/src/lib/url.ts +25 -0
  47. package/src/locale-add.ts +116 -0
  48. package/src/locale-list.ts +107 -0
  49. package/src/locale-remove.ts +88 -0
  50. package/src/locale-set-default.ts +131 -0
  51. package/src/locale.ts +60 -0
  52. package/src/login.ts +152 -0
  53. package/src/logout.ts +36 -0
  54. package/src/page-type-add-field-boolean.ts +238 -0
  55. package/src/page-type-add-field-color.ts +224 -0
  56. package/src/page-type-add-field-date.ts +227 -0
  57. package/src/page-type-add-field-embed.ts +224 -0
  58. package/src/page-type-add-field-geo-point.ts +221 -0
  59. package/src/page-type-add-field-group.ts +198 -0
  60. package/src/page-type-add-field-image.ts +224 -0
  61. package/src/page-type-add-field-key-text.ts +224 -0
  62. package/src/page-type-add-field-link.ts +247 -0
  63. package/src/page-type-add-field-number.ts +256 -0
  64. package/src/page-type-add-field-rich-text.ts +248 -0
  65. package/src/page-type-add-field-select.ts +230 -0
  66. package/src/page-type-add-field-timestamp.ts +227 -0
  67. package/src/page-type-add-field-uid.ts +207 -0
  68. package/src/page-type-add-field.ts +116 -0
  69. package/src/page-type-connect-slice.ts +214 -0
  70. package/src/page-type-create.ts +161 -0
  71. package/src/page-type-disconnect-slice.ts +171 -0
  72. package/src/page-type-list.ts +109 -0
  73. package/src/page-type-remove-field.ts +171 -0
  74. package/src/page-type-remove.ts +138 -0
  75. package/src/page-type-set-name.ts +138 -0
  76. package/src/page-type-set-repeatable.ts +147 -0
  77. package/src/page-type-view.ts +118 -0
  78. package/src/page-type.ts +90 -0
  79. package/src/preview-add.ts +126 -0
  80. package/src/preview-get-simulator.ts +104 -0
  81. package/src/preview-list.ts +106 -0
  82. package/src/preview-remove-simulator.ts +80 -0
  83. package/src/preview-remove.ts +109 -0
  84. package/src/preview-set-name.ts +137 -0
  85. package/src/preview-set-simulator.ts +116 -0
  86. package/src/preview.ts +75 -0
  87. package/src/pull.ts +242 -0
  88. package/src/push.ts +405 -0
  89. package/src/repo-create.ts +195 -0
  90. package/src/repo-get-access.ts +86 -0
  91. package/src/repo-list.ts +100 -0
  92. package/src/repo-set-access.ts +100 -0
  93. package/src/repo-set-name.ts +102 -0
  94. package/src/repo-view.ts +113 -0
  95. package/src/repo.ts +70 -0
  96. package/src/slice-add-field-boolean.ts +240 -0
  97. package/src/slice-add-field-color.ts +226 -0
  98. package/src/slice-add-field-date.ts +226 -0
  99. package/src/slice-add-field-embed.ts +226 -0
  100. package/src/slice-add-field-geo-point.ts +223 -0
  101. package/src/slice-add-field-group.ts +191 -0
  102. package/src/slice-add-field-image.ts +223 -0
  103. package/src/slice-add-field-key-text.ts +226 -0
  104. package/src/slice-add-field-link.ts +245 -0
  105. package/src/slice-add-field-number.ts +226 -0
  106. package/src/slice-add-field-rich-text.ts +250 -0
  107. package/src/slice-add-field-select.ts +232 -0
  108. package/src/slice-add-field-timestamp.ts +226 -0
  109. package/src/slice-add-field.ts +111 -0
  110. package/src/slice-add-variation.ts +139 -0
  111. package/src/slice-create.ts +203 -0
  112. package/src/slice-list-variations.ts +67 -0
  113. package/src/slice-list.ts +88 -0
  114. package/src/slice-remove-field.ts +122 -0
  115. package/src/slice-remove-variation.ts +112 -0
  116. package/src/slice-remove.ts +91 -0
  117. package/src/slice-rename.ts +122 -0
  118. package/src/slice-set-screenshot.ts +235 -0
  119. package/src/slice-view.ts +80 -0
  120. package/src/slice.ts +95 -0
  121. package/src/status.ts +873 -0
  122. package/src/token-create.ts +203 -0
  123. package/src/token-delete.ts +182 -0
  124. package/src/token-list.ts +223 -0
  125. package/src/token-set-name.ts +193 -0
  126. package/src/token.ts +60 -0
  127. package/src/webhook-add-header.ts +118 -0
  128. package/src/webhook-create.ts +152 -0
  129. package/src/webhook-disable.ts +109 -0
  130. package/src/webhook-enable.ts +132 -0
  131. package/src/webhook-list.ts +93 -0
  132. package/src/webhook-remove-header.ts +117 -0
  133. package/src/webhook-remove.ts +106 -0
  134. package/src/webhook-set-triggers.ts +148 -0
  135. package/src/webhook-status.ts +90 -0
  136. package/src/webhook-test.ts +106 -0
  137. package/src/webhook-view.ts +147 -0
  138. package/src/webhook.ts +95 -0
  139. package/src/whoami.ts +62 -0
@@ -0,0 +1,100 @@
1
+ import { parseArgs } from "node:util";
2
+ import * as v from "valibot";
3
+
4
+ import { isAuthenticated } from "./lib/auth";
5
+ import { stringify } from "./lib/json";
6
+ import { ForbiddenRequestError, request } from "./lib/request";
7
+ import { getRepoUrl, getUserServiceUrl } from "./lib/url";
8
+
9
+ const HELP = `
10
+ List all Prismic repositories.
11
+
12
+ USAGE
13
+ prismic repo list [flags]
14
+
15
+ FLAGS
16
+ --json Output as JSON
17
+ -h, --help Show help for command
18
+
19
+ LEARN MORE
20
+ Use \`prismic repo <command> --help\` for more information about a command.
21
+ `.trim();
22
+
23
+ const ProfileSchema = v.object({
24
+ repositories: v.array(
25
+ v.object({
26
+ domain: v.string(),
27
+ name: v.optional(v.string()),
28
+ role: v.string(),
29
+ }),
30
+ ),
31
+ });
32
+
33
+ export async function repoList(): Promise<void> {
34
+ const {
35
+ values: { help, json },
36
+ } = parseArgs({
37
+ args: process.argv.slice(4), // skip: node, script, "repo", "list"
38
+ options: {
39
+ help: { type: "boolean", short: "h" },
40
+ json: { type: "boolean" },
41
+ },
42
+ });
43
+
44
+ if (help) {
45
+ console.info(HELP);
46
+ return;
47
+ }
48
+
49
+ const authenticated = await isAuthenticated();
50
+ if (!authenticated) {
51
+ handleUnauthenticated();
52
+ return;
53
+ }
54
+
55
+ const response = await fetchProfile();
56
+ if (!response.ok) {
57
+ if (response.error instanceof ForbiddenRequestError) {
58
+ handleUnauthenticated();
59
+ } else {
60
+ console.error(`Failed to fetch repositories: ${stringify(response.value)}`);
61
+ process.exitCode = 1;
62
+ }
63
+ return;
64
+ }
65
+
66
+ const repos = response.value.repositories;
67
+
68
+ if (json) {
69
+ const output = await Promise.all(
70
+ repos.map(async (repo) => ({
71
+ domain: repo.domain,
72
+ name: repo.name || null,
73
+ role: repo.role,
74
+ url: (await getRepoUrl(repo.domain)).toString(),
75
+ })),
76
+ );
77
+ console.info(stringify(output));
78
+ return;
79
+ }
80
+
81
+ if (repos.length === 0) {
82
+ console.info("No repositories found.");
83
+ return;
84
+ }
85
+
86
+ for (const repo of repos) {
87
+ const name = repo.name || "(no name)";
88
+ console.info(`${repo.domain} ${name} ${repo.role}`);
89
+ }
90
+ }
91
+
92
+ async function fetchProfile(): ReturnType<typeof request<v.InferOutput<typeof ProfileSchema>>> {
93
+ const url = new URL("profile", await getUserServiceUrl());
94
+ return await request(url, { schema: ProfileSchema });
95
+ }
96
+
97
+ function handleUnauthenticated() {
98
+ console.error("Not logged in. Run `prismic login` first.");
99
+ process.exitCode = 1;
100
+ }
@@ -0,0 +1,100 @@
1
+ import { parseArgs } from "node:util";
2
+
3
+ import { isAuthenticated } from "./lib/auth";
4
+ import { safeGetRepositoryFromConfig } from "./lib/config";
5
+ import { stringify } from "./lib/json";
6
+ import { ForbiddenRequestError, request } from "./lib/request";
7
+ import { getRepoUrl } from "./lib/url";
8
+
9
+ const VALID_LEVELS = ["private", "public", "open"] as const;
10
+
11
+ const HELP = `
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
+ USAGE
18
+ prismic repo set-access <level> [flags]
19
+
20
+ ARGUMENTS
21
+ <level> The access level to set (private, public, open)
22
+
23
+ FLAGS
24
+ -r, --repo string Repository domain
25
+ -h, --help Show help for command
26
+
27
+ LEARN MORE
28
+ Use \`prismic <command> <subcommand> --help\` for more information about a command.
29
+ `.trim();
30
+
31
+ export async function repoSetAccess(): Promise<void> {
32
+ const {
33
+ values: { help, repo = await safeGetRepositoryFromConfig() },
34
+ positionals: [level],
35
+ } = parseArgs({
36
+ args: process.argv.slice(4), // skip: node, script, "repo", "set-access"
37
+ options: {
38
+ repo: { type: "string", short: "r" },
39
+ help: { type: "boolean", short: "h" },
40
+ },
41
+ allowPositionals: true,
42
+ });
43
+
44
+ if (help) {
45
+ console.info(HELP);
46
+ return;
47
+ }
48
+
49
+ if (!level) {
50
+ console.error("Missing required argument: <level>");
51
+ process.exitCode = 1;
52
+ return;
53
+ }
54
+
55
+ if (!VALID_LEVELS.includes(level as (typeof VALID_LEVELS)[number])) {
56
+ console.error(`Invalid access level: ${level}. Must be one of: ${VALID_LEVELS.join(", ")}`);
57
+ process.exitCode = 1;
58
+ return;
59
+ }
60
+
61
+ if (!repo) {
62
+ console.error("Missing prismic.config.json or --repo option");
63
+ process.exitCode = 1;
64
+ return;
65
+ }
66
+
67
+ const authenticated = await isAuthenticated();
68
+ if (!authenticated) {
69
+ handleUnauthenticated();
70
+ return;
71
+ }
72
+
73
+ const response = await setRepositoryAccess(repo, level);
74
+ if (!response.ok) {
75
+ if (response.error instanceof ForbiddenRequestError) {
76
+ handleUnauthenticated();
77
+ } else {
78
+ console.error(`Failed to set repository access: ${stringify(response.value)}`);
79
+ process.exitCode = 1;
80
+ }
81
+ return;
82
+ }
83
+
84
+ console.info(`Repository access set to: ${level}`);
85
+ }
86
+
87
+ async function setRepositoryAccess(domain: string, level: string) {
88
+ const repoUrl = await getRepoUrl(domain);
89
+ const url = new URL("settings/security/apiaccess", repoUrl);
90
+
91
+ return await request(url, {
92
+ method: "POST",
93
+ body: { api_access: level },
94
+ });
95
+ }
96
+
97
+ function handleUnauthenticated() {
98
+ console.error("Not logged in. Run `prismic login` first.");
99
+ process.exitCode = 1;
100
+ }
@@ -0,0 +1,102 @@
1
+ import { parseArgs } from "node:util";
2
+ import * as v from "valibot";
3
+
4
+ import { isAuthenticated } from "./lib/auth";
5
+ import { safeGetRepositoryFromConfig } from "./lib/config";
6
+ import { stringify } from "./lib/json";
7
+ import { ForbiddenRequestError, request } from "./lib/request";
8
+ import { getRepoUrl } from "./lib/url";
9
+
10
+ const HELP = `
11
+ Set the display name of a Prismic repository.
12
+
13
+ By default, this command reads the repository from prismic.config.json at the
14
+ project root.
15
+
16
+ USAGE
17
+ prismic repo set-name <name> [flags]
18
+
19
+ ARGUMENTS
20
+ <name> The new display name for the repository
21
+
22
+ FLAGS
23
+ -r, --repo string Repository domain
24
+ -h, --help Show help for command
25
+
26
+ LEARN MORE
27
+ Use \`prismic <command> <subcommand> --help\` for more information about a command.
28
+ `.trim();
29
+
30
+ export async function repoSetName(): Promise<void> {
31
+ const {
32
+ values: { help, repo = await safeGetRepositoryFromConfig() },
33
+ positionals: [displayName],
34
+ } = parseArgs({
35
+ args: process.argv.slice(4), // skip: node, script, "repo", "set-name"
36
+ options: {
37
+ repo: { type: "string", short: "r" },
38
+ help: { type: "boolean", short: "h" },
39
+ },
40
+ allowPositionals: true,
41
+ });
42
+
43
+ if (help) {
44
+ console.info(HELP);
45
+ return;
46
+ }
47
+
48
+ if (!displayName) {
49
+ console.error("Missing required argument: <name>");
50
+ process.exitCode = 1;
51
+ return;
52
+ }
53
+
54
+ if (!repo) {
55
+ console.error("Missing prismic.config.json or --repo option");
56
+ process.exitCode = 1;
57
+ return;
58
+ }
59
+
60
+ const authenticated = await isAuthenticated();
61
+ if (!authenticated) {
62
+ handleUnauthenticated();
63
+ return;
64
+ }
65
+
66
+ const response = await setRepositoryName(repo, displayName);
67
+ if (!response.ok) {
68
+ if (response.error instanceof ForbiddenRequestError) {
69
+ handleUnauthenticated();
70
+ } else if (v.isValiError(response.error)) {
71
+ console.error(
72
+ `Failed to set repository name: Invalid response: ${stringify(response.error.issues)}`,
73
+ );
74
+ process.exitCode = 1;
75
+ } else {
76
+ console.error(`Failed to set repository name: ${stringify(response.value)}`);
77
+ process.exitCode = 1;
78
+ }
79
+ return;
80
+ }
81
+
82
+ console.info(`Repository name set to: ${response.value.repository.name}`);
83
+ }
84
+
85
+ async function setRepositoryName(domain: string, displayName: string) {
86
+ const repoUrl = await getRepoUrl(domain);
87
+ const url = new URL("app/settings/repository", repoUrl);
88
+
89
+ const formData = new FormData();
90
+ formData.set("displayname", displayName);
91
+
92
+ return await request(url, {
93
+ method: "POST",
94
+ body: formData,
95
+ schema: v.object({ repository: v.object({ name: v.string() }) }),
96
+ });
97
+ }
98
+
99
+ function handleUnauthenticated() {
100
+ console.error("Not logged in. Run `prismic login` first.");
101
+ process.exitCode = 1;
102
+ }
@@ -0,0 +1,113 @@
1
+ import { exec } from "node:child_process";
2
+ import { parseArgs } from "node:util";
3
+ import * as v from "valibot";
4
+
5
+ import { isAuthenticated } from "./lib/auth";
6
+ import { safeGetRepositoryFromConfig } from "./lib/config";
7
+ import { stringify } from "./lib/json";
8
+ import { ForbiddenRequestError, request } from "./lib/request";
9
+ import { getRepoUrl, getUserServiceUrl } from "./lib/url";
10
+
11
+ const HELP = `
12
+ View a Prismic repository.
13
+
14
+ By default, this command reads the repository from prismic.config.json at the
15
+ project root.
16
+
17
+ USAGE
18
+ prismic repo view [flags]
19
+
20
+ FLAGS
21
+ -w, --web Open repository in browser
22
+ -r, --repo string Repository domain
23
+ -h, --help Show help for command
24
+
25
+ LEARN MORE
26
+ Use \`prismic <command> <subcommand> --help\` for more information about a command.
27
+ `.trim();
28
+
29
+ const ProfileSchema = v.object({
30
+ repositories: v.array(
31
+ v.object({
32
+ domain: v.string(),
33
+ name: v.optional(v.string()),
34
+ }),
35
+ ),
36
+ });
37
+
38
+ export async function repoView(): Promise<void> {
39
+ const {
40
+ values: { help, repo = await safeGetRepositoryFromConfig(), web },
41
+ } = parseArgs({
42
+ args: process.argv.slice(4), // skip: node, script, "repo", "view"
43
+ options: {
44
+ web: { type: "boolean", short: "w" },
45
+ repo: { type: "string", short: "r" },
46
+ help: { type: "boolean", short: "h" },
47
+ },
48
+ });
49
+
50
+ if (help) {
51
+ console.info(HELP);
52
+ return;
53
+ }
54
+
55
+ if (!repo) {
56
+ console.error("Missing prismic.config.json or --repo option");
57
+ process.exitCode = 1;
58
+ return;
59
+ }
60
+
61
+ const repoUrl = await getRepoUrl(repo);
62
+
63
+ if (web) {
64
+ openInBrowser(repoUrl.toString());
65
+ console.info(`Opening ${repoUrl}`);
66
+ return;
67
+ }
68
+
69
+ const authenticated = await isAuthenticated();
70
+ if (!authenticated) {
71
+ handleUnauthenticated();
72
+ return;
73
+ }
74
+
75
+ const response = await fetchProfile();
76
+ if (!response.ok) {
77
+ if (response.error instanceof ForbiddenRequestError) {
78
+ handleUnauthenticated();
79
+ } else {
80
+ console.error(`Failed to fetch repository info: ${stringify(response.value)}`);
81
+ process.exitCode = 1;
82
+ }
83
+ return;
84
+ }
85
+
86
+ const repoData = response.value.repositories.find((r) => r.domain === repo);
87
+ if (!repoData) {
88
+ console.error(`Repository not found: ${repo}`);
89
+ process.exitCode = 1;
90
+ return;
91
+ }
92
+
93
+ const name = repoData.name || "(no name)";
94
+ console.info(`Name: ${name}`);
95
+ console.info(`URL: ${repoUrl}`);
96
+ }
97
+
98
+ async function fetchProfile(): ReturnType<typeof request<v.InferOutput<typeof ProfileSchema>>> {
99
+ const url = new URL("profile", await getUserServiceUrl());
100
+ return await request(url, { schema: ProfileSchema });
101
+ }
102
+
103
+ function openInBrowser(url: string): void {
104
+ const cmd =
105
+ process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
106
+
107
+ exec(`${cmd} "${url}"`);
108
+ }
109
+
110
+ function handleUnauthenticated() {
111
+ console.error("Not logged in. Run `prismic login` first.");
112
+ process.exitCode = 1;
113
+ }
package/src/repo.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { parseArgs } from "node:util";
2
+
3
+ import { repoCreate } from "./repo-create";
4
+ import { repoGetAccess } from "./repo-get-access";
5
+ import { repoList } from "./repo-list";
6
+ import { repoSetAccess } from "./repo-set-access";
7
+ import { repoSetName } from "./repo-set-name";
8
+ import { repoView } from "./repo-view";
9
+
10
+ const HELP = `
11
+ Manage Prismic repositories.
12
+
13
+ USAGE
14
+ prismic repo <command> [flags]
15
+
16
+ COMMANDS
17
+ create Create a new Prismic repository
18
+ list List all repositories
19
+ view View repository details
20
+ get-access Get Content API access level
21
+ set-access Set Content API access level
22
+ set-name Set repository display name
23
+
24
+ FLAGS
25
+ -h, --help Show help for command
26
+
27
+ LEARN MORE
28
+ Use \`prismic repo <command> --help\` for more information about a command.
29
+ `.trim();
30
+
31
+ export async function repo(): Promise<void> {
32
+ const {
33
+ positionals: [subcommand],
34
+ } = parseArgs({
35
+ args: process.argv.slice(3), // skip: node, script, "repo"
36
+ options: {
37
+ help: { type: "boolean", short: "h" },
38
+ },
39
+ allowPositionals: true,
40
+ strict: false,
41
+ });
42
+
43
+ switch (subcommand) {
44
+ case "create":
45
+ await repoCreate();
46
+ break;
47
+ case "list":
48
+ await repoList();
49
+ break;
50
+ case "view":
51
+ await repoView();
52
+ break;
53
+ case "get-access":
54
+ await repoGetAccess();
55
+ break;
56
+ case "set-access":
57
+ await repoSetAccess();
58
+ break;
59
+ case "set-name":
60
+ await repoSetName();
61
+ break;
62
+ default: {
63
+ if (subcommand) {
64
+ console.error(`Unknown repo subcommand: ${subcommand}\n`);
65
+ process.exitCode = 1;
66
+ }
67
+ console.info(HELP);
68
+ }
69
+ }
70
+ }