ngx-cookie-service 19.1.2 → 20.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/ngx-cookie-service.mjs +8 -11
- package/fesm2022/ngx-cookie-service.mjs.map +1 -1
- package/index.d.ts +137 -6
- package/index.d.ts.map +1 -0
- package/package.json +4 -3
- package/lib/cookie.service.d.ts +0 -133
- package/lib/cookie.service.d.ts.map +0 -1
- package/ngx-cookie-service.d.ts.map +0 -1
- package/public-api.d.ts +0 -2
- package/public-api.d.ts.map +0 -1
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { isPlatformBrowser
|
|
1
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import {
|
|
3
|
+
import { DOCUMENT, PLATFORM_ID, Inject, Injectable } from '@angular/core';
|
|
4
4
|
|
|
5
|
-
// This service is based on the `ng2-cookies` package which sadly is not a service and does
|
|
6
|
-
// not use `DOCUMENT` injection and therefore doesn't work well with AoT production builds.
|
|
7
|
-
// Package: https://github.com/BCJTI/ng2-cookies
|
|
8
5
|
class CookieService {
|
|
9
6
|
constructor(document, // Get the `PLATFORM_ID` so we can check if we're in a browser.
|
|
10
7
|
platformId) {
|
|
@@ -22,7 +19,7 @@ class CookieService {
|
|
|
22
19
|
* @since: 1.0.0
|
|
23
20
|
*/
|
|
24
21
|
static getCookieRegExp(name) {
|
|
25
|
-
const escapedName = name.replace(/([
|
|
22
|
+
const escapedName = name.replace(/([[\]{}()|=;+?,.*^$\\])/gi, '\\$1');
|
|
26
23
|
return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
@@ -75,7 +72,7 @@ class CookieService {
|
|
|
75
72
|
name = encodeURIComponent(name);
|
|
76
73
|
const regExp = CookieService.getCookieRegExp(name);
|
|
77
74
|
const result = regExp.exec(this.document.cookie);
|
|
78
|
-
return result
|
|
75
|
+
return result?.[1] ? CookieService.safeDecodeURIComponent(result[1]) : '';
|
|
79
76
|
}
|
|
80
77
|
else {
|
|
81
78
|
return '';
|
|
@@ -113,7 +110,7 @@ class CookieService {
|
|
|
113
110
|
path,
|
|
114
111
|
domain,
|
|
115
112
|
secure,
|
|
116
|
-
sameSite: sameSite
|
|
113
|
+
sameSite: sameSite || 'Lax',
|
|
117
114
|
partitioned,
|
|
118
115
|
};
|
|
119
116
|
this.set(name, value, optionsBody);
|
|
@@ -194,10 +191,10 @@ class CookieService {
|
|
|
194
191
|
}
|
|
195
192
|
}
|
|
196
193
|
}
|
|
197
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
198
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
194
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: CookieService, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
195
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: CookieService, providedIn: 'root' }); }
|
|
199
196
|
}
|
|
200
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
197
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: CookieService, decorators: [{
|
|
201
198
|
type: Injectable,
|
|
202
199
|
args: [{
|
|
203
200
|
providedIn: 'root',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-cookie-service.mjs","sources":["../../../projects/ngx-cookie-service/src/lib/cookie.service.ts","../../../projects/ngx-cookie-service/src/public-api.ts","../../../projects/ngx-cookie-service/src/ngx-cookie-service.ts"],"sourcesContent":["// This service is based on the `ng2-cookies` package which sadly is not a service and does\n// not use `DOCUMENT` injection and therefore doesn't work well with AoT production builds.\n// Package: https://github.com/BCJTI/ng2-cookies\n\nimport { DOCUMENT, isPlatformBrowser } from '@angular/common';\nimport { Inject, Injectable, PLATFORM_ID } from '@angular/core';\n\nexport type SameSite = 'Lax' | 'None' | 'Strict';\n\nexport interface CookieOptions {\n expires?: number | Date;\n path?: string;\n domain?: string;\n secure?: boolean;\n sameSite?: SameSite;\n partitioned?: boolean;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class CookieService {\n private readonly documentIsAccessible: boolean;\n\n constructor(\n @Inject(DOCUMENT) private document: Document, // Get the `PLATFORM_ID` so we can check if we're in a browser.\n @Inject(PLATFORM_ID) private platformId: object\n ) {\n this.documentIsAccessible = isPlatformBrowser(this.platformId);\n }\n\n /**\n * Get cookie Regular Expression\n *\n * @param name Cookie name\n * @returns property RegExp\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n private static getCookieRegExp(name: string): RegExp {\n const escapedName: string = name.replace(/([\\[\\]{}()|=;+?,.*^$])/gi, '\\\\$1');\n\n return new RegExp('(?:^' + escapedName + '|;\\\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');\n }\n\n /**\n * Gets the decoded version of an encoded component of a Uniform Resource Identifier (URI).\n *\n * @param encodedURIComponent A value representing an encoded URI component.\n *\n * @returns The decoded version of an encoded component of a Uniform Resource Identifier (URI).\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n private static safeDecodeURIComponent(encodedURIComponent: string): string {\n try {\n return decodeURIComponent(encodedURIComponent);\n } catch {\n // probably it is not uri encoded. return as is\n return encodedURIComponent;\n }\n }\n\n /**\n * Return `true` if {@link Document} is accessible, otherwise return `false`\n *\n * @param name Cookie name\n * @returns boolean - whether cookie with specified name exists\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n check(name: string): boolean {\n if (!this.documentIsAccessible) {\n return false;\n }\n name = encodeURIComponent(name);\n const regExp = CookieService.getCookieRegExp(name);\n return regExp.test(this.document.cookie);\n }\n\n /**\n * Get cookies by name\n *\n * @param name Cookie name\n * @returns property value\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n get(name: string): string {\n if (this.check(name)) {\n name = encodeURIComponent(name);\n const regExp: RegExp = CookieService.getCookieRegExp(name);\n const result = regExp.exec(this.document.cookie);\n return result && result[1] ? CookieService.safeDecodeURIComponent(result[1]) : '';\n } else {\n return '';\n }\n }\n\n /**\n * Get all cookies in JSON format\n *\n * @returns all the cookies in json\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n getAll(): { [key: string]: string } {\n if (!this.documentIsAccessible) {\n return {};\n }\n\n const cookies: { [key: string]: string } = {};\n const document: any = this.document;\n\n if (document.cookie && document.cookie !== '') {\n document.cookie.split(';').forEach((currentCookie: string) => {\n const [cookieName, cookieValue] = currentCookie.split('=');\n cookies[CookieService.safeDecodeURIComponent(cookieName.replace(/^ /, ''))] = CookieService.safeDecodeURIComponent(cookieValue);\n });\n }\n\n return cookies;\n }\n\n /**\n * Set cookie based on provided information\n *\n * @param name Cookie name\n * @param value Cookie value\n * @param expires Number of days until the cookies expires or an actual `Date`\n * @param path Cookie path\n * @param domain Cookie domain\n * @param secure Secure flag\n * @param partitioned Partitioned flag\n * @param sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n set(\n name: string,\n value: string,\n expires?: CookieOptions['expires'],\n path?: CookieOptions['path'],\n domain?: CookieOptions['domain'],\n secure?: CookieOptions['secure'],\n sameSite?: SameSite,\n partitioned?: CookieOptions['partitioned']\n ): void;\n\n /**\n * Set cookie based on provided information\n *\n * Cookie's parameters:\n * <pre>\n * expires Number of days until the cookies expires or an actual `Date`\n * path Cookie path\n * domain Cookie domain\n * secure flag\n * sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`\n * </pre>\n *\n * @param name Cookie name\n * @param value Cookie value\n * @param options Body with cookie's params\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n set(name: string, value: string, options?: CookieOptions): void;\n\n set(\n name: string,\n value: string,\n expiresOrOptions?: CookieOptions['expires'] | CookieOptions,\n path?: CookieOptions['path'],\n domain?: CookieOptions['domain'],\n secure?: CookieOptions['secure'],\n sameSite?: SameSite,\n partitioned?: CookieOptions['partitioned']\n ): void {\n if (!this.documentIsAccessible) {\n return;\n }\n\n if (typeof expiresOrOptions === 'number' || expiresOrOptions instanceof Date || path || domain || secure || sameSite) {\n const optionsBody = {\n expires: expiresOrOptions as CookieOptions['expires'],\n path,\n domain,\n secure,\n sameSite: sameSite ? sameSite : 'Lax',\n partitioned,\n };\n\n this.set(name, value, optionsBody);\n return;\n }\n\n let cookieString: string = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';';\n\n const options = expiresOrOptions ? expiresOrOptions : {};\n\n if (options.expires) {\n if (typeof options.expires === 'number') {\n const dateExpires: Date = new Date(new Date().getTime() + options.expires * 1000 * 60 * 60 * 24);\n\n cookieString += 'expires=' + dateExpires.toUTCString() + ';';\n } else {\n cookieString += 'expires=' + options.expires.toUTCString() + ';';\n }\n }\n\n if (options.path) {\n cookieString += 'path=' + options.path + ';';\n }\n\n if (options.domain) {\n cookieString += 'domain=' + options.domain + ';';\n }\n\n if (options.secure === false && options.sameSite === 'None') {\n options.secure = true;\n console.warn(\n `[ngx-cookie-service] Cookie ${name} was forced with secure flag because sameSite=None.` +\n `More details : https://github.com/stevermeister/ngx-cookie-service/issues/86#issuecomment-597720130`\n );\n }\n if (options.secure) {\n cookieString += 'secure;';\n }\n\n if (!options.sameSite) {\n options.sameSite = 'Lax';\n }\n\n cookieString += 'sameSite=' + options.sameSite + ';';\n\n if (options.partitioned) {\n cookieString += 'Partitioned;';\n }\n\n this.document.cookie = cookieString;\n }\n\n /**\n * Delete cookie by name at given path and domain. If not path is not specified, cookie at '/' path will be deleted.\n *\n * @param name Cookie name\n * @param path Cookie path\n * @param domain Cookie domain\n * @param secure Cookie secure flag\n * @param sameSite Cookie sameSite flag - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n delete(name: string, path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite: SameSite = 'Lax'): void {\n if (!this.documentIsAccessible) {\n return;\n }\n const expiresDate = new Date('Thu, 01 Jan 1970 00:00:01 GMT');\n this.set(name, '', { expires: expiresDate, path, domain, secure, sameSite });\n }\n\n /**\n * Delete all cookies at given path and domain. If not path is not specified, all cookies at '/' path will be deleted.\n *\n * @param path Cookie path\n * @param domain Cookie domain\n * @param secure Is the Cookie secure\n * @param sameSite Is the cookie same site\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n deleteAll(path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite: SameSite = 'Lax'): void {\n if (!this.documentIsAccessible) {\n return;\n }\n\n const cookies: any = this.getAll();\n\n for (const cookieName in cookies) {\n if (cookies.hasOwnProperty(cookieName)) {\n this.delete(cookieName, path, domain, secure, sameSite);\n }\n }\n }\n}\n","/*\n * Public API Surface of ngx-cookie-service\n */\n\nexport * from './lib/cookie.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAAA;AACA;AACA;MAmBa,aAAa,CAAA;IAGxB,WAC4B,CAAA,QAAkB;IACf,UAAkB,EAAA;QADrB,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACL,IAAU,CAAA,UAAA,GAAV,UAAU;QAEvC,IAAI,CAAC,oBAAoB,GAAG,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC;;AAGhE;;;;;;;;AAQG;IACK,OAAO,eAAe,CAAC,IAAY,EAAA;QACzC,MAAM,WAAW,GAAW,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC;AAE5E,QAAA,OAAO,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HzB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;0BAKI,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,WAAW;;;AC1BvB;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngx-cookie-service.mjs","sources":["../../../projects/ngx-cookie-service/src/lib/cookie.service.ts","../../../projects/ngx-cookie-service/src/public-api.ts","../../../projects/ngx-cookie-service/src/ngx-cookie-service.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { Inject, Injectable, PLATFORM_ID, DOCUMENT } from '@angular/core';\n\nexport type SameSite = 'Lax' | 'None' | 'Strict';\n\nexport interface CookieOptions {\n expires?: number | Date;\n path?: string;\n domain?: string;\n secure?: boolean;\n sameSite?: SameSite;\n partitioned?: boolean;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class CookieService {\n private readonly documentIsAccessible: boolean;\n\n constructor(\n @Inject(DOCUMENT) private readonly document: Document, // Get the `PLATFORM_ID` so we can check if we're in a browser.\n @Inject(PLATFORM_ID) private readonly platformId: object\n ) {\n this.documentIsAccessible = isPlatformBrowser(this.platformId);\n }\n\n /**\n * Get cookie Regular Expression\n *\n * @param name Cookie name\n * @returns property RegExp\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n private static getCookieRegExp(name: string): RegExp {\n const escapedName: string = name.replace(/([[\\]{}()|=;+?,.*^$\\\\])/gi, '\\\\$1');\n\n return new RegExp('(?:^' + escapedName + '|;\\\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');\n }\n\n /**\n * Gets the decoded version of an encoded component of a Uniform Resource Identifier (URI).\n *\n * @param encodedURIComponent A value representing an encoded URI component.\n *\n * @returns The decoded version of an encoded component of a Uniform Resource Identifier (URI).\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n private static safeDecodeURIComponent(encodedURIComponent: string): string {\n try {\n return decodeURIComponent(encodedURIComponent);\n } catch {\n // probably it is not uri encoded. return as is\n return encodedURIComponent;\n }\n }\n\n /**\n * Return `true` if {@link Document} is accessible, otherwise return `false`\n *\n * @param name Cookie name\n * @returns boolean - whether cookie with specified name exists\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n check(name: string): boolean {\n if (!this.documentIsAccessible) {\n return false;\n }\n name = encodeURIComponent(name);\n const regExp = CookieService.getCookieRegExp(name);\n return regExp.test(this.document.cookie);\n }\n\n /**\n * Get cookies by name\n *\n * @param name Cookie name\n * @returns property value\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n get(name: string): string {\n if (this.check(name)) {\n name = encodeURIComponent(name);\n const regExp: RegExp = CookieService.getCookieRegExp(name);\n const result = regExp.exec(this.document.cookie);\n return result?.[1] ? CookieService.safeDecodeURIComponent(result[1]) : '';\n } else {\n return '';\n }\n }\n\n /**\n * Get all cookies in JSON format\n *\n * @returns all the cookies in json\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n getAll(): { [key: string]: string } {\n if (!this.documentIsAccessible) {\n return {};\n }\n\n const cookies: { [key: string]: string } = {};\n const document: any = this.document;\n\n if (document.cookie && document.cookie !== '') {\n document.cookie.split(';').forEach((currentCookie: string) => {\n const [cookieName, cookieValue] = currentCookie.split('=');\n cookies[CookieService.safeDecodeURIComponent(cookieName.replace(/^ /, ''))] = CookieService.safeDecodeURIComponent(cookieValue);\n });\n }\n\n return cookies;\n }\n\n /**\n * Set cookie based on provided information\n *\n * @param name Cookie name\n * @param value Cookie value\n * @param expires Number of days until the cookies expires or an actual `Date`\n * @param path Cookie path\n * @param domain Cookie domain\n * @param secure Secure flag\n * @param partitioned Partitioned flag\n * @param sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n set(\n name: string,\n value: string,\n expires?: CookieOptions['expires'],\n path?: CookieOptions['path'],\n domain?: CookieOptions['domain'],\n secure?: CookieOptions['secure'],\n sameSite?: SameSite,\n partitioned?: CookieOptions['partitioned']\n ): void;\n\n /**\n * Set cookie based on provided information\n *\n * Cookie's parameters:\n * <pre>\n * expires Number of days until the cookies expires or an actual `Date`\n * path Cookie path\n * domain Cookie domain\n * secure flag\n * sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`\n * </pre>\n *\n * @param name Cookie name\n * @param value Cookie value\n * @param options Body with cookie's params\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n set(name: string, value: string, options?: CookieOptions): void;\n\n set(\n name: string,\n value: string,\n expiresOrOptions?: CookieOptions['expires'] | CookieOptions,\n path?: CookieOptions['path'],\n domain?: CookieOptions['domain'],\n secure?: CookieOptions['secure'],\n sameSite?: SameSite,\n partitioned?: CookieOptions['partitioned']\n ): void {\n if (!this.documentIsAccessible) {\n return;\n }\n\n if (typeof expiresOrOptions === 'number' || expiresOrOptions instanceof Date || path || domain || secure || sameSite) {\n const optionsBody = {\n expires: expiresOrOptions as CookieOptions['expires'],\n path,\n domain,\n secure,\n sameSite: sameSite || 'Lax',\n partitioned,\n };\n\n this.set(name, value, optionsBody);\n return;\n }\n\n let cookieString: string = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';';\n\n const options = expiresOrOptions ? expiresOrOptions : {};\n\n if (options.expires) {\n if (typeof options.expires === 'number') {\n const dateExpires: Date = new Date(new Date().getTime() + options.expires * 1000 * 60 * 60 * 24);\n\n cookieString += 'expires=' + dateExpires.toUTCString() + ';';\n } else {\n cookieString += 'expires=' + options.expires.toUTCString() + ';';\n }\n }\n\n if (options.path) {\n cookieString += 'path=' + options.path + ';';\n }\n\n if (options.domain) {\n cookieString += 'domain=' + options.domain + ';';\n }\n\n if (options.secure === false && options.sameSite === 'None') {\n options.secure = true;\n console.warn(\n `[ngx-cookie-service] Cookie ${name} was forced with secure flag because sameSite=None.` +\n `More details : https://github.com/stevermeister/ngx-cookie-service/issues/86#issuecomment-597720130`\n );\n }\n if (options.secure) {\n cookieString += 'secure;';\n }\n\n if (!options.sameSite) {\n options.sameSite = 'Lax';\n }\n\n cookieString += 'sameSite=' + options.sameSite + ';';\n\n if (options.partitioned) {\n cookieString += 'Partitioned;';\n }\n\n this.document.cookie = cookieString;\n }\n\n /**\n * Delete cookie by name at given path and domain. If not path is not specified, cookie at '/' path will be deleted.\n *\n * @param name Cookie name\n * @param path Cookie path\n * @param domain Cookie domain\n * @param secure Cookie secure flag\n * @param sameSite Cookie sameSite flag - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n delete(name: string, path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite: SameSite = 'Lax'): void {\n if (!this.documentIsAccessible) {\n return;\n }\n const expiresDate = new Date('Thu, 01 Jan 1970 00:00:01 GMT');\n this.set(name, '', { expires: expiresDate, path, domain, secure, sameSite });\n }\n\n /**\n * Delete all cookies at given path and domain. If not path is not specified, all cookies at '/' path will be deleted.\n *\n * @param path Cookie path\n * @param domain Cookie domain\n * @param secure Is the Cookie secure\n * @param sameSite Is the cookie same site\n *\n * @author: Stepan Suvorov\n * @since: 1.0.0\n */\n deleteAll(path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite: SameSite = 'Lax'): void {\n if (!this.documentIsAccessible) {\n return;\n }\n\n const cookies: any = this.getAll();\n\n for (const cookieName in cookies) {\n if (cookies.hasOwnProperty(cookieName)) {\n this.delete(cookieName, path, domain, secure, sameSite);\n }\n }\n }\n}\n","/*\n * Public API Surface of ngx-cookie-service\n */\n\nexport * from './lib/cookie.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAiBa,aAAa,CAAA;IAGxB,WACqC,CAAA,QAAkB;IACf,UAAkB,EAAA;QADrB,IAAQ,CAAA,QAAA,GAAR,QAAQ;QACL,IAAU,CAAA,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AA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,aAAa,cAFZ,MAAM,EAAA,CAAA,CAAA;;2FAEP,aAAa,EAAA,UAAA,EAAA,CAAA;kBAHzB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;0BAKI,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,WAAW;;;ACtBvB;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
|
|
3
|
+
type SameSite = 'Lax' | 'None' | 'Strict';
|
|
4
|
+
interface CookieOptions {
|
|
5
|
+
expires?: number | Date;
|
|
6
|
+
path?: string;
|
|
7
|
+
domain?: string;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
sameSite?: SameSite;
|
|
10
|
+
partitioned?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare class CookieService {
|
|
13
|
+
private readonly document;
|
|
14
|
+
private readonly platformId;
|
|
15
|
+
private readonly documentIsAccessible;
|
|
16
|
+
constructor(document: Document, // Get the `PLATFORM_ID` so we can check if we're in a browser.
|
|
17
|
+
platformId: object);
|
|
18
|
+
/**
|
|
19
|
+
* Get cookie Regular Expression
|
|
20
|
+
*
|
|
21
|
+
* @param name Cookie name
|
|
22
|
+
* @returns property RegExp
|
|
23
|
+
*
|
|
24
|
+
* @author: Stepan Suvorov
|
|
25
|
+
* @since: 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
private static getCookieRegExp;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the decoded version of an encoded component of a Uniform Resource Identifier (URI).
|
|
30
|
+
*
|
|
31
|
+
* @param encodedURIComponent A value representing an encoded URI component.
|
|
32
|
+
*
|
|
33
|
+
* @returns The decoded version of an encoded component of a Uniform Resource Identifier (URI).
|
|
34
|
+
*
|
|
35
|
+
* @author: Stepan Suvorov
|
|
36
|
+
* @since: 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
private static safeDecodeURIComponent;
|
|
39
|
+
/**
|
|
40
|
+
* Return `true` if {@link Document} is accessible, otherwise return `false`
|
|
41
|
+
*
|
|
42
|
+
* @param name Cookie name
|
|
43
|
+
* @returns boolean - whether cookie with specified name exists
|
|
44
|
+
*
|
|
45
|
+
* @author: Stepan Suvorov
|
|
46
|
+
* @since: 1.0.0
|
|
47
|
+
*/
|
|
48
|
+
check(name: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Get cookies by name
|
|
51
|
+
*
|
|
52
|
+
* @param name Cookie name
|
|
53
|
+
* @returns property value
|
|
54
|
+
*
|
|
55
|
+
* @author: Stepan Suvorov
|
|
56
|
+
* @since: 1.0.0
|
|
57
|
+
*/
|
|
58
|
+
get(name: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Get all cookies in JSON format
|
|
61
|
+
*
|
|
62
|
+
* @returns all the cookies in json
|
|
63
|
+
*
|
|
64
|
+
* @author: Stepan Suvorov
|
|
65
|
+
* @since: 1.0.0
|
|
66
|
+
*/
|
|
67
|
+
getAll(): {
|
|
68
|
+
[key: string]: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Set cookie based on provided information
|
|
72
|
+
*
|
|
73
|
+
* @param name Cookie name
|
|
74
|
+
* @param value Cookie value
|
|
75
|
+
* @param expires Number of days until the cookies expires or an actual `Date`
|
|
76
|
+
* @param path Cookie path
|
|
77
|
+
* @param domain Cookie domain
|
|
78
|
+
* @param secure Secure flag
|
|
79
|
+
* @param partitioned Partitioned flag
|
|
80
|
+
* @param sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`
|
|
81
|
+
*
|
|
82
|
+
* @author: Stepan Suvorov
|
|
83
|
+
* @since: 1.0.0
|
|
84
|
+
*/
|
|
85
|
+
set(name: string, value: string, expires?: CookieOptions['expires'], path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite, partitioned?: CookieOptions['partitioned']): void;
|
|
86
|
+
/**
|
|
87
|
+
* Set cookie based on provided information
|
|
88
|
+
*
|
|
89
|
+
* Cookie's parameters:
|
|
90
|
+
* <pre>
|
|
91
|
+
* expires Number of days until the cookies expires or an actual `Date`
|
|
92
|
+
* path Cookie path
|
|
93
|
+
* domain Cookie domain
|
|
94
|
+
* secure flag
|
|
95
|
+
* sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`
|
|
96
|
+
* </pre>
|
|
97
|
+
*
|
|
98
|
+
* @param name Cookie name
|
|
99
|
+
* @param value Cookie value
|
|
100
|
+
* @param options Body with cookie's params
|
|
101
|
+
*
|
|
102
|
+
* @author: Stepan Suvorov
|
|
103
|
+
* @since: 1.0.0
|
|
104
|
+
*/
|
|
105
|
+
set(name: string, value: string, options?: CookieOptions): void;
|
|
106
|
+
/**
|
|
107
|
+
* Delete cookie by name at given path and domain. If not path is not specified, cookie at '/' path will be deleted.
|
|
108
|
+
*
|
|
109
|
+
* @param name Cookie name
|
|
110
|
+
* @param path Cookie path
|
|
111
|
+
* @param domain Cookie domain
|
|
112
|
+
* @param secure Cookie secure flag
|
|
113
|
+
* @param sameSite Cookie sameSite flag - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
|
|
114
|
+
*
|
|
115
|
+
* @author: Stepan Suvorov
|
|
116
|
+
* @since: 1.0.0
|
|
117
|
+
*/
|
|
118
|
+
delete(name: string, path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite): void;
|
|
119
|
+
/**
|
|
120
|
+
* Delete all cookies at given path and domain. If not path is not specified, all cookies at '/' path will be deleted.
|
|
121
|
+
*
|
|
122
|
+
* @param path Cookie path
|
|
123
|
+
* @param domain Cookie domain
|
|
124
|
+
* @param secure Is the Cookie secure
|
|
125
|
+
* @param sameSite Is the cookie same site
|
|
126
|
+
*
|
|
127
|
+
* @author: Stepan Suvorov
|
|
128
|
+
* @since: 1.0.0
|
|
129
|
+
*/
|
|
130
|
+
deleteAll(path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite): void;
|
|
131
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CookieService, never>;
|
|
132
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CookieService>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { CookieService };
|
|
136
|
+
export type { CookieOptions, SameSite };
|
|
137
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../projects/ngx-cookie-service/src/lib/cookie.service.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGM;;AAGJ;;;;;;AAMD;AAED;;;AAIE;;AAIwC;AAKxC;;;;;;;;AAQG;;AAOH;;;;;;;;;AASG;;AAUH;;;;;;;;AAQG;AACH;AASA;;;;;;;;AAQG;AACH;AAWA;;;;;;;AAOG;AACH;AAAY;AAAuB;AAkBnC;;;;;;;;;;;;;;AAcG;;AAYH;;;;;;;;;;;;;;;;;;AAkBG;AACH;AA4EA;;;;;;;;;;;AAWG;AACH;AAQA;;;;;;;;;;AAUG;AACH;;;AAaD;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-cookie-service",
|
|
3
3
|
"description": "Angular cookie service",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "20.0.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Stepan Suvorov <stevermeister@gmail.com>",
|
|
7
7
|
"keywords": [
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"angular-17",
|
|
27
27
|
"angular-18",
|
|
28
28
|
"angular-19",
|
|
29
|
+
"angular-20",
|
|
29
30
|
"ivy",
|
|
30
31
|
"ivy-compatible",
|
|
31
32
|
"ivy-compilation",
|
|
@@ -83,8 +84,8 @@
|
|
|
83
84
|
"email": "stepan@studytube.nl"
|
|
84
85
|
},
|
|
85
86
|
"peerDependencies": {
|
|
86
|
-
"@angular/common": "^
|
|
87
|
-
"@angular/core": "^
|
|
87
|
+
"@angular/common": "^20.0.0",
|
|
88
|
+
"@angular/core": "^20.0.0"
|
|
88
89
|
},
|
|
89
90
|
"dependencies": {
|
|
90
91
|
"tslib": "^2.8.0"
|
package/lib/cookie.service.d.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
export type SameSite = 'Lax' | 'None' | 'Strict';
|
|
3
|
-
export interface CookieOptions {
|
|
4
|
-
expires?: number | Date;
|
|
5
|
-
path?: string;
|
|
6
|
-
domain?: string;
|
|
7
|
-
secure?: boolean;
|
|
8
|
-
sameSite?: SameSite;
|
|
9
|
-
partitioned?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare class CookieService {
|
|
12
|
-
private document;
|
|
13
|
-
private platformId;
|
|
14
|
-
private readonly documentIsAccessible;
|
|
15
|
-
constructor(document: Document, // Get the `PLATFORM_ID` so we can check if we're in a browser.
|
|
16
|
-
platformId: object);
|
|
17
|
-
/**
|
|
18
|
-
* Get cookie Regular Expression
|
|
19
|
-
*
|
|
20
|
-
* @param name Cookie name
|
|
21
|
-
* @returns property RegExp
|
|
22
|
-
*
|
|
23
|
-
* @author: Stepan Suvorov
|
|
24
|
-
* @since: 1.0.0
|
|
25
|
-
*/
|
|
26
|
-
private static getCookieRegExp;
|
|
27
|
-
/**
|
|
28
|
-
* Gets the decoded version of an encoded component of a Uniform Resource Identifier (URI).
|
|
29
|
-
*
|
|
30
|
-
* @param encodedURIComponent A value representing an encoded URI component.
|
|
31
|
-
*
|
|
32
|
-
* @returns The decoded version of an encoded component of a Uniform Resource Identifier (URI).
|
|
33
|
-
*
|
|
34
|
-
* @author: Stepan Suvorov
|
|
35
|
-
* @since: 1.0.0
|
|
36
|
-
*/
|
|
37
|
-
private static safeDecodeURIComponent;
|
|
38
|
-
/**
|
|
39
|
-
* Return `true` if {@link Document} is accessible, otherwise return `false`
|
|
40
|
-
*
|
|
41
|
-
* @param name Cookie name
|
|
42
|
-
* @returns boolean - whether cookie with specified name exists
|
|
43
|
-
*
|
|
44
|
-
* @author: Stepan Suvorov
|
|
45
|
-
* @since: 1.0.0
|
|
46
|
-
*/
|
|
47
|
-
check(name: string): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Get cookies by name
|
|
50
|
-
*
|
|
51
|
-
* @param name Cookie name
|
|
52
|
-
* @returns property value
|
|
53
|
-
*
|
|
54
|
-
* @author: Stepan Suvorov
|
|
55
|
-
* @since: 1.0.0
|
|
56
|
-
*/
|
|
57
|
-
get(name: string): string;
|
|
58
|
-
/**
|
|
59
|
-
* Get all cookies in JSON format
|
|
60
|
-
*
|
|
61
|
-
* @returns all the cookies in json
|
|
62
|
-
*
|
|
63
|
-
* @author: Stepan Suvorov
|
|
64
|
-
* @since: 1.0.0
|
|
65
|
-
*/
|
|
66
|
-
getAll(): {
|
|
67
|
-
[key: string]: string;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Set cookie based on provided information
|
|
71
|
-
*
|
|
72
|
-
* @param name Cookie name
|
|
73
|
-
* @param value Cookie value
|
|
74
|
-
* @param expires Number of days until the cookies expires or an actual `Date`
|
|
75
|
-
* @param path Cookie path
|
|
76
|
-
* @param domain Cookie domain
|
|
77
|
-
* @param secure Secure flag
|
|
78
|
-
* @param partitioned Partitioned flag
|
|
79
|
-
* @param sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`
|
|
80
|
-
*
|
|
81
|
-
* @author: Stepan Suvorov
|
|
82
|
-
* @since: 1.0.0
|
|
83
|
-
*/
|
|
84
|
-
set(name: string, value: string, expires?: CookieOptions['expires'], path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite, partitioned?: CookieOptions['partitioned']): void;
|
|
85
|
-
/**
|
|
86
|
-
* Set cookie based on provided information
|
|
87
|
-
*
|
|
88
|
-
* Cookie's parameters:
|
|
89
|
-
* <pre>
|
|
90
|
-
* expires Number of days until the cookies expires or an actual `Date`
|
|
91
|
-
* path Cookie path
|
|
92
|
-
* domain Cookie domain
|
|
93
|
-
* secure flag
|
|
94
|
-
* sameSite OWASP same site token `Lax`, `None`, or `Strict`. Defaults to `Lax`
|
|
95
|
-
* </pre>
|
|
96
|
-
*
|
|
97
|
-
* @param name Cookie name
|
|
98
|
-
* @param value Cookie value
|
|
99
|
-
* @param options Body with cookie's params
|
|
100
|
-
*
|
|
101
|
-
* @author: Stepan Suvorov
|
|
102
|
-
* @since: 1.0.0
|
|
103
|
-
*/
|
|
104
|
-
set(name: string, value: string, options?: CookieOptions): void;
|
|
105
|
-
/**
|
|
106
|
-
* Delete cookie by name at given path and domain. If not path is not specified, cookie at '/' path will be deleted.
|
|
107
|
-
*
|
|
108
|
-
* @param name Cookie name
|
|
109
|
-
* @param path Cookie path
|
|
110
|
-
* @param domain Cookie domain
|
|
111
|
-
* @param secure Cookie secure flag
|
|
112
|
-
* @param sameSite Cookie sameSite flag - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
|
|
113
|
-
*
|
|
114
|
-
* @author: Stepan Suvorov
|
|
115
|
-
* @since: 1.0.0
|
|
116
|
-
*/
|
|
117
|
-
delete(name: string, path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite): void;
|
|
118
|
-
/**
|
|
119
|
-
* Delete all cookies at given path and domain. If not path is not specified, all cookies at '/' path will be deleted.
|
|
120
|
-
*
|
|
121
|
-
* @param path Cookie path
|
|
122
|
-
* @param domain Cookie domain
|
|
123
|
-
* @param secure Is the Cookie secure
|
|
124
|
-
* @param sameSite Is the cookie same site
|
|
125
|
-
*
|
|
126
|
-
* @author: Stepan Suvorov
|
|
127
|
-
* @since: 1.0.0
|
|
128
|
-
*/
|
|
129
|
-
deleteAll(path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite): void;
|
|
130
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<CookieService, never>;
|
|
131
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<CookieService>;
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=cookie.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.service.d.ts","sourceRoot":"","sources":["../../../projects/ngx-cookie-service/src/lib/cookie.service.ts"],"names":[],"mappings":";AAOA,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAGa,aAAa;IAIJ,OAAO,CAAC,QAAQ;IACb,OAAO,CAAC,UAAU;IAJzC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAU;gBAGnB,QAAQ,EAAE,QAAQ,EAAE,+DAA+D;IAChF,UAAU,EAAE,MAAM;IAKjD;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAM9B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IASrC;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,E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
-
{"version":3,"file":"ngx-cookie-service.d.ts","sourceRoot":"","sources":["../../projects/ngx-cookie-service/src/ngx-cookie-service.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,cAAc,cAAc,CAAC"}
|
package/public-api.d.ts
DELETED
package/public-api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../projects/ngx-cookie-service/src/public-api.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC"}
|