@astryxdesign/cli 0.6.0 → 0.6.1

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 (219) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +76 -67
  3. package/api/build/build.test.mjs +37 -0
  4. package/api/build/build.type.mjs +1 -1
  5. package/api/build/kit/kit.mjs +31 -1
  6. package/api/component/_adapter.mjs +14 -28
  7. package/api/component/integration-import-agreement.test.mjs +318 -0
  8. package/api/doctor/doctor.d.mts +32 -3
  9. package/api/doctor/doctor.doc.mjs +2 -1
  10. package/api/doctor/doctor.mjs +97 -4
  11. package/api/doctor/doctor.test.mjs +90 -1
  12. package/api/gap-report/gap-report-worker.d.mts +4 -0
  13. package/api/gap-report/gap-report-worker.mjs +73 -0
  14. package/api/gap-report/gap-report.d.mts +81 -0
  15. package/api/gap-report/gap-report.doc.d.mts +9 -0
  16. package/api/gap-report/gap-report.doc.mjs +127 -0
  17. package/api/gap-report/gap-report.mjs +707 -0
  18. package/api/gap-report/gap-report.test.mjs +1210 -0
  19. package/api/gap-report/gap-report.type.d.mts +88 -0
  20. package/api/gap-report/gap-report.type.mjs +69 -0
  21. package/api/index.d.mts +8 -1
  22. package/api/index.mjs +24 -1
  23. package/api/integration/add-contribution.d.mts +44 -0
  24. package/api/integration/add-contribution.mjs +1160 -0
  25. package/api/integration/add-contribution.test.mjs +733 -0
  26. package/api/integration/add-helpers.d.mts +80 -0
  27. package/api/integration/add-helpers.mjs +333 -0
  28. package/api/integration/add-helpers.test.mjs +161 -0
  29. package/api/integration/add-theme.d.mts +10 -0
  30. package/api/integration/add-theme.mjs +332 -0
  31. package/api/integration/add-theme.test.mjs +194 -0
  32. package/api/integration/integration-authoring.type.d.mts +55 -0
  33. package/api/integration/integration-authoring.type.mjs +76 -0
  34. package/api/integration/integration-block-exports.test.mjs +4 -0
  35. package/api/integration/integrationAdd.doc.d.mts +5 -0
  36. package/api/integration/integrationAdd.doc.mjs +100 -0
  37. package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
  38. package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
  39. package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
  40. package/api/integration/integrationAddCodemod.doc.mjs +55 -0
  41. package/api/integration/integrationAddComponent.doc.d.mts +5 -0
  42. package/api/integration/integrationAddComponent.doc.mjs +49 -0
  43. package/api/integration/integrationAddDoc.doc.d.mts +5 -0
  44. package/api/integration/integrationAddDoc.doc.mjs +59 -0
  45. package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
  46. package/api/integration/integrationAddTemplate.doc.mjs +55 -0
  47. package/api/integration/integrationAddTheme.doc.d.mts +5 -0
  48. package/api/integration/integrationAddTheme.doc.mjs +85 -0
  49. package/api/integration/integrationPackCheck.doc.d.mts +5 -0
  50. package/api/integration/integrationPackCheck.doc.mjs +35 -0
  51. package/api/integration/pack-check.d.mts +27 -0
  52. package/api/integration/pack-check.mjs +795 -0
  53. package/api/integration/pack-check.test.mjs +569 -0
  54. package/api/integration/pack-check.type.d.mts +45 -0
  55. package/api/integration/pack-check.type.mjs +56 -0
  56. package/api/integration/public-api.test.mjs +21 -0
  57. package/api/integration/validate-integration.mjs +221 -11
  58. package/api/integration/validate-integration.test.mjs +189 -5
  59. package/api/integration/validateIntegration.doc.mjs +2 -2
  60. package/api/json/index.ts +1 -0
  61. package/api/search/search.mjs +19 -1
  62. package/api/theme/_adapter.d.mts +26 -28
  63. package/api/theme/_adapter.mjs +101 -38
  64. package/api/theme/add/add.d.mts +2 -1
  65. package/api/theme/add/add.mjs +56 -20
  66. package/api/theme/add/add.test.mjs +1 -0
  67. package/api/theme/build/build.d.mts +25 -0
  68. package/api/theme/build/build.mjs +101 -70
  69. package/api/theme/build/build.test.mjs +77 -44
  70. package/api/theme/integration-themes.test.mjs +183 -0
  71. package/api/theme/list/list.d.mts +10 -2
  72. package/api/theme/list/list.mjs +31 -10
  73. package/api/theme/list/list.test.mjs +102 -23
  74. package/api/theme/listThemes.doc.d.mts +1 -5
  75. package/api/theme/listThemes.doc.mjs +6 -13
  76. package/api/theme/targets/targets.test.mjs +22 -8
  77. package/api/theme/theme.d.mts +1 -1
  78. package/api/theme/theme.mjs +1 -1
  79. package/api/theme/theme.type.d.mts +9 -0
  80. package/api/theme/theme.type.mjs +3 -1
  81. package/api/theme/themeAdd.doc.d.mts +1 -4
  82. package/api/theme/themeAdd.doc.mjs +31 -31
  83. package/api/theme/themeBuild.doc.mjs +1 -1
  84. package/api/theme/themeList.doc.d.mts +1 -4
  85. package/api/theme/themeList.doc.mjs +7 -15
  86. package/api/theme/themeListAvailable.doc.d.mts +8 -0
  87. package/api/theme/themeListAvailable.doc.mjs +57 -0
  88. package/api/theme/themeTargets.doc.mjs +21 -7
  89. package/api/upgrade/_adapter.d.mts +2 -0
  90. package/api/upgrade/_adapter.mjs +1 -0
  91. package/api/upgrade/registry/registry.d.mts +40 -0
  92. package/api/upgrade/registry/registry.mjs +1154 -0
  93. package/api/upgrade/registry/registry.test.mjs +826 -0
  94. package/api/upgrade/run/run.mjs +49 -8
  95. package/api/upgrade/status/status.d.mts +6 -4
  96. package/api/upgrade/status/status.mjs +26 -8
  97. package/api/upgrade/upgrade.d.mts +2 -2
  98. package/api/upgrade/upgrade.doc.mjs +33 -9
  99. package/api/upgrade/upgrade.mjs +34 -7
  100. package/api/upgrade/upgrade.test.mjs +198 -8
  101. package/api/upgrade/upgrade.type.d.mts +90 -1
  102. package/api/upgrade/upgrade.type.mjs +51 -2
  103. package/assets/docs/cli-integrations.doc.mjs +152 -28
  104. package/assets/docs/getting-started.doc.mjs +1 -1
  105. package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
  106. package/assets/docs/styling.doc.mjs +3 -3
  107. package/assets/docs/theme.doc.dense.mjs +2 -2
  108. package/assets/docs/theme.doc.mjs +23 -13
  109. package/assets/docs/theme.doc.zh.mjs +1 -1
  110. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
  111. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
  112. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
  113. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
  114. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
  115. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
  116. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
  117. package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
  118. package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
  119. package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
  120. package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
  121. package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
  122. package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
  123. package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
  124. package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
  125. package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
  126. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
  127. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
  128. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
  129. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
  130. package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
  131. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
  132. package/assets/templates/themes/butter/butterTheme.ts +3 -3
  133. package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
  134. package/assets/templates/themes/stone/stoneTheme.ts +3 -3
  135. package/assets/theme.template.ts +4 -7
  136. package/authoring/config/config.doc.mjs +9 -1
  137. package/authoring/config/parse.d.mts +2 -0
  138. package/authoring/config/parse.mjs +28 -3
  139. package/authoring/config/parse.test.mjs +25 -3
  140. package/authoring/config/type.ts +3 -0
  141. package/authoring/doctypes/_schema.d.mts +3 -0
  142. package/authoring/doctypes/_schema.mjs +6 -1
  143. package/authoring/doctypes/base/type.ts +6 -6
  144. package/authoring/doctypes/component/component.doc.mjs +6 -0
  145. package/authoring/doctypes/component/type.ts +2 -0
  146. package/authoring/gap-report/parse.d.mts +63 -0
  147. package/authoring/gap-report/parse.mjs +121 -0
  148. package/authoring/gap-report/parse.test.mjs +172 -0
  149. package/authoring/gap-report/type.ts +107 -0
  150. package/authoring/index.d.mts +1 -0
  151. package/authoring/index.d.ts +12 -0
  152. package/authoring/index.mjs +4 -0
  153. package/authoring/integration/integration.doc.mjs +14 -2
  154. package/authoring/integration/parse.test.mjs +9 -4
  155. package/authoring/integration/schema.d.mts +2 -0
  156. package/authoring/integration/schema.mjs +1 -0
  157. package/authoring/integration/type.ts +23 -6
  158. package/authoring/shadcn/receipt.d.mts +219 -0
  159. package/authoring/shadcn/receipt.mjs +248 -0
  160. package/authoring/shadcn/receipt.test.mjs +187 -0
  161. package/authoring/shadcn/source-variants.d.mts +28 -0
  162. package/authoring/shadcn/source-variants.mjs +176 -0
  163. package/authoring/shadcn/source-variants.test.mjs +120 -0
  164. package/clients/cli/commands/build-theme.mjs +54 -19
  165. package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
  166. package/clients/cli/commands/component/index.mjs +1 -1
  167. package/clients/cli/commands/docs.test.mjs +1 -0
  168. package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
  169. package/clients/cli/commands/gap-report.doc.mjs +73 -0
  170. package/clients/cli/commands/gap-report.mjs +114 -0
  171. package/clients/cli/commands/gap-report.test.mjs +198 -0
  172. package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
  173. package/clients/cli/commands/integration-add.doc.mjs +88 -0
  174. package/clients/cli/commands/integration-authoring.test.mjs +177 -0
  175. package/clients/cli/commands/integration-pack.doc.mjs +34 -0
  176. package/clients/cli/commands/integration-real-world.test.mjs +618 -0
  177. package/clients/cli/commands/integration.doc.mjs +28 -0
  178. package/clients/cli/commands/integration.mjs +153 -0
  179. package/clients/cli/commands/theme-add.doc.mjs +11 -6
  180. package/clients/cli/commands/theme-list.doc.mjs +21 -5
  181. package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
  182. package/clients/cli/commands/theme.doc.mjs +2 -2
  183. package/clients/cli/commands/upgrade.doc.mjs +17 -4
  184. package/clients/cli/commands/upgrade.mjs +12 -1
  185. package/clients/cli/commands/upgrade.test.mjs +41 -0
  186. package/clients/cli/index.mjs +5 -0
  187. package/clients/cli/lib/component-format.mjs +42 -26
  188. package/clients/cli/lib/component-format.test.mjs +34 -3
  189. package/clients/cli/lib/manifest.mjs +12 -0
  190. package/foundation/config/project-themes.test.mjs +127 -0
  191. package/foundation/config/project.d.mts +23 -4
  192. package/foundation/config/project.mjs +96 -9
  193. package/foundation/config/project.test.mjs +132 -6
  194. package/foundation/discovery/component-discovery.d.mts +36 -0
  195. package/foundation/discovery/component-discovery.mjs +96 -0
  196. package/foundation/discovery/theme-discovery.d.mts +39 -0
  197. package/foundation/discovery/theme-discovery.mjs +650 -0
  198. package/foundation/discovery/theme-discovery.test.mjs +375 -0
  199. package/foundation/discovery/theming-targets.d.mts +16 -0
  200. package/foundation/discovery/theming-targets.mjs +39 -3
  201. package/foundation/discovery/theming-targets.test.mjs +139 -0
  202. package/foundation/integrations/autolink.d.mts +96 -0
  203. package/foundation/integrations/autolink.mjs +265 -0
  204. package/foundation/integrations/autolink.test.mjs +430 -0
  205. package/foundation/integrations/contribution-inventory.d.mts +152 -0
  206. package/foundation/integrations/contribution-inventory.mjs +497 -0
  207. package/foundation/integrations/contribution-inventory.test.mjs +361 -0
  208. package/foundation/integrations/integrations.d.mts +73 -9
  209. package/foundation/integrations/integrations.mjs +158 -8
  210. package/foundation/integrations/integrations.test.mjs +152 -29
  211. package/foundation/integrations/manifest-writer.d.mts +56 -0
  212. package/foundation/integrations/manifest-writer.mjs +328 -0
  213. package/foundation/integrations/manifest-writer.test.mjs +229 -0
  214. package/foundation/integrations/validate-contributions.mjs +81 -6
  215. package/foundation/response/error-codes.d.mts +4 -1
  216. package/foundation/response/error-codes.doc.mjs +16 -1
  217. package/foundation/response/error-codes.mjs +10 -1
  218. package/foundation/response/response-types.doc.mjs +23 -2
  219. package/package.json +8 -1
