Skip to content

Commit

Permalink
updated to use isbeta
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Feb 20, 2024
1 parent 447cb30 commit 5e81ba8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1,305 deletions.
1 change: 0 additions & 1 deletion policies/custom-code-inbound/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"$id": "http://zuplo.com/schemas/policies/custom-code-inbound.json",
"type": "object",
"title": "Custom Code Inbound",
"isPreview": false,
"description": "Enables a custom code policy written in TypeScript. Change YOUR_MODULE to the name of your module (without .ts extension)",
"required": ["handler"],
"properties": {
Expand Down
1 change: 0 additions & 1 deletion policies/custom-code-outbound/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"$id": "http://zuplo.com/schemas/policies/custom-code-outbound.json",
"type": "object",
"title": "Custom Code Outbound",
"isPreview": false,
"description": "A custom outbound response policy.",
"required": ["handler"],
"properties": {
Expand Down
1,189 changes: 0 additions & 1,189 deletions policies/transform-body-inbound/policies.v3.json

This file was deleted.

113 changes: 8 additions & 105 deletions scripts/update-policies.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { dereference } from "@apidevtools/json-schema-ref-parser";
import chalk from "chalk";
import { existsSync } from "fs";
import { copyFile, mkdir, readFile, writeFile } from "fs/promises";
import { mkdir, readFile, writeFile } from "fs/promises";
import { glob } from "glob";
import { JSONSchema7, JSONSchema7Definition } from "json-schema";
import { JSONSchema7 } from "json-schema";
import type { Heading as AstHeading } from "mdast";
import { toString } from "mdast-util-to-string";
import path from "path";
Expand All @@ -23,7 +23,7 @@ type SchemaRecord = {
};

type PolicySchema = JSONSchema7 & {
isPreview?: boolean;
isBeta?: boolean;
isDeprecated?: boolean;
isInternal?: boolean;
isPaidAddOn?: boolean;
Expand Down Expand Up @@ -138,88 +138,6 @@ function isObjectSchema(val: unknown): asserts val is object {
}
}

function Heading3({ title, id }: { title: string; id: string }) {
return (
<h3
className="anchor anchorWithStickyNavbar_node_modules-@docusaurus-theme-classic-lib-theme-Heading-styles-module"
id={id}
>
{title}
<a
href={`#${id}`}
className="hash-link"
aria-label={`Direct link to ${title}`}
title={`Direct link to ${title}`}
>
</a>
</h3>
);
}

const PolicyOptions = ({
schema,
policyId,
}: {
schema: JSONSchema7Definition;
policyId: string;
}) => {
isObjectSchema(schema);
const { handler } = schema.properties!;
isObjectSchema(handler);
const { properties } = handler;
const { module: handlerModule, export: handlerExport, options } = properties!;
isObjectSchema(handlerModule);
isObjectSchema(handlerExport);
return (
<div>
<Heading3 title="Policy Configuration" id="policy-configuration" />
<ul>
<li>
<code>name</code> <span className="type-option">{"<string>"}</span> -
The name of your policy instance. This is used as a reference in your
routes.
</li>
<li>
<code>policyType</code>{" "}
<span className="type-option">{"<string>"}</span> - The identifier of
the policy. This is used by the Zuplo UI. Value should be{" "}
<code>{policyId}</code>.
</li>
<li>
<code>handler.export</code>{" "}
<span className="type-option">{"<string>"}</span> - The name of the
exported type. Value should be{" "}
<code>{handlerExport.const!.toString()}</code>.
</li>
<li>
<code>handler.module</code>{" "}
<span className="type-option">{"<string>"}</span> - The module
containing the policy. Value should be{" "}
<code>{handlerModule.const!.toString()}</code>.
</li>
{options && Object.keys(options).length > 0 ? (
<li>
<code>handler.options</code>{" "}
<span className="type-option">{"<object>"}</span> - The options for
this policy. <a href="#policy-options">See Policy Options</a> below.
</li>
) : null}
</ul>
{options && Object.keys(options).length > 0 ? (
<>
<Heading3 title="Policy Options" id="policy-options" />
<p>
The options for this policy are specified below. All properties are
optional unless specifically marked as required.
</p>
<OptionProperty schema={options as JSONSchema7} />
</>
) : null}
</div>
);
};

const docsDir = path.resolve(
process.cwd(),
isNext ? "./src/app/policies" : "./docs/policies",
Expand Down Expand Up @@ -318,6 +236,8 @@ function getPolicyFilePaths(policyDir) {
};
}

<<<<<<< HEAD
=======
async function generateMarkdown(
policyId: string,
schema: PolicySchema,
Expand Down Expand Up @@ -405,7 +325,7 @@ This policy is deprecated. ${schema.deprecatedMessage ?? ""}
${introMd ?? schema.description}
<!-- end: intro.md -->
<PolicyStatus isPreview={${schema.isPreview ?? false}} isPaidAddOn={${
<PolicyStatus isBeta={${schema.isBeta ?? false}} isPaidAddOn={${
schema.isPaidAddOn ?? false
}} />
Expand Down Expand Up @@ -436,6 +356,7 @@ Read more about [how policies work](/docs/articles/policies)
`;
}

>>>>>>> parent of 447cb30 (Revert "Support beta policies")
export async function run() {
console.log("Generating policies");
// await rm(docsDir, { recursive: true, force: true });
Expand Down Expand Up @@ -471,7 +392,7 @@ export async function run() {
// Build the meta format for use in the portal
const meta: Record<string, any> = {};
meta.name = schema.title;
meta.isPreview = !!schema.isPreview;
meta.isBeta = !!schema.isBeta;
meta.isPaidAddOn = !!schema.isPaidAddOn;
meta.isCustom = !!schema.isCustom;
meta.isDeprecated = !!schema.isDeprecated;
Expand Down Expand Up @@ -532,28 +453,10 @@ export async function run() {
}

policies.push(meta);

const generatedMd = await generateMarkdown(
policyId,
schema,
policyFilePaths,
);

const outPath = isNext
? path.join(docsDir, policyId, `page.md`)
: path.join(docsDir, `${policyId}.md`);
const outdir = path.dirname(outPath);
await mkdir(outdir, { recursive: true });
await writeFile(outPath, generatedMd, "utf-8");
});

await Promise.all(tasks);

await copyFile(
path.resolve(policiesDir, "index.md"),
path.resolve(docsDir, "index.md"),
);

const policyDataV3 = {
config: policyConfig,
policies,
Expand Down
2 changes: 1 addition & 1 deletion src/app/policies/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
) : null}
{intro}
<PolicyStatus
isPreview={schema.isPreview ?? false}
isBeta={schema.isBeta ?? false}
isPaidAddOn={schema.isPaidAddOn ?? false}
/>
{schema.isCustom && files.policyTs ? (
Expand Down
13 changes: 6 additions & 7 deletions src/components/policies/PolicyStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Callout from "@/components/markdown/Callout";

export default function PolicyStatus({
isPreview,
isBeta,
isPaidAddOn,
}: {
isPreview: boolean;
isBeta: boolean;
isPaidAddOn: boolean;
}) {
if (isPaidAddOn) {
Expand All @@ -20,14 +20,13 @@ export default function PolicyStatus({
</div>
);
}
if (isPreview) {
if (isBeta) {
return (
<div>
<Callout type="caution" title="Early Access">
<Callout type="caution" title="Beta">
<p>
This policy is in private beta. If you would like to use this please
reach out to us:{" "}
<a href="mailto:[email protected]">[email protected]</a>
This policy is in beta. You can use it today, but it may change in
non-backward compatible ways before the final release.
</p>
</Callout>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type NavItem = {
export interface Policy {
policyId: string;
schema: JSONSchema7 & {
isPreview?: boolean;
isBeta?: boolean;
isCustom?: boolean;
isDeprecated?: false;
isPaidAddOn?: false;
Expand Down

0 comments on commit 5e81ba8

Please sign in to comment.