priority-axi 0.1.0 → 0.2.1

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/odata.js CHANGED
@@ -23,7 +23,11 @@ const INTEGER = new Set(['Int16', 'Int32', 'Int64', 'Byte', 'SByte']);
23
23
  const DECIMAL = new Set(['Decimal', 'Double', 'Single']);
24
24
  const DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
25
25
  const TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
26
- /** A UTC timestamp with seconds and Z, as Priority recommends for filters. */
26
+ const LOCAL = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(\.\d{1,7})?)?)?(?:Z|[+-]\d{2}:\d{2})?$/;
27
+ /**
28
+ * A UTC timestamp with seconds and Z, for --since only: Priority's $since
29
+ * honours the offset, and its docs recommend UTC with Z for it.
30
+ */
27
31
  export function utc(raw, flag) {
28
32
  const day = DAY.exec(raw);
29
33
  let ms;
@@ -36,10 +40,31 @@ export function utc(raw, flag) {
36
40
  ms = TIME.test(raw) ? Date.parse(raw) : Number.NaN;
37
41
  }
38
42
  if (!Number.isFinite(ms)) {
39
- throw usage(`Invalid date for ${flag}; use YYYY-MM-DD or a full time such as 2026-10-01T08:00:00Z.`);
43
+ throw usage(`Invalid date for ${flag}; use YYYY-MM-DD, 7d, 24h or a full UTC time such as 2026-10-01T06:00:00Z.`);
40
44
  }
41
45
  return new Date(ms).toISOString().replace(/\.\d{3}Z$/, 'Z');
42
46
  }
47
+ /**
48
+ * A date or time in Priority's local (company) time, for --where, --set and
49
+ * --json-file. Priority reads only the wall-clock digits of a DateTimeOffset
50
+ * in $filter and in a write body, and ignores its offset (live, 23.1). So the
51
+ * digits go out exactly as given, with any offset dropped, never converted to
52
+ * UTC. The Z only completes the literal's form.
53
+ */
54
+ export function localTime(raw, flag) {
55
+ const m = LOCAL.exec(raw);
56
+ const [, y, mo, d, h = '00', mi = '00', sec = '00', frac = ''] = m ?? [];
57
+ const day = Date.UTC(Number(y), Number(mo) - 1, Number(d));
58
+ const real = m &&
59
+ new Date(day).toISOString().slice(0, 10) === `${y}-${mo}-${d}` &&
60
+ Number(h) < 24 &&
61
+ Number(mi) < 60 &&
62
+ Number(sec) < 60;
63
+ if (!real) {
64
+ throw usage(`Invalid date for ${flag}; use YYYY-MM-DD or YYYY-MM-DDTHH:MM in Priority's local (company) time, such as 2026-10-01T08:00. An offset is ignored, never converted.`);
65
+ }
66
+ return `${y}-${mo}-${d}T${h}:${mi}:${sec}${frac}Z`;
67
+ }
43
68
  /** An OData literal for a value of this field's type. */
44
69
  export function literal(field, raw) {
45
70
  if (field.type === 'String')
@@ -61,7 +86,7 @@ export function literal(field, raw) {
61
86
  return raw;
62
87
  }
63
88
  if (field.type === 'DateTimeOffset' || field.type === 'Date')
64
- return utc(raw, `--where ${field.name}`);
89
+ return localTime(raw, `--where ${field.name}`);
65
90
  throw usage(`--where cannot filter ${field.name} (${field.type}); use --filter with raw OData.`);
66
91
  }
67
92
  export function whereToFilter(wheres, type, screenName) {
@@ -106,3 +131,47 @@ export function screenSegment(name) {
106
131
  }
107
132
  return name;
108
133
  }
134
+ // The longest record segment the Gate's key type takes.
135
+ const SEGMENT_MAX = 256;
136
+ /**
137
+ * A record's path segment, NAME(<key>), for an update. A screen with one key
138
+ * field takes its value as given; a compound key takes F=V pairs joined by
139
+ * commas, one per key field. Each value is a typed OData literal. A value may
140
+ * not hold a slash, a percent sign, a backslash, a control character or two dots:
141
+ * the Gate's record type refuses them, and so does this.
142
+ */
143
+ export function recordSegment(name, type, raw, named = false) {
144
+ screenSegment(name);
145
+ if (!type.key.length)
146
+ throw usage(`${name} has no key, so its records cannot be updated.`);
147
+ const values = [];
148
+ if (type.key.length === 1) {
149
+ values.push([type.key[0] ?? '', raw]);
150
+ }
151
+ else {
152
+ for (const pair of raw.split(',')) {
153
+ const t = /^([A-Za-z][A-Za-z0-9_]*)=(.*)$/s.exec(pair);
154
+ if (!t)
155
+ throw usage(`${name} has a compound key (${type.key.join(', ')}); give it as ${type.key.map((k) => `${k}=VALUE`).join(',')}.`);
156
+ values.push([t[1] ?? '', t[2] ?? '']);
157
+ }
158
+ const given = values.map(([f]) => f.toUpperCase()).sort();
159
+ const keys = [...type.key].map((k) => k.toUpperCase()).sort();
160
+ if (given.join() !== keys.join())
161
+ throw usage(`${name} has a compound key (${type.key.join(', ')}); give each once as ${type.key.map((k) => `${k}=VALUE`).join(',')}.`);
162
+ }
163
+ const parts = [];
164
+ for (const [fieldName, value] of values) {
165
+ if (!value)
166
+ throw usage(`The key ${fieldName} needs a value.`);
167
+ if (value.includes('..') || /[/%\\\p{Cc}]/u.test(value))
168
+ throw usage('A key value cannot hold a slash, a percent sign, a backslash, a control character or two dots in a row.');
169
+ const field = resolveField(type, name, fieldName);
170
+ const text = literal(field, value);
171
+ parts.push(type.key.length === 1 && !named ? text : `${field.name}=${text}`);
172
+ }
173
+ const segment = `${name}(${parts.join(',')})`;
174
+ if (segment.length > SEGMENT_MAX)
175
+ throw usage(`The record's key is longer than ${SEGMENT_MAX - name.length - 2} characters.`);
176
+ return segment;
177
+ }
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Kept equal to package.json by test/unit/version.test.ts.
2
- export const VERSION = '0.1.0';
2
+ export const VERSION = '0.2.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "priority-axi",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "A command-line tool that lets AI agents read and create Priority ERP records through the REST API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,8 +50,8 @@
50
50
  "@toon-format/toon": "4.4.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@biomejs/biome": "2.5.15",
54
- "@types/node": "22.20.5",
53
+ "@biomejs/biome": "2.6.7",
54
+ "@types/node": "26.6.6",
55
55
  "typescript": "7.0.2"
56
56
  }
57
57
  }