@nodii/telemetry 0.0.2 → 0.3.0

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.
Files changed (82) hide show
  1. package/README.md +223 -1
  2. package/dist/active-span.d.ts +12 -0
  3. package/dist/active-span.d.ts.map +1 -0
  4. package/dist/active-span.js +20 -0
  5. package/dist/active-span.js.map +1 -0
  6. package/dist/agent-invocable.d.ts +24 -0
  7. package/dist/agent-invocable.d.ts.map +1 -0
  8. package/dist/agent-invocable.js +64 -0
  9. package/dist/agent-invocable.js.map +1 -0
  10. package/dist/audit-types.d.ts +15 -0
  11. package/dist/audit-types.d.ts.map +1 -0
  12. package/dist/audit-types.js +39 -0
  13. package/dist/audit-types.js.map +1 -0
  14. package/dist/audit.d.ts +226 -0
  15. package/dist/audit.d.ts.map +1 -0
  16. package/dist/audit.js +255 -0
  17. package/dist/audit.js.map +1 -0
  18. package/dist/configure.d.ts +34 -0
  19. package/dist/configure.d.ts.map +1 -0
  20. package/dist/configure.js +23 -0
  21. package/dist/configure.js.map +1 -0
  22. package/dist/context.d.ts +40 -0
  23. package/dist/context.d.ts.map +1 -0
  24. package/dist/context.js +70 -0
  25. package/dist/context.js.map +1 -0
  26. package/dist/drizzle/audit-schema.d.ts +884 -0
  27. package/dist/drizzle/audit-schema.d.ts.map +1 -0
  28. package/dist/drizzle/audit-schema.js +268 -0
  29. package/dist/drizzle/audit-schema.js.map +1 -0
  30. package/dist/drizzle/index.d.ts +3 -0
  31. package/dist/drizzle/index.d.ts.map +1 -0
  32. package/dist/drizzle/index.js +5 -0
  33. package/dist/drizzle/index.js.map +1 -0
  34. package/dist/index.d.ts +21 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +31 -5
  37. package/dist/index.js.map +1 -1
  38. package/dist/init.d.ts +39 -0
  39. package/dist/init.d.ts.map +1 -0
  40. package/dist/init.js +114 -0
  41. package/dist/init.js.map +1 -0
  42. package/dist/intent.d.ts +21 -0
  43. package/dist/intent.d.ts.map +1 -0
  44. package/dist/intent.js +123 -0
  45. package/dist/intent.js.map +1 -0
  46. package/dist/logger.d.ts +19 -0
  47. package/dist/logger.d.ts.map +1 -0
  48. package/dist/logger.js +99 -0
  49. package/dist/logger.js.map +1 -0
  50. package/dist/metrics.d.ts +53 -0
  51. package/dist/metrics.d.ts.map +1 -0
  52. package/dist/metrics.js +152 -0
  53. package/dist/metrics.js.map +1 -0
  54. package/dist/otlp-adapter.d.ts +44 -0
  55. package/dist/otlp-adapter.d.ts.map +1 -0
  56. package/dist/otlp-adapter.js +351 -0
  57. package/dist/otlp-adapter.js.map +1 -0
  58. package/dist/outbox-emit.d.ts +34 -0
  59. package/dist/outbox-emit.d.ts.map +1 -0
  60. package/dist/outbox-emit.js +58 -0
  61. package/dist/outbox-emit.js.map +1 -0
  62. package/dist/redaction.d.ts +51 -0
  63. package/dist/redaction.d.ts.map +1 -0
  64. package/dist/redaction.js +173 -0
  65. package/dist/redaction.js.map +1 -0
  66. package/dist/sdk-counters.d.ts +14 -0
  67. package/dist/sdk-counters.d.ts.map +1 -0
  68. package/dist/sdk-counters.js +42 -0
  69. package/dist/sdk-counters.js.map +1 -0
  70. package/dist/tracer.d.ts +63 -0
  71. package/dist/tracer.d.ts.map +1 -0
  72. package/dist/tracer.js +214 -0
  73. package/dist/tracer.js.map +1 -0
  74. package/dist/types.d.ts +230 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +66 -0
  77. package/dist/types.js.map +1 -0
  78. package/dist/uuid.d.ts +5 -0
  79. package/dist/uuid.d.ts.map +1 -0
  80. package/dist/uuid.js +34 -0
  81. package/dist/uuid.js.map +1 -0
  82. package/package.json +44 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-schema.d.ts","sourceRoot":"","sources":["../../src/drizzle/audit-schema.ts"],"names":[],"mappings":"AAyCA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,M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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHlB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS,UAAU,CAAC,OAAO,mBAAmB,CAAC,EAChD,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;EA2B/B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAmDlE"}
