@shipfox/api-logs 4.0.0 → 6.0.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 (37) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +52 -0
  3. package/dist/config.d.ts +1 -0
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +5 -10
  6. package/dist/config.js.map +1 -1
  7. package/dist/core/append-logs.d.ts +2 -6
  8. package/dist/core/append-logs.d.ts.map +1 -1
  9. package/dist/core/append-logs.js +7 -16
  10. package/dist/core/append-logs.js.map +1 -1
  11. package/dist/index.d.ts +5 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +63 -59
  14. package/dist/index.js.map +1 -1
  15. package/dist/presentation/routes/append-logs.d.ts +2 -1
  16. package/dist/presentation/routes/append-logs.d.ts.map +1 -1
  17. package/dist/presentation/routes/append-logs.js +61 -61
  18. package/dist/presentation/routes/append-logs.js.map +1 -1
  19. package/dist/presentation/routes/index.d.ts +2 -1
  20. package/dist/presentation/routes/index.d.ts.map +1 -1
  21. package/dist/presentation/routes/index.js +25 -23
  22. package/dist/presentation/routes/index.js.map +1 -1
  23. package/dist/tsconfig.test.tsbuildinfo +1 -1
  24. package/package.json +27 -34
  25. package/src/config.test.ts +8 -32
  26. package/src/config.ts +10 -15
  27. package/src/core/append-logs.test.ts +13 -19
  28. package/src/core/append-logs.ts +12 -20
  29. package/src/index.ts +63 -51
  30. package/src/presentation/routes/append-logs.test.ts +3 -2
  31. package/src/presentation/routes/append-logs.ts +54 -50
  32. package/src/presentation/routes/index.ts +22 -19
  33. package/src/presentation/routes/read-logs.test.ts +3 -2
  34. package/test/env.ts +1 -3
  35. package/test/fixtures/lease-token.ts +2 -1
  36. package/test/fixtures/workflows-client.ts +17 -0
  37. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,27 +1,30 @@
1
1
  import {AUTH_LEASED_JOB, AUTH_USER} from '@shipfox/api-auth-context';
2
+ import type {WorkflowsModuleClient} from '@shipfox/api-workflows-dto/inter-module';
2
3
  import {createRawBodyPlugin, type RouteGroup} from '@shipfox/node-fastify';
3
4
  import {config} from '#config.js';
4
- import {appendLogsRoute} from './append-logs.js';
5
+ import {createAppendLogsRoute} from './append-logs.js';
5
6
  import {readLogsRoute} from './read-logs.js';
6
7
 
7
8
  // Keep the lease-authed append in its own Fastify scope so the raw NDJSON parser does not
8
9
  // disturb the JSON read route (or workflow routes). The body limit also bounds one-append
9
10
  // budget overshoot. The read route is session-authed and workspace-scoped via the row.
10
- export const logsRoutes: RouteGroup[] = [
11
- {
12
- prefix: '/runs/jobs/current',
13
- auth: AUTH_LEASED_JOB,
14
- plugins: [
15
- createRawBodyPlugin({
16
- contentType: 'application/x-ndjson',
17
- bodyLimit: config.LOG_APPEND_BODY_LIMIT_BYTES,
18
- }),
19
- ],
20
- routes: [appendLogsRoute],
21
- },
22
- {
23
- prefix: '/steps',
24
- auth: AUTH_USER,
25
- routes: [readLogsRoute],
26
- },
27
- ];
11
+ export function createLogsRoutes(workflows: WorkflowsModuleClient): RouteGroup[] {
12
+ return [
13
+ {
14
+ prefix: '/runs/jobs/current',
15
+ auth: AUTH_LEASED_JOB,
16
+ plugins: [
17
+ createRawBodyPlugin({
18
+ contentType: 'application/x-ndjson',
19
+ bodyLimit: config.LOG_APPEND_BODY_LIMIT_BYTES,
20
+ }),
21
+ ],
22
+ routes: [createAppendLogsRoute(workflows)],
23
+ },
24
+ {
25
+ prefix: '/steps',
26
+ auth: AUTH_USER,
27
+ routes: [readLogsRoute],
28
+ },
29
+ ];
30
+ }
@@ -35,9 +35,10 @@ import {
35
35
  compactStreamActivity,
36
36
  } from '#temporal/activities/compact-stream.js';
