@localess/js-client 0.8.2-next.20250512-070343.0 → 0.8.2-next.20250615-165147.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.js CHANGED
@@ -46,6 +46,7 @@ function localessClient(options) {
46
46
  "X-Localess-Agent-Version": "0.6.0"
47
47
  }
48
48
  };
49
+ const cache = /* @__PURE__ */ new Map();
49
50
  return {
50
51
  async getLinks(params) {
51
52
  if (options.debug) {
@@ -67,12 +68,19 @@ function localessClient(options) {
67
68
  if (options.debug) {
68
69
  console.log(LOG_GROUP, "getLinks fetch url : ", url);
69
70
  }
71
+ if (cache.has(url)) {
72
+ if (options.debug) {
73
+ console.log(LOG_GROUP, "getLinks cache hit");
74
+ }
75
+ return cache.get(url);
76
+ }
70
77
  try {
71
78
  const response = await fetch(url, fetchOptions);
72
79
  if (options.debug) {
73
80
  console.log(LOG_GROUP, "getLinks status : ", response.status);
74
81
  }
75
82
  const data = await response.json();
83
+ cache.set(url, data);
76
84
  return data;
77
85
  } catch (error) {
78
86
  console.error(LOG_GROUP, "getLinks error : ", error);
@@ -96,12 +104,19 @@ function localessClient(options) {
96
104
  if (options.debug) {
97
105
  console.log(LOG_GROUP, "getContentBySlug fetch url : ", url);
98
106
  }
107
+ if (cache.has(url)) {
108
+ if (options.debug) {
109
+ console.log(LOG_GROUP, "getContentBySlug cache hit");
110
+ }
111
+ return cache.get(url);
112
+ }
99
113
  try {
100
114
  const response = await fetch(url, fetchOptions);
101
115
  if (options.debug) {
102
116
  console.log(LOG_GROUP, "getContentBySlug status : ", response.status);
103
117
  }
104
118
  const data = await response.json();
119
+ cache.set(url, data);
105
120
  return data;
106
121
  } catch (error) {
107
122
  console.error(LOG_GROUP, "getContentBySlug error : ", error);
@@ -125,12 +140,24 @@ function localessClient(options) {
125
140
  if (options.debug) {
126
141
  console.log(LOG_GROUP, "getContentById fetch url : ", url);
127
142
  }
128
- const response = await fetch(url, fetchOptions);
129
- if (options.debug) {
130
- console.log(LOG_GROUP, "getContentById status : ", response.status);
143
+ if (cache.has(url)) {
144
+ if (options.debug) {
145
+ console.log(LOG_GROUP, "getContentById cache hit");
146
+ }
147
+ return cache.get(url);
148
+ }
149
+ try {
150
+ const response = await fetch(url, fetchOptions);
151
+ if (options.debug) {
152
+ console.log(LOG_GROUP, "getContentById status : ", response.status);
153
+ }
154
+ const data = await response.json();
155
+ cache.set(url, data);
156
+ return data;
157
+ } catch (error) {
158
+ console.error(LOG_GROUP, "getContentById error : ", error);
159
+ return {};
131
160
  }
132
- const data = await response.json();
133
- return data;
134
161
  },
135
162
  async getTranslations(locale) {
136
163
  if (options.debug) {
@@ -140,12 +167,24 @@ function localessClient(options) {
140
167
  if (options.debug) {
141
168
  console.log(LOG_GROUP, "getTranslations fetch url : ", url);
142
169
  }
143
- const response = await fetch(url, fetchOptions);
144
- if (options.debug) {
145
- console.log(LOG_GROUP, "getTranslations status : ", response.status);
170
+ if (cache.has(url)) {
171
+ if (options.debug) {
172
+ console.log(LOG_GROUP, "getTranslations cache hit");
173
+ }
174
+ return cache.get(url);
175
+ }
176
+ try {
177
+ const response = await fetch(url, fetchOptions);
178
+ if (options.debug) {
179
+ console.log(LOG_GROUP, "getTranslations status : ", response.status);
180
+ }
181
+ const data = await response.json();
182
+ cache.set(url, data);
183
+ return data;
184
+ } catch (error) {
185
+ console.error(LOG_GROUP, "getTranslations error : ", error);
186
+ return {};
146
187
  }
147
- const data = await response.json();
148
- return data;
149
188
  },
150
189
  syncScriptUrl() {
151
190
  return `${options.origin}/scripts/sync-v1.js`;
package/dist/index.mjs CHANGED
@@ -17,6 +17,7 @@ function localessClient(options) {
17
17
  "X-Localess-Agent-Version": "0.6.0"
18
18
  }
19
19
  };
20
+ const cache = /* @__PURE__ */ new Map();
20
21
  return {
21
22
  async getLinks(params) {
22
23
  if (options.debug) {
@@ -38,12 +39,19 @@ function localessClient(options) {
38
39
  if (options.debug) {
39
40
  console.log(LOG_GROUP, "getLinks fetch url : ", url);
40
41
  }
42
+ if (cache.has(url)) {
43
+ if (options.debug) {
44
+ console.log(LOG_GROUP, "getLinks cache hit");
45
+ }
46
+ return cache.get(url);
47
+ }
41
48
  try {
42
49
  const response = await fetch(url, fetchOptions);
43
50
  if (options.debug) {
44
51
  console.log(LOG_GROUP, "getLinks status : ", response.status);
45
52
  }
46
53
  const data = await response.json();
54
+ cache.set(url, data);
47
55
  return data;
48
56
  } catch (error) {
49
57
  console.error(LOG_GROUP, "getLinks error : ", error);
@@ -67,12 +75,19 @@ function localessClient(options) {
67
75
  if (options.debug) {
68
76
  console.log(LOG_GROUP, "getContentBySlug fetch url : ", url);
69
77
  }
78
+ if (cache.has(url)) {
79
+ if (options.debug) {
80
+ console.log(LOG_GROUP, "getContentBySlug cache hit");
81
+ }
82
+ return cache.get(url);
83
+ }
70
84
  try {
71
85
  const response = await fetch(url, fetchOptions);
72
86
  if (options.debug) {
73
87
  console.log(LOG_GROUP, "getContentBySlug status : ", response.status);
74
88
  }
75
89
  const data = await response.json();
90
+ cache.set(url, data);
76
91
  return data;
77
92
  } catch (error) {
78
93
  console.error(LOG_GROUP, "getContentBySlug error : ", error);
@@ -96,12 +111,24 @@ function localessClient(options) {
96
111
  if (options.debug) {
97
112
  console.log(LOG_GROUP, "getContentById fetch url : ", url);
98
113
  }
99
- const response = await fetch(url, fetchOptions);
100
- if (options.debug) {
101
- console.log(LOG_GROUP, "getContentById status : ", response.status);
114
+ if (cache.has(url)) {
115
+ if (options.debug) {
116
+ console.log(LOG_GROUP, "getContentById cache hit");
117
+ }
118
+ return cache.get(url);
119
+ }
120
+ try {
121
+ const response = await fetch(url, fetchOptions);
122
+ if (options.debug) {
123
+ console.log(LOG_GROUP, "getContentById status : ", response.status);
124
+ }
125
+ const data = await response.json();
126
+ cache.set(url, data);
127
+ return data;
128
+ } catch (error) {
129
+ console.error(LOG_GROUP, "getContentById error : ", error);
130
+ return {};
102
131
  }
103
- const data = await response.json();
104
- return data;
105
132
  },
106
133
  async getTranslations(locale) {
107
134
  if (options.debug) {
@@ -111,12 +138,24 @@ function localessClient(options) {
111
138
  if (options.debug) {
112
139
  console.log(LOG_GROUP, "getTranslations fetch url : ", url);
113
140
  }
114
- const response = await fetch(url, fetchOptions);
115
- if (options.debug) {
116
- console.log(LOG_GROUP, "getTranslations status : ", response.status);
141
+ if (cache.has(url)) {
142
+ if (options.debug) {
143
+ console.log(LOG_GROUP, "getTranslations cache hit");
144
+ }
145
+ return cache.get(url);
146
+ }
147
+ try {
148
+ const response = await fetch(url, fetchOptions);
149
+ if (options.debug) {
150
+ console.log(LOG_GROUP, "getTranslations status : ", response.status);
151
+ }
152
+ const data = await response.json();
153
+ cache.set(url, data);
154
+ return data;
155
+ } catch (error) {
156
+ console.error(LOG_GROUP, "getTranslations error : ", error);
157
+ return {};
117
158
  }
118
- const data = await response.json();
119
- return data;
120
159
  },
121
160
  syncScriptUrl() {
122
161
  return `${options.origin}/scripts/sync-v1.js`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/js-client",
3
- "version": "0.8.2-next.20250512-070343.0",
3
+ "version": "0.8.2-next.20250615-165147.0",
4
4
  "description": "Universal JavaScript/TypeScript SDK for Localess's API.",
5
5
  "keywords": [
6
6
  "localess",