Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/extension/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const sendBootData = async (_, tab: Tabs.Tab) => {

const [deviceId, boot] = await Promise.all([
getOrGenerateDeviceId(),
getBootData('companion', href),
getBootData({ app: 'companion', url: href }),
]);

let settingsOutput = boot.settings;
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/contexts/BootProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ export const BootDataProvider = ({
} = useQuery<Partial<Boot>>({
queryKey: BOOT_QUERY_KEY,
queryFn: async () => {
const result = await getBootData(app);
const pathname = globalThis?.location?.pathname;
const result = await getBootData({ app, pathname });
preloadFeedsRef.current({ feeds: result.feeds, user: result.user });

return result;
Expand Down
39 changes: 31 additions & 8 deletions packages/shared/src/lib/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,28 @@ export type BootCacheData = Pick<
| 'geo'
> & { lastModifier?: string; isAndroidApp?: boolean };

const getBootURL = (app: string, url?: string) => {
/**
* Get normalized referrer type from pathname
* Only returns known referrer identifiers for privacy
*/
const getReferrerType = (pathname?: string): string | undefined => {
if (pathname?.startsWith('/recruiter')) {
return 'recruiter';
}
return undefined;
};

const getBootURL = (app: string, url?: string, pathname?: string) => {
const appRoute = app === 'companion' ? '/companion' : '';
const params = new URLSearchParams();
params.append('v', process.env.CURRENT_VERSION);
if (url) {
params.append('url', url);
}
const referrer = getReferrerType(pathname);
if (referrer) {
params.append('referrer', referrer);
}

return `${apiUrl}/boot${appRoute}?${params}`;
};
Expand All @@ -108,19 +123,27 @@ const enrichBootWithFeatures = async (boot: Boot): Promise<Boot> => {
return { ...boot, exp: { ...boot.exp, features: JSON.parse(features) } };
};

export async function getBootData(
app: string,
url?: string,
options?: Record<'cookies', string>,
): Promise<Boot> {
const bootURL = getBootURL(app, url);
interface GetBootDataParams {
app: string;
url?: string;
cookies?: string;
pathname?: string;
}

export async function getBootData({
app,
url,
cookies,
pathname,
}: GetBootDataParams): Promise<Boot> {
const bootURL = getBootURL(app, url, pathname);
const res = await fetch(bootURL, {
method: 'GET',
credentials: 'include',
headers: {
app,
'Content-Type': 'application/json',
...(options?.cookies && { Cookie: options.cookies }),
...(cookies && { Cookie: cookies }),
},
});
const result = await res.json();
Expand Down