@lssm/lib.contracts 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406

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 (237) hide show
  1. package/dist/app-config/app-config.feature.js +53 -1
  2. package/dist/app-config/contracts.d.ts +50 -50
  3. package/dist/app-config/contracts.js +396 -1
  4. package/dist/app-config/docs/app-config.docblock.js +22 -220
  5. package/dist/app-config/events.js +168 -1
  6. package/dist/app-config/index.js +8 -1
  7. package/dist/app-config/lifecycle-contracts.js +441 -1
  8. package/dist/app-config/runtime.js +617 -1
  9. package/dist/app-config/spec.js +36 -1
  10. package/dist/app-config/validation.js +538 -1
  11. package/dist/capabilities/docs/capabilities.docblock.js +22 -1
  12. package/dist/capabilities/openbanking.js +92 -1
  13. package/dist/capabilities.js +50 -1
  14. package/dist/client/index.js +9 -1
  15. package/dist/client/react/drivers/rn-reusables.js +21 -1
  16. package/dist/client/react/drivers/shadcn.js +11 -1
  17. package/dist/client/react/feature-render.js +43 -1
  18. package/dist/client/react/form-render.js +298 -1
  19. package/dist/client/react/index.js +8 -1
  20. package/dist/contract-registry/index.js +3 -1
  21. package/dist/contract-registry/schemas.js +61 -1
  22. package/dist/contracts-adapter-hydration.js +41 -1
  23. package/dist/contracts-adapter-input.js +77 -1
  24. package/dist/data-views/docs/data-views.docblock.js +22 -1
  25. package/dist/data-views/query-generator.js +48 -1
  26. package/dist/data-views/runtime.js +39 -1
  27. package/dist/data-views.js +35 -1
  28. package/dist/docs/PUBLISHING.docblock.js +17 -76
  29. package/dist/docs/accessibility_wcag_compliance_specs.docblock.js +17 -350
  30. package/dist/docs/index.js +33 -1
  31. package/dist/docs/meta.docs.js +15 -2
  32. package/dist/docs/presentations.js +77 -1
  33. package/dist/docs/registry.js +51 -1
  34. package/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +17 -383
  35. package/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +17 -68
  36. package/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +17 -140
  37. package/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +17 -86
  38. package/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +17 -1
  39. package/dist/docs/tech/auth/better-auth-nextjs.docblock.js +25 -2
  40. package/dist/docs/tech/contracts/README.docblock.js +21 -1
  41. package/dist/docs/tech/contracts/create-subscription.docblock.js +21 -1
  42. package/dist/docs/tech/contracts/graphql-typed-outputs.docblock.js +21 -180
  43. package/dist/docs/tech/contracts/migrations.docblock.js +21 -1
  44. package/dist/docs/tech/contracts/openapi-export.docblock.js +22 -2
  45. package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +19 -60
  46. package/dist/docs/tech/contracts/overlays.docblock.js +21 -68
  47. package/dist/docs/tech/contracts/tests.docblock.js +21 -132
  48. package/dist/docs/tech/contracts/themes.docblock.js +21 -1
  49. package/dist/docs/tech/contracts/vertical-pocket-family-office.docblock.js +21 -106
  50. package/dist/docs/tech/lifecycle-stage-system.docblock.js +17 -213
  51. package/dist/docs/tech/llm/llm-integration.docblock.js +74 -5
  52. package/dist/docs/tech/mcp-endpoints.docblock.js +38 -1
  53. package/dist/docs/tech/presentation-runtime.docblock.js +17 -1
  54. package/dist/docs/tech/schema/README.docblock.js +21 -262
  55. package/dist/docs/tech/studio/learning-events.docblock.js +49 -1
  56. package/dist/docs/tech/studio/learning-journeys.docblock.js +25 -2
  57. package/dist/docs/tech/studio/platform-admin-panel.docblock.js +24 -2
  58. package/dist/docs/tech/studio/project-access-teams.docblock.js +26 -16
  59. package/dist/docs/tech/studio/project-routing.docblock.js +68 -1
  60. package/dist/docs/tech/studio/sandbox-unlogged.docblock.js +23 -2
  61. package/dist/docs/tech/studio/team-invitations.docblock.js +41 -36
  62. package/dist/docs/tech/studio/workspace-ops.docblock.js +48 -1
  63. package/dist/docs/tech/studio/workspaces.docblock.js +24 -2
  64. package/dist/docs/tech/telemetry-ingest.docblock.js +37 -3
  65. package/dist/docs/tech/templates/runtime.docblock.js +21 -1
  66. package/dist/docs/tech/vscode-extension.docblock.js +37 -3
  67. package/dist/docs/tech/workflows/overview.docblock.js +21 -1
  68. package/dist/docs/tech-contracts.docs.js +19 -2
  69. package/dist/events.js +12 -1
  70. package/dist/experiments/docs/experiments.docblock.js +22 -128
  71. package/dist/experiments/evaluator.js +101 -1
  72. package/dist/experiments/spec.js +33 -1
  73. package/dist/features.js +68 -1
  74. package/dist/forms/docs/forms.docblock.js +22 -1
  75. package/dist/forms.js +119 -1
  76. package/dist/index.js +107 -1
  77. package/dist/install.js +40 -1
  78. package/dist/integrations/contracts.d.ts +102 -102
  79. package/dist/integrations/contracts.js +388 -1
  80. package/dist/integrations/docs/integrations.docblock.js +95 -1
  81. package/dist/integrations/health.js +69 -1
  82. package/dist/integrations/index.js +23 -1
  83. package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
  84. package/dist/integrations/openbanking/contracts/accounts.js +237 -1
  85. package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
  86. package/dist/integrations/openbanking/contracts/balances.js +167 -1
  87. package/dist/integrations/openbanking/contracts/index.js +12 -1
  88. package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
  89. package/dist/integrations/openbanking/contracts/transactions.js +218 -1
  90. package/dist/integrations/openbanking/guards.js +32 -1
  91. package/dist/integrations/openbanking/models.d.ts +55 -55
  92. package/dist/integrations/openbanking/models.js +242 -1
  93. package/dist/integrations/openbanking/openbanking.feature.js +68 -1
  94. package/dist/integrations/openbanking/telemetry.js +39 -1
  95. package/dist/integrations/providers/elevenlabs.js +56 -1
  96. package/dist/integrations/providers/gcs-storage.js +79 -1
  97. package/dist/integrations/providers/gmail.js +91 -1
  98. package/dist/integrations/providers/google-calendar.js +70 -1
  99. package/dist/integrations/providers/impls/elevenlabs-voice.js +95 -1
  100. package/dist/integrations/providers/impls/gcs-storage.js +88 -1
  101. package/dist/integrations/providers/impls/gmail-inbound.js +200 -1
  102. package/dist/integrations/providers/impls/gmail-outbound.js +104 -5
  103. package/dist/integrations/providers/impls/google-calendar.js +154 -1
  104. package/dist/integrations/providers/impls/index.js +16 -1
  105. package/dist/integrations/providers/impls/mistral-embedding.js +41 -1
  106. package/dist/integrations/providers/impls/mistral-llm.js +247 -1
  107. package/dist/integrations/providers/impls/postmark-email.js +55 -1
  108. package/dist/integrations/providers/impls/powens-client.js +171 -1
  109. package/dist/integrations/providers/impls/powens-openbanking.js +218 -1
  110. package/dist/integrations/providers/impls/provider-factory.js +142 -1
  111. package/dist/integrations/providers/impls/qdrant-vector.js +69 -1
  112. package/dist/integrations/providers/impls/stripe-payments.js +202 -1
  113. package/dist/integrations/providers/impls/twilio-sms.js +58 -1
  114. package/dist/integrations/providers/index.js +13 -1
  115. package/dist/integrations/providers/mistral.js +72 -1
  116. package/dist/integrations/providers/postmark.js +72 -1
  117. package/dist/integrations/providers/powens.js +120 -1
  118. package/dist/integrations/providers/qdrant.js +77 -1
  119. package/dist/integrations/providers/registry.js +34 -1
  120. package/dist/integrations/providers/stripe.js +87 -1
  121. package/dist/integrations/providers/twilio-sms.js +65 -1
  122. package/dist/integrations/runtime.js +186 -1
  123. package/dist/integrations/secrets/aws-secret-manager.js +231 -1
  124. package/dist/integrations/secrets/env-secret-provider.js +81 -1
  125. package/dist/integrations/secrets/gcp-secret-manager.js +229 -1
  126. package/dist/integrations/secrets/index.js +8 -1
  127. package/dist/integrations/secrets/manager.js +103 -1
  128. package/dist/integrations/secrets/provider.js +58 -1
  129. package/dist/integrations/secrets/scaleway-secret-manager.js +247 -1
  130. package/dist/integrations/spec.js +39 -1
  131. package/dist/jobs/define-job.js +16 -1
  132. package/dist/jobs/gcp-cloud-tasks.js +53 -1
  133. package/dist/jobs/gcp-pubsub.js +39 -1
  134. package/dist/jobs/handlers/gmail-sync-handler.js +9 -1
  135. package/dist/jobs/handlers/index.js +12 -1
  136. package/dist/jobs/handlers/ping-handler.js +15 -1
  137. package/dist/jobs/handlers/storage-document-handler.js +14 -1
  138. package/dist/jobs/index.js +4 -1
  139. package/dist/jobs/memory-queue.js +71 -1
  140. package/dist/jobs/queue.js +33 -1
  141. package/dist/jobs/scaleway-sqs-queue.js +153 -1
  142. package/dist/jsonschema.d.ts +3 -3
  143. package/dist/jsonschema.js +32 -1
  144. package/dist/knowledge/contracts.d.ts +66 -66
  145. package/dist/knowledge/contracts.js +317 -1
  146. package/dist/knowledge/docs/knowledge.docblock.js +22 -138
  147. package/dist/knowledge/index.js +10 -1
  148. package/dist/knowledge/ingestion/document-processor.js +54 -1
  149. package/dist/knowledge/ingestion/embedding-service.js +25 -1
  150. package/dist/knowledge/ingestion/gmail-adapter.js +50 -5
  151. package/dist/knowledge/ingestion/index.js +7 -1
  152. package/dist/knowledge/ingestion/storage-adapter.js +26 -1
  153. package/dist/knowledge/ingestion/vector-indexer.js +32 -1
  154. package/dist/knowledge/query/index.js +3 -1
  155. package/dist/knowledge/query/service.js +64 -2
  156. package/dist/knowledge/runtime.js +49 -1
  157. package/dist/knowledge/spaces/email-threads.js +38 -1
  158. package/dist/knowledge/spaces/financial-docs.js +38 -1
  159. package/dist/knowledge/spaces/financial-overview.js +42 -1
  160. package/dist/knowledge/spaces/index.js +8 -1
  161. package/dist/knowledge/spaces/product-canon.js +38 -1
  162. package/dist/knowledge/spaces/support-faq.js +41 -1
  163. package/dist/knowledge/spaces/uploaded-docs.js +38 -1
  164. package/dist/knowledge/spec.js +39 -1
  165. package/dist/llm/exporters.js +541 -8
  166. package/dist/llm/index.js +4 -1
  167. package/dist/llm/prompts.js +246 -56
  168. package/dist/markdown.js +116 -3
  169. package/dist/migrations.js +33 -1
  170. package/dist/onboarding-base.d.ts +29 -29
  171. package/dist/onboarding-base.js +196 -1
  172. package/dist/openapi.js +75 -1
  173. package/dist/openbanking/docs/openbanking.docblock.js +22 -109
  174. package/dist/ownership.js +40 -1
  175. package/dist/policy/docs/policy.docblock.js +22 -1
  176. package/dist/policy/engine.js +223 -1
  177. package/dist/policy/opa-adapter.js +71 -1
  178. package/dist/policy/spec.js +33 -1
  179. package/dist/presentations/docs/presentations-conventions.docblock.js +21 -7
  180. package/dist/presentations.backcompat.js +47 -1
  181. package/dist/presentations.d.ts +3 -3
  182. package/dist/presentations.js +66 -1
  183. package/dist/presentations.v2.js +278 -6
  184. package/dist/prompt.js +10 -1
  185. package/dist/promptRegistry.js +34 -1
  186. package/dist/regenerator/docs/regenerator.docblock.js +22 -184
  187. package/dist/regenerator/executor.js +86 -1
  188. package/dist/regenerator/index.js +6 -1
  189. package/dist/regenerator/service.js +92 -1
  190. package/dist/regenerator/sinks.js +32 -1
  191. package/dist/regenerator/utils.js +51 -1
  192. package/dist/registry.js +208 -1
  193. package/dist/resources.js +47 -1
  194. package/dist/schema/dist/EnumType.js +2 -1
  195. package/dist/schema/dist/FieldType.js +49 -1
  196. package/dist/schema/dist/ScalarTypeEnum.js +236 -1
  197. package/dist/schema/dist/SchemaModel.js +39 -1
  198. package/dist/schema/dist/entity/defineEntity.js +1 -1
  199. package/dist/schema/dist/entity/index.js +2 -1
  200. package/dist/schema/dist/entity/types.js +1 -1
  201. package/dist/schema/dist/index.js +6 -1
  202. package/dist/schema-to-markdown.js +214 -10
  203. package/dist/server/graphql-pothos.js +128 -1
  204. package/dist/server/index.js +10 -1
  205. package/dist/server/mcp/createMcpServer.js +28 -1
  206. package/dist/server/mcp/registerPresentations.js +151 -1
  207. package/dist/server/mcp/registerPrompts.js +36 -2
  208. package/dist/server/mcp/registerResources.js +35 -1
  209. package/dist/server/mcp/registerTools.js +22 -1
  210. package/dist/server/provider-mcp.js +3 -1
  211. package/dist/server/rest-elysia.js +20 -1
  212. package/dist/server/rest-express.js +39 -1
  213. package/dist/server/rest-generic.js +125 -1
  214. package/dist/server/rest-next-app.js +38 -1
  215. package/dist/server/rest-next-mcp.js +45 -1
  216. package/dist/server/rest-next-pages.js +25 -1
  217. package/dist/spec.js +35 -1
  218. package/dist/telemetry/anomaly.js +48 -1
  219. package/dist/telemetry/docs/telemetry.docblock.js +22 -139
  220. package/dist/telemetry/index.js +5 -1
  221. package/dist/telemetry/spec.js +69 -1
  222. package/dist/telemetry/tracker.js +76 -1
  223. package/dist/tests/index.js +4 -1
  224. package/dist/tests/runner.js +150 -1
  225. package/dist/tests/spec.js +33 -1
  226. package/dist/themes.js +39 -1
  227. package/dist/workflow/adapters/db-adapter.js +83 -1
  228. package/dist/workflow/adapters/file-adapter.js +11 -1
  229. package/dist/workflow/adapters/index.js +5 -1
  230. package/dist/workflow/adapters/memory-store.js +58 -1
  231. package/dist/workflow/expression.js +98 -1
  232. package/dist/workflow/index.js +9 -1
  233. package/dist/workflow/runner.js +337 -1
  234. package/dist/workflow/sla-monitor.js +47 -1
  235. package/dist/workflow/spec.js +32 -1
  236. package/dist/workflow/validation.js +175 -1
  237. package/package.json +11 -4
