Skip to content

Commit 01fdfba

Browse files
committed
repair export of custom AxiosRequestConfig + add raw example + remove examples from builded + rename build to lib
1 parent 6601ad6 commit 01fdfba

File tree

9 files changed

+71
-35
lines changed

9 files changed

+71
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ config.json
154154
!.gitkeep
155155
/package-lock.json
156156

157+
lib
157158
build
158159
last-check.json
159160
yarn.lock

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,5 @@ _config.yml
169169
jest.config.js
170170
tsconfig.json
171171
renovate.json
172-
unifi-storage
172+
unifi-storage
173+
examples/

examples/raw/RawRequests.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Controller } from '../../src';
2+
3+
// create main function to deal with async/await
4+
const main = async () => {
5+
const controller = new Controller({
6+
username: process.env.TEST_UNIFIOS_USERNAME,
7+
password: process.env.TEST_UNIFIOS_PASSWORD,
8+
url: process.env.TEST_UNIFIOS_URL || 'https://unifi',
9+
strictSSL: false
10+
});
11+
12+
await controller.login();
13+
14+
//exemple of a raw request to the controller
15+
// I want to call : https://unifi/api/users/self to get informations about mySelf
16+
const mySelf = await controller.getInstance().get('/api/users/self');
17+
18+
// exemple of a raw request to a site
19+
// I want to get sysinfo for the default site, so the request on my UDM pro is : https://unifi/proxy/network/api/s/default/stat/sysinfo
20+
// I get the "default" site
21+
const defaultSite = (await controller.getSites()).find((s) => s.name === 'default');
22+
// I call /stat/sysinfo ... The instance will automaticaly transform for the correct url, and set the params .
23+
const sysInfo = await defaultSite.getInstance().get('/stat/sysinfo');
24+
25+
// if I wan't to use a new V2 endpoint, like : https://unifi/proxy/network/v2/api/site/default/notifications
26+
// I just need to reuse my site, call /notifications, and specify that I wan't to use apiVersion 2
27+
const notifications = await defaultSite.getInstance().get('/notifications', {
28+
apiVersion: 2
29+
});
30+
};
31+
32+
//just run the async main, and log error if needed
33+
main().catch((e) => console.error(e));

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "unifi-client",
33
"version": "0.5.0",
4-
"main": "build/index.js",
4+
"main": "lib/index.js",
55
"description": "NodeJs client for Unifi products (https://www.ui.com/)",
66
"scripts": {
7-
"debug": "tsc && node -r source-map-support/register ./build/test.js",
8-
"start": "node -r source-map-support/register ./build/index.js",
7+
"debug": "tsc && node -r source-map-support/register ./lib/test.js",
8+
"start": "node -r source-map-support/register ./lib/index.js",
99
"build": "tsc",
1010
"test": "jest",
1111
"test:CI": "jest --ci",
@@ -49,7 +49,7 @@
4949
"set-cookie-parser": "2.4.8",
5050
"source-map-support": "0.5.19",
5151
"typescript": "4.3.5",
52-
"ws": "^8.0.0"
52+
"ws": "8.0.0"
5353
},
5454
"devDependencies": {
5555
"@types/cookie": "0.4.1",

renovate.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"extends": [
3-
"config:base"
3+
"config:base",
4+
":separateMajorReleases",
5+
":combinePatchMinorReleases",
6+
":prImmediately",
7+
":updateNotScheduled",
8+
":automergeDisabled",
9+
":ignoreModulesAndTests",
10+
":pinDependencies",
11+
":pinDevDependencies",
12+
"group:monorepos",
13+
"group:recommended",
14+
"workarounds:all"
415
]
516
}

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sonar.sources=src
77

88
sonar.sourceEncoding=UTF-8
99

10-
sonar.exclusions=**/*.test.*,node_modules/**,coverage/**, logs/**, build/**, buildTests/**, front/**, cache/**, tests/**, src/test.ts
10+
sonar.exclusions=**/*.test.*,node_modules/**,coverage/**, logs/**, build/**, lib/**, buildTests/**, front/**, cache/**, tests/**, src/test.ts
1111

1212
sonar.tests=tests
1313
; sonar.testExecutionReportPaths=coverage/test-report.xml

src/custom.d.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ export * from './WebSockets';
1111

1212
export { Controller };
1313
export default Controller;
14+
15+
declare module 'axios' {
16+
export interface AxiosRequestConfig {
17+
urlParams?: Record<string, string>;
18+
site?: string;
19+
apiVersion?: number;
20+
/**
21+
* default /proxy/network
22+
*/
23+
unifiUrl?: string;
24+
/**
25+
* default false
26+
*/
27+
authenticationRequest?: boolean;
28+
retryAuth?: boolean;
29+
}
30+
}

tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
"allowJs": true,
88
"esModuleInterop": true,
99
"declaration": true,
10-
"outDir": "build"
10+
"outDir": "lib"
1111
},
1212
"exclude": [
1313
"node_modules",
1414
"tests"
1515
],
1616
"include": [
1717
"src/**/*.ts"
18-
],
19-
"files": [
20-
"./src/custom.d.ts"
2118
]
2219
}

0 commit comments

Comments
 (0)