mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
39 lines
945 B
TypeScript
39 lines
945 B
TypeScript
export type SendInstance = {
|
|
uniqueId: string;
|
|
timestamp: Date;
|
|
version: string;
|
|
};
|
|
|
|
export const sendInstance = async ({ uniqueId, timestamp, version }: SendInstance) => {
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
const isTelemetryDisabled = process.env.DISABLE_TELEMETRY === 'true';
|
|
|
|
if (!isProduction || isTelemetryDisabled) {
|
|
return;
|
|
}
|
|
|
|
const url = 'https://documenso-instances.fly.dev/ping';
|
|
|
|
try {
|
|
const response = await fetch(url, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
uniqueId: String(uniqueId),
|
|
timestamp: new Date(timestamp).toISOString(),
|
|
version,
|
|
}),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to record instance, failed with status code ${response.status}`);
|
|
}
|
|
|
|
return await response.json();
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|