@aura-stack/auth 0.1.0-rc.8 → 0.1.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 (116) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +7 -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 +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 +15 -20
  11. package/dist/actions/callback/access-token.js +8 -4
  12. package/dist/actions/callback/callback.cjs +437 -455
  13. package/dist/actions/callback/callback.d.ts +10 -12
  14. package/dist/actions/callback/callback.js +16 -12
  15. package/dist/actions/callback/userinfo.cjs +131 -134
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +10 -6
  18. package/dist/actions/csrfToken/csrfToken.cjs +162 -171
  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 +746 -773
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +34 -18
  24. package/dist/actions/session/session.cjs +149 -155
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +11 -7
  27. package/dist/actions/signIn/authorization.cjs +231 -249
  28. package/dist/actions/signIn/authorization.d.ts +12 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +396 -423
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +14 -10
  33. package/dist/actions/signOut/signOut.cjs +417 -440
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +15 -11
  36. package/dist/assert.cjs +35 -36
  37. package/dist/assert.d.ts +4 -4
  38. package/dist/assert.js +10 -2
  39. package/dist/chunk-256KIVJL.js +85 -96
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-6SM22VVJ.js +13 -10
  42. package/dist/chunk-CAKJT3KS.js +84 -69
  43. package/dist/chunk-E3OXBRYF.js +19 -17
  44. package/dist/chunk-EBPE35JT.js +28 -26
  45. package/dist/chunk-FIPU4MLT.js +18 -16
  46. package/dist/chunk-FJUDBLCP.js +50 -43
  47. package/dist/chunk-FKRDCWBF.js +19 -17
  48. package/dist/chunk-GZU3RBTB.js +51 -40
  49. package/dist/chunk-HGJ4TXY4.js +132 -100
  50. package/dist/chunk-HMRKN75I.js +63 -63
  51. package/dist/chunk-IKHPGFCW.js +11 -9
  52. package/dist/chunk-JAPMIE6S.js +7 -5
  53. package/dist/chunk-KRNOMBXQ.js +19 -17
  54. package/dist/chunk-LLR722CL.js +91 -70
  55. package/dist/chunk-RLT4RFKV.js +39 -30
  56. package/dist/chunk-SJPDVKUS.js +107 -88
  57. package/dist/chunk-SMQO5WD7.js +26 -16
  58. package/dist/chunk-STHEPPUZ.js +8 -6
  59. package/dist/chunk-UJJ7R56J.js +47 -37
  60. package/dist/chunk-UTDLUEEG.js +27 -21
  61. package/dist/chunk-VFTYH33W.js +54 -37
  62. package/dist/chunk-XXJKNKGQ.js +33 -23
  63. package/dist/chunk-ZV4BH47P.js +132 -134
  64. package/dist/cookie.cjs +169 -175
  65. package/dist/cookie.d.ts +23 -51
  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 +15 -8
  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 +249 -298
  74. package/dist/index.cjs +936 -969
  75. package/dist/index.d.ts +10 -31
  76. package/dist/index.js +70 -50
  77. package/dist/jose.cjs +61 -64
  78. package/dist/jose.d.ts +8 -8
  79. package/dist/jose.js +9 -5
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +7 -7
  82. package/dist/oauth/bitbucket.js +6 -2
  83. package/dist/oauth/discord.cjs +48 -48
  84. package/dist/oauth/discord.d.ts +7 -7
  85. package/dist/oauth/discord.js +6 -2
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +7 -7
  88. package/dist/oauth/figma.js +6 -2
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +7 -7
  91. package/dist/oauth/github.js +6 -2
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +7 -7
  94. package/dist/oauth/gitlab.js +6 -2
  95. package/dist/oauth/index.cjs +180 -180
  96. package/dist/oauth/index.d.ts +7 -26
  97. package/dist/oauth/index.js +36 -9
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +7 -7
  100. package/dist/oauth/spotify.js +6 -2
  101. package/dist/oauth/x.cjs +39 -39
  102. package/dist/oauth/x.d.ts +7 -7
  103. package/dist/oauth/x.js +6 -2
  104. package/dist/response.cjs +27 -27
  105. package/dist/response.d.ts +2 -2
  106. package/dist/response.js +6 -2
  107. package/dist/schemas.cjs +91 -91
  108. package/dist/schemas.d.ts +93 -126
  109. package/dist/schemas.js +18 -18
  110. package/dist/secure.cjs +95 -98
  111. package/dist/secure.d.ts +17 -17
  112. package/dist/secure.js +18 -4
  113. package/dist/utils.cjs +119 -132
  114. package/dist/utils.d.ts +11 -26
  115. package/dist/utils.js +21 -21
  116. package/package.json +2 -2
