@stagepass/modules 2.0.0 → 2.2.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 +88 -31
- package/cookies.d.ts +70 -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 +10 -58
- package/inject.d.ts +62 -0
- package/maintenance.d.ts +24 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -7,33 +7,42 @@ This package provides optional browser modules that extend `@stagepass/loader`.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @stagepass/loader@2
|
|
10
|
+
npm install @stagepass/loader@2 @stagepass/modules@2
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
`@stagepass/loader`
|
|
13
|
+
`@stagepass/loader` should be loaded first.
|
|
14
|
+
Without the loader, `inject` and `cookies` still attach their APIs and warn; `maintenance` skips registration.
|
|
14
15
|
`@stagepass/modules` declares `@stagepass/loader` as a peer dependency (`>=2.0.0`).
|
|
15
16
|
|
|
16
17
|
## CDN Usage
|
|
17
18
|
|
|
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.2.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)).
|
|
19
20
|
|
|
20
21
|
```html
|
|
21
22
|
<script
|
|
22
|
-
src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2
|
|
23
|
-
data-stagepass-version="2.
|
|
23
|
+
src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js"
|
|
24
|
+
data-stagepass-version="2.2.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."
|
|
24
33
|
></script>
|
|
25
|
-
<script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2.0.0/dist/inject.min.js"></script>
|
|
26
|
-
<script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2.0.0/dist/cookies.min.js"></script>
|
|
27
34
|
```
|
|
28
35
|
|
|
29
36
|
Or load all modules:
|
|
30
37
|
|
|
31
38
|
```html
|
|
32
|
-
<script src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2
|
|
33
|
-
<script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2
|
|
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>
|
|
34
41
|
```
|
|
35
42
|
|
|
36
|
-
|
|
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`.
|
|
37
46
|
|
|
38
47
|
## Available Modules
|
|
39
48
|
|
|
@@ -48,21 +57,15 @@ await sp.inject({
|
|
|
48
57
|
localPath: 'lib.js', // alias: path
|
|
49
58
|
id: 'my-library',
|
|
50
59
|
type: 'script', // or 'style'; auto-detected from .css
|
|
51
|
-
version: '2.
|
|
60
|
+
version: '2.1.0', // production ?v=<version>
|
|
52
61
|
async: false, // default false (keeps order)
|
|
53
62
|
defer: true, // default true unless async is true
|
|
54
63
|
position: 'head', // 'head' | 'body-start' | 'body-end' | { target, action }
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{ src: 'https://cdn.example.com/b.css', stagepass: true, localPath: 'b.css', type: 'style', version: '2.0.0' },
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
await sp.inject({
|
|
64
|
-
scripts: [{ src: 'https://cdn.example.com/a.js', stagepass: true, localPath: 'a.js' }],
|
|
65
|
-
styles: [{ src: 'https://cdn.example.com/b.css', stagepass: true, localPath: 'b.css' }],
|
|
64
|
+
integrity: 'sha384-abc',
|
|
65
|
+
crossorigin: 'anonymous',
|
|
66
|
+
nonce: 'csp-nonce',
|
|
67
|
+
allowedHosts: ['cdn.example.com'],
|
|
68
|
+
attributes: { 'data-foo': 'bar' },
|
|
66
69
|
});
|
|
67
70
|
```
|
|
68
71
|
|
|
@@ -80,34 +83,49 @@ await sp.inject({
|
|
|
80
83
|
| `version` | Production cache bust: append `?v=<version>` (URL-encoded). |
|
|
81
84
|
| `cacheBust` | Deprecated; does **not** append per-view timestamps in v2 production. Prefer `version`. |
|
|
82
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. |
|
|
83
90
|
| `position` | `'head'` \| `'body-start'` \| `'body-end'` (default) \| `{ target: cssSelector, action: 'before' \| 'after' }`. |
|
|
84
91
|
|
|
85
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.
|
|
86
93
|
|
|
87
94
|
### Cookies (`cookies.min.js`)
|
|
88
95
|
|
|
89
|
-
Registers `sp.cookies`
|
|
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.
|
|
90
97
|
|
|
91
98
|
```js
|
|
92
99
|
sp.cookies.bake('token', 'abc123', { days: 7, path: '/' });
|
|
93
|
-
sp.
|
|
94
|
-
sp.cookies.has('token');
|
|
95
|
-
sp.cookies.list();
|
|
100
|
+
sp.cookie.eat('token'); // singular alias
|
|
101
|
+
sp.cookies.has('token'); // true
|
|
102
|
+
sp.cookies.list(); // { token: 'abc123', ... }
|
|
96
103
|
sp.cookies.throw('token', { path: '/' });
|
|
97
104
|
|
|
98
|
-
sp.cookies.bake('
|
|
99
|
-
sp.cookies.
|
|
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
|
|
100
115
|
```
|
|
101
116
|
|
|
102
117
|
| Method | Description |
|
|
103
118
|
| :--- | :--- |
|
|
104
|
-
| `bake(name, value, options?)` | Write/update a cookie. |
|
|
119
|
+
| `bake(name, value, options?)` | Write/update a cookie. Optional `category` remembers the category and may queue when consent rejects. |
|
|
105
120
|
| `eat(name, options?)` | Read a cookie; `null` if missing. |
|
|
106
121
|
| `throw(name, options?)` | Delete via `Max-Age=0` + expired date. |
|
|
107
122
|
| `has(name)` | Existence check. |
|
|
108
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`. |
|
|
109
127
|
|
|
110
|
-
**`bake` options:** `days?`, `maxAge?` (seconds), `path?` (default `/`), `domain?`, `secure?` (default `true` on HTTPS), `sameSite?` (`'Lax'` \| `'Strict'` \| `'None'`, default `'Lax'`), `encode?` (default `true`), `json?`.
|
|
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?`.
|
|
111
129
|
|
|
112
130
|
**`eat` / `list` options:** `decode?` (default `true`), `json?`.
|
|
113
131
|
|
|
@@ -115,9 +133,48 @@ sp.cookies.eat('profile', { json: true });
|
|
|
115
133
|
|
|
116
134
|
Notes: `HttpOnly` cookies are invisible to JS; use the same `path`/`domain` to delete; `sameSite: 'None'` forces `Secure=true`.
|
|
117
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
|
+
|
|
118
162
|
## Types
|
|
119
163
|
|
|
120
|
-
|
|
164
|
+
The modules extend `@stagepass/loader` via declaration merging. Use one entry per module your site actually loads, so an AI assistant or teammate cannot call a module that is not there:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{ "compilerOptions": { "types": ["@stagepass/loader", "@stagepass/modules/cookies"] } }
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
| Entry | Adds |
|
|
171
|
+
| :--- | :--- |
|
|
172
|
+
| `@stagepass/modules/inject` | `sp.inject` |
|
|
173
|
+
| `@stagepass/modules/cookies` | `sp.cookies` / `sp.cookie`, `sp.consent` |
|
|
174
|
+
| `@stagepass/modules/maintenance` | `sp.maintenance` |
|
|
175
|
+
| `@stagepass/modules` | all of the above (unchanged since 2.0) |
|
|
176
|
+
|
|
177
|
+
Module members are optional (`sp.cookies?`), because a page may not load the file; guard calls (`if (sp.cookies) …`). `stagepass new` / `stagepass upgrade` set these entries from `stagepass.json` `modules`.
|
|
121
178
|
|
|
122
179
|
## Repository
|
|
123
180
|
|
package/cookies.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Stagepass `cookies` module (`@stagepass/modules/dist/cookies.min.js`).
|
|
3
|
+
*
|
|
4
|
+
* Enable per project in tsconfig/jsconfig: `"types": ["@stagepass/loader", "@stagepass/modules/cookies"]`.
|
|
5
|
+
* Only list modules whose script tag is actually on the Webflow site.
|
|
6
|
+
*/
|
|
7
|
+
import '@stagepass/loader';
|
|
8
|
+
|
|
9
|
+
export interface StagepassCookieWriteOptions {
|
|
10
|
+
days?: number;
|
|
11
|
+
maxAge?: number;
|
|
12
|
+
path?: string;
|
|
13
|
+
domain?: string;
|
|
14
|
+
secure?: boolean;
|
|
15
|
+
sameSite?: 'Lax' | 'Strict' | 'None';
|
|
16
|
+
encode?: boolean;
|
|
17
|
+
json?: boolean;
|
|
18
|
+
/** Optional category for consent gating / throwAll filtering. */
|
|
19
|
+
category?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface StagepassCookiesAPI {
|
|
23
|
+
/** Write a cookie. */
|
|
24
|
+
bake: (name: string, value: unknown, options?: StagepassCookieWriteOptions) => void;
|
|
25
|
+
/** Read a cookie. */
|
|
26
|
+
eat: (name: string, options?: Record<string, unknown>) => unknown;
|
|
27
|
+
/** Delete a cookie. */
|
|
28
|
+
throw: (name: string, options?: Record<string, unknown>) => void;
|
|
29
|
+
/** Whether a cookie exists. */
|
|
30
|
+
has: (name: string) => boolean;
|
|
31
|
+
/** List cookies as a name → value map. */
|
|
32
|
+
list: (options?: Record<string, unknown>) => Record<string, unknown>;
|
|
33
|
+
/** Delete known cookies, optionally by category. */
|
|
34
|
+
throwAll: (options?: { category?: string }) => void;
|
|
35
|
+
/** Shallow copy of cookies known to this helper. */
|
|
36
|
+
jar: () => Record<string, unknown>;
|
|
37
|
+
/** Known cookie names starting with `prefix`. */
|
|
38
|
+
crumbs: (prefix: string) => string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tiny consent hook used by categorized `bake`.
|
|
43
|
+
* Tooling helper only: not a legal compliance solution.
|
|
44
|
+
*/
|
|
45
|
+
export interface StagepassConsentAPI {
|
|
46
|
+
allows: (category: string) => boolean;
|
|
47
|
+
set: (fn: (category: string) => boolean) => void;
|
|
48
|
+
/** Flush queued cookies against the current consent function. */
|
|
49
|
+
update: () => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare module '@stagepass/loader' {
|
|
53
|
+
interface StagepassAPI {
|
|
54
|
+
/**
|
|
55
|
+
* Cookie helpers (`cookies` module).
|
|
56
|
+
* @example
|
|
57
|
+
* if (sp.cookies) sp.cookies.bake('visited', '1', { days: 30 });
|
|
58
|
+
*/
|
|
59
|
+
cookies?: StagepassCookiesAPI;
|
|
60
|
+
/** Singular alias of `cookies` (`cookies` module). */
|
|
61
|
+
cookie?: StagepassCookiesAPI;
|
|
62
|
+
/**
|
|
63
|
+
* Consent hook for categorized cookies (`cookies` module).
|
|
64
|
+
* Documented as a tool, not legal compliance.
|
|
65
|
+
* @example
|
|
66
|
+
* if (sp.consent) { sp.consent.set((c) => c === 'necessary'); sp.consent.update(); }
|
|
67
|
+
*/
|
|
68
|
+
consent?: StagepassConsentAPI;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/dist/all.min.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
"use strict";var StagepassModules=(()=>{(function(){function u(){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 p(e){let n=u();(n.env==="local"||n.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 i=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return i?i[1]:"file"}let s=t.split("/");return s[s.length-1]||s[s.length-2]||"file"}catch{try{let t=e.match(/\/([^\/\?#]+)(?:\?|#|$)/);return t?t[1]:"file"}catch{return"file"}}}function b(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 m(e,n,t){let s=encodeURIComponent(t),i=e.indexOf("#"),d=i>=0?e.slice(i):"",l=i>=0?e.slice(0,i):e,a=l.includes("?")?"&":"?";return`${l}${a}${encodeURIComponent(n)}=${s}${d}`}function w(e){let n=u(),{src:t,stagepass:s,localPath:i,path:d,version:l}=e;if(!t||typeof t!="string")throw new Error("Invalid src: must be a non-empty string");if(s!==!1&&n.isLocal){let a=i||d||g(t);if(!a||typeof a!="string")return t;let o=a.startsWith("/")?a.substring(1):a,c=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(c&&typeof c.resolveLocalUrl=="function"){let f=c.resolveLocalUrl(o);if(f)return f}return`https://${n.domain}/${o}?_cb=${n.timestamp}`}return l?m(t,"v",l):t}function S(e,n){let{id:t,type:s}=e,i=b(e.src,s);if(t&&document.getElementById(t))return p(`Skipping injection: Element with id "${t}" already exists`),!0;let d=i==="script"?`script[src="${n}"]`:`link[href="${n}"]`;return document.querySelector(d)?(p(`Skipping injection: Resource "${n}" already loaded`),!0):!1}function j(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:t}=e,s=document.querySelector(n);return s?t==="before"?s:s.nextSibling||s.parentNode:(p(`Warning: Target selector "${n}" not found, falling back to body-end`),document.body)}function I(e){return new Promise((n,t)=>{if(!e.src){let o=u(),c=new Error('InjectOptions must have a "src" property');o.env!=="production"&&console.error("[Stagepass]",c),t(c);return}let s=u(),i=b(e.src,e.type),d=w(e);if(S(e,d)){n();return}let l=i==="script"?document.createElement("script"):document.createElement("link");if(i==="script"){let o=l;o.src=d,e.async?o.async=!0:(o.async=!1,e.defer!==!1&&(o.defer=!0)),e.id&&(o.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([c,f])=>{o.setAttribute(c,f)}),o.onload=()=>{p(`Injected: ${d}`),n()},o.onerror=()=>{let c=new Error(`Failed to load script: ${d}`);s.env!=="production"&&console.error("[Stagepass]",c),t(c)}}else{let o=l;o.rel="stylesheet",o.href=d,e.id&&(o.id=e.id),e.attributes&&Object.entries(e.attributes).forEach(([f,h])=>{o.setAttribute(f,h)});let c=setInterval(()=>{(o.sheet||o.styleSheet)&&(clearInterval(c),p(`Injected: ${d}`),n())},10);setTimeout(()=>{if(clearInterval(c),!(o.sheet||o.styleSheet)){let h=new Error(`Failed to load stylesheet: ${d}`);s.env!=="production"&&console.error("[Stagepass]",h),t(h)}},5e3)}let a=j(e.position);if(!a){t(new Error("Could not find insertion point"));return}if(a===document.head||a===document.body)a.appendChild(l);else{let o=a.parentNode;o&&(typeof e.position=="object"&&e.position.action==="before"?o.insertBefore(l,a):o.insertBefore(l,a.nextSibling))}})}async function y(e){let n=[];if(!Array.isArray(e)&&typeof e=="object"&&("scripts"in e||"styles"in e)){let t=e;t.scripts&&n.push(...t.scripts.filter(s=>s&&typeof s=="object"&&"src"in s&&typeof s.src=="string"&&s.src.trim().length>0).map(s=>({...s,type:"script"}))),t.styles&&n.push(...t.styles.filter(s=>s&&typeof s=="object"&&"src"in s&&typeof s.src=="string"&&s.src.trim().length>0).map(s=>({...s,type:"style"})))}else Array.isArray(e)?n=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&&(n=[e]);for(let t of n)try{await I(t)}catch(s){u().env!=="production"&&console.error("[Stagepass] Injection error:",s)}}let r=window.stagepass=window.stagepass||{};r.inject=y,globalThis.stagepass=r,window.sp=r,globalThis.sp=r})();(function(){function u(){let r=window.stagepass||globalThis.stagepass||window.sp||globalThis.sp;if(!r||!r.vars)throw new Error("Stagepass core loader must be loaded before modules");return r}function p(){return window.location.protocol==="https:"}function g(r){try{return decodeURIComponent(r)}catch{return r}}function b(r,e){let t=e.decode!==!1?g(r):r;if(!e.json)return t;try{return JSON.parse(t)}catch{return t}}function m(r,e,n={}){let t=u();if(!r||typeof r!="string"||r.includes(";"))throw new Error("Invalid cookie name");let s=n.encode!==!1,i=n.sameSite||"Lax",d=n.secure!==void 0?n.secure:p(),l=n.path||"/",a=n.json?JSON.stringify(e):String(e),o=s?encodeURIComponent(r):r;a=s?encodeURIComponent(a):a;let c=[`${o}=${a}`];if(typeof n.maxAge=="number"&&c.push(`Max-Age=${Math.floor(n.maxAge)}`),typeof n.days=="number"){let h=new Date(Date.now()+n.days*24*60*60*1e3);c.push(`Expires=${h.toUTCString()}`)}l&&c.push(`Path=${l}`),n.domain&&c.push(`Domain=${n.domain}`),c.push(`SameSite=${i}`);let f=d;i==="None"&&!f&&(f=!0,typeof t.warn=="function"&&t.warn("SameSite=None requires Secure=true. Enforcing Secure for cookie write.")),f&&c.push("Secure"),document.cookie=c.join("; ")}function w(r,e={}){if(!r||typeof r!="string")return null;let n=e.decode===!1?r:g(r),t=document.cookie?document.cookie.split("; "):[];for(let s of t){let i=s.indexOf("=");if(i<0)continue;let d=s.substring(0,i),l=s.substring(i+1),a=g(d);if(d===n||a===n)return b(l,e)}return null}function S(r){return w(r)!==null}function j(r={}){let e=document.cookie?document.cookie.split("; "):[],n={};for(let t of e){let s=t.indexOf("=");if(s<0)continue;let i=t.substring(0,s),d=t.substring(s+1),l=r.decode===!1?i:g(i);n[l]=b(d,r)}return n}function I(r,e={}){m(r,"",{days:-1,maxAge:0,path:e.path||"/",domain:e.domain,secure:e.secure,sameSite:e.sameSite})}let y=window.stagepass=window.stagepass||{};y.cookies={bake:m,eat:w,throw:I,has:S,list:j},globalThis.stagepass=y,window.sp=y,globalThis.sp=y})();})();
|
|
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
CHANGED
|
@@ -1,60 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Types for all Stagepass modules (`@stagepass/modules`, `dist/all.min.js`).
|
|
3
|
+
*
|
|
4
|
+
* Backward compatible entry: re-exports every module type and augments
|
|
5
|
+
* `StagepassAPI` with `inject`, `cookies`, `cookie`, `consent`, `maintenance`.
|
|
6
|
+
* For projects that load only some modules, use the per-module entries
|
|
7
|
+
* instead: `@stagepass/modules/inject`, `@stagepass/modules/cookies`,
|
|
8
|
+
* `@stagepass/modules/maintenance`.
|
|
3
9
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface StagepassInjectBatchOptions {
|
|
26
|
-
scripts?: StagepassInjectOptions[];
|
|
27
|
-
styles?: StagepassInjectOptions[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface StagepassCookiesAPI {
|
|
31
|
-
/** Write a cookie. */
|
|
32
|
-
bake: (name: string, value: unknown, options?: Record<string, unknown>) => void;
|
|
33
|
-
/** Read a cookie. */
|
|
34
|
-
eat: (name: string, options?: Record<string, unknown>) => unknown;
|
|
35
|
-
/** Delete a cookie. */
|
|
36
|
-
throw: (name: string, options?: Record<string, unknown>) => void;
|
|
37
|
-
/** Whether a cookie exists. */
|
|
38
|
-
has: (name: string) => boolean;
|
|
39
|
-
/** List cookies as a name → value map. */
|
|
40
|
-
list: (options?: Record<string, unknown>) => Record<string, unknown>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type StagepassInjectAPI = (
|
|
44
|
-
options:
|
|
45
|
-
| StagepassInjectOptions
|
|
46
|
-
| StagepassInjectOptions[]
|
|
47
|
-
| StagepassInjectBatchOptions
|
|
48
|
-
) => Promise<void>;
|
|
49
|
-
|
|
50
|
-
/** Declaration merging: extend loader StagepassAPI with modules. */
|
|
51
|
-
declare module '@stagepass/loader' {
|
|
52
|
-
interface StagepassAPI {
|
|
53
|
-
/** Programmatic asset injector (from `@stagepass/modules`). */
|
|
54
|
-
inject?: StagepassInjectAPI;
|
|
55
|
-
/** Cookie helpers (from `@stagepass/modules`). */
|
|
56
|
-
cookies?: StagepassCookiesAPI;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export {};
|
|
10
|
+
export * from './inject';
|
|
11
|
+
export * from './cookies';
|
|
12
|
+
export * from './maintenance';
|
package/inject.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Stagepass `inject` module (`@stagepass/modules/dist/inject.min.js`).
|
|
3
|
+
*
|
|
4
|
+
* Enable per project in tsconfig/jsconfig: `"types": ["@stagepass/loader", "@stagepass/modules/inject"]`.
|
|
5
|
+
* Only list modules whose script tag is actually on the Webflow site.
|
|
6
|
+
*/
|
|
7
|
+
import '@stagepass/loader';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for `stagepass.inject` / `sp.inject`.
|
|
11
|
+
*/
|
|
12
|
+
export interface StagepassInjectOptions {
|
|
13
|
+
src: string;
|
|
14
|
+
type?: 'script' | 'style';
|
|
15
|
+
stagepass?: boolean;
|
|
16
|
+
localPath?: string;
|
|
17
|
+
path?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
async?: boolean;
|
|
20
|
+
defer?: boolean;
|
|
21
|
+
/** @deprecated No longer appends per-view timestamps in production. Use `version`. */
|
|
22
|
+
cacheBust?: boolean;
|
|
23
|
+
/** Production version token appended as `?v=`. */
|
|
24
|
+
version?: string;
|
|
25
|
+
attributes?: Record<string, string>;
|
|
26
|
+
position?:
|
|
27
|
+
| 'head'
|
|
28
|
+
| 'body-start'
|
|
29
|
+
| 'body-end'
|
|
30
|
+
| { target: string; action: 'before' | 'after' };
|
|
31
|
+
/** Subresource Integrity hash. */
|
|
32
|
+
integrity?: string;
|
|
33
|
+
/** CORS mode (`anonymous` / `use-credentials`). */
|
|
34
|
+
crossorigin?: string;
|
|
35
|
+
/** CSP nonce. */
|
|
36
|
+
nonce?: string;
|
|
37
|
+
/** Reject src hosts outside this list (warn + skip). */
|
|
38
|
+
allowedHosts?: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface StagepassInjectBatchOptions {
|
|
42
|
+
scripts?: StagepassInjectOptions[];
|
|
43
|
+
styles?: StagepassInjectOptions[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type StagepassInjectAPI = (
|
|
47
|
+
options:
|
|
48
|
+
| StagepassInjectOptions
|
|
49
|
+
| StagepassInjectOptions[]
|
|
50
|
+
| StagepassInjectBatchOptions
|
|
51
|
+
) => Promise<void>;
|
|
52
|
+
|
|
53
|
+
declare module '@stagepass/loader' {
|
|
54
|
+
interface StagepassAPI {
|
|
55
|
+
/**
|
|
56
|
+
* Programmatic asset injector (`inject` module).
|
|
57
|
+
* @example
|
|
58
|
+
* if (sp.inject) await sp.inject({ src: 'https://cdn.example.com/lib.js', defer: true });
|
|
59
|
+
*/
|
|
60
|
+
inject?: StagepassInjectAPI;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/maintenance.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Stagepass `maintenance` module (`@stagepass/modules/dist/maintenance.min.js`).
|
|
3
|
+
*
|
|
4
|
+
* Enable per project in tsconfig/jsconfig: `"types": ["@stagepass/loader", "@stagepass/modules/maintenance"]`.
|
|
5
|
+
* Only list modules whose script tag is actually on the Webflow site.
|
|
6
|
+
*/
|
|
7
|
+
import '@stagepass/loader';
|
|
8
|
+
|
|
9
|
+
export interface StagepassMaintenanceAPI {
|
|
10
|
+
enable: (opts?: { title?: string; text?: string }) => void;
|
|
11
|
+
disable: () => void;
|
|
12
|
+
isActive: () => boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module '@stagepass/loader' {
|
|
16
|
+
interface StagepassAPI {
|
|
17
|
+
/**
|
|
18
|
+
* Client-side maintenance overlay (`maintenance` module). Not access protection.
|
|
19
|
+
* @example
|
|
20
|
+
* if (sp.maintenance && !sp.maintenance.isActive()) sp.maintenance.enable({ title: 'Back soon' });
|
|
21
|
+
*/
|
|
22
|
+
maintenance?: StagepassMaintenanceAPI;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stagepass/modules",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Modular feature extensions for Stagepass",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/all.min.js",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"global.d.ts",
|
|
11
|
+
"inject.d.ts",
|
|
12
|
+
"cookies.d.ts",
|
|
13
|
+
"maintenance.d.ts",
|
|
11
14
|
"README.md",
|
|
12
15
|
"LICENSE"
|
|
13
16
|
],
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
"dev": "tsup --watch",
|
|
17
20
|
"test": "vitest run && npm run typecheck",
|
|
18
21
|
"test:watch": "vitest",
|
|
19
|
-
"typecheck": "tsc --noEmit -p fixtures/tsconfig.json"
|
|
22
|
+
"typecheck": "tsc --noEmit -p fixtures/tsconfig.json && tsc --noEmit -p fixtures/tsconfig.cookies.json && tsc --noEmit -p fixtures/tsconfig.none.json"
|
|
20
23
|
},
|
|
21
24
|
"keywords": [
|
|
22
25
|
"stagepass",
|