@aura-stack/auth 0.1.0-rc.9 → 0.2.0-rc.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.
Files changed (153) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +7 -31
  3. package/dist/@types/index.js +1 -1
  4. package/dist/@types/router.d.cjs +1 -1
  5. package/dist/@types/router.d.d.ts +7 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +4 -8
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +176 -155
  10. package/dist/actions/callback/access-token.d.ts +15 -20
  11. package/dist/actions/callback/access-token.js +10 -4
  12. package/dist/actions/callback/callback.cjs +394 -490
  13. package/dist/actions/callback/callback.d.ts +10 -12
  14. package/dist/actions/callback/callback.js +16 -12
  15. package/dist/actions/callback/userinfo.cjs +166 -145
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +12 -6
  18. package/dist/actions/csrfToken/csrfToken.cjs +112 -190
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +12 -8
  21. package/dist/actions/index.cjs +652 -814
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +34 -18
  24. package/dist/actions/session/session.cjs +86 -176
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +10 -7
  27. package/dist/actions/signIn/authorization.cjs +254 -263
  28. package/dist/actions/signIn/authorization.d.ts +12 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +320 -456
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +13 -10
  33. package/dist/actions/signOut/signOut.cjs +304 -473
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +14 -11
  36. package/dist/assert.cjs +40 -36
  37. package/dist/assert.d.ts +13 -4
  38. package/dist/assert.js +12 -2
  39. package/dist/chunk-3EUWD5BB.js +63 -0
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-6R2YZ4AC.js +22 -0
  42. package/dist/chunk-A3N4PVAT.js +70 -0
  43. package/dist/chunk-B737EUJV.js +22 -0
  44. package/dist/chunk-CXLATHS5.js +143 -0
  45. package/dist/chunk-E3OXBRYF.js +19 -17
  46. package/dist/chunk-EIL2FPSS.js +22 -0
  47. package/dist/chunk-EMKJA2GJ.js +89 -0
  48. package/dist/chunk-FIPU4MLT.js +18 -16
  49. package/dist/chunk-FKRDCWBF.js +19 -17
  50. package/dist/chunk-GA2SMTJO.js +58 -0
  51. package/dist/chunk-HP34YGGJ.js +22 -0
  52. package/dist/chunk-HT4YLL7N.js +35 -0
  53. package/dist/chunk-IKHPGFCW.js +11 -9
  54. package/dist/chunk-IUYZQTJV.js +30 -0
  55. package/dist/chunk-IVET23KF.js +58 -0
  56. package/dist/chunk-JVFTCTTE.js +33 -0
  57. package/dist/chunk-KRNOMBXQ.js +19 -17
  58. package/dist/chunk-KSWLO5ZU.js +102 -0
  59. package/dist/chunk-N2APGLXA.js +71 -0
  60. package/dist/chunk-N4SX7TZT.js +96 -0
  61. package/dist/chunk-RRLIF4PQ.js +55 -0
  62. package/dist/chunk-STHEPPUZ.js +8 -6
  63. package/dist/chunk-TLE4PXY3.js +39 -0
  64. package/dist/chunk-W6LG7BFW.js +197 -0
  65. package/dist/chunk-YRCB5FLE.js +79 -0
  66. package/dist/chunk-ZNCZVF6U.js +14 -0
  67. package/dist/cookie.cjs +222 -187
  68. package/dist/cookie.d.ts +39 -76
  69. package/dist/cookie.js +27 -34
  70. package/dist/errors.cjs +85 -0
  71. package/dist/errors.d.ts +49 -0
  72. package/dist/errors.js +18 -0
  73. package/dist/headers.cjs +28 -28
  74. package/dist/headers.d.ts +2 -2
  75. package/dist/headers.js +6 -2
  76. package/dist/index-DkaLJFn8.d.ts +679 -0
  77. package/dist/index.cjs +1074 -1007
  78. package/dist/index.d.ts +10 -31
  79. package/dist/index.js +85 -51
  80. package/dist/jose.cjs +74 -66
  81. package/dist/jose.d.ts +11 -8
  82. package/dist/jose.js +10 -5
  83. package/dist/oauth/bitbucket.cjs +38 -38
  84. package/dist/oauth/bitbucket.d.ts +7 -7
  85. package/dist/oauth/bitbucket.js +6 -2
  86. package/dist/oauth/discord.cjs +47 -48
  87. package/dist/oauth/discord.d.ts +7 -7
  88. package/dist/oauth/discord.js +6 -2
  89. package/dist/oauth/figma.cjs +39 -39
  90. package/dist/oauth/figma.d.ts +7 -7
  91. package/dist/oauth/figma.js +6 -2
  92. package/dist/oauth/github.cjs +31 -31
  93. package/dist/oauth/github.d.ts +7 -7
  94. package/dist/oauth/github.js +6 -2
  95. package/dist/oauth/gitlab.cjs +39 -39
  96. package/dist/oauth/gitlab.d.ts +7 -7
  97. package/dist/oauth/gitlab.js +6 -2
  98. package/dist/oauth/index.cjs +350 -180
  99. package/dist/oauth/index.d.ts +7 -26
  100. package/dist/oauth/index.js +51 -9
  101. package/dist/oauth/mailchimp.cjs +46 -0
  102. package/dist/oauth/mailchimp.d.ts +7 -0
  103. package/dist/oauth/mailchimp.js +6 -0
  104. package/dist/oauth/pinterest.cjs +46 -0
  105. package/dist/oauth/pinterest.d.ts +7 -0
  106. package/dist/oauth/pinterest.js +6 -0
  107. package/dist/oauth/spotify.cjs +39 -39
  108. package/dist/oauth/spotify.d.ts +7 -7
  109. package/dist/oauth/spotify.js +6 -2
  110. package/dist/oauth/strava.cjs +46 -0
  111. package/dist/oauth/strava.d.ts +7 -0
  112. package/dist/oauth/strava.js +6 -0
  113. package/dist/oauth/x.cjs +39 -39
  114. package/dist/oauth/x.d.ts +7 -7
  115. package/dist/oauth/x.js +6 -2
  116. package/dist/request.cjs +38 -0
  117. package/dist/request.d.ts +13 -0
  118. package/dist/request.js +6 -0
  119. package/dist/schemas.cjs +103 -97
  120. package/dist/schemas.d.ts +96 -126
  121. package/dist/schemas.js +20 -18
  122. package/dist/secure.cjs +106 -101
  123. package/dist/secure.d.ts +17 -17
  124. package/dist/secure.js +19 -4
  125. package/dist/utils.cjs +197 -135
  126. package/dist/utils.d.ts +20 -26
  127. package/dist/utils.js +25 -21
  128. package/package.json +8 -7
  129. package/dist/chunk-256KIVJL.js +0 -110
  130. package/dist/chunk-6SM22VVJ.js +0 -15
  131. package/dist/chunk-CAKJT3KS.js +0 -77
  132. package/dist/chunk-EBPE35JT.js +0 -29
  133. package/dist/chunk-FJUDBLCP.js +0 -52
  134. package/dist/chunk-GZU3RBTB.js +0 -51
  135. package/dist/chunk-HGJ4TXY4.js +0 -105
  136. package/dist/chunk-HMRKN75I.js +0 -74
  137. package/dist/chunk-JAPMIE6S.js +0 -8
  138. package/dist/chunk-LLR722CL.js +0 -75
  139. package/dist/chunk-RLT4RFKV.js +0 -36
  140. package/dist/chunk-SJPDVKUS.js +0 -93
  141. package/dist/chunk-SMQO5WD7.js +0 -20
  142. package/dist/chunk-UJJ7R56J.js +0 -42
  143. package/dist/chunk-UTDLUEEG.js +0 -25
  144. package/dist/chunk-VFTYH33W.js +0 -44
  145. package/dist/chunk-XXJKNKGQ.js +0 -27
  146. package/dist/chunk-ZV4BH47P.js +0 -156
  147. package/dist/error.cjs +0 -88
  148. package/dist/error.d.ts +0 -62
  149. package/dist/error.js +0 -9
  150. package/dist/index-DpfbvTZ_.d.ts +0 -597
  151. package/dist/response.cjs +0 -34
  152. package/dist/response.d.ts +0 -10
  153. package/dist/response.js +0 -2
