@axova/shared 1.0.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/CONFIGURATION_GUIDE.md +1 -0
- package/README.md +384 -0
- package/SCHEMA_ORGANIZATION.md +209 -0
- package/dist/configs/index.d.ts +85 -0
- package/dist/configs/index.js +555 -0
- package/dist/events/kafka.d.ts +40 -0
- package/dist/events/kafka.js +311 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +41 -0
- package/dist/interfaces/customer-events.d.ts +85 -0
- package/dist/interfaces/customer-events.js +2 -0
- package/dist/interfaces/inventory-events.d.ts +453 -0
- package/dist/interfaces/inventory-events.js +3 -0
- package/dist/interfaces/inventory-types.d.ts +894 -0
- package/dist/interfaces/inventory-types.js +3 -0
- package/dist/interfaces/order-events.d.ts +320 -0
- package/dist/interfaces/order-events.js +3 -0
- package/dist/lib/auditLogger.d.ts +162 -0
- package/dist/lib/auditLogger.js +626 -0
- package/dist/lib/authOrganization.d.ts +24 -0
- package/dist/lib/authOrganization.js +110 -0
- package/dist/lib/db.d.ts +6 -0
- package/dist/lib/db.js +88 -0
- package/dist/middleware/serviceAuth.d.ts +60 -0
- package/dist/middleware/serviceAuth.js +272 -0
- package/dist/middleware/storeOwnership.d.ts +15 -0
- package/dist/middleware/storeOwnership.js +156 -0
- package/dist/middleware/storeValidationMiddleware.d.ts +44 -0
- package/dist/middleware/storeValidationMiddleware.js +180 -0
- package/dist/middleware/userAuth.d.ts +27 -0
- package/dist/middleware/userAuth.js +218 -0
- package/dist/schemas/admin/admin-schema.d.ts +741 -0
- package/dist/schemas/admin/admin-schema.js +111 -0
- package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +648 -0
- package/dist/schemas/ai-moderation/ai-moderation-schema.js +88 -0
- package/dist/schemas/common/common-schemas.d.ts +436 -0
- package/dist/schemas/common/common-schemas.js +94 -0
- package/dist/schemas/compliance/compliance-schema.d.ts +3388 -0
- package/dist/schemas/compliance/compliance-schema.js +472 -0
- package/dist/schemas/compliance/kyc-schema.d.ts +2642 -0
- package/dist/schemas/compliance/kyc-schema.js +361 -0
- package/dist/schemas/customer/customer-schema.d.ts +2727 -0
- package/dist/schemas/customer/customer-schema.js +399 -0
- package/dist/schemas/index.d.ts +27 -0
- package/dist/schemas/index.js +138 -0
- package/dist/schemas/inventory/inventory-tables.d.ts +9476 -0
- package/dist/schemas/inventory/inventory-tables.js +1470 -0
- package/dist/schemas/inventory/lot-tables.d.ts +3281 -0
- package/dist/schemas/inventory/lot-tables.js +608 -0
- package/dist/schemas/order/order-schema.d.ts +5825 -0
- package/dist/schemas/order/order-schema.js +954 -0
- package/dist/schemas/product/discount-relations.d.ts +15 -0
- package/dist/schemas/product/discount-relations.js +34 -0
- package/dist/schemas/product/discount-schema.d.ts +1975 -0
- package/dist/schemas/product/discount-schema.js +297 -0
- package/dist/schemas/product/product-relations.d.ts +41 -0
- package/dist/schemas/product/product-relations.js +133 -0
- package/dist/schemas/product/product-schema.d.ts +4544 -0
- package/dist/schemas/product/product-schema.js +671 -0
- package/dist/schemas/store/store-audit-schema.d.ts +4135 -0
- package/dist/schemas/store/store-audit-schema.js +556 -0
- package/dist/schemas/store/store-schema.d.ts +3100 -0
- package/dist/schemas/store/store-schema.js +381 -0
- package/dist/schemas/store/store-settings-schema.d.ts +665 -0
- package/dist/schemas/store/store-settings-schema.js +141 -0
- package/dist/schemas/types.d.ts +50 -0
- package/dist/schemas/types.js +3 -0
- package/dist/types/events.d.ts +2396 -0
- package/dist/types/events.js +505 -0
- package/dist/utils/errorHandler.d.ts +12 -0
- package/dist/utils/errorHandler.js +36 -0
- package/dist/utils/subdomain.d.ts +6 -0
- package/dist/utils/subdomain.js +20 -0
- package/nul +8 -0
- package/package.json +43 -0
- package/src/configs/index.ts +654 -0
- package/src/events/kafka.ts +429 -0
- package/src/index.ts +26 -0
- package/src/interfaces/customer-events.ts +106 -0
- package/src/interfaces/inventory-events.ts +545 -0
- package/src/interfaces/inventory-types.ts +1004 -0
- package/src/interfaces/order-events.ts +381 -0
- package/src/lib/auditLogger.ts +1117 -0
- package/src/lib/authOrganization.ts +153 -0
- package/src/lib/db.ts +64 -0
- package/src/middleware/serviceAuth.ts +328 -0
- package/src/middleware/storeOwnership.ts +199 -0
- package/src/middleware/storeValidationMiddleware.ts +247 -0
- package/src/middleware/userAuth.ts +248 -0
- package/src/schemas/admin/admin-schema.ts +208 -0
- package/src/schemas/ai-moderation/ai-moderation-schema.ts +180 -0
- package/src/schemas/common/common-schemas.ts +108 -0
- package/src/schemas/compliance/compliance-schema.ts +927 -0
- package/src/schemas/compliance/kyc-schema.ts +649 -0
- package/src/schemas/customer/customer-schema.ts +576 -0
- package/src/schemas/index.ts +189 -0
- package/src/schemas/inventory/inventory-tables.ts +1927 -0
- package/src/schemas/inventory/lot-tables.ts +799 -0
- package/src/schemas/order/order-schema.ts +1400 -0
- package/src/schemas/product/discount-relations.ts +44 -0
- package/src/schemas/product/discount-schema.ts +464 -0
- package/src/schemas/product/product-relations.ts +187 -0
- package/src/schemas/product/product-schema.ts +955 -0
- package/src/schemas/store/ethiopian_business_api.md.resolved +212 -0
- package/src/schemas/store/store-audit-schema.ts +1257 -0
- package/src/schemas/store/store-schema.ts +661 -0
- package/src/schemas/store/store-settings-schema.ts +231 -0
- package/src/schemas/types.ts +67 -0
- package/src/types/events.ts +646 -0
- package/src/utils/errorHandler.ts +44 -0
- package/src/utils/subdomain.ts +19 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appealsRelations = exports.storePoliciesRelations = exports.complianceActionsRelations = exports.complianceViolationsRelations = exports.storeComplianceRelations = exports.appeals = exports.storePolicies = exports.complianceActions = exports.complianceViolations = exports.storeCompliance = void 0;
|
|
4
|
+
const cuid2_1 = require("@paralleldrive/cuid2");
|
|
5
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
6
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
7
|
+
// Store Compliance Table - Enhanced
|
|
8
|
+
exports.storeCompliance = (0, pg_core_1.pgTable)("store_compliance", {
|
|
9
|
+
id: (0, pg_core_1.text)("id")
|
|
10
|
+
.primaryKey()
|
|
11
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
12
|
+
storeId: (0, pg_core_1.text)("store_id").notNull().unique(),
|
|
13
|
+
// Verification & Compliance Status
|
|
14
|
+
isVerified: (0, pg_core_1.boolean)("is_verified").notNull().default(false),
|
|
15
|
+
isFeatureStore: (0, pg_core_1.boolean)("is_feature_store").notNull().default(false),
|
|
16
|
+
verificationStatus: (0, pg_core_1.varchar)("verification_status", { length: 50 })
|
|
17
|
+
.notNull()
|
|
18
|
+
.default("STANDARD")
|
|
19
|
+
.$type(),
|
|
20
|
+
// Verification Details
|
|
21
|
+
verificationLevel: (0, pg_core_1.varchar)("verification_level", { length: 30 })
|
|
22
|
+
.$type()
|
|
23
|
+
.default("BASIC"),
|
|
24
|
+
verificationBadges: (0, pg_core_1.jsonb)("verification_badges")
|
|
25
|
+
.$type()
|
|
26
|
+
.default([]),
|
|
27
|
+
verifiedAt: (0, pg_core_1.timestamp)("verified_at", { withTimezone: true }),
|
|
28
|
+
verificationExpiry: (0, pg_core_1.timestamp)("verification_expiry", {
|
|
29
|
+
withTimezone: true,
|
|
30
|
+
}),
|
|
31
|
+
// Store Status
|
|
32
|
+
isBanned: (0, pg_core_1.boolean)("is_banned").notNull().default(false),
|
|
33
|
+
isSuspended: (0, pg_core_1.boolean)("is_suspended").notNull().default(false),
|
|
34
|
+
isUnderReview: (0, pg_core_1.boolean)("is_under_review").notNull().default(false),
|
|
35
|
+
// Ban/Suspension Details
|
|
36
|
+
banReason: (0, pg_core_1.text)("ban_reason"),
|
|
37
|
+
banLevel: (0, pg_core_1.varchar)("ban_level", { length: 20 }).$type(),
|
|
38
|
+
banStartDate: (0, pg_core_1.timestamp)("ban_start_date", { withTimezone: true }),
|
|
39
|
+
banEndDate: (0, pg_core_1.timestamp)("ban_end_date", { withTimezone: true }),
|
|
40
|
+
suspensionReason: (0, pg_core_1.text)("suspension_reason"),
|
|
41
|
+
suspensionLevel: (0, pg_core_1.varchar)("suspension_level", { length: 20 }).$type(),
|
|
42
|
+
suspensionStartDate: (0, pg_core_1.timestamp)("suspension_start_date", {
|
|
43
|
+
withTimezone: true,
|
|
44
|
+
}),
|
|
45
|
+
suspensionEndDate: (0, pg_core_1.timestamp)("suspension_end_date", { withTimezone: true }),
|
|
46
|
+
// Compliance Metrics
|
|
47
|
+
warningCount: (0, pg_core_1.integer)("warning_count").notNull().default(0),
|
|
48
|
+
violationCount: (0, pg_core_1.integer)("violation_count").notNull().default(0),
|
|
49
|
+
appealCount: (0, pg_core_1.integer)("appeal_count").notNull().default(0),
|
|
50
|
+
successfulAppealCount: (0, pg_core_1.integer)("successful_appeal_count")
|
|
51
|
+
.notNull()
|
|
52
|
+
.default(0),
|
|
53
|
+
lastWarningDate: (0, pg_core_1.timestamp)("last_warning_date", { withTimezone: true }),
|
|
54
|
+
lastViolationDate: (0, pg_core_1.timestamp)("last_violation_date", { withTimezone: true }),
|
|
55
|
+
// Compliance Score (0-100)
|
|
56
|
+
complianceScore: (0, pg_core_1.integer)("compliance_score").default(100),
|
|
57
|
+
riskLevel: (0, pg_core_1.varchar)("risk_level", { length: 20 })
|
|
58
|
+
.$type()
|
|
59
|
+
.default("LOW"),
|
|
60
|
+
// Trust and Safety
|
|
61
|
+
trustScore: (0, pg_core_1.decimal)("trust_score", { precision: 5, scale: 2 }).default("100.00"),
|
|
62
|
+
safetyRating: (0, pg_core_1.varchar)("safety_rating", { length: 10 })
|
|
63
|
+
.$type()
|
|
64
|
+
.default("A"),
|
|
65
|
+
// Review and Monitoring
|
|
66
|
+
nextReviewDate: (0, pg_core_1.timestamp)("next_review_date", { withTimezone: true }),
|
|
67
|
+
reviewFrequency: (0, pg_core_1.varchar)("review_frequency", { length: 20 })
|
|
68
|
+
.$type()
|
|
69
|
+
.default("QUARTERLY"),
|
|
70
|
+
monitoringLevel: (0, pg_core_1.varchar)("monitoring_level", { length: 20 })
|
|
71
|
+
.$type()
|
|
72
|
+
.default("STANDARD"),
|
|
73
|
+
// Compliance Flags
|
|
74
|
+
flags: (0, pg_core_1.jsonb)("flags")
|
|
75
|
+
.$type()
|
|
76
|
+
.default({}),
|
|
77
|
+
// Return and Refund Settings
|
|
78
|
+
returnSettings: (0, pg_core_1.jsonb)("return_settings")
|
|
79
|
+
.$type()
|
|
80
|
+
.default({
|
|
81
|
+
returnWindow: 30,
|
|
82
|
+
returnReasons: [],
|
|
83
|
+
returnInstructions: "",
|
|
84
|
+
returnShippingPolicy: "",
|
|
85
|
+
}),
|
|
86
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
87
|
+
.defaultNow()
|
|
88
|
+
.notNull(),
|
|
89
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
90
|
+
.defaultNow()
|
|
91
|
+
.notNull(),
|
|
92
|
+
}, (table) => ({
|
|
93
|
+
storeIdIndex: (0, pg_core_1.index)("idx_compliance_store_id").on(table.storeId),
|
|
94
|
+
verificationStatusIndex: (0, pg_core_1.index)("idx_compliance_verification_status").on(table.verificationStatus),
|
|
95
|
+
complianceScoreIndex: (0, pg_core_1.index)("idx_compliance_score").on(table.complianceScore),
|
|
96
|
+
riskLevelIndex: (0, pg_core_1.index)("idx_compliance_risk_level").on(table.riskLevel),
|
|
97
|
+
// Status monitoring indexes
|
|
98
|
+
bannedStoresIndex: (0, pg_core_1.index)("idx_compliance_banned").on(table.isBanned, table.banEndDate),
|
|
99
|
+
suspendedStoresIndex: (0, pg_core_1.index)("idx_compliance_suspended").on(table.isSuspended, table.suspensionEndDate),
|
|
100
|
+
underReviewIndex: (0, pg_core_1.index)("idx_compliance_under_review").on(table.isUnderReview),
|
|
101
|
+
// Review workflow indexes
|
|
102
|
+
nextReviewIndex: (0, pg_core_1.index)("idx_compliance_next_review").on(table.nextReviewDate, table.reviewFrequency),
|
|
103
|
+
monitoringIndex: (0, pg_core_1.index)("idx_compliance_monitoring").on(table.monitoringLevel, table.riskLevel),
|
|
104
|
+
}));
|
|
105
|
+
// Compliance Violations Table - Enhanced
|
|
106
|
+
exports.complianceViolations = (0, pg_core_1.pgTable)("compliance_violations", {
|
|
107
|
+
id: (0, pg_core_1.text)("id")
|
|
108
|
+
.primaryKey()
|
|
109
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
110
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
111
|
+
// Violation Classification
|
|
112
|
+
violationType: (0, pg_core_1.varchar)("violation_type", { length: 50 })
|
|
113
|
+
.notNull()
|
|
114
|
+
.$type(),
|
|
115
|
+
violationCategory: (0, pg_core_1.varchar)("violation_category", { length: 50 }).$type(),
|
|
116
|
+
severity: (0, pg_core_1.varchar)("severity", { length: 20 })
|
|
117
|
+
.notNull()
|
|
118
|
+
.$type(),
|
|
119
|
+
priority: (0, pg_core_1.varchar)("priority", { length: 20 })
|
|
120
|
+
.notNull()
|
|
121
|
+
.default("NORMAL")
|
|
122
|
+
.$type(),
|
|
123
|
+
// Violation Details
|
|
124
|
+
title: (0, pg_core_1.varchar)("title", { length: 255 }).notNull(),
|
|
125
|
+
description: (0, pg_core_1.text)("description").notNull(),
|
|
126
|
+
context: (0, pg_core_1.text)("context"), // Additional context about where/how violation occurred
|
|
127
|
+
// Evidence and Documentation
|
|
128
|
+
evidence: (0, pg_core_1.jsonb)("evidence").$type(),
|
|
129
|
+
// Detection Information
|
|
130
|
+
detectedBy: (0, pg_core_1.varchar)("detected_by", { length: 50 })
|
|
131
|
+
.notNull()
|
|
132
|
+
.$type(),
|
|
133
|
+
detectorId: (0, pg_core_1.text)("detector_id"), // ID of the user, system, or AI that detected it
|
|
134
|
+
detectionMethod: (0, pg_core_1.varchar)("detection_method", { length: 50 }).$type(),
|
|
135
|
+
detectionConfidence: (0, pg_core_1.decimal)("detection_confidence", {
|
|
136
|
+
precision: 5,
|
|
137
|
+
scale: 2,
|
|
138
|
+
}), // 0-100%
|
|
139
|
+
// Processing Status
|
|
140
|
+
status: (0, pg_core_1.varchar)("status", { length: 20 })
|
|
141
|
+
.notNull()
|
|
142
|
+
.default("PENDING")
|
|
143
|
+
.$type(),
|
|
144
|
+
// Actions and Resolution
|
|
145
|
+
actionTaken: (0, pg_core_1.varchar)("action_taken", { length: 50 }).$type(),
|
|
146
|
+
autoActionApplied: (0, pg_core_1.boolean)("auto_action_applied").notNull().default(false),
|
|
147
|
+
requiresManualReview: (0, pg_core_1.boolean)("requires_manual_review")
|
|
148
|
+
.notNull()
|
|
149
|
+
.default(false),
|
|
150
|
+
// Resolution Details
|
|
151
|
+
resolvedBy: (0, pg_core_1.text)("resolved_by"),
|
|
152
|
+
resolvedAt: (0, pg_core_1.timestamp)("resolved_at", { withTimezone: true }),
|
|
153
|
+
resolutionNotes: (0, pg_core_1.text)("resolution_notes"),
|
|
154
|
+
resolutionType: (0, pg_core_1.varchar)("resolution_type", { length: 30 }).$type(),
|
|
155
|
+
// Impact Assessment
|
|
156
|
+
impactScore: (0, pg_core_1.integer)("impact_score").default(1), // 1-10 scale
|
|
157
|
+
affectedUsers: (0, pg_core_1.integer)("affected_users").default(0),
|
|
158
|
+
businessImpact: (0, pg_core_1.varchar)("business_impact", { length: 20 }).$type(),
|
|
159
|
+
// Follow-up and Monitoring
|
|
160
|
+
followUpRequired: (0, pg_core_1.boolean)("follow_up_required").notNull().default(false),
|
|
161
|
+
followUpDate: (0, pg_core_1.timestamp)("follow_up_date", { withTimezone: true }),
|
|
162
|
+
monitoringPeriod: (0, pg_core_1.integer)("monitoring_period"), // days
|
|
163
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
164
|
+
.defaultNow()
|
|
165
|
+
.notNull(),
|
|
166
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
167
|
+
.defaultNow()
|
|
168
|
+
.notNull(),
|
|
169
|
+
}, (table) => ({
|
|
170
|
+
storeIdIndex: (0, pg_core_1.index)("idx_violations_store_id").on(table.storeId),
|
|
171
|
+
statusIndex: (0, pg_core_1.index)("idx_violations_status").on(table.status),
|
|
172
|
+
severityIndex: (0, pg_core_1.index)("idx_violations_severity").on(table.severity),
|
|
173
|
+
detectedByIndex: (0, pg_core_1.index)("idx_violations_detected_by").on(table.detectedBy),
|
|
174
|
+
// Workflow indexes
|
|
175
|
+
pendingReviewIndex: (0, pg_core_1.index)("idx_violations_pending_review").on(table.status, table.requiresManualReview),
|
|
176
|
+
// Performance monitoring indexes
|
|
177
|
+
violationTypeIndex: (0, pg_core_1.index)("idx_violations_type_category").on(table.violationType, table.violationCategory),
|
|
178
|
+
// Resolution tracking indexes
|
|
179
|
+
resolutionWorkflowIndex: (0, pg_core_1.index)("idx_violations_resolution").on(table.status, table.resolvedAt),
|
|
180
|
+
// Follow-up indexes
|
|
181
|
+
followUpIndex: (0, pg_core_1.index)("idx_violations_follow_up").on(table.followUpRequired, table.followUpDate),
|
|
182
|
+
}));
|
|
183
|
+
// Compliance Actions History - Enhanced
|
|
184
|
+
exports.complianceActions = (0, pg_core_1.pgTable)("compliance_actions", {
|
|
185
|
+
id: (0, pg_core_1.text)("id")
|
|
186
|
+
.primaryKey()
|
|
187
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
188
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
189
|
+
violationId: (0, pg_core_1.text)("violation_id").references(() => exports.complianceViolations.id),
|
|
190
|
+
// Action Classification
|
|
191
|
+
actionType: (0, pg_core_1.varchar)("action_type", { length: 50 })
|
|
192
|
+
.notNull()
|
|
193
|
+
.$type(),
|
|
194
|
+
actionCategory: (0, pg_core_1.varchar)("action_category", { length: 30 }).$type(),
|
|
195
|
+
severity: (0, pg_core_1.varchar)("severity", { length: 20 })
|
|
196
|
+
.notNull()
|
|
197
|
+
.$type(),
|
|
198
|
+
// Action Details
|
|
199
|
+
reason: (0, pg_core_1.text)("reason").notNull(),
|
|
200
|
+
description: (0, pg_core_1.text)("description"),
|
|
201
|
+
justification: (0, pg_core_1.text)("justification"),
|
|
202
|
+
// Duration and Scope
|
|
203
|
+
duration: (0, pg_core_1.integer)("duration"), // Duration in hours for temporary actions
|
|
204
|
+
durationType: (0, pg_core_1.varchar)("duration_type", { length: 20 }).$type(),
|
|
205
|
+
scope: (0, pg_core_1.jsonb)("scope").$type(),
|
|
206
|
+
// Execution Details
|
|
207
|
+
performedBy: (0, pg_core_1.text)("performed_by").notNull(),
|
|
208
|
+
performedByType: (0, pg_core_1.varchar)("performed_by_type", { length: 20 })
|
|
209
|
+
.notNull()
|
|
210
|
+
.$type(),
|
|
211
|
+
isAutomated: (0, pg_core_1.boolean)("is_automated").notNull().default(false),
|
|
212
|
+
automationRule: (0, pg_core_1.text)("automation_rule"), // Reference to the automation rule used
|
|
213
|
+
// Impact and Effectiveness
|
|
214
|
+
impactLevel: (0, pg_core_1.varchar)("impact_level", { length: 20 }).$type(),
|
|
215
|
+
effectiveness: (0, pg_core_1.varchar)("effectiveness", { length: 20 }).$type(),
|
|
216
|
+
// Additional Data and Context
|
|
217
|
+
additionalData: (0, pg_core_1.jsonb)("additional_data").$type(),
|
|
218
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
219
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"), // Not visible to store owner
|
|
220
|
+
// Review and Approval
|
|
221
|
+
requiresApproval: (0, pg_core_1.boolean)("requires_approval").notNull().default(false),
|
|
222
|
+
approvedBy: (0, pg_core_1.text)("approved_by"),
|
|
223
|
+
approvedAt: (0, pg_core_1.timestamp)("approved_at", { withTimezone: true }),
|
|
224
|
+
approvalNotes: (0, pg_core_1.text)("approval_notes"),
|
|
225
|
+
// Execution Tracking
|
|
226
|
+
executedAt: (0, pg_core_1.timestamp)("executed_at", { withTimezone: true }),
|
|
227
|
+
executionStatus: (0, pg_core_1.varchar)("execution_status", { length: 20 })
|
|
228
|
+
.notNull()
|
|
229
|
+
.default("PENDING")
|
|
230
|
+
.$type(),
|
|
231
|
+
executionNotes: (0, pg_core_1.text)("execution_notes"),
|
|
232
|
+
// Reversal and Appeals
|
|
233
|
+
isReversible: (0, pg_core_1.boolean)("is_reversible").notNull().default(true),
|
|
234
|
+
reversedBy: (0, pg_core_1.text)("reversed_by"),
|
|
235
|
+
reversedAt: (0, pg_core_1.timestamp)("reversed_at", { withTimezone: true }),
|
|
236
|
+
reversalReason: (0, pg_core_1.text)("reversal_reason"),
|
|
237
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
238
|
+
.defaultNow()
|
|
239
|
+
.notNull(),
|
|
240
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
241
|
+
.defaultNow()
|
|
242
|
+
.notNull(),
|
|
243
|
+
}, (table) => ({
|
|
244
|
+
storeIdIndex: (0, pg_core_1.index)("idx_actions_store_id").on(table.storeId),
|
|
245
|
+
actionTypeIndex: (0, pg_core_1.index)("idx_actions_type").on(table.actionType),
|
|
246
|
+
violationIdIndex: (0, pg_core_1.index)("idx_actions_violation_id").on(table.violationId),
|
|
247
|
+
// Workflow indexes
|
|
248
|
+
approvalWorkflowIndex: (0, pg_core_1.index)("idx_actions_approval_workflow").on(table.requiresApproval, table.approvedAt),
|
|
249
|
+
executionStatusIndex: (0, pg_core_1.index)("idx_actions_execution_status").on(table.executionStatus, table.executedAt),
|
|
250
|
+
// Performance tracking indexes
|
|
251
|
+
automationIndex: (0, pg_core_1.index)("idx_actions_automation").on(table.isAutomated, table.actionType),
|
|
252
|
+
effectivenessIndex: (0, pg_core_1.index)("idx_actions_effectiveness").on(table.effectiveness, table.impactLevel),
|
|
253
|
+
}));
|
|
254
|
+
// Store Policies Table - Enhanced
|
|
255
|
+
exports.storePolicies = (0, pg_core_1.pgTable)("store_policies", {
|
|
256
|
+
id: (0, pg_core_1.text)("id")
|
|
257
|
+
.primaryKey()
|
|
258
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
259
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
260
|
+
// Policy Classification
|
|
261
|
+
policyType: (0, pg_core_1.varchar)("policy_type", { length: 50 })
|
|
262
|
+
.notNull()
|
|
263
|
+
.$type(),
|
|
264
|
+
policyCategory: (0, pg_core_1.varchar)("policy_category", { length: 30 }).$type(),
|
|
265
|
+
// Content and Metadata
|
|
266
|
+
title: (0, pg_core_1.varchar)("title", { length: 255 }).notNull(),
|
|
267
|
+
content: (0, pg_core_1.text)("content").notNull(),
|
|
268
|
+
summary: (0, pg_core_1.text)("summary"), // Brief summary for quick reference
|
|
269
|
+
// Versioning
|
|
270
|
+
version: (0, pg_core_1.varchar)("version", { length: 20 }).notNull().default("1.0"),
|
|
271
|
+
versionNotes: (0, pg_core_1.text)("version_notes"),
|
|
272
|
+
previousVersionId: (0, pg_core_1.text)("previous_version_id"),
|
|
273
|
+
// Status and Lifecycle
|
|
274
|
+
status: (0, pg_core_1.varchar)("status", { length: 20 })
|
|
275
|
+
.notNull()
|
|
276
|
+
.default("DRAFT")
|
|
277
|
+
.$type(),
|
|
278
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(false),
|
|
279
|
+
isMandatory: (0, pg_core_1.boolean)("is_mandatory").notNull().default(false),
|
|
280
|
+
isPublic: (0, pg_core_1.boolean)("is_public").notNull().default(true),
|
|
281
|
+
// Compliance and Legal
|
|
282
|
+
requiresAcceptance: (0, pg_core_1.boolean)("requires_acceptance").notNull().default(false),
|
|
283
|
+
acceptanceTracking: (0, pg_core_1.boolean)("acceptance_tracking").notNull().default(false),
|
|
284
|
+
legalReviewRequired: (0, pg_core_1.boolean)("legal_review_required")
|
|
285
|
+
.notNull()
|
|
286
|
+
.default(false),
|
|
287
|
+
complianceStandards: (0, pg_core_1.jsonb)("compliance_standards")
|
|
288
|
+
.$type()
|
|
289
|
+
.default([]), // GDPR, CCPA, etc.
|
|
290
|
+
jurisdictions: (0, pg_core_1.jsonb)("jurisdictions").$type().default([]), // Countries/regions where this applies
|
|
291
|
+
// Approval Workflow
|
|
292
|
+
approvedBy: (0, pg_core_1.text)("approved_by"),
|
|
293
|
+
approvedAt: (0, pg_core_1.timestamp)("approved_at", { withTimezone: true }),
|
|
294
|
+
approvalNotes: (0, pg_core_1.text)("approval_notes"),
|
|
295
|
+
legalReviewedBy: (0, pg_core_1.text)("legal_reviewed_by"),
|
|
296
|
+
legalReviewedAt: (0, pg_core_1.timestamp)("legal_reviewed_at", { withTimezone: true }),
|
|
297
|
+
legalReviewNotes: (0, pg_core_1.text)("legal_review_notes"),
|
|
298
|
+
// Effective Dates
|
|
299
|
+
effectiveFrom: (0, pg_core_1.timestamp)("effective_from", { withTimezone: true }),
|
|
300
|
+
effectiveUntil: (0, pg_core_1.timestamp)("effective_until", { withTimezone: true }),
|
|
301
|
+
lastReviewDate: (0, pg_core_1.timestamp)("last_review_date", { withTimezone: true }),
|
|
302
|
+
nextReviewDate: (0, pg_core_1.timestamp)("next_review_date", { withTimezone: true }),
|
|
303
|
+
// Localization
|
|
304
|
+
language: (0, pg_core_1.varchar)("language", { length: 10 }).default("en"),
|
|
305
|
+
localizations: (0, pg_core_1.jsonb)("localizations")
|
|
306
|
+
.$type()
|
|
307
|
+
.default({}),
|
|
308
|
+
// Display and Integration
|
|
309
|
+
displayOrder: (0, pg_core_1.integer)("display_order").default(0),
|
|
310
|
+
categoryOrder: (0, pg_core_1.integer)("category_order").default(0),
|
|
311
|
+
// Templates and Customization
|
|
312
|
+
templateId: (0, pg_core_1.text)("template_id"), // Reference to policy template
|
|
313
|
+
customFields: (0, pg_core_1.jsonb)("custom_fields")
|
|
314
|
+
.$type()
|
|
315
|
+
.default({}),
|
|
316
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
317
|
+
.defaultNow()
|
|
318
|
+
.notNull(),
|
|
319
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
320
|
+
.defaultNow()
|
|
321
|
+
.notNull(),
|
|
322
|
+
}, (table) => ({
|
|
323
|
+
storeIdIndex: (0, pg_core_1.index)("idx_policies_store_id").on(table.storeId),
|
|
324
|
+
policyTypeIndex: (0, pg_core_1.index)("idx_policies_type").on(table.policyType),
|
|
325
|
+
statusIndex: (0, pg_core_1.index)("idx_policies_status").on(table.status),
|
|
326
|
+
// Active policies index for quick filtering
|
|
327
|
+
activePoliciesIndex: (0, pg_core_1.index)("idx_policies_active").on(table.storeId, table.isActive, table.policyType),
|
|
328
|
+
// Compliance workflow indexes
|
|
329
|
+
approvalWorkflowIndex: (0, pg_core_1.index)("idx_policies_approval_workflow").on(table.status, table.legalReviewRequired),
|
|
330
|
+
// Review scheduling indexes
|
|
331
|
+
reviewScheduleIndex: (0, pg_core_1.index)("idx_policies_review_schedule").on(table.nextReviewDate, table.isActive),
|
|
332
|
+
// Ensure only one active policy per type per store
|
|
333
|
+
uniqueActivePolicyPerType: (0, pg_core_1.unique)("unique_active_policy_per_type").on(table.storeId, table.policyType, table.isActive),
|
|
334
|
+
}));
|
|
335
|
+
// Appeals Table - Enhanced
|
|
336
|
+
exports.appeals = (0, pg_core_1.pgTable)("appeals", {
|
|
337
|
+
id: (0, pg_core_1.text)("id")
|
|
338
|
+
.primaryKey()
|
|
339
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
340
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
341
|
+
userId: (0, pg_core_1.text)("user_id").notNull(),
|
|
342
|
+
// Appeal Classification
|
|
343
|
+
appealType: (0, pg_core_1.varchar)("appeal_type", { length: 50 })
|
|
344
|
+
.notNull()
|
|
345
|
+
.$type(),
|
|
346
|
+
appealCategory: (0, pg_core_1.varchar)("appeal_category", { length: 30 }).$type(),
|
|
347
|
+
priority: (0, pg_core_1.varchar)("priority", { length: 20 })
|
|
348
|
+
.notNull()
|
|
349
|
+
.default("NORMAL")
|
|
350
|
+
.$type(),
|
|
351
|
+
// Original Action References
|
|
352
|
+
originalViolationId: (0, pg_core_1.text)("original_violation_id").references(() => exports.complianceViolations.id),
|
|
353
|
+
originalActionId: (0, pg_core_1.text)("original_action_id").references(() => exports.complianceActions.id),
|
|
354
|
+
// Appeal Content
|
|
355
|
+
title: (0, pg_core_1.varchar)("title", { length: 255 }).notNull(),
|
|
356
|
+
reason: (0, pg_core_1.text)("reason").notNull(),
|
|
357
|
+
description: (0, pg_core_1.text)("description"),
|
|
358
|
+
requestedOutcome: (0, pg_core_1.text)("requested_outcome"), // What the appellant wants to happen
|
|
359
|
+
// Evidence and Supporting Documents
|
|
360
|
+
evidence: (0, pg_core_1.jsonb)("evidence").$type(),
|
|
361
|
+
// Status and Processing
|
|
362
|
+
status: (0, pg_core_1.varchar)("status", { length: 20 })
|
|
363
|
+
.notNull()
|
|
364
|
+
.default("SUBMITTED")
|
|
365
|
+
.$type(),
|
|
366
|
+
// Assignment and Review
|
|
367
|
+
assignedTo: (0, pg_core_1.text)("assigned_to"),
|
|
368
|
+
assignedAt: (0, pg_core_1.timestamp)("assigned_at", { withTimezone: true }),
|
|
369
|
+
reviewLevel: (0, pg_core_1.varchar)("review_level", { length: 20 })
|
|
370
|
+
.$type()
|
|
371
|
+
.default("FIRST_LEVEL"),
|
|
372
|
+
// Review Process
|
|
373
|
+
reviewedBy: (0, pg_core_1.text)("reviewed_by"),
|
|
374
|
+
reviewedAt: (0, pg_core_1.timestamp)("reviewed_at", { withTimezone: true }),
|
|
375
|
+
reviewStartedAt: (0, pg_core_1.timestamp)("review_started_at", { withTimezone: true }),
|
|
376
|
+
// Decision and Outcome
|
|
377
|
+
decision: (0, pg_core_1.varchar)("decision", { length: 20 }).$type(),
|
|
378
|
+
reasoning: (0, pg_core_1.text)("reasoning"),
|
|
379
|
+
actionTaken: (0, pg_core_1.text)("action_taken"),
|
|
380
|
+
compensationOffered: (0, pg_core_1.text)("compensation_offered"),
|
|
381
|
+
// Review Notes and Communication
|
|
382
|
+
reviewNotes: (0, pg_core_1.text)("review_notes"),
|
|
383
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"), // Not visible to appellant
|
|
384
|
+
communicationHistory: (0, pg_core_1.jsonb)("communication_history")
|
|
385
|
+
.$type()
|
|
386
|
+
.default([]),
|
|
387
|
+
// Timeline and SLA
|
|
388
|
+
submittedAt: (0, pg_core_1.timestamp)("submitted_at", { withTimezone: true })
|
|
389
|
+
.defaultNow()
|
|
390
|
+
.notNull(),
|
|
391
|
+
acknowledgedAt: (0, pg_core_1.timestamp)("acknowledged_at", { withTimezone: true }),
|
|
392
|
+
targetResolutionDate: (0, pg_core_1.timestamp)("target_resolution_date", {
|
|
393
|
+
withTimezone: true,
|
|
394
|
+
}),
|
|
395
|
+
actualResolutionDate: (0, pg_core_1.timestamp)("actual_resolution_date", {
|
|
396
|
+
withTimezone: true,
|
|
397
|
+
}),
|
|
398
|
+
// Escalation
|
|
399
|
+
escalationLevel: (0, pg_core_1.integer)("escalation_level").default(0),
|
|
400
|
+
escalatedBy: (0, pg_core_1.text)("escalated_by"),
|
|
401
|
+
escalatedAt: (0, pg_core_1.timestamp)("escalated_at", { withTimezone: true }),
|
|
402
|
+
escalationReason: (0, pg_core_1.text)("escalation_reason"),
|
|
403
|
+
// Follow-up and Monitoring
|
|
404
|
+
requiresFollowUp: (0, pg_core_1.boolean)("requires_follow_up").notNull().default(false),
|
|
405
|
+
followUpDate: (0, pg_core_1.timestamp)("follow_up_date", { withTimezone: true }),
|
|
406
|
+
satisfactionRating: (0, pg_core_1.integer)("satisfaction_rating"), // 1-5 scale
|
|
407
|
+
appellantFeedback: (0, pg_core_1.text)("appellant_feedback"),
|
|
408
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
409
|
+
.defaultNow()
|
|
410
|
+
.notNull(),
|
|
411
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
412
|
+
.defaultNow()
|
|
413
|
+
.notNull(),
|
|
414
|
+
}, (table) => ({
|
|
415
|
+
storeIdIndex: (0, pg_core_1.index)("idx_appeals_store_id").on(table.storeId),
|
|
416
|
+
statusIndex: (0, pg_core_1.index)("idx_appeals_status").on(table.status),
|
|
417
|
+
appealTypeIndex: (0, pg_core_1.index)("idx_appeals_type").on(table.appealType),
|
|
418
|
+
// Assignment and workflow indexes
|
|
419
|
+
assignmentIndex: (0, pg_core_1.index)("idx_appeals_assignment").on(table.assignedTo, table.status),
|
|
420
|
+
reviewLevelIndex: (0, pg_core_1.index)("idx_appeals_review_level").on(table.reviewLevel, table.status),
|
|
421
|
+
// SLA and timeline tracking indexes
|
|
422
|
+
slaTrackingIndex: (0, pg_core_1.index)("idx_appeals_sla_tracking").on(table.targetResolutionDate, table.status),
|
|
423
|
+
// Escalation tracking indexes
|
|
424
|
+
escalationIndex: (0, pg_core_1.index)("idx_appeals_escalation").on(table.escalationLevel, table.escalatedAt),
|
|
425
|
+
// Performance analytics indexes
|
|
426
|
+
decisionTimeIndex: (0, pg_core_1.index)("idx_appeals_decision_time").on(table.submittedAt, table.actualResolutionDate),
|
|
427
|
+
}));
|
|
428
|
+
// Relations
|
|
429
|
+
exports.storeComplianceRelations = (0, drizzle_orm_1.relations)(exports.storeCompliance, ({ many }) => ({
|
|
430
|
+
violations: many(exports.complianceViolations),
|
|
431
|
+
actions: many(exports.complianceActions),
|
|
432
|
+
policies: many(exports.storePolicies),
|
|
433
|
+
appeals: many(exports.appeals),
|
|
434
|
+
}));
|
|
435
|
+
exports.complianceViolationsRelations = (0, drizzle_orm_1.relations)(exports.complianceViolations, ({ one, many }) => ({
|
|
436
|
+
compliance: one(exports.storeCompliance, {
|
|
437
|
+
fields: [exports.complianceViolations.storeId],
|
|
438
|
+
references: [exports.storeCompliance.storeId],
|
|
439
|
+
}),
|
|
440
|
+
actions: many(exports.complianceActions),
|
|
441
|
+
appeals: many(exports.appeals),
|
|
442
|
+
}));
|
|
443
|
+
exports.complianceActionsRelations = (0, drizzle_orm_1.relations)(exports.complianceActions, ({ one }) => ({
|
|
444
|
+
compliance: one(exports.storeCompliance, {
|
|
445
|
+
fields: [exports.complianceActions.storeId],
|
|
446
|
+
references: [exports.storeCompliance.storeId],
|
|
447
|
+
}),
|
|
448
|
+
violation: one(exports.complianceViolations, {
|
|
449
|
+
fields: [exports.complianceActions.violationId],
|
|
450
|
+
references: [exports.complianceViolations.id],
|
|
451
|
+
}),
|
|
452
|
+
}));
|
|
453
|
+
exports.storePoliciesRelations = (0, drizzle_orm_1.relations)(exports.storePolicies, ({ one }) => ({
|
|
454
|
+
compliance: one(exports.storeCompliance, {
|
|
455
|
+
fields: [exports.storePolicies.storeId],
|
|
456
|
+
references: [exports.storeCompliance.storeId],
|
|
457
|
+
}),
|
|
458
|
+
}));
|
|
459
|
+
exports.appealsRelations = (0, drizzle_orm_1.relations)(exports.appeals, ({ one }) => ({
|
|
460
|
+
compliance: one(exports.storeCompliance, {
|
|
461
|
+
fields: [exports.appeals.storeId],
|
|
462
|
+
references: [exports.storeCompliance.storeId],
|
|
463
|
+
}),
|
|
464
|
+
violation: one(exports.complianceViolations, {
|
|
465
|
+
fields: [exports.appeals.originalViolationId],
|
|
466
|
+
references: [exports.complianceViolations.id],
|
|
467
|
+
}),
|
|
468
|
+
action: one(exports.complianceActions, {
|
|
469
|
+
fields: [exports.appeals.originalActionId],
|
|
470
|
+
references: [exports.complianceActions.id],
|
|
471
|
+
}),
|
|
472
|
+
}));
|