@aura-stack/auth 0.1.0 → 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 (111) hide show
  1. package/dist/@types/index.d.ts +5 -5
  2. package/dist/@types/router.d.d.ts +5 -5
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +95 -74
  5. package/dist/actions/callback/access-token.d.ts +7 -7
  6. package/dist/actions/callback/access-token.js +5 -3
  7. package/dist/actions/callback/callback.cjs +171 -249
  8. package/dist/actions/callback/callback.d.ts +6 -6
  9. package/dist/actions/callback/callback.js +10 -10
  10. package/dist/actions/callback/userinfo.cjs +81 -57
  11. package/dist/actions/callback/userinfo.d.ts +5 -5
  12. package/dist/actions/callback/userinfo.js +7 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +36 -105
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +309 -444
  16. package/dist/actions/index.d.ts +5 -5
  17. package/dist/actions/index.js +19 -19
  18. package/dist/actions/session/session.cjs +25 -109
  19. package/dist/actions/session/session.js +4 -5
  20. package/dist/actions/signIn/authorization.cjs +96 -87
  21. package/dist/actions/signIn/authorization.d.ts +5 -5
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +133 -242
  24. package/dist/actions/signIn/signIn.d.ts +6 -6
  25. package/dist/actions/signIn/signIn.js +8 -9
  26. package/dist/actions/signOut/signOut.cjs +136 -282
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +10 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-3EUWD5BB.js +63 -0
  32. package/dist/chunk-6R2YZ4AC.js +22 -0
  33. package/dist/chunk-A3N4PVAT.js +70 -0
  34. package/dist/chunk-B737EUJV.js +22 -0
  35. package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
  36. package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
  37. package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
  38. package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
  39. package/dist/chunk-HP34YGGJ.js +22 -0
  40. package/dist/chunk-HT4YLL7N.js +35 -0
  41. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  42. package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
  43. package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
  44. package/dist/chunk-KSWLO5ZU.js +102 -0
  45. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  46. package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
  47. package/dist/chunk-RRLIF4PQ.js +55 -0
  48. package/dist/chunk-TLE4PXY3.js +39 -0
  49. package/dist/chunk-W6LG7BFW.js +197 -0
  50. package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
  51. package/dist/chunk-ZNCZVF6U.js +14 -0
  52. package/dist/cookie.cjs +140 -99
  53. package/dist/cookie.d.ts +35 -44
  54. package/dist/cookie.js +10 -17
  55. package/dist/errors.cjs +85 -0
  56. package/dist/errors.d.ts +49 -0
  57. package/dist/errors.js +18 -0
  58. package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
  59. package/dist/index.cjs +543 -443
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +42 -28
  62. package/dist/jose.cjs +25 -14
  63. package/dist/jose.d.ts +4 -1
  64. package/dist/jose.js +5 -4
  65. package/dist/oauth/bitbucket.d.ts +5 -5
  66. package/dist/oauth/discord.cjs +0 -1
  67. package/dist/oauth/discord.d.ts +5 -5
  68. package/dist/oauth/discord.js +1 -1
  69. package/dist/oauth/figma.d.ts +5 -5
  70. package/dist/oauth/github.d.ts +5 -5
  71. package/dist/oauth/gitlab.d.ts +5 -5
  72. package/dist/oauth/index.cjs +176 -6
  73. package/dist/oauth/index.d.ts +5 -5
  74. package/dist/oauth/index.js +19 -4
  75. package/dist/oauth/mailchimp.cjs +46 -0
  76. package/dist/oauth/mailchimp.d.ts +7 -0
  77. package/dist/oauth/mailchimp.js +6 -0
  78. package/dist/oauth/pinterest.cjs +46 -0
  79. package/dist/oauth/pinterest.d.ts +7 -0
  80. package/dist/oauth/pinterest.js +6 -0
  81. package/dist/oauth/spotify.d.ts +5 -5
  82. package/dist/oauth/strava.cjs +46 -0
  83. package/dist/oauth/strava.d.ts +7 -0
  84. package/dist/oauth/strava.js +6 -0
  85. package/dist/oauth/x.d.ts +5 -5
  86. package/dist/{response.cjs → request.cjs} +14 -10
  87. package/dist/request.d.ts +13 -0
  88. package/dist/request.js +6 -0
  89. package/dist/schemas.cjs +43 -37
  90. package/dist/schemas.d.ts +67 -64
  91. package/dist/schemas.js +3 -1
  92. package/dist/secure.cjs +32 -24
  93. package/dist/secure.d.ts +5 -5
  94. package/dist/secure.js +4 -3
  95. package/dist/utils.cjs +90 -15
  96. package/dist/utils.d.ts +11 -2
  97. package/dist/utils.js +8 -4
  98. package/package.json +8 -7
  99. package/dist/chunk-FJUDBLCP.js +0 -59
  100. package/dist/chunk-HGJ4TXY4.js +0 -137
  101. package/dist/chunk-JAPMIE6S.js +0 -10
  102. package/dist/chunk-LLR722CL.js +0 -96
  103. package/dist/chunk-SJPDVKUS.js +0 -112
  104. package/dist/chunk-SMQO5WD7.js +0 -30
  105. package/dist/chunk-UTDLUEEG.js +0 -31
  106. package/dist/chunk-ZV4BH47P.js +0 -154
  107. package/dist/error.cjs +0 -88
  108. package/dist/error.d.ts +0 -62
  109. package/dist/error.js +0 -16
  110. package/dist/response.d.ts +0 -10
  111. package/dist/response.js +0 -6
