@sixb/server 0.1.0 → 0.1.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 (171) hide show
  1. package/README.md +3 -3
  2. package/dist/auth/application-access.d.ts +2 -2
  3. package/dist/auth/application-access.d.ts.map +1 -1
  4. package/dist/auth/connector-callback-cookie.d.ts +12 -0
  5. package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
  6. package/dist/auth/guard.d.ts +3 -3
  7. package/dist/auth/guard.d.ts.map +1 -1
  8. package/dist/auth/public-routes.d.ts.map +1 -1
  9. package/dist/auth/scope.d.ts +21 -27
  10. package/dist/auth/scope.d.ts.map +1 -1
  11. package/dist/auth/session-cookies.d.ts +2 -2
  12. package/dist/auth/session-cookies.d.ts.map +1 -1
  13. package/dist/connectors/http.d.ts +16 -0
  14. package/dist/connectors/http.d.ts.map +1 -0
  15. package/dist/files/content.d.ts +11 -0
  16. package/dist/files/content.d.ts.map +1 -1
  17. package/dist/index.js +4164 -3541
  18. package/dist/index.js.map +57 -52
  19. package/dist/openapi/tags.d.ts +11 -3
  20. package/dist/openapi/tags.d.ts.map +1 -1
  21. package/dist/registerRoutes.d.ts +6 -2
  22. package/dist/registerRoutes.d.ts.map +1 -1
  23. package/dist/routes/action-runs.d.ts +21 -31
  24. package/dist/routes/action-runs.d.ts.map +1 -1
  25. package/dist/routes/actions.d.ts +9 -8
  26. package/dist/routes/actions.d.ts.map +1 -1
  27. package/dist/routes/agent-api-gateway.d.ts +2 -2
  28. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  29. package/dist/routes/agents.d.ts +130 -131
  30. package/dist/routes/agents.d.ts.map +1 -1
  31. package/dist/routes/auth.d.ts +90 -90
  32. package/dist/routes/auth.d.ts.map +1 -1
  33. package/dist/routes/connector-connection-runs.d.ts +794 -0
  34. package/dist/routes/connector-connection-runs.d.ts.map +1 -0
  35. package/dist/routes/connector-connections.d.ts +219 -0
  36. package/dist/routes/connector-connections.d.ts.map +1 -0
  37. package/dist/routes/connectors.d.ts +10 -4
  38. package/dist/routes/connectors.d.ts.map +1 -1
  39. package/dist/routes/datasets.d.ts +15 -9
  40. package/dist/routes/datasets.d.ts.map +1 -1
  41. package/dist/routes/events.d.ts +8 -8
  42. package/dist/routes/events.d.ts.map +1 -1
  43. package/dist/routes/files.d.ts +11 -10
  44. package/dist/routes/files.d.ts.map +1 -1
  45. package/dist/routes/links.d.ts +2 -2
  46. package/dist/routes/links.d.ts.map +1 -1
  47. package/dist/routes/logs.d.ts +5 -5
  48. package/dist/routes/logs.d.ts.map +1 -1
  49. package/dist/routes/objects.d.ts +34 -34
  50. package/dist/routes/objects.d.ts.map +1 -1
  51. package/dist/routes/ontology.d.ts +62 -62
  52. package/dist/routes/ontology.d.ts.map +1 -1
  53. package/dist/routes/pipelines.d.ts +28 -34
  54. package/dist/routes/pipelines.d.ts.map +1 -1
  55. package/dist/routes/project.d.ts +2 -2
  56. package/dist/routes/project.d.ts.map +1 -1
  57. package/dist/routes/projections.d.ts +131 -83
  58. package/dist/routes/projections.d.ts.map +1 -1
  59. package/dist/routes/rules.d.ts +6 -6
  60. package/dist/routes/rules.d.ts.map +1 -1
  61. package/dist/routes/status.d.ts +2 -2
  62. package/dist/routes/status.d.ts.map +1 -1
  63. package/dist/routes/syncs.d.ts +27 -30
  64. package/dist/routes/syncs.d.ts.map +1 -1
  65. package/dist/routes/telemetry.d.ts +2 -2
  66. package/dist/routes/telemetry.d.ts.map +1 -1
  67. package/dist/routes/webhook-runs.d.ts +9 -9
  68. package/dist/routes/webhook-runs.d.ts.map +1 -1
  69. package/dist/routes/webhooks.d.ts +2 -2
  70. package/dist/routes/webhooks.d.ts.map +1 -1
  71. package/dist/routes/workflows.d.ts +132 -107
  72. package/dist/routes/workflows.d.ts.map +1 -1
  73. package/dist/routes/ws/agents.d.ts +11 -5
  74. package/dist/routes/ws/agents.d.ts.map +1 -1
  75. package/dist/routes/ws/events.d.ts +8 -8
  76. package/dist/routes/ws/events.d.ts.map +1 -1
  77. package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
  78. package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
  79. package/dist/routes/ws/logs.d.ts +10 -10
  80. package/dist/routes/ws/logs.d.ts.map +1 -1
  81. package/dist/schemas/actions.d.ts +97 -202
  82. package/dist/schemas/actions.d.ts.map +1 -1
  83. package/dist/schemas/agents.d.ts +443 -440
  84. package/dist/schemas/agents.d.ts.map +1 -1
  85. package/dist/schemas/ai-usage.d.ts +34 -0
  86. package/dist/schemas/ai-usage.d.ts.map +1 -0
  87. package/dist/schemas/auth.d.ts +168 -168
  88. package/dist/schemas/common.d.ts +37 -0
  89. package/dist/schemas/common.d.ts.map +1 -1
  90. package/dist/schemas/connectors.d.ts +713 -2
  91. package/dist/schemas/connectors.d.ts.map +1 -1
  92. package/dist/schemas/datasets.d.ts +29 -23
  93. package/dist/schemas/datasets.d.ts.map +1 -1
  94. package/dist/schemas/event-payloads.d.ts +6 -6
  95. package/dist/schemas/events.d.ts +34 -34
  96. package/dist/schemas/logs.d.ts +22 -22
  97. package/dist/schemas/objects.d.ts +10 -10
  98. package/dist/schemas/ontology.d.ts +174 -174
  99. package/dist/schemas/pipelines.d.ts +131 -190
  100. package/dist/schemas/pipelines.d.ts.map +1 -1
  101. package/dist/schemas/projections.d.ts +918 -563
  102. package/dist/schemas/projections.d.ts.map +1 -1
  103. package/dist/schemas/rules.d.ts +6 -6
  104. package/dist/schemas/status.d.ts +2 -2
  105. package/dist/schemas/syncs.d.ts +88 -124
  106. package/dist/schemas/syncs.d.ts.map +1 -1
  107. package/dist/schemas/webhook-runs.d.ts +41 -41
  108. package/dist/schemas/webhook-runs.d.ts.map +1 -1
  109. package/dist/schemas/workflows.d.ts +792 -406
  110. package/dist/schemas/workflows.d.ts.map +1 -1
  111. package/dist/server.d.ts +6 -6
  112. package/dist/server.d.ts.map +1 -1
  113. package/dist/utils/http.d.ts +2 -0
  114. package/dist/utils/http.d.ts.map +1 -1
  115. package/dist/utils/ws.d.ts +4 -3
  116. package/dist/utils/ws.d.ts.map +1 -1
  117. package/package.json +8 -5
  118. package/src/auth/access-token-boundary.ts +4 -4
  119. package/src/auth/application-access.ts +8 -9
  120. package/src/auth/connector-callback-cookie.ts +95 -0
  121. package/src/auth/guard.ts +11 -11
  122. package/src/auth/public-routes.ts +13 -0
  123. package/src/auth/scope.ts +34 -30
  124. package/src/auth/session-cookies.ts +3 -3
  125. package/src/connectors/http.ts +110 -0
  126. package/src/files/content.ts +11 -0
  127. package/src/openapi/tags.ts +9 -1
  128. package/src/registerRoutes.ts +34 -23
  129. package/src/routes/action-runs.ts +49 -42
  130. package/src/routes/actions.ts +7 -13
  131. package/src/routes/agent-api-gateway.ts +87 -42
  132. package/src/routes/agents.ts +89 -200
  133. package/src/routes/auth.ts +87 -91
  134. package/src/routes/connector-connection-runs.ts +346 -0
  135. package/src/routes/connector-connections.ts +135 -0
  136. package/src/routes/connectors.ts +24 -12
  137. package/src/routes/datasets.ts +55 -54
  138. package/src/routes/events.ts +5 -5
  139. package/src/routes/files.ts +24 -31
  140. package/src/routes/links.ts +32 -35
  141. package/src/routes/logs.ts +6 -11
  142. package/src/routes/objects.ts +51 -114
  143. package/src/routes/ontology.ts +27 -38
  144. package/src/routes/pipelines.ts +28 -62
  145. package/src/routes/project.ts +3 -3
  146. package/src/routes/projections.ts +26 -38
  147. package/src/routes/rules.ts +11 -25
  148. package/src/routes/status.ts +5 -5
  149. package/src/routes/syncs.ts +19 -45
  150. package/src/routes/telemetry.ts +18 -29
  151. package/src/routes/webhook-runs.ts +5 -5
  152. package/src/routes/webhooks.ts +259 -341
  153. package/src/routes/workflows.ts +260 -259
  154. package/src/routes/ws/agents.ts +196 -66
  155. package/src/routes/ws/events.ts +11 -10
  156. package/src/routes/ws/log-subscription-hub.ts +6 -12
  157. package/src/routes/ws/logs.ts +13 -5
  158. package/src/schemas/actions.ts +58 -25
  159. package/src/schemas/agents.ts +19 -14
  160. package/src/schemas/ai-usage.ts +16 -0
  161. package/src/schemas/common.ts +24 -0
  162. package/src/schemas/connectors.ts +164 -0
  163. package/src/schemas/datasets.ts +3 -2
  164. package/src/schemas/pipelines.ts +24 -40
  165. package/src/schemas/projections.ts +17 -3
  166. package/src/schemas/syncs.ts +16 -10
  167. package/src/schemas/webhook-runs.ts +10 -5
  168. package/src/schemas/workflows.ts +42 -25
  169. package/src/server.ts +65 -26
  170. package/src/utils/http.ts +34 -6
  171. package/src/utils/ws.ts +10 -5
