@usefragments/core 1.7.0 → 1.8.0

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 (35) hide show
  1. package/dist/chunk-MZ4SW3TP.js +375 -0
  2. package/dist/chunk-MZ4SW3TP.js.map +1 -0
  3. package/dist/{chunk-WNMWKUYG.js → chunk-UUREQ4HD.js} +318 -6
  4. package/dist/chunk-UUREQ4HD.js.map +1 -0
  5. package/dist/codes/index.d.ts +1 -1
  6. package/dist/codes/index.js +1 -2
  7. package/dist/compiled-types/index.d.ts +1 -1
  8. package/dist/generate/index.d.ts +1 -1
  9. package/dist/governance-telemetry.d.ts +316 -0
  10. package/dist/governance-telemetry.js +11 -0
  11. package/dist/governance-telemetry.js.map +1 -0
  12. package/dist/{index-hZAlYCli.d.ts → index-Cxk3SOQP.d.ts} +1005 -1005
  13. package/dist/index.d.ts +529 -477
  14. package/dist/index.js +78 -37
  15. package/dist/index.js.map +1 -1
  16. package/dist/react-types.d.ts +1 -1
  17. package/dist/registry.d.ts +146 -146
  18. package/dist/schemas/index.d.ts +1 -1
  19. package/dist/schemas/index.js +3 -1
  20. package/dist/test-utils.d.ts +1 -1
  21. package/package.json +5 -1
  22. package/src/component-contract.ts +12 -0
  23. package/src/contract-parser.ts +2 -0
  24. package/src/governance-telemetry.test.ts +18 -0
  25. package/src/governance-telemetry.ts +398 -0
  26. package/src/index.ts +17 -0
  27. package/src/rules/index.ts +5 -1
  28. package/src/rules/tokens-css-vars-must-be-defined.test.ts +66 -1
  29. package/src/rules/tokens-css-vars-must-be-defined.ts +88 -16
  30. package/src/schemas/index.ts +4 -0
  31. package/src/schemas/normalize-finding.test.ts +50 -0
  32. package/dist/chunk-WNMWKUYG.js.map +0 -1
  33. package/dist/chunk-ZHS52OT4.js +0 -317
  34. package/dist/chunk-ZHS52OT4.js.map +0 -1
  35. package/dist/{governance-D9KtH-vg.d.ts → governance-eEzCyfes.d.ts} +154 -154
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ CompiledFragmentsFileValidationError,
3
+ parseCompiledFragmentsFile
4
+ } from "./chunk-RANPUC6C.js";
1
5
  import {
2
6
  generateContext
3
7
  } from "./chunk-X34IA4LR.js";
