@axova/shared 1.0.1 → 1.0.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.
Files changed (31) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -2
  3. package/dist/middleware/storeOwnership.js +3 -22
  4. package/dist/middleware/storeValidationMiddleware.js +39 -16
  5. package/dist/schemas/admin/admin-schema.d.ts +2 -2
  6. package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +2 -2
  7. package/dist/schemas/index.d.ts +0 -28
  8. package/dist/schemas/index.js +3 -125
  9. package/dist/utils/subdomain.d.ts +1 -1
  10. package/dist/utils/subdomain.js +15 -10
  11. package/package.json +1 -1
  12. package/src/index.ts +0 -3
  13. package/src/middleware/storeOwnership.ts +3 -21
  14. package/src/middleware/storeValidationMiddleware.ts +50 -17
  15. package/src/schemas/index.ts +5 -194
  16. package/src/utils/subdomain.ts +15 -11
  17. package/src/schemas/compliance/compliance-schema.ts +0 -927
  18. package/src/schemas/compliance/kyc-schema.ts +0 -649
  19. package/src/schemas/customer/customer-schema.ts +0 -576
  20. package/src/schemas/inventory/inventory-tables.ts +0 -1927
  21. package/src/schemas/inventory/lot-tables.ts +0 -799
  22. package/src/schemas/order/order-schema.ts +0 -1400
  23. package/src/schemas/product/discount-relations.ts +0 -44
  24. package/src/schemas/product/discount-schema.ts +0 -464
  25. package/src/schemas/product/product-relations.ts +0 -187
  26. package/src/schemas/product/product-schema.ts +0 -955
  27. package/src/schemas/store/ethiopian_business_api.md.resolved +0 -212
  28. package/src/schemas/store/store-audit-schema.ts +0 -1257
  29. package/src/schemas/store/store-schema.ts +0 -661
  30. package/src/schemas/store/store-settings-schema.ts +0 -231
  31. package/src/schemas/store/storefront-config-schema.ts +0 -604
package/dist/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from "./middleware/serviceAuth";
7
7
  export * from "./middleware/storeOwnership";
8
8
  export * from "./middleware/storeValidationMiddleware";
9
9
  export * from "./middleware/userAuth";
10
- export * from "./schemas";
11
10
  export * from "./types/events";
12
11
  export * from "./utils/errorHandler";
13
12
  export * from "./utils/subdomain";
package/dist/index.js CHANGED
@@ -32,8 +32,6 @@ __exportStar(require("./middleware/serviceAuth"), exports);
32
32
  __exportStar(require("./middleware/storeOwnership"), exports);
33
33
  __exportStar(require("./middleware/storeValidationMiddleware"), exports);
34
34
  __exportStar(require("./middleware/userAuth"), exports);
35
- // Schemas - Organized by Service
36
- __exportStar(require("./schemas"), exports);
37
35
  // Types and Interfaces
38
36
  __exportStar(require("./types/events"), exports);
39
37
  // Utilities
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireStoreOwner = requireStoreOwner;
4
- const drizzle_orm_1 = require("drizzle-orm");
5
- const db_1 = require("../lib/db");
6
- const store_schema_1 = require("../schemas/store/store-schema");
7
4
  const serviceAuth_1 = require("./serviceAuth");
