@aura-stack/auth 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/@types/index.d.ts +3 -4
  2. package/dist/@types/router.d.d.ts +3 -4
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +51 -41
  5. package/dist/actions/callback/access-token.d.ts +3 -4
  6. package/dist/actions/callback/access-token.js +4 -3
  7. package/dist/actions/callback/callback.cjs +115 -210
  8. package/dist/actions/callback/callback.d.ts +3 -4
  9. package/dist/actions/callback/callback.js +9 -10
  10. package/dist/actions/callback/userinfo.cjs +35 -22
  11. package/dist/actions/callback/userinfo.d.ts +3 -4
  12. package/dist/actions/callback/userinfo.js +6 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +34 -103
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +234 -391
  16. package/dist/actions/index.d.ts +3 -4
  17. package/dist/actions/index.js +16 -17
  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 +64 -55
  21. package/dist/actions/signIn/authorization.d.ts +3 -4
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +84 -206
  24. package/dist/actions/signIn/signIn.d.ts +3 -4
  25. package/dist/actions/signIn/signIn.js +7 -9
  26. package/dist/actions/signOut/signOut.cjs +88 -234
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +9 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-2RXNXMCZ.js +55 -0
  32. package/dist/{chunk-UJJ7R56J.js → chunk-4V4JNXVF.js} +13 -10
  33. package/dist/chunk-6R2YZ4AC.js +22 -0
  34. package/dist/{chunk-VFTYH33W.js → chunk-7H3OR6UU.js} +29 -9
  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-IMICRJ5U.js +197 -0
  38. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  39. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  40. package/dist/chunk-NEVKX6K2.js +70 -0
  41. package/dist/{chunk-XXJKNKGQ.js → chunk-PTJUYB33.js} +9 -13
  42. package/dist/chunk-QDO2KSRJ.js +35 -0
  43. package/dist/{chunk-CAKJT3KS.js → chunk-QEZL7EYN.js} +21 -17
  44. package/dist/chunk-RRLIF4PQ.js +55 -0
  45. package/dist/chunk-TLE4PXY3.js +39 -0
  46. package/dist/chunk-UEH3LVON.js +97 -0
  47. package/dist/{chunk-HMRKN75I.js → chunk-WD7AUHQ5.js} +12 -7
  48. package/dist/{chunk-RLT4RFKV.js → chunk-ZLR3LI6X.js} +19 -9
  49. package/dist/cookie.cjs +140 -99
  50. package/dist/cookie.d.ts +33 -43
  51. package/dist/cookie.js +10 -17
  52. package/dist/errors.cjs +85 -0
  53. package/dist/errors.d.ts +48 -0
  54. package/dist/errors.js +18 -0
  55. package/dist/{index-DpfbvTZ_.d.ts → index-EqsoyjrF.d.ts} +139 -57
  56. package/dist/index.cjs +427 -389
  57. package/dist/index.d.ts +4 -5
  58. package/dist/index.js +37 -26
  59. package/dist/jose.cjs +23 -12
  60. package/dist/jose.d.ts +4 -1
  61. package/dist/jose.js +5 -4
  62. package/dist/oauth/bitbucket.d.ts +3 -4
  63. package/dist/oauth/discord.cjs +0 -1
  64. package/dist/oauth/discord.d.ts +3 -4
  65. package/dist/oauth/discord.js +1 -1
  66. package/dist/oauth/figma.d.ts +3 -4
  67. package/dist/oauth/github.d.ts +3 -4
  68. package/dist/oauth/gitlab.d.ts +3 -4
  69. package/dist/oauth/index.cjs +132 -6
  70. package/dist/oauth/index.d.ts +3 -4
  71. package/dist/oauth/index.js +12 -5
  72. package/dist/oauth/spotify.d.ts +3 -4
  73. package/dist/{response.cjs → oauth/strava.cjs} +21 -9
  74. package/dist/oauth/strava.d.ts +6 -0
  75. package/dist/oauth/strava.js +6 -0
  76. package/dist/oauth/x.d.ts +3 -4
  77. package/dist/schemas.cjs +11 -5
  78. package/dist/schemas.d.ts +70 -67
  79. package/dist/schemas.js +3 -1
  80. package/dist/secure.cjs +27 -19
  81. package/dist/secure.d.ts +3 -4
  82. package/dist/secure.js +4 -3
  83. package/dist/utils.cjs +90 -15
  84. package/dist/utils.d.ts +11 -2
  85. package/dist/utils.js +8 -4
  86. package/package.json +5 -6
  87. package/dist/chunk-FJUDBLCP.js +0 -59
  88. package/dist/chunk-HGJ4TXY4.js +0 -137
  89. package/dist/chunk-JAPMIE6S.js +0 -10
  90. package/dist/chunk-LLR722CL.js +0 -96
  91. package/dist/chunk-SJPDVKUS.js +0 -112
  92. package/dist/chunk-SMQO5WD7.js +0 -30
  93. package/dist/chunk-UTDLUEEG.js +0 -31
  94. package/dist/chunk-ZV4BH47P.js +0 -154
  95. package/dist/error.cjs +0 -88
  96. package/dist/error.d.ts +0 -62
  97. package/dist/error.js +0 -16
  98. package/dist/response.d.ts +0 -10
  99. package/dist/response.js +0 -6
