@cords/sdk 0.0.6 → 0.0.7

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.d.mts CHANGED
@@ -78,6 +78,8 @@ type SearchOptions = {
78
78
  provincial?: boolean;
79
79
  national?: boolean;
80
80
  };
81
+ calculateProvinceFromSearchString?: boolean;
82
+ calculateCityFromSearchString?: boolean;
81
83
  };
82
84
  type CordsError = {
83
85
  detail: string;
@@ -87,11 +89,12 @@ type CordsError = {
87
89
  };
88
90
 
89
91
  declare const ResourceOptions: {};
90
- declare const CordsAPI: ({ apiKey, version, }: {
92
+ declare const CordsAPI: ({ apiKey, version, referer, }: {
91
93
  apiKey: string;
92
94
  version?: "production" | "dev";
95
+ referer?: string;
93
96
  }) => {
94
- search: (q: string, options: SearchOptions) => Promise<{
97
+ search: (q: string, { calculateCityFromSearchString, calculateProvinceFromSearchString, ...options }: SearchOptions) => Promise<{
95
98
  data: SearchResourceType[];
96
99
  meta: {
97
100
  total: number;
package/dist/index.d.ts CHANGED
@@ -78,6 +78,8 @@ type SearchOptions = {
78
78
  provincial?: boolean;
79
79
  national?: boolean;
80
80
  };
81
+ calculateProvinceFromSearchString?: boolean;
82
+ calculateCityFromSearchString?: boolean;
81
83
  };
82
84
  type CordsError = {
83
85
  detail: string;
@@ -87,11 +89,12 @@ type CordsError = {
87
89
  };
88
90
 
89
91
  declare const ResourceOptions: {};
90
- declare const CordsAPI: ({ apiKey, version, }: {
92
+ declare const CordsAPI: ({ apiKey, version, referer, }: {
91
93
  apiKey: string;
92
94
  version?: "production" | "dev";
95
+ referer?: string;
93
96
  }) => {
94
- search: (q: string, options: SearchOptions) => Promise<{
97
+ search: (q: string, { calculateCityFromSearchString, calculateProvinceFromSearchString, ...options }: SearchOptions) => Promise<{
95
98
  data: SearchResourceType[];
96
99
  meta: {
97
100
  total: number;
package/dist/index.js CHANGED
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
20
20
  return a;
21
21
  };
22
22
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __objRest = (source, exclude) => {
24
+ var target = {};
25
+ for (var prop in source)
26
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
+ target[prop] = source[prop];
28
+ if (source != null && __getOwnPropSymbols)
29
+ for (var prop of __getOwnPropSymbols(source)) {
30
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
+ target[prop] = source[prop];
32
+ }
33
+ return target;
34
+ };
23
35
  var __export = (target, all) => {
24
36
  for (var name in all)
25
37
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -65,14 +77,15 @@ module.exports = __toCommonJS(src_exports);
65
77
  var ResourceOptions = {};
66
78
  var CordsAPI = ({
67
79
  apiKey,
68
- version = "production"
80
+ version = "production",
81
+ referer
69
82
  }) => {
70
83
  const baseUrl = version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
71
84
  const request = (input, init) => __async(void 0, null, function* () {
72
85
  const res = yield fetch(input, __spreadProps(__spreadValues({}, init), {
73
- headers: __spreadValues({
86
+ headers: __spreadValues(__spreadValues({
74
87
  "x-api-key": apiKey
75
- }, init == null ? void 0 : init.headers)
88
+ }, referer ? { referer } : {}), init == null ? void 0 : init.headers)
76
89
  }));
77
90
  if (!res.ok) {
78
91
  if (res.status === 403)
@@ -83,7 +96,14 @@ var CordsAPI = ({
83
96
  }
84
97
  return res;
85
98
  });
86
- const search = (q, options) => __async(void 0, null, function* () {
99
+ const search = (q, _a) => __async(void 0, null, function* () {
100
+ var _b = _a, {
101
+ calculateCityFromSearchString = true,
102
+ calculateProvinceFromSearchString = true
103
+ } = _b, options = __objRest(_b, [
104
+ "calculateCityFromSearchString",
105
+ "calculateProvinceFromSearchString"
106
+ ]);
87
107
  const url = new URL("/search", baseUrl);
88
108
  const params = new URLSearchParams({
89
109
  q
@@ -93,6 +113,14 @@ var CordsAPI = ({
93
113
  if (options.page) params.append("page", options.page.toString());
94
114
  if (options.pageSize) params.append("pageSize", options.pageSize.toString());
95
115
  if (options.distance) params.append("distance", options.distance.toString());
116
+ params.append(
117
+ "calculateProvinceFromSearchString",
118
+ calculateProvinceFromSearchString ? "true" : "false"
119
+ );
120
+ params.append(
121
+ "calculateCityFromSearchString",
122
+ calculateCityFromSearchString ? "true" : "false"
123
+ );
96
124
  if (options.partner) {
97
125
  for (const [key, value] of Object.entries(options.partner)) {
98
126
  params.append(`filter[${key}]`, value ? "true" : "false");
package/dist/index.mjs CHANGED
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
20
32
  var __async = (__this, __arguments, generator) => {
21
33
  return new Promise((resolve, reject) => {
22
34
  var fulfilled = (value) => {
@@ -42,14 +54,15 @@ var __async = (__this, __arguments, generator) => {
42
54
  var ResourceOptions = {};
43
55
  var CordsAPI = ({
44
56
  apiKey,
45
- version = "production"
57
+ version = "production",
58
+ referer
46
59
  }) => {
47
60
  const baseUrl = version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
48
61
  const request = (input, init) => __async(void 0, null, function* () {
49
62
  const res = yield fetch(input, __spreadProps(__spreadValues({}, init), {
50
- headers: __spreadValues({
63
+ headers: __spreadValues(__spreadValues({
51
64
  "x-api-key": apiKey
52
- }, init == null ? void 0 : init.headers)
65
+ }, referer ? { referer } : {}), init == null ? void 0 : init.headers)
53
66
  }));
54
67
  if (!res.ok) {
55
68
  if (res.status === 403)
@@ -60,7 +73,14 @@ var CordsAPI = ({
60
73
  }
61
74
  return res;
62
75
  });
63
- const search = (q, options) => __async(void 0, null, function* () {
76
+ const search = (q, _a) => __async(void 0, null, function* () {
77
+ var _b = _a, {
78
+ calculateCityFromSearchString = true,
79
+ calculateProvinceFromSearchString = true
80
+ } = _b, options = __objRest(_b, [
81
+ "calculateCityFromSearchString",
82
+ "calculateProvinceFromSearchString"
83
+ ]);
64
84
  const url = new URL("/search", baseUrl);
65
85
  const params = new URLSearchParams({
66
86
  q
@@ -70,6 +90,14 @@ var CordsAPI = ({
70
90
  if (options.page) params.append("page", options.page.toString());
71
91
  if (options.pageSize) params.append("pageSize", options.pageSize.toString());
72
92
  if (options.distance) params.append("distance", options.distance.toString());
93
+ params.append(
94
+ "calculateProvinceFromSearchString",
95
+ calculateProvinceFromSearchString ? "true" : "false"
96
+ );
97
+ params.append(
98
+ "calculateCityFromSearchString",
99
+ calculateCityFromSearchString ? "true" : "false"
100
+ );
73
101
  if (options.partner) {
74
102
  for (const [key, value] of Object.entries(options.partner)) {
75
103
  params.append(`filter[${key}]`, value ? "true" : "false");
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.6",
6
+ "version": "0.0.7",
7
7
  "private": false,
8
8
  "publishConfig": {
9
9
  "access": "public"
package/src/index.ts CHANGED
@@ -12,17 +12,22 @@ export const ResourceOptions = {};
12
12
  export const CordsAPI = ({
13
13
  apiKey,
14
14
  version = "production",
15
+ referer,
15
16
  }: {
16
17
  apiKey: string;
17
18
  version?: "production" | "dev";
19
+ referer?: string;
18
20
  }) => {
21
+ // Set the base URL for the Cords API
19
22
  const baseUrl = version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
20
23
 
24
+ // Helper for making requests to the Cords API that applies the api key, referrer, and handles errors
21
25
  const request = async (input: RequestInfo, init?: RequestInit) => {
22
26
  const res = await fetch(input, {
23
27
  ...init,
24
28
  headers: {
25
29
  "x-api-key": apiKey,
30
+ ...(referer ? { referer } : {}),
26
31
  ...init?.headers,
27
32
  },
28
33
  });
@@ -36,7 +41,15 @@ export const CordsAPI = ({
36
41
  return res;
37
42
  };
38
43
 
39
- const search = async (q: string, options: SearchOptions) => {
44
+ // Search for resources
45
+ const search = async (
46
+ q: string,
47
+ {
48
+ calculateCityFromSearchString = true,
49
+ calculateProvinceFromSearchString = true,
50
+ ...options
51
+ }: SearchOptions
52
+ ) => {
40
53
  const url = new URL("/search", baseUrl);
41
54
  const params = new URLSearchParams({
42
55
  q,
@@ -50,6 +63,16 @@ export const CordsAPI = ({
50
63
  if (options.pageSize) params.append("pageSize", options.pageSize.toString());
51
64
  if (options.distance) params.append("distance", options.distance.toString());
52
65
 
66
+ // Add boolean parameters
67
+ params.append(
68
+ "calculateProvinceFromSearchString",
69
+ calculateProvinceFromSearchString ? "true" : "false"
70
+ );
71
+ params.append(
72
+ "calculateCityFromSearchString",
73
+ calculateCityFromSearchString ? "true" : "false"
74
+ );
75
+
53
76
  // Add partner parameters
54
77
  if (options.partner) {
55
78
  for (const [key, value] of Object.entries(options.partner)) {
@@ -72,6 +95,7 @@ export const CordsAPI = ({
72
95
  };
73
96
  };
74
97
 
98
+ // Get related to a resource
75
99
  const related = async (id: string) => {
76
100
  const url = new URL(`/resource/${id}/related`, baseUrl);
77
101
 
@@ -84,6 +108,7 @@ export const CordsAPI = ({
84
108
  return data as { data: ResourceType[] };
85
109
  };
86
110
 
111
+ // Get a single resource by id
87
112
  const resource = async (id: string) => {
88
113
  const url = new URL(`/resource/${id}`, baseUrl);
89
114
 
@@ -96,6 +121,7 @@ export const CordsAPI = ({
96
121
  return data as ResourceType;
97
122
  };
98
123
 
124
+ // Get a list of resources by id
99
125
  const resourceList = async (ids: string[]): Promise<{ data: ResourceType[] }> => {
100
126
  if (ids.length === 0)
101
127
  return {
@@ -111,6 +137,7 @@ export const CordsAPI = ({
111
137
  return data as { data: ResourceType[] };
112
138
  };
113
139
 
140
+ // Get the nearest neighbour to a resource
114
141
  const nearestNeighbour = async (
115
142
  id: string,
116
143
  options: {
@@ -143,6 +170,7 @@ export const CordsAPI = ({
143
170
  };
144
171
  };
145
172
 
173
+ // Helper function to format a service address
146
174
  export const formatServiceAddress = (address: ResourceAddressType) => {
147
175
  const street1 = address.street1 ? address.street1 + ", " : "";
148
176
  const street2 = address.street2 ? address.street2 + ", " : "";
package/src/types.ts CHANGED
@@ -86,6 +86,8 @@ export type SearchOptions = {
86
86
  provincial?: boolean;
87
87
  national?: boolean;
88
88
  };
89
+ calculateProvinceFromSearchString?: boolean;
90
+ calculateCityFromSearchString?: boolean;
89
91
  };
90
92
 
91
93
  export type CordsError = {