Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/merge files #1457

Merged
merged 19 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bfc9187
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 17, 2025
c18a36b
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 17, 2025
9c96e17
Merge remote-tracking branch 'origin/tech/node-22' into feature/merge…
nils-arne Feb 17, 2025
c9f971d
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 17, 2025
6b03d7b
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 17, 2025
f479706
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 19, 2025
40c5caa
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 19, 2025
54c8028
Endringer for sammenslåing av førsteside med søknad
nils-arne Feb 19, 2025
ea3970a
Endringer for sammenslåing av førsteside med søknad. Lagt til logging…
nils-arne Feb 19, 2025
213bc4a
Endringer for sammenslåing av førsteside med søknad. Nais konfigurasjon
nils-arne Feb 20, 2025
5ed31b3
Endringer for forberedelse til PR
nils-arne Feb 24, 2025
cab39ca
Merge remote-tracking branch 'origin/master' into feature/merge-files
nils-arne Feb 24, 2025
f26b881
Merging fra master og fikset pakke versjoner
nils-arne Feb 25, 2025
0b922c2
Oppdatering etter PR. Midlertidig beholdt ubrukt kode for generering …
nils-arne Mar 5, 2025
f25f18c
Oppdatering etter PR. Fjernet ubrukt kode for å generere PDF av søkna…
nils-arne Mar 5, 2025
c549e45
Merge remote-tracking branch 'origin/master' into feature/merge-files
nils-arne Mar 5, 2025
555f3e5
Merge branch 'master' into feature/merge-files
lotorvik Mar 5, 2025
720a89e
Lagt til håndtering av språk ved kall til Gotenberg
nils-arne Mar 12, 2025
5675c66
Merge remote-tracking branch 'origin/feature/merge-files' into featur…
nils-arne Mar 12, 2025
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
4 changes: 4 additions & 0 deletions .nais/fyllut/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ spec:
value: {{skjemabygging-proxy-url}}
- name: SKJEMABYGGING_PROXY_CLIENT_ID
value: {{skjemabygging-proxy-client-id}}
- name: GOTENBERG_URL
value: {{gotenberg-url}}
- name: GOTENBERG_URL_EN
value: {{gotenberg-url-en}}
- name: SEND_INN_TOKEN_X_CLIENT_ID
value: {{send-inn-token-x-client-id}}
- name: SEND_INN_HOST
Expand Down
5 changes: 5 additions & 0 deletions .nais/fyllut/dev-delingslenke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
gotenberg-url-en: http://upload-convert-to-pdf-en.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
forms-api-url: https://forms-api.nav.no
Expand Down Expand Up @@ -37,6 +39,9 @@ accessPolicy:
- application: formio-enterprise-server
namespace: skjemadigitalisering
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
cluster: dev-gcp
- application: innsending-api
namespace: team-soknad
cluster: dev-gcp
Expand Down
5 changes: 5 additions & 0 deletions .nais/fyllut/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
gotenberg-url-en: http://upload-convert-to-pdf-en.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand All @@ -29,6 +31,9 @@ accessPolicy:
- application: skjemabygging-proxy
namespace: skjemadigitalisering
cluster: dev-fss
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
cluster: dev-gcp
- application: innsending-api
namespace: team-soknad
cluster: dev-gcp
Expand Down
5 changes: 5 additions & 0 deletions .nais/fyllut/preprod-alt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
gotenberg-url-en: http://upload-convert-to-pdf-en.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand Down Expand Up @@ -38,6 +40,9 @@ accessPolicy:
- application: formio-api
namespace: skjemadigitalisering
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
cluster: dev-gcp
- application: innsending-api
namespace: team-soknad
cluster: dev-gcp
Expand Down
5 changes: 5 additions & 0 deletions .nais/fyllut/preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 95170319-b4d7-4190-8271-118ed19bafbf
skjemabygging-proxy-url: https://skjemabygging-proxy.dev-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
gotenberg-url-en: http://upload-convert-to-pdf-en.fyllut-sendinn
send-inn-token-x-client-id: dev-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand Down Expand Up @@ -39,6 +41,9 @@ accessPolicy:
- application: formio-api
namespace: skjemadigitalisering
cluster: dev-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
cluster: dev-gcp
- application: innsending-api
namespace: team-soknad
cluster: dev-gcp
Expand Down
5 changes: 5 additions & 0 deletions .nais/fyllut/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ foersteside-url: https://www.nav.no/soknader/api/forsteside
dekorator-url: https://www.nav.no/dekoratoren?simple=true
skjemabygging-proxy-client-id: 031863f2-9881-44af-ace5-6b5ab52afeb1
skjemabygging-proxy-url: https://skjemabygging-proxy.prod-fss-pub.nais.io
gotenberg-url: http://upload-convert-to-pdf.fyllut-sendinn
gotenberg-url-en: http://upload-convert-to-pdf-en.fyllut-sendinn
send-inn-token-x-client-id: prod-gcp:team-soknad:innsending-api
send-inn-host: http://innsending-api.team-soknad
kodeverk:
Expand All @@ -33,6 +35,9 @@ accessPolicy:
- application: innsending-api
namespace: team-soknad
cluster: prod-gcp
- application: upload-convert-to-pdf
namespace: fyllut-sendinn
cluster: prod-gcp
- application: pdl-api
namespace: pdl
cluster: prod-fss
Expand Down
2 changes: 1 addition & 1 deletion packages/bygger-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/node-jose": "^1.1.13",
"@types/uuid": "^10.0.0",
"memorystream": "^0.3.1",
"nock": "^13.5.6",
"nock": "^14",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spesifiser versjon

