@volter/twin-polar 0.1.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/LICENSE +202 -0
- package/README.md +36 -0
- package/package.json +43 -0
- package/src/cli.ts +25 -0
- package/src/index.ts +70 -0
- package/src/polar-budget.ts +443 -0
- package/src/polar-capabilities.ts +413 -0
- package/src/polar-conformance.ts +33 -0
- package/src/polar-connector.ts +155 -0
- package/src/polar-server.ts +33 -0
- package/src/polar-twin.ts +828 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Polar twin HTTP server — serve the full Polar API twin handler over HTTP so the real
|
|
2
|
+
// `@polar-sh/sdk` (pointed at this base URL) works unmodified. JSON bodies pass through to the
|
|
3
|
+
// handler. Writable by default; pass readOnly to reject writes with 405 (D3). State is the
|
|
4
|
+
// kernel projection (no side-store) — see polar-twin.ts.
|
|
5
|
+
//
|
|
6
|
+
// FETCH-FIRST (runtime contract R12b): the serve path is the plain fetch below, built from the
|
|
7
|
+
// kernel's ONE adaptation (`createTwinFetchFromHandler`); this file contributes only VALUES. The
|
|
8
|
+
// vendor's 204 deletes return `{ status: 204, body: null }`, which the adapter's null-body rule
|
|
9
|
+
// serves as a genuinely empty response. The server is one line of Bun.serve around that closure.
|
|
10
|
+
import { handlePolarTwinRequest } from './polar-twin.ts';
|
|
11
|
+
import { createTwinFetchFromHandler, statefulTwinManifest } from '@volter/twin';
|
|
12
|
+
|
|
13
|
+
/** Options every Polar-twin HTTP surface needs, independent of who owns the socket. */
|
|
14
|
+
export interface PolarTwinFetchOptions {
|
|
15
|
+
root?: string;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createPolarTwinFetch(options: PolarTwinFetchOptions = {}): (request: Request) => Promise<Response> {
|
|
20
|
+
return createTwinFetchFromHandler(handlePolarTwinRequest, {
|
|
21
|
+
...options,
|
|
22
|
+
manifest: statefulTwinManifest({ vendor: 'polar', twinOf: 'the Polar billing API', stores: 'customers, checkouts, subscriptions, meters and usage events' }),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createPolarTwinServer(options: { root?: string; port?: number; readOnly?: boolean } = {}): { port: number; stop: () => void } {
|
|
27
|
+
const server = Bun.serve({
|
|
28
|
+
port: options.port ?? 0,
|
|
29
|
+
idleTimeout: 60,
|
|
30
|
+
fetch: createPolarTwinFetch(options),
|
|
31
|
+
});
|
|
32
|
+
return { port: server.port ?? options.port ?? 0, stop: () => server.stop(true) };
|
|
33
|
+
}
|