@aura-stack/auth 0.1.0-rc.9 → 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 (140) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +6 -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 +6 -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 +159 -149
  10. package/dist/actions/callback/access-token.d.ts +14 -20
  11. package/dist/actions/callback/access-token.js +9 -4
  12. package/dist/actions/callback/callback.cjs +371 -484
  13. package/dist/actions/callback/callback.d.ts +9 -12
  14. package/dist/actions/callback/callback.js +15 -12
  15. package/dist/actions/callback/userinfo.cjs +149 -139
  16. package/dist/actions/callback/userinfo.d.ts +8 -9
  17. package/dist/actions/callback/userinfo.js +11 -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 +623 -807
  22. package/dist/actions/index.d.ts +12 -13
  23. package/dist/actions/index.js +33 -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 +248 -257
  28. package/dist/actions/signIn/authorization.d.ts +11 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +302 -451
  31. package/dist/actions/signIn/signIn.d.ts +9 -10
  32. package/dist/actions/signIn/signIn.js +12 -10
  33. package/dist/actions/signOut/signOut.cjs +299 -468
  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 +12 -4
  38. package/dist/assert.js +12 -2
  39. package/dist/chunk-2RXNXMCZ.js +55 -0
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-4V4JNXVF.js +55 -0
  42. package/dist/chunk-6R2YZ4AC.js +22 -0
  43. package/dist/chunk-7H3OR6UU.js +81 -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-FIPU4MLT.js +18 -16
  48. package/dist/chunk-FKRDCWBF.js +19 -17
  49. package/dist/chunk-IKHPGFCW.js +11 -9
  50. package/dist/chunk-IMICRJ5U.js +197 -0
  51. package/dist/chunk-IUYZQTJV.js +30 -0
  52. package/dist/chunk-KRNOMBXQ.js +19 -17
  53. package/dist/chunk-N2APGLXA.js +71 -0
  54. package/dist/chunk-NEVKX6K2.js +70 -0
  55. package/dist/chunk-PTJUYB33.js +33 -0
  56. package/dist/chunk-QDO2KSRJ.js +35 -0
  57. package/dist/chunk-QEZL7EYN.js +96 -0
  58. package/dist/chunk-RRLIF4PQ.js +55 -0
  59. package/dist/chunk-STHEPPUZ.js +8 -6
  60. package/dist/chunk-TLE4PXY3.js +39 -0
  61. package/dist/chunk-UEH3LVON.js +97 -0
  62. package/dist/chunk-WD7AUHQ5.js +79 -0
  63. package/dist/chunk-ZLR3LI6X.js +55 -0
  64. package/dist/cookie.cjs +222 -187
  65. package/dist/cookie.d.ts +38 -76
  66. package/dist/cookie.js +27 -34
  67. package/dist/errors.cjs +85 -0
  68. package/dist/errors.d.ts +48 -0
  69. package/dist/errors.js +18 -0
  70. package/dist/headers.cjs +28 -28
  71. package/dist/headers.d.ts +2 -2
  72. package/dist/headers.js +6 -2
  73. package/dist/{index-DpfbvTZ_.d.ts → index-EqsoyjrF.d.ts} +351 -318
  74. package/dist/index.cjs +1006 -1001
  75. package/dist/index.d.ts +9 -31
  76. package/dist/index.js +82 -51
  77. package/dist/jose.cjs +74 -66
  78. package/dist/jose.d.ts +11 -8
  79. package/dist/jose.js +10 -5
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +6 -7
  82. package/dist/oauth/bitbucket.js +6 -2
  83. package/dist/oauth/discord.cjs +47 -48
  84. package/dist/oauth/discord.d.ts +6 -7
  85. package/dist/oauth/discord.js +6 -2
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +6 -7
  88. package/dist/oauth/figma.js +6 -2
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +6 -7
  91. package/dist/oauth/github.js +6 -2
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +6 -7
  94. package/dist/oauth/gitlab.js +6 -2
  95. package/dist/oauth/index.cjs +306 -180
  96. package/dist/oauth/index.d.ts +6 -26
  97. package/dist/oauth/index.js +43 -9
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +6 -7
  100. package/dist/oauth/spotify.js +6 -2
  101. package/dist/oauth/strava.cjs +46 -0
  102. package/dist/oauth/strava.d.ts +6 -0
  103. package/dist/oauth/strava.js +6 -0
  104. package/dist/oauth/x.cjs +39 -39
  105. package/dist/oauth/x.d.ts +6 -7
  106. package/dist/oauth/x.js +6 -2
  107. package/dist/schemas.cjs +97 -91
  108. package/dist/schemas.d.ts +96 -126
  109. package/dist/schemas.js +20 -18
  110. package/dist/secure.cjs +106 -101
  111. package/dist/secure.d.ts +16 -17
  112. package/dist/secure.js +19 -4
  113. package/dist/utils.cjs +197 -135
  114. package/dist/utils.d.ts +20 -26
  115. package/dist/utils.js +25 -21
  116. package/package.json +5 -6
  117. package/dist/chunk-256KIVJL.js +0 -110
  118. package/dist/chunk-6SM22VVJ.js +0 -15
  119. package/dist/chunk-CAKJT3KS.js +0 -77
  120. package/dist/chunk-EBPE35JT.js +0 -29
  121. package/dist/chunk-FJUDBLCP.js +0 -52
  122. package/dist/chunk-GZU3RBTB.js +0 -51
  123. package/dist/chunk-HGJ4TXY4.js +0 -105
  124. package/dist/chunk-HMRKN75I.js +0 -74
  125. package/dist/chunk-JAPMIE6S.js +0 -8
  126. package/dist/chunk-LLR722CL.js +0 -75
  127. package/dist/chunk-RLT4RFKV.js +0 -36
  128. package/dist/chunk-SJPDVKUS.js +0 -93
  129. package/dist/chunk-SMQO5WD7.js +0 -20
  130. package/dist/chunk-UJJ7R56J.js +0 -42
  131. package/dist/chunk-UTDLUEEG.js +0 -25
  132. package/dist/chunk-VFTYH33W.js +0 -44
  133. package/dist/chunk-XXJKNKGQ.js +0 -27
  134. package/dist/chunk-ZV4BH47P.js +0 -156
  135. package/dist/error.cjs +0 -88
  136. package/dist/error.d.ts +0 -62
  137. package/dist/error.js +0 -9
  138. package/dist/response.cjs +0 -34
  139. package/dist/response.d.ts +0 -10
  140. package/dist/response.js +0 -2
