@zodic/shared 0.0.193 → 0.0.195

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.
@@ -71,7 +71,7 @@ export class ConceptService {
71
71
  }
72
72
 
73
73
  let attempts = 0;
74
- const maxAttempts = 3;
74
+ const maxAttempts = 2;
75
75
  let newlyGeneratedNames: string[] = []; // ✅ Track generated names in memory
76
76
 
77
77
  while (attempts < maxAttempts) {
@@ -127,8 +127,58 @@ export class ConceptService {
127
127
  // ✅ Check uniqueness before storing
128
128
  if (allNamesEN.includes(nameEN) || allNamesPT.includes(namePT)) {
129
129
  console.warn(`⚠️ Duplicate Name Detected: "${nameEN}" or "${namePT}"`);
130
- if (attempts >= maxAttempts)
131
- throw new Error(`🚨 Could not generate a unique name`);
130
+
131
+ // **On third attempt, store the name anyway & register in kvFailures**
132
+ if (attempts >= maxAttempts) {
133
+ console.log(`🚨 Max attempts reached. Storing name despite duplicate.`);
134
+
135
+ // ✅ **Register duplicate storage in KV failures**
136
+ await kvFailuresStore.put(
137
+ `failures:duplicates:${conceptSlug}:${combinationString}`,
138
+ JSON.stringify({
139
+ nameEN,
140
+ namePT,
141
+ attempts,
142
+ conceptSlug,
143
+ combinationString,
144
+ timestamp: new Date().toISOString(),
145
+ })
146
+ );
147
+
148
+ // ✅ **Store names in Durable Object**
149
+ await stub.fetch(`https://internal/add-name`, {
150
+ method: 'POST',
151
+ body: JSON.stringify({ language: 'en-us', name: nameEN }),
152
+ headers: { 'Content-Type': 'application/json' },
153
+ });
154
+
155
+ await stub.fetch(`https://internal/add-name`, {
156
+ method: 'POST',
157
+ body: JSON.stringify({ language: 'pt-br', name: namePT }),
158
+ headers: { 'Content-Type': 'application/json' },
159
+ });
160
+
161
+ // ✅ Store the generated basic info in KV
162
+ Object.assign(existingEN, {
163
+ name: nameEN,
164
+ description: descriptionEN,
165
+ poem: poemEN,
166
+ status: 'forced', // 🔥 Mark as "forced" due to duplication
167
+ });
168
+ await kvStore.put(kvKeyEN, JSON.stringify(existingEN));
169
+
170
+ Object.assign(existingPT, {
171
+ name: namePT,
172
+ description: descriptionPT,
173
+ poem: poemPT,
174
+ status: 'forced', // 🔥 Mark as "forced" due to duplication
175
+ });
176
+ await kvStore.put(kvKeyPT, JSON.stringify(existingPT));
177
+
178
+ console.log(`✅ Stored duplicate name after max retries: ${nameEN}, ${namePT}`);
179
+ return;
180
+ }
181
+
132
182
  console.log('🔁 Retrying due to duplicate name...');
133
183
  continue;
134
184
  }
@@ -165,35 +215,9 @@ export class ConceptService {
165
215
  await kvStore.put(kvKeyPT, JSON.stringify(existingPT));
166
216
 
167
217
  console.log(`✅ Stored basic info for ${conceptSlug}, combination: ${combinationString}.`);
168
-
169
- // ✅ **Throttling for next request**
170
- const delayMs = Math.floor(Math.random() * (500 - 200 + 1)) + 200; // 🔥 Random delay between 200-500ms
171
- console.log(`⏳ Waiting ${delayMs}ms before processing next missing entry...`);
172
- await new Promise((resolve) => setTimeout(resolve, delayMs));
173
-
174
218
  return;
175
219
  } catch (error) {
176
220
  console.error(`❌ Attempt ${attempts} failed at phase: ${phase}`, (error as Error).message);
177
-
178
- // ✅ Store failure details in KV for debugging
179
- await kvFailuresStore.put(
180
- failureKey,
181
- JSON.stringify({
182
- error: (error as Error).message,
183
- attempt: attempts,
184
- phase,
185
- conceptSlug,
186
- combinationString,
187
- timestamp: new Date().toISOString(),
188
- })
189
- );
190
-
191
- if (attempts >= maxAttempts) {
192
- console.error(`🚨 All ${maxAttempts} attempts failed.`);
193
- throw new Error(`Failed to generate basic info after ${maxAttempts} attempts.`);
194
- }
195
- console.log('🔁 Retrying...');
196
- await new Promise((resolve) => setTimeout(resolve, 300));
197
221
  }
198
222
  }
199
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.193",
3
+ "version": "0.0.195",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {