@spfn/core 0.3.0-beta.3 → 0.3.0-beta.4

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/README.md CHANGED
@@ -359,6 +359,39 @@ probe depends on, and a probe reaches it unauthenticated. An app with `src/serve
359
359
 
360
360
  ---
361
361
 
362
+ ## How does a client synchronize with the server clock?
363
+
364
+ Call `GET /_core/time` before minting a timestamped proof. It is a built-in,
365
+ unauthenticated and session-free operation registered before application middleware and
366
+ routes:
367
+
368
+ ```json
369
+ { "serverTimeMillis": 1750000000123 }
370
+ ```
371
+
372
+ The response is a closed contract: `serverTimeMillis` is an integer Unix epoch in
373
+ milliseconds and no additional fields are declared. It always carries
374
+ `Cache-Control: no-store`; a cached clock reading is not a synchronization point.
375
+
376
+ The value is trustworthy only when the transport is trustworthy. Production clients must
377
+ call the endpoint over HTTPS and validate the server certificate. The endpoint does not
378
+ sign its response, compensate for network latency, choose an authentication skew margin,
379
+ or define client retry and persistence policy — those belong to the consuming protocol.
380
+
381
+ Tests can inject an exact clock without replacing global time:
382
+
383
+ ```typescript
384
+ const app = await createServer(defineServerConfig()
385
+ .serverTime({ clock: { now: () => 1750000000123 } })
386
+ .build());
387
+ ```
388
+
389
+ `CORE_TIME_ROUTE`, `CORE_TIME_PATH`, `ServerTimeResponseSchema` and the
390
+ `ServerTimeResponse` type are exported from `@spfn/core/server` for separately deployed
391
+ client-contract exporters to consume from the same wire definition.
392
+
393
+ ---
394
+
362
395
  ## Can I deploy this to Vercel?
363
396
 
364
397
  Yes, and it is a first-class target rather than a workaround. From your app:
@@ -1,8 +1,9 @@
1
- import { R as Router } from '../router-Cy7rAfmj.js';
2
- import { C as ContractDocument, a as ContractViolation, b as ContractOperation, c as ContractSnapshot } from '../types-CfYVhIQ9.js';
3
- export { d as CompatibilityPolicy, e as ContractRequest, f as ContractViolationKind, J as JsonSchema } from '../types-CfYVhIQ9.js';
1
+ import { R as Router } from '../router-DJdpwuB6.js';
2
+ import { C as ContractDocument, a as ContractViolation, b as ContractOperation, c as ContractSnapshot } from '../types-ClQVomgV.js';
3
+ export { d as CompatibilityPolicy, e as ContractRequest, f as ContractViolationKind, J as JsonSchema } from '../types-ClQVomgV.js';
4
4
  import '../define-middleware-CVKgqo8S.js';
5
5
  import 'hono';
6
+ import '../route-builder-2ani2jEI.js';
6
7
  import '@sinclair/typebox';
7
8
  import 'hono/utils/http-status';
8
9
  import '../route/types.js';
@@ -1,6 +1,7 @@
1
1
  import { a as NamedMiddleware } from '../define-middleware-CVKgqo8S.js';
2
- import { a as RouteDef, R as Router, b as RouteBuilder } from '../router-Cy7rAfmj.js';
3
- import { J as JsonSchema } from '../types-CfYVhIQ9.js';
2
+ import { R as RouteDef, a as RouteBuilder } from '../route-builder-2ani2jEI.js';
3
+ import { R as Router } from '../router-DJdpwuB6.js';
4
+ import { J as JsonSchema } from '../types-ClQVomgV.js';
4
5
  import { HttpMethod } from '../route/types.js';
5
6
  import 'hono';
6
7
  import '@sinclair/typebox';
@@ -1,5 +1,7 @@
1
- import { a as RouteDef, R as Router } from '../router-Cy7rAfmj.js';
2
- export { M as MergedInput, P as PaginatedResult, c as RouteAuthProfile, d as RouteBuilderContext, e as RouteContract, f as RouteHandlerFn, g as RouteInput, h as defineRouter, r as route } from '../router-Cy7rAfmj.js';
1
+ import { R as RouteDef } from '../route-builder-2ani2jEI.js';
2
+ export { M as MergedInput, P as PaginatedResult, b as RouteAuthProfile, c as RouteBuilderContext, d as RouteContract, e as RouteHandlerFn, f as RouteInput, r as route } from '../route-builder-2ani2jEI.js';
3
+ import { R as Router } from '../router-DJdpwuB6.js';
4
+ export { d as defineRouter } from '../router-DJdpwuB6.js';
3
5
  import { Hono, MiddlewareHandler } from 'hono';
4
6
  import { HttpMethod } from './types.js';
5
7
  export { E as ExtractMiddlewareNames, a as NamedMiddleware, N as NamedMiddlewareFactory, d as defineMiddleware, b as defineMiddlewareFactory } from '../define-middleware-CVKgqo8S.js';
@@ -1,5 +1,5 @@
1
- import { a as NamedMiddleware } from './define-middleware-CVKgqo8S.js';
2
1
  import { Context, MiddlewareHandler } from 'hono';
2
+ import { a as NamedMiddleware } from './define-middleware-CVKgqo8S.js';
3
3
  import { TSchema, Static } from '@sinclair/typebox';
4
4
  import { ContentfulStatusCode, RedirectStatusCode } from 'hono/utils/http-status';
5
5
  import { HttpMethod } from './route/types.js';
@@ -550,127 +550,4 @@ declare const route: {
550
550
  delete: (path: string) => RouteBuilder;
551
551
  };
552
552
 
553
- /**
554
- * Router Definition
555
- *
556
- * Provides router composition and middleware management
557
- */
558
-
559
- /**
560
- * Router definition - holds all routes
561
- */
562
- interface Router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>> {
563
- routes: TRoutes;
564
- _routes: TRoutes;
565
- _packageRouters: Router<any>[];
566
- _globalMiddlewares: NamedMiddleware<string>[];
567
- /** The contract version these routes publish, or null when uncontracted. */
568
- _contractVersion: string | null;
569
- /**
570
- * Register package routers (type-hidden)
571
- *
572
- * Package routes are:
573
- * - Recognized by RPC proxy and backend
574
- * - NOT exposed in client types (use package's own API like authApi, cmsApi)
575
- *
576
- * @example
577
- * ```ts
578
- * import { authRouter } from '@spfn/auth/server';
579
- * import { cmsAppRouter } from '@spfn/cms/server';
580
- *
581
- * export const appRouter = defineRouter({
582
- * getRoot,
583
- * getStatus,
584
- * })
585
- * .packages([authRouter, cmsAppRouter]);
586
- *
587
- * // Client usage:
588
- * // api.getRoot.call({}) - app routes
589
- * // authApi.login.call({}) - package API
590
- * ```
591
- */
592
- packages(routers: Router<any>[]): Router<TRoutes>;
593
- /**
594
- * Register global middlewares
595
- *
596
- * Applied to all routes unless explicitly skipped via .skip()
597
- *
598
- * @example
599
- * ```ts
600
- * import { authMiddleware, loggingMiddleware } from './middlewares';
601
- *
602
- * export const appRouter = defineRouter({
603
- * getRoot,
604
- * getStatus,
605
- * })
606
- * .packages([authRouter])
607
- * .use([authMiddleware, loggingMiddleware]);
608
- * ```
609
- */
610
- use(middlewares: NamedMiddleware<string>[]): Router<TRoutes>;
611
- /**
612
- * Declare the contract version these routes publish.
613
- *
614
- * A client compiled against this server — a mobile app in a store — is
615
- * generated from one version of the contract and cannot be updated when the
616
- * server changes. The server announces this version on every response so
617
- * that client can tell whether the two ends still agree.
618
- *
619
- * This is the version's source. A released snapshot is written to
620
- * `contracts/released/<version>.json` from what is declared here, so the
621
- * filename follows the code rather than the code having to be told what the
622
- * filename said.
623
- *
624
- * Only a server with contracted routes needs it. Without it the contract
625
- * generator still writes `current.json` and still runs the compatibility
626
- * gate; what it cannot do is cut a release or announce a version.
627
- *
628
- * @example
629
- * ```ts
630
- * export const appRouter = defineRouter({ getRoot, listItems })
631
- * .contractVersion('1.2.0')
632
- * .packages([authRouter]);
633
- * ```
634
- */
635
- contractVersion(version: string): Router<TRoutes>;
636
- }
637
- /**
638
- * Define a router with multiple routes (tRPC-style)
639
- *
640
- * Supports chainable API for packages and middlewares:
641
- *
642
- * @example
643
- * ```ts
644
- * // Basic usage
645
- * export const appRouter = defineRouter({
646
- * getRoot,
647
- * getStatus,
648
- * listExamples,
649
- * });
650
- *
651
- * // With package routers (type-hidden)
652
- * export const appRouter = defineRouter({
653
- * getRoot,
654
- * getStatus,
655
- * })
656
- * .packages([authRouter, cmsAppRouter]);
657
- *
658
- * // With global middlewares
659
- * export const appRouter = defineRouter({
660
- * getRoot,
661
- * getStatus,
662
- * })
663
- * .packages([authRouter])
664
- * .use([authMiddleware, loggingMiddleware]);
665
- *
666
- * export type AppRouter = typeof appRouter;
667
- * ```
668
- *
669
- * Package routes:
670
- * - Recognized by RPC proxy and backend for routing
671
- * - NOT included in AppRouter type (use authApi, cmsApi instead)
672
- * - Prevents confusion between app API and package APIs
673
- */
674
- declare function defineRouter<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(routes: TRoutes): Router<TRoutes>;
675
-
676
- export { type MergedInput as M, type PaginatedResult as P, type Router as R, type RouteDef as a, RouteBuilder as b, type RouteAuthProfile as c, type RouteBuilderContext as d, type RouteContract as e, type RouteHandlerFn as f, type RouteInput as g, defineRouter as h, route as r };
553
+ export { type MergedInput as M, type PaginatedResult as P, type RouteDef as R, RouteBuilder as a, type RouteAuthProfile as b, type RouteBuilderContext as c, type RouteContract as d, type RouteHandlerFn as e, type RouteInput as f, route as r };
@@ -0,0 +1,127 @@
1
+ import { a as NamedMiddleware } from './define-middleware-CVKgqo8S.js';
2
+ import { R as RouteDef } from './route-builder-2ani2jEI.js';
3
+
4
+ /**
5
+ * Router Definition
6
+ *
7
+ * Provides router composition and middleware management
8
+ */
9
+
10
+ /**
11
+ * Router definition - holds all routes
12
+ */
13
+ interface Router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>> {
14
+ routes: TRoutes;
15
+ _routes: TRoutes;
16
+ _packageRouters: Router<any>[];
17
+ _globalMiddlewares: NamedMiddleware<string>[];
18
+ /** The contract version these routes publish, or null when uncontracted. */
19
+ _contractVersion: string | null;
20
+ /**
21
+ * Register package routers (type-hidden)
22
+ *
23
+ * Package routes are:
24
+ * - Recognized by RPC proxy and backend
25
+ * - NOT exposed in client types (use package's own API like authApi, cmsApi)
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { authRouter } from '@spfn/auth/server';
30
+ * import { cmsAppRouter } from '@spfn/cms/server';
31
+ *
32
+ * export const appRouter = defineRouter({
33
+ * getRoot,
34
+ * getStatus,
35
+ * })
36
+ * .packages([authRouter, cmsAppRouter]);
37
+ *
38
+ * // Client usage:
39
+ * // api.getRoot.call({}) - app routes
40
+ * // authApi.login.call({}) - package API
41
+ * ```
42
+ */
43
+ packages(routers: Router<any>[]): Router<TRoutes>;
44
+ /**
45
+ * Register global middlewares
46
+ *
47
+ * Applied to all routes unless explicitly skipped via .skip()
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { authMiddleware, loggingMiddleware } from './middlewares';
52
+ *
53
+ * export const appRouter = defineRouter({
54
+ * getRoot,
55
+ * getStatus,
56
+ * })
57
+ * .packages([authRouter])
58
+ * .use([authMiddleware, loggingMiddleware]);
59
+ * ```
60
+ */
61
+ use(middlewares: NamedMiddleware<string>[]): Router<TRoutes>;
62
+ /**
63
+ * Declare the contract version these routes publish.
64
+ *
65
+ * A client compiled against this server — a mobile app in a store — is
66
+ * generated from one version of the contract and cannot be updated when the
67
+ * server changes. The server announces this version on every response so
68
+ * that client can tell whether the two ends still agree.
69
+ *
70
+ * This is the version's source. A released snapshot is written to
71
+ * `contracts/released/<version>.json` from what is declared here, so the
72
+ * filename follows the code rather than the code having to be told what the
73
+ * filename said.
74
+ *
75
+ * Only a server with contracted routes needs it. Without it the contract
76
+ * generator still writes `current.json` and still runs the compatibility
77
+ * gate; what it cannot do is cut a release or announce a version.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * export const appRouter = defineRouter({ getRoot, listItems })
82
+ * .contractVersion('1.2.0')
83
+ * .packages([authRouter]);
84
+ * ```
85
+ */
86
+ contractVersion(version: string): Router<TRoutes>;
87
+ }
88
+ /**
89
+ * Define a router with multiple routes (tRPC-style)
90
+ *
91
+ * Supports chainable API for packages and middlewares:
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * // Basic usage
96
+ * export const appRouter = defineRouter({
97
+ * getRoot,
98
+ * getStatus,
99
+ * listExamples,
100
+ * });
101
+ *
102
+ * // With package routers (type-hidden)
103
+ * export const appRouter = defineRouter({
104
+ * getRoot,
105
+ * getStatus,
106
+ * })
107
+ * .packages([authRouter, cmsAppRouter]);
108
+ *
109
+ * // With global middlewares
110
+ * export const appRouter = defineRouter({
111
+ * getRoot,
112
+ * getStatus,
113
+ * })
114
+ * .packages([authRouter])
115
+ * .use([authMiddleware, loggingMiddleware]);
116
+ *
117
+ * export type AppRouter = typeof appRouter;
118
+ * ```
119
+ *
120
+ * Package routes:
121
+ * - Recognized by RPC proxy and backend for routing
122
+ * - NOT included in AppRouter type (use authApi, cmsApi instead)
123
+ * - Prevents confusion between app API and package APIs
124
+ */
125
+ declare function defineRouter<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(routes: TRoutes): Router<TRoutes>;
126
+
127
+ export { type Router as R, defineRouter as d };
@@ -10,8 +10,13 @@ import { b as EventRouterDef, E as EventDef } from '../token-manager-BT5EnUAR.js
10
10
  import { d as SSEHandlerConfig, e as SSEAuthConfig } from '../types-ZQODsBft.js';
