@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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/lib/db.d.ts +34406 -1
- package/dist/lib/db.js +21 -1
- package/dist/middleware/storeOwnership.js +22 -3
- package/dist/middleware/storeValidationMiddleware.js +16 -39
- package/dist/schemas/admin/admin-schema.d.ts +2 -2
- package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +6 -6
- package/dist/schemas/common/common-schemas.d.ts +71 -71
- package/dist/schemas/compliance/compliance-schema.d.ts +20 -20
- package/dist/schemas/compliance/kyc-schema.d.ts +8 -8
- package/dist/schemas/customer/customer-schema.d.ts +18 -18
- package/dist/schemas/index.d.ts +28 -0
- package/dist/schemas/index.js +134 -3
- package/dist/schemas/inventory/inventory-tables.d.ts +188 -188
- package/dist/schemas/inventory/lot-tables.d.ts +102 -102
- package/dist/schemas/order/cart-schema.d.ts +2865 -0
- package/dist/schemas/order/cart-schema.js +396 -0
- package/dist/schemas/order/order-schema.d.ts +19 -19
- package/dist/schemas/order/order-schema.js +8 -2
- package/dist/schemas/product/discount-schema.d.ts +3 -3
- package/dist/schemas/product/product-schema.d.ts +3 -3
- package/dist/schemas/store/store-audit-schema.d.ts +20 -20
- package/dist/schemas/store/store-schema.d.ts +182 -2
- package/dist/schemas/store/store-schema.js +19 -0
- package/dist/schemas/store/storefront-config-schema.d.ts +434 -823
- package/dist/schemas/store/storefront-config-schema.js +35 -62
- package/dist/utils/subdomain.d.ts +1 -1
- package/dist/utils/subdomain.js +10 -15
- package/package.json +1 -1
- package/src/configs/index.ts +654 -654
- package/src/index.ts +26 -23
- package/src/interfaces/customer-events.ts +106 -106
- package/src/interfaces/inventory-events.ts +545 -545
- package/src/interfaces/inventory-types.ts +1004 -1004
- package/src/interfaces/order-events.ts +381 -381
- package/src/lib/auditLogger.ts +1117 -1117
- package/src/lib/authOrganization.ts +153 -153
- package/src/lib/db.ts +84 -64
- package/src/middleware/serviceAuth.ts +328 -328
- package/src/middleware/storeOwnership.ts +199 -181
- package/src/middleware/storeValidationMiddleware.ts +17 -50
- package/src/middleware/userAuth.ts +248 -248
- package/src/schemas/admin/admin-schema.ts +208 -208
- package/src/schemas/ai-moderation/ai-moderation-schema.ts +180 -180
- package/src/schemas/common/common-schemas.ts +108 -108
- 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 +202 -3
- package/src/schemas/inventory/inventory-tables.ts +1927 -0
- package/src/schemas/inventory/lot-tables.ts +799 -0
- package/src/schemas/order/cart-schema.ts +652 -0
- package/src/schemas/order/order-schema.ts +1406 -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 +682 -0
- package/src/schemas/store/store-settings-schema.ts +231 -0
- package/src/schemas/store/storefront-config-schema.ts +382 -0
- package/src/schemas/types.ts +67 -67
- package/src/types/events.ts +646 -646
- package/src/utils/errorHandler.ts +44 -44
- package/src/utils/subdomain.ts +19 -23
- package/tsconfig.json +21 -21
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import type { FastifyReply } from "fastify";
|
|
2
|
-
|
|
3
|
-
export class APIError extends Error {
|
|
4
|
-
statusCode: number;
|
|
5
|
-
details?: unknown;
|
|
6
|
-
|
|
7
|
-
constructor(message: string, statusCode = 400, details?: unknown) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.statusCode = statusCode;
|
|
10
|
-
this.details = details;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Handles API errors in a unified way.
|
|
16
|
-
* @param {FastifyReply} reply The Fastify reply object.
|
|
17
|
-
* @param {APIError} error The API error object.
|
|
18
|
-
*/
|
|
19
|
-
export const handleAPIError = (
|
|
20
|
-
reply: FastifyReply,
|
|
21
|
-
error: APIError | Error,
|
|
22
|
-
) => {
|
|
23
|
-
// Default status code
|
|
24
|
-
let statusCode = 500;
|
|
25
|
-
let details: unknown;
|
|
26
|
-
|
|
27
|
-
// If it's an APIError, use its status code and details
|
|
28
|
-
if (error instanceof APIError) {
|
|
29
|
-
statusCode = error.statusCode || 500;
|
|
30
|
-
details = error.details;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Ensure there's always a message
|
|
34
|
-
const message = error.message || "An unexpected error occurred";
|
|
35
|
-
|
|
36
|
-
reply.status(statusCode).send({
|
|
37
|
-
success: false,
|
|
38
|
-
message,
|
|
39
|
-
...(details ? { details } : {}),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Log the error for debugging
|
|
43
|
-
console.error(`[API Error] ${statusCode}: ${message}`, details || "");
|
|
44
|
-
};
|
|
1
|
+
import type { FastifyReply } from "fastify";
|
|
2
|
+
|
|
3
|
+
export class APIError extends Error {
|
|
4
|
+
statusCode: number;
|
|
5
|
+
details?: unknown;
|
|
6
|
+
|
|
7
|
+
constructor(message: string, statusCode = 400, details?: unknown) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
this.details = details;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handles API errors in a unified way.
|
|
16
|
+
* @param {FastifyReply} reply The Fastify reply object.
|
|
17
|
+
* @param {APIError} error The API error object.
|
|
18
|
+
*/
|
|
19
|
+
export const handleAPIError = (
|
|
20
|
+
reply: FastifyReply,
|
|
21
|
+
error: APIError | Error,
|
|
22
|
+
) => {
|
|
23
|
+
// Default status code
|
|
24
|
+
let statusCode = 500;
|
|
25
|
+
let details: unknown;
|
|
26
|
+
|
|
27
|
+
// If it's an APIError, use its status code and details
|
|
28
|
+
if (error instanceof APIError) {
|
|
29
|
+
statusCode = error.statusCode || 500;
|
|
30
|
+
details = error.details;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Ensure there's always a message
|
|
34
|
+
const message = error.message || "An unexpected error occurred";
|
|
35
|
+
|
|
36
|
+
reply.status(statusCode).send({
|
|
37
|
+
success: false,
|
|
38
|
+
message,
|
|
39
|
+
...(details ? { details } : {}),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Log the error for debugging
|
|
43
|
+
console.error(`[API Error] ${statusCode}: ${message}`, details || "");
|
|
44
|
+
};
|
package/src/utils/subdomain.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
// Default to unavailable on error to be safe
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { db } from "../lib/db";
|
|
3
|
+
import { stores } from "../schemas/store/store-schema";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a subdomain is available.
|
|
7
|
+
* @param subdomain The subdomain to check.
|
|
8
|
+
* @returns {Promise<boolean>} True if available, false if taken.
|
|
9
|
+
*/
|
|
10
|
+
export const isSubdomainAvailable = async (
|
|
11
|
+
subdomain: string,
|
|
12
|
+
): Promise<boolean> => {
|
|
13
|
+
const existingStore = await db
|
|
14
|
+
.select()
|
|
15
|
+
.from(stores)
|
|
16
|
+
.where(eq(stores.subdomain, subdomain))
|
|
17
|
+
.limit(1);
|
|
18
|
+
return existingStore.length === 0;
|
|
19
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"allowSyntheticDefaultImports": true,
|
|
15
|
-
"experimentalDecorators": true,
|
|
16
|
-
"emitDecoratorMetadata": true,
|
|
17
|
-
"resolveJsonModule": true
|
|
18
|
-
},
|
|
19
|
-
"include": ["src/**/*"],
|
|
20
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
21
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"allowSyntheticDefaultImports": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
"emitDecoratorMetadata": true,
|
|
17
|
+
"resolveJsonModule": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
21
|
+
}
|