@almadar/orb 3.4.0 → 3.8.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/shell-hono",
3
- "version": "0.1.42",
3
+ "version": "0.1.65",
4
4
  "description": "Minimal full-stack shell template for Almadar applications (Hono server)",
5
5
  "workspaces": [
6
6
  "packages/*"
@@ -13,11 +13,11 @@
13
13
  "test:watch": "vitest"
14
14
  },
15
15
  "dependencies": {
16
- "@almadar/ui": "^5.147.0",
17
- "@almadar/syntax": "^1.15.0",
18
- "@almadar/evaluator": "^2.40.0",
16
+ "@almadar/ui": "^6.3.0",
17
+ "@almadar/syntax": "^1.16.0",
18
+ "@almadar/evaluator": "^2.44.0",
19
19
  "@almadar/patterns": "^2.101.0",
20
- "@almadar/core": "^10.57.0",
20
+ "@almadar/core": "^10.80.0",
21
21
  "firebase": "^11.4.0",
22
22
  "@tanstack/react-query": "^5.67.3",
23
23
  "react": "^19.0.0",
@@ -42,7 +42,7 @@
42
42
  "postprocessing": "^6.39.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@almadar/eslint-plugin": "^2.15.0",
45
+ "@almadar/eslint-plugin": "^2.17.0",
46
46
  "@typescript-eslint/parser": "8.56.0",
47
47
  "eslint": "10.0.0",
48
48
  "@testing-library/react": "^16.1.0",
@@ -13,10 +13,10 @@
13
13
  "test:watch": "vitest"
14
14
  },
