@aura-stack/auth 0.1.0 → 0.2.0-rc.1

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 (111) hide show
  1. package/dist/@types/index.d.ts +5 -5
  2. package/dist/@types/router.d.d.ts +5 -5
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +95 -74
  5. package/dist/actions/callback/access-token.d.ts +7 -7
  6. package/dist/actions/callback/access-token.js +5 -3
  7. package/dist/actions/callback/callback.cjs +171 -249
  8. package/dist/actions/callback/callback.d.ts +6 -6
  9. package/dist/actions/callback/callback.js +10 -10
  10. package/dist/actions/callback/userinfo.cjs +81 -57
  11. package/dist/actions/callback/userinfo.d.ts +5 -5
  12. package/dist/actions/callback/userinfo.js +7 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +36 -105
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +309 -444
  16. package/dist/actions/index.d.ts +5 -5
  17. package/dist/actions/index.js +19 -19
  18. package/dist/actions/session/session.cjs +25 -109
  19. package/dist/actions/session/session.js +4 -5
  20. package/dist/actions/signIn/authorization.cjs +96 -87
  21. package/dist/actions/signIn/authorization.d.ts +5 -5
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +133 -242
  24. package/dist/actions/signIn/signIn.d.ts +6 -6
  25. package/dist/actions/signIn/signIn.js +8 -9
  26. package/dist/actions/signOut/signOut.cjs +136 -282
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +10 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-3EUWD5BB.js +63 -0
  32. package/dist/chunk-6R2YZ4AC.js +22 -0
  33. package/dist/chunk-A3N4PVAT.js +70 -0
  34. package/dist/chunk-B737EUJV.js +22 -0
  35. package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
  36. package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
  37. package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
  38. package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
  39. package/dist/chunk-HP34YGGJ.js +22 -0
  40. package/dist/chunk-HT4YLL7N.js +35 -0
  41. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  42. package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
  43. package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
  44. package/dist/chunk-KSWLO5ZU.js +102 -0
  45. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  46. package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
  47. package/dist/chunk-RRLIF4PQ.js +55 -0
  48. package/dist/chunk-TLE4PXY3.js +39 -0
  49. package/dist/chunk-W6LG7BFW.js +197 -0
  50. package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
  51. package/dist/chunk-ZNCZVF6U.js +14 -0
  52. package/dist/cookie.cjs +140 -99
  53. package/dist/cookie.d.ts +35 -44
  54. package/dist/cookie.js +10 -17
  55. package/dist/errors.cjs +85 -0
  56. package/dist/errors.d.ts +49 -0
  57. package/dist/errors.js +18 -0
  58. package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
  59. package/dist/index.cjs +543 -443
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +42 -28
  62. package/dist/jose.cjs +25 -14
  63. package/dist/jose.d.ts +4 -1
  64. package/dist/jose.js +5 -4
  65. package/dist/oauth/bitbucket.d.ts +5 -5
  66. package/dist/oauth/discord.cjs +0 -1
  67. package/dist/oauth/discord.d.ts +5 -5
  68. package/dist/oauth/discord.js +1 -1
  69. package/dist/oauth/figma.d.ts +5 -5
  70. package/dist/oauth/github.d.ts +5 -5
  71. package/dist/oauth/gitlab.d.ts +5 -5
  72. package/dist/oauth/index.cjs +176 -6
  73. package/dist/oauth/index.d.ts +5 -5
  74. package/dist/oauth/index.js +19 -4
  75. package/dist/oauth/mailchimp.cjs +46 -0
  76. package/dist/oauth/mailchimp.d.ts +7 -0
  77. package/dist/oauth/mailchimp.js +6 -0
  78. package/dist/oauth/pinterest.cjs +46 -0
  79. package/dist/oauth/pinterest.d.ts +7 -0
  80. package/dist/oauth/pinterest.js +6 -0
  81. package/dist/oauth/spotify.d.ts +5 -5
  82. package/dist/oauth/strava.cjs +46 -0
  83. package/dist/oauth/strava.d.ts +7 -0
  84. package/dist/oauth/strava.js +6 -0
  85. package/dist/oauth/x.d.ts +5 -5
  86. package/dist/{response.cjs → request.cjs} +14 -10
  87. package/dist/request.d.ts +13 -0
  88. package/dist/request.js +6 -0
  89. package/dist/schemas.cjs +43 -37
  90. package/dist/schemas.d.ts +67 -64
  91. package/dist/schemas.js +3 -1
  92. package/dist/secure.cjs +32 -24
  93. package/dist/secure.d.ts +5 -5
  94. package/dist/secure.js +4 -3
  95. package/dist/utils.cjs +90 -15
  96. package/dist/utils.d.ts +11 -2
  97. package/dist/utils.js +8 -4
  98. package/package.json +8 -7
  99. package/dist/chunk-FJUDBLCP.js +0 -59
  100. package/dist/chunk-HGJ4TXY4.js +0 -137
  101. package/dist/chunk-JAPMIE6S.js +0 -10
  102. package/dist/chunk-LLR722CL.js +0 -96
  103. package/dist/chunk-SJPDVKUS.js +0 -112
  104. package/dist/chunk-SMQO5WD7.js +0 -30
  105. package/dist/chunk-UTDLUEEG.js +0 -31
  106. package/dist/chunk-ZV4BH47P.js +0 -154
  107. package/dist/error.cjs +0 -88
  108. package/dist/error.d.ts +0 -62
  109. package/dist/error.js +0 -16
  110. package/dist/response.d.ts +0 -10
  111. package/dist/response.js +0 -6
