npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shopify/gate-context-client

v1.0.1

Published

Utility API utilizing the AJAX Cart API to store wallet address and signature data.

Downloads

116

Readme

@shopify/gate-context-client

npm version CI PRs Welcome

The gate-context-client package provides an abstract interface to read and write gate context information. The client writes gate context information for use by Shopify functions. For example, the client could write a signed message to the context. That message could be validated and processed by a Shopify function in order to apply discounts or block checkout.

Installation

Install the shopify/gate-context-client package.

yarn add @shopify/gate-context-client

Documentation

See the Tokengating example app tutorial for further documentation. Specifically, the end of the Show gates on the storefront using a theme app extension part about writing an HMAC.

Code example

interface Input {
  walletAddress: string;
  walletVerificationMessage?: string;
  walletVerificationSignature?: string;
}

const client = getGateContextClient(
  backingStore: 'ajaxApi',
);

async function run(data: Input) {
  try {
    await client.write(data)
  } catch(error) {
    console.error('Error writing to GateContext', error);
  }
}

Backends

The client is intended to abstract backend details and automatically choose the correct backend where possible. For example, for the Online store channel, the Cart Ajax API will be used. The Cart Ajax API is the only supported backend right now.

Cart Ajax API

For the Cart Ajax API, the data will be written to a special cart attribute called _shopify_gate_context as a JSON string. The client implementation for this backend will automatically serialize and deserialize the value as needed.

After writing via the client and inspecting the cart, via /cart.js, you'd see something like the following:

{
  "token": "111f",
  "attributes": {
    "_shopify_gate_context": "{\"attribute1\": 123}"
  },
  ...
}

shopifyGateContextGenerator

This is an async transformation function that will get called before the write to the backend occurs, and may be used to override the written value.

interface Input {
  walletAddress: string;
  walletVerificationMessage?: string;
  walletVerificationSignature?: string;
}

const client = getGateContextClient({
  backingStore: 'ajaxApi',
  // adds an additional key before writing
  shopifyGateContextGenerator: (data: Input) => {
    const {walletAddress} = data;
    // async call using walletAddress
    return Promise.resolve({...data, extraKey: ''});
  },
});

async function run(data: Input) {
  try {
    await client.write(data);
  } catch (error) {
    console.error('Error writing to GateContext', error);
  }
}

Contributing

Pull requests are welcome. See the contribution guidelines for more information.

License

MIT © Shopify, see LICENSE.md for details.