@stagepass/modules 1.1.0 → 2.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/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/all.min.js +10 -1
- package/dist/cookies.min.js +1 -1
- package/dist/inject.min.js +1 -1
- package/dist/maintenance.min.js +10 -0
- package/global.d.ts +113 -0
- package/package.json +11 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Herz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# `@stagepass/modules`
|
|
2
|
+
|
|
3
|
+
Modular runtime extensions for Stagepass.
|
|
4
|
+
|
|
5
|
+
This package provides optional browser modules that extend `@stagepass/loader`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @stagepass/loader@2 @stagepass/modules@2
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@stagepass/loader` should be loaded first.
|
|
14
|
+
Without the loader, `inject` and `cookies` still attach their APIs and warn; `maintenance` skips registration.
|
|
15
|
+
`@stagepass/modules` declares `@stagepass/loader` as a peer dependency (`>=2.0.0`).
|
|
16
|
+
|
|
17
|
+
## CDN Usage
|
|
18
|
+
|
|
19
|
+
Prefer the major pin `@2` in production on jsDelivr. Stagepass follows strict semver: no breaking changes within v2; breaking changes only in a new major (v3). Exact pins (e.g. `@2.1.0`) are optional for maximum control. jsDelivr may cache `@2` for a while; purge with the same pattern as the loader (see root README [Version pinning](../../README.md#-version-pinning)).
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script
|
|
23
|
+
src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js"
|
|
24
|
+
data-stagepass-version="2.1.0"
|
|
25
|
+
></script>
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/inject.min.js"></script>
|
|
27
|
+
<script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/cookies.min.js"></script>
|
|
28
|
+
<script
|
|
29
|
+
src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/maintenance.min.js"
|
|
30
|
+
data-stagepass-maintenance="true"
|
|
31
|
+
data-stagepass-maintenance-title="We will be back soon"
|
|
32
|
+
data-stagepass-maintenance-text="Please check again shortly."
|
|
33
|
+
></script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or load all modules:
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<script src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js"></script>
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/all.min.js"></script>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
unpkg serves the same paths if you need an alternative CDN.
|
|
44
|
+
|
|
45
|
+
Published files: `dist/inject.min.js`, `dist/cookies.min.js`, `dist/maintenance.min.js`, `dist/all.min.js`.
|
|
46
|
+
|
|
47
|
+
## Available Modules
|
|
48
|
+
|
|
49
|
+
### Injector (`inject.min.js`)
|
|
50
|
+
|
|
51
|
+
Registers `sp.inject` (also `stagepass.inject`). Accepts a single options object, an array, or `{ scripts, styles }`.
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
await sp.inject({
|
|
55
|
+
src: 'https://cdn.example.com/lib.js',
|
|
56
|
+
stagepass: true,
|
|
57
|
+
localPath: 'lib.js', // alias: path
|
|
58
|
+
id: 'my-library',
|
|
59
|
+
type: 'script', // or 'style'; auto-detected from .css
|
|
60
|
+
version: '2.1.0', // production ?v=<version>
|
|
61
|
+
async: false, // default false (keeps order)
|
|
62
|
+
defer: true, // default true unless async is true
|
|
63
|
+
position: 'head', // 'head' | 'body-start' | 'body-end' | { target, action }
|
|
64
|
+
integrity: 'sha384-abc',
|
|
65
|
+
crossorigin: 'anonymous',
|
|
66
|
+
nonce: 'csp-nonce',
|
|
67
|
+
allowedHosts: ['cdn.example.com'],
|
|
68
|
+
attributes: { 'data-foo': 'bar' },
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Options**
|
|
73
|
+
|
|
74
|
+
| Field | Description |
|
|
75
|
+
| :--- | :--- |
|
|
76
|
+
| `src` | Required production URL. |
|
|
77
|
+
| `type` | `'script'` \| `'style'` (default: `.css` → style, else script). |
|
|
78
|
+
| `stagepass` | When not `false` and `sp.vars.isLocal`, resolve a local URL via `sp.resolveLocalUrl` (fallback `https://<domain>/<path>?_cb=<timestamp>`). |
|
|
79
|
+
| `localPath` / `path` | Local path under the linked root (default: filename from `src`). |
|
|
80
|
+
| `id` | Element id; skips inject if already present. |
|
|
81
|
+
| `async` | If `true`, set `script.async = true`; otherwise `async = false` and keep order. |
|
|
82
|
+
| `defer` | Default `true` when not async; set `false` to omit defer. |
|
|
83
|
+
| `version` | Production cache bust: append `?v=<version>` (URL-encoded). |
|
|
84
|
+
| `cacheBust` | Deprecated; does **not** append per-view timestamps in v2 production. Prefer `version`. |
|
|
85
|
+
| `attributes` | Extra HTML attributes on the created element. |
|
|
86
|
+
| `integrity` | Pass-through SRI hash. |
|
|
87
|
+
| `crossorigin` | Pass-through CORS mode. |
|
|
88
|
+
| `nonce` | Optional CSP nonce. |
|
|
89
|
+
| `allowedHosts` | Optional host allowlist; other hosts are skipped with a warning. |
|
|
90
|
+
| `position` | `'head'` \| `'body-start'` \| `'body-end'` (default) \| `{ target: cssSelector, action: 'before' \| 'after' }`. |
|
|
91
|
+
|
|
92
|
+
Deduplication: skips when `id` already exists or a matching `script[src]` / `link[href]` is present. Failed items log in non-production and do not abort the rest of a batch.
|
|
93
|
+
|
|
94
|
+
### Cookies (`cookies.min.js`)
|
|
95
|
+
|
|
96
|
+
Registers `sp.cookies` and singular alias `sp.cookie`. Cookie helpers only, **not** a consent manager or legal compliance solution. A tiny optional consent hook (`sp.consent`) can gate categorized writes.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
sp.cookies.bake('token', 'abc123', { days: 7, path: '/' });
|
|
100
|
+
sp.cookie.eat('token'); // singular alias
|
|
101
|
+
sp.cookies.has('token'); // true
|
|
102
|
+
sp.cookies.list(); // { token: 'abc123', ... }
|
|
103
|
+
sp.cookies.throw('token', { path: '/' });
|
|
104
|
+
|
|
105
|
+
sp.cookies.bake('analytics_id', 'x', { category: 'analytics', days: 30 });
|
|
106
|
+
sp.cookies.throwAll({ category: 'analytics' });
|
|
107
|
+
sp.cookies.jar(); // copy of known cookies
|
|
108
|
+
sp.cookies.crumbs('analytics_'); // matching known names
|
|
109
|
+
|
|
110
|
+
// Consent hook (tooling only; default allows all)
|
|
111
|
+
sp.consent.set((category) => category !== 'marketing');
|
|
112
|
+
sp.cookies.bake('ad', '1', { category: 'marketing' }); // queued
|
|
113
|
+
sp.consent.set(() => true);
|
|
114
|
+
sp.consent.update(); // flushes queue
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
| Method | Description |
|
|
118
|
+
| :--- | :--- |
|
|
119
|
+
| `bake(name, value, options?)` | Write/update a cookie. Optional `category` remembers the category and may queue when consent rejects. |
|
|
120
|
+
| `eat(name, options?)` | Read a cookie; `null` if missing. |
|
|
121
|
+
| `throw(name, options?)` | Delete via `Max-Age=0` + expired date. |
|
|
122
|
+
| `has(name)` | Existence check. |
|
|
123
|
+
| `list(options?)` | All visible cookies as a name → value map. |
|
|
124
|
+
| `throwAll({ category? })` | Delete known cookies, optionally by category. |
|
|
125
|
+
| `jar()` | Shallow copy of cookies known to this helper. |
|
|
126
|
+
| `crumbs(prefix)` | Known cookie names starting with `prefix`. |
|
|
127
|
+
|
|
128
|
+
**`bake` options:** `days?`, `maxAge?` (seconds), `path?` (default `/`), `domain?`, `secure?` (default `true` on HTTPS), `sameSite?` (`'Lax'` \| `'Strict'` \| `'None'`, default `'Lax'`), `encode?` (default `true`), `json?`, `category?`.
|
|
129
|
+
|
|
130
|
+
**`eat` / `list` options:** `decode?` (default `true`), `json?`.
|
|
131
|
+
|
|
132
|
+
**`throw` options:** `path?` (default `/`), `domain?`, `secure?`, `sameSite?`.
|
|
133
|
+
|
|
134
|
+
Notes: `HttpOnly` cookies are invisible to JS; use the same `path`/`domain` to delete; `sameSite: 'None'` forces `Secure=true`.
|
|
135
|
+
|
|
136
|
+
### Maintenance (`maintenance.min.js`)
|
|
137
|
+
|
|
138
|
+
Client-side full-page overlay for visitors when enabled. **Not access protection**: page HTML remains in the document. This module does **not** inject `noindex`; SEO handling belongs to the site.
|
|
139
|
+
|
|
140
|
+
Off unless `data-stagepass-maintenance="true"` on the module script tag (or enabled programmatically).
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<script
|
|
144
|
+
src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/maintenance.min.js"
|
|
145
|
+
data-stagepass-maintenance="true"
|
|
146
|
+
data-stagepass-maintenance-title="We will be back soon"
|
|
147
|
+
data-stagepass-maintenance-text="Please check again shortly."
|
|
148
|
+
></script>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Behaviour:
|
|
152
|
+
- Visitors without an active Stagepass session see the overlay (text via `textContent` only; accessible `role` / focus / `aria`).
|
|
153
|
+
- Developers with an active session (or `?stagepass=debug`) see the real page plus a small badge.
|
|
154
|
+
- Respects `prefers-color-scheme`; no external resources.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
sp.maintenance.enable({ title: 'We will be back soon', text: 'Please check again shortly.' });
|
|
158
|
+
sp.maintenance.isActive(); // true
|
|
159
|
+
sp.maintenance.disable();
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Types
|
|
163
|
+
|
|
164
|
+
`global.d.ts` extends `@stagepass/loader` via declaration merging (`inject`, `cookies` / `cookie`, `consent`, `maintenance`).
|
|
165
|
+
|
|
166
|
+
## Repository
|
|
167
|
+
|
|
168
|
+
- Full docs and examples: [stagepass repository](https://github.com/arobertherz/stagepass)
|
|
169
|
+
- Migration: [MIGRATION.md](../../MIGRATION.md)
|
package/dist/all.min.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
"use strict";var StagepassModules=(()=>{(function(){function p(){let e=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!e||!e.vars)throw new Error("Stagepass core loader must be loaded before modules");return e.vars}function y(e){let s=p();(s.env==="local"||s.env==="staging")&&console.log(`[Stagepass] ${e}`)}function g(e){if(!e||typeof e!="string")return"file";try{let t=new URL(e).pathname||"";if(!t||t.length===0){let o=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return o?o[1]:"file"}let n=t.split("/");return n[n.length-1]||n[n.length-2]||"file"}catch{try{let t=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return t?t[1]:"file"}catch{return"file"}}}function h(e,s){if(s)return s;if(!e||typeof e!="string")return"script";try{if(e.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function b(e){let s=p(),{src:t,stagepass:n,localPath:o,path:i,cacheBust:d}=e;if(!t||typeof t!="string")throw new Error("Invalid src: must be a non-empty string");if(n!==!1&&s.isLocal){let a=o||i||g(t);if(!a||typeof a!="string")return t;let r=a.startsWith("/")?a.substring(1):a,c=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(c&&typeof c.resolveLocalUrl=="function"){let l=c.resolveLocalUrl(r);if(l)return l}return`https://${s.domain}/${r}?_cb=${s.timestamp}`}return d?t+(t.includes("?")?"&":"?")+"_cb="+Date.now():t}function m(e,s){let{id:t,type:n}=e,o=h(e.src,n);if(t&&document.getElementById(t))return y(`Skipping injection: Element with id "${t}" already exists`),!0;let i=o==="script"?`script[src="${s}"]`:`link[href="${s}"]`;return document.querySelector(i)?(y(`Skipping injection: Resource "${s}" already loaded`),!0):!1}function w(e="body-end"){if(typeof e=="string")switch(e){case"head":return document.head;case"body-start":return document.body?.firstChild||document.body;case"body-end":return document.body;default:return document.body}let{target:s,action:t}=e,n=document.querySelector(s);return n?t==="before"?n:n.nextSibling||n.parentNode:(y(`Warning: Target selector "${s}" not found, falling back to body-end`),document.body)}function S(e){return new Promise((s,t)=>{if(!e.src){let r=p(),c=new Error('InjectOptions must have a "src" property');r.env!=="production"&&console.error("[Stagepass]",c),t(c);return}let n=p(),o=h(e.src,e.type),i=b(e);if(m(e,i)){s();return}let d=o==="script"?document.createElement("script"):document.createElement("link");if(o==="script"){let r=d;r.src=i,e.async?r.async=!0:e.defer!==!1&&(r.defer=!0),e.id&&(r.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([c,l])=>{r.setAttribute(c,l)}),r.onload=()=>{y(`Injected: ${i}`),s()},r.onerror=()=>{let c=new Error(`Failed to load script: ${i}`);n.env!=="production"&&console.error("[Stagepass]",c),t(c)}}else{let r=d;r.rel="stylesheet",r.href=i,e.id&&(r.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([l,u])=>{r.setAttribute(l,u)});let c=setInterval(()=>{(r.sheet||r.styleSheet)&&(clearInterval(c),y(`Injected: ${i}`),s())},10);setTimeout(()=>{if(clearInterval(c),!(r.sheet||r.styleSheet)){let u=new Error(`Failed to load stylesheet: ${i}`);n.env!=="production"&&console.error("[Stagepass]",u),t(u)}},5e3)}let a=w(e.position);if(!a){t(new Error("Could not find insertion point"));return}if(a===document.head||a===document.body)a.appendChild(d);else{let r=a.parentNode;r&&(typeof e.position=="object"&&e.position.action==="before"?r.insertBefore(d,a):r.insertBefore(d,a.nextSibling))}})}async function j(e){let s=[];if(!Array.isArray(e)&&typeof e=="object"&&("scripts"in e||"styles"in e)){let t=e;t.scripts&&s.push(...t.scripts.filter(n=>n&&typeof n=="object"&&"src"in n&&typeof n.src=="string"&&n.src.trim().length>0).map(n=>({...n,type:"script"}))),t.styles&&s.push(...t.styles.filter(n=>n&&typeof n=="object"&&"src"in n&&typeof n.src=="string"&&n.src.trim().length>0).map(n=>({...n,type:"style"})))}else Array.isArray(e)?s=e.filter(t=>t&&typeof t=="object"&&"src"in t&&typeof t.src=="string"&&t.src.trim().length>0):e&&typeof e=="object"&&"src"in e&&typeof e.src=="string"&&e.src.trim().length>0&&(s=[e]);for(let t of s)try{await S(t)}catch(n){p().env!=="production"&&console.error("[Stagepass] Injection error:",n)}}let f=window.stagepass=window.stagepass||{};f.inject=j,globalThis.stagepass=f,window.sp=f,globalThis.sp=f})();(function(){function p(){let e=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!e||!e.vars)throw new Error("Stagepass core loader must be loaded before modules");return e}function y(){return window.location.protocol==="https:"}function g(e){try{return decodeURIComponent(e)}catch{return e}}function h(e,s){let n=s.decode!==!1?g(e):e;if(!s.json)return n;try{return JSON.parse(n)}catch{return n}}function b(e,s,t={}){let n=p();if(!e||typeof e!="string"||e.includes(";"))throw new Error("Invalid cookie name");let o=t.encode!==!1,i=t.sameSite||"Lax",d=t.secure!==void 0?t.secure:y(),a=t.path||"/",r=t.json?JSON.stringify(s):String(s),c=o?encodeURIComponent(e):e;r=o?encodeURIComponent(r):r;let l=[`${c}=${r}`];if(typeof t.maxAge=="number"&&l.push(`Max-Age=${Math.floor(t.maxAge)}`),typeof t.days=="number"){let I=new Date(Date.now()+t.days*24*60*60*1e3);l.push(`Expires=${I.toUTCString()}`)}a&&l.push(`Path=${a}`),t.domain&&l.push(`Domain=${t.domain}`),l.push(`SameSite=${i}`);let u=d;i==="None"&&!u&&(u=!0,typeof n.warn=="function"&&n.warn("SameSite=None requires Secure=true. Enforcing Secure for cookie write.")),u&&l.push("Secure"),document.cookie=l.join("; ")}function m(e,s={}){if(!e||typeof e!="string")return null;let t=s.decode===!1?e:g(e),n=document.cookie?document.cookie.split("; "):[];for(let o of n){let i=o.indexOf("=");if(i<0)continue;let d=o.substring(0,i),a=o.substring(i+1),r=g(d);if(d===t||r===t)return h(a,s)}return null}function w(e){return m(e)!==null}function S(e={}){let s=document.cookie?document.cookie.split("; "):[],t={};for(let n of s){let o=n.indexOf("=");if(o<0)continue;let i=n.substring(0,o),d=n.substring(o+1),a=e.decode===!1?i:g(i);t[a]=h(d,e)}return t}function j(e,s={}){b(e,"",{days:-1,maxAge:0,path:s.path||"/",domain:s.domain,secure:s.secure,sameSite:s.sameSite})}let f=window.stagepass=window.stagepass||{};f.cookies={bake:b,eat:m,throw:j,has:w,list:S},globalThis.stagepass=f,window.sp=f,globalThis.sp=f})();})();
|
|
1
|
+
"use strict";var StagepassModules=(()=>{(function(){function b(){let e=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return e||null}function x(){try{console.warn("[Stagepass] Core loader should be loaded before the inject module.")}catch{}}function S(){let e=b();if(!e||!e.vars)throw new Error("Stagepass core loader must be loaded before modules");return e.vars}let j=new Set(["src","href","rel","integrity","crossorigin","nonce"]);function E(e){try{let n=S();(n.env==="local"||n.env==="staging")&&console.log(`[Stagepass] ${e}`)}catch{}}function A(e){try{let n=b();if(n&&typeof n.warn=="function"){n.warn(e);return}}catch{}try{console.warn(`[Stagepass] ${e}`)}catch{}}function L(e){if(!e||typeof e!="string")return"file";try{let s=new URL(e).pathname||"";if(!s||s.length===0){let p=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return p?p[1]:"file"}let a=s.split("/");return a[a.length-1]||a[a.length-2]||"file"}catch{try{let s=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return s?s[1]:"file"}catch{return"file"}}}function I(e,n){if(n)return n;if(!e||typeof e!="string")return"script";try{if(e.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function T(e,n,s){let a=encodeURIComponent(s),p=e.indexOf("#"),t=p>=0?e.slice(p):"",o=p>=0?e.slice(0,p):e,r=o.includes("?")?"&":"?";return`${o}${r}${encodeURIComponent(n)}=${a}${t}`}function f(e,n){if(!n||n.length===0)return!0;try{let s=new URL(e,window.location.href).hostname.toLowerCase();return n.map(p=>String(p).toLowerCase()).includes(s)}catch{return!1}}function m(e){let n=S(),{src:s,stagepass:a,localPath:p,path:t,version:o}=e;if(!s||typeof s!="string")throw new Error("Invalid src: must be a non-empty string");if(a!==!1&&n.isLocal){let r=p||t||L(s);if(!r||typeof r!="string")return s;let i=r.startsWith("/")?r.substring(1):r,c=b();if(c&&typeof c.resolveLocalUrl=="function"){let y=c.resolveLocalUrl(i);if(y)return y}return`https://${n.domain}/${i}?_cb=${n.timestamp}`}return o?T(s,"v",o):s}function w(e,n){let{id:s,type:a}=e,p=I(e.src,a);if(s&&document.getElementById(s))return E(`Skipping injection: Element with id "${s}" already exists`),!0;if(p==="script"){let t=document.getElementsByTagName("script");for(let o=0;o<t.length;o++)if(t[o].getAttribute("src")===n)return E(`Skipping injection: Resource "${n}" already loaded`),!0}else{let t=document.getElementsByTagName("link");for(let o=0;o<t.length;o++)if(t[o].getAttribute("href")===n)return E(`Skipping injection: Resource "${n}" already loaded`),!0}return!1}function O(e="body-end"){if(typeof e=="string")switch(e){case"head":return document.head;case"body-start":return document.body?.firstChild||document.body;case"body-end":return document.body;default:return document.body}let{target:n,action:s}=e,a=document.querySelector(n);return a?s==="before"?a:a.nextSibling||a.parentNode:(E(`Warning: Target selector "${n}" not found, falling back to body-end`),document.body)}function k(e,n){n.integrity&&e.setAttribute("integrity",n.integrity),n.crossorigin&&e.setAttribute("crossorigin",n.crossorigin),n.nonce&&e.setAttribute("nonce",n.nonce)}function $(e){return new Promise((n,s)=>{if(!e.src){let i=S(),c=new Error('InjectOptions must have a "src" property');i.env!=="production"&&console.error("[Stagepass]",c),s(c);return}if(!f(e.src,e.allowedHosts)){A(`inject: host not allowed for "${e.src}". Check allowedHosts.`),n();return}let a=S(),p=I(e.src,e.type),t=m(e);if(w(e,t)){n();return}let o=p==="script"?document.createElement("script"):document.createElement("link");if(p==="script"){let i=o;e.async?i.async=!0:(i.async=!1,e.defer!==!1&&(i.defer=!0)),e.id&&(i.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([c,y])=>{j.has(String(c).toLowerCase())||i.setAttribute(c,y)}),i.src=t,k(i,e),i.onload=()=>{E(`Injected: ${t}`),n()},i.onerror=()=>{let c=new Error(`Failed to load script: ${t}`);a.env!=="production"&&console.error("[Stagepass]",c),s(c)}}else{let i=o;e.id&&(i.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([y,h])=>{j.has(String(y).toLowerCase())||i.setAttribute(y,h)}),i.rel="stylesheet",i.href=t,k(i,e);let c=setInterval(()=>{(i.sheet||i.styleSheet)&&(clearInterval(c),E(`Injected: ${t}`),n())},10);setTimeout(()=>{if(clearInterval(c),!(i.sheet||i.styleSheet)){let h=new Error(`Failed to load stylesheet: ${t}`);a.env!=="production"&&console.error("[Stagepass]",h),s(h)}},5e3)}let r=O(e.position);if(!r){s(new Error("Could not find insertion point"));return}if(r===document.head||r===document.body)r.appendChild(o);else{let i=r.parentNode;i&&(typeof e.position=="object"&&e.position.action==="before"?i.insertBefore(o,r):i.insertBefore(o,r.nextSibling))}})}async function u(e){let n=[];if(!Array.isArray(e)&&typeof e=="object"&&("scripts"in e||"styles"in e)){let s=e;s.scripts&&n.push(...s.scripts.filter(a=>a&&typeof a=="object"&&"src"in a&&typeof a.src=="string"&&a.src.trim().length>0).map(a=>({...a,type:"script"}))),s.styles&&n.push(...s.styles.filter(a=>a&&typeof a=="object"&&"src"in a&&typeof a.src=="string"&&a.src.trim().length>0).map(a=>({...a,type:"style"})))}else Array.isArray(e)?n=e.filter(s=>s&&typeof s=="object"&&"src"in s&&typeof s.src=="string"&&s.src.trim().length>0):e&&typeof e=="object"&&"src"in e&&typeof e.src=="string"&&e.src.trim().length>0&&(n=[e]);for(let s of n)try{await $(s)}catch(a){try{S().env!=="production"&&console.error("[Stagepass] Injection error:",a)}catch{}}}function d(e){e.inject=u}let l=b()||{};l.vars||x(),l.vars&&typeof l.use=="function"?l.use("inject","2.0.0",d):d(l),window.stagepass=l,globalThis.stagepass=l,window.sp=l,globalThis.sp=l})();(function(){function b(){let f=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return f||null}function x(){try{console.warn("[Stagepass] Core loader should be loaded before the cookies module.")}catch{}}function S(f,m){if(!(m==null||m==="")&&/[;\r\n]/.test(m))throw new Error(`Invalid cookie ${f}`)}function j(){return window.location.protocol==="https:"}function E(f){try{return decodeURIComponent(f)}catch{return f}}function A(f,m){let O=m.decode!==!1?E(f):f;if(!m.json)return O;try{return JSON.parse(O)}catch{return O}}function L(f){let m=new Map,w=[],O=()=>!0;function k(t,o,r={}){if(!t||typeof t!="string"||t.includes(";")||/[\r\n]/.test(t))throw new Error("Invalid cookie name");let i=r.encode!==!1,c=r.sameSite||"Lax";S("sameSite",c);let y=r.secure!==void 0?r.secure:j(),h=r.path||"/";S("path",h),S("domain",r.domain);let v=r.json?JSON.stringify(o):String(o);i||(S("value",v),S("name",t));let _=i?encodeURIComponent(t):t;v=i?encodeURIComponent(v):v;let C=[`${_}=${v}`];if(typeof r.maxAge=="number"&&C.push(`Max-Age=${Math.floor(r.maxAge)}`),typeof r.days=="number"){let M=new Date(Date.now()+r.days*24*60*60*1e3);C.push(`Expires=${M.toUTCString()}`)}h&&C.push(`Path=${h}`),r.domain&&C.push(`Domain=${r.domain}`),C.push(`SameSite=${c}`);let R=y;c==="None"&&!R&&(R=!0,typeof f.warn=="function"&&f.warn("SameSite=None requires Secure=true. Enforcing Secure for cookie write.")),R&&C.push("Secure"),document.cookie=C.join("; ")}function $(t,o,r={}){let i=r.category,c={name:t,value:o,options:{...r},category:i};if(i&&!O(i)){let h=w.findIndex(v=>v.name===t);h>=0&&w.splice(h,1),w.push(c),m.set(t,c);return}k(t,o,r),m.set(t,c);let y=w.findIndex(h=>h.name===t);y>=0&&w.splice(y,1)}function u(t,o={}){if(!t||typeof t!="string")return null;let r=o.decode===!1?t:E(t),i=document.cookie?document.cookie.split("; "):[];for(let c of i){let y=c.indexOf("=");if(y<0)continue;let h=c.substring(0,y),v=c.substring(y+1),_=E(h);if(h===r||_===r)return A(v,o)}return null}function d(t){return u(t)!==null}function l(t={}){let o=document.cookie?document.cookie.split("; "):[],r={};for(let i of o){let c=i.indexOf("=");if(c<0)continue;let y=i.substring(0,c),h=i.substring(c+1),v=t.decode===!1?y:E(y);r[v]=A(h,t)}return r}function g(t,o={}){k(t,"",{days:-1,maxAge:0,path:o.path||"/",domain:o.domain,secure:o.secure,sameSite:o.sameSite}),m.delete(t);let r=w.findIndex(i=>i.name===t);r>=0&&w.splice(r,1)}function e(t={}){let o=t.category,r=[];m.forEach((i,c)=>{(!o||i.category===o)&&r.push(c)});for(let i of r){let c=m.get(i);g(i,{path:c?.options.path,domain:c?.options.domain,secure:c?.options.secure,sameSite:c?.options.sameSite})}}function n(){let t={};return m.forEach((o,r)=>{t[r]=o.value}),t}function s(t){let o=t==null?"":String(t),r=[];return m.forEach((i,c)=>{c.startsWith(o)&&r.push(c)}),r}let a={bake:$,eat:u,throw:g,has:d,list:l,throwAll:e,jar:n,crumbs:s},p={allows(t){try{return O(t)===!0}catch{return!1}},set(t){typeof t=="function"&&(O=t)},update(){let t=w.splice(0,w.length);for(let o of t)!o.category||O(o.category)?$(o.name,o.value,o.options):w.push(o)}};f.cookies=a,f.cookie=a,f.consent=p}let I=b()||{};I.vars||x(),I.vars&&typeof I.use=="function"?I.use("cookies","2.0.0",L):L(I),window.stagepass=I,globalThis.stagepass=I,window.sp=I,globalThis.sp=I})();(function(){let b="stagepass-maintenance-overlay",x="stagepass-maintenance-badge",S="stagepass-maintenance-style",j="We will be back soon",E="This site is temporarily unavailable while we perform maintenance.";function A(){let u=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!u||!u.vars){try{console.warn("[Stagepass] Core loader must be loaded before the maintenance module. Skipping registration.")}catch{}return null}return u}function L(){try{if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}catch{}try{let u=document.querySelectorAll('script[src*="maintenance"]');for(let l=u.length-1;l>=0;l--){let g=u[l];if(/maintenance(?:\.min)?\.js/i.test(g.src||""))return g}let d=document.querySelectorAll('script[src*="all"]');for(let l=d.length-1;l>=0;l--){let g=d[l];if(/all(?:\.min)?\.js/i.test(g.src||"")&&g.hasAttribute("data-stagepass-maintenance"))return g}}catch{}return null}function I(u){try{if(typeof u.is=="function"&&u.is("local"))return!0}catch{}try{let d=localStorage.getItem("stagepass_domain");if(!d)return!1;if(d.startsWith("{")){let l=JSON.parse(d),g=l&&l.domain;if(g==="debug"||typeof g=="string"&&g.endsWith(".sp")||g==="localhost"||typeof g=="string"&&g.startsWith("localhost:"))return!0}}catch{}return!1}function T(){if(document.getElementById(S))return;let u=document.createElement("style");u.id=S,u.textContent=`
|
|
2
|
+
#${b}{position:fixed;inset:0;z-index:2147483646;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#f4f4f5;color:#18181b}
|
|
3
|
+
#${b} .sp-m-card{max-width:32rem;width:100%;text-align:center}
|
|
4
|
+
#${b} .sp-m-title{margin:0 0 12px;font-size:1.75rem;line-height:1.2;font-weight:700}
|
|
5
|
+
#${b} .sp-m-text{margin:0;font-size:1rem;line-height:1.5;opacity:.85}
|
|
6
|
+
#${x}{position:fixed;left:0;bottom:0;z-index:2147483645;font:12px/1.2 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;font-weight:700;color:#fff;background:#b45309;padding:6px 8px;border-radius:0 4px 0 0;cursor:default;user-select:none}
|
|
7
|
+
@media (prefers-color-scheme:dark){
|
|
8
|
+
#${b}{background:#09090b;color:#fafafa}
|
|
9
|
+
#${x}{background:#d97706;color:#111}
|
|
10
|
+
}`,(document.head||document.documentElement).appendChild(u)}function f(u){let d=document.getElementById(u);d&&d.remove()}function m(u,d){T(),f(b),f(x);let l=document.createElement("div");l.id=b,l.setAttribute("role","alertdialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-labelledby","stagepass-maintenance-title"),l.setAttribute("aria-describedby","stagepass-maintenance-desc"),l.tabIndex=-1;let g=document.createElement("div");g.className="sp-m-card";let e=document.createElement("h1");e.id="stagepass-maintenance-title",e.className="sp-m-title",e.textContent=u;let n=document.createElement("p");n.id="stagepass-maintenance-desc",n.className="sp-m-text",n.textContent=d,g.appendChild(e),g.appendChild(n),l.appendChild(g);let s=()=>{(document.body||document.documentElement).appendChild(l);try{l.focus()}catch{}};document.body?s():document.addEventListener("DOMContentLoaded",s,{once:!0})}function w(u){T(),f(b),f(x);let d=document.createElement("div");d.id=x,d.setAttribute("role","status"),d.textContent=`Maintenance mode on (visitors see: ${u})`;let l=()=>{(document.body||document.documentElement).appendChild(d)};document.body?l():document.addEventListener("DOMContentLoaded",l,{once:!0})}function O(u){let d=!1,l=j,g=E;function e(t){t?.title&&(l=String(t.title)),t?.text&&(g=String(t.text)),d=!0,I(u)?w(l):m(l,g)}function n(){d=!1,f(b),f(x)}function s(){return d}u.maintenance={enable:e,disable:n,isActive:s};let a=L();if(a?.getAttribute("data-stagepass-maintenance")==="true"){let t=a?.getAttribute("data-stagepass-maintenance-title")||j,o=a?.getAttribute("data-stagepass-maintenance-text")||E;e({title:t,text:o})}}let k=A();if(!k)return;typeof k.use=="function"?k.use("maintenance","2.0.0",O):O(k),globalThis.stagepass=k,window.sp=k,globalThis.sp=k})();})();
|
package/dist/cookies.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var StagepassInject=(()=>{(function(){function
|
|
1
|
+
"use strict";var StagepassInject=(()=>{(function(){function R(){let i=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return i||null}function v(){try{console.warn("[Stagepass] Core loader should be loaded before the cookies module.")}catch{}}function p(i,r){if(!(r==null||r==="")&&/[;\r\n]/.test(r))throw new Error(`Invalid cookie ${i}`)}function I(){return window.location.protocol==="https:"}function y(i){try{return decodeURIComponent(i)}catch{return i}}function w(i,r){let l=r.decode!==!1?y(i):i;if(!r.json)return l;try{return JSON.parse(l)}catch{return l}}function S(i){let r=new Map,a=[],l=()=>!0;function h(e,o,n={}){if(!e||typeof e!="string"||e.includes(";")||/[\r\n]/.test(e))throw new Error("Invalid cookie name");let s=n.encode!==!1,t=n.sameSite||"Lax";p("sameSite",t);let u=n.secure!==void 0?n.secure:I(),c=n.path||"/";p("path",c),p("domain",n.domain);let d=n.json?JSON.stringify(o):String(o);s||(p("value",d),p("name",e));let k=s?encodeURIComponent(e):e;d=s?encodeURIComponent(d):d;let g=[`${k}=${d}`];if(typeof n.maxAge=="number"&&g.push(`Max-Age=${Math.floor(n.maxAge)}`),typeof n.days=="number"){let _=new Date(Date.now()+n.days*24*60*60*1e3);g.push(`Expires=${_.toUTCString()}`)}c&&g.push(`Path=${c}`),n.domain&&g.push(`Domain=${n.domain}`),g.push(`SameSite=${t}`);let m=u;t==="None"&&!m&&(m=!0,typeof i.warn=="function"&&i.warn("SameSite=None requires Secure=true. Enforcing Secure for cookie write.")),m&&g.push("Secure"),document.cookie=g.join("; ")}function b(e,o,n={}){let s=n.category,t={name:e,value:o,options:{...n},category:s};if(s&&!l(s)){let c=a.findIndex(d=>d.name===e);c>=0&&a.splice(c,1),a.push(t),r.set(e,t);return}h(e,o,n),r.set(e,t);let u=a.findIndex(c=>c.name===e);u>=0&&a.splice(u,1)}function C(e,o={}){if(!e||typeof e!="string")return null;let n=o.decode===!1?e:y(e),s=document.cookie?document.cookie.split("; "):[];for(let t of s){let u=t.indexOf("=");if(u<0)continue;let c=t.substring(0,u),d=t.substring(u+1),k=y(c);if(c===n||k===n)return w(d,o)}return null}function E(e){return C(e)!==null}function A(e={}){let o=document.cookie?document.cookie.split("; "):[],n={};for(let s of o){let t=s.indexOf("=");if(t<0)continue;let u=s.substring(0,t),c=s.substring(t+1),d=e.decode===!1?u:y(u);n[d]=w(c,e)}return n}function O(e,o={}){h(e,"",{days:-1,maxAge:0,path:o.path||"/",domain:o.domain,secure:o.secure,sameSite:o.sameSite}),r.delete(e);let n=a.findIndex(s=>s.name===e);n>=0&&a.splice(n,1)}function D(e={}){let o=e.category,n=[];r.forEach((s,t)=>{(!o||s.category===o)&&n.push(t)});for(let s of n){let t=r.get(s);O(s,{path:t?.options.path,domain:t?.options.domain,secure:t?.options.secure,sameSite:t?.options.sameSite})}}function N(){let e={};return r.forEach((o,n)=>{e[n]=o.value}),e}function $(e){let o=e==null?"":String(e),n=[];return r.forEach((s,t)=>{t.startsWith(o)&&n.push(t)}),n}let x={bake:b,eat:C,throw:O,has:E,list:A,throwAll:D,jar:N,crumbs:$},j={allows(e){try{return l(e)===!0}catch{return!1}},set(e){typeof e=="function"&&(l=e)},update(){let e=a.splice(0,a.length);for(let o of e)!o.category||l(o.category)?b(o.name,o.value,o.options):a.push(o)}};i.cookies=x,i.cookie=x,i.consent=j}let f=R()||{};f.vars||v(),f.vars&&typeof f.use=="function"?f.use("cookies","2.0.0",S):S(f),window.stagepass=f,globalThis.stagepass=f,window.sp=f,globalThis.sp=f})();})();
|
package/dist/inject.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var StagepassInject=(()=>{(function(){function
|
|
1
|
+
"use strict";var StagepassInject=(()=>{(function(){function y(){let t=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;return t||null}function w(){try{console.warn("[Stagepass] Core loader should be loaded before the inject module.")}catch{}}function g(){let t=y();if(!t||!t.vars)throw new Error("Stagepass core loader must be loaded before modules");return t.vars}let h=new Set(["src","href","rel","integrity","crossorigin","nonce"]);function d(t){try{let e=g();(e.env==="local"||e.env==="staging")&&console.log(`[Stagepass] ${t}`)}catch{}}function I(t){try{let e=y();if(e&&typeof e.warn=="function"){e.warn(t);return}}catch{}try{console.warn(`[Stagepass] ${t}`)}catch{}}function O(t){if(!t||typeof t!="string")return"file";try{let n=new URL(t).pathname||"";if(!n||n.length===0){let c=t.match(/\/([^\/\?#]+)(?:\?|#|$)/);return c?c[1]:"file"}let r=n.split("/");return r[r.length-1]||r[r.length-2]||"file"}catch{try{let n=t.match(/\/([^\/\?#]+)(?:\?|#|$)/);return n?n[1]:"file"}catch{return"file"}}}function b(t,e){if(e)return e;if(!t||typeof t!="string")return"script";try{if(t.split(".").pop()?.toLowerCase()==="css")return"style"}catch{}return"script"}function S(t,e,n){let r=encodeURIComponent(n),c=t.indexOf("#"),o=c>=0?t.slice(c):"",i=c>=0?t.slice(0,c):t,a=i.includes("?")?"&":"?";return`${i}${a}${encodeURIComponent(e)}=${r}${o}`}function E(t,e){if(!e||e.length===0)return!0;try{let n=new URL(t,window.location.href).hostname.toLowerCase();return e.map(c=>String(c).toLowerCase()).includes(n)}catch{return!1}}function v(t){let e=g(),{src:n,stagepass:r,localPath:c,path:o,version:i}=t;if(!n||typeof n!="string")throw new Error("Invalid src: must be a non-empty string");if(r!==!1&&e.isLocal){let a=c||o||O(n);if(!a||typeof a!="string")return n;let s=a.startsWith("/")?a.substring(1):a,l=y();if(l&&typeof l.resolveLocalUrl=="function"){let u=l.resolveLocalUrl(s);if(u)return u}return`https://${e.domain}/${s}?_cb=${e.timestamp}`}return i?S(n,"v",i):n}function $(t,e){let{id:n,type:r}=t,c=b(t.src,r);if(n&&document.getElementById(n))return d(`Skipping injection: Element with id "${n}" already exists`),!0;if(c==="script"){let o=document.getElementsByTagName("script");for(let i=0;i<o.length;i++)if(o[i].getAttribute("src")===e)return d(`Skipping injection: Resource "${e}" already loaded`),!0}else{let o=document.getElementsByTagName("link");for(let i=0;i<o.length;i++)if(o[i].getAttribute("href")===e)return d(`Skipping injection: Resource "${e}" already loaded`),!0}return!1}function L(t="body-end"){if(typeof t=="string")switch(t){case"head":return document.head;case"body-start":return document.body?.firstChild||document.body;case"body-end":return document.body;default:return document.body}let{target:e,action:n}=t,r=document.querySelector(e);return r?n==="before"?r:r.nextSibling||r.parentNode:(d(`Warning: Target selector "${e}" not found, falling back to body-end`),document.body)}function m(t,e){e.integrity&&t.setAttribute("integrity",e.integrity),e.crossorigin&&t.setAttribute("crossorigin",e.crossorigin),e.nonce&&t.setAttribute("nonce",e.nonce)}function T(t){return new Promise((e,n)=>{if(!t.src){let s=g(),l=new Error('InjectOptions must have a "src" property');s.env!=="production"&&console.error("[Stagepass]",l),n(l);return}if(!E(t.src,t.allowedHosts)){I(`inject: host not allowed for "${t.src}". Check allowedHosts.`),e();return}let r=g(),c=b(t.src,t.type),o=v(t);if($(t,o)){e();return}let i=c==="script"?document.createElement("script"):document.createElement("link");if(c==="script"){let s=i;t.async?s.async=!0:(s.async=!1,t.defer!==!1&&(s.defer=!0)),t.id&&(s.id=t.id),t.attributes&&Object.entries(t.attributes).forEach(([l,u])=>{h.has(String(l).toLowerCase())||s.setAttribute(l,u)}),s.src=o,m(s,t),s.onload=()=>{d(`Injected: ${o}`),e()},s.onerror=()=>{let l=new Error(`Failed to load script: ${o}`);r.env!=="production"&&console.error("[Stagepass]",l),n(l)}}else{let s=i;t.id&&(s.id=t.id),t.attributes&&Object.entries(t.attributes).forEach(([u,p])=>{h.has(String(u).toLowerCase())||s.setAttribute(u,p)}),s.rel="stylesheet",s.href=o,m(s,t);let l=setInterval(()=>{(s.sheet||s.styleSheet)&&(clearInterval(l),d(`Injected: ${o}`),e())},10);setTimeout(()=>{if(clearInterval(l),!(s.sheet||s.styleSheet)){let p=new Error(`Failed to load stylesheet: ${o}`);r.env!=="production"&&console.error("[Stagepass]",p),n(p)}},5e3)}let a=L(t.position);if(!a){n(new Error("Could not find insertion point"));return}if(a===document.head||a===document.body)a.appendChild(i);else{let s=a.parentNode;s&&(typeof t.position=="object"&&t.position.action==="before"?s.insertBefore(i,a):s.insertBefore(i,a.nextSibling))}})}async function A(t){let e=[];if(!Array.isArray(t)&&typeof t=="object"&&("scripts"in t||"styles"in t)){let n=t;n.scripts&&e.push(...n.scripts.filter(r=>r&&typeof r=="object"&&"src"in r&&typeof r.src=="string"&&r.src.trim().length>0).map(r=>({...r,type:"script"}))),n.styles&&e.push(...n.styles.filter(r=>r&&typeof r=="object"&&"src"in r&&typeof r.src=="string"&&r.src.trim().length>0).map(r=>({...r,type:"style"})))}else Array.isArray(t)?e=t.filter(n=>n&&typeof n=="object"&&"src"in n&&typeof n.src=="string"&&n.src.trim().length>0):t&&typeof t=="object"&&"src"in t&&typeof t.src=="string"&&t.src.trim().length>0&&(e=[t]);for(let n of e)try{await T(n)}catch(r){try{g().env!=="production"&&console.error("[Stagepass] Injection error:",r)}catch{}}}function j(t){t.inject=A}let f=y()||{};f.vars||w(),f.vars&&typeof f.use=="function"?f.use("inject","2.0.0",j):j(f),window.stagepass=f,globalThis.stagepass=f,window.sp=f,globalThis.sp=f})();})();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";var StagepassInject=(()=>{(function(){let s="stagepass-maintenance-overlay",c="stagepass-maintenance-badge",p="stagepass-maintenance-style",f="We will be back soon",g="This site is temporarily unavailable while we perform maintenance.";function h(){let t=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!t||!t.vars){try{console.warn("[Stagepass] Core loader must be loaded before the maintenance module. Skipping registration.")}catch{}return null}return t}function E(){try{if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}catch{}try{let t=document.querySelectorAll('script[src*="maintenance"]');for(let e=t.length-1;e>=0;e--){let a=t[e];if(/maintenance(?:\.min)?\.js/i.test(a.src||""))return a}let n=document.querySelectorAll('script[src*="all"]');for(let e=n.length-1;e>=0;e--){let a=n[e];if(/all(?:\.min)?\.js/i.test(a.src||"")&&a.hasAttribute("data-stagepass-maintenance"))return a}}catch{}return null}function x(t){try{if(typeof t.is=="function"&&t.is("local"))return!0}catch{}try{let n=localStorage.getItem("stagepass_domain");if(!n)return!1;if(n.startsWith("{")){let e=JSON.parse(n),a=e&&e.domain;if(a==="debug"||typeof a=="string"&&a.endsWith(".sp")||a==="localhost"||typeof a=="string"&&a.startsWith("localhost:"))return!0}}catch{}return!1}function b(){if(document.getElementById(p))return;let t=document.createElement("style");t.id=p,t.textContent=`
|
|
2
|
+
#${s}{position:fixed;inset:0;z-index:2147483646;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:#f4f4f5;color:#18181b}
|
|
3
|
+
#${s} .sp-m-card{max-width:32rem;width:100%;text-align:center}
|
|
4
|
+
#${s} .sp-m-title{margin:0 0 12px;font-size:1.75rem;line-height:1.2;font-weight:700}
|
|
5
|
+
#${s} .sp-m-text{margin:0;font-size:1rem;line-height:1.5;opacity:.85}
|
|
6
|
+
#${c}{position:fixed;left:0;bottom:0;z-index:2147483645;font:12px/1.2 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;font-weight:700;color:#fff;background:#b45309;padding:6px 8px;border-radius:0 4px 0 0;cursor:default;user-select:none}
|
|
7
|
+
@media (prefers-color-scheme:dark){
|
|
8
|
+
#${s}{background:#09090b;color:#fafafa}
|
|
9
|
+
#${c}{background:#d97706;color:#111}
|
|
10
|
+
}`,(document.head||document.documentElement).appendChild(t)}function r(t){let n=document.getElementById(t);n&&n.remove()}function S(t,n){b(),r(s),r(c);let e=document.createElement("div");e.id=s,e.setAttribute("role","alertdialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-labelledby","stagepass-maintenance-title"),e.setAttribute("aria-describedby","stagepass-maintenance-desc"),e.tabIndex=-1;let a=document.createElement("div");a.className="sp-m-card";let o=document.createElement("h1");o.id="stagepass-maintenance-title",o.className="sp-m-title",o.textContent=t;let l=document.createElement("p");l.id="stagepass-maintenance-desc",l.className="sp-m-text",l.textContent=n,a.appendChild(o),a.appendChild(l),e.appendChild(a);let u=()=>{(document.body||document.documentElement).appendChild(e);try{e.focus()}catch{}};document.body?u():document.addEventListener("DOMContentLoaded",u,{once:!0})}function v(t){b(),r(s),r(c);let n=document.createElement("div");n.id=c,n.setAttribute("role","status"),n.textContent=`Maintenance mode on (visitors see: ${t})`;let e=()=>{(document.body||document.documentElement).appendChild(n)};document.body?e():document.addEventListener("DOMContentLoaded",e,{once:!0})}function y(t){let n=!1,e=f,a=g;function o(d){d?.title&&(e=String(d.title)),d?.text&&(a=String(d.text)),n=!0,x(t)?v(e):S(e,a)}function l(){n=!1,r(s),r(c)}function u(){return n}t.maintenance={enable:o,disable:l,isActive:u};let m=E();if(m?.getAttribute("data-stagepass-maintenance")==="true"){let d=m?.getAttribute("data-stagepass-maintenance-title")||f,w=m?.getAttribute("data-stagepass-maintenance-text")||g;o({title:d,text:w})}}let i=h();if(!i)return;typeof i.use=="function"?i.use("maintenance","2.0.0",y):y(i),globalThis.stagepass=i,window.sp=i,globalThis.sp=i})();})();
|
package/global.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for `stagepass.inject` / `sp.inject`.
|
|
3
|
+
*/
|
|
4
|
+
export interface StagepassInjectOptions {
|
|
5
|
+
src: string;
|
|
6
|
+
type?: 'script' | 'style';
|
|
7
|
+
stagepass?: boolean;
|
|
8
|
+
localPath?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
async?: boolean;
|
|
12
|
+
defer?: boolean;
|
|
13
|
+
/** @deprecated No longer appends per-view timestamps in production. Use `version`. */
|
|
14
|
+
cacheBust?: boolean;
|
|
15
|
+
/** Production version token appended as `?v=`. */
|
|
16
|
+
version?: string;
|
|
17
|
+
attributes?: Record<string, string>;
|
|
18
|
+
position?:
|
|
19
|
+
| 'head'
|
|
20
|
+
| 'body-start'
|
|
21
|
+
| 'body-end'
|
|
22
|
+
| { target: string; action: 'before' | 'after' };
|
|
23
|
+
/** Subresource Integrity hash. */
|
|
24
|
+
integrity?: string;
|
|
25
|
+
/** CORS mode (`anonymous` / `use-credentials`). */
|
|
26
|
+
crossorigin?: string;
|
|
27
|
+
/** CSP nonce. */
|
|
28
|
+
nonce?: string;
|
|
29
|
+
/** Reject src hosts outside this list (warn + skip). */
|
|
30
|
+
allowedHosts?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface StagepassInjectBatchOptions {
|
|
34
|
+
scripts?: StagepassInjectOptions[];
|
|
35
|
+
styles?: StagepassInjectOptions[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface StagepassCookieWriteOptions {
|
|
39
|
+
days?: number;
|
|
40
|
+
maxAge?: number;
|
|
41
|
+
path?: string;
|
|
42
|
+
domain?: string;
|
|
43
|
+
secure?: boolean;
|
|
44
|
+
sameSite?: 'Lax' | 'Strict' | 'None';
|
|
45
|
+
encode?: boolean;
|
|
46
|
+
json?: boolean;
|
|
47
|
+
/** Optional category for consent gating / throwAll filtering. */
|
|
48
|
+
category?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface StagepassCookiesAPI {
|
|
52
|
+
/** Write a cookie. */
|
|
53
|
+
bake: (name: string, value: unknown, options?: StagepassCookieWriteOptions) => void;
|
|
54
|
+
/** Read a cookie. */
|
|
55
|
+
eat: (name: string, options?: Record<string, unknown>) => unknown;
|
|
56
|
+
/** Delete a cookie. */
|
|
57
|
+
throw: (name: string, options?: Record<string, unknown>) => void;
|
|
58
|
+
/** Whether a cookie exists. */
|
|
59
|
+
has: (name: string) => boolean;
|
|
60
|
+
/** List cookies as a name → value map. */
|
|
61
|
+
list: (options?: Record<string, unknown>) => Record<string, unknown>;
|
|
62
|
+
/** Delete known cookies, optionally by category. */
|
|
63
|
+
throwAll: (options?: { category?: string }) => void;
|
|
64
|
+
/** Shallow copy of cookies known to this helper. */
|
|
65
|
+
jar: () => Record<string, unknown>;
|
|
66
|
+
/** Known cookie names starting with `prefix`. */
|
|
67
|
+
crumbs: (prefix: string) => string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Tiny consent hook used by categorized `bake`.
|
|
72
|
+
* Tooling helper only: not a legal compliance solution.
|
|
73
|
+
*/
|
|
74
|
+
export interface StagepassConsentAPI {
|
|
75
|
+
allows: (category: string) => boolean;
|
|
76
|
+
set: (fn: (category: string) => boolean) => void;
|
|
77
|
+
/** Flush queued cookies against the current consent function. */
|
|
78
|
+
update: () => void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface StagepassMaintenanceAPI {
|
|
82
|
+
enable: (opts?: { title?: string; text?: string }) => void;
|
|
83
|
+
disable: () => void;
|
|
84
|
+
isActive: () => boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type StagepassInjectAPI = (
|
|
88
|
+
options:
|
|
89
|
+
| StagepassInjectOptions
|
|
90
|
+
| StagepassInjectOptions[]
|
|
91
|
+
| StagepassInjectBatchOptions
|
|
92
|
+
) => Promise<void>;
|
|
93
|
+
|
|
94
|
+
/** Declaration merging: extend loader StagepassAPI with modules. */
|
|
95
|
+
declare module '@stagepass/loader' {
|
|
96
|
+
interface StagepassAPI {
|
|
97
|
+
/** Programmatic asset injector (from `@stagepass/modules`). */
|
|
98
|
+
inject?: StagepassInjectAPI;
|
|
99
|
+
/** Cookie helpers (from `@stagepass/modules`). */
|
|
100
|
+
cookies?: StagepassCookiesAPI;
|
|
101
|
+
/** Singular alias of `cookies`. */
|
|
102
|
+
cookie?: StagepassCookiesAPI;
|
|
103
|
+
/**
|
|
104
|
+
* Consent hook for categorized cookies.
|
|
105
|
+
* Documented as a tool, not legal compliance.
|
|
106
|
+
*/
|
|
107
|
+
consent?: StagepassConsentAPI;
|
|
108
|
+
/** Client-side maintenance overlay (not access protection). */
|
|
109
|
+
maintenance?: StagepassMaintenanceAPI;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stagepass/modules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Modular feature extensions for Stagepass",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/all.min.js",
|
|
7
|
+
"types": "global.d.ts",
|
|
7
8
|
"files": [
|
|
8
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"global.d.ts",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
9
13
|
],
|
|
10
14
|
"scripts": {
|
|
11
15
|
"build": "tsup",
|
|
12
16
|
"dev": "tsup --watch",
|
|
13
|
-
"test": "vitest run",
|
|
14
|
-
"test:watch": "vitest"
|
|
17
|
+
"test": "vitest run && npm run typecheck",
|
|
18
|
+
"test:watch": "vitest",
|
|
19
|
+
"typecheck": "tsc --noEmit -p fixtures/tsconfig.json"
|
|
15
20
|
},
|
|
16
21
|
"keywords": [
|
|
17
22
|
"stagepass",
|
|
@@ -26,11 +31,11 @@
|
|
|
26
31
|
},
|
|
27
32
|
"license": "MIT",
|
|
28
33
|
"peerDependencies": {
|
|
29
|
-
"@stagepass/loader": ">=
|
|
34
|
+
"@stagepass/loader": ">=2.0.0"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
32
37
|
"tsup": "^8.0.1",
|
|
33
38
|
"typescript": "^5.3.3",
|
|
34
|
-
"vitest": "^
|
|
39
|
+
"vitest": "^5.0.5"
|
|
35
40
|
}
|
|
36
41
|
}
|