@@ -0,0 +1,268 @@
1
+ // `@nodii/telemetry/drizzle` — canonical `<service>_audit_event` Drizzle
2
+ // schema fragment per `02-audit-doctrine.md § 3`.
3
+ //
4
+ // Each Nodii service owns its own `<service>_audit_event` table (e.g.
5
+ // `billing_audit_event`, `inventory_audit_event`). The library ships
6
+ // the schema FRAGMENT so every service runs the same migration shape.
7
+ //
8
+ // Usage:
9
+ //
10
+ // import { makeAuditEventTable, auditEventIndexes,
11
+ // auditEventPartitionDDL } from "@nodii/telemetry/drizzle";
12
+ //
13
+ // export const auditEvent = makeAuditEventTable("billing");
14
+ // export const auditEventIdx = auditEventIndexes(auditEvent, "billing");
15
+ //
16
+ // Notes:
17
+ // - Drizzle cannot declare `PARTITION BY RANGE (at)` natively. Services
18
+ // that want monthly partitioning (D32) must emit the table via the raw
19
+ // `auditEventPartitionDDL("billing")` instead of letting Drizzle's
20
+ // migration tool create it. The doctrine ships partitioning as a
21
+ // recommendation, not a hard requirement.
22
+ // - `actor_kind` and `outcome` use Postgres enums. The enum types are
23
+ // declared once per DB (`audit_actor_kind`, `audit_outcome`) — this
24
+ // module ships the literal DDL via `AUDIT_ACTOR_KIND_ENUM_DDL` +
25
+ // `AUDIT_OUTCOME_ENUM_DDL` so service migrations can run them once.
26
+ import { bigint, customType, index, inet, integer, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, uuid, } from "drizzle-orm/pg-core";
27
+ import { sql } from "drizzle-orm";
28
+ import { AUDIT_ACTOR_KINDS, AUDIT_OUTCOMES, } from "../audit-types";
29
+ export { AUDIT_ACTOR_KINDS, AUDIT_OUTCOMES };
30
+ /**
31
+ * `bytea` column for the audit-chain hash columns (`prev_hash`, `row_hash`).
32
+ * Drizzle 0.36 lacks a first-class `bytea` builder, so this defines one as a
33
+ * `customType`. Round-trips `Uint8Array` (or Node `Buffer`) through `node-pg`
34
+ * which serialises `bytea` as `Buffer`.
35
+ */
36
+ const bytea = customType({
37
+ dataType() {
38
+ return "bytea";
39
+ },
40
+ toDriver(value) {
41
+ return Buffer.isBuffer(value) ? value : Buffer.from(value);
42
+ },
43
+ fromDriver(value) {
44
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
45
+ },
46
+ });
47
+ /**
48
+ * `CREATE TYPE` DDL for the global `audit_actor_kind` enum. Run once per DB
49
+ * during service bootstrap before any `<svc>_audit_event` table is created.
50
+ * Wrapped in a `DO` block to be idempotent (Postgres lacks `CREATE TYPE IF
51
+ * NOT EXISTS`).
52
+ */
53
+ export const AUDIT_ACTOR_KIND_ENUM_DDL = `
54
+ DO $$ BEGIN
55
+ CREATE TYPE audit_actor_kind AS ENUM (
56
+ 'employee_user','tenant_user','tenant_customer','service','worker',
57
+ 'webhook_provider','external_system','agent','system','unknown'
58
+ );
59
+ EXCEPTION WHEN duplicate_object THEN NULL;
60
+ END $$;
61
+ `.trim();
62
+ /**
63
+ * `CREATE TYPE` DDL for the global `audit_outcome` enum. Run once per DB.
64
+ */
65
+ export const AUDIT_OUTCOME_ENUM_DDL = `
66
+ DO $$ BEGIN
67
+ CREATE TYPE audit_outcome AS ENUM (
68
+ 'success','failure','partial','queued','dry_run','denied_by_authz','denied_by_mfa'
69
+ );
70
+ EXCEPTION WHEN duplicate_object THEN NULL;
71
+ END $$;
72
+ `.trim();
73
+ /** Drizzle handle for the shared `audit_actor_kind` enum. */
74
+ export const auditActorKindEnum = pgEnum("audit_actor_kind", AUDIT_ACTOR_KINDS);
75
+ /** Drizzle handle for the shared `audit_outcome` enum. */
76
+ export const auditOutcomeEnum = pgEnum("audit_outcome", AUDIT_OUTCOMES);
77
+ /**
78
+ * Build the canonical `<serviceName>_audit_event` Drizzle table per
79
+ * `02-audit-doctrine.md § 3`. Column order, types, and nullability match the
80
+ * doctrine 1:1. `tenant_id` FK is `ON DELETE RESTRICT` per § 3.1 — the
81
+ * tenants table is never row-deleted.
82
+ *
83
+ * Indexes (§ 3 lines 156-167) are declared inline via the pgTable extras
84
+ * callback so Drizzle owns column→index attachment. Consumers receive the
85
+ * canonical 8 indexes on the returned table; if a service wants additional
86
+ * service-specific indexes they layer them on top after this call.
87
+ */
88
+ export function makeAuditEventTable(serviceName) {
89
+ const tableName = `${serviceName}_audit_event`;
90
+ return pgTable(tableName, {
91
+ id: uuid("id").primaryKey().default(sql `gen_random_uuid()`),
92
+ // Tenant + timing
93
+ tenantId: uuid("tenant_id").notNull(),
94
+ at: timestamp("at", { withTimezone: true }).notNull().default(sql `now()`),
95
+ // Actor (kind discriminator + dual-identity columns + structured stamp)
96
+ actorKind: auditActorKindEnum("actor_kind").notNull(),
97
+ actorId: text("actor_id"),
98
+ actorExternalId: text("actor_external_id"),
99
+ actorDisplay: text("actor_display"),
100
+ actorIp: inet("actor_ip"),
101
+ actorUserAgent: text("actor_user_agent"),
102
+ actor: jsonb("actor").$type(),
103
+ // What
104
+ action: text("action").notNull(),
105
+ resourceType: text("resource_type").notNull(),
106
+ resourceId: text("resource_id"),
107
+ resourceLabel: text("resource_label"),
108
+ secondaryResourceType: text("secondary_resource_type"),
109
+ secondaryResourceId: text("secondary_resource_id"),
110
+ // Outcome
111
+ outcome: auditOutcomeEnum("outcome").notNull().default("success"),
112
+ httpStatus: integer("http_status"),
113
+ grpcCode: text("grpc_code"),
114
+ errorCode: text("error_code"),
115
+ errorMessage: text("error_message"),
116
+ errorDetails: jsonb("error_details").$type(),
117
+ // State capture (§ 8)
118
+ before: jsonb("before").$type(),
119
+ after: jsonb("after").$type(),
120
+ patch: jsonb("patch").$type(),
121
+ changedFields: text("changed_fields").array(),
122
+ // Reason
123
+ reasonCode: text("reason_code"),
124
+ reasonText: text("reason_text"),
125
+ // Correlation
126
+ requestId: text("request_id"),
127
+ correlationId: text("correlation_id"),
128
+ traceId: text("trace_id"),
129
+ spanId: text("span_id"),
130
+ intentId: uuid("intent_id"),
131
+ sagaId: text("saga_id"),
132
+ stepId: text("step_id"),
133
+ idempotencyKey: text("idempotency_key"),
134
+ // Async context
135
+ queueName: text("queue_name"),
136
+ jobId: text("job_id"),
137
+ parentAuditEventId: uuid("parent_audit_event_id"),
138
+ // Read coalescing (§ 9)
139
+ readCount: integer("read_count"),
140
+ firstReadAt: timestamp("first_read_at", { withTimezone: true }),
141
+ lastReadAt: timestamp("last_read_at", { withTimezone: true }),
142
+ // Tamper evidence (§ 13 — opt-in via @nodii/audit-chain)
143
+ prevHash: bytea("prev_hash"),
144
+ rowHash: bytea("row_hash"),
145
+ tenantAuditSeq: bigint("tenant_audit_seq", { mode: "bigint" }),
146
+ // Extensible
147
+ metadata: jsonb("metadata")
148
+ .$type()
149
+ .notNull()
150
+ .default(sql `'{}'::jsonb`),
151
+ }, (t) => ({
152
+ tenantTime: index(`${serviceName}_audit_tenant_time`).on(t.tenantId, t.at),
153
+ resource: index(`${serviceName}_audit_resource`).on(t.tenantId, t.resourceType, t.resourceId, t.at),
154
+ actionOutcome: index(`${serviceName}_audit_action_outcome`).on(t.tenantId, t.action, t.outcome, t.at),
155
+ actor: index(`${serviceName}_audit_actor`).on(t.tenantId, t.actorId, t.at),
156
+ correlation: index(`${serviceName}_audit_correlation`).on(t.tenantId, t.correlationId),
157
+ trace: index(`${serviceName}_audit_trace`).on(t.tenantId, t.traceId),
158
+ saga: index(`${serviceName}_audit_saga`)
159
+ .on(t.tenantId, t.sagaId, t.at)
160
+ .where(sql `${t.sagaId} IS NOT NULL`),
161
+ tenantSeq: uniqueIndex(`${serviceName}_audit_tenant_seq`)
162
+ .on(t.tenantId, t.tenantAuditSeq)
163
+ .where(sql `${t.tenantAuditSeq} IS NOT NULL`),
164
+ }));
165
+ }
166
+ /**
167
+ * Re-exposes the canonical 8 indexes that `makeAuditEventTable` already
168
+ * declares inline. Useful for tests + tooling that want to introspect the
169
+ * named-index set without rebuilding the table.
170
+ *
171
+ * For runtime migration purposes you do NOT need to call this — Drizzle's
172
+ * own kit picks up the inline indexes when emitting CREATE INDEX statements.
173
+ */
174
+ export function auditEventIndexes(table, _serviceName) {
175
+ // The table builder's third callback's return value is stored on the
176
+ // table's `_.extraConfig`/symbol fields per drizzle internals. The safer
177
+ // public approach is to look at the result of `getTableConfig`'s indexes.
178
+ // Re-deriving the names directly avoids depending on private symbols.
179
+ void table;
180
+ void _serviceName;
181
+ const names = [
182
+ `${_serviceName}_audit_tenant_time`,
183
+ `${_serviceName}_audit_resource`,
184
+ `${_serviceName}_audit_action_outcome`,
185
+ `${_serviceName}_audit_actor`,
186
+ `${_serviceName}_audit_correlation`,
187
+ `${_serviceName}_audit_trace`,
188
+ `${_serviceName}_audit_saga`,
189
+ `${_serviceName}_audit_tenant_seq`,
190
+ ];
191
+ return {
192
+ tenantTime: { name: names[0] },
193
+ resource: { name: names[1] },
194
+ actionOutcome: { name: names[2] },
195
+ actor: { name: names[3] },
196
+ correlation: { name: names[4] },
197
+ trace: { name: names[5] },
198
+ saga: { name: names[6] },
199
+ tenantSeq: { name: names[7] },
200
+ };
201
+ }
202
+ /**
203
+ * Raw `CREATE TABLE ... PARTITION BY RANGE (at)` DDL for services that want
204
+ * monthly range partitioning per D32 + § 3 line 169. Drizzle's declarative
205
+ * migration cannot emit `PARTITION BY` — services that adopt this must run
206
+ * this DDL directly via their migration runner BEFORE Drizzle's
207
+ * `migrate(...)` would otherwise create the table.
208
+ *
209
+ * After the partitioned parent table exists, the consumer migration scripts
210
+ * create monthly partition children (`<svc>_audit_event_2026_06` etc.) per
211
+ * their retention/operational cadence.
212
+ *
213
+ * Indexes from `auditEventIndexes` are still created against the parent
214
+ * table — Postgres propagates them to existing + future child partitions.
215
+ */
216
+ export function auditEventPartitionDDL(serviceName) {
217
+ return `
218
+ CREATE TABLE ${serviceName}_audit_event (
219
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
220
+ tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE RESTRICT,
221
+ at TIMESTAMPTZ NOT NULL DEFAULT now(),
222
+ actor_kind audit_actor_kind NOT NULL,
223
+ actor_id TEXT,
224
+ actor_external_id TEXT,
225
+ actor_display TEXT,
226
+ actor_ip INET,
227
+ actor_user_agent TEXT,
228
+ actor JSONB,
229
+ action TEXT NOT NULL,
230
+ resource_type TEXT NOT NULL,
231
+ resource_id TEXT,
232
+ resource_label TEXT,
233
+ secondary_resource_type TEXT,
234
+ secondary_resource_id TEXT,
235
+ outcome audit_outcome NOT NULL DEFAULT 'success',
236
+ http_status INTEGER,
237
+ grpc_code TEXT,
238
+ error_code TEXT,
239
+ error_message TEXT,
240
+ error_details JSONB,
241
+ before JSONB,
242
+ after JSONB,
243
+ patch JSONB,
244
+ changed_fields TEXT[],
245
+ reason_code TEXT,
246
+ reason_text TEXT,
247
+ request_id TEXT,
248
+ correlation_id TEXT,
249
+ trace_id TEXT,
250
+ span_id TEXT,
251
+ intent_id UUID,
252
+ saga_id TEXT,
253
+ step_id TEXT,
254
+ idempotency_key TEXT,
255
+ queue_name TEXT,
256
+ job_id TEXT,
257
+ parent_audit_event_id UUID REFERENCES ${serviceName}_audit_event(id),
258
+ read_count INTEGER,
259
+ first_read_at TIMESTAMPTZ,
260
+ last_read_at TIMESTAMPTZ,
261
+ prev_hash BYTEA,
262
+ row_hash BYTEA,
263
+ tenant_audit_seq BIGINT,
264
+ metadata JSONB NOT NULL DEFAULT '{}'::jsonb
265
+ ) PARTITION BY RANGE (at);
266
+ `.trim();
267
+ }
268
+ //# sourceMappingURL=audit-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-schema.js","sourceRoot":"","sources":["../../src/drizzle/audit-schema.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,kDAAkD;AAClD,EAAE;AACF,sEAAsE;AACtE,qEAAqE;AACrE,sEAAsE;AACtE,EAAE;AACF,SAAS;AACT,EAAE;AACF,qDAAqD;AACrD,uEAAuE;AACvE,EAAE;AACF,8DAA8D;AAC9D,2EAA2E;AAC3E,EAAE;AACF,SAAS;AACT,0EAA0E;AAC1E,2EAA2E;AAC3E,uEAAuE;AACvE,qEAAqE;AACrE,8CAA8C;AAC9C,wEAAwE;AACxE,wEAAwE;AACxE,qEAAqE;AACrE,wEAAwE;AAExE,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,EACL,IAAI,EACJ,OAAO,EACP,KAAK,EACL,MAAM,EACN,OAAO,EACP,IAAI,EACJ,SAAS,EACT,WAAW,EACX,IAAI,GACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,iBAAiB,EACjB,cAAc,GAGf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAC;AAG7C;;;;;GAKG;AACH,MAAM,KAAK,GAAG,UAAU,CAA2C;IACjE,QAAQ;QACN,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,QAAQ,CAAC,KAAK;QACZ,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IACD,UAAU,CAAC,KAAa;QACtB,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC1E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YAAY,oBAAoB;QACnC,GAAG,YAAY,cAAc;QAC7B,GAAG,YAAY,aAAa;QAC5B,GAAG,YAAY,mBAAmB;KAC1B,CAAC;IACX,OAAO;QACL,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QAC9B,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QAC5B,aAAa,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QACjC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QACzB,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QAC/B,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QACzB,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QACxB,SAAS,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;KACrB,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAmB;IACxD,OAAO;eACM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gDAuCsB,WAAW;;;;;;;;;CAS1D,CAAC,IAAI,EAAE,CAAC;AACT,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { AUDIT_ACTOR_KINDS, AUDIT_ACTOR_KIND_ENUM_DDL, AUDIT_OUTCOMES, AUDIT_OUTCOME_ENUM_DDL, auditActorKindEnum, auditEventIndexes, auditEventPartitionDDL, auditOutcomeEnum, makeAuditEventTable, } from "./audit-schema";
2
+ export type { ActorKind, AuditOutcome } from "./audit-schema";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ // `@nodii/telemetry/drizzle` — Drizzle schema fragments for the
2
+ // per-service audit_event table. Lives behind a subpath so consumers
3
+ // who don't use Drizzle don't transitively pull `drizzle-orm`.
4
+ export { AUDIT_ACTOR_KINDS, AUDIT_ACTOR_KIND_ENUM_DDL, AUDIT_OUTCOMES, AUDIT_OUTCOME_ENUM_DDL, auditActorKindEnum, auditEventIndexes, auditEventPartitionDDL, auditOutcomeEnum, makeAuditEventTable, } from "./audit-schema";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,qEAAqE;AACrE,+DAA+D;AAE/D,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,22 @@
1
- export declare const LIB_NAME = "telemetry";
2
- export declare const VERSION = "0.0.1";
1
+ export { initTelemetry } from "./init";
2
+ export { forceFlush, getOtlpAdapterHandle, installOtlpAdapter, shutdownOtlpAdapter, } from "./otlp-adapter";
3
+ export type { OtlpAdapterHandle, OtlpAdapterConfig } from "./otlp-adapter";
4
+ export { logger } from "./logger";
5
+ export { tracer, withSpanAttributes, getSagaTracer } from "./tracer";
6
+ export type { Span, SpanKind, SpanRecord, SpanStatus } from "./tracer";
7
+ export { metrics, MetricVocabularyError } from "./metrics";
8
+ export type { CounterHandle, HistogramHandle, MetricRegistration, } from "./metrics";
9
+ export { _getAuditChain, _resetAuditChainForTests, _resetAuditWriterForTests, _setAuditChain, _setAuditWriter, audit, AUDIT_ACTOR_KINDS, AUDIT_OUTCOMES, } from "./audit";
10
+ export type { ActorKind, ActorStamp, AuditArgs, AuditChainAdapter, AuditEvent, AuditEventRow, AuditOutcome, AuditWriter, } from "./audit";
11
+ export { TelemetryAuditWriterMissing } from "./audit";
12
+ export { configureTelemetry } from "./configure";
13
+ export type { ConfigureTelemetryOptions } from "./configure";
14
+ export { intent, IntentTypeNotRegistered } from "./intent";
15
+ export { agentInvocable, readAgentRegistry, AGENT_INVOCABLE_METADATA, } from "./agent-invocable";
16
+ export { getContext, requireContext, withContext, } from "./context";
17
+ export { isPiiFieldName, redactString, redactFields, PII_FIELD_NAMES, } from "./redaction";
18
+ export { uuidv7, isUuidv7 } from "./uuid";
19
+ export { TelemetryNotInitialized } from "./types";
20
+ export type { ActorType, AgentInvocableAuthTier, AgentInvocableConfig, AgentInvocableIdempotency, AgentInvocableMode, AgentInvocableRateLimit, AgentInvocableSideEffect, AutoInstrumentationConfig, ErrorHandlingConfig, ExportFailureReason, InitTelemetryConfig, IntentTypeDefinition, IntentTypeRegistry, LogEnvelope, LogLevel, MetricFamily, MetricVocabularyEntry, MetricVocabularyRegistry, NodiiContext, ResourceAttributes, SamplingConfig, } from "./types";
21
+ export { DEFAULT_SAMPLING_CONFIG, METRIC_FAMILIES, AGENT_INVOCABLE_SIDE_EFFECTS, } from "./types";
3
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ,cAAc,CAAC;AACpC,eAAO,MAAM,OAAO,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,aAAa,EAA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rB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,YAAY,EACV,SAAS,EACT,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,EACzB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,qBAAqB,EACrB,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,4BAA4B,GAC7B,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,33 @@
1
- // @nodii/telemetry — placeholder at v0.0.1.
2
- // Implementation lands at v0.1.0 per the locked feature_doc.
1
+ // @nodii/telemetry — public barrel.
3
2
  //
