@zyacreatives/shared 2.2.96 → 2.2.98

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.
@@ -80,6 +80,7 @@ export declare const BaseProductSchema: z.ZodObject<{
80
80
  }>;
81
81
  amount: z.ZodNumber;
82
82
  discountCode: z.ZodNullable<z.ZodOptional<z.ZodString>>;
83
+ expiry: z.ZodNullable<z.ZodOptional<z.ZodISODateTime>>;
83
84
  }, z.core.$strip>>>;
84
85
  supportEmail: z.ZodNullable<z.ZodString>;
85
86
  supportPhone: z.ZodNullable<z.ZodString>;
@@ -64,6 +64,7 @@ exports.BaseProductSchema = zod_openapi_1.z.object({
64
64
  discountType: zod_openapi_1.z.enum(constants_1.DISCOUNT_TYPES),
65
65
  amount: zod_openapi_1.z.number(),
66
66
  discountCode: zod_openapi_1.z.string().optional().nullable(),
67
+ expiry: zod_openapi_1.z.iso.datetime().optional().nullable(),
67
68
  }))
68
69
  .nullable(),
69
70
  supportEmail: zod_openapi_1.z.string().nullable(),
@@ -82,14 +83,14 @@ const ProductCoreInputSchema = zod_openapi_1.z.object({
82
83
  coverImages: zod_openapi_1.z
83
84
  .array(exports.CoverImageInputSchema)
84
85
  .min(1, "At least one cover image is required")
85
- .max(3, "Maximum of 3 cover images allowed"),
86
+ .max(5, "Maximum of 5 cover images allowed"),
86
87
  currency: zod_openapi_1.z.enum(constants_1.WAGES_CURRENCY),
87
88
  productFiles: zod_openapi_1.z.array(exports.DeliveryFileInputSchema).default([]),
88
89
  productLinks: zod_openapi_1.z.array(exports.ProductLinkSchema).default([]),
89
90
  pricingModel: zod_openapi_1.z.enum(constants_1.PRICING_MODELS).default(constants_1.PRICING_MODELS.FIXED),
90
91
  price: zod_openapi_1.z.number().int("Must be in cents").min(0).optional(),
91
92
  suggestedPrice: zod_openapi_1.z.number().int("Must be in cents").min(0).optional(),
92
- discounts: zod_openapi_1.z.array(exports.ProductDiscountEntitySchema).default([]),
93
+ discounts: zod_openapi_1.z.array(exports.ProductDiscountEntitySchema).max(3).default([]),
93
94
  });