package/dist/cookie.cjs CHANGED
@@ -21,40 +21,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var cookie_exports = {};
22
22
  __export(cookie_exports, {
23
23
  COOKIE_NAME: () => COOKIE_NAME,
24
+ createCookieStore: () => createCookieStore,
24
25
  createSessionCookie: () => createSessionCookie,
25
- defaultCookieConfig: () => defaultCookieConfig,
26
26
  defaultCookieOptions: () => defaultCookieOptions,
27
27
  defaultHostCookieConfig: () => defaultHostCookieConfig,
28
28
  defaultSecureCookieConfig: () => defaultSecureCookieConfig,
29
29
  defaultStandardCookieConfig: () => defaultStandardCookieConfig,
30
- defineDefaultCookieOptions: () => defineDefaultCookieOptions,
31
- expireCookie: () => expireCookie,
32
- expiredCookieOptions: () => expiredCookieOptions,
30
+ defineSecureCookieOptions: () => defineSecureCookieOptions,
31
+ expiredCookieAttributes: () => expiredCookieAttributes,
33
32
  getCookie: () => getCookie,
34
- oauthCookie: () => oauthCookie,
35
- parse: () => import_cookie2.parse,
36
- secureCookieOptions: () => secureCookieOptions,
33
+ getSetCookie: () => getSetCookie,
37
34
  setCookie: () => setCookie
38
35
  });
39
36
  module.exports = __toCommonJS(cookie_exports);
40
- var import_cookie = require("cookie");
37
+ var import_cookie = require("@aura-stack/router/cookie");
41
38
 
42
- // src/error.ts
43
- var AuthError = class extends Error {
44
- constructor(type, message) {
45
- super(message);
46
- this.type = type;
47
- this.name = "AuthError";
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
48
  }
49
49
  };
50
50
 
51
- // src/assert.ts
52
- var isRequest = (value) => {
53
- return typeof Request !== "undefined" && value instanceof Request;
54
- };
55
-
56
51
  // src/cookie.ts
57
- var import_cookie2 = require("cookie");
58
52
  var COOKIE_NAME = "aura-auth";
