Skip to content

Commit d49607e

Browse files
committed
Merge branch 'main' into better-api-import
# Conflicts: # packages/dashboard/src/app/(layout)/services/import/parsePostman.ts
2 parents 0c66585 + a50d0ce commit d49607e

10 files changed

Lines changed: 52 additions & 8 deletions

File tree

packages/backend/src/utils/database.types.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type Database = {
5050
mock_response: Json | null
5151
mock_status_code: number | null
5252
name: string
53+
path: string | null
5354
regex_path: string | null
5455
retry_count: number
5556
retry_enabled: boolean
@@ -78,6 +79,7 @@ export type Database = {
7879
mock_response?: Json | null
7980
mock_status_code?: number | null
8081
name: string
82+
path?: string | null
8183
regex_path?: string | null
8284
retry_count?: number
8385
retry_enabled?: boolean
@@ -106,6 +108,7 @@ export type Database = {
106108
mock_response?: Json | null
107109
mock_status_code?: number | null
108110
name?: string
111+
path?: string | null
109112
regex_path?: string | null
110113
retry_count?: number
111114
retry_enabled?: boolean
@@ -135,13 +138,13 @@ export type Database = {
135138
Insert: {
136139
created_at?: string | null
137140
endpoint_id: number
138-
id?: never
141+
id?: number
139142
schema?: Json | null
140143
}
141144
Update: {
142145
created_at?: string | null
143146
endpoint_id?: number
144-
id?: never
147+
id?: number
145148
schema?: Json | null
146149
}
147150
Relationships: [
@@ -346,13 +349,24 @@ export type Database = {
346349
}
347350
Returns: Json
348351
}
352+
increment_mcp_usage: {
353+
Args: { p_user_id: string; p_max_requests: number }
354+
Returns: {
355+
allowed: boolean
356+
c_count: number
357+
}[]
358+
}
349359
increment_usage: {
350360
Args: { p_user_id: string; p_max_requests: number }
351361
Returns: {
352362
allowed: boolean
353363
c_count: number
354364
}[]
355365
}
366+
update_full_url: {
367+
Args: { p_service_id: number }
368+
Returns: undefined
369+
}
356370
}
357371
Enums: {
358372
[_ in never]: never
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
alter table public.endpoints
2+
add column path text;
3+
4+
create or replace function update_full_url(p_service_id integer)
5+
returns void
6+
security definer
7+
language plpgsql
8+
as
9+
$$
10+
begin
11+
update public.endpoints e
12+
set full_url = concat(s.base_url, e.path)
13+
from public.services s
14+
where s.id = p_service_id and e.service_id = s.id;
15+
end;
16+
$$;

packages/dashboard/src/app/(layout)/endpoints/new/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export default function AddApi() {
158158
regexPath: '^' + data.name.replace(/{[^}]+}/g, '([^/]+)') + '$',
159159
customHeadersEnabled: data.customHeadersEnabled,
160160
customHeaders: JSON.parse(data.customHeaders ?? ''),
161+
path: data.path,
161162
}
162163
)
163164
})

packages/dashboard/src/app/(layout)/services/[id]/endpoints/[endpointId]/components/SettingsTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function Settings({endpoint, service}: Props) {
4545
resolver: zodResolver(endpointSchema),
4646
defaultValues: {
4747
name: endpoint.name ?? "",
48-
path: endpoint.full_url.replace(service.base_url, ''),
48+
path: endpoint.path ?? "",
4949
method: endpoint.method as "GET" ?? "GET",
5050
caching: endpoint.cache_enabled ?? true,
5151
cache_ttl_s: (endpoint.cache_ttl_s ?? 60).toString(),
@@ -150,6 +150,7 @@ export default function Settings({endpoint, service}: Props) {
150150
userId: service.user_id,
151151
customHeadersEnabled: data.customHeadersEnabled,
152152
customHeaders: JSON.parse(data.customHeaders ?? ''),
153+
path: data.path,
153154
})
154155
})
155156
.then(response => response.json())

