@hyperse-hub/hps-plugin-shipping-carrier
Shipping Carrier Plugin (src/)
This folder contains the runtime implementation of the @hyperse-hub/plugin-shipping-carrier Vendure plugin: the plugin class, Shop API extensions (GraphQL schema + resolvers), services, i18n resources, and the strategy interfaces used to fetch a fulfillment’s tracking timeline.
Exports
The public exports are re-exported from src/index.ts:
HpsPluginShippingCarrier: the Vendure plugin class (see hps-shipping-carrier.plugin.ts)
HpsPluginShippingCarrierOptions / strategy types: plugin init options and tracking strategy interfaces (see types.ts)
buildTestEligibleShippingMethodsInput: helper to build inputs for shipping method eligibility testing (see helpers/build-test-eligible-shipping-methods-input.ts)
- Constants: injection token + logger context (see
constants.ts)
Plugin entry (hps-shipping-carrier.plugin.ts)
HpsPluginShippingCarrier registers:
- Providers
EligibleShippingMethodsService
OrderShippingTrackingService
HPS_PLUGIN_SHIPPING_CARRIER_INIT_OPTIONS (injection token for init options)
- Shop API extensions
- GraphQL schema from
api/shop-api.ts
- Resolvers in
resolvers/*
During onApplicationBootstrap, the plugin:
- Registers i18n resources from
i18n/index.ts
- Calls
strategy.init(injector) (if provided) for each configured tracking timeline strategy
Shop GraphQL API (api/shop-api.ts)
The plugin extends the Shop API with:
It also defines types:
OrderShippingTracking
FulfillmentTracking
TrackingTimelineEntry
Resolvers (resolvers/*)
Services (services/*)
EligibleShippingMethodsService
Uses Vendure’s OrderTestingService.testEligibleShippingMethods() to compute shipping method quotes given a destination country (and optional mock lines).
Helper used:
helpers/build-test-eligible-shipping-methods-input.ts builds a TestEligibleShippingMethodsInput, filling required address fields when only countryCode is known.
OrderShippingTrackingService
Implements the tracking aggregation flow:
- Loads order by code via
OrderService.findOneByCode()
- If not found: throws
UserInputError('error.order_not_found', { orderCode })
- Loads fulfillments via
OrderService.getOrderFulfillments()
- For each fulfillment:
- If there is no
trackingCode: returns an empty timeline: []
- Otherwise finds the first matching strategy (see “Tracking timeline strategies”)
- If none matched:
- If
throwOnMissingStrategy is true: throws UserInputError('error.tracking_timeline_strategy_not_found', ...)
- Else: returns an empty
timeline: []
- If a strategy matched:
- Calls
strategy.getTimeline(ctx, input)
- Normalizes
occurredAt to a
Tracking timeline strategies (types.ts)
Tracking timelines are fetched via a strategy list configured at plugin init.
HpsPluginShippingCarrierOptions
trackingTimelineStrategies?: TrackingTimelineStrategy[]
- Checked in order; the first
supports() match wins.
throwOnMissingStrategy?: boolean
- If
true, missing strategy becomes a user-facing error.
- Default behavior is
false (returns empty timeline).
TrackingTimelineStrategy
Implement this interface to integrate a carrier/provider:
name?: string: for logging/debugging
init?(injector): optional lifecycle hook called once at bootstrap, allowing you to resolve Vendure providers via Injector
supports(input): returns whether this strategy can handle the (method, trackingCode) pair
getTimeline(ctx, input): returns a normalized TrackingTimelineEntryInput[]
TrackingTimelineEntryInput is like the GraphQL TrackingTimelineEntry, but accepts occurredAt as Date | string and omits __typename.
Minimal example
i18n (i18n/*)
User-facing errors use translation keys under:
Registered at bootstrap via i18n/index.ts and I18nTranslationService.useTranslationResource().
Constants (constants.ts)
loggerCtx: HpsPluginShippingCarrier (used for Vendure logger context)
HPS_PLUGIN_SHIPPING_CARRIER_INIT_OPTIONS: injection token for init options