package/dist/cookie.d.ts CHANGED
@@ -1,11 +1,9 @@
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';
3
+ import { A as AuthRuntimeConfig, C as CookieConfig, a as CookieStoreConfig } from './index-EqsoyjrF.js';
6
4
  import 'zod/v4';
7
5
  import './schemas.js';
8
- import 'zod/v4/core';
6
+ import './@types/utility.js';
9
7
 
10
8
  /**
11
9
  * Prefix for all cookies set by Aura Auth.
@@ -15,52 +13,51 @@ declare const COOKIE_NAME = "aura-auth";
15
13
  * Default cookie options used by Aura Auth.
16
14
  */
17
15
  declare const defaultCookieOptions: SerializeOptions;
16
+ declare const defaultStandardCookieConfig: SerializeOptions;
18
17
  /**
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.
18
+ * Default cookie options for "__Secure-" cookies.
25
19
  * @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__secure-prefix
26
20
  */
27
- declare const defaultSecureCookieConfig: CookieConfigInternal;
21
+ declare const defaultSecureCookieConfig: SerializeOptions;
28
22
  /**
29
- * Default cookie options for "host" cookies.
23
+ * Default cookie options for "__Host-" cookies.
30
24
  * @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__host-prefix
31
25
  */
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;
26
+ declare const defaultHostCookieConfig: SerializeOptions;
38
27
  /**
39
- * Set a cookie with the given name, value and `CookieOptionsInternal`; supports secure
28
+ * Set a cookie with the given name, value and `SerializeOptions`; supports secure
40
29
  * cookies with the `__Secure-` and `__Host-` prefixes.
41
30
  *
42
31
  * Cookie attributes are serialized in the following order:
43
32
  * Expires, Max-Age, Domain, Path, Secure, HttpOnly, SameSite, Partitioned, Priority.
44
33
  */
45
- declare const setCookie: (cookieName: LiteralUnion<CookieName>, value: string, options?: CookieConfigInternal) => string;
34
+ declare const setCookie: (cookieName: string, value: string, options?: SerializeOptions) => string;
35
+ declare const expiredCookieAttributes: SerializeOptions;
46
36
  /**
47
37
  * Get a cookie by name from the request.
48
38
  *
49
39
  * @param request The incoming request object
50
40
  * @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
41
+ * @returns The value of the cookie or throw an error if not found
42
+ */
43
+ declare const getCookie: (request: Request, cookieName: string) => string;
44
+ /**
45
+ * Get a Set-Cookie header value by cookie name from the response.
46
+ *
47
+ * @param response The response object
48
+ * @param cookieName Cookie name to retrieve
49
+ * @returns The value of the Set-Cookie header or throw an error if not found
54
50
  */
55
- declare const getCookie: (petition: Request | Response, cookie: LiteralUnion<CookieName>, options?: CookieConfigInternal, optional?: boolean) => string;
51
+ declare const getSetCookie: (response: Response, cookieName: string) => string | undefined;
56
52
  /**
57
53
  * Create a session cookie containing a signed and encrypted JWT, using the
58
54
  * `@aura-stack/jose` package for the encoding.
59
55
  *
56
+ * @param jose - Jose Instance
60
57
  * @param session - The JWT payload to be encoded in the session cookie
61
58
  * @returns The serialized session cookie string
62
59
  */
