- Create new @link-stack/logger package wrapping Pino for structured logging - Replace all console.log/error/warn statements across the monorepo - Configure environment-aware logging (pretty-print in dev, JSON in prod) - Add automatic redaction of sensitive fields (passwords, tokens, etc.) - Remove dead commented-out logger file from bridge-worker - Follow Pino's standard argument order (context object first, message second) - Support log levels via LOG_LEVEL environment variable - Export TypeScript types for better IDE support This provides consistent, structured logging across all applications and packages, making debugging easier and production logs more parseable.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { createLogger } from "@link-stack/logger";
|
|
|
|
const logger = createLogger('link-utils');
|
|
|
|
export const fetchLeafcutter = async (url: string, options: any) => {
|
|
/*
|
|
|
|
const headers = {
|
|
'X-Opensearch-Username': process.env.OPENSEARCH_USER!,
|
|
'X-Opensearch-Password': process.env.OPENSEARCH_PASSWORD!,
|
|
'X-Leafcutter-User': token.email.toLowerCase()
|
|
};
|
|
*/
|
|
const fetchData = async (url: string, options: any) => {
|
|
try {
|
|
const res = await fetch(url, options);
|
|
const json = await res.json();
|
|
return json;
|
|
} catch (error) {
|
|
logger.error({ error }, "Error occurred");
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const data = await fetchData(url, options);
|
|
|
|
if (!data) {
|
|
const csrfURL = `${process.env.NEXT_PUBLIC_LEAFCUTTER_URL}/api/auth/csrf`;
|
|
const csrfData = await fetchData(csrfURL, {});
|
|
const authURL = `${process.env.NEXT_PUBLIC_LEAFCUTTER_URL}/api/auth/callback/credentials`;
|
|
const authData = await fetchData(authURL, { method: "POST" });
|
|
if (!authData) {
|
|
return null;
|
|
} else {
|
|
return await fetchData(url, options);
|
|
}
|
|
} else {
|
|
return data;
|
|
}
|
|
};
|