"vite-plugin-node": "^4.0.0",
"vitest-mock-extended": "^2.0.2"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/fyllut-backend/icons/nav-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions packages/fyllut-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"prom-client": "^15.1.3",
"qs": "^6.14.0",
"react": "^18.3.1",
"vite-plugin-static-copy": "^2.2.0",
"winston": "^3.17.0"
},
"devDependencies": {
Expand All @@ -51,8 +52,9 @@
"@types/node-fetch": "^2.6.12",
"@types/node-jose": "^1.1.13",
"@types/supertest": "^6.0.2",
"nock": "^13.5.6",
"nock": "^14.0.1",
"supertest": "^7.0.0",
"vite-plugin-node": "^4.0.0"
"vite-plugin-node": "^4.0.0",
"vite-plugin-static-copy": "^2.2.0"
}
}
4 changes: 4 additions & 0 deletions packages/fyllut-backend/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const localDevelopmentConfig: DefaultConfig = {
forstesideUrl: 'https://www.nav.no/soknader/api/forsteside',
decoratorUrl: 'https://www.nav.no/dekoratoren?simple=true',
skjemabyggingProxyUrl: process.env.SKJEMABYGGING_PROXY_URL || 'https://skjemabygging-proxy.dev-fss-pub.nais.io',
gotenbergUrl: process.env.GOTENBERG_URL || 'https://convert-to-pdf.intern.dev.nav.no',
gotenbergUrlEn: process.env.GOTENBERG_URL_EN || 'https://convert-to-pdf-en.intern.dev.nav.no',
skjemabyggingProxyClientId: '95170319-b4d7-4190-8271-118ed19bafbf',
azureOpenidTokenEndpoint:
process.env.AZURE_OPENID_CONFIG_TOKEN_ENDPOINT ||
Expand Down Expand Up @@ -113,6 +115,8 @@ const defaultConfig: DefaultConfig = {
decoratorUrl: process.env.DECORATOR_URL!,
skjemabyggingProxyUrl: process.env.SKJEMABYGGING_PROXY_URL!,
skjemabyggingProxyClientId: process.env.SKJEMABYGGING_PROXY_CLIENT_ID!,
gotenbergUrl: process.env.GOTENBERG_URL!,
gotenbergUrlEn: process.env.GOTENBERG_URL_EN!,
azureOpenidTokenEndpoint: process.env.AZURE_OPENID_CONFIG_TOKEN_ENDPOINT!,
clientId: process.env.AZURE_APP_CLIENT_ID!,
skjemaDir: process.env.SKJEMA_DIR!,
Expand Down
2 changes: 2 additions & 0 deletions packages/fyllut-backend/src/config/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type DefaultConfig = {
decoratorUrl: string;
skjemabyggingProxyUrl: string;
skjemabyggingProxyClientId: string;
gotenbergUrl: string;
gotenbergUrlEn: string;
azureOpenidTokenEndpoint: string;
clientId: string;
skjemaDir?: string;
Expand Down
37 changes: 21 additions & 16 deletions packages/fyllut-backend/src/routers/api/exstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,30 @@ const parseBody = (
return { form, submission, submissionMethod, translations, language };
};

export const getPdf = async (req: Request) => {
const { form, submission, submissionMethod, translations, language } = parseBody(req);

if (!['nb-NO', 'nn-NO', 'en'].includes(language)) {
logger.warn(`Language code "${language}" is not supported. Language code will be defaulted to "nb".`);
}

const languageCode = localizationUtils.getLanguageCodeAsIso639_1(language);

return await createPdf(
req.headers.AzureAccessToken as string,
form,
submission,
submissionMethod,
translations,
languageCode,
);
};

const exstream = {
post: async (req: Request, res: Response, next: NextFunction) => {
try {
const { form, submission, submissionMethod, translations, language } = parseBody(req);

if (!['nb-NO', 'nn-NO', 'en'].includes(language)) {
logger.warn(`Language code "${language}" is not supported. Language code will be defaulted to "nb".`);
}

const languageCode = localizationUtils.getLanguageCodeAsIso639_1(language);

const pdf = await createPdf(
req.headers.AzureAccessToken as string,
form,
submission,
submissionMethod,
translations,
languageCode,
);
const pdf = await getPdf(req);

res.contentType(pdf.contentType);
res.send(base64Decode(pdf.data));
} catch (e) {
Expand Down
102 changes: 102 additions & 0 deletions packages/fyllut-backend/src/routers/api/forsteside-soknad.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { ForstesideRequestBody, forstesideUtils } from '@navikt/skjemadigitalisering-shared-domain';
import { readFileSync } from 'fs';
import nock from 'nock';
import path from 'path';
import { config } from '../../config/config';
import { mockNext, mockRequest, mockResponse } from '../../test/requestTestHelpers';
import forstesideAndSoknad from './forsteside-soknad';
import * as mottaksadresser from './mottaksadresser';

const { skjemabyggingProxyUrl, formsApiUrl } = config;

const addresses = [
{
_id: '6246de1afd03d2caeeda2825',
data: {
adresselinje1: 'Nav Arbeid og ytelser lønnsgaranti',
adresselinje2: 'Postboks 6683 St. Olavs Plass',
adresselinje3: '',
postnummer: '0129',
poststed: 'Oslo',
temakoder: 'FOS,HJE',
},
},
{
_id: '61c09f91ec962a0003c65014',
data: {
adresselinje1: 'Nav Skanning bidrag',
adresselinje2: 'PB 6215 Etterstad',
adresselinje3: '',
postnummer: '0603',
poststed: 'Oslo',
},
},
];

const formTitle = 'testskjema';
const filePathForsteside = path.join(process.cwd(), '/src/routers/api/test-forsteside.pdf');
const filePathSoknad = path.join(process.cwd(), '/src/routers/api/test-skjema.pdf');
const filePathMerged = path.join(process.cwd(), '/src/routers/api/test-merged.pdf');

describe('[endpoint] forsteside', () => {
beforeAll(() => {
vi.spyOn(mottaksadresser, 'loadMottaksadresser').mockImplementation(async () => addresses);
vi.spyOn(forstesideUtils, 'genererFoerstesideData').mockImplementation(
() =>
({
foerstesidetype: 'ETTERSENDELSE',
navSkjemaId: 'NAV 10.10.10',
spraakkode: 'NB',
overskriftstittel: 'Tittel',
arkivtittel: 'Tittel',
tema: 'HJE',
}) as ForstesideRequestBody,
);
});

it('Create front page', async () => {
const forstesidePdf = readFileSync(filePathForsteside);
const soknadPdf = readFileSync(filePathSoknad);
const mergedPdf = readFileSync(filePathMerged);
const encodedForstesidedPdf = forstesidePdf.toString('base64');
const encodedSoknadPdf = soknadPdf.toString('base64');

const recipientsMock = nock(formsApiUrl).get('/v1/recipients').reply(200, []);
const generateFileMock = nock(skjemabyggingProxyUrl!)
.post('/foersteside')
.reply(200, { foersteside: encodedForstesidedPdf });
const skjemabyggingproxyScope = nock(process.env.SKJEMABYGGING_PROXY_URL as string)
.post('/exstream')
.reply(200, { data: { result: [{ content: { data: encodedSoknadPdf } }] } });

const mergePdfScope = nock(process.env.GOTENBERG_URL as string)
.intercept('/forms/pdfengines/merge', 'POST', (body) => {
return body != null;
})
.reply(200, mergedPdf, { 'content-type': 'application/pdf' });

const req = mockRequest({
headers: {
AzureAccessToken: '',
},
body: {
form: JSON.stringify({
title: formTitle,
components: [],
properties: { mottaksadresseId: 'mottaksadresseId', path: '12345', skjemanummer: 'NAV 12.34-56' },
}),
submissionMethod: 'paper',
language: 'nb-NO',
submission: JSON.stringify({ data: {} }),
translations: JSON.stringify({}),
},
});

await forstesideAndSoknad.post(req, mockResponse(), mockNext());

expect(recipientsMock.isDone()).toBe(true);
expect(generateFileMock.isDone()).toBe(true);
expect(skjemabyggingproxyScope.isDone()).toBe(true);
expect(mergePdfScope.isDone()).toBe(true);
}, 10000);
});
Loading