@sdflc/backend-helpers 1.0.139 → 1.0.140

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.
Files changed (56) hide show
  1. package/README.md +176 -20
  2. package/build/EmergencyAlerter.d.ts +140 -0
  3. package/build/EmergencyAlerter.js +465 -0
  4. package/build/esm/EmergencyAlerter.d.ts +140 -0
  5. package/build/esm/EmergencyAlerter.js +454 -0
  6. package/build/esm/gateways/BaseExternalApiGateway.d.ts +94 -0
  7. package/build/esm/gateways/BaseExternalApiGateway.js +319 -0
  8. package/build/esm/gateways/DiscordWebhookGw.d.ts +50 -0
  9. package/build/esm/gateways/DiscordWebhookGw.js +70 -0
  10. package/build/esm/gateways/HttpWebhookGw.d.ts +43 -0
  11. package/build/esm/gateways/HttpWebhookGw.js +131 -0
  12. package/build/esm/gateways/SendGridGw.d.ts +41 -0
  13. package/build/esm/gateways/SendGridGw.js +116 -0
  14. package/build/esm/gateways/SlackWebhookGw.d.ts +23 -0
  15. package/build/esm/gateways/SlackWebhookGw.js +59 -0
  16. package/build/esm/gateways/TelegramGw.d.ts +45 -0
  17. package/build/esm/gateways/TelegramGw.js +110 -0
  18. package/build/esm/gateways/TwilioGw.d.ts +33 -0
  19. package/build/esm/gateways/TwilioGw.js +107 -0
  20. package/build/esm/gateways/externalUrl.d.ts +16 -0
  21. package/build/esm/gateways/externalUrl.js +116 -0
  22. package/build/esm/gateways/guardedFetch.d.ts +15 -0
  23. package/build/esm/gateways/guardedFetch.js +133 -0
  24. package/build/esm/gateways/index.d.ts +9 -0
  25. package/build/esm/gateways/index.js +9 -0
  26. package/build/esm/index.d.ts +2 -1
  27. package/build/esm/index.js +2 -1
  28. package/build/esm/interfaces/BaseExternalApiGatewayPropsInterface.d.ts +16 -2
  29. package/build/gateways/BaseExternalApiGateway.d.ts +94 -0
  30. package/build/gateways/BaseExternalApiGateway.js +326 -0
  31. package/build/gateways/DiscordWebhookGw.d.ts +50 -0
  32. package/build/gateways/DiscordWebhookGw.js +73 -0
  33. package/build/gateways/HttpWebhookGw.d.ts +43 -0
  34. package/build/gateways/HttpWebhookGw.js +135 -0
  35. package/build/gateways/SendGridGw.d.ts +41 -0
  36. package/build/gateways/SendGridGw.js +119 -0
  37. package/build/gateways/SlackWebhookGw.d.ts +23 -0
  38. package/build/gateways/SlackWebhookGw.js +62 -0
  39. package/build/gateways/TelegramGw.d.ts +45 -0
  40. package/build/gateways/TelegramGw.js +115 -0
  41. package/build/gateways/TwilioGw.d.ts +33 -0
  42. package/build/gateways/TwilioGw.js +110 -0
  43. package/build/gateways/externalUrl.d.ts +16 -0
  44. package/build/gateways/externalUrl.js +121 -0
  45. package/build/gateways/guardedFetch.d.ts +15 -0
  46. package/build/gateways/guardedFetch.js +141 -0
  47. package/build/gateways/index.d.ts +9 -0
  48. package/build/gateways/index.js +25 -0
  49. package/build/index.d.ts +2 -1
  50. package/build/index.js +2 -1
  51. package/build/interfaces/BaseExternalApiGatewayPropsInterface.d.ts +16 -2
  52. package/package.json +2 -1
  53. package/build/BaseExternalApiGateway.d.ts +0 -16
  54. package/build/BaseExternalApiGateway.js +0 -54
  55. package/build/esm/BaseExternalApiGateway.d.ts +0 -16
  56. package/build/esm/BaseExternalApiGateway.js +0 -48
