@openpolicy/vite 0.0.11 → 0.0.13
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.
- package/README.md +2 -3
- package/dist/html-D0xZQ7Fi.js +39 -0
- package/dist/html-D0xZQ7Fi.js.map +1 -0
- package/dist/index.d.ts +3 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +461 -658
- package/dist/index.js.map +1 -1
- package/dist/markdown-8LgFTJSZ.js +35 -0
- package/dist/markdown-8LgFTJSZ.js.map +1 -0
- package/dist/pdf-CTsnJvZX.js +93 -0
- package/dist/pdf-CTsnJvZX.js.map +1 -0
- package/dist/rolldown-runtime-CiIaOW0V.js +13 -0
- package/package.json +3 -2
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Vite plugin for compiling [OpenPolicy](https://openpolicy.sh) policy documents at build time.
|
|
4
4
|
|
|
5
|
-
Compiles `
|
|
5
|
+
Compiles `defineConfig()` configs to Markdown or HTML automatically — on every build and on save in dev mode.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -22,7 +22,6 @@ import { openPolicy } from "@openpolicy/vite";
|
|
|
22
22
|
export default defineConfig({
|
|
23
23
|
plugins: [
|
|
24
24
|
openPolicy({
|
|
25
|
-
configs: ["privacy.config.ts", "terms.config.ts"],
|
|
26
25
|
formats: ["markdown"],
|
|
27
26
|
outDir: "public/policies",
|
|
28
27
|
}),
|
|
@@ -34,7 +33,7 @@ export default defineConfig({
|
|
|
34
33
|
|
|
35
34
|
| Option | Type | Default | Description |
|
|
36
35
|
|---|---|---|---|
|
|
37
|
-
| `
|
|
36
|
+
| `configPath` | `string` | `"openpolicy.ts"` | Path to the unified policy config file, relative to the Vite root. |
|
|
38
37
|
| `formats` | `OutputFormat[]` | `["markdown"]` | `"markdown"` or `"html"` |
|
|
39
38
|
| `outDir` | `string` | `"public/policies"` | Output directory, relative to the Vite root |
|
|
40
39
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-CiIaOW0V.js";
|
|
2
|
+
//#region ../renderers/src/html.ts
|
|
3
|
+
var html_exports = /* @__PURE__ */ __exportAll({ renderHTML: () => renderHTML });
|
|
4
|
+
function escapeHtml(str) {
|
|
5
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
6
|
+
}
|
|
7
|
+
function renderInline(node) {
|
|
8
|
+
switch (node.type) {
|
|
9
|
+
case "text": return escapeHtml(node.value);
|
|
10
|
+
case "bold": return `<strong>${escapeHtml(node.value)}</strong>`;
|
|
11
|
+
case "italic": return `<em>${escapeHtml(node.value)}</em>`;
|
|
12
|
+
case "link": return `<a href="${escapeHtml(node.href)}">${escapeHtml(node.value)}</a>`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function renderListItem(item) {
|
|
16
|
+
return `<li>${item.children.map((child) => child.type === "list" ? renderList(child) : renderInline(child)).join("")}</li>`;
|
|
17
|
+
}
|
|
18
|
+
function renderList(node) {
|
|
19
|
+
const tag = node.ordered ? "ol" : "ul";
|
|
20
|
+
return `<${tag}>${node.items.map(renderListItem).join("")}</${tag}>`;
|
|
21
|
+
}
|
|
22
|
+
function renderHTML(doc) {
|
|
23
|
+
return doc.sections.map((section) => {
|
|
24
|
+
return section.content.map((node) => {
|
|
25
|
+
switch (node.type) {
|
|
26
|
+
case "heading": {
|
|
27
|
+
const level = node.level ?? 2;
|
|
28
|
+
return `<h${level}>${escapeHtml(node.value)}</h${level}>`;
|
|
29
|
+
}
|
|
30
|
+
case "paragraph": return `<p>${node.children.map(renderInline).join("")}</p>`;
|
|
31
|
+
case "list": return renderList(node);
|
|
32
|
+
}
|
|
33
|
+
}).join("\n");
|
|
34
|
+
}).join("\n");
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { html_exports as t };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=html-D0xZQ7Fi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-D0xZQ7Fi.js","names":[],"sources":["../../renderers/src/html.ts"],"sourcesContent":["import type {\n\tDocument,\n\tInlineNode,\n\tListItemNode,\n\tListNode,\n} from \"@openpolicy/core\";\n\nfunction escapeHtml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\");\n}\n\nfunction renderInline(node: InlineNode): string {\n\tswitch (node.type) {\n\t\tcase \"text\":\n\t\t\treturn escapeHtml(node.value);\n\t\tcase \"bold\":\n\t\t\treturn `<strong>${escapeHtml(node.value)}</strong>`;\n\t\tcase \"italic\":\n\t\t\treturn `<em>${escapeHtml(node.value)}</em>`;\n\t\tcase \"link\":\n\t\t\treturn `<a href=\"${escapeHtml(node.href)}\">${escapeHtml(node.value)}</a>`;\n\t}\n}\n\nfunction renderListItem(item: ListItemNode): string {\n\tconst content = item.children\n\t\t.map((child) =>\n\t\t\tchild.type === \"list\"\n\t\t\t\t? renderList(child)\n\t\t\t\t: renderInline(child as InlineNode),\n\t\t)\n\t\t.join(\"\");\n\treturn `<li>${content}</li>`;\n}\n\nfunction renderList(node: ListNode): string {\n\tconst tag = node.ordered ? \"ol\" : \"ul\";\n\tconst items = node.items.map(renderListItem).join(\"\");\n\treturn `<${tag}>${items}</${tag}>`;\n}\n\nexport function renderHTML(doc: Document): string {\n\treturn doc.sections\n\t\t.map((section) => {\n\t\t\t// biome-ignore lint/suspicious/useIterableCallbackReturn: typed\n\t\t\tconst blocks = section.content.map((node) => {\n\t\t\t\tswitch (node.type) {\n\t\t\t\t\tcase \"heading\": {\n\t\t\t\t\t\tconst level = node.level ?? 2;\n\t\t\t\t\t\treturn `<h${level}>${escapeHtml(node.value)}</h${level}>`;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"paragraph\":\n\t\t\t\t\t\treturn `<p>${node.children.map(renderInline).join(\"\")}</p>`;\n\t\t\t\t\tcase \"list\":\n\t\t\t\t\t\treturn renderList(node);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn blocks.join(\"\\n\");\n\t\t})\n\t\t.join(\"\\n\");\n}\n"],"mappings":";;;AAOA,SAAS,WAAW,KAAqB;AACxC,QAAO,IACL,QAAQ,MAAM,QAAQ,CACtB,QAAQ,MAAM,OAAO,CACrB,QAAQ,MAAM,OAAO,CACrB,QAAQ,MAAM,SAAS;;AAG1B,SAAS,aAAa,MAA0B;AAC/C,SAAQ,KAAK,MAAb;EACC,KAAK,OACJ,QAAO,WAAW,KAAK,MAAM;EAC9B,KAAK,OACJ,QAAO,WAAW,WAAW,KAAK,MAAM,CAAC;EAC1C,KAAK,SACJ,QAAO,OAAO,WAAW,KAAK,MAAM,CAAC;EACtC,KAAK,OACJ,QAAO,YAAY,WAAW,KAAK,KAAK,CAAC,IAAI,WAAW,KAAK,MAAM,CAAC;;;AAIvE,SAAS,eAAe,MAA4B;AAQnD,QAAO,OAPS,KAAK,SACnB,KAAK,UACL,MAAM,SAAS,SACZ,WAAW,MAAM,GACjB,aAAa,MAAoB,CACpC,CACA,KAAK,GAAG,CACY;;AAGvB,SAAS,WAAW,MAAwB;CAC3C,MAAM,MAAM,KAAK,UAAU,OAAO;AAElC,QAAO,IAAI,IAAI,GADD,KAAK,MAAM,IAAI,eAAe,CAAC,KAAK,GAAG,CAC7B,IAAI,IAAI;;AAGjC,SAAgB,WAAW,KAAuB;AACjD,QAAO,IAAI,SACT,KAAK,YAAY;AAcjB,SAZe,QAAQ,QAAQ,KAAK,SAAS;AAC5C,WAAQ,KAAK,MAAb;IACC,KAAK,WAAW;KACf,MAAM,QAAQ,KAAK,SAAS;AAC5B,YAAO,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,CAAC,KAAK,MAAM;;IAExD,KAAK,YACJ,QAAO,MAAM,KAAK,SAAS,IAAI,aAAa,CAAC,KAAK,GAAG,CAAC;IACvD,KAAK,OACJ,QAAO,WAAW,KAAK;;IAExB,CACY,KAAK,KAAK;GACvB,CACD,KAAK,KAAK"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,20 +5,13 @@ import { Plugin } from "vite";
|
|
|
5
5
|
type OutputFormat = "markdown" | "html" | "pdf" | "jsx";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/index.d.ts
|
|
8
|
-
type PolicyConfigEntry = string | {
|
|
9
|
-
config: string;
|
|
10
|
-
type?: "privacy" | "terms" | "cookie";
|
|
11
|
-
};
|
|
12
8
|
interface OpenPolicyOptions {
|
|
13
|
-
|
|
14
|
-
config?: string;
|
|
9
|
+
configPath?: string;
|
|
15
10
|
formats?: OutputFormat[];
|
|
16
11
|
outDir?: string;
|
|
17
|
-
type?: "privacy" | "terms" | "cookie";
|
|
18
12
|
}
|
|
19
|
-
declare function
|
|
20
|
-
declare function generatePolicies(configPath: string, outDir: string, formats: OutputFormat[], type?: "privacy" | "terms" | "cookie"): Promise<void>;
|
|
13
|
+
declare function generatePolicies(configPath: string, outDir: string, formats: OutputFormat[]): Promise<void>;
|
|
21
14
|
declare function openPolicy(options?: OpenPolicyOptions): Plugin;
|
|
22
15
|
//#endregion
|
|
23
|
-
export { OpenPolicyOptions,
|
|
16
|
+
export { OpenPolicyOptions, generatePolicies, openPolicy };
|
|
24
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["OutputFormat","CompileOptions","formats","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["OutputFormat","CompileOptions","formats","Jurisdiction","CompanyConfig","name","legalName","address","contact","PrivacyPolicyConfig","Record","effectiveDate","company","dataCollected","legalBasis","retention","cookies","essential","analytics","marketing","thirdParties","purpose","userRights","jurisdictions","children","underAge","noticeUrl","DisputeResolutionMethod","TermsOfServiceConfig","acceptance","methods","eligibility","minimumAge","jurisdictionRestrictions","accounts","registrationRequired","userResponsibleForCredentials","companyCanTerminate","prohibitedUses","userContent","usersOwnContent","licenseGrantedToCompany","licenseDescription","companyCanRemoveContent","intellectualProperty","companyOwnsService","usersMayNotCopy","payments","hasPaidFeatures","refundPolicy","priceChangesNotice","availability","noUptimeGuarantee","maintenanceWindows","termination","userCanTerminate","effectOfTermination","disclaimers","serviceProvidedAsIs","noWarranties","limitationOfLiability","excludesIndirectDamages","liabilityCap","indemnification","userIndemnifiesCompany","scope","thirdPartyServices","disputeResolution","method","venue","classActionWaiver","governingLaw","jurisdiction","changesPolicy","noticeMethod","noticePeriodDays","privacyPolicyUrl","CookiePolicyConfig","functional","policyUrl","trackingTechnologies","consentMechanism","hasBanner","hasPreferencePanel","canWithdraw","PolicyInput","type","OpenPolicyConfig","Omit","privacy","terms","cookie","isOpenPolicyConfig","value","ValidationIssue","level","message","NodeContext","reason","TextNode","context","BoldNode","ItalicNode","LinkNode","href","InlineNode","HeadingNode","ParagraphNode","ListItemNode","ListNode","ordered","items","ContentNode","DocumentSection","id","content","PolicyType","Document","policyType","sections","Node","heading","levelOrContext","text","bold","italic","link","p","li","ul","ol","section","compile","input","validatePrivacyPolicy","config","validateCookiePolicy","validateTermsOfService","expandOpenPolicyConfig"],"sources":["../../core/dist/index.d.ts","../src/index.ts"],"mappings":";;;;KACKA,YAAAA;;;UCYY,iBAAA;EAChB,UAAA;EACA,OAAA,GAAU,YAAA;EACV,MAAA;AAAA;AAAA,iBAGqB,gBAAA,CACrB,UAAA,UACA,MAAA,UACA,OAAA,EAAS,YAAA,KACP,OAAA;AAAA,iBAoDa,UAAA,CAAW,OAAA,GAAS,iBAAA,GAAyB,MAAA"}
|