hcloud-sdk 0.0.11 → 0.0.12

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/dto/IDP.d.ts CHANGED
@@ -8,7 +8,6 @@ export interface Token {
8
8
  token: string;
9
9
  }
10
10
  export interface ErrorMessage {
11
- code: string;
12
- error: string;
11
+ status: number;
13
12
  message: string;
14
13
  }
@@ -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.get(this.getEndpoint("/v1/authorize"), {}).catch((err) => {
23
+ const resp = yield axios_1.default.post(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.11",
3
+ "version": "0.0.12",
4
4
  "description": "hcloud platform sdk",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -46,5 +46,6 @@
46
46
  "doc:dev": "vuepress dev _docs/src",
47
47
  "doc:export": "vuepress export _docs/src",
48
48
  "build": "tsc"
49
- }
49
+ },
50
+ "readme": "# hcloud-sdk\n[![MIT License](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Latest Release](https://img.shields.io/npm/v/hcloud-sdk.svg)](https://www.npmjs.com/package/hcloud-sdk)\n"
50
51
  }
package/src/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;
@@ -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/src/lib/hcloud.js CHANGED
@@ -2,6 +2,7 @@
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");
7
8
  const package_json_1 = require("../../package.json");
@@ -9,8 +10,9 @@ const package_json_1 = require("../../package.json");
9
10
  class hcloud extends base_1.default {
10
11
  constructor(opts) {
11
12
  super(opts);
12
- this.IDP = new IDP_1.default(this.opts);
13
+ this.Auditor = new Auditor_1.default(this.opts);
13
14
  this.High5 = new High5_1.default(this.opts);
15
+ this.IDP = new IDP_1.default(this.opts);
14
16
  axios_1.default.defaults.headers.common = {
15
17
  "User-Agent": "hcloud-sdk-js/v" + package_json_1.version,
16
18
  };
@@ -19,6 +21,7 @@ class hcloud extends base_1.default {
19
21
  axios_1.default.defaults.headers.common = Object.assign(axios_1.default.defaults.headers.common, {
20
22
  Authorization: token,
21
23
  });
24
+ return this;
22
25
  }
23
26
  }
24
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
- }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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/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;