batteryincluded 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +35 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -109,11 +109,11 @@ Published under the [MIT License](https://github.com/freb97/autodisco/tree/main/
|
|
|
109
109
|
[github-actions-src]: https://github.com/freb97/batteryincluded-ts/actions/workflows/test.yml/badge.svg
|
|
110
110
|
[github-actions-href]: https://github.com/freb97/batteryincluded-ts/actions
|
|
111
111
|
|
|
112
|
-
[npm-version-src]: https://img.shields.io/npm/v/batteryincluded
|
|
113
|
-
[npm-version-href]: https://npmjs.com/package/batteryincluded
|
|
112
|
+
[npm-version-src]: https://img.shields.io/npm/v/batteryincluded/latest.svg?style=flat&colorA=18181B&colorB=31C553
|
|
113
|
+
[npm-version-href]: https://npmjs.com/package/batteryincluded
|
|
114
114
|
|
|
115
|
-
[npm-last-update-src]: https://img.shields.io/npm/last-update/batteryincluded
|
|
116
|
-
[npm-last-update-href]: https://npmjs.com/package/batteryincluded
|
|
115
|
+
[npm-last-update-src]: https://img.shields.io/npm/last-update/batteryincluded.svg?style=flat&colorA=18181B&colorB=31C553
|
|
116
|
+
[npm-last-update-href]: https://npmjs.com/package/batteryincluded
|
|
117
117
|
|
|
118
118
|
[license-src]: https://img.shields.io/github/license/freb97/batteryincluded-ts.svg?style=flat&colorA=18181B&colorB=31C553
|
|
119
119
|
[license-href]: https://github.com/freb97/batteryincluded-ts/tree/main/LICENSE
|
package/dist/index.d.mts
CHANGED
|
@@ -27,4 +27,6 @@ declare function createClient<customPaths extends object = paths>(config: {
|
|
|
27
27
|
apiKey: string;
|
|
28
28
|
}): import("openapi-fetch").Client<customPaths, `${string}/${string}`>;
|
|
29
29
|
declare function defineCodegenConfig(config: Record<string, ProbeConfig | ProbeConfig[]>): Record<string, ProbeConfig | ProbeConfig[]>;
|
|
30
|
-
|
|
30
|
+
declare function queryToFilters(query: URLSearchParams, labelMap?: Record<string, string>): Filter[];
|
|
31
|
+
declare function filtersToQuery(filters: Filter[], labelMap?: Record<string, string>): URLSearchParams;
|
|
32
|
+
export { type Browse, type Filter, type Highlights, type RangeFacet, type Recommendations, type SelectFacet, type Suggest, buildBaseUrl, buildHeaders, type components, createClient, defineCodegenConfig, filtersToQuery, type paths, queryToFilters };
|
package/dist/index.mjs
CHANGED
|
@@ -2,4 +2,38 @@ import { buildBaseUrl, buildHeaders, createClient } from "./_chunks/client.mjs";
|
|
|
2
2
|
function defineCodegenConfig(config) {
|
|
3
3
|
return config;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function fieldToLabel(field, labelMap) {
|
|
6
|
+
return labelMap[field] ?? field;
|
|
7
|
+
}
|
|
8
|
+
function labelToField(label, labelMap) {
|
|
9
|
+
const entry = Object.entries(labelMap).find(([, value]) => value === label);
|
|
10
|
+
return entry ? entry[0] : label;
|
|
11
|
+
}
|
|
12
|
+
function queryToFilters(query, labelMap = {}) {
|
|
13
|
+
const filters = [];
|
|
14
|
+
try {
|
|
15
|
+
const filtersJson = query.get("filters");
|
|
16
|
+
if (filtersJson) {
|
|
17
|
+
const filtersObj = JSON.parse(filtersJson);
|
|
18
|
+
Object.entries(filtersObj).forEach(([field, values]) => {
|
|
19
|
+
filters.push({
|
|
20
|
+
field: fieldToLabel(field, labelMap),
|
|
21
|
+
values
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error("Failed to parse filters from query:", error);
|
|
27
|
+
}
|
|
28
|
+
return filters;
|
|
29
|
+
}
|
|
30
|
+
function filtersToQuery(filters, labelMap = {}) {
|
|
31
|
+
const query = new URLSearchParams();
|
|
32
|
+
const filtersObj = {};
|
|
33
|
+
filters.forEach(({ field, values }) => {
|
|
34
|
+
filtersObj[labelToField(field, labelMap)] = values;
|
|
35
|
+
});
|
|
36
|
+
if (Object.keys(filtersObj).length > 0) query.set("filters", JSON.stringify(filtersObj));
|
|
37
|
+
return query;
|
|
38
|
+
}
|
|
39
|
+
export { buildBaseUrl, buildHeaders, createClient, defineCodegenConfig, filtersToQuery, queryToFilters };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "batteryincluded",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "A TypeScript client for the BatteryIncluded API",
|
|
6
6
|
"author": "Frederik Bußmann <frederik@bussmann.io>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"repository": "freb97/batteryincluded",
|
|
8
|
+
"repository": "freb97/batteryincluded-ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/index.mjs"
|
|
11
11
|
},
|