59
53
  var defaultCookieOptions = {
60
54
  httpOnly: true,
@@ -62,140 +56,187 @@ var defaultCookieOptions = {
62
56
  path: "/",
63
57
  maxAge: 60 * 60 * 24 * 15
64
58
  };
65
- var defaultCookieConfig = {
66
- strategy: "standard",
67
- name: COOKIE_NAME,
68
- options: defaultCookieOptions
69
- };
70
59
  var defaultStandardCookieConfig = {
71
60
  secure: false,
72
- httpOnly: true,
73
- prefix: ""
61
+ httpOnly: true
74
62
  };
75
63
  var defaultSecureCookieConfig = {
76
64
  secure: true,
77
- prefix: "__Secure-"
65
+ httpOnly: true
78
66
  };
79
67
  var defaultHostCookieConfig = {
80
68
  secure: true,
81
- prefix: "__Host-",
69
+ httpOnly: true,
82
70
  path: "/",
83
71
  domain: void 0
84
72
  };
85
- var expiredCookieOptions = {
73
+ var oauthCookieOptions = {
74
+ httpOnly: true,
75
+ maxAge: 5 * 60,
76
+ sameSite: "lax",
77
+ expires: new Date(Date.now() + 5 * 60 * 1e3)
78
+ };
79
+ var setCookie = (cookieName, value, options) => {
80
+ return (0, import_cookie.serialize)(cookieName, value, options);
81
+ };
82
+ var expiredCookieAttributes = {
86
83
  ...defaultCookieOptions,
87
84
  expires: /* @__PURE__ */ new Date(0),
88
85
  maxAge: 0
89
86
  };
90
- var defineDefaultCookieOptions = (options) => {
91
- return {
92
- name: options?.name ?? COOKIE_NAME,
93
- prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
94
- ...defaultCookieOptions,
95
- ...options
96
- };
97
- };
98
- var setCookie = (cookieName, value, options) => {
99
- const { prefix, name } = defineDefaultCookieOptions(options);
100
- const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
101
- return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
102
- ...defaultCookieOptions,
103
- ...options
104
- });
105
- };
106
- var getCookie = (petition, cookie, options, optional = false) => {
107
- const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
87
+ var getCookie = (request, cookieName) => {
88
+ const cookies = request.headers.get("Cookie");
108
89
  if (!cookies) {
109
- if (optional) {
110
- return "";
111
- }
112
- throw new AuthError("invalid_request", "No cookies found. There is no active session");
90
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
113
91
  }
114
- const { name, prefix } = defineDefaultCookieOptions(options);
115
- const parsedCookies = (0, import_cookie.parse)(cookies);
116
- const value = parsedCookies[`${prefix}${name}.${cookie}`];
117
- if (value === void 0) {
118
- if (optional) {
119
- return "";
120
- }
121
- throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
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`);
122
95
  }
123
96
  return value;
124
97
  };
125
- var createSessionCookie = async (session, cookieOptions, jose) => {
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) => {
126
110
  try {
127
111
  const encoded = await jose.encodeJWT(session);
128
- return setCookie("sessionToken", encoded, cookieOptions);
112
+ return encoded;
129
113
  } catch (error) {
130
- throw new AuthError("server_error", "Failed to create session cookie", { cause: error });
114
+ throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
131
115
  }
132
116
  };
133
- var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
134
- const name = cookieOptions.name ?? COOKIE_NAME;
135
- const isSecure = trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || request.headers.get("Forwarded")?.includes("proto=https") : request.url.startsWith("https://");
136
- if (!cookieOptions.options?.httpOnly) {
117
+ var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
118
+ if (!attributes.httpOnly) {
137
119
  console.warn(
138
120
  "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
139
121
  );
140
122
  }
141
- if (cookieOptions.options?.domain === "*") {
123
+ if (attributes.domain === "*") {
124
+ attributes.domain = void 0;
142
125
  console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
143
126
  }
144
- if (!isSecure) {
145
- const options = cookieOptions.options;
146
- if (options?.secure) {
127
+ if (!useSecure) {
128
+ if (attributes.secure) {
147
129
  console.warn(
148
130
  "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
149
131
  );
150
132
  }
151
- if (options?.sameSite == "none") {
152
- console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
133
+ if (attributes.sameSite == "none") {
134
+ attributes.sameSite = "lax";
135
+ console.warn("[WARNING]: SameSite=None requires Secure attribute. Changing SameSite to 'Lax'.");
153
136
  }
154
137
  if (process.env.NODE_ENV === "production") {
155
138
  console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
156
139
  }
140
+ if (strategy === "host") {
141
+ console.warn("[WARNING]: __Host- cookies require a secure context. Falling back to standard cookie settings.");
142
+ }
157
143
  return {
158
144
  ...defaultCookieOptions,
159
- ...cookieOptions.options,
160
- sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
161
- ...defaultStandardCookieConfig,
162
- name
145
+ ...attributes,
146
+ ...defaultStandardCookieConfig
163
147
  };
164
148
  }
165
- return cookieOptions.strategy === "host" ? {
149
+ return strategy === "host" ? {
166
150
  ...defaultCookieOptions,
167
- ...cookieOptions.options,
168
- ...defaultHostCookieConfig,
169
- name
170
- } : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
171
- };
172
- var expireCookie = (name, options) => {
173
- return setCookie(name, "", { ...options, ...expiredCookieOptions });
174
- };
175
- var oauthCookie = (options) => {
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-" : "";
176
159
  return {
177
- ...options,
178
- secure: options.secure,
179
- httpOnly: options.httpOnly,
180
- maxAge: 5 * 60,
181
- expires: new Date(Date.now() + 5 * 60 * 1e3)
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
+ )
225
+ }
182
226
  };
183
227
  };
184
228
  // Annotate the CommonJS export names for ESM import in node:
185
229
  0 && (module.exports = {
186
230
  COOKIE_NAME,
231
+ createCookieStore,
187
232
  createSessionCookie,
188
- defaultCookieConfig,
189
233
  defaultCookieOptions,
190
234
  defaultHostCookieConfig,
191
235
  defaultSecureCookieConfig,
192
236
  defaultStandardCookieConfig,
193
- defineDefaultCookieOptions,
194
- expireCookie,
195
- expiredCookieOptions,
237
+ defineSecureCookieOptions,
238
+ expiredCookieAttributes,
196
239
  getCookie,
197
- oauthCookie,
198
- parse,
199
- secureCookieOptions,
240
+ getSetCookie,
200
241
  setCookie
201
242
  });
package/dist/cookie.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { SerializeOptions } from 'cookie';
2
- export { parse } from 'cookie';
1
+ import { SerializeOptions } from '@aura-stack/router/cookie';
3
2
  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';
3
+ import { A as AuthRuntimeConfig, C as CookieConfig, a as CookieStoreConfig } from './index-DkaLJFn8.js';
4
+ import 'zod';
7
5
  import './schemas.js';
8
- import 'zod/v4/core';
6
+ import '@aura-stack/jose';
7
+ import './@types/utility.js';
9
8
 
10
9
  /**
11
10
  * Prefix for all cookies set by Aura Auth.
@@ -15,52 +14,51 @@ declare const COOKIE_NAME = "aura-auth";
15
14
  * Default cookie options used by Aura Auth.
16
15
  */
17
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: (petition: Request | Response, cookie: LiteralUnion<CookieName>, options?: CookieConfigInternal, optional?: boolean) => string;
52
+ declare const getSetCookie: (response: Response, cookieName: string) => string | undefined;
56
53
  /**
57
54
  * Create a session cookie containing a signed and encrypted JWT, using the
58
55
  * `@aura-stack/jose` package for the encoding.
59
56
  *
57
+ * @param jose - Jose Instance
60
58
  * @param session - The JWT payload to be encoded in the session cookie
61
59
  * @returns The serialized session cookie string
62
60
  */
63
- declare const createSessionCookie: (session: JWTPayload, cookieOptions: CookieConfigInternal, jose: AuthRuntimeConfig["jose"]) => Promise<string>;
61
+ declare const createSessionCookie: (jose: AuthRuntimeConfig["jose"], session: JWTPayload) => Promise<string>;
64
62
  /**
65
63
  * Defines the cookie configuration based on the request security and cookie options passed
66
64
  * in the Aura Auth configuration (`createAuth` function). This function ensures the correct
@@ -69,25 +67,18 @@ declare const createSessionCookie: (session: JWTPayload, cookieOptions: CookieCo
69
67
  *
70
68
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto
71
69
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Forwarded
72
- * @param request The incoming request object
73
- * @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"
74
73
  * @returns The finalized cookie options to be used for setting cookies
75
74
  */
76
- declare const secureCookieOptions: (request: Request, cookieOptions: CookieConfig, trustedProxyHeaders?: boolean) => CookieConfigInternal;
77
- /**
78
- * Expire a cookie by setting its value to an empty string and applying expired cookie options.
79
- *
80
- * @param name The name of the cookie to expire
81
- * @param options cookie options obtained from secureCookieOptions
82
- * @returns formatted cookie options for an expired cookie
83
- */
84
- declare const expireCookie: (name: LiteralUnion<CookieName>, options: CookieConfigInternal) => string;
75
+ declare const defineSecureCookieOptions: (useSecure: boolean, attributes: SerializeOptions, strategy: "host" | "secure" | "standard") => SerializeOptions;
85
76
  /**
86
- * Set OAuth-specific cookie options, including a short maxAge of 5 minutes.
87
- *
88
- * @param options cookie options obtained from secureCookieOptions
89
- * @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
90
81
  */
91
- declare const oauthCookie: (options: CookieConfigInternal) => CookieConfigInternal;
82
+ declare const createCookieStore: (useSecure: boolean, prefix?: string, overrides?: CookieConfig["overrides"]) => CookieStoreConfig;
92
83
 
93
- export { COOKIE_NAME, createSessionCookie, defaultCookieConfig, defaultCookieOptions, defaultHostCookieConfig, defaultSecureCookieConfig, defaultStandardCookieConfig, defineDefaultCookieOptions, expireCookie, expiredCookieOptions, getCookie, oauthCookie, secureCookieOptions, setCookie };
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
2
  COOKIE_NAME,
3
+ createCookieStore,
3
4
  createSessionCookie,
4
- defaultCookieConfig,
5
5
  defaultCookieOptions,
6
6
  defaultHostCookieConfig,
7
7
  defaultSecureCookieConfig,
8
8
  defaultStandardCookieConfig,
9
- defineDefaultCookieOptions,
10
- expireCookie,
11
- expiredCookieOptions,
9
+ defineSecureCookieOptions,
10
+ expiredCookieAttributes,
12
11
  getCookie,
13
- oauthCookie,
14
- parse,
15
- secureCookieOptions,
12
+ getSetCookie,
16
13
  setCookie
17
- } from "./chunk-ZV4BH47P.js";
18
- import "./chunk-6SM22VVJ.js";
19
- import "./chunk-FJUDBLCP.js";
14
+ } from "./chunk-W6LG7BFW.js";
15
+ import "./chunk-RRLIF4PQ.js";
20
16
  export {
21
17
  COOKIE_NAME,
18
+ createCookieStore,
22
19
  createSessionCookie,
23
- defaultCookieConfig,
24
20
  defaultCookieOptions,
25
21
  defaultHostCookieConfig,
26
22
  defaultSecureCookieConfig,
27
23
  defaultStandardCookieConfig,
28
- defineDefaultCookieOptions,
29
- expireCookie,
30
- expiredCookieOptions,
24
+ defineSecureCookieOptions,
25
+ expiredCookieAttributes,
31
26
  getCookie,
32
- oauthCookie,
33
- parse,
34
- secureCookieOptions,
27
+ getSetCookie,
35
28
  setCookie
36
29
  };
@@ -0,0 +1,85 @@
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
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
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);
19
+
20
+ // src/errors.ts
21
+ var errors_exports = {};
22
+ __export(errors_exports, {
23
+ AuthInternalError: () => AuthInternalError,
24
+ AuthSecurityError: () => AuthSecurityError,
25
+ OAuthProtocolError: () => OAuthProtocolError,
26
+ isAuthInternalError: () => isAuthInternalError,
27
+ isAuthSecurityError: () => isAuthSecurityError,
28
+ isNativeError: () => isNativeError,
29
+ isOAuthProtocolError: () => isOAuthProtocolError
30
+ });
31
+ module.exports = __toCommonJS(errors_exports);
32
+ var OAuthProtocolError = class extends Error {
33
+ type = "OAUTH_PROTOCOL_ERROR";
34
+ error;
35
+ errorURI;
36
+ constructor(error, description, errorURI, options) {
37
+ super(description, options);
38
+ this.error = error;
39
+ this.errorURI = errorURI;
40
+ this.name = new.target.name;
41
+ Error.captureStackTrace(this, new.target);
42
+ }
43
+ };
44
+ var AuthInternalError = class extends Error {
45
+ type = "AUTH_INTERNAL_ERROR";
46
+ code;
47
+ constructor(code, message, options) {
48
+ super(message, options);
49
+ this.code = code;
50
+ this.name = new.target.name;
51
+ Error.captureStackTrace(this, new.target);
52
+ }
53
+ };
54
+ var AuthSecurityError = class extends Error {
55
+ type = "AUTH_SECURITY_ERROR";
56
+ code;
57
+ constructor(code, message, options) {
58
+ super(message, options);
59
+ this.code = code;
60
+ this.name = new.target.name;
61
+ Error.captureStackTrace(this, new.target);
62
+ }
63
+ };
64
+ var isNativeError = (error) => {
65
+ return error instanceof Error;
66
+ };
67
+ var isOAuthProtocolError = (error) => {
68
+ return error instanceof OAuthProtocolError;
69
+ };
70
+ var isAuthInternalError = (error) => {
71
+ return error instanceof AuthInternalError;
72
+ };
73
+ var isAuthSecurityError = (error) => {
74
+ return error instanceof AuthSecurityError;
75
+ };
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ AuthInternalError,
79
+ AuthSecurityError,
80
+ OAuthProtocolError,
81
+ isAuthInternalError,
82
+ isAuthSecurityError,
83
+ isNativeError,
84
+ isOAuthProtocolError
85
+ });
@@ -0,0 +1,49 @@
1
+ import { E as ErrorType, b as AuthInternalErrorCode, c as AuthSecurityErrorCode } from './index-DkaLJFn8.js';
2
+ import { LiteralUnion } from './@types/utility.js';
3
+ import 'zod';
4
+ import './schemas.js';
5
+ import '@aura-stack/router/cookie';
6
+ import '@aura-stack/jose';
7
+ import '@aura-stack/jose/jose';
8
+
9
+ /**
10
+ * The object returned by the class to users its:
11
+ * - type: "OAUTH_PROTOCOL_ERROR" to identify the error type
12
+ * - error: A short error code
13
+ * - description: A human-readable description of the error. The description is obtained from the message property of the Error class
14
+ * - errorURI: A URI with more information about the error
15
+ */
16
+ declare class OAuthProtocolError extends Error {
17
+ readonly type = "OAUTH_PROTOCOL_ERROR";
18
+ readonly error: string;
19
+ readonly errorURI?: string;
20
+ constructor(error: LiteralUnion<Uppercase<ErrorType>>, description?: string, errorURI?: string, options?: ErrorOptions);
21
+ }
22
+ /**
23
+ * The object returned when an internal error occurs in the Aura Auth library.
24
+ * - type: "AUTH_INTERNAL_ERROR" to identify the error type
25
+ * - message: A human-readable description of the error. The description is obtained from the message property of the Error class
26
+ * - code: An optional error code that can be used to identify the specific error, for example, LIKE "ERR_AUTH_INTERNAL_ERROR"
27
+ */
28
+ declare class AuthInternalError extends Error {
29
+ readonly type = "AUTH_INTERNAL_ERROR";
30
+ readonly code: string;
31
+ constructor(code: AuthInternalErrorCode, message?: string, options?: ErrorOptions);
32
+ }
33
+ /**
34
+ * The object returned when a security error occurs in the Aura Auth library.
35
+ * - type: "AUTH_SECURITY_ERROR" to identify the error type
36
+ * - message: A human-readable description of the error. The description is obtained from the message property of the Error class
37
+ * - code: An optional error code that can be used to identify the specific error, for example, LIKE "ERR_AUTH_SECURITY_ERROR"
38
+ */
39
+ declare class AuthSecurityError extends Error {
40
+ readonly type = "AUTH_SECURITY_ERROR";
41
+ readonly code: string;
42
+ constructor(code: AuthSecurityErrorCode, message?: string, options?: ErrorOptions);
43
+ }
44
+ declare const isNativeError: (error: unknown) => error is Error;
45
+ declare const isOAuthProtocolError: (error: unknown) => error is OAuthProtocolError;
46
+ declare const isAuthInternalError: (error: unknown) => error is AuthInternalError;
47
+ declare const isAuthSecurityError: (error: unknown) => error is AuthSecurityError;
48
+
49
+ export { AuthInternalError, AuthSecurityError, OAuthProtocolError, isAuthInternalError, isAuthSecurityError, isNativeError, isOAuthProtocolError };
package/dist/errors.js ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ AuthInternalError,
3
+ AuthSecurityError,
4
+ OAuthProtocolError,
5
+ isAuthInternalError,
6
+ isAuthSecurityError,
7
+ isNativeError,
8
+ isOAuthProtocolError
9
+ } from "./chunk-RRLIF4PQ.js";
10
+ export {
11
+ AuthInternalError,
12
+ AuthSecurityError,
13
+ OAuthProtocolError,
14
+ isAuthInternalError,
15
+ isAuthSecurityError,
16
+ isNativeError,
17
+ isOAuthProtocolError
18
+ };