@kubohiroya/turbowarp-extension-security-dialog 0.10.0 → 0.12.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.
Files changed (44) hide show
  1. package/NOTICE.md +4 -2
  2. package/README.ja.md +22 -0
  3. package/README.md +19 -1
  4. package/dist/build-info.json +2 -2
  5. package/dist/catalog-library.cjs +113 -26
  6. package/dist/catalog-library.mjs +113 -26
  7. package/dist/catalog-preview.d.ts +9 -0
  8. package/dist/catalog-resources.d.ts +4 -0
  9. package/dist/extension-row.d.ts +3 -1
  10. package/dist/gallery-preview.d.ts +2 -0
  11. package/dist/index.cjs +236 -39
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.mjs +236 -39
  14. package/dist/permission-ui.cjs +4 -2
  15. package/dist/permission-ui.mjs +4 -2
  16. package/dist/preview.d.ts +1 -0
  17. package/dist/project-review.cjs +273 -21
  18. package/dist/project-review.d.ts +3 -1
  19. package/dist/project-review.mjs +273 -21
  20. package/dist/react.cjs +327 -103
  21. package/dist/react.d.ts +3 -0
  22. package/dist/react.mjs +327 -103
  23. package/dist/resources.d.ts +7 -0
  24. package/dist/review-types.d.ts +5 -0
  25. package/dist/review.d.ts +1 -1
  26. package/package.json +4 -1
  27. package/src/catalog-library.tsx +1 -1
  28. package/src/catalog-preview.ts +27 -0
  29. package/src/catalog-resources.ts +34 -0
  30. package/src/catalog.ts +3 -0
  31. package/src/extension-row.tsx +10 -4
  32. package/src/gallery-preview.ts +58 -0
  33. package/src/index.ts +4 -0
  34. package/src/messages.ts +4 -2
  35. package/src/metadata.ts +1 -1
  36. package/src/preview.tsx +12 -5
  37. package/src/project-review.tsx +20 -7
  38. package/src/react.tsx +3 -0
  39. package/src/resources.tsx +47 -0
  40. package/src/review-types.ts +6 -0
  41. package/src/review.css +41 -9
  42. package/src/review.tsx +42 -22
  43. package/styles.css +41 -9
  44. package/webpack4.css +41 -9
package/NOTICE.md CHANGED
@@ -8,14 +8,16 @@ notice, so this code can be combined into a larger work distributed under GPL-3.
8
8
  the TurboWarp-Plus Editor ships it.
9
9
 
10
10
  `assets/common.svg` is the fallback icon shown when an extension has no preview of its own. It is
11
- original to this package: a jigsaw piece outline with a serif T, drawn for it and derived from no
11
+ original to this package: white code brackets on a gray square, drawn for it and derived from no
12
12
  other work. `scripts/build.ts` embeds it into `dist` as a base64 data URI, so it travels in the
13
13
  published package.
14
14
 
