@extension-use/host 0.0.0-stage → 0.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.
@@ -0,0 +1,61 @@
1
+ import {
2
+ OPT_IN_GROUPS,
3
+ builtinGroups
4
+ } from "./chunk-QYMPEWZP.js";
5
+
6
+ // src/permissions.ts
7
+ var GROUP_NAMES = Object.keys(builtinGroups);
8
+ var DEFAULT_GROUP_NAMES = GROUP_NAMES.filter((n) => !OPT_IN_GROUPS.includes(n));
9
+ function permissionsFor(groups, options = {}) {
10
+ const permissions = /* @__PURE__ */ new Set();
11
+ let hostAccess = false;
12
+ for (const g of groups) {
13
+ for (const p of g.permissions) permissions.add(p);
14
+ if (g.needsHostAccess) hostAccess = true;
15
+ }
16
+ if (hostAccess && options.injectOnDemand !== false) permissions.add("scripting");
17
+ if (options.sidePanel) permissions.add("sidePanel");
18
+ if (options.remote) {
19
+ permissions.add("storage");
20
+ permissions.add("alarms");
21
+ }
22
+ return {
23
+ permissions: [...permissions].sort(),
24
+ host_permissions: hostAccess ? options.matches ?? ["<all_urls>"] : []
25
+ };
26
+ }
27
+ function withExtensionUse(manifest, options = {}) {
28
+ const names = options.groups ?? DEFAULT_GROUP_NAMES;
29
+ const unknown = names.filter((n) => !(n in builtinGroups));
30
+ if (unknown.length) throw new Error(`Unknown Extension-use groups: ${unknown.join(", ")}. Known: ${GROUP_NAMES.join(", ")}`);
31
+ const perms = permissionsFor(
32
+ names.map((n) => builtinGroups[n]),
33
+ {
34
+ ...options.matches ? { matches: options.matches } : {},
35
+ ...options.injectOnDemand !== void 0 ? { injectOnDemand: options.injectOnDemand } : {},
36
+ ...options.remote ? { remote: true } : {},
37
+ sidePanel: options.sidePanel ?? true
38
+ }
39
+ );
40
+ const out = { ...manifest };
41
+ out.permissions = unique([...manifest.permissions ?? [], ...perms.permissions]);
42
+ if (perms.host_permissions.length) out.host_permissions = unique([...manifest.host_permissions ?? [], ...perms.host_permissions]);
43
+ if (options.controllerOrigins?.length) {
44
+ const matches = options.controllerOrigins.map((o) => `${o.replace(/\/+$/, "")}/*`);
45
+ out.externally_connectable = {
46
+ ...manifest.externally_connectable,
47
+ matches: unique([...manifest.externally_connectable?.matches ?? [], ...matches])
48
+ };
49
+ }
50
+ return out;
51
+ }
52
+ function unique(xs) {
53
+ return [...new Set(xs)];
54
+ }
55
+
56
+ export {
57
+ GROUP_NAMES,
58
+ DEFAULT_GROUP_NAMES,
59
+ permissionsFor,
60
+ withExtensionUse
61
+ };
@@ -0,0 +1,16 @@
1
+ // src/wire.ts
2
+ var FRAME_PORT = "extension-use:frame";
3
+ var CONTENT_MESSAGE = "__extensionUseCall";
4
+ var CONTENT_CANCEL = "__extensionUseCancel";
5
+ var CONTENT_EVENT = "__extensionUseEvent";
6
+ var UI_PORT = "extension-use:ui";
7
+ var OFFSCREEN_MESSAGE = "__extensionUseOffscreen";
8
+
9
+ export {
10
+ FRAME_PORT,
11
+ CONTENT_MESSAGE,
12
+ CONTENT_CANCEL,
13
+ CONTENT_EVENT,
14
+ UI_PORT,
15
+ OFFSCREEN_MESSAGE
16
+ };