@deepintel-ltd/farmpro-contracts 1.7.1 → 1.7.2
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/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/routes/capital.routes.d.ts +3629 -0
- package/dist/routes/capital.routes.d.ts.map +1 -0
- package/dist/routes/capital.routes.js +131 -0
- package/dist/routes/index.d.ts +3 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +2 -0
- package/dist/schemas/capital.schemas.d.ts +1729 -0
- package/dist/schemas/capital.schemas.d.ts.map +1 -0
- package/dist/schemas/capital.schemas.js +142 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capital.schemas.d.ts","sourceRoot":"","sources":["../../src/schemas/capital.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB;;;GAGG;AAGH,eAAO,MAAM,iBAAiB,4FAO5B,CAAC;AAGH,eAAO,MAAM,mBAAmB,qFAM9B,CAAC;AAGH,eAAO,MAAM,qBAAqB,2BAAyB,CAAC;AAG5D,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBrB,CAAC;AAG3B,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBnD,CAAC;AAGH,eAAO,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAenD,CAAC;AAGH,eAAO,MAAM,gCAAgC;;;;;;;;;;;;EAI3C,CAAC;AAGH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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schemas';
|
|
3
|
+
/**
|
|
4
|
+
* Capital Transaction schemas - JSON:API compliant
|
|
5
|
+
* Used for tracking capital injections, loans, grants, and other funding sources
|
|
6
|
+
*/
|
|
7
|
+
// Capital transaction type enum
|
|
8
|
+
export const capitalTypeSchema = z.enum([
|
|
9
|
+
'OWNER_CONTRIBUTION',
|
|
10
|
+
'LOAN',
|
|
11
|
+
'GRANT',
|
|
12
|
+
'INVESTOR',
|
|
13
|
+
'WORKING_CAPITAL',
|
|
14
|
+
'OTHER'
|
|
15
|
+
]);
|
|
16
|
+
// Capital transaction status enum
|
|
17
|
+
export const capitalStatusSchema = z.enum([
|
|
18
|
+
'received',
|
|
19
|
+
'pending',
|
|
20
|
+
'partially_repaid',
|
|
21
|
+
'fully_repaid',
|
|
22
|
+
'cancelled'
|
|
23
|
+
]);
|
|
24
|
+
// Currency enum (matching the rest of the system)
|
|
25
|
+
export const capitalCurrencySchema = z.enum(['NGN', 'USD']);
|
|
26
|
+
// Capital transaction attributes schema (for JSON:API attributes object)
|
|
27
|
+
export const capitalTransactionAttributesSchema = z.object({
|
|
28
|
+
type: capitalTypeSchema,
|
|
29
|
+
amount: z.number().positive(),
|
|
30
|
+
currency: capitalCurrencySchema,
|
|
31
|
+
description: z.string().nullable(),
|
|
32
|
+
source: z.string().nullable(), // Who provided the funds
|
|
33
|
+
reference: z.string().nullable(), // External reference number
|
|
34
|
+
transactionDate: z.string().datetime(),
|
|
35
|
+
// For loans/repayable funds
|
|
36
|
+
isRepayable: z.boolean(),
|
|
37
|
+
repaymentTerms: z.string().nullable(),
|
|
38
|
+
interestRate: z.number().nullable(), // Annual interest rate as percentage
|
|
39
|
+
repaymentDueDate: z.string().datetime().nullable(),
|
|
40
|
+
// Status tracking
|
|
41
|
+
status: capitalStatusSchema,
|
|
42
|
+
amountRepaid: z.number().nonnegative(),
|
|
43
|
+
// Calculated fields
|
|
44
|
+
outstandingBalance: z.number().optional(), // amount - amountRepaid (for repayable)
|
|
45
|
+
notes: z.string().nullable(),
|
|
46
|
+
}).merge(timestampsSchema);
|
|
47
|
+
// Capital transaction attributes for creation (input)
|
|
48
|
+
export const createCapitalTransactionAttributesSchema = z.object({
|
|
49
|
+
type: capitalTypeSchema,
|
|
50
|
+
amount: z.number().positive(),
|
|
51
|
+
currency: capitalCurrencySchema.default('NGN'),
|
|
52
|
+
description: z.string().max(2000).optional(),
|
|
53
|
+
source: z.string().max(200).optional(), // Who provided the funds
|
|
54
|
+
reference: z.string().max(100).optional(), // External reference number
|
|
55
|
+
transactionDate: z.string().datetime(),
|
|
56
|
+
// For loans/repayable funds
|
|
57
|
+
isRepayable: z.boolean().default(false),
|
|
58
|
+
repaymentTerms: z.string().max(2000).optional(),
|
|
59
|
+
interestRate: z.number().min(0).max(100).optional(), // Annual interest rate
|
|
60
|
+
repaymentDueDate: z.string().datetime().optional(),
|
|
61
|
+
notes: z.string().max(2000).optional(),
|
|
62
|
+
}).refine((data) => {
|
|
63
|
+
// If repayable, due date should be provided
|
|
64
|
+
if (data.isRepayable && data.type === 'LOAN' && !data.repaymentDueDate) {
|
|
65
|
+
return true; // Allow loans without due date (open-ended)
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}, {
|
|
69
|
+
message: 'Repayment due date is recommended for repayable capital',
|
|
70
|
+
});
|
|
71
|
+
// Capital transaction attributes for update (input)
|
|
72
|
+
export const updateCapitalTransactionAttributesSchema = z.object({
|
|
73
|
+
type: capitalTypeSchema.optional(),
|
|
74
|
+
amount: z.number().positive().optional(),
|
|
75
|
+
currency: capitalCurrencySchema.optional(),
|
|
76
|
+
description: z.string().max(2000).nullable().optional(),
|
|
77
|
+
source: z.string().max(200).nullable().optional(),
|
|
78
|
+
reference: z.string().max(100).nullable().optional(),
|
|
79
|
+
transactionDate: z.string().datetime().optional(),
|
|
80
|
+
isRepayable: z.boolean().optional(),
|
|
81
|
+
repaymentTerms: z.string().max(2000).nullable().optional(),
|
|
82
|
+
interestRate: z.number().min(0).max(100).nullable().optional(),
|
|
83
|
+
repaymentDueDate: z.string().datetime().nullable().optional(),
|
|
84
|
+
status: capitalStatusSchema.optional(),
|
|
85
|
+
amountRepaid: z.number().nonnegative().optional(),
|
|
86
|
+
notes: z.string().max(2000).nullable().optional(),
|
|
87
|
+
});
|
|
88
|
+
// Repayment input schema (for recording loan repayments)
|
|
89
|
+
export const capitalRepaymentAttributesSchema = z.object({
|
|
90
|
+
amount: z.number().positive(),
|
|
91
|
+
repaymentDate: z.string().datetime(),
|
|
92
|
+
notes: z.string().max(500).optional(),
|
|
93
|
+
});
|
|
94
|
+
// Create input schemas (JSON:API format)
|
|
95
|
+
export const createCapitalTransactionSchema = z.object({
|
|
96
|
+
type: z.literal('capital-transactions'),
|
|
97
|
+
attributes: createCapitalTransactionAttributesSchema,
|
|
98
|
+
});
|
|
99
|
+
export const updateCapitalTransactionSchema = z.object({
|
|
100
|
+
type: z.literal('capital-transactions'),
|
|
101
|
+
id: z.string().uuid(),
|
|
102
|
+
attributes: updateCapitalTransactionAttributesSchema,
|
|
103
|
+
});
|
|
104
|
+
export const recordRepaymentSchema = z.object({
|
|
105
|
+
type: z.literal('capital-repayments'),
|
|
106
|
+
attributes: capitalRepaymentAttributesSchema,
|
|
107
|
+
});
|
|
108
|
+
// Resource schemas (JSON:API resource objects)
|
|
109
|
+
export const capitalTransactionResourceSchema = createJsonApiResourceSchema('capital-transactions', capitalTransactionAttributesSchema);
|
|
110
|
+
// Detail resource schema with relationships
|
|
111
|
+
export const capitalTransactionDetailResourceSchema = capitalTransactionResourceSchema.extend({
|
|
112
|
+
relationships: z.object({
|
|
113
|
+
farm: z.object({
|
|
114
|
+
links: z.object({
|
|
115
|
+
related: z.string(),
|
|
116
|
+
}),
|
|
117
|
+
}).optional(),
|
|
118
|
+
}).optional(),
|
|
119
|
+
});
|
|
120
|
+
// Response schemas (JSON:API format)
|
|
121
|
+
export const capitalTransactionResponseSchema = jsonApiSingleResponseSchema(capitalTransactionResourceSchema);
|
|
122
|
+
export const capitalTransactionDetailResponseSchema = jsonApiSingleResponseSchema(capitalTransactionDetailResourceSchema);
|
|
123
|
+
export const capitalTransactionListResponseSchema = jsonApiCollectionResponseSchema(capitalTransactionResourceSchema);
|
|
124
|
+
// Capital summary response (aggregate data)
|
|
125
|
+
export const capitalSummaryAttributesSchema = z.object({
|
|
126
|
+
totalCapitalReceived: z.number().nonnegative(),
|
|
127
|
+
totalRepayableAmount: z.number().nonnegative(),
|
|
128
|
+
totalAmountRepaid: z.number().nonnegative(),
|
|
129
|
+
outstandingLiabilities: z.number().nonnegative(),
|
|
130
|
+
// Breakdown by type
|
|
131
|
+
byType: z.record(capitalTypeSchema, z.object({
|
|
132
|
+
count: z.number().int().nonnegative(),
|
|
133
|
+
totalAmount: z.number().nonnegative(),
|
|
134
|
+
})),
|
|
135
|
+
// Breakdown by status
|
|
136
|
+
byStatus: z.record(capitalStatusSchema, z.object({
|
|
137
|
+
count: z.number().int().nonnegative(),
|
|
138
|
+
totalAmount: z.number().nonnegative(),
|
|
139
|
+
})),
|
|
140
|
+
});
|
|
141
|
+
export const capitalSummaryResourceSchema = createJsonApiResourceSchema('capital-summaries', capitalSummaryAttributesSchema);
|
|
142
|
+
export const capitalSummaryResponseSchema = jsonApiSingleResponseSchema(capitalSummaryResourceSchema);
|