@@ -1,15 +1,13 @@
1
1
  import type {
2
2
  LinkProjectionDefinition,
3
3
  ObjectProjectionDefinition,
4
- OntologySource,
5
4
  ProjectionDefinition,
6
- Sixb,
5
+ SixbHostView,
7
6
  TelemetryProjectionDefinition,
8
7
  } from "@sixb/core"
9
- import { canViewProjection, canViewProjectionRun } from "@sixb/core/internal/authorization"
10
8
  import type { ProjectionRunRecord } from "@sixb/core/storage"
11
9
  import type { Elysia } from "elysia"
12
- import { requestAuthState } from "../auth/scope"
10
+ import { requireRequestSixb } from "../auth/scope"
13
11
  import { OPENAPI_TAGS } from "../openapi/tags"
14
12
  import { ErrorResponseSchema } from "../schemas/common"
15
13
  import {
@@ -33,20 +31,20 @@ function serializeProjectionRun(run: ProjectionRunRecord) {
33
31
  return ProjectionRunSchema.parse({
34
32
  id: run.id,
35
33
  projectId: run.projectId,
34
+ executionId: run.executionId,
36
35
  identity: run.identity,
37
36
  target: run.target,
38
37
  status: run.status,
39
38
  attempt: run.attempt,
40
39
  progress: run.progress,
41
- startedAt: toIsoString(run.startedAt),
40
+ queuedAt: toIsoString(run.queuedAt),
41
+ startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
42
42
  finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
43
- errorMessage: run.errorMessage,
43
+ error: run.error,
44
44
  })
45
45
  }
46
46
 
47
47
  type SerializedProjectionRun = ReturnType<typeof serializeProjectionRun>
48
- type RequestAuthorization = ReturnType<typeof requestAuthState>["authz"]
49
-
50
48
  interface ViewableProjectionCatalog {
51
49
  readonly objectProjections: readonly ObjectProjectionDefinition[]
52
50
  readonly linkProjections: readonly LinkProjectionDefinition[]
@@ -54,32 +52,24 @@ interface ViewableProjectionCatalog {
54
52
  }
55
53
 
56
54
  async function getLatestProjectionRuns(
57
- sixb: Sixb<readonly OntologySource[]>,
55
+ sixb: ReturnType<typeof requireRequestSixb>,
58
56
  projectionIds: readonly string[]
59
57
  ): Promise<Map<string, SerializedProjectionRun>> {
60
- const storage = sixb.storage.projectionRuns
61
- if (!storage || projectionIds.length === 0) {
58
+ if (projectionIds.length === 0) {
62
59
  return new Map()
63
60
  }
64
61
 
65
- const result = await storage.listLatestByProjectionIds({ projectId: sixb.id, projectionIds })
62
+ const result = await sixb.projections.runs.listLatest(projectionIds)
66
63
  return new Map(result.runs.map((run) => [run.identity.projectionId, serializeProjectionRun(run)]))
67
64
  }
68
65
 
69
66
  function listViewableProjections(
70
- sixb: Sixb<readonly OntologySource[]>,
71
- authz: RequestAuthorization
67
+ sixb: ReturnType<typeof requireRequestSixb>
72
68
  ): ViewableProjectionCatalog {
73
69
  return {
74
- objectProjections: sixb
75
- .listObjectProjections()
76
- .filter((projection) => canViewProjection(authz, projection)),
77
- linkProjections: sixb
78
- .listLinkProjections()
79
- .filter((projection) => canViewProjection(authz, projection)),
80
- telemetryProjections: sixb
81
- .listTelemetryProjections()
82
- .filter((projection) => canViewProjection(authz, projection)),
70
+ objectProjections: sixb.projections.listObjects(),
71
+ linkProjections: sixb.projections.listLinks(),
72
+ telemetryProjections: sixb.projections.listTelemetry(),
83
73
  }
84
74
  }
85
75
 
@@ -118,13 +108,13 @@ function serializeProjectionCatalog(
118
108
  }
119
109
  }
120
110
 
121
- export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
111
+ export function registerProjectionRoutes(app: Elysia, host: SixbHostView) {
122
112
  return app
123
113
  .get(
124
114
  "/api/projections",
125
115
  async (context) => {
126
- const { authz } = requestAuthState(context)
127
- const catalog = listViewableProjections(sixb, authz)
116
+ const sixb = requireRequestSixb(context)
117
+ const catalog = listViewableProjections(sixb)
128
118
  const latestRuns = await getLatestProjectionRuns(sixb, projectionCatalogIds(catalog))
129
119
  return serializeProjectionCatalog(catalog, latestRuns)
130
120
  },
@@ -141,9 +131,9 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
141
131
  "/api/projections/:projectionId",
142
132
  async (context) => {
143
133
  const { params, set } = context
144
- const { authz } = requestAuthState(context)
145
- const found = sixb.getProjectionById(params.projectionId)
146
- if (!found || !canViewProjection(authz, found)) {
134
+ const sixb = requireRequestSixb(context)
135
+ const found = sixb.projections.getById(params.projectionId)
136
+ if (!found) {
147
137
  set.status = 404
148
138
  return { error: `Projection '${params.projectionId}' not found` }
149
139
  }
@@ -165,21 +155,19 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
165
155
  "/api/projection-runs",
166
156
  async (context) => {
167
157
  const { query, set } = context
168
- const { authz } = requestAuthState(context)
158
+ const sixb = requireRequestSixb(context)
169
159
  try {
170
- const storage = sixb.storage.projectionRuns
160
+ const storage = host.storage.projectionRuns
171
161
  if (!storage) {
172
162
  return unconfiguredStorageResponse(set, "Projection run storage")
173
163
  }
174
164
 
175
165
  const parsed = ProjectionRunsQuerySchema.parse(query)
176
- const result = await storage.list({
177
- projectId: sixb.id,
166
+ const result = await sixb.projections.runs.list({
178
167
  projectionId: parsed.projectionId,
179
168
  projectionKind: parsed.projectionKind,
180
169
  datasetId: parsed.datasetId,
181
170
  datasetVersionId: parsed.datasetVersionId,
182
- objectTypeIds: authz ? [...authz.grants["view:object"]] : undefined,
183
171
  statuses: parsed.status ? [parsed.status] : undefined,
184
172
  startedAfter: parseDate(parsed.startedAfter),
185
173
  startedBefore: parseDate(parsed.startedBefore),
@@ -215,15 +203,15 @@ export function registerProjectionRoutes(app: Elysia, sixb: Sixb<readonly Ontolo
215
203
  "/api/projection-runs/:runId",
216
204
  async (context) => {
217
205
  const { params, set } = context
218
- const { authz } = requestAuthState(context)
206
+ const sixb = requireRequestSixb(context)
219
207
  try {
220
- const storage = sixb.storage.projectionRuns
208
+ const storage = host.storage.projectionRuns
221
209
  if (!storage) {
222
210
  return unconfiguredStorageResponse(set, "Projection run storage")
223
211
  }
224
212
 
225
- const run = await storage.getById({ projectId: sixb.id, id: params.runId })
226
- if (!run || !canViewProjectionRun(authz, run.target)) {
213
+ const run = await sixb.projections.runs.getById(params.runId)
214
+ if (!run) {
227
215
  set.status = 404
228
216
  return { error: "Projection run not found" }
229
217
  }
@@ -1,8 +1,8 @@
1
- import { isAllowed, type OntologySource, type RuleDefinition, type Sixb } from "@sixb/core"
1
+ import type { RuleDefinition, SixbHostView } from "@sixb/core"
2
2
  import { deriveRuleEventDependencies } from "@sixb/core/internal/rules"
3
3
  import type { RuleStateRecord } from "@sixb/core/storage"
4
4
  import type { Elysia } from "elysia"
5
- import { requestAuthState } from "../auth/scope"
5
+ import { requireRequestSixb } from "../auth/scope"
6
6
  import { OPENAPI_TAGS } from "../openapi/tags"
7
7
  import { ErrorResponseSchema } from "../schemas/common"
8
8
  import {
@@ -25,12 +25,12 @@ function serializeRuleState(state: RuleStateRecord): ReturnType<typeof RuleState
25
25
  return RuleStateSchema.parse(state)
26
26
  }
27
27
 
28
- export function registerRuleRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
28
+ export function registerRuleRoutes(app: Elysia, host: SixbHostView) {
29
29
  return app
30
30
  .get(
31
31
  "/api/rules",
32
- () => {
33
- return sixb.listRules().map(serializeRule)
32
+ (context) => {
33
+ return requireRequestSixb(context).rules.list().map(serializeRule)
34
34
  },
35
35
  {
36
36
  response: { 200: RuleSchema.array() },
@@ -43,8 +43,9 @@ export function registerRuleRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
43
43
  )
44
44
  .get(
45
45
  "/api/rules/:ruleId",
46
- ({ params, set }) => {
47
- const rule = sixb.getRuleById(params.ruleId)
46
+ (context) => {
47
+ const { params, set } = context
48
+ const rule = requireRequestSixb(context).rules.getById(params.ruleId)
48
49
  if (!rule) {
49
50
  set.status = 404
50
51
  return { error: "Rule not found" }
@@ -66,32 +67,17 @@ export function registerRuleRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
66
67
  "/api/rule-states",
67
68
  async (context) => {
68
69
  const { query, set } = context
69
- const { authz } = requestAuthState(context)
70
+ const sixb = requireRequestSixb(context)
70
71
  try {
71
72
  const parsed = RuleStatesQuerySchema.parse(query)
72
- const storage = sixb.storage.rules
73
+ const storage = host.storage.rules
73
74
  if (!storage) {
74
75
  return unconfiguredStorageResponse(set, "Rule state storage")
75
76
  }
76
77
 
77
- const objectTypeIds = authz ? [...authz.grants["view:object"]] : undefined
78
- if (
79
- authz &&
80
- parsed.objectTypeId &&
81
- !isAllowed(authz, { kind: "object.view", objectTypeId: parsed.objectTypeId })
82
- ) {
83
- return {
84
- states: [],
85
- hasMore: false,
86
- total: 0,
87
- }
88
- }
89
-
90
- const result = await storage.listActive({
91
- projectId: sixb.id,
78
+ const result = await sixb.rules.states.list({
92
79
  ruleId: parsed.ruleId,
93
80
  objectTypeId: parsed.objectTypeId,
94
- objectTypeIds,
95
81
  primaryId: parsed.primaryId,
96
82
  limit: parseOptionalInt(parsed.limit),
97
83
  offset: parseOptionalInt(parsed.offset),
@@ -1,4 +1,4 @@
1
- import type { OntologySource, Sixb } from "@sixb/core"
1
+ import type { SixbHostView } from "@sixb/core"
2
2
  import type { Elysia } from "elysia"
3
3
  import { OPENAPI_TAGS } from "../openapi/tags"
4
4
  import {
@@ -6,7 +6,7 @@ import {
6
6
  ReadinessResponseSchema,
7
7
  StatusResponseSchema,
8
8
  } from "../schemas/status"
9
- export function registerStatusRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
9
+ export function registerStatusRoutes(app: Elysia, host: SixbHostView) {
10
10
  app.get("/health", () => ({ status: "ok" as const }), {
11
11
  response: { 200: HealthResponseSchema },
12
12
  detail: {
@@ -20,7 +20,7 @@ export function registerStatusRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
20
20
  app.get(
21
21
  "/ready",
22
22
  async ({ set }) => {
23
- const readiness = await sixb.checkReadiness()
23
+ const readiness = await host.checkReadiness()
24
24
  if (readiness.status === "unready") set.status = 503
25
25
  return readiness
26
26
  },
@@ -38,8 +38,8 @@ export function registerStatusRoutes(app: Elysia, sixb: Sixb<readonly OntologySo
38
38
  return app.get(
39
39
  "/api/status",
40
40
  async () => ({
41
- ...sixb.getOntologyOperationalStatus(),
42
- objectTypes: sixb.listObjectTypes().length,
41
+ ...host.getOntologyOperationalStatus(),
42
+ objectTypes: host.definitions.ontology.listObjectTypes().length,
43
43
  }),
44
44
  {
45
45
  response: { 200: StatusResponseSchema },
@@ -1,7 +1,7 @@
1
- import type { OntologySource, Sixb, SyncDefinition } from "@sixb/core"
1
+ import type { SixbHostView, SyncDefinition } from "@sixb/core"
2
2
  import type { SyncRunRecord } from "@sixb/core/storage"
3
3
  import type { Elysia } from "elysia"
4
- import { requestAuthState } from "../auth/scope"
4
+ import { requireRequestSixb } from "../auth/scope"
5
5
  import { SIXB_CSRF_SECURITY_REQUIREMENT } from "../openapi/security"
6
6
  import { OPENAPI_TAGS } from "../openapi/tags"
7
7
  import { ErrorResponseSchema } from "../schemas/common"
@@ -29,7 +29,8 @@ function serializeSyncRun(run: SyncRunRecord) {
29
29
  datasetId: run.datasetId,
30
30
  mode: run.mode,
31
31
  status: run.status,
32
- startedAt: toIsoString(run.startedAt),
32
+ queuedAt: toIsoString(run.queuedAt),
33
+ startedAt: run.startedAt ? toIsoString(run.startedAt) : undefined,
33
34
  finishedAt: run.finishedAt ? toIsoString(run.finishedAt) : undefined,
34
35
  rowsRead: run.rowsRead,
35
36
  output: run.output,
@@ -42,36 +43,24 @@ function serializeSyncRun(run: SyncRunRecord) {
42
43
  type SerializedSyncRun = ReturnType<typeof serializeSyncRun>
43
44
 
44
45
  async function getLatestSyncRun(
45
- sixb: Sixb<readonly OntologySource[]>,
46
+ sixb: ReturnType<typeof requireRequestSixb>,
46
47
  syncId: string
47
48
  ): Promise<SerializedSyncRun | null> {
48
- if (!sixb.storage.syncRuns) {
49
- return null
50
- }
51
-
52
- const storage = sixb.storage.syncRuns
53
- const result = await storage.listLatestBySyncIds({
54
- projectId: sixb.id,
55
- syncIds: [syncId],
56
- })
49
+ const result = await sixb.syncs.runs.listLatest([syncId])
57
50
 
58
51
  const [latest] = result.runs
59
52
  return latest ? serializeSyncRun(latest) : null
60
53
  }
61
54
 
62
55
  async function getLatestSyncRuns(
63
- sixb: Sixb<readonly OntologySource[]>,
56
+ sixb: ReturnType<typeof requireRequestSixb>,
64
57
  syncIds: readonly string[]
65
58
  ): Promise<Map<string, SerializedSyncRun>> {
66
- const storage = sixb.storage.syncRuns
67
- if (!storage || syncIds.length === 0) {
59
+ if (syncIds.length === 0) {
68
60
  return new Map()
69
61
  }
70
62
 
71
- const result = await storage.listLatestBySyncIds({
72
- projectId: sixb.id,
73
- syncIds,
74
- })
63
+ const result = await sixb.syncs.runs.listLatest(syncIds)
75
64
 
76
65
  return new Map(result.runs.map((run) => [run.syncId, serializeSyncRun(run)]))
77
66
  }
@@ -96,13 +85,13 @@ function serializeSync(
96
85
  })
97
86
  }
98
87
 
99
- export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
88
+ export function registerSyncRoutes(app: Elysia, host: SixbHostView) {
100
89
  return app
101
90
  .get(
102
91
  "/api/syncs",
103
92
  async (context) => {
104
- const { scoped } = requestAuthState(context)
105
- const syncs = scoped ? scoped.listSyncs() : sixb.listSyncs()
93
+ const sixb = requireRequestSixb(context)
94
+ const syncs = sixb.syncs.list()
106
95
  const latestRuns = await getLatestSyncRuns(
107
96
  sixb,
108
97
  syncs.map((sync) => sync.id)
@@ -123,8 +112,8 @@ export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
123
112
  "/api/syncs/:syncId",
124
113
  async (context) => {
125
114
  const { params, set } = context
126
- const { scoped } = requestAuthState(context)
127
- const sync = scoped ? scoped.getSyncById(params.syncId) : sixb.getSyncById(params.syncId)
115
+ const sixb = requireRequestSixb(context)
116
+ const sync = sixb.syncs.getById(params.syncId)
128
117
  if (!sync) {
129
118
  set.status = 404
130
119
  return { error: "Sync not found" }
@@ -146,23 +135,16 @@ export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
146
135
  "/api/sync-runs",
147
136
  async (context) => {
148
137
  const { query, set } = context
149
- const { authz } = requestAuthState(context)
138
+ const sixb = requireRequestSixb(context)
150
139
  try {
151
140
  const parsed = SyncRunsQuerySchema.parse(query)
152
- const storage = sixb.storage.syncRuns
141
+ const storage = host.storage.syncRuns
153
142
  if (!storage) {
154
143
  return unconfiguredStorageResponse(set, "Sync run storage")
155
144
  }
156
145
 
157
- // Scope to runnable syncs the same way workflow run history does: pass
158
- // the grant allowlist alongside any explicit syncId and let storage AND
159
- // them. An ungranted syncId yields an empty intersection (no rows), and
160
- // an empty allowlist short-circuits to no rows.
161
- const syncIds = authz ? [...authz.grants["run:sync"]] : undefined
162
- const result = await storage.list({
163
- projectId: sixb.id,
146
+ const result = await sixb.syncs.runs.list({
164
147
  syncId: parsed.syncId,
165
- syncIds,
166
148
  datasetId: parsed.datasetId,
167
149
  statuses: parsed.status ? [parsed.status] : undefined,
168
150
  startedAfter: parseDate(parsed.startedAfter),
@@ -199,18 +181,10 @@ export function registerSyncRoutes(app: Elysia, sixb: Sixb<readonly OntologySour
199
181
  "/api/syncs/:syncId/runs",
200
182
  async (context) => {
201
183
  const { params, body, set } = context
202
- const { scoped } = requestAuthState(context)
184
+ const sixb = requireRequestSixb(context)
203
185
  try {
204
- const sync = sixb.getSyncById(params.syncId)
205
- if (!sync) {
206
- set.status = 404
207
- return { error: "Sync not found" }
208
- }
209
-
210
186
  const parsedBody = RequestSyncRunBodySchema.parse(body)
211
- const result = scoped
212
- ? await scoped.requestSyncRun({ syncId: sync.id, ...parsedBody })
213
- : await sixb.requestSyncRun({ syncId: sync.id, ...parsedBody })
187
+ const result = await sixb.syncs.request({ syncId: params.syncId, ...parsedBody })
214
188
 
215
189
  set.status = 202
216
190
  return {
@@ -1,9 +1,8 @@
1
- import { isAllowed, type OntologySource, type Sixb } from "@sixb/core"
2
- import { getTelemetryHistoryBatch } from "@sixb/core/internal/objects"
1
+ import type { SixbHostView } from "@sixb/core"
3
2
  import type { TimeseriesPoint } from "@sixb/core/storage"
4
3
  import type { Elysia } from "elysia"
5
4
  import { bearerSecurityRequirement } from "../auth/access-token-boundary"
6
- import { requestAuthState } from "../auth/scope"
5
+ import { requireRequestSixb } from "../auth/scope"
7
6
  import { OPENAPI_TAGS } from "../openapi/tags"
8
7
  import { ErrorResponseSchema, SuccessResponseSchema } from "../schemas/common"
9
8
  import {
@@ -28,16 +27,15 @@ function serializeTelemetryPoint(point: TimeseriesPoint) {
28
27
  }
29
28
  }
30
29
 
31
- export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
30
+ export function registerTelemetryRoutes(app: Elysia, _host: SixbHostView) {
32
31
  return app
33
32
  .post(
34
33
  "/api/objects/:objectTypeId/:objectId/telemetry/:propertyId",
35
34
  async (context) => {
36
35
  const { params, body, set } = context
37
- const { scoped } = requestAuthState(context)
38
36
  try {
39
37
  const parsedBody = AppendTelemetryBodySchema.parse(body)
40
- await (scoped ?? sixb).appendTelemetry(params.objectTypeId, [
38
+ await requireRequestSixb(context).objects.appendTelemetry(params.objectTypeId, [
41
39
  {
42
40
  id: params.objectId,
43
41
  properties: {
@@ -75,22 +73,17 @@ export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
75
73
  "/api/telemetry/history",
76
74
  async (context) => {
77
75
  const { body, set } = context
78
- const { authz } = requestAuthState(context)
79
76
  try {
80
77
  const parsedBody = BulkTelemetryHistoryBodySchema.parse(body)
81
78
  const from = parseDate(parsedBody.from)
82
79
  const to = parseDate(parsedBody.to)
83
- const history = await getTelemetryHistoryBatch(
84
- {
85
- projectId: sixb.id,
86
- series: parsedBody.series,
87
- from,
88
- to,
89
- limitPerSeries: parsedBody.limitPerSeries,
90
- order: parsedBody.order,
91
- },
92
- { storage: sixb.storage.timeseries, authorization: authz }
93
- )
80
+ const history = await requireRequestSixb(context).objects.getTelemetryHistoryBatch({
81
+ series: parsedBody.series,
82
+ from,
83
+ to,
84
+ limitPerSeries: parsedBody.limitPerSeries,
85
+ order: parsedBody.order,
86
+ })
94
87
 
95
88
  return {
96
89
  series: history.map((series) => ({
@@ -121,16 +114,14 @@ export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
121
114
  "/api/objects/:objectTypeId/:objectId/telemetry/:propertyId/history",
122
115
  async (context) => {
123
116
  const { params, query, set } = context
124
- const { authz } = requestAuthState(context)
125
117
  try {
126
- const parsedQuery = TelemetryHistoryQuerySchema.parse(query)
127
- if (!isAllowed(authz, { kind: "object.view", objectTypeId: params.objectTypeId })) {
118
+ const sixb = requireRequestSixb(context)
119
+ if (!sixb.objects.getTypeById(params.objectTypeId)) {
128
120
  set.status = 404
129
121
  return { error: "Object not found" }
130
122
  }
131
-
132
- const history = await sixb.storage.timeseries.getHistory({
133
- projectId: sixb.id,
123
+ const parsedQuery = TelemetryHistoryQuerySchema.parse(query)
124
+ const history = await sixb.objects.getTelemetryHistory({
134
125
  objectTypeId: params.objectTypeId,
135
126
  objectId: params.objectId,
136
127
  propertyId: params.propertyId,
@@ -165,15 +156,13 @@ export function registerTelemetryRoutes(app: Elysia, sixb: Sixb<readonly Ontolog
165
156
  "/api/objects/:objectTypeId/:objectId/telemetry/:propertyId/latest",
166
157
  async (context) => {
167
158
  const { params, set } = context
168
- const { authz } = requestAuthState(context)
169
159
  try {
170
- if (!isAllowed(authz, { kind: "object.view", objectTypeId: params.objectTypeId })) {
160
+ const sixb = requireRequestSixb(context)
161
+ if (!sixb.objects.getTypeById(params.objectTypeId)) {
171
162
  set.status = 404
172
163
  return { error: "Object not found" }
173
164
  }
174
-
175
- const latest = await sixb.storage.timeseries.getLatest({
176
- projectId: sixb.id,
165
+ const latest = await sixb.objects.getLatestTelemetry({
177
166
  objectTypeId: params.objectTypeId,
178
167
  objectId: params.objectId,
179
168
  propertyId: params.propertyId,
@@ -1,4 +1,4 @@
1
- import type { OntologySource, Sixb } from "@sixb/core"
1
+ import type { SixbHostView } from "@sixb/core"
2
2
  import type { WebhookRunRecord } from "@sixb/core/storage"
3
3
  import type { Elysia } from "elysia"
4
4
  import { OPENAPI_TAGS } from "../openapi/tags"
@@ -16,6 +16,7 @@ function serializeWebhookRun(run: WebhookRunRecord) {
16
16
  return {
17
17
  id: run.id,
18
18
  projectId: run.projectId,
19
+ executionId: run.executionId,
19
20
  connectorId: run.connectorId,
20
21
  webhookId: run.webhookId,
21
22
  status: run.status,
@@ -26,24 +27,23 @@ function serializeWebhookRun(run: WebhookRunRecord) {
26
27
  requestBodyBytes: run.requestBodyBytes,
27
28
  responseStatus: run.responseStatus,
28
29
  idempotencyKey: run.idempotencyKey,
29
- deliveryClaimResult: run.deliveryClaimResult,
30
30
  error: run.error,
31
31
  }
32
32
  }
33
33
 
34
- export function registerWebhookRunRoutes(app: Elysia, sixb: Sixb<readonly OntologySource[]>) {
34
+ export function registerWebhookRunRoutes(app: Elysia, host: SixbHostView) {
35
35
  return app.get(
36
36
  "/api/webhook-runs",
37
37
  async ({ query, set }) => {
38
38
  try {
39
39
  const parsed = WebhookRunsQuerySchema.parse(query)
40
- const storage = sixb.storage.webhookRuns
40
+ const storage = host.storage.webhookRuns
41
41
  if (!storage) {
42
42
  return unconfiguredStorageResponse(set, "Webhook run storage")
43
43
  }
44
44
 
45
45
  const result = await storage.list({
46
- projectId: sixb.id,
46
+ projectId: host.id,
47
47
  connectorId: parsed.connectorId,
48
48
  webhookId: parsed.webhookId,
49
49
  statuses: parsed.status ? [parsed.status] : undefined,