Repository navigation
Conversation
Add a shared rewrite-rule directory so users can publish and adopt
request rewrite rules without installing anything: anonymous publish,
ranked by usage count.
- contracts: SharedRewriteRule payload/record schemas, list/get/publish/
use input schemas, sort enum, size limits, and a stage guard that
rejects rules carrying response-stage actions.
- apis worker: D1-backed registry (schema.sql + registry/*) exposing
POST /v1/rules/{list,get,publish,use}. Id is a content signature
(canonical JSON -> sha256) so publishing the same rule is an idempotent
upsert; only the `use` path increments usage_count. DB is optional:
when the binding is missing the worker degrades to not_configured (500)
instead of crashing, so the worker can ship before D1 is provisioned.
- core: outbound client + management service + route
POST /api/shared-rewrite-rule/{list,get,publish,use}; adopting a rule
creates a local rule with source 'imported' and best-effort usage bump.
- console: /shared-rules page (search, popular/recent sort, adopt), a
Share action on the local rules table, i18n catalogs, routing + nav.
- docs: apps/docs/specs/shared-rewrite-rules.md final-state spec.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
osw-apis | d9fb3b2 | Oct 04 2026, 02:09 AM |
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #53: a shared rewrite-rule directory on top of the existing
apps/apisCloudflare Worker. Users can publish request rewrite rules anonymously and adopt them without installing anything — save and it just works. Lists are ranked by usage count.Closes #53.
What changed
Contracts (
packages/contracts/source/shared-rewrite-rules.ts)SharedRewriteRulePayloadSchema(.strict()),SharedRewriteRuleSchema(record: +id/usageCount/createdTime/updatedTime).SharedRewriteRuleSortSchema(popular|recent), size/limit/length constants, and a stage guardsharedRewriteRuleDisabledReason()that rejects payloads carrying response-stage actions.Worker (
apps/apis)schema.sqlD1 tableshared_rewrite_ruleswithidx_shared_rewrite_rules_usage(usage DESC, updated DESC) andidx_shared_rewrite_rules_recent(updated DESC).source/registry/*: POST/v1/rules/{list,get,publish,use}. The recordidis a content signature (canonical JSON -> sha256,sha256:<hex>) so re-publishing the same rule is an idempotent upsert. Only theusepath incrementsusage_count.Core relay (
packages/core/source/management/shared-rules/*)getSettings().telemetryEndpoint, 404 ->RESOURCE_NOT_FOUND, non-2xx ->UPSTREAM_ERROR, 10s timeout) + management service + routePOST /api/shared-rewrite-rule/{list,get,publish,use}.publishRuleToDirectory(ruleId)is stage-gated (RESPONSE_REWRITE_DISABLED400).adoptSharedRule(id)creates a local rule withsource: 'imported',enabled: trueand best-effort bumps remote usage.Console (
packages/console)/shared-rulespage (search, popular/recent sort, adopt button) under the advanced nav section; a Share action on the local rules table; i18n catalogs (ui.en.ts/ui.zh-CN.ts).Docs
apps/docs/specs/shared-rewrite-rules.md— final-state spec (contract, relay, storage, deployment).Autonomous decisions
not_configured(500) instead of crashing, so the Worker can ship before D1 is provisioned.Deployment (manual, not done here)
wrangleris not authenticated in this environment, so D1 was not provisioned and the Worker was not deployed. Before deploying the Worker release:wrangler d1 create osw-shared-rulesapps/apis/wrangler.toml(currently the placeholderREPLACE_WITH_D1_DATABASE_ID).wrangler d1 execute osw-shared-rules --remote --file apps/apis/schema.sqlwrangler deployIf steps 1–3 are skipped, the endpoints respond
not_configuredbut the rest of the Worker is unaffected.Verification
typecheck— passeslint— pass (includes i18n / boundary / package-boundary rules)vitest— 215 files / 2618 tests pass (baseline was 194 files / 2298 tests)No version numbers were touched; this is not a release.