index.cjs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. // lib/cookie/index.ts
  20. var index_exports = {};
  21. __export(index_exports, {
  22. Cookie: () => Cookie,
  23. CookieJar: () => CookieJar,
  24. MemoryCookieStore: () => MemoryCookieStore,
  25. ParameterError: () => ParameterError,
  26. PrefixSecurityEnum: () => PrefixSecurityEnum,
  27. Store: () => Store,
  28. canonicalDomain: () => canonicalDomain,
  29. cookieCompare: () => cookieCompare,
  30. defaultPath: () => defaultPath,
  31. domainMatch: () => domainMatch,
  32. formatDate: () => formatDate,
  33. fromJSON: () => fromJSON2,
  34. getPublicSuffix: () => getPublicSuffix,
  35. parse: () => parse2,
  36. parseDate: () => parseDate,
  37. pathMatch: () => pathMatch,
  38. permuteDomain: () => permuteDomain,
  39. permutePath: () => permutePath,
  40. version: () => version
  41. });
  42. module.exports = __toCommonJS(index_exports);
  43. // lib/pathMatch.ts
  44. function pathMatch(reqPath, cookiePath) {
  45. if (cookiePath === reqPath) {
  46. return true;
  47. }
  48. const idx = reqPath.indexOf(cookiePath);
  49. if (idx === 0) {
  50. if (cookiePath[cookiePath.length - 1] === "/") {
  51. return true;
  52. }
  53. if (reqPath.startsWith(cookiePath) && reqPath[cookiePath.length] === "/") {
  54. return true;
  55. }
  56. }
  57. return false;
  58. }
  59. // lib/getPublicSuffix.ts
  60. var import_tldts = require("tldts");
  61. var SPECIAL_USE_DOMAINS = ["local", "example", "invalid", "localhost", "test"];
  62. var SPECIAL_TREATMENT_DOMAINS = ["localhost", "invalid"];
  63. var defaultGetPublicSuffixOptions = {
  64. allowSpecialUseDomain: false,
  65. ignoreError: false
  66. };
  67. function getPublicSuffix(domain, options = {}) {
  68. options = { ...defaultGetPublicSuffixOptions, ...options };
  69. const domainParts = domain.split(".");
  70. const topLevelDomain = domainParts[domainParts.length - 1];
  71. const allowSpecialUseDomain = !!options.allowSpecialUseDomain;
  72. const ignoreError = !!options.ignoreError;
  73. if (allowSpecialUseDomain && topLevelDomain !== void 0 && SPECIAL_USE_DOMAINS.includes(topLevelDomain)) {
  74. if (domainParts.length > 1) {
  75. const secondLevelDomain = domainParts[domainParts.length - 2];
  76. return `${secondLevelDomain}.${topLevelDomain}`;
  77. } else if (SPECIAL_TREATMENT_DOMAINS.includes(topLevelDomain)) {
  78. return topLevelDomain;
  79. }
  80. }
  81. if (!ignoreError && topLevelDomain !== void 0 && SPECIAL_USE_DOMAINS.includes(topLevelDomain)) {
  82. throw new Error(
  83. `Cookie has domain set to the public suffix "${topLevelDomain}" which is a special use domain. To allow this, configure your CookieJar with {allowSpecialUseDomain: true, rejectPublicSuffixes: false}.`
  84. );
  85. }
  86. const publicSuffix = (0, import_tldts.getDomain)(domain, {
  87. allowIcannDomains: true,
  88. allowPrivateDomains: true
  89. });
  90. if (publicSuffix) return publicSuffix;
  91. }
  92. // lib/permuteDomain.ts
  93. function permuteDomain(domain, allowSpecialUseDomain) {
  94. const pubSuf = getPublicSuffix(domain, {
  95. allowSpecialUseDomain
  96. });
  97. if (!pubSuf) {
  98. return void 0;
  99. }
  100. if (pubSuf == domain) {
  101. return [domain];
  102. }
  103. if (domain.slice(-1) == ".") {
  104. domain = domain.slice(0, -1);
  105. }
  106. const prefix = domain.slice(0, -(pubSuf.length + 1));
  107. const parts = prefix.split(".").reverse();
  108. let cur = pubSuf;
  109. const permutations = [cur];
  110. while (parts.length) {
  111. const part = parts.shift();
  112. cur = `${part}.${cur}`;
  113. permutations.push(cur);
  114. }
  115. return permutations;
  116. }
  117. // lib/store.ts
  118. var Store = class {
  119. constructor() {
  120. this.synchronous = false;
  121. }
  122. /**
  123. * @internal No doc because this is an overload that supports the implementation
  124. */
  125. findCookie(_domain, _path, _key, _callback) {
  126. throw new Error("findCookie is not implemented");
  127. }
  128. /**
  129. * @internal No doc because this is an overload that supports the implementation
  130. */
  131. findCookies(_domain, _path, _allowSpecialUseDomain = false, _callback) {
  132. throw new Error("findCookies is not implemented");
  133. }
  134. /**
  135. * @internal No doc because this is an overload that supports the implementation
  136. */
  137. putCookie(_cookie, _callback) {
  138. throw new Error("putCookie is not implemented");
  139. }
  140. /**
  141. * @internal No doc because this is an overload that supports the implementation
  142. */
  143. updateCookie(_oldCookie, _newCookie, _callback) {
  144. throw new Error("updateCookie is not implemented");
  145. }
  146. /**
  147. * @internal No doc because this is an overload that supports the implementation
  148. */
  149. removeCookie(_domain, _path, _key, _callback) {
  150. throw new Error("removeCookie is not implemented");
  151. }
  152. /**
  153. * @internal No doc because this is an overload that supports the implementation
  154. */
  155. removeCookies(_domain, _path, _callback) {
  156. throw new Error("removeCookies is not implemented");
  157. }
  158. /**
  159. * @internal No doc because this is an overload that supports the implementation
  160. */
  161. removeAllCookies(_callback) {
  162. throw new Error("removeAllCookies is not implemented");
  163. }
  164. /**
  165. * @internal No doc because this is an overload that supports the implementation
  166. */
  167. getAllCookies(_callback) {
  168. throw new Error(
  169. "getAllCookies is not implemented (therefore jar cannot be serialized)"
  170. );
  171. }
  172. };
  173. // lib/utils.ts
  174. var objectToString = (obj) => Object.prototype.toString.call(obj);
  175. var safeArrayToString = (arr, seenArrays) => {
  176. if (typeof arr.join !== "function") return objectToString(arr);
  177. seenArrays.add(arr);
  178. const mapped = arr.map(
  179. (val) => val === null || val === void 0 || seenArrays.has(val) ? "" : safeToStringImpl(val, seenArrays)
  180. );
  181. return mapped.join();
  182. };
  183. var safeToStringImpl = (val, seenArrays = /* @__PURE__ */ new WeakSet()) => {
  184. if (typeof val !== "object" || val === null) {
  185. return String(val);
  186. } else if (typeof val.toString === "function") {
  187. return Array.isArray(val) ? (
  188. // Arrays have a weird custom toString that we need to replicate
  189. safeArrayToString(val, seenArrays)
  190. ) : (
  191. // eslint-disable-next-line @typescript-eslint/no-base-to-string
  192. String(val)
  193. );
  194. } else {
  195. return objectToString(val);
  196. }
  197. };
  198. var safeToString = (val) => safeToStringImpl(val);
  199. function createPromiseCallback(cb) {
  200. let callback;
  201. let resolve;
  202. let reject;
  203. const promise = new Promise((_resolve, _reject) => {
  204. resolve = _resolve;
  205. reject = _reject;
  206. });
  207. if (typeof cb === "function") {
  208. callback = (err, result) => {
  209. try {
  210. if (err) cb(err);
  211. else cb(null, result);
  212. } catch (e) {
  213. reject(e instanceof Error ? e : new Error());
  214. }
  215. };
  216. } else {
  217. callback = (err, result) => {
  218. try {
  219. if (err) reject(err);
  220. else resolve(result);
  221. } catch (e) {
  222. reject(e instanceof Error ? e : new Error());
  223. }
  224. };
  225. }
  226. return {
  227. promise,
  228. callback,
  229. resolve: (value) => {
  230. callback(null, value);
  231. return promise;
  232. },
  233. reject: (error) => {
  234. callback(error);
  235. return promise;
  236. }
  237. };
  238. }
  239. function inOperator(k, o) {
  240. return k in o;
  241. }
  242. // lib/memstore.ts
  243. var MemoryCookieStore = class extends Store {
  244. /**
  245. * Create a new {@link MemoryCookieStore}.
  246. */
  247. constructor() {
  248. super();
  249. this.synchronous = true;
  250. this.idx = /* @__PURE__ */ Object.create(null);
  251. }
  252. /**
  253. * @internal No doc because this is an overload that supports the implementation
  254. */
  255. findCookie(domain, path, key, callback) {
  256. const promiseCallback = createPromiseCallback(callback);
  257. if (domain == null || path == null || key == null) {
  258. return promiseCallback.resolve(void 0);
  259. }
  260. const result = this.idx[domain]?.[path]?.[key];
  261. return promiseCallback.resolve(result);
  262. }
  263. /**
  264. * @internal No doc because this is an overload that supports the implementation
  265. */
  266. findCookies(domain, path, allowSpecialUseDomain = false, callback) {
  267. if (typeof allowSpecialUseDomain === "function") {
  268. callback = allowSpecialUseDomain;
  269. allowSpecialUseDomain = true;
  270. }
  271. const results = [];
  272. const promiseCallback = createPromiseCallback(callback);
  273. if (!domain) {
  274. return promiseCallback.resolve([]);
  275. }
  276. let pathMatcher;
  277. if (!path) {
  278. pathMatcher = function matchAll(domainIndex) {
  279. for (const curPath in domainIndex) {
  280. const pathIndex = domainIndex[curPath];
  281. for (const key in pathIndex) {
  282. const value = pathIndex[key];
  283. if (value) {
  284. results.push(value);
  285. }
  286. }
  287. }
  288. };
  289. } else {
  290. pathMatcher = function matchRFC(domainIndex) {
  291. for (const cookiePath in domainIndex) {
  292. if (pathMatch(path, cookiePath)) {
  293. const pathIndex = domainIndex[cookiePath];
  294. for (const key in pathIndex) {
  295. const value = pathIndex[key];
  296. if (value) {
  297. results.push(value);
  298. }
  299. }
  300. }
  301. }
  302. };
  303. }
  304. const domains = permuteDomain(domain, allowSpecialUseDomain) || [domain];
  305. const idx = this.idx;
  306. domains.forEach((curDomain) => {
  307. const domainIndex = idx[curDomain];
  308. if (!domainIndex) {
  309. return;
  310. }
  311. pathMatcher(domainIndex);
  312. });
  313. return promiseCallback.resolve(results);
  314. }
  315. /**
  316. * @internal No doc because this is an overload that supports the implementation
  317. */
  318. putCookie(cookie, callback) {
  319. const promiseCallback = createPromiseCallback(callback);
  320. const { domain, path, key } = cookie;
  321. if (domain == null || path == null || key == null) {
  322. return promiseCallback.resolve(void 0);
  323. }
  324. const domainEntry = this.idx[domain] ?? /* @__PURE__ */ Object.create(null);
  325. this.idx[domain] = domainEntry;
  326. const pathEntry = domainEntry[path] ?? /* @__PURE__ */ Object.create(null);
  327. domainEntry[path] = pathEntry;
  328. pathEntry[key] = cookie;
  329. return promiseCallback.resolve(void 0);
  330. }
  331. /**
  332. * @internal No doc because this is an overload that supports the implementation
  333. */
  334. updateCookie(_oldCookie, newCookie, callback) {
  335. if (callback) this.putCookie(newCookie, callback);
  336. else return this.putCookie(newCookie);
  337. }
  338. /**
  339. * @internal No doc because this is an overload that supports the implementation
  340. */
  341. removeCookie(domain, path, key, callback) {
  342. const promiseCallback = createPromiseCallback(callback);
  343. delete this.idx[domain]?.[path]?.[key];
  344. return promiseCallback.resolve(void 0);
  345. }
  346. /**
  347. * @internal No doc because this is an overload that supports the implementation
  348. */
  349. removeCookies(domain, path, callback) {
  350. const promiseCallback = createPromiseCallback(callback);
  351. const domainEntry = this.idx[domain];
  352. if (domainEntry) {
  353. if (path) {
  354. delete domainEntry[path];
  355. } else {
  356. delete this.idx[domain];
  357. }
  358. }
  359. return promiseCallback.resolve(void 0);
  360. }
  361. /**
  362. * @internal No doc because this is an overload that supports the implementation
  363. */
  364. removeAllCookies(callback) {
  365. const promiseCallback = createPromiseCallback(callback);
  366. this.idx = /* @__PURE__ */ Object.create(null);
  367. return promiseCallback.resolve(void 0);
  368. }
  369. /**
  370. * @internal No doc because this is an overload that supports the implementation
  371. */
  372. getAllCookies(callback) {
  373. const promiseCallback = createPromiseCallback(callback);
  374. const cookies = [];
  375. const idx = this.idx;
  376. const domains = Object.keys(idx);
  377. domains.forEach((domain) => {
  378. const domainEntry = idx[domain] ?? {};
  379. const paths = Object.keys(domainEntry);
  380. paths.forEach((path) => {
  381. const pathEntry = domainEntry[path] ?? {};
  382. const keys = Object.keys(pathEntry);
  383. keys.forEach((key) => {
  384. const keyEntry = pathEntry[key];
  385. if (keyEntry != null) {
  386. cookies.push(keyEntry);
  387. }
  388. });
  389. });
  390. });
  391. cookies.sort((a, b) => {
  392. return (a.creationIndex || 0) - (b.creationIndex || 0);
  393. });
  394. return promiseCallback.resolve(cookies);
  395. }
  396. };
  397. // lib/validators.ts
  398. function isNonEmptyString(data) {
  399. return isString(data) && data !== "";
  400. }
  401. function isEmptyString(data) {
  402. return data === "" || data instanceof String && data.toString() === "";
  403. }
  404. function isString(data) {
  405. return typeof data === "string" || data instanceof String;
  406. }
  407. function isObject(data) {
  408. return objectToString(data) === "[object Object]";
  409. }
  410. function validate(bool, cbOrMessage, message) {
  411. if (bool) return;
  412. const cb = typeof cbOrMessage === "function" ? cbOrMessage : void 0;
  413. let options = typeof cbOrMessage === "function" ? message : cbOrMessage;
  414. if (!isObject(options)) options = "[object Object]";
  415. const err = new ParameterError(safeToString(options));
  416. if (cb) cb(err);
  417. else throw err;
  418. }
  419. var ParameterError = class extends Error {
  420. };
  421. // lib/version.ts
  422. var version = "6.0.0";
  423. // lib/cookie/constants.ts
  424. var PrefixSecurityEnum = {
  425. SILENT: "silent",
  426. STRICT: "strict",
  427. DISABLED: "unsafe-disabled"
  428. };
  429. Object.freeze(PrefixSecurityEnum);
  430. var IP_V6_REGEX = `
  431. \\[?(?:
  432. (?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|
  433. (?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|
  434. (?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,2}|:)|
  435. (?:[a-fA-F\\d]{1,4}:){4}(?:(?::[a-fA-F\\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,3}|:)|
  436. (?:[a-fA-F\\d]{1,4}:){3}(?:(?::[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,4}|:)|
  437. (?:[a-fA-F\\d]{1,4}:){2}(?:(?::[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,5}|:)|
  438. (?:[a-fA-F\\d]{1,4}:){1}(?:(?::[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|
  439. (?::(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:))
  440. )(?:%[0-9a-zA-Z]{1,})?\\]?
  441. `.replace(/\s*\/\/.*$/gm, "").replace(/\n/g, "").trim();
  442. var IP_V6_REGEX_OBJECT = new RegExp(`^${IP_V6_REGEX}$`);
  443. var IP_V4_REGEX = `(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])`;
  444. var IP_V4_REGEX_OBJECT = new RegExp(`^${IP_V4_REGEX}$`);
  445. // lib/cookie/canonicalDomain.ts
  446. function domainToASCII(domain) {
  447. return new URL(`http://${domain}`).hostname;
  448. }
  449. function canonicalDomain(domainName) {
  450. if (domainName == null) {
  451. return void 0;
  452. }
  453. let str = domainName.trim().replace(/^\./, "");
  454. if (IP_V6_REGEX_OBJECT.test(str)) {
  455. if (!str.startsWith("[")) {
  456. str = "[" + str;
  457. }
  458. if (!str.endsWith("]")) {
  459. str = str + "]";
  460. }
  461. return domainToASCII(str).slice(1, -1);
  462. }
  463. if (/[^\u0001-\u007f]/.test(str)) {
  464. return domainToASCII(str);
  465. }
  466. return str.toLowerCase();
  467. }
  468. // lib/cookie/formatDate.ts
  469. function formatDate(date) {
  470. return date.toUTCString();
  471. }
  472. // lib/cookie/parseDate.ts
  473. var DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/;
  474. var MONTH_TO_NUM = {
  475. jan: 0,
  476. feb: 1,
  477. mar: 2,
  478. apr: 3,
  479. may: 4,
  480. jun: 5,
  481. jul: 6,
  482. aug: 7,
  483. sep: 8,
  484. oct: 9,
  485. nov: 10,
  486. dec: 11
  487. };
  488. function parseDigits(token, minDigits, maxDigits, trailingOK) {
  489. let count = 0;
  490. while (count < token.length) {
  491. const c = token.charCodeAt(count);
  492. if (c <= 47 || c >= 58) {
  493. break;
  494. }
  495. count++;
  496. }
  497. if (count < minDigits || count > maxDigits) {
  498. return;
  499. }
  500. if (!trailingOK && count != token.length) {
  501. return;
  502. }
  503. return parseInt(token.slice(0, count), 10);
  504. }
  505. function parseTime(token) {
  506. const parts = token.split(":");
  507. const result = [0, 0, 0];
  508. if (parts.length !== 3) {
  509. return;
  510. }
  511. for (let i = 0; i < 3; i++) {
  512. const trailingOK = i == 2;
  513. const numPart = parts[i];
  514. if (numPart === void 0) {
  515. return;
  516. }
  517. const num = parseDigits(numPart, 1, 2, trailingOK);
  518. if (num === void 0) {
  519. return;
  520. }
  521. result[i] = num;
  522. }
  523. return result;
  524. }
  525. function parseMonth(token) {
  526. token = String(token).slice(0, 3).toLowerCase();
  527. switch (token) {
  528. case "jan":
  529. return MONTH_TO_NUM.jan;
  530. case "feb":
  531. return MONTH_TO_NUM.feb;
  532. case "mar":
  533. return MONTH_TO_NUM.mar;
  534. case "apr":
  535. return MONTH_TO_NUM.apr;
  536. case "may":
  537. return MONTH_TO_NUM.may;
  538. case "jun":
  539. return MONTH_TO_NUM.jun;
  540. case "jul":
  541. return MONTH_TO_NUM.jul;
  542. case "aug":
  543. return MONTH_TO_NUM.aug;
  544. case "sep":
  545. return MONTH_TO_NUM.sep;
  546. case "oct":
  547. return MONTH_TO_NUM.oct;
  548. case "nov":
  549. return MONTH_TO_NUM.nov;
  550. case "dec":
  551. return MONTH_TO_NUM.dec;
  552. default:
  553. return;
  554. }
  555. }
  556. function parseDate(cookieDate) {
  557. if (!cookieDate) {
  558. return;
  559. }
  560. const tokens = cookieDate.split(DATE_DELIM);
  561. let hour;
  562. let minute;
  563. let second;
  564. let dayOfMonth;
  565. let month;
  566. let year;
  567. for (let i = 0; i < tokens.length; i++) {
  568. const token = (tokens[i] ?? "").trim();
  569. if (!token.length) {
  570. continue;
  571. }
  572. if (second === void 0) {
  573. const result = parseTime(token);
  574. if (result) {
  575. hour = result[0];
  576. minute = result[1];
  577. second = result[2];
  578. continue;
  579. }
  580. }
  581. if (dayOfMonth === void 0) {
  582. const result = parseDigits(token, 1, 2, true);
  583. if (result !== void 0) {
  584. dayOfMonth = result;
  585. continue;
  586. }
  587. }
  588. if (month === void 0) {
  589. const result = parseMonth(token);
  590. if (result !== void 0) {
  591. month = result;
  592. continue;
  593. }
  594. }
  595. if (year === void 0) {
  596. const result = parseDigits(token, 2, 4, true);
  597. if (result !== void 0) {
  598. year = result;
  599. if (year >= 70 && year <= 99) {
  600. year += 1900;
  601. } else if (year >= 0 && year <= 69) {
  602. year += 2e3;
  603. }
  604. }
  605. }
  606. }
  607. if (dayOfMonth === void 0 || month === void 0 || year === void 0 || hour === void 0 || minute === void 0 || second === void 0 || dayOfMonth < 1 || dayOfMonth > 31 || year < 1601 || hour > 23 || minute > 59 || second > 59) {
  608. return;
  609. }
  610. return new Date(Date.UTC(year, month, dayOfMonth, hour, minute, second));
  611. }
  612. // lib/cookie/cookie.ts
  613. var COOKIE_OCTETS = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/;
  614. var PATH_VALUE = /[\x20-\x3A\x3C-\x7E]+/;
  615. var CONTROL_CHARS = /[\x00-\x1F]/;
  616. var TERMINATORS = ["\n", "\r", "\0"];
  617. function trimTerminator(str) {
  618. if (isEmptyString(str)) return str;
  619. for (let t = 0; t < TERMINATORS.length; t++) {
  620. const terminator = TERMINATORS[t];
  621. const terminatorIdx = terminator ? str.indexOf(terminator) : -1;
  622. if (terminatorIdx !== -1) {
  623. str = str.slice(0, terminatorIdx);
  624. }
  625. }
  626. return str;
  627. }
  628. function parseCookiePair(cookiePair, looseMode) {
  629. cookiePair = trimTerminator(cookiePair);
  630. let firstEq = cookiePair.indexOf("=");
  631. if (looseMode) {
  632. if (firstEq === 0) {
  633. cookiePair = cookiePair.substring(1);
  634. firstEq = cookiePair.indexOf("=");
  635. }
  636. } else {
  637. if (firstEq <= 0) {
  638. return void 0;
  639. }
  640. }
  641. let cookieName, cookieValue;
  642. if (firstEq <= 0) {
  643. cookieName = "";
  644. cookieValue = cookiePair.trim();
  645. } else {
  646. cookieName = cookiePair.slice(0, firstEq).trim();
  647. cookieValue = cookiePair.slice(firstEq + 1).trim();
  648. }
  649. if (CONTROL_CHARS.test(cookieName) || CONTROL_CHARS.test(cookieValue)) {
  650. return void 0;
  651. }
  652. const c = new Cookie();
  653. c.key = cookieName;
  654. c.value = cookieValue;
  655. return c;
  656. }
  657. function parse(str, options) {
  658. if (isEmptyString(str) || !isString(str)) {
  659. return void 0;
  660. }
  661. str = str.trim();
  662. const firstSemi = str.indexOf(";");
  663. const cookiePair = firstSemi === -1 ? str : str.slice(0, firstSemi);
  664. const c = parseCookiePair(cookiePair, options?.loose ?? false);
  665. if (!c) {
  666. return void 0;
  667. }
  668. if (firstSemi === -1) {
  669. return c;
  670. }
  671. const unparsed = str.slice(firstSemi + 1).trim();
  672. if (unparsed.length === 0) {
  673. return c;
  674. }
  675. const cookie_avs = unparsed.split(";");
  676. while (cookie_avs.length) {
  677. const av = (cookie_avs.shift() ?? "").trim();
  678. if (av.length === 0) {
  679. continue;
  680. }
  681. const av_sep = av.indexOf("=");
  682. let av_key, av_value;
  683. if (av_sep === -1) {
  684. av_key = av;
  685. av_value = null;
  686. } else {
  687. av_key = av.slice(0, av_sep);
  688. av_value = av.slice(av_sep + 1);
  689. }
  690. av_key = av_key.trim().toLowerCase();
  691. if (av_value) {
  692. av_value = av_value.trim();
  693. }
  694. switch (av_key) {
  695. case "expires":
  696. if (av_value) {
  697. const exp = parseDate(av_value);
  698. if (exp) {
  699. c.expires = exp;
  700. }
  701. }
  702. break;
  703. case "max-age":
  704. if (av_value) {
  705. if (/^-?[0-9]+$/.test(av_value)) {
  706. const delta = parseInt(av_value, 10);
  707. c.setMaxAge(delta);
  708. }
  709. }
  710. break;
  711. case "domain":
  712. if (av_value) {
  713. const domain = av_value.trim().replace(/^\./, "");
  714. if (domain) {
  715. c.domain = domain.toLowerCase();
  716. }
  717. }
  718. break;
  719. case "path":
  720. c.path = av_value && av_value[0] === "/" ? av_value : null;
  721. break;
  722. case "secure":
  723. c.secure = true;
  724. break;
  725. case "httponly":
  726. c.httpOnly = true;
  727. break;
  728. case "samesite":
  729. switch (av_value ? av_value.toLowerCase() : "") {
  730. case "strict":
  731. c.sameSite = "strict";
  732. break;
  733. case "lax":
  734. c.sameSite = "lax";
  735. break;
  736. case "none":
  737. c.sameSite = "none";
  738. break;
  739. default:
  740. c.sameSite = void 0;
  741. break;
  742. }
  743. break;
  744. default:
  745. c.extensions = c.extensions || [];
  746. c.extensions.push(av);
  747. break;
  748. }
  749. }
  750. return c;
  751. }
  752. function fromJSON(str) {
  753. if (!str || isEmptyString(str)) {
  754. return void 0;
  755. }
  756. let obj;
  757. if (typeof str === "string") {
  758. try {
  759. obj = JSON.parse(str);
  760. } catch {
  761. return void 0;
  762. }
  763. } else {
  764. obj = str;
  765. }
  766. const c = new Cookie();
  767. Cookie.serializableProperties.forEach((prop) => {
  768. if (obj && typeof obj === "object" && inOperator(prop, obj)) {
  769. const val = obj[prop];
  770. if (val === void 0) {
  771. return;
  772. }
  773. if (inOperator(prop, cookieDefaults) && val === cookieDefaults[prop]) {
  774. return;
  775. }
  776. switch (prop) {
  777. case "key":
  778. case "value":
  779. case "sameSite":
  780. if (typeof val === "string") {
  781. c[prop] = val;
  782. }
  783. break;
  784. case "expires":
  785. case "creation":
  786. case "lastAccessed":
  787. if (typeof val === "number" || typeof val === "string" || val instanceof Date) {
  788. c[prop] = obj[prop] == "Infinity" ? "Infinity" : new Date(val);
  789. } else if (val === null) {
  790. c[prop] = null;
  791. }
  792. break;
  793. case "maxAge":
  794. if (typeof val === "number" || val === "Infinity" || val === "-Infinity") {
  795. c[prop] = val;
  796. }
  797. break;
  798. case "domain":
  799. case "path":
  800. if (typeof val === "string" || val === null) {
  801. c[prop] = val;
  802. }
  803. break;
  804. case "secure":
  805. case "httpOnly":
  806. if (typeof val === "boolean") {
  807. c[prop] = val;
  808. }
  809. break;
  810. case "extensions":
  811. if (Array.isArray(val) && val.every((item) => typeof item === "string")) {
  812. c[prop] = val;
  813. }
  814. break;
  815. case "hostOnly":
  816. case "pathIsDefault":
  817. if (typeof val === "boolean" || val === null) {
  818. c[prop] = val;
  819. }
  820. break;
  821. }
  822. }
  823. });
  824. return c;
  825. }
  826. var cookieDefaults = {
  827. // the order in which the RFC has them:
  828. key: "",
  829. value: "",
  830. expires: "Infinity",
  831. maxAge: null,
  832. domain: null,
  833. path: null,
  834. secure: false,
  835. httpOnly: false,
  836. extensions: null,
  837. // set by the CookieJar:
  838. hostOnly: null,
  839. pathIsDefault: null,
  840. creation: null,
  841. lastAccessed: null,
  842. sameSite: void 0
  843. };
  844. var _Cookie = class _Cookie {
  845. /**
  846. * Create a new Cookie instance.
  847. * @public
  848. * @param options - The attributes to set on the cookie
  849. */
  850. constructor(options = {}) {
  851. this.key = options.key ?? cookieDefaults.key;
  852. this.value = options.value ?? cookieDefaults.value;
  853. this.expires = options.expires ?? cookieDefaults.expires;
  854. this.maxAge = options.maxAge ?? cookieDefaults.maxAge;
  855. this.domain = options.domain ?? cookieDefaults.domain;
  856. this.path = options.path ?? cookieDefaults.path;
  857. this.secure = options.secure ?? cookieDefaults.secure;
  858. this.httpOnly = options.httpOnly ?? cookieDefaults.httpOnly;
  859. this.extensions = options.extensions ?? cookieDefaults.extensions;
  860. this.creation = options.creation ?? cookieDefaults.creation;
  861. this.hostOnly = options.hostOnly ?? cookieDefaults.hostOnly;
  862. this.pathIsDefault = options.pathIsDefault ?? cookieDefaults.pathIsDefault;
  863. this.lastAccessed = options.lastAccessed ?? cookieDefaults.lastAccessed;
  864. this.sameSite = options.sameSite ?? cookieDefaults.sameSite;
  865. this.creation = options.creation ?? /* @__PURE__ */ new Date();
  866. Object.defineProperty(this, "creationIndex", {
  867. configurable: false,
  868. enumerable: false,
  869. // important for assert.deepEqual checks
  870. writable: true,
  871. value: ++_Cookie.cookiesCreated
  872. });
  873. this.creationIndex = _Cookie.cookiesCreated;
  874. }
  875. [Symbol.for("nodejs.util.inspect.custom")]() {
  876. const now = Date.now();
  877. const hostOnly = this.hostOnly != null ? this.hostOnly.toString() : "?";
  878. const createAge = this.creation && this.creation !== "Infinity" ? `${String(now - this.creation.getTime())}ms` : "?";
  879. const accessAge = this.lastAccessed && this.lastAccessed !== "Infinity" ? `${String(now - this.lastAccessed.getTime())}ms` : "?";
  880. return `Cookie="${this.toString()}; hostOnly=${hostOnly}; aAge=${accessAge}; cAge=${createAge}"`;
  881. }
  882. /**
  883. * For convenience in using `JSON.stringify(cookie)`. Returns a plain-old Object that can be JSON-serialized.
  884. *
  885. * @remarks
  886. * - Any `Date` properties (such as {@link Cookie.expires}, {@link Cookie.creation}, and {@link Cookie.lastAccessed}) are exported in ISO format (`Date.toISOString()`).
  887. *
  888. * - Custom Cookie properties are discarded. In tough-cookie 1.x, since there was no {@link Cookie.toJSON} method explicitly defined, all enumerable properties were captured.
  889. * If you want a property to be serialized, add the property name to {@link Cookie.serializableProperties}.
  890. */
  891. toJSON() {
  892. const obj = {};
  893. for (const prop of _Cookie.serializableProperties) {
  894. const val = this[prop];
  895. if (val === cookieDefaults[prop]) {
  896. continue;
  897. }
  898. switch (prop) {
  899. case "key":
  900. case "value":
  901. case "sameSite":
  902. if (typeof val === "string") {
  903. obj[prop] = val;
  904. }
  905. break;
  906. case "expires":
  907. case "creation":
  908. case "lastAccessed":
  909. if (typeof val === "number" || typeof val === "string" || val instanceof Date) {
  910. obj[prop] = val == "Infinity" ? "Infinity" : new Date(val).toISOString();
  911. } else if (val === null) {
  912. obj[prop] = null;
  913. }
  914. break;
  915. case "maxAge":
  916. if (typeof val === "number" || val === "Infinity" || val === "-Infinity") {
  917. obj[prop] = val;
  918. }
  919. break;
  920. case "domain":
  921. case "path":
  922. if (typeof val === "string" || val === null) {
  923. obj[prop] = val;
  924. }
  925. break;
  926. case "secure":
  927. case "httpOnly":
  928. if (typeof val === "boolean") {
  929. obj[prop] = val;
  930. }
  931. break;
  932. case "extensions":
  933. if (Array.isArray(val)) {
  934. obj[prop] = val;
  935. }
  936. break;
  937. case "hostOnly":
  938. case "pathIsDefault":
  939. if (typeof val === "boolean" || val === null) {
  940. obj[prop] = val;
  941. }
  942. break;
  943. }
  944. }
  945. return obj;
  946. }
  947. /**
  948. * Does a deep clone of this cookie, implemented exactly as `Cookie.fromJSON(cookie.toJSON())`.
  949. * @public
  950. */
  951. clone() {
  952. return fromJSON(this.toJSON());
  953. }
  954. /**
  955. * Validates cookie attributes for semantic correctness. Useful for "lint" checking any `Set-Cookie` headers you generate.
  956. * For now, it returns a boolean, but eventually could return a reason string.
  957. *
  958. * @remarks
  959. * Works for a few things, but is by no means comprehensive.
  960. *
  961. * @beta
  962. */
  963. validate() {
  964. if (!this.value || !COOKIE_OCTETS.test(this.value)) {
  965. return false;
  966. }
  967. if (this.expires != "Infinity" && !(this.expires instanceof Date) && !parseDate(this.expires)) {
  968. return false;
  969. }
  970. if (this.maxAge != null && this.maxAge !== "Infinity" && (this.maxAge === "-Infinity" || this.maxAge <= 0)) {
  971. return false;
  972. }
  973. if (this.path != null && !PATH_VALUE.test(this.path)) {
  974. return false;
  975. }
  976. const cdomain = this.cdomain();
  977. if (cdomain) {
  978. if (cdomain.match(/\.$/)) {
  979. return false;
  980. }
  981. const suffix = getPublicSuffix(cdomain);
  982. if (suffix == null) {
  983. return false;
  984. }
  985. }
  986. return true;
  987. }
  988. /**
  989. * Sets the 'Expires' attribute on a cookie.
  990. *
  991. * @remarks
  992. * When given a `string` value it will be parsed with {@link parseDate}. If the value can't be parsed as a cookie date
  993. * then the 'Expires' attribute will be set to `"Infinity"`.
  994. *
  995. * @param exp - the new value for the 'Expires' attribute of the cookie.
  996. */
  997. setExpires(exp) {
  998. if (exp instanceof Date) {
  999. this.expires = exp;
  1000. } else {
  1001. this.expires = parseDate(exp) || "Infinity";
  1002. }
  1003. }
  1004. /**
  1005. * Sets the 'Max-Age' attribute (in seconds) on a cookie.
  1006. *
  1007. * @remarks
  1008. * Coerces `-Infinity` to `"-Infinity"` and `Infinity` to `"Infinity"` so it can be serialized to JSON.
  1009. *
  1010. * @param age - the new value for the 'Max-Age' attribute (in seconds).
  1011. */
  1012. setMaxAge(age) {
  1013. if (age === Infinity) {
  1014. this.maxAge = "Infinity";
  1015. } else if (age === -Infinity) {
  1016. this.maxAge = "-Infinity";
  1017. } else {
  1018. this.maxAge = age;
  1019. }
  1020. }
  1021. /**
  1022. * Encodes to a `Cookie` header value (specifically, the {@link Cookie.key} and {@link Cookie.value} properties joined with "=").
  1023. * @public
  1024. */
  1025. cookieString() {
  1026. const val = this.value || "";
  1027. if (this.key) {
  1028. return `${this.key}=${val}`;
  1029. }
  1030. return val;
  1031. }
  1032. /**
  1033. * Encodes to a `Set-Cookie header` value.
  1034. * @public
  1035. */
  1036. toString() {
  1037. let str = this.cookieString();
  1038. if (this.expires != "Infinity") {
  1039. if (this.expires instanceof Date) {
  1040. str += `; Expires=${formatDate(this.expires)}`;
  1041. }
  1042. }
  1043. if (this.maxAge != null && this.maxAge != Infinity) {
  1044. str += `; Max-Age=${String(this.maxAge)}`;
  1045. }
  1046. if (this.domain && !this.hostOnly) {
  1047. str += `; Domain=${this.domain}`;
  1048. }
  1049. if (this.path) {
  1050. str += `; Path=${this.path}`;
  1051. }
  1052. if (this.secure) {
  1053. str += "; Secure";
  1054. }
  1055. if (this.httpOnly) {
  1056. str += "; HttpOnly";
  1057. }
  1058. if (this.sameSite && this.sameSite !== "none") {
  1059. if (this.sameSite.toLowerCase() === _Cookie.sameSiteCanonical.lax.toLowerCase()) {
  1060. str += `; SameSite=${_Cookie.sameSiteCanonical.lax}`;
  1061. } else if (this.sameSite.toLowerCase() === _Cookie.sameSiteCanonical.strict.toLowerCase()) {
  1062. str += `; SameSite=${_Cookie.sameSiteCanonical.strict}`;
  1063. } else {
  1064. str += `; SameSite=${this.sameSite}`;
  1065. }
  1066. }
  1067. if (this.extensions) {
  1068. this.extensions.forEach((ext) => {
  1069. str += `; ${ext}`;
  1070. });
  1071. }
  1072. return str;
  1073. }
  1074. /**
  1075. * Computes the TTL relative to now (milliseconds).
  1076. *
  1077. * @remarks
  1078. * - `Infinity` is returned for cookies without an explicit expiry
  1079. *
  1080. * - `0` is returned if the cookie is expired.
  1081. *
  1082. * - Otherwise a time-to-live in milliseconds is returned.
  1083. *
  1084. * @param now - passing an explicit value is mostly used for testing purposes since this defaults to the `Date.now()`
  1085. * @public
  1086. */
  1087. TTL(now = Date.now()) {
  1088. if (this.maxAge != null && typeof this.maxAge === "number") {
  1089. return this.maxAge <= 0 ? 0 : this.maxAge * 1e3;
  1090. }
  1091. const expires = this.expires;
  1092. if (expires === "Infinity") {
  1093. return Infinity;
  1094. }
  1095. return (expires?.getTime() ?? now) - (now || Date.now());
  1096. }
  1097. /**
  1098. * Computes the absolute unix-epoch milliseconds that this cookie expires.
  1099. *
  1100. * The "Max-Age" attribute takes precedence over "Expires" (as per the RFC). The {@link Cookie.lastAccessed} attribute
  1101. * (or the `now` parameter if given) is used to offset the {@link Cookie.maxAge} attribute.
  1102. *
  1103. * If Expires ({@link Cookie.expires}) is set, that's returned.
  1104. *
  1105. * @param now - can be used to provide a time offset (instead of {@link Cookie.lastAccessed}) to use when calculating the "Max-Age" value
  1106. */
  1107. expiryTime(now) {
  1108. if (this.maxAge != null) {
  1109. const relativeTo = now || this.lastAccessed || /* @__PURE__ */ new Date();
  1110. const maxAge = typeof this.maxAge === "number" ? this.maxAge : -Infinity;
  1111. const age = maxAge <= 0 ? -Infinity : maxAge * 1e3;
  1112. if (relativeTo === "Infinity") {
  1113. return Infinity;
  1114. }
  1115. return relativeTo.getTime() + age;
  1116. }
  1117. if (this.expires == "Infinity") {
  1118. return Infinity;
  1119. }
  1120. return this.expires ? this.expires.getTime() : void 0;
  1121. }
  1122. /**
  1123. * Similar to {@link Cookie.expiryTime}, computes the absolute unix-epoch milliseconds that this cookie expires and returns it as a Date.
  1124. *
  1125. * The "Max-Age" attribute takes precedence over "Expires" (as per the RFC). The {@link Cookie.lastAccessed} attribute
  1126. * (or the `now` parameter if given) is used to offset the {@link Cookie.maxAge} attribute.
  1127. *
  1128. * If Expires ({@link Cookie.expires}) is set, that's returned.
  1129. *
  1130. * @param now - can be used to provide a time offset (instead of {@link Cookie.lastAccessed}) to use when calculating the "Max-Age" value
  1131. */
  1132. expiryDate(now) {
  1133. const millisec = this.expiryTime(now);
  1134. if (millisec == Infinity) {
  1135. return /* @__PURE__ */ new Date(2147483647e3);
  1136. } else if (millisec == -Infinity) {
  1137. return /* @__PURE__ */ new Date(0);
  1138. } else {
  1139. return millisec == void 0 ? void 0 : new Date(millisec);
  1140. }
  1141. }
  1142. /**
  1143. * Indicates if the cookie has been persisted to a store or not.
  1144. * @public
  1145. */
  1146. isPersistent() {
  1147. return this.maxAge != null || this.expires != "Infinity";
  1148. }
  1149. /**
  1150. * Calls {@link canonicalDomain} with the {@link Cookie.domain} property.
  1151. * @public
  1152. */
  1153. canonicalizedDomain() {
  1154. return canonicalDomain(this.domain);
  1155. }
  1156. /**
  1157. * Alias for {@link Cookie.canonicalizedDomain}
  1158. * @public
  1159. */
  1160. cdomain() {
  1161. return canonicalDomain(this.domain);
  1162. }
  1163. /**
  1164. * Parses a string into a Cookie object.
  1165. *
  1166. * @remarks
  1167. * Note: when parsing a `Cookie` header it must be split by ';' before each Cookie string can be parsed.
  1168. *
  1169. * @example
  1170. * ```
  1171. * // parse a `Set-Cookie` header
  1172. * const setCookieHeader = 'a=bcd; Expires=Tue, 18 Oct 2011 07:05:03 GMT'
  1173. * const cookie = Cookie.parse(setCookieHeader)
  1174. * cookie.key === 'a'
  1175. * cookie.value === 'bcd'
  1176. * cookie.expires === new Date(Date.parse('Tue, 18 Oct 2011 07:05:03 GMT'))
  1177. * ```
  1178. *
  1179. * @example
  1180. * ```
  1181. * // parse a `Cookie` header
  1182. * const cookieHeader = 'name=value; name2=value2; name3=value3'
  1183. * const cookies = cookieHeader.split(';').map(Cookie.parse)
  1184. * cookies[0].name === 'name'
  1185. * cookies[0].value === 'value'
  1186. * cookies[1].name === 'name2'
  1187. * cookies[1].value === 'value2'
  1188. * cookies[2].name === 'name3'
  1189. * cookies[2].value === 'value3'
  1190. * ```
  1191. *
  1192. * @param str - The `Set-Cookie` header or a Cookie string to parse.
  1193. * @param options - Configures `strict` or `loose` mode for cookie parsing
  1194. */
  1195. static parse(str, options) {
  1196. return parse(str, options);
  1197. }
  1198. /**
  1199. * Does the reverse of {@link Cookie.toJSON}.
  1200. *
  1201. * @remarks
  1202. * Any Date properties (such as .expires, .creation, and .lastAccessed) are parsed via Date.parse, not tough-cookie's parseDate, since ISO timestamps are being handled at this layer.
  1203. *
  1204. * @example
  1205. * ```
  1206. * const json = JSON.stringify({
  1207. * key: 'alpha',
  1208. * value: 'beta',
  1209. * domain: 'example.com',
  1210. * path: '/foo',
  1211. * expires: '2038-01-19T03:14:07.000Z',
  1212. * })
  1213. * const cookie = Cookie.fromJSON(json)
  1214. * cookie.key === 'alpha'
  1215. * cookie.value === 'beta'
  1216. * cookie.domain === 'example.com'
  1217. * cookie.path === '/foo'
  1218. * cookie.expires === new Date(Date.parse('2038-01-19T03:14:07.000Z'))
  1219. * ```
  1220. *
  1221. * @param str - An unparsed JSON string or a value that has already been parsed as JSON
  1222. */
  1223. static fromJSON(str) {
  1224. return fromJSON(str);
  1225. }
  1226. };
  1227. _Cookie.cookiesCreated = 0;
  1228. /**
  1229. * @internal
  1230. */
  1231. _Cookie.sameSiteLevel = {
  1232. strict: 3,
  1233. lax: 2,
  1234. none: 1
  1235. };
  1236. /**
  1237. * @internal
  1238. */
  1239. _Cookie.sameSiteCanonical = {
  1240. strict: "Strict",
  1241. lax: "Lax"
  1242. };
  1243. /**
  1244. * Cookie properties that will be serialized when using {@link Cookie.fromJSON} and {@link Cookie.toJSON}.
  1245. * @public
  1246. */
  1247. _Cookie.serializableProperties = [
  1248. "key",
  1249. "value",
  1250. "expires",
  1251. "maxAge",
  1252. "domain",
  1253. "path",
  1254. "secure",
  1255. "httpOnly",
  1256. "extensions",
  1257. "hostOnly",
  1258. "pathIsDefault",
  1259. "creation",
  1260. "lastAccessed",
  1261. "sameSite"
  1262. ];
  1263. var Cookie = _Cookie;
  1264. // lib/cookie/cookieCompare.ts
  1265. var MAX_TIME = 2147483647e3;
  1266. function cookieCompare(a, b) {
  1267. let cmp;
  1268. const aPathLen = a.path ? a.path.length : 0;
  1269. const bPathLen = b.path ? b.path.length : 0;
  1270. cmp = bPathLen - aPathLen;
  1271. if (cmp !== 0) {
  1272. return cmp;
  1273. }
  1274. const aTime = a.creation && a.creation instanceof Date ? a.creation.getTime() : MAX_TIME;
  1275. const bTime = b.creation && b.creation instanceof Date ? b.creation.getTime() : MAX_TIME;
  1276. cmp = aTime - bTime;
  1277. if (cmp !== 0) {
  1278. return cmp;
  1279. }
  1280. cmp = (a.creationIndex || 0) - (b.creationIndex || 0);
  1281. return cmp;
  1282. }
  1283. // lib/cookie/defaultPath.ts
  1284. function defaultPath(path) {
  1285. if (!path || path.slice(0, 1) !== "/") {
  1286. return "/";
  1287. }
  1288. if (path === "/") {
  1289. return path;
  1290. }
  1291. const rightSlash = path.lastIndexOf("/");
  1292. if (rightSlash === 0) {
  1293. return "/";
  1294. }
  1295. return path.slice(0, rightSlash);
  1296. }
  1297. // lib/cookie/domainMatch.ts
  1298. var IP_REGEX_LOWERCASE = /(?:^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$)|(?:^(?:(?:[a-f\d]{1,4}:){7}(?:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,2}|:)|(?:[a-f\d]{1,4}:){4}(?:(?::[a-f\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,3}|:)|(?:[a-f\d]{1,4}:){3}(?:(?::[a-f\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,4}|:)|(?:[a-f\d]{1,4}:){2}(?:(?::[a-f\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,5}|:)|(?:[a-f\d]{1,4}:){1}(?:(?::[a-f\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,6}|:)|(?::(?:(?::[a-f\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,7}|:)))$)/;
  1299. function domainMatch(domain, cookieDomain, canonicalize) {
  1300. if (domain == null || cookieDomain == null) {
  1301. return void 0;
  1302. }
  1303. let _str;
  1304. let _domStr;
  1305. if (canonicalize !== false) {
  1306. _str = canonicalDomain(domain);
  1307. _domStr = canonicalDomain(cookieDomain);
  1308. } else {
  1309. _str = domain;
  1310. _domStr = cookieDomain;
  1311. }
  1312. if (_str == null || _domStr == null) {
  1313. return void 0;
  1314. }
  1315. if (_str == _domStr) {
  1316. return true;
  1317. }
  1318. const idx = _str.lastIndexOf(_domStr);
  1319. if (idx <= 0) {
  1320. return false;
  1321. }
  1322. if (_str.length !== _domStr.length + idx) {
  1323. return false;
  1324. }
  1325. if (_str.substring(idx - 1, idx) !== ".") {
  1326. return false;
  1327. }
  1328. return !IP_REGEX_LOWERCASE.test(_str);
  1329. }
  1330. // lib/cookie/secureContext.ts
  1331. function isLoopbackV4(address) {
  1332. const octets = address.split(".");
  1333. return octets.length === 4 && octets[0] !== void 0 && parseInt(octets[0], 10) === 127;
  1334. }
  1335. function isLoopbackV6(address) {
  1336. return address === "::1";
  1337. }
  1338. function isNormalizedLocalhostTLD(lowerHost) {
  1339. return lowerHost.endsWith(".localhost");
  1340. }
  1341. function isLocalHostname(host) {
  1342. const lowerHost = host.toLowerCase();
  1343. return lowerHost === "localhost" || isNormalizedLocalhostTLD(lowerHost);
  1344. }
  1345. function hostNoBrackets(host) {
  1346. if (host.length >= 2 && host.startsWith("[") && host.endsWith("]")) {
  1347. return host.substring(1, host.length - 1);
  1348. }
  1349. return host;
  1350. }
  1351. function isPotentiallyTrustworthy(inputUrl, allowSecureOnLocal = true) {
  1352. let url;
  1353. if (typeof inputUrl === "string") {
  1354. try {
  1355. url = new URL(inputUrl);
  1356. } catch {
  1357. return false;
  1358. }
  1359. } else {
  1360. url = inputUrl;
  1361. }
  1362. const scheme = url.protocol.replace(":", "").toLowerCase();
  1363. const hostname = hostNoBrackets(url.hostname).replace(/\.+$/, "");
  1364. if (scheme === "https" || scheme === "wss") {
  1365. return true;
  1366. }
  1367. if (!allowSecureOnLocal) {
  1368. return false;
  1369. }
  1370. if (IP_V4_REGEX_OBJECT.test(hostname)) {
  1371. return isLoopbackV4(hostname);
  1372. }
  1373. if (IP_V6_REGEX_OBJECT.test(hostname)) {
  1374. return isLoopbackV6(hostname);
  1375. }
  1376. return isLocalHostname(hostname);
  1377. }
  1378. // lib/cookie/cookieJar.ts
  1379. var defaultSetCookieOptions = {
  1380. loose: false,
  1381. sameSiteContext: void 0,
  1382. ignoreError: false,
  1383. http: true
  1384. };
  1385. var defaultGetCookieOptions = {
  1386. http: true,
  1387. expire: true,
  1388. allPaths: false,
  1389. sameSiteContext: void 0,
  1390. sort: void 0
  1391. };
  1392. var SAME_SITE_CONTEXT_VAL_ERR = 'Invalid sameSiteContext option for getCookies(); expected one of "strict", "lax", or "none"';
  1393. function getCookieContext(url) {
  1394. if (url && typeof url === "object" && "hostname" in url && typeof url.hostname === "string" && "pathname" in url && typeof url.pathname === "string" && "protocol" in url && typeof url.protocol === "string") {
  1395. return {
  1396. hostname: url.hostname,
  1397. pathname: url.pathname,
  1398. protocol: url.protocol
  1399. };
  1400. } else if (typeof url === "string") {
  1401. try {
  1402. return new URL(decodeURI(url));
  1403. } catch {
  1404. return new URL(url);
  1405. }
  1406. } else {
  1407. throw new ParameterError("`url` argument is not a string or URL.");
  1408. }
  1409. }
  1410. function checkSameSiteContext(value) {
  1411. const context = String(value).toLowerCase();
  1412. if (context === "none" || context === "lax" || context === "strict") {
  1413. return context;
  1414. } else {
  1415. return void 0;
  1416. }
  1417. }
  1418. function isSecurePrefixConditionMet(cookie) {
  1419. const startsWithSecurePrefix = typeof cookie.key === "string" && cookie.key.startsWith("__Secure-");
  1420. return !startsWithSecurePrefix || cookie.secure;
  1421. }
  1422. function isHostPrefixConditionMet(cookie) {
  1423. const startsWithHostPrefix = typeof cookie.key === "string" && cookie.key.startsWith("__Host-");
  1424. return !startsWithHostPrefix || Boolean(
  1425. cookie.secure && cookie.hostOnly && cookie.path != null && cookie.path === "/"
  1426. );
  1427. }
  1428. function getNormalizedPrefixSecurity(prefixSecurity) {
  1429. const normalizedPrefixSecurity = prefixSecurity.toLowerCase();
  1430. switch (normalizedPrefixSecurity) {
  1431. case PrefixSecurityEnum.STRICT:
  1432. case PrefixSecurityEnum.SILENT:
  1433. case PrefixSecurityEnum.DISABLED:
  1434. return normalizedPrefixSecurity;
  1435. default:
  1436. return PrefixSecurityEnum.SILENT;
  1437. }
  1438. }
  1439. var CookieJar = class _CookieJar {
  1440. /**
  1441. * Creates a new `CookieJar` instance.
  1442. *
  1443. * @remarks
  1444. * - If a custom store is not passed to the constructor, an in-memory store ({@link MemoryCookieStore} will be created and used.
  1445. * - If a boolean value is passed as the `options` parameter, this is equivalent to passing `{ rejectPublicSuffixes: <value> }`
  1446. *
  1447. * @param store - a custom {@link Store} implementation (defaults to {@link MemoryCookieStore})
  1448. * @param options - configures how cookies are processed by the cookie jar
  1449. */
  1450. constructor(store, options) {
  1451. if (typeof options === "boolean") {
  1452. options = { rejectPublicSuffixes: options };
  1453. }
  1454. this.rejectPublicSuffixes = options?.rejectPublicSuffixes ?? true;
  1455. this.enableLooseMode = options?.looseMode ?? false;
  1456. this.allowSpecialUseDomain = options?.allowSpecialUseDomain ?? true;
  1457. this.allowSecureOnLocal = options?.allowSecureOnLocal ?? true;
  1458. this.prefixSecurity = getNormalizedPrefixSecurity(
  1459. options?.prefixSecurity ?? "silent"
  1460. );
  1461. this.store = store ?? new MemoryCookieStore();
  1462. }
  1463. callSync(fn) {
  1464. if (!this.store.synchronous) {
  1465. throw new Error(
  1466. "CookieJar store is not synchronous; use async API instead."
  1467. );
  1468. }
  1469. let syncErr = null;
  1470. let syncResult = void 0;
  1471. try {
  1472. fn.call(this, (error, result) => {
  1473. syncErr = error;
  1474. syncResult = result;
  1475. });
  1476. } catch (err) {
  1477. syncErr = err;
  1478. }
  1479. if (syncErr) throw syncErr;
  1480. return syncResult;
  1481. }
  1482. /**
  1483. * @internal No doc because this is the overload implementation
  1484. */
  1485. setCookie(cookie, url, options, callback) {
  1486. if (typeof options === "function") {
  1487. callback = options;
  1488. options = void 0;
  1489. }
  1490. const promiseCallback = createPromiseCallback(callback);
  1491. const cb = promiseCallback.callback;
  1492. let context;
  1493. try {
  1494. if (typeof url === "string") {
  1495. validate(
  1496. isNonEmptyString(url),
  1497. callback,
  1498. safeToString(options)
  1499. );
  1500. }
  1501. context = getCookieContext(url);
  1502. if (typeof url === "function") {
  1503. return promiseCallback.reject(new Error("No URL was specified"));
  1504. }
  1505. if (typeof options === "function") {
  1506. options = defaultSetCookieOptions;
  1507. }
  1508. validate(typeof cb === "function", cb);
  1509. if (!isNonEmptyString(cookie) && !isObject(cookie) && cookie instanceof String && cookie.length == 0) {
  1510. return promiseCallback.resolve(void 0);
  1511. }
  1512. } catch (err) {
  1513. return promiseCallback.reject(err);
  1514. }
  1515. const host = canonicalDomain(context.hostname) ?? null;
  1516. const loose = options?.loose || this.enableLooseMode;
  1517. let sameSiteContext = null;
  1518. if (options?.sameSiteContext) {
  1519. sameSiteContext = checkSameSiteContext(options.sameSiteContext);
  1520. if (!sameSiteContext) {
  1521. return promiseCallback.reject(new Error(SAME_SITE_CONTEXT_VAL_ERR));
  1522. }
  1523. }
  1524. if (typeof cookie === "string" || cookie instanceof String) {
  1525. const parsedCookie = Cookie.parse(cookie.toString(), { loose });
  1526. if (!parsedCookie) {
  1527. const err = new Error("Cookie failed to parse");
  1528. return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
  1529. }
  1530. cookie = parsedCookie;
  1531. } else if (!(cookie instanceof Cookie)) {
  1532. const err = new Error(
  1533. "First argument to setCookie must be a Cookie object or string"
  1534. );
  1535. return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
  1536. }
  1537. const now = options?.now || /* @__PURE__ */ new Date();
  1538. if (this.rejectPublicSuffixes && cookie.domain) {
  1539. try {
  1540. const cdomain = cookie.cdomain();
  1541. const suffix = typeof cdomain === "string" ? getPublicSuffix(cdomain, {
  1542. allowSpecialUseDomain: this.allowSpecialUseDomain,
  1543. ignoreError: options?.ignoreError
  1544. }) : null;
  1545. if (suffix == null && !IP_V6_REGEX_OBJECT.test(cookie.domain)) {
  1546. const err = new Error("Cookie has domain set to a public suffix");
  1547. return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
  1548. }
  1549. } catch (err) {
  1550. return options?.ignoreError ? promiseCallback.resolve(void 0) : (
  1551. // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  1552. promiseCallback.reject(err)
  1553. );
  1554. }
  1555. }
  1556. if (cookie.domain) {
  1557. if (!domainMatch(host ?? void 0, cookie.cdomain() ?? void 0, false)) {
  1558. const err = new Error(
  1559. `Cookie not in this host's domain. Cookie:${cookie.cdomain() ?? "null"} Request:${host ?? "null"}`
  1560. );
  1561. return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
  1562. }
  1563. if (cookie.hostOnly == null) {
  1564. cookie.hostOnly = false;
  1565. }
  1566. } else {
  1567. cookie.hostOnly = true;
  1568. cookie.domain = host;
  1569. }
  1570. if (!cookie.path || cookie.path[0] !== "/") {
  1571. cookie.path = defaultPath(context.pathname);
  1572. cookie.pathIsDefault = true;
  1573. }
  1574. if (options?.http === false && cookie.httpOnly) {
  1575. const err = new Error("Cookie is HttpOnly and this isn't an HTTP API");
  1576. return options.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
  1577. }
  1578. if (cookie.sameSite !== "none" && cookie.sameSite !== void 0 && sameSiteContext) {
  1579. if (sameSiteContext === "none") {
  1580. const err = new Error(
  1581. "Cookie is SameSite but this is a cross-origin request"
  1582. );
  1583. return options?.ignoreError ? promiseCallback.resolve(void 0) : promiseCallback.reject(err);
  1584. }
  1585. }
  1586. const ignoreErrorForPrefixSecurity = this.prefixSecurity === PrefixSecurityEnum.SILENT;
  1587. const prefixSecurityDisabled = this.prefixSecurity === PrefixSecurityEnum.DISABLED;
  1588. if (!prefixSecurityDisabled) {
  1589. let errorFound = false;
  1590. let errorMsg;
  1591. if (!isSecurePrefixConditionMet(cookie)) {
  1592. errorFound = true;
  1593. errorMsg = "Cookie has __Secure prefix but Secure attribute is not set";
  1594. } else if (!isHostPrefixConditionMet(cookie)) {
  1595. errorFound = true;
  1596. errorMsg = "Cookie has __Host prefix but either Secure or HostOnly attribute is not set or Path is not '/'";
  1597. }
  1598. if (errorFound) {
  1599. return options?.ignoreError || ignoreErrorForPrefixSecurity ? promiseCallback.resolve(void 0) : promiseCallback.reject(new Error(errorMsg));
  1600. }
  1601. }
  1602. const store = this.store;
  1603. if (!store.updateCookie) {
  1604. store.updateCookie = async function(_oldCookie, newCookie, cb2) {
  1605. return this.putCookie(newCookie).then(
  1606. () => cb2?.(null),
  1607. (error) => cb2?.(error)
  1608. );
  1609. };
  1610. }
  1611. const withCookie = function withCookie2(err, oldCookie) {
  1612. if (err) {
  1613. cb(err);
  1614. return;
  1615. }
  1616. const next = function(err2) {
  1617. if (err2) {
  1618. cb(err2);
  1619. } else if (typeof cookie === "string") {
  1620. cb(null, void 0);
  1621. } else {
  1622. cb(null, cookie);
  1623. }
  1624. };
  1625. if (oldCookie) {
  1626. if (options && "http" in options && options.http === false && oldCookie.httpOnly) {
  1627. err = new Error("old Cookie is HttpOnly and this isn't an HTTP API");
  1628. if (options.ignoreError) cb(null, void 0);
  1629. else cb(err);
  1630. return;
  1631. }
  1632. if (cookie instanceof Cookie) {
  1633. cookie.creation = oldCookie.creation;
  1634. cookie.creationIndex = oldCookie.creationIndex;
  1635. cookie.lastAccessed = now;
  1636. store.updateCookie(oldCookie, cookie, next);
  1637. }
  1638. } else {
  1639. if (cookie instanceof Cookie) {
  1640. cookie.creation = cookie.lastAccessed = now;
  1641. store.putCookie(cookie, next);
  1642. }
  1643. }
  1644. };
  1645. store.findCookie(cookie.domain, cookie.path, cookie.key, withCookie);
  1646. return promiseCallback.promise;
  1647. }
  1648. /**
  1649. * Synchronously attempt to set the {@link Cookie} in the {@link CookieJar}.
  1650. *
  1651. * <strong>Note:</strong> Only works if the configured {@link Store} is also synchronous.
  1652. *
  1653. * @remarks
  1654. * - If successfully persisted, the {@link Cookie} will have updated
  1655. * {@link Cookie.creation}, {@link Cookie.lastAccessed} and {@link Cookie.hostOnly}
  1656. * properties.
  1657. *
  1658. * - As per the RFC, the {@link Cookie.hostOnly} flag is set if there was no `Domain={value}`
  1659. * attribute on the cookie string. The {@link Cookie.domain} property is set to the
  1660. * fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an
  1661. * exact hostname match (not a {@link domainMatch} as per usual)
  1662. *
  1663. * @param cookie - The cookie object or cookie string to store. A string value will be parsed into a cookie using {@link Cookie.parse}.
  1664. * @param url - The domain to store the cookie with.
  1665. * @param options - Configuration settings to use when storing the cookie.
  1666. * @public
  1667. */
  1668. setCookieSync(cookie, url, options) {
  1669. const setCookieFn = options ? this.setCookie.bind(this, cookie, url, options) : this.setCookie.bind(this, cookie, url);
  1670. return this.callSync(setCookieFn);
  1671. }
  1672. /**
  1673. * @internal No doc because this is the overload implementation
  1674. */
  1675. getCookies(url, options, callback) {
  1676. if (typeof options === "function") {
  1677. callback = options;
  1678. options = defaultGetCookieOptions;
  1679. } else if (options === void 0) {
  1680. options = defaultGetCookieOptions;
  1681. }
  1682. const promiseCallback = createPromiseCallback(callback);
  1683. const cb = promiseCallback.callback;
  1684. let context;
  1685. try {
  1686. if (typeof url === "string") {
  1687. validate(isNonEmptyString(url), cb, url);
  1688. }
  1689. context = getCookieContext(url);
  1690. validate(
  1691. isObject(options),
  1692. cb,
  1693. safeToString(options)
  1694. );
  1695. validate(typeof cb === "function", cb);
  1696. } catch (parameterError) {
  1697. return promiseCallback.reject(parameterError);
  1698. }
  1699. const host = canonicalDomain(context.hostname);
  1700. const path = context.pathname || "/";
  1701. const potentiallyTrustworthy = isPotentiallyTrustworthy(
  1702. url,
  1703. this.allowSecureOnLocal
  1704. );
  1705. let sameSiteLevel = 0;
  1706. if (options.sameSiteContext) {
  1707. const sameSiteContext = checkSameSiteContext(options.sameSiteContext);
  1708. if (sameSiteContext == null) {
  1709. return promiseCallback.reject(new Error(SAME_SITE_CONTEXT_VAL_ERR));
  1710. }
  1711. sameSiteLevel = Cookie.sameSiteLevel[sameSiteContext];
  1712. if (!sameSiteLevel) {
  1713. return promiseCallback.reject(new Error(SAME_SITE_CONTEXT_VAL_ERR));
  1714. }
  1715. }
  1716. const http = options.http ?? true;
  1717. const now = Date.now();
  1718. const expireCheck = options.expire ?? true;
  1719. const allPaths = options.allPaths ?? false;
  1720. const store = this.store;
  1721. function matchingCookie(c) {
  1722. if (c.hostOnly) {
  1723. if (c.domain != host) {
  1724. return false;
  1725. }
  1726. } else {
  1727. if (!domainMatch(host ?? void 0, c.domain ?? void 0, false)) {
  1728. return false;
  1729. }
  1730. }
  1731. if (!allPaths && typeof c.path === "string" && !pathMatch(path, c.path)) {
  1732. return false;
  1733. }
  1734. if (c.secure && !potentiallyTrustworthy) {
  1735. return false;
  1736. }
  1737. if (c.httpOnly && !http) {
  1738. return false;
  1739. }
  1740. if (sameSiteLevel) {
  1741. let cookieLevel;
  1742. if (c.sameSite === "lax") {
  1743. cookieLevel = Cookie.sameSiteLevel.lax;
  1744. } else if (c.sameSite === "strict") {
  1745. cookieLevel = Cookie.sameSiteLevel.strict;
  1746. } else {
  1747. cookieLevel = Cookie.sameSiteLevel.none;
  1748. }
  1749. if (cookieLevel > sameSiteLevel) {
  1750. return false;
  1751. }
  1752. }
  1753. const expiryTime = c.expiryTime();
  1754. if (expireCheck && expiryTime != void 0 && expiryTime <= now) {
  1755. store.removeCookie(c.domain, c.path, c.key, () => {
  1756. });
  1757. return false;
  1758. }
  1759. return true;
  1760. }
  1761. store.findCookies(
  1762. host,
  1763. allPaths ? null : path,
  1764. this.allowSpecialUseDomain,
  1765. (err, cookies) => {
  1766. if (err) {
  1767. cb(err);
  1768. return;
  1769. }
  1770. if (cookies == null) {
  1771. cb(null, []);
  1772. return;
  1773. }
  1774. cookies = cookies.filter(matchingCookie);
  1775. if ("sort" in options && options.sort !== false) {
  1776. cookies = cookies.sort(cookieCompare);
  1777. }
  1778. const now2 = /* @__PURE__ */ new Date();
  1779. for (const cookie of cookies) {
  1780. cookie.lastAccessed = now2;
  1781. }
  1782. cb(null, cookies);
  1783. }
  1784. );
  1785. return promiseCallback.promise;
  1786. }
  1787. /**
  1788. * Synchronously retrieve the list of cookies that can be sent in a Cookie header for the
  1789. * current URL.
  1790. *
  1791. * <strong>Note</strong>: Only works if the configured Store is also synchronous.
  1792. *
  1793. * @remarks
  1794. * - The array of cookies returned will be sorted according to {@link cookieCompare}.
  1795. *
  1796. * - The {@link Cookie.lastAccessed} property will be updated on all returned cookies.
  1797. *
  1798. * @param url - The domain to store the cookie with.
  1799. * @param options - Configuration settings to use when retrieving the cookies.
  1800. */
  1801. getCookiesSync(url, options) {
  1802. return this.callSync(this.getCookies.bind(this, url, options)) ?? [];
  1803. }
  1804. /**
  1805. * @internal No doc because this is the overload implementation
  1806. */
  1807. getCookieString(url, options, callback) {
  1808. if (typeof options === "function") {
  1809. callback = options;
  1810. options = void 0;
  1811. }
  1812. const promiseCallback = createPromiseCallback(callback);
  1813. const next = function(err, cookies) {
  1814. if (err) {
  1815. promiseCallback.callback(err);
  1816. } else {
  1817. promiseCallback.callback(
  1818. null,
  1819. cookies?.sort(cookieCompare).map((c) => c.cookieString()).join("; ")
  1820. );
  1821. }
  1822. };
  1823. this.getCookies(url, options, next);
  1824. return promiseCallback.promise;
  1825. }
  1826. /**
  1827. * Synchronous version of `.getCookieString()`. Accepts the same options as `.getCookies()` but returns a string suitable for a
  1828. * `Cookie` header rather than an Array.
  1829. *
  1830. * <strong>Note</strong>: Only works if the configured Store is also synchronous.
  1831. *
  1832. * @param url - The domain to store the cookie with.
  1833. * @param options - Configuration settings to use when retrieving the cookies.
  1834. */
  1835. getCookieStringSync(url, options) {
  1836. return this.callSync(
  1837. options ? this.getCookieString.bind(this, url, options) : this.getCookieString.bind(this, url)
  1838. ) ?? "";
  1839. }
  1840. /**
  1841. * @internal No doc because this is the overload implementation
  1842. */
  1843. getSetCookieStrings(url, options, callback) {
  1844. if (typeof options === "function") {
  1845. callback = options;
  1846. options = void 0;
  1847. }
  1848. const promiseCallback = createPromiseCallback(
  1849. callback
  1850. );
  1851. const next = function(err, cookies) {
  1852. if (err) {
  1853. promiseCallback.callback(err);
  1854. } else {
  1855. promiseCallback.callback(
  1856. null,
  1857. cookies?.map((c) => {
  1858. return c.toString();
  1859. })
  1860. );
  1861. }
  1862. };
  1863. this.getCookies(url, options, next);
  1864. return promiseCallback.promise;
  1865. }
  1866. /**
  1867. * Synchronous version of `.getSetCookieStrings()`. Returns an array of strings suitable for `Set-Cookie` headers.
  1868. * Accepts the same options as `.getCookies()`.
  1869. *
  1870. * <strong>Note</strong>: Only works if the configured Store is also synchronous.
  1871. *
  1872. * @param url - The domain to store the cookie with.
  1873. * @param options - Configuration settings to use when retrieving the cookies.
  1874. */
  1875. getSetCookieStringsSync(url, options = {}) {
  1876. return this.callSync(this.getSetCookieStrings.bind(this, url, options)) ?? [];
  1877. }
  1878. /**
  1879. * @internal No doc because this is the overload implementation
  1880. */
  1881. serialize(callback) {
  1882. const promiseCallback = createPromiseCallback(callback);
  1883. let type = this.store.constructor.name;
  1884. if (isObject(type)) {
  1885. type = null;
  1886. }
  1887. const serialized = {
  1888. // The version of tough-cookie that serialized this jar. Generally a good
  1889. // practice since future versions can make data import decisions based on
  1890. // known past behavior. When/if this matters, use `semver`.
  1891. version: `tough-cookie@${version}`,
  1892. // add the store type, to make humans happy:
  1893. storeType: type,
  1894. // CookieJar configuration:
  1895. rejectPublicSuffixes: this.rejectPublicSuffixes,
  1896. enableLooseMode: this.enableLooseMode,
  1897. allowSpecialUseDomain: this.allowSpecialUseDomain,
  1898. prefixSecurity: getNormalizedPrefixSecurity(this.prefixSecurity),
  1899. // this gets filled from getAllCookies:
  1900. cookies: []
  1901. };
  1902. if (typeof this.store.getAllCookies !== "function") {
  1903. return promiseCallback.reject(
  1904. new Error(
  1905. "store does not support getAllCookies and cannot be serialized"
  1906. )
  1907. );
  1908. }
  1909. this.store.getAllCookies((err, cookies) => {
  1910. if (err) {
  1911. promiseCallback.callback(err);
  1912. return;
  1913. }
  1914. if (cookies == null) {
  1915. promiseCallback.callback(null, serialized);
  1916. return;
  1917. }
  1918. serialized.cookies = cookies.map((cookie) => {
  1919. const serializedCookie = cookie.toJSON();
  1920. delete serializedCookie.creationIndex;
  1921. return serializedCookie;
  1922. });
  1923. promiseCallback.callback(null, serialized);
  1924. });
  1925. return promiseCallback.promise;
  1926. }
  1927. /**
  1928. * Serialize the CookieJar if the underlying store supports `.getAllCookies`.
  1929. *
  1930. * <strong>Note</strong>: Only works if the configured Store is also synchronous.
  1931. */
  1932. serializeSync() {
  1933. return this.callSync((callback) => {
  1934. this.serialize(callback);
  1935. });
  1936. }
  1937. /**
  1938. * Alias of {@link CookieJar.serializeSync}. Allows the cookie to be serialized
  1939. * with `JSON.stringify(cookieJar)`.
  1940. */
  1941. toJSON() {
  1942. return this.serializeSync();
  1943. }
  1944. /**
  1945. * Use the class method CookieJar.deserialize instead of calling this directly
  1946. * @internal
  1947. */
  1948. _importCookies(serialized, callback) {
  1949. let cookies = void 0;
  1950. if (serialized && typeof serialized === "object" && inOperator("cookies", serialized) && Array.isArray(serialized.cookies)) {
  1951. cookies = serialized.cookies;
  1952. }
  1953. if (!cookies) {
  1954. callback(new Error("serialized jar has no cookies array"), void 0);
  1955. return;
  1956. }
  1957. cookies = cookies.slice();
  1958. const putNext = (err) => {
  1959. if (err) {
  1960. callback(err, void 0);
  1961. return;
  1962. }
  1963. if (Array.isArray(cookies)) {
  1964. if (!cookies.length) {
  1965. callback(err, this);
  1966. return;
  1967. }
  1968. let cookie;
  1969. try {
  1970. cookie = Cookie.fromJSON(cookies.shift());
  1971. } catch (e) {
  1972. callback(e instanceof Error ? e : new Error(), void 0);
  1973. return;
  1974. }
  1975. if (cookie === void 0) {
  1976. putNext(null);
  1977. return;
  1978. }
  1979. this.store.putCookie(cookie, putNext);
  1980. }
  1981. };
  1982. putNext(null);
  1983. }
  1984. /**
  1985. * @internal
  1986. */
  1987. _importCookiesSync(serialized) {
  1988. this.callSync(this._importCookies.bind(this, serialized));
  1989. }
  1990. /**
  1991. * @internal No doc because this is the overload implementation
  1992. */
  1993. clone(newStore, callback) {
  1994. if (typeof newStore === "function") {
  1995. callback = newStore;
  1996. newStore = void 0;
  1997. }
  1998. const promiseCallback = createPromiseCallback(callback);
  1999. const cb = promiseCallback.callback;
  2000. this.serialize((err, serialized) => {
  2001. if (err) {
  2002. return promiseCallback.reject(err);
  2003. }
  2004. return _CookieJar.deserialize(serialized ?? "", newStore, cb);
  2005. });
  2006. return promiseCallback.promise;
  2007. }
  2008. /**
  2009. * @internal
  2010. */
  2011. _cloneSync(newStore) {
  2012. const cloneFn = newStore && typeof newStore !== "function" ? this.clone.bind(this, newStore) : this.clone.bind(this);
  2013. return this.callSync((callback) => {
  2014. cloneFn(callback);
  2015. });
  2016. }
  2017. /**
  2018. * Produces a deep clone of this CookieJar. Modifications to the original do
  2019. * not affect the clone, and vice versa.
  2020. *
  2021. * <strong>Note</strong>: Only works if both the configured Store and destination
  2022. * Store are synchronous.
  2023. *
  2024. * @remarks
  2025. * - When no {@link Store} is provided, a new {@link MemoryCookieStore} will be used.
  2026. *
  2027. * - Transferring between store types is supported so long as the source
  2028. * implements `.getAllCookies()` and the destination implements `.putCookie()`.
  2029. *
  2030. * @param newStore - The target {@link Store} to clone cookies into.
  2031. */
  2032. cloneSync(newStore) {
  2033. if (!newStore) {
  2034. return this._cloneSync();
  2035. }
  2036. if (!newStore.synchronous) {
  2037. throw new Error(
  2038. "CookieJar clone destination store is not synchronous; use async API instead."
  2039. );
  2040. }
  2041. return this._cloneSync(newStore);
  2042. }
  2043. /**
  2044. * @internal No doc because this is the overload implementation
  2045. */
  2046. removeAllCookies(callback) {
  2047. const promiseCallback = createPromiseCallback(callback);
  2048. const cb = promiseCallback.callback;
  2049. const store = this.store;
  2050. if (typeof store.removeAllCookies === "function" && store.removeAllCookies !== Store.prototype.removeAllCookies) {
  2051. store.removeAllCookies(cb);
  2052. return promiseCallback.promise;
  2053. }
  2054. store.getAllCookies((err, cookies) => {
  2055. if (err) {
  2056. cb(err);
  2057. return;
  2058. }
  2059. if (!cookies) {
  2060. cookies = [];
  2061. }
  2062. if (cookies.length === 0) {
  2063. cb(null, void 0);
  2064. return;
  2065. }
  2066. let completedCount = 0;
  2067. const removeErrors = [];
  2068. const removeCookieCb = function removeCookieCb2(removeErr) {
  2069. if (removeErr) {
  2070. removeErrors.push(removeErr);
  2071. }
  2072. completedCount++;
  2073. if (completedCount === cookies.length) {
  2074. if (removeErrors[0]) cb(removeErrors[0]);
  2075. else cb(null, void 0);
  2076. return;
  2077. }
  2078. };
  2079. cookies.forEach((cookie) => {
  2080. store.removeCookie(
  2081. cookie.domain,
  2082. cookie.path,
  2083. cookie.key,
  2084. removeCookieCb
  2085. );
  2086. });
  2087. });
  2088. return promiseCallback.promise;
  2089. }
  2090. /**
  2091. * Removes all cookies from the CookieJar.
  2092. *
  2093. * <strong>Note</strong>: Only works if the configured Store is also synchronous.
  2094. *
  2095. * @remarks
  2096. * - This is a new backwards-compatible feature of tough-cookie version 2.5,
  2097. * so not all Stores will implement it efficiently. For Stores that do not
  2098. * implement `removeAllCookies`, the fallback is to call `removeCookie` after
  2099. * `getAllCookies`.
  2100. *
  2101. * - If `getAllCookies` fails or isn't implemented in the Store, an error is returned.
  2102. *
  2103. * - If one or more of the `removeCookie` calls fail, only the first error is returned.
  2104. */
  2105. removeAllCookiesSync() {
  2106. this.callSync((callback) => {
  2107. this.removeAllCookies(callback);
  2108. });
  2109. }
  2110. /**
  2111. * @internal No doc because this is the overload implementation
  2112. */
  2113. static deserialize(strOrObj, store, callback) {
  2114. if (typeof store === "function") {
  2115. callback = store;
  2116. store = void 0;
  2117. }
  2118. const promiseCallback = createPromiseCallback(callback);
  2119. let serialized;
  2120. if (typeof strOrObj === "string") {
  2121. try {
  2122. serialized = JSON.parse(strOrObj);
  2123. } catch (e) {
  2124. return promiseCallback.reject(e instanceof Error ? e : new Error());
  2125. }
  2126. } else {
  2127. serialized = strOrObj;
  2128. }
  2129. const readSerializedProperty = (property) => {
  2130. return serialized && typeof serialized === "object" && inOperator(property, serialized) ? serialized[property] : void 0;
  2131. };
  2132. const readSerializedBoolean = (property) => {
  2133. const value = readSerializedProperty(property);
  2134. return typeof value === "boolean" ? value : void 0;
  2135. };
  2136. const readSerializedString = (property) => {
  2137. const value = readSerializedProperty(property);
  2138. return typeof value === "string" ? value : void 0;
  2139. };
  2140. const jar = new _CookieJar(store, {
  2141. rejectPublicSuffixes: readSerializedBoolean("rejectPublicSuffixes"),
  2142. looseMode: readSerializedBoolean("enableLooseMode"),
  2143. allowSpecialUseDomain: readSerializedBoolean("allowSpecialUseDomain"),
  2144. prefixSecurity: getNormalizedPrefixSecurity(
  2145. readSerializedString("prefixSecurity") ?? "silent"
  2146. )
  2147. });
  2148. jar._importCookies(serialized, (err) => {
  2149. if (err) {
  2150. promiseCallback.callback(err);
  2151. return;
  2152. }
  2153. promiseCallback.callback(null, jar);
  2154. });
  2155. return promiseCallback.promise;
  2156. }
  2157. /**
  2158. * A new CookieJar is created and the serialized {@link Cookie} values are added to
  2159. * the underlying store. Each {@link Cookie} is added via `store.putCookie(...)` in
  2160. * the order in which they appear in the serialization.
  2161. *
  2162. * <strong>Note</strong>: Only works if the configured Store is also synchronous.
  2163. *
  2164. * @remarks
  2165. * - When no {@link Store} is provided, a new {@link MemoryCookieStore} will be used.
  2166. *
  2167. * - As a convenience, if `strOrObj` is a string, it is passed through `JSON.parse` first.
  2168. *
  2169. * @param strOrObj - A JSON string or object representing the deserialized cookies.
  2170. * @param store - The underlying store to persist the deserialized cookies into.
  2171. */
  2172. static deserializeSync(strOrObj, store) {
  2173. const serialized = typeof strOrObj === "string" ? JSON.parse(strOrObj) : strOrObj;
  2174. const readSerializedProperty = (property) => {
  2175. return serialized && typeof serialized === "object" && inOperator(property, serialized) ? serialized[property] : void 0;
  2176. };
  2177. const readSerializedBoolean = (property) => {
  2178. const value = readSerializedProperty(property);
  2179. return typeof value === "boolean" ? value : void 0;
  2180. };
  2181. const readSerializedString = (property) => {
  2182. const value = readSerializedProperty(property);
  2183. return typeof value === "string" ? value : void 0;
  2184. };
  2185. const jar = new _CookieJar(store, {
  2186. rejectPublicSuffixes: readSerializedBoolean("rejectPublicSuffixes"),
  2187. looseMode: readSerializedBoolean("enableLooseMode"),
  2188. allowSpecialUseDomain: readSerializedBoolean("allowSpecialUseDomain"),
  2189. prefixSecurity: getNormalizedPrefixSecurity(
  2190. readSerializedString("prefixSecurity") ?? "silent"
  2191. )
  2192. });
  2193. if (!jar.store.synchronous) {
  2194. throw new Error(
  2195. "CookieJar store is not synchronous; use async API instead."
  2196. );
  2197. }
  2198. jar._importCookiesSync(serialized);
  2199. return jar;
  2200. }
  2201. /**
  2202. * Alias of {@link CookieJar.deserializeSync}.
  2203. *
  2204. * @remarks
  2205. * - When no {@link Store} is provided, a new {@link MemoryCookieStore} will be used.
  2206. *
  2207. * - As a convenience, if `strOrObj` is a string, it is passed through `JSON.parse` first.
  2208. *
  2209. * @param jsonString - A JSON string or object representing the deserialized cookies.
  2210. * @param store - The underlying store to persist the deserialized cookies into.
  2211. */
  2212. static fromJSON(jsonString, store) {
  2213. return _CookieJar.deserializeSync(jsonString, store);
  2214. }
  2215. };
  2216. // lib/cookie/permutePath.ts
  2217. function permutePath(path) {
  2218. if (path === "/") {
  2219. return ["/"];
  2220. }
  2221. const permutations = [path];
  2222. while (path.length > 1) {
  2223. const lindex = path.lastIndexOf("/");
  2224. if (lindex === 0) {
  2225. break;
  2226. }
  2227. path = path.slice(0, lindex);
  2228. permutations.push(path);
  2229. }
  2230. permutations.push("/");
  2231. return permutations;
  2232. }
  2233. // lib/cookie/index.ts
  2234. function parse2(str, options) {
  2235. return Cookie.parse(str, options);
  2236. }
  2237. function fromJSON2(str) {
  2238. return Cookie.fromJSON(str);
  2239. }
  2240. // Annotate the CommonJS export names for ESM import in node:
  2241. 0 && (module.exports = {
  2242. Cookie,
  2243. CookieJar,
  2244. MemoryCookieStore,
  2245. ParameterError,
  2246. PrefixSecurityEnum,
  2247. Store,
  2248. canonicalDomain,
  2249. cookieCompare,
  2250. defaultPath,
  2251. domainMatch,
  2252. formatDate,
  2253. fromJSON,
  2254. getPublicSuffix,
  2255. parse,
  2256. parseDate,
  2257. pathMatch,
  2258. permuteDomain,
  2259. permutePath,
  2260. version
  2261. });
  2262. /*!
  2263. * Copyright (c) 2015-2020, Salesforce.com, Inc.
  2264. * All rights reserved.
  2265. *
  2266. * Redistribution and use in source and binary forms, with or without
  2267. * modification, are permitted provided that the following conditions are met:
  2268. *
  2269. * 1. Redistributions of source code must retain the above copyright notice,
  2270. * this list of conditions and the following disclaimer.
  2271. *
  2272. * 2. Redistributions in binary form must reproduce the above copyright notice,
  2273. * this list of conditions and the following disclaimer in the documentation
  2274. * and/or other materials provided with the distribution.
  2275. *
  2276. * 3. Neither the name of Salesforce.com nor the names of its contributors may
  2277. * be used to endorse or promote products derived from this software without
  2278. * specific prior written permission.
  2279. *
  2280. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  2281. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2282. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2283. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  2284. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  2285. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  2286. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  2287. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  2288. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  2289. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  2290. * POSSIBILITY OF SUCH DAMAGE.
  2291. */
  2292. //# sourceMappingURL=index.cjs.map