import { FetchFn } from "./types.js"; import { components, operations, paths } from "./schemas/folksonomy.js"; import * as _$openapi_fetch0 from "openapi-fetch"; import createClient from "openapi-fetch"; //#region src/folksonomy.d.ts type FolksonomyTag = components["schemas"]["ProductTag"]; type FolksonomyKey = { k: string; count: number; values: number; }; declare class Folksonomy { private readonly fetch; private readonly baseUrl; private authToken?; readonly client: ReturnType>; constructor(fetch: FetchFn, options?: { baseUrl?: string; authToken?: string; }); private validateAuthToken; /** * Get the list of keys with statistics * * The keys list can be restricted to private tags from some owner. */ getKeys(): Promise<_$openapi_fetch0.FetchResponse<{ parameters: { query?: { q?: string | null; owner?: string; }; header?: never; path?: never; cookie?: never; }; requestBody?: never; responses: { 200: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["KeyStats"][]; }; }; 422: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["HTTPValidationError"]; }; }; }; }, _$openapi_fetch0.FetchOptions<{ parameters: { query?: { q?: string | null; owner?: string; }; header?: never; path?: never; cookie?: never; }; requestBody?: never; responses: { 200: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["KeyStats"][]; }; }; 422: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["HTTPValidationError"]; }; }; }; }> | undefined, `${string}/${string}`>>; /** * Get the list of products that have a `key` or `key=value` if `value` is provided */ getProducts(key: string, value?: string): Promise<_$openapi_fetch0.FetchResponse<{ parameters: { query?: { owner?: unknown; k?: unknown; v?: unknown; }; header?: never; path?: never; cookie?: never; }; requestBody?: never; responses: { 200: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["ProductList"][]; }; }; 422: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["HTTPValidationError"]; }; }; }; }, { params: { query: { k: string; v: string; } | { k: string; v?: undefined; }; }; }, `${string}/${string}`>>; /** * Update a product tag, returns error if the tag does not exist * * @param tag Tag to update with the following fields: * - `k`: key * - `v`: value * - `product`: barcode * - `version`: version of the tag (must be equal to previous version + 1) * - `owner`: user_id of the owner of the tag (empty for public tags) * * @returns if the tag was added or updated * @example * const err = await folksonomy.putTag({ k: "vegan", v: "yes", product: "1234567890123", version: 2 }); * if (err) console.error("Error updating tag:", err); */ putTag(tag: FolksonomyTag): Promise<{ detail?: { loc: (string | number)[]; msg: string; type: string; }[] | undefined; } | undefined>; /** * Get a list of existing tags for a product */ getProductTags(barcode: string): Promise<_$openapi_fetch0.FetchResponse<{ parameters: { query?: { owner?: string; keys?: string; }; header?: never; path: { product: string; }; cookie?: never; }; requestBody?: never; responses: { 200: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["ProductTag"][]; }; }; 422: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["HTTPValidationError"]; }; }; }; }, { params: { path: { product: string; }; }; }, `${string}/${string}`>>; /** * Add a product tag, returns error if the tag already exists * * @param tag Tag to add or update with the following fields: * - `k`: key * - `v`: value * - `product`: barcode * - `version`: if passed it should be equal to 1 * - `owner`: user_id of the owner of the tag (empty for public tags) * * @returns if the tag was added or updated * @example * const err = await folksonomy.addTag({ k: "vegan", v: "yes", product: "1234567890123", version: 1 }); * if (err) console.error("Error adding tag:", err); */ addTag(tag: FolksonomyTag): Promise<{ detail?: { loc: (string | number)[]; msg: string; type: string; }[] | undefined; } | undefined>; /** * Delete a product tag * * @param tag Tag to delete with the following fields: * - `k`: key * - `v`: value * - `product`: barcode * - `version`: version of the tag [required] * - `owner`: user_id of the owner of the tag (empty for public tags) * * @returns if the tag was deleted */ removeTag(tag: FolksonomyTag & { version: number; }): Promise<{ detail?: { loc: (string | number)[]; msg: string; type: string; }[] | undefined; } | undefined>; /** * Authentication: provide user/password and get a bearer token in return * * @param username Open Food Facts user_id (not email) * @param password user password * @returns the bearer token, to be used in later requests with usual "Authorization: bearer token" headers */ login(username: string, password: string): Promise<_$openapi_fetch0.FetchResponse<{ parameters: { query?: never; header?: never; path?: never; cookie?: never; }; requestBody: { content: { "application/x-www-form-urlencoded": components["schemas"]["Body_authentication_auth_post"]; }; }; responses: { 200: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["TokenResponse"]; }; }; 422: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["HTTPValidationError"]; }; }; }; }, { body: { username: string; password: string; scope: string; }; headers: { "Content-Type": string; }; }, `${string}/${string}`>>; getValues(key: string, opts?: operations["get_unique_values_values__k__get"]["parameters"]["query"]): Promise<_$openapi_fetch0.FetchResponse<{ parameters: { query?: { owner?: string; q?: string; limit?: number; }; header?: never; path: { k: string; }; cookie?: never; }; requestBody?: never; responses: { 200: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["ValueCount"][]; }; }; 422: { headers: { [name: string]: unknown; }; content: { "application/json": components["schemas"]["HTTPValidationError"]; }; }; }; }, { params: { path: { k: string; }; query: { owner?: string; q?: string; limit?: number; } | undefined; }; }, `${string}/${string}`>>; } //#endregion export { Folksonomy, FolksonomyKey, FolksonomyTag }; //# sourceMappingURL=folksonomy.d.ts.map