@squarecloud/api
Version:
A NodeJS wrapper for Square Cloud API
159 lines (155 loc) • 5.58 kB
TypeScript
import { APIUserInfo, APIServiceStatus, RESTPostAPIApplicationUploadResult, APIApplicationStatusAll, APIApplication, APIApplicationStatus, APIApplicationLogs, APIApplicationBackup, RESTPostAPIApplicationBackupResult, RESTGetAPIFileContentQuery, APIReadFile, RESTGetAPIFilesListQuery, APIListedFile, RESTPutAPIFileUpsertJSONBody, RESTPatchAPIFileMoveJSONBody, RESTDeleteAPIFileDeleteQuery, APIDeployment, APIDeploymentCurrent, RESTPostAPIGithubWebhookJSONBody, RESTPostAPIGithubWebhookResult, APINetworkDNS, APINetworkAnalytics, RESTPostAPINetworkCustomDomainJSONBody, APIPayload } from '@squarecloud/api-types/v2';
type Route<T extends APIEndpoint> = string & {
__route: T;
};
declare const Route: <T extends APIEndpoint>(route: string) => Route<T>;
declare const Routes: {
user: () => Route<"user">;
service: {
status: () => Route<"service/status">;
};
apps: {
upload: () => Route<"apps/upload">;
statusAll: () => Route<"apps/status-all">;
info: (appId: string) => Route<"apps/info">;
status: (appId: string) => Route<"apps/status">;
logs: (appId: string) => Route<"apps/logs">;
delete: (appId: string) => Route<"apps/delete">;
commit: (appId: string) => Route<"apps/commit">;
snapshots: (appId: string) => Route<"apps/snapshots">;
generateSnapshot: (appId: string) => Route<"apps/generate-snapshot">;
start: (appId: string) => Route<"apps/start">;
restart: (appId: string) => Route<"apps/restart">;
stop: (appId: string) => Route<"apps/stop">;
files: {
read: (appId: string) => Route<"apps/files/read">;
list: (appId: string) => Route<"apps/files/list">;
upsert: (appId: string) => Route<"apps/files/upsert">;
move: (appId: string) => Route<"apps/files/move">;
delete: (appId: string) => Route<"apps/files/delete">;
};
deployments: {
list: (appId: string) => Route<"apps/deployments/list">;
current: (appId: string) => Route<"apps/deployments/current">;
webhook: (appId: string) => Route<"apps/deployments/webhook">;
};
network: {
dns: (appId: string) => Route<"apps/network/dns">;
custom: (appId: string) => Route<"apps/network/custom">;
analytics: (appId: string) => Route<"apps/network/analytics">;
};
};
};
interface APIEndpoints {
user: {
response: APIUserInfo;
};
"service/status": {
response: APIServiceStatus;
};
"apps/upload": {
method: "POST";
body: FormData;
response: RESTPostAPIApplicationUploadResult;
};
"apps/status-all": {
response: APIApplicationStatusAll[];
};
"apps/info": {
response: APIApplication;
};
"apps/status": {
response: APIApplicationStatus;
};
"apps/logs": {
response: APIApplicationLogs;
};
"apps/snapshots": {
response: APIApplicationBackup[];
};
"apps/generate-snapshot": {
method: "POST";
response: RESTPostAPIApplicationBackupResult;
};
"apps/start": {
method: "POST";
response: undefined;
};
"apps/restart": {
method: "POST";
response: undefined;
};
"apps/stop": {
method: "POST";
response: undefined;
};
"apps/delete": {
method: "DELETE";
response: undefined;
};
"apps/commit": {
method: "POST";
body: FormData;
response: undefined;
};
"apps/files/read": {
query: RESTGetAPIFileContentQuery;
response: APIReadFile;
};
"apps/files/list": {
query: RESTGetAPIFilesListQuery;
response: APIListedFile[];
};
"apps/files/upsert": {
method: "PUT";
body: RESTPutAPIFileUpsertJSONBody;
response: undefined;
};
"apps/files/move": {
method: "PATCH";
body: RESTPatchAPIFileMoveJSONBody;
response: undefined;
};
"apps/files/delete": {
method: "DELETE";
body: RESTDeleteAPIFileDeleteQuery;
response: undefined;
};
"apps/deployments/list": {
response: APIDeployment[];
};
"apps/deployments/current": {
response: APIDeploymentCurrent;
};
"apps/deployments/webhook": {
method: "POST";
body: RESTPostAPIGithubWebhookJSONBody;
response: RESTPostAPIGithubWebhookResult;
};
"apps/network/dns": {
response: APINetworkDNS[];
};
"apps/network/analytics": {
response: APINetworkAnalytics;
};
"apps/network/custom": {
method: "POST";
body: RESTPostAPINetworkCustomDomainJSONBody;
response: undefined;
};
}
type APIEndpoint = keyof APIEndpoints;
type APIMethod = "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
type APIRequestOptions<T extends APIEndpoint> = {
headers?: HeadersInit;
} & Omit<APIEndpoints[T], "response">;
type APIResponse<T extends APIEndpoint> = APIPayload<APIEndpoints[T]["response"]>;
type QueryOrBody = {
query: any;
} | {
body: any;
} | {
method: APIMethod;
};
type APIRequestArgs<T extends APIEndpoint, U extends APIRequestOptions<T> = APIRequestOptions<T>> = U extends QueryOrBody ? [path: Route<T>, options: U] : [path: Route<T>, options?: U];
export { type APIEndpoint as A, type QueryOrBody as Q, Route as R, type APIRequestArgs as a, type APIResponse as b, type APIEndpoints as c, type APIMethod as d, type APIRequestOptions as e, Routes as f };