@pikku/core 0.12.2 → 0.12.4

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 (282) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/crypto-utils.d.ts +10 -0
  3. package/dist/crypto-utils.js +62 -0
  4. package/dist/function/function-runner.js +4 -4
  5. package/dist/function/functions.types.d.ts +26 -1
  6. package/dist/function/functions.types.js +16 -0
  7. package/dist/handle-error.d.ts +1 -1
  8. package/dist/handle-error.js +7 -3
  9. package/dist/index.d.ts +14 -2
  10. package/dist/index.js +1 -1
  11. package/dist/pikku-state.js +3 -1
  12. package/dist/schema.js +1 -1
  13. package/dist/services/in-memory-workflow-service.d.ts +22 -3
  14. package/dist/services/in-memory-workflow-service.js +77 -1
  15. package/dist/services/workflow-service.d.ts +8 -2
  16. package/dist/testing/index.d.ts +2 -0
  17. package/dist/testing/index.js +1 -0
  18. package/dist/testing/service-tests.d.ts +31 -0
  19. package/dist/testing/service-tests.js +598 -0
  20. package/dist/types/core.types.d.ts +9 -1
  21. package/dist/types/state.types.d.ts +4 -2
  22. package/dist/utils/hash.d.ts +2 -0
  23. package/dist/utils/hash.js +23 -0
  24. package/dist/wirings/ai-agent/agent-dynamic-workflow.d.ts +6 -0
  25. package/dist/wirings/ai-agent/agent-dynamic-workflow.js +348 -0
  26. package/dist/wirings/ai-agent/ai-agent-memory.d.ts +1 -1
  27. package/dist/wirings/ai-agent/ai-agent-memory.js +6 -5
  28. package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +10 -7
  29. package/dist/wirings/ai-agent/ai-agent-prepare.js +127 -47
  30. package/dist/wirings/ai-agent/ai-agent-runner.d.ts +4 -0
  31. package/dist/wirings/ai-agent/ai-agent-runner.js +381 -27
  32. package/dist/wirings/ai-agent/ai-agent-stream.d.ts +7 -2
  33. package/dist/wirings/ai-agent/ai-agent-stream.js +109 -46
  34. package/dist/wirings/ai-agent/ai-agent.types.d.ts +22 -1
  35. package/dist/wirings/ai-agent/index.d.ts +1 -2
  36. package/dist/wirings/ai-agent/index.js +1 -2
  37. package/dist/wirings/channel/channel-handler.js +5 -1
  38. package/dist/wirings/channel/channel.types.d.ts +1 -7
  39. package/dist/wirings/channel/local/local-channel-handler.d.ts +1 -1
  40. package/dist/wirings/channel/local/local-channel-handler.js +5 -3
  41. package/dist/wirings/channel/local/local-channel-runner.js +14 -4
  42. package/dist/wirings/channel/serverless/serverless-channel-runner.js +4 -1
  43. package/dist/wirings/cli/cli-runner.js +10 -2
  44. package/dist/wirings/cli/cli.types.d.ts +1 -0
  45. package/dist/wirings/http/http-routes.js +0 -1
  46. package/dist/wirings/http/http-runner.d.ts +1 -1
  47. package/dist/wirings/http/http-runner.js +25 -3
  48. package/dist/wirings/http/http.types.d.ts +3 -11
  49. package/dist/wirings/http/index.d.ts +2 -1
  50. package/dist/wirings/http/index.js +1 -0
  51. package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -0
  52. package/dist/wirings/http/pikku-fetch-http-request.js +3 -0
  53. package/dist/wirings/http/pikku-fetch-http-response.d.ts +1 -0
  54. package/dist/wirings/http/pikku-fetch-http-response.js +4 -4
  55. package/dist/wirings/http/web-request.d.ts +12 -0
  56. package/dist/wirings/http/web-request.js +85 -0
  57. package/dist/wirings/mcp/mcp-endpoint-registry.js +1 -1
  58. package/dist/wirings/mcp/mcp-runner.js +13 -1
  59. package/dist/wirings/rpc/rpc-runner.d.ts +30 -6
  60. package/dist/wirings/rpc/rpc-runner.js +36 -14
  61. package/dist/wirings/rpc/rpc-types.d.ts +6 -1
  62. package/dist/wirings/rpc/wire-addon.d.ts +1 -0
  63. package/dist/wirings/rpc/wire-addon.js +1 -1
  64. package/dist/wirings/scheduler/scheduler-runner.js +1 -0
  65. package/dist/wirings/workflow/graph/graph-validation.d.ts +3 -0
  66. package/dist/wirings/workflow/graph/graph-validation.js +175 -0
  67. package/dist/wirings/workflow/graph/index.d.ts +1 -0
  68. package/dist/wirings/workflow/graph/index.js +1 -0
  69. package/dist/wirings/workflow/index.d.ts +1 -1
  70. package/dist/wirings/workflow/pikku-workflow-service.d.ts +8 -2
  71. package/dist/wirings/workflow/pikku-workflow-service.js +1 -2
  72. package/dist/wirings/workflow/workflow.types.d.ts +10 -1
  73. package/lcov.info +18891 -0
  74. package/package.json +4 -2
  75. package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +0 -5
  76. package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +0 -168
  77. package/src/crypto-utils.test.ts +0 -116
  78. package/src/crypto-utils.ts +0 -99
  79. package/src/errors/error-handler.ts +0 -62
  80. package/src/errors/error.test.ts +0 -195
  81. package/src/errors/errors.ts +0 -374
  82. package/src/errors/index.ts +0 -2
  83. package/src/factory-functions.test.ts +0 -109
  84. package/src/function/function-runner.test.ts +0 -536
  85. package/src/function/function-runner.ts +0 -365
  86. package/src/function/functions.types.ts +0 -267
  87. package/src/function/index.ts +0 -5
  88. package/src/handle-error.test.ts +0 -361
  89. package/src/handle-error.ts +0 -65
  90. package/src/index.ts +0 -104
  91. package/src/internal.ts +0 -6
  92. package/src/middleware/auth-apikey.test.ts +0 -363
  93. package/src/middleware/auth-apikey.ts +0 -47
  94. package/src/middleware/auth-bearer.test.ts +0 -450
  95. package/src/middleware/auth-bearer.ts +0 -72
  96. package/src/middleware/auth-cookie.test.ts +0 -528
  97. package/src/middleware/auth-cookie.ts +0 -80
  98. package/src/middleware/cors.test.ts +0 -424
  99. package/src/middleware/cors.ts +0 -104
  100. package/src/middleware/index.ts +0 -5
  101. package/src/middleware/remote-auth.test.ts +0 -488
  102. package/src/middleware/remote-auth.ts +0 -68
  103. package/src/middleware/timeout.ts +0 -15
  104. package/src/middleware-runner.test.ts +0 -418
  105. package/src/middleware-runner.ts +0 -234
  106. package/src/permissions.test.ts +0 -434
  107. package/src/permissions.ts +0 -319
  108. package/src/pikku-request.ts +0 -23
  109. package/src/pikku-response.ts +0 -5
  110. package/src/pikku-state.test.ts +0 -224
  111. package/src/pikku-state.ts +0 -214
  112. package/src/run-tests-script.test.ts +0 -49
  113. package/src/schema.test.ts +0 -249
  114. package/src/schema.ts +0 -151
  115. package/src/services/ai-agent-runner-service.ts +0 -41
  116. package/src/services/ai-run-state-service.ts +0 -20
  117. package/src/services/ai-storage-service.ts +0 -39
  118. package/src/services/content-service.ts +0 -76
  119. package/src/services/deployment-service.ts +0 -22
  120. package/src/services/gateway-service.ts +0 -20
  121. package/src/services/gopass-secrets.ts +0 -98
  122. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  123. package/src/services/in-memory-trigger-service.ts +0 -64
  124. package/src/services/in-memory-workflow-service.test.ts +0 -351
  125. package/src/services/in-memory-workflow-service.ts +0 -395
  126. package/src/services/index.ts +0 -56
  127. package/src/services/jwt-service.ts +0 -30
  128. package/src/services/local-content.ts +0 -120
  129. package/src/services/local-gateway-service.ts +0 -62
  130. package/src/services/local-secrets.test.ts +0 -80
  131. package/src/services/local-secrets.ts +0 -94
  132. package/src/services/local-variables.test.ts +0 -61
  133. package/src/services/local-variables.ts +0 -39
  134. package/src/services/logger-console.test.ts +0 -118
  135. package/src/services/logger-console.ts +0 -98
  136. package/src/services/logger.ts +0 -57
  137. package/src/services/scheduler-service.ts +0 -86
  138. package/src/services/schema-service.ts +0 -33
  139. package/src/services/scoped-secret-service.test.ts +0 -74
  140. package/src/services/scoped-secret-service.ts +0 -41
  141. package/src/services/secret-service.ts +0 -38
  142. package/src/services/trigger-service.ts +0 -17
  143. package/src/services/typed-secret-service.test.ts +0 -93
  144. package/src/services/typed-secret-service.ts +0 -70
  145. package/src/services/typed-variables-service.test.ts +0 -73
  146. package/src/services/typed-variables-service.ts +0 -81
  147. package/src/services/user-session-service.test.ts +0 -113
  148. package/src/services/user-session-service.ts +0 -86
  149. package/src/services/variables-service.ts +0 -11
  150. package/src/services/workflow-service.ts +0 -84
  151. package/src/time-utils.test.ts +0 -56
  152. package/src/time-utils.ts +0 -107
  153. package/src/types/core.types.ts +0 -470
  154. package/src/types/state.types.ts +0 -186
  155. package/src/utils.test.ts +0 -350
  156. package/src/utils.ts +0 -129
  157. package/src/version.test.ts +0 -80
  158. package/src/version.ts +0 -25
  159. package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +0 -363
  160. package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +0 -238
  161. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  162. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  163. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -309
  164. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  165. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  166. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -522
  167. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  168. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  169. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -317
  170. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -251
  171. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -652
  172. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1060
  173. package/src/wirings/ai-agent/ai-agent.types.ts +0 -360
  174. package/src/wirings/ai-agent/index.ts +0 -41
  175. package/src/wirings/channel/channel-common.ts +0 -90
  176. package/src/wirings/channel/channel-handler.ts +0 -241
  177. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  178. package/src/wirings/channel/channel-runner.ts +0 -166
  179. package/src/wirings/channel/channel-store.ts +0 -29
  180. package/src/wirings/channel/channel.types.ts +0 -178
  181. package/src/wirings/channel/define-channel-routes.ts +0 -25
  182. package/src/wirings/channel/eventhub-service.ts +0 -34
  183. package/src/wirings/channel/eventhub-store.ts +0 -13
  184. package/src/wirings/channel/index.ts +0 -24
  185. package/src/wirings/channel/local/index.ts +0 -3
  186. package/src/wirings/channel/local/local-channel-handler.ts +0 -79
  187. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  188. package/src/wirings/channel/local/local-channel-runner.ts +0 -200
  189. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  190. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  191. package/src/wirings/channel/log-channels.ts +0 -20
  192. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  193. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  194. package/src/wirings/channel/serverless/index.ts +0 -5
  195. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -286
  196. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  197. package/src/wirings/cli/channel/index.ts +0 -1
  198. package/src/wirings/cli/cli-runner.test.ts +0 -403
  199. package/src/wirings/cli/cli-runner.ts +0 -519
  200. package/src/wirings/cli/cli.types.ts +0 -357
  201. package/src/wirings/cli/command-parser.test.ts +0 -445
  202. package/src/wirings/cli/command-parser.ts +0 -504
  203. package/src/wirings/cli/define-cli-commands.ts +0 -24
  204. package/src/wirings/cli/index.ts +0 -19
  205. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  206. package/src/wirings/gateway/gateway-runner.ts +0 -411
  207. package/src/wirings/gateway/gateway.types.ts +0 -149
  208. package/src/wirings/gateway/index.ts +0 -13
  209. package/src/wirings/http/http-routes.test.ts +0 -322
  210. package/src/wirings/http/http-routes.ts +0 -198
  211. package/src/wirings/http/http-runner.test.ts +0 -144
  212. package/src/wirings/http/http-runner.ts +0 -563
  213. package/src/wirings/http/http.types.ts +0 -378
  214. package/src/wirings/http/index.ts +0 -25
  215. package/src/wirings/http/log-http-routes.ts +0 -22
  216. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  217. package/src/wirings/http/pikku-fetch-http-request.ts +0 -166
  218. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  219. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  220. package/src/wirings/http/routers/http-router.ts +0 -13
  221. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  222. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  223. package/src/wirings/mcp/index.ts +0 -27
  224. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  225. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  226. package/src/wirings/mcp/mcp-runner.ts +0 -305
  227. package/src/wirings/mcp/mcp.types.ts +0 -216
  228. package/src/wirings/node/index.ts +0 -2
  229. package/src/wirings/node/node.types.ts +0 -23
  230. package/src/wirings/oauth2/index.ts +0 -3
  231. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  232. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  233. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  234. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  235. package/src/wirings/queue/index.ts +0 -31
  236. package/src/wirings/queue/queue-runner.test.ts +0 -710
  237. package/src/wirings/queue/queue-runner.ts +0 -192
  238. package/src/wirings/queue/queue.types.ts +0 -189
  239. package/src/wirings/queue/register-queue-helper.ts +0 -60
  240. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  241. package/src/wirings/queue/validate-worker-config.ts +0 -116
  242. package/src/wirings/rpc/index.ts +0 -4
  243. package/src/wirings/rpc/rpc-runner.ts +0 -439
  244. package/src/wirings/rpc/rpc-types.ts +0 -51
  245. package/src/wirings/rpc/wire-addon.ts +0 -20
  246. package/src/wirings/scheduler/index.ts +0 -11
  247. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  248. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  249. package/src/wirings/scheduler/scheduler-runner.ts +0 -132
  250. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  251. package/src/wirings/secret/index.ts +0 -9
  252. package/src/wirings/secret/secret.types.ts +0 -32
  253. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  254. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  255. package/src/wirings/trigger/index.ts +0 -10
  256. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  257. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  258. package/src/wirings/trigger/trigger-runner.ts +0 -135
  259. package/src/wirings/trigger/trigger.types.ts +0 -178
  260. package/src/wirings/variable/index.ts +0 -8
  261. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  262. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  263. package/src/wirings/variable/variable.types.ts +0 -22
  264. package/src/wirings/workflow/dsl/index.ts +0 -31
  265. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  266. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  267. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  268. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  269. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  270. package/src/wirings/workflow/graph/index.ts +0 -14
  271. package/src/wirings/workflow/graph/template.test.ts +0 -49
  272. package/src/wirings/workflow/graph/template.ts +0 -42
  273. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  274. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  275. package/src/wirings/workflow/index.ts +0 -81
  276. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  277. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1165
  278. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  279. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  280. package/src/wirings/workflow/workflow.types.ts +0 -266
  281. package/tsconfig.json +0 -14
  282. package/tsconfig.tsbuildinfo +0 -1
