+
[version](./tough-cookie.version.md)
diff --git a/api/docs/tough-cookie.prefixsecurity.md b/api/docs/tough-cookie.prefixsecurity.md
deleted file mode 100644
index 8887f1ab..00000000
--- a/api/docs/tough-cookie.prefixsecurity.md
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-[Home](./index.md) > [tough-cookie](./tough-cookie.md) > [PrefixSecurity](./tough-cookie.prefixsecurity.md)
-
-## PrefixSecurity enum
-
-Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the first few characters of the cookie's name. These are defined in [RFC6265bis - Section 4.1.3](https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-13#section-4.1.3).
-
-The following values can be used to configure how a [CookieJar](./tough-cookie.cookiejar.md) enforces attribute restrictions for Cookie prefixes.
-
-**Signature:**
-
-```typescript
-export declare enum PrefixSecurity
-```
-
-## Enumeration Members
-
-
-
-Member
-
-
- |
-
-Value
-
-
- |
-
-Description
-
-
- |
-
-
-DISABLED
-
-
- |
-
-`"unsafe-disabled"`
-
-
- |
-
-Disables cookie prefix checking.
-
-
- |
-
-
-SILENT
-
-
- |
-
-`"silent"`
-
-
- |
-
-Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a [CookieJar](./tough-cookie.cookiejar.md).
-
-
- |
-
-
-STRICT
-
-
- |
-
-`"strict"`
-
-
- |
-
-Enables cookie prefix checking and will raise an error if conditions are not met.
-
-
- |
-
diff --git a/api/tough-cookie.api.md b/api/tough-cookie.api.md
index b383d4e1..424a50c4 100644
--- a/api/tough-cookie.api.md
+++ b/api/tough-cookie.api.md
@@ -254,11 +254,11 @@ export function permuteDomain(domain: string, allowSpecialUseDomain?: boolean):
export function permutePath(path: string): string[];
// @public
-export enum PrefixSecurity {
- DISABLED = "unsafe-disabled",
- SILENT = "silent",
- STRICT = "strict"
-}
+export const PrefixSecurityEnum: Readonly<{
+ SILENT: "silent";
+ STRICT: "strict";
+ DISABLED: "unsafe-disabled";
+}>;
// @public
export interface SerializedCookieJar {
diff --git a/lib/__tests__/cookiePrefixes.spec.ts b/lib/__tests__/cookiePrefixes.spec.ts
index 96759fb9..770f53a9 100644
--- a/lib/__tests__/cookiePrefixes.spec.ts
+++ b/lib/__tests__/cookiePrefixes.spec.ts
@@ -1,4 +1,4 @@
-import { PrefixSecurity } from '../cookie/constants'
+import { PrefixSecurityEnum } from '../cookie/constants'
import { CookieJar } from '../cookie/cookieJar'
let cookieJar: CookieJar
@@ -11,7 +11,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
cookieJar = new CookieJar(null, {
prefixSecurity: 'silent',
})
- expect(cookieJar.prefixSecurity).toBe(PrefixSecurity.SILENT)
+ expect(cookieJar.prefixSecurity).toBe(PrefixSecurityEnum.SILENT)
})
describe('__Secure prefix', () => {
@@ -106,7 +106,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
cookieJar = new CookieJar(null, {
prefixSecurity: 'strict',
})
- expect(cookieJar.prefixSecurity).toBe(PrefixSecurity.STRICT)
+ expect(cookieJar.prefixSecurity).toBe(PrefixSecurityEnum.STRICT)
})
describe('__Secure prefix', () => {
@@ -173,7 +173,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
cookieJar = new CookieJar(null, {
prefixSecurity: 'unsafe-disabled',
})
- expect(cookieJar.prefixSecurity).toBe(PrefixSecurity.DISABLED)
+ expect(cookieJar.prefixSecurity).toBe(PrefixSecurityEnum.DISABLED)
})
describe('__Secure prefix', () => {
diff --git a/lib/cookie/constants.ts b/lib/cookie/constants.ts
index aea9b1e7..0af44db5 100644
--- a/lib/cookie/constants.ts
+++ b/lib/cookie/constants.ts
@@ -2,23 +2,20 @@
* Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the
* first few characters of the cookie's name. These are defined in {@link https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-13#section-4.1.3 | RFC6265bis - Section 4.1.3}.
*
- * The following values can be used to configure how a {@link CookieJar} enforces attribute restrictions for Cookie prefixes.
+ * The following values can be used to configure how a {@link CookieJar} enforces attribute restrictions for Cookie prefixes:
+ *
+ * - `silent` - Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a {@link CookieJar}.
+ *
+ * - `strict` - Enables cookie prefix checking and will raise an error if conditions are not met.
+ *
+ * - `unsafe-disabled` - Disables cookie prefix checking.
* @public
*/
-export enum PrefixSecurity {
- /**
- * Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a {@link CookieJar}.
- */
- SILENT = 'silent',
- /**
- * Enables cookie prefix checking and will raise an error if conditions are not met.
- */
- STRICT = 'strict',
- /**
- * Disables cookie prefix checking.
- */
- DISABLED = 'unsafe-disabled',
-}
+export const PrefixSecurityEnum = Object.freeze({
+ SILENT: 'silent',
+ STRICT: 'strict',
+ DISABLED: 'unsafe-disabled',
+})
const IP_V6_REGEX = `
\\[?(?:
diff --git a/lib/cookie/cookieJar.ts b/lib/cookie/cookieJar.ts
index ecfe5f71..e87b111e 100644
--- a/lib/cookie/cookieJar.ts
+++ b/lib/cookie/cookieJar.ts
@@ -18,7 +18,7 @@ import {
import { canonicalDomain } from './canonicalDomain'
import {
IP_V6_REGEX_OBJECT,
- PrefixSecurity,
+ PrefixSecurityEnum,
SerializedCookieJar,
} from './constants'
import { defaultPath } from './defaultPath'
@@ -256,7 +256,8 @@ function isHostPrefixConditionMet(cookie: Cookie): boolean {
)
}
-type PrefixSecurityValue = (typeof PrefixSecurity)[keyof typeof PrefixSecurity]
+type PrefixSecurityValue =
+ (typeof PrefixSecurityEnum)[keyof typeof PrefixSecurityEnum]
function getNormalizedPrefixSecurity(
prefixSecurity: string,
): PrefixSecurityValue {
@@ -264,14 +265,14 @@ function getNormalizedPrefixSecurity(
const normalizedPrefixSecurity = prefixSecurity.toLowerCase()
/* The three supported options */
switch (normalizedPrefixSecurity) {
- case PrefixSecurity.STRICT:
- case PrefixSecurity.SILENT:
- case PrefixSecurity.DISABLED:
+ case PrefixSecurityEnum.STRICT:
+ case PrefixSecurityEnum.SILENT:
+ case PrefixSecurityEnum.DISABLED:
return normalizedPrefixSecurity
}
}
/* Default is SILENT */
- return PrefixSecurity.SILENT
+ return PrefixSecurityEnum.SILENT
}
/**
@@ -606,9 +607,9 @@ export class CookieJar {
/* 6265bis-02 S5.4 Steps 15 & 16 */
const ignoreErrorForPrefixSecurity =
- this.prefixSecurity === PrefixSecurity.SILENT
+ this.prefixSecurity === PrefixSecurityEnum.SILENT
const prefixSecurityDisabled =
- this.prefixSecurity === PrefixSecurity.DISABLED
+ this.prefixSecurity === PrefixSecurityEnum.DISABLED
/* If prefix checking is not disabled ...*/
if (!prefixSecurityDisabled) {
let errorFound = false
diff --git a/lib/cookie/index.ts b/lib/cookie/index.ts
index 10092e9d..e14c7999 100644
--- a/lib/cookie/index.ts
+++ b/lib/cookie/index.ts
@@ -7,7 +7,7 @@ export { ParameterError } from '../validators'
export { version } from '../version'
export { Callback, ErrorCallback } from '../utils'
export { canonicalDomain } from './canonicalDomain'
-export { PrefixSecurity, SerializedCookieJar } from './constants'
+export { PrefixSecurityEnum, SerializedCookieJar } from './constants'
export { Cookie } from './cookie'
export { cookieCompare } from './cookieCompare'
export {
|