lumen-framework 3.0.1 → 3.0.3
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 +1 -1
- package/dist/cli.cjs +2 -1
- package/dist/cli.cjs.map +2 -2
- package/dist/index.js +62 -15
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +62 -15
- package/dist/index.mjs.map +4 -4
- package/dist/types/packages/jsonapi/errors/not-acceptable-error.d.ts +1 -1
- package/dist/types/packages/jsonapi/index.d.ts +3 -1
- package/dist/types/packages/jsonapi/utils/has-media-type-params.d.ts +6 -0
- package/dist/types/packages/jsonapi/utils/is-jsonapi.d.ts +2 -0
- package/dist/types/packages/jsonapi/utils/media-type.d.ts +19 -0
- package/dist/types/packages/server/utils/validate-accept.d.ts +5 -1
- package/dist/types/packages/server/utils/validate-content-type.d.ts +4 -0
- package/package.json +1 -1
- package/dist/types/packages/jsonapi/utils/has-media-type.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -3728,10 +3728,11 @@ var MIME_TYPE = "application/vnd.api+json";
|
|
|
3728
3728
|
|
|
3729
3729
|
// src/packages/jsonapi/errors/not-acceptable-error.ts
|
|
3730
3730
|
var NotAcceptableError = class extends TypeError {
|
|
3731
|
-
constructor(
|
|
3731
|
+
constructor(accept) {
|
|
3732
3732
|
super(line`
|
|
3733
|
-
|
|
3734
|
-
|
|
3733
|
+
Every '${MIME_TYPE}' in Accept: '${accept}' has media type parameters,
|
|
3734
|
+
which are not supported. Try your request again with '${MIME_TYPE}'
|
|
3735
|
+
without parameters.
|
|
3735
3736
|
`);
|
|
3736
3737
|
}
|
|
3737
3738
|
};
|
|
@@ -3741,8 +3742,9 @@ var not_acceptable_error_default = createServerError(NotAcceptableError, 406);
|
|
|
3741
3742
|
var UnsupportedMediaTypeError = class extends TypeError {
|
|
3742
3743
|
constructor(contentType) {
|
|
3743
3744
|
super(line`
|
|
3744
|
-
Media type parameters
|
|
3745
|
-
|
|
3745
|
+
Media type parameters are not supported in Content-Type:
|
|
3746
|
+
'${contentType}'. Try your request again with Content-Type:
|
|
3747
|
+
'${MIME_TYPE}' without parameters.
|
|
3746
3748
|
`);
|
|
3747
3749
|
}
|
|
3748
3750
|
};
|
|
@@ -3757,17 +3759,59 @@ var InvalidContentTypeError = class extends TypeError {
|
|
|
3757
3759
|
`);
|
|
3758
3760
|
}
|
|
3759
3761
|
};
|
|
3760
|
-
var invalid_content_type_error_default = createServerError(InvalidContentTypeError,
|
|
3762
|
+
var invalid_content_type_error_default = createServerError(InvalidContentTypeError, 415);
|
|
3763
|
+
|
|
3764
|
+
// src/packages/jsonapi/utils/media-type.ts
|
|
3765
|
+
var QUALITY = /^q\s*=/i;
|
|
3766
|
+
function splitUnquoted(value, delimiter) {
|
|
3767
|
+
const parts = [];
|
|
3768
|
+
let current = "";
|
|
3769
|
+
let quoted = false;
|
|
3770
|
+
let escaped = false;
|
|
3771
|
+
for (const char of value) {
|
|
3772
|
+
if (escaped) {
|
|
3773
|
+
escaped = false;
|
|
3774
|
+
} else if (quoted && char === "\\") {
|
|
3775
|
+
escaped = true;
|
|
3776
|
+
} else if (char === '"') {
|
|
3777
|
+
quoted = !quoted;
|
|
3778
|
+
} else if (!quoted && char === delimiter) {
|
|
3779
|
+
parts.push(current);
|
|
3780
|
+
current = "";
|
|
3781
|
+
continue;
|
|
3782
|
+
}
|
|
3783
|
+
current += char;
|
|
3784
|
+
}
|
|
3785
|
+
return [...parts, current];
|
|
3786
|
+
}
|
|
3787
|
+
function parseMediaType(value) {
|
|
3788
|
+
const [type = "", ...params] = splitUnquoted(value, ";").map(
|
|
3789
|
+
(part) => part.trim()
|
|
3790
|
+
);
|
|
3791
|
+
return {
|
|
3792
|
+
type: type.toLowerCase(),
|
|
3793
|
+
params: params.filter(Boolean)
|
|
3794
|
+
};
|
|
3795
|
+
}
|
|
3796
|
+
function parseAccept(value) {
|
|
3797
|
+
return splitUnquoted(value, ",").map((range) => {
|
|
3798
|
+
const { type, params } = parseMediaType(range);
|
|
3799
|
+
const quality = params.findIndex((param) => QUALITY.test(param));
|
|
3800
|
+
return {
|
|
3801
|
+
type,
|
|
3802
|
+
params: quality === -1 ? params : params.slice(0, quality)
|
|
3803
|
+
};
|
|
3804
|
+
}).filter(({ type }) => type.length > 0);
|
|
3805
|
+
}
|
|
3761
3806
|
|
|
3762
3807
|
// src/packages/jsonapi/utils/is-jsonapi.ts
|
|
3763
3808
|
function isJSONAPI(value) {
|
|
3764
|
-
return value.
|
|
3809
|
+
return parseMediaType(value).type === MIME_TYPE;
|
|
3765
3810
|
}
|
|
3766
3811
|
|
|
3767
|
-
// src/packages/jsonapi/utils/has-media-type.ts
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
return PATTERN2.test(value);
|
|
3812
|
+
// src/packages/jsonapi/utils/has-media-type-params.ts
|
|
3813
|
+
function hasMediaTypeParams(value) {
|
|
3814
|
+
return parseMediaType(value).params.length > 0;
|
|
3771
3815
|
}
|
|
3772
3816
|
|
|
3773
3817
|
// src/utils/env.ts
|
|
@@ -3868,9 +3912,12 @@ function createResponder(req, res) {
|
|
|
3868
3912
|
}
|
|
3869
3913
|
|
|
3870
3914
|
// src/packages/server/utils/validate-accept.ts
|
|
3871
|
-
function validateAccept(
|
|
3872
|
-
if (
|
|
3873
|
-
|
|
3915
|
+
function validateAccept(accept) {
|
|
3916
|
+
if (accept) {
|
|
3917
|
+
const ranges = parseAccept(accept).filter(({ type }) => type === MIME_TYPE);
|
|
3918
|
+
if (ranges.length && ranges.every(({ params }) => params.length)) {
|
|
3919
|
+
throw new not_acceptable_error_default(accept);
|
|
3920
|
+
}
|
|
3874
3921
|
}
|
|
3875
3922
|
return true;
|
|
3876
3923
|
}
|
|
@@ -3879,7 +3926,7 @@ function validateAccept(contentType) {
|
|
|
3879
3926
|
function validateContentType(contentType) {
|
|
3880
3927
|
if (!contentType || !isJSONAPI(contentType)) {
|
|
3881
3928
|
throw new invalid_content_type_error_default(contentType);
|
|
3882
|
-
} else if (
|
|
3929
|
+
} else if (hasMediaTypeParams(contentType)) {
|
|
3883
3930
|
throw new unsupported_media_type_error_default(contentType);
|
|
3884
3931
|
}
|
|
3885
3932
|
return true;
|