Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
feat: Proxying rest of the endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Feb 29, 2024
1 parent 3d8ecfd commit 0dfd5d1
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 12 deletions.
114 changes: 114 additions & 0 deletions packages/api/mgmtRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function getCustomerOrFail(db: typeof _db, id: string) {
}

export const mgmtRouter = trpc.router({
// Customer management
listCustomers: mgmtProcedure
.meta({openapi: {method: 'GET', path: '/customers'}})
.input(z.void())
Expand Down Expand Up @@ -83,4 +84,117 @@ export const mgmtRouter = trpc.router({
// )
// return {record: await getCustomerOrFail(ctx.db, input.id)}
),

// Connection management

listConnections: mgmtProcedure
.meta({
openapi: {method: 'GET', path: '/customers/{customer_id}/connections'},
})
.input(z.object({customer_id: z.string()}))
.output(z.array(models.connection))
.query(async ({ctx, input}) =>
ctx.supaglue.mgmt
.GET('/customers/{customer_id}/connections', {
params: {path: {customer_id: input.customer_id}},
})
.then((r) => r.data),
),

getConnection: mgmtProcedure
.meta({
openapi: {
method: 'GET',
path: '/customers/{customer_id}/connections/{provider_name}',
},
})
.input(z.object({customer_id: z.string(), provider_name: z.string()}))
.output(models.connection)
.query(async ({ctx, input}) =>
ctx.supaglue.mgmt
.GET('/customers/{customer_id}/connections/{provider_name}', {
params: {
path: {
customer_id: input.customer_id,
provider_name: input.provider_name as 'hubspot',
},
},
})
.then((r) => r.data),
),
deleteConnection: mgmtProcedure
.meta({
openapi: {
method: 'DELETE',
path: '/customers/{customer_id}/connections/{provider_name}',
},
})
.input(z.object({customer_id: z.string(), provider_name: z.string()}))
.output(z.void())
.query(async ({ctx, input}) =>
ctx.supaglue.mgmt
.DELETE('/customers/{customer_id}/connections/{provider_name}', {
params: {
path: {
customer_id: input.customer_id,
provider_name: input.provider_name as 'hubspot',
},
},
})
.then((r) => r.data),
),

// MARK: - connection sync config

getConnectionSyncConfig: mgmtProcedure
.meta({
openapi: {
method: 'GET',
path: '/connection_sync_configs',
},
})
.input(z.void())
.output(models.connection_sync_config)
.query(async ({ctx}) =>
ctx.supaglue.mgmt
.GET('/connection_sync_configs', {
params: {
header: {
'x-customer-id': ctx.headers.get('x-customer-id')!,

Check warning on line 163 in packages/api/mgmtRouter.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Forbidden non-null assertion
'x-provider-name': ctx.headers.get('x-provider-name')!,

Check warning on line 164 in packages/api/mgmtRouter.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Forbidden non-null assertion
},
},
})

.then((r) => r.data),
),

upsertConnectionSyncConfig: mgmtProcedure
.meta({
openapi: {
method: 'PUT',
path: '/connection_sync_configs',
},
})
.input(models.connection_sync_config)
.output(models.connection_sync_config)
.query(async ({ctx, input}) =>
ctx.supaglue.mgmt
.PUT('/connection_sync_configs', {
params: {
header: {
'x-customer-id': ctx.headers.get('x-customer-id')!,

Check warning on line 186 in packages/api/mgmtRouter.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Forbidden non-null assertion
'x-provider-name': ctx.headers.get('x-provider-name')!,

Check warning on line 187 in packages/api/mgmtRouter.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Forbidden non-null assertion
},
},
body: {
custom_objects: input.custom_objects!,

Check warning on line 191 in packages/api/mgmtRouter.ts

View workflow job for this annotation

GitHub Actions / Run type checks, lint, and tests

Forbidden non-null assertion
destination_config: input.destination_config as {
type: 'postgres'
schema: string
},
},
})
.then((r) => r.data),
),
})
36 changes: 24 additions & 12 deletions packages/api/models.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {z} from '@supaglue/vdk'

/** workaround the issue that we get back date from db... need to figure out how to just get string */
const zTimestamp = z
.union([z.string(), z.date()])
.describe('ISO8601 date string')
// const zTimestamp = z
// .union([z.string(), z.date()])
// .describe('ISO8601 date string')

const dbRecord = z.object({
// id: z.string(),
/** z.string().datetime() does not work for simple things like `2023-07-19T23:46:48.000+0000` */
updated_at: zTimestamp,
created_at: zTimestamp,
})
// const dbRecord = z.object({
// // id: z.string(),
// /** z.string().datetime() does not work for simple things like `2023-07-19T23:46:48.000+0000` */
// updated_at: zTimestamp,
// created_at: zTimestamp,
// })

export const customer = z
.object({
Expand All @@ -20,8 +20,20 @@ export const customer = z
})
.openapi({ref: 'customer'})

export const resource = dbRecord
.extend({
export const connection = z
.object({
customer_id: z.string().nullish(),
provider_name: z.string(),
})
.openapi({ref: 'connection'})

/** @deprecated but still needed */
export const connection_sync_config = z
.object({
destination_config: z
.object({type: z.string(), schema: z.string().nullish()})
.nullish(),

custom_objects: z.array(z.object({object: z.string()})).nullish(),
})
.openapi({ref: 'resource'})
.openapi({ref: 'connection_sync_config'})

0 comments on commit 0dfd5d1

Please sign in to comment.