@vvedantb/server 0.10.0 → 0.12.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 +79 -0
- package/README.md +14 -6
- package/dist/ai/cost.d.ts +17 -0
- package/dist/ai/cost.js +20 -0
- package/dist/ai/errors.d.ts +35 -0
- package/dist/ai/errors.js +84 -0
- package/dist/ai/index.d.ts +3 -0
- package/dist/ai/index.js +3 -0
- package/dist/ai/serviceTier.d.ts +55 -0
- package/dist/ai/serviceTier.js +29 -0
- package/dist/convex/clerkBilling.d.ts +89 -0
- package/dist/convex/clerkBilling.js +130 -0
- package/dist/convex/clerkWebhook.d.ts +31 -0
- package/dist/convex/clerkWebhook.js +26 -0
- package/dist/convex/index.d.ts +4 -1
- package/dist/convex/index.js +4 -1
- package/dist/convex/vPlan.d.ts +22 -0
- package/dist/convex/vPlan.js +33 -0
- package/dist/convex/vProModule.d.ts +109 -0
- package/dist/convex/vProModule.js +87 -0
- package/docs/ai.md +135 -0
- package/docs/convex.md +225 -1
- package/package.json +17 -2
package/docs/convex.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @vvedantb/server
|
|
|
10
10
|
|
|
11
11
|
## Peers
|
|
12
12
|
|
|
13
|
-
None required. `@clerk/backend` is an optional peer. The package never imports it: `getClerkClient` takes its `createClerkClient`,
|
|
13
|
+
None required. `@clerk/backend` is an optional peer. The package never imports it: `getClerkClient` takes its `createClerkClient`, `verifyClerkAccessToken` takes a client (or a function that builds one), and `verifyClerkWebhook` takes `verifyWebhook` from `@clerk/backend/webhooks`.
|
|
14
14
|
|
|
15
15
|
`convex` is an optional peer for types only: the optimistic-update helpers and the MCP token cache below name Convex types (`FunctionReference`, `OptimisticLocalStore`, `GenericId`, `RegisteredQuery`, the type of `v`). The package never imports `convex` at runtime; the token cache takes `v`, `defineTable` and your function builders as arguments.
|
|
16
16
|
|
|
@@ -62,6 +62,8 @@ expectMcpToolCount(toolNames, 2);
|
|
|
62
62
|
| `createOriginAllowlistCors(allowedOrigins)` | `{ headers(origin), preflightHeaders(origin) }` for credentialed browser CORS on a fixed origin list. |
|
|
63
63
|
| `verifyClerkAccessToken(clerk, token, options?)`, `consoleClerkVerifyLogger` | Clerk bearer verification core: `{ userId, tokenType, auth }` or `null`. See below. |
|
|
64
64
|
| `createClerkUserAuth<DataModel>()(config)` | Clerk-user lookups for queries and mutations: `getCurrentUserId`, `requireCurrentUserId`, `getCurrentUser`, `isCurrentUserAdmin`, `getUserByClerkId`, `ensureUser`. See below. |
|
|
65
|
+
| `hasVPlan`, `hasVPro`, `parseVProCompUserIds` | V Pro checks: the session `pla` claim, stored plan slugs and a complimentary id list. See [V Pro plan check](#v-pro-plan-check). |
|
|
66
|
+
| `verifyClerkWebhook`, `parseClerkBillingEvent`, `createVProModule<DataModel>()(config)` | Clerk Billing webhook: verify, read the plan change, write it to the users row. See [Clerk Billing webhook](#clerk-billing-webhook-v-pro). |
|
|
65
67
|
|
|
66
68
|
Crypto primitives are in [crypto.md](crypto.md); MCP scaffolding in [mcp.md](mcp.md). Not included: rate limits.
|
|
67
69
|
|
|
@@ -407,6 +409,228 @@ if (!hasVPlan(identity)) throw new Error("V Pro required");
|
|
|
407
409
|
|
|
408
410
|
`null`, a missing `pla` or a malformed value returns `false`; it never throws. `V_PRO_PLAN_KEY` and `V_PRO_PLAN_KEYS` are exported too.
|
|
409
411
|
|
|
412
|
+
A Convex JWT template without a `pla` claim gives `hasVPlan` nothing to read. Apps then store the user's granting plan slugs on the users row from Clerk Billing webhooks, and check both with `hasVPro`:
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
import { hasVPro, parseVProCompUserIds } from "@vvedantb/server";
|
|
416
|
+
|
|
417
|
+
hasVPro({
|
|
418
|
+
identity, // hasVPlan(identity)
|
|
419
|
+
planSlugs: user?.planSlugs, // any slug in V_PRO_PLAN_KEYS
|
|
420
|
+
compIds: parseVProCompUserIds(process.env.V_PRO_COMP_USER_IDS), // complimentary Clerk user ids
|
|
421
|
+
clerkId: user?.clerkId, // matched against compIds; default identity.subject
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Any one source grants. Every field is optional; missing or malformed ones count as no plan, and it never throws. `hasVPro` reads no env: pass `compIds` yourself. `parseVProCompUserIds` splits a comma-separated list, trims each id and drops empty ones. A stored `vibot_pro` slug does not count.
|
|
426
|
+
|
|
427
|
+
## Clerk Billing webhook (V Pro)
|
|
428
|
+
|
|
429
|
+
Pure helpers for the webhook that keeps the stored slugs current, and a factory bound to your users table. Apps keep their own `httpAction`, `internalMutation` and Node backfill action; these are the logic inside them.
|
|
430
|
+
|
|
431
|
+
| Export | What it does |
|
|
432
|
+
| --- | --- |
|
|
433
|
+
| `verifyClerkWebhook(verifyWebhook, request, options?)` | Verify a Clerk (Svix) webhook. Pass `verifyWebhook` from `@clerk/backend/webhooks`; the event type is inferred from it. The secret is `options.signingSecret`, else `CLERK_WEBHOOK_SIGNING_SECRET` from `options.env` (default `process.env`). Returns `{ ok: true, event }` or `{ ok: false, reason, error }`; never throws. |
|
|
434
|
+
| `parseClerkBillingEvent(event, options?)` | `{ kind: "replace", clerkId, planSlugs }`, `{ kind: "item", clerkId, status, slug }`, or `null` when the event changes nothing. Reads `data` defensively; never throws. |
|
|
435
|
+
| `applyBillingChange(current, change, options?)` | The slugs to store after a change: `replace` overwrites, `item` merges. |
|
|
436
|
+
| `activePlanSlugs(items, options?)` | Slugs of the items that grant their plan, unique and sorted. Takes webhook `data.items` and the Clerk backend client's `subscription.subscriptionItems` as they are. |
|
|
437
|
+
| `applyItemToPlanSlugs(current, item, options?)` | Add the item's slug when it grants, remove it when it does not. |
|
|
438
|
+
| `itemGrantsPlan(item, options?)`, `GRANTING_ITEM_STATUSES` | By default `active`, `past_due` and `canceled` grant. See [Options](#options). |
|
|
439
|
+
| `GRANTING_STATUSES_ACTIVE_PAST_DUE`, `GRANTING_STATUSES_ACTIVE_ONLY` | Presets for `grantingStatuses`: `["active", "past_due"]` and `["active"]`. |
|
|
440
|
+
| `createVProModule<DataModel>()(config)` | Helpers bound to one users table and its field names. See below. |
|
|
441
|
+
|
|
442
|
+
### Events
|
|
443
|
+
|
|
444
|
+
| Event `type` | Change |
|
|
445
|
+
| --- | --- |
|
|
446
|
+
| `subscription.created`, `subscription.updated`, `subscription.active`, `subscription.pastDue` | `replace` with `activePlanSlugs(data.items)` |
|
|
447
|
+
| `subscriptionItem.updated`, `.active`, `.canceled`, `.ended`, `.abandoned`, `.incomplete`, `.pastDue` | `item` with `data.status` and `data.plan.slug` |
|
|
448
|
+
| anything else | `null` |
|
|
449
|
+
|
|
450
|
+
With `eventMatch: "prefix"`, any type that starts with `subscription.` gives `replace` and any type that starts with `subscriptionItem.` gives `item`. The listed types give the same change in both modes.
|
|
451
|
+
|
|
452
|
+
- **Granting statuses.** By default `active`, `past_due` and `canceled` grant. `canceled` means cancel at period end, so access stays until the item is `ended`. `ended`, `expired`, `abandoned`, `incomplete`, `upcoming` and any other status remove the slug.
|
|
453
|
+
- **Billing period.** Only `status` and `plan.slug` are read. Monthly and yearly items of `v_pro` both store `v_pro`.
|
|
454
|
+
- **Organisation payers.** An event whose `data.payer.user_id` is missing or empty returns `null`, so the app answers 200 and writes nothing.
|
|
455
|
+
- **Malformed data.** A subscription event without an `items` array returns `null` rather than revoking access. An item event without a string `status` or a plan slug returns `null`. Malformed entries in `items` are skipped.
|
|
456
|
+
- **Free plans.** A free plan's slug (for example `free_user`) is stored like any other granting slug. It does not count as V Pro. A subscription with no granting items stores `[]`.
|
|
457
|
+
- **Order.** The helpers do not assume events arrive in order. A subscription event lists every item, so it overwrites the stored set and corrects earlier drift. An item event knows only its own item and merges it. So an `ended` item event after `subscription.active` still removes the slug, and a later `active` item event restores it. One limit: when two items share a slug (for example a monthly and a yearly item of one plan), an item event with a non-granting status for one of them (`ended`, `upcoming`, `abandoned`, `incomplete`) removes the slug while the other still grants. The next subscription event, or a backfill, restores it.
|
|
458
|
+
|
|
459
|
+
### Options
|
|
460
|
+
|
|
461
|
+
The pure helpers take an optional `ClerkBillingOptions`. Leaving it out keeps the defaults listed below.
|
|
462
|
+
|
|
463
|
+
| Option | Default | Read by | Effect |
|
|
464
|
+
| --- | --- | --- | --- |
|
|
465
|
+
| `grantingStatuses` | `GRANTING_ITEM_STATUSES` (`active`, `past_due`, `canceled`) | `itemGrantsPlan`, `activePlanSlugs`, `applyItemToPlanSlugs`, `applyBillingChange`, `parseClerkBillingEvent` | Item statuses that grant the plan. Any other status removes the slug. |
|
|
466
|
+
| `eventMatch` | `"exact"` | `parseClerkBillingEvent` | `"exact"`: the listed event types only. `"prefix"`: any `subscription.*` or `subscriptionItem.*` type. |
|
|
467
|
+
|
|
468
|
+
Pass the same `grantingStatuses` to the parser and to the writer. A `replace` change is filtered when it is parsed; an `item` change keeps the raw `status` and is decided when it is applied. Mixed settings give a stored set that neither setting would give. `vPro.parseBillingEvent` and `vPro.writeBillingChange` share the module's settings, so using both avoids the mismatch.
|
|
469
|
+
|
|
470
|
+
Behaviours an app can keep through config:
|
|
471
|
+
|
|
472
|
+
| App behaviour | Config |
|
|
473
|
+
| --- | --- |
|
|
474
|
+
| `canceled` (cancel at period end) keeps access until `ended` | default |
|
|
475
|
+
| `past_due` keeps access; `canceled` removes it at once | `grantingStatuses: GRANTING_STATUSES_ACTIVE_PAST_DUE` |
|
|
476
|
+
| Only `active` grants | `grantingStatuses: GRANTING_STATUSES_ACTIVE_ONLY` |
|
|
477
|
+
| Event types matched by `startsWith("subscription.")` / `startsWith("subscriptionItem.")` | `eventMatch: "prefix"` |
|
|
478
|
+
| Refetch the subscription from Clerk on each billing event, ignoring the payload | Call `activePlanSlugs(subscription.subscriptionItems, { grantingStatuses })` on the fetched items and write a `replace` change |
|
|
479
|
+
| Insert a users row when the webhook arrives first | module `createUser` |
|
|
480
|
+
| Stamp a field on every write (for example `billingPlansUpdatedAt`) | module `extraPatch` |
|
|
481
|
+
| Different stored field names | module `clerkIdField`, `planSlugsField` |
|
|
482
|
+
|
|
483
|
+
Stored slugs are always unique and sorted. Apps that stored them unsorted see a different order after the next write, but the same members, so plan checks do not change.
|
|
484
|
+
|
|
485
|
+
### `verifyClerkWebhook` result
|
|
486
|
+
|
|
487
|
+
It never throws, so the route needs no `try`. Map both failure reasons to an HTTP error so Clerk retries. 400 for both is the suggested mapping; an app that answers 500 for a missing secret can keep doing so by checking `reason`:
|
|
488
|
+
|
|
489
|
+
| `reason` | When | `verifyWebhook` called |
|
|
490
|
+
| --- | --- | --- |
|
|
491
|
+
| `"missing-secret"` | No secret, or an empty one. `error` is `"CLERK_WEBHOOK_SIGNING_SECRET is not set in Convex env"`. An explicit empty `signingSecret` does not fall back to env. | no |
|
|
492
|
+
| `"invalid"` | `verifyWebhook` threw or rejected (bad signature, missing headers). `error` is its message. | yes |
|
|
493
|
+
|
|
494
|
+
The package does not import `@clerk/backend` and adds no dependency.
|
|
495
|
+
|
|
496
|
+
### `createVProModule`
|
|
497
|
+
|
|
498
|
+
Curried like `createClerkUserAuth`, so you pass your generated `DataModel` and the keys are checked against it. `planSlugsField` must be a `string[]` field (optional is fine), so each app keeps its stored field name with no data migration.
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
// convex/vPro.ts
|
|
502
|
+
import { createVProModule } from "@vvedantb/server";
|
|
503
|
+
import type { DataModel } from "./_generated/dataModel";
|
|
504
|
+
|
|
505
|
+
export const vPro = createVProModule<DataModel>()({
|
|
506
|
+
table: "users",
|
|
507
|
+
index: "by_clerk_id",
|
|
508
|
+
clerkIdField: "clerkId",
|
|
509
|
+
planSlugsField: "planSlugs", // or "billingPlanSlugs"
|
|
510
|
+
// lookup: "unique", // default "first"
|
|
511
|
+
});
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Optional config. Every field has a default, so leaving it out changes nothing.
|
|
515
|
+
|
|
516
|
+
| Field | Default | Effect |
|
|
517
|
+
| --- | --- | --- |
|
|
518
|
+
| `grantingStatuses` | `GRANTING_ITEM_STATUSES` | Used by `nextPlanSlugs`, `writeBillingChange` and `parseBillingEvent`. |
|
|
519
|
+
| `eventMatch` | `"exact"` | Used by `parseBillingEvent`. |
|
|
520
|
+
| `createUser(ctx, { clerkId, planSlugs })` | none | Called by `writeBillingChange` when there is no row. `ctx.db.insert` is typed against the table, so the app supplies its own fields (for example `createdAt`, `lastSeenAt`); the package adds none. `writeBillingChange` then returns `true`. |
|
|
521
|
+
| `onMissingUser` | `"noop"`, or `"create"` when `createUser` is set | `"create"` without `createUser` is a type error and throws at configure time. `"noop"` with `createUser` is a type error. |
|
|
522
|
+
| `extraPatch(planSlugs)` | none | Extra fields merged into the `writeBillingChange` patch of an existing row, typed as `Partial` of the document. The slugs field always wins. Not used by `planSlugsPatch` or `createUser`. |
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
// Insert a row when the webhook arrives first; only `active` grants; prefix event matching.
|
|
526
|
+
export const vPro = createVProModule<DataModel>()({
|
|
527
|
+
table: "users",
|
|
528
|
+
index: "by_clerk_user_id",
|
|
529
|
+
clerkIdField: "clerkUserId",
|
|
530
|
+
planSlugsField: "planSlugs",
|
|
531
|
+
grantingStatuses: GRANTING_STATUSES_ACTIVE_ONLY,
|
|
532
|
+
eventMatch: "prefix",
|
|
533
|
+
createUser: async (ctx, { clerkId, planSlugs }) => {
|
|
534
|
+
const now = Date.now();
|
|
535
|
+
await ctx.db.insert("users", { clerkUserId: clerkId, planSlugs, createdAt: now, lastSeenAt: now });
|
|
536
|
+
},
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// Stamp a timestamp on every write.
|
|
540
|
+
export const vPro = createVProModule<DataModel>()({
|
|
541
|
+
table: "users",
|
|
542
|
+
index: "by_clerk_id",
|
|
543
|
+
clerkIdField: "clerkId",
|
|
544
|
+
planSlugsField: "billingPlanSlugs",
|
|
545
|
+
extraPatch: () => ({ billingPlansUpdatedAt: Date.now() }),
|
|
546
|
+
});
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
| Function | Semantics |
|
|
550
|
+
| --- | --- |
|
|
551
|
+
| `writeBillingChange(ctx, change)` | Look up the row by `change.clerkId` through the index, then `ctx.db.patch(row._id, { ...extraPatch?.(next), [planSlugsField]: next })`. With no row: returns `false` with no write (the next event or a backfill fills it in), or calls `createUser` and returns `true`. Otherwise `true`. A `MutationCtx` fits without a cast. |
|
|
552
|
+
| `nextPlanSlugs(user, change)` | `applyBillingChange(planSlugsOf(user), change, { grantingStatuses })`. |
|
|
553
|
+
| `parseBillingEvent(event)` | `parseClerkBillingEvent(event, { grantingStatuses, eventMatch })`. |
|
|
554
|
+
| `planSlugsOf(user)` | The stored slugs; `[]` for no row, a missing field or a non-array value. |
|
|
555
|
+
| `planSlugsPatch(planSlugs)` | `{ [planSlugsField]: [...planSlugs] }`, for your own `ctx.db.patch`. |
|
|
556
|
+
| `userHasVPro(user, { identity?, compIds? })` | `hasVPro` over the row's stored slugs and Clerk id, plus the identity and comp ids given. |
|
|
557
|
+
|
|
558
|
+
`tests/convex/vProModule.types.ts` checks the config and ctx types against `convex/server` 1.47.
|
|
559
|
+
|
|
560
|
+
### Adoption sketch
|
|
561
|
+
|
|
562
|
+
```ts
|
|
563
|
+
// convex/clerkBilling.ts
|
|
564
|
+
import { v } from "convex/values";
|
|
565
|
+
import { internalMutation } from "./_generated/server";
|
|
566
|
+
import { vPro } from "./vPro";
|
|
567
|
+
|
|
568
|
+
export const applyBillingChangeInternal = internalMutation({
|
|
569
|
+
args: {
|
|
570
|
+
change: v.union(
|
|
571
|
+
v.object({ kind: v.literal("replace"), clerkId: v.string(), planSlugs: v.array(v.string()) }),
|
|
572
|
+
v.object({ kind: v.literal("item"), clerkId: v.string(), status: v.string(), slug: v.string() }),
|
|
573
|
+
),
|
|
574
|
+
},
|
|
575
|
+
returns: v.boolean(),
|
|
576
|
+
handler: (ctx, { change }) => vPro.writeBillingChange(ctx, change),
|
|
577
|
+
});
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
```ts
|
|
581
|
+
// convex/http/clerkWebhook.ts (httpAction, registered on POST)
|
|
582
|
+
import { verifyWebhook } from "@clerk/backend/webhooks";
|
|
583
|
+
import { parseClerkBillingEvent, verifyClerkWebhook } from "@vvedantb/server";
|
|
584
|
+
import { internal } from "../_generated/api";
|
|
585
|
+
import { httpAction } from "../_generated/server";
|
|
586
|
+
|
|
587
|
+
export const clerkWebhook = httpAction(async (ctx, request) => {
|
|
588
|
+
const verified = await verifyClerkWebhook(verifyWebhook, request);
|
|
589
|
+
if (!verified.ok) {
|
|
590
|
+
console.error("[clerkWebhook]", verified.reason, verified.error);
|
|
591
|
+
return new Response("Invalid webhook", { status: 400 });
|
|
592
|
+
}
|
|
593
|
+
const change = parseClerkBillingEvent(verified.event);
|
|
594
|
+
if (change) await ctx.runMutation(internal.clerkBilling.applyBillingChangeInternal, { change });
|
|
595
|
+
return new Response(null, { status: 200 });
|
|
596
|
+
});
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
```ts
|
|
600
|
+
// convex/users.ts
|
|
601
|
+
export const hasVPlan = query({
|
|
602
|
+
args: {},
|
|
603
|
+
returns: v.boolean(),
|
|
604
|
+
handler: async (ctx) => {
|
|
605
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
606
|
+
if (!identity) return false;
|
|
607
|
+
const user = await userAuth.getUserByClerkId(ctx, identity.subject); // createClerkUserAuth
|
|
608
|
+
return vPro.userHasVPro(user, {
|
|
609
|
+
identity,
|
|
610
|
+
compIds: parseVProCompUserIds(process.env.V_PRO_COMP_USER_IDS),
|
|
611
|
+
});
|
|
612
|
+
},
|
|
613
|
+
});
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
```ts
|
|
617
|
+
// Backfill ("use node" action, stays in the app), per Clerk user id:
|
|
618
|
+
const subscription = await clerk.billing.getUserBillingSubscription(clerkId);
|
|
619
|
+
await ctx.runMutation(internal.clerkBilling.applyBillingChangeInternal, {
|
|
620
|
+
change: { kind: "replace", clerkId, planSlugs: activePlanSlugs(subscription.subscriptionItems) },
|
|
621
|
+
});
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
Moving from an app copy: `planSlugsFromItems` is `activePlanSlugs`. `userHasVPlan(user, env)` is `vPro.userHasVPro(user, { compIds: parseVProCompUserIds(env.V_PRO_COMP_USER_IDS) })`. `identityHasVPlan(identity)` is `hasVPlan(identity)`. The replace and apply-item mutations can become one `writeBillingChange` mutation, or keep their names and call `vPro.writeBillingChange` with `{ kind: "replace", ... }` or `{ kind: "item", ... }`. Stays in the apps: the route, the mutation and query wrappers, the paged user listing and the backfill action.
|
|
625
|
+
|
|
626
|
+
Also stays in the apps, by design:
|
|
627
|
+
|
|
628
|
+
- **Webhook runtime.** V8 `httpAction` or a Node action that verifies a forwarded body and headers. `verifyClerkWebhook` takes any `verifyWebhook`-shaped function, so a Node action can pass a wrapper around Svix's `Webhook`.
|
|
629
|
+
- **HTTP status for a missing secret.** Map `reason` to 400 or 500 in the route.
|
|
630
|
+
- **Refetch on each event.** An app that ignores the payload and refetches the subscription from Clerk calls `activePlanSlugs` with its `grantingStatuses` on the fetched items.
|
|
631
|
+
- **Custom JWT claims.** Checks on app-specific claims (for example a custom `plans` or `plan` claim) stay beside `hasVPro`; `hasVPro` reads only `pla`.
|
|
632
|
+
- **Backfill.** Page size, scheduling and how a 404 from Clerk is stored. Pass the same `grantingStatuses` to `activePlanSlugs` as the webhook uses.
|
|
633
|
+
|
|
410
634
|
## Develop
|
|
411
635
|
|
|
412
636
|
```sh
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "MIT",
|
|
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).",
|
|
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, V Pro plan checks and Clerk Billing webhook helpers, 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); and, from the `@vvedantb/server/ai` subpath, Vercel AI Gateway helpers (service tier provider options, cost from provider metadata, error classification).",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
@@ -17,10 +17,15 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"import": "./dist/index.js"
|
|
19
19
|
},
|
|
20
|
+
"./ai": {
|
|
21
|
+
"types": "./dist/ai/index.d.ts",
|
|
22
|
+
"import": "./dist/ai/index.js"
|
|
23
|
+
},
|
|
20
24
|
"./package.json": "./package.json"
|
|
21
25
|
},
|
|
22
26
|
"files": [
|
|
23
27
|
"dist",
|
|
28
|
+
"docs/ai.md",
|
|
24
29
|
"docs/artifacts.md",
|
|
25
30
|
"docs/convex.md",
|
|
26
31
|
"docs/crypto.md",
|
|
@@ -43,14 +48,19 @@
|
|
|
43
48
|
"prepack": "tsc -p tsconfig.json"
|
|
44
49
|
},
|
|
45
50
|
"peerDependencies": {
|
|
51
|
+
"@ai-sdk/gateway": ">=1",
|
|
46
52
|
"@clerk/backend": ">=1",
|
|
47
53
|
"@jitl/quickjs-singlefile-cjs-release-sync": "^0.32.0",
|
|
48
54
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
55
|
+
"ai": ">=5",
|
|
49
56
|
"convex": "^1.24.0",
|
|
50
57
|
"quickjs-emscripten-core": "^0.32.0",
|
|
51
58
|
"zod": "^3.25.0 || ^4.0.0"
|
|
52
59
|
},
|
|
53
60
|
"peerDependenciesMeta": {
|
|
61
|
+
"@ai-sdk/gateway": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
54
64
|
"@clerk/backend": {
|
|
55
65
|
"optional": true
|
|
56
66
|
},
|
|
@@ -60,6 +70,9 @@
|
|
|
60
70
|
"@modelcontextprotocol/sdk": {
|
|
61
71
|
"optional": true
|
|
62
72
|
},
|
|
73
|
+
"ai": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
63
76
|
"convex": {
|
|
64
77
|
"optional": true
|
|
65
78
|
},
|
|
@@ -71,9 +84,11 @@
|
|
|
71
84
|
}
|
|
72
85
|
},
|
|
73
86
|
"devDependencies": {
|
|
87
|
+
"@ai-sdk/gateway": "^4.0.135",
|
|
74
88
|
"@jitl/quickjs-singlefile-cjs-release-sync": "^0.32.0",
|
|
75
89
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
76
90
|
"@types/node": "^22.0.0",
|
|
91
|
+
"ai": "^7.0.162",
|
|
77
92
|
"convex": "^1.47.0",
|
|
78
93
|
"quickjs-emscripten-core": "^0.32.0",
|
|
79
94
|
"typescript": "^5.9.0",
|