@vvedantb/server 0.8.0 → 0.9.0
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/CHANGELOG.md +34 -0
- package/README.md +1 -1
- package/dist/convex/index.d.ts +2 -1
- package/dist/convex/index.js +2 -1
- package/dist/convex/vPlan.d.ts +13 -0
- package/dist/convex/vPlan.js +25 -0
- package/dist/convex/verifyClerkOAuthJwt.d.ts +32 -14
- package/dist/convex/verifyClerkOAuthJwt.js +20 -6
- package/docs/convex.md +17 -4
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
Shared "V Pro" plan check for every Project V app. Additive; no new dependency.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `hasVPlan(claimsOrIdentity)`: true when the Clerk session token v2 `pla` claim (`u:<plan>` or `o:<plan>`, or a bare slug) is `v_pro` or the legacy `vibot_pro`. Takes a Convex `getUserIdentity()` result or raw JWT claims. `null`, `undefined`, a missing claim or a malformed one returns `false`; it never throws.
|
|
10
|
+
- `V_PRO_PLAN_KEY` (`"v_pro"`), `V_PRO_LEGACY_PLAN_KEY` (`"vibot_pro"`) and `V_PRO_PLAN_KEYS`.
|
|
11
|
+
|
|
12
|
+
### Tests
|
|
13
|
+
|
|
14
|
+
- `tests/convex/vPlan.test.ts`: both scopes for both plans, bare slugs, identity-shaped objects, unrelated plans and malformed input. `tests-node/esm-exports.mjs` checks the new exports.
|
|
15
|
+
|
|
16
|
+
## 0.8.1
|
|
17
|
+
|
|
18
|
+
Fix: 0.8.0 sent every JWT-shaped bearer to `verifyClerkOAuthJwt`, which rejects any header `typ` other than `at+jwt` or `application/at+jwt`. Clerk session tokens (RS256, `typ` `JWT` or none), which apps accept on `/mcp` with `acceptsToken: ["oauth_token", "session_token"]`, were rejected with no retry. No new dependency.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- `authenticateClerkBearer` verifies locally only a JWT whose header `typ` is `at+jwt` or `application/at+jwt` (case-insensitive). A failure there is still final: `verifyFallback` is not called. Every other token goes to `verifyFallback`: opaque OAuth tokens, session JWTs, JWTs with another or no `typ`, and JWTs with an undecodable header. `verifyClerkOAuthJwt` is unchanged and still rejects session JWTs when called directly.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- `verifyFallback` option on `authenticateClerkBearer`. It replaces `verifyOpaque` and receives non-access-token JWTs as well as opaque tokens. `verifyFallback` wins when both are set.
|
|
27
|
+
- `isOAuthAccessTokenJwt(token)`.
|
|
28
|
+
|
|
29
|
+
### Deprecated
|
|
30
|
+
|
|
31
|
+
- `verifyOpaque` option: alias of `verifyFallback`. Callers that pass only `verifyOpaque` still compile and work. Rename it when convenient.
|
|
32
|
+
|
|
33
|
+
### Tests
|
|
34
|
+
|
|
35
|
+
- `tests/convex/verifyClerkOAuthJwt.test.ts`: session JWT, missing `typ`, undecodable header and opaque token go to the fallback; a valid `at+jwt` verifies locally; a bad `at+jwt` returns `null` without the fallback; the `verifyOpaque` alias works.
|
|
36
|
+
|
|
3
37
|
## 0.8.0
|
|
4
38
|
|
|
5
39
|
Additive: V8-safe verification of Clerk OAuth access tokens that are JWTs. Nothing in 0.7.1 is removed or changed. No new dependency (WebCrypto and `fetch` only).
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ There are no subpath exports (0.2.0 removed `/convex` and `/mcp`; see [CHANGELOG
|
|
|
14
14
|
|
|
15
15
|
| Area | What it holds | Docs |
|
|
16
16
|
| --- | --- | --- |
|
|
17
|
-
| Convex helpers | Query-limit errors, Clerk auth config and client, Clerk token verification (Node `verifyClerkAccessToken`, V8 `authenticateClerkBearer` for OAuth JWTs; the MCP token cache is deprecated), Clerk-user lookups and `ensureUser` (`createClerkUserAuth`), bearer tokens, env, MCP CORS, origin-allowlist CORS, `jsonResponse`, server info, test helpers. | [docs/convex.md](docs/convex.md) |
|
|
17
|
+
| Convex helpers | Query-limit errors, Clerk auth config and client, Clerk token verification (Node `verifyClerkAccessToken`, V8 `authenticateClerkBearer` for OAuth access token JWTs, with `verifyFallback` for opaque tokens and session JWTs; the MCP token cache is deprecated), Clerk-user lookups and `ensureUser` (`createClerkUserAuth`), bearer tokens, env, MCP CORS, origin-allowlist CORS, `jsonResponse`, server info, test helpers. | [docs/convex.md](docs/convex.md) |
|
|
18
18
|
| MCP scaffolding | For Convex `httpAction`s: bearer-auth handler, OAuth metadata, route registration, a pure JSON-RPC dispatcher, tool helpers and explorer tools. | [docs/mcp.md](docs/mcp.md) |
|
|
19
19
|
| Crypto | WebCrypto-only base64/base64url/hex, SHA-256, random tokens, `timingSafeEqual`, AES-GCM. Convex default runtime and Node 20+. | [docs/crypto.md](docs/crypto.md) |
|
|
20
20
|
| Optimistic updates | `mapLoadedQuery` (also `forEachLoadedQuery`, `updateAllCachedQueries`), `patchLoadedQuery`, `tempId`, `createMemoryOptimisticStore`. Client-side, no React. | [docs/convex.md](docs/convex.md#optimistic-updates-client-side) |
|
package/dist/convex/index.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ export { defineMcpServerInfo, type McpServerInfo } from "./mcpServerInfo.js";
|
|
|
14
14
|
export { assertMcpTools, expectMcpToolCount } from "./mcpTestHelpers.js";
|
|
15
15
|
export { tempId, type TempIdFormat, type TempIdOptions } from "./tempId.js";
|
|
16
16
|
export { consoleClerkVerifyLogger, verifyClerkAccessToken, type ClerkAuthLike, type ClerkLike, type ClerkRequestStateLike, type ClerkTokenType, type ClerkVerifyRejection, type VerifiedClerkToken, type VerifyClerkAccessTokenOptions, } from "./verifyClerkAccessToken.js";
|
|
17
|
-
export { authenticateClerkBearer, CLERK_JWKS_REFETCH_MIN_MS, CLERK_JWKS_TTL_MS, clearClerkJwksCache, looksLikeJwt, verifyClerkOAuthJwt, type AuthenticateClerkBearerOptions, type ClerkOAuthJwtRejection, type VerifiedClerkOAuthJwt, type VerifyClerkOAuthJwtOptions, } from "./verifyClerkOAuthJwt.js";
|
|
17
|
+
export { authenticateClerkBearer, CLERK_JWKS_REFETCH_MIN_MS, CLERK_JWKS_TTL_MS, clearClerkJwksCache, isOAuthAccessTokenJwt, looksLikeJwt, verifyClerkOAuthJwt, type AuthenticateClerkBearerOptions, type ClerkOAuthJwtRejection, type VerifiedClerkOAuthJwt, type VerifyClerkOAuthJwtOptions, } from "./verifyClerkOAuthJwt.js";
|
|
18
|
+
export { hasVPlan, V_PRO_PLAN_KEY, V_PRO_PLAN_KEYS, V_PRO_LEGACY_PLAN_KEY, } from "./vPlan.js";
|
package/dist/convex/index.js
CHANGED
|
@@ -14,4 +14,5 @@ export { defineMcpServerInfo } from "./mcpServerInfo.js";
|
|
|
14
14
|
export { assertMcpTools, expectMcpToolCount } from "./mcpTestHelpers.js";
|
|
15
15
|
export { tempId } from "./tempId.js";
|
|
16
16
|
export { consoleClerkVerifyLogger, verifyClerkAccessToken, } from "./verifyClerkAccessToken.js";
|
|
17
|
-
export { authenticateClerkBearer, CLERK_JWKS_REFETCH_MIN_MS, CLERK_JWKS_TTL_MS, clearClerkJwksCache, looksLikeJwt, verifyClerkOAuthJwt, } from "./verifyClerkOAuthJwt.js";
|
|
17
|
+
export { authenticateClerkBearer, CLERK_JWKS_REFETCH_MIN_MS, CLERK_JWKS_TTL_MS, clearClerkJwksCache, isOAuthAccessTokenJwt, looksLikeJwt, verifyClerkOAuthJwt, } from "./verifyClerkOAuthJwt.js";
|
|
18
|
+
export { hasVPlan, V_PRO_PLAN_KEY, V_PRO_PLAN_KEYS, V_PRO_LEGACY_PLAN_KEY, } from "./vPlan.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Clerk Billing plan key for the shared V Pro plan ($10/month or $100/year). */
|
|
2
|
+
export declare const V_PRO_PLAN_KEY = "v_pro";
|
|
3
|
+
/** The earlier single-app plan. It still counts as V Pro. */
|
|
4
|
+
export declare const V_PRO_LEGACY_PLAN_KEY = "vibot_pro";
|
|
5
|
+
/** Plan keys that grant V Pro. */
|
|
6
|
+
export declare const V_PRO_PLAN_KEYS: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* True when the session's active plan is V Pro (`v_pro` or legacy `vibot_pro`).
|
|
9
|
+
* Reads the Clerk session token v2 `pla` claim, `u:<plan>` or `o:<plan>`, from a
|
|
10
|
+
* Convex `ctx.auth.getUserIdentity()` result or raw JWT claims. A bare plan slug
|
|
11
|
+
* also matches. Anything else, including `null`, returns `false`; it never throws.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hasVPlan(claimsOrIdentity: unknown): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Clerk Billing plan key for the shared V Pro plan ($10/month or $100/year). */
|
|
2
|
+
export const V_PRO_PLAN_KEY = "v_pro";
|
|
3
|
+
/** The earlier single-app plan. It still counts as V Pro. */
|
|
4
|
+
export const V_PRO_LEGACY_PLAN_KEY = "vibot_pro";
|
|
5
|
+
/** Plan keys that grant V Pro. */
|
|
6
|
+
export const V_PRO_PLAN_KEYS = [V_PRO_PLAN_KEY, V_PRO_LEGACY_PLAN_KEY];
|
|
7
|
+
/**
|
|
8
|
+
* True when the session's active plan is V Pro (`v_pro` or legacy `vibot_pro`).
|
|
9
|
+
* Reads the Clerk session token v2 `pla` claim, `u:<plan>` or `o:<plan>`, from a
|
|
10
|
+
* Convex `ctx.auth.getUserIdentity()` result or raw JWT claims. A bare plan slug
|
|
11
|
+
* also matches. Anything else, including `null`, returns `false`; it never throws.
|
|
12
|
+
*/
|
|
13
|
+
export function hasVPlan(claimsOrIdentity) {
|
|
14
|
+
if (typeof claimsOrIdentity !== "object" || claimsOrIdentity === null)
|
|
15
|
+
return false;
|
|
16
|
+
const pla = claimsOrIdentity.pla;
|
|
17
|
+
if (typeof pla !== "string")
|
|
18
|
+
return false;
|
|
19
|
+
const sep = pla.indexOf(":");
|
|
20
|
+
const scope = sep === -1 ? "" : pla.slice(0, sep);
|
|
21
|
+
const plan = sep === -1 ? pla : pla.slice(sep + 1);
|
|
22
|
+
if (sep !== -1 && scope !== "u" && scope !== "o")
|
|
23
|
+
return false;
|
|
24
|
+
return V_PRO_PLAN_KEYS.includes(plan);
|
|
25
|
+
}
|
|
@@ -61,26 +61,43 @@ export declare function looksLikeJwt(token: string): boolean;
|
|
|
61
61
|
* module scope for `CLERK_JWKS_TTL_MS`.
|
|
62
62
|
*/
|
|
63
63
|
export declare function verifyClerkOAuthJwt(token: string, options: VerifyClerkOAuthJwtOptions): Promise<VerifiedClerkOAuthJwt | null>;
|
|
64
|
-
|
|
64
|
+
type FallbackResult = {
|
|
65
|
+
clerkUserId: string;
|
|
66
|
+
} | {
|
|
67
|
+
userId: string;
|
|
68
|
+
} | null | undefined;
|
|
69
|
+
type VerifyFallback = (token: string) => Promise<FallbackResult>;
|
|
70
|
+
type AuthenticateClerkBearerBaseOptions = Omit<VerifyClerkOAuthJwtOptions, "onReject"> & {
|
|
65
71
|
/** The bearer token, without the `Bearer ` prefix. */
|
|
66
72
|
token: string;
|
|
73
|
+
/** Called for a rejected OAuth access token JWT. Default: silent. */
|
|
74
|
+
onReject?: (rejection: ClerkOAuthJwtRejection) => void;
|
|
75
|
+
};
|
|
76
|
+
export type AuthenticateClerkBearerOptions = AuthenticateClerkBearerBaseOptions & ({
|
|
67
77
|
/**
|
|
68
|
-
* Verifies
|
|
69
|
-
*
|
|
78
|
+
* Verifies every token that is not an OAuth access token JWT (header `typ`
|
|
79
|
+
* `at+jwt` or `application/at+jwt`): opaque OAuth tokens issued before the
|
|
80
|
+
* switch to JWTs, and other JWTs such as Clerk session tokens. Usually
|
|
81
|
+
* `ctx.runAction(internal.mcp.nodeActions.verifyAccessToken, { token })`.
|
|
70
82
|
* Returns `{ clerkUserId }`, or `{ userId }` as `verifyClerkAccessToken` does, or `null`.
|
|
71
83
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
};
|
|
84
|
+
verifyFallback: VerifyFallback;
|
|
85
|
+
/** @deprecated Use `verifyFallback`. Ignored when `verifyFallback` is set. */
|
|
86
|
+
verifyOpaque?: VerifyFallback;
|
|
87
|
+
} | {
|
|
88
|
+
verifyFallback?: VerifyFallback;
|
|
89
|
+
/** @deprecated Use `verifyFallback`. Alias kept so 0.8.0 callers compile. */
|
|
90
|
+
verifyOpaque: VerifyFallback;
|
|
91
|
+
});
|
|
92
|
+
/** True when the token is a JWT whose header `typ` is `at+jwt` or `application/at+jwt`. */
|
|
93
|
+
export declare function isOAuthAccessTokenJwt(token: string): boolean;
|
|
80
94
|
/**
|
|
81
|
-
* One call for an `httpAction`:
|
|
82
|
-
*
|
|
83
|
-
*
|
|
95
|
+
* One call for an `httpAction`: an OAuth access token JWT (header `typ`
|
|
96
|
+
* `at+jwt` or `application/at+jwt`) is verified locally in V8 (no Node action,
|
|
97
|
+
* no token cache). Every other token goes to `verifyFallback`: opaque OAuth
|
|
98
|
+
* tokens, and JWTs with another or no `typ`, such as Clerk session tokens. An
|
|
99
|
+
* access token JWT that fails local verification is not retried with
|
|
100
|
+
* `verifyFallback`. `verifyOpaque` is a deprecated alias of `verifyFallback`.
|
|
84
101
|
* Returns `{ clerkUserId }` or `null`.
|
|
85
102
|
*
|
|
86
103
|
* Clerk OAuth access tokens last 1 day
|
|
@@ -90,3 +107,4 @@ export type AuthenticateClerkBearerOptions = Omit<VerifyClerkOAuthJwtOptions, "o
|
|
|
90
107
|
export declare function authenticateClerkBearer(options: AuthenticateClerkBearerOptions): Promise<{
|
|
91
108
|
clerkUserId: string;
|
|
92
109
|
} | null>;
|
|
110
|
+
export {};
|
|
@@ -125,10 +125,21 @@ export async function verifyClerkOAuthJwt(token, options) {
|
|
|
125
125
|
return null;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
/** True when the token is a JWT whose header `typ` is `at+jwt` or `application/at+jwt`. */
|
|
129
|
+
export function isOAuthAccessTokenJwt(token) {
|
|
130
|
+
if (!looksLikeJwt(token))
|
|
131
|
+
return false;
|
|
132
|
+
const header = decodeJson(token.split(".")[0]);
|
|
133
|
+
const typ = typeof header?.typ === "string" ? header.typ.toLowerCase() : undefined;
|
|
134
|
+
return typ === "at+jwt" || typ === "application/at+jwt";
|
|
135
|
+
}
|
|
128
136
|
/**
|
|
129
|
-
* One call for an `httpAction`:
|
|
130
|
-
*
|
|
131
|
-
*
|
|
137
|
+
* One call for an `httpAction`: an OAuth access token JWT (header `typ`
|
|
138
|
+
* `at+jwt` or `application/at+jwt`) is verified locally in V8 (no Node action,
|
|
139
|
+
* no token cache). Every other token goes to `verifyFallback`: opaque OAuth
|
|
140
|
+
* tokens, and JWTs with another or no `typ`, such as Clerk session tokens. An
|
|
141
|
+
* access token JWT that fails local verification is not retried with
|
|
142
|
+
* `verifyFallback`. `verifyOpaque` is a deprecated alias of `verifyFallback`.
|
|
132
143
|
* Returns `{ clerkUserId }` or `null`.
|
|
133
144
|
*
|
|
134
145
|
* Clerk OAuth access tokens last 1 day
|
|
@@ -136,12 +147,15 @@ export async function verifyClerkOAuthJwt(token, options) {
|
|
|
136
147
|
* so opaque tokens stop arriving about 1 day after the instance switched to JWTs.
|
|
137
148
|
*/
|
|
138
149
|
export async function authenticateClerkBearer(options) {
|
|
139
|
-
const { token, verifyOpaque, ...jwtOptions } = options;
|
|
140
|
-
if (
|
|
150
|
+
const { token, verifyFallback, verifyOpaque, ...jwtOptions } = options;
|
|
151
|
+
if (isOAuthAccessTokenJwt(token)) {
|
|
141
152
|
const verified = await verifyClerkOAuthJwt(token, jwtOptions);
|
|
142
153
|
return verified ? { clerkUserId: verified.clerkUserId } : null;
|
|
143
154
|
}
|
|
144
|
-
const
|
|
155
|
+
const fallback = verifyFallback ?? verifyOpaque;
|
|
156
|
+
if (!fallback)
|
|
157
|
+
return null;
|
|
158
|
+
const result = await fallback(token);
|
|
145
159
|
if (!result)
|
|
146
160
|
return null;
|
|
147
161
|
const id = "clerkUserId" in result ? result.clerkUserId : result.userId;
|
package/docs/convex.md
CHANGED
|
@@ -234,7 +234,7 @@ Stays in the apps: legacy email lookups, migration-table lookups, API-key actors
|
|
|
234
234
|
|
|
235
235
|
## Clerk OAuth JWT verification (V8)
|
|
236
236
|
|
|
237
|
-
Clerk OAuth access tokens are JWTs now. `authenticateClerkBearer` verifies them in the Convex default runtime (`httpAction`): WebCrypto and `fetch`, no Node action, no token cache.
|
|
237
|
+
Clerk OAuth access tokens are JWTs now. `authenticateClerkBearer` verifies them in the Convex default runtime (`httpAction`): WebCrypto and `fetch`, no Node action, no token cache. Tokens that are not OAuth access token JWTs go to `verifyFallback`, your Node `verifyClerkAccessToken` action: opaque tokens issued earlier, and JWTs with another or no header `typ`, such as Clerk session tokens (`acceptsToken: ["oauth_token", "session_token"]`). `verifyOpaque` is a deprecated alias of `verifyFallback`. Clerk OAuth access tokens last 1 day ([Clerk docs](https://clerk.com/docs/guides/configure/auth-strategies/oauth/how-clerk-implements-oauth)), so opaque tokens stop arriving about 1 day after the switch.
|
|
238
238
|
|
|
239
239
|
```ts
|
|
240
240
|
import { authenticateClerkBearer } from "@vvedantb/server";
|
|
@@ -242,19 +242,19 @@ import { authenticateClerkBearer } from "@vvedantb/server";
|
|
|
242
242
|
const principal = await authenticateClerkBearer({
|
|
243
243
|
token,
|
|
244
244
|
issuer: "https://clerk.example.com", // Clerk Frontend API URL
|
|
245
|
-
|
|
245
|
+
verifyFallback: (token) => ctx.runAction(internal.mcp.nodeActions.verifyAccessToken, { token }),
|
|
246
246
|
});
|
|
247
247
|
// { clerkUserId } | null
|
|
248
248
|
```
|
|
249
249
|
|
|
250
250
|
| Export | Semantics |
|
|
251
251
|
| --- | --- |
|
|
252
|
-
| `authenticateClerkBearer({ token, issuer,
|
|
252
|
+
| `authenticateClerkBearer({ token, issuer, verifyFallback, jwksUrl?, fetch?, now?, clockSkewMs?, onReject?, onError? })` | Three base64url segments with header `typ` `at+jwt` or `application/at+jwt`: `verifyClerkOAuthJwt`, never retried through `verifyFallback`. Everything else (opaque tokens, session JWTs, other or missing `typ`): `verifyFallback(token)`, mapped from `{ clerkUserId }` or `{ userId }` to `{ clerkUserId }`. `null` on rejection. |
|
|
253
253
|
| `verifyClerkOAuthJwt(token, options)` | Checks RS256 signature (JWKS from `${issuer}/.well-known/jwks.json` unless `jwksUrl`), `iss` (trailing slash ignored), `exp` and `nbf` with `clockSkewMs` (default 5000), header `typ` `at+jwt` or `application/at+jwt`, and non-empty `sub`. Returns `{ clerkUserId, claims }` or `null`. Silent unless `onReject({ kind })` or `onError` is set. It does not check `aud`; check `claims` yourself if you need it. |
|
|
254
254
|
| `clearClerkJwksCache()` | The JWKS and imported keys are cached in module scope per isolate for `CLERK_JWKS_TTL_MS` (1 hour); an unknown `kid` refetches at most once per `CLERK_JWKS_REFETCH_MIN_MS` (1 minute). Revocation is not checked: a JWT is valid until `exp`. |
|
|
255
255
|
| `looksLikeJwt(token)` | Three non-empty base64url segments. |
|
|
256
256
|
|
|
257
|
-
Migration: change `authenticate` in your http/mcp files to call `authenticateClerkBearer`, keep the Node `verifyAccessToken` action for opaque tokens, then (about 1 day later) drop the Node action, the `mcpTokenCache` table and the purge cron.
|
|
257
|
+
Migration: change `authenticate` in your http/mcp files to call `authenticateClerkBearer`, rename `verifyOpaque` to `verifyFallback`, keep the Node `verifyAccessToken` action for opaque tokens and session tokens, then (about 1 day later) drop the Node action, the `mcpTokenCache` table and the purge cron.
|
|
258
258
|
|
|
259
259
|
## MCP token cache
|
|
260
260
|
|
|
@@ -394,6 +394,19 @@ expect(store.getQuery(api.tasks.list, { projectId })).toHaveLength(1);
|
|
|
394
394
|
- **Update callback.** app-a's map function gets the value only; app-b and app-d also get the args. Passing args to a one-argument callback changes nothing.
|
|
395
395
|
- **Memory stores.** app-d's is a `Map` per function; app-c's is one array. Same lookups, order and deletes. app-d also reads `setQuery` with missing args as `{}`; app-c would key it as `undefined` (unreachable through Convex's types). The package follows app-d. `getAllQueries` returns the stored entry objects (app-d), not copies (app-c).
|
|
396
396
|
|
|
397
|
+
## V Pro plan check
|
|
398
|
+
|
|
399
|
+
`hasVPlan` tells whether a session holds the shared V Pro plan (Clerk Billing key `v_pro`, $10/month or $100/year). The legacy `vibot_pro` plan counts too. It reads the Clerk session token v2 `pla` claim (`u:v_pro`, `o:v_pro`, `u:vibot_pro`, or a bare slug), because Clerk's `has({ plan })` is not available in Convex. Convex surfaces custom JWT claims on the identity.
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
import { hasVPlan } from "@vvedantb/server";
|
|
403
|
+
|
|
404
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
405
|
+
if (!hasVPlan(identity)) throw new Error("V Pro required");
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
`null`, a missing `pla` or a malformed value returns `false`; it never throws. `V_PRO_PLAN_KEY`, `V_PRO_LEGACY_PLAN_KEY` and `V_PRO_PLAN_KEYS` are exported too.
|
|
409
|
+
|
|
397
410
|
## Develop
|
|
398
411
|
|
|
399
412
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared Convex backend helpers, MCP server scaffolding and Node-side MCP OAuth client helpers from one root import: query-limit errors, Clerk auth and token verification, an MCP bearer-token cache, Clerk-user lookups and ensure-user for Convex functions, bearer tokens, env, CORS, JSON responses, MCP route registration, a bearer-auth MCP HTTP handler, OAuth metadata, a JSON-RPC dispatcher, explorer tools, WebCrypto primitives, Convex optimistic-update helpers, MCP OAuth client helpers (provider, sign-in, refresh, revocation, loopback redirect server) for desktop apps, a QuickJS code sandbox that bridges script tool calls to host handlers, and a pure artifacts core (Zod contract, state limits and ops, quiz and flashcards pages, a sandboxed document wrapper with CSP and a guest state bridge).",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,12 @@
|
|
|
36
36
|
"quickjs-emscripten-core": false,
|
|
37
37
|
"@jitl/quickjs-singlefile-cjs-release-sync": false
|
|
38
38
|
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
42
|
+
"test": "vitest run && node --test tests-node/esm-exports.mjs tests-node/bundle.mjs",
|
|
43
|
+
"prepack": "tsc -p tsconfig.json"
|
|
44
|
+
},
|
|
39
45
|
"peerDependencies": {
|
|
40
46
|
"@clerk/backend": ">=1",
|
|
41
47
|
"@jitl/quickjs-singlefile-cjs-release-sync": "^0.32.0",
|
|
@@ -74,10 +80,5 @@
|
|
|
74
80
|
"vitest": "^3.2.0",
|
|
75
81
|
"zod": "^4.0.0",
|
|
76
82
|
"zod3": "npm:zod@^3.25.76"
|
|
77
|
-
},
|
|
78
|
-
"scripts": {
|
|
79
|
-
"build": "tsc -p tsconfig.json",
|
|
80
|
-
"typecheck": "tsc -p tsconfig.test.json",
|
|
81
|
-
"test": "vitest run && node --test tests-node/esm-exports.mjs tests-node/bundle.mjs"
|
|
82
83
|
}
|
|
83
|
-
}
|
|
84
|
+
}
|