@camstack/addon-export-google 0.1.124 → 0.1.125
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 +6 -0
- package/dist/export-google.addon.js +656 -43
- package/dist/export-google.addon.mjs +656 -43
- package/package.json +2 -2
|
@@ -4632,6 +4632,12 @@ var numberProcessor = (schema, ctx, _json, _params) => {
|
|
|
4632
4632
|
var booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4633
4633
|
json.type = "boolean";
|
|
4634
4634
|
};
|
|
4635
|
+
var bigintProcessor = (_schema, ctx, _json, _params) => {
|
|
4636
|
+
if (ctx.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
|
|
4637
|
+
};
|
|
4638
|
+
var symbolProcessor = (_schema, ctx, _json, _params) => {
|
|
4639
|
+
if (ctx.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
|
|
4640
|
+
};
|
|
4635
4641
|
var nullProcessor = (_schema, ctx, json, _params) => {
|
|
4636
4642
|
if (ctx.target === "openapi-3.0") {
|
|
4637
4643
|
json.type = "string";
|
|
@@ -4639,12 +4645,17 @@ var nullProcessor = (_schema, ctx, json, _params) => {
|
|
|
4639
4645
|
json.enum = [null];
|
|
4640
4646
|
} else json.type = "null";
|
|
4641
4647
|
};
|
|
4648
|
+
var undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
4649
|
+
if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
|
|
4650
|
+
};
|
|
4642
4651
|
var voidProcessor = (_schema, ctx, _json, _params) => {
|
|
4643
4652
|
if (ctx.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
|
|
4644
4653
|
};
|
|
4645
4654
|
var neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4646
4655
|
json.not = {};
|
|
4647
4656
|
};
|
|
4657
|
+
var anyProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4658
|
+
var unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
4648
4659
|
var dateProcessor = (_schema, ctx, _json, _params) => {
|
|
4649
4660
|
if (ctx.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
|
|
4650
4661
|
};
|
|
@@ -4676,12 +4687,53 @@ var literalProcessor = (schema, ctx, json, _params) => {
|
|
|
4676
4687
|
json.enum = vals;
|
|
4677
4688
|
}
|
|
4678
4689
|
};
|
|
4690
|
+
var nanProcessor = (_schema, ctx, _json, _params) => {
|
|
4691
|
+
if (ctx.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
|
|
4692
|
+
};
|
|
4693
|
+
var templateLiteralProcessor = (schema, _ctx, json, _params) => {
|
|
4694
|
+
const _json = json;
|
|
4695
|
+
const pattern = schema._zod.pattern;
|
|
4696
|
+
if (!pattern) throw new Error("Pattern not found in template literal");
|
|
4697
|
+
_json.type = "string";
|
|
4698
|
+
_json.pattern = pattern.source;
|
|
4699
|
+
};
|
|
4700
|
+
var fileProcessor = (schema, _ctx, json, _params) => {
|
|
4701
|
+
const _json = json;
|
|
4702
|
+
const file = {
|
|
4703
|
+
type: "string",
|
|
4704
|
+
format: "binary",
|
|
4705
|
+
contentEncoding: "binary"
|
|
4706
|
+
};
|
|
4707
|
+
const { minimum, maximum, mime } = schema._zod.bag;
|
|
4708
|
+
if (minimum !== void 0) file.minLength = minimum;
|
|
4709
|
+
if (maximum !== void 0) file.maxLength = maximum;
|
|
4710
|
+
if (mime) if (mime.length === 1) {
|
|
4711
|
+
file.contentMediaType = mime[0];
|
|
4712
|
+
Object.assign(_json, file);
|
|
4713
|
+
} else {
|
|
4714
|
+
Object.assign(_json, file);
|
|
4715
|
+
_json.anyOf = mime.map((m) => ({ contentMediaType: m }));
|
|
4716
|
+
}
|
|
4717
|
+
else Object.assign(_json, file);
|
|
4718
|
+
};
|
|
4719
|
+
var successProcessor = (_schema, _ctx, json, _params) => {
|
|
4720
|
+
json.type = "boolean";
|
|
4721
|
+
};
|
|
4679
4722
|
var customProcessor = (_schema, ctx, _json, _params) => {
|
|
4680
4723
|
if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
|
|
4681
4724
|
};
|
|
4725
|
+
var functionProcessor = (_schema, ctx, _json, _params) => {
|
|
4726
|
+
if (ctx.unrepresentable === "throw") throw new Error("Function types cannot be represented in JSON Schema");
|
|
4727
|
+
};
|
|
4682
4728
|
var transformProcessor = (_schema, ctx, _json, _params) => {
|
|
4683
4729
|
if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
|
|
4684
4730
|
};
|
|
4731
|
+
var mapProcessor = (_schema, ctx, _json, _params) => {
|
|
4732
|
+
if (ctx.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
|
|
4733
|
+
};
|
|
4734
|
+
var setProcessor = (_schema, ctx, _json, _params) => {
|
|
4735
|
+
if (ctx.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
|
|
4736
|
+
};
|
|
4685
4737
|
var arrayProcessor = (schema, ctx, _json, params) => {
|
|
4686
4738
|
const json = _json;
|
|
4687
4739
|
const def = schema._zod.def;
|
|
@@ -4886,6 +4938,12 @@ var readonlyProcessor = (schema, ctx, json, params) => {
|
|
|
4886
4938
|
seen.ref = def.innerType;
|
|
4887
4939
|
json.readOnly = true;
|
|
4888
4940
|
};
|
|
4941
|
+
var promiseProcessor = (schema, ctx, _json, params) => {
|
|
4942
|
+
const def = schema._zod.def;
|
|
4943
|
+
process(def.innerType, ctx, params);
|
|
4944
|
+
const seen = ctx.seen.get(schema);
|
|
4945
|
+
seen.ref = def.innerType;
|
|
4946
|
+
};
|
|
4889
4947
|
var optionalProcessor = (schema, ctx, _json, params) => {
|
|
4890
4948
|
const def = schema._zod.def;
|
|
4891
4949
|
process(def.innerType, ctx, params);
|
|
@@ -4898,6 +4956,81 @@ var lazyProcessor = (schema, ctx, _json, params) => {
|
|
|
4898
4956
|
const seen = ctx.seen.get(schema);
|
|
4899
4957
|
seen.ref = innerType;
|
|
4900
4958
|
};
|
|
4959
|
+
var allProcessors = {
|
|
4960
|
+
string: stringProcessor,
|
|
4961
|
+
number: numberProcessor,
|
|
4962
|
+
boolean: booleanProcessor,
|
|
4963
|
+
bigint: bigintProcessor,
|
|
4964
|
+
symbol: symbolProcessor,
|
|
4965
|
+
null: nullProcessor,
|
|
4966
|
+
undefined: undefinedProcessor,
|
|
4967
|
+
void: voidProcessor,
|
|
4968
|
+
never: neverProcessor,
|
|
4969
|
+
any: anyProcessor,
|
|
4970
|
+
unknown: unknownProcessor,
|
|
4971
|
+
date: dateProcessor,
|
|
4972
|
+
enum: enumProcessor,
|
|
4973
|
+
literal: literalProcessor,
|
|
4974
|
+
nan: nanProcessor,
|
|
4975
|
+
template_literal: templateLiteralProcessor,
|
|
4976
|
+
file: fileProcessor,
|
|
4977
|
+
success: successProcessor,
|
|
4978
|
+
custom: customProcessor,
|
|
4979
|
+
function: functionProcessor,
|
|
4980
|
+
transform: transformProcessor,
|
|
4981
|
+
map: mapProcessor,
|
|
4982
|
+
set: setProcessor,
|
|
4983
|
+
array: arrayProcessor,
|
|
4984
|
+
object: objectProcessor,
|
|
4985
|
+
union: unionProcessor,
|
|
4986
|
+
intersection: intersectionProcessor,
|
|
4987
|
+
tuple: tupleProcessor,
|
|
4988
|
+
record: recordProcessor,
|
|
4989
|
+
nullable: nullableProcessor,
|
|
4990
|
+
nonoptional: nonoptionalProcessor,
|
|
4991
|
+
default: defaultProcessor,
|
|
4992
|
+
prefault: prefaultProcessor,
|
|
4993
|
+
catch: catchProcessor,
|
|
4994
|
+
pipe: pipeProcessor,
|
|
4995
|
+
readonly: readonlyProcessor,
|
|
4996
|
+
promise: promiseProcessor,
|
|
4997
|
+
optional: optionalProcessor,
|
|
4998
|
+
lazy: lazyProcessor
|
|
4999
|
+
};
|
|
5000
|
+
function toJSONSchema(input, params) {
|
|
5001
|
+
if ("_idmap" in input) {
|
|
5002
|
+
const registry = input;
|
|
5003
|
+
const ctx = initializeContext({
|
|
5004
|
+
...params,
|
|
5005
|
+
processors: allProcessors
|
|
5006
|
+
});
|
|
5007
|
+
const defs = {};
|
|
5008
|
+
for (const entry of registry._idmap.entries()) {
|
|
5009
|
+
const [_, schema] = entry;
|
|
5010
|
+
process(schema, ctx);
|
|
5011
|
+
}
|
|
5012
|
+
const schemas = {};
|
|
5013
|
+
ctx.external = {
|
|
5014
|
+
registry,
|
|
5015
|
+
uri: params?.uri,
|
|
5016
|
+
defs
|
|
5017
|
+
};
|
|
5018
|
+
for (const entry of registry._idmap.entries()) {
|
|
5019
|
+
const [key, schema] = entry;
|
|
5020
|
+
extractDefs(ctx, schema);
|
|
5021
|
+
schemas[key] = finalize(ctx, schema);
|
|
5022
|
+
}
|
|
5023
|
+
if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
|
|
5024
|
+
return { schemas };
|
|
5025
|
+
}
|
|
5026
|
+
const ctx = initializeContext({
|
|
5027
|
+
...params,
|
|
5028
|
+
processors: allProcessors
|
|
5029
|
+
});
|
|
5030
|
+
process(input, ctx);
|
|
5031
|
+
extractDefs(ctx, input);
|
|
5032
|
+
return finalize(ctx, input);
|
|
5033
|
+
}
|
|
4901
5034
|
//#endregion
|
|
4902
5035
|
//#region ../../node_modules/zod/v4/classic/iso.js
|
|
4903
5036
|
var ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
@@ -5922,7 +6055,7 @@ var ZodIssueCode = {
|
|
|
5922
6055
|
var ZodFirstPartyTypeKind;
|
|
5923
6056
|
ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
|
|
5924
6057
|
//#endregion
|
|
5925
|
-
//#region ../types/dist/sleep-
|
|
6058
|
+
//#region ../types/dist/sleep-BaWhXZFm.mjs
|
|
5926
6059
|
/**
|
|
5927
6060
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
5928
6061
|
* window to float samples (D455).
|
|
@@ -6885,7 +7018,7 @@ async function writeMembers(ctx, children, incoming, stored, pathOf) {
|
|
|
6885
7018
|
for (const [member, node] of children) applyMember(out, member, await writeNode(ctx, node, incoming[member], stored[member], pathOf(member)), stored);
|
|
6886
7019
|
return out;
|
|
6887
7020
|
}
|
|
6888
|
-
function rowId(row, idKey) {
|
|
7021
|
+
function rowId$1(row, idKey) {
|
|
6889
7022
|
const raw = row[idKey];
|
|
6890
7023
|
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
6891
7024
|
if (typeof raw === "number" && Number.isFinite(raw)) return String(raw);
|
|
@@ -6902,7 +7035,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6902
7035
|
}
|
|
6903
7036
|
const storedById = /* @__PURE__ */ new Map();
|
|
6904
7037
|
for (const row of storedRows) {
|
|
6905
|
-
const id = rowId(row, node.idKey);
|
|
7038
|
+
const id = rowId$1(row, node.idKey);
|
|
6906
7039
|
if (id !== null) storedById.set(id, row);
|
|
6907
7040
|
}
|
|
6908
7041
|
const kept = /* @__PURE__ */ new Set();
|
|
@@ -6912,13 +7045,13 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
6912
7045
|
rows.push(row);
|
|
6913
7046
|
continue;
|
|
6914
7047
|
}
|
|
6915
|
-
const id = rowId(row, node.idKey) ?? ctx.mintId();
|
|
7048
|
+
const id = rowId$1(row, node.idKey) ?? ctx.mintId();
|
|
6916
7049
|
kept.add(id);
|
|
6917
7050
|
const withId = {
|
|
6918
7051
|
...row,
|
|
6919
7052
|
[node.idKey]: row[node.idKey] ?? id
|
|
6920
7053
|
};
|
|
6921
|
-
if (rowId(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
7054
|
+
if (rowId$1(withId, node.idKey) === null) withId[node.idKey] = id;
|
|
6922
7055
|
const storedRow = storedById.get(id) ?? {};
|
|
6923
7056
|
rows.push(await writeMembers(ctx, node.item, withId, storedRow, (member) => arrayItemFieldPath(fieldPath, id, member)));
|
|
6924
7057
|
}
|
|
@@ -8653,6 +8786,38 @@ function normalizeAddonInitResult(result) {
|
|
|
8653
8786
|
if (Array.isArray(result)) return { providers: result };
|
|
8654
8787
|
return result;
|
|
8655
8788
|
}
|
|
8789
|
+
var PREFIX$1 = "records/";
|
|
8790
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
8791
|
+
var RecordsError = class extends Error {
|
|
8792
|
+
code;
|
|
8793
|
+
detail;
|
|
8794
|
+
constructor(code, detail) {
|
|
8795
|
+
super(`${PREFIX$1}${code}: ${detail}`);
|
|
8796
|
+
this.name = "RecordsError";
|
|
8797
|
+
this.code = code;
|
|
8798
|
+
this.detail = detail;
|
|
8799
|
+
}
|
|
8800
|
+
};
|
|
8801
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
8802
|
+
var RevConflictError = class extends RecordsError {
|
|
8803
|
+
constructor(detail) {
|
|
8804
|
+
super("rev-conflict", detail);
|
|
8805
|
+
this.name = "RevConflictError";
|
|
8806
|
+
}
|
|
8807
|
+
};
|
|
8808
|
+
var InvalidRecordError = class extends RecordsError {
|
|
8809
|
+
constructor(detail) {
|
|
8810
|
+
super("invalid-record", detail);
|
|
8811
|
+
this.name = "InvalidRecordError";
|
|
8812
|
+
}
|
|
8813
|
+
};
|
|
8814
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
8815
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
8816
|
+
constructor(detail) {
|
|
8817
|
+
super("declaration-refused", detail);
|
|
8818
|
+
this.name = "DeclarationRefusedError";
|
|
8819
|
+
}
|
|
8820
|
+
};
|
|
8656
8821
|
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
8657
8822
|
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
8658
8823
|
var RECORD_DATABASES = ["settings", "events"];
|
|
@@ -8668,6 +8833,50 @@ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
|
8668
8833
|
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
8669
8834
|
var RECORD_BATCH_MAX = 1e3;
|
|
8670
8835
|
var RECORD_QUERY_MAX = 1e3;
|
|
8836
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
8837
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
8838
|
+
/**
|
|
8839
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
8840
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
8841
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
8842
|
+
*
|
|
8843
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
8844
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
8845
|
+
* key releases exactly that key's secret.
|
|
8846
|
+
*
|
|
8847
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
8848
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
8849
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
8850
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
8851
|
+
*
|
|
8852
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
8853
|
+
*/
|
|
8854
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
8855
|
+
function parseSecretPath(path) {
|
|
8856
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
8857
|
+
return path.split(".").map((raw) => {
|
|
8858
|
+
const each = raw.endsWith("[]");
|
|
8859
|
+
const map = raw.endsWith("{}");
|
|
8860
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
8861
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
8862
|
+
return {
|
|
8863
|
+
key,
|
|
8864
|
+
each,
|
|
8865
|
+
map
|
|
8866
|
+
};
|
|
8867
|
+
});
|
|
8868
|
+
}
|
|
8869
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
8870
|
+
function secretArrayPrefixes(path) {
|
|
8871
|
+
const segments = parseSecretPath(path);
|
|
8872
|
+
const prefixes = [];
|
|
8873
|
+
const walked = [];
|
|
8874
|
+
for (const segment of segments) {
|
|
8875
|
+
walked.push(segment.key);
|
|
8876
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
8877
|
+
}
|
|
8878
|
+
return prefixes;
|
|
8879
|
+
}
|
|
8671
8880
|
/**
|
|
8672
8881
|
* The share-view scope kinds a share-link token can carry. The hub mints
|
|
8673
8882
|
* and validates them (`ShareViewGrantSchema` builds its
|
|
@@ -8692,6 +8901,75 @@ var PeerBytesTicketSchema = object({
|
|
|
8692
8901
|
*/
|
|
8693
8902
|
declaredBytes: number().int().nonnegative().nullable()
|
|
8694
8903
|
});
|
|
8904
|
+
function defOf(schema) {
|
|
8905
|
+
const zodBag = Reflect.get(schema, "_zod");
|
|
8906
|
+
if (typeof zodBag !== "object" || zodBag === null) return {};
|
|
8907
|
+
const def = Reflect.get(zodBag, "def");
|
|
8908
|
+
if (typeof def !== "object" || def === null) return {};
|
|
8909
|
+
return def;
|
|
8910
|
+
}
|
|
8911
|
+
function declaredHere(schema) {
|
|
8912
|
+
return globalRegistry.get(schema)?.secret === true;
|
|
8913
|
+
}
|
|
8914
|
+
/** Wrapper kinds whose `innerType` is the field itself. */
|
|
8915
|
+
var WRAPPERS = new Set([
|
|
8916
|
+
"optional",
|
|
8917
|
+
"nullable",
|
|
8918
|
+
"default",
|
|
8919
|
+
"prefault",
|
|
8920
|
+
"catch",
|
|
8921
|
+
"readonly",
|
|
8922
|
+
"nonoptional"
|
|
8923
|
+
]);
|
|
8924
|
+
/**
|
|
8925
|
+
* The schema layers that make up ONE field: the schema itself and every
|
|
8926
|
+
* wrapper below it (optional / default / nullable / readonly / catch), plus
|
|
8927
|
+
* both sides of a pipe (`z.preprocess` puts the real schema on `out`,
|
|
8928
|
+
* `.transform` on `in`).
|
|
8929
|
+
*/
|
|
8930
|
+
function layersOf(schema) {
|
|
8931
|
+
const out = [];
|
|
8932
|
+
const queue = [schema];
|
|
8933
|
+
while (queue.length > 0) {
|
|
8934
|
+
const s = queue.shift();
|
|
8935
|
+
if (!s || out.includes(s)) continue;
|
|
8936
|
+
out.push(s);
|
|
8937
|
+
const def = defOf(s);
|
|
8938
|
+
if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
|
|
8939
|
+
if (def.type === "pipe") {
|
|
8940
|
+
if (def.in) queue.push(def.in);
|
|
8941
|
+
if (def.out) queue.push(def.out);
|
|
8942
|
+
}
|
|
8943
|
+
}
|
|
8944
|
+
return out;
|
|
8945
|
+
}
|
|
8946
|
+
/** True when any layer of this field declares `.meta({ secret: true })`. */
|
|
8947
|
+
function isZodSecret(schema) {
|
|
8948
|
+
return layersOf(schema).some(declaredHere);
|
|
8949
|
+
}
|
|
8950
|
+
/**
|
|
8951
|
+
* Every declared secret path in a config schema: dotted keys, `[]` for "each
|
|
8952
|
+
* element of this array" (`connection.password`, `rows[].token`), `{}` for "each value of this
|
|
8953
|
+
* map" (`applianceSecrets{}`). A declared
|
|
8954
|
+
* object or array is reported as one path and not descended into — everything
|
|
8955
|
+
* under it is secret.
|
|
8956
|
+
*/
|
|
8957
|
+
function collectZodSecretPaths(schema, prefix = "") {
|
|
8958
|
+
if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
|
|
8959
|
+
const paths = [];
|
|
8960
|
+
for (const layer of layersOf(schema)) {
|
|
8961
|
+
const def = defOf(layer);
|
|
8962
|
+
if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
|
|
8963
|
+
else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
|
|
8964
|
+
else if (def.type === "record" && def.valueType) paths.push(...collectZodSecretPaths(def.valueType, `${prefix}{}`));
|
|
8965
|
+
else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
|
|
8966
|
+
else if (def.type === "intersection") {
|
|
8967
|
+
if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
|
|
8968
|
+
if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
|
|
8969
|
+
}
|
|
8970
|
+
}
|
|
8971
|
+
return [...new Set(paths)];
|
|
8972
|
+
}
|
|
8695
8973
|
/**
|
|
8696
8974
|
* Record kinds (D881): the declaration an addon makes of one kind of fact, the
|
|
8697
8975
|
* Zod row schema that describes it, and the helper that turns the two into the
|
|
@@ -8758,6 +9036,111 @@ var RecordKindDeclarationSchema = object({
|
|
|
8758
9036
|
}).strict();
|
|
8759
9037
|
/** The kind names: lower-case, dash separated, short enough for an index name. */
|
|
8760
9038
|
var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
|
|
9039
|
+
/** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
|
|
9040
|
+
function assertValidDeclaration(name, decl) {
|
|
9041
|
+
const refuse = (why) => {
|
|
9042
|
+
throw new DeclarationRefusedError(`kind "${name}": ${why}`);
|
|
9043
|
+
};
|
|
9044
|
+
if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
|
|
9045
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9046
|
+
for (const index of decl.indexes) {
|
|
9047
|
+
if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
|
|
9048
|
+
seen.add(index.name);
|
|
9049
|
+
}
|
|
9050
|
+
const { retention } = decl;
|
|
9051
|
+
const hasSecrets = decl.secretPaths.length > 0;
|
|
9052
|
+
if ("ttlMs" in retention) {
|
|
9053
|
+
if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
|
|
9054
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
|
|
9055
|
+
}
|
|
9056
|
+
if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
|
|
9057
|
+
if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
|
|
9058
|
+
if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
|
|
9059
|
+
if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
|
|
9060
|
+
const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
|
|
9061
|
+
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)`);
|
|
9062
|
+
}
|
|
9063
|
+
if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
|
|
9064
|
+
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`);
|
|
9065
|
+
}
|
|
9066
|
+
function bodyFieldsOf(schema) {
|
|
9067
|
+
return { ...toJSONSchema(schema, {
|
|
9068
|
+
unrepresentable: "any",
|
|
9069
|
+
io: "input"
|
|
9070
|
+
}) };
|
|
9071
|
+
}
|
|
9072
|
+
function isRecordLike(value) {
|
|
9073
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9074
|
+
}
|
|
9075
|
+
/** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
|
|
9076
|
+
function hasNameField(json, field) {
|
|
9077
|
+
const branches = json["oneOf"] ?? json["anyOf"];
|
|
9078
|
+
if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
|
|
9079
|
+
const properties = json["properties"];
|
|
9080
|
+
return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
|
|
9081
|
+
}
|
|
9082
|
+
/**
|
|
9083
|
+
* Declare the kinds of a package. The keys are the kind names. The result is
|
|
9084
|
+
* what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
|
|
9085
|
+
* types its handle from.
|
|
9086
|
+
*/
|
|
9087
|
+
function defineRecordKinds(specs) {
|
|
9088
|
+
const out = {};
|
|
9089
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
9090
|
+
const secretPaths = collectZodSecretPaths(spec.schema);
|
|
9091
|
+
const nameField = spec.entry?.nameField ?? "name";
|
|
9092
|
+
const fields = bodyFieldsOf(spec.schema);
|
|
9093
|
+
if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
|
|
9094
|
+
const parsed = RecordKindDeclarationSchema.parse({
|
|
9095
|
+
database: spec.database,
|
|
9096
|
+
class: spec.class,
|
|
9097
|
+
writeTrigger: spec.writeTrigger,
|
|
9098
|
+
device: spec.device,
|
|
9099
|
+
at: spec.at,
|
|
9100
|
+
indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
|
|
9101
|
+
retention: spec.retention,
|
|
9102
|
+
deviceRemoval: spec.deviceRemoval,
|
|
9103
|
+
maxDataBytes: spec.maxDataBytes,
|
|
9104
|
+
secretPaths: [...new Set([...secretPaths, ...spec.retiredSecretPaths ?? []])],
|
|
9105
|
+
secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
|
|
9106
|
+
transactFamily: spec.transactFamily,
|
|
9107
|
+
entry: spec.entry === void 0 ? void 0 : {
|
|
9108
|
+
title: spec.entry.title,
|
|
9109
|
+
nameField,
|
|
9110
|
+
fields
|
|
9111
|
+
}
|
|
9112
|
+
});
|
|
9113
|
+
assertValidDeclaration(name, parsed);
|
|
9114
|
+
out[name] = {
|
|
9115
|
+
name,
|
|
9116
|
+
schema: spec.schema,
|
|
9117
|
+
declaration: parsed
|
|
9118
|
+
};
|
|
9119
|
+
}
|
|
9120
|
+
return out;
|
|
9121
|
+
}
|
|
9122
|
+
/**
|
|
9123
|
+
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
9124
|
+
* engine, never aged, belonging to no device.
|
|
9125
|
+
*/
|
|
9126
|
+
function defineEntryKind(name, spec) {
|
|
9127
|
+
const defined = defineRecordKinds({ [name]: {
|
|
9128
|
+
schema: spec.schema,
|
|
9129
|
+
class: "config",
|
|
9130
|
+
writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
|
|
9131
|
+
retention: { none: "an entry goes only when the operator deletes it" },
|
|
9132
|
+
...spec.database === void 0 ? {} : { database: spec.database },
|
|
9133
|
+
...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
|
|
9134
|
+
...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
|
|
9135
|
+
...spec.retiredSecretPaths === void 0 ? {} : { retiredSecretPaths: spec.retiredSecretPaths },
|
|
9136
|
+
entry: {
|
|
9137
|
+
title: spec.title,
|
|
9138
|
+
...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
|
|
9139
|
+
}
|
|
9140
|
+
} })[name];
|
|
9141
|
+
if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
|
|
9142
|
+
return defined;
|
|
9143
|
+
}
|
|
8761
9144
|
object({
|
|
8762
9145
|
field: string().min(1),
|
|
8763
9146
|
on: literal("advance")
|
|
@@ -53595,6 +53978,21 @@ var IntegrationInstanceKindSchema = object({
|
|
|
53595
53978
|
disconnectPath: string().min(1).optional()
|
|
53596
53979
|
});
|
|
53597
53980
|
var IntegrationInstanceDescriptionSchema = object({
|
|
53981
|
+
/** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
|
|
53982
|
+
role: _enum([
|
|
53983
|
+
"devices",
|
|
53984
|
+
"services",
|
|
53985
|
+
"both"
|
|
53986
|
+
]),
|
|
53987
|
+
/** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
|
|
53988
|
+
discovery: object({
|
|
53989
|
+
mode: _enum([
|
|
53990
|
+
"none",
|
|
53991
|
+
"lan",
|
|
53992
|
+
"account"
|
|
53993
|
+
]),
|
|
53994
|
+
scopedToInstance: boolean()
|
|
53995
|
+
}).optional(),
|
|
53598
53996
|
/** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
|
|
53599
53997
|
instanceMode: IntegrationInstanceModeSchema,
|
|
53600
53998
|
/** What the instance is, for the UI (`destination`, `relay`, `account`). */
|
|
@@ -53634,10 +54032,11 @@ var IntegrationInstanceSchema = object({
|
|
|
53634
54032
|
/** The addon's own rule (an URL is present, a client id is present...). */
|
|
53635
54033
|
configured: boolean(),
|
|
53636
54034
|
/**
|
|
53637
|
-
* The instance's own on/off switch (D996)
|
|
53638
|
-
*
|
|
54035
|
+
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
54036
|
+
* so a row written before the field existed is on). Absent when the `integrations` registry
|
|
54037
|
+
* owns the switch (`describe().role` is `devices`): read it from the registry row.
|
|
53639
54038
|
*/
|
|
53640
|
-
enabled: boolean(),
|
|
54039
|
+
enabled: boolean().optional(),
|
|
53641
54040
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
53642
54041
|
kind: string().optional(),
|
|
53643
54042
|
/** Values for the instance form; a secret is a `SecretFieldView`, never text. */
|
|
@@ -90658,6 +91057,44 @@ var ActionSceneExports = class {
|
|
|
90658
91057
|
}
|
|
90659
91058
|
};
|
|
90660
91059
|
//#endregion
|
|
91060
|
+
//#region src/export-records.ts
|
|
91061
|
+
/**
|
|
91062
|
+
* What the Google export exposes, as a record (planning#408 P4): ONE `google-exports` record per
|
|
91063
|
+
* instance id (`export-google` today) holds the devices Google syncs and the actions it sees as
|
|
91064
|
+
* scenes. The addon is its only writer; the in-memory copy it loads at boot is what every
|
|
91065
|
+
* fulfillment intent reads.
|
|
91066
|
+
*/
|
|
91067
|
+
/** A single-instance addon keeps its records under its own addon id. */
|
|
91068
|
+
var GOOGLE_INSTANCE_ID = "export-google";
|
|
91069
|
+
var ExposedDeviceEntrySchema = object({
|
|
91070
|
+
deviceId: number(),
|
|
91071
|
+
exposedAt: number()
|
|
91072
|
+
});
|
|
91073
|
+
var ActionSceneEntrySchema = object({
|
|
91074
|
+
actionId: string(),
|
|
91075
|
+
displayName: string(),
|
|
91076
|
+
addedAt: number()
|
|
91077
|
+
});
|
|
91078
|
+
var GoogleExportsBodySchema = object({
|
|
91079
|
+
name: string().min(1),
|
|
91080
|
+
devices: array(ExposedDeviceEntrySchema),
|
|
91081
|
+
actions: array(ActionSceneEntrySchema)
|
|
91082
|
+
});
|
|
91083
|
+
var GOOGLE_EXPORTS_KIND_NAME = "google-exports";
|
|
91084
|
+
var GOOGLE_EXPORTS_NAME = "Google exposure";
|
|
91085
|
+
var googleExportsKind = defineEntryKind(GOOGLE_EXPORTS_KIND_NAME, {
|
|
91086
|
+
title: "Google exposure",
|
|
91087
|
+
nameField: "name",
|
|
91088
|
+
schema: GoogleExportsBodySchema
|
|
91089
|
+
});
|
|
91090
|
+
var EMPTY_GOOGLE_EXPORTS = {
|
|
91091
|
+
name: GOOGLE_EXPORTS_NAME,
|
|
91092
|
+
devices: [],
|
|
91093
|
+
actions: []
|
|
91094
|
+
};
|
|
91095
|
+
/** The settings keys that moved into the record; the migrations name them. */
|
|
91096
|
+
var MOVED_EXPOSURE_KEYS = ["exposed", "exposedActions"];
|
|
91097
|
+
//#endregion
|
|
90661
91098
|
//#region src/google-home/trait-catalog.ts
|
|
90662
91099
|
/**
|
|
90663
91100
|
* The trait catalog — one ROW per camstack capability, and that row is the
|
|
@@ -91488,24 +91925,151 @@ async function planDropPublicHubUrl(ports) {
|
|
|
91488
91925
|
}] };
|
|
91489
91926
|
}
|
|
91490
91927
|
//#endregion
|
|
91928
|
+
//#region src/migrations/exposure-to-record.ts
|
|
91929
|
+
/**
|
|
91930
|
+
* The Google exposure lists move into the `google-exports` record (planning#408 P4). Two
|
|
91931
|
+
* migrations, both `block-owner`: the addon must not serve a membership it cannot trust, and
|
|
91932
|
+
* after them nothing reads the old keys.
|
|
91933
|
+
*
|
|
91934
|
+
* 1. `moveExposureToRecord` (procedure): `exposed` and `exposedActions` become the record under
|
|
91935
|
+
* the instance id. An existing record is never overwritten. A record this pass just wrote is
|
|
91936
|
+
* read BACK and must equal what the settings carried, or the pass throws.
|
|
91937
|
+
* 2. `planDropMovedExposure` (plan): the two keys are deleted only while the record holds every
|
|
91938
|
+
* device and action the settings carried; a record that cannot be read leaves them in place.
|
|
91939
|
+
*/
|
|
91940
|
+
function devicesOf(value) {
|
|
91941
|
+
if (!Array.isArray(value)) return [];
|
|
91942
|
+
return value.flatMap((entry) => {
|
|
91943
|
+
const parsed = ExposedDeviceEntrySchema.safeParse(entry);
|
|
91944
|
+
return parsed.success ? [parsed.data] : [];
|
|
91945
|
+
});
|
|
91946
|
+
}
|
|
91947
|
+
function actionsOf(value) {
|
|
91948
|
+
if (!Array.isArray(value)) return [];
|
|
91949
|
+
return value.flatMap((entry) => {
|
|
91950
|
+
const parsed = ActionSceneEntrySchema.safeParse(entry);
|
|
91951
|
+
return parsed.success ? [parsed.data] : [];
|
|
91952
|
+
});
|
|
91953
|
+
}
|
|
91954
|
+
/** Key-order-independent JSON, so "identical" does not depend on how a store orders keys. */
|
|
91955
|
+
function canonical(value) {
|
|
91956
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
91957
|
+
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(",")}}`;
|
|
91958
|
+
return JSON.stringify(value) ?? "null";
|
|
91959
|
+
}
|
|
91960
|
+
async function moveExposureToRecord(ports) {
|
|
91961
|
+
const stored = await ports.readStored();
|
|
91962
|
+
if (!MOVED_EXPOSURE_KEYS.some((key) => key in stored)) return {
|
|
91963
|
+
outcome: "already-done",
|
|
91964
|
+
summary: { moved: false }
|
|
91965
|
+
};
|
|
91966
|
+
const devices = devicesOf(stored["exposed"]);
|
|
91967
|
+
const actions = actionsOf(stored["exposedActions"]);
|
|
91968
|
+
const dropped = (Array.isArray(stored["exposed"]) ? stored["exposed"].length : 0) - devices.length + ((Array.isArray(stored["exposedActions"]) ? stored["exposedActions"].length : 0) - actions.length);
|
|
91969
|
+
if (dropped > 0) ports.warn(`Google migration: ${dropped} exposure entr(ies) were not understood and are left out`);
|
|
91970
|
+
const body = {
|
|
91971
|
+
name: GOOGLE_EXPORTS_NAME,
|
|
91972
|
+
devices,
|
|
91973
|
+
actions
|
|
91974
|
+
};
|
|
91975
|
+
if (await ports.putExports(body) === "exists") return {
|
|
91976
|
+
outcome: "already-done",
|
|
91977
|
+
summary: { moved: false }
|
|
91978
|
+
};
|
|
91979
|
+
const held = await ports.readExports();
|
|
91980
|
+
if (held === null || canonical(held.devices) !== canonical(devices) || canonical(held.actions) !== canonical(actions)) throw new Error("the Google exposure record does not match the legacy settings; nothing was cleared");
|
|
91981
|
+
return {
|
|
91982
|
+
outcome: "done",
|
|
91983
|
+
summary: {
|
|
91984
|
+
moved: true,
|
|
91985
|
+
devices: devices.length,
|
|
91986
|
+
actions: actions.length
|
|
91987
|
+
}
|
|
91988
|
+
};
|
|
91989
|
+
}
|
|
91990
|
+
var rowId = (key) => `${GOOGLE_INSTANCE_ID}.${key}`;
|
|
91991
|
+
async function planDropMovedExposure(ports) {
|
|
91992
|
+
const stored = await ports.readStored();
|
|
91993
|
+
const present = MOVED_EXPOSURE_KEYS.filter((key) => key in stored);
|
|
91994
|
+
if (present.length === 0) return { edits: [] };
|
|
91995
|
+
const refuse = (reason) => {
|
|
91996
|
+
ports.warn(`Google migration: the legacy exposure keys are kept: ${reason}`);
|
|
91997
|
+
throw new Error(`the legacy Google exposure keys are not deleted: ${reason}`);
|
|
91998
|
+
};
|
|
91999
|
+
const held = await ports.readExports();
|
|
92000
|
+
if (held === null) return refuse("no exposure record exists");
|
|
92001
|
+
const heldDevices = new Set(held.devices.map((d) => d.deviceId));
|
|
92002
|
+
for (const device of devicesOf(stored["exposed"])) if (!heldDevices.has(device.deviceId)) return refuse(`the record lacks the device ${device.deviceId}`);
|
|
92003
|
+
const heldActions = new Set(held.actions.map((a) => a.actionId));
|
|
92004
|
+
for (const action of actionsOf(stored["exposedActions"])) if (!heldActions.has(action.actionId)) return refuse(`the record lacks the action ${action.actionId}`);
|
|
92005
|
+
return { edits: [{
|
|
92006
|
+
op: "deleteKeys",
|
|
92007
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
92008
|
+
keys: present.map(rowId),
|
|
92009
|
+
precondition: preconditionOf(Object.fromEntries(present.map((key) => [rowId(key), {
|
|
92010
|
+
addonId: GOOGLE_INSTANCE_ID,
|
|
92011
|
+
key,
|
|
92012
|
+
value: stored[key]
|
|
92013
|
+
}])))
|
|
92014
|
+
}] };
|
|
92015
|
+
}
|
|
92016
|
+
//#endregion
|
|
91491
92017
|
//#region src/migrations/index.ts
|
|
92018
|
+
var DROP_PUBLIC_HUB_URL_ID = "export-google/2026-11-02-drop-public-hub-url";
|
|
92019
|
+
var EXPOSURE_TO_RECORD_ID = "export-google/2026-11-04-exposure-to-record";
|
|
92020
|
+
var DROP_MOVED_EXPOSURE_ID = "export-google/2026-11-04-drop-moved-exposure";
|
|
92021
|
+
var FIXTURE_MARK = "the linked account list the migration does not know";
|
|
91492
92022
|
/** The `export-google` catalogue (D987): offered to the engine when the addon initialises. */
|
|
91493
|
-
var ADDON_MIGRATIONS = [
|
|
91494
|
-
|
|
91495
|
-
|
|
91496
|
-
|
|
91497
|
-
|
|
91498
|
-
|
|
91499
|
-
|
|
91500
|
-
|
|
91501
|
-
|
|
91502
|
-
|
|
91503
|
-
|
|
91504
|
-
|
|
91505
|
-
|
|
91506
|
-
|
|
91507
|
-
|
|
91508
|
-
|
|
92023
|
+
var ADDON_MIGRATIONS = [
|
|
92024
|
+
{
|
|
92025
|
+
meta: {
|
|
92026
|
+
id: DROP_PUBLIC_HUB_URL_ID,
|
|
92027
|
+
owner: "export-google",
|
|
92028
|
+
level: "addon-state",
|
|
92029
|
+
seq: 1,
|
|
92030
|
+
dependsOn: [],
|
|
92031
|
+
store: "settings",
|
|
92032
|
+
scope: "cluster",
|
|
92033
|
+
onFailure: "tolerate",
|
|
92034
|
+
bodyKind: "plan",
|
|
92035
|
+
description: "Delete the retired publicHubUrl and detectedPublicHubUrl settings; the public URL is the publicEndpoint role",
|
|
92036
|
+
fixtureMark: FIXTURE_MARK
|
|
92037
|
+
},
|
|
92038
|
+
plan: planDropPublicHubUrl
|
|
92039
|
+
},
|
|
92040
|
+
{
|
|
92041
|
+
meta: {
|
|
92042
|
+
id: EXPOSURE_TO_RECORD_ID,
|
|
92043
|
+
owner: "export-google",
|
|
92044
|
+
level: "addon-state",
|
|
92045
|
+
seq: 2,
|
|
92046
|
+
dependsOn: [],
|
|
92047
|
+
store: "settings",
|
|
92048
|
+
scope: "cluster",
|
|
92049
|
+
onFailure: "block-owner",
|
|
92050
|
+
bodyKind: "procedure",
|
|
92051
|
+
description: "Move the exposed devices and actions into the google-exports record; the record is read back before anything is deleted",
|
|
92052
|
+
fixtureMark: FIXTURE_MARK
|
|
92053
|
+
},
|
|
92054
|
+
procedure: moveExposureToRecord
|
|
92055
|
+
},
|
|
92056
|
+
{
|
|
92057
|
+
meta: {
|
|
92058
|
+
id: DROP_MOVED_EXPOSURE_ID,
|
|
92059
|
+
owner: "export-google",
|
|
92060
|
+
level: "addon-state",
|
|
92061
|
+
seq: 3,
|
|
92062
|
+
dependsOn: [EXPOSURE_TO_RECORD_ID],
|
|
92063
|
+
store: "settings",
|
|
92064
|
+
scope: "cluster",
|
|
92065
|
+
onFailure: "block-owner",
|
|
92066
|
+
bodyKind: "plan",
|
|
92067
|
+
description: "Delete the exposed and exposedActions settings keys once the record holds what they carried",
|
|
92068
|
+
fixtureMark: FIXTURE_MARK
|
|
92069
|
+
},
|
|
92070
|
+
plan: planDropMovedExposure
|
|
92071
|
+
}
|
|
92072
|
+
];
|
|
91509
92073
|
//#endregion
|
|
91510
92074
|
//#region src/public-endpoint.ts
|
|
91511
92075
|
/** The typed refusal when the role resolves to nothing. */
|
|
@@ -91575,11 +92139,7 @@ var buildConsoleSetupFromRole = async (input) => {
|
|
|
91575
92139
|
};
|
|
91576
92140
|
//#endregion
|
|
91577
92141
|
//#region src/types.ts
|
|
91578
|
-
var DEFAULT_SETTINGS = {
|
|
91579
|
-
exposed: [],
|
|
91580
|
-
exposedActions: [],
|
|
91581
|
-
linkedAccounts: []
|
|
91582
|
-
};
|
|
92142
|
+
var DEFAULT_SETTINGS = { linkedAccounts: [] };
|
|
91583
92143
|
//#endregion
|
|
91584
92144
|
//#region src/export-google.addon.ts
|
|
91585
92145
|
/**
|
|
@@ -91621,6 +92181,31 @@ var DEFAULT_SETTINGS = {
|
|
|
91621
92181
|
var ADDON_ID = "export-google";
|
|
91622
92182
|
var ExportGoogleAddon = class extends BaseAddon {
|
|
91623
92183
|
gateway = null;
|
|
92184
|
+
/**
|
|
92185
|
+
* The `google-exports` record: what Google syncs. Loaded once at boot after the migrations;
|
|
92186
|
+
* this addon is its only writer, so the in-memory copy is the synchronous read the fulfillment
|
|
92187
|
+
* path needs. No settings key backs it.
|
|
92188
|
+
*/
|
|
92189
|
+
exportsRow = EMPTY_GOOGLE_EXPORTS;
|
|
92190
|
+
exportsHandle = null;
|
|
92191
|
+
get exposedDevices() {
|
|
92192
|
+
return this.exportsRow.devices;
|
|
92193
|
+
}
|
|
92194
|
+
/** Persist a change of the exposure: the record first, the in-memory copy after it landed. */
|
|
92195
|
+
async writeExports(patch) {
|
|
92196
|
+
const handle = this.exportsHandle;
|
|
92197
|
+
if (handle === null) throw new Error("export-google: the exposure record is not open");
|
|
92198
|
+
const next = {
|
|
92199
|
+
name: this.exportsRow.name,
|
|
92200
|
+
devices: patch.devices ?? this.exportsRow.devices,
|
|
92201
|
+
actions: patch.actions ?? this.exportsRow.actions
|
|
92202
|
+
};
|
|
92203
|
+
await handle.put({
|
|
92204
|
+
id: GOOGLE_INSTANCE_ID,
|
|
92205
|
+
data: next
|
|
92206
|
+
});
|
|
92207
|
+
this.exportsRow = next;
|
|
92208
|
+
}
|
|
91624
92209
|
constructor() {
|
|
91625
92210
|
super({ ...DEFAULT_SETTINGS });
|
|
91626
92211
|
}
|
|
@@ -91630,15 +92215,43 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91630
92215
|
logger: this.ctx.logger
|
|
91631
92216
|
});
|
|
91632
92217
|
this.gateway = gateway;
|
|
91633
|
-
|
|
92218
|
+
const records = this.ctx.records;
|
|
92219
|
+
if (records === void 0) throw new Error("export-google needs ctx.records — check execution.placement (hub-only)");
|
|
92220
|
+
await records.declare({ "google-exports": googleExportsKind });
|
|
92221
|
+
const exportsHandle = records.kind(googleExportsKind);
|
|
92222
|
+
this.exportsHandle = exportsHandle;
|
|
92223
|
+
await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, {
|
|
92224
|
+
readStored: async () => this.resolveGlobalStore(),
|
|
92225
|
+
warn: (message) => {
|
|
92226
|
+
this.ctx.logger.warn(message, { tags: {
|
|
92227
|
+
topic: "export-google",
|
|
92228
|
+
phase: "migration"
|
|
92229
|
+
} });
|
|
92230
|
+
},
|
|
92231
|
+
putExports: async (body) => {
|
|
92232
|
+
if (await exportsHandle.get("export-google") !== null) return "exists";
|
|
92233
|
+
try {
|
|
92234
|
+
await exportsHandle.put({
|
|
92235
|
+
id: GOOGLE_INSTANCE_ID,
|
|
92236
|
+
data: body
|
|
92237
|
+
}, { ifRev: 0 });
|
|
92238
|
+
} catch (err) {
|
|
92239
|
+
if (err instanceof RevConflictError) return "exists";
|
|
92240
|
+
throw err;
|
|
92241
|
+
}
|
|
92242
|
+
return "created";
|
|
92243
|
+
},
|
|
92244
|
+
readExports: async () => (await exportsHandle.get("export-google"))?.data ?? null
|
|
92245
|
+
}));
|
|
92246
|
+
this.exportsRow = (await exportsHandle.get("export-google"))?.data ?? EMPTY_GOOGLE_EXPORTS;
|
|
91634
92247
|
const actionScenes = new ActionSceneExports({
|
|
91635
92248
|
api: this.ctx.api,
|
|
91636
92249
|
logger: this.ctx.logger,
|
|
91637
92250
|
isAdminUser: async (userId) => {
|
|
91638
92251
|
return (await this.ctx.api.userManagement.listUsers.query()).some((u) => u.id === userId && u.isAdmin);
|
|
91639
92252
|
},
|
|
91640
|
-
persist: (entries) => this.
|
|
91641
|
-
}, this.
|
|
92253
|
+
persist: (entries) => this.writeExports({ actions: [...entries] })
|
|
92254
|
+
}, this.exportsRow.actions);
|
|
91642
92255
|
actionScenes.reconcile().catch((err) => {
|
|
91643
92256
|
this.ctx.logger.warn("export-google: action scene reconcile at boot failed", { meta: { error: errMsg$1(err) } });
|
|
91644
92257
|
});
|
|
@@ -91648,7 +92261,7 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91648
92261
|
ownInstance(statusInstanceOf(input));
|
|
91649
92262
|
return {
|
|
91650
92263
|
linkState: this.config.linkedAccounts.length > 0 ? "linked" : "unlinked",
|
|
91651
|
-
exposedDeviceCount: this.
|
|
92264
|
+
exposedDeviceCount: this.exposedDevices.length,
|
|
91652
92265
|
setup: await this.buildSetupBlock()
|
|
91653
92266
|
};
|
|
91654
92267
|
},
|
|
@@ -91664,7 +92277,7 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91664
92277
|
},
|
|
91665
92278
|
listExposedDevices: async ({ instanceId }) => {
|
|
91666
92279
|
ownInstance(instanceId);
|
|
91667
|
-
return this.
|
|
92280
|
+
return this.exposedDevices.map((entry) => ({ deviceId: String(entry.deviceId) }));
|
|
91668
92281
|
},
|
|
91669
92282
|
exposeDevice: async ({ instanceId, deviceId }) => {
|
|
91670
92283
|
ownInstance(instanceId);
|
|
@@ -91678,7 +92291,7 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91678
92291
|
listExposedEntities: async ({ instanceId }) => {
|
|
91679
92292
|
ownInstance(instanceId);
|
|
91680
92293
|
await actionScenes.reconcile();
|
|
91681
|
-
return [...this.
|
|
92294
|
+
return [...this.exposedDevices.map((entry) => ({ entity: {
|
|
91682
92295
|
kind: "device",
|
|
91683
92296
|
deviceId: String(entry.deviceId)
|
|
91684
92297
|
} })), ...actionScenes.list()];
|
|
@@ -91707,7 +92320,7 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91707
92320
|
sync: {
|
|
91708
92321
|
gateway,
|
|
91709
92322
|
logger: this.ctx.logger,
|
|
91710
|
-
listExposed: () => this.
|
|
92323
|
+
listExposed: () => this.exposedDevices.map((entry) => entry.deviceId),
|
|
91711
92324
|
actions: actionScenes
|
|
91712
92325
|
},
|
|
91713
92326
|
query: {
|
|
@@ -91728,7 +92341,7 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91728
92341
|
}));
|
|
91729
92342
|
const oauthIntegrationProvider = { getDescriptor: async () => buildGoogleOauthIntegration() };
|
|
91730
92343
|
this.ctx.logger.info("export-google: initialized", { meta: {
|
|
91731
|
-
exposedCount: this.
|
|
92344
|
+
exposedCount: this.exposedDevices.length,
|
|
91732
92345
|
linkedAccounts: this.config.linkedAccounts.length,
|
|
91733
92346
|
willReportState: false
|
|
91734
92347
|
} });
|
|
@@ -91751,7 +92364,7 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91751
92364
|
this.gateway = null;
|
|
91752
92365
|
}
|
|
91753
92366
|
isExposed(deviceId) {
|
|
91754
|
-
return this.
|
|
92367
|
+
return this.exposedDevices.some((entry) => entry.deviceId === deviceId);
|
|
91755
92368
|
}
|
|
91756
92369
|
async exposeDevice(deviceIdRaw) {
|
|
91757
92370
|
const deviceId = Number.parseInt(deviceIdRaw, 10);
|
|
@@ -91770,20 +92383,20 @@ var ExportGoogleAddon = class extends BaseAddon {
|
|
|
91770
92383
|
});
|
|
91771
92384
|
throw new Error(`export-google: device ${deviceId} has no capability this addon exports (bound: ${facts.capNames.join(", ") || "none"})`);
|
|
91772
92385
|
}
|
|
91773
|
-
const next = this.
|
|
92386
|
+
const next = this.exposedDevices.filter((e) => e.deviceId !== deviceId);
|
|
91774
92387
|
next.push({
|
|
91775
92388
|
deviceId,
|
|
91776
92389
|
exposedAt: Date.now()
|
|
91777
92390
|
});
|
|
91778
|
-
await this.
|
|
92391
|
+
await this.writeExports({ devices: next });
|
|
91779
92392
|
this.ctx.logger.info("export-google: exposed device — visible after the next Google SYNC (\"Hey Google, sync my devices\")", { tags: { deviceId } });
|
|
91780
92393
|
}
|
|
91781
92394
|
async unexposeDevice(deviceIdRaw) {
|
|
91782
92395
|
const deviceId = Number.parseInt(deviceIdRaw, 10);
|
|
91783
92396
|
if (!Number.isFinite(deviceId)) return;
|
|
91784
|
-
const next = this.
|
|
91785
|
-
if (next.length === this.
|
|
91786
|
-
await this.
|
|
92397
|
+
const next = this.exposedDevices.filter((e) => e.deviceId !== deviceId);
|
|
92398
|
+
if (next.length === this.exposedDevices.length) return;
|
|
92399
|
+
await this.writeExports({ devices: next });
|
|
91787
92400
|
this.ctx.logger.info("export-google: unexposed device — removed from Google on its next SYNC", { tags: { deviceId } });
|
|
91788
92401
|
}
|
|
91789
92402
|
requireGateway() {
|