This commit is contained in:
2026-03-12 17:42:00 +08:00
parent 914ca64c10
commit 78f31d44ec
6 changed files with 88 additions and 143 deletions

View File

@@ -2,13 +2,14 @@ import { KintoneRestAPIClient } from "@kintone/rest-api-client";
import type { KintoneRestAPIError } from "@kintone/rest-api-client";
import type { DomainWithPassword } from "@shared/types/domain";
import type {
KintoneApp,
AppResponse,
AppsResponse,
AppCustomizeResponse,
AppDetail,
FileContent,
AppCustomizationConfig,
KintoneApiError,
JSFileConfig,
CSSFileConfig,
FileConfig,
} from "@shared/types/kintone";
/**
@@ -32,12 +33,6 @@ export class KintoneError extends Error {
}
}
// Use typeof to get SDK method return types
type KintoneClient = KintoneRestAPIClient;
type AppResponse = ReturnType<KintoneClient["app"]["getApp"]>;
type AppsResponse = ReturnType<KintoneClient["app"]["getApps"]>;
type AppCustomizeResponse = ReturnType<KintoneClient["app"]["getAppCustomize"]>;
/**
* Kintone REST API Client
*/
@@ -87,48 +82,24 @@ export class SelfKintoneClient {
}
}
private mapApp(app: Awaited<AppResponse>): KintoneApp {
return {
appId: app.appId,
name: app.name,
code: app.code,
spaceId: app.spaceId || undefined,
createdAt: app.createdAt,
creator: app.creator,
modifiedAt: app.modifiedAt,
modifier: app.modifier,
};
}
private mapResource(
resource:
| Awaited<AppCustomizeResponse>["desktop"]["js"][number]
| Awaited<AppCustomizeResponse>["desktop"]["css"][number],
): JSFileConfig | CSSFileConfig {
if (resource.type === "FILE") {
return {
type: "FILE",
file: {
fileKey: resource.file.fileKey,
name: resource.file.name,
size: parseInt(resource.file.size, 10),
},
};
}
return {
type: "URL",
url: resource.url,
};
): FileConfig {
// Return SDK type directly - no conversion needed
return resource;
}
private buildCustomizeSection(
js?: JSFileConfig[],
css?: CSSFileConfig[],
): Parameters<KintoneClient["app"]["updateAppCustomize"]>[0]["desktop"] {
js?: FileConfig[],
css?: FileConfig[],
): Parameters<
KintoneRestAPIClient["app"]["updateAppCustomize"]
>[0]["desktop"] {
if (!js && !css) return undefined;
const mapItem = (item: JSFileConfig | CSSFileConfig) => {
const mapItem = (item: FileConfig) => {
if (item.type === "FILE" && item.file) {
return { type: "FILE" as const, file: { fileKey: item.file.fileKey } };
}
@@ -150,7 +121,7 @@ export class SelfKintoneClient {
async getApps(options?: {
limit?: number;
offset?: number;
}): Promise<KintoneApp[]> {
}): Promise<AppResponse[]> {
return this.withErrorHandling(async () => {
// If pagination options provided, use them directly
if (options?.limit !== undefined || options?.offset !== undefined) {
@@ -158,11 +129,11 @@ export class SelfKintoneClient {
if (options.limit) params.limit = options.limit;
if (options.offset) params.offset = options.offset;
const response = await this.client.app.getApps(params);
return response.apps.map((app) => this.mapApp(app));
return response.apps;
}
// Otherwise, fetch all apps (pagination handled internally)
const allApps: Awaited<AppsResponse>["apps"] = [];
const allApps: AppResponse[] = [];
const limit = 100; // Max allowed by Kintone API
let offset = 0;
let hasMore = true;
@@ -179,7 +150,7 @@ export class SelfKintoneClient {
}
}
return allApps.map((app) => this.mapApp(app));
return allApps;
});
}
@@ -203,7 +174,6 @@ export class SelfKintoneClient {
mobile:
customizeInfo.mobile.css?.map((css) => this.mapResource(css)) || [],
},
plugins: [],
};
return {