packages/dashboard/src/app/(layout)/services/import/parsePostman.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ function processItems(items: PostmanItem[], endpoints: Tables<'endpoints'>[], ba
606606
const endpoint: Tables<'endpoints'> = {
607607
name: path,
608608
description: description,
609+
path: path,
609610
method: method,
610611
full_url: full_url,
611612
regex_path: regex_path,

packages/dashboard/src/app/(layout)/services/import/parseSwagger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ function createEndpointsArray(swagger: SwaggerSchema, baseUrl: string): Tables<'
253253
// Create endpoint object
254254
const endpoint: Partial<Tables<'endpoints'>> = {
255255
name,
256+
path: path,
256257
method: method.toUpperCase(),
257258
full_url,
258259
regex_path,

packages/dashboard/src/app/api/endpoints/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function POST(req: any) {
3131
regex_path: '^' + data.name.replace(/{[^}]+}/g, '([^/]+)') + '$',
3232
custom_headers_enabled: data.customHeadersEnabled,
3333
custom_headers: data.customHeaders,
34+
path: data.path,
3435
})
3536
.select()
3637
.single();
@@ -76,6 +77,7 @@ export async function PUT(req: any) {
7677
regex_path: '^' + data.name.replace(/{[^}]+}/g, '([^/]+)') + '$',
7778
custom_headers_enabled: data.customHeadersEnabled,
7879
custom_headers: data.customHeaders,
80+
path: data.path,
7981
})
8082
.eq('id', endpointId);
8183

packages/dashboard/src/app/api/service/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function POST(req: Request) {
5757

5858
if (result.error) throw result.error;
5959

60-
await dropServiceEndpointsCaches(userId!, body.serviceName);
60+
await dropServiceEndpointsCaches(userId!, body.name);
6161

6262
return NextResponse.json(result.data);
6363
} catch (error: any) {

packages/dashboard/src/utils/supabase/database.types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type Database = {
5050
mock_response: Json | null
5151
mock_status_code: number | null
5252
name: string
53+
path: string | null
5354
regex_path: string | null
5455
retry_count: number
5556
retry_enabled: boolean
@@ -78,6 +79,7 @@ export type Database = {
7879
mock_response?: Json | null
7980
mock_status_code?: number | null
8081
name: string
82+
path?: string | null
8183
regex_path?: string | null
8284
retry_count?: number
8385
retry_enabled?: boolean
@@ -106,6 +108,7 @@ export type Database = {
106108
mock_response?: Json | null
107109
mock_status_code?: number | null
108110
name?: string
111+
path?: string | null
109112
regex_path?: string | null
110113
retry_count?: number
111114
retry_enabled?: boolean
@@ -316,21 +319,18 @@ export type Database = {
316319
billing_started_at: string
317320
calls_count: number
318321
id: number
319-
mcp_calls_count: number
320322
user_id: string
321323
}
322324
Insert: {
323325
billing_started_at?: string
324326
calls_count?: number
325327
id?: number
326-
mcp_calls_count?: number
327328
user_id: string
328329
}
329330
Update: {
330331
billing_started_at?: string
331332
calls_count?: number
332333
id?: number
333-
mcp_calls_count?: number
334334
user_id?: string
335335
}
336336
Relationships: []
@@ -363,6 +363,10 @@ export type Database = {
363363
c_count: number
364364
}[]
365365
}
366+
update_full_url: {
367+
Args: { p_service_id: number }
368+
Returns: undefined
369+
}
366370
}
367371
Enums: {
368372
[_ in never]: never

setup.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ function generateRandomString(length = 32, includeSpecialChars = false) {
2727
.join('');
2828
}
2929

30+
function generateEncryptionKey() {
31+
return crypto.randomBytes(32).toString('hex');
32+
}
33+
3034
function generateJwt(secret, role, expiresIn) {
3135
const payload = {
3236
role: role,
@@ -112,7 +116,7 @@ function generateEnvFiles(hostname) {
112116
LOGFLARE_LOGGER_BACKEND_API_KEY: generateRandomString(64),
113117
LOGFLARE_API_KEY: generateRandomString(64),
114118
POOLER_TENANT_ID: generateRandomString(16),
115-
ENCRYPTION_KEY: generateRandomString(64),
119+
ENCRYPTION_KEY: generateEncryptionKey(),
116120
};
117121

118122
const supabaseEnv = `

0 commit comments

Comments
 (0)