prismic 0.0.0-pr.28.59bf330

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 (158) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +69 -0
  3. package/dist/builders-hKD4IrLX-DsO7BUQw.mjs +97 -0
  4. package/dist/dist-B11B2hHn.mjs +1 -0
  5. package/dist/dist-DT8CtumB.mjs +1 -0
  6. package/dist/framework-CfjEoVk0.mjs +17 -0
  7. package/dist/index.mjs +2537 -0
  8. package/dist/nextjs-9z7YrSnS.mjs +312 -0
  9. package/dist/nuxt-KoJ61G2q.mjs +59 -0
  10. package/dist/sveltekit-DjXKCG78.mjs +226 -0
  11. package/package.json +58 -0
  12. package/src/codegen-types.ts +82 -0
  13. package/src/codegen.ts +45 -0
  14. package/src/custom-type-add-field-boolean.ts +185 -0
  15. package/src/custom-type-add-field-color.ts +168 -0
  16. package/src/custom-type-add-field-date.ts +171 -0
  17. package/src/custom-type-add-field-embed.ts +168 -0
  18. package/src/custom-type-add-field-geo-point.ts +165 -0
  19. package/src/custom-type-add-field-group.ts +142 -0
  20. package/src/custom-type-add-field-image.ts +168 -0
  21. package/src/custom-type-add-field-key-text.ts +168 -0
  22. package/src/custom-type-add-field-link.ts +191 -0
  23. package/src/custom-type-add-field-number.ts +200 -0
  24. package/src/custom-type-add-field-rich-text.ts +192 -0
  25. package/src/custom-type-add-field-select.ts +174 -0
  26. package/src/custom-type-add-field-timestamp.ts +171 -0
  27. package/src/custom-type-add-field-uid.ts +151 -0
  28. package/src/custom-type-add-field.ts +116 -0
  29. package/src/custom-type-connect-slice.ts +178 -0
  30. package/src/custom-type-create.ts +98 -0
  31. package/src/custom-type-disconnect-slice.ts +134 -0
  32. package/src/custom-type-list.ts +110 -0
  33. package/src/custom-type-remove-field.ts +135 -0
  34. package/src/custom-type-remove.ts +103 -0
  35. package/src/custom-type-set-name.ts +102 -0
  36. package/src/custom-type-view.ts +118 -0
  37. package/src/custom-type.ts +85 -0
  38. package/src/docs-fetch.ts +146 -0
  39. package/src/docs-list.ts +131 -0
  40. package/src/docs.ts +54 -0
  41. package/src/env.d.ts +12 -0
  42. package/src/framework/index.ts +399 -0
  43. package/src/framework/nextjs.templates.ts +426 -0
  44. package/src/framework/nextjs.ts +216 -0
  45. package/src/framework/nuxt.templates.ts +74 -0
  46. package/src/framework/nuxt.ts +250 -0
  47. package/src/framework/sveltekit.templates.ts +278 -0
  48. package/src/framework/sveltekit.ts +241 -0
  49. package/src/index.ts +155 -0
  50. package/src/init.ts +173 -0
  51. package/src/lib/auth.ts +200 -0
  52. package/src/lib/browser.ts +11 -0
  53. package/src/lib/config.ts +111 -0
  54. package/src/lib/custom-types-api.ts +385 -0
  55. package/src/lib/field-path.ts +81 -0
  56. package/src/lib/file.ts +49 -0
  57. package/src/lib/json.ts +3 -0
  58. package/src/lib/packageJson.ts +35 -0
  59. package/src/lib/profile.ts +39 -0
  60. package/src/lib/request.ts +116 -0
  61. package/src/lib/segment.ts +145 -0
  62. package/src/lib/sentry.ts +63 -0
  63. package/src/lib/string.ts +10 -0
  64. package/src/lib/url.ts +31 -0
  65. package/src/locale-add.ts +116 -0
  66. package/src/locale-list.ts +107 -0
  67. package/src/locale-remove.ts +88 -0
  68. package/src/locale-set-default.ts +131 -0
  69. package/src/locale.ts +60 -0
  70. package/src/login.ts +45 -0
  71. package/src/logout.ts +36 -0
  72. package/src/page-type-add-field-boolean.ts +179 -0
  73. package/src/page-type-add-field-color.ts +165 -0
  74. package/src/page-type-add-field-date.ts +168 -0
  75. package/src/page-type-add-field-embed.ts +165 -0
  76. package/src/page-type-add-field-geo-point.ts +162 -0
  77. package/src/page-type-add-field-group.ts +139 -0
  78. package/src/page-type-add-field-image.ts +165 -0
  79. package/src/page-type-add-field-key-text.ts +165 -0
  80. package/src/page-type-add-field-link.ts +188 -0
  81. package/src/page-type-add-field-number.ts +197 -0
  82. package/src/page-type-add-field-rich-text.ts +189 -0
  83. package/src/page-type-add-field-select.ts +171 -0
  84. package/src/page-type-add-field-timestamp.ts +168 -0
  85. package/src/page-type-add-field-uid.ts +148 -0
  86. package/src/page-type-add-field.ts +116 -0
  87. package/src/page-type-connect-slice.ts +178 -0
  88. package/src/page-type-create.ts +128 -0
  89. package/src/page-type-disconnect-slice.ts +134 -0
  90. package/src/page-type-list.ts +109 -0
  91. package/src/page-type-remove-field.ts +135 -0
  92. package/src/page-type-remove.ts +103 -0
  93. package/src/page-type-set-name.ts +102 -0
  94. package/src/page-type-set-repeatable.ts +111 -0
  95. package/src/page-type-view.ts +118 -0
  96. package/src/page-type.ts +90 -0
  97. package/src/preview-add.ts +126 -0
  98. package/src/preview-get-simulator.ts +104 -0
  99. package/src/preview-list.ts +106 -0
  100. package/src/preview-remove-simulator.ts +80 -0
  101. package/src/preview-remove.ts +109 -0
  102. package/src/preview-set-name.ts +137 -0
  103. package/src/preview-set-simulator.ts +116 -0
  104. package/src/preview.ts +75 -0
  105. package/src/pull.ts +236 -0
  106. package/src/push.ts +409 -0
  107. package/src/repo-create.ts +175 -0
  108. package/src/repo-get-access.ts +86 -0
  109. package/src/repo-list.ts +100 -0
  110. package/src/repo-set-access.ts +100 -0
  111. package/src/repo-set-name.ts +102 -0
  112. package/src/repo-view.ts +113 -0
  113. package/src/repo.ts +70 -0
  114. package/src/slice-add-field-boolean.ts +219 -0
  115. package/src/slice-add-field-color.ts +205 -0
  116. package/src/slice-add-field-date.ts +205 -0
  117. package/src/slice-add-field-embed.ts +205 -0
  118. package/src/slice-add-field-geo-point.ts +202 -0
  119. package/src/slice-add-field-group.ts +170 -0
  120. package/src/slice-add-field-image.ts +202 -0
  121. package/src/slice-add-field-key-text.ts +205 -0
  122. package/src/slice-add-field-link.ts +224 -0
  123. package/src/slice-add-field-number.ts +205 -0
  124. package/src/slice-add-field-rich-text.ts +229 -0
  125. package/src/slice-add-field-select.ts +211 -0
  126. package/src/slice-add-field-timestamp.ts +205 -0
  127. package/src/slice-add-field.ts +111 -0
  128. package/src/slice-add-variation.ts +142 -0
  129. package/src/slice-create.ts +164 -0
  130. package/src/slice-list-variations.ts +71 -0
  131. package/src/slice-list.ts +60 -0
  132. package/src/slice-remove-field.ts +125 -0
  133. package/src/slice-remove-variation.ts +113 -0
  134. package/src/slice-remove.ts +92 -0
  135. package/src/slice-rename.ts +104 -0
  136. package/src/slice-set-screenshot.ts +239 -0
  137. package/src/slice-view.ts +83 -0
  138. package/src/slice.ts +95 -0
  139. package/src/status.ts +834 -0
  140. package/src/sync.ts +259 -0
  141. package/src/token-create.ts +203 -0
  142. package/src/token-delete.ts +182 -0
  143. package/src/token-list.ts +223 -0
  144. package/src/token-set-name.ts +193 -0
  145. package/src/token.ts +60 -0
  146. package/src/webhook-add-header.ts +118 -0
  147. package/src/webhook-create.ts +152 -0
  148. package/src/webhook-disable.ts +109 -0
  149. package/src/webhook-enable.ts +132 -0
  150. package/src/webhook-list.ts +93 -0
  151. package/src/webhook-remove-header.ts +117 -0
  152. package/src/webhook-remove.ts +106 -0
  153. package/src/webhook-set-triggers.ts +148 -0
  154. package/src/webhook-status.ts +90 -0
  155. package/src/webhook-test.ts +106 -0
  156. package/src/webhook-view.ts +147 -0
  157. package/src/webhook.ts +95 -0
  158. package/src/whoami.ts +62 -0
