@almadar/shell-runtime 0.1.0 → 1.0.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.
Files changed (167) hide show
  1. package/dist/chunk-57SBCUSM.js +62 -0
  2. package/dist/chunk-625EP7W2.js +108 -0
  3. package/dist/{chunk-NATGCIVM.js → chunk-7WB6VWRK.js} +344 -129
  4. package/dist/{chunk-Q2H75UYT.js → chunk-A2JJT4GA.js} +1 -37
  5. package/dist/chunk-BAS26HBN.js +10 -0
  6. package/dist/{chunk-REPX5QPI.js → chunk-BOVU4TCQ.js} +11 -3
  7. package/dist/chunk-BY5G4225.js +6 -0
  8. package/dist/chunk-DFDNHVDW.js +284 -0
  9. package/dist/chunk-I3TKINSO.js +398 -0
  10. package/dist/{chunk-DYOJGLIX.js → chunk-LKWYCYX5.js} +2 -5
  11. package/dist/chunk-LYFIQPXX.js +1 -0
  12. package/dist/{chunk-VNMG7NKY.js → chunk-MU335ZA4.js} +20 -26
  13. package/dist/{chunk-ODJCZ27I.js → chunk-N7HYNKK6.js} +35 -2
  14. package/dist/{chunk-4J2QEIUV.js → chunk-NTFQ36UN.js} +4 -30
  15. package/dist/chunk-NU6LVKGS.js +15 -0
  16. package/dist/chunk-P2N6K2IV.js +20 -0
  17. package/dist/{chunk-QQRDUMB2.js → chunk-QCJWPXLH.js} +11 -11
  18. package/dist/{chunk-QELZ6TEJ.js → chunk-UD2CXYSJ.js} +39 -3
  19. package/dist/{chunk-UJHOUZAL.js → chunk-V4EMDPCO.js} +2 -5
  20. package/dist/chunk-VNGXRYFF.js +9 -0
  21. package/dist/{chunk-HNOAZWFH.js → chunk-WGCWJOT2.js} +2 -0
  22. package/dist/chunk-X6W44WHO.js +26 -0
  23. package/dist/chunk-ZUSM4VW4.js +197 -0
  24. package/dist/client/EventTransport.d.ts +23 -7
  25. package/dist/client/EventTransport.js +1 -2
  26. package/dist/client/awaiting.js +0 -1
  27. package/dist/client/channel-transport.d.ts +6 -6
  28. package/dist/client/channel-transport.js +0 -1
  29. package/dist/client/circuit-store.d.ts +16 -5
  30. package/dist/client/circuit-store.js +2 -3
  31. package/dist/client/client-kernel.d.ts +36 -15
  32. package/dist/client/declared-input-dispatch.d.ts +19 -2
  33. package/dist/client/declared-input-dispatch.js +1 -2
  34. package/dist/client/inbound-dispatch.d.ts +21 -2
  35. package/dist/client/inbound-dispatch.js +1 -2
  36. package/dist/client/local-fold.d.ts +15 -8
  37. package/dist/client/local-fold.js +1 -2
  38. package/dist/client/render-sigils.js +0 -1
  39. package/dist/client/state-book.d.ts +9 -16
  40. package/dist/client/state-book.js +1 -2
  41. package/dist/client/trait-mount-error.js +0 -1
  42. package/dist/credentials/env-vars.d.ts +5 -1
  43. package/dist/credentials/env-vars.js +1 -3
  44. package/dist/credentials/scope.d.ts +8 -7
  45. package/dist/credentials/scope.js +0 -1
  46. package/dist/credentials/vault.d.ts +142 -0
  47. package/dist/credentials/vault.js +1 -0
  48. package/dist/effects/in-flight-calls.js +0 -1
  49. package/dist/effects/on-device-model.js +0 -1
  50. package/dist/events/EventBus.d.ts +1 -4
  51. package/dist/events/EventBus.js +0 -1
  52. package/dist/events/emit-stamp.js +0 -1
  53. package/dist/index.d.ts +25 -42
  54. package/dist/index.js +27 -45
  55. package/dist/kernel/decode.d.ts +8 -10
  56. package/dist/kernel/decode.js +1 -2
  57. package/dist/kernel/engine.d.ts +132 -31
  58. package/dist/kernel/engine.js +7 -9
  59. package/dist/kernel/frame-applier.d.ts +8 -7
  60. package/dist/kernel/frame-applier.js +1 -2
  61. package/dist/kernel/host.d.ts +127 -16
  62. package/dist/kernel/host.js +4 -7
  63. package/dist/kernel/lane.d.ts +1 -22
  64. package/dist/kernel/lane.js +1 -2
  65. package/dist/kernel/os-fetch-port.d.ts +7 -0
  66. package/dist/kernel/os-fetch-port.js +3 -0
  67. package/dist/kernel/os-port.d.ts +30 -8
  68. package/dist/kernel/os-port.js +1 -2
  69. package/dist/kernel/program-effects.d.ts +11 -28
  70. package/dist/kernel/program-effects.js +1 -2
  71. package/dist/kernel/secret-ports.d.ts +139 -0
  72. package/dist/kernel/secret-ports.js +2 -0
  73. package/dist/kernel/wire.d.ts +50 -12
  74. package/dist/loader/fetch-loader.d.ts +26 -0
  75. package/dist/loader/fetch-loader.js +1 -0
  76. package/dist/loader/lazy-page.js +0 -1
  77. package/dist/loader/schema-loader.d.ts +1 -17
  78. package/dist/persistence/native-memory.js +0 -1
  79. package/dist/runtime/entities/declaredCollections.d.ts +6 -0
  80. package/dist/runtime/entities/declaredCollections.js +1 -0
  81. package/dist/runtime/evaluation/local-store-transport.d.ts +14 -23
  82. package/dist/runtime/evaluation/local-store-transport.js +9 -13
  83. package/dist/runtime/evaluation/residence-transport.d.ts +3 -3
  84. package/dist/runtime/evaluation/residence-transport.js +1 -2
  85. package/dist/runtime/evaluation/routed-persistence.js +0 -1
  86. package/dist/runtime/events/identity/routing.d.ts +2 -53
  87. package/dist/runtime/events/identity/routing.js +1 -2
  88. package/dist/runtime/types.d.ts +5 -205
  89. package/dist/runtime/types.js +1 -2
  90. package/dist/service/default-call-service.js +0 -1
  91. package/dist/service/service-provider.js +0 -1
  92. package/package.json +8 -5
  93. package/dist/chunk-2JU7Y4KU.js +0 -21
  94. package/dist/chunk-46RWK2B5.js +0 -28
  95. package/dist/chunk-4ZICQ5PM.js +0 -192
  96. package/dist/chunk-53IPZXDP.js +0 -76
  97. package/dist/chunk-5D63EMO5.js +0 -16
  98. package/dist/chunk-CPSQXEJ6.js +0 -55
  99. package/dist/chunk-CQP5XAX6.js +0 -173
  100. package/dist/chunk-CROS2GEX.js +0 -49
  101. package/dist/chunk-D4XJTBLB.js +0 -217
  102. package/dist/chunk-D5USD2EX.js +0 -232
  103. package/dist/chunk-EV56K4GB.js +0 -63
  104. package/dist/chunk-FQ6IZMIU.js +0 -10
  105. package/dist/chunk-HMK6YMQS.js +0 -135
  106. package/dist/chunk-IHQLE5M7.js +0 -62
  107. package/dist/chunk-JFWFDUTR.js +0 -35
  108. package/dist/chunk-MHYSHSRG.js +0 -54
  109. package/dist/chunk-MLKGABMK.js +0 -7
  110. package/dist/chunk-NAECVIAR.js +0 -322
  111. package/dist/chunk-Q7JK4KY7.js +0 -9
  112. package/dist/chunk-RBUMDYFS.js +0 -681
  113. package/dist/chunk-SAS5KKCR.js +0 -43
  114. package/dist/chunk-SWPDU752.js +0 -28
  115. package/dist/chunk-T775TUCD.js +0 -18
  116. package/dist/chunk-VMOBW7RK.js +0 -21
  117. package/dist/chunk-WNPNNYXY.js +0 -22
  118. package/dist/chunk-XB5GYODW.js +0 -28
  119. package/dist/chunk-YL2SO5TP.js +0 -334
  120. package/dist/chunk-YO4LWS3I.js +0 -606
  121. package/dist/chunk-ZAQSS47X.js +0 -157
  122. package/dist/chunk-ZCQUUJIF.js +0 -129
  123. package/dist/client/ServerBridge.d.ts +0 -126
  124. package/dist/client/ServerBridge.js +0 -3
  125. package/dist/credentials/seed.d.ts +0 -21
  126. package/dist/credentials/seed.js +0 -2
  127. package/dist/credentials/store.d.ts +0 -110
  128. package/dist/credentials/store.js +0 -2
  129. package/dist/index-hT1xCdTq.d.ts +0 -46
  130. package/dist/kernel/beacon.d.ts +0 -32
  131. package/dist/kernel/beacon.js +0 -2
  132. package/dist/kernel/http.d.ts +0 -302
  133. package/dist/kernel/http.js +0 -6
  134. package/dist/kernel/oauth-effects.d.ts +0 -25
  135. package/dist/kernel/oauth-effects.js +0 -7
  136. package/dist/kernel/oauth-port.d.ts +0 -31
  137. package/dist/kernel/oauth-port.js +0 -2
  138. package/dist/loader/http-loader.d.ts +0 -111
  139. package/dist/loader/http-loader.js +0 -2
  140. package/dist/runtime/effects/composition/compose-behaviors.d.ts +0 -58
  141. package/dist/runtime/effects/composition/compose-behaviors.js +0 -4
  142. package/dist/runtime/effects/composition/event-wiring.d.ts +0 -38
  143. package/dist/runtime/effects/composition/event-wiring.js +0 -2
  144. package/dist/runtime/effects/composition/index.d.ts +0 -5
  145. package/dist/runtime/effects/composition/index.js +0 -6
  146. package/dist/runtime/effects/composition/layout-strategy.d.ts +0 -35
  147. package/dist/runtime/effects/composition/layout-strategy.js +0 -2
  148. package/dist/runtime/effects/composition/pipe.d.ts +0 -25
  149. package/dist/runtime/effects/composition/pipe.js +0 -2
  150. package/dist/runtime/entities/mockStoreSeed.d.ts +0 -56
  151. package/dist/runtime/entities/mockStoreSeed.js +0 -3
  152. package/dist/runtime/entities/seedBrowserStore.d.ts +0 -28
  153. package/dist/runtime/entities/seedBrowserStore.js +0 -2
  154. package/dist/runtime/entities/std-mock-seed.d.ts +0 -87
  155. package/dist/runtime/entities/std-mock-seed.js +0 -2
  156. package/dist/runtime/time/TickScheduler.d.ts +0 -77
  157. package/dist/runtime/time/TickScheduler.js +0 -3
  158. package/dist/runtime/time/cron.d.ts +0 -25
  159. package/dist/runtime/time/cron.js +0 -2
  160. package/dist/runtime/time/duration.d.ts +0 -20
  161. package/dist/runtime/time/duration.js +0 -2
  162. package/dist/runtime/traits/OrbitalTraitParsing.d.ts +0 -34
  163. package/dist/runtime/traits/OrbitalTraitParsing.js +0 -2
  164. package/dist/runtime/traits/listen-targets.d.ts +0 -16
  165. package/dist/runtime/traits/listen-targets.js +0 -3
  166. package/dist/runtime/traits/trait-index.d.ts +0 -35
  167. package/dist/runtime/traits/trait-index.js +0 -3
