@aura-stack/auth 0.1.0-rc.7 → 0.1.0-rc.9

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 (117) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +31 -7
  3. package/dist/@types/index.js +1 -1
  4. package/dist/@types/router.d.cjs +1 -1
  5. package/dist/@types/router.d.d.ts +7 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +6 -6
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +143 -143
  10. package/dist/actions/callback/access-token.d.ts +20 -15
  11. package/dist/actions/callback/access-token.js +4 -8
  12. package/dist/actions/callback/callback.cjs +455 -437
  13. package/dist/actions/callback/callback.d.ts +12 -10
  14. package/dist/actions/callback/callback.js +12 -16
  15. package/dist/actions/callback/userinfo.cjs +134 -131
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +6 -10
  18. package/dist/actions/csrfToken/csrfToken.cjs +171 -162
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +8 -12
  21. package/dist/actions/index.cjs +773 -746
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +18 -34
  24. package/dist/actions/session/session.cjs +155 -149
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +7 -11
  27. package/dist/actions/signIn/authorization.cjs +249 -231
  28. package/dist/actions/signIn/authorization.d.ts +18 -12
  29. package/dist/actions/signIn/authorization.js +6 -16
  30. package/dist/actions/signIn/signIn.cjs +423 -396
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +10 -14
  33. package/dist/actions/signOut/signOut.cjs +440 -417
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +11 -15
  36. package/dist/assert.cjs +36 -35
  37. package/dist/assert.d.ts +4 -4
  38. package/dist/assert.js +2 -10
  39. package/dist/chunk-256KIVJL.js +96 -85
  40. package/dist/chunk-42XB3YCW.js +17 -19
  41. package/dist/chunk-6SM22VVJ.js +10 -13
  42. package/dist/chunk-CAKJT3KS.js +69 -84
  43. package/dist/chunk-E3OXBRYF.js +17 -19
  44. package/dist/chunk-EBPE35JT.js +26 -28
  45. package/dist/chunk-FIPU4MLT.js +16 -18
  46. package/dist/chunk-FJUDBLCP.js +43 -50
  47. package/dist/chunk-FKRDCWBF.js +17 -19
  48. package/dist/chunk-GZU3RBTB.js +40 -51
  49. package/dist/chunk-HGJ4TXY4.js +100 -132
  50. package/dist/chunk-HMRKN75I.js +63 -63
  51. package/dist/chunk-IKHPGFCW.js +9 -11
  52. package/dist/chunk-JAPMIE6S.js +5 -7
  53. package/dist/chunk-KRNOMBXQ.js +17 -19
  54. package/dist/chunk-LLR722CL.js +70 -91
  55. package/dist/chunk-RLT4RFKV.js +30 -39
  56. package/dist/chunk-SJPDVKUS.js +88 -107
  57. package/dist/chunk-SMQO5WD7.js +16 -26
  58. package/dist/chunk-STHEPPUZ.js +6 -8
  59. package/dist/chunk-UJJ7R56J.js +37 -47
  60. package/dist/chunk-UTDLUEEG.js +25 -0
  61. package/dist/chunk-VFTYH33W.js +37 -54
  62. package/dist/chunk-XXJKNKGQ.js +23 -33
  63. package/dist/chunk-ZV4BH47P.js +134 -132
  64. package/dist/cookie.cjs +175 -169
  65. package/dist/cookie.d.ts +51 -23
  66. package/dist/cookie.js +34 -34
  67. package/dist/error.cjs +75 -75
  68. package/dist/error.d.ts +30 -30
  69. package/dist/error.js +8 -15
  70. package/dist/headers.cjs +28 -28
  71. package/dist/headers.d.ts +2 -2
  72. package/dist/headers.js +2 -6
  73. package/dist/index-DpfbvTZ_.d.ts +298 -249
  74. package/dist/index.cjs +969 -933
  75. package/dist/index.d.ts +31 -10
  76. package/dist/index.js +50 -70
  77. package/dist/jose.cjs +67 -52
  78. package/dist/jose.d.ts +8 -8
  79. package/dist/jose.js +5 -9
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +7 -7
  82. package/dist/oauth/bitbucket.js +2 -6
  83. package/dist/oauth/discord.cjs +48 -48
  84. package/dist/oauth/discord.d.ts +7 -7
  85. package/dist/oauth/discord.js +2 -6
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +7 -7
  88. package/dist/oauth/figma.js +2 -6
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +7 -7
  91. package/dist/oauth/github.js +2 -6
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +7 -7
  94. package/dist/oauth/gitlab.js +2 -6
  95. package/dist/oauth/index.cjs +180 -180
  96. package/dist/oauth/index.d.ts +26 -7
  97. package/dist/oauth/index.js +9 -36
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +7 -7
  100. package/dist/oauth/spotify.js +2 -6
  101. package/dist/oauth/x.cjs +39 -39
  102. package/dist/oauth/x.d.ts +7 -7
  103. package/dist/oauth/x.js +2 -6
  104. package/dist/response.cjs +27 -27
  105. package/dist/response.d.ts +2 -2
  106. package/dist/response.js +2 -6
  107. package/dist/schemas.cjs +91 -91
  108. package/dist/schemas.d.ts +126 -93
  109. package/dist/schemas.js +18 -18
  110. package/dist/secure.cjs +98 -95
  111. package/dist/secure.d.ts +17 -17
  112. package/dist/secure.js +4 -18
  113. package/dist/utils.cjs +132 -119
  114. package/dist/utils.d.ts +26 -11
  115. package/dist/utils.js +21 -21
  116. package/package.json +1 -1
  117. package/dist/chunk-X7M4CQTN.js +0 -25
