@empire-builder-kit/runtime 1.0.0-beta.9 → 1.0.0-rc.2

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 (218) hide show
  1. package/NOTICE +6 -0
  2. package/package.json +93 -3
  3. package/src/api-contract/artifacts.d.ts +67 -0
  4. package/src/api-contract/artifacts.js +349 -0
  5. package/src/api-contract/artifacts.js.map +1 -0
  6. package/src/api-contract/client.d.ts +79 -0
  7. package/src/api-contract/client.js +561 -0
  8. package/src/api-contract/client.js.map +1 -0
  9. package/src/api-contract/errors.d.ts +7 -0
  10. package/src/api-contract/errors.js +11 -0
  11. package/src/api-contract/errors.js.map +1 -0
  12. package/src/api-contract/index.d.ts +9 -0
  13. package/src/api-contract/index.js +10 -0
  14. package/src/api-contract/index.js.map +1 -0
  15. package/src/api-contract/operation.d.ts +118 -0
  16. package/src/api-contract/operation.js +609 -0
  17. package/src/api-contract/operation.js.map +1 -0
  18. package/src/api-contract/schema.d.ts +81 -0
  19. package/src/api-contract/schema.js +313 -0
  20. package/src/api-contract/schema.js.map +1 -0
  21. package/src/api-contract/server.d.ts +77 -0
  22. package/src/api-contract/server.js +466 -0
  23. package/src/api-contract/server.js.map +1 -0
  24. package/src/async-work/contract.d.ts +17 -0
  25. package/src/async-work/contract.js +105 -0
  26. package/src/async-work/contract.js.map +1 -0
  27. package/src/async-work/idempotency.d.ts +123 -0
  28. package/src/async-work/idempotency.js +167 -0
  29. package/src/async-work/idempotency.js.map +1 -0
  30. package/src/async-work/index.d.ts +8 -0
  31. package/src/async-work/index.js +9 -0
  32. package/src/async-work/index.js.map +1 -0
  33. package/src/async-work/provider.d.ts +90 -0
  34. package/src/async-work/provider.js +155 -0
  35. package/src/async-work/provider.js.map +1 -0
  36. package/src/async-work/recovery.d.ts +103 -0
  37. package/src/async-work/recovery.js +291 -0
  38. package/src/async-work/recovery.js.map +1 -0
  39. package/src/async-work/schedule.d.ts +117 -0
  40. package/src/async-work/schedule.js +279 -0
  41. package/src/async-work/schedule.js.map +1 -0
  42. package/src/async-work/sqs.d.ts +133 -0
  43. package/src/async-work/sqs.js +280 -0
  44. package/src/async-work/sqs.js.map +1 -0
  45. package/src/async-work/webhook.d.ts +60 -0
  46. package/src/async-work/webhook.js +178 -0
  47. package/src/async-work/webhook.js.map +1 -0
  48. package/src/async-work/workflow.d.ts +98 -0
  49. package/src/async-work/workflow.js +225 -0
  50. package/src/async-work/workflow.js.map +1 -0
  51. package/src/auth-backend.d.ts +12 -2
  52. package/src/auth-backend.js +30 -18
  53. package/src/auth-backend.js.map +1 -1
  54. package/src/authorization/admission.d.ts +30 -0
  55. package/src/authorization/admission.js +87 -0
  56. package/src/authorization/admission.js.map +1 -0
  57. package/src/authorization/approval.d.ts +99 -0
  58. package/src/authorization/approval.js +249 -0
  59. package/src/authorization/approval.js.map +1 -0
  60. package/src/authorization/audit.d.ts +35 -0
  61. package/src/authorization/audit.js +35 -0
  62. package/src/authorization/audit.js.map +1 -0
  63. package/src/authorization/delegation.d.ts +149 -0
  64. package/src/authorization/delegation.js +401 -0
  65. package/src/authorization/delegation.js.map +1 -0
  66. package/src/authorization/errors.d.ts +32 -0
  67. package/src/authorization/errors.js +153 -0
  68. package/src/authorization/errors.js.map +1 -0
  69. package/src/authorization/evaluator.d.ts +39 -0
  70. package/src/authorization/evaluator.js +199 -0
  71. package/src/authorization/evaluator.js.map +1 -0
  72. package/src/authorization/index.d.ts +14 -0
  73. package/src/authorization/index.js +15 -0
  74. package/src/authorization/index.js.map +1 -0
  75. package/src/authorization/machine-token.d.ts +87 -0
  76. package/src/authorization/machine-token.js +201 -0
  77. package/src/authorization/machine-token.js.map +1 -0
  78. package/src/authorization/machine.d.ts +32 -0
  79. package/src/authorization/machine.js +41 -0
  80. package/src/authorization/machine.js.map +1 -0
  81. package/src/authorization/model.d.ts +112 -0
  82. package/src/authorization/model.js +112 -0
  83. package/src/authorization/model.js.map +1 -0
  84. package/src/canonical-json.cjs +157 -0
  85. package/src/canonical-json.d.cts +26 -0
  86. package/src/canonical-json.d.ts +18 -0
  87. package/src/canonical-json.js +125 -0
  88. package/src/canonical-json.js.map +1 -0
  89. package/src/configuration/contract.d.ts +107 -0
  90. package/src/configuration/contract.js +461 -0
  91. package/src/configuration/contract.js.map +1 -0
  92. package/src/configuration/index.d.ts +3 -0
  93. package/src/configuration/index.js +4 -0
  94. package/src/configuration/index.js.map +1 -0
  95. package/src/configuration/provider.d.ts +59 -0
  96. package/src/configuration/provider.js +198 -0
  97. package/src/configuration/provider.js.map +1 -0
  98. package/src/configuration/rollout-evaluator.cjs +54 -0
  99. package/src/configuration/rollout-evaluator.d.cts +26 -0
  100. package/src/configuration/rollout-evaluator.d.ts +18 -0
  101. package/src/configuration/rollout-evaluator.js +38 -0
  102. package/src/configuration/rollout-evaluator.js.map +1 -0
  103. package/src/configuration/rollout-key.cjs +38 -0
  104. package/src/configuration/rollout-key.d.cts +14 -0
  105. package/src/configuration/rollout-key.d.ts +10 -0
  106. package/src/configuration/rollout-key.js +26 -0
  107. package/src/configuration/rollout-key.js.map +1 -0
  108. package/src/configuration/rollout.d.ts +60 -0
  109. package/src/configuration/rollout.js +42 -0
  110. package/src/configuration/rollout.js.map +1 -0
  111. package/src/data-lifecycle/contract.d.ts +33 -0
  112. package/src/data-lifecycle/contract.js +118 -0
  113. package/src/data-lifecycle/contract.js.map +1 -0
  114. package/src/data-lifecycle/event.d.ts +28 -0
  115. package/src/data-lifecycle/event.js +76 -0
  116. package/src/data-lifecycle/event.js.map +1 -0
  117. package/src/data-lifecycle/evidence.d.ts +65 -0
  118. package/src/data-lifecycle/evidence.js +162 -0
  119. package/src/data-lifecycle/evidence.js.map +1 -0
  120. package/src/data-lifecycle/holds.d.ts +29 -0
  121. package/src/data-lifecycle/holds.js +124 -0
  122. package/src/data-lifecycle/holds.js.map +1 -0
  123. package/src/data-lifecycle/index.d.ts +8 -0
  124. package/src/data-lifecycle/index.js +9 -0
  125. package/src/data-lifecycle/index.js.map +1 -0
  126. package/src/data-lifecycle/policy.d.ts +16 -0
  127. package/src/data-lifecycle/policy.js +79 -0
  128. package/src/data-lifecycle/policy.js.map +1 -0
  129. package/src/data-lifecycle/restore.d.ts +90 -0
  130. package/src/data-lifecycle/restore.js +336 -0
  131. package/src/data-lifecycle/restore.js.map +1 -0
  132. package/src/data-lifecycle/retention.d.ts +57 -0
  133. package/src/data-lifecycle/retention.js +232 -0
  134. package/src/data-lifecycle/retention.js.map +1 -0
  135. package/src/data-lifecycle/rights.d.ts +171 -0
  136. package/src/data-lifecycle/rights.js +533 -0
  137. package/src/data-lifecycle/rights.js.map +1 -0
  138. package/src/database.d.ts +36 -0
  139. package/src/database.js +119 -0
  140. package/src/database.js.map +1 -0
  141. package/src/deterministic-order.cjs +16 -0
  142. package/src/deterministic-order.d.cts +9 -0
  143. package/src/deterministic-order.d.ts +7 -0
  144. package/src/deterministic-order.js +10 -0
  145. package/src/deterministic-order.js.map +1 -0
  146. package/src/events.d.ts +28 -19
  147. package/src/events.js +171 -66
  148. package/src/events.js.map +1 -1
  149. package/src/index.d.ts +7 -1
  150. package/src/index.js +24 -0
  151. package/src/index.js.map +1 -1
  152. package/src/lambda.d.ts +8 -2
  153. package/src/lambda.js +100 -39
  154. package/src/lambda.js.map +1 -1
  155. package/src/logging.d.ts +95 -36
  156. package/src/logging.js +460 -62
  157. package/src/logging.js.map +1 -1
  158. package/src/observability.d.ts +80 -18
  159. package/src/observability.js +252 -61
  160. package/src/observability.js.map +1 -1
  161. package/src/performance/index.d.ts +1 -0
  162. package/src/performance/index.js +2 -0
  163. package/src/performance/index.js.map +1 -0
  164. package/src/performance/protected-load-endpoint.d.ts +140 -0
  165. package/src/performance/protected-load-endpoint.js +462 -0
  166. package/src/performance/protected-load-endpoint.js.map +1 -0
  167. package/src/rds-global-ca-bundle.d.ts +1 -0
  168. package/src/rds-global-ca-bundle.js +2742 -0
  169. package/src/rds-global-ca-bundle.js.map +1 -0
  170. package/src/reliability/burn.d.ts +39 -0
  171. package/src/reliability/burn.js +102 -0
  172. package/src/reliability/burn.js.map +1 -0
  173. package/src/reliability/contract.d.ts +5 -0
  174. package/src/reliability/contract.js +317 -0
  175. package/src/reliability/contract.js.map +1 -0
  176. package/src/reliability/incident.d.ts +16 -0
  177. package/src/reliability/incident.js +562 -0
  178. package/src/reliability/incident.js.map +1 -0
  179. package/src/reliability/index.d.ts +5 -0
  180. package/src/reliability/index.js +6 -0
  181. package/src/reliability/index.js.map +1 -0
  182. package/src/reliability/model.d.ts +191 -0
  183. package/src/reliability/model.fixtures.d.ts +2 -0
  184. package/src/reliability/model.fixtures.js +57 -0
  185. package/src/reliability/model.fixtures.js.map +1 -0
  186. package/src/reliability/model.js +2 -0
  187. package/src/reliability/model.js.map +1 -0
  188. package/src/reliability/slo.d.ts +9 -0
  189. package/src/reliability/slo.js +74 -0
  190. package/src/reliability/slo.js.map +1 -0
  191. package/src/request-context.d.ts +57 -15
  192. package/src/request-context.js +116 -36
  193. package/src/request-context.js.map +1 -1
  194. package/src/safe-reference.cjs +57 -0
  195. package/src/safe-reference.d.cts +25 -0
  196. package/src/safe-reference.d.ts +11 -0
  197. package/src/safe-reference.js +46 -0
  198. package/src/safe-reference.js.map +1 -0
  199. package/src/secrets/contract.d.ts +99 -0
  200. package/src/secrets/contract.js +238 -0
  201. package/src/secrets/contract.js.map +1 -0
  202. package/src/secrets/index.d.ts +4 -0
  203. package/src/secrets/index.js +5 -0
  204. package/src/secrets/index.js.map +1 -0
  205. package/src/secrets/observability.d.ts +14 -0
  206. package/src/secrets/observability.js +100 -0
  207. package/src/secrets/observability.js.map +1 -0
  208. package/src/secrets/personal.d.ts +48 -0
  209. package/src/secrets/personal.js +332 -0
  210. package/src/secrets/personal.js.map +1 -0
  211. package/src/secrets/resolver.d.ts +125 -0
  212. package/src/secrets/resolver.js +602 -0
  213. package/src/secrets/resolver.js.map +1 -0
  214. package/src/secrets/sensitive-patterns.cjs +84 -0
  215. package/src/secrets/sensitive-patterns.d.cts +62 -0
  216. package/src/secrets/sensitive-patterns.d.ts +40 -0
  217. package/src/secrets/sensitive-patterns.js +60 -0
  218. package/src/secrets/sensitive-patterns.js.map +1 -0
