@camstack/server 1.2.929 → 1.2.930
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/package.json +9 -11
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +3 -3
- package/system/dist/builtins/composer/composer.addon.mjs +3 -3
- package/system/dist/builtins/core-blocks/actions-service.d.ts +18 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +986 -208
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +985 -208
- package/system/dist/builtins/core-blocks/tcp-connect.d.ts +3 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +6 -487
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +3 -484
- package/system/dist/builtins/device-manager/device-manager.addon.js +3 -3
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +3 -3
- package/system/dist/{composition-sources-Caqv7O7z.mjs → composition-sources-BEUWn2s_.mjs} +1 -1
- package/system/dist/{composition-sources-CgnHjm8Q.js → composition-sources-acfR4hDq.js} +1 -1
- package/system/dist/{core-blocks.cap-LEMqVwxO.js → core-blocks.cap-BMeMCBrx.js} +37 -9
- package/system/dist/{core-blocks.cap-C6iKAZ-x.mjs → core-blocks.cap-BRPsLAij.mjs} +32 -10
- package/system/dist/index.js +2 -2
- package/system/dist/index.mjs +2 -2
- package/system/dist/{notification-rules.cap-B__YBgnG.js → notification-rules.cap-BDh0LDhV.js} +6 -0
- package/system/dist/{notification-rules.cap-D9ArZlwx.mjs → notification-rules.cap-DUmiMBQB.mjs} +1 -1
- package/system/dist/notification-targets-CRH-9Dy5.js +509 -0
- package/system/dist/notification-targets-DaNE-pIt.mjs +486 -0
- package/system/dist/{prefix-walk-DC0ljmbB.js → prefix-walk-BkMxoXpL.js} +1 -1
- package/system/dist/{prefix-walk-B4b2-9aK.mjs → prefix-walk-ifwg_ukx.mjs} +1 -1
- package/system/dist/{rename-composition-block-CcWLwVhG.js → rename-composition-block-BJsL58Ih.js} +121 -15
- package/system/dist/{rename-composition-block-7WIICIDq.mjs → rename-composition-block-OAtErZgq.mjs} +121 -15
- package/system/package.json +1 -1
|
@@ -1,491 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
|
|
2
2
|
import { Z as errMsg } from "../../scoped-settings-DVWUIP7Z.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { i as notificationTargetKinds, n as buildNotificationTargetInstances, r as listNotificationTargets, t as NotificationTargetStore } from "../../notification-targets-DaNE-pIt.mjs";
|
|
4
|
+
import { f as notificationOutputCapability, l as NotificationFieldSchema, o as AlarmPanelStatusSchema, r as NcScheduleSchema, s as AlarmStateSchema } from "../../notification-rules.cap-DUmiMBQB.mjs";
|
|
5
5
|
import { t as integrationInstancesCapability } from "../../integration-instances.cap-Cl9O-k4h.mjs";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
|
-
//#region ../types/dist/esm/addon/compose-instance-kinds.mjs
|
|
9
|
-
/** No part holds the id a call named. */
|
|
10
|
-
var UnknownInstanceError = class extends Error {
|
|
11
|
-
instanceId;
|
|
12
|
-
constructor(instanceId) {
|
|
13
|
-
super(`Unknown instance '${instanceId}'`);
|
|
14
|
-
this.instanceId = instanceId;
|
|
15
|
-
this.name = "UnknownInstanceError";
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
/** A create or a form named no kind, or a kind no part serves. */
|
|
19
|
-
var UnknownInstanceKindError = class extends Error {
|
|
20
|
-
kindId;
|
|
21
|
-
constructor(kindId) {
|
|
22
|
-
super(kindId === void 0 ? "This provider has several kinds: name one" : `Unknown instance kind '${kindId}'`);
|
|
23
|
-
this.kindId = kindId;
|
|
24
|
-
this.name = "UnknownInstanceKindError";
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
function composeInstanceKinds(parts, base) {
|
|
28
|
-
const byKind = (kindId) => {
|
|
29
|
-
if (kindId === void 0) {
|
|
30
|
-
const only = parts.length === 1 ? parts[0] : void 0;
|
|
31
|
-
if (only === void 0) throw new UnknownInstanceKindError(void 0);
|
|
32
|
-
return only;
|
|
33
|
-
}
|
|
34
|
-
const part = parts.find((candidate) => candidate.kind.id === kindId);
|
|
35
|
-
if (part === void 0) throw new UnknownInstanceKindError(kindId);
|
|
36
|
-
return part;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Whether a part's kind offers a Test. A kind that states `canTest` is believed; one that does not
|
|
40
|
-
* takes what its OWN provider declares, never the composed base (a calendar or an integration
|
|
41
|
-
* inherited the account's `canTest: true` and offered a button nothing answered, planning#543).
|
|
42
|
-
*/
|
|
43
|
-
const canTestPart = async (part) => part.kind.canTest ?? (await part.provider.describe()).canTest === true;
|
|
44
|
-
/**
|
|
45
|
-
* The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
|
|
46
|
-
* testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
|
|
47
|
-
*/
|
|
48
|
-
const draftPart = async (kindId) => {
|
|
49
|
-
if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
|
|
50
|
-
const flags = await Promise.all(parts.map(canTestPart));
|
|
51
|
-
const testable = parts.filter((_part, index) => flags[index] === true);
|
|
52
|
-
const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
|
|
53
|
-
if (only !== void 0) return only;
|
|
54
|
-
return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
|
|
55
|
-
};
|
|
56
|
-
const holderOf = async (id) => {
|
|
57
|
-
for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
|
|
58
|
-
throw new UnknownInstanceError(id);
|
|
59
|
-
};
|
|
60
|
-
const tagged = (part, instance) => ({
|
|
61
|
-
...instance,
|
|
62
|
-
kind: part.kind.id
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
describe: async () => {
|
|
66
|
-
const links = (await Promise.all(parts.map(async (part) => (await part.provider.describe()).links ?? []))).flat();
|
|
67
|
-
return {
|
|
68
|
-
...base,
|
|
69
|
-
kinds: await Promise.all(parts.map(async (part) => ({
|
|
70
|
-
...part.kind,
|
|
71
|
-
canTest: await canTestPart(part)
|
|
72
|
-
}))),
|
|
73
|
-
...links.length > 0 ? { links } : {}
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
instanceFormSchema: async ({ id, kind }) => {
|
|
77
|
-
return (id === null ? byKind(kind) : await holderOf(id)).provider.instanceFormSchema({ id });
|
|
78
|
-
},
|
|
79
|
-
listInstances: async (input) => {
|
|
80
|
-
return (await Promise.all(parts.map(async (part) => (await part.provider.listInstances(input)).map((instance) => tagged(part, instance))))).flat();
|
|
81
|
-
},
|
|
82
|
-
getInstance: async ({ id }) => {
|
|
83
|
-
for (const part of parts) {
|
|
84
|
-
const found = await part.provider.getInstance({ id });
|
|
85
|
-
if (found !== null) return tagged(part, found);
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
},
|
|
89
|
-
createInstance: async (input) => byKind(input.kind).provider.createInstance(input),
|
|
90
|
-
updateInstance: async (input) => (await holderOf(input.id)).provider.updateInstance(input),
|
|
91
|
-
setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
|
|
92
|
-
deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
|
|
93
|
-
testInstance: async (input) => {
|
|
94
|
-
const resolved = input.id === null ? await draftPart(input.kind) : await holderOf(input.id);
|
|
95
|
-
if ("error" in resolved) return {
|
|
96
|
-
success: false,
|
|
97
|
-
status: "inconclusive",
|
|
98
|
-
error: resolved.error
|
|
99
|
-
};
|
|
100
|
-
const test = resolved.provider.testInstance;
|
|
101
|
-
if (test === void 0) return {
|
|
102
|
-
success: false,
|
|
103
|
-
status: "inconclusive",
|
|
104
|
-
error: "This kind cannot be tested"
|
|
105
|
-
};
|
|
106
|
-
return test(input);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region ../types/dist/esm/addon/instances-of-cap.mjs
|
|
112
|
-
/**
|
|
113
|
-
* The kind's instances answer for `cap`: it is the kind's `functionCap`, or one the kind declares in
|
|
114
|
-
* `alsoServes`. The one rule a link (a picker, a resolver, a delete guard) matches a target by.
|
|
115
|
-
*/
|
|
116
|
-
function kindServesCap(kind, cap) {
|
|
117
|
-
return kind.functionCap === cap || (kind.alsoServes ?? []).includes(cap);
|
|
118
|
-
}
|
|
119
|
-
async function instancesOfCap(source, cap, filter = {}) {
|
|
120
|
-
const instances = [];
|
|
121
|
-
const unreadable = [];
|
|
122
|
-
for (const addonId of await source.holders(cap)) try {
|
|
123
|
-
const kinds = ((await source.describe(addonId)).kinds ?? []).filter((kind) => kindServesCap(kind, cap));
|
|
124
|
-
if (kinds.length === 0) continue;
|
|
125
|
-
for (const instance of await source.listInstances(addonId)) {
|
|
126
|
-
const kind = kinds.find((candidate) => candidate.id === instance.kind);
|
|
127
|
-
if (kind === void 0) continue;
|
|
128
|
-
if (filter.kind !== void 0 && (kind.brokerKind ?? kind.id) !== filter.kind) continue;
|
|
129
|
-
instances.push({
|
|
130
|
-
addonId,
|
|
131
|
-
kind,
|
|
132
|
-
instance
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} catch (err) {
|
|
136
|
-
unreadable.push({
|
|
137
|
-
addonId,
|
|
138
|
-
error: err instanceof Error ? err.message : String(err)
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
instances,
|
|
143
|
-
unreadable
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
async function providersOf(api, name) {
|
|
147
|
-
const info = await api.capabilities.getCapability.query({ name });
|
|
148
|
-
if (info === null) throw new Error(`the capability registry did not answer for ${name}`);
|
|
149
|
-
return info.providers;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* The source over `ctx.api`. Every provider of the cap is a holder, not only those that also serve
|
|
153
|
-
* `integration-instances`: a provider that does not (an addon older than the hub during an update)
|
|
154
|
-
* then fails `describe` and is reported unreadable, so its instances are retried as transient
|
|
155
|
-
* instead of vanishing from the catalogue and failing for good.
|
|
156
|
-
*/
|
|
157
|
-
function instanceSourceOverApi(api) {
|
|
158
|
-
return {
|
|
159
|
-
holders: (cap) => providersOf(api, cap),
|
|
160
|
-
describe: (addonId) => api.integrationInstances.describe.query({ addonId }),
|
|
161
|
-
listInstances: (addonId) => api.integrationInstances.listInstances.query({ addonId })
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region ../types/dist/esm/addon/notification-targets.mjs
|
|
166
|
-
/**
|
|
167
|
-
* Notification targets as instances of the function cap `notification-output` (epic #440, step 6).
|
|
168
|
-
*
|
|
169
|
-
* A notification target used to be one row of one record kind (`{ name, kind, addonId, enabled,
|
|
170
|
-
* config }`) with a free-form `config` blob whose secrets nobody could name. Now every target KIND
|
|
171
|
-
* the provider offers (ntfy, telegram, webhook, ...) is a record kind of its own whose flat body IS
|
|
172
|
-
* that kind's form: the adapter's `configSchema` lifted into a Zod object, a `password` field marked
|
|
173
|
-
* `.meta({ secret: true })` so the records door keeps it in the keychain, an `instance-select` field
|
|
174
|
-
* declared as a link so the hub refuses to delete what a target points at.
|
|
175
|
-
*
|
|
176
|
-
* Three providers (notifiers, Home Assistant, Alexa) serve the same shape, so the pieces are shared:
|
|
177
|
-
* - {@link defineNotificationTargetKind}: the record kind of one `TargetKind` descriptor;
|
|
178
|
-
* - {@link NotificationTargetStore}: the `Target`-shaped facade the provider's own code keeps
|
|
179
|
-
* using (send, the notification-center bridge), over one handle per kind;
|
|
180
|
-
* - {@link listNotificationTargets}: the targets as an addon on `ctx.api` reads them;
|
|
181
|
-
* - {@link buildNotificationTargetInstances}: the `integration-instances` provider, one kind each;
|
|
182
|
-
* - {@link moveTargetRows}: the D987 procedure that flattens the old `config` blobs into the bodies.
|
|
183
|
-
*/
|
|
184
|
-
/** The function cap every notification target is an instance of. */
|
|
185
|
-
var NOTIFICATION_OUTPUT_CAP = "notification-output";
|
|
186
|
-
/** The most targets one provider lists (a settings page, not a table). */
|
|
187
|
-
var TARGETS_LIST_MAX = 1e3;
|
|
188
|
-
/** The record kind name of one target kind: `telegram` is stored under `notify-telegram`. */
|
|
189
|
-
function notificationTargetKindName(kind) {
|
|
190
|
-
return `notify-${kind}`;
|
|
191
|
-
}
|
|
192
|
-
/** The body schema of a target kind: the entry's name and switch plus the adapter's fields. */
|
|
193
|
-
var TargetBodyBaseSchema = /* @__PURE__ */ z.looseObject({
|
|
194
|
-
name: /* @__PURE__ */ z.string().min(1),
|
|
195
|
-
enabled: /* @__PURE__ */ z.boolean().optional()
|
|
196
|
-
});
|
|
197
|
-
/** The shape of one `editable-array` row: the item fields, a `password` one a secret. */
|
|
198
|
-
function rowSchemaOf(itemFields) {
|
|
199
|
-
const shape = {};
|
|
200
|
-
let idKey = null;
|
|
201
|
-
let hasSecret = false;
|
|
202
|
-
for (const item of itemFields) {
|
|
203
|
-
if (item.type === "password") {
|
|
204
|
-
shape[item.key] = z.string().optional().meta({ secret: true });
|
|
205
|
-
hasSecret = true;
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
shape[item.key] = z.unknown().optional();
|
|
209
|
-
idKey ??= item.key;
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
row: z.looseObject(shape),
|
|
213
|
-
idKey,
|
|
214
|
-
hasSecret
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* The Zod fields of a descriptor's form. A `password` field is a secret; an `instance-select` field is
|
|
219
|
-
* a link to an instance of its function cap; an `editable-array` keeps its rows (a password inside a
|
|
220
|
-
* row is a secret matched by the row's first plain field); every other field keeps whatever the
|
|
221
|
-
* adapter's own parse accepts, because the form already validated its shape. The body is loose, so a key
|
|
222
|
-
* the schema does not know (the owner of a personal target) survives a write.
|
|
223
|
-
*/
|
|
224
|
-
function fieldsOf(descriptor) {
|
|
225
|
-
const shape = {};
|
|
226
|
-
const secretArrayKeys = {};
|
|
227
|
-
for (const section of descriptor.configSchema.sections) for (const field of section.fields) switch (field.type) {
|
|
228
|
-
case "info": break;
|
|
229
|
-
case "password":
|
|
230
|
-
shape[field.key] = z.string().optional().meta({ secret: true });
|
|
231
|
-
break;
|
|
232
|
-
case "instance-select":
|
|
233
|
-
shape[field.key] = optionalLinkField({
|
|
234
|
-
cap: field.functionCap,
|
|
235
|
-
...field.kind !== void 0 ? { kind: field.kind } : {}
|
|
236
|
-
});
|
|
237
|
-
break;
|
|
238
|
-
case "editable-array": {
|
|
239
|
-
const { row, idKey, hasSecret } = rowSchemaOf(field.itemFields);
|
|
240
|
-
shape[field.key] = z.array(row).optional();
|
|
241
|
-
if (hasSecret && idKey !== null) secretArrayKeys[field.key] = idKey;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
default: shape[field.key] = z.unknown().optional();
|
|
245
|
-
}
|
|
246
|
-
return {
|
|
247
|
-
shape,
|
|
248
|
-
secretArrayKeys
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
/** The record kind of one target kind, derived from its descriptor. */
|
|
252
|
-
function defineNotificationTargetKind(descriptor) {
|
|
253
|
-
const { shape, secretArrayKeys } = fieldsOf(descriptor);
|
|
254
|
-
return defineEntryKind(notificationTargetKindName(descriptor.kind), {
|
|
255
|
-
title: `${descriptor.label} notification targets`,
|
|
256
|
-
schema: TargetBodyBaseSchema.extend(shape),
|
|
257
|
-
writeTrigger: `an operator adds, edits, switches or removes a ${descriptor.label} notification target`,
|
|
258
|
-
...Object.keys(secretArrayKeys).length > 0 ? { secretArrayKeys } : {}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
/** The record kinds of a provider's descriptors, keyed by the record kind name (for `records.declare`). */
|
|
262
|
-
function notificationTargetKinds(descriptors) {
|
|
263
|
-
return Object.fromEntries(descriptors.map((descriptor) => {
|
|
264
|
-
const defined = defineNotificationTargetKind(descriptor);
|
|
265
|
-
return [defined.name, defined];
|
|
266
|
-
}));
|
|
267
|
-
}
|
|
268
|
-
/** The body a stored target becomes: the switch and the name, and the config fields flat beside them. */
|
|
269
|
-
function targetBody(target) {
|
|
270
|
-
return {
|
|
271
|
-
...target.config,
|
|
272
|
-
name: target.name.length > 0 ? target.name : target.id,
|
|
273
|
-
enabled: target.enabled
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
/** The `Target` a record of a kind is; null when the row is not a target. */
|
|
277
|
-
function targetOfRecord(addonId, kind, id, data) {
|
|
278
|
-
const { name, enabled: _enabled, ...config } = data;
|
|
279
|
-
const parsed = TargetSchema.safeParse({
|
|
280
|
-
id,
|
|
281
|
-
name,
|
|
282
|
-
kind,
|
|
283
|
-
addonId,
|
|
284
|
-
enabled: isInstanceOn(id),
|
|
285
|
-
config
|
|
286
|
-
});
|
|
287
|
-
return parsed.success ? parsed.data : null;
|
|
288
|
-
}
|
|
289
|
-
function targetOfOld(addonId, row) {
|
|
290
|
-
return {
|
|
291
|
-
id: row.id,
|
|
292
|
-
name: row.name,
|
|
293
|
-
kind: row.kind,
|
|
294
|
-
addonId,
|
|
295
|
-
enabled: row.enabled,
|
|
296
|
-
config: { ...row.config }
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* The `Target`-shaped facade over one record kind per target kind. `list` returns the stored form (a
|
|
301
|
-
* secret is a keychain marker: every reader redacts it anyway); `getById` returns the target with its
|
|
302
|
-
* secrets resolved, which is what a send, a probe and an edit's secret merge need. A keychain that
|
|
303
|
-
* cannot answer throws: a write never goes ahead with a secret it could not read (D49).
|
|
304
|
-
*/
|
|
305
|
-
var NotificationTargetStore = class NotificationTargetStore {
|
|
306
|
-
addonId;
|
|
307
|
-
handles;
|
|
308
|
-
options;
|
|
309
|
-
constructor(addonId, handles, options) {
|
|
310
|
-
this.addonId = addonId;
|
|
311
|
-
this.handles = handles;
|
|
312
|
-
this.options = options;
|
|
313
|
-
}
|
|
314
|
-
static of(records, addonId, kinds, descriptors, options = {}) {
|
|
315
|
-
const handles = [];
|
|
316
|
-
for (const descriptor of descriptors) {
|
|
317
|
-
const defined = kinds[notificationTargetKindName(descriptor.kind)];
|
|
318
|
-
if (defined === void 0) continue;
|
|
319
|
-
handles.push({
|
|
320
|
-
kind: descriptor.kind,
|
|
321
|
-
handle: records.kind(defined)
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
return new NotificationTargetStore(addonId, handles, options);
|
|
325
|
-
}
|
|
326
|
-
/** The record handle of each kind, for the migration ports. */
|
|
327
|
-
handlesByKind() {
|
|
328
|
-
return new Map(this.handles.map((entry) => [entry.kind, entry.handle]));
|
|
329
|
-
}
|
|
330
|
-
async list() {
|
|
331
|
-
const out = [];
|
|
332
|
-
for (const { kind, handle } of this.handles) {
|
|
333
|
-
const page = await handle.query({ limit: TARGETS_LIST_MAX });
|
|
334
|
-
for (const record of page.records) {
|
|
335
|
-
const target = targetOfRecord(this.addonId, kind, record.id, record.data);
|
|
336
|
-
if (target !== null) {
|
|
337
|
-
out.push(target);
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
this.options.logger?.warn("notification target record is not a valid target; left out of the list", { meta: {
|
|
341
|
-
targetId: record.id,
|
|
342
|
-
kind
|
|
343
|
-
} });
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
const held = new Set(out.map((target) => target.id));
|
|
347
|
-
for (const row of await this.legacyRows()) if (!held.has(row.id)) out.push(targetOfOld(this.addonId, row));
|
|
348
|
-
return out;
|
|
349
|
-
}
|
|
350
|
-
/** The legacy rows of a kind this provider serves (the others are not ours to show). */
|
|
351
|
-
async legacyRows() {
|
|
352
|
-
const legacy = this.options.legacy;
|
|
353
|
-
if (legacy === void 0) return [];
|
|
354
|
-
const served = new Set(this.handles.map((entry) => entry.kind));
|
|
355
|
-
return (await legacy.list()).filter((row) => served.has(row.kind));
|
|
356
|
-
}
|
|
357
|
-
async getById(id) {
|
|
358
|
-
for (const { kind, handle } of this.handles) {
|
|
359
|
-
const row = await handle.getResolved(id);
|
|
360
|
-
if (row !== null) return targetOfRecord(this.addonId, kind, row.id, row.data);
|
|
361
|
-
}
|
|
362
|
-
const old = (await this.legacyRows()).find((row) => row.id === id);
|
|
363
|
-
return old === void 0 ? null : targetOfOld(this.addonId, old);
|
|
364
|
-
}
|
|
365
|
-
/** Insert or replace by id; a target whose kind changed leaves the record of its old kind. */
|
|
366
|
-
async upsert(target) {
|
|
367
|
-
const own = this.handles.find((entry) => entry.kind === target.kind);
|
|
368
|
-
if (own === void 0) throw new Error(`invalid target '${target.id}': unknown kind '${target.kind}'`);
|
|
369
|
-
const { enabled: _switch, ...data } = targetBody(target);
|
|
370
|
-
await own.handle.put({
|
|
371
|
-
id: target.id,
|
|
372
|
-
data
|
|
373
|
-
});
|
|
374
|
-
recordInstanceSwitch(target.id, target.enabled);
|
|
375
|
-
for (const other of this.handles) if (other !== own) await other.handle.delete(target.id);
|
|
376
|
-
await this.options.legacy?.delete(target.id);
|
|
377
|
-
}
|
|
378
|
-
async delete(id) {
|
|
379
|
-
for (const { handle } of this.handles) await handle.delete(id);
|
|
380
|
-
await this.options.legacy?.delete(id);
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* A probe's answer as the tri-state of `testInstance`: `ok` validated; a refusal that carries an HTTP
|
|
385
|
-
* status is the remote saying no (`rejected`); a failure with no answer at all (the network, a missing
|
|
386
|
-
* field) proves nothing about the credentials (`inconclusive`).
|
|
387
|
-
*/
|
|
388
|
-
function probeToTestResult(probed) {
|
|
389
|
-
if (probed.ok) return {
|
|
390
|
-
success: true,
|
|
391
|
-
status: "validated",
|
|
392
|
-
...probed.stateInstance !== void 0 ? { detail: probed.stateInstance } : {}
|
|
393
|
-
};
|
|
394
|
-
const error = probed.error ?? "the probe failed";
|
|
395
|
-
return {
|
|
396
|
-
success: false,
|
|
397
|
-
status: probed.httpStatus !== void 0 ? "rejected" : "inconclusive",
|
|
398
|
-
error
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
/** The form of a kind: the adapter's own sections. */
|
|
402
|
-
function formOf(descriptor) {
|
|
403
|
-
return descriptor.configSchema;
|
|
404
|
-
}
|
|
405
|
-
/** The instance kinds of a notification provider, one per target kind: a part a composition can take. */
|
|
406
|
-
function notificationTargetParts(records, spec) {
|
|
407
|
-
return spec.descriptors.flatMap((descriptor) => {
|
|
408
|
-
const defined = spec.kinds[notificationTargetKindName(descriptor.kind)];
|
|
409
|
-
if (defined === void 0) return [];
|
|
410
|
-
const canTest = spec.probe !== void 0 && spec.canProbe(descriptor.kind);
|
|
411
|
-
const kind = {
|
|
412
|
-
id: descriptor.kind,
|
|
413
|
-
label: descriptor.label,
|
|
414
|
-
functionCap: NOTIFICATION_OUTPUT_CAP,
|
|
415
|
-
role: "services",
|
|
416
|
-
canTest,
|
|
417
|
-
...spec.widgets?.(descriptor.kind) !== void 0 ? { widgets: spec.widgets(descriptor.kind) } : {},
|
|
418
|
-
...descriptor.iconUrl !== void 0 ? { iconUrl: descriptor.iconUrl } : {},
|
|
419
|
-
...descriptor.iconMediaType !== void 0 ? { iconMediaType: descriptor.iconMediaType } : {}
|
|
420
|
-
};
|
|
421
|
-
return [{
|
|
422
|
-
kind,
|
|
423
|
-
provider: new RecordIntegrationInstances(records, defined, {
|
|
424
|
-
description: {
|
|
425
|
-
role: "services",
|
|
426
|
-
instanceMode: "multiple",
|
|
427
|
-
kind: "target",
|
|
428
|
-
canTest,
|
|
429
|
-
kinds: [kind]
|
|
430
|
-
},
|
|
431
|
-
formSchema: () => formOf(descriptor),
|
|
432
|
-
initialBody: (name) => ({ name }),
|
|
433
|
-
mintId: () => spec.mintId(),
|
|
434
|
-
configured: () => true,
|
|
435
|
-
validateWrite: ({ body }) => spec.validate?.({
|
|
436
|
-
kind: descriptor.kind,
|
|
437
|
-
config: body
|
|
438
|
-
}),
|
|
439
|
-
test: async ({ id, values }) => {
|
|
440
|
-
if (spec.probe === void 0 || !canTest) return {
|
|
441
|
-
success: false,
|
|
442
|
-
status: "unsupported",
|
|
443
|
-
error: "This kind cannot be tested"
|
|
444
|
-
};
|
|
445
|
-
return probeToTestResult(await spec.probe({
|
|
446
|
-
kind: descriptor.kind,
|
|
447
|
-
config: values,
|
|
448
|
-
targetId: id ?? void 0
|
|
449
|
-
}));
|
|
450
|
-
}
|
|
451
|
-
}).toProvider()
|
|
452
|
-
}];
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
/** The `integration-instances` provider of a notification provider: one kind per target kind. */
|
|
456
|
-
function buildNotificationTargetInstances(records, spec) {
|
|
457
|
-
const parts = notificationTargetParts(records, spec);
|
|
458
|
-
return composeInstanceKinds(parts, {
|
|
459
|
-
role: "services",
|
|
460
|
-
instanceMode: "multiple",
|
|
461
|
-
kind: "target",
|
|
462
|
-
canTest: parts.some((part) => part.kind.canTest === true),
|
|
463
|
-
mintsId: true
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* Every notification target, read as the instances of `notification-output` (D1013 rule 5). A holder
|
|
468
|
-
* that could not answer is NAMED in `unreadable`: a caller that acts on a target's absence (drops a
|
|
469
|
-
* selection, refuses a send) must check it first, because a partial read is not "deleted" (D315, D49).
|
|
470
|
-
*/
|
|
471
|
-
async function listNotificationTargets(api) {
|
|
472
|
-
const { instances, unreadable } = await instancesOfCap(instanceSourceOverApi(api), NOTIFICATION_OUTPUT_CAP);
|
|
473
|
-
return {
|
|
474
|
-
targets: instances.map(({ addonId, kind, instance }) => {
|
|
475
|
-
const owner = instance.formValues["ownerUserId"];
|
|
476
|
-
return {
|
|
477
|
-
id: instance.id,
|
|
478
|
-
name: instance.name,
|
|
479
|
-
kind: kind.id,
|
|
480
|
-
addonId,
|
|
481
|
-
enabled: instance.enabled !== false,
|
|
482
|
-
...typeof owner === "string" && owner.length > 0 ? { ownerUserId: owner } : {}
|
|
483
|
-
};
|
|
484
|
-
}),
|
|
485
|
-
unreadable
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
//#endregion
|
|
489
8
|
//#region ../types/dist/esm/notification/schedule.mjs
|
|
490
9
|
var WEEKDAY_TO_DAY = {
|
|
491
10
|
Sun: 0,
|
|
@@ -6,7 +6,7 @@ const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
|
6
6
|
const require_stream_catalog_cap = require("../../stream-catalog.cap-D3uwePiA.js");
|
|
7
7
|
const require_base_addon = require("../../base-addon-DD5dIfcZ.js");
|
|
8
8
|
const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
|
|
9
|
-
const require_rename_composition_block = require("../../rename-composition-block-
|
|
9
|
+
const require_rename_composition_block = require("../../rename-composition-block-BJsL58Ih.js");
|
|
10
10
|
const require_camstack_error = require("../../camstack-error-DJ-TUAi1.js");
|
|
11
11
|
const require_capability_definition = require("../../capability-definition-HCmTem8c.js");
|
|
12
12
|
const require_zod_secret = require("../../zod-secret-DS7mj1bk.js");
|
|
@@ -15,11 +15,11 @@ const require_device_identifiers = require("../../device-identifiers-BQg9EQi1.js
|
|
|
15
15
|
const require_tag = require("../../tag-BxLazvVb.js");
|
|
16
16
|
const require_device_type = require("../../device-type-CbQsnFdC.js");
|
|
17
17
|
const require_device_kind = require("../../device-kind-CsSiv_YF.js");
|
|
18
|
-
const require_core_blocks_cap = require("../../core-blocks.cap-
|
|
18
|
+
const require_core_blocks_cap = require("../../core-blocks.cap-BMeMCBrx.js");
|
|
19
19
|
const require_addon_settings_cap = require("../../addon-settings.cap-DAiE0Nb0.js");
|
|
20
20
|
require("../../error.cap-DBhgPeWK.js");
|
|
21
21
|
const require_source_info = require("../../source-info-DtWf4k2j.js");
|
|
22
|
-
const require_prefix_walk = require("../../prefix-walk-
|
|
22
|
+
const require_prefix_walk = require("../../prefix-walk-BkMxoXpL.js");
|
|
23
23
|
const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
|
|
24
24
|
const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
|
|
25
25
|
const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as deviceStatusCapability, w as DeviceStatusSchema } from "../../stream-catalog.cap-Bp7SkgIf.mjs";
|
|
2
2
|
import { b as EventCategory$1, g as WELL_KNOWN_TAB_MAP, n as secretTreeFromPaths, o as resolveSecretMarkers, s as transformSecretWrite, t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
|
|
3
3
|
import { B as SECRET_CLEAR, G as isSecretMarkerLike, H as isSecretClear, W as isSecretMarker, X as isKeychainStoredField, Z as errMsg$1, q as toSecretFieldView } from "../../scoped-settings-DVWUIP7Z.mjs";
|
|
4
|
-
import { Jn as ExportNameRefusedError, _n as deviceStateCapability, b as workloadTransition, c as kebabToCamel, fn as PUSH_CONFIRM_WINDOW_MS, g as WorkloadStateSchema, gn as FieldClaimSchema, h as WORKLOAD_TRANSITION_CATEGORY, hn as FieldClaimModeSchema, m as ALL_CAPABILITY_DEFINITIONS, mn as effectiveRefreshIntervalMs, n as renameCompositionBlock, pn as commandBurstOffsets, t as composedBlockIdOf, v as isWorkloadSettled, vn as deviceExtensionCapability, y as workloadCapability, yn as EXTENSION_SLOTS } from "../../rename-composition-block-
|
|
4
|
+
import { Jn as ExportNameRefusedError, _n as deviceStateCapability, b as workloadTransition, c as kebabToCamel, fn as PUSH_CONFIRM_WINDOW_MS, g as WorkloadStateSchema, gn as FieldClaimSchema, h as WORKLOAD_TRANSITION_CATEGORY, hn as FieldClaimModeSchema, m as ALL_CAPABILITY_DEFINITIONS, mn as effectiveRefreshIntervalMs, n as renameCompositionBlock, pn as commandBurstOffsets, t as composedBlockIdOf, v as isWorkloadSettled, vn as deviceExtensionCapability, y as workloadCapability, yn as EXTENSION_SLOTS } from "../../rename-composition-block-OAtErZgq.mjs";
|
|
5
5
|
import { t as userError } from "../../camstack-error-viZYfcj9.mjs";
|
|
6
6
|
import { a as expandCapMethods$1, s as isDeviceConfigCap } from "../../capability-definition-C2rJdVeX.mjs";
|
|
7
7
|
import { t as collectZodSecretPaths$1 } from "../../zod-secret-zY4nM61M.mjs";
|
|
@@ -10,11 +10,11 @@ import { a as isEmptyIdentifiers, c as sameIdentifiers, i as identifierStrength,
|
|
|
10
10
|
import { d as canonicalIconKey, o as normalizeTags } from "../../tag-uZBAq6ox.mjs";
|
|
11
11
|
import { n as DeviceRole, r as DeviceType$1, t as DeviceFeature } from "../../device-type-DgEvK3ch.mjs";
|
|
12
12
|
import { n as capAppliesToDeviceKind } from "../../device-kind-BJ2pfsjw.mjs";
|
|
13
|
-
import { A as CAP_RUNTIME_FIELD_UNITS,
|
|
13
|
+
import { A as CAP_RUNTIME_FIELD_UNITS, Kt as enumerateItemArrayFields, cn as allVocabActions, dn as vocabActionIdFor, pn as CAP_VOCABULARY_BY_NAME, qt as enumerateSchemaFields, sn as actionEffect, un as findVocabAction } from "../../core-blocks.cap-BRPsLAij.mjs";
|
|
14
14
|
import { u as locationIconKey } from "../../addon-settings.cap-3-TIIMq_.mjs";
|
|
15
15
|
import "../../error.cap-CSM_SRfR.mjs";
|
|
16
16
|
import { a as normalizeUnit, r as extractSourceInfoFromMetadata } from "../../source-info-DGB7SdB_.mjs";
|
|
17
|
-
import { r as ConditionMirror, t as loadPrefixed } from "../../prefix-walk-
|
|
17
|
+
import { r as ConditionMirror, t as loadPrefixed } from "../../prefix-walk-ifwg_ukx.mjs";
|
|
18
18
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
19
19
|
import { a as redactLogText, i as redactLogMeta, n as isSecretArgumentKey } from "../../log-redactor-XLDrPzOi.mjs";
|
|
20
20
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Z as errMsg } from "./scoped-settings-DVWUIP7Z.mjs";
|
|
2
|
-
import { k as CAP_CUSTOMIZE_CATALOG } from "./core-blocks.cap-
|
|
2
|
+
import { k as CAP_CUSTOMIZE_CATALOG } from "./core-blocks.cap-BRPsLAij.mjs";
|
|
3
3
|
import { N as compositionSourceKey, c as isIdentifier, d as signedToken, f as unsignedToken, l as linearExpr, o as constantExpr, s as dwellExpr, u as overrideExpr } from "./error.cap-CSM_SRfR.mjs";
|
|
4
4
|
//#region ../types/dist/esm/composition/customize/field-source.mjs
|
|
5
5
|
function fromRead(source, cap, fieldPath) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_scoped_settings = require("./scoped-settings-CylSSq_8.js");
|
|
2
|
-
const require_core_blocks_cap = require("./core-blocks.cap-
|
|
2
|
+
const require_core_blocks_cap = require("./core-blocks.cap-BMeMCBrx.js");
|
|
3
3
|
const require_error_cap = require("./error.cap-DBhgPeWK.js");
|
|
4
4
|
//#region ../types/dist/esm/composition/customize/field-source.mjs
|
|
5
5
|
function fromRead(source, cap, fieldPath) {
|
|
@@ -11707,9 +11707,11 @@ function refineKnownAction(step, ctx) {
|
|
|
11707
11707
|
}
|
|
11708
11708
|
var AutomationCommandStepSchema = /* @__PURE__ */ AutomationCommandStepBaseSchema.superRefine(refineKnownAction);
|
|
11709
11709
|
/**
|
|
11710
|
-
* The steps an
|
|
11711
|
-
*
|
|
11712
|
-
*
|
|
11710
|
+
* The leaf steps of an `else` list: command and wait, with no condition of their
|
|
11711
|
+
* own. (An Action's own list is wider: {@link ActionStepSchema}. It may call
|
|
11712
|
+
* another Action, so the cycle is cut elsewhere — `findActionCycle` refuses the
|
|
11713
|
+
* save that closes one, and a run carries a visited set and a depth bound,
|
|
11714
|
+
* `action-graph.ts`.)
|
|
11713
11715
|
*/
|
|
11714
11716
|
var LeafActionStepSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [AutomationWaitStepSchema, AutomationCommandStepSchema]);
|
|
11715
11717
|
/**
|
|
@@ -11729,11 +11731,13 @@ var elseNeedsIf = {
|
|
|
11729
11731
|
var GuardedWaitStepSchema = /* @__PURE__ */ AutomationWaitStepSchema.extend(stepGuardShape).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
11730
11732
|
var GuardedCommandStepSchema = /* @__PURE__ */ AutomationCommandStepBaseSchema.extend(stepGuardShape).superRefine(refineKnownAction).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
11731
11733
|
/**
|
|
11732
|
-
*
|
|
11733
|
-
*
|
|
11734
|
-
*
|
|
11734
|
+
* The NARROW step of a list that runs a device command or waits, and nothing
|
|
11735
|
+
* else: a scheduler point, a notification rule's action list. Pinned on
|
|
11736
|
+
* purpose — such a list has no run bag, no notification target of its own and
|
|
11737
|
+
* no place to nest a block, so it is not offered the rest of an Action's steps.
|
|
11738
|
+
* It is a subset of {@link ActionStep}: a runner built for the wide step runs it.
|
|
11735
11739
|
*/
|
|
11736
|
-
var
|
|
11740
|
+
var NarrowActionStepSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCommandStepSchema]).superRefine((step, ctx) => {
|
|
11737
11741
|
if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
|
|
11738
11742
|
code: "custom",
|
|
11739
11743
|
message: TRIGGERED_BY_NEEDS_AUTOMATION,
|
|
@@ -11804,6 +11808,8 @@ var AutomationNotifyStepSchema = /* @__PURE__ */ zod.z.object({
|
|
|
11804
11808
|
var HTTP_URL_MAX = 2e3;
|
|
11805
11809
|
var HTTP_BODY_MAX = 16384;
|
|
11806
11810
|
var HTTP_HEADER_VALUE_MAX = 1e3;
|
|
11811
|
+
/** How much of a response body a run keeps, in bytes: the rest is cut. */
|
|
11812
|
+
var HTTP_TEXT_CAP = 65536;
|
|
11807
11813
|
var saveAsSchema = /* @__PURE__ */ zod.z.string().regex(SET_VAR_NAME_RE, "a variable name is letters, digits and _, not starting with a digit (max 40)").refine((name) => !RESERVED_RUN_VARS.includes(name), { message: `the names ${/* @__PURE__ */ RESERVED_RUN_VARS.join(", ")} belong to the run and cannot be used` });
|
|
11808
11814
|
var retryUntilSecondsSchema = /* @__PURE__ */ zod.z.number().int().min(1).max(600, `a retry window is at most 600 s`);
|
|
11809
11815
|
/**
|
|
@@ -12051,6 +12057,13 @@ var AutomationActionSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
|
|
|
12051
12057
|
code: /* @__PURE__ */ zod.z.string().min(1).max(2e4)
|
|
12052
12058
|
})
|
|
12053
12059
|
]);
|
|
12060
|
+
var ActionStepSchema = /* @__PURE__ */ AutomationActionSchema.refine((step) => step.kind !== "code", { message: "an action is interpreted, so it has no code step: a code step is bundled into the block of an automation" }).superRefine((step, ctx) => {
|
|
12061
|
+
for (const condition of stepConditionsOf(step)) if (hasTriggeredByLeaves(condition.when)) ctx.addIssue({
|
|
12062
|
+
code: "custom",
|
|
12063
|
+
message: TRIGGERED_BY_NEEDS_AUTOMATION,
|
|
12064
|
+
path: condition.path.split(".").map((part) => /^\d+$/.test(part) ? Number(part) : part)
|
|
12065
|
+
});
|
|
12066
|
+
});
|
|
12054
12067
|
/**
|
|
12055
12068
|
* How a trigger that arrives while the automation is busy (or cooling down) is
|
|
12056
12069
|
* handled. One of the automation's execution modes, never a property of its
|
|
@@ -12258,7 +12271,7 @@ var HoldOverrideSchema = /* @__PURE__ */ zod.z.discriminatedUnion("mode", [/* @_
|
|
|
12258
12271
|
var DEFAULT_HOLD_OVERRIDE = { mode: "respect" };
|
|
12259
12272
|
/** A missed edge up to this late still runs. */
|
|
12260
12273
|
var DEFAULT_MAX_LATE_MS = 10 * 6e4;
|
|
12261
|
-
var SchedulerStepSchema = /* @__PURE__ */
|
|
12274
|
+
var SchedulerStepSchema = /* @__PURE__ */ NarrowActionStepSchema.refine((step) => step.kind !== "wait" || step.seconds <= 300, {
|
|
12262
12275
|
message: `a scheduler point waits at most five minutes (300 s); put a longer wait in an action`,
|
|
12263
12276
|
path: ["seconds"]
|
|
12264
12277
|
});
|
|
@@ -15054,7 +15067,16 @@ var CAP_CUSTOMIZE_CATALOG = {
|
|
|
15054
15067
|
when: "always"
|
|
15055
15068
|
}]
|
|
15056
15069
|
}
|
|
15057
|
-
]
|
|
15070
|
+
],
|
|
15071
|
+
sourceGroups: [{
|
|
15072
|
+
id: "meter-device",
|
|
15073
|
+
targets: [
|
|
15074
|
+
"power",
|
|
15075
|
+
"energy",
|
|
15076
|
+
"voltage",
|
|
15077
|
+
"current"
|
|
15078
|
+
]
|
|
15079
|
+
}]
|
|
15058
15080
|
},
|
|
15059
15081
|
"power-source": {
|
|
15060
15082
|
version: 1,
|
|
@@ -18127,6 +18149,12 @@ Object.defineProperty(exports, "EventVocabularyEntrySchema", {
|
|
|
18127
18149
|
return EventVocabularyEntrySchema;
|
|
18128
18150
|
}
|
|
18129
18151
|
});
|
|
18152
|
+
Object.defineProperty(exports, "HTTP_TEXT_CAP", {
|
|
18153
|
+
enumerable: true,
|
|
18154
|
+
get: function() {
|
|
18155
|
+
return HTTP_TEXT_CAP;
|
|
18156
|
+
}
|
|
18157
|
+
});
|
|
18130
18158
|
Object.defineProperty(exports, "IrNativeCodeSchema", {
|
|
18131
18159
|
enumerable: true,
|
|
18132
18160
|
get: function() {
|