remove spaces
This commit is contained in:
@@ -2,7 +2,6 @@ import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
||||
import type { KintoneRestAPIError } from "@kintone/rest-api-client";
|
||||
import type { DomainWithPassword } from "@shared/types/domain";
|
||||
import type {
|
||||
KintoneSpace,
|
||||
KintoneApp,
|
||||
AppDetail,
|
||||
FileContent,
|
||||
@@ -35,7 +34,6 @@ 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"]>;
|
||||
@@ -89,15 +87,6 @@ export class SelfKintoneClient {
|
||||
}
|
||||
}
|
||||
|
||||
private mapSpace(space: Awaited<SpaceResponse>): KintoneSpace {
|
||||
return {
|
||||
id: space.id,
|
||||
name: space.name,
|
||||
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: Awaited<AppResponse>): KintoneApp {
|
||||
return {
|
||||
@@ -150,30 +139,45 @@ export class SelfKintoneClient {
|
||||
};
|
||||
}
|
||||
|
||||
// ==================== 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.getSpace({ id: spaceId });
|
||||
return this.mapSpace(response);
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== App APIs ====================
|
||||
|
||||
async getApps(spaceId?: string): Promise<KintoneApp[]> {
|
||||
/**
|
||||
* Get all apps with pagination support
|
||||
* Fetches all apps by making multiple requests if needed
|
||||
*/
|
||||
async getApps(options?: {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}): Promise<KintoneApp[]> {
|
||||
return this.withErrorHandling(async () => {
|
||||
const params = spaceId ? { spaceIds: [spaceId] } : {};
|
||||
const response = await this.client.app.getApps(params);
|
||||
return response.apps.map((app) => this.mapApp(app));
|
||||
// If pagination options provided, use them directly
|
||||
if (options?.limit !== undefined || options?.offset !== undefined) {
|
||||
const params: { limit?: number; offset?: number } = {};
|
||||
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));
|
||||
}
|
||||
|
||||
// Otherwise, fetch all apps (pagination handled internally)
|
||||
const allApps: Awaited<AppsResponse>["apps"] = [];
|
||||
const limit = 100; // Max allowed by Kintone API
|
||||
let offset = 0;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
const response = await this.client.app.getApps({ limit, offset });
|
||||
allApps.push(...response.apps);
|
||||
|
||||
// If we got fewer than limit, we've reached the end
|
||||
if (response.apps.length < limit) {
|
||||
hasMore = false;
|
||||
} else {
|
||||
offset += limit;
|
||||
}
|
||||
}
|
||||
|
||||
return allApps.map((app) => this.mapApp(app));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -283,7 +287,8 @@ export class SelfKintoneClient {
|
||||
|
||||
async testConnection(): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
await this.getApps();
|
||||
// Use limit=1 to minimize data transfer for faster connection testing
|
||||
await this.client.app.getApps({ limit: 1 });
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user