@shipfox/api-logs 7.1.0 → 8.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/api-logs",
3
3
  "license": "MIT",
4
- "version": "7.1.0",
4
+ "version": "8.0.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -30,18 +30,18 @@
30
30
  "drizzle-orm": "^0.45.2",
31
31
  "zod": "^4.4.3",
32
32
  "@shipfox/api-auth-context": "7.1.0",
33
- "@shipfox/api-agent-dto": "6.0.0",
34
33
  "@shipfox/api-logs-dto": "5.0.0",
35
- "@shipfox/api-workflows-dto": "6.0.0",
34
+ "@shipfox/api-workflows-dto": "8.0.0",
36
35
  "@shipfox/config": "1.2.2",
37
36
  "@shipfox/node-drizzle": "0.3.2",
38
- "@shipfox/node-error-monitoring": "0.2.0",
39
37
  "@shipfox/node-fastify": "0.3.0",
40
38
  "@shipfox/node-module": "0.5.0",
41
- "@shipfox/node-opentelemetry": "0.6.0",
42
39
  "@shipfox/node-outbox": "0.2.4",
40
+ "@shipfox/node-opentelemetry": "0.6.0",
43
41
  "@shipfox/node-postgres": "0.4.2",
44
- "@shipfox/node-temporal": "0.4.0"
42
+ "@shipfox/node-temporal": "0.4.0",
43
+ "@shipfox/node-error-monitoring": "0.2.0",
44
+ "@shipfox/workflow-document": "2.1.1"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "shipfox-swc && shipfox-temporal-bundle dist/temporal/workflows/index.js",
@@ -1,5 +1,4 @@
1
1
  import {Buffer} from 'node:buffer';
2
- import {DEFAULT_HARNESS, type Harness} from '@shipfox/api-agent-dto';
3
2
  import {
4
3
  type LogRecord,
5
4
  parseLogRecordLine,
@@ -8,6 +7,7 @@ import {
8
7
  } from '@shipfox/api-logs-dto';
9
8
  import type {WorkflowsModuleClient} from '@shipfox/api-workflows-dto/inter-module';
10
9
  import {logger} from '@shipfox/node-opentelemetry';
10
+ import {DEFAULT_HARNESS, type Harness} from '@shipfox/workflow-document';
11
11
  import {config} from '#config.js';
12
12
  import {accrueStoredBytes, claimCap, ensureJobAccounting, isJobCapped} from '#db/accounting.js';
13
13
  import {insertChunk} from '#db/chunks.js';
@@ -1,5 +1,5 @@
1
- import type {Harness} from '@shipfox/api-agent-dto';
2
1
  import type {SessionViewRow} from '@shipfox/api-logs-dto';
2
+ import type {Harness} from '@shipfox/workflow-document';
3
3
  import {parseClaudeSessionRecord} from './claude-parser.js';
4
4
  import {parsePiSessionRecord} from './pi-parser.js';
5
5
  import type {AgentSessionRecord} from './session-record.js';
@@ -1,8 +1,7 @@
1
1
  import {Buffer} from 'node:buffer';
2
- import {createLeaseTokenAuthMethod} from '@shipfox/api-auth';
3
2
  import {AUTH_USER} from '@shipfox/api-auth-context';
4
3
  import {type AuthMethod, closeApp, createApp, type FastifyInstance} from '@shipfox/node-fastify';
5
- import {mintLeaseToken} from '#test/fixtures/lease-token.js';
4
+ import {fakeLeaseTokenAuthMethod, mintLeaseToken} from '#test/fixtures/lease-token.js';
6
5
  import {endLine, ndjsonBody, outputLine, recordLine} from '#test/fixtures/ndjson.js';
7
6
  import {createTestWorkflowsClient} from '#test/fixtures/workflows-client.js';
8
7
  import {createLogsRoutes} from './index.js';
@@ -36,7 +35,7 @@ describe('POST /runs/jobs/current/steps/:stepId/logs', () => {
36
35
 
37
36
  beforeAll(async () => {
38
37
  app = await createApp({
39
- auth: [createLeaseTokenAuthMethod(), stubUserAuth],
38
+ auth: [fakeLeaseTokenAuthMethod, stubUserAuth],
40
39
  routes: createLogsRoutes(createTestWorkflowsClient()),
41
40
  swagger: false,
42
41
  });
@@ -1,9 +1,8 @@
1
- import {JOB_LEASE_TOKEN_AUDIENCE} from '@shipfox/api-auth-dto';
2
- import {jobLeaseTokenKey} from '@shipfox/node-auth-root-key';
3
- import {signHs256} from '@shipfox/node-jwt';
1
+ import {AUTH_LEASED_JOB, setLeasedJobContext} from '@shipfox/api-auth-context';
2
+ import {JOB_LEASE_TOKEN_AUDIENCE, type JobLeaseTokenClaims} from '@shipfox/api-auth-dto';
3
+ import {type AuthMethod, ClientError, extractBearerToken} from '@shipfox/node-fastify';
4
4
 
5
- // Matches test/env.ts; the lease-token auth method reads this same value from config.
6
- const SECRET = jobLeaseTokenKey();
5
+ const leaseClaims = new Map<string, JobLeaseTokenClaims>();
7
6
 
8
7
  export interface MintLeaseTokenParams {
9
8
  jobId: string;
@@ -14,30 +13,35 @@ export interface MintLeaseTokenParams {
14
13
  workflowRunAttemptId?: string;
15
14
  currentStepId?: string;
16
15
  currentStepAttempt?: number;
17
- secret?: string;
18
- expiresIn?: string;
19
- audience?: string;
20
16
  }
21
17
 
22
18
  export function mintLeaseToken(params: MintLeaseTokenParams): Promise<string> {
23
- return signHs256({
24
- payload: {
25
- jobId: params.jobId,
26
- jobExecutionId: params.jobExecutionId,
27
- workflowRunId: params.workflowRunId ?? crypto.randomUUID(),
28
- workflowRunAttemptId: params.workflowRunAttemptId ?? crypto.randomUUID(),
29
- projectId: params.projectId ?? crypto.randomUUID(),
30
- workspaceId: params.workspaceId ?? crypto.randomUUID(),
31
- runnerSessionId: crypto.randomUUID(),
32
- ...(params.currentStepId && params.currentStepAttempt !== undefined
33
- ? {
34
- currentStepId: params.currentStepId,
35
- currentStepAttempt: params.currentStepAttempt,
36
- }
37
- : {}),
38
- },
39
- secret: params.secret ?? SECRET,
40
- expiresIn: params.expiresIn ?? '90m',
41
- audience: params.audience ?? JOB_LEASE_TOKEN_AUDIENCE,
19
+ const token = `test-auth-${crypto.randomUUID()}`;
20
+ leaseClaims.set(token, {
21
+ jobId: params.jobId,
22
+ jobExecutionId: params.jobExecutionId,
23
+ workflowRunId: params.workflowRunId ?? crypto.randomUUID(),
24
+ workflowRunAttemptId: params.workflowRunAttemptId ?? crypto.randomUUID(),
25
+ projectId: params.projectId ?? crypto.randomUUID(),
26
+ workspaceId: params.workspaceId ?? crypto.randomUUID(),
27
+ runnerSessionId: crypto.randomUUID(),
28
+ ...(params.currentStepId && params.currentStepAttempt !== undefined
29
+ ? {currentStepId: params.currentStepId, currentStepAttempt: params.currentStepAttempt}
30
+ : {}),
31
+ aud: JOB_LEASE_TOKEN_AUDIENCE,
32
+ iat: 0,
33
+ exp: Number.MAX_SAFE_INTEGER,
42
34
  });
35
+ return Promise.resolve(token);
43
36
  }
37
+
38
+ export const fakeLeaseTokenAuthMethod: AuthMethod = {
39
+ name: AUTH_LEASED_JOB,
40
+ authenticate: (request) => {
41
+ const token = extractBearerToken(request.headers.authorization);
42
+ const claims = token ? leaseClaims.get(token) : undefined;
43
+ if (!claims) throw new ClientError('Authentication required', 'unauthorized', {status: 401});
44
+ setLeasedJobContext(request, claims);
45
+ return Promise.resolve();
46
+ },
47
+ };