package/dist/utils.cjs CHANGED
@@ -1,154 +1,216 @@
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/utils.ts
20
- var utils_exports = {}
21
+ var utils_exports = {};
21
22
  __export(utils_exports, {
22
- equals: () => equals,
23
- getNormalizedOriginPath: () => getNormalizedOriginPath,
24
- isValidRelativePath: () => isValidRelativePath,
25
- onErrorHandler: () => onErrorHandler,
26
- sanitizeURL: () => sanitizeURL,
27
- toCastCase: () => toCastCase,
28
- toISOString: () => toISOString,
29
- toSnakeCase: () => toSnakeCase,
30
- toUpperCase: () => toUpperCase,
31
- })
32
- module.exports = __toCommonJS(utils_exports)
33
- var import_router = require("@aura-stack/router")
23
+ equals: () => equals,
24
+ formatZodError: () => formatZodError,
25
+ getNormalizedOriginPath: () => getNormalizedOriginPath,
26
+ isValidRelativePath: () => isValidRelativePath,
27
+ onErrorHandler: () => onErrorHandler,
28
+ sanitizeURL: () => sanitizeURL,
29
+ toCastCase: () => toCastCase,
30
+ toISOString: () => toISOString,
31
+ toSnakeCase: () => toSnakeCase,
32
+ toUpperCase: () => toUpperCase,
33
+ useSecureCookies: () => useSecureCookies
34
+ });
35
+ module.exports = __toCommonJS(utils_exports);
36
+ var import_router = require("@aura-stack/router");
34
37
 
