krillplayer-plugin 0.1.1 → 0.3.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.md +22 -0
- package/dist/cli.js +215 -196
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +1589 -0
- package/dist/zip.d.ts +13 -0
- package/dist/zip.js +68 -0
- package/package.json +11 -2
- package/skill/krillplayer-plugin/SKILL.md +2 -1
- package/skill/krillplayer-plugin/assets/samples/file-share/plugin.ts +1 -20
- package/skill/krillplayer-plugin/assets/samples/media-server/plugin.ts +1 -35
- package/skill/krillplayer-plugin/assets/samples/network-share/plugin.ts +1 -20
- package/skill/krillplayer-plugin/references/choosing-a-kind.md +2 -2
- package/skill/krillplayer-plugin/references/contract.d.ts +95 -129
- package/skill/krillplayer-plugin/references/errors-and-fixes.md +1 -1
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-empty-folder.json +0 -11
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-gone-not-found.json +0 -12
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-lists-subfolders-and-media.json +0 -28
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-second-page.json +0 -22
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-skips-subtitles.json +0 -21
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-root-first-page.json +0 -25
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-root-second-page.json +0 -22
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-everything-first-page.json +0 -74
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-everything-last-page.json +0 -86
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-nothing-new.json +0 -12
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-since-a-token-with-a-removal.json +0 -88
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-ids-first-page.json +0 -15
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-ids-last-page.json +0 -14
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-empty-folder.json +0 -60
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-gives-size-and-modified-time.json +0 -78
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-gone-not-found.json +0 -60
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-second-page.json +0 -71
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-a-range.json +0 -62
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-an-info-file.json +0 -62
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-file-gone-not-found.json +0 -62
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-root.json +0 -84
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-source-offline-retryable.json +0 -61
package/dist/cli.js
CHANGED
|
@@ -69,7 +69,6 @@ var Capability = enumeration("Capability", [
|
|
|
69
69
|
"music",
|
|
70
70
|
"play",
|
|
71
71
|
"resolve",
|
|
72
|
-
"library",
|
|
73
72
|
"resources",
|
|
74
73
|
"subtitles",
|
|
75
74
|
"subtitleSearch",
|
|
@@ -78,9 +77,10 @@ var Capability = enumeration("Capability", [
|
|
|
78
77
|
"status",
|
|
79
78
|
"login",
|
|
80
79
|
"playbackReport",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
80
|
+
"danmakuSend",
|
|
81
|
+
"browseLists",
|
|
82
|
+
"playerPanels",
|
|
83
|
+
"cardActions"
|
|
84
84
|
]);
|
|
85
85
|
var Media = enumeration("Media", ["video", "audio"]);
|
|
86
86
|
var ChannelKind = enumeration("ChannelKind", ["creator", "station", "podcast"]);
|
|
@@ -228,6 +228,8 @@ var Folder = object("Folder", { kind: constant("folder"), ...collectionBase });
|
|
|
228
228
|
var Collection = union("Collection", "kind", [Series, Season, BoxSet, Playlist, Folder], "CollectionContent");
|
|
229
229
|
var Entry = wrapped("Entry", "type", { item: Item, channel: Channel, collection: Collection });
|
|
230
230
|
var PagedEntry = paged(Entry);
|
|
231
|
+
var BrowseListKind = enumeration("BrowseListKind", ["video", "live", "audio", "file"]);
|
|
232
|
+
var BrowseList = object("BrowseList", { id: string, title: string, kind: BrowseListKind });
|
|
231
233
|
var ArtistRef = object("ArtistRef", { id: string, name: string, image: optional(string) });
|
|
232
234
|
var albumRef = {
|
|
233
235
|
id: string,
|
|
@@ -280,33 +282,6 @@ var Lyrics = object("Lyrics", {
|
|
|
280
282
|
synced: boolean,
|
|
281
283
|
lines: array(object("LyricsLine", { start: optional(number), end: optional(number), text: string, translation: optional(string) }))
|
|
282
284
|
});
|
|
283
|
-
var LibraryDirectory = object("LibraryDirectory", {
|
|
284
|
-
type: constant("directory"),
|
|
285
|
-
path: string,
|
|
286
|
-
name: string,
|
|
287
|
-
modified: optional(number),
|
|
288
|
-
tag: optional(string)
|
|
289
|
-
});
|
|
290
|
-
var LibraryFile = object("LibraryFile", {
|
|
291
|
-
type: constant("file"),
|
|
292
|
-
path: string,
|
|
293
|
-
name: string,
|
|
294
|
-
itemId: string,
|
|
295
|
-
media: Media,
|
|
296
|
-
size: optional(integer),
|
|
297
|
-
modified: optional(number),
|
|
298
|
-
tag: optional(string)
|
|
299
|
-
});
|
|
300
|
-
var LibraryIdentified = object("LibraryIdentified", { type: constant("identified"), item: Item, series: optional(Series) });
|
|
301
|
-
var LibraryEntry = union("LibraryEntry", "type", [LibraryDirectory, LibraryFile, LibraryIdentified]);
|
|
302
|
-
var PagedLibraryEntry = paged(LibraryEntry);
|
|
303
|
-
var LibraryChanges = object("LibraryChanges", {
|
|
304
|
-
entries: array(LibraryEntry),
|
|
305
|
-
removed: optional(array(string)),
|
|
306
|
-
next: optional(string),
|
|
307
|
-
since: string
|
|
308
|
-
});
|
|
309
|
-
var LibraryIds = object("LibraryIds", { ids: array(string), next: optional(string) });
|
|
310
285
|
var FilesProtocol = enumeration("FilesProtocol", ["smb", "local"]);
|
|
311
286
|
var FileEntry = object("FileEntry", {
|
|
312
287
|
name: string,
|
|
@@ -343,7 +318,8 @@ var Parameter = object("Parameter", {
|
|
|
343
318
|
options: optional(array(Option)),
|
|
344
319
|
dynamicOptions: optional(boolean),
|
|
345
320
|
dependsOn: optional(array(string)),
|
|
346
|
-
visibleWhen: optional(array(object("ParameterCondition", { name: string, values: array(string) })))
|
|
321
|
+
visibleWhen: optional(array(object("ParameterCondition", { name: string, values: array(string) }))),
|
|
322
|
+
perSource: optional(boolean)
|
|
347
323
|
});
|
|
348
324
|
var Contributions = object("Contributions", {
|
|
349
325
|
playerPanels: optional(array(object("PlayerPanelContribution", { id: string, title: string, kinds: array(ItemKind) }))),
|
|
@@ -368,6 +344,8 @@ var PluginManifest = object("PluginManifest", {
|
|
|
368
344
|
hosts: array(string),
|
|
369
345
|
userProvidedURLs: optional(boolean),
|
|
370
346
|
readsCredentials: optional(boolean),
|
|
347
|
+
loginRequired: optional(boolean),
|
|
348
|
+
singleSource: optional(boolean),
|
|
371
349
|
// 图片地址里不参与缓存键的查询参数名(不分大小写),例如每次都换的令牌与盐(ADR 0015「图片」)。尺寸参数内核另外固定去掉,不用写。
|
|
372
350
|
imageCacheIgnoredParameters: optional(array(string)),
|
|
373
351
|
// 要用 krillplayer.files 时写哪种协议(contract.md 6.1)。连哪台主机、哪个共享、用什么账号由内核向用户要,不写在 parameters 里,插件也读不到。
|
|
@@ -441,40 +419,31 @@ var Playable = object("Playable", {
|
|
|
441
419
|
// 这一路的原始文件名,给字幕插件与弹幕插件匹配用(contract.md 3.1);不给时内核用条目的文件名或标题。
|
|
442
420
|
filename: optional(string)
|
|
443
421
|
});
|
|
444
|
-
var
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
var Card = object("Card", {
|
|
450
|
-
kind: enumeration("CardKind", ["entry", "link", "banner", "comment"]),
|
|
451
|
-
title: string,
|
|
452
|
-
subtitle: optional(string),
|
|
453
|
-
caption: optional(string),
|
|
454
|
-
image: optional(string),
|
|
455
|
-
text: optional(string),
|
|
422
|
+
var Comment = object("Comment", {
|
|
423
|
+
id: string,
|
|
424
|
+
author: string,
|
|
425
|
+
text: string,
|
|
426
|
+
avatar: optional(string),
|
|
456
427
|
time: optional(number),
|
|
457
|
-
|
|
458
|
-
open: optional(PageLink)
|
|
428
|
+
likes: optional(integer)
|
|
459
429
|
});
|
|
460
|
-
var
|
|
461
|
-
|
|
430
|
+
var EntriesPanel = object("EntriesPanel", {
|
|
431
|
+
kind: constant("entries"),
|
|
462
432
|
title: optional(string),
|
|
463
|
-
|
|
464
|
-
|
|
433
|
+
entries: array(Entry),
|
|
434
|
+
next: optional(string),
|
|
435
|
+
maxAge: optional(number)
|
|
465
436
|
});
|
|
466
|
-
var
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
sections: array(Section),
|
|
437
|
+
var CommentsPanel = object("CommentsPanel", {
|
|
438
|
+
kind: constant("comments"),
|
|
439
|
+
comments: array(Comment),
|
|
470
440
|
next: optional(string),
|
|
471
|
-
maxAge: optional(number)
|
|
472
|
-
empty: optional(string)
|
|
473
|
-
}, "PageContent");
|
|
474
|
-
var ActionResult = object("ActionResult", {
|
|
475
|
-
open: optional(PageLink),
|
|
476
|
-
message: optional(string)
|
|
441
|
+
maxAge: optional(number)
|
|
477
442
|
});
|
|
443
|
+
var PanelPage = union("PanelPage", "kind", [EntriesPanel, CommentsPanel], "PanelContent");
|
|
444
|
+
var ActionMessage = object("ActionMessage", { kind: constant("message"), message: string });
|
|
445
|
+
var ActionEntries = object("ActionEntries", { kind: constant("entries"), title: optional(string), entries: array(Entry) });
|
|
446
|
+
var ActionResult = union("ActionResult", "kind", [ActionMessage, ActionEntries]);
|
|
478
447
|
var ChannelStatus = object("ChannelStatus", {
|
|
479
448
|
id: string,
|
|
480
449
|
live: enumeration("ChannelLive", ["online", "offline", "unknown"], "unknown"),
|
|
@@ -644,7 +613,7 @@ var RSSFeed = object("RSSFeed", {
|
|
|
644
613
|
episodes: array(RSSEpisode)
|
|
645
614
|
});
|
|
646
615
|
var WorkKind = enumeration("WorkKind", ["movie", "series"]);
|
|
647
|
-
var ListName = enumeration("ListName", ["trending", "popular", "topRated", "upcoming", "onAir"]);
|
|
616
|
+
var ListName = enumeration("ListName", ["trending", "popular", "topRated", "upcoming", "nowPlaying", "onAir"]);
|
|
648
617
|
var Genre = enumeration("Genre", [
|
|
649
618
|
"action",
|
|
650
619
|
"adventure",
|
|
@@ -670,6 +639,21 @@ var Genre = enumeration("Genre", [
|
|
|
670
639
|
"war",
|
|
671
640
|
"western"
|
|
672
641
|
]);
|
|
642
|
+
var Network = enumeration("Network", [
|
|
643
|
+
"netflix",
|
|
644
|
+
"hbo",
|
|
645
|
+
"disneyPlus",
|
|
646
|
+
"appleTv",
|
|
647
|
+
"primeVideo",
|
|
648
|
+
"hulu",
|
|
649
|
+
"peacock",
|
|
650
|
+
"paramountPlus",
|
|
651
|
+
"iqiyi",
|
|
652
|
+
"tencentVideo",
|
|
653
|
+
"youku",
|
|
654
|
+
"bilibili",
|
|
655
|
+
"mangoTv"
|
|
656
|
+
]);
|
|
673
657
|
var Work = object("Work", {
|
|
674
658
|
kind: WorkKind,
|
|
675
659
|
ids: Ids,
|
|
@@ -683,6 +667,7 @@ var PagedWork = paged(Work);
|
|
|
683
667
|
var MetadataSearchOptions = object("MetadataSearchOptions", { year: optional(integer), cursor: optional(string) });
|
|
684
668
|
var MetadataListOptions = object("MetadataListOptions", {
|
|
685
669
|
genre: optional(Genre),
|
|
670
|
+
network: optional(Network),
|
|
686
671
|
country: optional(string),
|
|
687
672
|
year: optional(integer),
|
|
688
673
|
cursor: optional(string)
|
|
@@ -767,11 +752,14 @@ var CryptoKey = object("CryptoKey", {
|
|
|
767
752
|
});
|
|
768
753
|
var CryptoKeyPair = object("CryptoKeyPair", { publicKey: CryptoKey, privateKey: CryptoKey });
|
|
769
754
|
var SLOT_RULES = {
|
|
755
|
+
// 导出 lists 的是具名列表(contract.md 2.1),list、parameters、options 都按列表的 id 问,能力是 browseLists 而不是 browse:
|
|
756
|
+
// 只认 browse 的旧内核不会按一份列表的老样子去调它,不认识的 browseLists 跳过。没导出 lists 的是只有一份列表的特例。
|
|
770
757
|
browse: {
|
|
771
|
-
functions: ["parameters", "options", "list", "search", "channel", "collection", "schedule"],
|
|
758
|
+
functions: ["lists", "parameters", "options", "list", "search", "channel", "collection", "schedule"],
|
|
772
759
|
required: ["list"],
|
|
773
760
|
pairs: [],
|
|
774
|
-
capabilities: { browse: ["list"] }
|
|
761
|
+
capabilities: { browse: ["list"], browseLists: ["lists"] },
|
|
762
|
+
supersedes: { browseLists: "browse" }
|
|
775
763
|
},
|
|
776
764
|
// 没有音乐内容的实例 sections 返回空数组,内核就不在音乐里显示它(contract.md 2.2)。
|
|
777
765
|
music: {
|
|
@@ -781,14 +769,6 @@ var SLOT_RULES = {
|
|
|
781
769
|
capabilities: { music: ["sections"] }
|
|
782
770
|
},
|
|
783
771
|
play: { functions: ["start"], required: ["start"], pairs: [], capabilities: { play: ["start"] } },
|
|
784
|
-
// 文件类来源导出 list(与可选的 read),媒体服务器导出 changes 与 ids(contract.md 2.10)。两样能力分开:只认 library 的旧内核
|
|
785
|
-
// 见到只导出 changes 的插件时不会去调它没有的 list,不认识的 libraryChanges 跳过。
|
|
786
|
-
library: {
|
|
787
|
-
functions: ["list", "read", "changes", "ids"],
|
|
788
|
-
required: [],
|
|
789
|
-
pairs: [["changes", "ids"]],
|
|
790
|
-
capabilities: { library: ["list"], libraryChanges: ["changes"] }
|
|
791
|
-
},
|
|
792
772
|
// 资源插件(contract.md 2.5):按作品回答有没有可播的版本。
|
|
793
773
|
resources: { functions: ["find"], required: ["find"], pairs: [], capabilities: { resources: ["find"] } },
|
|
794
774
|
// 只导出 search 的是字幕插件,不是自带字幕的来源(contract.md 第 2 节)。
|
|
@@ -813,12 +793,15 @@ var SLOT_RULES = {
|
|
|
813
793
|
capabilities: { login: ["methods"] }
|
|
814
794
|
},
|
|
815
795
|
playbackReport: { functions: ["report"], required: ["report"], pairs: [], capabilities: { playbackReport: ["report"] } },
|
|
816
|
-
|
|
796
|
+
// 组件页面 page 去掉了(ADR 0040),剩下播放器面板与卡片操作,都交数据(#753)。面板与操作各一项能力,
|
|
797
|
+
// 不再是 views:交组件格式的旧插件打的是 views,新内核不认识、跳过,不会按数据去解它;旧内核也不认识这两项,不会按组件格式去解新插件。
|
|
798
|
+
views: { functions: ["panel", "action"], required: [], pairs: [], capabilities: { playerPanels: ["panel"], cardActions: ["action"] } },
|
|
817
799
|
// 顶层的 parameters 不算能力(contract.md 第 2 节)。
|
|
818
800
|
parameters: { functions: ["options"], required: ["options"], pairs: [], capabilities: {} }
|
|
819
801
|
};
|
|
820
802
|
var SLOT_RETURNS = {
|
|
821
803
|
browse: {
|
|
804
|
+
lists: { schema: array(BrowseList) },
|
|
822
805
|
parameters: { schema: array(Parameter) },
|
|
823
806
|
options: { schema: array(Option) },
|
|
824
807
|
list: { schema: PagedEntry },
|
|
@@ -839,7 +822,6 @@ var SLOT_RETURNS = {
|
|
|
839
822
|
lyrics: { schema: Lyrics, nullable: true }
|
|
840
823
|
},
|
|
841
824
|
play: { start: { schema: Playable } },
|
|
842
|
-
library: { list: { schema: PagedLibraryEntry }, read: { schema: bytes }, changes: { schema: LibraryChanges }, ids: { schema: LibraryIds } },
|
|
843
825
|
resources: { find: { schema: array(ResourceVersion) } },
|
|
844
826
|
subtitles: { list: { schema: array(SubtitleTrack) }, search: { schema: array(SubtitleTrack) }, fetch: { schema: Subtitle } },
|
|
845
827
|
danmaku: {
|
|
@@ -856,7 +838,7 @@ var SLOT_RETURNS = {
|
|
|
856
838
|
poll: { schema: LoginPoll },
|
|
857
839
|
account: { schema: LoginAccount, nullable: true }
|
|
858
840
|
},
|
|
859
|
-
views: {
|
|
841
|
+
views: { panel: { schema: PanelPage }, action: { schema: ActionResult } },
|
|
860
842
|
parameters: { options: { schema: array(Option) } },
|
|
861
843
|
resolve: { "": { schema: Resolved, nullable: true } }
|
|
862
844
|
};
|
|
@@ -891,10 +873,12 @@ var NOT_YET_USED = [
|
|
|
891
873
|
"ArtistPage.artist",
|
|
892
874
|
"ArtistRef.image",
|
|
893
875
|
"BoxSet.ancestors",
|
|
876
|
+
"BoxSet.ids",
|
|
894
877
|
"ChannelRef.image",
|
|
895
878
|
"ChannelRef.kind",
|
|
896
879
|
"ChannelStatus.latest",
|
|
897
880
|
"CollectionRef.kind",
|
|
881
|
+
"Comment.avatar",
|
|
898
882
|
"CommentGift.count",
|
|
899
883
|
"CommentGift.name",
|
|
900
884
|
"CommentImage.height",
|
|
@@ -933,7 +917,6 @@ var NOT_YET_USED = [
|
|
|
933
917
|
"MusicPlaylist.count",
|
|
934
918
|
"MusicPlaylist.owner",
|
|
935
919
|
"MusicPlaylist.summary",
|
|
936
|
-
"MusicSection.kind",
|
|
937
920
|
"OnDemand.index",
|
|
938
921
|
"OnDemand.summary",
|
|
939
922
|
"OnDemand.version",
|
|
@@ -948,15 +931,13 @@ var NOT_YET_USED = [
|
|
|
948
931
|
"Podcast.order",
|
|
949
932
|
"Podcast.summary",
|
|
950
933
|
"PodcastEpisode.episodeType",
|
|
951
|
-
"PodcastEpisode.index",
|
|
952
|
-
"PodcastEpisode.published",
|
|
953
|
-
"PodcastEpisode.season",
|
|
954
934
|
"PodcastEpisode.summary",
|
|
955
935
|
"ResolvedBrowse.entry",
|
|
956
936
|
"ScheduleEntry.id",
|
|
957
937
|
"ScheduleEntry.image",
|
|
958
938
|
"ScheduleEntry.summary",
|
|
959
939
|
"Season.ancestors",
|
|
940
|
+
"Season.ids",
|
|
960
941
|
"Series.ancestors",
|
|
961
942
|
"Song.disc",
|
|
962
943
|
"Song.index",
|
|
@@ -1168,6 +1149,18 @@ var CREDENTIAL_HEADERS = /* @__PURE__ */ new Set(["authorization", "cookie", "pr
|
|
|
1168
1149
|
function carries(text, secret) {
|
|
1169
1150
|
return text.includes(secret) || text.includes("%") && percentDecoded(text).includes(secret);
|
|
1170
1151
|
}
|
|
1152
|
+
var TOKEN_MINIMUM_LENGTH = 16;
|
|
1153
|
+
function looksLikeToken(secret) {
|
|
1154
|
+
const scalars = [...secret];
|
|
1155
|
+
if (scalars.length < TOKEN_MINIMUM_LENGTH) return false;
|
|
1156
|
+
const classes = /* @__PURE__ */ new Set();
|
|
1157
|
+
for (const scalar of scalars) {
|
|
1158
|
+
const code = scalar.codePointAt(0) ?? 0;
|
|
1159
|
+
classes.add(code >= 48 && code <= 57 ? 0 : code >= 97 && code <= 122 ? 1 : code >= 65 && code <= 90 ? 2 : 3);
|
|
1160
|
+
if (classes.size >= 2) return true;
|
|
1161
|
+
}
|
|
1162
|
+
return false;
|
|
1163
|
+
}
|
|
1171
1164
|
function percentDecoded(text) {
|
|
1172
1165
|
const input = new TextEncoder().encode(text);
|
|
1173
1166
|
const bytes2 = [];
|
|
@@ -1332,6 +1325,8 @@ var Chain = class {
|
|
|
1332
1325
|
once;
|
|
1333
1326
|
remembered;
|
|
1334
1327
|
secrets;
|
|
1328
|
+
// `derived-no-secrets` 查的那部分:像令牌的值(`looksLikeToken`)。删减请求头仍按全部凭证值。
|
|
1329
|
+
tokens;
|
|
1335
1330
|
use;
|
|
1336
1331
|
grants;
|
|
1337
1332
|
startsAtUserAddress = false;
|
|
@@ -1348,6 +1343,7 @@ var Chain = class {
|
|
|
1348
1343
|
this.once = lower(grants.once);
|
|
1349
1344
|
this.remembered = grants.remembered ?? {};
|
|
1350
1345
|
this.secrets = (grants.secrets ?? []).filter((secret) => secret !== "");
|
|
1346
|
+
this.tokens = this.secrets.filter(looksLikeToken);
|
|
1351
1347
|
}
|
|
1352
1348
|
classify(host) {
|
|
1353
1349
|
return this.user.has(host) ? "user" : this.declared.has(host) ? "declared" : "derived";
|
|
@@ -1385,7 +1381,7 @@ var Chain = class {
|
|
|
1385
1381
|
let headers2 = becomesGet ? without(previous.headers, BODY_HEADERS) : previous.headers;
|
|
1386
1382
|
if (this.seen.has(`${method} ${address.href}`)) throw this.refuse("redirect-loop", address, `redirect loop at ${this.label(address)}`);
|
|
1387
1383
|
const downgrade = previous.address.scheme === "https" && address.scheme === "http";
|
|
1388
|
-
if (downgrade && this.use !== "playback-follow" && this.use !== "playback-probe") {
|
|
1384
|
+
if (downgrade && this.use !== "playback" && this.use !== "playback-follow" && this.use !== "playback-probe") {
|
|
1389
1385
|
throw this.refuse("no-downgrade", address, `will not follow a redirect from https to http at ${this.label(address)}`);
|
|
1390
1386
|
}
|
|
1391
1387
|
const hostClass = this.classify(address.host);
|
|
@@ -1491,7 +1487,7 @@ var Chain = class {
|
|
|
1491
1487
|
);
|
|
1492
1488
|
}
|
|
1493
1489
|
const carried = [address.href, ...Object.keys(headers2), ...Object.values(headers2), ...frames ?? []];
|
|
1494
|
-
if (this.
|
|
1490
|
+
if (this.tokens.some((secret) => carried.some((text) => carries(text, secret)))) {
|
|
1495
1491
|
throw this.refuse("derived-no-secrets", address, `credentials may not be sent to ${address.host}, a host that is neither declared nor given by the user`);
|
|
1496
1492
|
}
|
|
1497
1493
|
}
|
|
@@ -1998,11 +1994,11 @@ function checkSearch(query, year) {
|
|
|
1998
1994
|
if (year !== void 0) checkYear(year);
|
|
1999
1995
|
return trimmed;
|
|
2000
1996
|
}
|
|
2001
|
-
function checkList(name2, kind, { genre, country, year }) {
|
|
2002
|
-
if (name2 === "upcoming" && kind === "series" || name2 === "onAir" && kind === "movie") {
|
|
1997
|
+
function checkList(name2, kind, { genre, country, year, network }) {
|
|
1998
|
+
if ((name2 === "upcoming" || name2 === "nowPlaying") && kind === "series" || name2 === "onAir" && kind === "movie") {
|
|
2003
1999
|
throw invalid(`${name2} has no ${kind} list`);
|
|
2004
2000
|
}
|
|
2005
|
-
const filtered = genre !== void 0 || country !== void 0 || year !== void 0;
|
|
2001
|
+
const filtered = genre !== void 0 || country !== void 0 || year !== void 0 || network !== void 0;
|
|
2006
2002
|
if (name2 !== "popular" && name2 !== "topRated") {
|
|
2007
2003
|
if (filtered) throw invalid(`${name2} cannot be filtered`);
|
|
2008
2004
|
return;
|
|
@@ -2010,6 +2006,7 @@ function checkList(name2, kind, { genre, country, year }) {
|
|
|
2010
2006
|
if (genre !== void 0 && !GENRES[kind].has(genre)) throw invalid(`genre ${genre} has no ${kind} list`);
|
|
2011
2007
|
if (country !== void 0 && !/^[A-Z]{2}$/.test(country)) throw invalid("country must be a two-letter ISO 3166-1 code");
|
|
2012
2008
|
if (year !== void 0) checkYear(year);
|
|
2009
|
+
if (network !== void 0 && kind === "movie") throw invalid("network has no movie list");
|
|
2013
2010
|
}
|
|
2014
2011
|
var fail = (message) => new TypeError(message);
|
|
2015
2012
|
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
@@ -2091,15 +2088,20 @@ function createMetadata(service) {
|
|
|
2091
2088
|
throw fail(`krillplayer.metadata.list needs a list name: ${ListName.values.join(", ")}`);
|
|
2092
2089
|
}
|
|
2093
2090
|
const checkedKind = kindOf(kind);
|
|
2094
|
-
const fields = optionsOf(options, ["genre", "country", "year", "cursor"], "list");
|
|
2091
|
+
const fields = optionsOf(options, ["genre", "country", "year", "network", "cursor"], "list");
|
|
2095
2092
|
const genre = textOf2(fields.genre, "genre");
|
|
2096
2093
|
if (genre !== void 0 && !Genre.values.includes(genre)) {
|
|
2097
2094
|
throw fail(`krillplayer.metadata.list: unknown genre ${genre}`);
|
|
2098
2095
|
}
|
|
2096
|
+
const network = textOf2(fields.network, "network");
|
|
2097
|
+
if (network !== void 0 && !Network.values.includes(network)) {
|
|
2098
|
+
throw fail(`krillplayer.metadata.list: unknown network ${network}`);
|
|
2099
|
+
}
|
|
2099
2100
|
const filter = {
|
|
2100
2101
|
...genre === void 0 ? {} : { genre },
|
|
2101
2102
|
...optional2("country", textOf2(fields.country, "country")),
|
|
2102
|
-
...optional2("year", integerOf(fields.year, "year"))
|
|
2103
|
+
...optional2("year", integerOf(fields.year, "year")),
|
|
2104
|
+
...network === void 0 ? {} : { network }
|
|
2103
2105
|
};
|
|
2104
2106
|
const cursor = textOf2(fields.cursor, "cursor");
|
|
2105
2107
|
return run2(() => metadata.list(name2, checkedKind, filter, cursor));
|
|
@@ -2894,6 +2896,19 @@ function createSubtle() {
|
|
|
2894
2896
|
unwrapKey
|
|
2895
2897
|
};
|
|
2896
2898
|
}
|
|
2899
|
+
var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
|
|
2900
|
+
async function plainDigest(algorithm, data) {
|
|
2901
|
+
const name2 = DIGESTS.get(algorithm.toLowerCase());
|
|
2902
|
+
if (name2 === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
|
|
2903
|
+
return new Uint8Array(await subtle().digest(name2, typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data)));
|
|
2904
|
+
}
|
|
2905
|
+
function createCrypto() {
|
|
2906
|
+
return {
|
|
2907
|
+
randomBytes: (length) => globalThis.crypto.getRandomValues(new Uint8Array(length)),
|
|
2908
|
+
digest: plainDigest,
|
|
2909
|
+
subtle: createSubtle()
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2897
2912
|
|
|
2898
2913
|
// host/krillplayer.ts
|
|
2899
2914
|
function userAddressesOf(manifest, parameters) {
|
|
@@ -2911,7 +2926,6 @@ function userHostsOf(manifest, parameters) {
|
|
|
2911
2926
|
});
|
|
2912
2927
|
}
|
|
2913
2928
|
var STATUS_SLOT_CAPABILITIES = /* @__PURE__ */ new Set(["http", "decompress", "crypto", "formats", "log", "cache", "credentials", "parameters", "error"]);
|
|
2914
|
-
var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
|
|
2915
2929
|
var COMPRESSION_FORMATS = /* @__PURE__ */ new Set(["gzip", "deflate", "deflate-raw"]);
|
|
2916
2930
|
function createCache(now2 = Date.now) {
|
|
2917
2931
|
const entries = /* @__PURE__ */ new Map();
|
|
@@ -3015,8 +3029,8 @@ function createDerivedURLs() {
|
|
|
3015
3029
|
},
|
|
3016
3030
|
async parsed(data, guideURLs) {
|
|
3017
3031
|
if (typeof data === "string" || guideURLs.length === 0) return;
|
|
3018
|
-
const
|
|
3019
|
-
if (!state().bodies.includes(
|
|
3032
|
+
const digest2 = hex(await crypto.subtle.digest("SHA-256", toBytes(data)));
|
|
3033
|
+
if (!state().bodies.includes(digest2)) return;
|
|
3020
3034
|
for (const url of guideURLs) keep(state().urls, url, DERIVED_URLS_KEPT);
|
|
3021
3035
|
},
|
|
3022
3036
|
// 从用户填的地址跳到的派生主机(derived-lifetime):这个实例之后可以直接请求,只读、不带凭证。最多留 REMEMBERED_HOSTS 台。
|
|
@@ -3166,11 +3180,7 @@ function createKrillPlayer({
|
|
|
3166
3180
|
}
|
|
3167
3181
|
},
|
|
3168
3182
|
decompress: (format2, data) => decompress(format2, data),
|
|
3169
|
-
crypto:
|
|
3170
|
-
randomBytes: (length) => crypto.getRandomValues(new Uint8Array(length)),
|
|
3171
|
-
digest: digest2,
|
|
3172
|
-
subtle: createSubtle()
|
|
3173
|
-
},
|
|
3183
|
+
crypto: createCrypto(),
|
|
3174
3184
|
formats: {
|
|
3175
3185
|
async m3u(data) {
|
|
3176
3186
|
const playlist = parseM3U(data);
|
|
@@ -3326,11 +3336,6 @@ async function decompress(format2, data, limit = FORMAT_LIMITS.decompressedBytes
|
|
|
3326
3336
|
}
|
|
3327
3337
|
return output;
|
|
3328
3338
|
}
|
|
3329
|
-
async function digest2(algorithm, data) {
|
|
3330
|
-
const name2 = DIGESTS.get(algorithm.toLowerCase());
|
|
3331
|
-
if (name2 === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
|
|
3332
|
-
return new Uint8Array(await crypto.subtle.digest(name2, toBytes(data)));
|
|
3333
|
-
}
|
|
3334
3339
|
|
|
3335
3340
|
// contract/validate.ts
|
|
3336
3341
|
var UNKNOWN_KIND_HINTS = [
|
|
@@ -3781,16 +3786,21 @@ var isSecretParam = (value, names) => isSecretName(value) || names.has("u") && (
|
|
|
3781
3786
|
|
|
3782
3787
|
// trial-runner/credentials.ts
|
|
3783
3788
|
var REDACTED = "REDACTED";
|
|
3789
|
+
var REDACTED_TOKEN = "REDACTED-0000000000";
|
|
3790
|
+
var isRedacted = (value) => value === REDACTED || value === REDACTED_TOKEN;
|
|
3791
|
+
function fakeSecret(value) {
|
|
3792
|
+
return looksLikeToken(value) ? REDACTED_TOKEN : REDACTED;
|
|
3793
|
+
}
|
|
3784
3794
|
function fakeValue(value, index) {
|
|
3785
|
-
return /^\d+$/.test(value) ? String(9 - index % 9).repeat(value.length) :
|
|
3795
|
+
return /^\d+$/.test(value) ? String(9 - index % 9).repeat(value.length) : fakeSecret(value);
|
|
3786
3796
|
}
|
|
3787
3797
|
var isFakeId = (value) => /^(\d)\1*$/.test(value);
|
|
3788
3798
|
var SECRET_VALUES = [
|
|
3789
3799
|
/\bSESSDATA=(?!REDACTED\b)[^;&\s"]{8,}/,
|
|
3790
3800
|
/\bbili_jct=[0-9a-f]{16,}/i,
|
|
3791
|
-
/\bBearer\s+[\w.~+/-]{16,}/,
|
|
3801
|
+
/\bBearer\s+(?!(?:REDACTED-0{10}|REDACTED)(?![\w.~+/-]))[\w.~+/-]{16,}/,
|
|
3792
3802
|
/\beyJ[\w-]{8,}\.eyJ[\w-]{8,}\.[\w-]+/,
|
|
3793
|
-
/\b(?:access_key|access_token)=[\w.-]{16,}/
|
|
3803
|
+
/\b(?:access_key|access_token)=(?!(?:REDACTED-0{10}|REDACTED)(?![\w.-]))[\w.-]{16,}/
|
|
3794
3804
|
];
|
|
3795
3805
|
var redactSetCookie = (lines) => lines.split("\n").map((line) => line.replace(/^([^=;]*)=[^;]*/, `$1=${REDACTED}`)).join("\n");
|
|
3796
3806
|
var isRedactedSetCookie = (lines) => lines.split("\n").every((line) => new RegExp(`^[^=;]*=${REDACTED}(;|$)`).test(line));
|
|
@@ -3883,7 +3893,7 @@ function findingsIn(value, path, findings) {
|
|
|
3883
3893
|
const query = /^https?:\/\//.test(text) && URL.canParse(text) ? new URL(text).searchParams : queryOf(text);
|
|
3884
3894
|
if (query !== void 0) {
|
|
3885
3895
|
for (const [name2, entry] of query) {
|
|
3886
|
-
if (isSecretParam(name2, query) && entry
|
|
3896
|
+
if (isSecretParam(name2, query) && !isRedacted(entry) && entry !== "") findings.push(`${path}: query parameter ${name2}`);
|
|
3887
3897
|
}
|
|
3888
3898
|
}
|
|
3889
3899
|
return;
|
|
@@ -3899,7 +3909,7 @@ function findingsIn(value, path, findings) {
|
|
|
3899
3909
|
return;
|
|
3900
3910
|
}
|
|
3901
3911
|
for (const [key, entry] of Object.entries(value)) {
|
|
3902
|
-
const redacted = entry
|
|
3912
|
+
const redacted = isRedacted(entry) || typeof entry === "string" && isFakeId(entry) || key.toLowerCase() === "set-cookie" && typeof entry === "string" && isRedactedSetCookie(entry);
|
|
3903
3913
|
if (isSecretName(key) && typeof entry === "string" && !redacted && entry !== "") {
|
|
3904
3914
|
findings.push(`${path}.${key}: ${key}`);
|
|
3905
3915
|
}
|
|
@@ -4730,6 +4740,94 @@ function optional3(fields) {
|
|
|
4730
4740
|
return Object.fromEntries(Object.entries(fields).filter((entry) => entry[1] !== void 0));
|
|
4731
4741
|
}
|
|
4732
4742
|
|
|
4743
|
+
// trial-runner/capabilities.ts
|
|
4744
|
+
function inheritedFunctions(slot, functions) {
|
|
4745
|
+
const inherited = /* @__PURE__ */ new Set();
|
|
4746
|
+
for (let prototype = Object.getPrototypeOf(slot); prototype !== null; prototype = Object.getPrototypeOf(prototype)) {
|
|
4747
|
+
for (const member of Object.getOwnPropertyNames(prototype)) {
|
|
4748
|
+
if (functions.includes(member) && !Object.hasOwn(slot, member)) inherited.add(member);
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
return [...inherited];
|
|
4752
|
+
}
|
|
4753
|
+
function capabilitiesOf(namespace) {
|
|
4754
|
+
const problems = [];
|
|
4755
|
+
const found = /* @__PURE__ */ new Set();
|
|
4756
|
+
for (const [name2, value] of Object.entries(namespace)) {
|
|
4757
|
+
const top = TOP_LEVEL_FUNCTIONS[name2];
|
|
4758
|
+
if (top !== void 0) {
|
|
4759
|
+
if (typeof value === "function") found.add(top);
|
|
4760
|
+
else problems.push(`${name2} must be a function`);
|
|
4761
|
+
continue;
|
|
4762
|
+
}
|
|
4763
|
+
const rule = SLOT_RULES[name2];
|
|
4764
|
+
if (rule === void 0) {
|
|
4765
|
+
problems.push(`exports ${name2}; plugins export only ${[...Object.keys(SLOT_RULES), ...Object.keys(TOP_LEVEL_FUNCTIONS)].join(", ")}`);
|
|
4766
|
+
continue;
|
|
4767
|
+
}
|
|
4768
|
+
if (typeof value !== "object" || value === null) {
|
|
4769
|
+
problems.push(`${name2} must be an object of functions`);
|
|
4770
|
+
continue;
|
|
4771
|
+
}
|
|
4772
|
+
const has = (member) => typeof slotMember(value, member) === "function";
|
|
4773
|
+
for (const member of Object.getOwnPropertyNames(value)) {
|
|
4774
|
+
if (!rule.functions.includes(member)) problems.push(`${name2}.${member} is not in the contract (${rule.functions.join(", ")})`);
|
|
4775
|
+
else if (!has(member)) problems.push(`${name2}.${member} must be a function`);
|
|
4776
|
+
}
|
|
4777
|
+
for (const member of inheritedFunctions(value, rule.functions)) {
|
|
4778
|
+
problems.push(`${name2}.${member} is inherited; slot functions must be the object's own properties (an object literal, not a class instance)`);
|
|
4779
|
+
}
|
|
4780
|
+
for (const member of rule.required) if (!has(member)) problems.push(`${name2} needs ${member}`);
|
|
4781
|
+
for (const [first, second] of rule.pairs) {
|
|
4782
|
+
if (has(first) !== has(second)) {
|
|
4783
|
+
const [present, missing] = has(first) ? [first, second] : [second, first];
|
|
4784
|
+
problems.push(`${name2}.${present} needs ${name2}.${missing}`);
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
const matched = Object.entries(rule.capabilities).filter(([, any]) => any.some(has)).map(([capability]) => capability);
|
|
4788
|
+
const superseded = new Set(matched.flatMap((capability) => rule.supersedes?.[capability] ?? []));
|
|
4789
|
+
const generated = matched.filter((capability) => !superseded.has(capability));
|
|
4790
|
+
generated.forEach((capability) => found.add(capability));
|
|
4791
|
+
const all = Object.values(rule.capabilities).flat();
|
|
4792
|
+
if (all.length > 0 && generated.length === 0) problems.push(`${name2} needs one of ${all.join(", ")}`);
|
|
4793
|
+
}
|
|
4794
|
+
return { capabilities: Capability.values.filter((name2) => found.has(name2)), problems };
|
|
4795
|
+
}
|
|
4796
|
+
|
|
4797
|
+
// trial-runner/sandbox.ts
|
|
4798
|
+
import vm from "node:vm";
|
|
4799
|
+
var UTF8_LABELS = /* @__PURE__ */ new Set(["unicode-1-1-utf-8", "unicode11utf8", "unicode20utf8", "utf-8", "utf8", "x-unicode20utf8"]);
|
|
4800
|
+
var Utf8TextDecoder = class extends TextDecoder {
|
|
4801
|
+
constructor(label = "utf-8", options) {
|
|
4802
|
+
if (!UTF8_LABELS.has(String(label).trim().toLowerCase())) {
|
|
4803
|
+
throw new RangeError(`TextDecoder only supports utf-8, not ${label}`);
|
|
4804
|
+
}
|
|
4805
|
+
super("utf-8", options);
|
|
4806
|
+
}
|
|
4807
|
+
};
|
|
4808
|
+
async function loadPlugin(source, { identifier, allowCodeGeneration }) {
|
|
4809
|
+
const context = vm.createContext({}, { codeGeneration: { strings: allowCodeGeneration, wasm: false } });
|
|
4810
|
+
const remaining = vm.runInContext(`(() => {
|
|
4811
|
+
const allowed = new Set(${JSON.stringify([...PLUGIN_GLOBALS])});
|
|
4812
|
+
for (const name of Object.getOwnPropertyNames(globalThis)) if (!allowed.has(name)) delete globalThis[name];
|
|
4813
|
+
return Object.getOwnPropertyNames(globalThis).filter((name) => !allowed.has(name));
|
|
4814
|
+
})()`, context);
|
|
4815
|
+
if (remaining.length > 0) throw new Error(`could not remove globals: ${remaining.join(", ")}`);
|
|
4816
|
+
const global = vm.runInContext("globalThis", context);
|
|
4817
|
+
const silent = () => {
|
|
4818
|
+
};
|
|
4819
|
+
const consoleObject = Object.freeze({ debug: silent, trace: silent, log: silent, info: silent, warn: silent, error: silent });
|
|
4820
|
+
for (const [name2, value] of [["TextEncoder", TextEncoder], ["TextDecoder", Utf8TextDecoder], ["console", consoleObject]]) {
|
|
4821
|
+
Object.defineProperty(global, name2, { value, writable: true, configurable: true });
|
|
4822
|
+
}
|
|
4823
|
+
const module = new vm.SourceTextModule(source, { context, identifier });
|
|
4824
|
+
await module.link(() => {
|
|
4825
|
+
throw new Error("plugins cannot import modules");
|
|
4826
|
+
});
|
|
4827
|
+
await module.evaluate();
|
|
4828
|
+
return module.namespace;
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4733
4831
|
// trial-runner/static-check.ts
|
|
4734
4832
|
import { Linter } from "eslint";
|
|
4735
4833
|
var globalsRule = {
|
|
@@ -4779,6 +4877,13 @@ var RESERVED_PARAMETER_PREFIX = "krillplayer.files.";
|
|
|
4779
4877
|
function checkManifest(manifest) {
|
|
4780
4878
|
const parameters = Array.isArray(manifest.parameters) ? manifest.parameters : [];
|
|
4781
4879
|
const problems = [];
|
|
4880
|
+
if (manifest.loginRequired === true && Array.isArray(manifest.capabilities) && !manifest.capabilities.includes("login")) {
|
|
4881
|
+
problems.push("loginRequired needs a login slot: export login so the user can log in when adding a source, or drop loginRequired");
|
|
4882
|
+
}
|
|
4883
|
+
for (const parameter of parameters) {
|
|
4884
|
+
if (typeof parameter !== "object" || parameter === null || parameter.perSource === void 0) continue;
|
|
4885
|
+
problems.push(`parameter ${String(parameter.name)} sets perSource, which only applies to settings: instance parameters already belong to one source`);
|
|
4886
|
+
}
|
|
4782
4887
|
for (const parameter of parameters) {
|
|
4783
4888
|
if (typeof parameter !== "object" || parameter === null) continue;
|
|
4784
4889
|
const { name: name2, dependsOn, visibleWhen } = parameter;
|
|
@@ -4826,6 +4931,7 @@ async function readPlugin(path) {
|
|
|
4826
4931
|
const manifest = JSON.parse(files2.get("manifest.json") ?? "{}");
|
|
4827
4932
|
const source = files2.get(scripts[0]);
|
|
4828
4933
|
const checked = checkPlugin(source);
|
|
4934
|
+
const capabilities = Array.isArray(manifest.capabilities) || checked.violations.length > 0 ? manifest.capabilities : await loadPlugin(source, { identifier: join3(path, scripts[0]), allowCodeGeneration: !checked.exports.includes("status") }).then((namespace) => capabilitiesOf(namespace).capabilities, () => void 0);
|
|
4829
4935
|
return {
|
|
4830
4936
|
id: manifest.id ?? basename(resolve(path)),
|
|
4831
4937
|
file: join3(path, scripts[0]),
|
|
@@ -4839,7 +4945,7 @@ async function readPlugin(path) {
|
|
|
4839
4945
|
dictionaries: dictionariesIn(files2),
|
|
4840
4946
|
exports: checked.exports,
|
|
4841
4947
|
// 清单用了内核留用的参数名(contract.md 6.1)和静态检查拦下的一样判红。
|
|
4842
|
-
violations: [...checked.violations, ...checkManifest(manifest).map((problem) => ` manifest.json: ${problem}`)]
|
|
4948
|
+
violations: [...checked.violations, ...checkManifest({ ...manifest, capabilities }).map((problem) => ` manifest.json: ${problem}`)]
|
|
4843
4949
|
};
|
|
4844
4950
|
}
|
|
4845
4951
|
var TRIAL_CAPABILITIES = new Set(Object.keys(createKrillPlayer({
|
|
@@ -4987,8 +5093,8 @@ async function recordCommand(pluginDirectory, { slot, call: callName, args, cred
|
|
|
4987
5093
|
const redacted = credentials === null ? null : Object.fromEntries(Object.entries(credentials).map(([key, value]) => [key, typeof value === "string" ? withOwnValuesReplaced(value, own) : REDACTED]));
|
|
4988
5094
|
const keptArgs = withOwnValuesReplaced(args, own);
|
|
4989
5095
|
const secret = new Set(plugin2.parameters.filter((parameter) => parameter.secret).map((parameter) => parameter.name));
|
|
4990
|
-
const kept = parameters === void 0 ? void 0 : Object.fromEntries(Object.entries(parameters).map(([name2, value]) => [name2, secret.has(name2) ?
|
|
4991
|
-
const keptKeys = appKeys === void 0 ? void 0 : Object.fromEntries(Object.
|
|
5096
|
+
const kept = parameters === void 0 ? void 0 : Object.fromEntries(Object.entries(parameters).map(([name2, value]) => [name2, secret.has(name2) ? fakeSecret(value) : value]));
|
|
5097
|
+
const keptKeys = appKeys === void 0 ? void 0 : Object.fromEntries(Object.entries(appKeys).map(([name2, key]) => [name2, fakeSecret(key)]));
|
|
4992
5098
|
const exchanges = withOwnValuesReplaced(
|
|
4993
5099
|
withoutValues(recording.exchanges, Object.values(appKeys ?? {}).filter((key) => key !== "")),
|
|
4994
5100
|
own
|
|
@@ -5025,7 +5131,7 @@ ${findings.join("\n")}`);
|
|
|
5025
5131
|
function withoutValues(value, secrets) {
|
|
5026
5132
|
if (secrets.length === 0) return value;
|
|
5027
5133
|
const walk = (item) => {
|
|
5028
|
-
if (typeof item === "string") return secrets.reduce((text, secret) => text.split(secret).join(
|
|
5134
|
+
if (typeof item === "string") return secrets.reduce((text, secret) => text.split(secret).join(fakeSecret(secret)), item);
|
|
5029
5135
|
if (Array.isArray(item)) return item.map(walk);
|
|
5030
5136
|
if (item !== null && typeof item === "object") return Object.fromEntries(Object.entries(item).map(([key, entry]) => [key, walk(entry)]));
|
|
5031
5137
|
return item;
|
|
@@ -5086,7 +5192,7 @@ function withOwnValuesReplaced(value, own) {
|
|
|
5086
5192
|
return walk(value);
|
|
5087
5193
|
}
|
|
5088
5194
|
function leftoverValues(testCase, own) {
|
|
5089
|
-
const checked = own.filter(({ value }) => value.length >= 3 && value
|
|
5195
|
+
const checked = own.filter(({ value }) => value.length >= 3 && !isRedacted(value));
|
|
5090
5196
|
if (checked.length === 0) return [];
|
|
5091
5197
|
const pattern = bytePattern(checked);
|
|
5092
5198
|
const values = new Set(checked.map(({ value }) => value));
|
|
@@ -5131,40 +5237,6 @@ if (false) {
|
|
|
5131
5237
|
}
|
|
5132
5238
|
}
|
|
5133
5239
|
|
|
5134
|
-
// trial-runner/sandbox.ts
|
|
5135
|
-
import vm from "node:vm";
|
|
5136
|
-
var UTF8_LABELS = /* @__PURE__ */ new Set(["unicode-1-1-utf-8", "unicode11utf8", "unicode20utf8", "utf-8", "utf8", "x-unicode20utf8"]);
|
|
5137
|
-
var Utf8TextDecoder = class extends TextDecoder {
|
|
5138
|
-
constructor(label = "utf-8", options) {
|
|
5139
|
-
if (!UTF8_LABELS.has(String(label).trim().toLowerCase())) {
|
|
5140
|
-
throw new RangeError(`TextDecoder only supports utf-8, not ${label}`);
|
|
5141
|
-
}
|
|
5142
|
-
super("utf-8", options);
|
|
5143
|
-
}
|
|
5144
|
-
};
|
|
5145
|
-
async function loadPlugin(source, { identifier, allowCodeGeneration }) {
|
|
5146
|
-
const context = vm.createContext({}, { codeGeneration: { strings: allowCodeGeneration, wasm: false } });
|
|
5147
|
-
const remaining = vm.runInContext(`(() => {
|
|
5148
|
-
const allowed = new Set(${JSON.stringify([...PLUGIN_GLOBALS])});
|
|
5149
|
-
for (const name of Object.getOwnPropertyNames(globalThis)) if (!allowed.has(name)) delete globalThis[name];
|
|
5150
|
-
return Object.getOwnPropertyNames(globalThis).filter((name) => !allowed.has(name));
|
|
5151
|
-
})()`, context);
|
|
5152
|
-
if (remaining.length > 0) throw new Error(`could not remove globals: ${remaining.join(", ")}`);
|
|
5153
|
-
const global = vm.runInContext("globalThis", context);
|
|
5154
|
-
const silent = () => {
|
|
5155
|
-
};
|
|
5156
|
-
const consoleObject = Object.freeze({ debug: silent, trace: silent, log: silent, info: silent, warn: silent, error: silent });
|
|
5157
|
-
for (const [name2, value] of [["TextEncoder", TextEncoder], ["TextDecoder", Utf8TextDecoder], ["console", consoleObject]]) {
|
|
5158
|
-
Object.defineProperty(global, name2, { value, writable: true, configurable: true });
|
|
5159
|
-
}
|
|
5160
|
-
const module = new vm.SourceTextModule(source, { context, identifier });
|
|
5161
|
-
await module.link(() => {
|
|
5162
|
-
throw new Error("plugins cannot import modules");
|
|
5163
|
-
});
|
|
5164
|
-
await module.evaluate();
|
|
5165
|
-
return module.namespace;
|
|
5166
|
-
}
|
|
5167
|
-
|
|
5168
5240
|
// packer/pack.ts
|
|
5169
5241
|
var TEMPLATES = fileURLToPath2(new URL("../templates/", import.meta.url));
|
|
5170
5242
|
var SAMPLES = fileURLToPath2(new URL("../samples/src/", import.meta.url));
|
|
@@ -5215,59 +5287,6 @@ async function dictionaries(directory) {
|
|
|
5215
5287
|
if (problems.length > 0) throw new Error(`${directory}: ${problems.join("; ")}`);
|
|
5216
5288
|
return result.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
5217
5289
|
}
|
|
5218
|
-
function inheritedFunctions(slot, functions) {
|
|
5219
|
-
const inherited = /* @__PURE__ */ new Set();
|
|
5220
|
-
for (let prototype = Object.getPrototypeOf(slot); prototype !== null; prototype = Object.getPrototypeOf(prototype)) {
|
|
5221
|
-
for (const member of Object.getOwnPropertyNames(prototype)) {
|
|
5222
|
-
if (functions.includes(member) && !Object.hasOwn(slot, member)) inherited.add(member);
|
|
5223
|
-
}
|
|
5224
|
-
}
|
|
5225
|
-
return [...inherited];
|
|
5226
|
-
}
|
|
5227
|
-
function capabilitiesOf(namespace) {
|
|
5228
|
-
const problems = [];
|
|
5229
|
-
const found = /* @__PURE__ */ new Set();
|
|
5230
|
-
for (const [name2, value] of Object.entries(namespace)) {
|
|
5231
|
-
const top = TOP_LEVEL_FUNCTIONS[name2];
|
|
5232
|
-
if (top !== void 0) {
|
|
5233
|
-
if (typeof value === "function") found.add(top);
|
|
5234
|
-
else problems.push(`${name2} must be a function`);
|
|
5235
|
-
continue;
|
|
5236
|
-
}
|
|
5237
|
-
const rule = SLOT_RULES[name2];
|
|
5238
|
-
if (rule === void 0) {
|
|
5239
|
-
problems.push(`exports ${name2}; plugins export only ${[...Object.keys(SLOT_RULES), ...Object.keys(TOP_LEVEL_FUNCTIONS)].join(", ")}`);
|
|
5240
|
-
continue;
|
|
5241
|
-
}
|
|
5242
|
-
if (typeof value !== "object" || value === null) {
|
|
5243
|
-
problems.push(`${name2} must be an object of functions`);
|
|
5244
|
-
continue;
|
|
5245
|
-
}
|
|
5246
|
-
const has = (member) => typeof slotMember(value, member) === "function";
|
|
5247
|
-
for (const member of Object.getOwnPropertyNames(value)) {
|
|
5248
|
-
if (!rule.functions.includes(member)) problems.push(`${name2}.${member} is not in the contract (${rule.functions.join(", ")})`);
|
|
5249
|
-
else if (!has(member)) problems.push(`${name2}.${member} must be a function`);
|
|
5250
|
-
}
|
|
5251
|
-
for (const member of inheritedFunctions(value, rule.functions)) {
|
|
5252
|
-
problems.push(`${name2}.${member} is inherited; slot functions must be the object's own properties (an object literal, not a class instance)`);
|
|
5253
|
-
}
|
|
5254
|
-
for (const member of rule.required) if (!has(member)) problems.push(`${name2} needs ${member}`);
|
|
5255
|
-
for (const [first, second] of rule.pairs) {
|
|
5256
|
-
if (has(first) !== has(second)) {
|
|
5257
|
-
const [present, missing] = has(first) ? [first, second] : [second, first];
|
|
5258
|
-
problems.push(`${name2}.${present} needs ${name2}.${missing}`);
|
|
5259
|
-
}
|
|
5260
|
-
}
|
|
5261
|
-
const generated = Object.entries(rule.capabilities).filter(([, any]) => any.some(has)).map(([capability]) => capability);
|
|
5262
|
-
generated.forEach((capability) => found.add(capability));
|
|
5263
|
-
const all = Object.values(rule.capabilities).flat();
|
|
5264
|
-
if (all.length > 0 && generated.length === 0) problems.push(`${name2} needs one of ${all.join(", ")}`);
|
|
5265
|
-
}
|
|
5266
|
-
if (found.has("library") && found.has("resources")) {
|
|
5267
|
-
problems.push("exports both library and resources; a source that lists all its content is scanned into the library, so it does not also answer find");
|
|
5268
|
-
}
|
|
5269
|
-
return { capabilities: Capability.values.filter((name2) => found.has(name2)), problems };
|
|
5270
|
-
}
|
|
5271
5290
|
function notYetUsedExports(namespace) {
|
|
5272
5291
|
const unused = new Set(NOT_YET_USED);
|
|
5273
5292
|
const exported2 = Object.entries(namespace).flatMap(([name2, value]) => TOP_LEVEL_FUNCTIONS[name2] !== void 0 ? [name2] : (SLOT_RULES[name2]?.functions ?? []).filter((member) => typeof slotMember(value, member) === "function").map((member) => `${name2}.${member}`));
|
|
@@ -5299,7 +5318,7 @@ async function pack(directory, warn = () => {
|
|
|
5299
5318
|
if (metadata.interfaceLevel > CONTRACT.interfaceLevel || metadata.contractRevision !== CONTRACT.revision) {
|
|
5300
5319
|
throw new Error(`${directory}/manifest.ts targets interface level ${metadata.interfaceLevel} revision ${metadata.contractRevision}; the contract is level ${CONTRACT.interfaceLevel} revision ${CONTRACT.revision}`);
|
|
5301
5320
|
}
|
|
5302
|
-
const reserved = checkManifest(metadata);
|
|
5321
|
+
const reserved = checkManifest({ ...metadata, capabilities });
|
|
5303
5322
|
if (reserved.length > 0) throw new Error(`${directory}/manifest.ts: ${reserved.join("; ")}`);
|
|
5304
5323
|
const locales = await dictionaries(directory);
|
|
5305
5324
|
if (locales.length > 0 && metadata.language === void 0) {
|