@redocly/config-rules-builder 0.0.0-stage → 0.0.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 (3) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +142 -2
  3. package/package.json +68 -3
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright 2022 (C) Redocly Inc, all rights reserved.
2
+
3
+ See license agreement here: https://redocly.com/subscription-agreement/
package/README.md CHANGED
@@ -1,3 +1,143 @@
1
- # Temporary Holding Version
1
+ # @redocly/config-rules-builder
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Visual, two-panel builder for [Redocly configurable rules](https://redocly.com/docs/cli/rules/configurable-rules)
4
+ (`rule/*` entries in `redocly.yaml`). Build a rule with sentence-style form controls on the left
5
+ and instantly see which nodes of a real OpenAPI document it matches, and which of them fail the
6
+ assertions, on the right.
7
+
8
+ ```
9
+ ┌──────────────────────────────┬───────────────────────────────┐
10
+ │ Rule cards (collapsible) │ OpenAPI document editor │
11
+ │ subject / where / assertions │ matched nodes highlighted, │
12
+ │ message / suggest / severity │ failures underlined + tooltip │
13
+ │ import rules · redocly.yaml ├───────────────────────────────┤
14
+ │ export · add rule │ Problems (click to jump) │
15
+ └──────────────────────────────┴───────────────────────────────┘
16
+ ```
17
+
18
+ ## Features
19
+
20
+ - **Real lint engine.** Rules are evaluated by `@redocly/openapi-core` in the browser, so results
21
+ match `redocly lint` exactly.
22
+ - **Live matching.** Nodes matched by the selected rule are highlighted in the document. When the
23
+ rule targets a property (`subject.property`), only that property is highlighted. The
24
+ `N nodes matched` badge is a button: each click scrolls to the next match.
25
+ - **Inline problems.** Failing assertions get a squiggly underline with a hover tooltip, a gutter
26
+ marker, and an entry in the Problems list that jumps to the location.
27
+ - **Import and export.** Paste an existing `redocly.yaml`, or copy and download the generated one.
28
+ - **Bring your own document.** Upload any OpenAPI file (YAML or JSON, up to 2 MB) or edit the
29
+ sample in place.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ npm install @redocly/config-rules-builder
35
+ ```
36
+
37
+ Peer dependencies: `react` ≥18, `react-dom` ≥18, `styled-components` ≥6.
38
+
39
+ The package ships **ESM only**. `styled-components` v6 has no `exports` map, so a CJS build would
40
+ resolve its broken CJS entry in Node. Any modern bundler (Vite, webpack 5, esbuild) and Node ESM
41
+ consumers work; `require()` is not supported.
42
+
43
+ ## Usage
44
+
45
+ ```tsx
46
+ import { RulesBuilder } from '@redocly/config-rules-builder';
47
+
48
+ export function ConfigRulesBuilderPage() {
49
+ return <RulesBuilder />;
50
+ }
51
+ ```
52
+
53
+ The component is self-contained: it ships with a sample OpenAPI document, a demo rule, and
54
+ copy/download buttons for the generated `redocly.yaml` snippet. Pass `onRuleChange` to receive the
55
+ snippet in the host app; see [Props](#props).
56
+
57
+ ### Server-side rendering
58
+
59
+ CodeMirror and the lint engine are browser-only. When the host framework renders on the server
60
+ (for example a Realm or Next.js page), mount the component after hydration:
61
+
62
+ ```tsx
63
+ import { useEffect, useState } from 'react';
64
+ import { RulesBuilder } from '@redocly/config-rules-builder';
65
+
66
+ export default function RulesBuilderPage() {
67
+ const [isClientSide, setIsClientSide] = useState(false);
68
+ useEffect(() => setIsClientSide(true), []);
69
+
70
+ return isClientSide ? <RulesBuilder /> : <div style={{ minHeight: 640 }} />;
71
+ }
72
+ ```
73
+
74
+ The lint engine imports Node's `path` module. Bundlers that target the browser need it aliased to
75
+ `path-browserify` (Realm's client build already does this).
76
+
77
+ ### Props
78
+
79
+ All props are optional.
80
+
81
+ | Prop | Type | Default | Description |
82
+ | --- | --- | --- | --- |
83
+ | `defaultSpec` | `string` | Redocly Museum API | OpenAPI document shown initially |
84
+ | `defaultSpecFileName` | `string` | `museum-api.yaml` | File name shown above the editor |
85
+ | `initialRule` | `ConfigurableRule` | `Operation.summary` defined + `maxLength: 20` | Rule loaded into the first card |
86
+ | `initialRuleName` | `string` | `operation-summary` | Name of the first rule (`rule/<name>`) |
87
+ | `onRuleChange` | `(yaml: string, rules: NamedRule[]) => void` | | Called with the generated `redocly.yaml` snippet and the normalized rules on every change |
88
+ | `host` | `HostAdapters` | browser APIs | Environment integrations, see [Host adapters](#host-adapters) |
89
+ | `height` | `number` | `640` | Height of the two-panel area in px. Below 1024px the panels stack and auto-size |
90
+
91
+ ### Theming
92
+
93
+ Styling is fully scoped via `styled-components`: no global styles and no CSS framework, so the
94
+ component can be dropped into pages with their own global CSS. Colors and fonts default to
95
+ `@redocly/theme` CSS variables (`--color-primary-base`, `--font-family-base`, and so on) with
96
+ hard-coded fallbacks, so the component looks right inside Redocly products and standalone alike.
97
+ To restyle it, define those CSS variables on an ancestor element.
98
+
99
+ ### Host adapters
100
+
101
+ `host` swaps browser defaults for environment-specific integrations, for example inside a VS Code
102
+ webview:
103
+
104
+ | Adapter | Default | Used by |
105
+ | --- | --- | --- |
106
+ | `copyToClipboard(text)` | `navigator.clipboard.writeText` | Copy button in the `redocly.yaml` preview |
107
+ | `downloadFile(fileName, content)` | Blob download | Download button in the `redocly.yaml` preview |
108
+ | `pickSpecFile()` | `<input type="file">` | Upload button above the OpenAPI editor |
109
+
110
+ ### Other exports
111
+
112
+ Besides the component, the package exports its building blocks:
113
+
114
+ - `evaluateRules(specText, rules, fileName?)` runs the lint engine and returns matched nodes and
115
+ problems.
116
+ - `serializeRules(rules)` and `parseImportedRules(yaml)` convert between `NamedRule[]` and a
117
+ `redocly.yaml` snippet.
118
+ - `DEFAULT_SPEC` is the bundled Museum API sample.
119
+ - All public types: `RulesBuilderProps`, `ConfigurableRule`, `NamedRule`, `HostAdapters`,
120
+ `EvaluationResult`, `MatchedNode`, `ProblemInfo`, and the rule-shape types.
121
+
122
+ ## Development
123
+
124
+ This package lives in the Redocly monorepo. From `packages/config-rules-builder`:
125
+
126
+ ```bash
127
+ pnpm run dev # demo app at http://localhost:5199
128
+ pnpm run test # unit tests (Vitest)
129
+ pnpm run build # library build to dist/ (ESM bundle + .d.ts)
130
+ pnpm run ts:check # type-check
131
+ ```
132
+
133
+ CI runs `lint`, `ts:check`, `build`, and `vitest:test` through Nx, so
134
+ `pnpm nx run @redocly/config-rules-builder:lint` mirrors what the pipeline does.
135
+
136
+ ## Release
137
+
138
+ Versioning and npm releases use [Changesets](https://github.com/changesets/changesets). Run
139
+ everything from the monorepo root.
140
+
141
+ 1. Add a changeset with `pnpm run changeset:common` and include `@redocly/config-rules-builder`.
142
+ 2. Merge the PR with the changeset into `main`.
143
+ 3. Release automation opens a version PR; merging it publishes the package to npm.
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@redocly/config-rules-builder",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "Visual builder for Redocly configurable rules (rule/*) with live matching against an OpenAPI document",
5
+ "keywords": [
6
+ "redocly",
7
+ "openapi",
8
+ "lint",
9
+ "configurable-rules",
10
+ "react",
11
+ "editor"
12
+ ],
13
+ "author": "team@redocly.com",
14
+ "license": "SEE LICENSE IN LICENSE",
15
+ "type": "module",
16
+ "main": "./dist/config-rules-builder.js",
17
+ "module": "./dist/config-rules-builder.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/config-rules-builder.js"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "sideEffects": false,
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "@codemirror/commands": "^6.9.0",
35
+ "@codemirror/lang-yaml": "^6.1.2",
36
+ "@codemirror/language": "^6.11.3",
37
+ "@codemirror/state": "^6.5.2",
38
+ "@codemirror/view": "^6.25.1",
39
+ "@redocly/openapi-core": "2.62.1",
40
+ "js-yaml": "4.3.2",
41
+ "yaml-ast-parser": "0.0.43"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=18",
45
+ "react-dom": ">=18",
46
+ "styled-components": ">=6"
47
+ },
48
+ "devDependencies": {
49
+ "@types/js-yaml": "4.0.9",
50
+ "@types/react": "^19.2.7",
51
+ "@types/react-dom": "^19.2.3",
52
+ "@vitejs/plugin-react": "6.0.1",
53
+ "path-browserify": "^1.0.1",
54
+ "react": "^19.2.7",
55
+ "react-dom": "^19.2.7",
56
+ "styled-components": "^6.4.2",
57
+ "typescript": "6.0.3",
58
+ "vite": "8.3.3",
59
+ "vite-plugin-dts": "4.5.4",
60
+ "vitest": "4.1.11"
61
+ },
62
+ "scripts": {
63
+ "clean": "rm -rf dist dist-demo",
64
+ "build": "pnpm run clean && vite build",
65
+ "dev": "vite --config vite.demo.config.ts",
66
+ "build:demo": "vite build --config vite.demo.config.ts",
67
+ "preview": "vite preview --config vite.demo.config.ts",
68
+ "test": "vitest run",
69
+ "ts:check": "tsc --noEmit"
70
+ }
6
71
  }