@@ -1,157 +0,0 @@
1
- import { base64Standard, isOAuthReason, isOAuthCode } from './chunk-YO4LWS3I.js';
2
- import { isJsonObject } from '@almadar/core';
3
-
4
- var PENDING_GRANT_TTL_MS = 10 * 60 * 1e3;
5
- var MOCK_PENDING_TTL_MS = Number.MAX_SAFE_INTEGER;
6
- var PROVIDERS = ["google", "github", "auth0"];
7
- var OAuthEffectFailure = class extends Error {
8
- constructor(payload) {
9
- super(payload.error);
10
- this.payload = payload;
11
- }
12
- payload;
13
- };
14
- function parsed(text) {
15
- return JSON.parse(text);
16
- }
17
- function objectOf(value, what) {
18
- if (value === void 0 || !isJsonObject(value)) throw new Error(`${what} is malformed`);
19
- return value;
20
- }
21
- function failureOf(kernel, reason) {
22
- if (kernel.oauthFailure === void 0) throw new Error("this kernel build has no OAuth failure messages");
23
- const payload = objectOf(parsed(kernel.oauthFailure(reason)), "the oauth failure");
24
- const { error, code } = payload;
25
- if (typeof error !== "string" || !isOAuthCode(code)) throw new Error("the oauth failure is malformed");
26
- return new OAuthEffectFailure({ error, code, reason });
27
- }
28
- async function ask(ports, kernel, request, principal) {
29
- if (ports.oauth === void 0) throw failureOf(kernel, "store-unavailable");
30
- try {
31
- const reply = await ports.oauth.answer(request, principal);
32
- if (!isReplyOf(request, reply)) throw new Error("wrong reply");
33
- return reply;
34
- } catch {
35
- throw failureOf(kernel, "store-unavailable");
36
- }
37
- }
38
- function isReplyOf(request, reply) {
39
- switch (request.ask) {
40
- case "pendingPut":
41
- case "subjectRemember":
42
- case "subjectForget":
43
- case "metadataPut":
44
- return reply.reply === "done";
45
- case "pendingTake":
46
- return reply.reply === "taken";
47
- case "connectionAvailable":
48
- return reply.reply === "flag";
49
- case "connectionSave":
50
- case "connectionStatus":
51
- case "connectionRemove":
52
- return reply.reply === "row";
53
- case "subjectLookup":
54
- return reply.reply === "subject";
55
- case "metadataGet":
56
- return reply.reply === "metadata";
57
- case "clock":
58
- return reply.reply === "millis";
59
- case "mockTokenPut":
60
- return reply.reply === "done";
61
- case "mockTokenRefresh":
62
- case "mockTokenRevoke":
63
- return reply.reply === "flag";
64
- case "mockTokenCheck":
65
- return reply.reply === "mockToken";
66
- case "consent":
67
- return reply.reply === "code";
68
- }
69
- }
70
- async function oauthAuthorizePayload(ports, client, options, principal, key) {
71
- if (key !== void 0 && (typeof key !== "string" || key === "")) {
72
- throw new Error(`call key must evaluate to a non-empty string, got ${String(key)}`);
73
- }
74
- const echoed = typeof key === "string" ? key : null;
75
- const kernel = await ports.kernel();
76
- if (kernel.oauthAuthorizePlan === void 0 || kernel.oauthAuthorizeBuild === void 0) {
77
- throw new Error("oauth-authorize: this kernel build cannot run it");
78
- }
79
- const planned = objectOf(parsed(kernel.oauthAuthorizePlan(JSON.stringify(client ?? null), JSON.stringify(options ?? null))), "the authorize plan");
80
- if (planned.mode === "mock") {
81
- if (kernel.oauthAuthorizeMockBuild === void 0) throw new Error("oauth-authorize: this kernel build cannot run it");
82
- const mock = objectOf(parsed(kernel.oauthAuthorizeMockBuild(JSON.stringify(planned.plan ?? null), base64Standard(ports.random(16)))), "the authorization");
83
- return keepGrant(ports, kernel, mock, MOCK_PENDING_TTL_MS, principal, echoed, false);
84
- }
85
- const slot = objectOf(planned.clientId, "the client id slot");
86
- if (typeof slot.name !== "string") throw new Error("the client id slot is malformed");
87
- let owner;
88
- if (slot.scope === "user") {
89
- if (principal === void 0) throw failureOf(kernel, "not-signed-in");
90
- owner = principal;
91
- }
92
- const clientId = await ports.secrets.get(slot.name, owner);
93
- if (clientId === void 0) throw failureOf(kernel, "unconfigured-client");
94
- let metadata = planned.metadata ?? null;
95
- if (typeof planned.issuer === "string") {
96
- const reply = await ask(ports, kernel, { ask: "metadataGet", issuer: planned.issuer }, principal);
97
- metadata = reply.reply === "metadata" ? reply.metadata : null;
98
- }
99
- if (metadata === null) throw failureOf(kernel, "metadata-invalid");
100
- const state = ports.random(32);
101
- const verifier = ports.random(32);
102
- const built = objectOf(
103
- parsed(kernel.oauthAuthorizeBuild(JSON.stringify(planned.plan ?? null), clientId, JSON.stringify(metadata), base64Standard(state), base64Standard(verifier))),
104
- "the authorization"
105
- );
106
- if (typeof built.refused === "string") throw new Error(built.refused);
107
- if (built.failure !== void 0) {
108
- const failure = objectOf(built.failure, "the failure");
109
- const reason = failure.reason;
110
- if (!isOAuthReason(reason)) throw new Error("the oauth failure is malformed");
111
- throw failureOf(kernel, reason);
112
- }
113
- return keepGrant(ports, kernel, objectOf(built.ok, "the authorization"), PENDING_GRANT_TTL_MS, principal, echoed, true);
114
- }
115
- async function keepGrant(ports, kernel, ok, ttlMs, principal, key, consent) {
116
- const grant = objectOf(ok.grant, "the pending grant");
117
- if (typeof ok.authUrl !== "string" || typeof ok.state !== "string") throw new Error("the authorization is malformed");
118
- const scopes = Array.isArray(grant.scopes) ? grant.scopes.flatMap((scope) => typeof scope === "string" ? [scope] : []) : [];
119
- await ask(
120
- ports,
121
- kernel,
122
- {
123
- ask: "pendingPut",
124
- state: ok.state,
125
- ttlMs,
126
- grant: {
127
- provider: String(grant.provider),
128
- redirectUri: String(grant.redirectUri),
129
- verifier: String(grant.verifier),
130
- subject: typeof grant.subject === "string" ? grant.subject : null,
131
- scopes
132
- }
133
- },
134
- principal
135
- );
136
- let code = "";
137
- if (consent) {
138
- const reply = await ask(ports, kernel, { ask: "consent", authUrl: ok.authUrl, state: ok.state, redirectUri: String(grant.redirectUri) }, principal);
139
- code = reply.reply === "code" ? reply.code ?? "" : "";
140
- }
141
- return { authUrl: ok.authUrl, state: ok.state, code, key };
142
- }
143
- async function oauthConnectionPayload(ports, head, provider, principal) {
144
- const word = PROVIDERS.find((known) => known === provider);
145
- if (word === void 0) {
146
- throw new Error(typeof provider === "string" ? `${head}: provider must be google, github or auth0, not \`${provider}\`` : `${head}: provider must be a provider word`);
147
- }
148
- const kernel = await ports.kernel();
149
- const available = await ask(ports, kernel, { ask: "connectionAvailable" }, principal);
150
- if (available.reply !== "flag" || !available.value) throw failureOf(kernel, "store-unavailable");
151
- if (principal === void 0 || principal === "") throw failureOf(kernel, "not-signed-in");
152
- const reply = await ask(ports, kernel, head === "oauth-connection-status" ? { ask: "connectionStatus", provider: word } : { ask: "connectionRemove", provider: word }, principal);
153
- if (reply.reply !== "row") throw failureOf(kernel, "store-unavailable");
154
- return reply.row;
155
- }
156
-
157
- export { OAuthEffectFailure, oauthAuthorizePayload, oauthConnectionPayload };
@@ -1,129 +0,0 @@
1
- import { detectLayoutStrategy } from './chunk-EV56K4GB.js';
2
- import { applyEventWiring } from './chunk-MHYSHSRG.js';
3
-
4
- // src/runtime/effects/composition/compose-behaviors.ts
5
- function isSchema(input) {
6
- return "orbitals" in input && Array.isArray(input.orbitals);
7
- }
8
- function asDefinitions(inputs) {
9
- return inputs.flatMap(
10
- (input) => isSchema(input) ? input.orbitals : [input]
11
- );
12
- }
13
- function mergeLedgers(inputs) {
14
- const merged = /* @__PURE__ */ new Map();
15
- let sawLedger = false;
16
- for (const input of inputs) {
17
- if (!isSchema(input) || input.ledger === void 0) continue;
18
- sawLedger = true;
19
- for (const [id, entry] of Object.entries(input.ledger.entries)) {
20
- if (!merged.has(id)) merged.set(id, entry);
21
- }
22
- }
23
- if (!sawLedger) return void 0;
24
- const entries = {};
25
- for (const [id, entry] of [...merged.entries()].sort(
26
- ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
27
- )) {
28
- entries[id] = entry;
29
- }
30
- return { schemaVersion: 1, entries };
31
- }
32
- function mergeSchemaVersions(inputs) {
33
- let max;
34
- for (const input of inputs) {
35
- if (!isSchema(input) || input.schemaVersion === void 0) continue;
36
- max = max === void 0 ? input.schemaVersion : Math.max(max, input.schemaVersion);
37
- }
38
- return max;
39
- }
40
- function toKebabCase(name) {
41
- return name.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
42
- }
43
- function generatePages(orbitals, strategy) {
44
- switch (strategy) {
45
- case "single": {
46
- const orbital = orbitals[0];
47
- const name = orbital?.name ?? "Main";
48
- return [
49
- {
50
- name: `${name}Page`,
51
- path: "/",
52
- isInitial: true,
53
- primaryEntity: getEntityName(orbital)
54
- }
55
- ];
56
- }
57
- case "dashboard": {
58
- return [
59
- {
60
- name: "DashboardPage",
61
- path: "/",
62
- viewType: "dashboard",
63
- isInitial: true
64
- }
65
- ];
66
- }
67
- case "sidebar":
68
- case "tabs":
69
- case "wizard-flow": {
70
- return orbitals.map((orbital, index) => ({
71
- name: `${orbital.name}Page`,
72
- path: index === 0 ? "/" : `/${toKebabCase(orbital.name)}`,
73
- isInitial: index === 0,
74
- primaryEntity: getEntityName(orbital)
75
- }));
76
- }
77
- }
78
- }
79
- function getEntityName(orbital) {
80
- if (!orbital) return void 0;
81
- const entity = orbital.entity;
82
- if (typeof entity === "string") {
83
- return entity.replace(".entity", "");
84
- }
85
- return entity.name;
86
- }
87
- function composeBehaviors(input) {
88
- const {
89
- appName,
90
- orbitals: rawInputs,
91
- layoutStrategy: strategyInput,
92
- eventWiring
93
- } = input;
94
- const rawOrbitals = asDefinitions(rawInputs);
95
- const wiredOrbitals = eventWiring && eventWiring.length > 0 ? applyEventWiring(rawOrbitals, eventWiring) : rawOrbitals;
96
- const strategy = !strategyInput || strategyInput === "auto" ? detectLayoutStrategy(wiredOrbitals, eventWiring) : strategyInput;
97
- const pages = generatePages(wiredOrbitals, strategy);
98
- const orbitalsWithPages = wiredOrbitals.map((orbital, index) => {
99
- if (orbital.pages && orbital.pages.length > 0) {
100
- return orbital;
101
- }
102
- const page = strategy === "dashboard" || strategy === "single" ? pages[0] : pages[index];
103
- return {
104
- ...orbital,
105
- pages: page ? [page] : []
106
- };
107
- });
108
- const ledger = mergeLedgers(rawInputs);
109
- const schemaVersion = mergeSchemaVersions(rawInputs);
110
- const schema = {
111
- name: appName,
112
- version: "1.0.0",
113
- orbitals: orbitalsWithPages,
114
- ...schemaVersion !== void 0 ? { schemaVersion } : {},
115
- ...ledger !== void 0 ? { ledger } : {}
116
- };
117
- return {
118
- schema,
119
- layout: {
120
- strategy,
121
- pageCount: pages.length
122
- },
123
- wiring: {
124
- connections: eventWiring?.length ?? 0
125
- }
126
- };
127
- }
128
-
129
- export { composeBehaviors };
@@ -1,126 +0,0 @@
1
- import { IEventBus } from '../runtime/types.js';
2
- import { EventPayload, EmittedEvent } from '@almadar/core';
3
- import '../service/default-call-service.js';
4
- import '../service/service-provider.js';
5
- import '../kernel/program-effects.js';
6
- import '../runtime/effects/composition/compose-behaviors.js';
7
- import '../runtime/effects/composition/event-wiring.js';
8
- import '../runtime/effects/composition/layout-strategy.js';
9
- import '../runtime/effects/composition/pipe.js';
10
-
11
- /**
12
- * ServerBridge - Client-Server Trait Communication
13
- *
14
- * Bridges the client EventBus with the server OrbitalRuntime:
15
- * 1. Forwards specified events from client to server
16
- * 2. Receives events from server (via polling or WebSocket)
17
- * 3. Puts server events onto client EventBus
18
- *
19
- * This enables cross-orbital communication between client and server traits.
20
- *
21
- * @example
22
- * ```typescript
23
- * import { ServerBridge } from '@kflow-builder/shared/runtime';
24
- * import { useEventBus } from './hooks/useEventBus';
25
- *
26
- * // In your app initialization
27
- * const eventBus = useEventBus();
28
- * const bridge = new ServerBridge({
29
- * eventBus,
30
- * serverUrl: '/api/orbitals',
31
- * // Events to forward from client to server
32
- * forwardEvents: ['ORDER_PLACED', 'PAYMENT_COMPLETED'],
33
- * });
34
- *
35
- * bridge.connect();
36
- *
37
- * // Now when client emits ORDER_PLACED, server traits receive it
38
- * eventBus.emit('ORDER_PLACED', { orderId: '123' });
39
- * ```
40
- *
41
- * @packageDocumentation
42
- */
43
-
44
- interface ServerBridgeConfig {
45
- /** Client EventBus to bridge */
46
- eventBus: IEventBus;
47
- /** Base URL for orbital server API */
48
- serverUrl: string;
49
- /** Events to forward from client to server */
50
- forwardEvents?: string[];
51
- /** Forward all events matching pattern (e.g., 'Order*', '*') */
52
- forwardPattern?: string;
53
- /** Target orbital for forwarded events (or 'broadcast' for all) */
54
- targetOrbital?: string;
55
- /** Enable WebSocket for real-time server events */
56
- useWebSocket?: boolean;
57
- /** Polling interval in ms (if not using WebSocket) */
58
- pollInterval?: number;
59
- /** Enable debug logging */
60
- debug?: boolean;
61
- /** Custom fetch function (for testing or custom auth) */
62
- fetch?: typeof fetch;
63
- }
64
- interface ServerBridgeState {
65
- connected: boolean;
66
- lastError?: string;
67
- eventsForwarded: number;
68
- eventsReceived: number;
69
- }
70
- /**
71
- * Bridges client EventBus with server OrbitalRuntime
72
- */
73
- declare class ServerBridge {
74
- private config;
75
- private state;
76
- private unsubscribes;
77
- private pollTimer?;
78
- private ws?;
79
- private fetchFn;
80
- /** The one HTTP request/response leg — shared with `@almadar/ui`'s transport (P5, EventTransport.ts). */
81
- private transport;
82
- constructor(config: ServerBridgeConfig);
83
- /**
84
- * Connect the bridge - start forwarding events
85
- */
86
- connect(): void;
87
- /**
88
- * Disconnect the bridge
89
- */
90
- disconnect(): void;
91
- /**
92
- * Get current bridge state
93
- */
94
- getState(): ServerBridgeState;
95
- private setupEventForwarding;
96
- private forwardToServer;
97
- private sendEventToOrbital;
98
- private fetchOrbitals;
99
- private setupPolling;
100
- private setupWebSocket;
101
- /**
102
- * Send an event directly to a specific orbital (bypassing EventBus)
103
- */
104
- sendEvent(orbitalName: string, event: string, payload?: EventPayload): Promise<{
105
- success: boolean;
106
- states?: Record<string, string>;
107
- emittedEvents?: EmittedEvent[];
108
- error?: string;
109
- }>;
110
- /**
111
- * Get current state of an orbital's traits
112
- */
113
- getOrbitalState(orbitalName: string): Promise<{
114
- success: boolean;
115
- states?: Record<string, string>;
116
- error?: string;
117
- }>;
118
- private log;
119
- }
120
- /**
121
- * Create a ServerBridge instance
122
- */
123
- declare function createServerBridge(config: ServerBridgeConfig): ServerBridge;
124
-
125
- export { ServerBridge, createServerBridge };
126
- export type { ServerBridgeConfig, ServerBridgeState };
@@ -1,3 +0,0 @@
1
- export { ServerBridge, createServerBridge } from '../chunk-D5USD2EX.js';
2
- import '../chunk-QELZ6TEJ.js';
3
- import '../chunk-MLKGABMK.js';
@@ -1,21 +0,0 @@
1
- import { CredentialStore } from './store.js';
2
- import '@almadar/core';
3
-
4
- /** One credential the app declares: the service group it belongs to and the env var / credential name. */
5
- interface DeclaredCredential {
6
- readonly service: string;
7
- readonly envVar: string;
8
- }
9
- /** The kernel export that decides a seed (`credential_admin::seed_plan`): the rows to copy, never a value. */
10
- interface CredentialSeedKernel {
11
- credentialSeedPlan(declaredJson: string, heldJson: string, presentJson: string): string;
12
- }
13
- /**
14
- * The boot of `ALMADAR_CREDENTIALS_SOURCE=store`: the kernel plans which declared credentials the store lacks and the env
15
- * holds, and this copies each into the store, so the env stays the way to hand a deployment its first keys. A name
16
- * declared twice seeds once, a held row is never overwritten. Returns the count.
17
- */
18
- declare function seedCredentialStore(store: CredentialStore, declared: readonly DeclaredCredential[], env: Record<string, string | undefined>, kernel: CredentialSeedKernel): Promise<number>;
19
-
20
- export { seedCredentialStore };
21
- export type { CredentialSeedKernel, DeclaredCredential };
@@ -1,2 +0,0 @@
1
- export { seedCredentialStore } from '../chunk-SWPDU752.js';
2
- import '../chunk-MLKGABMK.js';
@@ -1,110 +0,0 @@
1
- import { PersistenceAdapter, CredentialIdentity } from '@almadar/core';
2
-
3
- /** Entity type the credential rows persist under (never a `.lolo`-declared entity). */
4
- declare const CREDENTIAL_ENTITY_TYPE = "AlmadarIntegrationCredential";
5
- /** Env var holding the 64-char-hex AES-256 master key (Secret Manager in production). */
6
- declare const CREDENTIAL_MASTER_KEY_ENV = "ALMADAR_CREDENTIAL_MASTER_KEY";
7
- /**
8
- * Env var holding the PREVIOUS master key during a rotation window (I-28):
9
- * decryption tries the row's stamped key, `rotate()` re-encrypts every row
10
- * under the current key, then the previous key is retired from the env.
11
- */
12
- declare const CREDENTIAL_PREVIOUS_MASTER_KEY_ENV = "ALMADAR_CREDENTIAL_MASTER_KEY_PREVIOUS";
13
- /** The slice of the persistence contract the credential store uses. */
14
- type CredentialPersistence = Pick<PersistenceAdapter, 'create' | 'update' | 'delete' | 'list'>;
15
- /** Entity type the shared one-use values (a pending OAuth grant) persist under. */
16
- declare const DERIVED_ENTITY_TYPE = "AlmadarKernelDerivedSecret";
17
- /** What an adapter also offers when it can share one-use values across instances: a read by id, and a conditional delete where the store has one. */
18
- type DerivedPersistence = Pick<PersistenceAdapter, 'getById'> & Partial<Pick<PersistenceAdapter, 'writeWhere' | 'writeCapabilities'>>;
19
- /** Masked view of one stored credential — safe to return to a settings page. */
20
- interface CredentialEntry {
21
- service: string;
22
- envVar: string;
23
- last4: string;
24
- updatedAt: number;
25
- principal?: CredentialIdentity['principal'];
26
- }
27
- /**
28
- * Tenant-scoped (app-wide) credential store: one AES-256-GCM-encrypted row
29
- * per (service, envVar) through the host's persistence adapter, master key
30
- * `ALMADAR_CREDENTIAL_MASTER_KEY` held alone in the platform secret store.
31
- *
32
- * Resolution contract: credential keys ARE env-var names (the same names
33
- * `serviceCredentials` declares and `connectionRef` carries), so a stored
34
- * value transparently shadows its env counterpart — store → env →
35
- * unconfigured, everywhere.
36
- *
37
- * `warm()` decrypts all rows into memory so resolution stays synchronous;
38
- * every write re-warms the affected entry and notifies subscribers (the
39
- * `RuntimeIntegrationManager` re-configures on that signal, so new keys go
40
- * live without a restart).
41
- */
42
- declare class CredentialStore {
43
- private readonly adapter;
44
- private readonly masterKeyHex;
45
- private readonly previousKeyHex;
46
- private readonly byIdentity;
47
- private readonly listeners;
48
- private warmed;
49
- constructor(adapter: CredentialPersistence, masterKey?: string, previousMasterKey?: string);
50
- /** True when a valid master key is present (writes and decryption enabled). */
51
- get enabled(): boolean;
52
- /** Subscribe to credential changes; returns an unsubscribe function. */
53
- subscribe(listener: (principal?: string) => void): () => void;
54
- private notify;
55
- private encrypt;
56
- private decryptWithKey;
57
- /**
58
- * Decrypt one row, selecting the key by the row's stamped `keyId` (I-28):
59
- * current key first, then the rotation-window previous key. Legacy rows
60
- * (no `keyId`) try current then previous. Returns null when no held key
61
- * decrypts the row — the row is unreadable, never silently wrong (GCM
62
- * auth tags make a wrong-key success impossible).
63
- */
64
- private decryptRow;
65
- /**
66
- * Load and decrypt every stored row into memory. Returns the number of
67
- * resolvable credentials. Without a master key nothing decrypts (rows are
68
- * left in place, resolution falls through to env).
69
- */
70
- warm(): Promise<number>;
71
- /** Resolve one credential by env-var name (warmed values only). */
72
- resolve(envVar: string, principal?: string): string | undefined;
73
- /** The non-secret account label stored in the clear beside a credential's ciphertext; undefined when its row carries none. */
74
- label(envVar: string, principal?: string): string | undefined;
75
- /** All warmed values as an env-shaped map, for merging over the process env. */
76
- snapshotEnv(): Record<string, string>;
77
- /** Masked entries for display — never includes plaintext. */
78
- entries(principal?: string): CredentialEntry[];
79
- /**
80
- * Upsert one credential (encrypts, persists, re-warms the entry, notifies). `label` is a non-secret account name kept
81
- * in the clear in the row beside the ciphertext; left out, the row's label stays as it is.
82
- */
83
- set(service: string, envVar: string, value: string, principal?: string, label?: string): Promise<CredentialEntry>;
84
- /**
85
- * Re-encrypt every readable row under the CURRENT master key (I-28).
86
- * Rotation window: deploy the new key as `ALMADAR_CREDENTIAL_MASTER_KEY`
87
- * with the old one as `..._PREVIOUS`, call `rotate()`, then retire the
88
- * previous key. Rows no held key can read are counted, never dropped.
89
- */
90
- rotate(): Promise<{
91
- rotated: number;
92
- alreadyCurrent: number;
93
- unreadable: number;
94
- }>;
95
- /** Whether one-use values are shared through the adapter: a master key and an adapter that reads a row by id. */
96
- get sharesDerived(): boolean;
97
- /** Keep `value` encrypted in the adapter until `expiresAt` (epoch ms) so any instance on the same store can take it once. */
98
- holdDerived(name: string, value: string, expiresAt: number, principal?: string): Promise<void>;
99
- /**
100
- * Remove and return a held value. Where the adapter has a conditional delete only the instance whose delete
101
- * lands gets the value; elsewhere the delete is unconditional, so two instances racing for one state can both
102
- * read it. An expired value is consumed and not returned.
103
- */
104
- takeDerived(name: string, principal: string | undefined, now: number): Promise<string | undefined>;
105
- /** Delete one credential row; resolution falls back to env afterwards. */
106
- remove(envVar: string, principal?: string): Promise<boolean>;
107
- }
108
-
109
- export { CREDENTIAL_ENTITY_TYPE, CREDENTIAL_MASTER_KEY_ENV, CREDENTIAL_PREVIOUS_MASTER_KEY_ENV, CredentialStore, DERIVED_ENTITY_TYPE };
110
- export type { CredentialEntry, CredentialPersistence, DerivedPersistence };
@@ -1,2 +0,0 @@
1
- export { CREDENTIAL_ENTITY_TYPE, CREDENTIAL_MASTER_KEY_ENV, CREDENTIAL_PREVIOUS_MASTER_KEY_ENV, CredentialStore, DERIVED_ENTITY_TYPE } from '../chunk-NAECVIAR.js';
2
- import '../chunk-MLKGABMK.js';
@@ -1,46 +0,0 @@
1
- import { ComposeBehaviorsInput, ComposeBehaviorsResult, composeBehaviors } from './runtime/effects/composition/compose-behaviors.js';
2
- import { EventWiringEntry, applyEventWiring } from './runtime/effects/composition/event-wiring.js';
3
- import { LayoutStrategy, detectLayoutStrategy } from './runtime/effects/composition/layout-strategy.js';
4
- import { PipeStep, pipeBehaviors } from './runtime/effects/composition/pipe.js';
5
-
6
- /**
7
- * Composition Module
8
- *
9
- * Runtime-side TypeScript composition layer for behavior/* operators.
10
- *
11
- * Composition is normally a compile-time concept, evaluated by the Rust
12
- * compiler pass before code generation. The runtime ships an equivalent
13
- * TypeScript implementation so dev-mode hot reload, agent-driven dynamic
14
- * composition, and the legacy `composeBehaviors()` callers all have a
15
- * usable in-process implementation. The handlers are wired into
16
- * `EffectExecutor` as optional handlers (`composeBehaviors`,
17
- * `applyEventWiring`, `detectLayoutStrategy`, `pipeBehaviors`) so
18
- * consumers that do not need composition pay no cost.
19
- *
20
- * @packageDocumentation
21
- */
22
-
23
- declare const index_ComposeBehaviorsInput: typeof ComposeBehaviorsInput;
24
- declare const index_ComposeBehaviorsResult: typeof ComposeBehaviorsResult;
25
- declare const index_EventWiringEntry: typeof EventWiringEntry;
26
- declare const index_LayoutStrategy: typeof LayoutStrategy;
27
- declare const index_PipeStep: typeof PipeStep;
28
- declare const index_applyEventWiring: typeof applyEventWiring;
29
- declare const index_composeBehaviors: typeof composeBehaviors;
30
- declare const index_detectLayoutStrategy: typeof detectLayoutStrategy;
31
- declare const index_pipeBehaviors: typeof pipeBehaviors;
32
- declare namespace index {
33
- export {
34
- index_ComposeBehaviorsInput as ComposeBehaviorsInput,
35
- index_ComposeBehaviorsResult as ComposeBehaviorsResult,
36
- index_EventWiringEntry as EventWiringEntry,
37
- index_LayoutStrategy as LayoutStrategy,
38
- index_PipeStep as PipeStep,
39
- index_applyEventWiring as applyEventWiring,
40
- index_composeBehaviors as composeBehaviors,
41
- index_detectLayoutStrategy as detectLayoutStrategy,
42
- index_pipeBehaviors as pipeBehaviors,
43
- };
44
- }
45
-
46
- export { index as i };
@@ -1,32 +0,0 @@
1
- /** The keepalive fetch a beacon falls back to: always the same method, mode and `text/plain` header. */
2
- interface BeaconFetchInit {
3
- method: 'POST';
4
- body: string;
5
- keepalive: true;
6
- mode: 'cors';
7
- headers: {
8
- 'Content-Type': 'text/plain';
9
- };
10
- }
11
- /** What a host offers a beacon: a queue that may accept the text (true) or decline, and a status-only fetch. */
12
- interface BeaconDeliveryPorts {
13
- queue?: (url: string, text: string) => boolean;
14
- fetch: (url: string, init: BeaconFetchInit) => Promise<{
15
- status: number;
16
- }>;
17
- }
18
- /** How a beacon was taken: the queue accepted it, or one fetch answered `status` (null when the fetch threw). */
19
- type BeaconDelivery = {
20
- via: 'queue';
21
- } | {
22
- via: 'fetch';
23
- status: number | null;
24
- };
25
- /**
26
- * The queue-first, fetch-fallback decision, once. text/plain keeps the request CORS "simple": no preflight,
27
- * adblocker-friendly when proxied. A declined, throwing or absent queue falls back; the fetch body is never read.
28
- */
29
- declare function deliverBeacon(url: string, text: string, ports: BeaconDeliveryPorts): Promise<BeaconDelivery>;
30
-
31
- export { deliverBeacon };
32
- export type { BeaconDelivery, BeaconDeliveryPorts, BeaconFetchInit };
@@ -1,2 +0,0 @@
1
- export { deliverBeacon } from '../chunk-VMOBW7RK.js';
2
- import '../chunk-MLKGABMK.js';