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/shopify-app-session-storage-prisma

v5.1.3

Published

Shopify App Session Storage for Prisma

Downloads

56,415

Readme

Session Storage Adapter for Prisma

This package implements the SessionStorage interface that works with an instance of Prisma.

Session storage for prisma requires a schema.prisma with a Session table with at-least the following columns:

model Session {
  id          String    @id
  shop        String
  state       String
  isOnline    Boolean   @default(false)
  scope       String?
  expires     DateTime?
  accessToken String
  userId      BigInt?
}

[!WARNING] Some DB adapters adapters may set a maximum length for the String type by default, please ensure your fields allow for long enough strings. See https://www.prisma.io/docs/orm/reference/prisma-schema-reference#string for more information

You can then instantiate and use PrismaSessionStorage like so:

import {shopifyApp} from '@shopify/shopify-app-express';
import {PrismaSessionStorage} from '@shopify/shopify-app-session-storage-prisma';
import {PrismaClient} from '@prisma/client';

const prisma = new PrismaClient();
const storage = new PrismaSessionStorage(prisma);

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

Options

You can also pass in some optional flags to tweak the behavior of the adapter.

Custom table name

You can pass in the tableName option if you want to use a different table name in your schema. For example:

const storage = new PrismaSessionStorage(prisma, {
  tableName: 'MyCustomSession',
});

Note: If you use SQLite with Prisma note that sqlite is a local, file-based SQL database. It persists all tables to a single file on your local disk. As such, it’s simple to set up and is a great choice for getting started with Shopify App development. However, it won’t work when your app getting scaled across multiple instances because they would each create their own database.

If you prefer to use your own implementation of a session storage mechanism that is compatible with the @shopify/shopify-app-express package, see the implementing session storage guide.

Connection retries

When the storage starts up, it will connect to the database during startup so the app can start. If the DB server takes too long to start, the setup may fail.

To avoid that, you can pass in the connectionRetries and connectionRetryIntervalMs options to control how many times to retry, and how long to wait between tries, respectively. For example:

const storage = new PrismaSessionStorage(prisma, {
  // Default values
  connectionRetries: 2,
  connectionRetryIntervalMs: 5000,
});

Updating your database

When updating the type of database you are using, you may need to make some changes to your project for Prisma to work correctly. Please review the prisma documentation for your specific database type for configuration.

Troubleshooting

MissingSessionTableError error is thrown

Some common reasons for that are:

  1. The database was not migrated.
  2. The Session table above was not added to the schema.
  3. The table is in the schema, but isn't named Session.

Here are some possible solutions for this issue:

  1. Ensure you've run the migrate command to apply the schema.
  2. Ensure you've copied the schema above into your prisma.schema file.
  3. If you've made changes to the table, make sure it's still called Session.

Error: The "mongodb" provider is not supported with this command

MongoDB does not support the prisma migrate command. If you are using MongoDB please see the Prisma documentation for configuring your database.