Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.265.0](https://github.com/opengovsg/FormSG/compare/v6.264.0...v6.265.0)

- fix(deps): bump playwright and @playwright/test [`#8827`](https://github.com/opengovsg/FormSG/pull/8827)
- build(deps): bump tar-fs from 3.1.0 to 3.1.1 in /serverless/pdf-gen-sparticuz [`#8758`](https://github.com/opengovsg/FormSG/pull/8758)
- fix(deps): bump validator from 13.15.15 to 13.15.20 in /shared [`#8840`](https://github.com/opengovsg/FormSG/pull/8840)
- fix(deps): bump validator from 13.12.0 to 13.15.20 [`#8844`](https://github.com/opengovsg/FormSG/pull/8844)
- build(deps): bump validator from 13.7.0 to 13.15.20 in /frontend [`#8845`](https://github.com/opengovsg/FormSG/pull/8845)
- feat: pinning pdf to generate from lambda [`#8858`](https://github.com/opengovsg/FormSG/pull/8858)
- build: merge release v6.264.0 to develop [`#8855`](https://github.com/opengovsg/FormSG/pull/8855)
- build: release v6.264.0 [`#8853`](https://github.com/opengovsg/FormSG/pull/8853)

#### [v6.264.0](https://github.com/opengovsg/FormSG/compare/v6.263.0...v6.264.0)

> 3 November 2025

- feat(i18n): extract text from various modals [`#8843`](https://github.com/opengovsg/FormSG/pull/8843)
- build: merge release v6.263. to develop [`#8848`](https://github.com/opengovsg/FormSG/pull/8848)
- build: release v6.263.0 [`#8847`](https://github.com/opengovsg/FormSG/pull/8847)
- chore: bump version to v6.264.0 [`6dbbae0`](https://github.com/opengovsg/FormSG/commit/6dbbae04ad0d0d574bd9188ab11d26ebc3369d67)

#### [v6.263.0](https://github.com/opengovsg/FormSG/compare/v6.262.0...v6.263.0)

Expand Down
18 changes: 9 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-frontend",
"version": "6.264.0",
"version": "6.265.0",
"homepage": ".",
"type": "module",
"private": true,
Expand Down Expand Up @@ -91,7 +91,7 @@
"type-fest": "^4.17.0",
"typescript": "^5.4.5",
"use-draggable-scroll": "^0.1.0",
"validator": "^13.7.0",
"validator": "^13.15.20",
"vite-plugin-node-stdlib-browser": "^0.2.1",
"zustand": "^4.1.1"
},
Expand Down
37 changes: 19 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FormSG",
"description": "Form Manager for Government",
"version": "6.264.0",
"version": "6.265.0",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down Expand Up @@ -154,14 +154,14 @@
"ulid": "^2.3.0",
"uuid": "^11.1.0",
"uuid-by-string": "^4.0.0",
"validator": "^13.12.0",
"validator": "^13.15.20",
"winston": "^3.13.0",
"winston-cloudwatch": "^6.3.0",
"zod": "^3.24.3"
},
"devDependencies": {
"@opengovsg/mockpass": "^4.3.4",
"@playwright/test": "^1.53.0",
"@playwright/test": "^1.56.1",
"@types/bcrypt": "^5.0.0",
"@types/bluebird": "^3.5.42",
"@types/body-parser": "^1.19.6",
Expand Down
6 changes: 3 additions & 3 deletions serverless/pdf-gen-sparticuz/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions shared/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 2 additions & 65 deletions src/app/utils/__tests__/convert-html-to-pdf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,6 @@ describe('convert-html-to-pdf', () => {
beforeEach(() => {
AwsConfig.pdfGeneratorLambda.invoke = jest.fn()
})
it('should not invoke lambda and just return local output when AwsConfig.pdfGeneratorLambdaFunctionName is empty', async () => {
// Arrange
const mockLocalBuffer = Buffer.from('local pdf content')
AwsConfig.pdfGeneratorLambdaFunctionName = ''

// Mock local response
const mockPage = {
setContent: jest.fn(),
pdf: jest.fn().mockResolvedValue(mockLocalBuffer),
}
const mockBrowser = {
newPage: jest.fn().mockResolvedValue(mockPage),
close: jest.fn(),
}
;(puppeteer.launch as jest.Mock).mockResolvedValue(mockBrowser)

// Act
const result = await generatePdfFromHtml(MOCK_HTML, true)

// Assert
expect(result).toEqual(mockLocalBuffer)
expect(AwsConfig.pdfGeneratorLambda.invoke).not.toHaveBeenCalled()
})

it('should use lambda output when isUseLambdaOutput is true and not use local output and AwsConfig.pdfGeneratorLambdaFunctionName is defined', async () => {
// Arrange
Expand Down Expand Up @@ -225,46 +202,6 @@ describe('convert-html-to-pdf', () => {
})
})

it('should use local output when isUseLambdaOutput is false and not use lambda output and AwsConfig.pdfGeneratorLambdaFunctionName is defined', async () => {
// Arrange
const mockLambdaBuffer = Buffer.from('lambda pdf content')
const mockLocalBuffer = Buffer.from('local pdf content')

const DUMMY_PDF_GENERATOR_FUNCTION_NAME =
'dummy-pdf-generator-function-name'
AwsConfig.pdfGeneratorLambdaFunctionName =
DUMMY_PDF_GENERATOR_FUNCTION_NAME

// Mock lambda response
const mockLambdaResponse = {
Payload: JSON.stringify({
statusCode: 200,
body: mockLambdaBuffer.toString('base64'),
}),
}
;(AwsConfig.pdfGeneratorLambda.invoke as jest.Mock).mockResolvedValueOnce(
mockLambdaResponse,
)

// Mock local response
const mockPage = {
setContent: jest.fn(),
pdf: jest.fn().mockResolvedValue(mockLocalBuffer),
}
const mockBrowser = {
newPage: jest.fn().mockResolvedValue(mockPage),
close: jest.fn(),
}
;(puppeteer.launch as jest.Mock).mockResolvedValue(mockBrowser)

// Act
const result = await generatePdfFromHtml(MOCK_HTML, false)

// Assert
expect(result).toEqual(mockLocalBuffer)
expect(result).not.toEqual(mockLambdaBuffer)
})

it('should generate PDFs using both methods in parallel regardless of isUseLambdaOutput setting if AwsConfig.pdfGeneratorLambdaFunctionName is defined', async () => {
// Arrange
const mockLambdaBuffer = Buffer.from('lambda pdf content')
Expand Down Expand Up @@ -307,8 +244,8 @@ describe('convert-html-to-pdf', () => {
// Assert
// Both lambda and local generation should be called for each invocation
expect(AwsConfig.pdfGeneratorLambda.invoke).toHaveBeenCalledTimes(2)
expect(puppeteer.launch).toHaveBeenCalledTimes(2)
expect(mockPage.pdf).toHaveBeenCalledTimes(2)
expect(puppeteer.launch).toHaveBeenCalledTimes(0)
expect(mockPage.pdf).toHaveBeenCalledTimes(0)

// Verify the lambda invocation parameters
expect(AwsConfig.pdfGeneratorLambda.invoke).toHaveBeenCalledWith({
Expand Down
50 changes: 8 additions & 42 deletions src/app/utils/convert-html-to-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,6 @@ export const generatePdfFromHtml = async (
meta: logMeta,
})

const localStopwatch = startStopwatch()
const localResult = generatePdfFromHtmlLocally(summaryHtml).then((result) => {
const latencyMs = localStopwatch.stop()
logger.info({
message: 'Successfully generated pdf from html using local',
meta: { ...logMeta, latencyMs },
})
submitPdfGenerationLatencyMetric({
latencyMs,
isLocal: true,
})
return result
})

const isPdfGenerationLambdaConfigured =
!!AwsConfig.pdfGeneratorLambdaFunctionName
if (!isPdfGenerationLambdaConfigured) {
logger.info({
message:
'Pdf generation lambda is not configured - using result from local pdf generation',
meta: logMeta,
})
return localResult
}

const lambdaStopwatch = startStopwatch()
const lambdaResultAsync = generatePdfFromHtmlLambda(summaryHtml).map(
(result) => {
Expand All @@ -187,31 +162,22 @@ export const generatePdfFromHtml = async (
},
)

if (isUseLambdaOutput) {
const lambdaResult = await lambdaResultAsync
if (lambdaResult.isErr()) {
logger.error({
message: 'Error generating pdf from html using lambda',
meta: logMeta,
error: lambdaResult.error,
})
throw lambdaResult.error
}

logger.info({
message:
'Successfully generated pdf from html - using result from lambda pdf generation',
const lambdaResult = await lambdaResultAsync
if (lambdaResult.isErr()) {
logger.error({
message: 'Error generating pdf from html using lambda',
meta: logMeta,
error: lambdaResult.error,
})
return lambdaResult.value
throw lambdaResult.error
}

logger.info({
message:
'Successfully generated pdf from html - using result from local pdf generation',
'Successfully generated pdf from html - using result from lambda pdf generation',
meta: logMeta,
})
return await localResult
return lambdaResult.value
}

export const _generatePdfFromHtmlLocallyForTest = generatePdfFromHtmlLocally
Expand Down
Loading