@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,83 @@
1
+ import { type AppPortManifest, type AppResponse, type ClientEnvelope, type DiscoveryDocument, type Principal, type ServerEnvelope, type Session } from "@appport/protocol";
2
+ import { type AppPortApplication } from "@appport/core/server-internal";
3
+ import { AppPortConnection, type SendEnvelope } from "./connection.js";
4
+ /** What a transport knows about a caller before any AppPort envelope is read. */
5
+ export interface AuthenticationRequest {
6
+ transport: string;
7
+ /** Session identifier supplied by the transport (header, IPC attribute, …). */
8
+ sessionId?: string;
9
+ /** Raw transport credentials. Opaque to AppPort; interpreted by the hook. */
10
+ headers?: Readonly<Record<string, string | undefined>>;
11
+ origin?: string;
12
+ /** Transport-specific caller detail (an Electron `WebContents` id, …). */
13
+ peer?: unknown;
14
+ }
15
+ export interface Identity {
16
+ session?: Session;
17
+ principal?: Principal;
18
+ }
19
+ /**
20
+ * Resolves an identity from transport-supplied credentials.
21
+ *
22
+ * AppPort deliberately does not authenticate: it represents the resulting
23
+ * identity (§35). Returning `{}` means anonymous — which is not the same as
24
+ * trusted, on any transport (§37, §38).
25
+ */
26
+ export type Authenticate = (request: AuthenticationRequest) => Identity | undefined | Promise<Identity | undefined>;
27
+ export interface ServerOptions {
28
+ application: AppPortApplication;
29
+ authenticate?: Authenticate;
30
+ maxEnvelopeBytes?: number;
31
+ /** Endpoint paths advertised through discovery (§39, §40). */
32
+ endpoints?: {
33
+ request?: string;
34
+ websocket?: string;
35
+ manifest?: string;
36
+ };
37
+ }
38
+ /**
39
+ * The server-side protocol runtime.
40
+ *
41
+ * It turns envelopes into dispatches and results back into envelopes, and owns
42
+ * discovery. It is transport-agnostic: HTTP, WebSocket and IPC bindings are
43
+ * thin adapters over this class.
44
+ */
45
+ export declare class AppPortServer {
46
+ #private;
47
+ readonly application: AppPortApplication;
48
+ readonly endpoints: {
49
+ request: string;
50
+ websocket: string;
51
+ manifest: string;
52
+ };
53
+ constructor(options: ServerOptions);
54
+ get connectionCount(): number;
55
+ manifest(): AppPortManifest;
56
+ /** The `.well-known` discovery document (§39). */
57
+ discovery(): DiscoveryDocument;
58
+ identify(request: AuthenticationRequest): Promise<Identity>;
59
+ /** Opens a duplex connection (WebSocket, IPC, in-process). */
60
+ createConnection(options: {
61
+ transport: string;
62
+ send: SendEnvelope;
63
+ identity?: Identity;
64
+ allowedCapabilities?: ReadonlySet<string>;
65
+ }): AppPortConnection;
66
+ releaseConnection(connection: AppPortConnection): void;
67
+ /**
68
+ * Handles a single request envelope without a persistent connection — the
69
+ * shape plain HTTP needs.
70
+ */
71
+ handleUnary(value: unknown, context: {
72
+ identity?: Identity;
73
+ transport: string;
74
+ allowedCapabilities?: ReadonlySet<string>;
75
+ }): Promise<AppResponse>;
76
+ /** Decodes a text frame into a validated client envelope. */
77
+ parseText(raw: string): ClientEnvelope;
78
+ errorEnvelope(requestId: string | undefined, error: unknown, traceId?: string): ServerEnvelope;
79
+ /** Closes every open connection. */
80
+ close(): Promise<void>;
81
+ }
82
+ export declare function createServer(options: ServerOptions): AppPortServer;
83
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,SA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ekTraceId, PROTOCOL_ID } from "@appport/protocol";
2
+ import { toWireError } from "@appport/core/server-internal";
3
+ import { AppPortConnection } from "./connection.js";
4
+ /**
5
+ * The server-side protocol runtime.
6
+ *
7
+ * It turns envelopes into dispatches and results back into envelopes, and owns
8
+ * discovery. It is transport-agnostic: HTTP, WebSocket and IPC bindings are
9
+ * thin adapters over this class.
10
+ */
11
+ export class AppPortServer {
12
+ application;
13
+ #authenticate;
14
+ #maxEnvelopeBytes;
15
+ endpoints;
16
+ #connections = new Set();
17
+ constructor(options) {
18
+ this.application = options.application;
19
+ this.#authenticate = options.authenticate;
20
+ this.#maxEnvelopeBytes = options.maxEnvelopeBytes;
21
+ this.endpoints = {
22
+ request: options.endpoints?.request ?? DEFAULT_HTTP_ENDPOINT,
23
+ websocket: options.endpoints?.websocket ?? DEFAULT_WS_ENDPOINT,
24
+ manifest: options.endpoints?.manifest ?? DEFAULT_MANIFEST_PATH
25
+ };
26
+ }
27
+ get connectionCount() {
28
+ return this.#connections.size;
29
+ }
30
+ manifest() {
31
+ return this.application.manifest();
32
+ }
33
+ /** The `.well-known` discovery document (§39). */
34
+ discovery() {
35
+ const manifest = this.manifest();
36
+ return {
37
+ protocol: PROTOCOL_ID,
38
+ manifest: this.endpoints.manifest,
39
+ endpoint: this.endpoints.request,
40
+ application: {
41
+ id: manifest.application.id,
42
+ name: manifest.application.name,
43
+ version: manifest.application.version
44
+ },
45
+ transports: manifest.transports
46
+ };
47
+ }
48
+ async identify(request) {
49
+ if (!this.#authenticate)
50
+ return {};
51
+ return (await this.#authenticate(request)) ?? {};
52
+ }
53
+ /** Opens a duplex connection (WebSocket, IPC, in-process). */
54
+ createConnection(options) {
55
+ const connection = new AppPortConnection({
56
+ application: this.application,
57
+ transport: options.transport,
58
+ send: options.send,
59
+ ...(options.identity?.session ? { session: options.identity.session } : {}),
60
+ ...(options.identity?.principal ? { principal: options.identity.principal } : {}),
61
+ ...(options.allowedCapabilities ? { allowedCapabilities: options.allowedCapabilities } : {}),
62
+ ...(this.#maxEnvelopeBytes !== undefined ? { maxEnvelopeBytes: this.#maxEnvelopeBytes } : {})
63
+ });
64
+ this.#connections.add(connection);
65
+ return connection;
66
+ }
67
+ releaseConnection(connection) {
68
+ connection.close();
69
+ this.#connections.delete(connection);
70
+ }
71
+ /**
72
+ * Handles a single request envelope without a persistent connection — the
73
+ * shape plain HTTP needs.
74
+ */
75
+ async handleUnary(value, context) {
76
+ const requestId = peekRequestId(value);
77
+ const traceId = peekTraceId(value);
78
+ try {
79
+ const envelope = parseClientEnvelope(value);
80
+ if (envelope.type !== "request") {
81
+ throw errors.invalidRequest(`Envelope type "${envelope.type}" requires a duplex transport`);
82
+ }
83
+ if (context.allowedCapabilities && envelope.capability.name !== "appport.manifest" && envelope.capability.name !== "appport.ping" && !context.allowedCapabilities.has(envelope.capability.name)) {
84
+ throw errors.forbidden(`${envelope.capability.name} is not exposed to this surface`);
85
+ }
86
+ return await this.application.handleRequest(envelope, {
87
+ ...(context.identity?.session ? { session: context.identity.session } : {}),
88
+ ...(context.identity?.principal ? { principal: context.identity.principal } : {}),
89
+ transport: context.transport
90
+ });
91
+ }
92
+ catch (error) {
93
+ return createErrorResponse(requestId ?? "req_unknown", toWireError(error, this.application.mode), traceId ? { traceId } : {});
94
+ }
95
+ }
96
+ /** Decodes a text frame into a validated client envelope. */
97
+ parseText(raw) {
98
+ return parseClientEnvelope(decodeEnvelopeText(raw, this.#maxEnvelopeBytes ? { maxBytes: this.#maxEnvelopeBytes } : {}));
99
+ }
100
+ errorEnvelope(requestId, error, traceId) {
101
+ return createErrorResponse(requestId ?? "req_unknown", toWireError(error, this.application.mode), traceId ? { traceId } : {});
102
+ }
103
+ /** Closes every open connection. */
104
+ async close() {
105
+ for (const connection of this.#connections)
106
+ connection.close();
107
+ this.#connections.clear();
108
+ await this.application.close();
109
+ }
110
+ }
111
+ export function createServer(options) {
112
+ return new AppPortServer(options);
113
+ }
114
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @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jC,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Duplex } from "node:stream";
2
+ import type { IncomingMessage } from "node:http";
3
+ export declare const DEFAULT_MAX_MESSAGE_BYTES: number;
4
+ export interface WebSocketPeerOptions {
5
+ maxMessageBytes?: number;
6
+ }
7
+ export type CloseListener = (code: number, reason: string) => void;
8
+ /** True when an HTTP request is a WebSocket upgrade. */
9
+ export declare function isWebSocketUpgrade(request: IncomingMessage): boolean;
10
+ export declare function acceptKey(key: string): string;
11
+ /** One accepted WebSocket connection. */
12
+ export declare class WebSocketPeer {
13
+ #private;
14
+ onMessage: ((data: string) => void) | undefined;
15
+ onClose: CloseListener | undefined;
16
+ onError: ((error: Error) => void) | undefined;
17
+ private constructor();
18
+ get closed(): boolean;
19
+ /** Completes the handshake and returns the peer, or null when it is not one. */
20
+ static accept(request: IncomingMessage, socket: Duplex, head: Buffer | undefined, options?: WebSocketPeerOptions): WebSocketPeer | null;
21
+ send(text: string): void;
22
+ ping(): void;
23
+ close(code?: number, reason?: string): void;
24
+ }
25
+ //# sourceMappingURL=websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAqBjD,eAAO,MAAM,yBAAyB,QAAkB,CAAC;AAEzD,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnE,wDAAwD;AACxD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAGpE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,yCAAyC;AACzC,qBAAa,aAAa;;IAQxB,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAChD,OAAO,EAAE,aAAa,GAAG,SAAS,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAE9C,OAAO;IAYP,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,gFAAgF;IAChF,MAAM,CAAC,MAAM,CACX,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,GAAE,oBAAyB,GACjC,aAAa,GAAG,IAAI;IAsBvB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKxB,IAAI,IAAI,IAAI;IAKZ,KAAK,CAAC,IAAI,SAAO,EAAE,MAAM,SAAK,GAAG,IAAI;CAqEtC"}
@@ -0,0 +1,221 @@
1
+ import { createHash } from "node:crypto";
2
+ /**
3
+ * A dependency-free RFC 6455 server endpoint.
4
+ *
5
+ * AppPort's WebSocket binding (§27) treats the socket as a pure carrier: every
6
+ * message is exactly one AppPort envelope. Implementing the framing here keeps
7
+ * `@appport/server` free of runtime dependencies and keeps the binding honest —
8
+ * nothing about the application semantics lives in the transport.
9
+ */
10
+ const GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
11
+ const OPCODE = {
12
+ continuation: 0x0,
13
+ text: 0x1,
14
+ binary: 0x2,
15
+ close: 0x8,
16
+ ping: 0x9,
17
+ pong: 0xa
18
+ };
19
+ export const DEFAULT_MAX_MESSAGE_BYTES = 4 * 1024 * 1024;
20
+ /** True when an HTTP request is a WebSocket upgrade. */
21
+ export function isWebSocketUpgrade(request) {
22
+ const upgrade = request.headers["upgrade"];
23
+ return typeof upgrade === "string" && upgrade.toLowerCase() === "websocket";
24
+ }
25
+ export function acceptKey(key) {
26
+ return createHash("sha1").update(key + GUID).digest("base64");
27
+ }
28
+ /** One accepted WebSocket connection. */
29
+ export class WebSocketPeer {
30
+ #socket;
31
+ #maxMessageBytes;
32
+ #buffer = Buffer.alloc(0);
33
+ #fragments = [];
34
+ #fragmentOpcode = 0;
35
+ #closed = false;
36
+ onMessage;
37
+ onClose;
38
+ onError;
39
+ constructor(socket, options) {
40
+ this.#socket = socket;
41
+ this.#maxMessageBytes = options.maxMessageBytes ?? DEFAULT_MAX_MESSAGE_BYTES;
42
+ socket.on("data", (chunk) => this.#ingest(chunk));
43
+ socket.on("error", (error) => {
44
+ this.onError?.(error);
45
+ this.#finish(1006, "socket error");
46
+ });
47
+ socket.on("close", () => this.#finish(1006, "socket closed"));
48
+ }
49
+ get closed() {
50
+ return this.#closed;
51
+ }
52
+ /** Completes the handshake and returns the peer, or null when it is not one. */
53
+ static accept(request, socket, head, options = {}) {
54
+ const key = request.headers["sec-websocket-key"];
55
+ const version = request.headers["sec-websocket-version"];
56
+ if (!isWebSocketUpgrade(request) || typeof key !== "string" || version !== "13") {
57
+ socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
58
+ return null;
59
+ }
60
+ socket.write([
61
+ "HTTP/1.1 101 Switching Protocols",
62
+ "Upgrade: websocket",
63
+ "Connection: Upgrade",
64
+ `Sec-WebSocket-Accept: ${acceptKey(key)}`,
65
+ "\r\n"
66
+ ].join("\r\n"));
67
+ socket.setNoDelay?.(true);
68
+ const peer = new WebSocketPeer(socket, options);
69
+ if (head?.length)
70
+ peer.#ingest(head);
71
+ return peer;
72
+ }
73
+ send(text) {
74
+ if (this.#closed)
75
+ return;
76
+ this.#socket.write(encodeFrame(OPCODE.text, Buffer.from(text, "utf8")));
77
+ }
78
+ ping() {
79
+ if (this.#closed)
80
+ return;
81
+ this.#socket.write(encodeFrame(OPCODE.ping, Buffer.alloc(0)));
82
+ }
83
+ close(code = 1000, reason = "") {
84
+ if (this.#closed)
85
+ return;
86
+ const payload = Buffer.alloc(2 + Buffer.byteLength(reason));
87
+ payload.writeUInt16BE(code, 0);
88
+ payload.write(reason, 2);
89
+ try {
90
+ this.#socket.write(encodeFrame(OPCODE.close, payload));
91
+ }
92
+ catch {
93
+ // The socket may already be gone; the close listener still fires.
94
+ }
95
+ this.#socket.end();
96
+ this.#finish(code, reason);
97
+ }
98
+ #finish(code, reason) {
99
+ if (this.#closed)
100
+ return;
101
+ this.#closed = true;
102
+ this.onClose?.(code, reason);
103
+ }
104
+ #ingest(chunk) {
105
+ this.#buffer = this.#buffer.length === 0 ? chunk : Buffer.concat([this.#buffer, chunk]);
106
+ for (;;) {
107
+ const frame = decodeFrame(this.#buffer);
108
+ if (!frame)
109
+ return;
110
+ this.#buffer = this.#buffer.subarray(frame.consumed);
111
+ this.#dispatch(frame);
112
+ if (this.#closed)
113
+ return;
114
+ }
115
+ }
116
+ #dispatch(frame) {
117
+ switch (frame.opcode) {
118
+ case OPCODE.ping:
119
+ this.#socket.write(encodeFrame(OPCODE.pong, frame.payload));
120
+ return;
121
+ case OPCODE.pong:
122
+ return;
123
+ case OPCODE.close: {
124
+ const code = frame.payload.length >= 2 ? frame.payload.readUInt16BE(0) : 1005;
125
+ this.close(code === 1005 ? 1000 : code);
126
+ return;
127
+ }
128
+ case OPCODE.binary:
129
+ // AppPort v1 is UTF-8 JSON on the wire (§50); binary uses blob refs (§51).
130
+ this.close(1003, "binary frames are not accepted");
131
+ return;
132
+ case OPCODE.text:
133
+ case OPCODE.continuation: {
134
+ if (frame.opcode === OPCODE.text) {
135
+ this.#fragments = [];
136
+ this.#fragmentOpcode = OPCODE.text;
137
+ }
138
+ this.#fragments.push(frame.payload);
139
+ const size = this.#fragments.reduce((total, part) => total + part.length, 0);
140
+ if (size > this.#maxMessageBytes) {
141
+ this.close(1009, "message too large");
142
+ return;
143
+ }
144
+ if (!frame.fin)
145
+ return;
146
+ const message = Buffer.concat(this.#fragments).toString("utf8");
147
+ this.#fragments = [];
148
+ if (this.#fragmentOpcode === OPCODE.text)
149
+ this.onMessage?.(message);
150
+ return;
151
+ }
152
+ default:
153
+ this.close(1002, "unsupported opcode");
154
+ }
155
+ }
156
+ }
157
+ function decodeFrame(buffer) {
158
+ if (buffer.length < 2)
159
+ return null;
160
+ const first = buffer[0];
161
+ const second = buffer[1];
162
+ const fin = (first & 0x80) !== 0;
163
+ const opcode = first & 0x0f;
164
+ const masked = (second & 0x80) !== 0;
165
+ let length = second & 0x7f;
166
+ let offset = 2;
167
+ if (length === 126) {
168
+ if (buffer.length < offset + 2)
169
+ return null;
170
+ length = buffer.readUInt16BE(offset);
171
+ offset += 2;
172
+ }
173
+ else if (length === 127) {
174
+ if (buffer.length < offset + 8)
175
+ return null;
176
+ const big = buffer.readBigUInt64BE(offset);
177
+ if (big > BigInt(Number.MAX_SAFE_INTEGER))
178
+ throw new Error("frame too large");
179
+ length = Number(big);
180
+ offset += 8;
181
+ }
182
+ let mask;
183
+ if (masked) {
184
+ if (buffer.length < offset + 4)
185
+ return null;
186
+ mask = buffer.subarray(offset, offset + 4);
187
+ offset += 4;
188
+ }
189
+ if (buffer.length < offset + length)
190
+ return null;
191
+ const raw = buffer.subarray(offset, offset + length);
192
+ const payload = mask ? unmask(raw, mask) : Buffer.from(raw);
193
+ return { fin, opcode, payload, consumed: offset + length };
194
+ }
195
+ function unmask(payload, mask) {
196
+ const out = Buffer.allocUnsafe(payload.length);
197
+ for (let i = 0; i < payload.length; i += 1)
198
+ out[i] = payload[i] ^ mask[i % 4];
199
+ return out;
200
+ }
201
+ function encodeFrame(opcode, payload) {
202
+ const length = payload.length;
203
+ let header;
204
+ if (length < 126) {
205
+ header = Buffer.alloc(2);
206
+ header[1] = length;
207
+ }
208
+ else if (length < 65536) {
209
+ header = Buffer.alloc(4);
210
+ header[1] = 126;
211
+ header.writeUInt16BE(length, 2);
212
+ }
213
+ else {
214
+ header = Buffer.alloc(10);
215
+ header[1] = 127;
216
+ header.writeBigUInt64BE(BigInt(length), 2);
217
+ }
218
+ header[0] = 0x80 | opcode;
219
+ return Buffer.concat([header, payload]);
220
+ }
221
+ //# sourceMappingURL=websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC;;;;;;;GAOG;AACH,MAAM,IAAI,GAAG,sCAAsC,CAAC;AAEpD,MAAM,MAAM,GAAG;IACb,YAAY,EAAE,GAAG;IACjB,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;CACD,CAAC;AAEX,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAQzD,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAC,OAAwB;IACzD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAChE,CAAC;AAED,yCAAyC;AACzC,MAAM,OAAO,aAAa;IACf,OAAO,CAAS;IAChB,gBAAgB,CAAS;IAClC,OAAO,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,UAAU,GAAa,EAAE,CAAC;IAC1B,eAAe,GAAG,CAAC,CAAC;IACpB,OAAO,GAAG,KAAK,CAAC;IAEhB,SAAS,CAAuC;IAChD,OAAO,CA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c,CAAC;IACnB,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QACjB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IACrB,CAAC;SAAM,IAAI,MAAM,GAAG,KAAK,EAAE,CAAC;QAC1B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1B,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@appport/server",
3
+ "version": "1.0.0",
4
+ "description": "Server-side AppPort protocol runtime with HTTP and WebSocket bindings.",
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
+ "./node": {
16
+ "types": "./dist/node-entry.d.ts",
17
+ "import": "./dist/node-entry.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsc -b",
26
+ "clean": "tsc -b --clean"
27
+ },
28
+ "dependencies": {
29
+ "@appport/protocol": "1.0.0",
30
+ "@appport/core": "1.0.0",
31
+ "@appport/authorization": "1.0.0"
32
+ },
33
+ "private": true
34
+ }
@@ -0,0 +1,56 @@
1
+ # @appport/transport-electron
2
+
3
+ The Electron IPC transport: main-process binding, preload bridge and renderer
4
+ transport, over a single generic channel.
5
+
6
+ ```js
7
+ // main process
8
+ import { ipcMain } from "electron";
9
+ import { serveElectronIpc } from "@appport/transport-electron";
10
+
11
+ serveElectronIpc({
12
+ server,
13
+ ipcMain,
14
+ validateSender: (event) => event.senderFrame?.url?.startsWith("file://") ?? false,
15
+ identify: (event) => resolveIdentity(event)
16
+ });
17
+ ```
18
+
19
+ ```js
20
+ // preload.cjs
21
+ const { contextBridge, ipcRenderer } = require("electron");
22
+ const { exposeAppPort } = require("@appport/transport-electron/preload");
23
+
24
+ exposeAppPort(contextBridge, ipcRenderer);
25
+ ```
26
+
27
+ ```ts
28
+ // renderer
29
+ import { createElectronTransport } from "@appport/transport-electron";
30
+
31
+ const transport = createElectronTransport(); // uses window.appport
32
+ ```
33
+
34
+ ## Why one channel
35
+
36
+ The AppPort envelope identifies the capability, so there is one IPC channel,
37
+ `appport:message`, not one per operation. Channels named `save-document` and
38
+ `open-document` would put the application API into the transport, which is what
39
+ the protocol exists to prevent.
40
+
41
+ ## Why a bridge, not ipcRenderer
42
+
43
+ Electron's guidance is to expose narrowly scoped context-bridge APIs; exposing
44
+ `ipcRenderer` grants arbitrary message access. The bridge here is two functions:
45
+ send an envelope, receive envelopes.
46
+
47
+ ## Trust
48
+
49
+ IPC is not identity. `validateSender` decides whether a frame may speak AppPort
50
+ at all, `identify` resolves the session, and every capability is still
51
+ authorized. Envelopes queue behind identity resolution, so the first request is
52
+ never dispatched as anonymous.
53
+
54
+ The package depends on structural types rather than on `electron`, so the same
55
+ build works in the main process, the preload script and the renderer — and so
56
+ the transport can be tested without launching a browser.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@appport/transport-electron` — the Electron IPC transport (§23, §28).
3
+ *
4
+ * Main-process binding, preload bridge and renderer transport, over a single
5
+ * generic IPC channel.
6
+ */
7
+ export * from "./types.js";
8
+ export * from "./main.js";
9
+ export * from "./preload.js";
10
+ export * from "./renderer.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@appport/transport-electron` — the Electron IPC transport (§23, §28).
3
+ *
4
+ * Main-process binding, preload bridge and renderer transport, over a single
5
+ * generic IPC channel.
6
+ */
7
+ export * from "./types.js";
8
+ export * from "./main.js";
9
+ export * from "./preload.js";
10
+ export * from "./renderer.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { AppPortServer, Identity } from "@appport/server";
2
+ import { type IpcMainEventLike, type IpcMainLike } from "./types.js";
3
+ export interface ElectronMainOptions {
4
+ server: AppPortServer;
5
+ ipcMain: IpcMainLike;
6
+ /** IPC channel name. One channel carries every capability (§28). */
7
+ channel?: string;
8
+ /**
9
+ * Decides whether a renderer may speak AppPort at all.
10
+ *
11
+ * Electron recommends validating the sender rather than trusting any frame
12
+ * that can reach IPC. Returning false drops the message silently.
13
+ */
14
+ validateSender?: (event: IpcMainEventLike) => boolean;
15
+ /** Resolves an identity for a renderer. IPC is not identity (§37). */
16
+ identify?: (event: IpcMainEventLike) => Identity | Promise<Identity>;
17
+ }
18
+ export interface ElectronMainBinding {
19
+ /** Stops listening and releases every renderer connection. */
20
+ dispose(): void;
21
+ readonly connectionCount: number;
22
+ }
23
+ /**
24
+ * Serves AppPort over Electron IPC from the main process (§28).
25
+ *
26
+ * One generic channel carries every capability; the envelope identifies the
27
+ * capability. Generating a channel per operation would put the application API
28
+ * into the transport, which is the mistake the protocol exists to prevent.
29
+ */
30
+ export declare function serveElectronIpc(options: ElectronMainOptions): ElectronMainBinding;
31
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAmB,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtF,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC;IACrB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC;IACtD,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAYD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,mBAAmB,CAoDlF"}