Skip to content

fix(core): Export and register Province entity and ProvinceService#4857

Merged
biggamesmallworld merged 4 commits into
vendurehq:masterfrom
grolmus:mgrolmus/oss-552-province-entity-and-provinceservice-not-found
Jul 7, 2026
Merged

fix(core): Export and register Province entity and ProvinceService#4857
biggamesmallworld merged 4 commits into
vendurehq:masterfrom
grolmus:mgrolmus/oss-552-province-entity-and-provinceservice-not-found

Conversation

@grolmus

@grolmus grolmus commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Province (entity) and ProvinceService are documented as public API (docs.vendure.io has pages for both) but importing them fails:

import { Province, ProvinceService } from '@vendure/core';
// '@vendure/core' has no exported member named 'ProvinceService' / 'Province'

Fixes #4792

Root cause

Province (a @ChildEntity of Region, single-table inheritance) and ProvinceService (a complete service: findAll/findOne/create/update/delete, already publishing ProvinceEvent) both exist, but:

  • entity/index.ts exported region/country.entity but not region/province.entity.
  • service/index.ts exported country.service but not province.service.
  • event-bus/index.ts exported country-event but not province-event.
  • ProvinceService was not in service.module.ts's services array, so it was never registered as a provider — even if imported, it could not be injected.

In a built @vendure/core, Country/CountryService resolve to functions while Province/ProvinceService were undefined. This is an oversight from the original "Regions & Provinces" work (the Country counterparts were all wired up; the Province ones were missed), not an intentional private API.

The change (mirrors the existing Country wiring)

  • entity/index.ts — export region/province.entity
  • service/index.ts — export services/province.service
  • event-bus/index.ts — export events/province-event (so consumers injecting ProvinceService can subscribe to the events it emits)
  • service.module.ts — import ProvinceService and add it to the services array (which feeds both providers and exports), making it injectable

Province uses single-table inheritance, so no dbConnectionOptions.entities registration is needed.

Test plan

New packages/core/e2e/province.e2e-spec.ts:

  • Asserts Province, ProvinceService and ProvinceEvent are exported from @vendure/core.
  • Asserts server.app.get(ProvinceService) is injectable (DI registration).
  • Exercises the full CRUD round-trip through the service (createfindOnefindAlldelete) and asserts the emitted ProvinceEvents are ['created', 'deleted'].

Verified: fails on master (Nest could not find given elementProvinceService isn't a provider; the imports resolve to undefined), passes on this branch. Sibling country.e2e (6 tests) still green; core tsc build + ESLint clean.

Out of scope (follow-up)

The Admin API schema (province.api.graphql) declares provinces / province / createProvince / updateProvince / deleteProvince, but there is no ProvinceResolver registered (only CountryResolver) — those GraphQL operations have never had a backing resolver. That is a pre-existing gap from the same original commit and is independent of this programmatic-export fix; it deserves its own issue. This PR restores the documented programmatic (@vendure/core) surface only.

Note: docs generation walks source @docsCategory annotations, not the index barrels, which is why ProvinceService had a published doc page despite being unexported — so no docs change is required.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Province and ProvinceService are documented as public API but were not exported
from @vendure/core, and ProvinceService was never registered as a provider, so
it could not be injected. Export the entity, the service and ProvinceEvent
(matching the existing Country wiring) and register ProvinceService in the
service module.

Fixes vendurehq#4792
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vendure-storybook Ready Ready Preview, Comment Jul 7, 2026 1:30pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c545c34a-c8e0-46bb-8502-e0a8e3684b50

📥 Commits

Reviewing files that changed from the base of the PR and between b039b06 and 962ae42.

📒 Files selected for processing (1)
  • packages/core/src/service/service.module.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/service/service.module.ts

📝 Walkthrough

Walkthrough

Compact Summary: This change adds three barrel re-exports in packages/core (entity, event-bus, and service index files) to expose the Province entity, ProvinceEvent, and ProvinceService from the public API. Additionally, service.module.ts is updated to import ProvinceService and include it in the services array, registering it as a provider and export within ServiceCoreModule.

Changes

File Change Summary
packages/core/src/entity/index.ts Added re-export of province.entity
packages/core/src/event-bus/index.ts Added re-export of province-event
packages/core/src/service/index.ts Added re-export of province.service
packages/core/src/service/service.module.ts Imported and registered ProvinceService in services array

Related Issues: #4792 (Province entity and ProvinceService not exported from @vendure/core)

Related PRs: None identified

Suggested Labels: enhancement, core

Suggested Reviewers: None specified

Poem
A rabbit hops through barrels wide,
Finding Province tucked inside,
"Export me too!" the service cried,
Now Country's neighbor stands beside,
No more errors, imports satisfied. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the core fix: exporting and registering Province artifacts.
Description check ✅ Passed The description includes the bug summary, root cause, implemented fix, linked issue, and testing notes.
Linked Issues check ✅ Passed The PR resolves #4792 by exporting Province and ProvinceService from @vendure/core as requested.
Out of Scope Changes check ✅ Passed The added event export and service registration are directly tied to the Province API fix and are not out of scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@michaelbromley michaelbromley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi Martin,
Thanks for this fix - adding the exports is probably all that is needed here because the e2e tests are not "true" e2e tests in the sense that all the other e2e tests are making Graphql API calls and asserting against the response, in general.

We could have an e2e suite for Province, but it should work via API not direct service instance injection. I'm not even sure if we have any exposed API surface for this however, as Province as a concept was created with future work in mind (potentially supporting nested regions) but we thus far never really did anything meaningful with it.

So for now I'd say you can remove those e2e tests (not something I often say! 😅)

Unless of course we are exposing a graphql interface for Province, in which case adapt the tests to go via the graphql API.

Per review feedback (vendurehq#4857): Vendure e2e tests assert against the
GraphQL API, but Province has no exposed API surface, so these
service-injection tests don't fit. The export/registration fix is
retained.

Relates to vendurehq#4792
@grolmus

grolmus commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks Michael! Makes sense — there's no GraphQL surface for Province (no ProvinceResolver), so I've removed the service-injection e2e tests rather than adapt them. The PR now just adds the missing exports and the ProvinceService provider registration, which is the actual fix. Re-requesting review.

@biggamesmallworld biggamesmallworld left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🏄‍♂️

@biggamesmallworld biggamesmallworld dismissed michaelbromley’s stale review July 7, 2026 13:29

Reviewed this myself in conjunction with Nigel, and Martin properly implemented the solution and your changes. Approving and moving through after CI pass

@biggamesmallworld biggamesmallworld enabled auto-merge (squash) July 7, 2026 13:29
@biggamesmallworld biggamesmallworld merged commit c1b5b3d into vendurehq:master Jul 7, 2026
23 of 24 checks passed
@vendure-ci-automation-bot vendure-ci-automation-bot Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Province entity and ProvinceService not found

3 participants