@cords/sdk 0.0.11 → 0.0.12

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/dist/index.js CHANGED
@@ -62,6 +62,7 @@ var CordsAPI = ({
62
62
  baseUrl: customBaseUrl
63
63
  }) => {
64
64
  const baseUrl = customBaseUrl ? customBaseUrl == null ? void 0 : customBaseUrl.replace(/\/$/, "") : version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
65
+ console.log("test", baseUrl);
65
66
  const request = async (input, init) => {
66
67
  const res = await fetch(input, __spreadProps(__spreadValues({}, init), {
67
68
  headers: __spreadValues(__spreadValues({
@@ -79,6 +80,11 @@ var CordsAPI = ({
79
80
  }
80
81
  return res;
81
82
  };
83
+ const formatUrl = (pathname) => {
84
+ const url = new URL(baseUrl);
85
+ url.pathname = url.pathname.replace(/\/$/, "") + pathname;
86
+ return url;
87
+ };
82
88
  const search = async (q, _a) => {
83
89
  var _b = _a, {
84
90
  calculateCityFromSearchString = true,
@@ -87,8 +93,7 @@ var CordsAPI = ({
87
93
  "calculateCityFromSearchString",
88
94
  "calculateProvinceFromSearchString"
89
95
  ]);
90
- const url = new URL(baseUrl);
91
- url.pathname += "/search";
96
+ const url = formatUrl("/search");
92
97
  const params = new URLSearchParams({
93
98
  q
94
99
  });
@@ -125,8 +130,7 @@ var CordsAPI = ({
125
130
  return data;
126
131
  };
127
132
  const related = async (id) => {
128
- const url = new URL(baseUrl);
129
- url.pathname += `/resource/${id}/related`;
133
+ const url = formatUrl(`/resource/${id}/related`);
130
134
  const res = await request(url.toString());
131
135
  if (!res.ok) {
132
136
  const data2 = await res.json();
@@ -136,8 +140,7 @@ var CordsAPI = ({
136
140
  return data;
137
141
  };
138
142
  const resource = async (id) => {
139
- const url = new URL(baseUrl);
140
- url.pathname += `/resource/${id}`;
143
+ const url = formatUrl(`/resource/${id}`);
141
144
  const res = await request(url.toString());
142
145
  if (!res.ok) {
143
146
  const data2 = await res.json();
@@ -153,16 +156,14 @@ var CordsAPI = ({
153
156
  };
154
157
  const params = new URLSearchParams();
155
158
  ids.forEach((id, index) => params.append(`ids[${index}]`, id));
156
- const url = new URL(baseUrl);
157
- url.pathname += "/resource/list";
159
+ const url = formatUrl("/resource/list");
158
160
  url.search = params.toString();
159
161
  const res = await request(url.toString());
160
162
  const data = await res.json();
161
163
  return data;
162
164
  };
163
165
  const nearestNeighbour = async (id, options) => {
164
- const url = new URL(baseUrl);
165
- url.pathname += `/resource/${id}/nearest-neighbor`;
166
+ const url = formatUrl(`/resource/${id}/nearest-neighbor`);
166
167
  const params = new URLSearchParams({
167
168
  lat: options.lat.toString(),
168
169
  lng: options.lng.toString()
package/dist/index.mjs CHANGED
@@ -39,6 +39,7 @@ var CordsAPI = ({
39
39
  baseUrl: customBaseUrl
40
40
  }) => {
41
41
  const baseUrl = customBaseUrl ? customBaseUrl == null ? void 0 : customBaseUrl.replace(/\/$/, "") : version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
42
+ console.log("test", baseUrl);
42
43
  const request = async (input, init) => {
43
44
  const res = await fetch(input, __spreadProps(__spreadValues({}, init), {
44
45
  headers: __spreadValues(__spreadValues({
@@ -56,6 +57,11 @@ var CordsAPI = ({
56
57
  }
57
58
  return res;
58
59
  };
60
+ const formatUrl = (pathname) => {
61
+ const url = new URL(baseUrl);
62
+ url.pathname = url.pathname.replace(/\/$/, "") + pathname;
63
+ return url;
64
+ };
59
65
  const search = async (q, _a) => {
60
66
  var _b = _a, {
61
67
  calculateCityFromSearchString = true,
@@ -64,8 +70,7 @@ var CordsAPI = ({
64
70
  "calculateCityFromSearchString",
65
71
  "calculateProvinceFromSearchString"
66
72
  ]);
67
- const url = new URL(baseUrl);
68
- url.pathname += "/search";
73
+ const url = formatUrl("/search");
69
74
  const params = new URLSearchParams({
70
75
  q
71
76
  });
@@ -102,8 +107,7 @@ var CordsAPI = ({
102
107
  return data;
103
108
  };
104
109
  const related = async (id) => {
105
- const url = new URL(baseUrl);
106
- url.pathname += `/resource/${id}/related`;
110
+ const url = formatUrl(`/resource/${id}/related`);
107
111
  const res = await request(url.toString());
108
112
  if (!res.ok) {
109
113
  const data2 = await res.json();
@@ -113,8 +117,7 @@ var CordsAPI = ({
113
117
  return data;
114
118
  };
115
119
  const resource = async (id) => {
116
- const url = new URL(baseUrl);
117
- url.pathname += `/resource/${id}`;
120
+ const url = formatUrl(`/resource/${id}`);
118
121
  const res = await request(url.toString());
119
122
  if (!res.ok) {
120
123
  const data2 = await res.json();
@@ -130,16 +133,14 @@ var CordsAPI = ({
130
133
  };
131
134
  const params = new URLSearchParams();
132
135
  ids.forEach((id, index) => params.append(`ids[${index}]`, id));
133
- const url = new URL(baseUrl);
134
- url.pathname += "/resource/list";
136
+ const url = formatUrl("/resource/list");
135
137
  url.search = params.toString();
136
138
  const res = await request(url.toString());
137
139
  const data = await res.json();
138
140
  return data;
139
141
  };
140
142
  const nearestNeighbour = async (id, options) => {
141
- const url = new URL(baseUrl);
142
- url.pathname += `/resource/${id}/nearest-neighbor`;
143
+ const url = formatUrl(`/resource/${id}/nearest-neighbor`);
143
144
  const params = new URLSearchParams({
144
145
  lat: options.lat.toString(),
145
146
  lng: options.lng.toString()
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.11",
6
+ "version": "0.0.12",
7
7
  "private": false,
8
8
  "publishConfig": {
9
9
  "access": "public"
package/src/index.ts CHANGED
@@ -49,6 +49,12 @@ export const CordsAPI = ({
49
49
  return res;
50
50
  };
51
51
 
52
+ const formatUrl = (pathname: string) => {
53
+ const url = new URL(baseUrl);
54
+ url.pathname = url.pathname.replace(/\/$/, "") + pathname;
55
+ return url;
56
+ };
57
+
52
58
  // Search for resources
53
59
  const search = async (
54
60
  q: string,
@@ -58,8 +64,7 @@ export const CordsAPI = ({
58
64
  ...options
59
65
  }: SearchOptions,
60
66
  ) => {
61
- const url = new URL(baseUrl);
62
- url.pathname += "/search";
67
+ const url = formatUrl("/search");
63
68
  const params = new URLSearchParams({
64
69
  q,
65
70
  });
@@ -111,8 +116,7 @@ export const CordsAPI = ({
111
116
 
112
117
  // Get related to a resource
113
118
  const related = async (id: string) => {
114
- const url = new URL(baseUrl);
115
- url.pathname += `/resource/${id}/related`;
119
+ const url = formatUrl(`/resource/${id}/related`);
116
120
 
117
121
  const res = await request(url.toString());
118
122
  if (!res.ok) {
@@ -125,8 +129,7 @@ export const CordsAPI = ({
125
129
 
126
130
  // Get a single resource by id
127
131
  const resource = async (id: string) => {
128
- const url = new URL(baseUrl);
129
- url.pathname += `/resource/${id}`;
132
+ const url = formatUrl(`/resource/${id}`);
130
133
 
131
134
  const res = await request(url.toString());
132
135
  if (!res.ok) {
@@ -148,8 +151,7 @@ export const CordsAPI = ({
148
151
  const params = new URLSearchParams();
149
152
  ids.forEach((id, index) => params.append(`ids[${index}]`, id));
150
153
 
151
- const url = new URL(baseUrl);
152
- url.pathname += "/resource/list";
154
+ const url = formatUrl("/resource/list");
153
155
  url.search = params.toString();
154
156
 
155
157
  const res = await request(url.toString());
@@ -165,8 +167,7 @@ export const CordsAPI = ({
165
167
  lng: number;
166
168
  },
167
169
  ) => {
168
- const url = new URL(baseUrl);
169
- url.pathname += `/resource/${id}/nearest-neighbor`;
170
+ const url = formatUrl(`/resource/${id}/nearest-neighbor`);
170
171
 
171
172
  const params = new URLSearchParams({
172
173
  lat: options.lat.toString(),