63
- declare const createSessionCookie: (session: JWTPayload, cookieOptions: CookieConfigInternal, jose: AuthRuntimeConfig["jose"]) => Promise<string>;
60
+ declare const createSessionCookie: (jose: AuthRuntimeConfig["jose"], session: JWTPayload) => Promise<string>;
64
61
  /**
65
62
  * Defines the cookie configuration based on the request security and cookie options passed
66
63
  * in the Aura Auth configuration (`createAuth` function). This function ensures the correct
@@ -69,25 +66,18 @@ declare const createSessionCookie: (session: JWTPayload, cookieOptions: CookieCo
69
66
  *
70
67
  * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto
71
68
  * @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
69
+ * @param useSecure Whether the request is secure (HTTPS)
70
+ * @param attributes The cookie attributes to be applied
71
+ * @param strategy The cookie strategy: "host", "secure", or "standard"
74
72
  * @returns The finalized cookie options to be used for setting cookies
75
73
  */
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;
74
+ declare const defineSecureCookieOptions: (useSecure: boolean, attributes: SerializeOptions, strategy: "host" | "secure" | "standard") => SerializeOptions;
85
75
  /**
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
76
+ * @param useSecure Whether the request is secure (HTTPS)
77
+ * @param prefix Optional prefix added to all cookie names
78
+ * @param overrides Optional overrides for individual cookie configurations
79
+ * @returns The complete cookie store configuration
90
80
  */
91
- declare const oauthCookie: (options: CookieConfigInternal) => CookieConfigInternal;
81
+ declare const createCookieStore: (useSecure: boolean, prefix?: string, overrides?: CookieConfig["overrides"]) => CookieStoreConfig;
92
82
 
93
- export { COOKIE_NAME, createSessionCookie, defaultCookieConfig, defaultCookieOptions, defaultHostCookieConfig, defaultSecureCookieConfig, defaultStandardCookieConfig, defineDefaultCookieOptions, expireCookie, expiredCookieOptions, getCookie, oauthCookie, secureCookieOptions, setCookie };
83
+ 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-IMICRJ5U.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,48 @@
1
+ import { E as ErrorType, b as AuthInternalErrorCode, c as AuthSecurityErrorCode } from './index-EqsoyjrF.js';
2
+ import { LiteralUnion } from './@types/utility.js';
3
+ import 'zod/v4';
4
+ import './schemas.js';
5
+ import '@aura-stack/router/cookie';
6
+ import '@aura-stack/jose/jose';
7
+
8
+ /**
9
+ * The object returned by the class to users its:
10
+ * - type: "OAUTH_PROTOCOL_ERROR" to identify the error type
11
+ * - error: A short error code
12
+ * - description: A human-readable description of the error. The description is obtained from the message property of the Error class
13
+ * - errorURI: A URI with more information about the error
14
+ */
15
+ declare class OAuthProtocolError extends Error {
16
+ readonly type = "OAUTH_PROTOCOL_ERROR";
17
+ readonly error: string;
18
+ readonly errorURI?: string;
19
+ constructor(error: LiteralUnion<Uppercase<ErrorType>>, description?: string, errorURI?: string, options?: ErrorOptions);
20
+ }
21
+ /**
22
+ * The object returned when an internal error occurs in the Aura Auth library.
23
+ * - type: "AUTH_INTERNAL_ERROR" to identify the error type
24
+ * - message: A human-readable description of the error. The description is obtained from the message property of the Error class
25
+ * - code: An optional error code that can be used to identify the specific error, for example, LIKE "ERR_AUTH_INTERNAL_ERROR"
26
+ */
27
+ declare class AuthInternalError extends Error {
28
+ readonly type = "AUTH_INTERNAL_ERROR";
29
+ readonly code: string;
30
+ constructor(code: AuthInternalErrorCode, message?: string, options?: ErrorOptions);
31
+ }
32
+ /**
33
+ * The object returned when a security error occurs in the Aura Auth library.
34
+ * - type: "AUTH_SECURITY_ERROR" to identify the error type
35
+ * - message: A human-readable description of the error. The description is obtained from the message property of the Error class
36
+ * - code: An optional error code that can be used to identify the specific error, for example, LIKE "ERR_AUTH_SECURITY_ERROR"
37
+ */
38
+ declare class AuthSecurityError extends Error {
39
+ readonly type = "AUTH_SECURITY_ERROR";
40
+ readonly code: string;
41
+ constructor(code: AuthSecurityErrorCode, message?: string, options?: ErrorOptions);
42
+ }
43
+ declare const isNativeError: (error: unknown) => error is Error;
44
+ declare const isOAuthProtocolError: (error: unknown) => error is OAuthProtocolError;
45
+ declare const isAuthInternalError: (error: unknown) => error is AuthInternalError;
46
+ declare const isAuthSecurityError: (error: unknown) => error is AuthSecurityError;
47
+
48
+ 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
+ };