@feltdb/feltkit 0.3.30 → 0.3.32

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.
Files changed (157) hide show
  1. package/dist/app.d.ts +67 -11
  2. package/dist/app.js +58 -2
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.js +2 -0
  5. package/dist/appboundry/build.js.map +1 -1
  6. package/dist/appboundry/guest.js +23 -1
  7. package/dist/appboundry/guest.js.map +1 -1
  8. package/dist/authorize.d.ts +24 -3
  9. package/dist/authorize.js.map +1 -1
  10. package/dist/broker/assertion.d.ts +68 -0
  11. package/dist/broker/assertion.js +104 -0
  12. package/dist/broker/assertion.js.map +1 -0
  13. package/dist/broker/keys.d.ts +9 -0
  14. package/dist/broker/keys.js +47 -0
  15. package/dist/broker/keys.js.map +1 -0
  16. package/dist/broker/server.d.ts +54 -0
  17. package/dist/broker/server.js +305 -0
  18. package/dist/broker/server.js.map +1 -0
  19. package/dist/cli/broker.d.ts +11 -0
  20. package/dist/cli/broker.js +72 -0
  21. package/dist/cli/broker.js.map +1 -0
  22. package/dist/cli/deploy.js +6 -0
  23. package/dist/cli/deploy.js.map +1 -1
  24. package/dist/cli/main.js +123 -0
  25. package/dist/cli/main.js.map +1 -1
  26. package/dist/client/index.d.ts +8 -2
  27. package/dist/client/index.js +45 -1
  28. package/dist/client/index.js.map +1 -1
  29. package/dist/docs.d.ts +1 -1
  30. package/dist/docs.js +3 -0
  31. package/dist/docs.js.map +1 -1
  32. package/dist/extension/build.d.ts +50 -0
  33. package/dist/extension/build.js +205 -0
  34. package/dist/extension/build.js.map +1 -0
  35. package/dist/extension/client-shim.d.ts +7 -0
  36. package/dist/extension/client-shim.js +13 -0
  37. package/dist/extension/client-shim.js.map +1 -0
  38. package/dist/extension/connect-ui.d.ts +24 -0
  39. package/dist/extension/connect-ui.js +67 -0
  40. package/dist/extension/connect-ui.js.map +1 -0
  41. package/dist/extension/connection.d.ts +109 -0
  42. package/dist/extension/connection.js +190 -0
  43. package/dist/extension/connection.js.map +1 -0
  44. package/dist/extension/host-core.d.ts +36 -0
  45. package/dist/extension/host-core.js +50 -0
  46. package/dist/extension/host-core.js.map +1 -0
  47. package/dist/extension/host.d.ts +1 -0
  48. package/dist/extension/host.js +8 -0
  49. package/dist/extension/host.js.map +1 -0
  50. package/dist/extension/icons.d.ts +13 -0
  51. package/dist/extension/icons.js +75 -0
  52. package/dist/extension/icons.js.map +1 -0
  53. package/dist/extension/identity.d.ts +40 -0
  54. package/dist/extension/identity.js +110 -0
  55. package/dist/extension/identity.js.map +1 -0
  56. package/dist/extension/options.d.ts +1 -0
  57. package/dist/extension/options.js +57 -0
  58. package/dist/extension/options.js.map +1 -0
  59. package/dist/extension/service-worker.d.ts +1 -0
  60. package/dist/extension/service-worker.js +38 -0
  61. package/dist/extension/service-worker.js.map +1 -0
  62. package/dist/extension/validate.d.ts +7 -0
  63. package/dist/extension/validate.js +143 -0
  64. package/dist/extension/validate.js.map +1 -0
  65. package/dist/extension/zip.d.ts +7 -0
  66. package/dist/extension/zip.js +94 -0
  67. package/dist/extension/zip.js.map +1 -0
  68. package/dist/index.d.ts +6 -2
  69. package/dist/index.js +1 -0
  70. package/dist/index.js.map +1 -1
  71. package/dist/policy.d.ts +179 -0
  72. package/dist/policy.js +311 -0
  73. package/dist/policy.js.map +1 -0
  74. package/dist/runtime/activity.d.ts +16 -0
  75. package/dist/runtime/activity.js.map +1 -1
  76. package/dist/runtime/application-authority.d.ts +22 -3
  77. package/dist/runtime/application-authority.js +94 -20
  78. package/dist/runtime/application-authority.js.map +1 -1
  79. package/dist/runtime/assemble.d.ts +13 -0
  80. package/dist/runtime/assemble.js +29 -1
  81. package/dist/runtime/assemble.js.map +1 -1
  82. package/dist/runtime/authority-contract.d.ts +55 -0
  83. package/dist/runtime/authority-contract.js +60 -0
  84. package/dist/runtime/authority-contract.js.map +1 -0
  85. package/dist/runtime/content.d.ts +50 -0
  86. package/dist/runtime/content.js +98 -1
  87. package/dist/runtime/content.js.map +1 -1
  88. package/dist/runtime/context.d.ts +86 -11
  89. package/dist/runtime/contract.js +11 -2
  90. package/dist/runtime/contract.js.map +1 -1
  91. package/dist/runtime/data.d.ts +25 -0
  92. package/dist/runtime/data.js +92 -8
  93. package/dist/runtime/data.js.map +1 -1
  94. package/dist/runtime/image-variants.d.ts +48 -0
  95. package/dist/runtime/image-variants.js +295 -0
  96. package/dist/runtime/image-variants.js.map +1 -0
  97. package/dist/runtime/integrations.d.ts +2 -0
  98. package/dist/runtime/integrations.js +10 -7
  99. package/dist/runtime/integrations.js.map +1 -1
  100. package/dist/runtime/invocations.d.ts +3 -0
  101. package/dist/runtime/invocations.js +1 -1
  102. package/dist/runtime/invocations.js.map +1 -1
  103. package/dist/runtime/live.d.ts +10 -7
  104. package/dist/runtime/live.js +24 -12
  105. package/dist/runtime/live.js.map +1 -1
  106. package/dist/runtime/local-authority.d.ts +80 -5
  107. package/dist/runtime/local-authority.js +259 -14
  108. package/dist/runtime/local-authority.js.map +1 -1
  109. package/dist/runtime/policies.d.ts +89 -0
  110. package/dist/runtime/policies.js +152 -0
  111. package/dist/runtime/policies.js.map +1 -0
  112. package/dist/runtime/readiness.js +31 -1
  113. package/dist/runtime/readiness.js.map +1 -1
  114. package/dist/runtime/runtime.d.ts +21 -1
  115. package/dist/runtime/runtime.js +200 -7
  116. package/dist/runtime/runtime.js.map +1 -1
  117. package/dist/runtime/services-rules.d.ts +9 -0
  118. package/dist/runtime/services-rules.js +47 -1
  119. package/dist/runtime/services-rules.js.map +1 -1
  120. package/dist/runtime/services.d.ts +117 -9
  121. package/dist/runtime/services.js +154 -13
  122. package/dist/runtime/services.js.map +1 -1
  123. package/dist/server/admin.d.ts +21 -0
  124. package/dist/server/admin.js +114 -0
  125. package/dist/server/admin.js.map +1 -1
  126. package/dist/server/index.js +33 -6
  127. package/dist/server/index.js.map +1 -1
  128. package/dist/server/oauth.d.ts +32 -2
  129. package/dist/server/oauth.js +130 -23
  130. package/dist/server/oauth.js.map +1 -1
  131. package/dist/server/operators.d.ts +1 -0
  132. package/dist/server/operators.js +1 -1
  133. package/dist/server/operators.js.map +1 -1
  134. package/dist/server/project.d.ts +3 -0
  135. package/dist/server/project.js +2 -2
  136. package/dist/server/project.js.map +1 -1
  137. package/dist/testing/index.d.ts +11 -0
  138. package/dist/testing/index.js +7 -0
  139. package/dist/testing/index.js.map +1 -1
  140. package/docs/AGENT-OPERATIONS.md +1 -1
  141. package/docs/ARCHITECTURE.md +2 -1
  142. package/docs/CONNECTIONS.md +10 -3
  143. package/docs/EXTENSION-HOSTS.md +64 -5
  144. package/docs/GUARANTEES.md +82 -6
  145. package/docs/LOCAL-AUTHORITY.md +118 -0
  146. package/docs/POLICIES.md +121 -0
  147. package/docs/README.md +5 -2
  148. package/docs/SECURITY.md +69 -0
  149. package/docs/SIGN-IN-BROKER.md +77 -0
  150. package/docs/TRANSACTIONS.md +4 -0
  151. package/package.json +13 -9
  152. package/skills/.claude-plugin/marketplace.json +1 -1
  153. package/skills/.claude-plugin/plugin.json +1 -1
  154. package/skills/feltkit-agent/SKILL.md +1 -1
  155. package/skills/feltkit-build/SKILL.md +10 -0
  156. package/skills/feltkit-data/SKILL.md +13 -1
  157. package/skills/feltkit-services/SKILL.md +14 -1
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Stands in for `@feltdb/feltkit/client` in an extension build: the same module, except that `createClient()` with
3
+ * no options defaults to the connected instance with a bearer session. Options the app passes still win.
4
+ */
5
+ import { createClient as createFeltKitClient } from "../client/index.js";
6
+ export * from "../client/index.js";
7
+ export function createClient(options = {}) {
8
+ const host = globalThis.__feltkitExtension;
9
+ if (!host)
10
+ throw new Error("The extension host is not connected: createClient() ran before the connection was made.");
11
+ return createFeltKitClient({ url: host.url, session: "bearer", tokens: host.tokens, ...options });
12
+ }
13
+ //# sourceMappingURL=client-shim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-shim.js","sourceRoot":"","sources":["../../src/extension/client-shim.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAsB,MAAM,oBAAoB,CAAC;AAE7F,cAAc,oBAAoB,CAAC;AAEnC,MAAM,UAAU,YAAY,CAAC,OAAO,GAAkB,EAAE;IACtD,MAAM,IAAI,GAAI,UAAqG,CAAC,kBAAkB,CAAC;IACvI,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAC;IACtH,OAAO,mBAAmB,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACpG,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The connect screen of a generated extension: the instance's address, optionally an operator-issued session,
3
+ * and one button. Plain DOM calls only: no framework, no `innerHTML`, no inline script or handler attribute, so it
4
+ * runs under Manifest V3's default content security policy (`script-src 'self'`) and renders nothing it was
5
+ * not given as text.
6
+ */
7
+ import { type ChromeLike, type Connection, type FetchLike } from "./connection.js";
8
+ export interface ConnectScreenOptions {
9
+ chrome: ChromeLike;
10
+ application: string;
11
+ /** Prefilled: the address stored or baked in. */
12
+ instance?: string;
13
+ /** The title of the page; defaults to the application's name. */
14
+ title?: string;
15
+ /** Why the screen is shown (a lost permission, a changed instance), as text. */
16
+ notice?: string;
17
+ fetch?: FetchLike;
18
+ /** Where to put the screen. */
19
+ into?: HTMLElement;
20
+ }
21
+ /** Shows the connect screen and resolves with the connection once the person has made one; the screen removes itself. */
22
+ export declare function showConnectScreen(options: ConnectScreenOptions): Promise<Connection & {
23
+ instance: string;
24
+ }>;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The connect screen of a generated extension: the instance's address, optionally an operator-issued session,
3
+ * and one button. Plain DOM calls only: no framework, no `innerHTML`, no inline script or handler attribute, so it
4
+ * runs under Manifest V3's default content security policy (`script-src 'self'`) and renders nothing it was
5
+ * not given as text.
6
+ */
7
+ import { connect, ConnectionError } from "./connection.js";
8
+ const STYLE = `
9
+ :root { color-scheme: light dark; --fk-bg: #fbfaf7; --fk-fg: #1d1c1a; --fk-muted: #6a6761; --fk-line: #d9d5cc; --fk-accent: #2f5d50; --fk-accent-fg: #fff; --fk-error: #a3271b; }
10
+ @media (prefers-color-scheme: dark) { :root { --fk-bg: #1b1a18; --fk-fg: #f2efe8; --fk-muted: #a8a49b; --fk-line: #3a3834; --fk-accent: #7fc4ae; --fk-accent-fg: #10231d; --fk-error: #ff8f80; } }
11
+ .fk-connect { box-sizing: border-box; min-height: 100vh; margin: 0; padding: 24px 20px; background: var(--fk-bg); color: var(--fk-fg); font: 14px/1.5 system-ui, sans-serif; }
12
+ .fk-connect main { max-width: 420px; margin: 0 auto; }
13
+ .fk-connect h1 { font-size: 20px; margin: 0 0 4px; }
14
+ .fk-connect p { color: var(--fk-muted); margin: 0 0 16px; }
15
+ .fk-connect label { display: block; font-weight: 600; margin: 14px 0 4px; }
16
+ .fk-connect input { box-sizing: border-box; width: 100%; padding: 9px 10px; border: 1px solid var(--fk-line); border-radius: 6px; background: transparent; color: inherit; font: inherit; }
17
+ .fk-connect input:focus-visible, .fk-connect button:focus-visible { outline: 2px solid var(--fk-accent); outline-offset: 2px; }
18
+ .fk-connect small { display: block; color: var(--fk-muted); margin-top: 4px; }
19
+ .fk-connect button { margin-top: 18px; padding: 9px 16px; border: 0; border-radius: 6px; background: var(--fk-accent); color: var(--fk-accent-fg); font: inherit; font-weight: 600; cursor: pointer; }
20
+ .fk-connect button[disabled] { opacity: .6; cursor: progress; }
21
+ .fk-connect [role="alert"] { color: var(--fk-error); margin-top: 14px; min-height: 1.5em; }
22
+ `;
23
+ function el(tag, attributes = {}, ...children) {
24
+ const node = document.createElement(tag);
25
+ for (const [name, value] of Object.entries(attributes))
26
+ node.setAttribute(name, value);
27
+ node.append(...children);
28
+ return node;
29
+ }
30
+ /** Shows the connect screen and resolves with the connection once the person has made one; the screen removes itself. */
31
+ export function showConnectScreen(options) {
32
+ const host = options.into ?? document.body;
33
+ const root = el("div", { class: "fk-connect", id: "feltkit-extension-connect" });
34
+ const style = el("style");
35
+ style.textContent = STYLE;
36
+ const instance = el("input", { id: "fk-instance", name: "instance", type: "text", inputmode: "url", autocomplete: "url", spellcheck: "false", placeholder: "https://app.example.com", required: "" });
37
+ instance.value = options.instance ?? "";
38
+ const token = el("input", { id: "fk-token", name: "session", type: "password", autocomplete: "off", spellcheck: "false" });
39
+ const message = el("div", { role: "alert", "aria-live": "polite" });
40
+ if (options.notice)
41
+ message.textContent = options.notice;
42
+ const submit = el("button", { type: "submit" }, "Connect");
43
+ const form = el("form", { novalidate: "" }, el("label", { for: "fk-instance" }, "Instance address"), instance, el("small", {}, "The extension asks the browser for access to this one address, and to nothing else."), el("label", { for: "fk-token" }, "Session token (optional)"), token, el("small", {}, "From `feltkit session create`, if an operator issued you one. Otherwise sign in inside the app."), submit, message);
44
+ root.append(el("main", {}, el("h1", {}, options.title ?? options.application), el("p", {}, `Connect this extension to your ${options.application} instance.`), form));
45
+ document.head.append(style);
46
+ host.append(root);
47
+ instance.focus();
48
+ return new Promise((resolve) => {
49
+ form.addEventListener("submit", (event) => {
50
+ event.preventDefault();
51
+ message.textContent = "";
52
+ submit.disabled = true;
53
+ // Called synchronously from the submit: the permission prompt needs this user gesture.
54
+ connect(options.chrome, { instance: instance.value, token: token.value, expectedApplication: options.application, ...(options.fetch ? { fetch: options.fetch } : {}) }).then((connection) => {
55
+ root.remove();
56
+ style.remove();
57
+ resolve({ instance: connection.instance, ...(connection.token ? { token: connection.token } : {}) });
58
+ }, (error) => {
59
+ submit.disabled = false;
60
+ message.textContent = error instanceof ConnectionError ? error.message : "Could not connect. Check the address and try again.";
61
+ if (error instanceof ConnectionError && error.step === "address")
62
+ instance.focus();
63
+ });
64
+ });
65
+ });
66
+ }
67
+ //# sourceMappingURL=connect-ui.js.map
@@ -0,0 +1 @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KAAK,CAAC,IAAI,KAAK,SAAS;oBAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;YACrF,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The extension side of `feltkit target:browser-extension`: how an extension page holds its connection to a
3
+ * FeltKit instance. It runs in extension pages (the side panel, the popup, the tab, the options page), never in
4
+ * the service worker, which holds no session and never calls the instance (docs/EXTENSION-HOSTS.md).
5
+ *
6
+ * Everything here takes the `chrome` API and `fetch` as parameters, so it is tested against fakes and against a
7
+ * real FeltKit server; nothing is written to the page's own storage.
8
+ *
9
+ * The contract is the one FeltKit already has: bearer sessions (`createClient({ session: "bearer", tokens })`), the
10
+ * session-end rule (`UNAUTHORIZED` + `hint: "SESSION"` clears the token), and `GET /api/session` naming the
11
+ * `application` an instance serves.
12
+ */
13
+ /** The storage keys: the instance's origin, and the bearer session. Both in `chrome.storage.local`. */
14
+ export declare const INSTANCE_KEY = "feltkit.extension.instance";
15
+ export declare const SESSION_KEY = "feltkit.extension.session";
16
+ /** The part of `chrome` this module uses. */
17
+ export interface ChromeLike {
18
+ storage: {
19
+ local: {
20
+ get(keys: string | string[]): Promise<Record<string, unknown>>;
21
+ set(items: Record<string, unknown>): Promise<void>;
22
+ remove(keys: string | string[]): Promise<void>;
23
+ setAccessLevel?(options: {
24
+ accessLevel: string;
25
+ }): Promise<void>;
26
+ };
27
+ onChanged?: {
28
+ addListener(listener: (changes: Record<string, {
29
+ oldValue?: unknown;
30
+ newValue?: unknown;
31
+ }>, area: string) => void): void;
32
+ };
33
+ };
34
+ permissions?: {
35
+ contains(permissions: {
36
+ origins: string[];
37
+ }): Promise<boolean>;
38
+ request(permissions: {
39
+ origins: string[];
40
+ }): Promise<boolean>;
41
+ remove?(permissions: {
42
+ origins: string[];
43
+ }): Promise<boolean>;
44
+ };
45
+ }
46
+ export interface TokenStoreLike {
47
+ get(): string | null;
48
+ set(token: string | null): void;
49
+ }
50
+ /** What a person is told when a step fails; thrown by this module, shown as is. */
51
+ export declare class ConnectionError extends Error {
52
+ readonly step: "address" | "permission" | "instance" | "application" | "session";
53
+ constructor(message: string, step: "address" | "permission" | "instance" | "application" | "session");
54
+ }
55
+ /**
56
+ * The origin of an instance, from what a person typed: `https://` anywhere, `http://` only for this machine. No
57
+ * credentials, no path, no query: the extension asks for one origin, and a session never travels in a URL.
58
+ */
59
+ export declare function normalizeInstance(input: string): string;
60
+ /** The match pattern for one instance origin: what the extension asks Chrome's permission for. */
61
+ export declare function originPattern(origin: string): string;
62
+ /** Storage readable only by the extension's own pages, never by content scripts that run inside web pages. */
63
+ export declare function lockStorage(chrome: ChromeLike): Promise<void>;
64
+ export interface Connection {
65
+ instance?: string;
66
+ token?: string;
67
+ }
68
+ export declare function readConnection(chrome: ChromeLike): Promise<Connection>;
69
+ /**
70
+ * A synchronous token store (what `createClient` needs) over memory, written through to `chrome.storage.local`. A
71
+ * token set or cleared elsewhere (the options page signing out, another panel) is picked up through
72
+ * `storage.onChanged`, so an open panel does not keep a session another page ended.
73
+ */
74
+ export declare function createTokenStore(chrome: ChromeLike, initial: string | null, onExternalChange?: (token: string | null) => void): TokenStoreLike;
75
+ export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
76
+ export interface InstanceInfo {
77
+ application: string;
78
+ principal: {
79
+ id: string;
80
+ } | null;
81
+ }
82
+ /** Asks the instance who it is (`GET /api/session`), with no credential. It must serve the extension's application. */
83
+ export declare function verifyInstance(origin: string, expectedApplication: string | null, fetchImpl?: FetchLike): Promise<InstanceInfo>;
84
+ /** Whether a session token is live on the instance (`GET /api/session` as that bearer). */
85
+ export declare function verifyToken(origin: string, token: string, fetchImpl?: FetchLike): Promise<InstanceInfo["principal"]>;
86
+ export declare function hasHostPermission(chrome: ChromeLike, origin: string): Promise<boolean>;
87
+ export interface ConnectOptions {
88
+ /** What the person typed. */
89
+ instance: string;
90
+ /** An operator-issued session (`feltkit session create`), optional: the app's own sign-in works too. */
91
+ token?: string;
92
+ /** The application this extension carries; an instance serving another is refused. */
93
+ expectedApplication: string | null;
94
+ fetch?: FetchLike;
95
+ }
96
+ /**
97
+ * Connects to an instance. Call it from the click that submits the form: `chrome.permissions.request` needs the
98
+ * user gesture, so the address is checked synchronously and the request is the first asynchronous step.
99
+ */
100
+ export declare function connect(chrome: ChromeLike, options: ConnectOptions): Promise<Required<Pick<Connection, "instance">> & Connection & {
101
+ info: InstanceInfo;
102
+ }>;
103
+ /**
104
+ * Ends the session and forgets the instance (`keepInstance`: only the session). The session is revoked on the
105
+ * instance first (best effort: an unreachable instance must not keep a person signed in here), then the keys go.
106
+ */
107
+ export declare function disconnect(chrome: ChromeLike, fetchImpl?: FetchLike, options?: {
108
+ keepInstance?: boolean;
109
+ }): Promise<void>;
@@ -0,0 +1,190 @@
1
+ /**
2
+ * The extension side of `feltkit target:browser-extension`: how an extension page holds its connection to a
3
+ * FeltKit instance. It runs in extension pages (the side panel, the popup, the tab, the options page), never in
4
+ * the service worker, which holds no session and never calls the instance (docs/EXTENSION-HOSTS.md).
5
+ *
6
+ * Everything here takes the `chrome` API and `fetch` as parameters, so it is tested against fakes and against a
7
+ * real FeltKit server; nothing is written to the page's own storage.
8
+ *
9
+ * The contract is the one FeltKit already has: bearer sessions (`createClient({ session: "bearer", tokens })`), the
10
+ * session-end rule (`UNAUTHORIZED` + `hint: "SESSION"` clears the token), and `GET /api/session` naming the
11
+ * `application` an instance serves.
12
+ */
13
+ /** The storage keys: the instance's origin, and the bearer session. Both in `chrome.storage.local`. */
14
+ export const INSTANCE_KEY = "feltkit.extension.instance";
15
+ export const SESSION_KEY = "feltkit.extension.session";
16
+ /** What a person is told when a step fails; thrown by this module, shown as is. */
17
+ export class ConnectionError extends Error {
18
+ step;
19
+ constructor(message, step) {
20
+ super(message);
21
+ this.step = step;
22
+ this.name = "ConnectionError";
23
+ }
24
+ }
25
+ const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]"]);
26
+ /**
27
+ * The origin of an instance, from what a person typed: `https://` anywhere, `http://` only for this machine. No
28
+ * credentials, no path, no query: the extension asks for one origin, and a session never travels in a URL.
29
+ */
30
+ export function normalizeInstance(input) {
31
+ const text = String(input ?? "").trim();
32
+ if (!text)
33
+ throw new ConnectionError("Enter the address of your FeltKit instance.", "address");
34
+ let url;
35
+ try {
36
+ url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `https://${text}`);
37
+ }
38
+ catch {
39
+ throw new ConnectionError(`"${text}" is not an address. Use something like https://app.example.com.`, "address");
40
+ }
41
+ if (url.username || url.password)
42
+ throw new ConnectionError("An address with a user name or password in it is refused: sign in inside the app instead.", "address");
43
+ if (url.protocol === "http:") {
44
+ if (!LOOPBACK.has(url.hostname))
45
+ throw new ConnectionError("Only https:// addresses are accepted (http:// is for this machine only).", "address");
46
+ }
47
+ else if (url.protocol !== "https:") {
48
+ throw new ConnectionError("Only https:// addresses are accepted.", "address");
49
+ }
50
+ return url.origin;
51
+ }
52
+ /** The match pattern for one instance origin: what the extension asks Chrome's permission for. */
53
+ export function originPattern(origin) {
54
+ return `${origin}/*`;
55
+ }
56
+ /** Storage readable only by the extension's own pages, never by content scripts that run inside web pages. */
57
+ export async function lockStorage(chrome) {
58
+ try {
59
+ await chrome.storage.local.setAccessLevel?.({ accessLevel: "TRUSTED_CONTEXTS" });
60
+ }
61
+ catch {
62
+ /* a Chrome without it keeps the default; the extension declares no content scripts, so none can read it */
63
+ }
64
+ }
65
+ export async function readConnection(chrome) {
66
+ const stored = await chrome.storage.local.get([INSTANCE_KEY, SESSION_KEY]);
67
+ const instance = typeof stored[INSTANCE_KEY] === "string" ? stored[INSTANCE_KEY] : undefined;
68
+ const token = typeof stored[SESSION_KEY] === "string" && stored[SESSION_KEY] ? stored[SESSION_KEY] : undefined;
69
+ return { ...(instance ? { instance } : {}), ...(token ? { token } : {}) };
70
+ }
71
+ /**
72
+ * A synchronous token store (what `createClient` needs) over memory, written through to `chrome.storage.local`. A
73
+ * token set or cleared elsewhere (the options page signing out, another panel) is picked up through
74
+ * `storage.onChanged`, so an open panel does not keep a session another page ended.
75
+ */
76
+ export function createTokenStore(chrome, initial, onExternalChange) {
77
+ let memory = initial;
78
+ chrome.storage.onChanged?.addListener((changes, area) => {
79
+ if (area !== "local" || !(SESSION_KEY in changes))
80
+ return;
81
+ const next = typeof changes[SESSION_KEY].newValue === "string" && changes[SESSION_KEY].newValue ? changes[SESSION_KEY].newValue : null;
82
+ if (next === memory)
83
+ return;
84
+ memory = next;
85
+ onExternalChange?.(next);
86
+ });
87
+ return {
88
+ get: () => memory,
89
+ set(token) {
90
+ memory = token;
91
+ const write = token ? chrome.storage.local.set({ [SESSION_KEY]: token }) : chrome.storage.local.remove(SESSION_KEY);
92
+ // Best effort: the in-memory token still works for this page if storage is unavailable.
93
+ void Promise.resolve(write).catch(() => undefined);
94
+ },
95
+ };
96
+ }
97
+ /** Asks the instance who it is (`GET /api/session`), with no credential. It must serve the extension's application. */
98
+ export async function verifyInstance(origin, expectedApplication, fetchImpl = fetch) {
99
+ let response;
100
+ try {
101
+ response = await fetchImpl(`${origin}/api/session`, { credentials: "omit", cache: "no-store", signal: AbortSignal.timeout(10_000), headers: { accept: "application/json" } });
102
+ }
103
+ catch {
104
+ throw new ConnectionError(`Could not reach ${origin}. Check the address, that the instance is running, and that this browser allowed access to it.`, "instance");
105
+ }
106
+ const body = await response.json().then((value) => (value && typeof value === "object" ? value : null), () => null);
107
+ if (!response.ok || !body || typeof body.application !== "string")
108
+ throw new ConnectionError(`${origin} did not answer like a FeltKit instance (GET /api/session).`, "instance");
109
+ if (expectedApplication && body.application !== expectedApplication) {
110
+ throw new ConnectionError(`${origin} serves "${body.application}", but this extension is for "${expectedApplication}".`, "application");
111
+ }
112
+ return { application: body.application, principal: body.principal && typeof body.principal.id === "string" ? body.principal : null };
113
+ }
114
+ /** Whether a session token is live on the instance (`GET /api/session` as that bearer). */
115
+ export async function verifyToken(origin, token, fetchImpl = fetch) {
116
+ let response;
117
+ try {
118
+ response = await fetchImpl(`${origin}/api/session`, { credentials: "omit", cache: "no-store", signal: AbortSignal.timeout(10_000), headers: { accept: "application/json", authorization: `Bearer ${token}` } });
119
+ }
120
+ catch {
121
+ throw new ConnectionError(`Could not reach ${origin} to check the session.`, "instance");
122
+ }
123
+ const body = (await response.json().catch(() => null));
124
+ const principal = body?.principal && typeof body.principal.id === "string" ? { id: body.principal.id } : null;
125
+ if (!principal)
126
+ throw new ConnectionError("That session is not valid on this instance (expired, revoked, or for another instance).", "session");
127
+ return principal;
128
+ }
129
+ export async function hasHostPermission(chrome, origin) {
130
+ if (!chrome.permissions)
131
+ return true;
132
+ try {
133
+ return await chrome.permissions.contains({ origins: [originPattern(origin)] });
134
+ }
135
+ catch {
136
+ return false;
137
+ }
138
+ }
139
+ /**
140
+ * Connects to an instance. Call it from the click that submits the form: `chrome.permissions.request` needs the
141
+ * user gesture, so the address is checked synchronously and the request is the first asynchronous step.
142
+ */
143
+ export function connect(chrome, options) {
144
+ let origin;
145
+ try {
146
+ origin = normalizeInstance(options.instance);
147
+ }
148
+ catch (error) {
149
+ return Promise.reject(error);
150
+ }
151
+ const permission = chrome.permissions ? chrome.permissions.request({ origins: [originPattern(origin)] }) : Promise.resolve(true);
152
+ return (async () => {
153
+ let granted = false;
154
+ try {
155
+ granted = await permission;
156
+ }
157
+ catch {
158
+ granted = false;
159
+ }
160
+ if (!granted)
161
+ throw new ConnectionError(`Access to ${origin} was not allowed. The extension needs it to talk to your instance, and to nothing else.`, "permission");
162
+ const info = await verifyInstance(origin, options.expectedApplication, options.fetch);
163
+ const token = options.token?.trim() || undefined;
164
+ let principal = info.principal;
165
+ if (token)
166
+ principal = await verifyToken(origin, token, options.fetch);
167
+ await chrome.storage.local.set({ [INSTANCE_KEY]: origin, ...(token ? { [SESSION_KEY]: token } : {}) });
168
+ if (!token)
169
+ await chrome.storage.local.remove(SESSION_KEY);
170
+ return { instance: origin, ...(token ? { token } : {}), info: { ...info, principal } };
171
+ })();
172
+ }
173
+ /**
174
+ * Ends the session and forgets the instance (`keepInstance`: only the session). The session is revoked on the
175
+ * instance first (best effort: an unreachable instance must not keep a person signed in here), then the keys go.
176
+ */
177
+ export async function disconnect(chrome, fetchImpl = fetch, options = {}) {
178
+ const current = await readConnection(chrome);
179
+ if (current.instance && current.token) {
180
+ try {
181
+ await fetchImpl(`${current.instance}/api/auth/signout`, { method: "POST", credentials: "omit", headers: { authorization: `Bearer ${current.token}`, "content-type": "application/json" }, body: "{}", signal: AbortSignal.timeout(5_000) });
182
+ }
183
+ catch {
184
+ /* the local session is dropped regardless */
185
+ }
186
+ }
187
+ // A build with its instance baked in has only that one: signing out keeps it (removing it would reload every open page).
188
+ await chrome.storage.local.remove(options.keepInstance ? [SESSION_KEY] : [INSTANCE_KEY, SESSION_KEY]);
189
+ }
190
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/extension/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,uGAAuG;AACvG,MAAM,CAAC,MAAM,YAAY,GAAG,4BAA4B,CAAC;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAyBvD,mFAAmF;AACnF,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACF,IAAI;IAA1C,YAAY,OAAe,EAAW,IAAuE;QAC3G,KAAK,CAAC,OAAO,CAAC,CAAC;oBADqB,IAAI;QAExC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9D;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CA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,CAAC;IACzF,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAkB,EAAE,SAAS,GAAc,KAAK,EAAE,OAAO,GAA+B,EAAE;IACzH,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,GAAG,OAAO,CAAC,QAAQ,mBAAmB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC9O,CAAC;QAAC,MAAM,CAAC;YACP,6CAA6C;QAC/C,CAAC;IACH,CAAC;IACD,yHAAyH;IACzH,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AACxG,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The host of an app running in a generated extension page: reads the stored connection (or shows the connect
3
+ * screen), then publishes what `createClient()` defaults to inside the extension (`url`, a bearer token store).
4
+ * `host.ts` runs it before the app's own entry module evaluates, so the unmodified app code finds a connected
5
+ * client.
6
+ */
7
+ import { type ChromeLike, type FetchLike, type TokenStoreLike } from "./connection.js";
8
+ import { showConnectScreen } from "./connect-ui.js";
9
+ /** Written into the bundle at build time (by `feltkit target:browser-extension`). */
10
+ export interface ExtensionConfig {
11
+ /** The application the extension carries: an instance serving another is refused. */
12
+ application: string;
13
+ /** The title shown on the connect screen. */
14
+ title: string;
15
+ /** An instance baked into the build (`--instance`): the only one this extension talks to. */
16
+ instance: string | null;
17
+ }
18
+ /** What the extension publishes for `createClient()`. */
19
+ export interface ExtensionHost {
20
+ url: string;
21
+ tokens: TokenStoreLike;
22
+ application: string;
23
+ }
24
+ declare global {
25
+ var __feltkitExtension: ExtensionHost | undefined;
26
+ }
27
+ export interface HostDependencies {
28
+ chrome?: ChromeLike;
29
+ fetch?: FetchLike;
30
+ /** Reload the page: the instance changed in another page. */
31
+ reload?: () => void;
32
+ /** The connect screen (replaceable in tests, which have no DOM). */
33
+ connectScreen?: typeof showConnectScreen;
34
+ }
35
+ /** Connects (showing the connect screen if there is no usable connection) and returns the host. */
36
+ export declare function startHost(config: ExtensionConfig, dependencies?: HostDependencies): Promise<ExtensionHost>;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The host of an app running in a generated extension page: reads the stored connection (or shows the connect
3
+ * screen), then publishes what `createClient()` defaults to inside the extension (`url`, a bearer token store).
4
+ * `host.ts` runs it before the app's own entry module evaluates, so the unmodified app code finds a connected
5
+ * client.
6
+ */
7
+ import { createTokenStore, hasHostPermission, INSTANCE_KEY, lockStorage, readConnection, } from "./connection.js";
8
+ import { showConnectScreen } from "./connect-ui.js";
9
+ /** Connects (showing the connect screen if there is no usable connection) and returns the host. */
10
+ export async function startHost(config, dependencies = {}) {
11
+ const chrome = dependencies.chrome ?? globalThis.chrome;
12
+ if (!chrome?.storage?.local)
13
+ throw new Error("This page must run as a browser extension page (chrome.storage is not available).");
14
+ await lockStorage(chrome);
15
+ const stored = await readConnection(chrome);
16
+ let instance = config.instance ?? stored.instance;
17
+ let token = config.instance && stored.instance && stored.instance !== config.instance ? undefined : stored.token;
18
+ let notice;
19
+ if (instance && !(await hasHostPermission(chrome, instance))) {
20
+ notice = `Access to ${instance} is no longer allowed. Connect again to allow it.`;
21
+ instance = undefined;
22
+ }
23
+ if (!instance) {
24
+ const connection = await (dependencies.connectScreen ?? showConnectScreen)({
25
+ chrome,
26
+ application: config.application,
27
+ title: config.title,
28
+ ...(config.instance ?? stored.instance ? { instance: (config.instance ?? stored.instance) } : {}),
29
+ ...(notice ? { notice } : {}),
30
+ ...(dependencies.fetch ? { fetch: dependencies.fetch } : {}),
31
+ });
32
+ instance = connection.instance;
33
+ token = connection.token;
34
+ }
35
+ else if (config.instance && stored.instance !== config.instance) {
36
+ // A baked instance is the one this build talks to: record it (its host permission was granted at install).
37
+ await chrome.storage.local.set({ [INSTANCE_KEY]: config.instance });
38
+ }
39
+ const reload = dependencies.reload ?? (() => globalThis.location?.reload());
40
+ // A session ended in another page is ended here too; the instance changing means this page's app is stale.
41
+ chrome.storage.onChanged?.addListener((changes, area) => {
42
+ if (area === "local" && INSTANCE_KEY in changes && changes[INSTANCE_KEY].newValue !== instance)
43
+ reload();
44
+ });
45
+ const tokens = createTokenStore(chrome, token ?? null);
46
+ const host = { url: instance, tokens, application: config.application };
47
+ globalThis.__feltkitExtension = host;
48
+ return host;
49
+ }
50
+ //# sourceMappingURL=host-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-core.js","sourceRoot":"","sources":["../../src/extension/host-core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,cAAc,GAIf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAiCpD,mGAAmG;AACnG,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAuB,EAAE,YAAY,GAAqB,EAAE;IAC1F,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,IAAK,UAAiD,CAAC,MAAM,CAAC;IAChG,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;IAClI,MAAM,WAAW,CAAC,MAAM,C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,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAC3B,CAAC;SAAM,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClE,2GAA2G;QAC3G,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5E,2GAA2G;IAC3G,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;QACtD,IAAI,IAAI,KAAK,OAAO,IAAI,YAAY,IAAI,OAAO,IAAI,OAAO,CAAC,YAAY,CAAE,CAAC,QAAQ,KAAK,QAAQ;YAAE,MAAM,EAAE,CAAC;IAC5G,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;IACvD,MAAM,IAAI,GAAkB,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;IACvF,UAAU,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACrC,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The entry the build puts in front of the app's own entry module (`feltkit target:browser-extension`): its
3
+ * top-level `await` holds the app's module graph until an instance is connected, so every `createClient()` in the
4
+ * app finds `globalThis.__feltkitExtension`.
5
+ */
6
+ import { startHost } from "./host-core.js";
7
+ await startHost(__FELTKIT_EXTENSION__);
8
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/extension/host.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AAKjE,MAAM,SAAS,CAAC,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare const isPng: (bytes: Uint8Array) => boolean;
2
+ /** The pixel size of a PNG (its IHDR), or null. */
3
+ export declare function pngSize(bytes: Uint8Array): {
4
+ width: number;
5
+ height: number;
6
+ } | null;
7
+ /** A rounded-corner square in `rgb`, with a lighter inner square: recognisable at 16 px, valid at any size. */
8
+ export declare function generatedIcon(size: number, rgb?: [number, number, number]): Buffer;
9
+ /** The icon bytes for the extension: `--icon`, else a project PNG, else a generated one. */
10
+ export declare function chooseIcon(projectDir: string, explicit?: string): {
11
+ bytes: Buffer;
12
+ source: string;
13
+ };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Icons for the manifest. The project's own PNG is used when it has one; otherwise a plain square in the
3
+ * extension's colour is generated, so every build has the icons Chrome wants. No image library: a PNG is a
4
+ * signature and a few CRC-ed chunks.
5
+ */
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { deflateSync } from "node:zlib";
9
+ import { crc32 } from "./zip.js";
10
+ const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
11
+ export const isPng = (bytes) => bytes.length > 24 && SIGNATURE.equals(Buffer.from(bytes.subarray(0, 8)));
12
+ /** The pixel size of a PNG (its IHDR), or null. */
13
+ export function pngSize(bytes) {
14
+ if (!isPng(bytes))
15
+ return null;
16
+ const buffer = Buffer.from(bytes.subarray(0, 24));
17
+ return { width: buffer.readUInt32BE(16), height: buffer.readUInt32BE(20) };
18
+ }
19
+ function chunk(type, data) {
20
+ const head = Buffer.alloc(8);
21
+ head.writeUInt32BE(data.length, 0);
22
+ head.write(type, 4, "ascii");
23
+ const tail = Buffer.alloc(4);
24
+ tail.writeUInt32BE(crc32(Buffer.concat([head.subarray(4), data])), 0);
25
+ return Buffer.concat([head, data, tail]);
26
+ }
27
+ /** A rounded-corner square in `rgb`, with a lighter inner square: recognisable at 16 px, valid at any size. */
28
+ export function generatedIcon(size, rgb = [0x2f, 0x5d, 0x50]) {
29
+ const rowLength = size * 4 + 1;
30
+ const raw = Buffer.alloc(rowLength * size);
31
+ const radius = Math.max(2, Math.round(size / 5));
32
+ const inner = [Math.round(size * 0.3), Math.round(size * 0.7)];
33
+ for (let y = 0; y < size; y++) {
34
+ raw[y * rowLength] = 0;
35
+ for (let x = 0; x < size; x++) {
36
+ const dx = Math.max(radius - x, x - (size - 1 - radius), 0);
37
+ const dy = Math.max(radius - y, y - (size - 1 - radius), 0);
38
+ const inside = dx * dx + dy * dy <= radius * radius;
39
+ const mark = x >= inner[0] && x < inner[1] && y >= inner[0] && y < inner[1];
40
+ const at = y * rowLength + 1 + x * 4;
41
+ const [r, g, b] = mark ? [255, 255, 255] : rgb;
42
+ raw[at] = r;
43
+ raw[at + 1] = g;
44
+ raw[at + 2] = b;
45
+ raw[at + 3] = inside ? 255 : 0;
46
+ }
47
+ }
48
+ const header = Buffer.alloc(13);
49
+ header.writeUInt32BE(size, 0);
50
+ header.writeUInt32BE(size, 4);
51
+ header[8] = 8; // bit depth
52
+ header[9] = 6; // RGBA
53
+ return Buffer.concat([SIGNATURE, chunk("IHDR", header), chunk("IDAT", deflateSync(raw)), chunk("IEND", Buffer.alloc(0))]);
54
+ }
55
+ /** Where a project keeps an icon, in order of preference. */
56
+ const CANDIDATES = ["extension/icon.png", "public/icon.png", "public/icon-128.png", "public/apple-touch-icon.png", "public/feltkit-mark.png", "public/favicon.png"];
57
+ /** The icon bytes for the extension: `--icon`, else a project PNG, else a generated one. */
58
+ export function chooseIcon(projectDir, explicit) {
59
+ if (explicit) {
60
+ const bytes = readFileSync(explicit);
61
+ if (!isPng(bytes))
62
+ throw new Error(`${explicit} is not a PNG.`);
63
+ return { bytes, source: explicit };
64
+ }
65
+ for (const candidate of CANDIDATES) {
66
+ const file = join(projectDir, candidate);
67
+ if (!existsSync(file))
68
+ continue;
69
+ const bytes = readFileSync(file);
70
+ if (isPng(bytes))
71
+ return { bytes, source: candidate };
72
+ }
73
+ return { bytes: generatedIcon(128), source: "generated" };
74
+ }
75
+ //# sourceMappingURL=icons.js.map