blocket.js 1.0.10 → 1.1.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 +17 -6
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +9 -4
- package/dist/client/index.js.map +1 -1
- package/dist/types/config.d.ts +2 -2
- package/dist/types/index.d.ts +7 -1
- package/lib/client/index.ts +20 -10
- package/lib/types/config.ts +2 -2
- package/lib/types/index.ts +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,25 +97,36 @@ import client from 'blocket.js';
|
|
|
97
97
|
|
|
98
98
|
## API Reference
|
|
99
99
|
|
|
100
|
-
`client.find(query:
|
|
100
|
+
`client.find(query: BlocketQueryConfig, fetchOptions?: FetchOptions<'json', any>): Promise<BlocketAd[]>`
|
|
101
101
|
|
|
102
102
|
Searches for ads on Blocket based on the provided query parameters.
|
|
103
103
|
|
|
104
104
|
- Parameters:
|
|
105
|
-
- `query`: An object conforming to the `
|
|
105
|
+
- `query`: An object conforming to the `BlocketQueryConfig` interface:
|
|
106
106
|
- `query` (string): The search query (e.g., `'macbook air'`).
|
|
107
|
-
- `limit` (number, optional): Maximum number of results to return (default:
|
|
107
|
+
- `limit` (number, optional): Maximum number of results to return (default: 20).
|
|
108
108
|
- `sort` (string, optional): Sorting order (default: `'rel'`).
|
|
109
109
|
- `listingType` (string, optional): Listing type; `'s'` for selling, `'b'` for buying (default: `'s'`).
|
|
110
110
|
- `status` (string, optional): Ad status (`'active'` or `'inactive'`, default: `'active'`).
|
|
111
|
-
- `
|
|
112
|
-
- `include` (string, optional): Additional filters or fields to include (e.g., '
|
|
111
|
+
- `geolocation` (number, optional): Maximum distance in kilometers.
|
|
112
|
+
- `include` (string, optional): Additional filters or fields to include (e.g., 'extend_with_shipping').
|
|
113
113
|
- `fetchOptions` (optional): Additional options to pass to the underlying fetch request.
|
|
114
114
|
- Returns: A promise that resolves to an array of `BlocketAd` objects.
|
|
115
115
|
|
|
116
|
+
`client.findById(adId: string, fetchOptions?: FetchOptions<'json', any>): Promise<BlocketAd>`
|
|
117
|
+
|
|
118
|
+
Retrieves a specific ad by its ID.
|
|
119
|
+
|
|
120
|
+
- Parameters:
|
|
121
|
+
- `adId`: The ID of the ad to retrieve.
|
|
122
|
+
- `fetchOptions` (optional): Additional options to pass to the underlying fetch request.
|
|
123
|
+
- Returns: A promise that resolves to a `BlocketAd` object or null if not found.
|
|
124
|
+
|
|
116
125
|
## License
|
|
117
126
|
|
|
118
|
-
This project is licensed under
|
|
127
|
+
This project is licensed under the [MIT License](https://github.com/rutbergphilip/blocket.js/blob/main/LICENSE) – free for personal and commercial use.
|
|
128
|
+
|
|
129
|
+
If you find this project useful, crediting the author is greatly appreciated!
|
|
119
130
|
|
|
120
131
|
## Star History
|
|
121
132
|
|
package/dist/client/index.d.ts
CHANGED
|
@@ -7,3 +7,10 @@ import type { BlocketAd, BlocketQueryConfig } from '../types';
|
|
|
7
7
|
* @returns Array of Blocket ads.
|
|
8
8
|
*/
|
|
9
9
|
export declare function find(query: BlocketQueryConfig, fetchOptions?: FetchOptions<'json', any>): Promise<BlocketAd[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Get details of a specific ad by its ID.
|
|
12
|
+
* @param adId Advertisement ID.
|
|
13
|
+
* @param fetchOptions Additional fetch options.
|
|
14
|
+
* @returns {Promise<BlocketAd | null>} Blocket ad details or null if not found.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findById(adId: string, fetchOptions?: FetchOptions<'json', any>): Promise<BlocketAd | null>;
|
package/dist/client/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.find = find;
|
|
13
|
+
exports.findById = findById;
|
|
13
14
|
const request_1 = require("./request");
|
|
14
15
|
const config_1 = require("../config");
|
|
15
16
|
/**
|
|
@@ -61,13 +62,17 @@ function find(query, fetchOptions) {
|
|
|
61
62
|
* Get details of a specific ad by its ID.
|
|
62
63
|
* @param adId Advertisement ID.
|
|
63
64
|
* @param fetchOptions Additional fetch options.
|
|
64
|
-
* @returns Blocket ad details.
|
|
65
|
+
* @returns {Promise<BlocketAd | null>} Blocket ad details or null if not found.
|
|
65
66
|
*/
|
|
66
|
-
function
|
|
67
|
+
function findById(adId, fetchOptions) {
|
|
67
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
69
|
const config = (0, config_1.getBaseConfig)();
|
|
69
|
-
const url = `${config.apiBaseUrl}
|
|
70
|
-
|
|
70
|
+
const url = `${config.apiBaseUrl}/${adId}`;
|
|
71
|
+
const ad = yield (0, request_1.apiRequest)(url, fetchOptions);
|
|
72
|
+
if (!ad || !(ad === null || ad === void 0 ? void 0 : ad.data)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return ad.data;
|
|
71
76
|
});
|
|
72
77
|
}
|
|
73
78
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAqDA,oBAwBC;AAQD,4BAcC;AAnGD,uCAAuC;AACvC,sCAA6D;AAW7D;;;;GAIG;AACH,SAAS,gBAAgB,CACvB,MAA0B;IAE1B,MAAM,OAAO,GAGT;QACF,KAAK,EAAE,GAAG;QACV,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,IAAI;QACjB,MAAM,EAAE,QAAQ;QAChB,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,SAAS;KACnB,CAAC;IAEF,MAAM,QAAQ,GAAsC,EAAE,CAAC;IAEvD,KAAK,MAAM,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AAE,GAAG,MAAM,IAAA,oBAAU,EAAoB,GAAG,EAAE,YAAY,CAAC,CAAC;QAElE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,IAAI,CAAA,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,EAAE,CAAC,IAAI,CAAC;IACjB,CAAC;CAAA"}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export interface BlocketQueryConfig {
|
|
|
53
53
|
* The status of the ad. `active`, `inactive`, or `all`.
|
|
54
54
|
* @default 'active'
|
|
55
55
|
*/
|
|
56
|
-
status?: 'active' | '
|
|
56
|
+
status?: 'active' | 'deleted' | 'hidden_by_user';
|
|
57
57
|
/**
|
|
58
58
|
* The maximum distance in kilometers from the search location.
|
|
59
59
|
*/
|
|
@@ -71,7 +71,7 @@ export interface BlocketQueryParamsNative {
|
|
|
71
71
|
lim?: number;
|
|
72
72
|
sort?: 'rel';
|
|
73
73
|
st?: 's' | 'b' | 'a';
|
|
74
|
-
status?: 'active' | '
|
|
74
|
+
status?: 'active' | 'deleted' | 'hidden_by_user';
|
|
75
75
|
gl?: number;
|
|
76
76
|
include?: string;
|
|
77
77
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,9 +10,15 @@ export type BlocketAccessToken = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Blocket API response containing an array of ads.
|
|
12
12
|
*/
|
|
13
|
-
export interface
|
|
13
|
+
export interface BlocketAdSearchResponse {
|
|
14
14
|
data: BlocketAd[];
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Blocket API response containing a single ad.
|
|
18
|
+
*/
|
|
19
|
+
export interface BlocketAdResponse {
|
|
20
|
+
data: BlocketAd;
|
|
21
|
+
}
|
|
16
22
|
/**
|
|
17
23
|
* Blocket advertisement object.
|
|
18
24
|
*/
|
package/lib/client/index.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { FetchOptions } from 'ofetch';
|
|
|
5
5
|
import type {
|
|
6
6
|
BlocketQueryParamsNative,
|
|
7
7
|
BlocketAd,
|
|
8
|
-
|
|
8
|
+
BlocketAdResponse,
|
|
9
|
+
BlocketAdSearchResponse,
|
|
9
10
|
BlocketQueryConfig,
|
|
10
11
|
} from '../types';
|
|
11
12
|
|
|
@@ -59,10 +60,13 @@ export async function find(
|
|
|
59
60
|
const config = getBaseConfig();
|
|
60
61
|
const queryConfig = createQueryConfig(query);
|
|
61
62
|
|
|
62
|
-
const response = await apiRequest<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const response = await apiRequest<BlocketAdSearchResponse>(
|
|
64
|
+
config.apiBaseUrl,
|
|
65
|
+
{
|
|
66
|
+
query: remapQueryParams(queryConfig),
|
|
67
|
+
...fetchOptions,
|
|
68
|
+
}
|
|
69
|
+
);
|
|
66
70
|
|
|
67
71
|
if (!response || !response.data || !Array.isArray(response.data)) {
|
|
68
72
|
throw new Error(
|
|
@@ -77,14 +81,20 @@ export async function find(
|
|
|
77
81
|
* Get details of a specific ad by its ID.
|
|
78
82
|
* @param adId Advertisement ID.
|
|
79
83
|
* @param fetchOptions Additional fetch options.
|
|
80
|
-
* @returns Blocket ad details.
|
|
84
|
+
* @returns {Promise<BlocketAd | null>} Blocket ad details or null if not found.
|
|
81
85
|
*/
|
|
82
|
-
async function
|
|
86
|
+
export async function findById(
|
|
83
87
|
adId: string,
|
|
84
88
|
fetchOptions?: FetchOptions<'json', any>
|
|
85
|
-
): Promise<BlocketAd> {
|
|
89
|
+
): Promise<BlocketAd | null> {
|
|
86
90
|
const config = getBaseConfig();
|
|
87
|
-
const url = `${config.apiBaseUrl}
|
|
91
|
+
const url = `${config.apiBaseUrl}/${adId}`;
|
|
92
|
+
|
|
93
|
+
const ad = await apiRequest<BlocketAdResponse>(url, fetchOptions);
|
|
94
|
+
|
|
95
|
+
if (!ad || !ad?.data) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
88
98
|
|
|
89
|
-
return
|
|
99
|
+
return ad.data;
|
|
90
100
|
}
|
package/lib/types/config.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface BlocketQueryConfig {
|
|
|
54
54
|
* The status of the ad. `active`, `inactive`, or `all`.
|
|
55
55
|
* @default 'active'
|
|
56
56
|
*/
|
|
57
|
-
status?: 'active' | '
|
|
57
|
+
status?: 'active' | 'deleted' | 'hidden_by_user';
|
|
58
58
|
/**
|
|
59
59
|
* The maximum distance in kilometers from the search location.
|
|
60
60
|
*/
|
|
@@ -73,7 +73,7 @@ export interface BlocketQueryParamsNative {
|
|
|
73
73
|
lim?: number;
|
|
74
74
|
sort?: 'rel';
|
|
75
75
|
st?: 's' | 'b' | 'a';
|
|
76
|
-
status?: 'active' | '
|
|
76
|
+
status?: 'active' | 'deleted' | 'hidden_by_user';
|
|
77
77
|
gl?: number;
|
|
78
78
|
include?: string;
|
|
79
79
|
}
|
package/lib/types/index.ts
CHANGED
|
@@ -12,10 +12,17 @@ export type BlocketAccessToken = {
|
|
|
12
12
|
/**
|
|
13
13
|
* Blocket API response containing an array of ads.
|
|
14
14
|
*/
|
|
15
|
-
export interface
|
|
15
|
+
export interface BlocketAdSearchResponse {
|
|
16
16
|
data: BlocketAd[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Blocket API response containing a single ad.
|
|
21
|
+
*/
|
|
22
|
+
export interface BlocketAdResponse {
|
|
23
|
+
data: BlocketAd;
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* Blocket advertisement object.
|
|
21
28
|
*/
|