0.2.0 • Published 3 years ago

@cipherstash/stashjs-adapter v0.2.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 years ago

Stash.js Adapter

This package provides an adapter class to simplify migrating types from existing databases (such as Prisma) to a CipherStash collection.

For new applications we recommend using Stash.js which this library uses under the hood anyway.

The main component of this package is the CollectionAPI<T> class which takes a type with a numeric id ({id: number}) and maps it to a CipherStash (which uses UUID) for IDs. CollectionAPI<T> exposes a simple API as described below. It does not attempt to mirror existing ORM interfaces like Prisma (though it may offer than in the future).

The primary goals of this module are:

  • To abstract the mapping of numeric to "secure" IDs
  • To provide an API to CipherStash that uses an existing type

Usage

First create a module to represent a model (say User) in CipherStash.

// -- user-vault.ts ==
// Existing User type
import { User } from "@prisma/client"
import CollectionAPI from "@cipherstash/stashjs-adapter"

const ID_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341"

export const UserVault = new CollectionAPI<User>("users", ID_NAMESPACE)

Then use in other parts of your application. For example, in an API:

import type { NextApiRequest, NextApiResponse } from "next"
import UserVault from "user-vault"

export default async function handler(_req: NextApiRequest, res: NextApiResponse<any>) {
  const users = await UserVault.list()
  res.status(200).json(users)
}
0.1.0

3 years ago

0.2.0

3 years ago

0.0.5-dev-2

3 years ago

0.0.5-dev-3

3 years ago

0.0.5-dev

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago