@zhoujinandrew/te-cli 1.0.1 → 1.0.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/dist/analysis-GWLVZ2YM.js +218 -0
- package/dist/analysis-M54YNGTJ.js +216 -0
- package/dist/analysis-XB56ZN7H.js +217 -0
- package/dist/chunk-4OJI46I5.js +148 -0
- package/dist/chunk-GZG7YDWV.js +145 -0
- package/dist/chunk-O6AQSK3A.js +149 -0
- package/dist/client-6TVMBUGP.js +16 -0
- package/dist/client-BYCN6252.js +16 -0
- package/dist/client-NEWKAE3M.js +16 -0
- package/dist/index.js +3 -3
- package/dist/raw-HYKP4YPT.js +59 -0
- package/dist/raw-M3K7FAJ4.js +59 -0
- package/dist/raw-MR5RWDLO.js +59 -0
- package/package.json +1 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// src/commands/analysis/list-reports.ts
|
|
2
|
+
var listReports = {
|
|
3
|
+
service: "analysis",
|
|
4
|
+
command: "+list-reports",
|
|
5
|
+
description: "List all analysis reports for a project",
|
|
6
|
+
flags: [
|
|
7
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" }
|
|
8
|
+
],
|
|
9
|
+
risk: "read",
|
|
10
|
+
execute: async (ctx) => {
|
|
11
|
+
return ctx.api("POST", "/v1/ta/event/listAll", {
|
|
12
|
+
projectId: ctx.num("project-id")
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/commands/analysis/get-report.ts
|
|
18
|
+
var getReport = {
|
|
19
|
+
service: "analysis",
|
|
20
|
+
command: "+get-report",
|
|
21
|
+
description: "Get full report definition by ID",
|
|
22
|
+
flags: [
|
|
23
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
24
|
+
{ name: "report-id", type: "number", required: true, desc: "Report ID" }
|
|
25
|
+
],
|
|
26
|
+
risk: "read",
|
|
27
|
+
execute: async (ctx) => {
|
|
28
|
+
return ctx.api("GET", "/v1/ta/event/reportsearch", {
|
|
29
|
+
projectId: ctx.num("project-id"),
|
|
30
|
+
reportId: ctx.num("report-id")
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/commands/analysis/save-report.ts
|
|
36
|
+
var saveReport = {
|
|
37
|
+
service: "analysis",
|
|
38
|
+
command: "+save-report",
|
|
39
|
+
description: "Save (create/update) an analysis report",
|
|
40
|
+
flags: [
|
|
41
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
42
|
+
{ name: "report-name", type: "string", required: true, desc: "Report name" },
|
|
43
|
+
{ name: "report-model", type: "number", required: true, desc: "0=Event, 1=Retention, 2=Funnel, 10=Distribution" },
|
|
44
|
+
{ name: "events", type: "json", required: true, desc: "Events configuration array" },
|
|
45
|
+
{ name: "event-view", type: "json", required: true, desc: "Event view configuration" }
|
|
46
|
+
],
|
|
47
|
+
risk: "write",
|
|
48
|
+
execute: async (ctx) => {
|
|
49
|
+
return ctx.api("POST", "/v1/ta/event/reportsave", {
|
|
50
|
+
projectId: ctx.num("project-id")
|
|
51
|
+
}, {
|
|
52
|
+
reportName: ctx.str("report-name"),
|
|
53
|
+
reportModel: ctx.num("report-model"),
|
|
54
|
+
events: ctx.json("events"),
|
|
55
|
+
eventView: ctx.json("event-view")
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/commands/analysis/list-dashboards.ts
|
|
61
|
+
var listDashboards = {
|
|
62
|
+
service: "analysis",
|
|
63
|
+
command: "+list-dashboards",
|
|
64
|
+
description: "List all dashboards for a project",
|
|
65
|
+
flags: [
|
|
66
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" }
|
|
67
|
+
],
|
|
68
|
+
risk: "read",
|
|
69
|
+
execute: async (ctx) => {
|
|
70
|
+
return ctx.api("GET", "/v1/ta/dashboard/all-dashboards", {
|
|
71
|
+
projectId: ctx.num("project-id")
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/commands/analysis/get-dashboard.ts
|
|
77
|
+
var getDashboard = {
|
|
78
|
+
service: "analysis",
|
|
79
|
+
command: "+get-dashboard",
|
|
80
|
+
description: "Get dashboard details by ID",
|
|
81
|
+
flags: [
|
|
82
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
83
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" }
|
|
84
|
+
],
|
|
85
|
+
risk: "read",
|
|
86
|
+
execute: async (ctx) => {
|
|
87
|
+
return ctx.api("POST", "/v1/ta/dashboard/search-dashboard", {
|
|
88
|
+
projectId: ctx.num("project-id")
|
|
89
|
+
}, {
|
|
90
|
+
dashboardId: ctx.num("dashboard-id")
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/commands/analysis/create-dashboard.ts
|
|
96
|
+
var createDashboard = {
|
|
97
|
+
service: "analysis",
|
|
98
|
+
command: "+create-dashboard",
|
|
99
|
+
description: "Create a new dashboard",
|
|
100
|
+
flags: [
|
|
101
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
102
|
+
{ name: "dashboard-name", type: "string", required: true, desc: "Dashboard name" }
|
|
103
|
+
],
|
|
104
|
+
risk: "write",
|
|
105
|
+
execute: async (ctx) => {
|
|
106
|
+
return ctx.api("POST", "/v1/ta/dashboard/create-dashboard", {
|
|
107
|
+
projectId: ctx.num("project-id")
|
|
108
|
+
}, {
|
|
109
|
+
dashboardName: ctx.str("dashboard-name")
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/commands/analysis/update-dashboard.ts
|
|
115
|
+
var updateDashboard = {
|
|
116
|
+
service: "analysis",
|
|
117
|
+
command: "+update-dashboard",
|
|
118
|
+
description: "Update dashboard report layout",
|
|
119
|
+
flags: [
|
|
120
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
121
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" },
|
|
122
|
+
{ name: "reports", type: "json", required: true, desc: "[{reportId, reportWidth?, indexOrder}]" }
|
|
123
|
+
],
|
|
124
|
+
risk: "write",
|
|
125
|
+
execute: async (ctx) => {
|
|
126
|
+
return ctx.api("POST", "/v1/ta/dashboard/update-dashboard", {
|
|
127
|
+
projectId: ctx.num("project-id")
|
|
128
|
+
}, {
|
|
129
|
+
dashbordId: ctx.num("dashboard-id"),
|
|
130
|
+
reports: ctx.json("reports")
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/commands/analysis/list-dashboard-reports.ts
|
|
136
|
+
var listDashboardReports = {
|
|
137
|
+
service: "analysis",
|
|
138
|
+
command: "+list-dashboard-reports",
|
|
139
|
+
description: "List reports within a dashboard",
|
|
140
|
+
flags: [
|
|
141
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
142
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" }
|
|
143
|
+
],
|
|
144
|
+
risk: "read",
|
|
145
|
+
execute: async (ctx) => {
|
|
146
|
+
const result = await ctx.api("POST", "/v1/ta/dashboard/search-dashboard", {
|
|
147
|
+
projectId: ctx.num("project-id")
|
|
148
|
+
}, {
|
|
149
|
+
dashboardId: ctx.num("dashboard-id")
|
|
150
|
+
});
|
|
151
|
+
return result?.eventReportList ?? result;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/commands/analysis/query-report-data.ts
|
|
156
|
+
var queryReportData = {
|
|
157
|
+
service: "analysis",
|
|
158
|
+
command: "+query-report-data",
|
|
159
|
+
description: "Query report data by report ID",
|
|
160
|
+
flags: [
|
|
161
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
162
|
+
{ name: "report-id", type: "number", required: true, desc: "Report ID" },
|
|
163
|
+
{ name: "dashboard-id", type: "number", desc: "Dashboard ID (optional)" },
|
|
164
|
+
{ name: "start-time", type: "string", desc: "Start time (YYYY-MM-DD HH:mm:ss)" },
|
|
165
|
+
{ name: "end-time", type: "string", desc: "End time (YYYY-MM-DD HH:mm:ss)" }
|
|
166
|
+
],
|
|
167
|
+
risk: "read",
|
|
168
|
+
execute: async (ctx) => {
|
|
169
|
+
const projectId = ctx.num("project-id");
|
|
170
|
+
const reportId = ctx.num("report-id");
|
|
171
|
+
const report = await ctx.api("GET", "/v1/ta/event/reportsearch", {
|
|
172
|
+
projectId,
|
|
173
|
+
reportId
|
|
174
|
+
});
|
|
175
|
+
const qp = {
|
|
176
|
+
events: report.events,
|
|
177
|
+
eventView: report.eventView
|
|
178
|
+
};
|
|
179
|
+
const startTime = ctx.str("start-time");
|
|
180
|
+
const endTime = ctx.str("end-time");
|
|
181
|
+
if (startTime) qp.eventView = { ...qp.eventView, startTime };
|
|
182
|
+
if (endTime) qp.eventView = { ...qp.eventView, endTime };
|
|
183
|
+
return ctx.queryReportData(projectId, reportId, qp, report.reportModel || 0);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/commands/analysis/query-sql.ts
|
|
188
|
+
var querySql = {
|
|
189
|
+
service: "analysis",
|
|
190
|
+
command: "+query-sql",
|
|
191
|
+
description: "Execute a SQL query against the project",
|
|
192
|
+
flags: [
|
|
193
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
194
|
+
{ name: "sql", type: "string", required: true, desc: "SQL query string" }
|
|
195
|
+
],
|
|
196
|
+
risk: "read",
|
|
197
|
+
execute: async (ctx) => {
|
|
198
|
+
return ctx.querySql(ctx.num("project-id"), ctx.str("sql"));
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/commands/analysis/index.ts
|
|
203
|
+
var commands = [
|
|
204
|
+
listReports,
|
|
205
|
+
getReport,
|
|
206
|
+
saveReport,
|
|
207
|
+
listDashboards,
|
|
208
|
+
getDashboard,
|
|
209
|
+
createDashboard,
|
|
210
|
+
updateDashboard,
|
|
211
|
+
listDashboardReports,
|
|
212
|
+
queryReportData,
|
|
213
|
+
querySql
|
|
214
|
+
];
|
|
215
|
+
var analysis_default = commands;
|
|
216
|
+
export {
|
|
217
|
+
analysis_default as default
|
|
218
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// src/commands/analysis/list-reports.ts
|
|
2
|
+
var listReports = {
|
|
3
|
+
service: "analysis",
|
|
4
|
+
command: "+list-reports",
|
|
5
|
+
description: "List all analysis reports for a project",
|
|
6
|
+
flags: [
|
|
7
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" }
|
|
8
|
+
],
|
|
9
|
+
risk: "read",
|
|
10
|
+
execute: async (ctx) => {
|
|
11
|
+
return ctx.api("POST", "/v1/ta/event/listAll", {
|
|
12
|
+
projectId: ctx.num("project-id")
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/commands/analysis/get-report.ts
|
|
18
|
+
var getReport = {
|
|
19
|
+
service: "analysis",
|
|
20
|
+
command: "+get-report",
|
|
21
|
+
description: "Get full report definition by ID",
|
|
22
|
+
flags: [
|
|
23
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
24
|
+
{ name: "report-id", type: "number", required: true, desc: "Report ID" }
|
|
25
|
+
],
|
|
26
|
+
risk: "read",
|
|
27
|
+
execute: async (ctx) => {
|
|
28
|
+
return ctx.api("GET", "/v1/ta/event/reportsearch", {
|
|
29
|
+
projectId: ctx.num("project-id"),
|
|
30
|
+
reportId: ctx.num("report-id")
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/commands/analysis/save-report.ts
|
|
36
|
+
var saveReport = {
|
|
37
|
+
service: "analysis",
|
|
38
|
+
command: "+save-report",
|
|
39
|
+
description: "Save (create/update) an analysis report",
|
|
40
|
+
flags: [
|
|
41
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
42
|
+
{ name: "report-name", type: "string", required: true, desc: "Report name" },
|
|
43
|
+
{ name: "report-model", type: "number", required: true, desc: "0=Event, 1=Retention, 2=Funnel, 10=Distribution" },
|
|
44
|
+
{ name: "events", type: "json", required: true, desc: "Events configuration array" },
|
|
45
|
+
{ name: "event-view", type: "json", required: true, desc: "Event view configuration" }
|
|
46
|
+
],
|
|
47
|
+
risk: "write",
|
|
48
|
+
execute: async (ctx) => {
|
|
49
|
+
return ctx.api("POST", "/v1/ta/event/reportsave", {
|
|
50
|
+
projectId: ctx.num("project-id")
|
|
51
|
+
}, {
|
|
52
|
+
reportName: ctx.str("report-name"),
|
|
53
|
+
reportModel: ctx.num("report-model"),
|
|
54
|
+
events: ctx.json("events"),
|
|
55
|
+
eventView: ctx.json("event-view")
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/commands/analysis/list-dashboards.ts
|
|
61
|
+
var listDashboards = {
|
|
62
|
+
service: "analysis",
|
|
63
|
+
command: "+list-dashboards",
|
|
64
|
+
description: "List all dashboards for a project",
|
|
65
|
+
flags: [
|
|
66
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" }
|
|
67
|
+
],
|
|
68
|
+
risk: "read",
|
|
69
|
+
execute: async (ctx) => {
|
|
70
|
+
return ctx.api("GET", "/v1/ta/dashboard/all-dashboards", {
|
|
71
|
+
projectId: ctx.num("project-id")
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/commands/analysis/get-dashboard.ts
|
|
77
|
+
var getDashboard = {
|
|
78
|
+
service: "analysis",
|
|
79
|
+
command: "+get-dashboard",
|
|
80
|
+
description: "Get dashboard details by ID",
|
|
81
|
+
flags: [
|
|
82
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
83
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" }
|
|
84
|
+
],
|
|
85
|
+
risk: "read",
|
|
86
|
+
execute: async (ctx) => {
|
|
87
|
+
return ctx.api("POST", "/v1/ta/dashboard/search-dashboard", {
|
|
88
|
+
projectId: ctx.num("project-id"),
|
|
89
|
+
dashbordId: ctx.num("dashboard-id")
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/commands/analysis/create-dashboard.ts
|
|
95
|
+
var createDashboard = {
|
|
96
|
+
service: "analysis",
|
|
97
|
+
command: "+create-dashboard",
|
|
98
|
+
description: "Create a new dashboard",
|
|
99
|
+
flags: [
|
|
100
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
101
|
+
{ name: "dashboard-name", type: "string", required: true, desc: "Dashboard name" }
|
|
102
|
+
],
|
|
103
|
+
risk: "write",
|
|
104
|
+
execute: async (ctx) => {
|
|
105
|
+
return ctx.api("POST", "/v1/ta/dashboard/create-dashboard", {
|
|
106
|
+
projectId: ctx.num("project-id")
|
|
107
|
+
}, {
|
|
108
|
+
dashboardName: ctx.str("dashboard-name")
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/commands/analysis/update-dashboard.ts
|
|
114
|
+
var updateDashboard = {
|
|
115
|
+
service: "analysis",
|
|
116
|
+
command: "+update-dashboard",
|
|
117
|
+
description: "Update dashboard report layout",
|
|
118
|
+
flags: [
|
|
119
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
120
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" },
|
|
121
|
+
{ name: "reports", type: "json", required: true, desc: "[{reportId, reportWidth?, indexOrder}]" }
|
|
122
|
+
],
|
|
123
|
+
risk: "write",
|
|
124
|
+
execute: async (ctx) => {
|
|
125
|
+
return ctx.api("POST", "/v1/ta/dashboard/update-dashboard", {
|
|
126
|
+
projectId: ctx.num("project-id")
|
|
127
|
+
}, {
|
|
128
|
+
dashbordId: ctx.num("dashboard-id"),
|
|
129
|
+
reports: ctx.json("reports")
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/commands/analysis/list-dashboard-reports.ts
|
|
135
|
+
var listDashboardReports = {
|
|
136
|
+
service: "analysis",
|
|
137
|
+
command: "+list-dashboard-reports",
|
|
138
|
+
description: "List reports within a dashboard",
|
|
139
|
+
flags: [
|
|
140
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
141
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" }
|
|
142
|
+
],
|
|
143
|
+
risk: "read",
|
|
144
|
+
execute: async (ctx) => {
|
|
145
|
+
const result = await ctx.api("POST", "/v1/ta/dashboard/search-dashboard", {
|
|
146
|
+
projectId: ctx.num("project-id"),
|
|
147
|
+
dashbordId: ctx.num("dashboard-id")
|
|
148
|
+
});
|
|
149
|
+
return result?.eventReportList ?? result;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/commands/analysis/query-report-data.ts
|
|
154
|
+
var queryReportData = {
|
|
155
|
+
service: "analysis",
|
|
156
|
+
command: "+query-report-data",
|
|
157
|
+
description: "Query report data by report ID",
|
|
158
|
+
flags: [
|
|
159
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
160
|
+
{ name: "report-id", type: "number", required: true, desc: "Report ID" },
|
|
161
|
+
{ name: "dashboard-id", type: "number", desc: "Dashboard ID (optional)" },
|
|
162
|
+
{ name: "start-time", type: "string", desc: "Start time (YYYY-MM-DD HH:mm:ss)" },
|
|
163
|
+
{ name: "end-time", type: "string", desc: "End time (YYYY-MM-DD HH:mm:ss)" }
|
|
164
|
+
],
|
|
165
|
+
risk: "read",
|
|
166
|
+
execute: async (ctx) => {
|
|
167
|
+
const projectId = ctx.num("project-id");
|
|
168
|
+
const reportId = ctx.num("report-id");
|
|
169
|
+
const report = await ctx.api("GET", "/v1/ta/event/reportsearch", {
|
|
170
|
+
projectId,
|
|
171
|
+
reportId
|
|
172
|
+
});
|
|
173
|
+
const qp = {
|
|
174
|
+
events: report.events,
|
|
175
|
+
eventView: report.eventView
|
|
176
|
+
};
|
|
177
|
+
const startTime = ctx.str("start-time");
|
|
178
|
+
const endTime = ctx.str("end-time");
|
|
179
|
+
if (startTime) qp.eventView = { ...qp.eventView, startTime };
|
|
180
|
+
if (endTime) qp.eventView = { ...qp.eventView, endTime };
|
|
181
|
+
return ctx.queryReportData(projectId, reportId, qp, report.reportModel || 0);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/commands/analysis/query-sql.ts
|
|
186
|
+
var querySql = {
|
|
187
|
+
service: "analysis",
|
|
188
|
+
command: "+query-sql",
|
|
189
|
+
description: "Execute a SQL query against the project",
|
|
190
|
+
flags: [
|
|
191
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
192
|
+
{ name: "sql", type: "string", required: true, desc: "SQL query string" }
|
|
193
|
+
],
|
|
194
|
+
risk: "read",
|
|
195
|
+
execute: async (ctx) => {
|
|
196
|
+
return ctx.querySql(ctx.num("project-id"), ctx.str("sql"));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/commands/analysis/index.ts
|
|
201
|
+
var commands = [
|
|
202
|
+
listReports,
|
|
203
|
+
getReport,
|
|
204
|
+
saveReport,
|
|
205
|
+
listDashboards,
|
|
206
|
+
getDashboard,
|
|
207
|
+
createDashboard,
|
|
208
|
+
updateDashboard,
|
|
209
|
+
listDashboardReports,
|
|
210
|
+
queryReportData,
|
|
211
|
+
querySql
|
|
212
|
+
];
|
|
213
|
+
var analysis_default = commands;
|
|
214
|
+
export {
|
|
215
|
+
analysis_default as default
|
|
216
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// src/commands/analysis/list-reports.ts
|
|
2
|
+
var listReports = {
|
|
3
|
+
service: "analysis",
|
|
4
|
+
command: "+list-reports",
|
|
5
|
+
description: "List all analysis reports for a project",
|
|
6
|
+
flags: [
|
|
7
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" }
|
|
8
|
+
],
|
|
9
|
+
risk: "read",
|
|
10
|
+
execute: async (ctx) => {
|
|
11
|
+
return ctx.api("POST", "/v1/ta/event/listAll", {
|
|
12
|
+
projectId: ctx.num("project-id")
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/commands/analysis/get-report.ts
|
|
18
|
+
var getReport = {
|
|
19
|
+
service: "analysis",
|
|
20
|
+
command: "+get-report",
|
|
21
|
+
description: "Get full report definition by ID",
|
|
22
|
+
flags: [
|
|
23
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
24
|
+
{ name: "report-id", type: "number", required: true, desc: "Report ID" }
|
|
25
|
+
],
|
|
26
|
+
risk: "read",
|
|
27
|
+
execute: async (ctx) => {
|
|
28
|
+
return ctx.api("GET", "/v1/ta/event/reportsearch", {
|
|
29
|
+
projectId: ctx.num("project-id"),
|
|
30
|
+
reportId: ctx.num("report-id")
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/commands/analysis/save-report.ts
|
|
36
|
+
var saveReport = {
|
|
37
|
+
service: "analysis",
|
|
38
|
+
command: "+save-report",
|
|
39
|
+
description: "Save (create/update) an analysis report",
|
|
40
|
+
flags: [
|
|
41
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
42
|
+
{ name: "report-name", type: "string", required: true, desc: "Report name" },
|
|
43
|
+
{ name: "report-model", type: "number", required: true, desc: "0=Event, 1=Retention, 2=Funnel, 10=Distribution" },
|
|
44
|
+
{ name: "events", type: "json", required: true, desc: "Events configuration array" },
|
|
45
|
+
{ name: "event-view", type: "json", required: true, desc: "Event view configuration" }
|
|
46
|
+
],
|
|
47
|
+
risk: "write",
|
|
48
|
+
execute: async (ctx) => {
|
|
49
|
+
return ctx.api("POST", "/v1/ta/event/reportsave", {
|
|
50
|
+
projectId: ctx.num("project-id")
|
|
51
|
+
}, {
|
|
52
|
+
reportName: ctx.str("report-name"),
|
|
53
|
+
reportModel: ctx.num("report-model"),
|
|
54
|
+
events: ctx.json("events"),
|
|
55
|
+
eventView: ctx.json("event-view")
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/commands/analysis/list-dashboards.ts
|
|
61
|
+
var listDashboards = {
|
|
62
|
+
service: "analysis",
|
|
63
|
+
command: "+list-dashboards",
|
|
64
|
+
description: "List all dashboards for a project",
|
|
65
|
+
flags: [
|
|
66
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" }
|
|
67
|
+
],
|
|
68
|
+
risk: "read",
|
|
69
|
+
execute: async (ctx) => {
|
|
70
|
+
return ctx.api("GET", "/v1/ta/dashboard/all-dashboards", {
|
|
71
|
+
projectId: ctx.num("project-id")
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/commands/analysis/get-dashboard.ts
|
|
77
|
+
var getDashboard = {
|
|
78
|
+
service: "analysis",
|
|
79
|
+
command: "+get-dashboard",
|
|
80
|
+
description: "Get dashboard details by ID",
|
|
81
|
+
flags: [
|
|
82
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
83
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" }
|
|
84
|
+
],
|
|
85
|
+
risk: "read",
|
|
86
|
+
execute: async (ctx) => {
|
|
87
|
+
return ctx.api("POST", "/v1/ta/dashboard/search-dashboard", {
|
|
88
|
+
projectId: ctx.num("project-id"),
|
|
89
|
+
dashbordId: ctx.num("dashboard-id")
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/commands/analysis/create-dashboard.ts
|
|
95
|
+
var createDashboard = {
|
|
96
|
+
service: "analysis",
|
|
97
|
+
command: "+create-dashboard",
|
|
98
|
+
description: "Create a new dashboard",
|
|
99
|
+
flags: [
|
|
100
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
101
|
+
{ name: "dashboard-name", type: "string", required: true, desc: "Dashboard name" }
|
|
102
|
+
],
|
|
103
|
+
risk: "write",
|
|
104
|
+
execute: async (ctx) => {
|
|
105
|
+
return ctx.api("POST", "/v1/ta/dashboard/create-dashboard", {
|
|
106
|
+
projectId: ctx.num("project-id")
|
|
107
|
+
}, {
|
|
108
|
+
dashboardName: ctx.str("dashboard-name")
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/commands/analysis/update-dashboard.ts
|
|
114
|
+
var updateDashboard = {
|
|
115
|
+
service: "analysis",
|
|
116
|
+
command: "+update-dashboard",
|
|
117
|
+
description: "Update dashboard report layout",
|
|
118
|
+
flags: [
|
|
119
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
120
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" },
|
|
121
|
+
{ name: "reports", type: "json", required: true, desc: "[{reportId, reportWidth?, indexOrder}]" }
|
|
122
|
+
],
|
|
123
|
+
risk: "write",
|
|
124
|
+
execute: async (ctx) => {
|
|
125
|
+
return ctx.api("POST", "/v1/ta/dashboard/update-dashboard", {
|
|
126
|
+
projectId: ctx.num("project-id")
|
|
127
|
+
}, {
|
|
128
|
+
dashbordId: ctx.num("dashboard-id"),
|
|
129
|
+
reports: ctx.json("reports")
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/commands/analysis/list-dashboard-reports.ts
|
|
135
|
+
var listDashboardReports = {
|
|
136
|
+
service: "analysis",
|
|
137
|
+
command: "+list-dashboard-reports",
|
|
138
|
+
description: "List reports within a dashboard",
|
|
139
|
+
flags: [
|
|
140
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
141
|
+
{ name: "dashboard-id", type: "number", required: true, desc: "Dashboard ID" }
|
|
142
|
+
],
|
|
143
|
+
risk: "read",
|
|
144
|
+
execute: async (ctx) => {
|
|
145
|
+
const result = await ctx.api("POST", "/v1/ta/dashboard/search-dashboard", {
|
|
146
|
+
projectId: ctx.num("project-id")
|
|
147
|
+
}, {
|
|
148
|
+
dashboardId: ctx.num("dashboard-id")
|
|
149
|
+
});
|
|
150
|
+
return result?.eventReportList ?? result;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/commands/analysis/query-report-data.ts
|
|
155
|
+
var queryReportData = {
|
|
156
|
+
service: "analysis",
|
|
157
|
+
command: "+query-report-data",
|
|
158
|
+
description: "Query report data by report ID",
|
|
159
|
+
flags: [
|
|
160
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
161
|
+
{ name: "report-id", type: "number", required: true, desc: "Report ID" },
|
|
162
|
+
{ name: "dashboard-id", type: "number", desc: "Dashboard ID (optional)" },
|
|
163
|
+
{ name: "start-time", type: "string", desc: "Start time (YYYY-MM-DD HH:mm:ss)" },
|
|
164
|
+
{ name: "end-time", type: "string", desc: "End time (YYYY-MM-DD HH:mm:ss)" }
|
|
165
|
+
],
|
|
166
|
+
risk: "read",
|
|
167
|
+
execute: async (ctx) => {
|
|
168
|
+
const projectId = ctx.num("project-id");
|
|
169
|
+
const reportId = ctx.num("report-id");
|
|
170
|
+
const report = await ctx.api("GET", "/v1/ta/event/reportsearch", {
|
|
171
|
+
projectId,
|
|
172
|
+
reportId
|
|
173
|
+
});
|
|
174
|
+
const qp = {
|
|
175
|
+
events: report.events,
|
|
176
|
+
eventView: report.eventView
|
|
177
|
+
};
|
|
178
|
+
const startTime = ctx.str("start-time");
|
|
179
|
+
const endTime = ctx.str("end-time");
|
|
180
|
+
if (startTime) qp.eventView = { ...qp.eventView, startTime };
|
|
181
|
+
if (endTime) qp.eventView = { ...qp.eventView, endTime };
|
|
182
|
+
return ctx.queryReportData(projectId, reportId, qp, report.reportModel || 0);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/commands/analysis/query-sql.ts
|
|
187
|
+
var querySql = {
|
|
188
|
+
service: "analysis",
|
|
189
|
+
command: "+query-sql",
|
|
190
|
+
description: "Execute a SQL query against the project",
|
|
191
|
+
flags: [
|
|
192
|
+
{ name: "project-id", type: "number", required: true, alias: "p", desc: "Project ID" },
|
|
193
|
+
{ name: "sql", type: "string", required: true, desc: "SQL query string" }
|
|
194
|
+
],
|
|
195
|
+
risk: "read",
|
|
196
|
+
execute: async (ctx) => {
|
|
197
|
+
return ctx.querySql(ctx.num("project-id"), ctx.str("sql"));
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/commands/analysis/index.ts
|
|
202
|
+
var commands = [
|
|
203
|
+
listReports,
|
|
204
|
+
getReport,
|
|
205
|
+
saveReport,
|
|
206
|
+
listDashboards,
|
|
207
|
+
getDashboard,
|
|
208
|
+
createDashboard,
|
|
209
|
+
updateDashboard,
|
|
210
|
+
listDashboardReports,
|
|
211
|
+
queryReportData,
|
|
212
|
+
querySql
|
|
213
|
+
];
|
|
214
|
+
var analysis_default = commands;
|
|
215
|
+
export {
|
|
216
|
+
analysis_default as default
|
|
217
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearToken,
|
|
3
|
+
getToken,
|
|
4
|
+
resolveHost
|
|
5
|
+
} from "./chunk-P7NQZGSZ.js";
|
|
6
|
+
|
|
7
|
+
// src/core/client.ts
|
|
8
|
+
import WebSocket from "ws";
|
|
9
|
+
import { randomBytes } from "crypto";
|
|
10
|
+
function genRequestId(prefix) {
|
|
11
|
+
const rand = randomBytes(4).toString("base64url").slice(0, 8);
|
|
12
|
+
return `${prefix}@@${rand}`;
|
|
13
|
+
}
|
|
14
|
+
function buildUrl(baseUrl, modulePath, params = {}) {
|
|
15
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
16
|
+
const p = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
17
|
+
const url = new URL(`${base}${p}`);
|
|
18
|
+
for (const [k, v] of Object.entries(params)) {
|
|
19
|
+
if (v !== void 0 && v !== null) url.searchParams.set(k, String(v));
|
|
20
|
+
}
|
|
21
|
+
return url.toString();
|
|
22
|
+
}
|
|
23
|
+
function buildWsUrl(baseUrl, token) {
|
|
24
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
25
|
+
const wsBase = base.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://");
|
|
26
|
+
return `${wsBase}/v1/ta-websocket/query/${token}`;
|
|
27
|
+
}
|
|
28
|
+
async function request(method, modulePath, params = {}, body = null, retry = true, hostUrl) {
|
|
29
|
+
const resolvedHost = resolveHost(hostUrl);
|
|
30
|
+
const token = await getToken(resolvedHost);
|
|
31
|
+
const url = buildUrl(resolvedHost, modulePath, params);
|
|
32
|
+
const headers = {
|
|
33
|
+
"Authorization": `bearer ${token}`,
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
};
|
|
36
|
+
const options = { method, headers };
|
|
37
|
+
if (body && method !== "GET") options.body = JSON.stringify(body);
|
|
38
|
+
if (process.env.TE_DEBUG) {
|
|
39
|
+
console.error(`[DEBUG] ${method} ${url}`);
|
|
40
|
+
console.error(`[DEBUG] body: ${options.body ?? "(none)"}`);
|
|
41
|
+
}
|
|
42
|
+
const resp = await fetch(url, options);
|
|
43
|
+
if ((resp.status === 401 || resp.status === 403) && retry) {
|
|
44
|
+
clearToken(resolvedHost);
|
|
45
|
+
return request(method, modulePath, params, body, false, resolvedHost);
|
|
46
|
+
}
|
|
47
|
+
const data = await resp.json();
|
|
48
|
+
if (data.return_code === -1001 && retry) {
|
|
49
|
+
clearToken(resolvedHost);
|
|
50
|
+
return request(method, modulePath, params, body, false, resolvedHost);
|
|
51
|
+
}
|
|
52
|
+
if (data.return_code !== 0 && data.return_code !== void 0) {
|
|
53
|
+
throw new Error(`TE API error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
|
|
54
|
+
}
|
|
55
|
+
return data.data !== void 0 ? data.data : data;
|
|
56
|
+
}
|
|
57
|
+
async function httpGet(modulePath, params = {}, hostUrl) {
|
|
58
|
+
return request("GET", modulePath, params, null, true, hostUrl);
|
|
59
|
+
}
|
|
60
|
+
async function httpPost(modulePath, params = {}, body, hostUrl) {
|
|
61
|
+
return request("POST", modulePath, params, body ?? {}, true, hostUrl);
|
|
62
|
+
}
|
|
63
|
+
async function wsQueryOnce(projectId, requestId, qp, eventModel, options = {}, token, hostUrl, timeoutMs = 3e4) {
|
|
64
|
+
const wsUrl = buildWsUrl(hostUrl, token);
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const ws = new WebSocket(wsUrl);
|
|
67
|
+
const timer = setTimeout(() => {
|
|
68
|
+
ws.close();
|
|
69
|
+
reject(new Error(`WebSocket query timed out after ${timeoutMs}ms`));
|
|
70
|
+
}, timeoutMs);
|
|
71
|
+
ws.on("open", () => {
|
|
72
|
+
const payload = {
|
|
73
|
+
requestId,
|
|
74
|
+
projectId,
|
|
75
|
+
eventModel,
|
|
76
|
+
qp: typeof qp === "string" ? qp : JSON.stringify(qp),
|
|
77
|
+
searchSource: options.searchSource || "reportQuery",
|
|
78
|
+
querySource: options.querySource || "single_report",
|
|
79
|
+
contentTranslate: options.contentTranslate !== false,
|
|
80
|
+
...options.extra || {}
|
|
81
|
+
};
|
|
82
|
+
ws.send(JSON.stringify(["data", payload, { channel: "ta" }]));
|
|
83
|
+
});
|
|
84
|
+
ws.on("message", (raw) => {
|
|
85
|
+
try {
|
|
86
|
+
const msg = JSON.parse(raw.toString());
|
|
87
|
+
if (Array.isArray(msg) && msg.length >= 2) {
|
|
88
|
+
const data = msg[1];
|
|
89
|
+
if (data.requestId === requestId && data.progress === 100) {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
ws.close();
|
|
92
|
+
resolve(data);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
ws.on("error", (err) => {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
reject(err);
|
|
101
|
+
});
|
|
102
|
+
ws.on("close", () => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async function wsQuery(projectId, requestId, qp, eventModel, options = {}, hostUrl) {
|
|
108
|
+
const resolvedHost = resolveHost(hostUrl);
|
|
109
|
+
const token = await getToken(resolvedHost);
|
|
110
|
+
try {
|
|
111
|
+
return await wsQueryOnce(projectId, requestId, qp, eventModel, options, token, resolvedHost);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
const msg = err.message || "";
|
|
114
|
+
if (msg.includes("401") || msg.includes("403") || msg.includes("auth")) {
|
|
115
|
+
clearToken(resolvedHost);
|
|
116
|
+
const newToken = await getToken(resolvedHost);
|
|
117
|
+
return wsQueryOnce(projectId, requestId, qp, eventModel, options, newToken, resolvedHost);
|
|
118
|
+
}
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function querySql(projectId, sql, hostUrl) {
|
|
123
|
+
const requestId = genRequestId("sqlIde");
|
|
124
|
+
const qp = {
|
|
125
|
+
events: { sql },
|
|
126
|
+
eventView: { sqlViewParams: [] }
|
|
127
|
+
};
|
|
128
|
+
return wsQuery(projectId, requestId, qp, 10, {
|
|
129
|
+
searchSource: "sqlIde",
|
|
130
|
+
querySource: "sqlIde"
|
|
131
|
+
}, hostUrl);
|
|
132
|
+
}
|
|
133
|
+
async function queryReportData(projectId, reportId, qp, eventModel, options = {}, hostUrl) {
|
|
134
|
+
const requestId = genRequestId("reportQuery");
|
|
135
|
+
return wsQuery(projectId, requestId, qp, eventModel, {
|
|
136
|
+
searchSource: "reportQuery",
|
|
137
|
+
querySource: "single_report",
|
|
138
|
+
...options
|
|
139
|
+
}, hostUrl);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
httpGet,
|
|
144
|
+
httpPost,
|
|
145
|
+
wsQuery,
|
|
146
|
+
querySql,
|
|
147
|
+
queryReportData
|
|
148
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearToken,
|
|
3
|
+
getToken,
|
|
4
|
+
resolveHost
|
|
5
|
+
} from "./chunk-P7NQZGSZ.js";
|
|
6
|
+
|
|
7
|
+
// src/core/client.ts
|
|
8
|
+
import WebSocket from "ws";
|
|
9
|
+
import { randomBytes } from "crypto";
|
|
10
|
+
function genRequestId(prefix) {
|
|
11
|
+
const rand = randomBytes(4).toString("base64url").slice(0, 8);
|
|
12
|
+
return `${prefix}@@${rand}`;
|
|
13
|
+
}
|
|
14
|
+
function buildUrl(baseUrl, modulePath, params = {}) {
|
|
15
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
16
|
+
const p = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
17
|
+
const url = new URL(`${base}${p}`);
|
|
18
|
+
for (const [k, v] of Object.entries(params)) {
|
|
19
|
+
if (v !== void 0 && v !== null) url.searchParams.set(k, String(v));
|
|
20
|
+
}
|
|
21
|
+
return url.toString();
|
|
22
|
+
}
|
|
23
|
+
function buildWsUrl(baseUrl, token) {
|
|
24
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
25
|
+
const wsBase = base.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://");
|
|
26
|
+
return `${wsBase}/v1/ta-websocket/query/${token}`;
|
|
27
|
+
}
|
|
28
|
+
async function request(method, modulePath, params = {}, body = null, retry = true, hostUrl) {
|
|
29
|
+
const resolvedHost = resolveHost(hostUrl);
|
|
30
|
+
const token = await getToken(resolvedHost);
|
|
31
|
+
const url = buildUrl(resolvedHost, modulePath, params);
|
|
32
|
+
const headers = {
|
|
33
|
+
"Authorization": `bearer ${token}`,
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
};
|
|
36
|
+
const options = { method, headers };
|
|
37
|
+
if (body && method !== "GET") options.body = JSON.stringify(body);
|
|
38
|
+
const resp = await fetch(url, options);
|
|
39
|
+
if ((resp.status === 401 || resp.status === 403) && retry) {
|
|
40
|
+
clearToken(resolvedHost);
|
|
41
|
+
return request(method, modulePath, params, body, false, resolvedHost);
|
|
42
|
+
}
|
|
43
|
+
const data = await resp.json();
|
|
44
|
+
if (data.return_code === -1001 && retry) {
|
|
45
|
+
clearToken(resolvedHost);
|
|
46
|
+
return request(method, modulePath, params, body, false, resolvedHost);
|
|
47
|
+
}
|
|
48
|
+
if (data.return_code !== 0 && data.return_code !== void 0) {
|
|
49
|
+
throw new Error(`TE API error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
|
|
50
|
+
}
|
|
51
|
+
return data.data !== void 0 ? data.data : data;
|
|
52
|
+
}
|
|
53
|
+
async function httpGet(modulePath, params = {}, hostUrl) {
|
|
54
|
+
return request("GET", modulePath, params, null, true, hostUrl);
|
|
55
|
+
}
|
|
56
|
+
async function httpPost(modulePath, params = {}, body, hostUrl) {
|
|
57
|
+
return request("POST", modulePath, params, body ?? {}, true, hostUrl);
|
|
58
|
+
}
|
|
59
|
+
async function wsQueryOnce(projectId, requestId, qp, eventModel, options = {}, token, hostUrl, timeoutMs = 3e4) {
|
|
60
|
+
const wsUrl = buildWsUrl(hostUrl, token);
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const ws = new WebSocket(wsUrl);
|
|
63
|
+
const timer = setTimeout(() => {
|
|
64
|
+
ws.close();
|
|
65
|
+
reject(new Error(`WebSocket query timed out after ${timeoutMs}ms`));
|
|
66
|
+
}, timeoutMs);
|
|
67
|
+
ws.on("open", () => {
|
|
68
|
+
const payload = {
|
|
69
|
+
requestId,
|
|
70
|
+
projectId,
|
|
71
|
+
eventModel,
|
|
72
|
+
qp: typeof qp === "string" ? qp : JSON.stringify(qp),
|
|
73
|
+
searchSource: options.searchSource || "reportQuery",
|
|
74
|
+
querySource: options.querySource || "single_report",
|
|
75
|
+
contentTranslate: options.contentTranslate !== false,
|
|
76
|
+
...options.extra || {}
|
|
77
|
+
};
|
|
78
|
+
ws.send(JSON.stringify(["data", payload, { channel: "ta" }]));
|
|
79
|
+
});
|
|
80
|
+
ws.on("message", (raw) => {
|
|
81
|
+
try {
|
|
82
|
+
const msg = JSON.parse(raw.toString());
|
|
83
|
+
if (Array.isArray(msg) && msg.length >= 2) {
|
|
84
|
+
const data = msg[1];
|
|
85
|
+
if (data.requestId === requestId && data.progress === 100) {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
ws.close();
|
|
88
|
+
resolve(data);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
ws.on("error", (err) => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
reject(err);
|
|
97
|
+
});
|
|
98
|
+
ws.on("close", () => {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
async function wsQuery(projectId, requestId, qp, eventModel, options = {}, hostUrl) {
|
|
104
|
+
const resolvedHost = resolveHost(hostUrl);
|
|
105
|
+
const token = await getToken(resolvedHost);
|
|
106
|
+
try {
|
|
107
|
+
return await wsQueryOnce(projectId, requestId, qp, eventModel, options, token, resolvedHost);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
const msg = err.message || "";
|
|
110
|
+
if (msg.includes("401") || msg.includes("403") || msg.includes("auth")) {
|
|
111
|
+
clearToken(resolvedHost);
|
|
112
|
+
const newToken = await getToken(resolvedHost);
|
|
113
|
+
return wsQueryOnce(projectId, requestId, qp, eventModel, options, newToken, resolvedHost);
|
|
114
|
+
}
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async function querySql(projectId, sql, hostUrl) {
|
|
119
|
+
const requestId = genRequestId("sqlIde");
|
|
120
|
+
const qp = {
|
|
121
|
+
events: { sql },
|
|
122
|
+
eventView: { sqlViewParams: [] }
|
|
123
|
+
};
|
|
124
|
+
return wsQuery(projectId, requestId, qp, 10, {
|
|
125
|
+
searchSource: "sqlIde",
|
|
126
|
+
querySource: "sqlIde"
|
|
127
|
+
}, hostUrl);
|
|
128
|
+
}
|
|
129
|
+
async function queryReportData(projectId, reportId, qp, eventModel, options = {}, hostUrl) {
|
|
130
|
+
const dashboardId = options.dashboardId || 0;
|
|
131
|
+
const requestId = genRequestId(`${projectId}_${dashboardId}_${reportId}`);
|
|
132
|
+
return wsQuery(projectId, requestId, qp, eventModel, {
|
|
133
|
+
searchSource: options.searchSource || "model_search",
|
|
134
|
+
querySource: options.querySource || "module",
|
|
135
|
+
...options
|
|
136
|
+
}, hostUrl);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
httpGet,
|
|
141
|
+
httpPost,
|
|
142
|
+
wsQuery,
|
|
143
|
+
querySql,
|
|
144
|
+
queryReportData
|
|
145
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearToken,
|
|
3
|
+
getToken,
|
|
4
|
+
resolveHost
|
|
5
|
+
} from "./chunk-P7NQZGSZ.js";
|
|
6
|
+
|
|
7
|
+
// src/core/client.ts
|
|
8
|
+
import WebSocket from "ws";
|
|
9
|
+
import { randomBytes } from "crypto";
|
|
10
|
+
function genRequestId(prefix) {
|
|
11
|
+
const rand = randomBytes(4).toString("base64url").slice(0, 8);
|
|
12
|
+
return `${prefix}@@${rand}`;
|
|
13
|
+
}
|
|
14
|
+
function buildUrl(baseUrl, modulePath, params = {}) {
|
|
15
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
16
|
+
const p = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
17
|
+
const url = new URL(`${base}${p}`);
|
|
18
|
+
for (const [k, v] of Object.entries(params)) {
|
|
19
|
+
if (v !== void 0 && v !== null) url.searchParams.set(k, String(v));
|
|
20
|
+
}
|
|
21
|
+
return url.toString();
|
|
22
|
+
}
|
|
23
|
+
function buildWsUrl(baseUrl, token) {
|
|
24
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
25
|
+
const wsBase = base.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://");
|
|
26
|
+
return `${wsBase}/v1/ta-websocket/query/${token}`;
|
|
27
|
+
}
|
|
28
|
+
async function request(method, modulePath, params = {}, body = null, retry = true, hostUrl) {
|
|
29
|
+
const resolvedHost = resolveHost(hostUrl);
|
|
30
|
+
const token = await getToken(resolvedHost);
|
|
31
|
+
const url = buildUrl(resolvedHost, modulePath, params);
|
|
32
|
+
const headers = {
|
|
33
|
+
"Authorization": `bearer ${token}`,
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
};
|
|
36
|
+
const options = { method, headers };
|
|
37
|
+
if (body && method !== "GET") options.body = JSON.stringify(body);
|
|
38
|
+
if (process.env.TE_DEBUG) {
|
|
39
|
+
console.error(`[DEBUG] ${method} ${url}`);
|
|
40
|
+
console.error(`[DEBUG] body: ${options.body ?? "(none)"}`);
|
|
41
|
+
}
|
|
42
|
+
const resp = await fetch(url, options);
|
|
43
|
+
if ((resp.status === 401 || resp.status === 403) && retry) {
|
|
44
|
+
clearToken(resolvedHost);
|
|
45
|
+
return request(method, modulePath, params, body, false, resolvedHost);
|
|
46
|
+
}
|
|
47
|
+
const data = await resp.json();
|
|
48
|
+
if (data.return_code === -1001 && retry) {
|
|
49
|
+
clearToken(resolvedHost);
|
|
50
|
+
return request(method, modulePath, params, body, false, resolvedHost);
|
|
51
|
+
}
|
|
52
|
+
if (data.return_code !== 0 && data.return_code !== void 0) {
|
|
53
|
+
throw new Error(`TE API error: ${data.return_message || "unknown"} (code: ${data.return_code})`);
|
|
54
|
+
}
|
|
55
|
+
return data.data !== void 0 ? data.data : data;
|
|
56
|
+
}
|
|
57
|
+
async function httpGet(modulePath, params = {}, hostUrl) {
|
|
58
|
+
return request("GET", modulePath, params, null, true, hostUrl);
|
|
59
|
+
}
|
|
60
|
+
async function httpPost(modulePath, params = {}, body, hostUrl) {
|
|
61
|
+
return request("POST", modulePath, params, body ?? {}, true, hostUrl);
|
|
62
|
+
}
|
|
63
|
+
async function wsQueryOnce(projectId, requestId, qp, eventModel, options = {}, token, hostUrl, timeoutMs = 3e4) {
|
|
64
|
+
const wsUrl = buildWsUrl(hostUrl, token);
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const ws = new WebSocket(wsUrl);
|
|
67
|
+
const timer = setTimeout(() => {
|
|
68
|
+
ws.close();
|
|
69
|
+
reject(new Error(`WebSocket query timed out after ${timeoutMs}ms`));
|
|
70
|
+
}, timeoutMs);
|
|
71
|
+
ws.on("open", () => {
|
|
72
|
+
const payload = {
|
|
73
|
+
requestId,
|
|
74
|
+
projectId,
|
|
75
|
+
eventModel,
|
|
76
|
+
qp: typeof qp === "string" ? qp : JSON.stringify(qp),
|
|
77
|
+
searchSource: options.searchSource || "reportQuery",
|
|
78
|
+
querySource: options.querySource || "single_report",
|
|
79
|
+
contentTranslate: options.contentTranslate !== false,
|
|
80
|
+
...options.extra || {}
|
|
81
|
+
};
|
|
82
|
+
ws.send(JSON.stringify(["data", payload, { channel: "ta" }]));
|
|
83
|
+
});
|
|
84
|
+
ws.on("message", (raw) => {
|
|
85
|
+
try {
|
|
86
|
+
const msg = JSON.parse(raw.toString());
|
|
87
|
+
if (Array.isArray(msg) && msg.length >= 2) {
|
|
88
|
+
const data = msg[1];
|
|
89
|
+
if (data.requestId === requestId && data.progress === 100) {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
ws.close();
|
|
92
|
+
resolve(data);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
ws.on("error", (err) => {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
reject(err);
|
|
101
|
+
});
|
|
102
|
+
ws.on("close", () => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async function wsQuery(projectId, requestId, qp, eventModel, options = {}, hostUrl) {
|
|
108
|
+
const resolvedHost = resolveHost(hostUrl);
|
|
109
|
+
const token = await getToken(resolvedHost);
|
|
110
|
+
try {
|
|
111
|
+
return await wsQueryOnce(projectId, requestId, qp, eventModel, options, token, resolvedHost);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
const msg = err.message || "";
|
|
114
|
+
if (msg.includes("401") || msg.includes("403") || msg.includes("auth")) {
|
|
115
|
+
clearToken(resolvedHost);
|
|
116
|
+
const newToken = await getToken(resolvedHost);
|
|
117
|
+
return wsQueryOnce(projectId, requestId, qp, eventModel, options, newToken, resolvedHost);
|
|
118
|
+
}
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function querySql(projectId, sql, hostUrl) {
|
|
123
|
+
const requestId = genRequestId("sqlIde");
|
|
124
|
+
const qp = {
|
|
125
|
+
events: { sql },
|
|
126
|
+
eventView: { sqlViewParams: [] }
|
|
127
|
+
};
|
|
128
|
+
return wsQuery(projectId, requestId, qp, 10, {
|
|
129
|
+
searchSource: "sqlIde",
|
|
130
|
+
querySource: "sqlIde"
|
|
131
|
+
}, hostUrl);
|
|
132
|
+
}
|
|
133
|
+
async function queryReportData(projectId, reportId, qp, eventModel, options = {}, hostUrl) {
|
|
134
|
+
const dashboardId = options.dashboardId || 0;
|
|
135
|
+
const requestId = genRequestId(`${projectId}_${dashboardId}_${reportId}`);
|
|
136
|
+
return wsQuery(projectId, requestId, qp, eventModel, {
|
|
137
|
+
searchSource: options.searchSource || "model_search",
|
|
138
|
+
querySource: options.querySource || "module",
|
|
139
|
+
...options
|
|
140
|
+
}, hostUrl);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export {
|
|
144
|
+
httpGet,
|
|
145
|
+
httpPost,
|
|
146
|
+
wsQuery,
|
|
147
|
+
querySql,
|
|
148
|
+
queryReportData
|
|
149
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpGet,
|
|
3
|
+
httpPost,
|
|
4
|
+
queryReportData,
|
|
5
|
+
querySql,
|
|
6
|
+
wsQuery
|
|
7
|
+
} from "./chunk-GZG7YDWV.js";
|
|
8
|
+
import "./chunk-P7NQZGSZ.js";
|
|
9
|
+
import "./chunk-CFCHSAMQ.js";
|
|
10
|
+
export {
|
|
11
|
+
httpGet,
|
|
12
|
+
httpPost,
|
|
13
|
+
queryReportData,
|
|
14
|
+
querySql,
|
|
15
|
+
wsQuery
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpGet,
|
|
3
|
+
httpPost,
|
|
4
|
+
queryReportData,
|
|
5
|
+
querySql,
|
|
6
|
+
wsQuery
|
|
7
|
+
} from "./chunk-4OJI46I5.js";
|
|
8
|
+
import "./chunk-P7NQZGSZ.js";
|
|
9
|
+
import "./chunk-CFCHSAMQ.js";
|
|
10
|
+
export {
|
|
11
|
+
httpGet,
|
|
12
|
+
httpPost,
|
|
13
|
+
queryReportData,
|
|
14
|
+
querySql,
|
|
15
|
+
wsQuery
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpGet,
|
|
3
|
+
httpPost,
|
|
4
|
+
queryReportData,
|
|
5
|
+
querySql,
|
|
6
|
+
wsQuery
|
|
7
|
+
} from "./chunk-O6AQSK3A.js";
|
|
8
|
+
import "./chunk-P7NQZGSZ.js";
|
|
9
|
+
import "./chunk-CFCHSAMQ.js";
|
|
10
|
+
export {
|
|
11
|
+
httpGet,
|
|
12
|
+
httpPost,
|
|
13
|
+
queryReportData,
|
|
14
|
+
querySql,
|
|
15
|
+
wsQuery
|
|
16
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -60,7 +60,7 @@ function createRuntimeContext(cmd, opts, globalOpts) {
|
|
|
60
60
|
let _clientModule = null;
|
|
61
61
|
async function getClient() {
|
|
62
62
|
if (!_clientModule) {
|
|
63
|
-
_clientModule = await import("./client-
|
|
63
|
+
_clientModule = await import("./client-6TVMBUGP.js");
|
|
64
64
|
}
|
|
65
65
|
return _clientModule;
|
|
66
66
|
}
|
|
@@ -191,7 +191,7 @@ async function loadCommands() {
|
|
|
191
191
|
} catch {
|
|
192
192
|
}
|
|
193
193
|
try {
|
|
194
|
-
const analysis = await import("./analysis-
|
|
194
|
+
const analysis = await import("./analysis-M54YNGTJ.js");
|
|
195
195
|
commands.push(...analysis.default);
|
|
196
196
|
} catch {
|
|
197
197
|
}
|
|
@@ -223,7 +223,7 @@ async function registerConfigCommands() {
|
|
|
223
223
|
}
|
|
224
224
|
async function registerApiCommand() {
|
|
225
225
|
try {
|
|
226
|
-
const { registerApi } = await import("./raw-
|
|
226
|
+
const { registerApi } = await import("./raw-M3K7FAJ4.js");
|
|
227
227
|
registerApi(program);
|
|
228
228
|
} catch {
|
|
229
229
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpGet,
|
|
3
|
+
httpPost
|
|
4
|
+
} from "./chunk-4OJI46I5.js";
|
|
5
|
+
import {
|
|
6
|
+
printError,
|
|
7
|
+
printOutput
|
|
8
|
+
} from "./chunk-KM57HI5B.js";
|
|
9
|
+
import {
|
|
10
|
+
resolveHost
|
|
11
|
+
} from "./chunk-P7NQZGSZ.js";
|
|
12
|
+
import "./chunk-CFCHSAMQ.js";
|
|
13
|
+
|
|
14
|
+
// src/api/raw.ts
|
|
15
|
+
function registerApi(program) {
|
|
16
|
+
program.command("api").description("Raw API call: te-cli api <METHOD> <PATH> [options]").argument("<method>", "HTTP method (GET, POST)").argument("<path>", "API path (e.g., /v1/ta/event/catalog/listEvent)").option("--params <json>", "URL parameters as JSON").option("--data <json>", "Request body as JSON").action(async (method, apiPath, opts) => {
|
|
17
|
+
const globalOpts = program.opts();
|
|
18
|
+
const host = resolveHost(globalOpts.host);
|
|
19
|
+
const format = globalOpts.format || "json";
|
|
20
|
+
const jq = globalOpts.jq;
|
|
21
|
+
if (!host) {
|
|
22
|
+
printError("config", "No TE host configured.", "Run: te-cli config set-host");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
let params = {};
|
|
27
|
+
let body = void 0;
|
|
28
|
+
if (opts.params) {
|
|
29
|
+
try {
|
|
30
|
+
params = JSON.parse(opts.params);
|
|
31
|
+
} catch {
|
|
32
|
+
printError("validation", `Invalid JSON for --params: ${opts.params}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (opts.data) {
|
|
37
|
+
try {
|
|
38
|
+
body = JSON.parse(opts.data);
|
|
39
|
+
} catch {
|
|
40
|
+
printError("validation", `Invalid JSON for --data: ${opts.data}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let result;
|
|
45
|
+
if (method.toUpperCase() === "GET") {
|
|
46
|
+
result = await httpGet(apiPath, params, host);
|
|
47
|
+
} else {
|
|
48
|
+
result = await httpPost(apiPath, params, body, host);
|
|
49
|
+
}
|
|
50
|
+
printOutput(result, format, jq);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
printError("api", err.message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
registerApi
|
|
59
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpGet,
|
|
3
|
+
httpPost
|
|
4
|
+
} from "./chunk-GZG7YDWV.js";
|
|
5
|
+
import {
|
|
6
|
+
printError,
|
|
7
|
+
printOutput
|
|
8
|
+
} from "./chunk-KM57HI5B.js";
|
|
9
|
+
import {
|
|
10
|
+
resolveHost
|
|
11
|
+
} from "./chunk-P7NQZGSZ.js";
|
|
12
|
+
import "./chunk-CFCHSAMQ.js";
|
|
13
|
+
|
|
14
|
+
// src/api/raw.ts
|
|
15
|
+
function registerApi(program) {
|
|
16
|
+
program.command("api").description("Raw API call: te-cli api <METHOD> <PATH> [options]").argument("<method>", "HTTP method (GET, POST)").argument("<path>", "API path (e.g., /v1/ta/event/catalog/listEvent)").option("--params <json>", "URL parameters as JSON").option("--data <json>", "Request body as JSON").action(async (method, apiPath, opts) => {
|
|
17
|
+
const globalOpts = program.opts();
|
|
18
|
+
const host = resolveHost(globalOpts.host);
|
|
19
|
+
const format = globalOpts.format || "json";
|
|
20
|
+
const jq = globalOpts.jq;
|
|
21
|
+
if (!host) {
|
|
22
|
+
printError("config", "No TE host configured.", "Run: te-cli config set-host");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
let params = {};
|
|
27
|
+
let body = void 0;
|
|
28
|
+
if (opts.params) {
|
|
29
|
+
try {
|
|
30
|
+
params = JSON.parse(opts.params);
|
|
31
|
+
} catch {
|
|
32
|
+
printError("validation", `Invalid JSON for --params: ${opts.params}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (opts.data) {
|
|
37
|
+
try {
|
|
38
|
+
body = JSON.parse(opts.data);
|
|
39
|
+
} catch {
|
|
40
|
+
printError("validation", `Invalid JSON for --data: ${opts.data}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let result;
|
|
45
|
+
if (method.toUpperCase() === "GET") {
|
|
46
|
+
result = await httpGet(apiPath, params, host);
|
|
47
|
+
} else {
|
|
48
|
+
result = await httpPost(apiPath, params, body, host);
|
|
49
|
+
}
|
|
50
|
+
printOutput(result, format, jq);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
printError("api", err.message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
registerApi
|
|
59
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
httpGet,
|
|
3
|
+
httpPost
|
|
4
|
+
} from "./chunk-O6AQSK3A.js";
|
|
5
|
+
import {
|
|
6
|
+
printError,
|
|
7
|
+
printOutput
|
|
8
|
+
} from "./chunk-KM57HI5B.js";
|
|
9
|
+
import {
|
|
10
|
+
resolveHost
|
|
11
|
+
} from "./chunk-P7NQZGSZ.js";
|
|
12
|
+
import "./chunk-CFCHSAMQ.js";
|
|
13
|
+
|
|
14
|
+
// src/api/raw.ts
|
|
15
|
+
function registerApi(program) {
|
|
16
|
+
program.command("api").description("Raw API call: te-cli api <METHOD> <PATH> [options]").argument("<method>", "HTTP method (GET, POST)").argument("<path>", "API path (e.g., /v1/ta/event/catalog/listEvent)").option("--params <json>", "URL parameters as JSON").option("--data <json>", "Request body as JSON").action(async (method, apiPath, opts) => {
|
|
17
|
+
const globalOpts = program.opts();
|
|
18
|
+
const host = resolveHost(globalOpts.host);
|
|
19
|
+
const format = globalOpts.format || "json";
|
|
20
|
+
const jq = globalOpts.jq;
|
|
21
|
+
if (!host) {
|
|
22
|
+
printError("config", "No TE host configured.", "Run: te-cli config set-host");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
let params = {};
|
|
27
|
+
let body = void 0;
|
|
28
|
+
if (opts.params) {
|
|
29
|
+
try {
|
|
30
|
+
params = JSON.parse(opts.params);
|
|
31
|
+
} catch {
|
|
32
|
+
printError("validation", `Invalid JSON for --params: ${opts.params}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (opts.data) {
|
|
37
|
+
try {
|
|
38
|
+
body = JSON.parse(opts.data);
|
|
39
|
+
} catch {
|
|
40
|
+
printError("validation", `Invalid JSON for --data: ${opts.data}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let result;
|
|
45
|
+
if (method.toUpperCase() === "GET") {
|
|
46
|
+
result = await httpGet(apiPath, params, host);
|
|
47
|
+
} else {
|
|
48
|
+
result = await httpPost(apiPath, params, body, host);
|
|
49
|
+
}
|
|
50
|
+
printOutput(result, format, jq);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
printError("api", err.message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
registerApi
|
|
59
|
+
};
|