Skip to content

feat(cloud-registry): validate form like the API - #510

Closed
uniqueg wants to merge 12 commits into
devfrom
feat/create-form-validation
Closed

uniqueg wants to merge 12 commits into
devfrom
feat/create-form-validation

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

The create form now checks its fields the way Cloud Registry 0.6.0 checks registrations (ExternalServiceRegister, FOCA's check_url()), so that users see what the API would reject with 400 at the field, while they type, instead of a generic error after submitting.

  • New module src/components/service-create/validation.ts: maximum lengths (code points, as the registry counts them), URL checks (schemes, host, user info, whitespace and control characters, characters that must be percent-encoded, malformed percent-encodings, IPv4/IPv6 hosts including zone IDs, mailto: contact URLs with email addresses), RFC 3339 date-times, unpaired surrogates, and reserved custom service IDs (., .., types, slashes, commas, line breaks).
  • New property urlSchemes / attribute url-schemes (comma- or space-separated). The registry's registration_rules.url_schemes from GET /service-info takes precedence; the default is https. Organization and documentation URLs allow http and https; contact URLs also allow mailto:.
  • Errors show under the fields (aria-live="polite"), and fields get aria-invalid with a red border. Missing required fields are flagged only after a submission was tried, until the form is reset.
  • On submit with blocking errors, the form sends nothing, expands "Advanced Configuration" if one of its fields is invalid, shows a note at the button, and fires ecc-service-create-validation-failed with { error, errors } (errors maps input IDs to messages; the event type is updated).
  • Invalid timestamps are flagged but don't block, because the registry ignores timestamps unless an admin sends them.
  • The create button also needs the type group.
  • Docs: a Validation section, urlSchemes, and the event table.

The registry still has the final say. Rare cases can slip through, e.g. international domain names that browsers accept (UTS 46) but IDNA 2008 rejects; the registry then reports them through ecc-service-create-failed.

Stacked on #505 (configurable environments). Review it after #505; GitHub shows #505's commits until that one is merged.

Closes #453

Verification

  • npx tsc -p tsconfig.prod.json: passes.
  • npm run build (package): passes.
  • npm run lint (pre-commit, whole repo): passes; only the warnings that were already there.
  • Differential test of checkUrl() against the registry's Python reference (174 URLs): no false rejections. The only remaining differences are IDNA leniency (see above).
  • Playwright checks against the built component, using a mock provider. They are run by hand (check-453-validation.mjs, about 80 assertions: every rule above, submission blocking, the event, the advanced section opening, non-blocking timestamps, registry rules versus the property) and check-461-environments.mjs: all pass.
  • Automated tests aren't possible yet: the package has no test setup on dev (test: set up unit, integration and e2e tests #484). fix(cloud-registry): react to provider changes #502 adds a WTR setup, and once it lands these checks can become tests there.
  • CI: all checks pass (Lint, Test on Node 22 and 24, Conflict markers, PR title, Read the Docs).

Declined review findings

  • aria attributes don't reach the inner <input>: the design components don't forward aria-invalid and aria-describedby. This needs a change in @elixir-cloud/design and belongs in a follow-up. The attributes are set on the host elements, aria-describedby only when there is an error, and the messages are announced through aria-live.
  • Declarative field table instead of per-field calls: the fields differ too much (schemes, mailto:, trimming, required). A table would add indirection without making the code shorter.
  • URL lengths checked twice (in the length check and in checkUrl()): this is harmless, because the first message of a field wins, and it keeps checkUrl() self-contained.
  • Collapsible trigger aria-expanded doesn't update: the cause is in @elixir-cloud/design, not in this change. It goes into the same follow-up as the aria forwarding.
  • IDNA 2008 strictness: browsers implement UTS 46 only. Matching IDNA 2008 exactly would need a library. The registry rejects these rare cases itself.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Align the Cloud Registry service creation form with API registration rules and provide actionable validation feedback before submission.

New Features:

  • Add Cloud Registry registration validation to the service creation form, including field-level URL, length, timestamp, identifier, and character checks.
  • Support registry-provided or configured URL schemes and environment options, including free-text environments when any value is allowed.
  • Expose detailed validation errors through the updated ecc-service-create-validation-failed event.

Bug Fixes:

  • Prevent submissions that contain blocking validation errors and identify the affected fields before the API request is made.

Enhancements:

  • Improve form feedback with inline error messages, invalid styling, submission guidance, and automatic expansion of advanced fields containing errors.
  • Require the service type group in the create form.
  • Add provider types for Cloud Registry registration rules and use service-info rules when configuring the form.

Documentation:

  • Document environment configuration, URL schemes, validation behavior, registry registration rules, and the expanded validation event detail.

uniqueg and others added 8 commits October 28, 2026 21:11
Offer the environments that the registry allows: the create form reads
`registration_rules.environments` from `GET /service-info` (Cloud
Registry 0.6.0 and later). For registries and providers without these
rules, the new property `environments` (values or `{ value, label }`)
applies; its default is today's `prod`, `test`, `dev` and `staging`. An
empty list allows any value, with a text field. A chosen environment
that is no longer offered is cleared. Export the types
`RegistrationRules` and `RegistryServiceInfo`.

Closes #461.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ignore outdated answers for the registration rules and log failures,
check the property (it may come from JSON), drop empty and duplicate
values, use a generic placeholder for free text, and document the
provider types and the attribute.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Show the free-text environment field only if the registry or the
property allows any value (an empty list), not when a list has no valid
entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Declare `getServiceInfo()` of `CloudRegistryProvider` and
`RestCloudRegistryProvider` with `RegistryServiceInfo`, so that
consumers can read the registration rules without a cast, and warn of
invalid environments in the rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check the fields of the create form as Cloud Registry checks
registrations, and show errors at the fields while users type: URLs
(schemes, host, user info, characters, percent-encodings; mailto: for
contact URLs), maximum lengths, RFC 3339 timestamps and custom IDs.
Service URLs must use the schemes that the registry publishes
(`registration_rules.url_schemes`), else those of the new property
`urlSchemes` (default `https`). Invalid submissions send nothing and
fire `ecc-service-create-validation-failed` with all messages.

Closes #453.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Compute the errors once per render, reference error messages only when
shown and announce them politely, add the errors by field to
`ecc-service-create-validation-failed`, accept URL schemes in any case,
write invisible characters as escapes, and clarify the docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Don't block on timestamps (the registry ignores them of non-admins),
expand the advanced section and show a note at the button on failed
submissions, and require the type group for the create button. Check
mailto: parts separately (fragments allowed) and addresses as written,
accept IPv4 hosts with a trailing dot and IPv6 zone IDs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Share the blocking-field logic and the HTTP schemes, clarify the
fieldErrors() contract and the docs on timestamps and urlSchemes, put
examples in messages in parentheses, and keep numeric last labels of
international mailto: domains from being parsed as IPv4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR adds registry-compatible, field-level validation to the Cloud Registry service creation form, including detailed URL and timestamp checks, blocking submission behavior, accessible error presentation, and an expanded validation event. It also makes URL schemes and environments registry-configurable via service-info registration rules with property fallbacks, updates provider/event types, and documents the new behavior.

Sequence diagram for registry-aware service creation validation

sequenceDiagram
    participant User
    participant Form as ServiceCreateForm
    participant Provider as CloudRegistryProvider
    participant Registry as CloudRegistry

    Form->>Provider: getServiceInfo()
    Provider->>Registry: GET /service-info
    Registry-->>Provider: RegistryServiceInfo.registration_rules
    Provider-->>Form: RegistryServiceInfo
    Form->>Form: fieldErrors(true)
    Form->>Form: blockingFields(errors)
    alt blocking errors exist
        Form->>Form: advancedOpen = true when needed
        Form-->>User: Render field errors and submission note
        Form-->>User: aria-invalid and aria-live messages
        Form-->>User: ecc-service-create-validation-failed
    else only timestamp errors or no errors
        Form->>Provider: Create service request
        Provider->>Registry: Submit registration
        Registry-->>Provider: Created or rejected
        Provider-->>Form: Result
    end
Loading

File-Level Changes

Change Details Files
Added client-side validation matching Cloud Registry 0.6.0 registration checks.
  • Implemented code-point length limits, URL parsing and character checks, host/IP validation, mailto validation, RFC 3339 timestamps, surrogate detection, and custom service ID restrictions.
  • Separated blocking field errors from non-blocking timestamp errors.
  • Added focused validation utilities for reuse by the form.
packages/ecc-client-elixir-cloud-registry/src/components/service-create/validation.ts
packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts
Integrated live validation and submission behavior into the service creation form.
  • Display per-field errors while typing, mark invalid fields, and reveal advanced configuration when it contains blocking errors.
  • Delay required-field errors until the first submission attempt and clear validation state on reset.
  • Prevent requests with blocking errors and emit the expanded validation-failed event payload; retain timestamp errors as non-blocking.
  • Require the service type group in the create-button gating logic.
packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts
packages/ecc-client-elixir-cloud-registry/src/events/ecc-service-create-validation-failed.ts
Added registry-driven URL scheme and environment configuration with property fallbacks.
  • Load registration rules from service info and ignore stale asynchronous responses.
  • Use registry URL schemes and environments when published, otherwise use component properties or defaults.
  • Support comma/space-separated url-schemes attributes and dynamic select versus free-text environment fields.
packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts
packages/ecc-client-elixir-cloud-registry/src/providers/cr-provider.ts
packages/ecc-client-elixir-cloud-registry/src/providers/rest-cr-provider.ts
packages/ecc-client-elixir-cloud-registry/src/providers/index.ts
Documented validation behavior, configurable properties, registry rules, and event changes.
  • Documented urlSchemes and environments precedence and attribute formats.
  • Added validation rules, blocking semantics, timestamp exceptions, and registry fallback behavior.
  • Updated provider interfaces and validation-failed event details.
apps/documentation/pages/docs/cloud-registry/components/service-create.mdx
apps/documentation/pages/docs/cloud-registry/providers.mdx

Assessment against linked issues

Issue Objective Addressed Explanation
#453 Validate create-form inputs against Cloud Registry rules, including required fields, URL syntax and allowed schemes, maximum lengths, custom service IDs, and RFC 3339 timestamps; display field-specific errors and prevent submission when blocking errors are present. ✅
#453 Allow the form to use the registry’s published service-URL schemes, with a configurable url-schemes property and an https default when registry rules are unavailable. ✅
#453 On blocked submission, send no request and fire ecc-service-create-validation-failed with field-specific errors. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

@uniqueg
uniqueg marked this pull request as ready for review October 29, 2026 01:50
@uniqueg
uniqueg requested a review from anuragxxd as a code owner October 29, 2026 01:50

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts" line_range="281-284" />
<code_context>
+    }
+    this.registryEnvironments = valid ? (environments as string[]) : null;
+    this.registryUrlSchemes =
+      Array.isArray(urlSchemes) &&
+      urlSchemes.length > 0 &&
+      urlSchemes.every((value) => HTTP_SCHEMES.includes(value))
+        ? urlSchemes
+        : null;
+  }
</code_context>
<issue_to_address>
**Uppercase schemes are rejected**