@@ -0,0 +1,192 @@
1
+ import type { CustomType, RichText } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a rich text field to an existing custom type.
12
+
13
+ USAGE
14
+ prismic custom-type add-field rich-text <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Custom type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --single string Allowed block types for single-line (comma-separated)
25
+ --multi string Allowed block types for multi-line (comma-separated)
26
+ --allow-target-blank Allow opening links in new tab
27
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
28
+ -h, --help Show help for command
29
+
30
+ BLOCK TYPES
31
+ heading1, heading2, heading3, heading4, heading5, heading6,
32
+ paragraph, strong, em, preformatted, hyperlink, image, embed,
33
+ list-item, o-list-item, rtl
34
+
35
+ EXAMPLES
36
+ prismic custom-type add-field rich-text homepage body
37
+ prismic custom-type add-field rich-text article content --multi "paragraph,heading2,heading3,strong,em,hyperlink"
38
+ prismic custom-type add-field rich-text page tagline --single "heading1"
39
+ prismic custom-type add-field rich-text blog post --multi "paragraph,strong,em,hyperlink" --allow-target-blank
40
+ `.trim();
41
+
42
+ export async function customTypeAddFieldRichText(): Promise<void> {
43
+ const {
44
+ values: {
45
+ help,
46
+ tab,
47
+ label,
48
+ placeholder,
49
+ single,
50
+ multi,
51
+ "allow-target-blank": allowTargetBlank,
52
+ types,
53
+ },
54
+ positionals: [typeId, fieldId],
55
+ } = parseArgs({
56
+ args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "rich-text"
57
+ options: {
58
+ tab: { type: "string", short: "t" },
59
+ label: { type: "string", short: "l" },
60
+ placeholder: { type: "string", short: "p" },
61
+ single: { type: "string" },
62
+ multi: { type: "string" },
63
+ "allow-target-blank": { type: "boolean" },
64
+ types: { type: "string" },
65
+ help: { type: "boolean", short: "h" },
66
+ },
67
+ allowPositionals: true,
68
+ });
69
+
70
+ if (help) {
71
+ console.info(HELP);
72
+ return;
73
+ }
74
+
75
+ if (!typeId) {
76
+ console.error("Missing required argument: type-id\n");
77
+ console.error("Usage: prismic custom-type add-field rich-text <type-id> <field-id>");
78
+ process.exitCode = 1;
79
+ return;
80
+ }
81
+
82
+ if (!fieldId) {
83
+ console.error("Missing required argument: field-id\n");
84
+ console.error("Usage: prismic custom-type add-field rich-text <type-id> <field-id>");
85
+ process.exitCode = 1;
86
+ return;
87
+ }
88
+
89
+ // Parse and validate field path
90
+ const fieldPath = parseFieldPath(fieldId);
91
+ const pathValidation = validateNestedFieldPath(fieldPath);
92
+ if (!pathValidation.ok) {
93
+ console.error(pathValidation.error);
94
+ process.exitCode = 1;
95
+ return;
96
+ }
97
+
98
+ const framework = await requireFramework();
99
+ if (!framework) return;
100
+
101
+ let model: CustomType;
102
+ try {
103
+ model = await framework.readCustomType(typeId);
104
+ } catch {
105
+ console.error(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
106
+ process.exitCode = 1;
107
+ return;
108
+ }
109
+
110
+ // Determine target tab
111
+ const existingTabs = Object.keys(model.json);
112
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
113
+
114
+ // Initialize tab if it doesn't exist
115
+ if (!model.json[targetTab]) {
116
+ model.json[targetTab] = {};
117
+ }
118
+
119
+ // Build field definition
120
+ const fieldDefinition: RichText = {
121
+ type: "StructuredText",
122
+ config: {
123
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
124
+ ...(placeholder && { placeholder }),
125
+ ...(single && { single }),
126
+ ...(multi && { multi }),
127
+ ...(allowTargetBlank && { allowTargetBlank: true }),
128
+ },
129
+ };
130
+
131
+ // Add field to model
132
+ if (fieldPath.type === "nested") {
133
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
134
+ if (!groupResult.ok) {
135
+ console.error(groupResult.error);
136
+ process.exitCode = 1;
137
+ return;
138
+ }
139
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
140
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
141
+ process.exitCode = 1;
142
+ return;
143
+ }
144
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
145
+ } else {
146
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
147
+ if (tabFields[fieldId]) {
148
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
149
+ process.exitCode = 1;
150
+ return;
151
+ }
152
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
153
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
154
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
155
+ process.exitCode = 1;
156
+ return;
157
+ }
158
+ }
159
+ }
160
+ model.json[targetTab][fieldId] = fieldDefinition;
161
+ }
162
+
163
+ // Write updated model
164
+ try {
165
+ await framework.updateCustomType(model);
166
+ } catch (error) {
167
+ if (error instanceof Error) {
168
+ console.error(`Failed to update custom type: ${error.message}`);
169
+ } else {
170
+ console.error("Failed to update custom type");
171
+ }
172
+ process.exitCode = 1;
173
+ return;
174
+ }
175
+
176
+ if (fieldPath.type === "nested") {
177
+ console.info(`Added field "${fieldPath.nestedFieldId}" (StructuredText) to group "${fieldPath.groupId}" in ${typeId}`);
178
+ } else {
179
+ console.info(`Added field "${fieldId}" (StructuredText) to "${targetTab}" tab in ${typeId}`);
180
+ }
181
+
182
+ try {
183
+ await buildTypes({ output: types });
184
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
185
+ } catch (error) {
186
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
187
+ }
188
+
189
+ console.info();
190
+ console.info("Next: Add more fields with `prismic custom-type add-field`");
191
+ console.info(" Run `prismic status` when done to find next steps");
192
+ }
@@ -0,0 +1,174 @@
1
+ import type { CustomType, Select } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a select (dropdown) field to an existing custom type.
12
+
13
+ USAGE
14
+ prismic custom-type add-field select <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Custom type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --option string Add an option (can be used multiple times)
25
+ --default string Default selected value
26
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
27
+ -h, --help Show help for command
28
+
29
+ EXAMPLES
30
+ prismic custom-type add-field select homepage layout --option "full" --option "sidebar"
31
+ prismic custom-type add-field select product size --option "small" --option "medium" --option "large" --default "medium"
32
+ prismic custom-type add-field select article status --option "draft" --option "published" --label "Status"
33
+ `.trim();
34
+
35
+ export async function customTypeAddFieldSelect(): Promise<void> {
36
+ const {
37
+ values: { help, tab, label, placeholder, option, default: defaultValue, types },
38
+ positionals: [typeId, fieldId],
39
+ } = parseArgs({
40
+ args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "select"
41
+ options: {
42
+ tab: { type: "string", short: "t" },
43
+ label: { type: "string", short: "l" },
44
+ placeholder: { type: "string", short: "p" },
45
+ option: { type: "string", multiple: true },
46
+ default: { type: "string" },
47
+ types: { type: "string" },
48
+ help: { type: "boolean", short: "h" },
49
+ },
50
+ allowPositionals: true,
51
+ });
52
+
53
+ if (help) {
54
+ console.info(HELP);
55
+ return;
56
+ }
57
+
58
+ if (!typeId) {
59
+ console.error("Missing required argument: type-id\n");
60
+ console.error("Usage: prismic custom-type add-field select <type-id> <field-id>");
61
+ process.exitCode = 1;
62
+ return;
63
+ }
64
+
65
+ if (!fieldId) {
66
+ console.error("Missing required argument: field-id\n");
67
+ console.error("Usage: prismic custom-type add-field select <type-id> <field-id>");
68
+ process.exitCode = 1;
69
+ return;
70
+ }
71
+
72
+ // Parse and validate field path
73
+ const fieldPath = parseFieldPath(fieldId);
74
+ const pathValidation = validateNestedFieldPath(fieldPath);
75
+ if (!pathValidation.ok) {
76
+ console.error(pathValidation.error);
77
+ process.exitCode = 1;
78
+ return;
79
+ }
80
+
81
+ const framework = await requireFramework();
82
+ if (!framework) return;
83
+
84
+ let model: CustomType;
85
+ try {
86
+ model = await framework.readCustomType(typeId);
87
+ } catch {
88
+ console.error(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
89
+ process.exitCode = 1;
90
+ return;
91
+ }
92
+
93
+ // Determine target tab
94
+ const existingTabs = Object.keys(model.json);
95
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
96
+
97
+ // Initialize tab if it doesn't exist
98
+ if (!model.json[targetTab]) {
99
+ model.json[targetTab] = {};
100
+ }
101
+
102
+ // Build field definition
103
+ const fieldDefinition: Select = {
104
+ type: "Select",
105
+ config: {
106
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
107
+ ...(placeholder && { placeholder }),
108
+ ...(option && option.length > 0 && { options: option }),
109
+ ...(defaultValue && { default_value: defaultValue }),
110
+ },
111
+ };
112
+
113
+ // Add field to model
114
+ if (fieldPath.type === "nested") {
115
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
116
+ if (!groupResult.ok) {
117
+ console.error(groupResult.error);
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
122
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
123
+ process.exitCode = 1;
124
+ return;
125
+ }
126
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
127
+ } else {
128
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
129
+ if (tabFields[fieldId]) {
130
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
131
+ process.exitCode = 1;
132
+ return;
133
+ }
134
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
135
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
136
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
137
+ process.exitCode = 1;
138
+ return;
139
+ }
140
+ }
141
+ }
142
+ model.json[targetTab][fieldId] = fieldDefinition;
143
+ }
144
+
145
+ // Write updated model
146
+ try {
147
+ await framework.updateCustomType(model);
148
+ } catch (error) {
149
+ if (error instanceof Error) {
150
+ console.error(`Failed to update custom type: ${error.message}`);
151
+ } else {
152
+ console.error("Failed to update custom type");
153
+ }
154
+ process.exitCode = 1;
155
+ return;
156
+ }
157
+
158
+ if (fieldPath.type === "nested") {
159
+ console.info(`Added field "${fieldPath.nestedFieldId}" (Select) to group "${fieldPath.groupId}" in ${typeId}`);
160
+ } else {
161
+ console.info(`Added field "${fieldId}" (Select) to "${targetTab}" tab in ${typeId}`);
162
+ }
163
+
164
+ try {
165
+ await buildTypes({ output: types });
166
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
167
+ } catch (error) {
168
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
169
+ }
170
+
171
+ console.info();
172
+ console.info("Next: Add more fields with `prismic custom-type add-field`");
173
+ console.info(" Run `prismic status` when done to find next steps");
174
+ }
@@ -0,0 +1,171 @@
1
+ import type { CustomType, Timestamp } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a timestamp (date and time) field to an existing custom type.
12
+
13
+ USAGE
14
+ prismic custom-type add-field timestamp <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Custom type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --default string Default timestamp value (ISO 8601 format)
25
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
26
+ -h, --help Show help for command
27
+
28
+ EXAMPLES
29
+ prismic custom-type add-field timestamp homepage event_time
30
+ prismic custom-type add-field timestamp event start --tab "Schedule"
31
+ prismic custom-type add-field timestamp article published_at --label "Published At"
32
+ `.trim();
33
+
34
+ export async function customTypeAddFieldTimestamp(): Promise<void> {
35
+ const {
36
+ values: { help, tab, label, placeholder, default: defaultValue, types },
37
+ positionals: [typeId, fieldId],
38
+ } = parseArgs({
39
+ args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "timestamp"
40
+ options: {
41
+ tab: { type: "string", short: "t" },
42
+ label: { type: "string", short: "l" },
43
+ placeholder: { type: "string", short: "p" },
44
+ default: { type: "string" },
45
+ types: { type: "string" },
46
+ help: { type: "boolean", short: "h" },
47
+ },
48
+ allowPositionals: true,
49
+ });
50
+
51
+ if (help) {
52
+ console.info(HELP);
53
+ return;
54
+ }
55
+
56
+ if (!typeId) {
57
+ console.error("Missing required argument: type-id\n");
58
+ console.error("Usage: prismic custom-type add-field timestamp <type-id> <field-id>");
59
+ process.exitCode = 1;
60
+ return;
61
+ }
62
+
63
+ if (!fieldId) {
64
+ console.error("Missing required argument: field-id\n");
65
+ console.error("Usage: prismic custom-type add-field timestamp <type-id> <field-id>");
66
+ process.exitCode = 1;
67
+ return;
68
+ }
69
+
70
+ // Parse and validate field path
71
+ const fieldPath = parseFieldPath(fieldId);
72
+ const pathValidation = validateNestedFieldPath(fieldPath);
73
+ if (!pathValidation.ok) {
74
+ console.error(pathValidation.error);
75
+ process.exitCode = 1;
76
+ return;
77
+ }
78
+
79
+ const framework = await requireFramework();
80
+ if (!framework) return;
81
+
82
+ let model: CustomType;
83
+ try {
84
+ model = await framework.readCustomType(typeId);
85
+ } catch {
86
+ console.error(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
87
+ process.exitCode = 1;
88
+ return;
89
+ }
90
+
91
+ // Determine target tab
92
+ const existingTabs = Object.keys(model.json);
93
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
94
+
95
+ // Initialize tab if it doesn't exist
96
+ if (!model.json[targetTab]) {
97
+ model.json[targetTab] = {};
98
+ }
99
+
100
+ // Build field definition
101
+ const fieldDefinition: Timestamp = {
102
+ type: "Timestamp",
103
+ config: {
104
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
105
+ ...(placeholder && { placeholder }),
106
+ ...(defaultValue && { default: defaultValue }),
107
+ },
108
+ };
109
+
110
+ // Add field to model
111
+ if (fieldPath.type === "nested") {
112
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
113
+ if (!groupResult.ok) {
114
+ console.error(groupResult.error);
115
+ process.exitCode = 1;
116
+ return;
117
+ }
118
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
119
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
120
+ process.exitCode = 1;
121
+ return;
122
+ }
123
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
124
+ } else {
125
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
126
+ if (tabFields[fieldId]) {
127
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
128
+ process.exitCode = 1;
129
+ return;
130
+ }
131
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
132
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
133
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
134
+ process.exitCode = 1;
135
+ return;
136
+ }
137
+ }
138
+ }
139
+ model.json[targetTab][fieldId] = fieldDefinition;
140
+ }
141
+
142
+ // Write updated model
143
+ try {
144
+ await framework.updateCustomType(model);
145
+ } catch (error) {
146
+ if (error instanceof Error) {
147
+ console.error(`Failed to update custom type: ${error.message}`);
148
+ } else {
149
+ console.error("Failed to update custom type");
150
+ }
151
+ process.exitCode = 1;
152
+ return;
153
+ }
154
+
155
+ if (fieldPath.type === "nested") {
156
+ console.info(`Added field "${fieldPath.nestedFieldId}" (Timestamp) to group "${fieldPath.groupId}" in ${typeId}`);
157
+ } else {
158
+ console.info(`Added field "${fieldId}" (Timestamp) to "${targetTab}" tab in ${typeId}`);
159
+ }
160
+
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}`);
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");
171
+ }
@@ -0,0 +1,151 @@
1
+ import type { CustomType, UID } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a UID (unique identifier) field to an existing custom type.
12
+
13
+ USAGE
14
+ prismic custom-type add-field uid <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Custom type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
25
+ -h, --help Show help for command
26
+
27
+ EXAMPLES
28
+ prismic custom-type add-field uid page uid
29
+ prismic custom-type add-field uid article slug --label "URL Slug"
30
+ prismic custom-type add-field uid product sku --placeholder "Enter unique SKU"
31
+ `.trim();
32
+
33
+ export async function customTypeAddFieldUid(): Promise<void> {
34
+ const {
35
+ values: { help, tab, label, placeholder, types },
36
+ positionals: [typeId, fieldId],
37
+ } = parseArgs({
38
+ args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "uid"
39
+ options: {
40
+ tab: { type: "string", short: "t" },
41
+ label: { type: "string", short: "l" },
42
+ placeholder: { type: "string", short: "p" },
43
+ types: { type: "string" },
44
+ help: { type: "boolean", short: "h" },
45
+ },
46
+ allowPositionals: true,
47
+ });
48
+
49
+ if (help) {
50
+ console.info(HELP);
51
+ return;
52
+ }
53
+
54
+ if (!typeId) {
55
+ console.error("Missing required argument: type-id\n");
56
+ console.error("Usage: prismic custom-type add-field uid <type-id> <field-id>");
57
+ process.exitCode = 1;
58
+ return;
59
+ }
60
+
61
+ if (!fieldId) {
62
+ console.error("Missing required argument: field-id\n");
63
+ console.error("Usage: prismic custom-type add-field uid <type-id> <field-id>");
64
+ process.exitCode = 1;
65
+ return;
66
+ }
67
+
68
+ // Parse and validate field path
69
+ const fieldPath = parseFieldPath(fieldId);
70
+ const pathValidation = validateNestedFieldPath(fieldPath);
71
+ if (!pathValidation.ok) {
72
+ console.error(pathValidation.error);
73
+ process.exitCode = 1;
74
+ return;
75
+ }
76
+
77
+ // UID fields cannot be nested in groups
78
+ if (fieldPath.type === "nested") {
79
+ console.error("UID fields cannot be nested inside groups");
80
+ process.exitCode = 1;
81
+ return;
82
+ }
83
+
84
+ const framework = await requireFramework();
85
+ if (!framework) return;
86
+
87
+ let model: CustomType;
88
+ try {
89
+ model = await framework.readCustomType(typeId);
90
+ } catch {
91
+ console.error(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
92
+ process.exitCode = 1;
93
+ return;
94
+ }
95
+
96
+ // Determine target tab
97
+ const existingTabs = Object.keys(model.json);
98
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
99
+
100
+ // Initialize tab if it doesn't exist
101
+ if (!model.json[targetTab]) {
102
+ model.json[targetTab] = {};
103
+ }
104
+
105
+ // Check if field already exists in any tab
106
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
107
+ if (tabFields[fieldId]) {
108
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
109
+ process.exitCode = 1;
110
+ return;
111
+ }
112
+ }
113
+
114
+ // Build field definition
115
+ const fieldDefinition: UID = {
116
+ type: "UID",
117
+ config: {
118
+ label: label ?? humanReadable(fieldId),
119
+ ...(placeholder && { placeholder }),
120
+ },
121
+ };
122
+
123
+ // Add field to model
124
+ model.json[targetTab][fieldId] = fieldDefinition;
125
+
126
+ // Write updated model
127
+ try {
128
+ await framework.updateCustomType(model);
129
+ } catch (error) {
130
+ if (error instanceof Error) {
131
+ console.error(`Failed to update custom type: ${error.message}`);
132
+ } else {
133
+ console.error("Failed to update custom type");
134
+ }
135
+ process.exitCode = 1;
136
+ return;
137
+ }
138
+
139
+ console.info(`Added field "${fieldId}" (UID) to "${targetTab}" tab in ${typeId}`);
140
+
141
+ try {
142
+ await buildTypes({ output: types });
143
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
144
+ } catch (error) {
145
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
146
+ }
147
+
148
+ console.info();
149
+ console.info("Next: Add more fields with `prismic custom-type add-field`");
150
+ console.info(" Run `prismic status` when done to find next steps");
151
+ }