(
request: FastifyRequest<{
Body: DeprecatedUpdateProfilePayload;
}>,
reply: FastifyReply,
)
| 10 | } from '@openpanel/validation'; |
| 11 | |
| 12 | export async function updateProfile( |
| 13 | request: FastifyRequest<{ |
| 14 | Body: DeprecatedUpdateProfilePayload; |
| 15 | }>, |
| 16 | reply: FastifyReply, |
| 17 | ) { |
| 18 | const payload = request.body; |
| 19 | const projectId = request.client!.projectId; |
| 20 | if (!projectId) { |
| 21 | return reply.status(400).send('No projectId'); |
| 22 | } |
| 23 | const ip = request.clientIp; |
| 24 | const ua = request.headers['user-agent']; |
| 25 | const uaInfo = parseUserAgent(ua, payload.properties); |
| 26 | const geo = await getGeoLocation(ip); |
| 27 | |
| 28 | await upsertProfile({ |
| 29 | ...payload, |
| 30 | id: payload.profileId, |
| 31 | isExternal: true, |
| 32 | projectId, |
| 33 | properties: { |
| 34 | ...(payload.properties ?? {}), |
| 35 | country: geo.country, |
| 36 | city: geo.city, |
| 37 | region: geo.region, |
| 38 | longitude: geo.longitude, |
| 39 | latitude: geo.latitude, |
| 40 | os: uaInfo.os, |
| 41 | os_version: uaInfo.osVersion, |
| 42 | browser: uaInfo.browser, |
| 43 | browser_version: uaInfo.browserVersion, |
| 44 | device: uaInfo.device, |
| 45 | brand: uaInfo.brand, |
| 46 | model: uaInfo.model, |
| 47 | }, |
| 48 | }); |
| 49 | |
| 50 | reply.status(202).send(payload.profileId); |
| 51 | } |
| 52 | |
| 53 | export async function incrementProfileProperty( |
| 54 | request: FastifyRequest<{ |
nothing calls this directly
no test coverage detected