@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":"schema.d.ts","sourceRoot":"","sources":["../../src/policies/schema.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc,oJASzB,CAAA;AAEF,eAAO,MAAM,uBAAuB,yEAIlC,CAAA;AAEF,eAAO,MAAM,kBAAkB,uGAM7B,CAAA;AAEF,e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AAA;AAEH,eAAO,MAAM,0BAA0B;;EAEpC,CAAA;AAEH,eAAO,MAAM,0BAA0B;;EAKpC,CAAA"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
|
|
2
|
+
import { relations } from "drizzle-orm";
|
|
3
|
+
import { date, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
4
|
+
// ---------- enums ----------
|
|
5
|
+
export const policyKindEnum = pgEnum("policy_kind", [
|
|
6
|
+
"cancellation",
|
|
7
|
+
"payment",
|
|
8
|
+
"terms_and_conditions",
|
|
9
|
+
"privacy",
|
|
10
|
+
"refund",
|
|
11
|
+
"commission",
|
|
12
|
+
"guarantee",
|
|
13
|
+
"other",
|
|
14
|
+
]);
|
|
15
|
+
export const policyVersionStatusEnum = pgEnum("policy_version_status", [
|
|
16
|
+
"draft",
|
|
17
|
+
"published",
|
|
18
|
+
"retired",
|
|
19
|
+
]);
|
|
20
|
+
export const policyRuleTypeEnum = pgEnum("policy_rule_type", [
|
|
21
|
+
"window",
|
|
22
|
+
"percentage",
|
|
23
|
+
"flat_amount",
|
|
24
|
+
"date_range",
|
|
25
|
+
"custom",
|
|
26
|
+
]);
|
|
27
|
+
export const policyRefundTypeEnum = pgEnum("policy_refund_type", [
|
|
28
|
+
"cash",
|
|
29
|
+
"credit",
|
|
30
|
+
"cash_or_credit",
|
|
31
|
+
"none",
|
|
32
|
+
]);
|
|
33
|
+
export const policyAssignmentScopeEnum = pgEnum("policy_assignment_scope", [
|
|
34
|
+
"product",
|
|
35
|
+
"channel",
|
|
36
|
+
"supplier",
|
|
37
|
+
"market",
|
|
38
|
+
"organization",
|
|
39
|
+
"global",
|
|
40
|
+
]);
|
|
41
|
+
export const policyBodyFormatEnum = pgEnum("policy_body_format", ["markdown", "html", "plain"]);
|
|
42
|
+
export const policyAcceptanceMethodEnum = pgEnum("policy_acceptance_method", [
|
|
43
|
+
"implicit",
|
|
44
|
+
"explicit_checkbox",
|
|
45
|
+
"signature",
|
|
46
|
+
]);
|
|
47
|
+
// ---------- policies ----------
|
|
48
|
+
export const policies = pgTable("policies", {
|
|
49
|
+
id: typeId("policies"),
|
|
50
|
+
kind: policyKindEnum("kind").notNull(),
|
|
51
|
+
name: text("name").notNull(),
|
|
52
|
+
slug: text("slug").notNull().unique(),
|
|
53
|
+
description: text("description"),
|
|
54
|
+
language: text("language").notNull().default("en"),
|
|
55
|
+
currentVersionId: typeIdRef("current_version_id"),
|
|
56
|
+
metadata: jsonb("metadata"),
|
|
57
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
58
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
59
|
+
}, (table) => [
|
|
60
|
+
index("idx_policies_kind").on(table.kind),
|
|
61
|
+
index("idx_policies_language").on(table.language),
|
|
62
|
+
uniqueIndex("uq_policies_slug").on(table.slug),
|
|
63
|
+
]);
|
|
64
|
+
// ---------- policy_versions ----------
|
|
65
|
+
export const policyVersions = pgTable("policy_versions", {
|
|
66
|
+
id: typeId("policy_versions"),
|
|
67
|
+
policyId: typeIdRef("policy_id")
|
|
68
|
+
.notNull()
|
|
69
|
+
.references(() => policies.id, { onDelete: "cascade" }),
|
|
70
|
+
version: integer("version").notNull(),
|
|
71
|
+
status: policyVersionStatusEnum("status").notNull().default("draft"),
|
|
72
|
+
title: text("title").notNull(),
|
|
73
|
+
bodyFormat: policyBodyFormatEnum("body_format").notNull().default("markdown"),
|
|
74
|
+
body: text("body"),
|
|
75
|
+
publishedAt: timestamp("published_at", { withTimezone: true }),
|
|
76
|
+
publishedBy: text("published_by"),
|
|
77
|
+
retiredAt: timestamp("retired_at", { withTimezone: true }),
|
|
78
|
+
metadata: jsonb("metadata"),
|
|
79
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
80
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
81
|
+
}, (table) => [
|
|
82
|
+
index("idx_policy_versions_policy").on(table.policyId),
|
|
83
|
+
index("idx_policy_versions_status").on(table.status),
|
|
84
|
+
uniqueIndex("uq_policy_versions_policy_version").on(table.policyId, table.version),
|
|
85
|
+
]);
|
|
86
|
+
// ---------- policy_rules ----------
|
|
87
|
+
export const policyRules = pgTable("policy_rules", {
|
|
88
|
+
id: typeId("policy_rules"),
|
|
89
|
+
policyVersionId: typeIdRef("policy_version_id")
|
|
90
|
+
.notNull()
|
|
91
|
+
.references(() => policyVersions.id, { onDelete: "cascade" }),
|
|
92
|
+
ruleType: policyRuleTypeEnum("rule_type").notNull(),
|
|
93
|
+
label: text("label"),
|
|
94
|
+
// Cancellation-window fields
|
|
95
|
+
daysBeforeDeparture: integer("days_before_departure"),
|
|
96
|
+
refundPercent: integer("refund_percent"),
|
|
97
|
+
refundType: policyRefundTypeEnum("refund_type"),
|
|
98
|
+
flatAmountCents: integer("flat_amount_cents"),
|
|
99
|
+
currency: text("currency"),
|
|
100
|
+
// Generic date range
|
|
101
|
+
validFrom: date("valid_from"),
|
|
102
|
+
validTo: date("valid_to"),
|
|
103
|
+
// Evaluation input
|
|
104
|
+
conditions: jsonb("conditions"),
|
|
105
|
+
sortOrder: integer("sort_order").notNull().default(0),
|
|
106
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
107
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
108
|
+
}, (table) => [
|
|
109
|
+
index("idx_policy_rules_version").on(table.policyVersionId),
|
|
110
|
+
index("idx_policy_rules_type").on(table.ruleType),
|
|
111
|
+
index("idx_policy_rules_sort").on(table.sortOrder),
|
|
112
|
+
]);
|
|
113
|
+
// ---------- policy_assignments ----------
|
|
114
|
+
export const policyAssignments = pgTable("policy_assignments", {
|
|
115
|
+
id: typeId("policy_assignments"),
|
|
116
|
+
policyId: typeIdRef("policy_id")
|
|
117
|
+
.notNull()
|
|
118
|
+
.references(() => policies.id, { onDelete: "cascade" }),
|
|
119
|
+
scope: policyAssignmentScopeEnum("scope").notNull(),
|
|
120
|
+
productId: typeIdRef("product_id"),
|
|
121
|
+
channelId: typeIdRef("channel_id"),
|
|
122
|
+
supplierId: typeIdRef("supplier_id"),
|
|
123
|
+
marketId: typeIdRef("market_id"),
|
|
124
|
+
organizationId: typeIdRef("organization_id"),
|
|
125
|
+
validFrom: date("valid_from"),
|
|
126
|
+
validTo: date("valid_to"),
|
|
127
|
+
priority: integer("priority").notNull().default(0),
|
|
128
|
+
metadata: jsonb("metadata"),
|
|
129
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
130
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
131
|
+
}, (table) => [
|
|
132
|
+
index("idx_policy_assignments_policy").on(table.policyId),
|
|
133
|
+
index("idx_policy_assignments_scope").on(table.scope),
|
|
134
|
+
index("idx_policy_assignments_product").on(table.productId),
|
|
135
|
+
index("idx_policy_assignments_channel").on(table.channelId),
|
|
136
|
+
index("idx_policy_assignments_supplier").on(table.supplierId),
|
|
137
|
+
index("idx_policy_assignments_market").on(table.marketId),
|
|
138
|
+
index("idx_policy_assignments_organization").on(table.organizationId),
|
|
139
|
+
index("idx_policy_assignments_priority").on(table.priority),
|
|
140
|
+
]);
|
|
141
|
+
// ---------- policy_acceptances ----------
|
|
142
|
+
export const policyAcceptances = pgTable("policy_acceptances", {
|
|
143
|
+
id: typeId("policy_acceptances"),
|
|
144
|
+
policyVersionId: typeIdRef("policy_version_id")
|
|
145
|
+
.notNull()
|
|
146
|
+
.references(() => policyVersions.id, { onDelete: "restrict" }),
|
|
147
|
+
personId: typeIdRef("person_id"),
|
|
148
|
+
bookingId: typeIdRef("booking_id"),
|
|
149
|
+
orderId: typeIdRef("order_id"),
|
|
150
|
+
offerId: typeIdRef("offer_id"),
|
|
151
|
+
acceptedAt: timestamp("accepted_at", { withTimezone: true }).notNull().defaultNow(),
|
|
152
|
+
acceptedBy: text("accepted_by"),
|
|
153
|
+
method: policyAcceptanceMethodEnum("method").notNull().default("implicit"),
|
|
154
|
+
ipAddress: text("ip_address"),
|
|
155
|
+
userAgent: text("user_agent"),
|
|
156
|
+
metadata: jsonb("metadata"),
|
|
157
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
158
|
+
}, (table) => [
|
|
159
|
+
index("idx_policy_acceptances_version").on(table.policyVersionId),
|
|
160
|
+
index("idx_policy_acceptances_person").on(table.personId),
|
|
161
|
+
index("idx_policy_acceptances_booking").on(table.bookingId),
|
|
162
|
+
index("idx_policy_acceptances_order").on(table.orderId),
|
|
163
|
+
index("idx_policy_acceptances_offer").on(table.offerId),
|
|
164
|
+
]);
|
|
165
|
+
// ---------- relations ----------
|
|
166
|
+
export const policiesRelations = relations(policies, ({ many }) => ({
|
|
167
|
+
versions: many(policyVersions),
|
|
168
|
+
assignments: many(policyAssignments),
|
|
169
|
+
}));
|
|
170
|
+
export const policyVersionsRelations = relations(policyVersions, ({ one, many }) => ({
|
|
171
|
+
policy: one(policies, { fields: [policyVersions.policyId], references: [policies.id] }),
|
|
172
|
+
rules: many(policyRules),
|
|
173
|
+
acceptances: many(policyAcceptances),
|
|
174
|
+
}));
|
|
175
|
+
export const policyRulesRelations = relations(policyRules, ({ one }) => ({
|
|
176
|
+
policyVersion: one(policyVersions, {
|
|
177
|
+
fields: [policyRules.policyVersionId],
|
|
178
|
+
references: [policyVersions.id],
|
|
179
|
+
}),
|
|
180
|
+
}));
|
|
181
|
+
export const policyAssignmentsRelations = relations(policyAssignments, ({ one }) => ({
|
|
182
|
+
policy: one(policies, { fields: [policyAssignments.policyId], references: [policies.id] }),
|
|
183
|
+
}));
|
|
184
|
+
export const policyAcceptancesRelations = relations(policyAcceptances, ({ one }) => ({
|
|
185
|
+
policyVersion: one(policyVersions, {
|
|
186
|
+
fields: [policyAcceptances.policyVersionId],
|
|
187
|
+
references: [policyVersions.id],
|
|
188
|
+
}),
|
|
189
|
+
}));
|