Skip to main content
These examples show the smallest useful implementation for each supported app-extension contract. Copy the relevant pattern into the file generated by napps create-extension, then adapt the business rule to your shop. All examples use @napps/component-extension types. App extensions run business logic and edit native-provided data; use @napps/nodes when you need to render custom React UI.

Product listing formatter

Add a tag to discounted products and hide products from a restricted vendor.
The formatter can be synchronous or asynchronous. Keep it idempotent because the same product can be formatted more than once. Async work must finish within the extension timeout. ProductTag is provided by the extension runtime as a global constructor.

Collection filters

Apply a default order and preselect a value only when the filter exists.
Initial runs before the collection query. UserFiltersChanged runs after the customer changes filters and before the updated query. Filter methods return false when the requested filter or value is unavailable.

Product detail handler

Format the PDP and block add-to-cart when a rule fails validation.
The PDP handler receives event.data payloads. onBeforeProductAddToCart uses { product, variant, quantity }; variant-carrying selection and completion events use { product, productVariant }. Return false from cancellable callbacks to stop the native action.

Cart operations

Return a cart operation when a qualifying product is present. Native can invoke this extension more than once, so make the rule converge instead of adding the same mutation forever.
Return CartOperation[] or a promise of that array. The native runner applies the operations and may run the extension again with the updated cart. Keep each pass deterministic and return an empty array when no change is needed. CartOperations is provided by the extension runtime as a global factory object.

Combining services with an extension

Services can be used inside an extension when the surface provides them. Handle nullable results from product lookups and inspect GraphQL errors after a resolved request.
See the individual extension contracts for the complete callback types, timeout behavior, and mutation methods.