@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.cjs CHANGED
@@ -12172,7 +12172,6 @@ var NumberCharacteristicSchema = import_zod9.z.object({
12172
12172
  label: import_zod9.z.string().min(1),
12173
12173
  type: import_zod9.z.literal("number"),
12174
12174
  required: import_zod9.z.boolean().default(false),
12175
- sku_dependent: import_zod9.z.boolean().default(false),
12176
12175
  validation: import_zod9.z.object({
12177
12176
  min: import_zod9.z.number().optional(),
12178
12177
  max: import_zod9.z.number().optional()
@@ -12190,47 +12189,64 @@ var SelectCharacteristicSchema = import_zod9.z.object({
12190
12189
  label: import_zod9.z.string().min(1),
12191
12190
  type: import_zod9.z.literal("select"),
12192
12191
  required: import_zod9.z.boolean().default(false),
12193
- sku_dependent: import_zod9.z.boolean().default(false),
12194
12192
  options: import_zod9.z.array(SelectOptionSchema).min(1)
12195
12193
  });
12194
+ var ToggleCharacteristicSchema = import_zod9.z.object({
12195
+ key: import_zod9.z.string().min(1),
12196
+ label: import_zod9.z.string().min(1),
12197
+ type: import_zod9.z.literal("toggle"),
12198
+ required: import_zod9.z.boolean().default(false),
12199
+ true_label: import_zod9.z.string().min(1),
12200
+ false_label: import_zod9.z.string().min(1)
12201
+ });
12202
+ var CheckboxCharacteristicSchema = import_zod9.z.object({
12203
+ key: import_zod9.z.string().min(1),
12204
+ label: import_zod9.z.string().min(1),
12205
+ type: import_zod9.z.literal("checkbox"),
12206
+ required: import_zod9.z.boolean().default(false)
12207
+ });
12196
12208
  var CharacteristicSchema = import_zod9.z.discriminatedUnion("type", [
12197
12209
  NumberCharacteristicSchema,
12198
- SelectCharacteristicSchema
12210
+ SelectCharacteristicSchema,
12211
+ ToggleCharacteristicSchema,
12212
+ CheckboxCharacteristicSchema
12199
12213
  ]);
12200
12214
  var CharacteristicsSchemeSchema = import_zod9.z.array(CharacteristicSchema);
12201
- var SKU_TEMPLATE_REGEX = /^(\{(brand|type|counter)(?::\d+)?\}|\{[a-z_]+(?::\d+)?\}|[^{}]+)+$/;
12215
+ var SKU_TEMPLATE_REGEX = /^(\{(brand|counter)(?::\d+)?\}|\{[a-z_]+(?::\d+)?\}|[^{}]+)+$/;
12216
+ var RESERVED_SKU_KEYS = /* @__PURE__ */ new Set(["brand", "counter"]);
12217
+ var SKU_COMPATIBLE_TYPES = /* @__PURE__ */ new Set(["number", "select", "toggle"]);
12218
+ function validateSkuTemplate(data) {
12219
+ if (data.skuMode !== "CUSTOM" || !data.skuTemplate || !data.characteristicsScheme) return true;
12220
+ const skuCompatibleKeys = new Set(
12221
+ data.characteristicsScheme.filter((c) => c.required && SKU_COMPATIBLE_TYPES.has(c.type)).map((c) => c.key)
12222
+ );
12223
+ const templateKeys = [...data.skuTemplate.matchAll(/\{([a-z_]+)(?::\d+)?\}/g)].map(([, key]) => key).filter((key) => !RESERVED_SKU_KEYS.has(key));
12224
+ return templateKeys.every((key) => skuCompatibleKeys.has(key));
12225
+ }
12202
12226
  var ProductTypeBaseSchema = import_zod9.z.object({
12203
12227
  name: import_zod9.z.string().min(1),
12204
- code: import_zod9.z.string().min(1).max(10).regex(/^[A-ZА-ЯЁ0-9]+$/, "Code must be uppercase letters and digits"),
12205
12228
  defaultWriteoffStrategy: import_zod9.z.enum(["FIFO", "LIFO", "FEFO", "MANUAL"]).default("FIFO"),
12206
12229
  skuMode: import_zod9.z.enum(["GLOBAL", "CUSTOM"]).default("GLOBAL"),
12207
- skuTemplate: import_zod9.z.string().regex(SKU_TEMPLATE_REGEX).optional().nullable(),
12230
+ skuTemplate: import_zod9.z.string().regex(SKU_TEMPLATE_REGEX, "Invalid SKU template format").optional().nullable(),
12208
12231
  characteristicsScheme: CharacteristicsSchemeSchema.optional().nullable()
12209
12232
  });
12210
- function refineCustomSkuTemplate(data) {
12211
- if (data.skuMode !== "CUSTOM" || !data.skuTemplate || !data.characteristicsScheme) return true;
12212
- const schemeKeys = new Set(data.characteristicsScheme.map((c) => c.key));
12213
- const templateKeys = [...data.skuTemplate.matchAll(/\{([a-z_]+)(?::\d+)?\}/g)].map(([, key]) => key).filter((key) => !["brand", "type", "counter"].includes(key));
12214
- return templateKeys.every((key) => schemeKeys.has(key));
12215
- }
12216
12233
  var CreateProductTypeSchema = ProductTypeBaseSchema.refine(
12217
12234
  (data) => !(data.skuMode === "CUSTOM" && !data.skuTemplate),
12218
12235
  { message: "skuTemplate is required for CUSTOM sku mode", path: ["skuTemplate"] }
12219
- ).refine(refineCustomSkuTemplate, {
12220
- message: "All characteristic keys in skuTemplate must exist in characteristicsScheme",
12236
+ ).refine(validateSkuTemplate, {
12237
+ message: "All keys in skuTemplate must be required characteristics of type number, select or toggle",
12221
12238
  path: ["skuTemplate"]
12222
12239
  });
12223
12240
  var UpdateProductTypeSchema = ProductTypeBaseSchema.partial().refine(
12224
12241
  (data) => !(data.skuMode === "CUSTOM" && data.skuTemplate === null),
12225
12242
  { message: "skuTemplate cannot be null for CUSTOM sku mode", path: ["skuTemplate"] }
12226
- ).refine(refineCustomSkuTemplate, {
12227
- message: "All characteristic keys in skuTemplate must exist in characteristicsScheme",
12243
+ ).refine(validateSkuTemplate, {
12244
+ message: "All keys in skuTemplate must be required characteristics of type number, select or toggle",
12228
12245
  path: ["skuTemplate"]
12229
12246
  });
12230
12247
  var ProductTypeSchema = import_zod9.z.object({
12231
12248
  id: import_zod9.z.number(),
12232
12249
  name: import_zod9.z.string(),
12233
- code: import_zod9.z.string(),
12234
12250
  defaultWriteoffStrategy: import_zod9.z.enum(["FIFO", "LIFO", "FEFO", "MANUAL"]),
12235
12251
  skuMode: import_zod9.z.enum(["GLOBAL", "CUSTOM"]),
12236
12252
  skuTemplate: import_zod9.z.string().nullable(),