@stagepass/modules 2.1.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 CHANGED
@@ -16,12 +16,12 @@ Without the loader, `inject` and `cookies` still attach their APIs and warn; `ma
16
16
 
17
17
  ## CDN Usage
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.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)).
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)).
20
20
 
21
21
  ```html
22
22
  <script
23
23
  src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js"
24
- data-stagepass-version="2.1.0"
24
+ data-stagepass-version="2.2.0"
25
25
  ></script>
26
26
  <script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/inject.min.js"></script>
27
27
  <script src="https://cdn.jsdelivr.net/npm/@stagepass/modules@2/dist/cookies.min.js"></script>
@@ -161,7 +161,20 @@ sp.maintenance.disable();
161
161
 
162
162
  ## Types
163
163
 
164
- `global.d.ts` extends `@stagepass/loader` via declaration merging (`inject`, `cookies` / `cookie`, `consent`, `maintenance`).
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`.
165
178
 
166
179
  ## Repository
167
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/global.d.ts CHANGED
@@ -1,113 +1,12 @@
1
1
  /**
2
- * Options for `stagepass.inject` / `sp.inject`.
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 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 {};
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
+ }
@@ -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.1.0",
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",