15
- `assets/trusted.svg` is the mark beside an extension the host trusts: the TurboWarp Plus mark (the
15
+ `assets/trusted.svg` is the mark beside a host-confirmed TurboWarp Plus family extension: the TurboWarp Plus mark (the
16
16
  hat block with a warp swirl and a plus sign, drawn by the same author for the TurboWarp-Plus Editor)
17
17
  with a green check over it. It is embedded into `dist` the same way.
18
18
 
19
+ `assets/host-trusted.svg` is an original, unbranded check mark for other extensions trusted by the host.
20
+
19
21
  ## JavaScript parsing
20
22
 
21
23
  The review bundles Acorn and Acorn Walk to read extension names without executing the source.
package/README.ja.md CHANGED
@@ -145,6 +145,20 @@ HTTP(S)のソースから説明を読み取り、相対バナーURLは取得後
145
145
  サンドボックスなしを適用します。すべての行が信頼済みの作品では、ホストは `requiresReview` で確認を
146
146
  省略できます。
147
147
 
148
+ 実行の信頼とファミリー所属は別です。ホストが Plus カタログとの照合で
149
+ `entry.state.plusFamily` も指定した行だけに Plus マークを表示します。それ以外の信頼済みの行は、
150
+ ブランドを含まないチェックで示します。`ExtensionRow` 単体では `plusFamily` プロパティで指定します。
151
+ 拡張が自称するメタデータや、ID の一致だけでは所属を決めません。
152
+
153
+ TurboWarp ギャラリーの拡張は、公式メタデータとコードの完全な URL を照合して画像を取得します。
154
+ 画像取得とソースの説明取得は並行して進み、操作や実行許可を待たせません。
155
+ 画像がない場合や表示に失敗した場合は、ブランドを含まない汎用アイコンへ戻します。
156
+
157
+ ギャラリーのバナーは180×90pxで表示し、それ以外の拡張も同じ高さ90pxの枠に揃えます。バナーレイアウトのないファミリー拡張は、
158
+ カタログが選んだブロックSVGを縦横比を保って枠内いっぱいに中央表示します。
159
+ 作品を開く場合も、URLと固定ハッシュを照合してカタログ画像を取得します。
160
+ 狭幅では説明を画像の上下に配置し、枠を画面幅に合わせて縮小します。
161
+
148
162
  **記録された答えは、いまも選択肢である場合だけ尊重します。** 作品が `remote-cacheable` から
149
163
  埋め込みに変わった、行が信頼済みになった、といった場合に、もう提示しない答えを持ち込みません。
150
164
 
@@ -295,3 +309,11 @@ npmが固定したGitHubアーカイブを`.git`なしでビルドする場合
295
309
 
296
310
  Editor 独自実装の移管元とライセンス確認は [EDITOR-MIGRATION.md](EDITOR-MIGRATION.md) に記録しています。
297
311
  追加した公開 API は GUI モジュールを import せず、ホストから必要な値・データ・コールバックを受け取ります。
312
+
313
+ ## リソース利用の宣言
314
+
315
+ カタログの `resourceDeclaration` は既存manifestパッケージの共通契約(0.6.0以降)に従います。追加画面と作品を開く確認画面の共通行に、独自SVG・可視ラベル・条件・用途・連携先・通信方向と内容を表示します。未申告と確認済み空配列は別の表示です。宣言から実行許可・ブラウザ権限を付与しません。
316
+
317
+ 有効化確認では、質問前にカタログのIDと正確なURL/ハッシュで対象を照合します。同梱形式・従来のdata URLもハッシュで照合します。作品内のパッケージ名や宣言だけでは他の版の申告を借用できません。取得不能時は不明として拒否・キャンセルを維持します。既存のホスト接続口を使うためScratch GUIの変更は不要です。表示を戻す場合は0.11.0と従来依存へ戻します。
318
+
319
+ 通常時はアイコンだけの縮約表示です。アイコン列のクリック、またはEnter/Spaceキーで、ラベルと説明を展開・縮約できます。縮約時もスクリーンリーダー向けの名称を保持します。
package/README.md CHANGED
@@ -129,7 +129,12 @@ scrolls independently of Cancel and Add. Dismissing the unsandboxed notice prese
129
129
  and returns focus to the control that opened it.
130
130
 
131
131
  Individual review keeps its top action visibly selected and disabled. Rows use the host's icon or
132
- the source's declared banner; the common icon is only for rows without a picture declaration.
132
+ the source's declared banner. Gallery images are resolved against the official catalog by the
133
+ full extension URL, independently of source metadata loading. Missing or broken pictures use
134
+ an unbranded common icon. Picture loading never grants execution permission.
135
+ Gallery banners use a 180 by 90 area, with other extension previews sharing its 90px height. Square family block SVGs fill its height and
136
+ stay centered without distortion. Opening a project can resolve the same catalog artwork by
137
+ its URL and pinned digest. Narrow screens stack the description and preview and scale the area to fit.
133
138
  Display metadata can be read from HTTP(S), and relative banners resolve against the final source URL.
134
139
  When CORS prevents caching an image, it can still be displayed directly by the browser.
135
140
 
@@ -138,6 +143,11 @@ GitHub versions link to their release notes. The description preserves line brea
138
143
  HTTP(S) URLs and email addresses into links. The creator's contact appears next to their name
139
144
  when supplied.
140
145
 
146
+ Execution trust and family membership are separate: only rows with host-confirmed
147
+ `entry.state.plusFamily` use the Plus mark. Other trusted rows use an unbranded check.
148
+ For a standalone `ExtensionRow`, pass `plusFamily` explicitly after checking the host's Plus
149
+ catalog. Extension-declared metadata and matching IDs alone do not establish membership.
150
+
141
151
  ### Using one row of the list
142
152
 
143
153
  `ExtensionRow` draws the same row the screen draws for each extension: its name (with a checkbox, if it can be chosen), IDs, trusted mark, version with a link to its release notes, picture, description, and creator with contact. Another screen that lists extensions shows them the same way. In TurboWarp Plus Editor, the screen that chooses which block palette groups to show uses it.
@@ -287,3 +297,11 @@ dependencies.
287
297
  The design record of the MPL-2.0 rewrite in 0.6.0 is in [the rewrite design (Japanese)](docs/mpl-rewrite.ja.md).
288
298
 
289
299
  When npm prepares a pinned GitHub archive without `.git`, the installer must pass its locked full SHA as `TWEXTSEC_SOURCE_REVISION`. The build records `sourceState: "git-archive"` and fails without a full SHA; the host verifies it against its manifest and lockfile.
300
+
301
+ ## Resource declarations
302
+
303
+ Catalog metadata may contain `resourceDeclaration`, following `@kubohiroya/turbowarp-extension-manifest/resources` 0.6.0. The add screen and project-open review use the same `ExtensionRow` disclosure: original SVG icons, visible localized labels, conditional use, purposes, providers and network direction/content. Missing declarations and explicit empty lists have distinct labels. The optional field is display-only and does not grant execution or browser permission.
304
+
305
+ The project-review port resolves declarations before asking. A declaration belongs to a catalog ID and exact URL/digest; embedded and legacy inline code are matched by digest. A project-supplied package name or declaration cannot borrow another version's claim. An unavailable catalog leaves the declaration unknown and does not block denial/cancellation. Existing host integration ports suffice; Scratch GUI code is unchanged. Roll back to 0.11.0 and the previous dependencies to remove the display.
306
+
307
+ Resource disclosures show only icons by default. Click the icon row or press Enter/Space to expand or collapse the labels and details. Accessible names remain available while collapsed.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-extension-security-dialog",
3
- "version": "0.10.0",
4
- "revision": "16e33970faded894c6b2a41b4f5f8a40a73c1c57",
3
+ "version": "0.12.0",
4
+ "revision": "7ba9737064d35eeddc4d05815c6de8fc9268810b",
5
5
  "sourceState": "commit"
6
6
  }
