@supa-media/convex 1.7.0 → 1.7.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supa-media/convex",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Backend package for the Supa framework — OTP auth, schema helpers, and backend utilities for Convex",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -8,14 +8,20 @@
8
8
  * the code, so the app stores no secret and only records the result.
9
9
  *
10
10
  * The keys are the provider's: `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`,
11
- * `TWILIO_VERIFY_SERVICE_SID`. With any missing, `twilioVerifyKeys` answers
12
- * `null`, and the app decides what that means. It should never mean "verified".
11
+ * `TWILIO_VERIFY_SERVICE_SID`. An API key works in place of the auth token:
12
+ * `TWILIO_API_KEY_SID` with `TWILIO_API_KEY_SECRET`, which Twilio recommends
13
+ * because it can be revoked on its own. With no usable pair, `twilioVerifyKeys`
14
+ * answers `null`, and the app decides what that means. It should never mean
15
+ * "verified".
13
16
  */
14
17
 
15
18
  export interface TwilioVerifyKeys {
16
19
  accountSid: string;
20
+ /** The account's auth token, or the API key's secret when `apiKeySid` is set. */
17
21
  authToken: string;
18
22
  serviceSid: string;
23
+ /** Set when signing requests with an API key rather than the auth token. */
24
+ apiKeySid?: string;
19
25
  }
20
26
 
21
27
  export type TwilioSendResult =
@@ -34,15 +40,19 @@ export function twilioVerifyKeys(
34
40
  const accountSid = env.TWILIO_ACCOUNT_SID?.trim();
35
41
  const authToken = env.TWILIO_AUTH_TOKEN?.trim();
36
42
  const serviceSid = env.TWILIO_VERIFY_SERVICE_SID?.trim();
37
- if (!accountSid || !authToken || !serviceSid) return null;
38
- return { accountSid, authToken, serviceSid };
43
+ if (!accountSid || !serviceSid) return null;
44
+ if (authToken) return { accountSid, authToken, serviceSid };
45
+ const apiKeySid = env.TWILIO_API_KEY_SID?.trim();
46
+ const apiKeySecret = env.TWILIO_API_KEY_SECRET?.trim();
47
+ if (!apiKeySid || !apiKeySecret) return null;
48
+ return { accountSid, authToken: apiKeySecret, serviceSid, apiKeySid };
39
49
  }
40
50
 
41
51
  function request(keys: TwilioVerifyKeys, path: string, body: Record<string, string>, fetchImpl: Fetch) {
42
52
  return fetchImpl(`https://verify.twilio.com/v2/Services/${keys.serviceSid}/${path}`, {
43
53
  method: "POST",
44
54
  headers: {
45
- Authorization: `Basic ${btoa(`${keys.accountSid}:${keys.authToken}`)}`,
55
+ Authorization: `Basic ${btoa(`${keys.apiKeySid ?? keys.accountSid}:${keys.authToken}`)}`,
46
56
  "Content-Type": "application/x-www-form-urlencoded",
47
57
  },
48
58
  body: new URLSearchParams(body),