8
5
  /**
9
6
  * Factory that returns a middleware ensuring the current user owns the target store.
@@ -117,26 +114,10 @@ async function fetchStoreById(storeId) {
117
114
  return store;
118
115
  }
119
116
  }
120
- catch {
121
- // ignore network error and try DB fallback when possible
122
- }
123
- // DB fallback (primarily for in-process store-service)
124
- try {
125
- const result = await db_1.db
126
- .select({
127
- id: store_schema_1.stores.id,
128
- storeName: store_schema_1.stores.storeName,
129
- isActive: store_schema_1.stores.isActive,
130
- userId: store_schema_1.stores.userId,
131
- })
132
- .from(store_schema_1.stores)
133
- .where((0, drizzle_orm_1.eq)(store_schema_1.stores.id, storeId))
134
- .limit(1);
135
- return result[0] || null;
136
- }
137
- catch {
138
- return null;
117
+ catch (error) {
118
+ console.error('Failed to fetch store from store service:', error);
139
119
  }
120
+ return null;
140
121
  }
141
122
  async function attachStoreInfoIfPossible(request, storeId) {
142
123
  try {
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireAnyStore = exports.requireOwnedStore = exports.requireValidStore = exports.clearAllStoreCache = exports.clearStoreCache = exports.validateStoreMiddleware = void 0;
4
- const drizzle_orm_1 = require("drizzle-orm");
5
- const db_1 = require("../lib/db");
6
- const store_schema_1 = require("../schemas/store/store-schema");
4
+ const serviceAuth_1 = require("./serviceAuth");
7
5
  // Store cache to reduce database calls
8
6
  const storeCache = new Map();
9
7
  const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
@@ -83,18 +81,9 @@ const validateStoreMiddleware = (options = {}) => {
83
81
  return; // Successfully validated using cache
84
82
  }
85
83
  }
86
- // Validate store exists and get details from database
87
- const store = await db_1.db
88
- .select({
89
- id: store_schema_1.stores.id,
90
- storeName: store_schema_1.stores.storeName,
91
- isActive: store_schema_1.stores.isActive,
92
- userId: store_schema_1.stores.userId,
93
- })
94
- .from(store_schema_1.stores)
95
- .where((0, drizzle_orm_1.eq)(store_schema_1.stores.id, storeId))
96
- .limit(1);
97
- if (store.length === 0) {
84
+ // Validate store exists and get details from store service API
85
+ const fetchedStore = await fetchStoreById(storeId);
86
+ if (!fetchedStore) {
98
87
  // Cache negative result
99
88
  storeCache.set(storeId, { isValid: false, timestamp: Date.now() });
100
89
  return reply.status(404).send({
@@ -103,7 +92,7 @@ const validateStoreMiddleware = (options = {}) => {
103
92
  code: "STORE_NOT_FOUND",
104
93
  });
105
94
  }
106
- const storeData = store[0];
95
+ const storeData = fetchedStore;
107
96
  // Check if store is active when required
108
97
  if (requireActive && !storeData.isActive) {
109
98
  return reply.status(403).send({
@@ -178,3 +167,37 @@ exports.requireOwnedStore = (0, exports.validateStoreMiddleware)({
178
167
  exports.requireAnyStore = (0, exports.validateStoreMiddleware)({
179
168
  requireActive: false,
180
169
  });
170
+ // Helper function to fetch store from store service
171
+ async function fetchStoreById(storeId) {
172
+ const baseUrl = process.env.STORE_SERVICE_URL || "http://localhost:3001";
173
+ const url = `${baseUrl}/internal/stores/${encodeURIComponent(storeId)}`;
174
+ let token;
175
+ try {
176
+ const cfg = (0, serviceAuth_1.getServiceAuthConfigFromEnv)();
177
+ token = (0, serviceAuth_1.createServiceAuthenticator)(cfg).generateServiceToken(process.env.SERVICE_NAME || "shared-middleware", ["store:read"]);
178
+ }
179
+ catch {
180
+ // Development fallback tokens accepted by store service
181
+ const isDev = process.env.NODE_ENV !== "production";
182
+ if (isDev)
183
+ token = "dev-access";
184
+ }
185
+ const headers = {
186
+ "Content-Type": "application/json",
187
+ };
188
+ if (token)
189
+ headers["x-service-token"] = token;
190
+ try {
191
+ const res = await fetch(url, { method: "GET", headers });
192
+ if (res.ok) {
193
+ const data = (await res.json());
194
+ const store = data?.store || data?.data?.store || null;
195
+ if (store)
196
+ return store;
197
+ }
198
+ }
199
+ catch (error) {
200
+ console.error('Failed to fetch store from store service:', error);
201
+ }
202
+ return null;
203
+ }
@@ -583,7 +583,7 @@ export declare const reviewQueues: import("drizzle-orm/pg-core").PgTableWithColu
583
583
  tableName: "review_queues";
584
584
  dataType: "string";
585
585
  columnType: "PgVarchar";
586
- data: "PENDING" | "IN_PROGRESS" | "ASSIGNED" | "COMPLETED" | "ESCALATED" | "CANCELLED";
586
+ data: "PENDING" | "ASSIGNED" | "IN_PROGRESS" | "COMPLETED" | "ESCALATED" | "CANCELLED";
587
587
  driverParam: string;
588
588
  notNull: true;
589
589
  hasDefault: true;
@@ -596,7 +596,7 @@ export declare const reviewQueues: import("drizzle-orm/pg-core").PgTableWithColu
596
596
  generated: undefined;
597
597
  }, {}, {
598
598
  length: 20;
599
- $type: "PENDING" | "IN_PROGRESS" | "ASSIGNED" | "COMPLETED" | "ESCALATED" | "CANCELLED";
599
+ $type: "PENDING" | "ASSIGNED" | "IN_PROGRESS" | "COMPLETED" | "ESCALATED" | "CANCELLED";
600
600
  }>;
601
601
  assignedTo: import("drizzle-orm/pg-core").PgColumn<{
602
602
  name: "assigned_to";
@@ -339,7 +339,7 @@ export declare const contentScans: import("drizzle-orm/pg-core").PgTableWithColu
339
339
  tableName: "content_scans";
340
340
  dataType: "string";
341
341
  columnType: "PgVarchar";
342
- data: "PENDING" | "COMPLETED" | "CANCELLED" | "PROCESSING" | "FAILED";
342
+ data: "PENDING" | "FAILED" | "COMPLETED" | "CANCELLED" | "PROCESSING";
343
343
  driverParam: string;
344
344
  notNull: true;
345
345
  hasDefault: true;
@@ -352,7 +352,7 @@ export declare const contentScans: import("drizzle-orm/pg-core").PgTableWithColu
352
352
  generated: undefined;
353
353
  }, {}, {
354
354
  length: 20;
355
- $type: "PENDING" | "COMPLETED" | "CANCELLED" | "PROCESSING" | "FAILED";
355
+ $type: "PENDING" | "FAILED" | "COMPLETED" | "CANCELLED" | "PROCESSING";
356
356
  }>;
357
357
  actionTaken: import("drizzle-orm/pg-core").PgColumn<{
358
358
  name: "action_taken";
@@ -1,29 +1 @@
1
- export { type AxovaKafkaConfig, createKafkaInstance, getKafkaConfigFromEnv, getKafkaInstance, } from "../events/kafka";
2
- export { CustomerServiceConfig, CustomerServiceEvents, } from "../interfaces/customer-events";
3
- export { ServiceConfig, ServiceEvents } from "../interfaces/inventory-events";
4
- export type { ABCClassification, AIRecommendation, AutomationRule, AutomationRuleFilter, BatchFilter, BatchInfo, CountItemRequest, CreateAutomationRuleRequest, CreateBatchRequest, CreateCycleCountRequest, CreateInventoryItemRequest, CreatePOSLocationRequest, CreateWarehouseRequest, CycleCount, CycleCountFilter, CycleCountItem, DashboardMetrics, ExpiryReport, ForecastData, InventoryFilter, InventoryInsight, InventoryItem, InventoryOverview, InventorySnapshot, LowStockAlert, OperationResult, PaginatedResult, POSLocation, QuantityUpdate, ReorderRecommendation, StockMovementReport, StockValuation, TenantContext, TransferFilter, TransferItem, TransferRequest, UpdateInventoryItemRequest, UserContext, VelocityAnalysis, Warehouse, } from "../interfaces/inventory-types";
5
- export * from "../types/events";
6
- export * from "./admin/admin-schema";
7
- export * from "./ai-moderation/ai-moderation-schema";
8
- export * from "./common/common-schemas";
9
- export * from "./compliance/compliance-schema";
10
- export * from "./compliance/kyc-schema";
11
- export { storeKyc, kycVerificationHistory, kycDocuments, kycAnalytics, kycWebhooksLog, } from "./compliance/kyc-schema";
12
- export * from "./customer/customer-schema";
13
- export { customerAddresses, customerInteractionHistory, customerNotes, customerPreferences, customerReviews, customerSupportTickets, customers, customerVisitHistory, } from "./customer/customer-schema";
14
- export * from "./inventory/inventory-tables";
15
- export { inventory, inventoryMovements, inventoryTransferItems, inventoryTransfers, posLocations, productSuppliers, purchaseOrderItems, purchaseOrders, qualityControls, qualityTemplates, supplierQualityRatings, suppliers, warehouses, } from "./inventory/inventory-tables";
16
- export { alertSeverityEnum, alertStatusEnum, alertTypeEnum, inventoryLotAlerts, inventoryLotMerges, inventoryLotMovements, inventoryLots, inventoryLotSplits, lotMovementTypeEnum, lotStatusEnum, LotSchema, InitializeProductInventorySchema, CreateLotSchema, ReserveLotQuantitySchema, ReleaseLotReservationSchema, AdjustLotQuantitySchema, TransferLotSchema, MergeLotsSchema, SplitLotSchema, GetLotsQuerySchema, GetAvailableLotsSchema, LotAnalyticsSchema, } from "./inventory/lot-tables";
17
- export { addressTypeEnum, discountTypeEnum, fulfillmentStatusEnum, orderAddresses, orderAddressesRelations, orderDiscounts, orderDiscountsRelations, orderFulfillments, orderFulfillmentsRelations, orderHistory, orderHistoryRelations, orderItems, orderItemsRelations, orderNotes, orderNotesRelations, orderPayments, orderPaymentsRelations, orderPriorityEnum, orderStatusEnum, orders, ordersRelations, orderTypeEnum, paymentMethodEnum, paymentStatusEnum, refundReasonEnum, } from "./order/order-schema";
18
- export * from "./product/product-relations";
19
- export * from "./product/product-schema";
20
- export * from "./product/product-relations";
21
- export * from "./product/discount-schema";
22
- export * from "./product/discount-relations";
23
- export * from "./store/store-schema";
24
- export * from "./store/store-settings-schema";
25
- export * from "./store/store-audit-schema";
26
- export * from "./store/storefront-config-schema";
27
- export { storeSettings, marketRegions, storeSettingsRelations, marketRegionsRelations, } from "./store/store-settings-schema";
28
- export { storefrontConfigs, storefrontConfigRelations, } from "./store/storefront-config-schema";
29
1
  export * from "./types";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
- // Export the ACTUAL Drizzle table objects for database operations
2
+ // Schemas have been moved to individual services
3
+ // Each service now maintains its own schemas in their src/[service-name]-schema folder
3
4
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
5
  if (k2 === undefined) k2 = k;
5
6
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -15,128 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
17
  };
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.GetAvailableLotsSchema = exports.GetLotsQuerySchema = exports.SplitLotSchema = exports.MergeLotsSchema = exports.TransferLotSchema = exports.AdjustLotQuantitySchema = exports.ReleaseLotReservationSchema = exports.ReserveLotQuantitySchema = exports.CreateLotSchema = exports.InitializeProductInventorySchema = exports.LotSchema = exports.lotStatusEnum = exports.lotMovementTypeEnum = exports.inventoryLotSplits = exports.inventoryLots = exports.inventoryLotMovements = exports.inventoryLotMerges = exports.inventoryLotAlerts = exports.alertTypeEnum = exports.alertStatusEnum = exports.alertSeverityEnum = exports.warehouses = exports.suppliers = exports.supplierQualityRatings = exports.qualityTemplates = exports.qualityControls = exports.purchaseOrders = exports.purchaseOrderItems = exports.productSuppliers = exports.posLocations = exports.inventoryTransfers = exports.inventoryTransferItems = exports.inventoryMovements = exports.inventory = exports.customerVisitHistory = exports.customers = exports.customerSupportTickets = exports.customerReviews = exports.customerPreferences = exports.customerNotes = exports.customerInteractionHistory = exports.customerAddresses = exports.kycWebhooksLog = exports.kycAnalytics = exports.kycDocuments = exports.kycVerificationHistory = exports.storeKyc = exports.getKafkaInstance = exports.getKafkaConfigFromEnv = exports.createKafkaInstance = void 0;
19
- exports.storefrontConfigRelations = exports.storefrontConfigs = exports.marketRegionsRelations = exports.storeSettingsRelations = exports.marketRegions = exports.storeSettings = exports.refundReasonEnum = exports.paymentStatusEnum = exports.paymentMethodEnum = exports.orderTypeEnum = exports.ordersRelations = exports.orders = exports.orderStatusEnum = exports.orderPriorityEnum = exports.orderPaymentsRelations = exports.orderPayments = exports.orderNotesRelations = exports.orderNotes = exports.orderItemsRelations = exports.orderItems = exports.orderHistoryRelations = exports.orderHistory = exports.orderFulfillmentsRelations = exports.orderFulfillments = exports.orderDiscountsRelations = exports.orderDiscounts = exports.orderAddressesRelations = exports.orderAddresses = exports.fulfillmentStatusEnum = exports.discountTypeEnum = exports.addressTypeEnum = exports.LotAnalyticsSchema = void 0;
20
- // Export event and Kafka functionality
21
- var kafka_1 = require("../events/kafka");
22
- Object.defineProperty(exports, "createKafkaInstance", { enumerable: true, get: function () { return kafka_1.createKafkaInstance; } });
23
- Object.defineProperty(exports, "getKafkaConfigFromEnv", { enumerable: true, get: function () { return kafka_1.getKafkaConfigFromEnv; } });
24
- Object.defineProperty(exports, "getKafkaInstance", { enumerable: true, get: function () { return kafka_1.getKafkaInstance; } });
25
- __exportStar(require("../types/events"), exports);
26
- // Admin Management
27
- __exportStar(require("./admin/admin-schema"), exports);
28
- // AI Moderation
29
- __exportStar(require("./ai-moderation/ai-moderation-schema"), exports);
30
- // Common Schemas
31
- __exportStar(require("./common/common-schemas"), exports);
32
- // Compliance Schemas
33
- __exportStar(require("./compliance/compliance-schema"), exports);
34
- __exportStar(require("./compliance/kyc-schema"), exports);
35
- var kyc_schema_1 = require("./compliance/kyc-schema");
36
- Object.defineProperty(exports, "storeKyc", { enumerable: true, get: function () { return kyc_schema_1.storeKyc; } });
37
- Object.defineProperty(exports, "kycVerificationHistory", { enumerable: true, get: function () { return kyc_schema_1.kycVerificationHistory; } });
38
- Object.defineProperty(exports, "kycDocuments", { enumerable: true, get: function () { return kyc_schema_1.kycDocuments; } });
39
- Object.defineProperty(exports, "kycAnalytics", { enumerable: true, get: function () { return kyc_schema_1.kycAnalytics; } });
40
- Object.defineProperty(exports, "kycWebhooksLog", { enumerable: true, get: function () { return kyc_schema_1.kycWebhooksLog; } });
41
- // Customer Management Schemas
42
- __exportStar(require("./customer/customer-schema"), exports);
43
- // Customer Schema Exports
44
- var customer_schema_1 = require("./customer/customer-schema");
45
- Object.defineProperty(exports, "customerAddresses", { enumerable: true, get: function () { return customer_schema_1.customerAddresses; } });
46
- Object.defineProperty(exports, "customerInteractionHistory", { enumerable: true, get: function () { return customer_schema_1.customerInteractionHistory; } });
47
- Object.defineProperty(exports, "customerNotes", { enumerable: true, get: function () { return customer_schema_1.customerNotes; } });
48
- Object.defineProperty(exports, "customerPreferences", { enumerable: true, get: function () { return customer_schema_1.customerPreferences; } });
49
- Object.defineProperty(exports, "customerReviews", { enumerable: true, get: function () { return customer_schema_1.customerReviews; } });
50
- Object.defineProperty(exports, "customerSupportTickets", { enumerable: true, get: function () { return customer_schema_1.customerSupportTickets; } });
51
- Object.defineProperty(exports, "customers", { enumerable: true, get: function () { return customer_schema_1.customers; } });
52
- Object.defineProperty(exports, "customerVisitHistory", { enumerable: true, get: function () { return customer_schema_1.customerVisitHistory; } });
53
- // Core Inventory tables and co-located schemas
54
- __exportStar(require("./inventory/inventory-tables"), exports);
55
- var inventory_tables_1 = require("./inventory/inventory-tables");
56
- Object.defineProperty(exports, "inventory", { enumerable: true, get: function () { return inventory_tables_1.inventory; } });
57
- Object.defineProperty(exports, "inventoryMovements", { enumerable: true, get: function () { return inventory_tables_1.inventoryMovements; } });
58
- Object.defineProperty(exports, "inventoryTransferItems", { enumerable: true, get: function () { return inventory_tables_1.inventoryTransferItems; } });
59
- Object.defineProperty(exports, "inventoryTransfers", { enumerable: true, get: function () { return inventory_tables_1.inventoryTransfers; } });
60
- Object.defineProperty(exports, "posLocations", { enumerable: true, get: function () { return inventory_tables_1.posLocations; } });
61
- Object.defineProperty(exports, "productSuppliers", { enumerable: true, get: function () { return inventory_tables_1.productSuppliers; } });
62
- Object.defineProperty(exports, "purchaseOrderItems", { enumerable: true, get: function () { return inventory_tables_1.purchaseOrderItems; } });
63
- Object.defineProperty(exports, "purchaseOrders", { enumerable: true, get: function () { return inventory_tables_1.purchaseOrders; } });
64
- Object.defineProperty(exports, "qualityControls", { enumerable: true, get: function () { return inventory_tables_1.qualityControls; } });
65
- Object.defineProperty(exports, "qualityTemplates", { enumerable: true, get: function () { return inventory_tables_1.qualityTemplates; } });
66
- Object.defineProperty(exports, "supplierQualityRatings", { enumerable: true, get: function () { return inventory_tables_1.supplierQualityRatings; } });
67
- Object.defineProperty(exports, "suppliers", { enumerable: true, get: function () { return inventory_tables_1.suppliers; } });
68
- Object.defineProperty(exports, "warehouses", { enumerable: true, get: function () { return inventory_tables_1.warehouses; } });
69
- // Lot & Batch Management schemas
70
- var lot_tables_1 = require("./inventory/lot-tables");
71
- Object.defineProperty(exports, "alertSeverityEnum", { enumerable: true, get: function () { return lot_tables_1.alertSeverityEnum; } });
72
- Object.defineProperty(exports, "alertStatusEnum", { enumerable: true, get: function () { return lot_tables_1.alertStatusEnum; } });
73
- Object.defineProperty(exports, "alertTypeEnum", { enumerable: true, get: function () { return lot_tables_1.alertTypeEnum; } });
74
- Object.defineProperty(exports, "inventoryLotAlerts", { enumerable: true, get: function () { return lot_tables_1.inventoryLotAlerts; } });
75
- Object.defineProperty(exports, "inventoryLotMerges", { enumerable: true, get: function () { return lot_tables_1.inventoryLotMerges; } });
76
- Object.defineProperty(exports, "inventoryLotMovements", { enumerable: true, get: function () { return lot_tables_1.inventoryLotMovements; } });
77
- Object.defineProperty(exports, "inventoryLots", { enumerable: true, get: function () { return lot_tables_1.inventoryLots; } });
78
- Object.defineProperty(exports, "inventoryLotSplits", { enumerable: true, get: function () { return lot_tables_1.inventoryLotSplits; } });
79
- Object.defineProperty(exports, "lotMovementTypeEnum", { enumerable: true, get: function () { return lot_tables_1.lotMovementTypeEnum; } });
80
- Object.defineProperty(exports, "lotStatusEnum", { enumerable: true, get: function () { return lot_tables_1.lotStatusEnum; } });
81
- // Zod Schemas for Lot Operations
82
- Object.defineProperty(exports, "LotSchema", { enumerable: true, get: function () { return lot_tables_1.LotSchema; } });
83
- Object.defineProperty(exports, "InitializeProductInventorySchema", { enumerable: true, get: function () { return lot_tables_1.InitializeProductInventorySchema; } });
84
- Object.defineProperty(exports, "CreateLotSchema", { enumerable: true, get: function () { return lot_tables_1.CreateLotSchema; } });
85
- Object.defineProperty(exports, "ReserveLotQuantitySchema", { enumerable: true, get: function () { return lot_tables_1.ReserveLotQuantitySchema; } });
86
- Object.defineProperty(exports, "ReleaseLotReservationSchema", { enumerable: true, get: function () { return lot_tables_1.ReleaseLotReservationSchema; } });
87
- Object.defineProperty(exports, "AdjustLotQuantitySchema", { enumerable: true, get: function () { return lot_tables_1.AdjustLotQuantitySchema; } });
88
- Object.defineProperty(exports, "TransferLotSchema", { enumerable: true, get: function () { return lot_tables_1.TransferLotSchema; } });
89
- Object.defineProperty(exports, "MergeLotsSchema", { enumerable: true, get: function () { return lot_tables_1.MergeLotsSchema; } });
90
- Object.defineProperty(exports, "SplitLotSchema", { enumerable: true, get: function () { return lot_tables_1.SplitLotSchema; } });
91
- Object.defineProperty(exports, "GetLotsQuerySchema", { enumerable: true, get: function () { return lot_tables_1.GetLotsQuerySchema; } });
92
- Object.defineProperty(exports, "GetAvailableLotsSchema", { enumerable: true, get: function () { return lot_tables_1.GetAvailableLotsSchema; } });
93
- Object.defineProperty(exports, "LotAnalyticsSchema", { enumerable: true, get: function () { return lot_tables_1.LotAnalyticsSchema; } });
94
- // Order schemas
95
- var order_schema_1 = require("./order/order-schema");
96
- Object.defineProperty(exports, "addressTypeEnum", { enumerable: true, get: function () { return order_schema_1.addressTypeEnum; } });
97
- Object.defineProperty(exports, "discountTypeEnum", { enumerable: true, get: function () { return order_schema_1.discountTypeEnum; } });
98
- Object.defineProperty(exports, "fulfillmentStatusEnum", { enumerable: true, get: function () { return order_schema_1.fulfillmentStatusEnum; } });
99
- Object.defineProperty(exports, "orderAddresses", { enumerable: true, get: function () { return order_schema_1.orderAddresses; } });
100
- Object.defineProperty(exports, "orderAddressesRelations", { enumerable: true, get: function () { return order_schema_1.orderAddressesRelations; } });
101
- Object.defineProperty(exports, "orderDiscounts", { enumerable: true, get: function () { return order_schema_1.orderDiscounts; } });
102
- Object.defineProperty(exports, "orderDiscountsRelations", { enumerable: true, get: function () { return order_schema_1.orderDiscountsRelations; } });
103
- Object.defineProperty(exports, "orderFulfillments", { enumerable: true, get: function () { return order_schema_1.orderFulfillments; } });
104
- Object.defineProperty(exports, "orderFulfillmentsRelations", { enumerable: true, get: function () { return order_schema_1.orderFulfillmentsRelations; } });
105
- Object.defineProperty(exports, "orderHistory", { enumerable: true, get: function () { return order_schema_1.orderHistory; } });
106
- Object.defineProperty(exports, "orderHistoryRelations", { enumerable: true, get: function () { return order_schema_1.orderHistoryRelations; } });
107
- Object.defineProperty(exports, "orderItems", { enumerable: true, get: function () { return order_schema_1.orderItems; } });
108
- Object.defineProperty(exports, "orderItemsRelations", { enumerable: true, get: function () { return order_schema_1.orderItemsRelations; } });
109
- Object.defineProperty(exports, "orderNotes", { enumerable: true, get: function () { return order_schema_1.orderNotes; } });
110
- Object.defineProperty(exports, "orderNotesRelations", { enumerable: true, get: function () { return order_schema_1.orderNotesRelations; } });
111
- Object.defineProperty(exports, "orderPayments", { enumerable: true, get: function () { return order_schema_1.orderPayments; } });
112
- Object.defineProperty(exports, "orderPaymentsRelations", { enumerable: true, get: function () { return order_schema_1.orderPaymentsRelations; } });
113
- Object.defineProperty(exports, "orderPriorityEnum", { enumerable: true, get: function () { return order_schema_1.orderPriorityEnum; } });
114
- Object.defineProperty(exports, "orderStatusEnum", { enumerable: true, get: function () { return order_schema_1.orderStatusEnum; } });
115
- Object.defineProperty(exports, "orders", { enumerable: true, get: function () { return order_schema_1.orders; } });
116
- Object.defineProperty(exports, "ordersRelations", { enumerable: true, get: function () { return order_schema_1.ordersRelations; } });
117
- // Enums
118
- Object.defineProperty(exports, "orderTypeEnum", { enumerable: true, get: function () { return order_schema_1.orderTypeEnum; } });
119
- Object.defineProperty(exports, "paymentMethodEnum", { enumerable: true, get: function () { return order_schema_1.paymentMethodEnum; } });
120
- Object.defineProperty(exports, "paymentStatusEnum", { enumerable: true, get: function () { return order_schema_1.paymentStatusEnum; } });
121
- Object.defineProperty(exports, "refundReasonEnum", { enumerable: true, get: function () { return order_schema_1.refundReasonEnum; } });
122
- __exportStar(require("./product/product-relations"), exports);
123
- // Product Management Schemas
124
- __exportStar(require("./product/product-schema"), exports);
125
- __exportStar(require("./product/product-relations"), exports);
126
- __exportStar(require("./product/discount-schema"), exports);
127
- __exportStar(require("./product/discount-relations"), exports);
128
- // Store Management
129
- __exportStar(require("./store/store-schema"), exports);
130
- __exportStar(require("./store/store-settings-schema"), exports);
131
- __exportStar(require("./store/store-audit-schema"), exports);
132
- __exportStar(require("./store/storefront-config-schema"), exports);
133
- var store_settings_schema_1 = require("./store/store-settings-schema");
134
- Object.defineProperty(exports, "storeSettings", { enumerable: true, get: function () { return store_settings_schema_1.storeSettings; } });
135
- Object.defineProperty(exports, "marketRegions", { enumerable: true, get: function () { return store_settings_schema_1.marketRegions; } });
136
- Object.defineProperty(exports, "storeSettingsRelations", { enumerable: true, get: function () { return store_settings_schema_1.storeSettingsRelations; } });
137
- Object.defineProperty(exports, "marketRegionsRelations", { enumerable: true, get: function () { return store_settings_schema_1.marketRegionsRelations; } });
138
- var storefront_config_schema_1 = require("./store/storefront-config-schema");
139
- Object.defineProperty(exports, "storefrontConfigs", { enumerable: true, get: function () { return storefront_config_schema_1.storefrontConfigs; } });
140
- Object.defineProperty(exports, "storefrontConfigRelations", { enumerable: true, get: function () { return storefront_config_schema_1.storefrontConfigRelations; } });
141
- // Types
19
+ // Common types used across services
142
20
  __exportStar(require("./types"), exports);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Checks if a subdomain is available.
2
+ * Checks if a subdomain is available by calling the store service API.
3
3
  * @param subdomain The subdomain to check.
4
4
  * @returns {Promise<boolean>} True if available, false if taken.
5
5
  */