package/dist/cookie.cjs CHANGED
@@ -1,207 +1,242 @@
1
- "use strict"
2
- var __defProp = Object.defineProperty
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor
4
- var __getOwnPropNames = Object.getOwnPropertyNames
5
- var __hasOwnProp = Object.prototype.hasOwnProperty
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
- for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
8
- }
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
9
10
  var __copyProps = (to, from, except, desc) => {
10
- if ((from && typeof from === "object") || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable })
14
- }
15
- return to
16
- }
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod)
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
20
  // src/cookie.ts
20
- var cookie_exports = {}
21
+ var cookie_exports = {};
21
22
  __export(cookie_exports, {
22
- COOKIE_NAME: () => COOKIE_NAME,
23
- createSessionCookie: () => createSessionCookie,
24
- defaultCookieConfig: () => defaultCookieConfig,
25
- defaultCookieOptions: () => defaultCookieOptions,
26
- defaultHostCookieConfig: () => defaultHostCookieConfig,
27
- defaultSecureCookieConfig: () => defaultSecureCookieConfig,
28
- defaultStandardCookieConfig: () => defaultStandardCookieConfig,
29
- defineDefaultCookieOptions: () => defineDefaultCookieOptions,
30
- expireCookie: () => expireCookie,
31
- expiredCookieOptions: () => expiredCookieOptions,
32
- getCookie: () => getCookie,
33
- oauthCookie: () => oauthCookie,
34
- parse: () => import_cookie2.parse,
35
- secureCookieOptions: () => secureCookieOptions,
36
- setCookie: () => setCookie,
37
- })
38
- module.exports = __toCommonJS(cookie_exports)
39
- var import_cookie = require("cookie")
40
-
41
- // src/error.ts
42
- var AuthError = class extends Error {
43
- constructor(type, message) {
44
- super(message)
45
- this.type = type
46
- this.name = "AuthError"
47
- }
48
- }
23
+ COOKIE_NAME: () => COOKIE_NAME,
24
+ createCookieStore: () => createCookieStore,
25
+ createSessionCookie: () => createSessionCookie,
26
+ defaultCookieOptions: () => defaultCookieOptions,
27
+ defaultHostCookieConfig: () => defaultHostCookieConfig,
28
+ defaultSecureCookieConfig: () => defaultSecureCookieConfig,
29
+ defaultStandardCookieConfig: () => defaultStandardCookieConfig,
30
+ defineSecureCookieOptions: () => defineSecureCookieOptions,
31
+ expiredCookieAttributes: () => expiredCookieAttributes,
32
+ getCookie: () => getCookie,
33
+ getSetCookie: () => getSetCookie,
34
+ setCookie: () => setCookie
35
+ });
36
+ module.exports = __toCommonJS(cookie_exports);
37
+ var import_cookie = require("@aura-stack/router/cookie");
49
38
 
