Skip to content

Commit

Permalink
Merge branch 'main' into MI-742
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarTrebinjac authored Jan 9, 2025
2 parents ba3b6bb + 23a7a5d commit 99df8ed
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const { serviceAccount } = createServiceAccountAndGrantRoles(
{ name: 'secret', role: 'roles/secretmanager.secretAccessor' },
{ name: 'pubsub', role: 'roles/pubsub.editor' },
{ name: 'objViewer', role: 'roles/storage.objectViewer' },
{ name: 'bigqueryJobUser', role: 'roles/bigquery.jobUser' },
{ name: 'bigqueryDataViwer', role: 'roles/bigquery.dataViewer' },
],
isAdhocEnv,
);
Expand Down
259 changes: 259 additions & 0 deletions src/common/geo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
export enum Continent {
Africa = 'AF',
Antarctica = 'AN',
Asia = 'AS',
Europe = 'EU',
Oceania = 'OC',
NorthAmerica = 'NA',
SouthAmerica = 'SA',
}

export const countryCodeToContinent: Record<string, Continent> = {
AF: Continent.Asia,
AX: Continent.Europe,
AL: Continent.Europe,
DZ: Continent.Africa,
AS: Continent.Oceania,
AD: Continent.Europe,
AO: Continent.Africa,
AI: Continent.NorthAmerica,
AQ: Continent.Antarctica,
AG: Continent.NorthAmerica,
AR: Continent.SouthAmerica,
AM: Continent.Asia,
AW: Continent.NorthAmerica,
AU: Continent.Oceania,
AT: Continent.Europe,
AZ: Continent.Asia,
BS: Continent.NorthAmerica,
BH: Continent.Asia,
BD: Continent.Asia,
BB: Continent.NorthAmerica,
BY: Continent.Europe,
BE: Continent.Europe,
BZ: Continent.NorthAmerica,
BJ: Continent.Africa,
BM: Continent.NorthAmerica,
BT: Continent.Asia,
BO: Continent.SouthAmerica,
BA: Continent.Europe,
BW: Continent.Africa,
BV: Continent.Antarctica,
BR: Continent.SouthAmerica,
IO: Continent.Asia,
BN: Continent.Asia,
BG: Continent.Europe,
BF: Continent.Africa,
BI: Continent.Africa,
KH: Continent.Asia,
CM: Continent.Africa,
CA: Continent.NorthAmerica,
CV: Continent.Africa,
KY: Continent.NorthAmerica,
CF: Continent.Africa,
TD: Continent.Africa,
CL: Continent.SouthAmerica,
CN: Continent.Asia,
CX: Continent.Asia,
CC: Continent.Asia,
CO: Continent.SouthAmerica,
KM: Continent.Africa,
CG: Continent.Africa,
CD: Continent.Africa,
CK: Continent.Oceania,
CR: Continent.NorthAmerica,
CI: Continent.Africa,
HR: Continent.Europe,
CU: Continent.NorthAmerica,
CY: Continent.Asia,
CZ: Continent.Europe,
DK: Continent.Europe,
DJ: Continent.Africa,
DM: Continent.NorthAmerica,
DO: Continent.NorthAmerica,
EC: Continent.SouthAmerica,
EG: Continent.Africa,
SV: Continent.NorthAmerica,
GQ: Continent.Africa,
ER: Continent.Africa,
EE: Continent.Europe,
SZ: Continent.Africa,
ET: Continent.Africa,
FK: Continent.SouthAmerica,
FO: Continent.Europe,
FJ: Continent.Oceania,
FI: Continent.Europe,
FR: Continent.Europe,
GF: Continent.SouthAmerica,
PF: Continent.Oceania,
TF: Continent.Antarctica,
GA: Continent.Africa,
GM: Continent.Africa,
GE: Continent.Asia,
DE: Continent.Europe,
GH: Continent.Africa,
GI: Continent.Europe,
GR: Continent.Europe,
GL: Continent.NorthAmerica,
GD: Continent.NorthAmerica,
GP: Continent.NorthAmerica,
GU: Continent.Oceania,
GT: Continent.NorthAmerica,
GG: Continent.Europe,
GN: Continent.Africa,
GW: Continent.Africa,
GY: Continent.SouthAmerica,
HT: Continent.NorthAmerica,
HM: Continent.Antarctica,
VA: Continent.Europe,
HN: Continent.NorthAmerica,
HK: Continent.Asia,
HU: Continent.Europe,
IS: Continent.Europe,
IN: Continent.Asia,
ID: Continent.Asia,
IR: Continent.Asia,
IQ: Continent.Asia,
IE: Continent.Europe,
IM: Continent.Europe,
IL: Continent.Asia,
IT: Continent.Europe,
JM: Continent.NorthAmerica,
JP: Continent.Asia,
JE: Continent.Europe,
JO: Continent.Asia,
KZ: Continent.Asia,
KE: Continent.Africa,
KI: Continent.Oceania,
KP: Continent.Asia,
KR: Continent.Asia,
KW: Continent.Asia,
KG: Continent.Asia,
LA: Continent.Asia,
LV: Continent.Europe,
LB: Continent.Asia,
LS: Continent.Africa,
LR: Continent.Africa,
LY: Continent.Africa,
LI: Continent.Europe,
LT: Continent.Europe,
LU: Continent.Europe,
MO: Continent.Asia,
MG: Continent.Africa,
MW: Continent.Africa,
MY: Continent.Asia,
MV: Continent.Asia,
ML: Continent.Africa,
MT: Continent.Europe,
MH: Continent.Oceania,
MQ: Continent.NorthAmerica,
MR: Continent.Africa,
MU: Continent.Africa,
YT: Continent.Africa,
MX: Continent.NorthAmerica,
FM: Continent.Oceania,
MD: Continent.Europe,
MC: Continent.Europe,
MN: Continent.Asia,
ME: Continent.Europe,
MS: Continent.NorthAmerica,
MA: Continent.Africa,
MZ: Continent.Africa,
MM: Continent.Asia,
NA: Continent.Africa,
NR: Continent.Oceania,
NP: Continent.Asia,
NL: Continent.Europe,
NC: Continent.Oceania,
NZ: Continent.Oceania,
NI: Continent.NorthAmerica,
NE: Continent.Africa,
NG: Continent.Africa,
NU: Continent.Oceania,
NF: Continent.Oceania,
MK: Continent.Europe,
MP: Continent.Oceania,
NO: Continent.Europe,
OM: Continent.Asia,
PK: Continent.Asia,
PW: Continent.Oceania,
PS: Continent.Asia,
PA: Continent.NorthAmerica,
PG: Continent.Oceania,
PY: Continent.SouthAmerica,
PE: Continent.SouthAmerica,
PH: Continent.Asia,
PN: Continent.Oceania,
PL: Continent.Europe,
PT: Continent.Europe,
PR: Continent.NorthAmerica,
QA: Continent.Asia,
RE: Continent.Africa,
RO: Continent.Europe,
RU: Continent.Europe,
RW: Continent.Africa,
BL: Continent.NorthAmerica,
SH: Continent.Africa,
KN: Continent.NorthAmerica,
LC: Continent.NorthAmerica,
MF: Continent.NorthAmerica,
PM: Continent.NorthAmerica,
VC: Continent.NorthAmerica,
WS: Continent.Oceania,
SM: Continent.Europe,
ST: Continent.Africa,
SA: Continent.Asia,
SN: Continent.Africa,
RS: Continent.Europe,
SC: Continent.Africa,
SL: Continent.Africa,
SG: Continent.Asia,
SX: Continent.NorthAmerica,
SK: Continent.Europe,
SI: Continent.Europe,
SB: Continent.Oceania,
SO: Continent.Africa,
ZA: Continent.Africa,
GS: Continent.Antarctica,
SS: Continent.Africa,
ES: Continent.Europe,
LK: Continent.Asia,
SD: Continent.Africa,
SR: Continent.SouthAmerica,
SJ: Continent.Europe,
SE: Continent.Europe,
CH: Continent.Europe,
SY: Continent.Asia,
TW: Continent.Asia,
TJ: Continent.Asia,
TZ: Continent.Africa,
TH: Continent.Asia,
TL: Continent.Asia,
TG: Continent.Africa,
TK: Continent.Oceania,
TO: Continent.Oceania,
TT: Continent.NorthAmerica,
TN: Continent.Africa,
TR: Continent.Asia,
TM: Continent.Asia,
TC: Continent.NorthAmerica,
TV: Continent.Oceania,
UG: Continent.Africa,
UA: Continent.Europe,
AE: Continent.Asia,
GB: Continent.Europe,
US: Continent.NorthAmerica,
UM: Continent.Oceania,
UY: Continent.SouthAmerica,
UZ: Continent.Asia,
VU: Continent.Oceania,
VE: Continent.SouthAmerica,
VN: Continent.Asia,
VG: Continent.NorthAmerica,
VI: Continent.NorthAmerica,
WF: Continent.Oceania,
EH: Continent.Africa,
YE: Continent.Asia,
ZM: Continent.Africa,
ZW: Continent.Africa,
};
7 changes: 6 additions & 1 deletion src/routes/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { maxFeedsPerUser } from '../types';
import { queryReadReplica } from '../common/queryReadReplica';
import { queryDataSource } from '../common/queryDataSource';
import { isPlusMember } from '../paddle';
import { Continent, countryCodeToContinent } from '../common/geo';

export type BootSquadSource = Omit<GQLSource, 'currentMember'> & {
permalink: string;
Expand All @@ -79,6 +80,7 @@ export type Experimentation = {

export type Geo = {
region?: string;
continent?: Continent;
};

interface ComputedAlerts {
Expand Down Expand Up @@ -136,8 +138,11 @@ type BootMiddleware = (
) => Promise<Record<string, unknown>>;

const geoSection = (req: FastifyRequest): BaseBoot['geo'] => {
const region = req.headers['x-client-region'] as string;

return {
region: req.headers['x-client-region'] as string,
region,
continent: countryCodeToContinent[region],
};
};

Expand Down

0 comments on commit 99df8ed

Please sign in to comment.