@listen-fire/engine-contracts 0.15.3 → 0.16.1

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/dist/adapter.d.ts CHANGED
@@ -14,78 +14,6 @@ export type { ConfigBlock } from './config_blocks';
14
14
  export { fileDescriptorOf, fileHandle, fileValue, fileValueOf, filesAtType, isFileValue, ownedFileSource } from './file_ref';
15
15
  export type { EarlierFileSource, FileRef, FileSource, FileValue } from './file_ref';
16
16
  export type { ExternalRecordRef, Fact, FieldEvidence, Resource, ResourceProvenance } from './records';
17
- /**
18
- * Minimal user descriptor returned by Listen-Fire's `resolveActingUser`
19
- * (acting_user/resolve.ts) and consumed by the engine's meta resolver to
20
- * populate `@user_email`,
21
- * `@user_name`, and `@user_id`. Kept shape-loose (name optional) so
22
- * adapters that can only surface an email don't have to fabricate a
23
- * display name.
24
- *
25
- */
26
- export interface ActingUser {
27
- id: string;
28
- email: string;
29
- name?: string | null;
30
- }
31
- /**
32
- * Raw event-side actor identity returned by `Adapter.extractActor`. Distinct
33
- * from `ActingUser`: an `ActorIdentity` is the external originator of the
34
- * event (the `From:` address on an email, the Slack user that posted, the
35
- * Attio actor that wrote a record) regardless of whether they are a
36
- * registered Listen-Fire team member. Powers `@actor_email` / `@actor_name` /
37
- * `@actor_id` so authors can compare "the team member responsible for this
38
- * dispatch" (`@user_*`) with "who actually originated the event" (`@actor_*`).
39
- *
40
- * Parsed from the event payload — no DB lookups — because actor identity
41
- * is a parse, not an auth decision. The method is async only so a remote
42
- * adapter can answer it over the wire; local impls are still pure parses.
43
- *
44
- */
45
- export interface ActorIdentity {
46
- /** Primary key in the source system (email address, phone number,
47
- * Slack user id, Attio actor id, etc.). */
48
- identifier: string;
49
- /** How this identity resolves to a Listen-Fire team user — the only thing the
50
- * resolution logic cares about, independent of which adapter produced it:
51
- * • `'email'` — resolvable to a team user by email (the address is on
52
- * `identifier` or `email`).
53
- * • `'phone'` — resolvable to a team user by phone number.
54
- * • `'opaque'` — neither; a raw external id with no resolved email/phone,
55
- * so it maps to no Listen-Fire user (e.g. a bare Slack/Attio id from the
56
- * pure-parse `extractActor`). Resolvers skip it rather than guessing. */
57
- scheme: 'email' | 'phone' | 'opaque';
58
- /** Which adapter sourced this identity — provenance only; the resolution
59
- * logic never branches on it (it branches on `scheme`). */
60
- adapterType?: string;
61
- /** Email address when the source carries one (every email event; Slack
62
- * messages don't have this without an API call). */
63
- email?: string;
64
- /** Display name (the friendly part of `"Ada" <h@x>`; Slack display
65
- * name; etc.). */
66
- name?: string;
67
- /** Fallback display label when `name` isn't available. */
68
- label?: string;
69
- /** True when the module checked that the source system vouches for this
70
- * identity (a verified address, a signed request). Absent reads as not
71
- * proven: it is a claim only the module can make. */
72
- proven?: boolean;
73
- }
74
- /**
75
- * An ordered actor candidate parsed from an inbound event by the adapter's
76
- * `getActorCandidates`. Distinct from `ActorIdentity` (the raw event
77
- * originator surfaced via `@actor_*`): a candidate is a *resolution input*
78
- * Listen-Fire's `resolveActingUser` maps to a team user. The `source` tag drives
79
- * the resolution order — `originator` candidates (who sent it) are matched
80
- * against non-service users first; `relay` candidates (the forwarding /
81
- * service inbox that delivered it) are matched against service users only.
82
- *
83
- */
84
- export interface ActorCandidate {
85
- identity: ActorIdentity;
86
- /** who-sent-it (`originator`) vs forwarding/service-inbox (`relay`). */
87
- source: 'originator' | 'relay';
88
- }
89
17
  /**
90
18
  * The protocol method names a write goes through. Used as the capability
91
19
  * basis for "is this adapter a valid TG target" — a manifest whose `methods`
@@ -252,21 +180,24 @@ export interface AdapterManifest {
252
180
  */
253
181
  triggerExpectation?: string;
254
182
  /**
255
- * Ownership gating for inbound events (message-write-unification §6.4b):
256
- * when true, the dispatcher processes an inbound event ONLY if its actor
257
- * resolves to a REGISTERED team user (the adapter's `getActorCandidates`
258
- * chain matched by `resolveActingUser`, WITHOUT trigger context — creator
259
- * override/fallback never pass the gate). The bot is never a registered
260
- * user, so self-echo drops for free; an unregistered person is dropped by
261
- * the same rule. Dropped events are recorded (receipt marked suppressed,
262
- * replayable), never silent. Set by adapters whose inbound channel is
263
- * globally addressable (Slack: anyone in the workspace can @-mention the
264
- * bot); adapters whose inbound is already identity-gated upstream omit it
265
- * (WhatsApp's sender→team resolution; Telegram's /start handshake binding
266
- * ON THE BUILT-IN SHARED BOT — a team running its own bot has no such
267
- * gate, so a BYO-bot team's inbound is not actually identity-gated here).
268
- */
269
- inboundRequiresRegisteredActor?: boolean;
183
+ * The release before which a host may have let only registered senders set
184
+ * a listen on this module off (Slack: `'0.16.0'`, when the hosted
185
+ * platform's gate on registered team members retired). From it, only a
186
+ * listen's filter decides who sets it off. An upgrade from an older key
187
+ * tells each listen whose filter does not limit it (`MOV_LISTEN_NOW_OPEN`).
188
+ * Omitted: no host ever limited this module's listens.
189
+ */
190
+ listensLimitedBefore?: string;
191
+ /**
192
+ * Connection settings this module no longer reads. A host refuses a
193
+ * connection that still holds one, with `instead` in the message: a
194
+ * setting is kept with the connection, outside any movement, so no
195
+ * upgrade can rewrite it.
196
+ */
197
+ retiredSettings?: Array<{
198
+ name: string;
199
+ instead: string;
200
+ }>;
270
201
  /** True when this adapter's schema comes from LIVE introspection of the
271
202
  * connected workspace (attio, airtable, sheets, affinity) — a
272
203
  * describeInstance costs upstream API calls, so callers should scope with
@@ -774,55 +705,6 @@ export interface Adapter {
774
705
  getDedupRules?(input: {
775
706
  typeRef: string;
776
707
  }): Promise<DedupRules | null>;
777
- /**
778
- * Parse ordered actor candidates from an inbound event — a pure parse of
779
- * who-sent-it / who-relayed-it, with NO Listen-Fire DB access (external-system
780
- * API enrichment IS allowed: Slack `users.info`, Attio
781
- * `/v2/workspace_members/{id}`, etc., to surface the actor's email).
782
- *
783
- * This is the adapter half of the acting-user split (the extensible
784
- * adapter protocol, 2026-05-29). The adapter no longer reaches into
785
- * Listen-Fire's user tables — it only describes the candidates; Listen-Fire's
786
- * `resolveActingUser` (acting_user/resolve.ts) runs the identical
787
- * resolution chain (creator-override → originator/non-service →
788
- * relay/service → creator-fallback → null) by mapping these candidates
789
- * to a team user. Splitting parse from resolution lets the parse cross a
790
- * remote-adapter boundary that the DB chain never could.
791
- *
792
- * Candidate ordering and `source` tags reproduce the prior per-adapter
793
- * chains exactly:
794
- * - Email: sender (`From:` / `sender`) as `originator`; each parsed
795
- * forwarding-header recipient as `relay`.
796
- * - Slack / Attio: the runtime-resolved actor email as a single
797
- * `originator` candidate (empty array when no email resolves).
798
- *
799
- * The terminal recipient on the deployment's own inbound address is ROUTING ONLY and is never a
800
- * candidate — auth comes from who SENT it or which inbox RELAYED it.
801
- *
802
- * Optional — adapters with no acting-user concept omit it; the resolver
803
- * then yields null (no `@user_*`). `extractActor` (`@actor_*`) is
804
- * independent of this method.
805
- *
806
- */
807
- getActorCandidates?(input: {
808
- event: TriggerEvent;
809
- }): Promise<ActorCandidate[]>;
810
- /**
811
- * Extract the raw actor identity from an inbound event. A pure parse,
812
- * no DB lookups — actor identity is "who originated this event
813
- * in the source system" regardless of whether they map to a Listen-Fire
814
- * user. Powers `@actor_email` / `@actor_name` / `@actor_id` so authors
815
- * can attribute events to their raw originator independently of the
816
- * authenticated team member.
817
- *
818
- * Returns `null` when the event has no actor-shaped originator (e.g.
819
- * a snapshot replay with no per-record provenance). Adapters that
820
- * don't implement get `@actor_*` = null at dispatch time, gracefully.
821
- *
822
- */
823
- extractActor?(input: {
824
- event: TriggerEvent;
825
- }): Promise<ActorIdentity | null>;
826
708
  didWeAuthor?(input: {
827
709
  event: TriggerEvent;
828
710
  }): Promise<boolean | null>;
@@ -1,4 +1,3 @@
1
- import type { ActorIdentity } from './adapter';
2
1
  /** A record a run waits on: the id its write answered, the data it
3
2
  * carried (Slack keys a thread by the channel in it, not by its id), and its
4
3
  * record type, as the module names it, wherever the host knows it (2.6). A
@@ -62,11 +61,6 @@ export type Arrival = {
62
61
  * it, however late a poll finds it (2.6), and the run it fires
63
62
  * stamps its writes with it (2.7). */
64
63
  occurredAt?: string;
65
- /** Who acted, where the provider says: the member who posted, the
66
- * sender of the mail, the owner of the meeting (2.7). The run's
67
- * `@actor_*` reads it, and a host resolves the acting user from it;
68
- * set at the door, so nothing after it needs the raw event. */
69
- actor?: ActorIdentity;
70
64
  } | {
71
65
  edge: string;
72
66
  key: string;
package/dist/catalog.d.ts CHANGED
@@ -32,6 +32,13 @@ export type ExpressionType = {
32
32
  } | {
33
33
  kind: 'record';
34
34
  fields: Record<string, ExpressionType>;
35
+ } | {
36
+ kind: 'branded';
37
+ of: ExpressionType;
38
+ brands: string[];
39
+ } | {
40
+ kind: 'union';
41
+ of: ExpressionType[];
35
42
  };
36
43
  export declare const genericEdgeSchema: z.ZodObject<{
37
44
  target: z.ZodType<ExpressionType, unknown, z.core.$ZodTypeInternals<ExpressionType, unknown>>;
@@ -480,6 +487,7 @@ export declare const schemaFieldDescriptorSchema: z.ZodObject<{
480
487
  typeId: z.ZodString;
481
488
  }, z.core.$strip>>;
482
489
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
490
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
483
491
  changedIn: z.ZodOptional<z.ZodObject<{
484
492
  release: z.ZodString;
485
493
  note: z.ZodString;
@@ -668,6 +676,7 @@ export declare const schemaReferenceDescriptorSchema: z.ZodPreprocess<z.ZodObjec
668
676
  typeId: z.ZodString;
669
677
  }, z.core.$strip>>;
670
678
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
679
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
671
680
  changedIn: z.ZodOptional<z.ZodObject<{
672
681
  release: z.ZodString;
673
682
  note: z.ZodString;
@@ -843,6 +852,7 @@ export declare const schemaTypeDescriptorSchema: z.ZodObject<{
843
852
  typeId: z.ZodString;
844
853
  }, z.core.$strip>>;
845
854
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
855
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
846
856
  changedIn: z.ZodOptional<z.ZodObject<{
847
857
  release: z.ZodString;
848
858
  note: z.ZodString;
@@ -1005,6 +1015,7 @@ export declare const schemaTypeDescriptorSchema: z.ZodObject<{
1005
1015
  typeId: z.ZodString;
1006
1016
  }, z.core.$strip>>;
1007
1017
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
1018
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1008
1019
  changedIn: z.ZodOptional<z.ZodObject<{
1009
1020
  release: z.ZodString;
1010
1021
  note: z.ZodString;
@@ -1236,6 +1247,7 @@ declare const schemaDescriptorSchema: z.ZodObject<{
1236
1247
  typeId: z.ZodString;
1237
1248
  }, z.core.$strip>>;
1238
1249
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
1250
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1239
1251
  changedIn: z.ZodOptional<z.ZodObject<{
1240
1252
  release: z.ZodString;
1241
1253
  note: z.ZodString;
@@ -1398,6 +1410,7 @@ declare const schemaDescriptorSchema: z.ZodObject<{
1398
1410
  typeId: z.ZodString;
1399
1411
  }, z.core.$strip>>;
1400
1412
  mayBeAbsent: z.ZodOptional<z.ZodBoolean>;
1413
+ brands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1401
1414
  changedIn: z.ZodOptional<z.ZodObject<{
1402
1415
  release: z.ZodString;
1403
1416
  note: z.ZodString;
@@ -1690,6 +1703,7 @@ declare const transformOutputKindSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1690
1703
  optional: z.ZodOptional<z.ZodBoolean>;
1691
1704
  description: z.ZodOptional<z.ZodString>;
1692
1705
  }, z.core.$strip>>;
1706
+ optional: z.ZodOptional<z.ZodBoolean>;
1693
1707
  }, z.core.$strip>, z.ZodObject<{
1694
1708
  kind: z.ZodLiteral<"records">;
1695
1709
  fields: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -1740,6 +1754,7 @@ declare const transformSignatureSchema: z.ZodObject<{
1740
1754
  optional: z.ZodOptional<z.ZodBoolean>;
1741
1755
  description: z.ZodOptional<z.ZodString>;
1742
1756
  }, z.core.$strip>>;
1757
+ optional: z.ZodOptional<z.ZodBoolean>;
1743
1758
  }, z.core.$strip>, z.ZodObject<{
1744
1759
  kind: z.ZodLiteral<"records">;
1745
1760
  fields: z.ZodRecord<z.ZodString, z.ZodObject<{
package/dist/catalog.js CHANGED
@@ -76,6 +76,20 @@ exports.expressionTypeSchema = zod_1.z.lazy(() => zod_1.z.discriminatedUnion('ki
76
76
  kind: zod_1.z.literal('record'),
77
77
  fields: zod_1.z.record(zod_1.z.string(), exports.expressionTypeSchema),
78
78
  }),
79
+ /** `string & Brand<"claim:email/address">`: `of` narrowed by each brand. A
80
+ * plugin parameter declares one; only a string or a number takes a brand. */
81
+ zod_1.z.object({
82
+ kind: zod_1.z.literal('branded'),
83
+ of: exports.expressionTypeSchema.refine((of) => of.kind === 'string' || of.kind === 'number', {
84
+ error: 'branded.of: expected a string or a number',
85
+ }),
86
+ brands: zod_1.z.array(zod_1.z.string().min(1)).min(1),
87
+ }),
88
+ /** One of several types, as the catalog spells a union. */
89
+ zod_1.z.object({
90
+ kind: zod_1.z.literal('union'),
91
+ of: zod_1.z.array(exports.expressionTypeSchema).min(1),
92
+ }),
79
93
  ]));
80
94
  // ── GenericShape: declared in-memory contract for a TG side ─────────────────
81
95
  // Used by `kind: 'generic'` schemaRefs. The shape declares properties (typed
@@ -633,6 +647,9 @@ exports.schemaFieldDescriptorSchema = zod_1.z.object({
633
647
  fieldId: zod_1.z.string(),
634
648
  displayName: zod_1.z.string(),
635
649
  kind: schemaFieldKindSchema,
650
+ /** With `kind: 'enum'`: a CLOSED list. A literal not in it is an error
651
+ * (`MOV_ENUM_UNKNOWN_VALUE`); with `cardinality: 'many'`, each tag of a list
652
+ * is checked. Example: `enumValues: ['cursed', 'heavy'], cardinality: 'many'`. */
636
653
  enumValues: zod_1.z.array(zod_1.z.string()).optional(),
637
654
  /**
638
655
  * OPEN known-values (distinct from `enumValues`, a closed set): live values
@@ -657,6 +674,12 @@ exports.schemaFieldDescriptorSchema = zod_1.z.object({
657
674
  * check time (MOV_WRITE_ONLY_PROPERTY) instead of silently yielding null.
658
675
  */
659
676
  readable: zod_1.z.boolean().optional(),
677
+ /**
678
+ * For WRITES: `true` says a write must give this field. Says nothing about
679
+ * reads: a field a read may find missing needs `mayBeAbsent`, whatever
680
+ * `required` is. Example: `required: true, mayBeAbsent: true` is a field
681
+ * every create gives but a read can still miss.
682
+ */
660
683
  required: zod_1.z.boolean(),
661
684
  /**
662
685
  * A read of this type must pin this field in its WHERE with `==`
@@ -738,9 +761,16 @@ exports.schemaFieldDescriptorSchema = zod_1.z.object({
738
761
  owned: zod_1.z.object({ name: zod_1.z.string().min(1), allowPattern: zod_1.z.string().optional(), format: zod_1.z.enum(['cron', 'timeZone']).optional() }).optional(),
739
762
  /** With `kind: 'record'`: the type of the record it holds, by its type id. */
740
763
  record: zod_1.z.object({ typeId: zod_1.z.string().min(1) }).optional(),
741
- /** A record may not hold the field at all (a change's row before, when
742
- * the row was created): a read of it may be absent. Absent ⇒ false. */
764
+ /** For READS: `true` says a read may find the field missing (a change's
765
+ * row before, when the row was created; an optional number), so the
766
+ * checker types it as possibly absent and a program tests it first.
767
+ * Absent ⇒ false, however `required` is set. Example:
768
+ * `{ fieldId: 'Hp', kind: 'number', writable: true, required: false, mayBeAbsent: true }`. */
743
769
  mayBeAbsent: zod_1.z.boolean().optional(),
770
+ /** With `kind: 'string'` or `'number'`: the module vouches for the value
771
+ * under these names (`claim:email/address`). A brand narrows the type, as
772
+ * TypeScript's intersection does; a name is compared whole, never parsed. */
773
+ brands: zod_1.z.array(zod_1.z.string().min(1)).min(1).optional(),
744
774
  /** The release that changed what the field holds, and how, as a check for
745
775
  * an upgrade from before it warns where a program reads it (gmail's
746
776
  * `Labels`: label ids before 0.13, names since). `unchangedValues` are
@@ -756,6 +786,13 @@ exports.schemaFieldDescriptorSchema = zod_1.z.object({
756
786
  message: `'${field.displayName}': 'owned' names the scalar of a field of kind 'owned', and only of one`,
757
787
  });
758
788
  }
789
+ if (field.brands !== undefined && field.kind !== 'string' && field.kind !== 'number') {
790
+ ctx.addIssue({
791
+ code: zod_1.z.ZodIssueCode.custom,
792
+ path: ['brands'],
793
+ message: `'${field.displayName}': 'brands' narrow a string or a number, and this field is of kind '${field.kind}'`,
794
+ });
795
+ }
759
796
  if ((field.kind === 'record') !== (field.record !== undefined)) {
760
797
  ctx.addIssue({
761
798
  code: zod_1.z.ZodIssueCode.custom,
@@ -2089,6 +2126,10 @@ const transformOutputKindSchema = zod_1.z.discriminatedUnion('kind', [
2089
2126
  zod_1.z.object({
2090
2127
  kind: zod_1.z.literal('record'),
2091
2128
  fields: zod_1.z.record(zod_1.z.string(), transformOutputFieldSchema),
2129
+ /** `{ … } | null`: the plugin may answer no record at all (a lookup that
2130
+ * found nobody). Read downstream as `record | absent`, so a field is
2131
+ * read off it with `?.`. */
2132
+ optional: zod_1.z.boolean().optional(),
2092
2133
  }),
2093
2134
  zod_1.z.object({
2094
2135
  kind: zod_1.z.literal('records'),
@@ -29,7 +29,6 @@
29
29
  "parents": [{ "recordId": "C1", "recordType": "Channel", "fields": { "Name": "deals" } }, null],
30
30
  "about": { "recordType": "Message", "externalId": "C1:1700000000.000100" },
31
31
  "occurredAt": "2023-11-14T22:14:10+00:00",
32
- "actor": { "identifier": "U1", "scheme": "opaque", "label": "U1" },
33
32
  "takenApplied": true
34
33
  },
35
34
  "trigger": {
@@ -41,8 +40,7 @@
41
40
  "edge": "Replies",
42
41
  "landing": { "recordId": "C1:1700000050.000200", "recordType": "Message", "fields": { "text": "on it", "user": "U1" } },
43
42
  "parents": [{ "recordId": "C1", "recordType": "Channel", "fields": { "Name": "deals" } }, null],
44
- "about": { "recordType": "Message", "externalId": "C1:1700000000.000100" },
45
- "actor": { "identifier": "U1", "scheme": "opaque", "label": "U1" }
43
+ "about": { "recordType": "Message", "externalId": "C1:1700000000.000100" }
46
44
  },
47
45
  "occurredAt": "2023-11-14T22:14:10.000Z"
48
46
  }
@@ -212,6 +212,22 @@
212
212
  "description": "the total",
213
213
  "type": "extract_value"
214
214
  },
215
+ "Field": {
216
+ "expression": {
217
+ "args": [
218
+ {
219
+ "fieldOnly": true,
220
+ "propertyTypeId": "Owner",
221
+ "type": "edge_property"
222
+ }
223
+ ],
224
+ "fn": "coalesce",
225
+ "type": "function"
226
+ },
227
+ "field": "Level",
228
+ "optional": true,
229
+ "type": "field"
230
+ },
215
231
  "Function": {
216
232
  "args": [
217
233
  {