Skip to content

Conversation

@cdrubin
Copy link
Collaborator

@cdrubin cdrubin commented Jan 27, 2026

  • Add granular applications list component
  • improve error handling of product availability component and add parentheses handling,
  • Remove partial for granular controls list
  • add better use of zod and typescript in middlecache-based content collections

…roduct availability component and add parentheses handling, remove partial for granular controls list
@github-actions
Copy link
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
*.astro @cloudflare/content-engineering, @kodster28
*.ts @cloudflare/content-engineering, @kodster28
/src/content/docs/cloudflare-one/traffic-policies/ @maxvp, @cloudflare/pcx-technical-writing
/src/content/docs/rules/ @pedrosousa, @cloudflare/pcx-technical-writing
* @cloudflare/pcx-technical-writing

display_id: display_id,
applications: item.applications,
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What you're looking for here is a reduce

const lookup = data.reduce(
    (acc, item) => {
        // do stuff
        return {...acc, newEntry}
    }, 
    {} as Record<string, GranularControlApplication>
)

Copy link
Collaborator Author

@cdrubin cdrubin Jan 30, 2026

Choose a reason for hiding this comment

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

I have recently started to use less of the map and reduce functions than previously. I don't find them as easy to read as the explicit actions in a loop and for the work being done here readability is a stronger consideration I think.

> = {
loader: middlecacheLoader("v1/application-controls/applications.json", {
parser: (fileContent: string) => {
const data = JSON.parse(fileContent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you confirm that this fileContent string will match the zod schema in this unconventional loader pattern? Will you need to use zod to validate this string? I think Astro will apply the schema against the the lookup value you return, but are you guaranteed that this data is a valid of array of X?

(I say X because I think it wouldn't match the schema you gave Astro but some other schema. And now that I type that out I'm guessing that Astro is not validating this string since you would need to provide two schemas, right?)

Copy link
Collaborator Author

@cdrubin cdrubin Jan 30, 2026

Choose a reason for hiding this comment

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

Astro is validating the data in fileContent against schema provided and, if there are issues throws a [InvalidContentEntryDataError] product-availability → XXX data does not match collection schema for that array item

for (const item of data) {
const display_id = item.category
.split("-")
.map((w: string) => w[0].toUpperCase() + w.substring(1).toLowerCase())
Copy link
Collaborator

Choose a reason for hiding this comment

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

You had to manually specify string here? It wasn't able to infer that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I think that's because you need a second schema. So it makes sense that at this point in the flow it doesn't know that category is a string.

Some of that is semantic "make TS happy" but the reason TS isn't happy is because you have a potential bug here. If the thing you write to the file isn't in the right shape, then this code will fail. There's no check that category exists and is a string. There's also no check that item.applications exists, but I think when Astro checks the resulting lookup that would effectively get checked.

(There's also no check that w has a length > 2, but TS wouldn't save you there.)

My original recommendation of using a standard pattern for object loader still applies. But if we're too far down this path, I think you'll want more validation.

…gory display name generation function for granular application control applications
@cdrubin cdrubin merged commit 7eed161 into production Jan 30, 2026
9 checks passed
@cdrubin cdrubin deleted the cefan/application_control_list_component branch January 30, 2026 13:52
cdrubin added a commit that referenced this pull request Jan 30, 2026
* Add granular applications list component, improve error handling of product availability component and add parentheses handling, remove partial for granular controls list

* Improve compliance with possible return values from Astro loader custom parser

* Improved use of Typescript and zod for typing and more resilient category display name generation function for granular application control applications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants