@shipfox/annotations 6.0.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +4 -21
- package/src/presentation/routes/write-annotations.test.ts +2 -3
- package/test/fixtures/lease-token.ts +32 -27
- package/test/index.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipfox/annotations",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "8.0.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/ShipfoxHQ/shipfox.git",
|
|
@@ -25,31 +25,14 @@
|
|
|
25
25
|
"drizzle-orm": "^0.45.2",
|
|
26
26
|
"zod": "^4.4.3",
|
|
27
27
|
"@shipfox/annotations-dto": "6.0.0",
|
|
28
|
-
"@shipfox/api-auth-context": "
|
|
28
|
+
"@shipfox/api-auth-context": "7.1.0",
|
|
29
29
|
"@shipfox/config": "1.2.2",
|
|
30
30
|
"@shipfox/inter-module": "0.2.0",
|
|
31
31
|
"@shipfox/node-drizzle": "0.3.2",
|
|
32
|
-
"@shipfox/node-fastify": "0.
|
|
33
|
-
"@shipfox/node-module": "0.
|
|
32
|
+
"@shipfox/node-fastify": "0.3.0",
|
|
33
|
+
"@shipfox/node-module": "0.5.0",
|
|
34
34
|
"@shipfox/node-postgres": "0.4.2"
|
|
35
35
|
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/pg": "^8.15.5",
|
|
38
|
-
"drizzle-kit": "^0.31.10",
|
|
39
|
-
"fastify": "^5.3.3",
|
|
40
|
-
"fastify-type-provider-zod": "^6.0.0",
|
|
41
|
-
"fishery": "^2.4.0",
|
|
42
|
-
"@shipfox/node-auth-root-key": "0.2.0",
|
|
43
|
-
"@shipfox/api-auth": "6.0.0",
|
|
44
|
-
"@shipfox/api-auth-dto": "6.0.0",
|
|
45
|
-
"@shipfox/biome": "1.8.2",
|
|
46
|
-
"@shipfox/depcruise": "1.0.2",
|
|
47
|
-
"@shipfox/node-jwt": "0.3.0",
|
|
48
|
-
"@shipfox/swc": "1.2.6",
|
|
49
|
-
"@shipfox/ts-config": "1.3.8",
|
|
50
|
-
"@shipfox/typescript": "1.1.7",
|
|
51
|
-
"@shipfox/vitest": "1.2.3"
|
|
52
|
-
},
|
|
53
36
|
"scripts": {
|
|
54
37
|
"build": "shipfox-swc",
|
|
55
38
|
"check": "shipfox-biome-check",
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {createLeaseTokenAuthMethod} from '@shipfox/api-auth';
|
|
2
1
|
import {AUTH_LEASED_JOB} from '@shipfox/api-auth-context';
|
|
3
2
|
import {closeApp, createApp, type FastifyInstance} from '@shipfox/node-fastify';
|
|
4
3
|
import {eq} from 'drizzle-orm';
|
|
5
4
|
import {db} from '#db/db.js';
|
|
6
5
|
import {annotations} from '#db/schema/annotations.js';
|
|
7
|
-
import {mintLeaseToken} from '#test/index.js';
|
|
6
|
+
import {fakeLeaseTokenAuthMethod, mintLeaseToken} from '#test/index.js';
|
|
8
7
|
import {writeAnnotationsRoute} from './write-annotations.js';
|
|
9
8
|
|
|
10
9
|
function annotationsUrl(): string {
|
|
@@ -31,7 +30,7 @@ describe('POST /runs/jobs/current/annotations', () => {
|
|
|
31
30
|
|
|
32
31
|
beforeAll(async () => {
|
|
33
32
|
app = await createApp({
|
|
34
|
-
auth: [
|
|
33
|
+
auth: [fakeLeaseTokenAuthMethod],
|
|
35
34
|
routes: [
|
|
36
35
|
{prefix: '/runs/jobs/current', auth: AUTH_LEASED_JOB, routes: [writeAnnotationsRoute]},
|
|
37
36
|
],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
const
|
|
5
|
+
const leaseClaims = new Map<string, JobLeaseTokenClaims>();
|
|
6
6
|
|
|
7
7
|
export interface MintLeaseTokenParams {
|
|
8
8
|
jobId: string;
|
|
@@ -14,31 +14,36 @@ export interface MintLeaseTokenParams {
|
|
|
14
14
|
workflowRunAttemptId?: string;
|
|
15
15
|
currentStepId?: string;
|
|
16
16
|
currentStepAttempt?: number;
|
|
17
|
-
secret?: string;
|
|
18
|
-
expiresIn?: string;
|
|
19
|
-
audience?: string;
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
export function mintLeaseToken(params: MintLeaseTokenParams): Promise<string> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
secret: params.secret ?? SECRET,
|
|
41
|
-
expiresIn: params.expiresIn ?? '90m',
|
|
42
|
-
audience: params.audience ?? JOB_LEASE_TOKEN_AUDIENCE,
|
|
20
|
+
const token = `test-auth-${crypto.randomUUID()}`;
|
|
21
|
+
leaseClaims.set(token, {
|
|
22
|
+
jobId: params.jobId,
|
|
23
|
+
jobExecutionId: params.jobExecutionId,
|
|
24
|
+
workflowRunId: params.workflowRunId ?? crypto.randomUUID(),
|
|
25
|
+
workflowRunAttempt: params.workflowRunAttempt ?? 1,
|
|
26
|
+
workflowRunAttemptId: params.workflowRunAttemptId ?? crypto.randomUUID(),
|
|
27
|
+
projectId: params.projectId ?? crypto.randomUUID(),
|
|
28
|
+
workspaceId: params.workspaceId ?? crypto.randomUUID(),
|
|
29
|
+
runnerSessionId: crypto.randomUUID(),
|
|
30
|
+
...(params.currentStepId && params.currentStepAttempt !== undefined
|
|
31
|
+
? {currentStepId: params.currentStepId, currentStepAttempt: params.currentStepAttempt}
|
|
32
|
+
: {}),
|
|
33
|
+
aud: JOB_LEASE_TOKEN_AUDIENCE,
|
|
34
|
+
iat: 0,
|
|
35
|
+
exp: Number.MAX_SAFE_INTEGER,
|
|
43
36
|
});
|
|
37
|
+
return Promise.resolve(token);
|
|
44
38
|
}
|
|
39
|
+
|
|
40
|
+
export const fakeLeaseTokenAuthMethod: AuthMethod = {
|
|
41
|
+
name: AUTH_LEASED_JOB,
|
|
42
|
+
authenticate: (request) => {
|
|
43
|
+
const token = extractBearerToken(request.headers.authorization);
|
|
44
|
+
const claims = token ? leaseClaims.get(token) : undefined;
|
|
45
|
+
if (!claims) throw new ClientError('Authentication required', 'unauthorized', {status: 401});
|
|
46
|
+
setLeasedJobContext(request, claims);
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
},
|
|
49
|
+
};
|
package/test/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {annotationFactory} from './factories/annotation.js';
|
|
2
|
-
export {mintLeaseToken} from './fixtures/lease-token.js';
|
|
2
|
+
export {fakeLeaseTokenAuthMethod, mintLeaseToken} from './fixtures/lease-token.js';
|