@cords/sdk 0.0.4 → 0.0.5
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 +11 -10
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +14 -11
- package/dist/index.mjs +14 -11
- package/package.json +1 -1
- package/src/index.ts +19 -11
- package/src/types.ts +7 -1
package/README.md
CHANGED
|
@@ -27,17 +27,18 @@ const cords = CordsAPI({ apiKey: "your_api_key_here" });
|
|
|
27
27
|
To perform a search, use the `search` method. You can pass a query string and optional search options:
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
const
|
|
31
|
-
page: 1,
|
|
30
|
+
const searchResults = await cords.search("query", {
|
|
32
31
|
lat: 40.7128,
|
|
33
32
|
lng: -74.006,
|
|
34
|
-
|
|
35
|
-
pageSize:
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
page: 1,
|
|
34
|
+
pageSize: 10,
|
|
35
|
+
distance: 100,
|
|
36
|
+
partner: {
|
|
37
|
+
"211": true,
|
|
38
38
|
mentor: true,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
},
|
|
40
|
+
delivery: {
|
|
41
|
+
local: true,
|
|
41
42
|
},
|
|
42
43
|
});
|
|
43
44
|
```
|
|
@@ -73,5 +74,5 @@ The SDK also includes a utility function to format service addresses:
|
|
|
73
74
|
```ts
|
|
74
75
|
import { formatServiceAddress } from "@cords/sdk";
|
|
75
76
|
|
|
76
|
-
const formattedAddress = formatServiceAddress(resource.data.address)
|
|
77
|
-
```
|
|
77
|
+
const formattedAddress = formatServiceAddress(resource.data.address);
|
|
78
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -60,12 +60,18 @@ type SearchOptions = {
|
|
|
60
60
|
page?: number;
|
|
61
61
|
distance?: number;
|
|
62
62
|
pageSize?: number;
|
|
63
|
-
|
|
63
|
+
partner?: {
|
|
64
64
|
"211"?: boolean;
|
|
65
65
|
mentor?: boolean;
|
|
66
66
|
prosper?: boolean;
|
|
67
67
|
magnet?: boolean;
|
|
68
68
|
};
|
|
69
|
+
delivery?: {
|
|
70
|
+
local?: boolean;
|
|
71
|
+
regional?: boolean;
|
|
72
|
+
provincial?: boolean;
|
|
73
|
+
national?: boolean;
|
|
74
|
+
};
|
|
69
75
|
};
|
|
70
76
|
type CordsError = {
|
|
71
77
|
detail: string;
|
|
@@ -79,7 +85,7 @@ declare const CordsAPI: ({ apiKey, version, }: {
|
|
|
79
85
|
apiKey: string;
|
|
80
86
|
version?: "production" | "dev";
|
|
81
87
|
}) => {
|
|
82
|
-
search: (q: string, options
|
|
88
|
+
search: (q: string, options: SearchOptions) => Promise<{
|
|
83
89
|
data: SearchResourceType[];
|
|
84
90
|
meta: {
|
|
85
91
|
total: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -60,12 +60,18 @@ type SearchOptions = {
|
|
|
60
60
|
page?: number;
|
|
61
61
|
distance?: number;
|
|
62
62
|
pageSize?: number;
|
|
63
|
-
|
|
63
|
+
partner?: {
|
|
64
64
|
"211"?: boolean;
|
|
65
65
|
mentor?: boolean;
|
|
66
66
|
prosper?: boolean;
|
|
67
67
|
magnet?: boolean;
|
|
68
68
|
};
|
|
69
|
+
delivery?: {
|
|
70
|
+
local?: boolean;
|
|
71
|
+
regional?: boolean;
|
|
72
|
+
provincial?: boolean;
|
|
73
|
+
national?: boolean;
|
|
74
|
+
};
|
|
69
75
|
};
|
|
70
76
|
type CordsError = {
|
|
71
77
|
detail: string;
|
|
@@ -79,7 +85,7 @@ declare const CordsAPI: ({ apiKey, version, }: {
|
|
|
79
85
|
apiKey: string;
|
|
80
86
|
version?: "production" | "dev";
|
|
81
87
|
}) => {
|
|
82
|
-
search: (q: string, options
|
|
88
|
+
search: (q: string, options: SearchOptions) => Promise<{
|
|
83
89
|
data: SearchResourceType[];
|
|
84
90
|
meta: {
|
|
85
91
|
total: number;
|
package/dist/index.js
CHANGED
|
@@ -90,18 +90,22 @@ var CordsAPI = ({
|
|
|
90
90
|
const params = new URLSearchParams({
|
|
91
91
|
q
|
|
92
92
|
});
|
|
93
|
-
|
|
93
|
+
params.append("lat", options.lat.toString());
|
|
94
|
+
params.append("lng", options.lng.toString());
|
|
95
|
+
if (options.page)
|
|
94
96
|
params.append("page", options.page.toString());
|
|
95
|
-
if (
|
|
96
|
-
params.append("
|
|
97
|
-
if (
|
|
98
|
-
params.append("lng", options.lng.toString());
|
|
99
|
-
if ((options == null ? void 0 : options.distance) !== void 0)
|
|
97
|
+
if (options.pageSize)
|
|
98
|
+
params.append("pageSize", options.pageSize.toString());
|
|
99
|
+
if (options.distance)
|
|
100
100
|
params.append("distance", options.distance.toString());
|
|
101
|
-
if (
|
|
102
|
-
for (const [key, value] of Object.entries(options.
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
if (options.partner) {
|
|
102
|
+
for (const [key, value] of Object.entries(options.partner)) {
|
|
103
|
+
params.append(`filter[${key}]`, value ? "true" : "false");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (options.delivery) {
|
|
107
|
+
for (const [key, value] of Object.entries(options.delivery)) {
|
|
108
|
+
params.append(`filter[delivery][${key}]`, value ? "true" : "false");
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
const res = yield request(`${url.toString()}?${params}`);
|
|
@@ -152,7 +156,6 @@ var CordsAPI = ({
|
|
|
152
156
|
throw new Error(data2.detail);
|
|
153
157
|
}
|
|
154
158
|
const data = yield res.json();
|
|
155
|
-
console.log(data);
|
|
156
159
|
return data;
|
|
157
160
|
});
|
|
158
161
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -67,18 +67,22 @@ var CordsAPI = ({
|
|
|
67
67
|
const params = new URLSearchParams({
|
|
68
68
|
q
|
|
69
69
|
});
|
|
70
|
-
|
|
70
|
+
params.append("lat", options.lat.toString());
|
|
71
|
+
params.append("lng", options.lng.toString());
|
|
72
|
+
if (options.page)
|
|
71
73
|
params.append("page", options.page.toString());
|
|
72
|
-
if (
|
|
73
|
-
params.append("
|
|
74
|
-
if (
|
|
75
|
-
params.append("lng", options.lng.toString());
|
|
76
|
-
if ((options == null ? void 0 : options.distance) !== void 0)
|
|
74
|
+
if (options.pageSize)
|
|
75
|
+
params.append("pageSize", options.pageSize.toString());
|
|
76
|
+
if (options.distance)
|
|
77
77
|
params.append("distance", options.distance.toString());
|
|
78
|
-
if (
|
|
79
|
-
for (const [key, value] of Object.entries(options.
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
if (options.partner) {
|
|
79
|
+
for (const [key, value] of Object.entries(options.partner)) {
|
|
80
|
+
params.append(`filter[${key}]`, value ? "true" : "false");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (options.delivery) {
|
|
84
|
+
for (const [key, value] of Object.entries(options.delivery)) {
|
|
85
|
+
params.append(`filter[delivery][${key}]`, value ? "true" : "false");
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
const res = yield request(`${url.toString()}?${params}`);
|
|
@@ -129,7 +133,6 @@ var CordsAPI = ({
|
|
|
129
133
|
throw new Error(data2.detail);
|
|
130
134
|
}
|
|
131
135
|
const data = yield res.json();
|
|
132
|
-
console.log(data);
|
|
133
136
|
return data;
|
|
134
137
|
});
|
|
135
138
|
return {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -36,22 +36,31 @@ export const CordsAPI = ({
|
|
|
36
36
|
return res;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const search = async (q: string, options
|
|
39
|
+
const search = async (q: string, options: SearchOptions) => {
|
|
40
40
|
const url = new URL("/search", baseUrl);
|
|
41
41
|
const params = new URLSearchParams({
|
|
42
42
|
q,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
params.append("lat", options.lat.toString());
|
|
46
|
+
params.append("lng", options.lng.toString());
|
|
47
|
+
|
|
45
48
|
// Add top-level parameters
|
|
46
|
-
if (options
|
|
47
|
-
if (options
|
|
48
|
-
if (options
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
if (options.page) params.append("page", options.page.toString());
|
|
50
|
+
if (options.pageSize) params.append("pageSize", options.pageSize.toString());
|
|
51
|
+
if (options.distance) params.append("distance", options.distance.toString());
|
|
52
|
+
|
|
53
|
+
// Add partner parameters
|
|
54
|
+
if (options.partner) {
|
|
55
|
+
for (const [key, value] of Object.entries(options.partner)) {
|
|
56
|
+
params.append(`filter[${key}]`, value ? "true" : "false");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Add delivery parameters
|
|
61
|
+
if (options.delivery) {
|
|
62
|
+
for (const [key, value] of Object.entries(options.delivery)) {
|
|
63
|
+
params.append(`filter[delivery][${key}]`, value ? "true" : "false");
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -122,7 +131,6 @@ export const CordsAPI = ({
|
|
|
122
131
|
throw new Error(data.detail);
|
|
123
132
|
}
|
|
124
133
|
const data = await res.json();
|
|
125
|
-
console.log(data);
|
|
126
134
|
return data as { data: ResourceType[] };
|
|
127
135
|
};
|
|
128
136
|
|
package/src/types.ts
CHANGED
|
@@ -68,12 +68,18 @@ export type SearchOptions = {
|
|
|
68
68
|
page?: number;
|
|
69
69
|
distance?: number;
|
|
70
70
|
pageSize?: number;
|
|
71
|
-
|
|
71
|
+
partner?: {
|
|
72
72
|
"211"?: boolean;
|
|
73
73
|
mentor?: boolean;
|
|
74
74
|
prosper?: boolean;
|
|
75
75
|
magnet?: boolean;
|
|
76
76
|
};
|
|
77
|
+
delivery?: {
|
|
78
|
+
local?: boolean;
|
|
79
|
+
regional?: boolean;
|
|
80
|
+
provincial?: boolean;
|
|
81
|
+
national?: boolean;
|
|
82
|
+
};
|
|
77
83
|
};
|
|
78
84
|
|
|
79
85
|
export type CordsError = {
|