sks-maximo-utils 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  Maximo 表结构和数据更新工具集。
4
4
 
5
+ 配合 VSCODE插件 [maximo-script-helper](https://marketplace.visualstudio.com/items?itemName=shoukaiseki.maximo-script-helper) 中的脚本
6
+
7
+ 配合web端 [maximo-manager-panel](https://gitee.com/shoukaiseki/maximo-manager-panel)
8
+
9
+ 该工具的示例代码: [maximo_request_demo](https://gitee.com/shoukaiseki/maximo-helper-box/tree/master/maximo_request_demo)
10
+
11
+
12
+
5
13
  ## 安装
6
14
 
7
15
  ### 全局安装(CLI 使用)
@@ -196,4 +204,4 @@ npm link sks-maximo-utils
196
204
 
197
205
  ## License
198
206
 
199
- ISC
207
+ ISC
@@ -58,6 +58,7 @@ export function loadConfig(env = null) {
58
58
 
59
59
  // 获取全局配置
60
60
  const globalLogLevel = allConfigs.logLevel || 'INFO';
61
+ // console.log("globalLogLevel:"+ globalLogLevel);
61
62
 
62
63
  // 获取环境配置
63
64
  const envs = allConfigs.envs || {};
@@ -5,6 +5,26 @@ import { getConfig } from './config.js';
5
5
  import os from 'os'
6
6
  import path from 'path'
7
7
 
8
+ /**
9
+ * 解析请求体内容:JSON 文件解析为对象,避免非法 JSON 字符串被 axios 当作普通字符串二次序列化;
10
+ * 非 JSON 文件(如 XML)原样返回字符串。
11
+ * @param {string} fileName - 文件名(用于判断是否为 JSON)
12
+ * @param {string} fileContent - 文件内容
13
+ * @param {string} logname - 日志打印名称
14
+ * @returns {{ok: boolean, data: any}} ok 为 false 表示 JSON 解析失败
15
+ */
16
+ function parseRequestBody(fileName, fileContent, logname) {
17
+ if (fileName && fileName.toLowerCase().endsWith('.json')) {
18
+ try {
19
+ return { ok: true, data: JSON.parse(fileContent) };
20
+ } catch (e) {
21
+ logger.error(`[${logname}]JSON解析失败: ${e.message}`);
22
+ return { ok: false, data: null };
23
+ }
24
+ }
25
+ return { ok: true, data: fileContent };
26
+ }
27
+
8
28
  /**
9
29
  * 导入Maximo对象配置
10
30
  * @param {Object} options - 配置选项
@@ -31,6 +51,11 @@ export async function importMaxObject({fileName, logname}) {
31
51
  logger.info(`[${logname}]文件大小: ${fileContent.length} 字节`);
32
52
  logger.info(`[${logname}]准备导入对象: ${logname || '未指定'}`);
33
53
 
54
+ const body = parseRequestBody(fileName, fileContent, logname);
55
+ if (!body.ok) {
56
+ return false;
57
+ }
58
+
34
59
  // 发送请求到Maximo API
35
60
  logger.info(`[${logname}]开始发送请求...`);
36
61
  const response = await request({
@@ -40,7 +65,7 @@ export async function importMaxObject({fileName, logname}) {
40
65
  develop: true,
41
66
  _langcode: getConfig().langcode,
42
67
  },
43
- data: fileContent // 将文件内容作为请求体发送
68
+ data: body.data, // 将文件内容作为请求体发送
44
69
  })
45
70
 
46
71
  logger.info(`[${logname}]收到响应`);
@@ -99,6 +124,11 @@ export async function importMaxPresentation({fileName, logname}) {
99
124
  logger.info(`[${logname}]成功读取文件: ${fileName}`);
100
125
  logger.info(`[${logname}]文件大小: ${fileContent.length} 字节`);
101
126
 
127
+ const body = parseRequestBody(fileName, fileContent, logname);
128
+ if (!body.ok) {
129
+ return false;
130
+ }
131
+
102
132
  logger.info(`[${logname}]开始发送请求...`);
103
133
  const response = await request({
104
134
  url: '/api/script/SKS.AUTOSCRIPT.SCREENS',
@@ -109,7 +139,7 @@ export async function importMaxPresentation({fileName, logname}) {
109
139
  params: {
110
140
  _langcode: getConfig().langcode,
111
141
  },
112
- data: fileContent
142
+ data: body.data
113
143
  })
114
144
 
115
145
  logger.info(`[${logname}]收到响应`);
@@ -193,6 +223,11 @@ export async function importMaxDomain({fileName, logname}) {
193
223
  logger.info(`[${logname}]文件大小: ${fileContent.length} 字节`);
194
224
  logger.info(`[${logname}]准备导入domain: ${logname || '未指定'}`);
195
225
 
226
+ const body = parseRequestBody(fileName, fileContent, logname);
227
+ if (!body.ok) {
228
+ return false;
229
+ }
230
+
196
231
  logger.info(`[${logname}]开始发送请求...`);
197
232
  const response = await request({
198
233
  url: '/api/script/SKS.AUTOSCRIPT.OBJECTS',
@@ -202,7 +237,7 @@ export async function importMaxDomain({fileName, logname}) {
202
237
  _action: 'import',
203
238
  _langcode: getConfig().langcode,
204
239
  },
205
- data: fileContent
240
+ data: body.data
206
241
  })
207
242
 
208
243
  const { ok, summary, result } = checkImportResult(response);
@@ -257,6 +292,11 @@ export async function importMaxIntObject({fileName, logname}) {
257
292
  logger.info(`[${logname}]文件大小: ${fileContent.length} 字节`);
258
293
  logger.info(`[${logname}]准备导入对象结构: ${logname || '未指定'}`);
259
294
 
295
+ const body = parseRequestBody(fileName, fileContent, logname);
296
+ if (!body.ok) {
297
+ return false;
298
+ }
299
+
260
300
  logger.info(`[${logname}]开始发送请求...`);
261
301
  const response = await request({
262
302
  url: '/api/script/SKS.AUTOSCRIPT.OBJECTS',
@@ -266,7 +306,7 @@ export async function importMaxIntObject({fileName, logname}) {
266
306
  _action: 'import',
267
307
  _langcode: getConfig().langcode,
268
308
  },
269
- data: fileContent
309
+ data: body.data
270
310
  })
271
311
 
272
312
  const { ok, summary, result } = checkImportResult(response);
@@ -614,6 +654,11 @@ export async function importMaxAutoKey({fileName, logname}) {
614
654
  logger.info(`[${logname}]文件大小: ${fileContent.length} 字节`);
615
655
  logger.info(`[${logname}]准备导入autokey: ${logname || '未指定'}`);
616
656
 
657
+ const body = parseRequestBody(fileName, fileContent, logname);
658
+ if (!body.ok) {
659
+ return false;
660
+ }
661
+
617
662
  logger.info(`[${logname}]开始发送请求...`);
618
663
  const response = await request({
619
664
  url: '/api/script/SKS_DEPLOY_AUTOKEY',
@@ -622,7 +667,7 @@ export async function importMaxAutoKey({fileName, logname}) {
622
667
  develop: true,
623
668
  _langcode: getConfig().langcode,
624
669
  },
625
- data: fileContent
670
+ data: body.data
626
671
  })
627
672
 
628
673
  logger.info(`[${logname}]收到响应`);
@@ -675,6 +720,11 @@ export async function importMaxAppInfo({fileName, logname}) {
675
720
  logger.info(`[${logname}]文件大小: ${fileContent.length} 字节`);
676
721
  logger.info(`[${logname}]准备导入应用信息: ${logname || '未指定'}`);
677
722
 
723
+ const body = parseRequestBody(fileName, fileContent, logname);
724
+ if (!body.ok) {
725
+ return false;
726
+ }
727
+
678
728
  logger.info(`[${logname}]开始发送请求...`);
679
729
  const response = await request({
680
730
  url: '/api/script/SKS_IMP_MAXAPPINFO',
@@ -683,7 +733,7 @@ export async function importMaxAppInfo({fileName, logname}) {
683
733
  develop: true,
684
734
  _langcode: getConfig().langcode,
685
735
  },
686
- data: fileContent
736
+ data: body.data
687
737
  })
688
738
 
689
739
  logger.info(`[${logname}]收到响应`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sks-maximo-utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Maximo helper tools for updating table structures and data",
5
5
  "type": "module",
6
6
  "main": "index.js",