@justflows/sdk 0.0.0-stage → 1.2.1
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 +95 -2
- package/dist/api-urls.d.ts +4 -0
- package/dist/api-urls.d.ts.map +1 -0
- package/dist/api-urls.js +22 -0
- package/dist/api-urls.js.map +1 -0
- package/dist/cache.d.ts +63 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +28 -0
- package/dist/cache.js.map +1 -0
- package/dist/capabilities.d.ts +73 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +118 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/compatibility.d.ts +7 -0
- package/dist/compatibility.d.ts.map +1 -0
- package/dist/compatibility.js +7 -0
- package/dist/compatibility.js.map +1 -0
- package/dist/cookies.d.ts +60 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +60 -0
- package/dist/cookies.js.map +1 -0
- package/dist/hooks.d.ts +1393 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +102 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/license.d.ts +26 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +90 -0
- package/dist/license.js.map +1 -0
- package/dist/media-html.d.ts +85 -0
- package/dist/media-html.d.ts.map +1 -0
- package/dist/media-html.js +181 -0
- package/dist/media-html.js.map +1 -0
- package/dist/patterns.d.ts +72 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +86 -0
- package/dist/patterns.js.map +1 -0
- package/dist/placeholders.d.ts +64 -0
- package/dist/placeholders.d.ts.map +1 -0
- package/dist/placeholders.js +38 -0
- package/dist/placeholders.js.map +1 -0
- package/dist/plugin.d.ts +2424 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +724 -0
- package/dist/plugin.js.map +1 -0
- package/dist/publisher-namespace.d.ts +49 -0
- package/dist/publisher-namespace.d.ts.map +1 -0
- package/dist/publisher-namespace.js +106 -0
- package/dist/publisher-namespace.js.map +1 -0
- package/dist/registry.d.ts +64 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +132 -0
- package/dist/registry.js.map +1 -0
- package/dist/search.d.ts +25 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +2 -0
- package/dist/search.js.map +1 -0
- package/dist/spam.d.ts +30 -0
- package/dist/spam.d.ts.map +1 -0
- package/dist/spam.js +3 -0
- package/dist/spam.js.map +1 -0
- package/dist/templates.d.ts +37 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +52 -0
- package/dist/templates.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/visibility.d.ts +79 -0
- package/dist/visibility.d.ts.map +1 -0
- package/dist/visibility.js +3 -0
- package/dist/visibility.js.map +1 -0
- package/package.json +46 -4
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @justflows/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The public API for [Justflows](https://github.com/JustFlows/justflows-ce)
|
|
4
|
+
plugins and themes: TypeScript types for the plugin context, hooks and
|
|
5
|
+
manifest, the schemas the host validates packages with, and a few small
|
|
6
|
+
runtime helpers.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install --save-dev @justflows/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Declare the SDK as a peer dependency too, at the lowest version whose features
|
|
15
|
+
you use:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"peerDependencies": { "@justflows/sdk": "^1.2.0" },
|
|
20
|
+
"devDependencies": { "@justflows/sdk": "^1.2.0" }
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The Justflows host provides the plugin runtime, so the SDK is what you build
|
|
25
|
+
against, not something you ship.
|
|
26
|
+
|
|
27
|
+
## A minimal plugin
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import type { PluginModule } from "@justflows/sdk";
|
|
31
|
+
|
|
32
|
+
const plugin: PluginModule = {
|
|
33
|
+
manifest: {
|
|
34
|
+
id: "acme.hello",
|
|
35
|
+
name: "Hello",
|
|
36
|
+
version: "1.0.0",
|
|
37
|
+
license: "GPL-2.0-or-later",
|
|
38
|
+
engines: { justflows: ">=1.1.0 <2.0.0" },
|
|
39
|
+
permissions: [],
|
|
40
|
+
main: "index.js",
|
|
41
|
+
},
|
|
42
|
+
activate(ctx) {
|
|
43
|
+
ctx.hooks.action("content.published", (event) => {
|
|
44
|
+
ctx.logger.info("published", { contentId: event.contentId });
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async deleteData(ctx) {
|
|
48
|
+
await ctx.data.clear();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default plugin;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`activate` receives a `PluginContext`: hooks, settings, plugin-scoped data and
|
|
56
|
+
secrets, HTTP routes, cache, mail, users and more, each behind the permissions
|
|
57
|
+
your manifest asks for.
|
|
58
|
+
|
|
59
|
+
## What is in it
|
|
60
|
+
|
|
61
|
+
- **Plugin contract:** `PluginModule`, `PluginContext`, `PluginManifestSchema`
|
|
62
|
+
and the permission names.
|
|
63
|
+
- **Hooks:** typed actions, gates and filters (`ActionEventMap`,
|
|
64
|
+
`FilterValueMap`, `GateEventMap`).
|
|
65
|
+
- **Package manifests:** `ExtensionEnginesSchema` for `engines.justflows`, plus
|
|
66
|
+
the theme template and pattern schemas.
|
|
67
|
+
- **Helpers:** `renderResponsiveImage` and `escapeHtml` for block output, and
|
|
68
|
+
`pluginApiUrl` to build your plugin's API URLs in the browser.
|
|
69
|
+
- **Versions:** `SDK_VERSION` and `SDK_API_VERSION`. At runtime, read
|
|
70
|
+
`ctx.runtime.sdk` and `ctx.runtime.justflows` for the host's versions.
|
|
71
|
+
|
|
72
|
+
## Versions
|
|
73
|
+
|
|
74
|
+
The SDK follows Semantic Versioning: minor releases only add, and breaking
|
|
75
|
+
changes wait for a major release after a deprecation period. Each release is
|
|
76
|
+
built and published from the Justflows repository by GitHub Actions, with npm
|
|
77
|
+
provenance.
|
|
78
|
+
|
|
79
|
+
| SDK | Justflows |
|
|
80
|
+
| ----- | ----------------------- |
|
|
81
|
+
| 1.2.x | the release after 1.1.0 |
|
|
82
|
+
| 1.0.x | 1.0.0 and 1.1.0 |
|
|
83
|
+
|
|
84
|
+
## Documentation
|
|
85
|
+
|
|
86
|
+
- [Plugin guide](https://github.com/JustFlows/justflows-ce/blob/main/docs/PLUGINS.md)
|
|
87
|
+
- [SDK compatibility and deprecation policy](https://github.com/JustFlows/justflows-ce/blob/main/docs/SDK-COMPATIBILITY.md)
|
|
88
|
+
- [Hooks](https://github.com/JustFlows/justflows-ce/blob/main/docs/HOOKS.md)
|
|
89
|
+
- [Themes](https://github.com/JustFlows/justflows-ce/blob/main/docs/THEMES.md)
|
|
90
|
+
|
|
91
|
+
For a plugin's admin screens, see
|
|
92
|
+
[`@justflows/admin-bridge`](https://www.npmjs.com/package/@justflows/admin-bridge).
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isValidPluginApiNamespace(namespace: string): boolean;
|
|
2
|
+
/** Build a neutral API URL. Paths are relative; query/hash suffixes are preserved. */
|
|
3
|
+
export declare function pluginApiUrl(namespace: string, path?: string): string;
|
|
4
|
+
//# sourceMappingURL=api-urls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-urls.d.ts","sourceRoot":"","sources":["../src/api-urls.ts"],"names":[],"mappings":"AAKA,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,MAAM,CAUjE"}
|
package/dist/api-urls.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/** Core owns these API namespaces; plugins cannot shadow them. */
|
|
3
|
+
const RESERVED = new Set("account ai api-keys audit auth backups blocks cache cdn comment-rules comment-spam-terms comments content content-types content-visibility cookies css-providers custom-code dashboard db diagnostics document-history domains emails error-pages headers health healthz i18n import install languages mail manage marketplace mcp media menus oauth patterns performance platform platform-account plugins preferences privacy-requests redirects reusable-blocks roles search security settings signup site static-export storage style-presets taxonomies template-parts templates themes trash updates users v1 webhooks widgets".split(" "));
|
|
4
|
+
export function isValidPluginApiNamespace(namespace) {
|
|
5
|
+
return /^[a-z][a-z0-9-]{0,39}$/.test(namespace) && !RESERVED.has(namespace);
|
|
6
|
+
}
|
|
7
|
+
/** Build a neutral API URL. Paths are relative; query/hash suffixes are preserved. */
|
|
8
|
+
export function pluginApiUrl(namespace, path = "") {
|
|
9
|
+
if (!isValidPluginApiNamespace(namespace))
|
|
10
|
+
throw new Error("Invalid or reserved plugin API namespace");
|
|
11
|
+
// eslint-disable-next-line no-control-regex -- control characters are exactly what this refuses
|
|
12
|
+
if (path.startsWith("/") || /[\\\s\x00-\x1f]/.test(path))
|
|
13
|
+
throw new Error("Plugin API paths must be relative");
|
|
14
|
+
const pathname = path.split(/[?#]/, 1)[0] ?? "";
|
|
15
|
+
for (const part of pathname.split("/")) {
|
|
16
|
+
const decoded = decodeURIComponent(part);
|
|
17
|
+
if (decoded === "." || decoded === ".." || /[\\/]/.test(decoded))
|
|
18
|
+
throw new Error("Invalid plugin API path segment");
|
|
19
|
+
}
|
|
20
|
+
return `/api/${namespace}${path ? `/${path}` : ""}`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IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACtD,CAAC"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when `key` is removed by `invalidate(prefix)`. A site-scoped prefix
|
|
3
|
+
* (`s:<siteId>:page:html:`) matches only that site. A logical prefix
|
|
4
|
+
* (`page:html:`) also matches the same tail inside every site
|
|
5
|
+
* (`s:<siteId>:page:html:…`). A cache store's `invalidate` must follow this.
|
|
6
|
+
*/
|
|
7
|
+
export declare function cacheKeyMatchesPrefix(key: string, prefix: string): boolean;
|
|
8
|
+
/** True for a prefix that already names one site (`s:<siteId>:…`). */
|
|
9
|
+
export declare function isSiteScopedCacheKey(key: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Where a store stands, shown in Admin → Tools and Site Health.
|
|
12
|
+
* `ready`: serving. `connecting`: starting or reconnecting.
|
|
13
|
+
* `unavailable`: cannot serve; the host bypasses the cache meanwhile.
|
|
14
|
+
*/
|
|
15
|
+
export interface CacheStoreStatus {
|
|
16
|
+
state: "ready" | "connecting" | "unavailable";
|
|
17
|
+
/** Short operator-facing reason. Never include credentials. */
|
|
18
|
+
detail?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A running cache store. Keys and values come from the host: keys are
|
|
22
|
+
* strings, values are JSON-serializable. A failing call should reject; the
|
|
23
|
+
* host turns a failed read into a miss and a failed write into a skip, and
|
|
24
|
+
* after a failed `delete`, `invalidate`, or `clear` it bypasses the store
|
|
25
|
+
* until a full `clear()` succeeds, so no process serves an entry whose
|
|
26
|
+
* invalidation was lost.
|
|
27
|
+
*/
|
|
28
|
+
export interface CacheStore {
|
|
29
|
+
get(key: string): Promise<unknown>;
|
|
30
|
+
/** `ttlSeconds` of 0 or less means no expiry. */
|
|
31
|
+
set(key: string, value: unknown, ttlSeconds: number): Promise<void>;
|
|
32
|
+
delete(key: string): Promise<void>;
|
|
33
|
+
/** Remove every key `cacheKeyMatchesPrefix(key, prefix)` accepts. */
|
|
34
|
+
invalidate(prefix: string): Promise<void>;
|
|
35
|
+
/** Remove every key this store holds for the installation, nothing else. */
|
|
36
|
+
clear(): Promise<void>;
|
|
37
|
+
has(key: string): Promise<boolean>;
|
|
38
|
+
status(): CacheStoreStatus;
|
|
39
|
+
/** Key count and a few sample keys for Admin → Tools. Optional and may be approximate. */
|
|
40
|
+
stats?(): Promise<{
|
|
41
|
+
keyCount: number;
|
|
42
|
+
sampleKeys: string[];
|
|
43
|
+
}>;
|
|
44
|
+
/** Release connections. Called when the store is deselected or its plugin deactivates. */
|
|
45
|
+
close?(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/** What `ctx.cache.registerStore` takes. */
|
|
48
|
+
export interface CacheStoreDefinition {
|
|
49
|
+
/** Lowercase kebab-case, unique within the plugin. */
|
|
50
|
+
id: string;
|
|
51
|
+
/** Shown in the Admin → Tools cache driver list. */
|
|
52
|
+
label: string;
|
|
53
|
+
/**
|
|
54
|
+
* Build the store. The host calls this only when the operator selected it
|
|
55
|
+
* as the cache driver, so an unselected store opens no connections. Throw
|
|
56
|
+
* when it cannot be configured; the host then bypasses the cache and shows
|
|
57
|
+
* the message.
|
|
58
|
+
*/
|
|
59
|
+
create(options: {
|
|
60
|
+
defaultTtlSeconds: number;
|
|
61
|
+
}): CacheStore;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAM1E;AAED,sEAAsE;AACtE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KA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
3
|
+
* Cache stores: a plugin can back the shared jf-cache with an external
|
|
4
|
+
* service, so several application processes share cache entries and
|
|
5
|
+
* invalidations. Available from SDK 0.1.9. See `docs/CACHE.md`.
|
|
6
|
+
*/
|
|
7
|
+
const SCOPED_KEY = /^s:([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}):(.*)$/i;
|
|
8
|
+
/**
|
|
9
|
+
* True when `key` is removed by `invalidate(prefix)`. A site-scoped prefix
|
|
10
|
+
* (`s:<siteId>:page:html:`) matches only that site. A logical prefix
|
|
11
|
+
* (`page:html:`) also matches the same tail inside every site
|
|
12
|
+
* (`s:<siteId>:page:html:…`). A cache store's `invalidate` must follow this.
|
|
13
|
+
*/
|
|
14
|
+
export function cacheKeyMatchesPrefix(key, prefix) {
|
|
15
|
+
if (key.startsWith(prefix))
|
|
16
|
+
return true;
|
|
17
|
+
const match = SCOPED_KEY.exec(key);
|
|
18
|
+
if (!match)
|
|
19
|
+
return false;
|
|
20
|
+
if (SCOPED_KEY.test(prefix))
|
|
21
|
+
return false;
|
|
22
|
+
return (match[2] ?? "").startsWith(prefix);
|
|
23
|
+
}
|
|
24
|
+
/** True for a prefix that already names one site (`s:<siteId>:…`). */
|
|
25
|
+
export function isSiteScopedCacheKey(key) {
|
|
26
|
+
return SCOPED_KEY.test(key);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;;GAIG;AAEH,MAAM,UAAU,GAAG,0EAA0E,CAAC;AAE9F;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW,EAAE,MAAc;IAC/D,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User capability definitions — stable public API.
|
|
3
|
+
* Code should always check capabilities, never role names directly.
|
|
4
|
+
*/
|
|
5
|
+
export declare const USER_CAPABILITIES: readonly ["content:read", "content:create", "content:update", "content:delete", "content:publish", "content:revisions:read", "content:revisions:restore", "content:revisions:discard",
|
|
6
|
+
/** Lock and unlock blocks; without it, locked blocks cannot be moved, removed, or edited (justflows-ce#298). */
|
|
7
|
+
"content:locks:manage", "media:read", "media:upload", "media:delete", "comments:moderate",
|
|
8
|
+
/**
|
|
9
|
+
* Read and change comment block/allow rules, spam-signal terms, and the
|
|
10
|
+
* spam-policy thresholds (justflows-ce#143). Administrators only: moderating
|
|
11
|
+
* a comment does not include changing why comments are held.
|
|
12
|
+
*/
|
|
13
|
+
"comments:rules:manage", "users:read", "users:manage", "plugins:read", "plugins:install", "plugins:activate", "plugins:delete", "themes:read", "themes:install", "themes:activate", "themes:delete", "settings:read", "settings:manage", "mail:read", "mail:manage", "email-templates:read", "email-templates:manage",
|
|
14
|
+
/**
|
|
15
|
+
* Read site design: templates, template parts, the header library, widget
|
|
16
|
+
* areas, menus, patterns, reusable blocks, style presets and global styles
|
|
17
|
+
* (justflows-ce#314).
|
|
18
|
+
*/
|
|
19
|
+
"design:read",
|
|
20
|
+
/** Change and publish site design (justflows-ce#314). */
|
|
21
|
+
"design:manage", "updates:manage",
|
|
22
|
+
/**
|
|
23
|
+
* Add, change, and switch off custom JavaScript and markup on public pages
|
|
24
|
+
* (justflows-ce#94). Administrators only by default; not part of any other
|
|
25
|
+
* built-in role, because custom code runs in every visitor's browser.
|
|
26
|
+
*/
|
|
27
|
+
"code:manage", "site:admin", "ai:use"];
|
|
28
|
+
export type CoreUserCapability = (typeof USER_CAPABILITIES)[number];
|
|
29
|
+
/** Core capability or a validated capability registered by an active plugin. */
|
|
30
|
+
export type UserCapability = CoreUserCapability | (string & {});
|
|
31
|
+
export interface UserCapabilityDefinition {
|
|
32
|
+
readonly id: UserCapability;
|
|
33
|
+
readonly label?: string;
|
|
34
|
+
readonly group?: string;
|
|
35
|
+
readonly description?: string;
|
|
36
|
+
/** Built-in roles receiving this capability by default. Defaults to administrator. */
|
|
37
|
+
readonly defaultRoles?: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
export declare const ACCESS_SCOPE_DOMAINS: readonly ["site", "contentType", "locale", "owner"];
|
|
40
|
+
export type AccessScopeDomain = (typeof ACCESS_SCOPE_DOMAINS)[number];
|
|
41
|
+
/** A resource constraint attached to a capability grant. Empty scopes are unrestricted. */
|
|
42
|
+
export interface AccessScope {
|
|
43
|
+
readonly siteIds?: readonly string[];
|
|
44
|
+
readonly contentTypes?: readonly string[];
|
|
45
|
+
readonly locales?: readonly string[];
|
|
46
|
+
/** `self` limits access to resources owned by the actor. */
|
|
47
|
+
readonly ownership?: "any" | "self";
|
|
48
|
+
}
|
|
49
|
+
/** Public, serialisable access policy used by admin, HTTP APIs, and plugins. */
|
|
50
|
+
export interface AccessPolicy {
|
|
51
|
+
readonly grants?: readonly UserCapability[];
|
|
52
|
+
readonly denies?: readonly UserCapability[];
|
|
53
|
+
readonly scopes?: Partial<Record<UserCapability, AccessScope>>;
|
|
54
|
+
}
|
|
55
|
+
export interface RoleDefinition {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly description?: string | null;
|
|
59
|
+
readonly builtIn: boolean;
|
|
60
|
+
readonly capabilities: readonly UserCapability[];
|
|
61
|
+
}
|
|
62
|
+
export interface AccessResource {
|
|
63
|
+
readonly siteId?: string;
|
|
64
|
+
readonly contentType?: string;
|
|
65
|
+
readonly locale?: string;
|
|
66
|
+
readonly ownerId?: string | null;
|
|
67
|
+
}
|
|
68
|
+
export declare const ROLE_CAPABILITIES: Record<string, UserCapability[]>;
|
|
69
|
+
export declare function roleHasCapability(role: string, capability: UserCapability): boolean;
|
|
70
|
+
/** Resolve role capabilities plus per-user grants, with explicit denies winning. */
|
|
71
|
+
export declare function effectiveCapabilities(roleCapabilities: readonly UserCapability[], policy?: AccessPolicy): UserCapability[];
|
|
72
|
+
export declare function scopeAllows(scope: AccessScope | undefined, resource: AccessResource, actorId: string): boolean;
|
|
73
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,iBAAiB,YAC5B,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B;AAC3B,gHAAgH;AAChH,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,mBAAmB;AACnB;;;;GAIG;AACH,uBAAuB,EACvB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,wBAAwB;AACxB;;;;GAIG;AACH,aAAa;AACb,yDAAyD;AACzD,eAAe,EACf,gBAAgB;AAChB;;;;GAIG;AACH,aAAa,EACb,YAA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CAAC,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,SAAS,cAAc,EAAE,CAAC;CAClD;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,CAkC9D,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAEnF;AAED,oFAAoF;AACpF,wBAAgB,qBAAqB,CACnC,gBAAgB,EAAE,SAAS,cAAc,EAAE,EAC3C,MAAM,GAAE,YAAiB,GACxB,cAAc,EAAE,CAKlB;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,GAAG,SAAS,EAC9B,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAUT"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User capability definitions — stable public API.
|
|
3
|
+
* Code should always check capabilities, never role names directly.
|
|
4
|
+
*/
|
|
5
|
+
export const USER_CAPABILITIES = [
|
|
6
|
+
"content:read",
|
|
7
|
+
"content:create",
|
|
8
|
+
"content:update",
|
|
9
|
+
"content:delete",
|
|
10
|
+
"content:publish",
|
|
11
|
+
"content:revisions:read",
|
|
12
|
+
"content:revisions:restore",
|
|
13
|
+
"content:revisions:discard",
|
|
14
|
+
/** Lock and unlock blocks; without it, locked blocks cannot be moved, removed, or edited (justflows-ce#298). */
|
|
15
|
+
"content:locks:manage",
|
|
16
|
+
"media:read",
|
|
17
|
+
"media:upload",
|
|
18
|
+
"media:delete",
|
|
19
|
+
"comments:moderate",
|
|
20
|
+
/**
|
|
21
|
+
* Read and change comment block/allow rules, spam-signal terms, and the
|
|
22
|
+
* spam-policy thresholds (justflows-ce#143). Administrators only: moderating
|
|
23
|
+
* a comment does not include changing why comments are held.
|
|
24
|
+
*/
|
|
25
|
+
"comments:rules:manage",
|
|
26
|
+
"users:read",
|
|
27
|
+
"users:manage",
|
|
28
|
+
"plugins:read",
|
|
29
|
+
"plugins:install",
|
|
30
|
+
"plugins:activate",
|
|
31
|
+
"plugins:delete",
|
|
32
|
+
"themes:read",
|
|
33
|
+
"themes:install",
|
|
34
|
+
"themes:activate",
|
|
35
|
+
"themes:delete",
|
|
36
|
+
"settings:read",
|
|
37
|
+
"settings:manage",
|
|
38
|
+
"mail:read",
|
|
39
|
+
"mail:manage",
|
|
40
|
+
"email-templates:read",
|
|
41
|
+
"email-templates:manage",
|
|
42
|
+
/**
|
|
43
|
+
* Read site design: templates, template parts, the header library, widget
|
|
44
|
+
* areas, menus, patterns, reusable blocks, style presets and global styles
|
|
45
|
+
* (justflows-ce#314).
|
|
46
|
+
*/
|
|
47
|
+
"design:read",
|
|
48
|
+
/** Change and publish site design (justflows-ce#314). */
|
|
49
|
+
"design:manage",
|
|
50
|
+
"updates:manage",
|
|
51
|
+
/**
|
|
52
|
+
* Add, change, and switch off custom JavaScript and markup on public pages
|
|
53
|
+
* (justflows-ce#94). Administrators only by default; not part of any other
|
|
54
|
+
* built-in role, because custom code runs in every visitor's browser.
|
|
55
|
+
*/
|
|
56
|
+
"code:manage",
|
|
57
|
+
"site:admin",
|
|
58
|
+
"ai:use",
|
|
59
|
+
];
|
|
60
|
+
export const ACCESS_SCOPE_DOMAINS = ["site", "contentType", "locale", "owner"];
|
|
61
|
+
export const ROLE_CAPABILITIES = {
|
|
62
|
+
administrator: [...USER_CAPABILITIES],
|
|
63
|
+
editor: [
|
|
64
|
+
"content:read",
|
|
65
|
+
"content:create",
|
|
66
|
+
"content:update",
|
|
67
|
+
"content:delete",
|
|
68
|
+
"content:publish",
|
|
69
|
+
"content:revisions:read",
|
|
70
|
+
"content:revisions:restore",
|
|
71
|
+
"content:revisions:discard",
|
|
72
|
+
"content:locks:manage",
|
|
73
|
+
"media:read",
|
|
74
|
+
"media:upload",
|
|
75
|
+
"media:delete",
|
|
76
|
+
"comments:moderate",
|
|
77
|
+
"users:read",
|
|
78
|
+
"design:read",
|
|
79
|
+
"design:manage",
|
|
80
|
+
"ai:use",
|
|
81
|
+
],
|
|
82
|
+
author: [
|
|
83
|
+
"content:read",
|
|
84
|
+
"content:create",
|
|
85
|
+
"content:update",
|
|
86
|
+
"content:revisions:read",
|
|
87
|
+
"content:revisions:restore",
|
|
88
|
+
"content:revisions:discard",
|
|
89
|
+
"media:read",
|
|
90
|
+
"media:upload",
|
|
91
|
+
"design:read",
|
|
92
|
+
],
|
|
93
|
+
contributor: ["content:read", "content:create", "content:revisions:read", "design:read"],
|
|
94
|
+
subscriber: ["content:read"],
|
|
95
|
+
};
|
|
96
|
+
export function roleHasCapability(role, capability) {
|
|
97
|
+
return ROLE_CAPABILITIES[role]?.includes(capability) ?? false;
|
|
98
|
+
}
|
|
99
|
+
/** Resolve role capabilities plus per-user grants, with explicit denies winning. */
|
|
100
|
+
export function effectiveCapabilities(roleCapabilities, policy = {}) {
|
|
101
|
+
const denied = new Set(policy.denies ?? []);
|
|
102
|
+
return [...new Set([...roleCapabilities, ...(policy.grants ?? [])])].filter((capability) => !denied.has(capability));
|
|
103
|
+
}
|
|
104
|
+
export function scopeAllows(scope, resource, actorId) {
|
|
105
|
+
if (!scope)
|
|
106
|
+
return true;
|
|
107
|
+
if (scope.siteIds?.length && (!resource.siteId || !scope.siteIds.includes(resource.siteId)))
|
|
108
|
+
return false;
|
|
109
|
+
if (scope.contentTypes?.length &&
|
|
110
|
+
(!resource.contentType || !scope.contentTypes.includes(resource.contentType)))
|
|
111
|
+
return false;
|
|
112
|
+
if (scope.locales?.length && (!resource.locale || !scope.locales.includes(resource.locale)))
|
|
113
|
+
return false;
|
|
114
|
+
if (scope.ownership === "self" && resource.ownerId !== actorId)
|
|
115
|
+
return false;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,cAAc;IACd,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB,wBAAwB;IACxB,2BAA2B;IAC3B,2BAA2B;IAC3B,gHAAgH;IAChH,sBAAsB;IACtB,YAAY;IACZ,cAAc;IACd,cAAc;IACd,mBAAmB;IACnB;;;;OAIG;IACH,uBAAuB;IACvB,YAAY;IACZ,cAAc;IACd,cAAc;IACd,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,aAAa;IACb,gBAAgB;IAChB,iBAAiB;IACjB,eAAe;IACf,eAAe;IACf,iBAAiB;IACjB,WAAW;IACX,aAAa;IACb,sBAAsB;IACtB,wBAAwB;IACxB;;;;OAIG;IACH,aAAa;IACb,yDAAyD;IACzD,eAAe;IACf,gBAAgB;IAChB;;;;OAIG;IACH,aAAa;IACb,YAAY;IACZ,QAAQ;CACA,CAAC;AAeX,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AAkCxF,MAAM,CAAC,MAAM,iBAAiB,GAAqC;IACjE,aAAa,EAAE,CAAC,GAAG,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O,EAAE,MAAM,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1G,IACE,KAAK,CAAC,YAAY,EAAE,MAAM;QAC1B,CAAC,CAAC,QAAQ,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC7E,OAAO,KAAK,CAAC;IACf,IAAI,KAAK,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1G,IAAI,KAAK,CAAC,SAAS,KAAK,MAAM,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Host requirements shared by plugin, theme, and CSS-provider manifests. */
|
|
3
|
+
export declare const ExtensionEnginesSchema: z.ZodObject<{
|
|
4
|
+
justflows: z.ZodString;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export type ExtensionEngines = z.infer<typeof ExtensionEnginesSchema>;
|
|
7
|
+
//# sourceMappingURL=compatibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../src/compatibility.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB;;iBAEjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Host requirements shared by plugin, theme, and CSS-provider manifests. */
|
|
4
|
+
export const ExtensionEnginesSchema = z.object({
|
|
5
|
+
justflows: z.string().min(1),
|
|
6
|
+
});
|
|
7
|
+
//# sourceMappingURL=compatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compatibility.js","sourceRoot":"","sources":["../src/compatibility.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,6EAA6E;AAC7E,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The consent categories every cookie a site sets must fall into. A plugin that
|
|
4
|
+
* writes any non-essential cookie MUST declare it (`ctx.cookies.declare`) so the
|
|
5
|
+
* consent banner can disclose it and expire it when its category is withdrawn.
|
|
6
|
+
*
|
|
7
|
+
* - `necessary` — required for the site to work (auth, CSRF, load balancing,
|
|
8
|
+
* the consent record itself). Cannot be declined.
|
|
9
|
+
* - `preferences` — remembers non-essential choices (language, region, theme).
|
|
10
|
+
* Also known as "functional".
|
|
11
|
+
* - `analytics` — measures usage; aggregated, no ad targeting.
|
|
12
|
+
* - `marketing` — advertising, retargeting, cross-site measurement, social.
|
|
13
|
+
*/
|
|
14
|
+
export declare const COOKIE_CATEGORIES: readonly ["necessary", "preferences", "analytics", "marketing"];
|
|
15
|
+
export type CookieCategory = (typeof COOKIE_CATEGORIES)[number];
|
|
16
|
+
export declare const CookieDeclarationSchema: z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
category: z.ZodEnum<{
|
|
19
|
+
analytics: "analytics";
|
|
20
|
+
marketing: "marketing";
|
|
21
|
+
necessary: "necessary";
|
|
22
|
+
preferences: "preferences";
|
|
23
|
+
}>;
|
|
24
|
+
purpose: z.ZodString;
|
|
25
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
26
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
27
|
+
duration: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type CookieDeclaration = z.infer<typeof CookieDeclarationSchema>;
|
|
30
|
+
/** A declaration after the host has attributed it and applied operator overrides. */
|
|
31
|
+
export interface ResolvedCookie extends CookieDeclaration {
|
|
32
|
+
/** `"core"` or the id of the plugin that declared it. */
|
|
33
|
+
declaredBy: string;
|
|
34
|
+
/** `category`, unless the operator re-classified this cookie name. */
|
|
35
|
+
effectiveCategory: CookieCategory;
|
|
36
|
+
/** True when the operator overrode the declared category. */
|
|
37
|
+
overridden: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface PluginCookiesApi {
|
|
40
|
+
/**
|
|
41
|
+
* Declare a cookie this plugin sets. Anything that is not strictly necessary
|
|
42
|
+
* MUST be declared so a consent plugin can disclose and enforce it. Calling
|
|
43
|
+
* again with the same `name` replaces the earlier declaration. All of a
|
|
44
|
+
* plugin's declarations are dropped when it deactivates.
|
|
45
|
+
*/
|
|
46
|
+
declare(cookie: CookieDeclaration | CookieDeclaration[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* The whole site cookie registry — the host's own cookies plus every active
|
|
49
|
+
* plugin's declarations — with the operator's category overrides applied.
|
|
50
|
+
*/
|
|
51
|
+
list(): Promise<ResolvedCookie[]>;
|
|
52
|
+
}
|
|
53
|
+
/** Resolve raw declarations against operator overrides, de-duplicating by name
|
|
54
|
+
* (host entries win over plugin entries for the same name). */
|
|
55
|
+
export declare function resolveCookies(declared: (CookieDeclaration & {
|
|
56
|
+
declaredBy: string;
|
|
57
|
+
})[], overrides?: Record<string, CookieCategory>): ResolvedCookie[];
|
|
58
|
+
/** Match a stored cookie name against a declaration name that may end in `*`. */
|
|
59
|
+
export declare function cookieNameMatches(pattern: string, cookieName: string): boolean;
|
|
60
|
+
//# sourceMappingURL=cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,YAAI,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AACjG,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;iBAmBlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,qFAAqF;AACrF,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACvD,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,iBAAiB,EAAE,cAAc,CAAC;IAClC,6DAA6D;IAC7D,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAE/D;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CACnC;AAED;+DAC+D;AAC/D,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,CAAC,iBAAiB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,EACxD,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAM,GAC7C,cAAc,EAAE,CAkBlB;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAG9E"}
|
package/dist/cookies.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* The consent categories every cookie a site sets must fall into. A plugin that
|
|
5
|
+
* writes any non-essential cookie MUST declare it (`ctx.cookies.declare`) so the
|
|
6
|
+
* consent banner can disclose it and expire it when its category is withdrawn.
|
|
7
|
+
*
|
|
8
|
+
* - `necessary` — required for the site to work (auth, CSRF, load balancing,
|
|
9
|
+
* the consent record itself). Cannot be declined.
|
|
10
|
+
* - `preferences` — remembers non-essential choices (language, region, theme).
|
|
11
|
+
* Also known as "functional".
|
|
12
|
+
* - `analytics` — measures usage; aggregated, no ad targeting.
|
|
13
|
+
* - `marketing` — advertising, retargeting, cross-site measurement, social.
|
|
14
|
+
*/
|
|
15
|
+
export const COOKIE_CATEGORIES = ["necessary", "preferences", "analytics", "marketing"];
|
|
16
|
+
export const CookieDeclarationSchema = z.object({
|
|
17
|
+
/** Exact cookie name, or a prefix ending in `*` (e.g. `_ga_*`). */
|
|
18
|
+
name: z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(128)
|
|
22
|
+
.regex(/^[A-Za-z0-9_.*-]+$/, "Cookie name may only contain letters, digits, _ . - and a trailing *"),
|
|
23
|
+
category: z.enum(COOKIE_CATEGORIES),
|
|
24
|
+
/** Why the cookie is set — shown verbatim in the consent disclosure. */
|
|
25
|
+
purpose: z.string().min(1).max(300),
|
|
26
|
+
/** Who sets it, when it is not first-party (e.g. "Google", "Meta"). */
|
|
27
|
+
provider: z.string().max(128).optional(),
|
|
28
|
+
/** Cookie domain, when it differs from the site host. */
|
|
29
|
+
domain: z.string().max(253).optional(),
|
|
30
|
+
/** Human-readable lifetime: `"session"`, `"13 months"`, `"1 year"`. */
|
|
31
|
+
duration: z.string().max(64).optional(),
|
|
32
|
+
});
|
|
33
|
+
/** Resolve raw declarations against operator overrides, de-duplicating by name
|
|
34
|
+
* (host entries win over plugin entries for the same name). */
|
|
35
|
+
export function resolveCookies(declared, overrides = {}) {
|
|
36
|
+
const byName = new Map();
|
|
37
|
+
for (const entry of declared) {
|
|
38
|
+
const existing = byName.get(entry.name);
|
|
39
|
+
if (!existing || (existing.declaredBy !== "core" && entry.declaredBy === "core")) {
|
|
40
|
+
byName.set(entry.name, entry);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [...byName.values()]
|
|
44
|
+
.map((entry) => {
|
|
45
|
+
const override = overrides[entry.name];
|
|
46
|
+
return {
|
|
47
|
+
...entry,
|
|
48
|
+
effectiveCategory: override ?? entry.category,
|
|
49
|
+
overridden: override !== undefined && override !== entry.category,
|
|
50
|
+
};
|
|
51
|
+
})
|
|
52
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
53
|
+
}
|
|
54
|
+
/** Match a stored cookie name against a declaration name that may end in `*`. */
|
|
55
|
+
export function cookieNameMatches(pattern, cookieName) {
|
|
56
|
+
if (pattern.endsWith("*"))
|
|
57
|
+
return cookieName.startsWith(pattern.slice(0, -1));
|
|
58
|
+
return pattern === cookieName;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AAGjG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,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