hcloud-sdk 0.0.6 → 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 CHANGED
@@ -1 +1 @@
1
- # hcloud-sdk-js
1
+ # hcloud-sdk
package/lib/Axios.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AxiosPromise } from 'axios';
2
2
  export default class AxiosService {
3
3
  get: (url: string) => Promise<AxiosPromise>;
4
+ post: (url: string, body: any) => Promise<AxiosPromise>;
4
5
  }
package/lib/Axios.js CHANGED
@@ -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
@@ -0,0 +1,9 @@
1
+ import AxiosService from './Axios';
2
+ export interface Options {
3
+ api: string;
4
+ }
5
+ export default abstract class Base {
6
+ protected opts: Options;
7
+ protected axios: AxiosService;
8
+ constructor(opts: Options);
9
+ }
package/lib/base.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Axios_1 = require("./Axios");
4
+ class Base {
5
+ constructor(opts) {
6
+ this.opts = opts;
7
+ this.axios = new Axios_1.default();
8
+ }
9
+ }
10
+ exports.default = Base;
@@ -0,0 +1,9 @@
1
+ import AxiosService from './Axios';
2
+ export interface options {
3
+ api: string;
4
+ }
5
+ export default abstract class common {
6
+ protected opts: options;
7
+ protected axios: AxiosService;
8
+ constructor(opts: options);
9
+ }
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;
@@ -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
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/hcloud.d.ts CHANGED
@@ -1,11 +1,8 @@
1
- import IDPService from './IDP';
2
- import AxiosService from './Axios';
3
- export interface options {
4
- api: string;
5
- }
6
- export default class hcloud {
7
- protected opts: options;
8
- protected axios: AxiosService;
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 {
9
5
  IDP: IDPService;
10
- constructor(opts: options);
6
+ High5: High5Service;
7
+ constructor(opts: Options);
11
8
  }
package/lib/hcloud.js CHANGED
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const IDP_1 = require("./IDP");
4
- const Axios_1 = require("./Axios");
3
+ const base_1 = require("./base");
4
+ const IDP_1 = require("./service/IDP");
5
+ const High5_1 = require("./service/High5");
5
6
  // tslint:disable-next-line
6
- class hcloud {
7
+ class hcloud extends base_1.default {
7
8
  constructor(opts) {
8
- this.opts = opts;
9
- this.axios = new Axios_1.default();
9
+ super(opts);
10
10
  this.IDP = new IDP_1.default(this.opts);
11
+ this.High5 = new High5_1.default(this.opts);
11
12
  }
12
13
  }
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,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.6",
3
+ "version": "0.0.7",
4
4
  "description": "hcloud platform sdk",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,13 +27,15 @@
27
27
  "devDependencies": {
28
28
  "@types/chai": "^4.3.1",
29
29
  "@types/mocha": "^9.1.1",
30
+ "@types/uuid": "^8.3.4",
30
31
  "chai": "^4.3.6",
31
32
  "mocha": "^10.0.0",
32
33
  "prettier": "^2.6.2",
33
34
  "ts-node": "^10.8.0",
34
35
  "tslint": "^6.1.3",
35
36
  "tslint-config-prettier": "^1.18.0",
36
- "typescript": "^4.7.2"
37
+ "typescript": "^4.7.2",
38
+ "uuid": "^8.3.2"
37
39
  },
38
40
  "dependencies": {
39
41
  "axios": "^0.27.2"
Binary file
package/lib/IDP.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import hcloud from './hcloud';
2
- export default class IDPService extends hcloud {
3
- authenticate: () => Promise<string>;
4
- }
package/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;