@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
|
@@ -5,492 +5,11 @@ Object.defineProperties(exports, {
|
|
|
5
5
|
require("../../chunk-Cek0wNdY.js");
|
|
6
6
|
const require_base_addon = require("../../base-addon-DD5dIfcZ.js");
|
|
7
7
|
const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const require_notification_targets = require("../../notification-targets-CRH-9Dy5.js");
|
|
9
|
+
const require_notification_rules_cap = require("../../notification-rules.cap-BDh0LDhV.js");
|
|
10
10
|
const require_integration_instances_cap = require("../../integration-instances.cap-dJIxg2_s.js");
|
|
11
11
|
let zod = require("zod");
|
|
12
12
|
let node_crypto = require("node:crypto");
|
|
13
|
-
//#region ../types/dist/esm/addon/compose-instance-kinds.mjs
|
|
14
|
-
/** No part holds the id a call named. */
|
|
15
|
-
var UnknownInstanceError = class extends Error {
|
|
16
|
-
instanceId;
|
|
17
|
-
constructor(instanceId) {
|
|
18
|
-
super(`Unknown instance '${instanceId}'`);
|
|
19
|
-
this.instanceId = instanceId;
|
|
20
|
-
this.name = "UnknownInstanceError";
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
/** A create or a form named no kind, or a kind no part serves. */
|
|
24
|
-
var UnknownInstanceKindError = class extends Error {
|
|
25
|
-
kindId;
|
|
26
|
-
constructor(kindId) {
|
|
27
|
-
super(kindId === void 0 ? "This provider has several kinds: name one" : `Unknown instance kind '${kindId}'`);
|
|
28
|
-
this.kindId = kindId;
|
|
29
|
-
this.name = "UnknownInstanceKindError";
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
function composeInstanceKinds(parts, base) {
|
|
33
|
-
const byKind = (kindId) => {
|
|
34
|
-
if (kindId === void 0) {
|
|
35
|
-
const only = parts.length === 1 ? parts[0] : void 0;
|
|
36
|
-
if (only === void 0) throw new UnknownInstanceKindError(void 0);
|
|
37
|
-
return only;
|
|
38
|
-
}
|
|
39
|
-
const part = parts.find((candidate) => candidate.kind.id === kindId);
|
|
40
|
-
if (part === void 0) throw new UnknownInstanceKindError(kindId);
|
|
41
|
-
return part;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Whether a part's kind offers a Test. A kind that states `canTest` is believed; one that does not
|
|
45
|
-
* takes what its OWN provider declares, never the composed base (a calendar or an integration
|
|
46
|
-
* inherited the account's `canTest: true` and offered a button nothing answered, planning#543).
|
|
47
|
-
*/
|
|
48
|
-
const canTestPart = async (part) => part.kind.canTest ?? (await part.provider.describe()).canTest === true;
|
|
49
|
-
/**
|
|
50
|
-
* The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
|
|
51
|
-
* testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
|
|
52
|
-
*/
|
|
53
|
-
const draftPart = async (kindId) => {
|
|
54
|
-
if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
|
|
55
|
-
const flags = await Promise.all(parts.map(canTestPart));
|
|
56
|
-
const testable = parts.filter((_part, index) => flags[index] === true);
|
|
57
|
-
const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
|
|
58
|
-
if (only !== void 0) return only;
|
|
59
|
-
return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
|
|
60
|
-
};
|
|
61
|
-
const holderOf = async (id) => {
|
|
62
|
-
for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
|
|
63
|
-
throw new UnknownInstanceError(id);
|
|
64
|
-
};
|
|
65
|
-
const tagged = (part, instance) => ({
|
|
66
|
-
...instance,
|
|
67
|
-
kind: part.kind.id
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
describe: async () => {
|
|
71
|
-
const links = (await Promise.all(parts.map(async (part) => (await part.provider.describe()).links ?? []))).flat();
|
|
72
|
-
return {
|
|
73
|
-
...base,
|
|
74
|
-
kinds: await Promise.all(parts.map(async (part) => ({
|
|
75
|
-
...part.kind,
|
|
76
|
-
canTest: await canTestPart(part)
|
|
77
|
-
}))),
|
|
78
|
-
...links.length > 0 ? { links } : {}
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
instanceFormSchema: async ({ id, kind }) => {
|
|
82
|
-
return (id === null ? byKind(kind) : await holderOf(id)).provider.instanceFormSchema({ id });
|
|
83
|
-
},
|
|
84
|
-
listInstances: async (input) => {
|
|
85
|
-
return (await Promise.all(parts.map(async (part) => (await part.provider.listInstances(input)).map((instance) => tagged(part, instance))))).flat();
|
|
86
|
-
},
|
|
87
|
-
getInstance: async ({ id }) => {
|
|
88
|
-
for (const part of parts) {
|
|
89
|
-
const found = await part.provider.getInstance({ id });
|
|
90
|
-
if (found !== null) return tagged(part, found);
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
},
|
|
94
|
-
createInstance: async (input) => byKind(input.kind).provider.createInstance(input),
|
|
95
|
-
updateInstance: async (input) => (await holderOf(input.id)).provider.updateInstance(input),
|
|
96
|
-
setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
|
|
97
|
-
deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
|
|
98
|
-
testInstance: async (input) => {
|
|
99
|
-
const resolved = input.id === null ? await draftPart(input.kind) : await holderOf(input.id);
|
|
100
|
-
if ("error" in resolved) return {
|
|
101
|
-
success: false,
|
|
102
|
-
status: "inconclusive",
|
|
103
|
-
error: resolved.error
|
|
104
|
-
};
|
|
105
|
-
const test = resolved.provider.testInstance;
|
|
106
|
-
if (test === void 0) return {
|
|
107
|
-
success: false,
|
|
108
|
-
status: "inconclusive",
|
|
109
|
-
error: "This kind cannot be tested"
|
|
110
|
-
};
|
|
111
|
-
return test(input);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region ../types/dist/esm/addon/instances-of-cap.mjs
|
|
117
|
-
/**
|
|
118
|
-
* The kind's instances answer for `cap`: it is the kind's `functionCap`, or one the kind declares in
|
|
119
|
-
* `alsoServes`. The one rule a link (a picker, a resolver, a delete guard) matches a target by.
|
|
120
|
-
*/
|
|
121
|
-
function kindServesCap(kind, cap) {
|
|
122
|
-
return kind.functionCap === cap || (kind.alsoServes ?? []).includes(cap);
|
|
123
|
-
}
|
|
124
|
-
async function instancesOfCap(source, cap, filter = {}) {
|
|
125
|
-
const instances = [];
|
|
126
|
-
const unreadable = [];
|
|
127
|
-
for (const addonId of await source.holders(cap)) try {
|
|
128
|
-
const kinds = ((await source.describe(addonId)).kinds ?? []).filter((kind) => kindServesCap(kind, cap));
|
|
129
|
-
if (kinds.length === 0) continue;
|
|
130
|
-
for (const instance of await source.listInstances(addonId)) {
|
|
131
|
-
const kind = kinds.find((candidate) => candidate.id === instance.kind);
|
|
132
|
-
if (kind === void 0) continue;
|
|
133
|
-
if (filter.kind !== void 0 && (kind.brokerKind ?? kind.id) !== filter.kind) continue;
|
|
134
|
-
instances.push({
|
|
135
|
-
addonId,
|
|
136
|
-
kind,
|
|
137
|
-
instance
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
} catch (err) {
|
|
141
|
-
unreadable.push({
|
|
142
|
-
addonId,
|
|
143
|
-
error: err instanceof Error ? err.message : String(err)
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
instances,
|
|
148
|
-
unreadable
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
async function providersOf(api, name) {
|
|
152
|
-
const info = await api.capabilities.getCapability.query({ name });
|
|
153
|
-
if (info === null) throw new Error(`the capability registry did not answer for ${name}`);
|
|
154
|
-
return info.providers;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* The source over `ctx.api`. Every provider of the cap is a holder, not only those that also serve
|
|
158
|
-
* `integration-instances`: a provider that does not (an addon older than the hub during an update)
|
|
159
|
-
* then fails `describe` and is reported unreadable, so its instances are retried as transient
|
|
160
|
-
* instead of vanishing from the catalogue and failing for good.
|
|
161
|
-
*/
|
|
162
|
-
function instanceSourceOverApi(api) {
|
|
163
|
-
return {
|
|
164
|
-
holders: (cap) => providersOf(api, cap),
|
|
165
|
-
describe: (addonId) => api.integrationInstances.describe.query({ addonId }),
|
|
166
|
-
listInstances: (addonId) => api.integrationInstances.listInstances.query({ addonId })
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region ../types/dist/esm/addon/notification-targets.mjs
|
|
171
|
-
/**
|
|
172
|
-
* Notification targets as instances of the function cap `notification-output` (epic #440, step 6).
|
|
173
|
-
*
|
|
174
|
-
* A notification target used to be one row of one record kind (`{ name, kind, addonId, enabled,
|
|
175
|
-
* config }`) with a free-form `config` blob whose secrets nobody could name. Now every target KIND
|
|
176
|
-
* the provider offers (ntfy, telegram, webhook, ...) is a record kind of its own whose flat body IS
|
|
177
|
-
* that kind's form: the adapter's `configSchema` lifted into a Zod object, a `password` field marked
|
|
178
|
-
* `.meta({ secret: true })` so the records door keeps it in the keychain, an `instance-select` field
|
|
179
|
-
* declared as a link so the hub refuses to delete what a target points at.
|
|
180
|
-
*
|
|
181
|
-
* Three providers (notifiers, Home Assistant, Alexa) serve the same shape, so the pieces are shared:
|
|
182
|
-
* - {@link defineNotificationTargetKind}: the record kind of one `TargetKind` descriptor;
|
|
183
|
-
* - {@link NotificationTargetStore}: the `Target`-shaped facade the provider's own code keeps
|
|
184
|
-
* using (send, the notification-center bridge), over one handle per kind;
|
|
185
|
-
* - {@link listNotificationTargets}: the targets as an addon on `ctx.api` reads them;
|
|
186
|
-
* - {@link buildNotificationTargetInstances}: the `integration-instances` provider, one kind each;
|
|
187
|
-
* - {@link moveTargetRows}: the D987 procedure that flattens the old `config` blobs into the bodies.
|
|
188
|
-
*/
|
|
189
|
-
/** The function cap every notification target is an instance of. */
|
|
190
|
-
var NOTIFICATION_OUTPUT_CAP = "notification-output";
|
|
191
|
-
/** The most targets one provider lists (a settings page, not a table). */
|
|
192
|
-
var TARGETS_LIST_MAX = 1e3;
|
|
193
|
-
/** The record kind name of one target kind: `telegram` is stored under `notify-telegram`. */
|
|
194
|
-
function notificationTargetKindName(kind) {
|
|
195
|
-
return `notify-${kind}`;
|
|
196
|
-
}
|
|
197
|
-
/** The body schema of a target kind: the entry's name and switch plus the adapter's fields. */
|
|
198
|
-
var TargetBodyBaseSchema = /* @__PURE__ */ zod.z.looseObject({
|
|
199
|
-
name: /* @__PURE__ */ zod.z.string().min(1),
|
|
200
|
-
enabled: /* @__PURE__ */ zod.z.boolean().optional()
|
|
201
|
-
});
|
|
202
|
-
/** The shape of one `editable-array` row: the item fields, a `password` one a secret. */
|
|
203
|
-
function rowSchemaOf(itemFields) {
|
|
204
|
-
const shape = {};
|
|
205
|
-
let idKey = null;
|
|
206
|
-
let hasSecret = false;
|
|
207
|
-
for (const item of itemFields) {
|
|
208
|
-
if (item.type === "password") {
|
|
209
|
-
shape[item.key] = zod.z.string().optional().meta({ secret: true });
|
|
210
|
-
hasSecret = true;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
shape[item.key] = zod.z.unknown().optional();
|
|
214
|
-
idKey ??= item.key;
|
|
215
|
-
}
|
|
216
|
-
return {
|
|
217
|
-
row: zod.z.looseObject(shape),
|
|
218
|
-
idKey,
|
|
219
|
-
hasSecret
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* The Zod fields of a descriptor's form. A `password` field is a secret; an `instance-select` field is
|
|
224
|
-
* a link to an instance of its function cap; an `editable-array` keeps its rows (a password inside a
|
|
225
|
-
* row is a secret matched by the row's first plain field); every other field keeps whatever the
|
|
226
|
-
* adapter's own parse accepts, because the form already validated its shape. The body is loose, so a key
|
|
227
|
-
* the schema does not know (the owner of a personal target) survives a write.
|
|
228
|
-
*/
|
|
229
|
-
function fieldsOf(descriptor) {
|
|
230
|
-
const shape = {};
|
|
231
|
-
const secretArrayKeys = {};
|
|
232
|
-
for (const section of descriptor.configSchema.sections) for (const field of section.fields) switch (field.type) {
|
|
233
|
-
case "info": break;
|
|
234
|
-
case "password":
|
|
235
|
-
shape[field.key] = zod.z.string().optional().meta({ secret: true });
|
|
236
|
-
break;
|
|
237
|
-
case "instance-select":
|
|
238
|
-
shape[field.key] = require_base_addon.optionalLinkField({
|
|
239
|
-
cap: field.functionCap,
|
|
240
|
-
...field.kind !== void 0 ? { kind: field.kind } : {}
|
|
241
|
-
});
|
|
242
|
-
break;
|
|
243
|
-
case "editable-array": {
|
|
244
|
-
const { row, idKey, hasSecret } = rowSchemaOf(field.itemFields);
|
|
245
|
-
shape[field.key] = zod.z.array(row).optional();
|
|
246
|
-
if (hasSecret && idKey !== null) secretArrayKeys[field.key] = idKey;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
default: shape[field.key] = zod.z.unknown().optional();
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
shape,
|
|
253
|
-
secretArrayKeys
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/** The record kind of one target kind, derived from its descriptor. */
|
|
257
|
-
function defineNotificationTargetKind(descriptor) {
|
|
258
|
-
const { shape, secretArrayKeys } = fieldsOf(descriptor);
|
|
259
|
-
return require_entry_kind.defineEntryKind(notificationTargetKindName(descriptor.kind), {
|
|
260
|
-
title: `${descriptor.label} notification targets`,
|
|
261
|
-
schema: TargetBodyBaseSchema.extend(shape),
|
|
262
|
-
writeTrigger: `an operator adds, edits, switches or removes a ${descriptor.label} notification target`,
|
|
263
|
-
...Object.keys(secretArrayKeys).length > 0 ? { secretArrayKeys } : {}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
/** The record kinds of a provider's descriptors, keyed by the record kind name (for `records.declare`). */
|
|
267
|
-
function notificationTargetKinds(descriptors) {
|
|
268
|
-
return Object.fromEntries(descriptors.map((descriptor) => {
|
|
269
|
-
const defined = defineNotificationTargetKind(descriptor);
|
|
270
|
-
return [defined.name, defined];
|
|
271
|
-
}));
|
|
272
|
-
}
|
|
273
|
-
/** The body a stored target becomes: the switch and the name, and the config fields flat beside them. */
|
|
274
|
-
function targetBody(target) {
|
|
275
|
-
return {
|
|
276
|
-
...target.config,
|
|
277
|
-
name: target.name.length > 0 ? target.name : target.id,
|
|
278
|
-
enabled: target.enabled
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
/** The `Target` a record of a kind is; null when the row is not a target. */
|
|
282
|
-
function targetOfRecord(addonId, kind, id, data) {
|
|
283
|
-
const { name, enabled: _enabled, ...config } = data;
|
|
284
|
-
const parsed = require_notification_rules_cap.TargetSchema.safeParse({
|
|
285
|
-
id,
|
|
286
|
-
name,
|
|
287
|
-
kind,
|
|
288
|
-
addonId,
|
|
289
|
-
enabled: require_base_addon.isInstanceOn(id),
|
|
290
|
-
config
|
|
291
|
-
});
|
|
292
|
-
return parsed.success ? parsed.data : null;
|
|
293
|
-
}
|
|
294
|
-
function targetOfOld(addonId, row) {
|
|
295
|
-
return {
|
|
296
|
-
id: row.id,
|
|
297
|
-
name: row.name,
|
|
298
|
-
kind: row.kind,
|
|
299
|
-
addonId,
|
|
300
|
-
enabled: row.enabled,
|
|
301
|
-
config: { ...row.config }
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* The `Target`-shaped facade over one record kind per target kind. `list` returns the stored form (a
|
|
306
|
-
* secret is a keychain marker: every reader redacts it anyway); `getById` returns the target with its
|
|
307
|
-
* secrets resolved, which is what a send, a probe and an edit's secret merge need. A keychain that
|
|
308
|
-
* cannot answer throws: a write never goes ahead with a secret it could not read (D49).
|
|
309
|
-
*/
|
|
310
|
-
var NotificationTargetStore = class NotificationTargetStore {
|
|
311
|
-
addonId;
|
|
312
|
-
handles;
|
|
313
|
-
options;
|
|
314
|
-
constructor(addonId, handles, options) {
|
|
315
|
-
this.addonId = addonId;
|
|
316
|
-
this.handles = handles;
|
|
317
|
-
this.options = options;
|
|
318
|
-
}
|
|
319
|
-
static of(records, addonId, kinds, descriptors, options = {}) {
|
|
320
|
-
const handles = [];
|
|
321
|
-
for (const descriptor of descriptors) {
|
|
322
|
-
const defined = kinds[notificationTargetKindName(descriptor.kind)];
|
|
323
|
-
if (defined === void 0) continue;
|
|
324
|
-
handles.push({
|
|
325
|
-
kind: descriptor.kind,
|
|
326
|
-
handle: records.kind(defined)
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
return new NotificationTargetStore(addonId, handles, options);
|
|
330
|
-
}
|
|
331
|
-
/** The record handle of each kind, for the migration ports. */
|
|
332
|
-
handlesByKind() {
|
|
333
|
-
return new Map(this.handles.map((entry) => [entry.kind, entry.handle]));
|
|
334
|
-
}
|
|
335
|
-
async list() {
|
|
336
|
-
const out = [];
|
|
337
|
-
for (const { kind, handle } of this.handles) {
|
|
338
|
-
const page = await handle.query({ limit: TARGETS_LIST_MAX });
|
|
339
|
-
for (const record of page.records) {
|
|
340
|
-
const target = targetOfRecord(this.addonId, kind, record.id, record.data);
|
|
341
|
-
if (target !== null) {
|
|
342
|
-
out.push(target);
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
this.options.logger?.warn("notification target record is not a valid target; left out of the list", { meta: {
|
|
346
|
-
targetId: record.id,
|
|
347
|
-
kind
|
|
348
|
-
} });
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
const held = new Set(out.map((target) => target.id));
|
|
352
|
-
for (const row of await this.legacyRows()) if (!held.has(row.id)) out.push(targetOfOld(this.addonId, row));
|
|
353
|
-
return out;
|
|
354
|
-
}
|
|
355
|
-
/** The legacy rows of a kind this provider serves (the others are not ours to show). */
|
|
356
|
-
async legacyRows() {
|
|
357
|
-
const legacy = this.options.legacy;
|
|
358
|
-
if (legacy === void 0) return [];
|
|
359
|
-
const served = new Set(this.handles.map((entry) => entry.kind));
|
|
360
|
-
return (await legacy.list()).filter((row) => served.has(row.kind));
|
|
361
|
-
}
|
|
362
|
-
async getById(id) {
|
|
363
|
-
for (const { kind, handle } of this.handles) {
|
|
364
|
-
const row = await handle.getResolved(id);
|
|
365
|
-
if (row !== null) return targetOfRecord(this.addonId, kind, row.id, row.data);
|
|
366
|
-
}
|
|
367
|
-
const old = (await this.legacyRows()).find((row) => row.id === id);
|
|
368
|
-
return old === void 0 ? null : targetOfOld(this.addonId, old);
|
|
369
|
-
}
|
|
370
|
-
/** Insert or replace by id; a target whose kind changed leaves the record of its old kind. */
|
|
371
|
-
async upsert(target) {
|
|
372
|
-
const own = this.handles.find((entry) => entry.kind === target.kind);
|
|
373
|
-
if (own === void 0) throw new Error(`invalid target '${target.id}': unknown kind '${target.kind}'`);
|
|
374
|
-
const { enabled: _switch, ...data } = targetBody(target);
|
|
375
|
-
await own.handle.put({
|
|
376
|
-
id: target.id,
|
|
377
|
-
data
|
|
378
|
-
});
|
|
379
|
-
require_base_addon.recordInstanceSwitch(target.id, target.enabled);
|
|
380
|
-
for (const other of this.handles) if (other !== own) await other.handle.delete(target.id);
|
|
381
|
-
await this.options.legacy?.delete(target.id);
|
|
382
|
-
}
|
|
383
|
-
async delete(id) {
|
|
384
|
-
for (const { handle } of this.handles) await handle.delete(id);
|
|
385
|
-
await this.options.legacy?.delete(id);
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
/**
|
|
389
|
-
* A probe's answer as the tri-state of `testInstance`: `ok` validated; a refusal that carries an HTTP
|
|
390
|
-
* status is the remote saying no (`rejected`); a failure with no answer at all (the network, a missing
|
|
391
|
-
* field) proves nothing about the credentials (`inconclusive`).
|
|
392
|
-
*/
|
|
393
|
-
function probeToTestResult(probed) {
|
|
394
|
-
if (probed.ok) return {
|
|
395
|
-
success: true,
|
|
396
|
-
status: "validated",
|
|
397
|
-
...probed.stateInstance !== void 0 ? { detail: probed.stateInstance } : {}
|
|
398
|
-
};
|
|
399
|
-
const error = probed.error ?? "the probe failed";
|
|
400
|
-
return {
|
|
401
|
-
success: false,
|
|
402
|
-
status: probed.httpStatus !== void 0 ? "rejected" : "inconclusive",
|
|
403
|
-
error
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
/** The form of a kind: the adapter's own sections. */
|
|
407
|
-
function formOf(descriptor) {
|
|
408
|
-
return descriptor.configSchema;
|
|
409
|
-
}
|
|
410
|
-
/** The instance kinds of a notification provider, one per target kind: a part a composition can take. */
|
|
411
|
-
function notificationTargetParts(records, spec) {
|
|
412
|
-
return spec.descriptors.flatMap((descriptor) => {
|
|
413
|
-
const defined = spec.kinds[notificationTargetKindName(descriptor.kind)];
|
|
414
|
-
if (defined === void 0) return [];
|
|
415
|
-
const canTest = spec.probe !== void 0 && spec.canProbe(descriptor.kind);
|
|
416
|
-
const kind = {
|
|
417
|
-
id: descriptor.kind,
|
|
418
|
-
label: descriptor.label,
|
|
419
|
-
functionCap: NOTIFICATION_OUTPUT_CAP,
|
|
420
|
-
role: "services",
|
|
421
|
-
canTest,
|
|
422
|
-
...spec.widgets?.(descriptor.kind) !== void 0 ? { widgets: spec.widgets(descriptor.kind) } : {},
|
|
423
|
-
...descriptor.iconUrl !== void 0 ? { iconUrl: descriptor.iconUrl } : {},
|
|
424
|
-
...descriptor.iconMediaType !== void 0 ? { iconMediaType: descriptor.iconMediaType } : {}
|
|
425
|
-
};
|
|
426
|
-
return [{
|
|
427
|
-
kind,
|
|
428
|
-
provider: new require_base_addon.RecordIntegrationInstances(records, defined, {
|
|
429
|
-
description: {
|
|
430
|
-
role: "services",
|
|
431
|
-
instanceMode: "multiple",
|
|
432
|
-
kind: "target",
|
|
433
|
-
canTest,
|
|
434
|
-
kinds: [kind]
|
|
435
|
-
},
|
|
436
|
-
formSchema: () => formOf(descriptor),
|
|
437
|
-
initialBody: (name) => ({ name }),
|
|
438
|
-
mintId: () => spec.mintId(),
|
|
439
|
-
configured: () => true,
|
|
440
|
-
validateWrite: ({ body }) => spec.validate?.({
|
|
441
|
-
kind: descriptor.kind,
|
|
442
|
-
config: body
|
|
443
|
-
}),
|
|
444
|
-
test: async ({ id, values }) => {
|
|
445
|
-
if (spec.probe === void 0 || !canTest) return {
|
|
446
|
-
success: false,
|
|
447
|
-
status: "unsupported",
|
|
448
|
-
error: "This kind cannot be tested"
|
|
449
|
-
};
|
|
450
|
-
return probeToTestResult(await spec.probe({
|
|
451
|
-
kind: descriptor.kind,
|
|
452
|
-
config: values,
|
|
453
|
-
targetId: id ?? void 0
|
|
454
|
-
}));
|
|
455
|
-
}
|
|
456
|
-
}).toProvider()
|
|
457
|
-
}];
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
/** The `integration-instances` provider of a notification provider: one kind per target kind. */
|
|
461
|
-
function buildNotificationTargetInstances(records, spec) {
|
|
462
|
-
const parts = notificationTargetParts(records, spec);
|
|
463
|
-
return composeInstanceKinds(parts, {
|
|
464
|
-
role: "services",
|
|
465
|
-
instanceMode: "multiple",
|
|
466
|
-
kind: "target",
|
|
467
|
-
canTest: parts.some((part) => part.kind.canTest === true),
|
|
468
|
-
mintsId: true
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Every notification target, read as the instances of `notification-output` (D1013 rule 5). A holder
|
|
473
|
-
* that could not answer is NAMED in `unreadable`: a caller that acts on a target's absence (drops a
|
|
474
|
-
* selection, refuses a send) must check it first, because a partial read is not "deleted" (D315, D49).
|
|
475
|
-
*/
|
|
476
|
-
async function listNotificationTargets(api) {
|
|
477
|
-
const { instances, unreadable } = await instancesOfCap(instanceSourceOverApi(api), NOTIFICATION_OUTPUT_CAP);
|
|
478
|
-
return {
|
|
479
|
-
targets: instances.map(({ addonId, kind, instance }) => {
|
|
480
|
-
const owner = instance.formValues["ownerUserId"];
|
|
481
|
-
return {
|
|
482
|
-
id: instance.id,
|
|
483
|
-
name: instance.name,
|
|
484
|
-
kind: kind.id,
|
|
485
|
-
addonId,
|
|
486
|
-
enabled: instance.enabled !== false,
|
|
487
|
-
...typeof owner === "string" && owner.length > 0 ? { ownerUserId: owner } : {}
|
|
488
|
-
};
|
|
489
|
-
}),
|
|
490
|
-
unreadable
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
//#endregion
|
|
494
13
|
//#region ../types/dist/esm/notification/schedule.mjs
|
|
495
14
|
var WEEKDAY_TO_DAY = {
|
|
496
15
|
Sun: 0,
|
|
@@ -817,7 +336,7 @@ function groupTargetKind() {
|
|
|
817
336
|
caps: GROUP_CAPS
|
|
818
337
|
};
|
|
819
338
|
}
|
|
820
|
-
var groupRecordKinds = notificationTargetKinds([groupTargetKind()]);
|
|
339
|
+
var groupRecordKinds = require_notification_targets.notificationTargetKinds([groupTargetKind()]);
|
|
821
340
|
//#endregion
|
|
822
341
|
//#region src/builtins/core-notifier/group-instances.ts
|
|
823
342
|
/**
|
|
@@ -1206,10 +725,10 @@ var CoreNotifierAddon = class extends require_base_addon.BaseAddon {
|
|
|
1206
725
|
if (api === void 0) throw new Error("core-notifier needs ctx.api to reach its members");
|
|
1207
726
|
await records.declare(groupRecordKinds);
|
|
1208
727
|
const logger = this.ctx.logger.child("notification-output");
|
|
1209
|
-
const store = NotificationTargetStore.of(records, NOTIFIER_GROUP_ADDON_ID, groupRecordKinds, [groupTargetKind()], { logger });
|
|
728
|
+
const store = require_notification_targets.NotificationTargetStore.of(records, NOTIFIER_GROUP_ADDON_ID, groupRecordKinds, [groupTargetKind()], { logger });
|
|
1210
729
|
const group = createGroupNotificationOutputProvider({
|
|
1211
730
|
store,
|
|
1212
|
-
listTargets: () => listNotificationTargets(api),
|
|
731
|
+
listTargets: () => require_notification_targets.listNotificationTargets(api),
|
|
1213
732
|
listMemberKinds: () => readMemberKinds(api),
|
|
1214
733
|
sendToMember: (input) => api.notificationOutput.send.mutate({
|
|
1215
734
|
addonId: input.addonId,
|
|
@@ -1243,7 +762,7 @@ var CoreNotifierAddon = class extends require_base_addon.BaseAddon {
|
|
|
1243
762
|
now: () => Date.now(),
|
|
1244
763
|
logger
|
|
1245
764
|
});
|
|
1246
|
-
const instances = refuseNestedGroups(buildNotificationTargetInstances(records, groupInstancesSpec({ mintId: () => (0, node_crypto.randomUUID)() })), async () => new Set((await store.list()).map((target) => target.id)));
|
|
765
|
+
const instances = refuseNestedGroups(require_notification_targets.buildNotificationTargetInstances(records, groupInstancesSpec({ mintId: () => (0, node_crypto.randomUUID)() })), async () => new Set((await store.list()).map((target) => target.id)));
|
|
1247
766
|
this.ctx.logger.info("CoreNotifier initialized");
|
|
1248
767
|
return { providers: [{
|
|
1249
768
|
capability: require_notification_rules_cap.notificationOutputCapability,
|