Skip to content

Conversation

@olemartinorg
Copy link
Contributor

@olemartinorg olemartinorg commented Jan 14, 2026

Description

This tests out an alternative fix for the recent post place lookup problem. Instead of relying on the APIs from Posten/Bring (which have been down today and yesterday), and the quickfix for using an older NPM package (#3943), this has an alternative approach discussed during a meeting today.

The plan is to place a static file on CDN the frontend can download whenever lookups are needed. I managed to get the file down to ~13kb when brotli compressed, using a two-stage lookup to get from zip code to post place from a fairly simple JSON structure. We should be able to keep this file up-to-date on CDN via a script that downloads and re-codes the source - something we can run periodically. We trust our own CDN to be as available as our frontend already is.

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Chores
    • Removed the norway-postal-codes package dependency. Updated postal code data fetching to retrieve from an external registry instead of a bundled library.

✏️ Tip: You can customize this high-level summary in your review settings.

…try file located on (soon to be) CDN, that we can download on-demand when we need to. This is more up-to-date than the package from NPM was, and we can keep it maintained across frontend versions without having to upgrade every app when there are changes upstream.
@olemartinorg olemartinorg self-assigned this Jan 14, 2026
@olemartinorg olemartinorg added kind/bug Something isn't working backport This PR should be cherry-picked onto older release branches labels Jan 14, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

The PR removes the "norway-postal-codes" npm dependency and replaces it with a data-fetching approach. Postal code data is now fetched from an external URL using React Query instead of being bundled as a package. Supporting changes include adding new types, query functions, URL constants, test mocks, and updating related test assertions.

Changes

Cohort / File(s) Summary
Dependency Removal
package.json
Removed "norway-postal-codes": "^4.1.0" from dependencies
Type and URL Definitions
src/types/shared.ts, src/utils/urls/appUrlHelper.ts
Added PostalCodesRegistry interface with places and mapping properties; added postalCodesUrl constant pointing to external registry endpoint
Query Layer
src/queries/queries.ts
Introduced new fetchPostalCodes function returning PostalCodesRegistry via axios call to postalCodesUrl
Hook Migration
src/layout/Address/usePostPlace.ts
Replaced local package lookup with React Query-based data fetching; added helper logic to resolve zip to place from fetched data
Test Infrastructure
src/test/renderWithProviders.tsx
Added defaultPostalCodesMock with indexed format containing places and mapping arrays; extended defaultQueryMocks with fetchPostalCodes
Test Updates
src/layout/Address/AddressComponent.test.tsx
Removed jest.mock block for norway-postal-codes
E2E Test Adjustment
test/e2e/integration/multiple-datamodels-test/saving.ts
Updated save request count expectation from exactly 4 to a range of 4-5

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Replacing post code API with package from npm #3943: Modifies the same postal-code lookup logic paths (usePostPlace.ts, queries, package.json, tests) but implements the opposite approach using the norway-postal-codes package instead of external data fetching.

Suggested reviewers

  • ErlingHauan
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: replacing runtime API calls with a static CDN file for postal code lookups.
Description check ✅ Passed The pull request provides a comprehensive description with clear context, motivation, related issues, and verification checklist mostly completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/post-number-registry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@olemartinorg olemartinorg moved this to 👷 In progress in Team Altinn Studio Jan 14, 2026
@olemartinorg olemartinorg added the taskforce/next Issues that belongs to the named task-force label Jan 14, 2026
…led because there were 5 requests. It's probably something other than the post code lookup
@sonarqubecloud
Copy link

@olemartinorg olemartinorg marked this pull request as ready for review January 15, 2026 11:22
@olemartinorg olemartinorg moved this from 👷 In progress to 🔎 In review in Team Altinn Studio Jan 15, 2026
@olemartinorg olemartinorg merged commit dffa0fc into main Jan 15, 2026
24 checks passed
@olemartinorg olemartinorg deleted the fix/post-number-registry branch January 15, 2026 13:42
@github-project-automation github-project-automation bot moved this from 🔎 In review to ✅ Done in Team Altinn Studio Jan 15, 2026
@github-actions
Copy link
Contributor

⚠️ Automatic backport failed due to conflicts

The automatic backport to release/v4.24 failed because of merge conflicts.

The release branch release/v4.24 already existed and was updated.

Manual backport required:

# Checkout the release branch
git checkout release/v4.24
git pull origin release/v4.24

# Create backport branch
git checkout -b backport/3947

# Cherry-pick the merge commit
git cherry-pick dffa0fc410641cbaff05ba32f06425e85c52c490

# Resolve conflicts, then:
git add .
git cherry-pick --continue

# Push and create PR
git push origin backport/3947

olemartinorg added a commit that referenced this pull request Jan 19, 2026
* Replacing the zip code lookup (once again) with a single static registry file located on (soon to be) CDN, that we can download on-demand when we need to. This is more up-to-date than the package from NPM was, and we can keep it maintained across frontend versions without having to upgrade every app when there are changes upstream.

* Bringing back the at least 4 and at most 5 assertion, as the test failed because there were 5 requests. It's probably something other than the post code lookup

* Updating URL to use CDN

---------

Co-authored-by: Ole Martin Handeland <git@olemartin.org>
olemartinorg added a commit that referenced this pull request Jan 20, 2026
* Replacing the zip code lookup (once again) with a single static registry file located on (soon to be) CDN, that we can download on-demand when we need to. This is more up-to-date than the package from NPM was, and we can keep it maintained across frontend versions without having to upgrade every app when there are changes upstream.

* Bringing back the at least 4 and at most 5 assertion, as the test failed because there were 5 requests. It's probably something other than the post code lookup

* Updating URL to use CDN

---------

Co-authored-by: Ole Martin Handeland <git@olemartin.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR should be cherry-picked onto older release branches kind/bug Something isn't working taskforce/next Issues that belongs to the named task-force

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants