fix ts problem
This commit is contained in:
@@ -33,10 +33,17 @@ export class KintoneError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
// Use typeof to get SDK method return types
|
||||
type KintoneClient = KintoneRestAPIClient;
|
||||
type SpaceResponse = ReturnType<KintoneClient["space"]["getSpace"]>;
|
||||
type AppResponse = ReturnType<KintoneClient["app"]["getApp"]>;
|
||||
type AppsResponse = ReturnType<KintoneClient["app"]["getApps"]>;
|
||||
type AppCustomizeResponse = ReturnType<KintoneClient["app"]["getAppCustomize"]>;
|
||||
|
||||
/**
|
||||
* 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<SpaceResponse>): 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<AppResponse>): 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<AppCustomizeResponse>["desktop"]["js"][number]
|
||||
| Awaited<AppCustomizeResponse>["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<KintoneClient["app"]["updateAppCustomize"]>[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<KintoneSpace[]> {
|
||||
// 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<KintoneSpace> {
|
||||
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<KintoneApp[]> {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user