@porulle/core 0.10.1 → 0.10.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.
- package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/promotions.js +6 -1
- package/dist/interfaces/rest/schemas/promotions.d.ts +34 -1
- package/dist/interfaces/rest/schemas/promotions.d.ts.map +1 -1
- package/dist/interfaces/rest/schemas/promotions.js +26 -2
- package/package.json +1 -1
- package/src/interfaces/rest/routes/promotions.ts +6 -1
- package/src/interfaces/rest/schemas/promotions.ts +27 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promotions.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/promotions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,EAAE,KAAK,MAAM,EAAqD,MAAM,aAAa,CAAC;AAG7F,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"promotions.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/promotions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,EAAE,KAAK,MAAM,EAAqD,MAAM,aAAa,CAAC;AAG7F,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,gCAiH7C"}
|
|
@@ -46,7 +46,12 @@ export function promotionRoutes(kernel) {
|
|
|
46
46
|
const payload = c.req.valid("json");
|
|
47
47
|
const actor = c.get("actor");
|
|
48
48
|
const orgId = resolveOrgId(actor);
|
|
49
|
-
|
|
49
|
+
// Apply (not just validate) so the response carries the authoritative
|
|
50
|
+
// discount the cart would receive — the same computation checkout runs.
|
|
51
|
+
// Returning only the promotion forces callers to re-derive the amount, which
|
|
52
|
+
// drifts from checkout and shows customers a wrong number. apply() still
|
|
53
|
+
// Err's on an invalid / inapplicable code (it validates first).
|
|
54
|
+
const result = await kernel.services.promotions.apply(payload.code, {
|
|
50
55
|
orgId,
|
|
51
56
|
currency: payload.currency,
|
|
52
57
|
subtotal: payload.subtotal,
|
|
@@ -48,6 +48,24 @@ export declare const ValidatePromotionBodySchema: z.ZodObject<{
|
|
|
48
48
|
export declare const PromotionResponseSchema: z.ZodObject<{
|
|
49
49
|
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
50
50
|
}, z.core.$strip>;
|
|
51
|
+
export declare const PromotionValidationResultSchema: z.ZodObject<{
|
|
52
|
+
data: z.ZodObject<{
|
|
53
|
+
totalDiscount: z.ZodNumber;
|
|
54
|
+
freeShipping: z.ZodBoolean;
|
|
55
|
+
applied: z.ZodArray<z.ZodObject<{
|
|
56
|
+
promotionId: z.ZodString;
|
|
57
|
+
code: z.ZodOptional<z.ZodString>;
|
|
58
|
+
type: z.ZodString;
|
|
59
|
+
discountAmount: z.ZodNumber;
|
|
60
|
+
freeShipping: z.ZodBoolean;
|
|
61
|
+
description: z.ZodString;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
rejectedCodes: z.ZodArray<z.ZodObject<{
|
|
64
|
+
code: z.ZodString;
|
|
65
|
+
reason: z.ZodString;
|
|
66
|
+
}, z.core.$strip>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
}, z.core.$strip>;
|
|
51
69
|
export declare const listPromotionsRoute: {
|
|
52
70
|
method: "get";
|
|
53
71
|
path: "/";
|
|
@@ -371,7 +389,22 @@ export declare const validatePromotionRoute: {
|
|
|
371
389
|
content: {
|
|
372
390
|
"application/json": {
|
|
373
391
|
schema: z.ZodObject<{
|
|
374
|
-
data: z.
|
|
392
|
+
data: z.ZodObject<{
|
|
393
|
+
totalDiscount: z.ZodNumber;
|
|
394
|
+
freeShipping: z.ZodBoolean;
|
|
395
|
+
applied: z.ZodArray<z.ZodObject<{
|
|
396
|
+
promotionId: z.ZodString;
|
|
397
|
+
code: z.ZodOptional<z.ZodString>;
|
|
398
|
+
type: z.ZodString;
|
|
399
|
+
discountAmount: z.ZodNumber;
|
|
400
|
+
freeShipping: z.ZodBoolean;
|
|
401
|
+
description: z.ZodString;
|
|
402
|
+
}, z.core.$strip>>;
|
|
403
|
+
rejectedCodes: z.ZodArray<z.ZodObject<{
|
|
404
|
+
code: z.ZodString;
|
|
405
|
+
reason: z.ZodString;
|
|
406
|
+
}, z.core.$strip>>;
|
|
407
|
+
}, z.core.$strip>;
|
|
375
408
|
}, z.core.$strip>;
|
|
376
409
|
};
|
|
377
410
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promotions.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/schemas/promotions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAKnD,OAAO,EACL,yBAAyB,EAE1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAErC,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;iBAaF,CAAC;AAIvC,eAAO,MAAM,uBAAuB;;iBAEL,CAAC;
|
|
1
|
+
{"version":3,"file":"promotions.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/schemas/promotions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAKnD,OAAO,EACL,yBAAyB,EAE1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAErC,CAAC;AAEF,eAAO,MAAM,2B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api("PromotionResponse");
|
|
25
|
+
// The authoritative result of applying a code to a cart — the SAME computation
|
|
26
|
+
// checkout uses, so a storefront can show the exact discount the order will get
|
|
27
|
+
// (no client-side re-derivation, which would drift from checkout).
|
|
28
|
+
export const PromotionValidationResultSchema = z.object({
|
|
29
|
+
data: z.object({
|
|
30
|
+
totalDiscount: z.number().openapi({
|
|
31
|
+
example: 1000,
|
|
32
|
+
description: "Discount this code applies to the cart, in the cart's minor units (e.g. cents).",
|
|
33
|
+
}),
|
|
34
|
+
freeShipping: z.boolean().openapi({ example: false }),
|
|
35
|
+
applied: z.array(z.object({
|
|
36
|
+
promotionId: z.string(),
|
|
37
|
+
code: z.string().optional(),
|
|
38
|
+
type: z.string(),
|
|
39
|
+
discountAmount: z.number(),
|
|
40
|
+
freeShipping: z.boolean(),
|
|
41
|
+
description: z.string(),
|
|
42
|
+
})).openapi({ description: "The promotion(s) applied by this code." }),
|
|
43
|
+
rejectedCodes: z.array(z.object({
|
|
44
|
+
code: z.string(),
|
|
45
|
+
reason: z.string(),
|
|
46
|
+
})),
|
|
47
|
+
}),
|
|
48
|
+
}).openapi("PromotionValidationResult");
|
|
25
49
|
// ─── Path Params ────────────────────────────────────────────────────────────
|
|
26
50
|
const PromotionIdParam = z.object({
|
|
27
51
|
id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
@@ -81,8 +105,8 @@ export const validatePromotionRoute = createRoute({
|
|
|
81
105
|
},
|
|
82
106
|
responses: {
|
|
83
107
|
200: {
|
|
84
|
-
content: { "application/json": { schema:
|
|
85
|
-
description: "
|
|
108
|
+
content: { "application/json": { schema: PromotionValidationResultSchema } },
|
|
109
|
+
description: "The code is valid for this cart: the authoritative discount it applies (same computation as checkout).",
|
|
86
110
|
},
|
|
87
111
|
...errorResponses,
|
|
88
112
|
},
|
package/package.json
CHANGED
|
@@ -61,7 +61,12 @@ export function promotionRoutes(kernel: Kernel) {
|
|
|
61
61
|
const actor = c.get("actor");
|
|
62
62
|
const orgId = resolveOrgId(actor);
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
// Apply (not just validate) so the response carries the authoritative
|
|
65
|
+
// discount the cart would receive — the same computation checkout runs.
|
|
66
|
+
// Returning only the promotion forces callers to re-derive the amount, which
|
|
67
|
+
// drifts from checkout and shows customers a wrong number. apply() still
|
|
68
|
+
// Err's on an invalid / inapplicable code (it validates first).
|
|
69
|
+
const result = await kernel.services.promotions.apply(payload.code, {
|
|
65
70
|
orgId,
|
|
66
71
|
currency: payload.currency,
|
|
67
72
|
subtotal: payload.subtotal,
|
|
@@ -34,6 +34,31 @@ export const PromotionResponseSchema = z.object({
|
|
|
34
34
|
data: z.record(z.string(), z.unknown()),
|
|
35
35
|
}).openapi("PromotionResponse");
|
|
36
36
|
|
|
37
|
+
// The authoritative result of applying a code to a cart — the SAME computation
|
|
38
|
+
// checkout uses, so a storefront can show the exact discount the order will get
|
|
39
|
+
// (no client-side re-derivation, which would drift from checkout).
|
|
40
|
+
export const PromotionValidationResultSchema = z.object({
|
|
41
|
+
data: z.object({
|
|
42
|
+
totalDiscount: z.number().openapi({
|
|
43
|
+
example: 1000,
|
|
44
|
+
description: "Discount this code applies to the cart, in the cart's minor units (e.g. cents).",
|
|
45
|
+
}),
|
|
46
|
+
freeShipping: z.boolean().openapi({ example: false }),
|
|
47
|
+
applied: z.array(z.object({
|
|
48
|
+
promotionId: z.string(),
|
|
49
|
+
code: z.string().optional(),
|
|
50
|
+
type: z.string(),
|
|
51
|
+
discountAmount: z.number(),
|
|
52
|
+
freeShipping: z.boolean(),
|
|
53
|
+
description: z.string(),
|
|
54
|
+
})).openapi({ description: "The promotion(s) applied by this code." }),
|
|
55
|
+
rejectedCodes: z.array(z.object({
|
|
56
|
+
code: z.string(),
|
|
57
|
+
reason: z.string(),
|
|
58
|
+
})),
|
|
59
|
+
}),
|
|
60
|
+
}).openapi("PromotionValidationResult");
|
|
61
|
+
|
|
37
62
|
// ─── Path Params ────────────────────────────────────────────────────────────
|
|
38
63
|
|
|
39
64
|
const PromotionIdParam = z.object({
|
|
@@ -98,8 +123,8 @@ export const validatePromotionRoute = createRoute({
|
|
|
98
123
|
},
|
|
99
124
|
responses: {
|
|
100
125
|
200: {
|
|
101
|
-
content: { "application/json": { schema:
|
|
102
|
-
description: "
|
|
126
|
+
content: { "application/json": { schema: PromotionValidationResultSchema } },
|
|
127
|
+
description: "The code is valid for this cart: the authoritative discount it applies (same computation as checkout).",
|
|
103
128
|
},
|
|
104
129
|
...errorResponses,
|
|
105
130
|
},
|