galaxy-opc-plugin 0.2.8 → 0.2.9

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": "galaxy-opc-plugin",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 OpenClaw 插件",
5
5
  "keywords": [
6
6
  "openclaw",
@@ -215,7 +215,7 @@ export function registerCompanyRoutes(api: OpenClawPluginApi, db: OpcDatabase, g
215
215
  apiAny.registerHttpHandler(handler);
216
216
  } else if (typeof apiAny.registerHttpRoute === "function") {
217
217
  apiAny.registerHttpRoute({
218
- path: /^\/opc\/api\/companies(?:\/.*)?$/,
218
+ path: "/opc/api/companies",
219
219
  handler: async (req, res) => {
220
220
  const handled = await handler(req, res);
221
221
  if (!handled) {
@@ -72,7 +72,7 @@ export function registerConfigUiRoutes(api: OpenClawPluginApi, db: OpcDatabase,
72
72
 
73
73
  // GET /opc/admin/api/payments/:id
74
74
  api.registerHttpRoute({
75
- path: /^\/opc\/admin\/api\/payments\/([^/]+)$/,
75
+ path: '/opc/admin/api/payments',
76
76
  handler: async (req, res) => {
77
77
  const match = req.url?.match(/^\/opc\/admin\/api\/payments\/([^/]+)$/);
78
78
  if (!match) {
@@ -135,7 +135,7 @@ export function registerConfigUiRoutes(api: OpenClawPluginApi, db: OpcDatabase,
135
135
 
136
136
  // PUT /opc/admin/api/payments/:id - 更新收付款
137
137
  api.registerHttpRoute({
138
- path: /^\/opc\/admin\/api\/payments\/([^/]+)$/,
138
+ path: '/opc/admin/api/payments',
139
139
  handler: async (req, res) => {
140
140
  if (req.method !== 'PUT') return false;
141
141
 
@@ -180,7 +180,7 @@ export function registerConfigUiRoutes(api: OpenClawPluginApi, db: OpcDatabase,
180
180
 
181
181
  // POST /opc/admin/api/payments/:id/record - 记账
182
182
  api.registerHttpRoute({
183
- path: /^\/opc\/admin\/api\/payments\/([^/]+)\/record$/,
183
+ path: '/opc/admin/api/payments',
184
184
  handler: async (req, res) => {
185
185
  if (req.method !== 'POST') return false;
186
186
 
@@ -3123,32 +3123,32 @@ function getCanvasJs(): string {
3123
3123
 
3124
3124
  /* ── Route registration ───────────────────────────────────── */
3125
3125
 
3126
- export function registerConfigUi(api: OpenClawPluginApi, db: OpcDatabase, gatewayToken?: string): void {
3126
+ export function registerConfigUi(api: OpenClawPluginApi, db: OpcDatabase, gatewayToken?: string): void {
3127
3127
  // 注册 Dashboard API 路由
3128
3128
  registerDashboardApiRoutes(api, db);
3129
3129
 
3130
- const handler = async (req: IncomingMessage, res: ServerResponse): Promise<boolean> => {
3130
+ const handler = async (req: IncomingMessage, res: ServerResponse): Promise<boolean> => {
3131
3131
  const rawUrl = req.url ?? "";
3132
3132
  const urlObj = new URL(rawUrl, "http://localhost");
3133
3133
  const pathname = urlObj.pathname;
3134
3134
  const method = req.method?.toUpperCase() ?? "GET";
3135
3135
 
3136
- if (!pathname.startsWith("/opc/admin")) {
3137
- return false;
3138
- }
3139
-
3140
- // Normalize accidental SPA deep-links (e.g. /opc/admin/chat) back to OPC admin root.
3141
- // Without this, users may land on OpenClaw's default chat UI and think OPC admin failed to load.
3142
- if (
3143
- !pathname.startsWith("/opc/admin/api/")
3144
- && pathname !== "/opc/admin"
3145
- && pathname !== "/opc/admin/"
3146
- ) {
3147
- const tokenParam = gatewayToken ? `?token=${encodeURIComponent(gatewayToken)}` : "";
3148
- res.writeHead(302, { Location: `/opc/admin${tokenParam}` });
3149
- res.end();
3150
- return true;
3151
- }
3136
+ if (!pathname.startsWith("/opc/admin")) {
3137
+ return false;
3138
+ }
3139
+
3140
+ // Normalize accidental SPA deep-links (e.g. /opc/admin/chat) back to OPC admin root.
3141
+ // Without this, users may land on OpenClaw's default chat UI and think OPC admin failed to load.
3142
+ if (
3143
+ !pathname.startsWith("/opc/admin/api/")
3144
+ && pathname !== "/opc/admin"
3145
+ && pathname !== "/opc/admin/"
3146
+ ) {
3147
+ const tokenParam = gatewayToken ? `?token=${encodeURIComponent(gatewayToken)}` : "";
3148
+ res.writeHead(302, { Location: `/opc/admin${tokenParam}` });
3149
+ res.end();
3150
+ return true;
3151
+ }
3152
3152
 
3153
3153
  // API 端点需要认证
3154
3154
  if (pathname.startsWith("/opc/admin/api/") && gatewayToken) {
@@ -4169,29 +4169,29 @@ export function registerConfigUi(api: OpenClawPluginApi, db: OpcDatabase, gatewa
4169
4169
  res.end(JSON.stringify({ error: err instanceof Error ? err.message : String(err) }));
4170
4170
  return true;
4171
4171
  }
4172
- };
4173
-
4174
- const apiAny = api as unknown as {
4175
- registerHttpHandler?: (h: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
4176
- registerHttpRoute?: (r: { path: string | RegExp; handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void> }) => void;
4177
- };
4178
-
4179
- if (typeof apiAny.registerHttpHandler === "function") {
4180
- apiAny.registerHttpHandler(handler);
4181
- } else if (typeof apiAny.registerHttpRoute === "function") {
4182
- apiAny.registerHttpRoute({
4183
- path: /^\/opc\/admin(?:\/.*)?$/,
4184
- handler: async (req, res) => {
4185
- const handled = await handler(req, res);
4186
- if (!handled) {
4187
- res.writeHead(404, { "Content-Type": "application/json; charset=utf-8" });
4188
- res.end(JSON.stringify({ error: "Not found" }));
4189
- }
4190
- },
4191
- });
4192
- } else {
4193
- throw new Error("No compatible HTTP registration API found on OpenClaw plugin API");
4194
- }
4172
+ };
4173
+
4174
+ const apiAny = api as unknown as {
4175
+ registerHttpHandler?: (h: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
4176
+ registerHttpRoute?: (r: { path: string | RegExp; handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void> }) => void;
4177
+ };
4178
+
4179
+ if (typeof apiAny.registerHttpHandler === "function") {
4180
+ apiAny.registerHttpHandler(handler);
4181
+ } else if (typeof apiAny.registerHttpRoute === "function") {
4182
+ apiAny.registerHttpRoute({
4183
+ path: "/opc/admin",
4184
+ handler: async (req, res) => {
4185
+ const handled = await handler(req, res);
4186
+ if (!handled) {
4187
+ res.writeHead(404, { "Content-Type": "application/json; charset=utf-8" });
4188
+ res.end(JSON.stringify({ error: "Not found" }));
4189
+ }
4190
+ },
4191
+ });
4192
+ } else {
4193
+ throw new Error("No compatible HTTP registration API found on OpenClaw plugin API");
4194
+ }
4195
4195
 
4196
4196
  api.logger.info("opc: 已注册配置管理 UI (/opc/admin)");
4197
4197
  }
@@ -324,7 +324,7 @@ export function registerLandingPage(api: OpenClawPluginApi): void {
324
324
  apiAny.registerHttpHandler(handler);
325
325
  } else if (typeof apiAny.registerHttpRoute === "function") {
326
326
  apiAny.registerHttpRoute({
327
- path: /^\/$/,
327
+ path: "/",
328
328
  handler: async (req, res) => {
329
329
  const handled = await handler(req, res);
330
330
  if (!handled) {