@shopify/shopify-app-session-storage-kv
TypeScript icon, indicating that this package has built-in type declarations

3.0.6 • Public • Published

Session Storage Adapter for CloudFlare KV

CloudFlare's KV storage can be used on worker runtimes. Before using it, you'll need to set up a namespace for your sessions and pass in a KVNamespace object. You can do that either when creating an instance of KVSessionStorage, or by calling the setNamespace method.

import {shopifyApp} from '@shopify/shopify-app-express';
import {KVSessionStorage} from '@shopify/shopify-app-session-storage-kv';

const shopify = shopifyApp({
  sessionStorage: new KVSessionStorage(),
  // ...
});

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext,
  ): Promise<Response> {
    shopify.config.sessionStorage.setNamespace(env.MY_KV_NAMESPACE);
    // Handle request
  },
};

// OR

import {Miniflare} from 'miniflare';
const mf = new Miniflare({
  kvNamespaces: ['MY_KV_NAMESPACE'],
});
const shopify = shopifyApp({
  sessionStorage: new KVSessionStorage(
    await mf.getKVNamespace('MY_KV_NAMESPACE'),
  ),
  // ...
});

If you prefer to use your own implementation of a session storage mechanism that uses the SessionStorage interface, see the implementing session storage guide.

Package Sidebar

Install

npm i @shopify/shopify-app-session-storage-kv

Weekly Downloads

569

Version

3.0.6

License

MIT

Unpacked Size

60.8 kB

Total Files

10

Last publish

Collaborators

  • jaimie.rockburn
  • blittle
  • shopify-admin
  • maryharte
  • crisfmb
  • pmoloney89
  • netlohan
  • st999999
  • justin-irl
  • megswim
  • wcandillon
  • nathanpjf
  • shopify-dep
  • goodforonefare
  • lemonmade
  • vsumner
  • wizardlyhel
  • antoine.grant
  • tsov
  • andyw8-shopify
  • henrytao
  • hannachen
  • vividviolet
  • bpscott