Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@six-socks-studio/sane-shopify-server
Advanced tools
A server and lambdas to serve & sync data between Shopify and Sanity
This package contains functions to use with Shopify's Webhooks.
Create a Sanity token:
Create the configuration settings. This uses dotenv
, but you can create these values however you would like. Be sure not to publish your Sanity token!
There are three ways to create webhooks:
createAWSWebhooks
createNextWebhooks
createWebhooks
.See the follow-up instructions below for each method.
Create a file that sets up the webhooks with your configuration, i.e. src/webhooks.js
import { createNextWebhooks } from '@six-socks-studio/sane-shopify-server'
// or
// import { createAWSWebhooks } from '@six-socks-studio/sane-shopify-server'
// or
// import { createWebhooks } from '@six-socks-studio/sane-shopify-server'
import dotEnv from 'dotenv'
dotEnv.config()
const projectId = process.env.SANITY_PROJECT_ID
const dataset = process.env.SANITY_DATASET
const authToken = process.env.SANITY_AUTH_TOKEN
const shopName = process.env.SHOPIFY_SHOP_NAME
const accessToken = process.env.SHOPIFY_STOREFRONT_TOKEN
if (!projectId) throw new Error('You must provide a sanity project ID')
if (!dataset) throw new Error('You must provide a sanity dataset')
if (!authToken) throw new Error('You must provide a sanity auth token')
if (!shopName) throw new Error('You must provide a shopify shop name')
if (!accessToken) throw new Error('You must provide a shopify access token')
// optional, see below
const handleError = (err: Error) => {
Sentry.captureException(err)
}
// 🚨 Alpha breaking change: This configuration changed in 0.20.0. If you are getting errors after updating, put your `onError` handler on the `config` object, and pass that object into `createWebhooks` as the sole argument.
const config = {
secrets: {
sanity: {
projectId,
dataset,
authToken,
},
shopify: {
shopName,
accessToken,
},
},
onError: handleError,
}
export const webhooks = createNextWebhooks(config)
// or
// export const webhooks = createAWSWebhooks(config)
// or
// export const webhooks = createWebhooks(config)
You can provide your own onError
handler. This is optional, but is a good way to make sure everything is working as expected. Shopify requires a 200 response within 5 seconds, and after multiple failed calls to your webhook, it will be removed from your Shopify settings. This package returns a 200 response even if there is an error updating the item.
You'll need to create 4 API endpoints in your project. Within your pages
, create an api
directory with the following files:
onCollectionUpdate.js
onCollectionDelete.js
onProductUpdate.js
onProductDelete.js
Within each of those, import the webhooks
you created and export the appropriate method:
onCollectionUpdate.js
import { webhooks } from '../src/webhooks'
export default webhooks.onCollectionUpdate
onCollectionDelete.js
import { webhooks } from '../src/webhooks'
export default webhooks.onCollectionDelete
onProductUpdate.js
import { webhooks } from '../src/webhooks'
export default webhooks.onProductUpdate
onProductDelete.js
import { webhooks } from '../src/webhooks'
export default webhooks.onProductDelete
Your site now has 4 new endpoints:
https://www.your-site.com/api/onCollectionUpdate
https://www.your-site.com/api/onCollectionDelete
https://www.your-site.com/api/onProductUpdate
https://www.your-site.com/api/onProductDelete
Add these to your Shopify settings (see Shopify Setup below)
Create 4 lamba files, i.e.:
/lambdas/onCollectionUpdate
/lambdas/onCollectionDelete
/lambdas/onProductUpdate
/lambdas/onProductDelete
Within these files, import the webhooks
you created and export them as exports.handler
onCollectionUpdate.js
import { webhooks } from '../src/webhooks'
exports.handler = webhooks.onCollectionUpdate
onCollectionDelete.js
import { webhooks } from '../src/webhooks'
exports.handler = webhooks.onCollectionDelete
onProductUpdate.js
import { webhooks } from '../src/webhooks'
exports.handler = webhooks.onProductUpdate
onProductDelete.js
import { webhooks } from '../src/webhooks'
exports.handler = webhooks.onProductDelete
Deploy your webhooks and add their URLs to your Shopify settings (see Shopify Setup below).
If you are using another service to create the endpoints, you can use createWebhooks
to generate simple functions to handle the syncing: onCollectionUpdate
, onCollectionDelete
, onProductUpdate
and onProductDelete
. Each of these functions accepts a single object with an id
parameter, which is provided in the body sent by Shopify.
An example express.js route might be:
import { webhooks } from './src/webhooks'
app.post('/api/onProductCreate', async (req, res) => {
const { body } = req;
await webhooks.onProductCreate(body)
res.status(200).send('success')
})
To log messages to your console, set the environment variable DEBUG=sane-shopify:server
(or DEBUG=sane-shopify:*
if you want all messages to be logged)
You'll need to create 4 webhooks pointing to the endpionts you just created. Within your Shopify settings, go to Notifications, and add new webhooks for the appropriate events. Note that you do not need to create a Collection Created or Product Created webhook - shopify will call the Update webhook for both of these when a collection or product is created.
FAQs
A server and lambdas to serve & sync data between Shopify and Sanity
We found that @six-socks-studio/sane-shopify-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.