@npora/request 1.9.0 → 1.9.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.
- package/README.md +4 -0
- package/dist/index.cjs +10 -3
- package/dist/index.js +10 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -126,6 +126,8 @@ api.patch(url, config)
|
|
|
126
126
|
api.delete(url, config)
|
|
127
127
|
api.head(url, config)
|
|
128
128
|
api.options(url, config)
|
|
129
|
+
api.sse(url, config)
|
|
130
|
+
api.ndjson(url, config)
|
|
129
131
|
|
|
130
132
|
api.getResponse(url, config)
|
|
131
133
|
api.postResponse(url, config)
|
|
@@ -134,6 +136,8 @@ api.patchResponse(url, config)
|
|
|
134
136
|
api.deleteResponse(url, config)
|
|
135
137
|
api.headResponse(url, config)
|
|
136
138
|
api.optionsResponse(url, config)
|
|
139
|
+
api.sseResponse(url, config)
|
|
140
|
+
api.ndjsonResponse(url, config)
|
|
137
141
|
```
|
|
138
142
|
|
|
139
143
|
## Plugins
|
package/dist/index.cjs
CHANGED
|
@@ -592,11 +592,18 @@ function copyResponseMetadata(source, target) {
|
|
|
592
592
|
}
|
|
593
593
|
function detectResponseType(response) {
|
|
594
594
|
const contentType = response.headers.get("content-type") ?? "";
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
if (
|
|
595
|
+
const parameterStart = contentType.indexOf(";");
|
|
596
|
+
const mediaType = contentType.slice(0, parameterStart === -1 ? void 0 : parameterStart).trim().toLowerCase();
|
|
597
|
+
if (mediaType === "text/event-stream") return "sse";
|
|
598
|
+
if (mediaType === "application/x-ndjson" || mediaType === "application/ndjson" || hasStructuredSuffix(mediaType, "+ndjson")) return "ndjson";
|
|
599
|
+
if (mediaType === "application/json" || hasStructuredSuffix(mediaType, "+json")) return "json";
|
|
598
600
|
return "text";
|
|
599
601
|
}
|
|
602
|
+
function hasStructuredSuffix(mediaType, suffix) {
|
|
603
|
+
const slashIndex = mediaType.indexOf("/");
|
|
604
|
+
const suffixStart = mediaType.length - suffix.length;
|
|
605
|
+
return slashIndex > 0 && suffixStart > slashIndex + 1 && mediaType.endsWith(suffix);
|
|
606
|
+
}
|
|
600
607
|
//#endregion
|
|
601
608
|
//#region src/utils/validateRequestConfig.ts
|
|
602
609
|
const BODY_FIELDS = [
|
package/dist/index.js
CHANGED
|
@@ -591,11 +591,18 @@ function copyResponseMetadata(source, target) {
|
|
|
591
591
|
}
|
|
592
592
|
function detectResponseType(response) {
|
|
593
593
|
const contentType = response.headers.get("content-type") ?? "";
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (
|
|
594
|
+
const parameterStart = contentType.indexOf(";");
|
|
595
|
+
const mediaType = contentType.slice(0, parameterStart === -1 ? void 0 : parameterStart).trim().toLowerCase();
|
|
596
|
+
if (mediaType === "text/event-stream") return "sse";
|
|
597
|
+
if (mediaType === "application/x-ndjson" || mediaType === "application/ndjson" || hasStructuredSuffix(mediaType, "+ndjson")) return "ndjson";
|
|
598
|
+
if (mediaType === "application/json" || hasStructuredSuffix(mediaType, "+json")) return "json";
|
|
597
599
|
return "text";
|
|
598
600
|
}
|
|
601
|
+
function hasStructuredSuffix(mediaType, suffix) {
|
|
602
|
+
const slashIndex = mediaType.indexOf("/");
|
|
603
|
+
const suffixStart = mediaType.length - suffix.length;
|
|
604
|
+
return slashIndex > 0 && suffixStart > slashIndex + 1 && mediaType.endsWith(suffix);
|
|
605
|
+
}
|
|
599
606
|
//#endregion
|
|
600
607
|
//#region src/utils/validateRequestConfig.ts
|
|
601
608
|
const BODY_FIELDS = [
|