@usefidel/contracts 0.1.0 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { RUN_ERROR_CODES, ERROR_CODE_META, mapSnapshotErrorToCode, mapFigmaErrorToCode, resolveRunDisplay, } from './run-errors.js';
2
2
  export type { RunErrorCode, RunErrorMeta, ErrorMapping, RunDisplay, } from './run-errors.js';
3
+ export type { IntakeFramework, UnsupportedStack, UnsupportedReason, UnresolvedReferenceSection, UnresolvedReferenceReason, UnresolvedReference, ParsedThemeColor, ParsedThemeTypography, ParsedThemeSize, ShadcnConfig, ParsedTheme, IntakeDetection, TokenSourceKind, TokenSource, PackageRole, PackageInfo, } from './theme-intake.js';
@@ -15,7 +15,7 @@
15
15
  * When editing this file, run `npx tsx scripts/check-vendor-sync.ts` and
16
16
  * update all consumer copies.
17
17
  */
18
- export declare const RUN_ERROR_CODES: readonly ["TARGET_AUTH_WALL", "TARGET_UNREACHABLE", "TARGET_TIMEOUT", "TARGET_CSP_BLOCKED", "FIGMA_ACCESS_DENIED", "FIGMA_TOKEN_EXPIRED", "FIGMA_NOT_FOUND", "FIGMA_RATE_LIMITED", "PIPELINE_TIMEOUT", "PIPELINE_ERROR", "ZERO_ELEMENTS_MATCHED", "PERSIST_FAILED", "SESSION_EXPIRED", "INVALID_REFERENCE_URL", "INVALID_TARGET_URL", "DESIGN_SYSTEM_NOT_AVAILABLE", "DESIGN_SYSTEM_CONTEXT_NOT_AVAILABLE", "DESIGN_SYSTEM_INCOMPATIBLE", "FLOW_STEP_FAILED", "UNKNOWN_ERROR"];
18
+ export declare const RUN_ERROR_CODES: readonly ["TARGET_AUTH_WALL", "TARGET_UNREACHABLE", "TARGET_TIMEOUT", "TARGET_CSP_BLOCKED", "FIGMA_ACCESS_DENIED", "FIGMA_TOKEN_EXPIRED", "FIGMA_NOT_FOUND", "FIGMA_RATE_LIMITED", "PIPELINE_TIMEOUT", "PIPELINE_ERROR", "ZERO_ELEMENTS_MATCHED", "PERSIST_FAILED", "SESSION_EXPIRED", "INVALID_REFERENCE_URL", "INVALID_TARGET_URL", "DESIGN_SYSTEM_NOT_AVAILABLE", "DESIGN_SYSTEM_CONTEXT_NOT_AVAILABLE", "DESIGN_SYSTEM_INCOMPATIBLE", "FLOW_STEP_FAILED", "CAPABILITY_UNAVAILABLE", "PROVIDER_REQUEST_REJECTED", "UNKNOWN_ERROR"];
19
19
  export type RunErrorCode = (typeof RUN_ERROR_CODES)[number];
