@zauru-sdk/common 6.6.0 → 6.7.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [6.7.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.6.0...@zauru-sdk/common@6.7.0) (2026-09-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * registrar reglas automáticas de % rechazo en el historial ([4784849](https://github.com/intuitiva/zauru-typescript-sdk/commit/4784849904f9ac6570e60543895a858dece8e039))
12
+
13
+
14
+
15
+
16
+
6
17
  # [6.6.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.5.0...@zauru-sdk/common@6.6.0) (2026-09-14)
7
18
 
8
19
 
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyRejectionPercentageAdjustmentRules = exports.resolveRejectionPercentageOrigin = exports.formatRejectionPercentageAdjustmentDescription = exports.rejectionPercentageAdjustmentRuleMatches = exports.filterActiveRejectionPercentageAdjustmentRules = exports.REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR = void 0;
3
+ exports.applyRejectionPercentageAdjustmentRules = exports.isAutomaticRejectionRuleHistoryType = exports.formatAutomaticRejectionRuleHistoryDescription = exports.getNewlyAppliedRejectionRuleSteps = exports.rejectionRuleStepKey = exports.resolveRejectionPercentageOrigin = exports.formatRejectionPercentageAdjustmentDescription = exports.rejectionPercentageAdjustmentRuleMatches = exports.filterActiveRejectionPercentageAdjustmentRules = exports.REJECTION_PERCENTAGE_RULE_HISTORY_TYPE = exports.REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR = void 0;
4
4
  exports.REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR = "rejection_percentage_adjustment_rules_web_app_table_id";
5
+ exports.REJECTION_PERCENTAGE_RULE_HISTORY_TYPE = "rechazo_regla_automatica";
5
6
  const defaultFilters = () => ({
6
7
  itemMode: "all",
7
8
  itemIds: [],
@@ -91,6 +92,27 @@ const resolveRejectionPercentageOrigin = (passedPercentage, previousCalculations
91
92
  return clampPercentage(safePreviousBase + (passed - previousFinal));
92
93
  };
93
94
  exports.resolveRejectionPercentageOrigin = resolveRejectionPercentageOrigin;
95
+ const rejectionRuleStepKey = (step) => `${step.ruleName}|${step.operation}|${step.value}`;
96
+ exports.rejectionRuleStepKey = rejectionRuleStepKey;
97
+ /**
98
+ * Rules already stored in the memo are skipped so a later edit does not
99
+ * create a second history line (or a second +2%) for the same rule.
100
+ */
101
+ const getNewlyAppliedRejectionRuleSteps = (previous, next) => {
102
+ if (!next?.steps?.length) {
103
+ return [];
104
+ }
105
+ const previousKeys = new Set((previous?.steps ?? []).map(exports.rejectionRuleStepKey));
106
+ return next.steps.filter((step) => !previousKeys.has((0, exports.rejectionRuleStepKey)(step)));
107
+ };
108
+ exports.getNewlyAppliedRejectionRuleSteps = getNewlyAppliedRejectionRuleSteps;
109
+ const formatAutomaticRejectionRuleHistoryDescription = (step) => {
110
+ const sign = step.operation === "subtract" ? "-" : "+";
111
+ return `% Rechazo aplicado automáticamente por regla "${step.ruleName}": ${sign}${formatPercentage(step.value)}%.`;
112
+ };
113
+ exports.formatAutomaticRejectionRuleHistoryDescription = formatAutomaticRejectionRuleHistoryDescription;
114
+ const isAutomaticRejectionRuleHistoryType = (type) => type === exports.REJECTION_PERCENTAGE_RULE_HISTORY_TYPE;
115
+ exports.isAutomaticRejectionRuleHistoryType = isAutomaticRejectionRuleHistoryType;
94
116
  const applyRejectionPercentageAdjustmentRules = (basePercentage, rules, ctx) => {
95
117
  const start = Number(basePercentage);
96
118
  const safeBase = Number.isFinite(start) ? clampPercentage(start) : 0;
@@ -1,5 +1,6 @@
1
- import type { RejectionCalculationMemo, RejectionPercentageAdjustmentContext, RejectionPercentageAdjustmentResult, RejectionPercentageAdjustmentRule, WebAppRowGraphQL } from "@zauru-sdk/types";
1
+ import type { RejectionCalculationMemo, RejectionPercentageAdjustmentContext, RejectionPercentageAdjustmentResult, RejectionPercentageAdjustmentRule, RejectionPercentageAdjustmentStep, WebAppRowGraphQL } from "@zauru-sdk/types";
2
2
  export declare const REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR = "rejection_percentage_adjustment_rules_web_app_table_id";
3
+ export declare const REJECTION_PERCENTAGE_RULE_HISTORY_TYPE: "rechazo_regla_automatica";
3
4
  export declare const filterActiveRejectionPercentageAdjustmentRules: (rules?: WebAppRowGraphQL<RejectionPercentageAdjustmentRule>[]) => WebAppRowGraphQL<RejectionPercentageAdjustmentRule>[];
4
5
  export declare const rejectionPercentageAdjustmentRuleMatches: (rule: RejectionPercentageAdjustmentRule, ctx: RejectionPercentageAdjustmentContext) => boolean;
5
6
  export declare const formatRejectionPercentageAdjustmentDescription: (result: Pick<RejectionPercentageAdjustmentResult, "basePercentage" | "finalPercentage" | "steps">, baseLabel?: string) => string;
@@ -8,4 +9,12 @@ export declare const formatRejectionPercentageAdjustmentDescription: (result: Pi
8
9
  * previous calculations we go back to the origin so the rules never stack twice.
9
10
  */
10
11
  export declare const resolveRejectionPercentageOrigin: (passedPercentage: number, previousCalculations?: RejectionCalculationMemo | null) => number;
12
+ export declare const rejectionRuleStepKey: (step: Pick<RejectionPercentageAdjustmentStep, "ruleName" | "operation" | "value">) => string;
13
+ /**
14
+ * Rules already stored in the memo are skipped so a later edit does not
15
+ * create a second history line (or a second +2%) for the same rule.
16
+ */
17
+ export declare const getNewlyAppliedRejectionRuleSteps: (previous?: RejectionCalculationMemo | null, next?: RejectionCalculationMemo | null) => RejectionPercentageAdjustmentStep[];
18
+ export declare const formatAutomaticRejectionRuleHistoryDescription: (step: RejectionPercentageAdjustmentStep) => string;
19
+ export declare const isAutomaticRejectionRuleHistoryType: (type: string | undefined) => boolean;
11
20
  export declare const applyRejectionPercentageAdjustmentRules: (basePercentage: number, rules: Array<RejectionPercentageAdjustmentRule | WebAppRowGraphQL<RejectionPercentageAdjustmentRule>>, ctx: RejectionPercentageAdjustmentContext) => RejectionPercentageAdjustmentResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/common",
3
- "version": "6.6.0",
3
+ "version": "6.7.0",
4
4
  "description": "Funciones de uso común en el desarrollo de webapps en Zauru",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -21,9 +21,9 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@remix-run/node": "^2.8.1",
24
- "@zauru-sdk/types": "^6.16.0",
24
+ "@zauru-sdk/types": "^6.17.0",
25
25
  "moment": "^2.30.1",
26
26
  "moment-timezone": "^0.5.45"
27
27
  },
28
- "gitHead": "9e840d01a540f2ab49233dda2cb2b0c916ffba0b"
28
+ "gitHead": "d3483aa3b55a9a692f955e6a56d13f33b70db1c4"
29
29
  }
@@ -12,6 +12,9 @@ import type {
12
12
  export const REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR =
13
13
  "rejection_percentage_adjustment_rules_web_app_table_id";
14
14
 
15
+ export const REJECTION_PERCENTAGE_RULE_HISTORY_TYPE =
16
+ "rechazo_regla_automatica" as const;
17
+
15
18
  const defaultFilters = (): PriceAdjustmentFilters => ({
16
19
  itemMode: "all",
17
20
  itemIds: [],
@@ -162,6 +165,43 @@ export const resolveRejectionPercentageOrigin = (
162
165
  return clampPercentage(safePreviousBase + (passed - previousFinal));
163
166
  };
164
167
 
168
+ export const rejectionRuleStepKey = (
169
+ step: Pick<
170
+ RejectionPercentageAdjustmentStep,
171
+ "ruleName" | "operation" | "value"
172
+ >,
173
+ ): string => `${step.ruleName}|${step.operation}|${step.value}`;
174
+
175
+ /**
176
+ * Rules already stored in the memo are skipped so a later edit does not
177
+ * create a second history line (or a second +2%) for the same rule.
178
+ */
179
+ export const getNewlyAppliedRejectionRuleSteps = (
180
+ previous?: RejectionCalculationMemo | null,
181
+ next?: RejectionCalculationMemo | null,
182
+ ): RejectionPercentageAdjustmentStep[] => {
183
+ if (!next?.steps?.length) {
184
+ return [];
185
+ }
186
+ const previousKeys = new Set(
187
+ (previous?.steps ?? []).map(rejectionRuleStepKey),
188
+ );
189
+ return next.steps.filter(
190
+ (step) => !previousKeys.has(rejectionRuleStepKey(step)),
191
+ );
192
+ };
193
+
194
+ export const formatAutomaticRejectionRuleHistoryDescription = (
195
+ step: RejectionPercentageAdjustmentStep,
196
+ ): string => {
197
+ const sign = step.operation === "subtract" ? "-" : "+";
198
+ return `% Rechazo aplicado automáticamente por regla "${step.ruleName}": ${sign}${formatPercentage(step.value)}%.`;
199
+ };
200
+
201
+ export const isAutomaticRejectionRuleHistoryType = (
202
+ type: string | undefined,
203
+ ): boolean => type === REJECTION_PERCENTAGE_RULE_HISTORY_TYPE;
204
+
165
205
  export const applyRejectionPercentageAdjustmentRules = (
166
206
  basePercentage: number,
167
207
  rules: Array<