@angeloashmore/prismic-cli-poc 0.0.0-canary.5fed593 → 0.0.0-canary.63deeeb

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 (65) hide show
  1. package/dist/index.mjs +274 -412
  2. package/package.json +1 -1
  3. package/src/custom-type-add-field-boolean.ts +9 -12
  4. package/src/custom-type-add-field-color.ts +10 -12
  5. package/src/custom-type-add-field-date.ts +10 -12
  6. package/src/custom-type-add-field-embed.ts +10 -12
  7. package/src/custom-type-add-field-geo-point.ts +10 -12
  8. package/src/custom-type-add-field-image.ts +10 -12
  9. package/src/custom-type-add-field-key-text.ts +10 -12
  10. package/src/custom-type-add-field-link.ts +9 -12
  11. package/src/custom-type-add-field-number.ts +10 -12
  12. package/src/custom-type-add-field-rich-text.ts +9 -12
  13. package/src/custom-type-add-field-select.ts +9 -12
  14. package/src/custom-type-add-field-timestamp.ts +10 -12
  15. package/src/custom-type-add-field-uid.ts +10 -12
  16. package/src/custom-type-connect-slice.ts +6 -12
  17. package/src/custom-type-create.ts +17 -13
  18. package/src/custom-type-disconnect-slice.ts +6 -12
  19. package/src/custom-type-remove-field.ts +6 -12
  20. package/src/custom-type-remove.ts +6 -12
  21. package/src/custom-type-set-name.ts +6 -12
  22. package/src/docs.ts +149 -0
  23. package/src/index.ts +10 -0
  24. package/src/lib/auth.ts +24 -1
  25. package/src/lib/framework.ts +143 -0
  26. package/src/page-type-add-field-boolean.ts +9 -12
  27. package/src/page-type-add-field-color.ts +10 -12
  28. package/src/page-type-add-field-date.ts +10 -12
  29. package/src/page-type-add-field-embed.ts +10 -12
  30. package/src/page-type-add-field-geo-point.ts +10 -12
  31. package/src/page-type-add-field-image.ts +10 -12
  32. package/src/page-type-add-field-key-text.ts +10 -12
  33. package/src/page-type-add-field-link.ts +9 -12
  34. package/src/page-type-add-field-number.ts +10 -12
  35. package/src/page-type-add-field-rich-text.ts +9 -12
  36. package/src/page-type-add-field-select.ts +9 -12
  37. package/src/page-type-add-field-timestamp.ts +10 -12
  38. package/src/page-type-add-field-uid.ts +10 -12
  39. package/src/page-type-connect-slice.ts +6 -12
  40. package/src/page-type-create.ts +41 -14
  41. package/src/page-type-disconnect-slice.ts +6 -12
  42. package/src/page-type-remove-field.ts +6 -12
  43. package/src/page-type-remove.ts +6 -12
  44. package/src/page-type-set-name.ts +6 -12
  45. package/src/page-type-set-repeatable.ts +6 -12
  46. package/src/pull.ts +1 -6
  47. package/src/slice-add-field-boolean.ts +9 -12
  48. package/src/slice-add-field-color.ts +10 -12
  49. package/src/slice-add-field-date.ts +10 -12
  50. package/src/slice-add-field-embed.ts +10 -12
  51. package/src/slice-add-field-geo-point.ts +10 -12
  52. package/src/slice-add-field-image.ts +10 -12
  53. package/src/slice-add-field-key-text.ts +10 -12
  54. package/src/slice-add-field-link.ts +9 -12
  55. package/src/slice-add-field-number.ts +10 -12
  56. package/src/slice-add-field-rich-text.ts +9 -12
  57. package/src/slice-add-field-select.ts +9 -12
  58. package/src/slice-add-field-timestamp.ts +10 -12
  59. package/src/slice-add-variation.ts +6 -12
  60. package/src/slice-create.ts +9 -12
  61. package/src/slice-remove-field.ts +6 -12
  62. package/src/slice-remove-variation.ts +6 -12
  63. package/src/slice-remove.ts +6 -12
  64. package/src/slice-rename.ts +6 -12
  65. package/src/status.ts +770 -0
@@ -19,14 +19,11 @@ ARGUMENTS
19
19
  type-id Custom type identifier (required)
20
20
  field-id Field identifier (required)
21
21
 
