hcloud-sdk 0.0.10 → 0.0.13
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/lib/Axios.d.ts +5 -0
- package/lib/Axios.js +23 -0
- package/lib/common.d.ts +9 -0
- package/lib/common.js +11 -0
- package/lib/dto/IDP.d.ts +2 -1
- package/lib/service/IDP.js +1 -1
- package/package.json +8 -8
- package/src/index.d.ts +2 -0
- package/src/index.js +4 -0
- package/src/lib/base.d.ts +12 -0
- package/src/lib/base.js +8 -0
- package/src/lib/dto/IDP.d.ts +14 -0
- package/src/lib/dto/IDP.js +2 -0
- package/src/lib/hcloud.d.ts +11 -0
- package/src/lib/hcloud.js +27 -0
- package/src/lib/interfaces/Auditor.d.ts +40 -0
- package/src/lib/interfaces/Auditor.js +37 -0
- package/src/lib/interfaces/Global.d.ts +8 -0
- package/src/lib/interfaces/Global.js +2 -0
- package/src/lib/interfaces/IDP.d.ts +9 -0
- package/src/lib/interfaces/IDP.js +2 -0
- package/src/lib/service/Auditor.d.ts +42 -0
- package/src/lib/service/Auditor.js +101 -0
- package/src/lib/service/High5.d.ts +4 -0
- package/src/lib/service/High5.js +9 -0
- package/src/lib/service/IDP.d.ts +39 -0
- package/src/lib/service/IDP.js +84 -0
package/lib/Axios.d.ts
ADDED
package/lib/Axios.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 axios_1 = require("axios");
|
|
13
|
+
class AxiosService {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.get = (url) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return axios_1.default.get(url);
|
|
17
|
+
});
|
|
18
|
+
this.post = (url, body) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return axios_1.default.post(url, body, {});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = AxiosService;
|
package/lib/common.d.ts
ADDED
package/lib/common.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Axios_1 = require("./Axios");
|
|
4
|
+
// tslint:disable-next-line
|
|
5
|
+
class common {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
this.opts = opts;
|
|
8
|
+
this.axios = new Axios_1.default();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.default = common;
|
package/lib/dto/IDP.d.ts
CHANGED
package/lib/service/IDP.js
CHANGED
|
@@ -20,7 +20,7 @@ class IDP extends base_1.default {
|
|
|
20
20
|
* @returns User object
|
|
21
21
|
*/
|
|
22
22
|
this.authorize = () => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const resp = yield axios_1.default.
|
|
23
|
+
const resp = yield axios_1.default.get(this.getEndpoint("/v1/authorize"), {}).catch((err) => {
|
|
24
24
|
throw err;
|
|
25
25
|
});
|
|
26
26
|
return resp.data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hcloud-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "hcloud platform sdk",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -22,21 +22,22 @@
|
|
|
22
22
|
"@types/chai": "^4.3.1",
|
|
23
23
|
"@types/mocha": "^9.1.1",
|
|
24
24
|
"@types/uuid": "^8.3.4",
|
|
25
|
+
"@types/node": "^18.0.0",
|
|
25
26
|
"chai": "^4.3.6",
|
|
27
|
+
"dayjs": "^1.11.3",
|
|
26
28
|
"mocha": "^10.0.0",
|
|
27
29
|
"prettier": "^2.6.2",
|
|
28
30
|
"ts-node": "^10.8.0",
|
|
29
31
|
"tslint": "^6.1.3",
|
|
30
32
|
"tslint-config-prettier": "^1.18.0",
|
|
31
33
|
"typescript": "^4.7.2",
|
|
32
|
-
"uuid": "^8.3.2"
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"axios": "^0.27.2",
|
|
36
|
-
"dayjs": "^1.11.3",
|
|
34
|
+
"uuid": "^8.3.2",
|
|
37
35
|
"vuepress": "^1.9.7",
|
|
38
36
|
"vuepress-theme-default-prefers-color-scheme": "^2.0.0"
|
|
39
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"axios": "^0.27.2"
|
|
40
|
+
},
|
|
40
41
|
"scripts": {
|
|
41
42
|
"test": "mocha -r ts-node/register tests/**/*.test.ts",
|
|
42
43
|
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.test.ts\"",
|
|
@@ -45,6 +46,5 @@
|
|
|
45
46
|
"doc:dev": "vuepress dev _docs/src",
|
|
46
47
|
"doc:export": "vuepress export _docs/src",
|
|
47
48
|
"build": "tsc"
|
|
48
|
-
}
|
|
49
|
-
"readme": "# hcloud-sdk\n[](https://opensource.org/licenses/MIT)\n[](https://www.npmjs.com/package/hcloud-sdk)\n"
|
|
49
|
+
}
|
|
50
50
|
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
package/src/lib/base.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import base, { Options } from "./base";
|
|
2
|
+
import IDPService from "./service/IDP";
|
|
3
|
+
import AuditorService from "./service/Auditor";
|
|
4
|
+
import High5Service from "./service/High5";
|
|
5
|
+
export default class hcloud extends base {
|
|
6
|
+
Auditor: AuditorService;
|
|
7
|
+
High5: High5Service;
|
|
8
|
+
IDP: IDPService;
|
|
9
|
+
constructor(opts: Options);
|
|
10
|
+
setAuthToken(token: string): hcloud;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 Auditor_1 = require("./service/Auditor");
|
|
6
|
+
const High5_1 = require("./service/High5");
|
|
7
|
+
const axios_1 = require("axios");
|
|
8
|
+
const package_json_1 = require("../../package.json");
|
|
9
|
+
// tslint:disable-next-line
|
|
10
|
+
class hcloud extends base_1.default {
|
|
11
|
+
constructor(opts) {
|
|
12
|
+
super(opts);
|
|
13
|
+
this.Auditor = new Auditor_1.default(this.opts);
|
|
14
|
+
this.High5 = new High5_1.default(this.opts);
|
|
15
|
+
this.IDP = new IDP_1.default(this.opts);
|
|
16
|
+
axios_1.default.defaults.headers.common = {
|
|
17
|
+
"User-Agent": "hcloud-sdk-js/v" + package_json_1.version,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
setAuthToken(token) {
|
|
21
|
+
axios_1.default.defaults.headers.common = Object.assign(axios_1.default.defaults.headers.common, {
|
|
22
|
+
Authorization: token,
|
|
23
|
+
});
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = hcloud;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare enum Level {
|
|
2
|
+
INFO = "info",
|
|
3
|
+
WARN = "warn",
|
|
4
|
+
ERROR = "error",
|
|
5
|
+
DEBUG = "debug"
|
|
6
|
+
}
|
|
7
|
+
export declare enum Origin {
|
|
8
|
+
IDP = "idp",
|
|
9
|
+
High5 = "high5"
|
|
10
|
+
}
|
|
11
|
+
export declare enum Event {
|
|
12
|
+
Login = "login",
|
|
13
|
+
Logout = "logout",
|
|
14
|
+
User = "user",
|
|
15
|
+
Organization = "organization",
|
|
16
|
+
App = "app",
|
|
17
|
+
Event = "event",
|
|
18
|
+
Stream = "stream"
|
|
19
|
+
}
|
|
20
|
+
export declare enum Type {
|
|
21
|
+
Read = "read",
|
|
22
|
+
Create = "create",
|
|
23
|
+
Update = "update",
|
|
24
|
+
Delete = "delete",
|
|
25
|
+
Execute = "execute",
|
|
26
|
+
Connect = "connect",
|
|
27
|
+
Disconnect = "disconnect",
|
|
28
|
+
Add = "add",
|
|
29
|
+
Remove = "remove"
|
|
30
|
+
}
|
|
31
|
+
export interface AuditLog {
|
|
32
|
+
level: Level;
|
|
33
|
+
origin: Origin;
|
|
34
|
+
organization?: string;
|
|
35
|
+
event: Event;
|
|
36
|
+
user: string;
|
|
37
|
+
type?: Type;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
message?: any;
|
|
40
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Type = exports.Event = exports.Origin = exports.Level = void 0;
|
|
4
|
+
var Level;
|
|
5
|
+
(function (Level) {
|
|
6
|
+
Level["INFO"] = "info";
|
|
7
|
+
Level["WARN"] = "warn";
|
|
8
|
+
Level["ERROR"] = "error";
|
|
9
|
+
Level["DEBUG"] = "debug";
|
|
10
|
+
})(Level = exports.Level || (exports.Level = {}));
|
|
11
|
+
var Origin;
|
|
12
|
+
(function (Origin) {
|
|
13
|
+
Origin["IDP"] = "idp";
|
|
14
|
+
Origin["High5"] = "high5";
|
|
15
|
+
})(Origin = exports.Origin || (exports.Origin = {}));
|
|
16
|
+
var Event;
|
|
17
|
+
(function (Event) {
|
|
18
|
+
Event["Login"] = "login";
|
|
19
|
+
Event["Logout"] = "logout";
|
|
20
|
+
Event["User"] = "user";
|
|
21
|
+
Event["Organization"] = "organization";
|
|
22
|
+
Event["App"] = "app";
|
|
23
|
+
Event["Event"] = "event";
|
|
24
|
+
Event["Stream"] = "stream";
|
|
25
|
+
})(Event = exports.Event || (exports.Event = {}));
|
|
26
|
+
var Type;
|
|
27
|
+
(function (Type) {
|
|
28
|
+
Type["Read"] = "read";
|
|
29
|
+
Type["Create"] = "create";
|
|
30
|
+
Type["Update"] = "update";
|
|
31
|
+
Type["Delete"] = "delete";
|
|
32
|
+
Type["Execute"] = "execute";
|
|
33
|
+
Type["Connect"] = "connect";
|
|
34
|
+
Type["Disconnect"] = "disconnect";
|
|
35
|
+
Type["Add"] = "add";
|
|
36
|
+
Type["Remove"] = "remove";
|
|
37
|
+
})(Type = exports.Type || (exports.Type = {}));
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import base from "../base";
|
|
2
|
+
import { AuditLog } from "../interfaces/Auditor";
|
|
3
|
+
import { Version } from "../interfaces/Global";
|
|
4
|
+
export default class Auditor extends base {
|
|
5
|
+
private queueExecutionInterval;
|
|
6
|
+
private logQueue;
|
|
7
|
+
private logQueueTimer;
|
|
8
|
+
/**
|
|
9
|
+
* Version requests the endpoint version
|
|
10
|
+
* @returns Version object
|
|
11
|
+
*/
|
|
12
|
+
version: () => Promise<Version>;
|
|
13
|
+
/**
|
|
14
|
+
* GetAuditLog requests logs from
|
|
15
|
+
* @param organizationId an optional organization ID to receive audit logs for
|
|
16
|
+
* @param limit an opitional response limit (1-1000; dafaults to 500)
|
|
17
|
+
* @param page an opitional page to skip certain results (page * limit; defaults to 0)
|
|
18
|
+
* @returns User object
|
|
19
|
+
*/
|
|
20
|
+
getAuditLogs: (organizationId: string | null, limit: number | null, page: number | null) => Promise<AuditLog[]>;
|
|
21
|
+
/**
|
|
22
|
+
* AddAuditLogs adds log entries
|
|
23
|
+
*
|
|
24
|
+
* THIS ENDPOINT WORKS INTERNALLY ONLY
|
|
25
|
+
*
|
|
26
|
+
* CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
|
|
27
|
+
* @param logs array (add multiple logs entries at once)
|
|
28
|
+
* @returns AuditLog array
|
|
29
|
+
*/
|
|
30
|
+
addAuditLogs: (logs: AuditLog[]) => Promise<AuditLog[]>;
|
|
31
|
+
/**
|
|
32
|
+
* QueueAuditLogs adds log entries to a queue that will be processed periodically
|
|
33
|
+
*
|
|
34
|
+
* THIS COMES WITH DOWNSIDE OF LOG TIMESTAMPS BEING INACCURATE AS THEY ARE CREATED BY THE Auditor SERVER
|
|
35
|
+
*
|
|
36
|
+
* TIMESTAMPS MIGHT DIFFER AS MUCH AS: this.opts.auditor.queue.executionInterval || 500
|
|
37
|
+
* @param logs array (add multiple logs entries at once)
|
|
38
|
+
*/
|
|
39
|
+
queueAuditLogs: (logs: AuditLog[]) => Promise<void>;
|
|
40
|
+
private startQueue;
|
|
41
|
+
private getEndpoint;
|
|
42
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 Auditor extends base_1.default {
|
|
15
|
+
constructor() {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.queueExecutionInterval = ((_b = (_a = this.opts.auditor) === null || _a === void 0 ? void 0 : _a.queue) === null || _b === void 0 ? void 0 : _b.executionInterval) || 500;
|
|
19
|
+
this.logQueue = [];
|
|
20
|
+
/**
|
|
21
|
+
* Version requests the endpoint version
|
|
22
|
+
* @returns Version object
|
|
23
|
+
*/
|
|
24
|
+
this.version = () => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const resp = yield axios_1.default.get(this.getEndpoint("/v1/version"), {}).catch((err) => {
|
|
26
|
+
throw err;
|
|
27
|
+
});
|
|
28
|
+
return resp.data;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* GetAuditLog requests logs from
|
|
32
|
+
* @param organizationId an optional organization ID to receive audit logs for
|
|
33
|
+
* @param limit an opitional response limit (1-1000; dafaults to 500)
|
|
34
|
+
* @param page an opitional page to skip certain results (page * limit; defaults to 0)
|
|
35
|
+
* @returns User object
|
|
36
|
+
*/
|
|
37
|
+
this.getAuditLogs = (organizationId, limit, page) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const parameters = [];
|
|
39
|
+
let url = "";
|
|
40
|
+
if (organizationId !== null) {
|
|
41
|
+
parameters.push("organization=" + organizationId);
|
|
42
|
+
}
|
|
43
|
+
if (limit !== null) {
|
|
44
|
+
parameters.push("limit=" + limit);
|
|
45
|
+
}
|
|
46
|
+
if (page !== null) {
|
|
47
|
+
parameters.push("page=" + page);
|
|
48
|
+
}
|
|
49
|
+
if (parameters.length > 0) {
|
|
50
|
+
url = "?" + parameters.join("&");
|
|
51
|
+
}
|
|
52
|
+
const resp = yield axios_1.default.get(this.getEndpoint("/v1/logs") + url, {}).catch((err) => {
|
|
53
|
+
throw err;
|
|
54
|
+
});
|
|
55
|
+
return resp.data;
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* AddAuditLogs adds log entries
|
|
59
|
+
*
|
|
60
|
+
* THIS ENDPOINT WORKS INTERNALLY ONLY
|
|
61
|
+
*
|
|
62
|
+
* CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
|
|
63
|
+
* @param logs array (add multiple logs entries at once)
|
|
64
|
+
* @returns AuditLog array
|
|
65
|
+
*/
|
|
66
|
+
this.addAuditLogs = (logs) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const resp = yield axios_1.default.post(this.getEndpoint("/logs"), logs).catch((err) => {
|
|
68
|
+
throw err;
|
|
69
|
+
});
|
|
70
|
+
return resp.data;
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* QueueAuditLogs adds log entries to a queue that will be processed periodically
|
|
74
|
+
*
|
|
75
|
+
* THIS COMES WITH DOWNSIDE OF LOG TIMESTAMPS BEING INACCURATE AS THEY ARE CREATED BY THE Auditor SERVER
|
|
76
|
+
*
|
|
77
|
+
* TIMESTAMPS MIGHT DIFFER AS MUCH AS: this.opts.auditor.queue.executionInterval || 500
|
|
78
|
+
* @param logs array (add multiple logs entries at once)
|
|
79
|
+
*/
|
|
80
|
+
this.queueAuditLogs = (logs) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!this.logQueueTimer) {
|
|
82
|
+
this.startQueue();
|
|
83
|
+
}
|
|
84
|
+
this.logQueue = this.logQueue.concat(logs);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
startQueue() {
|
|
88
|
+
if (!this.logQueueTimer) {
|
|
89
|
+
this.logQueueTimer = setTimeout(() => {
|
|
90
|
+
if (this.logQueue.length > 0) {
|
|
91
|
+
this.addAuditLogs(this.logQueue);
|
|
92
|
+
this.logQueue = [];
|
|
93
|
+
}
|
|
94
|
+
}, this.queueExecutionInterval);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
getEndpoint(endpoint) {
|
|
98
|
+
return `${this.opts.api}/api/auditor${endpoint}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.default = Auditor;
|
|
@@ -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,39 @@
|
|
|
1
|
+
import base from "../base";
|
|
2
|
+
import { Token, User } from "../interfaces/IDP";
|
|
3
|
+
import { Version } from "../interfaces/Global";
|
|
4
|
+
export default class IDP extends base {
|
|
5
|
+
/**
|
|
6
|
+
* Version requests the endpoint version
|
|
7
|
+
* @returns Version object
|
|
8
|
+
*/
|
|
9
|
+
version: () => Promise<Version>;
|
|
10
|
+
/**
|
|
11
|
+
* Authorize validates a token
|
|
12
|
+
* @param token
|
|
13
|
+
* @returns User object
|
|
14
|
+
*/
|
|
15
|
+
authorize: () => Promise<User>;
|
|
16
|
+
/**
|
|
17
|
+
* Register against the identity provider
|
|
18
|
+
* @param name
|
|
19
|
+
* @param email
|
|
20
|
+
* @param password
|
|
21
|
+
* @returns Bearer Token
|
|
22
|
+
*/
|
|
23
|
+
register: (name: string, email: string, password: string) => Promise<User>;
|
|
24
|
+
/**
|
|
25
|
+
* Authenticate against the identity provider with a given email and password.
|
|
26
|
+
* @param email
|
|
27
|
+
* @param password
|
|
28
|
+
* @returns Bearer Token
|
|
29
|
+
*/
|
|
30
|
+
authenticate: (email: string, password: string) => Promise<Token>;
|
|
31
|
+
/**
|
|
32
|
+
* authenticateReturnUser against the identity provider with a given email and password.
|
|
33
|
+
* @param email
|
|
34
|
+
* @param password
|
|
35
|
+
* @returns User object
|
|
36
|
+
*/
|
|
37
|
+
authenticateReturnUser: (email: string, password: string) => Promise<User>;
|
|
38
|
+
private getEndpoint;
|
|
39
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
* Version requests the endpoint version
|
|
19
|
+
* @returns Version object
|
|
20
|
+
*/
|
|
21
|
+
this.version = () => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const resp = yield axios_1.default.get(this.getEndpoint("/v1/version"), {}).catch((err) => {
|
|
23
|
+
throw err;
|
|
24
|
+
});
|
|
25
|
+
return resp.data;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Authorize validates a token
|
|
29
|
+
* @param token
|
|
30
|
+
* @returns User object
|
|
31
|
+
*/
|
|
32
|
+
this.authorize = () => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const resp = yield axios_1.default.get(this.getEndpoint("/v1/authorize"), {}).catch((err) => {
|
|
34
|
+
throw err;
|
|
35
|
+
});
|
|
36
|
+
return resp.data;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Register against the identity provider
|
|
40
|
+
* @param name
|
|
41
|
+
* @param email
|
|
42
|
+
* @param password
|
|
43
|
+
* @returns Bearer Token
|
|
44
|
+
*/
|
|
45
|
+
this.register = (name, email, password) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const resp = yield axios_1.default
|
|
47
|
+
.post(this.getEndpoint("/v1/registration"), { name: name, email: email, password: password })
|
|
48
|
+
.catch((err) => {
|
|
49
|
+
throw err;
|
|
50
|
+
});
|
|
51
|
+
return resp.data;
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Authenticate against the identity provider with a given email and password.
|
|
55
|
+
* @param email
|
|
56
|
+
* @param password
|
|
57
|
+
* @returns Bearer Token
|
|
58
|
+
*/
|
|
59
|
+
this.authenticate = (email, password) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const resp = yield axios_1.default.post(this.getEndpoint("/v1/authenticate"), { email: email, password: password }).catch((err) => {
|
|
61
|
+
throw err;
|
|
62
|
+
});
|
|
63
|
+
// tslint-disable: no-string-literal
|
|
64
|
+
const token = { token: resp.headers.authorization };
|
|
65
|
+
return token;
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* authenticateReturnUser against the identity provider with a given email and password.
|
|
69
|
+
* @param email
|
|
70
|
+
* @param password
|
|
71
|
+
* @returns User object
|
|
72
|
+
*/
|
|
73
|
+
this.authenticateReturnUser = (email, password) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const resp = yield axios_1.default.post(this.getEndpoint("/v1/authenticate"), { email: email, password: password }).catch((err) => {
|
|
75
|
+
throw err;
|
|
76
|
+
});
|
|
77
|
+
return resp.data;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getEndpoint(endpoint) {
|
|
81
|
+
return `${this.opts.api}/api/account${endpoint}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.default = IDP;
|