@absolutejs/voice 0.0.22-beta.664 → 0.0.22-beta.665

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
@@ -26493,10 +26493,6 @@ var createMemoryVoicePlivoWebhookNonceStore = () => {
26493
26493
  }
26494
26494
  nonces.add(nonce);
26495
26495
  return true;
26496
- },
26497
- has: (nonce) => nonces.has(nonce),
26498
- set: (nonce) => {
26499
- nonces.add(nonce);
26500
26496
  }
26501
26497
  };
26502
26498
  };
@@ -26544,20 +26540,13 @@ var createVoiceSQLitePlivoWebhookNonceStore = (options) => {
26544
26540
  expires_at INTEGER
26545
26541
  )`);
26546
26542
  const pruneExpired = database.query(`DELETE FROM "${tableName}" WHERE expires_at IS NOT NULL AND expires_at <= ?1`);
26547
- const select = database.query(`SELECT nonce FROM "${tableName}" WHERE nonce = ?1 AND (expires_at IS NULL OR expires_at > ?2) LIMIT 1`);
26548
26543
  const insert = database.query(`INSERT OR IGNORE INTO "${tableName}" (nonce, created_at, expires_at) VALUES (?1, ?2, ?3)`);
26549
- const upsert = database.query(`INSERT INTO "${tableName}" (nonce, created_at, expires_at) VALUES (?1, ?2, ?3)
26550
- ON CONFLICT(nonce) DO UPDATE SET expires_at = excluded.expires_at`);
26551
26544
  return {
26552
26545
  claim: (nonce) => {
26553
26546
  const now = Date.now();
26554
26547
  pruneExpired.run(now);
26555
26548
  const result = insert.run(nonce, now, getPlivoNonceExpiresAt(options.ttlSeconds));
26556
26549
  return result.changes > 0;
26557
- },
26558
- has: (nonce) => Boolean(select.get(nonce, Date.now())),
26559
- set: (nonce) => {
26560
- upsert.run(nonce, Date.now(), getPlivoNonceExpiresAt(options.ttlSeconds));
26561
26550
  }
26562
26551
  };
26563
26552
  };
@@ -26611,21 +26600,6 @@ var createVoicePostgresPlivoWebhookNonceStore = (options = {}) => {
26611
26600
  ON CONFLICT (nonce) DO NOTHING
26612
26601
  RETURNING nonce`, [nonce, Date.now(), getPlivoNonceExpiresAt(options.ttlSeconds)]);
26613
26602
  return rows.length > 0;
26614
- },
26615
- has: async (nonce) => {
26616
- await initialized;
26617
- const sql = await client;
26618
- const rows = await sql.unsafe(`SELECT nonce FROM ${qualifiedTableName}
26619
- WHERE nonce = $1 AND (expires_at IS NULL OR expires_at > $2)
26620
- LIMIT 1`, [nonce, Date.now()]);
26621
- return rows.length > 0;
26622
- },
26623
- set: async (nonce) => {
26624
- await initialized;
26625
- const sql = await client;
26626
- await sql.unsafe(`INSERT INTO ${qualifiedTableName} (nonce, created_at, expires_at)
26627
- VALUES ($1, $2, $3)
26628
- ON CONFLICT (nonce) DO UPDATE SET expires_at = EXCLUDED.expires_at`, [nonce, Date.now(), getPlivoNonceExpiresAt(options.ttlSeconds)]);
26629
26603
  }
26630
26604
  };
26631
26605
  };