When `registration_rules.url_schemes` contains an uppercase or mixed-case HTTP scheme, `loadRegistrationRules()` compares schemes case-sensitively with lowercase `HTTP_SCHEMES`, discards the registry's rules, and makes the form use its property or default schemes instead of the registry's allowed schemes.

Normalize registry schemes before checking them against `HTTP_SCHEMES` and storing them.
</issue_to_address>

### Comment 2
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/validation.ts" line_range="242" />
<code_context>
+    day <= days[month - 1] &&
+    hour < 24 &&
+    minute < 60 &&
+    second <= 60 &&
+    offsetHour < 24 &&
+    offsetMinute < 60
</code_context>
<issue_to_address>
**Invalid leap seconds pass validation**

When a timestamp uses seconds `60` at a time that is not an RFC 3339 leap second, `isDateTime()` accepts the timestamp, so the form shows no warning and submits a value the registry rejects.

Accept seconds `60` only when the timestamp represents an RFC 3339 leap second.
</issue_to_address>

### Comment 3
<location path="packages/ecc-client-elixir-cloud-registry/src/components/service-create/validation.ts" line_range="172" />
<code_context>
+  for (const address of path.split(",")) {
+    const at = address.lastIndexOf("@");
+    const domain = address.slice(at + 1);
+    if (at <= 0 || address.slice(0, at).includes("@") || domain === "") {
+      return invalid;
+    }
</code_context>
<issue_to_address>
**Malformed email locals pass validation**

When a contact URL uses an invalid local part, such as consecutive dots, `checkMailto` verifies that the local part is nonempty and has no second `@`, but does not validate its syntax. Addresses such as `mailto:[email protected]` therefore pass the form check even though they are not valid email addresses, and the registry can reject them after submission.

Validate the local part against the email syntax accepted by the registry before treating a `mailto:` URL as valid.
</issue_to_address>

### Comment 4
<location path="packages/ecc-client-elixir-cloud-registry/src/providers/cr-provider.ts" line_range="103" />
<code_context>
   createOrUpdateServiceInfo?(service: ServiceRegister): Promise<void>;
+
+  // Service info, with the registration rules (Cloud Registry 0.6.0 and later)
+  getServiceInfo(): Promise<RegistryServiceInfo>;
 }
 ```
</code_context>
<issue_to_address>
**Existing providers stop type-checking**

When a custom provider explicitly types its implementation using the former `Promise<Service>` return type, an existing custom provider that declares `getServiceInfo(): Promise<Service>` no longer satisfies `CloudRegistryProvider`, because `Promise<Service>` is not assignable to `Promise<RegistryServiceInfo>`. Consumers implementing the previously documented provider contract fail to compile.

Preserve compatibility with the `Promise<Service>` contract and expose registration rules through a compatible optional extension or separate method.
</issue_to_address>

### Comment 5
<location path="apps/documentation/pages/docs/cloud-registry/providers.mdx" line_range="37" />
<code_context>
   createOrUpdateServiceInfo?(service: ServiceRegister): Promise<void>;
+
+  // Service info, with the registration rules (Cloud Registry 0.6.0 and later)
+  getServiceInfo(): Promise<RegistryServiceInfo>;
 }
 ```
