@fastify/cookie 9.0.4 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/cookie",
3
- "version": "9.0.4",
3
+ "version": "9.1.0",
4
4
  "description": "Plugin for fastify to add support for cookies",
5
5
  "main": "plugin.js",
6
6
  "types": "types/plugin.d.ts",
@@ -43,11 +43,11 @@
43
43
  "@types/node": "^20.1.0",
44
44
  "benchmark": "^2.1.4",
45
45
  "fastify": "^4.0.0",
46
- "sinon": "^15.0.0",
46
+ "sinon": "^16.0.0",
47
47
  "snazzy": "^9.0.0",
48
48
  "standard": "^17.0.0",
49
49
  "tap": "^16.0.0",
50
- "tsd": "^0.28.0"
50
+ "tsd": "^0.29.0"
51
51
  },
52
52
  "dependencies": {
53
53
  "cookie": "^0.5.0",
package/plugin.js CHANGED
@@ -9,7 +9,7 @@ const kReplySetCookies = Symbol('fastify.reply.setCookies')
9
9
  const kReplySetCookiesHookRan = Symbol('fastify.reply.setCookiesHookRan')
10
10
 
11
11
  function fastifyCookieSetCookie (reply, name, value, options) {
12
- parseCookies(reply.context.server, reply.request, reply)
12
+ parseCookies(reply.server, reply.request, reply)
13
13
 
14
14
  const opts = Object.assign({}, options)
15
15
 
@@ -51,11 +51,9 @@ function fastifyCookieClearCookie (reply, name, options) {
51
51
  function parseCookies (fastify, request, reply) {
52
52
  if (reply[kReplySetCookies]) return
53
53
 
54
- request.cookies = {} // New container per request. Issue #53
55
54
  const cookieHeader = request.raw.headers.cookie
56
- if (cookieHeader) {
57
- request.cookies = fastify.parseCookie(cookieHeader)
58
- }
55
+
56
+ request.cookies = cookieHeader ? fastify.parseCookie(cookieHeader) : {} // New container per request. Issue #53
59
57
  reply[kReplySetCookies] = new Map()
60
58
  }
61
59
 
@@ -116,18 +114,6 @@ function fastifyCookieOnSendHandler (fastifyReq, fastifyRes, payload, done) {
116
114
  done()
117
115
  }
118
116
 
119
- function getHook (hook = 'onRequest') {
120
- const hooks = {
121
- onRequest: 'onRequest',
122
- preParsing: 'preParsing',
123
- preValidation: 'preValidation',
124
- preHandler: 'preHandler',
125
- [false]: false
126
- }
127
-
128
- return hooks[hook]
129
- }
130
-
131
117
  function plugin (fastify, options, next) {
132
118
  const secret = options.secret
133
119
  const hook = getHook(options.hook)
@@ -190,6 +176,18 @@ function plugin (fastify, options, next) {
190
176
  }
191
177
  }
192
178
 
179
+ function getHook (hook = 'onRequest') {
180
+ const hooks = {
181
+ onRequest: 'onRequest',
182
+ preParsing: 'preParsing',
183
+ preValidation: 'preValidation',
184
+ preHandler: 'preHandler',
185
+ [false]: false
186
+ }
187
+
188
+ return hooks[hook]
189
+ }
190
+
193
191
  function isConnectionSecure (request) {
194
192
  return (
195
193
  request.raw.socket?.encrypted === true ||
@@ -212,15 +210,9 @@ const fastifyCookie = fp(plugin, {
212
210
  * - `import { fastifyCookie } from 'fastify-cookie'`
213
211
  * - `import fastifyCookie from 'fastify-cookie'`
214
212
  */
215
- fastifyCookie.signerFactory = Signer
216
- fastifyCookie.fastifyCookie = fastifyCookie
217
- fastifyCookie.default = fastifyCookie
218
213
  module.exports = fastifyCookie
219
-
220
- fastifyCookie.fastifyCookie.signerFactory = Signer
221
- fastifyCookie.fastifyCookie.Signer = Signer
222
- fastifyCookie.fastifyCookie.sign = sign
223
- fastifyCookie.fastifyCookie.unsign = unsign
214
+ module.exports.default = fastifyCookie // supersedes fastifyCookie.default = fastifyCookie
215
+ module.exports.fastifyCookie = fastifyCookie // supersedes fastifyCookie.fastifyCookie = fastifyCookie
224
216
 
225
217
  module.exports.signerFactory = Signer
226
218
  module.exports.Signer = Signer
package/signer.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // The MIT License
7
7
  // Copyright (c) 2012–2022 LearnBoost <tj@learnboost.com> and other contributors;
8
8
 
9
- const crypto = require('crypto')
9
+ const crypto = require('node:crypto')
10
10
 
11
11
  const base64PaddingRE = /=/g
12
12
 
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const tap = require('tap')
4
- const test = tap.test
3
+ const { test } = require('tap')
5
4
  const Fastify = require('fastify')
6
5
  const sinon = require('sinon')
7
6
  const { sign, unsign } = require('../signer')
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { test } = require('tap')
4
4
  const sinon = require('sinon')
5
- const crypto = require('crypto')
5
+ const crypto = require('node:crypto')
6
6
  const { Signer, sign, unsign } = require('../signer')
7
7
 
8
8
  test('default', t => {