diff --git a/worker/src/data.ts b/worker/src/data.ts index d4bf58e9..5af3b148 100644 --- a/worker/src/data.ts +++ b/worker/src/data.ts @@ -10,6 +10,7 @@ export enum UuidMetadataKey { EXTRA = "e", INSTALLATION_TYPE = "i", UPDATED = "u", + REGION = "r", VERSION = "v", } @@ -32,6 +33,7 @@ export interface UuidMetadata { [UuidMetadataKey.VERSION]: string; [UuidMetadataKey.INSTALLATION_TYPE]: ShortInstallationType; [UuidMetadataKey.COUNTRY]?: string; + [UuidMetadataKey.REGION]?: string; [UuidMetadataKey.EXTRA]: MetadataExtra[]; } @@ -65,6 +67,7 @@ export interface IncomingPayload { addons?: { slug: string }[]; automation_count?: number; country?: string; + region?: string; custom_integrations?: { domain: string; version: string | null }[]; installation_type: string; integration_count?: number; @@ -140,6 +143,7 @@ export const generateUuidMetadata = ( [UuidMetadataKey.INSTALLATION_TYPE]: InstallationTypes[payload.installation_type], [UuidMetadataKey.COUNTRY]: payload.country, + [UuidMetadataKey.REGION]: payload.region, [UuidMetadataKey.VERSION]: payload.version, [UuidMetadataKey.EXTRA]: extra, }; diff --git a/worker/src/handlers/post.ts b/worker/src/handlers/post.ts index 603afa21..06a169f1 100644 --- a/worker/src/handlers/post.ts +++ b/worker/src/handlers/post.ts @@ -12,6 +12,7 @@ import { assertIncomingPayload } from "../utils/validate"; const updateThreshold = 2592000000; const expirationTtl = 5184000; +const withRegion = new Set(["US"]); export async function handlePostWrapper( request: Request, @@ -29,6 +30,9 @@ async function handlePost(request: Request, sentry: Toucan): Promise { sentry.addBreadcrumb({ message: "Prosess started" }); const incomingPayload = await request.json(); incomingPayload.country = request.cf.country; + if (withRegion.has(incomingPayload.country)) { + incomingPayload.region = request.cf.regionCode; + } sentry.setUser({ id: incomingPayload.uuid }); sentry.setExtras(incomingPayload); diff --git a/worker/src/utils/validate.ts b/worker/src/utils/validate.ts index 15d7c92d..8560abc1 100644 --- a/worker/src/utils/validate.ts +++ b/worker/src/utils/validate.ts @@ -37,7 +37,8 @@ export const IncomingPayload = object({ ) ), automation_count: optional(number()), - country: size(string(), 2, 5), + country: optional(size(string(), 2, 2)), + region: optional(size(string(), 2, 2)), custom_integrations: optional( array(object({ domain: string(), version: optional(nullable(string())) })) ),