Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

cleanup

Kiran K6f0cbe4db2ef
diff --git a/apps/web/lib/partners/evaluate-reward-conditions.ts b/apps/web/lib/partners/evaluate-reward-conditions.ts
index 9a1b7ea195..0bf35f6307 100644
--- a/apps/web/lib/partners/evaluate-reward-conditions.ts
+++ b/apps/web/lib/partners/evaluate-reward-conditions.ts
@@ -1,4 +1,50 @@
-import { RewardCondition, RewardConditions, RewardContext } from "../types";
+import { z } from "zod";
+
+// Represend an individual reward condition
+export const rewardConditionSchema = z.object({
+ entity: z.enum(["customer", "sale"]),
+ attribute: z.enum(["country", "productId"]),
+ operator: z.enum([
+ "equals_to",
+ "not_equals",
+ "starts_with",
+ "ends_with",
+ "in",
+ "not_in",
+ ]),
+ value: z.union([
+ z.string(),
+ z.number(),
+ z.array(z.string()),
+ z.array(z.number()),
+ ]),
+});
+
+// Individual condition can be combined using AND/OR operator
+export const rewardConditionsSchema = z.object({
+ operator: z.enum(["AND", "OR"]).default("AND"),
+ conditions: z.array(rewardConditionSchema).min(1),
+ amount: z.number().int().min(0),
+});
+
+// The context in which a reward condition is evaluated
+export const rewardContextSchema = z.object({
+ customer: z
+ .object({
+ country: z.string().nullish(),
+ })
+ .optional(),
+
+ sale: z
+ .object({
+ productId: z.string().nullish(),
+ })
+ .optional(),
+});
+
+export type RewardContext = z.infer<typeof rewardContextSchema>;
+export type RewardCondition = z.infer<typeof rewardConditionSchema>;
+export type RewardConditions = z.infer<typeof rewardConditionsSchema>;
export const evaluateRewardConditions = ({
conditions,
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 4deae96653..b76b1f5d1a 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -493,10 +493,4 @@ export type PaymentMethodOption = {
export interface FolderLinkCount {
folderId: string;
_count: number;
-}
-
-export type RewardContext = z.infer<typeof rewardContextSchema>;
-
-export type RewardCondition = z.infer<typeof rewardConditionSchema>;
-
-export type RewardConditions = z.infer<typeof rewardConditionsSchema>;
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/apps/web/lib/zod/schemas/reward-conditions.ts b/apps/web/lib/zod/schemas/reward-conditions.ts
deleted file mode 100644
index ae6014a8c8..0000000000
--- a/apps/web/lib/zod/schemas/reward-conditions.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import { z } from "zod";
-
-// Represend an individual reward condition
-export const rewardConditionSchema = z.object({
- entity: z.enum(["customer", "sale"]),
- attribute: z.enum(["country", "productId"]),
- operator: z.enum([
- "equals_to",
- "not_equals",
- "starts_with",
- "ends_with",
- "in",
- "not_in",
- ]),
- value: z.union([
- z.string(),
- z.number(),
- z.array(z.string()),
- z.array(z.number()),
- ]),
-});
-
-// Individual condition can be combined using AND/OR operator
-export const rewardConditionsSchema = z.object({
- operator: z.enum(["AND", "OR"]).default("AND"),
- conditions: z.array(rewardConditionSchema).min(1),
- amount: z.number().int().min(0),
-});
-
-// The context in which a reward condition is evaluated
-export const rewardContextSchema = z.object({
- customer: z
- .object({
- country: z.string().nullish(),
- })
- .optional(),
-
- sale: z
- .object({
- productId: z.string().nullish(),
- })
- .optional(),
-});