@@ -1,20 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isSubdomainAvailable = void 0;
4
- const drizzle_orm_1 = require("drizzle-orm");
5
- const db_1 = require("../lib/db");
6
- const store_schema_1 = require("../schemas/store/store-schema");
7
4
  /**
8
- * Checks if a subdomain is available.
5
+ * Checks if a subdomain is available by calling the store service API.
9
6
  * @param subdomain The subdomain to check.
10
7
  * @returns {Promise<boolean>} True if available, false if taken.
11
8
  */
12
9
  const isSubdomainAvailable = async (subdomain) => {
13
- const existingStore = await db_1.db
14
- .select()
15
- .from(store_schema_1.stores)
16
- .where((0, drizzle_orm_1.eq)(store_schema_1.stores.subdomain, subdomain))
17
- .limit(1);
18
- return existingStore.length === 0;
10
+ const baseUrl = process.env.STORE_SERVICE_URL || "http://localhost:3001";
11
+ const url = `${baseUrl}/api/stores/subdomain/${encodeURIComponent(subdomain)}/check`;
12
+ try {
13
+ const res = await fetch(url, { method: "GET" });
14
+ if (res.ok) {
15
+ const data = (await res.json());
16
+ return data.available;
17
+ }
18
+ }
19
+ catch (error) {
20
+ console.error('Failed to check subdomain availability:', error);
21
+ }
22
+ // Default to unavailable on error to be safe
23
+ return false;
19
24
  };