@@ -26652,16 +26626,9 @@ var createVoicePlivoWebhookVerifier = (options) => async (input) => {
26652
26626
  if (!nonce) {
26653
26627
  return { ok: false, reason: "invalid-signature" };
26654
26628
  }
26655
- if (nonceStore.claim) {
26656
- if (!await nonceStore.claim(nonce)) {
26657
- return { ok: false, reason: "invalid-signature" };
26658
- }
26659
- return verification;
26660
- }
26661
- if (await nonceStore.has(nonce)) {
26629
+ if (!await nonceStore.claim(nonce)) {
26662
26630
  return { ok: false, reason: "invalid-signature" };
26663
26631
  }
26664
- await nonceStore.set(nonce);
26665
26632
  return verification;
26666
26633
  };
26667
26634
  var createVoiceRedisPlivoWebhookNonceStore = (options = {}) => {
@@ -26676,11 +26643,7 @@ var createVoiceRedisPlivoWebhookNonceStore = (options = {}) => {
26676
26643
  return client.set(key, "1", ...nx ? ["NX"] : []);
26677
26644
  };
26678
26645
  return {
26679
- claim: async (nonce) => await setNonce(nonce, true) === "OK",
26680
- has: async (nonce) => Boolean(await client.exists(getPlivoRedisNonceKey(keyPrefix, nonce))),
26681
- set: async (nonce) => {
26682
- await setNonce(nonce, false);
26683
- }
26646
+ claim: async (nonce) => await setNonce(nonce, true) === "OK"
26684
26647
  };
26685
26648
  };
26686
26649
  var buildPlivoVoiceSetupStatus = async (options, input) => {
@@ -27092,10 +27055,6 @@ var createMemoryVoiceTelnyxWebhookEventStore = () => {
27092
27055
  }
27093
27056
  eventIds.add(eventId);
27094
27057
  return true;
27095
- },
27096
- has: (eventId) => eventIds.has(eventId),
27097
- set: (eventId) => {
27098
- eventIds.add(eventId);
27099
27058
  }
27100
27059
  };
27101
27060
  };
@@ -27145,20 +27104,13 @@ var createVoiceSQLiteTelnyxWebhookEventStore = (options) => {
27145
27104
  expires_at INTEGER
27146
27105
  )`);
27147
27106
  const pruneExpired = database.query(`DELETE FROM "${tableName}" WHERE expires_at IS NOT NULL AND expires_at <= ?1`);
27148
- const select = database.query(`SELECT event_id FROM "${tableName}" WHERE event_id = ?1 AND (expires_at IS NULL OR expires_at > ?2) LIMIT 1`);
27149
27107
  const insert = database.query(`INSERT OR IGNORE INTO "${tableName}" (event_id, created_at, expires_at) VALUES (?1, ?2, ?3)`);
27150
- const upsert = database.query(`INSERT INTO "${tableName}" (event_id, created_at, expires_at) VALUES (?1, ?2, ?3)
27151
- ON CONFLICT(event_id) DO UPDATE SET expires_at = excluded.expires_at`);
27152
27108
  return {
27153
27109
  claim: (eventId) => {
27154
27110
  const now = Date.now();
27155
27111
  pruneExpired.run(now);
27156
27112
  const result = insert.run(eventId, now, getTelnyxEventExpiresAt(options.ttlSeconds));
27157
27113
  return result.changes > 0;
27158
- },
27159
- has: (eventId) => Boolean(select.get(eventId, Date.now())),
27160
- set: (eventId) => {
27161
- upsert.run(eventId, Date.now(), getTelnyxEventExpiresAt(options.ttlSeconds));
27162
27114
  }
27163
27115
  };
27164
27116
  };
@@ -27212,21 +27164,6 @@ var createVoicePostgresTelnyxWebhookEventStore = (options = {}) => {
27212
27164
  ON CONFLICT (event_id) DO NOTHING
27213
27165
  RETURNING event_id`, [eventId, Date.now(), getTelnyxEventExpiresAt(options.ttlSeconds)]);
27214
27166
  return rows.length > 0;
27215
- },
27216
- has: async (eventId) => {
27217
- await initialized;
27218
- const sql = await client;
27219
- const rows = await sql.unsafe(`SELECT event_id FROM ${qualifiedTableName}
27220
- WHERE event_id = $1 AND (expires_at IS NULL OR expires_at > $2)
27221
- LIMIT 1`, [eventId, Date.now()]);
27222
- return rows.length > 0;
27223
- },
27224
- set: async (eventId) => {
27225
- await initialized;
27226
- const sql = await client;
27227
- await sql.unsafe(`INSERT INTO ${qualifiedTableName} (event_id, created_at, expires_at)
27228
- VALUES ($1, $2, $3)
27229
- ON CONFLICT (event_id) DO UPDATE SET expires_at = EXCLUDED.expires_at`, [eventId, Date.now(), getTelnyxEventExpiresAt(options.ttlSeconds)]);
27230
27167
  }
27231
27168
  };
27232
27169
  };
@@ -27243,11 +27180,7 @@ var createVoiceRedisTelnyxWebhookEventStore = (options = {}) => {
27243
27180
  return client.set(key, "1", ...nx ? ["NX"] : []);
27244
27181
  };
