kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
ac2d0c41a7
commit
903d052548
|
@ -5,6 +5,7 @@ import * as middleware from '@/lib/middleware'
|
||||||
|
|
||||||
import { registerHealthCheck } from './health-check'
|
import { registerHealthCheck } from './health-check'
|
||||||
import { registerV1ProjectsGetProject } from './projects/get-project'
|
import { registerV1ProjectsGetProject } from './projects/get-project'
|
||||||
|
import { registerV1ProjectsListProjects } from './projects/list-projects'
|
||||||
import { registerV1TeamsCreateTeam } from './teams/create-team'
|
import { registerV1TeamsCreateTeam } from './teams/create-team'
|
||||||
import { registerV1TeamsDeleteTeam } from './teams/delete-team'
|
import { registerV1TeamsDeleteTeam } from './teams/delete-team'
|
||||||
import { registerV1TeamsGetTeam } from './teams/get-team'
|
import { registerV1TeamsGetTeam } from './teams/get-team'
|
||||||
|
@ -44,6 +45,7 @@ registerV1TeamsMembersDeleteTeamMember(pri)
|
||||||
|
|
||||||
// Projects crud
|
// Projects crud
|
||||||
registerV1ProjectsGetProject(pri)
|
registerV1ProjectsGetProject(pri)
|
||||||
|
registerV1ProjectsListProjects(pri)
|
||||||
|
|
||||||
// Setup routes and middleware
|
// Setup routes and middleware
|
||||||
apiV1.route('/', pub)
|
apiV1.route('/', pub)
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import type { AuthenticatedEnv } from '@/lib/types'
|
import type { AuthenticatedEnv } from '@/lib/types'
|
||||||
import {
|
import { db, eq, populateProjectSchema, schema } from '@/db'
|
||||||
db,
|
|
||||||
eq,
|
|
||||||
// populateProjectSchema,
|
|
||||||
schema
|
|
||||||
} from '@/db'
|
|
||||||
import { acl } from '@/lib/acl'
|
import { acl } from '@/lib/acl'
|
||||||
import { assert, parseZodSchema } from '@/lib/utils'
|
import { assert, parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
|
@ -20,8 +15,8 @@ const route = createRoute({
|
||||||
path: 'projects/{projectId}',
|
path: 'projects/{projectId}',
|
||||||
security: [{ bearerAuth: [] }],
|
security: [{ bearerAuth: [] }],
|
||||||
request: {
|
request: {
|
||||||
params: ProjectIdParamsSchema
|
params: ProjectIdParamsSchema,
|
||||||
// query: populateProjectSchema
|
query: populateProjectSchema
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
@ -42,11 +37,11 @@ export function registerV1ProjectsGetProject(
|
||||||
) {
|
) {
|
||||||
return app.openapi(route, async (c) => {
|
return app.openapi(route, async (c) => {
|
||||||
const { projectId } = c.req.valid('param')
|
const { projectId } = c.req.valid('param')
|
||||||
// const { populate = [] } = c.req.valid('query')
|
const { populate = [] } = c.req.valid('query')
|
||||||
|
|
||||||
const project = await db.query.projects.findFirst({
|
const project = await db.query.projects.findFirst({
|
||||||
where: eq(schema.projects.id, projectId)
|
where: eq(schema.projects.id, projectId),
|
||||||
// with: Object.fromEntries(populate.map((field) => [field, true]))
|
with: Object.fromEntries(populate.map((field) => [field, true]))
|
||||||
})
|
})
|
||||||
assert(project, 404, `Project not found "${projectId}"`)
|
assert(project, 404, `Project not found "${projectId}"`)
|
||||||
await acl(c, project, { label: 'Project' })
|
await acl(c, project, { label: 'Project' })
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { createRoute, type OpenAPIHono, z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
|
import type { AuthenticatedEnv } from '@/lib/types'
|
||||||
|
import { db, eq, paginationSchema, schema } from '@/db'
|
||||||
|
import { parseZodSchema } from '@/lib/utils'
|
||||||
|
|
||||||
|
const route = createRoute({
|
||||||
|
description: 'Lists projects the authenticated user has access to.',
|
||||||
|
tags: ['projects'],
|
||||||
|
operationId: 'listProjects',
|
||||||
|
method: 'get',
|
||||||
|
path: 'projects',
|
||||||
|
security: [{ bearerAuth: [] }],
|
||||||
|
request: {
|
||||||
|
query: paginationSchema
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'A list of projects',
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: z.array(schema.projectSelectSchema)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO
|
||||||
|
// ...openApiErrorResponses
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export function registerV1ProjectsListProjects(
|
||||||
|
app: OpenAPIHono<AuthenticatedEnv>
|
||||||
|
) {
|
||||||
|
return app.openapi(route, async (c) => {
|
||||||
|
const {
|
||||||
|
offset = 0,
|
||||||
|
limit = 10,
|
||||||
|
sort = 'desc',
|
||||||
|
sortBy = 'createdAt'
|
||||||
|
} = c.req.valid('query')
|
||||||
|
|
||||||
|
const user = c.get('user')
|
||||||
|
const teamMember = c.get('teamMember')
|
||||||
|
const isAdmin = user.role === 'admin'
|
||||||
|
|
||||||
|
const projects = await db.query.projects.findMany({
|
||||||
|
where: isAdmin
|
||||||
|
? undefined
|
||||||
|
: teamMember
|
||||||
|
? eq(schema.projects.teamId, teamMember.teamId)
|
||||||
|
: eq(schema.projects.userId, user.id),
|
||||||
|
with: {
|
||||||
|
lastPublishedDeployment: true
|
||||||
|
},
|
||||||
|
orderBy: (projects, { asc, desc }) => [
|
||||||
|
sort === 'desc' ? desc(projects[sortBy]) : asc(projects[sortBy])
|
||||||
|
],
|
||||||
|
offset,
|
||||||
|
limit
|
||||||
|
})
|
||||||
|
|
||||||
|
return c.json(parseZodSchema(z.array(schema.projectSelectSchema), projects))
|
||||||
|
})
|
||||||
|
}
|
|
@ -6,10 +6,11 @@ import {
|
||||||
pgTable,
|
pgTable,
|
||||||
text
|
text
|
||||||
} from '@fisch0920/drizzle-orm/pg-core'
|
} from '@fisch0920/drizzle-orm/pg-core'
|
||||||
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { deployments } from './deployment'
|
import { deployments, deploymentSelectSchema } from './deployment'
|
||||||
import { projects } from './project'
|
import { projects, projectSelectSchema } from './project'
|
||||||
import { users } from './user'
|
import { users, userSelectSchema } from './user'
|
||||||
import {
|
import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
|
@ -114,24 +115,43 @@ const stripeValidSubscriptionStatuses = new Set([
|
||||||
])
|
])
|
||||||
|
|
||||||
export const consumerSelectSchema = createSelectSchema(consumers)
|
export const consumerSelectSchema = createSelectSchema(consumers)
|
||||||
.openapi('Consumer')
|
|
||||||
.omit({
|
.omit({
|
||||||
_stripeCustomerId: true
|
_stripeCustomerId: true
|
||||||
})
|
})
|
||||||
|
.extend({
|
||||||
|
user: z
|
||||||
|
.lazy(() => userSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('User', { type: 'object' }),
|
||||||
|
|
||||||
export const consumerInsertSchema = createInsertSchema(consumers).pick({
|
project: z
|
||||||
token: true,
|
.lazy(() => projectSelectSchema)
|
||||||
plan: true,
|
.optional()
|
||||||
env: true,
|
.openapi('Project', { type: 'object' }),
|
||||||
coupon: true,
|
|
||||||
source: true,
|
|
||||||
userId: true,
|
|
||||||
projectId: true,
|
|
||||||
deploymentId: true
|
|
||||||
})
|
|
||||||
|
|
||||||
export const consumerUpdateSchema = createUpdateSchema(consumers).refine(
|
deployment: z
|
||||||
(consumer) => {
|
.lazy(() => deploymentSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Deployment', { type: 'object' })
|
||||||
|
})
|
||||||
|
.openapi('Consumer')
|
||||||
|
|
||||||
|
export const consumerInsertSchema = createInsertSchema(consumers)
|
||||||
|
.pick({
|
||||||
|
token: true,
|
||||||
|
plan: true,
|
||||||
|
env: true,
|
||||||
|
coupon: true,
|
||||||
|
source: true,
|
||||||
|
userId: true,
|
||||||
|
projectId: true,
|
||||||
|
deploymentId: true
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
||||||
|
export const consumerUpdateSchema = createUpdateSchema(consumers)
|
||||||
|
.strict()
|
||||||
|
.refine((consumer) => {
|
||||||
return {
|
return {
|
||||||
...consumer,
|
...consumer,
|
||||||
enabled:
|
enabled:
|
||||||
|
@ -139,5 +159,4 @@ export const consumerUpdateSchema = createUpdateSchema(consumers).refine(
|
||||||
(consumer.status &&
|
(consumer.status &&
|
||||||
stripeValidSubscriptionStatuses.has(consumer.status))
|
stripeValidSubscriptionStatuses.has(consumer.status))
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
|
@ -10,14 +10,14 @@ import {
|
||||||
import { z } from '@hono/zod-openapi'
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { projects } from './project'
|
import { projects } from './project'
|
||||||
import { teams } from './team'
|
import { teams, teamSelectSchema } from './team'
|
||||||
import {
|
import {
|
||||||
type Coupon,
|
type Coupon,
|
||||||
couponSchema,
|
couponSchema,
|
||||||
type PricingPlan,
|
type PricingPlan,
|
||||||
pricingPlanSchema
|
pricingPlanSchema
|
||||||
} from './types'
|
} from './types'
|
||||||
import { users } from './user'
|
import { users, userSelectSchema } from './user'
|
||||||
import {
|
import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
|
@ -114,6 +114,17 @@ export const deploymentSelectSchema = createSelectSchema(deployments, {
|
||||||
.omit({
|
.omit({
|
||||||
_url: true
|
_url: true
|
||||||
})
|
})
|
||||||
|
.extend({
|
||||||
|
user: z
|
||||||
|
.lazy(() => userSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('User', { type: 'object' }),
|
||||||
|
|
||||||
|
team: z
|
||||||
|
.lazy(() => teamSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Team', { type: 'object' })
|
||||||
|
})
|
||||||
.openapi('Deployment')
|
.openapi('Deployment')
|
||||||
|
|
||||||
export const deploymentInsertSchema = createInsertSchema(deployments, {
|
export const deploymentInsertSchema = createInsertSchema(deployments, {
|
||||||
|
@ -133,13 +144,17 @@ export const deploymentInsertSchema = createInsertSchema(deployments, {
|
||||||
// env: z.object({}),
|
// env: z.object({}),
|
||||||
pricingPlans: z.array(pricingPlanSchema),
|
pricingPlans: z.array(pricingPlanSchema),
|
||||||
coupons: z.array(couponSchema).optional()
|
coupons: z.array(couponSchema).optional()
|
||||||
}).omit({ id: true, createdAt: true, updatedAt: true })
|
|
||||||
|
|
||||||
export const deploymentUpdateSchema = createUpdateSchema(deployments).pick({
|
|
||||||
enabled: true,
|
|
||||||
published: true,
|
|
||||||
version: true,
|
|
||||||
description: true
|
|
||||||
})
|
})
|
||||||
|
.omit({ id: true, createdAt: true, updatedAt: true })
|
||||||
|
.strict()
|
||||||
|
|
||||||
|
export const deploymentUpdateSchema = createUpdateSchema(deployments)
|
||||||
|
.pick({
|
||||||
|
enabled: true,
|
||||||
|
published: true,
|
||||||
|
version: true,
|
||||||
|
description: true
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
||||||
// TODO: add admin select schema which includes all fields?
|
// TODO: add admin select schema which includes all fields?
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { relations } from '@fisch0920/drizzle-orm'
|
import { relations } from '@fisch0920/drizzle-orm'
|
||||||
import { index, pgTable, text } from '@fisch0920/drizzle-orm/pg-core'
|
import { index, pgTable, text } from '@fisch0920/drizzle-orm/pg-core'
|
||||||
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { consumers } from './consumer'
|
import { consumers, consumerSelectSchema } from './consumer'
|
||||||
import { deployments } from './deployment'
|
import { deployments, deploymentSelectSchema } from './deployment'
|
||||||
import { projects } from './project'
|
import { projects, projectSelectSchema } from './project'
|
||||||
import { users } from './user'
|
import { users, userSelectSchema } from './user'
|
||||||
import {
|
import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
|
@ -78,11 +79,34 @@ export const logEntriesRelations = relations(logEntries, ({ one }) => ({
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
export const logEntrySelectSchema =
|
export const logEntrySelectSchema = createSelectSchema(logEntries)
|
||||||
createSelectSchema(logEntries).openapi('LogEntry')
|
.extend({
|
||||||
|
user: z
|
||||||
|
.lazy(() => userSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('User', { type: 'object' }),
|
||||||
|
|
||||||
export const logEntryInsertSchema = createInsertSchema(logEntries).omit({
|
project: z
|
||||||
id: true,
|
.lazy(() => projectSelectSchema)
|
||||||
createdAt: true,
|
.optional()
|
||||||
updatedAt: true
|
.openapi('Project', { type: 'object' }),
|
||||||
})
|
|
||||||
|
deployment: z
|
||||||
|
.lazy(() => deploymentSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Deployment', { type: 'object' }),
|
||||||
|
|
||||||
|
consumer: z
|
||||||
|
.lazy(() => consumerSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Consumer', { type: 'object' })
|
||||||
|
})
|
||||||
|
.openapi('LogEntry')
|
||||||
|
|
||||||
|
export const logEntryInsertSchema = createInsertSchema(logEntries)
|
||||||
|
.omit({
|
||||||
|
id: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
|
@ -12,10 +12,10 @@ import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { getProviderToken } from '@/lib/auth/get-provider-token'
|
import { getProviderToken } from '@/lib/auth/get-provider-token'
|
||||||
|
|
||||||
import { deployments } from './deployment'
|
import { deployments, deploymentSelectSchema } from './deployment'
|
||||||
import { teams } from './team'
|
import { teams, teamSelectSchema } from './team'
|
||||||
import { type Webhook } from './types'
|
import { type Webhook } from './types'
|
||||||
import { users } from './user'
|
import { users, userSelectSchema } from './user'
|
||||||
import {
|
import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
|
@ -144,11 +144,11 @@ export const projectRelationsSchema: z.ZodType<ProjectRelationFields> = z.enum([
|
||||||
'team',
|
'team',
|
||||||
'lastPublishedDeployment',
|
'lastPublishedDeployment',
|
||||||
'lastDeployment'
|
'lastDeployment'
|
||||||
// 'deployments',
|
|
||||||
// 'publishedDeployments'
|
|
||||||
])
|
])
|
||||||
|
|
||||||
export const projectSelectSchema = createSelectSchema(projects, {
|
export const projectSelectSchema = createSelectSchema(projects, {
|
||||||
|
applicationFeePercent: (schema) => schema.nonnegative(),
|
||||||
|
|
||||||
stripeMetricProductIds: z.record(z.string(), z.string()).optional()
|
stripeMetricProductIds: z.record(z.string(), z.string()).optional()
|
||||||
// _webhooks: z.array(webhookSchema),
|
// _webhooks: z.array(webhookSchema),
|
||||||
// _stripeCouponIds: z.record(z.string(), z.string()).optional(),
|
// _stripeCouponIds: z.record(z.string(), z.string()).optional(),
|
||||||
|
@ -171,6 +171,27 @@ export const projectSelectSchema = createSelectSchema(projects, {
|
||||||
_stripePlanIds: true,
|
_stripePlanIds: true,
|
||||||
_stripeAccountId: true
|
_stripeAccountId: true
|
||||||
})
|
})
|
||||||
|
.extend({
|
||||||
|
user: z
|
||||||
|
.lazy(() => userSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('User', { type: 'object' }),
|
||||||
|
|
||||||
|
team: z
|
||||||
|
.lazy(() => teamSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Team', { type: 'object' }),
|
||||||
|
|
||||||
|
lastPublishedDeployment: z
|
||||||
|
.lazy(() => deploymentSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Deployment', { type: 'object' }),
|
||||||
|
|
||||||
|
lastDeployment: z
|
||||||
|
.lazy(() => deploymentSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('Deployment', { type: 'object' })
|
||||||
|
})
|
||||||
.openapi('Project')
|
.openapi('Project')
|
||||||
|
|
||||||
export const projectInsertSchema = createInsertSchema(projects, {
|
export const projectInsertSchema = createInsertSchema(projects, {
|
||||||
|
@ -189,6 +210,7 @@ export const projectInsertSchema = createInsertSchema(projects, {
|
||||||
name: true,
|
name: true,
|
||||||
userId: true
|
userId: true
|
||||||
})
|
})
|
||||||
|
.strict()
|
||||||
.refine((data) => {
|
.refine((data) => {
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
|
@ -197,7 +219,7 @@ export const projectInsertSchema = createInsertSchema(projects, {
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: narrow update schema
|
// TODO: narrow update schema
|
||||||
export const projectUpdateSchema = createUpdateSchema(projects)
|
export const projectUpdateSchema = createUpdateSchema(projects).strict()
|
||||||
|
|
||||||
export const projectDebugSelectSchema = createSelectSchema(projects).pick({
|
export const projectDebugSelectSchema = createSelectSchema(projects).pick({
|
||||||
id: true,
|
id: true,
|
||||||
|
|
|
@ -5,9 +5,10 @@ import {
|
||||||
pgTable,
|
pgTable,
|
||||||
primaryKey
|
primaryKey
|
||||||
} from '@fisch0920/drizzle-orm/pg-core'
|
} from '@fisch0920/drizzle-orm/pg-core'
|
||||||
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { teams } from './team'
|
import { teams, teamSelectSchema } from './team'
|
||||||
import { users } from './user'
|
import { users, userSelectSchema } from './user'
|
||||||
import {
|
import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
|
@ -59,14 +60,29 @@ export const teamMembersRelations = relations(teamMembers, ({ one }) => ({
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
export const teamMemberSelectSchema =
|
export const teamMemberSelectSchema = createSelectSchema(teamMembers)
|
||||||
createSelectSchema(teamMembers).openapi('TeamMember')
|
.extend({
|
||||||
|
user: z
|
||||||
|
.lazy(() => userSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('User', { type: 'object' }),
|
||||||
|
|
||||||
export const teamMemberInsertSchema = createInsertSchema(teamMembers).pick({
|
team: z
|
||||||
userId: true,
|
.lazy(() => teamSelectSchema)
|
||||||
role: true
|
.optional()
|
||||||
})
|
.openapi('Team', { type: 'object' })
|
||||||
|
})
|
||||||
|
.openapi('TeamMember')
|
||||||
|
|
||||||
export const teamMemberUpdateSchema = createUpdateSchema(teamMembers).pick({
|
export const teamMemberInsertSchema = createInsertSchema(teamMembers)
|
||||||
role: true
|
.pick({
|
||||||
})
|
userId: true,
|
||||||
|
role: true
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
||||||
|
export const teamMemberUpdateSchema = createUpdateSchema(teamMembers)
|
||||||
|
.pick({
|
||||||
|
role: true
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
|
@ -6,9 +6,10 @@ import {
|
||||||
text,
|
text,
|
||||||
uniqueIndex
|
uniqueIndex
|
||||||
} from '@fisch0920/drizzle-orm/pg-core'
|
} from '@fisch0920/drizzle-orm/pg-core'
|
||||||
|
import { z } from '@hono/zod-openapi'
|
||||||
|
|
||||||
import { teamMembers } from './team-member'
|
import { teamMembers } from './team-member'
|
||||||
import { users } from './user'
|
import { users, userSelectSchema } from './user'
|
||||||
import {
|
import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
|
@ -45,16 +46,27 @@ export const teamsRelations = relations(teams, ({ one, many }) => ({
|
||||||
members: many(teamMembers)
|
members: many(teamMembers)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
export const teamSelectSchema = createSelectSchema(teams).openapi('Team')
|
export const teamSelectSchema = createSelectSchema(teams)
|
||||||
|
.extend({
|
||||||
|
owner: z
|
||||||
|
.lazy(() => userSelectSchema)
|
||||||
|
.optional()
|
||||||
|
.openapi('User', { type: 'object' })
|
||||||
|
})
|
||||||
|
.openapi('Team')
|
||||||
|
|
||||||
export const teamInsertSchema = createInsertSchema(teams, {
|
export const teamInsertSchema = createInsertSchema(teams, {
|
||||||
slug: (schema) =>
|
slug: (schema) =>
|
||||||
schema.refine((slug) => validators.team(slug), {
|
schema.refine((slug) => validators.team(slug), {
|
||||||
message: 'Invalid team slug'
|
message: 'Invalid team slug'
|
||||||
})
|
})
|
||||||
}).omit({ id: true, createdAt: true, updatedAt: true, ownerId: true })
|
|
||||||
|
|
||||||
export const teamUpdateSchema = createUpdateSchema(teams).pick({
|
|
||||||
name: true,
|
|
||||||
ownerId: true
|
|
||||||
})
|
})
|
||||||
|
.omit({ id: true, createdAt: true, updatedAt: true, ownerId: true })
|
||||||
|
.strict()
|
||||||
|
|
||||||
|
export const teamUpdateSchema = createUpdateSchema(teams)
|
||||||
|
.pick({
|
||||||
|
name: true,
|
||||||
|
ownerId: true
|
||||||
|
})
|
||||||
|
.strict()
|
||||||
|
|
|
@ -89,6 +89,7 @@ export const userInsertSchema = createInsertSchema(users, {
|
||||||
lastName: true,
|
lastName: true,
|
||||||
image: true
|
image: true
|
||||||
})
|
})
|
||||||
|
.strict()
|
||||||
.refine((user) => {
|
.refine((user) => {
|
||||||
return {
|
return {
|
||||||
...user,
|
...user,
|
||||||
|
@ -105,6 +106,7 @@ export const userUpdateSchema = createUpdateSchema(users)
|
||||||
password: true,
|
password: true,
|
||||||
isStripeConnectEnabledByDefault: true
|
isStripeConnectEnabledByDefault: true
|
||||||
})
|
})
|
||||||
|
.strict()
|
||||||
.refine((user) => {
|
.refine((user) => {
|
||||||
return {
|
return {
|
||||||
...user,
|
...user,
|
||||||
|
|
|
@ -44,3 +44,5 @@ export type ConsumerWithProjectAndDeployment = BuildQueryResult<
|
||||||
Tables['consumers'],
|
Tables['consumers'],
|
||||||
{ with: { project: true; deployment: true } }
|
{ with: { project: true; deployment: true } }
|
||||||
>
|
>
|
||||||
|
|
||||||
|
export type LogEntry = z.infer<typeof schema.logEntrySelectSchema>
|
||||||
|
|
|
@ -7,9 +7,6 @@ import { env } from '@/lib/env'
|
||||||
|
|
||||||
import { assert } from '../utils'
|
import { assert } from '../utils'
|
||||||
|
|
||||||
const token = await jwt.sign({ userId: 'test', type: 'user' }, env.JWT_SECRET)
|
|
||||||
console.log({ token })
|
|
||||||
|
|
||||||
export const authenticate = createMiddleware<AuthenticatedEnv>(
|
export const authenticate = createMiddleware<AuthenticatedEnv>(
|
||||||
async function authenticateMiddleware(ctx, next) {
|
async function authenticateMiddleware(ctx, next) {
|
||||||
const credentials = ctx.req.raw.headers.get('Authorization')
|
const credentials = ctx.req.raw.headers.get('Authorization')
|
||||||
|
|
Ładowanie…
Reference in New Issue