From dee538c61d83ab3ec46b223421eba69df4a987ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Baumruck?= Date: Thu, 7 Mar 2024 07:39:55 +0100 Subject: [PATCH 01/13] update api, by swagger changed --- scripts/data/swagger-spec.json | 681 +++++++++++++++++- src/api/query/articles/articles.ts | 79 +- src/api/query/auth-social/auth-social.msw.ts | 6 +- src/api/query/auth-social/auth-social.ts | 41 +- src/api/query/auth/auth.msw.ts | 28 +- src/api/query/auth/auth.ts | 323 ++++++++- src/api/query/files/files.ts | 46 +- src/api/query/health/health.msw.ts | 46 ++ src/api/query/health/health.ts | 81 +++ src/api/query/users/users.ts | 78 +- src/api/types/authEntity.ts | 2 +- .../types/authResendVerificationEmailDto.ts | 13 + src/api/types/errorEntity.ts | 17 + src/api/types/errorServerEntity.ts | 15 + src/api/types/errorTooManyRequestsEntity.ts | 15 + src/api/types/errorUnauthorizedEntity.ts | 15 + src/api/types/healthCheckInfoDto.ts | 18 + src/api/types/healthCheckStatusDto.ts | 13 + src/api/types/healthEntity.ts | 21 + src/api/types/healthEntityError.ts | 13 + src/api/types/index.ts | 9 + 21 files changed, 1452 insertions(+), 108 deletions(-) create mode 100644 src/api/query/health/health.msw.ts create mode 100644 src/api/query/health/health.ts create mode 100644 src/api/types/authResendVerificationEmailDto.ts create mode 100644 src/api/types/errorEntity.ts create mode 100644 src/api/types/errorServerEntity.ts create mode 100644 src/api/types/errorTooManyRequestsEntity.ts create mode 100644 src/api/types/errorUnauthorizedEntity.ts create mode 100644 src/api/types/healthCheckInfoDto.ts create mode 100644 src/api/types/healthCheckStatusDto.ts create mode 100644 src/api/types/healthEntity.ts create mode 100644 src/api/types/healthEntityError.ts diff --git a/scripts/data/swagger-spec.json b/scripts/data/swagger-spec.json index 9128f619..e5f06c01 100644 --- a/scripts/data/swagger-spec.json +++ b/scripts/data/swagger-spec.json @@ -4,6 +4,8 @@ "/api/v1/articles": { "post": { "operationId": "ArticlesController_create", + "summary": "Create Article", + "description": "Creates a new article with the provided details.", "parameters": [], "requestBody": { "required": true, @@ -17,12 +19,20 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ArticleEntity" } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["articles"] }, "get": { "operationId": "ArticlesController_findAll", + "summary": "Find All Articles", + "description": "Retrieves a list of all articles with pagination support.", "parameters": [ { "name": "page", "required": true, "in": "query", "schema": { "type": "number" } }, { "name": "pageSize", "required": true, "in": "query", "schema": { "type": "number" } } @@ -38,6 +48,12 @@ } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["articles"] @@ -46,6 +62,8 @@ "/api/v1/articles/drafts": { "get": { "operationId": "ArticlesController_findDrafts", + "summary": "Find Draft Articles", + "description": "Retrieves a list of draft articles with pagination support.", "parameters": [ { "name": "page", "required": true, "in": "query", "schema": { "type": "number" } }, { "name": "pageSize", "required": true, "in": "query", "schema": { "type": "number" } } @@ -61,6 +79,12 @@ } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["articles"] @@ -69,6 +93,8 @@ "/api/v1/articles/{id}": { "get": { "operationId": "ArticlesController_findOne", + "summary": "Find Article by ID", + "description": "Retrieves an article by its unique identifier.", "parameters": [ { "name": "id", "required": true, "in": "path", "schema": { "type": "number" } } ], @@ -78,12 +104,20 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ArticleEntity" } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["articles"] }, "patch": { "operationId": "ArticlesController_update", + "summary": "Update Article", + "description": "Updates an article with the provided details.", "parameters": [ { "name": "id", "required": true, "in": "path", "schema": { "type": "number" } } ], @@ -99,22 +133,40 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ArticleEntity" } } } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["articles"] }, "delete": { "operationId": "ArticlesController_remove", + "summary": "Remove Article", + "description": "Deletes an article by its unique identifier.", "parameters": [ { "name": "id", "required": true, "in": "path", "schema": { "type": "number" } } ], - "responses": { "204": { "description": "" } }, + "responses": { + "204": { "description": "" }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["articles"] } }, "/api/v1/users": { "post": { "operationId": "UsersController_create", + "summary": "Create User", + "description": "Creates a new user.", "parameters": [], "requestBody": { "required": true, @@ -128,6 +180,26 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserEntity" } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["users"], @@ -135,6 +207,8 @@ }, "get": { "operationId": "UsersController_findAll", + "summary": "Find All Users", + "description": "Retrieves a list of all users.", "parameters": [ { "name": "page", "required": true, "in": "query", "schema": { "type": "number" } }, { "name": "pageSize", "required": true, "in": "query", "schema": { "type": "number" } } @@ -150,6 +224,26 @@ } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["users"], @@ -159,6 +253,8 @@ "/api/v1/users/{id}": { "get": { "operationId": "UsersController_findOne", + "summary": "Find User by ID", + "description": "Retrieves a user by its ID.", "parameters": [ { "name": "id", "required": true, "in": "path", "schema": { "type": "string" } } ], @@ -168,6 +264,26 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserEntity" } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["users"], @@ -175,6 +291,8 @@ }, "patch": { "operationId": "UsersController_update", + "summary": "Update User", + "description": "Updates a user with the provided details.", "parameters": [ { "name": "id", "required": true, "in": "path", "schema": { "type": "string" } } ], @@ -190,6 +308,26 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserEntity" } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["users"], @@ -197,6 +335,8 @@ }, "delete": { "operationId": "UsersController_remove", + "summary": "Remove User", + "description": "Deletes a user by their unique identifier.", "parameters": [ { "name": "id", "required": true, "in": "path", "schema": { "type": "string" } } ], @@ -206,6 +346,26 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserEntity" } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["users"], @@ -215,6 +375,8 @@ "/api/v1/auth/email/login": { "post": { "operationId": "AuthController_login", + "summary": "User Login", + "description": "Logs the user into the system and returns access tokens", "parameters": [], "requestBody": { "required": true, @@ -228,6 +390,34 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuthEntity" } } } + }, + "401": { + "description": "Unauthorized - Invalid credentials", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "403": { + "description": "Please activate your account before proceeding", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "429": { + "description": "ThrottlerException: Too Many Requests", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorTooManyRequestsEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth"] @@ -236,6 +426,8 @@ "/api/v1/auth/email/register": { "post": { "operationId": "AuthController_register", + "summary": "User Registration", + "description": "Registers a new user with email and password", "parameters": [ { "name": "Accept-Language", @@ -259,6 +451,21 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserEntity" } } } + }, + "400": { "description": "Bad Request - Missing or invalid registration details" }, + "429": { + "description": "ThrottlerException: Too Many Requests", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorTooManyRequestsEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth"] @@ -267,6 +474,8 @@ "/api/v1/auth/email/confirm": { "post": { "operationId": "AuthController_confirmEmail", + "summary": "Confirm Email", + "description": "Confirms the user's email address using the provided confirmation hash.", "parameters": [ { "name": "Accept-Language", @@ -282,13 +491,78 @@ "application/json": { "schema": { "$ref": "#/components/schemas/AuthConfirmEmailDto" } } } }, - "responses": { "200": { "description": "" } }, + "responses": { + "400": { "description": "Bad Request - Invalid or expired hash code" }, + "429": { + "description": "ThrottlerException: Too Many Requests", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorTooManyRequestsEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, + "tags": ["auth"] + } + }, + "/api/v1/auth/email/resend": { + "post": { + "operationId": "AuthController_resendVerificationEmail", + "summary": "Resend Verification Email", + "description": "Resend the verification email to the user's email address.", + "parameters": [ + { + "name": "Accept-Language", + "in": "header", + "description": "Specifies the preferred language for API responses. Supported values are: en (English), de (German), pl (Polish)", + "required": false, + "schema": { "type": "string" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AuthResendVerificationEmailDto" } + } + } + }, + "responses": { + "400": { + "description": "Bad Request - Invalid email format", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "429": { + "description": "ThrottlerException: Too Many Requests", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorTooManyRequestsEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["auth"] } }, "/api/v1/auth/forgot/password": { "post": { "operationId": "AuthController_forgotPassword", + "summary": "Forgot Password", + "description": "Initiates the password reset process by sending an email with a reset link to the user's email address.", "parameters": [ { "name": "Accept-Language", @@ -306,13 +580,36 @@ } } }, - "responses": { "200": { "description": "" } }, + "responses": { + "400": { + "description": "Bad Request - Invalid email format", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "429": { + "description": "ThrottlerException: Too Many Requests", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorTooManyRequestsEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["auth"] } }, "/api/v1/auth/reset/password": { "post": { "operationId": "AuthController_resetPassword", + "summary": "Reset Password", + "description": "Resets the user's password using the provided reset password hash.", "parameters": [], "requestBody": { "required": true, @@ -322,13 +619,36 @@ } } }, - "responses": { "204": { "description": "" } }, + "responses": { + "400": { + "description": "Bad Request - Invalid or expired hash code", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "429": { + "description": "ThrottlerException: Too Many Requests", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorTooManyRequestsEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["auth"] } }, "/api/v1/auth/me": { "get": { "operationId": "AuthController_me", + "summary": "Get Current User", + "description": "Retrieves information about the current authenticated user", "parameters": [], "responses": { "201": { @@ -336,6 +656,20 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserEntity" } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth"], @@ -343,6 +677,8 @@ }, "patch": { "operationId": "AuthController_update", + "summary": "Update Current User", + "description": "Updates information about the current authenticated user", "parameters": [], "requestBody": { "required": true, @@ -350,14 +686,53 @@ "application/json": { "schema": { "$ref": "#/components/schemas/AuthUpdateDto" } } } }, - "responses": { "200": { "description": "" } }, + "responses": { + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "404": { "description": "User not found" }, + "422": { + "description": "Missing old password / Incorrect old password / Missing password", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["auth"], "security": [{ "bearer": [] }] }, "delete": { "operationId": "AuthController_delete", + "summary": "Delete Current User", + "description": "Deletes the current authenticated user", "parameters": [], - "responses": { "204": { "description": "" } }, + "responses": { + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["auth"], "security": [{ "bearer": [] }] } @@ -365,6 +740,8 @@ "/api/v1/auth/refresh": { "post": { "operationId": "AuthController_refresh", + "summary": "Refresh Access Token", + "description": "Refreshes the access token using the refresh token", "parameters": [], "responses": { "201": { @@ -372,6 +749,20 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RefreshEntity" } } } + }, + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth"], @@ -381,8 +772,51 @@ "/api/v1/auth/logout": { "post": { "operationId": "AuthController_logout", + "summary": "Logout", + "description": "Logs the user out of the system", + "parameters": [], + "responses": { + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, + "tags": ["auth"], + "security": [{ "bearer": [] }] + } + }, + "/api/v1/auth/logout/all": { + "post": { + "operationId": "AuthController_logoutAll", + "summary": "Logout all sessions", + "description": "Logs the user out of all active sessions to enhance security in case of unauthorized access or when changing sensitive account information like passwords", "parameters": [], - "responses": { "204": { "description": "" } }, + "responses": { + "401": { + "description": "Unauthorized", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorUnauthorizedEntity" } + } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } + } + }, "tags": ["auth"], "security": [{ "bearer": [] }] } @@ -390,6 +824,8 @@ "/api/v1/files/upload": { "post": { "operationId": "FilesController_uploadFile", + "summary": "Upload File", + "description": "Uploads a file with a specified category.", "parameters": [], "requestBody": { "required": true, @@ -411,7 +847,9 @@ "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FileEntity" } } } - } + }, + "422": { "description": "Unprocessable Entity - No file selected or missing user ID." }, + "500": { "description": "Internal server error" } }, "tags": ["files"], "security": [{ "bearer": [] }] @@ -420,19 +858,33 @@ "/api/v1/files/{fileName}": { "get": { "operationId": "FilesController_download", + "summary": "Download File", + "description": "Downloads the specified file.", "parameters": [ { "name": "fileName", "required": true, "in": "path", "schema": { "type": "string" } } ], - "responses": { "200": { "description": "" } }, + "responses": { + "403": { + "description": "Forbidden - You do not have permission to view this file or file does not exist." + }, + "500": { "description": "Internal server error" } + }, "tags": ["files"], "security": [{ "bearer": [] }] }, "delete": { "operationId": "FilesController_deleteFile", + "summary": "Delete File", + "description": "Deletes the specified file.", "parameters": [ { "name": "fileName", "required": true, "in": "path", "schema": { "type": "string" } } ], - "responses": { "200": { "description": "" } }, + "responses": { + "403": { + "description": "Forbidden - You do not have permission to delete this file or file does not exist." + }, + "500": { "description": "Internal server error" } + }, "tags": ["files"], "security": [{ "bearer": [] }] } @@ -440,6 +892,8 @@ "/api/v1/auth/google/login": { "post": { "operationId": "AuthGoogleController_login", + "summary": "Login with Google", + "description": "Logs the user into the system using Google authentication", "parameters": [], "requestBody": { "required": true, @@ -449,10 +903,28 @@ }, "responses": { "201": { - "description": "", + "description": "Successfully logged in with Google", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuthEntity" } } } + }, + "400": { + "description": "Bad Request - Error during Google token verification or processing", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "422": { + "description": "Unprocessable Entity - Invalid or expired Google token", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth-social"] @@ -461,6 +933,8 @@ "/api/v1/auth/facebook/login": { "post": { "operationId": "AuthFacebookController_login", + "summary": "Login with Facebook", + "description": "Logs the user into the system using Facebook authentication", "parameters": [], "requestBody": { "required": true, @@ -472,10 +946,28 @@ }, "responses": { "201": { - "description": "", + "description": "Successfully logged in with Facebook", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuthEntity" } } } + }, + "400": { + "description": "Bad Request - Error during Facebook token verification or processing", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "422": { + "description": "Unprocessable Entity - Invalid or expired Facebook token", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth-social"] @@ -484,6 +976,8 @@ "/api/v1/auth/apple/login": { "post": { "operationId": "AuthAppleController_login", + "summary": "Login with Apple", + "description": "Logs the user into the system using Apple authentication", "parameters": [], "requestBody": { "required": true, @@ -493,14 +987,56 @@ }, "responses": { "201": { - "description": "", + "description": "Successfully logged in with Apple", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AuthEntity" } } } + }, + "400": { + "description": "Bad Request - Error during Apple token verification or processing", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "422": { + "description": "Unprocessable Entity - Invalid or expired Apple token", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorServerEntity" } } + } } }, "tags": ["auth-social"] } + }, + "/api/v1/health": { + "get": { + "operationId": "HealthController_check", + "summary": "Check Health", + "description": "Performs a health check, verifying the database, frontend domain, and cache connectivity.", + "parameters": [], + "responses": { + "200": { + "description": "The health check result.", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/HealthEntity" } } + } + }, + "500": { + "description": "Internal server error", + "content": { + "application/json": { "schema": { "$ref": "#/components/schemas/ErrorEntity" } } + } + }, + "503": { "description": "One or more health checks failed" } + }, + "tags": ["health"] + } } }, "info": { @@ -522,6 +1058,18 @@ "components": { "securitySchemes": { "bearer": { "scheme": "bearer", "bearerFormat": "JWT", "type": "http" } }, "schemas": { + "ErrorServerEntity": { + "type": "object", + "properties": { + "error": { "type": "string", "description": "Type of error", "example": "Server Error" }, + "statusCode": { + "type": "number", + "description": "HTTP status code indicating the error", + "example": 500 + } + }, + "required": ["error", "statusCode"] + }, "CreateArticleDto": { "type": "object", "properties": { @@ -575,6 +1123,35 @@ "published": { "type": "boolean", "default": false } } }, + "ErrorUnauthorizedEntity": { + "type": "object", + "properties": { + "error": { "type": "string", "description": "Type of error", "example": "Unauthorized" }, + "statusCode": { + "type": "number", + "description": "HTTP status code indicating the error", + "example": 401 + } + }, + "required": ["error", "statusCode"] + }, + "ErrorEntity": { + "type": "object", + "properties": { + "message": { + "type": "string", + "description": "Message describing the error", + "example": "An error occurred while processing your request" + }, + "error": { "type": "string", "description": "Type of error", "example": "Forbidden" }, + "statusCode": { + "type": "number", + "description": "HTTP status code indicating the error", + "example": 403 + } + }, + "required": ["message", "error", "statusCode"] + }, "RoleDto": { "type": "object", "properties": { @@ -816,7 +1393,7 @@ "example": "eyJhb...adQssw5c" }, "tokenExpires": { - "type": "string", + "type": "number", "description": "The expiry timestamp of the access token.", "example": 1708531622031 }, @@ -827,6 +1404,22 @@ }, "required": ["accessToken", "refreshToken", "tokenExpires", "user"] }, + "ErrorTooManyRequestsEntity": { + "type": "object", + "properties": { + "error": { + "type": "string", + "description": "Type of error", + "example": "ThrottlerException: Too Many Requests" + }, + "statusCode": { + "type": "number", + "description": "HTTP status code indicating the error", + "example": 429 + } + }, + "required": ["error", "statusCode"] + }, "AuthRegisterLoginDto": { "type": "object", "properties": { @@ -863,6 +1456,17 @@ }, "required": ["hash"] }, + "AuthResendVerificationEmailDto": { + "type": "object", + "properties": { + "email": { + "type": "string", + "example": "example@binarapps.com", + "description": "The email address associated with the user account." + } + }, + "required": ["email"] + }, "AuthForgotPasswordDto": { "type": "object", "properties": { @@ -1032,6 +1636,55 @@ } }, "required": ["idToken"] + }, + "HealthCheckStatusDto": { + "type": "object", + "properties": { + "status": { + "type": "string", + "description": "The status of the component", + "example": "up" + } + }, + "required": ["status"] + }, + "HealthCheckInfoDto": { + "type": "object", + "properties": { + "db": { + "description": "The status of the database connection", + "allOf": [{ "$ref": "#/components/schemas/HealthCheckStatusDto" }] + }, + "domain": { + "description": "The status of the domain", + "allOf": [{ "$ref": "#/components/schemas/HealthCheckStatusDto" }] + }, + "cache": { + "description": "The status of the cache", + "allOf": [{ "$ref": "#/components/schemas/HealthCheckStatusDto" }] + } + }, + "required": ["db", "domain", "cache"] + }, + "HealthEntity": { + "type": "object", + "properties": { + "status": { "type": "string", "description": "Overall health status", "example": "ok" }, + "info": { + "description": "Detailed info about each component's health", + "allOf": [{ "$ref": "#/components/schemas/HealthCheckInfoDto" }] + }, + "error": { + "type": "object", + "description": "Details of any errors encountered during the health check", + "example": {} + }, + "details": { + "description": "Detailed health check results for each component", + "allOf": [{ "$ref": "#/components/schemas/HealthCheckInfoDto" }] + } + }, + "required": ["status", "info", "error", "details"] } } }, diff --git a/src/api/query/articles/articles.ts b/src/api/query/articles/articles.ts index 7433ea4d..6c02cc4b 100644 --- a/src/api/query/articles/articles.ts +++ b/src/api/query/articles/articles.ts @@ -23,11 +23,16 @@ import type { ArticlesControllerFindAllParams, ArticlesControllerFindDraftsParams, CreateArticleDto, + ErrorServerEntity, UpdateArticleDto, } from '../../types' type SecondParameter any> = Parameters[1] +/** + * Creates a new article with the provided details. + * @summary Create Article + */ export const articlesControllerCreate = ( createArticleDto: BodyType, options?: SecondParameter @@ -44,7 +49,7 @@ export const articlesControllerCreate = ( } export const getArticlesControllerCreateMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -78,10 +83,13 @@ export type ArticlesControllerCreateMutationResult = NonNullable< Awaited> > export type ArticlesControllerCreateMutationBody = BodyType -export type ArticlesControllerCreateMutationError = ErrorType +export type ArticlesControllerCreateMutationError = ErrorType +/** + * @summary Create Article + */ export const useArticlesControllerCreate = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -96,6 +104,10 @@ export const useArticlesControllerCreate = < return useMutation(mutationOptions) } +/** + * Retrieves a list of all articles with pagination support. + * @summary Find All Articles + */ export const articlesControllerFindAll = ( params: ArticlesControllerFindAllParams, options?: SecondParameter, @@ -113,7 +125,7 @@ export const getArticlesControllerFindAllQueryKey = (params: ArticlesControllerF export const getArticlesControllerFindAllQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( params: ArticlesControllerFindAllParams, options?: { @@ -139,11 +151,14 @@ export const getArticlesControllerFindAllQueryOptions = < export type ArticlesControllerFindAllQueryResult = NonNullable< Awaited> > -export type ArticlesControllerFindAllQueryError = ErrorType +export type ArticlesControllerFindAllQueryError = ErrorType +/** + * @summary Find All Articles + */ export const useArticlesControllerFindAll = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( params: ArticlesControllerFindAllParams, options?: { @@ -160,6 +175,10 @@ export const useArticlesControllerFindAll = < return query } +/** + * Retrieves a list of draft articles with pagination support. + * @summary Find Draft Articles + */ export const articlesControllerFindDrafts = ( params: ArticlesControllerFindDraftsParams, options?: SecondParameter, @@ -179,7 +198,7 @@ export const getArticlesControllerFindDraftsQueryKey = ( export const getArticlesControllerFindDraftsQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( params: ArticlesControllerFindDraftsParams, options?: { @@ -205,11 +224,14 @@ export const getArticlesControllerFindDraftsQueryOptions = < export type ArticlesControllerFindDraftsQueryResult = NonNullable< Awaited> > -export type ArticlesControllerFindDraftsQueryError = ErrorType +export type ArticlesControllerFindDraftsQueryError = ErrorType +/** + * @summary Find Draft Articles + */ export const useArticlesControllerFindDrafts = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( params: ArticlesControllerFindDraftsParams, options?: { @@ -226,6 +248,10 @@ export const useArticlesControllerFindDrafts = < return query } +/** + * Retrieves an article by its unique identifier. + * @summary Find Article by ID + */ export const articlesControllerFindOne = ( id: number, options?: SecondParameter, @@ -243,7 +269,7 @@ export const getArticlesControllerFindOneQueryKey = (id: number) => { export const getArticlesControllerFindOneQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( id: number, options?: { @@ -269,11 +295,14 @@ export const getArticlesControllerFindOneQueryOptions = < export type ArticlesControllerFindOneQueryResult = NonNullable< Awaited> > -export type ArticlesControllerFindOneQueryError = ErrorType +export type ArticlesControllerFindOneQueryError = ErrorType +/** + * @summary Find Article by ID + */ export const useArticlesControllerFindOne = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( id: number, options?: { @@ -290,6 +319,10 @@ export const useArticlesControllerFindOne = < return query } +/** + * Updates an article with the provided details. + * @summary Update Article + */ export const articlesControllerUpdate = ( id: number, updateArticleDto: BodyType, @@ -307,7 +340,7 @@ export const articlesControllerUpdate = ( } export const getArticlesControllerUpdateMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -341,10 +374,13 @@ export type ArticlesControllerUpdateMutationResult = NonNullable< Awaited> > export type ArticlesControllerUpdateMutationBody = BodyType -export type ArticlesControllerUpdateMutationError = ErrorType +export type ArticlesControllerUpdateMutationError = ErrorType +/** + * @summary Update Article + */ export const useArticlesControllerUpdate = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -359,6 +395,10 @@ export const useArticlesControllerUpdate = < return useMutation(mutationOptions) } +/** + * Deletes an article by its unique identifier. + * @summary Remove Article + */ export const articlesControllerRemove = ( id: number, options?: SecondParameter @@ -367,7 +407,7 @@ export const articlesControllerRemove = ( } export const getArticlesControllerRemoveMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -401,10 +441,13 @@ export type ArticlesControllerRemoveMutationResult = NonNullable< Awaited> > -export type ArticlesControllerRemoveMutationError = ErrorType +export type ArticlesControllerRemoveMutationError = ErrorType +/** + * @summary Remove Article + */ export const useArticlesControllerRemove = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< diff --git a/src/api/query/auth-social/auth-social.msw.ts b/src/api/query/auth-social/auth-social.msw.ts index e4e74235..fcf67f16 100644 --- a/src/api/query/auth-social/auth-social.msw.ts +++ b/src/api/query/auth-social/auth-social.msw.ts @@ -16,7 +16,7 @@ export const getAuthGoogleControllerLoginResponseMock = ( ): AuthEntity => ({ accessToken: faker.word.sample(), refreshToken: faker.word.sample(), - tokenExpires: faker.word.sample(), + tokenExpires: faker.number.int({ min: undefined, max: undefined }), user: { consent: faker.helpers.arrayElement([ { @@ -56,7 +56,7 @@ export const getAuthFacebookControllerLoginResponseMock = ( ): AuthEntity => ({ accessToken: faker.word.sample(), refreshToken: faker.word.sample(), - tokenExpires: faker.word.sample(), + tokenExpires: faker.number.int({ min: undefined, max: undefined }), user: { consent: faker.helpers.arrayElement([ { @@ -96,7 +96,7 @@ export const getAuthAppleControllerLoginResponseMock = ( ): AuthEntity => ({ accessToken: faker.word.sample(), refreshToken: faker.word.sample(), - tokenExpires: faker.word.sample(), + tokenExpires: faker.number.int({ min: undefined, max: undefined }), user: { consent: faker.helpers.arrayElement([ { diff --git a/src/api/query/auth-social/auth-social.ts b/src/api/query/auth-social/auth-social.ts index c9c7c4c4..ad3ce63b 100644 --- a/src/api/query/auth-social/auth-social.ts +++ b/src/api/query/auth-social/auth-social.ts @@ -16,10 +16,16 @@ import type { AuthEntity, AuthFacebookLoginDto, AuthGoogleLoginDto, + ErrorEntity, + ErrorServerEntity, } from '../../types' type SecondParameter any> = Parameters[1] +/** + * Logs the user into the system using Google authentication + * @summary Login with Google + */ export const authGoogleControllerLogin = ( authGoogleLoginDto: BodyType, options?: SecondParameter @@ -36,7 +42,7 @@ export const authGoogleControllerLogin = ( } export const getAuthGoogleControllerLoginMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -70,10 +76,13 @@ export type AuthGoogleControllerLoginMutationResult = NonNullable< Awaited> > export type AuthGoogleControllerLoginMutationBody = BodyType -export type AuthGoogleControllerLoginMutationError = ErrorType +export type AuthGoogleControllerLoginMutationError = ErrorType +/** + * @summary Login with Google + */ export const useAuthGoogleControllerLogin = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -88,6 +97,10 @@ export const useAuthGoogleControllerLogin = < return useMutation(mutationOptions) } +/** + * Logs the user into the system using Facebook authentication + * @summary Login with Facebook + */ export const authFacebookControllerLogin = ( authFacebookLoginDto: BodyType, options?: SecondParameter @@ -104,7 +117,7 @@ export const authFacebookControllerLogin = ( } export const getAuthFacebookControllerLoginMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -138,10 +151,13 @@ export type AuthFacebookControllerLoginMutationResult = NonNullable< Awaited> > export type AuthFacebookControllerLoginMutationBody = BodyType -export type AuthFacebookControllerLoginMutationError = ErrorType +export type AuthFacebookControllerLoginMutationError = ErrorType +/** + * @summary Login with Facebook + */ export const useAuthFacebookControllerLogin = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -156,6 +172,10 @@ export const useAuthFacebookControllerLogin = < return useMutation(mutationOptions) } +/** + * Logs the user into the system using Apple authentication + * @summary Login with Apple + */ export const authAppleControllerLogin = ( authAppleLoginDto: BodyType, options?: SecondParameter @@ -172,7 +192,7 @@ export const authAppleControllerLogin = ( } export const getAuthAppleControllerLoginMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -206,10 +226,13 @@ export type AuthAppleControllerLoginMutationResult = NonNullable< Awaited> > export type AuthAppleControllerLoginMutationBody = BodyType -export type AuthAppleControllerLoginMutationError = ErrorType +export type AuthAppleControllerLoginMutationError = ErrorType +/** + * @summary Login with Apple + */ export const useAuthAppleControllerLogin = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< diff --git a/src/api/query/auth/auth.msw.ts b/src/api/query/auth/auth.msw.ts index 5036fc13..057ddc56 100644 --- a/src/api/query/auth/auth.msw.ts +++ b/src/api/query/auth/auth.msw.ts @@ -14,7 +14,7 @@ import type { AuthEntity, RefreshEntity, UserEntity } from '../../types' export const getAuthControllerLoginResponseMock = (overrideResponse: any = {}): AuthEntity => ({ accessToken: faker.word.sample(), refreshToken: faker.word.sample(), - tokenExpires: faker.word.sample(), + tokenExpires: faker.number.int({ min: undefined, max: undefined }), user: { consent: faker.helpers.arrayElement([ { @@ -164,6 +164,18 @@ export const getAuthControllerConfirmEmailMockHandler = () => { }) } +export const getAuthControllerResendVerificationEmailMockHandler = () => { + return http.post('*/api/v1/auth/email/resend', async () => { + await delay(1000) + return new HttpResponse(null, { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }) + }) +} + export const getAuthControllerForgotPasswordMockHandler = () => { return http.post('*/api/v1/auth/forgot/password', async () => { await delay(1000) @@ -253,10 +265,23 @@ export const getAuthControllerLogoutMockHandler = () => { }) }) } + +export const getAuthControllerLogoutAllMockHandler = () => { + return http.post('*/api/v1/auth/logout/all', async () => { + await delay(1000) + return new HttpResponse(null, { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }) + }) +} export const getAuthMock = () => [ getAuthControllerLoginMockHandler(), getAuthControllerRegisterMockHandler(), getAuthControllerConfirmEmailMockHandler(), + getAuthControllerResendVerificationEmailMockHandler(), getAuthControllerForgotPasswordMockHandler(), getAuthControllerResetPasswordMockHandler(), getAuthControllerMeMockHandler(), @@ -264,4 +289,5 @@ export const getAuthMock = () => [ getAuthControllerDeleteMockHandler(), getAuthControllerRefreshMockHandler(), getAuthControllerLogoutMockHandler(), + getAuthControllerLogoutAllMockHandler(), ] diff --git a/src/api/query/auth/auth.ts b/src/api/query/auth/auth.ts index 12fb6b3a..3c5e2f98 100644 --- a/src/api/query/auth/auth.ts +++ b/src/api/query/auth/auth.ts @@ -24,14 +24,23 @@ import type { AuthEntity, AuthForgotPasswordDto, AuthRegisterLoginDto, + AuthResendVerificationEmailDto, AuthResetPasswordDto, AuthUpdateDto, + ErrorEntity, + ErrorServerEntity, + ErrorTooManyRequestsEntity, + ErrorUnauthorizedEntity, RefreshEntity, UserEntity, } from '../../types' type SecondParameter any> = Parameters[1] +/** + * Logs the user into the system and returns access tokens + * @summary User Login + */ export const authControllerLogin = ( authEmailLoginDto: BodyType, options?: SecondParameter @@ -48,7 +57,9 @@ export const authControllerLogin = ( } export const getAuthControllerLoginMutationOptions = < - TError = ErrorType, + TError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorTooManyRequestsEntity | ErrorServerEntity + >, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -82,9 +93,19 @@ export type AuthControllerLoginMutationResult = NonNullable< Awaited> > export type AuthControllerLoginMutationBody = BodyType -export type AuthControllerLoginMutationError = ErrorType +export type AuthControllerLoginMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorTooManyRequestsEntity | ErrorServerEntity +> -export const useAuthControllerLogin = , TContext = unknown>(options?: { +/** + * @summary User Login + */ +export const useAuthControllerLogin = < + TError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorTooManyRequestsEntity | ErrorServerEntity + >, + TContext = unknown +>(options?: { mutation?: UseMutationOptions< Awaited>, TError, @@ -97,6 +118,10 @@ export const useAuthControllerLogin = , TContext = u return useMutation(mutationOptions) } +/** + * Registers a new user with email and password + * @summary User Registration + */ export const authControllerRegister = ( authRegisterLoginDto: BodyType, options?: SecondParameter @@ -113,7 +138,7 @@ export const authControllerRegister = ( } export const getAuthControllerRegisterMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -147,10 +172,15 @@ export type AuthControllerRegisterMutationResult = NonNullable< Awaited> > export type AuthControllerRegisterMutationBody = BodyType -export type AuthControllerRegisterMutationError = ErrorType +export type AuthControllerRegisterMutationError = ErrorType< + void | ErrorTooManyRequestsEntity | ErrorServerEntity +> +/** + * @summary User Registration + */ export const useAuthControllerRegister = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -165,11 +195,15 @@ export const useAuthControllerRegister = < return useMutation(mutationOptions) } +/** + * Confirms the user's email address using the provided confirmation hash. + * @summary Confirm Email + */ export const authControllerConfirmEmail = ( authConfirmEmailDto: BodyType, options?: SecondParameter ) => { - return customInstance( + return customInstance( { url: `/api/v1/auth/email/confirm`, method: 'POST', @@ -181,7 +215,7 @@ export const authControllerConfirmEmail = ( } export const getAuthControllerConfirmEmailMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -215,10 +249,15 @@ export type AuthControllerConfirmEmailMutationResult = NonNullable< Awaited> > export type AuthControllerConfirmEmailMutationBody = BodyType -export type AuthControllerConfirmEmailMutationError = ErrorType +export type AuthControllerConfirmEmailMutationError = ErrorType< + void | ErrorTooManyRequestsEntity | ErrorServerEntity +> +/** + * @summary Confirm Email + */ export const useAuthControllerConfirmEmail = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -233,11 +272,93 @@ export const useAuthControllerConfirmEmail = < return useMutation(mutationOptions) } +/** + * Resend the verification email to the user's email address. + * @summary Resend Verification Email + */ +export const authControllerResendVerificationEmail = ( + authResendVerificationEmailDto: BodyType, + options?: SecondParameter +) => { + return customInstance( + { + url: `/api/v1/auth/email/resend`, + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + data: authResendVerificationEmailDto, + }, + options + ) +} + +export const getAuthControllerResendVerificationEmailMutationOptions = < + TError = ErrorType, + TContext = unknown +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + { data: BodyType }, + TContext + > + request?: SecondParameter +}): UseMutationOptions< + Awaited>, + TError, + { data: BodyType }, + TContext +> => { + const { mutation: mutationOptions, request: requestOptions } = options ?? {} + + const mutationFn: MutationFunction< + Awaited>, + { data: BodyType } + > = (props) => { + const { data } = props ?? {} + + return authControllerResendVerificationEmail(data, requestOptions) + } + + return { mutationFn, ...mutationOptions } +} + +export type AuthControllerResendVerificationEmailMutationResult = NonNullable< + Awaited> +> +export type AuthControllerResendVerificationEmailMutationBody = + BodyType +export type AuthControllerResendVerificationEmailMutationError = ErrorType< + ErrorEntity | ErrorTooManyRequestsEntity | ErrorServerEntity +> + +/** + * @summary Resend Verification Email + */ +export const useAuthControllerResendVerificationEmail = < + TError = ErrorType, + TContext = unknown +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + { data: BodyType }, + TContext + > + request?: SecondParameter +}) => { + const mutationOptions = getAuthControllerResendVerificationEmailMutationOptions(options) + + return useMutation(mutationOptions) +} +/** + * Initiates the password reset process by sending an email with a reset link to the user's email address. + * @summary Forgot Password + */ export const authControllerForgotPassword = ( authForgotPasswordDto: BodyType, options?: SecondParameter ) => { - return customInstance( + return customInstance( { url: `/api/v1/auth/forgot/password`, method: 'POST', @@ -249,7 +370,7 @@ export const authControllerForgotPassword = ( } export const getAuthControllerForgotPasswordMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -283,10 +404,15 @@ export type AuthControllerForgotPasswordMutationResult = NonNullable< Awaited> > export type AuthControllerForgotPasswordMutationBody = BodyType -export type AuthControllerForgotPasswordMutationError = ErrorType +export type AuthControllerForgotPasswordMutationError = ErrorType< + ErrorEntity | ErrorTooManyRequestsEntity | ErrorServerEntity +> +/** + * @summary Forgot Password + */ export const useAuthControllerForgotPassword = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -301,11 +427,15 @@ export const useAuthControllerForgotPassword = < return useMutation(mutationOptions) } +/** + * Resets the user's password using the provided reset password hash. + * @summary Reset Password + */ export const authControllerResetPassword = ( authResetPasswordDto: BodyType, options?: SecondParameter ) => { - return customInstance( + return customInstance( { url: `/api/v1/auth/reset/password`, method: 'POST', @@ -317,7 +447,7 @@ export const authControllerResetPassword = ( } export const getAuthControllerResetPasswordMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -351,10 +481,15 @@ export type AuthControllerResetPasswordMutationResult = NonNullable< Awaited> > export type AuthControllerResetPasswordMutationBody = BodyType -export type AuthControllerResetPasswordMutationError = ErrorType +export type AuthControllerResetPasswordMutationError = ErrorType< + ErrorEntity | ErrorTooManyRequestsEntity | ErrorServerEntity +> +/** + * @summary Reset Password + */ export const useAuthControllerResetPassword = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -369,6 +504,10 @@ export const useAuthControllerResetPassword = < return useMutation(mutationOptions) } +/** + * Retrieves information about the current authenticated user + * @summary Get Current User + */ export const authControllerMe = ( options?: SecondParameter, signal?: AbortSignal @@ -382,7 +521,7 @@ export const getAuthControllerMeQueryKey = () => { export const getAuthControllerMeQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >(options?: { query?: UseQueryOptions>, TError, TData> request?: SecondParameter @@ -402,11 +541,14 @@ export const getAuthControllerMeQueryOptions = < } export type AuthControllerMeQueryResult = NonNullable>> -export type AuthControllerMeQueryError = ErrorType +export type AuthControllerMeQueryError = ErrorType +/** + * @summary Get Current User + */ export const useAuthControllerMe = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >(options?: { query?: UseQueryOptions>, TError, TData> request?: SecondParameter @@ -420,11 +562,15 @@ export const useAuthControllerMe = < return query } +/** + * Updates information about the current authenticated user + * @summary Update Current User + */ export const authControllerUpdate = ( authUpdateDto: BodyType, options?: SecondParameter ) => { - return customInstance( + return customInstance( { url: `/api/v1/auth/me`, method: 'PATCH', @@ -436,7 +582,7 @@ export const authControllerUpdate = ( } export const getAuthControllerUpdateMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -470,9 +616,17 @@ export type AuthControllerUpdateMutationResult = NonNullable< Awaited> > export type AuthControllerUpdateMutationBody = BodyType -export type AuthControllerUpdateMutationError = ErrorType +export type AuthControllerUpdateMutationError = ErrorType< + ErrorUnauthorizedEntity | void | ErrorEntity | ErrorServerEntity +> -export const useAuthControllerUpdate = , TContext = unknown>(options?: { +/** + * @summary Update Current User + */ +export const useAuthControllerUpdate = < + TError = ErrorType, + TContext = unknown +>(options?: { mutation?: UseMutationOptions< Awaited>, TError, @@ -485,12 +639,16 @@ export const useAuthControllerUpdate = , TContext = return useMutation(mutationOptions) } +/** + * Deletes the current authenticated user + * @summary Delete Current User + */ export const authControllerDelete = (options?: SecondParameter) => { - return customInstance({ url: `/api/v1/auth/me`, method: 'DELETE' }, options) + return customInstance({ url: `/api/v1/auth/me`, method: 'DELETE' }, options) } export const getAuthControllerDeleteMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -522,9 +680,17 @@ export type AuthControllerDeleteMutationResult = NonNullable< Awaited> > -export type AuthControllerDeleteMutationError = ErrorType +export type AuthControllerDeleteMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorServerEntity +> -export const useAuthControllerDelete = , TContext = unknown>(options?: { +/** + * @summary Delete Current User + */ +export const useAuthControllerDelete = < + TError = ErrorType, + TContext = unknown +>(options?: { mutation?: UseMutationOptions< Awaited>, TError, @@ -537,12 +703,16 @@ export const useAuthControllerDelete = , TContext = return useMutation(mutationOptions) } +/** + * Refreshes the access token using the refresh token + * @summary Refresh Access Token + */ export const authControllerRefresh = (options?: SecondParameter) => { return customInstance({ url: `/api/v1/auth/refresh`, method: 'POST' }, options) } export const getAuthControllerRefreshMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -574,10 +744,15 @@ export type AuthControllerRefreshMutationResult = NonNullable< Awaited> > -export type AuthControllerRefreshMutationError = ErrorType +export type AuthControllerRefreshMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorServerEntity +> +/** + * @summary Refresh Access Token + */ export const useAuthControllerRefresh = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -592,12 +767,16 @@ export const useAuthControllerRefresh = < return useMutation(mutationOptions) } +/** + * Logs the user out of the system + * @summary Logout + */ export const authControllerLogout = (options?: SecondParameter) => { - return customInstance({ url: `/api/v1/auth/logout`, method: 'POST' }, options) + return customInstance({ url: `/api/v1/auth/logout`, method: 'POST' }, options) } export const getAuthControllerLogoutMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -629,9 +808,17 @@ export type AuthControllerLogoutMutationResult = NonNullable< Awaited> > -export type AuthControllerLogoutMutationError = ErrorType +export type AuthControllerLogoutMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorServerEntity +> -export const useAuthControllerLogout = , TContext = unknown>(options?: { +/** + * @summary Logout + */ +export const useAuthControllerLogout = < + TError = ErrorType, + TContext = unknown +>(options?: { mutation?: UseMutationOptions< Awaited>, TError, @@ -644,3 +831,67 @@ export const useAuthControllerLogout = , TContext = return useMutation(mutationOptions) } +/** + * Logs the user out of all active sessions to enhance security in case of unauthorized access or when changing sensitive account information like passwords + * @summary Logout all sessions + */ +export const authControllerLogoutAll = (options?: SecondParameter) => { + return customInstance({ url: `/api/v1/auth/logout/all`, method: 'POST' }, options) +} + +export const getAuthControllerLogoutAllMutationOptions = < + TError = ErrorType, + TContext = unknown +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + void, + TContext + > + request?: SecondParameter +}): UseMutationOptions< + Awaited>, + TError, + void, + TContext +> => { + const { mutation: mutationOptions, request: requestOptions } = options ?? {} + + const mutationFn: MutationFunction< + Awaited>, + void + > = () => { + return authControllerLogoutAll(requestOptions) + } + + return { mutationFn, ...mutationOptions } +} + +export type AuthControllerLogoutAllMutationResult = NonNullable< + Awaited> +> + +export type AuthControllerLogoutAllMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorServerEntity +> + +/** + * @summary Logout all sessions + */ +export const useAuthControllerLogoutAll = < + TError = ErrorType, + TContext = unknown +>(options?: { + mutation?: UseMutationOptions< + Awaited>, + TError, + void, + TContext + > + request?: SecondParameter +}) => { + const mutationOptions = getAuthControllerLogoutAllMutationOptions(options) + + return useMutation(mutationOptions) +} diff --git a/src/api/query/files/files.ts b/src/api/query/files/files.ts index 6576f102..0808d73c 100644 --- a/src/api/query/files/files.ts +++ b/src/api/query/files/files.ts @@ -22,6 +22,10 @@ import type { FileEntity, FilesControllerUploadFileBody } from '../../types' type SecondParameter any> = Parameters[1] +/** + * Uploads a file with a specified category. + * @summary Upload File + */ export const filesControllerUploadFile = ( filesControllerUploadFileBody: BodyType, options?: SecondParameter @@ -46,7 +50,7 @@ export const filesControllerUploadFile = ( } export const getFilesControllerUploadFileMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -80,10 +84,13 @@ export type FilesControllerUploadFileMutationResult = NonNullable< Awaited> > export type FilesControllerUploadFileMutationBody = BodyType -export type FilesControllerUploadFileMutationError = ErrorType +export type FilesControllerUploadFileMutationError = ErrorType +/** + * @summary Upload File + */ export const useFilesControllerUploadFile = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -98,12 +105,19 @@ export const useFilesControllerUploadFile = < return useMutation(mutationOptions) } +/** + * Downloads the specified file. + * @summary Download File + */ export const filesControllerDownload = ( fileName: string, options?: SecondParameter, signal?: AbortSignal ) => { - return customInstance({ url: `/api/v1/files/${fileName}`, method: 'GET', signal }, options) + return customInstance( + { url: `/api/v1/files/${fileName}`, method: 'GET', signal }, + options + ) } export const getFilesControllerDownloadQueryKey = (fileName: string) => { @@ -112,7 +126,7 @@ export const getFilesControllerDownloadQueryKey = (fileName: string) => { export const getFilesControllerDownloadQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( fileName: string, options?: { @@ -138,11 +152,14 @@ export const getFilesControllerDownloadQueryOptions = < export type FilesControllerDownloadQueryResult = NonNullable< Awaited> > -export type FilesControllerDownloadQueryError = ErrorType +export type FilesControllerDownloadQueryError = ErrorType +/** + * @summary Download File + */ export const useFilesControllerDownload = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( fileName: string, options?: { @@ -159,15 +176,19 @@ export const useFilesControllerDownload = < return query } +/** + * Deletes the specified file. + * @summary Delete File + */ export const filesControllerDeleteFile = ( fileName: string, options?: SecondParameter ) => { - return customInstance({ url: `/api/v1/files/${fileName}`, method: 'DELETE' }, options) + return customInstance({ url: `/api/v1/files/${fileName}`, method: 'DELETE' }, options) } export const getFilesControllerDeleteFileMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -201,10 +222,13 @@ export type FilesControllerDeleteFileMutationResult = NonNullable< Awaited> > -export type FilesControllerDeleteFileMutationError = ErrorType +export type FilesControllerDeleteFileMutationError = ErrorType +/** + * @summary Delete File + */ export const useFilesControllerDeleteFile = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< diff --git a/src/api/query/health/health.msw.ts b/src/api/query/health/health.msw.ts new file mode 100644 index 00000000..fd9a6d15 --- /dev/null +++ b/src/api/query/health/health.msw.ts @@ -0,0 +1,46 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ +import { faker } from '@faker-js/faker' +import { HttpResponse, delay, http } from 'msw' + +import type { HealthEntity } from '../../types' + +export const getHealthControllerCheckResponseMock = (overrideResponse: any = {}): HealthEntity => ({ + details: { + cache: { status: faker.word.sample(), ...overrideResponse }, + db: { status: faker.word.sample(), ...overrideResponse }, + domain: { status: faker.word.sample(), ...overrideResponse }, + ...overrideResponse, + }, + error: {}, + info: { + cache: { status: faker.word.sample(), ...overrideResponse }, + db: { status: faker.word.sample(), ...overrideResponse }, + domain: { status: faker.word.sample(), ...overrideResponse }, + ...overrideResponse, + }, + status: faker.word.sample(), + ...overrideResponse, +}) + +export const getHealthControllerCheckMockHandler = (overrideResponse?: HealthEntity) => { + return http.get('*/api/v1/health', async () => { + await delay(1000) + return new HttpResponse( + JSON.stringify(overrideResponse ? overrideResponse : getHealthControllerCheckResponseMock()), + { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + } + ) + }) +} +export const getHealthMock = () => [getHealthControllerCheckMockHandler()] diff --git a/src/api/query/health/health.ts b/src/api/query/health/health.ts new file mode 100644 index 00000000..1ee684fe --- /dev/null +++ b/src/api/query/health/health.ts @@ -0,0 +1,81 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ +import { useQuery } from '@tanstack/react-query' +import type { + QueryFunction, + QueryKey, + UseQueryOptions, + UseQueryResult, +} from '@tanstack/react-query' + +import { customInstance } from '../../axios/custom-instance' +import type { ErrorType } from '../../axios/custom-instance' +import type { ErrorEntity, HealthEntity } from '../../types' + +type SecondParameter any> = Parameters[1] + +/** + * Performs a health check, verifying the database, frontend domain, and cache connectivity. + * @summary Check Health + */ +export const healthControllerCheck = ( + options?: SecondParameter, + signal?: AbortSignal +) => { + return customInstance({ url: `/api/v1/health`, method: 'GET', signal }, options) +} + +export const getHealthControllerCheckQueryKey = () => { + return [`/api/v1/health`] as const +} + +export const getHealthControllerCheckQueryOptions = < + TData = Awaited>, + TError = ErrorType +>(options?: { + query?: UseQueryOptions>, TError, TData> + request?: SecondParameter +}) => { + const { query: queryOptions, request: requestOptions } = options ?? {} + + const queryKey = queryOptions?.queryKey ?? getHealthControllerCheckQueryKey() + + const queryFn: QueryFunction>> = ({ signal }) => + healthControllerCheck(requestOptions, signal) + + return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< + Awaited>, + TError, + TData + > & { queryKey: QueryKey } +} + +export type HealthControllerCheckQueryResult = NonNullable< + Awaited> +> +export type HealthControllerCheckQueryError = ErrorType + +/** + * @summary Check Health + */ +export const useHealthControllerCheck = < + TData = Awaited>, + TError = ErrorType +>(options?: { + query?: UseQueryOptions>, TError, TData> + request?: SecondParameter +}): UseQueryResult & { queryKey: QueryKey } => { + const queryOptions = getHealthControllerCheckQueryOptions(options) + + const query = useQuery(queryOptions) as UseQueryResult & { queryKey: QueryKey } + + query.queryKey = queryOptions.queryKey + + return query +} diff --git a/src/api/query/users/users.ts b/src/api/query/users/users.ts index 61fb00f4..ddcbfbb2 100644 --- a/src/api/query/users/users.ts +++ b/src/api/query/users/users.ts @@ -20,6 +20,9 @@ import { customInstance } from '../../axios/custom-instance' import type { ErrorType, BodyType } from '../../axios/custom-instance' import type { CreateUserDto, + ErrorEntity, + ErrorServerEntity, + ErrorUnauthorizedEntity, UpdateUserDto, UserEntity, UsersControllerFindAllParams, @@ -27,6 +30,10 @@ import type { type SecondParameter any> = Parameters[1] +/** + * Creates a new user. + * @summary Create User + */ export const usersControllerCreate = ( createUserDto: BodyType, options?: SecondParameter @@ -43,7 +50,7 @@ export const usersControllerCreate = ( } export const getUsersControllerCreateMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -77,10 +84,15 @@ export type UsersControllerCreateMutationResult = NonNullable< Awaited> > export type UsersControllerCreateMutationBody = BodyType -export type UsersControllerCreateMutationError = ErrorType +export type UsersControllerCreateMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorServerEntity +> +/** + * @summary Create User + */ export const useUsersControllerCreate = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -95,6 +107,10 @@ export const useUsersControllerCreate = < return useMutation(mutationOptions) } +/** + * Retrieves a list of all users. + * @summary Find All Users + */ export const usersControllerFindAll = ( params: UsersControllerFindAllParams, options?: SecondParameter, @@ -112,7 +128,7 @@ export const getUsersControllerFindAllQueryKey = (params: UsersControllerFindAll export const getUsersControllerFindAllQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( params: UsersControllerFindAllParams, options?: { @@ -137,11 +153,16 @@ export const getUsersControllerFindAllQueryOptions = < export type UsersControllerFindAllQueryResult = NonNullable< Awaited> > -export type UsersControllerFindAllQueryError = ErrorType +export type UsersControllerFindAllQueryError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorServerEntity +> +/** + * @summary Find All Users + */ export const useUsersControllerFindAll = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( params: UsersControllerFindAllParams, options?: { @@ -158,6 +179,10 @@ export const useUsersControllerFindAll = < return query } +/** + * Retrieves a user by its ID. + * @summary Find User by ID + */ export const usersControllerFindOne = ( id: string, options?: SecondParameter, @@ -172,7 +197,7 @@ export const getUsersControllerFindOneQueryKey = (id: string) => { export const getUsersControllerFindOneQueryOptions = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( id: string, options?: { @@ -197,11 +222,16 @@ export const getUsersControllerFindOneQueryOptions = < export type UsersControllerFindOneQueryResult = NonNullable< Awaited> > -export type UsersControllerFindOneQueryError = ErrorType +export type UsersControllerFindOneQueryError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorServerEntity +> +/** + * @summary Find User by ID + */ export const useUsersControllerFindOne = < TData = Awaited>, - TError = ErrorType + TError = ErrorType >( id: string, options?: { @@ -218,6 +248,10 @@ export const useUsersControllerFindOne = < return query } +/** + * Updates a user with the provided details. + * @summary Update User + */ export const usersControllerUpdate = ( id: string, updateUserDto: BodyType, @@ -235,7 +269,7 @@ export const usersControllerUpdate = ( } export const getUsersControllerUpdateMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -269,10 +303,15 @@ export type UsersControllerUpdateMutationResult = NonNullable< Awaited> > export type UsersControllerUpdateMutationBody = BodyType -export type UsersControllerUpdateMutationError = ErrorType +export type UsersControllerUpdateMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorServerEntity +> +/** + * @summary Update User + */ export const useUsersControllerUpdate = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -287,6 +326,10 @@ export const useUsersControllerUpdate = < return useMutation(mutationOptions) } +/** + * Deletes a user by their unique identifier. + * @summary Remove User + */ export const usersControllerRemove = ( id: string, options?: SecondParameter @@ -295,7 +338,7 @@ export const usersControllerRemove = ( } export const getUsersControllerRemoveMutationOptions = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< @@ -329,10 +372,15 @@ export type UsersControllerRemoveMutationResult = NonNullable< Awaited> > -export type UsersControllerRemoveMutationError = ErrorType +export type UsersControllerRemoveMutationError = ErrorType< + ErrorUnauthorizedEntity | ErrorEntity | ErrorServerEntity +> +/** + * @summary Remove User + */ export const useUsersControllerRemove = < - TError = ErrorType, + TError = ErrorType, TContext = unknown >(options?: { mutation?: UseMutationOptions< diff --git a/src/api/types/authEntity.ts b/src/api/types/authEntity.ts index 7788b771..7c5d1476 100644 --- a/src/api/types/authEntity.ts +++ b/src/api/types/authEntity.ts @@ -14,7 +14,7 @@ export interface AuthEntity { /** The refresh token for refreshing the access token. */ refreshToken: string /** The expiry timestamp of the access token. */ - tokenExpires: string + tokenExpires: number /** The user entity associated with the authentication. */ user: UserEntity } diff --git a/src/api/types/authResendVerificationEmailDto.ts b/src/api/types/authResendVerificationEmailDto.ts new file mode 100644 index 00000000..0e52cd1e --- /dev/null +++ b/src/api/types/authResendVerificationEmailDto.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +export interface AuthResendVerificationEmailDto { + /** The email address associated with the user account. */ + email: string +} diff --git a/src/api/types/errorEntity.ts b/src/api/types/errorEntity.ts new file mode 100644 index 00000000..aea52a31 --- /dev/null +++ b/src/api/types/errorEntity.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +export interface ErrorEntity { + /** Type of error */ + error: string + /** Message describing the error */ + message: string + /** HTTP status code indicating the error */ + statusCode: number +} diff --git a/src/api/types/errorServerEntity.ts b/src/api/types/errorServerEntity.ts new file mode 100644 index 00000000..d69d365b --- /dev/null +++ b/src/api/types/errorServerEntity.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +export interface ErrorServerEntity { + /** Type of error */ + error: string + /** HTTP status code indicating the error */ + statusCode: number +} diff --git a/src/api/types/errorTooManyRequestsEntity.ts b/src/api/types/errorTooManyRequestsEntity.ts new file mode 100644 index 00000000..a078ba8b --- /dev/null +++ b/src/api/types/errorTooManyRequestsEntity.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +export interface ErrorTooManyRequestsEntity { + /** Type of error */ + error: string + /** HTTP status code indicating the error */ + statusCode: number +} diff --git a/src/api/types/errorUnauthorizedEntity.ts b/src/api/types/errorUnauthorizedEntity.ts new file mode 100644 index 00000000..22ca8402 --- /dev/null +++ b/src/api/types/errorUnauthorizedEntity.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +export interface ErrorUnauthorizedEntity { + /** Type of error */ + error: string + /** HTTP status code indicating the error */ + statusCode: number +} diff --git a/src/api/types/healthCheckInfoDto.ts b/src/api/types/healthCheckInfoDto.ts new file mode 100644 index 00000000..a91e5bde --- /dev/null +++ b/src/api/types/healthCheckInfoDto.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ +import type { HealthCheckStatusDto } from './healthCheckStatusDto' + +export interface HealthCheckInfoDto { + /** The status of the cache */ + cache: HealthCheckStatusDto + /** The status of the database connection */ + db: HealthCheckStatusDto + /** The status of the domain */ + domain: HealthCheckStatusDto +} diff --git a/src/api/types/healthCheckStatusDto.ts b/src/api/types/healthCheckStatusDto.ts new file mode 100644 index 00000000..08efa128 --- /dev/null +++ b/src/api/types/healthCheckStatusDto.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +export interface HealthCheckStatusDto { + /** The status of the component */ + status: string +} diff --git a/src/api/types/healthEntity.ts b/src/api/types/healthEntity.ts new file mode 100644 index 00000000..5cb78903 --- /dev/null +++ b/src/api/types/healthEntity.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ +import type { HealthCheckInfoDto } from './healthCheckInfoDto' +import type { HealthEntityError } from './healthEntityError' + +export interface HealthEntity { + /** Detailed health check results for each component */ + details: HealthCheckInfoDto + /** Details of any errors encountered during the health check */ + error: HealthEntityError + /** Detailed info about each component's health */ + info: HealthCheckInfoDto + /** Overall health status */ + status: string +} diff --git a/src/api/types/healthEntityError.ts b/src/api/types/healthEntityError.ts new file mode 100644 index 00000000..821b8468 --- /dev/null +++ b/src/api/types/healthEntityError.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Generated by orval 🍺 + * Do not edit manually. + * API + * API documentation for the starter-kit project in NestJS by BinarApps. The API allows management of users, sessions and offers various functions for logged in users. Contains examples of authentication, authorization, and CRUD for selected resources. + * OpenAPI spec version: 1.0 + */ + +/** + * Details of any errors encountered during the health check + */ +export type HealthEntityError = { [key: string]: any } diff --git a/src/api/types/index.ts b/src/api/types/index.ts index f83fbb0e..3ac56100 100644 --- a/src/api/types/index.ts +++ b/src/api/types/index.ts @@ -18,13 +18,22 @@ export * from './authFacebookLoginDto' export * from './authForgotPasswordDto' export * from './authGoogleLoginDto' export * from './authRegisterLoginDto' +export * from './authResendVerificationEmailDto' export * from './authResetPasswordDto' export * from './authUpdateDto' export * from './authorPublicDto' export * from './createArticleDto' export * from './createUserDto' +export * from './errorEntity' +export * from './errorServerEntity' +export * from './errorTooManyRequestsEntity' +export * from './errorUnauthorizedEntity' export * from './fileEntity' export * from './filesControllerUploadFileBody' +export * from './healthCheckInfoDto' +export * from './healthCheckStatusDto' +export * from './healthEntity' +export * from './healthEntityError' export * from './lastConsentProperties' export * from './refreshEntity' export * from './role' From b23627655e0b04cfb2ebcb71677e1bb8af8c0e58 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:46:24 +0100 Subject: [PATCH 02/13] chore: add msw library and update axios library; --- package.json | 4 +++- yarn.lock | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8e2d8e66..b54bff87 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "@react-navigation/native-stack": "^6.9.17", "@react-navigation/stack": "^6.3.20", "@tanstack/react-query": "^4.29.19", - "axios": "^0.27.2", + "axios": "^1.6.7", "expo": "^50.0.3", "expo-app-loading": "^2.1.1", "expo-application": "~5.8.3", @@ -182,6 +182,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-native": "^4.0.0", "eslint-plugin-react-native-globals": "^0.1.2", + "fast-text-encoding": "^1.0.6", "husky": "^8.0.3", "jest": "^29.6.1", "jest-expo": "~50.0.1", @@ -193,6 +194,7 @@ "prettier": "^2.8.8", "pretty-quick": "^4.0.0", "prompt-sync": "^4.2.0", + "react-native-url-polyfill": "^2.0.0", "react-test-renderer": "^18.2.0", "readline": "^1.3.0", "select-prompt": "^0.3.2", diff --git a/yarn.lock b/yarn.lock index 7f0ab148..99b3798c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4637,13 +4637,14 @@ available-typed-arrays@^1.0.6, available-typed-arrays@^1.0.7: dependencies: possible-typed-array-names "^1.0.0" -axios@^0.27.2: - version "0.27.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== +axios@^1.6.7: + version "1.6.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" + integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== dependencies: - follow-redirects "^1.14.9" + follow-redirects "^1.15.4" form-data "^4.0.0" + proxy-from-env "^1.1.0" babel-core@^7.0.0-bridge.0: version "7.0.0-bridge.0" @@ -7276,6 +7277,11 @@ fast-safe-stringify@^2.0.7: resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz#c406a83b6e70d9e35ce3b30a81141df30aeba884" integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA== +fast-text-encoding@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/fast-text-encoding/-/fast-text-encoding-1.0.6.tgz#0aa25f7f638222e3396d72bf936afcf1d42d6867" + integrity sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w== + fast-xml-parser@^4.0.12, fast-xml-parser@^4.2.4: version "4.3.3" resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-4.3.3.tgz#aeaf5778392329f17168c40c51bcbfec8ff965be" @@ -7502,7 +7508,7 @@ flow-parser@^0.206.0: resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.206.0.tgz#f4f794f8026535278393308e01ea72f31000bfef" integrity sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w== -follow-redirects@^1.0.0, follow-redirects@^1.14.9: +follow-redirects@^1.0.0, follow-redirects@^1.15.4: version "1.15.5" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020" integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw== @@ -11673,6 +11679,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + psl@^1.1.33: version "1.9.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" @@ -11938,6 +11949,13 @@ react-native-svg@14.1.0: css-select "^5.1.0" css-tree "^1.1.3" +react-native-url-polyfill@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz#db714520a2985cff1d50ab2e66279b9f91ffd589" + integrity sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA== + dependencies: + whatwg-url-without-unicode "8.0.0-3" + react-native-web@~0.19.6: version "0.19.10" resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.19.10.tgz#5f7205f8909c0889bc89c9fde7c6e287defa7c63" From 84c1b7d79f6d5ae30b7822f149fe5f2d0c45ecca Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:46:51 +0100 Subject: [PATCH 03/13] chore: update injectToken function to work with new axios --- src/api/axios/interceptors/injectToken.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/api/axios/interceptors/injectToken.ts b/src/api/axios/interceptors/injectToken.ts index 6261ac80..c30485c2 100644 --- a/src/api/axios/interceptors/injectToken.ts +++ b/src/api/axios/interceptors/injectToken.ts @@ -1,18 +1,14 @@ import { getToken } from '@baca/services' -import { AxiosRequestConfig } from 'axios' +import { InternalAxiosRequestConfig } from 'axios' -export const injectTokenToRequest = async (config: AxiosRequestConfig) => { +export const injectTokenToRequest = async ( + config: InternalAxiosRequestConfig +): Promise> => { const token = await getToken() - let Authorization = '' if (token) { - Authorization = `Bearer ${token}` - } - return { - ...config, - headers: { - ...config?.headers, - Authorization, - }, + config.headers['Authorization'] = `Bearer ${token}` } + + return config } From 0190c6ad0551488a572ce3988bc0736dd824f12d Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:47:22 +0100 Subject: [PATCH 04/13] chore: make mocking work again (on web only right now) --- App.tsx | 7 ++++--- src/services/MockedServerService.ts | 32 +++++++++++++---------------- src/types/global.d.ts | 4 +++- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/App.tsx b/App.tsx index 9c2cd17d..328631cc 100644 --- a/App.tsx +++ b/App.tsx @@ -5,14 +5,15 @@ import 'setimmediate' import 'react-native-reanimated' +import 'fast-text-encoding' +import 'react-native-url-polyfill/auto' + // Rest imports import '@baca/i18n' - +import { enableAndroidBackgroundNotificationListener, startMockedServer } from '@baca/services' import * as Device from 'expo-device' import 'expo-router/entry' -import { enableAndroidBackgroundNotificationListener, startMockedServer } from '@baca/services' - // FIXME: there is some issue with miragejs that causes console.log to not work const DISABLE_CONSOLE_ENABLE_MOCKED_SERVER = false diff --git a/src/services/MockedServerService.ts b/src/services/MockedServerService.ts index 2735e2d2..83eac94c 100644 --- a/src/services/MockedServerService.ts +++ b/src/services/MockedServerService.ts @@ -1,22 +1,18 @@ -import { createServer } from 'miragejs' +import { getArticlesMock } from '@baca/api/query/articles/articles.msw' +import { getAuthMock } from '@baca/api/query/auth/auth.msw' +import { getAuthSocialMock } from '@baca/api/query/auth-social/auth-social.msw' +import { getFilesMock } from '@baca/api/query/files/files.msw' +import { getUsersMock } from '@baca/api/query/users/users.msw' +import { setupServer } from 'msw/native' export const startMockedServer = (): void => { - if (window.server) { - server.shutdown() - } + const server = setupServer( + ...getAuthMock(), + ...getUsersMock(), + ...getFilesMock(), + ...getAuthSocialMock(), + ...getArticlesMock() + ) - window.server = createServer({ - environment: 'development', - namespace: '/api', - timing: 400, - logging: true, - useDefaultPassthroughs: true, - routes() { - this.get('/timestamp', () => { - return { - timestamp: new Date().toISOString(), - } - }) - }, - }) + server.listen({ onUnhandledRequest: 'bypass' }) } diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 7f7ba695..0a00d4bf 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -1,4 +1,6 @@ -import { Server } from 'miragejs' +import { setupServer } from 'msw/native' + +type Server = ReturnType declare global { interface Window { From 428dcc2fda1cea9de2b9be5a711b3e07becc10b7 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:49:01 +0100 Subject: [PATCH 05/13] chore: add comment about mocking on mobile --- App.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/App.tsx b/App.tsx index 328631cc..35fed6e0 100644 --- a/App.tsx +++ b/App.tsx @@ -14,10 +14,10 @@ import { enableAndroidBackgroundNotificationListener, startMockedServer } from ' import * as Device from 'expo-device' import 'expo-router/entry' -// FIXME: there is some issue with miragejs that causes console.log to not work -const DISABLE_CONSOLE_ENABLE_MOCKED_SERVER = false +// FIXME: moking not working on mobile app - follow this discussion https://github.com/mswjs/msw/issues/2026 +const ENABLE_MOCKED_SERVER = false -if (DISABLE_CONSOLE_ENABLE_MOCKED_SERVER) { +if (ENABLE_MOCKED_SERVER) { startMockedServer() } From 454295319f2249a982b7c8ee9a4e5322266c9645 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 10:19:56 +0100 Subject: [PATCH 06/13] chore: remove mirage js library --- package.json | 1 - yarn.lock | 40 +--------------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/package.json b/package.json index b54bff87..cfb5820c 100644 --- a/package.json +++ b/package.json @@ -187,7 +187,6 @@ "jest": "^29.6.1", "jest-expo": "~50.0.1", "lint-staged": "^13.2.3", - "miragejs": "^0.1.48", "msw": "^2.2.2", "orval": "^6.25.0", "patch-package": "^7.0.1", diff --git a/yarn.lock b/yarn.lock index 99b3798c..9100e4ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2369,11 +2369,6 @@ resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== -"@miragejs/pretender-node-polyfill@^0.1.0": - version "0.1.2" - resolved "https://registry.yarnpkg.com/@miragejs/pretender-node-polyfill/-/pretender-node-polyfill-0.1.2.tgz#d26b6b7483fb70cd62189d05c95d2f67153e43f2" - integrity sha512-M/BexG/p05C5lFfMunxo/QcgIJnMT2vDVCd00wNqK2ImZONIlEETZwWJu1QtLxtmYlSHlCFl3JNzp0tLe7OJ5g== - "@motify/components@^0.17.1": version "0.17.1" resolved "https://registry.yarnpkg.com/@motify/components/-/components-0.17.1.tgz#96888fb0d5c6d41f484d98c9364764e511d83086" @@ -7226,11 +7221,6 @@ express@^4.17.3: utils-merge "1.0.1" vary "~1.1.2" -fake-xml-http-request@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.1.2.tgz#f1786720cae50bbb46273035a0173414f3e85e74" - integrity sha512-HaFMBi7r+oEC9iJNpc3bvcW7Z7iLmM26hPDmlb0mFwyANSsOQAtJxbdWsXITKOzZUyMYK0zYCv3h5yDj9TsiXg== - fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" @@ -8321,11 +8311,6 @@ infer-owner@^1.0.4: resolved "https://registry.yarnpkg.com/infer-owner/-/infer-owner-1.0.4.tgz#c4cefcaa8e51051c2a40ba2ce8a3d27295af9467" integrity sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A== -inflected@^2.0.4: - version "2.1.0" - resolved "https://registry.yarnpkg.com/inflected/-/inflected-2.1.0.tgz#2816ac17a570bbbc8303ca05bca8bf9b3f959687" - integrity sha512-hAEKNxvHf2Iq3H60oMBHkB4wl5jn3TPF3+fXek/sRwAB5gP9xWs4r7aweSF95f99HFoz69pnZTcu8f0SIHV18w== - inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -9777,7 +9762,7 @@ lodash.uniqwith@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniqwith/-/lodash.uniqwith-4.5.0.tgz#7a0cbf65f43b5928625a9d4d0dc54b18cadc7ef3" integrity sha512-7lYL8bLopMoy4CTICbxygAUq6CdRJ36vFc80DucPueUee+d5NBRxz3FdT9Pes/HEx5mPoT9jwnsEJWz1N7uq7Q== -lodash@^4, lodash@^4.0.0, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@~4.17.21: +lodash@^4, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@~4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -10308,16 +10293,6 @@ minizlib@^2.1.1: minipass "^3.0.0" yallist "^4.0.0" -miragejs@^0.1.48: - version "0.1.48" - resolved "https://registry.yarnpkg.com/miragejs/-/miragejs-0.1.48.tgz#f30babc00186ac556f0058e5b050fa1137807c5c" - integrity sha512-MGZAq0Q3OuRYgZKvlB69z4gLN4G3PvgC4A2zhkCXCXrLD5wm2cCnwNB59xOBVA+srZ0zEes6u+VylcPIkB4SqA== - dependencies: - "@miragejs/pretender-node-polyfill" "^0.1.0" - inflected "^2.0.4" - lodash "^4.0.0" - pretender "^3.4.7" - mitt@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1" @@ -11545,14 +11520,6 @@ prepend-http@^2.0.0: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" integrity sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA== -pretender@^3.4.7: - version "3.4.7" - resolved "https://registry.yarnpkg.com/pretender/-/pretender-3.4.7.tgz#34a2ae2d1fc9db440a990d50e6c0f5481d8755fc" - integrity sha512-jkPAvt1BfRi0RKamweJdEcnjkeu7Es8yix3bJ+KgBC5VpG/Ln4JE3hYN6vJym4qprm8Xo5adhWpm3HCoft1dOw== - dependencies: - fake-xml-http-request "^2.1.2" - route-recognizer "^0.3.3" - prettier-linter-helpers@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" @@ -12399,11 +12366,6 @@ rimraf@~2.6.2: dependencies: glob "^7.1.3" -route-recognizer@^0.3.3: - version "0.3.4" - resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3" - integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g== - rtl-detect@^1.0.2: version "1.1.2" resolved "https://registry.yarnpkg.com/rtl-detect/-/rtl-detect-1.1.2.tgz#ca7f0330af5c6bb626c15675c642ba85ad6273c6" From 2aada8877e9280a97d58a3f764361b01e3173e04 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 10:20:40 +0100 Subject: [PATCH 07/13] chore: remove not needed useTimestamp hook --- src/hooks/index.ts | 1 - src/hooks/useTimestamp.ts | 15 --------------- 2 files changed, 16 deletions(-) delete mode 100644 src/hooks/useTimestamp.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 0635df19..8515d463 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -62,5 +62,4 @@ export * from './useCachedResources' export * from './useKeyboardHeight' export * from './useSafeAreaInsetsStyle' export * from './useSecurePassword' -export * from './useTimestamp' export * from './useToggle' diff --git a/src/hooks/useTimestamp.ts b/src/hooks/useTimestamp.ts deleted file mode 100644 index f56c4c78..00000000 --- a/src/hooks/useTimestamp.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { alert } from '@baca/utils' -import { useEffect } from 'react' - -export const useTimestamp = (): void => { - useEffect(() => { - fetch('/api/timestamp') - .then((response) => response.json()) - .then((data) => { - alert( - 'Warning', - `This is just an example response form miragejs \n\n ${JSON.stringify(data)}` - ) - }) - }, []) -} From d195653e7cc88145da59d46d187e0bd8563e09b4 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:46:24 +0100 Subject: [PATCH 08/13] chore: add msw library and update axios library; --- package.json | 4 +++- yarn.lock | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8e2d8e66..b54bff87 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "@react-navigation/native-stack": "^6.9.17", "@react-navigation/stack": "^6.3.20", "@tanstack/react-query": "^4.29.19", - "axios": "^0.27.2", + "axios": "^1.6.7", "expo": "^50.0.3", "expo-app-loading": "^2.1.1", "expo-application": "~5.8.3", @@ -182,6 +182,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-native": "^4.0.0", "eslint-plugin-react-native-globals": "^0.1.2", + "fast-text-encoding": "^1.0.6", "husky": "^8.0.3", "jest": "^29.6.1", "jest-expo": "~50.0.1", @@ -193,6 +194,7 @@ "prettier": "^2.8.8", "pretty-quick": "^4.0.0", "prompt-sync": "^4.2.0", + "react-native-url-polyfill": "^2.0.0", "react-test-renderer": "^18.2.0", "readline": "^1.3.0", "select-prompt": "^0.3.2", diff --git a/yarn.lock b/yarn.lock index 7f0ab148..99b3798c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4637,13 +4637,14 @@ available-typed-arrays@^1.0.6, available-typed-arrays@^1.0.7: dependencies: possible-typed-array-names "^1.0.0" -axios@^0.27.2: - version "0.27.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== +axios@^1.6.7: + version "1.6.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" + integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== dependencies: - follow-redirects "^1.14.9" + follow-redirects "^1.15.4" form-data "^4.0.0" + proxy-from-env "^1.1.0" babel-core@^7.0.0-bridge.0: version "7.0.0-bridge.0" @@ -7276,6 +7277,11 @@ fast-safe-stringify@^2.0.7: resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz#c406a83b6e70d9e35ce3b30a81141df30aeba884" integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA== +fast-text-encoding@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/fast-text-encoding/-/fast-text-encoding-1.0.6.tgz#0aa25f7f638222e3396d72bf936afcf1d42d6867" + integrity sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w== + fast-xml-parser@^4.0.12, fast-xml-parser@^4.2.4: version "4.3.3" resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-4.3.3.tgz#aeaf5778392329f17168c40c51bcbfec8ff965be" @@ -7502,7 +7508,7 @@ flow-parser@^0.206.0: resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.206.0.tgz#f4f794f8026535278393308e01ea72f31000bfef" integrity sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w== -follow-redirects@^1.0.0, follow-redirects@^1.14.9: +follow-redirects@^1.0.0, follow-redirects@^1.15.4: version "1.15.5" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020" integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw== @@ -11673,6 +11679,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + psl@^1.1.33: version "1.9.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" @@ -11938,6 +11949,13 @@ react-native-svg@14.1.0: css-select "^5.1.0" css-tree "^1.1.3" +react-native-url-polyfill@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz#db714520a2985cff1d50ab2e66279b9f91ffd589" + integrity sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA== + dependencies: + whatwg-url-without-unicode "8.0.0-3" + react-native-web@~0.19.6: version "0.19.10" resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.19.10.tgz#5f7205f8909c0889bc89c9fde7c6e287defa7c63" From 55f538978d30295cc72722faf408800f4c03715d Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:46:51 +0100 Subject: [PATCH 09/13] chore: update injectToken function to work with new axios --- src/api/axios/interceptors/injectToken.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/api/axios/interceptors/injectToken.ts b/src/api/axios/interceptors/injectToken.ts index 6261ac80..c30485c2 100644 --- a/src/api/axios/interceptors/injectToken.ts +++ b/src/api/axios/interceptors/injectToken.ts @@ -1,18 +1,14 @@ import { getToken } from '@baca/services' -import { AxiosRequestConfig } from 'axios' +import { InternalAxiosRequestConfig } from 'axios' -export const injectTokenToRequest = async (config: AxiosRequestConfig) => { +export const injectTokenToRequest = async ( + config: InternalAxiosRequestConfig +): Promise> => { const token = await getToken() - let Authorization = '' if (token) { - Authorization = `Bearer ${token}` - } - return { - ...config, - headers: { - ...config?.headers, - Authorization, - }, + config.headers['Authorization'] = `Bearer ${token}` } + + return config } From e07ed772e6d0675e63b35b5e69d2bd9a40d44c33 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:47:22 +0100 Subject: [PATCH 10/13] chore: make mocking work again (on web only right now) --- App.tsx | 7 ++++--- src/services/MockedServerService.ts | 32 +++++++++++++---------------- src/types/global.d.ts | 4 +++- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/App.tsx b/App.tsx index 9c2cd17d..328631cc 100644 --- a/App.tsx +++ b/App.tsx @@ -5,14 +5,15 @@ import 'setimmediate' import 'react-native-reanimated' +import 'fast-text-encoding' +import 'react-native-url-polyfill/auto' + // Rest imports import '@baca/i18n' - +import { enableAndroidBackgroundNotificationListener, startMockedServer } from '@baca/services' import * as Device from 'expo-device' import 'expo-router/entry' -import { enableAndroidBackgroundNotificationListener, startMockedServer } from '@baca/services' - // FIXME: there is some issue with miragejs that causes console.log to not work const DISABLE_CONSOLE_ENABLE_MOCKED_SERVER = false diff --git a/src/services/MockedServerService.ts b/src/services/MockedServerService.ts index 2735e2d2..83eac94c 100644 --- a/src/services/MockedServerService.ts +++ b/src/services/MockedServerService.ts @@ -1,22 +1,18 @@ -import { createServer } from 'miragejs' +import { getArticlesMock } from '@baca/api/query/articles/articles.msw' +import { getAuthMock } from '@baca/api/query/auth/auth.msw' +import { getAuthSocialMock } from '@baca/api/query/auth-social/auth-social.msw' +import { getFilesMock } from '@baca/api/query/files/files.msw' +import { getUsersMock } from '@baca/api/query/users/users.msw' +import { setupServer } from 'msw/native' export const startMockedServer = (): void => { - if (window.server) { - server.shutdown() - } + const server = setupServer( + ...getAuthMock(), + ...getUsersMock(), + ...getFilesMock(), + ...getAuthSocialMock(), + ...getArticlesMock() + ) - window.server = createServer({ - environment: 'development', - namespace: '/api', - timing: 400, - logging: true, - useDefaultPassthroughs: true, - routes() { - this.get('/timestamp', () => { - return { - timestamp: new Date().toISOString(), - } - }) - }, - }) + server.listen({ onUnhandledRequest: 'bypass' }) } diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 7f7ba695..0a00d4bf 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -1,4 +1,6 @@ -import { Server } from 'miragejs' +import { setupServer } from 'msw/native' + +type Server = ReturnType declare global { interface Window { From ea23ce61ec96aebc152c3a39144d39f92de23c69 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 09:49:01 +0100 Subject: [PATCH 11/13] chore: add comment about mocking on mobile --- App.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/App.tsx b/App.tsx index 328631cc..35fed6e0 100644 --- a/App.tsx +++ b/App.tsx @@ -14,10 +14,10 @@ import { enableAndroidBackgroundNotificationListener, startMockedServer } from ' import * as Device from 'expo-device' import 'expo-router/entry' -// FIXME: there is some issue with miragejs that causes console.log to not work -const DISABLE_CONSOLE_ENABLE_MOCKED_SERVER = false +// FIXME: moking not working on mobile app - follow this discussion https://github.com/mswjs/msw/issues/2026 +const ENABLE_MOCKED_SERVER = false -if (DISABLE_CONSOLE_ENABLE_MOCKED_SERVER) { +if (ENABLE_MOCKED_SERVER) { startMockedServer() } From 0c466ffedc63db2d8f4265d5e1fca352b21e990d Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 10:19:56 +0100 Subject: [PATCH 12/13] chore: remove mirage js library --- package.json | 1 - yarn.lock | 40 +--------------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/package.json b/package.json index b54bff87..cfb5820c 100644 --- a/package.json +++ b/package.json @@ -187,7 +187,6 @@ "jest": "^29.6.1", "jest-expo": "~50.0.1", "lint-staged": "^13.2.3", - "miragejs": "^0.1.48", "msw": "^2.2.2", "orval": "^6.25.0", "patch-package": "^7.0.1", diff --git a/yarn.lock b/yarn.lock index 99b3798c..9100e4ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2369,11 +2369,6 @@ resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== -"@miragejs/pretender-node-polyfill@^0.1.0": - version "0.1.2" - resolved "https://registry.yarnpkg.com/@miragejs/pretender-node-polyfill/-/pretender-node-polyfill-0.1.2.tgz#d26b6b7483fb70cd62189d05c95d2f67153e43f2" - integrity sha512-M/BexG/p05C5lFfMunxo/QcgIJnMT2vDVCd00wNqK2ImZONIlEETZwWJu1QtLxtmYlSHlCFl3JNzp0tLe7OJ5g== - "@motify/components@^0.17.1": version "0.17.1" resolved "https://registry.yarnpkg.com/@motify/components/-/components-0.17.1.tgz#96888fb0d5c6d41f484d98c9364764e511d83086" @@ -7226,11 +7221,6 @@ express@^4.17.3: utils-merge "1.0.1" vary "~1.1.2" -fake-xml-http-request@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.1.2.tgz#f1786720cae50bbb46273035a0173414f3e85e74" - integrity sha512-HaFMBi7r+oEC9iJNpc3bvcW7Z7iLmM26hPDmlb0mFwyANSsOQAtJxbdWsXITKOzZUyMYK0zYCv3h5yDj9TsiXg== - fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" @@ -8321,11 +8311,6 @@ infer-owner@^1.0.4: resolved "https://registry.yarnpkg.com/infer-owner/-/infer-owner-1.0.4.tgz#c4cefcaa8e51051c2a40ba2ce8a3d27295af9467" integrity sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A== -inflected@^2.0.4: - version "2.1.0" - resolved "https://registry.yarnpkg.com/inflected/-/inflected-2.1.0.tgz#2816ac17a570bbbc8303ca05bca8bf9b3f959687" - integrity sha512-hAEKNxvHf2Iq3H60oMBHkB4wl5jn3TPF3+fXek/sRwAB5gP9xWs4r7aweSF95f99HFoz69pnZTcu8f0SIHV18w== - inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -9777,7 +9762,7 @@ lodash.uniqwith@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniqwith/-/lodash.uniqwith-4.5.0.tgz#7a0cbf65f43b5928625a9d4d0dc54b18cadc7ef3" integrity sha512-7lYL8bLopMoy4CTICbxygAUq6CdRJ36vFc80DucPueUee+d5NBRxz3FdT9Pes/HEx5mPoT9jwnsEJWz1N7uq7Q== -lodash@^4, lodash@^4.0.0, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@~4.17.21: +lodash@^4, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@~4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -10308,16 +10293,6 @@ minizlib@^2.1.1: minipass "^3.0.0" yallist "^4.0.0" -miragejs@^0.1.48: - version "0.1.48" - resolved "https://registry.yarnpkg.com/miragejs/-/miragejs-0.1.48.tgz#f30babc00186ac556f0058e5b050fa1137807c5c" - integrity sha512-MGZAq0Q3OuRYgZKvlB69z4gLN4G3PvgC4A2zhkCXCXrLD5wm2cCnwNB59xOBVA+srZ0zEes6u+VylcPIkB4SqA== - dependencies: - "@miragejs/pretender-node-polyfill" "^0.1.0" - inflected "^2.0.4" - lodash "^4.0.0" - pretender "^3.4.7" - mitt@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1" @@ -11545,14 +11520,6 @@ prepend-http@^2.0.0: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" integrity sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA== -pretender@^3.4.7: - version "3.4.7" - resolved "https://registry.yarnpkg.com/pretender/-/pretender-3.4.7.tgz#34a2ae2d1fc9db440a990d50e6c0f5481d8755fc" - integrity sha512-jkPAvt1BfRi0RKamweJdEcnjkeu7Es8yix3bJ+KgBC5VpG/Ln4JE3hYN6vJym4qprm8Xo5adhWpm3HCoft1dOw== - dependencies: - fake-xml-http-request "^2.1.2" - route-recognizer "^0.3.3" - prettier-linter-helpers@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" @@ -12399,11 +12366,6 @@ rimraf@~2.6.2: dependencies: glob "^7.1.3" -route-recognizer@^0.3.3: - version "0.3.4" - resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3" - integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g== - rtl-detect@^1.0.2: version "1.1.2" resolved "https://registry.yarnpkg.com/rtl-detect/-/rtl-detect-1.1.2.tgz#ca7f0330af5c6bb626c15675c642ba85ad6273c6" From 9b8e6b7c36eef9b62abc12e4800ac39d8d3b3826 Mon Sep 17 00:00:00 2001 From: Mateusz Rostkowski Date: Thu, 7 Mar 2024 10:20:40 +0100 Subject: [PATCH 13/13] chore: remove not needed useTimestamp hook --- src/hooks/index.ts | 1 - src/hooks/useTimestamp.ts | 15 --------------- 2 files changed, 16 deletions(-) delete mode 100644 src/hooks/useTimestamp.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 0635df19..8515d463 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -62,5 +62,4 @@ export * from './useCachedResources' export * from './useKeyboardHeight' export * from './useSafeAreaInsetsStyle' export * from './useSecurePassword' -export * from './useTimestamp' export * from './useToggle' diff --git a/src/hooks/useTimestamp.ts b/src/hooks/useTimestamp.ts deleted file mode 100644 index f56c4c78..00000000 --- a/src/hooks/useTimestamp.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { alert } from '@baca/utils' -import { useEffect } from 'react' - -export const useTimestamp = (): void => { - useEffect(() => { - fetch('/api/timestamp') - .then((response) => response.json()) - .then((data) => { - alert( - 'Warning', - `This is just an example response form miragejs \n\n ${JSON.stringify(data)}` - ) - }) - }, []) -}