@@ -1,7 +1,7 @@
1
- import 'zod/v4';
2
- import '@aura-stack/jose/jose';
1
+ import 'zod';
3
2
  import '../schemas.js';
4
- import 'cookie';
3
+ import '@aura-stack/router/cookie';
4
+ import '@aura-stack/jose';
5
+ import '@aura-stack/jose/jose';
6
+ export { i as APIErrorMap, a0 as AccessTokenError, d as AuthConfig, e as AuthInstance, b as AuthInternalErrorCode, A as AuthRuntimeConfig, c as AuthSecurityErrorCode, $ as AuthorizationError, C as CookieConfig, Z as CookieName, a as CookieStoreConfig, Y as CookieStrategyAttributes, E as ErrorType, V as HostCookie, J as JWTPayloadWithToken, Q as JWTStandardClaims, f as JoseInstance, a2 as OAuthEnv, _ as OAuthError, O as OAuthProvider, g as OAuthProviderConfig, h as OAuthProviderCredentials, j as OAuthProviderRecord, R as RouterGlobalContext, T as SecureCookie, S as Session, W as StandardCookie, a1 as TokenRevocationError, U as User } from '../index-DkaLJFn8.js';
5
7
  export { LiteralUnion, Prettify } from './utility.js';
6
- export { y as AccessTokenError, c as AuthConfig, d as AuthInstance, A as AuthRuntimeConfig, w as AuthorizationError, C as CookieConfig, a as CookieConfigInternal, b as CookieName, u as CookieStrategyOptions, E as ErrorType, H as HostCookie, q as JWTStandardClaims, J as JoseInstance, v as OAuthError, O as OAuthProvider, e as OAuthProviderConfig, f as OAuthProviderCredentials, R as RouterGlobalContext, r as SecureCookie, S as Session, t as StandardCookie, T as TokenRevocationError, U as User } from '../index-DpfbvTZ_.js';
7
- import 'zod/v4/core';
@@ -1,9 +1,9 @@
1
- import { R as RouterGlobalContext } from '../index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
1
+ import { R as RouterGlobalContext } from '../index-DkaLJFn8.js';
2
+ import 'zod';
4
3
  import '../schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
7
  import './utility.js';
8
8
 
