@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
@@ -1,8 +1,8 @@
1
- import * as _aura_stack_router from '@aura-stack/router';
1
+ import * as _aura_stack_router from "@aura-stack/router"
2
2
 
3
3
  /**
4
4
  * @see https://datatracker.ietf.org/doc/html/rfc7009
5
5
  */
6
- declare const signOutAction: _aura_stack_router.RouteEndpoint<"POST", "/signOut", {}>;
6
+ declare const signOutAction: _aura_stack_router.RouteEndpoint<"POST", "/signOut", {}>
7
7
 
8
- export { signOutAction };
8
+ export { signOutAction }
@@ -1,15 +1,11 @@
1
- import {
2
- signOutAction
3
- } from "../../chunk-SJPDVKUS.js";
4
- import "../../chunk-CAKJT3KS.js";
5
- import "../../chunk-ZV4BH47P.js";
6
- import "../../chunk-6SM22VVJ.js";
7
- import "../../chunk-STHEPPUZ.js";
8
- import "../../chunk-GZU3RBTB.js";
9
- import "../../chunk-256KIVJL.js";
10
- import "../../chunk-FJUDBLCP.js";
11
- import "../../chunk-JAPMIE6S.js";
12
- import "../../chunk-HMRKN75I.js";
13
- export {
14
- signOutAction
15
- };
1
+ import { signOutAction } from "../../chunk-SJPDVKUS.js"
2
+ import "../../chunk-CAKJT3KS.js"
3
+ import "../../chunk-ZV4BH47P.js"
4
+ import "../../chunk-6SM22VVJ.js"
5
+ import "../../chunk-STHEPPUZ.js"
6
+ import "../../chunk-GZU3RBTB.js"
7
+ import "../../chunk-256KIVJL.js"
8
+ import "../../chunk-FJUDBLCP.js"
9
+ import "../../chunk-JAPMIE6S.js"
10
+ import "../../chunk-HMRKN75I.js"
11
+ export { signOutAction }
package/dist/assert.cjs CHANGED
@@ -1,44 +1,45 @@
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/assert.ts
21
- var assert_exports = {};
20
+ var assert_exports = {}
22
21
  __export(assert_exports, {
23
- isFalsy: () => isFalsy,
24
- isRequest: () => isRequest,
25
- isValidURL: () => isValidURL
26
- });
27
- module.exports = __toCommonJS(assert_exports);
22
+ isFalsy: () => isFalsy,
23
+ isRequest: () => isRequest,
24
+ isValidURL: () => isValidURL,
25
+ })
26
+ module.exports = __toCommonJS(assert_exports)
28
27
  var isFalsy = (value) => {
29
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
30
- };
28
+ return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value)
29
+ }
31
30
  var isRequest = (value) => {
32
- return typeof Request !== "undefined" && value instanceof Request;
33
- };
31
+ return typeof Request !== "undefined" && value instanceof Request
32
+ }
34
33
  var isValidURL = (value) => {
35
- if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
36
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
37
- return regex.test(value);
38
- };
34
+ if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
35
+ const regex =
36
+ /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
37
+ return regex.test(value)
38
+ }
39
39
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- isFalsy,
42
- isRequest,
43
- isValidURL
44
- });
40
+ 0 &&
41
+ (module.exports = {
42
+ isFalsy,
43
+ isRequest,
44
+ isValidURL,
45
+ })
package/dist/assert.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- declare const isFalsy: (value: unknown) => boolean;
2
- declare const isRequest: (value: unknown) => value is Request;
3
- declare const isValidURL: (value: string) => boolean;
1
+ declare const isFalsy: (value: unknown) => boolean
2
+ declare const isRequest: (value: unknown) => value is Request
3
+ declare const isValidURL: (value: string) => boolean
4
4
 
5
- export { isFalsy, isRequest, isValidURL };
5
+ export { isFalsy, isRequest, isValidURL }
package/dist/assert.js CHANGED
@@ -1,10 +1,2 @@
1
- import {
2
- isFalsy,
3
- isRequest,
4
- isValidURL
5
- } from "./chunk-6SM22VVJ.js";
6
- export {
7
- isFalsy,
8
- isRequest,
9
- isValidURL
10
- };
1
+ import { isFalsy, isRequest, isValidURL } from "./chunk-6SM22VVJ.js"
2
+ export { isFalsy, isRequest, isValidURL }
@@ -1,99 +1,110 @@
1
- import {
2
- isAuthError
3
- } from "./chunk-FJUDBLCP.js";
1
+ import { isAuthError } from "./chunk-FJUDBLCP.js"
4
2
 