35
- // src/error.ts
36
- var AuthError = class extends Error {
37
- constructor(type, message) {
38
- super(message)
39
- this.type = type
40
- this.name = "AuthError"
41
- }
42
- }
43
- var isAuthError = (error) => {
44
- return error instanceof AuthError
45
- }
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);
49
+ }
50
+ };
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;
79
+ };
46
80
 
47
81
  // src/utils.ts
48
82
  var toSnakeCase = (str) => {
49
- return str
50
- .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
51
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
52
- .toLowerCase()
53
- .replace(/^_+/, "")
54
- }
83
+ return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
84
+ };
55
85
  var toUpperCase = (str) => {
56
- return str.toUpperCase()
57
- }
86
+ return str.toUpperCase();
87
+ };
58
88
  var toCastCase = (obj, type = "snake") => {
59
- return Object.entries(obj).reduce((previous, [key, value]) => {
60
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key)
61
- return { ...previous, [newKey]: value }
62
- }, {})
63
- }
89
+ return Object.entries(obj).reduce((previous, [key, value]) => {
90
+ const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
91
+ return { ...previous, [newKey]: value };
92
+ }, {});
93
+ };
64
94
  var equals = (a, b) => {
65
- if (a === null || b === null || a === void 0 || b === void 0) return false
66
- return a === b
67
- }
95
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
96
+ return a === b;
97
+ };
68
98
  var sanitizeURL = (url) => {
69
- try {
70
- let decodedURL = decodeURIComponent(url).trim()
71
- const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/)
72
- let protocol = ""
73
- let rest = decodedURL
74
- if (protocolMatch) {
75
- protocol = protocolMatch[1]
76
- rest = decodedURL.slice(protocol.length)
77
- const slashIndex = rest.indexOf("/")
78
- if (slashIndex === -1) {
79
- return protocol + rest
80
- }
81
- const domain = rest.slice(0, slashIndex)
82
- let path = rest
83
- .slice(slashIndex)
84
- .replace(/\/\.\.\//g, "/")
85
- .replace(/\/\.\.$/, "")
86
- .replace(/\.{2,}/g, "")
87
- .replace(/\/{2,}/g, "/")
88
- if (path !== "/" && path.endsWith("/")) {
89
- path = path.replace(/\/+$/, "/")
90
- } else if (path !== "/") {
91
- path = path.replace(/\/+$/, "")
92
- }
93
- return protocol + domain + path
94
- }
95
- let sanitized = decodedURL
96
- .replace(/\/\.\.\//g, "/")
97
- .replace(/\/\.\.$/, "")
98
- .replace(/\.{2,}/g, "")
99
- .replace(/\/{2,}/g, "/")
100
- if (sanitized !== "/" && sanitized.endsWith("/")) {
101
- sanitized = sanitized.replace(/\/+$/, "/")
102
- } else if (sanitized !== "/") {
103
- sanitized = sanitized.replace(/\/+$/, "")
104
- }
105
- return sanitized
106
- } catch {
107
- return url.trim()
99
+ try {
100
+ let decodedURL = decodeURIComponent(url).trim();
101
+ const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
102
+ let protocol = "";
103
+ let rest = decodedURL;
104
+ if (protocolMatch) {
105
+ protocol = protocolMatch[1];
106
+ rest = decodedURL.slice(protocol.length);
107
+ const slashIndex = rest.indexOf("/");
108
+ if (slashIndex === -1) {
109
+ return protocol + rest;
110
+ }
111
+ const domain = rest.slice(0, slashIndex);
112
+ let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
113
+ if (path !== "/" && path.endsWith("/")) {
114
+ path = path.replace(/\/+$/, "/");
115
+ } else if (path !== "/") {
116
+ path = path.replace(/\/+$/, "");
117
+ }
118
+ return protocol + domain + path;
119
+ }
120
+ let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
121
+ if (sanitized !== "/" && sanitized.endsWith("/")) {
122
+ sanitized = sanitized.replace(/\/+$/, "/");
123
+ } else if (sanitized !== "/") {
124
+ sanitized = sanitized.replace(/\/+$/, "");
108
125
  }
109
- }
126
+ return sanitized;
127
+ } catch {
128
+ return url.trim();
129
+ }
130
+ };
110
131
  var isValidRelativePath = (path) => {
111
- if (!path || typeof path !== "string") return false
112
- if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false
113
- if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false
114
- const sanitized = sanitizeURL(path)
115
- if (sanitized.includes("..")) return false
116
- return true
117
- }
132
+ if (!path || typeof path !== "string") return false;
133
+ if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
134
+ if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
135
+ const sanitized = sanitizeURL(path);
136
+ if (sanitized.includes("..")) return false;
137
+ return true;
138
+ };
118
139
  var onErrorHandler = (error) => {
119
- if ((0, import_router.isRouterError)(error)) {
120
- const { message, status, statusText } = error
121
- return Response.json({ error: "invalid_request", error_description: message }, { status, statusText })
122
- }
123
- if (isAuthError(error)) {
124
- const { type, message } = error
125
- return Response.json({ error: type, error_description: message }, { status: 400 })
126
- }
127
- return Response.json({ error: "server_error", error_description: "An unexpected error occurred" }, { status: 500 })
128
- }
140
+ if ((0, import_router.isRouterError)(error)) {
141
+ const { message, status, statusText } = error;
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 });
146
+ }
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
+ );
158
+ }
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 });
171
+ };
129
172
  var getNormalizedOriginPath = (path) => {
130
- try {
131
- const url = new URL(path)
132
- url.hash = ""
133
- url.search = ""
134
- return `${url.origin}${url.pathname}`
135
- } catch {
136
- return sanitizeURL(path)
137
- }
138
- }
173
+ try {
174
+ const url = new URL(path);
175
+ url.hash = "";
176
+ url.search = "";
177
+ return `${url.origin}${url.pathname}`;
178
+ } catch {
179
+ return sanitizeURL(path);
180
+ }
181
+ };
139
182
  var toISOString = (date) => {
140
- return new Date(date).toISOString()
141
- }
183
+ return new Date(date).toISOString();
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
+ };
142
203
  // Annotate the CommonJS export names for ESM import in node:
