diff --git a/example/test.ts b/example/test.ts new file mode 100644 index 0000000..d2ca796 --- /dev/null +++ b/example/test.ts @@ -0,0 +1,16 @@ +import {MangroveReviews} from "../lib"; + +async function example() : Promise{ + + const subReviews = await MangroveReviews.getReviews({ + sub: "geo:51.4954589,11.9659188", + q: "verwöner", + u: 30, + issuers: true, + maresi_subjects: true + }); + + console.log(subReviews.reviews); +} + +example() \ No newline at end of file diff --git a/lib/Mangrove-reviews.ts b/lib/Mangrove-reviews.ts index 2e22e80..beb10ca 100644 --- a/lib/Mangrove-reviews.ts +++ b/lib/Mangrove-reviews.ts @@ -59,6 +59,12 @@ export interface QueryParameters { */ maresi_subjects?: boolean + /** + * Only used for 'geo:'-queries + * uncertainty in meters + */ + u?: number + } export class MangroveReviews { @@ -80,7 +86,7 @@ export class MangroveReviews { .setProtectedHeader({ alg: algo, kid, - jwk: jwk, + jwk: jwk, enc: "utf-8" }) .sign(keypair.privateKey); @@ -127,6 +133,21 @@ export class MangroveReviews { maresi_subjects?: any[], issuers?: any[] }> { + if (query.sub?.startsWith("geo:")) { + const parts = [] + if (query.q) { + parts.push("q=" + encodeURIComponent(query.q)) + delete query.q + } + if (query.u) { + parts.push("u=" + query.u) + delete query.u + } + if (parts.length > 0) { + query.sub = query.sub + "?" + parts.join("&") + } + + } const {data} = await axios.get(`${api}/reviews`, { params: query, headers: {'Content-Type': 'application/json'} diff --git a/package.json b/package.json index c171226..34e41f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mangrove-reviews-typescript", - "version": "1.1.0", + "version": "1.3.0", "description": "A library to interface with Mangrove.reviews", "main": "dist/index.js", "types": "dist/index.d.ts",