insite-cookie 2.5.1 → 2.6.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/README.md
CHANGED
|
@@ -73,7 +73,7 @@ Or use [insite-client](../client/README.md) with `cookie: {}`.
|
|
|
73
73
|
|--------|------|-------------|
|
|
74
74
|
| `CookieSetter` | class | Sets cookies via token handoff; session sync on connect/session change |
|
|
75
75
|
| `CookieMiddleware` | class | HTTP middleware for `/cookie?token` |
|
|
76
|
-
| `parseCookie` | function | Parses cookie string
|
|
76
|
+
| `parseCookie` | function | Parses a cookie string into `Record<string, unknown>`, splitting each pair on the first `=` |
|
|
77
77
|
| `CookieMiddlewareOptions` | type | CookieMiddleware constructor options |
|
|
78
78
|
|
|
79
79
|
**Client (`insite-cookie/client`):**
|
|
@@ -94,7 +94,7 @@ class CookieSetter<AS extends AbilitiesSchema>
|
|
|
94
94
|
| Member | Signature | Description |
|
|
95
95
|
|--------|------------|-------------|
|
|
96
96
|
| constructor | `(options: Options<AS>)` | `usersServer` required; `domain` defaults to `process.env.INSITE_HOST`; `maxAge` defaults to session TTL |
|
|
97
|
-
| set | `(wssc, cookie, options) => void` | Queues cookie, sends token; client fetches
|
|
97
|
+
| set | `(wssc, cookie, options) => void` | Queues cookie, sends a 32-byte token; client fetches `GET /cookie?token` for Set-Cookie |
|
|
98
98
|
| unset | `(wssc, names) => void` | Clears cookies by name |
|
|
99
99
|
| usersServer | `UsersServer<AS>` | Injected |
|
|
100
100
|
| domain | `string \| undefined` | Cookie domain |
|
package/dist/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var r={set:"~setcookie"};var s=class o{constructor(e,t={}){let{method:n="GET",url:h="/cookie",onload:i=o.onXhrLoad,onerror:d=o.onXhrError}=t;this.method=n,this.url=h,this.#t=i,this.#e=d,e.on(`message:${r.set}`,this.#o)}method;url;#t;#e;#o=e=>{let t=new XMLHttpRequest;t.onload=this.#t,t.onerror=this.#e,t.open(this.method,`${this.url}?${e}`,!0),t.send(null)};static onXhrLoad(){this.readyState===4&&this.status!==200&&console.error("Set cookie:",this.statusText)}static onXhrError(){console.error("Set cookie:",this.statusText)}};export{s as CookieSetter};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/common.ts", "../../src/client/Setter.ts"],
|
|
4
4
|
"sourcesContent": ["export const headers = {\n\tset: \"~setcookie\"\n};\n\nexport type Method = \"GET\" | \"POST\";\n", "import type { WS } from \"insite-ws/client\";\nimport { headers, type Method } from \"../common\";\n\n\n/* eslint-disable unicorn/prefer-add-event-listener */\n\n\nexport type Options = {\n\tmethod?: Method;\n\turl?: string;\n\tonload?: (this: XMLHttpRequest, event: ProgressEvent) => unknown;\n\tonerror?: (this: XMLHttpRequest, event: ProgressEvent) => unknown;\n};\n\n\nexport class CookieSetter {\n\tconstructor(ws: WS, options: Options = {}) {\n\t\t\n\t\tconst {\n\t\t\tmethod = \"GET\",\n\t\t\turl = \"/cookie\",\n\t\t\tonload = CookieSetter.onXhrLoad,\n\t\t\tonerror = CookieSetter.onXhrError\n\t\t} = options;\n\t\t\n\t\tthis.method = method;\n\t\tthis.url = url;\n\t\tthis.#onload = onload;\n\t\tthis.#onerror = onerror;\n\t\t\n\t\tws.on(`message:${headers.set}`, this.#handleSet);\n\t\t\n\t}\n\t\n\treadonly method;\n\treadonly url;\n\t#onload;\n\t#onerror;\n\t\n\t#handleSet = (token: string) => {\n\t\t\n\t\tconst xhr = new XMLHttpRequest();\n\t\t\n\t\txhr.onload = this.#onload;\n\t\txhr.onerror = this.#onerror;\n\t\t\n\t\txhr.open(this.method, `${this.url}?${token}`, true);\n\t\t\n\t\txhr.send(null);\n\t\t\n\t};\n\t\n\t\n\tstatic onXhrLoad(this: XMLHttpRequest) {\n\t\t\n\t\tif (this.readyState === 4 && this.status !== 200)\n\t\t\tconsole.error(\"Set cookie:\", this.statusText);\n\t\t\n\t}\n\t\n\tstatic onXhrError(this: XMLHttpRequest) {\n\t\t\n\t\tconsole.error(\"Set cookie:\", this.statusText);\n\t\t\n\t}\n\t\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["headers", "
|
|
5
|
+
"mappings": "AAAO,IAAMA,EAAU,CACtB,IAAK,YACN,ECaO,IAAMC,EAAN,MAAMC,CAAa,CACzB,YAAYC,EAAQC,EAAmB,CAAC,EAAG,CAE1C,GAAM,CACL,OAAAC,EAAS,MACT,IAAAC,EAAM,UACN,OAAAC,EAASL,EAAa,UACtB,QAAAM,EAAUN,EAAa,UACxB,EAAIE,EAEJ,KAAK,OAASC,EACd,KAAK,IAAMC,EACX,KAAKG,GAAUF,EACf,KAAKG,GAAWF,EAEhBL,EAAG,GAAG,WAAWQ,EAAQ,GAAG,GAAI,KAAKC,EAAU,CAEhD,CAES,OACA,IACTH,GACAC,GAEAE,GAAcC,GAAkB,CAE/B,IAAMC,EAAM,IAAI,eAEhBA,EAAI,OAAS,KAAKL,GAClBK,EAAI,QAAU,KAAKJ,GAEnBI,EAAI,KAAK,KAAK,OAAQ,GAAG,KAAK,GAAG,IAAID,CAAK,GAAI,EAAI,EAElDC,EAAI,KAAK,IAAI,CAEd,EAGA,OAAO,WAAgC,CAElC,KAAK,aAAe,GAAK,KAAK,SAAW,KAC5C,QAAQ,MAAM,cAAe,KAAK,UAAU,CAE9C,CAEA,OAAO,YAAiC,CAEvC,QAAQ,MAAM,cAAe,KAAK,UAAU,CAE7C,CAED",
|
|
6
|
+
"names": ["headers", "CookieSetter", "_CookieSetter", "ws", "options", "method", "url", "onload", "onerror", "#onload", "#onerror", "headers", "#handleSet", "token", "xhr"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Middleware.d.ts","sourceRoot":"","sources":["../../src/server/Middleware.ts"],"names":[],"mappings":"AACA,OAAO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out as
|
|
1
|
+
import{getWithTimeout as k}from"@nesvet/n";import{ClassMiddleware as C}from"insite-http";var d=new Map;function a(n){if(n.includes(";")||n.includes("\r")||n.includes(`
|
|
2
|
+
`)||n.includes("\0"))throw new Error("Invalid cookie attribute")}var m=class n extends C{constructor(e={}){super();let{path:t="/cookie"}=e;this.listeners={GET:[[t,this.#e]]}}#e=(e,t)=>{let i=e.querystring?k(d,e.querystring):void 0;if(i){let[s,o,p]=i;return p&&t.once("finish",p),t.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Set-Cookie":n.cookify(s,o)}).end()}return!1};static make({name:e,value:t,maxAge:i,expiresAt:s,domain:o,path:p="/",secure:l=!0,httpOnly:g=!0,sameSite:u="Strict"}){a(e),a(t),o&&a(o),typeof p=="string"&&a(p);let r=[`${e}=${t}`];return i!==void 0?r.push(`Max-Age=${i}`):s&&r.push(`Max-Age=${Math.round((s.getTime()-Date.now())/1e3)}`),o&&r.push(`Domain=${o}`),p&&r.push(`Path=${p}`),l&&r.push("Secure"),g&&r.push("HttpOnly"),u&&r.push(`SameSite=${u}`),r.join("; ")}static cookify(e,t){return Object.entries(e).map(([i,s])=>this.make({name:i,value:s,...t}))}};function h(n){return n?n.split(/;\s*/).reduce((e,t)=>{let i=t.indexOf("="),s=i===-1?t:t.slice(0,i),o=i===-1?void 0:t.slice(i+1);try{e[s]=JSON.parse(o)}catch{e[s]=o}return e},{}):{}}import A from"node:crypto";import{setWithTimeout as x}from"@nesvet/n";var c={set:"~setcookie"};var S=2e3,y=86400,f=class{constructor({usersServer:e,domain:t,maxAge:i,updateAge:s}){this.usersServer=e,this.domain=t??process.env.INSITE_HOST,this.maxAge=i??this.usersServer.users.sessions.collection.expireAfterSeconds,this.updateAge=s??Math.min(y,Math.floor(this.maxAge/2)),this.usersServer.wss.on("client-connect",this.#o),this.usersServer.wss.on("client-session",this.#n),this.usersServer.users.on("session-delete",this.#r)}#e=new WeakMap;#t=new Map;#i=new Set;usersServer;domain;maxAge;updateAge;set(e,t,i,s){let o=A.randomBytes(32).toString("hex");x(d,o,[t,i,s],S),e.sendMessage(c.set,o)}unset(e,t){this.set(e,t.reduce((i,s)=>(i[s]="",i),{}),{domain:this.domain,maxAge:0})}#o=(e,t)=>{if(this.#e.set(e,null),t.headers.cookie){let{sessionId:i=null}=h(t.headers.cookie);this.#e.set(e,i),i&&this.usersServer.setSession(e,i,!0)}};#n=(e,t)=>{let i=e.session?._id??null;this.#e.get(e)!==i?(this.#e.set(e,i),e.isOpen&&e.session?this.#s(e):this.unset(e,["sessionId"])):t&&e.isOpen&&e.session&&this.#p(e.session)&&this.#s(e)};#r=e=>{this.#t.delete(e._id),this.#i.delete(e._id)};#s(e){let{session:t}=e;if(!t||this.#i.has(t._id))return;this.#i.add(t._id);let i=setTimeout(()=>{this.#i.delete(t._id),this.#t.has(t._id)||this.#t.set(t._id,0)},S);this.set(e,{sessionId:t._id},{domain:this.domain,maxAge:this.maxAge},()=>{clearTimeout(i),this.#i.delete(t._id),this.#t.set(t._id,Date.now())})}#p(e){let t=this.#t.get(e._id)??e.createdAt;return Date.now()-t>=this.updateAge*1e3}static parse=h};export{m as CookieMiddleware,f as CookieSetter,h as parseCookie};
|
|
2
3
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/Middleware.ts", "../../src/server/tokenMap.ts", "../../src/server/parse.ts", "../../src/server/Setter.ts", "../../src/common.ts"],
|
|
4
|
-
"sourcesContent": ["import { getWithTimeout } from \"@nesvet/n\";\nimport { ClassMiddleware, type RequestHandler } from \"insite-http\";\nimport { tokenMap } from \"./tokenMap\";\nimport type { Cookie, CookieOptions } from \"./types\";\n\n\ntype Options = {\n\tpath?: RegExp | string;\n};\n\nexport type { Options as CookieMiddlewareOptions };\n\ntype MakeArg = CookieOptions & {\n\tname: keyof Cookie;\n\tvalue: Cookie[keyof Cookie];\n};\n\n\nexport class CookieMiddleware extends ClassMiddleware {\n\tconstructor(options: Options = {}) {\n\t\tsuper();\n\t\t\n\t\tconst {\n\t\t\tpath = \"/cookie\"\n\t\t} = options;\n\t\t\n\t\tthis.listeners = {\n\t\t\tGET: [ [ path, this.#handler ] ]\n\t\t};\n\t\t\n\t}\n\t\n\t#handler: RequestHandler = (request, response) => {\n\t\tconst pending = request.querystring ? getWithTimeout(tokenMap, request.querystring) : undefined;\n\t\t\n\t\tif (pending) {\n\t\t\tconst [ cookie, options, onSet ] = pending;\n\t\t\t\n\t\t\
|
|
5
|
-
"mappings": "AAAA,OAAS,kBAAAA,MAAsB,YAC/B,OAAS,mBAAAC,MAA4C,cCQ9C,IAAMC,EAAW,IAAI,
|
|
6
|
-
"names": ["getWithTimeout", "ClassMiddleware", "tokenMap", "CookieMiddleware", "_CookieMiddleware", "ClassMiddleware", "options", "path", "#handler", "request", "response", "pending", "getWithTimeout", "tokenMap", "cookie", "onSet", "name", "
|
|
4
|
+
"sourcesContent": ["import { getWithTimeout } from \"@nesvet/n\";\nimport { ClassMiddleware, type RequestHandler } from \"insite-http\";\nimport { tokenMap } from \"./tokenMap\";\nimport type { Cookie, CookieOptions } from \"./types\";\n\n\ntype Options = {\n\tpath?: RegExp | string;\n};\n\nexport type { Options as CookieMiddlewareOptions };\n\ntype MakeArg = CookieOptions & {\n\tname: keyof Cookie;\n\tvalue: Cookie[keyof Cookie];\n};\n\nfunction assertCookiePart(value: string) {\n\tif (value.includes(\";\") || value.includes(\"\\r\") || value.includes(\"\\n\") || value.includes(\"\\0\"))\n\t\tthrow new Error(\"Invalid cookie attribute\");\n}\n\n\nexport class CookieMiddleware extends ClassMiddleware {\n\tconstructor(options: Options = {}) {\n\t\tsuper();\n\t\t\n\t\tconst {\n\t\t\tpath = \"/cookie\"\n\t\t} = options;\n\t\t\n\t\tthis.listeners = {\n\t\t\tGET: [ [ path, this.#handler ] ]\n\t\t};\n\t\t\n\t}\n\t\n\t#handler: RequestHandler = (request, response) => {\n\t\tconst pending = request.querystring ? getWithTimeout(tokenMap, request.querystring) : undefined;\n\t\t\n\t\tif (pending) {\n\t\t\tconst [ cookie, options, onSet ] = pending;\n\t\t\t\n\t\t\tif (onSet)\n\t\t\t\tresponse.once(\"finish\", onSet);\n\t\t\t\n\t\t\treturn response.writeHead(200, {\n\t\t\t\t\"Content-Type\": \"text/plain; charset=utf-8\",\n\t\t\t\t\"Set-Cookie\": CookieMiddleware.cookify(cookie, options)\n\t\t\t}).end();\n\t\t}\n\t\t\n\t\treturn false;\n\t};\n\t\n\t\n\tstatic make({ name, value, maxAge, expiresAt, domain, path = \"/\", secure = true, httpOnly = true, sameSite = \"Strict\" }: MakeArg) {\n\t\tassertCookiePart(name);\n\t\tassertCookiePart(value);\n\t\t\n\t\tif (domain)\n\t\t\tassertCookiePart(domain);\n\t\t\n\t\tif (typeof path == \"string\")\n\t\t\tassertCookiePart(path);\n\t\t\n\t\tconst cookie = [ `${name}=${value}` ];\n\t\t\n\t\tif (maxAge !== undefined)\n\t\t\tcookie.push(`Max-Age=${maxAge}`);\n\t\telse if (expiresAt)\n\t\t\tcookie.push(`Max-Age=${Math.round((expiresAt.getTime() - Date.now()) / 1000)}`);\n\t\t\n\t\tif (domain)\n\t\t\tcookie.push(`Domain=${domain}`);\n\t\t\n\t\tif (path)\n\t\t\tcookie.push(`Path=${path}`);\n\t\t\n\t\tif (secure)\n\t\t\tcookie.push(\"Secure\");\n\t\t\n\t\tif (httpOnly)\n\t\t\tcookie.push(\"HttpOnly\");\n\t\t\n\t\tif (sameSite)\n\t\t\tcookie.push(`SameSite=${sameSite}`);\n\t\t\n\t\treturn cookie.join(\"; \");\n\t}\n\t\n\tstatic cookify(cookie: Cookie, options: CookieOptions) {\n\t\treturn Object.entries(cookie).map(([ name, value ]) => this.make({ name, value, ...options }));\n\t}\n\t\n}\n", "import type { Cookie, CookieOptions } from \"./types\";\n\n\ntype PendingCookie = [\n\tcookie: Cookie,\n\toptions: CookieOptions,\n\tonSet?: () => void\n];\n\nexport const tokenMap = new Map<string, PendingCookie>();\n", "export function parseCookie(cookie: string) {\n\treturn cookie ? cookie.split(/;\\s*/).reduce((object, keyEqValue) => {\n\t\tconst separatorIndex = keyEqValue.indexOf(\"=\");\n\t\tconst key = separatorIndex === -1 ? keyEqValue : keyEqValue.slice(0, separatorIndex);\n\t\tconst value = separatorIndex === -1 ? undefined : keyEqValue.slice(separatorIndex + 1);\n\t\t\n\t\ttry {\n\t\t\tobject[key] = JSON.parse(value as string);\n\t\t} catch {\n\t\t\tobject[key] = value;\n\t\t}\n\t\t\n\t\treturn object;\n\t}, {} as Record<string, unknown>) : {};\n}\n", "import crypto from \"node:crypto\";\nimport type { IncomingMessage } from \"node:http\";\nimport { setWithTimeout } from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport type { UsersServer, WSSCWithUser } from \"insite-users-server-ws\";\nimport { headers } from \"../common\";\nimport { parseCookie } from \"./parse\";\nimport { tokenMap } from \"./tokenMap\";\nimport type { Cookie, CookieOptions } from \"./types\";\n\n\nconst cookieTokenTimeout = 2000;\n\n/** Auth.js default: rewrite the session cookie at most once a day. */\nconst defaultUpdateAge = 86_400;\n\nexport type Options<AS extends AbilitiesSchema> = {\n\tusersServer: UsersServer<AS>;\n\tdomain?: string;\n\t/** Cookie `Max-Age` in seconds. Defaults to the session TTL. */\n\tmaxAge?: number;\n\t/**\n\t * Minimum seconds between cookie rewrites.\n\t * `0` rewrites on every prolonged connect.\n\t * Defaults to one day, or half of `maxAge` when that is shorter.\n\t */\n\tupdateAge?: number;\n};\n\n\nexport class CookieSetter<AS extends AbilitiesSchema> {\n\tconstructor({ usersServer, domain, maxAge, updateAge }: Options<AS>) {\n\t\tthis.usersServer = usersServer;\n\t\tthis.domain = domain ?? process.env.INSITE_HOST;\n\t\tthis.maxAge = maxAge ?? this.usersServer.users.sessions.collection.expireAfterSeconds;\n\t\tthis.updateAge = updateAge ?? Math.min(defaultUpdateAge, Math.floor(this.maxAge / 2));\n\t\t\n\t\tthis.usersServer.wss.on(\"client-connect\", this.#handleClientConnect);\n\t\tthis.usersServer.wss.on(\"client-session\", this.#handleClientSession);\n\t\tthis.usersServer.users.on(\"session-delete\", this.#handleSessionDelete);\n\t\t\n\t}\n\t\n\t#wsSessionIdMap = new WeakMap<WSSCWithUser<AS>, string | null>();\n\t\n\t/** When the cookie handoff last completed. Absent entries fall back to `createdAt`. `0` means the last attempt expired. */\n\t#cookieSetAtBySessionId = new Map<string, number>();\n\t\n\t/** Session ids with a cookie token that has not been redeemed or expired yet. */\n\t#cookieWritePending = new Set<string>();\n\t\n\tusersServer;\n\tdomain;\n\tmaxAge;\n\t\n\t/** Seconds. A connect inside this window prolongs the document and leaves the cookie alone. */\n\tupdateAge;\n\t\n\tset(wssc: WSSCWithUser<AS>, cookie: Cookie, options: CookieOptions, onSet?: () => void) {\n\t\t\n\t\tconst token = crypto.randomBytes(32).toString(\"hex\");\n\t\t\n\t\tsetWithTimeout(tokenMap, token, [ cookie, options, onSet ], cookieTokenTimeout);\n\t\t\n\t\twssc.sendMessage(headers.set, token);\n\t\t\n\t}\n\t\n\tunset(wssc: WSSCWithUser<AS>, names: string[]) {\n\t\tthis.set(wssc, names.reduce((cookie, name) => {\n\t\t\tcookie[name] = \"\";\n\t\t\t\n\t\t\treturn cookie;\n\t\t}, {} as Cookie), { domain: this.domain, maxAge: 0 });\n\t\t\n\t}\n\t\n\t#handleClientConnect = (wssc: WSSCWithUser<AS>, request: IncomingMessage) => {\n\t\tthis.#wsSessionIdMap.set(wssc, null);\n\t\t\n\t\tif (request.headers.cookie) {\n\t\t\tconst { sessionId = null } = parseCookie(request.headers.cookie) as { sessionId: string | null };\n\t\t\t\n\t\t\tthis.#wsSessionIdMap.set(wssc, sessionId);\n\t\t\t\n\t\t\tif (sessionId)\n\t\t\t\tthis.usersServer.setSession(wssc, sessionId, true);\n\t\t}\n\t\t\n\t};\n\t\n\t#handleClientSession = (wssc: WSSCWithUser<AS>, shouldProlong?: boolean) => {\n\t\tconst sessionId = wssc.session?._id ?? null;\n\t\t\n\t\tif (this.#wsSessionIdMap.get(wssc) !== sessionId) {\n\t\t\tthis.#wsSessionIdMap.set(wssc, sessionId);\n\t\t\t\n\t\t\tif (wssc.isOpen && wssc.session)\n\t\t\t\tthis.#writeSessionCookie(wssc);\n\t\t\telse\n\t\t\t\tthis.unset(wssc, [ \"sessionId\" ]);\n\t\t} else if (shouldProlong && wssc.isOpen && wssc.session && this.#isCookieStale(wssc.session))\n\t\t\tthis.#writeSessionCookie(wssc);\n\t\t\n\t};\n\t\n\t#handleSessionDelete = (session: { _id: string }) => {\n\t\tthis.#cookieSetAtBySessionId.delete(session._id);\n\t\tthis.#cookieWritePending.delete(session._id);\n\t\t\n\t};\n\t\n\t#writeSessionCookie(wssc: WSSCWithUser<AS>) {\n\t\tconst { session } = wssc;\n\t\t\n\t\tif (!session || this.#cookieWritePending.has(session._id))\n\t\t\treturn;\n\t\t\n\t\tthis.#cookieWritePending.add(session._id);\n\t\t\n\t\tconst pendingTimeout = setTimeout(() => {\n\t\t\tthis.#cookieWritePending.delete(session._id);\n\t\t\t\n\t\t\tif (!this.#cookieSetAtBySessionId.has(session._id))\n\t\t\t\tthis.#cookieSetAtBySessionId.set(session._id, 0);\n\t\t}, cookieTokenTimeout);\n\t\t\n\t\tthis.set(wssc, { sessionId: session._id }, { domain: this.domain, maxAge: this.maxAge }, () => {\n\t\t\tclearTimeout(pendingTimeout);\n\t\t\tthis.#cookieWritePending.delete(session._id);\n\t\t\tthis.#cookieSetAtBySessionId.set(session._id, Date.now());\n\t\t});\n\t\t\n\t}\n\t\n\t#isCookieStale(session: { _id: string; createdAt: number }) {\n\t\tconst setAt = this.#cookieSetAtBySessionId.get(session._id) ?? session.createdAt;\n\t\t\n\t\treturn Date.now() - setAt >= this.updateAge * 1000;\n\t}\n\t\n\t\n\tstatic parse = parseCookie;\n\t\n}\n", "export const headers = {\n\tset: \"~setcookie\"\n};\n\nex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["getWithTimeout", "ClassMiddleware", "tokenMap", "assertCookiePart", "value", "CookieMiddleware", "_CookieMiddleware", "ClassMiddleware", "options", "path", "#handler", "request", "response", "pending", "getWithTimeout", "tokenMap", "cookie", "onSet", "name", "maxAge", "expiresAt", "domain", "secure", "httpOnly", "sameSite", "parseCookie", "cookie", "object", "keyEqValue", "separatorIndex", "key", "value", "crypto", "setWithTimeout", "headers", "cookieTokenTimeout", "defaultUpdateAge", "CookieSetter", "usersServer", "domain", "maxAge", "updateAge", "#handleClientConnect", "#handleClientSession", "#handleSessionDelete", "#wsSessionIdMap", "#cookieSetAtBySessionId", "#cookieWritePending", "wssc", "cookie", "options", "onSet", "token", "crypto", "setWithTimeout", "tokenMap", "headers", "names", "name", "request", "sessionId", "parseCookie", "shouldProlong", "#writeSessionCookie", "#isCookieStale", "session", "pendingTimeout", "setAt"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/server/parse.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/server/parse.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,2BAczC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-cookie",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Cookie-based auth for inSite (client + server)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"insite",
|
|
@@ -44,12 +44,13 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@nesvet/n": "^1.2.1",
|
|
47
|
-
"insite-common": "^2.
|
|
48
|
-
"insite-http": "^2.
|
|
49
|
-
"insite-users-server-ws": "^2.
|
|
50
|
-
"insite-ws": "^2.
|
|
47
|
+
"insite-common": "^2.6.0",
|
|
48
|
+
"insite-http": "^2.6.0",
|
|
49
|
+
"insite-users-server-ws": "^2.6.0",
|
|
50
|
+
"insite-ws": "^2.6.0"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
|
-
"
|
|
53
|
+
"bun": ">=1.4.4",
|
|
54
|
+
"node": ">=22.0.0"
|
|
54
55
|
}
|
|
55
56
|
}
|