@openpolicy/sdk 0.0.9 → 0.0.11
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 +90 -2
- package/dist/index.d.ts +43 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@openpolicy/sdk`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> TypeScript SDK for defining privacy policies and terms of service as code.
|
|
4
|
+
|
|
5
|
+
Part of [OpenPolicy](https://openpolicy.sh) — a policy-as-code framework that compiles legal agreements from TypeScript at build time.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @openpolicy/sdk
|
|
11
|
+
# or: npm install @openpolicy/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### Privacy policy
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// privacy.config.ts
|
|
20
|
+
import { definePrivacyPolicy } from "@openpolicy/sdk";
|
|
21
|
+
|
|
22
|
+
export default definePrivacyPolicy({
|
|
23
|
+
effectiveDate: "2026-01-01",
|
|
24
|
+
company: {
|
|
25
|
+
name: "Acme",
|
|
26
|
+
legalName: "Acme, Inc.",
|
|
27
|
+
address: "123 Main St, San Francisco, CA 94105",
|
|
28
|
+
contact: "privacy@acme.com",
|
|
29
|
+
},
|
|
30
|
+
dataCollected: {
|
|
31
|
+
"Account information": ["Email address", "Display name"],
|
|
32
|
+
"Usage data": ["Pages visited", "Session duration"],
|
|
33
|
+
},
|
|
34
|
+
legalBasis: "Legitimate interests and user consent",
|
|
35
|
+
retention: {
|
|
36
|
+
"Account data": "Until account deletion",
|
|
37
|
+
"Analytics data": "13 months",
|
|
38
|
+
},
|
|
39
|
+
cookies: { essential: true, analytics: true, marketing: false },
|
|
40
|
+
thirdParties: [
|
|
41
|
+
{ name: "Vercel", purpose: "Hosting" },
|
|
42
|
+
{ name: "Plausible", purpose: "Privacy-friendly analytics" },
|
|
43
|
+
],
|
|
44
|
+
userRights: ["access", "erasure", "portability"],
|
|
45
|
+
jurisdictions: ["us", "eu"],
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Terms of service
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// terms.config.ts
|
|
53
|
+
import { defineTermsOfService } from "@openpolicy/sdk";
|
|
54
|
+
|
|
55
|
+
export default defineTermsOfService({
|
|
56
|
+
effectiveDate: "2026-01-01",
|
|
57
|
+
company: {
|
|
58
|
+
name: "Acme",
|
|
59
|
+
legalName: "Acme, Inc.",
|
|
60
|
+
address: "123 Main St, San Francisco, CA 94105",
|
|
61
|
+
contact: "legal@acme.com",
|
|
62
|
+
},
|
|
63
|
+
acceptance: { methods: ["using the service", "creating an account"] },
|
|
64
|
+
eligibility: { minimumAge: 13 },
|
|
65
|
+
disclaimers: { serviceProvidedAsIs: true, noWarranties: true },
|
|
66
|
+
limitationOfLiability: { excludesIndirectDamages: true },
|
|
67
|
+
governingLaw: { jurisdiction: "Delaware, USA" },
|
|
68
|
+
changesPolicy: {
|
|
69
|
+
noticeMethod: "email or prominent notice on the website",
|
|
70
|
+
noticePeriodDays: 30,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Compiling policies
|
|
76
|
+
|
|
77
|
+
The SDK exports types and helper functions for _defining_ policies. To compile them to Markdown or HTML, pair it with one of:
|
|
78
|
+
|
|
79
|
+
- **[`@openpolicy/vite`](https://openpolicy.sh/docs/getting-started/vite)** — Vite plugin (build-time, with hot-reload in dev)
|
|
80
|
+
- **[`@openpolicy/astro`](https://openpolicy.sh/docs/getting-started/astro)** — Astro integration
|
|
81
|
+
- **[`@openpolicy/cli`](https://openpolicy.sh/docs/getting-started/cli)** — `openpolicy generate` CLI command
|
|
82
|
+
|
|
83
|
+
## Documentation
|
|
84
|
+
|
|
85
|
+
Full field reference and guides: [openpolicy.sh/docs](https://openpolicy.sh/docs)
|
|
86
|
+
|
|
87
|
+
## Links
|
|
88
|
+
|
|
89
|
+
- [GitHub](https://github.com/jamiedavenport/openpolicy)
|
|
90
|
+
- [openpolicy.sh](https://openpolicy.sh)
|
|
91
|
+
- [npm](https://www.npmjs.com/package/@openpolicy/sdk)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
//#region ../core/dist/index.d.ts
|
|
2
2
|
type Jurisdiction = "us" | "eu" | "ca" | "au" | "nz" | "other";
|
|
3
|
+
type CompanyConfig = {
|
|
4
|
+
name: string;
|
|
5
|
+
legalName: string;
|
|
6
|
+
address: string;
|
|
7
|
+
contact: string;
|
|
8
|
+
};
|
|
3
9
|
type PrivacyPolicyConfig = {
|
|
4
10
|
effectiveDate: string;
|
|
5
|
-
company:
|
|
6
|
-
name: string;
|
|
7
|
-
legalName: string;
|
|
8
|
-
address: string;
|
|
9
|
-
contact: string;
|
|
10
|
-
};
|
|
11
|
+
company: CompanyConfig;
|
|
11
12
|
dataCollected: Record<string, string[]>;
|
|
12
13
|
legalBasis: string;
|
|
13
14
|
retention: Record<string, string>;
|
|
@@ -22,16 +23,15 @@ type PrivacyPolicyConfig = {
|
|
|
22
23
|
}[];
|
|
23
24
|
userRights: string[];
|
|
24
25
|
jurisdictions: Jurisdiction[];
|
|
26
|
+
children?: {
|
|
27
|
+
underAge: number;
|
|
28
|
+
noticeUrl?: string;
|
|
29
|
+
};
|
|
25
30
|
};
|
|
26
31
|
type DisputeResolutionMethod = "arbitration" | "litigation" | "mediation";
|
|
27
32
|
type TermsOfServiceConfig = {
|
|
28
33
|
effectiveDate: string;
|
|
29
|
-
company:
|
|
30
|
-
name: string;
|
|
31
|
-
legalName: string;
|
|
32
|
-
address: string;
|
|
33
|
-
contact: string;
|
|
34
|
-
};
|
|
34
|
+
company: CompanyConfig;
|
|
35
35
|
acceptance: {
|
|
36
36
|
methods: string[];
|
|
37
37
|
};
|
|
@@ -99,10 +99,40 @@ type TermsOfServiceConfig = {
|
|
|
99
99
|
};
|
|
100
100
|
privacyPolicyUrl?: string;
|
|
101
101
|
};
|
|
102
|
+
type CookiePolicyConfig = {
|
|
103
|
+
effectiveDate: string;
|
|
104
|
+
company: CompanyConfig;
|
|
105
|
+
cookies: {
|
|
106
|
+
essential: boolean;
|
|
107
|
+
analytics: boolean;
|
|
108
|
+
functional: boolean;
|
|
109
|
+
marketing: boolean;
|
|
110
|
+
};
|
|
111
|
+
thirdParties?: {
|
|
112
|
+
name: string;
|
|
113
|
+
purpose: string;
|
|
114
|
+
policyUrl?: string;
|
|
115
|
+
}[];
|
|
116
|
+
trackingTechnologies?: string[];
|
|
117
|
+
consentMechanism?: {
|
|
118
|
+
hasBanner: boolean;
|
|
119
|
+
hasPreferencePanel: boolean;
|
|
120
|
+
canWithdraw: boolean;
|
|
121
|
+
};
|
|
122
|
+
jurisdictions: Jurisdiction[];
|
|
123
|
+
};
|
|
124
|
+
type OpenPolicyConfig = {
|
|
125
|
+
company: CompanyConfig;
|
|
126
|
+
privacy?: Omit<PrivacyPolicyConfig, "company">;
|
|
127
|
+
terms?: Omit<TermsOfServiceConfig, "company">;
|
|
128
|
+
cookie?: Omit<CookiePolicyConfig, "company">;
|
|
129
|
+
};
|
|
102
130
|
//#endregion
|
|
103
131
|
//#region src/index.d.ts
|
|
132
|
+
declare function defineConfig(config: OpenPolicyConfig): OpenPolicyConfig;
|
|
104
133
|
declare function definePrivacyPolicy(config: PrivacyPolicyConfig): PrivacyPolicyConfig;
|
|
105
134
|
declare function defineTermsOfService(config: TermsOfServiceConfig): TermsOfServiceConfig;
|
|
135
|
+
declare function defineCookiePolicy(config: CookiePolicyConfig): CookiePolicyConfig;
|
|
106
136
|
//#endregion
|
|
107
|
-
export { type PrivacyPolicyConfig, type TermsOfServiceConfig, definePrivacyPolicy, defineTermsOfService };
|
|
137
|
+
export { type CookiePolicyConfig, type OpenPolicyConfig, type PrivacyPolicyConfig, type TermsOfServiceConfig, defineConfig, defineCookiePolicy, definePrivacyPolicy, defineTermsOfService };
|
|
108
138
|
//# 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","PolicySection","id","title","body","Jurisdiction","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["OutputFormat","CompileOptions","formats","PolicySection","id","title","body","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","compileCookiePolicy","config","options","format","content","sections","compilePrivacyPolicy","compileTermsOfService","validatePrivacyPolicy","validateCookiePolicy","validateTermsOfService","expandOpenPolicyConfig","compilePolicy","input"],"sources":["../../core/dist/index.d.ts","../src/index.ts"],"mappings":";KAUKO,YAAAA;AAAAA,KACAC,aAAAA;EACHC,IAAAA;EACAC,SAAAA;EACAC,OAAAA;EACAC,OAAAA;AAAAA;AAAAA,KAEGC,mBAAAA;EACHE,aAAAA;EACAC,OAAAA,EAASR,aAAAA;EACTS,aAAAA,EAAeH,MAAAA;EACfI,UAAAA;EACAC,SAAAA,EAAWL,MAAAA;EACXM,OAAAA;IACEC,SAAAA;IACAC,SAAAA;IACAC,SAAAA;EAAAA;EAEFC,YAAAA;IACEf,IAAAA;IACAgB,OAAAA;EAAAA;EAEFC,UAAAA;EACAC,aAAAA,EAAepB,YAAAA;EACfqB,QAAAA;IACEC,QAAAA;IACAC,SAAAA;EAAAA;AAAAA;AAAAA,KAGCC,uBAAAA;AAAAA,KACAC,oBAAAA;EACHjB,aAAAA;EACAC,OAAAA,EAASR,aAAAA;EACTyB,UAAAA;IACEC,OAAAA;EAAAA;EAEFC,WAAAA;IACEC,UAAAA;IACAC,wBAAAA;EAAAA;EAEFC,QAAAA;IACEC,oBAAAA;IACAC,6BAAAA;IACAC,mBAAAA;EAAAA;EAEFC,cAAAA;EACAC,WAAAA;IACEC,eAAAA;IACAC,uBAAAA;IACAC,kBAAAA;IACAC,uBAAAA;EAAAA;EAEFC,oBAAAA;IACEC,kBAAAA;IACAC,eAAAA;EAAAA;EAEFC,QAAAA;IACEC,eAAAA;IACAC,YAAAA;IACAC,kBAAAA;EAAAA;EAEFC,YAAAA;IACEC,iBAAAA;IACAC,kBAAAA;EAAAA;EAEFC,WAAAA;IACEjB,mBAAAA;IACAkB,gBAAAA;IACAC,mBAAAA;EAAAA;EAEFC,WAAAA;IACEC,mBAAAA;IACAC,YAAAA;EAAAA;EAEFC,qBAAAA;IACEC,uBAAAA;IACAC,YAAAA;EAAAA;EAEFC,eAAAA;IACEC,sBAAAA;IACAC,KAAAA;EAAAA;EAEFC,kBAAAA;IACE7D,IAAAA;IACAgB,OAAAA;EAAAA;EAEF8C,iBAAAA;IACEC,MAAAA,EAAQzC,uBAAAA;IACR0C,KAAAA;IACAC,iBAAAA;EAAAA;EAEFC,YAAAA;IACEC,YAAAA;EAAAA;EAEFC,aAAAA;IACEC,YAAAA;IACAC,gBAAAA;EAAAA;EAEFC,gBAAAA;AAAAA;AAAAA,KAEGC,kBAAAA;EACHlE,aAAAA;EACAC,OAAAA,EAASR,aAAAA;EACTY,OAAAA;IACEC,SAAAA;IACAC,SAAAA;IACA4D,UAAAA;IACA3D,SAAAA;EAAAA;EAEFC,YAAAA;IACEf,IAAAA;IACAgB,OAAAA;IACA0D,SAAAA;EAAAA;EAEFC,oBAAAA;EACAC,gBAAAA;IACEC,SAAAA;IACAC,kBAAAA;IACAC,WAAAA;EAAAA;EAEF7D,aAAAA,EAAepB,YAAAA;AAAAA;AAAAA,KASZoF,gBAAAA;EACH3E,OAAAA,EAASR,aAAAA;EACTqF,OAAAA,GAAUD,IAAAA,CAAK/E,mBAAAA;EACfiF,KAAAA,GAAQF,IAAAA,CAAK5D,oBAAAA;EACb+D,MAAAA,GAASH,IAAAA,CAAKX,kBAAAA;AAAAA;;;iBCjIA,YAAA,CAAa,MAAA,EAAQ,gBAAA,GAAmB,gBAAA;AAAA,iBAIxC,mBAAA,CACf,MAAA,EAAQ,mBAAA,GACN,mBAAA;AAAA,iBAIa,oBAAA,CACf,MAAA,EAAQ,oBAAA,GACN,oBAAA;AAAA,iBAIa,kBAAA,CACf,MAAA,EAAQ,kBAAA,GACN,kBAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
|
+
function defineConfig(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
2
5
|
function definePrivacyPolicy(config) {
|
|
3
6
|
return config;
|
|
4
7
|
}
|
|
5
8
|
function defineTermsOfService(config) {
|
|
6
9
|
return config;
|
|
7
10
|
}
|
|
11
|
+
function defineCookiePolicy(config) {
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
8
14
|
//#endregion
|
|
9
|
-
export { definePrivacyPolicy, defineTermsOfService };
|
|
15
|
+
export { defineConfig, defineCookiePolicy, definePrivacyPolicy, defineTermsOfService };
|
|
10
16
|
|
|
11
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n\tPrivacyPolicyConfig,\n\tTermsOfServiceConfig,\n} from \"@openpolicy/core\";\n\nexport type {\n\tPrivacyPolicyConfig,\n\tTermsOfServiceConfig,\n} from \"@openpolicy/core\";\n\nexport function definePrivacyPolicy(\n\tconfig: PrivacyPolicyConfig,\n): PrivacyPolicyConfig {\n\treturn config;\n}\n\nexport function defineTermsOfService(\n\tconfig: TermsOfServiceConfig,\n): TermsOfServiceConfig {\n\treturn config;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n\tCookiePolicyConfig,\n\tOpenPolicyConfig,\n\tPrivacyPolicyConfig,\n\tTermsOfServiceConfig,\n} from \"@openpolicy/core\";\n\nexport type {\n\tCookiePolicyConfig,\n\tOpenPolicyConfig,\n\tPrivacyPolicyConfig,\n\tTermsOfServiceConfig,\n} from \"@openpolicy/core\";\n\nexport function defineConfig(config: OpenPolicyConfig): OpenPolicyConfig {\n\treturn config;\n}\n\nexport function definePrivacyPolicy(\n\tconfig: PrivacyPolicyConfig,\n): PrivacyPolicyConfig {\n\treturn config;\n}\n\nexport function defineTermsOfService(\n\tconfig: TermsOfServiceConfig,\n): TermsOfServiceConfig {\n\treturn config;\n}\n\nexport function defineCookiePolicy(\n\tconfig: CookiePolicyConfig,\n): CookiePolicyConfig {\n\treturn config;\n}\n"],"mappings":";AAcA,SAAgB,aAAa,QAA4C;AACxE,QAAO;;AAGR,SAAgB,oBACf,QACsB;AACtB,QAAO;;AAGR,SAAgB,qBACf,QACuB;AACvB,QAAO;;AAGR,SAAgB,mBACf,QACqB;AACrB,QAAO"}
|