11
11
  import { W as WSRouterDef, f as WSHandlerConfig, e as WSMessageHandlers, g as WSAuthConfig } from '../types-2AbaW4Ie.js';
12
12
  import { DatabaseProvider, MigrationStatus, MigrationStatusDb } from '@spfn/core/db';
13
- import '@sinclair/typebox';
13
+ import * as _sinclair_typebox from '@sinclair/typebox';
14
+ import { Static } from '@sinclair/typebox';
15
+ import { R as RouteDef } from '../route-builder-2ani2jEI.js';
14
16
  import 'pg-boss';
17
+ import '../define-middleware-CVKgqo8S.js';
18
+ import 'hono/utils/http-status';
19
+ import '../route/types.js';
15
20
 
16
21
  /**
17
22
  * @deprecated Use `loadEnv` from '@spfn/core/env/loader' instead.
@@ -22,6 +27,33 @@ import 'pg-boss';
22
27
  */
23
28
  declare function loadEnvFiles(): void;
24
29
 
30
+ /** Stable operation identity used by separately deployed clients. */
31
+ declare const CORE_TIME_OPERATION_ID = "core.time";
32
+ /**
33
+ * Closed response shape for the server-time wire capability.
34
+ *
35
+ * Millisecond timestamps use integers throughout SPFN's external contracts.
36
+ */
37
+ declare const ServerTimeResponseSchema: _sinclair_typebox.TObject<{
38
+ serverTimeMillis: _sinclair_typebox.TInteger;
39
+ }>;
40
+ type ServerTimeResponse = Static<typeof ServerTimeResponseSchema>;
41
+ /** Injectable source of Unix epoch milliseconds. */
42
+ interface ServerClock {
43
+ now(): number;
44
+ }
45
+ /**
46
+ * Build the route from a clock so tests and alternate runtimes can supply the
47
+ * epoch source without replacing global time.
48
+ */
49
+ declare function createCoreTimeRoute(clock?: ServerClock): RouteDef<{}, {}, {
50
+ serverTimeMillis: number;
51
+ }>;
52
+ /** The production route and the public wire-contract source of truth. */
53
+ declare const CORE_TIME_ROUTE: RouteDef<{}, {}, {
54
+ serverTimeMillis: number;
55
+ }>;
56
+
25
57
  /**
26
58
  * Workflow router interface for @spfn/core integration
27
59
  *
@@ -489,6 +521,15 @@ interface ServerConfig {
489
521
  */
