@kehto/shell 0.11.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.
- package/README.md +14 -2
- package/dist/index.d.ts +74 -312
- package/dist/index.js +27 -134
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -893,7 +893,7 @@ var audioManager = {
|
|
|
893
893
|
if (iframeWindow) {
|
|
894
894
|
const muteEvent = {
|
|
895
895
|
kind: 29e3,
|
|
896
|
-
//
|
|
896
|
+
// INC_PEER — inlined numeric after Phase 24 DRIFT-01 shim removal
|
|
897
897
|
created_at: Math.floor(Date.now() / 1e3),
|
|
898
898
|
tags: [["t", "napplet:audio-muted"]],
|
|
899
899
|
content: JSON.stringify({ muted }),
|
|
@@ -975,107 +975,7 @@ function createKeysForwarder(deps) {
|
|
|
975
975
|
};
|
|
976
976
|
}
|
|
977
977
|
|
|
978
|
-
// src/connect-store.ts
|
|
979
|
-
var STORAGE_KEY3 = "napplet:connect";
|
|
980
|
-
function connectKey(dTag, aggregateHash) {
|
|
981
|
-
return `${dTag}:${aggregateHash}`;
|
|
982
|
-
}
|
|
983
|
-
var store2 = /* @__PURE__ */ new Map();
|
|
984
|
-
var connectStore = {
|
|
985
|
-
check(dTag, aggregateHash, origin) {
|
|
986
|
-
const entry = store2.get(connectKey(dTag, aggregateHash));
|
|
987
|
-
if (!entry) return false;
|
|
988
|
-
return entry.origins.includes(origin);
|
|
989
|
-
},
|
|
990
|
-
getOrigins(dTag, aggregateHash) {
|
|
991
|
-
const entry = store2.get(connectKey(dTag, aggregateHash));
|
|
992
|
-
return entry ? [...entry.origins] : [];
|
|
993
|
-
},
|
|
994
|
-
grant(dTag, aggregateHash, origins) {
|
|
995
|
-
const key = connectKey(dTag, aggregateHash);
|
|
996
|
-
const sorted = [...new Set(origins)].sort();
|
|
997
|
-
store2.set(key, { key, dTag, aggregateHash, origins: sorted, grantedAt: Date.now() });
|
|
998
|
-
connectStore.persist();
|
|
999
|
-
},
|
|
1000
|
-
revoke(dTag, aggregateHash) {
|
|
1001
|
-
store2.delete(connectKey(dTag, aggregateHash));
|
|
1002
|
-
connectStore.persist();
|
|
1003
|
-
},
|
|
1004
|
-
getAllGrants() {
|
|
1005
|
-
return Array.from(store2.values()).map((e) => ({
|
|
1006
|
-
dTag: e.dTag,
|
|
1007
|
-
aggregateHash: e.aggregateHash,
|
|
1008
|
-
origins: [...e.origins]
|
|
1009
|
-
}));
|
|
1010
|
-
},
|
|
1011
|
-
persist() {
|
|
1012
|
-
try {
|
|
1013
|
-
const entries = Array.from(store2.entries()).map(([k, v]) => [k, {
|
|
1014
|
-
dTag: v.dTag,
|
|
1015
|
-
aggregateHash: v.aggregateHash,
|
|
1016
|
-
origins: v.origins,
|
|
1017
|
-
grantedAt: v.grantedAt
|
|
1018
|
-
}]);
|
|
1019
|
-
localStorage.setItem(STORAGE_KEY3, JSON.stringify(entries));
|
|
1020
|
-
} catch {
|
|
1021
|
-
}
|
|
1022
|
-
},
|
|
1023
|
-
load() {
|
|
1024
|
-
try {
|
|
1025
|
-
const raw = localStorage.getItem(STORAGE_KEY3);
|
|
1026
|
-
if (!raw) return;
|
|
1027
|
-
const entries = JSON.parse(raw);
|
|
1028
|
-
store2.clear();
|
|
1029
|
-
for (const [key, val] of entries) {
|
|
1030
|
-
if (!Array.isArray(val.origins)) continue;
|
|
1031
|
-
store2.set(key, {
|
|
1032
|
-
key,
|
|
1033
|
-
dTag: val.dTag,
|
|
1034
|
-
aggregateHash: val.aggregateHash,
|
|
1035
|
-
origins: [...val.origins],
|
|
1036
|
-
grantedAt: val.grantedAt ?? 0
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
} catch {
|
|
1040
|
-
store2.clear();
|
|
1041
|
-
}
|
|
1042
|
-
},
|
|
1043
|
-
clear() {
|
|
1044
|
-
store2.clear();
|
|
1045
|
-
try {
|
|
1046
|
-
localStorage.removeItem(STORAGE_KEY3);
|
|
1047
|
-
} catch {
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
function connectGrantKey(dTag, aggregateHash) {
|
|
1052
|
-
return `${dTag}:${aggregateHash}`;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
978
|
// src/shell-init.ts
|
|
1056
|
-
var LEGACY_NUB_DOMAINS = [
|
|
1057
|
-
"identity",
|
|
1058
|
-
"storage",
|
|
1059
|
-
"ifc",
|
|
1060
|
-
"theme",
|
|
1061
|
-
"keys",
|
|
1062
|
-
"media",
|
|
1063
|
-
"notify",
|
|
1064
|
-
"config",
|
|
1065
|
-
"resource",
|
|
1066
|
-
"connect",
|
|
1067
|
-
"class",
|
|
1068
|
-
"cvm"
|
|
1069
|
-
];
|
|
1070
|
-
var LEGACY_IFC_PROTOCOLS = [
|
|
1071
|
-
"ifc:NAP-01",
|
|
1072
|
-
"ifc:NUB-01",
|
|
1073
|
-
"ifc:NUB-02",
|
|
1074
|
-
"ifc:NUB-03",
|
|
1075
|
-
"ifc:NUB-04",
|
|
1076
|
-
"ifc:NUB-05",
|
|
1077
|
-
"ifc:NUB-06"
|
|
1078
|
-
];
|
|
1079
979
|
var NAP_DOMAINS = [
|
|
1080
980
|
"identity",
|
|
1081
981
|
"storage",
|
|
@@ -1086,8 +986,6 @@ var NAP_DOMAINS = [
|
|
|
1086
986
|
"notify",
|
|
1087
987
|
"config",
|
|
1088
988
|
"resource",
|
|
1089
|
-
"connect",
|
|
1090
|
-
"class",
|
|
1091
989
|
"cvm"
|
|
1092
990
|
];
|
|
1093
991
|
var NAP_INC_PROTOCOLS = [
|
|
@@ -1112,10 +1010,7 @@ function buildShellCapabilities(hooks) {
|
|
|
1112
1010
|
const naps = hooks.relayPool ? ["relay", "outbox", ...NAP_DOMAINS, ...NAP_INC_PROTOCOLS] : [...NAP_DOMAINS, ...NAP_INC_PROTOCOLS];
|
|
1113
1011
|
if (hooks.upload) naps.push("upload");
|
|
1114
1012
|
if (hooks.intent?.isAvailable()) naps.push("intent");
|
|
1115
|
-
|
|
1116
|
-
if (hooks.upload) nubs.push("upload");
|
|
1117
|
-
if (hooks.intent?.isAvailable()) nubs.push("intent");
|
|
1118
|
-
return { domains, protocols, naps, nubs, sandbox };
|
|
1013
|
+
return { domains, protocols, naps, sandbox };
|
|
1119
1014
|
}
|
|
1120
1015
|
|
|
1121
1016
|
// src/shell-ready.ts
|
|
@@ -1131,7 +1026,7 @@ function handleShellReady({
|
|
|
1131
1026
|
return;
|
|
1132
1027
|
}
|
|
1133
1028
|
const capabilities = buildShellCapabilities(hooks);
|
|
1134
|
-
postShellInit(
|
|
1029
|
+
postShellInit(windowId, capabilities, Object.keys(hooks.services ?? {}));
|
|
1135
1030
|
initSent.add(windowId);
|
|
1136
1031
|
}
|
|
1137
1032
|
function registerNip5dSessionIfNeeded({
|
|
@@ -1156,8 +1051,7 @@ function registerNip5dSessionIfNeeded({
|
|
|
1156
1051
|
aggregateHash: identity.aggregateHash,
|
|
1157
1052
|
registeredAt: Date.now(),
|
|
1158
1053
|
instanceId: crypto.randomUUID(),
|
|
1159
|
-
provenance: "nip-5d"
|
|
1160
|
-
class: identity.class
|
|
1054
|
+
provenance: "nip-5d"
|
|
1161
1055
|
};
|
|
1162
1056
|
runtime.sessionRegistry.register(windowId, entry);
|
|
1163
1057
|
}
|
|
@@ -1166,8 +1060,7 @@ function resolveNip5dIdentity(hooks, windowId) {
|
|
|
1166
1060
|
if (hookIdentity !== null && hookIdentity !== void 0) {
|
|
1167
1061
|
return {
|
|
1168
1062
|
dTag: hookIdentity.dTag,
|
|
1169
|
-
aggregateHash: hookIdentity.aggregateHash
|
|
1170
|
-
class: hookIdentity.class
|
|
1063
|
+
aggregateHash: hookIdentity.aggregateHash
|
|
1171
1064
|
};
|
|
1172
1065
|
}
|
|
1173
1066
|
const win = originRegistry.getIframeWindow(windowId);
|
|
@@ -1180,30 +1073,29 @@ function resolveNip5dIdentity(hooks, windowId) {
|
|
|
1180
1073
|
}
|
|
1181
1074
|
return {
|
|
1182
1075
|
dTag: originIdentity.dTag,
|
|
1183
|
-
aggregateHash: originIdentity.aggregateHash
|
|
1184
|
-
class: null
|
|
1076
|
+
aggregateHash: originIdentity.aggregateHash
|
|
1185
1077
|
};
|
|
1186
1078
|
}
|
|
1187
|
-
function
|
|
1188
|
-
if (c === null) return null;
|
|
1189
|
-
const match = /^class-(\d+)$/.exec(c);
|
|
1190
|
-
if (!match) return null;
|
|
1191
|
-
return Number.parseInt(match[1], 10);
|
|
1192
|
-
}
|
|
1193
|
-
function postShellInit(runtime, windowId, capabilities, services) {
|
|
1194
|
-
const sessionEntry = runtime.sessionRegistry.getEntryByWindowId(windowId);
|
|
1195
|
-
const resolvedClass = sessionEntry?.class ?? null;
|
|
1079
|
+
function postShellInit(windowId, capabilities, services) {
|
|
1196
1080
|
const initMsg = {
|
|
1197
1081
|
type: "shell.init",
|
|
1198
1082
|
capabilities,
|
|
1199
|
-
services
|
|
1200
|
-
class: classToWireCode(resolvedClass)
|
|
1083
|
+
services
|
|
1201
1084
|
};
|
|
1202
1085
|
const win = originRegistry.getIframeWindow(windowId);
|
|
1203
1086
|
if (win) win.postMessage(initMsg, "*");
|
|
1204
1087
|
}
|
|
1205
1088
|
|
|
1206
1089
|
// src/shell-bridge.ts
|
|
1090
|
+
function reportUnrouted(hooks, event, reason) {
|
|
1091
|
+
if (!hooks.onUnroutedMessage) return;
|
|
1092
|
+
const data = event.data;
|
|
1093
|
+
const type = typeof data === "object" && data !== null && typeof data.type === "string" ? data.type : void 0;
|
|
1094
|
+
try {
|
|
1095
|
+
hooks.onUnroutedMessage({ type, origin: event.origin, reason });
|
|
1096
|
+
} catch {
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1207
1099
|
function createShellBridge(hooks) {
|
|
1208
1100
|
const runtimeHooks = adaptHooks(hooks, {
|
|
1209
1101
|
originRegistry,
|
|
@@ -1241,9 +1133,15 @@ function createShellBridge(hooks) {
|
|
|
1241
1133
|
return {
|
|
1242
1134
|
handleMessage(event) {
|
|
1243
1135
|
const sourceWindow = event.source;
|
|
1244
|
-
if (!sourceWindow)
|
|
1136
|
+
if (!sourceWindow) {
|
|
1137
|
+
reportUnrouted(hooks, event, "no-source-window");
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1245
1140
|
const windowId = originRegistry.getWindowId(sourceWindow);
|
|
1246
|
-
if (!windowId)
|
|
1141
|
+
if (!windowId) {
|
|
1142
|
+
reportUnrouted(hooks, event, "unregistered-window");
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1247
1145
|
const msg = event.data;
|
|
1248
1146
|
if (typeof msg !== "object" || msg === null || typeof msg.type !== "string") return;
|
|
1249
1147
|
if (msg.type === "shell.ready") {
|
|
@@ -1272,16 +1170,13 @@ function createShellBridge(hooks) {
|
|
|
1272
1170
|
},
|
|
1273
1171
|
get runtime() {
|
|
1274
1172
|
return runtime;
|
|
1275
|
-
},
|
|
1276
|
-
get connectStore() {
|
|
1277
|
-
return connectStore;
|
|
1278
1173
|
}
|
|
1279
1174
|
};
|
|
1280
1175
|
}
|
|
1281
1176
|
|
|
1282
1177
|
// src/index.ts
|
|
1283
1178
|
import { ALL_CAPABILITIES as ALL_CAPABILITIES2 } from "@kehto/runtime";
|
|
1284
|
-
import { createEnforceGate,
|
|
1179
|
+
import { createEnforceGate, createNapEnforceGate, formatDenialReason } from "@kehto/runtime";
|
|
1285
1180
|
|
|
1286
1181
|
// src/topics.ts
|
|
1287
1182
|
import { TOPICS } from "@napplet/core";
|
|
@@ -1356,15 +1251,13 @@ export {
|
|
|
1356
1251
|
adaptHooks,
|
|
1357
1252
|
audioManager,
|
|
1358
1253
|
buildShellCapabilities,
|
|
1359
|
-
connectGrantKey,
|
|
1360
|
-
connectStore,
|
|
1361
1254
|
createEnforceGate,
|
|
1362
1255
|
createIdentityProxy,
|
|
1363
1256
|
createKeysForwarder,
|
|
1364
1257
|
createKeysProxy,
|
|
1365
1258
|
createMediaProxy,
|
|
1259
|
+
createNapEnforceGate,
|
|
1366
1260
|
createNotifyProxy,
|
|
1367
|
-
createNubEnforceGate,
|
|
1368
1261
|
createShellBridge,
|
|
1369
1262
|
createThemeProxy,
|
|
1370
1263
|
formatDenialReason,
|