Skip to content

Commit cdb275c

Browse files
committed
code review fixes
1 parent de1c1e7 commit cdb275c

File tree

12 files changed

+255
-225
lines changed

12 files changed

+255
-225
lines changed

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"license": "ISC",
1313
"devDependencies": {
1414
"@codecov/vite-plugin": "^1.9.1",
15+
"@types/node": "^25.2.3",
1516
"typescript": "^5.9.3",
1617
"vite": "^7.3.1",
1718
"vitest": "^4.0.18"
@@ -27,7 +28,6 @@
2728
"@furystack/shades": "^12.0.1",
2829
"@furystack/shades-common-components": "^12.1.0",
2930
"@furystack/utils": "^8.1.10",
30-
"@types/node": "^25.2.3",
3131
"common": "workspace:^"
3232
}
3333
}

service/src/app-models/identity/actions/password-reset-action.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import type { PasswordResetAction as PasswordResetActionType } from 'common'
88
export const PasswordResetAction: RequestAction<PasswordResetActionType> = async ({ injector, getBody }) => {
99
const logger = getLogger(injector).withScope('PasswordReset')
1010

11-
const postBody = await getBody()
12-
const { currentPassword, newPassword } = postBody as { currentPassword: string; newPassword: string }
11+
const { currentPassword, newPassword } = await getBody()
1312

1413
const currentUser = await getCurrentUser(injector)
1514

service/src/app-models/install/service-installer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export class ServiceStatusProvider {
2929
}
3030

3131
@Injected(StoreManager)
32-
declare public storeManager: StoreManager
32+
declare private storeManager: StoreManager
3333

3434
@Injected(PasswordAuthenticator)
35-
declare public authenticator: PasswordAuthenticator
35+
declare private authenticator: PasswordAuthenticator
3636

3737
@Injected(LoggerCollection)
38-
declare public logger: LoggerCollection
38+
declare private logger: LoggerCollection
3939
}

service/src/app-models/services/actions/service-lifecycle-action.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync, mkdirSync, rmSync } from 'fs'
2-
import { dirname, join } from 'path'
2+
import { dirname, join, resolve } from 'path'
33

44
import { getLogger } from '@furystack/logging'
55
import { resolvePath } from '../../../utils/resolve-path.js'
@@ -71,6 +71,11 @@ export const ServiceLifecycleAction =
7171
}
7272

7373
const cwd = resolvePath(getServiceCwd(stack, svc, repo))
74+
const stackRoot = resolve(resolvePath(stack.mainDirectory))
75+
if (!cwd.startsWith(stackRoot)) {
76+
throw new RequestError(`Resolved path "${cwd}" is outside the stack directory "${stackRoot}"`, 400)
77+
}
78+
7479
const git = injector.getInstance(GitService)
7580
const isGitRepo = existsSync(cwd) && existsSync(join(cwd, '.git'))
7681

service/src/app-models/tokens/setup-tokens-rest-api.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CreateTokenAction: RequestAction<CreateTokenEndpoint> = async ({ injector,
2020
throw new RequestError('Not authenticated', 401)
2121
}
2222

23-
const { name } = (await getBody()) as { name: string }
23+
const { name } = await getBody()
2424
const plainTextToken = randomBytes(32).toString('hex')
2525
const tokenHash = createHash('sha256').update(plainTextToken).digest('hex')
2626

@@ -91,8 +91,9 @@ const populatePublicTokenStore = async (injector: Injector) => {
9191
const allTokens = await sm.getStoreFor(ApiToken, 'id').find({})
9292
const publicStore = sm.getStoreFor(PublicApiToken, 'id')
9393

94-
for (const { tokenHash: _hash, ...publicToken } of allTokens) {
95-
await publicStore.add(publicToken)
94+
const publicTokens = allTokens.map(({ tokenHash: _hash, ...rest }) => rest)
95+
if (publicTokens.length > 0) {
96+
await publicStore.add(...publicTokens)
9697
}
9798
}
9899

service/src/get-cors-options.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ import { getCorsOptions } from './get-cors-options.js'
33

44
describe('getCorsOptions', () => {
55
it('should return CORS options with credentials enabled', () => {
6-
const options = getCorsOptions()
6+
const options = getCorsOptions({})
77
expect(options.credentials).toBe(true)
88
})
99

10-
it('should allow localhost:8080 as origin', () => {
11-
const options = getCorsOptions()
10+
it('should allow localhost:8080 as default origin', () => {
11+
const options = getCorsOptions({})
1212
expect(options.origins).toContain('http://localhost:8080')
1313
})
1414

15+
it('should use CORS_ORIGINS env var when set', () => {
16+
const options = getCorsOptions({ CORS_ORIGINS: 'https://app.example.com, https://admin.example.com' })
17+
expect(options.origins).toEqual(['https://app.example.com', 'https://admin.example.com'])
18+
})
19+
1520
it('should include required HTTP methods', () => {
16-
const options = getCorsOptions()
21+
const options = getCorsOptions({})
1722
expect(options.methods).toEqual(expect.arrayContaining(['GET', 'POST', 'PATCH', 'DELETE']))
1823
})
1924

2025
it('should include content-type in allowed headers', () => {
21-
const options = getCorsOptions()
26+
const options = getCorsOptions({})
2227
expect(options.headers).toContain('content-type')
2328
})
2429
})

service/src/get-cors-options.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { CorsOptions } from '@furystack/rest-service'
22

3-
export const getCorsOptions = (): CorsOptions => ({
3+
const DEFAULT_ORIGINS = ['http://localhost:8080']
4+
5+
export const getCorsOptions = (env = process.env): CorsOptions => ({
46
credentials: true,
5-
origins: ['http://localhost:8080'],
7+
origins: env.CORS_ORIGINS ? env.CORS_ORIGINS.split(',').map((o) => o.trim()) : DEFAULT_ORIGINS,
68
headers: ['cache', 'content-type'],
79
methods: ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'],
810
})

0 commit comments

Comments
 (0)