@@ -0,0 +1,191 @@
1
+ import type { AlarmDefinition, AlarmSeverity } from '../observability.js';
2
+ import type { ApprovalRequest } from '../authorization/approval.js';
3
+ export declare const RELIABILITY_SCHEMA_VERSION: 1;
4
+ export type SliType = 'availability' | 'latency' | 'freshness' | 'durability' | 'correctness' | 'deadline';
5
+ export type SloWindowKind = 'rolling' | 'calendar';
6
+ export type SloTier = 'critical' | 'important' | 'standard';
7
+ export type ReliabilityMeasurementProvider = 'direct-cloudwatch-metric-math' | 'application-signals';
8
+ export interface ReliabilityCostEstimate {
9
+ currency: 'USD';
10
+ monthly: number;
11
+ provenance: 'estimate';
12
+ }
13
+ export interface ReliabilityProviderDecision {
14
+ applicationSignalsCoverage: readonly string[];
15
+ basis: string;
16
+ cost: ReliabilityCostEstimate;
17
+ directMetricMathCoverage: readonly string[];
18
+ reviewedAt: string;
19
+ selected: ReliabilityMeasurementProvider;
20
+ }
21
+ export interface SloIndicator {
22
+ goodEventDefinition: string;
23
+ metricRef: string;
24
+ threshold?: number;
25
+ type: SliType;
26
+ unit?: string;
27
+ validEventDefinition: string;
28
+ }
29
+ export interface SloLowTrafficPolicy {
30
+ mode: 'data-insufficient' | 'synthetic';
31
+ syntheticRef?: string;
32
+ }
33
+ export interface SloBurnThresholds {
34
+ fast: number;
35
+ slow: number;
36
+ warning: number;
37
+ }
38
+ export interface SloMinimumValidEvents {
39
+ diagnosticSample: number;
40
+ fastBurnWindow: number;
41
+ objectiveWindow: number;
42
+ slowBurnWindow: number;
43
+ }
44
+ export interface SloReferences {
45
+ alarmIds: readonly string[];
46
+ dashboardRef: string;
47
+ runbookRef: string;
48
+ syntheticRef?: string;
49
+ }
50
+ export interface SloObjective {
51
+ allowedExclusionPolicyRef: string;
52
+ burn: SloBurnThresholds;
53
+ effectiveAt: string;
54
+ feature: string;
55
+ id: string;
56
+ indicator: SloIndicator;
57
+ journey: string;
58
+ lowTraffic: SloLowTrafficPolicy;
59
+ minimumValidEvents: SloMinimumValidEvents;
60
+ owner: string;
61
+ references: SloReferences;
62
+ target: number;
63
+ tier: SloTier;
64
+ window: {
65
+ days: number;
66
+ kind: SloWindowKind;
67
+ };
68
+ }
69
+ export interface SliceReliabilityContract {
70
+ escalationRouteKey: string;
71
+ objectives: readonly SloObjective[];
72
+ owner: string;
73
+ providerDecision: ReliabilityProviderDecision;
74
+ schemaVersion: typeof RELIABILITY_SCHEMA_VERSION;
75
+ slice: string;
76
+ }
77
+ export type AlarmMissingDataBehavior = 'breaching' | 'notBreaching' | 'ignore' | 'missing';
78
+ export interface AlarmRegistrationMetadata {
79
+ businessSymptom: string;
80
+ condition: string;
81
+ dependencyAlarmIds: readonly string[];
82
+ escalationRouteKey: string;
83
+ expectedFalseNegativeRisk: string;
84
+ expectedFalsePositiveRisk: string;
85
+ id: string;
86
+ missingData: AlarmMissingDataBehavior;
87
+ owner: string;
88
+ runbookRef: string;
89
+ severity: AlarmSeverity;
90
+ testRef: string;
91
+ }
92
+ export interface RegisteredAlarmDefinition extends AlarmDefinition {
93
+ registration: AlarmRegistrationMetadata;
94
+ }
95
+ export type SloEvaluationState = 'data-insufficient' | 'synthetic-healthy' | 'synthetic-failed' | 'healthy' | 'warning' | 'slow-burn' | 'fast-burn' | 'exhausted';
96
+ export interface SloEvaluation {
97
+ badEvents: number;
98
+ burnRate: number | null;
99
+ errorBudgetEvents: number;
100
+ errorBudgetRemainingEvents: number;
101
+ goodEvents: number;
102
+ objectiveId: string;
103
+ state: SloEvaluationState;
104
+ target: number;
105
+ validEvents: number;
106
+ }
107
+ export type IncidentSeverity = 'SEV-1' | 'SEV-2' | 'SEV-3' | 'SEV-4';
108
+ export type IncidentState = 'declared' | 'stabilizing' | 'diagnosing' | 'recovering' | 'monitoring' | 'resolved';
109
+ export interface IncidentRoles {
110
+ communicationsOwner: string;
111
+ incidentCommander: string;
112
+ scribe: string;
113
+ technicalLead: string;
114
+ }
115
+ export interface IncidentTimelineEntry {
116
+ actor: string;
117
+ at: string;
118
+ evidenceRefs: readonly string[];
119
+ message: string;
120
+ type: 'observation' | 'decision' | 'action' | 'verification';
121
+ }
122
+ export interface IncidentRecord {
123
+ affectedJourneyIds: readonly string[];
124
+ candidateId?: string;
125
+ configurationDigest?: string;
126
+ declaredAt: string;
127
+ followUpRefs: readonly string[];
128
+ id: string;
129
+ impact: string;
130
+ roles: IncidentRoles;
131
+ severity: IncidentSeverity;
132
+ slice: string;
133
+ state: IncidentState;
134
+ timeline: readonly IncidentTimelineEntry[];
135
+ }
136
+ export type DiagnosticSource = 'alarm-state' | 'resource-metadata' | 'sanitized-signal' | 'bounded-log-query';
137
+ export interface DiagnosticTarget {
138
+ account: string;
139
+ region: string;
140
+ slice: string;
141
+ stage: string;
142
+ }
143
+ export interface SensitiveDiagnosticApproval {
144
+ allowedLogGroups: readonly string[];
145
+ authorization: ApprovalRequest<'reliability-diagnostic'>;
146
+ incidentRef: string;
147
+ queryClass: string;
148
+ reason: string;
149
+ target: DiagnosticTarget;
150
+ windowEnd: string;
151
+ windowStart: string;
152
+ }
153
+ export interface DiagnosticRequest {
154
+ approval?: SensitiveDiagnosticApproval;
155
+ source: DiagnosticSource;
156
+ target: DiagnosticTarget;
157
+ }
158
+ export interface DiagnosticPlan {
159
+ approvalRequired: boolean;
160
+ expiresAt?: string;
161
+ queryClass?: string;
162
+ source: DiagnosticSource;
163
+ target: DiagnosticTarget;
164
+ }
165
+ export type RemediationAction = 'protected-revert' | 'roll-forward' | 'redrive' | 'replay' | 'restore' | 'degraded-mode';
166
+ export interface RemediationApproval {
167
+ authorization: ApprovalRequest<'reliability-remediation'>;
168
+ incidentRef: string;
169
+ }
170
+ export type RemediationExecution = {
171
+ adapter: 'protected-async-recovery';
172
+ asyncRecoveryReportDigest: string;
173
+ } | {
174
+ adapter: 'report-only';
175
+ };
176
+ export interface RemediationRequest {
177
+ action: RemediationAction;
178
+ approval?: RemediationApproval;
179
+ cleanup: readonly string[];
180
+ execution: RemediationExecution;
181
+ mode: 'report' | 'apply';
182
+ preconditions: readonly string[];
183
+ stopConditions: readonly string[];
184
+ target: DiagnosticTarget;
185
+ verification: readonly string[];
186
+ }
187
+ export interface RemediationPlan extends RemediationRequest {
188
+ approvalRequired: true;
189
+ authorized: boolean;
190
+ remediationPlanDigest: string;
191
+ }
@@ -0,0 +1,2 @@
1
+ import type { SliceReliabilityContract } from './model.js';
2
+ export declare function reliabilityFixture(): SliceReliabilityContract;
@@ -0,0 +1,57 @@
1
+ export function reliabilityFixture() {
2
+ return {
3
+ escalationRouteKey: 'commerce-on-call',
4
+ objectives: [
5
+ {
6
+ allowedExclusionPolicyRef: 'docs:reliability/exclusions.md',
7
+ burn: { fast: 14.4, slow: 6, warning: 0.5 },
8
+ effectiveAt: '2026-07-29T00:00:00.000Z',
9
+ feature: 'web',
10
+ id: 'checkout-availability',
11
+ indicator: {
12
+ goodEventDefinition: 'Valid checkout requests complete without a server failure.',
13
+ metricRef: 'operations:metrics/checkout-availability',
14
+ type: 'availability',
15
+ validEventDefinition: 'Authenticated checkout requests accepted by policy.',
16
+ },
17
+ journey: 'complete-checkout',
18
+ lowTraffic: {
19
+ mode: 'synthetic',
20
+ syntheticRef: 'synthetic:checkout',
21
+ },
22
+ minimumValidEvents: {
23
+ diagnosticSample: 100,
24
+ fastBurnWindow: 1,
25
+ objectiveWindow: 100,
26
+ slowBurnWindow: 5,
27
+ },
28
+ owner: 'commerce',
29
+ references: {
30
+ alarmIds: ['checkout-fast-burn', 'checkout-slow-burn'],
31
+ dashboardRef: 'dashboard:checkout',
32
+ runbookRef: 'runbook:checkout-recovery',
33
+ syntheticRef: 'synthetic:checkout',
34
+ },
35
+ target: 0.99,
36
+ tier: 'critical',
37
+ window: { days: 28, kind: 'rolling' },
38
+ },
39
+ ],
40
+ owner: 'commerce',
41
+ providerDecision: {
42
+ applicationSignalsCoverage: ['lambda', 'next'],
43
+ basis: 'Direct metric math covers every generated workload at lower forecast cost.',
44
+ cost: {
45
+ currency: 'USD',
46
+ monthly: 4.25,
47
+ provenance: 'estimate',
48
+ },
49
+ directMetricMathCoverage: ['lambda', 'next', 'service', 'job', 'queue'],
50
+ reviewedAt: '2026-07-29T00:00:00.000Z',
51
+ selected: 'direct-cloudwatch-metric-math',
52
+ },
53
+ schemaVersion: 1,
54
+ slice: 'billing',
55
+ };
56
+ }
57
+ //# sourceMappingURL=model.fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.fixtures.js","sourceRoot":"","sources":["../../../../../packages/runtime/src/reliability/model.fixtures.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,kBAAkB,EAAE,kBAAkB;QACtC,UAAU,EAAE;YACV;gBACE,yBAAyB,EAAE,gCAAgC;gBAC3D,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE;gBAC3C,WAAW,EAAE,0BAA0B;gBACvC,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,uBAAuB;gBAC3B,SAAS,EAAE;oBACT,mBAAmB,EACjB,4DAA4D;oBAC9D,SAAS,EAAE,0CAA0C;oBACrD,IAAI,EAAE,cAAc;oBACpB,oBAAoB,EAClB,qDAAqD;iBACxD;gBACD,OAAO,EAAE,mBAAmB;gBAC5B,UAAU,EAAE;oBACV,IAAI,EAAE,WAAW;oBACjB,YAAY,EAAE,oBAAoB;iBACnC;gBACD,kBAAkB,EAAE;oBAClB,gBAAgB,EAAE,GAAG;oBACrB,cAAc,EAAE,CAAC;oBACjB,eAAe,EAAE,GAAG;oBACpB,cAAc,EAAE,CAAC;iBAClB;gBACD,KAAK,EAAE,UAAU;gBACjB,UAAU,EAAE;oBACV,QAAQ,EAAE,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;oBACtD,YAAY,EAAE,oBAAoB;oBAClC,UAAU,EAAE,2BAA2B;oBACvC,YAAY,EAAE,oBAAoB;iBACnC;gBACD,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;aACtC;SACF;QACD,KAAK,EAAE,UAAU;QACjB,gBAAgB,EAAE;YAChB,0BAA0B,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;YAC9C,KAAK,EACH,4EAA4E;YAC9E,IAAI,EAAE;gBACJ,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,UAAU;aACvB;YACD,wBAAwB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC;YACvE,UAAU,EAAE,0BAA0B;YACtC,QAAQ,EAAE,+BAA+B;SAC1C;QACD,aAAa,EAAE,CAAC;QAChB,KAAK,EAAE,SAAS;KACjB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const RELIABILITY_SCHEMA_VERSION = 1;
2
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../../packages/runtime/src/reliability/model.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAU,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { SloEvaluation, SloObjective } from './model.js';
2
+ export interface EvaluateSloInput {
3
+ goodEvents: number;
4
+ minimumValidEvents?: number;
5
+ objective: SloObjective;
6
+ syntheticSuccess?: boolean;
7
+ validEvents: number;
8
+ }
9
+ export declare function evaluateSlo(input: EvaluateSloInput): SloEvaluation;
@@ -0,0 +1,74 @@
1
+ function count(value, field) {
2
+ if (!Number.isSafeInteger(value) || value < 0) {
3
+ throw new Error(`[runtime/reliability] \`${field}\` must be a non-negative safe integer.`);
4
+ }
5
+ return value;
6
+ }
7
+ export function evaluateSlo(input) {
8
+ var _a;
9
+ const validEvents = count(input.validEvents, 'validEvents');
10
+ const goodEvents = count(input.goodEvents, 'goodEvents');
11
+ if (goodEvents > validEvents) {
12
+ throw new Error('[runtime/reliability] goodEvents cannot exceed validEvents.');
13
+ }
14
+ const badEvents = validEvents - goodEvents;
15
+ const errorBudgetEvents = validEvents * (1 - input.objective.target);
16
+ const errorBudgetRemainingEvents = errorBudgetEvents - badEvents;
17
+ const minimumValidEvents = (_a = input.minimumValidEvents) !== null && _a !== void 0 ? _a : input.objective.minimumValidEvents.objectiveWindow;
18
+ count(minimumValidEvents, 'minimumValidEvents');
19
+ if (minimumValidEvents < 1) {
20
+ throw new Error('[runtime/reliability] `minimumValidEvents` must be positive.');
21
+ }
22
+ if (validEvents < minimumValidEvents) {
23
+ let state = 'data-insufficient';
24
+ if (input.objective.lowTraffic.mode === 'synthetic') {
25
+ if (input.syntheticSuccess === undefined) {
26
+ throw new Error('[runtime/reliability] A synthetic result is required by the low-traffic policy.');
27
+ }
28
+ state = input.syntheticSuccess ? 'synthetic-healthy' : 'synthetic-failed';
29
+ }
30
+ return {
31
+ badEvents,
32
+ burnRate: null,
33
+ errorBudgetEvents,
34
+ errorBudgetRemainingEvents,
35
+ goodEvents,
36
+ objectiveId: input.objective.id,
37
+ state,
38
+ target: input.objective.target,
39
+ validEvents,
40
+ };
41
+ }
42
+ const allowedErrorRate = 1 - input.objective.target;
43
+ const actualErrorRate = validEvents === 0 ? 0 : badEvents / validEvents;
44
+ const burnRate = allowedErrorRate === 0
45
+ ? actualErrorRate === 0
46
+ ? 0
47
+ : Number.POSITIVE_INFINITY
48
+ : actualErrorRate / allowedErrorRate;
49
+ let state = 'healthy';
50
+ if (burnRate >= input.objective.burn.fast) {
51
+ state = 'fast-burn';
52
+ }
53
+ else if (burnRate >= input.objective.burn.slow) {
54
+ state = 'slow-burn';
55
+ }
56
+ else if (errorBudgetRemainingEvents <= 0) {
57
+ state = 'exhausted';
58
+ }
59
+ else if (burnRate >= input.objective.burn.warning) {
60
+ state = 'warning';
61
+ }
62
+ return {
63
+ badEvents,
64
+ burnRate,
65
+ errorBudgetEvents,
66
+ errorBudgetRemainingEvents,
67
+ goodEvents,
68
+ objectiveId: input.objective.id,
69
+ state,
70
+ target: input.objective.target,
71
+ validEvents,
72
+ };
73
+ }
74
+ //# sourceMappingURL=slo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slo.js","sourceRoot":"","sources":["../../../../../packages/runtime/src/reliability/slo.ts"],"names":[],"mappings":"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"}
@@ -4,38 +4,80 @@ export interface RequestActor {
4
4
  id?: string;
5
5
  type: 'service' | 'system' | 'user';
6
6
  }