15
15
  "dependencies": {
16
- "@almadar/server-hono": "^0.4.11",
17
- "@almadar/evaluator": "^2.40.0",
18
- "@almadar/core": "^10.57.0",
19
- "@almadar/integrations": "^2.23.0",
16
+ "@almadar/server-hono": "^0.4.13",
17
+ "@almadar/evaluator": "^2.44.0",
18
+ "@almadar/core": "^10.80.0",
19
+ "@almadar/integrations": "^2.30.0",
20
20
  "hono": "^4.7.0",
21
21
  "@hono/node-server": "^1.14.0",
22
22
  "@hono/zod-validator": "^0.4.0",
@@ -25,7 +25,7 @@
25
25
  "zod": "^3.22.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@almadar/eslint-plugin": "^2.15.0",
28
+ "@almadar/eslint-plugin": "^2.17.0",
29
29
  "@typescript-eslint/parser": "8.56.0",
30
30
  "@types/bun": "^1.1.0",
31
31
  "@types/node": "^20.17.19",
@@ -8,8 +8,15 @@ import {
8
8
  errorHandler,
9
9
  notFoundHandler,
10
10
  debugEventsRouter,
11
+ pushRouter,
12
+ pushServiceWorkerHandler,
13
+ PUSH_SERVICE_WORKER_PATH,
14
+ reportsRouter,
15
+ createHooksRouter,
11
16
  type AppEnv,
12
17
  } from '@almadar/server-hono';
18
+ import { hookProviders } from './hooks-providers.js';
19
+ import { broadcastBusEvent } from './sse.js';
13
20
  import { registerRoutes } from './routes.js';
14
21
 
15
22
  export const app = new Hono<AppEnv>();
@@ -23,9 +30,41 @@ app.get('/health', (c) => c.json({ status: 'ok' }));
23
30
  // Debug event bus endpoints (dev-only, no-op in production)
24
31
  app.route('/api/debug', debugEventsRouter());
25
32
 
33
+ // Web Push surface (browser/push-subscribe): public VAPID key + the shared
34
+ // service worker (root-scoped — a SW's max scope is its own directory).
35
+ app.route('/api/push', pushRouter);
36
+ app.get(PUSH_SERVICE_WORKER_PATH, pushServiceWorkerHandler);
37
+
38
+ // Inbound webhook ingress (I-19 decision): mounted BEFORE the authenticated
39
+ // /api routes — hook senders (Google Calendar watch channels, e-sign status,
40
+ // banking callbacks) cannot present a Firebase token, so each provider
41
+ // VERIFIES its own signature/channel token and unverified requests get 400.
42
+ // Dispatch = SSE bus broadcast to every connected client, so client circuits'
43
+ // `listens` fire; the cron pull cycle stays the no-client backstop.
44
+ app.route(
45
+ '/api/hooks',
46
+ createHooksRouter({
47
+ // Derived from this app's invoked services (generated hooks-providers.ts, I-26).
48
+ providers: hookProviders(),
49
+ dispatch: (event, payload) => {
50
+ broadcastBusEvent(undefined, {
51
+ type: 'bus',
52
+ event,
53
+ payload,
54
+ source: { orbital: 'webhook', trait: 'ingress' },
55
+ timestamp: Date.now(),
56
+ });
57
+ },
58
+ }),
59
+ );
60
+
26
61
  // Register generated routes
27
62
  registerRoutes(app);
28
63
 
64
+ // Server-side report export (Excel/PDF/CSV). Mounted AFTER registerRoutes so
65
+ // the /api/* auth middleware it registers covers this route too.
66
+ app.route('/api/reports', reportsRouter);
67
+
29
68
  // Error handling
30
69
  app.notFound(notFoundHandler);
31
70
  app.onError(errorHandler);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Hook Providers
3
+ *
4
+ * Checked-in stub so the template builds standalone in CI; the compiler
5
+ * overwrites it with the provider map derived from the app's invoked
6
+ * services × the registry's hook declarations (I-26).
7
+ */
8
+
9
+ export function hookProviders() {
10
+ return {};
11
+ }
@@ -22,11 +22,36 @@ try {
22
22
  }
23
23
 
24
24
  import { serve } from '@hono/node-server';
25
+ import { validateIntegrationEnv, FirestoreCredentialPersistence } from '@almadar/server-hono';
25
26
  import { app } from './app.js';
27
+ import { invokedServices, installTenantCredentialStore } from './services/clients.js';
28
+
29
+ // Fail fast in production when a required integration credential is missing
30
+ // (see SECRETS.md); registers the invoked services for /health reporting.
31
+ validateIntegrationEnv(invokedServices);
26
32
 
27
33
  const PORT = env.PORT || 3030;
28
34
 
29
35
  async function start(): Promise<void> {
36
+ // W4 tenant credential store: with a master key configured, stored
37
+ // credentials (Firestore rows, AES-256-GCM) layer over the env —
38
+ // store → env → unconfigured — and go live on change without restart.
39
+ if (process.env.ALMADAR_CREDENTIAL_MASTER_KEY) {
40
+ try {
41
+ await installTenantCredentialStore(new FirestoreCredentialPersistence());
42
+ logger.info('Tenant credential store installed');
43
+ } catch (e) {
44
+ const message = e instanceof Error ? e.message : String(e);
45
+ // A configured master key IS the deployment's statement that the store
46
+ // is in use — failing to serve it in production is a boot failure.
47
+ if (env.NODE_ENV === 'production') {
48
+ logger.error(`Tenant credential store failed to initialize — refusing to start: ${message}`);
49
+ throw e;
50
+ }
51
+ logger.warn(`Tenant credential store unavailable — falling back to env credentials: ${message}`);
52
+ }
53
+ }
54
+
30
55
  // Seed mock data when USE_MOCK_DATA is enabled
31
56
  if (env.USE_MOCK_DATA) {
32
57
  try {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Service Clients — placeholder
3
+ *
4
+ * Compiler generates the real service clients here (delegating to
5
+ * @almadar/integrations; see orbital-shell-typescript codegen/service.rs).
6
+ * This stub only lets the template build standalone; an emitted app
7
+ * overwrites it wholesale.
8
+ */
9
+
10
+ export const declaredServices = [] as const;
11
+
12
+ export const invokedServices = [] as const;
13
+
14
+ /** Overwritten at emit time with the RuntimeIntegrationManager-backed store install. */
15
+ export async function installTenantCredentialStore(_adapter: object): Promise<void> {
16
+ // {{GENERATED_SERVICE_CLIENTS}}
17
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Live-push SSE channel — placeholder
3
+ *
4
+ * Compiler generates the real SSE module here (connection registry +
5
+ * cross-client broadcast; see orbital-shell-typescript backend/server/sse.rs).
6
+ * This stub only lets the template build standalone; an emitted app
7
+ * overwrites it wholesale.
8
+ */
9
+
10
+ export interface BusBroadcastItem {
11
+ type: 'bus';
12
+ event: string;
13
+ payload?: object;
14
+ source: { orbital: string; trait: string };
15
+ timestamp: number;
16
+ }
17
+
18
+ export function broadcastBusEvent(_originClientId: string | undefined, _item: BusBroadcastItem): void {
19
+ // {{GENERATED_SSE_BROADCAST}}
20
+ }