hcloud-sdk 0.0.5 → 0.0.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 MoovIT Software Products GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # hcloud-sdk
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import hcloud from "./lib/hcloud";
2
+ export default hcloud;
package/lib/base.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface Options {
2
+ api: string;
3
+ }
4
+ export default abstract class Base {
5
+ protected opts: Options;
6
+ constructor(opts: Options);
7
+ }
package/lib/base.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Base {
4
+ constructor(opts) {
5
+ this.opts = opts;
6
+ }
7
+ }
8
+ exports.default = Base;
@@ -0,0 +1,13 @@
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 ErrorMessage {
11
+ status: number;
12
+ message: string;
13
+ }
package/lib/dto/IDP.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import base, { Options } from "./base";
2
+ import IDPService from "./service/IDP";
3
+ import High5Service from "./service/High5";
4
+ export default class hcloud extends base {
5
+ IDP: IDPService;
6
+ High5: High5Service;
7
+ constructor(opts: Options);
8
+ }
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,4 @@
1
+ import base from "../base";
2
+ export default class High5 extends base {
3
+ private getEndpoint;
4
+ }
@@ -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,74 @@
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.post(this.getEndpoint("/v1/authenticate"), {}, { headers: { Authorization: token } }).catch((err) => {
24
+ throw err;
25
+ });
26
+ return resp.data;
27
+ });
28
+ /**
29
+ * Register against the identity provider
30
+ * @param name
31
+ * @param email
32
+ * @param password
33
+ * @returns Bearer Token
34
+ */
35
+ this.register = (name, email, password) => __awaiter(this, void 0, void 0, function* () {
36
+ const resp = yield axios_1.default
37
+ .post(this.getEndpoint("/v1/registration"), { name: name, email: email, password: password })
38
+ .catch((err) => {
39
+ throw err;
40
+ });
41
+ return resp.data;
42
+ });
43
+ /**
44
+ * Authenticate against the identity provider with a given email and password.
45
+ * @param email
46
+ * @param password
47
+ * @returns Bearer Token
48
+ */
49
+ this.authenticate = (email, password) => __awaiter(this, void 0, void 0, function* () {
50
+ const resp = yield axios_1.default.post(this.getEndpoint("/v1/authorize"), { email: email, password: password }).catch((err) => {
51
+ throw err;
52
+ });
53
+ // tslint-disable: no-string-literal
54
+ const token = { token: resp.headers.authorization };
55
+ return token;
56
+ });
57
+ /**
58
+ * authenticateReturnUser against the identity provider with a given email and password.
59
+ * @param email
60
+ * @param password
61
+ * @returns User object
62
+ */
63
+ this.authenticateReturnUser = (email, password) => __awaiter(this, void 0, void 0, function* () {
64
+ const resp = yield axios_1.default.post(this.getEndpoint("/v1/authorize"), { email: email, password: password }).catch((err) => {
65
+ throw err;
66
+ });
67
+ return resp.data;
68
+ });
69
+ }
70
+ getEndpoint(endpoint) {
71
+ return `${this.opts.api}/api/account${endpoint}`;
72
+ }
73
+ }
74
+ exports.default = IDP;
package/package.json CHANGED
@@ -1,44 +1,43 @@
1
1
  {
2
- "name": "hcloud-sdk",
3
- "version": "0.0.5",
4
- "description": "hcloud platform sdk",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "scripts": {
8
- "test": "mocha -r ts-node/register test/**/*.test.ts",
9
- "format": "prettier --write \"src/**/*.ts\"",
10
- "lint": "tslint -p tsconfig.json",
11
- "build": "tsc"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/moovit-sp-gmbh/hcloud-sdk-js.git"
16
- },
17
- "keywords": [
18
- "hcloud",
19
- "sdk"
20
- ],
21
- "files": [
22
- "build/**/*"
23
- ],
24
- "license": "ISC",
25
- "bugs": {
26
- "url": "https://github.com/moovit-sp-gmbh/hcloud-sdk-js/issues"
27
- },
28
- "author": "moovit-sp-gmbh",
29
- "homepage": "https://github.com/moovit-sp-gmbh/hcloud-sdk-js#readme",
30
- "devDependencies": {
31
- "@types/chai": "^4.3.1",
32
- "@types/mocha": "^9.1.1",
33
- "chai": "^4.3.6",
34
- "mocha": "^10.0.0",
35
- "prettier": "^2.6.2",
36
- "ts-node": "^10.8.0",
37
- "tslint": "^6.1.3",
38
- "tslint-config-prettier": "^1.18.0",
39
- "typescript": "^4.7.2"
40
- },
41
- "dependencies": {
42
- "axios": "^0.27.2"
43
- }
2
+ "name": "hcloud-sdk",
3
+ "version": "0.0.8",
4
+ "description": "hcloud platform sdk",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "mocha -r ts-node/register tests/**/*.test.ts",
9
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.test.ts\"",
10
+ "lint": "tslint -p tsconfig.json",
11
+ "build": "tsc"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/moovit-sp-gmbh/hcloud-sdk-js.git"
16
+ },
17
+ "keywords": [
18
+ "hcloud",
19
+ "sdk"
20
+ ],
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/moovit-sp-gmbh/hcloud-sdk-js/issues"
24
+ },
25
+ "author": "moovit-sp-gmbh",
26
+ "homepage": "https://github.com/moovit-sp-gmbh/hcloud-sdk-js#readme",
27
+ "devDependencies": {
28
+ "@types/chai": "^4.3.1",
29
+ "@types/mocha": "^9.1.1",
30
+ "@types/uuid": "^8.3.4",
31
+ "chai": "^4.3.6",
32
+ "mocha": "^10.0.0",
33
+ "prettier": "^2.6.2",
34
+ "ts-node": "^10.8.0",
35
+ "tslint": "^6.1.3",
36
+ "tslint-config-prettier": "^1.18.0",
37
+ "typescript": "^4.7.2",
38
+ "uuid": "^8.3.2"
39
+ },
40
+ "dependencies": {
41
+ "axios": "^0.27.2"
42
+ }
44
43
  }