update main ts
This commit is contained in:
@@ -3,11 +3,9 @@ import type { KintoneRestAPIError } from "@kintone/rest-api-client";
|
||||
import type { DomainWithPassword } from "@shared/types/domain";
|
||||
import type {
|
||||
AppResponse,
|
||||
AppsResponse,
|
||||
AppCustomizeResponse,
|
||||
AppDetail,
|
||||
FileContent,
|
||||
AppCustomizationConfig,
|
||||
KintoneApiError,
|
||||
FileConfig,
|
||||
} from "@shared/types/kintone";
|
||||
@@ -82,34 +80,19 @@ export class SelfKintoneClient {
|
||||
}
|
||||
}
|
||||
|
||||
private mapResource(
|
||||
resource:
|
||||
| Awaited<AppCustomizeResponse>["desktop"]["js"][number]
|
||||
| Awaited<AppCustomizeResponse>["desktop"]["css"][number],
|
||||
): FileConfig {
|
||||
// Return SDK type directly - no conversion needed
|
||||
return resource;
|
||||
}
|
||||
|
||||
private buildCustomizeSection(
|
||||
js?: FileConfig[],
|
||||
css?: FileConfig[],
|
||||
): Parameters<
|
||||
KintoneRestAPIClient["app"]["updateAppCustomize"]
|
||||
>[0]["desktop"] {
|
||||
if (!js && !css) return undefined;
|
||||
files?: FileConfig[],
|
||||
): NonNullable<
|
||||
Parameters<KintoneRestAPIClient["app"]["updateAppCustomize"]>[0]["desktop"]
|
||||
>["js"] {
|
||||
if (!files || files.length === 0) return undefined;
|
||||
|
||||
const mapItem = (item: FileConfig) => {
|
||||
return files.map((item) => {
|
||||
if (item.type === "FILE" && item.file) {
|
||||
return { type: "FILE" as const, file: { fileKey: item.file.fileKey } };
|
||||
}
|
||||
return { type: "URL" as const, url: item.url || "" };
|
||||
};
|
||||
|
||||
return {
|
||||
js: js?.map(mapItem),
|
||||
css: css?.map(mapItem),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== App APIs ====================
|
||||
@@ -161,32 +144,9 @@ export class SelfKintoneClient {
|
||||
this.client.app.getAppCustomize({ app: appId }),
|
||||
]);
|
||||
|
||||
const customization: AppCustomizationConfig = {
|
||||
javascript: {
|
||||
pc: customizeInfo.desktop.js?.map((js) => this.mapResource(js)) || [],
|
||||
mobile:
|
||||
customizeInfo.mobile.js?.map((js) => this.mapResource(js)) || [],
|
||||
},
|
||||
stylesheet: {
|
||||
pc:
|
||||
customizeInfo.desktop.css?.map((css) => this.mapResource(css)) ||
|
||||
[],
|
||||
mobile:
|
||||
customizeInfo.mobile.css?.map((css) => this.mapResource(css)) || [],
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
appId: appInfo.appId,
|
||||
name: appInfo.name,
|
||||
code: appInfo.code,
|
||||
description: appInfo.description,
|
||||
spaceId: appInfo.spaceId || undefined,
|
||||
createdAt: appInfo.createdAt,
|
||||
creator: appInfo.creator,
|
||||
modifiedAt: appInfo.modifiedAt,
|
||||
modifier: appInfo.modifier,
|
||||
customization,
|
||||
...appInfo,
|
||||
customization: customizeInfo,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -226,20 +186,20 @@ export class SelfKintoneClient {
|
||||
|
||||
async updateAppCustomize(
|
||||
appId: string,
|
||||
config: AppCustomizationConfig,
|
||||
config: AppCustomizeResponse,
|
||||
): Promise<void> {
|
||||
return this.withErrorHandling(async () => {
|
||||
await this.client.app.updateAppCustomize({
|
||||
app: appId,
|
||||
desktop: this.buildCustomizeSection(
|
||||
config.javascript?.pc,
|
||||
config.stylesheet?.pc,
|
||||
),
|
||||
mobile: this.buildCustomizeSection(
|
||||
config.javascript?.mobile,
|
||||
config.stylesheet?.mobile,
|
||||
),
|
||||
scope: "ALL",
|
||||
desktop: {
|
||||
js: this.buildCustomizeSection(config.desktop?.js),
|
||||
css: this.buildCustomizeSection(config.desktop?.css),
|
||||
},
|
||||
mobile: {
|
||||
js: this.buildCustomizeSection(config.mobile?.js),
|
||||
css: this.buildCustomizeSection(config.mobile?.css),
|
||||
},
|
||||
scope: config.scope || "ALL",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user