7
- export interface RequestContext {
8
- app: string;
9
- actor?: RequestActor;
7
+ /**
8
+ * The propagation context shared by HTTP, event, Next.js server, Service, and
9
+ * Job workloads. Identity and authorization data can coexist with this context
10
+ * in the more specific request/event types, but is deliberately not part of
11
+ * the logging projection.
12
+ */
13
+ export interface RuntimeContext {
10
14
  causationId?: string;
11
15
  correlationId: string;
16
+ eventId?: string;
17
+ eventType?: string;
18
+ requestId?: string;
19
+ spanId?: string;
20
+ traceId?: string;
21
+ traceParent?: string;
22
+ traceState?: string;
23
+ }
24
+ export interface RuntimeContextInput {
25
+ causationId?: string;
26
+ correlationId?: string;
27
+ eventId?: string;
28
+ eventType?: string;
29
+ requestId?: string;
30
+ traceParent?: string;
31
+ traceState?: string;
32
+ }
33
+ export interface RequestContext extends RuntimeContext {
34
+ actor?: RequestActor;
12
35
  metadata: RequestMetadata;
13
36
  operation: string;
14
37
  requestId: string;
38
+ slice: string;
15
39
  source?: string;
16
40
  stage?: string;
17
41
  tenantId?: string;
18
- traceParent?: string;
19
- traceState?: string;
20
42
  }
21
- export interface RequestContextInput {
22
- app: string;
43
+ export interface RequestContextInput extends RuntimeContextInput {
23
44
  actor?: RequestActor;
24
- causationId?: string;
25
- correlationId?: string;
26
45
  metadata?: Record<string, RequestMetadataValue | undefined>;
27
46
  operation: string;
28
- requestId?: string;
47
+ slice: string;
29
48
  source?: string;
30
49
  stage?: string;
31
50
  tenantId?: string;
32
- traceParent?: string;
33
- traceState?: string;
34
51
  }
52
+ export type RequestContextOverrides = Omit<Partial<RequestContextInput>, 'slice'>;
35
53
  export declare function normalizePropagationId(value: string | null | undefined): string | undefined;
54
+ export declare function normalizeEventType(value: string | null | undefined): string | undefined;
36
55
  export declare function normalizeTraceParent(value: string | null | undefined): string | undefined;
37
56
  export declare function normalizeTraceState(value: string | null | undefined): string | undefined;
57
+ export declare function traceIdsFromParent(traceParent: string | null | undefined): Pick<RuntimeContext, 'spanId' | 'traceId'>;
58
+ export declare function normalizeTraceId(value: string | null | undefined): string | undefined;
59
+ export declare function normalizeSpanId(value: string | null | undefined): string | undefined;
60
+ /**
61
+ * Creates the shared propagation context. Invalid inbound identifiers are
62
+ * rejected from the context rather than reflected; a fresh correlation ID is
63
+ * used when no valid propagation anchor remains.
64
+ */
65
+ export declare function createRuntimeContext(input?: RuntimeContextInput): RuntimeContext;
38
66
  export declare function createRequestContext(input: RequestContextInput): RequestContext;
39
- export declare function extendRequestContext(context: RequestContext, overrides?: Partial<RequestContextInput>): RequestContext;
40
- export declare function toRequestHeaders(context: Pick<RequestContext, 'correlationId' | 'requestId' | 'traceParent' | 'traceState'>): Record<string, string>;
41
- export declare function toRequestLogMetadata(context: Partial<RequestContext>): RequestMetadata;
67
+ export declare function extendRequestContext(context: RequestContext, overrides?: RequestContextOverrides): RequestContext;
68
+ /**
69
+ * Named helpers keep generated workload entry points on one context contract
70
+ * without inventing per-workload propagation shapes.
71
+ */
72
+ export declare function createPublisherContext(input?: RuntimeContextInput): RuntimeContext;
73
+ export declare function createConsumerContext(input: RuntimeContextInput): RuntimeContext;
74
+ export declare function createNextServerContext(input: RequestContextInput): RequestContext;
75
+ export declare function createServiceContext(input?: RuntimeContextInput): RuntimeContext;
76
+ export declare function createJobContext(input?: RuntimeContextInput): RuntimeContext;
77
+ export declare function toRequestHeaders(context: Pick<RuntimeContext, 'causationId' | 'correlationId' | 'requestId' | 'traceParent' | 'traceState'>): Record<string, string>;
78
+ /**
79
+ * Projects only operational lookup fields. Actor, tenant, arbitrary request
80
+ * metadata, network identity, headers, paths, query, and bodies are
81
+ * intentionally excluded.
82
+ */
83
+ export declare function toLogContext(context: Partial<RuntimeContext>): Partial<RuntimeContext>;
@@ -1,15 +1,34 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  const PROPAGATION_ID_PATTERN = /^[A-Za-z0-9._:/-]{1,128}$/;
3
- const TRACE_PARENT_PATTERN = /^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/;
3
+ const EVENT_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9._:-]{0,127}$/;
4
+ const TRACE_PARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
5
+ const TRACE_ID_PATTERN = /^[0-9a-f]{32}$/;
6
+ const SPAN_ID_PATTERN = /^[0-9a-f]{16}$/;
7
+ const ZERO_TRACE_ID = '0'.repeat(32);
8
+ const ZERO_SPAN_ID = '0'.repeat(16);
9
+ function assertNonEmpty(value, field) {
10
+ const normalized = value.trim();
11
+ if (normalized.length === 0) {
12
+ throw new Error(`[runtime/request-context] \`${field}\` is required.`);
13
+ }
14
+ return normalized;
15
+ }
4
16
  export function normalizePropagationId(value) {
5
17
  const normalized = value === null || value === void 0 ? void 0 : value.trim();
6
18
  return normalized && PROPAGATION_ID_PATTERN.test(normalized)
7
19
  ? normalized
8
20
  : undefined;
9
21
  }
22
+ export function normalizeEventType(value) {
23
+ const normalized = value === null || value === void 0 ? void 0 : value.trim();
24
+ return normalized && EVENT_TYPE_PATTERN.test(normalized)
25
+ ? normalized
26
+ : undefined;
27
+ }
10
28
  export function normalizeTraceParent(value) {
11
29
  const normalized = value === null || value === void 0 ? void 0 : value.trim().toLowerCase();
12
- return normalized && TRACE_PARENT_PATTERN.test(normalized)
30
+ const match = normalized === null || normalized === void 0 ? void 0 : normalized.match(TRACE_PARENT_PATTERN);
31
+ return match && match[1] !== ZERO_TRACE_ID && match[2] !== ZERO_SPAN_ID
13
32
  ? normalized
14
33
  : undefined;
15
34
  }
@@ -19,50 +38,111 @@ export function normalizeTraceState(value) {
19
38
  ? normalized
20
39
  : undefined;
21
40
  }
41
+ export function traceIdsFromParent(traceParent) {
42
+ const normalized = normalizeTraceParent(traceParent);
43
+ const match = normalized === null || normalized === void 0 ? void 0 : normalized.match(TRACE_PARENT_PATTERN);
44
+ return match ? { traceId: match[1], spanId: match[2] } : {};
45
+ }
46
+ export function normalizeTraceId(value) {
47
+ const normalized = value === null || value === void 0 ? void 0 : value.trim().toLowerCase();
48
+ return normalized &&
49
+ TRACE_ID_PATTERN.test(normalized) &&
50
+ normalized !== ZERO_TRACE_ID
51
+ ? normalized
52
+ : undefined;
53
+ }
54
+ export function normalizeSpanId(value) {
55
+ const normalized = value === null || value === void 0 ? void 0 : value.trim().toLowerCase();
56
+ return normalized &&
57
+ SPAN_ID_PATTERN.test(normalized) &&
58
+ normalized !== ZERO_SPAN_ID
59
+ ? normalized
60
+ : undefined;
61
+ }
22
62
  function normalizeMetadata(metadata) {
23
63
  const entries = Object.entries(metadata !== null && metadata !== void 0 ? metadata : {}).filter(([, value]) => value !== undefined);
24
64
  return Object.fromEntries(entries);
25
65
  }
66
+ /**
67
+ * Creates the shared propagation context. Invalid inbound identifiers are
68
+ * rejected from the context rather than reflected; a fresh correlation ID is
69
+ * used when no valid propagation anchor remains.
70
+ */
71
+ export function createRuntimeContext(input = {}) {
72
+ var _a, _b, _c;
73
+ const requestId = normalizePropagationId(input.requestId);
74
+ const eventId = normalizePropagationId(input.eventId);
75
+ const correlationId = (_c = (_b = (_a = normalizePropagationId(input.correlationId)) !== null && _a !== void 0 ? _a : requestId) !== null && _b !== void 0 ? _b : eventId) !== null && _c !== void 0 ? _c : randomUUID();
76
+ const traceParent = normalizeTraceParent(input.traceParent);
77
+ return Object.assign(Object.assign({ causationId: normalizePropagationId(input.causationId), correlationId,
78
+ eventId, eventType: normalizeEventType(input.eventType), requestId }, traceIdsFromParent(traceParent)), { traceParent, traceState: normalizeTraceState(input.traceState) });
79
+ }
26
80
  export function createRequestContext(input) {
27
- var _a, _b;
81
+ var _a, _b, _c;
28
82
  const requestId = (_a = normalizePropagationId(input.requestId)) !== null && _a !== void 0 ? _a : randomUUID();
29
- return {
30
- app: input.app,
31
- actor: input.actor,
32
- causationId: normalizePropagationId(input.causationId),
33
- correlationId: (_b = normalizePropagationId(input.correlationId)) !== null && _b !== void 0 ? _b : requestId,
34
- metadata: normalizeMetadata(input.metadata),
35
- operation: input.operation,
36
- requestId,
37
- source: input.source,
38
- stage: input.stage,
39
- tenantId: normalizePropagationId(input.tenantId),
40
- traceParent: normalizeTraceParent(input.traceParent),
41
- traceState: normalizeTraceState(input.traceState),
42
- };
83
+ const propagation = createRuntimeContext(Object.assign(Object.assign({}, input), { requestId, correlationId: (_b = normalizePropagationId(input.correlationId)) !== null && _b !== void 0 ? _b : requestId }));
84
+ return Object.assign(Object.assign({}, propagation), { actor: input.actor, metadata: normalizeMetadata(input.metadata), operation: assertNonEmpty(input.operation, 'operation'), requestId, slice: assertNonEmpty(input.slice, 'slice'), source: input.source, stage: ((_c = input.stage) === null || _c === void 0 ? void 0 : _c.trim()) || undefined, tenantId: normalizePropagationId(input.tenantId) });
43
85
  }
44
86
  export function extendRequestContext(context, overrides = {}) {
45
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
46
- return {
47
- app: (_a = overrides.app) !== null && _a !== void 0 ? _a : context.app,
48
- actor: (_b = overrides.actor) !== null && _b !== void 0 ? _b : context.actor,
49
- causationId: (_c = normalizePropagationId(overrides.causationId)) !== null && _c !== void 0 ? _c : context.causationId,
50
- correlationId: (_d = normalizePropagationId(overrides.correlationId)) !== null && _d !== void 0 ? _d : context.correlationId,
51
- metadata: Object.assign(Object.assign({}, context.metadata), normalizeMetadata(overrides.metadata)),
52
- operation: (_e = overrides.operation) !== null && _e !== void 0 ? _e : context.operation,
53
- requestId: (_f = overrides.requestId) !== null && _f !== void 0 ? _f : context.requestId,
54
- source: (_g = overrides.source) !== null && _g !== void 0 ? _g : context.source,
55
- stage: (_h = overrides.stage) !== null && _h !== void 0 ? _h : context.stage,
56
- tenantId: (_j = normalizePropagationId(overrides.tenantId)) !== null && _j !== void 0 ? _j : context.tenantId,
57
- traceParent: (_k = normalizeTraceParent(overrides.traceParent)) !== null && _k !== void 0 ? _k : context.traceParent,
58
- traceState: (_l = normalizeTraceState(overrides.traceState)) !== null && _l !== void 0 ? _l : context.traceState,
59
- };
87
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
88
+ if ('slice' in overrides) {
89
+ throw new Error('[runtime/request-context] A request context cannot change its Slice.');
90
+ }
91
+ const requestId = (_a = normalizePropagationId(overrides.requestId)) !== null && _a !== void 0 ? _a : context.requestId;
92
+ const traceParent = overrides.traceParent === undefined
93
+ ? context.traceParent
94
+ : normalizeTraceParent(overrides.traceParent);
95
+ const traceState = overrides.traceState === undefined
96
+ ? context.traceState
97
+ : normalizeTraceState(overrides.traceState);
98
+ return Object.assign(Object.assign({ actor: (_b = overrides.actor) !== null && _b !== void 0 ? _b : context.actor, causationId: (_c = normalizePropagationId(overrides.causationId)) !== null && _c !== void 0 ? _c : context.causationId, correlationId: (_d = normalizePropagationId(overrides.correlationId)) !== null && _d !== void 0 ? _d : context.correlationId, eventId: (_e = normalizePropagationId(overrides.eventId)) !== null && _e !== void 0 ? _e : context.eventId, eventType: (_f = normalizeEventType(overrides.eventType)) !== null && _f !== void 0 ? _f : context.eventType, metadata: Object.assign(Object.assign({}, context.metadata), normalizeMetadata(overrides.metadata)), operation: overrides.operation === undefined
99
+ ? context.operation
100
+ : assertNonEmpty(overrides.operation, 'operation'), requestId, slice: context.slice, source: (_g = overrides.source) !== null && _g !== void 0 ? _g : context.source, stage: ((_h = overrides.stage) === null || _h === void 0 ? void 0 : _h.trim()) || context.stage, tenantId: (_j = normalizePropagationId(overrides.tenantId)) !== null && _j !== void 0 ? _j : context.tenantId }, traceIdsFromParent(traceParent)), { traceParent,
101
+ traceState });
102
+ }
103
+ /**
104
+ * Named helpers keep generated workload entry points on one context contract
105
+ * without inventing per-workload propagation shapes.
106
+ */
107
+ export function createPublisherContext(input = {}) {
108
+ return createRuntimeContext(input);
109
+ }
110
+ export function createConsumerContext(input) {
111
+ return createRuntimeContext(input);
112
+ }
113
+ export function createNextServerContext(input) {
114
+ return createRequestContext(input);
115
+ }
116
+ export function createServiceContext(input = {}) {
117
+ var _a;
118
+ return createRuntimeContext(Object.assign(Object.assign({}, input), { requestId: (_a = normalizePropagationId(input.requestId)) !== null && _a !== void 0 ? _a : randomUUID() }));
119
+ }
120
+ export function createJobContext(input = {}) {
121
+ var _a;
122
+ return createRuntimeContext(Object.assign(Object.assign({}, input), { requestId: (_a = normalizePropagationId(input.requestId)) !== null && _a !== void 0 ? _a : randomUUID() }));
60
123
  }
61
124
  export function toRequestHeaders(context) {
62
- return Object.assign(Object.assign({ 'x-causation-id': context.requestId, 'x-correlation-id': context.correlationId, 'x-request-id': context.requestId }, (context.traceParent ? { traceparent: context.traceParent } : {})), (context.traceState ? { tracestate: context.traceState } : {}));
125
+ var _a;
126
+ const causationId = (_a = context.requestId) !== null && _a !== void 0 ? _a : context.causationId;
127
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (causationId ? { 'x-causation-id': causationId } : {})), { 'x-correlation-id': context.correlationId }), (context.requestId ? { 'x-request-id': context.requestId } : {})), (context.traceParent ? { traceparent: context.traceParent } : {})), (context.traceState ? { tracestate: context.traceState } : {}));
63
128
  }