94
95
  exports.CreateProductInputSchema = ProductCoreInputSchema.superRefine((data, ctx) => {
95
96
  if (data.pricingModel === constants_1.PRICING_MODELS.FIXED &&
@@ -100,15 +101,15 @@ exports.CreateProductInputSchema = ProductCoreInputSchema.superRefine((data, ctx
100
101
  path: ["price"],
101
102
  });
102
103
  }
103
- if (data.pricingModel === constants_1.PRICING_MODELS.PWYW) {
104
- if (data.suggestedPrice !== undefined && data.price !== undefined) {
105
- if (data.suggestedPrice < data.price) {
106
- ctx.addIssue({
107
- code: "custom",
108
- message: "Suggested price cannot be lower than the minimum price.",
109
- path: ["suggestedPrice"],
110
- });
111
- }
104
+ if (data.pricingModel === constants_1.PRICING_MODELS.PWYW &&
105
+ data.suggestedPrice !== undefined &&
106
+ data.price !== undefined) {
107
+ if (data.suggestedPrice < data.price) {
108
+ ctx.addIssue({
109
+ code: "custom",
110
+ message: "Suggested price cannot be lower than the minimum price.",
111
+ path: ["suggestedPrice"],
112
+ });
112
113
  }
113
114
  }
114
115
  if (data.pricingModel === constants_1.PRICING_MODELS.FREE &&
@@ -135,6 +136,26 @@ exports.CreateProductInputSchema = ProductCoreInputSchema.superRefine((data, ctx
135
136
  path: ["coverImages"],
136
137
  });
137
138
  }
139
+ data.discounts.forEach((discount, index) => {
140
+ const isPercentage = String(discount.discountType).toUpperCase() === "PERCENTAGE";
141
+ const isFixed = String(discount.discountType).toUpperCase() === "FIXED";
142
+ if (isPercentage && discount.amount >= 100) {
143
+ ctx.addIssue({
144
+ code: "custom",
145
+ message: "Percentage discounts must be less than 100%.",
146
+ path: ["discounts", index, "amount"],
147
+ });
148
+ }
149
+ if (isFixed && data.price !== undefined) {
150
+ if (discount.amount >= data.price) {
151
+ ctx.addIssue({
152
+ code: "custom",
153
+ message: "Fixed discount amounts must be less than the product price.",
154
+ path: ["discounts", index, "amount"],
155
+ });
156
+ }
157
+ }
158
+ });
138
159
  });
139
160
  exports.ProductServiceAndComplianceInputSchema = zod_openapi_1.z.object({
140
161
  id: zod_openapi_1.z.cuid2().openapi({ description: "ID of the product" }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyacreatives/shared",
3
- "version": "2.2.96",
3
+ "version": "2.2.98",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -80,6 +80,7 @@ export const BaseProductSchema = z.object({
80
80
  discountType: z.enum(DISCOUNT_TYPES),
81
81
  amount: z.number(),
82
82
  discountCode: z.string().optional().nullable(),
83
+ expiry: z.iso.datetime().optional().nullable(),
83
84
  }),
84
85
  )
85
86
  .nullable(),
@@ -103,7 +104,7 @@ const ProductCoreInputSchema = z.object({
103
104
  coverImages: z
104
105
  .array(CoverImageInputSchema)
105
106
  .min(1, "At least one cover image is required")
106
- .max(3, "Maximum of 3 cover images allowed"),
107
+ .max(5, "Maximum of 5 cover images allowed"),
107
108
  currency: z.enum(WAGES_CURRENCY),
108
109
  productFiles: z.array(DeliveryFileInputSchema).default([]),
109
110
 
@@ -114,7 +115,7 @@ const ProductCoreInputSchema = z.object({
114
115
  price: z.number().int("Must be in cents").min(0).optional(),
115
116
  suggestedPrice: z.number().int("Must be in cents").min(0).optional(),
116
117
 
117
- discounts: z.array(ProductDiscountEntitySchema).default([]),
118
+ discounts: z.array(ProductDiscountEntitySchema).max(3).default([]),
118
119
  });
119
120
 
120
121
  export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
@@ -130,15 +131,17 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
130
131
  });
131
132
  }
132
133
 
133
- if (data.pricingModel === PRICING_MODELS.PWYW) {
134
- if (data.suggestedPrice !== undefined && data.price !== undefined) {
135
- if (data.suggestedPrice < data.price) {
136
- ctx.addIssue({
137
- code: "custom",
138
- message: "Suggested price cannot be lower than the minimum price.",
139
- path: ["suggestedPrice"],
140
- });
141
- }
134
+ if (
135
+ data.pricingModel === PRICING_MODELS.PWYW &&
136
+ data.suggestedPrice !== undefined &&
137
+ data.price !== undefined
138
+ ) {
139
+ if (data.suggestedPrice < data.price) {
140
+ ctx.addIssue({
141
+ code: "custom",
142
+ message: "Suggested price cannot be lower than the minimum price.",
143
+ path: ["suggestedPrice"],
144
+ });
142
145
  }
143
146
  }
144
147
 
@@ -171,6 +174,31 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
171
174
  path: ["coverImages"],
172
175
  });
173
176
  }
177
+
178
+ data.discounts.forEach((discount, index) => {
179
+ const isPercentage =
180
+ String(discount.discountType).toUpperCase() === "PERCENTAGE";
181
+ const isFixed = String(discount.discountType).toUpperCase() === "FIXED";
182
+
183
+ if (isPercentage && discount.amount >= 100) {
184
+ ctx.addIssue({
185
+ code: "custom",
186
+ message: "Percentage discounts must be less than 100%.",
187
+ path: ["discounts", index, "amount"],
188
+ });
189
+ }
190
+
191
+ if (isFixed && data.price !== undefined) {
192
+ if (discount.amount >= data.price) {
193
+ ctx.addIssue({
194
+ code: "custom",
195
+ message:
196
+ "Fixed discount amounts must be less than the product price.",
197
+ path: ["discounts", index, "amount"],
198
+ });
199
+ }
200
+ }
201
+ });
174
202
  },
175
203
  );
176
204