@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 +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +20 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
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
|
|
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) {
|