woocommerce/plugins/woocommerce-blocks/assets/js/data/schema
Mike Jolley a58b2d0ac4 Store API: Introduce API Versioning System (https://github.com/woocommerce/woocommerce-blocks/pull/5911)
* Fix missing dependency

* Min version exceeds required 5.6

* Move exceptions

* Move schemas under V1 namespace

* Move routes to v1

* Move RouteException

* Route versioning

* Update route and schema identifiers/init

* Rework route init to support multiple versions and multiple schema

* Tests for cart routes

* Cart coupons tests

* Batch

* extensions

* Update docs

* Update remaining tests

* woocommerce_store_api_route_version was unused

* Revert unrelated change

* Fix phpcs

* Update src/StoreApi/docs/guiding-principles.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update src/StoreApi/docs/cart-items.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update src/StoreApi/RoutesController.php

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Note about v1 unversioned endpoints

* Remove unused get_route_version

* 409 comment in tests

* Remove copy pasted comments

* Update all usage to v1

* Correct namespace

* More v1 namespaces

* More missing v1

* fix mocks

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-02-23 12:00:45 +00:00
..
test Add @woocommerce/eslint-plugin dependency (https://github.com/woocommerce/woocommerce-blocks/pull/3115) 2020-09-07 13:31:10 -04:00
README.md Rename modelName to resourceName everywhere (https://github.com/woocommerce/woocommerce-blocks/pull/1173) 2019-11-14 11:10:50 -05:00
action-types.js All Products with Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/1032) 2019-10-28 09:53:09 -04:00
actions.js All Products with Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/1032) 2019-10-28 09:53:09 -04:00
constants.js Store API: Introduce API Versioning System (https://github.com/woocommerce/woocommerce-blocks/pull/5911) 2022-02-23 12:00:45 +00:00
index.js All Products with Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/1032) 2019-10-28 09:53:09 -04:00
reducers.js Rename modelName to resourceName everywhere (https://github.com/woocommerce/woocommerce-blocks/pull/1173) 2019-11-14 11:10:50 -05:00
resolvers.js All Products with Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/1032) 2019-10-28 09:53:09 -04:00
selectors.js re-enable @wordpress/valid-sprintf eslint rule and fix violations (https://github.com/woocommerce/woocommerce-blocks/pull/3201) 2020-09-26 16:05:00 -04:00
utils.js Active filters block (https://github.com/woocommerce/woocommerce-blocks/pull/1168) 2019-11-15 14:41:23 +00:00

README.md

Schema Store

To utilize this store you will import the SCHEMA_STORE_KEY in any module referencing it. Assuming @woocommerce/block-data is registered as an external pointing to wc.wcBlocksData you can import the key via:

import { SCHEMA_STORE_KEY } from '@woocommerce/block-data';

Actions

The following actions are used for dispatching data to this store state.

Note: You should rarely need to use any of these actions directly as they are mostly used internally by the resolvers.

receiveRoutes( routes, namespace = '/wc/blocks' )

This returns an action object used to update the store with the provided list of resource routes.

Argument Type Description
routes Array This should be an array of routes attached for the given namespace. Eg. [ '/wc/blocks/products', '/wc/blocks/products/attributes/(?P<id>[\d]+)' ]
namespace string The namespace the routes belong to (eg. /wc/blocks)

Selectors

getRoute( namespace, resourceName, ids = [] )

This is used for retrieving a route for the given namespace, resource name and (if necessary) ids.

Example: If you are looking for a route for a single product on the wc/blocks namespace, then you'd have [20] as the ids.

// '/wc/blocks/products/20'
wp.data.select( SCHEMA_STORE_KEY ).getRoute( '/wc/blocks', 'products', [20] );
Argument Type Description
namespace string Namespace for the route (eg. /wc/blocks)
resourceName string The resource name for the route (eg. products/attributes/terms)
ids array Only needed if the route has placeholders for ids.

getRoutes( namespace )

This will return all the registered routes for the given namespace as a flat array.