@code-nl/shopify-to-firestore
v1.0.2
Published
Package with methods to store and remove Shopify JSON Object simply to and from Firestore.
Readme
Shopify to Firestore
Provides functionality to:
- Store data from Shopify in Cloud Firestore
- Delete data of Shopify from Cloud Firestore
How to use
npm install @code-nl/shopify-to-firestore -- saveStore data
Load the storetoFirestore() function:
const { storeToFirestore } = require('@code-nl/shopify-to-firestore');To use the storeToFirestore method :
storeToFirestore(firestore, shopifyDomain, documentRoot, documentId, sfyObject, extractToCollections);Note that this returns a Promise so it is advisable to put this in your promise chain.
firestore | object | This is the reference to your Cloud Firestore instance (firebase.firestore())
shopifyDomain | string | This is the myshopify.com domain name of your Shopify Instance
documentRoot | callback | This is a callback function that returns the Firestore collection root of the Shopify object you want to store (see below for more info)
documentId | string | The unique ID of the Shopify object
sfyObject | object | The Shopify object that you want to store
extractToCollections | array | Array with collection options to extract specific elements to separate collections (see below for more info)Delete data
Load the deleteFromFirestore() function:
const { deleteFromFirestore } = require('@code-nl/shopify-to-firestore');To use the deleteFromFirestore method :
deleteFromFirestore(firestore, shopifyDomain, documentRoot, documentId, extractToCollections);Note that this returns a Promise so it is advisable to put this in your promise chain.
firestore | object | This is the reference to your Cloud Firestore instance (firebase.firestore())
shopifyDomain | string | This is the myshopify.com domain name of your Shopify Instance
documentRoot | callback | This is a callback function that returns the Firestore collection root of the Shopify object you want to delete (see below for more info)
documentId | string | The unique ID of the Shopify object you want to delete
extractToCollections | array | Array with collection options to delete the related separate collections (see below for more info)documentRoot
The contains a callback to the Cloud Firestore collection where the main data is stored. The first argument that is passed is the shopify domain name. An example of the callback can be:
/**
* Helper to get the Shopify orders root
* @param {string} shopifyDomain The myshopify.com domain name
*/
exports.getOrderDocRoot = (shopifyDomain) => {
return module.exports.getShopDocRoot(shopifyDomain).collection('sfyOrders');
};In this case getOrderDocRoot is the callback you will have to pass on. The sfyOrders is the collection name that is used as subcollection in the shops collection.
extractToCollections
This contains an array of objects which provides a config for linked elements that needs to be stored or removed.
An example:
// set the collections that needs to be extracted to a main collection
const extractToCollections = [
{
name: 'fulfillments',
collection: getFulfillmentDocRoot,
parentDocRef: 'orderId',
documentId: 'id'
}
];In this case the fulfillments array in the Shopify object will be stored as seperate document(s) in the getFulfillmentDocRoot collection. The parentDocRef will contain the ID of the parent document. documentId is the unique ID that is used to store the extracted document in.
