chaimi-keep-mcp 3.1.45-beta.0 → 3.1.45-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chaimi-keep-mcp",
3
- "version": "3.1.45-beta.0",
3
+ "version": "3.1.45-beta.1",
4
4
  "description": "柴米记账 MCP Server - 支持 Claude、Cursor、OpenClaw、WorkBuddy 等 AI 工具直接记账",
5
5
  "main": "server.js",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "bin/",
11
+ "utils/",
11
12
  "server.js",
12
13
  "oauth.js",
13
14
  "SKILL.md",
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 数据校验工具函数
3
+ */
4
+
5
+ /**
6
+ * 校验日期合理性
7
+ * @param {number|string} dateInput - 日期(毫秒级时间戳或日期字符串)
8
+ * @param {string} fieldName - 字段名称(用于错误提示)
9
+ * @returns {Date} 校验通过后的 Date 对象
10
+ * @throws {Error} 校验失败时抛出错误
11
+ */
12
+ function validateDate(dateInput, fieldName = '日期') {
13
+ if (!dateInput) {
14
+ return new Date(); // 默认当前时间
15
+ }
16
+
17
+ const inputDate = new Date(dateInput);
18
+ const now = new Date();
19
+ const sixtyYearsAgo = new Date();
20
+ sixtyYearsAgo.setFullYear(now.getFullYear() - 60);
21
+
22
+ // 校验 1:日期格式是否有效
23
+ if (isNaN(inputDate.getTime())) {
24
+ throw new Error(`${fieldName}格式无效,请使用毫秒级时间戳(13位数字,如:${Date.now()})`);
25
+ }
26
+
27
+ // 校验 2:日期不能是未来时间
28
+ if (inputDate > now) {
29
+ throw new Error(`${fieldName}不能是未来时间`);
30
+ }
31
+
32
+ // 校验 3:日期不能是 60 年前
33
+ if (inputDate < sixtyYearsAgo) {
34
+ throw new Error(`${fieldName}不能是60年前`);
35
+ }
36
+
37
+ return inputDate;
38
+ }
39
+
40
+ module.exports = {
41
+ validateDate
42
+ };