mage-remote-run 1.0.0 → 1.2.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.
Files changed (2) hide show
  1. package/lib/utils.js +49 -27
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -105,36 +105,58 @@ export function buildSearchCriteria(options) {
105
105
  };
106
106
 
107
107
  if (options.filter && options.filter.length > 0) {
108
- for (const f of options.filter) {
109
- let match = f.match(/^([^=<>:]+)(?::([a-z]+))?(?:(<=|>=|<|>|=)(.*))?$/);
110
- if (match) {
111
- const field = match[1];
112
- const opString = match[2];
113
- const shorthand = match[3];
114
- let value = match[4] || '';
115
-
116
- let condition = 'eq';
117
-
118
- if (opString) {
119
- condition = opString;
120
- } else if (shorthand) {
121
- if (shorthand === '>') condition = 'gt';
122
- else if (shorthand === '<') condition = 'lt';
123
- else if (shorthand === '>=') condition = 'gteq';
124
- else if (shorthand === '<=') condition = 'lteq';
125
- else condition = 'eq';
108
+ for (const group of options.filter) {
109
+ const orFilters = group.split(/\s*\|\|\s*/);
110
+ let addedAny = false;
111
+ let orIndex = 0;
112
+
113
+ for (const f of orFilters) {
114
+ let match = f.match(/^([\w\.]+)(?::([a-z!]+))?(?:(<=|>=|<|>|=|!=|!~|~|\?|!|@@)(.*))?$/);
115
+ if (match) {
116
+ const field = match[1];
117
+ const opString = match[2];
118
+ const shorthand = match[3];
119
+ let value = match[4] || '';
120
+
121
+ let condition = 'eq';
122
+
123
+ if (opString) {
124
+ condition = opString === '!in' ? 'nin' : opString;
125
+ } else if (shorthand) {
126
+ switch (shorthand) {
127
+ case '>': condition = 'gt'; break;
128
+ case '<': condition = 'lt'; break;
129
+ case '>=': condition = 'gteq'; break;
130
+ case '<=': condition = 'lteq'; break;
131
+ case '!=': condition = 'neq'; break;
132
+ case '~': condition = 'like'; break;
133
+ case '!~': condition = 'nlike'; break;
134
+ case '@@': condition = 'finset'; break;
135
+ case '?': condition = 'null'; value = '1'; break;
136
+ case '!': condition = 'notnull'; value = '1'; break;
137
+ default: condition = 'eq';
138
+ }
139
+ } else {
140
+ console.error(chalk.yellow(`Warning: Invalid filter format "${f}". Expected formats like "field=value", "field:like=value", etc.`));
141
+ continue;
142
+ }
143
+
144
+ if ((condition === 'like' || condition === 'nlike') && value.includes('*')) {
145
+ value = value.replaceAll('*', '%');
146
+ }
147
+
148
+ params[`searchCriteria[filter_groups][${filterIndex}][filters][${orIndex}][field]`] = field;
149
+ params[`searchCriteria[filter_groups][${filterIndex}][filters][${orIndex}][value]`] = value;
150
+ params[`searchCriteria[filter_groups][${filterIndex}][filters][${orIndex}][condition_type]`] = condition;
151
+
152
+ orIndex++;
153
+ addedAny = true;
126
154
  } else {
127
155
  console.error(chalk.yellow(`Warning: Invalid filter format "${f}". Expected formats like "field=value", "field:like=value", etc.`));
128
- continue;
129
156
  }
130
-
131
- if (condition === 'like' && value.includes('*')) {
132
- value = value.replaceAll('*', '%');
133
- }
134
-
135
- addFilter(field, value, condition);
136
- } else {
137
- console.error(chalk.yellow(`Warning: Invalid filter format "${f}". Expected formats like "field=value", "field:like=value", etc.`));
157
+ }
158
+ if (addedAny) {
159
+ filterIndex++;
138
160
  }
139
161
  }
140
162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-remote-run",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "The remote swiss army knife for Magento Open Source, Mage-OS, Adobe Commerce",
5
5
  "main": "index.js",
6
6
  "scripts": {