@vvedantb/server 0.8.1 → 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 +13 -0
- package/dist/convex/index.d.ts +1 -0
- package/dist/convex/index.js +1 -0
- package/dist/convex/vPlan.d.ts +13 -0
- package/dist/convex/vPlan.js +25 -0
- package/docs/convex.md +13 -0
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
3
16
|
## 0.8.1
|
|
4
17
|
|
|
5
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.
|
package/dist/convex/index.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ 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
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
|
@@ -15,3 +15,4 @@ export { assertMcpTools, expectMcpToolCount } from "./mcpTestHelpers.js";
|
|
|
15
15
|
export { tempId } from "./tempId.js";
|
|
16
16
|
export { consoleClerkVerifyLogger, verifyClerkAccessToken, } from "./verifyClerkAccessToken.js";
|
|
17
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
|
+
}
|
package/docs/convex.md
CHANGED
|
@@ -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
|
+
}
|