@absolutejs/auth 0.0.2 → 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.
@@ -1,5 +1,5 @@
1
- import Elysia from 'elysia';
2
- import type { ClientProviders, OAuthEventHandler } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { ClientProviders, OAuthEventHandler } from './types';
3
3
  type AuthorizeProps = {
4
4
  clientProviders: ClientProviders;
5
5
  authorizeRoute?: string;
@@ -31,7 +31,7 @@ export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize
31
31
  response: {
32
32
  200: import("undici-types").Response;
33
33
  400: "Provider is required" | "Invalid provider";
34
- 500: "Internal Server Error";
34
+ 500: `Failed to authorize: ${string}` | `Unknown error: ${string}`;
35
35
  422: {
36
36
  type: "validation";
37
37
  on: string;
@@ -1,5 +1,5 @@
1
- import Elysia from 'elysia';
2
- import type { ClientProviders, CreateUser, GetUser, OAuthEventHandler } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { ClientProviders, CreateUser, GetUser, OAuthEventHandler } from './types';
3
3
  type CallbackProps<UserType> = {
4
4
  clientProviders: ClientProviders;
5
5
  callbackRoute?: string;
@@ -10,13 +10,13 @@ type CallbackProps<UserType> = {
10
10
  export declare const callback: <UserType>({ clientProviders, callbackRoute, onCallback, getUser, createUser }: CallbackProps<UserType>) => Elysia<"", {
11
11
  decorator: {};
12
12
  store: {
13
- session: import("./types").SessionRecord<UserType_1>;
13
+ session: import("./types").SessionRecord<UserType>;
14
14
  };
15
15
  derive: {};
16
16
  resolve: {};
17
17
  }, {
18
18
  error: {};
19
- typebox: import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>;
19
+ typebox: import("@sinclair/typebox").TModule<{}, {}>;
20
20
  }, {
21
21
  schema: {};
22
22
  macro: {};
@@ -31,9 +31,9 @@ export declare const callback: <UserType>({ clientProviders, callbackRoute, onCa
31
31
  headers: unknown;
32
32
  response: {
33
33
  200: import("undici-types").Response;
34
- 400: "Invalid provider" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
35
- 500: "Internal Server Error" | "Invalid user schema";
36
- 401: "No auth provider found";
34
+ 400: "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
35
+ 401: "Invalid provider" | "No auth provider found";
36
+ 500: "Invalid user schema" | `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
37
37
  };
38
38
  };
39
39
  };
@@ -0,0 +1,8 @@
1
+ export declare const SECONDS_IN_A_MINUTE = 60;
2
+ export declare const MILLISECONDS_IN_A_SECOND = 1000;
3
+ export declare const MILLISECONDS_IN_A_MINUTE: number;
4
+ export declare const MINUTES_IN_AN_HOUR = 60;
5
+ export declare const HOURS_IN_A_DAY = 24;
6
+ export declare const MILLISECONDS_IN_A_DAY: number;
7
+ export declare const COOKIE_MINUTES = 30;
8
+ export declare const COOKIE_DURATION: number;
@@ -1,10 +1,10 @@
1
- import Elysia from 'elysia';
2
1
  import { OAuth2RequestError, ArcticFetchError } from 'arctic';
3
- import type { AbsoluteAuthProps } from './types';
4
- export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callbackRoute, logoutRoute, statusRoute, refreshRoute, revokeRoute, onAuthorize, onCallback, onStatus, onRefresh, onLogout, onRevoke, createUser, getUser }: AbsoluteAuthProps) => Elysia<"", {
2
+ import { Elysia } from 'elysia';
3
+ import { AbsoluteAuthProps } from './types';
4
+ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callbackRoute, logoutRoute, statusRoute, refreshRoute, revokeRoute, onAuthorize, onCallback, onStatus, onRefresh, onLogout, onRevoke, createUser, getUser }: AbsoluteAuthProps<UserType>) => Elysia<"", {
5
5
  decorator: {};
6
6
  store: {
7
- session: import("./types").SessionRecord<UserType_1>;
7
+ session: import("./types").SessionRecord<UserType> & import("./types").SessionRecord<unknown>;
8
8
  };
9
9
  derive: {};
10
10
  resolve: {};
@@ -13,7 +13,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
13
13
  OAUTH2_REQUEST_ERROR: OAuth2RequestError;
14
14
  ARCTIC_FETCH_ERROR: ArcticFetchError;
15
15
  };
16
- typebox: import("elysia/types").MergeTypeModule<import("elysia/types").MergeTypeModule<import("elysia/types").MergeTypeModule<import("elysia/types").MergeTypeModule<import("elysia/types").MergeTypeModule<import("elysia/types").MergeTypeModule<import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>, import("@sinclair/typebox").TModule<{}, {}>>, import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>>, import("@sinclair/typebox").TModule<{}, {}>>, import("@sinclair/typebox").TModule<{}, {}>>, import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>>, import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>>;
16
+ typebox: import("@sinclair/typebox").TModule<{}, {}>;
17
17
  }, {
18
18
  schema: {};
19
19
  macro: {};
@@ -28,8 +28,8 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
28
28
  headers: unknown;
29
29
  response: {
30
30
  200: Response;
31
- 500: "Internal Server Error";
32
31
  401: "No auth provider found";
32
+ 500: `Failed to logout: ${string}`;
33
33
  };
34
34
  };
35
35
  };
@@ -42,9 +42,10 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
42
42
  query: unknown;
43
43
  headers: unknown;
44
44
  response: {
45
- 200: undefined;
46
- 400: "Invalid provider";
45
+ 200: Response;
47
46
  401: "No auth provider found" | "No refresh token found";
47
+ 501: "Provider does not support revocation";
48
+ 500: `Failed to revoke token: ${string}`;
48
49
  };
49
50
  };
50
51
  };
@@ -58,7 +59,8 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
58
59
  headers: unknown;
59
60
  response: {
60
61
  200: Response;
61
- 500: "Internal Server Error";
62
+ 501: "Provider is not refreshable";
63
+ 500: `Error: ${string} - ${string}` | `Unknown Error: ${string}`;
62
64
  };
63
65
  };
64
66
  };
@@ -71,8 +73,9 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
71
73
  headers: unknown;
72
74
  response: {
73
75
  200: Response;
74
- 500: "Internal Server Error";
75
- 401: "No auth provider found" | "No refresh token found" | "Provider is not refreshable";
76
+ 401: "No auth provider found" | "No refresh token found";
77
+ 501: "Provider is not refreshable";
78
+ 500: `Failed to refresh token: ${string}` | `Faile to refresh token: Unknown error: ${string}`;
76
79
  };
77
80
  };
78
81
  };
@@ -89,7 +92,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
89
92
  response: {
90
93
  200: import("undici-types").Response;
91
94
  400: "Provider is required" | "Invalid provider";
92
- 500: "Internal Server Error";
95
+ 500: `Failed to authorize: ${string}` | `Unknown error: ${string}`;
93
96
  422: {
94
97
  type: "validation";
95
98
  on: string;
@@ -112,15 +115,15 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
112
115
  headers: unknown;
113
116
  response: {
114
117
  200: import("undici-types").Response;
115
- 400: "Invalid provider" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
116
- 500: "Internal Server Error" | "Invalid user schema";
117
- 401: "No auth provider found";
118
+ 400: "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
119
+ 401: "Invalid provider" | "No auth provider found";
120
+ 500: "Invalid user schema" | `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
118
121
  };
119
122
  };
120
123
  };
121
124
  }, {
122
125
  derive: {
123
- readonly protectRoute: (onAuth: () => Promise<Response>, onAuthFail?: (() => Promise<Response>) | undefined) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<401, "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<401, "No session found", 401>>;
126
+ readonly protectRoute: (handleAuth: () => Promise<Response>, handleAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session found", 401>>;
124
127
  };
125
128
  resolve: {};
126
129
  schema: import("elysia").MergeSchema<{
@@ -1,5 +1,5 @@
1
- import Elysia from 'elysia';
2
- import type { OAuthEventHandler } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { OAuthEventHandler } from './types';
3
3
  type LogoutProps = {
4
4
  logoutRoute?: string;
5
5
  onLogout?: OAuthEventHandler;
@@ -26,8 +26,8 @@ export declare const logout: ({ logoutRoute, onLogout }: LogoutProps) => Elysia<
26
26
  headers: unknown;
27
27
  response: {
28
28
  200: Response;
29
- 500: "Internal Server Error";
30
29
  401: "No auth provider found";
30
+ 500: `Failed to logout: ${string}`;
31
31
  };
32
32
  };
33
33
  };
@@ -1,14 +1,14 @@
1
- import Elysia from 'elysia';
1
+ import { Elysia } from 'elysia';
2
2
  export declare const protectRoute: <UserType>() => Elysia<"", {
3
3
  decorator: {};
4
4
  store: {
5
- session: import("./types").SessionRecord<UserType_1>;
5
+ session: import("./types").SessionRecord<UserType>;
6
6
  };
7
7
  derive: {};
8
8
  resolve: {};
9
9
  }, {
10
10
  error: {};
11
- typebox: import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>;
11
+ typebox: import("@sinclair/typebox").TModule<{}, {}>;
12
12
  }, {
13
13
  schema: {};
14
14
  macro: {};
@@ -16,7 +16,7 @@ export declare const protectRoute: <UserType>() => Elysia<"", {
16
16
  parser: {};
17
17
  }, {}, {
18
18
  derive: {
19
- readonly protectRoute: (onAuth: () => Promise<Response>, onAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<401, "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<401, "No session found", 401>>;
19
+ readonly protectRoute: (handleAuth: () => Promise<Response>, handleAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session found", 401>>;
20
20
  };
21
21
  resolve: {};
22
22
  schema: import("elysia").MergeSchema<{}, {}, "">;
@@ -1,5 +1,5 @@
1
1
  import { AmazonCognito, AniList, Apple, Atlassian, Auth0, Authentik, Bitbucket, Box, Coinbase, Discord, Dribbble, Dropbox, Facebook, Figma, Intuit, GitHub, GitLab, Google, Kakao, KeyCloak, Lichess, Line, Linear, LinkedIn, MicrosoftEntraId, MyAnimeList, Notion, Okta, Osu, Patreon, Reddit, Roblox, Salesforce, Shikimori, Slack, Spotify, Strava, Tiltify, Tumblr, Twitch, Twitter, VK, WorkOS, Yahoo, Yandex, Zoom, FortyTwo } from 'arctic';
2
- export type ProvidersMap = {
2
+ export declare const providers: {
3
3
  AmazonCognito: typeof AmazonCognito;
4
4
  AniList: typeof AniList;
5
5
  Apple: typeof Apple;
@@ -48,9 +48,4 @@ export type ProvidersMap = {
48
48
  Yandex: typeof Yandex;
49
49
  Zoom: typeof Zoom;
50
50
  };
51
- export declare const providers: ProvidersMap;
52
51
  export declare const normalizedProviderKeys: Record<string, string>;
53
- export declare const userInfoURLs: Record<string, string>;
54
- export declare const issuerURLs: Record<string, string>;
55
- export declare const normalizedUserInfoURLKeys: Record<string, string>;
56
- export declare const normalizedIssuerURLKeys: Record<string, string>;
@@ -1,5 +1,5 @@
1
- import Elysia from 'elysia';
2
- import type { ClientProviders, OAuthEventHandler } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { ClientProviders, OAuthEventHandler } from './types';
3
3
  type RefreshProps = {
4
4
  clientProviders: ClientProviders;
5
5
  refreshRoute?: string;
@@ -27,8 +27,9 @@ export declare const refresh: ({ clientProviders, refreshRoute, onRefresh }: Ref
27
27
  headers: unknown;
28
28
  response: {
29
29
  200: Response;
30
- 500: "Internal Server Error";
31
- 401: "No auth provider found" | "No refresh token found" | "Provider is not refreshable";
30
+ 401: "No auth provider found" | "No refresh token found";
31
+ 501: "Provider is not refreshable";
32
+ 500: `Failed to refresh token: ${string}` | `Faile to refresh token: Unknown error: ${string}`;
32
33
  };
33
34
  };
34
35
  };
@@ -1,5 +1,5 @@
1
- import Elysia from 'elysia';
2
- import type { ClientProviders, OAuthEventHandler } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { ClientProviders, OAuthEventHandler } from './types';
3
3
  type RevokeProps = {
4
4
  clientProviders: ClientProviders;
5
5
  revokeRoute?: string;
@@ -27,9 +27,10 @@ export declare const revoke: ({ clientProviders, revokeRoute, onRevoke }: Revoke
27
27
  query: unknown;
28
28
  headers: unknown;
29
29
  response: {
30
- 200: undefined;
31
- 400: "Invalid provider";
30
+ 200: Response;
32
31
  401: "No auth provider found" | "No refresh token found";
32
+ 501: "Provider does not support revocation";
33
+ 500: `Failed to revoke token: ${string}`;
33
34
  };
34
35
  };
35
36
  };
@@ -1,5 +1,5 @@
1
- import Elysia from 'elysia';
2
- import type { SessionRecord } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { SessionRecord } from './types';
3
3
  export declare const sessionStore: <UserType>() => Elysia<"", {
4
4
  decorator: {};
5
5
  store: {
@@ -1,19 +1,20 @@
1
- import Elysia from 'elysia';
2
- import type { OAuthEventHandler } from './types';
1
+ import { Elysia } from 'elysia';
2
+ import { ClientProviders, OAuthEventHandler } from './types';
3
3
  type StatusProps = {
4
+ clientProviders: ClientProviders;
4
5
  statusRoute?: string;
5
6
  onStatus?: OAuthEventHandler;
6
7
  };
7
- export declare const status: <UserType>({ statusRoute, onStatus }: StatusProps) => Elysia<"", {
8
+ export declare const status: <UserType>({ clientProviders, statusRoute, onStatus }: StatusProps) => Elysia<"", {
8
9
  decorator: {};
9
10
  store: {
10
- session: import("./types").SessionRecord<UserType_1>;
11
+ session: import("./types").SessionRecord<UserType>;
11
12
  };
12
13
  derive: {};
13
14
  resolve: {};
14
15
  }, {
15
16
  error: {};
16
- typebox: import("elysia/types").MergeTypeModule<import("@sinclair/typebox").TModule<{}, {}>, import("@sinclair/typebox").TModule<{}, {}>>;
17
+ typebox: import("@sinclair/typebox").TModule<{}, {}>;
17
18
  }, {
18
19
  schema: {};
19
20
  macro: {};
@@ -28,7 +29,8 @@ export declare const status: <UserType>({ statusRoute, onStatus }: StatusProps)
28
29
  headers: unknown;
29
30
  response: {
30
31
  200: Response;
31
- 500: "Internal Server Error";
32
+ 501: "Provider is not refreshable";
33
+ 500: `Error: ${string} - ${string}` | `Unknown Error: ${string}`;
32
34
  };
33
35
  };
34
36
  };
@@ -1,6 +1,6 @@
1
1
  import { OAuth2Tokens } from 'arctic';
2
- import { providers, userInfoURLs, issuerURLs } from './providers';
3
- import type { Providers } from './types';
2
+ import { providers } from './providers';
3
+ import { Providers } from './types';
4
4
  export declare const isRefreshableProvider: (provider: InstanceType<(typeof providers)[Providers]>) => provider is InstanceType<(typeof providers)[Providers]> & {
5
5
  refreshAccessToken: () => Promise<OAuth2Tokens>;
6
6
  };
@@ -8,6 +8,5 @@ export declare const isRevocableProvider: (provider: InstanceType<(typeof provid
8
8
  revokeAccessToken: (token: string) => Promise<void>;
9
9
  };
10
10
  export declare const isValidProviderKey: (provider: string) => provider is keyof typeof providers;
11
- export declare const isValidUserInfoURLKey: (userInfoURLKey: string) => userInfoURLKey is keyof typeof userInfoURLs;
12
- export declare const isValidIssuerURLKey: (issuerURLKey: string) => issuerURLKey is keyof typeof issuerURLs;
13
- export declare const isValidUser: <UserType>(user: any) => user is UserType;
11
+ export declare const isValidUser: <UserType>(user: unknown) => user is UserType;
12
+ export declare const isNonEmptyString: (str: string | null | undefined) => str is string;
@@ -1,17 +1,17 @@
1
1
  import { providers } from './providers';
2
- export type Providers = keyof typeof providers;
3
- export type SessionData<UserType> = {
2
+ type SessionData<UserType> = {
4
3
  user: UserType;
5
4
  expiresAt: number;
6
5
  };
7
- export type SessionRecord<UserType> = Record<string, SessionData<UserType> | undefined>;
8
- export type Oauth2ConfigOptions = {
6
+ type Oauth2ConfigOptions = {
9
7
  [K in Providers]?: {
10
8
  credentials: ConstructorParameters<(typeof providers)[K]>;
11
9
  scopes?: string[];
12
10
  searchParams?: [string, string][];
13
11
  };
14
12
  };
13
+ export type Providers = keyof typeof providers;
14
+ export type SessionRecord<UserType> = Record<string, SessionData<UserType> | undefined>;
15
15
  export type OAuthEventHandler = () => void;
16
16
  export type CreateUser<UserType> = ({ decodedIdToken, authProvider }: {
17
17
  decodedIdToken: {
@@ -25,7 +25,7 @@ export type GetUser<UserType> = ({ decodedIdToken, authProvider }: {
25
25
  };
26
26
  authProvider: string;
27
27
  }) => Promise<UserType | null>;
28
- export type AbsoluteAuthProps = {
28
+ export type AbsoluteAuthProps<UserType> = {
29
29
  config: Oauth2ConfigOptions;
30
30
  authorizeRoute?: string;
31
31
  callbackRoute?: string;
@@ -39,12 +39,12 @@ export type AbsoluteAuthProps = {
39
39
  onRefresh?: OAuthEventHandler;
40
40
  onLogout?: OAuthEventHandler;
41
41
  onRevoke?: OAuthEventHandler;
42
- createUser?: CreateUser<any>;
43
- getUser?: GetUser<any>;
42
+ createUser?: CreateUser<UserType>;
43
+ getUser?: GetUser<UserType>;
44
44
  };
45
45
  export type ClientProviders = Record<string, {
46
46
  providerInstance: InstanceType<(typeof providers)[Providers]>;
47
47
  scopes: string[];
48
48
  searchParams: [string, string][];
49
- userInfoURL?: string;
50
49
  }>;
50
+ export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.2",
2
+ "version": "0.1.0",
3
3
  "name": "@absolutejs/auth",
4
4
  "description": "An authorization library for absolutejs",
5
5
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "elysia",
26
26
  "oauth"
27
27
  ],
28
- "types": "dist/index.d.ts",
28
+ "types": "dist/src/index.d.ts",
29
29
  "dependencies": {
30
30
  "arctic": "3.6.0",
31
31
  "elysia": "1.2.25"