1.3.2 • Published 12 months ago

drksession v1.3.2

Weekly downloads
-
License
MIT OR Apache-2.0
Repository
github
Last release
12 months ago

drksession

Lightweight session manager using Cloudflare KV storage

Usage

Create a SessionManager object providing a KvAdapter encapsulating a KVNamespace bound to your worker. You need to provide the cookie name and an array of valid domains for setting and receiving cookies. The first domain in the array will be used as return URL if no referrer is provided when the user hits the worker.

Maturity

This library is really new and it is the very first project I write in TypeScript for Cloudflare workers. Using it for managing session with potential access to sensitive information is discouraged.

TODO

  • Add tests
  • Add Update session feature to refresh tokens provided by authentications authorities.
  • Refactor to make it more OOP (It was a set of functions originally)

Tooling setup

Install wrangler

npm install wrangler --save-dev

Update wrangler

npm install wrangler@latest

Add vitest

npm install --save-dev --save-exact vitest@1.5.3
npm install --save-dev @cloudflare/vitest-pool-workers

In the tsconfig.json add:

  {
    "compilerOptions": {
      ...,
      "types": [
        "@cloudflare/workers-types/experimental"
+       "@cloudflare/vitest-pool-workers"
      ]
    },
  }

Use with import:

import { env } from "cloudflare:test";

Add ESlint

npm init @eslint/config@1.1.0

Add prettier

npm install --save-dev --save-exact prettier

Add coverage to vitest with istanbul

npm i -D @vitest/coverage-istanbul@1.5.3

And change vitest.config.ts:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    coverage: {
      provider: 'istanbul'
    },
  },
})

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.3.2

12 months ago

1.3.1

12 months ago

1.3.0

12 months ago

1.2.0

12 months ago

1.1.1

12 months ago

1.0.19

12 months ago

1.1.0

12 months ago

1.0.18

12 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.1.9

12 months ago

1.1.8

12 months ago

1.1.7

12 months ago

1.1.6

12 months ago

1.1.5

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.0.22

12 months ago

1.0.21

12 months ago

1.0.20

12 months ago

1.0.26

12 months ago

1.0.25

12 months ago

1.0.24

12 months ago

1.0.23

12 months ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago