From cb6d3f7ee052e307923835e76063652dddeb63a9 Mon Sep 17 00:00:00 2001 From: xue jiahao Date: Thu, 12 Mar 2026 15:11:41 +0800 Subject: [PATCH] fix ts problem --- src/main/ipc-handlers.ts | 14 +-- src/main/kintone-api.ts | 112 ++++++++---------- src/preload/index.d.ts | 4 +- src/preload/index.ts | 4 +- .../src/components/AppDetail/AppDetail.tsx | 2 +- src/shared/types/kintone.ts | 8 +- 6 files changed, 67 insertions(+), 77 deletions(-) diff --git a/src/main/ipc-handlers.ts b/src/main/ipc-handlers.ts index 2827fb1..d055d1b 100644 --- a/src/main/ipc-handlers.ts +++ b/src/main/ipc-handlers.ts @@ -16,7 +16,7 @@ import { saveDownload, saveBackup, } from "./storage"; -import { KintoneClient, createKintoneClient } from "./kintone-api"; +import { SelfKintoneClient, createKintoneClient } from "./kintone-api"; import type { Result } from "@shared/types/ipc"; import type { CreateDomainParams, @@ -41,12 +41,12 @@ import type { } from "@shared/types/version"; // Cache for Kintone clients -const clientCache = new Map(); +const clientCache = new Map(); /** * Get or create a Kintone client for a domain */ -async function getClient(domainId: string): Promise { +async function getClient(domainId: string): Promise { if (clientCache.has(domainId)) { return clientCache.get(domainId)!; } @@ -243,7 +243,7 @@ function registerTestDomainConnection(): void { function registerGetSpaces(): void { handleWithParams< GetSpacesParams, - Awaited> + Awaited> >("getSpaces", async (params) => { const client = await getClient(params.domainId); return client.getSpaces(); @@ -256,7 +256,7 @@ function registerGetSpaces(): void { function registerGetApps(): void { handleWithParams< GetAppsParams, - Awaited> + Awaited> >("getApps", async (params) => { const client = await getClient(params.domainId); return client.getApps(params.spaceId); @@ -269,7 +269,7 @@ function registerGetApps(): void { function registerGetAppDetail(): void { handleWithParams< GetAppDetailParams, - Awaited> + Awaited> >("getAppDetail", async (params) => { const client = await getClient(params.domainId); return client.getAppDetail(params.appId); @@ -282,7 +282,7 @@ function registerGetAppDetail(): void { function registerGetFileContent(): void { handleWithParams< GetFileContentParams, - Awaited> + Awaited> >("getFileContent", async (params) => { const client = await getClient(params.domainId); return client.getFileContent(params.fileKey); diff --git a/src/main/kintone-api.ts b/src/main/kintone-api.ts index a4934ca..f835b1c 100644 --- a/src/main/kintone-api.ts +++ b/src/main/kintone-api.ts @@ -33,10 +33,17 @@ export class KintoneError extends Error { } } +// Use typeof to get SDK method return types +type KintoneClient = KintoneRestAPIClient; +type SpaceResponse = ReturnType; +type AppResponse = ReturnType; +type AppsResponse = ReturnType; +type AppCustomizeResponse = ReturnType; + /** * Kintone REST API Client */ -export class KintoneClient { +export class SelfKintoneClient { private client: KintoneRestAPIClient; private domain: string; @@ -82,39 +89,22 @@ export class KintoneClient { } } - private mapSpace(space: { - id: string | number; - name: string; - code: string; - createdAt?: string; - creator?: { code: string; name: string }; - }): KintoneSpace { + private mapSpace(space: Awaited): KintoneSpace { return { - id: String(space.id), + id: space.id, name: space.name, - code: space.code, - createdAt: space.createdAt, - creator: space.creator - ? { code: space.creator.code, name: space.creator.name } - : undefined, + code: "", // Space API doesn't return code + createdAt: undefined, // Space API doesn't return createdAt + creator: { code: space.creator.code, name: space.creator.name }, }; } - private mapApp(app: { - appId: string | number; - name: string; - code?: string; - spaceId?: string | number; - createdAt: string; - creator?: { code: string; name: string }; - modifiedAt?: string; - modifier?: { code: string; name: string }; - }): KintoneApp { + private mapApp(app: Awaited): KintoneApp { return { - appId: String(app.appId), + appId: app.appId, name: app.name, code: app.code, - spaceId: app.spaceId ? String(app.spaceId) : undefined, + spaceId: app.spaceId || undefined, createdAt: app.createdAt, creator: app.creator, modifiedAt: app.modifiedAt, @@ -122,15 +112,19 @@ export class KintoneClient { }; } - private mapResource(resource: { - type: string; - file?: { fileKey: string; name: string }; - url?: string; - }): JSFileConfig | CSSFileConfig { + private mapResource( + resource: + | Awaited["desktop"]["js"][number] + | Awaited["desktop"]["css"][number], + ): JSFileConfig | CSSFileConfig { return { - type: resource.type as "FILE" | "URL", + type: resource.type, file: resource.file - ? { fileKey: resource.file.fileKey, name: resource.file.name, size: 0 } + ? { + fileKey: resource.file.fileKey, + name: resource.file.name, + size: parseInt(resource.file.size, 10), + } : undefined, url: resource.url, }; @@ -139,9 +133,7 @@ export class KintoneClient { private buildCustomizeSection( js?: JSFileConfig[], css?: CSSFileConfig[], - ): - | { js?: CustomizeResourceItem[]; css?: CustomizeResourceItem[] } - | undefined { + ): Parameters[0] | undefined { if (!js && !css) return undefined; return { @@ -160,10 +152,18 @@ export class KintoneClient { // ==================== Space APIs ==================== + // Note: Kintone REST API does not provide an endpoint to list all spaces. + // Use getSpace(spaceId) to retrieve individual spaces. async getSpaces(): Promise { + // Since SDK doesn't have getSpaces and REST API doesn't support listing spaces, + // we return empty array. Users should use getSpace() for individual spaces. + return []; + } + + async getSpace(spaceId: string): Promise { return this.withErrorHandling(async () => { - const response = await this.client.space.getSpaces(); - return response.spaces.map((space) => this.mapSpace(space)); + const response = await this.client.space.getSpace({ id: spaceId }); + return this.mapSpace(response); }); } @@ -171,7 +171,7 @@ export class KintoneClient { async getApps(spaceId?: string): Promise { return this.withErrorHandling(async () => { - const params = spaceId ? { spaceId } : {}; + const params = spaceId ? { spaceIds: [spaceId] } : {}; const response = await this.client.app.getApps(params); return response.apps.map((app) => this.mapApp(app)); }); @@ -186,28 +186,26 @@ export class KintoneClient { const customization: AppCustomizationConfig = { javascript: { - pc: - customizeInfo.desktop?.js?.map((js) => this.mapResource(js)) || [], + pc: customizeInfo.desktop.js?.map((js) => this.mapResource(js)) || [], mobile: - customizeInfo.mobile?.js?.map((js) => this.mapResource(js)) || [], + customizeInfo.mobile.js?.map((js) => this.mapResource(js)) || [], }, stylesheet: { pc: - customizeInfo.desktop?.css?.map((css) => this.mapResource(css)) || + customizeInfo.desktop.css?.map((css) => this.mapResource(css)) || [], mobile: - customizeInfo.mobile?.css?.map((css) => this.mapResource(css)) || - [], + customizeInfo.mobile.css?.map((css) => this.mapResource(css)) || [], }, plugins: [], }; return { - appId: String(appInfo.appId), + appId: appInfo.appId, name: appInfo.name, code: appInfo.code, description: appInfo.description, - spaceId: appInfo.spaceId ? String(appInfo.spaceId) : undefined, + spaceId: appInfo.spaceId || undefined, createdAt: appInfo.createdAt, creator: appInfo.creator, modifiedAt: appInfo.modifiedAt, @@ -257,14 +255,10 @@ export class KintoneClient { return this.withErrorHandling(async () => { await this.client.app.updateAppCustomize({ app: appId, - desktop: this.buildCustomizeSection( + ...this.buildCustomizeSection( config.javascript?.pc, config.stylesheet?.pc, ), - mobile: this.buildCustomizeSection( - config.javascript?.mobile, - config.stylesheet?.mobile, - ), scope: "ALL", }); }); @@ -280,7 +274,7 @@ export class KintoneClient { appId: string, ): Promise<"PROCESSING" | "SUCCESS" | "FAIL" | "CANCEL"> { return this.withErrorHandling(async () => { - const response = await this.client.app.getDeployStatus({ app: appId }); + const response = await this.client.app.getDeployStatus({ apps: [appId] }); return response.apps[0]?.status || "FAIL"; }); } @@ -305,12 +299,8 @@ export class KintoneClient { } } -type CustomizeResourceItem = { - type: string; - file?: { fileKey: string }; - url?: string; -}; - -export function createKintoneClient(domain: DomainWithPassword): KintoneClient { - return new KintoneClient(domain); +export function createKintoneClient( + domain: DomainWithPassword, +): SelfKintoneClient { + return new SelfKintoneClient(domain); } diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index 92fc6fa..0dcf011 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -27,11 +27,11 @@ import type { Version } from "@shared/types/version"; declare global { interface Window { electron: ElectronAPI; - api: ElectronAPI; + api: SelfAPI; } } -export interface ElectronAPI { +export interface SelfAPI { // Platform detection platform: NodeJS.Platform; diff --git a/src/preload/index.ts b/src/preload/index.ts index 23df7e0..2cc2c17 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -1,9 +1,9 @@ import { contextBridge, ipcRenderer } from "electron"; import { electronAPI } from "@electron-toolkit/preload"; -import type { ElectronAPI } from "./index.d"; +import type { SelfAPI } from "./index.d"; // Custom APIs for renderer - bridges to IPC handlers -const api: ElectronAPI = { +const api: SelfAPI = { // Platform detection platform: process.platform, diff --git a/src/renderer/src/components/AppDetail/AppDetail.tsx b/src/renderer/src/components/AppDetail/AppDetail.tsx index 73f53de..c9b7816 100644 --- a/src/renderer/src/components/AppDetail/AppDetail.tsx +++ b/src/renderer/src/components/AppDetail/AppDetail.tsx @@ -5,7 +5,6 @@ import React from "react"; import { - Card, Descriptions, Tabs, Empty, @@ -25,6 +24,7 @@ import { createStyles } from "antd-style"; import { useAppStore } from "@renderer/stores"; import { useDomainStore } from "@renderer/stores"; import { CodeViewer } from "../CodeViewer"; +import { JSFileConfig, CSSFileConfig } from "@shared/types/kintone"; const useStyles = createStyles(({ token, css }) => ({ container: css` diff --git a/src/shared/types/kintone.ts b/src/shared/types/kintone.ts index bc75238..3c7ed80 100644 --- a/src/shared/types/kintone.ts +++ b/src/shared/types/kintone.ts @@ -38,8 +38,8 @@ export interface JSFileConfig { type: "FILE" | "URL"; file?: { fileKey: string; - name: string; - size: number; + name?: string; // Optional for deploy, filled by Kintone + size?: number; // Optional for deploy, filled by Kintone }; url?: string; } @@ -48,8 +48,8 @@ export interface CSSFileConfig { type: "FILE" | "URL"; file?: { fileKey: string; - name: string; - size: number; + name?: string; // Optional for deploy, filled by Kintone + size?: number; // Optional for deploy, filled by Kintone }; url?: string; }