diff --git a/build/index.d.ts b/build/index.d.ts index 033c402..49c0af5 100644 --- a/build/index.d.ts +++ b/build/index.d.ts @@ -1,5 +1,6 @@ export * from './src/ai/stream'; export * from './src/auth/tokensPair'; +export * from './src/auth/oauth'; export * from './src/base/businessOperation/businessOperation'; export * from './src/billing/planProlongrationPayload'; export * from './src/base/event/affectedUser'; @@ -34,6 +35,7 @@ export * from './src/dbScheme/workspace'; export * from './src/dbScheme/bankCard'; export * from './src/dbScheme/sso'; export * from './src/dbScheme/projectEventGroupingPattern'; +export * from './src/dbScheme/oauthClient'; export * from './src/notifications/createProjectNotifications'; export * from './src/notifications/receiveTypes'; export * from './src/notifications/updateProjectNotifications'; diff --git a/build/index.js b/build/index.js index cc6ddf2..b56051b 100644 --- a/build/index.js +++ b/build/index.js @@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./src/ai/stream"), exports); __exportStar(require("./src/auth/tokensPair"), exports); +__exportStar(require("./src/auth/oauth"), exports); __exportStar(require("./src/base/businessOperation/businessOperation"), exports); __exportStar(require("./src/billing/planProlongrationPayload"), exports); __exportStar(require("./src/base/event/affectedUser"), exports); @@ -50,6 +51,7 @@ __exportStar(require("./src/dbScheme/workspace"), exports); __exportStar(require("./src/dbScheme/bankCard"), exports); __exportStar(require("./src/dbScheme/sso"), exports); __exportStar(require("./src/dbScheme/projectEventGroupingPattern"), exports); +__exportStar(require("./src/dbScheme/oauthClient"), exports); __exportStar(require("./src/notifications/createProjectNotifications"), exports); __exportStar(require("./src/notifications/receiveTypes"), exports); __exportStar(require("./src/notifications/updateProjectNotifications"), exports); diff --git a/build/src/auth/OAuth.d.ts b/build/src/auth/OAuth.d.ts new file mode 100644 index 0000000..78a642f --- /dev/null +++ b/build/src/auth/OAuth.d.ts @@ -0,0 +1,96 @@ +/** + * Possible {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-17#section-3.2.4 | OAuth error codes} + */ +export declare enum OAuthErrorCode { + /** + * The request is missing a required parameter, includes an unsupported parameter value + * (other than grant type), repeats a parameter, includes multiple credentials, utilizes + * more than one mechanism for authenticating the client, contains a code_verifier + * although no code_challenge was sent in the authorization request, or is otherwise malformed + */ + invalidRequest = "invalid_request", + /** + * Client authentication failed (e.g., unknown client, no client authentication included, + * or unsupported authentication method). + */ + invalidClient = "invalid_client", + /** + * The provided authorization grant (e.g., authorization code, resource owner credentials) + * or refresh token is invalid, expired, revoked, does not match the redirect URI used in + * the authorization request, or was issued to another client. + */ + invalidGrant = "invalid_grant", + /** + * The authenticated client is not authorized to use this authorization grant type + */ + unauthorizedClient = "unauthorized_client", + /** + * The authorization grant type is not supported by the authorization server + */ + unsupportedGrantType = "unsupported_grant_type", + /** + * requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner + */ + invalidScope = "invalid_scope" +} +/** + * Authorization request + */ +export interface OAuthRequest { + /** + * Client Identifier + */ + client_id: string; + /** + * Indicates the URL to return the user to after authorization is complete + */ + redirect_uri: string; + /** + * Opaque value used by the client to maintain state between the request and callback + */ + state?: string; + /** + * Base64-URL-encoded string of the SHA256 hash of the code verifier + */ + code_challenge: string; + /** + * The code challenge transformation method + */ + code_challenge_method: 'S256'; + /** + * Target service or resource to which access is being requested. + * MUST be an absolute URI + */ + resource?: string; + /** + * Additional access requested by the application + */ + scope?: string; + /** + * URL string that references a logo for the client + */ + logoUrl?: string; +} +/** + * Authorization response + */ +export interface OAuthResponse { + /** + * Indicates the URL to return the user to after authorization is complete. + * Populated with additional parameters + */ + redirect_uri: string; +} +/** + * Authorization error + */ +export interface OAuthError { + /** + * Error code + */ + error: OAuthErrorCode; + /** + * Optional text providing additional information + */ + error_description?: string; +} diff --git a/build/src/auth/OAuth.js b/build/src/auth/OAuth.js new file mode 100644 index 0000000..89f6374 --- /dev/null +++ b/build/src/auth/OAuth.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +; +; diff --git a/build/src/auth/mcp/authorizationEndpoint.d.ts b/build/src/auth/mcp/authorizationEndpoint.d.ts new file mode 100644 index 0000000..e0879e7 --- /dev/null +++ b/build/src/auth/mcp/authorizationEndpoint.d.ts @@ -0,0 +1,31 @@ +/** + * MCP Authorization Endpoint request body interface + */ +export interface AuthorizationEndpointRequest { + /** + * MCP Client Identifier + */ + client_id: string; + /** + * Indicates the URL to return the user to after authorization is complete + */ + redirect_uri: string; + /** + * Opaque value used by the client to maintain state between the request and callback + */ + state: string; + /** + * Base64-URL-encoded string of the SHA256 hash of the code verifier + */ + code_challenge: string; +} +/** + * MCP Authorization Endpoint response body interface + */ +export interface AuthorizationEndpointResponse { + /** + * Indicates the URL to return the user to after authorization is complete. + * Populated with additional parameters + */ + redirect_uri: string; +} diff --git a/build/src/auth/mcp/authorizationEndpoint.js b/build/src/auth/mcp/authorizationEndpoint.js new file mode 100644 index 0000000..89f6374 --- /dev/null +++ b/build/src/auth/mcp/authorizationEndpoint.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +; +; diff --git a/build/src/auth/oauth.d.ts b/build/src/auth/oauth.d.ts new file mode 100644 index 0000000..78a642f --- /dev/null +++ b/build/src/auth/oauth.d.ts @@ -0,0 +1,96 @@ +/** + * Possible {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-17#section-3.2.4 | OAuth error codes} + */ +export declare enum OAuthErrorCode { + /** + * The request is missing a required parameter, includes an unsupported parameter value + * (other than grant type), repeats a parameter, includes multiple credentials, utilizes + * more than one mechanism for authenticating the client, contains a code_verifier + * although no code_challenge was sent in the authorization request, or is otherwise malformed + */ + invalidRequest = "invalid_request", + /** + * Client authentication failed (e.g., unknown client, no client authentication included, + * or unsupported authentication method). + */ + invalidClient = "invalid_client", + /** + * The provided authorization grant (e.g., authorization code, resource owner credentials) + * or refresh token is invalid, expired, revoked, does not match the redirect URI used in + * the authorization request, or was issued to another client. + */ + invalidGrant = "invalid_grant", + /** + * The authenticated client is not authorized to use this authorization grant type + */ + unauthorizedClient = "unauthorized_client", + /** + * The authorization grant type is not supported by the authorization server + */ + unsupportedGrantType = "unsupported_grant_type", + /** + * requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner + */ + invalidScope = "invalid_scope" +} +/** + * Authorization request + */ +export interface OAuthRequest { + /** + * Client Identifier + */ + client_id: string; + /** + * Indicates the URL to return the user to after authorization is complete + */ + redirect_uri: string; + /** + * Opaque value used by the client to maintain state between the request and callback + */ + state?: string; + /** + * Base64-URL-encoded string of the SHA256 hash of the code verifier + */ + code_challenge: string; + /** + * The code challenge transformation method + */ + code_challenge_method: 'S256'; + /** + * Target service or resource to which access is being requested. + * MUST be an absolute URI + */ + resource?: string; + /** + * Additional access requested by the application + */ + scope?: string; + /** + * URL string that references a logo for the client + */ + logoUrl?: string; +} +/** + * Authorization response + */ +export interface OAuthResponse { + /** + * Indicates the URL to return the user to after authorization is complete. + * Populated with additional parameters + */ + redirect_uri: string; +} +/** + * Authorization error + */ +export interface OAuthError { + /** + * Error code + */ + error: OAuthErrorCode; + /** + * Optional text providing additional information + */ + error_description?: string; +} diff --git a/build/src/auth/oauth.js b/build/src/auth/oauth.js new file mode 100644 index 0000000..89f6374 --- /dev/null +++ b/build/src/auth/oauth.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +; +; diff --git a/build/src/dbScheme/oauthClient.d.ts b/build/src/dbScheme/oauthClient.d.ts new file mode 100644 index 0000000..59da10b --- /dev/null +++ b/build/src/dbScheme/oauthClient.d.ts @@ -0,0 +1,46 @@ +import type { ObjectId, Timestamp } from 'bson'; +/** + * Permissions granted to token + */ +export type TokenPermissions = 'read' | 'write'; +/** + * Database representation of active to oauth client + */ +export interface OAuthClientDBScheme { + /** + * External client identifier + */ + _id: ObjectId; + /** + * Token owner id + */ + userId: string; + /** + * User agent id + */ + clientId: string; + /** + * Unique JSON Web Token Identifier + */ + jti: string; + /** + * What client is allowed to do + */ + permissions: TokenPermissions[]; + /** + * Label set by user + */ + lable: string; + /** + * Last time the client interacted with hawk api + */ + lastUsedAt: Timestamp | null; + /** + * Usage count + */ + requestCount: number; + /** + * Creation date + */ + createdAt: Timestamp; +} diff --git a/build/src/dbScheme/oauthClient.js b/build/src/dbScheme/oauthClient.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/build/src/dbScheme/oauthClient.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/src/dbScheme/thirdparty.d.ts b/build/src/dbScheme/thirdparty.d.ts new file mode 100644 index 0000000..c0c97e0 --- /dev/null +++ b/build/src/dbScheme/thirdparty.d.ts @@ -0,0 +1,46 @@ +import type { ObjectId, Timestamp } from 'bson'; +/** + * Permissions granted to token + */ +export type TokenPermissions = 'read' | 'write'; +/** + * Database representation of active to third-party clients + */ +export interface ThirdpartyDBScheme { + /** + * External token identifier + */ + _id: ObjectId; + /** + * Token owner id + */ + userId: string; + /** + * Unique JSON Web Token Identifier + */ + jti: string; + /** + * Last characters of the token, used to tell tokens apart in user settings + */ + preview: string; + /** + * What token can be used for + */ + permissions: TokenPermissions[]; + /** + * Label set by user + */ + lable: string; + /** + * Last time token was used + */ + lastUsedAt: Timestamp | null; + /** + * Usage count + */ + requestCount: number; + /** + * Creation date + */ + createdAt: Timestamp; +} diff --git a/build/src/dbScheme/thirdparty.js b/build/src/dbScheme/thirdparty.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/build/src/dbScheme/thirdparty.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/index.ts b/index.ts index c11e6e3..0af41f9 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,7 @@ export * from './src/ai/stream'; export * from './src/auth/tokensPair'; +export * from './src/auth/oauth'; export * from './src/base/businessOperation/businessOperation'; @@ -40,6 +41,7 @@ export * from './src/dbScheme/workspace'; export * from './src/dbScheme/bankCard'; export * from './src/dbScheme/sso'; export * from './src/dbScheme/projectEventGroupingPattern'; +export * from './src/dbScheme/oauthClient'; export * from './src/notifications/createProjectNotifications'; export * from './src/notifications/receiveTypes'; diff --git a/package.json b/package.json index 4768fa1..3300df1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hawk.so/types", - "version": "0.9.0", + "version": "0.9.1", "description": "TypeScript definitions for Hawk", "types": "build/index.d.ts", "main": "build/index.js", diff --git a/src/auth/oauth.ts b/src/auth/oauth.ts new file mode 100644 index 0000000..e33efa2 --- /dev/null +++ b/src/auth/oauth.ts @@ -0,0 +1,112 @@ +/** + * Possible {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-17#section-3.2.4 | OAuth error codes} + */ +export declare enum OAuthErrorCode { + /** + * The request is missing a required parameter, includes an unsupported parameter value + * (other than grant type), repeats a parameter, includes multiple credentials, utilizes + * more than one mechanism for authenticating the client, contains a code_verifier + * although no code_challenge was sent in the authorization request, or is otherwise malformed + */ + invalidRequest = 'invalid_request', + + /** + * Client authentication failed (e.g., unknown client, no client authentication included, + * or unsupported authentication method). + */ + invalidClient = 'invalid_client', + + /** + * The provided authorization grant (e.g., authorization code, resource owner credentials) + * or refresh token is invalid, expired, revoked, does not match the redirect URI used in + * the authorization request, or was issued to another client. + */ + invalidGrant = 'invalid_grant', + + /** + * The authenticated client is not authorized to use this authorization grant type + */ + unauthorizedClient = 'unauthorized_client', + + /** + * The authorization grant type is not supported by the authorization server + */ + unsupportedGrantType = 'unsupported_grant_type', + + /** + * requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner + */ + invalidScope = 'invalid_scope' +} + +/** + * Authorization request + */ +export interface OAuthRequest { + /** + * Client Identifier + */ + client_id: string; + + /** + * Indicates the URL to return the user to after authorization is complete + */ + redirect_uri: string; + + /** + * Opaque value used by the client to maintain state between the request and callback + */ + state?: string; + + /** + * Base64-URL-encoded string of the SHA256 hash of the code verifier + */ + code_challenge: string; + + /** + * The code challenge transformation method + */ + code_challenge_method: 'S256'; + + /** + * Target service or resource to which access is being requested. + * MUST be an absolute URI + */ + resource?: string; + + /** + * Additional access requested by the application + */ + scope?: string; + + /** + * URL string that references a logo for the client + */ + logoUrl?: string; +}; + +/** + * Authorization response + */ +export interface OAuthResponse { + /** + * Indicates the URL to return the user to after authorization is complete. + * Populated with additional parameters + */ + redirect_uri: string; +}; + +/** + * Authorization error + */ +export interface OAuthError { + /** + * Error code + */ + error: OAuthErrorCode; + + /** + * Optional text providing additional information + */ + error_description?: string; +} diff --git a/src/dbScheme/oauthClient.ts b/src/dbScheme/oauthClient.ts new file mode 100644 index 0000000..cc2a7b9 --- /dev/null +++ b/src/dbScheme/oauthClient.ts @@ -0,0 +1,56 @@ +import type { ObjectId, Timestamp } from 'bson'; + +/** + * Permissions granted to token + */ +export type TokenPermissions = 'read' | 'write'; + +/** + * Database representation of active to oauth client + */ +export interface OAuthClientDBScheme { + /** + * External client identifier + */ + _id: ObjectId; + + /** + * Token owner id + */ + userId: string; + + /** + * User agent id + */ + clientId: string; + + /** + * Unique JSON Web Token Identifier + */ + jti: string; + + /** + * What client is allowed to do + */ + permissions: TokenPermissions[]; + + /** + * Label set by user + */ + lable: string; + + /** + * Last time the client interacted with hawk api + */ + lastUsedAt: Timestamp | null; + + /** + * Usage count + */ + requestCount: number; + + /** + * Creation date + */ + createdAt: Timestamp; +}