@@ -53,6 +53,91 @@ __export(catalog_library_exports, {
53
53
  module.exports = __toCommonJS(catalog_library_exports);
54
54
  var import_react = require("@kubohiroya/turbowarp-extension-security-dialog/react");
55
55
 
56
+ // node_modules/.pnpm/@kubohiroya+turbowarp-extension-manifest@0.6.0/node_modules/@kubohiroya/turbowarp-extension-manifest/dist/resources.js
57
+ var RESOURCE_TYPES = [
58
+ "camera",
59
+ "microphone",
60
+ "network",
61
+ "bluetooth",
62
+ "usb",
63
+ "storage",
64
+ "files",
65
+ "audio-output"
66
+ ];
67
+ function fail(message) {
68
+ throw new TypeError(`Resource declaration: ${message}`);
69
+ }
70
+ function record(value, label, keys) {
71
+ if (!value || typeof value !== "object" || Array.isArray(value))
72
+ fail(`${label} must be an object`);
73
+ const result = value;
74
+ if (keys && Object.keys(result).some((key) => !keys.includes(key)))
75
+ fail(`${label} has an unknown field`);
76
+ return result;
77
+ }
78
+ function text(value, label) {
79
+ const source = record(value, label);
80
+ if (!Object.hasOwn(source, "en") || Object.keys(source).length > 12)
81
+ fail(`${label} requires English text`);
82
+ const result = {};
83
+ for (const [locale, value2] of Object.entries(source)) {
84
+ if (!/^[a-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(locale) || typeof value2 !== "string" || !value2.trim() || value2.length > 1e3 || [...value2].length > 500)
85
+ fail(`${label} must contain bounded localized text`);
86
+ result[locale] = value2;
87
+ }
88
+ return Object.freeze(result);
89
+ }
90
+ function parseResourceDeclaration(value) {
91
+ if (value === void 0)
92
+ return void 0;
93
+ const source = record(value, "declaration", ["schemaVersion", "resources"]);
94
+ if (source["schemaVersion"] !== 1)
95
+ fail("unsupported schemaVersion");
96
+ const list = source["resources"];
97
+ if (!Array.isArray(list) || list.length > RESOURCE_TYPES.length)
98
+ fail("resources must be a bounded list");
99
+ const seen = /* @__PURE__ */ new Set();
100
+ const resources = list.map((value2) => {
101
+ const item = record(value2, "resource", ["type", "usage", "purpose", "condition", "access", "via", "data"]);
102
+ const type = item["type"];
103
+ if (!RESOURCE_TYPES.includes(type) || seen.has(type))
104
+ fail("unknown or duplicate resource type");
105
+ seen.add(type);
106
+ const usage = item["usage"];
107
+ if (usage !== "required" && usage !== "conditional")
108
+ fail("usage must be required or conditional");
109
+ const result = { type, usage, purpose: text(item["purpose"], "purpose") };
110
+ if (item["condition"] !== void 0)
111
+ result.condition = text(item["condition"], "condition");
112
+ if (usage === "conditional" && !result.condition)
113
+ fail("conditional use requires a condition");
114
+ if (item["access"] !== void 0) {
115
+ if (item["access"] !== "use" && item["access"] !== "permission-request")
116
+ fail("invalid access");
117
+ result.access = item["access"];
118
+ }
119
+ if (item["via"] !== void 0) {
120
+ const via = item["via"];
121
+ if (!Array.isArray(via) || via.length === 0 || via.length > 8 || new Set(via).size !== via.length || via.some((name) => typeof name !== "string" || name.length > 214 || !/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name)))
122
+ fail("invalid via packages");
123
+ result.via = Object.freeze([...via]);
124
+ }
125
+ if (item["data"] !== void 0) {
126
+ if (type !== "network")
127
+ fail("data is only valid for network");
128
+ const data = record(item["data"], "data", ["direction", "content"]);
129
+ const direction = data["direction"];
130
+ if (direction !== "download" && direction !== "upload" && direction !== "bidirectional")
131
+ fail("invalid data direction");
132
+ result.data = Object.freeze({ direction, content: text(data["content"], "data content") });
133
+ }
134
+ if (type === "network" && !result.data)
135
+ fail("network requires data direction and content");
136
+ return Object.freeze(result);
137
+ });
138
+ return Object.freeze({ schemaVersion: 1, resources: Object.freeze(resources) });
139
+ }
140
+
56
141
  // src/display-urls.ts
57
142
  var displayURL = (value, allowMail = false) => {
58
143
  if (typeof value !== "string" || !value || /[\u0000-\u0020\u007f]/.test(value)) return null;
@@ -75,34 +160,36 @@ var contactURL = (value) => {
75
160
 
76
161
  // src/catalog.ts
77
162
  var ID = /^[A-Za-z0-9]+$/;
78
- function fail(message) {
163
+ function fail2(message) {
79
164
  throw new Error(message);
80
165
  }
81
166
  var object = (value, what) => {
82
- if (value === null || typeof value !== "object" || Array.isArray(value)) fail(`${what} must be an object`);
167
+ if (value === null || typeof value !== "object" || Array.isArray(value)) fail2(`${what} must be an object`);
83
168
  return value;
84
169
  };
85
170
  var string = (value, what, limit = 2048) => {
86
- if (typeof value !== "string" || value.length === 0 || value.length > limit) fail(`${what} must be text`);
171
+ if (typeof value !== "string" || value.length === 0 || value.length > limit) fail2(`${what} must be text`);
87
172
  return value;
88
173
  };
89
174
  var reviewURL = (value, what = "URL", allowHTTP = false) => {
90
- const text2 = string(value, what);
175
+ const text3 = string(value, what);
91
176
  let url;
92
177
  try {
93
- url = new URL(text2);
178
+ url = new URL(text3);
94
179
  } catch (error) {
95
- fail(`${what} must be an absolute URL`);
180
+ fail2(`${what} must be an absolute URL`);
96
181
  }
97
182
  const schemes = allowHTTP ? ["https:", "http:"] : ["https:"];
98
183
  if (!schemes.includes(url.protocol) || url.username || url.password || url.hash) {
99
- fail(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
184
+ fail2(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
100
185
  }
101
- return text2;
186
+ return text3;
102
187
  };
103
188
  var metadataOf = (value) => {
104
189
  const source = object(value, "metadata");
105
190
  const result = {};
191
+ const resources = parseResourceDeclaration(source.resourceDeclaration);
192
+ if (resources !== void 0) result.resourceDeclaration = resources;
106
193
  for (const key of [
107
194
  "name",
108
195
  "id",
@@ -124,21 +211,21 @@ var metadataOf = (value) => {
124
211
  if (source.descriptions !== void 0) {
125
212
  const descriptions = object(source.descriptions, "descriptions");
126
213
  result.descriptions = {};
127
- for (const [tag, text2] of Object.entries(descriptions)) {
128
- if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag)) fail("descriptions keys must be language tags");
129
- result.descriptions[tag] = string(text2, "description", 4096);
214
+ for (const [tag, text3] of Object.entries(descriptions)) {
215
+ if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag)) fail2("descriptions keys must be language tags");
216
+ result.descriptions[tag] = string(text3, "description", 4096);
130
217
  }
131
218
  }
132
219
  return result;
133
220
  };
134
221
  var categoriesOf = (value) => {
135
222
  const list = value === void 0 ? [] : value;
136
- if (!Array.isArray(list)) fail("categories must be a list");
223
+ if (!Array.isArray(list)) fail2("categories must be a list");
137
224
  const byId = /* @__PURE__ */ new Map();
138
225
  list.forEach((item, order) => {
139
226
  const category = object(item, "category");
140
227
  const id = string(category.id, "category id", 128);
141
- if (byId.has(id)) fail(`Duplicate category ${id}`);
228
+ if (byId.has(id)) fail2(`Duplicate category ${id}`);
142
229
  const resolved = { id, title: string(category.title, "category title", 256), order };
143
230
  if (category.titleJa !== void 0) resolved.titleJa = string(category.titleJa, "category titleJa", 256);
144
231
  byId.set(id, Object.freeze(resolved));
@@ -148,23 +235,23 @@ var categoriesOf = (value) => {
148
235
  function parseExtensionCatalog(data) {
149
236
  const document = object(data, "catalog");
150
237
  if (document.schemaVersion !== void 0 && document.schemaVersion !== 1) {
151
- fail(`Unsupported catalog schema ${document.schemaVersion}`);
238
+ fail2(`Unsupported catalog schema ${document.schemaVersion}`);
152
239
  }
153
240
  const categories = categoriesOf(document.categories);
154
241
  const list = document.extensions;
155
- if (!Array.isArray(list)) fail("catalog extensions must be a list");
242
+ if (!Array.isArray(list)) fail2("catalog extensions must be a list");
156
243
  const byId = /* @__PURE__ */ new Map();
157
244
  const urls = /* @__PURE__ */ new Set();
158
245
  const entries = list.map((item) => {
159
246
  const source = object(item, "extension");
160
247
  const id = string(source.id, "extension id", 128);
161
- if (!ID.test(id)) fail(`Invalid extension id ${id}`);
162
- if (byId.has(id)) fail(`Duplicate extension ${id}`);
248
+ if (!ID.test(id)) fail2(`Invalid extension id ${id}`);
249
+ if (byId.has(id)) fail2(`Duplicate extension ${id}`);
163
250
  const url = reviewURL(source.url, `${id} url`);
164
- if (urls.has(url)) fail(`Duplicate extension URL ${url}`);
251
+ if (urls.has(url)) fail2(`Duplicate extension URL ${url}`);
165
252
  urls.add(url);
166
253
  const dependencies = source.dependencies === void 0 ? [] : source.dependencies;
167
- if (!Array.isArray(dependencies)) fail(`${id} dependencies must be a list`);
254
+ if (!Array.isArray(dependencies)) fail2(`${id} dependencies must be a list`);
168
255
  const entry = {
169
256
  key: id,
170
257
  id,
@@ -177,11 +264,11 @@ function parseExtensionCatalog(data) {
177
264
  };
178
265
  if (source.sha256 !== void 0) {
179
266
  entry.sha256 = string(source.sha256, "sha256", 64);
180
- if (!/^[0-9a-f]{64}$/.test(entry.sha256)) fail(`Invalid sha256 for ${id}`);
267
+ if (!/^[0-9a-f]{64}$/.test(entry.sha256)) fail2(`Invalid sha256 for ${id}`);
181
268
  }
182
269
  if (source.category !== void 0) {
183
270
  const category = string(source.category, "category", 128);
184
- if (!categories.has(category)) fail(`Unknown category ${category}`);
271
+ if (!categories.has(category)) fail2(`Unknown category ${category}`);
185
272
  entry.category = categories.get(category);
186
273
  }
187
274
  byId.set(id, entry);
@@ -189,14 +276,14 @@ function parseExtensionCatalog(data) {
189
276
  });
190
277
  for (const entry of entries) {
191
278
  for (const dependency of entry.dependencies) {
192
- if (!byId.has(dependency)) fail(`${entry.id} depends on missing ${dependency}`);
279
+ if (!byId.has(dependency)) fail2(`${entry.id} depends on missing ${dependency}`);
193
280
  }
194
281
  }
195
282
  const state = /* @__PURE__ */ new Map();
196
283
  const walk = (id) => {
197
284
  const mark = state.get(id);
198
285
  if (mark === "done") return;
199
- if (mark === "open") fail(`Dependency cycle at ${id}`);
286
+ if (mark === "open") fail2(`Dependency cycle at ${id}`);
200
287
  state.set(id, "open");
201
288
  for (const dependency of byId.get(id).dependencies) walk(dependency);
202
289
  state.set(id, "done");
@@ -207,7 +294,7 @@ function parseExtensionCatalog(data) {
207
294
 
208
295
  // src/catalog-library.tsx
209
296
  var import_react2 = __toESM(require("react"), 1);
210
- var text = {
297
+ var text2 = {
211
298
  en: {
212
299
  loading: "Loading TurboWarp Plus extensions\u2026",
213
300
  failed: "The extension catalog could not be loaded.",
@@ -227,7 +314,7 @@ var reviewRows = (entries, vm, loader = true) => entries.map((entry) => ({
227
314
  metadata: entry.metadata,
228
315
  source: { kind: loader ? "catalog" : "legacy", url: entry.url },
229
316
  dependencies: [...entry.dependencies || []],
230
- state: { trusted: true, loaded: vm.extensionManager.isExtensionLoaded(entry.id) }
317
+ state: { trusted: true, plusFamily: true, loaded: vm.extensionManager.isExtensionLoaded(entry.id) }
231
318
  }));
232
319
  function createCatalogLibrary({
233
320
  catalog: plusCatalog,
@@ -355,7 +442,7 @@ function createCatalogLibrary({
355
442
  }
356
443
  }
357
444
  render() {
358
- const t = text[this.props.locale.startsWith("ja") ? "ja" : "en"];
445
+ const t = text2[this.props.locale.startsWith("ja") ? "ja" : "en"];
359
446
  const { entries, busy, denied, failure, fetchError, decisions } = this.state;
360
447
  if (!entries) {
361
448
  return /* @__PURE__ */ import_react2.default.createElement(
@@ -21,6 +21,91 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  // src/catalog-library.tsx
22
22
  import { ExtensionReview } from "@kubohiroya/turbowarp-extension-security-dialog/react";
23
23
 
24
+ // node_modules/.pnpm/@kubohiroya+turbowarp-extension-manifest@0.6.0/node_modules/@kubohiroya/turbowarp-extension-manifest/dist/resources.js
25
+ var RESOURCE_TYPES = [
26
+ "camera",
27
+ "microphone",
28
+ "network",
29
+ "bluetooth",
30
+ "usb",
31
+ "storage",
32
+ "files",
33
+ "audio-output"
34
+ ];
35
+ function fail(message) {
36
+ throw new TypeError(`Resource declaration: ${message}`);
37
+ }
38
+ function record(value, label, keys) {
39
+ if (!value || typeof value !== "object" || Array.isArray(value))
40
+ fail(`${label} must be an object`);
41
+ const result = value;
42
+ if (keys && Object.keys(result).some((key) => !keys.includes(key)))
43
+ fail(`${label} has an unknown field`);
44
+ return result;
45
+ }
46
+ function text(value, label) {
47
+ const source = record(value, label);
48
+ if (!Object.hasOwn(source, "en") || Object.keys(source).length > 12)
49
+ fail(`${label} requires English text`);
50
+ const result = {};
51
+ for (const [locale, value2] of Object.entries(source)) {
52
+ if (!/^[a-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(locale) || typeof value2 !== "string" || !value2.trim() || value2.length > 1e3 || [...value2].length > 500)
53
+ fail(`${label} must contain bounded localized text`);
54
+ result[locale] = value2;
55
+ }
56
+ return Object.freeze(result);
57
+ }
58
+ function parseResourceDeclaration(value) {
59
+ if (value === void 0)
60
+ return void 0;
61
+ const source = record(value, "declaration", ["schemaVersion", "resources"]);
62
+ if (source["schemaVersion"] !== 1)
63
+ fail("unsupported schemaVersion");
64
+ const list = source["resources"];
65
+ if (!Array.isArray(list) || list.length > RESOURCE_TYPES.length)
66
+ fail("resources must be a bounded list");
67
+ const seen = /* @__PURE__ */ new Set();
68
+ const resources = list.map((value2) => {
69
+ const item = record(value2, "resource", ["type", "usage", "purpose", "condition", "access", "via", "data"]);
70
+ const type = item["type"];
71
+ if (!RESOURCE_TYPES.includes(type) || seen.has(type))
72
+ fail("unknown or duplicate resource type");
73
+ seen.add(type);
74
+ const usage = item["usage"];
75
+ if (usage !== "required" && usage !== "conditional")
76
+ fail("usage must be required or conditional");
77
+ const result = { type, usage, purpose: text(item["purpose"], "purpose") };
78
+ if (item["condition"] !== void 0)
79
+ result.condition = text(item["condition"], "condition");
80
+ if (usage === "conditional" && !result.condition)
81
+ fail("conditional use requires a condition");
82
+ if (item["access"] !== void 0) {
83
+ if (item["access"] !== "use" && item["access"] !== "permission-request")
84
+ fail("invalid access");
85
+ result.access = item["access"];
86
+ }
87
+ if (item["via"] !== void 0) {
88
+ const via = item["via"];
89
+ if (!Array.isArray(via) || via.length === 0 || via.length > 8 || new Set(via).size !== via.length || via.some((name) => typeof name !== "string" || name.length > 214 || !/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name)))
90
+ fail("invalid via packages");
91
+ result.via = Object.freeze([...via]);
92
+ }
93
+ if (item["data"] !== void 0) {
94
+ if (type !== "network")
95
+ fail("data is only valid for network");
96
+ const data = record(item["data"], "data", ["direction", "content"]);
97
+ const direction = data["direction"];
98
+ if (direction !== "download" && direction !== "upload" && direction !== "bidirectional")
99
+ fail("invalid data direction");
100
+ result.data = Object.freeze({ direction, content: text(data["content"], "data content") });
101
+ }
102
+ if (type === "network" && !result.data)
103
+ fail("network requires data direction and content");
104
+ return Object.freeze(result);
105
+ });
106
+ return Object.freeze({ schemaVersion: 1, resources: Object.freeze(resources) });
107
+ }
108
+
24
109
  // src/display-urls.ts
25
110
  var displayURL = (value, allowMail = false) => {
26
111
  if (typeof value !== "string" || !value || /[\u0000-\u0020\u007f]/.test(value)) return null;
@@ -43,34 +128,36 @@ var contactURL = (value) => {
43
128
 
44
129
  // src/catalog.ts
45
130
  var ID = /^[A-Za-z0-9]+$/;
46
- function fail(message) {
131
+ function fail2(message) {
47
132
  throw new Error(message);
48
133
  }
49
134
  var object = (value, what) => {
50
- if (value === null || typeof value !== "object" || Array.isArray(value)) fail(`${what} must be an object`);
135
+ if (value === null || typeof value !== "object" || Array.isArray(value)) fail2(`${what} must be an object`);
51
136
  return value;
52
137
  };
53
138
  var string = (value, what, limit = 2048) => {
54
- if (typeof value !== "string" || value.length === 0 || value.length > limit) fail(`${what} must be text`);
139
+ if (typeof value !== "string" || value.length === 0 || value.length > limit) fail2(`${what} must be text`);
55
140
  return value;
56
141
  };
57
142
  var reviewURL = (value, what = "URL", allowHTTP = false) => {
58
- const text2 = string(value, what);
143
+ const text3 = string(value, what);
59
144
  let url;
60
145
  try {
61
- url = new URL(text2);
146
+ url = new URL(text3);
62
147
  } catch (error) {
63
- fail(`${what} must be an absolute URL`);
148
+ fail2(`${what} must be an absolute URL`);
64
149
  }
65
150
  const schemes = allowHTTP ? ["https:", "http:"] : ["https:"];
66
151
  if (!schemes.includes(url.protocol) || url.username || url.password || url.hash) {
67
- fail(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
152
+ fail2(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
68
153
  }
69
- return text2;
154
+ return text3;
70
155
  };
71
156
  var metadataOf = (value) => {
72
157
  const source = object(value, "metadata");
73
158
  const result = {};
159
+ const resources = parseResourceDeclaration(source.resourceDeclaration);
160
+ if (resources !== void 0) result.resourceDeclaration = resources;
74
161
  for (const key of [
75
162
  "name",
76
163
  "id",
@@ -92,21 +179,21 @@ var metadataOf = (value) => {
92
179
  if (source.descriptions !== void 0) {
93
180
  const descriptions = object(source.descriptions, "descriptions");
94
181
  result.descriptions = {};
95
- for (const [tag, text2] of Object.entries(descriptions)) {
96
- if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag)) fail("descriptions keys must be language tags");
97
- result.descriptions[tag] = string(text2, "description", 4096);
182
+ for (const [tag, text3] of Object.entries(descriptions)) {
183
+ if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag)) fail2("descriptions keys must be language tags");
184
+ result.descriptions[tag] = string(text3, "description", 4096);
98
185
  }
99
186
  }
100
187
  return result;
101
188
  };
102
189
  var categoriesOf = (value) => {
103
190
  const list = value === void 0 ? [] : value;
104
- if (!Array.isArray(list)) fail("categories must be a list");
191
+ if (!Array.isArray(list)) fail2("categories must be a list");
105
192
  const byId = /* @__PURE__ */ new Map();
106
193
  list.forEach((item, order) => {
107
194
  const category = object(item, "category");
108
195
  const id = string(category.id, "category id", 128);
109
- if (byId.has(id)) fail(`Duplicate category ${id}`);
196
+ if (byId.has(id)) fail2(`Duplicate category ${id}`);
110
197
  const resolved = { id, title: string(category.title, "category title", 256), order };
111
198
  if (category.titleJa !== void 0) resolved.titleJa = string(category.titleJa, "category titleJa", 256);
112
199
  byId.set(id, Object.freeze(resolved));
@@ -116,23 +203,23 @@ var categoriesOf = (value) => {
116
203
  function parseExtensionCatalog(data) {
117
204
  const document = object(data, "catalog");
118
205
  if (document.schemaVersion !== void 0 && document.schemaVersion !== 1) {
119
- fail(`Unsupported catalog schema ${document.schemaVersion}`);
206
+ fail2(`Unsupported catalog schema ${document.schemaVersion}`);
120
207
  }
121
208
  const categories = categoriesOf(document.categories);
122
209
  const list = document.extensions;
123
- if (!Array.isArray(list)) fail("catalog extensions must be a list");
210
+ if (!Array.isArray(list)) fail2("catalog extensions must be a list");
124
211
  const byId = /* @__PURE__ */ new Map();
125
212
  const urls = /* @__PURE__ */ new Set();
126
213
  const entries = list.map((item) => {
127
214
  const source = object(item, "extension");
128
215
  const id = string(source.id, "extension id", 128);
129
- if (!ID.test(id)) fail(`Invalid extension id ${id}`);
130
- if (byId.has(id)) fail(`Duplicate extension ${id}`);
216
+ if (!ID.test(id)) fail2(`Invalid extension id ${id}`);
217
+ if (byId.has(id)) fail2(`Duplicate extension ${id}`);
131
218
  const url = reviewURL(source.url, `${id} url`);
132
- if (urls.has(url)) fail(`Duplicate extension URL ${url}`);
219
+ if (urls.has(url)) fail2(`Duplicate extension URL ${url}`);
133
220
  urls.add(url);
134
221
  const dependencies = source.dependencies === void 0 ? [] : source.dependencies;
135
- if (!Array.isArray(dependencies)) fail(`${id} dependencies must be a list`);
222
+ if (!Array.isArray(dependencies)) fail2(`${id} dependencies must be a list`);
136
223
  const entry = {
137
224
  key: id,
138
225
  id,
@@ -145,11 +232,11 @@ function parseExtensionCatalog(data) {
145
232
  };
146
233
  if (source.sha256 !== void 0) {
147
234
  entry.sha256 = string(source.sha256, "sha256", 64);
148
- if (!/^[0-9a-f]{64}$/.test(entry.sha256)) fail(`Invalid sha256 for ${id}`);
235
+ if (!/^[0-9a-f]{64}$/.test(entry.sha256)) fail2(`Invalid sha256 for ${id}`);
149
236
  }
150
237
  if (source.category !== void 0) {
151
238
  const category = string(source.category, "category", 128);
152
- if (!categories.has(category)) fail(`Unknown category ${category}`);
239
+ if (!categories.has(category)) fail2(`Unknown category ${category}`);
153
240
  entry.category = categories.get(category);
154
241
  }
155
242
  byId.set(id, entry);
@@ -157,14 +244,14 @@ function parseExtensionCatalog(data) {
157
244
  });
158
245
  for (const entry of entries) {
159
246
  for (const dependency of entry.dependencies) {
160
- if (!byId.has(dependency)) fail(`${entry.id} depends on missing ${dependency}`);
247
+ if (!byId.has(dependency)) fail2(`${entry.id} depends on missing ${dependency}`);
161
248
  }
162
249
  }
163
250
  const state = /* @__PURE__ */ new Map();
164
251
  const walk = (id) => {
165
252
  const mark = state.get(id);
166
253
  if (mark === "done") return;
167
- if (mark === "open") fail(`Dependency cycle at ${id}`);
254
+ if (mark === "open") fail2(`Dependency cycle at ${id}`);
168
255
  state.set(id, "open");
169
256
  for (const dependency of byId.get(id).dependencies) walk(dependency);
170
257
  state.set(id, "done");
@@ -175,7 +262,7 @@ function parseExtensionCatalog(data) {
175
262
 
176
263
  // src/catalog-library.tsx
177
264
  import React from "react";
178
- var text = {
265
+ var text2 = {
179
266
  en: {
180
267
  loading: "Loading TurboWarp Plus extensions\u2026",
181
268
  failed: "The extension catalog could not be loaded.",
@@ -195,7 +282,7 @@ var reviewRows = (entries, vm, loader = true) => entries.map((entry) => ({
195
282
  metadata: entry.metadata,
196
283
  source: { kind: loader ? "catalog" : "legacy", url: entry.url },
197
284
  dependencies: [...entry.dependencies || []],
198
- state: { trusted: true, loaded: vm.extensionManager.isExtensionLoaded(entry.id) }
285
+ state: { trusted: true, plusFamily: true, loaded: vm.extensionManager.isExtensionLoaded(entry.id) }
199
286
  }));
200
287
  function createCatalogLibrary({
201
288
  catalog: plusCatalog,
@@ -323,7 +410,7 @@ function createCatalogLibrary({
323
410
  }
324
411
  }
325
412
  render() {
326
- const t = text[this.props.locale.startsWith("ja") ? "ja" : "en"];
413
+ const t = text2[this.props.locale.startsWith("ja") ? "ja" : "en"];
327
414
  const { entries, busy, denied, failure, fetchError, decisions } = this.state;
328
415
  if (!entries) {
329
416
  return /* @__PURE__ */ React.createElement(
@@ -0,0 +1,9 @@
1
+ import type { ReviewEntry } from './review-types.js';
2
+ export interface PreviewCatalog {
3
+ read(signal: AbortSignal): Promise<{
4
+ catalog?: unknown;
5
+ icons?: Record<string, string>;
6
+ }>;
7
+ }
8
+ /** The catalog already chooses the declared banner or the package's block SVG. */
9
+ export declare function createCatalogPreviewResolver(catalog?: PreviewCatalog): (entry: ReviewEntry, signal: AbortSignal) => Promise<string | undefined>;
@@ -0,0 +1,4 @@
1
+ import type { PreviewCatalog } from './catalog-preview.js';
2
+ import type { ReviewEntry } from './review-types.js';
3
+ /** Bind declarations to the exact catalog address/digest, never to a project's package-name claim. */
4
+ export declare function createCatalogResourceResolver(catalog?: PreviewCatalog): (entry: ReviewEntry, signal: AbortSignal) => Promise<import("@kubohiroya/turbowarp-extension-manifest/resources").ResourceDeclaration | undefined>;
@@ -17,6 +17,8 @@ export interface ExtensionRowProps {
17
17
  locale?: string;
18
18
  /** Marks the row as trusted by the host. */
19
19
  trusted?: boolean;
20
+ /** The host confirmed membership in the TurboWarp Plus family. Independent of execution trust. */
21
+ plusFamily?: boolean;
20
22
  /** Given, the row has a checkbox, and its picture chooses the same way. */
21
23
  pick?: ExtensionRowPick;
22
24
  /** Where pictures are kept between visits; null keeps nothing. */
@@ -33,5 +35,5 @@ export interface ExtensionRowProps {
33
35
  * picture, what it says it does and who made it. The review screen and any other list of
34
36
  * extensions draw the same row, so an extension looks the same wherever it is offered.
35
37
  */
36
- export declare const ExtensionRow: ({ metadata, ids, locale, trusted, pick, previewCache, itemProps, details, children }: ExtensionRowProps) => React.JSX.Element;
38
+ export declare const ExtensionRow: ({ metadata, ids, locale, trusted, plusFamily, pick, previewCache, itemProps, details, children }: ExtensionRowProps) => React.JSX.Element;
37
39
  export default ExtensionRow;
@@ -0,0 +1,2 @@
1
+ /** One catalog read per review, matched by the code's full URL rather than a claimed ID. */
2
+ export declare function createGalleryPreviewResolver(): (url: string, signal: AbortSignal) => Promise<string | undefined>;