5
3
  // src/utils.ts
6
- import { isRouterError } from "@aura-stack/router";
4
+ import { isRouterError } from "@aura-stack/router"
7
5
  var toSnakeCase = (str) => {
8
- return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
9
- };
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
+ }
10
12
  var toUpperCase = (str) => {
11
- return str.toUpperCase();
12
- };
13
+ return str.toUpperCase()
14
+ }
13
15
  var toCastCase = (obj, type = "snake") => {
14
- return Object.entries(obj).reduce((previous, [key, value]) => {
15
- const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
16
- return { ...previous, [newKey]: value };
17
- }, {});
18
- };
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
+ }
19
21
  var equals = (a, b) => {
20
- if (a === null || b === null || a === void 0 || b === void 0) return false;
21
- return a === b;
22
- };
22
+ if (a === null || b === null || a === void 0 || b === void 0) return false
23
+ return a === b
24
+ }
23
25
  var sanitizeURL = (url) => {
24
- try {
25
- let decodedURL = decodeURIComponent(url).trim();
26
- const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
27
- let protocol = "";
28
- let rest = decodedURL;
29
- if (protocolMatch) {
30
- protocol = protocolMatch[1];
31
- rest = decodedURL.slice(protocol.length);
32
- const slashIndex = rest.indexOf("/");
33
- if (slashIndex === -1) {
34
- return protocol + rest;
35
- }
36
- const domain = rest.slice(0, slashIndex);
37
- let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
38
- if (path !== "/" && path.endsWith("/")) {
39
- path = path.replace(/\/+$/, "/");
40
- } else if (path !== "/") {
41
- path = path.replace(/\/+$/, "");
42
- }
43
- return protocol + domain + path;
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()
44
65
  }
45
- let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
46
- if (sanitized !== "/" && sanitized.endsWith("/")) {
47
- sanitized = sanitized.replace(/\/+$/, "/");
48
- } else if (sanitized !== "/") {
49
- sanitized = sanitized.replace(/\/+$/, "");
50
- }
51
- return sanitized;
52
- } catch {
53
- return url.trim();
54
- }
55
- };
66
+ }
56
67
  var isValidRelativePath = (path) => {
57
- if (!path || typeof path !== "string") return false;
58
- if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
59
- if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
60
- const sanitized = sanitizeURL(path);
61
- if (sanitized.includes("..")) return false;
62
- return true;
63
- };
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
+ }
64
75
  var onErrorHandler = (error) => {
65
- if (isRouterError(error)) {
66
- const { message, status, statusText } = error;
67
- return Response.json({ error: "invalid_request", error_description: message }, { status, statusText });
68
- }
69
- if (isAuthError(error)) {
70
- const { type, message } = error;
71
- return Response.json({ error: type, error_description: message }, { status: 400 });
72
- }
73
- return Response.json({ error: "server_error", error_description: "An unexpected error occurred" }, { status: 500 });
74
- };
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
+ }
75
86
  var getNormalizedOriginPath = (path) => {
76
- try {
77
- const url = new URL(path);
78
- url.hash = "";
79
- url.search = "";
80
- return `${url.origin}${url.pathname}`;
81
- } catch {
82
- return sanitizeURL(path);
83
- }
84
- };
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
+ }
85
96
  var toISOString = (date) => {
86
- return new Date(date).toISOString();
87
- };
97
+ return new Date(date).toISOString()
98
+ }
88
99
 
89
100
  export {
90
- toSnakeCase,
91
- toUpperCase,
92
- toCastCase,
93
- equals,
94
- sanitizeURL,
95
- isValidRelativePath,
96
- onErrorHandler,
97
- getNormalizedOriginPath,
98
- toISOString
99
- };
101
+ toSnakeCase,
102
+ toUpperCase,
103
+ toCastCase,
104
+ equals,
105
+ sanitizeURL,
106
+ isValidRelativePath,
107
+ onErrorHandler,
108
+ getNormalizedOriginPath,
109
+ toISOString,
110
+ }
@@ -1,22 +1,20 @@
1
1
  // src/oauth/x.ts
