@pikku/skills 0.12.47 → 0.12.50

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.
@@ -107,17 +107,30 @@ subscribe to its events as `<source>:<event>`:
107
107
  - The route is `POST /webhooks/<name>` unless `method`/`route` say otherwise.
108
108
  `method` may be a list, e.g. `['get', 'post']` for a provider that verifies
109
109
  the URL with a GET and delivers events with a POST, or `['head', 'post']`
110
- for one that checks the URL with a HEAD.
111
- It needs no session.
110
+ for one that checks the URL with a HEAD. A HEAD is answered with a `200`
111
+ before `verify` or `receive` run. It needs no session.
112
112
  - `events` maps each event name to a schema. An event that fails its schema is
113
113
  logged and dropped; so is one no `wireTrigger` listens for. Both still get a
114
114
  `200`, so the provider does not retry forever.
115
- - `receive(services, { body, headers, method, url, query })` gets the **raw
116
- bytes** and only parses them: it returns `{ events: [{ name, id?, data }] }`,
117
- or `{ respond: { status, body } }` for a handshake. Throwing
115
+ - `receive(services, { body, headers, method, url, query }, { http })` gets the
116
+ **raw bytes** and only parses them: it returns `{ events: [{ name, id?, data }] }`.
117
+ A handshake returns nothing and answers through `http.response`
118
+ (`http.response.header('x-hook-secret', secret)`,
119
+ `http.response.json({ challenge })`), which is sent only then. Throwing
118
120
  rejects the request with the error's status (`UnauthorizedError` → 401).
119
121
  Omitted, the JSON body becomes one event dispatched to a trigger named just
120
122
  `<source>`.
123
+ - A named `receive` is declared with `pikkuWebhookReceive` from `#pikku/trigger`
124
+ (`#pikku/addon/trigger` in an addon), never `pikkuSessionlessFunc`: it is
125
+ public, typed to the request, and never callable as an RPC. The inspector
126
+ rejects any other wrapper. `parseJson` from `#pikku/utils`
127
+ (`#pikku/addon/utils`) parses the bytes and answers a body that is not JSON
128
+ with a 400:
129
+
130
+ ```ts snippet:pikkuWebhookReceive
131
+
132
+ ```
133
+
121
134
  - Every accepted event is queued on `pikku-incoming-webhooks` and run by a
122
135
  generated worker, so the provider is answered quickly and a failing trigger is
123
136
  retried by the queue. This needs a `queueService` and an
@@ -150,7 +163,7 @@ subscribe to its events as `<source>:<event>`:
150
163
  `timingSafeStringEqual` in `@pikku/core/hmac`.
151
164
 
152
165
  A request with a body that fails is refused with a 401. A bodiless request
153
- that fails (a HEAD probe, a validation token in the query) still reaches
166
+ that fails (a validation token in the query) still reaches
154
167
  `receive` so it can answer the handshake, but any events it returns are
155
168
  refused. A handshake that hands over the secret (Asana) stores it with
156
169
  `credentialService.set` under the same credential name.