conare 0.13.0 → 0.13.1

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.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.13.0";
1
+ export declare const VERSION = "0.13.1";
2
2
  /** A metadata value: string, number, boolean or an array of strings. */
3
3
  export type MetadataValue = string | number | boolean | string[];
4
4
  export type Metadata = Record<string, MetadataValue>;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // conare: TypeScript client for the Conare API. Zero dependencies; uses global fetch.
2
- export const VERSION = "0.13.0";
2
+ export const VERSION = "0.13.1";
3
3
  const DEFAULT_BASE_URL = "https://api.conare.ai";
4
4
  const BATCH_SIZE = 100;
5
5
  // ---- Errors ----------------------------------------------------------------
@@ -16,6 +16,18 @@ export class ConareError extends Error {
16
16
  this.requestId = requestId;
17
17
  }
18
18
  }
19
+ /**
20
+ * One path segment (a namespace, document id or source id), percent-encoded. A value holding "/"
21
+ * or "\\", or one that is "." or "..", is refused here: the API's ingress decodes %2F and resolves
22
+ * dot segments before routing, so such a value would reach another route, even another namespace.
23
+ * No valid name or id contains them.
24
+ */
25
+ function segment(value) {
26
+ if (/[\\/]/.test(value) || value === "." || value === "..") {
27
+ throw new ConareError(400, "invalid_id", `${JSON.stringify(value)} cannot be a path segment: it holds "/" or "\\" or is a dot segment.`);
28
+ }
29
+ return encodeURIComponent(value);
30
+ }
19
31
  // ---- Client ----------------------------------------------------------------
20
32
  /**
21
33
  * The Conare client.
@@ -148,7 +160,7 @@ export class Namespace {
148
160
  this.name = name;
149
161
  }
150
162
  path(suffix = "") {
151
- return `/namespaces/${encodeURIComponent(this.name)}${suffix}`;
163
+ return `/namespaces/${segment(this.name)}${suffix}`;
152
164
  }
153
165
  /**
154
166
  * Create the namespace before its first write. Only a namespace with a sparse (SPLADE) index
@@ -185,7 +197,7 @@ export class Namespace {
185
197
  /** One document by id, or null if it does not exist. */
186
198
  async get(id, options) {
187
199
  try {
188
- const d = await this.client.request("GET", this.path(`/documents/${encodeURIComponent(id)}`), undefined, options);
200
+ const d = await this.client.request("GET", this.path(`/documents/${segment(id)}`), undefined, options);
189
201
  return { id: d.id, text: d.text, metadata: d.metadata, updatedAt: new Date(d.updated_at) };
190
202
  }
191
203
  catch (err) {
@@ -213,7 +225,7 @@ export class Namespace {
213
225
  }
214
226
  /** Delete one document. Throws a ConareError with status 404 (`document_not_found`) if it does not exist. */
215
227
  async delete(id, options) {
216
- await this.client.request("DELETE", this.path(`/documents/${encodeURIComponent(id)}`), undefined, options);
228
+ await this.client.request("DELETE", this.path(`/documents/${segment(id)}`), undefined, options);
217
229
  }
218
230
  /** Delete up to 1000 documents by id in one call. Ids that do not exist are skipped. Returns how many were deleted. */
219
231
  async deleteMany(ids, options) {
@@ -257,16 +269,16 @@ export class Sources {
257
269
  }
258
270
  /** One source by id. */
259
271
  async get(id, options) {
260
- return toSource(await this.client.request("GET", `/sources/${encodeURIComponent(id)}`, undefined, options));
272
+ return toSource(await this.client.request("GET", `/sources/${segment(id)}`, undefined, options));
261
273
  }
262
274
  /** Start a sync now. */
263
275
  async sync(id, options) {
264
- return toSource(await this.client.request("POST", `/sources/${encodeURIComponent(id)}/sync`, undefined, options, true));
276
+ return toSource(await this.client.request("POST", `/sources/${segment(id)}/sync`, undefined, options, true));
265
277
  }
266
278
  /** Disconnect a source. Pass `deleteDocuments: true` to also delete what it synced. */
267
279
  async delete(id, options = {}) {
268
280
  const qs = options.deleteDocuments ? "?delete_documents=true" : "";
269
- await this.client.request("DELETE", `/sources/${encodeURIComponent(id)}${qs}`, undefined, options);
281
+ await this.client.request("DELETE", `/sources/${segment(id)}${qs}`, undefined, options);
270
282
  }
271
283
  /** The apps you can connect. */
272
284
  async types(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conare",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "TypeScript client for Conare: add documents, query them, connect apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",