20
25
  exports.isSubdomainAvailable = isSubdomainAvailable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axova/shared",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Shared utilities, models, and libraries for Axova platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -15,9 +15,6 @@ export * from "./middleware/storeOwnership";
15
15
  export * from "./middleware/storeValidationMiddleware";
16
16
  export * from "./middleware/userAuth";
17
17
 
18
- // Schemas - Organized by Service
19
- export * from "./schemas";
20
-
21
18
  // Types and Interfaces
22
19
  export * from "./types/events";
23
20
 
@@ -1,7 +1,4 @@
1
- import { eq } from "drizzle-orm";
2
1
  import type { FastifyReply, FastifyRequest } from "fastify";
3
- import { db } from "../lib/db";
4
- import { stores } from "../schemas/store/store-schema";
5
2
  import {
6
3
  createServiceAuthenticator,
7
4
  getServiceAuthConfigFromEnv,
@@ -158,25 +155,10 @@ async function fetchStoreById(storeId: string): Promise<{
158
155
  const store = data?.store || data?.data?.store || null;
159
156
  if (store) return store;
160
157
  }
161
- } catch {
162
- // ignore network error and try DB fallback when possible
163
- }
164
- // DB fallback (primarily for in-process store-service)
165
- try {
166
- const result = await db
167
- .select({
168
- id: stores.id,
169
- storeName: stores.storeName,
170
- isActive: stores.isActive,
171
- userId: stores.userId,
172
- })
173
- .from(stores)
174
- .where(eq(stores.id, storeId))
175
- .limit(1);
176
- return result[0] || null;
177
- } catch {
178
- return null;
158
+ } catch (error) {
159
+ console.error('Failed to fetch store from store service:', error);
179
160
  }
