@kubohiroya/turbowarp-extension-security-dialog 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +8 -0
- package/README.md +8 -0
- package/dist/build-info.json +2 -2
- package/dist/catalog-library.cjs +112 -25
- package/dist/catalog-library.mjs +112 -25
- package/dist/catalog-resources.d.ts +4 -0
- package/dist/index.cjs +154 -37
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +154 -37
- package/dist/project-review.cjs +158 -36
- package/dist/project-review.mjs +158 -36
- package/dist/react.cjs +213 -71
- package/dist/react.d.ts +1 -0
- package/dist/react.mjs +213 -71
- package/dist/resources.d.ts +7 -0
- package/dist/review-types.d.ts +3 -0
- package/package.json +6 -3
- package/src/catalog-resources.ts +34 -0
- package/src/catalog.ts +3 -0
- package/src/extension-row.tsx +2 -0
- package/src/index.ts +1 -0
- package/src/metadata.ts +1 -1
- package/src/project-review.tsx +13 -4
- package/src/react.tsx +1 -0
- package/src/resources.tsx +47 -0
- package/src/review-types.ts +4 -0
- package/src/review.css +18 -0
- package/styles.css +18 -0
- package/webpack4.css +18 -0
package/README.ja.md
CHANGED
|
@@ -309,3 +309,11 @@ npmが固定したGitHubアーカイブを`.git`なしでビルドする場合
|
|
|
309
309
|
|
|
310
310
|
Editor 独自実装の移管元とライセンス確認は [EDITOR-MIGRATION.md](EDITOR-MIGRATION.md) に記録しています。
|
|
311
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
|
@@ -297,3 +297,11 @@ dependencies.
|
|
|
297
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).
|
|
298
298
|
|
|
299
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.
|
package/dist/build-info.json
CHANGED
package/dist/catalog-library.cjs
CHANGED
|
@@ -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
|
|
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))
|
|
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)
|
|
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
|
|
175
|
+
const text3 = string(value, what);
|
|
91
176
|
let url;
|
|
92
177
|
try {
|
|
93
|
-
url = new URL(
|
|
178
|
+
url = new URL(text3);
|
|
94
179
|
} catch (error) {
|
|
95
|
-
|
|
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
|
-
|
|
184
|
+
fail2(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
|
|
100
185
|
}
|
|
101
|
-
return
|
|
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,
|
|
128
|
-
if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag))
|
|
129
|
-
result.descriptions[tag] = string(
|
|
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))
|
|
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))
|
|
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
|
-
|
|
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))
|
|
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))
|
|
162
|
-
if (byId.has(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))
|
|
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))
|
|
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))
|
|
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))
|
|
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))
|
|
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")
|
|
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
|
|
297
|
+
var text2 = {
|
|
211
298
|
en: {
|
|
212
299
|
loading: "Loading TurboWarp Plus extensions\u2026",
|
|
213
300
|
failed: "The extension catalog could not be loaded.",
|
|
@@ -355,7 +442,7 @@ function createCatalogLibrary({
|
|
|
355
442
|
}
|
|
356
443
|
}
|
|
357
444
|
render() {
|
|
358
|
-
const t =
|
|
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(
|
package/dist/catalog-library.mjs
CHANGED
|
@@ -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
|
|
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))
|
|
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)
|
|
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
|
|
143
|
+
const text3 = string(value, what);
|
|
59
144
|
let url;
|
|
60
145
|
try {
|
|
61
|
-
url = new URL(
|
|
146
|
+
url = new URL(text3);
|
|
62
147
|
} catch (error) {
|
|
63
|
-
|
|
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
|
-
|
|
152
|
+
fail2(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
|
|
68
153
|
}
|
|
69
|
-
return
|
|
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,
|
|
96
|
-
if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag))
|
|
97
|
-
result.descriptions[tag] = string(
|
|
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))
|
|
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))
|
|
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
|
-
|
|
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))
|
|
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))
|
|
130
|
-
if (byId.has(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))
|
|
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))
|
|
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))
|
|
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))
|
|
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))
|
|
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")
|
|
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
|
|
265
|
+
var text2 = {
|
|
179
266
|
en: {
|
|
180
267
|
loading: "Loading TurboWarp Plus extensions\u2026",
|
|
181
268
|
failed: "The extension catalog could not be loaded.",
|
|
@@ -323,7 +410,7 @@ function createCatalogLibrary({
|
|
|
323
410
|
}
|
|
324
411
|
}
|
|
325
412
|
render() {
|
|
326
|
-
const t =
|
|
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,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>;
|