@flexzap/utilities 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -59,14 +59,14 @@ Service for handling navigation and URL opening in a safe, platform-agnostic way
|
|
|
59
59
|
|
|
60
60
|
#### Methods
|
|
61
61
|
|
|
62
|
-
| Method | Parameters
|
|
63
|
-
| -------------- |
|
|
64
|
-
| `goToUrl` | `url: string`, `target?:
|
|
65
|
-
| `mailTo` | `email: string`, `subject?: string`, `body?: string`
|
|
66
|
-
| `callTo` | `tel: string`
|
|
67
|
-
| `smsTo` | `tel: string`
|
|
68
|
-
| `linkTo` | `id: string`
|
|
69
|
-
| `downloadFile` | `url: string`
|
|
62
|
+
| Method | Parameters | Description |
|
|
63
|
+
| -------------- | -------------------------------------------------------------------- | -------------------------------------------------------------- |
|
|
64
|
+
| `goToUrl` | `url: string`, `target?: '_self' \| '_blank' \| '_parent' \| '_top'` | Navigates to the specified URL. Default target is `_self`. |
|
|
65
|
+
| `mailTo` | `email: string`, `subject?: string`, `body?: string` | Opens the default email client with optional subject and body. |
|
|
66
|
+
| `callTo` | `tel: string` | Initiates a phone call to the specified number. |
|
|
67
|
+
| `smsTo` | `tel: string` | Initiates an SMS to the specified number. |
|
|
68
|
+
| `linkTo` | `id: string` | Smoothly scrolls to the element with the specified ID. |
|
|
69
|
+
| `downloadFile` | `url: string`, `filename?: string` | Downloads a file from the specified URL. |
|
|
70
70
|
|
|
71
71
|
#### Features
|
|
72
72
|
|
|
@@ -1,8 +1,79 @@
|
|
|
1
|
-
import { isPlatformBrowser } from '@angular/common';
|
|
1
|
+
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { SecurityContext, PLATFORM_ID, Inject
|
|
3
|
+
import { inject, Injectable, SecurityContext, PLATFORM_ID, Inject } from '@angular/core';
|
|
4
4
|
import * as i1 from '@angular/platform-browser';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Utility service for managing browser cookies.
|
|
8
|
+
* Provides typesafe methods to get and set cookies with support for:
|
|
9
|
+
* - Expiration days
|
|
10
|
+
* - Path and Domain
|
|
11
|
+
* - Secure flag
|
|
12
|
+
* - SameSite policy
|
|
13
|
+
*/
|
|
14
|
+
class ZapCookieUtil {
|
|
15
|
+
document = inject(DOCUMENT);
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves a cookie value by name.
|
|
18
|
+
* @param name The name of the cookie
|
|
19
|
+
* @returns The cookie value or null if not found
|
|
20
|
+
*/
|
|
21
|
+
getCookie(name) {
|
|
22
|
+
if (!this.document) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const nameEQ = name + '=';
|
|
26
|
+
const ca = this.getCookieString().split(';');
|
|
27
|
+
for (const c of ca) {
|
|
28
|
+
let cookie = c.trim();
|
|
29
|
+
if (cookie.startsWith(nameEQ)) {
|
|
30
|
+
return decodeURIComponent(cookie.substring(nameEQ.length));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Sets a cookie with the specified parameters.
|
|
37
|
+
* @param name Name of the cookie
|
|
38
|
+
* @param value Value of the cookie
|
|
39
|
+
* @param days Expiration in days (optional)
|
|
40
|
+
* @param path Cookie path (default: '/')
|
|
41
|
+
* @param domain Cookie domain (optional)
|
|
42
|
+
* @param secure Secure flag (optional)
|
|
43
|
+
* @param sameSite SameSite policy (default: 'Lax')
|
|
44
|
+
*/
|
|
45
|
+
setCookie(name, value, days, path, domain, secure, sameSite) {
|
|
46
|
+
if (!this.document) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (sameSite === 'None' && !secure) {
|
|
50
|
+
secure = true;
|
|
51
|
+
}
|
|
52
|
+
let expires = '';
|
|
53
|
+
if (days) {
|
|
54
|
+
const date = new Date();
|
|
55
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
56
|
+
expires = '; expires=' + date.toUTCString();
|
|
57
|
+
}
|
|
58
|
+
const cookieString = `${name}=${encodeURIComponent(value)}${expires}; path=${path ?? '/'}${domain ? '; domain=' + domain : ''}${secure ? '; secure' : ''}; SameSite=${sameSite ?? 'Lax'}`;
|
|
59
|
+
this.setCookieString(cookieString);
|
|
60
|
+
}
|
|
61
|
+
getCookieString() {
|
|
62
|
+
return this.document.cookie;
|
|
63
|
+
}
|
|
64
|
+
setCookieString(value) {
|
|
65
|
+
this.document.cookie = value;
|
|
66
|
+
}
|
|
67
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ZapCookieUtil, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
68
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ZapCookieUtil, providedIn: 'root' });
|
|
69
|
+
}
|
|
70
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: ZapCookieUtil, decorators: [{
|
|
71
|
+
type: Injectable,
|
|
72
|
+
args: [{
|
|
73
|
+
providedIn: 'root'
|
|
74
|
+
}]
|
|
75
|
+
}] });
|
|
76
|
+
|
|
6
77
|
/**
|
|
7
78
|
* Service for handling navigation and URL opening in a safe, platform-agnostic way.
|
|
8
79
|
* It ensures that URLs are sanitized (rejecting 'unsafe:' prefixes) and that window operations are only performed in the browser environment.
|
|
@@ -97,14 +168,15 @@ class ZapNavigation {
|
|
|
97
168
|
* Downloads a file from the specified URL.
|
|
98
169
|
*
|
|
99
170
|
* @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.
|
|
171
|
+
* @param {string} [filename] - Optional filename to suggest for the downloaded file. If provided, it takes precedence (for same-origin URLs). If omitted, the browser infers the name from the server headers (Content-Disposition) or URL.
|
|
100
172
|
*/
|
|
101
|
-
downloadFile(url) {
|
|
173
|
+
downloadFile(url, filename) {
|
|
102
174
|
if (isPlatformBrowser(this.platformId)) {
|
|
103
175
|
const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);
|
|
104
176
|
if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {
|
|
105
177
|
const link = document.createElement('a');
|
|
106
178
|
link.href = sanitizedUrl;
|
|
107
|
-
link.download = '
|
|
179
|
+
link.download = filename ?? '';
|
|
108
180
|
link.click();
|
|
109
181
|
}
|
|
110
182
|
}
|
|
@@ -130,5 +202,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
130
202
|
* Generated bundle index. Do not edit.
|
|
131
203
|
*/
|
|
132
204
|
|
|
133
|
-
export { ZapNavigation };
|
|
205
|
+
export { ZapCookieUtil, ZapNavigation };
|
|
134
206
|
//# sourceMappingURL=flexzap-utilities.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flexzap-utilities.mjs","sources":["../../../../projects/flexzap/utilities/src/lib/navigation/navigation.ts","../../../../projects/flexzap/utilities/src/public-api.ts","../../../../projects/flexzap/utilities/src/flexzap-utilities.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { Inject, Injectable, PLATFORM_ID, SecurityContext } from '@angular/core';\nimport { DomSanitizer } from '@angular/platform-browser';\n\n/**\n * Service for handling navigation and URL opening in a safe, platform-agnostic way.\n * It ensures that URLs are sanitized (rejecting 'unsafe:' prefixes) and that window operations are only performed in the browser environment.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class ZapNavigation {\n constructor(\n @Inject(PLATFORM_ID) private platformId: Object,\n private sanitizer: DomSanitizer\n ) {}\n\n /**\n * Navigates to the specified URL in the given target window/tab.\n *\n * This method performs the following safety checks:\n * 1. Verifies the code is running in a browser environment.\n * 2. Sanitizes the URL to prevent security vulnerabilities (like XSS) and rejects URLs prefixed with 'unsafe:'.\n * 3. When target is '_blank', automatically adds 'noopener,noreferrer' and clears the opener to prevent reverse tabnabbing.\n *\n * @param {string} url - The URL to navigate to.\n * @param {string} [target='_self'] - The target context for opening the URL (e.g., '_self', '_blank'). Defaults to '_self'.\n */\n goToUrl(url: string, target: '_self' | '_blank' | '_parent' | '_top' = '_self') {\n if (isPlatformBrowser(this.platformId)) {\n const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);\n\n if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {\n if (target === '_blank') {\n const newWindow = window.open(sanitizedUrl, target, 'noopener,noreferrer');\n if (newWindow) {\n newWindow.opener = null;\n }\n } else {\n window.open(sanitizedUrl, target);\n }\n }\n }\n }\n\n /**\n * Opens the default email client with the specified email, subject, and body.\n *\n * @param {string} email - The recipient's email address.\n * @param {string} [subject] - The subject of the email (optional).\n * @param {string} [body] - The body of the email (optional).\n */\n mailTo(email: string, subject?: string, body?: string) {\n const params: string[] = [];\n if (subject) {\n params.push(`subject=${encodeURIComponent(subject)}`);\n }\n if (body) {\n params.push(`body=${encodeURIComponent(body)}`);\n }\n\n let url = `mailto:${email}`;\n if (params.length > 0) {\n url += `?${params.join('&')}`;\n }\n\n this.goToUrl(url);\n }\n\n /**\n * Initiates a phone call to the specified telephone number.\n *\n * @param {string} tel - The telephone number to call.\n */\n callTo(tel: string) {\n this.goToUrl(`tel:${tel}`);\n }\n\n /**\n * Initiates a SMS to the specified telephone number.\n *\n * @param {string} tel - The telephone number to send SMS to.\n */\n smsTo(tel: string) {\n this.goToUrl(`sms:${tel}`);\n }\n\n /**\n * Navigates to the specified element id on the current page.\n *\n * This method performs a smooth scroll to the element. It is safe to call in SSR environments (no-op on server).\n *\n * @param {string} id - The element id to navigate to.\n */\n linkTo(id: string) {\n if (isPlatformBrowser(this.platformId)) {\n const element = document.getElementById(id);\n\n if (element) {\n element.scrollIntoView({ behavior: 'smooth' });\n }\n }\n }\n\n /**\n * Downloads a file from the specified URL.\n *\n * @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.\n */\n downloadFile(url: string) {\n if (isPlatformBrowser(this.platformId)) {\n const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);\n\n if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {\n const link = document.createElement('a');\n link.href = sanitizedUrl;\n link.download = 'file';\n link.click();\n }\n }\n }\n}\n","/*\n * Public API Surface of utilities\n */\n\nexport * from './lib/navigation/index';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAIA;;;AAGG;MAIU,aAAa,CAAA;AAEO,IAAA,UAAA;AACrB,IAAA,SAAA;IAFV,WAAA,CAC+B,UAAkB,EACvC,SAAuB,EAAA;QADF,IAAA,CAAA,UAAU,GAAV,UAAU;QAC/B,IAAA,CAAA,SAAS,GAAT,SAAS;IAChB;AAEH;;;;;;;;;;AAUG;AACH,IAAA,OAAO,CAAC,GAAW,EAAE,MAAA,GAAkD,OAAO,EAAA;AAC5E,QAAA,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AACtC,YAAA,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC;YAEtE,IAAI,YAAY,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;AACvD,gBAAA,IAAI,MAAM,KAAK,QAAQ,EAAE;AACvB,oBAAA,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,qBAAqB,CAAC;oBAC1E,IAAI,SAAS,EAAE;AACb,wBAAA,SAAS,CAAC,MAAM,GAAG,IAAI;oBACzB;gBACF;qBAAO;AACL,oBAAA,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC;gBACnC;YACF;QACF;IACF;AAEA;;;;;;A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;AACtC,YAAA,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC;YAEtE,IAAI,YAAY,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;gBACvD,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC;AACxC,gBAAA,IAAI,CAAC,IAAI,GAAG,YAAY;AACxB,gBAAA,IAAI,CAAC,QAAQ,GAAG,MAAM;gBACtB,IAAI,CAAC,KAAK,EAAE;YACd;QACF;IACF;AA7GW,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,kBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,aAAa,kBAEd,WAAW,EAAA,EAAA,EAAA,KAAA,EAAA,EAAA,CAAA,YAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAFV,IAAA,OAAA,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;;2FAEP,aAAa,EAAA,UAAA,EAAA,CAAA;kBAHzB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;0BAGI,MAAM;2BAAC,WAAW;;;ACbvB;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"flexzap-utilities.mjs","sources":["../../../../projects/flexzap/utilities/src/lib/cookies/cookie-util.ts","../../../../projects/flexzap/utilities/src/lib/navigation/navigation.ts","../../../../projects/flexzap/utilities/src/public-api.ts","../../../../projects/flexzap/utilities/src/flexzap-utilities.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport { Injectable, inject } from '@angular/core';\n\n/**\n * Utility service for managing browser cookies.\n * Provides typesafe methods to get and set cookies with support for:\n * - Expiration days\n * - Path and Domain\n * - Secure flag\n * - SameSite policy\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class ZapCookieUtil {\n private document = inject(DOCUMENT);\n\n /**\n * Retrieves a cookie value by name.\n * @param name The name of the cookie\n * @returns The cookie value or null if not found\n */\n getCookie(name: string): string | null {\n if (!this.document) {\n return null;\n }\n const nameEQ = name + '=';\n const ca = this.getCookieString().split(';');\n for (const c of ca) {\n let cookie = c.trim();\n if (cookie.startsWith(nameEQ)) {\n return decodeURIComponent(cookie.substring(nameEQ.length));\n }\n }\n return null;\n }\n\n /**\n * Sets a cookie with the specified parameters.\n * @param name Name of the cookie\n * @param value Value of the cookie\n * @param days Expiration in days (optional)\n * @param path Cookie path (default: '/')\n * @param domain Cookie domain (optional)\n * @param secure Secure flag (optional)\n * @param sameSite SameSite policy (default: 'Lax')\n */\n setCookie(\n name: string,\n value: string,\n days?: number,\n path?: string,\n domain?: string,\n secure?: boolean,\n sameSite?: 'Lax' | 'Strict' | 'None'\n ): void {\n if (!this.document) {\n return;\n }\n\n if (sameSite === 'None' && !secure) {\n secure = true;\n }\n\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n const cookieString = `${name}=${encodeURIComponent(value)}${expires}; path=${path ?? '/'}${\n domain ? '; domain=' + domain : ''\n }${secure ? '; secure' : ''}; SameSite=${sameSite ?? 'Lax'}`;\n this.setCookieString(cookieString);\n }\n\n private getCookieString(): string {\n return this.document.cookie;\n }\n\n private setCookieString(value: string): void {\n this.document.cookie = value;\n }\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport { Inject, Injectable, PLATFORM_ID, SecurityContext } from '@angular/core';\nimport { DomSanitizer } from '@angular/platform-browser';\n\n/**\n * Service for handling navigation and URL opening in a safe, platform-agnostic way.\n * It ensures that URLs are sanitized (rejecting 'unsafe:' prefixes) and that window operations are only performed in the browser environment.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class ZapNavigation {\n constructor(\n @Inject(PLATFORM_ID) private platformId: Object,\n private sanitizer: DomSanitizer\n ) {}\n\n /**\n * Navigates to the specified URL in the given target window/tab.\n *\n * This method performs the following safety checks:\n * 1. Verifies the code is running in a browser environment.\n * 2. Sanitizes the URL to prevent security vulnerabilities (like XSS) and rejects URLs prefixed with 'unsafe:'.\n * 3. When target is '_blank', automatically adds 'noopener,noreferrer' and clears the opener to prevent reverse tabnabbing.\n *\n * @param {string} url - The URL to navigate to.\n * @param {string} [target='_self'] - The target context for opening the URL (e.g., '_self', '_blank'). Defaults to '_self'.\n */\n goToUrl(url: string, target: '_self' | '_blank' | '_parent' | '_top' = '_self') {\n if (isPlatformBrowser(this.platformId)) {\n const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);\n\n if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {\n if (target === '_blank') {\n const newWindow = window.open(sanitizedUrl, target, 'noopener,noreferrer');\n if (newWindow) {\n newWindow.opener = null;\n }\n } else {\n window.open(sanitizedUrl, target);\n }\n }\n }\n }\n\n /**\n * Opens the default email client with the specified email, subject, and body.\n *\n * @param {string} email - The recipient's email address.\n * @param {string} [subject] - The subject of the email (optional).\n * @param {string} [body] - The body of the email (optional).\n */\n mailTo(email: string, subject?: string, body?: string) {\n const params: string[] = [];\n if (subject) {\n params.push(`subject=${encodeURIComponent(subject)}`);\n }\n if (body) {\n params.push(`body=${encodeURIComponent(body)}`);\n }\n\n let url = `mailto:${email}`;\n if (params.length > 0) {\n url += `?${params.join('&')}`;\n }\n\n this.goToUrl(url);\n }\n\n /**\n * Initiates a phone call to the specified telephone number.\n *\n * @param {string} tel - The telephone number to call.\n */\n callTo(tel: string) {\n this.goToUrl(`tel:${tel}`);\n }\n\n /**\n * Initiates a SMS to the specified telephone number.\n *\n * @param {string} tel - The telephone number to send SMS to.\n */\n smsTo(tel: string) {\n this.goToUrl(`sms:${tel}`);\n }\n\n /**\n * Navigates to the specified element id on the current page.\n *\n * This method performs a smooth scroll to the element. It is safe to call in SSR environments (no-op on server).\n *\n * @param {string} id - The element id to navigate to.\n */\n linkTo(id: string) {\n if (isPlatformBrowser(this.platformId)) {\n const element = document.getElementById(id);\n\n if (element) {\n element.scrollIntoView({ behavior: 'smooth' });\n }\n }\n }\n\n /**\n * Downloads a file from the specified URL.\n *\n * @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.\n * @param {string} [filename] - Optional filename to suggest for the downloaded file. If provided, it takes precedence (for same-origin URLs). If omitted, the browser infers the name from the server headers (Content-Disposition) or URL.\n */\n downloadFile(url: string, filename?: string) {\n if (isPlatformBrowser(this.platformId)) {\n const sanitizedUrl = this.sanitizer.sanitize(SecurityContext.URL, url);\n\n if (sanitizedUrl && !sanitizedUrl.startsWith('unsafe:')) {\n const link = document.createElement('a');\n link.href = sanitizedUrl;\n link.download = filename ?? '';\n link.click();\n }\n }\n }\n}\n","/*\n * Public API Surface of utilities\n */\n\nexport * from './lib/cookies/index';\nexport * from './lib/navigation/index';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAGA;;;;;;;AAOG;MAIU,aAAa,CAAA;AAChB,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAEnC;;;;AAIG;AACH,IAAA,SAAS,CAAC,IAAY,EAAA;AACpB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAClB,YAAA,OAAO,IAAI;QACb;AACA,QAAA,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG;QACzB,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;AAC5C,QAAA,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE;AAClB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
|
|
2
|
+
import { DomSanitizer } from '@angular/platform-browser';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utility service for managing browser cookies.
|
|
6
|
+
* Provides typesafe methods to get and set cookies with support for:
|
|
7
|
+
* - Expiration days
|
|
8
|
+
* - Path and Domain
|
|
9
|
+
* - Secure flag
|
|
10
|
+
* - SameSite policy
|
|
11
|
+
*/
|
|
12
|
+
declare class ZapCookieUtil {
|
|
13
|
+
private document;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves a cookie value by name.
|
|
16
|
+
* @param name The name of the cookie
|
|
17
|
+
* @returns The cookie value or null if not found
|
|
18
|
+
*/
|
|
19
|
+
getCookie(name: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Sets a cookie with the specified parameters.
|
|
22
|
+
* @param name Name of the cookie
|
|
23
|
+
* @param value Value of the cookie
|
|
24
|
+
* @param days Expiration in days (optional)
|
|
25
|
+
* @param path Cookie path (default: '/')
|
|
26
|
+
* @param domain Cookie domain (optional)
|
|
27
|
+
* @param secure Secure flag (optional)
|
|
28
|
+
* @param sameSite SameSite policy (default: 'Lax')
|
|
29
|
+
*/
|
|
30
|
+
setCookie(name: string, value: string, days?: number, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'Strict' | 'None'): void;
|
|
31
|
+
private getCookieString;
|
|
32
|
+
private setCookieString;
|
|
33
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ZapCookieUtil, never>;
|
|
34
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ZapCookieUtil>;
|
|
35
|
+
}
|
|
3
36
|
|
|
4
37
|
/**
|
|
5
38
|
* Service for handling navigation and URL opening in a safe, platform-agnostic way.
|
|
@@ -53,10 +86,11 @@ declare class ZapNavigation {
|
|
|
53
86
|
* Downloads a file from the specified URL.
|
|
54
87
|
*
|
|
55
88
|
* @param {string} url - The URL of the file to download. It will be sanitized to prevent security vulnerabilities and rejected if prefixed with 'unsafe:'.
|
|
89
|
+
* @param {string} [filename] - Optional filename to suggest for the downloaded file. If provided, it takes precedence (for same-origin URLs). If omitted, the browser infers the name from the server headers (Content-Disposition) or URL.
|
|
56
90
|
*/
|
|
57
|
-
downloadFile(url: string): void;
|
|
91
|
+
downloadFile(url: string, filename?: string): void;
|
|
58
92
|
static ɵfac: i0.ɵɵFactoryDeclaration<ZapNavigation, never>;
|
|
59
93
|
static ɵprov: i0.ɵɵInjectableDeclaration<ZapNavigation>;
|
|
60
94
|
}
|
|
61
95
|
|
|
62
|
-
export { ZapNavigation };
|
|
96
|
+
export { ZapCookieUtil, ZapNavigation };
|