@giaeulate/baas-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/demo/index.html +133 -0
- package/js/src/index.ts +278 -0
- package/package.json +34 -0
- package/realtime.test.ts +184 -0
- package/scripts/dev.sh +30 -0
- package/src/client.ts +263 -0
- package/src/http-client.ts +144 -0
- package/src/index.ts +43 -0
- package/src/modules/api-keys.ts +36 -0
- package/src/modules/audit.ts +46 -0
- package/src/modules/auth.ts +158 -0
- package/src/modules/backups.ts +68 -0
- package/src/modules/branches.ts +46 -0
- package/src/modules/database.ts +158 -0
- package/src/modules/email.ts +93 -0
- package/src/modules/env-vars.ts +42 -0
- package/src/modules/functions.ts +57 -0
- package/src/modules/graphql.ts +24 -0
- package/src/modules/jobs.ts +78 -0
- package/src/modules/log-drains.ts +76 -0
- package/src/modules/metrics.ts +72 -0
- package/src/modules/migrations.ts +51 -0
- package/src/modules/projects.ts +25 -0
- package/src/modules/realtime.ts +30 -0
- package/src/modules/search.ts +37 -0
- package/src/modules/storage.ts +27 -0
- package/src/modules/users.ts +31 -0
- package/src/modules/webhooks.ts +58 -0
- package/src/query-builder.ts +157 -0
- package/src/realtime.ts +157 -0
- package/src/types.ts +49 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jobs Module - Scheduled jobs (CRON) operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface JobInput {
|
|
8
|
+
name: string;
|
|
9
|
+
schedule: string;
|
|
10
|
+
function_id: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
payload?: Record<string, any>;
|
|
13
|
+
timezone?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface JobUpdateInput {
|
|
17
|
+
name?: string;
|
|
18
|
+
schedule?: string;
|
|
19
|
+
function_id?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
payload?: Record<string, any>;
|
|
22
|
+
timezone?: string;
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface JobsModule {
|
|
27
|
+
create(input: JobInput): Promise<any>;
|
|
28
|
+
list(): Promise<any>;
|
|
29
|
+
get(id: string): Promise<any>;
|
|
30
|
+
update(id: string, input: JobUpdateInput): Promise<any>;
|
|
31
|
+
delete(id: string): Promise<any>;
|
|
32
|
+
toggle(id: string, enabled: boolean): Promise<any>;
|
|
33
|
+
runNow(id: string): Promise<any>;
|
|
34
|
+
getExecutions(id: string, limit?: number): Promise<any>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createJobsModule(client: HttpClient): JobsModule {
|
|
38
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
39
|
+
const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
|
|
40
|
+
const put = (endpoint: string, body?: unknown) => (client as any).put(endpoint, body);
|
|
41
|
+
const del = (endpoint: string) => (client as any).delete(endpoint);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
async create(input: JobInput) {
|
|
45
|
+
return post('/api/jobs', input);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
async list() {
|
|
49
|
+
return get('/api/jobs');
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
async get(id: string) {
|
|
53
|
+
return get(`/api/jobs/${id}`);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async update(id: string, input: JobUpdateInput) {
|
|
57
|
+
return put(`/api/jobs/${id}`, input);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
async delete(id: string) {
|
|
61
|
+
return del(`/api/jobs/${id}`);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async toggle(id: string, enabled: boolean) {
|
|
65
|
+
return post(`/api/jobs/${id}/toggle`, { enabled });
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
async runNow(id: string) {
|
|
69
|
+
return post(`/api/jobs/${id}/run`);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
async getExecutions(id: string, limit?: number) {
|
|
73
|
+
const params = new URLSearchParams();
|
|
74
|
+
if (limit) params.set('limit', limit.toString());
|
|
75
|
+
return get(`/api/jobs/${id}/executions?${params.toString()}`);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log Drains Module
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface LogDrainInput {
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
url: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
filters?: {
|
|
14
|
+
levels?: string[];
|
|
15
|
+
sources?: string[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LogDrainUpdateInput {
|
|
20
|
+
name?: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
filters?: {
|
|
25
|
+
levels?: string[];
|
|
26
|
+
sources?: string[];
|
|
27
|
+
};
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface LogDrainsModule {
|
|
32
|
+
create(input: LogDrainInput): Promise<any>;
|
|
33
|
+
list(): Promise<any>;
|
|
34
|
+
get(id: string): Promise<any>;
|
|
35
|
+
update(id: string, input: LogDrainUpdateInput): Promise<any>;
|
|
36
|
+
delete(id: string): Promise<any>;
|
|
37
|
+
toggle(id: string, enabled: boolean): Promise<any>;
|
|
38
|
+
test(id: string): Promise<any>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createLogDrainsModule(client: HttpClient): LogDrainsModule {
|
|
42
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
43
|
+
const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
|
|
44
|
+
const put = (endpoint: string, body?: unknown) => (client as any).put(endpoint, body);
|
|
45
|
+
const del = (endpoint: string) => (client as any).delete(endpoint);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
async create(input: LogDrainInput) {
|
|
49
|
+
return post('/api/log-drains', input);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
async list() {
|
|
53
|
+
return get('/api/log-drains');
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async get(id: string) {
|
|
57
|
+
return get(`/api/log-drains/${id}`);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
async update(id: string, input: LogDrainUpdateInput) {
|
|
61
|
+
return put(`/api/log-drains/${id}`, input);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async delete(id: string) {
|
|
65
|
+
return del(`/api/log-drains/${id}`);
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
async toggle(id: string, enabled: boolean) {
|
|
69
|
+
return post(`/api/log-drains/${id}/toggle`, { enabled });
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
async test(id: string) {
|
|
73
|
+
return post(`/api/log-drains/${id}/test`);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics Module - Monitoring and metrics operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface RequestLogsOptions {
|
|
8
|
+
limit?: number;
|
|
9
|
+
offset?: number;
|
|
10
|
+
method?: string;
|
|
11
|
+
status?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ApplicationLogsOptions {
|
|
16
|
+
limit?: number;
|
|
17
|
+
offset?: number;
|
|
18
|
+
level?: string;
|
|
19
|
+
source?: string;
|
|
20
|
+
search?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TimeseriesOptions {
|
|
24
|
+
interval?: string;
|
|
25
|
+
start?: string;
|
|
26
|
+
end?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MetricsModule {
|
|
30
|
+
getDashboardStats(): Promise<any>;
|
|
31
|
+
getRequestLogs(options?: RequestLogsOptions): Promise<any>;
|
|
32
|
+
getApplicationLogs(options?: ApplicationLogsOptions): Promise<any>;
|
|
33
|
+
getTimeseries(metric: string, options?: TimeseriesOptions): Promise<any>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createMetricsModule(client: HttpClient): MetricsModule {
|
|
37
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
async getDashboardStats() {
|
|
41
|
+
return get('/api/metrics/dashboard');
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
async getRequestLogs(options?: RequestLogsOptions) {
|
|
45
|
+
const params = new URLSearchParams();
|
|
46
|
+
if (options?.limit) params.set('limit', options.limit.toString());
|
|
47
|
+
if (options?.offset) params.set('offset', options.offset.toString());
|
|
48
|
+
if (options?.method) params.set('method', options.method);
|
|
49
|
+
if (options?.status) params.set('status', options.status);
|
|
50
|
+
if (options?.path) params.set('path', options.path);
|
|
51
|
+
return get(`/api/metrics/requests?${params.toString()}`);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async getApplicationLogs(options?: ApplicationLogsOptions) {
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
if (options?.limit) params.set('limit', options.limit.toString());
|
|
57
|
+
if (options?.offset) params.set('offset', options.offset.toString());
|
|
58
|
+
if (options?.level) params.set('level', options.level);
|
|
59
|
+
if (options?.source) params.set('source', options.source);
|
|
60
|
+
if (options?.search) params.set('search', options.search);
|
|
61
|
+
return get(`/api/metrics/logs?${params.toString()}`);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async getTimeseries(metric: string, options?: TimeseriesOptions) {
|
|
65
|
+
const params = new URLSearchParams({ metric });
|
|
66
|
+
if (options?.interval) params.set('interval', options.interval);
|
|
67
|
+
if (options?.start) params.set('start', options.start);
|
|
68
|
+
if (options?.end) params.set('end', options.end);
|
|
69
|
+
return get(`/api/metrics/timeseries?${params.toString()}`);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migrations Module - Database migration operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface MigrationsModule {
|
|
8
|
+
create(input: { name: string; description?: string; up_sql: string; down_sql?: string }): Promise<any>;
|
|
9
|
+
list(): Promise<any>;
|
|
10
|
+
get(id: string): Promise<any>;
|
|
11
|
+
apply(id: string): Promise<any>;
|
|
12
|
+
rollback(id: string): Promise<any>;
|
|
13
|
+
delete(id: string): Promise<any>;
|
|
14
|
+
generate(tableName: string, changes: any[]): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createMigrationsModule(client: HttpClient): MigrationsModule {
|
|
18
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
19
|
+
const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
|
|
20
|
+
const del = (endpoint: string) => (client as any).delete(endpoint);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
async create(input: { name: string; description?: string; up_sql: string; down_sql?: string }) {
|
|
24
|
+
return post('/api/migrations', input);
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
async list() {
|
|
28
|
+
return get('/api/migrations');
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async get(id: string) {
|
|
32
|
+
return get(`/api/migrations/${id}`);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
async apply(id: string) {
|
|
36
|
+
return post(`/api/migrations/${id}/apply`, {});
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
async rollback(id: string) {
|
|
40
|
+
return post(`/api/migrations/${id}/rollback`, {});
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
async delete(id: string) {
|
|
44
|
+
return del(`/api/migrations/${id}`);
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
async generate(tableName: string, changes: any[]) {
|
|
48
|
+
return post('/api/migrations/generate', { table_name: tableName, changes });
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projects Module - Project management operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface ProjectsModule {
|
|
8
|
+
list(): Promise<any>;
|
|
9
|
+
create(name: string): Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createProjectsModule(client: HttpClient): ProjectsModule {
|
|
13
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
14
|
+
const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
async list() {
|
|
18
|
+
return get('/api/projects');
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
async create(name: string) {
|
|
22
|
+
return post('/api/projects', { name });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Realtime Module - WebSocket subscriptions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
import { RealtimeService } from '../realtime';
|
|
7
|
+
import { RealtimeAction, RealtimeCallback } from '../types';
|
|
8
|
+
|
|
9
|
+
export interface Subscription {
|
|
10
|
+
unsubscribe: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface RealtimeModule {
|
|
14
|
+
subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>): Promise<Subscription>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createRealtimeModule(client: HttpClient): RealtimeModule {
|
|
18
|
+
const service = new RealtimeService(
|
|
19
|
+
client.url,
|
|
20
|
+
client.getDynamicProjectID(),
|
|
21
|
+
() => client.getDynamicToken(),
|
|
22
|
+
typeof WebSocket !== 'undefined' ? WebSocket : undefined
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
async subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>): Promise<Subscription> {
|
|
27
|
+
return service.subscribe(table, action, callback);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Module - Full-text search operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface SearchOptions {
|
|
8
|
+
tables?: string[];
|
|
9
|
+
columns?: string[];
|
|
10
|
+
limit?: number;
|
|
11
|
+
offset?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SearchModule {
|
|
15
|
+
search(query: string, options?: SearchOptions): Promise<any>;
|
|
16
|
+
createIndex(table: string, columns: string[]): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createSearchModule(client: HttpClient): SearchModule {
|
|
20
|
+
const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
async search(query: string, options?: SearchOptions) {
|
|
24
|
+
return post('/api/search', {
|
|
25
|
+
query,
|
|
26
|
+
tables: options?.tables,
|
|
27
|
+
columns: options?.columns,
|
|
28
|
+
limit: options?.limit,
|
|
29
|
+
offset: options?.offset,
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
async createIndex(table: string, columns: string[]) {
|
|
34
|
+
return post('/api/search/index', { table, columns });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Module - File storage operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface StorageModule {
|
|
8
|
+
upload(table: string, file: File): Promise<any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createStorageModule(client: HttpClient): StorageModule {
|
|
12
|
+
return {
|
|
13
|
+
async upload(_table: string, file: File) {
|
|
14
|
+
const formData = new FormData();
|
|
15
|
+
formData.append('file', file);
|
|
16
|
+
|
|
17
|
+
const res = await fetch(`${client.url}/api/storage/upload`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: client.getHeaders(''),
|
|
20
|
+
body: formData
|
|
21
|
+
});
|
|
22
|
+
const data = await res.json();
|
|
23
|
+
if (!res.ok && res.status === 401) client.forceLogout();
|
|
24
|
+
return data;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Users Module - User management operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface UsersModule {
|
|
8
|
+
list(limit?: number, offset?: number): Promise<any>;
|
|
9
|
+
update(id: string, updates: { email?: string; role?: string; email_verified?: boolean }): Promise<any>;
|
|
10
|
+
delete(id: string): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createUsersModule(client: HttpClient): UsersModule {
|
|
14
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
15
|
+
const put = (endpoint: string, body?: unknown) => (client as any).put(endpoint, body);
|
|
16
|
+
const del = (endpoint: string) => (client as any).delete(endpoint);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
async list(limit = 20, offset = 0) {
|
|
20
|
+
return get(`/api/users?limit=${limit}&offset=${offset}`);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
async update(id: string, updates: { email?: string; role?: string; email_verified?: boolean }) {
|
|
24
|
+
return put(`/api/users/${id}`, updates);
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
async delete(id: string) {
|
|
28
|
+
return del(`/api/users/${id}`);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhooks Module
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../http-client';
|
|
6
|
+
|
|
7
|
+
export interface WebhookInput {
|
|
8
|
+
url: string;
|
|
9
|
+
event_types: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface WebhookUpdateInput {
|
|
13
|
+
url: string;
|
|
14
|
+
event_types: string[];
|
|
15
|
+
is_active: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface WebhooksModule {
|
|
19
|
+
list(): Promise<any>;
|
|
20
|
+
get(id: string): Promise<any>;
|
|
21
|
+
create(input: WebhookInput): Promise<any>;
|
|
22
|
+
update(id: string, input: WebhookUpdateInput): Promise<any>;
|
|
23
|
+
delete(id: string): Promise<any>;
|
|
24
|
+
test(id: string): Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createWebhooksModule(client: HttpClient): WebhooksModule {
|
|
28
|
+
const get = (endpoint: string) => (client as any).get(endpoint);
|
|
29
|
+
const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
|
|
30
|
+
const put = (endpoint: string, body?: unknown) => (client as any).put(endpoint, body);
|
|
31
|
+
const del = (endpoint: string) => (client as any).delete(endpoint);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
async list() {
|
|
35
|
+
return get('/api/webhooks');
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async get(id: string) {
|
|
39
|
+
return get(`/api/webhooks/${id}`);
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
async create(input: WebhookInput) {
|
|
43
|
+
return post('/api/webhooks', input);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async update(id: string, input: WebhookUpdateInput) {
|
|
47
|
+
return put(`/api/webhooks/${id}`, input);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
async delete(id: string) {
|
|
51
|
+
return del(`/api/webhooks/${id}`);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async test(id: string) {
|
|
55
|
+
return post(`/api/webhooks/${id}/test`);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QueryBuilder - Fluent API for data queries
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from './http-client';
|
|
6
|
+
import type { QueryFilter } from './types';
|
|
7
|
+
|
|
8
|
+
export class QueryBuilder {
|
|
9
|
+
private table: string;
|
|
10
|
+
private url: string;
|
|
11
|
+
private client: HttpClient;
|
|
12
|
+
private queryParams: URLSearchParams = new URLSearchParams();
|
|
13
|
+
// @ts-ignore - used for future filter improvements
|
|
14
|
+
private filters: QueryFilter[] = [];
|
|
15
|
+
|
|
16
|
+
constructor(table: string, url: string, client: HttpClient) {
|
|
17
|
+
this.table = table;
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
select(columns: string = '*') {
|
|
23
|
+
this.queryParams.set('select', columns);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
eq(column: string, value: any) {
|
|
28
|
+
this.queryParams.set(column, `eq.${value}`);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
neq(column: string, value: any) {
|
|
33
|
+
this.queryParams.set(column, `neq.${value}`);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
gt(column: string, value: any) {
|
|
38
|
+
this.queryParams.set(column, `gt.${value}`);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
gte(column: string, value: any) {
|
|
43
|
+
this.queryParams.set(column, `gte.${value}`);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
lt(column: string, value: any) {
|
|
48
|
+
this.queryParams.set(column, `lt.${value}`);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
lte(column: string, value: any) {
|
|
53
|
+
this.queryParams.set(column, `lte.${value}`);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
like(column: string, value: any) {
|
|
58
|
+
this.queryParams.set(column, `like.${value}`);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ilike(column: string, value: any) {
|
|
63
|
+
this.queryParams.set(column, `ilike.${value}`);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
is(column: string, value: any) {
|
|
68
|
+
this.queryParams.set(column, `is.${value}`);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
in(column: string, values: any[]) {
|
|
73
|
+
this.queryParams.set(column, `in.(${values.join(',')})`);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
not(column: string, operator: string, value: any) {
|
|
78
|
+
this.queryParams.set(column, `not.${operator}.${value}`);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
or(filters: string) {
|
|
83
|
+
this.queryParams.set('or', `(${filters})`);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
order(column: string, { ascending = true } = {}) {
|
|
88
|
+
this.queryParams.set('order', `${column}.${ascending ? 'asc' : 'desc'}`);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
limit(count: number) {
|
|
93
|
+
this.queryParams.set('limit', count.toString());
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
offset(count: number) {
|
|
98
|
+
this.queryParams.set('offset', count.toString());
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async get() {
|
|
103
|
+
const res = await fetch(`${this.url}/api/v1/data/${this.table}?${this.queryParams.toString()}`, {
|
|
104
|
+
headers: this.getHeaders(),
|
|
105
|
+
});
|
|
106
|
+
return await this.handleResponse(res);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async insert(data: any) {
|
|
110
|
+
const res = await fetch(`${this.url}/api/v1/data/${this.table}`, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: this.getHeaders(),
|
|
113
|
+
body: JSON.stringify(data),
|
|
114
|
+
});
|
|
115
|
+
return await this.handleResponse(res);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async update(id: string | number, data: any) {
|
|
119
|
+
const res = await fetch(`${this.url}/api/v1/data/${this.table}/${id}`, {
|
|
120
|
+
method: 'PATCH',
|
|
121
|
+
headers: this.getHeaders(),
|
|
122
|
+
body: JSON.stringify(data),
|
|
123
|
+
});
|
|
124
|
+
return await this.handleResponse(res);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async delete(id: string | number) {
|
|
128
|
+
const res = await fetch(`${this.url}/api/v1/data/${this.table}/${id}`, {
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
headers: this.getHeaders(),
|
|
131
|
+
});
|
|
132
|
+
if (res.status === 204) return { success: true };
|
|
133
|
+
return await this.handleResponse(res);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private getHeaders() {
|
|
137
|
+
return this.client.getHeaders();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async handleResponse(res: Response) {
|
|
141
|
+
const text = await res.text();
|
|
142
|
+
let data = null;
|
|
143
|
+
try {
|
|
144
|
+
data = text ? JSON.parse(text) : null;
|
|
145
|
+
} catch {
|
|
146
|
+
// Silently fail parsing
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (!res.ok) {
|
|
150
|
+
if (res.status === 401) {
|
|
151
|
+
this.client.forceLogout();
|
|
152
|
+
}
|
|
153
|
+
return { data: null, error: data?.error || 'Request failed', status: res.status };
|
|
154
|
+
}
|
|
155
|
+
return { data, error: null, status: res.status };
|
|
156
|
+
}
|
|
157
|
+
}
|