2
2
  var x = {
3
- id: "x",
4
- name: "X",
5
- authorizeURL: "https://x.com/i/oauth2/authorize",
6
- accessToken: "https://api.x.com/2/oauth2/token",
7
- userInfo: "https://api.x.com/2/users/me?user.fields=profile_image_url",
8
- scope: "users.read users.email tweet.read offline.access",
9
- responseType: "code",
10
- profile({ data }) {
11
- return {
12
- sub: data.id,
13
- name: data.name,
14
- image: data.profile_image_url,
15
- email: ""
16
- };
17
- }
18
- };
3
+ id: "x",
4
+ name: "X",
5
+ authorizeURL: "https://x.com/i/oauth2/authorize",
6
+ accessToken: "https://api.x.com/2/oauth2/token",
7
+ userInfo: "https://api.x.com/2/users/me?user.fields=profile_image_url",
8
+ scope: "users.read users.email tweet.read offline.access",
9
+ responseType: "code",
10
+ profile({ data }) {
11
+ return {
12
+ sub: data.id,
13
+ name: data.name,
14
+ image: data.profile_image_url,
15
+ email: "",
16
+ }
17
+ },
18
+ }
19
19
 
20
- export {
21
- x
22
- };
20
+ export { x }
@@ -1,18 +1,15 @@
1
1
  // src/assert.ts
2
2
  var isFalsy = (value) => {
3
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
4
- };
3
+ return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value)
4
+ }
5
5
  var isRequest = (value) => {
6
- return typeof Request !== "undefined" && value instanceof Request;
7
- };
6
+ return typeof Request !== "undefined" && value instanceof Request
7
+ }
8
8
  var isValidURL = (value) => {
9
- if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
10
- const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
11
- return regex.test(value);
12
- };
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
+ }
13
14
 
14
- export {
15
- isFalsy,
16
- isRequest,
17
- isValidURL
18
- };
15
+ export { isFalsy, isRequest, isValidURL }
@@ -1,92 +1,77 @@
1
- import {
2
- isValidURL
3
- } from "./chunk-6SM22VVJ.js";
4
- import {
5
- equals,
6
- getNormalizedOriginPath,
7
- sanitizeURL,
8
- toCastCase
9
- } from "./chunk-256KIVJL.js";
10
- import {
11
- AuthError,
12
- ERROR_RESPONSE,
13
- InvalidRedirectToError,
14
- isAuthError
15
- } from "./chunk-FJUDBLCP.js";
16
- import {
17
- OAuthAuthorization
18
- } from "./chunk-HMRKN75I.js";
1
+ import { isValidURL } from "./chunk-6SM22VVJ.js"
2
+ import { equals, getNormalizedOriginPath, sanitizeURL, toCastCase } from "./chunk-256KIVJL.js"
3
+ import { AuthError, ERROR_RESPONSE, InvalidRedirectToError, isAuthError } from "./chunk-FJUDBLCP.js"
4
+ import { OAuthAuthorization } from "./chunk-HMRKN75I.js"
19
5
 
20
6
  // src/actions/signIn/authorization.ts
21
7
  var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
