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

73 lines · 1450 bytes

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