@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
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { d as optionalLinkField, l as RecordIntegrationInstances, v as isInstanceOn, y as recordInstanceSwitch } from "./base-addon-Md14i7pe.mjs";
|
|
2
|
+
import { d as TargetSchema } from "./notification-rules.cap-DUmiMBQB.mjs";
|
|
3
|
+
import { t as defineEntryKind } from "./entry-kind-D9MuVJCK.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region ../types/dist/esm/addon/compose-instance-kinds.mjs
|
|
6
|
+
/** No part holds the id a call named. */
|
|
7
|
+
var UnknownInstanceError = class extends Error {
|
|
8
|
+
instanceId;
|
|
9
|
+
constructor(instanceId) {
|
|
10
|
+
super(`Unknown instance '${instanceId}'`);
|
|
11
|
+
this.instanceId = instanceId;
|
|
12
|
+
this.name = "UnknownInstanceError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/** A create or a form named no kind, or a kind no part serves. */
|
|
16
|
+
var UnknownInstanceKindError = class extends Error {
|
|
17
|
+
kindId;
|
|
18
|
+
constructor(kindId) {
|
|
19
|
+
super(kindId === void 0 ? "This provider has several kinds: name one" : `Unknown instance kind '${kindId}'`);
|
|
20
|
+
this.kindId = kindId;
|
|
21
|
+
this.name = "UnknownInstanceKindError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function composeInstanceKinds(parts, base) {
|
|
25
|
+
const byKind = (kindId) => {
|
|
26
|
+
if (kindId === void 0) {
|
|
27
|
+
const only = parts.length === 1 ? parts[0] : void 0;
|
|
28
|
+
if (only === void 0) throw new UnknownInstanceKindError(void 0);
|
|
29
|
+
return only;
|
|
30
|
+
}
|
|
31
|
+
const part = parts.find((candidate) => candidate.kind.id === kindId);
|
|
32
|
+
if (part === void 0) throw new UnknownInstanceKindError(kindId);
|
|
33
|
+
return part;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Whether a part's kind offers a Test. A kind that states `canTest` is believed; one that does not
|
|
37
|
+
* takes what its OWN provider declares, never the composed base (a calendar or an integration
|
|
38
|
+
* inherited the account's `canTest: true` and offered a button nothing answered, planning#543).
|
|
39
|
+
*/
|
|
40
|
+
const canTestPart = async (part) => part.kind.canTest ?? (await part.provider.describe()).canTest === true;
|
|
41
|
+
/**
|
|
42
|
+
* The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
|
|
43
|
+
* testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
|
|
44
|
+
*/
|
|
45
|
+
const draftPart = async (kindId) => {
|
|
46
|
+
if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
|
|
47
|
+
const flags = await Promise.all(parts.map(canTestPart));
|
|
48
|
+
const testable = parts.filter((_part, index) => flags[index] === true);
|
|
49
|
+
const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
|
|
50
|
+
if (only !== void 0) return only;
|
|
51
|
+
return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
|
|
52
|
+
};
|
|
53
|
+
const holderOf = async (id) => {
|
|
54
|
+
for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
|
|
55
|
+
throw new UnknownInstanceError(id);
|
|
56
|
+
};
|
|
57
|
+
const tagged = (part, instance) => ({
|
|
58
|
+
...instance,
|
|
59
|
+
kind: part.kind.id
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
describe: async () => {
|
|
63
|
+
const links = (await Promise.all(parts.map(async (part) => (await part.provider.describe()).links ?? []))).flat();
|
|
64
|
+
return {
|
|
65
|
+
...base,
|
|
66
|
+
kinds: await Promise.all(parts.map(async (part) => ({
|
|
67
|
+
...part.kind,
|
|
68
|
+
canTest: await canTestPart(part)
|
|
69
|
+
}))),
|
|
70
|
+
...links.length > 0 ? { links } : {}
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
instanceFormSchema: async ({ id, kind }) => {
|
|
74
|
+
return (id === null ? byKind(kind) : await holderOf(id)).provider.instanceFormSchema({ id });
|
|
75
|
+
},
|
|
76
|
+
listInstances: async (input) => {
|
|
77
|
+
return (await Promise.all(parts.map(async (part) => (await part.provider.listInstances(input)).map((instance) => tagged(part, instance))))).flat();
|
|
78
|
+
},
|
|
79
|
+
getInstance: async ({ id }) => {
|
|
80
|
+
for (const part of parts) {
|
|
81
|
+
const found = await part.provider.getInstance({ id });
|
|
82
|
+
if (found !== null) return tagged(part, found);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
},
|
|
86
|
+
createInstance: async (input) => byKind(input.kind).provider.createInstance(input),
|
|
87
|
+
updateInstance: async (input) => (await holderOf(input.id)).provider.updateInstance(input),
|
|
88
|
+
setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
|
|
89
|
+
deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
|
|
90
|
+
testInstance: async (input) => {
|
|
91
|
+
const resolved = input.id === null ? await draftPart(input.kind) : await holderOf(input.id);
|
|
92
|
+
if ("error" in resolved) return {
|
|
93
|
+
success: false,
|
|
94
|
+
status: "inconclusive",
|
|
95
|
+
error: resolved.error
|
|
96
|
+
};
|
|
97
|
+
const test = resolved.provider.testInstance;
|
|
98
|
+
if (test === void 0) return {
|
|
99
|
+
success: false,
|
|
100
|
+
status: "inconclusive",
|
|
101
|
+
error: "This kind cannot be tested"
|
|
102
|
+
};
|
|
103
|
+
return test(input);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region ../types/dist/esm/addon/instances-of-cap.mjs
|
|
109
|
+
/**
|
|
110
|
+
* The kind's instances answer for `cap`: it is the kind's `functionCap`, or one the kind declares in
|
|
111
|
+
* `alsoServes`. The one rule a link (a picker, a resolver, a delete guard) matches a target by.
|
|
112
|
+
*/
|
|
113
|
+
function kindServesCap(kind, cap) {
|
|
114
|
+
return kind.functionCap === cap || (kind.alsoServes ?? []).includes(cap);
|
|
115
|
+
}
|
|
116
|
+
async function instancesOfCap(source, cap, filter = {}) {
|
|
117
|
+
const instances = [];
|
|
118
|
+
const unreadable = [];
|
|
119
|
+
for (const addonId of await source.holders(cap)) try {
|
|
120
|
+
const kinds = ((await source.describe(addonId)).kinds ?? []).filter((kind) => kindServesCap(kind, cap));
|
|
121
|
+
if (kinds.length === 0) continue;
|
|
122
|
+
for (const instance of await source.listInstances(addonId)) {
|
|
123
|
+
const kind = kinds.find((candidate) => candidate.id === instance.kind);
|
|
124
|
+
if (kind === void 0) continue;
|
|
125
|
+
if (filter.kind !== void 0 && (kind.brokerKind ?? kind.id) !== filter.kind) continue;
|
|
126
|
+
instances.push({
|
|
127
|
+
addonId,
|
|
128
|
+
kind,
|
|
129
|
+
instance
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
} catch (err) {
|
|
133
|
+
unreadable.push({
|
|
134
|
+
addonId,
|
|
135
|
+
error: err instanceof Error ? err.message : String(err)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
instances,
|
|
140
|
+
unreadable
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async function providersOf(api, name) {
|
|
144
|
+
const info = await api.capabilities.getCapability.query({ name });
|
|
145
|
+
if (info === null) throw new Error(`the capability registry did not answer for ${name}`);
|
|
146
|
+
return info.providers;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The source over `ctx.api`. Every provider of the cap is a holder, not only those that also serve
|
|
150
|
+
* `integration-instances`: a provider that does not (an addon older than the hub during an update)
|
|
151
|
+
* then fails `describe` and is reported unreadable, so its instances are retried as transient
|
|
152
|
+
* instead of vanishing from the catalogue and failing for good.
|
|
153
|
+
*/
|
|
154
|
+
function instanceSourceOverApi(api) {
|
|
155
|
+
return {
|
|
156
|
+
holders: (cap) => providersOf(api, cap),
|
|
157
|
+
describe: (addonId) => api.integrationInstances.describe.query({ addonId }),
|
|
158
|
+
listInstances: (addonId) => api.integrationInstances.listInstances.query({ addonId })
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region ../types/dist/esm/addon/notification-targets.mjs
|
|
163
|
+
/**
|
|
164
|
+
* Notification targets as instances of the function cap `notification-output` (epic #440, step 6).
|
|
165
|
+
*
|
|
166
|
+
* A notification target used to be one row of one record kind (`{ name, kind, addonId, enabled,
|
|
167
|
+
* config }`) with a free-form `config` blob whose secrets nobody could name. Now every target KIND
|
|
168
|
+
* the provider offers (ntfy, telegram, webhook, ...) is a record kind of its own whose flat body IS
|
|
169
|
+
* that kind's form: the adapter's `configSchema` lifted into a Zod object, a `password` field marked
|
|
170
|
+
* `.meta({ secret: true })` so the records door keeps it in the keychain, an `instance-select` field
|
|
171
|
+
* declared as a link so the hub refuses to delete what a target points at.
|
|
172
|
+
*
|
|
173
|
+
* Three providers (notifiers, Home Assistant, Alexa) serve the same shape, so the pieces are shared:
|
|
174
|
+
* - {@link defineNotificationTargetKind}: the record kind of one `TargetKind` descriptor;
|
|
175
|
+
* - {@link NotificationTargetStore}: the `Target`-shaped facade the provider's own code keeps
|
|
176
|
+
* using (send, the notification-center bridge), over one handle per kind;
|
|
177
|
+
* - {@link listNotificationTargets}: the targets as an addon on `ctx.api` reads them;
|
|
178
|
+
* - {@link buildNotificationTargetInstances}: the `integration-instances` provider, one kind each;
|
|
179
|
+
* - {@link moveTargetRows}: the D987 procedure that flattens the old `config` blobs into the bodies.
|
|
180
|
+
*/
|
|
181
|
+
/** The function cap every notification target is an instance of. */
|
|
182
|
+
var NOTIFICATION_OUTPUT_CAP = "notification-output";
|
|
183
|
+
/** The most targets one provider lists (a settings page, not a table). */
|
|
184
|
+
var TARGETS_LIST_MAX = 1e3;
|
|
185
|
+
/** The record kind name of one target kind: `telegram` is stored under `notify-telegram`. */
|
|
186
|
+
function notificationTargetKindName(kind) {
|
|
187
|
+
return `notify-${kind}`;
|
|
188
|
+
}
|
|
189
|
+
/** The body schema of a target kind: the entry's name and switch plus the adapter's fields. */
|
|
190
|
+
var TargetBodyBaseSchema = /* @__PURE__ */ z.looseObject({
|
|
191
|
+
name: /* @__PURE__ */ z.string().min(1),
|
|
192
|
+
enabled: /* @__PURE__ */ z.boolean().optional()
|
|
193
|
+
});
|
|
194
|
+
/** The shape of one `editable-array` row: the item fields, a `password` one a secret. */
|
|
195
|
+
function rowSchemaOf(itemFields) {
|
|
196
|
+
const shape = {};
|
|
197
|
+
let idKey = null;
|
|
198
|
+
let hasSecret = false;
|
|
199
|
+
for (const item of itemFields) {
|
|
200
|
+
if (item.type === "password") {
|
|
201
|
+
shape[item.key] = z.string().optional().meta({ secret: true });
|
|
202
|
+
hasSecret = true;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
shape[item.key] = z.unknown().optional();
|
|
206
|
+
idKey ??= item.key;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
row: z.looseObject(shape),
|
|
210
|
+
idKey,
|
|
211
|
+
hasSecret
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The Zod fields of a descriptor's form. A `password` field is a secret; an `instance-select` field is
|
|
216
|
+
* a link to an instance of its function cap; an `editable-array` keeps its rows (a password inside a
|
|
217
|
+
* row is a secret matched by the row's first plain field); every other field keeps whatever the
|
|
218
|
+
* adapter's own parse accepts, because the form already validated its shape. The body is loose, so a key
|
|
219
|
+
* the schema does not know (the owner of a personal target) survives a write.
|
|
220
|
+
*/
|
|
221
|
+
function fieldsOf(descriptor) {
|
|
222
|
+
const shape = {};
|
|
223
|
+
const secretArrayKeys = {};
|
|
224
|
+
for (const section of descriptor.configSchema.sections) for (const field of section.fields) switch (field.type) {
|
|
225
|
+
case "info": break;
|
|
226
|
+
case "password":
|
|
227
|
+
shape[field.key] = z.string().optional().meta({ secret: true });
|
|
228
|
+
break;
|
|
229
|
+
case "instance-select":
|
|
230
|
+
shape[field.key] = optionalLinkField({
|
|
231
|
+
cap: field.functionCap,
|
|
232
|
+
...field.kind !== void 0 ? { kind: field.kind } : {}
|
|
233
|
+
});
|
|
234
|
+
break;
|
|
235
|
+
case "editable-array": {
|
|
236
|
+
const { row, idKey, hasSecret } = rowSchemaOf(field.itemFields);
|
|
237
|
+
shape[field.key] = z.array(row).optional();
|
|
238
|
+
if (hasSecret && idKey !== null) secretArrayKeys[field.key] = idKey;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
default: shape[field.key] = z.unknown().optional();
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
shape,
|
|
245
|
+
secretArrayKeys
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** The record kind of one target kind, derived from its descriptor. */
|
|
249
|
+
function defineNotificationTargetKind(descriptor) {
|
|
250
|
+
const { shape, secretArrayKeys } = fieldsOf(descriptor);
|
|
251
|
+
return defineEntryKind(notificationTargetKindName(descriptor.kind), {
|
|
252
|
+
title: `${descriptor.label} notification targets`,
|
|
253
|
+
schema: TargetBodyBaseSchema.extend(shape),
|
|
254
|
+
writeTrigger: `an operator adds, edits, switches or removes a ${descriptor.label} notification target`,
|
|
255
|
+
...Object.keys(secretArrayKeys).length > 0 ? { secretArrayKeys } : {}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/** The record kinds of a provider's descriptors, keyed by the record kind name (for `records.declare`). */
|
|
259
|
+
function notificationTargetKinds(descriptors) {
|
|
260
|
+
return Object.fromEntries(descriptors.map((descriptor) => {
|
|
261
|
+
const defined = defineNotificationTargetKind(descriptor);
|
|
262
|
+
return [defined.name, defined];
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
/** The body a stored target becomes: the switch and the name, and the config fields flat beside them. */
|
|
266
|
+
function targetBody(target) {
|
|
267
|
+
return {
|
|
268
|
+
...target.config,
|
|
269
|
+
name: target.name.length > 0 ? target.name : target.id,
|
|
270
|
+
enabled: target.enabled
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/** The `Target` a record of a kind is; null when the row is not a target. */
|
|
274
|
+
function targetOfRecord(addonId, kind, id, data) {
|
|
275
|
+
const { name, enabled: _enabled, ...config } = data;
|
|
276
|
+
const parsed = TargetSchema.safeParse({
|
|
277
|
+
id,
|
|
278
|
+
name,
|
|
279
|
+
kind,
|
|
280
|
+
addonId,
|
|
281
|
+
enabled: isInstanceOn(id),
|
|
282
|
+
config
|
|
283
|
+
});
|
|
284
|
+
return parsed.success ? parsed.data : null;
|
|
285
|
+
}
|
|
286
|
+
function targetOfOld(addonId, row) {
|
|
287
|
+
return {
|
|
288
|
+
id: row.id,
|
|
289
|
+
name: row.name,
|
|
290
|
+
kind: row.kind,
|
|
291
|
+
addonId,
|
|
292
|
+
enabled: row.enabled,
|
|
293
|
+
config: { ...row.config }
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The `Target`-shaped facade over one record kind per target kind. `list` returns the stored form (a
|
|
298
|
+
* secret is a keychain marker: every reader redacts it anyway); `getById` returns the target with its
|
|
299
|
+
* secrets resolved, which is what a send, a probe and an edit's secret merge need. A keychain that
|
|
300
|
+
* cannot answer throws: a write never goes ahead with a secret it could not read (D49).
|
|
301
|
+
*/
|
|
302
|
+
var NotificationTargetStore = class NotificationTargetStore {
|
|
303
|
+
addonId;
|
|
304
|
+
handles;
|
|
305
|
+
options;
|
|
306
|
+
constructor(addonId, handles, options) {
|
|
307
|
+
this.addonId = addonId;
|
|
308
|
+
this.handles = handles;
|
|
309
|
+
this.options = options;
|
|
310
|
+
}
|
|
311
|
+
static of(records, addonId, kinds, descriptors, options = {}) {
|
|
312
|
+
const handles = [];
|
|
313
|
+
for (const descriptor of descriptors) {
|
|
314
|
+
const defined = kinds[notificationTargetKindName(descriptor.kind)];
|
|
315
|
+
if (defined === void 0) continue;
|
|
316
|
+
handles.push({
|
|
317
|
+
kind: descriptor.kind,
|
|
318
|
+
handle: records.kind(defined)
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return new NotificationTargetStore(addonId, handles, options);
|
|
322
|
+
}
|
|
323
|
+
/** The record handle of each kind, for the migration ports. */
|
|
324
|
+
handlesByKind() {
|
|
325
|
+
return new Map(this.handles.map((entry) => [entry.kind, entry.handle]));
|
|
326
|
+
}
|
|
327
|
+
async list() {
|
|
328
|
+
const out = [];
|
|
329
|
+
for (const { kind, handle } of this.handles) {
|
|
330
|
+
const page = await handle.query({ limit: TARGETS_LIST_MAX });
|
|
331
|
+
for (const record of page.records) {
|
|
332
|
+
const target = targetOfRecord(this.addonId, kind, record.id, record.data);
|
|
333
|
+
if (target !== null) {
|
|
334
|
+
out.push(target);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
this.options.logger?.warn("notification target record is not a valid target; left out of the list", { meta: {
|
|
338
|
+
targetId: record.id,
|
|
339
|
+
kind
|
|
340
|
+
} });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const held = new Set(out.map((target) => target.id));
|
|
344
|
+
for (const row of await this.legacyRows()) if (!held.has(row.id)) out.push(targetOfOld(this.addonId, row));
|
|
345
|
+
return out;
|
|
346
|
+
}
|
|
347
|
+
/** The legacy rows of a kind this provider serves (the others are not ours to show). */
|
|
348
|
+
async legacyRows() {
|
|
349
|
+
const legacy = this.options.legacy;
|
|
350
|
+
if (legacy === void 0) return [];
|
|
351
|
+
const served = new Set(this.handles.map((entry) => entry.kind));
|
|
352
|
+
return (await legacy.list()).filter((row) => served.has(row.kind));
|
|
353
|
+
}
|
|
354
|
+
async getById(id) {
|
|
355
|
+
for (const { kind, handle } of this.handles) {
|
|
356
|
+
const row = await handle.getResolved(id);
|
|
357
|
+
if (row !== null) return targetOfRecord(this.addonId, kind, row.id, row.data);
|
|
358
|
+
}
|
|
359
|
+
const old = (await this.legacyRows()).find((row) => row.id === id);
|
|
360
|
+
return old === void 0 ? null : targetOfOld(this.addonId, old);
|
|
361
|
+
}
|
|
362
|
+
/** Insert or replace by id; a target whose kind changed leaves the record of its old kind. */
|
|
363
|
+
async upsert(target) {
|
|
364
|
+
const own = this.handles.find((entry) => entry.kind === target.kind);
|
|
365
|
+
if (own === void 0) throw new Error(`invalid target '${target.id}': unknown kind '${target.kind}'`);
|
|
366
|
+
const { enabled: _switch, ...data } = targetBody(target);
|
|
367
|
+
await own.handle.put({
|
|
368
|
+
id: target.id,
|
|
369
|
+
data
|
|
370
|
+
});
|
|
371
|
+
recordInstanceSwitch(target.id, target.enabled);
|
|
372
|
+
for (const other of this.handles) if (other !== own) await other.handle.delete(target.id);
|
|
373
|
+
await this.options.legacy?.delete(target.id);
|
|
374
|
+
}
|
|
375
|
+
async delete(id) {
|
|
376
|
+
for (const { handle } of this.handles) await handle.delete(id);
|
|
377
|
+
await this.options.legacy?.delete(id);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* A probe's answer as the tri-state of `testInstance`: `ok` validated; a refusal that carries an HTTP
|
|
382
|
+
* status is the remote saying no (`rejected`); a failure with no answer at all (the network, a missing
|
|
383
|
+
* field) proves nothing about the credentials (`inconclusive`).
|
|
384
|
+
*/
|
|
385
|
+
function probeToTestResult(probed) {
|
|
386
|
+
if (probed.ok) return {
|
|
387
|
+
success: true,
|
|
388
|
+
status: "validated",
|
|
389
|
+
...probed.stateInstance !== void 0 ? { detail: probed.stateInstance } : {}
|
|
390
|
+
};
|
|
391
|
+
const error = probed.error ?? "the probe failed";
|
|
392
|
+
return {
|
|
393
|
+
success: false,
|
|
394
|
+
status: probed.httpStatus !== void 0 ? "rejected" : "inconclusive",
|
|
395
|
+
error
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/** The form of a kind: the adapter's own sections. */
|
|
399
|
+
function formOf(descriptor) {
|
|
400
|
+
return descriptor.configSchema;
|
|
401
|
+
}
|
|
402
|
+
/** The instance kinds of a notification provider, one per target kind: a part a composition can take. */
|
|
403
|
+
function notificationTargetParts(records, spec) {
|
|
404
|
+
return spec.descriptors.flatMap((descriptor) => {
|
|
405
|
+
const defined = spec.kinds[notificationTargetKindName(descriptor.kind)];
|
|
406
|
+
if (defined === void 0) return [];
|
|
407
|
+
const canTest = spec.probe !== void 0 && spec.canProbe(descriptor.kind);
|
|
408
|
+
const kind = {
|
|
409
|
+
id: descriptor.kind,
|
|
410
|
+
label: descriptor.label,
|
|
411
|
+
functionCap: NOTIFICATION_OUTPUT_CAP,
|
|
412
|
+
role: "services",
|
|
413
|
+
canTest,
|
|
414
|
+
...spec.widgets?.(descriptor.kind) !== void 0 ? { widgets: spec.widgets(descriptor.kind) } : {},
|
|
415
|
+
...descriptor.iconUrl !== void 0 ? { iconUrl: descriptor.iconUrl } : {},
|
|
416
|
+
...descriptor.iconMediaType !== void 0 ? { iconMediaType: descriptor.iconMediaType } : {}
|
|
417
|
+
};
|
|
418
|
+
return [{
|
|
419
|
+
kind,
|
|
420
|
+
provider: new RecordIntegrationInstances(records, defined, {
|
|
421
|
+
description: {
|
|
422
|
+
role: "services",
|
|
423
|
+
instanceMode: "multiple",
|
|
424
|
+
kind: "target",
|
|
425
|
+
canTest,
|
|
426
|
+
kinds: [kind]
|
|
427
|
+
},
|
|
428
|
+
formSchema: () => formOf(descriptor),
|
|
429
|
+
initialBody: (name) => ({ name }),
|
|
430
|
+
mintId: () => spec.mintId(),
|
|
431
|
+
configured: () => true,
|
|
432
|
+
validateWrite: ({ body }) => spec.validate?.({
|
|
433
|
+
kind: descriptor.kind,
|
|
434
|
+
config: body
|
|
435
|
+
}),
|
|
436
|
+
test: async ({ id, values }) => {
|
|
437
|
+
if (spec.probe === void 0 || !canTest) return {
|
|
438
|
+
success: false,
|
|
439
|
+
status: "unsupported",
|
|
440
|
+
error: "This kind cannot be tested"
|
|
441
|
+
};
|
|
442
|
+
return probeToTestResult(await spec.probe({
|
|
443
|
+
kind: descriptor.kind,
|
|
444
|
+
config: values,
|
|
445
|
+
targetId: id ?? void 0
|
|
446
|
+
}));
|
|
447
|
+
}
|
|
448
|
+
}).toProvider()
|
|
449
|
+
}];
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
/** The `integration-instances` provider of a notification provider: one kind per target kind. */
|
|
453
|
+
function buildNotificationTargetInstances(records, spec) {
|
|
454
|
+
const parts = notificationTargetParts(records, spec);
|
|
455
|
+
return composeInstanceKinds(parts, {
|
|
456
|
+
role: "services",
|
|
457
|
+
instanceMode: "multiple",
|
|
458
|
+
kind: "target",
|
|
459
|
+
canTest: parts.some((part) => part.kind.canTest === true),
|
|
460
|
+
mintsId: true
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Every notification target, read as the instances of `notification-output` (D1013 rule 5). A holder
|
|
465
|
+
* that could not answer is NAMED in `unreadable`: a caller that acts on a target's absence (drops a
|
|
466
|
+
* selection, refuses a send) must check it first, because a partial read is not "deleted" (D315, D49).
|
|
467
|
+
*/
|
|
468
|
+
async function listNotificationTargets(api) {
|
|
469
|
+
const { instances, unreadable } = await instancesOfCap(instanceSourceOverApi(api), NOTIFICATION_OUTPUT_CAP);
|
|
470
|
+
return {
|
|
471
|
+
targets: instances.map(({ addonId, kind, instance }) => {
|
|
472
|
+
const owner = instance.formValues["ownerUserId"];
|
|
473
|
+
return {
|
|
474
|
+
id: instance.id,
|
|
475
|
+
name: instance.name,
|
|
476
|
+
kind: kind.id,
|
|
477
|
+
addonId,
|
|
478
|
+
enabled: instance.enabled !== false,
|
|
479
|
+
...typeof owner === "string" && owner.length > 0 ? { ownerUserId: owner } : {}
|
|
480
|
+
};
|
|
481
|
+
}),
|
|
482
|
+
unreadable
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
486
|
+
export { notificationTargetKinds as i, buildNotificationTargetInstances as n, listNotificationTargets as r, NotificationTargetStore as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_core_blocks_cap = require("./core-blocks.cap-
|
|
1
|
+
const require_core_blocks_cap = require("./core-blocks.cap-BMeMCBrx.js");
|
|
2
2
|
const require_error_cap = require("./error.cap-DBhgPeWK.js");
|
|
3
3
|
const require_prefix_range = require("./prefix-range-D_KueXbQ.js");
|
|
4
4
|
//#region ../types/dist/esm/time/time-window.mjs
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as eventLeafIdAt, Bt as anySubjectMatches, Ft as describeHoldMs, Lt as describeWantedFaults, Nt as isEventLeaf, Pt as compareValues, Qt as occurrenceOn, Rt as faultMatches, Ut as isQuantityValue, Xt as localDateOf, Yt as isKnownTimeZone, en as weekdayOfLocalDate, jt as forEachLeaf, zt as readFault } from "./core-blocks.cap-BRPsLAij.mjs";
|
|
2
2
|
import { lt as toExpressionValue, st as evaluateExpressionSource } from "./error.cap-CSM_SRfR.mjs";
|
|
3
3
|
import { t as prefixRange } from "./prefix-range-Dl0znowN.mjs";
|
|
4
4
|
//#region ../types/dist/esm/time/time-window.mjs
|
package/system/dist/{rename-composition-block-CcWLwVhG.js → rename-composition-block-BJsL58Ih.js}
RENAMED
|
@@ -3,7 +3,7 @@ const require_stream_catalog_cap = require("./stream-catalog.cap-D3uwePiA.js");
|
|
|
3
3
|
const require_base_addon = require("./base-addon-DD5dIfcZ.js");
|
|
4
4
|
const require_scoped_settings = require("./scoped-settings-CylSSq_8.js");
|
|
5
5
|
const require_capability_definition = require("./capability-definition-HCmTem8c.js");
|
|
6
|
-
const require_notification_rules_cap = require("./notification-rules.cap-
|
|
6
|
+
const require_notification_rules_cap = require("./notification-rules.cap-BDh0LDhV.js");
|
|
7
7
|
const require_device_manager_cap = require("./device-manager.cap-2abwVLCM.js");
|
|
8
8
|
const require_device_identifiers = require("./device-identifiers-BQg9EQi1.js");
|
|
9
9
|
const require_device_transitions_cap = require("./device-transitions.cap-B5w5PYU_.js");
|
|
@@ -19,7 +19,7 @@ const require_platform_probe_cap = require("./platform-probe.cap-1WrMhWHx.js");
|
|
|
19
19
|
const require_user_management_cap = require("./user-management.cap-B9QDu8NE.js");
|
|
20
20
|
const require_device_type = require("./device-type-CbQsnFdC.js");
|
|
21
21
|
const require_device_certificate = require("./device-certificate-CguVACQO.js");
|
|
22
|
-
const require_core_blocks_cap = require("./core-blocks.cap-
|
|
22
|
+
const require_core_blocks_cap = require("./core-blocks.cap-BMeMCBrx.js");
|
|
23
23
|
const require_addon_settings_cap = require("./addon-settings.cap-DAiE0Nb0.js");
|
|
24
24
|
const require_error_cap = require("./error.cap-DBhgPeWK.js");
|
|
25
25
|
const require_source_info = require("./source-info-DtWf4k2j.js");
|
|
@@ -1520,19 +1520,84 @@ function normalizeCommandStepUnits(step, resolver, path) {
|
|
|
1520
1520
|
warnings
|
|
1521
1521
|
};
|
|
1522
1522
|
}
|
|
1523
|
+
/** One step's own units, then every step nested under it (a block's body, a branch, an `else`). */
|
|
1524
|
+
function normalizeStepUnits(action, resolver, path) {
|
|
1525
|
+
const nested = (steps, at) => normalizeActionUnits(steps ?? [], resolver, at);
|
|
1526
|
+
switch (action.kind) {
|
|
1527
|
+
case "command": {
|
|
1528
|
+
const own = normalizeCommandStepUnits(action, resolver, path);
|
|
1529
|
+
if (!("else" in action) || action.else === void 0) return own;
|
|
1530
|
+
const inner = nested(action.else, `${path}.else`);
|
|
1531
|
+
const { argUnits: _stale, ...kept } = action;
|
|
1532
|
+
return {
|
|
1533
|
+
value: {
|
|
1534
|
+
...kept,
|
|
1535
|
+
...own.value,
|
|
1536
|
+
else: inner.value
|
|
1537
|
+
},
|
|
1538
|
+
warnings: [...own.warnings, ...inner.warnings]
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
case "wait": {
|
|
1542
|
+
if (!("else" in action) || action.else === void 0) return {
|
|
1543
|
+
value: action,
|
|
1544
|
+
warnings: []
|
|
1545
|
+
};
|
|
1546
|
+
const inner = nested(action.else, `${path}.else`);
|
|
1547
|
+
return {
|
|
1548
|
+
value: {
|
|
1549
|
+
...action,
|
|
1550
|
+
else: inner.value
|
|
1551
|
+
},
|
|
1552
|
+
warnings: inner.warnings
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
case "parallel":
|
|
1556
|
+
case "repeat": {
|
|
1557
|
+
const inner = nested(action.steps, `${path}.steps`);
|
|
1558
|
+
return {
|
|
1559
|
+
value: {
|
|
1560
|
+
...action,
|
|
1561
|
+
steps: inner.value
|
|
1562
|
+
},
|
|
1563
|
+
warnings: inner.warnings
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
case "choose": {
|
|
1567
|
+
const branches = action.branches.map((branch, i) => ({
|
|
1568
|
+
branch,
|
|
1569
|
+
inner: nested(branch.steps, `${path}.branches.${i}.steps`)
|
|
1570
|
+
}));
|
|
1571
|
+
const other = action.else === void 0 ? void 0 : nested(action.else, `${path}.else`);
|
|
1572
|
+
return {
|
|
1573
|
+
value: {
|
|
1574
|
+
...action,
|
|
1575
|
+
branches: branches.map(({ branch, inner }) => ({
|
|
1576
|
+
...branch,
|
|
1577
|
+
steps: inner.value
|
|
1578
|
+
})),
|
|
1579
|
+
...other === void 0 ? {} : { else: other.value }
|
|
1580
|
+
},
|
|
1581
|
+
warnings: [...branches.flatMap(({ inner }) => inner.warnings), ...other?.warnings ?? []]
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
default: return {
|
|
1585
|
+
value: action,
|
|
1586
|
+
warnings: []
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1523
1590
|
/**
|
|
1524
1591
|
* Normalise the command steps of an action list (an internal Action's steps, or a
|
|
1525
|
-
* recipe's actions)
|
|
1592
|
+
* recipe's actions), at any depth: a `choose` branch, a `parallel` or `repeat` body and
|
|
1593
|
+
* an `else` are walked like the top level. Other step kinds pass through. Throws
|
|
1594
|
+
* {@link QuantityUnitError}.
|
|
1526
1595
|
*/
|
|
1527
1596
|
function normalizeActionUnits(actions, resolver, path = "steps") {
|
|
1528
1597
|
const out = [];
|
|
1529
1598
|
const warnings = [];
|
|
1530
1599
|
actions.forEach((action, i) => {
|
|
1531
|
-
|
|
1532
|
-
out.push(action);
|
|
1533
|
-
return;
|
|
1534
|
-
}
|
|
1535
|
-
const normalized = normalizeCommandStepUnits(action, resolver, `${path}.${i}`);
|
|
1600
|
+
const normalized = normalizeStepUnits(action, resolver, `${path}.${i}`);
|
|
1536
1601
|
out.push(normalized.value);
|
|
1537
1602
|
warnings.push(...normalized.warnings);
|
|
1538
1603
|
});
|
|
@@ -1941,15 +2006,47 @@ var actionSourceCapability = {
|
|
|
1941
2006
|
var ACTION_RUN_MAX_MS = 60 * 6e4;
|
|
1942
2007
|
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
1943
2008
|
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
2009
|
+
function listMs(steps) {
|
|
2010
|
+
return steps.reduce((total, step) => total + stepMs(step), 0);
|
|
2011
|
+
}
|
|
2012
|
+
/** How long a repeat's iterations run at most: the bound the schema already forces on every loop form. */
|
|
2013
|
+
function repeatMs(step) {
|
|
2014
|
+
const body = listMs(step.steps);
|
|
2015
|
+
switch (step.loop.by) {
|
|
2016
|
+
case "count": return step.loop.count * body;
|
|
2017
|
+
case "forEach": return step.loop.target.ids.length * body;
|
|
2018
|
+
case "while":
|
|
2019
|
+
case "until": return step.loop.maxIterations * (body + (step.loop.waitS ?? 0) * 1e3);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
/** The longest one step holds the run, in ms: its own wait, or what it nests. Device commands take extra, never less. */
|
|
2023
|
+
function stepMs(step) {
|
|
2024
|
+
switch (step.kind) {
|
|
2025
|
+
case "wait": {
|
|
2026
|
+
const own = step.seconds * 1e3;
|
|
2027
|
+
return "else" in step && step.else !== void 0 ? Math.max(own, listMs(step.else)) : own;
|
|
2028
|
+
}
|
|
2029
|
+
case "wait-until": return step.timeoutS * 1e3;
|
|
2030
|
+
case "probe":
|
|
2031
|
+
case "http-request": return (step.retryUntilSeconds ?? 0) * 1e3;
|
|
2032
|
+
case "repeat": return repeatMs(step);
|
|
2033
|
+
case "parallel": return Math.max(0, ...step.steps.map(stepMs));
|
|
2034
|
+
case "choose": return Math.max(0, ...step.branches.map((branch) => listMs(branch.steps)), listMs(step.else ?? []));
|
|
2035
|
+
case "command": return "else" in step && step.else !== void 0 ? listMs(step.else) : 0;
|
|
2036
|
+
case "action":
|
|
2037
|
+
case "notify":
|
|
2038
|
+
case "set":
|
|
2039
|
+
case "stop": return 0;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
1944
2042
|
/**
|
|
1945
|
-
* The time an action's
|
|
1946
|
-
*
|
|
1947
|
-
*
|
|
2043
|
+
* The most time an action's steps hold the run for by waiting alone, in ms: a
|
|
2044
|
+
* wait, a wait-until up to its timeout, a retry window, a repeat (its bound
|
|
2045
|
+
* times its body), the longest of a parallel's members and of a choose's
|
|
2046
|
+
* branches. Device commands take extra, never less.
|
|
1948
2047
|
*/
|
|
1949
2048
|
function actionWaitTotalMs(steps) {
|
|
1950
|
-
|
|
1951
|
-
for (const step of steps) if (step.kind === "wait") total += step.seconds * 1e3;
|
|
1952
|
-
return total;
|
|
2049
|
+
return listMs(steps);
|
|
1953
2050
|
}
|
|
1954
2051
|
//#endregion
|
|
1955
2052
|
//#region ../types/dist/esm/capabilities/actions.cap.mjs
|
|
@@ -21990,7 +22087,16 @@ var powerMeterCapability = {
|
|
|
21990
22087
|
/* @__PURE__ */ powerTarget("energy", "kWh"),
|
|
21991
22088
|
/* @__PURE__ */ powerTarget("voltage", "V"),
|
|
21992
22089
|
/* @__PURE__ */ powerTarget("current", "A")
|
|
21993
|
-
]
|
|
22090
|
+
],
|
|
22091
|
+
sourceGroups: [{
|
|
22092
|
+
id: "meter-device",
|
|
22093
|
+
targets: [
|
|
22094
|
+
"power",
|
|
22095
|
+
"energy",
|
|
22096
|
+
"voltage",
|
|
22097
|
+
"current"
|
|
22098
|
+
]
|
|
22099
|
+
}]
|
|
21994
22100
|
},
|
|
21995
22101
|
vocabulary: {
|
|
21996
22102
|
noun: /* @__PURE__ */ require_l10n.t("Power meter", "Misuratore di energia"),
|