@cords/sdk 0.0.9 → 0.0.10

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +16 -12
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./dist/index.js",
4
4
  "module": "./dist/index.mjs",
5
5
  "types": "./dist/index.d.ts",
6
- "version": "0.0.9",
6
+ "version": "0.0.10",
7
7
  "private": false,
8
8
  "publishConfig": {
9
9
  "access": "public"
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ export const CordsAPI = ({
13
13
  apiKey,
14
14
  version = "production",
15
15
  referer,
16
- baseUrl,
16
+ baseUrl: customBaseUrl,
17
17
  }: {
18
18
  apiKey: string;
19
19
  version?: "production" | "dev";
@@ -21,13 +21,11 @@ export const CordsAPI = ({
21
21
  baseUrl?: string;
22
22
  }) => {
23
23
  // Set the base URL for the Cords API
24
- baseUrl =
25
- baseUrl ??
26
- (version === "production"
24
+ const baseUrl = customBaseUrl
25
+ ? customBaseUrl?.replace(/\/$/, "")
26
+ : version === "production"
27
27
  ? "https://api.cords.ai"
28
- : "https://api.cords.dev");
29
-
30
- baseUrl = baseUrl.replace(/\/$/, "");
28
+ : "https://api.cords.dev";
31
29
 
32
30
  // Helper for making requests to the Cords API that applies the api key, referrer, and handles errors
33
31
  const request = async (input: RequestInfo, init?: RequestInit) => {
@@ -60,7 +58,8 @@ export const CordsAPI = ({
60
58
  ...options
61
59
  }: SearchOptions,
62
60
  ) => {
63
- const url = new URL(`${baseUrl}/search`);
61
+ const url = new URL(baseUrl);
62
+ url.pathname += "/search";
64
63
  const params = new URLSearchParams({
65
64
  q,
66
65
  });
@@ -112,7 +111,8 @@ export const CordsAPI = ({
112
111
 
113
112
  // Get related to a resource
114
113
  const related = async (id: string) => {
115
- const url = new URL(`${baseUrl}/resource/${id}/related`);
114
+ const url = new URL(baseUrl);
115
+ url.pathname += `/resource/${id}/related`;
116
116
 
117
117
  const res = await request(url.toString());
118
118
  if (!res.ok) {
@@ -125,7 +125,8 @@ export const CordsAPI = ({
125
125
 
126
126
  // Get a single resource by id
127
127
  const resource = async (id: string) => {
128
- const url = new URL(`${baseUrl}/resource/${id}`);
128
+ const url = new URL(baseUrl);
129
+ url.pathname += `/resource/${id}`;
129
130
 
130
131
  const res = await request(url.toString());
131
132
  if (!res.ok) {
@@ -147,7 +148,9 @@ export const CordsAPI = ({
147
148
  const params = new URLSearchParams();
148
149
  ids.forEach((id, index) => params.append(`ids[${index}]`, id));
149
150
 
150
- const url = new URL(`${baseUrl}/search?${params.toString()}`);
151
+ const url = new URL(baseUrl);
152
+ url.pathname += "/resource/list";
153
+ url.search = params.toString();
151
154
 
152
155
  const res = await request(url.toString());
153
156
  const data = await res.json();
@@ -162,7 +165,8 @@ export const CordsAPI = ({
162
165
  lng: number;
163
166
  },
164
167
  ) => {
165
- const url = new URL(`${baseUrl}/resource/${id}/nearest-neighbor`);
168
+ const url = new URL(baseUrl);
169
+ url.pathname += `/resource/${id}/nearest-neighbor`;
166
170
 
167
171
  const params = new URLSearchParams({
168
172
  lat: options.lat.toString(),