@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,208 @@
|
|
|
1
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
+
import {
|
|
3
|
+
boolean,
|
|
4
|
+
index,
|
|
5
|
+
integer,
|
|
6
|
+
jsonb,
|
|
7
|
+
pgTable,
|
|
8
|
+
text,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/pg-core";
|
|
12
|
+
|
|
13
|
+
// Admin Users Table
|
|
14
|
+
export const adminUsers = pgTable(
|
|
15
|
+
"admin_users",
|
|
16
|
+
{
|
|
17
|
+
id: text("id")
|
|
18
|
+
.primaryKey()
|
|
19
|
+
.$defaultFn(() => createId()),
|
|
20
|
+
|
|
21
|
+
userId: text("user_id").notNull().unique(),
|
|
22
|
+
email: varchar("email", { length: 255 }).notNull(),
|
|
23
|
+
name: varchar("name", { length: 255 }).notNull(),
|
|
24
|
+
|
|
25
|
+
// Role and Permissions
|
|
26
|
+
role: varchar("role", { length: 30 })
|
|
27
|
+
.notNull()
|
|
28
|
+
.$type<
|
|
29
|
+
| "SUPER_ADMIN"
|
|
30
|
+
| "COMPLIANCE_ADMIN"
|
|
31
|
+
| "CONTENT_MODERATOR"
|
|
32
|
+
| "CUSTOMER_SUPPORT"
|
|
33
|
+
| "ANALYST"
|
|
34
|
+
| "REVIEWER"
|
|
35
|
+
>(),
|
|
36
|
+
|
|
37
|
+
permissions: jsonb("permissions").$type<string[]>().default([]),
|
|
38
|
+
|
|
39
|
+
// Status
|
|
40
|
+
isActive: boolean("is_active").notNull().default(true),
|
|
41
|
+
lastLoginAt: timestamp("last_login_at", { withTimezone: true }),
|
|
42
|
+
|
|
43
|
+
// Department and Team
|
|
44
|
+
department: varchar("department", { length: 50 }),
|
|
45
|
+
team: varchar("team", { length: 50 }),
|
|
46
|
+
|
|
47
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
48
|
+
.defaultNow()
|
|
49
|
+
.notNull(),
|
|
50
|
+
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
51
|
+
.defaultNow()
|
|
52
|
+
.notNull(),
|
|
53
|
+
},
|
|
54
|
+
(table) => ({
|
|
55
|
+
userIdIndex: index("idx_admin_users_user_id").on(table.userId),
|
|
56
|
+
emailIndex: index("idx_admin_users_email").on(table.email),
|
|
57
|
+
roleIndex: index("idx_admin_users_role").on(table.role),
|
|
58
|
+
activeIndex: index("idx_admin_users_active").on(table.isActive),
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Admin Actions Table
|
|
63
|
+
export const adminActions = pgTable(
|
|
64
|
+
"admin_actions",
|
|
65
|
+
{
|
|
66
|
+
id: text("id")
|
|
67
|
+
.primaryKey()
|
|
68
|
+
.$defaultFn(() => createId()),
|
|
69
|
+
|
|
70
|
+
adminUserId: text("admin_user_id").notNull(),
|
|
71
|
+
|
|
72
|
+
// Action Details
|
|
73
|
+
actionType: varchar("action_type", { length: 50 })
|
|
74
|
+
.notNull()
|
|
75
|
+
.$type<
|
|
76
|
+
| "COMPLIANCE_OVERRIDE"
|
|
77
|
+
| "MANUAL_REVIEW"
|
|
78
|
+
| "STORE_VERIFICATION"
|
|
79
|
+
| "CONTENT_APPROVAL"
|
|
80
|
+
| "VIOLATION_DISMISS"
|
|
81
|
+
| "APPEAL_REVIEW"
|
|
82
|
+
| "POLICY_UPDATE"
|
|
83
|
+
| "SYSTEM_CONFIG"
|
|
84
|
+
>(),
|
|
85
|
+
|
|
86
|
+
targetType: varchar("target_type", { length: 30 }).$type<
|
|
87
|
+
| "STORE"
|
|
88
|
+
| "USER"
|
|
89
|
+
| "VIOLATION"
|
|
90
|
+
| "APPEAL"
|
|
91
|
+
| "CONTENT"
|
|
92
|
+
| "POLICY"
|
|
93
|
+
| "SYSTEM"
|
|
94
|
+
>(),
|
|
95
|
+
|
|
96
|
+
targetId: text("target_id").notNull(),
|
|
97
|
+
|
|
98
|
+
// Action Data
|
|
99
|
+
actionData: jsonb("action_data")
|
|
100
|
+
.$type<Record<string, unknown>>()
|
|
101
|
+
.default({}),
|
|
102
|
+
reason: text("reason").notNull(),
|
|
103
|
+
notes: text("notes"),
|
|
104
|
+
|
|
105
|
+
// Impact and Risk
|
|
106
|
+
impactLevel: varchar("impact_level", { length: 20 }).$type<
|
|
107
|
+
"LOW" | "MEDIUM" | "HIGH" | "CRITICAL"
|
|
108
|
+
>(),
|
|
109
|
+
|
|
110
|
+
requiresApproval: boolean("requires_approval").notNull().default(false),
|
|
111
|
+
approvedBy: text("approved_by"),
|
|
112
|
+
approvedAt: timestamp("approved_at", { withTimezone: true }),
|
|
113
|
+
|
|
114
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
115
|
+
.defaultNow()
|
|
116
|
+
.notNull(),
|
|
117
|
+
},
|
|
118
|
+
(table) => ({
|
|
119
|
+
adminUserIndex: index("idx_admin_actions_user").on(table.adminUserId),
|
|
120
|
+
actionTypeIndex: index("idx_admin_actions_type").on(table.actionType),
|
|
121
|
+
targetIndex: index("idx_admin_actions_target").on(
|
|
122
|
+
table.targetType,
|
|
123
|
+
table.targetId,
|
|
124
|
+
),
|
|
125
|
+
approvalIndex: index("idx_admin_actions_approval").on(
|
|
126
|
+
table.requiresApproval,
|
|
127
|
+
table.approvedAt,
|
|
128
|
+
),
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// Review Queues Table
|
|
133
|
+
export const reviewQueues = pgTable(
|
|
134
|
+
"review_queues",
|
|
135
|
+
{
|
|
136
|
+
id: text("id")
|
|
137
|
+
.primaryKey()
|
|
138
|
+
.$defaultFn(() => createId()),
|
|
139
|
+
|
|
140
|
+
queueName: varchar("queue_name", { length: 100 }).notNull(),
|
|
141
|
+
queueType: varchar("queue_type", { length: 30 })
|
|
142
|
+
.notNull()
|
|
143
|
+
.$type<
|
|
144
|
+
| "COMPLIANCE_REVIEW"
|
|
145
|
+
| "CONTENT_MODERATION"
|
|
146
|
+
| "STORE_VERIFICATION"
|
|
147
|
+
| "APPEAL_REVIEW"
|
|
148
|
+
| "HIGH_RISK_MONITORING"
|
|
149
|
+
>(),
|
|
150
|
+
|
|
151
|
+
// Item Details
|
|
152
|
+
itemType: varchar("item_type", { length: 30 }).$type<
|
|
153
|
+
"STORE" | "VIOLATION" | "APPEAL" | "CONTENT" | "USER"
|
|
154
|
+
>(),
|
|
155
|
+
|
|
156
|
+
itemId: text("item_id").notNull(),
|
|
157
|
+
|
|
158
|
+
// Priority and Status
|
|
159
|
+
priority: varchar("priority", { length: 20 })
|
|
160
|
+
.notNull()
|
|
161
|
+
.default("NORMAL")
|
|
162
|
+
.$type<"LOW" | "NORMAL" | "HIGH" | "URGENT" | "CRITICAL">(),
|
|
163
|
+
|
|
164
|
+
status: varchar("status", { length: 20 })
|
|
165
|
+
.notNull()
|
|
166
|
+
.default("PENDING")
|
|
167
|
+
.$type<
|
|
168
|
+
| "PENDING"
|
|
169
|
+
| "ASSIGNED"
|
|
170
|
+
| "IN_PROGRESS"
|
|
171
|
+
| "COMPLETED"
|
|
172
|
+
| "ESCALATED"
|
|
173
|
+
| "CANCELLED"
|
|
174
|
+
>(),
|
|
175
|
+
|
|
176
|
+
// Assignment
|
|
177
|
+
assignedTo: text("assigned_to"),
|
|
178
|
+
assignedAt: timestamp("assigned_at", { withTimezone: true }),
|
|
179
|
+
|
|
180
|
+
// SLA and Timing
|
|
181
|
+
slaDeadline: timestamp("sla_deadline", { withTimezone: true }),
|
|
182
|
+
estimatedEffort: integer("estimated_effort"), // minutes
|
|
183
|
+
|
|
184
|
+
// Context
|
|
185
|
+
context: jsonb("context").$type<Record<string, unknown>>().default({}),
|
|
186
|
+
reviewNotes: text("review_notes"),
|
|
187
|
+
|
|
188
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
189
|
+
.defaultNow()
|
|
190
|
+
.notNull(),
|
|
191
|
+
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
192
|
+
.defaultNow()
|
|
193
|
+
.notNull(),
|
|
194
|
+
},
|
|
195
|
+
(table) => ({
|
|
196
|
+
queueTypeIndex: index("idx_queues_type").on(table.queueType),
|
|
197
|
+
statusIndex: index("idx_queues_status").on(table.status),
|
|
198
|
+
assignmentIndex: index("idx_queues_assignment").on(
|
|
199
|
+
table.assignedTo,
|
|
200
|
+
table.status,
|
|
201
|
+
),
|
|
202
|
+
priorityIndex: index("idx_queues_priority").on(
|
|
203
|
+
table.priority,
|
|
204
|
+
table.createdAt,
|
|
205
|
+
),
|
|
206
|
+
slaIndex: index("idx_queues_sla").on(table.slaDeadline, table.status),
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
+
import {
|
|
3
|
+
boolean,
|
|
4
|
+
decimal,
|
|
5
|
+
index,
|
|
6
|
+
integer,
|
|
7
|
+
jsonb,
|
|
8
|
+
pgTable,
|
|
9
|
+
text,
|
|
10
|
+
timestamp,
|
|
11
|
+
varchar,
|
|
12
|
+
} from "drizzle-orm/pg-core";
|
|
13
|
+
|
|
14
|
+
// Content Scans Table
|
|
15
|
+
export const contentScans = pgTable(
|
|
16
|
+
"content_scans",
|
|
17
|
+
{
|
|
18
|
+
id: text("id")
|
|
19
|
+
.primaryKey()
|
|
20
|
+
.$defaultFn(() => createId()),
|
|
21
|
+
|
|
22
|
+
// Content Information
|
|
23
|
+
contentId: text("content_id").notNull(),
|
|
24
|
+
contentType: varchar("content_type", { length: 50 })
|
|
25
|
+
.notNull()
|
|
26
|
+
.$type<
|
|
27
|
+
| "STORE_DESCRIPTION"
|
|
28
|
+
| "PRODUCT_TITLE"
|
|
29
|
+
| "PRODUCT_DESCRIPTION"
|
|
30
|
+
| "BLOG_POST"
|
|
31
|
+
| "USER_REVIEW"
|
|
32
|
+
| "STORE_NAME"
|
|
33
|
+
| "IMAGE"
|
|
34
|
+
| "VIDEO"
|
|
35
|
+
>(),
|
|
36
|
+
|
|
37
|
+
storeId: text("store_id"),
|
|
38
|
+
userId: text("user_id"),
|
|
39
|
+
|
|
40
|
+
// Scan Configuration
|
|
41
|
+
scanType: varchar("scan_type", { length: 30 })
|
|
42
|
+
.$type<"AUTOMATED" | "MANUAL" | "SCHEDULED" | "TRIGGERED">()
|
|
43
|
+
.default("AUTOMATED"),
|
|
44
|
+
|
|
45
|
+
provider: varchar("provider", { length: 30 })
|
|
46
|
+
.default("OPENAI")
|
|
47
|
+
.$type<
|
|
48
|
+
"OPENAI" | "GOOGLE_PERSPECTIVE" | "AZURE_CONTENT_SAFETY" | "INTERNAL"
|
|
49
|
+
>(),
|
|
50
|
+
|
|
51
|
+
// Content Data
|
|
52
|
+
originalContent: text("original_content").notNull(),
|
|
53
|
+
processedContent: text("processed_content"), // Cleaned/normalized content
|
|
54
|
+
contentHash: varchar("content_hash", { length: 64 }), // SHA-256 for deduplication
|
|
55
|
+
|
|
56
|
+
// Scan Results
|
|
57
|
+
flagged: boolean("flagged").notNull().default(false),
|
|
58
|
+
confidence: decimal("confidence", { precision: 5, scale: 4 }), // 0-1
|
|
59
|
+
|
|
60
|
+
// OpenAI Moderation Categories
|
|
61
|
+
categories: jsonb("categories").$type<{
|
|
62
|
+
sexual?: boolean;
|
|
63
|
+
hate?: boolean;
|
|
64
|
+
harassment?: boolean;
|
|
65
|
+
selfHarm?: boolean;
|
|
66
|
+
sexualMinors?: boolean;
|
|
67
|
+
hateThreatening?: boolean;
|
|
68
|
+
violenceGraphic?: boolean;
|
|
69
|
+
selfHarmIntent?: boolean;
|
|
70
|
+
selfHarmInstructions?: boolean;
|
|
71
|
+
harassmentThreatening?: boolean;
|
|
72
|
+
violence?: boolean;
|
|
73
|
+
}>(),
|
|
74
|
+
|
|
75
|
+
categoryScores: jsonb("category_scores").$type<{
|
|
76
|
+
sexual?: number;
|
|
77
|
+
hate?: number;
|
|
78
|
+
harassment?: number;
|
|
79
|
+
selfHarm?: number;
|
|
80
|
+
sexualMinors?: number;
|
|
81
|
+
hateThreatening?: number;
|
|
82
|
+
violenceGraphic?: number;
|
|
83
|
+
selfHarmIntent?: number;
|
|
84
|
+
selfHarmInstructions?: number;
|
|
85
|
+
harassmentThreatening?: number;
|
|
86
|
+
violence?: number;
|
|
87
|
+
}>(),
|
|
88
|
+
|
|
89
|
+
// Custom Rules and Patterns
|
|
90
|
+
customViolations: jsonb("custom_violations")
|
|
91
|
+
.$type<
|
|
92
|
+
Array<{
|
|
93
|
+
ruleId: string;
|
|
94
|
+
ruleName: string;
|
|
95
|
+
matched: boolean;
|
|
96
|
+
confidence: number;
|
|
97
|
+
matchedText?: string;
|
|
98
|
+
}>
|
|
99
|
+
>()
|
|
100
|
+
.default([]),
|
|
101
|
+
|
|
102
|
+
// Status and Actions
|
|
103
|
+
status: varchar("status", { length: 20 })
|
|
104
|
+
.notNull()
|
|
105
|
+
.default("COMPLETED")
|
|
106
|
+
.$type<"PENDING" | "PROCESSING" | "COMPLETED" | "FAILED" | "CANCELLED">(),
|
|
107
|
+
|
|
108
|
+
actionTaken: varchar("action_taken", { length: 30 }).$type<
|
|
109
|
+
"NONE" | "FLAGGED" | "BLOCKED" | "QUARANTINED" | "REPORTED"
|
|
110
|
+
>(),
|
|
111
|
+
|
|
112
|
+
// Processing Metadata
|
|
113
|
+
processingTime: integer("processing_time"), // milliseconds
|
|
114
|
+
cost: decimal("cost", { precision: 8, scale: 6 }), // API cost in USD
|
|
115
|
+
|
|
116
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
117
|
+
.defaultNow()
|
|
118
|
+
.notNull(),
|
|
119
|
+
},
|
|
120
|
+
(table) => ({
|
|
121
|
+
contentIdIndex: index("idx_scans_content").on(table.contentId),
|
|
122
|
+
storeIdIndex: index("idx_scans_store").on(table.storeId),
|
|
123
|
+
flaggedIndex: index("idx_scans_flagged").on(
|
|
124
|
+
table.flagged,
|
|
125
|
+
table.confidence,
|
|
126
|
+
),
|
|
127
|
+
statusIndex: index("idx_scans_status").on(table.status),
|
|
128
|
+
contentTypeIndex: index("idx_scans_content_type").on(table.contentType),
|
|
129
|
+
hashIndex: index("idx_scans_hash").on(table.contentHash),
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// Moderation Rules Table
|
|
134
|
+
export const moderationRules = pgTable(
|
|
135
|
+
"moderation_rules",
|
|
136
|
+
{
|
|
137
|
+
id: text("id")
|
|
138
|
+
.primaryKey()
|
|
139
|
+
.$defaultFn(() => createId()),
|
|
140
|
+
|
|
141
|
+
name: varchar("name", { length: 100 }).notNull(),
|
|
142
|
+
description: text("description"),
|
|
143
|
+
|
|
144
|
+
ruleType: varchar("rule_type", { length: 30 })
|
|
145
|
+
.notNull()
|
|
146
|
+
.$type<
|
|
147
|
+
"KEYWORD_FILTER" | "PATTERN_MATCH" | "ML_CLASSIFIER" | "CUSTOM_LOGIC"
|
|
148
|
+
>(),
|
|
149
|
+
|
|
150
|
+
severity: varchar("severity", { length: 20 })
|
|
151
|
+
.notNull()
|
|
152
|
+
.$type<"LOW" | "MEDIUM" | "HIGH" | "CRITICAL">(),
|
|
153
|
+
|
|
154
|
+
// Rule Configuration
|
|
155
|
+
configuration: jsonb("configuration").$type<{
|
|
156
|
+
keywords?: string[];
|
|
157
|
+
patterns?: string[];
|
|
158
|
+
threshold?: number;
|
|
159
|
+
customLogic?: string;
|
|
160
|
+
}>(),
|
|
161
|
+
|
|
162
|
+
// Targeting
|
|
163
|
+
contentTypes: jsonb("content_types").$type<string[]>().default([]),
|
|
164
|
+
storeTypes: jsonb("store_types").$type<string[]>().default([]),
|
|
165
|
+
|
|
166
|
+
isActive: boolean("is_active").notNull().default(true),
|
|
167
|
+
|
|
168
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
169
|
+
.defaultNow()
|
|
170
|
+
.notNull(),
|
|
171
|
+
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
172
|
+
.defaultNow()
|
|
173
|
+
.notNull(),
|
|
174
|
+
},
|
|
175
|
+
(table) => ({
|
|
176
|
+
nameIndex: index("idx_rules_name").on(table.name),
|
|
177
|
+
typeIndex: index("idx_rules_type").on(table.ruleType),
|
|
178
|
+
activeIndex: index("idx_rules_active").on(table.isActive),
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
// =====================================================
|
|
4
|
+
// SHARED COMMON SCHEMAS
|
|
5
|
+
// =====================================================
|
|
6
|
+
|
|
7
|
+
// CUID2 validation schema aligned with createId() from @paralleldrive/cuid2
|
|
8
|
+
export const CuidSchema = z.string().cuid2();
|
|
9
|
+
|
|
10
|
+
export const GeoLocationSchema = z.object({
|
|
11
|
+
lat: z.number().min(-90).max(90),
|
|
12
|
+
lng: z.number().min(-180).max(180),
|
|
13
|
+
address: z.object({
|
|
14
|
+
line1: z.string(),
|
|
15
|
+
line2: z.string().optional(),
|
|
16
|
+
city: z.string(),
|
|
17
|
+
state: z.string(),
|
|
18
|
+
postalCode: z.string(),
|
|
19
|
+
country: z.string(),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const AuditTrailSchema = z.object({
|
|
24
|
+
action: z.string(),
|
|
25
|
+
performedBy: z.string(),
|
|
26
|
+
performedAt: z.date(),
|
|
27
|
+
details: z.record(z.any()).optional(),
|
|
28
|
+
ipAddress: z.string().optional(),
|
|
29
|
+
userAgent: z.string().optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const MoneySchema = z.object({
|
|
33
|
+
amount: z.number(),
|
|
34
|
+
currency: z.string().length(3).default("USD"),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const ContactInfoSchema = z.object({
|
|
38
|
+
name: z.string().optional(),
|
|
39
|
+
phone: z.string().optional(),
|
|
40
|
+
email: z.string().email().optional(),
|
|
41
|
+
alternatePhone: z.string().optional(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Allow days that are explicitly closed to omit open/close times
|
|
45
|
+
const DayHoursSchema = z.union([
|
|
46
|
+
z.object({
|
|
47
|
+
closed: z.literal(true),
|
|
48
|
+
open: z.string().optional(),
|
|
49
|
+
close: z.string().optional(),
|
|
50
|
+
}),
|
|
51
|
+
z.object({
|
|
52
|
+
open: z.string(),
|
|
53
|
+
close: z.string(),
|
|
54
|
+
closed: z.literal(false).optional(),
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
export const BusinessHoursSchema = z.object({
|
|
59
|
+
timezone: z.string(),
|
|
60
|
+
monday: DayHoursSchema.optional(),
|
|
61
|
+
tuesday: DayHoursSchema.optional(),
|
|
62
|
+
wednesday: DayHoursSchema.optional(),
|
|
63
|
+
thursday: DayHoursSchema.optional(),
|
|
64
|
+
friday: DayHoursSchema.optional(),
|
|
65
|
+
saturday: DayHoursSchema.optional(),
|
|
66
|
+
sunday: DayHoursSchema.optional(),
|
|
67
|
+
holidays: z
|
|
68
|
+
.array(
|
|
69
|
+
z.object({
|
|
70
|
+
date: z.string(),
|
|
71
|
+
name: z.string(),
|
|
72
|
+
closed: z.boolean().default(true),
|
|
73
|
+
}),
|
|
74
|
+
)
|
|
75
|
+
.optional(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Common enum types
|
|
79
|
+
export const CurrencyEnum = z.enum([
|
|
80
|
+
"USD",
|
|
81
|
+
"EUR",
|
|
82
|
+
"GBP",
|
|
83
|
+
"CAD",
|
|
84
|
+
"AUD",
|
|
85
|
+
"JPY",
|
|
86
|
+
"CNY",
|
|
87
|
+
"INR",
|
|
88
|
+
]);
|
|
89
|
+
export const TimezoneEnum = z.enum([
|
|
90
|
+
"UTC",
|
|
91
|
+
"America/New_York",
|
|
92
|
+
"America/Chicago",
|
|
93
|
+
"America/Denver",
|
|
94
|
+
"America/Los_Angeles",
|
|
95
|
+
"Europe/London",
|
|
96
|
+
"Europe/Paris",
|
|
97
|
+
"Europe/Berlin",
|
|
98
|
+
"Asia/Tokyo",
|
|
99
|
+
"Asia/Shanghai",
|
|
100
|
+
"Asia/Kolkata",
|
|
101
|
+
"Australia/Sydney",
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
export type GeoLocation = z.infer<typeof GeoLocationSchema>;
|
|
105
|
+
export type AuditTrail = z.infer<typeof AuditTrailSchema>;
|
|
106
|
+
export type Money = z.infer<typeof MoneySchema>;
|
|
107
|
+
export type ContactInfo = z.infer<typeof ContactInfoSchema>;
|
|
108
|
+
export type BusinessHours = z.infer<typeof BusinessHoursSchema>;
|