76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { z } from "zod";
|
|
|
|
export const ChatActionTypeSchema = z.enum([
|
|
"giftOffer",
|
|
"privateAlbumOffer",
|
|
"openProfile",
|
|
"openWallet",
|
|
"openCoinsRules",
|
|
"activateVip",
|
|
"topUp",
|
|
"openFeedback",
|
|
"resumePayment",
|
|
]);
|
|
|
|
export const ChatActionSchema = z
|
|
.object({
|
|
actionId: z.string().min(1),
|
|
kind: z.enum(["support", "commercial"]),
|
|
type: ChatActionTypeSchema,
|
|
copy: z.string().min(1),
|
|
ctaLabel: z.string().min(1),
|
|
ruleId: z.string().min(1).nullable(),
|
|
orderId: z.string().min(1).nullable(),
|
|
})
|
|
.superRefine((action, context) => {
|
|
if (action.type === "resumePayment" && action.orderId === null) {
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["orderId"],
|
|
message: "orderId is required for resumePayment",
|
|
});
|
|
}
|
|
if (action.type !== "resumePayment" && action.orderId !== null) {
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["orderId"],
|
|
message: "orderId is only allowed for resumePayment",
|
|
});
|
|
}
|
|
})
|
|
.readonly();
|
|
|
|
export const ChatActionEventTypeSchema = z.enum([
|
|
"viewed",
|
|
"opened",
|
|
"dismissed",
|
|
"arrived",
|
|
]);
|
|
|
|
export const ChatActionEventRequestSchema = z
|
|
.object({
|
|
eventId: z.uuid(),
|
|
actionId: z.string().min(1),
|
|
characterId: z.string().min(1),
|
|
eventType: ChatActionEventTypeSchema,
|
|
})
|
|
.readonly();
|
|
|
|
export const ChatActionEventResponseSchema = z
|
|
.object({
|
|
eventId: z.uuid(),
|
|
actionId: z.string().min(1),
|
|
eventType: ChatActionEventTypeSchema,
|
|
duplicate: z.boolean(),
|
|
})
|
|
.readonly();
|
|
|
|
export type ChatAction = z.output<typeof ChatActionSchema>;
|
|
export type ChatActionEventType = z.output<typeof ChatActionEventTypeSchema>;
|
|
export type ChatActionEventRequest = z.input<
|
|
typeof ChatActionEventRequestSchema
|
|
>;
|
|
export type ChatActionEventResponse = z.output<
|
|
typeof ChatActionEventResponseSchema
|
|
>;
|