@@ -1 +1,92 @@
1
- import{behaviorToEnvelope as e,errorToEnvelope as t,telemetryToEnvelope as n}from"./utils.js";import{setTimeout as r}from"node:timers/promises";var i=class{contexts;lastPoll=new Map;timer;running=!1;pollInterval;batchDuration;clock;constructor(e){if(this.options=e,this.contexts=new Map(e.contexts.map(e=>[e.id,e])),this.pollInterval=e.pollIntervalMs??6e4,this.batchDuration=e.batchDurationMs??3e5,this.clock=e.clock??(()=>new Date),this.options.rules.length===0)throw Error(`RegeneratorService requires at least one rule`)}start(){this.running||(this.running=!0,this.tick(),this.timer=setInterval(()=>{this.tick()},this.pollInterval))}stop(){this.running&&(this.running=!1,this.timer&&=(clearInterval(this.timer),void 0))}async runOnce(){await this.tick()}async tick(){let e=this.clock(),t=new Date(e.getTime()-this.batchDuration);for(let n of this.contexts.values()){let r=this.lastPoll.get(n.id)??t;await this.evaluateContext(n,r,e),this.lastPoll.set(n.id,e)}}async evaluateContext(e,t,n){let r=await this.collectSignals(e,t,n);if(r.length!==0)for(let t of this.options.rules){let n=[];try{n=await t.evaluate(e,r)}catch(e){console.error(`[regenerator] rule ${t.id} failed`,e instanceof Error?e:Error(String(e)));continue}await this.flushProposals(e,n)}}async collectSignals(r,i,a){let o=[],{adapters:s}=this.options;if(s.telemetry){let e=await s.telemetry.pollTelemetry(r,i,a);o.push(...e.map(e=>n(r.id,e,this.clock)))}if(s.errors){let e=await s.errors.pollErrors(r,i,a);o.push(...e.map(e=>t(r.id,e,this.clock)))}if(s.behavior){let t=await s.behavior.pollBehavior(r,i,a);o.push(...t.map(t=>e(r.id,t,this.clock)))}return o}async flushProposals(e,t){for(let n of t)n.signalIds.length!==0&&(await this.options.sink.submit(e,n),t.length>10&&await r(0))}};export{i as RegeneratorService};
1
+ import { behaviorToEnvelope, errorToEnvelope, telemetryToEnvelope } from "./utils.js";
2
+ import { setTimeout } from "node:timers/promises";
3
+
4
+ //#region src/regenerator/service.ts
5
+ const DEFAULT_POLL_INTERVAL = 6e4;
6
+ const DEFAULT_BATCH_DURATION = 5 * 6e4;
7
+ var RegeneratorService = class {
8
+ contexts;
9
+ lastPoll = /* @__PURE__ */ new Map();
10
+ timer;
11
+ running = false;
12
+ pollInterval;
13
+ batchDuration;
14
+ clock;
15
+ constructor(options) {
16
+ this.options = options;
17
+ this.contexts = new Map(options.contexts.map((ctx) => [ctx.id, ctx]));
18
+ this.pollInterval = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL;
19
+ this.batchDuration = options.batchDurationMs ?? DEFAULT_BATCH_DURATION;
20
+ this.clock = options.clock ?? (() => /* @__PURE__ */ new Date());
21
+ if (this.options.rules.length === 0) throw new Error("RegeneratorService requires at least one rule");
22
+ }
23
+ start() {
24
+ if (this.running) return;
25
+ this.running = true;
26
+ this.tick();
27
+ this.timer = setInterval(() => {
28
+ this.tick();
29
+ }, this.pollInterval);
30
+ }
31
+ stop() {
32
+ if (!this.running) return;
33
+ this.running = false;
34
+ if (this.timer) {
35
+ clearInterval(this.timer);
36
+ this.timer = void 0;
37
+ }
38
+ }
39
+ async runOnce() {
40
+ await this.tick();
41
+ }
42
+ async tick() {
43
+ const now = this.clock();
44
+ const sinceDefault = new Date(now.getTime() - this.batchDuration);
45
+ for (const context of this.contexts.values()) {
46
+ const last = this.lastPoll.get(context.id) ?? sinceDefault;
47
+ await this.evaluateContext(context, last, now);
48
+ this.lastPoll.set(context.id, now);
49
+ }
50
+ }
51
+ async evaluateContext(context, since, until) {
52
+ const signals = await this.collectSignals(context, since, until);
53
+ if (signals.length === 0) return;
54
+ for (const rule of this.options.rules) {
55
+ let proposals = [];
56
+ try {
57
+ proposals = await rule.evaluate(context, signals);
58
+ } catch (error) {
59
+ console.error(`[regenerator] rule ${rule.id} failed`, error instanceof Error ? error : new Error(String(error)));
60
+ continue;
61
+ }
62
+ await this.flushProposals(context, proposals);
63
+ }
64
+ }
65
+ async collectSignals(context, since, until) {
66
+ const envelopes = [];
67
+ const { adapters } = this.options;
68
+ if (adapters.telemetry) {
69
+ const telemetrySignals = await adapters.telemetry.pollTelemetry(context, since, until);
70
+ envelopes.push(...telemetrySignals.map((signal) => telemetryToEnvelope(context.id, signal, this.clock)));
71
+ }
72
+ if (adapters.errors) {
73
+ const errorSignals = await adapters.errors.pollErrors(context, since, until);
74
+ envelopes.push(...errorSignals.map((signal) => errorToEnvelope(context.id, signal, this.clock)));
75
+ }
76
+ if (adapters.behavior) {
77
+ const behaviorSignals = await adapters.behavior.pollBehavior(context, since, until);
78
+ envelopes.push(...behaviorSignals.map((signal) => behaviorToEnvelope(context.id, signal, this.clock)));
79
+ }
80
+ return envelopes;
81
+ }
82
+ async flushProposals(context, proposals) {
83
+ for (const proposal of proposals) {
84
+ if (proposal.signalIds.length === 0) continue;
85
+ await this.options.sink.submit(context, proposal);
86
+ if (proposals.length > 10) await setTimeout(0);
87
+ }
88
+ }
89
+ };
90
+
91
+ //#endregion
92
+ export { RegeneratorService };
@@ -1 +1,32 @@
1
- var e=class{constructor(e,t={}){this.executor=e,this.options=t}async submit(e,t){let n=this.options.dryRun??!1;try{let r=await this.executor.execute(e,t,{dryRun:n});this.options.logger?.info&&this.options.logger.info(`[regenerator] proposal executed`,{proposalId:t.id,contextId:e.id,status:r.status}),this.options.onResult&&await this.options.onResult({context:e,proposal:t,result:r})}catch(n){throw this.options.logger?.error&&this.options.logger.error(`[regenerator] proposal execution failed`,n instanceof Error?n:Error(String(n)),{proposalId:t.id,contextId:e.id}),n instanceof Error?n:Error(String(n))}}};export{e as ExecutorProposalSink};
1
+ //#region src/regenerator/sinks.ts
2
+ var ExecutorProposalSink = class {
3
+ constructor(executor, options = {}) {
4
+ this.executor = executor;
5
+ this.options = options;
6
+ }
7
+ async submit(context, proposal) {
8
+ const dryRun = this.options.dryRun ?? false;
9
+ try {
10
+ const result = await this.executor.execute(context, proposal, { dryRun });
11
+ if (this.options.logger?.info) this.options.logger.info("[regenerator] proposal executed", {
12
+ proposalId: proposal.id,
13
+ contextId: context.id,
14
+ status: result.status
15
+ });
16
+ if (this.options.onResult) await this.options.onResult({
17
+ context,
18
+ proposal,
19
+ result
20
+ });
21
+ } catch (error) {
22
+ if (this.options.logger?.error) this.options.logger.error("[regenerator] proposal execution failed", error instanceof Error ? error : new Error(String(error)), {
23
+ proposalId: proposal.id,
24
+ contextId: context.id
25
+ });
26
+ throw error instanceof Error ? error : new Error(String(error));
27
+ }
28
+ }
29
+ };
30
+
31
+ //#endregion
32
+ export { ExecutorProposalSink };
@@ -1 +1,51 @@
1
- function e(e,t,n){return{type:`telemetry`,contextId:e,signal:r(t,n)}}function t(e,t,n){return{type:`error`,contextId:e,signal:i(t,n)}}function n(e,t,n){return{type:`behavior`,contextId:e,signal:a(t,n)}}function r(e,t){return{...e,windowStart:o(e.windowStart,t),windowEnd:o(e.windowEnd,t)}}function i(e,t){return{...e,occurredAt:o(e.occurredAt,t)}}function a(e,t){return{...e,windowStart:o(e.windowStart,t),windowEnd:o(e.windowEnd,t)}}function o(e,t){if(e instanceof Date)return e;let n=new Date(e);return Number.isNaN(n.getTime())?t():n}export{n as behaviorToEnvelope,t as errorToEnvelope,e as telemetryToEnvelope};
1
+ //#region src/regenerator/utils.ts
2
+ function telemetryToEnvelope(contextId, signal, clock) {
3
+ return {
4
+ type: "telemetry",
5
+ contextId,
6
+ signal: normalizeTelemetryDates(signal, clock)
7
+ };
8
+ }
9
+ function errorToEnvelope(contextId, signal, clock) {
10
+ return {
11
+ type: "error",
12
+ contextId,
13
+ signal: normalizeErrorDates(signal, clock)
14
+ };
15
+ }
16
+ function behaviorToEnvelope(contextId, signal, clock) {
17
+ return {
18
+ type: "behavior",
19
+ contextId,
20
+ signal: normalizeBehaviorDates(signal, clock)
21
+ };
22
+ }
23
+ function normalizeTelemetryDates(signal, clock) {
24
+ return {
25
+ ...signal,
26
+ windowStart: toDate(signal.windowStart, clock),
27
+ windowEnd: toDate(signal.windowEnd, clock)
28
+ };
29
+ }
30
+ function normalizeErrorDates(signal, clock) {
31
+ return {
32
+ ...signal,
33
+ occurredAt: toDate(signal.occurredAt, clock)
34
+ };
35
+ }
36
+ function normalizeBehaviorDates(signal, clock) {
37
+ return {
38
+ ...signal,
39
+ windowStart: toDate(signal.windowStart, clock),
40
+ windowEnd: toDate(signal.windowEnd, clock)
41
+ };
42
+ }
43
+ function toDate(value, clock) {
44
+ if (value instanceof Date) return value;
45
+ const parsed = new Date(value);
46
+ if (Number.isNaN(parsed.getTime())) return clock();
47
+ return parsed;
48
+ }
49
+
50
+ //#endregion
51
+ export { behaviorToEnvelope, errorToEnvelope, telemetryToEnvelope };
package/dist/registry.js CHANGED
@@ -1 +1,208 @@
1
- import{eventKey as e}from"./events.js";import{isEmitDeclRef as t}from"./spec.js";import{defaultDocRegistry as n,docId as r,registerDocBlocks as i}from"./docs/registry.js";function a(e,t){return`${e}.v${t}`}var o=class{specs=new Map;handlers=new Map;register(e){let t=a(e.meta.name,e.meta.version);if(this.specs.has(t))throw Error(`Duplicate spec ${t}`);return this.specs.set(t,e),this}bind(e,t){let n=a(e.meta.name,e.meta.version);if(!this.specs.has(n))throw Error(`Cannot bind; spec not found: ${n}`);if(this.handlers.has(n))throw Error(`Handler already bound for ${n}`);return this.handlers.set(n,t),this}getSpec(e,t){if(t!=null)return this.specs.get(a(e,t));let n,r=-1/0;for(let[t,i]of this.specs.entries())t.startsWith(`${e}.v`)&&i.meta.version>r&&(r=i.meta.version,n=i);return n}getHandler(e,t){let n=this.getSpec(e,t);if(n)return this.handlers.get(a(n.meta.name,n.meta.version))}listSpecs(){return[...this.specs.values()]}listBound(){let e=[];for(let[t,n]of this.specs.entries()){let r=this.handlers.get(t);r&&e.push({spec:n,handler:r})}return e}async execute(n,r,i,o){let s=this.getSpec(n,r);if(!s)throw Error(`Spec not found for ${n}${r?`.v${r}`:``}`);let c=await o.specVariantResolver?.resolve({name:s.meta.name,version:s.meta.version,kind:s.meta.kind},o)??s,l=a(c.meta.name,c.meta.version),u=this.handlers.get(l);if(!u){let e=a(s.meta.name,s.meta.version);u=this.handlers.get(e),l=e}if(!u)throw Error(`No handler bound for ${l}`);let d=c.io.input?.getZod().parse(i);if(o.decide){let[e,t]=c.meta.name.split(`.`),n=await o.decide({service:e,command:t,version:c.meta.version,actor:o.actor??`anonymous`,channel:o.channel,roles:o.roles,organizationId:o.organizationId,userId:o.userId,flags:[]});if(n.effect===`deny`)throw Error(`PolicyDenied: ${c.meta.name}.v${c.meta.version}`);if(n.rateLimit&&o.rateLimit){let e=n.rateLimit.key??`default`,t=n.rateLimit.rpm??60;await o.rateLimit(e,1,t)}}let f=new Map;if(c.sideEffects?.emits)for(let e of c.sideEffects.emits)t(e)?f.set(`${e.ref.name}.v${e.ref.version}`,e.ref.payload):f.set(`${e.name}.v${e.version}`,e.payload);let p=async(t,n,r)=>{let i=e(t,n),s=f.get(i);if(!s)throw Error(`UndeclaredEvent: ${i} not allowed by ${a(c.meta.name,c.meta.version)}`);let l=s.getZod().parse(r);await o.eventPublisher?.({name:t,version:n,payload:l,traceId:o.traceId})};o.appConfig&&(o.branding||=o.appConfig.branding,o.translation?o.translation.config||(o.translation={...o.translation,config:o.appConfig.translation}):o.translation={config:o.appConfig.translation});let m=o.telemetry,h=async(e,t)=>{if(!(!m||!e?.event))try{let n=e.properties?.(t)??{};await m.track(e.event.name,e.event.version??1,n,{tenantId:o.organizationId??void 0,organizationId:o.organizationId,userId:o.userId,actor:o.actor,channel:o.channel,metadata:o.traceId?{traceId:o.traceId}:void 0})}catch{}},g;try{g=await u(d,{...o,__emitGuard__:p})}catch(e){throw c.telemetry?.failure&&await h(c.telemetry.failure,{input:d??i,error:e}),e}c.telemetry?.success&&await h(c.telemetry.success,{input:d??i,output:g});let _=c.io.output;return _?.getZod?_.getZod().parse(g):g}};export{o as SpecRegistry,n as defaultDocRegistry,r as docId,a as opKey,i as registerDocBlocks};
1
+ import { eventKey } from "./events.js";
2
+ import { isEmitDeclRef } from "./spec.js";
3
+ import { defaultDocRegistry, docId, registerDocBlocks } from "./docs/registry.js";
4
+
5
+ //#region src/registry.ts
6
+ /**
7
+ * SpecRegistry:
8
+ * - Registers ContractSpecs (unique by name+version)
9
+ * - Binds runtime handlers to specs
10
+ * - Provides lookup, iteration, and a safe execute() with validation/policy/enforcement
11
+ *
12
+ * Includes a minimal OpRegistry shim for backward-compat (deprecated).
13
+ */
14
+ function opKey(name, version) {
15
+ return `${name}.v${version}`;
16
+ }
17
+ /**
18
+ * In-memory registry for ContractSpecs and their bound handlers.
19
+ * Provides validation, policy enforcement, and guarded event emission at execute time.
20
+ */
21
+ var SpecRegistry = class {
22
+ specs = /* @__PURE__ */ new Map();
23
+ handlers = /* @__PURE__ */ new Map();
24
+ /**
25
+ * Registers a ContractSpec definition.
26
+ *
27
+ * @param spec - The contract specification to register.
28
+ * @returns The registry instance for chaining.
29
+ * @throws If a spec with the same name and version is already registered.
30
+ */
31
+ register(spec) {
32
+ const key = opKey(spec.meta.name, spec.meta.version);
33
+ if (this.specs.has(key)) throw new Error(`Duplicate spec ${key}`);
34
+ this.specs.set(key, spec);
35
+ return this;
36
+ }
37
+ /**
38
+ * Binds a runtime handler implementation to a previously registered spec.
39
+ *
40
+ * @param spec - The spec to bind to.
41
+ * @param handler - The async function implementing the business logic.
42
+ * @returns The registry instance for chaining.
43
+ * @throws If the spec is not found or a handler is already bound.
44
+ */
45
+ bind(spec, handler) {
46
+ const key = opKey(spec.meta.name, spec.meta.version);
47
+ if (!this.specs.has(key)) throw new Error(`Cannot bind; spec not found: ${key}`);
48
+ if (this.handlers.has(key)) throw new Error(`Handler already bound for ${key}`);
49
+ this.handlers.set(key, handler);
50
+ return this;
51
+ }
52
+ /**
53
+ * Retrieves a registered spec by name and version.
54
+ * If version is omitted, returns the highest version found.
55
+ *
56
+ * @param name - Operation name.
57
+ * @param version - (Optional) Specific version.
58
+ */
59
+ getSpec(name, version) {
60
+ if (version != null) return this.specs.get(opKey(name, version));
61
+ let found;
62
+ let maxV = -Infinity;
63
+ for (const [k, s] of this.specs.entries()) {
64
+ if (!k.startsWith(`${name}.v`)) continue;
65
+ if (s.meta.version > maxV) {
66
+ maxV = s.meta.version;
67
+ found = s;
68
+ }
69
+ }
70
+ return found;
71
+ }
72
+ /**
73
+ * Retrieves the bound handler for a spec.
74
+ */
75
+ getHandler(name, version) {
76
+ const spec = this.getSpec(name, version);
77
+ if (!spec) return void 0;
78
+ return this.handlers.get(opKey(spec.meta.name, spec.meta.version));
79
+ }
80
+ /** Iterate all registered specs. */
81
+ listSpecs() {
82
+ return [...this.specs.values()];
83
+ }
84
+ /** Iterate all bound operations (spec+handler). */
85
+ listBound() {
86
+ const out = [];
87
+ for (const [k, spec] of this.specs.entries()) {
88
+ const h = this.handlers.get(k);
89
+ if (h) out.push({
90
+ spec,
91
+ handler: h
92
+ });
93
+ }
94
+ return out;
95
+ }
96
+ /**
97
+ * Execute an operation by name/version with full runtime protections:
98
+ * 1. Validates input against Zod schema.
99
+ * 2. Enforces policy (Auth, RBAC, Rate Limits) via PDP.
100
+ * 3. Guards event emission to ensure only declared events are sent.
101
+ * 4. Validates output against Zod schema (if applicable).
102
+ * 5. Tracks telemetry (success/failure).
103
+ *
104
+ * @param name - Operation name.
105
+ * @param version - Operation version (optional, defaults to latest).
106
+ * @param rawInput - The raw input payload (e.g. from JSON body).
107
+ * @param ctx - The runtime context (actor, tenant, etc.).
108
+ */
109
+ async execute(name, version, rawInput, ctx) {
110
+ const baseSpec = this.getSpec(name, version);
111
+ if (!baseSpec) throw new Error(`Spec not found for ${name}${version ? `.v${version}` : ""}`);
112
+ const spec = await ctx.specVariantResolver?.resolve({
113
+ name: baseSpec.meta.name,
114
+ version: baseSpec.meta.version,
115
+ kind: baseSpec.meta.kind
116
+ }, ctx) ?? baseSpec;
117
+ let key = opKey(spec.meta.name, spec.meta.version);
118
+ let handler = this.handlers.get(key);
119
+ if (!handler) {
120
+ const fallbackKey = opKey(baseSpec.meta.name, baseSpec.meta.version);
121
+ handler = this.handlers.get(fallbackKey);
122
+ key = fallbackKey;
123
+ }
124
+ if (!handler) throw new Error(`No handler bound for ${key}`);
125
+ const parsedInput = spec.io.input?.getZod().parse(rawInput);
126
+ if (ctx.decide) {
127
+ const [service, command] = spec.meta.name.split(".");
128
+ const decision = await ctx.decide({
129
+ service,
130
+ command,
131
+ version: spec.meta.version,
132
+ actor: ctx.actor ?? "anonymous",
133
+ channel: ctx.channel,
134
+ roles: ctx.roles,
135
+ organizationId: ctx.organizationId,
136
+ userId: ctx.userId,
137
+ flags: []
138
+ });
139
+ if (decision.effect === "deny") throw new Error(`PolicyDenied: ${spec.meta.name}.v${spec.meta.version}`);
140
+ if (decision.rateLimit && ctx.rateLimit) {
141
+ const key$1 = decision.rateLimit.key ?? "default";
142
+ const rpm = decision.rateLimit.rpm ?? 60;
143
+ await ctx.rateLimit(key$1, 1, rpm);
144
+ }
145
+ }
146
+ const allowedEvents = /* @__PURE__ */ new Map();
147
+ if (spec.sideEffects?.emits) for (const e of spec.sideEffects.emits) if (isEmitDeclRef(e)) allowedEvents.set(`${e.ref.name}.v${e.ref.version}`, e.ref.payload);
148
+ else allowedEvents.set(`${e.name}.v${e.version}`, e.payload);
149
+ const emitGuard = async (eventName, eventVersion, payload) => {
150
+ const key2 = eventKey(eventName, eventVersion);
151
+ const schema = allowedEvents.get(key2);
152
+ if (!schema) throw new Error(`UndeclaredEvent: ${key2} not allowed by ${opKey(spec.meta.name, spec.meta.version)}`);
153
+ const parsed = schema.getZod().parse(payload);
154
+ await ctx.eventPublisher?.({
155
+ name: eventName,
156
+ version: eventVersion,
157
+ payload: parsed,
158
+ traceId: ctx.traceId
159
+ });
160
+ };
161
+ if (ctx.appConfig) {
162
+ if (!ctx.branding) ctx.branding = ctx.appConfig.branding;
163
+ if (!ctx.translation) ctx.translation = { config: ctx.appConfig.translation };
164
+ else if (!ctx.translation.config) ctx.translation = {
165
+ ...ctx.translation,
166
+ config: ctx.appConfig.translation
167
+ };
168
+ }
169
+ const telemetryContext = ctx.telemetry;
170
+ const trackTelemetry = async (trigger, details) => {
171
+ if (!telemetryContext || !trigger?.event) return;
172
+ try {
173
+ const props = trigger.properties?.(details) ?? {};
174
+ await telemetryContext.track(trigger.event.name, trigger.event.version ?? 1, props, {
175
+ tenantId: ctx.organizationId ?? void 0,
176
+ organizationId: ctx.organizationId,
177
+ userId: ctx.userId,
178
+ actor: ctx.actor,
179
+ channel: ctx.channel,
180
+ metadata: ctx.traceId ? { traceId: ctx.traceId } : void 0
181
+ });
182
+ } catch (_error) {}
183
+ };
184
+ let result;
185
+ try {
186
+ result = await handler(parsedInput, {
187
+ ...ctx,
188
+ __emitGuard__: emitGuard
189
+ });
190
+ } catch (error) {
191
+ if (spec.telemetry?.failure) await trackTelemetry(spec.telemetry.failure, {
192
+ input: parsedInput ?? rawInput,
193
+ error
194
+ });
195
+ throw error;
196
+ }
197
+ if (spec.telemetry?.success) await trackTelemetry(spec.telemetry.success, {
198
+ input: parsedInput ?? rawInput,
199
+ output: result
200
+ });
201
+ const outputModel = spec.io.output;
202
+ if (outputModel?.getZod) return outputModel.getZod().parse(result);
203
+ return result;
204
+ }
205
+ };
206
+
207
+ //#endregion
208
+ export { SpecRegistry, defaultDocRegistry, docId, opKey, registerDocBlocks };
package/dist/resources.js CHANGED
@@ -1 +1,47 @@
1
- import"zod";function e(e){return e}var t=class{templates=[];register(e){return this.templates.push(e),this}listTemplates(){return[...this.templates]}match(e){for(let t of this.templates){let n=RegExp(`^`+t.meta.uriTemplate.replace(/\{[^}]+\}/g,`([^/]+)`)+`$`),r=e.match(n);if(!r)continue;let i=[...t.meta.uriTemplate.matchAll(/\{([^}]+)\}/g)].map(e=>e[1]),a={};return i.forEach((e,t)=>a[e]=decodeURIComponent(r[t+1])),{tmpl:t,params:a}}}};function n(e,t){return{kind:`resource_ref`,uriTemplate:e,varName:t.varName??`id`,graphQLType:t.graphQLType,many:t.many}}function r(e){let t=e;return!!t&&t.kind===`resource_ref`&&typeof t.uriTemplate==`string`}export{t as ResourceRegistry,e as defineResourceTemplate,r as isResourceRef,n as resourceRef};
1
+ import "zod";
2
+
3
+ //#region src/resources.ts
4
+ function defineResourceTemplate(spec) {
5
+ return spec;
6
+ }
7
+ var ResourceRegistry = class {
8
+ templates = [];
9
+ register(tmpl) {
10
+ this.templates.push(tmpl);
11
+ return this;
12
+ }
13
+ listTemplates() {
14
+ return [...this.templates];
15
+ }
16
+ /** Try to match a concrete URI to a template by naive pattern substitution */
17
+ match(uri) {
18
+ for (const tmpl of this.templates) {
19
+ const re = /* @__PURE__ */ new RegExp("^" + tmpl.meta.uriTemplate.replace(/\{[^}]+\}/g, "([^/]+)") + "$");
20
+ const m = uri.match(re);
21
+ if (!m) continue;
22
+ const names = [...tmpl.meta.uriTemplate.matchAll(/\{([^}]+)\}/g)].map((x) => x[1]);
23
+ const params = {};
24
+ names.forEach((n, i) => params[n] = decodeURIComponent(m[i + 1]));
25
+ return {
26
+ tmpl,
27
+ params
28
+ };
29
+ }
30
+ }
31
+ };
32
+ function resourceRef(uriTemplate, opts) {
33
+ return {
34
+ kind: "resource_ref",
35
+ uriTemplate,
36
+ varName: opts.varName ?? "id",
37
+ graphQLType: opts.graphQLType,
38
+ many: opts.many
39
+ };
40
+ }
41
+ function isResourceRef(x) {
42
+ const o = x;
43
+ return !!o && o.kind === "resource_ref" && typeof o.uriTemplate === "string";
44
+ }
45
+
46
+ //#endregion
47
+ export { ResourceRegistry, defineResourceTemplate, isResourceRef, resourceRef };
@@ -1 +1,2 @@
1
- import"zod";import"graphql";
1
+ import "zod";
2
+ import "graphql";
@@ -1 +1,49 @@
1
- import"zod";import{GraphQLScalarType as e}from"graphql";var t=class extends e{zodSchema;jsonSchemaDef;constructor(e){super(e),this.zodSchema=e.zod,this.jsonSchemaDef=e.jsonSchema}getZod(){return this.zodSchema}getPothos(){return this}getJson(){return typeof this.jsonSchemaDef==`function`?this.jsonSchemaDef():this.jsonSchemaDef}getJsonSchemaDef(){return this.jsonSchemaDef}getJsonSchema(){let e=t=>{let n=typeof t==`function`?t():t;if(Array.isArray(n))return n.map(t=>e(t));if(n&&typeof n==`object`){let t={};for(let[r,i]of Object.entries(n))t[r]=e(i);return t}return n};return e(this.getJson())}};export{t};
1
+ import "zod";
2
+ import { GraphQLScalarType } from "graphql";
3
+
4
+ //#region ../schema/dist/FieldType.js
5
+ /**
6
+ * GraphQL scalar wrapper that carries zod and JSON Schema metadata.
7
+ *
8
+ * TInternal is the runtime representation; TExternal is the GraphQL output.
9
+ */
10
+ var FieldType = class extends GraphQLScalarType {
11
+ zodSchema;
12
+ jsonSchemaDef;
13
+ constructor(config) {
14
+ super(config);
15
+ this.zodSchema = config.zod;
16
+ this.jsonSchemaDef = config.jsonSchema;
17
+ }
18
+ /** Return the attached zod schema for validation. */
19
+ getZod() {
20
+ return this.zodSchema;
21
+ }
22
+ /** GraphQL scalar instance usable by Pothos or vanilla GraphQL. */
23
+ getPothos() {
24
+ return this;
25
+ }
26
+ /** Return the JSON Schema (evaluates factory if provided). */
27
+ getJson() {
28
+ return typeof this.jsonSchemaDef === "function" ? this.jsonSchemaDef() : this.jsonSchemaDef;
29
+ }
30
+ getJsonSchemaDef() {
31
+ return this.jsonSchemaDef;
32
+ }
33
+ getJsonSchema() {
34
+ const deepResolve = (v) => {
35
+ const value = typeof v === "function" ? v() : v;
36
+ if (Array.isArray(value)) return value.map((item) => deepResolve(item));
37
+ if (value && typeof value === "object") {
38
+ const obj = {};
39
+ for (const [k, val] of Object.entries(value)) obj[k] = deepResolve(val);
40
+ return obj;
41
+ }
42
+ return value;
43
+ };
44
+ return deepResolve(this.getJson());
45
+ }
46
+ };
47
+
48
+ //#endregion
49
+ export { FieldType };