@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/schemas.d.ts CHANGED
@@ -1,63 +1,62 @@
1
- import * as zod_v4_core from 'zod/v4/core';
2
- import * as zod_v4 from 'zod/v4';
1
+ import { z } from 'zod/v4';
3
2
 
4
3
  /**
5
4
  * Schema for OAuth Provider Configuration
6
5
  */
7
- declare const OAuthProviderConfigSchema: zod_v4.ZodObject<{
8
- authorizeURL: zod_v4.ZodURL;
9
- accessToken: zod_v4.ZodURL;
10
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
11
- userInfo: zod_v4.ZodURL;
12
- responseType: zod_v4.ZodEnum<{
13
- token: "token";
6
+ declare const OAuthProviderConfigSchema: z.ZodObject<{
7
+ authorizeURL: z.ZodURL;
8
+ accessToken: z.ZodURL;
9
+ scope: z.ZodOptional<z.ZodString>;
10
+ userInfo: z.ZodURL;
11
+ responseType: z.ZodEnum<{
14
12
  code: "code";
13
+ token: "token";
15
14
  id_token: "id_token";
16
15
  }>;
17
- clientId: zod_v4.ZodString;
18
- clientSecret: zod_v4.ZodString;
19
- }, zod_v4_core.$strip>;
16
+ clientId: z.ZodString;
17
+ clientSecret: z.ZodString;
18
+ }, z.core.$strip>;
20
19
  /**
21
20
  * Schema used to create the authorization URL for the OAuth flow and verify the
22
21
  * OAuth configuration.
23
22
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
24
23
  */
25
- declare const OAuthAuthorization: zod_v4.ZodObject<{
26
- authorizeURL: zod_v4.ZodURL;
27
- accessToken: zod_v4.ZodURL;
28
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
29
- userInfo: zod_v4.ZodURL;
30
- responseType: zod_v4.ZodEnum<{
31
- token: "token";
24
+ declare const OAuthAuthorization: z.ZodObject<{
25
+ authorizeURL: z.ZodURL;
26
+ accessToken: z.ZodURL;
27
+ scope: z.ZodOptional<z.ZodString>;
28
+ userInfo: z.ZodURL;
29
+ responseType: z.ZodEnum<{
32
30
  code: "code";
31
+ token: "token";
33
32
  id_token: "id_token";
34
33
  }>;
35
- clientId: zod_v4.ZodString;
36
- clientSecret: zod_v4.ZodString;
37
- redirectURI: zod_v4.ZodString;
38
- state: zod_v4.ZodString;
39
- codeChallenge: zod_v4.ZodString;
40
- codeChallengeMethod: zod_v4.ZodEnum<{
41
- S256: "S256";
34
+ clientId: z.ZodString;
35
+ clientSecret: z.ZodString;
36
+ redirectURI: z.ZodString;
37
+ state: z.ZodString;
38
+ codeChallenge: z.ZodString;
39
+ codeChallengeMethod: z.ZodEnum<{
42
40
  plain: "plain";
41
+ S256: "S256";
43
42
  }>;
44
- }, zod_v4_core.$strip>;
43
+ }, z.core.$strip>;
45
44
  /**
46
45
  * Schema used in the callback action to validate the authorization response when the resource owner
47
46
  * has granted.
48
47
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2
49
48
  */
50
- declare const OAuthAuthorizationResponse: zod_v4.ZodObject<{
51
- state: zod_v4.ZodString;
52
- code: zod_v4.ZodString;
53
- }, zod_v4_core.$strip>;
49
+ declare const OAuthAuthorizationResponse: z.ZodObject<{
50
+ state: z.ZodString;
51
+ code: z.ZodString;
52
+ }, z.core.$strip>;
54
53
  /**
55
54
  * Schema used in the callback action to validate the authorization error response when the resource owner
56
55
  * has denied the authorization request.
57
56
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
58
57
  */
59
- declare const OAuthAuthorizationErrorResponse: zod_v4.ZodObject<{
60
- error: zod_v4.ZodEnum<{
58
+ declare const OAuthAuthorizationErrorResponse: z.ZodObject<{
59
+ error: z.ZodEnum<{
61
60
  invalid_request: "invalid_request";
62
61
  unauthorized_client: "unauthorized_client";
63
62
  access_denied: "access_denied";
@@ -66,48 +65,48 @@ declare const OAuthAuthorizationErrorResponse: zod_v4.ZodObject<{
66
65
  server_error: "server_error";
67
66
  temporarily_unavailable: "temporarily_unavailable";
68
67
  }>;
69
- error_description: zod_v4.ZodOptional<zod_v4.ZodString>;
70
- error_uri: zod_v4.ZodOptional<zod_v4.ZodString>;
71
- state: zod_v4.ZodString;
72
- }, zod_v4_core.$strip>;
68
+ error_description: z.ZodOptional<z.ZodString>;
69
+ error_uri: z.ZodOptional<z.ZodString>;
70
+ state: z.ZodString;
71
+ }, z.core.$strip>;
73
72
  /**
74
73
  * Schema for OAuth Access Token Request and OAuth Configuration
75
74
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3
76
75
  */
77
- declare const OAuthAccessToken: zod_v4.ZodObject<{
78
- authorizeURL: zod_v4.ZodURL;
79
- accessToken: zod_v4.ZodURL;
80
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
81
- userInfo: zod_v4.ZodURL;
82
- responseType: zod_v4.ZodEnum<{
83
- token: "token";
76
+ declare const OAuthAccessToken: z.ZodObject<{
77
+ authorizeURL: z.ZodURL;
78
+ accessToken: z.ZodURL;
79
+ scope: z.ZodOptional<z.ZodString>;
80
+ userInfo: z.ZodURL;
81
+ responseType: z.ZodEnum<{
84
82
  code: "code";
83
+ token: "token";
85
84
  id_token: "id_token";
86
85
  }>;
87
- clientId: zod_v4.ZodString;
88
- clientSecret: zod_v4.ZodString;
89
- redirectURI: zod_v4.ZodString;
90
- code: zod_v4.ZodString;
91
- codeVerifier: zod_v4.ZodString;
92
- }, zod_v4_core.$strip>;
86
+ clientId: z.ZodString;
87
+ clientSecret: z.ZodString;
88
+ redirectURI: z.ZodString;
89
+ code: z.ZodString;
90
+ codeVerifier: z.ZodString;
91
+ }, z.core.$strip>;
93
92
  /**
94
93
  * Schema for OAuth Access Token Response
95
94
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
96
95
  * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4
97
96
  */
98
- declare const OAuthAccessTokenResponse: zod_v4.ZodObject<{
99
- access_token: zod_v4.ZodString;
100
- token_type: zod_v4.ZodString;
101
- expires_in: zod_v4.ZodOptional<zod_v4.ZodNumber>;
102
- refresh_token: zod_v4.ZodOptional<zod_v4.ZodString>;
103
- scope: zod_v4.ZodOptional<zod_v4.ZodString>;
104
- }, zod_v4_core.$strip>;
97
+ declare const OAuthAccessTokenResponse: z.ZodObject<{
98
+ access_token: z.ZodString;
99
+ token_type: z.ZodString;
100
+ expires_in: z.ZodOptional<z.ZodNumber>;
101
+ refresh_token: z.ZodOptional<z.ZodString>;
102
+ scope: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$strip>;
105
104
  /**
106
105
  * Schema for OAuth Access Token Error Response
107
106
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
108
107
  */
109
- declare const OAuthAccessTokenErrorResponse: zod_v4.ZodObject<{
110
- error: zod_v4.ZodEnum<{
108
+ declare const OAuthAccessTokenErrorResponse: z.ZodObject<{
109
+ error: z.ZodEnum<{
111
110
  invalid_request: "invalid_request";
112
111
  unauthorized_client: "unauthorized_client";
113
112
  invalid_scope: "invalid_scope";
@@ -115,16 +114,20 @@ declare const OAuthAccessTokenErrorResponse: zod_v4.ZodObject<{
115
114
  invalid_grant: "invalid_grant";
116
115
  unsupported_grant_type: "unsupported_grant_type";
117
116
  }>;
118
- error_description: zod_v4.ZodOptional<zod_v4.ZodString>;
119
- error_uri: zod_v4.ZodOptional<zod_v4.ZodString>;
120
- }, zod_v4_core.$strip>;
117
+ error_description: z.ZodOptional<z.ZodString>;
118
+ error_uri: z.ZodOptional<z.ZodString>;
119
+ }, z.core.$strip>;
121
120
  /**
122
121
  * @todo: verify if this schema is still needed
123
122
  * @deprecated
124
123
  */
125
- declare const OAuthErrorResponse: zod_v4.ZodObject<{
126
- error: zod_v4.ZodString;
127
- error_description: zod_v4.ZodOptional<zod_v4.ZodString>;
128
- }, zod_v4_core.$strip>;
124
+ declare const OAuthErrorResponse: z.ZodObject<{
125
+ error: z.ZodString;
126
+ error_description: z.ZodOptional<z.ZodString>;
127
+ }, z.core.$strip>;
128
+ declare const OAuthEnvSchema: z.ZodObject<{
129
+ clientId: z.ZodString;
130
+ clientSecret: z.ZodString;
131
+ }, z.core.$strip>;
129
132
 
130
- export { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse, OAuthAuthorization, OAuthAuthorizationErrorResponse, OAuthAuthorizationResponse, OAuthErrorResponse, OAuthProviderConfigSchema };
133
+ export { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse, OAuthAuthorization, OAuthAuthorizationErrorResponse, OAuthAuthorizationResponse, OAuthEnvSchema, OAuthErrorResponse, OAuthProviderConfigSchema };
package/dist/schemas.js CHANGED
@@ -5,9 +5,10 @@ import {
5
5
  OAuthAuthorization,
6
6
  OAuthAuthorizationErrorResponse,
7
7
  OAuthAuthorizationResponse,
8
+ OAuthEnvSchema,
8
9
  OAuthErrorResponse,
9
10
  OAuthProviderConfigSchema
10
- } from "./chunk-HMRKN75I.js";
11
+ } from "./chunk-WD7AUHQ5.js";
11
12
  export {
12
13
  OAuthAccessToken,
13
14
  OAuthAccessTokenErrorResponse,
@@ -15,6 +16,7 @@ export {
15
16
  OAuthAuthorization,
16
17
  OAuthAuthorizationErrorResponse,
17
18
  OAuthAuthorizationResponse,
19
+ OAuthEnvSchema,
18
20
  OAuthErrorResponse,
19
21
  OAuthProviderConfigSchema
20
22
  };
package/dist/secure.cjs CHANGED
@@ -43,18 +43,15 @@ var import_node_crypto = __toESM(require("crypto"), 1);
43
43
  // src/utils.ts
44
44
  var import_router = require("@aura-stack/router");
45
45
 
46
- // src/error.ts
47
- var AuthError = class extends Error {
48
- constructor(type, message) {
49
- super(message);
50
- this.type = type;
51
- this.name = "AuthError";
52
- }
53
- };
54
- var InvalidCsrfTokenError = class extends AuthError {
55
- constructor(message = "The provided CSRF token is invalid or has expired") {
56
- super("invalid_csrf_token", message);
57
- this.name = "InvalidCsrfTokenError";
46
+ // src/errors.ts
47
+ var AuthSecurityError = class extends Error {
48
+ type = "AUTH_SECURITY_ERROR";
49
+ code;
50
+ constructor(code, message, options) {
51
+ super(message, options);
52
+ this.code = code;
53
+ this.name = new.target.name;
54
+ Error.captureStackTrace(this, new.target);
58
55
  }
59
56
  };
60
57
 
@@ -64,6 +61,11 @@ var equals = (a, b) => {
64
61
  return a === b;
65
62
  };
66
63
 
64
+ // src/assert.ts
65
+ var isJWTPayloadWithToken = (payload) => {
66
+ return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
67
+ };
68
+
67
69
  // src/secure.ts
68
70
  var generateSecure = (length = 32) => {
69
71
  return import_node_crypto.default.randomBytes(length).toString("base64url");
@@ -91,19 +93,25 @@ var createCSRF = async (jose, csrfCookie) => {
91
93
  };
92
94
  var verifyCSRF = async (jose, cookie, header) => {
93
95
  try {
94
- const { token: cookieToken } = await jose.verifyJWS(cookie);
95
- const { token: headerToken } = await jose.verifyJWS(header);
96
- const cookieBuffer = Buffer.from(cookieToken);
97
- const headerBuffer = Buffer.from(headerToken);
96
+ const cookiePayload = await jose.verifyJWS(cookie);
97
+ const headerPayload = await jose.verifyJWS(header);
98
+ if (!isJWTPayloadWithToken(cookiePayload)) {
99
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
100
+ }
101
+ if (!isJWTPayloadWithToken(headerPayload)) {
102
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
103
+ }
104
+ const cookieBuffer = Buffer.from(cookiePayload.token);
105
+ const headerBuffer = Buffer.from(headerPayload.token);
98
106
  if (!equals(headerBuffer.length, cookieBuffer.length)) {
99
- throw new InvalidCsrfTokenError();
107
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
100
108
  }
101
109
  if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
102
- throw new InvalidCsrfTokenError();
110
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
103
111
  }
104
112
  return true;
105
113
  } catch {
106
- throw new InvalidCsrfTokenError();
114
+ throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
107
115
  }
108
116
  };
109
117
  var createDerivedSalt = (secret) => {
package/dist/secure.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { A as AuthRuntimeConfig } from './index-DpfbvTZ_.js';
1
+ import { A as AuthRuntimeConfig } from './index-EqsoyjrF.js';
2
2
  import 'zod/v4';
3
- import '@aura-stack/jose/jose';
4
3
  import './schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose/jose';
7
6
  import './@types/utility.js';
8
7
 
9
8
  declare const generateSecure: (length?: number) => string;
package/dist/secure.js CHANGED
@@ -5,9 +5,10 @@ import {
5
5
  createPKCE,
6
6
  generateSecure,
7
7
  verifyCSRF
8
- } from "./chunk-GZU3RBTB.js";
9
- import "./chunk-256KIVJL.js";
10
- import "./chunk-FJUDBLCP.js";
8
+ } from "./chunk-N2APGLXA.js";
9
+ import "./chunk-CXLATHS5.js";
10
+ import "./chunk-EIL2FPSS.js";
11
+ import "./chunk-RRLIF4PQ.js";
11
12
  export {
12
13
  createCSRF,
13
14
  createDerivedSalt,
package/dist/utils.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
23
  equals: () => equals,
24
+ formatZodError: () => formatZodError,
24
25
  getNormalizedOriginPath: () => getNormalizedOriginPath,
25
26
  isValidRelativePath: () => isValidRelativePath,
26
27
  onErrorHandler: () => onErrorHandler,
@@ -28,21 +29,53 @@ __export(utils_exports, {
28
29
  toCastCase: () => toCastCase,
29
30
  toISOString: () => toISOString,
30
31
  toSnakeCase: () => toSnakeCase,
31
- toUpperCase: () => toUpperCase
32
+ toUpperCase: () => toUpperCase,
33
+ useSecureCookies: () => useSecureCookies
32
34
  });
33
35
  module.exports = __toCommonJS(utils_exports);
34
36
  var import_router = require("@aura-stack/router");
35
37
 
36
- // src/error.ts
37
- var AuthError = class extends Error {
38
- constructor(type, message) {
39
- super(message);
40
- this.type = type;
41
- this.name = "AuthError";
38
+ // src/errors.ts
39
+ var OAuthProtocolError = class extends Error {
40
+ type = "OAUTH_PROTOCOL_ERROR";
41
+ error;
42
+ errorURI;
43
+ constructor(error, description, errorURI, options) {
44
+ super(description, options);
45
+ this.error = error;
46
+ this.errorURI = errorURI;
47
+ this.name = new.target.name;
48
+ Error.captureStackTrace(this, new.target);
42
49
  }
43
50
  };
44
- var isAuthError = (error) => {
45
- return error instanceof AuthError;
51
+ var AuthInternalError = class extends Error {
52
+ type = "AUTH_INTERNAL_ERROR";
53
+ code;
54
+ constructor(code, message, options) {
55
+ super(message, options);
56
+ this.code = code;
57
+ this.name = new.target.name;
58
+ Error.captureStackTrace(this, new.target);
59
+ }
60
+ };
61
+ var AuthSecurityError = class extends Error {
62
+ type = "AUTH_SECURITY_ERROR";
63
+ code;
64
+ constructor(code, message, options) {
65
+ super(message, options);
66
+ this.code = code;
67
+ this.name = new.target.name;
68
+ Error.captureStackTrace(this, new.target);
69
+ }
70
+ };
71
+ var isOAuthProtocolError = (error) => {
72
+ return error instanceof OAuthProtocolError;
73
+ };
74
+ var isAuthInternalError = (error) => {
75
+ return error instanceof AuthInternalError;
76
+ };
77
+ var isAuthSecurityError = (error) => {
78
+ return error instanceof AuthSecurityError;
46
79
  };
47
80
 
48
81
  // src/utils.ts
@@ -106,13 +139,35 @@ var isValidRelativePath = (path) => {
106
139
  var onErrorHandler = (error) => {
107
140
  if ((0, import_router.isRouterError)(error)) {
108
141
  const { message, status, statusText } = error;
109
- return Response.json({ error: "invalid_request", error_description: message }, { status, statusText });
142
+ return Response.json({ type: "ROUTER_ERROR", code: "ROUTER_INTERNAL_ERROR", message }, { status, statusText });
143
+ }
144
+ if ((0, import_router.isInvalidZodSchemaError)(error)) {
145
+ return Response.json({ type: "ROUTER_ERROR", code: "INVALID_REQUEST", message: error.errors }, { status: 422 });
110
146
  }
111
- if (isAuthError(error)) {
112
- const { type, message } = error;
113
- return Response.json({ error: type, error_description: message }, { status: 400 });
147
+ if (isOAuthProtocolError(error)) {
148
+ const { error: errorCode, message, type, errorURI } = error;
149
+ return Response.json(
150
+ {
151
+ type,
152
+ error: errorCode,
153
+ error_description: message,
154
+ error_uri: errorURI
155
+ },
156
+ { status: 400 }
157
+ );
114
158
  }
115
- return Response.json({ error: "server_error", error_description: "An unexpected error occurred" }, { status: 500 });
159
+ if (isAuthInternalError(error) || isAuthSecurityError(error)) {
160
+ const { type, code, message } = error;
161
+ return Response.json(
162
+ {
163
+ type,
164
+ code,
165
+ message
166
+ },
167
+ { status: 400 }
168
+ );
169
+ }
170
+ return Response.json({ type: "SERVER_ERROR", code: "server_error", message: "An unexpected error occurred" }, { status: 500 });
116
171
  };
117
172
  var getNormalizedOriginPath = (path) => {
118
173
  try {
@@ -127,9 +182,28 @@ var getNormalizedOriginPath = (path) => {
127
182
  var toISOString = (date) => {
128
183
  return new Date(date).toISOString();
129
184
  };
185
+ var useSecureCookies = (request, trustedProxyHeaders) => {
186
+ return trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || (request.headers.get("Forwarded")?.includes("proto=https") ?? false) : request.url.startsWith("https://");
187
+ };
188
+ var formatZodError = (error) => {
189
+ if (!error.issues || error.issues.length === 0) {
190
+ return {};
191
+ }
192
+ return error.issues.reduce((previous, issue) => {
193
+ const key = issue.path.join(".");
194
+ return {
195
+ ...previous,
196
+ [key]: {
197
+ code: issue.code,
198
+ message: issue.message
199
+ }
200
+ };
201
+ }, {});
202
+ };
130
203
  // Annotate the CommonJS export names for ESM import in node:
131
204
  0 && (module.exports = {
132
205
  equals,
206
+ formatZodError,
133
207
  getNormalizedOriginPath,
134
208
  isValidRelativePath,
135
209
  onErrorHandler,
@@ -137,5 +211,6 @@ var toISOString = (date) => {
137
211
  toCastCase,
138
212
  toISOString,
139
213
  toSnakeCase,
140
- toUpperCase
214
+ toUpperCase,
215
+ useSecureCookies
141
216
  });
package/dist/utils.d.ts CHANGED
@@ -1,8 +1,15 @@
1
+ import { ZodError } from 'zod';
1
2
  import { RouterConfig } from '@aura-stack/router';
3
+ import { i as APIErrorMap } from './index-EqsoyjrF.js';
4
+ import 'zod/v4';
5
+ import './schemas.js';
6
+ import '@aura-stack/router/cookie';
7
+ import '@aura-stack/jose/jose';
8
+ import './@types/utility.js';
2
9
 
3
10
  declare const toSnakeCase: (str: string) => string;
4
11
  declare const toUpperCase: (str: string) => string;
5
- declare const toCastCase: <Obj extends Record<string, any>, Type extends "snake" | "upper">(obj: Obj, type?: Type) => Type extends "snake" ? { [K in keyof Obj as `${string & K}`]: Obj[K]; } : { [K in keyof Obj as Uppercase<string & K>]: Obj[K]; };
12
+ declare const toCastCase: <Obj extends Record<string, string>, Type extends "snake" | "upper">(obj: Obj, type?: Type) => Type extends "snake" ? { [K in keyof Obj as `${string & K}`]: Obj[K]; } : { [K in keyof Obj as Uppercase<string & K>]: Obj[K]; };
6
13
  declare const equals: (a: string | number | undefined | null, b: string | number | undefined | null) => boolean;
7
14
  /**
8
15
  * Sanitizes a URL by removing dangerous patterns that could be used for path traversal
@@ -41,5 +48,7 @@ declare const onErrorHandler: RouterConfig["onError"];
41
48
  */
42
49
  declare const getNormalizedOriginPath: (path: string) => string;
43
50
  declare const toISOString: (date: Date | string | number) => string;
51
+ declare const useSecureCookies: (request: Request, trustedProxyHeaders: boolean) => boolean;
52
+ declare const formatZodError: <T extends Record<string, unknown> = Record<string, unknown>>(error: ZodError<T>) => APIErrorMap;
44
53
 
45
- export { equals, getNormalizedOriginPath, isValidRelativePath, onErrorHandler, sanitizeURL, toCastCase, toISOString, toSnakeCase, toUpperCase };
54
+ export { equals, formatZodError, getNormalizedOriginPath, isValidRelativePath, onErrorHandler, sanitizeURL, toCastCase, toISOString, toSnakeCase, toUpperCase, useSecureCookies };
package/dist/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  equals,
3
+ formatZodError,
3
4
  getNormalizedOriginPath,
4
5
  isValidRelativePath,
5
6
  onErrorHandler,
@@ -7,11 +8,13 @@ import {
7
8
  toCastCase,
8
9
  toISOString,
9
10
  toSnakeCase,
10
- toUpperCase
11
- } from "./chunk-256KIVJL.js";
12
- import "./chunk-FJUDBLCP.js";
11
+ toUpperCase,
12
+ useSecureCookies
13
+ } from "./chunk-CXLATHS5.js";
14
+ import "./chunk-RRLIF4PQ.js";
13
15
  export {
14
16
  equals,
17
+ formatZodError,
15
18
  getNormalizedOriginPath,
16
19
  isValidRelativePath,
17
20
  onErrorHandler,
@@ -19,5 +22,6 @@ export {
19
22
  toCastCase,
20
23
  toISOString,
21
24
  toSnakeCase,
22
- toUpperCase
25
+ toUpperCase,
26
+ useSecureCookies
23
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aura-stack/auth",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Core auth for @aura-stack/auth",
@@ -44,15 +44,14 @@
44
44
  },
45
45
  "license": "MIT",
46
46
  "dependencies": {
47
- "@aura-stack/router": "^0.4.0",
48
- "cookie": "^1.0.2",
47
+ "@aura-stack/router": "^0.5.0",
49
48
  "dotenv": "^17.2.3",
50
49
  "zod": "^4.1.12",
51
- "@aura-stack/jose": "0.1.0"
50
+ "@aura-stack/jose": "0.2.0"
52
51
  },
53
52
  "devDependencies": {
54
- "@aura-stack/tsconfig": "0.0.0",
55
- "@aura-stack/tsup-config": "0.0.0"
53
+ "@aura-stack/tsup-config": "0.0.0",
54
+ "@aura-stack/tsconfig": "0.0.0"
56
55
  },
57
56
  "scripts": {
58
57
  "dev": "tsup --watch",
@@ -1,59 +0,0 @@
1
- // src/error.ts
2
- var AuthError = class extends Error {
3
- constructor(type, message) {
4
- super(message);
5
- this.type = type;
6
- this.name = "AuthError";
7
- }
8
- };
9
- var InvalidCsrfTokenError = class extends AuthError {
10
- constructor(message = "The provided CSRF token is invalid or has expired") {
11
- super("invalid_csrf_token", message);
12
- this.name = "InvalidCsrfTokenError";
13
- }
14
- };
15
- var InvalidRedirectToError = class extends AuthError {
16
- constructor(message = "The redirectTo parameter does not match the hosted origin.") {
17
- super("invalid_redirect_to", message);
18
- this.name = "InvalidRedirectToError";
19
- }
20
- };
21
- var isAuthError = (error) => {
22
- return error instanceof AuthError;
23
- };
24
- var throwAuthError = (error, message) => {
25
- if (error instanceof Error) {
26
- if (isAuthError(error)) {
27
- throw error;
28
- }
29
- throw new AuthError("invalid_request", error.message ?? message);
30
- }
31
- };
32
- var ERROR_RESPONSE = {
33
- AUTHORIZATION: {
34
- INVALID_REQUEST: "invalid_request",
35
- UNAUTHORIZED_CLIENT: "unauthorized_client",
36
- ACCESS_DENIED: "access_denied",
37
- UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
38
- INVALID_SCOPE: "invalid_scope",
39
- SERVER_ERROR: "server_error",
40
- TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
41
- },
42
- ACCESS_TOKEN: {
43
- INVALID_REQUEST: "invalid_request",
44
- INVALID_CLIENT: "invalid_client",
45
- INVALID_GRANT: "invalid_grant",
46
- UNAUTHORIZED_CLIENT: "unauthorized_client",
47
- UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
48
- INVALID_SCOPE: "invalid_scope"
49
- }
50
- };
51
-
52
- export {
53
- AuthError,
54
- InvalidCsrfTokenError,
55
- InvalidRedirectToError,
56
- isAuthError,
57
- throwAuthError,
58
- ERROR_RESPONSE
59
- };