@typhoslabs/shopify

Thin wrapper for specific handling of Shopify for TyphosLabs

Usage no npm install needed!

<script type="module">
  import typhoslabsShopify from 'https://cdn.skypack.dev/@typhoslabs/shopify';
</script>

README

shopify

A wrapper around shopify-node-api for specific handling of Shopify for TyphosLabs lambdas.

Usage

Typical usage:

'use strict';

var ShopifyAPI = require('@typhoslabs/shopify')(optional_settings);

module.exports = Shopify.lambda((event, context, callback, shopify) => {
    // do a typical shopify-node-api. Getting the token, filling in the shop, and setting up
    // the shopify-node-api instance is done for you.
    shopify.get("/admin/shop.json", function(err, data, headers){
        // do stuff etc.
        
        // when done
        callback(null);
    });
});

Note: your lambda must use the shopify-auth custom authorizer.

Install usage:

'use strict';

var Shopify = require('@typhoslabs/shopify')();

module.exports = Shopify.install((event, context, callback, shopify) => {
    // think normal lambda but this function is called when we've
    // requested the permissions, got the token and saved it to the database, and
    // need to add things to the theme files etc. Additional values to be saved
    // to the store record for this app may be returned using the callback
    
    // do async stuff
    
    // success
    return callback();
});

// Will return { session: "averylongsessiontoken", shop: "typhoslabs" } when already installed
// Will return { session: "averylongsessiontoken", shop: "typhoslabs", "installed": true } when newly installed
// Will return { redirect: "... a redirect url ..." } if a redirect is needed

Note: the lambda event must look similar to this:

{
    "query": {
        "shop": "typhoslabs.myshopify.com",
        "...": "my querystring values..."
    },
    "shopify": {
        "api_key": "MY_API_KEY",
        "api_secret": "MY_API_SECRET",
        "redirect_url": "https://api.typhoslabs.com/apps/my-app",
        "scopes": "read_orders,write_orders",
    }
}

Optional Settings

Include optional setting overrides to be passed to shopify-node-api.