UNPKG

@alessiofrittoli/next-api

Version:
1 lines 1.12 kB
'use strict';var Cookie=require('@alessiofrittoli/web-utils/storage/Cookie');var r=class r{static request(e){return this._request=e,this}static headers(e){return this._headers=e,this}static getHeaders(){return this._headers||(this._headers=new Headers),this._headers}static get(e){if(this._request)return Cookie.Cookie.fromListString(this._request.headers.get("Cookie")||"").get(e)}static getAll(){return Cookie.Cookie.fromListString(this._request?.headers.get("Cookie")||"")}static set(e){let s=Cookie.Cookie.parse(e),o=this.getHeaders();return s.has("path")||s.set("path","/"),s.has("httpOnly")||s.set("httpOnly",true),o.append("Set-Cookie",Cookie.Cookie.toString(s)),this}static delete(e){return r.set(Cookie.Cookie.parse(e).set("maxAge",0))}};r.toString=Cookie.Cookie.toString,r.fromString=Cookie.Cookie.fromString,r.fromListString=Cookie.Cookie.fromListString,r.parse=Cookie.Cookie.parse;var i=r;Object.defineProperty(exports,"Priority",{enumerable:true,get:function(){return Cookie.Priority}});Object.defineProperty(exports,"SameSite",{enumerable:true,get:function(){return Cookie.SameSite}});exports.HttpCookie=i;