@compresr/sdk 1.0.0
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 +263 -0
- package/dist/cjs/clients/compression.d.ts +137 -0
- package/dist/cjs/clients/compression.d.ts.map +1 -0
- package/dist/cjs/clients/compression.js +220 -0
- package/dist/cjs/clients/compression.js.map +1 -0
- package/dist/cjs/clients/index.d.ts +2 -0
- package/dist/cjs/clients/index.d.ts.map +1 -0
- package/dist/cjs/clients/index.js +6 -0
- package/dist/cjs/clients/index.js.map +1 -0
- package/dist/cjs/config/constants.d.ts +61 -0
- package/dist/cjs/config/constants.d.ts.map +1 -0
- package/dist/cjs/config/constants.js +77 -0
- package/dist/cjs/config/constants.js.map +1 -0
- package/dist/cjs/config/endpoints.d.ts +18 -0
- package/dist/cjs/config/endpoints.d.ts.map +1 -0
- package/dist/cjs/config/endpoints.js +25 -0
- package/dist/cjs/config/endpoints.js.map +1 -0
- package/dist/cjs/config/index.d.ts +3 -0
- package/dist/cjs/config/index.d.ts.map +1 -0
- package/dist/cjs/config/index.js +20 -0
- package/dist/cjs/config/index.js.map +1 -0
- package/dist/cjs/errors/exceptions.d.ts +72 -0
- package/dist/cjs/errors/exceptions.d.ts.map +1 -0
- package/dist/cjs/errors/exceptions.js +107 -0
- package/dist/cjs/errors/exceptions.js.map +1 -0
- package/dist/cjs/errors/index.d.ts +2 -0
- package/dist/cjs/errors/index.d.ts.map +1 -0
- package/dist/cjs/errors/index.js +13 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/http/client.d.ts +53 -0
- package/dist/cjs/http/client.d.ts.map +1 -0
- package/dist/cjs/http/client.js +268 -0
- package/dist/cjs/http/client.js.map +1 -0
- package/dist/cjs/http/errors.d.ts +19 -0
- package/dist/cjs/http/errors.d.ts.map +1 -0
- package/dist/cjs/http/errors.js +87 -0
- package/dist/cjs/http/errors.js.map +1 -0
- package/dist/cjs/http/index.d.ts +3 -0
- package/dist/cjs/http/index.d.ts.map +1 -0
- package/dist/cjs/http/index.js +8 -0
- package/dist/cjs/http/index.js.map +1 -0
- package/dist/cjs/index.d.ts +33 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/schemas/common.d.ts +47 -0
- package/dist/cjs/schemas/common.d.ts.map +1 -0
- package/dist/cjs/schemas/common.js +29 -0
- package/dist/cjs/schemas/common.js.map +1 -0
- package/dist/cjs/schemas/compression.d.ts +378 -0
- package/dist/cjs/schemas/compression.d.ts.map +1 -0
- package/dist/cjs/schemas/compression.js +99 -0
- package/dist/cjs/schemas/compression.js.map +1 -0
- package/dist/cjs/schemas/index.d.ts +7 -0
- package/dist/cjs/schemas/index.d.ts.map +1 -0
- package/dist/cjs/schemas/index.js +30 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/schemas/search.d.ts +184 -0
- package/dist/cjs/schemas/search.d.ts.map +1 -0
- package/dist/cjs/schemas/search.js +75 -0
- package/dist/cjs/schemas/search.js.map +1 -0
- package/dist/esm/clients/compression.d.ts +137 -0
- package/dist/esm/clients/compression.d.ts.map +1 -0
- package/dist/esm/clients/compression.js +216 -0
- package/dist/esm/clients/compression.js.map +1 -0
- package/dist/esm/clients/index.d.ts +2 -0
- package/dist/esm/clients/index.d.ts.map +1 -0
- package/dist/esm/clients/index.js +2 -0
- package/dist/esm/clients/index.js.map +1 -0
- package/dist/esm/config/constants.d.ts +61 -0
- package/dist/esm/config/constants.d.ts.map +1 -0
- package/dist/esm/config/constants.js +74 -0
- package/dist/esm/config/constants.js.map +1 -0
- package/dist/esm/config/endpoints.d.ts +18 -0
- package/dist/esm/config/endpoints.d.ts.map +1 -0
- package/dist/esm/config/endpoints.js +22 -0
- package/dist/esm/config/endpoints.js.map +1 -0
- package/dist/esm/config/index.d.ts +3 -0
- package/dist/esm/config/index.d.ts.map +1 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/index.js.map +1 -0
- package/dist/esm/errors/exceptions.d.ts +72 -0
- package/dist/esm/errors/exceptions.d.ts.map +1 -0
- package/dist/esm/errors/exceptions.js +96 -0
- package/dist/esm/errors/exceptions.js.map +1 -0
- package/dist/esm/errors/index.d.ts +2 -0
- package/dist/esm/errors/index.d.ts.map +1 -0
- package/dist/esm/errors/index.js +2 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/http/client.d.ts +53 -0
- package/dist/esm/http/client.d.ts.map +1 -0
- package/dist/esm/http/client.js +264 -0
- package/dist/esm/http/client.js.map +1 -0
- package/dist/esm/http/errors.d.ts +19 -0
- package/dist/esm/http/errors.d.ts.map +1 -0
- package/dist/esm/http/errors.js +84 -0
- package/dist/esm/http/errors.js.map +1 -0
- package/dist/esm/http/index.d.ts +3 -0
- package/dist/esm/http/index.d.ts.map +1 -0
- package/dist/esm/http/index.js +3 -0
- package/dist/esm/http/index.js.map +1 -0
- package/dist/esm/index.d.ts +33 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +36 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/schemas/common.d.ts +47 -0
- package/dist/esm/schemas/common.d.ts.map +1 -0
- package/dist/esm/schemas/common.js +26 -0
- package/dist/esm/schemas/common.js.map +1 -0
- package/dist/esm/schemas/compression.d.ts +378 -0
- package/dist/esm/schemas/compression.d.ts.map +1 -0
- package/dist/esm/schemas/compression.js +96 -0
- package/dist/esm/schemas/compression.js.map +1 -0
- package/dist/esm/schemas/index.d.ts +7 -0
- package/dist/esm/schemas/index.d.ts.map +1 -0
- package/dist/esm/schemas/index.js +10 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/schemas/search.d.ts +184 -0
- package/dist/esm/schemas/search.d.ts.map +1 -0
- package/dist/esm/schemas/search.js +72 -0
- package/dist/esm/schemas/search.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base HTTP client for Compresr API
|
|
6
|
+
*
|
|
7
|
+
* Uses native fetch API for Node.js 18+ and browser compatibility.
|
|
8
|
+
*/
|
|
9
|
+
const constants_js_1 = require("../config/constants.js");
|
|
10
|
+
const index_js_1 = require("../errors/index.js");
|
|
11
|
+
const errors_js_1 = require("./errors.js");
|
|
12
|
+
const SDK_VERSION = '1.0.0';
|
|
13
|
+
/**
|
|
14
|
+
* Internal HTTP client for all Compresr API requests
|
|
15
|
+
*/
|
|
16
|
+
class HttpClient {
|
|
17
|
+
apiKey;
|
|
18
|
+
baseUrl;
|
|
19
|
+
timeout;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
// Validate API key
|
|
22
|
+
if (!options.apiKey) {
|
|
23
|
+
throw new index_js_1.AuthenticationError('API key is required');
|
|
24
|
+
}
|
|
25
|
+
if (!options.apiKey.startsWith(constants_js_1.API_KEY_PREFIX)) {
|
|
26
|
+
throw new index_js_1.AuthenticationError(`Invalid API key format. Keys must start with '${constants_js_1.API_KEY_PREFIX}'`);
|
|
27
|
+
}
|
|
28
|
+
this.apiKey = options.apiKey;
|
|
29
|
+
this.baseUrl = options.baseUrl ?? constants_js_1.DEFAULT_BASE_URL;
|
|
30
|
+
this.timeout = options.timeout ?? constants_js_1.DEFAULT_TIMEOUT;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get default headers for requests
|
|
34
|
+
*/
|
|
35
|
+
get headers() {
|
|
36
|
+
return {
|
|
37
|
+
[constants_js_1.HEADERS.API_KEY]: this.apiKey,
|
|
38
|
+
[constants_js_1.HEADERS.CONTENT_TYPE]: 'application/json',
|
|
39
|
+
[constants_js_1.HEADERS.ACCEPT]: 'application/json',
|
|
40
|
+
[constants_js_1.HEADERS.USER_AGENT]: `compresr-typescript-sdk/${SDK_VERSION}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build full URL from endpoint
|
|
45
|
+
*/
|
|
46
|
+
url(endpoint) {
|
|
47
|
+
return `${this.baseUrl}${endpoint}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Make a POST request
|
|
51
|
+
*/
|
|
52
|
+
async post(endpoint, data) {
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
55
|
+
try {
|
|
56
|
+
const response = await fetch(this.url(endpoint), {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: this.headers,
|
|
59
|
+
body: JSON.stringify(data),
|
|
60
|
+
signal: controller.signal,
|
|
61
|
+
});
|
|
62
|
+
const body = (await response.json());
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
(0, errors_js_1.handleHttpError)(response.status, body);
|
|
65
|
+
}
|
|
66
|
+
return body;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof index_js_1.CompresrError) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
if (error instanceof Error) {
|
|
73
|
+
if (error.name === 'AbortError') {
|
|
74
|
+
throw new index_js_1.ConnectionError('Request timed out');
|
|
75
|
+
}
|
|
76
|
+
throw new index_js_1.ConnectionError(`Connection failed: ${error.message}`);
|
|
77
|
+
}
|
|
78
|
+
throw new index_js_1.CompresrError(`Request failed: ${String(error)}`);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
clearTimeout(timeoutId);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Make a GET request
|
|
86
|
+
*/
|
|
87
|
+
async get(endpoint) {
|
|
88
|
+
const controller = new AbortController();
|
|
89
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
90
|
+
try {
|
|
91
|
+
const response = await fetch(this.url(endpoint), {
|
|
92
|
+
method: 'GET',
|
|
93
|
+
headers: this.headers,
|
|
94
|
+
signal: controller.signal,
|
|
95
|
+
});
|
|
96
|
+
const body = (await response.json());
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
(0, errors_js_1.handleHttpError)(response.status, body);
|
|
99
|
+
}
|
|
100
|
+
return body;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof index_js_1.CompresrError) {
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
if (error instanceof Error) {
|
|
107
|
+
if (error.name === 'AbortError') {
|
|
108
|
+
throw new index_js_1.ConnectionError('Request timed out');
|
|
109
|
+
}
|
|
110
|
+
throw new index_js_1.ConnectionError(`Connection failed: ${error.message}`);
|
|
111
|
+
}
|
|
112
|
+
throw new index_js_1.CompresrError(`Request failed: ${String(error)}`);
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
clearTimeout(timeoutId);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Make a DELETE request
|
|
120
|
+
*/
|
|
121
|
+
async delete(endpoint) {
|
|
122
|
+
const controller = new AbortController();
|
|
123
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetch(this.url(endpoint), {
|
|
126
|
+
method: 'DELETE',
|
|
127
|
+
headers: this.headers,
|
|
128
|
+
signal: controller.signal,
|
|
129
|
+
});
|
|
130
|
+
const body = (await response.json());
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
(0, errors_js_1.handleHttpError)(response.status, body);
|
|
133
|
+
}
|
|
134
|
+
return body;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error instanceof index_js_1.CompresrError) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
if (error instanceof Error) {
|
|
141
|
+
if (error.name === 'AbortError') {
|
|
142
|
+
throw new index_js_1.ConnectionError('Request timed out');
|
|
143
|
+
}
|
|
144
|
+
throw new index_js_1.ConnectionError(`Connection failed: ${error.message}`);
|
|
145
|
+
}
|
|
146
|
+
throw new index_js_1.CompresrError(`Request failed: ${String(error)}`);
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
clearTimeout(timeoutId);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Stream response from SSE endpoint
|
|
154
|
+
*/
|
|
155
|
+
async *stream(endpoint, data) {
|
|
156
|
+
const controller = new AbortController();
|
|
157
|
+
const timeoutId = setTimeout(() => controller.abort(), constants_js_1.STREAM_TIMEOUT);
|
|
158
|
+
try {
|
|
159
|
+
const response = await fetch(this.url(endpoint), {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
headers: {
|
|
162
|
+
...this.headers,
|
|
163
|
+
[constants_js_1.HEADERS.ACCEPT]: 'text/event-stream',
|
|
164
|
+
},
|
|
165
|
+
body: JSON.stringify(data),
|
|
166
|
+
signal: controller.signal,
|
|
167
|
+
});
|
|
168
|
+
if (!response.ok) {
|
|
169
|
+
const body = (await response.json());
|
|
170
|
+
(0, errors_js_1.handleHttpError)(response.status, body);
|
|
171
|
+
}
|
|
172
|
+
if (!response.body) {
|
|
173
|
+
throw new index_js_1.CompresrError('No response body for stream');
|
|
174
|
+
}
|
|
175
|
+
const reader = response.body.getReader();
|
|
176
|
+
const decoder = new TextDecoder();
|
|
177
|
+
let buffer = '';
|
|
178
|
+
while (true) {
|
|
179
|
+
const { done, value } = await reader.read();
|
|
180
|
+
if (done)
|
|
181
|
+
break;
|
|
182
|
+
buffer += decoder.decode(value, { stream: true });
|
|
183
|
+
const lines = buffer.split('\n');
|
|
184
|
+
buffer = lines.pop() ?? '';
|
|
185
|
+
for (const line of lines) {
|
|
186
|
+
const trimmed = line.trim();
|
|
187
|
+
if (trimmed.startsWith('data: ')) {
|
|
188
|
+
const chunk = trimmed.slice(6);
|
|
189
|
+
if (chunk === '[DONE]') {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const parsed = JSON.parse(chunk);
|
|
194
|
+
if (parsed.content) {
|
|
195
|
+
yield parsed.content;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// Yield raw content if not JSON
|
|
200
|
+
if (chunk) {
|
|
201
|
+
yield chunk;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (error instanceof index_js_1.CompresrError) {
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
if (error instanceof Error) {
|
|
213
|
+
if (error.name === 'AbortError') {
|
|
214
|
+
throw new index_js_1.ConnectionError('Stream timed out');
|
|
215
|
+
}
|
|
216
|
+
throw new index_js_1.ConnectionError(`Stream failed: ${error.message}`);
|
|
217
|
+
}
|
|
218
|
+
throw new index_js_1.CompresrError(`Stream failed: ${String(error)}`);
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
clearTimeout(timeoutId);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Upload multipart form data (for index creation)
|
|
226
|
+
*/
|
|
227
|
+
async postMultipart(endpoint, files) {
|
|
228
|
+
const controller = new AbortController();
|
|
229
|
+
const timeoutId = setTimeout(() => controller.abort(), constants_js_1.STREAM_TIMEOUT);
|
|
230
|
+
try {
|
|
231
|
+
const formData = new FormData();
|
|
232
|
+
for (const [key, file] of Object.entries(files)) {
|
|
233
|
+
formData.append(key, file.data, file.filename);
|
|
234
|
+
}
|
|
235
|
+
const response = await fetch(this.url(endpoint), {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
headers: {
|
|
238
|
+
[constants_js_1.HEADERS.API_KEY]: this.apiKey,
|
|
239
|
+
[constants_js_1.HEADERS.USER_AGENT]: `compresr-typescript-sdk/${SDK_VERSION}`,
|
|
240
|
+
},
|
|
241
|
+
body: formData,
|
|
242
|
+
signal: controller.signal,
|
|
243
|
+
});
|
|
244
|
+
const body = (await response.json());
|
|
245
|
+
if (!response.ok) {
|
|
246
|
+
(0, errors_js_1.handleHttpError)(response.status, body);
|
|
247
|
+
}
|
|
248
|
+
return body;
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
if (error instanceof index_js_1.CompresrError) {
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
if (error instanceof Error) {
|
|
255
|
+
if (error.name === 'AbortError') {
|
|
256
|
+
throw new index_js_1.ConnectionError('Request timed out');
|
|
257
|
+
}
|
|
258
|
+
throw new index_js_1.ConnectionError(`Connection failed: ${error.message}`);
|
|
259
|
+
}
|
|
260
|
+
throw new index_js_1.CompresrError(`Request failed: ${String(error)}`);
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
clearTimeout(timeoutId);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.HttpClient = HttpClient;
|
|
268
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/http/client.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,yDAMgC;AAChC,iDAI4B;AAC5B,2CAA8D;AAE9D,MAAM,WAAW,GAAG,OAAO,CAAC;AAc5B;;GAEG;AACH,MAAa,UAAU;IACJ,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,OAAO,CAAS;IAEjC,YAAY,OAA0B;QACpC,mBAAmB;QACnB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,8BAAmB,CAAC,qBAAqB,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,6BAAc,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,8BAAmB,CAC3B,iDAAiD,6BAAc,GAAG,CACnE,C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
|
4
|
+
export interface ErrorBody {
|
|
5
|
+
error?: string;
|
|
6
|
+
detail?: string | Array<{
|
|
7
|
+
loc?: string[];
|
|
8
|
+
msg?: string;
|
|
9
|
+
}>;
|
|
10
|
+
message?: string;
|
|
11
|
+
field?: string;
|
|
12
|
+
retry_after?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Map HTTP status code and body to appropriate error class
|
|
16
|
+
* @throws Always throws an appropriate CompresrError subclass
|
|
17
|
+
*/
|
|
18
|
+
export declare function handleHttpError(status: number, body: ErrorBody): never;
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/http/errors.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAyDD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,KAAK,CAgDtE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleHttpError = handleHttpError;
|
|
4
|
+
/**
|
|
5
|
+
* HTTP error handling utilities
|
|
6
|
+
*/
|
|
7
|
+
const constants_js_1 = require("../config/constants.js");
|
|
8
|
+
const index_js_1 = require("../errors/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Convert ErrorBody to ErrorResponseData (normalizes detail to string)
|
|
11
|
+
*/
|
|
12
|
+
function normalizeErrorBody(body) {
|
|
13
|
+
let detail;
|
|
14
|
+
if (body.detail) {
|
|
15
|
+
if (Array.isArray(body.detail)) {
|
|
16
|
+
detail = body.detail
|
|
17
|
+
.map((e) => {
|
|
18
|
+
const field = e.loc?.join('.') ?? '';
|
|
19
|
+
const msg = e.msg ?? '';
|
|
20
|
+
return field ? `${field}: ${msg}` : msg;
|
|
21
|
+
})
|
|
22
|
+
.join('; ') || 'Validation error';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
detail = body.detail;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
error: body.error,
|
|
30
|
+
detail,
|
|
31
|
+
field: body.field,
|
|
32
|
+
retry_after: body.retry_after,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract user-friendly error message from API response
|
|
37
|
+
*/
|
|
38
|
+
function extractErrorMessage(body) {
|
|
39
|
+
if (body.error) {
|
|
40
|
+
return body.error;
|
|
41
|
+
}
|
|
42
|
+
if (body.detail) {
|
|
43
|
+
if (Array.isArray(body.detail)) {
|
|
44
|
+
const messages = body.detail.map((e) => {
|
|
45
|
+
const field = e.loc?.join('.') ?? '';
|
|
46
|
+
const msg = e.msg ?? '';
|
|
47
|
+
return field ? `${field}: ${msg}` : msg;
|
|
48
|
+
});
|
|
49
|
+
return messages.join('; ') || 'Validation error';
|
|
50
|
+
}
|
|
51
|
+
return body.detail;
|
|
52
|
+
}
|
|
53
|
+
if (body.message) {
|
|
54
|
+
return body.message;
|
|
55
|
+
}
|
|
56
|
+
return 'Unknown error';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Map HTTP status code and body to appropriate error class
|
|
60
|
+
* @throws Always throws an appropriate CompresrError subclass
|
|
61
|
+
*/
|
|
62
|
+
function handleHttpError(status, body) {
|
|
63
|
+
const msg = extractErrorMessage(body);
|
|
64
|
+
const normalized = normalizeErrorBody(body);
|
|
65
|
+
switch (status) {
|
|
66
|
+
case constants_js_1.STATUS_CODES.UNAUTHORIZED:
|
|
67
|
+
throw new index_js_1.AuthenticationError(`Authentication failed: ${msg}. Check your API key is valid.`, normalized);
|
|
68
|
+
case constants_js_1.STATUS_CODES.FORBIDDEN:
|
|
69
|
+
throw new index_js_1.ScopeError(`Permission denied: ${msg}. Your API key may lack the required scope.`, undefined, normalized);
|
|
70
|
+
case constants_js_1.STATUS_CODES.NOT_FOUND:
|
|
71
|
+
throw new index_js_1.NotFoundError(`Resource not found: ${msg}`, undefined, normalized);
|
|
72
|
+
case constants_js_1.STATUS_CODES.VALIDATION_ERROR:
|
|
73
|
+
throw new index_js_1.ValidationError(`Invalid request: ${msg}`, body.field, normalized);
|
|
74
|
+
case constants_js_1.STATUS_CODES.RATE_LIMITED: {
|
|
75
|
+
const retryMsg = body.retry_after
|
|
76
|
+
? ` Retry after ${body.retry_after} seconds.`
|
|
77
|
+
: '';
|
|
78
|
+
throw new index_js_1.RateLimitError(`Rate limit exceeded: ${msg}.${retryMsg}`, body.retry_after, normalized);
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
if (status >= 500) {
|
|
82
|
+
throw new index_js_1.ServerError(`Server error: ${msg}. Please try again later or contact support.`, normalized);
|
|
83
|
+
}
|
|
84
|
+
throw new index_js_1.CompresrError(`Request failed (${status}): ${msg}`, 'request_error', normalized);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/http/errors.ts"],"names":[],"mappings":";;AAqFA,0CAgDC;AArID;;GAEG;AACH,yDAAsD;AACtD,iDAS4B;AAa5B;;GAEG;AACH,SAAS,kBAAkB,CAAC,IAAe;IACzC,IAAI,MAA0B,CAAC;IAE/B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,KA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wB,GAAG,IAAI,QAAQ,EAAE,EACzC,IAAI,CAAC,WAAW,EAChB,UAAU,CACX,CAAC;QACJ,CAAC;QAED;YACE,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;gBAClB,MAAM,IAAI,sBAAW,CACnB,iBAAiB,GAAG,8CAA8C,EAClE,UAAU,CACX,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,wBAAa,CACrB,mBAAmB,MAAM,MAAM,GAAG,EAAE,EACpC,eAAe,EACf,UAAU,CACX,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleHttpError = exports.HttpClient = void 0;
|
|
4
|
+
var client_js_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return client_js_1.HttpClient; } });
|
|
6
|
+
var errors_js_1 = require("./errors.js");
|
|
7
|
+
Object.defineProperty(exports, "handleHttpError", { enumerable: true, get: function () { return errors_js_1.handleHttpError; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http/index.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AAAxD,uGAAA,UAAU,OAAA;AACnB,yCAA8D;AAArD,4GAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compresr TypeScript SDK
|
|
3
|
+
*
|
|
4
|
+
* Intelligent context compression to reduce LLM API costs by 30-70%.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { CompressionClient, MODELS } from 'compresr';
|
|
9
|
+
*
|
|
10
|
+
* const client = new CompressionClient({ apiKey: 'cmp_...' });
|
|
11
|
+
*
|
|
12
|
+
* // Agnostic compression (espresso_v1, default)
|
|
13
|
+
* const result = await client.compress({
|
|
14
|
+
* context: 'Your long context...',
|
|
15
|
+
* });
|
|
16
|
+
* console.log(result.data.compressed_context);
|
|
17
|
+
*
|
|
18
|
+
* // Query-specific compression (latte_v1)
|
|
19
|
+
* const result = await client.compress({
|
|
20
|
+
* context: 'Your long context...',
|
|
21
|
+
* query: 'What is the main conclusion?',
|
|
22
|
+
* compressionModelName: 'latte_v1',
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @packageDocumentation
|
|
27
|
+
*/
|
|
28
|
+
export { CompressionClient, type CompressOptions, type CompressBatchOptions, } from './clients/index.js';
|
|
29
|
+
export { MODELS, type CompressionModel } from './config/index.js';
|
|
30
|
+
export { CompresrError, AuthenticationError, ValidationError, RateLimitError, ScopeError, ServerError, ConnectionError, NotFoundError, type ErrorResponseData, } from './errors/index.js';
|
|
31
|
+
export { type CompressResponse, type CompressResult, type CompressBatchResponse, type CompressBatchResult, type CompressBatchItemResult, type StreamChunk, } from './schemas/index.js';
|
|
32
|
+
export declare const VERSION = "1.0.0";
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EACL,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,MAAM,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGlE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,EACV,WAAW,EACX,eAAe,EACf,aAAa,EACb,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Compresr TypeScript SDK
|
|
4
|
+
*
|
|
5
|
+
* Intelligent context compression to reduce LLM API costs by 30-70%.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { CompressionClient, MODELS } from 'compresr';
|
|
10
|
+
*
|
|
11
|
+
* const client = new CompressionClient({ apiKey: 'cmp_...' });
|
|
12
|
+
*
|
|
13
|
+
* // Agnostic compression (espresso_v1, default)
|
|
14
|
+
* const result = await client.compress({
|
|
15
|
+
* context: 'Your long context...',
|
|
16
|
+
* });
|
|
17
|
+
* console.log(result.data.compressed_context);
|
|
18
|
+
*
|
|
19
|
+
* // Query-specific compression (latte_v1)
|
|
20
|
+
* const result = await client.compress({
|
|
21
|
+
* context: 'Your long context...',
|
|
22
|
+
* query: 'What is the main conclusion?',
|
|
23
|
+
* compressionModelName: 'latte_v1',
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.VERSION = exports.NotFoundError = exports.ConnectionError = exports.ServerError = exports.ScopeError = exports.RateLimitError = exports.ValidationError = exports.AuthenticationError = exports.CompresrError = exports.MODELS = exports.CompressionClient = void 0;
|
|
31
|
+
// Clients
|
|
32
|
+
var index_js_1 = require("./clients/index.js");
|
|
33
|
+
Object.defineProperty(exports, "CompressionClient", { enumerable: true, get: function () { return index_js_1.CompressionClient; } });
|
|
34
|
+
// Configuration
|
|
35
|
+
var index_js_2 = require("./config/index.js");
|
|
36
|
+
Object.defineProperty(exports, "MODELS", { enumerable: true, get: function () { return index_js_2.MODELS; } });
|
|
37
|
+
// Errors
|
|
38
|
+
var index_js_3 = require("./errors/index.js");
|
|
39
|
+
Object.defineProperty(exports, "CompresrError", { enumerable: true, get: function () { return index_js_3.CompresrError; } });
|
|
40
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return index_js_3.AuthenticationError; } });
|
|
41
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return index_js_3.ValidationError; } });
|
|
42
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return index_js_3.RateLimitError; } });
|
|
43
|
+
Object.defineProperty(exports, "ScopeError", { enumerable: true, get: function () { return index_js_3.ScopeError; } });
|
|
44
|
+
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return index_js_3.ServerError; } });
|
|
45
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return index_js_3.ConnectionError; } });
|
|
46
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return index_js_3.NotFoundError; } });
|
|
47
|
+
// Version
|
|
48
|
+
exports.VERSION = '1.0.0';
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,UAAU;AACV,+CAI4B;AAH1B,6GAAA,iBAAiB,OAAA;AAKnB,gBAAgB;AAChB,8CAAkE;AAAzD,kGAAA,MAAM,OAAA;AAEf,SAAS;AACT,8CAU2B;AATzB,yGAAA,aAAa,OAAA;AACb,+GAAA,mBAAmB,OAAA;AACnB,2GAAA,eAAe,OAAA;AACf,0GAAA,cAAc,OAAA;AACd,sGAAA,UAAU,OAAA;AACV,uGAAA,WAAW,OAAA;AACX,2GAAA,eAAe,OAAA;AACf,yGAAA,aAAa,OAAA;AAcf,UAAU;AACG,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common/shared schemas
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* Base API response schema
|
|
7
|
+
*/
|
|
8
|
+
export declare const BaseResponseSchema: z.ZodObject<{
|
|
9
|
+
success: z.ZodBoolean;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
success: boolean;
|
|
12
|
+
}, {
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export type BaseResponse = z.infer<typeof BaseResponseSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* Stream chunk schema for SSE responses
|
|
18
|
+
*/
|
|
19
|
+
export declare const StreamChunkSchema: z.ZodObject<{
|
|
20
|
+
content: z.ZodString;
|
|
21
|
+
done: z.ZodDefault<z.ZodBoolean>;
|
|
22
|
+
error: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
done: boolean;
|
|
25
|
+
content: string;
|
|
26
|
+
error?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
content: string;
|
|
29
|
+
error?: string | undefined;
|
|
30
|
+
done?: boolean | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export type StreamChunk = z.infer<typeof StreamChunkSchema>;
|
|
33
|
+
/**
|
|
34
|
+
* Health check response
|
|
35
|
+
*/
|
|
36
|
+
export declare const HealthResponseSchema: z.ZodObject<{
|
|
37
|
+
status: z.ZodString;
|
|
38
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
status: string;
|
|
41
|
+
timestamp?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
status: string;
|
|
44
|
+
timestamp?: string | undefined;
|
|
45
|
+
}>;
|
|
46
|
+
export type HealthResponse = z.infer<typeof HealthResponseSchema>;
|
|
47
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/schemas/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;EAE7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;EAI5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;EAG/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HealthResponseSchema = exports.StreamChunkSchema = exports.BaseResponseSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Common/shared schemas
|
|
6
|
+
*/
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
/**
|
|
9
|
+
* Base API response schema
|
|
10
|
+
*/
|
|
11
|
+
exports.BaseResponseSchema = zod_1.z.object({
|
|
12
|
+
success: zod_1.z.boolean(),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Stream chunk schema for SSE responses
|
|
16
|
+
*/
|
|
17
|
+
exports.StreamChunkSchema = zod_1.z.object({
|
|
18
|
+
content: zod_1.z.string(),
|
|
19
|
+
done: zod_1.z.boolean().default(false),
|
|
20
|
+
error: zod_1.z.string().optional(),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Health check response
|
|
24
|
+
*/
|
|
25
|
+
exports.HealthResponseSchema = zod_1.z.object({
|
|
26
|
+
status: zod_1.z.string(),
|
|
27
|
+
timestamp: zod_1.z.string().optional(),
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/schemas/common.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,6BAAwB;AAExB;;GAEG;AACU,QAAA,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE;CACrB,CAAC,CAAC;AAIH;;GAEG;AACU,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAChC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7B,CAAC,CAAC;AAIH;;GAEG;AACU,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC"}
|