(
request: FastifyRequest<{ Body: z.infer<typeof zCreateProject> }>,
reply: FastifyReply
)
| 91 | } |
| 92 | |
| 93 | export async function createProject( |
| 94 | request: FastifyRequest<{ Body: z.infer<typeof zCreateProject> }>, |
| 95 | reply: FastifyReply |
| 96 | ) { |
| 97 | const { name, domain, cors, crossDomain, types } = request.body; |
| 98 | |
| 99 | // Generate a default client secret |
| 100 | const secret = `sec_${crypto.randomBytes(10).toString('hex')}`; |
| 101 | const clientData = { |
| 102 | organizationId: request.client!.organizationId, |
| 103 | name: 'First client', |
| 104 | type: 'write' as const, |
| 105 | secret: await hashPassword(secret), |
| 106 | }; |
| 107 | |
| 108 | const project = await db.project.create({ |
| 109 | data: { |
| 110 | id: await getId('project', name), |
| 111 | organizationId: request.client!.organizationId, |
| 112 | name, |
| 113 | domain: domain ? stripTrailingSlash(domain) : null, |
| 114 | cors: cors.map((c) => stripTrailingSlash(c)), |
| 115 | crossDomain: crossDomain ?? false, |
| 116 | allowUnsafeRevenueTracking: false, |
| 117 | filters: [], |
| 118 | types, |
| 119 | clients: { |
| 120 | create: clientData, |
| 121 | }, |
| 122 | }, |
| 123 | include: { |
| 124 | clients: { |
| 125 | select: { |
| 126 | id: true, |
| 127 | }, |
| 128 | }, |
| 129 | }, |
| 130 | }); |
| 131 | |
| 132 | await Promise.all([ |
| 133 | getProjectByIdCached.clear(project.id), |
| 134 | ...project.clients.map((client) => getClientByIdCached.clear(client.id)), |
| 135 | ]); |
| 136 | |
| 137 | reply.send({ |
| 138 | data: { |
| 139 | ...project, |
| 140 | client: project.clients[0] |
| 141 | ? { |
| 142 | id: project.clients[0].id, |
| 143 | secret, |
| 144 | } |
| 145 | : null, |
| 146 | }, |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | export async function updateProject( |
nothing calls this directly
no test coverage detected