Personal Telegram developer console for GitHub

feat(hardening): add durable kill switch client

davoodmehraban89 committed Oct 5, 2026 at 13:22 UTC 33218a3427966dfffa984630b3e68ca37b16df2e
1 file changed +17
src/core/kill-switch-store.js new
+17
@@ -0,0 +1,17 @@
1 +export class DurableKillSwitchStoreClient {
2 + constructor({ namespace } = {}) { this.namespace = namespace || null; }
3 + #stub() {
4 + if (!this.namespace || typeof this.namespace.idFromName !== 'function' || typeof this.namespace.get !== 'function') throw new Error('Kill switch durable store is not configured');
5 + return this.namespace.get(this.namespace.idFromName('global-emergency-kill-switch'));
6 + }
7 + async get() {
8 + const response = await this.#stub().fetch('https://kill-switch.local/state');
9 + if (!response.ok) throw new Error(`Kill switch read failed (${response.status})`);
10 + return response.json();
11 + }
12 + async set(state) {
13 + const response = await this.#stub().fetch('https://kill-switch.local/state', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(state) });
14 + if (!response.ok) throw new Error(`Kill switch write failed (${response.status})`);
15 + return response.json();
16 + }
17 +}