@@ -7,6 +11,11 @@ import {
7
11
  import {
8
12
  resolveArea
9
13
  } from "./chunk-3LLRNCPX.js";
14
+ import {
15
+ GOVERNANCE_TELEMETRY_FIELDS,
16
+ GOVERNANCE_TELEMETRY_SOURCE_DISCLOSURE,
17
+ GOVERNANCE_TELEMETRY_TOP_LEVEL_FIELDS
18
+ } from "./chunk-MZ4SW3TP.js";
10
19
  import {
11
20
  REGISTRY_ARTIFACT_SCHEMA_VERSION,
12
21
  REGISTRY_INSTALL_RECEIPT_SCHEMA_VERSION,
@@ -41,11 +50,16 @@ import {
41
50
  sha256Hex
42
51
  } from "./chunk-YF65VYRY.js";
43
52
  import {
53
+ AGENT_FORMAT_SCHEMA_VERSION,
44
54
  CODES,
45
55
  EXPLAIN_URL_BASE,
46
56
  FactIndex,
47
57
  RULE_FAMILY_IDS,
48
58
  RULE_FAMILY_MEMBERS,
59
+ agentErrorEnvelopeSchema,
60
+ agentFormatSchema,
61
+ agentIntegritySchema,
62
+ agentOutputSchema,
49
63
  asComponentId,
50
64
  bridgeSourceViolation,
51
65
  bridgeSourceViolations,
@@ -61,13 +75,25 @@ import {
61
75
  describePolicyExclude,
62
76
  excludeGlobToRegExp,
63
77
  explainUrlForCode,
78
+ factEvidenceSchema,
64
79
  factId,
80
+ factLocationSchema,
81
+ findingFixSchema,
82
+ findingReplaceClassTokenFixSchema,
83
+ findingReplaceComponentFixSchema,
84
+ findingReplaceImportFixSchema,
85
+ findingReplacePropValueFixSchema,
86
+ findingReplaceStyleValueFixSchema,
87
+ findingSchema,
88
+ fixSchema,
65
89
  g,
66
90
  globalGovernanceRecordSchema,
67
91
  globalJsxGovernanceRecordSchema,
68
92
  globalStyleGovernanceRecordSchema,
69
93
  governanceConfigSchema,
70
94
  governanceSeveritySchema,
95
+ governanceVerdictMetadataSchema,
96
+ governanceVerdictSchema,
71
97
  hash64Hex,
72
98
  isPresetSourcedRule,
73
99
  isRuleFamilyId,
@@ -116,8 +142,11 @@ import {
116
142
  matchPolicyExclude,
117
143
  matchesGlob,
118
144
  normalizeExcludePath,
145
+ normalizeFinding,
119
146
  normalizeGovernanceConfig,
120
147
  normalizePolicyExcludes,
148
+ normalizeSeverity,
149
+ normalizeViolation,
121
150
  ownedComponentIdsEqual,
122
151
  ownedImportMatchesRoot,
123
152
  ownedImportsEqual,
@@ -126,33 +155,11 @@ import {
126
155
  projectSupersededImportPathPreferences,
127
156
  resolveComponentGovernance,
128
157
  ruleFamilyMembers,
129
- scaleGovernanceRecordSchema
130
- } from "./chunk-WNMWKUYG.js";
131
- import {
132
- AGENT_FORMAT_SCHEMA_VERSION,
133
- agentErrorEnvelopeSchema,
134
- agentFormatSchema,
135
- agentIntegritySchema,
136
- agentOutputSchema,
137
- factEvidenceSchema,
138
- factLocationSchema,
139
- findingFixSchema,
140
- findingReplaceClassTokenFixSchema,
141
- findingReplaceComponentFixSchema,
142
- findingReplaceImportFixSchema,
143
- findingReplacePropValueFixSchema,
144
- findingReplaceStyleValueFixSchema,
145
- findingSchema,
146
- fixSchema,
147
- governanceVerdictMetadataSchema,
148
- governanceVerdictSchema,
149
- normalizeFinding,
150
- normalizeSeverity,
151
- normalizeViolation,
158
+ scaleGovernanceRecordSchema,
152
159
  suppressionDirectiveSchema,
153
160
  validatorResultSchema,
154
161
  violationSchema
155
- } from "./chunk-ZHS52OT4.js";
162
+ } from "./chunk-UUREQ4HD.js";
156
163
  import {
157
164
  OWNED_PACKAGE_IDENTITY_EPOCH,
158
165
  OWNED_PACKAGE_IDENTITY_SOURCE_SHA256,
@@ -182,10 +189,6 @@ import {
182
189
  severitySchema,
183
190
  sortBySeverity
184
191
  } from "./chunk-V4VQB57N.js";
185
- import {
186
- CompiledFragmentsFileValidationError,
187
- parseCompiledFragmentsFile
188
- } from "./chunk-RANPUC6C.js";
189
192
 
190
193
  // src/constants.ts
191
194
  var BRAND = {
@@ -4098,6 +4101,11 @@ var componentContractSchema = z6.object({
4098
4101
  tags: z6.array(z6.string()).optional(),
4099
4102
  status: z6.enum(["stable", "beta", "deprecated", "experimental"]).optional(),
4100
4103
  framework: z6.enum(["react", "vue", "svelte", "web-components", "angular"]).optional(),
4104
+ dependencies: z6.array(z6.object({
4105
+ name: z6.string(),
4106
+ version: z6.string(),
4107
+ reason: z6.string().optional()
4108
+ })).optional(),
4101
4109
  sourcePath: z6.string(),
4102
4110
  exportName: z6.string(),
4103
4111
  propsSummary: z6.array(z6.string()),
@@ -4128,6 +4136,7 @@ function parseComponentContract(content, filePath) {
4128
4136
  category: validated.category,
4129
4137
  tags: validated.tags,
4130
4138
  status: validated.status,
4139
+ dependencies: validated.dependencies,
4131
4140
  figma: validated.figma?.nodeUrl,
4132
4141
  figmaProps: validated.figma?.propMappings
4133
4142
  },
@@ -8754,16 +8763,28 @@ function indexTokensByCssVariable(tokens) {
8754
8763
  var RULE_ID22 = "tokens/css-vars-must-be-defined";
8755
8764
  var RULE_VERSION23 = "1";
8756
8765
  var CSS_VAR_REFERENCE = /var\(\s*(--[A-Za-z0-9_-]+)/gi;
8766
+ function contractVocabularyContext(ix) {
8767
+ if (!ix.policy.cssVarsMustBeDefined()) return void 0;
8768
+ const vocabulary = new Set(ix.byKind("contract_token").map((token) => token.name));
8769
+ if (vocabulary.size === 0) return void 0;
8770
+ return {
8771
+ vocabulary,
8772
+ prefixes: contractPrefixFamilies(vocabulary),
8773
+ hasFlatTokens: [...vocabulary].some(isSingleSegmentVarName),
8774
+ locallyDefinedCustomProperties: new Set(
8775
+ ix.byKind("style_declaration").filter((decl) => decl.property.startsWith("--")).map((decl) => decl.property)
8776
+ )
8777
+ };
8778
+ }
8779
+ function isJudgedReference(tokenName, context) {
8780
+ return context.vocabulary.has(tokenName) || sharesContractPrefix(tokenName, context.prefixes) || context.hasFlatTokens && isSingleSegmentVarName(tokenName) || context.locallyDefinedCustomProperties.has(tokenName);
8781
+ }
8757
8782
  function ruleTokensCssVarsMustBeDefined(ix) {
8758
8783
  const policy = ix.policy.cssVarsMustBeDefined();
8759
8784
  if (!policy) return [];
8760
- const vocabulary = new Set(ix.byKind("contract_token").map((token) => token.name));
8761
- if (vocabulary.size === 0) return [];
8762
- const prefixes = contractPrefixFamilies(vocabulary);
8763
- const hasFlatTokens = [...vocabulary].some(isSingleSegmentVarName);
8764
- const locallyDefinedCustomProperties = new Set(
8765
- ix.byKind("style_declaration").filter((decl) => decl.property.startsWith("--")).map((decl) => decl.property)
8766
- );
8785
+ const context = contractVocabularyContext(ix);
8786
+ if (!context) return [];
8787
+ const { vocabulary } = context;
8767
8788
  const findings = [];
8768
8789
  for (const decl of ix.byKind("style_declaration")) {
8769
8790
  const seen = /* @__PURE__ */ new Set();
@@ -8773,8 +8794,7 @@ function ruleTokensCssVarsMustBeDefined(ix) {
8773
8794
  const tokenName = match[1];
8774
8795
  CSS_VAR_REFERENCE.lastIndex = skipToCloseParen(decl.value, match.index + 3);
8775
8796
  if (vocabulary.has(tokenName)) continue;
8776
- const shaped = sharesContractPrefix(tokenName, prefixes) || hasFlatTokens && isSingleSegmentVarName(tokenName) || locallyDefinedCustomProperties.has(tokenName);
8777
- if (!shaped) continue;
8797
+ if (!isJudgedReference(tokenName, context)) continue;
8778
8798
  if (seen.has(tokenName)) continue;
8779
8799
  seen.add(tokenName);
8780
8800
  findings.push(
@@ -8813,6 +8833,23 @@ function sharesContractPrefix(name, prefixes) {
8813
8833
  function isSingleSegmentVarName(name) {
8814
8834
  return name.indexOf("-", 2) === -1;
8815
8835
  }
8836
+ function contractTokenReferenceCensus(ix) {
8837
+ const context = contractVocabularyContext(ix);
8838
+ if (!context) return void 0;
8839
+ const checked = /* @__PURE__ */ new Set();
8840
+ for (const decl of ix.byKind("style_declaration")) {
8841
+ CSS_VAR_REFERENCE.lastIndex = 0;
8842
+ let match;
8843
+ while ((match = CSS_VAR_REFERENCE.exec(decl.value)) !== null) {
8844
+ const tokenName = match[1];
8845
+ CSS_VAR_REFERENCE.lastIndex = skipToCloseParen(decl.value, match.index + 3);
8846
+ if (!isJudgedReference(tokenName, context)) continue;
8847
+ checked.add(`${decl.location.file}:${decl.location.line}:${decl.location.column}`);
8848
+ break;
8849
+ }
8850
+ }
8851
+ return { checkedSites: checked.size };
8852
+ }
8816
8853
  function skipToCloseParen(value, openParenIndex) {
8817
8854
  let depth = 0;
8818
8855
  for (let i = openParenIndex; i < value.length; i++) {
@@ -10276,6 +10313,9 @@ export {
10276
10313
  EXPLAIN_URL_BASE,
10277
10314
  FRAGMENTS_INTERNAL_RULE_IDS,
10278
10315
  FactIndex,
10316
+ GOVERNANCE_TELEMETRY_FIELDS,
10317
+ GOVERNANCE_TELEMETRY_SOURCE_DISCLOSURE,
10318
+ GOVERNANCE_TELEMETRY_TOP_LEVEL_FIELDS,
10279
10319
  OWNED_PACKAGE_IDENTITY_EPOCH,
10280
10320
  OWNED_PACKAGE_IDENTITY_SOURCE_SHA256,
10281
10321
  PRESET_NAMES,
@@ -10377,6 +10417,7 @@ export {
10377
10417
  contractHash,
10378
10418
  contractPolicyFromGovernanceConfig,
10379
10419
  contractTierRuleIds,
10420
+ contractTokenReferenceCensus,
10380
10421
  customerDefaultRuleStates,
10381
10422
  defineBlock,
10382
10423
  defineConfig,