@finsweet/consentpro-scan 1.0.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 +194 -0
- package/dist/results.js +1 -0
- package/dist/scan.js +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Consent Scan
|
|
2
|
+
|
|
3
|
+
Frontend client for the ConsentPro scanner API. Provides URL validation, scan initiation, and results display for GDPR/CCPA compliance scanning.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is a Webflow-integrated frontend that connects to the ConsentPro scanner backend API. Users enter a URL, the app validates and initiates a scan, then redirects to a results page that polls for completion and displays compliance data.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **URL Validation**: Strict validation requiring valid protocol and hostname with TLD
|
|
12
|
+
- **Scanner API Client**: Full integration with ConsentPro v2 scanner endpoints
|
|
13
|
+
- **Real-time Status Polling**: Monitors scan progress with live activity updates
|
|
14
|
+
- **Compliance Scoring**: Displays overall compliance score with pass/fail/warning breakdown
|
|
15
|
+
- **Detected Items Display**: Shows unblocked scripts, cookies, and tracking technologies
|
|
16
|
+
- **Criteria Accordion**: Expandable list of all compliance criteria with status
|
|
17
|
+
- **Typed Selectors**: Type-safe element queries using `data-fs-cs` attributes
|
|
18
|
+
|
|
19
|
+
## Project Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/
|
|
23
|
+
├── api/
|
|
24
|
+
│ ├── backend.ts # Scanner API client (startScan, getStatus, getResults)
|
|
25
|
+
│ ├── types.ts # API response types
|
|
26
|
+
│ └── index.ts
|
|
27
|
+
├── pages/
|
|
28
|
+
│ ├── scan.ts # Scan page - URL validation & scan initiation
|
|
29
|
+
│ └── results.ts # Results page - polling & display
|
|
30
|
+
├── icons/
|
|
31
|
+
│ └── index.ts # Inline SVG icon injection
|
|
32
|
+
├── utils/
|
|
33
|
+
│ ├── selectors.ts # Typed selector system
|
|
34
|
+
│ ├── compliance.ts # Compliance evaluation logic
|
|
35
|
+
│ ├── data-extractor.ts # Extract structured data from API responses
|
|
36
|
+
│ ├── constants.ts # Colors, categories, config
|
|
37
|
+
│ ├── helpers.ts # UI utilities (displayError, clearError)
|
|
38
|
+
│ ├── errors.ts # Custom error classes
|
|
39
|
+
│ ├── url.ts # URL validation
|
|
40
|
+
│ └── index.ts
|
|
41
|
+
└── types/
|
|
42
|
+
└── index.ts # Type exports
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Pages
|
|
46
|
+
|
|
47
|
+
### Scan Page (`/scan`)
|
|
48
|
+
|
|
49
|
+
Handles URL input and scan initiation:
|
|
50
|
+
|
|
51
|
+
1. User enters URL in form
|
|
52
|
+
2. Validates URL (requires `https://`, valid hostname with `.`)
|
|
53
|
+
3. Calls `scannerApi.startScan(origin)`
|
|
54
|
+
4. Redirects to `/result?trid={trackingId}&site={hostname}`
|
|
55
|
+
|
|
56
|
+
**Required Webflow Elements:**
|
|
57
|
+
|
|
58
|
+
- `data-fs-cs="scan-form"` - Form element
|
|
59
|
+
- `data-fs-cs="scan-url-input"` - URL input field
|
|
60
|
+
- `data-fs-cs="scan-submit"` - Submit button (`<input type="submit">`)
|
|
61
|
+
- `data-fs-cs="error-message"` - Error display
|
|
62
|
+
|
|
63
|
+
### Results Page (`/result`)
|
|
64
|
+
|
|
65
|
+
Polls scan status and displays results:
|
|
66
|
+
|
|
67
|
+
1. Parses `?trid=` and `?site=` query params
|
|
68
|
+
2. Polls `scannerApi.getStatus(trackingId)` every second
|
|
69
|
+
3. On completion, fetches `scannerApi.getResults(trackingId)`
|
|
70
|
+
4. Updates all result sections via modular updaters
|
|
71
|
+
|
|
72
|
+
**Required Webflow Elements:**
|
|
73
|
+
|
|
74
|
+
- `data-fs-cs="compliance-score"` - Main score display
|
|
75
|
+
- `data-fs-cs="compliance-container"` - Status hero card
|
|
76
|
+
- `data-fs-cs="violations-list"` - Major violations list
|
|
77
|
+
- `data-fs-cs="script-list"` - Unblocked scripts
|
|
78
|
+
- `data-fs-cs="cookie-list"` - Unblocked cookies
|
|
79
|
+
- `data-fs-cs="criteria-list"` - Compliance criteria accordion
|
|
80
|
+
- Plus various stat cards, progress indicators, etc.
|
|
81
|
+
|
|
82
|
+
## API Client
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { scannerApi } from '$api';
|
|
86
|
+
|
|
87
|
+
// Start a scan
|
|
88
|
+
const { trackingId } = await scannerApi.startScan('https://example.com');
|
|
89
|
+
|
|
90
|
+
// Poll status
|
|
91
|
+
const status = await scannerApi.getStatus(trackingId);
|
|
92
|
+
// status.status: 'queued' | 'running' | 'completed' | 'failed'
|
|
93
|
+
// status.progress: { pagesScanned, totalPages }
|
|
94
|
+
|
|
95
|
+
// Get results
|
|
96
|
+
const results = await scannerApi.getResults(trackingId);
|
|
97
|
+
// results.results: ScanResults with detectedItems, statistics, etc.
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Selector System
|
|
101
|
+
|
|
102
|
+
Type-safe element queries with automatic type inference:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { querySelector, querySelectorAll } from '$utils';
|
|
106
|
+
|
|
107
|
+
// Returns HTMLFormElement | null
|
|
108
|
+
const form = querySelector('scan-form');
|
|
109
|
+
|
|
110
|
+
// Returns HTMLInputElement | null
|
|
111
|
+
const input = querySelector('scan-url-input');
|
|
112
|
+
|
|
113
|
+
// Query within scope
|
|
114
|
+
const value = querySelector('value', parentElement);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
All element names are defined in `src/utils/selectors.ts` with their corresponding HTML element types.
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
### Setup
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pnpm install
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Development Mode
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pnpm dev
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Serves at `http://localhost:3000` with live reload.
|
|
134
|
+
|
|
135
|
+
### Build
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pnpm build
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Outputs to `dist/scan.js` and `dist/results.js`.
|
|
142
|
+
|
|
143
|
+
### Type Check
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
pnpm check
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Lint
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
pnpm lint:fix
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Configuration
|
|
156
|
+
|
|
157
|
+
### API Base URL
|
|
158
|
+
|
|
159
|
+
Set via environment variable or `.env` file:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
API_BASE_URL=https://fs-consentpro-api-dev.finsweet.workers.dev
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Injected at build time via `bin/build.js`.
|
|
166
|
+
|
|
167
|
+
## Webflow Integration
|
|
168
|
+
|
|
169
|
+
1. Build the project: `pnpm build`
|
|
170
|
+
2. Upload `dist/scan.js` to your scan page
|
|
171
|
+
3. Upload `dist/results.js` to your results page
|
|
172
|
+
4. Add required `data-fs-cs` attributes to elements
|
|
173
|
+
|
|
174
|
+
### Scan Page Structure
|
|
175
|
+
|
|
176
|
+
```html
|
|
177
|
+
<form data-fs-cs="scan-form">
|
|
178
|
+
<input type="url" data-fs-cs="scan-url-input" placeholder="https://example.com" />
|
|
179
|
+
<input type="submit" data-fs-cs="scan-submit" value="Scan" data-wait="Scanning..." />
|
|
180
|
+
</form>
|
|
181
|
+
<div data-fs-cs="error-message" style="display: none;"></div>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Results Page Structure
|
|
185
|
+
|
|
186
|
+
See `src/utils/selectors.ts` for the complete list of element names and their expected types.
|
|
187
|
+
|
|
188
|
+
## Path Aliases
|
|
189
|
+
|
|
190
|
+
- `$api` → `src/api/index.ts`
|
|
191
|
+
- `$utils` → `src/utils/index.ts`
|
|
192
|
+
- `$types` → `src/types/index.ts`
|
|
193
|
+
- `$pages` → `src/pages/`
|
|
194
|
+
- `$icons` → `src/icons/index.ts`
|
package/dist/results.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var re=Object.defineProperty;var ie=(t,e,o)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var H=(t,e,o)=>ie(t,typeof e!="symbol"?e+"":e,o);var E=t=>t.type==="script"||t.type==="iframe"||t.type==="link"||t.type==="noscript",R=t=>t.type==="cookie"||t.type==="local-storage"||t.type==="session-storage",ae=[{id:"cookieyes",name:"CookieYes",patterns:{scripts:[/cookieyes\.com/i,/cookie-law-info/i],cookies:[/cookieyes-consent/i,/cky-consent/i,/cookielawinfo/i],dom:[/cky-consent/i,/cookie-law-info/i]}},{id:"termly",name:"Termly",patterns:{scripts:[/termly\.io/i,/termly-embed/i],cookies:[/termly/i],dom:[/termly/i]}},{id:"consentmanager",name:"Consentmanager.net",patterns:{scripts:[/consentmanager\.net/i,/consent-manager/i],cookies:[/consentmanager/i,/cmapi/i],dom:[/consent-manager/i]}},{id:"enzuzo",name:"Enzuzo",patterns:{scripts:[/enzuzo\.com/i],cookies:[/enzuzo/i],dom:[/enzuzo/i]}},{id:"cookiebot",name:"Cookiebot (by Usercentrics)",patterns:{scripts:[/cookiebot\.com/i,/consent\.cookiebot/i],cookies:[/CookieConsent/i,/cookiebot/i],dom:[/CookieConsent/i,/cookiebot/i]}},{id:"iubenda",name:"Iubenda",patterns:{scripts:[/iubenda\.com/i,/iubenda_cs/i],cookies:[/_iub_cs/i,/iubenda/i],dom:[/iubenda/i,/_iub_cs/i]}},{id:"osano",name:"Osano",patterns:{scripts:[/osano\.com/i],cookies:[/osano/i],dom:[/osano/i]}},{id:"usercentrics",name:"Usercentrics",patterns:{scripts:[/usercentrics\.eu/i,/usercentrics\.com/i],cookies:[/usercentrics/i,/uc_user_interaction/i],dom:[/usercentrics/i]}},{id:"cookiescript",name:"CookieScript",patterns:{scripts:[/cookiescript\.com/i,/cookie-script/i],cookies:[/CookieScriptConsent/i],dom:[/cookie-script/i]}},{id:"secureprivacy",name:"Secure Privacy",patterns:{scripts:[/secureprivacy\.ai/i],cookies:[/secureprivacy/i],dom:[/secureprivacy/i]}},{id:"onetrust",name:"OneTrust",patterns:{scripts:[/onetrust\.com/i,/optanon/i],cookies:[/OptanonConsent/i,/OptanonAlertBoxClosed/i],dom:[/onetrust/i,/optanon/i]}},{id:"trustarc",name:"TrustArc",patterns:{scripts:[/trustarc\.com/i,/truste\.com/i],cookies:[/truste/i,/notice_behavior/i],dom:[/truste/i]}},{id:"axeptio",name:"Axeptio",patterns:{scripts:[/axept\.io/i,/static\.axept\.io/i],cookies:[/axeptio_/i,/axeptio/i],dom:[/axeptio/i]}},{id:"complianz",name:"Complianz",patterns:{scripts:[/complianz/i],cookies:[/complianz/i,/cmplz/i],dom:[/complianz/i,/cmplz/i]}},{id:"quantcast",name:"Quantcast",patterns:{scripts:[/quantcast/i,/quantserve/i],cookies:[/quantcast/i,/__qca/i],dom:[/quantcast/i]}},{id:"cookieconsent-termsfeed",name:"Cookie Consent by TermsFeed",patterns:{scripts:[/cookieconsent\.com/i,/termsfeed\.com/i],cookies:[/cc_cookie/i],dom:[/cookieconsent/i]}},{id:"finsweet-fs-cc",name:"Finsweet [fs-cc] Consent",patterns:{scripts:[/@finsweet\/cookie-consent/i,/fs-cc\.js/i],cookies:[/fs-cc/i,/finsweet.*cookie/i],dom:[/fs-cc-(mode|src|category|placeholder)\s*=/i,/(?:^|[^-])fs-cc(?:[^-]|$)/i,/fs-consent-element/i,/fs-consent_banner/i]}},{id:"finsweet-cookie-consent",name:"Finsweet Cookie Consent | Finsweet Consent Pro",patterns:{scripts:[/@finsweet\/fs-components/i,/finsweet.*cookie-consent/i,/fs-cc\.js/i],cookies:[/fs-consent/i,/(?:^|[^-])fs-cc(?:[^-]|$)/i,/(?:^|[^-])fs-consent(?:[^-]|$)/i,/finsweet.*cookie/i],dom:[/fs-components-installed\s*=\s*["']consent["']/i,/(?:^|[^-])fs-cc(?:[^-]|$)/i,/(?:^|[^-])fs-consent(?:[^-]|$)/i,/fs-consent-element/i,/fs-consent_banner/i]}}],_=/youtube\.com|youtu\.be|vimeo\.com|player\.vimeo/i,U=/maps\.google|maps\.googleapis|google\.com\/maps/i,O=/fonts\.googleapis\.com|fonts\.gstatic\.com/i,j=/googletagmanager\.com|gtm\.js/i,ce=/cdn\.intellimize\.co\/snippet\/\d+\.js/i,z=/intellimize/i,I={ga4:{pattern:/gtag|gtm\.js|googletagmanager|analytics\.js|ga\.js/i,name:"Google Analytics",category:"analytics"},gtm:{pattern:/googletagmanager\.com\/gtm\.js/i,name:"Google Tag Manager",category:"analytics"},metaPixel:{pattern:/connect\.facebook\.net|fbevents\.js|fb-pixel/i,name:"Meta Pixel",category:"marketing"},bingUET:{pattern:/bat\.bing\.com/i,name:"Bing UET",category:"marketing"},googleAds:{pattern:/googleadservices\.com|googlesyndication|pagead2/i,name:"Google Ads",category:"marketing"},hotjar:{pattern:/hotjar\.com|static\.hotjar/i,name:"Hotjar",category:"analytics"},clarity:{pattern:/clarity\.ms/i,name:"Microsoft Clarity",category:"analytics"},linkedin:{pattern:/snap\.licdn\.com|linkedin.*insight/i,name:"LinkedIn Insight",category:"marketing"},twitter:{pattern:/static\.ads-twitter\.com/i,name:"Twitter Pixel",category:"marketing"},tiktok:{pattern:/analytics\.tiktok\.com/i,name:"TikTok Pixel",category:"marketing"},pinterest:{pattern:/pintrk|pinterest.*tag/i,name:"Pinterest Tag",category:"marketing"},hubspot:{pattern:/js\.hs-scripts\.com|js\.hubspot\.com/i,name:"HubSpot",category:"marketing"},intercom:{pattern:/widget\.intercom\.io/i,name:"Intercom",category:"marketing"},segment:{pattern:/segment\.com|segment\.io/i,name:"Segment",category:"analytics"},mixpanel:{pattern:/mixpanel\.com/i,name:"Mixpanel",category:"analytics"},amplitude:{pattern:/amplitude\.com/i,name:"Amplitude",category:"analytics"},heap:{pattern:/heap-analytics|heapanalytics/i,name:"Heap Analytics",category:"analytics"},youtube:{pattern:/youtube\.com|youtu\.be/i,name:"YouTube Embed",category:"marketing"},vimeo:{pattern:/vimeo\.com|player\.vimeo/i,name:"Vimeo Embed",category:"marketing"}};function F(t){let e=[];e.push(le(t)),e.push(me(t)),e.push(pe(t)),e.push(N(t)),e.push(ue(t)),e.push({id:"script-head-placement",name:"Script Head Placement",description:"Verify consent script is placed at the top of <head> section",status:"not-verifiable",details:"Cannot be verified from scan results. Manual review required."}),e.push(de(t)),e.push({id:"auto-placeholder",name:"Auto-placeholder Support",description:"Check if blocked videos have placeholder elements",status:"not-verifiable",details:"Cannot be verified from scan results. Manual review required."});let o={passed:e.filter(l=>l.status==="pass").length,failed:e.filter(l=>l.status==="fail").length,warnings:e.filter(l=>l.status==="warning").length,notVerifiable:e.filter(l=>l.status==="not-verifiable").length},s=e.filter(l=>l.status!=="not-verifiable");if(s.length===0)return{overallScore:0,hasViolations:o.failed>0,criteria:e,summary:o};let n=["consent-tool"],r=0,i=0;for(let l of s){let p=n.includes(l.id)?2:1,g=l.status==="pass"?1:l.status==="warning"?.5:0;r+=g*p,i+=p}return{overallScore:Math.round(r/i*100),hasViolations:o.failed>0,criteria:e,summary:o}}function M(t){if(!t.results)throw new Error("No results found in response for compliance evaluation");return F(t.results)}function le(t){let e=t.detectedItems.filter(E).filter(n=>_.test(n.domain)||_.test(n.source)),o=e.map(n=>n.id);if(e.length===0)return{id:"video-embeds",name:"YouTube/Vimeo Detection",description:"Detect YouTube or Vimeo video embeds that may store cookies",status:"pass",details:"No YouTube or Vimeo embeds detected."};let s=e.filter(n=>n.isThirdParty);return{id:"video-embeds",name:"YouTube/Vimeo Detection",description:"Detect YouTube or Vimeo video embeds that may store cookies",status:"fail",details:`Found ${e.length} video embed(s) from YouTube/Vimeo. ${s.length} are third-party resources that may store cookies before consent.`,affectedItems:o}}function me(t){let e=t.detectedItems.filter(E).filter(s=>U.test(s.domain)||U.test(s.source)),o=e.map(s=>s.id);return e.length===0?{id:"google-maps",name:"Google Maps Detection",description:"Detect Google Maps embeds that may store cookies",status:"pass",details:"No Google Maps embeds detected."}:{id:"google-maps",name:"Google Maps Detection",description:"Detect Google Maps embeds that may store cookies",status:"fail",details:`Found ${e.length} Google Maps embed(s) that may store cookies before consent.`,affectedItems:o}}function pe(t){let e=t.detectedItems.filter(E).filter(s=>O.test(s.domain)||O.test(s.source)),o=e.map(s=>s.id);return e.length===0?{id:"google-fonts",name:"Google Fonts Detection",description:"Detect Google Fonts which transfer IP addresses to Google servers without consent",status:"pass",details:"No Google Fonts detected. Website may be using self-hosted fonts."}:{id:"google-fonts",name:"Google Fonts Detection",description:"Detect Google Fonts which transfer IP addresses to Google servers without consent",status:"fail",details:`Found ${e.length} Google Fonts resource(s). This transfers visitor IP addresses to Google without consent, which is a GDPR violation. Fonts should be self-hosted or loaded only after consent.`,affectedItems:o}}function N(t){let e=[],o=new Map;for(let n of ae){let r=0;if(t.detectedItems&&Array.isArray(t.detectedItems)){for(let i of t.detectedItems)if(E(i)&&i.type==="script"){let{source:a}=i,l=i.element?.outerHTML||"";for(let p of n.patterns.scripts)if(p.test(a)||p.test(l)){r+=1,e.includes(i.id)||e.push(i.id);break}}}if(t.trackersInfo?.providers&&Array.isArray(t.trackersInfo.providers))for(let i of t.trackersInfo.providers){let a=i.name||"";for(let l of n.patterns.scripts)if(l.test(a)){r+=1,e.includes(i.id)||e.push(i.id);break}}if(t.detectedItems&&Array.isArray(t.detectedItems)){for(let i of t.detectedItems)if(R(i)&&i.type==="cookie"){let{name:a}=i;for(let l of n.patterns.cookies)if(l.test(a)){r+=1,e.includes(i.id)||e.push(i.id);break}}}if(t.detectedItems&&Array.isArray(t.detectedItems))for(let i of t.detectedItems){let l=E(i)&&i.element?.outerHTML||"";for(let p of n.patterns.dom)if(p.test(l)){r+=1,e.includes(i.id)||e.push(i.id);break}}r>0&&o.set(n.name,r)}let s=Array.from(o.entries()).sort((n,r)=>r[1]-n[1]).map(([n])=>n);return s.length===0?{id:"consent-tool",name:"\u26A0\uFE0F Consent Tool Detection",description:"Check if a cookie consent management tool is installed",status:"fail",details:"No cookie consent tool detected. A consent banner is required for GDPR compliance."}:{id:"consent-tool",name:"Consent Tool Detection",description:"Check if a cookie consent management tool is installed",status:"pass",details:`Detected consent tool(s): ${s.join(", ")}`,affectedItems:e}}function ue(t){let e=t.detectedItems.filter(s=>{if(!E(s)||s.category!=="uncategorized"||!s.isThirdParty)return!1;let n=s.domain??"",r=s.source??"";return!(j.test(n)||j.test(r))}),o=e.map(s=>s.id);return e.length===0?{id:"uncategorized-trackers",name:"Uncategorized Third-Party Trackers",description:"Check for third-party resources without proper categorization",status:"pass",details:"All third-party resources are properly categorized."}:{id:"uncategorized-trackers",name:"Uncategorized Third-Party Trackers",description:"Check for third-party resources without proper categorization",status:"fail",details:`Found ${e.length} uncategorized third-party resource(s). These should be reviewed and categorized for proper consent management.`,affectedItems:o}}function de(t){let e=t.detectedItems??[];if(!e.some(l=>E(l)&&l.type==="script"&&ce.test(l.source)))return{id:"webflow-optimize",name:"Webflow Optimize Detection",description:"Detect Webflow Optimize and Analyze configurations",status:"pass",details:"Webflow Optimize/Analyze (Intellimize) not detected."};if(N(t).status!=="pass")return{id:"webflow-optimize",name:"Webflow Optimize Detection",description:"Detect Webflow Optimize and Analyze configurations",status:"pass",details:"Webflow Optimize detected; no CMP\u2014consent-gating not applicable."};let n=e.filter(l=>R(l)&&l.type==="cookie"&&z.test(l.name)),r=e.filter(l=>R(l)&&l.type==="session-storage"&&z.test(l.name)),i=e.filter(l=>R(l)&&l.type==="local-storage"&&z.test(l.name)),a=[];if(n.length>0&&a.push(`${n.length} cookie(s)`),r.length>0&&a.push(`${r.length} session-storage key(s)`),i.length>0&&a.push(`${i.length} local-storage key(s)`),a.length>0){let l=[...n.map(p=>p.id),...r.map(p=>p.id),...i.map(p=>p.id)];return{id:"webflow-optimize",name:"Webflow Optimize Detection",description:"Detect Webflow Optimize and Analyze configurations",status:"fail",details:`Intellimize cookies/storage present despite CMP: ${a.join(", ")}.`,affectedItems:l}}return{id:"webflow-optimize",name:"Webflow Optimize Detection",description:"Detect Webflow Optimize and Analyze configurations",status:"pass",details:"Webflow Optimize detected; CMP present and no Intellimize cookies or storage detected."}}function $(t){let e=N(t);return e.status!=="pass"||!e.details?null:e.details.match(/Detected consent tool\(s\): (.+)/)?.[1]?.trim()??null}function V(t){return F(t).criteria.filter(o=>o.status==="fail").map(o=>`${o.name}: ${o.details}`)}function G(t){let e=[],o=t.detectedItems??[],s=o.filter(E),n=o.filter(R),r=s.some(m=>m.type==="script"&&m.isThirdParty&&I.ga4.pattern.test(m.source)),i=s.some(m=>m.type==="script"&&m.isThirdParty&&I.metaPixel.pattern.test(m.source)),a=s.some(m=>m.type==="script"&&m.isThirdParty&&I.bingUET.pattern.test(m.source)),l=s.some(m=>m.type==="script"&&m.isThirdParty&&I.hotjar.pattern.test(m.source)),p=s.some(m=>m.type==="script"&&m.isThirdParty&&I.clarity.pattern.test(m.source));r&&e.push("\u{1F534} Google Analytics/GTM is running before user consent"),i&&e.push("\u{1F534} Meta Pixel is firing before user consent"),a&&e.push("\u{1F534} Bing UET tag loads pre-consent"),l&&e.push("\u{1F534} Hotjar is tracking before consent"),p&&e.push("\u{1F534} Microsoft Clarity runs pre-consent");let g=n.filter(m=>m.type==="cookie"&&m.category!=="essential"&&m.category!=="necessary");g.length>0&&e.push(`\u{1F36A} ${g.length} non-essential cookies set before consent`);let u=n.filter(m=>(m.type==="local-storage"||m.type==="session-storage")&&m.category!=="essential"&&m.category!=="necessary");return u.length>0&&e.push(`\u{1F4BE} ${u.length} localStorage/sessionStorage items set pre-consent`),$(t)||e.push("\u26A0\uFE0F No consent management platform detected"),e}var fe=localStorage.getItem("cs-dev")==="true",L=fe?"http://127.0.0.1:8787":"https://fs-consentpro-api-dev.finsweet.workers.dev",ot=1440*60*1e3;var f={success:"#07601d",warning:"#bb5902",error:"#8f0c3d",info:"#367cff","success-foreground":"#25fc54","warning-foreground":"#ffebc4","error-foreground":"#ffcdd9","info-foreground":"#d5e8ff"};function q(t){if(!t.results)throw new Error("No results found in response for scan summary extraction");let{results:e}=t;return{scanId:e.trackingId,scanDuration:e.scanDuration,pagesScanned:e.pagesScanned.length,totalPages:e.totalPagesFound,detectedItemsCount:e.detectedItems.length,scannedAt:e.scannedAt}}function B(t){let e=M(t);return{compliant:!e.hasViolations,score:e.overallScore,violations:e.summary.failed}}function W(t){if(!t.results)throw new Error("No results found in response for actionable items extraction");let{results:e}=t,o=e.detectedItems.filter(r=>r.type==="script").length,s=e.detectedItems.filter(r=>r.type==="cookie").length,n=$(e);return{scripts:o,cookies:s,cmpInstalled:n??void 0}}function Y(t){if(!t.results)throw new Error("No results found in response for violations extraction");return V(t.results)}function X(t){if(!t.results)throw new Error("No results found in response for detected items extraction");let{results:e}=t,o=e.detectedItems.filter(n=>n.type==="script"||n.type==="link"),s=e.detectedItems.filter(n=>n.type==="cookie"||n.type==="local-storage"||n.type==="session-storage");return{dom:o,storage:s}}function Z(t){let e=M(t);return{pass:e.summary.passed,fail:e.summary.failed,warn:e.summary.warnings,unverified:e.summary.notVerifiable}}function K(t){if(!t.results)throw new Error("No results found in response for major violations extraction");return G(t.results)}function Q(t){if(!t.results)throw new Error("No results found in response for statistics extraction");let{results:e}=t;return{scanDuration:he(e.scanDuration),resourcesCount:e.detectedItems.length,firstParty:e.statistics?.firstPartyResources??0,thirdParty:e.statistics?.thirdPartyResources??0,categories:Object.keys(e.statistics?.categoryCounts||{}).length}}function ge(t){return M(t)}function ye(t){return{scanSummary:q(t),compliance:B(t),actionableItems:W(t),violations:Y(t),detectedItems:X(t),complianceSummary:Z(t),majorViolations:K(t),statistics:Q(t)}}function he(t){let e=Math.floor(t/1e3);if(e<60)return`${e}s`;let o=Math.floor(e/60),s=e%60;return`${o}m ${s}s`}var h={extractScanSummary:q,extractCompliance:B,extractActionableItems:W,extractViolations:Y,extractDetectedItems:X,extractComplianceSummary:Z,extractMajorViolations:K,extractStatistics:Q,extractFullCompliance:ge,extractAll:ye};var J="data-fs-cs";var c=(t,e=document)=>e.querySelector(`[${J}="${t}"]`),x=(t,e=document)=>e.querySelectorAll(`[${J}="${t}"]`);var ee={"X-Finsweet-ConsentPro-Version":"v2"},te={"X-Finsweet-ConsentPro-Version":"v2","Content-Type":"application/json"},k=class extends Error{constructor(o,s,n){super(o);H(this,"status");H(this,"response");this.name="ScannerApiError",this.status=s,this.response=n}};async function D(t){if(!t.ok){let e=await t.text().catch(()=>"Unknown error");throw new k(`API request failed: ${t.statusText}`,t.status,e)}return t.json()}var P={async startScan(t){let e=await fetch(`${L}/v2/scanner/public/scan`,{method:"POST",headers:te,body:JSON.stringify({url:t})});if(e.status===409){let s=await e.json(),{trackingId:n}=s;if(n&&typeof n=="string")return s;throw new k("Scan conflict (409) but no trackingId in response",409,s)}return await D(e)},async getStatus(t){let e=await fetch(`${L}/v2/scanner/public/status/${t}`,{headers:ee});return await D(e)},async getResults(t){let e=await fetch(`${L}/v2/scanner/public/results/${t}`,{headers:ee});return await D(e)},async cancelScan(t){let e=await fetch(`${L}/v2/scanner/public/scan/${t}`,{method:"DELETE",headers:te});return await D(e)}};var Ee='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>',ke='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',be='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 2 20 20"/><path d="M8.35 2.69A10 10 0 0 1 21.3 15.65"/><path d="M19.08 19.08A10 10 0 1 1 4.92 4.92"/></svg>',Ce='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16h.01M12 8v4M7.86 2h8.28L22 7.86v8.28L16.14 22H7.86L2 16.14V7.86z"/></svg>',xe='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>',Se='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/></svg>',we='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',Te='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg>',Ie={"warning-triangle":Ee,"check-circle":ke,"circle-off":be,"alert-octagon":Ce,"chevron-right":xe,"alert-circle":Se,clock:we,"help-circle":Te},Re=(t,e)=>{let o=Ie[t];return e?.color&&(o=o.replace(/currentColor/g,e.color)),e?.size&&(o=o.replace("<svg",`<svg width="${e.size}" height="${e.size}"`)),o},b=(t,e,o)=>{let s=Re(e,o),n=document.createElement("template");n.innerHTML=s.trim();let r=n.content.firstElementChild;if(!r)return null;if(r.setAttribute("data-fs-icon",e),o?.size&&(r.style.setProperty("width",`${o.size}px`,"important"),r.style.setProperty("height",`${o.size}px`,"important")),t.className){let i=r.getAttribute("class")||"";r.setAttribute("class",`${i} ${t.className}`.trim())}return t.replaceWith(r),r};var Le=1e3,A={compliant:"check-circle",notCompliant:"circle-off",warning:"warning-triangle"},oe={pass:{icon:"check-circle",color:f.success,label:"pass"},fail:{icon:"alert-circle",color:f.error,label:"fail"},warning:{icon:"warning-triangle",color:f.warning,label:"warning"},"not-verifiable":{icon:"help-circle",color:f.info,label:"not verifiable"}},ne=t=>t.type==="script"||t.type==="iframe"||t.type==="link"||t.type==="noscript",se=t=>t.type==="cookie"||t.type==="local-storage"||t.type==="session-storage",Ae=()=>{let t=new URLSearchParams(window.location.search),e=t.get("trid"),o=t.get("site");return!e||!o?(console.error("[Results] Missing required query parameters:",{trid:e,site:o}),null):{trackingId:e,site:o}},Me=t=>{let e=c("current-scan-activity");e&&(e.textContent=t)},De=(t,e)=>{let o=c("scan-progress");if(o){let s=e>0?Math.round(t/e*100):0;o.textContent=`${t} / ${e} pages (${s}%)`}},Pe=async t=>new Promise((e,o)=>{let s=setInterval(async()=>{try{let n=await P.getStatus(t);if(n.currentActivity&&Me(n.currentActivity),n.progress){let{pagesScanned:r,totalPages:i}=n.progress;De(r,i)}if(n.status==="completed")clearInterval(s),e();else if(n.status==="failed"){let r=n.error||"Scan failed unexpectedly";console.error("[Results] Scan failed:",r),window.alert(`Scan failed: ${r}`),clearInterval(s),o(new Error(r))}}catch(n){console.error("[Results] Error polling status:",n),window.alert("Unable to check scan status. Please try again."),clearInterval(s),o(n)}},Le)}),He=()=>{let t=c("scan_status-style");t&&t.remove()},ze=async t=>{try{return await P.getResults(t)}catch(e){return e instanceof k?console.error("[Results] API Error:",{message:e.message,status:e.status,response:e.response}):console.error("[Results] Failed to fetch results:",e),null}},Ne=t=>{if(!t.results)return;let{origin:e}=t.results,o=new URL(e).hostname;x("target-website").forEach(r=>{r.textContent=o}),x("target-website-url").forEach(r=>{r instanceof HTMLAnchorElement?r.href=e:r.textContent=e})},$e=t=>{let e=h.extractFullCompliance(t),o=c("compliance-score");if(o){let s=c("value",o);if(s){let n=Math.round(e.overallScore);s.textContent=`${n}%`;let r;n>=80?r=f["success-foreground"]:n>=50?r=f.warning:r=f.error,s.style.color=r}}},_e=(t,e)=>{x("target-website").forEach(n=>{n.textContent=e}),x("target-website-url").forEach(n=>{n instanceof HTMLAnchorElement?n.href=t:n.textContent=t})},Ue=t=>{let e=Math.floor(t/1e3);if(e<60)return`${e}s`;let o=Math.floor(e/60),s=e%60;return`${o}m ${s}s`},Oe=t=>new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),C=(t,e,o,s)=>{let n=c(t);if(!n)return;let r=c("value",n),i=c("text",n);r&&(r.textContent=e),i&&o&&(i.textContent=o),s&&(n.style.backgroundColor=f[s])},je=t=>{if(!t.results)return;let{scanDuration:e,pagesScanned:o,detectedItems:s,scannedAt:n}=t.results;C("scan-duration-card",Ue(e)),C("pages-scanned-card",o.length.toString()),C("items-detected-card",s.length.toString()),C("scan-date-card",Oe(n))},Fe=t=>{if(!t.results)return;let{detectedItems:e}=t.results,o=e.filter(a=>ne(a)&&a.type==="script"&&a.isThirdParty&&(a.category==="analytics"||a.category==="marketing"||a.category==="advertising"||a.category==="uncategorized")).length,s=e.filter(a=>se(a)&&a.type==="cookie"&&a.category!=="essential"&&a.category!=="necessary").length,r=h.extractComplianceSummary(t).fail,{cmpInstalled:i}=h.extractActionableItems(t);C("scripts-detected-card",o.toString(),void 0,o===0?"success":"error"),C("cookies-detected-card",s.toString(),void 0,s===0?"success":"warning"),C("action-items-card",r.toString(),"Violations",r===0?"success":"info"),Ve(!!i)},Ve=t=>{let e=c("cmp-status-card");if(!e)return;let o=c("icon",e),s=c("text",e),n=t?f["success-foreground"]:f["error-foreground"];o&&b(o,t?A.compliant:A.notCompliant,{color:n,size:24}),s&&(s.textContent=t?"CMP Detected":"CMP Not Found"),e.style.backgroundColor=t?f.success:f.error},Ge=t=>{let e=h.extractFullCompliance(t),o=x("compliance-container");if(o.length===0)return;let s=e.summary.failed,n;s===0?n="compliant":s<=2?n="partial":n="non-compliant";let i={compliant:{label:"Compliant",message:"No pre-consent violations detected. Nice work!",icon:A.compliant,color:f.success,iconColor:f["success-foreground"]},partial:{label:"Partial Compliance",message:"Some issues found, but fixable. Let's get you compliant.",icon:A.warning,color:f.warning,iconColor:f["warning-foreground"]},"non-compliant":{label:"Not Compliant",message:"Major compliance gaps detected. Action needed ASAP.",icon:A.notCompliant,color:f.error,iconColor:f["error-foreground"]}}[n];o.forEach(u=>{u.setAttribute("fs-cloak",""),u.classList.add("hide")});let a=null;o.forEach(u=>{(n==="compliant"&&u.classList.contains("compliant")||n!=="compliant"&&!u.classList.contains("compliant"))&&(a=u)}),a||([a]=o),a.removeAttribute("fs-cloak"),a.classList.remove("hide");let l=c("compliance-status",a);if(l){let u=c("icon",l),m=c("text",l);u&&b(u,i.icon,{color:i.iconColor,size:30}),m&&(m.textContent=i.label)}let p=c("compliance-details",a);p&&(p.textContent=i.message);let g=c("violations-wrapper",a);if(g){let u=c("value",g);u&&(u.textContent=s.toString())}a.style.backgroundColor=i.color},qe=t=>{let e=h.extractFullCompliance(t),o=c("violations-component"),s=c("violations-list"),n=c("violation-template");if(!s||!n)return;let r=e.criteria.filter(l=>l.status==="fail");if(o){let l=c("icon",o);l&&b(l,"alert-octagon",{color:f.error,size:24})}Array.from(s.children).forEach(l=>{l!==n&&l.remove()}),n.style.display="none";let a=c("violations-list-empty");if(r.length===0){a&&(a.removeAttribute("fs-cloak"),a.classList.remove("hide")),s.setAttribute("fs-cloak",""),s.classList.add("hide");return}a&&(a.setAttribute("fs-cloak",""),a.classList.add("hide")),s.removeAttribute("fs-cloak"),s.classList.remove("hide"),r.forEach(l=>{let p=n.cloneNode(!0);p.removeAttribute("data-fs-cs"),p.style.display="";let g=c("icon",p);g&&b(g,"chevron-right",{color:f.error,size:16});let u=c("text",p);u&&(u.textContent=`${l.name}: ${l.details}`),s.appendChild(p)})},Be=t=>{let e=h.extractDetectedItems(t),o=e.dom.filter(m=>ne(m)&&m.type==="script"&&m.isThirdParty&&(m.category==="analytics"||m.category==="marketing"||m.category==="advertising"||m.category==="uncategorized")),s=e.storage.filter(m=>se(m)&&m.type==="cookie"&&m.category!=="essential"&&m.category!=="necessary"),n=c("scripts-component"),r=c("script-list"),i=c("script-item"),a=c("script-list-empty");if(r&&i){if(n){let d=c("scripts-title",n);d&&(d.textContent=`Unblocked Scripts (${o.length})`)}Array.from(r.children).forEach(d=>{d!==i&&d.remove()}),i.style.display="none",o.length===0?(a&&(a.removeAttribute("fs-cloak"),a.classList.remove("hide")),r.setAttribute("fs-cloak",""),r.classList.add("hide")):(a&&(a.setAttribute("fs-cloak",""),a.classList.add("hide")),r.removeAttribute("fs-cloak"),r.classList.remove("hide"),o.forEach(d=>{let y=i.cloneNode(!0);y.removeAttribute("data-fs-cs"),y.style.display="";let S=c("script-title",y),w=c("script-url",y),v=c("script-tag",y);if(S&&(S.textContent=d.domain||"Unknown Script"),w&&(w.textContent=d.source?.slice(0,100)||"N/A"),v){let T=d.category||"uncategorized";v.textContent=T,v.classList.remove("is-marketing","is-analytics","is-advertising","is-uncategorized"),v.classList.add(`is-${T}`)}r.appendChild(y)}))}let l=c("cookies-component"),p=c("cookie-list"),g=c("cookie-item"),u=c("cookie-list-empty");if(p&&g){if(l){let d=c("cookies-title",l);d&&(d.textContent=`Unblocked Cookies (${s.length})`)}Array.from(p.children).forEach(d=>{d!==g&&d.remove()}),g.style.display="none",s.length===0?(u&&(u.removeAttribute("fs-cloak"),u.classList.remove("hide")),p.setAttribute("fs-cloak",""),p.classList.add("hide")):(u&&(u.setAttribute("fs-cloak",""),u.classList.add("hide")),p.removeAttribute("fs-cloak"),p.classList.remove("hide"),s.forEach(d=>{let y=g.cloneNode(!0);y.removeAttribute("data-fs-cs"),y.style.display="";let S=c("cookie-name",y),w=c("cookie-url",y),v=c("cookie-tag",y);if(S&&(S.textContent=d.name||"Unknown Cookie"),w&&(w.textContent=d.domain||"N/A"),v){let T=d.category||"uncategorized";v.textContent=T,v.classList.remove("is-marketing","is-analytics","is-advertising","is-uncategorized"),v.classList.add(`is-${T}`)}p.appendChild(y)}))}},We=t=>{let e=h.extractMajorViolations(t),o=c("attention-list"),s=c("attention-item"),n=c("attention-list-empty");if(!(!o||!s)){if(s.style.display="none",e.length===0){n&&(n.removeAttribute("fs-cloak"),n.classList.remove("hide")),o.setAttribute("fs-cloak",""),o.classList.add("hide");return}n&&(n.setAttribute("fs-cloak",""),n.classList.add("hide")),o.removeAttribute("fs-cloak"),o.classList.remove("hide"),e.forEach(r=>{let i=s.cloneNode(!0);i.removeAttribute("data-fs-cs"),i.style.display="";let a=c("text",i);a&&(a.textContent=r),o.appendChild(i)})}},Ye=t=>{let e=h.extractComplianceSummary(t),o=c("passed-items");if(o){let i=c("value",o);i&&(i.textContent=e.pass.toString())}let s=c("failed-items");if(s){let i=c("value",s);i&&(i.textContent=e.fail.toString())}let n=c("warning-items");if(n){let i=c("value",n);i&&(i.textContent=e.warn.toString())}let r=c("unverified-items");if(r){let i=c("value",r);i&&(i.textContent=e.unverified.toString())}},Xe=t=>{let e=h.extractFullCompliance(t),o=c("criteria-list"),s=c("criteria-item");if(!o||!s)return;Array.from(o.children).forEach(r=>{r!==s&&r.remove()}),s.style.display="none",e.criteria.forEach(r=>{let i=s.cloneNode(!0);i.removeAttribute("data-fs-cs"),i.style.display="";let a=oe[r.status]||oe["not-verifiable"],l=c("icon",i);l&&b(l,a.icon,{color:a.color,size:24});let p=c("criteria-title",i),g=c("criteria-description",i);p&&(p.textContent=r.name),g&&(g.textContent=r.description);let u=c("criteria-status",i);u&&(u.textContent=a.label);let m=i.querySelector(".result-detect_right img");m&&b(m,"chevron-right",{size:16});let d=c("criteria-answer",i);d&&(d.textContent=r.details||"No additional details available."),o.appendChild(i)})},Ze=t=>{let e=h.extractStatistics(t),o=c("stat-duration");if(o){let a=c("value",o);a&&(a.textContent=e.scanDuration)}let s=c("stat-resources");if(s){let a=c("value",s);a&&(a.textContent=e.resourcesCount.toString())}let n=c("stat-first-party");if(n){let a=c("value",n);a&&(a.textContent=e.firstParty.toString())}let r=c("stat-third-party");if(r){let a=c("value",r);a&&(a.textContent=e.thirdParty.toString())}let i=c("stat-categories");if(i){let a=c("value",i);a&&(a.textContent=e.categories.toString())}},Ke=[{name:"websiteInfo",updater:Ne},{name:"complianceScore",updater:$e,requiredElements:["compliance-score"]},{name:"primaryStats",updater:je},{name:"secondaryStats",updater:Fe},{name:"complianceContainer",updater:Ge,requiredElements:["compliance-container"]},{name:"violationsList",updater:qe,requiredElements:["violations-list"]},{name:"detectedItems",updater:Be},{name:"actionItems",updater:We},{name:"complianceSummary",updater:Ye},{name:"complianceCriteria",updater:Xe,requiredElements:["criteria-list"]},{name:"statistics",updater:Ze}],Qe=t=>{Ke.forEach(({name:e,updater:o,requiredElements:s})=>{try{if(s&&s.find(r=>!c(r)))return;o(t)}catch(n){console.error(`[Results] Error in updater "${e}":`,n)}})},Je=async()=>{let t=Ae();if(!t){console.error("[Results] Cannot fetch results without tracking ID");return}_e(`https://${t.site}`,t.site);try{await Pe(t.trackingId);let e=await ze(t.trackingId);e?(Qe(e),He()):(console.error("[Results] Failed to fetch results"),window.alert("Unable to load scan results. Please try again."))}catch(e){console.error("[Results] Error during scan monitoring:",e),window.alert(e instanceof Error?e.message:"An error occurred while monitoring the scan. Please try again.")}};window.Webflow||(window.Webflow=[]);window.Webflow.push(()=>{Je()});})();
|
package/dist/scan.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var T=Object.defineProperty;var E=(t,e,n)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var m=(t,e,n)=>E(t,typeof e!="symbol"?e+"":e,n);var S=localStorage.getItem("cs-dev")==="true",a=S?"http://127.0.0.1:8787":"https://fs-consentpro-api-dev.finsweet.workers.dev",z=1440*60*1e3;var k="data-fs-cs";var r=(t,e=document)=>e.querySelector(`[${k}="${t}"]`);var c=t=>{let e=r("error-message");if(!e){console.error("[Helpers] Error element not found:",t);return}e.textContent=t,e.style.display="block",setTimeout(()=>{e.style.display="none"},5e3)},d=()=>{let t=r("error-message");t&&(t.style.display="none",t.textContent="")};var f=t=>{let e=t.trim();if(!e||!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(e)&&e.includes("@"))return null;try{let o=p(e),s=new URL(o);return s.protocol!=="http:"&&s.protocol!=="https:"||!s.hostname||!s.hostname.includes(".")?null:s}catch{return null}};var g={"X-Finsweet-ConsentPro-Version":"v2"},y={"X-Finsweet-ConsentPro-Version":"v2","Content-Type":"application/json"},i=class extends Error{constructor(n,o,s){super(n);m(this,"status");m(this,"response");this.name="ScannerApiError",this.status=o,this.response=s}};async function l(t){if(!t.ok){let e=await t.text().catch(()=>"Unknown error");throw new i(`API request failed: ${t.statusText}`,t.status,e)}return t.json()}var u={async startScan(t){let e=await fetch(`${a}/v2/scanner/public/scan`,{method:"POST",headers:y,body:JSON.stringify({url:t})});if(e.status===409){let o=await e.json(),{trackingId:s}=o;if(s&&typeof s=="string")return o;throw new i("Scan conflict (409) but no trackingId in response",409,o)}return await l(e)},async getStatus(t){let e=await fetch(`${a}/v2/scanner/public/status/${t}`,{headers:g});return await l(e)},async getResults(t){let e=await fetch(`${a}/v2/scanner/public/results/${t}`,{headers:g});return await l(e)},async cancelScan(t){let e=await fetch(`${a}/v2/scanner/public/scan/${t}`,{method:"DELETE",headers:y});return await l(e)}},p=t=>{let e=t.trim();return!e.startsWith("http://")&&!e.startsWith("https://")&&(e="https://"+e),e};var b="[Scan]",h="Please enter a valid URL (e.g. https://example.com).",v="Failed to start scan. Please try again.",x="/result",C=()=>{let t=r("scan-form"),e=r("scan-url-input"),n=r("scan-submit");return!t||!e||!n?(console.error(`${b} Missing elements:`,{form:!!t,urlInput:!!e,submitButton:!!n}),null):{form:t,urlInput:e,submitButton:n}},w=t=>{let e=t.value.trim();if(!e)return c(h),null;let n=f(e);return n||(c(h),null)},I=t=>{let e=t.dataset.wait;e&&(t.value=e)},R=(t,e)=>{t.value=e,t.disabled=!1},M=t=>`${t.origin}${t.pathname}`,D=async(t,e,n)=>{try{let o=await u.startScan(M(t));if(!o.trackingId)throw new Error("No tracking ID returned");let s=new URL(x,window.location.origin);s.searchParams.set("trid",o.trackingId),s.searchParams.set("site",t.hostname),window.location.href=s.href}catch(o){console.error(`${b} Scan failed:`,o);let s=o instanceof i?`Scan failed: ${o.message}`:v;c(s),R(e.submitButton,n)}},L=async(t,e)=>{t.preventDefault(),t.stopPropagation();let n=w(e.urlInput);if(!n)return;e.urlInput.value=n.href,d();let o=e.submitButton.value||"Scan";I(e.submitButton),e.submitButton.disabled=!0,await D(n,e,o)},A=()=>{let t=C();t&&t.form.addEventListener("submit",e=>L(e,t),{capture:!0})};window.Webflow||(window.Webflow=[]);window.Webflow.push(A);})();
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@finsweet/consentpro-scan",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A frontend scanner for ConsentPro, a cookie consent management platform by Finsweet.",
|
|
5
|
+
"homepage": "https://github.com/finsweet/consentpro-scan#readme",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Finsweet",
|
|
10
|
+
"url": "https://finsweet.com/"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/finsweet/consentpro-scan.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/finsweet/consentpro-scan/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "src/index.ts",
|
|
21
|
+
"module": "src/index.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"dev": "cross-env NODE_ENV=development node ./bin/build.js",
|
|
27
|
+
"build": "cross-env NODE_ENV=production node ./bin/build.js",
|
|
28
|
+
"lint": "eslint ./src && prettier --check ./src",
|
|
29
|
+
"lint:fix": "eslint ./src --fix",
|
|
30
|
+
"check": "tsc --noEmit",
|
|
31
|
+
"format": "prettier --write ./src",
|
|
32
|
+
"test": "playwright test",
|
|
33
|
+
"test:ui": "playwright test --ui",
|
|
34
|
+
"release": "changeset publish",
|
|
35
|
+
"update": "pnpm update -i -L -r"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@changesets/changelog-git": "^0.2.0",
|
|
39
|
+
"@changesets/cli": "^2.27.12",
|
|
40
|
+
"@eslint/js": "^9.19.0",
|
|
41
|
+
"@finsweet/eslint-config": "^3.0.3",
|
|
42
|
+
"@finsweet/tsconfig": "^1.4.2",
|
|
43
|
+
"@playwright/test": "^1.50.1",
|
|
44
|
+
"cross-env": "^7.0.3",
|
|
45
|
+
"esbuild": "^0.24.2",
|
|
46
|
+
"eslint": "^9.19.0",
|
|
47
|
+
"eslint-config-prettier": "^10.0.1",
|
|
48
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
49
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
50
|
+
"prettier": "^3.4.2",
|
|
51
|
+
"typescript": "^5.7.3",
|
|
52
|
+
"typescript-eslint": "^8.23.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@finsweet/ts-utils": "^0.40.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"pnpm": ">=10"
|
|
59
|
+
},
|
|
60
|
+
"pnpm": {
|
|
61
|
+
"overrides": {
|
|
62
|
+
"esbuild@<=0.24.2": ">=0.25.0",
|
|
63
|
+
"@babel/runtime@<7.26.10": ">=7.26.10",
|
|
64
|
+
"cross-spawn@>=7.0.0 <7.0.5": ">=7.0.5",
|
|
65
|
+
"brace-expansion@>=2.0.0 <=2.0.1": ">=2.0.2",
|
|
66
|
+
"@eslint/plugin-kit@<0.3.4": ">=0.3.4",
|
|
67
|
+
"playwright@<1.55.1": ">=1.55.1",
|
|
68
|
+
"tmp@<=0.2.3": ">=0.2.4",
|
|
69
|
+
"js-yaml@>=4.0.0 <4.1.1": ">=4.1.1"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|