</code_context>
<issue_to_address>
**Registration rules stay hidden**

When a consumer copies the documented provider interface and reads `getServiceInfo()`, the provider interface example declares `getServiceInfo()` first as `Promise<Service>` and again as `Promise<RegistryServiceInfo>`. Consumers following the snippet get the first overload's broader return type, so `registration_rules` is not available without a cast, contrary to the new documentation.

Replace the original `Promise<Service>` declaration in the example with `Promise<RegistryServiceInfo>` instead of adding a second declaration.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and when registry rules no longer include the selected environment, the form clears it before submission, so a created service can be stored without the environment the user had chosen. Reverting the form change does not restore an already-created record, though the affected registration can be corrected.

Blocking findings: packages/ecc-client-elixir-cloud-registry/src/components/service-create/service-create.ts:284, packages/ecc-client-elixir-cloud-registry/src/components/service-create/validation.ts:242, packages/ecc-client-elixir-cloud-registry/src/components/service-create/validation.ts:172, packages/ecc-client-elixir-cloud-registry/src/providers/cr-provider.ts:103, apps/documentation/pages/docs/cloud-registry/providers.mdx:37


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

uniqueg and others added 3 commits October 29, 2026 02:58
Lowercase the URL schemes published by the registry before checking
them, as schemes are case-insensitive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The provider interface example declared getServiceInfo() twice; keep
only the declaration with the registration rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts in service-create.ts and its docs: keep the
validation, environments and URL schemes; dev's provider handling (#502)
now loads the registration rules too, and resets them without a
provider. The event table takes dev's failure details (#504) and the
PR's validation details.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.65482% with 247 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.87%. Comparing base (6b15bb0) to head (84a0c88).

