vr-commons 1.0.102 → 1.0.104

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.
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkIsUserBanned = checkIsUserBanned;
4
4
  exports.checkIsUserSuspended = checkIsUserSuspended;
5
5
  exports.checkUserAccountStatus = checkUserAccountStatus;
6
- const account_utils_1 = require("../../utils/account.utils");
7
- const response_utils_1 = require("../../utils/response.utils");
6
+ const account_utils_1 = require("../utils/account.utils");
7
+ const response_utils_1 = require("../utils/response.utils");
8
8
  // Check if user is banned
9
9
  async function checkIsUserBanned(req, res, next) {
10
10
  try {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.checkAdminAuthentication = void 0;
7
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
8
  const vr_models_1 = require("vr-models");
9
- const response_utils_1 = require("../../utils/response.utils");
9
+ const response_utils_1 = require("../utils/response.utils");
10
10
  const checkAdminAuthentication = (allowedRoles) => async (req, res, next) => {
11
11
  try {
12
12
  const token = req.cookies?.access_token;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.checkUserAuthentication = void 0;
7
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
8
  const vr_models_1 = require("vr-models");
9
- const response_utils_1 = require("../../utils/response.utils");
10
- const authTokens_utils_1 = require("../../utils/authTokens.utils");
9
+ const response_utils_1 = require("../utils/response.utils");
10
+ const authTokens_utils_1 = require("../utils/authTokens.utils");
11
11
  const checkUserAuthentication = (allowedRoles) => async (req, res, next) => {
12
12
  try {
13
13
  const authHeader = req.headers.authorization;
@@ -1,3 +1,3 @@
1
- export { checkAdminAuthentication } from "./admin/auth.admin.middlewares";
2
- export { checkUserAuthentication } from "./users/auth.users.middlewares";
3
- export { checkIsUserBanned, checkIsUserSuspended, checkUserAccountStatus, } from "./shared/account.shared.middlewares";
1
+ export { checkAdminAuthentication } from "./auth.admin.middlewares";
2
+ export { checkUserAuthentication } from "./auth.users.middlewares";
3
+ export { checkIsUserBanned, checkIsUserSuspended, checkUserAccountStatus, } from "./account.shared.middlewares";
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkUserAccountStatus = exports.checkIsUserSuspended = exports.checkIsUserBanned = exports.checkUserAuthentication = exports.checkAdminAuthentication = void 0;
4
- var auth_admin_middlewares_1 = require("./admin/auth.admin.middlewares");
4
+ var auth_admin_middlewares_1 = require("./auth.admin.middlewares");
5
5
  Object.defineProperty(exports, "checkAdminAuthentication", { enumerable: true, get: function () { return auth_admin_middlewares_1.checkAdminAuthentication; } });
6
- var auth_users_middlewares_1 = require("./users/auth.users.middlewares");
6
+ var auth_users_middlewares_1 = require("./auth.users.middlewares");
7
7
  Object.defineProperty(exports, "checkUserAuthentication", { enumerable: true, get: function () { return auth_users_middlewares_1.checkUserAuthentication; } });
8
- var account_shared_middlewares_1 = require("./shared/account.shared.middlewares");
8
+ var account_shared_middlewares_1 = require("./account.shared.middlewares");
9
9
  Object.defineProperty(exports, "checkIsUserBanned", { enumerable: true, get: function () { return account_shared_middlewares_1.checkIsUserBanned; } });
10
10
  Object.defineProperty(exports, "checkIsUserSuspended", { enumerable: true, get: function () { return account_shared_middlewares_1.checkIsUserSuspended; } });
11
11
  Object.defineProperty(exports, "checkUserAccountStatus", { enumerable: true, get: function () { return account_shared_middlewares_1.checkUserAccountStatus; } });
@@ -2,33 +2,28 @@ import { z } from "zod";
2
2
  export declare const createProductSchema: z.ZodObject<{
3
3
  body: z.ZodObject<{
4
4
  name: z.ZodString;
5
- stock: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
5
+ stock: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodNumber>>, number, unknown>;
6
6
  description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
7
- isActive: z.ZodOptional<z.ZodBoolean>;
8
7
  }, "strip", z.ZodTypeAny, {
9
8
  name: string;
10
9
  stock: number;
11
- isActive?: boolean | undefined;
12
10
  description?: string | null | undefined;
13
11
  }, {
14
12
  name: string;
15
- isActive?: boolean | undefined;
13
+ stock?: unknown;
16
14
  description?: string | null | undefined;
17
- stock?: number | undefined;
18
15
  }>;
19
16
  }, "strip", z.ZodTypeAny, {
20
17
  body: {
21
18
  name: string;
22
19
  stock: number;
23
- isActive?: boolean | undefined;
24
20
  description?: string | null | undefined;
25
21
  };
26
22
  }, {
27
23
  body: {
28
24
  name: string;
29
- isActive?: boolean | undefined;
25
+ stock?: unknown;
30
26
  description?: string | null | undefined;
31
- stock?: number | undefined;
32
27
  };
33
28
  }>;
34
29
  export declare const updateProductSchema: z.ZodObject<{
@@ -40,41 +35,41 @@ export declare const updateProductSchema: z.ZodObject<{
40
35
  id: string;
41
36
  }>;
42
37
  body: z.ZodObject<{
43
- name: z.ZodOptional<z.ZodString>;
44
- description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
45
- stock: z.ZodOptional<z.ZodNumber>;
46
- isActive: z.ZodOptional<z.ZodBoolean>;
38
+ name: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
39
+ description: z.ZodEffects<z.ZodNullable<z.ZodOptional<z.ZodString>>, string | null | undefined, unknown>;
40
+ stock: z.ZodEffects<z.ZodOptional<z.ZodNumber>, number | undefined, unknown>;
41
+ isActive: z.ZodEffects<z.ZodOptional<z.ZodBoolean>, boolean | undefined, unknown>;
47
42
  }, "strip", z.ZodTypeAny, {
48
- isActive?: boolean | undefined;
49
- description?: string | null | undefined;
50
43
  name?: string | undefined;
51
44
  stock?: number | undefined;
52
- }, {
53
- isActive?: boolean | undefined;
54
45
  description?: string | null | undefined;
55
- name?: string | undefined;
56
- stock?: number | undefined;
46
+ isActive?: boolean | undefined;
47
+ }, {
48
+ name?: unknown;
49
+ stock?: unknown;
50
+ description?: unknown;
51
+ isActive?: unknown;
57
52
  }>;
58
53
  }, "strip", z.ZodTypeAny, {
59
- body: {
60
- isActive?: boolean | undefined;
61
- description?: string | null | undefined;
62
- name?: string | undefined;
63
- stock?: number | undefined;
64
- };
65
54
  params: {
66
55
  id: string;
67
56
  };
68
- }, {
69
57
  body: {
70
- isActive?: boolean | undefined;
71
- description?: string | null | undefined;
72
58
  name?: string | undefined;
73
59
  stock?: number | undefined;
60
+ description?: string | null | undefined;
61
+ isActive?: boolean | undefined;
74
62
  };
63
+ }, {
75
64
  params: {
76
65
  id: string;
77
66
  };
67
+ body: {
68
+ name?: unknown;
69
+ stock?: unknown;
70
+ description?: unknown;
71
+ isActive?: unknown;
72
+ };
78
73
  }>;
79
74
  export declare const getProductSchema: z.ZodObject<{
80
75
  params: z.ZodObject<{
@@ -103,41 +98,41 @@ export declare const getProductsSchema: z.ZodObject<{
103
98
  sortBy: z.ZodOptional<z.ZodEnum<["name", "stock", "createdAt", "updatedAt"]>>;
104
99
  sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
105
100
  }, "strip", z.ZodTypeAny, {
106
- search?: string | undefined;
107
- limit?: number | undefined;
108
101
  isActive?: "true" | "false" | undefined;
109
102
  page?: number | undefined;
110
- sortBy?: "createdAt" | "updatedAt" | "name" | "stock" | undefined;
111
- sortOrder?: "DESC" | "ASC" | undefined;
103
+ limit?: number | undefined;
104
+ search?: string | undefined;
112
105
  minStock?: number | undefined;
106
+ sortBy?: "name" | "stock" | "createdAt" | "updatedAt" | undefined;
107
+ sortOrder?: "ASC" | "DESC" | undefined;
113
108
  }, {
114
- search?: string | undefined;
115
- limit?: string | undefined;
116
109
  isActive?: "true" | "false" | undefined;
117
110
  page?: string | undefined;
118
- sortBy?: "createdAt" | "updatedAt" | "name" | "stock" | undefined;
119
- sortOrder?: "DESC" | "ASC" | undefined;
111
+ limit?: string | undefined;
112
+ search?: string | undefined;
120
113
  minStock?: string | undefined;
114
+ sortBy?: "name" | "stock" | "createdAt" | "updatedAt" | undefined;
115
+ sortOrder?: "ASC" | "DESC" | undefined;
121
116
  }>;
122
117
  }, "strip", z.ZodTypeAny, {
123
118
  query: {
124
- search?: string | undefined;
125
- limit?: number | undefined;
126
119
  isActive?: "true" | "false" | undefined;
127
120
  page?: number | undefined;
128
- sortBy?: "createdAt" | "updatedAt" | "name" | "stock" | undefined;
129
- sortOrder?: "DESC" | "ASC" | undefined;
121
+ limit?: number | undefined;
122
+ search?: string | undefined;
130
123
  minStock?: number | undefined;
124
+ sortBy?: "name" | "stock" | "createdAt" | "updatedAt" | undefined;
125
+ sortOrder?: "ASC" | "DESC" | undefined;
131
126
  };
132
127
  }, {
133
128
  query: {
134
- search?: string | undefined;
135
- limit?: string | undefined;
136
129
  isActive?: "true" | "false" | undefined;
137
130
  page?: string | undefined;
138
- sortBy?: "createdAt" | "updatedAt" | "name" | "stock" | undefined;
139
- sortOrder?: "DESC" | "ASC" | undefined;
131
+ limit?: string | undefined;
132
+ search?: string | undefined;
140
133
  minStock?: string | undefined;
134
+ sortBy?: "name" | "stock" | "createdAt" | "updatedAt" | undefined;
135
+ sortOrder?: "ASC" | "DESC" | undefined;
141
136
  };
142
137
  }>;
143
138
  export declare const deleteProductSchema: z.ZodObject<{
@@ -203,26 +198,26 @@ export declare const updateStockSchema: z.ZodObject<{
203
198
  operation: z.ZodEnum<["increment", "decrement", "set"]>;
204
199
  amount: z.ZodNumber;
205
200
  }, "strip", z.ZodTypeAny, {
201
+ operation: "set" | "increment" | "decrement";
206
202
  amount: number;
207
- operation: "increment" | "decrement" | "set";
208
203
  }, {
204
+ operation: "set" | "increment" | "decrement";
209
205
  amount: number;
210
- operation: "increment" | "decrement" | "set";
211
206
  }>;
212
207
  }, "strip", z.ZodTypeAny, {
213
- body: {
214
- amount: number;
215
- operation: "increment" | "decrement" | "set";
216
- };
217
208
  params: {
218
209
  id: string;
219
210
  };
220
- }, {
221
211
  body: {
212
+ operation: "set" | "increment" | "decrement";
222
213
  amount: number;
223
- operation: "increment" | "decrement" | "set";
224
214
  };
215
+ }, {
225
216
  params: {
226
217
  id: string;
227
218
  };
219
+ body: {
220
+ operation: "set" | "increment" | "decrement";
221
+ amount: number;
222
+ };
228
223
  }>;
@@ -12,24 +12,25 @@ const productBaseSchema = {
12
12
  stock: zod_1.z.number().int().min(0, "Stock cannot be negative").optional(),
13
13
  isActive: zod_1.z.boolean().optional(),
14
14
  };
15
- // Create product schema
15
+ // Update product schema to handle FormData strings
16
16
  exports.createProductSchema = zod_1.z.object({
17
17
  body: zod_1.z.object({
18
- ...productBaseSchema,
19
- name: productBaseSchema.name, // Required for create
20
- stock: productBaseSchema.stock.default(1),
18
+ name: productBaseSchema.name,
19
+ stock: zod_1.z.preprocess((val) => (val ? Number(val) : 1), productBaseSchema.stock.default(1)),
20
+ description: productBaseSchema.description,
21
+ // image is handled by multer, not in validation
21
22
  }),
22
23
  });
23
- // Update product schema
24
+ // Update product schema to handle FormData strings
24
25
  exports.updateProductSchema = zod_1.z.object({
25
26
  params: zod_1.z.object({
26
27
  id: zod_1.z.string().uuid("Invalid product ID"),
27
28
  }),
28
29
  body: zod_1.z.object({
29
- name: productBaseSchema.name.optional(),
30
- description: productBaseSchema.description,
31
- stock: productBaseSchema.stock,
32
- isActive: productBaseSchema.isActive,
30
+ name: zod_1.z.preprocess((val) => (val === "" ? undefined : val), productBaseSchema.name.optional()),
31
+ description: zod_1.z.preprocess((val) => (val === "" ? null : val), productBaseSchema.description),
32
+ stock: zod_1.z.preprocess((val) => (val ? Number(val) : undefined), productBaseSchema.stock),
33
+ isActive: zod_1.z.preprocess((val) => (val === "true" ? true : val === "false" ? false : undefined), productBaseSchema.isActive),
33
34
  }),
34
35
  });
35
36
  // Get product by ID schema
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.102",
3
+ "version": "1.0.104",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",