4
- // Spec: https://planning.dev.nucleus-cloud.in/api/v1/feature-docs?serviceId=nodii-libs&docKey=telemetry
5
- export const LIB_NAME = "telemetry";
6
- export const VERSION = "0.0.1";
3
+ // Spec: planning hub feature_doc serviceId=nodii-libs docKey=telemetry v3
4
+ //
5
+ // Use subpath imports for tree-shaking:
6
+ // - @nodii/telemetry/grpc — gRPC interceptor + client wrapper
7
+ // - @nodii/telemetry/bullmq — BullMQ producer + consumer wrappers
8
+ // - @nodii/telemetry/outbox — Outbox emit + drainer instrumentation
9
+ // - @nodii/telemetry/system-process — System-process adapter
10
+ // - @nodii/telemetry/lambda — Lambda lifecycle wrapper
11
+ //
12
+ // Top-level barrel re-exports the public surface so the common-case
13
+ // import works:
14
+ //
15
+ // import { initTelemetry, logger, tracer, metrics, audit, intent,
16
+ // agentInvocable, withSpanAttributes, getSagaTracer,
17
+ // type NodiiContext } from '@nodii/telemetry';
18
+ export { initTelemetry } from "./init";
19
+ export { forceFlush, getOtlpAdapterHandle, installOtlpAdapter, shutdownOtlpAdapter, } from "./otlp-adapter";
20
+ export { logger } from "./logger";
21
+ export { tracer, withSpanAttributes, getSagaTracer } from "./tracer";
22
+ export { metrics, MetricVocabularyError } from "./metrics";
23
+ export { _getAuditChain, _resetAuditChainForTests, _resetAuditWriterForTests, _setAuditChain, _setAuditWriter, audit, AUDIT_ACTOR_KINDS, AUDIT_OUTCOMES, } from "./audit";
24
+ export { TelemetryAuditWriterMissing } from "./audit";
25
+ export { configureTelemetry } from "./configure";
26
+ export { intent, IntentTypeNotRegistered } from "./intent";
27
+ export { agentInvocable, readAgentRegistry, AGENT_INVOCABLE_METADATA, } from "./agent-invocable";
28
+ export { getContext, requireContext, withContext, } from "./context";
29
+ export { isPiiFieldName, redactString, redactFields, PII_FIELD_NAMES, } from "./redaction";
30
+ export { uuidv7, isUuidv7 } from "./uuid";
31
+ export { TelemetryNotInitialized } from "./types";
32
+ export { DEFAULT_SAMPLING_CONFIG, METRIC_FAMILIES, AGENT_INVOCABLE_SIDE_EFFECTS, } from "./types";
7
33
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,6DAA6D;AAC7D,EAAE;AACF,wGAAwG;AAExG,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,EAAE;AACF,0EAA0E;AAC1E,EAAE;AACF,wCAAwC;AACxC,2EAA2E;AAC3E,6EAA6E;AAC7E,+EAA+E;AAC/E,gEAAgE;AAChE,kEAAkE;AAClE,EAAE;AACF,oEAAoE;AACpE,gBAAgB;AAChB,EAAE;AACF,oEAAoE;AACpE,gEAAgE;AAChE,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAErE,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAM3D,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,eAAe,EACf,KAAK,EACL,iBAAiB,EACjB,cAAc,GACf,MAAM,SAAS,CAAC;AAWjB,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,UAAU,EACV,cAAc,EACd,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAwBlD,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,4BAA4B,GAC7B,MAAM,SAAS,CAAC"}
package/dist/init.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { type AutoInstrumentationConfig, type ErrorHandlingConfig, type InitTelemetryConfig, type IntentTypeRegistry, type MetricVocabularyRegistry, type SamplingConfig } from "./types";
2
+ /** Snapshot of the resolved init config that runtime modules read from. */
3
+ export interface ResolvedTelemetryConfig {
4
+ serviceName: string;
5
+ env: string;
6
+ serviceVersion?: string;
7
+ deploymentRegion?: string;
8
+ otlpEndpoint?: string;
9
+ vocabularyRegistry: MetricVocabularyRegistry;
10
+ intentTypes: IntentTypeRegistry;
11
+ autoInstrumentation: Required<AutoInstrumentationConfig>;
12
+ samplingConfig: SamplingConfig;
13
+ errorHandling: ErrorHandlingConfig;
14
+ resourceAttributes: Record<string, string | number | boolean>;
15
+ }
16
+ /**
17
+ * Public bootstrap. Per D152 — call once at process start. Subsequent
18
+ * calls warn-log + no-op.
19
+ *
20
+ * When `otlpEndpoint` is supplied (or `NODII_TELEMETRY_OTLP_ENDPOINT`
21
+ * env var is set), real OTLP gRPC exporters are wired up by
22
+ * `installOtlpAdapter()` per D153 + D154. Spans, logs, and metrics
23
+ * flow into the configured collector immediately.
24
+ *
25
+ * If `disableOtlp: true` is passed, the no-op emitters/sinks/backends
26
+ * stay in place — for tests that want to assert SDK semantics without
27
+ * a live collector.
28
+ */
29
+ export declare function initTelemetry(config: InitTelemetryConfig): void;
30
+ /**
31
+ * SDK-internal accessor. Throws `TelemetryNotInitialized` if called
32
+ * before `initTelemetry()`. Every public API funnels through this.
33
+ */
34
+ export declare function requireTelemetry(): ResolvedTelemetryConfig;
35
+ /** Returns null when not initialized — for SDK internals that can no-op. */
36
+ export declare function getTelemetryOrNull(): ResolvedTelemetryConfig | null;
37
+ /** Test-only reset. NOT exported through the public barrel. */
38
+ export declare function _resetForTests(): void;
39
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,yBAAyB,EAE9B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EAEpB,MAAM,SAAS,CAAC;AAEjB,2EAA2E;AAC3E,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,wBAAwB,CAAC;IAC7C,WAAW,EAAE,kBAAkB,CAAC;IAChC,mBAAmB,EAAE,QAAQ,CAAC,yBAAyB,CAAC,CAAC;IACzD,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,mBAAmB,CAAC;IACnC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAC/D;AA8BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAqD/D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,uBAAuB,CAK1D;AAED,4EAA4E;AAC5E,wBAAgB,kBAAkB,IAAI,uBAAuB,GAAG,IAAI,CAEnE;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
package/dist/init.js ADDED
@@ -0,0 +1,114 @@
1
+ // Bootstrap — `initTelemetry()`. Per D152: single explicit init at
2
+ // process start, NOT side-effect import.
3
+ //
4
+ // Behavior:
5
+ // - First call: validates config, stores it in a process-local
6
+ // singleton, marks the SDK ready.
7
+ // - Subsequent calls: warn-log + no-op (per § 5.1).
8
+ // - Any public-API call before init: throws `TelemetryNotInitialized`.
9
+ import { installOtlpAdapter } from "./otlp-adapter";
10
+ import { DEFAULT_SAMPLING_CONFIG, TelemetryNotInitialized, } from "./types";
11
+ /** D154 defaults. */
12
+ const AUTO_INSTR_DEFAULTS = {
13
+ httpServer: true,
14
+ httpClient: true,
15
+ grpcServer: true,
16
+ grpcClient: true,
17
+ bullmqProducer: true,
18
+ bullmqConsumer: true,
19
+ pgQuerySpans: true,
20
+ hostMetrics: true,
21
+ logAutoStamping: true,
22
+ resourceAttributes: true,
23
+ piiRedaction: true,
24
+ redisSpans: false,
25
+ dnsLookups: false,
26
+ fileSystem: false,
27
+ pgDetailedStatement: false,
28
+ };
29
+ /** D153 defaults. */
30
+ const ERROR_HANDLING_DEFAULTS = {
31
+ otlpSendingQueueSize: 5000,
32
+ dropOnFull: true,
33
+ };
34
+ /** Process-local singleton; null until `initTelemetry()` runs. */
35
+ let resolved = null;
36
+ /**
37
+ * Public bootstrap. Per D152 — call once at process start. Subsequent
38
+ * calls warn-log + no-op.
39
+ *
40
+ * When `otlpEndpoint` is supplied (or `NODII_TELEMETRY_OTLP_ENDPOINT`
41
+ * env var is set), real OTLP gRPC exporters are wired up by
42
+ * `installOtlpAdapter()` per D153 + D154. Spans, logs, and metrics
43
+ * flow into the configured collector immediately.
44
+ *
45
+ * If `disableOtlp: true` is passed, the no-op emitters/sinks/backends
46
+ * stay in place — for tests that want to assert SDK semantics without
47
+ * a live collector.
48
+ */
49
+ export function initTelemetry(config) {
50
+ if (resolved) {
51
+ // eslint-disable-next-line no-console
52
+ console.warn("[@nodii/telemetry] initTelemetry() called more than once; ignoring subsequent call.");
53
+ return;
54
+ }
55
+ if (!config.serviceName) {
56
+ throw new Error("initTelemetry: `serviceName` is required.");
57
+ }
58
+ if (!config.env) {
59
+ throw new Error("initTelemetry: `env` is required.");
60
+ }
61
+ const otlpEndpoint = config.otlpEndpoint ?? process.env.NODII_TELEMETRY_OTLP_ENDPOINT;
62
+ resolved = {
63
+ serviceName: config.serviceName,
64
+ env: config.env,
65
+ serviceVersion: config.serviceVersion,
66
+ deploymentRegion: config.deploymentRegion,
67
+ otlpEndpoint,
68
+ vocabularyRegistry: config.vocabularyRegistry ?? {},
69
+ intentTypes: config.intentTypes ?? {},
70
+ autoInstrumentation: {
71
+ ...AUTO_INSTR_DEFAULTS,
72
+ ...config.autoInstrumentation,
73
+ },
74
+ samplingConfig: config.samplingConfig ?? DEFAULT_SAMPLING_CONFIG,
75
+ errorHandling: {
76
+ ...ERROR_HANDLING_DEFAULTS,
77
+ ...config.errorHandling,
78
+ },
79
+ resourceAttributes: config.resourceAttributes ?? {},
80
+ };
81
+ // D153/D154 — wire real OTLP exporters when an endpoint is present
82
+ // and OTLP isn't explicitly disabled. The adapter replaces the no-op
83
+ // SpanEmitter / LogSink / MetricsBackend with real OTel SDK pipelines.
84
+ if (otlpEndpoint && !config.disableOtlp) {
85
+ installOtlpAdapter({
86
+ serviceName: resolved.serviceName,
87
+ env: resolved.env,
88
+ serviceVersion: resolved.serviceVersion,
89
+ deploymentRegion: resolved.deploymentRegion,
90
+ otlpEndpoint,
91
+ errorHandling: resolved.errorHandling,
92
+ resourceAttributes: resolved.resourceAttributes,
93
+ });
94
+ }
95
+ }
96
+ /**
97
+ * SDK-internal accessor. Throws `TelemetryNotInitialized` if called
98
+ * before `initTelemetry()`. Every public API funnels through this.
99
+ */
100
+ export function requireTelemetry() {
101
+ if (!resolved) {
102
+ throw new TelemetryNotInitialized();
103
+ }
104
+ return resolved;
105
+ }
106
+ /** Returns null when not initialized — for SDK internals that can no-op. */
107
+ export function getTelemetryOrNull() {
108
+ return resolved;
109
+ }
110
+ /** Test-only reset. NOT exported through the public barrel. */
111
+ export function _resetForTests() {
112
+ resolved = null;
113
+ }
114
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,yCAAyC;AACzC,EAAE;AACF,YAAY;AACZ,iEAAiE;AACjE,sCAAsC;AACtC,sDAAsD;AACtD,yEAAyE;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAEL,uBAAuB,EAMvB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAiBjB,qBAAqB;AACrB,MAAM,mBAAmB,GAAwC;IAC/D,UAAU,EAAE,IA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E;QACnD,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;QACrC,mBAAmB,EAAE;YACnB,GAAG,mBAAmB;YACtB,GAAG,MAAM,CAAC,mBAAmB;SAC9B;QACD,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,uBAAuB;QAChE,aAAa,EAAE;YACb,GAAG,uBAAuB;YAC1B,GAAG,MAAM,CAAC,aAAa;SACxB;QACD,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,IAAI,EAAE;KACpD,CAAC;IAEF,mEAAmE;IACnE,qEAAqE;IACrE,uEAAuE;IACvE,IAAI,YAAY,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACxC,kBAAkB,CAAC;YACjB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;YAC3C,YAAY;YACZ,aAAa,EAAE,QAAQ,CAAC,aAAa;YACrC,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;SAChD,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,kBAAkB;IAChC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,cAAc;IAC5B,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC"}
@@ -0,0 +1,21 @@
1
+ declare function begin(typeName: string, payload?: Record<string, unknown>): Promise<string>;
2
+ declare function complete(id: string, result?: Record<string, unknown>): Promise<void>;
3
+ declare function abandon(id: string, reason: string): Promise<void>;
4
+ declare function progress(_id: string, _payload?: Record<string, unknown>): void;
5
+ declare function current(): string | null;
6
+ /** Thrown by `intent.begin` when the type isn't in the registry (D155 HARD). */
7
+ export declare class IntentTypeNotRegistered extends Error {
8
+ readonly typeName: string;
9
+ constructor(typeName: string);
10
+ }
11
+ /** Test-only stack reset. */
12
+ export declare function _resetIntentStackForTests(): void;
13
+ export declare const intent: {
14
+ readonly begin: typeof begin;
15
+ readonly progress: typeof progress;
16
+ readonly complete: typeof complete;
17
+ readonly abandon: typeof abandon;
18
+ readonly current: typeof current;
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=intent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../src/intent.ts"],"names":[],"mappings":"AAoCA,iBAAe,KAAK,CAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,iBAAe,QAAQ,CACrB,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,iBAAe,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAGvE;AAED,iBAAS,OAAO,IAAI,MAAM,GAAG,IAAI,CAEhC;AAsBD,gFAAgF;AAChF,qBAAa,uBAAwB,SAAQ,KAAK;aACpB,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM;CAM7C;AAED,6BAA6B;AAC7B,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD;AAED,eAAO,MAAM,MAAM;;;;;;CAMT,CAAC"}