490
522
  detailed?: boolean;
491
523
  };
524
+ /**
525
+ * Server-time capability dependencies.
526
+ *
527
+ * The endpoint is always enabled at `GET /_core/time`. Supplying a clock is
528
+ * primarily a deterministic test seam; production defaults to `Date.now()`.
529
+ */
530
+ serverTime?: {
531
+ clock?: ServerClock;
532
+ };
492
533
  /**
493
534
  * Migration boot gate
494
535
  *
@@ -757,6 +798,13 @@ declare const CORE_NAMESPACE = "/_core";
757
798
  * balancer console — and a version bump migrates none of them.
758
799
  */
759
800
  declare const CORE_HEALTH_PATH = "/_core/health";
801
+ /**
802
+ * Where clients obtain the server's current Unix epoch in milliseconds.
803
+ *
804
+ * This endpoint is registered before application routes and application auth
805
+ * middleware so a client can call it before it has a proof or session.
806
+ */
807
+ declare const CORE_TIME_PATH = "/_core/time";
760
808
 
761
809
  /**
762
810
  * Start SPFN Server
@@ -1197,6 +1245,12 @@ declare class ServerConfigBuilder {
1197
1245
  * Configure health check endpoint
1198
1246
  */
1199
1247
  healthCheck(healthCheck: ServerConfig['healthCheck']): this;
