Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions CHANGELOG.md

This file was deleted.

68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
# ts-npm-package-boilerplate
# mc-utils
this is general utilities for usage in Map Colonies project.
Comment thread
asafMasa marked this conversation as resolved.

After cloning this template, please do the following:
1. insert secrets to repo secrets for the github actions.
2. replace every string "ts-npm-package-boilerplate" with your package name.
# included components
- [http client](#http-client)

# usage
## http client
this is abstract base class for sending http request with logging and request retries.

this class constructor requires the following parameters:
- [ILogger](#ilogger) instance.
- base url to use for all requests.
- optional name for target service to be used in logs.
- optional [retry configuration](#ihttpretryconfig).

the class have the following protected attributes
-```axiosOptions``` the options used by axios when sending requests

the class have the protected methods for sending http requests:
- ```protected async get<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```
- ```protected async post<T>(url: string, body?: unknown, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```
- ```protected async put<T>(url: string, body?: unknown, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```
- ```protected async delete<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```
- ```protected async head<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```
- ```protected async options<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```
- ```protected async patch<T>(url: string, body?: unknown, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig): Promise<T>```

function parameters list:
- `url`: url path to send the request to (not including the base url).
- `body`: optional object to be used as request body (in relevant request types).
- `queryParams`: optional dictionary with query parameters and value.
- `retryConfig`: optional override to the class retry configuration.

usage example:
```typescript
class myServiceClient extends HttpClient {
public constructor(logger: ILogger){
super(logger,'https://myService.com','myService',{
attempts: 3,
delay: 'exponential',
shouldResetTimeout: true
})
}

public async getName(): string {
const name = await this.get<string>('api/name',{queryParam1: 'name'});
return name;
}
}
```
# models
## ILogger
logger interface
with the flowing log methods
- ``` error(message:string) ```
- ```warn(message:string)```
- ```info(message: string)```
- ```debug(message: string)```

## IHttpRetryConfig
http requests retry configuration interface with the following attributes:
- ```attempts``` - the number of request to send until valid response (not 500+ status code). this value must be integer and greater then 0.
- ```delay``` - the amount of time in ms to wait between attempts (for constant delay) or ```'exponential'``` for exponential backoff.
- ```shouldResetTimeout``` boolean value to indicate if the request timeout should be for each request (true) or global for all attempts (false)
16 changes: 8 additions & 8 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@map-colonies/ts-npm-package-boilerplate</title>
<meta name="description" content="Documentation for @map-colonies/ts-npm-package-boilerplate">
<title>@map-colonies/mc-utiles</title>
<meta name="description" content="Documentation for @map-colonies/mc-utiles">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
Expand All @@ -23,7 +23,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">@map-colonies/ts-npm-package-boilerplate</a>
<a href="index.html" class="title">@map-colonies/mc-utiles</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand All @@ -50,21 +50,21 @@
</div>
<div class="tsd-page-title">
<div class="container">
<h1>@map-colonies/ts-npm-package-boilerplate</h1>
<h1>@map-colonies/mc-utiles</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<a href="#ts-npm-package-boilerplate" id="ts-npm-package-boilerplate" style="color: inherit; text-decoration: none;">
<h1>ts-npm-package-boilerplate</h1>
<a href="#mc-utiles" id="mc-utiles" style="color: inherit; text-decoration: none;">
<h1>mc-utiles</h1>
</a>
<p>After cloning this template, please do the following:</p>
<ol>
<li>insert secrets to repo secrets for the github actions.</li>
<li>replace every string &quot;ts-npm-package-boilerplate&quot; with your package name.</li>
<li>replace every string &quot;mc-utiles&quot; with your package name.</li>
</ol>
</div>
</div>
Expand Down Expand Up @@ -99,4 +99,4 @@ <h2>Legend</h2>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>
</html>
12 changes: 6 additions & 6 deletions docs/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@map-colonies/ts-npm-package-boilerplate</title>
<meta name="description" content="Documentation for @map-colonies/ts-npm-package-boilerplate">
<title>@map-colonies/mc-utiles</title>
<meta name="description" content="Documentation for @map-colonies/mc-utiles">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
Expand All @@ -23,7 +23,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">@map-colonies/ts-npm-package-boilerplate</a>
<a href="index.html" class="title">@map-colonies/mc-utiles</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand All @@ -50,7 +50,7 @@
</div>
<div class="tsd-page-title">
<div class="container">
<h1>@map-colonies/ts-npm-package-boilerplate</h1>
<h1>@map-colonies/mc-utiles</h1>
</div>
</div>
</header>
Expand Down Expand Up @@ -78,7 +78,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> cat</h3>
<div class="tsd-signature tsd-kind-icon">cat<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>say<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol"> = ...</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/MapColonies/ts-npm-package-boilerplate/blob/bbe0aad/src/index.ts#L1">index.ts:1</a></li>
<li>Defined in <a href="https://github.com/MapColonies/mc-utiles/blob/bbe0aad/src/index.ts#L1">index.ts:1</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -123,4 +123,4 @@ <h2>Legend</h2>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>
</html>
Loading