@appport/sdk 1.0.1

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 (387) hide show
  1. package/LICENSE +126 -0
  2. package/README.md +39 -0
  3. package/dist/index.d.ts +14 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +14 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/node.d.ts +3 -0
  8. package/dist/node.d.ts.map +1 -0
  9. package/dist/node.js +3 -0
  10. package/dist/node.js.map +1 -0
  11. package/node_modules/@appport/authorization/README.md +28 -0
  12. package/node_modules/@appport/authorization/dist/index.d.ts +94 -0
  13. package/node_modules/@appport/authorization/dist/index.d.ts.map +1 -0
  14. package/node_modules/@appport/authorization/dist/index.js +131 -0
  15. package/node_modules/@appport/authorization/dist/index.js.map +1 -0
  16. package/node_modules/@appport/authorization/package.json +28 -0
  17. package/node_modules/@appport/client/README.md +35 -0
  18. package/node_modules/@appport/client/dist/channel.d.ts +14 -0
  19. package/node_modules/@appport/client/dist/channel.d.ts.map +1 -0
  20. package/node_modules/@appport/client/dist/channel.js +58 -0
  21. package/node_modules/@appport/client/dist/channel.js.map +1 -0
  22. package/node_modules/@appport/client/dist/client.d.ts +61 -0
  23. package/node_modules/@appport/client/dist/client.d.ts.map +1 -0
  24. package/node_modules/@appport/client/dist/client.js +214 -0
  25. package/node_modules/@appport/client/dist/client.js.map +1 -0
  26. package/node_modules/@appport/client/dist/contract.d.ts +55 -0
  27. package/node_modules/@appport/client/dist/contract.d.ts.map +1 -0
  28. package/node_modules/@appport/client/dist/contract.js +12 -0
  29. package/node_modules/@appport/client/dist/contract.js.map +1 -0
  30. package/node_modules/@appport/client/dist/discovery.d.ts +17 -0
  31. package/node_modules/@appport/client/dist/discovery.d.ts.map +1 -0
  32. package/node_modules/@appport/client/dist/discovery.js +56 -0
  33. package/node_modules/@appport/client/dist/discovery.js.map +1 -0
  34. package/node_modules/@appport/client/dist/duplex.d.ts +25 -0
  35. package/node_modules/@appport/client/dist/duplex.d.ts.map +1 -0
  36. package/node_modules/@appport/client/dist/duplex.js +194 -0
  37. package/node_modules/@appport/client/dist/duplex.js.map +1 -0
  38. package/node_modules/@appport/client/dist/index.d.ts +13 -0
  39. package/node_modules/@appport/client/dist/index.d.ts.map +1 -0
  40. package/node_modules/@appport/client/dist/index.js +13 -0
  41. package/node_modules/@appport/client/dist/index.js.map +1 -0
  42. package/node_modules/@appport/client/dist/transport.d.ts +42 -0
  43. package/node_modules/@appport/client/dist/transport.d.ts.map +1 -0
  44. package/node_modules/@appport/client/dist/transport.js +2 -0
  45. package/node_modules/@appport/client/dist/transport.js.map +1 -0
  46. package/node_modules/@appport/client/package.json +32 -0
  47. package/node_modules/@appport/core/README.md +91 -0
  48. package/node_modules/@appport/core/dist/appboundry-contract.d.ts +80 -0
  49. package/node_modules/@appport/core/dist/appboundry-contract.d.ts.map +1 -0
  50. package/node_modules/@appport/core/dist/appboundry-contract.js +160 -0
  51. package/node_modules/@appport/core/dist/appboundry-contract.js.map +1 -0
  52. package/node_modules/@appport/core/dist/application-implementation.d.ts +125 -0
  53. package/node_modules/@appport/core/dist/application-implementation.d.ts.map +1 -0
  54. package/node_modules/@appport/core/dist/application-implementation.js +220 -0
  55. package/node_modules/@appport/core/dist/application-implementation.js.map +1 -0
  56. package/node_modules/@appport/core/dist/application-lifecycle.d.ts +150 -0
  57. package/node_modules/@appport/core/dist/application-lifecycle.d.ts.map +1 -0
  58. package/node_modules/@appport/core/dist/application-lifecycle.js +70 -0
  59. package/node_modules/@appport/core/dist/application-lifecycle.js.map +1 -0
  60. package/node_modules/@appport/core/dist/application-source.d.ts +109 -0
  61. package/node_modules/@appport/core/dist/application-source.d.ts.map +1 -0
  62. package/node_modules/@appport/core/dist/application-source.js +186 -0
  63. package/node_modules/@appport/core/dist/application-source.js.map +1 -0
  64. package/node_modules/@appport/core/dist/application.d.ts +122 -0
  65. package/node_modules/@appport/core/dist/application.d.ts.map +1 -0
  66. package/node_modules/@appport/core/dist/application.js +515 -0
  67. package/node_modules/@appport/core/dist/application.js.map +1 -0
  68. package/node_modules/@appport/core/dist/artifact.d.ts +395 -0
  69. package/node_modules/@appport/core/dist/artifact.d.ts.map +1 -0
  70. package/node_modules/@appport/core/dist/artifact.js +392 -0
  71. package/node_modules/@appport/core/dist/artifact.js.map +1 -0
  72. package/node_modules/@appport/core/dist/assembly.d.ts +237 -0
  73. package/node_modules/@appport/core/dist/assembly.d.ts.map +1 -0
  74. package/node_modules/@appport/core/dist/assembly.js +458 -0
  75. package/node_modules/@appport/core/dist/assembly.js.map +1 -0
  76. package/node_modules/@appport/core/dist/authority-attestation.d.ts +34 -0
  77. package/node_modules/@appport/core/dist/authority-attestation.d.ts.map +1 -0
  78. package/node_modules/@appport/core/dist/authority-attestation.js +72 -0
  79. package/node_modules/@appport/core/dist/authority-attestation.js.map +1 -0
  80. package/node_modules/@appport/core/dist/authorization-grant.d.ts +107 -0
  81. package/node_modules/@appport/core/dist/authorization-grant.d.ts.map +1 -0
  82. package/node_modules/@appport/core/dist/authorization-grant.js +131 -0
  83. package/node_modules/@appport/core/dist/authorization-grant.js.map +1 -0
  84. package/node_modules/@appport/core/dist/binding.d.ts +294 -0
  85. package/node_modules/@appport/core/dist/binding.d.ts.map +1 -0
  86. package/node_modules/@appport/core/dist/binding.js +263 -0
  87. package/node_modules/@appport/core/dist/binding.js.map +1 -0
  88. package/node_modules/@appport/core/dist/builtins.d.ts +18 -0
  89. package/node_modules/@appport/core/dist/builtins.d.ts.map +1 -0
  90. package/node_modules/@appport/core/dist/builtins.js +38 -0
  91. package/node_modules/@appport/core/dist/builtins.js.map +1 -0
  92. package/node_modules/@appport/core/dist/capability.d.ts +94 -0
  93. package/node_modules/@appport/core/dist/capability.d.ts.map +1 -0
  94. package/node_modules/@appport/core/dist/capability.js +85 -0
  95. package/node_modules/@appport/core/dist/capability.js.map +1 -0
  96. package/node_modules/@appport/core/dist/concurrency.d.ts +16 -0
  97. package/node_modules/@appport/core/dist/concurrency.d.ts.map +1 -0
  98. package/node_modules/@appport/core/dist/concurrency.js +46 -0
  99. package/node_modules/@appport/core/dist/concurrency.js.map +1 -0
  100. package/node_modules/@appport/core/dist/context.d.ts +59 -0
  101. package/node_modules/@appport/core/dist/context.d.ts.map +1 -0
  102. package/node_modules/@appport/core/dist/context.js +14 -0
  103. package/node_modules/@appport/core/dist/context.js.map +1 -0
  104. package/node_modules/@appport/core/dist/contract-artifact.d.ts +15 -0
  105. package/node_modules/@appport/core/dist/contract-artifact.d.ts.map +1 -0
  106. package/node_modules/@appport/core/dist/contract-artifact.js +152 -0
  107. package/node_modules/@appport/core/dist/contract-artifact.js.map +1 -0
  108. package/node_modules/@appport/core/dist/contract-attestation.d.ts +68 -0
  109. package/node_modules/@appport/core/dist/contract-attestation.d.ts.map +1 -0
  110. package/node_modules/@appport/core/dist/contract-attestation.js +76 -0
  111. package/node_modules/@appport/core/dist/contract-attestation.js.map +1 -0
  112. package/node_modules/@appport/core/dist/crash-injection.d.ts +3 -0
  113. package/node_modules/@appport/core/dist/crash-injection.d.ts.map +1 -0
  114. package/node_modules/@appport/core/dist/crash-injection.js +8 -0
  115. package/node_modules/@appport/core/dist/crash-injection.js.map +1 -0
  116. package/node_modules/@appport/core/dist/events.d.ts +33 -0
  117. package/node_modules/@appport/core/dist/events.d.ts.map +1 -0
  118. package/node_modules/@appport/core/dist/events.js +79 -0
  119. package/node_modules/@appport/core/dist/events.js.map +1 -0
  120. package/node_modules/@appport/core/dist/execution-barrier.d.ts +13 -0
  121. package/node_modules/@appport/core/dist/execution-barrier.d.ts.map +1 -0
  122. package/node_modules/@appport/core/dist/execution-barrier.js +33 -0
  123. package/node_modules/@appport/core/dist/execution-barrier.js.map +1 -0
  124. package/node_modules/@appport/core/dist/execution-ledger.d.ts +81 -0
  125. package/node_modules/@appport/core/dist/execution-ledger.d.ts.map +1 -0
  126. package/node_modules/@appport/core/dist/execution-ledger.js +173 -0
  127. package/node_modules/@appport/core/dist/execution-ledger.js.map +1 -0
  128. package/node_modules/@appport/core/dist/execution.d.ts +387 -0
  129. package/node_modules/@appport/core/dist/execution.d.ts.map +1 -0
  130. package/node_modules/@appport/core/dist/execution.js +165 -0
  131. package/node_modules/@appport/core/dist/execution.js.map +1 -0
  132. package/node_modules/@appport/core/dist/idempotency.d.ts +36 -0
  133. package/node_modules/@appport/core/dist/idempotency.d.ts.map +1 -0
  134. package/node_modules/@appport/core/dist/idempotency.js +36 -0
  135. package/node_modules/@appport/core/dist/idempotency.js.map +1 -0
  136. package/node_modules/@appport/core/dist/implementation.d.ts +110 -0
  137. package/node_modules/@appport/core/dist/implementation.d.ts.map +1 -0
  138. package/node_modules/@appport/core/dist/implementation.js +65 -0
  139. package/node_modules/@appport/core/dist/implementation.js.map +1 -0
  140. package/node_modules/@appport/core/dist/index.d.ts +44 -0
  141. package/node_modules/@appport/core/dist/index.d.ts.map +1 -0
  142. package/node_modules/@appport/core/dist/index.js +44 -0
  143. package/node_modules/@appport/core/dist/index.js.map +1 -0
  144. package/node_modules/@appport/core/dist/invocation.d.ts +253 -0
  145. package/node_modules/@appport/core/dist/invocation.d.ts.map +1 -0
  146. package/node_modules/@appport/core/dist/invocation.js +258 -0
  147. package/node_modules/@appport/core/dist/invocation.js.map +1 -0
  148. package/node_modules/@appport/core/dist/manifest.d.ts +157 -0
  149. package/node_modules/@appport/core/dist/manifest.d.ts.map +1 -0
  150. package/node_modules/@appport/core/dist/manifest.js +255 -0
  151. package/node_modules/@appport/core/dist/manifest.js.map +1 -0
  152. package/node_modules/@appport/core/dist/memory-application-data-store.d.ts +19 -0
  153. package/node_modules/@appport/core/dist/memory-application-data-store.d.ts.map +1 -0
  154. package/node_modules/@appport/core/dist/memory-application-data-store.js +161 -0
  155. package/node_modules/@appport/core/dist/memory-application-data-store.js.map +1 -0
  156. package/node_modules/@appport/core/dist/operations.d.ts +61 -0
  157. package/node_modules/@appport/core/dist/operations.d.ts.map +1 -0
  158. package/node_modules/@appport/core/dist/operations.js +210 -0
  159. package/node_modules/@appport/core/dist/operations.js.map +1 -0
  160. package/node_modules/@appport/core/dist/public.d.ts +19 -0
  161. package/node_modules/@appport/core/dist/public.d.ts.map +1 -0
  162. package/node_modules/@appport/core/dist/public.js +18 -0
  163. package/node_modules/@appport/core/dist/public.js.map +1 -0
  164. package/node_modules/@appport/core/dist/registration.d.ts +165 -0
  165. package/node_modules/@appport/core/dist/registration.d.ts.map +1 -0
  166. package/node_modules/@appport/core/dist/registration.js +253 -0
  167. package/node_modules/@appport/core/dist/registration.js.map +1 -0
  168. package/node_modules/@appport/core/dist/registry.d.ts +29 -0
  169. package/node_modules/@appport/core/dist/registry.d.ts.map +1 -0
  170. package/node_modules/@appport/core/dist/registry.js +148 -0
  171. package/node_modules/@appport/core/dist/registry.js.map +1 -0
  172. package/node_modules/@appport/core/dist/repository-connection.d.ts +100 -0
  173. package/node_modules/@appport/core/dist/repository-connection.d.ts.map +1 -0
  174. package/node_modules/@appport/core/dist/repository-connection.js +57 -0
  175. package/node_modules/@appport/core/dist/repository-connection.js.map +1 -0
  176. package/node_modules/@appport/core/dist/resolver.d.ts +130 -0
  177. package/node_modules/@appport/core/dist/resolver.d.ts.map +1 -0
  178. package/node_modules/@appport/core/dist/resolver.js +252 -0
  179. package/node_modules/@appport/core/dist/resolver.js.map +1 -0
  180. package/node_modules/@appport/core/dist/runtime-manifest.d.ts +68 -0
  181. package/node_modules/@appport/core/dist/runtime-manifest.d.ts.map +1 -0
  182. package/node_modules/@appport/core/dist/runtime-manifest.js +84 -0
  183. package/node_modules/@appport/core/dist/runtime-manifest.js.map +1 -0
  184. package/node_modules/@appport/core/dist/sanitize.d.ts +14 -0
  185. package/node_modules/@appport/core/dist/sanitize.d.ts.map +1 -0
  186. package/node_modules/@appport/core/dist/sanitize.js +49 -0
  187. package/node_modules/@appport/core/dist/sanitize.js.map +1 -0
  188. package/node_modules/@appport/core/dist/server-internal.d.ts +5 -0
  189. package/node_modules/@appport/core/dist/server-internal.d.ts.map +1 -0
  190. package/node_modules/@appport/core/dist/server-internal.js +4 -0
  191. package/node_modules/@appport/core/dist/server-internal.js.map +1 -0
  192. package/node_modules/@appport/core/dist/sessions.d.ts +29 -0
  193. package/node_modules/@appport/core/dist/sessions.d.ts.map +1 -0
  194. package/node_modules/@appport/core/dist/sessions.js +39 -0
  195. package/node_modules/@appport/core/dist/sessions.js.map +1 -0
  196. package/node_modules/@appport/core/dist/sha256.d.ts +3 -0
  197. package/node_modules/@appport/core/dist/sha256.d.ts.map +1 -0
  198. package/node_modules/@appport/core/dist/sha256.js +46 -0
  199. package/node_modules/@appport/core/dist/sha256.js.map +1 -0
  200. package/node_modules/@appport/core/dist/source-verification.d.ts +53 -0
  201. package/node_modules/@appport/core/dist/source-verification.d.ts.map +1 -0
  202. package/node_modules/@appport/core/dist/source-verification.js +92 -0
  203. package/node_modules/@appport/core/dist/source-verification.js.map +1 -0
  204. package/node_modules/@appport/core/dist/state-context.d.ts +312 -0
  205. package/node_modules/@appport/core/dist/state-context.d.ts.map +1 -0
  206. package/node_modules/@appport/core/dist/state-context.js +100 -0
  207. package/node_modules/@appport/core/dist/state-context.js.map +1 -0
  208. package/node_modules/@appport/core/dist/state.d.ts +96 -0
  209. package/node_modules/@appport/core/dist/state.d.ts.map +1 -0
  210. package/node_modules/@appport/core/dist/state.js +89 -0
  211. package/node_modules/@appport/core/dist/state.js.map +1 -0
  212. package/node_modules/@appport/core/dist/streams.d.ts +38 -0
  213. package/node_modules/@appport/core/dist/streams.d.ts.map +1 -0
  214. package/node_modules/@appport/core/dist/streams.js +123 -0
  215. package/node_modules/@appport/core/dist/streams.js.map +1 -0
  216. package/node_modules/@appport/core/dist/telemetry.d.ts +42 -0
  217. package/node_modules/@appport/core/dist/telemetry.d.ts.map +1 -0
  218. package/node_modules/@appport/core/dist/telemetry.js +32 -0
  219. package/node_modules/@appport/core/dist/telemetry.js.map +1 -0
  220. package/node_modules/@appport/core/dist/wasm-engine.d.ts +22 -0
  221. package/node_modules/@appport/core/dist/wasm-engine.d.ts.map +1 -0
  222. package/node_modules/@appport/core/dist/wasm-engine.js +367 -0
  223. package/node_modules/@appport/core/dist/wasm-engine.js.map +1 -0
  224. package/node_modules/@appport/core/package.json +58 -0
  225. package/node_modules/@appport/mobile/README.md +10 -0
  226. package/node_modules/@appport/mobile/dist/index.d.ts +66 -0
  227. package/node_modules/@appport/mobile/dist/index.d.ts.map +1 -0
  228. package/node_modules/@appport/mobile/dist/index.js +182 -0
  229. package/node_modules/@appport/mobile/dist/index.js.map +1 -0
  230. package/node_modules/@appport/mobile/package.json +33 -0
  231. package/node_modules/@appport/protocol/README.md +41 -0
  232. package/node_modules/@appport/protocol/dist/blob.d.ts +46 -0
  233. package/node_modules/@appport/protocol/dist/blob.d.ts.map +1 -0
  234. package/node_modules/@appport/protocol/dist/blob.js +23 -0
  235. package/node_modules/@appport/protocol/dist/blob.js.map +1 -0
  236. package/node_modules/@appport/protocol/dist/compatibility.d.ts +25 -0
  237. package/node_modules/@appport/protocol/dist/compatibility.d.ts.map +1 -0
  238. package/node_modules/@appport/protocol/dist/compatibility.js +189 -0
  239. package/node_modules/@appport/protocol/dist/compatibility.js.map +1 -0
  240. package/node_modules/@appport/protocol/dist/envelopes.d.ts +175 -0
  241. package/node_modules/@appport/protocol/dist/envelopes.d.ts.map +1 -0
  242. package/node_modules/@appport/protocol/dist/envelopes.js +97 -0
  243. package/node_modules/@appport/protocol/dist/envelopes.js.map +1 -0
  244. package/node_modules/@appport/protocol/dist/errors.d.ts +74 -0
  245. package/node_modules/@appport/protocol/dist/errors.d.ts.map +1 -0
  246. package/node_modules/@appport/protocol/dist/errors.js +91 -0
  247. package/node_modules/@appport/protocol/dist/errors.js.map +1 -0
  248. package/node_modules/@appport/protocol/dist/ids.d.ts +12 -0
  249. package/node_modules/@appport/protocol/dist/ids.d.ts.map +1 -0
  250. package/node_modules/@appport/protocol/dist/ids.js +50 -0
  251. package/node_modules/@appport/protocol/dist/ids.js.map +1 -0
  252. package/node_modules/@appport/protocol/dist/index.d.ts +20 -0
  253. package/node_modules/@appport/protocol/dist/index.d.ts.map +1 -0
  254. package/node_modules/@appport/protocol/dist/index.js +20 -0
  255. package/node_modules/@appport/protocol/dist/index.js.map +1 -0
  256. package/node_modules/@appport/protocol/dist/jsonschema.d.ts +50 -0
  257. package/node_modules/@appport/protocol/dist/jsonschema.d.ts.map +1 -0
  258. package/node_modules/@appport/protocol/dist/jsonschema.js +6 -0
  259. package/node_modules/@appport/protocol/dist/jsonschema.js.map +1 -0
  260. package/node_modules/@appport/protocol/dist/manifest.d.ts +131 -0
  261. package/node_modules/@appport/protocol/dist/manifest.d.ts.map +1 -0
  262. package/node_modules/@appport/protocol/dist/manifest.js +20 -0
  263. package/node_modules/@appport/protocol/dist/manifest.js.map +1 -0
  264. package/node_modules/@appport/protocol/dist/names.d.ts +26 -0
  265. package/node_modules/@appport/protocol/dist/names.d.ts.map +1 -0
  266. package/node_modules/@appport/protocol/dist/names.js +85 -0
  267. package/node_modules/@appport/protocol/dist/names.js.map +1 -0
  268. package/node_modules/@appport/protocol/dist/operations.d.ts +34 -0
  269. package/node_modules/@appport/protocol/dist/operations.d.ts.map +1 -0
  270. package/node_modules/@appport/protocol/dist/operations.js +9 -0
  271. package/node_modules/@appport/protocol/dist/operations.js.map +1 -0
  272. package/node_modules/@appport/protocol/dist/session.d.ts +27 -0
  273. package/node_modules/@appport/protocol/dist/session.d.ts.map +1 -0
  274. package/node_modules/@appport/protocol/dist/session.js +7 -0
  275. package/node_modules/@appport/protocol/dist/session.js.map +1 -0
  276. package/node_modules/@appport/protocol/dist/validate.d.ts +37 -0
  277. package/node_modules/@appport/protocol/dist/validate.d.ts.map +1 -0
  278. package/node_modules/@appport/protocol/dist/validate.js +321 -0
  279. package/node_modules/@appport/protocol/dist/validate.js.map +1 -0
  280. package/node_modules/@appport/protocol/dist/version.d.ts +27 -0
  281. package/node_modules/@appport/protocol/dist/version.d.ts.map +1 -0
  282. package/node_modules/@appport/protocol/dist/version.js +26 -0
  283. package/node_modules/@appport/protocol/dist/version.js.map +1 -0
  284. package/node_modules/@appport/protocol/package.json +25 -0
  285. package/node_modules/@appport/schema/README.md +32 -0
  286. package/node_modules/@appport/schema/dist/builder.d.ts +85 -0
  287. package/node_modules/@appport/schema/dist/builder.d.ts.map +1 -0
  288. package/node_modules/@appport/schema/dist/builder.js +278 -0
  289. package/node_modules/@appport/schema/dist/builder.js.map +1 -0
  290. package/node_modules/@appport/schema/dist/from-json-schema.d.ts +12 -0
  291. package/node_modules/@appport/schema/dist/from-json-schema.d.ts.map +1 -0
  292. package/node_modules/@appport/schema/dist/from-json-schema.js +186 -0
  293. package/node_modules/@appport/schema/dist/from-json-schema.js.map +1 -0
  294. package/node_modules/@appport/schema/dist/index.d.ts +23 -0
  295. package/node_modules/@appport/schema/dist/index.d.ts.map +1 -0
  296. package/node_modules/@appport/schema/dist/index.js +22 -0
  297. package/node_modules/@appport/schema/dist/index.js.map +1 -0
  298. package/node_modules/@appport/schema/dist/standard.d.ts +46 -0
  299. package/node_modules/@appport/schema/dist/standard.d.ts.map +1 -0
  300. package/node_modules/@appport/schema/dist/standard.js +42 -0
  301. package/node_modules/@appport/schema/dist/standard.js.map +1 -0
  302. package/node_modules/@appport/schema/dist/types.d.ts +40 -0
  303. package/node_modules/@appport/schema/dist/types.d.ts.map +1 -0
  304. package/node_modules/@appport/schema/dist/types.js +19 -0
  305. package/node_modules/@appport/schema/dist/types.js.map +1 -0
  306. package/node_modules/@appport/schema/package.json +28 -0
  307. package/node_modules/@appport/server/README.md +39 -0
  308. package/node_modules/@appport/server/dist/connection.d.ts +45 -0
  309. package/node_modules/@appport/server/dist/connection.d.ts.map +1 -0
  310. package/node_modules/@appport/server/dist/connection.js +217 -0
  311. package/node_modules/@appport/server/dist/connection.js.map +1 -0
  312. package/node_modules/@appport/server/dist/fetch.d.ts +10 -0
  313. package/node_modules/@appport/server/dist/fetch.d.ts.map +1 -0
  314. package/node_modules/@appport/server/dist/fetch.js +50 -0
  315. package/node_modules/@appport/server/dist/fetch.js.map +1 -0
  316. package/node_modules/@appport/server/dist/http.d.ts +80 -0
  317. package/node_modules/@appport/server/dist/http.d.ts.map +1 -0
  318. package/node_modules/@appport/server/dist/http.js +306 -0
  319. package/node_modules/@appport/server/dist/http.js.map +1 -0
  320. package/node_modules/@appport/server/dist/index.d.ts +11 -0
  321. package/node_modules/@appport/server/dist/index.d.ts.map +1 -0
  322. package/node_modules/@appport/server/dist/index.js +11 -0
  323. package/node_modules/@appport/server/dist/index.js.map +1 -0
  324. package/node_modules/@appport/server/dist/node-entry.d.ts +4 -0
  325. package/node_modules/@appport/server/dist/node-entry.d.ts.map +1 -0
  326. package/node_modules/@appport/server/dist/node-entry.js +4 -0
  327. package/node_modules/@appport/server/dist/node-entry.js.map +1 -0
  328. package/node_modules/@appport/server/dist/node.d.ts +45 -0
  329. package/node_modules/@appport/server/dist/node.d.ts.map +1 -0
  330. package/node_modules/@appport/server/dist/node.js +190 -0
  331. package/node_modules/@appport/server/dist/node.js.map +1 -0
  332. package/node_modules/@appport/server/dist/server.d.ts +83 -0
  333. package/node_modules/@appport/server/dist/server.d.ts.map +1 -0
  334. package/node_modules/@appport/server/dist/server.js +114 -0
  335. package/node_modules/@appport/server/dist/server.js.map +1 -0
  336. package/node_modules/@appport/server/dist/websocket.d.ts +25 -0
  337. package/node_modules/@appport/server/dist/websocket.d.ts.map +1 -0
  338. package/node_modules/@appport/server/dist/websocket.js +221 -0
  339. package/node_modules/@appport/server/dist/websocket.js.map +1 -0
  340. package/node_modules/@appport/server/package.json +34 -0
  341. package/node_modules/@appport/transport-electron/README.md +56 -0
  342. package/node_modules/@appport/transport-electron/dist/index.d.ts +11 -0
  343. package/node_modules/@appport/transport-electron/dist/index.d.ts.map +1 -0
  344. package/node_modules/@appport/transport-electron/dist/index.js +11 -0
  345. package/node_modules/@appport/transport-electron/dist/index.js.map +1 -0
  346. package/node_modules/@appport/transport-electron/dist/main.d.ts +31 -0
  347. package/node_modules/@appport/transport-electron/dist/main.d.ts.map +1 -0
  348. package/node_modules/@appport/transport-electron/dist/main.js +61 -0
  349. package/node_modules/@appport/transport-electron/dist/main.js.map +1 -0
  350. package/node_modules/@appport/transport-electron/dist/preload.d.ts +22 -0
  351. package/node_modules/@appport/transport-electron/dist/preload.d.ts.map +1 -0
  352. package/node_modules/@appport/transport-electron/dist/preload.js +29 -0
  353. package/node_modules/@appport/transport-electron/dist/preload.js.map +1 -0
  354. package/node_modules/@appport/transport-electron/dist/renderer.d.ts +16 -0
  355. package/node_modules/@appport/transport-electron/dist/renderer.d.ts.map +1 -0
  356. package/node_modules/@appport/transport-electron/dist/renderer.js +36 -0
  357. package/node_modules/@appport/transport-electron/dist/renderer.js.map +1 -0
  358. package/node_modules/@appport/transport-electron/dist/types.d.ts +49 -0
  359. package/node_modules/@appport/transport-electron/dist/types.d.ts.map +1 -0
  360. package/node_modules/@appport/transport-electron/dist/types.js +5 -0
  361. package/node_modules/@appport/transport-electron/dist/types.js.map +1 -0
  362. package/node_modules/@appport/transport-electron/package.json +46 -0
  363. package/node_modules/@appport/transport-http/README.md +24 -0
  364. package/node_modules/@appport/transport-http/dist/index.d.ts +18 -0
  365. package/node_modules/@appport/transport-http/dist/index.d.ts.map +1 -0
  366. package/node_modules/@appport/transport-http/dist/index.js +223 -0
  367. package/node_modules/@appport/transport-http/dist/index.js.map +1 -0
  368. package/node_modules/@appport/transport-http/package.json +29 -0
  369. package/node_modules/@appport/transport-inprocess/README.md +24 -0
  370. package/node_modules/@appport/transport-inprocess/dist/index.d.ts +16 -0
  371. package/node_modules/@appport/transport-inprocess/dist/index.d.ts.map +1 -0
  372. package/node_modules/@appport/transport-inprocess/dist/index.js +30 -0
  373. package/node_modules/@appport/transport-inprocess/dist/index.js.map +1 -0
  374. package/node_modules/@appport/transport-inprocess/package.json +30 -0
  375. package/node_modules/@appport/transport-tauri/README.md +45 -0
  376. package/node_modules/@appport/transport-tauri/dist/index.d.ts +23 -0
  377. package/node_modules/@appport/transport-tauri/dist/index.d.ts.map +1 -0
  378. package/node_modules/@appport/transport-tauri/dist/index.js +44 -0
  379. package/node_modules/@appport/transport-tauri/dist/index.js.map +1 -0
  380. package/node_modules/@appport/transport-tauri/package.json +29 -0
  381. package/node_modules/@appport/transport-websocket/README.md +22 -0
  382. package/node_modules/@appport/transport-websocket/dist/index.d.ts +26 -0
  383. package/node_modules/@appport/transport-websocket/dist/index.d.ts.map +1 -0
  384. package/node_modules/@appport/transport-websocket/dist/index.js +72 -0
  385. package/node_modules/@appport/transport-websocket/dist/index.js.map +1 -0
  386. package/node_modules/@appport/transport-websocket/package.json +29 -0
  387. package/package.json +79 -0
