web/src/utils/fetch-privacy-policy.ts

69 lines · 1379 bytes

 1import { error } from './logger';
 2
 3export const fetchTosdrPrivacy = async (
 4  serviceId: string,
 5): Promise<PrivacyPolicyResponse | null> => {
 6  const endpoint = `https://privacy-policies.as93.workers.dev/${serviceId}`;
 7  try {
 8    const res = await fetch(endpoint);
 9    if (!res.ok) {
10      error('ToS;DR', `HTTP ${res.status} for service ${serviceId} (${endpoint})`);
11      return null;
12    }
13    return await res.json();
14  } catch (err) {
15    error('ToS;DR', `Network error for service ${serviceId}: ${err}`);
16    return null;
17  }
18};
19
20interface Document {
21  id: number;
22  name: string;
23  url: string;
24  updated_at: string;
25  created_at: string;
26}
27
28interface Case {
29  id: number;
30  weight: number;
31  title: string;
32  description: string;
33  updated_at: string;
34  created_at: string;
35  topic_id: number;
36  classification: string;
37}
38
39interface Point {
40  id: number;
41  title: string;
42  source: string;
43  status: string;
44  analysis: string;
45  case: Case;
46  document_id: number | null;
47  updated_at: string;
48  created_at: string;
49}
50
51interface Params {
52  id: number;
53  is_comprehensively_reviewed: boolean;
54  name: string;
55  updated_at: string;
56  created_at: string;
57  slug: string;
58  rating: string;
59  urls: string[];
60  image: string;
61  documents: Document[];
62  points: Point[];
63}
64
65export interface PrivacyPolicyResponse {
66  error: number;
67  message: string;
68  parameters: Params;
69}