@zyacreatives/shared 2.5.4 → 2.5.7

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.
@@ -298,6 +298,8 @@ export declare const UserWithPostsEntitySchema: z.ZodObject<{
298
298
  readonly JOB: "JOB";
299
299
  readonly POST: "POST";
300
300
  readonly PRODUCT: "PRODUCT";
301
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
302
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
301
303
  readonly COMMENT: "COMMENT";
302
304
  readonly JOB_APPLICATION: "JOB_APPLICATION";
303
305
  }>>;
@@ -349,6 +351,8 @@ export declare const UserWithPostsEntitySchema: z.ZodObject<{
349
351
  readonly JOB: "JOB";
350
352
  readonly POST: "POST";
351
353
  readonly PRODUCT: "PRODUCT";
354
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
355
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
352
356
  readonly COMMENT: "COMMENT";
353
357
  readonly JOB_APPLICATION: "JOB_APPLICATION";
354
358
  }>>;
@@ -373,6 +377,8 @@ export declare const UserWithProjectLikesEntitySchema: z.ZodObject<{
373
377
  readonly JOB: "JOB";
374
378
  readonly POST: "POST";
375
379
  readonly PRODUCT: "PRODUCT";
380
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
381
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
376
382
  readonly COMMENT: "COMMENT";
377
383
  readonly JOB_APPLICATION: "JOB_APPLICATION";
378
384
  }>;
@@ -400,6 +406,8 @@ export declare const UserWithPostLikesEntitySchema: z.ZodObject<{
400
406
  readonly JOB: "JOB";
401
407
  readonly POST: "POST";
402
408
  readonly PRODUCT: "PRODUCT";
409
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
410
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
403
411
  readonly COMMENT: "COMMENT";
404
412
  readonly JOB_APPLICATION: "JOB_APPLICATION";
405
413
  }>;
@@ -428,6 +436,8 @@ export declare const UserWithJobBookmarksEntitySchema: z.ZodObject<{
428
436
  readonly JOB: "JOB";
429
437
  readonly POST: "POST";
430
438
  readonly PRODUCT: "PRODUCT";
439
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
440
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
431
441
  readonly COMMENT: "COMMENT";
432
442
  readonly JOB_APPLICATION: "JOB_APPLICATION";
433
443
  }>;
@@ -476,6 +486,8 @@ export declare const UserWithJobBookmarksOutputSchema: z.ZodObject<{
476
486
  readonly JOB: "JOB";
477
487
  readonly POST: "POST";
478
488
  readonly PRODUCT: "PRODUCT";
489
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
490
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
479
491
  readonly COMMENT: "COMMENT";
480
492
  readonly JOB_APPLICATION: "JOB_APPLICATION";
481
493
  }>;
@@ -521,6 +533,8 @@ export declare const UserWithProjectBookmarksEntitySchema: z.ZodObject<{
521
533
  readonly JOB: "JOB";
522
534
  readonly POST: "POST";
523
535
  readonly PRODUCT: "PRODUCT";
536
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
537
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
524
538
  readonly COMMENT: "COMMENT";
525
539
  readonly JOB_APPLICATION: "JOB_APPLICATION";
526
540
  }>;
@@ -592,6 +606,8 @@ export declare const UserWithPostBookmarksEntitySchema: z.ZodObject<{
592
606
  readonly JOB: "JOB";
593
607
  readonly POST: "POST";
594
608
  readonly PRODUCT: "PRODUCT";
609
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
610
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
595
611
  readonly COMMENT: "COMMENT";
596
612
  readonly JOB_APPLICATION: "JOB_APPLICATION";
597
613
  }>;
@@ -604,6 +620,8 @@ export declare const UserWithPostBookmarksEntitySchema: z.ZodObject<{
604
620
  readonly JOB: "JOB";
605
621
  readonly POST: "POST";
606
622
  readonly PRODUCT: "PRODUCT";
623
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
624
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
607
625
  readonly COMMENT: "COMMENT";
608
626
  readonly JOB_APPLICATION: "JOB_APPLICATION";
609
627
  }>>;
@@ -655,6 +673,8 @@ export declare const UserWithPostBookmarksEntitySchema: z.ZodObject<{
655
673
  readonly JOB: "JOB";
656
674
  readonly POST: "POST";
657
675
  readonly PRODUCT: "PRODUCT";
676
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
677
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
658
678
  readonly COMMENT: "COMMENT";
659
679
  readonly JOB_APPLICATION: "JOB_APPLICATION";
660
680
  }>>;