1248
+ /**
1249
+ * Supply the clock used by the built-in `GET /_core/time` capability.
1250
+ * Production servers normally keep the default `Date.now()` clock; this is
1251
+ * exposed so tests can assert an exact wire value without replacing globals.
1252
+ */
1253
+ serverTime(serverTime: ServerConfig['serverTime']): this;
1200
1254
  /**
1201
1255
  * Configure infrastructure initialization
1202
1256
  */
@@ -1273,4 +1327,4 @@ declare class ServerConfigBuilder {
1273
1327
  */
1274
1328
  declare function defineServerConfig(): ServerConfigBuilder;
1275
1329
 
1276
- export { type AppFactory, CORE_HEALTH_PATH, CORE_NAMESPACE, type MigrationSnapshot, PendingMigrationsError, type ServerConfig, type ServerInstance, type ShutdownHookOptions, createServer, createServerlessApp, defineServerConfig, getMigrationSnapshot, getShutdownManager, loadEnvFiles, provisionInfrastructure, resetMigrationSnapshot, resetServerlessApp, startServer };
1330
+ export { type AppFactory, CORE_HEALTH_PATH, CORE_NAMESPACE, CORE_TIME_OPERATION_ID, CORE_TIME_PATH, CORE_TIME_ROUTE, type MigrationSnapshot, PendingMigrationsError, type ServerClock, type ServerConfig, type ServerInstance, type ServerTimeResponse, ServerTimeResponseSchema, type ShutdownHookOptions, createCoreTimeRoute, createServer, createServerlessApp, defineServerConfig, getMigrationSnapshot, getShutdownManager, loadEnvFiles, provisionInfrastructure, resetMigrationSnapshot, resetServerlessApp, startServer };