@voyantjs/legal 0.1.0
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/LICENSE +109 -0
- package/README.md +60 -0
- package/dist/contracts/index.d.ts +13 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +19 -0
- package/dist/contracts/routes.d.ts +1297 -0
- package/dist/contracts/routes.d.ts.map +1 -0
- package/dist/contracts/routes.js +224 -0
- package/dist/contracts/schema.d.ts +1531 -0
- package/dist/contracts/schema.d.ts.map +1 -0
- package/dist/contracts/schema.js +227 -0
- package/dist/contracts/service.d.ts +1753 -0
- package/dist/contracts/service.d.ts.map +1 -0
- package/dist/contracts/service.js +570 -0
- package/dist/contracts/validation.d.ts +274 -0
- package/dist/contracts/validation.d.ts.map +1 -0
- package/dist/contracts/validation.js +125 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/policies/index.d.ts +16 -0
- package/dist/policies/index.d.ts.map +1 -0
- package/dist/policies/index.js +26 -0
- package/dist/policies/routes.d.ts +916 -0
- package/dist/policies/routes.d.ts.map +1 -0
- package/dist/policies/routes.js +162 -0
- package/dist/policies/schema.d.ts +1176 -0
- package/dist/policies/schema.d.ts.map +1 -0
- package/dist/policies/schema.js +189 -0
- package/dist/policies/service.d.ts +1384 -0
- package/dist/policies/service.d.ts.map +1 -0
- package/dist/policies/service.js +438 -0
- package/dist/policies/validation.d.ts +273 -0
- package/dist/policies/validation.d.ts.map +1 -0
- package/dist/policies/validation.js +140 -0
- package/package.json +83 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/policies/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAqBjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAmB7B,CAAA;AAEJ,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { policiesService } from "./service.js";
|
|
3
|
+
import { evaluateCancellationInputSchema, insertPolicyAcceptanceSchema, insertPolicyAssignmentSchema, insertPolicyRuleSchema, insertPolicySchema, insertPolicyVersionSchema, policyAcceptanceListQuerySchema, policyAssignmentListQuerySchema, policyListQuerySchema, resolvePolicyInputSchema, updatePolicyAssignmentSchema, updatePolicyRuleSchema, updatePolicySchema, updatePolicyVersionSchema, } from "./validation.js";
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Policies admin routes — `/v1/admin/policies/*`
|
|
6
|
+
// ============================================================================
|
|
7
|
+
export const policiesAdminRoutes = new Hono()
|
|
8
|
+
// ---------- policies ----------
|
|
9
|
+
.get("/", async (c) => {
|
|
10
|
+
const query = policyListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
11
|
+
return c.json(await policiesService.listPolicies(c.get("db"), query));
|
|
12
|
+
})
|
|
13
|
+
.post("/", async (c) => {
|
|
14
|
+
const row = await policiesService.createPolicy(c.get("db"), insertPolicySchema.parse(await c.req.json()));
|
|
15
|
+
return c.json({ data: row }, 201);
|
|
16
|
+
})
|
|
17
|
+
.get("/resolve", async (c) => {
|
|
18
|
+
const input = resolvePolicyInputSchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
19
|
+
const result = await policiesService.resolvePolicy(c.get("db"), input);
|
|
20
|
+
if (!result)
|
|
21
|
+
return c.json({ data: null });
|
|
22
|
+
return c.json({ data: result });
|
|
23
|
+
})
|
|
24
|
+
.get("/:id", async (c) => {
|
|
25
|
+
const row = await policiesService.getPolicyById(c.get("db"), c.req.param("id"));
|
|
26
|
+
if (!row)
|
|
27
|
+
return c.json({ error: "Policy not found" }, 404);
|
|
28
|
+
return c.json({ data: row });
|
|
29
|
+
})
|
|
30
|
+
.patch("/:id", async (c) => {
|
|
31
|
+
const row = await policiesService.updatePolicy(c.get("db"), c.req.param("id"), updatePolicySchema.parse(await c.req.json()));
|
|
32
|
+
if (!row)
|
|
33
|
+
return c.json({ error: "Policy not found" }, 404);
|
|
34
|
+
return c.json({ data: row });
|
|
35
|
+
})
|
|
36
|
+
.delete("/:id", async (c) => {
|
|
37
|
+
const row = await policiesService.deletePolicy(c.get("db"), c.req.param("id"));
|
|
38
|
+
if (!row)
|
|
39
|
+
return c.json({ error: "Policy not found" }, 404);
|
|
40
|
+
return c.json({ success: true });
|
|
41
|
+
})
|
|
42
|
+
.post("/:id/evaluate", async (c) => {
|
|
43
|
+
const input = evaluateCancellationInputSchema.parse(await c.req.json());
|
|
44
|
+
const result = await policiesService.evaluateCancellation(c.get("db"), c.req.param("id"), input);
|
|
45
|
+
if (!result)
|
|
46
|
+
return c.json({ error: "Policy or current version not found" }, 404);
|
|
47
|
+
return c.json({ data: result });
|
|
48
|
+
})
|
|
49
|
+
// ---------- versions ----------
|
|
50
|
+
.get("/:id/versions", async (c) => {
|
|
51
|
+
const rows = await policiesService.listPolicyVersions(c.get("db"), c.req.param("id"));
|
|
52
|
+
return c.json({ data: rows });
|
|
53
|
+
})
|
|
54
|
+
.post("/:id/versions", async (c) => {
|
|
55
|
+
const version = await policiesService.createPolicyVersion(c.get("db"), c.req.param("id"), insertPolicyVersionSchema.parse(await c.req.json()));
|
|
56
|
+
if (!version)
|
|
57
|
+
return c.json({ error: "Policy not found" }, 404);
|
|
58
|
+
return c.json({ data: version }, 201);
|
|
59
|
+
})
|
|
60
|
+
.get("/versions/:versionId", async (c) => {
|
|
61
|
+
const row = await policiesService.getPolicyVersionById(c.get("db"), c.req.param("versionId"));
|
|
62
|
+
if (!row)
|
|
63
|
+
return c.json({ error: "Policy version not found" }, 404);
|
|
64
|
+
return c.json({ data: row });
|
|
65
|
+
})
|
|
66
|
+
.patch("/versions/:versionId", async (c) => {
|
|
67
|
+
const row = await policiesService.updatePolicyVersion(c.get("db"), c.req.param("versionId"), updatePolicyVersionSchema.parse(await c.req.json()));
|
|
68
|
+
if (!row)
|
|
69
|
+
return c.json({ error: "Policy version not found or not a draft" }, 404);
|
|
70
|
+
return c.json({ data: row });
|
|
71
|
+
})
|
|
72
|
+
.post("/versions/:versionId/publish", async (c) => {
|
|
73
|
+
const result = await policiesService.publishPolicyVersion(c.get("db"), c.req.param("versionId"));
|
|
74
|
+
if (result.status === "not_found")
|
|
75
|
+
return c.json({ error: "Policy version not found" }, 404);
|
|
76
|
+
if (result.status === "not_draft") {
|
|
77
|
+
return c.json({ error: "Only draft versions can be published" }, 409);
|
|
78
|
+
}
|
|
79
|
+
return c.json({ data: result.version });
|
|
80
|
+
})
|
|
81
|
+
.post("/versions/:versionId/retire", async (c) => {
|
|
82
|
+
const row = await policiesService.retirePolicyVersion(c.get("db"), c.req.param("versionId"));
|
|
83
|
+
if (!row)
|
|
84
|
+
return c.json({ error: "Policy version not found" }, 404);
|
|
85
|
+
return c.json({ data: row });
|
|
86
|
+
})
|
|
87
|
+
// ---------- rules ----------
|
|
88
|
+
.get("/versions/:versionId/rules", async (c) => {
|
|
89
|
+
const rows = await policiesService.listPolicyRules(c.get("db"), c.req.param("versionId"));
|
|
90
|
+
return c.json({ data: rows });
|
|
91
|
+
})
|
|
92
|
+
.post("/versions/:versionId/rules", async (c) => {
|
|
93
|
+
const row = await policiesService.createPolicyRule(c.get("db"), c.req.param("versionId"), insertPolicyRuleSchema.parse(await c.req.json()));
|
|
94
|
+
if (!row)
|
|
95
|
+
return c.json({ error: "Policy version not found" }, 404);
|
|
96
|
+
return c.json({ data: row }, 201);
|
|
97
|
+
})
|
|
98
|
+
.patch("/rules/:ruleId", async (c) => {
|
|
99
|
+
const row = await policiesService.updatePolicyRule(c.get("db"), c.req.param("ruleId"), updatePolicyRuleSchema.parse(await c.req.json()));
|
|
100
|
+
if (!row)
|
|
101
|
+
return c.json({ error: "Policy rule not found" }, 404);
|
|
102
|
+
return c.json({ data: row });
|
|
103
|
+
})
|
|
104
|
+
.delete("/rules/:ruleId", async (c) => {
|
|
105
|
+
const row = await policiesService.deletePolicyRule(c.get("db"), c.req.param("ruleId"));
|
|
106
|
+
if (!row)
|
|
107
|
+
return c.json({ error: "Policy rule not found" }, 404);
|
|
108
|
+
return c.json({ success: true });
|
|
109
|
+
})
|
|
110
|
+
// ---------- assignments ----------
|
|
111
|
+
.get("/assignments", async (c) => {
|
|
112
|
+
const query = policyAssignmentListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
113
|
+
return c.json(await policiesService.listPolicyAssignments(c.get("db"), query));
|
|
114
|
+
})
|
|
115
|
+
.post("/assignments", async (c) => {
|
|
116
|
+
const row = await policiesService.createPolicyAssignment(c.get("db"), insertPolicyAssignmentSchema.parse(await c.req.json()));
|
|
117
|
+
return c.json({ data: row }, 201);
|
|
118
|
+
})
|
|
119
|
+
.patch("/assignments/:id", async (c) => {
|
|
120
|
+
const row = await policiesService.updatePolicyAssignment(c.get("db"), c.req.param("id"), updatePolicyAssignmentSchema.parse(await c.req.json()));
|
|
121
|
+
if (!row)
|
|
122
|
+
return c.json({ error: "Policy assignment not found" }, 404);
|
|
123
|
+
return c.json({ data: row });
|
|
124
|
+
})
|
|
125
|
+
.delete("/assignments/:id", async (c) => {
|
|
126
|
+
const row = await policiesService.deletePolicyAssignment(c.get("db"), c.req.param("id"));
|
|
127
|
+
if (!row)
|
|
128
|
+
return c.json({ error: "Policy assignment not found" }, 404);
|
|
129
|
+
return c.json({ success: true });
|
|
130
|
+
})
|
|
131
|
+
// ---------- acceptances ----------
|
|
132
|
+
.get("/acceptances", async (c) => {
|
|
133
|
+
const query = policyAcceptanceListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
134
|
+
return c.json(await policiesService.listPolicyAcceptances(c.get("db"), query));
|
|
135
|
+
})
|
|
136
|
+
.post("/acceptances", async (c) => {
|
|
137
|
+
const row = await policiesService.recordPolicyAcceptance(c.get("db"), insertPolicyAcceptanceSchema.parse(await c.req.json()));
|
|
138
|
+
return c.json({ data: row }, 201);
|
|
139
|
+
});
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Policies public routes — `/v1/public/policies/*`
|
|
142
|
+
// Customer-facing: fetch current published version by slug + record acceptance
|
|
143
|
+
// ============================================================================
|
|
144
|
+
export const policiesPublicRoutes = new Hono()
|
|
145
|
+
.get("/:slug", async (c) => {
|
|
146
|
+
const policy = await policiesService.getPolicyBySlug(c.get("db"), c.req.param("slug"));
|
|
147
|
+
if (!policy)
|
|
148
|
+
return c.json({ error: "Policy not found" }, 404);
|
|
149
|
+
if (!policy.currentVersionId) {
|
|
150
|
+
return c.json({ error: "Policy has no published version" }, 404);
|
|
151
|
+
}
|
|
152
|
+
const version = await policiesService.getPolicyVersionById(c.get("db"), policy.currentVersionId);
|
|
153
|
+
if (!version || version.status !== "published") {
|
|
154
|
+
return c.json({ error: "Policy has no published version" }, 404);
|
|
155
|
+
}
|
|
156
|
+
return c.json({ data: { policy, version } });
|
|
157
|
+
})
|
|
158
|
+
.post("/:id/accept", async (c) => {
|
|
159
|
+
const input = insertPolicyAcceptanceSchema.parse(await c.req.json());
|
|
160
|
+
const row = await policiesService.recordPolicyAcceptance(c.get("db"), input);
|
|
161
|
+
return c.json({ data: row }, 201);
|
|
162
|
+
});
|