@@ -15,8 +15,8 @@ export const doc = {
15
15
  description:
16
16
  'The astryx.integration.* manifest that sits beside an integration ' +
17
17
  "package's package.json. Points the CLI at the package's components, " +
18
- 'templates, codemods, doc topics, and managed agent guidance, and where to ' +
19
- 'file issues. Every field is optional.',
18
+ 'templates, codemods, doc topics, source themes, and managed agent guidance, ' +
19
+ 'and where to file issues. Every field is optional.',
20
20
  appliesTo: 'astryx.integration.{ts,mjs,js}',
21
21
  fields: [
22
22
  {
@@ -46,6 +46,13 @@ export const doc = {
46
46
  'Relative path to the reference-docs (topics) root (resolved to absolute). Every {topic}.doc.{ts,mjs,js} under it is served by `astryx docs` beside the built-in topics; a topic may also declare `replaces` or `extends` to take the place of a built-in one or merge onto it.',
47
47
  example: "'./docs'",
48
48
  },
49
+ {
50
+ name: 'themes',
51
+ type: 'string',
52
+ description:
53
+ 'Relative path to a source-theme catalog root containing manifest.json plus one directory per theme slug. Installed themes appear in `astryx theme list` and can be copied with `astryx theme add`.',
54
+ example: "'./themes'",
55
+ },
49
56
  {
50
57
  name: 'agentDocs',
51
58
  type: '{ append?: readonly string[] }',
@@ -68,6 +75,7 @@ export const doc = {
68
75
  templates: './src/templates',
69
76
  codemods: './codemods',
70
77
  docs: './docs',
78
+ themes: './themes',
71
79
  agentDocs: {
72
80
  append: ['Run acme verify before finishing.'],
73
81
  },
@@ -92,6 +100,10 @@ export const doc = {
92
100
  'text. The configured project may contain at most 32 integration lines ' +
93
101
  'total.',
94
102
  },
103
+ {
104
+ type: 'prose',
105
+ text: 'A themes root is forward-compatible but version-gated: a CLI released before this field ignores it with a warning and continues loading every contribution kind it understands. That older CLI cannot list or add the contributed themes.',
106
+ },
95
107
  {
96
108
  type: 'prose',
97
109
  text:
@@ -28,6 +28,9 @@ describe('parseIntegration (load boundary)', () => {
28
28
  components: './src',
29
29
  });
30
30
  expect(parseIntegration({docs: './docs'})).toEqual({docs: './docs'});
31
+ expect(parseIntegration({themes: './themes'})).toEqual({
32
+ themes: './themes',
33
+ });
31
34
  expect(() =>
32
35
  parseIntegration({components: './c', issuesUrl: 'https://example.com/i'}),
33
36
  ).not.toThrow();
@@ -38,12 +41,14 @@ describe('parseIntegration (load boundary)', () => {
38
41
  // integration is published once and installed against many CLI versions.
39
42
  // Rejecting the manifest took the whole package's contributions down with
40
43
  // it, silently, on every older consumer (#5119).
41
- expect(parseIntegration({components: './src', futureRoot: './future'})).toEqual({
44
+ expect(
45
+ parseIntegration({components: './src', futureRoot: './future'}),
46
+ ).toEqual({
42
47
  components: './src',
43
48
  });
44
- expect(unknownIntegrationKeys({components: './src', futureRoot: './future'})).toEqual([
45
- 'futureRoot',
46
- ]);
49
+ expect(
50
+ unknownIntegrationKeys({components: './src', futureRoot: './future'}),
51
+ ).toEqual(['futureRoot']);
47
52
  expect(unknownIntegrationKeys({components: './src'})).toEqual([]);
48
53
  // Not a manifest at all — nothing to report, and the parser owns the error.
49
54
  expect(unknownIntegrationKeys(null)).toEqual([]);
@@ -36,6 +36,7 @@ export const integrationBaseSchema: z.ZodObject<{
36
36
  templates: z.ZodOptional<z.ZodString>;
37
37
  codemods: z.ZodOptional<z.ZodString>;
38
38
  docs: z.ZodOptional<z.ZodString>;
39
+ themes: z.ZodOptional<z.ZodString>;
39
40
  issuesUrl: z.ZodOptional<z.ZodString>;
40
41
  }, z.core.$strip>;
41
42
  export const integrationSchema: z.ZodObject<{
@@ -43,6 +44,7 @@ export const integrationSchema: z.ZodObject<{
43
44
  templates: z.ZodOptional<z.ZodString>;
44
45
  codemods: z.ZodOptional<z.ZodString>;
45
46
  docs: z.ZodOptional<z.ZodString>;
47
+ themes: z.ZodOptional<z.ZodString>;
46
48
  issuesUrl: z.ZodOptional<z.ZodString>;
47
49
  agentDocs: z.ZodOptional<z.ZodObject<{
48
50
  append: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
@@ -70,6 +70,7 @@ export const integrationBaseSchema = z.object({
70
70
  templates: z.string().optional(),
71
71
  codemods: z.string().optional(),
72
72
  docs: z.string().optional(),
73
+ themes: z.string().optional(),
73
74
  issuesUrl: z.string().url().optional(),
74
75
  });
75
76
 
@@ -7,12 +7,10 @@
7
7
  * manifest. Authors write a plain object against {@link AstryxIntegration};
8
8
  * the CLI validates it via `parseIntegration` at the load boundary.
9
9
  *
10
- * The manifest module may also carry a `debug` NAMED export — a
11
- * `DebugEventHandler` that receives every command run in the apps that install
12
- * the integration. It is not a field here on purpose: a CLI released before a
13
- * given field existed rejects it, and a rejected manifest contributes nothing
14
- * at all, while a named export is simply not read. See the `cli-integrations`
15
- * doc topic.
10
+ * The manifest module may also carry `debug` and `gapReport` NAMED exports.
11
+ * They are not fields here on purpose: a CLI released before a given manifest
12
+ * field existed could reject it and lose every contribution, while an unknown
13
+ * named export is simply not read. See the `cli-integrations` doc topic.
16
14
  */
17
15
  export interface AstryxIntegration {
18
16
  /** Relative path to the components/docs root (resolved to absolute). */
@@ -26,6 +24,9 @@ export interface AstryxIntegration {
26
24
  * serves from `astryx docs`, alongside the built-in ones. A topic may also
27
25
  * `replace` or `extend` a built-in topic; see the ReferenceDoc type. */
28
26
  docs?: string;
27
+ /** Relative path to the source-theme catalog root (resolved to absolute).
28
+ * The root contains `manifest.json` plus one directory per theme slug. */
29
+ themes?: string;
29
30
  /** Static package guidance appended to the CLI-owned managed agent block. */
30
31
  agentDocs?: {
31
32
  append?: readonly string[];
@@ -33,3 +34,19 @@ export interface AstryxIntegration {
33
34
  /** Where to file issues/feedback for this integration. */
34
35
  issuesUrl?: string;
35
36
  }
37
+
38
+ /**
39
+ * A handler that receives a normalized gap report. Used as a named export
40
+ * from integration manifests and as a config field.
41
+ *
42
+ * Re-exported from `@astryxdesign/cli/authoring`; see
43
+ * `authoring/gap-report/type.ts` for the full contract.
44
+ */
45
+ export type {
46
+ GapReportHandler,
47
+ GapReportHandlerContext,
48
+ GapReport,
49
+ GapReportCategory,
50
+ GapReportTarget,
51
+ GapReportHandlerReceipt,
52
+ } from '../gap-report/type';
@@ -0,0 +1,219 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in authoring/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /** @param {unknown} input */
5
+ export function parseRegistryUpgradeItem(input: unknown): {
6
+ [x: string]: unknown;
7
+ name: string;
8
+ type: "registry:block" | "registry:page";
9
+ files: {
10
+ [x: string]: unknown;
11
+ path: string;
12
+ type: string;
13
+ content: string;
14
+ target?: string | undefined;
15
+ }[];
16
+ };
17
+ /** @param {string} content */
18
+ export function registryContentHash(content: string): string;
19
+ /**
20
+ * Place a receipt beside its copied source so custom ShadCN aliases resolve
21
+ * both files through the same root.
22
+ * @param {string} sourceTarget
23
+ * @param {string} itemName
24
+ */
25
+ export function registryReceiptTarget(sourceTarget: string, itemName: string): string;
26
+ /**
27
+ * @param {{
28
+ * item: {name: string, path: string, aliases: string[], kind: 'showcase'|'example'|'block'|'page'},
29
+ * sourceVersion: string,
30
+ * receiptTarget: string,
31
+ * files: Array<{
32
+ * id: string,
33
+ * target: string,
34
+ * registryPath: string,
35
+ * content: string,
36
+ * variants?: Array<{format: 'javascript', target: string, content: string}>,
37
+ * }>,
38
+ * }} input
39
+ */
40
+ export function createRegistryReceipt(input: {
41
+ item: {
42
+ name: string;
43
+ path: string;
44
+ aliases: string[];
45
+ kind: "showcase" | "example" | "block" | "page";
46
+ };
47
+ sourceVersion: string;
48
+ receiptTarget: string;
49
+ files: Array<{
50
+ id: string;
51
+ target: string;
52
+ registryPath: string;
53
+ content: string;
54
+ variants?: Array<{
55
+ format: "javascript";
56
+ target: string;
57
+ content: string;
58
+ }>;
59
+ }>;
60
+ }): {
61
+ schemaVersion: 1;
62
+ item: {
63
+ name: string;
64
+ path: string;
65
+ aliases: string[];
66
+ kind: "block" | "page" | "example" | "showcase";
67
+ };
68
+ source: {
69
+ package: "@astryxdesign/cli";
70
+ version: string;
71
+ };
72
+ files: {
73
+ id: string;
74
+ target: string;
75
+ registryTarget: string;
76
+ registryPath: string;
77
+ sha256: string;
78
+ content: string;
79
+ }[];
80
+ } | {
81
+ schemaVersion: 2;
82
+ item: {
83
+ name: string;
84
+ path: string;
85
+ aliases: string[];
86
+ kind: "block" | "page" | "example" | "showcase";
87
+ };
88
+ source: {
89
+ package: "@astryxdesign/cli";
90
+ version: string;
91
+ };
92
+ files: {
93
+ variants: {
94
+ format: "javascript";
95
+ target: string;
96
+ registryTarget: string;
97
+ sha256: string;
98
+ content: string;
99
+ }[];
100
+ id: string;
101
+ target: string;
102
+ registryTarget: string;
103
+ registryPath: string;
104
+ sha256: string;
105
+ content: string;
106
+ }[];
107
+ };
108
+ /** @param {unknown} input */
109
+ export function parseRegistryReceipt(input: unknown): {
110
+ schemaVersion: 1;
111
+ item: {
112
+ name: string;
113
+ path: string;
114
+ aliases: string[];
115
+ kind: "block" | "page" | "example" | "showcase";
116
+ };
117
+ source: {
118
+ package: "@astryxdesign/cli";
119
+ version: string;
120
+ };
121
+ files: {
122
+ id: string;
123
+ target: string;
124
+ registryTarget: string;
125
+ registryPath: string;
126
+ sha256: string;
127
+ content: string;
128
+ }[];
129
+ } | {
130
+ schemaVersion: 2;
131
+ item: {
132
+ name: string;
133
+ path: string;
134
+ aliases: string[];
135
+ kind: "block" | "page" | "example" | "showcase";
136
+ };
137
+ source: {
138
+ package: "@astryxdesign/cli";
139
+ version: string;
140
+ };
141
+ files: {
142
+ variants: {
143
+ format: "javascript";
144
+ target: string;
145
+ registryTarget: string;
146
+ sha256: string;
147
+ content: string;
148
+ }[];
149
+ id: string;
150
+ target: string;
151
+ registryTarget: string;
152
+ registryPath: string;
153
+ sha256: string;
154
+ content: string;
155
+ }[];
156
+ };
157
+ /** @param {ReturnType<typeof createRegistryReceipt>} receipt */
158
+ export function serializeRegistryReceipt(receipt: ReturnType<typeof createRegistryReceipt>): string;
159
+ export const REGISTRY_RECEIPT_SCHEMA_VERSION: 2;
160
+ export const PUBLIC_SHADCN_REGISTRY_ORIGIN: "https://astryx.atmeta.com/shadcn";
161
+ export const registryReceiptSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
162
+ schemaVersion: z.ZodLiteral<1>;
163
+ item: z.ZodObject<{
164
+ name: z.ZodString;
165
+ path: z.ZodString;
166
+ aliases: z.ZodArray<z.ZodString>;
167
+ kind: z.ZodEnum<{
168
+ block: "block";
169
+ page: "page";
170
+ example: "example";
171
+ showcase: "showcase";
172
+ }>;
173
+ }, z.core.$strict>;
174
+ source: z.ZodObject<{
175
+ package: z.ZodLiteral<"@astryxdesign/cli">;
176
+ version: z.ZodString;
177
+ }, z.core.$strict>;
178
+ files: z.ZodArray<z.ZodObject<{
179
+ id: z.ZodString;
180
+ target: z.ZodString;
181
+ registryTarget: z.ZodString;
182
+ registryPath: z.ZodString;
183
+ sha256: z.ZodString;
184
+ content: z.ZodString;
185
+ }, z.core.$strict>>;
186
+ }, z.core.$strict>, z.ZodObject<{
187
+ schemaVersion: z.ZodLiteral<2>;
188
+ item: z.ZodObject<{
189
+ name: z.ZodString;
190
+ path: z.ZodString;
191
+ aliases: z.ZodArray<z.ZodString>;
192
+ kind: z.ZodEnum<{
193
+ block: "block";
194
+ page: "page";
195
+ example: "example";
196
+ showcase: "showcase";
197
+ }>;
198
+ }, z.core.$strict>;
199
+ source: z.ZodObject<{
200
+ package: z.ZodLiteral<"@astryxdesign/cli">;
201
+ version: z.ZodString;
202
+ }, z.core.$strict>;
203
+ files: z.ZodArray<z.ZodObject<{
204
+ variants: z.ZodArray<z.ZodObject<{
205
+ format: z.ZodLiteral<"javascript">;
206
+ target: z.ZodString;
207
+ registryTarget: z.ZodString;
208
+ sha256: z.ZodString;
209
+ content: z.ZodString;
210
+ }, z.core.$strict>>;
211
+ id: z.ZodString;
212
+ target: z.ZodString;
213
+ registryTarget: z.ZodString;
214
+ registryPath: z.ZodString;
215
+ sha256: z.ZodString;
216
+ content: z.ZodString;
217
+ }, z.core.$strict>>;
218
+ }, z.core.$strict>], "schemaVersion">;
219
+ import { z } from 'zod';
@@ -0,0 +1,248 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Shared provenance receipt contract for ShadCN-copied Astryx source.
5
+ * @input A stable registry identity and exact canonical and format-specific install bytes.
6
+ * @output Validated, deterministic receipts used by registry generation and upgrade.
7
+ * @position Protocol boundary between the public ShadCN registry and `astryx upgrade`.
8
+ */
9
+
10
+ import {createHash} from 'node:crypto';
11
+ import * as path from 'node:path';
12
+ import {z} from 'zod';
13
+
14
+ export const REGISTRY_RECEIPT_SCHEMA_VERSION = 2;
15
+ export const PUBLIC_SHADCN_REGISTRY_ORIGIN = 'https://astryx.atmeta.com/shadcn';
16
+
17
+ const receiptTargetSchema = z
18
+ .string()
19
+ .regex(/^\.\.\/[^/\\]+$/, 'must point to one adjacent source file')
20
+ .refine(
21
+ value => value !== '../.' && value !== '../..',
22
+ 'must point to one adjacent source file',
23
+ );
24
+
25
+ const registryFilePathSchema = z
26
+ .string()
27
+ .min(1)
28
+ .refine(value => !path.posix.isAbsolute(value), 'must be relative')
29
+ .refine(value => !value.includes('\\'), 'must use forward slashes')
30
+ .refine(
31
+ value =>
32
+ value
33
+ .split('/')
34
+ .every(
35
+ segment => segment !== '' && segment !== '.' && segment !== '..',
36
+ ),
37
+ 'must be a normalized registry path',
38
+ );
39
+
40
+ const registryPathSchema = z
41
+ .string()
42
+ .regex(
43
+ /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/,
44
+ 'must be a lowercase registry path',
45
+ );
46
+
47
+ const sourceVersionSchema = z
48
+ .string()
49
+ .regex(
50
+ /^(?:canary|\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/,
51
+ 'must be canary or an exact semantic version',
52
+ );
53
+
54
+ const receiptItemSchema = z
55
+ .object({
56
+ name: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
57
+ path: registryPathSchema,
58
+ aliases: z.array(registryPathSchema),
59
+ kind: z.enum(['showcase', 'example', 'block', 'page']),
60
+ })
61
+ .strict();
62
+
63
+ const receiptSourceSchema = z
64
+ .object({
65
+ package: z.literal('@astryxdesign/cli'),
66
+ version: sourceVersionSchema,
67
+ })
68
+ .strict();
69
+
70
+ const receiptFileBaseShape = {
71
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
72
+ target: receiptTargetSchema,
73
+ registryTarget: registryFilePathSchema,
74
+ registryPath: registryFilePathSchema,
75
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
76
+ content: z.string(),
77
+ };
78
+
79
+ const receiptVariantSchema = z
80
+ .object({
81
+ format: z.literal('javascript'),
82
+ target: receiptTargetSchema,
83
+ registryTarget: registryFilePathSchema,
84
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
85
+ content: z.string(),
86
+ })
87
+ .strict();
88
+
89
+ const receiptFileV1Schema = z.object(receiptFileBaseShape).strict();
90
+ const receiptFileV2Schema = z
91
+ .object({
92
+ ...receiptFileBaseShape,
93
+ variants: z.array(receiptVariantSchema),
94
+ })
95
+ .strict();
96
+
97
+ const receiptV1Schema = z
98
+ .object({
99
+ schemaVersion: z.literal(1),
100
+ item: receiptItemSchema,
101
+ source: receiptSourceSchema,
102
+ files: z.array(receiptFileV1Schema).min(1),
103
+ })
104
+ .strict();
105
+
106
+ const receiptV2Schema = z
107
+ .object({
108
+ schemaVersion: z.literal(REGISTRY_RECEIPT_SCHEMA_VERSION),
109
+ item: receiptItemSchema,
110
+ source: receiptSourceSchema,
111
+ files: z.array(receiptFileV2Schema).min(1),
112
+ })
113
+ .strict();
114
+
115
+ export const registryReceiptSchema = z
116
+ .discriminatedUnion('schemaVersion', [receiptV1Schema, receiptV2Schema])
117
+ .superRefine((receipt, context) => {
118
+ const identities = [
119
+ {label: 'id', values: receipt.files.map(file => file.id)},
120
+ {
121
+ label: 'registryPath',
122
+ values: receipt.files.map(file => file.registryPath),
123
+ },
124
+ ];
125
+ const installTargets = [];
126
+ const registryTargets = [];
127
+ for (const file of receipt.files) {
128
+ installTargets.push(file.target);
129
+ registryTargets.push(file.registryTarget);
130
+ if ('variants' in file) {
131
+ const formats = file.variants.map(variant => variant.format);
132
+ if (new Set(formats).size !== formats.length) {
133
+ context.addIssue({
134
+ code: 'custom',
135
+ path: ['files'],
136
+ message: 'receipt file variant formats must be unique',
137
+ });
138
+ }
139
+ installTargets.push(...file.variants.map(variant => variant.target));
140
+ registryTargets.push(
141
+ ...file.variants.map(variant => variant.registryTarget),
142
+ );
143
+ }
144
+ }
145
+ identities.push(
146
+ {label: 'target', values: installTargets},
147
+ {label: 'registryTarget', values: registryTargets},
148
+ );
149
+ for (const {label, values} of identities) {
150
+ if (new Set(values).size !== values.length) {
151
+ context.addIssue({
152
+ code: 'custom',
153
+ path: ['files'],
154
+ message: `receipt file ${label} values must be unique`,
155
+ });
156
+ }
157
+ }
158
+ });
159
+
160
+ const registryUpgradeFileSchema = z
161
+ .object({
162
+ path: registryFilePathSchema,
163
+ type: z.string().min(1),
164
+ target: registryFilePathSchema.optional(),
165
+ content: z.string(),
166
+ })
167
+ .passthrough();
168
+
169
+ const registryUpgradeItemSchema = z
170
+ .object({
171
+ name: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
172
+ type: z.enum(['registry:block', 'registry:page']),
173
+ files: z.array(registryUpgradeFileSchema).min(1),
174
+ })
175
+ .passthrough();
176
+
177
+ /** @param {unknown} input */
178
+ export function parseRegistryUpgradeItem(input) {
179
+ return registryUpgradeItemSchema.parse(input);
180
+ }
181
+
182
+ /** @param {string} content */
183
+ export function registryContentHash(content) {
184
+ return createHash('sha256').update(content, 'utf8').digest('hex');
185
+ }
186
+
187
+ /**
188
+ * Place a receipt beside its copied source so custom ShadCN aliases resolve
189
+ * both files through the same root.
190
+ * @param {string} sourceTarget
191
+ * @param {string} itemName
192
+ */
193
+ export function registryReceiptTarget(sourceTarget, itemName) {
194
+ const sourceDir = path.posix.dirname(sourceTarget);
195
+ return path.posix.join(sourceDir, '.astryx', `${itemName}.json`);
196
+ }
197
+
198
+ /**
199
+ * @param {{
200
+ * item: {name: string, path: string, aliases: string[], kind: 'showcase'|'example'|'block'|'page'},
201
+ * sourceVersion: string,
202
+ * receiptTarget: string,
203
+ * files: Array<{
204
+ * id: string,
205
+ * target: string,
206
+ * registryPath: string,
207
+ * content: string,
208
+ * variants?: Array<{format: 'javascript', target: string, content: string}>,
209
+ * }>,
210
+ * }} input
211
+ */
212
+ export function createRegistryReceipt(input) {
213
+ const receiptDir = path.posix.dirname(input.receiptTarget);
214
+ const receipt = {
215
+ schemaVersion: REGISTRY_RECEIPT_SCHEMA_VERSION,
216
+ item: input.item,
217
+ source: {
218
+ package: '@astryxdesign/cli',
219
+ version: input.sourceVersion,
220
+ },
221
+ files: input.files.map(file => ({
222
+ id: file.id,
223
+ target: path.posix.relative(receiptDir, file.target),
224
+ registryTarget: file.target,
225
+ registryPath: file.registryPath,
226
+ sha256: registryContentHash(file.content),
227
+ content: file.content,
228
+ variants: (file.variants ?? []).map(variant => ({
229
+ format: variant.format,
230
+ target: path.posix.relative(receiptDir, variant.target),
231
+ registryTarget: variant.target,
232
+ sha256: registryContentHash(variant.content),
233
+ content: variant.content,
234
+ })),
235
+ })),
236
+ };
237
+ return registryReceiptSchema.parse(receipt);
238
+ }
239
+
240
+ /** @param {unknown} input */
241
+ export function parseRegistryReceipt(input) {
242
+ return registryReceiptSchema.parse(input);
243
+ }
244
+
245
+ /** @param {ReturnType<typeof createRegistryReceipt>} receipt */
246
+ export function serializeRegistryReceipt(receipt) {
247
+ return `${JSON.stringify(receipt, null, 2)}\n`;
248
+ }