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. Function names are illustrative: export each function under the functionName of its entry in napps.config.json. See How App Extensions work. 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 a runtime global constructor. The package exports its type only, so don’t import it as a value.

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 extension exports a factory that returns the handler. The 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. The app can call this extension more than once, so make the rule converge instead of adding the same mutation on every pass.
Return CartOperation[] or a promise of that array. The app 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 a runtime global factory object, also available as NAPPS.CartOperations. The package exports its type only. Its type allows undefined, so check it before use.

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.