@cords/sdk 0.1.9 → 0.1.11
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 +90 -15
- package/dist/index.d.ts +90 -15
- package/dist/index.js +99 -37
- package/dist/index.mjs +98 -36
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,22 @@ type LocalizedFieldType = {
|
|
|
2
2
|
en: string;
|
|
3
3
|
fr: string;
|
|
4
4
|
};
|
|
5
|
+
type APIOptions = {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
version?: "production" | "dev";
|
|
8
|
+
referer?: string;
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
};
|
|
11
|
+
type PageOptions = {
|
|
12
|
+
page?: number;
|
|
13
|
+
pageSize?: number;
|
|
14
|
+
};
|
|
15
|
+
type CordsError = {
|
|
16
|
+
detail: string;
|
|
17
|
+
status: number;
|
|
18
|
+
title: string;
|
|
19
|
+
type: string;
|
|
20
|
+
};
|
|
5
21
|
type ResourceAddressType = {
|
|
6
22
|
street1: string;
|
|
7
23
|
street2: string;
|
|
@@ -66,9 +82,7 @@ type SearchOptions = ({
|
|
|
66
82
|
} | {
|
|
67
83
|
ids: string[];
|
|
68
84
|
}) & {
|
|
69
|
-
page?: number;
|
|
70
85
|
distance?: number;
|
|
71
|
-
pageSize?: number;
|
|
72
86
|
partner?: {
|
|
73
87
|
"211"?: boolean;
|
|
74
88
|
mentor?: boolean;
|
|
@@ -87,21 +101,64 @@ type SearchOptions = ({
|
|
|
87
101
|
meta?: {
|
|
88
102
|
taxonomy?: TaxonomyCodeType[];
|
|
89
103
|
};
|
|
104
|
+
} & PageOptions;
|
|
105
|
+
type EmbeddingType = {
|
|
106
|
+
document: string;
|
|
107
|
+
embedding: number[];
|
|
108
|
+
addresses: ResourceAddressType[];
|
|
90
109
|
};
|
|
91
|
-
type
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
type ReportOptions = {
|
|
111
|
+
/** Account holder email must include value */
|
|
112
|
+
email?: string;
|
|
113
|
+
/** Search term must include value */
|
|
114
|
+
searchTerm?: string;
|
|
115
|
+
/** Either 'dev' or 'prod' */
|
|
116
|
+
keyType?: "dev" | "prod";
|
|
117
|
+
/** The ID of the api-key. Not the key itself! */
|
|
118
|
+
apiKey?: string;
|
|
119
|
+
/** The provincial abbreviation (e.g. ON) that the search was set to. */
|
|
120
|
+
province?: string;
|
|
121
|
+
/** The postal code that the search was set to must include value */
|
|
122
|
+
postalCode?: string;
|
|
123
|
+
/** The country that the search was set to must include value */
|
|
124
|
+
country?: string;
|
|
125
|
+
/** 25 results are included per page */
|
|
126
|
+
page?: PageOptions["page"];
|
|
127
|
+
/** Type of report */
|
|
128
|
+
type?: "view" | "search";
|
|
129
|
+
dates?: {
|
|
130
|
+
start: Date;
|
|
131
|
+
end: Date;
|
|
132
|
+
};
|
|
96
133
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
declare const CordsAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }: {
|
|
134
|
+
type ReportRecordType = {
|
|
135
|
+
ip: string;
|
|
100
136
|
apiKey: string;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
137
|
+
searchString: string;
|
|
138
|
+
latitude: number | null;
|
|
139
|
+
longitude: number | null;
|
|
140
|
+
province: string | null;
|
|
141
|
+
derivedProvince: string | null;
|
|
142
|
+
derivedCity: string | null;
|
|
143
|
+
derivedLat: string | null;
|
|
144
|
+
derivedLng: string | null;
|
|
145
|
+
type: "view" | "search";
|
|
146
|
+
createdDate: {
|
|
147
|
+
date: string;
|
|
148
|
+
timezone_type: number;
|
|
149
|
+
timezone: string;
|
|
150
|
+
};
|
|
151
|
+
email: string;
|
|
152
|
+
filters: string[];
|
|
153
|
+
searchEmbedding: number[] | null;
|
|
154
|
+
country: string | null;
|
|
155
|
+
postalCode: string | null;
|
|
156
|
+
sid: string | null;
|
|
157
|
+
fingerprint: string | null;
|
|
158
|
+
lead: string | null;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
declare const CordsAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }: APIOptions) => {
|
|
105
162
|
search: ({ calculateCityFromSearchString, calculateProvinceFromSearchString, ...options }: SearchOptions) => Promise<{
|
|
106
163
|
data: SearchResourceType[];
|
|
107
164
|
meta: {
|
|
@@ -120,7 +177,25 @@ declare const CordsAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }:
|
|
|
120
177
|
}) => Promise<{
|
|
121
178
|
data: ResourceType[];
|
|
122
179
|
}>;
|
|
180
|
+
embeddings: (options?: PageOptions) => Promise<{
|
|
181
|
+
data: Record<string, EmbeddingType>;
|
|
182
|
+
meta: {
|
|
183
|
+
total: number;
|
|
184
|
+
page: number;
|
|
185
|
+
pageSize: number;
|
|
186
|
+
};
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
declare const CordsPartnerAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }: APIOptions) => {
|
|
190
|
+
report: (options?: ReportOptions) => Promise<{
|
|
191
|
+
data: ReportRecordType[];
|
|
192
|
+
meta: {
|
|
193
|
+
total: number;
|
|
194
|
+
page: number;
|
|
195
|
+
};
|
|
196
|
+
}>;
|
|
123
197
|
};
|
|
198
|
+
/** Helper function to format a service address */
|
|
124
199
|
declare const formatServiceAddress: (address: ResourceAddressType) => string;
|
|
125
200
|
|
|
126
|
-
export { CordsAPI, type CordsError, type
|
|
201
|
+
export { type APIOptions, CordsAPI, type CordsError, CordsPartnerAPI, type EmbeddingType, type PageOptions, type ReportOptions, type ReportRecordType, type ResourceAddressType, type ResourceBodyType, type ResourceType, type SearchOptions, type SearchResourceType, type TaxonomyCodeType, formatServiceAddress };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,22 @@ type LocalizedFieldType = {
|
|
|
2
2
|
en: string;
|
|
3
3
|
fr: string;
|
|
4
4
|
};
|
|
5
|
+
type APIOptions = {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
version?: "production" | "dev";
|
|
8
|
+
referer?: string;
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
};
|
|
11
|
+
type PageOptions = {
|
|
12
|
+
page?: number;
|
|
13
|
+
pageSize?: number;
|
|
14
|
+
};
|
|
15
|
+
type CordsError = {
|
|
16
|
+
detail: string;
|
|
17
|
+
status: number;
|
|
18
|
+
title: string;
|
|
19
|
+
type: string;
|
|
20
|
+
};
|
|
5
21
|
type ResourceAddressType = {
|
|
6
22
|
street1: string;
|
|
7
23
|
street2: string;
|
|
@@ -66,9 +82,7 @@ type SearchOptions = ({
|
|
|
66
82
|
} | {
|
|
67
83
|
ids: string[];
|
|
68
84
|
}) & {
|
|
69
|
-
page?: number;
|
|
70
85
|
distance?: number;
|
|
71
|
-
pageSize?: number;
|
|
72
86
|
partner?: {
|
|
73
87
|
"211"?: boolean;
|
|
74
88
|
mentor?: boolean;
|
|
@@ -87,21 +101,64 @@ type SearchOptions = ({
|
|
|
87
101
|
meta?: {
|
|
88
102
|
taxonomy?: TaxonomyCodeType[];
|
|
89
103
|
};
|
|
104
|
+
} & PageOptions;
|
|
105
|
+
type EmbeddingType = {
|
|
106
|
+
document: string;
|
|
107
|
+
embedding: number[];
|
|
108
|
+
addresses: ResourceAddressType[];
|
|
90
109
|
};
|
|
91
|
-
type
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
type ReportOptions = {
|
|
111
|
+
/** Account holder email must include value */
|
|
112
|
+
email?: string;
|
|
113
|
+
/** Search term must include value */
|
|
114
|
+
searchTerm?: string;
|
|
115
|
+
/** Either 'dev' or 'prod' */
|
|
116
|
+
keyType?: "dev" | "prod";
|
|
117
|
+
/** The ID of the api-key. Not the key itself! */
|
|
118
|
+
apiKey?: string;
|
|
119
|
+
/** The provincial abbreviation (e.g. ON) that the search was set to. */
|
|
120
|
+
province?: string;
|
|
121
|
+
/** The postal code that the search was set to must include value */
|
|
122
|
+
postalCode?: string;
|
|
123
|
+
/** The country that the search was set to must include value */
|
|
124
|
+
country?: string;
|
|
125
|
+
/** 25 results are included per page */
|
|
126
|
+
page?: PageOptions["page"];
|
|
127
|
+
/** Type of report */
|
|
128
|
+
type?: "view" | "search";
|
|
129
|
+
dates?: {
|
|
130
|
+
start: Date;
|
|
131
|
+
end: Date;
|
|
132
|
+
};
|
|
96
133
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
declare const CordsAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }: {
|
|
134
|
+
type ReportRecordType = {
|
|
135
|
+
ip: string;
|
|
100
136
|
apiKey: string;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
137
|
+
searchString: string;
|
|
138
|
+
latitude: number | null;
|
|
139
|
+
longitude: number | null;
|
|
140
|
+
province: string | null;
|
|
141
|
+
derivedProvince: string | null;
|
|
142
|
+
derivedCity: string | null;
|
|
143
|
+
derivedLat: string | null;
|
|
144
|
+
derivedLng: string | null;
|
|
145
|
+
type: "view" | "search";
|
|
146
|
+
createdDate: {
|
|
147
|
+
date: string;
|
|
148
|
+
timezone_type: number;
|
|
149
|
+
timezone: string;
|
|
150
|
+
};
|
|
151
|
+
email: string;
|
|
152
|
+
filters: string[];
|
|
153
|
+
searchEmbedding: number[] | null;
|
|
154
|
+
country: string | null;
|
|
155
|
+
postalCode: string | null;
|
|
156
|
+
sid: string | null;
|
|
157
|
+
fingerprint: string | null;
|
|
158
|
+
lead: string | null;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
declare const CordsAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }: APIOptions) => {
|
|
105
162
|
search: ({ calculateCityFromSearchString, calculateProvinceFromSearchString, ...options }: SearchOptions) => Promise<{
|
|
106
163
|
data: SearchResourceType[];
|
|
107
164
|
meta: {
|
|
@@ -120,7 +177,25 @@ declare const CordsAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }:
|
|
|
120
177
|
}) => Promise<{
|
|
121
178
|
data: ResourceType[];
|
|
122
179
|
}>;
|
|
180
|
+
embeddings: (options?: PageOptions) => Promise<{
|
|
181
|
+
data: Record<string, EmbeddingType>;
|
|
182
|
+
meta: {
|
|
183
|
+
total: number;
|
|
184
|
+
page: number;
|
|
185
|
+
pageSize: number;
|
|
186
|
+
};
|
|
187
|
+
}>;
|
|
188
|
+
};
|
|
189
|
+
declare const CordsPartnerAPI: ({ apiKey, version, referer, baseUrl: customBaseUrl, }: APIOptions) => {
|
|
190
|
+
report: (options?: ReportOptions) => Promise<{
|
|
191
|
+
data: ReportRecordType[];
|
|
192
|
+
meta: {
|
|
193
|
+
total: number;
|
|
194
|
+
page: number;
|
|
195
|
+
};
|
|
196
|
+
}>;
|
|
123
197
|
};
|
|
198
|
+
/** Helper function to format a service address */
|
|
124
199
|
declare const formatServiceAddress: (address: ResourceAddressType) => string;
|
|
125
200
|
|
|
126
|
-
export { CordsAPI, type CordsError, type
|
|
201
|
+
export { type APIOptions, CordsAPI, type CordsError, CordsPartnerAPI, type EmbeddingType, type PageOptions, type ReportOptions, type ReportRecordType, type ResourceAddressType, type ResourceBodyType, type ResourceType, type SearchOptions, type SearchResourceType, type TaxonomyCodeType, formatServiceAddress };
|
package/dist/index.js
CHANGED
|
@@ -50,11 +50,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
50
50
|
var index_exports = {};
|
|
51
51
|
__export(index_exports, {
|
|
52
52
|
CordsAPI: () => CordsAPI,
|
|
53
|
-
|
|
53
|
+
CordsPartnerAPI: () => CordsPartnerAPI,
|
|
54
54
|
formatServiceAddress: () => formatServiceAddress
|
|
55
55
|
});
|
|
56
56
|
module.exports = __toCommonJS(index_exports);
|
|
57
|
-
var
|
|
57
|
+
var request = async (options, input, init) => {
|
|
58
|
+
const res = await fetch(input, __spreadProps(__spreadValues({}, init), {
|
|
59
|
+
headers: __spreadValues(__spreadValues(__spreadValues({
|
|
60
|
+
"x-api-key": options.apiKey
|
|
61
|
+
}, options.referer ? { referer: options.referer } : {}), options.sessionId ? { "session-id": options.sessionId } : {}), init == null ? void 0 : init.headers)
|
|
62
|
+
}));
|
|
63
|
+
if (!res.ok) {
|
|
64
|
+
if ([401, 403].includes(res.status)) {
|
|
65
|
+
throw new Error("Bad API key. Ensure you have a valid API key.");
|
|
66
|
+
}
|
|
67
|
+
if (res.status === 404) {
|
|
68
|
+
throw new Error("Not found");
|
|
69
|
+
}
|
|
70
|
+
const data = await res.json();
|
|
71
|
+
if (data.detail) throw new Error(data.detail);
|
|
72
|
+
else throw new Error("An error occurred");
|
|
73
|
+
}
|
|
74
|
+
return res;
|
|
75
|
+
};
|
|
58
76
|
var CordsAPI = ({
|
|
59
77
|
apiKey,
|
|
60
78
|
version = "production",
|
|
@@ -62,26 +80,13 @@ var CordsAPI = ({
|
|
|
62
80
|
baseUrl: customBaseUrl
|
|
63
81
|
}) => {
|
|
64
82
|
let sessionId = null;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"x-api-key": apiKey
|
|
70
|
-
}, referer ? { referer } : {}), sessionId ? { "session-id": sessionId } : {}), init == null ? void 0 : init.headers)
|
|
71
|
-
}));
|
|
72
|
-
if (!res.ok) {
|
|
73
|
-
if ([401, 403].includes(res.status)) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
"Bad API key. Ensure you have a valid API key."
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
const data = await res.json();
|
|
79
|
-
if (data.detail) throw new Error(data.detail);
|
|
80
|
-
else throw new Error("An error occurred");
|
|
81
|
-
}
|
|
82
|
-
return res;
|
|
83
|
+
const requestOptions = {
|
|
84
|
+
apiKey,
|
|
85
|
+
referer,
|
|
86
|
+
sessionId
|
|
83
87
|
};
|
|
84
88
|
const formatUrl = (pathname) => {
|
|
89
|
+
const baseUrl = customBaseUrl ? customBaseUrl == null ? void 0 : customBaseUrl.replace(/\/$/, "") : version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
|
|
85
90
|
const url = new URL(baseUrl);
|
|
86
91
|
url.pathname = url.pathname.replace(/\/$/, "") + pathname;
|
|
87
92
|
return url;
|
|
@@ -140,28 +145,23 @@ var CordsAPI = ({
|
|
|
140
145
|
params.append("filter[meta][TaxonomyCodes][]", code);
|
|
141
146
|
});
|
|
142
147
|
}
|
|
143
|
-
const res = await request(
|
|
148
|
+
const res = await request(
|
|
149
|
+
requestOptions,
|
|
150
|
+
`${url.toString()}?${params}`
|
|
151
|
+
);
|
|
144
152
|
const data = await res.json();
|
|
145
153
|
sessionId = res.headers.get("session-id");
|
|
146
154
|
return data;
|
|
147
155
|
};
|
|
148
156
|
const related = async (id) => {
|
|
149
157
|
const url = formatUrl(`/resource/${id}/related`);
|
|
150
|
-
const res = await request(url.toString());
|
|
151
|
-
if (!res.ok) {
|
|
152
|
-
const data2 = await res.json();
|
|
153
|
-
throw new Error(data2.detail);
|
|
154
|
-
}
|
|
158
|
+
const res = await request(requestOptions, url.toString());
|
|
155
159
|
const data = await res.json();
|
|
156
160
|
return data;
|
|
157
161
|
};
|
|
158
162
|
const resource = async (id) => {
|
|
159
163
|
const url = formatUrl(`/resource/${id}`);
|
|
160
|
-
const res = await request(url.toString());
|
|
161
|
-
if (!res.ok) {
|
|
162
|
-
const data2 = await res.json();
|
|
163
|
-
throw new Error(data2.detail);
|
|
164
|
-
}
|
|
164
|
+
const res = await request(requestOptions, url.toString());
|
|
165
165
|
const data = await res.json();
|
|
166
166
|
sessionId = res.headers.get("session-id");
|
|
167
167
|
return data;
|
|
@@ -173,12 +173,22 @@ var CordsAPI = ({
|
|
|
173
173
|
lng: options.lng.toString()
|
|
174
174
|
});
|
|
175
175
|
const res = await request(
|
|
176
|
+
requestOptions,
|
|
176
177
|
url.toString() + "?delivery=local&" + params.toString()
|
|
177
178
|
);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
const data = await res.json();
|
|
180
|
+
return data;
|
|
181
|
+
};
|
|
182
|
+
const embeddings = async (options) => {
|
|
183
|
+
const url = formatUrl("/embeddings");
|
|
184
|
+
const params = new URLSearchParams();
|
|
185
|
+
if (options == null ? void 0 : options.page) params.append("page", options.page.toString());
|
|
186
|
+
if (options == null ? void 0 : options.pageSize)
|
|
187
|
+
params.append("pageSize", options.pageSize.toString());
|
|
188
|
+
const res = await request(
|
|
189
|
+
requestOptions,
|
|
190
|
+
`${url.toString()}?${params.toString()}`
|
|
191
|
+
);
|
|
182
192
|
const data = await res.json();
|
|
183
193
|
return data;
|
|
184
194
|
};
|
|
@@ -186,7 +196,59 @@ var CordsAPI = ({
|
|
|
186
196
|
search,
|
|
187
197
|
related,
|
|
188
198
|
resource,
|
|
189
|
-
nearestNeighbour
|
|
199
|
+
nearestNeighbour,
|
|
200
|
+
embeddings
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
var CordsPartnerAPI = ({
|
|
204
|
+
apiKey,
|
|
205
|
+
version = "production",
|
|
206
|
+
referer,
|
|
207
|
+
baseUrl: customBaseUrl
|
|
208
|
+
}) => {
|
|
209
|
+
const requestOptions = {
|
|
210
|
+
apiKey,
|
|
211
|
+
referer
|
|
212
|
+
};
|
|
213
|
+
const formatUrl = (pathname) => {
|
|
214
|
+
const baseUrl = customBaseUrl ? customBaseUrl == null ? void 0 : customBaseUrl.replace(/\/$/, "") : version === "production" ? "https://partners-api.cords.ai" : "https://partners-api.cords.dev";
|
|
215
|
+
const url = new URL(baseUrl);
|
|
216
|
+
url.pathname = url.pathname.replace(/\/$/, "") + pathname;
|
|
217
|
+
return url;
|
|
218
|
+
};
|
|
219
|
+
const report = async (options) => {
|
|
220
|
+
const url = formatUrl("/partner/approved/report");
|
|
221
|
+
const params = new URLSearchParams();
|
|
222
|
+
if (options == null ? void 0 : options.email) params.append("filters[email]", options.email);
|
|
223
|
+
if (options == null ? void 0 : options.searchTerm)
|
|
224
|
+
params.append("filters[search-term]", options.searchTerm);
|
|
225
|
+
if (options == null ? void 0 : options.keyType)
|
|
226
|
+
params.append("filters[key-type]", options.keyType);
|
|
227
|
+
if (options == null ? void 0 : options.apiKey) params.append("filters[api-key]", options.apiKey);
|
|
228
|
+
if (options == null ? void 0 : options.type) params.append("filters[type]", options.type);
|
|
229
|
+
if (options == null ? void 0 : options.province)
|
|
230
|
+
params.append("filters[province]", options.province);
|
|
231
|
+
if (options == null ? void 0 : options.postalCode)
|
|
232
|
+
params.append("filters[postal-code]", options.postalCode);
|
|
233
|
+
if (options == null ? void 0 : options.country)
|
|
234
|
+
params.append("filters[country]", options.country);
|
|
235
|
+
if (options == null ? void 0 : options.page) params.append("page", options.page.toString());
|
|
236
|
+
if (options == null ? void 0 : options.dates) {
|
|
237
|
+
params.append(
|
|
238
|
+
"filters[dates]",
|
|
239
|
+
options.dates.start.getTime() + "|" + options.dates.end.getTime()
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
console.log(decodeURIComponent(url.toString() + "?" + params));
|
|
243
|
+
const res = await request(
|
|
244
|
+
requestOptions,
|
|
245
|
+
url.toString() + "?" + params
|
|
246
|
+
);
|
|
247
|
+
const data = await res.json();
|
|
248
|
+
return data;
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
report
|
|
190
252
|
};
|
|
191
253
|
};
|
|
192
254
|
var formatServiceAddress = (address) => {
|
|
@@ -203,6 +265,6 @@ var formatServiceAddress = (address) => {
|
|
|
203
265
|
// Annotate the CommonJS export names for ESM import in node:
|
|
204
266
|
0 && (module.exports = {
|
|
205
267
|
CordsAPI,
|
|
206
|
-
|
|
268
|
+
CordsPartnerAPI,
|
|
207
269
|
formatServiceAddress
|
|
208
270
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -31,7 +31,25 @@ var __objRest = (source, exclude) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// src/index.ts
|
|
34
|
-
var
|
|
34
|
+
var request = async (options, input, init) => {
|
|
35
|
+
const res = await fetch(input, __spreadProps(__spreadValues({}, init), {
|
|
36
|
+
headers: __spreadValues(__spreadValues(__spreadValues({
|
|
37
|
+
"x-api-key": options.apiKey
|
|
38
|
+
}, options.referer ? { referer: options.referer } : {}), options.sessionId ? { "session-id": options.sessionId } : {}), init == null ? void 0 : init.headers)
|
|
39
|
+
}));
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
if ([401, 403].includes(res.status)) {
|
|
42
|
+
throw new Error("Bad API key. Ensure you have a valid API key.");
|
|
43
|
+
}
|
|
44
|
+
if (res.status === 404) {
|
|
45
|
+
throw new Error("Not found");
|
|
46
|
+
}
|
|
47
|
+
const data = await res.json();
|
|
48
|
+
if (data.detail) throw new Error(data.detail);
|
|
49
|
+
else throw new Error("An error occurred");
|
|
50
|
+
}
|
|
51
|
+
return res;
|
|
52
|
+
};
|
|
35
53
|
var CordsAPI = ({
|
|
36
54
|
apiKey,
|
|
37
55
|
version = "production",
|
|
@@ -39,26 +57,13 @@ var CordsAPI = ({
|
|
|
39
57
|
baseUrl: customBaseUrl
|
|
40
58
|
}) => {
|
|
41
59
|
let sessionId = null;
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"x-api-key": apiKey
|
|
47
|
-
}, referer ? { referer } : {}), sessionId ? { "session-id": sessionId } : {}), init == null ? void 0 : init.headers)
|
|
48
|
-
}));
|
|
49
|
-
if (!res.ok) {
|
|
50
|
-
if ([401, 403].includes(res.status)) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
"Bad API key. Ensure you have a valid API key."
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
const data = await res.json();
|
|
56
|
-
if (data.detail) throw new Error(data.detail);
|
|
57
|
-
else throw new Error("An error occurred");
|
|
58
|
-
}
|
|
59
|
-
return res;
|
|
60
|
+
const requestOptions = {
|
|
61
|
+
apiKey,
|
|
62
|
+
referer,
|
|
63
|
+
sessionId
|
|
60
64
|
};
|
|
61
65
|
const formatUrl = (pathname) => {
|
|
66
|
+
const baseUrl = customBaseUrl ? customBaseUrl == null ? void 0 : customBaseUrl.replace(/\/$/, "") : version === "production" ? "https://api.cords.ai" : "https://api.cords.dev";
|
|
62
67
|
const url = new URL(baseUrl);
|
|
63
68
|
url.pathname = url.pathname.replace(/\/$/, "") + pathname;
|
|
64
69
|
return url;
|
|
@@ -117,28 +122,23 @@ var CordsAPI = ({
|
|
|
117
122
|
params.append("filter[meta][TaxonomyCodes][]", code);
|
|
118
123
|
});
|
|
119
124
|
}
|
|
120
|
-
const res = await request(
|
|
125
|
+
const res = await request(
|
|
126
|
+
requestOptions,
|
|
127
|
+
`${url.toString()}?${params}`
|
|
128
|
+
);
|
|
121
129
|
const data = await res.json();
|
|
122
130
|
sessionId = res.headers.get("session-id");
|
|
123
131
|
return data;
|
|
124
132
|
};
|
|
125
133
|
const related = async (id) => {
|
|
126
134
|
const url = formatUrl(`/resource/${id}/related`);
|
|
127
|
-
const res = await request(url.toString());
|
|
128
|
-
if (!res.ok) {
|
|
129
|
-
const data2 = await res.json();
|
|
130
|
-
throw new Error(data2.detail);
|
|
131
|
-
}
|
|
135
|
+
const res = await request(requestOptions, url.toString());
|
|
132
136
|
const data = await res.json();
|
|
133
137
|
return data;
|
|
134
138
|
};
|
|
135
139
|
const resource = async (id) => {
|
|
136
140
|
const url = formatUrl(`/resource/${id}`);
|
|
137
|
-
const res = await request(url.toString());
|
|
138
|
-
if (!res.ok) {
|
|
139
|
-
const data2 = await res.json();
|
|
140
|
-
throw new Error(data2.detail);
|
|
141
|
-
}
|
|
141
|
+
const res = await request(requestOptions, url.toString());
|
|
142
142
|
const data = await res.json();
|
|
143
143
|
sessionId = res.headers.get("session-id");
|
|
144
144
|
return data;
|
|
@@ -150,12 +150,22 @@ var CordsAPI = ({
|
|
|
150
150
|
lng: options.lng.toString()
|
|
151
151
|
});
|
|
152
152
|
const res = await request(
|
|
153
|
+
requestOptions,
|
|
153
154
|
url.toString() + "?delivery=local&" + params.toString()
|
|
154
155
|
);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
const data = await res.json();
|
|
157
|
+
return data;
|
|
158
|
+
};
|
|
159
|
+
const embeddings = async (options) => {
|
|
160
|
+
const url = formatUrl("/embeddings");
|
|
161
|
+
const params = new URLSearchParams();
|
|
162
|
+
if (options == null ? void 0 : options.page) params.append("page", options.page.toString());
|
|
163
|
+
if (options == null ? void 0 : options.pageSize)
|
|
164
|
+
params.append("pageSize", options.pageSize.toString());
|
|
165
|
+
const res = await request(
|
|
166
|
+
requestOptions,
|
|
167
|
+
`${url.toString()}?${params.toString()}`
|
|
168
|
+
);
|
|
159
169
|
const data = await res.json();
|
|
160
170
|
return data;
|
|
161
171
|
};
|
|
@@ -163,7 +173,59 @@ var CordsAPI = ({
|
|
|
163
173
|
search,
|
|
164
174
|
related,
|
|
165
175
|
resource,
|
|
166
|
-
nearestNeighbour
|
|
176
|
+
nearestNeighbour,
|
|
177
|
+
embeddings
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
var CordsPartnerAPI = ({
|
|
181
|
+
apiKey,
|
|
182
|
+
version = "production",
|
|
183
|
+
referer,
|
|
184
|
+
baseUrl: customBaseUrl
|
|
185
|
+
}) => {
|
|
186
|
+
const requestOptions = {
|
|
187
|
+
apiKey,
|
|
188
|
+
referer
|
|
189
|
+
};
|
|
190
|
+
const formatUrl = (pathname) => {
|
|
191
|
+
const baseUrl = customBaseUrl ? customBaseUrl == null ? void 0 : customBaseUrl.replace(/\/$/, "") : version === "production" ? "https://partners-api.cords.ai" : "https://partners-api.cords.dev";
|
|
192
|
+
const url = new URL(baseUrl);
|
|
193
|
+
url.pathname = url.pathname.replace(/\/$/, "") + pathname;
|
|
194
|
+
return url;
|
|
195
|
+
};
|
|
196
|
+
const report = async (options) => {
|
|
197
|
+
const url = formatUrl("/partner/approved/report");
|
|
198
|
+
const params = new URLSearchParams();
|
|
199
|
+
if (options == null ? void 0 : options.email) params.append("filters[email]", options.email);
|
|
200
|
+
if (options == null ? void 0 : options.searchTerm)
|
|
201
|
+
params.append("filters[search-term]", options.searchTerm);
|
|
202
|
+
if (options == null ? void 0 : options.keyType)
|
|
203
|
+
params.append("filters[key-type]", options.keyType);
|
|
204
|
+
if (options == null ? void 0 : options.apiKey) params.append("filters[api-key]", options.apiKey);
|
|
205
|
+
if (options == null ? void 0 : options.type) params.append("filters[type]", options.type);
|
|
206
|
+
if (options == null ? void 0 : options.province)
|
|
207
|
+
params.append("filters[province]", options.province);
|
|
208
|
+
if (options == null ? void 0 : options.postalCode)
|
|
209
|
+
params.append("filters[postal-code]", options.postalCode);
|
|
210
|
+
if (options == null ? void 0 : options.country)
|
|
211
|
+
params.append("filters[country]", options.country);
|
|
212
|
+
if (options == null ? void 0 : options.page) params.append("page", options.page.toString());
|
|
213
|
+
if (options == null ? void 0 : options.dates) {
|
|
214
|
+
params.append(
|
|
215
|
+
"filters[dates]",
|
|
216
|
+
options.dates.start.getTime() + "|" + options.dates.end.getTime()
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
console.log(decodeURIComponent(url.toString() + "?" + params));
|
|
220
|
+
const res = await request(
|
|
221
|
+
requestOptions,
|
|
222
|
+
url.toString() + "?" + params
|
|
223
|
+
);
|
|
224
|
+
const data = await res.json();
|
|
225
|
+
return data;
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
report
|
|
167
229
|
};
|
|
168
230
|
};
|
|
169
231
|
var formatServiceAddress = (address) => {
|
|
@@ -179,6 +241,6 @@ var formatServiceAddress = (address) => {
|
|
|
179
241
|
};
|
|
180
242
|
export {
|
|
181
243
|
CordsAPI,
|
|
182
|
-
|
|
244
|
+
CordsPartnerAPI,
|
|
183
245
|
formatServiceAddress
|
|
184
246
|
};
|