hcloud-sdk 0.0.15 → 0.0.16

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/hcloud.d.ts CHANGED
@@ -2,10 +2,12 @@ import base, { Options } from "./base";
2
2
  import IDPService from "./service/IDP";
3
3
  import AuditorService from "./service/Auditor";
4
4
  import High5Service from "./service/High5";
5
+ import MailerService from "./service/Mailer";
5
6
  export default class hcloud extends base {
6
7
  Auditor: AuditorService;
7
8
  High5: High5Service;
8
9
  IDP: IDPService;
10
+ Mailer: MailerService;
9
11
  constructor(opts: Options);
10
12
  setAuthToken(token: string): hcloud;
11
13
  }
package/lib/hcloud.js CHANGED
@@ -4,6 +4,7 @@ const base_1 = require("./base");
4
4
  const IDP_1 = require("./service/IDP");
5
5
  const Auditor_1 = require("./service/Auditor");
6
6
  const High5_1 = require("./service/High5");
7
+ const Mailer_1 = require("./service/Mailer");
7
8
  const axios_1 = require("axios");
8
9
  const package_json_1 = require("../package.json");
9
10
  // tslint:disable-next-line
@@ -13,6 +14,7 @@ class hcloud extends base_1.default {
13
14
  this.Auditor = new Auditor_1.default(this.opts);
14
15
  this.High5 = new High5_1.default(this.opts);
15
16
  this.IDP = new IDP_1.default(this.opts);
17
+ this.Mailer = new Mailer_1.default(this.opts);
16
18
  axios_1.default.defaults.headers.common = {
17
19
  "User-Agent": "hcloud-sdk-js/v" + package_json_1.version,
18
20
  };
@@ -6,7 +6,9 @@ export declare enum Level {
6
6
  }
7
7
  export declare enum Origin {
8
8
  IDP = "idp",
9
- High5 = "high5"
9
+ High5 = "high5",
10
+ Auditor = "auditor",
11
+ Mailer = "mailer"
10
12
  }
11
13
  export declare enum Event {
12
14
  Login = "login",
@@ -15,10 +17,12 @@ export declare enum Event {
15
17
  Organization = "organization",
16
18
  App = "app",
17
19
  Event = "event",
18
- Stream = "stream"
20
+ Stream = "stream",
21
+ Mail = "mail"
19
22
  }
20
23
  export declare enum Type {
21
24
  Read = "read",
25
+ Write = "write",
22
26
  Create = "create",
23
27
  Update = "update",
24
28
  Delete = "delete",
@@ -26,7 +30,9 @@ export declare enum Type {
26
30
  Connect = "connect",
27
31
  Disconnect = "disconnect",
28
32
  Add = "add",
29
- Remove = "remove"
33
+ Remove = "remove",
34
+ Send = "send",
35
+ Receive = "receive"
30
36
  }
31
37
  export interface AuditLog {
32
38
  level: Level;
@@ -12,6 +12,8 @@ var Origin;
12
12
  (function (Origin) {
13
13
  Origin["IDP"] = "idp";
14
14
  Origin["High5"] = "high5";
15
+ Origin["Auditor"] = "auditor";
16
+ Origin["Mailer"] = "mailer";
15
17
  })(Origin = exports.Origin || (exports.Origin = {}));
16
18
  var Event;
17
19
  (function (Event) {
@@ -22,10 +24,12 @@ var Event;
22
24
  Event["App"] = "app";
23
25
  Event["Event"] = "event";
24
26
  Event["Stream"] = "stream";
27
+ Event["Mail"] = "mail";
25
28
  })(Event = exports.Event || (exports.Event = {}));
26
29
  var Type;
27
30
  (function (Type) {
28
31
  Type["Read"] = "read";
32
+ Type["Write"] = "write";
29
33
  Type["Create"] = "create";
30
34
  Type["Update"] = "update";
31
35
  Type["Delete"] = "delete";
@@ -34,4 +38,6 @@ var Type;
34
38
  Type["Disconnect"] = "disconnect";
35
39
  Type["Add"] = "add";
36
40
  Type["Remove"] = "remove";
41
+ Type["Send"] = "send";
42
+ Type["Receive"] = "receive";
37
43
  })(Type = exports.Type || (exports.Type = {}));
@@ -0,0 +1,29 @@
1
+ export declare enum Template {
2
+ REGISTER = "register",
3
+ RESET_PASSWORD = "reset_password"
4
+ }
5
+ export interface Mail {
6
+ recipients: string[];
7
+ subject: string;
8
+ }
9
+ export interface MailReplacement {
10
+ key: string;
11
+ value: string;
12
+ }
13
+ export interface TemplateMail extends Mail {
14
+ template: Template;
15
+ replacements: MailReplacement[];
16
+ }
17
+ /**
18
+ * @param html base64 encoded html string
19
+ */
20
+ export interface HtmlMail extends Mail {
21
+ html: string;
22
+ }
23
+ /**
24
+ * @param html base64 encoded html string
25
+ */
26
+ export interface MustacheMail extends Mail {
27
+ html: string;
28
+ replacements: MailReplacement[];
29
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Template = void 0;
4
+ var Template;
5
+ (function (Template) {
6
+ Template["REGISTER"] = "register";
7
+ Template["RESET_PASSWORD"] = "reset_password";
8
+ })(Template = exports.Template || (exports.Template = {}));
@@ -1,10 +1,10 @@
1
- import base from "../base";
1
+ import base, { Options } from "../base";
2
2
  import { AuditLog } from "../interfaces/Auditor";
3
3
  import { Version } from "../interfaces/Global";
4
+ import { AuditorInternal } from "./AuditorInternal";
4
5
  export default class Auditor extends base {
5
- private queueExecutionInterval;
6
- private logQueue;
7
- private logQueueTimer;
6
+ internal: AuditorInternal;
7
+ constructor(opts: Options);
8
8
  /**
9
9
  * Version requests the endpoint version
10
10
  * @returns Version object
@@ -18,25 +18,5 @@ export default class Auditor extends base {
18
18
  * @returns User object
19
19
  */
20
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
21
  private getEndpoint;
42
22
  }
@@ -11,12 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const base_1 = require("../base");
13
13
  const axios_1 = require("axios");
14
+ const AuditorInternal_1 = require("./AuditorInternal");
14
15
  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 = [];
16
+ constructor(opts) {
17
+ super(opts);
20
18
  /**
21
19
  * Version requests the endpoint version
22
20
  * @returns Version object
@@ -54,45 +52,7 @@ class Auditor extends base_1.default {
54
52
  });
55
53
  return resp.data;
56
54
  });
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
- }
55
+ this.internal = new AuditorInternal_1.AuditorInternal(opts);
96
56
  }
97
57
  getEndpoint(endpoint) {
98
58
  return `${this.opts.api}/api/auditor${endpoint}`;
@@ -0,0 +1,28 @@
1
+ import base from "../base";
2
+ import { AuditLog } from "../interfaces/Auditor";
3
+ export declare class AuditorInternal extends base {
4
+ private queueExecutionInterval;
5
+ private logQueue;
6
+ private logQueueTimer;
7
+ /**
8
+ * AddAuditLogs adds log entries
9
+ *
10
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
11
+ *
12
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
13
+ * @param logs array (add multiple logs entries at once)
14
+ * @returns AuditLog array
15
+ */
16
+ addAuditLogs: (logs: AuditLog[]) => Promise<AuditLog[]>;
17
+ /**
18
+ * QueueAuditLogs adds log entries to a queue that will be processed periodically
19
+ *
20
+ * THIS COMES WITH DOWNSIDE OF LOG TIMESTAMPS BEING INACCURATE AS THEY ARE CREATED BY THE Auditor SERVER
21
+ *
22
+ * TIMESTAMPS MIGHT DIFFER AS MUCH AS: this.opts.auditor.queue.executionInterval || 500
23
+ * @param logs array (add multiple logs entries at once)
24
+ */
25
+ queueAuditLogs: (logs: AuditLog[]) => Promise<void>;
26
+ private startQueue;
27
+ private getEndpoint;
28
+ }
@@ -0,0 +1,65 @@
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
+ exports.AuditorInternal = void 0;
13
+ const axios_1 = require("axios");
14
+ const base_1 = require("../base");
15
+ class AuditorInternal extends base_1.default {
16
+ constructor() {
17
+ var _a, _b;
18
+ super(...arguments);
19
+ this.queueExecutionInterval = ((_b = (_a = this.opts.auditor) === null || _a === void 0 ? void 0 : _a.queue) === null || _b === void 0 ? void 0 : _b.executionInterval) || 500;
20
+ this.logQueue = [];
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
+ this.addAuditLogs = (logs) => __awaiter(this, void 0, void 0, function* () {
31
+ const resp = yield axios_1.default.post(this.getEndpoint("/v1/logs"), logs).catch((err) => {
32
+ throw err;
33
+ });
34
+ return resp.data;
35
+ });
36
+ /**
37
+ * QueueAuditLogs adds log entries to a queue that will be processed periodically
38
+ *
39
+ * THIS COMES WITH DOWNSIDE OF LOG TIMESTAMPS BEING INACCURATE AS THEY ARE CREATED BY THE Auditor SERVER
40
+ *
41
+ * TIMESTAMPS MIGHT DIFFER AS MUCH AS: this.opts.auditor.queue.executionInterval || 500
42
+ * @param logs array (add multiple logs entries at once)
43
+ */
44
+ this.queueAuditLogs = (logs) => __awaiter(this, void 0, void 0, function* () {
45
+ if (!this.logQueueTimer) {
46
+ this.startQueue();
47
+ }
48
+ this.logQueue = this.logQueue.concat(logs);
49
+ });
50
+ }
51
+ startQueue() {
52
+ if (!this.logQueueTimer) {
53
+ this.logQueueTimer = setTimeout(() => {
54
+ if (this.logQueue.length > 0) {
55
+ this.addAuditLogs(this.logQueue);
56
+ this.logQueue = [];
57
+ }
58
+ }, this.queueExecutionInterval);
59
+ }
60
+ }
61
+ getEndpoint(endpoint) {
62
+ return `${this.opts.api}/api/auditor/internal${endpoint}`;
63
+ }
64
+ }
65
+ exports.AuditorInternal = AuditorInternal;
@@ -0,0 +1,13 @@
1
+ import base, { Options } from "../base";
2
+ import { Version } from "../interfaces/Global";
3
+ import MailerInternal from "./MailerInternal";
4
+ export default class Mailer extends base {
5
+ interal: MailerInternal;
6
+ constructor(opts: Options);
7
+ /**
8
+ * Version requests the endpoint version
9
+ * @returns Version object
10
+ */
11
+ version: () => Promise<Version>;
12
+ private getEndpoint;
13
+ }
@@ -0,0 +1,34 @@
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
+ const MailerInternal_1 = require("./MailerInternal");
15
+ class Mailer extends base_1.default {
16
+ constructor(opts) {
17
+ super(opts);
18
+ /**
19
+ * Version requests the endpoint version
20
+ * @returns Version object
21
+ */
22
+ this.version = () => __awaiter(this, void 0, void 0, function* () {
23
+ const resp = yield axios_1.default.get(this.getEndpoint("/v1/version"), {}).catch((err) => {
24
+ throw err;
25
+ });
26
+ return resp.data;
27
+ });
28
+ this.interal = new MailerInternal_1.default(opts);
29
+ }
30
+ getEndpoint(endpoint) {
31
+ return `${this.opts.api}/api/mailer${endpoint}`;
32
+ }
33
+ }
34
+ exports.default = Mailer;
@@ -0,0 +1,32 @@
1
+ import base from "../base";
2
+ import { HtmlMail, MustacheMail, TemplateMail } from "../interfaces/Mail";
3
+ export default class MailerInternal extends base {
4
+ /**
5
+ * sendMailMustache sends a new mail based on a mustache html body
6
+ *
7
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
8
+ *
9
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
10
+ * @param mail TemplateMail
11
+ */
12
+ sendMailMustache: (mail: MustacheMail) => Promise<void>;
13
+ /**
14
+ * sendMailHtml sends a new mail based on a html body
15
+ *
16
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
17
+ *
18
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
19
+ * @param mail TemplateMail
20
+ */
21
+ sendMailHtml: (mail: HtmlMail) => Promise<void>;
22
+ /**
23
+ * sendMailTemplate sends a new mail based on an existing template
24
+ *
25
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
26
+ *
27
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
28
+ * @param mail TemplateMail
29
+ */
30
+ sendMailTemplate: (mail: TemplateMail) => Promise<void>;
31
+ private getEndpoint;
32
+ }
@@ -0,0 +1,64 @@
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 MailerInternal extends base_1.default {
15
+ constructor() {
16
+ super(...arguments);
17
+ /**
18
+ * sendMailMustache sends a new mail based on a mustache html body
19
+ *
20
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
21
+ *
22
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
23
+ * @param mail TemplateMail
24
+ */
25
+ this.sendMailMustache = (mail) => __awaiter(this, void 0, void 0, function* () {
26
+ const resp = yield axios_1.default.post(this.getEndpoint("/v1/send/mustache"), mail).catch((err) => {
27
+ throw err;
28
+ });
29
+ return resp.data;
30
+ });
31
+ /**
32
+ * sendMailHtml sends a new mail based on a html body
33
+ *
34
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
35
+ *
36
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
37
+ * @param mail TemplateMail
38
+ */
39
+ this.sendMailHtml = (mail) => __awaiter(this, void 0, void 0, function* () {
40
+ const resp = yield axios_1.default.post(this.getEndpoint("/v1/send/html"), mail).catch((err) => {
41
+ throw err;
42
+ });
43
+ return resp.data;
44
+ });
45
+ /**
46
+ * sendMailTemplate sends a new mail based on an existing template
47
+ *
48
+ * THIS ENDPOINT WORKS INTERNALLY ONLY
49
+ *
50
+ * CAN ONLY BE USED FROM BACKENDS WITHIN THE hcloud DEPLOYMENT AS THE ENDPOINT IS NOT PUBLICLY EXPOSED
51
+ * @param mail TemplateMail
52
+ */
53
+ this.sendMailTemplate = (mail) => __awaiter(this, void 0, void 0, function* () {
54
+ const resp = yield axios_1.default.post(this.getEndpoint("/v1/send/template"), mail).catch((err) => {
55
+ throw err;
56
+ });
57
+ return resp.data;
58
+ });
59
+ }
60
+ getEndpoint(endpoint) {
61
+ return `${this.opts.api}/api/mailer/internal${endpoint}`;
62
+ }
63
+ }
64
+ exports.default = MailerInternal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hcloud-sdk",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
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
  }