22
- const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
23
- if (!parsed.success) {
24
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration");
25
- }
26
- const { authorizeURL, ...options } = parsed.data;
27
- const { userInfo, accessToken, clientSecret, ...required } = options;
28
- const searchParams = new URLSearchParams(toCastCase(required));
29
- return `${authorizeURL}?${searchParams}`;
30
- };
8
+ const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod })
9
+ if (!parsed.success) {
10
+ throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration")
11
+ }
12
+ const { authorizeURL, ...options } = parsed.data
13
+ const { userInfo, accessToken, clientSecret, ...required } = options
14
+ const searchParams = new URLSearchParams(toCastCase(required))
15
+ return `${authorizeURL}?${searchParams}`
16
+ }
31
17
  var getOriginURL = (request, trustedProxyHeaders) => {
32
- const headers = request.headers;
33
- if (trustedProxyHeaders) {
34
- const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
35
- const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
36
- return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
37
- } else {
38
- return new URL(getNormalizedOriginPath(request.url));
39
- }
40
- };
18
+ const headers = request.headers
19
+ if (trustedProxyHeaders) {
20
+ const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http"
21
+ const host =
22
+ headers.get("X-Forwarded-Host") ??
23
+ headers.get("Host") ??
24
+ headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ??
25
+ null
26
+ return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`)
27
+ } else {
28
+ return new URL(getNormalizedOriginPath(request.url))
29
+ }
30
+ }
41
31
  var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
42
- const url = getOriginURL(request, trustedProxyHeaders);
43
- return `${url.origin}${basePath}/callback/${oauth}`;
44
- };
32
+ const url = getOriginURL(request, trustedProxyHeaders)
33
+ return `${url.origin}${basePath}/callback/${oauth}`
34
+ }
45
35
  var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
46
- try {
47
- const headers = request.headers;
48
- const origin = headers.get("Origin");
49
- const referer = headers.get("Referer");
50
- let hostedURL = getOriginURL(request, trustedProxyHeaders);
51
- if (redirectTo) {
52
- if (redirectTo.startsWith("/")) {
53
- return sanitizeURL(redirectTo);
54
- }
55
- const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
56
- if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
57
- throw new InvalidRedirectToError();
58
- }
59
- return sanitizeURL(redirectToURL.pathname);
60
- }
61
- if (referer) {
62
- const refererURL = new URL(sanitizeURL(referer));
63
- if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
64
- throw new AuthError(
65
- ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
66
- "The referer of the request does not match the hosted origin."
67
- );
68
- }
69
- return sanitizeURL(refererURL.pathname);
70
- }
71
- if (origin) {
72
- const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
73
- if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
74
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
75
- }
76
- return sanitizeURL(originURL.pathname);
77
- }
78
- return "/";
79
- } catch (error) {
80
- if (isAuthError(error)) {
81
- throw error;
36
+ try {
37
+ const headers = request.headers
38
+ const origin = headers.get("Origin")
39
+ const referer = headers.get("Referer")
40
+ let hostedURL = getOriginURL(request, trustedProxyHeaders)
41
+ if (redirectTo) {
42
+ if (redirectTo.startsWith("/")) {
43
+ return sanitizeURL(redirectTo)
44
+ }
45
+ const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)))
46
+ if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
47
+ throw new InvalidRedirectToError()
48
+ }
49
+ return sanitizeURL(redirectToURL.pathname)
50
+ }
51
+ if (referer) {
52
+ const refererURL = new URL(sanitizeURL(referer))
53
+ if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
54
+ throw new AuthError(
55
+ ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
56
+ "The referer of the request does not match the hosted origin."
57
+ )
58
+ }
59
+ return sanitizeURL(refererURL.pathname)
60
+ }
61
+ if (origin) {
62
+ const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)))
63
+ if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
64
+ throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
65
+ }
66
+ return sanitizeURL(originURL.pathname)
67
+ }
68
+ return "/"
69
+ } catch (error) {
70
+ if (isAuthError(error)) {
71
+ throw error
72
+ }
73
+ throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
82
74
  }
83
- throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
84
- }
85
- };
75
+ }
86
76
 
87
- export {
88
- createAuthorizationURL,
89
- getOriginURL,
90
- createRedirectURI,
91
- createRedirectTo
92
- };
77
+ export { createAuthorizationURL, getOriginURL, createRedirectURI, createRedirectTo }
@@ -1,22 +1,20 @@
1
1
  // src/oauth/spotify.ts
2
2
  var spotify = {
3
- id: "spotify",
4
- name: "Spotify",
5
- authorizeURL: "https://accounts.spotify.com/authorize",
6
- accessToken: "https://accounts.spotify.com/api/token",
7
- userInfo: "https://api.spotify.com/v1/me",
8
- scope: "user-read-email user-read-private",
9
- responseType: "token",
10
- profile(profile) {
11
- return {
12
- sub: profile.id,
13
- name: profile.display_name,
14
- email: profile.email,
15
- image: profile.images?.[0]?.url
16
- };
17
- }
18
- };
3
+ id: "spotify",
4
+ name: "Spotify",
5
+ authorizeURL: "https://accounts.spotify.com/authorize",
6
+ accessToken: "https://accounts.spotify.com/api/token",
7
+ userInfo: "https://api.spotify.com/v1/me",
8
+ scope: "user-read-email user-read-private",
9
+ responseType: "token",
10
+ profile(profile) {
11
+ return {
12
+ sub: profile.id,
13
+ name: profile.display_name,
14
+ email: profile.email,
15
+ image: profile.images?.[0]?.url,
16
+ }
17
+ },
18
+ }
19
19
 
20
- export {
21
- spotify
22
- };
20
+ export { spotify }