20
20
  export interface RunErrorMeta {
21
21
  retryable: boolean;
@@ -66,6 +66,23 @@ export const RUN_ERROR_CODES = [
66
66
  // (e.g. a transition target is missing or the step response is invalid).
67
67
  // retryable: false — this is a structural design problem, not a transient error.
68
68
  'FLOW_STEP_FAILED',
69
+ // Plan G-10 follow-up: replay-provider outcomes that cannot recover by
70
+ // retrying. Both are deliberately provider-NEUTRAL, in name and in message.
71
+ // The provider, its status codes and its response bodies stay in structured
72
+ // logs (`replay_provider_failed`); error_message is owner-readable AND
73
+ // projected through get_shared_run to anon share viewers, so it must not
74
+ // name a vendor or describe our configuration (same H-4 reasoning as the
75
+ // DESIGN_SYSTEM_* codes above).
76
+ //
77
+ // CAPABILITY_UNAVAILABLE — the saved-session capability itself is not
78
+ // usable: credential absent, rejected, or the plan/quota is exhausted.
79
+ // Operator-side. retryable: false — no number of retries configures a key.
80
+ 'CAPABILITY_UNAVAILABLE',
81
+ // PROVIDER_REQUEST_REJECTED — a deterministic rejection of this specific
82
+ // request (a 4xx that is not auth, not "gone", not rate limiting), or a 2xx
83
+ // whose body was structurally unusable. retryable: false — the same request
84
+ // will be rejected the same way.
85
+ 'PROVIDER_REQUEST_REJECTED',
69
86
  'UNKNOWN_ERROR',
70
87
  ];
71
88
  export const ERROR_CODE_META = {
@@ -134,6 +151,16 @@ export const ERROR_CODE_META = {
134
151
  userMessage: "This site's saved session has expired. Reconnect it to validate again.",
135
152
  shortLabel: 'Session expired',
136
153
  },
154
+ CAPABILITY_UNAVAILABLE: {
155
+ retryable: false,
156
+ userMessage: "Validating sites that need a saved sign-in isn't available right now. This one's on us — contact support and we'll get it working.",
157
+ shortLabel: 'Capability unavailable',
158
+ },
159
+ PROVIDER_REQUEST_REJECTED: {
160
+ retryable: false,
161
+ userMessage: "This validation couldn't be completed. Trying again won't change the result — contact support if you need it looked at.",
162
+ shortLabel: 'Validation rejected',
163
+ },
137
164
  INVALID_REFERENCE_URL: {
138
165
  retryable: false,
139
166
  userMessage: 'The reference URL is invalid. It must start with https:// and point to a real page.',
@@ -0,0 +1,160 @@
1
+ /**
2
+ * theme-intake — the wire contract for the `theme-intake` edge function's
3
+ * response, as consumed by the webapp.
4
+ *
5
+ * THIS FILE IS THE CONTRACT, NOT A MIRROR OF ONE FILE.
6
+ * ────────────────────────────────────────────────────
7
+ * The shape is assembled from TWO backend sources, which is why it can never be
8
+ * a byte-copy the way `run-errors.ts` is:
9
+ *
10
+ * 1. `supabase/functions/_shared/theme-parser/types.ts` — the ParsedTheme core.
11
+ * That file also declares parser INTERNALS (RawToken's full shape,
12
+ * SEMANTIC_COLOR_NAMES) which are deliberately NOT re-exported here: this
13
+ * package is installable by a contractor, so it carries the wire and
14
+ * nothing else.
15
+ *
16
+ * 2. `supabase/functions/theme-intake/index.ts` — adds three W3d fields to the
17
+ * response at the edge boundary: `tokenSources`, `packages`,
18
+ * `tokenSourcesTruncated`.
19
+ *
20
+ * Some type NAMES differ from the backend's on purpose (ColorToken →
21
+ * ParsedThemeColor, etc.); the FIELD names are what must stay in lockstep,
22
+ * because those are what cross the wire.
23
+ *
24
+ * ENFORCEMENT. `scripts/check-canonical-sync.mjs` asserts structurally that
25
+ * ParsedTheme here declares every field of the canonical ParsedTheme plus
26
+ * exactly the W3d extension fields. It runs in the monorepo merge gate and again
27
+ * in the publisher workflow at the pinned SHA before publishing.
28
+ *
29
+ * HISTORY. Until #591 this lived at `webapp/src/types/theme-intake.ts` with a
30
+ * `vendor-sync.config.json` pair pointing only at source (1). #591 moved webapp/
31
+ * to usefidel/fidel-web and the pair was deleted rather than migrated, leaving
32
+ * the contract spanning two repositories with nothing checking it. Recorded as
33
+ * `theme-intake-wire-contract-unguarded` (#601); this file closes it.
34
+ */
35
+ export type IntakeFramework = 'next' | 'remix' | 'astro' | 'sveltekit' | 'solidstart' | 'vite' | 'react' | 'unknown';
36
+ export type UnsupportedStack = 'chakra' | 'mui' | 'mantine' | 'antd' | 'radix-themes' | 'stitches' | 'vanilla-extract' | 'panda' | 'styled-components' | 'emotion';
37
+ export type UnsupportedReason = 'tailwind-v3-needs-js-eval' | 'tailwind-version-unknown' | 'no-token-sources' | 'token-values-not-parsed';
38
+ export type UnresolvedReferenceSection = 'colors' | 'fontFamily' | 'fontSize' | 'spacing' | 'borderRadius' | 'lineHeight' | 'letterSpacing' | 'fontWeight' | 'boxShadow' | 'dropShadow' | 'presets' | 'plugins' | 'other';
39
+ export type UnresolvedReferenceReason = 'imported_value' | 'computed_expression' | 'function_call' | 'preset_referenced' | 'plugin_referenced' | 'unparseable';
40
+ export interface UnresolvedReference {
41
+ section: UnresolvedReferenceSection;
42
+ reason: UnresolvedReferenceReason;
43
+ detail: string;
44
+ }
45
+ export interface ParsedThemeColor {
46
+ name: string;
47
+ value: string;
48
+ source: string;
49
+ layer: 'theme' | 'root';
50
+ resolved: string | null;
51
+ resolveTrail: string[];
52
+ /** Where the resolved value came from. */
53
+ resolvedFrom: 'user' | 'tailwind-default' | null;
54
+ /** sRGB hex (`#rrggbb`) for swatch rendering, or null when format unsupported. PR 27-06. */
55
+ srgb: string | null;
56
+ }
57
+ export interface ParsedThemeTypography {
58
+ name: string;
59
+ value: string;
60
+ source: string;
61
+ kind: 'family' | 'size' | 'weight' | 'leading' | 'tracking' | 'other';
62
+ }
63
+ export interface ParsedThemeSize {
64
+ category: string;
65
+ name: string;
66
+ /** Resolved value — `var(--X)` and `calc(var(--X) * N)` references are
67
+ * walked and computed against other tokens before the row is rendered.
68
+ * Falls back to the raw value when a reference can't be resolved. */
69
+ value: string;
70
+ /** Original CSS authoring value when resolution changed it. Optional —
71
+ * populated only when the resolved value differs from the source. */
72
+ raw_value?: string;
73
+ source: string;
74
+ }
75
+ export interface ShadcnConfig {
76
+ style: string | null;
77
+ rsc: boolean | null;
78
+ tsx: boolean | null;
79
+ tailwind: {
80
+ config: string | null;
81
+ css: string | null;
82
+ baseColor: string | null;
83
+ cssVariables: boolean | null;
84
+ prefix: string | null;
85
+ } | null;
86
+ aliases: {
87
+ components: string | null;
88
+ utils: string | null;
89
+ ui: string | null;
90
+ lib: string | null;
91
+ hooks: string | null;
92
+ } | null;
93
+ iconLibrary: string | null;
94
+ }
95
+ export interface ParsedTheme {
96
+ tailwindVersion: 'v3' | 'v4' | 'unknown';
97
+ unsupported_reason: UnsupportedReason | null;
98
+ rawTokens: unknown[];
99
+ colors: ParsedThemeColor[];
100
+ typography: ParsedThemeTypography[];
101
+ sizes: ParsedThemeSize[];
102
+ files: string[];
103
+ unresolvedImports: string[];
104
+ references_default_palette: boolean;
105
+ shadcn: ShadcnConfig | null;
106
+ counts: {
107
+ colors: number;
108
+ typography: number;
109
+ sizes: number;
110
+ rawTokens: number;
111
+ };
112
+ unresolvedReferences?: UnresolvedReference[];
113
+ tokenSources?: TokenSource[];
114
+ packages?: PackageInfo[];
115
+ tokenSourcesTruncated?: boolean;
116
+ }
117
+ export interface IntakeDetection {
118
+ ref: string;
119
+ detected_at: string;
120
+ framework: IntakeFramework;
121
+ tailwind_version: 'v3' | 'v4' | 'unknown' | null;
122
+ has_shadcn: boolean;
123
+ unsupported_stack: UnsupportedStack | null;
124
+ files_found: string[];
125
+ files_missing: string[];
126
+ errors: {
127
+ path: string;
128
+ code: string;
129
+ }[];
130
+ hints: {
131
+ tailwind_config_path: string | null;
132
+ components_json_path: string | null;
133
+ globals_css_path: string | null;
134
+ css_token_files: string[];
135
+ };
136
+ recursive_discovery: boolean;
137
+ tree_truncated: boolean;
138
+ parsed_theme: ParsedTheme | null;
139
+ }
140
+ export type TokenSourceKind = 'tailwind-config' | 'tailwind-v4-css' | 'style-dictionary' | 'token-json' | 'css-variables';
141
+ export interface TokenSource {
142
+ kind: TokenSourceKind;
143
+ /** Config file or representative file (GitHub tree path). */
144
+ path: string;
145
+ /** Owning workspace package name; null = repo root, no package ownership. */
146
+ packageName: string | null;
147
+ counts: {
148
+ tokens?: number;
149
+ customProperties?: number;
150
+ files?: number;
151
+ };
152
+ /** True only when values made it into parsed_theme.modes. */
153
+ parsed: boolean;
154
+ }
155
+ export type PackageRole = 'components' | 'tokens' | 'assets' | 'utilities' | 'docs' | 'unknown';
156
+ export interface PackageInfo {
157
+ name: string;
158
+ path: string;
159
+ role: PackageRole;
160
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * theme-intake — the wire contract for the `theme-intake` edge function's
3
+ * response, as consumed by the webapp.
4
+ *
5
+ * THIS FILE IS THE CONTRACT, NOT A MIRROR OF ONE FILE.
6
+ * ────────────────────────────────────────────────────
7
+ * The shape is assembled from TWO backend sources, which is why it can never be
8
+ * a byte-copy the way `run-errors.ts` is:
9
+ *
10
+ * 1. `supabase/functions/_shared/theme-parser/types.ts` — the ParsedTheme core.
11
+ * That file also declares parser INTERNALS (RawToken's full shape,
12
+ * SEMANTIC_COLOR_NAMES) which are deliberately NOT re-exported here: this
13
+ * package is installable by a contractor, so it carries the wire and
14
+ * nothing else.
15
+ *
16
+ * 2. `supabase/functions/theme-intake/index.ts` — adds three W3d fields to the
17
+ * response at the edge boundary: `tokenSources`, `packages`,
18
+ * `tokenSourcesTruncated`.
19
+ *
20
+ * Some type NAMES differ from the backend's on purpose (ColorToken →
21
+ * ParsedThemeColor, etc.); the FIELD names are what must stay in lockstep,
22
+ * because those are what cross the wire.
23
+ *
24
+ * ENFORCEMENT. `scripts/check-canonical-sync.mjs` asserts structurally that
25
+ * ParsedTheme here declares every field of the canonical ParsedTheme plus
26
+ * exactly the W3d extension fields. It runs in the monorepo merge gate and again
27
+ * in the publisher workflow at the pinned SHA before publishing.
28
+ *
29
+ * HISTORY. Until #591 this lived at `webapp/src/types/theme-intake.ts` with a
30
+ * `vendor-sync.config.json` pair pointing only at source (1). #591 moved webapp/
31
+ * to usefidel/fidel-web and the pair was deleted rather than migrated, leaving
32
+ * the contract spanning two repositories with nothing checking it. Recorded as
33
+ * `theme-intake-wire-contract-unguarded` (#601); this file closes it.
34
+ */
35
+ export {};
package/package.json CHANGED
@@ -7,8 +7,8 @@
7
7
  "The source of truth still lives in the monorepo at packages/contracts/."
8
8
  ],
9
9
  "name": "@usefidel/contracts",
10
- "version": "0.1.0",
11
- "description": "Shared, code-free contracts between Fidel surfaces. Run-error taxonomy only.",
10
+ "version": "0.3.0",
11
+ "description": "Shared, code-free contracts between Fidel surfaces. Run-error taxonomy and theme-intake wire types.",
12
12
  "license": "UNLICENSED",
13
13
  "private": false,
14
14
  "type": "module",
@@ -23,6 +23,10 @@
23
23
  "./run-errors": {
24
24
  "types": "./dist/run-errors.d.ts",
25
25
  "import": "./dist/run-errors.js"
26
+ },
27
+ "./theme-intake": {
28
+ "types": "./dist/theme-intake.d.ts",
29
+ "import": "./dist/theme-intake.js"
26
30
  }
27
31
  },
28
32
  "files": [