diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..f7bcb7978 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,10 @@ +{ + "extends": ["plugin:mdx/recommended"], + // optional, if you want to lint code blocks at the same time + "settings": { + "mdx/code-blocks": true, + // optional, if you want to disable language mapper, set it to `false` + // if you want to override the default language mapper inside, you can provide your own + "mdx/language-mapper": {} + } +} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..7b9909307 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,16 @@ +name: lint-valid-mdx +on: + - pull_request + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js v17.x + uses: actions/setup-node@v3 + with: + node-version: 17.x + - run: npm ci + - run: npm run lint diff --git a/.gitignore b/.gitignore index 485dee64b..f307f8393 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .idea +node_modules +.DS_Store + diff --git a/docs/available-apis.md b/docs/available-apis.mdx similarity index 92% rename from docs/available-apis.md rename to docs/available-apis.mdx index 49c9a1e3e..ba481d8bc 100644 --- a/docs/available-apis.md +++ b/docs/available-apis.mdx @@ -1,64 +1,64 @@ -# Available APIs - -## Storefront APIs - -### REST - -Manage a shopper's cart and checkout and fetch order data via client-side JavaScript on BigCommerce [Stencil](/stencil-docs/getting-started/about-stencil) powered storefronts. - -[Learn more about storefront APIs](/api-docs/storefront/overview). - -### GraphQL - -Use GraphQL to query data for headless storefronts and BigCommerce [Stencil](/stencil-docs/getting-started/about-stencil) powered storefronts. - -[Learn more about the GraphQL Storefront API](/api-docs/storefront/graphql/graphql-storefront-api-overview) - -### Add to cart URLs - -Append query string parameters to product and `/cart.php` URLs to pre-select a SKU or add a product to cart. Use these parameters to build custom add to cart links and forms on BigCommerce hosted storefronts and remote sites (such as WordPress, blog posts, and social media). - -[Learn more about add to cart URLs](/api-docs/cart-and-checkout/add-to-cart-url). - -### Current Customer - -Identify logged-in customers securely via JavaScript. - -[Learn more about the current customer API](/api-docs/customers/current-customer-api). - -### Customer Login SSO - -Enable single sign-on for shoppers on BigCommerce hosted storefronts. - -[Learn more about the customer login API](/api-docs/customers/customer-login-api). - -## Management APIs - -### V2 REST API - -Mananage store resources from server-side code. - -Some **V2** resources are not yet exposed in the **V3 API**; however, for resources that are accessible via both APIs, the **V3 API** is recommended; it contains performance optimizations and [other improvements](#v3-rest-api). - -### V3 REST API - -Mananage store resources from server-side code. - -Interactions with the **V3** API are very similar to that of the **V2** API; however, the **V3** API introduces a number of improvements: -* Most tasks can be performed with fewer API calls (for example, a product with variants and custom fields can be created in a single request) -* Each **V3** resource includes a `meta` object, simplifying pagination -* **V3** Brands, Categories, Products, and Product Variants expose a [metafields](/api-reference/catalog/catalog-api/product-metafields/createproductmetafield) resource for use by developers to store custom data. -* **V3** API is optimized for performance (in general, data can be sent, received, and processed faster via **V3**, relative to **V2**). - -[Learn more about the V3 API](/api-docs/getting-started/about-our-api). - -## Provider APIs - -Implement endpoints consumed by BigCommerce for custom integrations (ex: custom shipping carrier rates via `/rates`). - -[Learn more about the Shipping Provider API](/api-docs/store-management/shipping/shipping-provider-api). - -## Resources - -- [Deprecations and Sunsets](/api-docs/getting-started/deprecations-and-sunsets) -- [Difference between V2 and V3 Catalog REST APIs](/api-docs/store-management/catalog/v2-vs-v3) +# Available APIs + +## Storefront APIs + +### REST + +Manage a shopper's cart and checkout and fetch order data via client-side JavaScript on BigCommerce [Stencil](/stencil-docs/getting-started/about-stencil) powered storefronts. + +[Learn more about storefront APIs](/api-docs/storefront/overview). + +### GraphQL + +Use GraphQL to query data for headless storefronts and BigCommerce [Stencil](/stencil-docs/getting-started/about-stencil) powered storefronts. + +[Learn more about the GraphQL Storefront API](/api-docs/storefront/graphql/graphql-storefront-api-overview) + +### Add to cart URLs + +Append query string parameters to product and `/cart.php` URLs to pre-select a SKU or add a product to cart. Use these parameters to build custom add to cart links and forms on BigCommerce hosted storefronts and remote sites (such as WordPress, blog posts, and social media). + +[Learn more about add to cart URLs](/api-docs/cart-and-checkout/add-to-cart-url). + +### Current Customer + +Identify logged-in customers securely via JavaScript. + +[Learn more about the current customer API](/api-docs/customers/current-customer-api). + +### Customer Login SSO + +Enable single sign-on for shoppers on BigCommerce hosted storefronts. + +[Learn more about the customer login API](/api-docs/customers/customer-login-api). + +## Management APIs + +### V2 REST API + +Mananage store resources from server-side code. + +Some **V2** resources are not yet exposed in the **V3 API**; however, for resources that are accessible via both APIs, the **V3 API** is recommended; it contains performance optimizations and [other improvements](#v3-rest-api). + +### V3 REST API + +Mananage store resources from server-side code. + +Interactions with the **V3** API are very similar to that of the **V2** API; however, the **V3** API introduces a number of improvements: +* Most tasks can be performed with fewer API calls (for example, a product with variants and custom fields can be created in a single request) +* Each **V3** resource includes a `meta` object, simplifying pagination +* **V3** Brands, Categories, Products, and Product Variants expose a [metafields](/docs/rest-management/catalog/product-metafields#create-a-product-metafield) resource for use by developers to store custom data. +* **V3** API is optimized for performance (in general, data can be sent, received, and processed faster via **V3**, relative to **V2**). + +[Learn more about the V3 API](/api-docs/getting-started/about-our-api). + +## Provider APIs + +Implement endpoints consumed by BigCommerce for custom integrations (ex: custom shipping carrier rates via `/rates`). + +[Learn more about the Shipping Provider API](/api-docs/store-management/shipping/shipping-provider-api). + +## Resources + +- [Deprecations and Sunsets](/api-docs/getting-started/deprecations-and-sunsets) +- [Difference between V2 and V3 Catalog REST APIs](/api-docs/store-management/catalog/v2-vs-v3) diff --git a/docs/customer-login-sso.md b/docs/customer-login-sso.mdx similarity index 86% rename from docs/customer-login-sso.md rename to docs/customer-login-sso.mdx index 736c1e25b..9cad1bf37 100644 --- a/docs/customer-login-sso.md +++ b/docs/customer-login-sso.mdx @@ -1,12 +1,13 @@ # Customer Login SSO -* **Host**: {store_domain}/graphql +* **Host**: `{store_domain}/graphql` * **Protocols**:`https` * **Accepts**: `application/json` * **Responds With**: `application/json` -Download Spec: [customer_login.json](https://bigcommerce.stoplight.io/api/v1/projects/bigcommerce/api-reference/nodes/reference/customer_login.yml?branch=master&deref=all&format=json) +Download Spec: [customer_login.json](#) +{/* https://bigcommerce.stoplight.io/api/v1/projects/bigcommerce/api-reference/nodes/reference/customer_login.yml?branch=master&deref=all&format=json */} Create a login URL for customer single sign-on. @@ -14,7 +15,7 @@ Create a login URL for customer single sign-on. To log in a customer using the Customer Login API, redirect the customer's browser to the following access point URL: -```http +```http copy https://yourstore.example.com/login/token/{{TOKEN}} ``` @@ -35,7 +36,7 @@ We recommend writing a script to generate a login token since the `JWT iat` (iss ### JWT Header -```json +```json copy { "alg": "HS256", "typ": "JWT" @@ -50,7 +51,7 @@ We recommend writing a script to generate a login token since the `JWT iat` (iss To create the signature, sign the encoded header, the encoded payload, and client_secret using the `HMAC SHA256` algorithm. -```js +```js copy HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), @@ -63,21 +64,29 @@ To create the signature, sign the encoded header, the encoded payload, and clien Create `urlGenerator.js` node app and install dependencies. -```shell +```shell copy mkdir urlGenerator +``` +```shell copy cd urlGenerator +``` +```shell copy touch urlGenerator.js +``` +```shell copy npm init +``` +```shell copy npm install jsonwebtoken uuid ``` Paste the following into `urlGenerator/urlGenerator.js`. -```js +```js copy const jwt = require('jsonwebtoken'); const {v4: uuidv4} = require('uuid'); @@ -109,15 +118,15 @@ Paste the following into `urlGenerator/urlGenerator.js`. Replace `{{CLIENT_ID}}` and other variables with your credentials, then run the app. -```shell +```shell copy node urlGenerator.js ``` You should receive a complete access point URL as an output. - -> #### Note -> You are required to include the `channel_id` when using the login JWTs to redirect to an embedded checkout. Default value = 1. For more information, see the [Embedded Checkout Overview](/api-docs/storefronts/embedded-checkout/embedded-checkout-overview). + + You are required to include the `channel_id` when using the login JWTs to redirect to an embedded checkout. Default value = 1. For more information, see the [Embedded Checkout Overview](/api-docs/storefronts/embedded-checkout/embedded-checkout-overview). + ## Resources diff --git a/docs/storefront-graphql.md b/docs/storefront-graphql.mdx similarity index 84% rename from docs/storefront-graphql.md rename to docs/storefront-graphql.mdx index f59fbddf5..6ae0e3396 100644 --- a/docs/storefront-graphql.md +++ b/docs/storefront-graphql.mdx @@ -19,9 +19,9 @@ To explore Storefront nodes in an interactive graph, check out the [GraphQL Expl ### Request tokens with REST API -Create JWT tokens for authenticating cross-origin requests by making a `POST` request to the [Create a token](/api-reference/store-management/tokens/api-token/createtoken) endpoint. +Create JWT tokens for authenticating cross-origin requests by making a `POST` request to the [Create a token](/docs/storefront-auth/tokens#create-a-token) endpoint. -```http title="Example request: Create a token" lineNumbers +```http filename="Example request: Create a token" showLineNumbers copy POST https://api.bigcommerce.com/stores/{{STORE_HASH}}/v3/storefront/api-token X-Auth-Token: {{ACCESS_TOKEN}} Content-Type: application/json @@ -36,7 +36,7 @@ Accept: application/json } ```   -```json title="Example response: Create a token" lineNumbers +```json filename="Example response: Create a token" showLineNumbers copy { "data": { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" @@ -47,7 +47,7 @@ Accept: application/json You can complete the GraphQL query call with any HTTP library. Use the `data.token` value from the preceding response as the `{{JWT}}` value in the `Authorization: Bearer {{JWT}}` header. -```http title="Example GraphQL query" lineNumbers +```http filename="Example GraphQL query" showLineNumbers copy POST /graphql Authorization: Bearer {{JWT}} Content-Type: application/json @@ -62,7 +62,7 @@ Content-Type: application/json Client scripts on BigCommerce [Stencil](/stencil-docs/getting-started/about-stencil)-powered storefronts can access a token with the `{{settings.storefront_api.token}}` Handlebars object. -```handlebars title="Example GraphQL query script with Stencil token" lineNumbers +```handlebars filename="Example GraphQL query script with Stencil token" showLineNumbers copy