143
- 0 &&
144
- (module.exports = {
145
- equals,
146
- getNormalizedOriginPath,
147
- isValidRelativePath,
148
- onErrorHandler,
149
- sanitizeURL,
150
- toCastCase,
151
- toISOString,
152
- toSnakeCase,
153
- toUpperCase,
154
- })
204
+ 0 && (module.exports = {
205
+ equals,
206
+ formatZodError,
207
+ getNormalizedOriginPath,
208
+ isValidRelativePath,
209
+ onErrorHandler,
210
+ sanitizeURL,
211
+ toCastCase,
212
+ toISOString,
213
+ toSnakeCase,
214
+ toUpperCase,
215
+ useSecureCookies
216
+ });
package/dist/utils.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- import { RouterConfig } from "@aura-stack/router"
1
+ import { ZodError } from 'zod';
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
- declare const toSnakeCase: (str: string) => string
4
- declare const toUpperCase: (str: string) => string
5
- declare const toCastCase: <Obj extends Record<string, any>, Type extends "snake" | "upper">(
6
- obj: Obj,
7
- type?: Type
8
- ) => Type extends "snake"
9
- ? { [K in keyof Obj as `${string & K}`]: Obj[K] }
10
- : { [K in keyof Obj as Uppercase<string & K>]: Obj[K] }
11
- declare const equals: (a: string | number | undefined | null, b: string | number | undefined | null) => boolean
10
+ declare const toSnakeCase: (str: string) => string;
11
+ declare const toUpperCase: (str: string) => string;
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]; };
13
+ declare const equals: (a: string | number | undefined | null, b: string | number | undefined | null) => boolean;
12
14
  /**
13
15
  * Sanitizes a URL by removing dangerous patterns that could be used for path traversal
14
16
  * or other attacks. This function:
@@ -21,7 +23,7 @@ declare const equals: (a: string | number | undefined | null, b: string | number
21
23
  * @param url - The URL or path to sanitize
22
24
  * @returns The sanitized URL or path
23
25
  */