@@ -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,11 +1,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 }
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
+ };
package/dist/assert.cjs CHANGED
@@ -1,45 +1,44 @@
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/assert.ts
20
- var assert_exports = {}
21
+ var assert_exports = {};
21
22
  __export(assert_exports, {
22
- isFalsy: () => isFalsy,
23
- isRequest: () => isRequest,
24
- isValidURL: () => isValidURL,
25
- })
26
- module.exports = __toCommonJS(assert_exports)
23
+ isFalsy: () => isFalsy,
24
+ isRequest: () => isRequest,
25
+ isValidURL: () => isValidURL
26
+ });
27
+ module.exports = __toCommonJS(assert_exports);
27
28
  var isFalsy = (value) => {
28
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value)
29
- }
29
+ return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
30
+ };
30
31
  var isRequest = (value) => {
31
- return typeof Request !== "undefined" && value instanceof Request
32
- }
32
+ return typeof Request !== "undefined" && value instanceof Request;
33
+ };
33
34
  var isValidURL = (value) => {
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
- }
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
+ };
39
39
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 &&
41
- (module.exports = {
42
- isFalsy,
43
- isRequest,
44
- isValidURL,
45
- })
40
+ 0 && (module.exports = {
41
+ isFalsy,
42
+ isRequest,
43
+ isValidURL
44
+ });
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,2 +1,10 @@
1
- import { isFalsy, isRequest, isValidURL } from "./chunk-6SM22VVJ.js"
2
- export { isFalsy, isRequest, isValidURL }
1
+ import {
2
+ isFalsy,
3
+ isRequest,
4
+ isValidURL
5
+ } from "./chunk-6SM22VVJ.js";
6
+ export {
7
+ isFalsy,
8
+ isRequest,
9
+ isValidURL
10
+ };
@@ -1,110 +1,99 @@
1
- import { isAuthError } from "./chunk-FJUDBLCP.js"
1
+ import {
2
+ isAuthError
3
+ } from "./chunk-FJUDBLCP.js";
2
4
 
3
5
  // src/utils.ts
4
- import { isRouterError } from "@aura-stack/router"
6
+ import { isRouterError } from "@aura-stack/router";
5
7
  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
- }
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
+ };
12
10
  var toUpperCase = (str) => {
13
- return str.toUpperCase()
14
- }
11
+ return str.toUpperCase();
12
+ };
15
13
  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
- }
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
+ };
21
19
  var equals = (a, b) => {
22
- if (a === null || b === null || a === void 0 || b === void 0) return false
23
- return a === b
24
- }
20
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
21
+ return a === b;
22
+ };
25
23
  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()
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;
65
44
  }
66
- }
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
+ };
67
56
  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
- }
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
+ };
75
64
  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
- }
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
+ };
86
75
  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
- }
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
+ };
96
85
  var toISOString = (date) => {
97
- return new Date(date).toISOString()
98
- }
86
+ return new Date(date).toISOString();
87
+ };
99
88
 
100
89
  export {
101
- toSnakeCase,
102
- toUpperCase,
103
- toCastCase,
104
- equals,
105
- sanitizeURL,
106
- isValidRelativePath,
107
- onErrorHandler,
108
- getNormalizedOriginPath,
109
- toISOString,
110
- }
90
+ toSnakeCase,
91
+ toUpperCase,
92
+ toCastCase,
93
+ equals,
94
+ sanitizeURL,
95
+ isValidRelativePath,
96
+ onErrorHandler,
97
+ getNormalizedOriginPath,
98
+ toISOString
99
+ };
@@ -1,20 +1,22 @@
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 { x }
20
+ export {
21
+ x
22
+ };
@@ -1,15 +1,18 @@
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 =
11
- /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
12
- return regex.test(value)
13
- }
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
+ };
14
13
 
15
- export { isFalsy, isRequest, isValidURL }
14
+ export {
15
+ isFalsy,
16
+ isRequest,
17
+ isValidURL
18
+ };
@@ -1,77 +1,92 @@
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"
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";
5
19
 
6
20
  // src/actions/signIn/authorization.ts
7
21
  var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
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
- }
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
+ };
17
31
  var getOriginURL = (request, trustedProxyHeaders) => {
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
- }
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
+ };
31
41
  var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
32
- const url = getOriginURL(request, trustedProxyHeaders)
33
- return `${url.origin}${basePath}/callback/${oauth}`
34
- }
42
+ const url = getOriginURL(request, trustedProxyHeaders);
43
+ return `${url.origin}${basePath}/callback/${oauth}`;
44
+ };
35
45
  var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
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).")
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;
74
82
  }
75
- }
83
+ throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).");
84
+ }
85
+ };
76
86
 
77
- export { createAuthorizationURL, getOriginURL, createRedirectURI, createRedirectTo }
87
+ export {
88
+ createAuthorizationURL,
89
+ getOriginURL,
90
+ createRedirectURI,
91
+ createRedirectTo
92
+ };
@@ -1,20 +1,22 @@
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 { spotify }
20
+ export {
21
+ spotify
22
+ };