Files with missing lines Patch % Lines
...ry/src/components/service-create/service-create.ts 75.67% 123 Missing and 4 partials ⚠️
...gistry/src/components/service-create/validation.ts 54.19% 120 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #510      +/-   ##
==========================================
- Coverage   69.93%   69.87%   -0.07%     
==========================================
  Files          23       24       +1     
  Lines        5216     5942     +726     
  Branches      132      199      +67     
==========================================
+ Hits         3648     4152     +504     
- Misses       1566     1784     +218     
- Partials        2        6       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@uniqueg uniqueg changed the title feat(cloud-registry): validate the form like the API feat(cloud-registry): validate form like the API Oct 31, 2026
@anuragxxd

Copy link
Copy Markdown
Member

@uniqueg Thanks for this, it's very thorough work.

I'd prefer not to keep these rules in the component, though. The registry already enforces them, so that's where they should live. A client-side copy means about 600 lines we'd have to keep in step with the registry. If either side changes a rule, the two disagree, and the form blocks valid registrations or lets invalid ones through.

Could the registry instead return a stable error code and, where possible, the field name in its 400 responses? The component could then show the right message at the right field without keeping any rules of its own, just as it already takes the environments and URL schemes from GET /service-info since #505.

This PR could then become the part that shows the registry's errors at the right fields. What do you think?

@uniqueg

uniqueg commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@uniqueg Thanks for this, it's very thorough work.

I'd prefer not to keep these rules in the component, though. The registry already enforces them, so that's where they should live. A client-side copy means about 600 lines we'd have to keep in step with the registry. If either side changes a rule, the two disagree, and the form blocks valid registrations or lets invalid ones through.

Could the registry instead return a stable error code and, where possible, the field name in its 400 responses? The component could then show the right message at the right field without keeping any rules of its own, just as it already takes the environments and URL schemes from GET /service-info since #505.

This PR could then become the part that shows the registry's errors at the right fields. What do you think?

This is a great idea! I might write an issue for that and then create a new PR though, so that the provenance of that design becomes clearer.

@uniqueg

uniqueg commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@anuragxxd Thanks again, and agreed: the APIs should report invalid fields, and the components should only show them. I've written that up as fresh issues, so we start clean and the design has a clear origin:

We'll pick this up after the initial Cloud Registry deployment (backend and frontend). Until the new system is in place, the registry frontend works around the missing field errors as well as it can.

Could you review #535, and the format in elixir-cloud-aai/foca#586 as far as it concerns the components? You have the final say on how the design package should do this. If anything there doesn't fit how you'd build it, say so in the issues before anyone starts.

I'm closing this PR and #453 in favour of the new issues. The branch stays for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cloud-registry): validate the create form like the API

2 participants