24
- declare const sanitizeURL: (url: string) => string
26
+ declare const sanitizeURL: (url: string) => string;
25
27
  /**
26
28
  * Validates that a path is a safe relative path to prevent open redirect attacks.
27
29
  * A safe relative path must:
@@ -34,8 +36,8 @@ declare const sanitizeURL: (url: string) => string
34
36
  * @param path - The path to validate
35
37
  * @returns true if the path is safe, false otherwise
36
38
  */
37
- declare const isValidRelativePath: (path: string | undefined | null) => boolean
38
- declare const onErrorHandler: RouterConfig["onError"]
39
+ declare const isValidRelativePath: (path: string | undefined | null) => boolean;
40
+ declare const onErrorHandler: RouterConfig["onError"];
39
41
  /**
40
42
  * Extracts and normalizes the origin and pathname from a URL string.
41
43
  * Removes query parameters and hash fragments for a clean path.
@@ -44,17 +46,9 @@ declare const onErrorHandler: RouterConfig["onError"]
44
46
  * @param path - The URL or path string to process
45
47
  * @returns The normalized URL with origin and pathname, or the original path
46
48
  */
47
- declare const getNormalizedOriginPath: (path: string) => string
48
- declare const toISOString: (date: Date | string | number) => string
49
+ declare const getNormalizedOriginPath: (path: string) => string;
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;
49
53
 
