@shivaedev/test-kits 0.4.0 → 0.6.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/README.md +42 -0
- package/dist/contract/settledQueries.d.ts +13 -0
- package/dist/contract/settledQueries.d.ts.map +1 -0
- package/dist/contract/settledQueries.js +20 -0
- package/dist/contract/settledQueries.js.map +1 -0
- package/dist/github/adapters/appProvider.d.ts +31 -0
- package/dist/github/adapters/appProvider.d.ts.map +1 -0
- package/dist/github/adapters/appProvider.js +31 -0
- package/dist/github/adapters/appProvider.js.map +1 -0
- package/dist/github/adapters/credentials.d.ts +21 -0
- package/dist/github/adapters/credentials.d.ts.map +1 -0
- package/dist/github/adapters/credentials.js +48 -0
- package/dist/github/adapters/credentials.js.map +1 -0
- package/dist/github/adapters/webhookDelivery.d.ts +7 -0
- package/dist/github/adapters/webhookDelivery.d.ts.map +1 -0
- package/dist/github/adapters/webhookDelivery.js +15 -0
- package/dist/github/adapters/webhookDelivery.js.map +1 -0
- package/dist/github/fake.d.ts +52 -0
- package/dist/github/fake.d.ts.map +1 -0
- package/dist/github/fake.js +18 -0
- package/dist/github/fake.js.map +1 -0
- package/dist/host/ProcessError.d.ts +10 -0
- package/dist/host/ProcessError.d.ts.map +1 -0
- package/dist/host/ProcessError.js +4 -0
- package/dist/host/ProcessError.js.map +1 -0
- package/dist/host/adapters/process.d.ts +24 -0
- package/dist/host/adapters/process.d.ts.map +1 -0
- package/dist/host/adapters/process.js +111 -0
- package/dist/host/adapters/process.js.map +1 -0
- package/dist/host/adapters/processReadouts.d.ts +10 -0
- package/dist/host/adapters/processReadouts.d.ts.map +1 -0
- package/dist/host/adapters/processReadouts.js +26 -0
- package/dist/host/adapters/processReadouts.js.map +1 -0
- package/dist/host/process.d.ts +26 -0
- package/dist/host/process.d.ts.map +1 -0
- package/dist/host/process.js +56 -0
- package/dist/host/process.js.map +1 -0
- package/dist/host/processChild.d.ts +7 -0
- package/dist/host/processChild.d.ts.map +1 -0
- package/dist/host/processChild.js +19 -0
- package/dist/host/processChild.js.map +1 -0
- package/dist/host/processProtocol.d.ts +20 -0
- package/dist/host/processProtocol.d.ts.map +1 -0
- package/dist/host/processProtocol.js +11 -0
- package/dist/host/processProtocol.js.map +1 -0
- package/dist/host/processReadouts.d.ts +7 -0
- package/dist/host/processReadouts.d.ts.map +1 -0
- package/dist/host/processReadouts.js +37 -0
- package/dist/host/processReadouts.js.map +1 -0
- package/dist/host/time.d.ts +9 -0
- package/dist/host/time.d.ts.map +1 -0
- package/dist/host/time.js +27 -0
- package/dist/host/time.js.map +1 -0
- package/dist/identity/adapters/oauthAuthorization.d.ts +20 -0
- package/dist/identity/adapters/oauthAuthorization.d.ts.map +1 -0
- package/dist/identity/adapters/oauthAuthorization.js +39 -0
- package/dist/identity/adapters/oauthAuthorization.js.map +1 -0
- package/dist/identity/adapters/oauthProtocol.d.ts +9 -0
- package/dist/identity/adapters/oauthProtocol.d.ts.map +1 -0
- package/dist/identity/adapters/oauthProtocol.js +105 -0
- package/dist/identity/adapters/oauthProtocol.js.map +1 -0
- package/dist/identity/adapters/oidcTokens.d.ts +39 -0
- package/dist/identity/adapters/oidcTokens.d.ts.map +1 -0
- package/dist/identity/adapters/oidcTokens.js +39 -0
- package/dist/identity/adapters/oidcTokens.js.map +1 -0
- package/dist/identity/oauth.d.ts +43 -0
- package/dist/identity/oauth.d.ts.map +1 -0
- package/dist/identity/oauth.js +20 -0
- package/dist/identity/oauth.js.map +1 -0
- package/dist/webhooks/adapters/githubHeaders.d.ts +5 -0
- package/dist/webhooks/adapters/githubHeaders.d.ts.map +1 -0
- package/dist/webhooks/adapters/githubHeaders.js +6 -0
- package/dist/webhooks/adapters/githubHeaders.js.map +1 -0
- package/dist/webhooks/deliver.d.ts +13 -0
- package/dist/webhooks/deliver.d.ts.map +1 -0
- package/dist/webhooks/deliver.js +20 -0
- package/dist/webhooks/deliver.js.map +1 -0
- package/package.json +13 -11
- package/src/contract/settledQueries.ts +39 -0
- package/src/github/adapters/appProvider.ts +34 -0
- package/src/github/adapters/credentials.ts +62 -0
- package/src/github/adapters/webhookDelivery.ts +20 -0
- package/src/github/fake.ts +30 -0
- package/src/host/ProcessError.ts +6 -0
- package/src/host/adapters/process.ts +122 -0
- package/src/host/adapters/processReadouts.ts +29 -0
- package/src/host/process.ts +69 -0
- package/src/host/processChild.ts +25 -0
- package/src/host/processProtocol.ts +11 -0
- package/src/host/processReadouts.ts +46 -0
- package/src/host/time.ts +33 -0
- package/src/identity/adapters/oauthAuthorization.ts +54 -0
- package/src/identity/adapters/oauthProtocol.ts +111 -0
- package/src/identity/adapters/oidcTokens.ts +42 -0
- package/src/identity/oauth.ts +35 -0
- package/src/webhooks/adapters/githubHeaders.ts +6 -0
- package/src/webhooks/deliver.ts +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 - 2026-11-05
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Publish host process and controlled clock helpers, settled query observations and signed webhook delivery helpers.
|
|
8
|
+
- Publish `fakeOauthProvider` for application sign-in stories over real HTTP, with OAuth authorization codes, consent refusal, controlled expiry, profiles and OIDC discovery with signed ID tokens.
|
|
9
|
+
|
|
10
|
+
## 0.5.0 - 2026-11-04
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Publish a scoped fake GitHub App with real HTTP installation-token exchanges, configurable REST and GraphQL routes, provider fault controls and signed webhook delivery for application stories.
|
|
15
|
+
|
|
3
16
|
## 0.4.0 - 2026-11-04
|
|
4
17
|
|
|
5
18
|
### Added
|
package/README.md
CHANGED
|
@@ -27,10 +27,48 @@ 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
|
+
### Social sign-in
|
|
31
|
+
|
|
32
|
+
Import `fakeOauthProvider` from `@shivaedev/test-kits/identity/oauth.ts` and acquire it in the story's scope. It runs a loopback OAuth 2.0 / OpenID Connect provider; the application's real Better Auth mount handles the redirects, code exchange and session creation.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const provider = yield* fakeOauthProvider({
|
|
36
|
+
profile: { sub: "123", email: "alice@example.test", name: "Alice" },
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Use `provider.credentials.clientId` and `clientSecret` in Better Auth. For OIDC, configure its `genericOAuth` plugin with `discoveryUrl: provider.discoveryUrl`, scopes `openid`, `profile`, `email` and `requireIdTokenVerification: true`. Drive `signIn.social` with that provider's ID. The provider publishes RS256 signing keys through JWKS and returns signed ID tokens. For GitHub, use `routeOutbound` from `@shivaedev/test-story/server/routeOutbound.ts` to route `github.com` and `api.github.com` to `provider.server.url` while retaining the real GitHub client.
|
|
41
|
+
|
|
42
|
+
Consent is accepted by default; yield `provider.refuseConsent()` before visiting the authorization URL to return `access_denied` with the original state. Codes are single-use, bound to the client and redirect URI, and expire after one minute on the acquiring Effect Clock. Set `codeLifetime` to an Effect duration to change that interval. Advance the story clock between the provider redirect and the app callback to exercise expiry. S256 PKCE is checked when the client supplies a challenge. Token exchanges accept client credentials in POST fields or HTTP Basic authentication; issued bearer tokens grant profile access for one hour.
|
|
43
|
+
|
|
44
|
+
`profile` accepts a subject, email, name and optional `emailVerified` (default true), or a function of the authorization request for multi-user stories. `routes` adds provider-specific HTTP endpoints, such as organization membership. `provider.server` exposes test-story's request observations, holds and fault controls. Keep that composition in the application's story kit. This provider covers authorization-code sign-in; refresh grants, provider logout and a browser consent screen are outside its scope.
|
|
45
|
+
|
|
30
46
|
### Discord bots
|
|
31
47
|
|
|
32
48
|
Import `fakeDiscord` from `@shivaedev/test-kits/discord/fake.ts` and acquire it in a scope. Its loopback `server` retains messages across creation, editing, history reads and deletion, and supports the standard fake HTTP fault controls. Use the token `story-discord-token` with the real Discord REST client and set its API URL to `server.url`. Provide `gateway.transport` as the real gateway client's `GatewayTransport`; it speaks identify, heartbeat and resume frames, retains sessions and replays dispatches emitted during a dropped connection. `gateway.dispatch(type, data)`, `drop(code?)` and `invalidate(resumable)` change the provider, while `frames` and `urls` expose outbound observations. Drive reconnect and rate-limit time through the story kit's controlled clock.
|
|
33
49
|
|
|
50
|
+
### GitHub Apps
|
|
51
|
+
|
|
52
|
+
Import `fakeGitHubApp` from `@shivaedev/test-kits/github/fake.ts` and acquire it in a scope. The provider exchanges signed App JWTs for installation tokens over loopback HTTP. Give the real `@shivaedev/github` client its `credentials.appId`, redacted `credentials.privateKey`, an installation ID and `server.url` as `GitHubConfig.apiUrl`.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const github = yield* fakeGitHubApp({
|
|
56
|
+
routes: ({ installationToken }) => ({
|
|
57
|
+
repository: {
|
|
58
|
+
guard: installationToken,
|
|
59
|
+
path: "/repos/acme/widgets/issues/3",
|
|
60
|
+
reply: () => ({ body: { title: "Ship widgets" } }),
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`routes` uses test-story's named fake HTTP routes for REST reads and writes and GraphQL POSTs. `installationToken` admits issued tokens, `installationOf(request)` returns their installation ID, and `appRequest` checks an App JWT. Routes own their paths; `prefix` changes the token exchange path for Enterprise API bases. Supply `credentials` from `githubAppCredentials()` in `@shivaedev/test-kits/github/adapters/credentials.ts` when several fixtures need the same App key.
|
|
67
|
+
|
|
68
|
+
`server.requests` records method, path, headers and raw body; `server.scriptFault`, `hold` and the other fake HTTP controls drive rate limits and delayed or refused exchanges. Return rate-limit headers on routes or script a 403/429 reply with `retry-after` to exercise the real client's typed rate-limit handling. The kit does not simulate a GitHub database or interpret GraphQL queries: route replies describe the outside provider's data.
|
|
69
|
+
|
|
70
|
+
`deliverWebhook(url, { body, event, deliveryId })` sends the exact body bytes over HTTP with GitHub event, delivery and HMAC signature headers, consumes the receiver's response and returns its status. Configure the receiver with `credentials.webhookSecret`; `credentials.webhookSignature(body)` is available for signature-specific stories. Drive token expiry and rate-limit time through the story clock. No client implementation is replaced.
|
|
71
|
+
|
|
34
72
|
### MCP bearer tokens
|
|
35
73
|
|
|
36
74
|
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:
|
|
@@ -136,6 +174,10 @@ yield* testing.untilJob(SendEmail, id, "completed", { within: "5 seconds" });
|
|
|
136
174
|
// Gave up after 5s waiting until job <id> in send-email is completed; last seen: retry
|
|
137
175
|
```
|
|
138
176
|
|
|
177
|
+
### Host processes and query observations
|
|
178
|
+
|
|
179
|
+
Import `hostProcess`, `hostProcessReadouts`, `hostTime` and the child IPC helpers from their modules under `@shivaedev/test-kits/host/`. The [host guide](https://github.com/ShivaeDev/platform/tree/main/packages/server#readme) describes real-process setup and lifecycle observations. `hostTime` provides SQL’s `WorkerReleaseClock` scheduling port with the story’s controlled clock. Query observations use `settledQueries` from `@shivaedev/test-kits/contract/settledQueries.ts`; signed webhook senders use `deliverWebhook` from `@shivaedev/test-kits/webhooks/deliver.ts`.
|
|
180
|
+
|
|
139
181
|
### Development setup
|
|
140
182
|
|
|
141
183
|
Install `@shivaedev/test-kits` as a development dependency alongside `effect`, Better Auth and the runtime packages used by the kit. The package depends on `@shivaedev/test-story` and `@shivaedev/test-sql`; runtime packages are peers. The [story-testing skill](https://github.com/ShivaeDev/platform/blob/main/packages/skills/skills/story-testing/SKILL.md) describes how to compose an application's facade and prove its behavior.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
4
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
5
|
+
export interface SettledQueries<A, E> {
|
|
6
|
+
readonly latest: Effect.Effect<AsyncResult.AsyncResult<A, E>>;
|
|
7
|
+
readonly next: Effect.Effect<AsyncResult.AsyncResult<A, E>>;
|
|
8
|
+
}
|
|
9
|
+
export declare const settledQueries: <A, E>(query: Atom.Atom<AsyncResult.AsyncResult<A, E>>) => Effect.Effect<{
|
|
10
|
+
latest: Effect.Effect<AsyncResult.AsyncResult<A, E>, never, never>;
|
|
11
|
+
next: Effect.Effect<AsyncResult.AsyncResult<A, E>, never, never>;
|
|
12
|
+
}, never, AtomRegistry.AtomRegistry | import("effect/Scope").Scope>;
|
|
13
|
+
//# sourceMappingURL=settledQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settledQueries.d.ts","sourceRoot":"","sources":["../../src/contract/settledQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAG/D,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,cAAc,GAAmD,CAAC,EAAE,CAAC;;;mEA2BhF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect, Queue } from "effect";
|
|
2
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import { querySignals } from "@shivaedev/contract/querySignals.ts";
|
|
4
|
+
export const settledQueries = Effect.fn("Contract.settledQueries")(function* (query) {
|
|
5
|
+
const registry = yield* AtomRegistry.AtomRegistry;
|
|
6
|
+
const results = yield* Queue.unbounded();
|
|
7
|
+
let completed = 0;
|
|
8
|
+
yield* Effect.acquireRelease(Effect.sync(() => registry.mount(query)), (stop) => Effect.sync(stop));
|
|
9
|
+
yield* Effect.acquireRelease(Effect.sync(() => registry.subscribe(querySignals(query), (state) => {
|
|
10
|
+
if (!state.pending && state.completed > completed) {
|
|
11
|
+
completed = state.completed;
|
|
12
|
+
Queue.offerUnsafe(results, registry.get(query));
|
|
13
|
+
}
|
|
14
|
+
}, { immediate: true })), (stop) => Effect.sync(stop));
|
|
15
|
+
return {
|
|
16
|
+
latest: Effect.sync(() => registry.get(query)),
|
|
17
|
+
next: Queue.take(results),
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=settledQueries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settledQueries.js","sourceRoot":"","sources":["../../src/contract/settledQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGvC,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAOnE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,QAAQ,CAAC,E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Request } from "@shivaedev/test-story/server/fakeHttpService.ts";
|
|
3
|
+
import type { GitHubAppAccess } from "#github/fake.ts";
|
|
4
|
+
import type { AppJwt } from "./credentials.ts";
|
|
5
|
+
export declare const appProvider: (credentials: {
|
|
6
|
+
appId: string;
|
|
7
|
+
appJwtOf: (authorization: string | undefined, nowMillis: number) => AppJwt | undefined;
|
|
8
|
+
privateKey: string;
|
|
9
|
+
signedByApp: (jwt: AppJwt | undefined) => boolean;
|
|
10
|
+
tokenPrefix: string;
|
|
11
|
+
webhookSecret: string;
|
|
12
|
+
webhookSignature: (body: Uint8Array) => string;
|
|
13
|
+
}, prefix: string) => Effect.Effect<{
|
|
14
|
+
access: GitHubAppAccess;
|
|
15
|
+
state: {
|
|
16
|
+
exchanges: number;
|
|
17
|
+
jwts: (AppJwt | undefined)[];
|
|
18
|
+
};
|
|
19
|
+
token: {
|
|
20
|
+
guard: (request: FakeHttpRequest) => boolean;
|
|
21
|
+
method: string;
|
|
22
|
+
path: string;
|
|
23
|
+
reply: (request: FakeHttpRequest) => {
|
|
24
|
+
body: {
|
|
25
|
+
expires_at: string;
|
|
26
|
+
token: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}, never, never>;
|
|
31
|
+
//# sourceMappingURL=appProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appProvider.d.ts","sourceRoot":"","sources":["../../../src/github/adapters/appProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAwB,MAAM,kBAAkB,CAAC;AAErE,eAAO,MAAM,WAAW;;;;;;;;;;;mBAEG,MAAM;cAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE;;;QAe5D,KAAK;QACL,MAAM;QACN,IAAI;QACJ,KAAK,YAAY,eAAe;;;;;;;gBAQjC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Clock, Effect } from "effect";
|
|
2
|
+
export const appProvider = Effect.fnUntraced(function* (credentials, prefix) {
|
|
3
|
+
const clock = yield* Clock.Clock;
|
|
4
|
+
const state = { exchanges: 0, jwts: [] };
|
|
5
|
+
const tokens = new Map();
|
|
6
|
+
const access = {
|
|
7
|
+
appRequest: (request) => {
|
|
8
|
+
const jwt = credentials.appJwtOf(request.headers.authorization, clock.currentTimeMillisUnsafe());
|
|
9
|
+
state.jwts.push(jwt);
|
|
10
|
+
return credentials.signedByApp(jwt);
|
|
11
|
+
},
|
|
12
|
+
installationOf: (request) => tokens.get(request.headers.authorization ?? ""),
|
|
13
|
+
installationToken: (request) => tokens.has(request.headers.authorization ?? ""),
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
access,
|
|
17
|
+
state,
|
|
18
|
+
token: {
|
|
19
|
+
guard: access.appRequest,
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: `${prefix}/app/installations/:installationId/access_tokens`,
|
|
22
|
+
reply: (request) => {
|
|
23
|
+
state.exchanges += 1;
|
|
24
|
+
const token = `${credentials.tokenPrefix}-${state.exchanges}`;
|
|
25
|
+
tokens.set(`Bearer ${token}`, Number(request.params.installationId));
|
|
26
|
+
return { body: { "expires_at": new Date(clock.currentTimeMillisUnsafe() + 3_600_000).toISOString(), token } };
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=appProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appProvider.js","sourceRoot":"","sources":["../../../src/github/adapters/appProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKvC,MAAM,CAA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AE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;gBACrE,OAAO,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;YAC/G,CAAC;SACD;KACD,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
export declare function githubAppCredentials(): {
|
|
3
|
+
appId: string;
|
|
4
|
+
appJwtOf: (authorization: string | undefined, nowMillis: number) => AppJwt | undefined;
|
|
5
|
+
privateKey: string;
|
|
6
|
+
signedByApp: (jwt: AppJwt | undefined) => boolean;
|
|
7
|
+
tokenPrefix: string;
|
|
8
|
+
webhookSecret: string;
|
|
9
|
+
webhookSignature: (body: Uint8Array) => string;
|
|
10
|
+
};
|
|
11
|
+
export interface AppJwt {
|
|
12
|
+
readonly algorithm: string;
|
|
13
|
+
readonly expiresIn: number;
|
|
14
|
+
readonly issuedAgo: number;
|
|
15
|
+
readonly issuer: string;
|
|
16
|
+
readonly signedBy: "the App's key" | "another key";
|
|
17
|
+
readonly type: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function appJwtOf(publicKey: KeyObject, authorization: string | undefined, nowMillis: number): AppJwt | undefined;
|
|
20
|
+
export declare function signedByApp(appId: string, jwt: AppJwt | undefined): boolean;
|
|
21
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../src/github/adapters/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,SAAS,EAAU,MAAM,aAAa,CAAC;AAGtF,wBAAgB,oBAAoB;;8BAMR,MAAM,GAAG,SAAS,aAAa,MAAM;;uBAE5C,MAAM,GAAG,SAAS;;;6BAGZ,UAAU;EAEpC;AAKD,MAAM,WAAW,MAAM;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,aAAa,CAAC;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBvH;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,WAWjE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createHmac, generateKeyPairSync, verify } from "node:crypto";
|
|
2
|
+
import { Option, Schema } from "effect";
|
|
3
|
+
export function githubAppCredentials() {
|
|
4
|
+
const keys = generateKeyPairSync("rsa", { modulusLength: 2048 });
|
|
5
|
+
const appId = "123456";
|
|
6
|
+
const webhookSecret = "webhook-secret";
|
|
7
|
+
return {
|
|
8
|
+
appId,
|
|
9
|
+
appJwtOf: (authorization, nowMillis) => appJwtOf(keys.publicKey, authorization, nowMillis),
|
|
10
|
+
privateKey: keys.privateKey.export({ format: "pem", type: "pkcs8" }).toString(),
|
|
11
|
+
signedByApp: (jwt) => signedByApp(appId, jwt),
|
|
12
|
+
tokenPrefix: "installation-token-secret",
|
|
13
|
+
webhookSecret,
|
|
14
|
+
webhookSignature: (body) => `sha256=${createHmac("sha256", webhookSecret).update(body).digest("hex")}`,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const Claims = Schema.fromJsonString(Schema.Struct({ exp: Schema.Number, iat: Schema.Number, iss: Schema.String }));
|
|
18
|
+
const Header = Schema.fromJsonString(Schema.Struct({ alg: Schema.String, typ: Schema.String }));
|
|
19
|
+
export function appJwtOf(publicKey, authorization, nowMillis) {
|
|
20
|
+
const [header = "", payload = "", signature = ""] = (authorization?.replace(/^Bearer /u, "") ?? "").split(".");
|
|
21
|
+
const claims = Schema.decodeUnknownOption(Claims)(Buffer.from(payload, "base64url").toString());
|
|
22
|
+
const fields = Schema.decodeUnknownOption(Header)(Buffer.from(header, "base64url").toString());
|
|
23
|
+
if (Option.isNone(claims) || Option.isNone(fields)) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const now = nowMillis / 1000;
|
|
27
|
+
return {
|
|
28
|
+
algorithm: fields.value.alg,
|
|
29
|
+
expiresIn: claims.value.exp - now,
|
|
30
|
+
issuedAgo: now - claims.value.iat,
|
|
31
|
+
issuer: claims.value.iss,
|
|
32
|
+
signedBy: verify("RSA-SHA256", Buffer.from(`${header}.${payload}`), publicKey, Buffer.from(signature, "base64url"))
|
|
33
|
+
? "the App's key"
|
|
34
|
+
: "another key",
|
|
35
|
+
type: fields.value.typ,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function signedByApp(appId, jwt) {
|
|
39
|
+
return (jwt !== undefined
|
|
40
|
+
&& jwt.signedBy === "the App's key"
|
|
41
|
+
&& jwt.algorithm === "RS256"
|
|
42
|
+
&& jwt.issuer === appId
|
|
43
|
+
&& jwt.issuedAgo >= 0
|
|
44
|
+
&& jwt.issuedAgo <= 600
|
|
45
|
+
&& jwt.expiresIn > 0
|
|
46
|
+
&& jwt.expiresIn <= 600);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/github/adapters/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAkB,MAAM,EAAE,MAAM,aAAa,CAAC;AACtF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AG;KACtB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,GAAuB;IACjE,OAAO,CACN,GAAG,KAAK,SAAS;WACd,GAAG,CAAC,QAAQ,KAAK,eAAe;WAChC,GAAG,CAAC,SAAS,KAAK,OAAO;WACzB,GAAG,CAAC,MAAM,KAAK,KAAK;WACpB,GAAG,CAAC,SAAS,IAAI,CAAC;WAClB,GAAG,CAAC,SAAS,IAAI,GAAG;WACpB,GAAG,CAAC,SAAS,GAAG,CAAC;WACjB,GAAG,CAAC,SAAS,IAAI,GAAG,CACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
export declare function webhookDelivery(sign: (body: Uint8Array) => string): (url: string, delivery: {
|
|
3
|
+
readonly body: Uint8Array;
|
|
4
|
+
readonly event: string;
|
|
5
|
+
readonly deliveryId: string;
|
|
6
|
+
}) => Effect.Effect<number, import("effect/http/HttpClientError").HttpClientError, never>;
|
|
7
|
+
//# sourceMappingURL=webhookDelivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhookDelivery.d.ts","sourceRoot":"","sources":["../../../src/github/adapters/webhookDelivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,wBAAgB,eAAe,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM;mBACW,UAAU;oBAAkB,MAAM;yBAAuB,MAAM;0FAe3I"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
3
|
+
export function webhookDelivery(sign) {
|
|
4
|
+
return Effect.fnUntraced(function* (url, delivery) {
|
|
5
|
+
const client = yield* HttpClient.HttpClient;
|
|
6
|
+
const response = yield* client.execute(HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders({
|
|
7
|
+
"x-github-delivery": delivery.deliveryId,
|
|
8
|
+
"x-github-event": delivery.event,
|
|
9
|
+
"x-hub-signature-256": sign(delivery.body),
|
|
10
|
+
}), HttpClientRequest.bodyUint8Array(delivery.body, "application/json")));
|
|
11
|
+
yield* response.text;
|
|
12
|
+
return response.status;
|
|
13
|
+
}, Effect.provide(FetchHttpClient.layer));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=webhookDelivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhookDelivery.js","sourceRoot":"","sources":["../../../src/github/adapters/webhookDelivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,UAAU,eAAe,CAAC,IAAkC;IACjE,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,GAAW,EAAE,QAA4F;QAC5I,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;QAC5C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CACrC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC/B,iBAAiB,CAAC,UAAU,CAAC;YAC5B,mBAAmB,EAAE,QAAQ,CAAC,UAAU;YACxC,gBAAgB,EAAE,QAAQ,CAAC,KAAK;YAChC,qBAAqB,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;SAC1C,CAAC,EACF,iBAAiB,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC,CACnE,CACD,CAAC;QACF,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrB,OAAO,QAAQ,CAAC,MAAM,CAAC;IACxB,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type FakeHttpRequest, type FakeHttpRoute } from "@shivaedev/test-story/server/fakeHttpService.ts";
|
|
3
|
+
import { githubAppCredentials } from "#github/adapters/credentials.ts";
|
|
4
|
+
export interface GitHubAppAccess {
|
|
5
|
+
readonly appRequest: (request: FakeHttpRequest) => boolean;
|
|
6
|
+
readonly installationOf: (request: FakeHttpRequest) => number | undefined;
|
|
7
|
+
readonly installationToken: (request: FakeHttpRequest) => boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const fakeGitHubApp: (options?: {
|
|
10
|
+
readonly credentials?: ReturnType<typeof githubAppCredentials>;
|
|
11
|
+
readonly prefix?: string;
|
|
12
|
+
readonly routes?: (access: GitHubAppAccess) => Readonly<Record<string, FakeHttpRoute>>;
|
|
13
|
+
} | undefined) => Effect.Effect<{
|
|
14
|
+
credentials: {
|
|
15
|
+
appId: string;
|
|
16
|
+
appJwtOf: (authorization: string | undefined, nowMillis: number) => import("#github/adapters/credentials.ts").AppJwt | undefined;
|
|
17
|
+
privateKey: string;
|
|
18
|
+
signedByApp: (jwt: import("#github/adapters/credentials.ts").AppJwt | undefined) => boolean;
|
|
19
|
+
tokenPrefix: string;
|
|
20
|
+
webhookSecret: string;
|
|
21
|
+
webhookSignature: (body: Uint8Array) => string;
|
|
22
|
+
};
|
|
23
|
+
deliverWebhook: (url: string, delivery: {
|
|
24
|
+
readonly body: Uint8Array;
|
|
25
|
+
readonly event: string;
|
|
26
|
+
readonly deliveryId: string;
|
|
27
|
+
}) => Effect.Effect<number, import("effect/http/HttpClientError").HttpClientError, never>;
|
|
28
|
+
server: {
|
|
29
|
+
completed: import("effect/Stream").Stream<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord, never, never>;
|
|
30
|
+
fault: (route: string, fault: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpFault, scope?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScope) => Effect.Effect<void, never, never>;
|
|
31
|
+
hold: (route: string, holdOptions?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpHoldOptions) => Effect.Effect<{
|
|
32
|
+
release: Effect.Effect<void, never, never>;
|
|
33
|
+
waiting: Effect.Effect<void, never, never>;
|
|
34
|
+
}, never, never>;
|
|
35
|
+
narrate: (sink: (line: string) => void) => void;
|
|
36
|
+
received: import("effect/Stream").Stream<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord, never, never>;
|
|
37
|
+
releaseOnArrival: (route: string, arrival: string, scope?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScope) => Effect.Effect<void, never, never>;
|
|
38
|
+
readonly requests: readonly import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord[];
|
|
39
|
+
scriptFault: (route: string, fault: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpFault, scriptOptions?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScriptOptions) => Effect.Effect<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScript, never, never>;
|
|
40
|
+
stall: (route: string, scope?: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpScope) => Effect.Effect<{
|
|
41
|
+
release: Effect.Effect<void, never, never>;
|
|
42
|
+
waiting: Effect.Effect<void, never, never>;
|
|
43
|
+
}, never, never>;
|
|
44
|
+
untilAbandoned: (matches: (request: import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord) => boolean, wait: import("@shivaedev/test-story/server/until.ts").UntilOptions) => Effect.Effect<import("@shivaedev/test-story/server/fakeHttpService.ts").FakeHttpRequestRecord, import("@shivaedev/test-story/server/until.ts").SignalNotReceived, never>;
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
47
|
+
state: {
|
|
48
|
+
exchanges: number;
|
|
49
|
+
jwts: (import("#github/adapters/credentials.ts").AppJwt | undefined)[];
|
|
50
|
+
};
|
|
51
|
+
}, import("effect/Cause").UnknownError, import("effect/Scope").Scope>;
|
|
52
|
+
//# sourceMappingURL=fake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.d.ts","sourceRoot":"","sources":["../../src/github/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAmB,MAAM,iDAAiD,CAAC;AAE5H,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC;IAC3D,QAAQ,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,GAAG,SAAS,CAAC;IAC1E,QAAQ,CAAC,iBAAiB,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC;CAClE;AAED,eAAO,MAAM,aAAa;2BAED,UAAU,CAAC,OAAO,oBAAoB,CAAC;sBAC5C,MAAM;sBACN,CAAC,MAAM,EAAE,eAAe,KAAK,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAatF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { fakeHttpService } from "@shivaedev/test-story/server/fakeHttpService.ts";
|
|
3
|
+
import { appProvider } from "#github/adapters/appProvider.ts";
|
|
4
|
+
import { githubAppCredentials } from "#github/adapters/credentials.ts";
|
|
5
|
+
import { webhookDelivery } from "#github/adapters/webhookDelivery.ts";
|
|
6
|
+
export const fakeGitHubApp = Effect.fnUntraced(function* (options = {}) {
|
|
7
|
+
const credentials = options.credentials ?? githubAppCredentials();
|
|
8
|
+
const prefix = options.prefix ?? "";
|
|
9
|
+
const { access, state, token } = yield* appProvider(credentials, prefix);
|
|
10
|
+
const server = yield* fakeHttpService({
|
|
11
|
+
routes: {
|
|
12
|
+
token,
|
|
13
|
+
...options.routes?.(access),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
return { credentials, deliverWebhook: webhookDelivery(credentials.webhookSignature), server, state };
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=fake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.js","sourceRoot":"","sources":["../../src/github/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAA4C,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAC5H,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAQtE,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EACvD,OAAO,GAIH,EAAE;IAEN,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,oBAAoB,EAAE,CAAC;IAClE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC;QACrC,MAAM,EAAE;YACP,KAAK;YACL,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC;SAC3B;KACD,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACtG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const HostProcessError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
2
|
+
readonly _tag: "HostProcessError";
|
|
3
|
+
} & Readonly<A>;
|
|
4
|
+
export declare class HostProcessError extends HostProcessError_base<{
|
|
5
|
+
readonly operation: "launch" | "signal" | "request" | "readout";
|
|
6
|
+
readonly cause: unknown;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=ProcessError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessError.d.ts","sourceRoot":"","sources":["../../src/host/ProcessError.ts"],"names":[],"mappings":";;;AAEA,qBAAa,gBAAiB,SAAQ,sBAAqC;IAC1E,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACxB,CAAC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessError.js","sourceRoot":"","sources":["../../src/host/ProcessError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAGvE;CAAG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
import { type Redacted, Schema } from "effect";
|
|
3
|
+
export interface HostProcessOptions {
|
|
4
|
+
readonly args?: readonly string[];
|
|
5
|
+
readonly cwd?: string;
|
|
6
|
+
readonly databaseUrl?: Redacted.Redacted<string>;
|
|
7
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
8
|
+
readonly execArgv?: readonly string[];
|
|
9
|
+
readonly module: string | URL;
|
|
10
|
+
}
|
|
11
|
+
export declare function forkHost(options: HostProcessOptions, databaseUrl?: string): ChildProcess;
|
|
12
|
+
export declare function receiveHostMessage<A>(child: ChildProcess, schema: Schema.Codec<A>, signal: AbortSignal, action?: () => void): Promise<A>;
|
|
13
|
+
export declare function stopHost(child: ChildProcess): Promise<void>;
|
|
14
|
+
export declare function sendHostMessage(message: unknown): Promise<void>;
|
|
15
|
+
export declare function sendHostReady(url: string): Promise<void>;
|
|
16
|
+
export declare function waitForHostStart(signal: AbortSignal): Promise<void>;
|
|
17
|
+
export declare function hostResponse(url: string, path: string, signal: AbortSignal): Promise<{
|
|
18
|
+
body: string;
|
|
19
|
+
headers: {
|
|
20
|
+
[k: string]: string;
|
|
21
|
+
};
|
|
22
|
+
status: number;
|
|
23
|
+
}>;
|
|
24
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../src/host/adapters/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAA0B,MAAM,oBAAoB,CAAC;AAG/E,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;CAC9B;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,EAAE,WAAW,CAAC,EAAE,MAAM,gBAQzE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM,IAAI,cAyC3H;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,iBAQ3C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,iBAQ/C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,iBAExC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,iBAyBnD;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;;;;;;GAGhF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { fork } from "node:child_process";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { Option, Schema } from "effect";
|
|
5
|
+
export function forkHost(options, databaseUrl) {
|
|
6
|
+
const settings = {
|
|
7
|
+
cwd: options.cwd,
|
|
8
|
+
env: databaseUrl === undefined ? options.env : { ...options.env, "DATABASE_URL": databaseUrl },
|
|
9
|
+
execArgv: [...(options.execArgv ?? [])],
|
|
10
|
+
stdio: ["ignore", "ignore", "inherit", "ipc"],
|
|
11
|
+
};
|
|
12
|
+
return fork(typeof options.module === "string" ? options.module : fileURLToPath(options.module), [...(options.args ?? [])], settings);
|
|
13
|
+
}
|
|
14
|
+
export function receiveHostMessage(child, schema, signal, action) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
function cleanup() {
|
|
17
|
+
child.off("message", message);
|
|
18
|
+
child.off("exit", exited);
|
|
19
|
+
child.off("error", failed);
|
|
20
|
+
signal.removeEventListener("abort", aborted);
|
|
21
|
+
}
|
|
22
|
+
function failed(cause) {
|
|
23
|
+
cleanup();
|
|
24
|
+
reject(cause);
|
|
25
|
+
}
|
|
26
|
+
function exited(code, delivered) {
|
|
27
|
+
failed(new Error(`Host exited (${delivered ?? code}) before IPC acknowledgement`));
|
|
28
|
+
}
|
|
29
|
+
function aborted() {
|
|
30
|
+
failed(signal.reason);
|
|
31
|
+
}
|
|
32
|
+
function message(value) {
|
|
33
|
+
const decoded = Schema.decodeUnknownOption(schema)(value);
|
|
34
|
+
if (Option.isSome(decoded)) {
|
|
35
|
+
cleanup();
|
|
36
|
+
resolve(decoded.value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
child.on("message", message);
|
|
40
|
+
child.once("exit", exited);
|
|
41
|
+
child.once("error", failed);
|
|
42
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
43
|
+
if (signal.aborted) {
|
|
44
|
+
aborted();
|
|
45
|
+
}
|
|
46
|
+
else if (child.exitCode !== null || child.signalCode !== null) {
|
|
47
|
+
exited(child.exitCode, child.signalCode);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
try {
|
|
51
|
+
action?.();
|
|
52
|
+
}
|
|
53
|
+
catch (cause) {
|
|
54
|
+
failed(cause);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export function stopHost(child) {
|
|
60
|
+
if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) {
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
}
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
child.once("exit", () => resolve());
|
|
65
|
+
child.kill("SIGKILL");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function sendHostMessage(message) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
if (process.send === undefined) {
|
|
71
|
+
reject(new Error("Host process needs a parent IPC channel"));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
process.send(message, (error) => (error === null ? resolve() : reject(error)));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function sendHostReady(url) {
|
|
78
|
+
return sendHostMessage({ pid: process.pid, type: "host-ready", url });
|
|
79
|
+
}
|
|
80
|
+
export function waitForHostStart(signal) {
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
function cleanup() {
|
|
83
|
+
process.off("SIGUSR2", start);
|
|
84
|
+
signal.removeEventListener("abort", aborted);
|
|
85
|
+
}
|
|
86
|
+
function failed(cause) {
|
|
87
|
+
cleanup();
|
|
88
|
+
reject(cause);
|
|
89
|
+
}
|
|
90
|
+
function start() {
|
|
91
|
+
cleanup();
|
|
92
|
+
resolve();
|
|
93
|
+
}
|
|
94
|
+
function aborted() {
|
|
95
|
+
failed(signal.reason);
|
|
96
|
+
}
|
|
97
|
+
process.once("SIGUSR2", start);
|
|
98
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
99
|
+
if (signal.aborted) {
|
|
100
|
+
aborted();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
void sendHostMessage({ type: "host-prepared" }).catch(failed);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export async function hostResponse(url, path, signal) {
|
|
108
|
+
const response = await fetch(new URL(path, url), { redirect: "manual", signal });
|
|
109
|
+
return { body: await response.text(), headers: Object.fromEntries(response.headers), status: response.status };
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../../src/host/adapters/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,a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0,0 +1,10 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import { HostReadouts } from "#host/processProtocol.ts";
|
|
3
|
+
export declare function listenHostReadouts(read: () => typeof HostReadouts.Type): () => NodeJS.Process;
|
|
4
|
+
export declare function collectHostReadouts(child: ChildProcess): (signal: AbortSignal) => Promise<{
|
|
5
|
+
readonly activeWork: readonly string[];
|
|
6
|
+
readonly finalizers: readonly string[];
|
|
7
|
+
readonly shutdownDuration: number | null;
|
|
8
|
+
readonly type: "host-readouts";
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=processReadouts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processReadouts.d.ts","sourceRoot":"","sources":["../../../src/host/adapters/processReadouts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,OAAO,YAAY,CAAC,IAAI,wBAQtE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,YAQtC,WAAW;;;;;GAI3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { Option, Predicate, Schema } from "effect";
|
|
3
|
+
import { HostReadouts } from "#host/processProtocol.ts";
|
|
4
|
+
import { receiveHostMessage } from "./process.js";
|
|
5
|
+
export function listenHostReadouts(read) {
|
|
6
|
+
function requested(message) {
|
|
7
|
+
if (Predicate.hasProperty(message, "type") && message.type === "host-readouts") {
|
|
8
|
+
process.send?.(read());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
process.on("message", requested);
|
|
12
|
+
return () => process.off("message", requested);
|
|
13
|
+
}
|
|
14
|
+
export function collectHostReadouts(child) {
|
|
15
|
+
let completed;
|
|
16
|
+
child.on("message", (message) => {
|
|
17
|
+
const decoded = Schema.decodeUnknownOption(HostReadouts)(message);
|
|
18
|
+
if (Option.isSome(decoded) && decoded.value.shutdownDuration !== null) {
|
|
19
|
+
completed = decoded.value;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return (signal) => completed === undefined
|
|
23
|
+
? receiveHostMessage(child, HostReadouts, signal, () => child.send({ type: "host-readouts" }))
|
|
24
|
+
: Promise.resolve(completed);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=processReadouts.js.map
|