@creator.co/wapi 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +6 -1
- package/dist/src/API/Request.d.ts +45 -82
- package/dist/src/API/Request.js +49 -77
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +94 -163
- package/dist/src/API/Response.js +101 -161
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +21 -42
- package/dist/src/API/Utils.js +22 -43
- package/dist/src/API/Utils.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
- package/dist/src/BaseEvent/EventProcessor.js +30 -38
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +20 -43
- package/dist/src/BaseEvent/Process.js +16 -27
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +94 -2
- package/dist/src/BaseEvent/Transaction.js +49 -4
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +48 -66
- package/dist/src/Config/Configuration.js +25 -42
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.d.ts +30 -57
- package/dist/src/Config/EnvironmentVar.js +28 -41
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +17 -35
- package/dist/src/Crypto/Crypto.js +12 -21
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +21 -32
- package/dist/src/Crypto/JWT.js +14 -22
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Globals.d.ts +26 -94
- package/dist/src/Globals.js +26 -95
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.d.ts +82 -105
- package/dist/src/Logger/Logger.js +111 -136
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +39 -75
- package/dist/src/Mailer/Mailer.js +36 -65
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.d.ts +17 -25
- package/dist/src/Publisher/Publisher.js +21 -32
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.d.ts +14 -22
- package/dist/src/Server/RouteResolver.js +21 -34
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +72 -51
- package/dist/src/Server/Router.js +8 -17
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
- package/dist/src/Server/lib/ContainerServer.js +13 -28
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.d.ts +17 -32
- package/dist/src/Server/lib/Server.js +18 -28
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
- package/dist/src/Server/lib/container/GenericHandler.js +16 -3
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
- package/dist/src/Server/lib/container/Proxy.js +49 -50
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.d.ts +6 -10
- package/dist/src/Server/lib/container/Utils.js +6 -10
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.d.ts +9 -13
- package/dist/src/Validation/Validator.js +8 -12
- package/dist/src/Validation/Validator.js.map +1 -1
- package/index.ts +15 -0
- package/package.json +6 -1
- package/src/API/Request.ts +66 -84
- package/src/API/Response.ts +144 -203
- package/src/API/Utils.ts +28 -44
- package/src/BaseEvent/EventProcessor.ts +52 -77
- package/src/BaseEvent/Process.ts +27 -52
- package/src/BaseEvent/Transaction.ts +100 -10
- package/src/Config/Configuration.ts +59 -76
- package/src/Config/EnvironmentVar.ts +39 -62
- package/src/Crypto/Crypto.ts +20 -36
- package/src/Crypto/JWT.ts +31 -35
- package/src/Globals.ts +28 -96
- package/src/Logger/Logger.ts +141 -160
- package/src/Mailer/Mailer.ts +43 -76
- package/src/Publisher/Publisher.ts +31 -40
- package/src/Server/RouteResolver.ts +31 -52
- package/src/Server/Router.ts +75 -54
- package/src/Server/lib/ContainerServer.ts +20 -32
- package/src/Server/lib/Server.ts +19 -34
- package/src/Server/lib/container/GenericHandler.ts +17 -3
- package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
- package/src/Server/lib/container/HealthHandler.ts +6 -0
- package/src/Server/lib/container/Proxy.ts +37 -57
- package/src/Server/lib/container/Utils.ts +7 -10
- package/src/Validation/Validator.ts +11 -13
- package/tests/API/Response.test.ts +55 -56
- package/tests/BaseEvent/EventProcessor.test.ts +49 -50
- package/tests/BaseEvent/Process.test.ts +2 -2
- package/tests/BaseEvent/Transaction.test.ts +48 -49
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Publisher/Publisher.test.ts +3 -3
- package/tests/Server/lib/ContainerServer.test.ts +21 -22
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
- package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
- package/tests/Server/lib/container/Proxy.test.ts +37 -35
- package/tsconfig.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,217 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WAPI - Web Application Programming Interface
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
**WAPI** is a powerful API wrapper designed to streamline web application development. It offers opinionated abstractions, simplifying common web development tasks. At its core, WAPI revolves around the concept of **transactions**, which can be applied in diverse scenarios, including handling async events, managing message queues, running AWS Lambda functions, and creating hybrid HTTP servers that seamlessly blend serverless and container-based approaches.
|
|
4
|
+
|
|
5
|
+
-    
|
|
6
|
+
- 
|
|
7
|
+
- 
|
|
8
|
+
|
|
9
|
+
## 📖 Table of Contents
|
|
10
|
+
- [📖 Table of Contents](#-table-of-contents)
|
|
11
|
+
- [📍 Overview](#-overview)
|
|
12
|
+
- [📦 Features](#-features)
|
|
13
|
+
- [⚙️ Modules](#modules)
|
|
14
|
+
- [🚀 Getting Started](#-getting-started)
|
|
15
|
+
- [🔧 Installation](#-installation)
|
|
16
|
+
- [🤖 Running .](#-running-.)
|
|
17
|
+
- [🧪 Tests](#-tests)
|
|
18
|
+
- [🤝 Contributing](#-contributing)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 📍 Overview
|
|
23
|
+
|
|
24
|
+
The project is a TypeScript application that provides a collection of modules for handling transactions, managing processes, routing requests, sending emails, performing cryptographic operations, managing configuration settings, constructing HTTP responses, and providing utility functions and route definitions. It also includes tools for logging messages, validating data, and working with JSON Web Tokens. The core functionalities of the project revolve around helping developers build robust web applications and simplify common development tasks, such as handling requests, managing processes, and ensuring secure communication. Its value proposition lies in providing a comprehensive set of reusable components and abstractions that streamline the development process and improve the overall stability and security of web applications.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 📦 Features
|
|
29
|
+
|
|
30
|
+
Opinionated Framework Wrapping: WAPI offers opinionated abstractions to simplify common web development tasks and guide developers towards best practices.
|
|
31
|
+
|
|
32
|
+
Transaction-Based Architecture: The core concept of transactions simplifies request and response handling, ensuring reliability and consistency.
|
|
33
|
+
|
|
34
|
+
Support for Async Events: WAPI excels at handling asynchronous events, making it ideal for managing background processes and event-driven workflows.
|
|
35
|
+
|
|
36
|
+
Message Queue Integration: Seamlessly integrate WAPI with message queues, simplifying the creation of distributed systems and asynchronous message processing.
|
|
37
|
+
|
|
38
|
+
AWS Lambda Functionality: Deploy your code as AWS Lambda functions with ease, providing scalability and flexibility for your applications.
|
|
39
|
+
|
|
40
|
+
Hybrid HTTP Servers: Create hybrid HTTP servers that seamlessly combine serverless and container-based architectures, allowing deployment in various environments.
|
|
41
|
+
|
|
42
|
+
Crypto Utilities: WAPI provides utility classes for cryptographic operations, including encryption and decryption using AWS KMS. Securely manage sensitive data with ease.
|
|
43
|
+
|
|
44
|
+
Email Sending: The Mailer class simplifies sending emails using AWS SES. Send both raw and templated emails with customizable parameters, enhancing communication capabilities.
|
|
45
|
+
|
|
46
|
+
## ⚙️ Modules
|
|
47
|
+
|
|
48
|
+
<details closed><summary>Root</summary>
|
|
49
|
+
|
|
50
|
+
| File | Summary |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| [.eslintrc.cjs](https://github.com/Creator-co/Wapi/blob/main/.eslintrc.cjs) | The code defines the linting rules for a TypeScript project. It extends recommended configurations, adds TypeScript-specific rules, and enables Prettier formatting. It also sets rules for imports ordering and disables certain rules. |
|
|
53
|
+
| [index.ts](https://github.com/Creator-co/Wapi/blob/main/index.ts) | This code provides modules for handling transactions, managing processes, processing events, routing requests, sending emails, performing cryptographic operations, handling JSON Web Tokens, managing configuration settings, constructing HTTP responses, and providing utility functions and route definitions. |
|
|
54
|
+
| [.eslintignore](https://github.com/Creator-co/Wapi/blob/main/.eslintignore) | The.eslintignore file specifies file and directory patterns to exclude from linting using ESLint. In this case, it excludes the node_modules directory and the dist directory from being checked for linting issues. |
|
|
55
|
+
| [jest.config.ts](https://github.com/Creator-co/Wapi/blob/main/jest.config.ts) | This code is a Jest configuration file that sets up the testing environment for a TypeScript project. It includes options for generating code coverage reports in various formats, setting coverage thresholds, and configuring reporters for test results. |
|
|
56
|
+
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
<details closed><summary>Workflows</summary>
|
|
60
|
+
|
|
61
|
+
| File | Summary |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| [npmpublish.yml](https://github.com/Creator-co/Wapi/blob/main/.github/workflows/npmpublish.yml) | This code is a GitHub workflow that runs when code is pushed to the "main" or "gabe/tweaks" branches. It uses a tool to publish an NPM package, using Node version 16.x. |
|
|
64
|
+
| [prs.yml](https://github.com/Creator-co/Wapi/blob/main/.github/workflows/prs.yml) | This code sets up a GitHub workflow that runs checks on pull requests (PRs) targeting the'master' or'main' branches. It uses a predefined workflow template called'prs-check.yml' and inherits secrets. The specified Node.js version is 16.x. |
|
|
65
|
+
|
|
66
|
+
</details>
|
|
67
|
+
|
|
68
|
+
<details closed><summary>Src</summary>
|
|
69
|
+
|
|
70
|
+
| File | Summary |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| [Globals.ts](https://github.com/Creator-co/Wapi/blob/main/src/Globals.ts) | The code in Globals.ts contains global constants and configurations for the application. It includes error messages, error codes, default values for HTTP listeners, and response messages and codes for exceptions. |
|
|
73
|
+
|
|
74
|
+
</details>
|
|
75
|
+
|
|
76
|
+
<details closed><summary>Crypto</summary>
|
|
77
|
+
|
|
78
|
+
| File | Summary |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| [JWT.ts](https://github.com/Creator-co/Wapi/blob/main/src/Crypto/JWT.ts) | The code in JWT.ts provides functionalities to create and validate JSON Web Tokens (JWTs). It includes methods to generate a JWT given data and options, as well as to validate a JWT and return a response indicating its validity. The class has a constructor that sets the token secret and default expiration time. Overall, the code enables secure token generation and verification. |
|
|
81
|
+
| [Crypto.ts](https://github.com/Creator-co/Wapi/blob/main/src/Crypto/Crypto.ts) | The Crypto class provides encryption and decryption functionality using AWS KMS. It encrypts data using RSAES_OAEP_SHA_256 encryption algorithm and decrypts data using the same algorithm. The class requires an AWS region and a KMS key ID to perform encryption and decryption operations. |
|
|
82
|
+
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
<details closed><summary>Logger</summary>
|
|
86
|
+
|
|
87
|
+
| File | Summary |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| [Logger.ts](https://github.com/Creator-co/Wapi/blob/main/src/Logger/Logger.ts) | The Logger class is used for logging messages with different log levels. It provides functions for logging debug, info, warning, and error messages. The class can be configured with a log level and sensitive filtering keywords. It also has a blacklist of sensitive strings that can be excluded from logs. The logger formats the log messages and logs them using the console object. |
|
|
90
|
+
|
|
91
|
+
</details>
|
|
92
|
+
|
|
93
|
+
<details closed><summary>Config</summary>
|
|
94
|
+
|
|
95
|
+
| File | Summary |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| [EnvironmentVar.ts](https://github.com/Creator-co/Wapi/blob/main/src/Config/EnvironmentVar.ts) | The code defines a class called EnvironmentVar that represents an environment variable. It has methods to resolve the value of the variable based on the environment type (local, plain remote, secure remote). It uses AWS SDK clients to retrieve the values from AWS SSM and Secrets Manager. |
|
|
98
|
+
| [Configuration.ts](https://github.com/Creator-co/Wapi/blob/main/src/Config/Configuration.ts) | The code in the Configuration.ts file defines a Configuration class that allows retrieving values from environment variables or cache. It utilizes a schema to determine the properties to retrieve and their attributes. The class supports both synchronous and asynchronous retrieval of values, and also provides caching functionality. |
|
|
99
|
+
|
|
100
|
+
</details>
|
|
101
|
+
|
|
102
|
+
<details closed><summary>Publisher</summary>
|
|
103
|
+
|
|
104
|
+
| File | Summary |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| [Publisher.ts](https://github.com/Creator-co/Wapi/blob/main/src/Publisher/Publisher.ts) | This code defines a Publisher class that can publish messages to an SNS topic. It establishes a connection to the SNS client and provides a method to publish messages on a specified topic. |
|
|
107
|
+
|
|
108
|
+
</details>
|
|
109
|
+
|
|
110
|
+
<details closed><summary>Server</summary>
|
|
111
|
+
|
|
112
|
+
| File | Summary |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| [Router.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/Router.ts) | The code is defining a Router class that handles routing logic for a web application. It includes functionalities such as configuring routes, listening on a port, setting a timeout, enabling CORS, and implementing a health check endpoint. The router can be used to handle different types of transactions and execute corresponding handlers. |
|
|
115
|
+
| [RouteResolver.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/RouteResolver.ts) | The code implements a RouteResolver class that resolves routes based on provided configurations. It builds a routing system using a Routes class to add and resolve routes. The resolveRoute method takes an HTTP method and path and returns the resolved route, or undefined if not found. The buildRoutes method constructs the routes based on the given configuration. |
|
|
116
|
+
|
|
117
|
+
</details>
|
|
118
|
+
|
|
119
|
+
<details closed><summary>Lib</summary>
|
|
120
|
+
|
|
121
|
+
| File | Summary |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| [ContainerServer.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/ContainerServer.ts) | The ContainerServer class extends the Server class and handles serverless events. It utilizes a Proxy object for handling requests and responses. The class has methods for starting and stopping the server, as well as handling process events. The getExport method returns a callable function for exporting data. |
|
|
124
|
+
| [Server.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/Server.ts) | The Server class handles serverless events by executing transactions and resolving routes based on the event. It validates input, parses path parameters, and calls the appropriate route handler. |
|
|
125
|
+
|
|
126
|
+
</details>
|
|
127
|
+
|
|
128
|
+
<details closed><summary>Container</summary>
|
|
129
|
+
|
|
130
|
+
| File | Summary |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| [HealthHandler.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/container/HealthHandler.ts) | The code in HealthHandler.ts defines a function that handles a request and sends a response with the message'Healthy!'. It takes in a request object and a response object, and returns nothing. |
|
|
133
|
+
| [GenericHandler.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/container/GenericHandler.ts) | This code defines a function that handles HTTP requests by invoking a serverless function and processing the response. It also includes a helper function to translate the serverless response to HTTP and send it back to the client. |
|
|
134
|
+
| [Utils.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/container/Utils.ts) | The code provides two functions for parsing query string parameters from a given URL.-`parseMultiValueQueryStringParameters` parses multi-value query parameters into an object, allowing multiple values for the same key.-`parseQueryStringParameters` parses query parameters into an object, without support for multiple values. |
|
|
135
|
+
| [GenericHandlerEvent.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/container/GenericHandlerEvent.ts) | The code is a TypeScript class that represents a generic handler event for serverless functions. It builds an APIGatewayProxyEvent object based on an HTTP request and provides methods to invoke the serverless handler function and build the context object for an AWS Lambda function. |
|
|
136
|
+
| [Proxy.ts](https://github.com/Creator-co/Wapi/blob/main/src/Server/lib/container/Proxy.ts) | The code defines a Proxy class that handles routing and server functionality. It creates an Express application, sets up middleware, starts listeners, and installs routes. It also provides methods to load, unload, and stop the listeners. |
|
|
137
|
+
|
|
138
|
+
</details>
|
|
139
|
+
|
|
140
|
+
<details closed><summary>Mailer</summary>
|
|
141
|
+
|
|
142
|
+
| File | Summary |
|
|
143
|
+
| --- | --- |
|
|
144
|
+
| [Mailer.ts](https://github.com/Creator-co/Wapi/blob/main/src/Mailer/Mailer.ts) | The Mailer class is responsible for sending emails using AWS SES. It provides functions to send raw emails and templated emails with customizable parameters. It also includes methods for creating a new SMTP transporter and choosing the appropriate template based on the provided data. |
|
|
145
|
+
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
<details closed><summary>Api</summary>
|
|
149
|
+
|
|
150
|
+
| File | Summary |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| [Utils.ts](https://github.com/Creator-co/Wapi/blob/main/src/API/Utils.ts) | The Utils class contains various static methods for common operations. It includes functions to check if the application is running in a hybridless container, validate strings, parse strings into integers, parse JSON strings, validate numbers, and retrieve values from objects using case-insensitive key lookup. |
|
|
153
|
+
| [Response.ts](https://github.com/Creator-co/Wapi/blob/main/src/API/Response.ts) | The code in the Response.ts file defines a class called Response, which represents an API response. It provides methods for manipulating and building the response, including handling errors, setting headers, and streaming the response. It also includes static methods for creating different types of API responses, such as success, error, redirect, and streaming responses. |
|
|
154
|
+
| [Request.ts](https://github.com/Creator-co/Wapi/blob/main/src/API/Request.ts) | The code defines a class called Request that provides utility methods for accessing request information in an API Gateway event. It can retrieve query parameters, headers, path parameters, request body, HTTP method, and other request details. It also allows setting fixed path parameters. This class is designed to facilitate handling and processing of incoming requests in a serverless environment. |
|
|
155
|
+
|
|
156
|
+
</details>
|
|
157
|
+
|
|
158
|
+
<details closed><summary>Baseevent</summary>
|
|
159
|
+
|
|
160
|
+
| File | Summary |
|
|
161
|
+
| --- | --- |
|
|
162
|
+
| [Process.ts](https://github.com/Creator-co/Wapi/blob/main/src/BaseEvent/Process.ts) | The Process class provides functionality to create and manage processes. It allows executing shell commands in a child process, streaming the output, and capturing the exit code. This class is useful for managing and monitoring external processes or running background tasks. |
|
|
163
|
+
| [ExecutionResult.ts](https://github.com/Creator-co/Wapi/blob/main/src/BaseEvent/ExecutionResult.ts) | The ExecutionResult class represents the result of executing a process. It includes information such as the command that was executed, the exit code, and the standard output and error streams. This class is used for capturing and reporting the results of process execution. |
|
|
164
|
+
| [Transaction.ts](https://github.com/Creator-co/Wapi/blob/main/src/BaseEvent/Transaction.ts) | The Transaction class is a central part of WAPI. It encapsulates the core concept of transactions, allowing developers to handle complex sequences of events and actions. A transaction represents a unit of work that can include multiple steps, such as database queries, HTTP requests, and more. |
|
|
165
|
+
| [Executor.ts](https://github.com/Creator-co/Wapi/blob/main/src/BaseEvent/Executor.ts) | The Executor class is responsible for executing a series of steps in a transaction. It manages the transaction's state, ensures that steps are executed in the correct order, and handles error recovery. This class plays a key role in orchestrating the execution of transactions. |
|
|
166
|
+
| [Events.ts](https://github.com/Creator-co/Wapi/blob/main/src/BaseEvent/Events.ts) | The Events class defines a set of event types that can be used within transactions. Events can be triggered, caught, and processed in various ways to implement business logic. This class provides a clear structure for managing events and actions within transactions. |
|
|
167
|
+
|
|
168
|
+
</details>
|
|
169
|
+
|
|
170
|
+
## 🚀 Getting Started
|
|
171
|
+
|
|
172
|
+
To get started with the **WAPI** project, follow these steps:
|
|
173
|
+
|
|
174
|
+
### 🔧 Installation
|
|
175
|
+
|
|
176
|
+
Install Dependencies: Navigate to the project's root directory and install the required dependencies.
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
cd your-repo-name
|
|
180
|
+
npm install
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Set Up Configuration: Configure your environment by setting the necessary environment variables or AWS credentials, as required by the project.
|
|
184
|
+
|
|
185
|
+
Build the Project: Build the project using TypeScript.
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
npm run build
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 🤖 Running the Project
|
|
192
|
+
|
|
193
|
+
Run the Project Locally: You can run the project locally using the following command:
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
npm run start-local
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
This command starts the local development server.
|
|
200
|
+
|
|
201
|
+
### 🧪 Tests
|
|
202
|
+
|
|
203
|
+
Run Tests: The project includes a comprehensive set of tests. You can run the tests using:
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
npm test
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Additionally, there are tests for running the project in a local environment:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
npm run test-local
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Congratulations! You now have WAPI up and running, and you're ready to start developing your web applications.
|
|
216
|
+
|
|
217
|
+
If you have any more questions or need further assistance, please don't hesitate to ask.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,19 @@ import Crypto from './src/Crypto/Crypto';
|
|
|
8
8
|
import JWT from './src/Crypto/JWT';
|
|
9
9
|
import Mailer from './src/Mailer/Mailer';
|
|
10
10
|
import Router, { Route } from './src/Server/Router';
|
|
11
|
+
/**
|
|
12
|
+
* Exported modules:
|
|
13
|
+
* - Transaction: A module for handling transactions.
|
|
14
|
+
* - Process: A module for managing processes.
|
|
15
|
+
* - EventProcessor: A module for processing events.
|
|
16
|
+
* - Router: A module for routing requests.
|
|
17
|
+
* - Mailer: A module for sending emails.
|
|
18
|
+
* - Crypto: A module for cryptographic operations.
|
|
19
|
+
* - JWT: A module for handling JSON Web Tokens.
|
|
20
|
+
* - Configuration: A module for managing configuration settings.
|
|
21
|
+
* - Response: A module for constructing HTTP responses.
|
|
22
|
+
* - Utils: A module containing utility functions.
|
|
23
|
+
* - Route: A module for defining routes.
|
|
24
|
+
* - ResponseErrorType: An enumeration of possible response error types.
|
|
25
|
+
*/
|
|
11
26
|
export { Transaction, Process, EventProcessor, Router, Mailer, Crypto, JWT, Configuration, Response, Utils, Route, ResponseErrorType, };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAgE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAgE;AAsC9D,mBAtCK,kBAAQ,CAsCL;AArCV,yCAAmC;AAuCjC,gBAvCK,eAAK,CAuCL;AAtCP,iEAA2D;AA4BzD,yBA5BK,wBAAc,CA4BL;AA3BhB,mDAA6C;AA0B3C,kBA1BK,iBAAO,CA0BL;AAzBT,2DAAqD;AAwBnD,sBAxBK,qBAAW,CAwBL;AAvBb,4DAAsD;AA+BpD,wBA/BK,uBAAa,CA+BL;AA9Bf,8CAAwC;AA4BtC,iBA5BK,gBAAM,CA4BL;AA3BR,wCAAkC;AA4BhC,cA5BK,aAAG,CA4BL;AA3BL,8CAAwC;AAyBtC,iBAzBK,gBAAM,CAyBL;AAxBR,8CAAmD;AAsBjD,iBAtBK,gBAAM,CAsBL"}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,19 +37,24 @@
|
|
|
37
37
|
"node-cache": "^5.1.2",
|
|
38
38
|
"object-hash": "^3.0.0",
|
|
39
39
|
"parse-duration": "^1.1.0",
|
|
40
|
+
"path-to-regexp": "^6.2.1",
|
|
40
41
|
"pg": "^8.11.3",
|
|
41
42
|
"sha1": "^1.1.1",
|
|
42
43
|
"stack-trace": "0.0.10",
|
|
43
44
|
"zod": "^3.22.4"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
47
|
+
"@jest/globals": "^29.7.0",
|
|
46
48
|
"@types/aws-lambda": "^8.10.119",
|
|
47
49
|
"@types/chai": "^4.3.9",
|
|
50
|
+
"@types/cors": "^2.8.15",
|
|
48
51
|
"@types/express": "^4.17.19",
|
|
49
52
|
"@types/jest": "^29.5.6",
|
|
50
53
|
"@types/jsonwebtoken": "^9.0.3",
|
|
51
54
|
"@types/node": "^20.5.7",
|
|
55
|
+
"@types/path-to-regexp": "^1.7.0",
|
|
52
56
|
"@types/pg": "^8.10.5",
|
|
57
|
+
"@types/supertest": "^2.0.15",
|
|
53
58
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
54
59
|
"@typescript-eslint/parser": "^6.5.0",
|
|
55
60
|
"aws-lambda": "^1.0.7",
|
|
@@ -1,140 +1,103 @@
|
|
|
1
1
|
import type { Context, APIGatewayEvent } from 'aws-lambda';
|
|
2
2
|
import Logger from '../Logger/Logger';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @class Request
|
|
8
|
-
* @typedef {Request}
|
|
9
|
-
* @template InputType
|
|
4
|
+
* Represents a request object with utility methods for accessing request information.
|
|
5
|
+
* @template InputType - The type of the request body.
|
|
10
6
|
*/
|
|
11
7
|
export default class Request<InputType> {
|
|
12
8
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @private
|
|
9
|
+
* Represents an API Gateway event for a request.
|
|
16
10
|
* @type {APIGatewayEvent}
|
|
17
11
|
*/
|
|
18
12
|
private requestEvent;
|
|
19
13
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @private
|
|
23
|
-
* @type {Context}
|
|
14
|
+
* The context object for the current instance.
|
|
24
15
|
*/
|
|
25
16
|
private context;
|
|
26
17
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
* @param {
|
|
31
|
-
* @
|
|
32
|
-
* @param {Logger} logger
|
|
18
|
+
* Constructs a new instance of the class.
|
|
19
|
+
* @param {APIGatewayEvent} requestEvent - The API Gateway event object.
|
|
20
|
+
* @param {Context} context - The context object.
|
|
21
|
+
* @param {Logger} logger - The logger object.
|
|
22
|
+
* @returns None
|
|
33
23
|
*/
|
|
34
24
|
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger);
|
|
35
25
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
39
|
-
* @param {string} paramName
|
|
40
|
-
* @returns {boolean}
|
|
26
|
+
* Checks if the given query parameter exists and has a valid value.
|
|
27
|
+
* @param {string} paramName - The name of the query parameter to check.
|
|
28
|
+
* @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise.
|
|
41
29
|
*/
|
|
42
30
|
containsQueryParam(paramName: string): boolean;
|
|
43
31
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
* @param {string} paramName
|
|
48
|
-
* @returns {(string | null)}
|
|
32
|
+
* Retrieves the value of a query parameter from the request event's query string parameters.
|
|
33
|
+
* @param {string} paramName - The name of the query parameter to retrieve.
|
|
34
|
+
* @returns {string | null} The value of the query parameter, or null if it does not exist.
|
|
49
35
|
*/
|
|
50
36
|
getQueryParam(paramName: string): string | null;
|
|
51
37
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
* @param {string} headerName
|
|
56
|
-
* @returns {(string | null)}
|
|
38
|
+
* Retrieves the value of the specified header from the request event headers.
|
|
39
|
+
* @param {string} headerName - The name of the header to retrieve.
|
|
40
|
+
* @returns {string | null} - The value of the header, or null if the header is not found.
|
|
57
41
|
*/
|
|
58
42
|
getHeader(headerName: string): string | null;
|
|
59
43
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
* @param {string} cxtParam
|
|
64
|
-
* @returns {(any | null)}
|
|
44
|
+
* Retrieves the value of a context parameter from the request context object.
|
|
45
|
+
* @param {string} cxtParam - The name of the context parameter to retrieve.
|
|
46
|
+
* @returns The value of the context parameter, or null if it does not exist.
|
|
65
47
|
*/
|
|
66
48
|
getContextParam(cxtParam: string): any | null;
|
|
67
49
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* @
|
|
71
|
-
* @param {string} paramName
|
|
72
|
-
* @returns {boolean}
|
|
50
|
+
* Checks if the given parameter name exists in the path parameters and if its value is a valid string or number.
|
|
51
|
+
* @param {string} paramName - The name of the parameter to check.
|
|
52
|
+
* @returns {boolean} - True if the parameter exists and its value is a valid string or number, false otherwise.
|
|
73
53
|
*/
|
|
74
54
|
containsPathParam(paramName: string): boolean;
|
|
75
55
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @
|
|
79
|
-
* @param {string} paramName
|
|
80
|
-
* @returns {(string | null)}
|
|
56
|
+
* Retrieves the value of a path parameter from the request event.
|
|
57
|
+
* @param {string} paramName - The name of the path parameter to retrieve.
|
|
58
|
+
* @returns {string | null} The value of the path parameter, or null if it does not exist.
|
|
81
59
|
*/
|
|
82
60
|
getPathParam(paramName: string): string | null;
|
|
83
61
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @public
|
|
87
|
-
* @returns {InputType}
|
|
62
|
+
* Retrieves the body of the request event and parses it if it is a string.
|
|
63
|
+
* @returns {InputType} The parsed body of the request event.
|
|
88
64
|
*/
|
|
89
65
|
getBody(): InputType;
|
|
90
66
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @public
|
|
94
|
-
* @returns {string}
|
|
67
|
+
* Retrieves the path from the request event.
|
|
68
|
+
* @returns {string} The path of the request event.
|
|
95
69
|
*/
|
|
96
70
|
getPath(): string;
|
|
97
71
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @public
|
|
101
|
-
* @returns {string}
|
|
72
|
+
* Retrieves the HTTP method of the current request.
|
|
73
|
+
* @returns {string} The HTTP method of the request.
|
|
102
74
|
*/
|
|
103
75
|
getMethod(): string;
|
|
104
76
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @public
|
|
108
|
-
* @returns {(object | null)}
|
|
77
|
+
* Retrieves the path parameters from the request event.
|
|
78
|
+
* @returns {object | null} - The path parameters object, or null if not found.
|
|
109
79
|
*/
|
|
110
80
|
getPathParams(): object | null;
|
|
111
81
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* @public
|
|
115
|
-
* @returns {(string | null)}
|
|
82
|
+
* Retrieves the value of the 'Authorization' header from the request.
|
|
83
|
+
* @returns The value of the 'Authorization' header, or null if it is not present.
|
|
116
84
|
*/
|
|
117
85
|
getAuthorizationHeader(): string | null;
|
|
118
86
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* @public
|
|
122
|
-
* @returns {string}
|
|
87
|
+
* Retrieves the request ID associated with the current execution context.
|
|
88
|
+
* @returns {string} The request ID.
|
|
123
89
|
*/
|
|
124
90
|
getRequestID(): string;
|
|
125
91
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @public
|
|
129
|
-
* @returns {string}
|
|
92
|
+
* Retrieves the origin IP address of the request.
|
|
93
|
+
* @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'.
|
|
130
94
|
*/
|
|
131
95
|
getOriginIP(): string;
|
|
132
96
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* @
|
|
136
|
-
* @
|
|
137
|
-
* @param {any[]} result
|
|
97
|
+
* Sets the fixed path parameters in the request event object.
|
|
98
|
+
* @param {any[]} keys - An array of keys representing the path parameter names.
|
|
99
|
+
* @param {any[]} result - An array of values representing the path parameter values.
|
|
100
|
+
* @returns None
|
|
138
101
|
*/
|
|
139
102
|
setFixedPathParams(keys: any[], result: any[]): void;
|
|
140
103
|
}
|