package/dist/schemas.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import {
2
- OAuthAccessToken,
3
- OAuthAccessTokenErrorResponse,
4
- OAuthAccessTokenResponse,
5
- OAuthAuthorization,
6
- OAuthAuthorizationErrorResponse,
7
- OAuthAuthorizationResponse,
8
- OAuthErrorResponse,
9
- OAuthProviderConfigSchema
10
- } from "./chunk-HMRKN75I.js";
2
+ OAuthAccessToken,
3
+ OAuthAccessTokenErrorResponse,
4
+ OAuthAccessTokenResponse,
5
+ OAuthAuthorization,
6
+ OAuthAuthorizationErrorResponse,
7
+ OAuthAuthorizationResponse,
8
+ OAuthErrorResponse,
9
+ OAuthProviderConfigSchema,
10
+ } from "./chunk-HMRKN75I.js"
11
11
  export {
12
- OAuthAccessToken,
13
- OAuthAccessTokenErrorResponse,
14
- OAuthAccessTokenResponse,
15
- OAuthAuthorization,
16
- OAuthAuthorizationErrorResponse,
17
- OAuthAuthorizationResponse,
18
- OAuthErrorResponse,
19
- OAuthProviderConfigSchema
20
- };
12
+ OAuthAccessToken,
13
+ OAuthAccessTokenErrorResponse,
14
+ OAuthAccessTokenResponse,
15
+ OAuthAuthorization,
16
+ OAuthAuthorizationErrorResponse,
17
+ OAuthAuthorizationResponse,
18
+ OAuthErrorResponse,
19
+ OAuthProviderConfigSchema,
20
+ }
package/dist/secure.cjs CHANGED
@@ -1,120 +1,123 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1
+ "use strict"
2
+ var __create = Object.create
3
+ var __defProp = Object.defineProperty
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor
5
+ var __getOwnPropNames = Object.getOwnPropertyNames
6
+ var __getProtoOf = Object.getPrototypeOf
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty
8
8
  var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
9
+ for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
10
+ }
12
11
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
12
+ if ((from && typeof from === "object") || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable })
16
+ }
17
+ return to
18
+ }
19
+ var __toESM = (mod, isNodeMode, target) => (
20
+ (target = mod != null ? __create(__getProtoOf(mod)) : {}),
21
+ __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ )
29
+ )
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod)
29
31
 
30
32
  // src/secure.ts
31
- var secure_exports = {};
33
+ var secure_exports = {}
32
34
  __export(secure_exports, {
33
- createCSRF: () => createCSRF,
34
- createDerivedSalt: () => createDerivedSalt,
35
- createHash: () => createHash,
36
- createPKCE: () => createPKCE,
37
- generateSecure: () => generateSecure,
38
- verifyCSRF: () => verifyCSRF
39
- });
40
- module.exports = __toCommonJS(secure_exports);
41
- var import_node_crypto = __toESM(require("crypto"), 1);
35
+ createCSRF: () => createCSRF,
36
+ createDerivedSalt: () => createDerivedSalt,
37
+ createHash: () => createHash,
38
+ createPKCE: () => createPKCE,
39
+ generateSecure: () => generateSecure,
40
+ verifyCSRF: () => verifyCSRF,
41
+ })
42
+ module.exports = __toCommonJS(secure_exports)
43
+ var import_node_crypto = __toESM(require("crypto"), 1)
42
44
 
