@fastify/cookie 8.1.0 → 8.2.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": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "Plugin for fastify to add support for cookies",
5
5
  "main": "plugin.js",
6
6
  "types": "types/plugin.d.ts",
@@ -47,7 +47,7 @@
47
47
  "snazzy": "^9.0.0",
48
48
  "standard": "^17.0.0",
49
49
  "tap": "^16.0.0",
50
- "tsd": "^0.22.0"
50
+ "tsd": "^0.24.1"
51
51
  },
52
52
  "dependencies": {
53
53
  "cookie": "^0.5.0",
package/plugin.js CHANGED
@@ -42,7 +42,7 @@ function fastifyCookieSetCookie (reply, name, value, options, signer) {
42
42
  }
43
43
 
44
44
  function fastifyCookieClearCookie (reply, name, options) {
45
- const opts = Object.assign({ path: '/' }, options || { }, {
45
+ const opts = Object.assign({ path: '/' }, options, {
46
46
  expires: new Date(1),
47
47
  signed: undefined,
48
48
  maxAge: undefined
@@ -135,8 +135,9 @@ function plugin (fastify, options, next) {
135
135
  return fastifyCookieSetCookie(this, name, value, opts, signer)
136
136
  }
137
137
 
138
- function clearCookie (name, options) {
139
- return fastifyCookieClearCookie(this, name, options)
138
+ function clearCookie (name, cookieOptions) {
139
+ const opts = Object.assign({}, options.parseOptions, cookieOptions)
140
+ return fastifyCookieClearCookie(this, name, opts)
140
141
  }
141
142
  }
142
143
 
@@ -942,3 +942,51 @@ test('if cookies are not set, then the handler creates an empty req.cookies obje
942
942
  t.equal(res.statusCode, 200)
943
943
  })
944
944
  })
945
+
946
+ test('clearCookie should include parseOptions', (t) => {
947
+ t.plan(14)
948
+ const fastify = Fastify()
949
+ fastify.register(plugin, {
950
+ parseOptions: {
951
+ path: '/test',
952
+ domain: 'example.com'
953
+ }
954
+ })
955
+
956
+ const cookieOptions = {
957
+ path: '/test',
958
+ maxAge: 36000
959
+ }
960
+
961
+ fastify.get('/test1', (req, reply) => {
962
+ reply
963
+ .setCookie('foo', 'foo', cookieOptions)
964
+ .clearCookie('foo', cookieOptions)
965
+ .send({ hello: 'world' })
966
+ })
967
+
968
+ fastify.inject({
969
+ method: 'GET',
970
+ url: '/test1'
971
+ }, (err, res) => {
972
+ t.error(err)
973
+ t.equal(res.statusCode, 200)
974
+ t.same(JSON.parse(res.body), { hello: 'world' })
975
+
976
+ const cookies = res.cookies
977
+
978
+ t.equal(cookies.length, 2)
979
+ t.equal(cookies[0].name, 'foo')
980
+ t.equal(cookies[0].value, 'foo')
981
+ t.equal(cookies[0].maxAge, 36000)
982
+ t.equal(cookies[0].path, '/test')
983
+ t.equal(cookies[0].domain, 'example.com')
984
+
985
+ t.equal(cookies[1].name, 'foo')
986
+ t.equal(cookies[1].value, '')
987
+ t.equal(cookies[1].path, '/test')
988
+ t.equal(cookies[1].domain, 'example.com')
989
+
990
+ t.ok(new Date(cookies[1].expires) < new Date())
991
+ })
992
+ })
@@ -3,8 +3,7 @@ import { expectError, expectType } from 'tsd';
3
3
  import * as fastifyCookieStar from '..';
4
4
  import fastifyCookieCjsImport = require('..');
5
5
  import fastifyCookieDefault, { fastifyCookie as fastifyCookieNamed } from '..';
6
- import fastify, { FastifyInstance, FastifyPluginCallback, FastifyReply, setCookieWrapper } from 'fastify';
7
- import { Server } from 'http';
6
+ import fastify, { FastifyInstance, FastifyReply, setCookieWrapper } from 'fastify';
8
7
 
9
8
  const fastifyCookieCjs = require('..');
10
9