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.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.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.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.