vr-commons 1.0.141 → 1.0.142

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.
@@ -56,4 +56,14 @@ export declare const stockUtil: {
56
56
  transaction?: Transaction;
57
57
  actorId?: string;
58
58
  }): Promise<StockChangeResult>;
59
+ /**
60
+ * Generate serial number from pair ID and dedication
61
+ * Format: VIBERIDE-{RIDER|PASSENGER}-{pairId}
62
+ */
63
+ generateSerialNumber(pairId: string, dedication: string): Promise<string>;
64
+ /**
65
+ * Validate pair ID format
66
+ * No letter 'O' to avoid confusion with 0
67
+ */
68
+ validatePairIdFormat(pairId: string): Promise<boolean>;
59
69
  };
@@ -4,6 +4,7 @@ exports.stockUtil = void 0;
4
4
  // src/utils/stock.util.ts
5
5
  const vr_models_1 = require("vr-models");
6
6
  const eventLog_utils_1 = require("./eventLog.utils");
7
+ const admin_devices_validations_1 = require("vr-commons/validations/admin.devices.validations");
7
8
  exports.stockUtil = {
8
9
  /**
9
10
  * Increment stock when devices are added/created
@@ -228,4 +229,18 @@ exports.stockUtil = {
228
229
  actorType: actorType,
229
230
  });
230
231
  },
232
+ /**
233
+ * Generate serial number from pair ID and dedication
234
+ * Format: VIBERIDE-{RIDER|PASSENGER}-{pairId}
235
+ */
236
+ async generateSerialNumber(pairId, dedication) {
237
+ return `VIBERIDE-${dedication}-${pairId}`;
238
+ },
239
+ /**
240
+ * Validate pair ID format
241
+ * No letter 'O' to avoid confusion with 0
242
+ */
243
+ async validatePairIdFormat(pairId) {
244
+ return admin_devices_validations_1.PAIR_ID_REGEX.test(pairId);
245
+ },
231
246
  };
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ export declare const PAIR_ID_REGEX: RegExp;
3
+ export declare const validateUniquePairIds: (pairIds: string[]) => boolean;
2
4
  export declare const createDevicePairsSchema: z.ZodEffects<z.ZodObject<{
3
5
  body: z.ZodObject<{
4
6
  productId: z.ZodString;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAvailabilitySchema = exports.makePermanentSchema = exports.disableDeviceSchema = exports.adminUnlockDeviceSchema = exports.adminLockDeviceSchema = exports.deleteDeviceSchema = exports.getDevicesSchema = exports.getDeviceSchema = exports.updateDeviceSchema = exports.createDevicePairsSchema = void 0;
3
+ exports.checkAvailabilitySchema = exports.makePermanentSchema = exports.disableDeviceSchema = exports.adminUnlockDeviceSchema = exports.adminLockDeviceSchema = exports.deleteDeviceSchema = exports.getDevicesSchema = exports.getDeviceSchema = exports.updateDeviceSchema = exports.createDevicePairsSchema = exports.validateUniquePairIds = exports.PAIR_ID_REGEX = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const vr_models_1 = require("vr-models");
6
6
  // Constants
@@ -19,20 +19,21 @@ const deviceBaseSchema = {
19
19
  // ✅ Pair ID format: 2 letters + 3 numbers + 1 letter
20
20
  // Example: AA001A, AB123B, XZ999Z
21
21
  // No letter 'O' to avoid confusion with 0
22
- const PAIR_ID_REGEX = /^[A-NP-Z]{2}[0-9]{3}[A-NP-Z]{1}$/;
22
+ exports.PAIR_ID_REGEX = /^[A-NP-Z]{2}[0-9]{3}[A-NP-Z]{1}$/;
23
23
  const PAIR_ID_ERROR = "Pair ID must be 6 characters: 2 letters (A-Z, excluding O) + 3 digits + 1 letter (A-Z, excluding O). Example: AA001A";
24
24
  // ✅ Helper to validate pair IDs are unique in body
25
25
  const validateUniquePairIds = (pairIds) => {
26
26
  const unique = new Set(pairIds);
27
27
  return unique.size === pairIds.length;
28
28
  };
29
+ exports.validateUniquePairIds = validateUniquePairIds;
29
30
  // ✅ ONLY bulk create - no single device creation
30
31
  exports.createDevicePairsSchema = zod_1.z
31
32
  .object({
32
33
  body: zod_1.z.object({
33
34
  productId: zod_1.z.string().uuid("Invalid product ID"),
34
35
  pairIds: zod_1.z
35
- .array(zod_1.z.string().regex(PAIR_ID_REGEX, PAIR_ID_ERROR))
36
+ .array(zod_1.z.string().regex(exports.PAIR_ID_REGEX, PAIR_ID_ERROR))
36
37
  .min(1, "At least one pair ID required")
37
38
  .max(50, "Cannot create more than 50 pairs at once"),
38
39
  }),
@@ -40,7 +41,7 @@ exports.createDevicePairsSchema = zod_1.z
40
41
  .superRefine((data, ctx) => {
41
42
  const { pairIds } = data.body;
42
43
  // ✅ Ensure no duplicate pair IDs in the request body
43
- if (!validateUniquePairIds(pairIds)) {
44
+ if (!(0, exports.validateUniquePairIds)(pairIds)) {
44
45
  ctx.addIssue({
45
46
  code: zod_1.z.ZodIssueCode.custom,
46
47
  message: `Duplicate pair IDs found. Please ensure all pair IDs are unique.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.141",
3
+ "version": "1.0.142",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",