43
45
  // src/utils.ts
44
- var import_router = require("@aura-stack/router");
46
+ var import_router = require("@aura-stack/router")
45
47
 
46
48
  // src/error.ts
47
49
  var AuthError = class extends Error {
48
- constructor(type, message) {
49
- super(message);
50
- this.type = type;
51
- this.name = "AuthError";
52
- }
53
- };
50
+ constructor(type, message) {
51
+ super(message)
52
+ this.type = type
53
+ this.name = "AuthError"
54
+ }
55
+ }
54
56
  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";
58
- }
59
- };
57
+ constructor(message = "The provided CSRF token is invalid or has expired") {
58
+ super("invalid_csrf_token", message)
59
+ this.name = "InvalidCsrfTokenError"
60
+ }
61
+ }
60
62
 
61
63
  // src/utils.ts
62
64
  var equals = (a, b) => {
63
- if (a === null || b === null || a === void 0 || b === void 0) return false;
64
- return a === b;
65
- };
65
+ if (a === null || b === null || a === void 0 || b === void 0) return false
66
+ return a === b
67
+ }
66
68
 
67
69
  // src/secure.ts
68
70
  var generateSecure = (length = 32) => {
69
- return import_node_crypto.default.randomBytes(length).toString("base64url");
70
- };
71
+ return import_node_crypto.default.randomBytes(length).toString("base64url")
72
+ }
71
73
  var createHash = (data, base = "hex") => {
72
- return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base);
73
- };
74
+ return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base)
75
+ }
74
76
  var createPKCE = async (verifier) => {
75
- const codeVerifier = verifier ?? generateSecure(86);
76
- const codeChallenge = createHash(codeVerifier, "base64url");
77
- return { codeVerifier, codeChallenge, method: "S256" };
78
- };
77
+ const codeVerifier = verifier ?? generateSecure(86)
78
+ const codeChallenge = createHash(codeVerifier, "base64url")
79
+ return { codeVerifier, codeChallenge, method: "S256" }
80
+ }
79
81
  var createCSRF = async (jose, csrfCookie) => {
80
- try {
81
- const token = generateSecure(32);
82
- if (csrfCookie) {
83
- await jose.verifyJWS(csrfCookie);
84
- return csrfCookie;
82
+ try {
83
+ const token = generateSecure(32)
84
+ if (csrfCookie) {
85
+ await jose.verifyJWS(csrfCookie)
86
+ return csrfCookie
87
+ }
88
+ return jose.signJWS({ token })
89
+ } catch {
90
+ const token = generateSecure(32)
91
+ return jose.signJWS({ token })
85
92
  }
86
- return jose.signJWS({ token });
87
- } catch {
88
- const token = generateSecure(32);
89
- return jose.signJWS({ token });
90
- }
91
- };
93
+ }
92
94
  var verifyCSRF = async (jose, cookie, header) => {
93
- 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);
98
- if (!equals(headerBuffer.length, cookieBuffer.length)) {
99
- throw new InvalidCsrfTokenError();
100
- }
101
- if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
102
- throw new InvalidCsrfTokenError();
95
+ try {
96
+ const { token: cookieToken } = await jose.verifyJWS(cookie)
97
+ const { token: headerToken } = await jose.verifyJWS(header)
98
+ const cookieBuffer = Buffer.from(cookieToken)
99
+ const headerBuffer = Buffer.from(headerToken)
100
+ if (!equals(headerBuffer.length, cookieBuffer.length)) {
101
+ throw new InvalidCsrfTokenError()
102
+ }
103
+ if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
104
+ throw new InvalidCsrfTokenError()
105
+ }
106
+ return true
107
+ } catch {
108
+ throw new InvalidCsrfTokenError()
103
109
  }
104
- return true;
105
- } catch {
106
- throw new InvalidCsrfTokenError();
107
- }
108
- };
110
+ }
109
111
  var createDerivedSalt = (secret) => {
110
- return import_node_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
111
- };
112
+ return import_node_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex")
113
+ }
112
114
  // Annotate the CommonJS export names for ESM import in node:
