ebay-mcp-remote-edition 2.0.11 → 2.0.13

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.
@@ -1,4 +1,36 @@
1
1
  import axios from 'axios';
2
+ /**
3
+ * Purely in-memory KV store with optional per-entry TTL.
4
+ * Useful for local development, single-user setups, or when
5
+ * EBAY_TOKEN_STORE_BACKEND=memory.
6
+ * All data is lost on process restart.
7
+ */
8
+ export class InMemoryKVStore {
9
+ store = new Map();
10
+ async get(key) {
11
+ const entry = this.store.get(key);
12
+ if (!entry)
13
+ return null;
14
+ if (entry.expiresAt !== undefined && Date.now() > entry.expiresAt) {
15
+ this.store.delete(key);
16
+ return null;
17
+ }
18
+ return entry.value;
19
+ }
20
+ async put(key, value, expirationTtl) {
21
+ this.store.set(key, {
22
+ value,
23
+ expiresAt: expirationTtl !== undefined ? Date.now() + expirationTtl * 1_000 : undefined,
24
+ });
25
+ }
26
+ async delete(key) {
27
+ this.store.delete(key);
28
+ }
29
+ }
30
+ /**
31
+ * Cloudflare KV REST API backend with an in-memory read-through cache.
32
+ * Used when EBAY_TOKEN_STORE_BACKEND=cloudflare-kv (the default for hosted deployments).
33
+ */
2
34
  export class CloudflareKVStore {
3
35
  client;
4
36
  accountId;
@@ -52,9 +84,7 @@ export class CloudflareKVStore {
52
84
  await this.client.put(`/values/${encodeURIComponent(key)}`, JSON.stringify(value), { params });
53
85
  // Keep the in-memory cache consistent with what we wrote.
54
86
  // If the KV entry has its own TTL, honour it for the cache as well.
55
- const cacheTtl = expirationTtl
56
- ? Math.min(expirationTtl * 1_000, this.cacheTtlMs)
57
- : this.cacheTtlMs;
87
+ const cacheTtl = expirationTtl ? Math.min(expirationTtl * 1_000, this.cacheTtlMs) : this.cacheTtlMs;
58
88
  this.cache.set(key, { value, expiresAt: Date.now() + cacheTtl });
59
89
  }
60
90
  async delete(key) {
@@ -70,3 +100,33 @@ export class CloudflareKVStore {
70
100
  this.cache.clear();
71
101
  }
72
102
  }
103
+ // ── Factory ───────────────────────────────────────────────────────────────────
104
+ /**
105
+ * Returns the appropriate KV store backend based on the EBAY_TOKEN_STORE_BACKEND
106
+ * environment variable:
107
+ *
108
+ * memory → InMemoryKVStore (no external dependencies, data lost on restart)
109
+ * cloudflare-kv → CloudflareKVStore (default; requires CLOUDFLARE_* env vars)
110
+ *
111
+ * If the variable is unset or unrecognised, defaults to cloudflare-kv so that
112
+ * existing hosted deployments continue to work without any config change.
113
+ */
114
+ export function createKVStore() {
115
+ const rawEnv = process.env.EBAY_TOKEN_STORE_BACKEND;
116
+ const backend = (rawEnv ?? 'cloudflare-kv').toLowerCase().trim();
117
+ // Always log to stdout so the chosen backend is visible in server logs.
118
+ // This runs once at startup when MultiUserAuthStore is first instantiated.
119
+ switch (backend) {
120
+ case 'memory':
121
+ case 'in-memory': {
122
+ console.log(`[kv-store] EBAY_TOKEN_STORE_BACKEND="${rawEnv ?? ''}" → using InMemoryKVStore (no external KV calls)`);
123
+ return new InMemoryKVStore();
124
+ }
125
+ case 'cloudflare-kv':
126
+ case 'cloudflare':
127
+ default: {
128
+ console.log(`[kv-store] EBAY_TOKEN_STORE_BACKEND="${rawEnv ?? '(unset)'}" → using CloudflareKVStore (accountId="${process.env.CLOUDFLARE_ACCOUNT_ID ?? '(unset)'}") — set EBAY_TOKEN_STORE_BACKEND=memory to disable`);
129
+ return new CloudflareKVStore();
130
+ }
131
+ }
132
+ }
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from 'crypto';
2
- import { CloudflareKVStore } from '../auth/kv-store.js';
2
+ import { createKVStore } from '../auth/kv-store.js';
3
3
  export class MultiUserAuthStore {
4
- kv = new CloudflareKVStore();
4
+ kv = createKVStore();
5
5
  /**
6
6
  * In-memory map of sessionToken → timestamp of last KV write for touchSession.
7
7
  * Prevents a KV PUT on every single authenticated request — we only persist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ebay-mcp-remote-edition",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "Remote + Local MCP server for eBay APIs - provides access to eBay developer functionality through MCP (Model Context Protocol)",
5
5
  "type": "module",
6
6
  "main": "build/index.js",