hcloud-sdk 0.0.4 → 0.0.7
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 +1 -1
- package/{lib/index.d.ts → index.d.ts} +0 -0
- package/{lib/index.js → index.js} +0 -0
- package/lib/{lib/Axios.d.ts → Axios.d.ts} +1 -0
- package/lib/{lib/Axios.js → Axios.js} +3 -0
- package/lib/base.d.ts +9 -0
- package/lib/base.js +10 -0
- package/lib/{lib/hcloud.d.ts → common.d.ts} +1 -3
- package/lib/{lib/hcloud.js → common.js} +2 -4
- package/lib/dto/IDP.d.ts +17 -0
- package/lib/dto/IDP.js +2 -0
- package/lib/hcloud.d.ts +8 -0
- package/lib/hcloud.js +14 -0
- package/lib/service/High5.d.ts +4 -0
- package/lib/service/High5.js +9 -0
- package/lib/service/IDP.d.ts +33 -0
- package/lib/service/IDP.js +80 -0
- package/package.json +4 -5
- package/lib/lib/IDP.d.ts +0 -4
- package/lib/lib/IDP.js +0 -22
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# hcloud-sdk
|
|
1
|
+
# hcloud-sdk
|
|
File without changes
|
|
File without changes
|
|
@@ -15,6 +15,9 @@ class AxiosService {
|
|
|
15
15
|
this.get = (url) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
return axios_1.default.get(url);
|
|
17
17
|
});
|
|
18
|
+
this.post = (url, body) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return axios_1.default.post(url, body, {});
|
|
20
|
+
});
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
exports.default = AxiosService;
|
package/lib/base.d.ts
ADDED
package/lib/base.js
ADDED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import IDPService from './IDP';
|
|
2
1
|
import AxiosService from './Axios';
|
|
3
2
|
export interface options {
|
|
4
3
|
api: string;
|
|
5
4
|
}
|
|
6
|
-
export default class
|
|
5
|
+
export default abstract class common {
|
|
7
6
|
protected opts: options;
|
|
8
7
|
protected axios: AxiosService;
|
|
9
|
-
IDP: IDPService;
|
|
10
8
|
constructor(opts: options);
|
|
11
9
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const IDP_1 = require("./IDP");
|
|
4
3
|
const Axios_1 = require("./Axios");
|
|
5
4
|
// tslint:disable-next-line
|
|
6
|
-
class
|
|
5
|
+
class common {
|
|
7
6
|
constructor(opts) {
|
|
8
7
|
this.opts = opts;
|
|
9
8
|
this.axios = new Axios_1.default();
|
|
10
|
-
this.IDP = new IDP_1.default(this.opts);
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
|
-
exports.default =
|
|
11
|
+
exports.default = common;
|
package/lib/dto/IDP.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
_id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
company: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Token {
|
|
8
|
+
token: string;
|
|
9
|
+
}
|
|
10
|
+
export interface UserAndToken {
|
|
11
|
+
user: User;
|
|
12
|
+
token: Token;
|
|
13
|
+
}
|
|
14
|
+
export interface ErrorMessage {
|
|
15
|
+
status: number;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
package/lib/dto/IDP.js
ADDED
package/lib/hcloud.d.ts
ADDED
package/lib/hcloud.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("./base");
|
|
4
|
+
const IDP_1 = require("./service/IDP");
|
|
5
|
+
const High5_1 = require("./service/High5");
|
|
6
|
+
// tslint:disable-next-line
|
|
7
|
+
class hcloud extends base_1.default {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super(opts);
|
|
10
|
+
this.IDP = new IDP_1.default(this.opts);
|
|
11
|
+
this.High5 = new High5_1.default(this.opts);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.default = hcloud;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const base_1 = require("../base");
|
|
4
|
+
class High5 extends base_1.default {
|
|
5
|
+
getEndpoint(endpoint) {
|
|
6
|
+
return `${this.opts.api}/api/high5${endpoint}`;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.default = High5;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import base from '../base';
|
|
2
|
+
import { Token, User } from '../dto/IDP';
|
|
3
|
+
export default class IDP extends base {
|
|
4
|
+
/**
|
|
5
|
+
* Authorize validates a token
|
|
6
|
+
* @param token
|
|
7
|
+
* @returns User object
|
|
8
|
+
*/
|
|
9
|
+
authorize: (token: string) => Promise<User>;
|
|
10
|
+
/**
|
|
11
|
+
* Register against the identity provider
|
|
12
|
+
* @param name
|
|
13
|
+
* @param email
|
|
14
|
+
* @param password
|
|
15
|
+
* @returns Bearer Token
|
|
16
|
+
*/
|
|
17
|
+
register: (name: string, email: string, password: string) => Promise<User>;
|
|
18
|
+
/**
|
|
19
|
+
* Authenticate against the identity provider with a given email and password.
|
|
20
|
+
* @param email
|
|
21
|
+
* @param password
|
|
22
|
+
* @returns Bearer Token
|
|
23
|
+
*/
|
|
24
|
+
authenticate: (email: string, password: string) => Promise<Token>;
|
|
25
|
+
/**
|
|
26
|
+
* authenticateReturnUser against the identity provider with a given email and password.
|
|
27
|
+
* @param email
|
|
28
|
+
* @param password
|
|
29
|
+
* @returns User object
|
|
30
|
+
*/
|
|
31
|
+
authenticateReturnUser: (email: string, password: string) => Promise<User>;
|
|
32
|
+
private getEndpoint;
|
|
33
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const base_1 = require("../base");
|
|
13
|
+
const axios_1 = require("axios");
|
|
14
|
+
class IDP extends base_1.default {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
/**
|
|
18
|
+
* Authorize validates a token
|
|
19
|
+
* @param token
|
|
20
|
+
* @returns User object
|
|
21
|
+
*/
|
|
22
|
+
this.authorize = (token) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const resp = yield axios_1.default
|
|
24
|
+
.post(this.getEndpoint('/v1/authenticate'), {}, { headers: { Authorization: token } })
|
|
25
|
+
.catch((err) => {
|
|
26
|
+
throw err;
|
|
27
|
+
});
|
|
28
|
+
return resp.data;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Register against the identity provider
|
|
32
|
+
* @param name
|
|
33
|
+
* @param email
|
|
34
|
+
* @param password
|
|
35
|
+
* @returns Bearer Token
|
|
36
|
+
*/
|
|
37
|
+
this.register = (name, email, password) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const resp = yield axios_1.default
|
|
39
|
+
.post(this.getEndpoint('/v1/registration'), { name: name, email: email, password: password })
|
|
40
|
+
.catch((err) => {
|
|
41
|
+
throw err;
|
|
42
|
+
});
|
|
43
|
+
return resp.data;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Authenticate against the identity provider with a given email and password.
|
|
47
|
+
* @param email
|
|
48
|
+
* @param password
|
|
49
|
+
* @returns Bearer Token
|
|
50
|
+
*/
|
|
51
|
+
this.authenticate = (email, password) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const resp = yield axios_1.default
|
|
53
|
+
.post(this.getEndpoint('/v1/authorize'), { email: email, password: password })
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
throw err;
|
|
56
|
+
});
|
|
57
|
+
// tslint-disable: no-string-literal
|
|
58
|
+
const token = { token: resp.headers.authorization };
|
|
59
|
+
return token;
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* authenticateReturnUser against the identity provider with a given email and password.
|
|
63
|
+
* @param email
|
|
64
|
+
* @param password
|
|
65
|
+
* @returns User object
|
|
66
|
+
*/
|
|
67
|
+
this.authenticateReturnUser = (email, password) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const resp = yield axios_1.default
|
|
69
|
+
.post(this.getEndpoint('/v1/authorize'), { email: email, password: password })
|
|
70
|
+
.catch((err) => {
|
|
71
|
+
throw err;
|
|
72
|
+
});
|
|
73
|
+
return resp.data;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getEndpoint(endpoint) {
|
|
77
|
+
return `${this.opts.api}/api/account${endpoint}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.default = IDP;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hcloud-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "hcloud platform sdk",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -18,9 +18,6 @@
|
|
|
18
18
|
"hcloud",
|
|
19
19
|
"sdk"
|
|
20
20
|
],
|
|
21
|
-
"files": [
|
|
22
|
-
"lib/**/*"
|
|
23
|
-
],
|
|
24
21
|
"license": "ISC",
|
|
25
22
|
"bugs": {
|
|
26
23
|
"url": "https://github.com/moovit-sp-gmbh/hcloud-sdk-js/issues"
|
|
@@ -30,13 +27,15 @@
|
|
|
30
27
|
"devDependencies": {
|
|
31
28
|
"@types/chai": "^4.3.1",
|
|
32
29
|
"@types/mocha": "^9.1.1",
|
|
30
|
+
"@types/uuid": "^8.3.4",
|
|
33
31
|
"chai": "^4.3.6",
|
|
34
32
|
"mocha": "^10.0.0",
|
|
35
33
|
"prettier": "^2.6.2",
|
|
36
34
|
"ts-node": "^10.8.0",
|
|
37
35
|
"tslint": "^6.1.3",
|
|
38
36
|
"tslint-config-prettier": "^1.18.0",
|
|
39
|
-
"typescript": "^4.7.2"
|
|
37
|
+
"typescript": "^4.7.2",
|
|
38
|
+
"uuid": "^8.3.2"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"axios": "^0.27.2"
|
package/lib/lib/IDP.d.ts
DELETED
package/lib/lib/IDP.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const hcloud_1 = require("./hcloud");
|
|
13
|
-
class IDPService extends hcloud_1.default {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.authenticate = () => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
// const resp = await this.axios.get('https://google.com');
|
|
18
|
-
return this.opts.api;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.default = IDPService;
|