diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bcb8d0..7814463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.2.1 + +- Added `--dir` option `serve` command.˝ + ## 0.2.0 - Removed `email` field from user model. diff --git a/docs/malta.config.json b/docs/malta.config.json index 20527ac..11a7837 100644 --- a/docs/malta.config.json +++ b/docs/malta.config.json @@ -35,8 +35,9 @@ { "title": "API reference", "pages": [ - ["Rest API", "/api-reference/rest"], - ["JavaScript SDK", "/api-reference/sdk-js"] + ["CLI", "/reference/cli"], + ["Rest API", "/reference/rest"], + ["JavaScript SDK", "/reference/sdk-js"] ] }, { diff --git a/docs/pages/api-reference/rest/index.md b/docs/pages/api-reference/rest/index.md deleted file mode 100644 index 6afe5a4..0000000 --- a/docs/pages/api-reference/rest/index.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: "REST API reference" ---- - -# REST API reference - -All rest endpoints expects a JSON body and returns an JSON object. - -## Authentication - -Set the `Authorization` header to the credential you provided when initializing your server. - -``` -Authorization: YOUR_CREDENTIAL -``` - -Faroe will return a 401 error response if the request has an invalid credential. - -```json -{ - "error": "NOT_AUTHENTICATED" -} -``` - -## Responses - -Successful responses will have a 200 status if it includes a response body or 204 status if not. - -All error responses have a 4xx or 5xx status and includes a JSON object with an `error` field. See each endpoint's page for a list of possible response statuses and error codes. - -```json -{ - "error": "INVALID_DATA" -} -``` - -## Data types - -- Email address: Must be less than 256 characters long, have a "@", and a "." in the domain part. Cannot start or end with a whitespace. -- Password: Must be between 8 and 127 characters. - -## Models - -- [User](/api-reference/rest/models/user) -- [User email verification request](/api-reference/rest/models/user-email-verification-request) -- [User TOTP credential](/api-reference/rest/models/user-totp-credential) -- [Password reset request](/api-reference/rest/models/password-reset-request) - -## Endpoints - -### Authentication - -- [POST /authenticate/password](/api-reference/rest/endpoints/post_authenticate_password): Authenticate user with email and password. - -### Users - -- [POST /users](/api-reference/rest/endpoints/post_users): Create a new user. -- [GET /users](/api-reference/rest/endpoints/get_users): Get a list of users. -- [GET /users/\[user_id\]](/api-reference/rest/endpoints/get_users_userid): Get a user. -- [DELETE /users/\[user_id\]](/api-reference/rest/endpoints/delete_users_userid): Delete a user. -- [POST /users/\[user_id\]/update-password](/api-reference/rest/endpoints/post_users_userid_update-password): Update a user's password. - -#### Email verification - -- [POST /users/\[user_id\]/email-verification-request](/api-reference/rest/endpoints/post_users_userid_email-verification-request): Create a new user email verification request. -- [GET /users/\[user_id\]/email-verification-request](/api-reference/rest/endpoints/get_users_userid_email-verification-request): Get a user's email verification request. -- [DELETE /users/\[user_id\]/email-verification-request](/api-reference/rest/endpoints/delete_users_userid_email-verification-request): Delete a user's email verification request. -- [POST /users/\[user_id\]/verify-email](/api-reference/rest/endpoints/post_users_userid_verify-email): Verify their email verification request code. - -#### Email update - -- [POST /users/\[user_id\]/email-update-requests](/api-reference/rest/endpoints/post_users_userid_email-update-requests): Create a new user email update request. -- [GET /users/\[user_id\]/email-update-requests](/api-reference/rest/endpoints/get_users_userid_email-update-requests): Gets a list of a user's email update requests. -- [DELETE /users/\[user_id\]/email-update-requests](/api-reference/rest/endpoints/delete_users_userid_email-update-requests): Deletes a user's email update requests. -- [GET /email-update-requests/\[request_id\]](/api-reference/rest/endpoints/get_email-update-requests_requestid): Get an email update request. -- [DELETE /email-update-requests/\[request_id\]](/api-reference/rest/endpoints/delete_email-update-requests_requestid): Delete an email update request. -- [POST /verify-new-email](/api-reference/rest/endpoints/post_verify-new-email): Update a user's email by verifying their email update request code. - -#### Two-factor authentication - -- [POST /users/\[user_id\/register-totp](/api-reference/rest/endpoints/post_users_userid_register-totp): Register a TOTP credential. -- [GET /users/\[user_id\]/totp-credential](/api-reference/rest/endpoints/get_users_userid_totp-credential): Get a user's TOTP credential. -- [DELETE /users/\[user_id\]/totp-credential](/api-reference/rest/endpoints/delete_users_userid_totp-credential): Delete a user's TOTP credential. -- [POST /users/\[user_id\]/verify-2fa/totp](/api-reference/rest/endpoints/post_users_userid_verify-2fa_totp): Verify a user's TOTP code. -- [POST /users/\[user_id\]/regenerate-recovery-code](/api-reference/rest/endpoints/post_users_userid_regenerate-recovery-code): Generate a new user recovery code. -- [POST /users/\[user_id\]/reset-2fa](/api-reference/rest/endpoints/post_users_userid_reset-2fa): Reset a user's second factors with a recovery code. - -### Password reset - -- [POST /users/\[user_id\]/password-reset-requests](/api-reference/rest/endpoints/post_users_userid_password-reset-requests): Create a new password reset request for a user. -- [GET /password-reset-requests/\[request_id\]](/api-reference/rest/endpoints/get_password-reset-requests_requestid): Get a password reset request. -- [DELETE /password-reset-requests/\[request_id\]](/api-reference/rest/endpoints/delete_password-reset-requests_requestid): Delete a password reset request. -- [POST /password-reset-requests/\[request_id\]/verify-email](/api-reference/rest/endpoints/post_password-reset-requests_requestid_verify-email): Verify a reset request's email. -- [POST /reset-password](/api-reference/rest/endpoints/post_reset-password): Reset the user's password with a verified reset request. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/index.md b/docs/pages/api-reference/sdk-js/main/Faroe/index.md deleted file mode 100644 index 0315a35..0000000 --- a/docs/pages/api-reference/sdk-js/main/Faroe/index.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: "Faroe" ---- - -# Faroe - -Represents a Faroe server client. - -Server errors are thrown as [`FaroeError`](/api-reference/sdk-js/main/FaroeError). The error code is available from `FaroeError.code`. See each method for a list of possible error codes. - -```ts -import { Faroe, FaroeError } from "@faroe/sdk" - -const faroe = new Faroe(url, secret); - -try { - await faroe.createUser(password, clientIP); -} catch (e) { - if (e instanceof FaroeError) { - const errorCode = e.code; - } -} -``` - -Errors caused by `fetch()` are wrapped as [`FaroeFetchError`](/api-reference/sdk-js/main/FaroeFetchError). - -## Constructor - -```ts -function constructor(url: string, credential: string | null): this -``` - -### Parameters - -- `url`: The base URL of the Faroe server (e.g. `https://your-domain.com`). -- `credential`: The server credential. - -## Methods - -- [`createUser()`](/api-reference/sdk-js/main/Faroe/createUser) -- [`createUserEmailUpdateRequest()`](/api-reference/sdk-js/main/Faroe/createUserEmailUpdateRequest) -- [`createUserEmailVerificationRequest()`](/api-reference/sdk-js/main/Faroe/createUserEmailVerificationRequest) -- [`createUserPasswordResetRequest()`](/api-reference/sdk-js/main/Faroe/createUserPasswordResetRequest) -- [`deleteEmailUpdateRequest()`](/api-reference/sdk-js/main/Faroe/deleteEmailUpdateRequest) -- [`deletePasswordResetRequest()`](/api-reference/sdk-js/main/Faroe/deletePasswordResetRequest) -- [`deleteUser()`](/api-reference/sdk-js/main/Faroe/deleteUser) -- [`deleteUserEmailUpdateRequests()`](/api-reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests) -- [`deleteUserEmailVerificationRequest()`](/api-reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest) -- [`deleteUserPasswordResetRequests()`](/api-reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests) -- [`deleteUserTOTPCredential()`](/api-reference/sdk-js/main/Faroe/deleteUserTOTPCredential) -- [`getEmailUpdateRequest()`](/api-reference/sdk-js/main/Faroe/getEmailUpdateRequest) -- [`getPasswordResetRequest()`](/api-reference/sdk-js/main/Faroe/getPasswordResetRequest) -- [`getUser()`](/api-reference/sdk-js/main/Faroe/getUser) -- [`getUserEmailUpdateRequests()`](/api-reference/sdk-js/main/Faroe/getUserEmailUpdateRequests) -- [`getUserEmailVerificationRequest()`](/api-reference/sdk-js/main/Faroe/getUserEmailVerificationRequest) -- [`getUserPasswordResetRequests()`](/api-reference/sdk-js/main/Faroe/getUserPasswordResetRequests) -- [`getUsers()`](/api-reference/sdk-js/main/Faroe/getUsers) -- [`getUserTOTPCredential()`](/api-reference/sdk-js/main/Faroe/getUserTOTPCredential) -- [`regenerateUserRecoveryCode()`](/api-reference/sdk-js/main/Faroe/regenerateUserRecoveryCode) -- [`registerUserTOTPCredential()`](/api-reference/sdk-js/main/Faroe/registerUserTOTPCredential) -- [`resetUser2FA()`](/api-reference/sdk-js/main/Faroe/resetUser2FA) -- [`resetUserPassword()`](/api-reference/sdk-js/main/Faroe/resetUserPassword) -- [`updateUserPassword()`](/api-reference/sdk-js/main/Faroe/updateUserPassword) -- [`verifyNewUserEmail()`](/api-reference/sdk-js/main/Faroe/verifyNewUserEmail) -- [`verifyPasswordResetRequestEmail()`](/api-reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail) -- [`verifyUser2FAWithTOTP()`](/api-reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP) -- [`verifyUserEmail()`](/api-reference/sdk-js/main/Faroe/verifyUserEmail) -- [`verifyUserPassword()`](/api-reference/sdk-js/main/Faroe/verifyUserPassword) - -## Example - -```ts -import { Faroe } from "@faroe/sdk" - -const faroe = new Faroe("https://your-domain.com", process.env.FAROE_CREDENTIAL); -``` diff --git a/docs/pages/api-reference/sdk-js/main/index.md b/docs/pages/api-reference/sdk-js/main/index.md deleted file mode 100644 index b329d58..0000000 --- a/docs/pages/api-reference/sdk-js/main/index.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: "@faroe/sdk" ---- - -# @faroe/sdk - -## Functions - -- [`verifyEmailInput()`](/api-reference/sdk-js/main/verifyEmailInput) -- [`verifyPasswordInput()`](/api-reference/sdk-js/main/verifyPasswordInput) - -## Classes - -- [`Faroe`](/api-reference/sdk-js/main/Faroe) -- [`FaroeError`](/api-reference/sdk-js/main/FaroeError) -- [`FaroeFetchError`](/api-reference/sdk-js/main/FaroeFetchError) - -## Interfaces - -- [`FaroeEmailUpdateRequest`](/api-reference/sdk-js/main/FaroeEmailUpdateRequest) -- [`FaroePasswordResetRequest`](/api-reference/sdk-js/main/FaroePasswordResetRequest) -- [`FaroeUserEmailVerificationRequest`](/api-reference/sdk-js/main/FaroeUserEmailVerificationRequest) -- [`FaroeUserTOTPCredential`](/api-reference/sdk-js/main/FaroeUserTOTPCredential) -- [`FaroeUser`](/api-reference/sdk-js/main/FaroeUser) -- [`PaginationResult`](/api-reference/sdk-js/main/PaginationResult) - -## Enums - -- [`UserSortBy`](/api-reference/sdk-js/main/UserSortBy) -- [`SortOrder`](/api-reference/sdk-js/main/SortOrder) diff --git a/docs/pages/reference/cli/index.md b/docs/pages/reference/cli/index.md new file mode 100644 index 0000000..5b974a1 --- /dev/null +++ b/docs/pages/reference/cli/index.md @@ -0,0 +1,33 @@ +--- +title: "CLI reference" +--- + +# CLI reference + +## generate-secret + +Generates a random secret with 200 bits of entropy using a cryptographically secure source. + +``` +faroe generate-secret +``` + +## serve + +Creates a `faroe_data` directory with an SQLite database file if it doesn't already exist and starts the server on port 4000. + +``` +faroe serve [...options] +``` + +### Options + +- `--port`: The port number (default: 4000). +- `--dir`: The path of the directory to store data (default: `faroe_data`). +- `--secret`: A random secret. If provided, requires requests to the server to include the secret in the `Authorization` header. + +### Example + +``` +faroe serve --port=3000 --dir="/data/faroe" --secret=SECURE_SECRET +``` \ No newline at end of file diff --git a/docs/pages/api-reference/rest/endpoints/delete_email-update-requests_requestid.md b/docs/pages/reference/rest/endpoints/delete_email-update-requests_requestid.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_email-update-requests_requestid.md rename to docs/pages/reference/rest/endpoints/delete_email-update-requests_requestid.md diff --git a/docs/pages/api-reference/rest/endpoints/delete_password-reset-requests_requestid.md b/docs/pages/reference/rest/endpoints/delete_password-reset-requests_requestid.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_password-reset-requests_requestid.md rename to docs/pages/reference/rest/endpoints/delete_password-reset-requests_requestid.md diff --git a/docs/pages/api-reference/rest/endpoints/delete_users_userid.md b/docs/pages/reference/rest/endpoints/delete_users_userid.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_users_userid.md rename to docs/pages/reference/rest/endpoints/delete_users_userid.md diff --git a/docs/pages/api-reference/rest/endpoints/delete_users_userid_email-update-requests.md b/docs/pages/reference/rest/endpoints/delete_users_userid_email-update-requests.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_users_userid_email-update-requests.md rename to docs/pages/reference/rest/endpoints/delete_users_userid_email-update-requests.md diff --git a/docs/pages/api-reference/rest/endpoints/delete_users_userid_email-verification-request.md b/docs/pages/reference/rest/endpoints/delete_users_userid_email-verification-request.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_users_userid_email-verification-request.md rename to docs/pages/reference/rest/endpoints/delete_users_userid_email-verification-request.md diff --git a/docs/pages/api-reference/rest/endpoints/delete_users_userid_password-reset-requests.md b/docs/pages/reference/rest/endpoints/delete_users_userid_password-reset-requests.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_users_userid_password-reset-requests.md rename to docs/pages/reference/rest/endpoints/delete_users_userid_password-reset-requests.md diff --git a/docs/pages/api-reference/rest/endpoints/delete_users_userid_totp-credential.md b/docs/pages/reference/rest/endpoints/delete_users_userid_totp-credential.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/delete_users_userid_totp-credential.md rename to docs/pages/reference/rest/endpoints/delete_users_userid_totp-credential.md diff --git a/docs/pages/api-reference/rest/endpoints/get_email-update-requests_requestid.md b/docs/pages/reference/rest/endpoints/get_email-update-requests_requestid.md similarity index 72% rename from docs/pages/api-reference/rest/endpoints/get_email-update-requests_requestid.md rename to docs/pages/reference/rest/endpoints/get_email-update-requests_requestid.md index ccf8561..4e812fc 100644 --- a/docs/pages/api-reference/rest/endpoints/get_email-update-requests_requestid.md +++ b/docs/pages/reference/rest/endpoints/get_email-update-requests_requestid.md @@ -12,7 +12,7 @@ GET https://your-domain.com/email-update-requests/[request_id] ## Successful response -Returns the [email update request model](/api-reference/rest/models/email-update-request) if the request exists and is valid. +Returns the [email update request model](/reference/rest/models/email-update-request) if the request exists and is valid. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/get_password-reset-requests_requestid.md b/docs/pages/reference/rest/endpoints/get_password-reset-requests_requestid.md similarity index 72% rename from docs/pages/api-reference/rest/endpoints/get_password-reset-requests_requestid.md rename to docs/pages/reference/rest/endpoints/get_password-reset-requests_requestid.md index a011948..c749a9a 100644 --- a/docs/pages/api-reference/rest/endpoints/get_password-reset-requests_requestid.md +++ b/docs/pages/reference/rest/endpoints/get_password-reset-requests_requestid.md @@ -12,7 +12,7 @@ GET https://your-domain.com/password-reset-requests/REQUEST_ID ## Successful response -Returns the [password reset request model](/api-reference/rest/models/password-reset-request) if the request exists and is valid. +Returns the [password reset request model](/reference/rest/models/password-reset-request) if the request exists and is valid. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/get_users.md b/docs/pages/reference/rest/endpoints/get_users.md similarity index 89% rename from docs/pages/api-reference/rest/endpoints/get_users.md rename to docs/pages/reference/rest/endpoints/get_users.md index 0005553..e581476 100644 --- a/docs/pages/api-reference/rest/endpoints/get_users.md +++ b/docs/pages/reference/rest/endpoints/get_users.md @@ -31,7 +31,7 @@ All parameters are optional. ## Successful response -Returns a JSON array of [user models](/api-reference/rest/models/user). If there are no users in the page, it will return an empty array. +Returns a JSON array of [user models](/reference/rest/models/user). If there are no users in the page, it will return an empty array. You can get the number of total pages from the `X-Pagination-Total-Pages` header and the total number of users with the `X-Pagination-Total` header.. diff --git a/docs/pages/api-reference/rest/endpoints/get_users_userid.md b/docs/pages/reference/rest/endpoints/get_users_userid.md similarity index 73% rename from docs/pages/api-reference/rest/endpoints/get_users_userid.md rename to docs/pages/reference/rest/endpoints/get_users_userid.md index a089c6f..54af342 100644 --- a/docs/pages/api-reference/rest/endpoints/get_users_userid.md +++ b/docs/pages/reference/rest/endpoints/get_users_userid.md @@ -12,7 +12,7 @@ GET https://your-domain.com/users/USER_ID ## Successful response -Returns the [user model](/api-reference/rest/models/user) of the user if they exist. +Returns the [user model](/reference/rest/models/user) of the user if they exist. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/get_users_userid_email-update-requests.md b/docs/pages/reference/rest/endpoints/get_users_userid_email-update-requests.md similarity index 76% rename from docs/pages/api-reference/rest/endpoints/get_users_userid_email-update-requests.md rename to docs/pages/reference/rest/endpoints/get_users_userid_email-update-requests.md index 91d4067..2872a53 100644 --- a/docs/pages/api-reference/rest/endpoints/get_users_userid_email-update-requests.md +++ b/docs/pages/reference/rest/endpoints/get_users_userid_email-update-requests.md @@ -12,7 +12,7 @@ GET https://your-domain.com/users/USER_ID/email-update-requests ## Successful response -Returns a JSON array of [email update request models](/api-reference/rest/models/email-update-request). If the user does not have any update requests, it will return an empty array. +Returns a JSON array of [email update request models](/reference/rest/models/email-update-request). If the user does not have any update requests, it will return an empty array. ### Example diff --git a/docs/pages/api-reference/rest/endpoints/get_users_userid_email-verification-request.md b/docs/pages/reference/rest/endpoints/get_users_userid_email-verification-request.md similarity index 74% rename from docs/pages/api-reference/rest/endpoints/get_users_userid_email-verification-request.md rename to docs/pages/reference/rest/endpoints/get_users_userid_email-verification-request.md index 609433f..ecdce3a 100644 --- a/docs/pages/api-reference/rest/endpoints/get_users_userid_email-verification-request.md +++ b/docs/pages/reference/rest/endpoints/get_users_userid_email-verification-request.md @@ -12,7 +12,7 @@ GET https://your-domain.com/users/USER_ID/email-verification-reqes ## Successful response -Returns the [user email verification request model](/api-reference/rest/models/user-email-verification-request) if the request exists and is valid. +Returns the [user email verification request model](/reference/rest/models/user-email-verification-request) if the request exists and is valid. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/get_users_userid_password-reset-requests.md b/docs/pages/reference/rest/endpoints/get_users_userid_password-reset-requests.md similarity index 74% rename from docs/pages/api-reference/rest/endpoints/get_users_userid_password-reset-requests.md rename to docs/pages/reference/rest/endpoints/get_users_userid_password-reset-requests.md index cf61d00..f3c9b86 100644 --- a/docs/pages/api-reference/rest/endpoints/get_users_userid_password-reset-requests.md +++ b/docs/pages/reference/rest/endpoints/get_users_userid_password-reset-requests.md @@ -12,7 +12,7 @@ GET https://your-domain.com/users/USER_ID/password-reset-requests ## Successful response -Returns a JSON array of [password reset request models](/api-reference/rest/models/password-reset-request). If the user does not have any update requests, it will return an empty array. +Returns a JSON array of [password reset request models](/reference/rest/models/password-reset-request). If the user does not have any update requests, it will return an empty array. ### Example diff --git a/docs/pages/api-reference/rest/endpoints/get_users_userid_totp-credential.md b/docs/pages/reference/rest/endpoints/get_users_userid_totp-credential.md similarity index 71% rename from docs/pages/api-reference/rest/endpoints/get_users_userid_totp-credential.md rename to docs/pages/reference/rest/endpoints/get_users_userid_totp-credential.md index f20a2d0..a484e9a 100644 --- a/docs/pages/api-reference/rest/endpoints/get_users_userid_totp-credential.md +++ b/docs/pages/reference/rest/endpoints/get_users_userid_totp-credential.md @@ -12,7 +12,7 @@ GET https://your-domain.com/users/USER_ID/totp-credential ## Response body -Returns the [user TOTP credential model](/api-reference/rest/models/user-totp-credential) of the credential if it exists. +Returns the [user TOTP credential model](/reference/rest/models/user-totp-credential) of the credential if it exists. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/post_password-reset-requests_requestid_verify-email.md b/docs/pages/reference/rest/endpoints/post_password-reset-requests_requestid_verify-email.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_password-reset-requests_requestid_verify-email.md rename to docs/pages/reference/rest/endpoints/post_password-reset-requests_requestid_verify-email.md diff --git a/docs/pages/api-reference/rest/endpoints/post_reset-password.md b/docs/pages/reference/rest/endpoints/post_reset-password.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_reset-password.md rename to docs/pages/reference/rest/endpoints/post_reset-password.md diff --git a/docs/pages/api-reference/rest/endpoints/post_users.md b/docs/pages/reference/rest/endpoints/post_users.md similarity index 91% rename from docs/pages/api-reference/rest/endpoints/post_users.md rename to docs/pages/reference/rest/endpoints/post_users.md index 580787c..f5d9085 100644 --- a/docs/pages/api-reference/rest/endpoints/post_users.md +++ b/docs/pages/reference/rest/endpoints/post_users.md @@ -35,7 +35,7 @@ POST https://your-domain.com/users ## Successful response -Returns the [user model](/api-reference/rest/models/user) of the created user. +Returns the [user model](/reference/rest/models/user) of the created user. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_email-update-requests.md b/docs/pages/reference/rest/endpoints/post_users_userid_email-update-requests.md similarity index 84% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_email-update-requests.md rename to docs/pages/reference/rest/endpoints/post_users_userid_email-update-requests.md index 43ac3e3..f125fb0 100644 --- a/docs/pages/api-reference/rest/endpoints/post_users_userid_email-update-requests.md +++ b/docs/pages/reference/rest/endpoints/post_users_userid_email-update-requests.md @@ -24,7 +24,7 @@ POST https://your-domain.com/users/USER_ID/email-update-requests ## Successful response -Returns the [email update request model](/api-reference/rest/models/email-verification-request) of the created request. +Returns the [email update request model](/reference/rest/models/email-verification-request) of the created request. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_email-verification-request.md b/docs/pages/reference/rest/endpoints/post_users_userid_email-verification-request.md similarity index 77% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_email-verification-request.md rename to docs/pages/reference/rest/endpoints/post_users_userid_email-verification-request.md index e6e13ce..c29a77e 100644 --- a/docs/pages/api-reference/rest/endpoints/post_users_userid_email-verification-request.md +++ b/docs/pages/reference/rest/endpoints/post_users_userid_email-verification-request.md @@ -12,7 +12,7 @@ POST https://your-domain.com/users/USER_ID/email-verification-request ## Successful response -Returns the [user email verification request model](/api-reference/rest/models/user-email-verification-request) of the created request. +Returns the [user email verification request model](/reference/rest/models/user-email-verification-request) of the created request. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_password-reset-requests.md b/docs/pages/reference/rest/endpoints/post_users_userid_password-reset-requests.md similarity index 86% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_password-reset-requests.md rename to docs/pages/reference/rest/endpoints/post_users_userid_password-reset-requests.md index e123273..19e1712 100644 --- a/docs/pages/api-reference/rest/endpoints/post_users_userid_password-reset-requests.md +++ b/docs/pages/reference/rest/endpoints/post_users_userid_password-reset-requests.md @@ -30,7 +30,7 @@ POST https://your-domain.com/users/USER_ID/password-reset-requests ## Successful response -Returns the [password reset request model](/api-reference/rest/models/password-reset-requests-request) of the created request and a verification code. The code is only available here. +Returns the [password reset request model](/reference/rest/models/password-reset-requests-request) of the created request and a verification code. The code is only available here. ```ts { diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_regenerate-recovery-code.md b/docs/pages/reference/rest/endpoints/post_users_userid_regenerate-recovery-code.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_regenerate-recovery-code.md rename to docs/pages/reference/rest/endpoints/post_users_userid_regenerate-recovery-code.md diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_register-totp.md b/docs/pages/reference/rest/endpoints/post_users_userid_register-totp.md similarity index 84% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_register-totp.md rename to docs/pages/reference/rest/endpoints/post_users_userid_register-totp.md index 3f800a6..64ddc56 100644 --- a/docs/pages/api-reference/rest/endpoints/post_users_userid_register-totp.md +++ b/docs/pages/reference/rest/endpoints/post_users_userid_register-totp.md @@ -26,7 +26,7 @@ All fields are required. ## Response body -Returns the [user TOTP credential model](/api-reference/rest/models/user-totp-credential) of the registered credential. +Returns the [user TOTP credential model](/reference/rest/models/user-totp-credential) of the registered credential. ## Error codes diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_reset-2fa.md b/docs/pages/reference/rest/endpoints/post_users_userid_reset-2fa.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_reset-2fa.md rename to docs/pages/reference/rest/endpoints/post_users_userid_reset-2fa.md diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_update-password.md b/docs/pages/reference/rest/endpoints/post_users_userid_update-password.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_update-password.md rename to docs/pages/reference/rest/endpoints/post_users_userid_update-password.md diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_verify-2fa_totp.md b/docs/pages/reference/rest/endpoints/post_users_userid_verify-2fa_totp.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_verify-2fa_totp.md rename to docs/pages/reference/rest/endpoints/post_users_userid_verify-2fa_totp.md diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_verify-email.md b/docs/pages/reference/rest/endpoints/post_users_userid_verify-email.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_verify-email.md rename to docs/pages/reference/rest/endpoints/post_users_userid_verify-email.md diff --git a/docs/pages/api-reference/rest/endpoints/post_users_userid_verify-password.md b/docs/pages/reference/rest/endpoints/post_users_userid_verify-password.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_users_userid_verify-password.md rename to docs/pages/reference/rest/endpoints/post_users_userid_verify-password.md diff --git a/docs/pages/api-reference/rest/endpoints/post_verify-new-email.md b/docs/pages/reference/rest/endpoints/post_verify-new-email.md similarity index 100% rename from docs/pages/api-reference/rest/endpoints/post_verify-new-email.md rename to docs/pages/reference/rest/endpoints/post_verify-new-email.md diff --git a/docs/pages/reference/rest/index.md b/docs/pages/reference/rest/index.md new file mode 100644 index 0000000..e95eb19 --- /dev/null +++ b/docs/pages/reference/rest/index.md @@ -0,0 +1,94 @@ +--- +title: "REST API reference" +--- + +# REST API reference + +All rest endpoints expects a JSON body and returns an JSON object. + +## Authentication + +Set the `Authorization` header to the credential you provided when initializing your server. + +``` +Authorization: YOUR_CREDENTIAL +``` + +Faroe will return a 401 error response if the request has an invalid credential. + +```json +{ + "error": "NOT_AUTHENTICATED" +} +``` + +## Responses + +Successful responses will have a 200 status if it includes a response body or 204 status if not. + +All error responses have a 4xx or 5xx status and includes a JSON object with an `error` field. See each endpoint's page for a list of possible response statuses and error codes. + +```json +{ + "error": "INVALID_DATA" +} +``` + +## Data types + +- Email address: Must be less than 256 characters long, have a "@", and a "." in the domain part. Cannot start or end with a whitespace. +- Password: Must be between 8 and 127 characters. + +## Models + +- [User](/reference/rest/models/user) +- [User email verification request](/reference/rest/models/user-email-verification-request) +- [User TOTP credential](/reference/rest/models/user-totp-credential) +- [Password reset request](/reference/rest/models/password-reset-request) + +## Endpoints + +### Authentication + +- [POST /authenticate/password](/reference/rest/endpoints/post_authenticate_password): Authenticate user with email and password. + +### Users + +- [POST /users](/reference/rest/endpoints/post_users): Create a new user. +- [GET /users](/reference/rest/endpoints/get_users): Get a list of users. +- [GET /users/\[user_id\]](/reference/rest/endpoints/get_users_userid): Get a user. +- [DELETE /users/\[user_id\]](/reference/rest/endpoints/delete_users_userid): Delete a user. +- [POST /users/\[user_id\]/update-password](/reference/rest/endpoints/post_users_userid_update-password): Update a user's password. + +#### Email verification + +- [POST /users/\[user_id\]/email-verification-request](/reference/rest/endpoints/post_users_userid_email-verification-request): Create a new user email verification request. +- [GET /users/\[user_id\]/email-verification-request](/reference/rest/endpoints/get_users_userid_email-verification-request): Get a user's email verification request. +- [DELETE /users/\[user_id\]/email-verification-request](/reference/rest/endpoints/delete_users_userid_email-verification-request): Delete a user's email verification request. +- [POST /users/\[user_id\]/verify-email](/reference/rest/endpoints/post_users_userid_verify-email): Verify their email verification request code. + +#### Email update + +- [POST /users/\[user_id\]/email-update-requests](/reference/rest/endpoints/post_users_userid_email-update-requests): Create a new user email update request. +- [GET /users/\[user_id\]/email-update-requests](/reference/rest/endpoints/get_users_userid_email-update-requests): Gets a list of a user's email update requests. +- [DELETE /users/\[user_id\]/email-update-requests](/reference/rest/endpoints/delete_users_userid_email-update-requests): Deletes a user's email update requests. +- [GET /email-update-requests/\[request_id\]](/reference/rest/endpoints/get_email-update-requests_requestid): Get an email update request. +- [DELETE /email-update-requests/\[request_id\]](/reference/rest/endpoints/delete_email-update-requests_requestid): Delete an email update request. +- [POST /verify-new-email](/reference/rest/endpoints/post_verify-new-email): Update a user's email by verifying their email update request code. + +#### Two-factor authentication + +- [POST /users/\[user_id\/register-totp](/reference/rest/endpoints/post_users_userid_register-totp): Register a TOTP credential. +- [GET /users/\[user_id\]/totp-credential](/reference/rest/endpoints/get_users_userid_totp-credential): Get a user's TOTP credential. +- [DELETE /users/\[user_id\]/totp-credential](/reference/rest/endpoints/delete_users_userid_totp-credential): Delete a user's TOTP credential. +- [POST /users/\[user_id\]/verify-2fa/totp](/reference/rest/endpoints/post_users_userid_verify-2fa_totp): Verify a user's TOTP code. +- [POST /users/\[user_id\]/regenerate-recovery-code](/reference/rest/endpoints/post_users_userid_regenerate-recovery-code): Generate a new user recovery code. +- [POST /users/\[user_id\]/reset-2fa](/reference/rest/endpoints/post_users_userid_reset-2fa): Reset a user's second factors with a recovery code. + +### Password reset + +- [POST /users/\[user_id\]/password-reset-requests](/reference/rest/endpoints/post_users_userid_password-reset-requests): Create a new password reset request for a user. +- [GET /password-reset-requests/\[request_id\]](/reference/rest/endpoints/get_password-reset-requests_requestid): Get a password reset request. +- [DELETE /password-reset-requests/\[request_id\]](/reference/rest/endpoints/delete_password-reset-requests_requestid): Delete a password reset request. +- [POST /password-reset-requests/\[request_id\]/verify-email](/reference/rest/endpoints/post_password-reset-requests_requestid_verify-email): Verify a reset request's email. +- [POST /reset-password](/reference/rest/endpoints/post_reset-password): Reset the user's password with a verified reset request. diff --git a/docs/pages/api-reference/rest/models/email-update-request.md b/docs/pages/reference/rest/models/email-update-request.md similarity index 100% rename from docs/pages/api-reference/rest/models/email-update-request.md rename to docs/pages/reference/rest/models/email-update-request.md diff --git a/docs/pages/api-reference/rest/models/password-reset-request.md b/docs/pages/reference/rest/models/password-reset-request.md similarity index 100% rename from docs/pages/api-reference/rest/models/password-reset-request.md rename to docs/pages/reference/rest/models/password-reset-request.md diff --git a/docs/pages/api-reference/rest/models/user-email-verification-request.md b/docs/pages/reference/rest/models/user-email-verification-request.md similarity index 100% rename from docs/pages/api-reference/rest/models/user-email-verification-request.md rename to docs/pages/reference/rest/models/user-email-verification-request.md diff --git a/docs/pages/api-reference/rest/models/user-totp-credential.md b/docs/pages/reference/rest/models/user-totp-credential.md similarity index 100% rename from docs/pages/api-reference/rest/models/user-totp-credential.md rename to docs/pages/reference/rest/models/user-totp-credential.md diff --git a/docs/pages/api-reference/rest/models/user.md b/docs/pages/reference/rest/models/user.md similarity index 100% rename from docs/pages/api-reference/rest/models/user.md rename to docs/pages/reference/rest/models/user.md diff --git a/docs/pages/api-reference/sdk-js/index.md b/docs/pages/reference/sdk-js/index.md similarity index 90% rename from docs/pages/api-reference/sdk-js/index.md rename to docs/pages/reference/sdk-js/index.md index c7a2f34..5d2a815 100644 --- a/docs/pages/api-reference/sdk-js/index.md +++ b/docs/pages/reference/sdk-js/index.md @@ -14,4 +14,4 @@ npm install @faroe/sdk ## Modules -- [`@faroe/sdk`](/api-reference/sdk-js/main) +- [`@faroe/sdk`](/reference/sdk-js/main) diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/createUser.md b/docs/pages/reference/sdk-js/main/Faroe/createUser.md similarity index 85% rename from docs/pages/api-reference/sdk-js/main/Faroe/createUser.md rename to docs/pages/reference/sdk-js/main/Faroe/createUser.md index 0490d24..0ddf2db 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/createUser.md +++ b/docs/pages/reference/sdk-js/main/Faroe/createUser.md @@ -4,7 +4,7 @@ title: "Faroe.createUser()" # Faroe.createUser() -Mapped to [POST /users](/api-reference/rest/endpoints/post_users). +Mapped to [POST /users](/reference/rest/endpoints/post_users). Creates a new user. @@ -13,7 +13,7 @@ We highly recommend putting a Captcha or equivalent in front for spam and bot de ## Definition ```ts -//$ FaroeUser=/api-reference/sdk-js/main/FaroeUser +//$ FaroeUser=/reference/sdk-js/main/FaroeUser async function createUser( password: string, clientIP: string | null diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/createUserEmailUpdateRequest.md b/docs/pages/reference/sdk-js/main/Faroe/createUserEmailUpdateRequest.md similarity index 73% rename from docs/pages/api-reference/sdk-js/main/Faroe/createUserEmailUpdateRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/createUserEmailUpdateRequest.md index 3850db4..6548341 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/createUserEmailUpdateRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/createUserEmailUpdateRequest.md @@ -4,14 +4,14 @@ title: "Faroe.createUserEmailUpdateRequest()" # Faroe.createUserEmailUpdateRequest() -Mapped to [POST /users/\[user_id\]/email-update-requests](/api-reference/rest/endpoints/post_users_userid_email-update-requests). +Mapped to [POST /users/\[user_id\]/email-update-requests](/reference/rest/endpoints/post_users_userid_email-update-requests). Creates a new email verification request for a user. This can only be called 3 times in a 15 minute window per user. ## Definition ```ts -//$ $$FaroeEmailUpdateRequest=/api-reference/sdk-js/main/$$FaroeEmailUpdateRequest +//$ $$FaroeEmailUpdateRequest=/reference/sdk-js/main/$$FaroeEmailUpdateRequest async function createUserEmailUpdateRequest( userId: string, email: string diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/createUserEmailVerificationRequest.md b/docs/pages/reference/sdk-js/main/Faroe/createUserEmailVerificationRequest.md similarity index 78% rename from docs/pages/api-reference/sdk-js/main/Faroe/createUserEmailVerificationRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/createUserEmailVerificationRequest.md index db32aee..09ce571 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/createUserEmailVerificationRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/createUserEmailVerificationRequest.md @@ -4,14 +4,14 @@ title: "Faroe.createUserEmailVerificationRequest()" # Faroe.createUserEmailVerificationRequest() -Mapped to [POST /users/\[user_id\]/email-verification-request](/api-reference/rest/endpoints/post_users_userid_email-verification-request). +Mapped to [POST /users/\[user_id\]/email-verification-request](/reference/rest/endpoints/post_users_userid_email-verification-request). Creates a new email verification request for a user. This can only be called 3 times in a 15 minute window per user. ## Definition ```ts -//$ FaroeUserEmailVerificationRequest=/api-reference/sdk-js/main/FaroeUserEmailVerificationRequest +//$ FaroeUserEmailVerificationRequest=/reference/sdk-js/main/FaroeUserEmailVerificationRequest async function createUserEmailVerificationRequest( userId: string ): Promise<$$FaroeUserEmailVerificationRequest> diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/createUserPasswordResetRequest.md b/docs/pages/reference/sdk-js/main/Faroe/createUserPasswordResetRequest.md similarity index 78% rename from docs/pages/api-reference/sdk-js/main/Faroe/createUserPasswordResetRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/createUserPasswordResetRequest.md index 2792841..bb34c6d 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/createUserPasswordResetRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/createUserPasswordResetRequest.md @@ -4,7 +4,7 @@ title: "Faroe.createPasswordResetRequest()" # Faroe.createPasswordResetRequest() -Mapped to [POST /password-reset-requests](/api-reference/rest/endpoints/post_password-reset-requests). +Mapped to [POST /password-reset-requests](/reference/rest/endpoints/post_password-reset-requests). Creates a new password reset request for a user. This can only be called 3 times in a 15 minute window per user. @@ -13,7 +13,7 @@ Send the created reset request's code to the email address. ## Definition ```ts -//$ FaroePasswordResetRequest=/api-reference/sdk-js/main/$$FaroePasswordResetRequest +//$ FaroePasswordResetRequest=/reference/sdk-js/main/$$FaroePasswordResetRequest async function createPasswordResetRequest( email: string, clientIP: string | null diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deleteEmailUpdateRequest.md b/docs/pages/reference/sdk-js/main/Faroe/deleteEmailUpdateRequest.md similarity index 73% rename from docs/pages/api-reference/sdk-js/main/Faroe/deleteEmailUpdateRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/deleteEmailUpdateRequest.md index 175bc19..225f0aa 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deleteEmailUpdateRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deleteEmailUpdateRequest.md @@ -4,7 +4,7 @@ title: "Faroe.deleteEmailUpdateRequest()" # Faroe.deleteEmailUpdateRequest() -Mapped to [DELETE /email-update-requests/\[request_id\]](/api-reference/rest/endpoints/delete_email-update-requests_requestid). +Mapped to [DELETE /email-update-requests/\[request_id\]](/reference/rest/endpoints/delete_email-update-requests_requestid). Deletes an email update request. Deleting a non-existent request will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deletePasswordResetRequest.md b/docs/pages/reference/sdk-js/main/Faroe/deletePasswordResetRequest.md similarity index 72% rename from docs/pages/api-reference/sdk-js/main/Faroe/deletePasswordResetRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/deletePasswordResetRequest.md index e4bf17a..a687162 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deletePasswordResetRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deletePasswordResetRequest.md @@ -4,7 +4,7 @@ title: "Faroe.deletePasswordResetRequest()" # Faroe.deletePasswordResetRequest() -Mapped to [DELETE /password-reset-requests/\[request_id\]](/api-reference/rest/endpoints/delete_password-reset-requests_requestid). +Mapped to [DELETE /password-reset-requests/\[request_id\]](/reference/rest/endpoints/delete_password-reset-requests_requestid). Deletes a passwod reset request. Deleting a non-existent request will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUser.md b/docs/pages/reference/sdk-js/main/Faroe/deleteUser.md similarity index 75% rename from docs/pages/api-reference/sdk-js/main/Faroe/deleteUser.md rename to docs/pages/reference/sdk-js/main/Faroe/deleteUser.md index ff68a2e..66510ac 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUser.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deleteUser.md @@ -4,7 +4,7 @@ title: "Faroe.deleteUser()" # Faroe.deleteUser() -Mapped to [DELETE /users/\[user_id\]](/api-reference/rest/endpoints/delete_users_userid). +Mapped to [DELETE /users/\[user_id\]](/reference/rest/endpoints/delete_users_userid). Deletes a user. Deleting a non-existent user will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests.md b/docs/pages/reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests.md similarity index 73% rename from docs/pages/api-reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests.md rename to docs/pages/reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests.md index 8571a72..aa7e08e 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests.md @@ -4,7 +4,7 @@ title: "Faroe.deleteUserEmailUpdateRequests()" # Faroe.deleteUserEmailUpdateRequests() -Mapped to [DELETE /users/\[user_id\]/email-update-requests](/api-reference/rest/endpoints/delete_users_userid_email-update-requests). +Mapped to [DELETE /users/\[user_id\]/email-update-requests](/reference/rest/endpoints/delete_users_userid_email-update-requests). Deletes a user's email update requests. Attempting to delete email update requests of a non-existent user will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest.md b/docs/pages/reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest.md similarity index 84% rename from docs/pages/api-reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest.md index 125279b..e9cac79 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest.md @@ -4,7 +4,7 @@ title: "Faroe.deleteUserEmailVerificationRequest()" # Faroe.deleteUserEmailVerificationRequest() -Mapped to [DELETE /users/\[user_id\]/email-verification-request](/api-reference/rest/endpoints/delete_users_userid_email-verification-request). +Mapped to [DELETE /users/\[user_id\]/email-verification-request](/reference/rest/endpoints/delete_users_userid_email-verification-request). Deletes a user's email verification request. Deleting a non-existent request will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests.md b/docs/pages/reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests.md similarity index 74% rename from docs/pages/api-reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests.md rename to docs/pages/reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests.md index 9d41376..70fddd1 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests.md @@ -4,7 +4,7 @@ title: "Faroe.deleteUserPasswordResetRequests()" # Faroe.deleteUserPasswordResetRequests() -Mapped to [DELETE /users/\[user_id\]/password-reset-requests](/api-reference/rest/endpoints/delete_users_userid_email-reset-requests). +Mapped to [DELETE /users/\[user_id\]/password-reset-requests](/reference/rest/endpoints/delete_users_userid_email-reset-requests). Deletes a user's password reset requests. Attempting to delete password reset requests of a non-existent user will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserTOTPCredential.md b/docs/pages/reference/sdk-js/main/Faroe/deleteUserTOTPCredential.md similarity index 74% rename from docs/pages/api-reference/sdk-js/main/Faroe/deleteUserTOTPCredential.md rename to docs/pages/reference/sdk-js/main/Faroe/deleteUserTOTPCredential.md index 5629c76..60948fe 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/deleteUserTOTPCredential.md +++ b/docs/pages/reference/sdk-js/main/Faroe/deleteUserTOTPCredential.md @@ -4,7 +4,7 @@ title: "Faroe.deleteUserTOTPCredential()" # Faroe.deleteUserTOTPCredential() -Mapped to [DELETE /users/\[user_id\]/totp-credential](/api-reference/rest/endpoints/delete_users_userid_totp-credential). +Mapped to [DELETE /users/\[user_id\]/totp-credential](/reference/rest/endpoints/delete_users_userid_totp-credential). Deletes a user's TOTP credential. Deleting a non-existent credential will not result in an error. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getEmailUpdateRequest.md b/docs/pages/reference/sdk-js/main/Faroe/getEmailUpdateRequest.md similarity index 64% rename from docs/pages/api-reference/sdk-js/main/Faroe/getEmailUpdateRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/getEmailUpdateRequest.md index 8972470..afe0bbf 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getEmailUpdateRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getEmailUpdateRequest.md @@ -4,14 +4,14 @@ title: "Faroe.getEmailUpdateRequest()" # Faroe.getEmailUpdateRequest() -Mapped to [GET /email-update-requests/\[request_id\]](/api-reference/rest/endpoints/get_email-update-requests_requestid). +Mapped to [GET /email-update-requests/\[request_id\]](/reference/rest/endpoints/get_email-update-requests_requestid). Gets a email update request. Returns `null` if the request doesn't exist or has expired. ## Definition ```ts -//$ FaroeEmailUpdateRequest=/api-reference/sdk-js/main/FaroeEmailUpdateRequest +//$ FaroeEmailUpdateRequest=/reference/sdk-js/main/FaroeEmailUpdateRequest async function getEmailUpdateRequest( requestId: string ): Promise<$$FaroeEmailUpdateRequest | null> diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getPasswordResetRequest.md b/docs/pages/reference/sdk-js/main/Faroe/getPasswordResetRequest.md similarity index 63% rename from docs/pages/api-reference/sdk-js/main/Faroe/getPasswordResetRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/getPasswordResetRequest.md index 7b0d173..246d399 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getPasswordResetRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getPasswordResetRequest.md @@ -4,14 +4,14 @@ title: "Faroe.getPasswordResetRequest()" # Faroe.getPasswordResetRequest() -Mapped to [GET /password-reset-requests/\[request_id\]](/api-reference/rest/endpoints/get_password-reset-requests_requestid). +Mapped to [GET /password-reset-requests/\[request_id\]](/reference/rest/endpoints/get_password-reset-requests_requestid). Gets a password reset request. Returns `null` if the request doesn't exist. ## Definition ```ts -//$ FaroePasswordResetRequest=/api-reference/sdk-js/main/FaroePasswordResetRequest +//$ FaroePasswordResetRequest=/reference/sdk-js/main/FaroePasswordResetRequest async function getPasswordResetRequest( requestId: string ): Promise<$$FaroePasswordResetRequest | null> diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getUser.md b/docs/pages/reference/sdk-js/main/Faroe/getUser.md similarity index 70% rename from docs/pages/api-reference/sdk-js/main/Faroe/getUser.md rename to docs/pages/reference/sdk-js/main/Faroe/getUser.md index 0215f36..155723b 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getUser.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getUser.md @@ -4,14 +4,14 @@ title: "Faroe.getUser()" # Faroe.getPasswordResetRequest() -Mapped to [GET /users](/api-reference/rest/endpoints/get_users). +Mapped to [GET /users](/reference/rest/endpoints/get_users). Gets a user. Returns `null` if the user doesn't exist. ## Definition ```ts -//$ FaroeUser=/api-reference/sdk-js/main/FaroeUser +//$ FaroeUser=/reference/sdk-js/main/FaroeUser async function getUser(userId: string): Promise<$$FaroeUser | null> ``` diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getUserEmailUpdateRequests.md b/docs/pages/reference/sdk-js/main/Faroe/getUserEmailUpdateRequests.md similarity index 69% rename from docs/pages/api-reference/sdk-js/main/Faroe/getUserEmailUpdateRequests.md rename to docs/pages/reference/sdk-js/main/Faroe/getUserEmailUpdateRequests.md index 781be72..61d9978 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getUserEmailUpdateRequests.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getUserEmailUpdateRequests.md @@ -4,14 +4,14 @@ title: "Faroe.getUserEmailUpdateRequests()" # Faroe.getUserEmailUpdateRequests() -Mapped to [GET /users/\[user_id\]/email-update-requests](/api-reference/rest/endpoints/get_users_userid_email-update-requests). +Mapped to [GET /users/\[user_id\]/email-update-requests](/reference/rest/endpoints/get_users_userid_email-update-requests). Gets an array of a user's valid email update requests. Returns an empty array if the user doesn't have any valid update requests or null if the user doesn't exist. ## Definition ```ts -//$ FaroeEmailUpdateRequest=/api-reference/sdk-js/main/FaroeEmailUpdateRequest +//$ FaroeEmailUpdateRequest=/reference/sdk-js/main/FaroeEmailUpdateRequest async function getUserEmailUpdateRequests( userId: string ): Promise<$$FaroeEmailUpdateRequest[] | null> diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getUserEmailVerificationRequest.md b/docs/pages/reference/sdk-js/main/Faroe/getUserEmailVerificationRequest.md similarity index 63% rename from docs/pages/api-reference/sdk-js/main/Faroe/getUserEmailVerificationRequest.md rename to docs/pages/reference/sdk-js/main/Faroe/getUserEmailVerificationRequest.md index ef02364..9f992bc 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getUserEmailVerificationRequest.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getUserEmailVerificationRequest.md @@ -4,14 +4,14 @@ title: "Faroe.getUserEmailVerificationRequest()" # Faroe.getUserEmailVerificationRequest() -Mapped to [GET /users/\[user_id\]/email-verification-request](/api-reference/rest/endpoints/get_users_userid_email-verification-request). +Mapped to [GET /users/\[user_id\]/email-verification-request](/reference/rest/endpoints/get_users_userid_email-verification-request). Gets a user's email verification request. Returns `null` if the request doesn't exist or has expired. ## Definition ```ts -//$ FaroeUserEmailVerificationRequest=/api-reference/sdk-js/main/FaroeUserEmailVerificationRequest +//$ FaroeUserEmailVerificationRequest=/reference/sdk-js/main/FaroeUserEmailVerificationRequest async function getUserEmailVerificationRequest( userId: string ): Promise<$$FaroeUserEmailVerificationRequest | null> diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getUserPasswordResetRequests.md b/docs/pages/reference/sdk-js/main/Faroe/getUserPasswordResetRequests.md similarity index 66% rename from docs/pages/api-reference/sdk-js/main/Faroe/getUserPasswordResetRequests.md rename to docs/pages/reference/sdk-js/main/Faroe/getUserPasswordResetRequests.md index 2982234..fe90cd8 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getUserPasswordResetRequests.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getUserPasswordResetRequests.md @@ -4,14 +4,14 @@ title: "Faroe.getUserPasswordResetRequests()" # Faroe.getUserPasswordResetRequests() -Mapped to [GET /users/\[user_id\]/password-reset-requests](/api-reference/rest/endpoints/get_users_userid_password-reset-requests). +Mapped to [GET /users/\[user_id\]/password-reset-requests](/reference/rest/endpoints/get_users_userid_password-reset-requests). Gets an array of a user's valid password reset requests. Returns an empty array if the user doesn't have any valid reset requests or null if the user doesn't exist. ## Definition ```ts -//$ FaroePasswordResetRequest=/api-reference/sdk-js/main/FaroePasswordResetRequest +//$ FaroePasswordResetRequest=/reference/sdk-js/main/FaroePasswordResetRequest async function getUserPasswordResetRequests( userId: string ): Promise<$$FaroePasswordResetRequest[] | null> diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getUserTOTPCredential.md b/docs/pages/reference/sdk-js/main/Faroe/getUserTOTPCredential.md similarity index 66% rename from docs/pages/api-reference/sdk-js/main/Faroe/getUserTOTPCredential.md rename to docs/pages/reference/sdk-js/main/Faroe/getUserTOTPCredential.md index 16271fa..41a4aff 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getUserTOTPCredential.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getUserTOTPCredential.md @@ -4,14 +4,14 @@ title: "Faroe.getUserTOTPCredential()" # Faroe.getUserTOTPCredential() -Mapped to [GET /users/\[user_id\]/totp-credential](/api-reference/rest/endpoints/get_users_userid_totp-credential). +Mapped to [GET /users/\[user_id\]/totp-credential](/reference/rest/endpoints/get_users_userid_totp-credential). Gets a user's TOTP credential. Returns `null` if the user doesn't exist or if the user doesn't have a TOTP credential. ## Definition ```ts -//$ FaroeUserTOTPCredential=/api-reference/sdk-js/main/FaroeUserTOTPCredential +//$ FaroeUserTOTPCredential=/reference/sdk-js/main/FaroeUserTOTPCredential async function getUserTOTPCredential(userId: string): Promise<$$FaroeUserTOTPCredential | null> ``` diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/getUsers.md b/docs/pages/reference/sdk-js/main/Faroe/getUsers.md similarity index 80% rename from docs/pages/api-reference/sdk-js/main/Faroe/getUsers.md rename to docs/pages/reference/sdk-js/main/Faroe/getUsers.md index 66c068d..b19329b 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/getUsers.md +++ b/docs/pages/reference/sdk-js/main/Faroe/getUsers.md @@ -4,15 +4,15 @@ title: "Faroe.getUsers()" # Faroe.getUsers() -Mapped to [GET /users](/api-reference/rest/endpoints/get_users). +Mapped to [GET /users](/reference/rest/endpoints/get_users). Gets an array of users. Returns an empty array if there are no users. ## Definition ```ts -//$ PaginationResult=/api-reference/sdk-js/main/PaginationResult -//$ FaroeUser=/api-reference/sdk-js/main/FaroeUser +//$ PaginationResult=/reference/sdk-js/main/PaginationResult +//$ FaroeUser=/reference/sdk-js/main/FaroeUser async function getUsers(options?: { sortBy: UserSortBy = UserSortBy.CreatedAt, sortOrder: SortOrder = SortOrder.Ascending, diff --git a/docs/pages/reference/sdk-js/main/Faroe/index.md b/docs/pages/reference/sdk-js/main/Faroe/index.md new file mode 100644 index 0000000..5cb4ca5 --- /dev/null +++ b/docs/pages/reference/sdk-js/main/Faroe/index.md @@ -0,0 +1,76 @@ +--- +title: "Faroe" +--- + +# Faroe + +Represents a Faroe server client. + +Server errors are thrown as [`FaroeError`](/reference/sdk-js/main/FaroeError). The error code is available from `FaroeError.code`. See each method for a list of possible error codes. + +```ts +import { Faroe, FaroeError } from "@faroe/sdk" + +const faroe = new Faroe(url, secret); + +try { + await faroe.createUser(password, clientIP); +} catch (e) { + if (e instanceof FaroeError) { + const errorCode = e.code; + } +} +``` + +Errors caused by `fetch()` are wrapped as [`FaroeFetchError`](/reference/sdk-js/main/FaroeFetchError). + +## Constructor + +```ts +function constructor(url: string, credential: string | null): this +``` + +### Parameters + +- `url`: The base URL of the Faroe server (e.g. `https://your-domain.com`). +- `credential`: The server credential. + +## Methods + +- [`createUser()`](/reference/sdk-js/main/Faroe/createUser) +- [`createUserEmailUpdateRequest()`](/reference/sdk-js/main/Faroe/createUserEmailUpdateRequest) +- [`createUserEmailVerificationRequest()`](/reference/sdk-js/main/Faroe/createUserEmailVerificationRequest) +- [`createUserPasswordResetRequest()`](/reference/sdk-js/main/Faroe/createUserPasswordResetRequest) +- [`deleteEmailUpdateRequest()`](/reference/sdk-js/main/Faroe/deleteEmailUpdateRequest) +- [`deletePasswordResetRequest()`](/reference/sdk-js/main/Faroe/deletePasswordResetRequest) +- [`deleteUser()`](/reference/sdk-js/main/Faroe/deleteUser) +- [`deleteUserEmailUpdateRequests()`](/reference/sdk-js/main/Faroe/deleteUserEmailUpdateRequests) +- [`deleteUserEmailVerificationRequest()`](/reference/sdk-js/main/Faroe/deleteUserEmailVerificationRequest) +- [`deleteUserPasswordResetRequests()`](/reference/sdk-js/main/Faroe/deleteUserPasswordResetRequests) +- [`deleteUserTOTPCredential()`](/reference/sdk-js/main/Faroe/deleteUserTOTPCredential) +- [`getEmailUpdateRequest()`](/reference/sdk-js/main/Faroe/getEmailUpdateRequest) +- [`getPasswordResetRequest()`](/reference/sdk-js/main/Faroe/getPasswordResetRequest) +- [`getUser()`](/reference/sdk-js/main/Faroe/getUser) +- [`getUserEmailUpdateRequests()`](/reference/sdk-js/main/Faroe/getUserEmailUpdateRequests) +- [`getUserEmailVerificationRequest()`](/reference/sdk-js/main/Faroe/getUserEmailVerificationRequest) +- [`getUserPasswordResetRequests()`](/reference/sdk-js/main/Faroe/getUserPasswordResetRequests) +- [`getUsers()`](/reference/sdk-js/main/Faroe/getUsers) +- [`getUserTOTPCredential()`](/reference/sdk-js/main/Faroe/getUserTOTPCredential) +- [`regenerateUserRecoveryCode()`](/reference/sdk-js/main/Faroe/regenerateUserRecoveryCode) +- [`registerUserTOTPCredential()`](/reference/sdk-js/main/Faroe/registerUserTOTPCredential) +- [`resetUser2FA()`](/reference/sdk-js/main/Faroe/resetUser2FA) +- [`resetUserPassword()`](/reference/sdk-js/main/Faroe/resetUserPassword) +- [`updateUserPassword()`](/reference/sdk-js/main/Faroe/updateUserPassword) +- [`verifyNewUserEmail()`](/reference/sdk-js/main/Faroe/verifyNewUserEmail) +- [`verifyPasswordResetRequestEmail()`](/reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail) +- [`verifyUser2FAWithTOTP()`](/reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP) +- [`verifyUserEmail()`](/reference/sdk-js/main/Faroe/verifyUserEmail) +- [`verifyUserPassword()`](/reference/sdk-js/main/Faroe/verifyUserPassword) + +## Example + +```ts +import { Faroe } from "@faroe/sdk" + +const faroe = new Faroe("https://your-domain.com", process.env.FAROE_CREDENTIAL); +``` diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/regenerateUserRecoveryCode.md b/docs/pages/reference/sdk-js/main/Faroe/regenerateUserRecoveryCode.md similarity index 70% rename from docs/pages/api-reference/sdk-js/main/Faroe/regenerateUserRecoveryCode.md rename to docs/pages/reference/sdk-js/main/Faroe/regenerateUserRecoveryCode.md index ed434c5..457e57a 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/regenerateUserRecoveryCode.md +++ b/docs/pages/reference/sdk-js/main/Faroe/regenerateUserRecoveryCode.md @@ -4,7 +4,7 @@ title: "Faroe.regenerateUserRecoveryCode()" # Faroe.regenerateUserRecoveryCode() -Mapped to [POST /users/\[user_id\]/regenerate-recovery-code](/api-reference/rest/endpoints/post_users_userid_regenerate-recovery-code). +Mapped to [POST /users/\[user_id\]/regenerate-recovery-code](/reference/rest/endpoints/post_users_userid_regenerate-recovery-code). Regenerates a user's recovery code and returns the new recovery code. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/registerUserTOTPCredential.md b/docs/pages/reference/sdk-js/main/Faroe/registerUserTOTPCredential.md similarity index 82% rename from docs/pages/api-reference/sdk-js/main/Faroe/registerUserTOTPCredential.md rename to docs/pages/reference/sdk-js/main/Faroe/registerUserTOTPCredential.md index 221faee..4411444 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/registerUserTOTPCredential.md +++ b/docs/pages/reference/sdk-js/main/Faroe/registerUserTOTPCredential.md @@ -4,14 +4,14 @@ title: "Faroe.registerUserTOTPCredential()" # Faroe.registerUserTOTPCredential() -Mapped to [POST /users/\[user_id\/register-totp](/api-reference/rest/endpoints/post_users_userid_register-totp). +Mapped to [POST /users/\[user_id\/register-totp](/reference/rest/endpoints/post_users_userid_register-totp). Registers a TOTP (SHA-1, 6 digits, 30 seconds interval) credential to a user. ## Definition ```ts -//$ FaroeUserTOTPCredential=/api-reference/sdk-js/main/FaroeUserTOTPCredential +//$ FaroeUserTOTPCredential=/reference/sdk-js/main/FaroeUserTOTPCredential async function registerUserTOTPCredential( userId: string, totpKey: Uint8Array, diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/resetUser2FA.md b/docs/pages/reference/sdk-js/main/Faroe/resetUser2FA.md similarity index 84% rename from docs/pages/api-reference/sdk-js/main/Faroe/resetUser2FA.md rename to docs/pages/reference/sdk-js/main/Faroe/resetUser2FA.md index 0cbcc34..134b3df 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/resetUser2FA.md +++ b/docs/pages/reference/sdk-js/main/Faroe/resetUser2FA.md @@ -4,7 +4,7 @@ title: "Faroe.resetUser2FA()" # Faroe.resetUser2FA() -Mapped to [POST /users/\[user_id\]/reset-2fa](/api-reference/rest/endpoints/post_users_userid_reset-2fa). +Mapped to [POST /users/\[user_id\]/reset-2fa](/reference/rest/endpoints/post_users_userid_reset-2fa). Resets a user's second factors using a recovery code and returns a new recovery code. The user will be locked out from using their recovery code for 15 minutes after their 5th consecutive failed attempts. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/resetUserPassword.md b/docs/pages/reference/sdk-js/main/Faroe/resetUserPassword.md similarity index 91% rename from docs/pages/api-reference/sdk-js/main/Faroe/resetUserPassword.md rename to docs/pages/reference/sdk-js/main/Faroe/resetUserPassword.md index a6949a0..c5eec81 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/resetUserPassword.md +++ b/docs/pages/reference/sdk-js/main/Faroe/resetUserPassword.md @@ -4,7 +4,7 @@ title: "Faroe.resetUserPassword()" # Faroe.resetUserPassword() -Mapped to [POST /reset-password](/api-reference/rest/endpoints/post_reset-password). +Mapped to [POST /reset-password](/reference/rest/endpoints/post_reset-password). Resets a user's password with a password reset request.On validation, it will mark the user's email as verified and invalidate all password reset requests linked to the user. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/updateUserPassword.md b/docs/pages/reference/sdk-js/main/Faroe/updateUserPassword.md similarity index 87% rename from docs/pages/api-reference/sdk-js/main/Faroe/updateUserPassword.md rename to docs/pages/reference/sdk-js/main/Faroe/updateUserPassword.md index 88d98ee..68d33ce 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/updateUserPassword.md +++ b/docs/pages/reference/sdk-js/main/Faroe/updateUserPassword.md @@ -4,7 +4,7 @@ title: "Faroe.updateUserPassword()" # Faroe.updateUserPassword() -Mapped to [POST /users/\[user_id\]/password](/api-reference/rest/endpoints/post_users_userid_password). +Mapped to [POST /users/\[user_id\]/password](/reference/rest/endpoints/post_users_userid_password). Updates a user's password. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/verifyNewUserEmail.md b/docs/pages/reference/sdk-js/main/Faroe/verifyNewUserEmail.md similarity index 89% rename from docs/pages/api-reference/sdk-js/main/Faroe/verifyNewUserEmail.md rename to docs/pages/reference/sdk-js/main/Faroe/verifyNewUserEmail.md index b87677c..bf99d09 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/verifyNewUserEmail.md +++ b/docs/pages/reference/sdk-js/main/Faroe/verifyNewUserEmail.md @@ -4,7 +4,7 @@ title: "Faroe.verifyNewUserEmail()" # Faroe.verifyNewUserEmail() -Mapped to [POST /verify-new-email](/api-reference/rest/endpoints/post_verify-new-email). +Mapped to [POST /verify-new-email](/reference/rest/endpoints/post_verify-new-email). Verifies an email update request's verification code. Upon a successful verification, all email update requests linked to the email address and password reset requests to the user are invalidated. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail.md b/docs/pages/reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail.md similarity index 89% rename from docs/pages/api-reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail.md rename to docs/pages/reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail.md index 8433737..ba2d6f9 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail.md +++ b/docs/pages/reference/sdk-js/main/Faroe/verifyPasswordResetRequestEmail.md @@ -4,7 +4,7 @@ title: "Faroe.verifyPasswordResetRequestEmail()" # Faroe.verifyPasswordResetRequestEmail() -Mapped to [POST /password-reset-requests/\[request_id\]/verify-email](/api-reference/rest/endpoints/post_password-reset-requests_requestid_verify-email). +Mapped to [POST /password-reset-requests/\[request_id\]/verify-email](/reference/rest/endpoints/post_password-reset-requests_requestid_verify-email). Verifies the email linked to a password reset request with a verification code. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP.md b/docs/pages/reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP.md similarity index 84% rename from docs/pages/api-reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP.md rename to docs/pages/reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP.md index 328ca61..7d5f702 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP.md +++ b/docs/pages/reference/sdk-js/main/Faroe/verifyUser2FAWithTOTP.md @@ -4,7 +4,7 @@ title: "Faroe.verifyUser2FAWithTOTP()" # Faroe.verifyUser2FAWithTOTP() -Mapped to [POST /users/\[user_id\]/verify-2fa/totp](/api-reference/rest/endpoints/post_users_userid_verify-2fa_totp). +Mapped to [POST /users/\[user_id\]/verify-2fa/totp](/reference/rest/endpoints/post_users_userid_verify-2fa_totp). Verifies a user's TOTP code. The user will be locked out from using TOTP as their second factor for 15 minutes after their 5th consecutive failed attempts. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/verifyUserEmail.md b/docs/pages/reference/sdk-js/main/Faroe/verifyUserEmail.md similarity index 86% rename from docs/pages/api-reference/sdk-js/main/Faroe/verifyUserEmail.md rename to docs/pages/reference/sdk-js/main/Faroe/verifyUserEmail.md index 561c427..216c7c8 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/verifyUserEmail.md +++ b/docs/pages/reference/sdk-js/main/Faroe/verifyUserEmail.md @@ -4,7 +4,7 @@ title: "Faroe.verifyUserEmail()" # Faroe.verifyUserEmail() -Mapped to [POST /users/\[user_id\]/verify-email](/api-reference/rest/endpoints/post_users_userid_verify-email). +Mapped to [POST /users/\[user_id\]/verify-email](/reference/rest/endpoints/post_users_userid_verify-email). Verifies and updates a user's email with the user's email verification request code. The user will be locked out from verifying their email for 15 minutes after their 5th consecutive failed attempts. diff --git a/docs/pages/api-reference/sdk-js/main/Faroe/verifyUserPassword.md b/docs/pages/reference/sdk-js/main/Faroe/verifyUserPassword.md similarity index 82% rename from docs/pages/api-reference/sdk-js/main/Faroe/verifyUserPassword.md rename to docs/pages/reference/sdk-js/main/Faroe/verifyUserPassword.md index d2d09ef..5349fea 100644 --- a/docs/pages/api-reference/sdk-js/main/Faroe/verifyUserPassword.md +++ b/docs/pages/reference/sdk-js/main/Faroe/verifyUserPassword.md @@ -4,7 +4,7 @@ title: "Faroe.verifyUserPassword()" # Faroe.verifyUserPassword() -Mapped to [POST /users/\[user_id\]/verify-password](/api-reference/rest/endpoints/post_users_userid_verify-password). +Mapped to [POST /users/\[user_id\]/verify-password](/reference/rest/endpoints/post_users_userid_verify-password). Verifies a user's password. It will temporary block the IP address if the client sends an incorrect password 5 times in a 15 minute window. diff --git a/docs/pages/api-reference/sdk-js/main/FaroeEmailUpdateRequest.md b/docs/pages/reference/sdk-js/main/FaroeEmailUpdateRequest.md similarity index 87% rename from docs/pages/api-reference/sdk-js/main/FaroeEmailUpdateRequest.md rename to docs/pages/reference/sdk-js/main/FaroeEmailUpdateRequest.md index eada30b..2c7cf7d 100644 --- a/docs/pages/api-reference/sdk-js/main/FaroeEmailUpdateRequest.md +++ b/docs/pages/reference/sdk-js/main/FaroeEmailUpdateRequest.md @@ -4,7 +4,7 @@ title: "FaroeEmailUpdateRequest" # FaroeEmailUpdateRequest -Mapped to the [email update request model](/api-reference/rest/models/email-update-request). +Mapped to the [email update request model](/reference/rest/models/email-update-request). Represents an email update request. diff --git a/docs/pages/api-reference/sdk-js/main/FaroeError.md b/docs/pages/reference/sdk-js/main/FaroeError.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/FaroeError.md rename to docs/pages/reference/sdk-js/main/FaroeError.md diff --git a/docs/pages/api-reference/sdk-js/main/FaroeFetchError.md b/docs/pages/reference/sdk-js/main/FaroeFetchError.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/FaroeFetchError.md rename to docs/pages/reference/sdk-js/main/FaroeFetchError.md diff --git a/docs/pages/api-reference/sdk-js/main/FaroePasswordResetRequest.md b/docs/pages/reference/sdk-js/main/FaroePasswordResetRequest.md similarity index 83% rename from docs/pages/api-reference/sdk-js/main/FaroePasswordResetRequest.md rename to docs/pages/reference/sdk-js/main/FaroePasswordResetRequest.md index 13f90df..3d3d734 100644 --- a/docs/pages/api-reference/sdk-js/main/FaroePasswordResetRequest.md +++ b/docs/pages/reference/sdk-js/main/FaroePasswordResetRequest.md @@ -4,7 +4,7 @@ title: "FaroePasswordResetRequest" # FaroePasswordResetRequest -Mapped to the [password reset request model](/api-reference/rest/models/password-reset-request). +Mapped to the [password reset request model](/reference/rest/models/password-reset-request). Represents an user. diff --git a/docs/pages/api-reference/sdk-js/main/FaroeUser.md b/docs/pages/reference/sdk-js/main/FaroeUser.md similarity index 85% rename from docs/pages/api-reference/sdk-js/main/FaroeUser.md rename to docs/pages/reference/sdk-js/main/FaroeUser.md index 91a5530..cf5d024 100644 --- a/docs/pages/api-reference/sdk-js/main/FaroeUser.md +++ b/docs/pages/reference/sdk-js/main/FaroeUser.md @@ -4,7 +4,7 @@ title: "FaroeUser" # FaroeUser -Represents an user. Mapped to the [user model](/api-reference/rest/models/user). +Represents an user. Mapped to the [user model](/reference/rest/models/user). ## Definition diff --git a/docs/pages/api-reference/sdk-js/main/FaroeUserEmailVerificationRequest.md b/docs/pages/reference/sdk-js/main/FaroeUserEmailVerificationRequest.md similarity index 81% rename from docs/pages/api-reference/sdk-js/main/FaroeUserEmailVerificationRequest.md rename to docs/pages/reference/sdk-js/main/FaroeUserEmailVerificationRequest.md index 267c3b7..d07487d 100644 --- a/docs/pages/api-reference/sdk-js/main/FaroeUserEmailVerificationRequest.md +++ b/docs/pages/reference/sdk-js/main/FaroeUserEmailVerificationRequest.md @@ -4,7 +4,7 @@ title: "FaroeUserEmailVerificationRequest" # FaroeUserEmailVerificationRequest -Mapped to the [user email verification request model](/api-reference/rest/models/user-email-verification-request). +Mapped to the [user email verification request model](/reference/rest/models/user-email-verification-request). Represents an email verification request. diff --git a/docs/pages/api-reference/sdk-js/main/FaroeUserTOTPCredential.md b/docs/pages/reference/sdk-js/main/FaroeUserTOTPCredential.md similarity index 80% rename from docs/pages/api-reference/sdk-js/main/FaroeUserTOTPCredential.md rename to docs/pages/reference/sdk-js/main/FaroeUserTOTPCredential.md index f6d699b..2e5f759 100644 --- a/docs/pages/api-reference/sdk-js/main/FaroeUserTOTPCredential.md +++ b/docs/pages/reference/sdk-js/main/FaroeUserTOTPCredential.md @@ -4,7 +4,7 @@ title: "FaroeUserTOTPCredential" # FaroeUserTOTPCredential -Mapped to the [user totp credential model](/api-reference/rest/models/user-totp-credential). +Mapped to the [user totp credential model](/reference/rest/models/user-totp-credential). Represents a user's totp credential. diff --git a/docs/pages/api-reference/sdk-js/main/PaginationResult.md b/docs/pages/reference/sdk-js/main/PaginationResult.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/PaginationResult.md rename to docs/pages/reference/sdk-js/main/PaginationResult.md diff --git a/docs/pages/api-reference/sdk-js/main/SortOrder.md b/docs/pages/reference/sdk-js/main/SortOrder.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/SortOrder.md rename to docs/pages/reference/sdk-js/main/SortOrder.md diff --git a/docs/pages/api-reference/sdk-js/main/UserSortBy.md b/docs/pages/reference/sdk-js/main/UserSortBy.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/UserSortBy.md rename to docs/pages/reference/sdk-js/main/UserSortBy.md diff --git a/docs/pages/reference/sdk-js/main/index.md b/docs/pages/reference/sdk-js/main/index.md new file mode 100644 index 0000000..9931bbf --- /dev/null +++ b/docs/pages/reference/sdk-js/main/index.md @@ -0,0 +1,30 @@ +--- +title: "@faroe/sdk" +--- + +# @faroe/sdk + +## Functions + +- [`verifyEmailInput()`](/reference/sdk-js/main/verifyEmailInput) +- [`verifyPasswordInput()`](/reference/sdk-js/main/verifyPasswordInput) + +## Classes + +- [`Faroe`](/reference/sdk-js/main/Faroe) +- [`FaroeError`](/reference/sdk-js/main/FaroeError) +- [`FaroeFetchError`](/reference/sdk-js/main/FaroeFetchError) + +## Interfaces + +- [`FaroeEmailUpdateRequest`](/reference/sdk-js/main/FaroeEmailUpdateRequest) +- [`FaroePasswordResetRequest`](/reference/sdk-js/main/FaroePasswordResetRequest) +- [`FaroeUserEmailVerificationRequest`](/reference/sdk-js/main/FaroeUserEmailVerificationRequest) +- [`FaroeUserTOTPCredential`](/reference/sdk-js/main/FaroeUserTOTPCredential) +- [`FaroeUser`](/reference/sdk-js/main/FaroeUser) +- [`PaginationResult`](/reference/sdk-js/main/PaginationResult) + +## Enums + +- [`UserSortBy`](/reference/sdk-js/main/UserSortBy) +- [`SortOrder`](/reference/sdk-js/main/SortOrder) diff --git a/docs/pages/api-reference/sdk-js/main/verifyEmailInput.md b/docs/pages/reference/sdk-js/main/verifyEmailInput.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/verifyEmailInput.md rename to docs/pages/reference/sdk-js/main/verifyEmailInput.md diff --git a/docs/pages/api-reference/sdk-js/main/verifyPasswordInput.md b/docs/pages/reference/sdk-js/main/verifyPasswordInput.md similarity index 100% rename from docs/pages/api-reference/sdk-js/main/verifyPasswordInput.md rename to docs/pages/reference/sdk-js/main/verifyPasswordInput.md diff --git a/src/db.go b/src/db.go index 17bf6d6..1e0f5a7 100644 --- a/src/db.go +++ b/src/db.go @@ -2,41 +2,9 @@ package main import ( "database/sql" - "fmt" - "io" - "os" "time" ) -func backupDatabase(db *sql.DB) error { - _, err := db.Exec("BEGIN IMMEDIATE") - if err != nil { - return err - } - src, err := os.Open("faroe_data/sqlite.db") - if err != nil { - db.Exec("COMMIT") - return err - } - dst, err := os.Create(fmt.Sprintf("faroe_data/backups/%d.db", time.Now().Unix())) - if err != nil { - src.Close() - db.Exec("COMMIT") - return err - } - _, err = io.Copy(dst, src) - if err != nil { - src.Close() - dst.Close() - db.Exec("COMMIT") - return err - } - src.Close() - dst.Close() - _, err = db.Exec("COMMIT") - return err -} - func cleanUpDatabase(db *sql.DB) error { _, err := db.Exec("DELETE FROM user_email_verification_request WHERE expires_at <= ?", time.Now().Unix()) if err != nil { diff --git a/src/main.go b/src/main.go index dd72656..d842c72 100644 --- a/src/main.go +++ b/src/main.go @@ -11,6 +11,7 @@ import ( "log" "net/http" "os" + "path" "strings" "time" @@ -75,19 +76,21 @@ func serveCommand() { os.Args = os.Args[1:] var port int + var dataDir string var secretString string flag.IntVar(&port, "port", 4000, "Port number") + flag.StringVar(&dataDir, "dir", "faroe_data", "Data directory name") flag.StringVar(&secretString, "secret", "", "Server secret") flag.Parse() secret := []byte(secretString) - err := os.MkdirAll("faroe_data", os.ModePerm) + err := os.MkdirAll(dataDir, os.ModePerm) if err != nil { log.Fatal(err) } - db, err := sql.Open("sqlite", "./faroe_data/sqlite.db") + db, err := sql.Open("sqlite", path.Join(dataDir, "sqlite.db")) if err != nil { log.Fatal(err) }