Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions worker/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum UuidMetadataKey {
EXTRA = "e",
INSTALLATION_TYPE = "i",
UPDATED = "u",
REGION = "r",
VERSION = "v",
}

Expand All @@ -32,6 +33,7 @@ export interface UuidMetadata {
[UuidMetadataKey.VERSION]: string;
[UuidMetadataKey.INSTALLATION_TYPE]: ShortInstallationType;
[UuidMetadataKey.COUNTRY]?: string;
[UuidMetadataKey.REGION]?: string;
[UuidMetadataKey.EXTRA]: MetadataExtra[];
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};
Expand Down
4 changes: 4 additions & 0 deletions worker/src/handlers/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +30,9 @@ async function handlePost(request: Request, sentry: Toucan): Promise<Response> {
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);
Expand Down
3 changes: 2 additions & 1 deletion worker/src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())) }))
),
Expand Down