@@ -1,16 +0,0 @@
1
- import { Logger } from '@sdflc/utils';
2
- import { BaseExternalApiGatewayPropsInterface } from './interfaces';
3
- declare abstract class BaseExternalApiGateway {
4
- protected logger: Logger;
5
- protected baseUrl: string;
6
- protected timeoutMs: number;
7
- private _credentials;
8
- private _credentialsSet;
9
- constructor(props?: BaseExternalApiGatewayPropsInterface);
10
- setCredentials(credentials: string | Record<string, any>): this;
11
- hasCredentials(): boolean;
12
- protected get credentials(): string | Record<string, any>;
13
- protected assertCredentials(): void;
14
- protected onCredentialsSet(): void;
15
- }
16
- export { BaseExternalApiGateway };
@@ -1,54 +0,0 @@
1
- "use strict";
2
- // ./src/baseExternalApiGateway.ts
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BaseExternalApiGateway = void 0;
8
- const check_types_1 = __importDefault(require("check-types"));
9
- const utils_1 = require("@sdflc/utils");
10
- class BaseExternalApiGateway {
11
- logger;
12
- baseUrl;
13
- timeoutMs;
14
- _credentials = null;
15
- _credentialsSet = false;
16
- constructor(props) {
17
- const { credentials, baseUrl, timeoutMs, logger } = props || {};
18
- this.baseUrl = baseUrl ?? '';
19
- this.timeoutMs = timeoutMs ?? 10_000;
20
- this.logger = (0, utils_1.isLogger)(logger) ? logger : new utils_1.Logger({ level: utils_1.LoggerLevels.ERROR });
21
- if (credentials !== undefined) {
22
- this.setCredentials(credentials);
23
- }
24
- }
25
- // ─── Credentials ───────────────────────────────────────────────────────────
26
- setCredentials(credentials) {
27
- if (!check_types_1.default.string(credentials) && !check_types_1.default.object(credentials)) {
28
- throw new Error(`${this.constructor.name}.setCredentials: credentials must be a string or an object`);
29
- }
30
- if (check_types_1.default.string(credentials) && !credentials.trim()) {
31
- throw new Error(`${this.constructor.name}.setCredentials: credentials string must not be empty`);
32
- }
33
- this._credentials = credentials;
34
- this._credentialsSet = true;
35
- this.onCredentialsSet();
36
- return this;
37
- }
38
- hasCredentials() {
39
- return this._credentialsSet;
40
- }
41
- get credentials() {
42
- return this._credentials;
43
- }
44
- assertCredentials() {
45
- if (!this._credentialsSet) {
46
- throw new Error(`${this.constructor.name}: credentials have not been set. ` + `Call setCredentials() before making API calls.`);
47
- }
48
- }
49
- // ─── Lifecycle hook ────────────────────────────────────────────────────────
50
- onCredentialsSet() {
51
- // no-op — override in subclass to initialise SDK clients etc.
52
- }
53
- }
54
- exports.BaseExternalApiGateway = BaseExternalApiGateway;
@@ -1,16 +0,0 @@
1
- import { Logger } from '@sdflc/utils';
2
- import { BaseExternalApiGatewayPropsInterface } from './interfaces';
3
- declare abstract class BaseExternalApiGateway {
4
- protected logger: Logger;
5
- protected baseUrl: string;
6
- protected timeoutMs: number;
7
- private _credentials;
8
- private _credentialsSet;
9
- constructor(props?: BaseExternalApiGatewayPropsInterface);
10
- setCredentials(credentials: string | Record<string, any>): this;
11
- hasCredentials(): boolean;
12
- protected get credentials(): string | Record<string, any>;
13
- protected assertCredentials(): void;
14
- protected onCredentialsSet(): void;
15
- }
16
- export { BaseExternalApiGateway };
@@ -1,48 +0,0 @@
1
- // ./src/baseExternalApiGateway.ts
2
- import check from 'check-types';
3
- import { Logger, LoggerLevels, isLogger } from '@sdflc/utils';
4
- class BaseExternalApiGateway {
5
- logger;
6
- baseUrl;
7
- timeoutMs;
8
- _credentials = null;
9
- _credentialsSet = false;
10
- constructor(props) {
11
- const { credentials, baseUrl, timeoutMs, logger } = props || {};
12
- this.baseUrl = baseUrl ?? '';
13
- this.timeoutMs = timeoutMs ?? 10_000;
14
- this.logger = isLogger(logger) ? logger : new Logger({ level: LoggerLevels.ERROR });
15
- if (credentials !== undefined) {
16
- this.setCredentials(credentials);
17
- }
18
- }
19
- // ─── Credentials ───────────────────────────────────────────────────────────
20
- setCredentials(credentials) {
21
- if (!check.string(credentials) && !check.object(credentials)) {
22
- throw new Error(`${this.constructor.name}.setCredentials: credentials must be a string or an object`);
23
- }
24
- if (check.string(credentials) && !credentials.trim()) {
25
- throw new Error(`${this.constructor.name}.setCredentials: credentials string must not be empty`);
26
- }
27
- this._credentials = credentials;
28
- this._credentialsSet = true;
29
- this.onCredentialsSet();
30
- return this;
31
- }
32
- hasCredentials() {
33
- return this._credentialsSet;
34
- }
35
- get credentials() {
36
- return this._credentials;
37
- }
38
- assertCredentials() {
39
- if (!this._credentialsSet) {
40
- throw new Error(`${this.constructor.name}: credentials have not been set. ` + `Call setCredentials() before making API calls.`);
41
- }
42
- }
43
- // ─── Lifecycle hook ────────────────────────────────────────────────────────
44
- onCredentialsSet() {
45
- // no-op — override in subclass to initialise SDK clients etc.
46
- }
47
- }
48
- export { BaseExternalApiGateway };