diff --git a/.eslintrc.js b/.eslintrc.js
index eabf3f8e..f3673a63 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -13,9 +13,7 @@ module.exports = {
"node/no-unpublished-require": [
"error",
{
- allowModules: [
- "supertest",
- ],
+ allowModules: ["supertest"],
},
],
"no-process-exit": "off",
diff --git a/docs/reference/Source_Documentation.md b/docs/reference/Source_Documentation.md
index e1db3e3e..acc2a9ce 100644
--- a/docs/reference/Source_Documentation.md
+++ b/docs/reference/Source_Documentation.md
@@ -27,11 +27,6 @@ But this does provide an opportunity to allow multiple caching systems.
Provides an interface of a large collection of functions to interact
with and retrieve data from the cloud hosted database instance.
-debug_util
-A collection of simple functions to help devs debug the application during runtime,
-to better assist in tracking down bugs. Since many sets of data cannot be reliably output to the console
-this can help to view the transmutations of data as its handled.
-
dev_server
The Development initializer of main.js
as well as managing the startup of a locally created Docker SQL
Server. This uses pg-test to set up a database hosted on local Docker. Migrating all data as needed,
@@ -42,15 +37,6 @@ the backend API server as normal.
Allows easy logging of the server. Allowing it to become simple to add additional
logging methods if a log server is ever implemented.
-main
-The Main functionality for the entire server. Sets up the Express server, providing
-all endpoints it listens on. With those endpoints being further documented in api.md
.
-
-query
-Home to parsing all query parameters from the Request
object. Ensuring a valid response.
-While most values will just return their default there are some expecptions:
-engine(): Returns false if not defined, to allow a fast way to determine if results need to be pruned.
-
server
The initializer of main.js
starting up the Express Server, and setting the port
to listen on. As well as handling a graceful shutdown of the server.
@@ -72,37 +58,62 @@ function.
webhook
Handles sending out webhooks based on function calls.
-common_handler
-Provides a simplistic way to refer to implement common endpoint returns.
-So these can be called as an async function without more complex functions, reducing
-verbosity, and duplication within the codebase.
-
-delete_package_handler
-Endpoint Handlers for every DELETE Request that relates to packages themselves
-
-get_package_handler
-Endpoint Handlers for every GET Request that relates to packages themselves
-
-oauth_handler
-Endpoint Handlers for Authentication URLs
-
-package_handler
-Exports individual files handling endpoints relating to Packages
-
-post_package_handler
-Endpoint Handlers for every POST Request that relates to packages themselves
-
-star_handler
-Handler for any endpoints whose slug after /api/
is star
.
-
-theme_handler
-Endpoint Handlers relating to themes only.
-
-update_handler
-Endpoint Handlers relating to updating the editor.
-
-user_handler
-Handler for endpoints whose slug after /api/
is user
.
+deletePackagesPackageName
+
+DeletePackagesPackageNameStar
+
+deletePackagesPackageNameVersionsVersionName
+
+getLogin
+
+getOauth
+
+getPackages
+
+getPackagesFeatured
+
+getPackagesPackageName
+
+getPackagesPackageNameStargazers
+
+getPackagesPackageNameVersionsVersionName
+
+getPackagesPackageNameVersionsVersionNameTarball
+
+getPackagesSearch
+
+getPat
+
+getRoot
+
+getStars
+
+getThemes
+
+getThemesFeatured
+
+getThemesSearch
+
+getUpdates
+
+getUsers
+
+getUsersLogin
+
+getUsersLoginStars
+
+postPackages
+
+postPackagesPackageNameStar
+
+postPackagesPackageNameVersions
+
+postPackagesPackageNameVersionsVersionNameEventsUninstall
+
+query
+Home to parsing all query parameters from the Request
object. Ensuring a valid response.
+While most values will just return their default there are some expecptions:
+engine(): Returns false if not defined, to allow a fast way to determine if results need to be pruned.
@@ -117,6 +128,67 @@ Once that is done, we can go ahead and search for said user within the database.
If the user exists, then we can confirm that they are both locally and globally
authenticated, and execute whatever action it is they wanted to.
+auth(req) ⇒ string
+Retrieves Authorization Headers from Request, and Checks for Undefined.
+
+direction(req) ⇒ string
+Parser for either 'direction' or 'order' query parameter, prioritizing
+'direction'.
+
+engine(semver) ⇒ string
| boolean
+Parses the 'engine' query parameter to ensure it's valid, otherwise returning false.
+
+fileExtension(req) ⇒ string
| boolean
+Returns the file extension being requested.
+
+login(req) ⇒ string
+Returns the User from the URL Path, otherwise ''
+
+user(req) ⇒ string
| boolean
+
+packageName(req) ⇒ string
+This function will convert a user provided package name into a safe format.
+It ensures the name is converted to lower case. As is the requirement of all package names.
+
+page(req) ⇒ number
+Parser of the Page query parameter. Defaulting to 1.
+
+query(req) ⇒ string
+Checks the 'q' query parameter, trunicating it at 50 characters, and checking simplisticly that
+it is not a malicious request. Returning "" if an unsafe or invalid query is passed.
+
+rename(req) ⇒ boolean
+Since this is intended to be returning a boolean value, returns false
+if invalid, otherwise returns true. Checking for mixed captilization.
+
+repo(req) ⇒ string
+Parses the 'repository' query parameter, returning it if valid, otherwise returning ''.
+
+service(req) ⇒ string
| boolean
+Returns the service being requested.
+
+serviceType(req) ⇒ string
| boolean
+Returns the service type being requested.
+
+serviceVersion(req) ⇒ string
| boolean
+Returns the version of whatever service is being requested.
+
+sort(req, [def]) ⇒ string
+Parser for the 'sort' query parameter. Defaulting usually to downloads.
+
+tag(req) ⇒ string
+Parses the 'tag' query parameter, returning it if valid, otherwise returning ''.
+
+stringValidation(value) ⇒ string
| boolean
+Provides a generic Query Utility that validates if a provided value
+is a string, as well as trimming it to the safe max length of query strings,
+while additionally passing it through the Path Traversal Detection function.
+
+pathTraversalAttempt(data) ⇒ boolean
+Completes some short checks to determine if the data contains a malicious
+path traversal attempt. Returning a boolean indicating if a path traversal attempt
+exists in the data.
+
## Typedefs
@@ -1034,26 +1106,6 @@ A custom timestamp can be passed as argument for testing purpose, otherwise the
| stateKey | string
| The key code string to delete. |
| timestamp | string
| A string in SQL timestamp format to check against the created timestamp of the given state key. If not provided, the current UNIX timestamp is used. |
-
-
-## debug\_util
-A collection of simple functions to help devs debug the application during runtime,
-to better assist in tracking down bugs. Since many sets of data cannot be reliably output to the console
-this can help to view the transmutations of data as its handled.
-
-
-
-### debug_util~roughSizeOfObject(obj) ⇒ integer
-Returns the rough size of the object in memory, in Bytes. Can be used
-to help determine how an object changes over time.
-
-**Kind**: inner method of [debug\_util
](#module_debug_util)
-**Returns**: integer
- Returns the integer value of the object in Bytes.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| obj | object
| The Object to inspect. |
-
## dev\_server
@@ -1062,17 +1114,6 @@ Server. This uses pg-test to set up a database hosted on local Docker. Migrating
to allow the real server feel, without having access or the risk of the production database. But otherwise runs
the backend API server as normal.
-
-* [dev_server](#module_dev_server)
- * [~dbSetup](#module_dev_server..dbSetup)
- * [~localExterminate(callee, serve, db)](#module_dev_server..localExterminate)
-
-
-
-### dev_server~dbSetup
-This is the recommended and only way to mock how Jest would use the module.
-
-**Kind**: inner constant of [dev\_server
](#module_dev_server)
### dev_server~localExterminate(callee, serve, db)
@@ -1178,260 +1219,6 @@ provided.
| --- | --- | --- |
| meta | string
| An object containing `req`, and `res` |
-
-
-## main
-The Main functionality for the entire server. Sets up the Express server, providing
-all endpoints it listens on. With those endpoints being further documented in `api.md`.
-
-
-
-## query
-Home to parsing all query parameters from the `Request` object. Ensuring a valid response.
-While most values will just return their default there are some expecptions:
-engine(): Returns false if not defined, to allow a fast way to determine if results need to be pruned.
-
-
-* [query](#module_query)
- * [~page(req)](#module_query..page) ⇒ number
- * [~sort(req, [def])](#module_query..sort) ⇒ string
- * [~dir(req)](#module_query..dir) ⇒ string
- * [~query(req)](#module_query..query) ⇒ string
- * [~engine(semver)](#module_query..engine) ⇒ string
\| boolean
- * [~auth(req)](#module_query..auth) ⇒ string
- * [~repo(req)](#module_query..repo) ⇒ string
- * [~tag(req)](#module_query..tag) ⇒ string
- * [~rename(req)](#module_query..rename) ⇒ boolean
- * [~packageName(req)](#module_query..packageName) ⇒ string
- * [~pathTraversalAttempt(data)](#module_query..pathTraversalAttempt) ⇒ boolean
- * [~login(req)](#module_query..login) ⇒ string
- * [~serviceType(req)](#module_query..serviceType) ⇒ string
\| boolean
- * [~serviceVersion(req)](#module_query..serviceVersion) ⇒ string
\| boolean
- * [~service(req)](#module_query..service) ⇒ string
\| boolean
- * [~fileExtension(req)](#module_query..fileExtension) ⇒ string
\| boolean
- * [~stringValidation(value)](#module_query..stringValidation) ⇒ string
\| boolean
-
-
-
-### query~page(req) ⇒ number
-Parser of the Page query parameter. Defaulting to 1.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: number
- Returns the valid page provided in the query parameter or 1, as the default.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~sort(req, [def]) ⇒ string
-Parser for the 'sort' query parameter. Defaulting usually to downloads.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- Either the user provided 'sort' query parameter, or the default specified.
-
-| Param | Type | Default | Description |
-| --- | --- | --- | --- |
-| req | object
| | The `Request` object inherited from the Express endpoint. |
-| [def] | string
| "\"downloads\""
| The default provided for sort. Allowing The search function to use "relevance" instead of the default "downloads". |
-
-
-
-### query~dir(req) ⇒ string
-Parser for either 'direction' or 'order' query parameter, prioritizing
-'direction'.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- The valid direction value from the 'direction' or 'order'
-query parameter.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~query(req) ⇒ string
-Checks the 'q' query parameter, trunicating it at 50 characters, and checking simplisticly that
-it is not a malicious request. Returning "" if an unsafe or invalid query is passed.
-
-**Kind**: inner method of [query
](#module_query)
-**Implements**: pathTraversalAttempt
-**Returns**: string
- A valid search string derived from 'q' query parameter. Or '' if invalid.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~engine(semver) ⇒ string
\| boolean
-Parses the 'engine' query parameter to ensure it's valid, otherwise returning false.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
\| boolean
- Returns the valid 'engine' specified, or if none, returns false.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| semver | string
| The engine string. |
-
-
-
-### query~auth(req) ⇒ string
-Retrieves Authorization Headers from Request, and Checks for Undefined.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- Returning a valid Authorization Token, or '' if invalid/not found.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| = The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~repo(req) ⇒ string
-Parses the 'repository' query parameter, returning it if valid, otherwise returning ''.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- Returning the valid 'repository' query parameter, or '' if invalid.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~tag(req) ⇒ string
-Parses the 'tag' query parameter, returning it if valid, otherwise returning ''.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- Returns a valid 'tag' query parameter. Or '' if invalid.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~rename(req) ⇒ boolean
-Since this is intended to be returning a boolean value, returns false
-if invalid, otherwise returns true. Checking for mixed captilization.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: boolean
- Returns false if invalid, or otherwise returns the boolean value of the string.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~packageName(req) ⇒ string
-This function will convert a user provided package name into a safe format.
-It ensures the name is converted to lower case. As is the requirement of all package names.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- Returns the package name in a safe format that can be worked with further.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` Object inherited from the Express endpoint. |
-
-
-
-### query~pathTraversalAttempt(data) ⇒ boolean
-Completes some short checks to determine if the data contains a malicious
-path traversal attempt. Returning a boolean indicating if a path traversal attempt
-exists in the data.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: boolean
- True indicates a path traversal attempt was found. False otherwise.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| data | string
| The data to check for possible malicious data. |
-
-
-
-### query~login(req) ⇒ string
-Returns the User from the URL Path, otherwise ''
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
- Returns a valid specified user or ''.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~serviceType(req) ⇒ string
\| boolean
-Returns the service type being requested.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
-nonexistent. Returns `providedServices` if the query is `provided` or returns
-`consumedServices` if the query is `consumed`
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~serviceVersion(req) ⇒ string
\| boolean
-Returns the version of whatever service is being requested.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
-nonexistant. Returns the version as a string otherwise.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express Endpoint. |
-
-
-
-### query~service(req) ⇒ string
\| boolean
-Returns the service being requested.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
-nonexistant. Returns the service string otherwise.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~fileExtension(req) ⇒ string
\| boolean
-Returns the file extension being requested.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
-nonexistant. Returns the service string otherwise.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-
-
-
-### query~stringValidation(value) ⇒ string
\| boolean
-Provides a generic Query Utility that validates if a provided value
-is a string, as well as trimming it to the safe max length of query strings,
-while additionally passing it through the Path Traversal Detection function.
-
-**Kind**: inner method of [query
](#module_query)
-**Returns**: string
\| boolean
- Returns false if any check fails, otherwise returns
-the valid string.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| value | string
| The value to check |
-
## server
@@ -1588,7 +1375,7 @@ to this server for download.
### utils~engineFilter() ⇒ object
A complex function that provides filtering by Atom engine version.
-This should take a package with it's versions and retrieve whatever matches
+This should take a package with its versions and retrieve whatever matches
that engine version as provided.
**Kind**: inner method of [utils
](#module_utils)
@@ -1853,854 +1640,336 @@ Used to preform the actual sending of the webhook.
| obj | object
| The Object to send via the webhook |
| webhookURL | string
| The URL to send the webhook to. |
-
+
-## common\_handler
-Provides a simplistic way to refer to implement common endpoint returns.
-So these can be called as an async function without more complex functions, reducing
-verbosity, and duplication within the codebase.
+## deletePackagesPackageName
+
-**Implements**: logger
+## DeletePackagesPackageNameStar
+
-* [common_handler](#module_common_handler)
- * [~handleError(req, res, obj)](#module_common_handler..handleError)
- * [~handleDetailedError(req, res, obj)](#module_common_handler..handleDetailedError)
- * [~authFail(req, res, user)](#module_common_handler..authFail)
- * [~serverError(req, res, err)](#module_common_handler..serverError)
- * [~notFound(req, res)](#module_common_handler..notFound)
- * [~notSupported(req, res)](#module_common_handler..notSupported)
- * [~siteWideNotFound(req, res)](#module_common_handler..siteWideNotFound)
- * [~badRepoJSON(req, res)](#module_common_handler..badRepoJSON)
- * [~badPackageJSON(req, res)](#module_common_handler..badPackageJSON)
- * [~packageExists(req, res)](#module_common_handler..packageExists)
- * [~missingAuthJSON(req, res)](#module_common_handler..missingAuthJSON)
+## deletePackagesPackageNameVersionsVersionName
+
-
-
-### common_handler~handleError(req, res, obj)
-Generic error handler mostly used to reduce the duplication of error handling in other modules.
-It checks the short error string and calls the relative endpoint.
-Note that it's designed to be called as the last async function before the return.
-
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-| obj | object
| the Raw Status Object of the User, expected to return from `VerifyAuth`. |
+## getLogin
+
-
+## getOauth
+
-### common_handler~handleDetailedError(req, res, obj)
-Less generic error handler than `handleError()`. Used for returned the
-improved error messages to users. Where instead of only returning an error
-`message` it will return `message` and `details`. Providing better insight into
-what has gone wrong with the server.
-Additionally this will aim to simplify error handling by not handing off the
-handling to additional functions.
+## getPackages
+
-**Kind**: inner method of [common\_handler
](#module_common_handler)
+## getPackagesFeatured
+
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-| obj | object
| The Object provided to return the error message. |
-| obj.short | string
| The recognized Short Code string for error handling. |
-| obj.content | string
| The detailed user friendly content of what's gone wrong. |
+## getPackagesPackageName
+
-
+## getPackagesPackageNameStargazers
+
-### common_handler~authFail(req, res, user)
-Will take the failed user object from VerifyAuth, and respond for the endpoint as
-either a "Server Error" or a "Bad Auth", whichever is correct based on the Error bubbled from VerifyAuth.
+## getPackagesPackageNameVersionsVersionName
+
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: MissingAuthJSON
, ServerErrorJSON
, logger.HTTPLog
+## getPackagesPackageNameVersionsVersionNameTarball
+
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-| user | object
| The Raw Status Object of the User, expected to return from `VerifyAuth`. |
+## getPackagesSearch
+
-
+## getPat
+
-### common_handler~serverError(req, res, err)
-Returns a standard Server Error to the user as JSON. Logging the detailed error message to the server.
-###### Setting:
-* Status Code: 500
-* JSON Response Body: message: "Application Error"
+## getRoot
+
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
, logger.generic
+## getStars
+
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-| err | string
| The detailed error message to log server side. |
+## getThemes
+
-
+## getThemesFeatured
+
-### common_handler~notFound(req, res)
-Standard endpoint to return the JSON Not Found error to the user.
-###### Setting:
-* Status Code: 404
-* JSON Respone Body: message: "Not Found"
+## getThemesSearch
+
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
+## getUpdates
+
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
+## getUsers
+
-
+## getUsersLogin
+
-### common_handler~notSupported(req, res)
-Returns a Not Supported message to the user.
-###### Setting:
-* Status Code: 501
-* JSON Response Body: message: "While under development this feature is not supported."
+## getUsersLoginStars
+
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
+## postPackages
+
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
+## postPackagesPackageNameStar
+
-
+## postPackagesPackageNameVersions
+
-### common_handler~siteWideNotFound(req, res)
-Returns the SiteWide 404 page to the end user.
-###### Setting Currently:
-* Status Code: 404
-* JSON Response Body: message: "This is a standin for the proper site wide 404 page."
+## postPackagesPackageNameVersionsVersionNameEventsUninstall
+
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
-
-
-### common_handler~badRepoJSON(req, res)
-Returns the BadRepoJSON message to the user.
-###### Setting:
-* Status Code: 400
-* JSON Response Body: message: That repo does not exist, isn't an atom package, or atombot does not have access.
-
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
-
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
-
-
-### common_handler~badPackageJSON(req, res)
-Returns the BadPackageJSON message to the user.
-###### Setting:
-* Status Code: 400
-* JSON Response Body: message: The package.json at owner/repo isn't valid.
+## query
+Home to parsing all query parameters from the `Request` object. Ensuring a valid response.
+While most values will just return their default there are some expecptions:
+engine(): Returns false if not defined, to allow a fast way to determine if results need to be pruned.
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
+
-| Param | Type | Description |
-| --- | --- | --- |
-| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
+## verifyAuth() ⇒ object
+This will be the major function to determine, confirm, and provide user
+details of an authenticated user. This will take a users provided token,
+and use it to check GitHub for the details of whoever owns this token.
+Once that is done, we can go ahead and search for said user within the database.
+If the user exists, then we can confirm that they are both locally and globally
+authenticated, and execute whatever action it is they wanted to.
-
+**Kind**: global function
+**Returns**: object
- A server status object.
+**Params**: string
token - The token the user provided.
+
-### common_handler~packageExists(req, res)
-Returns the PackageExist message to the user.
-###### Setting:
-* Status Code: 409
-* JSON Response Body: message: "A Package by that name already exists."
+## auth(req) ⇒ string
+Retrieves Authorization Headers from Request, and Checks for Undefined.
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
+**Kind**: global function
+**Returns**: string
- Returning a valid Authorization Token, or '' if invalid/not found.
| Param | Type | Description |
| --- | --- | --- |
| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
+
-### common_handler~missingAuthJSON(req, res)
-Returns the MissingAuth message to the user.
-###### Setting:
-* Status Code: 401
-* JSON Response Body: message: "Requires authentication. Please update your token if you haven't done so recently."
+## direction(req) ⇒ string
+Parser for either 'direction' or 'order' query parameter, prioritizing
+'direction'.
-**Kind**: inner method of [common\_handler
](#module_common_handler)
-**Implements**: logger.HTTPLog
+**Kind**: global function
+**Returns**: string
- The valid direction value from the 'direction' or 'order'
+query parameter.
| Param | Type | Description |
| --- | --- | --- |
| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
-
-
-## delete\_package\_handler
-Endpoint Handlers for every DELETE Request that relates to packages themselves
-
-
-* [delete_package_handler](#module_delete_package_handler)
- * [~deletePackagesName(params, db, auth, vcs)](#module_delete_package_handler..deletePackagesName)
- * [~deletePackageStar(params, db, auth)](#module_delete_package_handler..deletePackageStar)
- * [~deletePackageVersion(params, db, auth, vcs)](#module_delete_package_handler..deletePackageVersion)
-
-
-
-### delete_package_handler~deletePackagesName(params, db, auth, vcs)
-Allows the user to delete a repo they have ownership of.
-
-**Kind**: inner method of [delete\_package\_handler
](#module_delete_package_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters |
-| params.auth | string
| The API key for the user |
-| params.packageName | string
| The name of the package |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-| vcs | module
| An instance of the `vcs.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| DELETE |
-| http\_endpoint
| /api/packages/:packageName |
-
-
-
-### delete_package_handler~deletePackageStar(params, db, auth)
-Used to remove a star from a specific package for the authenticated usesr.
-
-**Kind**: inner method of [delete\_package\_handler
](#module_delete_package_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters |
-| params.auth | string
| The API Key of the user |
-| params.packageName | string
| The name of the package |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| DELETE |
-| http\_endpoint
| /api/packages/:packageName/star |
-
-
-
-### delete_package_handler~deletePackageVersion(params, db, auth, vcs)
-Allows a user to delete a specific version of their package.
-
-**Kind**: inner method of [delete\_package\_handler
](#module_delete_package_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters |
-| params.auth | string
| The API key of the user |
-| params.packageName | string
| The name of the package |
-| params.versionName | string
| The version of the package |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-| vcs | module
| An instance of the `vcs.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| DELETE |
-| http\_endpoint
| /api/packages/:packageName/versions/:versionName |
-
-
-
-## get\_package\_handler
-Endpoint Handlers for every GET Request that relates to packages themselves
+
-* [get_package_handler](#module_get_package_handler)
- * [~getPackages(params, db)](#module_get_package_handler..getPackages)
- * [~getPackagesFeatured(db)](#module_get_package_handler..getPackagesFeatured)
- * [~getPackagesSearch(params, db)](#module_get_package_handler..getPackagesSearch)
- * [~getPackagesDetails(param, db)](#module_get_package_handler..getPackagesDetails)
- * [~getPackagesStargazers(params, db)](#module_get_package_handler..getPackagesStargazers)
- * [~getPackagesVersion(params, db)](#module_get_package_handler..getPackagesVersion)
- * [~getPackagesVersionTarball(params, db)](#module_get_package_handler..getPackagesVersionTarball)
-
-
-
-### get_package_handler~getPackages(params, db)
-Endpoint to return all packages to the user. Based on any filtering
-theyved applied via query parameters.
-
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters for this endpoint. |
-| params.page | integer
| The page to retreive |
-| params.sort | string
| The method to sort by |
-| params.direction | string
| The direction to sort with |
-| params.serviceType | string
| The service type to display |
-| params.service | string
| The service to display |
-| params.serviceVersion | string
| The service version to show |
-| params.fileExtension | string
| File extension to only show compatible grammar package's of. |
-| db | module
| An instance of the database |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages |
-
-
-
-### get_package_handler~getPackagesFeatured(db)
-Allows the user to retrieve the featured packages, as package object shorts.
-This endpoint was originally undocumented. The decision to return 200 is based off similar endpoints.
-Additionally for the time being this list is created manually, the same method used
-on Atom.io for now. Although there are plans to have this become automatic later on.
-
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
-**See**
-
-- [Source Code](https://github.com/atom/apm/blob/master/src/featured.coffee)
-- [Discussion](https://github.com/confused-Techie/atom-community-server-backend-JS/issues/23)
-
-
-| Param | Type | Description |
-| --- | --- | --- |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages/featured |
-
-
-
-### get_package_handler~getPackagesSearch(params, db)
-Allows user to search through all packages. Using their specified
-query parameter.
-
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
-**Todo**
-
-- [ ] Note: This **has** been migrated to the new DB, and is fully functional.
-The TODO here is to eventually move this to use the custom built in LCS search,
-rather than simple search.
+## engine(semver) ⇒ string
\| boolean
+Parses the 'engine' query parameter to ensure it's valid, otherwise returning false.
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns the valid 'engine' specified, or if none, returns false.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters |
-| params.page | integer
| The page to retreive |
-| params.sort | string
| The method to sort by |
-| params.direction | string
| The direction to sort with |
-| params.query | string
| The search query |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages/search |
+| semver | string
| The engine string. |
-
+
-### get_package_handler~getPackagesDetails(param, db)
-Allows the user to request a single package object full, depending
-on the package included in the path parameter.
+## fileExtension(req) ⇒ string
\| boolean
+Returns the file extension being requested.
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
+nonexistant. Returns the service string otherwise.
| Param | Type | Description |
| --- | --- | --- |
-| param | object
| The query parameters |
-| param.engine | string
| The version of Pulsar to check compatibility with |
-| param.name | string
| The package name |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages/:packageName |
+| req | object
| The `Request` object inherited from the Express endpoint. |
-
+
-### get_package_handler~getPackagesStargazers(params, db)
-Endpoint returns the array of `star_gazers` from a specified package.
-Taking only the package wanted, and returning it directly.
+## login(req) ⇒ string
+Returns the User from the URL Path, otherwise ''
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
+**Kind**: global function
+**Returns**: string
- Returns a valid specified user or ''.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters |
-| params.packageName | string
| The name of the package |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages/:packageName/stargazers |
-
-
+| req | object
| The `Request` object inherited from the Express endpoint. |
-### get_package_handler~getPackagesVersion(params, db)
-Used to retrieve a specific version from a package.
+
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
+## user(req) ⇒ string
\| boolean
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns false if the provided value is invalid or
+ nonexistent. Returns the user name otherwise.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters |
-| params.packageName | string
| The Package name we care about |
-| params.versionName | string
| The package version we care about |
-| db | module
| An instance of the `database.js` module |
+| req | object
| The `Request` object inherited from the Express endpoint. |
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages/:packageName/versions/:versionName |
+
-
-
-### get_package_handler~getPackagesVersionTarball(params, db)
-Allows the user to get the tarball for a specific package version.
-Which should initiate a download of said tarball on their end.
+## packageName(req) ⇒ string
+This function will convert a user provided package name into a safe format.
+It ensures the name is converted to lower case. As is the requirement of all package names.
-**Kind**: inner method of [get\_package\_handler
](#module_get_package_handler)
+**Kind**: global function
+**Returns**: string
- Returns the package name in a safe format that can be worked with further.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters |
-| params.packageName | string
| The name of the package |
-| params.versionName | string
| The version of the package |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/packages/:packageName/versions/:versionName/tarball |
-
-
-
-## oauth\_handler
-Endpoint Handlers for Authentication URLs
-
-**Implements**: config
, common\_handler
-
-* [oauth_handler](#module_oauth_handler)
- * [~getLogin(req, res)](#module_oauth_handler..getLogin)
- * [~getOauth(req, res)](#module_oauth_handler..getOauth)
- * [~getPat(req, res)](#module_oauth_handler..getPat)
+| req | object
| The `Request` Object inherited from the Express endpoint. |
-
+
-### oauth_handler~getLogin(req, res)
-Endpoint used to redirect users to login. Users will reach GitHub OAuth Page
-based on the backends client id. A key from crypto module is retrieved and used as
-state parameter for GH authentication.
+## page(req) ⇒ number
+Parser of the Page query parameter. Defaulting to 1.
-**Kind**: inner method of [oauth\_handler
](#module_oauth_handler)
+**Kind**: global function
+**Returns**: number
- Returns the valid page provided in the query parameter or 1, as the default.
| Param | Type | Description |
| --- | --- | --- |
| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
-**Properties**
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/lgoin |
+
-
-
-### oauth_handler~getOauth(req, res)
-Endpoint intended to use as the actual return from GitHub to login.
+## query(req) ⇒ string
+Checks the 'q' query parameter, trunicating it at 50 characters, and checking simplisticly that
+it is not a malicious request. Returning "" if an unsafe or invalid query is passed.
-**Kind**: inner method of [oauth\_handler
](#module_oauth_handler)
+**Kind**: global function
+**Implements**: [pathTraversalAttempt
](#pathTraversalAttempt)
+**Returns**: string
- A valid search string derived from 'q' query parameter. Or '' if invalid.
| Param | Type | Description |
| --- | --- | --- |
| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/oath |
-
+
-### oauth_handler~getPat(req, res)
-Endpoint intended to Allow users to sign up with a Pat Token.
+## rename(req) ⇒ boolean
+Since this is intended to be returning a boolean value, returns false
+if invalid, otherwise returns true. Checking for mixed captilization.
-**Kind**: inner method of [oauth\_handler
](#module_oauth_handler)
+**Kind**: global function
+**Returns**: boolean
- Returns false if invalid, or otherwise returns the boolean value of the string.
| Param | Type | Description |
| --- | --- | --- |
| req | object
| The `Request` object inherited from the Express endpoint. |
-| res | object
| The `Response` object inherited from the Express endpoint. |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/pat |
-
-
-## package\_handler
-Exports individual files handling endpoints relating to Packages
-
-
-
-## post\_package\_handler
-Endpoint Handlers for every POST Request that relates to packages themselves
-
-
-* [post_package_handler](#module_post_package_handler)
- * [~postPackages(params, db, auth, vcs)](#module_post_package_handler..postPackages) ⇒ string
- * [~postPackagesStar(params, db, auth)](#module_post_package_handler..postPackagesStar)
- * [~postPackagesVersion(params, db, auth, vcs)](#module_post_package_handler..postPackagesVersion)
-
-
-
-### post_package_handler~postPackages(params, db, auth, vcs) ⇒ string
-This endpoint is used to publish a new package to the backend server.
-Taking the repo, and your authentication for it, determines if it can be published,
-then goes about doing so.
-
-**Kind**: inner method of [post\_package\_handler
](#module_post_package_handler)
-**Returns**: string
- JSON object of new data pushed into the database, but stripped of
-sensitive informations like primary and foreign keys.
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters |
-| params.repository | string
| The `owner/repo` combo of the remote package |
-| params.auth | string
| The API key of the user |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-| vcs | module
| An instance of the `vcs.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| POST |
-| http\_endpoint
| /api/packages |
-
-
-
-### post_package_handler~postPackagesStar(params, db, auth)
-Used to submit a new star to a package from the authenticated user.
-
-**Kind**: inner method of [post\_package\_handler
](#module_post_package_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters |
-| params.auth | string
| The API key of the user |
-| params.packageName | string
| The name of the package |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
+
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| POST |
-| http\_endpoint
| /api/packages/:packageName/star |
-
-
-
-### post_package_handler~postPackagesVersion(params, db, auth, vcs)
-Allows a new version of a package to be published. But also can allow
-a user to rename their application during this process.
-
-**Kind**: inner method of [post\_package\_handler
](#module_post_package_handler)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| params | object
| The query parameters |
-| params.rename | boolean
| Whether or not to preform a rename |
-| params.auth | string
| The API key of the user |
-| params.packageName | string
| The name of the package |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-| vcs | module
| An instance of the `vcs.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| POST |
-| http\_endpoint
| /api/packages/:packageName/versions |
-
-
-
-## star\_handler
-Handler for any endpoints whose slug after `/api/` is `star`.
-
-
-
-### star_handler~getStars(param, db, auth)
-Endpoint for `GET /api/stars`. Whose endgoal is to return an array of all packages
-the authenticated user has stared.
+## repo(req) ⇒ string
+Parses the 'repository' query parameter, returning it if valid, otherwise returning ''.
-**Kind**: inner method of [star\_handler
](#module_star_handler)
+**Kind**: global function
+**Returns**: string
- Returning the valid 'repository' query parameter, or '' if invalid.
| Param | Type | Description |
| --- | --- | --- |
-| param | object
| The supported query parameters. |
-| param.auth | string
| The authentication API token |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/stars |
-
-
-
-## theme\_handler
-Endpoint Handlers relating to themes only.
-
-**Implements**: database
, utils
, logger
, config
-
-* [theme_handler](#module_theme_handler)
- * [~getThemeFeatured(db)](#module_theme_handler..getThemeFeatured)
- * [~getThemes(params, db)](#module_theme_handler..getThemes) ⇒ object
- * [~getThemesSearch(params, db)](#module_theme_handler..getThemesSearch)
-
-
-
-### theme_handler~getThemeFeatured(db)
-Used to retrieve all Featured Packages that are Themes. Originally an undocumented
-endpoint. Returns a 200 response based on other similar responses.
-Additionally for the time being this list is created manually, the same method used
-on Atom.io for now. Although there are plans to have this become automatic later on.
+| req | object
| The `Request` object inherited from the Express endpoint. |
-**Kind**: inner method of [theme\_handler
](#module_theme_handler)
-**See**
+
-- [Source Code](https://github.com/atom/apm/blob/master/src/featured.coffee)
-- [Discussion](https://github.com/confused-Techie/atom-community-server-backend-JS/issues/23)
+## service(req) ⇒ string
\| boolean
+Returns the service being requested.
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns false if the provided value is invalid or
+nonexistent. Returns the service string otherwise.
| Param | Type | Description |
| --- | --- | --- |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/themes/featured |
+| req | object
| The `Request` object inherited from the Express endpoint. |
-
+
-### theme_handler~getThemes(params, db) ⇒ object
-Endpoint to return all Themes to the user. Based on any filtering
-they'ved applied via query parameters.
+## serviceType(req) ⇒ string
\| boolean
+Returns the service type being requested.
-**Kind**: inner method of [theme\_handler
](#module_theme_handler)
-**Returns**: object
- An HTTP ServerStatus.
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
+nonexistent. Returns `providedServices` if the query is `provided` or returns
+`consumedServices` if the query is `consumed`
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters that can operate on this endpoint. |
-| params.page | integer
| The page of results to retreive. |
-| params.sort | string
| The sort method to use. |
-| params.direction | string
| The direction to sort results. |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/themes |
+| req | object
| The `Request` object inherited from the Express endpoint. |
-
+
-### theme_handler~getThemesSearch(params, db)
-Endpoint to Search from all themes on the registry.
+## serviceVersion(req) ⇒ string
\| boolean
+Returns the version of whatever service is being requested.
-**Kind**: inner method of [theme\_handler
](#module_theme_handler)
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns false if the provided value is invalid, or
+nonexistant. Returns the version as a string otherwise.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters from the initial request. |
-| params.page | integer
| The page number to return |
-| params.sort | string
| The method to use to sort |
-| params.direction | string
| The direction to sort |
-| params.query | string
| The search query to use |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/themes/search |
-
-
-
-## update\_handler
-Endpoint Handlers relating to updating the editor.
-
-**Implments**: command\_handler
-
-
-### update_handler~getUpdates()
-Used to retrieve new editor update information.
-
-**Kind**: inner method of [update\_handler
](#module_update_handler)
-**Todo**
-
-- [ ] This function has never been implemented on this system. Since there is currently no
-update methodology.
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/updates |
+| req | object
| The `Request` object inherited from the Express Endpoint. |
-
+
-## user\_handler
-Handler for endpoints whose slug after `/api/` is `user`.
+## sort(req, [def]) ⇒ string
+Parser for the 'sort' query parameter. Defaulting usually to downloads.
+**Kind**: global function
+**Returns**: string
- Either the user provided 'sort' query parameter, or the default specified.
-* [user_handler](#module_user_handler)
- * [~getLoginStars(params, db)](#module_user_handler..getLoginStars)
- * [~getAuthUser(params, db, auth)](#module_user_handler..getAuthUser)
- * [~getUser(params, db)](#module_user_handler..getUser)
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| req | object
| | The `Request` object inherited from the Express endpoint. |
+| [def] | string
| "\"downloads\""
| The default provided for sort. Allowing The search function to use "relevance" instead of the default "downloads". |
-
+
-### user_handler~getLoginStars(params, db)
-Endpoint that returns another users Star Gazers List.
+## tag(req) ⇒ string
+Parses the 'tag' query parameter, returning it if valid, otherwise returning ''.
-**Kind**: inner method of [user\_handler
](#module_user_handler)
+**Kind**: global function
+**Returns**: string
- Returns a valid 'tag' query parameter. Or '' if invalid.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters for the request |
-| params.login | string
| The username |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/users/:login/stars |
+| req | object
| The `Request` object inherited from the Express endpoint. |
-
+
-### user_handler~getAuthUser(params, db, auth)
-Endpoint that returns the currently authenticated Users User Details
+## stringValidation(value) ⇒ string
\| boolean
+Provides a generic Query Utility that validates if a provided value
+is a string, as well as trimming it to the safe max length of query strings,
+while additionally passing it through the Path Traversal Detection function.
-**Kind**: inner method of [user\_handler
](#module_user_handler)
+**Kind**: global function
+**Returns**: string
\| boolean
- Returns false if any check fails, otherwise returns
+the valid string.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters for this endpoint |
-| params.auth | string
| The API Key |
-| db | module
| An instance of the `database.js` module |
-| auth | module
| An instance of the `auth.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/users |
+| value | string
| The value to check |
-
+
-### user_handler~getUser(params, db)
-Endpoint that returns the user account details of another user. Including all packages
-published.
+## pathTraversalAttempt(data) ⇒ boolean
+Completes some short checks to determine if the data contains a malicious
+path traversal attempt. Returning a boolean indicating if a path traversal attempt
+exists in the data.
-**Kind**: inner method of [user\_handler
](#module_user_handler)
+**Kind**: global function
+**Returns**: boolean
- True indicates a path traversal attempt was found. False otherwise.
| Param | Type | Description |
| --- | --- | --- |
-| params | object
| The query parameters |
-| params.login | string
| The Username we want to look for |
-| db | module
| An instance of the `database.js` module |
-
-**Properties**
-
-| Type | Description |
-| --- | --- |
-| http\_method
| GET |
-| http\_endpoint
| /api/users/:login |
-
-
-
-## verifyAuth() ⇒ object
-This will be the major function to determine, confirm, and provide user
-details of an authenticated user. This will take a users provided token,
-and use it to check GitHub for the details of whoever owns this token.
-Once that is done, we can go ahead and search for said user within the database.
-If the user exists, then we can confirm that they are both locally and globally
-authenticated, and execute whatever action it is they wanted to.
+| data | string
| The data to check for possible malicious data. |
-**Kind**: global function
-**Returns**: object
- A server status object.
-**Params**: string
token - The token the user provided.
## ServerStatusObject : object
diff --git a/docs/resources/complexity-report.md b/docs/resources/complexity-report.md
index 6f19097d..0720a060 100644
--- a/docs/resources/complexity-report.md
+++ b/docs/resources/complexity-report.md
@@ -1,22 +1,22 @@
-# Complexity report, 9/19/2023
-
-* Mean per-function logical LOC: 14.272727272727273
-* Mean per-function parameter count: 0.2840909090909091
-* Mean per-function cyclomatic complexity: 1.3863636363636365
-* Mean per-function Halstead effort: 3943.557748871758
-* Mean per-module maintainability index: 69.41048329189348
-* First-order density: 0.4132231404958678%
-* Change cost: 4.958677685950414%
+# Complexity report, 1/13/2024
+
+* Mean per-function logical LOC: 14.271929824561404
+* Mean per-function parameter count: 0.1324561403508772
+* Mean per-function cyclomatic complexity: 1.1736842105263159
+* Mean per-function Halstead effort: 3371.505283870604
+* Mean per-module maintainability index: 69.2796371850002
+* First-order density: 0.9233610341643583%
+* Change cost: 5.786395814096645%
* Core size: 100%
## /home/runner/work/package-backend/package-backend/jest.config.js
-* Physical LOC: 53
-* Logical LOC: 24
+* Physical LOC: 35
+* Logical LOC: 16
* Mean parameter count: 0
* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 4.166666666666666%
-* Maintainability index: 53.406190105164676
+* Cyclomatic complexity density: 6.25%
+* Maintainability index: 58.62281095645006
* Dependency count: 0
## /home/runner/work/package-backend/package-backend/jsdoc.conf.js
@@ -41,13 +41,13 @@
## /home/runner/work/package-backend/package-backend/src/PackageObject.js
-* Physical LOC: 468
-* Logical LOC: 3
+* Physical LOC: 485
+* Logical LOC: 4
* Mean parameter count: 0
* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 33.33333333333333%
-* Maintainability index: 79.75031095891569
-* Dependency count: 2
+* Cyclomatic complexity density: 25%
+* Maintainability index: 76.17088968963267
+* Dependency count: 3
## /home/runner/work/package-backend/package-backend/src/cache.js
@@ -59,7 +59,27 @@
* Maintainability index: 78.8444767459975
* Dependency count: 1
-## /home/runner/work/package-backend/package-backend/src/debug_utils.js
+## /home/runner/work/package-backend/package-backend/src/context.js
+
+* Physical LOC: 15
+* Logical LOC: 14
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 7.142857142857142%
+* Maintainability index: 60.516428793372064
+* Dependency count: 13
+
+## /home/runner/work/package-backend/package-backend/docs/resources/jsdoc_typedef.js
+
+* Physical LOC: 1
+* Logical LOC: 0
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: Infinity%
+* Maintainability index: 100
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/scripts/deprecated/debug_utils.js
* Physical LOC: 30
* Logical LOC: 22
@@ -79,116 +99,6 @@
* Halstead volume: 475.6861996976024
* Halstead effort: 8970.082622869073
-## /home/runner/work/package-backend/package-backend/test/PackageObject.unit.test.js
-
-* Physical LOC: 41
-* Logical LOC: 2
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 50%
-* Maintainability index: 86.03073855173344
-* Dependency count: 1
-
-## /home/runner/work/package-backend/package-backend/test/ServerStatusObject.unit.test.js
-
-* Physical LOC: 40
-* Logical LOC: 3
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 33.33333333333333%
-* Maintainability index: 80.69690997202572
-* Dependency count: 2
-
-## /home/runner/work/package-backend/package-backend/test/debug_utils.unit.test.js
-
-* Physical LOC: 31
-* Logical LOC: 2
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 50%
-* Maintainability index: 86.03073855173344
-* Dependency count: 1
-
-## /home/runner/work/package-backend/package-backend/test/global.setup.jest.js
-
-* Physical LOC: 38
-* Logical LOC: 21
-* Mean parameter count: 1.5
-* Cyclomatic complexity: 3
-* Cyclomatic complexity density: 14.285714285714285%
-* Maintainability index: 67.68423518589408
-* Dependency count: 1
-* Function: **toBeArray**
- * Line No.: 10
- * Physical LOC: 14
- * Logical LOC: 8
- * Parameter count: 1
- * Cyclomatic complexity: 2
- * Cyclomatic complexity density: 25%
- * Halstead difficulty: 5.25
- * Halstead volume: 93.76537429460444
- * Halstead effort: 492.26821504667333
-* Function: **toHaveHTTPCode**
- * Line No.: 25
- * Physical LOC: 15
- * Logical LOC: 8
- * Parameter count: 2
- * Cyclomatic complexity: 2
- * Cyclomatic complexity density: 25%
- * Halstead difficulty: 5.6875
- * Halstead volume: 97.67226489021297
- * Halstead effort: 555.5110065630863
-
-## /home/runner/work/package-backend/package-backend/test/handlers.setup.jest.js
-
-* Physical LOC: 35
-* Logical LOC: 18
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 5.555555555555555%
-* Maintainability index: 57.15938083859105
-* Dependency count: 0
-
-## /home/runner/work/package-backend/package-backend/test/logger.unit.test.js
-
-* Physical LOC: 95
-* Logical LOC: 4
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 25%
-* Maintainability index: 76.39879935103494
-* Dependency count: 1
-
-## /home/runner/work/package-backend/package-backend/test/query.unit.test.js
-
-* Physical LOC: 179
-* Logical LOC: 99
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 1.0101010101010102%
-* Maintainability index: 34.86610584264533
-* Dependency count: 1
-
-## /home/runner/work/package-backend/package-backend/test/vcs.unit.test.js
-
-* Physical LOC: 66
-* Logical LOC: 2
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 50%
-* Maintainability index: 86.03073855173344
-* Dependency count: 1
-
-## /home/runner/work/package-backend/package-backend/docs/resources/jsdoc_typedef.js
-
-* Physical LOC: 1
-* Logical LOC: 0
-* Mean parameter count: 0
-* Cyclomatic complexity: 1
-* Cyclomatic complexity density: Infinity%
-* Maintainability index: 100
-* Dependency count: 0
-
## /home/runner/work/package-backend/package-backend/scripts/deprecated/search.js
* Physical LOC: 176
@@ -309,47 +219,537 @@
* Halstead volume: 91.37651812938249
* Halstead effort: 186.9065143555551
-## /home/runner/work/package-backend/package-backend/src/handlers/package_handler.js
+## /home/runner/work/package-backend/package-backend/src/controllers/endpoints.js
+
+* Physical LOC: 30
+* Logical LOC: 1
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 100%
+* Maintainability index: 85.19382950159975
+* Dependency count: 27
+
+## /home/runner/work/package-backend/package-backend/src/models/ssoHTML.js
+
+* Physical LOC: 12
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 85.13446209533382
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/src/models/ssoPaginate.js
+
+* Physical LOC: 55
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 85.13446209533382
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/src/models/ssoRedirect.js
+
+* Physical LOC: 12
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 85.13446209533382
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/engine.js
+
+* Physical LOC: 30
+* Logical LOC: 10
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 10%
+* Maintainability index: 66.46226874267799
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/fileExtension.js
+
+* Physical LOC: 18
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 64.33327792249773
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/filter.js
+
+* Physical LOC: 32
+* Logical LOC: 13
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 7.6923076923076925%
+* Maintainability index: 62.60994532732379
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/index.js
+
+* Physical LOC: 61
+* Logical LOC: 57
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 1.7543859649122806%
+* Maintainability index: 41.85471679977376
+* Dependency count: 18
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/packageName.js
-* Physical LOC: 20
-* Logical LOC: 18
+* Physical LOC: 17
+* Logical LOC: 11
* Mean parameter count: 0
* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 5.555555555555555%
-* Maintainability index: 56.530575217792624
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 65.36316082704943
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/page.js
+
+* Physical LOC: 32
+* Logical LOC: 13
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 7.6923076923076925%
+* Maintainability index: 63.29354678537644
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/query.js
+
+* Physical LOC: 38
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 64.33327792249773
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/rename.js
+
+* Physical LOC: 33
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 65.2835832019749
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/repo.js
+
+* Physical LOC: 30
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 65.36316082704943
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/service.js
+
+* Physical LOC: 17
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 64.33327792249773
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/serviceType.js
+
+* Physical LOC: 33
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 64.55996348727876
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/serviceVersion.js
+
+* Physical LOC: 24
+* Logical LOC: 10
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 10%
+* Maintainability index: 66.46226874267799
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/tag.js
+
+* Physical LOC: 16
+* Logical LOC: 11
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 9.090909090909092%
+* Maintainability index: 65.19959506149854
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/utils.js
+
+* Physical LOC: 40
+* Logical LOC: 12
+* Mean parameter count: 1
+* Cyclomatic complexity: 3
+* Cyclomatic complexity density: 25%
+* Maintainability index: 75.35244691757542
+* Dependency count: 0
+* Function: **stringValidation**
+ * Line No.: 10
+ * Physical LOC: 10
+ * Logical LOC: 5
+ * Parameter count: 1
+ * Cyclomatic complexity: 3
+ * Cyclomatic complexity density: 60%
+ * Halstead difficulty: 7.2
+ * Halstead volume: 131.68575291675114
+ * Halstead effort: 948.1374210006082
+* Function: **pathTraversalAttempt**
+ * Line No.: 29
+ * Physical LOC: 16
+ * Logical LOC: 2
+ * Parameter count: 1
+ * Cyclomatic complexity: 1
+ * Cyclomatic complexity density: 50%
+ * Halstead difficulty: 4.199999999999999
+ * Halstead volume: 44.97261104228487
+ * Halstead effort: 188.8849663775964
+
+## /home/runner/work/package-backend/package-backend/src/query_parameters/versionName.js
+
+* Physical LOC: 16
+* Logical LOC: 12
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 8.333333333333332%
+* Maintainability index: 63.05438887045247
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/helpers/global.setup.jest.js
+
+* Physical LOC: 100
+* Logical LOC: 60
+* Mean parameter count: 1.8
+* Cyclomatic complexity: 8
+* Cyclomatic complexity density: 13.333333333333334%
+* Maintainability index: 63.41842305529267
* Dependency count: 3
+* Function: **toBeArray**
+ * Line No.: 13
+ * Physical LOC: 14
+ * Logical LOC: 8
+ * Parameter count: 1
+ * Cyclomatic complexity: 2
+ * Cyclomatic complexity density: 25%
+ * Halstead difficulty: 5.25
+ * Halstead volume: 93.76537429460444
+ * Halstead effort: 492.26821504667333
+* Function: **toBeTypeof**
+ * Line No.: 28
+ * Physical LOC: 13
+ * Logical LOC: 8
+ * Parameter count: 2
+ * Cyclomatic complexity: 2
+ * Cyclomatic complexity density: 25%
+ * Halstead difficulty: 6
+ * Halstead volume: 91.37651812938249
+ * Halstead effort: 548.259108776295
+* Function: **toBeIncludedBy**
+ * Line No.: 42
+ * Physical LOC: 13
+ * Logical LOC: 8
+ * Parameter count: 2
+ * Cyclomatic complexity: 2
+ * Cyclomatic complexity density: 25%
+ * Halstead difficulty: 6.4
+ * Halstead volume: 129.26767504471167
+ * Halstead effort: 827.3131202861547
+* Function: **toMatchEndpointSuccessObject**
+ * Line No.: 56
+ * Physical LOC: 29
+ * Logical LOC: 18
+ * Parameter count: 2
+ * Cyclomatic complexity: 4
+ * Cyclomatic complexity density: 22.22222222222222%
+ * Halstead difficulty: 12.69047619047619
+ * Halstead volume: 406.9970273000272
+ * Halstead effort: 5164.986084545583
+* Function: **toHaveHTTPCode**
+ * Line No.: 86
+ * Physical LOC: 15
+ * Logical LOC: 8
+ * Parameter count: 2
+ * Cyclomatic complexity: 2
+ * Cyclomatic complexity density: 25%
+ * Halstead difficulty: 5.6875
+ * Halstead volume: 97.67226489021297
+ * Halstead effort: 555.5110065630863
+
+## /home/runner/work/package-backend/package-backend/tests/helpers/handlers.setup.jest.js
+
+* Physical LOC: 33
+* Logical LOC: 17
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 5.88235294117647%
+* Maintainability index: 57.795357898379244
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/tests/models/message.js
+
+* Physical LOC: 19
+* Logical LOC: 12
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 8.333333333333332%
+* Maintainability index: 62.226244150536175
+* Dependency count: 0
-## /home/runner/work/package-backend/package-backend/test/fixtures/git.createPackage_returns/valid_multi_version.js
+## /home/runner/work/package-backend/package-backend/tests/models/packageObjectFull.js
-* Physical LOC: 43
-* Logical LOC: 34
+* Physical LOC: 147
+* Logical LOC: 86
* Mean parameter count: 0
* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 2.941176470588235%
-* Maintainability index: 50.83192723928399
+* Cyclomatic complexity density: 1.1627906976744187%
+* Maintainability index: 37.52288274528104
* Dependency count: 0
-## /home/runner/work/package-backend/package-backend/test/fixtures/git.createPackage_returns/valid_one_version.js
+## /home/runner/work/package-backend/package-backend/tests/models/packageObjectFullArray.js
-* Physical LOC: 25
-* Logical LOC: 19
+* Physical LOC: 5
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 73.83569622868538
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/models/packageObjectShort.js
+
+* Physical LOC: 137
+* Logical LOC: 88
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 1.1363636363636365%
+* Maintainability index: 37.62685787133425
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/tests/models/packageObjectShortArray.js
+
+* Physical LOC: 5
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 73.83569622868538
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/models/userObjectPrivate.js
+
+* Physical LOC: 48
+* Logical LOC: 36
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 2.7777777777777777%
+* Maintainability index: 48.1797728952525
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/tests/models/userObjectPublic.js
+
+* Physical LOC: 38
+* Logical LOC: 28
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 3.571428571428571%
+* Maintainability index: 51.33890916054792
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/tests/unit/PackageObject.test.js
+
+* Physical LOC: 54
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/ServerStatusObject.test.js
+
+* Physical LOC: 40
+* Logical LOC: 3
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 33.33333333333333%
+* Maintainability index: 80.69690997202572
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/unit/endpoints.test.js
+
+* Physical LOC: 40
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/logger.test.js
+
+* Physical LOC: 95
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 76.39879935103494
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/query.test.js
+
+* Physical LOC: 192
+* Logical LOC: 108
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 0.9259259259259258%
+* Maintainability index: 33.49221524957683
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/vcs/vcs.unit.test.js
+
+* Physical LOC: 66
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/deletePackagesPackageName.test.js
+
+* Physical LOC: 18
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/deletePackagesPackageNameStar.js
+
+* Physical LOC: 21
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/deletePackagesPackageNameVersionsVersionName.test.js
+
+* Physical LOC: 21
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/getRoot.test.js
+
+* Physical LOC: 18
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/getThemes.test.js
+
+* Physical LOC: 52
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 77.34651555826905
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/getThemesSearch.test.js
+
+* Physical LOC: 54
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 77.34651555826905
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/getUsers.test.js
+
+* Physical LOC: 51
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 77.34651555826905
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/getUsersLogin.test.js
+
+* Physical LOC: 37
+* Logical LOC: 4
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 25%
+* Maintainability index: 77.34651555826905
+* Dependency count: 2
+
+## /home/runner/work/package-backend/package-backend/tests/unit/controllers/postPackagesPackageNameVersions.test.js
+
+* Physical LOC: 13
+* Logical LOC: 2
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 50%
+* Maintainability index: 86.03073855173344
+* Dependency count: 1
+
+## /home/runner/work/package-backend/package-backend/tests/database/fixtures/git.createPackage_returns/valid_multi_version.js
+
+* Physical LOC: 44
+* Logical LOC: 35
+* Mean parameter count: 0
+* Cyclomatic complexity: 1
+* Cyclomatic complexity density: 2.857142857142857%
+* Maintainability index: 50.54467615127807
+* Dependency count: 0
+
+## /home/runner/work/package-backend/package-backend/tests/database/fixtures/git.createPackage_returns/valid_one_version.js
+
+* Physical LOC: 26
+* Logical LOC: 20
* Mean parameter count: 0
* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 5.263157894736842%
-* Maintainability index: 58.378034894518755
+* Cyclomatic complexity density: 5%
+* Maintainability index: 57.81245775166893
* Dependency count: 0
-## /home/runner/work/package-backend/package-backend/test/fixtures/lifetime/package-a.js
+## /home/runner/work/package-backend/package-backend/tests/database/fixtures/lifetime/package-a.js
-* Physical LOC: 53
-* Logical LOC: 25
+* Physical LOC: 54
+* Logical LOC: 26
* Mean parameter count: 0
* Cyclomatic complexity: 1
-* Cyclomatic complexity density: 4%
-* Maintainability index: 54.4848955157022
+* Cyclomatic complexity density: 3.8461538461538463%
+* Maintainability index: 54.06517395834382
* Dependency count: 0
-## /home/runner/work/package-backend/package-backend/test/fixtures/lifetime/user-a.js
+## /home/runner/work/package-backend/package-backend/tests/database/fixtures/lifetime/user-a.js
* Physical LOC: 9
* Logical LOC: 6
@@ -359,7 +759,7 @@
* Maintainability index: 71.67165455570546
* Dependency count: 0
-## /home/runner/work/package-backend/package-backend/test/handlers/common_handler/express_fakes.js
+## /home/runner/work/package-backend/package-backend/scripts/deprecated/test/handlers/common_handler/express_fakes.js
* Physical LOC: 26
* Logical LOC: 3
diff --git a/jest.config.js b/jest.config.js
index 63514535..5b7304fa 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -1,43 +1,35 @@
const config = {
- setupFilesAfterEnv: [
- "/tests/helpers/global.setup.jest.js"
- ],
+ setupFilesAfterEnv: ["/tests/helpers/global.setup.jest.js"],
verbose: true,
collectCoverage: true,
- coverageReporters: [
- "text",
- "clover"
- ],
+ coverageReporters: ["text", "clover"],
coveragePathIgnorePatterns: [
"/tests/",
"/test/",
- "/node_modules/"
+ "/node_modules/",
],
projects: [
{
displayName: "Integration-Tests",
globalSetup: "/node_modules/@databases/pg-test/jest/globalSetup",
- globalTeardown: "/node_modules/@databases/pg-test/jest/globalTeardown",
+ globalTeardown:
+ "/node_modules/@databases/pg-test/jest/globalTeardown",
setupFilesAfterEnv: [
"/tests/helpers/handlers.setup.jest.js",
- "/tests/helpers/global.setup.jest.js"
+ "/tests/helpers/global.setup.jest.js",
],
testMatch: [
"/tests/database/**.test.js",
"/tests/http/**.test.js",
- "/tests/vcs/**.test.js"
- ]
+ "/tests/vcs/**.test.js",
+ ],
},
{
displayName: "Unit-Tests",
- setupFilesAfterEnv: [
- "/tests/helpers/global.setup.jest.js"
- ],
- testMatch: [
- "/tests/unit/**/**.test.js"
- ]
- }
- ]
+ setupFilesAfterEnv: ["/tests/helpers/global.setup.jest.js"],
+ testMatch: ["/tests/unit/**/**.test.js"],
+ },
+ ],
};
module.exports = config;
diff --git a/scripts/tools/add-owner-field.js b/scripts/tools/add-owner-field.js
index 0a13f287..f8c27b44 100644
--- a/scripts/tools/add-owner-field.js
+++ b/scripts/tools/add-owner-field.js
@@ -6,30 +6,29 @@ const { DB_HOST, DB_USER, DB_PASS, DB_DB, DB_PORT, DB_SSL_CERT } =
let sqlStorage;
-const LIMIT = parseInt(process.env.LIMIT ?? '-1', 10);
-const OFFSET = parseInt(process.env.OFFSET ?? '0', 10);
-const VERBOSE = (process.env.VERBOSE ?? '0') !== '0';
+const LIMIT = parseInt(process.env.LIMIT ?? "-1", 10);
+const OFFSET = parseInt(process.env.OFFSET ?? "0", 10);
+const VERBOSE = (process.env.VERBOSE ?? "0") !== "0";
-function log (...args) {
+function log(...args) {
if (!VERBOSE) return;
return console.log(...args);
}
-function debug (...args) {
+function debug(...args) {
if (!VERBOSE) return;
return console.debug(...args);
}
-function warn (...args) {
+function warn(...args) {
if (!VERBOSE) return;
return console.warn(...args);
}
-
-async function init () {
+async function init() {
let allPointers = await getPointers();
let totalPointers = allPointers.length;
- log('Package count:', totalPointers);
+ log("Package count:", totalPointers);
for (let { name, pointer } of allPointers) {
log(`Checking: ${name}::${pointer}`);
@@ -41,9 +40,7 @@ async function init () {
continue;
}
if (typeof pointer !== "string") {
- console.error(
- `The package ${name}::${pointer} likely has been deleted.`
- );
+ console.error(`The package ${name}::${pointer} likely has been deleted.`);
continue;
}
@@ -62,7 +59,9 @@ async function init () {
let parsed = parseGithubUrl(repositoryUrl);
if (parsed === null) {
- console.error(`Could not parse repo URL for package: ${name}: ${repositoryUrl}`);
+ console.error(
+ `Could not parse repo URL for package: ${name}: ${repositoryUrl}`
+ );
continue;
}
@@ -72,7 +71,7 @@ async function init () {
continue;
}
- log('Updating owner field of package:', name);
+ log("Updating owner field of package:", name);
await sqlStorage`
UPDATE packages SET owner = ${owner} WHERE pointer = ${pointer};
`;
@@ -107,7 +106,7 @@ async function getPointers() {
}
async function getPackageData(pointer) {
- console.log('getting package data:', pointer);
+ console.log("getting package data:", pointer);
try {
sqlStorage ??= setupSQL();
diff --git a/src/PackageObject.js b/src/PackageObject.js
index 170e882f..b324fcaa 100644
--- a/src/PackageObject.js
+++ b/src/PackageObject.js
@@ -1,4 +1,4 @@
-const parseGithubUrl = require('parse-github-url');
+const parseGithubUrl = require("parse-github-url");
/**
* @module PackageObject
diff --git a/src/context.js b/src/context.js
index da2fd5aa..863b72c3 100644
--- a/src/context.js
+++ b/src/context.js
@@ -14,5 +14,5 @@ module.exports = {
sso: require("./models/sso.js"),
ssoPaginate: require("./models/ssoPaginate.js"),
ssoRedirect: require("./models/ssoRedirect.js"),
- ssoHTML: require("./models/ssoHTML.js")
+ ssoHTML: require("./models/ssoHTML.js"),
};
diff --git a/src/controllers/deletePackagesPackageName.js b/src/controllers/deletePackagesPackageName.js
index c5e96c7e..63ce0433 100644
--- a/src/controllers/deletePackagesPackageName.js
+++ b/src/controllers/deletePackagesPackageName.js
@@ -7,26 +7,27 @@ module.exports = {
summary: "Delete a package.",
responses: {
204: {
- description: "An empty response, indicating success."
- }
- }
+ description: "An empty response, indicating success.",
+ },
+ },
},
endpoint: {
method: "DELETE",
- paths: [
- "/api/packages/:packageName",
- "/api/themes/:packageName"
- ],
+ paths: ["/api/packages/:packageName", "/api/themes/:packageName"],
rateLimit: "auth",
successStatus: 204,
options: {
Allow: "DELETE, GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- auth: (context, req) => { return context.query.auth(req); },
- packageName: (context, req) => { return context.query.packageName(req); }
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
},
async logic(params, context) {
@@ -35,34 +36,45 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addMessage("Please update your token if you haven't done so recently.")
- .addCalls("auth.verifyAuth", user);
+ return sso
+ .notOk()
+ .addContent(user)
+ .addMessage("Please update your token if you haven't done so recently.")
+ .addCalls("auth.verifyAuth", user);
}
// Lets also first check to make sure the package exists
- const packageExists = await context.database.getPackageByName(params.packageName, true);
+ const packageExists = await context.database.getPackageByName(
+ params.packageName,
+ true
+ );
if (!packageExists.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packageExists)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packageExists);
+ return sso
+ .notOk()
+ .addContent(packageExists)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packageExists);
}
// Get `owner/repo` string format from pacakge
- const ownerRepo = context.utils.getOwnerRepoFromPackage(packageExists.content.data);
+ const ownerRepo = context.utils.getOwnerRepoFromPackage(
+ packageExists.content.data
+ );
const gitowner = await context.vcs.ownership(user.content, ownerRepo);
if (!gitowner.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(gitowner)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packageExists)
- .addCalls("vcs.ownership", gitowner);
+ return sso
+ .notOk()
+ .addContent(gitowner)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packageExists)
+ .addCalls("vcs.ownership", gitowner);
}
// Now they are logged in locally, and have permissions over the GitHub repo
@@ -71,15 +83,17 @@ module.exports = {
if (!rm.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(rm)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packageExists)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("db.removePackageByName", rm);
+ return sso
+ .notOk()
+ .addContent(rm)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packageExists)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("db.removePackageByName", rm);
}
const sso = new context.sso();
return sso.isOk().addContent(false);
- }
+ },
};
diff --git a/src/controllers/deletePackagesPackageNameStar.js b/src/controllers/deletePackagesPackageNameStar.js
index 55b55e94..cb862d3a 100644
--- a/src/controllers/deletePackagesPackageNameStar.js
+++ b/src/controllers/deletePackagesPackageNameStar.js
@@ -7,26 +7,27 @@ module.exports = {
summary: "Unstar a package.",
responses: {
204: {
- description: "An empty response, indicating success."
- }
- }
+ description: "An empty response, indicating success.",
+ },
+ },
},
endpoint: {
method: "DELETE",
- paths: [
- "/api/packages/:packageName/star",
- "/api/themes/:packageName/star"
- ],
+ paths: ["/api/packages/:packageName/star", "/api/themes/:packageName/star"],
rateLimit: "auth",
successStatus: 204,
options: {
Allow: "DELETE, POST",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- auth: (context, req) => { return context.query.auth(req); },
- packageName: (context, req) => { return context.query.packageName(req); }
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
},
async logic(params, context) {
const user = await context.auth.verifyAuth(params.auth, context.database);
@@ -34,22 +35,26 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("auth.verifyAuth", user);
+ return sso.notOk().addContent(user).addCalls("auth.verifyAuth", user);
}
- const unstar = await context.database.updateDecrementStar(user.content, params.packageName);
+ const unstar = await context.database.updateDecrementStar(
+ user.content,
+ params.packageName
+ );
if (!unstar.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(unstar)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.updateDecrementStar", unstar);
+ return sso
+ .notOk()
+ .addContent(unstar)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.updateDecrementStar", unstar);
}
const sso = new context.sso();
return sso.isOk().addContent(false);
- }
+ },
};
diff --git a/src/controllers/deletePackagesPackageNameVersionsVersionName.js b/src/controllers/deletePackagesPackageNameVersionsVersionName.js
index f6205855..d0c25079 100644
--- a/src/controllers/deletePackagesPackageNameVersionsVersionName.js
+++ b/src/controllers/deletePackagesPackageNameVersionsVersionName.js
@@ -4,25 +4,32 @@
module.exports = {
docs: {
- summary: "Deletes a package version. Once a version is deleted, it cannot be used again."
+ summary:
+ "Deletes a package version. Once a version is deleted, it cannot be used again.",
},
endpoint: {
method: "DELETE",
paths: [
"/api/packages/:packageName/versions/:versionName",
- "/api/themes/:packageName/versions/:versionName"
+ "/api/themes/:packageName/versions/:versionName",
],
rateLimit: "auth",
successStatus: 204,
options: {
Allow: "GET, DELETE",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- auth: (context, req) => { return context.query.auth(req); },
- packageName: (context, req) => { return context.query.packageName(req); },
- versionName: (context, req) => { return context.query.engine(req.params.versionName); }
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
+ versionName: (context, req) => {
+ return context.query.engine(req.params.versionName);
+ },
},
async logic(params, context) {
@@ -31,8 +38,10 @@ module.exports = {
if (params.versionName === false) {
const sso = new context.sso();
- return sso.notOk().addShort("not_found")
- .addMessage("The version provided is invalid.");
+ return sso
+ .notOk()
+ .addShort("not_found")
+ .addMessage("The version provided is invalid.");
}
// Verify the user has local and remote permissions
@@ -41,30 +50,39 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("auth.verifyAuth", user);
+ return sso.notOk().addContent(user).addCalls("auth.verifyAuth", user);
}
// Lets also first check to make sure the package exists
- const packageExists = await context.database.getPackageByName(params.packageName, true);
+ const packageExists = await context.database.getPackageByName(
+ params.packageName,
+ true
+ );
if (!packageExists.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packageExists)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packageExists);
+ return sso
+ .notOk()
+ .addContent(packageExists)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packageExists);
}
- const gitowner = await context.vcs.ownership(user.content, packageExists.content);
+ const gitowner = await context.vcs.ownership(
+ user.content,
+ packageExists.content
+ );
if (!gitowner.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(gitowner)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packageExists)
- .addCalls("vcs.ownership", gitowner);
+ return sso
+ .notOk()
+ .addContent(gitowner)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packageExists)
+ .addCalls("vcs.ownership", gitowner);
}
// Mark the specified version for deletion, if version is valid
@@ -76,15 +94,17 @@ module.exports = {
if (!removeVersion.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(removeVersion)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packageExists)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("db.removePackageVersion", removeVersion);
+ return sso
+ .notOk()
+ .addContent(removeVersion)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packageExists)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("db.removePackageVersion", removeVersion);
}
const sso = new context.sso();
return sso.isOk().addContent(false);
- }
+ },
};
diff --git a/src/controllers/getLogin.js b/src/controllers/getLogin.js
index 34aa9e88..59ff8b25 100644
--- a/src/controllers/getLogin.js
+++ b/src/controllers/getLogin.js
@@ -4,18 +4,18 @@
module.exports = {
docs: {
- summary: "OAuth callback URL."
+ summary: "OAuth callback URL.",
},
endpoint: {
method: "GET",
- paths: [ "/api/login" ],
+ paths: ["/api/login"],
rateLimit: "auth",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
+ "X-Content-Type-Options": "nosniff",
},
- endpointKind: "raw"
+ endpointKind: "raw",
},
async logic(req, res, context) {
@@ -32,17 +32,19 @@ module.exports = {
if (!saveStateKey.ok) {
res.status(500).json({
- message: "Application Error: Failed to generate secure state key."
+ message: "Application Error: Failed to generate secure state key.",
});
context.logger.httpLog(req, res);
return;
}
- res.status(302).redirect(
- `https://github.com/login/oauth/authorize?client_id=${context.config.GH_CLIENTID}&redirect_uri=${context.config.GH_REDIRECTURI}&state=${stateKey}&scope=public_repo%20read:org`
- );
+ res
+ .status(302)
+ .redirect(
+ `https://github.com/login/oauth/authorize?client_id=${context.config.GH_CLIENTID}&redirect_uri=${context.config.GH_REDIRECTURI}&state=${stateKey}&scope=public_repo%20read:org`
+ );
context.logger.httpLog(req, res);
return;
- }
+ },
};
diff --git a/src/controllers/getOauth.js b/src/controllers/getOauth.js
index cce376a7..6627f102 100644
--- a/src/controllers/getOauth.js
+++ b/src/controllers/getOauth.js
@@ -6,32 +6,34 @@ const superagent = require("superagent");
module.exports = {
docs: {
- summary: "OAuth Callback URL."
+ summary: "OAuth Callback URL.",
},
endpoint: {
method: "GET",
- paths: [ "/api/oauth" ],
+ paths: ["/api/oauth"],
rateLimit: "auth",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
+ "X-Content-Type-Options": "nosniff",
},
- endpointKind: "raw"
+ endpointKind: "raw",
},
async logic(req, res, context) {
let params = {
state: req.query.state ?? "",
- code: req.query.code ?? ""
+ code: req.query.code ?? "",
};
// First we want to ensure that the received state key is valid
- const validStateKey = await context.database.authCheckAndDeleteStateKey(params.state);
+ const validStateKey = await context.database.authCheckAndDeleteStateKey(
+ params.state
+ );
if (!validStateKey.ok) {
res.status(500).json({
- message: "Application Error: Invalid State Key provided."
+ message: "Application Error: Invalid State Key provided.",
});
context.logger.httpLog(req, res);
return;
@@ -44,85 +46,88 @@ module.exports = {
code: params.code,
redirect_uri: context.config.GH_REDIRECTURI,
client_id: context.config.GH_CLIENTID,
- client_secret: context.config.GH_CLIENTSECRET
+ client_secret: context.config.GH_CLIENTSECRET,
});
- const accessToken = initialAuth.body?.access_token;
+ const accessToken = initialAuth.body?.access_token;
- if (accessToken === null || initialAuth.body?.token_type === null) {
+ if (accessToken === null || initialAuth.body?.token_type === null) {
+ res.status(500).json({
+ message: "Application Error: Authentication to GitHub failed.",
+ });
+ context.logger.httpLog(req, res);
+ return;
+ }
+
+ try {
+ // Request the user data using the access token
+ const userData = await superagent
+ .get("https://api.github.com/user")
+ .set({ Authorization: `Bearer ${accessToken}` })
+ .set({ "User-Agent": context.config.GH_USERAGENT });
+
+ if (userData.status !== 200) {
res.status(500).json({
- message: "Application Error: Authentication to GitHub failed."
+ message: `Application Error: Received HTTP Status ${userData.status}`,
});
context.logger.httpLog(req, res);
return;
}
- try {
- // Request the user data using the access token
- const userData = await superagent
- .get("https://api.github.com/user")
- .set({ Authorization: `Bearer ${accessToken}` })
- .set({ "User-Agent": context.config.GH_USERAGENT });
-
- if (userData.status !== 200) {
- res.status(500).json({
- message: `Application Error: Received HTTP Status ${userData.status}`
- });
- context.logger.httpLog(req, res);
- return;
- }
-
- // Now retrieve the user data that we need to store into the DB
- const username = userData.body.login;
- const userId = userData.body.node_id;
- const userAvatar = userData.body.avatar_url;
-
- const userExists = await context.database.getUserByNodeID(userId);
-
- if (userExists.ok) {
- // This means that the user does in fact already exist.
- // And from there they are likely reauthenticating,
- // But since we don't save any type of auth tokens, the user just needs
- // a new one and we should return their new one to them.
-
- // Now we redirect to the frontend site
- res.redirect(`https://web.pulsar-edit.dev/users?token=${accessToken}`);
- context.logger.httpLog(req, res);
- return;
- }
-
- // The user does not exist, so we save its data into the DB
- let createdUser = await context.database.insertNewUser(
- username,
- userId,
- userAvatar
- );
-
- if (!createdUser.ok) {
- res.status(500).json({
- message: "Application Error: Creating the user account failed!"
- });
- context.logger.httpLog(req, res);
- return;
- }
-
- // Before returning, lets append their access token
- createdUser.content.token = accessToken;
-
- // Now re redirect to the frontend site
- res.redirect(
- `https://web.pulsar-edit.dev/users?token=${createdUser.content.token}`
- );
+ // Now retrieve the user data that we need to store into the DB
+ const username = userData.body.login;
+ const userId = userData.body.node_id;
+ const userAvatar = userData.body.avatar_url;
+
+ const userExists = await context.database.getUserByNodeID(userId);
+
+ if (userExists.ok) {
+ // This means that the user does in fact already exist.
+ // And from there they are likely reauthenticating,
+ // But since we don't save any type of auth tokens, the user just needs
+ // a new one and we should return their new one to them.
+
+ // Now we redirect to the frontend site
+ res.redirect(`https://web.pulsar-edit.dev/users?token=${accessToken}`);
context.logger.httpLog(req, res);
return;
+ }
+
+ // The user does not exist, so we save its data into the DB
+ let createdUser = await context.database.insertNewUser(
+ username,
+ userId,
+ userAvatar
+ );
- } catch(err) {
- context.logger.generic(2, "/api/oauth Caught an Error!", { type: "error", err: err });
+ if (!createdUser.ok) {
res.status(500).json({
- message: "Application Error: The server encountered an error processing the request."
+ message: "Application Error: Creating the user account failed!",
});
context.logger.httpLog(req, res);
return;
}
- }
+
+ // Before returning, lets append their access token
+ createdUser.content.token = accessToken;
+
+ // Now re redirect to the frontend site
+ res.redirect(
+ `https://web.pulsar-edit.dev/users?token=${createdUser.content.token}`
+ );
+ context.logger.httpLog(req, res);
+ return;
+ } catch (err) {
+ context.logger.generic(2, "/api/oauth Caught an Error!", {
+ type: "error",
+ err: err,
+ });
+ res.status(500).json({
+ message:
+ "Application Error: The server encountered an error processing the request.",
+ });
+ context.logger.httpLog(req, res);
+ return;
+ }
+ },
};
diff --git a/src/controllers/getOwnersOwnerName.js b/src/controllers/getOwnersOwnerName.js
index 0dbac251..bbffeefc 100644
--- a/src/controllers/getOwnersOwnerName.js
+++ b/src/controllers/getOwnersOwnerName.js
@@ -5,26 +5,34 @@ module.exports = {
200: {
description: "A paginated response of packages.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/owners/:ownerName" ],
+ paths: ["/api/owners/:ownerName"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- page: (context, req) => { return context.query.page(req); },
- sort: (context, req) => { return context.query.sort(req); },
- direction: (context, req) => { return context.query.direction(req); },
- owner: (context, req) => { return context.query.owner(req); }
+ page: (context, req) => {
+ return context.query.page(req);
+ },
+ sort: (context, req) => {
+ return context.query.sort(req);
+ },
+ direction: (context, req) => {
+ return context.query.direction(req);
+ },
+ owner: (context, req) => {
+ return context.query.owner(req);
+ },
},
async logic(params, context) {
@@ -33,22 +41,31 @@ module.exports = {
if (!packages.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packages).addCalls("db.getSortedPackages", packages);
+ return sso
+ .notOk()
+ .addContent(packages)
+ .addCalls("db.getSortedPackages", packages);
}
const packObjShort = await context.utils.constructPackageObjectShort(
packages.content
);
- const packArray = Array.isArray(packObjShort) ? packObjShort : [ packObjShort ];
+ const packArray = Array.isArray(packObjShort)
+ ? packObjShort
+ : [packObjShort];
const ssoP = new context.ssoPaginate();
ssoP.resultCount = packages.pagination.count;
ssoP.totalPages = packages.pagination.total;
ssoP.limit = packages.pagination.limit;
- ssoP.buildLink(`${context.config.server_url}/api/owners/${params.owner}`, packages.pagination.page, params);
+ ssoP.buildLink(
+ `${context.config.server_url}/api/owners/${params.owner}`,
+ packages.pagination.page,
+ params
+ );
return ssoP.isOk().addContent(packArray);
- }
+ },
};
diff --git a/src/controllers/getPackages.js b/src/controllers/getPackages.js
index f986fe98..4ae11d90 100644
--- a/src/controllers/getPackages.js
+++ b/src/controllers/getPackages.js
@@ -9,32 +9,46 @@ module.exports = {
200: {
description: "An array of packages.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/packages" ],
+ paths: ["/api/packages"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "POST, GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- page: (context, req) => { return context.query.page(req); },
- sort: (context, req) => { return context.query.sort(req); },
- direction: (context, req) => { return context.query.direction(req); },
- serviceType: (context, req) => { return context.query.serviceType(req); },
- service: (context, req) => { return context.query.service(req); },
- serviceVersion: (context, req) => { return context.query.serviceVersion(req); },
- fileExtension: (context, req) => { return context.query.fileExtension(req); },
+ page: (context, req) => {
+ return context.query.page(req);
+ },
+ sort: (context, req) => {
+ return context.query.sort(req);
+ },
+ direction: (context, req) => {
+ return context.query.direction(req);
+ },
+ serviceType: (context, req) => {
+ return context.query.serviceType(req);
+ },
+ service: (context, req) => {
+ return context.query.service(req);
+ },
+ serviceVersion: (context, req) => {
+ return context.query.serviceVersion(req);
+ },
+ fileExtension: (context, req) => {
+ return context.query.fileExtension(req);
+ },
owner: (context, req) => {
return context.query.owner(req);
- }
+ },
},
/**
@@ -52,21 +66,31 @@ module.exports = {
if (!packages.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packages)
- .addCalls("db.getSortedPackages", packages);
+ return sso
+ .notOk()
+ .addContent(packages)
+ .addCalls("db.getSortedPackages", packages);
}
- const packObjShort = await context.utils.constructPackageObjectShort(packages.content);
+ const packObjShort = await context.utils.constructPackageObjectShort(
+ packages.content
+ );
- const packArray = Array.isArray(packObjShort) ? packObjShort : [ packObjShort ];
+ const packArray = Array.isArray(packObjShort)
+ ? packObjShort
+ : [packObjShort];
const ssoP = new context.ssoPaginate();
ssoP.resultCount = packages.pagination.count;
ssoP.totalPages = packages.pagination.total;
ssoP.limit = packages.pagination.limit;
- ssoP.buildLink(`${context.config.server_url}/api/packages`, packages.pagination.page, params);
+ ssoP.buildLink(
+ `${context.config.server_url}/api/packages`,
+ packages.pagination.page,
+ params
+ );
return ssoP.isOk().addContent(packArray);
- }
+ },
};
diff --git a/src/controllers/getPackagesFeatured.js b/src/controllers/getPackagesFeatured.js
index bbbff4a3..963096a7 100644
--- a/src/controllers/getPackagesFeatured.js
+++ b/src/controllers/getPackagesFeatured.js
@@ -9,20 +9,20 @@ module.exports = {
200: {
description: "An array of featured packages.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/packages/featured" ],
+ paths: ["/api/packages/featured"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {},
@@ -39,17 +39,23 @@ module.exports = {
if (!packs.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packs)
- .addCalls("db.getFeaturedPackages", packs);
+ return sso
+ .notOk()
+ .addContent(packs)
+ .addCalls("db.getFeaturedPackages", packs);
}
- const packObjShort = await context.utils.constructPackageObjectShort(packs.content);
+ const packObjShort = await context.utils.constructPackageObjectShort(
+ packs.content
+ );
// The endpoint using this ufnction needs an array
- const packArray = Array.isArray(packObjShort) ? packObjShort : [ packObjShort ];
+ const packArray = Array.isArray(packObjShort)
+ ? packObjShort
+ : [packObjShort];
const sso = new context.sso();
return sso.isOk().addContent(packArray);
- }
+ },
};
diff --git a/src/controllers/getPackagesPackageName.js b/src/controllers/getPackagesPackageName.js
index 60d88ba3..29bada32 100644
--- a/src/controllers/getPackagesPackageName.js
+++ b/src/controllers/getPackagesPackageName.js
@@ -9,27 +9,28 @@ module.exports = {
200: {
description: "A 'Package Object Full' of the requested package.",
content: {
- "application/json": "$packageObjectFull"
- }
- }
- }
+ "application/json": "$packageObjectFull",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [
- "/api/packages/:packageName",
- "/api/themes/:packageName"
- ],
+ paths: ["/api/packages/:packageName", "/api/themes/:packageName"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "DELETE, GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- engine: (context, req) => { return context.query.engine(req.query.engine); },
- packageName: (context, req) => { return context.query.packageName(req); }
+ engine: (context, req) => {
+ return context.query.engine(req.query.engine);
+ },
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
},
/**
@@ -42,13 +43,15 @@ module.exports = {
* @returns {sso}
*/
async logic(params, context) {
- let pack = await context.database.getPackageByName(params.packageName, true);
+ let pack = await context.database.getPackageByName(
+ params.packageName,
+ true
+ );
if (!pack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(pack)
- .addCalls("db.getPackageByName", pack);
+ return sso.notOk().addContent(pack).addCalls("db.getPackageByName", pack);
}
pack = await context.utils.constructPackageObjectFull(pack.content);
@@ -63,5 +66,5 @@ module.exports = {
const sso = new context.sso();
return sso.isOk().addContent(pack);
- }
+ },
};
diff --git a/src/controllers/getPackagesPackageNameStargazers.js b/src/controllers/getPackagesPackageNameStargazers.js
index cf4cd77f..4d4d292d 100644
--- a/src/controllers/getPackagesPackageNameStargazers.js
+++ b/src/controllers/getPackagesPackageNameStargazers.js
@@ -4,23 +4,25 @@
module.exports = {
docs: {
- summary: "List the users that have starred a package."
+ summary: "List the users that have starred a package.",
},
endpoint: {
method: "GET",
paths: [
"/api/packages/:packageName/stargazers",
- "/api/themes/:packageName/stargazers"
+ "/api/themes/:packageName/stargazers",
],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- packageName: (context, req) => { return context.query.packageName(req); }
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
},
/**
@@ -39,18 +41,21 @@ module.exports = {
if (!pack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(pack)
- .addCalls("db.getPackageByName", pack);
+ return sso.notOk().addContent(pack).addCalls("db.getPackageByName", pack);
}
- const stars = await context.database.getStarringUsersByPointer(pack.content);
+ const stars = await context.database.getStarringUsersByPointer(
+ pack.content
+ );
if (!stars.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(stars)
- .addCalls("db.getPackageByName", pack)
- .addCalls("db.getStarringUsersByPointer", stars);
+ return sso
+ .notOk()
+ .addContent(stars)
+ .addCalls("db.getPackageByName", pack)
+ .addCalls("db.getStarringUsersByPointer", stars);
}
const gazers = await context.database.getUserCollectionById(stars.content);
@@ -58,14 +63,16 @@ module.exports = {
if (!gazers.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(gazers)
- .addCalls("db.getPackageByName", pack)
- .addCalls("db.getStarringUsersByPointer", stars)
- .addCalls("db.getUserCollectionById", gazers);
+ return sso
+ .notOk()
+ .addContent(gazers)
+ .addCalls("db.getPackageByName", pack)
+ .addCalls("db.getStarringUsersByPointer", stars)
+ .addCalls("db.getUserCollectionById", gazers);
}
const sso = new context.sso();
return sso.isOk().addContent(gazers.content);
- }
+ },
};
diff --git a/src/controllers/getPackagesPackageNameVersionsVersionName.js b/src/controllers/getPackagesPackageNameVersionsVersionName.js
index 97574d54..c8ae189d 100644
--- a/src/controllers/getPackagesPackageNameVersionsVersionName.js
+++ b/src/controllers/getPackagesPackageNameVersionsVersionName.js
@@ -4,24 +4,28 @@
module.exports = {
docs: {
- summary: "Get the details of a specific package version."
+ summary: "Get the details of a specific package version.",
},
endpoint: {
method: "GET",
paths: [
"/api/packages/:packageName/versions/:versionName",
- "/api/themes/:packageName/versions/:versionName"
+ "/api/themes/:packageName/versions/:versionName",
],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET, DELETE",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- packageName: (context, req) => { return context.query.packageName(req); },
- versionName: (context, req) => { return context.query.engine(req.params.versionName); }
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
+ versionName: (context, req) => {
+ return context.query.engine(req.params.versionName);
+ },
},
/**
@@ -38,8 +42,10 @@ module.exports = {
if (params.versionName === false) {
const sso = new context.sso();
- return sso.notOk().addShort("not_found")
- .addMessage("The version provided is invalid.");
+ return sso
+ .notOk()
+ .addShort("not_found")
+ .addMessage("The version provided is invalid.");
}
// Now we know the version is a valid semver.
@@ -52,14 +58,18 @@ module.exports = {
if (!pack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(pack)
- .addCalls("db.getPackageVersionByNameAndVersion", pack);
+ return sso
+ .notOk()
+ .addContent(pack)
+ .addCalls("db.getPackageVersionByNameAndVersion", pack);
}
- const packRes = await context.utils.constructPackageObjectJSON(pack.content);
+ const packRes = await context.utils.constructPackageObjectJSON(
+ pack.content
+ );
const sso = new context.sso();
return sso.isOk().addContent(packRes);
- }
-}
+ },
+};
diff --git a/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js b/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js
index f32a74b7..01cb4c53 100644
--- a/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js
+++ b/src/controllers/getPackagesPackageNameVersionsVersionNameTarball.js
@@ -6,31 +6,36 @@ const { URL } = require("node:url");
module.exports = {
docs: {
- summary: "Previously undocumented endpoint. Allows for installation of a package.",
+ summary:
+ "Previously undocumented endpoint. Allows for installation of a package.",
responses: [
{
302: {
- description: "Redirect to the GitHub tarball URL."
- }
- }
- ]
+ description: "Redirect to the GitHub tarball URL.",
+ },
+ },
+ ],
},
endpoint: {
method: "GET",
paths: [
"/api/packages/:packageName/versions/:versionName/tarball",
- "/api/themes/:packageName/versions/:versionName/tarball"
+ "/api/themes/:packageName/versions/:versionName/tarball",
],
rateLimit: "generic",
successStatus: 302,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- packageName: (context, req) => { return context.query.packageName(req); },
- versionName: (context, req) => { return context.query.engine(req.params.versionName); }
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
+ versionName: (context, req) => {
+ return context.query.engine(req.params.versionName);
+ },
},
/**
@@ -43,15 +48,16 @@ module.exports = {
* @returns {sso}
*/
async logic(params, context) {
-
// First ensure our version is valid
if (params.versionName === false) {
// since query.engine gives false if invalid, we can check the truthiness
// but returning early uses less compute, as a false version will never be found
const sso = new context.sso();
- return sso.notOk().addShort("not_found")
- .addMessage("The version provided is invalid.");
+ return sso
+ .notOk()
+ .addShort("not_found")
+ .addMessage("The version provided is invalid.");
}
const pack = await context.database.getPackageVersionByNameAndVersion(
@@ -62,16 +68,20 @@ module.exports = {
if (!pack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(pack)
- .addCalls("db.getPackageVersionByNameAndVersion", pack);
+ return sso
+ .notOk()
+ .addContent(pack)
+ .addCalls("db.getPackageVersionByNameAndVersion", pack);
}
- const save = await context.database.updatePackageIncrementDownloadByName(params.packageName);
+ const save = await context.database.updatePackageIncrementDownloadByName(
+ params.packageName
+ );
if (!save.ok) {
context.logger.generic(3, "Failed to Update Downloads Count", {
type: "object",
- obj: save.content
+ obj: save.content,
});
// TODO We will probably want to revisit this after rewriting logging
// We don't want to exit on failed update to download count, only log
@@ -95,29 +105,35 @@ module.exports = {
);
const sso = new context.sso();
- return sso.notOk().addContent(err)
- .addShort("server_error")
- .addMessage(`The URL to download this package seems invalid: ${tarballURL}.`);
+ return sso
+ .notOk()
+ .addContent(err)
+ .addShort("server_error")
+ .addMessage(
+ `The URL to download this package seems invalid: ${tarballURL}.`
+ );
}
const allowedHostnames = [
"codeload.github.com",
"api.github.com",
"github.com",
- "raw.githubusercontent.com"
+ "raw.githubusercontent.com",
];
if (
!allowedHostnames.includes(hostname) &&
- process.env.PULSAR_STATUS !== "dev"
+ process.env.PULSAR_STATUS !== "dev"
) {
const sso = new context.sso();
- return sso.notOk().addShort("server_error")
- .addMessage(`Invalid Domain for Download Redirect: ${hostname}`);
+ return sso
+ .notOk()
+ .addShort("server_error")
+ .addMessage(`Invalid Domain for Download Redirect: ${hostname}`);
}
const sso = new context.ssoRedirect();
return sso.isOk().addContent(tarballURL);
- }
+ },
};
diff --git a/src/controllers/getPackagesSearch.js b/src/controllers/getPackagesSearch.js
index 418a61d7..760b95dd 100644
--- a/src/controllers/getPackagesSearch.js
+++ b/src/controllers/getPackagesSearch.js
@@ -9,27 +9,37 @@ module.exports = {
200: {
description: "Any array of packages.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/packages/search" ],
+ paths: ["/api/packages/search"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- sort: (context, req) => { return context.query.sort(req); },
- page: (context, req) => { return context.query.page(req); },
- direction: (context, req) => { return context.query.direction(req); },
- query: (context, req) => { return context.query.query(req); },
- filter: (context, req) => { return context.query.filter(req); }
+ sort: (context, req) => {
+ return context.query.sort(req);
+ },
+ page: (context, req) => {
+ return context.query.page(req);
+ },
+ direction: (context, req) => {
+ return context.query.direction(req);
+ },
+ query: (context, req) => {
+ return context.query.query(req);
+ },
+ filter: (context, req) => {
+ return context.query.filter(req);
+ },
},
/**
@@ -53,7 +63,7 @@ module.exports = {
params.page,
params.direction,
params.sort,
- (params.filter === "theme")
+ params.filter === "theme"
);
if (!packs.ok) {
@@ -72,11 +82,12 @@ module.exports = {
const sso = new context.sso();
- return sso.notOk().addContent(packs)
- .addCalls("db.simpleSearch", packs);
+ return sso.notOk().addContent(packs).addCalls("db.simpleSearch", packs);
}
- const newPacks = await context.utils.constructPackageObjectShort(packs.content);
+ const newPacks = await context.utils.constructPackageObjectShort(
+ packs.content
+ );
let packArray = null;
@@ -96,8 +107,12 @@ module.exports = {
ssoP.resultCount = packs.pagination.count;
ssoP.totalPages = packs.pagination.total;
ssoP.limit = packs.pagination.limit;
- ssoP.buildLink(`${context.config.server_url}/api/packages/search`, packs.pagination.page, params);
+ ssoP.buildLink(
+ `${context.config.server_url}/api/packages/search`,
+ packs.pagination.page,
+ params
+ );
return ssoP.isOk().addContent(packArray);
- }
+ },
};
diff --git a/src/controllers/getPat.js b/src/controllers/getPat.js
index fdec38f0..a4226e99 100644
--- a/src/controllers/getPat.js
+++ b/src/controllers/getPat.js
@@ -6,28 +6,28 @@ const superagent = require("superagent");
module.exports = {
docs: {
- summary: "PAT Token Signup URL."
+ summary: "PAT Token Signup URL.",
},
endpoint: {
method: "GET",
- paths: [ "/api/pat" ],
+ paths: ["/api/pat"],
rateLimit: "auth",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
+ "X-Content-Type-Options": "nosniff",
},
- endpointKind: "raw"
+ endpointKind: "raw",
},
async logic(req, res, context) {
let params = {
- token: req.query.token ?? ""
+ token: req.query.token ?? "",
};
if (params.token === "") {
res.status(404).json({
- message: "Not Found: Parameter 'token' is empty."
+ message: "Not Found: Parameter 'token' is empty.",
});
context.logger.httpLog(req, res);
return;
@@ -42,10 +42,10 @@ module.exports = {
if (userData.status !== 200) {
context.logger.generic(2, "User Data request to GitHub failed!", {
type: "object",
- obj: userData
+ obj: userData,
});
res.status(500).json({
- message: `Application Error: Received HTTP Status ${userData.status} when contacting GitHub!`
+ message: `Application Error: Received HTTP Status ${userData.status} when contacting GitHub!`,
});
context.logger.httpLog(req, res);
return;
@@ -76,7 +76,7 @@ module.exports = {
if (!createdUser.ok) {
context.logger.generic(2, `Creating user failed! ${username}`);
res.status(500).json({
- message: "Application Error: Creating the user account failed!"
+ message: "Application Error: Creating the user account failed!",
});
context.logger.httpLog(req, res);
return;
@@ -90,13 +90,17 @@ module.exports = {
);
context.logger.httpLog(req, res);
return;
- } catch(err) {
- context.logger.generic(2, "/api/pat Caught an Error!", { type: "error", err: err });
+ } catch (err) {
+ context.logger.generic(2, "/api/pat Caught an Error!", {
+ type: "error",
+ err: err,
+ });
res.status(500).json({
- message: "Application Error: The server encountered an error processing the request."
+ message:
+ "Application Error: The server encountered an error processing the request.",
});
context.logger.httpLog(req, res);
return;
}
- }
+ },
};
diff --git a/src/controllers/getRoot.js b/src/controllers/getRoot.js
index d77f357c..000f1467 100644
--- a/src/controllers/getRoot.js
+++ b/src/controllers/getRoot.js
@@ -4,17 +4,18 @@
module.exports = {
docs: {
- summary: "Non-Essential endpoint to return status message, and link to Swagger Instance."
+ summary:
+ "Non-Essential endpoint to return status message, and link to Swagger Instance.",
},
endpoint: {
method: "GET",
- paths: [ "/" ],
+ paths: ["/"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {},
async logic(params, context) {
@@ -27,5 +28,5 @@ module.exports = {
const sso = new context.ssoHTML();
return sso.isOk().addContent(str);
- }
+ },
};
diff --git a/src/controllers/getStars.js b/src/controllers/getStars.js
index 7115043d..28932788 100644
--- a/src/controllers/getStars.js
+++ b/src/controllers/getStars.js
@@ -1,31 +1,34 @@
/**
* @module getStars
*/
-
+
module.exports = {
docs: {
summary: "List the authenticated users' starred packages.",
responses: [
{
200: {
- description: "Return a value similar to `GET /api/packages`, an array of package objects.",
- content: {}
- }
- }
- ]
+ description:
+ "Return a value similar to `GET /api/packages`, an array of package objects.",
+ content: {},
+ },
+ },
+ ],
},
endpoint: {
method: "GET",
- paths: [ "/api/stars" ],
+ paths: ["/api/stars"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- auth: (context, req) => { return context.query.auth(req); }
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
},
/**
@@ -40,19 +43,25 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addMessage("Please update your token if you haven't done so recently.")
- .addCalls("auth.verifyAuth", user);
+ return sso
+ .notOk()
+ .addContent(user)
+ .addMessage("Please update your token if you haven't done so recently.")
+ .addCalls("auth.verifyAuth", user);
}
- let userStars = await context.database.getStarredPointersByUserID(user.content.id);
+ let userStars = await context.database.getStarredPointersByUserID(
+ user.content.id
+ );
if (!userStars.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(userStars)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getStarredPointersByUserID", userStars);
+ return sso
+ .notOk()
+ .addContent(userStars)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getStarredPointersByUserID", userStars);
}
if (userStars.content.length === 0) {
@@ -64,21 +73,27 @@ module.exports = {
return sso.isOk().addContent([]);
}
- let packCol = await context.database.getPackageCollectionByID(userStars.content);
+ let packCol = await context.database.getPackageCollectionByID(
+ userStars.content
+ );
if (!packCol.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packCol)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getStarredPointersByUserID", userStars)
- .addCalls("db.getPackageCollectionByID", packCol);
+ return sso
+ .notOk()
+ .addContent(packCol)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getStarredPointersByUserID", userStars)
+ .addCalls("db.getPackageCollectionByID", packCol);
}
- let newCol = await context.utils.constructPackageObjectShort(packCol.content);
+ let newCol = await context.utils.constructPackageObjectShort(
+ packCol.content
+ );
const sso = new context.sso();
return sso.isOk().addContent(newCol);
- }
+ },
};
diff --git a/src/controllers/getThemes.js b/src/controllers/getThemes.js
index 0f452cf9..2d18457d 100644
--- a/src/controllers/getThemes.js
+++ b/src/controllers/getThemes.js
@@ -9,25 +9,31 @@ module.exports = {
200: {
description: "A paginated response of themes.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/themes" ],
+ paths: ["/api/themes"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "POST, GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- page: (context, req) => { return context.query.page(req); },
- sort: (context, req) => { return context.query.sort(req); },
- direction: (context, req) => { return context.query.direction(req); }
+ page: (context, req) => {
+ return context.query.page(req);
+ },
+ sort: (context, req) => {
+ return context.query.sort(req);
+ },
+ direction: (context, req) => {
+ return context.query.direction(req);
+ },
},
/**
@@ -39,28 +45,36 @@ module.exports = {
* @returns {object} ssoPaginate
*/
async logic(params, context) {
-
const packages = await context.database.getSortedPackages(params, true);
if (!packages.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packages).addCalls("db.getSortedPackages", packages);
+ return sso
+ .notOk()
+ .addContent(packages)
+ .addCalls("db.getSortedPackages", packages);
}
const packObjShort = await context.utils.constructPackageObjectShort(
packages.content
);
- const packArray = Array.isArray(packObjShort) ? packObjShort : [ packObjShort ];
+ const packArray = Array.isArray(packObjShort)
+ ? packObjShort
+ : [packObjShort];
const ssoP = new context.ssoPaginate();
ssoP.resultCount = packages.pagination.count;
ssoP.totalPages = packages.pagination.total;
ssoP.limit = packages.pagination.limit;
- ssoP.buildLink(`${context.config.server_url}/api/themes`, packages.pagination.page, params);
+ ssoP.buildLink(
+ `${context.config.server_url}/api/themes`,
+ packages.pagination.page,
+ params
+ );
return ssoP.isOk().addContent(packArray);
- }
+ },
};
diff --git a/src/controllers/getThemesFeatured.js b/src/controllers/getThemesFeatured.js
index 6bc83646..a71222a1 100644
--- a/src/controllers/getThemesFeatured.js
+++ b/src/controllers/getThemesFeatured.js
@@ -9,20 +9,20 @@ module.exports = {
200: {
description: "An array of featured themes.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/themes/featured" ],
+ paths: ["/api/themes/featured"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
// Currently we don't seem to utilize any query parameters here.
@@ -42,5 +42,5 @@ module.exports = {
const sso = new context.sso();
return sso.isOk().addContent(newCol);
- }
+ },
};
diff --git a/src/controllers/getThemesSearch.js b/src/controllers/getThemesSearch.js
index 82733f36..1dcc9681 100644
--- a/src/controllers/getThemesSearch.js
+++ b/src/controllers/getThemesSearch.js
@@ -9,26 +9,34 @@ module.exports = {
200: {
description: "A paginated response of themes.",
content: {
- "application/json": "$packageObjectShortArray"
- }
- }
- }
+ "application/json": "$packageObjectShortArray",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/themes/search" ],
+ paths: ["/api/themes/search"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- sort: (context, req) => { return context.query.sort(req); },
- page: (context, req) => { return context.query.page(req); },
- direction: (context, req) => { return context.query.direction(req); },
- query: (context, req) => { return context.query.query(req); }
+ sort: (context, req) => {
+ return context.query.sort(req);
+ },
+ page: (context, req) => {
+ return context.query.page(req);
+ },
+ direction: (context, req) => {
+ return context.query.direction(req);
+ },
+ query: (context, req) => {
+ return context.query.query(req);
+ },
},
async logic(params, context) {
@@ -43,11 +51,12 @@ module.exports = {
if (!packs.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packs)
- .addCalls("db.simpleSearch", packs);
+ return sso.notOk().addContent(packs).addCalls("db.simpleSearch", packs);
}
- const newPacks = await context.utils.constructPackageObjectShort(packs.content);
+ const newPacks = await context.utils.constructPackageObjectShort(
+ packs.content
+ );
let packArray = null;
@@ -56,15 +65,19 @@ module.exports = {
} else if (Object.keys(newPacks).length < 1) {
packArray = [];
} else {
- packArray = [ newPacks ];
+ packArray = [newPacks];
}
const ssoP = new context.ssoPaginate();
ssoP.total = packs.pagination.total;
ssoP.limit = packs.pagination.limit;
- ssoP.buildLink(`${context.config.server_url}/api/themes/search`, packs.pagination.page, params);
+ ssoP.buildLink(
+ `${context.config.server_url}/api/themes/search`,
+ packs.pagination.page,
+ params
+ );
return ssoP.isOk().addContent(packArray);
- }
+ },
};
diff --git a/src/controllers/getUpdates.js b/src/controllers/getUpdates.js
index e8104195..1615f08b 100644
--- a/src/controllers/getUpdates.js
+++ b/src/controllers/getUpdates.js
@@ -1,29 +1,31 @@
/**
* @module getUpdates
*/
-
+
module.exports = {
docs: {
summary: "List Pulsar Updates",
- description: "Currently returns 'Not Implemented' as Squirrel AutoUpdate is not supported.",
+ description:
+ "Currently returns 'Not Implemented' as Squirrel AutoUpdate is not supported.",
responses: [
{
200: {
- description: "Atom update feed, following the format expected by Squirrel.",
- content: {}
- }
- }
- ]
+ description:
+ "Atom update feed, following the format expected by Squirrel.",
+ content: {},
+ },
+ },
+ ],
},
endpoint: {
method: "GET",
- paths: [ "/api/updates" ],
+ paths: ["/api/updates"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {},
@@ -38,5 +40,5 @@ module.exports = {
const sso = new context.sso();
return sso.notOk().addShort("not_supported");
- }
+ },
};
diff --git a/src/controllers/getUsers.js b/src/controllers/getUsers.js
index ee0c8ba1..5a8a0a73 100644
--- a/src/controllers/getUsers.js
+++ b/src/controllers/getUsers.js
@@ -4,36 +4,44 @@
module.exports = {
docs: {
- summary: "Display details of the currently authenticated user. This endpoint is undocumented and is somewhat strange.",
- description: "This endpoint only exists on the web version of the upstream API. Having no backend equivolent.",
+ summary:
+ "Display details of the currently authenticated user. This endpoint is undocumented and is somewhat strange.",
+ description:
+ "This endpoint only exists on the web version of the upstream API. Having no backend equivolent.",
responses: {
200: {
description: "Details of the Authenticated User Account.",
content: {
- "application/json": "$userObjectPrivate"
- }
- }
- }
+ "application/json": "$userObjectPrivate",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/users" ],
+ paths: ["/api/users"],
rateLimit: "auth",
successStatus: 200,
options: {
Allow: "GET",
"Access-Control-Allow-Methods": "GET",
- "Access-Control-Allow-Headers": "Content-Type, Authorization, Access-Control-Allow-Credentials",
+ "Access-Control-Allow-Headers":
+ "Content-Type, Authorization, Access-Control-Allow-Credentials",
"Access-Control-Allow-Origin": "https://web.pulsar-edit.dev",
- "Access-Control-Allow-Credentials": true
- }
+ "Access-Control-Allow-Credentials": true,
+ },
},
params: {
- auth: (context, req) => { return context.query.auth(req); }
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
},
async preLogic(req, res, context) {
res.header("Access-Control-Allow-Methods", "GET");
- res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, Access-Control-Allow-Credentials");
+ res.header(
+ "Access-Control-Allow-Headers",
+ "Content-Type, Authorization, Access-Control-Allow-Credentials"
+ );
res.header("Access-Control-Allow-Origin", "https://web.pulsar-edit.dev");
res.header("Access-Control-Allow-Credentials", true);
},
@@ -52,8 +60,7 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("auth.verifyAuth", user);
+ return sso.notOk().addContent(user).addCalls("auth.verifyAuth", user);
}
// TODO We need to find a way to add the users published pacakges here
@@ -74,5 +81,5 @@ module.exports = {
const sso = new context.sso();
return sso.isOk().addContent(returnUser);
- }
+ },
};
diff --git a/src/controllers/getUsersLogin.js b/src/controllers/getUsersLogin.js
index b1af684c..2f97bc40 100644
--- a/src/controllers/getUsersLogin.js
+++ b/src/controllers/getUsersLogin.js
@@ -4,35 +4,38 @@
module.exports = {
docs: {
- summary: "Display the details of any user, as well as the packages they have published.",
+ summary:
+ "Display the details of any user, as well as the packages they have published.",
responses: {
200: {
description: "The public details of a specific user.",
content: {
// This references the file name of a `./tests/models` model
- "application/json": "$userObjectPublic"
- }
+ "application/json": "$userObjectPublic",
+ },
},
404: {
description: "The User requested cannot be found.",
content: {
- "application/json": "$message"
- }
- }
- }
+ "application/json": "$message",
+ },
+ },
+ },
},
endpoint: {
method: "GET",
- paths: [ "/api/users/:login" ],
+ paths: ["/api/users/:login"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- login: (context, req) => { return context.query.login(req); }
+ login: (context, req) => {
+ return context.query.login(req);
+ },
},
/**
@@ -47,8 +50,7 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("db.getUserByName", user);
+ return sso.notOk().addContent(user).addCalls("db.getUserByName", user);
}
// TODO We need to find a way to add the users published pacakges here
@@ -65,9 +67,8 @@ module.exports = {
packages: [], // included as it should be used in the future
};
-
const sso = new context.sso();
return sso.isOk().addContent(returnUser);
- }
+ },
};
diff --git a/src/controllers/getUsersLoginStars.js b/src/controllers/getUsersLoginStars.js
index 48536e75..7fec8291 100644
--- a/src/controllers/getUsersLoginStars.js
+++ b/src/controllers/getUsersLoginStars.js
@@ -1,7 +1,7 @@
/**
* @module getUsersLoginStars
*/
-
+
module.exports = {
docs: {
summary: "List a user's starred packages.",
@@ -9,23 +9,25 @@ module.exports = {
{
200: {
description: "Return value is similar to `GET /api/packages`.",
- content: {}
- }
- }
- ]
+ content: {},
+ },
+ },
+ ],
},
endpoint: {
method: "GET",
- paths: [ "/api/users/:login/stars" ],
+ paths: ["/api/users/:login/stars"],
rateLimit: "generic",
successStatus: 200,
options: {
Allow: "GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- login: (context, req) => { return context.query.login(req); }
+ login: (context, req) => {
+ return context.query.login(req);
+ },
},
async logic(params, context) {
const user = await context.database.getUserByName(params.login);
@@ -33,18 +35,21 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("db.getUserByName", user);
+ return sso.notOk().addContent(user).addCalls("db.getUserByName", user);
}
- let pointerCollection = await context.database.getStarredPointersByUserID(user.content.id);
+ let pointerCollection = await context.database.getStarredPointersByUserID(
+ user.content.id
+ );
if (!pointerCollection.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(pointerCollection)
- .addCalls("db.getUserByName", user)
- .addCalls("db.getStarredPointersByUserID", pointerCollection);
+ return sso
+ .notOk()
+ .addContent(pointerCollection)
+ .addCalls("db.getUserByName", user)
+ .addCalls("db.getStarredPointersByUserID", pointerCollection);
}
// Since even if the pointerCollection is okay, it could be empty. Meaning the user
@@ -69,16 +74,20 @@ module.exports = {
if (!packageCollection.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packageCollection)
- .addCalls("db.getUserByName", user)
- .addCalls("db.getStarredPointersByUserID", pointerCollection)
- .addCalls("db.getPackageCollectionByID", packageCollection);
+ return sso
+ .notOk()
+ .addContent(packageCollection)
+ .addCalls("db.getUserByName", user)
+ .addCalls("db.getStarredPointersByUserID", pointerCollection)
+ .addCalls("db.getPackageCollectionByID", packageCollection);
}
- packageCollection = await utils.constructPackageObjectShort(packageCollection.content);
+ packageCollection = await utils.constructPackageObjectShort(
+ packageCollection.content
+ );
const sso = new context.sso();
return sso.isOk().addContent(packageCollection);
- }
+ },
};
diff --git a/src/controllers/postPackages.js b/src/controllers/postPackages.js
index 08dcf443..74156774 100644
--- a/src/controllers/postPackages.js
+++ b/src/controllers/postPackages.js
@@ -4,28 +4,32 @@
module.exports = {
docs: {
- summary: "Publishes a new Package."
+ summary: "Publishes a new Package.",
},
endpoint: {
method: "POST",
- paths: [
- "/api/packages",
- "/api/themes"
- ],
+ paths: ["/api/packages", "/api/themes"],
rateLimit: "auth",
successStatus: 201,
options: {
Allow: "POST, GET",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- repository: (context, req) => { return context.query.repo(req); },
- auth: (context, req) => { return context.query.auth(req); }
+ repository: (context, req) => {
+ return context.query.repo(req);
+ },
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
},
async postReturnHTTP(req, res, context, obj) {
// Return to user before wbehook call, so user doesn't wait on it
- await context.webhook.alertPublishPackage(obj.webhook.pack, obj.webhook.user);
+ await context.webhook.alertPublishPackage(
+ obj.webhook.pack,
+ obj.webhook.user
+ );
// Now to call for feature detection
let features = await context.vcs.featureDetection(
obj.featureDetection.user,
@@ -65,8 +69,7 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("auth.verifyAuth", user);
+ return sso.notOk().addContent(user).addCalls("auth.verifyAuth", user);
}
// Check repository format validity.
@@ -74,8 +77,10 @@ module.exports = {
// repository format is invalid
const sso = new context.sso();
- return sso.notOk().addShort("bad_repo")
- .addMessage("Repository is missing.");
+ return sso
+ .notOk()
+ .addShort("bad_repo")
+ .addMessage("Repository is missing.");
}
// Currently though the repository is in `owner/repo` format,
@@ -86,8 +91,10 @@ module.exports = {
if (repo === undefined) {
const sso = new context.sso();
- return sso.notOk().addShort("bad_repo")
- .addMessage("Repository format is invalid.");
+ return sso
+ .notOk()
+ .addShort("bad_repo")
+ .addMessage("Repository format is invalid.");
}
// Now check if the name is banned.
@@ -97,20 +104,27 @@ module.exports = {
// The package name is banned
const sso = new context.sso();
- return sso.notOk().addShort("server_error")
- .addMessage("This package name is banned.");
+ return sso
+ .notOk()
+ .addShort("server_error")
+ .addMessage("This package name is banned.");
}
// Now we know the package doesn't exist. And we want to check that the user
// has permissions to this package
- const gitowner = await context.vcs.ownership(user.content, params.repository);
+ const gitowner = await context.vcs.ownership(
+ user.content,
+ params.repository
+ );
if (!gitowner.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(gitowner)
- .addCalls("auth.verifyAuth", user)
- .addCalls("vcs.ownership", gitowner);
+ return sso
+ .notOk()
+ .addContent(gitowner)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("vcs.ownership", gitowner);
}
// Now knowing they own the git repo, and it doesn't exist here, lets publish.
@@ -124,15 +138,19 @@ module.exports = {
if (!newPack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(newPack)
- .addCalls("auth.verifyAuth", user)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("vcs.newPackageData", newPack);
+ return sso
+ .notOk()
+ .addContent(newPack)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("vcs.newPackageData", newPack);
}
// Now that we have the name the package will actually take, we want
// to make sure this doesn't exist
- const nameAvailable = await context.database.packageNameAvailability(newPack.content.name);
+ const nameAvailable = await context.database.packageNameAvailability(
+ newPack.content.name
+ );
if (!nameAvailable.ok) {
// We need to ensure the error is not found or otherwise
@@ -140,52 +158,65 @@ module.exports = {
// the server failed for some other bubbled reason
const sso = new context.sso();
- return sso.notOk().addContent(nameAvailable)
- .addCalls("auth.verifyAuth", user)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("vcs.newPackageData", newPack)
- .addCalls("db.packageNameAvailability", nameAvailable);
+ return sso
+ .notOk()
+ .addContent(nameAvailable)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("vcs.newPackageData", newPack)
+ .addCalls("db.packageNameAvailability", nameAvailable);
}
// But if the short is in fact "not_found" we can report the package as
// not being available at this name
const sso = new context.sso();
- return sso.notOk().addShort("package_exists")
- .addCalls("auth.verifyAuth", user)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("vcs.newPackageData", newPack)
- .addCalls("db.packageNameAvailability", nameAvailable);
+ return sso
+ .notOk()
+ .addShort("package_exists")
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("vcs.newPackageData", newPack)
+ .addCalls("db.packageNameAvailability", nameAvailable);
}
// Now with valid package data, we can insert them into the DB
- const insertedNewPack = await context.database.insertNewPackage(newPack.content);
+ const insertedNewPack = await context.database.insertNewPackage(
+ newPack.content
+ );
if (!insertedNewPack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(insertedNewPack)
- .addCalls("auth.verifyAuth", user)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("vcs.newPackageData", newPack)
- .addCalls("db.packageNameAvailability", nameAvailable)
- .addCalls("db.insertNewPackage", insertedNewPack);
+ return sso
+ .notOk()
+ .addContent(insertedNewPack)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("vcs.newPackageData", newPack)
+ .addCalls("db.packageNameAvailability", nameAvailable)
+ .addCalls("db.insertNewPackage", insertedNewPack);
}
// Finally we can return what was actually put into the databse.
// Retreive the data from database.getPackageByName() and
// convert it inot a package object full format
- const newDbPack = await context.database.getPackageByName(newPack.content.name, true);
+ const newDbPack = await context.database.getPackageByName(
+ newPack.content.name,
+ true
+ );
if (!newDbPack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(newDbPack)
- .addCalls("auth.verifyAuth", user)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("vcs.newPackageData", newPack)
- .addCalls("db.insertNewPackage", insertedNewPack)
- .addCalls("db.packageNameAvailability", nameAvailable)
- .addCalls("db.getPackageByName", newDbPack);
+ return sso
+ .notOk()
+ .addContent(newDbPack)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("vcs.newPackageData", newPack)
+ .addCalls("db.insertNewPackage", insertedNewPack)
+ .addCalls("db.packageNameAvailability", nameAvailable)
+ .addCalls("db.getPackageByName", newDbPack);
}
const packageObjectFull = await context.utils.constructPackageObjectFull(
@@ -198,15 +229,15 @@ module.exports = {
sso.webhook = {
pack: packageObjectFull,
- user: user.content
+ user: user.content,
};
sso.featureDetection = {
user: user.content,
service: "git", // TODO stop hardcoding git
- ownerRepo: params.repository
+ ownerRepo: params.repository,
};
return sso.isOk().addContent(packageObjectFull);
- }
+ },
};
diff --git a/src/controllers/postPackagesPackageNameStar.js b/src/controllers/postPackagesPackageNameStar.js
index ebe0cd99..205a99bd 100644
--- a/src/controllers/postPackagesPackageNameStar.js
+++ b/src/controllers/postPackagesPackageNameStar.js
@@ -9,27 +9,28 @@ module.exports = {
200: {
description: "A 'Package Object Full' of the modified package",
content: {
- "application/json": "$packageObjectFull"
- }
- }
- }
+ "application/json": "$packageObjectFull",
+ },
+ },
+ },
},
endpoint: {
method: "POST",
- paths: [
- "/api/packages/:packageName/star",
- "/api/themes/:packageName/star"
- ],
+ paths: ["/api/packages/:packageName/star", "/api/themes/:packageName/star"],
rateLimit: "auth",
successStatus: 200,
options: {
Allow: "DELETE, POST",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- auth: (context, req) => { return context.query.auth(req); },
- packageName: (context, req) => { return context.query.packageName(req); }
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
},
async logic(params, context) {
const user = await context.auth.verifyAuth(params.auth, context.database);
@@ -37,30 +38,39 @@ module.exports = {
if (!user.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(user)
- .addCalls("auth.verifyAuth", user);
+ return sso.notOk().addContent(user).addCalls("auth.verifyAuth", user);
}
- const star = await context.database.updateIncrementStar(user.content, params.packageName);
+ const star = await context.database.updateIncrementStar(
+ user.content,
+ params.packageName
+ );
if (!star.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(star)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.updateIncrementStar", star);
+ return sso
+ .notOk()
+ .addContent(star)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.updateIncrementStar", star);
}
// Now with a success we want to return the package back in this query
- let pack = await context.database.getPackageByName(params.packageName, true);
+ let pack = await context.database.getPackageByName(
+ params.packageName,
+ true
+ );
if (!pack.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(pack)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.updateIncrementStar", star)
- .addCalls("db.getPackageByName", pack);
+ return sso
+ .notOk()
+ .addContent(pack)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.updateIncrementStar", star)
+ .addCalls("db.getPackageByName", pack);
}
pack = await context.utils.constructPackageObjectFull(pack.content);
@@ -68,5 +78,5 @@ module.exports = {
const sso = new context.sso();
return sso.isOk().addContent(pack);
- }
+ },
};
diff --git a/src/controllers/postPackagesPackageNameVersions.js b/src/controllers/postPackagesPackageNameVersions.js
index ed79d603..7ceba37f 100644
--- a/src/controllers/postPackagesPackageNameVersions.js
+++ b/src/controllers/postPackagesPackageNameVersions.js
@@ -4,29 +4,38 @@
module.exports = {
docs: {
- summary: "Creates a new package version."
+ summary: "Creates a new package version.",
},
endpoint: {
method: "POST",
paths: [
"/api/packages/:packageName/versions",
- "/api/themes/:packageName/versions"
+ "/api/themes/:packageName/versions",
],
rateLimit: "auth",
successStatus: 201,
options: {
Allow: "POST",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {
- rename: (context, req) => { return context.query.rename(req); },
- auth: (context, req) => { return context.query.auth(req); },
- packageName: (context, req) => { return context.query.packageName(req); }
+ rename: (context, req) => {
+ return context.query.rename(req);
+ },
+ auth: (context, req) => {
+ return context.query.auth(req);
+ },
+ packageName: (context, req) => {
+ return context.query.packageName(req);
+ },
},
async postReturnHTTP(req, res, context, obj) {
// We use postReturnHTTP to ensure the user doesn't wait on these other actions
- await context.webhook.alertPublishVersion(obj.webhook.pack, obj.webhook.user);
+ await context.webhook.alertPublishVersion(
+ obj.webhook.pack,
+ obj.webhook.user
+ );
// Now to call for feature detection
let features = await context.vcs.featureDetection(
@@ -75,10 +84,14 @@ module.exports = {
// TODO LOG
const sso = new context.sso();
- return sso.notOk().addShort("unauthorized")
- .addContent(user)
- .addCalls("auth.verifyAuth", user)
- .addMessage("User Authentication Failed when attempting to publish package version!");
+ return sso
+ .notOk()
+ .addShort("unauthorized")
+ .addContent(user)
+ .addCalls("auth.verifyAuth", user)
+ .addMessage(
+ "User Authentication Failed when attempting to publish package version!"
+ );
}
context.logger.generic(
@@ -90,33 +103,48 @@ module.exports = {
// packages new name. Which means we have to check if they have ownership AFTER
// we collect it's data.
- const packExists = await context.database.getPackageByName(params.packageName, true);
+ const packExists = await context.database.getPackageByName(
+ params.packageName,
+ true
+ );
if (!packExists.ok) {
// TODO LOG
const sso = new context.sso();
- return sso.notOk().addShort("not_found")
- .addContent(packExists)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addMessage("The server was unable to locate your package when publishing a new version.");
+ return sso
+ .notOk()
+ .addShort("not_found")
+ .addContent(packExists)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addMessage(
+ "The server was unable to locate your package when publishing a new version."
+ );
}
// Get `owner/repo` string format from package.
- let ownerRepo = context.utils.getOwnerRepoFromPackage(packExists.content.data);
+ let ownerRepo = context.utils.getOwnerRepoFromPackage(
+ packExists.content.data
+ );
// Using our new VCS Service
// TODO: The "git" service shouldn't always be hardcoded.
- let packMetadata = await context.vcs.newVersionData(user.content, ownerRepo, "git");
+ let packMetadata = await context.vcs.newVersionData(
+ user.content,
+ ownerRepo,
+ "git"
+ );
if (!packMetadata.ok) {
const sso = new context.sso();
- return sso.notOk().addContent(packMetadata)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addCalls("vcs.newVersionData", packMetadata);
+ return sso
+ .notOk()
+ .addContent(packMetadata)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addCalls("vcs.newVersionData", packMetadata);
}
const newName = packMetadata.content.name;
@@ -125,11 +153,15 @@ module.exports = {
if (newName !== currentName && !params.rename) {
const sso = new context.sso();
- return sso.notOk().addShort("bad_repo")
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addCalls("vcs.newVersionData", packMetadata)
- .addMessage("Package name doesn't match local name, with rename false.");
+ return sso
+ .notOk()
+ .addShort("bad_repo")
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addCalls("vcs.newVersionData", packMetadata)
+ .addMessage(
+ "Package name doesn't match local name, with rename false."
+ );
}
// Else we will continue, and trust the name provided from the package as being accurate.
@@ -138,18 +170,23 @@ module.exports = {
// By passing `packMetadata` explicitely, it ensures that data we use to check
// ownership is fresh, allowing for things like a package rename.
- const gitowner = await context.vcs.ownership(user.content, packMetadata.content);
+ const gitowner = await context.vcs.ownership(
+ user.content,
+ packMetadata.content
+ );
if (!gitowner.ok) {
const sso = new context.sso();
- return sso.notOk().addShort("unauthorized")
- .addContent(gitowner)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addCalls("vcs.newVersionData", packMetadata)
- .addCalls("vcs.ownership", gitowner)
- .addMessage("User failed git ownership check!");
+ return sso
+ .notOk()
+ .addShort("unauthorized")
+ .addContent(gitowner)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addCalls("vcs.newVersionData", packMetadata)
+ .addCalls("vcs.ownership", gitowner)
+ .addMessage("User failed git ownership check!");
}
// Now the only thing left to do, is add this new version with the name from the package.
@@ -164,28 +201,34 @@ module.exports = {
if (isBanned.ok) {
const sso = new context.sso();
- return sso.notOk().addShort("server_error")
- .addContent(isBanned)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addCalls("vcs.newVersionData", packMetadata)
- .addCalls("vcs.ownership", gitowner)
- .addMessage("This package Name is Banned on the Pulsar Registry");
+ return sso
+ .notOk()
+ .addShort("server_error")
+ .addContent(isBanned)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addCalls("vcs.newVersionData", packMetadata)
+ .addCalls("vcs.ownership", gitowner)
+ .addMessage("This package Name is Banned on the Pulsar Registry");
}
- const isAvailable = await context.database.packageNameAvailability(newName);
+ const isAvailable = await context.database.packageNameAvailability(
+ newName
+ );
if (isAvailable.ok) {
const sso = new context.sso();
- return sso.notOk().addShort("server_error")
- .addContent(isAvailable)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addCalls("vcs.newVersionData", packMetadata)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("db.packageNameAvailability", isAvailable)
- .addMessage(`The Package Name: ${newName} is not available.`);
+ return sso
+ .notOk()
+ .addShort("server_error")
+ .addContent(isAvailable)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addCalls("vcs.newVersionData", packMetadata)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("db.packageNameAvailability", isAvailable)
+ .addMessage(`The Package Name: ${newName} is not available.`);
}
}
@@ -199,15 +242,17 @@ module.exports = {
// TODO Use hardcoded message until we can verify messages from db are safe
const sso = new context.sso();
- return sso.notOk().addShort("server_error")
- .addContent(addVer)
- .addCalls("auth.verifyAuth", user)
- .addCalls("db.getPackageByName", packExists)
- .addCalls("vcs.newVersionData", packMetadata)
- .addCalls("vcs.ownership", gitowner)
- .addCalls("db.packageNameAvailability", isAvailable)
- .addCalls("db.insertNewPackageVersion", addVer)
- .addMessage("Failed to add the new package version to the database.");
+ return sso
+ .notOk()
+ .addShort("server_error")
+ .addContent(addVer)
+ .addCalls("auth.verifyAuth", user)
+ .addCalls("db.getPackageByName", packExists)
+ .addCalls("vcs.newVersionData", packMetadata)
+ .addCalls("vcs.ownership", gitowner)
+ .addCalls("db.packageNameAvailability", isAvailable)
+ .addCalls("db.insertNewPackageVersion", addVer)
+ .addMessage("Failed to add the new package version to the database.");
}
const sso = new context.sso();
@@ -215,15 +260,15 @@ module.exports = {
// TODO the following reduces the good things an object builder gets us
sso.webhook = {
pack: packMetadata.content,
- user: user.content
+ user: user.content,
};
sso.featureDetection = {
user: user.content,
service: "git", // TODO stop hardcoding git
- ownerRepo: ownerRepo
+ ownerRepo: ownerRepo,
};
return sso.isOk().addContent(addVer.content);
- }
+ },
};
diff --git a/src/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.js b/src/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.js
index 401a34a9..86e34939 100644
--- a/src/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.js
+++ b/src/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.js
@@ -1,7 +1,7 @@
/**
* @module postPackagesPackageNameVersionsVersionNameEventsUninstall
*/
-
+
module.exports = {
docs: {
summary: "Previously undocumented endpoint. Since v1.0.2 has no effect.",
@@ -10,14 +10,14 @@ module.exports = {
method: "POST",
paths: [
"/api/packages/:packageName/versions/:versionName/events/uninstall",
- "/api/themes/:packageName/versions/:versionName/events/uninstall"
+ "/api/themes/:packageName/versions/:versionName/events/uninstall",
],
rateLimit: "auth",
successStatus: 201,
options: {
Allow: "POST",
- "X-Content-Type-Options": "nosniff"
- }
+ "X-Content-Type-Options": "nosniff",
+ },
},
params: {},
async logic(params, context) {
@@ -38,5 +38,5 @@ module.exports = {
const sso = new context.sso();
return sso.isOk().addContent({ ok: true });
- }
-}
+ },
+};
diff --git a/src/database.js b/src/database.js
index 9f3bb159..087d10f4 100644
--- a/src/database.js
+++ b/src/database.js
@@ -138,7 +138,9 @@ async function insertNewPackage(pack) {
RETURNING pointer;
`;
} catch (e) {
- throw `A constraint has been violated while inserting ${pack.name} in packages table: ${e.toString()}`;
+ throw `A constraint has been violated while inserting ${
+ pack.name
+ } in packages table: ${e.toString()}`;
}
if (!insertNewPack?.count) {
@@ -633,7 +635,7 @@ async function getPackageByName(name, user = false) {
return {
ok: false,
content: err,
- short: "server_error"
+ short: "server_error",
};
}
}
@@ -1123,7 +1125,7 @@ async function getUserByName(username) {
return {
ok: false,
content: err,
- short: "server_error"
+ short: "server_error",
};
}
}
@@ -1561,24 +1563,27 @@ async function getUserCollectionById(ids) {
let emptyClause;
-function getEmptyClause () {
+function getEmptyClause() {
emptyClause ??= sqlStorage``;
return emptyClause;
}
-function ownerClause (opts) {
- if (typeof opts.owner !== 'string') {
+function ownerClause(opts) {
+ if (typeof opts.owner !== "string") {
return getEmptyClause();
}
return sqlStorage`AND p.owner = ${opts.owner}`;
}
-function serviceClause (opts) {
- if (typeof opts.service !== 'string' || typeof opts.serviceType !== 'string') {
+function serviceClause(opts) {
+ if (
+ typeof opts.service !== "string" ||
+ typeof opts.serviceType !== "string"
+ ) {
return getEmptyClause();
}
let versionClause;
- if (typeof opts.serviceVersion !== 'string') {
+ if (typeof opts.serviceVersion !== "string") {
versionClause = sqlStorage`IS NOT NULL`;
} else {
versionClause = sqlStorage`-> 'versions' -> ${opts.serviceVersion} IS NOT NULL`;
@@ -1587,8 +1592,8 @@ function serviceClause (opts) {
return sqlStorage`AND v.meta -> ${opts.serviceType} -> ${opts.service} ${versionClause}`;
}
-function fileExtensionClause (opts) {
- if (typeof opts.fileExtension !== 'string') {
+function fileExtensionClause(opts) {
+ if (typeof opts.fileExtension !== "string") {
return getEmptyClause();
}
diff --git a/src/models/sso.js b/src/models/sso.js
index 10f0e19f..64c63621 100644
--- a/src/models/sso.js
+++ b/src/models/sso.js
@@ -7,38 +7,37 @@ const validEnums = [
"not_supported",
"unauthorized",
"bad_repo",
- "package_exists"
+ "package_exists",
];
const enumDetails = {
- "not_found": {
+ not_found: {
code: 404,
- message: "Not Found"
+ message: "Not Found",
},
- "server_error": {
+ server_error: {
code: 500,
- message: "Application Error"
+ message: "Application Error",
},
- "not_supported": {
+ not_supported: {
code: 501,
- message: "While under development this feature is not supported."
+ message: "While under development this feature is not supported.",
},
- "unauthorized": {
+ unauthorized: {
code: 401,
- message: "Unauthorized"
+ message: "Unauthorized",
},
- "bad_repo": {
+ bad_repo: {
code: 400,
- message: "That repo does not exist, or is inaccessible"
+ message: "That repo does not exist, or is inaccessible",
},
- "package_exists": {
+ package_exists: {
code: 409,
- message: "A Package by that name already exists."
- }
+ message: "A Package by that name already exists.",
+ },
};
-module.exports =
-class SSO {
+module.exports = class SSO {
constructor() {
this.ok = false;
this.content = {};
@@ -71,7 +70,7 @@ class SSO {
addCalls(id, content) {
this.calls[id] = {
content: content,
- time: performance.now()
+ time: performance.now(),
};
return this;
}
@@ -116,18 +115,20 @@ class SSO {
if (typeof this.short === "string" && this.short.length > 0) {
// Use the short given to us during the build stage
shortToUse = this.short;
-
- } else if (typeof this.content?.short === "string" && this.content.short.length > 0) {
+ } else if (
+ typeof this.content?.short === "string" &&
+ this.content.short.length > 0
+ ) {
// Use the short that's bubbled up from other calls
shortToUse = this.content.short;
-
} else {
// Use the default short
shortToUse = "server_error";
}
// Now that we have our short, we must determine the text of our message.
- msgToUse = enumDetails[shortToUse]?.message ?? `Server Error: From ${shortToUse}`;
+ msgToUse =
+ enumDetails[shortToUse]?.message ?? `Server Error: From ${shortToUse}`;
codeToUse = enumDetails[shortToUse]?.code ?? 500;
@@ -140,7 +141,7 @@ class SSO {
// providing helpful error logs and such.
res.status(codeToUse).json({
- message: msgToUse
+ message: msgToUse,
});
// TODO Log our error too!
@@ -149,7 +150,6 @@ class SSO {
}
handleSuccess(req, res, context) {
-
if (typeof this.content === "boolean" && this.content === false) {
res.status(this.successStatusCode).send();
} else {
@@ -158,4 +158,4 @@ class SSO {
context.logger.httpLog(req, res);
return;
}
-}
+};
diff --git a/src/models/ssoHTML.js b/src/models/ssoHTML.js
index e8c4343b..c7cf4365 100644
--- a/src/models/ssoHTML.js
+++ b/src/models/ssoHTML.js
@@ -1,7 +1,6 @@
const SSO = require("./sso.js");
-module.exports =
-class SSOHTML extends SSO {
+module.exports = class SSOHTML extends SSO {
constructor() {
super();
}
@@ -10,4 +9,4 @@ class SSOHTML extends SSO {
res.send(this.content);
context.logger.httpLog(req, res);
}
-}
+};
diff --git a/src/models/ssoPaginate.js b/src/models/ssoPaginate.js
index 0715afa1..ce549a5e 100644
--- a/src/models/ssoPaginate.js
+++ b/src/models/ssoPaginate.js
@@ -1,7 +1,6 @@
const SSO = require("./sso.js");
-module.exports =
-class SSOPaginate extends SSO {
+module.exports = class SSOPaginate extends SSO {
constructor() {
super();
@@ -36,14 +35,15 @@ class SSOPaginate extends SSO {
linkString += `<${url}?page=${this.totalPages}${paramString}>; rel="last"`;
if (currentPage !== this.totalPages) {
- linkString += `, <${url}?page=${parseInt(currentPage) + 1}${paramString}>; rel="next"`;
+ linkString += `, <${url}?page=${
+ parseInt(currentPage) + 1
+ }${paramString}>; rel="next"`;
}
this.link = linkString;
}
handleSuccess(req, res, context) {
-
res.append("Link", this.link);
res.append("Query-Total", this.resultCount);
res.append("Query-Limit", this.limit);
@@ -52,4 +52,4 @@ class SSOPaginate extends SSO {
context.logger.httpLog(req, res);
return;
}
-}
+};
diff --git a/src/models/ssoRedirect.js b/src/models/ssoRedirect.js
index 7e7714f5..08b193b1 100644
--- a/src/models/ssoRedirect.js
+++ b/src/models/ssoRedirect.js
@@ -1,7 +1,6 @@
const SSO = require("./sso.js");
-module.exports =
-class SSORedirect extends SSO {
+module.exports = class SSORedirect extends SSO {
constructor() {
super();
}
@@ -10,4 +9,4 @@ class SSORedirect extends SSO {
res.redirect(this.content);
context.logger.httpLog(req, res);
}
-}
+};
diff --git a/src/query_parameters/auth.js b/src/query_parameters/auth.js
index 7b6892ce..0a06d40e 100644
--- a/src/query_parameters/auth.js
+++ b/src/query_parameters/auth.js
@@ -9,15 +9,15 @@ module.exports = {
name: "auth",
in: "header",
schema: {
- type: "string"
+ type: "string",
},
required: true,
allowEmptyValue: false,
- description: "Authorization Headers"
+ description: "Authorization Headers",
},
logic: (req) => {
const token = req.get("Authorization");
return token ?? "";
- }
+ },
};
diff --git a/src/query_parameters/direction.js b/src/query_parameters/direction.js
index 5c62af57..857f18cf 100644
--- a/src/query_parameters/direction.js
+++ b/src/query_parameters/direction.js
@@ -10,45 +10,40 @@ module.exports = {
schema: {
name: "multiSchema", // Special name to indicate that within this query
// parameter module, multiple schemas are supported, seperated by name
- "direction": {
+ direction: {
name: "direction",
in: "query",
schema: {
type: "string",
- enum: [
- "desc",
- "asc"
- ],
- default: "desc"
+ enum: ["desc", "asc"],
+ default: "desc",
},
example: "desc",
allowEmptyValue: true,
- description: "Direction to list search results."
+ description: "Direction to list search results.",
},
- "order": {
+ order: {
name: "order",
in: "query",
schema: {
type: "string",
- enum: [
- "desc",
- "asc"
- ],
- default: "desc"
+ enum: ["desc", "asc"],
+ default: "desc",
},
example: "desc",
allowEmptyValue: true,
- description: "Deprecated method to list search results. Use 'direction' instead."
- }
+ description:
+ "Deprecated method to list search results. Use 'direction' instead.",
+ },
},
logic: (req) => {
const def = "desc";
- const valid = [ "asc", "desc" ];
+ const valid = ["asc", "desc"];
// Seems that the autolink headers use order, while documentation uses direction.
// Since we are not sure where in the codebase it uses the other, we will just accept both.
const prov = req.query.direction ?? req.query.order ?? def;
return valid.includes(prov) ? prov : def;
- }
+ },
};
diff --git a/src/query_parameters/engine.js b/src/query_parameters/engine.js
index 73bae256..f3f41b66 100644
--- a/src/query_parameters/engine.js
+++ b/src/query_parameters/engine.js
@@ -9,11 +9,12 @@ module.exports = {
name: "engine",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "1.0.0",
allowEmptyValue: true,
- description: "Only show packages compatible with this Pulsar version. Must be a valid Semver."
+ description:
+ "Only show packages compatible with this Pulsar version. Must be a valid Semver.",
},
// TODO: Why does this accept `semver` and not a request object?
logic: (semver) => {
@@ -31,5 +32,5 @@ module.exports = {
} catch (e) {
return false;
}
- }
+ },
};
diff --git a/src/query_parameters/fileExtension.js b/src/query_parameters/fileExtension.js
index efd4c331..3477cb60 100644
--- a/src/query_parameters/fileExtension.js
+++ b/src/query_parameters/fileExtension.js
@@ -12,13 +12,14 @@ module.exports = {
name: "fileExtension",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "coffee",
allowEmptyValue: true,
- description: "File extension of which to only show compatible grammar package's of."
+ description:
+ "File extension of which to only show compatible grammar package's of.",
},
logic: (req) => {
return utils.stringValidation(req.query.fileExtension);
- }
+ },
};
diff --git a/src/query_parameters/filter.js b/src/query_parameters/filter.js
index 6605ce4a..a9b2ee31 100644
--- a/src/query_parameters/filter.js
+++ b/src/query_parameters/filter.js
@@ -4,20 +4,18 @@ module.exports = {
in: "query",
schema: {
type: "string",
- enum: [
- "package",
- "theme"
- ],
- default: "pacakge"
+ enum: ["package", "theme"],
+ default: "pacakge",
},
required: false,
allowEmptyValue: false,
example: "package",
- description: "Deprecated method to display packages or themes. Use `/api/themes/search` or `/api/packages/search` instead."
+ description:
+ "Deprecated method to display packages or themes. Use `/api/themes/search` or `/api/packages/search` instead.",
},
logic: (req) => {
const def = "package";
- const valid = [ "theme", "package" ];
+ const valid = ["theme", "package"];
const prov = req.query.filter;
@@ -30,5 +28,5 @@ module.exports = {
}
return prov;
- }
+ },
};
diff --git a/src/query_parameters/index.js b/src/query_parameters/index.js
index b4643367..53bf90c2 100644
--- a/src/query_parameters/index.js
+++ b/src/query_parameters/index.js
@@ -64,5 +64,5 @@ module.exports = {
sort: sort.schema,
tag: tag.schema,
versionName: versionName.schema,
- }
+ },
};
diff --git a/src/query_parameters/login.js b/src/query_parameters/login.js
index 4b001f72..71d29054 100644
--- a/src/query_parameters/login.js
+++ b/src/query_parameters/login.js
@@ -10,14 +10,14 @@ module.exports = {
name: "login",
in: "path",
schema: {
- type: "string"
+ type: "string",
},
required: true,
allowEmptyValue: false,
example: "confused-Techie",
- description: "The User from the URL Path"
+ description: "The User from the URL Path",
},
logic: (req) => {
return req.params.login ?? "";
- }
+ },
};
diff --git a/src/query_parameters/owner.js b/src/query_parameters/owner.js
index a0140746..d2f1e904 100644
--- a/src/query_parameters/owner.js
+++ b/src/query_parameters/owner.js
@@ -11,28 +11,28 @@ const utils = require("./utils.js");
module.exports = {
schema: {
name: "multiSchema", // Special name to indicate multi support
- "owner": {
+ owner: {
name: "owner",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "pulsar-edit",
allowEmptyValue: false,
required: false,
- description: "Owner to filter results by."
+ description: "Owner to filter results by.",
},
- "ownerName": {
+ ownerName: {
name: "ownerName",
in: "path",
schema: {
- type: "string"
+ type: "string",
},
example: "pulsar-edit",
allowEmptyValue: false,
required: true,
- description: "Owner of packages to retreive."
- }
+ description: "Owner of packages to retreive.",
+ },
},
logic: (req) => {
// Owner accepts the owner as an argument for things like search,
@@ -46,5 +46,5 @@ module.exports = {
return false;
}
return prov;
- }
+ },
};
diff --git a/src/query_parameters/packageName.js b/src/query_parameters/packageName.js
index cbe82c8f..efa38e72 100644
--- a/src/query_parameters/packageName.js
+++ b/src/query_parameters/packageName.js
@@ -10,14 +10,15 @@ module.exports = {
name: "packageName",
in: "path",
schema: {
- type: "string"
+ type: "string",
},
required: true,
allowEmptyValue: false,
example: "autocomplete-powershell",
- description: "The name of the package to reutrn details for. Must be URL escaped."
+ description:
+ "The name of the package to reutrn details for. Must be URL escaped.",
},
logic: (req) => {
return req.params.packageName.toLowerCase();
- }
+ },
};
diff --git a/src/query_parameters/page.js b/src/query_parameters/page.js
index 2d89e792..71092796 100644
--- a/src/query_parameters/page.js
+++ b/src/query_parameters/page.js
@@ -12,12 +12,12 @@ module.exports = {
schema: {
type: "number",
minimum: 1,
- default: 1
+ default: 1,
},
example: 1,
allowEmptyValue: true,
required: false,
- description: "The page of available results to return."
+ description: "The page of available results to return.",
},
logic: (req) => {
const def = 1;
@@ -35,5 +35,5 @@ module.exports = {
default:
return def;
}
- }
+ },
};
diff --git a/src/query_parameters/query.js b/src/query_parameters/query.js
index 03c03f87..6d867dbc 100644
--- a/src/query_parameters/query.js
+++ b/src/query_parameters/query.js
@@ -13,11 +13,11 @@ module.exports = {
name: "q",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "generic-lsp",
required: true,
- description: "Search Query"
+ description: "Search Query",
},
logic: (req) => {
const maxLength = 50; // While package.json names according to NPM can be up to 214 characters,
@@ -31,6 +31,8 @@ module.exports = {
// If there is a path traversal attach detected return empty query.
// Additionally do not allow strings longer than `maxLength`
- return utils.pathTraversalAttempt(prov) ? "" : prov.slice(0, maxLength).trim();
- }
+ return utils.pathTraversalAttempt(prov)
+ ? ""
+ : prov.slice(0, maxLength).trim();
+ },
};
diff --git a/src/query_parameters/rename.js b/src/query_parameters/rename.js
index b6670b5a..ed9239b1 100644
--- a/src/query_parameters/rename.js
+++ b/src/query_parameters/rename.js
@@ -11,12 +11,12 @@ module.exports = {
name: "rename",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "new-package-name",
allowEmptyValue: false,
required: false,
- description: "The new package name to rename to, if applicable."
+ description: "The new package name to rename to, if applicable.",
},
logic: (req) => {
const prov = req.query.rename;
@@ -37,5 +37,5 @@ module.exports = {
}
return false;
- }
+ },
};
diff --git a/src/query_parameters/repo.js b/src/query_parameters/repo.js
index 563a2b59..91f4b323 100644
--- a/src/query_parameters/repo.js
+++ b/src/query_parameters/repo.js
@@ -10,12 +10,12 @@ module.exports = {
name: "repository",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "pulsar-edit/pulsar",
allowEmptyValue: false,
required: true,
- description: "Repository to publish."
+ description: "Repository to publish.",
},
logic: (req) => {
const prov = req.query.repository;
@@ -33,5 +33,5 @@ module.exports = {
// - cannot begin with a dot or an underscore
// - cannot contain a space.
return prov.match(re) !== null ? prov : "";
- }
+ },
};
diff --git a/src/query_parameters/service.js b/src/query_parameters/service.js
index 5060d8ed..17bc6c3a 100644
--- a/src/query_parameters/service.js
+++ b/src/query_parameters/service.js
@@ -12,13 +12,13 @@ module.exports = {
name: "service",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "autocomplete.watchEditor",
allowEmptyValue: true,
- description: "The service of which to filter packages by"
+ description: "The service of which to filter packages by",
},
logic: (req) => {
return utils.stringValidation(req.query.service);
- }
+ },
};
diff --git a/src/query_parameters/serviceType.js b/src/query_parameters/serviceType.js
index 196dabd3..bf46558d 100644
--- a/src/query_parameters/serviceType.js
+++ b/src/query_parameters/serviceType.js
@@ -13,14 +13,12 @@ module.exports = {
in: "query",
schema: {
type: "string",
- enum: [
- "consumed",
- "provided"
- ]
+ enum: ["consumed", "provided"],
},
example: "consumed",
allowEmptyValue: true,
- deescription: "Choos whether to display 'consumer' or 'providers' of the specified service."
+ deescription:
+ "Choos whether to display 'consumer' or 'providers' of the specified service.",
},
logic: (req) => {
// TODO determine if there's a way to indicate this is a required
@@ -40,5 +38,5 @@ module.exports = {
}
return false; // fallback
- }
+ },
};
diff --git a/src/query_parameters/serviceVersion.js b/src/query_parameters/serviceVersion.js
index 9907cd54..3119ba49 100644
--- a/src/query_parameters/serviceVersion.js
+++ b/src/query_parameters/serviceVersion.js
@@ -11,11 +11,11 @@ module.exports = {
name: "serviceVersion",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "0.0.1",
allowEmptyValue: true,
- description: "Filter by a specific version of the 'service'"
+ description: "Filter by a specific version of the 'service'",
},
logic: (req) => {
const semver = req.query.serviceVersion;
@@ -28,5 +28,5 @@ module.exports = {
} catch (err) {
return false;
}
- }
+ },
};
diff --git a/src/query_parameters/sort.js b/src/query_parameters/sort.js
index 50361216..bd831e65 100644
--- a/src/query_parameters/sort.js
+++ b/src/query_parameters/sort.js
@@ -13,29 +13,29 @@ module.exports = {
in: "query",
schema: {
type: "string",
- enum: [
- "downloads",
- "created_at",
- "updated_at",
- "stars",
- "relevance"
- ],
- default: "downloads"
+ enum: ["downloads", "created_at", "updated_at", "stars", "relevance"],
+ default: "downloads",
},
example: "downloads",
required: false,
allowEmptyValue: false,
- description: "Value to sort search results by."
+ description: "Value to sort search results by.",
},
logic: (req, def = "downloads") => {
// TODO: Determine if allowing `def` value here makes any sense still
// using sort with a default def value of downloads, means when using the generic sort parameter
// it will default to downloads, but if we pass the default, such as during search we can provide
// the default relevance
- const valid = ["downloads", "created_at", "updated_at", "stars", "relevance"];
+ const valid = [
+ "downloads",
+ "created_at",
+ "updated_at",
+ "stars",
+ "relevance",
+ ];
const prov = req.query.sort ?? def;
return valid.includes(prov) ? prov : def;
- }
+ },
};
diff --git a/src/query_parameters/tag.js b/src/query_parameters/tag.js
index 5d4aa059..509ae2d3 100644
--- a/src/query_parameters/tag.js
+++ b/src/query_parameters/tag.js
@@ -10,14 +10,14 @@ module.exports = {
name: "tag",
in: "query",
schema: {
- type: "string"
+ type: "string",
},
example: "TODO",
allowEmptyValue: false,
required: false,
- description: "TODO"
+ description: "TODO",
},
logic: (req) => {
return typeof req.query.tag !== "string" ? "" : req.query.tag;
- }
+ },
};
diff --git a/src/query_parameters/utils.js b/src/query_parameters/utils.js
index efb2a5a8..5d71e4ca 100644
--- a/src/query_parameters/utils.js
+++ b/src/query_parameters/utils.js
@@ -46,4 +46,4 @@ function pathTraversalAttempt(data) {
module.exports = {
stringValidation,
pathTraversalAttempt,
-}
+};
diff --git a/src/query_parameters/versionName.js b/src/query_parameters/versionName.js
index 6f6e35ce..2b131106 100644
--- a/src/query_parameters/versionName.js
+++ b/src/query_parameters/versionName.js
@@ -5,12 +5,12 @@ module.exports = {
name: "versionName",
in: "path",
schema: {
- type: 'string"'
+ type: 'string"',
},
required: true,
allowEmptyValue: false,
example: "1.0.0",
- description: "The version of the package to access"
+ description: "The version of the package to access",
},
- logic: engine
+ logic: engine,
};
diff --git a/src/setupEndpoints.js b/src/setupEndpoints.js
index 376ada21..33fd4b58 100644
--- a/src/setupEndpoints.js
+++ b/src/setupEndpoints.js
@@ -11,7 +11,8 @@ const app = express();
const genericLimit = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
// Limit each IP per window, 0 disables rate limit
- max: process.env.PULSAR_STATUS === "dev" ? 0 : context.config.RATE_LIMIT_GENERIC,
+ max:
+ process.env.PULSAR_STATUS === "dev" ? 0 : context.config.RATE_LIMIT_GENERIC,
standardHeaders: true, // Return rate limit info in headers
legacyHeaders: true, // Legacy rate limit info in headers
store: new MemoryStore(), // use default memory store
@@ -20,12 +21,12 @@ const genericLimit = rateLimit({
handler: (request, response, next, options) => {
response.status(options.statusCode).json({ message: options.message });
context.logger.httpLog(request, response);
- }
+ },
});
const authLimit = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
- // Limit each IP per window, 0 disables rate limit.
+ // Limit each IP per window, 0 disables rate limit.
max: process.env.PULSAR_STATUS === "dev" ? 0 : context.config.RATE_LIMIT_AUTH,
standardHeaders: true, // Return rate limit info on headers
legacyHeaders: true, // Legacy rate limit info in headers
@@ -35,7 +36,7 @@ const authLimit = rateLimit({
handler: (request, response, next, options) => {
response.status(options.statusCode).json({ message: options.message });
context.logger.httpLog(request, response);
- }
+ },
});
// Set express defaults
@@ -44,7 +45,7 @@ app.set("trust proxy", true);
app.use("/swagger-ui", express.static("docs/swagger"));
-const endpointHandler = async function(node, req, res) {
+const endpointHandler = async function (node, req, res) {
let params = {};
for (const param in node.params) {
@@ -62,17 +63,18 @@ const endpointHandler = async function(node, req, res) {
await node.logic(req, res, context);
// If it's a raw endpoint, they must handle all other steps manually
return;
-
} else {
obj = await node.logic(params, context);
}
- } catch(err) {
+ } catch (err) {
// The main logic request has failed. We will generate our own return obj,
// and exit.
obj = new context.sso();
- obj.notOk().addContent(err)
- .addMessage("An unexpected error has occurred.")
- .addShort("server_error");
+ obj
+ .notOk()
+ .addContent(err)
+ .addMessage("An unexpected error has occurred.")
+ .addShort("server_error");
}
if (typeof node.postLogic === "function") {
@@ -96,7 +98,6 @@ const pathOptions = [];
for (const node of endpoints) {
for (const path of node.endpoint.paths) {
-
let limiter = genericLimit;
if (node.endpoint.rateLimit === "auth") {
@@ -115,7 +116,7 @@ for (const node of endpoints) {
pathOptions.push(path);
}
- switch(node.endpoint.method) {
+ switch (node.endpoint.method) {
case "GET":
app.get(path, limiter, async (req, res) => {
await endpointHandler(node, req, res);
@@ -134,7 +135,6 @@ for (const node of endpoints) {
default:
console.log(`Unsupported method: ${node.endpoint.method} for ${path}`);
}
-
}
}
diff --git a/src/storage.js b/src/storage.js
index 01016eff..96834a1a 100644
--- a/src/storage.js
+++ b/src/storage.js
@@ -39,7 +39,9 @@ async function getGcpContent(file) {
const fs = require("fs");
const path = require("path");
- const contents = fs.readFileSync(path.resolve(`./docs/resources/${file}`), { encoding: "utf8" });
+ const contents = fs.readFileSync(path.resolve(`./docs/resources/${file}`), {
+ encoding: "utf8",
+ });
return contents;
} else {
// This is a production request
@@ -64,9 +66,7 @@ async function getGcpContent(file) {
* @returns {Array} Parsed JSON Array of all Banned Packages.
*/
async function getBanList() {
-
const getNew = async function () {
-
try {
const contents = await getGcpContent("name_ban_list.json");
@@ -74,9 +74,10 @@ async function getBanList() {
cachedBanlist.last_validate = Date.now();
return new sso().isOk().addContent(cachedBanlist.data);
} catch (err) {
- return new sso().notOk()
- .addShort("server_error")
- .addCalls("getGcpContent", err);
+ return new sso()
+ .notOk()
+ .addShort("server_error")
+ .addCalls("getGcpContent", err);
}
};
@@ -102,20 +103,18 @@ async function getBanList() {
* @returns {Array} Parsed JSON Array of all Featured Packages.
*/
async function getFeaturedPackages() {
-
const getNew = async function () {
-
try {
const contents = await getGcpContent("featured_packages.json");
cachedFeaturedlist = new CacheObject(JSON.parse(contents));
cachedFeaturedlist.last_validate = Date.now();
- return new sso().isOk()
- .addContent(cachedFeaturedlist.data);
+ return new sso().isOk().addContent(cachedFeaturedlist.data);
} catch (err) {
- return new sso().notOk()
- .addShort("server_error")
- .addCalls("getGcpContent", err);
+ return new sso()
+ .notOk()
+ .addShort("server_error")
+ .addCalls("getGcpContent", err);
}
};
@@ -126,8 +125,7 @@ async function getFeaturedPackages() {
if (!cachedFeaturedlist.Expired) {
logger.generic(5, "Ban List Cache NOT Expired.");
- return new sso().isOk()
- .addContent(cachedFeaturedlist.data);
+ return new sso().isOk().addContent(cachedFeaturedlist.data);
}
logger.generic(5, "Ban List Cache IS Expired.");
@@ -141,9 +139,7 @@ async function getFeaturedPackages() {
* @returns {Array} JSON Parsed Array of Featured Theme Names.
*/
async function getFeaturedThemes() {
-
const getNew = async function () {
-
try {
const contents = await getGcpContent("featured_themes.json");
@@ -151,9 +147,10 @@ async function getFeaturedThemes() {
cachedThemelist.last_validate = Date.now();
return new sso().isOk().addContent(cachedThemelist.data);
} catch (err) {
- return new sso().notOk()
- .addShort("server_error")
- .addCalls("getGcpContent", err);
+ return new sso()
+ .notOk()
+ .addShort("server_error")
+ .addCalls("getGcpContent", err);
}
};
diff --git a/tests/database/database.test.js b/tests/database/database.test.js
index 671c35ea..9024f988 100644
--- a/tests/database/database.test.js
+++ b/tests/database/database.test.js
@@ -477,7 +477,7 @@ describe("Package Lifecycle Tests", () => {
name: "language-css",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
@@ -487,9 +487,9 @@ describe("Package Lifecycle Tests", () => {
versions: {
"1.0.0": {
dist: { tarball: "download-url", sha: "1234" },
- name: "language-css"
- }
- }
+ name: "language-css",
+ },
+ },
});
const starPack = await database.updateIncrementStar(
getUserID.content,
diff --git a/tests/helpers/global.setup.jest.js b/tests/helpers/global.setup.jest.js
index 8485d276..b708a509 100644
--- a/tests/helpers/global.setup.jest.js
+++ b/tests/helpers/global.setup.jest.js
@@ -29,12 +29,12 @@ expect.extend({
if (typeof actual === want) {
return {
pass: true,
- message: () => ""
+ message: () => "",
};
} else {
return {
pass: false,
- message: () => `Expected "${want}" but got "${typeof actual}"`
+ message: () => `Expected "${want}" but got "${typeof actual}"`,
};
}
},
@@ -43,12 +43,12 @@ expect.extend({
if (Array.isArray(want) && want.includes(actual)) {
return {
pass: true,
- message: () => ""
+ message: () => "",
};
} else {
return {
pass: false,
- message: () => `Expected ${want} to include ${actual}`
+ message: () => `Expected ${want} to include ${actual}`,
};
}
},
@@ -62,7 +62,7 @@ expect.extend({
let obj = endpoint.docs.responses[response].content["application/json"];
if (obj.startsWith("$")) {
- obj = require(`../models/${obj.replace("$","")}.js`);
+ obj = require(`../models/${obj.replace("$", "")}.js`);
}
expect(sso.content).toMatchSchema(obj.test);
@@ -72,13 +72,13 @@ expect.extend({
}
if (done) {
return {
- pass: true, message: () => ""
+ pass: true,
+ message: () => "",
};
} else {
return {
pass: false,
- message: () =>
- `Unable to find ${endpoint.endpoint.successStatus}.`
+ message: () => `Unable to find ${endpoint.endpoint.successStatus}.`,
};
}
},
diff --git a/tests/http/deletePackagesPackageName.test.js b/tests/http/deletePackagesPackageName.test.js
index 81374522..4d781cb6 100644
--- a/tests/http/deletePackagesPackageName.test.js
+++ b/tests/http/deletePackagesPackageName.test.js
@@ -9,7 +9,7 @@ describe("DELETE /api/packages/:packageName", () => {
return {
ok: false,
short: "unauthorized",
- content: "Bad Auth Mock Return"
+ content: "Bad Auth Mock Return",
};
};
@@ -28,15 +28,18 @@ describe("DELETE /api/packages/:packageName", () => {
id: 9999,
node_id: "dlt-pkg-test-user-node-id",
username: "dlt-pkg-test-user-node-id",
- avatar: "https://roadtonowhere.com"
- }
+ avatar: "https://roadtonowhere.com",
+ },
};
};
- const sso = await endpoint.logic({
- auth: "valid-token",
- packageName: "no-exist"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ auth: "valid-token",
+ packageName: "no-exist",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.content.short).toBe("not_found");
@@ -47,12 +50,12 @@ describe("DELETE /api/packages/:packageName", () => {
name: "dlt-pkg-by-name-test",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: { name: "dlt-pkg-by-name-test" },
@@ -60,11 +63,11 @@ describe("DELETE /api/packages/:packageName", () => {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "dlt-pkg-by-name-test"
- }
- }
+ name: "dlt-pkg-by-name-test",
+ },
+ },
});
let addUser = await database.insertNewUser(
@@ -85,35 +88,44 @@ describe("DELETE /api/packages/:packageName", () => {
id: addUser.content.id,
node_id: addUser.content.node_id,
username: addUser.content.username,
- avatar: addUser.content.avatar
- }
+ avatar: addUser.content.avatar,
+ },
};
};
localContext.vcs.ownership = () => {
return {
ok: true,
- content: "admin"
+ content: "admin",
};
};
- const sso = await endpoint.logic({
- auth: "valid-token",
- packageName: "dlt-pkg-by-name-test"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ auth: "valid-token",
+ packageName: "dlt-pkg-by-name-test",
+ },
+ localContext
+ );
expect(sso.ok).toBe(true);
expect(sso.content).toBe(false);
- let doesPackageStillExist = await database.getPackageByName("dlt-pkg-by-name-test");
+ let doesPackageStillExist = await database.getPackageByName(
+ "dlt-pkg-by-name-test"
+ );
expect(doesPackageStillExist.ok).toBe(false);
expect(doesPackageStillExist.short).toBe("not_found");
- let isPackageNameAvailable = await database.packageNameAvailability("dlt-pkg-by-name-test");
+ let isPackageNameAvailable = await database.packageNameAvailability(
+ "dlt-pkg-by-name-test"
+ );
expect(isPackageNameAvailable.ok).toBe(false);
expect(isPackageNameAvailable.short).toBe("not_found");
- expect(isPackageNameAvailable.content).toBe("dlt-pkg-by-name-test is not available to be used for a new package.");
+ expect(isPackageNameAvailable.content).toBe(
+ "dlt-pkg-by-name-test is not available to be used for a new package."
+ );
});
});
diff --git a/tests/http/deletePackagesPackageNameVersionsVersionName.test.js b/tests/http/deletePackagesPackageNameVersionsVersionName.test.js
index 52b0caa3..f3c8348a 100644
--- a/tests/http/deletePackagesPackageNameVersionsVersionName.test.js
+++ b/tests/http/deletePackagesPackageNameVersionsVersionName.test.js
@@ -9,7 +9,7 @@ describe("DELETE /api/packages/:packageName/versions/:versionName", () => {
return {
ok: false,
short: "unauthorized",
- content: "Bad Auth Mock Return"
+ content: "Bad Auth Mock Return",
};
};
@@ -28,16 +28,19 @@ describe("DELETE /api/packages/:packageName/versions/:versionName", () => {
id: 9999,
node_id: "dlt-pkg-ver-user-node-id",
username: "dlt-pkg-ver-user-node-id",
- avatar: "https://roadtonowhere.com"
- }
+ avatar: "https://roadtonowhere.com",
+ },
};
};
- const sso = await endpoint.logic({
- auth: "valid-token",
- packageName: "no-exist",
- versionName: "1.0.0"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ auth: "valid-token",
+ packageName: "no-exist",
+ versionName: "1.0.0",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.content.short).toBe("not_found");
@@ -47,12 +50,12 @@ describe("DELETE /api/packages/:packageName/versions/:versionName", () => {
name: "dlt-pkg-ver-by-name-test",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
releases: {
- latest: "1.0.1"
+ latest: "1.0.1",
},
readme: "This is a readme!",
metadata: { name: "dlt-pkg-ver-by-name-test" },
@@ -60,18 +63,18 @@ describe("DELETE /api/packages/:packageName/versions/:versionName", () => {
"1.0.1": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "dlt-pkg-ver-by-name-test"
+ name: "dlt-pkg-ver-by-name-test",
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "dlt-pkg-ver-by-name-test"
- }
- }
+ name: "dlt-pkg-ver-by-name-test",
+ },
+ },
});
let addUser = await database.insertNewUser(
@@ -92,31 +95,38 @@ describe("DELETE /api/packages/:packageName/versions/:versionName", () => {
id: addUser.content.id,
node_id: addUser.content.node_id,
username: addUser.content.username,
- avatar: addUser.content.avatar
- }
+ avatar: addUser.content.avatar,
+ },
};
};
localContext.vcs.ownership = () => {
return {
ok: true,
- content: "admin"
+ content: "admin",
};
};
- const sso = await endpoint.logic({
- auth: "valid-token",
- packageName: "dlt-pkg-ver-by-name-test",
- versionName: "1.0.1"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ auth: "valid-token",
+ packageName: "dlt-pkg-ver-by-name-test",
+ versionName: "1.0.1",
+ },
+ localContext
+ );
expect(sso.ok).toBe(true);
expect(sso.content).toBe(false);
- let currentPackageData = await database.getPackageByName("dlt-pkg-ver-by-name-test");
+ let currentPackageData = await database.getPackageByName(
+ "dlt-pkg-ver-by-name-test"
+ );
expect(currentPackageData.ok).toBe(true);
- currentPackageData = await context.utils.constructPackageObjectFull(currentPackageData.content);
+ currentPackageData = await context.utils.constructPackageObjectFull(
+ currentPackageData.content
+ );
expect(currentPackageData.name).toBe("dlt-pkg-ver-by-name-test");
// Does it modify the latest package version
diff --git a/tests/http/getOwnersOwnerName.test.js b/tests/http/getOwnersOwnerName.test.js
index 03b6024c..1ec8cd28 100644
--- a/tests/http/getOwnersOwnerName.test.js
+++ b/tests/http/getOwnersOwnerName.test.js
@@ -15,12 +15,15 @@ describe("Behaves as expected", () => {
});
test("Returns empty array with no matching results", async () => {
- const sso = await endpoint.logic({
- owner: "i-dont-exist",
- page: "1",
- sort: "downloads",
- direction: "desc"
- }, context);
+ const sso = await endpoint.logic(
+ {
+ owner: "i-dont-exist",
+ page: "1",
+ sort: "downloads",
+ direction: "desc",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content).toBeArray();
@@ -32,34 +35,37 @@ describe("Behaves as expected", () => {
name: "get-owner-test",
repository: {
url: "https://github.com/pulsar-cooperative/get-owner-test",
- type: "git"
+ type: "git",
},
owner: "pulsar-cooperative",
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: {
- name: "get-owner-test"
+ name: "get-owner-test",
},
versions: {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "get-owner-test"
- }
- }
+ name: "get-owner-test",
+ },
+ },
});
- const sso = await endpoint.logic({
- owner: "pulsar-cooperative",
- page: 1,
- sort: "downloads",
- direction: "desc"
- }, context);
+ const sso = await endpoint.logic(
+ {
+ owner: "pulsar-cooperative",
+ page: 1,
+ sort: "downloads",
+ direction: "desc",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content[0].name).toBe("get-owner-test");
diff --git a/tests/http/getPackages.test.js b/tests/http/getPackages.test.js
index 5767b665..b50a3bfc 100644
--- a/tests/http/getPackages.test.js
+++ b/tests/http/getPackages.test.js
@@ -3,100 +3,99 @@ const database = require("../../src/database.js");
const context = require("../../src/context.js");
describe("Behaves as expected", () => {
-
beforeAll(async () => {
await database.insertNewPackage({
name: "get-packages-test",
repository: {
url: "https://github.com/unique_user/package-backend",
- type: "git"
+ type: "git",
},
owner: "unique_user",
creation_method: "Test Package",
releases: {
- latest: "1.1.0"
+ latest: "1.1.0",
},
readme: "This is a readme!",
metadata: {
name: "get-packages-test",
- "providedServices": {
- "refactor": {
- "versions": {
- "0.0.1": "provideRefactor"
- }
- }
- }
+ providedServices: {
+ refactor: {
+ versions: {
+ "0.0.1": "provideRefactor",
+ },
+ },
+ },
},
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
name: "get-packages-test",
- "providedServices": {
- "refactor": {
- "versions": {
- "0.0.1": "provideRefactor"
- }
- }
- }
+ providedServices: {
+ refactor: {
+ versions: {
+ "0.0.1": "provideRefactor",
+ },
+ },
+ },
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
name: "get-packages-test",
- "providedServices": {
- "refactor": {
- "versions": {
- "0.0.1": "provideRefactor"
- }
- }
- }
- }
- }
+ providedServices: {
+ refactor: {
+ versions: {
+ "0.0.1": "provideRefactor",
+ },
+ },
+ },
+ },
+ },
});
await database.insertNewPackage({
name: "calculator-light-ui",
repository: {
url: "https://github.com/savetheclocktower/calculator-light-ui",
- type: "git"
+ type: "git",
},
owner: "savetheclocktower",
creation_method: "Test Package",
releases: {
- latest: "9.0.0"
+ latest: "9.0.0",
},
readme: "This is a second readme!",
metadata: {
name: "get-packages-test",
- "providedServices": {
- "another": {
- "versions": {
- "0.1.1": "provideanother"
- }
- }
- }
+ providedServices: {
+ another: {
+ versions: {
+ "0.1.1": "provideanother",
+ },
+ },
+ },
},
versions: {
"9.0.0": {
dist: {
tarball: "download-url",
- sha: "5678"
+ sha: "5678",
},
name: "get-packages-test",
- "providedServices": {
- "another": {
- "versions": {
- "0.1.1": "provideanother"
- }
- }
- }
- }
- }
+ providedServices: {
+ another: {
+ versions: {
+ "0.1.1": "provideanother",
+ },
+ },
+ },
+ },
+ },
});
});
@@ -106,15 +105,18 @@ describe("Behaves as expected", () => {
});
test("Allows filtering by owner field", async () => {
- let sso = await endpoint.logic({
- engine: false,
- owner: "unique_user",
- page: 1,
- sort: 'downloads',
- direction: 'desc',
- serviceVersion: false,
- fileExtension: false
- }, context);
+ let sso = await endpoint.logic(
+ {
+ engine: false,
+ owner: "unique_user",
+ page: 1,
+ sort: "downloads",
+ direction: "desc",
+ serviceVersion: false,
+ fileExtension: false,
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content.length).toBe(1);
@@ -124,16 +126,19 @@ describe("Behaves as expected", () => {
});
test("Allows filtering by services field", async () => {
- let sso = await endpoint.logic({
- engine: false,
- service: "refactor",
- serviceType: "providedServices",
- page: 1,
- sort: 'downloads',
- direction: 'desc',
- serviceVersion: false,
- fileExtension: false
- }, context);
+ let sso = await endpoint.logic(
+ {
+ engine: false,
+ service: "refactor",
+ serviceType: "providedServices",
+ page: 1,
+ sort: "downloads",
+ direction: "desc",
+ serviceVersion: false,
+ fileExtension: false,
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content.length).toBe(1);
@@ -143,17 +148,20 @@ describe("Behaves as expected", () => {
});
test("Allows filtering by both owner and services", async () => {
- let sso = await endpoint.logic({
- engine: false,
- owner: "unique_user",
- service: "refactor",
- serviceType: "providedServices",
- page: 1,
- sort: 'downloads',
- direction: 'desc',
- serviceVersion: false,
- fileExtension: false
- }, context);
+ let sso = await endpoint.logic(
+ {
+ engine: false,
+ owner: "unique_user",
+ service: "refactor",
+ serviceType: "providedServices",
+ page: 1,
+ sort: "downloads",
+ direction: "desc",
+ serviceVersion: false,
+ fileExtension: false,
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content.length).toBe(1);
@@ -161,5 +169,4 @@ describe("Behaves as expected", () => {
expect(sso.content[0].owner).toBe("unique_user");
expect(sso).toMatchEndpointSuccessObject(endpoint);
});
-
});
diff --git a/tests/http/getPackagesFeatured.test.js b/tests/http/getPackagesFeatured.test.js
index cef86597..dcd248cf 100644
--- a/tests/http/getPackagesFeatured.test.js
+++ b/tests/http/getPackagesFeatured.test.js
@@ -27,33 +27,33 @@ describe("Behaves as expected", () => {
name: "x-terminal-reloaded",
repository: {
url: "https://github.com/Spiker985/x-terminal-reloaded",
- type: "git"
+ type: "git",
},
owner: "Spiker985",
creation_method: "Test Package",
releases: {
- latest: "1.1.0"
+ latest: "1.1.0",
},
readme: "This is a readme!",
metadata: {
- name: "atom-material-ui"
+ name: "atom-material-ui",
},
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "x-terminal-reloaded"
+ name: "x-terminal-reloaded",
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "x-terminal-reloaded"
- }
- }
+ name: "x-terminal-reloaded",
+ },
+ },
});
const sso = await endpoint.logic({}, context);
diff --git a/tests/http/getPackagesPackageName.test.js b/tests/http/getPackagesPackageName.test.js
index 117e8353..bdc2564e 100644
--- a/tests/http/getPackagesPackageName.test.js
+++ b/tests/http/getPackagesPackageName.test.js
@@ -15,10 +15,13 @@ describe("Behaves as expected", () => {
});
test("Returns 'not_found' when package doesn't exist", async () => {
- const sso = await endpoint.logic({
- engine: false,
- packageName: "anything"
- }, context);
+ const sso = await endpoint.logic(
+ {
+ engine: false,
+ packageName: "anything",
+ },
+ context
+ );
expect(sso.ok).toBe(false);
expect(sso.content.short).toBe("not_found");
@@ -29,39 +32,42 @@ describe("Behaves as expected", () => {
name: "get-package-test",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
releases: {
- latest: "1.1.0"
+ latest: "1.1.0",
},
readme: "This is a readme!",
metadata: {
- name: "get-package-test"
+ name: "get-package-test",
},
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "get-package-test"
+ name: "get-package-test",
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "get-package-test"
- }
- }
+ name: "get-package-test",
+ },
+ },
});
- const sso = await endpoint.logic({
- engine: false,
- packageName: "get-package-test"
- }, context);
+ const sso = await endpoint.logic(
+ {
+ engine: false,
+ packageName: "get-package-test",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content.name).toBe("get-package-test");
@@ -69,6 +75,4 @@ describe("Behaves as expected", () => {
expect(sso).toMatchEndpointSuccessObject(endpoint);
await database.removePackageByName("get-package-test", true);
});
-
-
});
diff --git a/tests/http/getPackagesSearch.test.js b/tests/http/getPackagesSearch.test.js
index bdfb1806..f57b699c 100644
--- a/tests/http/getPackagesSearch.test.js
+++ b/tests/http/getPackagesSearch.test.js
@@ -3,61 +3,59 @@ const database = require("../../src/database.js");
const context = require("../../src/context.js");
describe("Behaves as expected", () => {
-
beforeAll(async () => {
await database.insertNewPackage({
name: "get-packages-search-theme-test",
repository: {
url: "https://github.com/getPackagesSearch/get-packages-search-theme-test",
- type: "git"
+ type: "git",
},
owner: "getPackagesSearch",
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: {
name: "get-packages-search-theme-test",
- theme: "syntax"
+ theme: "syntax",
},
versions: {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "get-packages-search-theme-test"
- }
- }
+ name: "get-packages-search-theme-test",
+ },
+ },
});
await database.insertNewPackage({
name: "get-packages-search-test",
repository: {
url: "https://github.com/getPackagesSearch/get-packages-search-test",
- type: "git"
+ type: "git",
},
owner: "getPackagesSearch",
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: {
- name: "get-packages-search-test"
+ name: "get-packages-search-test",
},
versions: {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "get-packages-search-test"
- }
- }
+ name: "get-packages-search-test",
+ },
+ },
});
-
});
afterAll(async () => {
@@ -66,13 +64,16 @@ describe("Behaves as expected", () => {
});
test("Successfully searches", async () => {
- let sso = await endpoint.logic({
- sort: "downloads",
- page: 1,
- direction: "desc",
- query: "get packages search",
- filter: "package"
- }, context);
+ let sso = await endpoint.logic(
+ {
+ sort: "downloads",
+ page: 1,
+ direction: "desc",
+ query: "get packages search",
+ filter: "package",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content.length).toBe(2);
@@ -82,13 +83,16 @@ describe("Behaves as expected", () => {
});
test("Successfully searches and filters by theme", async () => {
- let sso = await endpoint.logic({
- sort: "downloads",
- page: 1,
- direction: "desc",
- query: "get packages search",
- filter: "theme"
- }, context);
+ let sso = await endpoint.logic(
+ {
+ sort: "downloads",
+ page: 1,
+ direction: "desc",
+ query: "get packages search",
+ filter: "theme",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content.length).toBe(1);
diff --git a/tests/http/getThemes.test.js b/tests/http/getThemes.test.js
index 4e37991d..d28bcab2 100644
--- a/tests/http/getThemes.test.js
+++ b/tests/http/getThemes.test.js
@@ -3,7 +3,6 @@ const database = require("../../src/database.js");
const context = require("../../src/context.js");
describe("Behaves as expected", () => {
-
test("Calls the correct function", async () => {
const context = require("../../src/context.js");
const localContext = context;
@@ -22,7 +21,7 @@ describe("Behaves as expected", () => {
{
page: "1",
sort: "downloads",
- direction: "desc"
+ direction: "desc",
},
context
);
@@ -31,10 +30,10 @@ describe("Behaves as expected", () => {
expect(sso.content).toBeArray();
expect(sso.content.length).toBe(0);
expect(sso.link).toBe(
- `<${context.config.server_url}/api/themes?page=0&sort=downloads&direction=desc>;`
- + ' rel="self", '
- + `<${context.config.server_url}/api/themes?page=0&sort=downloads&direction=desc>;`
- + ' rel="last"'
+ `<${context.config.server_url}/api/themes?page=0&sort=downloads&direction=desc>;` +
+ ' rel="self", ' +
+ `<${context.config.server_url}/api/themes?page=0&sort=downloads&direction=desc>;` +
+ ' rel="last"'
);
});
test("Returns proper data on success", async () => {
@@ -42,41 +41,41 @@ describe("Behaves as expected", () => {
name: "test-package",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
creation_method: "Test Package",
releases: {
- latest: "1.1.0"
+ latest: "1.1.0",
},
readme: "This is a readme!",
metadata: {
name: "test-package",
- theme: "syntax"
+ theme: "syntax",
},
owner: "confused-Techie",
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "test-package"
+ name: "test-package",
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "test-package"
- }
- }
+ name: "test-package",
+ },
+ },
});
const sso = await endpoint.logic(
{
page: "1",
sort: "downloads",
- direction: "desc"
+ direction: "desc",
},
context
);
@@ -87,10 +86,10 @@ describe("Behaves as expected", () => {
expect(sso.content[0].name).toBe("test-package");
expect(sso.content[0].owner).toBe("confused-Techie");
expect(sso.link).toBe(
- `<${context.config.server_url}/api/themes?page=1&sort=downloads&direction=desc>;`
- + ' rel="self", '
- + `<${context.config.server_url}/api/themes?page=1&sort=downloads&direction=desc>;`
- + ' rel="last"'
+ `<${context.config.server_url}/api/themes?page=1&sort=downloads&direction=desc>;` +
+ ' rel="self", ' +
+ `<${context.config.server_url}/api/themes?page=1&sort=downloads&direction=desc>;` +
+ ' rel="last"'
);
expect(sso).toMatchEndpointSuccessObject(endpoint);
await database.removePackageByName("test-package", true);
@@ -99,14 +98,16 @@ describe("Behaves as expected", () => {
test("Returns bad SSO on failure", async () => {
const localContext = context;
localContext.database = {
- getSortedPackages: () => { return { ok: false, content: "Test Failure" }; }
+ getSortedPackages: () => {
+ return { ok: false, content: "Test Failure" };
+ },
};
const sso = await endpoint.logic(
{
page: "1",
sort: "downloads",
- direction: "desc"
+ direction: "desc",
},
localContext
);
diff --git a/tests/http/getThemesFeatured.test.js b/tests/http/getThemesFeatured.test.js
index 04423064..e5197c2e 100644
--- a/tests/http/getThemesFeatured.test.js
+++ b/tests/http/getThemesFeatured.test.js
@@ -27,34 +27,34 @@ describe("Behaves as expected", () => {
name: "atom-material-ui",
repository: {
url: "https://github.com/confused-Techie/atom-material-ui",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
releases: {
- latest: "1.1.0"
+ latest: "1.1.0",
},
readme: "This is a readme!",
metadata: {
name: "atom-material-ui",
- theme: "ui"
+ theme: "ui",
},
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "atom-material-ui"
+ name: "atom-material-ui",
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "atom-material-ui"
- }
- }
+ name: "atom-material-ui",
+ },
+ },
});
const sso = await endpoint.logic({}, context);
diff --git a/tests/http/getThemesSearch.test.js b/tests/http/getThemesSearch.test.js
index 349e7485..b260806d 100644
--- a/tests/http/getThemesSearch.test.js
+++ b/tests/http/getThemesSearch.test.js
@@ -15,12 +15,15 @@ describe("Behaves as expected", () => {
});
test("Returns zero length array when not found", async () => {
- const sso = await endpoint.logic({
- sort: "downloads",
- page: "1",
- direction: "desc",
- query: "hello-world"
- }, context);
+ const sso = await endpoint.logic(
+ {
+ sort: "downloads",
+ page: "1",
+ direction: "desc",
+ query: "hello-world",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content).toBeArray();
@@ -32,42 +35,45 @@ describe("Behaves as expected", () => {
name: "atom-material-syntax",
repository: {
url: "https://github.com/confused-Techie/atom-material-syntax",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
releases: {
- latest: "1.1.0"
+ latest: "1.1.0",
},
readme: "This is a readme!",
metadata: {
name: "atom-material-syntax",
- theme: "ui"
+ theme: "ui",
},
versions: {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "atom-material-syntax"
+ name: "atom-material-syntax",
},
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "atom-material-syntax"
- }
- }
+ name: "atom-material-syntax",
+ },
+ },
});
- const sso = await endpoint.logic({
- sort: "downloads",
- page: "1",
- direction: "desc",
- query: "atom-material"
- }, context);
+ const sso = await endpoint.logic(
+ {
+ sort: "downloads",
+ page: "1",
+ direction: "desc",
+ query: "atom-material",
+ },
+ context
+ );
expect(sso.ok).toBe(true);
expect(sso.content).toBeArray();
@@ -81,15 +87,20 @@ describe("Behaves as expected", () => {
// Moved to last position, since it modifies our shallow copied context
const localContext = context;
localContext.database = {
- simpleSearch: () => { return { ok: false, content: "Test Error" } }
+ simpleSearch: () => {
+ return { ok: false, content: "Test Error" };
+ },
};
- const sso = await endpoint.logic({
- sort: "downloads",
- page: "1",
- direction: "desc",
- query: "hello-world"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ sort: "downloads",
+ page: "1",
+ direction: "desc",
+ query: "hello-world",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.content.content).toBe("Test Error");
diff --git a/tests/http/getUsers.test.js b/tests/http/getUsers.test.js
index ebf0bb1b..410b994a 100644
--- a/tests/http/getUsers.test.js
+++ b/tests/http/getUsers.test.js
@@ -4,11 +4,12 @@ const context = require("../../src/context.js");
const userObject = require("../models/userObjectPrivate.js");
describe("Behaves as expected", () => {
-
test("Calls the correct function", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: false }; }
+ verifyAuth: () => {
+ return { ok: false };
+ },
};
const spy = jest.spyOn(localContext.auth, "verifyAuth");
@@ -23,7 +24,9 @@ describe("Behaves as expected", () => {
test("Returns bad SSO on failure", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: false, content: "A test fail" }; }
+ verifyAuth: () => {
+ return { ok: false, content: "A test fail" };
+ },
};
const sso = await endpoint.logic({}, localContext);
@@ -41,9 +44,9 @@ describe("Behaves as expected", () => {
verifyAuth: () => {
return {
ok: true,
- content: testUser
+ content: testUser,
};
- }
+ },
};
const sso = await endpoint.logic({}, localContext);
@@ -58,16 +61,19 @@ describe("Extra functions behave", () => {
test("preLogic adds headers as needed", async () => {
const headerObj = {};
const res = {
- header: (name, val) => { headerObj[name] = val; }
+ header: (name, val) => {
+ headerObj[name] = val;
+ },
};
await endpoint.preLogic({}, res, {});
const expected = {
"Access-Control-Allow-Methods": "GET",
- "Access-Control-Allow-Headers": "Content-Type, Authorization, Access-Control-Allow-Credentials",
+ "Access-Control-Allow-Headers":
+ "Content-Type, Authorization, Access-Control-Allow-Credentials",
"Access-Control-Allow-Origin": "https://web.pulsar-edit.dev",
- "Access-Control-Allow-Credentials": true
+ "Access-Control-Allow-Credentials": true,
};
expect(headerObj).toMatchObject(expected);
@@ -77,13 +83,15 @@ describe("Extra functions behave", () => {
let headerObj = {};
const res = {
- set: (obj) => { headerObj = obj; }
+ set: (obj) => {
+ headerObj = obj;
+ },
};
await endpoint.postLogic({}, res, {});
const expected = {
- "Access-Control-Allow-Credentials": true
+ "Access-Control-Allow-Credentials": true,
};
expect(headerObj).toMatchObject(expected);
diff --git a/tests/http/getUsersLogin.test.js b/tests/http/getUsersLogin.test.js
index 19012752..194259ef 100644
--- a/tests/http/getUsersLogin.test.js
+++ b/tests/http/getUsersLogin.test.js
@@ -4,7 +4,6 @@ const context = require("../../src/context.js");
const userObject = require("../models/userObjectPublic.js");
describe("Behaves as expected", () => {
-
test("Calls the correct db function", async () => {
const localContext = context;
const spy = jest.spyOn(localContext.database, "getUserByName");
@@ -34,7 +33,7 @@ describe("Behaves as expected", () => {
const res = await endpoint.logic(
{
- login: userObj.username
+ login: userObj.username,
},
context
);
diff --git a/tests/http/postPackages.test.js b/tests/http/postPackages.test.js
index f3849500..e17ce2cc 100644
--- a/tests/http/postPackages.test.js
+++ b/tests/http/postPackages.test.js
@@ -3,14 +3,13 @@ const database = require("../../src/database.js");
const context = require("../../src/context.js");
describe("POST /api/packages Behaves as expected", () => {
-
test("Fails with 'unauthorized' when bad token is passed", async () => {
const localContext = context;
localContext.auth.verifyAuth = () => {
return {
ok: false,
short: "unauthorized",
- content: "Bad Auth Mock Return"
+ content: "Bad Auth Mock Return",
};
};
@@ -30,15 +29,18 @@ describe("POST /api/packages Behaves as expected", () => {
id: 9999,
node_id: "post-pkg-publish-test-user-node-id",
username: "post-pkg-publish-test-user",
- avatar: "https://roadtonowhere.com"
- }
+ avatar: "https://roadtonowhere.com",
+ },
};
};
- const sso = await endpoint.logic({
- repository: "",
- auth: "valid-token"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ repository: "",
+ auth: "valid-token",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.short).toBe("bad_repo");
@@ -54,15 +56,18 @@ describe("POST /api/packages Behaves as expected", () => {
id: 9999,
node_id: "post-pkg-publish-test-user-node-id",
username: "post-pkg-publish-test-user",
- avatar: "https://roadtonowhere.com"
- }
+ avatar: "https://roadtonowhere.com",
+ },
};
};
- const sso = await endpoint.logic({
- repository: "bad-format",
- auth: "valid-token"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ repository: "bad-format",
+ auth: "valid-token",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.short).toBe("bad_repo");
@@ -78,14 +83,14 @@ describe("POST /api/packages Behaves as expected", () => {
id: 9999,
node_id: "post-pkg-publish-test-user-node-id",
username: "post-pkg-publish-test-user",
- avatar: "https://roadtonowhere.com"
- }
+ avatar: "https://roadtonowhere.com",
+ },
};
};
localContext.vcs.ownership = () => {
return {
ok: true,
- content: "admin"
+ content: "admin",
};
};
localContext.vcs.newPackageData = () => {
@@ -95,14 +100,14 @@ describe("POST /api/packages Behaves as expected", () => {
name: "post-pkg-test-pkg-exists",
repository: {
url: "https://github.com/confused-Techie/post-pkg-test-pkg-exists",
- type: "git"
+ type: "git",
},
- owner: 'confused-Techie',
+ owner: "confused-Techie",
downloads: 0,
stargazers_count: 0,
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: { name: "post-pkg-test-pkg-exists" },
@@ -110,12 +115,12 @@ describe("POST /api/packages Behaves as expected", () => {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "post-pkg-test-pkg-exists"
- }
- }
- }
+ name: "post-pkg-test-pkg-exists",
+ },
+ },
+ },
};
};
@@ -123,10 +128,10 @@ describe("POST /api/packages Behaves as expected", () => {
name: "post-pkg-test-pkg-exists",
repository: {
url: "https://github.com/confused-Techie/post-pkg-test-pkg-exists",
- type: "git"
+ type: "git",
},
creation_method: "Test Package",
- owner: 'confused-Techie',
+ owner: "confused-Techie",
releases: { latest: "1.1.0" },
readme: "This is a readme!",
metadata: { name: "post-pkg-test-pkg-exists" },
@@ -134,17 +139,20 @@ describe("POST /api/packages Behaves as expected", () => {
"1.1.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "post-pkg-test-pkg-exists"
- }
- }
+ name: "post-pkg-test-pkg-exists",
+ },
+ },
});
- const sso = await endpoint.logic({
- repository: "confused-Techie/post-pkg-test-pkg-exists",
- auth: "valid-token"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ repository: "confused-Techie/post-pkg-test-pkg-exists",
+ auth: "valid-token",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.short).toBe("package_exists");
@@ -171,14 +179,14 @@ describe("POST /api/packages Behaves as expected", () => {
id: addUser.content.id,
node_id: addUser.content.node_id,
username: addUser.content.username,
- avatar: addUser.content.avatar
- }
+ avatar: addUser.content.avatar,
+ },
};
};
localContext.vcs.ownership = () => {
return {
ok: true,
- content: "admin"
+ content: "admin",
};
};
localContext.vcs.newPackageData = () => {
@@ -188,14 +196,14 @@ describe("POST /api/packages Behaves as expected", () => {
name: "post-pkg-test-pkg-name",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
- owner: 'confused-Techie',
+ owner: "confused-Techie",
downloads: 0,
stargazers_count: 0,
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: { name: "post-pkg-test-pkg-name" },
@@ -203,20 +211,23 @@ describe("POST /api/packages Behaves as expected", () => {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "post-pkg-test-pkg-name"
- }
- }
- }
+ name: "post-pkg-test-pkg-name",
+ },
+ },
+ },
};
};
- const sso = await endpoint.logic({
- repository: "confused-Techie/post-pkg-test-pkg-name",
- auth: "valid-token"
- }, localContext);
-
+ const sso = await endpoint.logic(
+ {
+ repository: "confused-Techie/post-pkg-test-pkg-name",
+ auth: "valid-token",
+ },
+ localContext
+ );
+
expect(sso.ok).toBe(true);
expect(sso.content.name).toBe("post-pkg-test-pkg-name");
expect(sso.content.releases.latest).toBe("1.0.0");
@@ -229,13 +240,16 @@ describe("POST /api/packages Behaves as expected", () => {
expect(packByVer.ok).toBe(true);
- packByVer = await context.utils.constructPackageObjectJSON(packByVer.content);
+ packByVer = await context.utils.constructPackageObjectJSON(
+ packByVer.content
+ );
expect(packByVer.name).toBe("post-pkg-test-pkg-name");
- expect(packByVer.dist.tarball).toContain("/api/packages/post-pkg-test-pkg-name/versions/1.0.0");
+ expect(packByVer.dist.tarball).toContain(
+ "/api/packages/post-pkg-test-pkg-name/versions/1.0.0"
+ );
// Cleanup
await database.removePackageByName("post-pkg-test-pkg-name", true);
});
-
});
diff --git a/tests/http/postPackagesPackageNameStar.test.js b/tests/http/postPackagesPackageNameStar.test.js
index 9734c02b..8bbff80e 100644
--- a/tests/http/postPackagesPackageNameStar.test.js
+++ b/tests/http/postPackagesPackageNameStar.test.js
@@ -9,7 +9,7 @@ describe("POST /api/packages/:packageName/star", () => {
return {
ok: false,
short: "unauthorized",
- content: "Bad Auth Mock Return"
+ content: "Bad Auth Mock Return",
};
};
@@ -29,15 +29,18 @@ describe("POST /api/packages/:packageName/star", () => {
id: 99999,
node_id: "post-pkg-star-test-user-node-id",
username: "post-pkg-star-test-user-node-id",
- avatar: "https://roadtonowhere.com"
- }
+ avatar: "https://roadtonowhere.com",
+ },
};
};
- const sso = await endpoint.logic({
- auth: "valid-token",
- packageName: "no-exist"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ auth: "valid-token",
+ packageName: "no-exist",
+ },
+ localContext
+ );
expect(sso.ok).toBe(false);
expect(sso.content.short).toBe("not_found");
@@ -48,12 +51,12 @@ describe("POST /api/packages/:packageName/star", () => {
name: "post-packages-star-test",
repository: {
url: "https://github.com/confused-Techie/package-backend",
- type: "git"
+ type: "git",
},
owner: "confused-Techie",
creation_method: "Test Package",
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
readme: "This is a readme!",
metadata: { name: "post-packages-star-test" },
@@ -61,14 +64,18 @@ describe("POST /api/packages/:packageName/star", () => {
"1.0.0": {
dist: {
tarball: "download-url",
- sha: "1234"
+ sha: "1234",
},
- name: "post-packages-star-test"
- }
- }
+ name: "post-packages-star-test",
+ },
+ },
});
- let addUser = await database.insertNewUser("post-pkg-star-test-user-node-id", "post-pkg-star-test-user-node-id", "https://roadtonowhere.com");
+ let addUser = await database.insertNewUser(
+ "post-pkg-star-test-user-node-id",
+ "post-pkg-star-test-user-node-id",
+ "https://roadtonowhere.com"
+ );
expect(addUser.ok).toBe(true);
@@ -82,15 +89,18 @@ describe("POST /api/packages/:packageName/star", () => {
id: addUser.content.id,
node_id: addUser.content.node_id,
username: addUser.content.username,
- avatar: addUser.content.avatar
- }
- }
+ avatar: addUser.content.avatar,
+ },
+ };
};
- const sso = await endpoint.logic({
- auth: "valid-token",
- packageName: "post-packages-star-test"
- }, localContext);
+ const sso = await endpoint.logic(
+ {
+ auth: "valid-token",
+ packageName: "post-packages-star-test",
+ },
+ localContext
+ );
expect(sso.ok).toBe(true);
expect(sso.content.name).toBe("post-packages-star-test");
diff --git a/tests/http/postPackagesPackageNameVersions.test.js b/tests/http/postPackagesPackageNameVersions.test.js
index 6b0624ec..61657c45 100644
--- a/tests/http/postPackagesPackageNameVersions.test.js
+++ b/tests/http/postPackagesPackageNameVersions.test.js
@@ -9,7 +9,7 @@ describe("POST /api/packages/:packageName/versions", () => {
return {
ok: false,
short: "unauthorized",
- context: "Bad Auth Mock Return"
+ context: "Bad Auth Mock Return",
};
};
diff --git a/tests/http/stars.test.js b/tests/http/stars.test.js
index 19b45e42..9354f2ff 100644
--- a/tests/http/stars.test.js
+++ b/tests/http/stars.test.js
@@ -17,7 +17,9 @@ describe("GET /api/stars", () => {
.get("/api/stars")
.set("Authorization", "invalid");
expect(res).toHaveHTTPCode(401);
- expect(res.body.message).toEqual("Unauthorized: Please update your token if you haven't done so recently.");
+ expect(res.body.message).toEqual(
+ "Unauthorized: Please update your token if you haven't done so recently."
+ );
tmpMock.mockClear();
});
diff --git a/tests/models/message.js b/tests/models/message.js
index eba46891..1540618c 100644
--- a/tests/models/message.js
+++ b/tests/models/message.js
@@ -1,21 +1,19 @@
module.exports = {
schema: {
- description: "A generic object that could contain status information or error messages.",
+ description:
+ "A generic object that could contain status information or error messages.",
type: "object",
- required: [
- "message"
- ],
+ required: ["message"],
properties: {
message: {
- type: "string"
- }
- }
+ type: "string",
+ },
+ },
},
example: {
- message: "This is some message content."
+ message: "This is some message content.",
},
- test:
- Joi.object({
- message: Joi.string().required()
- })
+ test: Joi.object({
+ message: Joi.string().required(),
+ }),
};
diff --git a/tests/models/packageObjectFull.js b/tests/models/packageObjectFull.js
index be552728..2a862121 100644
--- a/tests/models/packageObjectFull.js
+++ b/tests/models/packageObjectFull.js
@@ -3,8 +3,17 @@ module.exports = {
description: "A 'Package Object Full' of a package on the PPR.",
type: "object",
required: [
- "name", "readme", "metadata", "releases", "versions",
- "repository", "creation_method", "downloads", "stargazers_count", "badges", "owner"
+ "name",
+ "readme",
+ "metadata",
+ "releases",
+ "versions",
+ "repository",
+ "creation_method",
+ "downloads",
+ "stargazers_count",
+ "badges",
+ "owner",
],
properties: {
name: { type: "string" },
@@ -17,8 +26,8 @@ module.exports = {
downloads: { type: "string" },
stargazers_count: { type: "string" },
badges: { type: "array" },
- owner: { type: "string" }
- }
+ owner: { type: "string" },
+ },
},
example: {
// This is nearly the full return of `language-powershell-revised`
@@ -30,44 +39,50 @@ module.exports = {
// With the `dist` object added
dist: {
sha: "604a047247ded9df50e7325345405c93871868e5",
- tarball: "https://api.github.com/repos/confused-Techie/language-powershell-revised/tarball/refs/tags/v1.0.0"
+ tarball:
+ "https://api.github.com/repos/confused-Techie/language-powershell-revised/tarball/refs/tags/v1.0.0",
},
name: "language-powershell-revised",
engines: {
- atom: ">=1.0.0 <2.0.0"
+ atom: ">=1.0.0 <2.0.0",
},
license: "MIT",
version: "1.0.0",
keywords: [],
// This may be a repository object
- repository: "https://github.com/confused-Techie/language-powershell-revised",
- description: "Updated, revised PowerShell Syntax Highlighting Support in Pulsar."
+ repository:
+ "https://github.com/confused-Techie/language-powershell-revised",
+ description:
+ "Updated, revised PowerShell Syntax Highlighting Support in Pulsar.",
},
releases: {
- latest: "1.0.0"
+ latest: "1.0.0",
},
versions: {
"1.0.0": {
// This is the `package.json` of every version
// With a `dist` key added
dist: {
- tarball: "https://api.pulsar-edit.dev/api/packages/language-powershell-revised/versions/1.0.0/tarball"
+ tarball:
+ "https://api.pulsar-edit.dev/api/packages/language-powershell-revised/versions/1.0.0/tarball",
},
name: "language-powershell-revised",
engines: {
- atom: ">=1.0.0 <2.0.0"
+ atom: ">=1.0.0 <2.0.0",
},
license: "MIT",
version: "1.0.0",
keywords: [],
- repository: "https://github.com/confsued-Techie/language-powershell-revised",
- description: "Updated, revised PowerShell Syntax Highlighting Support in Pulsar"
- }
+ repository:
+ "https://github.com/confsued-Techie/language-powershell-revised",
+ description:
+ "Updated, revised PowerShell Syntax Highlighting Support in Pulsar",
+ },
},
repository: {
// This is the repo object for the VCS Service
url: "https://github.com/confsued-Techie/langauge-powershell-revised",
- type: "git"
+ type: "git",
},
// This can be either `User Made Package` or `Migrated Package`
creation_method: "User Made Package",
@@ -78,54 +93,55 @@ module.exports = {
// Some badges are baked in, some are applied at render time.
{
title: "Made for Pulsar!",
- type: "success"
- }
- ]
+ type: "success",
+ },
+ ],
},
- test:
- Joi.object({
- name: Joi.string().required(),
- readme: Joi.string().required(),
- metadata: Joi.object().required(),
- releases: Joi.object({
- latest: Joi.string().required()
- }).required(),
- owner: Joi.string().required(),
- versions: Joi.object().required(),
- repository: Joi.object({
- url: Joi.string().required(),
- type: Joi.string().valid(
- "git",
- "bit",
- "sfr",
- "lab",
- "berg",
- "unknown",
- "na"
- ).required()
- }).required(),
- creation_method: Joi.string().valid(
+ test: Joi.object({
+ name: Joi.string().required(),
+ readme: Joi.string().required(),
+ metadata: Joi.object().required(),
+ releases: Joi.object({
+ latest: Joi.string().required(),
+ }).required(),
+ owner: Joi.string().required(),
+ versions: Joi.object().required(),
+ repository: Joi.object({
+ url: Joi.string().required(),
+ type: Joi.string()
+ .valid("git", "bit", "sfr", "lab", "berg", "unknown", "na")
+ .required(),
+ }).required(),
+ creation_method: Joi.string()
+ .valid(
"User Made Package",
"Migrated from Atom.io",
"Test Package" // Should only be used during tests
- ).required(),
- downloads: Joi.string().pattern(/^[0-9]+$/).required(),
- stargazers_count: Joi.string().pattern(/^[0-9]+$/).required(),
- badges: Joi.array().items(
+ )
+ .required(),
+ downloads: Joi.string()
+ .pattern(/^[0-9]+$/)
+ .required(),
+ stargazers_count: Joi.string()
+ .pattern(/^[0-9]+$/)
+ .required(),
+ badges: Joi.array()
+ .items(
Joi.object({
- title: Joi.string().valid(
- "Outdated",
- "Made for Pulsar!",
- "Broken",
- "Archived",
- "Deprecated"
- ).required(),
- type: Joi.string().valid(
- "warn", "info", "success"
- ).required(),
+ title: Joi.string()
+ .valid(
+ "Outdated",
+ "Made for Pulsar!",
+ "Broken",
+ "Archived",
+ "Deprecated"
+ )
+ .required(),
+ type: Joi.string().valid("warn", "info", "success").required(),
text: Joi.string(),
- link: Joi.string()
+ link: Joi.string(),
})
- ).required()
- }).required()
+ )
+ .required(),
+ }).required(),
};
diff --git a/tests/models/packageObjectFullArray.js b/tests/models/packageObjectFullArray.js
index 6e397930..62729a75 100644
--- a/tests/models/packageObjectFullArray.js
+++ b/tests/models/packageObjectFullArray.js
@@ -1,12 +1,5 @@
module.exports = {
- schema: {
-
- },
- example: [
- require("./packageObjectFull.js").example
- ],
- test:
- Joi.array().items(
- require("./packageObjectFull.js").test
- ).required()
+ schema: {},
+ example: [require("./packageObjectFull.js").example],
+ test: Joi.array().items(require("./packageObjectFull.js").test).required(),
};
diff --git a/tests/models/packageObjectShort.js b/tests/models/packageObjectShort.js
index e0d0d969..8cdc89d8 100644
--- a/tests/models/packageObjectShort.js
+++ b/tests/models/packageObjectShort.js
@@ -3,8 +3,15 @@ module.exports = {
description: "A 'Package Object Short' of a package on the PPR.",
type: "object",
required: [
- "name", "readme", "metadata", "repository", "downloads", "stargazers_count",
- "releases", "badges", "owner"
+ "name",
+ "readme",
+ "metadata",
+ "repository",
+ "downloads",
+ "stargazers_count",
+ "releases",
+ "badges",
+ "owner",
],
properties: {
name: { type: "string" },
@@ -16,8 +23,8 @@ module.exports = {
stargazers_count: { type: "string" },
releases: { type: "object" },
badges: { type: "array" },
- owner: { type: "string" }
- }
+ owner: { type: "string" },
+ },
},
example: {
// Example taken from `platformio-ide-terminal`
@@ -30,105 +37,101 @@ module.exports = {
// This could be an author object
author: "Jeremy Ebneyamin",
engines: {
- atom: ">=1.12.2 <2.0.0"
+ atom: ">=1.12.2 <2.0.0",
},
license: "MIT",
version: "2.10.1",
homepage: "https://atom.io/packages/platformio=ide-terminal",
- keywords: [
- "PlatformIO",
- "terminal-plus",
- "terminal"
- ],
+ keywords: ["PlatformIO", "terminal-plus", "terminal"],
repository: "https://github.com/platformio/platformio-iatom-ide-terminal",
- description: "A terminal package for Atom, complete with themes, API and more for PlatformIO IDE. Fork of terminal-plus.",
+ description:
+ "A terminal package for Atom, complete with themes, API and more for PlatformIO IDE. Fork of terminal-plus.",
contributors: [
{
url: "http://platformio.org",
name: "Ivan Kravets",
- email: "me@kravets.com"
- }
+ email: "me@kravets.com",
+ },
],
dependencies: {
"term.js": "https://github.com/jeremyramin/term.js/tarball/master",
underscore: "^1.8.3",
"atom-psace-pen-views": "^2.2.0",
- "node-pty-prebuilt-multiarch": "^0.9.0"
+ "node-pty-prebuilt-multiarch": "^0.9.0",
},
- activationHooks: [
- "core:loaded-shell-encironmnet"
- ],
+ activationHooks: ["core:loaded-shell-encironmnet"],
consumedServices: {
"status-bar": {
versions: {
- "^1.0.0": "consumeStatusBar"
- }
- }
+ "^1.0.0": "consumeStatusBar",
+ },
+ },
},
providedServices: {
runInTerminal: {
versions: {
- "0.14.5": "provideRunInTerminal"
+ "0.14.5": "provideRunInTerminal",
},
- description: "Deprecated API for PlatformIO IDE 1.0"
- }
- }
+ description: "Deprecated API for PlatformIO IDE 1.0",
+ },
+ },
},
repository: {
url: "https://github.com/platformio/platformio-atom-ide-terminal",
- type: "git"
+ type: "git",
},
creation_method: "User Made Package",
downloads: "16997915",
stargazers_count: "1114",
releases: {
- latest: "2.10.1"
+ latest: "2.10.1",
},
- badges: []
+ badges: [],
},
- test:
- Joi.object({
- name: Joi.string().required(),
- readme: Joi.string().required(),
- metadata: Joi.object().required(),
- releases: Joi.object({
- latest: Joi.string().required()
- }).required(),
- owner: Joi.string().required(),
- repository: Joi.object({
- url: Joi.string().required(),
- type: Joi.string().valid(
- "git",
- "bit",
- "sfr",
- "lab",
- "berg",
- "unknown",
- "na"
- ).required()
- }).required(),
- creation_method: Joi.string().valid(
+ test: Joi.object({
+ name: Joi.string().required(),
+ readme: Joi.string().required(),
+ metadata: Joi.object().required(),
+ releases: Joi.object({
+ latest: Joi.string().required(),
+ }).required(),
+ owner: Joi.string().required(),
+ repository: Joi.object({
+ url: Joi.string().required(),
+ type: Joi.string()
+ .valid("git", "bit", "sfr", "lab", "berg", "unknown", "na")
+ .required(),
+ }).required(),
+ creation_method: Joi.string()
+ .valid(
"User Made Package",
"Migrated from Atom.io",
"Test Package" // Should only be used during tests
- ).required(),
- downloads: Joi.string().pattern(/^[0-9]+$/).required(),
- stargazers_count: Joi.string().pattern(/^[0-9]+$/).required(),
- badges:Joi.array().items(
+ )
+ .required(),
+ downloads: Joi.string()
+ .pattern(/^[0-9]+$/)
+ .required(),
+ stargazers_count: Joi.string()
+ .pattern(/^[0-9]+$/)
+ .required(),
+ badges: Joi.array()
+ .items(
Joi.object({
- title: Joi.string().valid(
- "Outdated",
- "Made for Pulsar!",
- "Broken",
- "Archived",
- "Deprecated"
- ).required(),
- type: Joi.string().valid(
- "warn", "info", "success"
- ).required(),
+ title: Joi.string()
+ .valid(
+ "Outdated",
+ "Made for Pulsar!",
+ "Broken",
+ "Archived",
+ "Deprecated"
+ )
+ .required(),
+ type: Joi.string().valid("warn", "info", "success").required(),
text: Joi.string(),
- link: Joi.string()
+ link: Joi.string(),
})
- ).required()
- }).required()
+ )
+ .required(),
+ }).required(),
};
diff --git a/tests/models/packageObjectShortArray.js b/tests/models/packageObjectShortArray.js
index bb27a389..887ea550 100644
--- a/tests/models/packageObjectShortArray.js
+++ b/tests/models/packageObjectShortArray.js
@@ -1,12 +1,5 @@
module.exports = {
- schema: {
-
- },
- example: [
- require("./packageObjectShort.js").example
- ],
- test:
- Joi.array().items(
- require("./packageObjectShort.js").test
- ).required()
+ schema: {},
+ example: [require("./packageObjectShort.js").example],
+ test: Joi.array().items(require("./packageObjectShort.js").test).required(),
};
diff --git a/tests/models/userObjectPrivate.js b/tests/models/userObjectPrivate.js
index 744b77b2..1bbc1fbd 100644
--- a/tests/models/userObjectPrivate.js
+++ b/tests/models/userObjectPrivate.js
@@ -2,32 +2,30 @@ module.exports = {
schema: {
description: "Privately returned information of users on Pulsar.",
type: "object",
- required: [
- "username", "avatar", "data", "created_at", "packages"
- ],
+ required: ["username", "avatar", "data", "created_at", "packages"],
properties: {
username: {
- type: "string"
+ type: "string",
},
avatar: {
- type: "string"
+ type: "string",
},
data: {
- type: "object"
+ type: "object",
},
node_id: {
- type: "string"
+ type: "string",
},
token: {
- type: "string"
+ type: "string",
},
created_at: {
- type: "string"
+ type: "string",
},
packages: {
- type: "array"
- }
- }
+ type: "array",
+ },
+ },
},
example: {
username: "confused-Techie",
@@ -36,16 +34,15 @@ module.exports = {
node_id: "users-node-id",
token: "user-api-token",
created_at: "2023-09-16T00:58:36.755Z",
- packages: []
+ packages: [],
},
- test:
- Joi.object({
- username: Joi.string().required(),
- avatar: Joi.string().required(),
- data: Joi.object().required(),
- node_id: Joi.string().required(),
- token: Joi.string().required(),
- created_at: Joi.string().required(),
- packages: Joi.array().required()
- })
+ test: Joi.object({
+ username: Joi.string().required(),
+ avatar: Joi.string().required(),
+ data: Joi.object().required(),
+ node_id: Joi.string().required(),
+ token: Joi.string().required(),
+ created_at: Joi.string().required(),
+ packages: Joi.array().required(),
+ }),
};
diff --git a/tests/models/userObjectPublic.js b/tests/models/userObjectPublic.js
index 1b0f97a3..0a0cff75 100644
--- a/tests/models/userObjectPublic.js
+++ b/tests/models/userObjectPublic.js
@@ -2,40 +2,37 @@ module.exports = {
schema: {
description: "Publicaly returned information of users on Pulsar.",
type: "object",
- required: [
- "username", "avatar", "data", "created_at", "packages"
- ],
+ required: ["username", "avatar", "data", "created_at", "packages"],
properties: {
username: {
- type: "string"
+ type: "string",
},
avatar: {
- type: "string"
+ type: "string",
},
data: {
- type: "object"
+ type: "object",
},
created_at: {
- type: "string"
+ type: "string",
},
packages: {
- type: "array"
- }
- }
+ type: "array",
+ },
+ },
},
example: {
username: "confused-Techie",
avatar: "https://avatar.url",
data: {},
created_at: "2023-09-16T00:58:36.755Z",
- packages: []
+ packages: [],
},
- test:
- Joi.object({
- username: Joi.string().required(),
- avatar: Joi.string().required(),
- data: Joi.object().required(),
- created_at: Joi.string().required(),
- packages: Joi.array().required()
- })
+ test: Joi.object({
+ username: Joi.string().required(),
+ avatar: Joi.string().required(),
+ data: Joi.object().required(),
+ created_at: Joi.string().required(),
+ packages: Joi.array().required(),
+ }),
};
diff --git a/tests/unit/controllers/deletePackagesPackageName.test.js b/tests/unit/controllers/deletePackagesPackageName.test.js
index 9acac063..81f61735 100644
--- a/tests/unit/controllers/deletePackagesPackageName.test.js
+++ b/tests/unit/controllers/deletePackagesPackageName.test.js
@@ -4,9 +4,9 @@ describe("Has features expected", () => {
test("endpoint features", () => {
const expected = {
method: "DELETE",
- paths: [ "/api/packages/:packageName", "/api/themes/:packageName" ],
+ paths: ["/api/packages/:packageName", "/api/themes/:packageName"],
rateLimit: "auth",
- successStatus: 204
+ successStatus: 204,
};
expect(endpoint.endpoint).toMatchObject(expected);
diff --git a/tests/unit/controllers/deletePackagesPackageNameStar.js b/tests/unit/controllers/deletePackagesPackageNameStar.js
index 7a84a507..c2d07773 100644
--- a/tests/unit/controllers/deletePackagesPackageNameStar.js
+++ b/tests/unit/controllers/deletePackagesPackageNameStar.js
@@ -4,9 +4,12 @@ describe("Has features expected", () => {
test("endpoint features", () => {
const expected = {
method: "DELETE",
- paths: [ "/api/packages/:packageName/star", "/api/themes/:packageName/star" ],
+ paths: [
+ "/api/packages/:packageName/star",
+ "/api/themes/:packageName/star",
+ ],
rateLimit: "auth",
- successStatus: 204
+ successStatus: 204,
};
expect(endpoint.endpoint).toMatchObject(expected);
diff --git a/tests/unit/controllers/deletePackagesPackageNameVersionsVersionName.test.js b/tests/unit/controllers/deletePackagesPackageNameVersionsVersionName.test.js
index cf5c9673..54f552e4 100644
--- a/tests/unit/controllers/deletePackagesPackageNameVersionsVersionName.test.js
+++ b/tests/unit/controllers/deletePackagesPackageNameVersionsVersionName.test.js
@@ -4,9 +4,12 @@ describe("Has features expected", () => {
test("endpoint features", () => {
const expected = {
method: "DELETE",
- paths: [ "/api/packages/:packageName/versions/:versionName", "/api/themes/:packageName/versions/:versionName" ],
+ paths: [
+ "/api/packages/:packageName/versions/:versionName",
+ "/api/themes/:packageName/versions/:versionName",
+ ],
rateLimit: "auth",
- successStatus: 204
+ successStatus: 204,
};
expect(endpoint.endpoint).toMatchObject(expected);
diff --git a/tests/unit/controllers/getRoot.test.js b/tests/unit/controllers/getRoot.test.js
index b81e64e9..0b0fe158 100644
--- a/tests/unit/controllers/getRoot.test.js
+++ b/tests/unit/controllers/getRoot.test.js
@@ -4,9 +4,9 @@ describe("Has features expected", () => {
test("Has correct endpoint features", () => {
const expected = {
method: "GET",
- paths: [ "/" ],
+ paths: ["/"],
rateLimit: "generic",
- successStatus: 200
+ successStatus: 200,
};
expect(endpoint.endpoint).toMatchObject(expected);
diff --git a/tests/unit/controllers/getStars.test.js b/tests/unit/controllers/getStars.test.js
index 022cfd7e..97b634e9 100644
--- a/tests/unit/controllers/getStars.test.js
+++ b/tests/unit/controllers/getStars.test.js
@@ -5,9 +5,9 @@ describe("Has features expected", () => {
test("Has correct endpoint features", () => {
const expected = {
method: "GET",
- paths: [ "/api/stars" ],
+ paths: ["/api/stars"],
rateLimit: "generic",
- successStatus: 200
+ successStatus: 200,
};
expect(endpoint.endpoint).toMatchObject(expected);
@@ -18,7 +18,9 @@ describe("Returns as expected", () => {
test("When 'auth.verifyAuth' fails", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: false, content: "Test Failure" }; }
+ verifyAuth: () => {
+ return { ok: false, content: "Test Failure" };
+ },
};
const res = await endpoint.logic({}, localContext);
@@ -31,10 +33,14 @@ describe("Returns as expected", () => {
test("When 'db.getStarredPointersByUserID' fails", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: true, content: { id: 1 } }; }
+ verifyAuth: () => {
+ return { ok: true, content: { id: 1 } };
+ },
};
localContext.database = {
- getStarredPointersByUserID: () => { return { ok: false, content: "db Test Failure" }; }
+ getStarredPointersByUserID: () => {
+ return { ok: false, content: "db Test Failure" };
+ },
};
const res = await endpoint.logic({}, localContext);
@@ -47,10 +53,14 @@ describe("Returns as expected", () => {
test("When the user has no stars", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: true, content: { id: 1 } }; }
+ verifyAuth: () => {
+ return { ok: true, content: { id: 1 } };
+ },
};
localContext.database = {
- getStarredPointersByUserID: () => { return { ok: true, content: [] }; }
+ getStarredPointersByUserID: () => {
+ return { ok: true, content: [] };
+ },
};
const res = await endpoint.logic({}, localContext);
@@ -63,11 +73,17 @@ describe("Returns as expected", () => {
test("When 'db.getPackageCollectionByID' fails", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: true, content: { id: 1 } }; }
+ verifyAuth: () => {
+ return { ok: true, content: { id: 1 } };
+ },
};
localContext.database = {
- getStarredPointersByUserID: () => { return { ok: true, content: [ "an_id" ] }; },
- getPackageCollectionByID: () => { return { ok: false, content: "Another DB Error" }; }
+ getStarredPointersByUserID: () => {
+ return { ok: true, content: ["an_id"] };
+ },
+ getPackageCollectionByID: () => {
+ return { ok: false, content: "Another DB Error" };
+ },
};
const res = await endpoint.logic({}, localContext);
@@ -79,14 +95,22 @@ describe("Returns as expected", () => {
test("When request succeeds", async () => {
const localContext = context;
localContext.auth = {
- verifyAuth: () => { return { ok: true, content: { id: 1 } }; }
+ verifyAuth: () => {
+ return { ok: true, content: { id: 1 } };
+ },
};
localContext.database = {
- getStarredPointersByUserID: () => { return { ok: true, content: [ "an_id" ] }; },
- getPackageCollectionByID: () => { return { ok: true, content: {} }; }
+ getStarredPointersByUserID: () => {
+ return { ok: true, content: ["an_id"] };
+ },
+ getPackageCollectionByID: () => {
+ return { ok: true, content: {} };
+ },
};
localContext.utils = {
- constructPackageObjectShort: () => { return { item: "is_a_package" }; }
+ constructPackageObjectShort: () => {
+ return { item: "is_a_package" };
+ },
};
const res = await endpoint.logic({}, localContext);
diff --git a/tests/unit/controllers/getThemes.test.js b/tests/unit/controllers/getThemes.test.js
index ff6e25a6..61bdb7c8 100644
--- a/tests/unit/controllers/getThemes.test.js
+++ b/tests/unit/controllers/getThemes.test.js
@@ -5,9 +5,9 @@ describe("Has features expected", () => {
test("Has correct endpoint features", () => {
const expected = {
method: "GET",
- paths: [ "/api/themes" ],
+ paths: ["/api/themes"],
rateLimit: "generic",
- successStatus: 200
+ successStatus: 200,
};
expect(endpoint.endpoint).toMatchObject(expected);
@@ -22,8 +22,8 @@ describe("Parameters behave as expected", () => {
test("Returns valid 'page'", () => {
const req = {
query: {
- page: "1"
- }
+ page: "1",
+ },
};
const res = endpoint.params.page(context, req);
@@ -32,8 +32,8 @@ describe("Parameters behave as expected", () => {
test("Returns valid 'sort'", () => {
const req = {
query: {
- sort: "downloads"
- }
+ sort: "downloads",
+ },
};
const res = endpoint.params.sort(context, req);
@@ -42,8 +42,8 @@ describe("Parameters behave as expected", () => {
test("Returns valid 'direction'", () => {
const req = {
query: {
- direction: "desc"
- }
+ direction: "desc",
+ },
};
const res = endpoint.params.direction(context, req);
diff --git a/tests/unit/controllers/getThemesSearch.test.js b/tests/unit/controllers/getThemesSearch.test.js
index 655d5fb7..22295eef 100644
--- a/tests/unit/controllers/getThemesSearch.test.js
+++ b/tests/unit/controllers/getThemesSearch.test.js
@@ -5,9 +5,9 @@ describe("Has features expected", () => {
test("Has correct endpoint features", () => {
const expected = {
method: "GET",
- paths: [ "/api/themes/search" ],
+ paths: ["/api/themes/search"],
rateLimit: "generic",
- successStatus: 200
+ successStatus: 200,
};
expect(endpoint.endpoint).toMatchObject(expected);
@@ -21,7 +21,7 @@ describe("Has features expected", () => {
describe("Parameters behave as expected", () => {
test("Returns valid 'sort'", () => {
const req = {
- query: { sort: "downloads" }
+ query: { sort: "downloads" },
};
const res = endpoint.params.sort(context, req);
@@ -29,7 +29,7 @@ describe("Parameters behave as expected", () => {
});
test("Returns valid 'page'", () => {
const req = {
- query: { page: "1" }
+ query: { page: "1" },
};
const res = endpoint.params.page(context, req);
@@ -37,7 +37,7 @@ describe("Parameters behave as expected", () => {
});
test("Returns valid 'direction'", () => {
const req = {
- query: { direction: "desc" }
+ query: { direction: "desc" },
};
const res = endpoint.params.direction(context, req);
@@ -45,7 +45,7 @@ describe("Parameters behave as expected", () => {
});
test("Returns valid 'query'", () => {
const req = {
- query: { q: "hello" }
+ query: { q: "hello" },
};
const res = endpoint.params.query(context, req);
diff --git a/tests/unit/controllers/getUpdates.test.js b/tests/unit/controllers/getUpdates.test.js
index 38797558..56372663 100644
--- a/tests/unit/controllers/getUpdates.test.js
+++ b/tests/unit/controllers/getUpdates.test.js
@@ -6,7 +6,7 @@ describe("Has features expected", () => {
method: "GET",
rateLimit: "generic",
successStatus: 200,
- paths: [ "/api/updates" ]
+ paths: ["/api/updates"],
};
expect(endpoint.endpoint).toMatchObject(expected);
@@ -19,13 +19,9 @@ describe("Has features expected", () => {
describe("Functions as expected", () => {
test("Returns correct SSO Object", async () => {
- const sso = await endpoint.logic(
- {},
- require("../../../src/context.js")
- );
+ const sso = await endpoint.logic({}, require("../../../src/context.js"));
expect(sso.ok).toBe(false);
expect(sso.short).toBe("not_supported");
-
});
});
diff --git a/tests/unit/controllers/getUsers.test.js b/tests/unit/controllers/getUsers.test.js
index 65ac2dca..81e1f42c 100644
--- a/tests/unit/controllers/getUsers.test.js
+++ b/tests/unit/controllers/getUsers.test.js
@@ -5,9 +5,9 @@ describe("Has features expected", () => {
test("Has correct endpoint features", () => {
const expected = {
method: "GET",
- paths: [ "/api/users" ],
+ paths: ["/api/users"],
rateLimit: "auth",
- successStatus: 200
+ successStatus: 200,
};
expect(endpoint.endpoint).toMatchObject(expected);
@@ -29,7 +29,7 @@ describe("Parameters function as expected", () => {
} else {
return "";
}
- }
+ },
};
const res = endpoint.params.auth(context, req);
@@ -39,7 +39,9 @@ describe("Parameters function as expected", () => {
test("Returns params when missing", () => {
const req = {
- get: () => { return ""; }
+ get: () => {
+ return "";
+ },
};
const res = endpoint.params.auth(context, req);
diff --git a/tests/unit/controllers/getUsersLogin.test.js b/tests/unit/controllers/getUsersLogin.test.js
index f475b58f..48d1e9ae 100644
--- a/tests/unit/controllers/getUsersLogin.test.js
+++ b/tests/unit/controllers/getUsersLogin.test.js
@@ -5,22 +5,21 @@ describe("Has features expected", () => {
test("Has correct endpoint features", () => {
const expected = {
method: "GET",
- paths: [ "/api/users/:login" ],
+ paths: ["/api/users/:login"],
rateLimit: "generic",
- successStatus: 200
+ successStatus: 200,
};
expect(endpoint.endpoint).toMatchObject(expected);
});
-
});
describe("Parameters function as expected", () => {
test("Returns params as provided", () => {
const req = {
params: {
- login: "test-user"
- }
+ login: "test-user",
+ },
};
const res = endpoint.params.login(context, req);
diff --git a/tests/unit/controllers/postPackagesPackageNameVersions.test.js b/tests/unit/controllers/postPackagesPackageNameVersions.test.js
index 5a1f860a..5272ffa3 100644
--- a/tests/unit/controllers/postPackagesPackageNameVersions.test.js
+++ b/tests/unit/controllers/postPackagesPackageNameVersions.test.js
@@ -5,7 +5,7 @@ describe("Has features expected", () => {
const expected = {
method: "POST",
rateLimit: "auth",
- successStatus: 201
+ successStatus: 201,
};
expect(endpoint.endpoint).toMatchObject(expected);
diff --git a/tests/unit/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.test.js b/tests/unit/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.test.js
index 9853c087..8b17dec4 100644
--- a/tests/unit/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.test.js
+++ b/tests/unit/controllers/postPackagesPackageNameVersionsVersionNameEventsUninstall.test.js
@@ -6,7 +6,7 @@ describe("Has features expected", () => {
const expected = {
method: "POST",
rateLimit: "auth",
- successStatus: 201
+ successStatus: 201,
};
expect(endpoint.endpoint).toMatchObject(expected);
diff --git a/tests/unit/endpoints.test.js b/tests/unit/endpoints.test.js
index b4c00381..5f4cd8a1 100644
--- a/tests/unit/endpoints.test.js
+++ b/tests/unit/endpoints.test.js
@@ -2,11 +2,8 @@ const endpoints = require("../../src/controllers/endpoints.js");
describe("All endpoints are valid", () => {
test("Have expected objects", () => {
-
for (const node of endpoints) {
-
for (const item in node) {
-
const validItems = [
"docs",
"endpoint",
@@ -14,13 +11,12 @@ describe("All endpoints are valid", () => {
"logic",
"preLogic",
"postLogic",
- "postReturnHTTP"
+ "postReturnHTTP",
];
expect(validItems.includes(item));
}
}
-
});
test("Have a valid 'endpoint' object", () => {
@@ -28,18 +24,17 @@ describe("All endpoints are valid", () => {
const endpoint = node.endpoint;
expect(endpoint.method).toBeTypeof("string");
- expect(endpoint.method).toBeIncludedBy([ "GET", "POST", "DELETE" ]);
+ expect(endpoint.method).toBeIncludedBy(["GET", "POST", "DELETE"]);
expect(endpoint.paths).toBeArray();
expect(endpoint.rateLimit).toBeTypeof("string");
- expect(endpoint.rateLimit).toBeIncludedBy([ "generic", "auth" ]);
+ expect(endpoint.rateLimit).toBeIncludedBy(["generic", "auth"]);
expect(endpoint.successStatus).toBeTypeof("number");
expect(endpoint.options).toBeDefined();
if (endpoint.endpointKind) {
expect(endpoint.endpointKind).toBeTypeof("string");
- expect(endpoint.endpointKind).toBeIncludedBy([ "raw", "default" ]);
+ expect(endpoint.endpointKind).toBeIncludedBy(["raw", "default"]);
}
}
-
});
});
diff --git a/tests/unit/query.test.js b/tests/unit/query.test.js
index cb907a12..ca681da7 100644
--- a/tests/unit/query.test.js
+++ b/tests/unit/query.test.js
@@ -180,7 +180,7 @@ describe("Verify fileExtension Returns", () => {
const ownerCases = [
[{ query: { owner: "savetheclocktower" } }, "savetheclocktower"],
- [{ query: { owner: '' } }, false],
+ [{ query: { owner: "" } }, false],
[{ query: { owner: 101 } }, false],
[{ query: {} }, false],
];