@voyantjs/legal 0.2.0 → 0.3.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.
@@ -1,54 +1,31 @@
1
- import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
- import type { z } from "zod";
3
- import type { contractListQuerySchema, contractTemplateListQuerySchema, insertContractAttachmentSchema, insertContractNumberSeriesSchema, insertContractSchema, insertContractSignatureSchema, insertContractTemplateSchema, insertContractTemplateVersionSchema, renderTemplateInputSchema, updateContractAttachmentSchema, updateContractNumberSeriesSchema, updateContractSchema, updateContractTemplateSchema } from "./validation.js";
4
- type ContractListQuery = z.infer<typeof contractListQuerySchema>;
5
- type ContractTemplateListQuery = z.infer<typeof contractTemplateListQuerySchema>;
6
- type CreateContractTemplateInput = z.infer<typeof insertContractTemplateSchema>;
7
- type UpdateContractTemplateInput = z.infer<typeof updateContractTemplateSchema>;
8
- type CreateContractTemplateVersionInput = z.infer<typeof insertContractTemplateVersionSchema>;
9
- type CreateContractNumberSeriesInput = z.infer<typeof insertContractNumberSeriesSchema>;
10
- type UpdateContractNumberSeriesInput = z.infer<typeof updateContractNumberSeriesSchema>;
11
- type CreateContractInput = z.infer<typeof insertContractSchema>;
12
- type UpdateContractInput = z.infer<typeof updateContractSchema>;
13
- type CreateContractSignatureInput = z.infer<typeof insertContractSignatureSchema>;
14
- type CreateContractAttachmentInput = z.infer<typeof insertContractAttachmentSchema>;
15
- type UpdateContractAttachmentInput = z.infer<typeof updateContractAttachmentSchema>;
16
- type RenderTemplateInput = z.infer<typeof renderTemplateInputSchema>;
17
- /**
18
- * Substitute variables in a template body. Supports:
19
- * - markdown / html / plain text: mustache replacement `{{path.to.value}}`
20
- * - lexical_json: walks the AST, rewriting text nodes only
21
- */
22
- export declare function renderTemplate(body: string, bodyFormat: "markdown" | "html" | "lexical_json", variables: Record<string, unknown>): string;
23
- /**
24
- * Validate variable values against a template's variableSchema (JSON object
25
- * shape describing required fields). Returns a list of issues; empty array
26
- * means valid.
27
- */
28
- export declare function validateTemplateVariables(variableSchema: unknown, values: Record<string, unknown>): string[];
29
- /**
30
- * Transactionally allocate the next sequence number for a series. Honors the
31
- * reset strategy (never/annual/monthly). Uses SELECT ... FOR UPDATE to avoid
32
- * concurrent-increment races.
33
- */
34
- export declare function allocateContractNumber(db: PostgresJsDatabase, seriesId: string): Promise<{
35
- number: string;
36
- sequence: number;
37
- } | null>;
1
+ import { allocateContractNumber, renderTemplate, validateTemplateVariables } from "./service-shared.js";
2
+ export { allocateContractNumber, renderTemplate, validateTemplateVariables };
38
3
  export declare const contractsService: {
39
- listTemplates(db: PostgresJsDatabase, query: ContractTemplateListQuery): Promise<{
4
+ listContracts(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, query: import("./service-shared.js").ContractListQuery): Promise<{
40
5
  data: {
41
6
  id: string;
42
- name: string;
43
- slug: string;
7
+ contractNumber: string | null;
44
8
  scope: "customer" | "partner" | "supplier" | "other" | "channel";
9
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
10
+ title: string;
11
+ templateVersionId: string | null;
12
+ seriesId: string | null;
13
+ personId: string | null;
14
+ organizationId: string | null;
15
+ supplierId: string | null;
16
+ channelId: string | null;
17
+ bookingId: string | null;
18
+ orderId: string | null;
19
+ issuedAt: Date | null;
20
+ sentAt: Date | null;
21
+ executedAt: Date | null;
22
+ expiresAt: Date | null;
23
+ voidedAt: Date | null;
45
24
  language: string;
46
- description: string | null;
47
- bodyFormat: "markdown" | "html" | "lexical_json";
48
- body: string;
49
- variableSchema: unknown;
50
- currentVersionId: string | null;
51
- active: boolean;
25
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
26
+ renderedBody: string | null;
27
+ variables: unknown;
28
+ metadata: unknown;
52
29
  createdAt: Date;
53
30
  updatedAt: Date;
54
31
  }[];
@@ -56,58 +33,206 @@ export declare const contractsService: {
56
33
  limit: number;
57
34
  offset: number;
58
35
  }>;
59
- getTemplateById(db: PostgresJsDatabase, id: string): Promise<{
36
+ getContractById(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
60
37
  id: string;
61
- name: string;
62
- slug: string;
38
+ contractNumber: string | null;
63
39
  scope: "customer" | "partner" | "supplier" | "other" | "channel";
40
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
41
+ title: string;
42
+ templateVersionId: string | null;
43
+ seriesId: string | null;
44
+ personId: string | null;
45
+ organizationId: string | null;
46
+ supplierId: string | null;
47
+ channelId: string | null;
48
+ bookingId: string | null;
49
+ orderId: string | null;
50
+ issuedAt: Date | null;
51
+ sentAt: Date | null;
52
+ executedAt: Date | null;
53
+ expiresAt: Date | null;
54
+ voidedAt: Date | null;
64
55
  language: string;
65
- description: string | null;
66
- bodyFormat: "markdown" | "html" | "lexical_json";
67
- body: string;
68
- variableSchema: unknown;
69
- currentVersionId: string | null;
70
- active: boolean;
56
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
57
+ renderedBody: string | null;
58
+ variables: unknown;
59
+ metadata: unknown;
71
60
  createdAt: Date;
72
61
  updatedAt: Date;
73
62
  } | null>;
74
- createTemplate(db: PostgresJsDatabase, data: CreateContractTemplateInput): Promise<{
63
+ createContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, data: import("./service-shared.js").CreateContractInput): Promise<{
75
64
  id: string;
76
- name: string;
77
- active: boolean;
65
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
78
66
  createdAt: Date;
79
67
  updatedAt: Date;
80
- description: string | null;
81
- slug: string;
68
+ organizationId: string | null;
69
+ personId: string | null;
70
+ sentAt: Date | null;
71
+ title: string;
72
+ metadata: unknown;
73
+ supplierId: string | null;
82
74
  scope: "customer" | "partner" | "supplier" | "other" | "channel";
83
75
  language: string;
84
- bodyFormat: "markdown" | "html" | "lexical_json";
85
- body: string;
86
- variableSchema: unknown;
87
- currentVersionId: string | null;
76
+ contractNumber: string | null;
77
+ templateVersionId: string | null;
78
+ seriesId: string | null;
79
+ channelId: string | null;
80
+ bookingId: string | null;
81
+ orderId: string | null;
82
+ issuedAt: Date | null;
83
+ executedAt: Date | null;
84
+ expiresAt: Date | null;
85
+ voidedAt: Date | null;
86
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
87
+ renderedBody: string | null;
88
+ variables: unknown;
88
89
  } | null>;
89
- updateTemplate(db: PostgresJsDatabase, id: string, data: UpdateContractTemplateInput): Promise<{
90
+ updateContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string, data: import("./service-shared.js").UpdateContractInput): Promise<{
90
91
  id: string;
91
- name: string;
92
- slug: string;
92
+ contractNumber: string | null;
93
93
  scope: "customer" | "partner" | "supplier" | "other" | "channel";
94
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
95
+ title: string;
96
+ templateVersionId: string | null;
97
+ seriesId: string | null;
98
+ personId: string | null;
99
+ organizationId: string | null;
100
+ supplierId: string | null;
101
+ channelId: string | null;
102
+ bookingId: string | null;
103
+ orderId: string | null;
104
+ issuedAt: Date | null;
105
+ sentAt: Date | null;
106
+ executedAt: Date | null;
107
+ expiresAt: Date | null;
108
+ voidedAt: Date | null;
94
109
  language: string;
95
- description: string | null;
96
- bodyFormat: "markdown" | "html" | "lexical_json";
97
- body: string;
98
- variableSchema: unknown;
99
- currentVersionId: string | null;
100
- active: boolean;
110
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
111
+ renderedBody: string | null;
112
+ variables: unknown;
113
+ metadata: unknown;
101
114
  createdAt: Date;
102
115
  updatedAt: Date;
103
116
  } | null>;
104
- deleteTemplate(db: PostgresJsDatabase, id: string): Promise<{
105
- id: string;
106
- } | null>;
107
- listTemplateVersions(db: PostgresJsDatabase, templateId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"contract_template_versions", {
117
+ deleteContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
118
+ status: "not_found";
119
+ } | {
120
+ status: "not_draft";
121
+ } | {
122
+ status: "deleted";
123
+ }>;
124
+ issueContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string): Promise<{
125
+ status: "not_found";
126
+ contract?: undefined;
127
+ } | {
128
+ status: "not_draft";
129
+ contract?: undefined;
130
+ } | {
131
+ status: "issued";
132
+ contract: {
133
+ id: string;
134
+ contractNumber: string | null;
135
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
136
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
137
+ title: string;
138
+ templateVersionId: string | null;
139
+ seriesId: string | null;
140
+ personId: string | null;
141
+ organizationId: string | null;
142
+ supplierId: string | null;
143
+ channelId: string | null;
144
+ bookingId: string | null;
145
+ orderId: string | null;
146
+ issuedAt: Date | null;
147
+ sentAt: Date | null;
148
+ executedAt: Date | null;
149
+ expiresAt: Date | null;
150
+ voidedAt: Date | null;
151
+ language: string;
152
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
153
+ renderedBody: string | null;
154
+ variables: unknown;
155
+ metadata: unknown;
156
+ createdAt: Date;
157
+ updatedAt: Date;
158
+ } | null;
159
+ }>;
160
+ sendContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string): Promise<{
161
+ status: "not_found";
162
+ contract?: undefined;
163
+ } | {
164
+ status: "not_issued";
165
+ contract?: undefined;
166
+ } | {
167
+ status: "sent";
168
+ contract: {
169
+ id: string;
170
+ contractNumber: string | null;
171
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
172
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
173
+ title: string;
174
+ templateVersionId: string | null;
175
+ seriesId: string | null;
176
+ personId: string | null;
177
+ organizationId: string | null;
178
+ supplierId: string | null;
179
+ channelId: string | null;
180
+ bookingId: string | null;
181
+ orderId: string | null;
182
+ issuedAt: Date | null;
183
+ sentAt: Date | null;
184
+ executedAt: Date | null;
185
+ expiresAt: Date | null;
186
+ voidedAt: Date | null;
187
+ language: string;
188
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
189
+ renderedBody: string | null;
190
+ variables: unknown;
191
+ metadata: unknown;
192
+ createdAt: Date;
193
+ updatedAt: Date;
194
+ } | null;
195
+ }>;
196
+ voidContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string): Promise<{
197
+ status: "not_found";
198
+ contract?: undefined;
199
+ } | {
200
+ status: "already_void";
201
+ contract?: undefined;
202
+ } | {
203
+ status: "voided";
204
+ contract: {
205
+ id: string;
206
+ contractNumber: string | null;
207
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
208
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
209
+ title: string;
210
+ templateVersionId: string | null;
211
+ seriesId: string | null;
212
+ personId: string | null;
213
+ organizationId: string | null;
214
+ supplierId: string | null;
215
+ channelId: string | null;
216
+ bookingId: string | null;
217
+ orderId: string | null;
218
+ issuedAt: Date | null;
219
+ sentAt: Date | null;
220
+ executedAt: Date | null;
221
+ expiresAt: Date | null;
222
+ voidedAt: Date | null;
223
+ language: string;
224
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
225
+ renderedBody: string | null;
226
+ variables: unknown;
227
+ metadata: unknown;
228
+ createdAt: Date;
229
+ updatedAt: Date;
230
+ } | null;
231
+ }>;
232
+ listSignatures(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"contract_signatures", {
108
233
  id: import("drizzle-orm/pg-core").PgColumn<{
109
234
  name: string;
110
- tableName: "contract_template_versions";
235
+ tableName: "contract_signatures";
111
236
  dataType: "string";
112
237
  columnType: "PgText";
113
238
  data: string;
@@ -122,9 +247,9 @@ export declare const contractsService: {
122
247
  identity: undefined;
123
248
  generated: undefined;
124
249
  }, {}, {}>;
125
- templateId: import("drizzle-orm/pg-core").PgColumn<{
250
+ contractId: import("drizzle-orm/pg-core").PgColumn<{
126
251
  name: string;
127
- tableName: "contract_template_versions";
252
+ tableName: "contract_signatures";
128
253
  dataType: "string";
129
254
  columnType: "PgText";
130
255
  data: string;
@@ -139,77 +264,43 @@ export declare const contractsService: {
139
264
  identity: undefined;
140
265
  generated: undefined;
141
266
  }, {}, {}>;
142
- version: import("drizzle-orm/pg-core").PgColumn<{
143
- name: "version";
144
- tableName: "contract_template_versions";
145
- dataType: "number";
146
- columnType: "PgInteger";
147
- data: number;
148
- driverParam: string | number;
267
+ signerName: import("drizzle-orm/pg-core").PgColumn<{
268
+ name: "signer_name";
269
+ tableName: "contract_signatures";
270
+ dataType: "string";
271
+ columnType: "PgText";
272
+ data: string;
273
+ driverParam: string;
149
274
  notNull: true;
150
275
  hasDefault: false;
151
276
  isPrimaryKey: false;
152
277
  isAutoincrement: false;
153
278
  hasRuntimeDefault: false;
154
- enumValues: undefined;
279
+ enumValues: [string, ...string[]];
155
280
  baseColumn: never;
156
281
  identity: undefined;
157
282
  generated: undefined;
158
283
  }, {}, {}>;
159
- bodyFormat: import("drizzle-orm/pg-core").PgColumn<{
160
- name: "body_format";
161
- tableName: "contract_template_versions";
162
- dataType: "string";
163
- columnType: "PgEnumColumn";
164
- data: "markdown" | "html" | "lexical_json";
165
- driverParam: string;
166
- notNull: true;
167
- hasDefault: true;
168
- isPrimaryKey: false;
169
- isAutoincrement: false;
170
- hasRuntimeDefault: false;
171
- enumValues: ["markdown", "html", "lexical_json"];
172
- baseColumn: never;
173
- identity: undefined;
174
- generated: undefined;
175
- }, {}, {}>;
176
- body: import("drizzle-orm/pg-core").PgColumn<{
177
- name: "body";
178
- tableName: "contract_template_versions";
284
+ signerEmail: import("drizzle-orm/pg-core").PgColumn<{
285
+ name: "signer_email";
286
+ tableName: "contract_signatures";
179
287
  dataType: "string";
180
288
  columnType: "PgText";
181
289
  data: string;
182
290
  driverParam: string;
183
- notNull: true;
184
- hasDefault: false;
185
- isPrimaryKey: false;
186
- isAutoincrement: false;
187
- hasRuntimeDefault: false;
188
- enumValues: [string, ...string[]];
189
- baseColumn: never;
190
- identity: undefined;
191
- generated: undefined;
192
- }, {}, {}>;
193
- variableSchema: import("drizzle-orm/pg-core").PgColumn<{
194
- name: "variable_schema";
195
- tableName: "contract_template_versions";
196
- dataType: "json";
197
- columnType: "PgJsonb";
198
- data: unknown;
199
- driverParam: unknown;
200
291
  notNull: false;
201
292
  hasDefault: false;
202
293
  isPrimaryKey: false;
203
294
  isAutoincrement: false;
204
295
  hasRuntimeDefault: false;
205
- enumValues: undefined;
296
+ enumValues: [string, ...string[]];
206
297
  baseColumn: never;
207
298
  identity: undefined;
208
299
  generated: undefined;
209
300
  }, {}, {}>;
210
- changelog: import("drizzle-orm/pg-core").PgColumn<{
211
- name: "changelog";
212
- tableName: "contract_template_versions";
301
+ signerRole: import("drizzle-orm/pg-core").PgColumn<{
302
+ name: "signer_role";
303
+ tableName: "contract_signatures";
213
304
  dataType: "string";
214
305
  columnType: "PgText";
215
306
  data: string;
@@ -224,9 +315,9 @@ export declare const contractsService: {
224
315
  identity: undefined;
225
316
  generated: undefined;
226
317
  }, {}, {}>;
227
- createdBy: import("drizzle-orm/pg-core").PgColumn<{
228
- name: "created_by";
229
- tableName: "contract_template_versions";
318
+ personId: import("drizzle-orm/pg-core").PgColumn<{
319
+ name: string;
320
+ tableName: "contract_signatures";
230
321
  dataType: "string";
231
322
  columnType: "PgText";
232
323
  data: string;
@@ -241,59 +332,48 @@ export declare const contractsService: {
241
332
  identity: undefined;
242
333
  generated: undefined;
243
334
  }, {}, {}>;
244
- createdAt: import("drizzle-orm/pg-core").PgColumn<{
245
- name: "created_at";
246
- tableName: "contract_template_versions";
247
- dataType: "date";
248
- columnType: "PgTimestamp";
249
- data: Date;
335
+ method: import("drizzle-orm/pg-core").PgColumn<{
336
+ name: "method";
337
+ tableName: "contract_signatures";
338
+ dataType: "string";
339
+ columnType: "PgEnumColumn";
340
+ data: "other" | "manual" | "electronic" | "docusign";
250
341
  driverParam: string;
251
342
  notNull: true;
252
343
  hasDefault: true;
253
344
  isPrimaryKey: false;
254
345
  isAutoincrement: false;
255
346
  hasRuntimeDefault: false;
256
- enumValues: undefined;
347
+ enumValues: ["manual", "electronic", "docusign", "other"];
257
348
  baseColumn: never;
258
349
  identity: undefined;
259
350
  generated: undefined;
260
351
  }, {}, {}>;
261
- }, "single", Record<"contract_template_versions", "not-null">, false, "where" | "orderBy", {
262
- id: string;
263
- templateId: string;
264
- version: number;
265
- bodyFormat: "markdown" | "html" | "lexical_json";
266
- body: string;
267
- variableSchema: unknown;
268
- changelog: string | null;
269
- createdBy: string | null;
270
- createdAt: Date;
271
- }[], {
272
- id: import("drizzle-orm/pg-core").PgColumn<{
273
- name: string;
274
- tableName: "contract_template_versions";
352
+ provider: import("drizzle-orm/pg-core").PgColumn<{
353
+ name: "provider";
354
+ tableName: "contract_signatures";
275
355
  dataType: "string";
276
356
  columnType: "PgText";
277
357
  data: string;
278
358
  driverParam: string;
279
- notNull: true;
280
- hasDefault: true;
281
- isPrimaryKey: true;
359
+ notNull: false;
360
+ hasDefault: false;
361
+ isPrimaryKey: false;
282
362
  isAutoincrement: false;
283
- hasRuntimeDefault: true;
363
+ hasRuntimeDefault: false;
284
364
  enumValues: [string, ...string[]];
285
365
  baseColumn: never;
286
366
  identity: undefined;
287
367
  generated: undefined;
288
368
  }, {}, {}>;
289
- templateId: import("drizzle-orm/pg-core").PgColumn<{
290
- name: string;
291
- tableName: "contract_template_versions";
369
+ externalReference: import("drizzle-orm/pg-core").PgColumn<{
370
+ name: "external_reference";
371
+ tableName: "contract_signatures";
292
372
  dataType: "string";
293
373
  columnType: "PgText";
294
374
  data: string;
295
375
  driverParam: string;
296
- notNull: true;
376
+ notNull: false;
297
377
  hasDefault: false;
298
378
  isPrimaryKey: false;
299
379
  isAutoincrement: false;
@@ -303,48 +383,31 @@ export declare const contractsService: {
303
383
  identity: undefined;
304
384
  generated: undefined;
305
385
  }, {}, {}>;
306
- version: import("drizzle-orm/pg-core").PgColumn<{
307
- name: "version";
308
- tableName: "contract_template_versions";
309
- dataType: "number";
310
- columnType: "PgInteger";
311
- data: number;
312
- driverParam: string | number;
313
- notNull: true;
314
- hasDefault: false;
315
- isPrimaryKey: false;
316
- isAutoincrement: false;
317
- hasRuntimeDefault: false;
318
- enumValues: undefined;
319
- baseColumn: never;
320
- identity: undefined;
321
- generated: undefined;
322
- }, {}, {}>;
323
- bodyFormat: import("drizzle-orm/pg-core").PgColumn<{
324
- name: "body_format";
325
- tableName: "contract_template_versions";
386
+ signatureData: import("drizzle-orm/pg-core").PgColumn<{
387
+ name: "signature_data";
388
+ tableName: "contract_signatures";
326
389
  dataType: "string";
327
- columnType: "PgEnumColumn";
328
- data: "markdown" | "html" | "lexical_json";
390
+ columnType: "PgText";
391
+ data: string;
329
392
  driverParam: string;
330
- notNull: true;
331
- hasDefault: true;
393
+ notNull: false;
394
+ hasDefault: false;
332
395
  isPrimaryKey: false;
333
396
  isAutoincrement: false;
334
397
  hasRuntimeDefault: false;
335
- enumValues: ["markdown", "html", "lexical_json"];
398
+ enumValues: [string, ...string[]];
336
399
  baseColumn: never;
337
400
  identity: undefined;
338
401
  generated: undefined;
339
402
  }, {}, {}>;
340
- body: import("drizzle-orm/pg-core").PgColumn<{
341
- name: "body";
342
- tableName: "contract_template_versions";
403
+ ipAddress: import("drizzle-orm/pg-core").PgColumn<{
404
+ name: "ip_address";
405
+ tableName: "contract_signatures";
343
406
  dataType: "string";
344
407
  columnType: "PgText";
345
408
  data: string;
346
409
  driverParam: string;
347
- notNull: true;
410
+ notNull: false;
348
411
  hasDefault: false;
349
412
  isPrimaryKey: false;
350
413
  isAutoincrement: false;
@@ -354,60 +417,60 @@ export declare const contractsService: {
354
417
  identity: undefined;
355
418
  generated: undefined;
356
419
  }, {}, {}>;
357
- variableSchema: import("drizzle-orm/pg-core").PgColumn<{
358
- name: "variable_schema";
359
- tableName: "contract_template_versions";
360
- dataType: "json";
361
- columnType: "PgJsonb";
362
- data: unknown;
363
- driverParam: unknown;
420
+ userAgent: import("drizzle-orm/pg-core").PgColumn<{
421
+ name: "user_agent";
422
+ tableName: "contract_signatures";
423
+ dataType: "string";
424
+ columnType: "PgText";
425
+ data: string;
426
+ driverParam: string;
364
427
  notNull: false;
365
428
  hasDefault: false;
366
429
  isPrimaryKey: false;
367
430
  isAutoincrement: false;
368
431
  hasRuntimeDefault: false;
369
- enumValues: undefined;
432
+ enumValues: [string, ...string[]];
370
433
  baseColumn: never;
371
434
  identity: undefined;
372
435
  generated: undefined;
373
436
  }, {}, {}>;
374
- changelog: import("drizzle-orm/pg-core").PgColumn<{
375
- name: "changelog";
376
- tableName: "contract_template_versions";
377
- dataType: "string";
378
- columnType: "PgText";
379
- data: string;
437
+ signedAt: import("drizzle-orm/pg-core").PgColumn<{
438
+ name: "signed_at";
439
+ tableName: "contract_signatures";
440
+ dataType: "date";
441
+ columnType: "PgTimestamp";
442
+ data: Date;
380
443
  driverParam: string;
381
- notNull: false;
382
- hasDefault: false;
444
+ notNull: true;
445
+ hasDefault: true;
383
446
  isPrimaryKey: false;
384
447
  isAutoincrement: false;
385
448
  hasRuntimeDefault: false;
386
- enumValues: [string, ...string[]];
449
+ enumValues: undefined;
387
450
  baseColumn: never;
388
451
  identity: undefined;
389
452
  generated: undefined;
390
453
  }, {}, {}>;
391
- createdBy: import("drizzle-orm/pg-core").PgColumn<{
392
- name: "created_by";
393
- tableName: "contract_template_versions";
394
- dataType: "string";
395
- columnType: "PgText";
396
- data: string;
397
- driverParam: string;
454
+ metadata: import("drizzle-orm/pg-core").PgColumn<{
455
+ name: "metadata";
456
+ tableName: "contract_signatures";
457
+ dataType: "json";
458
+ columnType: "PgJsonb";
459
+ data: unknown;
460
+ driverParam: unknown;
398
461
  notNull: false;
399
462
  hasDefault: false;
400
463
  isPrimaryKey: false;
401
464
  isAutoincrement: false;
402
465
  hasRuntimeDefault: false;
403
- enumValues: [string, ...string[]];
466
+ enumValues: undefined;
404
467
  baseColumn: never;
405
468
  identity: undefined;
406
469
  generated: undefined;
407
470
  }, {}, {}>;
408
471
  createdAt: import("drizzle-orm/pg-core").PgColumn<{
409
472
  name: "created_at";
410
- tableName: "contract_template_versions";
473
+ tableName: "contract_signatures";
411
474
  dataType: "date";
412
475
  columnType: "PgTimestamp";
413
476
  data: Date;
@@ -422,326 +485,23 @@ export declare const contractsService: {
422
485
  identity: undefined;
423
486
  generated: undefined;
424
487
  }, {}, {}>;
425
- }>, "where" | "orderBy">;
426
- getTemplateVersionById(db: PostgresJsDatabase, id: string): Promise<{
427
- id: string;
428
- templateId: string;
429
- version: number;
430
- bodyFormat: "markdown" | "html" | "lexical_json";
431
- body: string;
432
- variableSchema: unknown;
433
- changelog: string | null;
434
- createdBy: string | null;
435
- createdAt: Date;
436
- } | null>;
437
- createTemplateVersion(db: PostgresJsDatabase, templateId: string, data: CreateContractTemplateVersionInput): Promise<{
438
- id: string;
439
- createdAt: Date;
440
- bodyFormat: "markdown" | "html" | "lexical_json";
441
- body: string;
442
- variableSchema: unknown;
443
- templateId: string;
444
- version: number;
445
- changelog: string | null;
446
- createdBy: string | null;
447
- } | null>;
448
- listSeries(db: PostgresJsDatabase): Promise<{
449
- id: string;
450
- code: string;
451
- name: string;
452
- prefix: string;
453
- separator: string;
454
- padLength: number;
455
- currentSequence: number;
456
- resetStrategy: "never" | "annual" | "monthly";
457
- resetAt: Date | null;
458
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
459
- active: boolean;
460
- createdAt: Date;
461
- updatedAt: Date;
462
- }[]>;
463
- getSeriesById(db: PostgresJsDatabase, id: string): Promise<{
464
- id: string;
465
- code: string;
466
- name: string;
467
- prefix: string;
468
- separator: string;
469
- padLength: number;
470
- currentSequence: number;
471
- resetStrategy: "never" | "annual" | "monthly";
472
- resetAt: Date | null;
473
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
474
- active: boolean;
475
- createdAt: Date;
476
- updatedAt: Date;
477
- } | null>;
478
- createSeries(db: PostgresJsDatabase, data: CreateContractNumberSeriesInput): Promise<{
479
- id: string;
480
- name: string;
481
- active: boolean;
482
- createdAt: Date;
483
- updatedAt: Date;
484
- code: string;
485
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
486
- prefix: string;
487
- separator: string;
488
- padLength: number;
489
- currentSequence: number;
490
- resetStrategy: "never" | "annual" | "monthly";
491
- resetAt: Date | null;
492
- } | null>;
493
- updateSeries(db: PostgresJsDatabase, id: string, data: UpdateContractNumberSeriesInput): Promise<{
494
- id: string;
495
- code: string;
496
- name: string;
497
- prefix: string;
498
- separator: string;
499
- padLength: number;
500
- currentSequence: number;
501
- resetStrategy: "never" | "annual" | "monthly";
502
- resetAt: Date | null;
503
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
504
- active: boolean;
505
- createdAt: Date;
506
- updatedAt: Date;
507
- } | null>;
508
- deleteSeries(db: PostgresJsDatabase, id: string): Promise<{
509
- id: string;
510
- } | null>;
511
- listContracts(db: PostgresJsDatabase, query: ContractListQuery): Promise<{
512
- data: {
513
- id: string;
514
- contractNumber: string | null;
515
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
516
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
517
- title: string;
518
- templateVersionId: string | null;
519
- seriesId: string | null;
520
- personId: string | null;
521
- organizationId: string | null;
522
- supplierId: string | null;
523
- channelId: string | null;
524
- bookingId: string | null;
525
- orderId: string | null;
526
- issuedAt: Date | null;
527
- sentAt: Date | null;
528
- executedAt: Date | null;
529
- expiresAt: Date | null;
530
- voidedAt: Date | null;
531
- language: string;
532
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
533
- renderedBody: string | null;
534
- variables: unknown;
535
- metadata: unknown;
536
- createdAt: Date;
537
- updatedAt: Date;
538
- }[];
539
- total: number;
540
- limit: number;
541
- offset: number;
542
- }>;
543
- getContractById(db: PostgresJsDatabase, id: string): Promise<{
544
- id: string;
545
- contractNumber: string | null;
546
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
547
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
548
- title: string;
549
- templateVersionId: string | null;
550
- seriesId: string | null;
551
- personId: string | null;
552
- organizationId: string | null;
553
- supplierId: string | null;
554
- channelId: string | null;
555
- bookingId: string | null;
556
- orderId: string | null;
557
- issuedAt: Date | null;
558
- sentAt: Date | null;
559
- executedAt: Date | null;
560
- expiresAt: Date | null;
561
- voidedAt: Date | null;
562
- language: string;
563
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
564
- renderedBody: string | null;
565
- variables: unknown;
566
- metadata: unknown;
567
- createdAt: Date;
568
- updatedAt: Date;
569
- } | null>;
570
- createContract(db: PostgresJsDatabase, data: CreateContractInput): Promise<{
571
- id: string;
572
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
573
- createdAt: Date;
574
- updatedAt: Date;
575
- organizationId: string | null;
576
- title: string;
577
- personId: string | null;
578
- sentAt: Date | null;
579
- metadata: unknown;
580
- supplierId: string | null;
581
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
582
- language: string;
583
- contractNumber: string | null;
584
- templateVersionId: string | null;
585
- seriesId: string | null;
586
- channelId: string | null;
587
- bookingId: string | null;
588
- orderId: string | null;
589
- issuedAt: Date | null;
590
- executedAt: Date | null;
591
- expiresAt: Date | null;
592
- voidedAt: Date | null;
593
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
594
- renderedBody: string | null;
595
- variables: unknown;
596
- } | null>;
597
- updateContract(db: PostgresJsDatabase, id: string, data: UpdateContractInput): Promise<{
488
+ }, "single", Record<"contract_signatures", "not-null">, false, "where" | "orderBy", {
598
489
  id: string;
599
- contractNumber: string | null;
600
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
601
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
602
- title: string;
603
- templateVersionId: string | null;
604
- seriesId: string | null;
490
+ contractId: string;
491
+ signerName: string;
492
+ signerEmail: string | null;
493
+ signerRole: string | null;
605
494
  personId: string | null;
606
- organizationId: string | null;
607
- supplierId: string | null;
608
- channelId: string | null;
609
- bookingId: string | null;
610
- orderId: string | null;
611
- issuedAt: Date | null;
612
- sentAt: Date | null;
613
- executedAt: Date | null;
614
- expiresAt: Date | null;
615
- voidedAt: Date | null;
616
- language: string;
617
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
618
- renderedBody: string | null;
619
- variables: unknown;
620
- metadata: unknown;
621
- createdAt: Date;
622
- updatedAt: Date;
623
- } | null>;
624
- deleteContract(db: PostgresJsDatabase, id: string): Promise<{
625
- status: "not_found";
626
- } | {
627
- status: "not_draft";
628
- } | {
629
- status: "deleted";
630
- }>;
631
- /**
632
- * Transition a draft contract to `issued`: renders body from the template
633
- * version, allocates a contract number if a series is set, timestamps
634
- * `issuedAt`. Returns null if contract is missing or not in `draft`.
635
- */
636
- issueContract(db: PostgresJsDatabase, contractId: string): Promise<{
637
- status: "not_found";
638
- contract?: undefined;
639
- } | {
640
- status: "not_draft";
641
- contract?: undefined;
642
- } | {
643
- status: "issued";
644
- contract: {
645
- id: string;
646
- contractNumber: string | null;
647
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
648
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
649
- title: string;
650
- templateVersionId: string | null;
651
- seriesId: string | null;
652
- personId: string | null;
653
- organizationId: string | null;
654
- supplierId: string | null;
655
- channelId: string | null;
656
- bookingId: string | null;
657
- orderId: string | null;
658
- issuedAt: Date | null;
659
- sentAt: Date | null;
660
- executedAt: Date | null;
661
- expiresAt: Date | null;
662
- voidedAt: Date | null;
663
- language: string;
664
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
665
- renderedBody: string | null;
666
- variables: unknown;
667
- metadata: unknown;
668
- createdAt: Date;
669
- updatedAt: Date;
670
- } | null;
671
- }>;
672
- sendContract(db: PostgresJsDatabase, contractId: string): Promise<{
673
- status: "not_found";
674
- contract?: undefined;
675
- } | {
676
- status: "not_issued";
677
- contract?: undefined;
678
- } | {
679
- status: "sent";
680
- contract: {
681
- id: string;
682
- contractNumber: string | null;
683
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
684
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
685
- title: string;
686
- templateVersionId: string | null;
687
- seriesId: string | null;
688
- personId: string | null;
689
- organizationId: string | null;
690
- supplierId: string | null;
691
- channelId: string | null;
692
- bookingId: string | null;
693
- orderId: string | null;
694
- issuedAt: Date | null;
695
- sentAt: Date | null;
696
- executedAt: Date | null;
697
- expiresAt: Date | null;
698
- voidedAt: Date | null;
699
- language: string;
700
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
701
- renderedBody: string | null;
702
- variables: unknown;
703
- metadata: unknown;
704
- createdAt: Date;
705
- updatedAt: Date;
706
- } | null;
707
- }>;
708
- voidContract(db: PostgresJsDatabase, contractId: string): Promise<{
709
- status: "not_found";
710
- contract?: undefined;
711
- } | {
712
- status: "already_void";
713
- contract?: undefined;
714
- } | {
715
- status: "voided";
716
- contract: {
717
- id: string;
718
- contractNumber: string | null;
719
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
720
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
721
- title: string;
722
- templateVersionId: string | null;
723
- seriesId: string | null;
724
- personId: string | null;
725
- organizationId: string | null;
726
- supplierId: string | null;
727
- channelId: string | null;
728
- bookingId: string | null;
729
- orderId: string | null;
730
- issuedAt: Date | null;
731
- sentAt: Date | null;
732
- executedAt: Date | null;
733
- expiresAt: Date | null;
734
- voidedAt: Date | null;
735
- language: string;
736
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
737
- renderedBody: string | null;
738
- variables: unknown;
739
- metadata: unknown;
740
- createdAt: Date;
741
- updatedAt: Date;
742
- } | null;
743
- }>;
744
- listSignatures(db: PostgresJsDatabase, contractId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"contract_signatures", {
495
+ method: "other" | "manual" | "electronic" | "docusign";
496
+ provider: string | null;
497
+ externalReference: string | null;
498
+ signatureData: string | null;
499
+ ipAddress: string | null;
500
+ userAgent: string | null;
501
+ signedAt: Date;
502
+ metadata: unknown;
503
+ createdAt: Date;
504
+ }[], {
745
505
  id: import("drizzle-orm/pg-core").PgColumn<{
746
506
  name: string;
747
507
  tableName: "contract_signatures";
@@ -997,26 +757,102 @@ export declare const contractsService: {
997
757
  identity: undefined;
998
758
  generated: undefined;
999
759
  }, {}, {}>;
1000
- }, "single", Record<"contract_signatures", "not-null">, false, "where" | "orderBy", {
1001
- id: string;
1002
- contractId: string;
1003
- signerName: string;
1004
- signerEmail: string | null;
1005
- signerRole: string | null;
1006
- personId: string | null;
1007
- method: "other" | "manual" | "electronic" | "docusign";
1008
- provider: string | null;
1009
- externalReference: string | null;
1010
- signatureData: string | null;
1011
- ipAddress: string | null;
1012
- userAgent: string | null;
1013
- signedAt: Date;
1014
- metadata: unknown;
1015
- createdAt: Date;
1016
- }[], {
760
+ }>, "where" | "orderBy">;
761
+ signContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string, data: import("./service-shared.js").CreateContractSignatureInput): Promise<{
762
+ status: "not_found";
763
+ contract?: undefined;
764
+ signature?: undefined;
765
+ } | {
766
+ status: "not_signable";
767
+ contract?: undefined;
768
+ signature?: undefined;
769
+ } | {
770
+ status: "signed";
771
+ contract: {
772
+ id: string;
773
+ contractNumber: string | null;
774
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
775
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
776
+ title: string;
777
+ templateVersionId: string | null;
778
+ seriesId: string | null;
779
+ personId: string | null;
780
+ organizationId: string | null;
781
+ supplierId: string | null;
782
+ channelId: string | null;
783
+ bookingId: string | null;
784
+ orderId: string | null;
785
+ issuedAt: Date | null;
786
+ sentAt: Date | null;
787
+ executedAt: Date | null;
788
+ expiresAt: Date | null;
789
+ voidedAt: Date | null;
790
+ language: string;
791
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
792
+ renderedBody: string | null;
793
+ variables: unknown;
794
+ metadata: unknown;
795
+ createdAt: Date;
796
+ updatedAt: Date;
797
+ } | null;
798
+ signature: {
799
+ id: string;
800
+ createdAt: Date;
801
+ personId: string | null;
802
+ metadata: unknown;
803
+ contractId: string;
804
+ signerName: string;
805
+ signerEmail: string | null;
806
+ signerRole: string | null;
807
+ method: "other" | "manual" | "electronic" | "docusign";
808
+ provider: string | null;
809
+ externalReference: string | null;
810
+ signatureData: string | null;
811
+ ipAddress: string | null;
812
+ userAgent: string | null;
813
+ signedAt: Date;
814
+ } | null;
815
+ }>;
816
+ executeContract(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string): Promise<{
817
+ status: "not_found";
818
+ contract?: undefined;
819
+ } | {
820
+ status: "not_signed";
821
+ contract?: undefined;
822
+ } | {
823
+ status: "executed";
824
+ contract: {
825
+ id: string;
826
+ contractNumber: string | null;
827
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
828
+ status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
829
+ title: string;
830
+ templateVersionId: string | null;
831
+ seriesId: string | null;
832
+ personId: string | null;
833
+ organizationId: string | null;
834
+ supplierId: string | null;
835
+ channelId: string | null;
836
+ bookingId: string | null;
837
+ orderId: string | null;
838
+ issuedAt: Date | null;
839
+ sentAt: Date | null;
840
+ executedAt: Date | null;
841
+ expiresAt: Date | null;
842
+ voidedAt: Date | null;
843
+ language: string;
844
+ renderedBodyFormat: "markdown" | "html" | "lexical_json";
845
+ renderedBody: string | null;
846
+ variables: unknown;
847
+ metadata: unknown;
848
+ createdAt: Date;
849
+ updatedAt: Date;
850
+ } | null;
851
+ }>;
852
+ listAttachments(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"contract_attachments", {
1017
853
  id: import("drizzle-orm/pg-core").PgColumn<{
1018
854
  name: string;
1019
- tableName: "contract_signatures";
855
+ tableName: "contract_attachments";
1020
856
  dataType: "string";
1021
857
  columnType: "PgText";
1022
858
  data: string;
@@ -1033,7 +869,7 @@ export declare const contractsService: {
1033
869
  }, {}, {}>;
1034
870
  contractId: import("drizzle-orm/pg-core").PgColumn<{
1035
871
  name: string;
1036
- tableName: "contract_signatures";
872
+ tableName: "contract_attachments";
1037
873
  dataType: "string";
1038
874
  columnType: "PgText";
1039
875
  data: string;
@@ -1048,9 +884,26 @@ export declare const contractsService: {
1048
884
  identity: undefined;
1049
885
  generated: undefined;
1050
886
  }, {}, {}>;
1051
- signerName: import("drizzle-orm/pg-core").PgColumn<{
1052
- name: "signer_name";
1053
- tableName: "contract_signatures";
887
+ kind: import("drizzle-orm/pg-core").PgColumn<{
888
+ name: "kind";
889
+ tableName: "contract_attachments";
890
+ dataType: "string";
891
+ columnType: "PgText";
892
+ data: string;
893
+ driverParam: string;
894
+ notNull: true;
895
+ hasDefault: true;
896
+ isPrimaryKey: false;
897
+ isAutoincrement: false;
898
+ hasRuntimeDefault: false;
899
+ enumValues: [string, ...string[]];
900
+ baseColumn: never;
901
+ identity: undefined;
902
+ generated: undefined;
903
+ }, {}, {}>;
904
+ name: import("drizzle-orm/pg-core").PgColumn<{
905
+ name: "name";
906
+ tableName: "contract_attachments";
1054
907
  dataType: "string";
1055
908
  columnType: "PgText";
1056
909
  data: string;
@@ -1065,9 +918,9 @@ export declare const contractsService: {
1065
918
  identity: undefined;
1066
919
  generated: undefined;
1067
920
  }, {}, {}>;
1068
- signerEmail: import("drizzle-orm/pg-core").PgColumn<{
1069
- name: "signer_email";
1070
- tableName: "contract_signatures";
921
+ mimeType: import("drizzle-orm/pg-core").PgColumn<{
922
+ name: "mime_type";
923
+ tableName: "contract_attachments";
1071
924
  dataType: "string";
1072
925
  columnType: "PgText";
1073
926
  data: string;
@@ -1082,9 +935,26 @@ export declare const contractsService: {
1082
935
  identity: undefined;
1083
936
  generated: undefined;
1084
937
  }, {}, {}>;
1085
- signerRole: import("drizzle-orm/pg-core").PgColumn<{
1086
- name: "signer_role";
1087
- tableName: "contract_signatures";
938
+ fileSize: import("drizzle-orm/pg-core").PgColumn<{
939
+ name: "file_size";
940
+ tableName: "contract_attachments";
941
+ dataType: "number";
942
+ columnType: "PgInteger";
943
+ data: number;
944
+ driverParam: string | number;
945
+ notNull: false;
946
+ hasDefault: false;
947
+ isPrimaryKey: false;
948
+ isAutoincrement: false;
949
+ hasRuntimeDefault: false;
950
+ enumValues: undefined;
951
+ baseColumn: never;
952
+ identity: undefined;
953
+ generated: undefined;
954
+ }, {}, {}>;
955
+ storageKey: import("drizzle-orm/pg-core").PgColumn<{
956
+ name: "storage_key";
957
+ tableName: "contract_attachments";
1088
958
  dataType: "string";
1089
959
  columnType: "PgText";
1090
960
  data: string;
@@ -1099,9 +969,9 @@ export declare const contractsService: {
1099
969
  identity: undefined;
1100
970
  generated: undefined;
1101
971
  }, {}, {}>;
1102
- personId: import("drizzle-orm/pg-core").PgColumn<{
1103
- name: string;
1104
- tableName: "contract_signatures";
972
+ checksum: import("drizzle-orm/pg-core").PgColumn<{
973
+ name: "checksum";
974
+ tableName: "contract_attachments";
1105
975
  dataType: "string";
1106
976
  columnType: "PgText";
1107
977
  data: string;
@@ -1116,31 +986,77 @@ export declare const contractsService: {
1116
986
  identity: undefined;
1117
987
  generated: undefined;
1118
988
  }, {}, {}>;
1119
- method: import("drizzle-orm/pg-core").PgColumn<{
1120
- name: "method";
1121
- tableName: "contract_signatures";
1122
- dataType: "string";
1123
- columnType: "PgEnumColumn";
1124
- data: "other" | "manual" | "electronic" | "docusign";
989
+ metadata: import("drizzle-orm/pg-core").PgColumn<{
990
+ name: "metadata";
991
+ tableName: "contract_attachments";
992
+ dataType: "json";
993
+ columnType: "PgJsonb";
994
+ data: unknown;
995
+ driverParam: unknown;
996
+ notNull: false;
997
+ hasDefault: false;
998
+ isPrimaryKey: false;
999
+ isAutoincrement: false;
1000
+ hasRuntimeDefault: false;
1001
+ enumValues: undefined;
1002
+ baseColumn: never;
1003
+ identity: undefined;
1004
+ generated: undefined;
1005
+ }, {}, {}>;
1006
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
1007
+ name: "created_at";
1008
+ tableName: "contract_attachments";
1009
+ dataType: "date";
1010
+ columnType: "PgTimestamp";
1011
+ data: Date;
1125
1012
  driverParam: string;
1126
1013
  notNull: true;
1127
1014
  hasDefault: true;
1128
1015
  isPrimaryKey: false;
1129
1016
  isAutoincrement: false;
1130
1017
  hasRuntimeDefault: false;
1131
- enumValues: ["manual", "electronic", "docusign", "other"];
1018
+ enumValues: undefined;
1132
1019
  baseColumn: never;
1133
1020
  identity: undefined;
1134
1021
  generated: undefined;
1135
1022
  }, {}, {}>;
1136
- provider: import("drizzle-orm/pg-core").PgColumn<{
1137
- name: "provider";
1138
- tableName: "contract_signatures";
1023
+ }, "single", Record<"contract_attachments", "not-null">, false, "where" | "orderBy", {
1024
+ id: string;
1025
+ contractId: string;
1026
+ kind: string;
1027
+ name: string;
1028
+ mimeType: string | null;
1029
+ fileSize: number | null;
1030
+ storageKey: string | null;
1031
+ checksum: string | null;
1032
+ metadata: unknown;
1033
+ createdAt: Date;
1034
+ }[], {
1035
+ id: import("drizzle-orm/pg-core").PgColumn<{
1036
+ name: string;
1037
+ tableName: "contract_attachments";
1139
1038
  dataType: "string";
1140
1039
  columnType: "PgText";
1141
1040
  data: string;
1142
1041
  driverParam: string;
1143
- notNull: false;
1042
+ notNull: true;
1043
+ hasDefault: true;
1044
+ isPrimaryKey: true;
1045
+ isAutoincrement: false;
1046
+ hasRuntimeDefault: true;
1047
+ enumValues: [string, ...string[]];
1048
+ baseColumn: never;
1049
+ identity: undefined;
1050
+ generated: undefined;
1051
+ }, {}, {}>;
1052
+ contractId: import("drizzle-orm/pg-core").PgColumn<{
1053
+ name: string;
1054
+ tableName: "contract_attachments";
1055
+ dataType: "string";
1056
+ columnType: "PgText";
1057
+ data: string;
1058
+ driverParam: string;
1059
+ notNull: true;
1144
1060
  hasDefault: false;
1145
1061
  isPrimaryKey: false;
1146
1062
  isAutoincrement: false;
@@ -1150,14 +1066,31 @@ export declare const contractsService: {
1150
1066
  identity: undefined;
1151
1067
  generated: undefined;
1152
1068
  }, {}, {}>;
1153
- externalReference: import("drizzle-orm/pg-core").PgColumn<{
1154
- name: "external_reference";
1155
- tableName: "contract_signatures";
1069
+ kind: import("drizzle-orm/pg-core").PgColumn<{
1070
+ name: "kind";
1071
+ tableName: "contract_attachments";
1072
+ dataType: "string";
1073
+ columnType: "PgText";
1074
+ data: string;
1075
+ driverParam: string;
1076
+ notNull: true;
1077
+ hasDefault: true;
1078
+ isPrimaryKey: false;
1079
+ isAutoincrement: false;
1080
+ hasRuntimeDefault: false;
1081
+ enumValues: [string, ...string[]];
1082
+ baseColumn: never;
1083
+ identity: undefined;
1084
+ generated: undefined;
1085
+ }, {}, {}>;
1086
+ name: import("drizzle-orm/pg-core").PgColumn<{
1087
+ name: "name";
1088
+ tableName: "contract_attachments";
1156
1089
  dataType: "string";
1157
1090
  columnType: "PgText";
1158
1091
  data: string;
1159
1092
  driverParam: string;
1160
- notNull: false;
1093
+ notNull: true;
1161
1094
  hasDefault: false;
1162
1095
  isPrimaryKey: false;
1163
1096
  isAutoincrement: false;
@@ -1167,9 +1100,9 @@ export declare const contractsService: {
1167
1100
  identity: undefined;
1168
1101
  generated: undefined;
1169
1102
  }, {}, {}>;
1170
- signatureData: import("drizzle-orm/pg-core").PgColumn<{
1171
- name: "signature_data";
1172
- tableName: "contract_signatures";
1103
+ mimeType: import("drizzle-orm/pg-core").PgColumn<{
1104
+ name: "mime_type";
1105
+ tableName: "contract_attachments";
1173
1106
  dataType: "string";
1174
1107
  columnType: "PgText";
1175
1108
  data: string;
@@ -1184,26 +1117,26 @@ export declare const contractsService: {
1184
1117
  identity: undefined;
1185
1118
  generated: undefined;
1186
1119
  }, {}, {}>;
1187
- ipAddress: import("drizzle-orm/pg-core").PgColumn<{
1188
- name: "ip_address";
1189
- tableName: "contract_signatures";
1190
- dataType: "string";
1191
- columnType: "PgText";
1192
- data: string;
1193
- driverParam: string;
1120
+ fileSize: import("drizzle-orm/pg-core").PgColumn<{
1121
+ name: "file_size";
1122
+ tableName: "contract_attachments";
1123
+ dataType: "number";
1124
+ columnType: "PgInteger";
1125
+ data: number;
1126
+ driverParam: string | number;
1194
1127
  notNull: false;
1195
1128
  hasDefault: false;
1196
1129
  isPrimaryKey: false;
1197
1130
  isAutoincrement: false;
1198
1131
  hasRuntimeDefault: false;
1199
- enumValues: [string, ...string[]];
1132
+ enumValues: undefined;
1200
1133
  baseColumn: never;
1201
1134
  identity: undefined;
1202
1135
  generated: undefined;
1203
1136
  }, {}, {}>;
1204
- userAgent: import("drizzle-orm/pg-core").PgColumn<{
1205
- name: "user_agent";
1206
- tableName: "contract_signatures";
1137
+ storageKey: import("drizzle-orm/pg-core").PgColumn<{
1138
+ name: "storage_key";
1139
+ tableName: "contract_attachments";
1207
1140
  dataType: "string";
1208
1141
  columnType: "PgText";
1209
1142
  data: string;
@@ -1218,26 +1151,26 @@ export declare const contractsService: {
1218
1151
  identity: undefined;
1219
1152
  generated: undefined;
1220
1153
  }, {}, {}>;
1221
- signedAt: import("drizzle-orm/pg-core").PgColumn<{
1222
- name: "signed_at";
1223
- tableName: "contract_signatures";
1224
- dataType: "date";
1225
- columnType: "PgTimestamp";
1226
- data: Date;
1154
+ checksum: import("drizzle-orm/pg-core").PgColumn<{
1155
+ name: "checksum";
1156
+ tableName: "contract_attachments";
1157
+ dataType: "string";
1158
+ columnType: "PgText";
1159
+ data: string;
1227
1160
  driverParam: string;
1228
- notNull: true;
1229
- hasDefault: true;
1161
+ notNull: false;
1162
+ hasDefault: false;
1230
1163
  isPrimaryKey: false;
1231
1164
  isAutoincrement: false;
1232
1165
  hasRuntimeDefault: false;
1233
- enumValues: undefined;
1166
+ enumValues: [string, ...string[]];
1234
1167
  baseColumn: never;
1235
1168
  identity: undefined;
1236
1169
  generated: undefined;
1237
1170
  }, {}, {}>;
1238
1171
  metadata: import("drizzle-orm/pg-core").PgColumn<{
1239
1172
  name: "metadata";
1240
- tableName: "contract_signatures";
1173
+ tableName: "contract_attachments";
1241
1174
  dataType: "json";
1242
1175
  columnType: "PgJsonb";
1243
1176
  data: unknown;
@@ -1254,7 +1187,7 @@ export declare const contractsService: {
1254
1187
  }, {}, {}>;
1255
1188
  createdAt: import("drizzle-orm/pg-core").PgColumn<{
1256
1189
  name: "created_at";
1257
- tableName: "contract_signatures";
1190
+ tableName: "contract_attachments";
1258
1191
  dataType: "date";
1259
1192
  columnType: "PgTimestamp";
1260
1193
  data: Date;
@@ -1270,101 +1203,168 @@ export declare const contractsService: {
1270
1203
  generated: undefined;
1271
1204
  }, {}, {}>;
1272
1205
  }>, "where" | "orderBy">;
1273
- signContract(db: PostgresJsDatabase, contractId: string, data: CreateContractSignatureInput): Promise<{
1274
- status: "not_found";
1275
- contract?: undefined;
1276
- signature?: undefined;
1277
- } | {
1278
- status: "not_signable";
1279
- contract?: undefined;
1280
- signature?: undefined;
1281
- } | {
1282
- status: "signed";
1283
- contract: {
1284
- id: string;
1285
- contractNumber: string | null;
1286
- scope: "customer" | "partner" | "supplier" | "other" | "channel";
1287
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
1288
- title: string;
1289
- templateVersionId: string | null;
1290
- seriesId: string | null;
1291
- personId: string | null;
1292
- organizationId: string | null;
1293
- supplierId: string | null;
1294
- channelId: string | null;
1295
- bookingId: string | null;
1296
- orderId: string | null;
1297
- issuedAt: Date | null;
1298
- sentAt: Date | null;
1299
- executedAt: Date | null;
1300
- expiresAt: Date | null;
1301
- voidedAt: Date | null;
1302
- language: string;
1303
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
1304
- renderedBody: string | null;
1305
- variables: unknown;
1306
- metadata: unknown;
1307
- createdAt: Date;
1308
- updatedAt: Date;
1309
- } | null;
1310
- signature: {
1311
- id: string;
1312
- createdAt: Date;
1313
- personId: string | null;
1314
- metadata: unknown;
1315
- contractId: string;
1316
- signerName: string;
1317
- signerEmail: string | null;
1318
- signerRole: string | null;
1319
- method: "other" | "manual" | "electronic" | "docusign";
1320
- provider: string | null;
1321
- externalReference: string | null;
1322
- signatureData: string | null;
1323
- ipAddress: string | null;
1324
- userAgent: string | null;
1325
- signedAt: Date;
1326
- } | null;
1327
- }>;
1328
- executeContract(db: PostgresJsDatabase, contractId: string): Promise<{
1329
- status: "not_found";
1330
- contract?: undefined;
1331
- } | {
1332
- status: "not_signed";
1333
- contract?: undefined;
1334
- } | {
1335
- status: "executed";
1336
- contract: {
1206
+ createAttachment(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, contractId: string, data: import("./service-shared.js").CreateContractAttachmentInput): Promise<{
1207
+ id: string;
1208
+ name: string;
1209
+ createdAt: Date;
1210
+ kind: string;
1211
+ metadata: unknown;
1212
+ contractId: string;
1213
+ mimeType: string | null;
1214
+ fileSize: number | null;
1215
+ storageKey: string | null;
1216
+ checksum: string | null;
1217
+ } | null>;
1218
+ updateAttachment(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, attachmentId: string, data: import("./service-shared.js").UpdateContractAttachmentInput): Promise<{
1219
+ id: string;
1220
+ contractId: string;
1221
+ kind: string;
1222
+ name: string;
1223
+ mimeType: string | null;
1224
+ fileSize: number | null;
1225
+ storageKey: string | null;
1226
+ checksum: string | null;
1227
+ metadata: unknown;
1228
+ createdAt: Date;
1229
+ } | null>;
1230
+ deleteAttachment(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, attachmentId: string): Promise<{
1231
+ id: string;
1232
+ } | null>;
1233
+ listSeries(db: import("drizzle-orm/postgres-js").PostgresJsDatabase): Promise<{
1234
+ id: string;
1235
+ code: string;
1236
+ name: string;
1237
+ prefix: string;
1238
+ separator: string;
1239
+ padLength: number;
1240
+ currentSequence: number;
1241
+ resetStrategy: "never" | "annual" | "monthly";
1242
+ resetAt: Date | null;
1243
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1244
+ active: boolean;
1245
+ createdAt: Date;
1246
+ updatedAt: Date;
1247
+ }[]>;
1248
+ getSeriesById(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
1249
+ id: string;
1250
+ code: string;
1251
+ name: string;
1252
+ prefix: string;
1253
+ separator: string;
1254
+ padLength: number;
1255
+ currentSequence: number;
1256
+ resetStrategy: "never" | "annual" | "monthly";
1257
+ resetAt: Date | null;
1258
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1259
+ active: boolean;
1260
+ createdAt: Date;
1261
+ updatedAt: Date;
1262
+ } | null>;
1263
+ createSeries(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, data: import("./service-shared.js").CreateContractNumberSeriesInput): Promise<{
1264
+ id: string;
1265
+ name: string;
1266
+ active: boolean;
1267
+ createdAt: Date;
1268
+ updatedAt: Date;
1269
+ code: string;
1270
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1271
+ prefix: string;
1272
+ separator: string;
1273
+ padLength: number;
1274
+ currentSequence: number;
1275
+ resetStrategy: "never" | "annual" | "monthly";
1276
+ resetAt: Date | null;
1277
+ } | null>;
1278
+ updateSeries(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string, data: import("./service-shared.js").UpdateContractNumberSeriesInput): Promise<{
1279
+ id: string;
1280
+ code: string;
1281
+ name: string;
1282
+ prefix: string;
1283
+ separator: string;
1284
+ padLength: number;
1285
+ currentSequence: number;
1286
+ resetStrategy: "never" | "annual" | "monthly";
1287
+ resetAt: Date | null;
1288
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1289
+ active: boolean;
1290
+ createdAt: Date;
1291
+ updatedAt: Date;
1292
+ } | null>;
1293
+ deleteSeries(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
1294
+ id: string;
1295
+ } | null>;
1296
+ listTemplates(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, query: import("./service-shared.js").ContractTemplateListQuery): Promise<{
1297
+ data: {
1337
1298
  id: string;
1338
- contractNumber: string | null;
1299
+ name: string;
1300
+ slug: string;
1339
1301
  scope: "customer" | "partner" | "supplier" | "other" | "channel";
1340
- status: "draft" | "sent" | "expired" | "issued" | "signed" | "executed" | "void";
1341
- title: string;
1342
- templateVersionId: string | null;
1343
- seriesId: string | null;
1344
- personId: string | null;
1345
- organizationId: string | null;
1346
- supplierId: string | null;
1347
- channelId: string | null;
1348
- bookingId: string | null;
1349
- orderId: string | null;
1350
- issuedAt: Date | null;
1351
- sentAt: Date | null;
1352
- executedAt: Date | null;
1353
- expiresAt: Date | null;
1354
- voidedAt: Date | null;
1355
1302
  language: string;
1356
- renderedBodyFormat: "markdown" | "html" | "lexical_json";
1357
- renderedBody: string | null;
1358
- variables: unknown;
1359
- metadata: unknown;
1303
+ description: string | null;
1304
+ bodyFormat: "markdown" | "html" | "lexical_json";
1305
+ body: string;
1306
+ variableSchema: unknown;
1307
+ currentVersionId: string | null;
1308
+ active: boolean;
1360
1309
  createdAt: Date;
1361
1310
  updatedAt: Date;
1362
- } | null;
1311
+ }[];
1312
+ total: number;
1313
+ limit: number;
1314
+ offset: number;
1363
1315
  }>;
1364
- listAttachments(db: PostgresJsDatabase, contractId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"contract_attachments", {
1316
+ getTemplateById(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
1317
+ id: string;
1318
+ name: string;
1319
+ slug: string;
1320
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1321
+ language: string;
1322
+ description: string | null;
1323
+ bodyFormat: "markdown" | "html" | "lexical_json";
1324
+ body: string;
1325
+ variableSchema: unknown;
1326
+ currentVersionId: string | null;
1327
+ active: boolean;
1328
+ createdAt: Date;
1329
+ updatedAt: Date;
1330
+ } | null>;
1331
+ createTemplate(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, data: import("./service-shared.js").CreateContractTemplateInput): Promise<{
1332
+ id: string;
1333
+ name: string;
1334
+ active: boolean;
1335
+ createdAt: Date;
1336
+ updatedAt: Date;
1337
+ description: string | null;
1338
+ slug: string;
1339
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1340
+ language: string;
1341
+ bodyFormat: "markdown" | "html" | "lexical_json";
1342
+ body: string;
1343
+ variableSchema: unknown;
1344
+ currentVersionId: string | null;
1345
+ } | null>;
1346
+ updateTemplate(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string, data: import("./service-shared.js").UpdateContractTemplateInput): Promise<{
1347
+ id: string;
1348
+ name: string;
1349
+ slug: string;
1350
+ scope: "customer" | "partner" | "supplier" | "other" | "channel";
1351
+ language: string;
1352
+ description: string | null;
1353
+ bodyFormat: "markdown" | "html" | "lexical_json";
1354
+ body: string;
1355
+ variableSchema: unknown;
1356
+ currentVersionId: string | null;
1357
+ active: boolean;
1358
+ createdAt: Date;
1359
+ updatedAt: Date;
1360
+ } | null>;
1361
+ deleteTemplate(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
1362
+ id: string;
1363
+ } | null>;
1364
+ listTemplateVersions(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, templateId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"contract_template_versions", {
1365
1365
  id: import("drizzle-orm/pg-core").PgColumn<{
1366
1366
  name: string;
1367
- tableName: "contract_attachments";
1367
+ tableName: "contract_template_versions";
1368
1368
  dataType: "string";
1369
1369
  columnType: "PgText";
1370
1370
  data: string;
@@ -1379,9 +1379,9 @@ export declare const contractsService: {
1379
1379
  identity: undefined;
1380
1380
  generated: undefined;
1381
1381
  }, {}, {}>;
1382
- contractId: import("drizzle-orm/pg-core").PgColumn<{
1382
+ templateId: import("drizzle-orm/pg-core").PgColumn<{
1383
1383
  name: string;
1384
- tableName: "contract_attachments";
1384
+ tableName: "contract_template_versions";
1385
1385
  dataType: "string";
1386
1386
  columnType: "PgText";
1387
1387
  data: string;
@@ -1396,48 +1396,48 @@ export declare const contractsService: {
1396
1396
  identity: undefined;
1397
1397
  generated: undefined;
1398
1398
  }, {}, {}>;
1399
- kind: import("drizzle-orm/pg-core").PgColumn<{
1400
- name: "kind";
1401
- tableName: "contract_attachments";
1402
- dataType: "string";
1403
- columnType: "PgText";
1404
- data: string;
1405
- driverParam: string;
1399
+ version: import("drizzle-orm/pg-core").PgColumn<{
1400
+ name: "version";
1401
+ tableName: "contract_template_versions";
1402
+ dataType: "number";
1403
+ columnType: "PgInteger";
1404
+ data: number;
1405
+ driverParam: string | number;
1406
1406
  notNull: true;
1407
- hasDefault: true;
1407
+ hasDefault: false;
1408
1408
  isPrimaryKey: false;
1409
1409
  isAutoincrement: false;
1410
1410
  hasRuntimeDefault: false;
1411
- enumValues: [string, ...string[]];
1411
+ enumValues: undefined;
1412
1412
  baseColumn: never;
1413
1413
  identity: undefined;
1414
1414
  generated: undefined;
1415
1415
  }, {}, {}>;
1416
- name: import("drizzle-orm/pg-core").PgColumn<{
1417
- name: "name";
1418
- tableName: "contract_attachments";
1416
+ bodyFormat: import("drizzle-orm/pg-core").PgColumn<{
1417
+ name: "body_format";
1418
+ tableName: "contract_template_versions";
1419
1419
  dataType: "string";
1420
- columnType: "PgText";
1421
- data: string;
1420
+ columnType: "PgEnumColumn";
1421
+ data: "markdown" | "html" | "lexical_json";
1422
1422
  driverParam: string;
1423
1423
  notNull: true;
1424
- hasDefault: false;
1424
+ hasDefault: true;
1425
1425
  isPrimaryKey: false;
1426
1426
  isAutoincrement: false;
1427
1427
  hasRuntimeDefault: false;
1428
- enumValues: [string, ...string[]];
1428
+ enumValues: ["markdown", "html", "lexical_json"];
1429
1429
  baseColumn: never;
1430
1430
  identity: undefined;
1431
1431
  generated: undefined;
1432
1432
  }, {}, {}>;
1433
- mimeType: import("drizzle-orm/pg-core").PgColumn<{
1434
- name: "mime_type";
1435
- tableName: "contract_attachments";
1433
+ body: import("drizzle-orm/pg-core").PgColumn<{
1434
+ name: "body";
1435
+ tableName: "contract_template_versions";
1436
1436
  dataType: "string";
1437
1437
  columnType: "PgText";
1438
1438
  data: string;
1439
1439
  driverParam: string;
1440
- notNull: false;
1440
+ notNull: true;
1441
1441
  hasDefault: false;
1442
1442
  isPrimaryKey: false;
1443
1443
  isAutoincrement: false;
@@ -1447,13 +1447,13 @@ export declare const contractsService: {
1447
1447
  identity: undefined;
1448
1448
  generated: undefined;
1449
1449
  }, {}, {}>;
1450
- fileSize: import("drizzle-orm/pg-core").PgColumn<{
1451
- name: "file_size";
1452
- tableName: "contract_attachments";
1453
- dataType: "number";
1454
- columnType: "PgInteger";
1455
- data: number;
1456
- driverParam: string | number;
1450
+ variableSchema: import("drizzle-orm/pg-core").PgColumn<{
1451
+ name: "variable_schema";
1452
+ tableName: "contract_template_versions";
1453
+ dataType: "json";
1454
+ columnType: "PgJsonb";
1455
+ data: unknown;
1456
+ driverParam: unknown;
1457
1457
  notNull: false;
1458
1458
  hasDefault: false;
1459
1459
  isPrimaryKey: false;
@@ -1464,9 +1464,9 @@ export declare const contractsService: {
1464
1464
  identity: undefined;
1465
1465
  generated: undefined;
1466
1466
  }, {}, {}>;
1467
- storageKey: import("drizzle-orm/pg-core").PgColumn<{
1468
- name: "storage_key";
1469
- tableName: "contract_attachments";
1467
+ changelog: import("drizzle-orm/pg-core").PgColumn<{
1468
+ name: "changelog";
1469
+ tableName: "contract_template_versions";
1470
1470
  dataType: "string";
1471
1471
  columnType: "PgText";
1472
1472
  data: string;
@@ -1481,9 +1481,9 @@ export declare const contractsService: {
1481
1481
  identity: undefined;
1482
1482
  generated: undefined;
1483
1483
  }, {}, {}>;
1484
- checksum: import("drizzle-orm/pg-core").PgColumn<{
1485
- name: "checksum";
1486
- tableName: "contract_attachments";
1484
+ createdBy: import("drizzle-orm/pg-core").PgColumn<{
1485
+ name: "created_by";
1486
+ tableName: "contract_template_versions";
1487
1487
  dataType: "string";
1488
1488
  columnType: "PgText";
1489
1489
  data: string;
@@ -1498,26 +1498,9 @@ export declare const contractsService: {
1498
1498
  identity: undefined;
1499
1499
  generated: undefined;
1500
1500
  }, {}, {}>;
1501
- metadata: import("drizzle-orm/pg-core").PgColumn<{
1502
- name: "metadata";
1503
- tableName: "contract_attachments";
1504
- dataType: "json";
1505
- columnType: "PgJsonb";
1506
- data: unknown;
1507
- driverParam: unknown;
1508
- notNull: false;
1509
- hasDefault: false;
1510
- isPrimaryKey: false;
1511
- isAutoincrement: false;
1512
- hasRuntimeDefault: false;
1513
- enumValues: undefined;
1514
- baseColumn: never;
1515
- identity: undefined;
1516
- generated: undefined;
1517
- }, {}, {}>;
1518
1501
  createdAt: import("drizzle-orm/pg-core").PgColumn<{
1519
1502
  name: "created_at";
1520
- tableName: "contract_attachments";
1503
+ tableName: "contract_template_versions";
1521
1504
  dataType: "date";
1522
1505
  columnType: "PgTimestamp";
1523
1506
  data: Date;
@@ -1532,21 +1515,20 @@ export declare const contractsService: {
1532
1515
  identity: undefined;
1533
1516
  generated: undefined;
1534
1517
  }, {}, {}>;
1535
- }, "single", Record<"contract_attachments", "not-null">, false, "where" | "orderBy", {
1518
+ }, "single", Record<"contract_template_versions", "not-null">, false, "where" | "orderBy", {
1536
1519
  id: string;
1537
- contractId: string;
1538
- kind: string;
1539
- name: string;
1540
- mimeType: string | null;
1541
- fileSize: number | null;
1542
- storageKey: string | null;
1543
- checksum: string | null;
1544
- metadata: unknown;
1520
+ templateId: string;
1521
+ version: number;
1522
+ bodyFormat: "markdown" | "html" | "lexical_json";
1523
+ body: string;
1524
+ variableSchema: unknown;
1525
+ changelog: string | null;
1526
+ createdBy: string | null;
1545
1527
  createdAt: Date;
1546
1528
  }[], {
1547
1529
  id: import("drizzle-orm/pg-core").PgColumn<{
1548
1530
  name: string;
1549
- tableName: "contract_attachments";
1531
+ tableName: "contract_template_versions";
1550
1532
  dataType: "string";
1551
1533
  columnType: "PgText";
1552
1534
  data: string;
@@ -1561,9 +1543,9 @@ export declare const contractsService: {
1561
1543
  identity: undefined;
1562
1544
  generated: undefined;
1563
1545
  }, {}, {}>;
1564
- contractId: import("drizzle-orm/pg-core").PgColumn<{
1546
+ templateId: import("drizzle-orm/pg-core").PgColumn<{
1565
1547
  name: string;
1566
- tableName: "contract_attachments";
1548
+ tableName: "contract_template_versions";
1567
1549
  dataType: "string";
1568
1550
  columnType: "PgText";
1569
1551
  data: string;
@@ -1578,48 +1560,48 @@ export declare const contractsService: {
1578
1560
  identity: undefined;
1579
1561
  generated: undefined;
1580
1562
  }, {}, {}>;
1581
- kind: import("drizzle-orm/pg-core").PgColumn<{
1582
- name: "kind";
1583
- tableName: "contract_attachments";
1584
- dataType: "string";
1585
- columnType: "PgText";
1586
- data: string;
1587
- driverParam: string;
1563
+ version: import("drizzle-orm/pg-core").PgColumn<{
1564
+ name: "version";
1565
+ tableName: "contract_template_versions";
1566
+ dataType: "number";
1567
+ columnType: "PgInteger";
1568
+ data: number;
1569
+ driverParam: string | number;
1588
1570
  notNull: true;
1589
- hasDefault: true;
1571
+ hasDefault: false;
1590
1572
  isPrimaryKey: false;
1591
1573
  isAutoincrement: false;
1592
1574
  hasRuntimeDefault: false;
1593
- enumValues: [string, ...string[]];
1575
+ enumValues: undefined;
1594
1576
  baseColumn: never;
1595
1577
  identity: undefined;
1596
1578
  generated: undefined;
1597
1579
  }, {}, {}>;
1598
- name: import("drizzle-orm/pg-core").PgColumn<{
1599
- name: "name";
1600
- tableName: "contract_attachments";
1580
+ bodyFormat: import("drizzle-orm/pg-core").PgColumn<{
1581
+ name: "body_format";
1582
+ tableName: "contract_template_versions";
1601
1583
  dataType: "string";
1602
- columnType: "PgText";
1603
- data: string;
1584
+ columnType: "PgEnumColumn";
1585
+ data: "markdown" | "html" | "lexical_json";
1604
1586
  driverParam: string;
1605
1587
  notNull: true;
1606
- hasDefault: false;
1588
+ hasDefault: true;
1607
1589
  isPrimaryKey: false;
1608
1590
  isAutoincrement: false;
1609
1591
  hasRuntimeDefault: false;
1610
- enumValues: [string, ...string[]];
1592
+ enumValues: ["markdown", "html", "lexical_json"];
1611
1593
  baseColumn: never;
1612
1594
  identity: undefined;
1613
1595
  generated: undefined;
1614
1596
  }, {}, {}>;
1615
- mimeType: import("drizzle-orm/pg-core").PgColumn<{
1616
- name: "mime_type";
1617
- tableName: "contract_attachments";
1597
+ body: import("drizzle-orm/pg-core").PgColumn<{
1598
+ name: "body";
1599
+ tableName: "contract_template_versions";
1618
1600
  dataType: "string";
1619
1601
  columnType: "PgText";
1620
1602
  data: string;
1621
1603
  driverParam: string;
1622
- notNull: false;
1604
+ notNull: true;
1623
1605
  hasDefault: false;
1624
1606
  isPrimaryKey: false;
1625
1607
  isAutoincrement: false;
@@ -1629,13 +1611,13 @@ export declare const contractsService: {
1629
1611
  identity: undefined;
1630
1612
  generated: undefined;
1631
1613
  }, {}, {}>;
1632
- fileSize: import("drizzle-orm/pg-core").PgColumn<{
1633
- name: "file_size";
1634
- tableName: "contract_attachments";
1635
- dataType: "number";
1636
- columnType: "PgInteger";
1637
- data: number;
1638
- driverParam: string | number;
1614
+ variableSchema: import("drizzle-orm/pg-core").PgColumn<{
1615
+ name: "variable_schema";
1616
+ tableName: "contract_template_versions";
1617
+ dataType: "json";
1618
+ columnType: "PgJsonb";
1619
+ data: unknown;
1620
+ driverParam: unknown;
1639
1621
  notNull: false;
1640
1622
  hasDefault: false;
1641
1623
  isPrimaryKey: false;
@@ -1646,9 +1628,9 @@ export declare const contractsService: {
1646
1628
  identity: undefined;
1647
1629
  generated: undefined;
1648
1630
  }, {}, {}>;
1649
- storageKey: import("drizzle-orm/pg-core").PgColumn<{
1650
- name: "storage_key";
1651
- tableName: "contract_attachments";
1631
+ changelog: import("drizzle-orm/pg-core").PgColumn<{
1632
+ name: "changelog";
1633
+ tableName: "contract_template_versions";
1652
1634
  dataType: "string";
1653
1635
  columnType: "PgText";
1654
1636
  data: string;
@@ -1663,9 +1645,9 @@ export declare const contractsService: {
1663
1645
  identity: undefined;
1664
1646
  generated: undefined;
1665
1647
  }, {}, {}>;
1666
- checksum: import("drizzle-orm/pg-core").PgColumn<{
1667
- name: "checksum";
1668
- tableName: "contract_attachments";
1648
+ createdBy: import("drizzle-orm/pg-core").PgColumn<{
1649
+ name: "created_by";
1650
+ tableName: "contract_template_versions";
1669
1651
  dataType: "string";
1670
1652
  columnType: "PgText";
1671
1653
  data: string;
@@ -1680,26 +1662,9 @@ export declare const contractsService: {
1680
1662
  identity: undefined;
1681
1663
  generated: undefined;
1682
1664
  }, {}, {}>;
1683
- metadata: import("drizzle-orm/pg-core").PgColumn<{
1684
- name: "metadata";
1685
- tableName: "contract_attachments";
1686
- dataType: "json";
1687
- columnType: "PgJsonb";
1688
- data: unknown;
1689
- driverParam: unknown;
1690
- notNull: false;
1691
- hasDefault: false;
1692
- isPrimaryKey: false;
1693
- isAutoincrement: false;
1694
- hasRuntimeDefault: false;
1695
- enumValues: undefined;
1696
- baseColumn: never;
1697
- identity: undefined;
1698
- generated: undefined;
1699
- }, {}, {}>;
1700
1665
  createdAt: import("drizzle-orm/pg-core").PgColumn<{
1701
1666
  name: "created_at";
1702
- tableName: "contract_attachments";
1667
+ tableName: "contract_template_versions";
1703
1668
  dataType: "date";
1704
1669
  columnType: "PgTimestamp";
1705
1670
  data: Date;
@@ -1715,39 +1680,28 @@ export declare const contractsService: {
1715
1680
  generated: undefined;
1716
1681
  }, {}, {}>;
1717
1682
  }>, "where" | "orderBy">;
1718
- createAttachment(db: PostgresJsDatabase, contractId: string, data: CreateContractAttachmentInput): Promise<{
1683
+ getTemplateVersionById(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, id: string): Promise<{
1719
1684
  id: string;
1720
- name: string;
1685
+ templateId: string;
1686
+ version: number;
1687
+ bodyFormat: "markdown" | "html" | "lexical_json";
1688
+ body: string;
1689
+ variableSchema: unknown;
1690
+ changelog: string | null;
1691
+ createdBy: string | null;
1721
1692
  createdAt: Date;
1722
- kind: string;
1723
- metadata: unknown;
1724
- contractId: string;
1725
- mimeType: string | null;
1726
- fileSize: number | null;
1727
- storageKey: string | null;
1728
- checksum: string | null;
1729
1693
  } | null>;
1730
- updateAttachment(db: PostgresJsDatabase, attachmentId: string, data: UpdateContractAttachmentInput): Promise<{
1694
+ createTemplateVersion(db: import("drizzle-orm/postgres-js").PostgresJsDatabase, templateId: string, data: import("./service-shared.js").CreateContractTemplateVersionInput): Promise<{
1731
1695
  id: string;
1732
- contractId: string;
1733
- kind: string;
1734
- name: string;
1735
- mimeType: string | null;
1736
- fileSize: number | null;
1737
- storageKey: string | null;
1738
- checksum: string | null;
1739
- metadata: unknown;
1740
1696
  createdAt: Date;
1697
+ bodyFormat: "markdown" | "html" | "lexical_json";
1698
+ body: string;
1699
+ variableSchema: unknown;
1700
+ templateId: string;
1701
+ version: number;
1702
+ changelog: string | null;
1703
+ createdBy: string | null;
1741
1704
  } | null>;
1742
- deleteAttachment(db: PostgresJsDatabase, attachmentId: string): Promise<{
1743
- id: string;
1744
- } | null>;
1745
- /**
1746
- * Preview render: substitute variables against an arbitrary body without
1747
- * touching the database. Used by `/v1/admin/contracts/:id/render` and
1748
- * `/v1/admin/contracts/templates/:id/preview`.
1749
- */
1750
- renderPreview(input: RenderTemplateInput): string;
1705
+ renderPreview(input: import("./service-shared.js").RenderTemplateInput): string;
1751
1706
  };
1752
- export {};
1753
1707
  //# sourceMappingURL=service.d.ts.map