@camstack/addon-export-hap 1.2.191 → 1.2.192
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/CHANGELOG.md +7 -0
- package/dist/hap-export.addon.js +1405 -138
- package/dist/hap-export.addon.mjs +1405 -138
- package/package.json +5 -2
|
@@ -4598,6 +4598,12 @@ var numberProcessor = (schema, ctx, _json, _params) => {
|
|
|
4598
4598
|
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4599
4599
|
json.type = "boolean";
|
|
4600
4600
|
};
|
|
4601
|
+
var bigintProcessor = (_schema, ctx, _json, _params) => {
|
|
4602
|
+
if (ctx.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
|
|
4603
|
+
};
|
|
4604
|
+
var symbolProcessor = (_schema, ctx, _json, _params) => {
|
|
4605
|
+
if (ctx.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
|
|
4606
|
+
};
|
|
4601
4607
|
var nullProcessor = (_schema, ctx, json, _params) => {
|
|
4602
4608
|
if (ctx.target === "openapi-3.0") {
|
|
4603
4609
|
json.type = "string";
|
|
@@ -4605,12 +4611,17 @@ var nullProcessor = (_schema, ctx, json, _params) => {
|
|
|
4605
4611
|
json.enum = [null];
|
|
4606
4612
|
} else json.type = "null";
|
|
4607
4613
|
};
|
|
4614
|
+
var undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
4615
|
+
if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
|
|
4616
|
+
};
|
|
4608
4617
|
var voidProcessor = (_schema, ctx, _json, _params) => {
|
|
4609
4618
|
if (ctx.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
|
|
4610
4619
|
};
|
|
4611
4620
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4612
4621
|
json.not = {};
|
|
4613
4622
|
};
|
|
4623
|
+
var anyProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4624
|
+
var unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4614
4625
|
var dateProcessor = (_schema, ctx, _json, _params) => {
|
|
4615
4626
|
if (ctx.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
|
|
4616
4627
|
};
|
|
@@ -4642,12 +4653,53 @@ var literalProcessor = (schema, ctx, json, _params) => {
|
|
|
4642
4653
|
json.enum = vals;
|
|
4643
4654
|
}
|
|
4644
4655
|
};
|
|
4656
|
+
var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
4657
|
+
if (ctx.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
|
|
4658
|
+
};
|
|
4659
|
+
var templateLiteralProcessor = (schema, _ctx, json, _params) => {
|
|
4660
|
+
const _json = json;
|
|
4661
|
+
const pattern = schema._zod.pattern;
|
|
4662
|
+
if (!pattern) throw new Error("Pattern not found in template literal");
|
|
4663
|
+
_json.type = "string";
|
|
4664
|
+
_json.pattern = pattern.source;
|
|
4665
|
+
};
|
|
4666
|
+
var fileProcessor = (schema, _ctx, json, _params) => {
|
|
4667
|
+
const _json = json;
|
|
4668
|
+
const file = {
|
|
4669
|
+
type: "string",
|
|
4670
|
+
format: "binary",
|
|
4671
|
+
contentEncoding: "binary"
|
|
4672
|
+
};
|
|
4673
|
+
const { minimum, maximum, mime } = schema._zod.bag;
|
|
4674
|
+
if (minimum !== void 0) file.minLength = minimum;
|
|
4675
|
+
if (maximum !== void 0) file.maxLength = maximum;
|
|
4676
|
+
if (mime) if (mime.length === 1) {
|
|
4677
|
+
file.contentMediaType = mime[0];
|
|
4678
|
+
Object.assign(_json, file);
|
|
4679
|
+
} else {
|
|
4680
|
+
Object.assign(_json, file);
|
|
4681
|
+
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
4682
|
+
}
|
|
4683
|
+
else Object.assign(_json, file);
|
|
4684
|
+
};
|
|
4685
|
+
var successProcessor = (_schema, _ctx, json, _params) => {
|
|
4686
|
+
json.type = "boolean";
|
|
4687
|
+
};
|
|
4645
4688
|
var customProcessor = (_schema, ctx, _json, _params) => {
|
|
4646
4689
|
if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
|
|
4647
4690
|
};
|
|
4691
|
+
var functionProcessor = (_schema, ctx, _json, _params) => {
|
|
4692
|
+
if (ctx.unrepresentable === "throw") throw new Error("Function types cannot be represented in JSON Schema");
|
|
4693
|
+
};
|
|
4648
4694
|
var transformProcessor = (_schema, ctx, _json, _params) => {
|
|
4649
4695
|
if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
|
|
4650
4696
|
};
|
|
4697
|
+
var mapProcessor = (_schema, ctx, _json, _params) => {
|
|
4698
|
+
if (ctx.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
|
|
4699
|
+
};
|
|
4700
|
+
var setProcessor = (_schema, ctx, _json, _params) => {
|
|
4701
|
+
if (ctx.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
|
|
4702
|
+
};
|
|
4651
4703
|
var arrayProcessor = (schema, ctx, _json, params) => {
|
|
4652
4704
|
const json = _json;
|
|
4653
4705
|
const def = schema._zod.def;
|
|
@@ -4852,6 +4904,12 @@ var readonlyProcessor = (schema, ctx, json, params) => {
|
|
|
4852
4904
|
seen.ref = def.innerType;
|
|
4853
4905
|
json.readOnly = true;
|
|
4854
4906
|
};
|
|
4907
|
+
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
4908
|
+
const def = schema._zod.def;
|
|
4909
|
+
process$1(def.innerType, ctx, params);
|
|
4910
|
+
const seen = ctx.seen.get(schema);
|
|
4911
|
+
seen.ref = def.innerType;
|
|
4912
|
+
};
|
|
4855
4913
|
var optionalProcessor = (schema, ctx, _json, params) => {
|
|
4856
4914
|
const def = schema._zod.def;
|
|
4857
4915
|
process$1(def.innerType, ctx, params);
|
|
@@ -4864,6 +4922,81 @@ var lazyProcessor = (schema, ctx, _json, params) => {
|
|
|
4864
4922
|
const seen = ctx.seen.get(schema);
|
|
4865
4923
|
seen.ref = innerType;
|
|
4866
4924
|
};
|
|
4925
|
+
var allProcessors = {
|
|
4926
|
+
string: stringProcessor,
|
|
4927
|
+
number: numberProcessor,
|
|
4928
|
+
boolean: booleanProcessor,
|
|
4929
|
+
bigint: bigintProcessor,
|
|
4930
|
+
symbol: symbolProcessor,
|
|
4931
|
+
null: nullProcessor,
|
|
4932
|
+
undefined: undefinedProcessor,
|
|
4933
|
+
void: voidProcessor,
|
|
4934
|
+
never: neverProcessor,
|
|
4935
|
+
any: anyProcessor,
|
|
4936
|
+
unknown: unknownProcessor,
|
|
4937
|
+
date: dateProcessor,
|
|
4938
|
+
enum: enumProcessor,
|
|
4939
|
+
literal: literalProcessor,
|
|
4940
|
+
nan: nanProcessor,
|
|
4941
|
+
template_literal: templateLiteralProcessor,
|
|
4942
|
+
file: fileProcessor,
|
|
4943
|
+
success: successProcessor,
|
|
4944
|
+
custom: customProcessor,
|
|
4945
|
+
function: functionProcessor,
|
|
4946
|
+
transform: transformProcessor,
|
|
4947
|
+
map: mapProcessor,
|
|
4948
|
+
set: setProcessor,
|
|
4949
|
+
array: arrayProcessor,
|
|
4950
|
+
object: objectProcessor,
|
|
4951
|
+
union: unionProcessor,
|
|
4952
|
+
intersection: intersectionProcessor,
|
|
4953
|
+
tuple: tupleProcessor,
|
|
4954
|
+
record: recordProcessor,
|
|
4955
|
+
nullable: nullableProcessor,
|
|
4956
|
+
nonoptional: nonoptionalProcessor,
|
|
4957
|
+
default: defaultProcessor,
|
|
4958
|
+
prefault: prefaultProcessor,
|
|
4959
|
+
catch: catchProcessor,
|
|
4960
|
+
pipe: pipeProcessor,
|
|
4961
|
+
readonly: readonlyProcessor,
|
|
4962
|
+
promise: promiseProcessor,
|
|
4963
|
+
optional: optionalProcessor,
|
|
4964
|
+
lazy: lazyProcessor
|
|
4965
|
+
};
|
|
4966
|
+
function toJSONSchema(input, params) {
|
|
4967
|
+
if ("_idmap" in input) {
|
|
4968
|
+
const registry = input;
|
|
4969
|
+
const ctx = initializeContext({
|
|
4970
|
+
...params,
|
|
4971
|
+
processors: allProcessors
|
|
4972
|
+
});
|
|
4973
|
+
const defs = {};
|
|
4974
|
+
for (const entry of registry._idmap.entries()) {
|
|
4975
|
+
const [_, schema] = entry;
|
|
4976
|
+
process$1(schema, ctx);
|
|
4977
|
+
}
|
|
4978
|
+
const schemas = {};
|
|
4979
|
+
ctx.external = {
|
|
4980
|
+
registry,
|
|
4981
|
+
uri: params?.uri,
|
|
4982
|
+
defs
|
|
4983
|
+
};
|
|
4984
|
+
for (const entry of registry._idmap.entries()) {
|
|
4985
|
+
const [key, schema] = entry;
|
|
4986
|
+
extractDefs(ctx, schema);
|
|
4987
|
+
schemas[key] = finalize(ctx, schema);
|
|
4988
|
+
}
|
|
4989
|
+
if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
|
|
4990
|
+
return { schemas };
|
|
4991
|
+
}
|
|
4992
|
+
const ctx = initializeContext({
|
|
4993
|
+
...params,
|
|
4994
|
+
processors: allProcessors
|
|
4995
|
+
});
|
|
4996
|
+
process$1(input, ctx);
|
|
4997
|
+
extractDefs(ctx, input);
|
|
4998
|
+
return finalize(ctx, input);
|
|
4999
|
+
}
|
|
4867
5000
|
//#endregion
|
|
4868
5001
|
//#region ../../node_modules/zod/v4/classic/iso.js
|
|
4869
5002
|
var ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
@@ -5888,7 +6021,7 @@ var ZodIssueCode = {
|
|
|
5888
6021
|
var ZodFirstPartyTypeKind;
|
|
5889
6022
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5890
6023
|
//#endregion
|
|
5891
|
-
//#region ../types/dist/sleep-
|
|
6024
|
+
//#region ../types/dist/sleep-BaWhXZFm.mjs
|
|
5892
6025
|
/**
|
|
5893
6026
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5894
6027
|
* window to float samples (D455).
|
|
@@ -6036,9 +6169,16 @@ function isSecretMarker(value) {
|
|
|
6036
6169
|
const ref = value["$secret"];
|
|
6037
6170
|
return typeof ref === "string" && ref.length > 0;
|
|
6038
6171
|
}
|
|
6172
|
+
/** Anything carrying a `$secret` key — a stored marker or a UI view of one. */
|
|
6173
|
+
function isSecretMarkerLike(value) {
|
|
6174
|
+
return isRecord$7(value) && Object.prototype.hasOwnProperty.call(value, "$secret");
|
|
6175
|
+
}
|
|
6039
6176
|
function isSecretClear(value) {
|
|
6040
6177
|
return isRecord$7(value) && value["$secretClear"] === true;
|
|
6041
6178
|
}
|
|
6179
|
+
function isSecretFieldView(value) {
|
|
6180
|
+
return isRecord$7(value) && value["set"] === true && isSecretMarkerLike(value);
|
|
6181
|
+
}
|
|
6042
6182
|
/**
|
|
6043
6183
|
* The UI view of a stored secret field value: a marker becomes "set", inline
|
|
6044
6184
|
* plaintext becomes "set (inline)", nothing becomes `null`. A value never
|
|
@@ -6688,11 +6828,36 @@ function projectStore(store, perNodeKeys, nodeId) {
|
|
|
6688
6828
|
}
|
|
6689
6829
|
return out;
|
|
6690
6830
|
}
|
|
6831
|
+
/**
|
|
6832
|
+
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
6833
|
+
*
|
|
6834
|
+
* A ref is DETERMINISTIC from where the value lives — the owner addon, the
|
|
6835
|
+
* scope (global, one node, one device, one integration, one row of a business
|
|
6836
|
+
* collection) and the field path inside that scope — so saving the same field
|
|
6837
|
+
* twice updates the same ref, and the ref itself says which settings blob
|
|
6838
|
+
* points at it. It is also the AAD of the value's ciphertext: a ciphertext
|
|
6839
|
+
* copied onto another ref does not decrypt.
|
|
6840
|
+
*
|
|
6841
|
+
* Array items are addressed by ITEM ID, never by index
|
|
6842
|
+
* (`providers[authentik].clientSecret`), so reordering a list keeps every ref.
|
|
6843
|
+
*
|
|
6844
|
+
* Pure and browser-safe: no node builtins, no I/O.
|
|
6845
|
+
*/
|
|
6846
|
+
/** The URI scheme of every keychain ref. */
|
|
6847
|
+
var SECRET_REF_SCHEME = "secret://";
|
|
6691
6848
|
var GLOBAL_SCOPE = { kind: "global" };
|
|
6692
6849
|
/** The scope every addon-wide (not per-node, not per-device) setting lives in. */
|
|
6693
6850
|
function globalSecretScope() {
|
|
6694
6851
|
return GLOBAL_SCOPE;
|
|
6695
6852
|
}
|
|
6853
|
+
/**
|
|
6854
|
+
* An addon id as a ref owner. A hub in-process builtin's context id is
|
|
6855
|
+
* `addon:<id>`; the owner of its secrets is `<id>`, exactly as for the same
|
|
6856
|
+
* addon running forked.
|
|
6857
|
+
*/
|
|
6858
|
+
function normalizeSecretOwner(addonId) {
|
|
6859
|
+
return addonId.startsWith("addon:") ? addonId.slice(6) : addonId;
|
|
6860
|
+
}
|
|
6696
6861
|
function encodeSegment(value) {
|
|
6697
6862
|
return encodeURIComponent(value);
|
|
6698
6863
|
}
|
|
@@ -6703,6 +6868,16 @@ function decodeSegment(value) {
|
|
|
6703
6868
|
return null;
|
|
6704
6869
|
}
|
|
6705
6870
|
}
|
|
6871
|
+
/** The scope as it appears inside a ref (`global`, `node/<id>`, …). */
|
|
6872
|
+
function formatSecretScope(scope) {
|
|
6873
|
+
switch (scope.kind) {
|
|
6874
|
+
case "global": return "global";
|
|
6875
|
+
case "node": return `node/${encodeSegment(scope.nodeId)}`;
|
|
6876
|
+
case "device": return `device/${scope.deviceId}`;
|
|
6877
|
+
case "integration": return `integration/${encodeSegment(scope.integrationId)}`;
|
|
6878
|
+
case "row": return `row/${encodeSegment(scope.collection)}/${encodeSegment(scope.rowId)}`;
|
|
6879
|
+
}
|
|
6880
|
+
}
|
|
6706
6881
|
/**
|
|
6707
6882
|
* The field path of a value inside an array item, addressed by the item's id:
|
|
6708
6883
|
* `arrayItemFieldPath('providers', 'authentik', 'clientSecret')` →
|
|
@@ -6711,6 +6886,13 @@ function decodeSegment(value) {
|
|
|
6711
6886
|
function arrayItemFieldPath(arrayKey, itemId, fieldKey) {
|
|
6712
6887
|
return `${arrayKey}[${encodeSegment(itemId)}].${fieldKey}`;
|
|
6713
6888
|
}
|
|
6889
|
+
/** Build a ref. Throws on an empty owner or field path — both are bugs. */
|
|
6890
|
+
function buildSecretRef(parts) {
|
|
6891
|
+
const owner = normalizeSecretOwner(parts.owner);
|
|
6892
|
+
if (owner.length === 0) throw new Error("buildSecretRef: owner is empty");
|
|
6893
|
+
if (parts.fieldPath.length === 0) throw new Error("buildSecretRef: fieldPath is empty");
|
|
6894
|
+
return `${SECRET_REF_SCHEME}${encodeSegment(owner)}/${formatSecretScope(parts.scope)}/${parts.fieldPath}`;
|
|
6895
|
+
}
|
|
6714
6896
|
function parseScope(segments) {
|
|
6715
6897
|
switch (segments[0]) {
|
|
6716
6898
|
case "global": return {
|
|
@@ -6851,7 +7033,7 @@ async function writeMembers(ctx, children, incoming, stored, pathOf) {
|
|
|
6851
7033
|
for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
|
|
6852
7034
|
return out;
|
|
6853
7035
|
}
|
|
6854
|
-
function rowId(row, idKey) {
|
|
7036
|
+
function rowId$1(row, idKey) {
|
|
6855
7037
|
const raw = row[idKey];
|
|
6856
7038
|
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
6857
7039
|
if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
|
|
@@ -6868,7 +7050,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6868
7050
|
}
|
|
6869
7051
|
const storedById = /* @__PURE__ */ new Map();
|
|
6870
7052
|
for (const row of storedRows) {
|
|
6871
|
-
const id = rowId(row, node.idKey);
|
|
7053
|
+
const id = rowId$1(row, node.idKey);
|
|
6872
7054
|
if (id !== null) storedById.set(id, row);
|
|
6873
7055
|
}
|
|
6874
7056
|
const kept = /* @__PURE__ */ new Set();
|
|
@@ -6878,13 +7060,13 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6878
7060
|
rows.push(row);
|
|
6879
7061
|
continue;
|
|
6880
7062
|
}
|
|
6881
|
-
const id = rowId(row, node.idKey) ?? ctx.mintId();
|
|
7063
|
+
const id = rowId$1(row, node.idKey) ?? ctx.mintId();
|
|
6882
7064
|
kept.add(id);
|
|
6883
7065
|
const withId = {
|
|
6884
7066
|
...row,
|
|
6885
7067
|
[node.idKey]: row[node.idKey] ?? id
|
|
6886
7068
|
};
|
|
6887
|
-
if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
7069
|
+
if (rowId$1(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
6888
7070
|
const storedRow = storedById.get(id) ?? {};
|
|
6889
7071
|
rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
|
|
6890
7072
|
}
|
|
@@ -8619,6 +8801,45 @@ function normalizeAddonInitResult(result) {
|
|
|
8619
8801
|
if (Array.isArray(result)) return { providers: result };
|
|
8620
8802
|
return result;
|
|
8621
8803
|
}
|
|
8804
|
+
var PREFIX = "records/";
|
|
8805
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8806
|
+
var RecordsError = class extends Error {
|
|
8807
|
+
code;
|
|
8808
|
+
detail;
|
|
8809
|
+
constructor(code, detail) {
|
|
8810
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
8811
|
+
this.name = "RecordsError";
|
|
8812
|
+
this.code = code;
|
|
8813
|
+
this.detail = detail;
|
|
8814
|
+
}
|
|
8815
|
+
};
|
|
8816
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8817
|
+
var RevConflictError = class extends RecordsError {
|
|
8818
|
+
constructor(detail) {
|
|
8819
|
+
super("rev-conflict", detail);
|
|
8820
|
+
this.name = "RevConflictError";
|
|
8821
|
+
}
|
|
8822
|
+
};
|
|
8823
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
8824
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
8825
|
+
constructor(detail) {
|
|
8826
|
+
super("secret-unavailable", detail);
|
|
8827
|
+
this.name = "RecordSecretUnavailableError";
|
|
8828
|
+
}
|
|
8829
|
+
};
|
|
8830
|
+
var InvalidRecordError = class extends RecordsError {
|
|
8831
|
+
constructor(detail) {
|
|
8832
|
+
super("invalid-record", detail);
|
|
8833
|
+
this.name = "InvalidRecordError";
|
|
8834
|
+
}
|
|
8835
|
+
};
|
|
8836
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8837
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
8838
|
+
constructor(detail) {
|
|
8839
|
+
super("declaration-refused", detail);
|
|
8840
|
+
this.name = "DeclarationRefusedError";
|
|
8841
|
+
}
|
|
8842
|
+
};
|
|
8622
8843
|
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8623
8844
|
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8624
8845
|
var RECORD_DATABASES = ["settings", "events"];
|
|
@@ -8634,6 +8855,174 @@ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
|
8634
8855
|
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8635
8856
|
var RECORD_BATCH_MAX = 1e3;
|
|
8636
8857
|
var RECORD_QUERY_MAX = 1e3;
|
|
8858
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8859
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8860
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
8861
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
8862
|
+
/**
|
|
8863
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8864
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8865
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
8866
|
+
*
|
|
8867
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8868
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8869
|
+
* key releases exactly that key's secret.
|
|
8870
|
+
*
|
|
8871
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8872
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8873
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8874
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
8875
|
+
*
|
|
8876
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
8877
|
+
*/
|
|
8878
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
8879
|
+
function parseSecretPath(path) {
|
|
8880
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8881
|
+
return path.split(".").map((raw) => {
|
|
8882
|
+
const each = raw.endsWith("[]");
|
|
8883
|
+
const map = raw.endsWith("{}");
|
|
8884
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8885
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8886
|
+
return {
|
|
8887
|
+
key,
|
|
8888
|
+
each,
|
|
8889
|
+
map
|
|
8890
|
+
};
|
|
8891
|
+
});
|
|
8892
|
+
}
|
|
8893
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8894
|
+
function secretArrayPrefixes(path) {
|
|
8895
|
+
const segments = parseSecretPath(path);
|
|
8896
|
+
const prefixes = [];
|
|
8897
|
+
const walked = [];
|
|
8898
|
+
for (const segment of segments) {
|
|
8899
|
+
walked.push(segment.key);
|
|
8900
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
8901
|
+
}
|
|
8902
|
+
return prefixes;
|
|
8903
|
+
}
|
|
8904
|
+
function isRecord$4(value) {
|
|
8905
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8906
|
+
}
|
|
8907
|
+
function elementId(element, idKey, declared, prefix) {
|
|
8908
|
+
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
8909
|
+
if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
|
|
8910
|
+
return id;
|
|
8911
|
+
}
|
|
8912
|
+
/**
|
|
8913
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
8914
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
8915
|
+
* result is a new body, `data` is untouched.
|
|
8916
|
+
*/
|
|
8917
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
8918
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
8919
|
+
if (!isRecord$4(node)) return node;
|
|
8920
|
+
const segment = segments[index];
|
|
8921
|
+
if (segment === void 0) return node;
|
|
8922
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
8923
|
+
const child = node[segment.key];
|
|
8924
|
+
const keys = [...walkedKeys, segment.key];
|
|
8925
|
+
const last = index === segments.length - 1;
|
|
8926
|
+
if (segment.each) {
|
|
8927
|
+
if (!Array.isArray(child)) return node;
|
|
8928
|
+
const prefix = keys.join(".");
|
|
8929
|
+
const idKey = arrayKeys[prefix];
|
|
8930
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
8931
|
+
const mapped = child.map((element) => {
|
|
8932
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
8933
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
8934
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
8935
|
+
});
|
|
8936
|
+
return {
|
|
8937
|
+
...node,
|
|
8938
|
+
[segment.key]: mapped
|
|
8939
|
+
};
|
|
8940
|
+
}
|
|
8941
|
+
if (segment.map) {
|
|
8942
|
+
if (!isRecord$4(child)) return node;
|
|
8943
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
8944
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
8945
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
8946
|
+
return [mapKey, visit({
|
|
8947
|
+
declared,
|
|
8948
|
+
concrete,
|
|
8949
|
+
value
|
|
8950
|
+
})];
|
|
8951
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
8952
|
+
return {
|
|
8953
|
+
...node,
|
|
8954
|
+
[segment.key]: Object.fromEntries(kept)
|
|
8955
|
+
};
|
|
8956
|
+
}
|
|
8957
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
8958
|
+
if (last) {
|
|
8959
|
+
const replacement = visit({
|
|
8960
|
+
declared,
|
|
8961
|
+
concrete,
|
|
8962
|
+
value: child
|
|
8963
|
+
});
|
|
8964
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
8965
|
+
return {
|
|
8966
|
+
...node,
|
|
8967
|
+
[segment.key]: replacement
|
|
8968
|
+
};
|
|
8969
|
+
}
|
|
8970
|
+
return {
|
|
8971
|
+
...node,
|
|
8972
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
8973
|
+
};
|
|
8974
|
+
}
|
|
8975
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
8976
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
8977
|
+
let current = data;
|
|
8978
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
8979
|
+
return current;
|
|
8980
|
+
}
|
|
8981
|
+
/**
|
|
8982
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
8983
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
8984
|
+
* already holds during an adoption.
|
|
8985
|
+
*/
|
|
8986
|
+
function recordSecretCollection(kind) {
|
|
8987
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
8988
|
+
}
|
|
8989
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
8990
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
8991
|
+
return buildSecretRef({
|
|
8992
|
+
owner,
|
|
8993
|
+
scope: {
|
|
8994
|
+
kind: "row",
|
|
8995
|
+
collection: recordSecretCollection(kind),
|
|
8996
|
+
rowId
|
|
8997
|
+
},
|
|
8998
|
+
fieldPath: concretePath
|
|
8999
|
+
});
|
|
9000
|
+
}
|
|
9001
|
+
/**
|
|
9002
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
9003
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
9004
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
9005
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
9006
|
+
* stored secret (the records door reads a view as KEEP).
|
|
9007
|
+
*
|
|
9008
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
9009
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
9010
|
+
*/
|
|
9011
|
+
function isRecord$3(value) {
|
|
9012
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9013
|
+
}
|
|
9014
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
9015
|
+
if (decl.secretPaths.length === 0) return data;
|
|
9016
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
9017
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
9018
|
+
return {
|
|
9019
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
9020
|
+
v: 1,
|
|
9021
|
+
set: true
|
|
9022
|
+
};
|
|
9023
|
+
});
|
|
9024
|
+
return isRecord$3(shown) ? shown : data;
|
|
9025
|
+
}
|
|
8637
9026
|
/**
|
|
8638
9027
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
8639
9028
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -8658,6 +9047,75 @@ var PeerBytesTicketSchema = object({
|
|
|
8658
9047
|
*/
|
|
8659
9048
|
declaredBytes: number().int().nonnegative().nullable()
|
|
8660
9049
|
});
|
|
9050
|
+
function defOf(schema) {
|
|
9051
|
+
const zodBag = Reflect.get(schema, "_zod");
|
|
9052
|
+
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
9053
|
+
const def = Reflect.get(zodBag, "def");
|
|
9054
|
+
if (typeof def !== "object" || def === null) return {};
|
|
9055
|
+
return def;
|
|
9056
|
+
}
|
|
9057
|
+
function declaredHere(schema) {
|
|
9058
|
+
return globalRegistry.get(schema)?.secret === true;
|
|
9059
|
+
}
|
|
9060
|
+
/** Wrapper kinds whose `innerType` is the field itself. */
|
|
9061
|
+
var WRAPPERS = new Set([
|
|
9062
|
+
"optional",
|
|
9063
|
+
"nullable",
|
|
9064
|
+
"default",
|
|
9065
|
+
"prefault",
|
|
9066
|
+
"catch",
|
|
9067
|
+
"readonly",
|
|
9068
|
+
"nonoptional"
|
|
9069
|
+
]);
|
|
9070
|
+
/**
|
|
9071
|
+
* The schema layers that make up ONE field: the schema itself and every
|
|
9072
|
+
* wrapper below it (optional / default / nullable / readonly / catch), plus
|
|
9073
|
+
* both sides of a pipe (`z.preprocess` puts the real schema on `out`,
|
|
9074
|
+
* `.transform` on `in`).
|
|
9075
|
+
*/
|
|
9076
|
+
function layersOf(schema) {
|
|
9077
|
+
const out = [];
|
|
9078
|
+
const queue = [schema];
|
|
9079
|
+
while (queue.length > 0) {
|
|
9080
|
+
const s = queue.shift();
|
|
9081
|
+
if (!s || out.includes(s)) continue;
|
|
9082
|
+
out.push(s);
|
|
9083
|
+
const def = defOf(s);
|
|
9084
|
+
if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
|
|
9085
|
+
if (def.type === "pipe") {
|
|
9086
|
+
if (def.in) queue.push(def.in);
|
|
9087
|
+
if (def.out) queue.push(def.out);
|
|
9088
|
+
}
|
|
9089
|
+
}
|
|
9090
|
+
return out;
|
|
9091
|
+
}
|
|
9092
|
+
/** True when any layer of this field declares `.meta({ secret: true })`. */
|
|
9093
|
+
function isZodSecret(schema) {
|
|
9094
|
+
return layersOf(schema).some(declaredHere);
|
|
9095
|
+
}
|
|
9096
|
+
/**
|
|
9097
|
+
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
9098
|
+
* element of this array" (`connection.password`, `rows[].token`), `{}` for "each value of this
|
|
9099
|
+
* map" (`applianceSecrets{}`). A declared
|
|
9100
|
+
* object or array is reported as one path and not descended into — everything
|
|
9101
|
+
* under it is secret.
|
|
9102
|
+
*/
|
|
9103
|
+
function collectZodSecretPaths(schema, prefix = "") {
|
|
9104
|
+
if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
|
|
9105
|
+
const paths = [];
|
|
9106
|
+
for (const layer of layersOf(schema)) {
|
|
9107
|
+
const def = defOf(layer);
|
|
9108
|
+
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
9109
|
+
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
9110
|
+
else if (def.type === "record" && def.valueType) paths.push(...collectZodSecretPaths(def.valueType, `${prefix}{}`));
|
|
9111
|
+
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
9112
|
+
else if (def.type === "intersection") {
|
|
9113
|
+
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
9114
|
+
if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
|
|
9115
|
+
}
|
|
9116
|
+
}
|
|
9117
|
+
return [...new Set(paths)];
|
|
9118
|
+
}
|
|
8661
9119
|
/**
|
|
8662
9120
|
* Record kinds (D881): the declaration an addon makes of one kind of fact, the
|
|
8663
9121
|
* Zod row schema that describes it, and the helper that turns the two into the
|
|
@@ -8724,6 +9182,111 @@ var RecordKindDeclarationSchema = object({
|
|
|
8724
9182
|
}).strict();
|
|
8725
9183
|
/** The kind names: lower-case, dash separated, short enough for an index name. */
|
|
8726
9184
|
var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
|
|
9185
|
+
/** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
|
|
9186
|
+
function assertValidDeclaration(name, decl) {
|
|
9187
|
+
const refuse = (why) => {
|
|
9188
|
+
throw new DeclarationRefusedError(`kind "${name}": ${why}`);
|
|
9189
|
+
};
|
|
9190
|
+
if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
|
|
9191
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9192
|
+
for (const index of decl.indexes) {
|
|
9193
|
+
if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
|
|
9194
|
+
seen.add(index.name);
|
|
9195
|
+
}
|
|
9196
|
+
const { retention } = decl;
|
|
9197
|
+
const hasSecrets = decl.secretPaths.length > 0;
|
|
9198
|
+
if ("ttlMs" in retention) {
|
|
9199
|
+
if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
|
|
9200
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
|
|
9201
|
+
}
|
|
9202
|
+
if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
|
|
9203
|
+
if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
|
|
9204
|
+
if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
|
|
9205
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
|
|
9206
|
+
const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
|
|
9207
|
+
if (decl.database === "settings" && bound > 5e4) refuse(`a row bound above ${RECORD_SETTINGS_MAX_ROWS} belongs in database: "events" (a big delete on the settings thread stalls every configuration read)`);
|
|
9208
|
+
}
|
|
9209
|
+
if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
|
|
9210
|
+
for (const path of decl.secretPaths) for (const prefix of secretArrayPrefixes(path)) if (decl.secretArrayKeys[prefix] === void 0) refuse(`secret path "${path}" crosses the array "${prefix}": declare its id key in secretArrayKeys`);
|
|
9211
|
+
}
|
|
9212
|
+
function bodyFieldsOf(schema) {
|
|
9213
|
+
return { ...toJSONSchema(schema, {
|
|
9214
|
+
unrepresentable: "any",
|
|
9215
|
+
io: "input"
|
|
9216
|
+
}) };
|
|
9217
|
+
}
|
|
9218
|
+
function isRecordLike(value) {
|
|
9219
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9220
|
+
}
|
|
9221
|
+
/** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
|
|
9222
|
+
function hasNameField(json, field) {
|
|
9223
|
+
const branches = json["oneOf"] ?? json["anyOf"];
|
|
9224
|
+
if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
|
|
9225
|
+
const properties = json["properties"];
|
|
9226
|
+
return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
|
|
9227
|
+
}
|
|
9228
|
+
/**
|
|
9229
|
+
* Declare the kinds of a package. The keys are the kind names. The result is
|
|
9230
|
+
* what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
|
|
9231
|
+
* types its handle from.
|
|
9232
|
+
*/
|
|
9233
|
+
function defineRecordKinds(specs) {
|
|
9234
|
+
const out = {};
|
|
9235
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
9236
|
+
const secretPaths = collectZodSecretPaths(spec.schema);
|
|
9237
|
+
const nameField = spec.entry?.nameField ?? "name";
|
|
9238
|
+
const fields = bodyFieldsOf(spec.schema);
|
|
9239
|
+
if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
|
|
9240
|
+
const parsed = RecordKindDeclarationSchema.parse({
|
|
9241
|
+
database: spec.database,
|
|
9242
|
+
class: spec.class,
|
|
9243
|
+
writeTrigger: spec.writeTrigger,
|
|
9244
|
+
device: spec.device,
|
|
9245
|
+
at: spec.at,
|
|
9246
|
+
indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
|
|
9247
|
+
retention: spec.retention,
|
|
9248
|
+
deviceRemoval: spec.deviceRemoval,
|
|
9249
|
+
maxDataBytes: spec.maxDataBytes,
|
|
9250
|
+
secretPaths: [...new Set([...secretPaths, ...spec.retiredSecretPaths ?? []])],
|
|
9251
|
+
secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
|
|
9252
|
+
transactFamily: spec.transactFamily,
|
|
9253
|
+
entry: spec.entry === void 0 ? void 0 : {
|
|
9254
|
+
title: spec.entry.title,
|
|
9255
|
+
nameField,
|
|
9256
|
+
fields
|
|
9257
|
+
}
|
|
9258
|
+
});
|
|
9259
|
+
assertValidDeclaration(name, parsed);
|
|
9260
|
+
out[name] = {
|
|
9261
|
+
name,
|
|
9262
|
+
schema: spec.schema,
|
|
9263
|
+
declaration: parsed
|
|
9264
|
+
};
|
|
9265
|
+
}
|
|
9266
|
+
return out;
|
|
9267
|
+
}
|
|
9268
|
+
/**
|
|
9269
|
+
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
9270
|
+
* engine, never aged, belonging to no device.
|
|
9271
|
+
*/
|
|
9272
|
+
function defineEntryKind(name, spec) {
|
|
9273
|
+
const defined = defineRecordKinds({ [name]: {
|
|
9274
|
+
schema: spec.schema,
|
|
9275
|
+
class: "config",
|
|
9276
|
+
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
9277
|
+
retention: { none: "an entry goes only when the operator deletes it" },
|
|
9278
|
+
...spec.database === void 0 ? {} : { database: spec.database },
|
|
9279
|
+
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
9280
|
+
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
9281
|
+
...spec.retiredSecretPaths === void 0 ? {} : { retiredSecretPaths: spec.retiredSecretPaths },
|
|
9282
|
+
entry: {
|
|
9283
|
+
title: spec.title,
|
|
9284
|
+
...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
|
|
9285
|
+
}
|
|
9286
|
+
} })[name];
|
|
9287
|
+
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
9288
|
+
return defined;
|
|
9289
|
+
}
|
|
8727
9290
|
object({
|
|
8728
9291
|
field: string().min(1),
|
|
8729
9292
|
on: literal("advance")
|
|
@@ -13379,6 +13942,205 @@ var IntegrationInstanceRefSchema = object({
|
|
|
13379
13942
|
]),
|
|
13380
13943
|
candidateStableId: string().optional()
|
|
13381
13944
|
});
|
|
13945
|
+
/**
|
|
13946
|
+
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
13947
|
+
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
13948
|
+
*
|
|
13949
|
+
* Every instance is one record of the addon's own kind, keyed by the
|
|
13950
|
+
* `integrations` registry id. The records door does the secret work: a field the
|
|
13951
|
+
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
13952
|
+
* deleting the row deletes the secret, and one row's value is never another's.
|
|
13953
|
+
*
|
|
13954
|
+
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
13955
|
+
* token or the view the form was given KEEP the stored secret;
|
|
13956
|
+
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
13957
|
+
*/
|
|
13958
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
13959
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
13960
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
13961
|
+
function topLevelSecretKeys(paths) {
|
|
13962
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
13963
|
+
}
|
|
13964
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
13965
|
+
function secretMapKeys(paths) {
|
|
13966
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
13967
|
+
}
|
|
13968
|
+
/**
|
|
13969
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
13970
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
13971
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
13972
|
+
*/
|
|
13973
|
+
function secretMapPatch(value) {
|
|
13974
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13975
|
+
const out = {};
|
|
13976
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
13977
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
13978
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
13979
|
+
}
|
|
13980
|
+
/** Does the kind's body schema carry an `enabled` field? */
|
|
13981
|
+
function declaresEnabled(kind) {
|
|
13982
|
+
const json = toJSONSchema(kind.schema, {
|
|
13983
|
+
unrepresentable: "any",
|
|
13984
|
+
io: "input"
|
|
13985
|
+
});
|
|
13986
|
+
const properties = Reflect.get(json, "properties");
|
|
13987
|
+
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
13988
|
+
}
|
|
13989
|
+
var RecordIntegrationInstances = class {
|
|
13990
|
+
records;
|
|
13991
|
+
kind;
|
|
13992
|
+
hooks;
|
|
13993
|
+
handle;
|
|
13994
|
+
secretKeys;
|
|
13995
|
+
secretMaps;
|
|
13996
|
+
nameField;
|
|
13997
|
+
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
13998
|
+
registryOwnsEnabled;
|
|
13999
|
+
constructor(records, kind, hooks) {
|
|
14000
|
+
this.records = records;
|
|
14001
|
+
this.kind = kind;
|
|
14002
|
+
this.hooks = hooks;
|
|
14003
|
+
this.handle = records.kind(kind);
|
|
14004
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
14005
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
14006
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
14007
|
+
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
14008
|
+
if (this.registryOwnsEnabled && declaresEnabled(kind)) throw new Error(`kind "${kind.name}": the integrations registry owns the on/off switch of a role "devices" addon, so the body must not declare "enabled"`);
|
|
14009
|
+
}
|
|
14010
|
+
/**
|
|
14011
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
14012
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
14013
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
14014
|
+
*/
|
|
14015
|
+
async readResolved(id) {
|
|
14016
|
+
try {
|
|
14017
|
+
const record = await this.handle.getResolved(id);
|
|
14018
|
+
return record === null ? null : {
|
|
14019
|
+
id,
|
|
14020
|
+
body: record.data,
|
|
14021
|
+
enabled: record.data.enabled !== false,
|
|
14022
|
+
secrets: "resolved"
|
|
14023
|
+
};
|
|
14024
|
+
} catch (err) {
|
|
14025
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
14026
|
+
const stored = await this.handle.get(id);
|
|
14027
|
+
if (stored === null) return null;
|
|
14028
|
+
return {
|
|
14029
|
+
id,
|
|
14030
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
14031
|
+
enabled: stored.data.enabled !== false,
|
|
14032
|
+
secrets: "unavailable"
|
|
14033
|
+
};
|
|
14034
|
+
}
|
|
14035
|
+
}
|
|
14036
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
14037
|
+
async getResolved(id) {
|
|
14038
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
14039
|
+
}
|
|
14040
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
14041
|
+
async listResolved() {
|
|
14042
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
14043
|
+
const out = [];
|
|
14044
|
+
for (const record of page.records) {
|
|
14045
|
+
const read = await this.readResolved(record.id);
|
|
14046
|
+
if (read !== null) out.push(read);
|
|
14047
|
+
}
|
|
14048
|
+
return out;
|
|
14049
|
+
}
|
|
14050
|
+
viewOf(record) {
|
|
14051
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
14052
|
+
const rawName = record.data[this.nameField];
|
|
14053
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
14054
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
14055
|
+
return {
|
|
14056
|
+
id: record.id,
|
|
14057
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
14058
|
+
configured: this.hooks.configured(record.data),
|
|
14059
|
+
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
14060
|
+
formValues: shown,
|
|
14061
|
+
...kind !== void 0 ? { kind } : {},
|
|
14062
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
14063
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
14064
|
+
};
|
|
14065
|
+
}
|
|
14066
|
+
describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
|
|
14067
|
+
...this.hooks.description,
|
|
14068
|
+
mintsId: true
|
|
14069
|
+
};
|
|
14070
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
14071
|
+
listInstances = async () => {
|
|
14072
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
14073
|
+
};
|
|
14074
|
+
getInstance = async ({ id }) => {
|
|
14075
|
+
const record = await this.handle.get(id);
|
|
14076
|
+
return record === null ? null : this.viewOf(record);
|
|
14077
|
+
};
|
|
14078
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
14079
|
+
createInstance = async ({ id, name, kind }) => {
|
|
14080
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
14081
|
+
name,
|
|
14082
|
+
...kind !== void 0 ? { kind } : {}
|
|
14083
|
+
});
|
|
14084
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
14085
|
+
await this.handle.put({
|
|
14086
|
+
id: minted,
|
|
14087
|
+
data: this.hooks.initialBody(name, kind)
|
|
14088
|
+
}, { ifRev: 0 });
|
|
14089
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
14090
|
+
return { id: minted };
|
|
14091
|
+
};
|
|
14092
|
+
updateInstance = async ({ id, name, values }) => {
|
|
14093
|
+
const patch = {};
|
|
14094
|
+
for (const [key, value] of Object.entries(values)) {
|
|
14095
|
+
if (value === void 0) continue;
|
|
14096
|
+
if (this.secretMaps.has(key)) {
|
|
14097
|
+
const entries = secretMapPatch(value);
|
|
14098
|
+
if (entries !== null) patch[key] = entries;
|
|
14099
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
14100
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
14101
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
14102
|
+
}
|
|
14103
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
14104
|
+
await this.handle.patch(id, patch);
|
|
14105
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
14106
|
+
return { ok: true };
|
|
14107
|
+
};
|
|
14108
|
+
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
14109
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
14110
|
+
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
14111
|
+
await this.handle.patch(id, { enabled });
|
|
14112
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
14113
|
+
return { ok: true };
|
|
14114
|
+
};
|
|
14115
|
+
/** The row and its keychain refs go together (the records door). */
|
|
14116
|
+
deleteInstance = async ({ id }) => {
|
|
14117
|
+
await this.handle.delete(id);
|
|
14118
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
14119
|
+
return { ok: true };
|
|
14120
|
+
};
|
|
14121
|
+
testInstance = async (input) => {
|
|
14122
|
+
if (this.hooks.test === void 0) return {
|
|
14123
|
+
success: false,
|
|
14124
|
+
status: "unsupported",
|
|
14125
|
+
error: "This integration declares no connection test"
|
|
14126
|
+
};
|
|
14127
|
+
return this.hooks.test(input);
|
|
14128
|
+
};
|
|
14129
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
14130
|
+
toProvider() {
|
|
14131
|
+
return {
|
|
14132
|
+
describe: this.describe,
|
|
14133
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
14134
|
+
listInstances: this.listInstances,
|
|
14135
|
+
getInstance: this.getInstance,
|
|
14136
|
+
createInstance: this.createInstance,
|
|
14137
|
+
updateInstance: this.updateInstance,
|
|
14138
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
14139
|
+
deleteInstance: this.deleteInstance,
|
|
14140
|
+
testInstance: this.testInstance
|
|
14141
|
+
};
|
|
14142
|
+
}
|
|
14143
|
+
};
|
|
13382
14144
|
var EncodeProfileSchema = object({
|
|
13383
14145
|
video: object({
|
|
13384
14146
|
codec: _enum([
|
|
@@ -54377,6 +55139,21 @@ var IntegrationInstanceKindSchema = object({
|
|
|
54377
55139
|
disconnectPath: string().min(1).optional()
|
|
54378
55140
|
});
|
|
54379
55141
|
var IntegrationInstanceDescriptionSchema = object({
|
|
55142
|
+
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
55143
|
+
role: _enum([
|
|
55144
|
+
"devices",
|
|
55145
|
+
"services",
|
|
55146
|
+
"both"
|
|
55147
|
+
]),
|
|
55148
|
+
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
55149
|
+
discovery: object({
|
|
55150
|
+
mode: _enum([
|
|
55151
|
+
"none",
|
|
55152
|
+
"lan",
|
|
55153
|
+
"account"
|
|
55154
|
+
]),
|
|
55155
|
+
scopedToInstance: boolean()
|
|
55156
|
+
}).optional(),
|
|
54380
55157
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
54381
55158
|
instanceMode: IntegrationInstanceModeSchema,
|
|
54382
55159
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -54416,10 +55193,11 @@ var IntegrationInstanceSchema = object({
|
|
|
54416
55193
|
/** The addon's own rule (an URL is present, a client id is present...). */
|
|
54417
55194
|
configured: boolean(),
|
|
54418
55195
|
/**
|
|
54419
|
-
* The instance's own on/off switch (D996)
|
|
54420
|
-
*
|
|
55196
|
+
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
55197
|
+
* so a row written before the field existed is on). Absent when the `integrations` registry
|
|
55198
|
+
* owns the switch (`describe().role` is `devices`): read it from the registry row.
|
|
54421
55199
|
*/
|
|
54422
|
-
enabled: boolean(),
|
|
55200
|
+
enabled: boolean().optional(),
|
|
54423
55201
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
54424
55202
|
kind: string().optional(),
|
|
54425
55203
|
/** Values for the instance form; a secret is a `SecretFieldView`, never text. */
|
|
@@ -54434,32 +55212,57 @@ var IntegrationInstancePatchSchema = object({
|
|
|
54434
55212
|
/** Omitted / '' / redaction token keeps a secret; `{ $secretClear: true }` clears it. */
|
|
54435
55213
|
values: record(string(), unknown())
|
|
54436
55214
|
});
|
|
54437
|
-
|
|
54438
|
-
|
|
54439
|
-
|
|
54440
|
-
|
|
54441
|
-
|
|
54442
|
-
|
|
54443
|
-
|
|
54444
|
-
|
|
54445
|
-
|
|
54446
|
-
|
|
54447
|
-
|
|
54448
|
-
|
|
54449
|
-
|
|
54450
|
-
|
|
54451
|
-
|
|
54452
|
-
|
|
54453
|
-
|
|
54454
|
-
|
|
54455
|
-
|
|
54456
|
-
|
|
54457
|
-
|
|
54458
|
-
|
|
54459
|
-
}),
|
|
54460
|
-
|
|
54461
|
-
|
|
54462
|
-
})
|
|
55215
|
+
var integrationInstancesCapability = {
|
|
55216
|
+
name: "integration-instances",
|
|
55217
|
+
scope: "system",
|
|
55218
|
+
mode: "collection",
|
|
55219
|
+
methods: {
|
|
55220
|
+
describe: method(_void(), IntegrationInstanceDescriptionSchema, { auth: "admin" }),
|
|
55221
|
+
/** The form; `id: null` is the create form. */
|
|
55222
|
+
instanceFormSchema: method(object({ id: IntegrationInstanceIdSchema.nullable() }), ConfigSchemaPassthrough$3, { auth: "admin" }),
|
|
55223
|
+
listInstances: method(_void(), array(IntegrationInstanceSchema).readonly(), { auth: "admin" }),
|
|
55224
|
+
getInstance: method(object({ id: IntegrationInstanceIdSchema }), IntegrationInstanceSchema.nullable(), { auth: "admin" }),
|
|
55225
|
+
/**
|
|
55226
|
+
* Insert the typed record. With `id` it is stored under that id (a duplicate id is refused);
|
|
55227
|
+
* without one the PROVIDER mints it and answers it. `kind` picks one of `describe().kinds`.
|
|
55228
|
+
*/
|
|
55229
|
+
createInstance: method(object({
|
|
55230
|
+
id: IntegrationInstanceIdSchema.optional(),
|
|
55231
|
+
name: string().min(1),
|
|
55232
|
+
kind: string().min(1).optional()
|
|
55233
|
+
}), object({ id: string() }), {
|
|
55234
|
+
kind: "mutation",
|
|
55235
|
+
auth: "admin"
|
|
55236
|
+
}),
|
|
55237
|
+
updateInstance: method(IntegrationInstancePatchSchema, object({ ok: literal(true) }), {
|
|
55238
|
+
kind: "mutation",
|
|
55239
|
+
auth: "admin"
|
|
55240
|
+
}),
|
|
55241
|
+
/**
|
|
55242
|
+
* Switch ONE instance on or off. A row control, not a form field: `updateInstance.values` is the
|
|
55243
|
+
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
55244
|
+
*/
|
|
55245
|
+
setInstanceEnabled: method(object({
|
|
55246
|
+
id: IntegrationInstanceIdSchema,
|
|
55247
|
+
enabled: boolean()
|
|
55248
|
+
}), object({ ok: literal(true) }), {
|
|
55249
|
+
kind: "mutation",
|
|
55250
|
+
auth: "admin"
|
|
55251
|
+
}),
|
|
55252
|
+
/** Delete the record and its keychain refs together. */
|
|
55253
|
+
deleteInstance: method(object({ id: IntegrationInstanceIdSchema }), object({ ok: literal(true) }), {
|
|
55254
|
+
kind: "mutation",
|
|
55255
|
+
auth: "admin"
|
|
55256
|
+
}),
|
|
55257
|
+
testInstance: optionalMethod(object({
|
|
55258
|
+
id: IntegrationInstanceIdSchema.nullable(),
|
|
55259
|
+
values: record(string(), unknown())
|
|
55260
|
+
}), TestConnectionResultSchema$1, {
|
|
55261
|
+
kind: "mutation",
|
|
55262
|
+
auth: "admin"
|
|
55263
|
+
})
|
|
55264
|
+
}
|
|
55265
|
+
};
|
|
54463
55266
|
/**
|
|
54464
55267
|
* Two-way audio / talk-back cap. Clients open a WebRTC audio-only
|
|
54465
55268
|
* session (server-initiated offer pattern, identical to the main
|
|
@@ -138661,6 +139464,133 @@ function carryForward(base, existing, keys) {
|
|
|
138661
139464
|
return out;
|
|
138662
139465
|
}
|
|
138663
139466
|
//#endregion
|
|
139467
|
+
//#region src/hap-export-records.ts
|
|
139468
|
+
/**
|
|
139469
|
+
* What one HomeKit bridge exposes (D985, D996): a `hap-bridge-exports` row per bridge instance,
|
|
139470
|
+
* under the instance's own id, holds the devices it mirrors (with their per-device export
|
|
139471
|
+
* settings) and the actions it publishes as momentary switches. The identity a controller pairs
|
|
139472
|
+
* with is the sibling `hap-bridges` row; this row is what that bridge CARRIES.
|
|
139473
|
+
*
|
|
139474
|
+
* It replaces the `exposed` and `exposedActions` addon settings. The migration moved them; the
|
|
139475
|
+
* addon reads this record and nothing else.
|
|
139476
|
+
*/
|
|
139477
|
+
var ExportDeviceSettingsSchema = object({
|
|
139478
|
+
multiTierService: boolean().optional(),
|
|
139479
|
+
streamPreference: string(),
|
|
139480
|
+
useBridge: boolean().optional(),
|
|
139481
|
+
allowTranscode: boolean().optional(),
|
|
139482
|
+
keepClips: boolean().optional(),
|
|
139483
|
+
clipRetentionDays: number().optional()
|
|
139484
|
+
});
|
|
139485
|
+
var MapperKindSchema = _enum(["camera", "generic"]);
|
|
139486
|
+
var ExposedConfigEntrySchema = object({
|
|
139487
|
+
deviceId: string(),
|
|
139488
|
+
displayName: string(),
|
|
139489
|
+
mapperKind: MapperKindSchema,
|
|
139490
|
+
capabilities: array(string()).optional(),
|
|
139491
|
+
childAccessoryUuids: array(string()).optional(),
|
|
139492
|
+
addedAt: number().optional(),
|
|
139493
|
+
settings: ExportDeviceSettingsSchema.optional()
|
|
139494
|
+
});
|
|
139495
|
+
var ActionExportEntrySchema = object({
|
|
139496
|
+
actionId: string(),
|
|
139497
|
+
displayName: string(),
|
|
139498
|
+
addedAt: number()
|
|
139499
|
+
});
|
|
139500
|
+
var HapBridgeExportsBodySchema = object({
|
|
139501
|
+
name: string().min(1),
|
|
139502
|
+
devices: array(ExposedConfigEntrySchema),
|
|
139503
|
+
actions: array(ActionExportEntrySchema)
|
|
139504
|
+
});
|
|
139505
|
+
/** The label of every exposure record: it is the instance's, not an operator's name. */
|
|
139506
|
+
var HAP_EXPOSURE_NAME = "HomeKit exposure";
|
|
139507
|
+
var hapBridgeExportsKind = defineEntryKind("hap-bridge-exports", {
|
|
139508
|
+
title: "HomeKit exposure",
|
|
139509
|
+
nameField: "name",
|
|
139510
|
+
schema: HapBridgeExportsBodySchema,
|
|
139511
|
+
writeTrigger: "an operator exposes or unexposes a device or action to HomeKit"
|
|
139512
|
+
});
|
|
139513
|
+
/** The settings keys that moved into the record; the migrations name them. */
|
|
139514
|
+
var MOVED_EXPOSURE_KEYS = ["exposed", "exposedActions"];
|
|
139515
|
+
//#endregion
|
|
139516
|
+
//#region src/hap-instance-kinds.ts
|
|
139517
|
+
/**
|
|
139518
|
+
* The HomeKit export's instances as records (D985, D996): one `hap-bridges` row per bridge
|
|
139519
|
+
* identity, owned by `export-hap`. A row IS what a paired controller knows the bridge by: the
|
|
139520
|
+
* MAC-style `username`, the bridge `uuid` and the setup code (`pincode`, a keychain marker bound to
|
|
139521
|
+
* the row). The directory its pairing state lives in is derived from the id, never stored
|
|
139522
|
+
* (`hapPersistDirOf`). The default instance is keyed by the
|
|
139523
|
+
* addon id and ADOPTS the identity the addon held in its settings, byte for byte, so a
|
|
139524
|
+
* controller that paired before keeps working.
|
|
139525
|
+
*/
|
|
139526
|
+
/** The default instance keeps its record under the addon id (it adopted the old identity). */
|
|
139527
|
+
var HAP_DEFAULT_INSTANCE_ID = "export-hap";
|
|
139528
|
+
/** Where the pairing state of the default instance has always lived, under the addon data dir. */
|
|
139529
|
+
var HAP_DEFAULT_PERSIST_DIR = "hap-store";
|
|
139530
|
+
/** The pairing-state directory of an instance, relative to the addon data dir: derived, not stored. */
|
|
139531
|
+
function hapPersistDirOf(instanceId) {
|
|
139532
|
+
return instanceId === "export-hap" ? HAP_DEFAULT_PERSIST_DIR : `hap-store-${instanceId}`;
|
|
139533
|
+
}
|
|
139534
|
+
var hapBridgesKind = defineEntryKind("hap-bridges", {
|
|
139535
|
+
title: "HomeKit bridge",
|
|
139536
|
+
nameField: "name",
|
|
139537
|
+
schema: object({
|
|
139538
|
+
name: string().min(1),
|
|
139539
|
+
username: string().min(1),
|
|
139540
|
+
uuid: string().min(1),
|
|
139541
|
+
pincode: string().min(1).meta({ secret: true }),
|
|
139542
|
+
enabled: boolean().optional()
|
|
139543
|
+
})
|
|
139544
|
+
});
|
|
139545
|
+
function identityOfBody(body) {
|
|
139546
|
+
return {
|
|
139547
|
+
username: body.username,
|
|
139548
|
+
uuid: body.uuid,
|
|
139549
|
+
pincode: body.pincode
|
|
139550
|
+
};
|
|
139551
|
+
}
|
|
139552
|
+
//#endregion
|
|
139553
|
+
//#region src/hap-identity.ts
|
|
139554
|
+
/**
|
|
139555
|
+
* Which HomeKit bridge identity the addon boots with: the default instance record, and nothing
|
|
139556
|
+
* else. There is no fallback to the settings the identity once lived in; the migration moved it.
|
|
139557
|
+
* A fresh identity is minted only when no record exists AND no legacy identity is still stored.
|
|
139558
|
+
* A legacy identity without a record means the migration did not finish, and minting then would
|
|
139559
|
+
* unpair every controller, so the addon refuses to boot with the reason.
|
|
139560
|
+
*/
|
|
139561
|
+
/** An operator-supplied `fixedPin` overrides the pincode, never the username/uuid. */
|
|
139562
|
+
async function resolveBridgeIdentity(fixedPin, ports) {
|
|
139563
|
+
const stored = await ports.readRecord();
|
|
139564
|
+
if (stored.kind === "unavailable") throw new Error("export-hap: the bridge identity exists but the keychain cannot serve it");
|
|
139565
|
+
if (stored.kind === "resolved") {
|
|
139566
|
+
if (fixedPin !== null && fixedPin !== stored.body.pincode) {
|
|
139567
|
+
await ports.patchPincode(fixedPin);
|
|
139568
|
+
return {
|
|
139569
|
+
identity: identityOfBody({
|
|
139570
|
+
...stored.body,
|
|
139571
|
+
pincode: fixedPin
|
|
139572
|
+
}),
|
|
139573
|
+
minted: false
|
|
139574
|
+
};
|
|
139575
|
+
}
|
|
139576
|
+
return {
|
|
139577
|
+
identity: identityOfBody(stored.body),
|
|
139578
|
+
minted: false
|
|
139579
|
+
};
|
|
139580
|
+
}
|
|
139581
|
+
if (await ports.legacyIdentityPresent()) throw new Error("export-hap: a bridge identity is still in the old settings but its instance record does not exist; the identity migration did not complete. Refusing to boot: a new identity would unpair every HomeKit controller");
|
|
139582
|
+
const fresh = ports.mint();
|
|
139583
|
+
const body = fixedPin === null ? fresh : {
|
|
139584
|
+
...fresh,
|
|
139585
|
+
pincode: fixedPin
|
|
139586
|
+
};
|
|
139587
|
+
await ports.putFresh(body);
|
|
139588
|
+
return {
|
|
139589
|
+
identity: identityOfBody(body),
|
|
139590
|
+
minted: true
|
|
139591
|
+
};
|
|
139592
|
+
}
|
|
139593
|
+
//#endregion
|
|
138664
139594
|
//#region src/migrations/hub-node-fields.ts
|
|
138665
139595
|
/**
|
|
138666
139596
|
* Fields stored once for the cluster that are facts of ONE node become node settings (D986): a
|
|
@@ -138731,40 +139661,248 @@ async function moveFixedPinToKeychain(ports) {
|
|
|
138731
139661
|
};
|
|
138732
139662
|
}
|
|
138733
139663
|
//#endregion
|
|
139664
|
+
//#region src/migrations/exposure-to-record.ts
|
|
139665
|
+
/**
|
|
139666
|
+
* The exposure lists the addon kept in its settings (`exposed`: the devices it mirrors, with
|
|
139667
|
+
* their per-device settings; `exposedActions`: the actions it publishes) move into the
|
|
139668
|
+
* `hap-bridge-exports` record of the default instance (D985, D996). Two migrations, in order:
|
|
139669
|
+
*
|
|
139670
|
+
* 1. `moveExposureToRecord` (procedure): put the record with `ifRev: 0`, read it BACK and
|
|
139671
|
+
* compare it with what the settings carried; a record that does not hold the same lists
|
|
139672
|
+
* throws and the settings are kept. An existing record is never overwritten.
|
|
139673
|
+
* 2. `planDropExposureKeys` (plan): the two keys are deleted from the canonical `addon-settings`
|
|
139674
|
+
* rows, and only while the record holds exactly what they carry. A record that differs (the
|
|
139675
|
+
* operator edited the lists since) keeps the old keys, which nothing reads any more.
|
|
139676
|
+
*
|
|
139677
|
+
* An entry the schema does not know (a mapper kind the addon no longer serves) is dropped on the
|
|
139678
|
+
* way, which is what the boot sweep did to it anyway.
|
|
139679
|
+
*/
|
|
139680
|
+
/** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
|
|
139681
|
+
function canonical(value) {
|
|
139682
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
139683
|
+
if (typeof value === "object" && value !== null) return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
139684
|
+
return JSON.stringify(value) ?? "null";
|
|
139685
|
+
}
|
|
139686
|
+
function parsedList(value, parse) {
|
|
139687
|
+
if (!Array.isArray(value)) return [];
|
|
139688
|
+
const kept = [];
|
|
139689
|
+
for (const entry of value) {
|
|
139690
|
+
const parsed = parse(entry);
|
|
139691
|
+
if (parsed.success) kept.push(parsed.data);
|
|
139692
|
+
}
|
|
139693
|
+
return kept;
|
|
139694
|
+
}
|
|
139695
|
+
/** The record body the legacy settings describe. */
|
|
139696
|
+
function exposureBodyFrom(stored) {
|
|
139697
|
+
return {
|
|
139698
|
+
name: HAP_EXPOSURE_NAME,
|
|
139699
|
+
devices: parsedList(stored["exposed"], (e) => ExposedConfigEntrySchema.safeParse(e)),
|
|
139700
|
+
actions: parsedList(stored["exposedActions"], (e) => ActionExportEntrySchema.safeParse(e))
|
|
139701
|
+
};
|
|
139702
|
+
}
|
|
139703
|
+
function sameLists(a, b) {
|
|
139704
|
+
return canonical(a.devices) === canonical(b.devices) && canonical(a.actions) === canonical(b.actions);
|
|
139705
|
+
}
|
|
139706
|
+
async function moveExposureToRecord(ports) {
|
|
139707
|
+
const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
|
|
139708
|
+
if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
|
|
139709
|
+
outcome: "already-done",
|
|
139710
|
+
summary: { moved: false }
|
|
139711
|
+
};
|
|
139712
|
+
const body = exposureBodyFrom(stored);
|
|
139713
|
+
const put = await ports.putExposure(body);
|
|
139714
|
+
const held = await ports.readExposure();
|
|
139715
|
+
if (held === null) throw new Error("the HomeKit exposure record cannot be read back");
|
|
139716
|
+
if (put === "created" && !sameLists(held, body)) throw new Error("the HomeKit exposure record does not hold the lists it adopted");
|
|
139717
|
+
return put === "created" ? {
|
|
139718
|
+
outcome: "done",
|
|
139719
|
+
summary: {
|
|
139720
|
+
moved: true,
|
|
139721
|
+
devices: body.devices.length
|
|
139722
|
+
}
|
|
139723
|
+
} : {
|
|
139724
|
+
outcome: "already-done",
|
|
139725
|
+
summary: { moved: false }
|
|
139726
|
+
};
|
|
139727
|
+
}
|
|
139728
|
+
var rowId = (key) => `${HAP_DEFAULT_INSTANCE_ID}.${key}`;
|
|
139729
|
+
async function planDropExposureKeys(ports) {
|
|
139730
|
+
const stored = await ports.readStored(MOVED_EXPOSURE_KEYS);
|
|
139731
|
+
const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
|
|
139732
|
+
if (present.length === 0) return { edits: [] };
|
|
139733
|
+
const held = await ports.readExposure();
|
|
139734
|
+
if (held === null || !sameLists(held, exposureBodyFrom(stored))) return { edits: [] };
|
|
139735
|
+
return { edits: [{
|
|
139736
|
+
op: "deleteKeys",
|
|
139737
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
139738
|
+
keys: present.map(rowId),
|
|
139739
|
+
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
139740
|
+
addonId: HAP_DEFAULT_INSTANCE_ID,
|
|
139741
|
+
key,
|
|
139742
|
+
value: stored[key]
|
|
139743
|
+
}])))
|
|
139744
|
+
}] };
|
|
139745
|
+
}
|
|
139746
|
+
//#endregion
|
|
139747
|
+
//#region src/migrations/identity-to-instance.ts
|
|
139748
|
+
/**
|
|
139749
|
+
* The bridge identity the addon kept in its settings (`identity`: username, uuid, pincode) moves
|
|
139750
|
+
* into the default instance record (D985, D996). Paired controllers know the bridge by exactly
|
|
139751
|
+
* these values, so the record is created with them UNCHANGED and the pass proves it by reading the
|
|
139752
|
+
* record back and comparing, field by field, before it reports `done`.
|
|
139753
|
+
*
|
|
139754
|
+
* Only once the read-back matches is the old `identity` cleared (its keychain entry released with
|
|
139755
|
+
* it), in this same pass: one path, no copy. An existing record is never overwritten; when it is
|
|
139756
|
+
* already there and names the same bridge (username, uuid) the leftover old identity of an
|
|
139757
|
+
* interrupted pass is cleared, and when it names another bridge the pass fails rather than guess.
|
|
139758
|
+
* An incomplete or unreadable legacy identity is `already-done` or throws, and never mints a new
|
|
139759
|
+
* one (a new identity unpairs every controller).
|
|
139760
|
+
*/
|
|
139761
|
+
async function moveIdentityToDefaultInstance(ports) {
|
|
139762
|
+
const legacy = await ports.readLegacyIdentity();
|
|
139763
|
+
if (legacy === null) return {
|
|
139764
|
+
outcome: "already-done",
|
|
139765
|
+
summary: { moved: false }
|
|
139766
|
+
};
|
|
139767
|
+
const name = (await ports.readBridgeName()).trim();
|
|
139768
|
+
const body = {
|
|
139769
|
+
name: name.length > 0 ? name : "CamStack Bridge",
|
|
139770
|
+
username: legacy.username,
|
|
139771
|
+
uuid: legacy.uuid,
|
|
139772
|
+
pincode: legacy.pincode
|
|
139773
|
+
};
|
|
139774
|
+
const put = await ports.putDefaultRecord(body);
|
|
139775
|
+
const held = await ports.readDefaultRecord();
|
|
139776
|
+
if (held === null) throw new Error("the HomeKit default instance record cannot be read back");
|
|
139777
|
+
if (put === "exists") {
|
|
139778
|
+
if (held.username !== body.username || held.uuid !== body.uuid) throw new Error("the HomeKit default instance is another bridge than the stored identity");
|
|
139779
|
+
await ports.clearLegacyIdentity();
|
|
139780
|
+
return {
|
|
139781
|
+
outcome: "done",
|
|
139782
|
+
summary: {
|
|
139783
|
+
moved: false,
|
|
139784
|
+
cleared: true
|
|
139785
|
+
}
|
|
139786
|
+
};
|
|
139787
|
+
}
|
|
139788
|
+
if (!sameIdentity(identityOfBody(held), identityOfBody(body))) throw new Error("the HomeKit default instance does not hold the identity it adopted");
|
|
139789
|
+
await ports.clearLegacyIdentity();
|
|
139790
|
+
return {
|
|
139791
|
+
outcome: "done",
|
|
139792
|
+
summary: { moved: true }
|
|
139793
|
+
};
|
|
139794
|
+
}
|
|
139795
|
+
function sameIdentity(a, b) {
|
|
139796
|
+
return a.username === b.username && a.uuid === b.uuid && a.pincode === b.pincode;
|
|
139797
|
+
}
|
|
139798
|
+
/**
|
|
139799
|
+
* The identity a settings value describes, secrets resolved; null when it is not a complete
|
|
139800
|
+
* identity (first boot, or the empty sentinel). A pincode still a keychain marker was not
|
|
139801
|
+
* resolved: that throws, because treating "unreadable" as "absent" would mint a new identity.
|
|
139802
|
+
*/
|
|
139803
|
+
function legacyIdentityOf(value) {
|
|
139804
|
+
if (typeof value !== "object" || value === null) return null;
|
|
139805
|
+
const username = Reflect.get(value, "username");
|
|
139806
|
+
const uuid = Reflect.get(value, "uuid");
|
|
139807
|
+
const pincode = Reflect.get(value, "pincode");
|
|
139808
|
+
if (isSecretMarker(pincode)) throw new Error("the stored HomeKit setup code cannot be resolved");
|
|
139809
|
+
if (typeof username !== "string" || typeof uuid !== "string" || typeof pincode !== "string" || username === "" || uuid === "" || pincode === "") return null;
|
|
139810
|
+
return {
|
|
139811
|
+
username,
|
|
139812
|
+
uuid,
|
|
139813
|
+
pincode
|
|
139814
|
+
};
|
|
139815
|
+
}
|
|
139816
|
+
//#endregion
|
|
138734
139817
|
//#region src/migrations/index.ts
|
|
138735
139818
|
var EXPORT_HAP_ID = "export-hap";
|
|
139819
|
+
var INTERFACE_NAME_PER_NODE_ID = "export-hap/2026-11-03-interface-name-per-node";
|
|
139820
|
+
var FIXED_PIN_TO_KEYCHAIN_ID = "export-hap/2026-11-03-fixed-pin-to-keychain";
|
|
139821
|
+
var IDENTITY_TO_INSTANCE_ID = "export-hap/2026-11-04-identity-to-default-instance";
|
|
139822
|
+
var EXPOSURE_TO_RECORD_ID = "export-hap/2026-11-04-exposure-to-record";
|
|
138736
139823
|
/** The `export-hap` catalogue (D987): offered to the engine when the addon initialises. */
|
|
138737
|
-
var ADDON_MIGRATIONS = [
|
|
138738
|
-
|
|
138739
|
-
|
|
138740
|
-
|
|
138741
|
-
|
|
138742
|
-
|
|
138743
|
-
|
|
138744
|
-
|
|
138745
|
-
|
|
138746
|
-
|
|
138747
|
-
|
|
138748
|
-
|
|
138749
|
-
|
|
138750
|
-
|
|
138751
|
-
|
|
138752
|
-
|
|
138753
|
-
|
|
138754
|
-
|
|
138755
|
-
|
|
138756
|
-
|
|
138757
|
-
|
|
138758
|
-
|
|
138759
|
-
|
|
138760
|
-
|
|
138761
|
-
|
|
138762
|
-
|
|
138763
|
-
|
|
138764
|
-
|
|
138765
|
-
|
|
138766
|
-
|
|
138767
|
-
}
|
|
139824
|
+
var ADDON_MIGRATIONS = [
|
|
139825
|
+
{
|
|
139826
|
+
meta: {
|
|
139827
|
+
id: INTERFACE_NAME_PER_NODE_ID,
|
|
139828
|
+
owner: EXPORT_HAP_ID,
|
|
139829
|
+
level: "addon-state",
|
|
139830
|
+
seq: 1,
|
|
139831
|
+
dependsOn: [],
|
|
139832
|
+
store: "settings",
|
|
139833
|
+
scope: "per-node",
|
|
139834
|
+
onFailure: "tolerate",
|
|
139835
|
+
bodyKind: "plan",
|
|
139836
|
+
description: "Copy the bare network interface setting to its hub node row; the bare row stays for a release",
|
|
139837
|
+
fixtureMark: "the bridge name the migration does not know"
|
|
139838
|
+
},
|
|
139839
|
+
plan: (ports) => planHubNodeFields(EXPORT_HAP_ID, ["interfaceName"], ports)
|
|
139840
|
+
},
|
|
139841
|
+
{
|
|
139842
|
+
meta: {
|
|
139843
|
+
id: FIXED_PIN_TO_KEYCHAIN_ID,
|
|
139844
|
+
owner: EXPORT_HAP_ID,
|
|
139845
|
+
level: "addon-state",
|
|
139846
|
+
seq: 2,
|
|
139847
|
+
dependsOn: [],
|
|
139848
|
+
store: "settings",
|
|
139849
|
+
scope: "cluster",
|
|
139850
|
+
onFailure: "tolerate",
|
|
139851
|
+
bodyKind: "procedure",
|
|
139852
|
+
description: "Move the fixed setup code from an inline setting into the keychain, where a password field keeps it",
|
|
139853
|
+
fixtureMark: "the bridge name the migration does not know"
|
|
139854
|
+
},
|
|
139855
|
+
procedure: moveFixedPinToKeychain
|
|
139856
|
+
},
|
|
139857
|
+
{
|
|
139858
|
+
meta: {
|
|
139859
|
+
id: IDENTITY_TO_INSTANCE_ID,
|
|
139860
|
+
owner: EXPORT_HAP_ID,
|
|
139861
|
+
level: "addon-state",
|
|
139862
|
+
seq: 3,
|
|
139863
|
+
dependsOn: [],
|
|
139864
|
+
store: "settings",
|
|
139865
|
+
scope: "cluster",
|
|
139866
|
+
onFailure: "block-owner",
|
|
139867
|
+
bodyKind: "procedure",
|
|
139868
|
+
description: "Move the bridge identity (username, uuid, setup code) into the default HomeKit instance record, unchanged, then clear the old setting and its keychain entry",
|
|
139869
|
+
fixtureMark: "the bridge name the migration does not know"
|
|
139870
|
+
},
|
|
139871
|
+
procedure: moveIdentityToDefaultInstance
|
|
139872
|
+
},
|
|
139873
|
+
{
|
|
139874
|
+
meta: {
|
|
139875
|
+
id: EXPOSURE_TO_RECORD_ID,
|
|
139876
|
+
owner: EXPORT_HAP_ID,
|
|
139877
|
+
level: "addon-state",
|
|
139878
|
+
seq: 4,
|
|
139879
|
+
dependsOn: [IDENTITY_TO_INSTANCE_ID],
|
|
139880
|
+
store: "settings",
|
|
139881
|
+
scope: "cluster",
|
|
139882
|
+
onFailure: "block-owner",
|
|
139883
|
+
bodyKind: "procedure",
|
|
139884
|
+
description: "Move the exposed devices and actions into the default bridge exposure record, verified by read-back",
|
|
139885
|
+
fixtureMark: "the bridge name the migration does not know"
|
|
139886
|
+
},
|
|
139887
|
+
procedure: moveExposureToRecord
|
|
139888
|
+
},
|
|
139889
|
+
{
|
|
139890
|
+
meta: {
|
|
139891
|
+
id: "export-hap/2026-11-04-drop-exposure-keys",
|
|
139892
|
+
owner: EXPORT_HAP_ID,
|
|
139893
|
+
level: "addon-state",
|
|
139894
|
+
seq: 5,
|
|
139895
|
+
dependsOn: [EXPOSURE_TO_RECORD_ID],
|
|
139896
|
+
store: "settings",
|
|
139897
|
+
scope: "cluster",
|
|
139898
|
+
onFailure: "tolerate",
|
|
139899
|
+
bodyKind: "plan",
|
|
139900
|
+
description: "Delete the old exposed and exposedActions settings once the record holds exactly what they carried",
|
|
139901
|
+
fixtureMark: "the bridge name the migration does not know"
|
|
139902
|
+
},
|
|
139903
|
+
plan: planDropExposureKeys
|
|
139904
|
+
}
|
|
139905
|
+
];
|
|
138768
139906
|
//#endregion
|
|
138769
139907
|
//#region src/hap-setup-uri.ts
|
|
138770
139908
|
function errMsg$15(e) {
|
|
@@ -157967,9 +159105,8 @@ function syncStateToJson(map) {
|
|
|
157967
159105
|
* Operator flow:
|
|
157968
159106
|
* 1. Install + enable the addon (hub-only, group `export-hap`).
|
|
157969
159107
|
* 2. On first boot the addon generates a random pincode + bridge
|
|
157970
|
-
* MAC username and persists them
|
|
157971
|
-
* `
|
|
157972
|
-
* addon-store IS the cache).
|
|
159108
|
+
* MAC username and persists them in the default instance record
|
|
159109
|
+
* (`hap-bridges`, no JSON sidecar files).
|
|
157973
159110
|
* 3. The setup URI (`X-HM://…`) is logged AND surfaced via the
|
|
157974
159111
|
* `getStatus` cap method so the wizard UI can render the QR.
|
|
157975
159112
|
* 4. Operator opens iOS Home → + → scan QR → enter pincode.
|
|
@@ -158107,13 +159244,6 @@ var DEFAULT_CONFIG = {
|
|
|
158107
159244
|
fixedPin: "",
|
|
158108
159245
|
interfaceName: "",
|
|
158109
159246
|
clipRetentionDays: 14,
|
|
158110
|
-
identity: {
|
|
158111
|
-
username: "",
|
|
158112
|
-
pincode: "",
|
|
158113
|
-
uuid: ""
|
|
158114
|
-
},
|
|
158115
|
-
exposed: [],
|
|
158116
|
-
exposedActions: [],
|
|
158117
159247
|
exportSyncState: {}
|
|
158118
159248
|
};
|
|
158119
159249
|
var BANNED_PINCODES = new Set([
|
|
@@ -158152,12 +159282,27 @@ function buildBridgeUuid(bridgeName) {
|
|
|
158152
159282
|
return import_dist.uuid.generate(`camstack:bridge:${bridgeName}:${Date.now()}`);
|
|
158153
159283
|
}
|
|
158154
159284
|
var ExportHapAddon = class extends BaseAddon {
|
|
158155
|
-
/**
|
|
159285
|
+
/**
|
|
159286
|
+
* The old `identity.pincode` secret: declared only so the identity migration can release its
|
|
159287
|
+
* keychain entry when it clears the old setting. The identity itself is a record now.
|
|
159288
|
+
*/
|
|
158156
159289
|
secretStatePaths = ["identity.pincode"];
|
|
158157
159290
|
exposed = /* @__PURE__ */ new Map();
|
|
158158
159291
|
/** The exported actions — switches beside the devices (D968). */
|
|
158159
159292
|
actionExports = null;
|
|
158160
159293
|
lastError;
|
|
159294
|
+
/** The HomeKit instances (D985): one record per bridge identity. */
|
|
159295
|
+
instances = null;
|
|
159296
|
+
/**
|
|
159297
|
+
* What the bridge exposes: the devices (with their per-device settings) and the actions, held in
|
|
159298
|
+
* the `hap-bridge-exports` record of the default instance. The in-memory copy is loaded once at
|
|
159299
|
+
* boot and written through on every change; this addon is the record's only writer.
|
|
159300
|
+
*/
|
|
159301
|
+
exposure = {
|
|
159302
|
+
name: HAP_EXPOSURE_NAME,
|
|
159303
|
+
devices: [],
|
|
159304
|
+
actions: []
|
|
159305
|
+
};
|
|
158161
159306
|
/** Shared HAP setup code applied to every published accessory. */
|
|
158162
159307
|
pincode = "";
|
|
158163
159308
|
/** Optional mDNS/bind interface (config.interfaceName), or undefined. */
|
|
@@ -158213,8 +159358,31 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158213
159358
|
super({ ...DEFAULT_CONFIG });
|
|
158214
159359
|
}
|
|
158215
159360
|
async onInitialize() {
|
|
159361
|
+
const records = this.ctx.records;
|
|
159362
|
+
if (records === void 0) throw new Error("export-hap needs ctx.records — check execution.placement (hub-only)");
|
|
159363
|
+
await records.declare({
|
|
159364
|
+
"hap-bridges": hapBridgesKind,
|
|
159365
|
+
"hap-bridge-exports": hapBridgeExportsKind
|
|
159366
|
+
});
|
|
159367
|
+
this.instances = new RecordIntegrationInstances(records, hapBridgesKind, {
|
|
159368
|
+
description: {
|
|
159369
|
+
role: "services",
|
|
159370
|
+
instanceMode: "single",
|
|
159371
|
+
kind: "bridge",
|
|
159372
|
+
canTest: false
|
|
159373
|
+
},
|
|
159374
|
+
formSchema: () => this.schema({ sections: [] }),
|
|
159375
|
+
initialBody: (name) => ({
|
|
159376
|
+
name,
|
|
159377
|
+
username: generateUsername(),
|
|
159378
|
+
uuid: buildBridgeUuid(name),
|
|
159379
|
+
pincode: generatePincode()
|
|
159380
|
+
}),
|
|
159381
|
+
configured: (body) => body.username !== "" && body.pincode !== ""
|
|
159382
|
+
});
|
|
158216
159383
|
await this.migrateSettings();
|
|
158217
159384
|
const identity = await this.ensureIdentity();
|
|
159385
|
+
await this.loadExposure();
|
|
158218
159386
|
this.pincode = identity.pincode;
|
|
158219
159387
|
this.bind = this.config.interfaceName || void 0;
|
|
158220
159388
|
this.bridgeHost = new BridgeHost({
|
|
@@ -158225,7 +159393,7 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158225
159393
|
logger: this.ctx.logger
|
|
158226
159394
|
});
|
|
158227
159395
|
try {
|
|
158228
|
-
await initHapStorage(path.join(this.ctx.dataDir,
|
|
159396
|
+
await initHapStorage(path.join(this.ctx.dataDir, hapPersistDirOf(HAP_DEFAULT_INSTANCE_ID)));
|
|
158229
159397
|
} catch (err) {
|
|
158230
159398
|
this.lastError = errMsg(err);
|
|
158231
159399
|
this.ctx.logger.error("export-hap: HAP storage init failed", { meta: { error: this.lastError } });
|
|
@@ -158251,12 +159419,12 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158251
159419
|
});
|
|
158252
159420
|
await this.serveHksvClipPlanes();
|
|
158253
159421
|
const validKinds = new Set(SUPPORTED_MAPPER_KINDS);
|
|
158254
|
-
const cleaned = this.
|
|
159422
|
+
const cleaned = this.exposure.devices.filter((entry) => {
|
|
158255
159423
|
if (validKinds.has(entry.mapperKind)) return true;
|
|
158256
159424
|
this.ctx.logger.withTags({ deviceId: Number.parseInt(entry.deviceId, 10) }).info("export-hap: dropping stale exposed entry (unknown mapperKind)", { meta: { mapperKind: entry.mapperKind } });
|
|
158257
159425
|
return false;
|
|
158258
159426
|
});
|
|
158259
|
-
if (cleaned.length !== this.
|
|
159427
|
+
if (cleaned.length !== this.exposure.devices.length) await this.setExposedDevices(cleaned);
|
|
158260
159428
|
for (const entry of cleaned) {
|
|
158261
159429
|
const log = this.ctx.logger.withTags({ deviceId: Number.parseInt(entry.deviceId, 10) });
|
|
158262
159430
|
try {
|
|
@@ -158289,8 +159457,8 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158289
159457
|
}
|
|
158290
159458
|
await unpublishAccessory(accessory, this.ctx.logger);
|
|
158291
159459
|
},
|
|
158292
|
-
persist: (entries) => this.
|
|
158293
|
-
}, this.
|
|
159460
|
+
persist: (entries) => this.setExposedActions(entries)
|
|
159461
|
+
}, this.exposure.actions);
|
|
158294
159462
|
await this.actionExports.attachAll();
|
|
158295
159463
|
await this.actionExports.reconcile();
|
|
158296
159464
|
this.ctx.addDisposer(async () => {
|
|
@@ -158329,7 +159497,7 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158329
159497
|
listExposedDevices: async ({ instanceId }) => {
|
|
158330
159498
|
ownInstance(instanceId);
|
|
158331
159499
|
return Array.from(this.exposed.entries()).map(([deviceId, m]) => {
|
|
158332
|
-
const entry = this.
|
|
159500
|
+
const entry = this.exposure.devices.find((e) => e.deviceId === deviceId);
|
|
158333
159501
|
return {
|
|
158334
159502
|
deviceId,
|
|
158335
159503
|
exposedAs: m.accessory.displayName,
|
|
@@ -158383,54 +159551,95 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158383
159551
|
thumbnailUrl: (deviceId, stem) => this.hksvClipUrl("thumb", deviceId, stem),
|
|
158384
159552
|
clipFilePath: async (deviceId, stem) => await this.hksvClipStore?.artifactPath(deviceId, stem, "clip") ?? null
|
|
158385
159553
|
});
|
|
158386
|
-
return [
|
|
158387
|
-
|
|
158388
|
-
|
|
158389
|
-
|
|
158390
|
-
|
|
158391
|
-
|
|
158392
|
-
|
|
159554
|
+
return [
|
|
159555
|
+
{
|
|
159556
|
+
capability: deviceExportCapability,
|
|
159557
|
+
provider
|
|
159558
|
+
},
|
|
159559
|
+
{
|
|
159560
|
+
capability: videoclipsCapability,
|
|
159561
|
+
provider: clipsProvider
|
|
159562
|
+
},
|
|
159563
|
+
{
|
|
159564
|
+
capability: integrationInstancesCapability,
|
|
159565
|
+
provider: this.requireInstances().toProvider()
|
|
159566
|
+
}
|
|
159567
|
+
];
|
|
158393
159568
|
}
|
|
158394
159569
|
async onConfigChanged() {
|
|
158395
|
-
|
|
158396
|
-
|
|
158397
|
-
|
|
158398
|
-
|
|
158399
|
-
|
|
158400
|
-
|
|
158401
|
-
|
|
158402
|
-
|
|
159570
|
+
const fixedPin = this.config.fixedPin;
|
|
159571
|
+
if (!fixedPin || !isValidPincode(fixedPin)) return;
|
|
159572
|
+
const handle = this.requireRecords().kind(hapBridgesKind);
|
|
159573
|
+
const row = await handle.getResolved(HAP_DEFAULT_INSTANCE_ID);
|
|
159574
|
+
if (row === null || row.data.pincode === fixedPin) return;
|
|
159575
|
+
await handle.patch(HAP_DEFAULT_INSTANCE_ID, { pincode: fixedPin });
|
|
159576
|
+
}
|
|
159577
|
+
requireInstances() {
|
|
159578
|
+
if (this.instances === null) throw new Error("export-hap: instances are not initialised");
|
|
159579
|
+
return this.instances;
|
|
159580
|
+
}
|
|
159581
|
+
requireRecords() {
|
|
159582
|
+
const records = this.ctx.records;
|
|
159583
|
+
if (records === void 0) throw new Error("export-hap: records are not available");
|
|
159584
|
+
return records;
|
|
159585
|
+
}
|
|
159586
|
+
/** The ports the identity migration reads and writes through. */
|
|
159587
|
+
identityMigrationPorts() {
|
|
159588
|
+
const handle = this.requireRecords().kind(hapBridgesKind);
|
|
159589
|
+
return {
|
|
159590
|
+
readLegacyIdentity: async () => legacyIdentityOf((await this.resolveGlobalStore())["identity"]),
|
|
159591
|
+
clearLegacyIdentity: () => this.updateGlobalSettingsAsOperator({ identity: null }),
|
|
159592
|
+
readBridgeName: async () => {
|
|
159593
|
+
const name = (await this.resolveGlobalStore())["bridgeName"];
|
|
159594
|
+
return typeof name === "string" ? name : "";
|
|
159595
|
+
},
|
|
159596
|
+
putDefaultRecord: async (body) => {
|
|
159597
|
+
if (await handle.get("export-hap") !== null) return "exists";
|
|
159598
|
+
try {
|
|
159599
|
+
await handle.put({
|
|
159600
|
+
id: HAP_DEFAULT_INSTANCE_ID,
|
|
159601
|
+
data: body
|
|
159602
|
+
}, { ifRev: 0 });
|
|
159603
|
+
} catch (err) {
|
|
159604
|
+
if (err instanceof RevConflictError) return "exists";
|
|
159605
|
+
throw err;
|
|
159606
|
+
}
|
|
159607
|
+
return "created";
|
|
159608
|
+
},
|
|
159609
|
+
readDefaultRecord: async () => (await handle.getResolved("export-hap"))?.data ?? null
|
|
159610
|
+
};
|
|
158403
159611
|
}
|
|
158404
|
-
/**
|
|
158405
|
-
* Resolve the persistent bridge identity. Empty `username` is the
|
|
158406
|
-
* "first boot" sentinel — generate fresh + persist. On subsequent
|
|
158407
|
-
* boots the persisted record is reused. An operator-supplied
|
|
158408
|
-
* `fixedPin` overrides the persisted pincode (useful for CI replay)
|
|
158409
|
-
* but never the username/uuid (those drive the iOS pairing record).
|
|
158410
|
-
*/
|
|
159612
|
+
/** The identity of the default instance; see `resolveBridgeIdentity`. */
|
|
158411
159613
|
async ensureIdentity() {
|
|
158412
|
-
const
|
|
158413
|
-
const
|
|
158414
|
-
|
|
158415
|
-
|
|
158416
|
-
|
|
158417
|
-
|
|
158418
|
-
|
|
158419
|
-
|
|
158420
|
-
};
|
|
158421
|
-
|
|
158422
|
-
|
|
158423
|
-
|
|
158424
|
-
|
|
158425
|
-
|
|
158426
|
-
|
|
158427
|
-
|
|
158428
|
-
|
|
158429
|
-
|
|
158430
|
-
|
|
158431
|
-
|
|
158432
|
-
|
|
158433
|
-
|
|
159614
|
+
const handle = this.requireRecords().kind(hapBridgesKind);
|
|
159615
|
+
const { identity, minted } = await resolveBridgeIdentity(this.config.fixedPin && isValidPincode(this.config.fixedPin) ? this.config.fixedPin : null, {
|
|
159616
|
+
readRecord: async () => {
|
|
159617
|
+
const resolved = await this.requireInstances().readResolved(HAP_DEFAULT_INSTANCE_ID);
|
|
159618
|
+
if (resolved === null) return { kind: "absent" };
|
|
159619
|
+
return resolved.secrets === "resolved" ? {
|
|
159620
|
+
kind: "resolved",
|
|
159621
|
+
body: resolved.body
|
|
159622
|
+
} : { kind: "unavailable" };
|
|
159623
|
+
},
|
|
159624
|
+
legacyIdentityPresent: async () => legacyIdentityOf((await this.resolveGlobalStore())["identity"]) !== null,
|
|
159625
|
+
patchPincode: async (pincode) => {
|
|
159626
|
+
await handle.patch(HAP_DEFAULT_INSTANCE_ID, { pincode });
|
|
159627
|
+
},
|
|
159628
|
+
putFresh: async (body) => {
|
|
159629
|
+
await handle.put({
|
|
159630
|
+
id: HAP_DEFAULT_INSTANCE_ID,
|
|
159631
|
+
data: body
|
|
159632
|
+
}, { ifRev: 0 });
|
|
159633
|
+
},
|
|
159634
|
+
mint: () => ({
|
|
159635
|
+
name: this.config.bridgeName,
|
|
159636
|
+
username: generateUsername(),
|
|
159637
|
+
uuid: buildBridgeUuid(this.config.bridgeName),
|
|
159638
|
+
pincode: generatePincode()
|
|
159639
|
+
})
|
|
159640
|
+
});
|
|
159641
|
+
if (minted) this.ctx.logger.info("export-hap: generated bridge identity on first boot", { meta: { username: identity.username } });
|
|
159642
|
+
return identity;
|
|
158434
159643
|
}
|
|
158435
159644
|
/**
|
|
158436
159645
|
* Build the generic `device-export` `setup` block surfaced via
|
|
@@ -158440,7 +159649,7 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158440
159649
|
* until the bridge has booted and produced both values.
|
|
158441
159650
|
*/
|
|
158442
159651
|
buildSetupBlock() {
|
|
158443
|
-
const setupCode = this.
|
|
159652
|
+
const setupCode = this.pincode;
|
|
158444
159653
|
if (!setupCode) return null;
|
|
158445
159654
|
const qr = firstExposedAccessorySetupUri(this.exposed, this.ctx.logger);
|
|
158446
159655
|
return {
|
|
@@ -158474,7 +159683,7 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158474
159683
|
const mapperKind = pickMapperKind(summary?.type);
|
|
158475
159684
|
if (!mapperKind) throw new Error(`export-hap: device ${numericId} has type '${summary?.type ?? "unknown"}', which HomeKit export does not support`);
|
|
158476
159685
|
const displayName = summary?.name ?? `Device ${deviceId}`;
|
|
158477
|
-
const previous = this.
|
|
159686
|
+
const previous = this.exposure.devices.find((e) => e.deviceId === deviceId);
|
|
158478
159687
|
const rebuilt = {
|
|
158479
159688
|
deviceId,
|
|
158480
159689
|
displayName,
|
|
@@ -158491,9 +159700,9 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158491
159700
|
...baseEntry,
|
|
158492
159701
|
childAccessoryUuids: attached.childAccessoryUuids
|
|
158493
159702
|
};
|
|
158494
|
-
const next = this.
|
|
159703
|
+
const next = this.exposure.devices.filter((e) => e.deviceId !== deviceId);
|
|
158495
159704
|
next.push(finalEntry);
|
|
158496
|
-
await this.
|
|
159705
|
+
await this.setExposedDevices(next);
|
|
158497
159706
|
if (Number.isFinite(numericId)) {
|
|
158498
159707
|
const fp = await this.computeExportFingerprint(numericId);
|
|
158499
159708
|
if (fp !== null) await this.persistFingerprint(numericId, fp);
|
|
@@ -158509,8 +159718,8 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158509
159718
|
const log = this.ctx.logger.withTags({ deviceId: numericId });
|
|
158510
159719
|
const mapperKind = this.findEntry(numericId)?.mapperKind ?? "camera";
|
|
158511
159720
|
await this.detachMapper(deviceId);
|
|
158512
|
-
const next = this.
|
|
158513
|
-
if (next.length !== this.
|
|
159721
|
+
const next = this.exposure.devices.filter((e) => e.deviceId !== deviceId);
|
|
159722
|
+
if (next.length !== this.exposure.devices.length) await this.setExposedDevices(next);
|
|
158514
159723
|
if (options.clearPairing !== false) clearPairingFiles(accessoryUuidFor(mapperKind, numericId), this.ctx.logger);
|
|
158515
159724
|
await this.forgetFingerprint(numericId);
|
|
158516
159725
|
this.hksvBuilds.forget(numericId);
|
|
@@ -158873,7 +160082,9 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158873
160082
|
async migrateSettings() {
|
|
158874
160083
|
if ((await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, {
|
|
158875
160084
|
readStored: (keys) => readRawKeys((key) => this.readStoredGlobalKey(key), "export-hap", keys),
|
|
158876
|
-
storeFixedPin: (pin) => this.updateGlobalSettingsAsOperator({ fixedPin: pin })
|
|
160085
|
+
storeFixedPin: (pin) => this.updateGlobalSettingsAsOperator({ fixedPin: pin }),
|
|
160086
|
+
...this.identityMigrationPorts(),
|
|
160087
|
+
...this.exposureMigrationPorts()
|
|
158877
160088
|
}))).applied.length > 0) await this.resolveConfig();
|
|
158878
160089
|
}
|
|
158879
160090
|
globalSettingsSchema() {
|
|
@@ -158931,7 +160142,7 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
158931
160142
|
const bridged = mapper !== null && this.bridgeHost?.holds(mapper.accessory) === true;
|
|
158932
160143
|
const name = entry?.displayName ?? `Device ${deviceId}`;
|
|
158933
160144
|
const bridgePaired = this.bridgeHost?.accessory !== null && this.bridgeHost?.accessory !== void 0 ? accessoryPaired(this.bridgeHost.accessory) : false;
|
|
158934
|
-
const statusLabel = !enabled ? "Not exposed" : bridged ? bridgePaired ? `On the “${this.config.bridgeName}” bridge, as “${name}”` : `On the “${this.config.bridgeName}” bridge, as “${name}” — the BRIDGE is not paired yet. In iOS Home: + → Add Accessory → “${this.config.bridgeName}”, then enter setup code ${this.
|
|
160145
|
+
const statusLabel = !enabled ? "Not exposed" : bridged ? bridgePaired ? `On the “${this.config.bridgeName}” bridge, as “${name}”` : `On the “${this.config.bridgeName}” bridge, as “${name}” — the BRIDGE is not paired yet. In iOS Home: + → Add Accessory → “${this.config.bridgeName}”, then enter setup code ${this.pincode}. Every bridged device arrives with it.` : paired ? `Paired — exposed as “${name}”` : `Exposed as “${name}” — not paired yet. In iOS Home: + → Add Accessory → “${name}”, then enter setup code ${this.pincode}.`;
|
|
158935
160146
|
const qrSource = bridged ? this.bridgeHost?.accessory ?? null : mapper?.accessory ?? null;
|
|
158936
160147
|
let qrValue = "";
|
|
158937
160148
|
if (qrSource) try {
|
|
@@ -159058,7 +160269,7 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
159058
160269
|
type: "qr-code",
|
|
159059
160270
|
key: "__hap-pair-qr",
|
|
159060
160271
|
label: paired ? "Pairing QR (already paired)" : "Pairing QR",
|
|
159061
|
-
caption: paired ? `Already paired with at least one device. Scan from another iPhone / iPad to add it there too. Setup code: ${this.
|
|
160272
|
+
caption: paired ? `Already paired with at least one device. Scan from another iPhone / iPad to add it there too. Setup code: ${this.pincode}.` : `Scan with the iOS Camera app to pair this accessory in HomeKit. Setup code: ${this.pincode}.`,
|
|
159062
160273
|
value: qrValue,
|
|
159063
160274
|
size: 192,
|
|
159064
160275
|
alt: `HomeKit pairing QR for ${name}`,
|
|
@@ -159222,16 +160433,72 @@ var ExportHapAddon = class extends BaseAddon {
|
|
|
159222
160433
|
const planes = this.hksvClipPlanes;
|
|
159223
160434
|
return `/addon/${EXPORT_HAP_ADDON_ID}/${kind === "media" ? planes?.mediaPrefix ?? "hksv-clip" : planes?.thumbPrefix ?? "hksv-clip-thumb"}/${String(deviceId)}/${stem}.${kind === "media" ? "mp4" : "jpg"}`;
|
|
159224
160435
|
}
|
|
160436
|
+
/** The exposure record's handle: one row per bridge instance, under the instance id. */
|
|
160437
|
+
exposureHandle() {
|
|
160438
|
+
return this.requireRecords().kind(hapBridgeExportsKind);
|
|
160439
|
+
}
|
|
160440
|
+
/** Load the default instance's exposure record; create it empty when none exists. */
|
|
160441
|
+
async loadExposure() {
|
|
160442
|
+
const handle = this.exposureHandle();
|
|
160443
|
+
const row = await handle.get(HAP_DEFAULT_INSTANCE_ID);
|
|
160444
|
+
if (row !== null) {
|
|
160445
|
+
this.exposure = row.data;
|
|
160446
|
+
return;
|
|
160447
|
+
}
|
|
160448
|
+
await handle.put({
|
|
160449
|
+
id: HAP_DEFAULT_INSTANCE_ID,
|
|
160450
|
+
data: this.exposure
|
|
160451
|
+
}, { ifRev: 0 });
|
|
160452
|
+
}
|
|
160453
|
+
async writeExposure(next) {
|
|
160454
|
+
await this.exposureHandle().put({
|
|
160455
|
+
id: HAP_DEFAULT_INSTANCE_ID,
|
|
160456
|
+
data: next
|
|
160457
|
+
});
|
|
160458
|
+
this.exposure = next;
|
|
160459
|
+
}
|
|
160460
|
+
setExposedDevices(devices) {
|
|
160461
|
+
return this.writeExposure({
|
|
160462
|
+
...this.exposure,
|
|
160463
|
+
devices
|
|
160464
|
+
});
|
|
160465
|
+
}
|
|
160466
|
+
setExposedActions(actions) {
|
|
160467
|
+
return this.writeExposure({
|
|
160468
|
+
...this.exposure,
|
|
160469
|
+
actions
|
|
160470
|
+
});
|
|
160471
|
+
}
|
|
160472
|
+
/** The ports the exposure migration reads and writes through. */
|
|
160473
|
+
exposureMigrationPorts() {
|
|
160474
|
+
const handle = this.exposureHandle();
|
|
160475
|
+
return {
|
|
160476
|
+
putExposure: async (body) => {
|
|
160477
|
+
if (await handle.get("export-hap") !== null) return "exists";
|
|
160478
|
+
try {
|
|
160479
|
+
await handle.put({
|
|
160480
|
+
id: HAP_DEFAULT_INSTANCE_ID,
|
|
160481
|
+
data: body
|
|
160482
|
+
}, { ifRev: 0 });
|
|
160483
|
+
} catch (err) {
|
|
160484
|
+
if (err instanceof RevConflictError) return "exists";
|
|
160485
|
+
throw err;
|
|
160486
|
+
}
|
|
160487
|
+
return "created";
|
|
160488
|
+
},
|
|
160489
|
+
readExposure: async () => (await handle.get("export-hap"))?.data ?? null
|
|
160490
|
+
};
|
|
160491
|
+
}
|
|
159225
160492
|
findEntry(deviceId) {
|
|
159226
160493
|
const id = String(deviceId);
|
|
159227
|
-
return this.
|
|
160494
|
+
return this.exposure.devices.find((e) => e.deviceId === id) ?? null;
|
|
159228
160495
|
}
|
|
159229
160496
|
async updateEntrySettings(deviceIdStr, settings) {
|
|
159230
|
-
const next = this.
|
|
160497
|
+
const next = this.exposure.devices.map((e) => e.deviceId === deviceIdStr ? {
|
|
159231
160498
|
...e,
|
|
159232
160499
|
settings
|
|
159233
160500
|
} : e);
|
|
159234
|
-
await this.
|
|
160501
|
+
await this.setExposedDevices(next);
|
|
159235
160502
|
}
|
|
159236
160503
|
};
|
|
159237
160504
|
function errMsg(err) {
|