Add context variable to webhooks process function
Overview
In Cloudflare workers/pages to access environment variables you need access to the context argument passed into functions. Without this context you are limited in what you can do within the process functions in webhooks (e.g. connect to databases, access Shopify tokens etc).
Proposal
Include a context variable to shopify.webhooks.process( e.g.
export const onRequestPost = async (context) => {
return shopify(context).webhooks.process({
context: context,
rawBody: await context.request.text(),
rawRequest: context.request,
});
};
Then pass this context into the
const webhooks = {
APP_UNINSTALLED: {
deliveryMethod: "http",
callbackUrl: "/",
callback: async (
topic,
shop,
body,
webhookId,
apiVersion,
context,
) => {
const payload = JSON.parse(body);
console.log({ apiVersion, payload, shop, topic, webhookId, context });
}
}
}
Thereby enabling workers/pages to access environment variables context.env.DATABASE_URL from callback.
It would also be easier to grok the callback if we changed the signature to an object.
callback: ({
topic,
shop,
body,
webhookId,
apiVersion,
context,
}) => {}
``
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.
We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.
If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines
Thank you!