50
- // src/assert.ts
51
- var isRequest = (value) => {
52
- return typeof Request !== "undefined" && value instanceof Request
53
- }
39
+ // src/errors.ts
40
+ var AuthInternalError = class extends Error {
41
+ type = "AUTH_INTERNAL_ERROR";
42
+ code;
43
+ constructor(code, message, options) {
44
+ super(message, options);
45
+ this.code = code;
46
+ this.name = new.target.name;
47
+ Error.captureStackTrace(this, new.target);
48
+ }
49
+ };
54
50
 
55
51
  // src/cookie.ts
56
- var import_cookie2 = require("cookie")
57
- var COOKIE_NAME = "aura-auth"
52
+ var COOKIE_NAME = "aura-auth";
58
53
  var defaultCookieOptions = {
59
- httpOnly: true,
60
- sameSite: "lax",
61
- path: "/",
62
- maxAge: 60 * 60 * 24 * 15,
63
- }
64
- var defaultCookieConfig = {
65
- strategy: "standard",
66
- name: COOKIE_NAME,
67
- options: defaultCookieOptions,
68
- }
54
+ httpOnly: true,
55
+ sameSite: "lax",
56
+ path: "/",
57
+ maxAge: 60 * 60 * 24 * 15
58
+ };
69
59
  var defaultStandardCookieConfig = {
70
- secure: false,
71
- httpOnly: true,
72
- prefix: "",
73
- }
60
+ secure: false,
61
+ httpOnly: true
62
+ };
74
63
  var defaultSecureCookieConfig = {
75
- secure: true,
76
- prefix: "__Secure-",
77
- }
64
+ secure: true,
65
+ httpOnly: true
66
+ };
78
67
  var defaultHostCookieConfig = {
79
- secure: true,
80
- prefix: "__Host-",
81
- path: "/",
82
- domain: void 0,
83
- }
84
- var expiredCookieOptions = {
85
- ...defaultCookieOptions,
86
- expires: /* @__PURE__ */ new Date(0),
87
- maxAge: 0,
88
- }
89
- var defineDefaultCookieOptions = (options) => {
90
- return {
91
- name: options?.name ?? COOKIE_NAME,
92
- prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
93
- ...defaultCookieOptions,
94
- ...options,
95
- }
96
- }
68
+ secure: true,
69
+ httpOnly: true,
70
+ path: "/",
71
+ domain: void 0
72
+ };
73
+ var oauthCookieOptions = {
74
+ httpOnly: true,
75
+ maxAge: 5 * 60,
76
+ sameSite: "lax",
77
+ expires: new Date(Date.now() + 5 * 60 * 1e3)
78
+ };
97
79
  var setCookie = (cookieName, value, options) => {
98
- const { prefix, name } = defineDefaultCookieOptions(options)
99
- const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`
100
- return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
101
- ...defaultCookieOptions,
102
- ...options,
103
- })
104
- }
105
- var getCookie = (petition, cookie, options, optional = false) => {
106
- const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ")
107
- if (!cookies) {
108
- if (optional) {
109
- return ""
110
- }
111
- throw new AuthError("invalid_request", "No cookies found. There is no active session")
112
- }
113
- const { name, prefix } = defineDefaultCookieOptions(options)
114
- const parsedCookies = (0, import_cookie.parse)(cookies)
115
- const value = parsedCookies[`${prefix}${name}.${cookie}`]
116
- if (value === void 0) {
117
- if (optional) {
118
- return ""
119
- }
120
- throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`)
80
+ return (0, import_cookie.serialize)(cookieName, value, options);
81
+ };
82
+ var expiredCookieAttributes = {
83
+ ...defaultCookieOptions,
84
+ expires: /* @__PURE__ */ new Date(0),
85
+ maxAge: 0
86
+ };
87
+ var getCookie = (request, cookieName) => {
88
+ const cookies = request.headers.get("Cookie");
89
+ if (!cookies) {
90
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
91
+ }
92
+ const value = (0, import_cookie.parse)(cookies)[cookieName];
93
+ if (!value) {
94
+ throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
95
+ }
96
+ return value;
97
+ };
98
+ var getSetCookie = (response, cookieName) => {
99
+ const cookies = response.headers.getSetCookie();
100
+ if (!cookies) {
101
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found in response.");
102
+ }
103
+ const strCookie = cookies.find((cookie) => cookie.startsWith(`${cookieName}=`));
104
+ if (!strCookie) {
105
+ throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found in response.`);
106
+ }
107
+ return (0, import_cookie.parseSetCookie)(strCookie).value;
108
+ };
109
+ var createSessionCookie = async (jose, session) => {
110
+ try {
111
+ const encoded = await jose.encodeJWT(session);
112
+ return encoded;
113
+ } catch (error) {
114
+ throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
115
+ }
116
+ };
117
+ var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
118
+ if (!attributes.httpOnly) {
119
+ console.warn(
120
+ "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
121
+ );
122
+ }
123
+ if (attributes.domain === "*") {
124
+ attributes.domain = void 0;
125
+ console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
126
+ }
127
+ if (!useSecure) {
128
+ if (attributes.secure) {
129
+ console.warn(
130
+ "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
131
+ );
121
132
  }
122
- return value
123
- }
124
- var createSessionCookie = async (session, cookieOptions, jose) => {
125
- try {
126
- const encoded = await jose.encodeJWT(session)
127
- return setCookie("sessionToken", encoded, cookieOptions)
128
- } catch (error) {
129
- throw new AuthError("server_error", "Failed to create session cookie", { cause: error })
133
+ if (attributes.sameSite == "none") {
134
+ attributes.sameSite = "lax";
135
+ console.warn("[WARNING]: SameSite=None requires Secure attribute. Changing SameSite to 'Lax'.");
130
136
  }
131
- }
132
- var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
133
- const name = cookieOptions.name ?? COOKIE_NAME
134
- const isSecure = trustedProxyHeaders
135
- ? request.url.startsWith("https://") ||
136
- request.headers.get("X-Forwarded-Proto") === "https" ||
137
- request.headers.get("Forwarded")?.includes("proto=https")
138
- : request.url.startsWith("https://")
139
- if (!cookieOptions.options?.httpOnly) {
140
- console.warn(
141
- "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
142
- )
137
+ if (process.env.NODE_ENV === "production") {
138
+ console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
143
139
  }
144
- if (cookieOptions.options?.domain === "*") {
145
- console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.")
140
+ if (strategy === "host") {
141
+ console.warn("[WARNING]: __Host- cookies require a secure context. Falling back to standard cookie settings.");
146
142
  }
147
- if (!isSecure) {
148
- const options = cookieOptions.options
149
- if (options?.secure) {
150
- console.warn(
151
- "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
152
- )
153
- }
154
- if (options?.sameSite == "none") {
155
- console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
156
- }
157
- if (process.env.NODE_ENV === "production") {
158
- console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
159
- }
160
- return {
161
- ...defaultCookieOptions,
162
- ...cookieOptions.options,
163
- sameSite: options?.sameSite === "none" ? "lax" : (options?.sameSite ?? "lax"),
164
- ...defaultStandardCookieConfig,
165
- name,
166
- }
167
- }
168
- return cookieOptions.strategy === "host"
169
- ? {
170
- ...defaultCookieOptions,
171
- ...cookieOptions.options,
172
- ...defaultHostCookieConfig,
173
- name,
174
- }
175
- : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
176
- }
177
- var expireCookie = (name, options) => {
178
- return setCookie(name, "", { ...options, ...expiredCookieOptions })
179
- }
180
- var oauthCookie = (options) => {
181
143
  return {
182
- ...options,
183
- secure: options.secure,
184
- httpOnly: options.httpOnly,
185
- maxAge: 5 * 60,
186
- expires: new Date(Date.now() + 5 * 60 * 1e3),
144
+ ...defaultCookieOptions,
145
+ ...attributes,
146
+ ...defaultStandardCookieConfig
147
+ };
148
+ }
149
+ return strategy === "host" ? {
150
+ ...defaultCookieOptions,
151
+ ...attributes,
152
+ ...defaultHostCookieConfig
153
+ } : { ...defaultCookieOptions, ...attributes, ...defaultSecureCookieConfig };
154
+ };
155
+ var createCookieStore = (useSecure, prefix, overrides) => {
156
+ prefix ??= COOKIE_NAME;
157
+ const securePrefix = useSecure ? "__Secure-" : "";
158
+ const hostPrefix = useSecure ? "__Host-" : "";
159
+ return {
160
+ sessionToken: {
161
+ name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "session_token"}`,
162
+ attributes: defineSecureCookieOptions(
163
+ useSecure,
164
+ {
165
+ ...defaultCookieOptions,
166
+ ...overrides?.sessionToken?.attributes
167
+ },
168
+ overrides?.sessionToken?.attributes?.strategy ?? "secure"
169
+ )
170
+ },
171
+ state: {
172
+ name: `${securePrefix}${prefix}.${overrides?.state?.name ?? "state"}`,
173
+ attributes: defineSecureCookieOptions(
174
+ useSecure,
175
+ {
176
+ ...oauthCookieOptions,
177
+ ...overrides?.state?.attributes
178
+ },
179
+ overrides?.state?.attributes?.strategy ?? "secure"
180
+ )
181
+ },
182
+ csrfToken: {
183
+ name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "csrf_token"}`,
184
+ attributes: defineSecureCookieOptions(
185
+ useSecure,
186
+ {
187
+ ...overrides?.csrfToken?.attributes,
188
+ ...defaultHostCookieConfig
189
+ },
190
+ overrides?.csrfToken?.attributes?.strategy ?? "host"
191
+ )
192
+ },
193
+ redirectTo: {
194
+ name: `${securePrefix}${prefix}.${overrides?.redirectTo?.name ?? "redirect_to"}`,
195
+ attributes: defineSecureCookieOptions(
196
+ useSecure,
197
+ {
198
+ ...oauthCookieOptions,
199
+ ...overrides?.redirectTo?.attributes
200
+ },
201
+ overrides?.redirectTo?.attributes?.strategy ?? "secure"
202
+ )
203
+ },
204
+ redirectURI: {
205
+ name: `${securePrefix}${prefix}.${overrides?.redirectURI?.name ?? "redirect_uri"}`,
206
+ attributes: defineSecureCookieOptions(
207
+ useSecure,
208
+ {
209
+ ...oauthCookieOptions,
210
+ ...overrides?.redirectURI?.attributes
211
+ },
212
+ overrides?.redirectURI?.attributes?.strategy ?? "secure"
213
+ )
214
+ },
215
+ codeVerifier: {
216
+ name: `${securePrefix}${prefix}.${overrides?.codeVerifier?.name ?? "code_verifier"}`,
217
+ attributes: defineSecureCookieOptions(
218
+ useSecure,
219
+ {
220
+ ...oauthCookieOptions,
221
+ ...overrides?.codeVerifier?.attributes
222
+ },
223
+ overrides?.codeVerifier?.attributes?.strategy ?? "secure"
224
+ )
187
225
  }
188
- }
226
+ };
227
+ };
189
228
  // Annotate the CommonJS export names for ESM import in node:
190
- 0 &&
191
- (module.exports = {
192
- COOKIE_NAME,
193
- createSessionCookie,
194
- defaultCookieConfig,
195
- defaultCookieOptions,
196
- defaultHostCookieConfig,
197
- defaultSecureCookieConfig,
198
- defaultStandardCookieConfig,
199
- defineDefaultCookieOptions,
200
- expireCookie,
201
- expiredCookieOptions,
202
- getCookie,
203
- oauthCookie,
204
- parse,
205
- secureCookieOptions,
206
- setCookie,
207
- })
229
+ 0 && (module.exports = {
230
+ COOKIE_NAME,
231
+ createCookieStore,
232
+ createSessionCookie,
233
+ defaultCookieOptions,
234
+ defaultHostCookieConfig,
235
+ defaultSecureCookieConfig,
236
+ defaultStandardCookieConfig,
237
+ defineSecureCookieOptions,
238
+ expiredCookieAttributes,
239
+ getCookie,
240
+ getSetCookie,
241
+ setCookie
242
+ });
package/dist/cookie.d.ts CHANGED
@@ -1,75 +1,64 @@
1
- import { SerializeOptions } from "cookie"
2
- export { parse } from "cookie"
3
- import { JWTPayload } from "@aura-stack/jose/jose"
4
- import { C as CookieConfig, a as CookieConfigInternal, b as CookieName, A as AuthRuntimeConfig } from "./index-DpfbvTZ_.js"
5
- import { LiteralUnion } from "./@types/utility.js"
6
- import "zod/v4"
7
- import "./schemas.js"
8
- import "zod/v4/core"
1
+ import { SerializeOptions } from '@aura-stack/router/cookie';
2
+ import { JWTPayload } from '@aura-stack/jose/jose';
3
+ import { A as AuthRuntimeConfig, C as CookieConfig, a as CookieStoreConfig } from './index-DkaLJFn8.js';
4
+ import 'zod';
5
+ import './schemas.js';
6
+ import '@aura-stack/jose';
7
+ import './@types/utility.js';
9
8
 
10
9
  /**
11
10
  * Prefix for all cookies set by Aura Auth.
12
11
  */
13
- declare const COOKIE_NAME = "aura-auth"
12
+ declare const COOKIE_NAME = "aura-auth";
14
13
  /**
15
14
  * Default cookie options used by Aura Auth.
16
15
  */
17
- declare const defaultCookieOptions: SerializeOptions
16
+ declare const defaultCookieOptions: SerializeOptions;
17
+ declare const defaultStandardCookieConfig: SerializeOptions;
18
18
  /**
19
- * Default cookie options for "standard" cookies.
20
- */
21
- declare const defaultCookieConfig: CookieConfig
22
- declare const defaultStandardCookieConfig: CookieConfigInternal
23
- /**
24
- * Default cookie options for "secure" cookies.
19
+ * Default cookie options for "__Secure-" cookies.
25
20
  * @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__secure-prefix
26
21
  */
27
- declare const defaultSecureCookieConfig: CookieConfigInternal
22
+ declare const defaultSecureCookieConfig: SerializeOptions;
28
23
  /**
29
- * Default cookie options for "host" cookies.
24
+ * Default cookie options for "__Host-" cookies.
30
25
  * @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__host-prefix
31
26
  */
32
- declare const defaultHostCookieConfig: CookieConfigInternal
33
- /**
34
- * Cookie options for expired cookies.
35
- */
36
- declare const expiredCookieOptions: SerializeOptions
37
- declare const defineDefaultCookieOptions: (options?: CookieConfigInternal) => CookieConfigInternal
27
+ declare const defaultHostCookieConfig: SerializeOptions;
38
28
  /**
39
- * Set a cookie with the given name, value and `CookieOptionsInternal`; supports secure
29
+ * Set a cookie with the given name, value and `SerializeOptions`; supports secure
40
30
  * cookies with the `__Secure-` and `__Host-` prefixes.
41
31
  *
42
32
  * Cookie attributes are serialized in the following order:
43
33
  * Expires, Max-Age, Domain, Path, Secure, HttpOnly, SameSite, Partitioned, Priority.
44
34
  */
45
- declare const setCookie: (cookieName: LiteralUnion<CookieName>, value: string, options?: CookieConfigInternal) => string
35
+ declare const setCookie: (cookieName: string, value: string, options?: SerializeOptions) => string;
36
+ declare const expiredCookieAttributes: SerializeOptions;
46
37
  /**
47
38
  * Get a cookie by name from the request.
48
39
  *
49
40
  * @param request The incoming request object
50
41
  * @param cookie Cookie name to retrieve
51
- * @param options Cookie options to define the prefix and other attributes
52
- * @param optional If true, returns an empty string instead of throwing an error when the cookie is not found
53
- * @returns The value of the cookie or undefined if not found
42
+ * @returns The value of the cookie or throw an error if not found
43
+ */
44
+ declare const getCookie: (request: Request, cookieName: string) => string;
45
+ /**
46
+ * Get a Set-Cookie header value by cookie name from the response.
47
+ *
48
+ * @param response The response object
49
+ * @param cookieName Cookie name to retrieve
50
+ * @returns The value of the Set-Cookie header or throw an error if not found
54
51
  */
55
- declare const getCookie: (
56
- petition: Request | Response,
57
- cookie: LiteralUnion<CookieName>,
58
- options?: CookieConfigInternal,
59
- optional?: boolean
60
- ) => string
52
+ declare const getSetCookie: (response: Response, cookieName: string) => string | undefined;
61
53
  /**
62
54
  * Create a session cookie containing a signed and encrypted JWT, using the
63
55
  * `@aura-stack/jose` package for the encoding.
64
56
  *
57
+ * @param jose - Jose Instance
65
58
  * @param session - The JWT payload to be encoded in the session cookie
66
59
  * @returns The serialized session cookie string
67
60
  */
68
- declare const createSessionCookie: (
69
- session: JWTPayload,
70
- cookieOptions: CookieConfigInternal,
71
- jose: AuthRuntimeConfig["jose"]
72
- ) => Promise<string>
61
+ declare const createSessionCookie: (jose: AuthRuntimeConfig["jose"], session: JWTPayload) => Promise<string>;
73
62
  /**
74
63
  * Defines the cookie configuration based on the request security and cookie options passed
75
64
  * in the Aura Auth configuration (`createAuth` function). This function ensures the correct
@@ -78,44 +67,18 @@ declare const createSessionCookie: (
78
67
  *
79
68
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto
80
69
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Forwarded
81
- * @param request The incoming request object
82
- * @param cookieOptions Cookie options from the Aura Auth configuration
70
+ * @param useSecure Whether the request is secure (HTTPS)
71
+ * @param attributes The cookie attributes to be applied
72
+ * @param strategy The cookie strategy: "host", "secure", or "standard"
83
73
  * @returns The finalized cookie options to be used for setting cookies
84
74
  */
85
- declare const secureCookieOptions: (
86
- request: Request,
87
- cookieOptions: CookieConfig,
88
- trustedProxyHeaders?: boolean
89
- ) => CookieConfigInternal
90
- /**
91
- * Expire a cookie by setting its value to an empty string and applying expired cookie options.
92
- *
93
- * @param name The name of the cookie to expire
94
- * @param options cookie options obtained from secureCookieOptions
95
- * @returns formatted cookie options for an expired cookie
96
- */
97
- declare const expireCookie: (name: LiteralUnion<CookieName>, options: CookieConfigInternal) => string
75
+ declare const defineSecureCookieOptions: (useSecure: boolean, attributes: SerializeOptions, strategy: "host" | "secure" | "standard") => SerializeOptions;
98
76
  /**
99
- * Set OAuth-specific cookie options, including a short maxAge of 5 minutes.
100
- *
101
- * @param options cookie options obtained from secureCookieOptions
102
- * @returns formatted cookie options for OAuth cookies
77
+ * @param useSecure Whether the request is secure (HTTPS)
78
+ * @param prefix Optional prefix added to all cookie names
79
+ * @param overrides Optional overrides for individual cookie configurations
80
+ * @returns The complete cookie store configuration
103
81
  */
104
- declare const oauthCookie: (options: CookieConfigInternal) => CookieConfigInternal
82
+ declare const createCookieStore: (useSecure: boolean, prefix?: string, overrides?: CookieConfig["overrides"]) => CookieStoreConfig;
105
83
 
106
- export {
107
- COOKIE_NAME,
108
- createSessionCookie,
109
- defaultCookieConfig,
110
- defaultCookieOptions,
111
- defaultHostCookieConfig,
112
- defaultSecureCookieConfig,
113
- defaultStandardCookieConfig,
114
- defineDefaultCookieOptions,
115
- expireCookie,
116
- expiredCookieOptions,
117
- getCookie,
118
- oauthCookie,
119
- secureCookieOptions,
120
- setCookie,
121
- }
84
+ export { COOKIE_NAME, createCookieStore, createSessionCookie, defaultCookieOptions, defaultHostCookieConfig, defaultSecureCookieConfig, defaultStandardCookieConfig, defineSecureCookieOptions, expiredCookieAttributes, getCookie, getSetCookie, setCookie };
package/dist/cookie.js CHANGED
@@ -1,36 +1,29 @@
1
1
  import {
2
- COOKIE_NAME,
3
- createSessionCookie,
4
- defaultCookieConfig,
5
- defaultCookieOptions,
6
- defaultHostCookieConfig,
7
- defaultSecureCookieConfig,
8
- defaultStandardCookieConfig,
9
- defineDefaultCookieOptions,
10
- expireCookie,
11
- expiredCookieOptions,
12
- getCookie,
13
- oauthCookie,
14
- parse,
15
- secureCookieOptions,
16
- setCookie,
17
- } from "./chunk-ZV4BH47P.js"
18
- import "./chunk-6SM22VVJ.js"
19
- import "./chunk-FJUDBLCP.js"
2
+ COOKIE_NAME,
3
+ createCookieStore,
4
+ createSessionCookie,
5
+ defaultCookieOptions,
6
+ defaultHostCookieConfig,
7
+ defaultSecureCookieConfig,
8
+ defaultStandardCookieConfig,
9
+ defineSecureCookieOptions,
10
+ expiredCookieAttributes,
11
+ getCookie,
12
+ getSetCookie,
13
+ setCookie
14
+ } from "./chunk-W6LG7BFW.js";
15
+ import "./chunk-RRLIF4PQ.js";
20
16
  export {
21
- COOKIE_NAME,
22
- createSessionCookie,
23
- defaultCookieConfig,
24
- defaultCookieOptions,
25
- defaultHostCookieConfig,
26
- defaultSecureCookieConfig,
27
- defaultStandardCookieConfig,
28
- defineDefaultCookieOptions,
29
- expireCookie,
30
- expiredCookieOptions,
31
- getCookie,
32
- oauthCookie,
33
- parse,
34
- secureCookieOptions,
35
- setCookie,
36
- }
17
+ COOKIE_NAME,
18
+ createCookieStore,
19
+ createSessionCookie,
20
+ defaultCookieOptions,
21
+ defaultHostCookieConfig,
22
+ defaultSecureCookieConfig,
23
+ defaultStandardCookieConfig,
24
+ defineSecureCookieOptions,
25
+ expiredCookieAttributes,
26
+ getCookie,
27
+ getSetCookie,
28
+ setCookie
29
+ };