9
9
  declare module "@aura-stack/router" {
@@ -1,10 +1,6 @@
1
1
  type Prettify<T> = {
2
2
  [K in keyof T]: T[K];
3
- } & {
4
- __aura_auth_prettify_brand?: never;
5
- };
6
- type LiteralUnion<T extends U, U = string> = (T | (U & Record<never, never>)) & {
7
- __aura_auth_literal_union_brand?: never;
8
3
  };
4
+ type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
9
5
 
10
6
  export type { LiteralUnion, Prettify };
@@ -24,68 +24,84 @@ __export(access_token_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(access_token_exports);
26
26
 
27
- // src/error.ts
28
- var AuthError = class extends Error {
29
- constructor(type, message) {
30
- super(message);
31
- this.type = type;
32
- this.name = "AuthError";
33
- }
27
+ // src/request.ts
28
+ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
29
+ const controller = new AbortController();
30
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
31
+ const response = await fetch(url, {
32
+ ...options2,
33
+ signal: controller.signal
34
+ }).finally(() => clearTimeout(timeoutId));
35
+ return response;
34
36
  };
35
- var isAuthError = (error) => {
36
- return error instanceof AuthError;
37
+
38
+ // src/utils.ts
39
+ var import_router = require("@aura-stack/router");
40
+
41
+ // src/errors.ts
42
+ var OAuthProtocolError = class extends Error {
43
+ type = "OAUTH_PROTOCOL_ERROR";
44
+ error;
45
+ errorURI;
46
+ constructor(error, description, errorURI, options2) {
47
+ super(description, options2);
48
+ this.error = error;
49
+ this.errorURI = errorURI;
50
+ this.name = new.target.name;
51
+ Error.captureStackTrace(this, new.target);
52
+ }
37
53
  };
38
- var throwAuthError = (error, message) => {
39
- if (error instanceof Error) {
40
- if (isAuthError(error)) {
41
- throw error;
42
- }
43
- throw new AuthError("invalid_request", error.message ?? message);
54
+ var AuthInternalError = class extends Error {
55
+ type = "AUTH_INTERNAL_ERROR";
56
+ code;
57
+ constructor(code, message, options2) {
58
+ super(message, options2);
59
+ this.code = code;
60
+ this.name = new.target.name;
61
+ Error.captureStackTrace(this, new.target);
44
62
  }
45
63
  };
46
- var ERROR_RESPONSE = {
47
- AUTHORIZATION: {
48
- INVALID_REQUEST: "invalid_request",
49
- UNAUTHORIZED_CLIENT: "unauthorized_client",
50
- ACCESS_DENIED: "access_denied",
51
- UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
52
- INVALID_SCOPE: "invalid_scope",
53
- SERVER_ERROR: "server_error",
54
- TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
55
- },
56
- ACCESS_TOKEN: {
57
- INVALID_REQUEST: "invalid_request",
58
- INVALID_CLIENT: "invalid_client",
59
- INVALID_GRANT: "invalid_grant",
60
- UNAUTHORIZED_CLIENT: "unauthorized_client",
61
- UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
62
- INVALID_SCOPE: "invalid_scope"
64
+
65
+ // src/utils.ts
66
+ var formatZodError = (error) => {
67
+ if (!error.issues || error.issues.length === 0) {
68
+ return {};
63
69
  }
70
+ return error.issues.reduce((previous, issue) => {
71
+ const key = issue.path.join(".");
72
+ return {
73
+ ...previous,
74
+ [key]: {
75
+ code: issue.code,
76
+ message: issue.message
77
+ }
78
+ };
79
+ }, {});
64
80
  };
65
81
 
66
82
  // src/schemas.ts
67
- var import_v4 = require("zod/v4");
68
- var OAuthProviderConfigSchema = (0, import_v4.object)({
69
- authorizeURL: (0, import_v4.url)(),
70
- accessToken: (0, import_v4.url)(),
71
- scope: (0, import_v4.string)().optional(),
72
- userInfo: (0, import_v4.url)(),
73
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
74
- clientId: (0, import_v4.string)(),
75
- clientSecret: (0, import_v4.string)()
83
+ var import_zod = require("zod");
84
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
85
+ authorizeURL: (0, import_zod.string)().url(),
86
+ accessToken: (0, import_zod.string)().url(),
87
+ scope: (0, import_zod.string)().optional(),
88
+ userInfo: (0, import_zod.string)().url(),
89
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
90
+ clientId: (0, import_zod.string)(),
91
+ clientSecret: (0, import_zod.string)()
76
92
  });
77
93
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
78
- redirectURI: (0, import_v4.string)(),
79
- state: (0, import_v4.string)(),
80
- codeChallenge: (0, import_v4.string)(),
81
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
94
+ redirectURI: (0, import_zod.string)(),
95
+ state: (0, import_zod.string)(),
96
+ codeChallenge: (0, import_zod.string)(),
97
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
82
98
  });
83
- var OAuthAuthorizationResponse = (0, import_v4.object)({
84
- state: (0, import_v4.string)(),
85
- code: (0, import_v4.string)()
99
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
100
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
101
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
86
102
  });
87
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
88
- error: (0, import_v4.enum)([
103
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
104
+ error: (0, import_zod.enum)([
89
105
  "invalid_request",
90
106
  "unauthorized_client",
91
107
  "access_denied",
@@ -94,24 +110,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
94
110
  "server_error",
95
111
  "temporarily_unavailable"
96
112
  ]),
97
- error_description: (0, import_v4.string)().optional(),
98
- error_uri: (0, import_v4.string)().optional(),
99
- state: (0, import_v4.string)()
113
+ error_description: (0, import_zod.string)().optional(),
114
+ error_uri: (0, import_zod.string)().optional(),
115
+ state: (0, import_zod.string)()
100
116
  });
101
117
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
102
- redirectURI: (0, import_v4.string)(),
103
- code: (0, import_v4.string)(),
104
- codeVerifier: (0, import_v4.string)().min(43).max(128)
118
+ redirectURI: (0, import_zod.string)(),
119
+ code: (0, import_zod.string)(),
120
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
105
121
  });
106
- var OAuthAccessTokenResponse = (0, import_v4.object)({
107
- access_token: (0, import_v4.string)(),
108
- token_type: (0, import_v4.string)(),
109
- expires_in: (0, import_v4.number)().optional(),
110
- refresh_token: (0, import_v4.string)().optional(),
111
- scope: (0, import_v4.string)().optional()
122
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
123
+ access_token: (0, import_zod.string)(),
124
+ token_type: (0, import_zod.string)().optional(),
125
+ expires_in: (0, import_zod.number)().optional(),
126
+ refresh_token: (0, import_zod.string)().optional(),
127
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
112
128
  });
113
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
114
- error: (0, import_v4.enum)([
129
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
130
+ error: (0, import_zod.enum)([
115
131
  "invalid_request",
116
132
  "invalid_client",
117
133
  "invalid_grant",
@@ -119,23 +135,28 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
119
135
  "unsupported_grant_type",
120
136
  "invalid_scope"
121
137
  ]),
122
- error_description: (0, import_v4.string)().optional(),
123
- error_uri: (0, import_v4.string)().optional()
138
+ error_description: (0, import_zod.string)().optional(),
139
+ error_uri: (0, import_zod.string)().optional()
140
+ });
141
+ var OAuthErrorResponse = (0, import_zod.object)({
142
+ error: (0, import_zod.string)(),
143
+ error_description: (0, import_zod.string)().optional()
124
144
  });
125
- var OAuthErrorResponse = (0, import_v4.object)({
126
- error: (0, import_v4.string)(),
127
- error_description: (0, import_v4.string)().optional()
145
+ var OAuthEnvSchema = (0, import_zod.object)({
146
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
147
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
128
148
  });
129
149
 
130
150
  // src/actions/callback/access-token.ts
131
151
  var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
132
152
  const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
133
153
  if (!parsed.success) {
134
- throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Invalid OAuth configuration");
154
+ const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
155
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
135
156
  }
136
157
  const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
137
158
  try {
138
- const response = await fetch(accessToken, {
159
+ const response = await fetchAsync(accessToken, {
139
160
  method: "POST",
140
161
  headers: {
141
162
  Accept: "application/json",
@@ -155,13 +176,13 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
155
176
  if (!token.success) {
156
177
  const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
157
178
  if (!success) {
158
- throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_GRANT, "Invalid access token response format");
179
+ throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
159
180
  }
160
- throw new AuthError(data.error, data?.error_description ?? "Failed to retrieve access token");
181
+ throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
161
182
  }
162
183
  return token.data;
163
184
  } catch (error) {
164
- throw throwAuthError(error, "Failed to create access token");
185
+ throw error;
165
186
  }
166
187
  };
167
188
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,9 +1,9 @@
1
- import { f as OAuthProviderCredentials } from '../../index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
1
+ import { h as OAuthProviderCredentials } from '../../index-DkaLJFn8.js';
2
+ import 'zod';
4
3
  import '../../schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
7
  import '../../@types/utility.js';
8
8
 
9
9
  /**
@@ -19,10 +19,10 @@ import '../../@types/utility.js';
19
19
  */
20
20
  declare const createAccessToken: (oauthConfig: OAuthProviderCredentials, redirectURI: string, code: string, codeVerifier: string) => Promise<{
21
21
  access_token: string;
22
- token_type: string;
22
+ token_type?: string | undefined;
23
23
  expires_in?: number | undefined;
24
24
  refresh_token?: string | undefined;
25
- scope?: string | undefined;
25
+ scope?: string | null | undefined;
26
26
  }>;
27
27
 
28
28
  export { createAccessToken };
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  createAccessToken
3
- } from "../../chunk-UJJ7R56J.js";
4
- import "../../chunk-FJUDBLCP.js";
5
- import "../../chunk-HMRKN75I.js";
3
+ } from "../../chunk-GA2SMTJO.js";
4
+ import "../../chunk-CXLATHS5.js";
5
+ import "../../chunk-RRLIF4PQ.js";
6
+ import "../../chunk-ZNCZVF6U.js";
7
+ import "../../chunk-YRCB5FLE.js";
6
8
  export {
7
9
  createAccessToken
8
10
  };