@absolutejs/auth 0.17.4 → 0.17.6

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.
@@ -19,7 +19,7 @@ export declare const absoluteAuth: <UserType>({ providersConfiguration, authoriz
19
19
  } | {
20
20
  readonly code: "Unauthorized";
21
21
  readonly message: "User is not authenticated";
22
- }) => Promise<Response | import("./types").StatusReturn>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required", unknown, number> | import("elysia/error").ElysiaCustomStatusResponse<"Bad Request" | "Internal Server Error", "Cookies are missing" | `Error: ${string} - ${string}` | `Unknown Error: ${string}`, 400 | 500> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "User is not authenticated", 401>>;
22
+ }) => Promise<Response | import("./types").StatusReturn>) => Promise<Response | import("./types").StatusReturn | import("elysia/error").ElysiaCustomStatusResponse<"Bad Request" | "Internal Server Error", "Cookies are missing" | `Error: ${string} - ${string}` | `Unknown Error: ${string}`, 400 | 500> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "User is not authenticated", 401>>;
23
23
  };
24
24
  resolve: {};
25
25
  }, {
@@ -12,7 +12,7 @@ export declare const protectRoute: <UserType>() => Elysia<"", {
12
12
  unregisteredSession: import("./types").UnregisteredSessionRecord;
13
13
  };
14
14
  derive: {
15
- readonly protectRoute: (handleAuth: (user: UserType) => Promise<Response | StatusReturn>, handleAuthFail?: (error: AuthFailError) => Promise<Response | StatusReturn>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required", unknown, number> | import("elysia/error").ElysiaCustomStatusResponse<"Bad Request" | "Internal Server Error", "Cookies are missing" | `Error: ${string} - ${string}` | `Unknown Error: ${string}`, 400 | 500> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "User is not authenticated", 401>>;
15
+ readonly protectRoute: (handleAuth: (user: UserType) => Promise<Response | StatusReturn>, handleAuthFail?: (error: AuthFailError) => Promise<Response | StatusReturn>) => Promise<Response | StatusReturn | import("elysia/error").ElysiaCustomStatusResponse<"Bad Request" | "Internal Server Error", "Cookies are missing" | `Error: ${string} - ${string}` | `Unknown Error: ${string}`, 400 | 500> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "User is not authenticated", 401>>;
16
16
  };
17
17
  resolve: {};
18
18
  }, {
@@ -1,5 +1,6 @@
1
1
  import { CredentialsFor, NonEmptyArray, OAuth2Client, OAuth2TokenResponse, ProviderOption, ProvidersMap } from 'citra';
2
2
  import { Cookie, status as statusType, redirect as redirectType } from 'elysia';
3
+ import { ElysiaCustomStatusResponse } from 'elysia/error';
3
4
  type SessionData<UserType> = {
4
5
  user: UserType;
5
6
  accessToken: string;
@@ -21,7 +22,7 @@ export type UnregisteredSessionRecord = Record<string, {
21
22
  userIdentity: Record<string, unknown>;
22
23
  expiresAt: number;
23
24
  }>;
24
- export type OnNewUser<UserType> = (userIdentity: Record<string, unknown>) => UserType | Response | StatusReturn | Promise<UserType | Response | StatusReturn>;
25
+ export type OnNewUser<UserType> = <Text extends AllowedStatusText, Body extends AllowedBody>(userIdentity: Record<string, unknown>) => Response | StatusReturn<Text, Body> | UserType | Promise<Response | StatusReturn<Text, Body> | UserType>;
25
26
  export type GetUser<UserType> = (userIdentity: Record<string, unknown>) => UserType | null | undefined | Promise<UserType | null | undefined>;
26
27
  export type CallbackCookie = Record<string, Cookie<string | undefined>> & {
27
28
  user_session_id: Cookie<`${string}-${string}-${string}-${string}-${string}` | undefined>;
@@ -90,7 +91,10 @@ export type GetStatusProps<UserType> = {
90
91
  session: SessionRecord<UserType>;
91
92
  onStatus?: OnStatus<UserType>;
92
93
  };
93
- export type StatusReturn = ReturnType<typeof statusType>;
94
+ type AllowedStatusText = Parameters<typeof statusType>[0];
95
+ type AllowedBody = Parameters<typeof statusType>[1];
96
+ type StatusCodeFor<Text extends AllowedStatusText> = ReturnType<typeof statusType> extends ElysiaCustomStatusResponse<Text, infer InferredBody, infer InferredCode> ? [InferredBody] extends [unknown] ? InferredCode : never : never;
97
+ export type StatusReturn<Text extends AllowedStatusText = AllowedStatusText, Body extends AllowedBody = AllowedBody> = ElysiaCustomStatusResponse<Text, Body, StatusCodeFor<Text>>;
94
98
  export type AbsoluteAuthProps<UserType> = {
95
99
  providersConfiguration: OAuth2ConfigurationOptions;
96
100
  authorizeRoute?: AuthorizeRoute;
@@ -1,5 +1,5 @@
1
1
  import { AbsoluteAuthProps, GetStatusProps, InsantiateUserSessionProps, OAuth2ConfigurationOptions } from './types';
2
- export declare const instantiateUserSession: <UserType>({ userSessionId, authProvider, session, unregisteredSession, tokenResponse, providerInstance, getUser, onNewUser }: InsantiateUserSessionProps<UserType>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required", unknown, number> | undefined>;
2
+ export declare const instantiateUserSession: <UserType>({ userSessionId, authProvider, session, unregisteredSession, tokenResponse, providerInstance, getUser, onNewUser }: InsantiateUserSessionProps<UserType>) => Promise<Response | import("./types").StatusReturn<number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required", unknown> | undefined>;
3
3
  export declare const createAuthConfiguration: <UserType>(configuration: AbsoluteAuthProps<UserType>) => AbsoluteAuthProps<UserType>;
4
4
  export declare const createProvidersConfiguration: (providersConfiguration: OAuth2ConfigurationOptions) => OAuth2ConfigurationOptions;
5
5
  export declare const getStatus: <UserType>({ user_session_id, session, onStatus }: GetStatusProps<UserType>) => Promise<{
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.17.4",
2
+ "version": "0.17.6",
3
3
  "name": "@absolutejs/auth",
4
4
  "description": "An authorization library for absolutejs",
5
5
  "repository": {