@@ -0,0 +1,42 @@
1
+ export function isStandardSchema(value) {
2
+ return typeof value === "object" && value !== null && "~standard" in value;
3
+ }
4
+ function toIssuePath(path, base) {
5
+ if (!path)
6
+ return base;
7
+ return [
8
+ ...base,
9
+ ...path.map((segment) => {
10
+ const key = typeof segment === "object" && segment !== null ? segment.key : segment;
11
+ return typeof key === "number" ? key : String(key);
12
+ })
13
+ ];
14
+ }
15
+ /**
16
+ * Adapts a Standard Schema (Zod, Valibot, …) to the AppPort schema contract.
17
+ *
18
+ * Validation must be synchronous: AppPort validates inside the dispatch
19
+ * pipeline, and an async validator would change request ordering semantics.
20
+ */
21
+ export function fromStandardSchema(schema, options = {}) {
22
+ const jsonSchema = options.jsonSchema ?? { "x-appport-schema": "opaque", description: "Schema not published" };
23
+ return {
24
+ appport: "schema",
25
+ validate(value, path = []) {
26
+ const result = schema["~standard"].validate(value);
27
+ if (result instanceof Promise) {
28
+ throw new TypeError("AppPort requires synchronous schema validation; this Standard Schema returned a Promise");
29
+ }
30
+ if (result.issues && result.issues.length > 0) {
31
+ const issues = result.issues.map((entry) => ({
32
+ path: toIssuePath(entry.path, path),
33
+ message: entry.message
34
+ }));
35
+ return { ok: false, issues };
36
+ }
37
+ return { ok: true, value: result.value };
38
+ },
39
+ toJSONSchema: () => jsonSchema
40
+ };
41
+ }
42
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MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9C,MAAM,MAAM,GAAsB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAC9D,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;oBACnC,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB,CAAC,CAAC,CAAC;gBACJ,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YAC/B,CAAC;YACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAe,EAAE,CAAC;QACrD,CAAC;QACD,YAAY,EAAE,GAAG,EAAE,CAAC,UAAU;KAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { JSONSchema } from "@appport/protocol";
2
+ /** Path to the offending value inside a validated payload. */
3
+ export type IssuePath = Array<string | number>;
4
+ export interface ValidationIssue {
5
+ path: IssuePath;
6
+ message: string;
7
+ /** Optional machine-readable reason, e.g. `type`, `required`, `pattern`. */
8
+ code?: string;
9
+ }
10
+ export type ValidationResult<T> = {
11
+ ok: true;
12
+ value: T;
13
+ } | {
14
+ ok: false;
15
+ issues: ValidationIssue[];
16
+ };
17
+ /**
18
+ * The schema contract used by the AppPort runtime.
19
+ *
20
+ * A schema does two things: it validates an unknown value at runtime, and it
21
+ * renders itself as JSON Schema so the manifest stays language-neutral (§32).
22
+ */
23
+ export interface Schema<T = unknown> {
24
+ readonly appport: "schema";
25
+ /** True when the schema is used as an optional object property. */
26
+ readonly isOptional?: boolean;
27
+ validate(value: unknown, path?: IssuePath): ValidationResult<T>;
28
+ toJSONSchema(): JSONSchema;
29
+ }
30
+ export type Infer<S> = S extends Schema<infer T> ? T : never;
31
+ export declare function isSchema(value: unknown): value is Schema;
32
+ /** Renders issues into a compact, non-sensitive detail payload for errors. */
33
+ export declare function issuesToDetails(issues: ValidationIssue[]): {
34
+ issues: Array<{
35
+ path: string;
36
+ message: string;
37
+ }>;
38
+ };
39
+ export declare function formatIssues(issues: ValidationIssue[]): string;
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,8DAA8D;AAC9D,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC;AAEpG;;;;;GAKG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IACjC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAChE,YAAY,IAAI,UAAU,CAAC;CAC5B;AAED,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE7D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG;IAAE,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAO/G;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAK9D"}
@@ -0,0 +1,19 @@
1
+ export function isSchema(value) {
2
+ return typeof value === "object" && value !== null && value.appport === "schema";
3
+ }
4
+ /** Renders issues into a compact, non-sensitive detail payload for errors. */
5
+ export function issuesToDetails(issues) {
6
+ return {
7
+ issues: issues.slice(0, 25).map((issue) => ({
8
+ path: issue.path.length === 0 ? "" : issue.path.map(String).join("."),
9
+ message: issue.message
10
+ }))
11
+ };
12
+ }
13
+ export function formatIssues(issues) {
14
+ return issues
15
+ .slice(0, 5)
16
+ .map((issue) => (issue.path.length ? `${issue.path.map(String).join(".")}: ${issue.message}` : issue.message))
17
+ .join("; ");
18
+ }
19
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA8BA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAAgB,CAAC,OAAO,KAAK,QAAQ,CAAC;AAC/F,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,eAAe,CAAC,MAAyB;IACvD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC1C,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YACrE,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAyB;IACpD,OAAO,MAAM;SACV,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SACX,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SAC7G,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@appport/schema",
3
+ "version": "1.0.0",
4
+ "description": "Schema adapters and JSON Schema generation for AppPort capabilities.",
5
+ "license": "Apache-2.0",
6
+ "repository": "github:rkendel1/appport",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -b",
22
+ "clean": "tsc -b --clean"
23
+ },
24
+ "dependencies": {
25
+ "@appport/protocol": "1.0.0"
26
+ },
27
+ "private": true
28
+ }
@@ -0,0 +1,39 @@
1
+ # @appport/server
2
+
3
+ The server-side protocol runtime and its web bindings.
4
+
5
+ ```ts
6
+ import { createServer } from "@appport/server";
7
+ import { serve } from "@appport/server/node";
8
+
9
+ const server = createServer({
10
+ application,
11
+ authenticate: ({ sessionId }) => sessions.resolve(sessionId)
12
+ });
13
+
14
+ const running = await serve({ server, port: 4400, cors: { origins: "*" } });
15
+ ```
16
+
17
+ `serve` exposes, against one capability server:
18
+
19
+ | Route | Purpose |
20
+ | ------------------------ | --------------------------------------- |
21
+ | `POST /appport` | requests, and streams as NDJSON |
22
+ | `GET /appport/events` | events as Server-Sent Events |
23
+ | `GET /appport/manifest` | the manifest |
24
+ | `GET /.well-known/appport` | discovery |
25
+ | `WS /appport/ws` | the WebSocket binding |
26
+
27
+ The WebSocket endpoint is a dependency-free RFC 6455 implementation: framing,
28
+ fragmentation, ping/pong and close, with one AppPort envelope per message.
29
+
30
+ `AppPortConnection` is the duplex half used by WebSocket, IPC and in-process
31
+ transports. It owns subscription and stream bookkeeping, so unsubscribe releases
32
+ resources and cancellation reaches the handler.
33
+
34
+ For edge runtimes, `createFetchHandler(binding)` returns a standard
35
+ `(Request) => Promise<Response>`.
36
+
37
+ `authenticate` resolves an identity from transport-supplied credentials. AppPort
38
+ does not authenticate; it represents the resulting identity, and authorizes every
39
+ capability regardless of which transport delivered it.
@@ -0,0 +1,45 @@
1
+ import { type ClientEnvelope, type ServerEnvelope, type Principal, type Session } from "@appport/protocol";
2
+ import { type AppPortApplication } from "@appport/core/server-internal";
3
+ export type SendEnvelope = (envelope: ServerEnvelope) => void | Promise<void>;
4
+ export interface ConnectionOptions {
5
+ application: AppPortApplication;
6
+ /** Transport kind, recorded for telemetry. Never a source of trust (§37). */
7
+ transport: string;
8
+ send: SendEnvelope;
9
+ session?: Session;
10
+ principal?: Principal;
11
+ maxEnvelopeBytes?: number;
12
+ /** Capability/event names this transport surface may reach. */
13
+ allowedCapabilities?: ReadonlySet<string>;
14
+ }
15
+ /**
16
+ * One duplex client connection.
17
+ *
18
+ * Connections exist for transports that can push (WebSocket, IPC, in-process).
19
+ * They own the subscription and stream bookkeeping the protocol requires:
20
+ * unsubscribe releases resources (§18), cancellation terminates the underlying
21
+ * operation (§21).
22
+ */
23
+ export declare class AppPortConnection {
24
+ #private;
25
+ readonly transport: string;
26
+ constructor(options: ConnectionOptions);
27
+ get session(): Session | undefined;
28
+ get closed(): boolean;
29
+ get openStreamCount(): number;
30
+ get subscriptionCount(): number;
31
+ /** Binds an authenticated identity to this connection. */
32
+ authenticate(identity: {
33
+ session?: Session;
34
+ principal?: Principal;
35
+ }): void;
36
+ /** Accepts a raw text frame. */
37
+ accept(raw: string): Promise<void>;
38
+ /** Accepts an already-decoded envelope value (IPC and in-process transports). */
39
+ acceptValue(value: unknown): Promise<void>;
40
+ /** Routes a validated client envelope. */
41
+ handle(envelope: ClientEnvelope): Promise<void>;
42
+ /** Releases every subscription and stream held by this connection. */
43
+ close(): void;
44
+ }
45
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAaL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAe,KAAK,kBAAkB,EAAwB,MAAM,+BAA+B,CAAC;AAE3G,MAAM,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9E,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,kBAAkB,CAAC;IAChC,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,mBAAmB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC3C;AAOD;;;;;;;GAOG;AACH,qBAAa,iBAAiB;;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAWf,OAAO,EAAE,iBAAiB;IAUtC,IAAI,OAAO,IAAI,OAAO,GAAG,SAAS,CAEjC;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED,0DAA0D;IAC1D,YAAY,CAAC,QAAQ,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,IAAI;IAK1E,gCAAgC;IAC1B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxC,iFAAiF;IAC3E,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAahD,0CAA0C;IACpC,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA2CrD,sEAAsE;IACtE,KAAK,IAAI,IAAI;CAgHd"}
@@ -0,0 +1,217 @@
1
+ import { AppPortError, createErrorResponse, createStreamChunk, createStreamEnd, createStreamStart, createSuccessResponse, decodeEnvelopeText, errors, parseClientEnvelope, peekRequestId, peekTraceId } from "@appport/protocol";
2
+ import { grantsPermission } from "@appport/authorization";
3
+ import { toWireError } from "@appport/core/server-internal";
4
+ /**
5
+ * One duplex client connection.
6
+ *
7
+ * Connections exist for transports that can push (WebSocket, IPC, in-process).
8
+ * They own the subscription and stream bookkeeping the protocol requires:
9
+ * unsubscribe releases resources (§18), cancellation terminates the underlying
10
+ * operation (§21).
11
+ */
12
+ export class AppPortConnection {
13
+ transport;
14
+ #application;
15
+ #send;
16
+ #subscriptions = new Map();
17
+ #streams = new Map();
18
+ #maxEnvelopeBytes;
19
+ #allowedCapabilities;
20
+ #session;
21
+ #principal;
22
+ #closed = false;
23
+ constructor(options) {
24
+ this.#application = options.application;
25
+ this.transport = options.transport;
26
+ this.#send = options.send;
27
+ this.#session = options.session;
28
+ this.#principal = options.principal;
29
+ this.#maxEnvelopeBytes = options.maxEnvelopeBytes;
30
+ this.#allowedCapabilities = options.allowedCapabilities;
31
+ }
32
+ get session() {
33
+ return this.#session;
34
+ }
35
+ get closed() {
36
+ return this.#closed;
37
+ }
38
+ get openStreamCount() {
39
+ return this.#streams.size;
40
+ }
41
+ get subscriptionCount() {
42
+ return this.#subscriptions.size;
43
+ }
44
+ /** Binds an authenticated identity to this connection. */
45
+ authenticate(identity) {
46
+ this.#session = identity.session;
47
+ this.#principal = identity.principal ?? identity.session?.principal;
48
+ }
49
+ /** Accepts a raw text frame. */
50
+ async accept(raw) {
51
+ let value;
52
+ try {
53
+ value = decodeEnvelopeText(raw, this.#maxEnvelopeBytes ? { maxBytes: this.#maxEnvelopeBytes } : {});
54
+ }
55
+ catch (error) {
56
+ await this.#fail(undefined, undefined, error);
57
+ return;
58
+ }
59
+ await this.acceptValue(value);
60
+ }
61
+ /** Accepts an already-decoded envelope value (IPC and in-process transports). */
62
+ async acceptValue(value) {
63
+ const requestId = peekRequestId(value);
64
+ const traceId = peekTraceId(value);
65
+ let envelope;
66
+ try {
67
+ envelope = parseClientEnvelope(value);
68
+ }
69
+ catch (error) {
70
+ await this.#fail(requestId, traceId, error);
71
+ return;
72
+ }
73
+ await this.handle(envelope);
74
+ }
75
+ /** Routes a validated client envelope. */
76
+ async handle(envelope) {
77
+ if (this.#closed)
78
+ return;
79
+ const target = envelope.type === "request" || envelope.type === "stream.request"
80
+ ? envelope.capability.name
81
+ : envelope.type === "subscribe"
82
+ ? envelope.event.name
83
+ : undefined;
84
+ if (target && this.#allowedCapabilities && target !== "appport.manifest" && target !== "appport.ping" && !this.#allowedCapabilities.has(target)) {
85
+ await this.#emit(createErrorResponse(peekRequestId(envelope) ?? "req_unknown", errors.forbidden(`${target} is not exposed to this surface`).toErrorObject()));
86
+ return;
87
+ }
88
+ switch (envelope.type) {
89
+ case "request": {
90
+ const response = await this.#application.handleRequest(envelope, this.#dispatchOptions());
91
+ await this.#emit(response);
92
+ return;
93
+ }
94
+ case "stream.request": {
95
+ await this.#startStream(envelope);
96
+ return;
97
+ }
98
+ case "subscribe": {
99
+ await this.#subscribe(envelope);
100
+ return;
101
+ }
102
+ case "unsubscribe": {
103
+ const release = this.#subscriptions.get(envelope.subscriptionId);
104
+ release?.();
105
+ this.#subscriptions.delete(envelope.subscriptionId);
106
+ await this.#emit(createSuccessResponse(envelope.requestId, { subscriptionId: envelope.subscriptionId, active: false }));
107
+ return;
108
+ }
109
+ case "stream.cancel": {
110
+ const active = this.#streams.get(envelope.streamId);
111
+ active?.execution.cancel(envelope.reason);
112
+ active?.abort.abort();
113
+ return;
114
+ }
115
+ }
116
+ }
117
+ /** Releases every subscription and stream held by this connection. */
118
+ close() {
119
+ if (this.#closed)
120
+ return;
121
+ this.#closed = true;
122
+ for (const release of this.#subscriptions.values())
123
+ release();
124
+ this.#subscriptions.clear();
125
+ for (const active of this.#streams.values()) {
126
+ active.execution.cancel("Connection closed");
127
+ active.abort.abort();
128
+ }
129
+ this.#streams.clear();
130
+ }
131
+ #dispatchOptions() {
132
+ return {
133
+ ...(this.#session ? { session: this.#session } : {}),
134
+ ...(this.#principal ? { principal: this.#principal } : {}),
135
+ transport: this.transport
136
+ };
137
+ }
138
+ async #subscribe(envelope) {
139
+ const name = envelope.event.name;
140
+ const definition = name === "*" ? undefined : this.#application.registry.getEvent(name, envelope.event.version);
141
+ const required = definition?.authorization ?? [];
142
+ const granted = this.#session?.permissions ?? [];
143
+ if (required.length > 0 && !required.every((permission) => grantsPermission(granted, permission))) {
144
+ const error = this.#principal
145
+ ? errors.forbidden(`Missing permission to observe ${name}`)
146
+ : errors.unauthorized();
147
+ await this.#emit(createErrorResponse(envelope.requestId, error.toErrorObject()));
148
+ return;
149
+ }
150
+ if (this.#subscriptions.has(envelope.subscriptionId)) {
151
+ await this.#emit(createErrorResponse(envelope.requestId, errors.conflict(`Subscription ${envelope.subscriptionId} already exists`).toErrorObject()));
152
+ return;
153
+ }
154
+ const release = this.#application.subscribe(envelope.event.version === undefined ? { name } : { name, version: envelope.event.version }, (event) => {
155
+ void this.#emit({ ...event, subscriptionId: envelope.subscriptionId });
156
+ }, envelope.subscriptionId);
157
+ this.#subscriptions.set(envelope.subscriptionId, release);
158
+ await this.#emit(createSuccessResponse(envelope.requestId, { subscriptionId: envelope.subscriptionId, active: true }));
159
+ }
160
+ async #startStream(envelope) {
161
+ const abort = new AbortController();
162
+ let execution;
163
+ try {
164
+ execution = await this.#application.handleStreamRequest(envelope, {
165
+ ...this.#dispatchOptions(),
166
+ signal: abort.signal
167
+ });
168
+ }
169
+ catch (error) {
170
+ await this.#fail(envelope.requestId, envelope.traceId, error);
171
+ return;
172
+ }
173
+ const streamId = execution.streamId;
174
+ this.#streams.set(streamId, { execution, abort });
175
+ await this.#emit(createStreamStart(envelope.requestId, streamId, envelope.traceId));
176
+ void (async () => {
177
+ let sequence = 0;
178
+ try {
179
+ for await (const chunk of execution.chunks) {
180
+ if (this.#closed)
181
+ break;
182
+ await this.#emit(createStreamChunk(streamId, sequence, chunk));
183
+ sequence += 1;
184
+ }
185
+ await this.#emit(createStreamEnd(streamId));
186
+ }
187
+ catch (error) {
188
+ await this.#emit(createStreamEnd(streamId, toWireError(error, this.#application.mode)));
189
+ }
190
+ finally {
191
+ this.#streams.delete(streamId);
192
+ }
193
+ })();
194
+ }
195
+ async #fail(requestId, traceId, error) {
196
+ const wire = toWireError(error, this.#application.mode);
197
+ await this.#emit(createErrorResponse(requestId ?? "req_unknown", wire, traceId ? { traceId } : {}));
198
+ if (!AppPortError.is(error)) {
199
+ this.#application.logger.error("connection failed to handle an envelope", { transport: this.transport });
200
+ }
201
+ }
202
+ async #emit(envelope) {
203
+ if (this.#closed)
204
+ return;
205
+ try {
206
+ await this.#send(envelope);
207
+ }
208
+ catch (error) {
209
+ this.#application.logger.warn("failed to deliver an envelope", {
210
+ transport: this.transport,
211
+ type: envelope.type,
212
+ reason: error instanceof Error ? error.name : "unknown"
213
+ });
214
+ }
215
+ }
216
+ }
217
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js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C;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAA6B,EAAE,OAA2B,EAAE,KAAc;QACpF,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,IAAI,CAAC,KAAK,CACd,mBAAmB,CAAC,SAAS,IAAI,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAClF,CAAC;QACF,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAC3G,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAwB;QAClC,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,+BAA+B,EAAE;gBAC7D,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;aACxD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { HttpBinding } from "./http.js";
2
+ /**
3
+ * A WHATWG `fetch` handler for the HTTP binding.
4
+ *
5
+ * Works anywhere `Request`/`Response` exist — Deno, Bun, Cloudflare Workers,
6
+ * Node's `node:http` via an adapter — which keeps the HTTP binding portable
7
+ * without dragging a server framework into the protocol (§73).
8
+ */
9
+ export declare function createFetchHandler(binding: HttpBinding): (request: Request) => Promise<Response>;
10
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAwB,MAAM,WAAW,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA4ChG"}
@@ -0,0 +1,50 @@
1
+ import { HttpBinding } from "./http.js";
2
+ /**
3
+ * A WHATWG `fetch` handler for the HTTP binding.
4
+ *
5
+ * Works anywhere `Request`/`Response` exist — Deno, Bun, Cloudflare Workers,
6
+ * Node's `node:http` via an adapter — which keeps the HTTP binding portable
7
+ * without dragging a server framework into the protocol (§73).
8
+ */
9
+ export function createFetchHandler(binding) {
10
+ return async (request) => {
11
+ const url = new URL(request.url);
12
+ const headers = {};
13
+ request.headers.forEach((value, key) => {
14
+ headers[key.toLowerCase()] = value;
15
+ });
16
+ const httpRequest = {
17
+ method: request.method,
18
+ path: url.pathname,
19
+ query: url.searchParams,
20
+ headers,
21
+ body: request.method === "POST" ? await request.text() : "",
22
+ signal: request.signal
23
+ };
24
+ const outcome = await binding.route(httpRequest);
25
+ if (outcome.kind === "json") {
26
+ return new Response(JSON.stringify(outcome.body), { status: outcome.status, headers: outcome.headers });
27
+ }
28
+ if (outcome.kind === "text") {
29
+ return new Response(outcome.body, { status: outcome.status, headers: outcome.headers });
30
+ }
31
+ const encoder = new TextEncoder();
32
+ const iterator = outcome.frames[Symbol.asyncIterator]();
33
+ const body = new ReadableStream({
34
+ async pull(controller) {
35
+ const next = await iterator.next();
36
+ if (next.done) {
37
+ controller.close();
38
+ return;
39
+ }
40
+ controller.enqueue(encoder.encode(next.value));
41
+ },
42
+ cancel() {
43
+ outcome.cancel();
44
+ void iterator.return?.();
45
+ }
46
+ });
47
+ return new Response(body, { status: outcome.status, headers: outcome.headers });
48
+ };
49
+ }
50
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAwB,MAAM,WAAW,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAoB;IACrD,OAAO,KAAK,EAAE,OAAgB,EAAqB,EAAE;QACnD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,OAAO,GAAuC,EAAE,CAAC;QACvD,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACrC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,MAAM,WAAW,GAAoB;YACnC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,IAAI,EAAE,GAAG,CAAC,QAAQ;YAClB,KAAK,EAAE,GAAG,CAAC,YAAY;YACvB,OAAO;YACP,IAAI,EAAE,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;YAC3D,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;QAEF,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACjD,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1G,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1F,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,GAAG,IAAI,cAAc,CAAa;YAC1C,KAAK,CAAC,IAAI,CAAC,UAAU;gBACnB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACd,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO;gBACT,CAAC;gBACD,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACjD,CAAC;YACD,MAAM;gBACJ,OAAO,CAAC,MAAM,EAAE,CAAC;gBACjB,KAAK,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3B,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { type ErrorCode } from "@appport/protocol";
2
+ import type { AppPortServer } from "./server.js";
3
+ /**
4
+ * HTTP binding (specification §25, §26).
5
+ *
6
+ * One endpoint, `POST /appport`, carries every capability. Streams are answered
7
+ * as newline-delimited envelopes and events as Server-Sent Events, so a plain
8
+ * HTTP deployment still reaches conformance level 3 without WebSocket.
9
+ */
10
+ export declare const APPPORT_CONTENT_TYPE = "application/json";
11
+ export declare const NDJSON_CONTENT_TYPE = "application/x-ndjson";
12
+ export declare const SSE_CONTENT_TYPE = "text/event-stream";
13
+ /** Header carrying a session identifier. Deployments may use cookies instead. */
14
+ export declare const SESSION_HEADER = "x-appport-session";
15
+ export declare function originMatches(origin: string, allowed: string): boolean;
16
+ /**
17
+ * Recommended AppPort → HTTP status mapping (§26).
18
+ *
19
+ * `mapped` follows the table. `protocol` answers 200 for every well-formed
20
+ * envelope and reserves non-2xx for transport-level failures, which keeps
21
+ * application status strictly separate from transport status.
22
+ */
23
+ export type StatusMode = "mapped" | "protocol";
24
+ export declare function statusForError(code: ErrorCode, mode?: StatusMode): number;
25
+ export interface HttpRequestLike {
26
+ method: string;
27
+ /** Path without query string. */
28
+ path: string;
29
+ query?: URLSearchParams;
30
+ headers?: Readonly<Record<string, string | undefined>>;
31
+ /** Raw request body, already decoded as UTF-8 text. */
32
+ body?: string;
33
+ /** Aborted when the client disconnects. */
34
+ signal?: AbortSignal;
35
+ }
36
+ export type HttpOutcome = {
37
+ kind: "json";
38
+ status: number;
39
+ headers: Record<string, string>;
40
+ body: unknown;
41
+ } | {
42
+ kind: "text";
43
+ status: number;
44
+ headers: Record<string, string>;
45
+ body: string;
46
+ } | {
47
+ kind: "stream";
48
+ status: number;
49
+ headers: Record<string, string>;
50
+ /** Encoded frames, ready to write. */
51
+ frames: AsyncIterable<string>;
52
+ cancel(): void;
53
+ };
54
+ export interface HttpBindingOptions {
55
+ server: AppPortServer;
56
+ statusMode?: StatusMode;
57
+ /** Allowed origins for browser clients. Omit to send no CORS headers. */
58
+ cors?: {
59
+ origins: readonly string[] | "*";
60
+ credentials?: boolean;
61
+ };
62
+ /** Maximum accepted request body size in bytes. */
63
+ maxBodyBytes?: number;
64
+ /** Reject browser origins outside this list. Supports localhost `:*` patterns. */
65
+ allowedOrigins?: readonly string[];
66
+ /** Capability and event names exposed through this binding. */
67
+ allowedCapabilities?: readonly string[];
68
+ }
69
+ export declare class HttpBinding {
70
+ #private;
71
+ readonly server: AppPortServer;
72
+ readonly statusMode: StatusMode;
73
+ constructor(options: HttpBindingOptions);
74
+ /** True when this binding serves the given path. */
75
+ handles(path: string): boolean;
76
+ corsHeaders(origin: string | undefined): Record<string, string>;
77
+ route(request: HttpRequestLike): Promise<HttpOutcome>;
78
+ }
79
+ export declare function createHttpBinding(options: HttpBindingOptions): HttpBinding;
80
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,SAAS,EAEf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAEpD,iFAAiF;AACjF,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAElD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAUtE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;AA8B/C,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,GAAE,UAAqB,GAAG,MAAM,CAGnF;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACvD,uDAA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