@@ -1,378 +0,0 @@
1
- import type { SerializeOptions } from 'cookie'
2
- import type { StandardSchemaV1 } from '@standard-schema/spec'
3
- import type { PikkuError } from '../../errors/error-handler.js'
4
- import type {
5
- CorePikkuMiddleware,
6
- CommonWireMeta,
7
- } from '../../types/core.types.js'
8
- import type {
9
- CorePikkuFunction,
10
- CorePikkuFunctionSessionless,
11
- CorePikkuPermission,
12
- CorePermissionGroup,
13
- CorePikkuFunctionConfig,
14
- } from '../../function/functions.types.js'
15
-
16
- type ExtractHTTPWiringParams<S extends string> =
17
- S extends `${string}:${infer Param}/${infer Rest}`
18
- ? Param | ExtractHTTPWiringParams<`/${Rest}`>
19
- : S extends `${string}:${infer Param}`
20
- ? Param
21
- : never
22
-
23
- export type AssertHTTPWiringParams<In, HTTPWiring extends string> =
24
- ExtractHTTPWiringParams<HTTPWiring> extends keyof In
25
- ? unknown
26
- : [
27
- 'Error: HTTPWiring parameters',
28
- ExtractHTTPWiringParams<HTTPWiring>,
29
- 'not in',
30
- keyof In,
31
- ]
32
-
33
- export type RunHTTPWiringOptions = Partial<{
34
- skipUserSession: boolean
35
- respondWith404: boolean
36
- logWarningsForStatusCodes: number[]
37
- coerceDataFromSchema: boolean
38
- bubbleErrors: boolean
39
- generateRequestId: () => string
40
- }>
41
-
42
- /**
43
- * Represents the HTTP methods supported for API HTTP wirings.
44
- */
45
- export type HTTPMethod =
46
- | 'post'
47
- | 'get'
48
- | 'delete'
49
- | 'patch'
50
- | 'head'
51
- | 'put'
52
- | 'options'
53
-
54
- /**
55
- * Header schema type for request header validation.
56
- * Uses Standard Schema interface - works with Zod, Valibot, ArkType, Effect Schema, etc.
57
- */
58
- export type HTTPHeadersSchema = StandardSchemaV1<
59
- Record<string, string | string[] | undefined>
60
- >
61
-
62
- /**
63
- * Documentation config for OpenAPI generation
64
- */
65
- export type HTTPRouteDocsConfig = {
66
- description?: string
67
- response?: string
68
- errors?: Array<typeof PikkuError>
69
- tags?: string[]
70
- }
71
-
72
- /**
73
- * Common HTTP route configuration shared between wireHTTP and wireHTTPRoutes
74
- */
75
- export type HTTPRouteBaseConfig = {
76
- contentType?: 'xml' | 'json'
77
- timeout?: number
78
- tags?: string[]
79
- headers?: HTTPHeadersSchema
80
- docs?: HTTPRouteDocsConfig
81
- }
82
-
83
- /**
84
- * Represents an API HTTP wiring without a function, including metadata such as content type, route, and timeout settings.
85
- */
86
- export type CoreHTTPFunction = HTTPRouteBaseConfig & {
87
- route: string
88
- eventChannel?: false
89
- returnsJSON?: false
90
- }
91
- /**
92
- * Represents a http wire within Pikku, including a request and response.
93
- */
94
- export interface PikkuHTTP<In = unknown> {
95
- request?: PikkuHTTPRequest<In>
96
- response?: PikkuHTTPResponse
97
- }
98
-
99
- /**
100
- * Represents request headers as either a record or a function to get headers by name.
101
- */
102
- export type RequestHeaders =
103
- | Record<string, string | string[] | undefined>
104
- | ((headerName: string) => string | string[] | undefined)
105
-
106
- /**
107
- * Represents a query object for Pikku, where each key can be a string, a value, or an array of values.
108
- */
109
- export type PikkuQuery<T = Record<string, string | undefined>> = Record<
110
- string,
111
- string | T | null | Array<T | null>
112
- >
113
-
114
- /**
115
- * Represents a core API HTTP wiring, which can have different configurations depending on whether it requires authentication and permissions.
116
- *
117
- * @template In - The input type.
118
- * @template Out - The output type.
119
- * @template R - The route string type.
120
- * @template PikkuFunction - The API function type, defaults to `CorePikkuFunction`.
121
- * @template PikkuFunctionSessionless - The sessionless API function type, defaults to `CorePikkuFunctionSessionless`.
122
- * @template PikkuPermission - The permission function type, defaults to `CorePikkuPermission`.
123
- */
124
- export type CoreHTTPFunctionWiring<
125
- In,
126
- Out,
127
- R extends string,
128
- PikkuFunction extends CorePikkuFunction<
129
- In,
130
- Out,
131
- any,
132
- any,
133
- any
134
- > = CorePikkuFunction<In, Out>,
135
- PikkuFunctionSessionless extends CorePikkuFunctionSessionless<
136
- In,
137
- Out,
138
- any,
139
- any,
140
- any
141
- > = CorePikkuFunctionSessionless<In, Out>,
142
- PikkuPermission extends CorePikkuPermission<
143
- In,
144
- any,
145
- any
146
- > = CorePikkuPermission<In, any, any>,
147
- PikkuMiddleware extends CorePikkuMiddleware<
148
- any,
149
- any
150
- > = CorePikkuMiddleware<any>,
151
- > =
152
- | (CoreHTTPFunction & {
153
- route: R
154
- method: HTTPMethod
155
- func: CorePikkuFunctionConfig<
156
- PikkuFunction,
157
- PikkuPermission,
158
- PikkuMiddleware
159
- >
160
- permissions?: CorePermissionGroup<PikkuPermission>
161
- auth?: true
162
- middleware?: PikkuMiddleware[]
163
- sse?: undefined
164
- })
165
- | (CoreHTTPFunction & {
166
- route: R
167
- method: HTTPMethod
168
- func: CorePikkuFunctionConfig<
169
- PikkuFunctionSessionless,
170
- PikkuPermission,
171
- PikkuMiddleware
172
- >
173
- permissions?: undefined
174
- auth?: false
175
- middleware?: PikkuMiddleware[]
176
- sse?: undefined
177
- })
178
- | (CoreHTTPFunction & {
179
- route: R
180
- method: 'get'
181
- func: CorePikkuFunctionConfig<
182
- PikkuFunction,
183
- PikkuPermission,
184
- PikkuMiddleware
185
- >
186
- permissions?: CorePermissionGroup<PikkuPermission>
187
- auth?: true
188
- middleware?: PikkuMiddleware[]
189
- sse?: boolean
190
- })
191
- | (CoreHTTPFunction & {
192
- route: R
193
- method: 'get'
194
- func: CorePikkuFunctionConfig<
195
- PikkuFunctionSessionless,
196
- PikkuPermission,
197
- PikkuMiddleware
198
- >
199
- permissions?: undefined
200
- auth?: false
201
- middleware?: PikkuMiddleware[]
202
- sse?: boolean
203
- })
204
- | (CoreHTTPFunction & {
205
- route: R
206
- method: 'post'
207
- func: CorePikkuFunctionConfig<
208
- PikkuFunction,
209
- PikkuPermission,
210
- PikkuMiddleware
211
- >
212
- permissions?: CorePermissionGroup<PikkuPermission>
213
- auth?: true
214
- middleware?: PikkuMiddleware[]
215
- query?: Array<keyof In>
216
- sse?: undefined
217
- })
218
- | (CoreHTTPFunction & {
219
- route: R
220
- method: 'post'
221
- func: CorePikkuFunctionConfig<
222
- PikkuFunctionSessionless,
223
- PikkuPermission,
224
- PikkuMiddleware
225
- >
226
- permissions?: undefined
227
- auth?: false
228
- middleware?: PikkuMiddleware[]
229
- query?: Array<keyof In>
230
- sse?: undefined
231
- })
232
-
233
- /**
234
- * Represents the input types for HTTP wiring metadata, including parameters, query, and body types.
235
- */
236
- export type HTTPFunctionMetaInputTypes = {
237
- params?: string
238
- query?: string
239
- body?: string
240
- }
241
-
242
- /**
243
- * Represents metadata for a set of HTTP wirings, including HTTP wiring details, methods, input/output types, and documentation.
244
- */
245
- export type HTTPWiringMeta = CommonWireMeta & {
246
- route: string
247
- method: HTTPMethod
248
- params?: string[]
249
- query?: string[]
250
- inputTypes?: HTTPFunctionMetaInputTypes
251
- headersSchemaName?: string
252
- sse?: true
253
- groupBasePath?: string
254
- }
255
- export type HTTPWiringsMeta = Record<HTTPMethod, Record<string, HTTPWiringMeta>>
256
-
257
- export type HTTPFunctionsMeta = Array<{
258
- name: string
259
- inputs: string[] | null
260
- outputs: string[] | null
261
- }>
262
-
263
- export type HTTPWiringMiddleware = {
264
- route: string
265
- middleware: CorePikkuMiddleware[]
266
- }
267
-
268
- export interface PikkuHTTPRequest<In = unknown> {
269
- method(): HTTPMethod
270
- path(): string
271
- data(): Promise<In>
272
- json(): Promise<unknown>
273
- arrayBuffer(): Promise<ArrayBuffer>
274
- header(headerName: string): string | null
275
- cookie(name?: string): string | null
276
- params(): Partial<Record<string, string | string[]>>
277
- setParams(params: Record<string, string | string[] | undefined>): void
278
- query(): PikkuQuery
279
- }
280
-
281
- export interface PikkuHTTPResponse<Out = unknown> {
282
- status(code: number): this
283
- cookie(name: string, value: string | null, options: SerializeOptions): this
284
- header(name: string, value: string | string[]): this
285
- arrayBuffer(
286
- data:
287
- | ArrayBuffer
288
- | ArrayBufferView
289
- | Blob
290
- | string
291
- | FormData
292
- | URLSearchParams
293
- | ReadableStream
294
- ): this
295
- json(data: Out): this
296
- redirect(location: string, status?: number): this
297
- close?: () => void
298
- setMode?: (mode: 'stream') => void
299
- }
300
-
301
- /**
302
- * Single route configuration - supports all wireHTTP options
303
- */
304
- export type HTTPRouteConfig<
305
- PikkuFunction extends
306
- | CorePikkuFunction<any, any, any, any, any>
307
- | CorePikkuFunctionSessionless<any, any, any, any, any> =
308
- | CorePikkuFunction<any, any, any, any, any>
309
- | CorePikkuFunctionSessionless<any, any, any, any, any>,
310
- PikkuPermission extends CorePikkuPermission<
311
- any,
312
- any,
313
- any
314
- > = CorePikkuPermission<any>,
315
- PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
316
- any,
317
- any
318
- >,
319
- > = HTTPRouteBaseConfig & {
320
- // Required
321
- method: HTTPMethod
322
- route: string
323
- func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>
324
-
325
- // Auth & permissions
326
- auth?: boolean
327
- permissions?: CorePermissionGroup<PikkuPermission>
328
-
329
- // Middleware
330
- middleware?: PikkuMiddleware[]
331
-
332
- // SSE support
333
- sse?: boolean
334
- }
335
-
336
- /**
337
- * Group-level configuration applied to all routes
338
- */
339
- export type HTTPRoutesGroupConfig<
340
- PikkuPermission extends CorePikkuPermission<
341
- any,
342
- any,
343
- any
344
- > = CorePikkuPermission<any>,
345
- PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
346
- any,
347
- any
348
- >,
349
- > = {
350
- basePath?: string
351
- tags?: string[]
352
- auth?: boolean
353
- middleware?: PikkuMiddleware[]
354
- permissions?: CorePermissionGroup<PikkuPermission>
355
- }
356
-
357
- /**
358
- * Nested route map - allows hierarchical organization
359
- * Can contain individual routes, nested maps, or contracts with config
360
- */
361
- export type HTTPRouteMap = {
362
- [key: string]: HTTPRouteConfig | HTTPRouteMap | HTTPRouteContract
363
- }
364
-
365
- /**
366
- * A route contract with optional group config (returned by defineRoutes)
367
- */
368
- export type HTTPRouteContract<T extends HTTPRouteMap = HTTPRouteMap> =
369
- HTTPRoutesGroupConfig & {
370
- routes: T
371
- }
372
-
373
- /**
374
- * Full configuration for wireHTTPRoutes
375
- */
376
- export type WireHTTPRoutesConfig = HTTPRoutesGroupConfig & {
377
- routes: HTTPRouteMap | HTTPRouteConfig[]
378
- }
@@ -1,25 +0,0 @@
1
- export { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js'
2
- export { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js'
3
- export { logRoutes } from './log-http-routes.js'
4
-
5
- export {
6
- fetch,
7
- fetchData,
8
- wireHTTP,
9
- addHTTPMiddleware,
10
- addHTTPPermission,
11
- } from './http-runner.js'
12
-
13
- export { wireHTTPRoutes, defineHTTPRoutes } from './http-routes.js'
14
-
15
- export type {
16
- AssertHTTPWiringParams,
17
- CoreHTTPFunctionWiring,
18
- HTTPMethod,
19
- HTTPRouteBaseConfig,
20
- HTTPWiringsMeta,
21
- PikkuHTTPRequest,
22
- PikkuHTTPResponse,
23
- PikkuQuery,
24
- RunHTTPWiringOptions,
25
- } from './http.types.js'
@@ -1,22 +0,0 @@
1
- import { pikkuState } from '../../pikku-state.js'
2
- import type { Logger } from '../../services/index.js'
3
-
4
- /**
5
- * Logs all the loaded routes.
6
- * @param logger - A logger for logging information.
7
- */
8
- export const logRoutes = (logger: Logger) => {
9
- const routesByType = pikkuState(null, 'http', 'routes')
10
- if (routesByType.size === 0) {
11
- logger.info('No routes added')
12
- return
13
- }
14
-
15
- let routesMessage = 'Routes loaded:'
16
- routesByType.forEach((routes) => {
17
- routes.forEach((route) => {
18
- routesMessage += `\n\t- ${route.method.toUpperCase()} -> ${route.route}`
19
- })
20
- })
21
- logger.info(routesMessage)
22
- }
@@ -1,237 +0,0 @@
1
- import { test } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { PikkuFetchHTTPRequest } from './pikku-fetch-http-request'
4
-
5
- const createRequest = (method, url, body, headers = {}) => {
6
- return new Request(url, {
7
- method,
8
- headers,
9
- body:
10
- method === 'POST'
11
- ? typeof body === 'string'
12
- ? body
13
- : JSON.stringify(body)
14
- : undefined,
15
- })
16
- }
17
-
18
- test('method() returns lowercase HTTP method', () => {
19
- const req = createRequest('POST', 'http://localhost/test', null)
20
- const pikkuReq = new PikkuFetchHTTPRequest(req)
21
- assert.equal(pikkuReq.method(), 'post')
22
- })
23
-
24
- test('path() returns pathname only', () => {
25
- const req = createRequest('GET', 'http://localhost/foo/bar?x=1', null)
26
- const pikkuReq = new PikkuFetchHTTPRequest(req)
27
- assert.equal(pikkuReq.path(), '/foo/bar')
28
- })
29
-
30
- test('header() retrieves headers case-insensitively', () => {
31
- const req = createRequest('GET', 'http://localhost', null, {
32
- 'Content-Type': 'application/json',
33
- })
34
- const pikkuReq = new PikkuFetchHTTPRequest(req)
35
- assert.equal(pikkuReq.header('content-type'), 'application/json')
36
- })
37
-
38
- test('cookie() parses cookies correctly', () => {
39
- const req = createRequest('GET', 'http://localhost', null, {
40
- Cookie: 'session=abc; user=test',
41
- })
42
- const pikkuReq = new PikkuFetchHTTPRequest(req)
43
- assert.equal(pikkuReq.cookie('session'), 'abc')
44
- assert.equal(pikkuReq.cookie('user'), 'test')
45
- assert.equal(pikkuReq.cookie('missing'), null)
46
- })
47
-
48
- test('params() and setParams()', () => {
49
- const req = createRequest('GET', 'http://localhost', null)
50
- const pikkuReq = new PikkuFetchHTTPRequest(req)
51
- assert.deepEqual(pikkuReq.params(), {})
52
- pikkuReq.setParams({ id: '123' })
53
- assert.deepEqual(pikkuReq.params(), { id: '123' })
54
- })
55
-
56
- test('query() parses URL search params', () => {
57
- const req = createRequest('GET', 'http://localhost?x=1&y=2', null)
58
- const pikkuReq = new PikkuFetchHTTPRequest(req)
59
- assert.equal(pikkuReq.query().x, '1')
60
- assert.equal(pikkuReq.query().y, '2')
61
- })
62
-
63
- test('data() merges json body, query, and params', async () => {
64
- const req = createRequest(
65
- 'POST',
66
- 'http://localhost/test?a=5',
67
- { foo: 'bar' },
68
- { 'Content-Type': 'application/json' }
69
- )
70
- const pikkuReq = new PikkuFetchHTTPRequest(req)
71
- pikkuReq.setParams({ id: '22' })
72
- const result = await pikkuReq.data()
73
- assert.deepEqual(result, { id: '22', a: '5', foo: 'bar' })
74
- })
75
-
76
- test('data() wraps string JSON body under data key', async () => {
77
- const req = createRequest('POST', 'http://localhost', '"hello"', {
78
- 'Content-Type': 'application/json',
79
- })
80
- const pikkuReq = new PikkuFetchHTTPRequest(req)
81
- const result = await pikkuReq.data()
82
- assert.deepEqual(result, { data: 'hello' })
83
- })
84
-
85
- test('data() handles text/plain correctly', async () => {
86
- const req = new Request('http://localhost', {
87
- method: 'POST',
88
- headers: { 'Content-Type': 'text/plain' },
89
- body: 'hello world',
90
- })
91
- const pikkuReq = new PikkuFetchHTTPRequest(req)
92
- const result = await pikkuReq.data()
93
- assert.deepEqual(result, { data: 'hello world' })
94
- })
95
-
96
- test('data() returns arrayBuffer for unknown content-type', async () => {
97
- const buffer = Buffer.from('raw')
98
- const req = new Request('http://localhost', {
99
- method: 'POST',
100
- headers: { 'Content-Type': 'application/octet-stream' },
101
- body: buffer,
102
- })
103
- const pikkuReq = new PikkuFetchHTTPRequest<any>(req)
104
- const result = await pikkuReq.data()
105
- assert(result.data instanceof ArrayBuffer)
106
- const str = Buffer.from(result.data).toString()
107
- assert.equal(str, 'raw')
108
- })
109
-
110
- test('data() handles invalid JSON safely', async () => {
111
- const req = new Request('http://localhost', {
112
- method: 'POST',
113
- headers: { 'Content-Type': 'application/json' },
114
- body: 'not-json',
115
- })
116
- const pikkuReq = new PikkuFetchHTTPRequest(req)
117
- try {
118
- await pikkuReq.data()
119
- assert(false, 'Should have thrown')
120
- } catch (e) {
121
- assert(e.message.includes('Error parsing body'))
122
- }
123
- })
124
-
125
- test('data() parses application/x-www-form-urlencoded correctly', async () => {
126
- const formBody = 'name=Yasser&age=35&active=true'
127
-
128
- const req = new Request('http://localhost/form?ref=abc', {
129
- method: 'POST',
130
- headers: {
131
- 'Content-Type': 'application/x-www-form-urlencoded',
132
- },
133
- body: formBody,
134
- })
135
-
136
- const pikkuReq = new PikkuFetchHTTPRequest(req)
137
- pikkuReq.setParams({ userId: '999' })
138
-
139
- const result = await pikkuReq.data()
140
-
141
- assert.deepEqual(result, {
142
- userId: '999',
143
- ref: 'abc',
144
- name: 'Yasser',
145
- age: '35',
146
- active: 'true',
147
- })
148
- })
149
-
150
- // --- Compatible types
151
-
152
- test('data() treats "123" and 123 as equivalent', async () => {
153
- const req = createRequest(
154
- 'POST',
155
- 'http://localhost?id=123',
156
- { id: 123 },
157
- {
158
- 'Content-Type': 'application/json',
159
- }
160
- )
161
-
162
- const r = new PikkuFetchHTTPRequest(req)
163
- r.setParams({ id: '123' }) // All match
164
- const result = await r.data()
165
- assert.deepEqual(result, { id: '123' })
166
- })
167
-
168
- test('data() treats "true" and true as equivalent', async () => {
169
- const req = createRequest(
170
- 'POST',
171
- 'http://localhost?flag=true',
172
- { flag: true },
173
- {
174
- 'Content-Type': 'application/json',
175
- }
176
- )
177
-
178
- const r = new PikkuFetchHTTPRequest(req)
179
- r.setParams({ flag: 'true' }) // All match
180
- const result = await r.data()
181
- assert.deepEqual(result, { flag: 'true' })
182
- })
183
-
184
- // --- Conflicts
185
-
186
- test('data() throws on conflicting values', async () => {
187
- const req = createRequest(
188
- 'POST',
189
- 'http://localhost?foo=123',
190
- { foo: 456 },
191
- {
192
- 'Content-Type': 'application/json',
193
- }
194
- )
195
-
196
- const r = new PikkuFetchHTTPRequest(req)
197
- r.setParams({ foo: '123' })
198
-
199
- await assert.rejects(async () => await r.data(), {
200
- message: 'Conflicting values for key "foo": "123" vs "456"',
201
- })
202
- })
203
-
204
- test('data() throws on boolean conflict', async () => {
205
- const req = createRequest(
206
- 'POST',
207
- 'http://localhost?debug=false',
208
- { debug: true },
209
- {
210
- 'Content-Type': 'application/json',
211
- }
212
- )
213
-
214
- const r = new PikkuFetchHTTPRequest(req)
215
- r.setParams({})
216
-
217
- await assert.rejects(async () => await r.data(), {
218
- message: 'Conflicting values for key "debug": "false" vs "true"',
219
- })
220
- })
221
-
222
- // --- Safe fallback: only one source
223
-
224
- test('data() works when only body has values', async () => {
225
- const req = createRequest(
226
- 'POST',
227
- 'http://localhost',
228
- { test: 'ok' },
229
- {
230
- 'Content-Type': 'application/json',
231
- }
232
- )
233
-
234
- const r = new PikkuFetchHTTPRequest(req)
235
- const result = await r.data()
236
- assert.deepEqual(result, { test: 'ok' })
237
- })