@axova/shared 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +2 -0
  3. package/dist/lib/db.d.ts +34406 -1
  4. package/dist/lib/db.js +21 -1
  5. package/dist/middleware/storeOwnership.js +22 -3
  6. package/dist/middleware/storeValidationMiddleware.js +16 -39
  7. package/dist/schemas/admin/admin-schema.d.ts +2 -2
  8. package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +6 -6
  9. package/dist/schemas/common/common-schemas.d.ts +71 -71
  10. package/dist/schemas/compliance/compliance-schema.d.ts +20 -20
  11. package/dist/schemas/compliance/kyc-schema.d.ts +8 -8
  12. package/dist/schemas/customer/customer-schema.d.ts +18 -18
  13. package/dist/schemas/index.d.ts +28 -0
  14. package/dist/schemas/index.js +134 -3
  15. package/dist/schemas/inventory/inventory-tables.d.ts +188 -188
  16. package/dist/schemas/inventory/lot-tables.d.ts +102 -102
  17. package/dist/schemas/order/cart-schema.d.ts +2865 -0
  18. package/dist/schemas/order/cart-schema.js +396 -0
  19. package/dist/schemas/order/order-schema.d.ts +19 -19
  20. package/dist/schemas/order/order-schema.js +8 -2
  21. package/dist/schemas/product/discount-schema.d.ts +3 -3
  22. package/dist/schemas/product/product-schema.d.ts +3 -3
  23. package/dist/schemas/store/store-audit-schema.d.ts +20 -20
  24. package/dist/schemas/store/store-schema.d.ts +182 -2
  25. package/dist/schemas/store/store-schema.js +19 -0
  26. package/dist/schemas/store/storefront-config-schema.d.ts +434 -823
  27. package/dist/schemas/store/storefront-config-schema.js +35 -62
  28. package/dist/utils/subdomain.d.ts +1 -1
  29. package/dist/utils/subdomain.js +10 -15
  30. package/package.json +1 -1
  31. package/src/configs/index.ts +654 -654
  32. package/src/index.ts +26 -23
  33. package/src/interfaces/customer-events.ts +106 -106
  34. package/src/interfaces/inventory-events.ts +545 -545
  35. package/src/interfaces/inventory-types.ts +1004 -1004
  36. package/src/interfaces/order-events.ts +381 -381
  37. package/src/lib/auditLogger.ts +1117 -1117
  38. package/src/lib/authOrganization.ts +153 -153
  39. package/src/lib/db.ts +84 -64
  40. package/src/middleware/serviceAuth.ts +328 -328
  41. package/src/middleware/storeOwnership.ts +199 -181
  42. package/src/middleware/storeValidationMiddleware.ts +17 -50
  43. package/src/middleware/userAuth.ts +248 -248
  44. package/src/schemas/admin/admin-schema.ts +208 -208
  45. package/src/schemas/ai-moderation/ai-moderation-schema.ts +180 -180
  46. package/src/schemas/common/common-schemas.ts +108 -108
  47. package/src/schemas/compliance/compliance-schema.ts +927 -0
  48. package/src/schemas/compliance/kyc-schema.ts +649 -0
  49. package/src/schemas/customer/customer-schema.ts +576 -0
  50. package/src/schemas/index.ts +202 -3
  51. package/src/schemas/inventory/inventory-tables.ts +1927 -0
  52. package/src/schemas/inventory/lot-tables.ts +799 -0
  53. package/src/schemas/order/cart-schema.ts +652 -0
  54. package/src/schemas/order/order-schema.ts +1406 -0
  55. package/src/schemas/product/discount-relations.ts +44 -0
  56. package/src/schemas/product/discount-schema.ts +464 -0
  57. package/src/schemas/product/product-relations.ts +187 -0
  58. package/src/schemas/product/product-schema.ts +955 -0
  59. package/src/schemas/store/ethiopian_business_api.md.resolved +212 -0
  60. package/src/schemas/store/store-audit-schema.ts +1257 -0
  61. package/src/schemas/store/store-schema.ts +682 -0
  62. package/src/schemas/store/store-settings-schema.ts +231 -0
  63. package/src/schemas/store/storefront-config-schema.ts +382 -0
  64. package/src/schemas/types.ts +67 -67
  65. package/src/types/events.ts +646 -646
  66. package/src/utils/errorHandler.ts +44 -44
  67. package/src/utils/subdomain.ts +19 -23
  68. package/tsconfig.json +21 -21
@@ -1,208 +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
- );
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
+ );