37
37
  import {ndjsonBody, outputLine, recordLine} from '#test/fixtures/ndjson.js';
38
+ import {createTestWorkflowsClient} from '#test/fixtures/workflows-client.js';
38
39
  import {findStream} from '#test/queries.js';
39
40
  import {onStepAttemptTerminated} from '../subscribers/on-step-attempt-terminated.js';
40
- import {logsRoutes} from './index.js';
41
+ import {createLogsRoutes} from './index.js';
41
42
 
42
43
  // AUTH_USER stub: a `Bearer user` request is a member of whatever workspace it names in the
43
44
  // `x-test-workspace` header, so each test grants or withholds access against the arranged
@@ -159,7 +160,7 @@ describe('GET /steps/:stepId/attempts/:attempt/logs', () => {
159
160
  beforeAll(async () => {
160
161
  app = await createApp({
161
162
  auth: [fakeUserAuth, stubLeaseAuth],
162
- routes: logsRoutes,
163
+ routes: createLogsRoutes(createTestWorkflowsClient()),
163
164
  swagger: false,
164
165
  });
165
166
  await app.ready();
package/test/env.ts CHANGED
@@ -4,9 +4,7 @@ process.env.POSTGRES_USERNAME ??= 'shipfox';
4
4
  process.env.POSTGRES_PASSWORD ??= 'password';
5
5
  process.env.POSTGRES_DATABASE = 'api_test';
6
6
  process.env.POSTGRES_MAX_CONNECTIONS ??= '5';
7
- process.env.AUTH_JWT_SECRET = 'test-secret';
8
- process.env.AUTH_JOB_LEASE_TOKEN_SECRET = 'test-lease-secret';
9
- process.env.AUTH_RUNNER_SESSION_TOKEN_SECRET = 'test-runner-session-secret';
7
+ process.env.AUTH_ROOT_KEY = 'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=';
10
8
  process.env.SECRETS_ENCRYPTION_KEK = 'ZmVkY2JhOTg3NjU0MzIxMGZlZGNiYTk4NzY1NDMyMTA=';
11
9
 
12
10
  // Small accrual budget so cap/budget tests use tiny payloads: base 100 bytes,
@@ -1,8 +1,9 @@
1
1
  import {JOB_LEASE_TOKEN_AUDIENCE} from '@shipfox/api-auth-dto';
2
+ import {jobLeaseTokenKey} from '@shipfox/node-auth-root-key';
2
3
  import {signHs256} from '@shipfox/node-jwt';
3
4
 
4
5
  // Matches test/env.ts; the lease-token auth method reads this same value from config.
5
- const SECRET = process.env.AUTH_JOB_LEASE_TOKEN_SECRET ?? 'test-lease-secret';
6
+ const SECRET = jobLeaseTokenKey();
6
7
 
7
8
  export interface MintLeaseTokenParams {
8
9
  jobId: string;
@@ -0,0 +1,17 @@
1
+ import {
2
+ type WorkflowsModuleClient,
3
+ workflowsInterModuleContract,
4
+ } from '@shipfox/api-workflows-dto/inter-module';
5
+ import {defineInterModulePresentation} from '@shipfox/inter-module';
6
+ import {createFakeInterModuleClients} from '@shipfox/node-module/inter-module/testing';
7
+
8
+ export function createTestWorkflowsClient(): WorkflowsModuleClient {
9
+ return createFakeInterModuleClients({
10
+ workflows: defineInterModulePresentation(workflowsInterModuleContract, {
11
+ startRunFromTrigger: vi.fn(),
12
+ deliverEventToJobListener: vi.fn(),
13
+ getStepLogContext: () => ({harness: 'pi' as const}),
14
+ getLeasedAgentToolContext: vi.fn(),
15
+ }),
16
+ }).workflows;
17
+ }