@dupecom/botcha-cloudflare 0.3.1 → 0.3.2

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 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/routes/stream.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAKzE,KAAK,QAAQ,GAAG;IACd,UAAU,EAAE,WAAW,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAYF,QAAA,MAAM,GAAG;cAAwB,QAAQ;yCAAK,CAAC;AAoS/C,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/routes/stream.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAKzE,KAAK,QAAQ,GAAG;IACd,UAAU,EAAE,WAAW,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAYF,QAAA,MAAM,GAAG;cAAwB,QAAQ;yCAAK,CAAC;AAiT/C,eAAe,GAAG,CAAC"}
@@ -143,29 +143,40 @@ app.post('/v1/challenge/stream/:session', async (c) => {
143
143
  expectedAnswers.push(await sha256First(num.toString(), 8));
144
144
  }
145
145
  // Update session
146
+ const timerStart = Date.now();
146
147
  session.status = 'challenged';
147
148
  session.problems = problems;
148
149
  session.expectedAnswers = expectedAnswers;
149
- session.timerStart = Date.now();
150
+ session.timerStart = timerStart;
151
+ // Store session
150
152
  await storeSession(c.env.CHALLENGES, session);
151
- // Return challenge event
153
+ // Return challenge event with timer start for client to track
152
154
  return c.json({
153
155
  success: true,
154
156
  event: 'challenge',
155
157
  data: {
156
158
  problems,
157
159
  timeLimit: 500,
160
+ timerStart, // Include so client can verify timing
158
161
  instructions: 'Compute SHA256 of each number, return first 8 hex chars',
159
162
  },
160
163
  });
161
164
  }
162
165
  // Handle "solve" action - verify answers
163
166
  if (action === 'solve') {
167
+ // Handle KV eventual consistency - retry once if still in 'ready' state
168
+ if (session.status === 'ready') {
169
+ await new Promise(resolve => setTimeout(resolve, 100));
170
+ const retrySession = await getSession(c.env.CHALLENGES, sessionId);
171
+ if (retrySession && retrySession.status === 'challenged') {
172
+ Object.assign(session, retrySession);
173
+ }
174
+ }
164
175
  if (session.status !== 'challenged') {
165
176
  return c.json({
166
177
  success: false,
167
178
  error: 'INVALID_STATE',
168
- message: `Session is in ${session.status} state, expected challenged`,
179
+ message: `Session is in ${session.status} state, expected challenged. Try sending GO first.`,
169
180
  }, 400);
170
181
  }
171
182
  if (!answers || !Array.isArray(answers)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dupecom/botcha-cloudflare",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "BOTCHA for Cloudflare Workers - Prove you're a bot. Humans need not apply.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",