@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
@@ -56,6 +56,28 @@ describe('parseConfig (load boundary)', () => {
56
56
  expect(msg).toContain('packages');
57
57
  });
58
58
 
59
+ it('accepts the project gap-report handler shape', () => {
60
+ const handle = () => ({status: 'filed', message: 'ok'});
61
+ expect(
62
+ parseConfig({gapReport: {audience: 'internal', handle}}).gapReport,
63
+ ).toEqual({audience: 'internal', handle});
64
+ });
65
+
66
+ it('rejects obsolete or extended gap-report handler shapes', () => {
67
+ expect(reason({gapReport: {command: './report.mjs'}})).toContain(
68
+ 'gapReport',
69
+ );
70
+ expect(
71
+ reason({
72
+ gapReport: {
73
+ audience: 'internal',
74
+ handle: () => ({status: 'skipped'}),
75
+ extra: true,
76
+ },
77
+ }),
78
+ ).toContain('gapReport');
79
+ });
80
+
59
81
  it('rejects a non-array integrations field', () => {
60
82
  expect(reason({integrations: '@acme/widgets'})).toContain('expected array');
61
83
  expect(reason({integrations: [1]})).toContain('integrations.0');
@@ -72,9 +94,9 @@ describe('parseConfig (load boundary)', () => {
72
94
  });
73
95
 
74
96
  it('rejects a non-function postCodemod.buildCommand', () => {
75
- expect(reason({hooks: {postCodemod: [{buildCommand: 'notAFn'}]}})).toContain(
76
- 'buildCommand',
77
- );
97
+ expect(
98
+ reason({hooks: {postCodemod: [{buildCommand: 'notAFn'}]}}),
99
+ ).toContain('buildCommand');
78
100
  });
79
101
 
80
102
  it('rejects unknown nested keys inside experimental.xle.components', () => {
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  import type {DebugEventHandler} from '../debug/type';
13
+ import type {GapReportHandler} from '../gap-report/type';
13
14
 
14
15
  /**
15
16
  * A command to run as part of a post-codemod hook. Returned by a hook's
@@ -81,6 +82,8 @@ export interface AstryxConfig {
81
82
  };
82
83
  /** Record every astryx command run in this project. See {@link DebugConfig}. */
83
84
  debug?: DebugConfig;
85
+ /** Route gap reports through a project-owned handler. See {@link GapReportHandler}. */
86
+ gapReport?: GapReportHandler;
84
87
  /**
85
88
  * EXPERIMENTAL — shape may change and is not part of the stable config
86
89
  * contract. Provisional home for features still being proven out.
@@ -18,6 +18,7 @@ export const ComponentDocKindSchema: z.ZodObject<{
18
18
  displayName: z.ZodOptional<z.ZodString>;
19
19
  description: z.ZodOptional<z.ZodString>;
20
20
  usage: z.ZodOptional<z.ZodUnknown>;
21
+ import: z.ZodOptional<z.ZodString>;
21
22
  group: z.ZodOptional<z.ZodString>;
22
23
  category: z.ZodOptional<z.ZodString>;
23
24
  keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -46,6 +47,7 @@ export const FunctionDocKindSchema: z.ZodObject<{
46
47
  displayName: z.ZodOptional<z.ZodString>;
47
48
  description: z.ZodOptional<z.ZodString>;
48
49
  usage: z.ZodOptional<z.ZodUnknown>;
50
+ import: z.ZodOptional<z.ZodString>;
49
51
  group: z.ZodOptional<z.ZodString>;
50
52
  category: z.ZodOptional<z.ZodString>;
51
53
  keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -63,6 +65,7 @@ export const GenericDocKindSchema: z.ZodObject<{
63
65
  displayName: z.ZodOptional<z.ZodString>;
64
66
  description: z.ZodOptional<z.ZodString>;
65
67
  usage: z.ZodOptional<z.ZodUnknown>;
68
+ import: z.ZodOptional<z.ZodString>;
66
69
  group: z.ZodOptional<z.ZodString>;
67
70
  category: z.ZodOptional<z.ZodString>;
68
71
  keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -46,6 +46,7 @@ const BaseDocFields = {
46
46
  displayName: z.string().optional(),
47
47
  description: z.string().optional(),
48
48
  usage: z.unknown().optional(),
49
+ import: z.string().min(1).optional(),
49
50
  group: z.string().optional(),
50
51
  category: z.string().optional(),
51
52
  keywords: z.array(z.string()).optional(),
@@ -139,7 +140,11 @@ export const SchemaDocKindSchema = z
139
140
  appliesTo: z.string().optional(),
140
141
  fields: z.array(SchemaFieldSchema),
141
142
  examples: z
142
- .array(z.object({label: z.string().optional(), code: z.string()}).passthrough())
143
+ .array(
144
+ z
145
+ .object({label: z.string().optional(), code: z.string()})
146
+ .passthrough(),
147
+ )
143
148
  .optional(),
144
149
  notes: z.array(z.unknown()).optional(),
145
150
  })
@@ -457,14 +457,14 @@ export interface ComponentThemingTarget {
457
457
  * selectors such as `[data-checked="checked"]`. Omit if the element has no
458
458
  * state-driven selectors. */
459
459
  states?: string[];
460
- /** Set when this target has been RENAMED and this entry is the old name.
461
- * The component still emits the class (via `themeProps`'s `legacyNames`),
462
- * so existing themes keep working, but the docsite should steer readers to
463
- * the replacement. The value is the class name that supersedes this one,
460
+ /** Set when this target has been renamed and this entry is the old name.
461
+ * The component continues emitting the class through `themeProps`'s
462
+ * `legacyNames`, so existing themes keep working while discovery and build
463
+ * guidance prefer the replacement. The value is the canonical target key
464
464
  * without the `astryx-` prefix — e.g. `"checkbox-indicator"`.
465
465
  *
466
- * A theme target is public API; renaming one without this is a silent
467
- * break for every theme styling it. */
466
+ * A theme target is public API; deprecation alone does not authorize
467
+ * removing either this metadata or runtime support. */
468
468
  deprecatedFor?: string;
469
469
  }
470
470
 
@@ -46,6 +46,12 @@ export const doc = {
46
46
  description:
47
47
  'Optional public registry identity. The converter derives a stable kebab-case slug from `name`; set `slug` only to override it, and keep prior relative paths in `aliases` after a published rename.',
48
48
  },
49
+ {
50
+ name: 'import',
51
+ type: 'string',
52
+ description:
53
+ 'Exact public package specifier consumers use to import an integration-owned component. The packed-package gate resolves this specifier and verifies it exports the component name.',
54
+ },
49
55
  {
50
56
  name: 'keywords',
51
57
  type: 'string[]',
@@ -45,6 +45,8 @@ export interface ComponentBaseDoc {
45
45
  * regex derivation. Backfill with
46
46
  * `apps/docsite/scripts/backfill-display-name.mjs`. */
47
47
  displayName: string;
48
+ /** Exact consumer import specifier for integration-owned components. */
49
+ import?: string;
48
50
  /** Search keywords for CLI discovery. Terms a developer might type when
49
51
  * looking for this component: synonyms, related UI concepts, and common
50
52
  * names from other design systems (MUI, Chakra, Radix, shadcn).
@@ -0,0 +1,63 @@
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
+ /**
5
+ * @typedef {import('../_shared/contract').Expect<
6
+ * import('../_shared/contract').MutuallyAssignable<z.infer<typeof receiptSchema>, GapReportHandlerReceipt>
7
+ * >} _GapReportReceiptDriftLock
8
+ */
9
+ /**
10
+ * Validate an unknown value as a `GapReportHandler`, or throw a readable error.
11
+ *
12
+ * @param {unknown} input
13
+ * @param {string} [label]
14
+ * @returns {GapReportHandler}
15
+ */
16
+ export function parseGapReportHandler(input: unknown, label?: string): GapReportHandler;
17
+ /**
18
+ * Validate a handler's return value as a strict `GapReportHandlerReceipt`.
19
+ * Returns the validated receipt, or null when invalid.
20
+ *
21
+ * This runs on the HOT path (called per handler per invocation), so it returns
22
+ * null on failure rather than throwing — the caller records a failed delivery.
23
+ *
24
+ * @param {unknown} input
25
+ * @returns {GapReportHandlerReceipt | null}
26
+ */
27
+ export function parseGapReportReceipt(input: unknown): GapReportHandlerReceipt | null;
28
+ export type _GapReportReceiptDriftLock = import("../_shared/contract").Expect<import("../_shared/contract").MutuallyAssignable<z.infer<typeof receiptSchema>, GapReportHandlerReceipt>>;
29
+ export type GapReportHandler = import("./type").GapReportHandler;
30
+ export type GapReportHandlerReceipt = import("./type").GapReportHandlerReceipt;
31
+ /**
32
+ * Compile-time drift-lock: the sealed schema must infer EXACTLY the public
33
+ * {@link GapReportHandler} type. If they drift, `MutuallyAssignable` becomes
34
+ * `false` and `Expect<false>` fails `tsconfig.authoring-contract.json`.
35
+ */
36
+ export type _GapReportHandlerDriftLock = import("../_shared/contract").Expect<import("../_shared/contract").MutuallyAssignable<z.infer<typeof handlerSchema>, GapReportHandler>>;
37
+ import { z } from 'zod';
38
+ /**
39
+ * Compile-time drift-lock: the sealed schema must infer EXACTLY the public
40
+ * {@link GapReportHandler} type. If they drift, `MutuallyAssignable` becomes
41
+ * `false` and `Expect<false>` fails `tsconfig.authoring-contract.json`.
42
+ *
43
+ * @typedef {import('../_shared/contract').Expect<
44
+ * import('../_shared/contract').MutuallyAssignable<z.infer<typeof handlerSchema>, GapReportHandler>
45
+ * >} _GapReportHandlerDriftLock
46
+ */
47
+ declare const receiptSchema: z.ZodObject<{
48
+ status: z.ZodEnum<{
49
+ filed: "filed";
50
+ routed_only: "routed_only";
51
+ skipped: "skipped";
52
+ }>;
53
+ url: z.ZodOptional<z.ZodString>;
54
+ message: z.ZodOptional<z.ZodString>;
55
+ }, z.core.$strict>;
56
+ declare const handlerSchema: z.ZodObject<{
57
+ audience: z.ZodEnum<{
58
+ internal: "internal";
59
+ public: "public";
60
+ }>;
61
+ handle: z.ZodType<(report: import("./type").GapReport, context: import("./type").GapReportHandlerContext) => import("./type").GapReportHandlerReceipt | Promise<import("./type").GapReportHandlerReceipt>, any, z.core.$ZodTypeInternals<(report: import("./type").GapReport, context: import("./type").GapReportHandlerContext) => import("./type").GapReportHandlerReceipt | Promise<import("./type").GapReportHandlerReceipt>, any>>;
62
+ }, z.core.$strict>;
63
+ export {};
@@ -0,0 +1,121 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Gap-report handler parser — the load-boundary validator for the
5
+ * `gapReport` named export in integration manifests and the `gapReport` field
6
+ * in `astryx.config`.
7
+ *
8
+ * Zod is sealed in here: the schema is module-private, never exported, and
9
+ * never appears in a public type. A compile-time drift-lock asserts it still
10
+ * infers exactly the published interface.
11
+ */
12
+
13
+ import {z} from 'zod';
14
+ import {formatZodError} from '../_shared/errors.mjs';
15
+
16
+ /** @typedef {import('./type').GapReportHandler} GapReportHandler */
17
+ /** @typedef {import('./type').GapReportHandlerReceipt} GapReportHandlerReceipt */
18
+
19
+ // Typed z.custom so z.infer reproduces the real function type, matching the
20
+ // pattern used by the debug handler and post-codemod hook parsers.
21
+ const handleFn = /** @type {z.ZodType<GapReportHandler['handle']>} */ (
22
+ z.custom(value => typeof value === 'function', {
23
+ message: 'Expected a function',
24
+ })
25
+ );
26
+
27
+ const handlerSchema = z
28
+ .object({
29
+ audience: z.enum(['internal', 'public']),
30
+ handle: handleFn,
31
+ })
32
+ .strict();
33
+
34
+ /**
35
+ * Compile-time drift-lock: the sealed schema must infer EXACTLY the public
36
+ * {@link GapReportHandler} type. If they drift, `MutuallyAssignable` becomes
37
+ * `false` and `Expect<false>` fails `tsconfig.authoring-contract.json`.
38
+ *
39
+ * @typedef {import('../_shared/contract').Expect<
40
+ * import('../_shared/contract').MutuallyAssignable<z.infer<typeof handlerSchema>, GapReportHandler>
41
+ * >} _GapReportHandlerDriftLock
42
+ */
43
+
44
+ const receiptSchema = z
45
+ .object({
46
+ status: z.enum(['filed', 'routed_only', 'skipped']),
47
+ url: z.string().optional(),
48
+ message: z.string().optional(),
49
+ })
50
+ .strict();
51
+
52
+ /**
53
+ * @typedef {import('../_shared/contract').Expect<
54
+ * import('../_shared/contract').MutuallyAssignable<z.infer<typeof receiptSchema>, GapReportHandlerReceipt>
55
+ * >} _GapReportReceiptDriftLock
56
+ */
57
+
58
+ /**
59
+ * Validate an unknown value as a `GapReportHandler`, or throw a readable error.
60
+ *
61
+ * @param {unknown} input
62
+ * @param {string} [label]
63
+ * @returns {GapReportHandler}
64
+ */
65
+ export function parseGapReportHandler(input, label = 'gapReport handler') {
66
+ const result = handlerSchema.safeParse(input);
67
+ if (!result.success) {
68
+ throw new Error(formatZodError(label, result.error));
69
+ }
70
+ return result.data;
71
+ }
72
+
73
+ /**
74
+ * Validate a handler's return value as a strict `GapReportHandlerReceipt`.
75
+ * Returns the validated receipt, or null when invalid.
76
+ *
77
+ * This runs on the HOT path (called per handler per invocation), so it returns
78
+ * null on failure rather than throwing — the caller records a failed delivery.
79
+ *
80
+ * @param {unknown} input
81
+ * @returns {GapReportHandlerReceipt | null}
82
+ */
83
+ export function parseGapReportReceipt(input) {
84
+ const result = receiptSchema.safeParse(input);
85
+ if (!result.success) return null;
86
+
87
+ const receipt = result.data;
88
+ const url = receipt.url?.trim() || undefined;
89
+ const message = receipt.message?.trim() || undefined;
90
+
91
+ // routed_only requires a URL
92
+ if (receipt.status === 'routed_only' && !url) return null;
93
+
94
+ // URL must be http(s)
95
+ if (url != null) {
96
+ try {
97
+ const parsed = new URL(url);
98
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
99
+ return null;
100
+ }
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
105
+
106
+ // message length cap
107
+ if (message != null && Array.from(message).length > 2000) {
108
+ return null;
109
+ }
110
+
111
+ // At least url or message where applicable (filed/routed_only)
112
+ if (receipt.status !== 'skipped' && url == null && message == null) {
113
+ return null;
114
+ }
115
+
116
+ return {
117
+ status: receipt.status,
118
+ ...(url == null ? {} : {url}),
119
+ ...(message == null ? {} : {message}),
120
+ };
121
+ }
@@ -0,0 +1,172 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import {parseGapReportHandler, parseGapReportReceipt} from './parse.mjs';
5
+
6
+ describe('parseGapReportHandler', () => {
7
+ it('accepts a valid handler with audience and handle', () => {
8
+ const handler = parseGapReportHandler({
9
+ audience: 'internal',
10
+ handle: () => ({status: 'filed', message: 'ok'}),
11
+ });
12
+ expect(handler.audience).toBe('internal');
13
+ expect(typeof handler.handle).toBe('function');
14
+ });
15
+
16
+ it('accepts public audience', () => {
17
+ const handler = parseGapReportHandler({
18
+ audience: 'public',
19
+ handle: () => ({status: 'skipped'}),
20
+ });
21
+ expect(handler.audience).toBe('public');
22
+ });
23
+
24
+ it('rejects missing audience', () => {
25
+ expect(() => parseGapReportHandler({handle: () => ({})})).toThrow();
26
+ });
27
+
28
+ it('rejects invalid audience value', () => {
29
+ expect(() =>
30
+ parseGapReportHandler({audience: 'secret', handle: () => ({})}),
31
+ ).toThrow();
32
+ });
33
+
34
+ it('rejects missing handle function', () => {
35
+ expect(() => parseGapReportHandler({audience: 'internal'})).toThrow();
36
+ });
37
+
38
+ it('rejects handle that is not a function', () => {
39
+ expect(() =>
40
+ parseGapReportHandler({audience: 'internal', handle: './writer.mjs'}),
41
+ ).toThrow();
42
+ });
43
+
44
+ it('rejects unknown fields (strict)', () => {
45
+ expect(() =>
46
+ parseGapReportHandler({
47
+ audience: 'internal',
48
+ handle: () => ({}),
49
+ command: './writer.mjs',
50
+ }),
51
+ ).toThrow();
52
+ });
53
+
54
+ it('rejects null input', () => {
55
+ expect(() => parseGapReportHandler(null)).toThrow();
56
+ });
57
+
58
+ it('rejects array input', () => {
59
+ expect(() => parseGapReportHandler([])).toThrow();
60
+ });
61
+
62
+ it('rejects bare function (not a plain object)', () => {
63
+ const fn = () => ({status: 'filed'});
64
+ fn.audience = 'internal';
65
+ fn.handle = fn;
66
+ expect(() => parseGapReportHandler(fn)).toThrow();
67
+ });
68
+ });
69
+
70
+ describe('parseGapReportReceipt', () => {
71
+ it('accepts valid filed receipt with message', () => {
72
+ const receipt = parseGapReportReceipt({
73
+ status: 'filed',
74
+ message: 'Report created',
75
+ });
76
+ expect(receipt).toEqual({status: 'filed', message: 'Report created'});
77
+ });
78
+
79
+ it('accepts valid filed receipt with url', () => {
80
+ const receipt = parseGapReportReceipt({
81
+ status: 'filed',
82
+ url: 'https://example.com/issue/1',
83
+ });
84
+ expect(receipt).toEqual({
85
+ status: 'filed',
86
+ url: 'https://example.com/issue/1',
87
+ });
88
+ });
89
+
90
+ it('accepts valid filed receipt with both url and message', () => {
91
+ const receipt = parseGapReportReceipt({
92
+ status: 'filed',
93
+ url: 'https://example.com/issue/1',
94
+ message: 'Created issue #1',
95
+ });
96
+ expect(receipt).not.toBeNull();
97
+ expect(receipt.status).toBe('filed');
98
+ });
99
+
100
+ it('accepts valid routed_only with url', () => {
101
+ const receipt = parseGapReportReceipt({
102
+ status: 'routed_only',
103
+ url: 'https://example.com/issues',
104
+ });
105
+ expect(receipt).toEqual({
106
+ status: 'routed_only',
107
+ url: 'https://example.com/issues',
108
+ });
109
+ });
110
+
111
+ it('rejects routed_only without url', () => {
112
+ expect(
113
+ parseGapReportReceipt({status: 'routed_only', message: 'no url'}),
114
+ ).toBeNull();
115
+ });
116
+
117
+ it('accepts valid skipped without url or message', () => {
118
+ const receipt = parseGapReportReceipt({status: 'skipped'});
119
+ expect(receipt).toEqual({status: 'skipped'});
120
+ });
121
+
122
+ it('rejects filed without url or message', () => {
123
+ expect(parseGapReportReceipt({status: 'filed'})).toBeNull();
124
+ });
125
+
126
+ it('rejects filed with empty message', () => {
127
+ expect(parseGapReportReceipt({status: 'filed', message: ' '})).toBeNull();
128
+ });
129
+
130
+ it('rejects unknown status', () => {
131
+ expect(
132
+ parseGapReportReceipt({status: 'pending', message: 'ok'}),
133
+ ).toBeNull();
134
+ });
135
+
136
+ it('rejects unknown fields', () => {
137
+ expect(
138
+ parseGapReportReceipt({status: 'filed', message: 'ok', extra: true}),
139
+ ).toBeNull();
140
+ });
141
+
142
+ it('rejects non-http url', () => {
143
+ expect(
144
+ parseGapReportReceipt({status: 'filed', url: 'ftp://example.com'}),
145
+ ).toBeNull();
146
+ });
147
+
148
+ it('rejects message over 2000 characters', () => {
149
+ expect(
150
+ parseGapReportReceipt({
151
+ status: 'filed',
152
+ message: 'x'.repeat(2001),
153
+ }),
154
+ ).toBeNull();
155
+ });
156
+
157
+ it('accepts message of exactly 2000 characters', () => {
158
+ const receipt = parseGapReportReceipt({
159
+ status: 'filed',
160
+ message: 'x'.repeat(2000),
161
+ });
162
+ expect(receipt).not.toBeNull();
163
+ });
164
+
165
+ it('rejects null input', () => {
166
+ expect(parseGapReportReceipt(null)).toBeNull();
167
+ });
168
+
169
+ it('rejects string input', () => {
170
+ expect(parseGapReportReceipt('filed')).toBeNull();
171
+ });
172
+ });
@@ -0,0 +1,107 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * Public type surface for gap-report handlers.
5
+ *
6
+ * A handler receives a normalized gap report and routes it to a destination.
7
+ * Project config may define one (`gapReport` in `astryx.config`); every loaded
8
+ * integration may export one as a `gapReport` NAMED export. The CLI composes
9
+ * them additively: project handler first, then each integration handler in
10
+ * config order. Every handler receives a `structuredClone` of the same
11
+ * normalized report.
12
+ *
13
+ * This module is the shared authoring surface for both config and integration
14
+ * gap-report handlers.
15
+ */
16
+
17
+ import type {DebugInvocationSource} from '../debug/type';
18
+
19
+ /** Supported gap-report categories. */
20
+ export type GapReportCategory =
21
+ | 'missing_component'
22
+ | 'missing_variant'
23
+ | 'layout_gap'
24
+ | 'styling_gap'
25
+ | 'a11y_gap'
26
+ | 'api_friction'
27
+ | 'docs_gap'
28
+ | 'other';
29
+
30
+ /**
31
+ * The normalized report event handed to each handler. Plain camelCase,
32
+ * with no handler-private context.
33
+ */
34
+ export interface GapReport {
35
+ schemaVersion: 1;
36
+ component: string;
37
+ category: GapReportCategory;
38
+ categoryLabel: string;
39
+ intention: string;
40
+ detail?: string;
41
+ source: DebugInvocationSource;
42
+ timestamp: string;
43
+ target: GapReportTarget;
44
+ }
45
+
46
+ /** The package a gap report describes. */
47
+ export interface GapReportTarget {
48
+ package: string;
49
+ version: string | null;
50
+ issuesUrl: string | null;
51
+ }
52
+
53
+ /**
54
+ * What a handler returns. Strict: unknown fields are invalid, and an invalid
55
+ * return is recorded as a failed delivery.
56
+ *
57
+ * - `filed` — the handler created or queued the report.
58
+ * - `routed_only` — the handler pointed at a destination but did not create
59
+ * the report itself; `url` is REQUIRED.
60
+ * - `skipped` — the handler chose not to act (e.g. deduplication).
61
+ *
62
+ * At least `url` or `message` must be present where applicable (filed or
63
+ * routed_only).
64
+ */
65
+ export interface GapReportHandlerReceipt {
66
+ status: 'filed' | 'routed_only' | 'skipped';
67
+ /** HTTP(S) URL. Required when status is `routed_only`. */
68
+ url?: string;
69
+ /** Human-readable message, at most 2000 characters. */
70
+ message?: string;
71
+ }
72
+
73
+ /** Context for one handler invocation. */
74
+ export interface GapReportHandlerContext {
75
+ /** Aborted when the handler exceeds its 30-second budget. */
76
+ readonly signal: AbortSignal;
77
+ }
78
+
79
+ /**
80
+ * A handler that receives a normalized gap report. Use a plain object, not a
81
+ * bare function or callable-with-properties.
82
+ *
83
+ * ```
84
+ * export const gapReport = {
85
+ * audience: 'public',
86
+ * handle: async (report) => ({status: 'filed', url: '...'}),
87
+ * };
88
+ * ```
89
+ *
90
+ * The handler is called with `structuredClone(report)`, so mutations are
91
+ * harmless. It may be sync or async; async handlers are awaited with a 30 s
92
+ * timeout. A throw, timeout, or `process.exit` attempt becomes a failed
93
+ * delivery — later handlers still run. Handler stdout is redirected to stderr
94
+ * so JSON stdout remains one envelope.
95
+ */
96
+ export interface GapReportHandler {
97
+ /** Whether the handler's destination is organization-internal or public. */
98
+ audience: 'internal' | 'public';
99
+ /**
100
+ * Called with a normalized, cloned report and an abort signal. Return a strict
101
+ * receipt. Async handlers are awaited with a 30 s timeout.
102
+ */
103
+ handle: (
104
+ report: GapReport,
105
+ context: GapReportHandlerContext,
106
+ ) => GapReportHandlerReceipt | Promise<GapReportHandlerReceipt>;
107
+ }
@@ -15,3 +15,4 @@ export { parseSchema } from "./doctypes/schema/parse.mjs";
15
15
  export { parseCommand } from "./doctypes/command/parse.mjs";
16
16
  export { parseEnum } from "./doctypes/enum/parse.mjs";
17
17
  export { parseLegacyDoc } from "./doctypes/legacy.mjs";
18
+ export { parseGapReportHandler, parseGapReportReceipt } from "./gap-report/parse.mjs";
@@ -34,6 +34,14 @@ export type {EnumDoc} from './doctypes/types'; // error-codes.doc.mjs (v
34
34
  export type {AstryxConfig} from './config/type'; // astryx.config.{ts,mjs}
35
35
  export type {DebugEvent} from './debug/type'; // one recorded CLI run
36
36
  export type {AstryxIntegration} from './integration/type'; // astryx.integration.{ts,mjs}
37
+ export type {
38
+ GapReportHandler,
39
+ GapReportHandlerContext,
40
+ GapReport,
41
+ GapReportCategory,
42
+ GapReportTarget,
43
+ GapReportHandlerReceipt,
44
+ } from './gap-report/type'; // gap-report handler contract
37
45
  export type {AstryxCodemod, AstryxConfigCodemod} from './codemod/type'; // codemods/*
38
46
 
39
47
  // ═══════════════════════════════════════════════════════════════════════
@@ -51,6 +59,10 @@ export {parseEnum} from './doctypes/enum/parse.mjs';
51
59
  export {parseLegacyDoc} from './doctypes/legacy.mjs';
52
60
  export {parseConfig} from './config/parse.mjs';
53
61
  export {parseIntegration} from './integration/parse.mjs';
62
+ export {
63
+ parseGapReportHandler,
64
+ parseGapReportReceipt,
65
+ } from './gap-report/parse.mjs';
54
66
  export {parseCodemod} from './codemod/parse.mjs';
55
67
  export {parseDebugEvent} from './debug/parse.mjs';
56
68
 
@@ -16,6 +16,10 @@
16
16
 
17
17
  export {parseConfig} from './config/parse.mjs';
18
18
  export {parseIntegration} from './integration/parse.mjs';
19
+ export {
20
+ parseGapReportHandler,
21
+ parseGapReportReceipt,
22
+ } from './gap-report/parse.mjs';
19
23
  export {parseCodemod} from './codemod/parse.mjs';
20
24
  export {parseDebugEvent} from './debug/parse.mjs';
21
25
  export {parseDoc} from './doctypes/parse.mjs';