@porulle/plugin-marketplace 0.64.0 → 0.65.1
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/README.md +11 -59
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -11
- package/dist/routes/b2b.d.ts +1 -3
- package/dist/routes/b2b.d.ts.map +1 -1
- package/dist/routes/b2b.js +2 -70
- package/dist/routes/sub-orders.js +3 -3
- package/dist/routes/vendor-portal.js +6 -6
- package/dist/schema.d.ts +0 -194
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +0 -14
- package/dist/schemas/b2b.d.ts +0 -986
- package/dist/schemas/b2b.d.ts.map +1 -1
- package/dist/schemas/b2b.js +1 -184
- package/dist/schemas/commission.d.ts +0 -495
- package/dist/schemas/commission.d.ts.map +1 -1
- package/dist/schemas/commission.js +1 -78
- package/dist/schemas/disputes-returns-reviews.d.ts +0 -1354
- package/dist/schemas/disputes-returns-reviews.d.ts.map +1 -1
- package/dist/schemas/disputes-returns-reviews.js +1 -208
- package/dist/schemas/sub-orders.d.ts +0 -290
- package/dist/schemas/sub-orders.d.ts.map +1 -1
- package/dist/schemas/sub-orders.js +1 -59
- package/dist/schemas/vendor-portal.d.ts +0 -1755
- package/dist/schemas/vendor-portal.d.ts.map +1 -1
- package/dist/schemas/vendor-portal.js +1 -247
- package/dist/schemas/vendors.d.ts +0 -1321
- package/dist/schemas/vendors.d.ts.map +1 -1
- package/dist/schemas/vendors.js +1 -205
- package/dist/services/sub-order.d.ts +1 -31
- package/dist/services/sub-order.d.ts.map +1 -1
- package/dist/services/sub-order.js +14 -22
- package/dist/types.d.ts +0 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -4
- package/package.json +13 -11
- package/src/index.ts +3 -11
- package/src/routes/b2b.ts +1 -76
- package/src/routes/sub-orders.ts +3 -3
- package/src/routes/vendor-portal.ts +6 -6
- package/src/schema.ts +0 -16
- package/src/schemas/b2b.ts +1 -208
- package/src/schemas/commission.ts +1 -86
- package/src/schemas/disputes-returns-reviews.ts +1 -225
- package/src/schemas/sub-orders.ts +1 -65
- package/src/schemas/vendor-portal.ts +1 -269
- package/src/schemas/vendors.ts +1 -222
- package/src/services/sub-order.ts +16 -18
- package/src/types.ts +0 -28
- package/dist/schemas/payouts.d.ts +0 -375
- package/dist/schemas/payouts.d.ts.map +0 -1
- package/dist/schemas/payouts.js +0 -78
- package/dist/services/contract-price.d.ts +0 -64
- package/dist/services/contract-price.d.ts.map +0 -1
- package/dist/services/contract-price.js +0 -57
- package/src/schemas/payouts.ts +0 -90
- package/src/services/contract-price.ts +0 -80
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { eq, and, desc } from "@porulle/core/drizzle";
|
|
2
|
-
import { contractPrices } from "../schema.js";
|
|
3
|
-
export class ContractPriceService {
|
|
4
|
-
db;
|
|
5
|
-
constructor(db) {
|
|
6
|
-
this.db = db;
|
|
7
|
-
}
|
|
8
|
-
async create(data) {
|
|
9
|
-
const [price] = await this.db.insert(contractPrices).values(data).returning();
|
|
10
|
-
return price;
|
|
11
|
-
}
|
|
12
|
-
async update(id, data) {
|
|
13
|
-
const [updated] = await this.db.update(contractPrices).set(data)
|
|
14
|
-
.where(eq(contractPrices.id, id)).returning();
|
|
15
|
-
return updated ?? null;
|
|
16
|
-
}
|
|
17
|
-
async delete(id) {
|
|
18
|
-
await this.db.delete(contractPrices).where(eq(contractPrices.id, id));
|
|
19
|
-
}
|
|
20
|
-
async list(filters) {
|
|
21
|
-
let query = this.db.select().from(contractPrices).$dynamic();
|
|
22
|
-
const conditions = [];
|
|
23
|
-
if (filters?.vendorId)
|
|
24
|
-
conditions.push(eq(contractPrices.vendorId, filters.vendorId));
|
|
25
|
-
if (filters?.buyerId)
|
|
26
|
-
conditions.push(eq(contractPrices.buyerId, filters.buyerId));
|
|
27
|
-
if (conditions.length > 0) {
|
|
28
|
-
query = query.where(conditions.length === 1 ? conditions[0] : and(...conditions));
|
|
29
|
-
}
|
|
30
|
-
return query.orderBy(desc(contractPrices.createdAt));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Resolve the best contract price for a buyer+vendor+entity+quantity.
|
|
34
|
-
* Returns null if no matching contract exists.
|
|
35
|
-
*/
|
|
36
|
-
async resolvePrice(vendorId, buyerId, entityId, variantId, quantity) {
|
|
37
|
-
const now = new Date();
|
|
38
|
-
const all = await this.db.select().from(contractPrices)
|
|
39
|
-
.where(and(eq(contractPrices.vendorId, vendorId), eq(contractPrices.buyerId, buyerId), eq(contractPrices.entityId, entityId)))
|
|
40
|
-
.orderBy(desc(contractPrices.priceCents));
|
|
41
|
-
for (const cp of all) {
|
|
42
|
-
// Check variant match
|
|
43
|
-
if (variantId != null && cp.variantId != null && cp.variantId !== variantId)
|
|
44
|
-
continue;
|
|
45
|
-
// Check quantity
|
|
46
|
-
if (quantity < (cp.minQuantity ?? 1))
|
|
47
|
-
continue;
|
|
48
|
-
// Check time validity
|
|
49
|
-
if (cp.validFrom && cp.validFrom > now)
|
|
50
|
-
continue;
|
|
51
|
-
if (cp.validUntil && cp.validUntil < now)
|
|
52
|
-
continue;
|
|
53
|
-
return cp.priceCents;
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/schemas/payouts.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { z, createRoute } from "@hono/zod-openapi";
|
|
2
|
-
|
|
3
|
-
const ErrorSchema = z.object({
|
|
4
|
-
error: z.object({
|
|
5
|
-
code: z.string(),
|
|
6
|
-
message: z.string(),
|
|
7
|
-
}),
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const errorResponses = {
|
|
11
|
-
401: { content: { "application/json": { schema: ErrorSchema } }, description: "Authentication required." },
|
|
12
|
-
403: { content: { "application/json": { schema: ErrorSchema } }, description: "Insufficient permissions." },
|
|
13
|
-
404: { content: { "application/json": { schema: ErrorSchema } }, description: "Not found." },
|
|
14
|
-
422: { content: { "application/json": { schema: ErrorSchema } }, description: "Validation error." },
|
|
15
|
-
500: { content: { "application/json": { schema: ErrorSchema } }, description: "Server error." },
|
|
16
|
-
} as const;
|
|
17
|
-
|
|
18
|
-
const PayoutResponseSchema = z.object({ data: z.any() });
|
|
19
|
-
|
|
20
|
-
// ─── Run Payout Cycle ────────────────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
export const RunPayoutCycleBodySchema = z.object({
|
|
23
|
-
vendorIds: z.array(z.uuid()).optional().openapi({ description: "Limit payout run to specific vendors" }),
|
|
24
|
-
force: z.boolean().optional().openapi({ description: "Force payout even if below minimum threshold" }),
|
|
25
|
-
}).openapi("RunPayoutCycleRequest");
|
|
26
|
-
|
|
27
|
-
export const runPayoutCycleRoute = createRoute({
|
|
28
|
-
method: "post",
|
|
29
|
-
path: "/api/marketplace/payouts/run",
|
|
30
|
-
tags: ["Marketplace - Payouts"],
|
|
31
|
-
summary: "Run a payout cycle",
|
|
32
|
-
request: {
|
|
33
|
-
body: { content: { "application/json": { schema: RunPayoutCycleBodySchema } }, required: true },
|
|
34
|
-
},
|
|
35
|
-
responses: {
|
|
36
|
-
200: { content: { "application/json": { schema: PayoutResponseSchema } }, description: "Payout cycle completed." },
|
|
37
|
-
...errorResponses,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ─── List Payouts ───────────────────────────────────────────────────────────
|
|
42
|
-
|
|
43
|
-
export const listPayoutsRoute = createRoute({
|
|
44
|
-
method: "get",
|
|
45
|
-
path: "/api/marketplace/payouts",
|
|
46
|
-
tags: ["Marketplace - Payouts"],
|
|
47
|
-
summary: "List payouts",
|
|
48
|
-
request: {
|
|
49
|
-
query: z.object({
|
|
50
|
-
vendorId: z.string().optional(),
|
|
51
|
-
status: z.string().optional(),
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
responses: {
|
|
55
|
-
200: { content: { "application/json": { schema: PayoutResponseSchema } }, description: "Success" },
|
|
56
|
-
...errorResponses,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// ─── Retry Payout ───────────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
export const retryPayoutRoute = createRoute({
|
|
63
|
-
method: "post",
|
|
64
|
-
path: "/api/marketplace/payouts/{id}/retry",
|
|
65
|
-
tags: ["Marketplace - Payouts"],
|
|
66
|
-
summary: "Retry a failed payout",
|
|
67
|
-
request: {
|
|
68
|
-
params: z.object({ id: z.uuid() }),
|
|
69
|
-
},
|
|
70
|
-
responses: {
|
|
71
|
-
200: { content: { "application/json": { schema: PayoutResponseSchema } }, description: "Payout retried." },
|
|
72
|
-
...errorResponses,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// ─── Get Payout ─────────────────────────────────────────────────────────────
|
|
77
|
-
|
|
78
|
-
export const getPayoutRoute = createRoute({
|
|
79
|
-
method: "get",
|
|
80
|
-
path: "/api/marketplace/payouts/{id}",
|
|
81
|
-
tags: ["Marketplace - Payouts"],
|
|
82
|
-
summary: "Get payout by ID",
|
|
83
|
-
request: {
|
|
84
|
-
params: z.object({ id: z.uuid() }),
|
|
85
|
-
},
|
|
86
|
-
responses: {
|
|
87
|
-
200: { content: { "application/json": { schema: PayoutResponseSchema } }, description: "Success" },
|
|
88
|
-
...errorResponses,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { eq, and, desc, lte, gte, isNull, or } from "@porulle/core/drizzle";
|
|
2
|
-
import { contractPrices } from "../schema.js";
|
|
3
|
-
import type { Db } from "../types.js";
|
|
4
|
-
|
|
5
|
-
export class ContractPriceService {
|
|
6
|
-
constructor(private db: Db) {}
|
|
7
|
-
|
|
8
|
-
async create(data: {
|
|
9
|
-
vendorId: string;
|
|
10
|
-
buyerId: string;
|
|
11
|
-
entityId: string;
|
|
12
|
-
variantId?: string;
|
|
13
|
-
priceCents: number;
|
|
14
|
-
minQuantity?: number;
|
|
15
|
-
currency?: string;
|
|
16
|
-
validFrom?: Date | undefined;
|
|
17
|
-
validUntil?: Date | undefined;
|
|
18
|
-
}) {
|
|
19
|
-
const [price] = await this.db.insert(contractPrices).values(data).returning();
|
|
20
|
-
return price;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async update(id: string, data: Record<string, unknown>) {
|
|
24
|
-
const [updated] = await this.db.update(contractPrices).set(data)
|
|
25
|
-
.where(eq(contractPrices.id, id)).returning();
|
|
26
|
-
return updated ?? null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async delete(id: string) {
|
|
30
|
-
await this.db.delete(contractPrices).where(eq(contractPrices.id, id));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async list(filters?: { vendorId?: string; buyerId?: string }) {
|
|
34
|
-
let query = this.db.select().from(contractPrices).$dynamic();
|
|
35
|
-
const conditions = [];
|
|
36
|
-
if (filters?.vendorId) conditions.push(eq(contractPrices.vendorId, filters.vendorId));
|
|
37
|
-
if (filters?.buyerId) conditions.push(eq(contractPrices.buyerId, filters.buyerId));
|
|
38
|
-
if (conditions.length > 0) {
|
|
39
|
-
query = query.where(conditions.length === 1 ? conditions[0]! : and(...conditions));
|
|
40
|
-
}
|
|
41
|
-
return query.orderBy(desc(contractPrices.createdAt));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Resolve the best contract price for a buyer+vendor+entity+quantity.
|
|
46
|
-
* Returns null if no matching contract exists.
|
|
47
|
-
*/
|
|
48
|
-
async resolvePrice(
|
|
49
|
-
vendorId: string,
|
|
50
|
-
buyerId: string,
|
|
51
|
-
entityId: string,
|
|
52
|
-
variantId: string | null,
|
|
53
|
-
quantity: number,
|
|
54
|
-
): Promise<number | null> {
|
|
55
|
-
const now = new Date();
|
|
56
|
-
const all = await this.db.select().from(contractPrices)
|
|
57
|
-
.where(
|
|
58
|
-
and(
|
|
59
|
-
eq(contractPrices.vendorId, vendorId),
|
|
60
|
-
eq(contractPrices.buyerId, buyerId),
|
|
61
|
-
eq(contractPrices.entityId, entityId),
|
|
62
|
-
),
|
|
63
|
-
)
|
|
64
|
-
.orderBy(desc(contractPrices.priceCents));
|
|
65
|
-
|
|
66
|
-
for (const cp of all) {
|
|
67
|
-
// Check variant match
|
|
68
|
-
if (variantId != null && cp.variantId != null && cp.variantId !== variantId) continue;
|
|
69
|
-
// Check quantity
|
|
70
|
-
if (quantity < (cp.minQuantity ?? 1)) continue;
|
|
71
|
-
// Check time validity
|
|
72
|
-
if (cp.validFrom && cp.validFrom > now) continue;
|
|
73
|
-
if (cp.validUntil && cp.validUntil < now) continue;
|
|
74
|
-
|
|
75
|
-
return cp.priceCents;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
}
|