xmemory 2.1.0 → 2.1.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/README.md CHANGED
@@ -15,7 +15,7 @@ import { XmemoryClient } from "xmemory";
15
15
 
16
16
  const xm = new XmemoryClient({
17
17
  url: "https://api.xmemory.ai", // or set XMEM_API_URL env var
18
- token: "<your-token>", // or set XMEM_AUTH_TOKEN env var
18
+ apiKey: "<your-api-key>", // or set XMEM_API_KEY env var
19
19
  });
20
20
 
21
21
  // Write and read from an existing instance
@@ -28,11 +28,13 @@ console.log(result.reader_result);
28
28
 
29
29
  ## Configuration
30
30
 
31
- | Parameter | Env var | Default | Description |
32
- |-------------|-------------------|----------------------------|----------------------------------------|
33
- | `url` | `XMEM_API_URL` | `https://api.xmemory.ai` | Base URL of the Xmemory API |
34
- | `token` | `XMEM_AUTH_TOKEN` | `undefined` | Bearer token for authentication |
35
- | `timeoutMs` | — | `60000` | Default request timeout in milliseconds |
31
+ | Parameter | Env var | Default | Description |
32
+ |-------------|------------------|---------------------------|-----------------------------------------|
33
+ | `url` | `XMEM_API_URL` | `https://api.xmemory.ai` | Base URL of the Xmemory API |
34
+ | `apiKey` | `XMEM_API_KEY` | `undefined` | Bearer API key for authentication |
35
+ | `timeoutMs` | — | `60000` | Default request timeout in milliseconds |
36
+
37
+ The legacy `token` option and `XMEM_AUTH_TOKEN` env var are still accepted for backwards compatibility but are deprecated and will be removed in a future release. Using them prints a deprecation warning. If both the new and legacy values are set, the new ones win.
36
38
 
37
39
  ## Creating a client
38
40
 
@@ -40,13 +42,13 @@ console.log(result.reader_result);
40
42
  import { XmemoryClient, xmemoryInstance } from "xmemory";
41
43
 
42
44
  // Option 1: constructor (no health check)
43
- const xm1 = new XmemoryClient({ token: "..." });
45
+ const xm1 = new XmemoryClient({ apiKey: "..." });
44
46
 
45
47
  // Option 2: factory with health check
46
- const xm2 = await XmemoryClient.create({ token: "..." });
48
+ const xm2 = await XmemoryClient.create({ apiKey: "..." });
47
49
 
48
50
  // Option 3: convenience function (same as Option 2)
49
- const xm3 = await xmemoryInstance({ token: "..." });
51
+ const xm3 = await xmemoryInstance({ apiKey: "..." });
50
52
  ```
51
53
 
52
54
  ## Admin operations
@@ -189,7 +191,7 @@ All errors throw `XmemoryAPIError`. Health check failures throw `XmemoryHealthCh
189
191
  import { XmemoryClient, XmemoryAPIError, XmemoryHealthCheckError } from "xmemory";
190
192
 
191
193
  try {
192
- const xm = await XmemoryClient.create({ token: "..." });
194
+ const xm = await XmemoryClient.create({ apiKey: "..." });
193
195
  } catch (e) {
194
196
  if (e instanceof XmemoryHealthCheckError) {
195
197
  console.error("Server unreachable:", e.message);
package/dist/client.d.ts CHANGED
@@ -22,9 +22,10 @@ export interface AdminNamespace {
22
22
  export declare class XmemoryClient {
23
23
  private readonly _baseUrl;
24
24
  private readonly _timeoutMs;
25
- private readonly _token;
25
+ private readonly _apiKey;
26
26
  readonly admin: AdminNamespace;
27
27
  constructor(options?: XmemoryClientOptions);
28
+ private static _resolveApiKey;
28
29
  /** Factory that performs a health check before returning the client. */
29
30
  static create(options?: XmemoryClientOptions): Promise<XmemoryClient>;
30
31
  /** Return an InstanceHandle scoped to the given instance ID. */
package/dist/client.js CHANGED
@@ -5,21 +5,41 @@ import { InstanceHandle } from "./instance.js";
5
5
  import { XmemoryAPIError, XmemoryHealthCheckError, buildInstanceSchema, } from "./types.js";
6
6
  const DEFAULT_BASE_URL = "https://api.xmemory.ai";
7
7
  const DEFAULT_TIMEOUT_MS = 60_000;
8
+ const ORANGE = "\x1b[38;5;208m";
9
+ const RESET = "\x1b[0m";
10
+ function deprecationWarning(message) {
11
+ console.warn(`${ORANGE}[xmemory] DEPRECATION: ${message}${RESET}`);
12
+ }
8
13
  // ---------------------------------------------------------------------------
9
14
  // Client
10
15
  // ---------------------------------------------------------------------------
11
16
  export class XmemoryClient {
12
17
  _baseUrl;
13
18
  _timeoutMs;
14
- _token;
19
+ _apiKey;
15
20
  admin;
16
21
  constructor(options = {}) {
17
22
  const env = typeof process !== "undefined" ? process.env : undefined;
18
23
  this._baseUrl = (options.url ?? env?.XMEM_API_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
19
- this._token = options.token ?? env?.XMEM_AUTH_TOKEN;
24
+ this._apiKey = XmemoryClient._resolveApiKey(options, env);
20
25
  this._timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
21
26
  this.admin = this._buildAdmin();
22
27
  }
28
+ static _resolveApiKey(options, env) {
29
+ if (options.apiKey != null)
30
+ return options.apiKey;
31
+ if (options.token != null) {
32
+ deprecationWarning("The `token` constructor option is deprecated and will be removed soon. Use `apiKey` instead.");
33
+ return options.token;
34
+ }
35
+ if (env?.XMEM_API_KEY)
36
+ return env.XMEM_API_KEY;
37
+ if (env?.XMEM_AUTH_TOKEN) {
38
+ deprecationWarning("The `XMEM_AUTH_TOKEN` environment variable is deprecated and will be removed soon. Use `XMEM_API_KEY` instead.");
39
+ return env.XMEM_AUTH_TOKEN;
40
+ }
41
+ return undefined;
42
+ }
23
43
  /** Factory that performs a health check before returning the client. */
24
44
  static async create(options = {}) {
25
45
  const client = new XmemoryClient(options);
@@ -64,8 +84,8 @@ export class XmemoryClient {
64
84
  };
65
85
  if (hasBody)
66
86
  h["Content-Type"] = "application/json";
67
- if (this._token)
68
- h["Authorization"] = `Bearer ${this._token}`;
87
+ if (this._apiKey)
88
+ h["Authorization"] = `Bearer ${this._apiKey}`;
69
89
  return h;
70
90
  }
71
91
  /** Core request — returns the raw API wrapper `{ids, items, errors}`. */
package/dist/types.d.ts CHANGED
@@ -82,6 +82,8 @@ export interface RawDescribeResult {
82
82
  }
83
83
  export interface XmemoryClientOptions {
84
84
  url?: string;
85
+ apiKey?: string;
86
+ /** @deprecated Use `apiKey` instead. Will be removed in a future release. */
85
87
  token?: string;
86
88
  timeoutMs?: number;
87
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmemory",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "xmemory",
5
5
  "keywords": [
6
6
  "xmemory"