-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
robotoff.ts
51 lines (43 loc) · 1.36 KB
/
robotoff.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import createClient from "openapi-fetch";
import { paths } from "./schemas/robotoff";
export class Robotoff {
/** The fetch function used for every request */
private readonly fetch: typeof global.fetch;
/** The raw openapi-fetch client is used for every request exposed by the openapi schema */
private readonly raw: ReturnType<typeof createClient<paths>>;
constructor(fetch: typeof global.fetch) {
this.fetch = fetch;
this.raw = createClient<paths>({
fetch: this.fetch,
baseUrl: "https://robotoff.openfoodfacts.org/api/v1",
});
}
async annotate(
body: paths["/insights/annotate"]["post"]["requestBody"]["content"]["application/x-www-form-urlencoded"]
) {
return this.raw.POST("/insights/annotate", {
body: body,
});
}
async questionsByProductCode(code: number) {
const result = await this.raw.GET("/questions/{barcode}", {
params: {
path: { barcode: code },
},
});
return result.data;
}
async insightDetail(id: string) {
const result = await this.raw.GET("/insights/detail/{id}", {
params: { path: { id } },
});
return result.data;
}
async loadLogo(logoId: string) {
// @ts-expect-error TODO: still not documented
const result = await this.raw.GET("/images/logos/{logoId}", {
params: { path: { logoId } },
});
return result.data;
}
}