161
+ return null;
180
162
  }
181
163
 
182
164
  async function attachStoreInfoIfPossible(
@@ -1,7 +1,8 @@
1
- import { eq } from "drizzle-orm";
2
1
  import { FastifyReply, FastifyRequest } from "fastify";
3
- import { db } from "../lib/db";
4
- import { stores } from "../schemas/store/store-schema";
2
+ import {
3
+ createServiceAuthenticator,
4
+ getServiceAuthConfigFromEnv,
5
+ } from "./serviceAuth";
5
6
 
6
7
  // Store cache to reduce database calls
7
8
  const storeCache = new Map<
@@ -143,19 +144,10 @@ export const validateStoreMiddleware = (
143
144
  }
144
145
  }
145
146
 
146
- // Validate store exists and get details from database
147
- const store = await db
148
- .select({
149
- id: stores.id,
150
- storeName: stores.storeName,
151
- isActive: stores.isActive,
152
- userId: stores.userId,
153
- })
154
- .from(stores)
155
- .where(eq(stores.id, storeId))
156
- .limit(1);
157
-
158
- if (store.length === 0) {
147
+ // Validate store exists and get details from store service API
148
+ const fetchedStore = await fetchStoreById(storeId);
149
+
150
+ if (!fetchedStore) {
159
151
  // Cache negative result
160
152
  storeCache.set(storeId, { isValid: false, timestamp: Date.now() });
161
153
 
@@ -166,7 +158,7 @@ export const validateStoreMiddleware = (
166
158
  });
167
159
  }
