URN Functions
A URN is EverShop's stable, portable reference to an entity:
urn:evershop:<service>:<type>:<uuid>
for example urn:evershop:catalog:product:7afebbbd-69f6-4e2c-84c5-5b899173b867.
URNs exist because entity URLs are not stable. A widget that stored /women/shoes broke the moment somebody renamed the category. A URN stores identity instead of a URL and resolves to the current URL at request time. They are also the cross-module handle: the CMS module can reference a catalog product without importing catalog code or knowing its table layout.
There is no urn column anywhere. URNs are built on demand from an entity's uuid — usually in a GraphQL resolver, or when a page-builder widget saves a link. The entity tables are untouched.
Import
import {
registerUrnSchema,
getUrnSchema,
hasUrnSchema,
listUrnSchemas,
UrnService,
CatalogUrn,
CmsUrn,
OmsUrn,
BlogUrn,
CustomerUrn,
PromotionUrn
} from '@evershop/evershop/lib/urn';
import type { UrnSchema, UrnParts } from '@evershop/evershop/lib/urn';
lib/urn registers the core schemas at module-load time. Importing it — even only for the UrnService class — triggers that registration. This is why core types are always available without any bootstrap step.
Types
interface UrnSchema {
service: string;
type: string;
description: string;
}
interface UrnParts {
raw: string;
scheme: string; // always 'urn'
platform: string; // always 'evershop'
service: string;
type: string;
uuid: string;
}
Built-in schemas
| Service | Type | Description |
|---|---|---|
catalog | product | Catalog product |
catalog | category | Product category |
cms | widget_instance | Page builder widget instance |
cms | widget_placement | Widget placement on a route + area |
cms | page | CMS page |
oms | order | Customer order |
customer | customer | Customer account |
blog | post | Blog post |
blog | category | Blog category |
blog | tag | Blog tag |
promotion | landing_page | Promotion landing page |
catalog:collection schemaCollections are non-navigable groupings — they have no public page — so they are referenced by code in widget settings, not by URN.
registerUrnSchema
registerUrnSchema(schema: UrnSchema): void
Register a (service, type) pair so UrnService.build and UrnService.parse will accept it. Call this from your module's bootstrap.ts.
Parameters
| Field | Type | Description |
|---|---|---|
schema.service | string | The owning service / module, e.g. 'reviews'. |
schema.type | string | The entity type within that service, e.g. 'review'. |
schema.description | string | Human-readable label. Required. |
Return Value
void.
Throws
URN schema already registered: <service>:<type> when the pair is already in the registry. Registration is not idempotent — guard with hasUrnSchema if two of your entry points might both register.
Example
import { registerUrnSchema } from '@evershop/evershop/lib/urn';
export default () => {
registerUrnSchema({
service: 'reviews',
type: 'review',
description: 'Product review'
});
};
getUrnSchema
getUrnSchema(service: string, type: string): UrnSchema | undefined
Look up a registered schema. Returns undefined when the pair is unknown — it never throws.
import { getUrnSchema } from '@evershop/evershop/lib/urn';
getUrnSchema('catalog', 'product');
// { service: 'catalog', type: 'product', description: 'Catalog product' }
hasUrnSchema
hasUrnSchema(service: string, type: string): boolean
true when the pair is registered. Use it as the guard before a conditional registerUrnSchema, or to check whether an extension that owns a type is installed.
listUrnSchemas
listUrnSchemas(): UrnSchema[]
Every registered schema, in registration order. Useful for building admin pickers that enumerate linkable entity types.