@fire-spark/core 0.3.3 → 0.3.4

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -13
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -7083,15 +7083,13 @@ const orderTotal = (condition, total) => {
7083
7083
  };
7084
7084
  //#endregion
7085
7085
  //#region src/rules/customMatcher.ts
7086
- const MULTI_CUSTOM_TYPES = [
7087
- "Fulfillments",
7088
- "Stores",
7089
- "Channels",
7090
- "Brands",
7091
- "Payments"
7086
+ const MULTI_OPERATORS = [
7087
+ "is any of",
7088
+ "is none of",
7089
+ "is all of"
7092
7090
  ];
7093
- const isMultiCustomType = (type) => {
7094
- return MULTI_CUSTOM_TYPES.includes(type);
7091
+ const isMultiOperator = (operator) => {
7092
+ return MULTI_OPERATORS.includes(operator);
7095
7093
  };
7096
7094
  const splitCsv = (value) => {
7097
7095
  return value.split(",").map((part) => part.trim()).filter(Boolean);
@@ -7114,15 +7112,25 @@ const matchCustomMulti = (condition, matcher) => {
7114
7112
  assert(typeof value === "string", "Invalid custom value");
7115
7113
  const allowed = splitCsv(value);
7116
7114
  if (allowed.length === 0) return false;
7117
- const candidates = [matcher];
7115
+ const candidates = typeof matcher === "object" ? matcher : [matcher];
7116
+ if (candidates.length === 0) return false;
7118
7117
  if (operator === "is any of") return allowed.some((id) => candidates.includes(id));
7119
7118
  if (operator === "is none of") return !allowed.some((id) => candidates.includes(id));
7120
7119
  if (operator === "is all of") return allowed.every((id) => candidates.includes(id));
7121
7120
  throw new Error(`Operator ${operator} not supported in custom matcher`);
7122
7121
  };
7122
+ /**
7123
+ * The operator picks the arity: `Payment` is single-select in order rules and
7124
+ * multi-select in fulfillment workflows. `matcher` may be a set (one id per
7125
+ * tender): `is` matches when some id matches, `is not` when none does.
7126
+ */
7123
7127
  const matchCustom = (condition, matcher) => {
7124
- if (isMultiCustomType(condition.type)) return matchCustomMulti(condition, matcher);
7125
- return matchCustomEquality(condition, matcher);
7128
+ if (isMultiOperator(condition.operator)) return matchCustomMulti(condition, matcher);
7129
+ if (typeof matcher === "undefined" || typeof matcher === "string") return matchCustomEquality(condition, matcher);
7130
+ if (matcher.length === 0) return false;
7131
+ const matches = (id) => matchCustomEquality(condition, id);
7132
+ if (condition.operator === "is not") return matcher.every(matches);
7133
+ return matcher.some(matches);
7126
7134
  };
7127
7135
  const assertCustom = (condition, order) => {
7128
7136
  const { type } = condition;
@@ -8000,9 +8008,9 @@ var RulesEngine = class {
8000
8008
  throw new Error(msg);
8001
8009
  };
8002
8010
  assertCustom = (condition) => {
8003
- if (condition.type === "Payment" || condition.type === "Payments") {
8011
+ if (condition.type === "Payment") {
8004
8012
  const payment = this.getDependency("payment", condition.type);
8005
- return matchCustom(condition, payment.id);
8013
+ return matchCustom(condition, payment.ids ?? payment.id);
8006
8014
  }
8007
8015
  const order = this.getDependency("order", condition.type);
8008
8016
  return assertCustom(condition, order);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fire-spark/core",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Fire Spark headless SDK",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -20,8 +20,8 @@
20
20
  "big.js": "6.2.1",
21
21
  "dayjs": "1.11.9",
22
22
  "@types/big.js": "6.2.2",
23
- "@fire-spark/payments": "^0.3.3",
24
- "@fire-spark/types": "^0.3.3"
23
+ "@fire-spark/payments": "^0.3.4",
24
+ "@fire-spark/types": "^0.3.4"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsdown": "^0.22.14",