27245
27182
  return {
27246
- claim: async (eventId) => await setEvent(eventId, true) === "OK",
27247
- has: async (eventId) => Boolean(await client.exists(getTelnyxRedisEventKey(keyPrefix, eventId))),
27248
- set: async (eventId) => {
27249
- await setEvent(eventId, false);
27250
- }
27183
+ claim: async (eventId) => await setEvent(eventId, true) === "OK"
27251
27184
  };
27252
27185
  };
27253
27186
  var readTelnyxWebhookEventId = (rawBody) => {
@@ -27288,14 +27221,7 @@ var createVoiceTelnyxWebhookVerifier = (options) => async (input) => {
27288
27221
  if (!eventId) {
27289
27222
  return { ok: false, reason: "invalid-signature" };
27290
27223
  }
27291
- if (eventStore.claim) {
27292
- return await eventStore.claim(eventId) ? verification : { ok: false, reason: "invalid-signature" };
27293
- }
27294
- if (await eventStore.has(eventId)) {
27295
- return { ok: false, reason: "invalid-signature" };
27296
- }
27297
- await eventStore.set(eventId);
27298
- return verification;
27224
+ return await eventStore.claim(eventId) ? verification : { ok: false, reason: "invalid-signature" };
27299
27225
  };
27300
27226
  var buildTelnyxVoiceSetupStatus = async (options, input) => {
27301
27227
  const origin = resolveRequestOrigin2(input.request);
@@ -135,9 +135,8 @@ export type PlivoVoiceSmokeOptions = {
135
135
  title?: string;
136
136
  };
137
137
  export type VoicePlivoWebhookNonceStore = {
138
- claim?: (nonce: string) => Promise<boolean> | boolean;
139
- has: (nonce: string) => Promise<boolean> | boolean;
140
- set: (nonce: string) => Promise<void> | void;
138
+ /** Atomically accepts an unseen signature nonce and rejects every replay. */
139
+ claim: (nonce: string) => Promise<boolean> | boolean;
141
140
  };
142
141
  export type VoicePlivoWebhookNonceStoreOptions = {
143
142
  ttlSeconds?: number;
@@ -155,7 +154,7 @@ export type VoicePostgresPlivoWebhookNonceStoreOptions = VoicePlivoWebhookNonceS
155
154
  tableName?: string;
156
155
  tablePrefix?: string;
157
156
  };
158
- export type VoiceRedisPlivoWebhookNonceClient = Pick<RedisClient, "exists" | "set">;
157
+ export type VoiceRedisPlivoWebhookNonceClient = Pick<RedisClient, "set">;
159
158
  export type VoiceRedisPlivoWebhookNonceStoreOptions = VoicePlivoWebhookNonceStoreOptions & {
160
159
  client?: VoiceRedisPlivoWebhookNonceClient;
161
160
  keyPrefix?: string;
@@ -162,9 +162,8 @@ export type TelnyxVoiceRoutesOptions<TContext = unknown, TSession extends VoiceS
162
162
  };
163
163
  };
164
164
  export type VoiceTelnyxWebhookEventStore = {
165
- claim?: (eventId: string) => Promise<boolean> | boolean;
166
- has: (eventId: string) => Promise<boolean> | boolean;
167
- set: (eventId: string) => Promise<void> | void;
165
+ /** Atomically accepts an unseen event id and rejects every duplicate. */
166
+ claim: (eventId: string) => Promise<boolean> | boolean;
168
167
  };
169
168
  export type VoiceTelnyxWebhookEventStoreOptions = {
170
169
  ttlSeconds?: number;
@@ -182,7 +181,7 @@ export type VoicePostgresTelnyxWebhookEventStoreOptions = VoiceTelnyxWebhookEven
182
181
  tableName?: string;
183
182
  tablePrefix?: string;
184
183
  };
185
- export type VoiceRedisTelnyxWebhookEventClient = Pick<RedisClient, "exists" | "set">;
184
+ export type VoiceRedisTelnyxWebhookEventClient = Pick<RedisClient, "set">;
186
185
  export type VoiceRedisTelnyxWebhookEventStoreOptions = VoiceTelnyxWebhookEventStoreOptions & {
187
186
  client?: VoiceRedisTelnyxWebhookEventClient;
188
187
  keyPrefix?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.664",
3
+ "version": "0.0.22-beta.665",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",