hcloud-sdk 0.0.11 → 0.0.14

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/base.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  export interface Options {
2
2
  api: string;
3
+ auditor?: {
4
+ queue?: {
5
+ executionInterval?: number;
6
+ };
7
+ };
3
8
  }
4
9
  export default abstract class Base {
5
10
  protected opts: Options;
package/lib/hcloud.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import base, { Options } from "./base";
2
2
  import IDPService from "./service/IDP";
3
+ import AuditorService from "./service/Auditor";
3
4
  import High5Service from "./service/High5";
4
5
  export default class hcloud extends base {
5
- IDP: IDPService;
6
+ Auditor: AuditorService;
6
7
  High5: High5Service;
8
+ IDP: IDPService;
7
9
  constructor(opts: Options);
8
- setAuthToken(token: string): void;
10
+ setAuthToken(token: string): hcloud;
9
11
  }
package/lib/hcloud.js CHANGED
@@ -2,19 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const base_1 = require("./base");
4
4
  const IDP_1 = require("./service/IDP");
5
+ const Auditor_1 = require("./service/Auditor");
5
6
  const High5_1 = require("./service/High5");
6
7
  const axios_1 = require("axios");
8
+ const package_json_1 = require("../../package.json");
7
9
  // tslint:disable-next-line
8
10
  class hcloud extends base_1.default {
9
11
  constructor(opts) {
10
12
  super(opts);
11
- this.IDP = new IDP_1.default(this.opts);
13
+ this.Auditor = new Auditor_1.default(this.opts);
12
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
+ };
13
19
  }
14
20
  setAuthToken(token) {
15
- axios_1.default.defaults.headers.common = {
21
+ axios_1.default.defaults.headers.common = Object.assign(axios_1.default.defaults.headers.common, {
16
22
  Authorization: token,
17
- };
23
+ });
24
+ return this;
18
25
  }
19
26
  }
20
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,8 @@
1
+ export interface Version {
2
+ version: string;
3
+ }
4
+ export interface ErrorMessage {
5
+ code: string;
6
+ error: string;
7
+ message: string;
8
+ }
File without changes
@@ -7,8 +7,3 @@ export interface User {
7
7
  export interface Token {
8
8
  token: string;
9
9
  }
10
- export interface ErrorMessage {
11
- code: string;
12
- error: string;
13
- message: string;
14
- }
File without changes
@@ -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;
@@ -1,6 +1,12 @@
1
1
  import base from "../base";
2
- import { Token, User } from "../dto/IDP";
2
+ import { Token, User } from "../interfaces/IDP";
3
+ import { Version } from "../interfaces/Global";
3
4
  export default class IDP extends base {
5
+ /**
6
+ * Version requests the endpoint version
7
+ * @returns Version object
8
+ */
9
+ version: () => Promise<Version>;
4
10
  /**
5
11
  * Authorize validates a token
6
12
  * @param token
@@ -14,6 +14,16 @@ const axios_1 = require("axios");
14
14
  class IDP extends base_1.default {
15
15
  constructor() {
16
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
+ });
17
27
  /**
18
28
  * Authorize validates a token
19
29
  * @param token
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hcloud-sdk",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "description": "hcloud platform sdk",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/lib/Axios.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { AxiosPromise } from 'axios';
2
- export default class AxiosService {
3
- get: (url: string) => Promise<AxiosPromise>;
4
- post: (url: string, body: any) => Promise<AxiosPromise>;
5
- }
package/lib/Axios.js DELETED
@@ -1,23 +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 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 DELETED
@@ -1,9 +0,0 @@
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 DELETED
@@ -1,11 +0,0 @@
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 DELETED
@@ -1,14 +0,0 @@
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
- code: string;
12
- error: string;
13
- message: string;
14
- }
package/src/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import hcloud from "./lib/hcloud";
2
- export default hcloud;
package/src/index.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const hcloud_1 = require("./lib/hcloud");
4
- exports.default = hcloud_1.default;
package/src/lib/base.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export interface Options {
2
- api: string;
3
- }
4
- export default abstract class Base {
5
- protected opts: Options;
6
- constructor(opts: Options);
7
- }
package/src/lib/base.js DELETED
@@ -1,8 +0,0 @@
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;
@@ -1,9 +0,0 @@
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
- setAuthToken(token: string): void;
9
- }
package/src/lib/hcloud.js DELETED
@@ -1,24 +0,0 @@
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
- const axios_1 = require("axios");
7
- const package_json_1 = require("../../package.json");
8
- // tslint:disable-next-line
9
- class hcloud extends base_1.default {
10
- constructor(opts) {
11
- super(opts);
12
- this.IDP = new IDP_1.default(this.opts);
13
- this.High5 = new High5_1.default(this.opts);
14
- axios_1.default.defaults.headers.common = {
15
- "User-Agent": "hcloud-sdk-js/v" + package_json_1.version,
16
- };
17
- }
18
- setAuthToken(token) {
19
- axios_1.default.defaults.headers.common = Object.assign(axios_1.default.defaults.headers.common, {
20
- Authorization: token,
21
- });
22
- }
23
- }
24
- exports.default = hcloud;
@@ -1,4 +0,0 @@
1
- import base from "../base";
2
- export default class High5 extends base {
3
- private getEndpoint;
4
- }
@@ -1,9 +0,0 @@
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;
@@ -1,33 +0,0 @@
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: () => 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
- }
@@ -1,74 +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 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 = () => __awaiter(this, void 0, void 0, function* () {
23
- const resp = yield axios_1.default.get(this.getEndpoint("/v1/authorize"), {}).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/authenticate"), { 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/authenticate"), { 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;