@@ -688,16 +708,28 @@ export declare const UserWithProductsEntitySchema: z.ZodObject<{
688
708
  category: z.ZodString;
689
709
  subcategory: z.ZodNullable<z.ZodOptional<z.ZodString>>;
690
710
  tags: z.ZodArray<z.ZodString>;
691
- coverImages: z.ZodDefault<z.ZodArray<z.ZodObject<{
692
- fileId: z.ZodCUID2;
693
- isThumbnail: z.ZodDefault<z.ZodBoolean>;
694
- order: z.ZodDefault<z.ZodNumber>;
695
- url: z.ZodURL;
696
- }, z.core.$strip>>>;
697
- productFiles: z.ZodDefault<z.ZodArray<z.ZodObject<{
698
- fileId: z.ZodCUID2;
699
- order: z.ZodDefault<z.ZodNumber>;
711
+ files: z.ZodDefault<z.ZodArray<z.ZodObject<{
712
+ id: z.ZodCUID2;
713
+ key: z.ZodString;
714
+ mimeType: z.ZodString;
700
715
  url: z.ZodURL;
716
+ parentId: z.ZodNullable<z.ZodCUID2>;
717
+ parentType: z.ZodNullable<z.ZodEnum<{
718
+ readonly PROJECT: "PROJECT";
719
+ readonly USER: "USER";
720
+ readonly JOB: "JOB";
721
+ readonly POST: "POST";
722
+ readonly PRODUCT: "PRODUCT";
723
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
724
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
725
+ readonly COMMENT: "COMMENT";
726
+ readonly JOB_APPLICATION: "JOB_APPLICATION";
727
+ }>>;
728
+ isThumbnail: z.ZodNullable<z.ZodBoolean>;
729
+ order: z.ZodNumber;
730
+ createdAt: z.ZodCoercedDate<unknown>;
731
+ updatedAt: z.ZodCoercedDate<unknown>;
732
+ deletedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
701
733
  }, z.core.$strip>>>;
702
734
  productLinks: z.ZodDefault<z.ZodArray<z.ZodObject<{
703
735
  title: z.ZodNullable<z.ZodString>;
@@ -729,8 +761,12 @@ export declare const UserWithProductsEntitySchema: z.ZodObject<{
729
761
  }>;
730
762
  amount: z.ZodNumber;
731
763
  discountCode: z.ZodOptional<z.ZodString>;
732
- expiry: z.ZodNullable<z.ZodOptional<z.ZodCoercedDate<unknown>>>;
764
+ active: z.ZodDefault<z.ZodBoolean>;
733
765
  }, z.core.$strip>>>;
766
+ ownsRights: z.ZodBoolean;
767
+ noHarmfulContent: z.ZodBoolean;
768
+ providesSupport: z.ZodBoolean;
769
+ agreesToTerms: z.ZodBoolean;
734
770
  supportEmail: z.ZodNullable<z.ZodOptional<z.ZodEmail>>;
735
771
  supportPhone: z.ZodNullable<z.ZodOptional<z.ZodString>>;
736
772
  createdAt: z.ZodCoercedDate<unknown>;
@@ -761,6 +797,8 @@ export declare const GetUserWithProjectBookmarksOutputSchema: z.ZodObject<{
761
797
  readonly JOB: "JOB";
762
798
  readonly POST: "POST";
763
799
  readonly PRODUCT: "PRODUCT";
800
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
801
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
764
802
  readonly COMMENT: "COMMENT";
765
803
  readonly JOB_APPLICATION: "JOB_APPLICATION";
766
804
  }>;
@@ -843,16 +881,28 @@ export declare const GetUserWithProductsOutputSchema: z.ZodObject<{
843
881
  category: z.ZodString;
844
882
  subcategory: z.ZodNullable<z.ZodOptional<z.ZodString>>;
845
883
  tags: z.ZodArray<z.ZodString>;
846
- coverImages: z.ZodDefault<z.ZodArray<z.ZodObject<{
847
- fileId: z.ZodCUID2;
848
- isThumbnail: z.ZodDefault<z.ZodBoolean>;
849
- order: z.ZodDefault<z.ZodNumber>;
850
- url: z.ZodURL;
851
- }, z.core.$strip>>>;
852
- productFiles: z.ZodDefault<z.ZodArray<z.ZodObject<{
853
- fileId: z.ZodCUID2;
854
- order: z.ZodDefault<z.ZodNumber>;
884
+ files: z.ZodDefault<z.ZodArray<z.ZodObject<{
885
+ id: z.ZodCUID2;
886
+ key: z.ZodString;
887
+ mimeType: z.ZodString;
855
888
  url: z.ZodURL;
889
+ parentId: z.ZodNullable<z.ZodCUID2>;
890
+ parentType: z.ZodNullable<z.ZodEnum<{
891
+ readonly PROJECT: "PROJECT";
892
+ readonly USER: "USER";
893
+ readonly JOB: "JOB";
894
+ readonly POST: "POST";
895
+ readonly PRODUCT: "PRODUCT";
896
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
897
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
898
+ readonly COMMENT: "COMMENT";
899
+ readonly JOB_APPLICATION: "JOB_APPLICATION";
900
+ }>>;
901
+ isThumbnail: z.ZodNullable<z.ZodBoolean>;
902
+ order: z.ZodNumber;
903
+ createdAt: z.ZodCoercedDate<unknown>;
904
+ updatedAt: z.ZodCoercedDate<unknown>;
905
+ deletedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
856
906
  }, z.core.$strip>>>;
857
907
  productLinks: z.ZodDefault<z.ZodArray<z.ZodObject<{
858
908
  title: z.ZodNullable<z.ZodString>;
@@ -884,8 +934,12 @@ export declare const GetUserWithProductsOutputSchema: z.ZodObject<{
884
934
  }>;
885
935
  amount: z.ZodNumber;
886
936
  discountCode: z.ZodOptional<z.ZodString>;
887
- expiry: z.ZodNullable<z.ZodOptional<z.ZodCoercedDate<unknown>>>;
937
+ active: z.ZodDefault<z.ZodBoolean>;
888
938
  }, z.core.$strip>>>;
939
+ ownsRights: z.ZodBoolean;
940
+ noHarmfulContent: z.ZodBoolean;
941
+ providesSupport: z.ZodBoolean;
942
+ agreesToTerms: z.ZodBoolean;
889
943
  supportEmail: z.ZodNullable<z.ZodOptional<z.ZodEmail>>;
890
944
  supportPhone: z.ZodNullable<z.ZodOptional<z.ZodString>>;
891
945
  createdAt: z.ZodCoercedDate<unknown>;
@@ -909,6 +963,8 @@ export declare const GetUserWithPostBookmarksOutputSchema: z.ZodObject<{
909
963
  readonly JOB: "JOB";
910
964
  readonly POST: "POST";
911
965
  readonly PRODUCT: "PRODUCT";
966
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
967
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
912
968
  readonly COMMENT: "COMMENT";
913
969
  readonly JOB_APPLICATION: "JOB_APPLICATION";
914
970
  }>;
@@ -921,6 +977,8 @@ export declare const GetUserWithPostBookmarksOutputSchema: z.ZodObject<{
921
977
  readonly JOB: "JOB";
922
978
  readonly POST: "POST";
923
979
  readonly PRODUCT: "PRODUCT";
980
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
981
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
924
982
  readonly COMMENT: "COMMENT";
925
983
  readonly JOB_APPLICATION: "JOB_APPLICATION";
926
984
  }>>;
@@ -972,6 +1030,8 @@ export declare const GetUserWithPostBookmarksOutputSchema: z.ZodObject<{
972
1030
  readonly JOB: "JOB";
973
1031
  readonly POST: "POST";
974
1032
  readonly PRODUCT: "PRODUCT";
1033
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
1034
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
975
1035
  readonly COMMENT: "COMMENT";
976
1036
  readonly JOB_APPLICATION: "JOB_APPLICATION";
977
1037
  }>>;
@@ -991,6 +1051,8 @@ export declare const GetUserWithPostBookmarksOutputSchema: z.ZodObject<{
991
1051
  readonly JOB: "JOB";
992
1052
  readonly POST: "POST";
993
1053
  readonly PRODUCT: "PRODUCT";
1054
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
1055
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
994
1056
  readonly COMMENT: "COMMENT";
995
1057
  readonly JOB_APPLICATION: "JOB_APPLICATION";
996
1058
  }>;
@@ -1390,6 +1452,8 @@ export declare const GetAuthenticatedUserWithProjectBookmarksOutputSchema: z.Zod
1390
1452
  readonly JOB: "JOB";
1391
1453
  readonly POST: "POST";
1392
1454
  readonly PRODUCT: "PRODUCT";
1455
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
1456
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
1393
1457
  readonly COMMENT: "COMMENT";
1394
1458
  readonly JOB_APPLICATION: "JOB_APPLICATION";
1395
1459
  }>;
@@ -1461,6 +1525,8 @@ export declare const GetAuthenticatedUserWithProjectLikesOutputSchema: z.ZodObje
1461
1525
  readonly JOB: "JOB";
1462
1526
  readonly POST: "POST";
1463
1527
  readonly PRODUCT: "PRODUCT";
1528
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
1529
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
1464
1530
  readonly COMMENT: "COMMENT";
1465
1531
  readonly JOB_APPLICATION: "JOB_APPLICATION";
1466
1532
  }>;
@@ -1548,6 +1614,8 @@ export declare const GetUserActivityOutputSchema: z.ZodArray<z.ZodObject<{
1548
1614
  JOB: "JOB";
1549
1615
  POST: "POST";
1550
1616
  PRODUCT: "PRODUCT";
1617
+ PRODUCT_COVER: "PRODUCT_COVER";
1618
+ PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
1551
1619
  COMMENT: "COMMENT";
1552
1620
  JOB_APPLICATION: "JOB_APPLICATION";
1553
1621
  }>;
@@ -11,6 +11,8 @@ export declare const ViewEntitySchema: z.ZodObject<{
11
11
  readonly JOB: "JOB";
12
12
  readonly POST: "POST";
13
13
  readonly PRODUCT: "PRODUCT";
14
+ readonly PRODUCT_COVER: "PRODUCT_COVER";
15
+ readonly PRODUCT_DELIVERY: "PRODUCT_DELIVERY";
14
16
  readonly COMMENT: "COMMENT";
15
17
  readonly JOB_APPLICATION: "JOB_APPLICATION";
16
18
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyacreatives/shared",
3
- "version": "2.5.4",
3
+ "version": "2.5.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/constants.ts CHANGED
@@ -109,6 +109,8 @@ export const ACTIVITY_PARENT_TYPES = {
109
109
  JOB: "JOB",
110
110
  POST: "POST",
111
111
  PRODUCT: "PRODUCT",
112
+ PRODUCT_COVER: "PRODUCT_COVER",
113
+ PRODUCT_DELIVERY: "PRODUCT_DELIVERY",
112
114
  COMMENT: "COMMENT",
113
115
  JOB_APPLICATION: "JOB_APPLICATION",
114
116
  } as const;
@@ -8,10 +8,7 @@ export const FileEntitySchema = z
8
8
  mimeType: z.string().openapi({ example: "image/jpeg" }),
9
9
  url: z.url().openapi({ example: "https://example.com/file.jpg" }),
10
10
  parentId: z.cuid2().nullable().openapi({ example: "ckj1a2b3c0000xyz" }),
11
- parentType: z
12
- .enum(ACTIVITY_PARENT_TYPES)
13
- .nullable()
14
- .openapi({ example: "POST" }),
11
+ parentType: z.enum(ACTIVITY_PARENT_TYPES).nullable(),
15
12
  isThumbnail: z.boolean().nullable().openapi({ example: false }),
16
13
  order: z.number().int().openapi({ example: 0 }),
17
14
  createdAt: z.coerce.date().openapi({ example: "2025-10-14T08:00:00.000Z" }),
@@ -4,35 +4,9 @@ import {
4
4
  PRICING_MODELS,
5
5
  PRODUCT_STATUS,
6
6
  WAGES_CURRENCY,
7
+ ACTIVITY_PARENT_TYPES, // Assumes this includes 'PRODUCT_COVER' and 'PRODUCT_DELIVERY'
7
8
  } from "../constants";
8
-
9
- export const CoverImageInputSchema = z.object({
10
- key: z.string().openapi({ description: "Storage key of the uploaded file" }),
11
- mimeType: z.string().openapi({ example: "image/jpeg" }),
12
- isThumbnail: z.boolean().default(false),
13
- order: z.number().int().default(0),
14
- });
15
-
16
- export const DeliveryFileInputSchema = z.object({
17
- key: z.string().openapi({ description: "Storage key of the uploaded file" }),
18
- mimeType: z.string().openapi({ example: "application/zip" }),
19
- order: z.number().int().default(0),
20
- });
21
-
22
- export const ProductCoverImageEntitySchema = z.object({
23
- fileId: z
24
- .cuid2()
25
- .openapi({ example: "f123e4567-e89b-12d3-a456-426614174000" }),
26
- isThumbnail: z.boolean().default(false),
27
- order: z.number().int().default(0),
28
- });
29
-
30
- export const ProductDeliveryFileEntitySchema = z.object({
31
- fileId: z
32
- .cuid2()
33
- .openapi({ example: "f987e6543-e89b-12d3-a456-426614174000" }),
34
- order: z.number().int().default(0),
35
- });
9
+ import { CreateFileInputSchema, FileEntitySchema } from "./file";
36
10
 
37
11
  export const ProductDiscountEntitySchema = z.object({
38
12
  discountType: z.enum(DISCOUNT_TYPES),
@@ -41,48 +15,13 @@ export const ProductDiscountEntitySchema = z.object({
41
15
  .int("Amount must be a whole number")
42
16
  .min(0, "Discount amount cannot be negative"),
43
17
  discountCode: z.string().optional(),
44
- expiry: z.coerce.date().optional().nullable(),
18
+ active: z.boolean().default(true),
45
19
  });
46
20
 
47
21
  export const ProductLinkSchema = z.object({
48
22
  title: z.string().nullable(),
49
23
  url: z.string(),
50
24
  });
51
- export type ProductLink = z.infer<typeof ProductLinkSchema>;
52
-
53
- export const BaseProductSchema = z.object({
54
- id: z.cuid2(),
55
- createdAt: z.date(),
56
- updatedAt: z.date(),
57
- deletedAt: z.date().nullable(),
58
- status: z.enum(PRODUCT_STATUS).default("DRAFT"),
59
- sellerId: z.cuid2(),
60
- title: z.string(),
61
- description: z.string(),
62
- keyFeatures: z.string(),
63
-
64
- category: z.string(),
65
- subcategory: z.string().nullable(),
66
- tags: z.array(z.string()).nullable(),
67
-
68
- productLinks: z.array(ProductLinkSchema).nullable(),
69
- pricingModel: z.enum(PRICING_MODELS),
70
- currency: z.enum(WAGES_CURRENCY),
71
- price: z.number().nullable(),
72
- suggestedPrice: z.number().nullable(),
73
- discounts: z
74
- .array(
75
- z.object({
76
- discountType: z.enum(DISCOUNT_TYPES),
77
- amount: z.number(),
78
- discountCode: z.string().optional().nullable(),
79
- expiry: z.coerce.date().optional().nullable(),
80
- }),
81
- )
82
- .nullable(),
83
- supportEmail: z.string().nullable(),
84
- supportPhone: z.string().nullable(),
85
- });
86
25
 
87
26
  const ProductCoreInputSchema = z.object({
88
27
  id: z.cuid2().openapi({ description: "Client-generated ID for the product" }),
@@ -94,26 +33,19 @@ const ProductCoreInputSchema = z.object({
94
33
  category: z.string().min(1, "Category is required"),
95
34
  subcategory: z.string().optional(),
96
35
  tags: z.array(z.string()).max(10, "Keep tags to a maximum of 10").default([]),
97
-
98
- coverImages: z
99
- .array(CoverImageInputSchema)
100
- .min(1, "At least one cover image is required")
101
- .max(5, "Maximum of 5 cover images allowed"),
102
- currency: z.enum(WAGES_CURRENCY),
103
- productFiles: z.array(DeliveryFileInputSchema).default([]),
104
-
36
+ files: z.array(CreateFileInputSchema).default([]),
105
37
  productLinks: z.array(ProductLinkSchema).default([]),
106
38
 
39
+ currency: z.enum(WAGES_CURRENCY),
107
40
  pricingModel: z.enum(PRICING_MODELS).default(PRICING_MODELS.FIXED),
108
-
109
41
  price: z.number().int("Must be a whole number").min(0).optional(),
110
42
  suggestedPrice: z.number().int("Must be in cents").min(0).optional(),
111
-
112
43
  discounts: z.array(ProductDiscountEntitySchema).max(3).default([]),
113
44
  });
114
45
 
115
46
  export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
116
47
  (data, ctx) => {
48
+
117
49
  if (
118
50
  data.pricingModel === PRICING_MODELS.FIXED &&
119
51
  (!data.price || data.price <= 0)
@@ -128,15 +60,14 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
128
60
  if (
129
61
  data.pricingModel === PRICING_MODELS.PWYW &&
130
62
  data.suggestedPrice !== undefined &&
131
- data.price !== undefined
63
+ data.price !== undefined &&
64
+ data.suggestedPrice < data.price
132
65
  ) {
133
- if (data.suggestedPrice < data.price) {
134
- ctx.addIssue({
135
- code: "custom",
136
- message: "Suggested price cannot be lower than the minimum price.",
137
- path: ["suggestedPrice"],
138
- });
139
- }
66
+ ctx.addIssue({
67
+ code: "custom",
68
+ message: "Suggested price cannot be lower than the minimum price.",
69
+ path: ["suggestedPrice"],
70
+ });
140
71
  }
141
72
 
142
73
  if (
@@ -151,22 +82,37 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
151
82
  });
152
83
  }
153
84
 
154
- if (data.productFiles.length === 0 && data.productLinks.length === 0) {
85
+ const deliveryFiles = data.files.filter(
86
+ (f) => f.parentType === "PRODUCT_DELIVERY",
87
+ );
88
+ const coverImages = data.files.filter(
89
+ (f) => f.parentType === "PRODUCT_COVER",
90
+ );
91
+
92
+ if (deliveryFiles.length === 0 && data.productLinks.length === 0) {
155
93
  ctx.addIssue({
156
94
  code: "custom",
157
95
  message:
158
96
  "You must provide at least one product file or a link for the buyer to receive.",
159
- path: ["productFiles"],
97
+ path: ["files"],
160
98
  });
161
99
  }
162
100
 
163
- const thumbnails = data.coverImages.filter((img) => img.isThumbnail);
164
- if (thumbnails.length !== 1) {
101
+ if (coverImages.length < 1 || coverImages.length > 5) {
165
102
  ctx.addIssue({
166
103
  code: "custom",
167
- message: "Exactly one cover image must be set as the thumbnail.",
168
- path: ["coverImages"],
104
+ message: "Between 1 and 5 cover images are required.",
105
+ path: ["files"],
169
106
  });
107
+ } else {
108
+ const thumbnails = coverImages.filter((img) => img.isThumbnail);
109
+ if (thumbnails.length !== 1) {
110
+ ctx.addIssue({
111
+ code: "custom",
112
+ message: "Exactly one cover image must be set as the thumbnail.",
113
+ path: ["files"],
114
+ });
115
+ }
170
116
  }
171
117
 
172
118
  data.discounts.forEach((discount, index) => {
@@ -182,15 +128,17 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
182
128
  });
183
129
  }
184
130
 
185
- if (isFixed && data.price !== undefined) {
186
- if (discount.amount >= data.price) {
187
- ctx.addIssue({
188
- code: "custom",
189
- message:
190
- "Fixed discount amounts must be less than the product price.",
191
- path: ["discounts", index, "amount"],
192
- });
193
- }
131
+ if (
132
+ isFixed &&
133
+ data.price !== undefined &&
134
+ discount.amount >= data.price
135
+ ) {
136
+ ctx.addIssue({
137
+ code: "custom",
138
+ message:
139
+ "Fixed discount amounts must be less than the product price.",
140
+ path: ["discounts", index, "amount"],
141
+ });
194
142
  }
195
143
  });
196
144
  },
@@ -198,17 +146,13 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
198
146
 
199
147
  export const ProductServiceAndComplianceInputSchema = z.object({
200
148
  id: z.cuid2().openapi({ description: "ID of the product" }),
201
-
202
149
  supportEmail: z.email("A valid support email is required"),
203
150
  supportPhone: z.string().optional(),
204
-
205
151
  ownsRights: z.literal(
206
152
  true,
207
- "You must confirm you own the rights to this product.",
153
+ '"You must confirm you own the rights to this product."',
208
154
  ),
209
-
210
155
  noHarmfulContent: z.literal(true, "You must confirm no harmful content."),
211
-
212
156
  providesSupport: z.boolean(),
213
157
  agreesToTerms: z.literal(true, "You must agree to the Terms."),
214
158
  });
@@ -221,10 +165,10 @@ export const UpdateProductInputSchema = ProductCoreInputSchema.extend(
221
165
  id: z.cuid2().openapi({ description: "ID of the product being updated" }),
222
166
  });
223
167
 
168
+
224
169
  export const ProductEntitySchema = z
225
170
  .object({
226
171
  id: z.cuid2(),
227
-
228
172
  sellerId: z.cuid2().openapi({ description: "ID of the creator/seller" }),
229
173
  sellerUsername: z.string(),
230
174
  sellerName: z.string(),
@@ -238,22 +182,22 @@ export const ProductEntitySchema = z
238
182
  subcategory: z.string().optional().nullable(),
239
183
  tags: z.array(z.string()),
240
184
 
241
- coverImages: z
242
- .array(ProductCoverImageEntitySchema.extend({ url: z.url() }))
243
- .default([]),
244
- productFiles: z
245
- .array(ProductDeliveryFileEntitySchema.extend({ url: z.url() }))
246
- .default([]),
185
+ files: z.array(FileEntitySchema).default([]),
247
186
  productLinks: z.array(ProductLinkSchema).default([]),
187
+
248
188
  pricingModel: z.enum(PRICING_MODELS),
249
189
  currency: z.enum(WAGES_CURRENCY),
250
190
  price: z.number().int().optional().nullable(),
251
191
  suggestedPrice: z.number().int().optional().nullable(),
252
-
253
192
  discounts: z.array(ProductDiscountEntitySchema).default([]),
254
193
 
194
+ ownsRights: z.boolean(),
195
+ noHarmfulContent: z.boolean(),
196
+ providesSupport: z.boolean(),
197
+ agreesToTerms: z.boolean(),
255
198
  supportEmail: z.email().optional().nullable(),
256
199
  supportPhone: z.string().optional().nullable(),
200
+
257
201
  createdAt: z.coerce.date(),
258
202
  updatedAt: z.coerce.date(),
259
203
  deletedAt: z.coerce.date().optional().nullable(),
@@ -311,11 +255,9 @@ export const GetMarketplaceInfoOutputSchema = z.object({
311
255
  communityFavourites: z.array(ProductSearchDocumentSchema),
312
256
  });
313
257
 
258
+ export type ProductLink = z.infer<typeof ProductLinkSchema>;
314
259
  export type SearchProductInput = z.infer<typeof SearchProductInputSchema>;
315
260
  export type SearchProductOutput = z.infer<typeof SearchProductOutputSchema>;
316
- export type CoverImageInput = z.infer<typeof CoverImageInputSchema>;
317
- export type DeliveryFileInput = z.infer<typeof DeliveryFileInputSchema>;
318
-
319
261
  export type MarketplaceCategoryOutput = z.infer<
320
262
  typeof MarketplaceCategorySchema
321
263
  >;
@@ -323,21 +265,11 @@ export type GetMarketplaceInfoOutput = z.infer<
323
265
  typeof GetMarketplaceInfoOutputSchema
324
266
  >;
325
267
 
326
- export type ProductCoverImageEntity = z.infer<
327
- typeof ProductCoverImageEntitySchema
328
- >;
329
-
330
- export type ProductDeliveryFileEntity = z.infer<
331
- typeof ProductDeliveryFileEntitySchema
332
- >;
333
268
  export type ProductDiscountEntity = z.infer<typeof ProductDiscountEntitySchema>;
334
-
335
269
  export type CreateProductInputEntity = z.infer<typeof CreateProductInputSchema>;
336
270
  export type ProductServiceAndComplianceInputEntity = z.infer<
337
271
  typeof ProductServiceAndComplianceInputSchema
338
272
  >;
339
273
  export type UpdateProductInputEntity = z.infer<typeof UpdateProductInputSchema>;
340
274
  export type ProductEntity = z.infer<typeof ProductEntitySchema>;
341
-
342
- export type BaseProductEntity = z.infer<typeof BaseProductSchema>;
343
275
  export type ProductSearchDocument = z.infer<typeof ProductSearchDocumentSchema>;