@cords/sdk 0.0.4 → 0.0.6
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 +10 -9
- package/dist/index.d.mts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +16 -19
- package/dist/index.mjs +16 -19
- package/package.json +1 -1
- package/src/index.ts +19 -11
- package/src/types.ts +14 -2
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,
|
|
33
|
+
page: 1,
|
|
34
|
+
pageSize: 10,
|
|
34
35
|
distance: 10,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
211: true,
|
|
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
|
@@ -53,18 +53,30 @@ type ResourceType = {
|
|
|
53
53
|
vectorDistance: number;
|
|
54
54
|
} | null;
|
|
55
55
|
};
|
|
56
|
-
type SearchResourceType = Omit<ResourceType, "website" | "email" | "phoneNumbers" | "addresses" | "address"
|
|
56
|
+
type SearchResourceType = Omit<ResourceType, "website" | "email" | "phoneNumbers" | "addresses" | "address"> & {
|
|
57
|
+
location: {
|
|
58
|
+
lat: number | null;
|
|
59
|
+
lng: number | null;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
57
62
|
type SearchOptions = {
|
|
58
63
|
lat: number;
|
|
59
64
|
lng: number;
|
|
60
65
|
page?: number;
|
|
61
66
|
distance?: number;
|
|
62
67
|
pageSize?: number;
|
|
63
|
-
|
|
68
|
+
partner?: {
|
|
64
69
|
"211"?: boolean;
|
|
65
70
|
mentor?: boolean;
|
|
66
71
|
prosper?: boolean;
|
|
67
72
|
magnet?: boolean;
|
|
73
|
+
volunteer?: boolean;
|
|
74
|
+
};
|
|
75
|
+
delivery?: {
|
|
76
|
+
local?: boolean;
|
|
77
|
+
regional?: boolean;
|
|
78
|
+
provincial?: boolean;
|
|
79
|
+
national?: boolean;
|
|
68
80
|
};
|
|
69
81
|
};
|
|
70
82
|
type CordsError = {
|
|
@@ -79,7 +91,7 @@ declare const CordsAPI: ({ apiKey, version, }: {
|
|
|
79
91
|
apiKey: string;
|
|
80
92
|
version?: "production" | "dev";
|
|
81
93
|
}) => {
|
|
82
|
-
search: (q: string, options
|
|
94
|
+
search: (q: string, options: SearchOptions) => Promise<{
|
|
83
95
|
data: SearchResourceType[];
|
|
84
96
|
meta: {
|
|
85
97
|
total: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -53,18 +53,30 @@ type ResourceType = {
|
|
|
53
53
|
vectorDistance: number;
|
|
54
54
|
} | null;
|
|
55
55
|
};
|
|
56
|
-
type SearchResourceType = Omit<ResourceType, "website" | "email" | "phoneNumbers" | "addresses" | "address"
|
|
56
|
+
type SearchResourceType = Omit<ResourceType, "website" | "email" | "phoneNumbers" | "addresses" | "address"> & {
|
|
57
|
+
location: {
|
|
58
|
+
lat: number | null;
|
|
59
|
+
lng: number | null;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
57
62
|
type SearchOptions = {
|
|
58
63
|
lat: number;
|
|
59
64
|
lng: number;
|
|
60
65
|
page?: number;
|
|
61
66
|
distance?: number;
|
|
62
67
|
pageSize?: number;
|
|
63
|
-
|
|
68
|
+
partner?: {
|
|
64
69
|
"211"?: boolean;
|
|
65
70
|
mentor?: boolean;
|
|
66
71
|
prosper?: boolean;
|
|
67
72
|
magnet?: boolean;
|
|
73
|
+
volunteer?: boolean;
|
|
74
|
+
};
|
|
75
|
+
delivery?: {
|
|
76
|
+
local?: boolean;
|
|
77
|
+
regional?: boolean;
|
|
78
|
+
provincial?: boolean;
|
|
79
|
+
national?: boolean;
|
|
68
80
|
};
|
|
69
81
|
};
|
|
70
82
|
type CordsError = {
|
|
@@ -79,7 +91,7 @@ declare const CordsAPI: ({ apiKey, version, }: {
|
|
|
79
91
|
apiKey: string;
|
|
80
92
|
version?: "production" | "dev";
|
|
81
93
|
}) => {
|
|
82
|
-
search: (q: string, options
|
|
94
|
+
search: (q: string, options: SearchOptions) => Promise<{
|
|
83
95
|
data: SearchResourceType[];
|
|
84
96
|
meta: {
|
|
85
97
|
total: number;
|
package/dist/index.js
CHANGED
|
@@ -78,10 +78,8 @@ var CordsAPI = ({
|
|
|
78
78
|
if (res.status === 403)
|
|
79
79
|
throw new Error("Bad API key. Ensure you have a valid API key.");
|
|
80
80
|
const data = yield res.json();
|
|
81
|
-
if (data.detail)
|
|
82
|
-
|
|
83
|
-
else
|
|
84
|
-
throw new Error("An error occurred");
|
|
81
|
+
if (data.detail) throw new Error(data.detail);
|
|
82
|
+
else throw new Error("An error occurred");
|
|
85
83
|
}
|
|
86
84
|
return res;
|
|
87
85
|
});
|
|
@@ -90,18 +88,19 @@ var CordsAPI = ({
|
|
|
90
88
|
const params = new URLSearchParams({
|
|
91
89
|
q
|
|
92
90
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
params.append("lat", options.lat.toString());
|
|
92
|
+
params.append("lng", options.lng.toString());
|
|
93
|
+
if (options.page) params.append("page", options.page.toString());
|
|
94
|
+
if (options.pageSize) params.append("pageSize", options.pageSize.toString());
|
|
95
|
+
if (options.distance) params.append("distance", options.distance.toString());
|
|
96
|
+
if (options.partner) {
|
|
97
|
+
for (const [key, value] of Object.entries(options.partner)) {
|
|
98
|
+
params.append(`filter[${key}]`, value ? "true" : "false");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (options.delivery) {
|
|
102
|
+
for (const [key, value] of Object.entries(options.delivery)) {
|
|
103
|
+
params.append(`filter[delivery][${key}]`, value ? "true" : "false");
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
const res = yield request(`${url.toString()}?${params}`);
|
|
@@ -152,7 +151,6 @@ var CordsAPI = ({
|
|
|
152
151
|
throw new Error(data2.detail);
|
|
153
152
|
}
|
|
154
153
|
const data = yield res.json();
|
|
155
|
-
console.log(data);
|
|
156
154
|
return data;
|
|
157
155
|
});
|
|
158
156
|
return {
|
|
@@ -172,8 +170,7 @@ var formatServiceAddress = (address) => {
|
|
|
172
170
|
const newAddress = street1 + street2 + city + province + postalCode;
|
|
173
171
|
if (newAddress.endsWith(", ")) {
|
|
174
172
|
return newAddress.slice(0, -2);
|
|
175
|
-
} else
|
|
176
|
-
return newAddress;
|
|
173
|
+
} else return newAddress;
|
|
177
174
|
};
|
|
178
175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
179
176
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -55,10 +55,8 @@ var CordsAPI = ({
|
|
|
55
55
|
if (res.status === 403)
|
|
56
56
|
throw new Error("Bad API key. Ensure you have a valid API key.");
|
|
57
57
|
const data = yield res.json();
|
|
58
|
-
if (data.detail)
|
|
59
|
-
|
|
60
|
-
else
|
|
61
|
-
throw new Error("An error occurred");
|
|
58
|
+
if (data.detail) throw new Error(data.detail);
|
|
59
|
+
else throw new Error("An error occurred");
|
|
62
60
|
}
|
|
63
61
|
return res;
|
|
64
62
|
});
|
|
@@ -67,18 +65,19 @@ var CordsAPI = ({
|
|
|
67
65
|
const params = new URLSearchParams({
|
|
68
66
|
q
|
|
69
67
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
params.append("lat", options.lat.toString());
|
|
69
|
+
params.append("lng", options.lng.toString());
|
|
70
|
+
if (options.page) params.append("page", options.page.toString());
|
|
71
|
+
if (options.pageSize) params.append("pageSize", options.pageSize.toString());
|
|
72
|
+
if (options.distance) params.append("distance", options.distance.toString());
|
|
73
|
+
if (options.partner) {
|
|
74
|
+
for (const [key, value] of Object.entries(options.partner)) {
|
|
75
|
+
params.append(`filter[${key}]`, value ? "true" : "false");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (options.delivery) {
|
|
79
|
+
for (const [key, value] of Object.entries(options.delivery)) {
|
|
80
|
+
params.append(`filter[delivery][${key}]`, value ? "true" : "false");
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
const res = yield request(`${url.toString()}?${params}`);
|
|
@@ -129,7 +128,6 @@ var CordsAPI = ({
|
|
|
129
128
|
throw new Error(data2.detail);
|
|
130
129
|
}
|
|
131
130
|
const data = yield res.json();
|
|
132
|
-
console.log(data);
|
|
133
131
|
return data;
|
|
134
132
|
});
|
|
135
133
|
return {
|
|
@@ -149,8 +147,7 @@ var formatServiceAddress = (address) => {
|
|
|
149
147
|
const newAddress = street1 + street2 + city + province + postalCode;
|
|
150
148
|
if (newAddress.endsWith(", ")) {
|
|
151
149
|
return newAddress.slice(0, -2);
|
|
152
|
-
} else
|
|
153
|
-
return newAddress;
|
|
150
|
+
} else return newAddress;
|
|
154
151
|
};
|
|
155
152
|
export {
|
|
156
153
|
CordsAPI,
|
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
|
@@ -60,7 +60,12 @@ export type ResourceType = {
|
|
|
60
60
|
export type SearchResourceType = Omit<
|
|
61
61
|
ResourceType,
|
|
62
62
|
"website" | "email" | "phoneNumbers" | "addresses" | "address"
|
|
63
|
-
|
|
63
|
+
> & {
|
|
64
|
+
location: {
|
|
65
|
+
lat: number | null;
|
|
66
|
+
lng: number | null;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
64
69
|
|
|
65
70
|
export type SearchOptions = {
|
|
66
71
|
lat: number;
|
|
@@ -68,11 +73,18 @@ export type SearchOptions = {
|
|
|
68
73
|
page?: number;
|
|
69
74
|
distance?: number;
|
|
70
75
|
pageSize?: number;
|
|
71
|
-
|
|
76
|
+
partner?: {
|
|
72
77
|
"211"?: boolean;
|
|
73
78
|
mentor?: boolean;
|
|
74
79
|
prosper?: boolean;
|
|
75
80
|
magnet?: boolean;
|
|
81
|
+
volunteer?: boolean;
|
|
82
|
+
};
|
|
83
|
+
delivery?: {
|
|
84
|
+
local?: boolean;
|
|
85
|
+
regional?: boolean;
|
|
86
|
+
provincial?: boolean;
|
|
87
|
+
national?: boolean;
|
|
76
88
|
};
|
|
77
89
|
};
|
|
78
90
|
|