113
- 0 && (module.exports = {
114
- createCSRF,
115
- createDerivedSalt,
116
- createHash,
117
- createPKCE,
118
- generateSecure,
119
- verifyCSRF
120
- });
115
+ 0 &&
116
+ (module.exports = {
117
+ createCSRF,
118
+ createDerivedSalt,
119
+ createHash,
120
+ createPKCE,
121
+ generateSecure,
122
+ verifyCSRF,
123
+ })
package/dist/secure.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { A as AuthRuntimeConfig } from './index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
4
- import './schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
7
- import './@types/utility.js';
1
+ import { A as AuthRuntimeConfig } from "./index-DpfbvTZ_.js"
2
+ import "zod/v4"
3
+ import "@aura-stack/jose/jose"
4
+ import "./schemas.js"
5
+ import "zod/v4/core"
6
+ import "cookie"
7
+ import "./@types/utility.js"
8
8
 
9
- declare const generateSecure: (length?: number) => string;
10
- declare const createHash: (data: string, base?: "hex" | "base64" | "base64url") => string;
9
+ declare const generateSecure: (length?: number) => string
10
+ declare const createHash: (data: string, base?: "hex" | "base64" | "base64url") => string
11
11
  /**
12
12
  * Creates the code challenge flow for PKCE OAuth flow. It generates a code verifier and its corresponding
13
13
  * code challenge using SHA-256 hashing.
@@ -18,24 +18,24 @@ declare const createHash: (data: string, base?: "hex" | "base64" | "base64url")
18
18
  * @see https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
19
19
  */
20
20
  declare const createPKCE: (verifier?: string) => Promise<{
21
- codeVerifier: string;
22
- codeChallenge: string;
23
- method: string;
24
- }>;
21
+ codeVerifier: string
22
+ codeChallenge: string
23
+ method: string
24
+ }>
25
25
  /**
26
26
  * Creates a CSRF token to be used in OAuth flows to prevent cross-site request forgery attacks.
27
27
  *
28
28
  * @param csrfCookie - Optional existing CSRF cookie to verify and reuse
29
29
  * @returns Signed CSRF token
30
30
  */
31
- declare const createCSRF: (jose: AuthRuntimeConfig["jose"], csrfCookie?: string) => Promise<string>;
32
- declare const verifyCSRF: (jose: AuthRuntimeConfig["jose"], cookie: string, header: string) => Promise<boolean>;
31
+ declare const createCSRF: (jose: AuthRuntimeConfig["jose"], csrfCookie?: string) => Promise<string>
32
+ declare const verifyCSRF: (jose: AuthRuntimeConfig["jose"], cookie: string, header: string) => Promise<boolean>
33
33
  /**
34
34
  * Creates a deterministic derived salt from the provided secret.
35
35
  *
36
36
  * @param secret the base secret to derive the salt from
37
37
  * @returns the derived salt as a hexadecimal string
38
38
  */
39
- declare const createDerivedSalt: (secret: string) => string;
39
+ declare const createDerivedSalt: (secret: string) => string
40
40
 
41
- export { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF };
41
+ export { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF }
package/dist/secure.js CHANGED
@@ -1,18 +1,4 @@
1
- import {
2
- createCSRF,
3
- createDerivedSalt,
4
- createHash,
5
- createPKCE,
6
- generateSecure,
7
- verifyCSRF
8
- } from "./chunk-GZU3RBTB.js";
9
- import "./chunk-256KIVJL.js";
10
- import "./chunk-FJUDBLCP.js";
11
- export {
12
- createCSRF,
13
- createDerivedSalt,
14
- createHash,
15
- createPKCE,
16
- generateSecure,
17
- verifyCSRF
18
- };
1
+ import { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF } from "./chunk-GZU3RBTB.js"
2
+ import "./chunk-256KIVJL.js"
3
+ import "./chunk-FJUDBLCP.js"
4
+ export { createCSRF, createDerivedSalt, createHash, createPKCE, generateSecure, verifyCSRF }
package/dist/utils.cjs CHANGED
@@ -1,141 +1,154 @@
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)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
7
+ for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
8
+ }
10
9
  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);
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)
19
18
 
20
19
  // src/utils.ts
21
- var utils_exports = {};
20
+ var utils_exports = {}
22
21
  __export(utils_exports, {
23
- equals: () => equals,
24
- getNormalizedOriginPath: () => getNormalizedOriginPath,
25
- isValidRelativePath: () => isValidRelativePath,
26
- onErrorHandler: () => onErrorHandler,
27
- sanitizeURL: () => sanitizeURL,
28
- toCastCase: () => toCastCase,
29
- toISOString: () => toISOString,
30
- toSnakeCase: () => toSnakeCase,
31
- toUpperCase: () => toUpperCase
32
- });
33
- module.exports = __toCommonJS(utils_exports);
34
- var import_router = require("@aura-stack/router");
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")
35
34
 
36
35
  // src/error.ts
