@orieljs/cookie 0.1.0-alpha.1
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/LICENSE +202 -0
- package/NOTICE +9 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +259 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Oriel
|
|
2
|
+
Copyright 2026 meeeet-dev and Oriel contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Oriel project
|
|
5
|
+
(https://orieljs.vercel.app, https://github.com/orieljs).
|
|
6
|
+
|
|
7
|
+
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
|
+
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
|
+
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Cookie as Cookie$1, CookieJar as CookieJar$1, Middleware, HttpRequest, Next, Encrypter } from '@orieljs/contracts';
|
|
2
|
+
import * as _orieljs_support from '@orieljs/support';
|
|
3
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
4
|
+
|
|
5
|
+
/** A Set-Cookie header value. Negative minutes delete the cookie; 0 is a session cookie. */
|
|
6
|
+
declare function serializeCookie(cookie: Cookie$1, now?: number): string;
|
|
7
|
+
interface ParsedSetCookie {
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
/** Everything after the name=value pair, including the leading '; ' (empty when there are no attributes). */
|
|
11
|
+
attributes: string;
|
|
12
|
+
}
|
|
13
|
+
/** Splits a Set-Cookie header value into its name, decoded value and untouched attributes. */
|
|
14
|
+
declare function parseSetCookie(header: string): ParsedSetCookie;
|
|
15
|
+
/** Parses a Cookie request header (`a=1; b=2`). The first occurrence of a name wins. */
|
|
16
|
+
declare function parseCookieHeader(header: string | undefined): Record<string, string>;
|
|
17
|
+
/** A copy of the response whose headers can be changed (Response.redirect() and fetch() headers are immutable). */
|
|
18
|
+
declare function withHeaders(response: Response, change: (headers: Headers) => void): Response;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Laravel's CookieValuePrefix: encrypted cookie values start with hmac_sha1(name + 'v2', key) + '|', which binds
|
|
22
|
+
* each value to its cookie name so an encrypted value can't be replayed under another cookie.
|
|
23
|
+
*/
|
|
24
|
+
declare const CookieValuePrefix: {
|
|
25
|
+
create(name: string, key: Uint8Array): string;
|
|
26
|
+
remove(value: string): string;
|
|
27
|
+
/** The value without its prefix when the prefix matches one of the keys, else undefined. */
|
|
28
|
+
validate(name: string, value: string, keys: Uint8Array[]): string | undefined;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface CookieDefaults {
|
|
32
|
+
path?: string;
|
|
33
|
+
domain?: string | undefined;
|
|
34
|
+
secure?: boolean;
|
|
35
|
+
sameSite?: Cookie$1['sameSite'];
|
|
36
|
+
}
|
|
37
|
+
type CookieOptions = Partial<Omit<Cookie$1, 'name' | 'value' | 'minutes'>>;
|
|
38
|
+
/** Laravel's CookieJar. One per request scope: queued cookies are attached by AddQueuedCookiesToResponse. */
|
|
39
|
+
declare class CookieJar implements CookieJar$1 {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(defaults?: CookieDefaults);
|
|
42
|
+
make(name: string, value: string, minutes?: number, options?: CookieOptions): Cookie$1;
|
|
43
|
+
/** Five years, like Laravel. */
|
|
44
|
+
forever(name: string, value: string, options?: CookieOptions): Cookie$1;
|
|
45
|
+
/** An expired cookie that makes the browser delete it. */
|
|
46
|
+
forget(name: string, options?: CookieOptions): Cookie$1;
|
|
47
|
+
/** Queue a cookie for the response. A cookie with the same name and path replaces the earlier one. */
|
|
48
|
+
queue(cookie: Cookie$1): void;
|
|
49
|
+
queued(): Cookie$1[];
|
|
50
|
+
hasQueued(name: string, path?: string): boolean;
|
|
51
|
+
queuedCookie(name: string, path?: string): Cookie$1 | undefined;
|
|
52
|
+
unqueue(name: string, path?: string): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Laravel's AddQueuedCookiesToResponse: writes the request's queued cookies as Set-Cookie headers. */
|
|
56
|
+
declare class AddQueuedCookiesToResponse implements Middleware {
|
|
57
|
+
#private;
|
|
58
|
+
handle(request: HttpRequest, next: Next): Promise<Response>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Laravel's EncryptCookies: request cookies are decrypted (and dropped when they don't decrypt), and every
|
|
63
|
+
* Set-Cookie on the outgoing response is encrypted, whoever wrote it (queued on the CookieJar, or written straight
|
|
64
|
+
* onto the response such as RedirectResponse.withCookie()), except the names in `except` and deletions. It runs
|
|
65
|
+
* once, outermost in `web`, so every cookie is encrypted exactly once.
|
|
66
|
+
*/
|
|
67
|
+
declare class EncryptCookies implements Middleware {
|
|
68
|
+
/** Cookie names that are never encrypted (Laravel 11's $middleware->encryptCookies(except: [...])). */
|
|
69
|
+
static except(cookies: string | string[]): void;
|
|
70
|
+
/** Forget the names added with except() (for tests). */
|
|
71
|
+
static flushState(): void;
|
|
72
|
+
/** Subclasses list cookie names that are not encrypted. */
|
|
73
|
+
protected except: string[];
|
|
74
|
+
protected readonly encrypter: Encrypter;
|
|
75
|
+
isDisabled(name: string): boolean;
|
|
76
|
+
handle(request: HttpRequest, next: Next): Promise<Response>;
|
|
77
|
+
protected decrypt(request: HttpRequest): void;
|
|
78
|
+
protected encrypt(response: Response): Response;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The Cookie facade: the request's jar, plus get()/has() reading the (decrypted) request cookies. */
|
|
82
|
+
declare const Cookie: _orieljs_support.Facade<CookieJar$1, {
|
|
83
|
+
get: (name: string, defaultValue?: string) => string | undefined;
|
|
84
|
+
has: (name: string) => boolean;
|
|
85
|
+
}>;
|
|
86
|
+
/** cookie(): the jar; cookie(name, value, minutes?, options?): a new cookie (queue it, or attach it to a redirect). */
|
|
87
|
+
declare function cookie(): CookieJar$1;
|
|
88
|
+
declare function cookie(name: string, value: string, minutes?: number, options?: Partial<Omit<Cookie$1, 'name' | 'value' | 'minutes'>>): Cookie$1;
|
|
89
|
+
|
|
90
|
+
declare class CookieServiceProvider extends ServiceProvider {
|
|
91
|
+
register(): void;
|
|
92
|
+
boot(): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { AddQueuedCookiesToResponse, Cookie, type CookieDefaults, CookieJar, CookieServiceProvider, CookieValuePrefix, EncryptCookies, type ParsedSetCookie, cookie, parseCookieHeader, parseSetCookie, serializeCookie, withHeaders };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// serialize.ts
|
|
2
|
+
var SAME_SITE = { lax: "Lax", strict: "Strict", none: "None" };
|
|
3
|
+
function serializeCookie(cookie2, now = Date.now()) {
|
|
4
|
+
const parts = [];
|
|
5
|
+
if (cookie2.minutes < 0) {
|
|
6
|
+
parts.push(`${cookie2.name}=`, "Expires=Thu, 01 Jan 1970 00:00:00 GMT", "Max-Age=0");
|
|
7
|
+
} else {
|
|
8
|
+
parts.push(`${cookie2.name}=${encodeURIComponent(cookie2.value)}`);
|
|
9
|
+
if (cookie2.minutes > 0) {
|
|
10
|
+
parts.push(`Expires=${new Date(now + cookie2.minutes * 6e4).toUTCString()}`, `Max-Age=${cookie2.minutes * 60}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
parts.push(`Path=${cookie2.path}`);
|
|
14
|
+
if (cookie2.domain !== void 0 && cookie2.domain !== "") parts.push(`Domain=${cookie2.domain}`);
|
|
15
|
+
if (cookie2.secure) parts.push("Secure");
|
|
16
|
+
if (cookie2.httpOnly) parts.push("HttpOnly");
|
|
17
|
+
parts.push(`SameSite=${SAME_SITE[cookie2.sameSite]}`);
|
|
18
|
+
return parts.join("; ");
|
|
19
|
+
}
|
|
20
|
+
var decode = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
return decodeURIComponent(value);
|
|
23
|
+
} catch {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function parseSetCookie(header) {
|
|
28
|
+
const semicolon = header.indexOf(";");
|
|
29
|
+
const pair = semicolon === -1 ? header : header.slice(0, semicolon);
|
|
30
|
+
const equals = pair.indexOf("=");
|
|
31
|
+
return {
|
|
32
|
+
name: (equals === -1 ? pair : pair.slice(0, equals)).trim(),
|
|
33
|
+
value: equals === -1 ? "" : decode(pair.slice(equals + 1).trim()),
|
|
34
|
+
attributes: semicolon === -1 ? "" : header.slice(semicolon)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function parseCookieHeader(header) {
|
|
38
|
+
const cookies = {};
|
|
39
|
+
for (const part of (header ?? "").split(";")) {
|
|
40
|
+
const equals = part.indexOf("=");
|
|
41
|
+
if (equals === -1) continue;
|
|
42
|
+
const name = part.slice(0, equals).trim();
|
|
43
|
+
if (name === "" || Object.hasOwn(cookies, name) || name === "__proto__") continue;
|
|
44
|
+
cookies[name] = decode(part.slice(equals + 1).trim());
|
|
45
|
+
}
|
|
46
|
+
return cookies;
|
|
47
|
+
}
|
|
48
|
+
function withHeaders(response, change) {
|
|
49
|
+
const headers = new Headers(response.headers);
|
|
50
|
+
change(headers);
|
|
51
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// CookieValuePrefix.ts
|
|
55
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
56
|
+
var CookieValuePrefix = {
|
|
57
|
+
create(name, key) {
|
|
58
|
+
return `${createHmac("sha1", key).update(`${name}v2`).digest("hex")}|`;
|
|
59
|
+
},
|
|
60
|
+
remove(value) {
|
|
61
|
+
return value.slice(41);
|
|
62
|
+
},
|
|
63
|
+
/** The value without its prefix when the prefix matches one of the keys, else undefined. */
|
|
64
|
+
validate(name, value, keys) {
|
|
65
|
+
const actual = Buffer.from(value.slice(0, 41));
|
|
66
|
+
for (const key of keys) {
|
|
67
|
+
const expected = Buffer.from(CookieValuePrefix.create(name, key));
|
|
68
|
+
if (actual.length === expected.length && timingSafeEqual(actual, expected)) return CookieValuePrefix.remove(value);
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// CookieJar.ts
|
|
75
|
+
var CookieJar = class {
|
|
76
|
+
#queued = /* @__PURE__ */ new Map();
|
|
77
|
+
#defaults;
|
|
78
|
+
constructor(defaults = {}) {
|
|
79
|
+
this.#defaults = {
|
|
80
|
+
path: defaults.path ?? "/",
|
|
81
|
+
domain: defaults.domain ?? void 0,
|
|
82
|
+
secure: defaults.secure ?? false,
|
|
83
|
+
sameSite: defaults.sameSite ?? "lax"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
make(name, value, minutes = 0, options = {}) {
|
|
87
|
+
const domain = options.domain ?? this.#defaults.domain;
|
|
88
|
+
return {
|
|
89
|
+
name,
|
|
90
|
+
value,
|
|
91
|
+
minutes,
|
|
92
|
+
path: options.path ?? this.#defaults.path,
|
|
93
|
+
...domain === void 0 ? {} : { domain },
|
|
94
|
+
secure: options.secure ?? this.#defaults.secure,
|
|
95
|
+
httpOnly: options.httpOnly ?? true,
|
|
96
|
+
sameSite: options.sameSite ?? this.#defaults.sameSite
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Five years, like Laravel. */
|
|
100
|
+
forever(name, value, options = {}) {
|
|
101
|
+
return this.make(name, value, 576e3, options);
|
|
102
|
+
}
|
|
103
|
+
/** An expired cookie that makes the browser delete it. */
|
|
104
|
+
forget(name, options = {}) {
|
|
105
|
+
return this.make(name, "", -2628e3, options);
|
|
106
|
+
}
|
|
107
|
+
/** Queue a cookie for the response. A cookie with the same name and path replaces the earlier one. */
|
|
108
|
+
queue(cookie2) {
|
|
109
|
+
this.#queued.set(`${cookie2.name}\0${cookie2.path}`, cookie2);
|
|
110
|
+
}
|
|
111
|
+
queued() {
|
|
112
|
+
return [...this.#queued.values()];
|
|
113
|
+
}
|
|
114
|
+
hasQueued(name, path) {
|
|
115
|
+
return this.queuedCookie(name, path) !== void 0;
|
|
116
|
+
}
|
|
117
|
+
queuedCookie(name, path) {
|
|
118
|
+
return this.queued().find((cookie2) => cookie2.name === name && (path === void 0 || cookie2.path === path));
|
|
119
|
+
}
|
|
120
|
+
unqueue(name, path) {
|
|
121
|
+
for (const [key, cookie2] of this.#queued) {
|
|
122
|
+
if (cookie2.name === name && (path === void 0 || cookie2.path === path)) this.#queued.delete(key);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// middleware/AddQueuedCookiesToResponse.ts
|
|
128
|
+
import { CookieJar as CookieJar2 } from "@orieljs/contracts";
|
|
129
|
+
import { inject } from "@orieljs/container";
|
|
130
|
+
var AddQueuedCookiesToResponse = class {
|
|
131
|
+
#jar = inject(CookieJar2);
|
|
132
|
+
async handle(request, next) {
|
|
133
|
+
const response = await next(request);
|
|
134
|
+
const cookies = this.#jar.queued();
|
|
135
|
+
if (cookies.length === 0) return response;
|
|
136
|
+
return withHeaders(response, (headers) => {
|
|
137
|
+
for (const cookie2 of cookies) headers.append("Set-Cookie", serializeCookie(cookie2));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// middleware/EncryptCookies.ts
|
|
143
|
+
import { Encrypter } from "@orieljs/contracts";
|
|
144
|
+
import { inject as inject2 } from "@orieljs/container";
|
|
145
|
+
var neverEncrypt = /* @__PURE__ */ new Set();
|
|
146
|
+
function isDeletion(attributes, now = Date.now()) {
|
|
147
|
+
for (const part of attributes.split(";")) {
|
|
148
|
+
const equals = part.indexOf("=");
|
|
149
|
+
if (equals === -1) continue;
|
|
150
|
+
const key = part.slice(0, equals).trim().toLowerCase();
|
|
151
|
+
const value = part.slice(equals + 1).trim();
|
|
152
|
+
if (key === "max-age" && Number(value) <= 0) return true;
|
|
153
|
+
if (key === "expires" && Date.parse(value) <= now) return true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
var EncryptCookies = class {
|
|
158
|
+
/** Cookie names that are never encrypted (Laravel 11's $middleware->encryptCookies(except: [...])). */
|
|
159
|
+
static except(cookies) {
|
|
160
|
+
for (const name of Array.isArray(cookies) ? cookies : [cookies]) neverEncrypt.add(name);
|
|
161
|
+
}
|
|
162
|
+
/** Forget the names added with except() (for tests). */
|
|
163
|
+
static flushState() {
|
|
164
|
+
neverEncrypt.clear();
|
|
165
|
+
}
|
|
166
|
+
/** Subclasses list cookie names that are not encrypted. */
|
|
167
|
+
except = [];
|
|
168
|
+
encrypter = inject2(Encrypter);
|
|
169
|
+
isDisabled(name) {
|
|
170
|
+
return this.except.includes(name) || neverEncrypt.has(name);
|
|
171
|
+
}
|
|
172
|
+
async handle(request, next) {
|
|
173
|
+
this.decrypt(request);
|
|
174
|
+
return this.encrypt(await next(request));
|
|
175
|
+
}
|
|
176
|
+
decrypt(request) {
|
|
177
|
+
const keys = this.encrypter.getAllKeys?.() ?? [this.encrypter.getKey()];
|
|
178
|
+
const decrypted = {};
|
|
179
|
+
for (const [name, value] of Object.entries(parseCookieHeader(request.header("cookie")))) {
|
|
180
|
+
if (this.isDisabled(name)) {
|
|
181
|
+
decrypted[name] = value;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const plain = CookieValuePrefix.validate(name, this.encrypter.decrypt(value, false), keys);
|
|
186
|
+
if (plain !== void 0) decrypted[name] = plain;
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
request.setCookies(decrypted);
|
|
191
|
+
}
|
|
192
|
+
encrypt(response) {
|
|
193
|
+
const cookies = response.headers.getSetCookie();
|
|
194
|
+
if (cookies.length === 0) return response;
|
|
195
|
+
return withHeaders(response, (headers) => {
|
|
196
|
+
headers.delete("Set-Cookie");
|
|
197
|
+
for (const header of cookies) {
|
|
198
|
+
const { name, value, attributes } = parseSetCookie(header);
|
|
199
|
+
if (this.isDisabled(name) || isDeletion(attributes)) {
|
|
200
|
+
headers.append("Set-Cookie", header);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const encrypted = this.encrypter.encrypt(CookieValuePrefix.create(name, this.encrypter.getKey()) + value, false);
|
|
204
|
+
headers.append("Set-Cookie", `${name}=${encodeURIComponent(encrypted)}${attributes}`);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// facade.ts
|
|
211
|
+
import { CookieJar as CookieJar3, HttpRequest } from "@orieljs/contracts";
|
|
212
|
+
import { inject as inject3 } from "@orieljs/container";
|
|
213
|
+
import { facade } from "@orieljs/support";
|
|
214
|
+
var Cookie = facade(CookieJar3, {
|
|
215
|
+
get: (name, defaultValue) => inject3(HttpRequest).cookie(name) ?? defaultValue,
|
|
216
|
+
has: (name) => inject3(HttpRequest).cookie(name) !== void 0
|
|
217
|
+
});
|
|
218
|
+
function cookie(name, value, minutes, options) {
|
|
219
|
+
const jar = inject3(CookieJar3);
|
|
220
|
+
return name === void 0 ? jar : jar.make(name, value ?? "", minutes, options);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// CookieServiceProvider.ts
|
|
224
|
+
import { ConfigRepository, CookieJar as CookieJarToken, HttpRequest as HttpRequest2, Router } from "@orieljs/contracts";
|
|
225
|
+
import { ServiceProvider } from "@orieljs/support";
|
|
226
|
+
var CookieServiceProvider = class extends ServiceProvider {
|
|
227
|
+
register() {
|
|
228
|
+
this.app.scoped(CookieJarToken, (container) => {
|
|
229
|
+
const config = container.make(ConfigRepository);
|
|
230
|
+
const domain = config.get("session.domain");
|
|
231
|
+
const secureConfig = config.get("session.secure", null);
|
|
232
|
+
const secure = secureConfig ?? (container.bound(HttpRequest2) && container.make(HttpRequest2).url().startsWith("https:"));
|
|
233
|
+
return new CookieJar({
|
|
234
|
+
path: config.get("session.path", "/"),
|
|
235
|
+
domain: domain ?? void 0,
|
|
236
|
+
secure,
|
|
237
|
+
sameSite: config.get("session.same_site", "lax") ?? "lax"
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
boot() {
|
|
242
|
+
if (!this.app.bound(Router)) return;
|
|
243
|
+
this.app.make(Router).pushMiddlewareToGroup("web", EncryptCookies).pushMiddlewareToGroup("web", AddQueuedCookiesToResponse);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
export {
|
|
247
|
+
AddQueuedCookiesToResponse,
|
|
248
|
+
Cookie,
|
|
249
|
+
CookieJar,
|
|
250
|
+
CookieServiceProvider,
|
|
251
|
+
CookieValuePrefix,
|
|
252
|
+
EncryptCookies,
|
|
253
|
+
cookie,
|
|
254
|
+
parseCookieHeader,
|
|
255
|
+
parseSetCookie,
|
|
256
|
+
serializeCookie,
|
|
257
|
+
withHeaders
|
|
258
|
+
};
|
|
259
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../serialize.ts","../CookieValuePrefix.ts","../CookieJar.ts","../middleware/AddQueuedCookiesToResponse.ts","../middleware/EncryptCookies.ts","../facade.ts","../CookieServiceProvider.ts"],"sourcesContent":["import type { Cookie } from '@orieljs/contracts'\n\nconst SAME_SITE = { lax: 'Lax', strict: 'Strict', none: 'None' } as const\n\n/** A Set-Cookie header value. Negative minutes delete the cookie; 0 is a session cookie. */\nexport function serializeCookie(cookie: Cookie, now: number = Date.now()): string {\n const parts: string[] = []\n if (cookie.minutes < 0) {\n parts.push(`${cookie.name}=`, 'Expires=Thu, 01 Jan 1970 00:00:00 GMT', 'Max-Age=0')\n } else {\n parts.push(`${cookie.name}=${encodeURIComponent(cookie.value)}`)\n if (cookie.minutes > 0) {\n parts.push(`Expires=${new Date(now + cookie.minutes * 60_000).toUTCString()}`, `Max-Age=${cookie.minutes * 60}`)\n }\n }\n parts.push(`Path=${cookie.path}`)\n if (cookie.domain !== undefined && cookie.domain !== '') parts.push(`Domain=${cookie.domain}`)\n if (cookie.secure) parts.push('Secure')\n if (cookie.httpOnly) parts.push('HttpOnly')\n parts.push(`SameSite=${SAME_SITE[cookie.sameSite]}`)\n return parts.join('; ')\n}\n\nexport interface ParsedSetCookie {\n name: string\n value: string\n /** Everything after the name=value pair, including the leading '; ' (empty when there are no attributes). */\n attributes: string\n}\n\nconst decode = (value: string): string => {\n try {\n return decodeURIComponent(value)\n } catch {\n return value\n }\n}\n\n/** Splits a Set-Cookie header value into its name, decoded value and untouched attributes. */\nexport function parseSetCookie(header: string): ParsedSetCookie {\n const semicolon = header.indexOf(';')\n const pair = semicolon === -1 ? header : header.slice(0, semicolon)\n const equals = pair.indexOf('=')\n return {\n name: (equals === -1 ? pair : pair.slice(0, equals)).trim(),\n value: equals === -1 ? '' : decode(pair.slice(equals + 1).trim()),\n attributes: semicolon === -1 ? '' : header.slice(semicolon),\n }\n}\n\n/** Parses a Cookie request header (`a=1; b=2`). The first occurrence of a name wins. */\nexport function parseCookieHeader(header: string | undefined): Record<string, string> {\n const cookies: Record<string, string> = {}\n for (const part of (header ?? '').split(';')) {\n const equals = part.indexOf('=')\n if (equals === -1) continue\n const name = part.slice(0, equals).trim()\n if (name === '' || Object.hasOwn(cookies, name) || name === '__proto__') continue\n cookies[name] = decode(part.slice(equals + 1).trim())\n }\n return cookies\n}\n\n/** A copy of the response whose headers can be changed (Response.redirect() and fetch() headers are immutable). */\nexport function withHeaders(response: Response, change: (headers: Headers) => void): Response {\n const headers = new Headers(response.headers)\n change(headers)\n return new Response(response.body, { status: response.status, statusText: response.statusText, headers })\n}\n","import { createHmac, timingSafeEqual } from 'node:crypto'\n\n/**\n * Laravel's CookieValuePrefix: encrypted cookie values start with hmac_sha1(name + 'v2', key) + '|', which binds\n * each value to its cookie name so an encrypted value can't be replayed under another cookie.\n */\nexport const CookieValuePrefix = {\n create(name: string, key: Uint8Array): string {\n return `${createHmac('sha1', key).update(`${name}v2`).digest('hex')}|`\n },\n\n remove(value: string): string {\n return value.slice(41)\n },\n\n /** The value without its prefix when the prefix matches one of the keys, else undefined. */\n validate(name: string, value: string, keys: Uint8Array[]): string | undefined {\n const actual = Buffer.from(value.slice(0, 41))\n for (const key of keys) {\n const expected = Buffer.from(CookieValuePrefix.create(name, key))\n if (actual.length === expected.length && timingSafeEqual(actual, expected)) return CookieValuePrefix.remove(value)\n }\n return undefined\n },\n}\n","import type { Cookie, CookieJar as CookieJarContract } from '@orieljs/contracts'\n\nexport interface CookieDefaults {\n path?: string\n domain?: string | undefined\n secure?: boolean\n sameSite?: Cookie['sameSite']\n}\n\ntype CookieOptions = Partial<Omit<Cookie, 'name' | 'value' | 'minutes'>>\n\n/** Laravel's CookieJar. One per request scope: queued cookies are attached by AddQueuedCookiesToResponse. */\nexport class CookieJar implements CookieJarContract {\n readonly #queued = new Map<string, Cookie>()\n readonly #defaults: Required<Omit<CookieDefaults, 'domain'>> & { domain: string | undefined }\n\n constructor(defaults: CookieDefaults = {}) {\n this.#defaults = {\n path: defaults.path ?? '/',\n domain: defaults.domain ?? undefined,\n secure: defaults.secure ?? false,\n sameSite: defaults.sameSite ?? 'lax',\n }\n }\n\n make(name: string, value: string, minutes = 0, options: CookieOptions = {}): Cookie {\n const domain = options.domain ?? this.#defaults.domain\n return {\n name,\n value,\n minutes,\n path: options.path ?? this.#defaults.path,\n ...(domain === undefined ? {} : { domain }),\n secure: options.secure ?? this.#defaults.secure,\n httpOnly: options.httpOnly ?? true,\n sameSite: options.sameSite ?? this.#defaults.sameSite,\n }\n }\n\n /** Five years, like Laravel. */\n forever(name: string, value: string, options: CookieOptions = {}): Cookie {\n return this.make(name, value, 576000, options)\n }\n\n /** An expired cookie that makes the browser delete it. */\n forget(name: string, options: CookieOptions = {}): Cookie {\n return this.make(name, '', -2628000, options)\n }\n\n /** Queue a cookie for the response. A cookie with the same name and path replaces the earlier one. */\n queue(cookie: Cookie): void {\n this.#queued.set(`${cookie.name}\\0${cookie.path}`, cookie)\n }\n\n queued(): Cookie[] {\n return [...this.#queued.values()]\n }\n\n hasQueued(name: string, path?: string): boolean {\n return this.queuedCookie(name, path) !== undefined\n }\n\n queuedCookie(name: string, path?: string): Cookie | undefined {\n return this.queued().find((cookie) => cookie.name === name && (path === undefined || cookie.path === path))\n }\n\n unqueue(name: string, path?: string): void {\n for (const [key, cookie] of this.#queued) {\n if (cookie.name === name && (path === undefined || cookie.path === path)) this.#queued.delete(key)\n }\n }\n}\n","import { CookieJar, type HttpRequest, type Middleware, type Next } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { serializeCookie, withHeaders } from '../serialize'\n\n/** Laravel's AddQueuedCookiesToResponse: writes the request's queued cookies as Set-Cookie headers. */\nexport class AddQueuedCookiesToResponse implements Middleware {\n readonly #jar = inject(CookieJar)\n\n async handle(request: HttpRequest, next: Next): Promise<Response> {\n const response = await next(request)\n const cookies = this.#jar.queued()\n if (cookies.length === 0) return response\n return withHeaders(response, (headers) => {\n for (const cookie of cookies) headers.append('Set-Cookie', serializeCookie(cookie))\n })\n }\n}\n","import { Encrypter, type HttpRequest, type Middleware, type Next } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { CookieValuePrefix } from '../CookieValuePrefix'\nimport { parseCookieHeader, parseSetCookie, withHeaders } from '../serialize'\n\nconst neverEncrypt = new Set<string>()\n\n/** Whether a Set-Cookie deletes the cookie (Max-Age <= 0, or Expires in the past): its value is left alone. */\nfunction isDeletion(attributes: string, now = Date.now()): boolean {\n for (const part of attributes.split(';')) {\n const equals = part.indexOf('=')\n if (equals === -1) continue\n const key = part.slice(0, equals).trim().toLowerCase()\n const value = part.slice(equals + 1).trim()\n if (key === 'max-age' && Number(value) <= 0) return true\n if (key === 'expires' && Date.parse(value) <= now) return true\n }\n return false\n}\n\n/**\n * Laravel's EncryptCookies: request cookies are decrypted (and dropped when they don't decrypt), and every\n * Set-Cookie on the outgoing response is encrypted, whoever wrote it (queued on the CookieJar, or written straight\n * onto the response such as RedirectResponse.withCookie()), except the names in `except` and deletions. It runs\n * once, outermost in `web`, so every cookie is encrypted exactly once.\n */\nexport class EncryptCookies implements Middleware {\n /** Cookie names that are never encrypted (Laravel 11's $middleware->encryptCookies(except: [...])). */\n static except(cookies: string | string[]): void {\n for (const name of Array.isArray(cookies) ? cookies : [cookies]) neverEncrypt.add(name)\n }\n\n /** Forget the names added with except() (for tests). */\n static flushState(): void {\n neverEncrypt.clear()\n }\n\n /** Subclasses list cookie names that are not encrypted. */\n protected except: string[] = []\n\n protected readonly encrypter = inject(Encrypter)\n\n isDisabled(name: string): boolean {\n return this.except.includes(name) || neverEncrypt.has(name)\n }\n\n async handle(request: HttpRequest, next: Next): Promise<Response> {\n this.decrypt(request)\n return this.encrypt(await next(request))\n }\n\n protected decrypt(request: HttpRequest): void {\n const keys = (this.encrypter as { getAllKeys?(): Uint8Array[] }).getAllKeys?.() ?? [this.encrypter.getKey()]\n const decrypted: Record<string, string> = {}\n for (const [name, value] of Object.entries(parseCookieHeader(request.header('cookie')))) {\n if (this.isDisabled(name)) {\n decrypted[name] = value\n continue\n }\n try {\n const plain = CookieValuePrefix.validate(name, this.encrypter.decrypt<string>(value, false), keys)\n if (plain !== undefined) decrypted[name] = plain\n } catch {\n // A cookie that doesn't decrypt reads as absent (Laravel sets it to null).\n }\n }\n request.setCookies(decrypted)\n }\n\n protected encrypt(response: Response): Response {\n const cookies = response.headers.getSetCookie()\n if (cookies.length === 0) return response\n return withHeaders(response, (headers) => {\n headers.delete('Set-Cookie')\n for (const header of cookies) {\n const { name, value, attributes } = parseSetCookie(header)\n if (this.isDisabled(name) || isDeletion(attributes)) {\n headers.append('Set-Cookie', header)\n continue\n }\n const encrypted = this.encrypter.encrypt(CookieValuePrefix.create(name, this.encrypter.getKey()) + value, false)\n headers.append('Set-Cookie', `${name}=${encodeURIComponent(encrypted)}${attributes}`)\n }\n })\n }\n}\n","import { CookieJar, HttpRequest, type Cookie as CookieShape } from '@orieljs/contracts'\nimport { inject } from '@orieljs/container'\nimport { facade } from '@orieljs/support'\n\n/** The Cookie facade: the request's jar, plus get()/has() reading the (decrypted) request cookies. */\nexport const Cookie = facade(CookieJar, {\n get: (name: string, defaultValue?: string): string | undefined => inject(HttpRequest).cookie(name) ?? defaultValue,\n has: (name: string): boolean => inject(HttpRequest).cookie(name) !== undefined,\n})\n\n/** cookie(): the jar; cookie(name, value, minutes?, options?): a new cookie (queue it, or attach it to a redirect). */\nexport function cookie(): CookieJar\nexport function cookie(name: string, value: string, minutes?: number, options?: Partial<Omit<CookieShape, 'name' | 'value' | 'minutes'>>): CookieShape\nexport function cookie(\n name?: string,\n value?: string,\n minutes?: number,\n options?: Partial<Omit<CookieShape, 'name' | 'value' | 'minutes'>>,\n): CookieJar | CookieShape {\n const jar = inject(CookieJar)\n return name === undefined ? jar : jar.make(name, value ?? '', minutes, options)\n}\n","import { ConfigRepository, CookieJar as CookieJarToken, HttpRequest, Router, type Cookie } from '@orieljs/contracts'\nimport { ServiceProvider } from '@orieljs/support'\nimport { CookieJar } from './CookieJar'\nimport { AddQueuedCookiesToResponse } from './middleware/AddQueuedCookiesToResponse'\nimport { EncryptCookies } from './middleware/EncryptCookies'\n\nexport class CookieServiceProvider extends ServiceProvider {\n override register(): void {\n // Laravel's CookieServiceProvider takes the jar's defaults from config/session.php.\n this.app.scoped(CookieJarToken, (container) => {\n const config = container.make(ConfigRepository)\n const domain = config.get<string | null | undefined>('session.domain')\n // secure defaults to null (ruling F6); an explicit true/false wins, otherwise it follows the request's scheme\n // (Symfony's setSecureDefault), so cookies built from these defaults (e.g. the remember cookie) are Secure on HTTPS.\n const secureConfig = config.get<boolean | null | undefined>('session.secure', null)\n const secure = secureConfig ?? (container.bound(HttpRequest) && container.make(HttpRequest).url().startsWith('https:'))\n return new CookieJar({\n path: config.get('session.path', '/'),\n domain: domain ?? undefined,\n secure,\n sameSite: config.get<Cookie['sameSite'] | null>('session.same_site', 'lax') ?? 'lax',\n })\n })\n }\n\n override boot(): void {\n if (!this.app.bound(Router)) return\n this.app.make(Router).pushMiddlewareToGroup('web', EncryptCookies).pushMiddlewareToGroup('web', AddQueuedCookiesToResponse)\n }\n}\n"],"mappings":";AAEA,IAAM,YAAY,EAAE,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO;AAGxD,SAAS,gBAAgBA,SAAgB,MAAc,KAAK,IAAI,GAAW;AAChF,QAAM,QAAkB,CAAC;AACzB,MAAIA,QAAO,UAAU,GAAG;AACtB,UAAM,KAAK,GAAGA,QAAO,IAAI,KAAK,yCAAyC,WAAW;AAAA,EACpF,OAAO;AACL,UAAM,KAAK,GAAGA,QAAO,IAAI,IAAI,mBAAmBA,QAAO,KAAK,CAAC,EAAE;AAC/D,QAAIA,QAAO,UAAU,GAAG;AACtB,YAAM,KAAK,WAAW,IAAI,KAAK,MAAMA,QAAO,UAAU,GAAM,EAAE,YAAY,CAAC,IAAI,WAAWA,QAAO,UAAU,EAAE,EAAE;AAAA,IACjH;AAAA,EACF;AACA,QAAM,KAAK,QAAQA,QAAO,IAAI,EAAE;AAChC,MAAIA,QAAO,WAAW,UAAaA,QAAO,WAAW,GAAI,OAAM,KAAK,UAAUA,QAAO,MAAM,EAAE;AAC7F,MAAIA,QAAO,OAAQ,OAAM,KAAK,QAAQ;AACtC,MAAIA,QAAO,SAAU,OAAM,KAAK,UAAU;AAC1C,QAAM,KAAK,YAAY,UAAUA,Q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,MAAM,SAAS,IAAI,SAAS,OAAO;AAChF;;;ACrBA,SAAS,kBAAkB,aAAa,gBAAgB,eAAAE,cAAa,cAA2B;AAChG,SAAS,uBAAuB;AAKzB,IAAM,wBAAN,cAAoC,gBAAgB;AAAA,EAChD,WAAiB;AAExB,SAAK,IAAI,OAAO,gBAAgB,CAAC,cAAc;AAC7C,YAAM,SAAS,UAAU,KAAK,gBAAgB;AAC9C,YAAM,SAAS,OAAO,IAA+B,gBAAgB;AAGrE,YAAM,eAAe,OAAO,IAAgC,kBAAkB,IAAI;AAClF,YAAM,SAAS,iBAAiB,UAAU,MAAMC,YAAW,KAAK,UAAU,KAAKA,YAAW,EAAE,IAAI,EAAE,WAAW,QAAQ;AACrH,aAAO,IAAI,UAAU;AAAA,QACnB,MAAM,OAAO,IAAI,gBAAgB,GAAG;AAAA,QACpC,QAAQ,UAAU;AAAA,QAClB;AAAA,QACA,UAAU,OAAO,IAA+B,qBAAqB,KAAK,KAAK;AAAA,MACjF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAES,OAAa;AACpB,QAAI,CAAC,KAAK,IAAI,MAAM,MAAM,EAAG;AAC7B,SAAK,IAAI,KAAK,MAAM,EAAE,sBAAsB,OAAO,cAAc,EAAE,sBAAsB,OAAO,0BAA0B;AAAA,EAC5H;AACF;","names":["cookie","cookie","CookieJar","CookieJar","cookie","inject","inject","CookieJar","inject","HttpRequest","HttpRequest"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orieljs/cookie",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "The Oriel Cookie component.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/orieljs/framework.git",
|
|
11
|
+
"directory": "src/Oriel/Cookie"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"NOTICE"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@orieljs/contracts": "0.1.0-alpha.1",
|
|
33
|
+
"@orieljs/container": "0.1.0-alpha.1",
|
|
34
|
+
"@orieljs/support": "0.1.0-alpha.1"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup && node ../../../scripts/copy-license.mjs"
|
|
38
|
+
}
|
|
39
|
+
}
|