remove api token auth
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { KintoneRestAPIClient } from '@kintone/rest-api-client';
|
||||
import type { KintoneRestAPIError } from '@kintone/rest-api-client';
|
||||
import type { DomainWithPassword } from '@shared/types/domain';
|
||||
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
||||
import type { KintoneRestAPIError } from "@kintone/rest-api-client";
|
||||
import type { DomainWithPassword } from "@shared/types/domain";
|
||||
import {
|
||||
type AppResponse,
|
||||
type AppDetail,
|
||||
type FileContent,
|
||||
type KintoneApiError,
|
||||
AppCustomizeParameter,
|
||||
} from '@shared/types/kintone';
|
||||
} from "@shared/types/kintone";
|
||||
|
||||
/**
|
||||
* Custom error class for Kintone API errors
|
||||
@@ -17,9 +17,13 @@ export class KintoneError extends Error {
|
||||
public readonly id?: string;
|
||||
public readonly statusCode?: number;
|
||||
|
||||
constructor(message: string, apiError?: KintoneApiError, statusCode?: number) {
|
||||
constructor(
|
||||
message: string,
|
||||
apiError?: KintoneApiError,
|
||||
statusCode?: number,
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'KintoneError';
|
||||
this.name = "KintoneError";
|
||||
this.code = apiError?.code;
|
||||
this.id = apiError?.id;
|
||||
this.statusCode = statusCode;
|
||||
@@ -36,22 +40,17 @@ export class KintoneClient {
|
||||
constructor(domainConfig: DomainWithPassword) {
|
||||
this.domain = domainConfig.domain;
|
||||
|
||||
const auth =
|
||||
domainConfig.authType === 'api_token'
|
||||
? { apiToken: domainConfig.apiToken || '' }
|
||||
: {
|
||||
username: domainConfig.username,
|
||||
password: domainConfig.password,
|
||||
};
|
||||
|
||||
this.client = new KintoneRestAPIClient({
|
||||
baseUrl: `https://${domainConfig.domain}`,
|
||||
auth,
|
||||
auth: {
|
||||
username: domainConfig.username,
|
||||
password: domainConfig.password,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private convertError(error: unknown): KintoneError {
|
||||
if (error && typeof error === 'object' && 'code' in error) {
|
||||
if (error && typeof error === "object" && "code" in error) {
|
||||
const apiError = error as KintoneRestAPIError;
|
||||
return new KintoneError(
|
||||
apiError.message,
|
||||
@@ -64,7 +63,7 @@ export class KintoneClient {
|
||||
return new KintoneError(error.message);
|
||||
}
|
||||
|
||||
return new KintoneError('Unknown error occurred');
|
||||
return new KintoneError("Unknown error occurred");
|
||||
}
|
||||
|
||||
private async withErrorHandling<T>(operation: () => Promise<T>): Promise<T> {
|
||||
@@ -81,7 +80,10 @@ export class KintoneClient {
|
||||
* Get all apps with pagination support
|
||||
* Fetches all apps by making multiple requests if needed
|
||||
*/
|
||||
async getApps(options?: { limit?: number; offset?: number }): Promise<AppResponse[]> {
|
||||
async getApps(options?: {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}): Promise<AppResponse[]> {
|
||||
return this.withErrorHandling(async () => {
|
||||
// If pagination options provided, use them directly
|
||||
if (options?.limit !== undefined || options?.offset !== undefined) {
|
||||
@@ -134,19 +136,23 @@ export class KintoneClient {
|
||||
return this.withErrorHandling(async () => {
|
||||
const data = await this.client.file.downloadFile({ fileKey });
|
||||
const buffer = Buffer.from(data);
|
||||
const content = buffer.toString('base64');
|
||||
const content = buffer.toString("base64");
|
||||
|
||||
return {
|
||||
fileKey,
|
||||
name: fileKey,
|
||||
size: buffer.byteLength,
|
||||
mimeType: 'application/octet-stream',
|
||||
mimeType: "application/octet-stream",
|
||||
content,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async uploadFile(content: string | Buffer, fileName: string, _mimeType?: string): Promise<{ fileKey: string }> {
|
||||
async uploadFile(
|
||||
content: string | Buffer,
|
||||
fileName: string,
|
||||
_mimeType?: string,
|
||||
): Promise<{ fileKey: string }> {
|
||||
return this.withErrorHandling(async () => {
|
||||
const response = await this.client.file.uploadFile({
|
||||
file: { name: fileName, data: content },
|
||||
@@ -157,7 +163,10 @@ export class KintoneClient {
|
||||
|
||||
// ==================== Deploy APIs ====================
|
||||
|
||||
async updateAppCustomize(appId: string, config: Omit<AppCustomizeParameter, 'app'>): Promise<void> {
|
||||
async updateAppCustomize(
|
||||
appId: string,
|
||||
config: Omit<AppCustomizeParameter, "app">,
|
||||
): Promise<void> {
|
||||
return this.withErrorHandling(async () => {
|
||||
await this.client.app.updateAppCustomize({ ...config, app: appId });
|
||||
});
|
||||
@@ -169,10 +178,12 @@ export class KintoneClient {
|
||||
});
|
||||
}
|
||||
|
||||
async getDeployStatus(appId: string): Promise<'PROCESSING' | 'SUCCESS' | 'FAIL' | 'CANCEL'> {
|
||||
async getDeployStatus(
|
||||
appId: string,
|
||||
): Promise<"PROCESSING" | "SUCCESS" | "FAIL" | "CANCEL"> {
|
||||
return this.withErrorHandling(async () => {
|
||||
const response = await this.client.app.getDeployStatus({ apps: [appId] });
|
||||
return response.apps[0]?.status || 'FAIL';
|
||||
return response.apps[0]?.status || "FAIL";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -186,7 +197,8 @@ export class KintoneClient {
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof KintoneError ? error.message : 'Connection failed',
|
||||
error:
|
||||
error instanceof KintoneError ? error.message : "Connection failed",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user