37
36
  var AuthError = class extends Error {
38
- constructor(type, message) {
39
- super(message);
40
- this.type = type;
41
- this.name = "AuthError";
42
- }
43
- };
37
+ constructor(type, message) {
38
+ super(message)
39
+ this.type = type
40
+ this.name = "AuthError"
41
+ }
42
+ }
44
43
  var isAuthError = (error) => {
45
- return error instanceof AuthError;
46
- };
44
+ return error instanceof AuthError
45
+ }
47
46
 
48
47
  // src/utils.ts
49
48
  var toSnakeCase = (str) => {
50
- return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
51
- };
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
+ }
52
55
  var toUpperCase = (str) => {
53
- return str.toUpperCase();
54
- };
56
+ return str.toUpperCase()
57
+ }
55
58
  var toCastCase = (obj, type = "snake") => {
56
- return Object.entries(obj).reduce((previous, [key, value]) => {
57
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
58
- return { ...previous, [newKey]: value };
59
- }, {});
60
- };
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
+ }
61
64
  var equals = (a, b) => {
62
- if (a === null || b === null || a === void 0 || b === void 0) return false;
63
- return a === b;
64
- };
65
+ if (a === null || b === null || a === void 0 || b === void 0) return false
66
+ return a === b
67
+ }
65
68
  var sanitizeURL = (url) => {
66
- try {
67
- let decodedURL = decodeURIComponent(url).trim();
68
- const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
69
- let protocol = "";
70
- let rest = decodedURL;
71
- if (protocolMatch) {
72
- protocol = protocolMatch[1];
73
- rest = decodedURL.slice(protocol.length);
74
- const slashIndex = rest.indexOf("/");
75
- if (slashIndex === -1) {
76
- return protocol + rest;
77
- }
78
- const domain = rest.slice(0, slashIndex);
79
- let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
80
- if (path !== "/" && path.endsWith("/")) {
81
- path = path.replace(/\/+$/, "/");
82
- } else if (path !== "/") {
83
- path = path.replace(/\/+$/, "");
84
- }
85
- return protocol + domain + path;
86
- }
87
- let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
88
- if (sanitized !== "/" && sanitized.endsWith("/")) {
89
- sanitized = sanitized.replace(/\/+$/, "/");
90
- } else if (sanitized !== "/") {
91
- sanitized = sanitized.replace(/\/+$/, "");
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()
92
108
  }
93
- return sanitized;
94
- } catch {
95
- return url.trim();
96
- }
97
- };
109
+ }
98
110
  var isValidRelativePath = (path) => {
99
- if (!path || typeof path !== "string") return false;
100
- if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
101
- if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
102
- const sanitized = sanitizeURL(path);
103
- if (sanitized.includes("..")) return false;
104
- return true;
105
- };
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
+ }
106
118
  var onErrorHandler = (error) => {
107
- if ((0, import_router.isRouterError)(error)) {
108
- const { message, status, statusText } = error;
109
- return Response.json({ error: "invalid_request", error_description: message }, { status, statusText });
110
- }
111
- if (isAuthError(error)) {
112
- const { type, message } = error;
113
- return Response.json({ error: type, error_description: message }, { status: 400 });
114
- }
115
- return Response.json({ error: "server_error", error_description: "An unexpected error occurred" }, { status: 500 });
116
- };
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
+ }
117
129
  var getNormalizedOriginPath = (path) => {
118
- try {
119
- const url = new URL(path);
120
- url.hash = "";
121
- url.search = "";
122
- return `${url.origin}${url.pathname}`;
123
- } catch {
124
- return sanitizeURL(path);
125
- }
126
- };
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
+ }
127
139
  var toISOString = (date) => {
128
- return new Date(date).toISOString();
129
- };
140
+ return new Date(date).toISOString()
141
+ }
130
142
  // Annotate the CommonJS export names for ESM import in node:
131
- 0 && (module.exports = {
132
- equals,
133
- getNormalizedOriginPath,
134
- isValidRelativePath,
135
- onErrorHandler,
136
- sanitizeURL,
137
- toCastCase,
138
- toISOString,
139
- toSnakeCase,
140
- toUpperCase
141
- });
143
+ 0 &&
144
+ (module.exports = {
145
+ equals,
146
+ getNormalizedOriginPath,
147
+ isValidRelativePath,
148
+ onErrorHandler,
149
+ sanitizeURL,
150
+ toCastCase,
151
+ toISOString,
152
+ toSnakeCase,
153
+ toUpperCase,
154
+ })