@kevisual/router 0.0.38 → 0.0.40
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/dist/router-browser.d.ts +3 -3
- package/dist/router-browser.js +2 -5
- package/dist/router-sign.js +1 -3
- package/dist/router-simple.d.ts +2 -2
- package/dist/router.d.ts +98 -4
- package/dist/router.js +243 -369
- package/package.json +6 -8
- package/src/result/error.ts +2 -5
- package/src/server/cookie.ts +543 -0
- package/src/server/server.ts +1 -1
package/dist/router.js
CHANGED
|
@@ -78,11 +78,8 @@ class CustomError extends Error {
|
|
|
78
78
|
* @param err
|
|
79
79
|
* @returns
|
|
80
80
|
*/
|
|
81
|
-
static isError(
|
|
82
|
-
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
81
|
+
static isError(error) {
|
|
82
|
+
return error instanceof CustomError || (typeof error === 'object' && error !== null && 'code' in error);
|
|
86
83
|
}
|
|
87
84
|
parse(e) {
|
|
88
85
|
if (e) {
|
|
@@ -906,370 +903,243 @@ const handleServer = async (req, res) => {
|
|
|
906
903
|
return data;
|
|
907
904
|
};
|
|
908
905
|
|
|
909
|
-
|
|
910
|
-
|
|
906
|
+
/**
|
|
907
|
+
* RegExp to match cookie-name in RFC 6265 sec 4.1.1
|
|
908
|
+
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
|
|
909
|
+
* which has been replaced by the token definition in RFC 7230 appendix B.
|
|
910
|
+
*
|
|
911
|
+
* cookie-name = token
|
|
912
|
+
* token = 1*tchar
|
|
913
|
+
* tchar = "!" / "#" / "$" / "%" / "&" / "'" /
|
|
914
|
+
* "*" / "+" / "-" / "." / "^" / "_" /
|
|
915
|
+
* "`" / "|" / "~" / DIGIT / ALPHA
|
|
916
|
+
*
|
|
917
|
+
* Note: Allowing more characters - https://github.com/jshttp/cookie/issues/191
|
|
918
|
+
* Allow same range as cookie value, except `=`, which delimits end of name.
|
|
919
|
+
*/
|
|
920
|
+
const cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
|
|
921
|
+
/**
|
|
922
|
+
* RegExp to match cookie-value in RFC 6265 sec 4.1.1
|
|
923
|
+
*
|
|
924
|
+
* cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
|
|
925
|
+
* cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
|
|
926
|
+
* ; US-ASCII characters excluding CTLs,
|
|
927
|
+
* ; whitespace DQUOTE, comma, semicolon,
|
|
928
|
+
* ; and backslash
|
|
929
|
+
*
|
|
930
|
+
* Allowing more characters: https://github.com/jshttp/cookie/issues/191
|
|
931
|
+
* Comma, backslash, and DQUOTE are not part of the parsing algorithm.
|
|
932
|
+
*/
|
|
933
|
+
const cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
|
|
934
|
+
/**
|
|
935
|
+
* RegExp to match domain-value in RFC 6265 sec 4.1.1
|
|
936
|
+
*
|
|
937
|
+
* domain-value = <subdomain>
|
|
938
|
+
* ; defined in [RFC1034], Section 3.5, as
|
|
939
|
+
* ; enhanced by [RFC1123], Section 2.1
|
|
940
|
+
* <subdomain> = <label> | <subdomain> "." <label>
|
|
941
|
+
* <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
|
|
942
|
+
* Labels must be 63 characters or less.
|
|
943
|
+
* 'let-dig' not 'letter' in the first char, per RFC1123
|
|
944
|
+
* <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
|
|
945
|
+
* <let-dig-hyp> = <let-dig> | "-"
|
|
946
|
+
* <let-dig> = <letter> | <digit>
|
|
947
|
+
* <letter> = any one of the 52 alphabetic characters A through Z in
|
|
948
|
+
* upper case and a through z in lower case
|
|
949
|
+
* <digit> = any one of the ten digits 0 through 9
|
|
950
|
+
*
|
|
951
|
+
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
|
|
952
|
+
*
|
|
953
|
+
* > (Note that a leading %x2E ("."), if present, is ignored even though that
|
|
954
|
+
* character is not permitted, but a trailing %x2E ("."), if present, will
|
|
955
|
+
* cause the user agent to ignore the attribute.)
|
|
956
|
+
*/
|
|
957
|
+
const domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
958
|
+
/**
|
|
959
|
+
* RegExp to match path-value in RFC 6265 sec 4.1.1
|
|
960
|
+
*
|
|
961
|
+
* path-value = <any CHAR except CTLs or ";">
|
|
962
|
+
* CHAR = %x01-7F
|
|
963
|
+
* ; defined in RFC 5234 appendix B.1
|
|
964
|
+
*/
|
|
965
|
+
const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
966
|
+
const __toString = Object.prototype.toString;
|
|
967
|
+
const NullObject = /* @__PURE__ */ (() => {
|
|
968
|
+
const C = function () { };
|
|
969
|
+
C.prototype = Object.create(null);
|
|
970
|
+
return C;
|
|
971
|
+
})();
|
|
972
|
+
/**
|
|
973
|
+
* Parse a `Cookie` header.
|
|
974
|
+
*
|
|
975
|
+
* Parse the given cookie header string into an object
|
|
976
|
+
* The object has the various cookies as keys(names) => values
|
|
977
|
+
*/
|
|
978
|
+
function parseCookie(str, options) {
|
|
979
|
+
const obj = new NullObject();
|
|
980
|
+
const len = str.length;
|
|
981
|
+
// RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
|
|
982
|
+
if (len < 2)
|
|
983
|
+
return obj;
|
|
984
|
+
const dec = decode$1;
|
|
985
|
+
let index = 0;
|
|
986
|
+
do {
|
|
987
|
+
const eqIdx = eqIndex(str, index, len);
|
|
988
|
+
if (eqIdx === -1)
|
|
989
|
+
break; // No more cookie pairs.
|
|
990
|
+
const endIdx = endIndex(str, index, len);
|
|
991
|
+
if (eqIdx > endIdx) {
|
|
992
|
+
// backtrack on prior semicolon
|
|
993
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
994
|
+
continue;
|
|
995
|
+
}
|
|
996
|
+
const key = valueSlice(str, index, eqIdx);
|
|
997
|
+
// only assign once
|
|
998
|
+
if (obj[key] === undefined) {
|
|
999
|
+
obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
|
|
1000
|
+
}
|
|
1001
|
+
index = endIdx + 1;
|
|
1002
|
+
} while (index < len);
|
|
1003
|
+
return obj;
|
|
911
1004
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
cookieStrings.push(`${name}=${value}`);
|
|
1050
|
-
}
|
|
1051
|
-
return cookieStrings.join("; ");
|
|
1052
|
-
}
|
|
1053
|
-
function stringifySetCookie(_name, _val, _opts) {
|
|
1054
|
-
const cookie = typeof _name === "object"
|
|
1055
|
-
? _name
|
|
1056
|
-
: { ..._opts, name: _name, value: String(_val) };
|
|
1057
|
-
const options = typeof _val === "object" ? _val : _opts;
|
|
1058
|
-
const enc = options?.encode || encodeURIComponent;
|
|
1059
|
-
if (!cookieNameRegExp.test(cookie.name)) {
|
|
1060
|
-
throw new TypeError(`argument name is invalid: ${cookie.name}`);
|
|
1061
|
-
}
|
|
1062
|
-
const value = cookie.value ? enc(cookie.value) : "";
|
|
1063
|
-
if (!cookieValueRegExp.test(value)) {
|
|
1064
|
-
throw new TypeError(`argument val is invalid: ${cookie.value}`);
|
|
1065
|
-
}
|
|
1066
|
-
let str = cookie.name + "=" + value;
|
|
1067
|
-
if (cookie.maxAge !== undefined) {
|
|
1068
|
-
if (!Number.isInteger(cookie.maxAge)) {
|
|
1069
|
-
throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
|
|
1070
|
-
}
|
|
1071
|
-
str += "; Max-Age=" + cookie.maxAge;
|
|
1072
|
-
}
|
|
1073
|
-
if (cookie.domain) {
|
|
1074
|
-
if (!domainValueRegExp.test(cookie.domain)) {
|
|
1075
|
-
throw new TypeError(`option domain is invalid: ${cookie.domain}`);
|
|
1076
|
-
}
|
|
1077
|
-
str += "; Domain=" + cookie.domain;
|
|
1078
|
-
}
|
|
1079
|
-
if (cookie.path) {
|
|
1080
|
-
if (!pathValueRegExp.test(cookie.path)) {
|
|
1081
|
-
throw new TypeError(`option path is invalid: ${cookie.path}`);
|
|
1082
|
-
}
|
|
1083
|
-
str += "; Path=" + cookie.path;
|
|
1084
|
-
}
|
|
1085
|
-
if (cookie.expires) {
|
|
1086
|
-
if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
|
|
1087
|
-
throw new TypeError(`option expires is invalid: ${cookie.expires}`);
|
|
1088
|
-
}
|
|
1089
|
-
str += "; Expires=" + cookie.expires.toUTCString();
|
|
1090
|
-
}
|
|
1091
|
-
if (cookie.httpOnly) {
|
|
1092
|
-
str += "; HttpOnly";
|
|
1093
|
-
}
|
|
1094
|
-
if (cookie.secure) {
|
|
1095
|
-
str += "; Secure";
|
|
1096
|
-
}
|
|
1097
|
-
if (cookie.partitioned) {
|
|
1098
|
-
str += "; Partitioned";
|
|
1099
|
-
}
|
|
1100
|
-
if (cookie.priority) {
|
|
1101
|
-
const priority = typeof cookie.priority === "string"
|
|
1102
|
-
? cookie.priority.toLowerCase()
|
|
1103
|
-
: undefined;
|
|
1104
|
-
switch (priority) {
|
|
1105
|
-
case "low":
|
|
1106
|
-
str += "; Priority=Low";
|
|
1107
|
-
break;
|
|
1108
|
-
case "medium":
|
|
1109
|
-
str += "; Priority=Medium";
|
|
1110
|
-
break;
|
|
1111
|
-
case "high":
|
|
1112
|
-
str += "; Priority=High";
|
|
1113
|
-
break;
|
|
1114
|
-
default:
|
|
1115
|
-
throw new TypeError(`option priority is invalid: ${cookie.priority}`);
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
if (cookie.sameSite) {
|
|
1119
|
-
const sameSite = typeof cookie.sameSite === "string"
|
|
1120
|
-
? cookie.sameSite.toLowerCase()
|
|
1121
|
-
: cookie.sameSite;
|
|
1122
|
-
switch (sameSite) {
|
|
1123
|
-
case true:
|
|
1124
|
-
case "strict":
|
|
1125
|
-
str += "; SameSite=Strict";
|
|
1126
|
-
break;
|
|
1127
|
-
case "lax":
|
|
1128
|
-
str += "; SameSite=Lax";
|
|
1129
|
-
break;
|
|
1130
|
-
case "none":
|
|
1131
|
-
str += "; SameSite=None";
|
|
1132
|
-
break;
|
|
1133
|
-
default:
|
|
1134
|
-
throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
return str;
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* Deserialize a `Set-Cookie` header into an object.
|
|
1141
|
-
*
|
|
1142
|
-
* deserialize('foo=bar; httpOnly')
|
|
1143
|
-
* => { name: 'foo', value: 'bar', httpOnly: true }
|
|
1144
|
-
*/
|
|
1145
|
-
function parseSetCookie(str, options) {
|
|
1146
|
-
const dec = options?.decode || decode;
|
|
1147
|
-
const len = str.length;
|
|
1148
|
-
const endIdx = endIndex(str, 0, len);
|
|
1149
|
-
const eqIdx = eqIndex(str, 0, endIdx);
|
|
1150
|
-
const setCookie = eqIdx === -1
|
|
1151
|
-
? { name: "", value: dec(valueSlice(str, 0, endIdx)) }
|
|
1152
|
-
: {
|
|
1153
|
-
name: valueSlice(str, 0, eqIdx),
|
|
1154
|
-
value: dec(valueSlice(str, eqIdx + 1, endIdx)),
|
|
1155
|
-
};
|
|
1156
|
-
let index = endIdx + 1;
|
|
1157
|
-
while (index < len) {
|
|
1158
|
-
const endIdx = endIndex(str, index, len);
|
|
1159
|
-
const eqIdx = eqIndex(str, index, endIdx);
|
|
1160
|
-
const attr = eqIdx === -1
|
|
1161
|
-
? valueSlice(str, index, endIdx)
|
|
1162
|
-
: valueSlice(str, index, eqIdx);
|
|
1163
|
-
const val = eqIdx === -1 ? undefined : valueSlice(str, eqIdx + 1, endIdx);
|
|
1164
|
-
switch (attr.toLowerCase()) {
|
|
1165
|
-
case "httponly":
|
|
1166
|
-
setCookie.httpOnly = true;
|
|
1167
|
-
break;
|
|
1168
|
-
case "secure":
|
|
1169
|
-
setCookie.secure = true;
|
|
1170
|
-
break;
|
|
1171
|
-
case "partitioned":
|
|
1172
|
-
setCookie.partitioned = true;
|
|
1173
|
-
break;
|
|
1174
|
-
case "domain":
|
|
1175
|
-
setCookie.domain = val;
|
|
1176
|
-
break;
|
|
1177
|
-
case "path":
|
|
1178
|
-
setCookie.path = val;
|
|
1179
|
-
break;
|
|
1180
|
-
case "max-age":
|
|
1181
|
-
if (val && maxAgeRegExp.test(val))
|
|
1182
|
-
setCookie.maxAge = Number(val);
|
|
1183
|
-
break;
|
|
1184
|
-
case "expires":
|
|
1185
|
-
if (!val)
|
|
1186
|
-
break;
|
|
1187
|
-
const date = new Date(val);
|
|
1188
|
-
if (Number.isFinite(date.valueOf()))
|
|
1189
|
-
setCookie.expires = date;
|
|
1190
|
-
break;
|
|
1191
|
-
case "priority":
|
|
1192
|
-
if (!val)
|
|
1193
|
-
break;
|
|
1194
|
-
const priority = val.toLowerCase();
|
|
1195
|
-
if (priority === "low" ||
|
|
1196
|
-
priority === "medium" ||
|
|
1197
|
-
priority === "high") {
|
|
1198
|
-
setCookie.priority = priority;
|
|
1199
|
-
}
|
|
1200
|
-
break;
|
|
1201
|
-
case "samesite":
|
|
1202
|
-
if (!val)
|
|
1203
|
-
break;
|
|
1204
|
-
const sameSite = val.toLowerCase();
|
|
1205
|
-
if (sameSite === "lax" ||
|
|
1206
|
-
sameSite === "strict" ||
|
|
1207
|
-
sameSite === "none") {
|
|
1208
|
-
setCookie.sameSite = sameSite;
|
|
1209
|
-
}
|
|
1210
|
-
break;
|
|
1211
|
-
}
|
|
1212
|
-
index = endIdx + 1;
|
|
1213
|
-
}
|
|
1214
|
-
return setCookie;
|
|
1215
|
-
}
|
|
1216
|
-
/**
|
|
1217
|
-
* Find the `;` character between `min` and `len` in str.
|
|
1218
|
-
*/
|
|
1219
|
-
function endIndex(str, min, len) {
|
|
1220
|
-
const index = str.indexOf(";", min);
|
|
1221
|
-
return index === -1 ? len : index;
|
|
1222
|
-
}
|
|
1223
|
-
/**
|
|
1224
|
-
* Find the `=` character between `min` and `max` in str.
|
|
1225
|
-
*/
|
|
1226
|
-
function eqIndex(str, min, max) {
|
|
1227
|
-
const index = str.indexOf("=", min);
|
|
1228
|
-
return index < max ? index : -1;
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* Slice out a value between startPod to max.
|
|
1232
|
-
*/
|
|
1233
|
-
function valueSlice(str, min, max) {
|
|
1234
|
-
let start = min;
|
|
1235
|
-
let end = max;
|
|
1236
|
-
do {
|
|
1237
|
-
const code = str.charCodeAt(start);
|
|
1238
|
-
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
1239
|
-
break;
|
|
1240
|
-
} while (++start < end);
|
|
1241
|
-
while (end > start) {
|
|
1242
|
-
const code = str.charCodeAt(end - 1);
|
|
1243
|
-
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
1244
|
-
break;
|
|
1245
|
-
end--;
|
|
1246
|
-
}
|
|
1247
|
-
return str.slice(start, end);
|
|
1248
|
-
}
|
|
1249
|
-
/**
|
|
1250
|
-
* URL-decode string value. Optimized to skip native call when no %.
|
|
1251
|
-
*/
|
|
1252
|
-
function decode(str) {
|
|
1253
|
-
if (str.indexOf("%") === -1)
|
|
1254
|
-
return str;
|
|
1255
|
-
try {
|
|
1256
|
-
return decodeURIComponent(str);
|
|
1257
|
-
}
|
|
1258
|
-
catch (e) {
|
|
1259
|
-
return str;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Determine if value is a Date.
|
|
1264
|
-
*/
|
|
1265
|
-
function isDate(val) {
|
|
1266
|
-
return __toString.call(val) === "[object Date]";
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
return dist;
|
|
1005
|
+
function stringifySetCookie(_name, _val, _opts) {
|
|
1006
|
+
const cookie = typeof _name === "object"
|
|
1007
|
+
? _name
|
|
1008
|
+
: { ..._opts, name: _name, value: String(_val) };
|
|
1009
|
+
const options = typeof _val === "object" ? _val : _opts;
|
|
1010
|
+
const enc = options?.encode || encodeURIComponent;
|
|
1011
|
+
if (!cookieNameRegExp.test(cookie.name)) {
|
|
1012
|
+
throw new TypeError(`argument name is invalid: ${cookie.name}`);
|
|
1013
|
+
}
|
|
1014
|
+
const value = cookie.value ? enc(cookie.value) : "";
|
|
1015
|
+
if (!cookieValueRegExp.test(value)) {
|
|
1016
|
+
throw new TypeError(`argument val is invalid: ${cookie.value}`);
|
|
1017
|
+
}
|
|
1018
|
+
let str = cookie.name + "=" + value;
|
|
1019
|
+
if (cookie.maxAge !== undefined) {
|
|
1020
|
+
if (!Number.isInteger(cookie.maxAge)) {
|
|
1021
|
+
throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
|
|
1022
|
+
}
|
|
1023
|
+
str += "; Max-Age=" + cookie.maxAge;
|
|
1024
|
+
}
|
|
1025
|
+
if (cookie.domain) {
|
|
1026
|
+
if (!domainValueRegExp.test(cookie.domain)) {
|
|
1027
|
+
throw new TypeError(`option domain is invalid: ${cookie.domain}`);
|
|
1028
|
+
}
|
|
1029
|
+
str += "; Domain=" + cookie.domain;
|
|
1030
|
+
}
|
|
1031
|
+
if (cookie.path) {
|
|
1032
|
+
if (!pathValueRegExp.test(cookie.path)) {
|
|
1033
|
+
throw new TypeError(`option path is invalid: ${cookie.path}`);
|
|
1034
|
+
}
|
|
1035
|
+
str += "; Path=" + cookie.path;
|
|
1036
|
+
}
|
|
1037
|
+
if (cookie.expires) {
|
|
1038
|
+
if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
|
|
1039
|
+
throw new TypeError(`option expires is invalid: ${cookie.expires}`);
|
|
1040
|
+
}
|
|
1041
|
+
str += "; Expires=" + cookie.expires.toUTCString();
|
|
1042
|
+
}
|
|
1043
|
+
if (cookie.httpOnly) {
|
|
1044
|
+
str += "; HttpOnly";
|
|
1045
|
+
}
|
|
1046
|
+
if (cookie.secure) {
|
|
1047
|
+
str += "; Secure";
|
|
1048
|
+
}
|
|
1049
|
+
if (cookie.partitioned) {
|
|
1050
|
+
str += "; Partitioned";
|
|
1051
|
+
}
|
|
1052
|
+
if (cookie.priority) {
|
|
1053
|
+
const priority = typeof cookie.priority === "string"
|
|
1054
|
+
? cookie.priority.toLowerCase()
|
|
1055
|
+
: undefined;
|
|
1056
|
+
switch (priority) {
|
|
1057
|
+
case "low":
|
|
1058
|
+
str += "; Priority=Low";
|
|
1059
|
+
break;
|
|
1060
|
+
case "medium":
|
|
1061
|
+
str += "; Priority=Medium";
|
|
1062
|
+
break;
|
|
1063
|
+
case "high":
|
|
1064
|
+
str += "; Priority=High";
|
|
1065
|
+
break;
|
|
1066
|
+
default:
|
|
1067
|
+
throw new TypeError(`option priority is invalid: ${cookie.priority}`);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
if (cookie.sameSite) {
|
|
1071
|
+
const sameSite = typeof cookie.sameSite === "string"
|
|
1072
|
+
? cookie.sameSite.toLowerCase()
|
|
1073
|
+
: cookie.sameSite;
|
|
1074
|
+
switch (sameSite) {
|
|
1075
|
+
case true:
|
|
1076
|
+
case "strict":
|
|
1077
|
+
str += "; SameSite=Strict";
|
|
1078
|
+
break;
|
|
1079
|
+
case "lax":
|
|
1080
|
+
str += "; SameSite=Lax";
|
|
1081
|
+
break;
|
|
1082
|
+
case "none":
|
|
1083
|
+
str += "; SameSite=None";
|
|
1084
|
+
break;
|
|
1085
|
+
default:
|
|
1086
|
+
throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
return str;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Find the `;` character between `min` and `len` in str.
|
|
1093
|
+
*/
|
|
1094
|
+
function endIndex(str, min, len) {
|
|
1095
|
+
const index = str.indexOf(";", min);
|
|
1096
|
+
return index === -1 ? len : index;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Find the `=` character between `min` and `max` in str.
|
|
1100
|
+
*/
|
|
1101
|
+
function eqIndex(str, min, max) {
|
|
1102
|
+
const index = str.indexOf("=", min);
|
|
1103
|
+
return index < max ? index : -1;
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Slice out a value between startPod to max.
|
|
1107
|
+
*/
|
|
1108
|
+
function valueSlice(str, min, max) {
|
|
1109
|
+
let start = min;
|
|
1110
|
+
let end = max;
|
|
1111
|
+
do {
|
|
1112
|
+
const code = str.charCodeAt(start);
|
|
1113
|
+
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
1114
|
+
break;
|
|
1115
|
+
} while (++start < end);
|
|
1116
|
+
while (end > start) {
|
|
1117
|
+
const code = str.charCodeAt(end - 1);
|
|
1118
|
+
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
1119
|
+
break;
|
|
1120
|
+
end--;
|
|
1121
|
+
}
|
|
1122
|
+
return str.slice(start, end);
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* URL-decode string value. Optimized to skip native call when no %.
|
|
1126
|
+
*/
|
|
1127
|
+
function decode$1(str) {
|
|
1128
|
+
if (str.indexOf("%") === -1)
|
|
1129
|
+
return str;
|
|
1130
|
+
try {
|
|
1131
|
+
return decodeURIComponent(str);
|
|
1132
|
+
}
|
|
1133
|
+
catch (e) {
|
|
1134
|
+
return str;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Determine if value is a Date.
|
|
1139
|
+
*/
|
|
1140
|
+
function isDate(val) {
|
|
1141
|
+
return __toString.call(val) === "[object Date]";
|
|
1270
1142
|
}
|
|
1271
|
-
|
|
1272
|
-
var distExports = /*@__PURE__*/ requireDist();
|
|
1273
1143
|
|
|
1274
1144
|
// 实现函数
|
|
1275
1145
|
function createHandleCtx(req, res) {
|
|
@@ -1280,7 +1150,7 @@ function createHandleCtx(req, res) {
|
|
|
1280
1150
|
// 扩展 res.cookie 方法
|
|
1281
1151
|
const cookieFn = (name, value, options = {}, end = true) => {
|
|
1282
1152
|
// 序列化新的 Cookie
|
|
1283
|
-
const serializedCookie =
|
|
1153
|
+
const serializedCookie = stringifySetCookie(name, value, options);
|
|
1284
1154
|
cookies.push(serializedCookie); // 将新的 Cookie 添加到数组
|
|
1285
1155
|
if (end) {
|
|
1286
1156
|
// 如果设置了 end 参数,则立即设置到响应头
|
|
@@ -1288,7 +1158,7 @@ function createHandleCtx(req, res) {
|
|
|
1288
1158
|
}
|
|
1289
1159
|
};
|
|
1290
1160
|
// 解析请求中的现有 Cookie
|
|
1291
|
-
const parsedCookies =
|
|
1161
|
+
const parsedCookies = parseCookie(req.headers.cookie || '');
|
|
1292
1162
|
handReq.cookies = parsedCookies;
|
|
1293
1163
|
handRes.cookie = cookieFn;
|
|
1294
1164
|
// 返回扩展的上下文
|
|
@@ -5725,6 +5595,10 @@ const createSchema = (rule) => {
|
|
|
5725
5595
|
}
|
|
5726
5596
|
};
|
|
5727
5597
|
|
|
5598
|
+
function getDefaultExportFromCjs (x) {
|
|
5599
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5600
|
+
}
|
|
5601
|
+
|
|
5728
5602
|
var constants;
|
|
5729
5603
|
var hasRequiredConstants;
|
|
5730
5604
|
|