diff --git a/docs/API_REFERENCE.md b/docs/API_REFERENCE.md index b101eea4a..0c1ee28fd 100644 --- a/docs/API_REFERENCE.md +++ b/docs/API_REFERENCE.md @@ -1,130 +1,49 @@ ## Classes
The JS Buy SDK checkout resource
+The JS Buy SDK Client.
The JS Buy SDK collection resource
+The class used to configure the JS Buy SDK Client.
Promise
| GraphModel
Fetches a checkout by ID.
-Promise
| GraphModel
Creates a checkout.
-Promise
| GraphModel
Adds line items to an existing checkout.
-Promise
| GraphModel
Removes line items from an existing checkout.
-Promise
| GraphModel
Updates line items on an existing checkout.
-Promise
| Array.<GraphModel>
Fetches all collections on the shop, not including products. -To fetch collections with products use fetchAllsWithProducts.
-Promise
| Array.<GraphModel>
Fetches all collections on the shop, including products.
-Promise
| GraphModel
Fetches a single collection by ID on the shop, not including products. -To fetch the collection with products use fetchWithProducts.
-Promise
| GraphModel
Fetches a single collection by ID on the shop, including products.
-Promise
| GraphModel
Fetches a collection by handle on the shop.
-Promise
| Array.<GraphModel>
Fetches all collections on the shop that match the query.
+The JS Buy SDK image resource
Promise
| Array.<GraphModel>
Fetches all products on the shop.
+The JS Buy SDK product resource
Promise
| GraphModel
Fetches a single product by ID on the shop.
-Promise
| GraphModel
Fetches a single product by handle on the shop.
-Promise
| Array.<GraphModel>
Fetches all products on the shop that match the query.
-Promise
| GraphModel
Fetches shop information (currencyCode
, description
, moneyFormat
, name
, and primaryDomain
).
-See the Storefront API reference for more information.
Promise
| GraphModel
Fetches shop policies (privacy policy, terms of service and refund policy).
+The JS Buy SDK shop resource
Object
| The property under which product fetching methods live. |
-| collection | Object
| The property under which collection fetching methods live. |
-| shop | Object
| The property under which shop fetching methods live. |
-| checkout | Object
| The property under which shop fetching and mutating methods live. |
-| image | Object
| The property under which image helper methods live. |
+* [CheckoutResource](#CheckoutResource)
+ * [.fetch(id)](#CheckoutResource+fetch) ⇒ Promise
\| GraphModel
+ * [.create([input])](#CheckoutResource+create) ⇒ Promise
\| GraphModel
+ * [.addLineItems(checkoutId, lineItems)](#CheckoutResource+addLineItems) ⇒ Promise
\| GraphModel
+ * [.removeLineItems(checkoutId, lineItemIds)](#CheckoutResource+removeLineItems) ⇒ Promise
\| GraphModel
+ * [.updateLineItems(checkoutId, lineItems)](#CheckoutResource+updateLineItems) ⇒ Promise
\| GraphModel
+
-* [Client](#Client)
- * [new Client(config)](#new_Client_new)
- * [.buildClient()](#Client.buildClient)
-
-
-
-### new Client(config)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| config | [Config](#Config)
| An instance of [Config](#Config) used to configure the Client. |
-
-
-
-### Client.buildClient()
-Primary entry point for building a new Client.
-
-**Kind**: static method of [Client](#Client)
-
-
-## Config
-The class used to configure the JS Buy SDK Client.
-
-**Kind**: global class
-
-
-### new Config(attrs)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| attrs | Object
| An object specifying the configuration. Requires the following properties: |
-| attrs.storefrontAccessToken | String
| The [Storefront access token](https://help.shopify.com/api/reference/storefront_access_token) for the shop. |
-| attrs.domain | String
| The `myshopify` domain for the shop (e.g. `graphql.myshopify.com`). |
-
-
-
-## fetch(id) ⇒ Promise
\| GraphModel
+### checkoutResource.fetch(id) ⇒ Promise
\| GraphModel
Fetches a checkout by ID.
-**Kind**: global function
+**Kind**: instance method of [CheckoutResource
](#CheckoutResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the checkout.
| Param | Type | Description |
@@ -137,12 +56,12 @@ client.checkout.fetch('FlZj9rZXlN5MDY4ZDFiZTUyZTUwNTE2MDNhZjg=').then((checkout)
// Do something with the checkout
});
```
-
+
-## create([input]) ⇒ Promise
\| GraphModel
+### checkoutResource.create([input]) ⇒ Promise
\| GraphModel
Creates a checkout.
-**Kind**: global function
+**Kind**: instance method of [CheckoutResource
](#CheckoutResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with the created checkout.
| Param | Type | Description |
@@ -166,12 +85,12 @@ client.checkout.create(input).then((checkout) => {
// Do something with the newly created checkout
});
```
-
+
-## addLineItems(checkoutId, lineItems) ⇒ Promise
\| GraphModel
+### checkoutResource.addLineItems(checkoutId, lineItems) ⇒ Promise
\| GraphModel
Adds line items to an existing checkout.
-**Kind**: global function
+**Kind**: instance method of [CheckoutResource
](#CheckoutResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with the updated checkout.
| Param | Type | Description |
@@ -188,12 +107,12 @@ client.checkout.addLineItems(checkoutId, lineItems).then((checkout) => {
// Do something with the updated checkout
});
```
-
+
-## removeLineItems(checkoutId, lineItemIds) ⇒ Promise
\| GraphModel
+### checkoutResource.removeLineItems(checkoutId, lineItemIds) ⇒ Promise
\| GraphModel
Removes line items from an existing checkout.
-**Kind**: global function
+**Kind**: instance method of [CheckoutResource
](#CheckoutResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with the updated checkout.
| Param | Type | Description |
@@ -210,12 +129,12 @@ client.checkout.removeLineItems(checkoutId, lineItemIds).then((checkout) => {
// Do something with the updated checkout
});
```
-
+
-## updateLineItems(checkoutId, lineItems) ⇒ Promise
\| GraphModel
+### checkoutResource.updateLineItems(checkoutId, lineItems) ⇒ Promise
\| GraphModel
Updates line items on an existing checkout.
-**Kind**: global function
+**Kind**: instance method of [CheckoutResource
](#CheckoutResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with the updated checkout.
| Param | Type | Description |
@@ -238,13 +157,63 @@ client.checkout.updateLineItems(checkoutId, lineItems).then(checkout => {
// Do something with the updated checkout
});
```
-
+
-## fetchAll() ⇒ Promise
\| Array.<GraphModel>
+## Client
+The JS Buy SDK Client.
+
+**Kind**: global class
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| product | [ProductResource
](#ProductResource) | The property under which product fetching methods live. |
+| collection | [CollectionResource
](#CollectionResource) | The property under which collection fetching methods live. |
+| shop | [ShopResource
](#ShopResource) | The property under which shop fetching methods live. |
+| checkout | [CheckoutResource
](#CheckoutResource) | The property under which shop fetching and mutating methods live. |
+| image | [ImageResource
](#ImageResource) | The property under which image helper methods live. |
+
+
+* [Client](#Client)
+ * [new Client(config)](#new_Client_new)
+ * [.buildClient()](#Client.buildClient)
+
+
+
+### new Client(config)
+
+| Param | Type | Description |
+| --- | --- | --- |
+| config | [Config
](#Config) | An instance of [Config](#Config) used to configure the Client. |
+
+
+
+### Client.buildClient()
+Primary entry point for building a new Client.
+
+**Kind**: static method of [Client
](#Client)
+
+
+## CollectionResource
+The JS Buy SDK collection resource
+
+**Kind**: global class
+
+* [CollectionResource](#CollectionResource)
+ * [.fetchAll()](#CollectionResource+fetchAll) ⇒ Promise
\| Array.<GraphModel>
+ * [.fetchAllWithProducts()](#CollectionResource+fetchAllWithProducts) ⇒ Promise
\| Array.<GraphModel>
+ * [.fetch(id)](#CollectionResource+fetch) ⇒ Promise
\| GraphModel
+ * [.fetchWithProducts(id)](#CollectionResource+fetchWithProducts) ⇒ Promise
\| GraphModel
+ * [.fetchByHandle(handle)](#CollectionResource+fetchByHandle) ⇒ Promise
\| GraphModel
+ * [.fetchQuery([args])](#CollectionResource+fetchQuery) ⇒ Promise
\| Array.<GraphModel>
+
+
+
+### collectionResource.fetchAll() ⇒ Promise
\| Array.<GraphModel>
Fetches all collections on the shop, not including products.
To fetch collections with products use [fetchAllsWithProducts](Client#fetchAllsWithProducts).
-**Kind**: global function
+**Kind**: instance method of [CollectionResource
](#CollectionResource)
**Returns**: Promise
\| Array.<GraphModel>
- A promise resolving with an array of `GraphModel`s of the collections.
**Example**
```js
@@ -252,12 +221,12 @@ client.collection.fetchAll().then((collections) => {
// Do something with the collections
});
```
-
+
-## fetchAllWithProducts() ⇒ Promise
\| Array.<GraphModel>
+### collectionResource.fetchAllWithProducts() ⇒ Promise
\| Array.<GraphModel>
Fetches all collections on the shop, including products.
-**Kind**: global function
+**Kind**: instance method of [CollectionResource
](#CollectionResource)
**Returns**: Promise
\| Array.<GraphModel>
- A promise resolving with an array of `GraphModel`s of the collections.
**Example**
```js
@@ -265,13 +234,13 @@ client.collection.fetchAllWithProducts().then((collections) => {
// Do something with the collections
});
```
-
+
-## fetch(id) ⇒ Promise
\| GraphModel
+### collectionResource.fetch(id) ⇒ Promise
\| GraphModel
Fetches a single collection by ID on the shop, not including products.
To fetch the collection with products use [fetchWithProducts](Client#fetchWithProducts).
-**Kind**: global function
+**Kind**: instance method of [CollectionResource
](#CollectionResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the collection.
| Param | Type | Description |
@@ -284,12 +253,12 @@ client.collection.fetch('Xk9lM2JkNzFmNzIQ4NTIY4ZDFiZTUyZTUwNTE2MDNhZjg==').then(
// Do something with the collection
});
```
-
+
-## fetchWithProducts(id) ⇒ Promise
\| GraphModel
+### collectionResource.fetchWithProducts(id) ⇒ Promise
\| GraphModel
Fetches a single collection by ID on the shop, including products.
-**Kind**: global function
+**Kind**: instance method of [CollectionResource
](#CollectionResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the collection.
| Param | Type | Description |
@@ -302,12 +271,12 @@ client.collection.fetchWithProducts('Xk9lM2JkNzFmNzIQ4NTIY4ZDFiZTUyZTUwNTE2MDNhZ
// Do something with the collection
});
```
-
+
-## fetchByHandle(handle) ⇒ Promise
\| GraphModel
+### collectionResource.fetchByHandle(handle) ⇒ Promise
\| GraphModel
Fetches a collection by handle on the shop.
-**Kind**: global function
+**Kind**: instance method of [CollectionResource
](#CollectionResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the collection.
| Param | Type | Description |
@@ -320,12 +289,12 @@ client.collection.fetchByHandle('my-collection').then((collection) => {
// Do something with the collection
});
```
-
+
-## fetchQuery([args]) ⇒ Promise
\| Array.<GraphModel>
+### collectionResource.fetchQuery([args]) ⇒ Promise
\| Array.<GraphModel>
Fetches all collections on the shop that match the query.
-**Kind**: global function
+**Kind**: instance method of [CollectionResource
](#CollectionResource)
**Returns**: Promise
\| Array.<GraphModel>
- A promise resolving with an array of `GraphModel`s of the collections.
| Param | Type | Default | Description |
@@ -342,12 +311,47 @@ client.collection.fetchQuery({first: 20, sortKey: 'CREATED_AT', reverse: true}).
// Do something with the first 10 collections sorted by title in ascending order
});
```
-
+
+
+## Config
+The class used to configure the JS Buy SDK Client.
+
+**Kind**: global class
+
+
+### new Config(attrs)
+
+| Param | Type | Description |
+| --- | --- | --- |
+| attrs | Object
| An object specifying the configuration. Requires the following properties: |
+| attrs.storefrontAccessToken | String
| The [Storefront access token](https://help.shopify.com/api/reference/storefront_access_token) for the shop. |
+| attrs.domain | String
| The `myshopify` domain for the shop (e.g. `graphql.myshopify.com`). |
+
+
+
+## ImageResource
+The JS Buy SDK image resource
+
+**Kind**: global class
+
+
+## ProductResource
+The JS Buy SDK product resource
+
+**Kind**: global class
-## fetchAll([pageSize]) ⇒ Promise
\| Array.<GraphModel>
+* [ProductResource](#ProductResource)
+ * [.fetchAll([pageSize])](#ProductResource+fetchAll) ⇒ Promise
\| Array.<GraphModel>
+ * [.fetch(id)](#ProductResource+fetch) ⇒ Promise
\| GraphModel
+ * [.fetchByHandle(handle)](#ProductResource+fetchByHandle) ⇒ Promise
\| GraphModel
+ * [.fetchQuery([args])](#ProductResource+fetchQuery) ⇒ Promise
\| Array.<GraphModel>
+
+
+
+### productResource.fetchAll([pageSize]) ⇒ Promise
\| Array.<GraphModel>
Fetches all products on the shop.
-**Kind**: global function
+**Kind**: instance method of [ProductResource
](#ProductResource)
**Returns**: Promise
\| Array.<GraphModel>
- A promise resolving with an array of `GraphModel`s of the products.
| Param | Type | Default | Description |
@@ -360,12 +364,12 @@ client.product.fetchAll().then((products) => {
// Do something with the products
});
```
-
+
-## fetch(id) ⇒ Promise
\| GraphModel
+### productResource.fetch(id) ⇒ Promise
\| GraphModel
Fetches a single product by ID on the shop.
-**Kind**: global function
+**Kind**: instance method of [ProductResource
](#ProductResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the product.
| Param | Type | Description |
@@ -378,12 +382,12 @@ client.product.fetch('Xk9lM2JkNzFmNzIQ4NTIY4ZDFi9DaGVja291dC9lM2JkN==').then((pr
// Do something with the product
});
```
-
+
-## fetchByHandle(handle) ⇒ Promise
\| GraphModel
+### productResource.fetchByHandle(handle) ⇒ Promise
\| GraphModel
Fetches a single product by handle on the shop.
-**Kind**: global function
+**Kind**: instance method of [ProductResource
](#ProductResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the product.
| Param | Type | Description |
@@ -396,12 +400,12 @@ client.product.fetchByHandle('my-product').then((product) => {
// Do something with the product
});
```
-
+
-## fetchQuery([args]) ⇒ Promise
\| Array.<GraphModel>
+### productResource.fetchQuery([args]) ⇒ Promise
\| Array.<GraphModel>
Fetches all products on the shop that match the query.
-**Kind**: global function
+**Kind**: instance method of [ProductResource
](#ProductResource)
**Returns**: Promise
\| Array.<GraphModel>
- A promise resolving with an array of `GraphModel`s of the products.
| Param | Type | Default | Description |
@@ -418,13 +422,24 @@ client.product.fetchQuery({first: 20, sortKey: 'CREATED_AT', reverse: true}).the
// Do something with the first 10 products sorted by title in ascending order
});
```
-
+
+
+## ShopResource
+The JS Buy SDK shop resource
+
+**Kind**: global class
+
+* [ShopResource](#ShopResource)
+ * [.fetchInfo()](#ShopResource+fetchInfo) ⇒ Promise
\| GraphModel
+ * [.fetchPolicies()](#ShopResource+fetchPolicies) ⇒ Promise
\| GraphModel
+
+
-## fetchInfo() ⇒ Promise
\| GraphModel
+### shopResource.fetchInfo() ⇒ Promise
\| GraphModel
Fetches shop information (`currencyCode`, `description`, `moneyFormat`, `name`, and `primaryDomain`).
See the [Storefront API reference](https://help.shopify.com/api/storefront-api/reference/object/shop) for more information.
-**Kind**: global function
+**Kind**: instance method of [ShopResource
](#ShopResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the shop.
**Example**
```js
@@ -432,12 +447,12 @@ client.shop.fetchInfo().then((shop) => {
// Do something with the shop
});
```
-
+
-## fetchPolicies() ⇒ Promise
\| GraphModel
+### shopResource.fetchPolicies() ⇒ Promise
\| GraphModel
Fetches shop policies (privacy policy, terms of service and refund policy).
-**Kind**: global function
+**Kind**: instance method of [ShopResource
](#ShopResource)
**Returns**: Promise
\| GraphModel
- A promise resolving with a `GraphModel` of the shop.
**Example**
```js
diff --git a/src/checkout-resource.js b/src/checkout-resource.js
index 7a8ec03bc..3106823e4 100644
--- a/src/checkout-resource.js
+++ b/src/checkout-resource.js
@@ -9,7 +9,11 @@ import checkoutLineItemsAddMutation from './graphql/checkoutLineItemsAddMutation
import checkoutLineItemsRemoveMutation from './graphql/checkoutLineItemsRemoveMutation.graphql';
import checkoutLineItemsUpdateMutation from './graphql/checkoutLineItemsUpdateMutation.graphql';
-export default class CheckoutResource extends Resource {
+/**
+ * The JS Buy SDK checkout resource
+ * @class
+ */
+class CheckoutResource extends Resource {
/**
* Fetches a checkout by ID.
@@ -132,3 +136,5 @@ export default class CheckoutResource extends Resource {
.then(handleCheckoutMutation('checkoutLineItemsUpdate', this.graphQLClient));
}
}
+
+export default CheckoutResource;
diff --git a/src/client.js b/src/client.js
index 3f3e0a0d2..852586cbd 100644
--- a/src/client.js
+++ b/src/client.js
@@ -14,11 +14,11 @@ import types from '../schema.json';
* The JS Buy SDK Client.
* @class
*
- * @property {Object} product The property under which product fetching methods live.
- * @property {Object} collection The property under which collection fetching methods live.
- * @property {Object} shop The property under which shop fetching methods live.
- * @property {Object} checkout The property under which shop fetching and mutating methods live.
- * @property {Object} image The property under which image helper methods live.
+ * @property {ProductResource} product The property under which product fetching methods live.
+ * @property {CollectionResource} collection The property under which collection fetching methods live.
+ * @property {ShopResource} shop The property under which shop fetching methods live.
+ * @property {CheckoutResource} checkout The property under which shop fetching and mutating methods live.
+ * @property {ImageResource} image The property under which image helper methods live.
*/
class Client {
diff --git a/src/collection-resource.js b/src/collection-resource.js
index b0630a5c2..a8e7284ed 100644
--- a/src/collection-resource.js
+++ b/src/collection-resource.js
@@ -9,7 +9,11 @@ import collectionConnectionQuery from './graphql/collectionConnectionQuery.graph
import collectionConnectionWithProductsQuery from './graphql/collectionConnectionWithProductsQuery.graphql';
import collectionByHandleQuery from './graphql/collectionByHandleQuery.graphql';
-export default class CollectionResource extends Resource {
+/**
+ * The JS Buy SDK collection resource
+ * @class
+ */
+class CollectionResource extends Resource {
/**
* Fetches all collections on the shop, not including products.
@@ -123,3 +127,4 @@ export default class CollectionResource extends Resource {
}).then(defaultResolver('shop.collections'));
}
}
+export default CollectionResource;
diff --git a/src/image-resource.js b/src/image-resource.js
index 1a1d2fd46..262805bc9 100644
--- a/src/image-resource.js
+++ b/src/image-resource.js
@@ -1,8 +1,14 @@
import Resource from './resource';
import imageHelpers from './image-helpers';
-export default class ImageResource extends Resource {
+/**
+ * The JS Buy SDK image resource
+ * @class
+ */
+class ImageResource extends Resource {
get helpers() {
return imageHelpers;
}
}
+
+export default ImageResource;
diff --git a/src/product-resource.js b/src/product-resource.js
index e4d59ac45..727d53b47 100644
--- a/src/product-resource.js
+++ b/src/product-resource.js
@@ -8,7 +8,11 @@ import productNodeQuery from './graphql/productNodeQuery.graphql';
import productConnectionQuery from './graphql/productConnectionQuery.graphql';
import productByHandleQuery from './graphql/productByHandleQuery.graphql';
-export default class ProductResource extends Resource {
+/**
+ * The JS Buy SDK product resource
+ * @class
+ */
+class ProductResource extends Resource {
get helpers() {
return productHelpers;
}
@@ -95,3 +99,5 @@ export default class ProductResource extends Resource {
.then(paginateProductConnectionsAndResolve(this.graphQLClient));
}
}
+
+export default ProductResource;
diff --git a/src/shop-resource.js b/src/shop-resource.js
index ea54e63cc..7b4b3468e 100644
--- a/src/shop-resource.js
+++ b/src/shop-resource.js
@@ -5,7 +5,11 @@ import defaultResolver from './default-resolver';
import shopQuery from './graphql/shopQuery.graphql';
import shopPolicyQuery from './graphql/shopPolicyQuery.graphql';
-export default class ShopResource extends Resource {
+/**
+ * The JS Buy SDK shop resource
+ * @class
+ */
+class ShopResource extends Resource {
/**
* Fetches shop information (`currencyCode`, `description`, `moneyFormat`, `name`, and `primaryDomain`).
@@ -40,3 +44,5 @@ export default class ShopResource extends Resource {
.then(defaultResolver('shop'));
}
}
+
+export default ShopResource;