nofax 0.2.50 → 0.2.51
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 +7 -0
- package/PRIVACY.md +25 -0
- package/README.md +34 -2
- package/docs/desktop-extension.md +18 -0
- package/manifest.json +81 -0
- package/package.json +5 -2
- package/src/cli.mjs +89 -16
- package/src/config.mjs +59 -4
- package/src/mcp-server.mjs +1 -1
- package/src/mcp-tools.mjs +3 -26
- package/src/ntfy.mjs +152 -33
- package/src/protocol.mjs +728 -5
- package/src/requests.mjs +17 -2
package/src/requests.mjs
CHANGED
|
@@ -28,6 +28,21 @@ function boundResponseText(value) {
|
|
|
28
28
|
return `${text.slice(0, end)}${TRUNCATION_MARKER}`;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
function parseRequestTimestamp(value) {
|
|
32
|
+
if (typeof value !== 'string') return NaN;
|
|
33
|
+
const parsed = Date.parse(value);
|
|
34
|
+
if (!Number.isFinite(parsed)) return NaN;
|
|
35
|
+
// Date.parse normalizes impossible ISO calendar days, e.g. February 30.
|
|
36
|
+
const calendar = /^(\d{4})-(\d{2})-(\d{2})(?:T|$)/.exec(value);
|
|
37
|
+
if (!calendar) return parsed; // Preserve preexisting non-ISO record compatibility.
|
|
38
|
+
const year = Number(calendar[1]);
|
|
39
|
+
const month = Number(calendar[2]);
|
|
40
|
+
const day = Number(calendar[3]);
|
|
41
|
+
const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
42
|
+
const daysInMonth = [31, leapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
43
|
+
return day >= 1 && day <= daysInMonth ? parsed : NaN;
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
function validateRequest(input) {
|
|
32
47
|
if (!input || input.version !== 1) throw new Error('NOFAX_REQUEST_VERSION');
|
|
33
48
|
const requestId = validateRequestId(input.requestId);
|
|
@@ -58,7 +73,7 @@ function validateRequest(input) {
|
|
|
58
73
|
// treat its record as a fresh, unresolved approval request.
|
|
59
74
|
throw new Error('NOFAX_REQUEST_PENDING_TERMINAL_FIELDS_INVALID');
|
|
60
75
|
}
|
|
61
|
-
const createdAtMs =
|
|
76
|
+
const createdAtMs = parseRequestTimestamp(input.createdAt);
|
|
62
77
|
if (!Number.isFinite(createdAtMs)) throw new Error('NOFAX_REQUEST_CREATED_AT_INVALID');
|
|
63
78
|
const hasServer = input.server !== undefined;
|
|
64
79
|
const hasTopic = input.topic !== undefined;
|
|
@@ -80,7 +95,7 @@ function validateRequest(input) {
|
|
|
80
95
|
base.topic = input.topic;
|
|
81
96
|
}
|
|
82
97
|
if (input.status === 'resolved') {
|
|
83
|
-
const resolvedAtMs =
|
|
98
|
+
const resolvedAtMs = parseRequestTimestamp(input.resolvedAt);
|
|
84
99
|
// A terminal decision cannot precede the request it purportedly resolved.
|
|
85
100
|
if (!Number.isFinite(resolvedAtMs) || resolvedAtMs < createdAtMs) throw new Error('NOFAX_REQUEST_RESOLVED_AT_INVALID');
|
|
86
101
|
if (typeof input.decision !== 'string') throw new Error('NOFAX_REQUEST_DECISION_INVALID');
|