@shivaedev/test-kits 0.1.1 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1 - 2026-11-04
4
+
5
+ ### Changed
6
+
7
+ - Update `@shivaedev/contract` from 0.33.1 to 0.34.0.
8
+ - Update `@shivaedev/email` from 0.3.1 to 0.3.2.
9
+ - Update `@shivaedev/identity` from 0.22.1 to 0.23.0.
10
+ - Update `@shivaedev/sql` from 0.36.0 to 0.36.1.
11
+ - Update `@shivaedev/test-sql` from 0.18.1 to 0.18.2.
12
+ - Update `@shivaedev/test-story` from 0.36.1 to 0.37.0.
13
+
14
+ ## 0.2.0 - 2026-11-03
15
+
16
+ ### Added
17
+
18
+ - Issue valid MCP bearer tokens with `mcpBearerToken` using the application's Better Auth issuer, signing key and persisted consent grant, so application stories exercise live grant checks.
19
+
3
20
  ## 0.1.1 - 2026-11-03
4
21
 
5
22
  ### Changed
package/README.md CHANGED
@@ -27,6 +27,20 @@ Import `inbox`, `emailLink` and the `ReceivedEmail` type from `@shivaedev/test-k
27
27
 
28
28
  Import `signedInUser`, `signInAgain`, `passwordUser` and `storedProviderAccounts` from `@shivaedev/test-kits/identity/adapters/betterAuth.ts`. They use Better Auth's adapter without requiring its test plugin. `signedInUser(auth, fields)` returns the user, session, headers, cookies and token. Optional `providerAccounts` attach provider identities. `signInAgain(auth, userId)` renews the same user's session on the caller's Effect Clock. `passwordUser` accepts either `password` or `passwordHash`; use an existing hash when password hashing is only a precondition. `storedProviderAccounts` reports credential-presence booleans without returning credential values.
29
29
 
30
+ ### MCP bearer tokens
31
+
32
+ Import `mcpBearerToken` from `@shivaedev/test-kits/mcp/adapters/bearerToken.ts`. With the application's mounted Better Auth instance (JWT and MCP provider plugins enabled), an existing signed-in user and OAuth client, mint the token precondition:
33
+
34
+ ```ts
35
+ const access = yield* mcpBearerToken(auth, {
36
+ userId: alice.user.id,
37
+ clientId: client.clientId,
38
+ resource: `${publicUrl}/mcp`,
39
+ });
40
+ ```
41
+
42
+ The verb creates a persisted `mcp` consent grant and signs a bearer token with the app's advertised issuer and JWT key. It includes the subject, client, grant, resource audience, scope, issued-at and one-hour expiry on the Effect Clock. The result contains `token`, bearer `headers` and `grantId`. Use the token with the app's real MCP adapter; revoking the grant refuses it. This mints a precondition and does not exercise browser OAuth consent or code exchange.
43
+
30
44
  ### SQL change coverage
31
45
 
32
46
  Import `withChangeCoverage`, `expectPublished`, `UnannouncedWrites`, `PublishedKeysMismatch` and the `ChangeCoverage` type from `@shivaedev/test-kits/sql/testing.ts`. `withChangeCoverage(body, { covers }?)` checks PostgreSQL write counters inside `transact` and rolls back writes without declared, recorded keys. `body.pipe(expectPublished(keys))` checks distinct published keys after the body; a mismatch cannot undo a completed commit. The [change guide](https://github.com/ShivaeDev/platform/blob/main/docs/framework/changes.md) explains declarations and publication boundaries. Compose these with [test-sql](https://github.com/ShivaeDev/platform/tree/main/packages/test-sql#readme) for PostgreSQL isolation.
@@ -0,0 +1,30 @@
1
+ import type { AuthContext } from "better-auth";
2
+ import { Effect } from "effect";
3
+ interface McpAuth {
4
+ readonly $context: Promise<{
5
+ readonly adapter: Pick<AuthContext["adapter"], "create">;
6
+ }>;
7
+ readonly api: {
8
+ readonly "getOAuthServerConfig": () => Promise<{
9
+ readonly issuer: string;
10
+ }>;
11
+ readonly "signJWT": (input: {
12
+ readonly body: {
13
+ readonly payload: Record<string, string | number>;
14
+ };
15
+ }) => Promise<{
16
+ readonly token: string;
17
+ }>;
18
+ };
19
+ }
20
+ export declare const mcpBearerToken: (auth: McpAuth, args_1: {
21
+ readonly userId: string;
22
+ readonly clientId: string;
23
+ readonly resource: string;
24
+ }) => Effect.Effect<{
25
+ readonly grantId: string;
26
+ readonly headers: Headers;
27
+ readonly token: string;
28
+ }, never, never>;
29
+ export {};
30
+ //# sourceMappingURL=bearerToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearerToken.d.ts","sourceRoot":"","sources":["../../../src/mcp/adapters/bearerToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvC,UAAU,OAAO;IAChB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,CAAA;KAAE,CAAC,CAAC;IACzF,QAAQ,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,sBAAsB,EAAE,MAAM,OAAO,CAAC;YAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAC5E,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE;gBAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;aAAE,CAAA;SAAE,KAAK,OAAO,CAAC;YAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC7I,CAAC;CACF;AAED,eAAO,MAAM,cAAc;qBAEyB,MAAM;uBAAqB,MAAM;uBAAqB,MAAM;;sBACxE,MAAM;sBAAoB,OAAO;oBAAkB,MAAM;gBA2B/F,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Clock, Effect } from "effect";
2
+ export const mcpBearerToken = Effect.fnUntraced(function* (auth, { userId, clientId, resource }) {
3
+ const { adapter } = yield* Effect.promise(() => auth.$context);
4
+ const { issuer } = yield* Effect.promise(() => auth.api.getOAuthServerConfig());
5
+ const now = yield* Clock.currentTimeMillis;
6
+ const grant = yield* Effect.promise(() => adapter.create({
7
+ data: { clientId, createdAt: new Date(now), scopes: ["mcp"], updatedAt: new Date(now), userId },
8
+ model: "oauthConsent",
9
+ }));
10
+ const { token } = yield* Effect.promise(() => auth.api.signJWT({
11
+ body: {
12
+ payload: {
13
+ aud: resource,
14
+ "client_id": clientId,
15
+ exp: Math.floor(now / 1000) + 3600,
16
+ "grant_id": grant.id,
17
+ iat: Math.floor(now / 1000),
18
+ iss: issuer,
19
+ scope: "mcp",
20
+ sub: userId,
21
+ },
22
+ },
23
+ }));
24
+ return { grantId: grant.id, headers: new Headers({ authorization: `Bearer ${token}` }), token };
25
+ });
26
+ //# sourceMappingURL=bearerToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearerToken.js","sourceRoot":"","sources":["../../../src/mcp/adapters/bearerToken.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUvC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EACxD,IAAa,EACb,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAqF;IAEjH,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAChF,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CACxC,OAAO,CAAC,MAAM,CAAiB;QAC9B,IAAI,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE;QAC/F,KAAK,EAAE,cAAc;KACrB,CAAC,CACF,CAAC;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAC5C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;QAChB,IAAI,EAAE;YACL,OAAO,EAAE;gBACR,GAAG,EAAE,QAAQ;gBACb,WAAW,EAAE,QAAQ;gBACrB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI;gBAClC,UAAU,EAAE,KAAK,CAAC,EAAE;gBACpB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC;gBAC3B,GAAG,EAAE,MAAM;gBACX,KAAK,EAAE,KAAK;gBACZ,GAAG,EAAE,MAAM;aACX;SACD;KACD,CAAC,CACF,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AACjG,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/test-kits",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Reusable story building blocks for Platform applications",
5
5
  "keywords": [
6
6
  "effect"
@@ -43,11 +43,11 @@
43
43
  "README.md"
44
44
  ],
45
45
  "dependencies": {
46
- "@shivaedev/test-sql": "0.18.0",
47
- "@shivaedev/test-story": "0.36.0"
46
+ "@shivaedev/test-sql": "0.18.2",
47
+ "@shivaedev/test-story": "0.37.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@shivaedev/quality": "0.57.1",
50
+ "@shivaedev/quality": "0.58.0",
51
51
  "@types/node": "24.19.2",
52
52
  "better-auth": "1.7.14",
53
53
  "effect": "4.0.6",
@@ -56,10 +56,10 @@
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@shivaedev/changes": "0.9.0",
59
- "@shivaedev/contract": "0.33.0",
60
- "@shivaedev/email": "0.3.0",
61
- "@shivaedev/identity": "0.22.0",
62
- "@shivaedev/sql": "0.35.0",
59
+ "@shivaedev/contract": "0.34.0",
60
+ "@shivaedev/email": "0.3.2",
61
+ "@shivaedev/identity": "0.23.0",
62
+ "@shivaedev/sql": "0.36.1",
63
63
  "better-auth": "1.7.14",
64
64
  "effect": "4.0.6"
65
65
  },
@@ -0,0 +1,42 @@
1
+ import type { AuthContext } from "better-auth";
2
+ import { Clock, Effect } from "effect";
3
+
4
+ interface McpAuth {
5
+ readonly $context: Promise<{ readonly adapter: Pick<AuthContext["adapter"], "create"> }>;
6
+ readonly api: {
7
+ readonly "getOAuthServerConfig": () => Promise<{ readonly issuer: string }>;
8
+ readonly "signJWT": (input: { readonly body: { readonly payload: Record<string, string | number> } }) => Promise<{ readonly token: string }>;
9
+ };
10
+ }
11
+
12
+ export const mcpBearerToken = Effect.fnUntraced(function* (
13
+ auth: McpAuth,
14
+ { userId, clientId, resource }: { readonly userId: string; readonly clientId: string; readonly resource: string },
15
+ ): Effect.fn.Return<{ readonly grantId: string; readonly headers: Headers; readonly token: string }> {
16
+ const { adapter } = yield* Effect.promise(() => auth.$context);
17
+ const { issuer } = yield* Effect.promise(() => auth.api.getOAuthServerConfig());
18
+ const now = yield* Clock.currentTimeMillis;
19
+ const grant = yield* Effect.promise(() =>
20
+ adapter.create<{ id: string }>({
21
+ data: { clientId, createdAt: new Date(now), scopes: ["mcp"], updatedAt: new Date(now), userId },
22
+ model: "oauthConsent",
23
+ }),
24
+ );
25
+ const { token } = yield* Effect.promise(() =>
26
+ auth.api.signJWT({
27
+ body: {
28
+ payload: {
29
+ aud: resource,
30
+ "client_id": clientId,
31
+ exp: Math.floor(now / 1000) + 3600,
32
+ "grant_id": grant.id,
33
+ iat: Math.floor(now / 1000),
34
+ iss: issuer,
35
+ scope: "mcp",
36
+ sub: userId,
37
+ },
38
+ },
39
+ }),
40
+ );
41
+ return { grantId: grant.id, headers: new Headers({ authorization: `Bearer ${token}` }), token };
42
+ });