@yourrealm/sdk 0.0.0-alpha.1380.bdd09a9f → 0.0.0-alpha.1388.a6c32ffa
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/dist/{chunk-O3UIK34B.js → chunk-NDE63TCY.js} +419 -43
- package/dist/cli.js +14 -6
- package/dist/index.js +39 -343
- package/dist/test.js +16 -7
- package/dist/ui.js +2 -0
- package/package.json +4 -3
- package/src/compile.ts +5 -1
- package/src/generator/resolve-refs.ts +9 -3
- package/src/keys.ts +19 -3
- package/src/ref.ts +1 -1
- package/src/resolve.ts +89 -2
- package/src/stable-secret.ts +34 -2
- package/src/test/compile.ts +1 -0
- package/src/ui/components/qr-code.tsx +55 -0
- package/src/ui/index.ts +3 -0
- package/src/ui-runtime/index.ts +1 -0
|
@@ -4,10 +4,15 @@ import {
|
|
|
4
4
|
REALM_STATS_MOUNT,
|
|
5
5
|
SPAWN_PLACEHOLDER,
|
|
6
6
|
homeProxyMount,
|
|
7
|
+
nameSchema,
|
|
7
8
|
siloNetwork,
|
|
8
9
|
spawnMounts,
|
|
9
10
|
speculativeSilo
|
|
10
11
|
} from "./chunk-VHTUSZUX.js";
|
|
12
|
+
import {
|
|
13
|
+
SELF_APP_ID,
|
|
14
|
+
Service
|
|
15
|
+
} from "./chunk-AITGS27R.js";
|
|
11
16
|
import {
|
|
12
17
|
__export
|
|
13
18
|
} from "./chunk-MLKGABMK.js";
|
|
@@ -1045,6 +1050,412 @@ var artifact = remotable(
|
|
|
1045
1050
|
}
|
|
1046
1051
|
);
|
|
1047
1052
|
|
|
1053
|
+
// src/resolve.ts
|
|
1054
|
+
import { z as z8 } from "zod";
|
|
1055
|
+
|
|
1056
|
+
// src/app-icon.ts
|
|
1057
|
+
import { z as z6 } from "zod";
|
|
1058
|
+
var PACK_REPOS = {
|
|
1059
|
+
"dashboard-icons": "homarr-labs/dashboard-icons",
|
|
1060
|
+
selfhst: "selfhst/icons"
|
|
1061
|
+
};
|
|
1062
|
+
var PACK_KEY_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1063
|
+
var URL_UNSAFE_RE = /[\s"'<>\\`]/;
|
|
1064
|
+
var FORM_MESSAGE = 'icon must be "dashboard-icons:<key>", "selfhst:<key>" or an https:// URL';
|
|
1065
|
+
function parseIcon(spec) {
|
|
1066
|
+
for (const [prefix, repo] of Object.entries(PACK_REPOS)) {
|
|
1067
|
+
if (!spec.startsWith(`${prefix}:`)) continue;
|
|
1068
|
+
const key = spec.slice(prefix.length + 1);
|
|
1069
|
+
if (!PACK_KEY_RE.test(key)) {
|
|
1070
|
+
return {
|
|
1071
|
+
error: `${prefix} key must be lowercase and match ${PACK_KEY_RE.source}`
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
return { url: `https://cdn.jsdelivr.net/gh/${repo}/svg/${key}.svg` };
|
|
1075
|
+
}
|
|
1076
|
+
if (spec.startsWith("https://")) {
|
|
1077
|
+
const rest = spec.slice("https://".length);
|
|
1078
|
+
if (rest === "") return { error: "https icon URL must have a host" };
|
|
1079
|
+
if (URL_UNSAFE_RE.test(rest))
|
|
1080
|
+
return { error: "https icon URL must not contain whitespace or quotes" };
|
|
1081
|
+
return { url: spec };
|
|
1082
|
+
}
|
|
1083
|
+
return { error: FORM_MESSAGE };
|
|
1084
|
+
}
|
|
1085
|
+
var appIconSchema = z6.string().superRefine((spec, ctx) => {
|
|
1086
|
+
const parsed = parseIcon(spec);
|
|
1087
|
+
if ("error" in parsed) ctx.addIssue({ code: "custom", message: parsed.error });
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
// src/schema/build-apps.ts
|
|
1091
|
+
import { z as z7 } from "zod";
|
|
1092
|
+
var buildRecipeSchema = z7.object({
|
|
1093
|
+
dockerfile: z7.string().optional(),
|
|
1094
|
+
buildArgs: z7.record(z7.string(), z7.string()).optional(),
|
|
1095
|
+
context: z7.string().optional()
|
|
1096
|
+
}).strict();
|
|
1097
|
+
var buildAppsSchema = z7.array(
|
|
1098
|
+
z7.object({
|
|
1099
|
+
appId: z7.string(),
|
|
1100
|
+
service: z7.string(),
|
|
1101
|
+
recipe: buildRecipeSchema
|
|
1102
|
+
})
|
|
1103
|
+
);
|
|
1104
|
+
|
|
1105
|
+
// src/resolve.ts
|
|
1106
|
+
var derivedBodySchema = z8.object({
|
|
1107
|
+
kind: z8.literal("derived"),
|
|
1108
|
+
appId: z8.string(),
|
|
1109
|
+
name: z8.string(),
|
|
1110
|
+
rotatable: z8.boolean().optional(),
|
|
1111
|
+
description: z8.string().optional()
|
|
1112
|
+
});
|
|
1113
|
+
var sharedBodySchema = z8.object({
|
|
1114
|
+
kind: z8.literal("shared"),
|
|
1115
|
+
providerAppId: z8.string(),
|
|
1116
|
+
serviceKey: z8.string(),
|
|
1117
|
+
name: z8.string()
|
|
1118
|
+
});
|
|
1119
|
+
var secretBodySchema = z8.object({ kind: z8.literal("secret"), path: z8.string() });
|
|
1120
|
+
function hasDeferredDescendant(value) {
|
|
1121
|
+
if (value == null || typeof value !== "object") return false;
|
|
1122
|
+
if (Array.isArray(value)) return value.some(hasDeferredDescendant);
|
|
1123
|
+
if ("__realmRef" in value) {
|
|
1124
|
+
const m = value.__realmRef;
|
|
1125
|
+
if (m && typeof m === "object") {
|
|
1126
|
+
if (m.kind === "deferred") return true;
|
|
1127
|
+
return hasDeferredDescendant(m);
|
|
1128
|
+
}
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
for (const v of Object.values(value)) {
|
|
1132
|
+
if (hasDeferredDescendant(v)) return true;
|
|
1133
|
+
}
|
|
1134
|
+
return false;
|
|
1135
|
+
}
|
|
1136
|
+
var deferredBodySchema = z8.object({
|
|
1137
|
+
kind: z8.literal("deferred"),
|
|
1138
|
+
id: z8.number().int().nonnegative(),
|
|
1139
|
+
input: z8.unknown().refine((v) => !hasDeferredDescendant(v), {
|
|
1140
|
+
message: "deferred input must not contain another deferred marker"
|
|
1141
|
+
})
|
|
1142
|
+
});
|
|
1143
|
+
var concatLeafSchema = z8.discriminatedUnion("kind", [
|
|
1144
|
+
derivedBodySchema,
|
|
1145
|
+
sharedBodySchema,
|
|
1146
|
+
secretBodySchema
|
|
1147
|
+
]);
|
|
1148
|
+
var concatBodySchema = z8.object({
|
|
1149
|
+
kind: z8.literal("concat"),
|
|
1150
|
+
parts: z8.array(z8.union([z8.string(), concatLeafSchema]))
|
|
1151
|
+
});
|
|
1152
|
+
var markerBodySchema = z8.discriminatedUnion("kind", [
|
|
1153
|
+
derivedBodySchema,
|
|
1154
|
+
sharedBodySchema,
|
|
1155
|
+
secretBodySchema,
|
|
1156
|
+
deferredBodySchema,
|
|
1157
|
+
concatBodySchema
|
|
1158
|
+
]);
|
|
1159
|
+
var refMarkerSchema = z8.object({ __realmRef: markerBodySchema });
|
|
1160
|
+
var stringOrRef = z8.union([z8.string(), refMarkerSchema]);
|
|
1161
|
+
var hostPathSchema = z8.string().refine((p) => (p.startsWith("./") || p.startsWith("/")) && !p.includes(".."), {
|
|
1162
|
+
message: "hostPath must start with ./ or / and must not contain .."
|
|
1163
|
+
});
|
|
1164
|
+
var RESERVED_PORTS = /* @__PURE__ */ new Set([
|
|
1165
|
+
22,
|
|
1166
|
+
// SSH on the worker host
|
|
1167
|
+
3100,
|
|
1168
|
+
// Home
|
|
1169
|
+
3101,
|
|
1170
|
+
// Home's dev uplink listener
|
|
1171
|
+
6021
|
|
1172
|
+
// The worker's verify relay
|
|
1173
|
+
]);
|
|
1174
|
+
var hostPortNumberSchema = z8.number().int().min(1, "hostPort must be >= 1").max(65535, "hostPort must be <= 65535").refine((p) => !RESERVED_PORTS.has(p), {
|
|
1175
|
+
message: `hostPort must not be a Realm-reserved port (${[...RESERVED_PORTS].join(", ")})`
|
|
1176
|
+
});
|
|
1177
|
+
var imageReferenceSchema = z8.string().min(1, "image must not be empty").regex(
|
|
1178
|
+
/^[a-z0-9_./\-:@]+$/,
|
|
1179
|
+
"image must contain only Docker reference characters (a-z 0-9 _ . - / : @)"
|
|
1180
|
+
);
|
|
1181
|
+
var duration = (defaultSeconds) => z8.number().int().nonnegative().default(defaultSeconds);
|
|
1182
|
+
var healthcheckSchema = z8.object({
|
|
1183
|
+
test: z8.array(z8.string()),
|
|
1184
|
+
interval: duration(3),
|
|
1185
|
+
timeout: duration(5),
|
|
1186
|
+
retries: z8.number().int().nonnegative().default(10),
|
|
1187
|
+
startPeriod: duration(10)
|
|
1188
|
+
});
|
|
1189
|
+
var containerPortSchema = z8.number().int().min(1).max(65535);
|
|
1190
|
+
var routerSchema = z8.object({
|
|
1191
|
+
name: z8.string().min(1).optional(),
|
|
1192
|
+
icon: appIconSchema.optional(),
|
|
1193
|
+
// Home-screen tile opt-out. Absent = shown; `false` keeps the gated route
|
|
1194
|
+
// but drops the tile (machine-facing endpoints like webhooks/registries).
|
|
1195
|
+
// Optional rather than `.default(true)` so only opted-out routers carry
|
|
1196
|
+
// the field in resolved state.
|
|
1197
|
+
tile: z8.boolean().optional(),
|
|
1198
|
+
containerPort: containerPortSchema,
|
|
1199
|
+
// The whole resolved `r.home.publicDomain()` value, hosts and redirect mode
|
|
1200
|
+
// together. No `stringOrRef` arm: that would let a bare author-supplied
|
|
1201
|
+
// string in through the back door, which is what the permission closes.
|
|
1202
|
+
// Absent when the app declares no such permission or none was granted.
|
|
1203
|
+
publicDomain: publicDomainValueSchema.optional(),
|
|
1204
|
+
pathPrefix: z8.string().regex(/^\/[a-zA-Z0-9/_-]*$/, "pathPrefix must start with / and contain only [a-zA-Z0-9/_-]").optional(),
|
|
1205
|
+
compress: z8.boolean().default(true),
|
|
1206
|
+
maxRequestSizeMb: z8.number().nullable().default(4),
|
|
1207
|
+
rateLimit: z8.union([
|
|
1208
|
+
z8.number(),
|
|
1209
|
+
z8.object({
|
|
1210
|
+
requests: z8.number(),
|
|
1211
|
+
window: z8.string().regex(/^\d+(ms|s|m|h)$/, "window must be a duration like 10s, 1m, 1h")
|
|
1212
|
+
})
|
|
1213
|
+
]).nullable().default({ requests: 1e3, window: "10s" }),
|
|
1214
|
+
headers: z8.record(z8.string(), z8.string().nullable()).optional()
|
|
1215
|
+
});
|
|
1216
|
+
var hostPortSchema = z8.object({
|
|
1217
|
+
containerPort: containerPortSchema,
|
|
1218
|
+
hostPort: hostPortNumberSchema,
|
|
1219
|
+
protocol: z8.enum(["tcp", "udp"]).optional()
|
|
1220
|
+
});
|
|
1221
|
+
var backupStrategySchema = z8.discriminatedUnion("kind", [
|
|
1222
|
+
z8.object({ kind: z8.literal("file-copy") }),
|
|
1223
|
+
z8.object({ kind: z8.literal("sqlite"), file: z8.string() }),
|
|
1224
|
+
z8.object({
|
|
1225
|
+
kind: z8.literal("pg-dump"),
|
|
1226
|
+
url: stringOrRef,
|
|
1227
|
+
version: z8.number().int().positive()
|
|
1228
|
+
}),
|
|
1229
|
+
z8.object({ kind: z8.literal("valkey-save"), url: stringOrRef }),
|
|
1230
|
+
z8.object({
|
|
1231
|
+
kind: z8.literal("mysql-dump"),
|
|
1232
|
+
url: stringOrRef,
|
|
1233
|
+
version: z8.number().int().positive()
|
|
1234
|
+
})
|
|
1235
|
+
]);
|
|
1236
|
+
var absoluteContainerPath = z8.string().startsWith("/", {
|
|
1237
|
+
message: "containerPath must be absolute (start with '/')"
|
|
1238
|
+
});
|
|
1239
|
+
var homeServiceSchema = z8.object({
|
|
1240
|
+
// Exactly one of `image` / `build` is present (enforced in the
|
|
1241
|
+
// superRefine below). `image` is the prebuilt-pull path; `build` is the
|
|
1242
|
+
// build-from-source path, which has no pinned digest until its first
|
|
1243
|
+
// build, so Home leaves the app inert until one is set.
|
|
1244
|
+
image: imageReferenceSchema.optional(),
|
|
1245
|
+
// `build: true` is author sugar for the default recipe — normalize it to
|
|
1246
|
+
// `{}` here so `HomeService.build` is always a `BuildRecipe` object.
|
|
1247
|
+
// The image/build XOR (superRefine below) reads the transformed value, so
|
|
1248
|
+
// `true`/`{}` both count as "build present".
|
|
1249
|
+
build: z8.literal(true).or(buildRecipeSchema).transform((v) => v === true ? {} : v).optional(),
|
|
1250
|
+
router: routerSchema.optional(),
|
|
1251
|
+
hostPorts: z8.array(hostPortSchema).optional(),
|
|
1252
|
+
env: z8.record(z8.string(), z8.union([stringOrRef, z8.number()])).optional(),
|
|
1253
|
+
files: z8.record(absoluteContainerPath, stringOrRef).optional(),
|
|
1254
|
+
command: z8.array(stringOrRef).optional(),
|
|
1255
|
+
volumes: z8.array(
|
|
1256
|
+
z8.object({
|
|
1257
|
+
hostPath: hostPathSchema,
|
|
1258
|
+
containerPath: absoluteContainerPath,
|
|
1259
|
+
// Silo-owned group. Present only on a Silo's volume entry; the
|
|
1260
|
+
// renderer derives `group_add` from it and the grant gate matches
|
|
1261
|
+
// (hostPath, gid) against the Silos the app joined.
|
|
1262
|
+
gid: z8.number().int().positive().optional(),
|
|
1263
|
+
readOnly: z8.boolean().optional(),
|
|
1264
|
+
backup: z8.union([backupStrategySchema, z8.literal(false)]).optional()
|
|
1265
|
+
})
|
|
1266
|
+
).optional(),
|
|
1267
|
+
gpu: z8.boolean().optional(),
|
|
1268
|
+
iptables: z8.boolean().optional(),
|
|
1269
|
+
joinNetworks: z8.array(z8.string()).optional(),
|
|
1270
|
+
healthcheck: healthcheckSchema.optional(),
|
|
1271
|
+
memory: z8.string().optional(),
|
|
1272
|
+
cpu: z8.number().positive().max(128).optional(),
|
|
1273
|
+
replicas: z8.number().int().min(1).max(100).default(1),
|
|
1274
|
+
labels: z8.array(z8.string()).optional(),
|
|
1275
|
+
shmSizeMb: z8.number().int().positive().optional()
|
|
1276
|
+
}).strict().superRefine((svc, ctx) => {
|
|
1277
|
+
if (svc.image == null && svc.build == null) {
|
|
1278
|
+
ctx.addIssue({
|
|
1279
|
+
code: "custom",
|
|
1280
|
+
path: ["image"],
|
|
1281
|
+
message: "a service must set either `image` or `build`"
|
|
1282
|
+
});
|
|
1283
|
+
} else if (svc.image != null && svc.build != null) {
|
|
1284
|
+
ctx.addIssue({
|
|
1285
|
+
code: "custom",
|
|
1286
|
+
path: ["build"],
|
|
1287
|
+
message: "a service cannot set both `image` and `build`"
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1291
|
+
for (const [i, vol] of (svc.volumes ?? []).entries()) {
|
|
1292
|
+
if (seen.has(vol.containerPath)) {
|
|
1293
|
+
ctx.addIssue({
|
|
1294
|
+
code: "custom",
|
|
1295
|
+
path: ["volumes", i, "containerPath"],
|
|
1296
|
+
message: `containerPath ${vol.containerPath} is mounted by two volumes`
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
seen.add(vol.containerPath);
|
|
1300
|
+
}
|
|
1301
|
+
if (!svc.files || !svc.volumes) return;
|
|
1302
|
+
const volumePaths = new Set(svc.volumes.map((v) => v.containerPath));
|
|
1303
|
+
for (const fileKey of Object.keys(svc.files)) {
|
|
1304
|
+
if (volumePaths.has(fileKey)) {
|
|
1305
|
+
ctx.addIssue({
|
|
1306
|
+
code: "custom",
|
|
1307
|
+
path: ["files", fileKey],
|
|
1308
|
+
message: `containerPath ${fileKey} is used by both files: and volumes:`
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
var requestManifestSchema = z8.object({
|
|
1314
|
+
method: z8.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
|
|
1315
|
+
path: z8.string(),
|
|
1316
|
+
query: z8.record(z8.string(), z8.union([z8.string(), z8.number(), z8.boolean()])).optional(),
|
|
1317
|
+
body: z8.unknown().optional()
|
|
1318
|
+
});
|
|
1319
|
+
var loaderManifestSchema = z8.object({
|
|
1320
|
+
service: z8.string(),
|
|
1321
|
+
port: z8.number().int().positive().max(65535),
|
|
1322
|
+
headers: z8.record(z8.string(), stringOrRef).optional(),
|
|
1323
|
+
outputSchema: z8.unknown(),
|
|
1324
|
+
merge: z8.literal(true).optional()
|
|
1325
|
+
});
|
|
1326
|
+
var actionManifestSchema = z8.object({
|
|
1327
|
+
service: z8.string(),
|
|
1328
|
+
port: z8.number().int().positive().max(65535),
|
|
1329
|
+
headers: z8.record(z8.string(), stringOrRef).optional(),
|
|
1330
|
+
inputSchema: z8.unknown(),
|
|
1331
|
+
outputSchema: z8.unknown().optional()
|
|
1332
|
+
});
|
|
1333
|
+
var baseSurfaceManifestSchema = z8.object({
|
|
1334
|
+
title: z8.string().min(1),
|
|
1335
|
+
// Icon name from `@yourrealm/sdk/ui/components/icons.tsx` named exports.
|
|
1336
|
+
// Runtime is just `string` (the TS-side `IconName` union catches
|
|
1337
|
+
// typos at authoring time); the Home sidebar falls back to a default
|
|
1338
|
+
// glyph if a value isn't a known export, so a typo doesn't 500.
|
|
1339
|
+
icon: z8.string().min(1),
|
|
1340
|
+
// The surface's live UI state + settings schemas (JSON Schema form).
|
|
1341
|
+
// `configSchema` (built from the config leaves' zod schemas) lets Home
|
|
1342
|
+
// validate a submitted config; `stateSchema`'s `{}`-parse seeds the
|
|
1343
|
+
// runtime's initial state.
|
|
1344
|
+
stateSchema: z8.unknown().optional(),
|
|
1345
|
+
configSchema: z8.unknown().optional(),
|
|
1346
|
+
// The config form's render descriptor: one `ConfigFieldLeaf` per
|
|
1347
|
+
// `r.input.*` leaf (type/label/placeholder/default/enum values/bounds),
|
|
1348
|
+
// so the tile's config screen reuses the same field renderer the app
|
|
1349
|
+
// install/edit form uses. Absent when the surface takes no config.
|
|
1350
|
+
configFields: z8.unknown().optional(),
|
|
1351
|
+
// The surface's resolved config: each leaf's `.prefill()` default,
|
|
1352
|
+
// shipped to the iframe as the base layer for every loader's
|
|
1353
|
+
// request(state, config) (Home merges the placement's persisted config
|
|
1354
|
+
// over it).
|
|
1355
|
+
defaultConfig: z8.unknown().optional(),
|
|
1356
|
+
loaders: z8.record(z8.string(), loaderManifestSchema).optional(),
|
|
1357
|
+
actions: z8.record(z8.string(), actionManifestSchema).optional()
|
|
1358
|
+
});
|
|
1359
|
+
var widgetManifestSchema = baseSurfaceManifestSchema.extend({
|
|
1360
|
+
cols: z8.number().int().min(1).default(2),
|
|
1361
|
+
rows: z8.number().int().min(1).default(2)
|
|
1362
|
+
});
|
|
1363
|
+
var uiManifestSchema = z8.object({
|
|
1364
|
+
pages: z8.record(z8.string(), baseSurfaceManifestSchema).optional(),
|
|
1365
|
+
widgets: z8.record(z8.string(), widgetManifestSchema).optional()
|
|
1366
|
+
});
|
|
1367
|
+
var headerFieldSchema = z8.object({ field: z8.enum(["username", "email"]) });
|
|
1368
|
+
var headerSegmentSchema = z8.union([z8.string(), headerFieldSchema]);
|
|
1369
|
+
var authHeaderSourceSchema = z8.union([
|
|
1370
|
+
headerFieldSchema,
|
|
1371
|
+
z8.object({ literal: z8.string() }),
|
|
1372
|
+
z8.object({ template: z8.array(headerSegmentSchema) })
|
|
1373
|
+
]);
|
|
1374
|
+
var trustedHeadersManifestSchema = z8.object({
|
|
1375
|
+
keys: z8.array(z8.string()),
|
|
1376
|
+
byRole: z8.record(z8.enum(["admin", "member"]), z8.record(z8.string(), authHeaderSourceSchema))
|
|
1377
|
+
});
|
|
1378
|
+
var homeAppSchema = z8.object({
|
|
1379
|
+
services: z8.record(nameSchema, homeServiceSchema),
|
|
1380
|
+
egress: z8.literal(true).optional(),
|
|
1381
|
+
ui: uiManifestSchema.optional(),
|
|
1382
|
+
trustedHeaders: trustedHeadersManifestSchema.optional(),
|
|
1383
|
+
// True when the app declares verifyAnonymousRequest. Home-side only (never
|
|
1384
|
+
// crosses to the worker wire); recompute reads it to register the app's
|
|
1385
|
+
// routed hosts in the anonymous-gate cache.
|
|
1386
|
+
hasAnonymousGate: z8.boolean().optional(),
|
|
1387
|
+
// Single = run on one selected worker (default). System = fan out to
|
|
1388
|
+
// every compatible worker. Drives the install panel's picker and the
|
|
1389
|
+
// Home's UI fan-out behavior. See platform/docs realm-ts/workers.mdx.
|
|
1390
|
+
kind: z8.enum(["single", "system"]).default("single")
|
|
1391
|
+
});
|
|
1392
|
+
function resolveDesiredApp(state, opts = {}) {
|
|
1393
|
+
const resolvedServices = {};
|
|
1394
|
+
for (const [key, service] of Object.entries(state.services ?? {})) {
|
|
1395
|
+
if (service instanceof Service) {
|
|
1396
|
+
const qualifiedKey = opts.appId ? `${opts.appId}_${key}` : key;
|
|
1397
|
+
service._setServiceKey(qualifiedKey);
|
|
1398
|
+
resolvedServices[key] = service.getServiceDefinition();
|
|
1399
|
+
} else {
|
|
1400
|
+
resolvedServices[key] = service;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
const serialized = JSON.parse(JSON.stringify({ ...state, services: resolvedServices }));
|
|
1404
|
+
const app = homeAppSchema.parse(serialized);
|
|
1405
|
+
collectRotatableSecrets(app);
|
|
1406
|
+
return app;
|
|
1407
|
+
}
|
|
1408
|
+
function collectRotatableSecrets(app) {
|
|
1409
|
+
const byName = /* @__PURE__ */ new Map();
|
|
1410
|
+
function conflict(name, message) {
|
|
1411
|
+
throw new RealmCompileError({ kind: "validation", path: ["stableSecret", name], message });
|
|
1412
|
+
}
|
|
1413
|
+
function visit(marker) {
|
|
1414
|
+
if (marker == null || typeof marker !== "object") return;
|
|
1415
|
+
const m = marker;
|
|
1416
|
+
if (m.kind === "derived" && m.appId === SELF_APP_ID && typeof m.name === "string") {
|
|
1417
|
+
const rotatable = m.rotatable === true;
|
|
1418
|
+
const description = typeof m.description === "string" ? m.description : void 0;
|
|
1419
|
+
const seen = byName.get(m.name);
|
|
1420
|
+
if (seen !== void 0 && seen.rotatable !== rotatable) {
|
|
1421
|
+
conflict(
|
|
1422
|
+
m.name,
|
|
1423
|
+
`secret ${m.name} is used both with and without rotatable: true; a secret is rotatable everywhere or nowhere`
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
if (seen?.description !== void 0 && description !== void 0 && seen.description !== description) {
|
|
1427
|
+
conflict(
|
|
1428
|
+
m.name,
|
|
1429
|
+
`secret ${m.name} is given two different descriptions; give it one, at one use or at every use`
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
byName.set(m.name, { rotatable, description: description ?? seen?.description });
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
if (m.kind === "concat") {
|
|
1436
|
+
for (const part of marker.parts ?? []) visit(part);
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
walk(marker);
|
|
1440
|
+
}
|
|
1441
|
+
function walk(node) {
|
|
1442
|
+
if (node == null || typeof node !== "object") return;
|
|
1443
|
+
if (Array.isArray(node)) {
|
|
1444
|
+
for (const v of node) walk(v);
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
if ("__realmRef" in node) {
|
|
1448
|
+
visit(node.__realmRef);
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
for (const v of Object.values(node)) walk(v);
|
|
1452
|
+
}
|
|
1453
|
+
walk(app);
|
|
1454
|
+
return [...byName].filter(([, v]) => v.rotatable).map(
|
|
1455
|
+
([name, v]) => v.description !== void 0 ? { name, description: v.description } : { name }
|
|
1456
|
+
).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1048
1459
|
// src/deep-merge.ts
|
|
1049
1460
|
function deepMergeConfig(base, over) {
|
|
1050
1461
|
const out = { ...base };
|
|
@@ -1063,7 +1474,7 @@ function isPlainMergeableObject(v) {
|
|
|
1063
1474
|
}
|
|
1064
1475
|
|
|
1065
1476
|
// src/security.ts
|
|
1066
|
-
import { z as
|
|
1477
|
+
import { z as z9 } from "zod";
|
|
1067
1478
|
|
|
1068
1479
|
// src/grants.ts
|
|
1069
1480
|
var HOST_REGISTRY = deriveHostRegistry(host_exports);
|
|
@@ -1141,11 +1552,11 @@ function permissionAllowsAppKind(kind, appKind) {
|
|
|
1141
1552
|
}
|
|
1142
1553
|
|
|
1143
1554
|
// src/security.ts
|
|
1144
|
-
var rawGrantSchema =
|
|
1145
|
-
kind:
|
|
1146
|
-
data:
|
|
1555
|
+
var rawGrantSchema = z9.object({
|
|
1556
|
+
kind: z9.string(),
|
|
1557
|
+
data: z9.unknown().optional()
|
|
1147
1558
|
});
|
|
1148
|
-
var grantsSchema =
|
|
1559
|
+
var grantsSchema = z9.record(z9.string(), rawGrantSchema);
|
|
1149
1560
|
function validateGrantData(grant) {
|
|
1150
1561
|
if (isHostGrant(grant)) {
|
|
1151
1562
|
const hooks = hostHooks(grant.kind);
|
|
@@ -1367,50 +1778,15 @@ function checkPermissionAppKinds(appKind, permissionsFlat) {
|
|
|
1367
1778
|
return violations;
|
|
1368
1779
|
}
|
|
1369
1780
|
|
|
1370
|
-
// src/app-icon.ts
|
|
1371
|
-
import { z as z7 } from "zod";
|
|
1372
|
-
var PACK_REPOS = {
|
|
1373
|
-
"dashboard-icons": "homarr-labs/dashboard-icons",
|
|
1374
|
-
selfhst: "selfhst/icons"
|
|
1375
|
-
};
|
|
1376
|
-
var PACK_KEY_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1377
|
-
var URL_UNSAFE_RE = /[\s"'<>\\`]/;
|
|
1378
|
-
var FORM_MESSAGE = 'icon must be "dashboard-icons:<key>", "selfhst:<key>" or an https:// URL';
|
|
1379
|
-
function parseIcon(spec) {
|
|
1380
|
-
for (const [prefix, repo] of Object.entries(PACK_REPOS)) {
|
|
1381
|
-
if (!spec.startsWith(`${prefix}:`)) continue;
|
|
1382
|
-
const key = spec.slice(prefix.length + 1);
|
|
1383
|
-
if (!PACK_KEY_RE.test(key)) {
|
|
1384
|
-
return {
|
|
1385
|
-
error: `${prefix} key must be lowercase and match ${PACK_KEY_RE.source}`
|
|
1386
|
-
};
|
|
1387
|
-
}
|
|
1388
|
-
return { url: `https://cdn.jsdelivr.net/gh/${repo}/svg/${key}.svg` };
|
|
1389
|
-
}
|
|
1390
|
-
if (spec.startsWith("https://")) {
|
|
1391
|
-
const rest = spec.slice("https://".length);
|
|
1392
|
-
if (rest === "") return { error: "https icon URL must have a host" };
|
|
1393
|
-
if (URL_UNSAFE_RE.test(rest))
|
|
1394
|
-
return { error: "https icon URL must not contain whitespace or quotes" };
|
|
1395
|
-
return { url: spec };
|
|
1396
|
-
}
|
|
1397
|
-
return { error: FORM_MESSAGE };
|
|
1398
|
-
}
|
|
1399
|
-
var appIconSchema = z7.string().superRefine((spec, ctx) => {
|
|
1400
|
-
const parsed = parseIcon(spec);
|
|
1401
|
-
if ("error" in parsed) ctx.addIssue({ code: "custom", message: parsed.error });
|
|
1402
|
-
});
|
|
1403
|
-
|
|
1404
1781
|
export {
|
|
1405
|
-
|
|
1406
|
-
|
|
1782
|
+
RealmCompileError,
|
|
1783
|
+
formatIssue,
|
|
1784
|
+
resolveDesiredApp,
|
|
1407
1785
|
deepMergeConfig,
|
|
1408
1786
|
defineMethod,
|
|
1409
1787
|
cloneAnd,
|
|
1410
1788
|
baseInput,
|
|
1411
1789
|
numberInput,
|
|
1412
|
-
RealmCompileError,
|
|
1413
|
-
formatIssue,
|
|
1414
1790
|
host_exports,
|
|
1415
1791
|
home_exports,
|
|
1416
1792
|
isHostGrant,
|
package/dist/cli.js
CHANGED
|
@@ -6729,13 +6729,19 @@ async function bundleUiSurfaces(source, bundledCode) {
|
|
|
6729
6729
|
function toHex(bytes) {
|
|
6730
6730
|
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6731
6731
|
}
|
|
6732
|
-
async function deriveAppPassword(seedKey, appId, name) {
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6732
|
+
async function deriveAppPassword(seedKey, appId, name, revision) {
|
|
6733
|
+
if (!Number.isInteger(revision) || revision < 0) {
|
|
6734
|
+
throw new Error(`derived secret revision must be a non-negative integer, got ${revision}`);
|
|
6735
|
+
}
|
|
6736
|
+
const parts = ["derived-password", appId, name];
|
|
6737
|
+
if (revision > 0) parts.push(revision);
|
|
6738
|
+
const message = new TextEncoder().encode(JSON.stringify(parts));
|
|
6736
6739
|
const sig = await crypto.subtle.sign("HMAC", seedKey, message);
|
|
6737
6740
|
return toHex(new Uint8Array(sig));
|
|
6738
6741
|
}
|
|
6742
|
+
function derivedRevisionKey(appId, name) {
|
|
6743
|
+
return JSON.stringify([appId, name]);
|
|
6744
|
+
}
|
|
6739
6745
|
|
|
6740
6746
|
// src/generator/resolve-refs.ts
|
|
6741
6747
|
function buildAllowMap(entries) {
|
|
@@ -6754,13 +6760,14 @@ function isMarker(value) {
|
|
|
6754
6760
|
return typeof value === "object" && value !== null && !Array.isArray(value) && "__realmRef" in value && typeof value.__realmRef === "object" && value.__realmRef !== null;
|
|
6755
6761
|
}
|
|
6756
6762
|
async function resolveDerived(appId, name, ctx) {
|
|
6757
|
-
const
|
|
6763
|
+
const revision = ctx.derivedRevisions.get(derivedRevisionKey(appId, name)) ?? 0;
|
|
6764
|
+
const cacheKey = JSON.stringify(["derived", appId, name, revision]);
|
|
6758
6765
|
const cached = ctx.derivedCache.get(cacheKey);
|
|
6759
6766
|
if (cached) return cached;
|
|
6760
6767
|
if (!ctx.derivationSeed) {
|
|
6761
6768
|
throw new RealmCompileError({ kind: "eval", message: "derivationSeed is not configured" });
|
|
6762
6769
|
}
|
|
6763
|
-
const hash = await deriveAppPassword(ctx.derivationSeed, appId, name);
|
|
6770
|
+
const hash = await deriveAppPassword(ctx.derivationSeed, appId, name, revision);
|
|
6764
6771
|
ctx.derivedCache.set(cacheKey, hash);
|
|
6765
6772
|
return hash;
|
|
6766
6773
|
}
|
|
@@ -7238,6 +7245,7 @@ async function compile(inputs) {
|
|
|
7238
7245
|
derivationSeed,
|
|
7239
7246
|
secrets,
|
|
7240
7247
|
allowedProviders: buildAllowMap(resolved.allowedProviders),
|
|
7248
|
+
derivedRevisions: /* @__PURE__ */ new Map(),
|
|
7241
7249
|
derivedCache: /* @__PURE__ */ new Map(),
|
|
7242
7250
|
runDeferred: (items) => executeDeferred(bundledCode, data, appId, items, preview)
|
|
7243
7251
|
};
|