@meerkapp/wms-contracts 0.3.0-beta.1 → 0.3.0-beta.3

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.
package/dist/index.js CHANGED
@@ -10477,7 +10477,6 @@ var NumberCharacteristicSchema = z882.object({
10477
10477
  label: z882.string().min(1),
10478
10478
  type: z882.literal("number"),
10479
10479
  required: z882.boolean().default(false),
10480
- sku_dependent: z882.boolean().default(false),
10481
10480
  validation: z882.object({
10482
10481
  min: z882.number().optional(),
10483
10482
  max: z882.number().optional()
@@ -10495,47 +10494,64 @@ var SelectCharacteristicSchema = z882.object({
10495
10494
  label: z882.string().min(1),
10496
10495
  type: z882.literal("select"),
10497
10496
  required: z882.boolean().default(false),
10498
- sku_dependent: z882.boolean().default(false),
10499
10497
  options: z882.array(SelectOptionSchema).min(1)
10500
10498
  });
10499
+ var ToggleCharacteristicSchema = z882.object({
10500
+ key: z882.string().min(1),
10501
+ label: z882.string().min(1),
10502
+ type: z882.literal("toggle"),
10503
+ required: z882.boolean().default(false),
10504
+ true_label: z882.string().min(1),
10505
+ false_label: z882.string().min(1)
10506
+ });
10507
+ var CheckboxCharacteristicSchema = z882.object({
10508
+ key: z882.string().min(1),
10509
+ label: z882.string().min(1),
10510
+ type: z882.literal("checkbox"),
10511
+ required: z882.boolean().default(false)
10512
+ });
10501
10513
  var CharacteristicSchema = z882.discriminatedUnion("type", [
10502
10514
  NumberCharacteristicSchema,
10503
- SelectCharacteristicSchema
10515
+ SelectCharacteristicSchema,
10516
+ ToggleCharacteristicSchema,
10517
+ CheckboxCharacteristicSchema
10504
10518
  ]);
10505
10519
  var CharacteristicsSchemeSchema = z882.array(CharacteristicSchema);
10506
- var SKU_TEMPLATE_REGEX = /^(\{(brand|type|counter)(?::\d+)?\}|\{[a-z_]+(?::\d+)?\}|[^{}]+)+$/;
10520
+ var SKU_TEMPLATE_REGEX = /^(\{(brand|counter)(?::\d+)?\}|\{[a-z_]+(?::\d+)?\}|[^{}]+)+$/;
10521
+ var RESERVED_SKU_KEYS = /* @__PURE__ */ new Set(["brand", "counter"]);
10522
+ var SKU_COMPATIBLE_TYPES = /* @__PURE__ */ new Set(["number", "select", "toggle"]);
10523
+ function validateSkuTemplate(data) {
10524
+ if (data.skuMode !== "CUSTOM" || !data.skuTemplate || !data.characteristicsScheme) return true;
10525
+ const skuCompatibleKeys = new Set(
10526
+ data.characteristicsScheme.filter((c) => c.required && SKU_COMPATIBLE_TYPES.has(c.type)).map((c) => c.key)
10527
+ );
10528
+ const templateKeys = [...data.skuTemplate.matchAll(/\{([a-z_]+)(?::\d+)?\}/g)].map(([, key]) => key).filter((key) => !RESERVED_SKU_KEYS.has(key));
10529
+ return templateKeys.every((key) => skuCompatibleKeys.has(key));
10530
+ }
10507
10531
  var ProductTypeBaseSchema = z882.object({
10508
10532
  name: z882.string().min(1),
10509
- code: z882.string().min(1).max(10).regex(/^[A-ZА-ЯЁ0-9]+$/, "Code must be uppercase letters and digits"),
10510
10533
  defaultWriteoffStrategy: z882.enum(["FIFO", "LIFO", "FEFO", "MANUAL"]).default("FIFO"),
10511
10534
  skuMode: z882.enum(["GLOBAL", "CUSTOM"]).default("GLOBAL"),
10512
- skuTemplate: z882.string().regex(SKU_TEMPLATE_REGEX).optional().nullable(),
10535
+ skuTemplate: z882.string().regex(SKU_TEMPLATE_REGEX, "Invalid SKU template format").optional().nullable(),
10513
10536
  characteristicsScheme: CharacteristicsSchemeSchema.optional().nullable()
10514
10537
  });
10515
- function refineCustomSkuTemplate(data) {
10516
- if (data.skuMode !== "CUSTOM" || !data.skuTemplate || !data.characteristicsScheme) return true;
10517
- const schemeKeys = new Set(data.characteristicsScheme.map((c) => c.key));
10518
- const templateKeys = [...data.skuTemplate.matchAll(/\{([a-z_]+)(?::\d+)?\}/g)].map(([, key]) => key).filter((key) => !["brand", "type", "counter"].includes(key));
10519
- return templateKeys.every((key) => schemeKeys.has(key));
10520
- }
10521
10538
  var CreateProductTypeSchema = ProductTypeBaseSchema.refine(
10522
10539
  (data) => !(data.skuMode === "CUSTOM" && !data.skuTemplate),
10523
10540
  { message: "skuTemplate is required for CUSTOM sku mode", path: ["skuTemplate"] }
10524
- ).refine(refineCustomSkuTemplate, {
10525
- message: "All characteristic keys in skuTemplate must exist in characteristicsScheme",
10541
+ ).refine(validateSkuTemplate, {
10542
+ message: "All keys in skuTemplate must be required characteristics of type number, select or toggle",
10526
10543
  path: ["skuTemplate"]
10527
10544
  });
10528
10545
  var UpdateProductTypeSchema = ProductTypeBaseSchema.partial().refine(
10529
10546
  (data) => !(data.skuMode === "CUSTOM" && data.skuTemplate === null),
10530
10547
  { message: "skuTemplate cannot be null for CUSTOM sku mode", path: ["skuTemplate"] }
10531
- ).refine(refineCustomSkuTemplate, {
10532
- message: "All characteristic keys in skuTemplate must exist in characteristicsScheme",
10548
+ ).refine(validateSkuTemplate, {
10549
+ message: "All keys in skuTemplate must be required characteristics of type number, select or toggle",
10533
10550
  path: ["skuTemplate"]
10534
10551
  });
10535
10552
  var ProductTypeSchema = z882.object({
10536
10553
  id: z882.number(),
10537
10554
  name: z882.string(),
10538
- code: z882.string(),
10539
10555
  defaultWriteoffStrategy: z882.enum(["FIFO", "LIFO", "FEFO", "MANUAL"]),
10540
10556
  skuMode: z882.enum(["GLOBAL", "CUSTOM"]),
10541
10557
  skuTemplate: z882.string().nullable(),