50
- export {
51
- equals,
52
- getNormalizedOriginPath,
53
- isValidRelativePath,
54
- onErrorHandler,
55
- sanitizeURL,
56
- toCastCase,
57
- toISOString,
58
- toSnakeCase,
59
- toUpperCase,
60
- }
54
+ export { equals, formatZodError, getNormalizedOriginPath, isValidRelativePath, onErrorHandler, sanitizeURL, toCastCase, toISOString, toSnakeCase, toUpperCase, useSecureCookies };
package/dist/utils.js CHANGED
@@ -1,23 +1,27 @@
1
1
  import {
2
- equals,
3
- getNormalizedOriginPath,
4
- isValidRelativePath,
5
- onErrorHandler,
6
- sanitizeURL,
7
- toCastCase,
8
- toISOString,
9
- toSnakeCase,
10
- toUpperCase,
11
- } from "./chunk-256KIVJL.js"
12
- import "./chunk-FJUDBLCP.js"
2
+ equals,
3
+ formatZodError,
4
+ getNormalizedOriginPath,
5
+ isValidRelativePath,
6
+ onErrorHandler,
7
+ sanitizeURL,
8
+ toCastCase,
9
+ toISOString,
10
+ toSnakeCase,
11
+ toUpperCase,
12
+ useSecureCookies
13
+ } from "./chunk-CXLATHS5.js";
14
+ import "./chunk-RRLIF4PQ.js";
13
15
  export {
14
- equals,
15
- getNormalizedOriginPath,
16
- isValidRelativePath,
17
- onErrorHandler,
18
- sanitizeURL,
19
- toCastCase,
20
- toISOString,
21
- toSnakeCase,
22
- toUpperCase,
23
- }
16
+ equals,
17
+ formatZodError,
18
+ getNormalizedOriginPath,
19
+ isValidRelativePath,
20
+ onErrorHandler,
21
+ sanitizeURL,
22
+ toCastCase,
23
+ toISOString,
24
+ toSnakeCase,
25
+ toUpperCase,
26
+ useSecureCookies
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aura-stack/auth",
3
- "version": "0.1.0-rc.9",
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-rc.1"
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,110 +0,0 @@
1
- import { isAuthError } from "./chunk-FJUDBLCP.js"
2
-
3
- // src/utils.ts
4
- import { isRouterError } from "@aura-stack/router"
5
- var toSnakeCase = (str) => {
6
- return str
7
- .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
8
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
9
- .toLowerCase()
10
- .replace(/^_+/, "")
11
- }
12
- var toUpperCase = (str) => {
13
- return str.toUpperCase()
14
- }
15
- var toCastCase = (obj, type = "snake") => {
16
- return Object.entries(obj).reduce((previous, [key, value]) => {
17
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key)
18
- return { ...previous, [newKey]: value }
19
- }, {})
20
- }
21
- var equals = (a, b) => {
22
- if (a === null || b === null || a === void 0 || b === void 0) return false
23
- return a === b
24
- }
25
- var sanitizeURL = (url) => {
26
- try {
27
- let decodedURL = decodeURIComponent(url).trim()
28
- const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/)
29
- let protocol = ""
30
- let rest = decodedURL
31
- if (protocolMatch) {
32
- protocol = protocolMatch[1]
33
- rest = decodedURL.slice(protocol.length)
34
- const slashIndex = rest.indexOf("/")
35
- if (slashIndex === -1) {
36
- return protocol + rest
37
- }
38
- const domain = rest.slice(0, slashIndex)
39
- let path = rest
40
- .slice(slashIndex)
41
- .replace(/\/\.\.\//g, "/")
42
- .replace(/\/\.\.$/, "")
43
- .replace(/\.{2,}/g, "")
44
- .replace(/\/{2,}/g, "/")
45
- if (path !== "/" && path.endsWith("/")) {
46
- path = path.replace(/\/+$/, "/")
47
- } else if (path !== "/") {
48
- path = path.replace(/\/+$/, "")
49
- }
50
- return protocol + domain + path
51
- }
52
- let sanitized = decodedURL
53
- .replace(/\/\.\.\//g, "/")
54
- .replace(/\/\.\.$/, "")
55
- .replace(/\.{2,}/g, "")
56
- .replace(/\/{2,}/g, "/")
57
- if (sanitized !== "/" && sanitized.endsWith("/")) {
58
- sanitized = sanitized.replace(/\/+$/, "/")
59
- } else if (sanitized !== "/") {
60
- sanitized = sanitized.replace(/\/+$/, "")
61
- }
62
- return sanitized
63
- } catch {
64
- return url.trim()
65
- }
66
- }
67
- var isValidRelativePath = (path) => {
68
- if (!path || typeof path !== "string") return false
69
- if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false
70
- if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false
71
- const sanitized = sanitizeURL(path)
72
- if (sanitized.includes("..")) return false
73
- return true
74
- }
75
- var onErrorHandler = (error) => {
76
- if (isRouterError(error)) {
77
- const { message, status, statusText } = error
78
- return Response.json({ error: "invalid_request", error_description: message }, { status, statusText })
79
- }
80
- if (isAuthError(error)) {
81
- const { type, message } = error
82
- return Response.json({ error: type, error_description: message }, { status: 400 })
83
- }
84
- return Response.json({ error: "server_error", error_description: "An unexpected error occurred" }, { status: 500 })
85
- }
86
- var getNormalizedOriginPath = (path) => {
87
- try {
88
- const url = new URL(path)
89
- url.hash = ""
90
- url.search = ""
91
- return `${url.origin}${url.pathname}`
92
- } catch {
93
- return sanitizeURL(path)
94
- }
95
- }
96
- var toISOString = (date) => {
97
- return new Date(date).toISOString()
98
- }
99
-
100
- export {
101
- toSnakeCase,
102
- toUpperCase,
103
- toCastCase,
104
- equals,
105
- sanitizeURL,
106
- isValidRelativePath,
107
- onErrorHandler,
108
- getNormalizedOriginPath,
109
- toISOString,
110
- }
@@ -1,15 +0,0 @@
1
- // src/assert.ts
2
- var isFalsy = (value) => {
3
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value)
4
- }
5
- var isRequest = (value) => {
6
- return typeof Request !== "undefined" && value instanceof Request
7
- }
8
- var isValidURL = (value) => {
9
- if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
10
- const regex =
11
- /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
12
- return regex.test(value)
13
- }
14
-
15
- export { isFalsy, isRequest, isValidURL }