64
- export function toRequestLogMetadata(context) {
65
- var _a, _b;
66
- return normalizeMetadata(Object.assign({ actorId: (_a = context.actor) === null || _a === void 0 ? void 0 : _a.id, actorType: (_b = context.actor) === null || _b === void 0 ? void 0 : _b.type, app: context.app, causationId: context.causationId, correlationId: context.correlationId, operation: context.operation, requestId: context.requestId, source: context.source, stage: context.stage, tenantId: context.tenantId, traceParent: context.traceParent, traceState: context.traceState }, context.metadata));
129
+ /**
130
+ * Projects only operational lookup fields. Actor, tenant, arbitrary request
131
+ * metadata, network identity, headers, paths, query, and bodies are
132
+ * intentionally excluded.
133
+ */
134
+ export function toLogContext(context) {
135
+ const projected = {
136
+ causationId: normalizePropagationId(context.causationId),
137
+ correlationId: normalizePropagationId(context.correlationId),
138
+ eventId: normalizePropagationId(context.eventId),
139
+ eventType: normalizeEventType(context.eventType),
140
+ requestId: normalizePropagationId(context.requestId),
141
+ spanId: normalizeSpanId(context.spanId),
142
+ traceId: normalizeTraceId(context.traceId),
143
+ traceParent: normalizeTraceParent(context.traceParent),
144
+ traceState: normalizeTraceState(context.traceState),
145
+ };
146
+ return Object.fromEntries(Object.entries(projected).filter(([, value]) => value !== undefined));
67
147
  }
68
148
  //# sourceMappingURL=request-context.js.map