22
- Types are generated by default after changes. Use --no-types to skip.
23
-
24
22
  FLAGS
25
23
  -t, --tab string Target tab (default: first existing tab, or "Main")
26
24
  -l, --label string Display label for the field (inferred from field-id if omitted)
27
25
  -p, --placeholder string Placeholder text
28
26
  --types string Output file for generated types (default: "prismicio-types.d.ts")
29
- --no-types Skip type generation
30
27
  -h, --help Show help for command
31
28
 
32
29
  EXAMPLES
@@ -46,7 +43,7 @@ const CustomTypeSchema = v.object({
46
43
 
47
44
  export async function customTypeAddFieldUid(): Promise<void> {
48
45
  const {
49
- values: { help, tab, label, placeholder, types, "no-types": noTypes },
46
+ values: { help, tab, label, placeholder, types },
50
47
  positionals: [typeId, fieldId],
51
48
  } = parseArgs({
52
49
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "uid"
@@ -55,7 +52,6 @@ export async function customTypeAddFieldUid(): Promise<void> {
55
52
  label: { type: "string", short: "l" },
56
53
  placeholder: { type: "string", short: "p" },
57
54
  types: { type: "string" },
58
- "no-types": { type: "boolean" },
59
55
  help: { type: "boolean", short: "h" },
60
56
  },
61
57
  allowPositionals: true,
@@ -162,12 +158,14 @@ export async function customTypeAddFieldUid(): Promise<void> {
162
158
 
163
159
  console.info(`Added field "${fieldId}" (UID) to "${targetTab}" tab in ${typeId}`);
164
160
 
165
- if (!noTypes) {
166
- try {
167
- await buildTypes({ output: types });
168
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
169
- } catch (error) {
170
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
171
- }
161
+ try {
162
+ await buildTypes({ output: types });
163
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
164
+ } catch (error) {
165
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
172
166
  }
167
+
168
+ console.info();
169
+ console.info("Next: Add more fields with `prismic custom-type add-field`");
170
+ console.info(" Run `prismic status` when done to find next steps");
173
171
  }
@@ -23,12 +23,9 @@ ARGUMENTS
23
23
  type-id Custom type identifier (required)
24
24
  slice-id Slice identifier (required)
25
25
 
26
- Types are generated by default after changes. Use --no-types to skip.
27
-
28
26
  FLAGS
29
27
  -z, --slice-zone string Target slice zone field ID (default: "slices")
30
28
  --types string Output file for generated types (default: "prismicio-types.d.ts")
31
- --no-types Skip type generation
32
29
  -h, --help Show help for command
33
30
 
34
31
  EXAMPLES
@@ -48,14 +45,13 @@ const CustomTypeSchema = v.object({
48
45
 
49
46
  export async function customTypeConnectSlice(): Promise<void> {
50
47
  const {
51
- values: { help, "slice-zone": sliceZoneId, types, "no-types": noTypes },
48
+ values: { help, "slice-zone": sliceZoneId, types },
52
49
  positionals: [typeId, sliceId],
53
50
  } = parseArgs({
54
51
  args: process.argv.slice(4), // skip: node, script, "custom-type", "connect-slice"
55
52
  options: {
56
53
  "slice-zone": { type: "string", short: "z" },
57
54
  types: { type: "string" },
58
- "no-types": { type: "boolean" },
59
55
  help: { type: "boolean", short: "h" },
60
56
  },
61
57
  allowPositionals: true,
@@ -209,12 +205,10 @@ export async function customTypeConnectSlice(): Promise<void> {
209
205
 
210
206
  console.info(`Connected slice "${sliceId}" to slice zone "${sliceZoneFieldId}" in ${typeId}`);
211
207
 
212
- if (!noTypes) {
213
- try {
214
- await buildTypes({ output: types });
215
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
216
- } catch (error) {
217
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
218
- }
208
+ try {
209
+ await buildTypes({ output: types });
210
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
211
+ } catch (error) {
212
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
219
213
  }
220
214
  }
@@ -16,13 +16,10 @@ USAGE
16
16
  ARGUMENTS
17
17
  id Custom type identifier (required)
18
18
 
19
- Types are generated by default after changes. Use --no-types to skip.
20
-
21
19
  FLAGS
22
20
  -n, --name string Display name for the custom type
23
21
  --single Create as a singleton (non-repeatable) type
24
22
  --types string Output file for generated types (default: "prismicio-types.d.ts")
25
- --no-types Skip type generation
26
23
  -h, --help Show help for command
27
24
 
28
25
  LEARN MORE
@@ -31,7 +28,7 @@ LEARN MORE
31
28
 
32
29
  export async function customTypeCreate(): Promise<void> {
33
30
  const {
34
- values: { help, name, single, types, "no-types": noTypes },
31
+ values: { help, name, single, types },
35
32
  positionals: [id],
36
33
  } = parseArgs({
37
34
  args: process.argv.slice(4), // skip: node, script, "custom-type", "create"
@@ -39,7 +36,6 @@ export async function customTypeCreate(): Promise<void> {
39
36
  name: { type: "string", short: "n" },
40
37
  single: { type: "boolean" },
41
38
  types: { type: "string" },
42
- "no-types": { type: "boolean" },
43
39
  help: { type: "boolean", short: "h" },
44
40
  },
45
41
  allowPositionals: true,
@@ -63,7 +59,14 @@ export async function customTypeCreate(): Promise<void> {
63
59
  status: true,
64
60
  format: "custom",
65
61
  json: {
66
- Main: {},
62
+ Main: single
63
+ ? {}
64
+ : {
65
+ uid: {
66
+ type: "UID",
67
+ config: { label: "UID", placeholder: "" },
68
+ },
69
+ },
67
70
  },
68
71
  } satisfies CustomType;
69
72
 
@@ -93,14 +96,15 @@ export async function customTypeCreate(): Promise<void> {
93
96
 
94
97
  console.info(`Created custom type at ${modelPath.href}`);
95
98
 
96
- if (!noTypes) {
97
- try {
98
- await buildTypes({ output: types });
99
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
100
- } catch (error) {
101
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
102
- }
99
+ try {
100
+ await buildTypes({ output: types });
101
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
102
+ } catch (error) {
103
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
103
104
  }
105
+
106
+ console.info();
107
+ console.info("Next: Add fields with `prismic custom-type add-field`");
104
108
  }
105
109
 
106
110
  export function pascalCase(input: string): string {
@@ -18,12 +18,9 @@ ARGUMENTS
18
18
  type-id Custom type identifier (required)
19
19
  slice-id Slice identifier (required)
20
20
 
21
- Types are generated by default after changes. Use --no-types to skip.
22
-
23
21
  FLAGS
24
22
  -z, --slice-zone string Target slice zone field ID (default: "slices")
25
23
  --types string Output file for generated types (default: "prismicio-types.d.ts")
26
- --no-types Skip type generation
27
24
  -h, --help Show help for command
28
25
 
29
26
  EXAMPLES
@@ -43,14 +40,13 @@ const CustomTypeSchema = v.object({
43
40
 
44
41
  export async function customTypeDisconnectSlice(): Promise<void> {
45
42
  const {
46
- values: { help, "slice-zone": sliceZoneId, types, "no-types": noTypes },
43
+ values: { help, "slice-zone": sliceZoneId, types },
47
44
  positionals: [typeId, sliceId],
48
45
  } = parseArgs({
49
46
  args: process.argv.slice(4), // skip: node, script, "custom-type", "disconnect-slice"
50
47
  options: {
51
48
  "slice-zone": { type: "string", short: "z" },
52
49
  types: { type: "string" },
53
- "no-types": { type: "boolean" },
54
50
  help: { type: "boolean", short: "h" },
55
51
  },
56
52
  allowPositionals: true,
@@ -166,12 +162,10 @@ export async function customTypeDisconnectSlice(): Promise<void> {
166
162
  `Disconnected slice "${sliceId}" from slice zone "${sliceZoneFieldId}" in ${typeId}`,
167
163
  );
168
164
 
169
- if (!noTypes) {
170
- try {
171
- await buildTypes({ output: types });
172
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
173
- } catch (error) {
174
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
175
- }
165
+ try {
166
+ await buildTypes({ output: types });
167
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
168
+ } catch (error) {
169
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
176
170
  }
177
171
  }
@@ -18,12 +18,9 @@ ARGUMENTS
18
18
  type-id Custom type identifier (required)
19
19
  field-id Field identifier (required)
20
20
 
21
- Types are generated by default after changes. Use --no-types to skip.
22
-
23
21
  FLAGS
24
22
  --tab string Specific tab (searches all tabs if not specified)
25
23
  --types string Output file for generated types (default: "prismicio-types.d.ts")
26
- --no-types Skip type generation
27
24
  -h, --help Show help for command
28
25
 
29
26
  EXAMPLES
@@ -42,14 +39,13 @@ const CustomTypeSchema = v.object({
42
39
 
43
40
  export async function customTypeRemoveField(): Promise<void> {
44
41
  const {
45
- values: { help, tab, types, "no-types": noTypes },
42
+ values: { help, tab, types },
46
43
  positionals: [typeId, fieldId],
47
44
  } = parseArgs({
48
45
  args: process.argv.slice(4), // skip: node, script, "custom-type", "remove-field"
49
46
  options: {
50
47
  tab: { type: "string" },
51
48
  types: { type: "string" },
52
- "no-types": { type: "boolean" },
53
49
  help: { type: "boolean", short: "h" },
54
50
  },
55
51
  allowPositionals: true,
@@ -166,12 +162,10 @@ export async function customTypeRemoveField(): Promise<void> {
166
162
 
167
163
  console.info(`Removed field "${fieldId}" from tab "${foundTab}" in custom type "${typeId}"`);
168
164
 
169
- if (!noTypes) {
170
- try {
171
- await buildTypes({ output: types });
172
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
173
- } catch (error) {
174
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
175
- }
165
+ try {
166
+ await buildTypes({ output: types });
167
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
168
+ } catch (error) {
169
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
176
170
  }
177
171
  }
@@ -16,12 +16,9 @@ USAGE
16
16
  ARGUMENTS
17
17
  type-id Custom type identifier (required)
18
18
 
19
- Types are generated by default after changes. Use --no-types to skip.
20
-
21
19
  FLAGS
22
20
  -y Confirm removal
23
21
  --types string Output file for generated types (default: "prismicio-types.d.ts")
24
- --no-types Skip type generation
25
22
  -h, --help Show help for command
26
23
 
27
24
  EXAMPLES
@@ -40,14 +37,13 @@ const CustomTypeSchema = v.object({
40
37
 
41
38
  export async function customTypeRemove(): Promise<void> {
42
39
  const {
43
- values: { help, y, types, "no-types": noTypes },
40
+ values: { help, y, types },
44
41
  positionals: [typeId],
45
42
  } = parseArgs({
46
43
  args: process.argv.slice(4), // skip: node, script, "custom-type", "remove"
47
44
  options: {
48
45
  y: { type: "boolean", short: "y" },
49
46
  types: { type: "string" },
50
- "no-types": { type: "boolean" },
51
47
  help: { type: "boolean", short: "h" },
52
48
  },
53
49
  allowPositionals: true,
@@ -133,12 +129,10 @@ export async function customTypeRemove(): Promise<void> {
133
129
 
134
130
  console.info(`Removed custom type "${typeId}"`);
135
131
 
136
- if (!noTypes) {
137
- try {
138
- await buildTypes({ output: types });
139
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
140
- } catch (error) {
141
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
142
- }
132
+ try {
133
+ await buildTypes({ output: types });
134
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
135
+ } catch (error) {
136
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
143
137
  }
144
138
  }
@@ -18,11 +18,8 @@ ARGUMENTS
18
18
  type-id Custom type identifier (required)
19
19
  new-name New display name (required)
20
20
 
21
- Types are generated by default after changes. Use --no-types to skip.
22
-
23
21
  FLAGS
24
22
  --types string Output file for generated types (default: "prismicio-types.d.ts")
25
- --no-types Skip type generation
26
23
  -h, --help Show help for command
27
24
 
28
25
  EXAMPLES
@@ -41,13 +38,12 @@ const CustomTypeSchema = v.object({
41
38
 
42
39
  export async function customTypeSetName(): Promise<void> {
43
40
  const {
44
- values: { help, types, "no-types": noTypes },
41
+ values: { help, types },
45
42
  positionals: [typeId, newName],
46
43
  } = parseArgs({
47
44
  args: process.argv.slice(4), // skip: node, script, "custom-type", "set-name"
48
45
  options: {
49
46
  types: { type: "string" },
50
- "no-types": { type: "boolean" },
51
47
  help: { type: "boolean", short: "h" },
52
48
  },
53
49
  allowPositionals: true,
@@ -133,12 +129,10 @@ export async function customTypeSetName(): Promise<void> {
133
129
 
134
130
  console.info(`Renamed custom type "${typeId}" to "${newName}"`);
135
131
 
136
- if (!noTypes) {
137
- try {
138
- await buildTypes({ output: types });
139
- console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
140
- } catch (error) {
141
- console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
142
- }
132
+ try {
133
+ await buildTypes({ output: types });
134
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
135
+ } catch (error) {
136
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
143
137
  }
144
138
  }
package/src/docs.ts ADDED
@@ -0,0 +1,149 @@
1
+ import { parseArgs } from "node:util";
2
+
3
+ const HELP = `
4
+ Fetch and display documentation from Prismic's docs site.
5
+
6
+ USAGE
7
+ prismic docs <path> [flags]
8
+
9
+ ARGUMENTS
10
+ path Documentation path with optional anchor (e.g., "nextjs" or "nextjs#set-up-a-prismic-client")
11
+
12
+ FLAGS
13
+ -h, --help Show help for command
14
+
15
+ EXAMPLES
16
+ prismic docs nextjs
17
+ prismic docs nextjs#set-up-a-prismic-client
18
+
19
+ LEARN MORE
20
+ Visit https://prismic.io/docs for the full documentation.
21
+ `.trim();
22
+
23
+ function parsePathAndAnchor(input: string): { path: string; anchor?: string } {
24
+ const hashIndex = input.indexOf("#");
25
+ if (hashIndex === -1) {
26
+ return { path: input };
27
+ }
28
+ return {
29
+ path: input.slice(0, hashIndex),
30
+ anchor: input.slice(hashIndex + 1),
31
+ };
32
+ }
33
+
34
+ async function fetchMarkdown(
35
+ url: string,
36
+ ): Promise<{ ok: true; content: string } | { ok: false; error: string }> {
37
+ try {
38
+ const response = await fetch(url);
39
+ if (response.status === 404) {
40
+ return { ok: false, error: `Documentation not found: ${url}` };
41
+ }
42
+ if (!response.ok) {
43
+ return {
44
+ ok: false,
45
+ error: `Failed to fetch documentation: ${response.status}`,
46
+ };
47
+ }
48
+ const content = await response.text();
49
+ return { ok: true, content };
50
+ } catch (error) {
51
+ const message = error instanceof Error ? error.message : String(error);
52
+ return { ok: false, error: `Network error: ${message}` };
53
+ }
54
+ }
55
+
56
+ function anchorToHeadingPattern(anchor: string): RegExp {
57
+ // Convert kebab-case anchor to a pattern that matches the heading text
58
+ // Each hyphen/space becomes a flexible match for hyphens or spaces
59
+ const pattern = anchor
60
+ .split("-")
61
+ .map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
62
+ .join("[\\s-]+");
63
+ return new RegExp(`^(#{1,6})\\s+${pattern}\\s*$`, "im");
64
+ }
65
+
66
+ function extractSection(
67
+ markdown: string,
68
+ anchor: string,
69
+ ): { ok: true; content: string } | { ok: false; error: string } {
70
+ const lines = markdown.split("\n");
71
+ const headingPattern = anchorToHeadingPattern(anchor);
72
+
73
+ let startIndex = -1;
74
+ let headingLevel = 0;
75
+
76
+ // Find the matching heading
77
+ for (let i = 0; i < lines.length; i++) {
78
+ const match = lines[i].match(headingPattern);
79
+ if (match) {
80
+ startIndex = i;
81
+ headingLevel = match[1].length;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if (startIndex === -1) {
87
+ return { ok: false, error: `Anchor not found: #${anchor}` };
88
+ }
89
+
90
+ // Find the end of this section (next heading of equal or lower level number)
91
+ let endIndex = lines.length;
92
+ for (let i = startIndex + 1; i < lines.length; i++) {
93
+ const headingMatch = lines[i].match(/^(#{1,6})\s/);
94
+ if (headingMatch && headingMatch[1].length <= headingLevel) {
95
+ endIndex = i;
96
+ break;
97
+ }
98
+ }
99
+
100
+ const content = lines.slice(startIndex, endIndex).join("\n").trim();
101
+ return { ok: true, content };
102
+ }
103
+
104
+ export async function docs(): Promise<void> {
105
+ const {
106
+ positionals: [pathArg],
107
+ values: { help },
108
+ } = parseArgs({
109
+ args: process.argv.slice(3),
110
+ options: {
111
+ help: { type: "boolean", short: "h" },
112
+ },
113
+ allowPositionals: true,
114
+ });
115
+
116
+ if (help) {
117
+ console.info(HELP);
118
+ return;
119
+ }
120
+
121
+ if (!pathArg) {
122
+ console.info(HELP);
123
+ return;
124
+ }
125
+
126
+ const { path, anchor } = parsePathAndAnchor(pathArg);
127
+ const url = `https://prismic.io/docs/${path}.md`;
128
+
129
+ const fetchResult = await fetchMarkdown(url);
130
+ if (!fetchResult.ok) {
131
+ console.error(fetchResult.error);
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+
136
+ let output = fetchResult.content;
137
+
138
+ if (anchor) {
139
+ const extractResult = extractSection(output, anchor);
140
+ if (!extractResult.ok) {
141
+ console.error(extractResult.error);
142
+ process.exitCode = 1;
143
+ return;
144
+ }
145
+ output = extractResult.content;
146
+ }
147
+
148
+ console.info(output);
149
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { parseArgs } from "node:util";
5
5
  import packageJson from "../package.json" with { type: "json" };
6
6
  import { codegen } from "./codegen";
7
7
  import { customType } from "./custom-type";
8
+ import { docs } from "./docs";
8
9
  import { init } from "./init";
9
10
  import { locale } from "./locale";
10
11
  import { login } from "./login";
@@ -15,6 +16,7 @@ import { pull } from "./pull";
15
16
  import { push } from "./push";
16
17
  import { repo } from "./repo";
17
18
  import { slice } from "./slice";
19
+ import { status } from "./status";
18
20
  import { token } from "./token";
19
21
  import { webhook } from "./webhook";
20
22
  import { whoami } from "./whoami";
@@ -30,6 +32,7 @@ COMMANDS
30
32
  login Log in to Prismic
31
33
  logout Log out of Prismic
32
34
  whoami Show the currently logged in user
35
+ status Show the status of the current project
33
36
  repo Manage Prismic repositories
34
37
  locale Manage locales in a repository
35
38
  page-type Manage page types in a repository
@@ -38,6 +41,7 @@ COMMANDS
38
41
  pull Pull types and slices from Prismic
39
42
  push Push types and slices to Prismic
40
43
  codegen Generate code from Prismic models
44
+ docs Fetch documentation from Prismic
41
45
  preview Manage preview configurations
42
46
  token Manage API tokens in a repository
43
47
  webhook Manage webhooks in a repository
@@ -78,6 +82,9 @@ if (version) {
78
82
  case "whoami":
79
83
  await whoami();
80
84
  break;
85
+ case "status":
86
+ await status();
87
+ break;
81
88
  case "repo":
82
89
  await repo();
83
90
  break;
@@ -102,6 +109,9 @@ if (version) {
102
109
  case "codegen":
103
110
  await codegen();
104
111
  break;
112
+ case "docs":
113
+ await docs();
114
+ break;
105
115
  case "preview":
106
116
  await preview();
107
117
  break;
package/src/lib/auth.ts CHANGED
@@ -19,7 +19,30 @@ export async function saveToken(token: string, options?: { host?: string }): Pro
19
19
 
20
20
  export async function isAuthenticated(): Promise<boolean> {
21
21
  const token = await readToken();
22
- return Boolean(token);
22
+ if (!token) return false;
23
+
24
+ // Verify token is still valid by calling the profile endpoint
25
+ try {
26
+ const host = await readHost();
27
+ host.hostname = `user-service.${host.hostname}`;
28
+ const url = new URL("profile", host);
29
+
30
+ const response = await fetch(url, {
31
+ headers: {
32
+ Accept: "application/json",
33
+ Cookie: `SESSION=fake_session; prismic-auth=${token}`,
34
+ },
35
+ });
36
+
37
+ if (!response.ok) {
38
+ await removeToken();
39
+ return false;
40
+ }
41
+
42
+ return true;
43
+ } catch {
44
+ return false;
45
+ }
23
46
  }
24
47
 
25
48
  export async function readToken(): Promise<string | undefined> {