@localess/js-client 0.9.1-next.20260119-221431.0 → 0.9.2-next.20260125-093607.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/dist/index.d.mts CHANGED
@@ -194,6 +194,11 @@ type LocalessClientOptions = {
194
194
  * Enable debug mode
195
195
  */
196
196
  debug?: boolean;
197
+ /**
198
+ * Cache TTL (time to live) for API responses. Default is 5 minutes (300000 ms).
199
+ * Set to false to disable caching.
200
+ */
201
+ cacheTTL?: number | false;
197
202
  };
198
203
  type LinksFetchParams = {
199
204
  /**
package/dist/index.d.ts CHANGED
@@ -194,6 +194,11 @@ type LocalessClientOptions = {
194
194
  * Enable debug mode
195
195
  */
196
196
  debug?: boolean;
197
+ /**
198
+ * Cache TTL (time to live) for API responses. Default is 5 minutes (300000 ms).
199
+ * Set to false to disable caching.
200
+ */
201
+ cacheTTL?: number | false;
197
202
  };
198
203
  type LinksFetchParams = {
199
204
  /**
package/dist/index.js CHANGED
@@ -39,6 +39,44 @@ var isBrowser = () => typeof window !== "undefined";
39
39
  var isServer = () => typeof window === "undefined";
40
40
  var isIframe = () => isBrowser() && window.self !== window.top;
41
41
 
42
+ // src/cache.ts
43
+ var NoCache = class {
44
+ set(key, value) {
45
+ }
46
+ get(key) {
47
+ return void 0;
48
+ }
49
+ has(key) {
50
+ return false;
51
+ }
52
+ };
53
+ var TTLCache = class {
54
+ /**
55
+ * Creates a TTLCache with a specified time-to-live (TTL) for each entry.
56
+ * default is 5 minutes (300000 ms).
57
+ * @param ttlMs
58
+ */
59
+ constructor(ttlMs = 3e5) {
60
+ this.ttlMs = ttlMs;
61
+ }
62
+ cache = /* @__PURE__ */ new Map();
63
+ set(key, value) {
64
+ this.cache.set(key, { value, expiresAt: Date.now() + this.ttlMs });
65
+ }
66
+ get(key) {
67
+ const entry = this.cache.get(key);
68
+ if (!entry) return void 0;
69
+ if (Date.now() > entry.expiresAt) {
70
+ this.cache.delete(key);
71
+ return void 0;
72
+ }
73
+ return entry.value;
74
+ }
75
+ has(key) {
76
+ return this.get(key) !== void 0;
77
+ }
78
+ };
79
+
42
80
  // src/client.ts
43
81
  var LOG_GROUP = `${FG_BLUE}[Localess:Client]${RESET}`;
44
82
  function localessClient(options) {
@@ -54,7 +92,7 @@ function localessClient(options) {
54
92
  "X-Localess-Agent-Version": "0.9.0"
55
93
  }
56
94
  };
57
- const cache = /* @__PURE__ */ new Map();
95
+ const cache = options.cacheTTL === false ? new NoCache() : new TTLCache(options.cacheTTL);
58
96
  return {
59
97
  async getLinks(params) {
60
98
  if (options.debug) {
package/dist/index.mjs CHANGED
@@ -5,6 +5,44 @@ var isBrowser = () => typeof window !== "undefined";
5
5
  var isServer = () => typeof window === "undefined";
6
6
  var isIframe = () => isBrowser() && window.self !== window.top;
7
7
 
8
+ // src/cache.ts
9
+ var NoCache = class {
10
+ set(key, value) {
11
+ }
12
+ get(key) {
13
+ return void 0;
14
+ }
15
+ has(key) {
16
+ return false;
17
+ }
18
+ };
19
+ var TTLCache = class {
20
+ /**
21
+ * Creates a TTLCache with a specified time-to-live (TTL) for each entry.
22
+ * default is 5 minutes (300000 ms).
23
+ * @param ttlMs
24
+ */
25
+ constructor(ttlMs = 3e5) {
26
+ this.ttlMs = ttlMs;
27
+ }
28
+ cache = /* @__PURE__ */ new Map();
29
+ set(key, value) {
30
+ this.cache.set(key, { value, expiresAt: Date.now() + this.ttlMs });
31
+ }
32
+ get(key) {
33
+ const entry = this.cache.get(key);
34
+ if (!entry) return void 0;
35
+ if (Date.now() > entry.expiresAt) {
36
+ this.cache.delete(key);
37
+ return void 0;
38
+ }
39
+ return entry.value;
40
+ }
41
+ has(key) {
42
+ return this.get(key) !== void 0;
43
+ }
44
+ };
45
+
8
46
  // src/client.ts
9
47
  var LOG_GROUP = `${FG_BLUE}[Localess:Client]${RESET}`;
10
48
  function localessClient(options) {
@@ -20,7 +58,7 @@ function localessClient(options) {
20
58
  "X-Localess-Agent-Version": "0.9.0"
21
59
  }
22
60
  };
23
- const cache = /* @__PURE__ */ new Map();
61
+ const cache = options.cacheTTL === false ? new NoCache() : new TTLCache(options.cacheTTL);
24
62
  return {
25
63
  async getLinks(params) {
26
64
  if (options.debug) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/js-client",
3
- "version": "0.9.1-next.20260119-221431.0",
3
+ "version": "0.9.2-next.20260125-093607.0",
4
4
  "description": "Universal JavaScript/TypeScript SDK for Localess's API.",
5
5
  "keywords": [
6
6
  "localess",