168
160
 
169
- const storeData = store[0];
161
+ const storeData = fetchedStore;
170
162
 
171
163
  // Check if store is active when required
172
164
  if (requireActive && !storeData.isActive) {
@@ -245,3 +237,44 @@ export const requireOwnedStore = validateStoreMiddleware({
245
237
  export const requireAnyStore = validateStoreMiddleware({
246
238
  requireActive: false,
247
239
  });
240
+
241
+ // Helper function to fetch store from store service
242
+ async function fetchStoreById(storeId: string): Promise<{
243
+ id: string;
244
+ storeName: string;
245
+ isActive: boolean;
246
+ userId: string;
247
+ } | null> {
248
+ const baseUrl = process.env.STORE_SERVICE_URL || "http://localhost:3001";
249
+ const url = `${baseUrl}/internal/stores/${encodeURIComponent(storeId)}`;
250
+
251
+ let token: string | undefined;
252
+ try {
253
+ const cfg = getServiceAuthConfigFromEnv();
254
+ token = createServiceAuthenticator(cfg).generateServiceToken(
255
+ process.env.SERVICE_NAME || "shared-middleware",
256
+ ["store:read"],
257
+ );
258
+ } catch {
259
+ // Development fallback tokens accepted by store service
260
+ const isDev = process.env.NODE_ENV !== "production";
261
+ if (isDev) token = "dev-access";
262
+ }
263
+
264
+ const headers: Record<string, string> = {
265
+ "Content-Type": "application/json",
266
+ };
267
+ if (token) headers["x-service-token"] = token;
268
+
269
+ try {
270
+ const res = await fetch(url, { method: "GET", headers });
271
+ if (res.ok) {
272
+ const data = (await res.json()) as any;
273
+ const store = data?.store || data?.data?.store || null;
274
+ if (store) return store;
275
+ }
276
+ } catch (error) {
277
+ console.error('Failed to fetch store from store service:', error);
278
+ }
279
+ return null;
280
+ }