@junoflow/testkit 0.3.0 → 0.6.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junoflow/testkit",
3
- "version": "0.3.0",
3
+ "version": "0.6.0",
4
4
  "description": "Test harness for Juno integrations",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/index.d.ts CHANGED
@@ -94,6 +94,7 @@ export interface WebhookRequestInit {
94
94
  /** A string is sent as-is; anything else is JSON.stringify'd. */
95
95
  body?: unknown;
96
96
  url?: string;
97
+ subpath?: string;
97
98
  }
98
99
 
99
100
  export interface WebhookResult {
package/src/index.js CHANGED
@@ -506,16 +506,35 @@ function buildWebhookRequest(request) {
506
506
  typeof request.body === 'string'
507
507
  ? request.body
508
508
  : JSON.stringify(request.body ?? '');
509
+ const headers = request.headers ?? {};
509
510
  return {
510
511
  method: (request.method ?? 'POST').toUpperCase(),
511
- headers: request.headers ?? {},
512
+ headers,
512
513
  query: request.query ?? {},
513
514
  body,
514
515
  json: parseJSONOrNull(body),
515
516
  url: request.url ?? '/',
517
+ subpath: request.subpath ?? '',
518
+ form: parseFormOrNull(headers, body),
516
519
  };
517
520
  }
518
521
 
522
+ // The host's rule: lower-cased content-type, media type
523
+ // application/x-www-form-urlencoded (a charset parameter is ignored), first
524
+ // value per key — else null.
525
+ function parseFormOrNull(headers, body) {
526
+ const contentType = (headers['content-type'] ?? headers['Content-Type'] ?? '')
527
+ .toLowerCase()
528
+ .split(';')[0]
529
+ .trim();
530
+ if (contentType !== 'application/x-www-form-urlencoded') return null;
531
+ const form = {};
532
+ for (const [key, value] of new URLSearchParams(body)) {
533
+ if (!(key in form)) form[key] = value;
534
+ }
535
+ return form;
536
+ }
537
+
519
538
  // The host's rule (cmd/control-plane readWebhookRequest): whatever parses is
520
539
  // parsed, whatever does not is null — content-type is not consulted.
521
540
  function parseJSONOrNull(body) {