@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/contracts/schema.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,iBAAiB,+FAM5B,CAAA;AAEF,eAAO,MAAM,kBAAkB,4GAQ7B,CAAA;AAEF,eAAO,MAAM,2BAA2B,qFAKtC,CAAA;A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AAkB,CAAC,YAAY,CAAA;AAIzE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiB/B,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,mBAAmB,CAAC,YAAY,CAAA;AACxE,MAAM,MAAM,qBAAqB,GAAG,OAAO,mBAAmB,CAAC,YAAY,CAAA;AAI3E,eAAO,MAAM,0BAA0B;;EAEpC,CAAA;AAEH,eAAO,MAAM,iCAAiC;;;EAS7C,CAAA;AAED,eAAO,MAAM,6BAA6B;;EAEvC,CAAA;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;EAiB5B,CAAA;AAEH,eAAO,MAAM,2BAA2B;;;EAMrC,CAAA;AAEH,eAAO,MAAM,4BAA4B;;EAKtC,CAAA"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { organizations, people } from "@voyantjs/crm/schema";
|
|
2
|
+
import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
|
|
3
|
+
import { suppliers } from "@voyantjs/suppliers/schema";
|
|
4
|
+
import { relations } from "drizzle-orm";
|
|
5
|
+
import { boolean, index, integer, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
6
|
+
// ---------- enums ----------
|
|
7
|
+
export const contractScopeEnum = pgEnum("contract_scope", [
|
|
8
|
+
"customer",
|
|
9
|
+
"supplier",
|
|
10
|
+
"partner",
|
|
11
|
+
"channel",
|
|
12
|
+
"other",
|
|
13
|
+
]);
|
|
14
|
+
export const contractStatusEnum = pgEnum("contract_status", [
|
|
15
|
+
"draft",
|
|
16
|
+
"issued",
|
|
17
|
+
"sent",
|
|
18
|
+
"signed",
|
|
19
|
+
"executed",
|
|
20
|
+
"expired",
|
|
21
|
+
"void",
|
|
22
|
+
]);
|
|
23
|
+
export const contractSignatureMethodEnum = pgEnum("contract_signature_method", [
|
|
24
|
+
"manual",
|
|
25
|
+
"electronic",
|
|
26
|
+
"docusign",
|
|
27
|
+
"other",
|
|
28
|
+
]);
|
|
29
|
+
export const contractNumberResetStrategyEnum = pgEnum("contract_number_reset_strategy", [
|
|
30
|
+
"never",
|
|
31
|
+
"annual",
|
|
32
|
+
"monthly",
|
|
33
|
+
]);
|
|
34
|
+
export const contractBodyFormatEnum = pgEnum("contract_body_format", [
|
|
35
|
+
"markdown",
|
|
36
|
+
"html",
|
|
37
|
+
"lexical_json",
|
|
38
|
+
]);
|
|
39
|
+
// ---------- contract_templates ----------
|
|
40
|
+
export const contractTemplates = pgTable("contract_templates", {
|
|
41
|
+
id: typeId("contract_templates"),
|
|
42
|
+
name: text("name").notNull(),
|
|
43
|
+
slug: text("slug").notNull().unique(),
|
|
44
|
+
scope: contractScopeEnum("scope").notNull(),
|
|
45
|
+
language: text("language").notNull().default("en"),
|
|
46
|
+
description: text("description"),
|
|
47
|
+
bodyFormat: contractBodyFormatEnum("body_format").notNull().default("markdown"),
|
|
48
|
+
body: text("body").notNull(),
|
|
49
|
+
variableSchema: jsonb("variable_schema"),
|
|
50
|
+
currentVersionId: typeIdRef("current_version_id"),
|
|
51
|
+
active: boolean("active").notNull().default(true),
|
|
52
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
53
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
54
|
+
}, (table) => [
|
|
55
|
+
index("idx_contract_templates_scope").on(table.scope),
|
|
56
|
+
index("idx_contract_templates_language").on(table.language),
|
|
57
|
+
index("idx_contract_templates_active").on(table.active),
|
|
58
|
+
uniqueIndex("uq_contract_templates_slug").on(table.slug),
|
|
59
|
+
]);
|
|
60
|
+
// ---------- contract_template_versions ----------
|
|
61
|
+
export const contractTemplateVersions = pgTable("contract_template_versions", {
|
|
62
|
+
id: typeId("contract_template_versions"),
|
|
63
|
+
templateId: typeIdRef("template_id")
|
|
64
|
+
.notNull()
|
|
65
|
+
.references(() => contractTemplates.id, { onDelete: "cascade" }),
|
|
66
|
+
version: integer("version").notNull(),
|
|
67
|
+
bodyFormat: contractBodyFormatEnum("body_format").notNull().default("markdown"),
|
|
68
|
+
body: text("body").notNull(),
|
|
69
|
+
variableSchema: jsonb("variable_schema"),
|
|
70
|
+
changelog: text("changelog"),
|
|
71
|
+
createdBy: text("created_by"),
|
|
72
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
73
|
+
}, (table) => [
|
|
74
|
+
index("idx_contract_template_versions_template").on(table.templateId),
|
|
75
|
+
uniqueIndex("uq_contract_template_versions_template_version").on(table.templateId, table.version),
|
|
76
|
+
]);
|
|
77
|
+
// ---------- contract_number_series ----------
|
|
78
|
+
export const contractNumberSeries = pgTable("contract_number_series", {
|
|
79
|
+
id: typeId("contract_number_series"),
|
|
80
|
+
code: text("code").notNull().unique(),
|
|
81
|
+
name: text("name").notNull(),
|
|
82
|
+
prefix: text("prefix").notNull().default(""),
|
|
83
|
+
separator: text("separator").notNull().default(""),
|
|
84
|
+
padLength: integer("pad_length").notNull().default(4),
|
|
85
|
+
currentSequence: integer("current_sequence").notNull().default(0),
|
|
86
|
+
resetStrategy: contractNumberResetStrategyEnum("reset_strategy").notNull().default("never"),
|
|
87
|
+
resetAt: timestamp("reset_at", { withTimezone: true }),
|
|
88
|
+
scope: contractScopeEnum("scope").notNull().default("customer"),
|
|
89
|
+
active: boolean("active").notNull().default(true),
|
|
90
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
91
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
92
|
+
}, (table) => [
|
|
93
|
+
uniqueIndex("uq_contract_number_series_code").on(table.code),
|
|
94
|
+
index("idx_contract_number_series_scope").on(table.scope),
|
|
95
|
+
index("idx_contract_number_series_active").on(table.active),
|
|
96
|
+
]);
|
|
97
|
+
// ---------- contracts ----------
|
|
98
|
+
export const contracts = pgTable("contracts", {
|
|
99
|
+
id: typeId("contracts"),
|
|
100
|
+
contractNumber: text("contract_number").unique(),
|
|
101
|
+
scope: contractScopeEnum("scope").notNull(),
|
|
102
|
+
status: contractStatusEnum("status").notNull().default("draft"),
|
|
103
|
+
title: text("title").notNull(),
|
|
104
|
+
templateVersionId: typeIdRef("template_version_id").references(() => contractTemplateVersions.id, { onDelete: "set null" }),
|
|
105
|
+
seriesId: typeIdRef("series_id").references(() => contractNumberSeries.id, {
|
|
106
|
+
onDelete: "set null",
|
|
107
|
+
}),
|
|
108
|
+
personId: typeIdRef("person_id").references(() => people.id, { onDelete: "set null" }),
|
|
109
|
+
organizationId: typeIdRef("organization_id").references(() => organizations.id, {
|
|
110
|
+
onDelete: "set null",
|
|
111
|
+
}),
|
|
112
|
+
supplierId: typeIdRef("supplier_id").references(() => suppliers.id, {
|
|
113
|
+
onDelete: "set null",
|
|
114
|
+
}),
|
|
115
|
+
channelId: typeIdRef("channel_id"),
|
|
116
|
+
bookingId: typeIdRef("booking_id"),
|
|
117
|
+
orderId: typeIdRef("order_id"),
|
|
118
|
+
issuedAt: timestamp("issued_at", { withTimezone: true }),
|
|
119
|
+
sentAt: timestamp("sent_at", { withTimezone: true }),
|
|
120
|
+
executedAt: timestamp("executed_at", { withTimezone: true }),
|
|
121
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }),
|
|
122
|
+
voidedAt: timestamp("voided_at", { withTimezone: true }),
|
|
123
|
+
language: text("language").notNull().default("en"),
|
|
124
|
+
renderedBodyFormat: contractBodyFormatEnum("rendered_body_format")
|
|
125
|
+
.notNull()
|
|
126
|
+
.default("markdown"),
|
|
127
|
+
renderedBody: text("rendered_body"),
|
|
128
|
+
variables: jsonb("variables"),
|
|
129
|
+
metadata: jsonb("metadata"),
|
|
130
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
131
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
132
|
+
}, (table) => [
|
|
133
|
+
index("idx_contracts_scope").on(table.scope),
|
|
134
|
+
index("idx_contracts_status").on(table.status),
|
|
135
|
+
index("idx_contracts_template_version").on(table.templateVersionId),
|
|
136
|
+
index("idx_contracts_series").on(table.seriesId),
|
|
137
|
+
index("idx_contracts_person").on(table.personId),
|
|
138
|
+
index("idx_contracts_organization").on(table.organizationId),
|
|
139
|
+
index("idx_contracts_supplier").on(table.supplierId),
|
|
140
|
+
index("idx_contracts_booking").on(table.bookingId),
|
|
141
|
+
index("idx_contracts_order").on(table.orderId),
|
|
142
|
+
index("idx_contracts_contract_number").on(table.contractNumber),
|
|
143
|
+
]);
|
|
144
|
+
// ---------- contract_signatures ----------
|
|
145
|
+
export const contractSignatures = pgTable("contract_signatures", {
|
|
146
|
+
id: typeId("contract_signatures"),
|
|
147
|
+
contractId: typeIdRef("contract_id")
|
|
148
|
+
.notNull()
|
|
149
|
+
.references(() => contracts.id, { onDelete: "cascade" }),
|
|
150
|
+
signerName: text("signer_name").notNull(),
|
|
151
|
+
signerEmail: text("signer_email"),
|
|
152
|
+
signerRole: text("signer_role"),
|
|
153
|
+
personId: typeIdRef("person_id").references(() => people.id, { onDelete: "set null" }),
|
|
154
|
+
method: contractSignatureMethodEnum("method").notNull().default("manual"),
|
|
155
|
+
provider: text("provider"),
|
|
156
|
+
externalReference: text("external_reference"),
|
|
157
|
+
signatureData: text("signature_data"),
|
|
158
|
+
ipAddress: text("ip_address"),
|
|
159
|
+
userAgent: text("user_agent"),
|
|
160
|
+
signedAt: timestamp("signed_at", { withTimezone: true }).notNull().defaultNow(),
|
|
161
|
+
metadata: jsonb("metadata"),
|
|
162
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
163
|
+
}, (table) => [
|
|
164
|
+
index("idx_contract_signatures_contract").on(table.contractId),
|
|
165
|
+
index("idx_contract_signatures_person").on(table.personId),
|
|
166
|
+
index("idx_contract_signatures_method").on(table.method),
|
|
167
|
+
]);
|
|
168
|
+
// ---------- contract_attachments ----------
|
|
169
|
+
export const contractAttachments = pgTable("contract_attachments", {
|
|
170
|
+
id: typeId("contract_attachments"),
|
|
171
|
+
contractId: typeIdRef("contract_id")
|
|
172
|
+
.notNull()
|
|
173
|
+
.references(() => contracts.id, { onDelete: "cascade" }),
|
|
174
|
+
kind: text("kind").notNull().default("appendix"),
|
|
175
|
+
name: text("name").notNull(),
|
|
176
|
+
mimeType: text("mime_type"),
|
|
177
|
+
fileSize: integer("file_size"),
|
|
178
|
+
storageKey: text("storage_key"),
|
|
179
|
+
checksum: text("checksum"),
|
|
180
|
+
metadata: jsonb("metadata"),
|
|
181
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
182
|
+
}, (table) => [index("idx_contract_attachments_contract").on(table.contractId)]);
|
|
183
|
+
// ---------- relations ----------
|
|
184
|
+
export const contractTemplatesRelations = relations(contractTemplates, ({ many }) => ({
|
|
185
|
+
versions: many(contractTemplateVersions),
|
|
186
|
+
}));
|
|
187
|
+
export const contractTemplateVersionsRelations = relations(contractTemplateVersions, ({ one, many }) => ({
|
|
188
|
+
template: one(contractTemplates, {
|
|
189
|
+
fields: [contractTemplateVersions.templateId],
|
|
190
|
+
references: [contractTemplates.id],
|
|
191
|
+
}),
|
|
192
|
+
contracts: many(contracts),
|
|
193
|
+
}));
|
|
194
|
+
export const contractNumberSeriesRelations = relations(contractNumberSeries, ({ many }) => ({
|
|
195
|
+
contracts: many(contracts),
|
|
196
|
+
}));
|
|
197
|
+
export const contractsRelations = relations(contracts, ({ one, many }) => ({
|
|
198
|
+
templateVersion: one(contractTemplateVersions, {
|
|
199
|
+
fields: [contracts.templateVersionId],
|
|
200
|
+
references: [contractTemplateVersions.id],
|
|
201
|
+
}),
|
|
202
|
+
series: one(contractNumberSeries, {
|
|
203
|
+
fields: [contracts.seriesId],
|
|
204
|
+
references: [contractNumberSeries.id],
|
|
205
|
+
}),
|
|
206
|
+
person: one(people, { fields: [contracts.personId], references: [people.id] }),
|
|
207
|
+
organization: one(organizations, {
|
|
208
|
+
fields: [contracts.organizationId],
|
|
209
|
+
references: [organizations.id],
|
|
210
|
+
}),
|
|
211
|
+
supplier: one(suppliers, { fields: [contracts.supplierId], references: [suppliers.id] }),
|
|
212
|
+
signatures: many(contractSignatures),
|
|
213
|
+
attachments: many(contractAttachments),
|
|
214
|
+
}));
|
|
215
|
+
export const contractSignaturesRelations = relations(contractSignatures, ({ one }) => ({
|
|
216
|
+
contract: one(contracts, {
|
|
217
|
+
fields: [contractSignatures.contractId],
|
|
218
|
+
references: [contracts.id],
|
|
219
|
+
}),
|
|
220
|
+
person: one(people, { fields: [contractSignatures.personId], references: [people.id] }),
|
|
221
|
+
}));
|
|
222
|
+
export const contractAttachmentsRelations = relations(contractAttachments, ({ one }) => ({
|
|
223
|
+
contract: one(contracts, {
|
|
224
|
+
fields: [contractAttachments.contractId],
|
|
225
|
+
references: [contracts.id],
|
|
226
|
+
}),
|
|
227
|
+
}));
|