Installations
npm install @t00nday/nestjs-got
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
^14.0.0 || >=16.0.0 || ^18.0.0
Node Version
14.18.0
NPM Version
9.2.0
Score
69.5
Supply Chain
98.9
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (96.63%)
JavaScript (1.88%)
Shell (0.9%)
Batchfile (0.58%)
Developer
toondaey
Download Statistics
Total Downloads
42,617
Last Day
114
Last Week
211
Last Month
885
Last Year
11,158
GitHub Statistics
15 Stars
198 Commits
5 Forks
2 Watching
23 Branches
2 Contributors
Bundle Size
12.87 kB
Minified
2.36 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.2.19
Package Id
@t00nday/nestjs-got@2.2.19
Unpacked Size
42.97 kB
Size
9.45 kB
File Count
39
NPM Version
9.2.0
Node Version
14.18.0
Total Downloads
Cumulative downloads
Total Downloads
42,617
Last day
107.3%
114
Compared to previous day
Last week
-51.9%
211
Compared to previous week
Last month
-16.2%
885
Compared to previous month
Last year
-58.1%
11,158
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
4
Dev Dependencies
33
Nestjs Got
This is a simple nestjs module that exposes the got http package by exporting the GotService
after module registration while leveraging the Reactive Programming Pattern provided by rxjs.
Table of content (click to expand)
Installation
Installation is pretty simple and straightforward as all you have to do is run the following commands depending on your package manager:
- npm
npm install --save @t00nday/nestjs-got got@^11.0.0
- yarn
yarn add @t00nday/nestjs-got got@^11.0.0
Usage
Using this module is quite simple, you just have to register it as a dependency using any of the methods below:
This could be done synchronously using the register()
method:
./app.module.ts
1import { Module } from '@nestjs/common'; 2import { GotModule } from '@t00nday/nestjs-got'; 3 4@Module({ 5 imports: [ 6 // ... other modules 7 GotModule.register({ 8 prefixUrl: 'http://example.org', 9 // ... 10 }), // Accepts a GotModuleOptions object as a parameter 11 ], 12}) 13export class AppModule {}
The module could also be registered asynchronously using any of the approaches provided by the registerAsync()
method:
Examples below:
- Using options factory provider approach
./app.module.ts
1// prettier-ignore 2import { 3 GotModule, 4 GotModuleOptions 5} from '@t00nday/nestjs-got'; 6import { Module } from '@nestjs/common'; 7 8@Module({ 9 imports: [ 10 // ... other modules 11 GotModule.registerAsync({ 12 useFactory: (): GotModuleOptions => ({ 13 prefixUrl: 'https://example.org', 14 // ... 15 }), 16 }), 17 ], 18}) 19export class AppModule {}
- Using class or existing provider approach:
./got-config.service.ts
1import { Injectable } from '@nestjs/common'; 2import { GotModuleOptions, GotOptionsFactory } from '@t00nday/nestjs-got'; 3 4@Injectable() 5export class GotConfigService implements GotModuleOptionsFactory { 6 createGotOptions(): GotModuleOptions { 7 return { 8 prefixUrl: 'https://example.org', 9 // ... 10 }; 11 } 12}
The GotConfigService
SHOULD implement the GotModuleOptionsFactory
, MUST declare the createGotOptions()
method and MUST return GotModuleOptions
object.
./app.module.ts
1// prettier-ignore 2import { Module } from '@nestjs/common'; 3import { GotModule, GotModuleOptions } from '@t00nday/nestjs-got'; 4 5import { GotConfigService } from './got-config.service.ts'; 6 7@Module({ 8 imports: [ 9 // ... other modules 10 GotModule.registerAsync({ 11 useClass: GotConfigService, 12 }), 13 ], 14}) 15export class AppModule {}
Configuration
The GotModuleOptions
is an alias for the got
package's ExtendOptions
hence accepts the same configuration object.
API Methods
HTTP
The module currently only exposes the basic JSON HTTP verbs, as well as the pagination methods through the GotService
.
For all JSON HTTP verbs - get
, head
, post
, put
, patch
and delete
- which are also the exposed methods, below is the the method signature where method: string
MUST be any of their corresponding verbs.
1// This is just used to explain the methods as this code doesn't exist in the package 2import { Observable } from 'rxjs'; 3import { Response, OptionsOfJSONResponseBody } from 'got'; 4 5interface GotInterface { 6 // prettier-ignore 7 [method: string]: ( // i.e. 'get', 'head', 'post', 'put' or 'delete' method 8 url: string | URL, 9 options?: OptionsOfJSONResponseBody, 10 ) => Observable<Response<T>>;; 11}
Pagination
For all pagination methods - each
and all
, below is the method signature each of them.
1// This is just used to explain the methods as this code doesn't exist in the package 2import { Observable } from 'rxjs'; 3import { Response, OptionsOfJSONResponseBody } from 'got'; 4 5interface PaginateInterface { 6 [method: string]: <T = any, R = unknown>( // i.e 'all' or 'each' method 7 url: string | URL, 8 options?: OptionsWithPagination<T, R>, 9 ) => Observable<T | T[]>; 10}
Usage examples:
1@Controller() 2export class ExampleController { 3 constructor(private readonly gotService: GotService) {} 4 5 controllerMethod() { 6 // ... 7 this.gotService.pagination.all<T>(someUrl, withOptions); // Returns Observable<T[]> 8 // or 9 this.gotService.pagination.each<T>(someUrl, withOptions); // Returns Observable<T> 10 // ... 11 } 12}
For more information of the usage pattern, please check here
Stream
The stream feature is divided into two parts. This is because (and as stated in the documentation here), while the stream request is actually a stream.Duplex
the GET and HEAD requests return a stream.Readable
and the POST, PUT, PATCH and DELETE requests return a stream.Writable
.
This prompted an implementation that attempts to cover both scenarios. The difference is only present in the arguments acceptable by the respective methods.
Further, all methods of the stream property return a stream request to which we can chain an on<T>(eventType)
method which in turn returns a fromEvent observable. This affords us the ability to subscribe to events we wish to listen for from the request.
Possible eventType
s include (and quite constrained to those provided by the got package):
-
end
-
data
-
error
-
request
-
readable
-
response
-
redirect
-
uploadProgress
-
downloadProgress
For GET and HEAD stream requests, below is the method signature:
1// This is just used to explain the methods as this code doesn't exist in the package 2import { Observable } from 'rxjs'; 3import { StreamOptions } from 'got'; 4import { StreamRequest } from '@toonday/nestjs-got/dist/stream.request'; 5 6interface StreamInterface { 7 [method: string]: <T = unknown>( 8 url: string | URL, 9 options?: StreamOptions, 10 ): StreamRequest; 11}
while that of the POST, PUT, PATCH and DELETE is:
1// This is just used to explain the methods as this code doesn't exist in the package 2import { Observable } from 'rxjs'; 3import { StreamOptions } from 'got'; 4import { StreamRequest } from '@toonday/nestjs-got/dist/stream.request'; 5 6interface StreamInterface { 7 [method: string]: <T = unknown>( 8 url: string | URL, 9 filePathOrStream?: string | Readable, // This is relative to 'process.cwd()' 10 options?: StreamOptions, 11 ): StreamRequest<T>; 12}
Usage examples:
1@Controller() 2export class ExampleController { 3 constructor(private readonly gotService: GotService) {} 4 5 controllerMethod() { 6 // ... 7 this 8 .gotService 9 .stream 10 .get(someUrl, streamOptions) 11 .on<T>(eventType) 12 .subscribe(subscribeFunction: Function); // Returns Observable<T> 13 // or 14 this 15 .gotService 16 .stream 17 .head(someUrl, streamOptions) 18 .on<T>(eventType) 19 .subscribe(subscribeFunction: Function); // Returns Observable<T> 20 // or 21 this 22 .gotService 23 .stream 24 .post(someUrl, filePathOrStream, streamOptions) 25 .on<T>(eventType) 26 .subscribe(subscribeFunction: Function); // Returns Observable<T> 27 // or 28 this 29 .gotService 30 .stream 31 .put(someUrl, filePathOrStream, streamOptions) 32 .on<T>(eventType) 33 .subscribe(subscribeFunction: Function); // Returns Observable<T> 34 // or 35 this 36 .gotService 37 .stream 38 .patch(someUrl, filePathOrStream, streamOptions) 39 .on<T>(eventType) 40 .subscribe(subscribeFunction: Function); // Returns Observable<T> 41 // or 42 this 43 .gotService 44 .stream 45 .delete(someUrl, filePathOrStream, streamOptions) 46 .on<T>(eventType) 47 .subscribe(subscribeFunction: Function); // Returns Observable<T> 48 // ... 49 } 50}
Contributing
Contributions are welcome. However, please read the contribution's guide.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENCE:0
- Info: FSF or OSI recognized license: MIT License: LICENCE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/publish.yaml:1
- Warn: no topLevel permission defined: .github/workflows/tests.yaml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/publish.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yaml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/publish.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yaml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/tests.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yaml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/tests.yaml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yaml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/tests.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yaml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/tests.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yaml:80: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/tests.yaml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yaml:110: update your workflow using https://app.stepsecurity.io/secureworkflow/toondaey/nestjs-got/tests.yaml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/tests.yaml:36
- Warn: npmCommand not pinned by hash: .github/workflows/tests.yaml:39
- Warn: npmCommand not pinned by hash: .github/workflows/tests.yaml:86
- Warn: npmCommand not pinned by hash: .github/workflows/tests.yaml:89
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 4 npmCommand dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
36 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-xwcq-pm8m-c4vf
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-x3cc-x39p-42qx
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-3xq5-wjfh-ppjc
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-ch3c-v47x-4pgp
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-wgrm-67xf-hhpq
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-9w5j-4mwv-2wj8
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-7jxr-cg7f-gpgv
- Warn: Project is vulnerable to: GHSA-xj72-wvfv-8985
- Warn: Project is vulnerable to: GHSA-ch3r-j5x3-6q2m
- Warn: Project is vulnerable to: GHSA-p5gc-c584-jj6v
- Warn: Project is vulnerable to: GHSA-whpj-8f3w-67p5
- Warn: Project is vulnerable to: GHSA-cchq-frgv-rjh5
- Warn: Project is vulnerable to: GHSA-g644-9gfx-q4q4
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-f9xv-q969-pqx4
- Warn: Project is vulnerable to: GHSA-m95q-7qp3-xv42
Score
2.8
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More