@rapidrest/core 1.0.1

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 (135) hide show
  1. package/LICENSE +23 -0
  2. package/README.rst +37 -0
  3. package/dist/lib/AlertUtils.js +239 -0
  4. package/dist/lib/AlertUtils.js.map +1 -0
  5. package/dist/lib/ApiError.js +34 -0
  6. package/dist/lib/ApiError.js.map +1 -0
  7. package/dist/lib/ClassLoader.js +159 -0
  8. package/dist/lib/ClassLoader.js.map +1 -0
  9. package/dist/lib/FileUtils.js +190 -0
  10. package/dist/lib/FileUtils.js.map +1 -0
  11. package/dist/lib/JWTUtils.js +111 -0
  12. package/dist/lib/JWTUtils.js.map +1 -0
  13. package/dist/lib/Logger.js +28 -0
  14. package/dist/lib/Logger.js.map +1 -0
  15. package/dist/lib/MessagingUtils.js +218 -0
  16. package/dist/lib/MessagingUtils.js.map +1 -0
  17. package/dist/lib/NotificationsUtils.js +52 -0
  18. package/dist/lib/NotificationsUtils.js.map +1 -0
  19. package/dist/lib/OASUtils.js +207 -0
  20. package/dist/lib/OASUtils.js.map +1 -0
  21. package/dist/lib/ObjectFactory.js +302 -0
  22. package/dist/lib/ObjectFactory.js.map +1 -0
  23. package/dist/lib/ObjectUtils.js +49 -0
  24. package/dist/lib/ObjectUtils.js.map +1 -0
  25. package/dist/lib/StringUtils.js +104 -0
  26. package/dist/lib/StringUtils.js.map +1 -0
  27. package/dist/lib/TelemetryUtils.js +159 -0
  28. package/dist/lib/TelemetryUtils.js.map +1 -0
  29. package/dist/lib/UserUtils.js +138 -0
  30. package/dist/lib/UserUtils.js.map +1 -0
  31. package/dist/lib/ValidationUtils.js +130 -0
  32. package/dist/lib/ValidationUtils.js.map +1 -0
  33. package/dist/lib/decorators/ObjectDecorators.js +95 -0
  34. package/dist/lib/decorators/ObjectDecorators.js.map +1 -0
  35. package/dist/lib/decorators/index.js +2 -0
  36. package/dist/lib/decorators/index.js.map +1 -0
  37. package/dist/lib/index.js +18 -0
  38. package/dist/lib/index.js.map +1 -0
  39. package/dist/lib/sleep.js +15 -0
  40. package/dist/lib/sleep.js.map +1 -0
  41. package/dist/lib/threads/ThreadLogger.js +43 -0
  42. package/dist/lib/threads/ThreadLogger.js.map +1 -0
  43. package/dist/lib/threads/ThreadPool.js +270 -0
  44. package/dist/lib/threads/ThreadPool.js.map +1 -0
  45. package/dist/lib/threads/ThreadWorker.js +25 -0
  46. package/dist/lib/threads/ThreadWorker.js.map +1 -0
  47. package/dist/lib/threads/ThreadWorkerEntry.js +77 -0
  48. package/dist/lib/threads/ThreadWorkerEntry.js.map +1 -0
  49. package/dist/lib/threads/index.js +3 -0
  50. package/dist/lib/threads/index.js.map +1 -0
  51. package/dist/types/AlertUtils.d.ts +132 -0
  52. package/dist/types/ApiError.d.ts +13 -0
  53. package/dist/types/ClassLoader.d.ts +87 -0
  54. package/dist/types/FileUtils.d.ts +46 -0
  55. package/dist/types/JWTUtils.d.ts +139 -0
  56. package/dist/types/Logger.d.ts +7 -0
  57. package/dist/types/MessagingUtils.d.ts +77 -0
  58. package/dist/types/NotificationsUtils.d.ts +32 -0
  59. package/dist/types/OASUtils.d.ts +54 -0
  60. package/dist/types/ObjectFactory.d.ts +77 -0
  61. package/dist/types/ObjectUtils.d.ts +17 -0
  62. package/dist/types/StringUtils.d.ts +52 -0
  63. package/dist/types/TelemetryUtils.d.ts +84 -0
  64. package/dist/types/UserUtils.d.ts +61 -0
  65. package/dist/types/ValidationUtils.d.ts +66 -0
  66. package/dist/types/decorators/ObjectDecorators.d.ts +55 -0
  67. package/dist/types/decorators/index.d.ts +1 -0
  68. package/dist/types/index.d.ts +17 -0
  69. package/dist/types/sleep.d.ts +5 -0
  70. package/dist/types/threads/ThreadLogger.d.ts +15 -0
  71. package/dist/types/threads/ThreadPool.d.ts +115 -0
  72. package/dist/types/threads/ThreadWorker.d.ts +41 -0
  73. package/dist/types/threads/ThreadWorkerEntry.d.ts +1 -0
  74. package/dist/types/threads/index.d.ts +2 -0
  75. package/docs/Makefile +20 -0
  76. package/docs/conf.py +58 -0
  77. package/docs/index.rst +17 -0
  78. package/docs/make.bat +35 -0
  79. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/README.md +21 -0
  80. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Config.md +47 -0
  81. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Destroy.md +27 -0
  82. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Init.md +33 -0
  83. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Inject.md +45 -0
  84. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Logger.md +27 -0
  85. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Nullable.md +27 -0
  86. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/functions/Validator.md +39 -0
  87. package/docs/reference/@rapidrest/namespaces/ObjectDecorators/type-aliases/ValidatorFunction.md +31 -0
  88. package/docs/reference/README.md +73 -0
  89. package/docs/reference/classes/AlertUtils.md +158 -0
  90. package/docs/reference/classes/ApiError.md +263 -0
  91. package/docs/reference/classes/ClassLoader.md +224 -0
  92. package/docs/reference/classes/Event.md +109 -0
  93. package/docs/reference/classes/EventUtils.md +123 -0
  94. package/docs/reference/classes/FileUtils.md +193 -0
  95. package/docs/reference/classes/JWTUtils.md +91 -0
  96. package/docs/reference/classes/MessagingUtils.md +145 -0
  97. package/docs/reference/classes/OASUtils.md +213 -0
  98. package/docs/reference/classes/ObjectFactory.md +274 -0
  99. package/docs/reference/classes/ObjectUtils.md +60 -0
  100. package/docs/reference/classes/StringUtils.md +169 -0
  101. package/docs/reference/classes/ThreadPool.md +249 -0
  102. package/docs/reference/classes/ThreadWorker.md +91 -0
  103. package/docs/reference/classes/UserUtils.md +239 -0
  104. package/docs/reference/classes/ValidationUtils.md +294 -0
  105. package/docs/reference/enumerations/AlertPriority.md +61 -0
  106. package/docs/reference/enumerations/JWTUtilsCompressionMethods.md +21 -0
  107. package/docs/reference/enumerations/WorkerMessageType.md +43 -0
  108. package/docs/reference/functions/sleep.md +25 -0
  109. package/docs/reference/interfaces/Alert.md +101 -0
  110. package/docs/reference/interfaces/AlertAttachment.md +51 -0
  111. package/docs/reference/interfaces/AlertClose.md +31 -0
  112. package/docs/reference/interfaces/AlertUtilsAttachmentOptions.md +42 -0
  113. package/docs/reference/interfaces/AlertUtilsOptions.md +41 -0
  114. package/docs/reference/interfaces/InstanceOptions.md +35 -0
  115. package/docs/reference/interfaces/JWTPayload.md +143 -0
  116. package/docs/reference/interfaces/JWTUser.md +55 -0
  117. package/docs/reference/interfaces/JWTUtilsConfig.md +45 -0
  118. package/docs/reference/interfaces/JWTUtilsPayloadKeyOptions.md +68 -0
  119. package/docs/reference/interfaces/JWTUtilsPayloadOptions.md +40 -0
  120. package/docs/reference/interfaces/JWTUtilsPayloadPasswordOptions.md +78 -0
  121. package/docs/reference/interfaces/NewEvent.md +25 -0
  122. package/docs/reference/interfaces/OriginSettings.md +25 -0
  123. package/docs/reference/interfaces/SlackConfig.md +33 -0
  124. package/docs/reference/interfaces/SmtpAuth.md +25 -0
  125. package/docs/reference/interfaces/SmtpConfig.md +41 -0
  126. package/docs/reference/interfaces/Template.md +81 -0
  127. package/docs/reference/interfaces/TemplateMapBase.md +13 -0
  128. package/docs/reference/interfaces/TwilioConfig.md +33 -0
  129. package/docs/reference/interfaces/WorkerMessage.md +31 -0
  130. package/docs/reference/interfaces/WorkerOptions.md +61 -0
  131. package/docs/reference/type-aliases/BooleanFunc.md +23 -0
  132. package/docs/reference/type-aliases/TemplateMap.md +17 -0
  133. package/docs/reference/type-aliases/WorkerCallback.md +31 -0
  134. package/docs/reference/variables/Logger.md +21 -0
  135. package/package.json +96 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The *ClassLoader* provides a container for dynamically loading classes at runtime using C#/Java style namespaces.
3
+ * Namespaces are determined from the folder structure relative to the root.
4
+ *
5
+ * Class names are derived either directly from the modules export name or inferred from the module's file path when
6
+ * the `default` export is used.
7
+ *
8
+ * For example, given the following example TypeScript module at relative path `com/company/MyClass.ts` would register
9
+ * a class with fully qualified name `com.company.MyClass`.
10
+ *
11
+ * ```javascript
12
+ * export default class MyClass {
13
+ * // ...
14
+ * }
15
+ * ```
16
+ *
17
+ * In the event that multiple exports are defined, the fully qualified name will take on the export name instead of the
18
+ * module name. Thus, the following example module at relative path `com/company/MyClasses.ts` would register the following
19
+ * classes.
20
+ * - `com.company.MyClass`
21
+ * - `com.company.MyEnum`
22
+ *
23
+ * ```javascript
24
+ * export class MyClass {
25
+ * // ...
26
+ * }
27
+ *
28
+ * export enum MyEnum {
29
+ * // ...
30
+ * }
31
+ * ```
32
+ *
33
+ * **IMPORTANT**: If you use *ClassLoader* to dynamically load TypeScript files (.ts, .cts, .mts, etc.) at runtime using
34
+ * an ESM-only project you must use the `ts-node/esm` module loader. This can be specified by passing the `--loader` to
35
+ * node at runtime.
36
+ *
37
+ * ```
38
+ * node --loader ts-node/esm <module>
39
+ * ```
40
+ *
41
+ * @author Jean-Philippe Steinmetz
42
+ */
43
+ export declare class ClassLoader {
44
+ /** The map containnig all loaded classes. */
45
+ protected classes: Map<string, any>;
46
+ protected ignore: (string | RegExp)[];
47
+ /** Indicates if TypeScript classes should be loaded. */
48
+ protected includeTypeScript: boolean;
49
+ /** Indicates if JavaScript classes should be loaded. */
50
+ protected includeJavaScript: boolean;
51
+ /** The path to the root directory containing all classes on disk. */
52
+ protected rootDir: string;
53
+ /**
54
+ * Creates a new instance of `ClassLoader` with the specified defaults.
55
+ *
56
+ * @param rootDir The root directory to load all classes from.
57
+ * @param includeJavaScript Set to `true` to load all TypeScript classes from the given `rootDir`, otherwise set to `false.
58
+ * @param includeTypeScript Set to `true` to load all JavaScript classes from the given `rootDir`, otherwise set to `false.
59
+ * @param ignore A list of regex pattern of file paths to ignore.
60
+ */
61
+ constructor(rootDir: string, includeJavaScript?: boolean, includeTypeScript?: boolean, ignore?: (string | RegExp)[]);
62
+ /**
63
+ * Returns the class with the specified fully qualified name.
64
+ *
65
+ * @param fqn The fully qualified name of the class to return.
66
+ * @returns The class definition for the given fully qualified name if found, otherwise `undefined`.
67
+ */
68
+ getClass(fqn: string): any | undefined;
69
+ /**
70
+ * Returns the map containing all classes that have been loaded.
71
+ */
72
+ getClasses(): Map<string, any>;
73
+ /**
74
+ * Returns `true` if a class exists with the specified fully qualified name.
75
+ *
76
+ * @param fqn The fully qualified name of the class to search.
77
+ * @returns `true` if a class definition exists for the given fully qualified name, otherwise `false`.
78
+ */
79
+ hasClass(fqn: string): any | undefined;
80
+ /**
81
+ * Loads all modules exports contained in the directory specified. The folder must be a child
82
+ * directory to the `rootDir` parameter passed in to the constructor.
83
+ *
84
+ * @param dir The directory, relative to `rootDir`, containing modules to load.
85
+ */
86
+ load(dir?: string): Promise<void>;
87
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Utility functions for working with files.
3
+ * @author Jean-Philippe Steinmetz
4
+ */
5
+ export declare class FileUtils {
6
+ /**
7
+ * Attempts to write the provided contents to the file path given. If a file already exists the user is prompted to
8
+ * allow the file to be overwritten or merged. In the case of a merge, srcPath is used as a baseline in order to
9
+ * perform a 3-way merge.
10
+ *
11
+ * @param {string} srcPath The baseline template file to use during a merge.
12
+ * @param {string} outPath The destination file path to be written.
13
+ * @param {any} contents The contents of the file to write.
14
+ * @param {boolean} overwrite Set to `true` to overwite the file and not perform a merge.
15
+ */
16
+ static writeFile(srcPath: string, outPath: string, contents: any, overwrite?: boolean): Promise<void>;
17
+ /**
18
+ * Generates a copy of the source file at the desired output destination and performs a swap of all values of the
19
+ * variables specified.
20
+ *
21
+ * @param {string} srcPath The source file to copy.
22
+ * @param {string} outPath The destination file to generate.
23
+ * @param {any} variables The map of variable names to values to swap.
24
+ */
25
+ static copyFile(srcPath: string, outPath: string, variables?: any, overwrite?: boolean): Promise<void>;
26
+ /**
27
+ * Generates a copy of the source file at the desired output destination using binary copy mode.
28
+ *
29
+ * @param {string} srcPath The source file to copy.
30
+ * @param {string} outPath The destination file to generate.
31
+ * @param {Map<string,string>} variables The map of variable names to values to swap. Applies to outPath only.
32
+ */
33
+ static copyBinaryFile(srcPath: string, outPath: string, variables?: any): Promise<void>;
34
+ /**
35
+ * Performs a deep copy of a directory tree at the given srcPath to the specified output directory. Performs
36
+ * template replacement for all variables given and skips any files in the specified filter.
37
+ *
38
+ * @param {string} srcPath The path to the source directory to copy files from.
39
+ * @param {string} outPath The path to the destination directory to copy files to.
40
+ * @param {any} vars The map of template variables to perform replacement on.
41
+ * @param {array} excludeFilters The list of file extension filters to exclude during the copy process.
42
+ * @param {array} binaryFilters The list of file extension filters to copy as binary only.
43
+ * @param {boolean} force Set to `true` to force writing over any existing files.
44
+ */
45
+ static copyDirectory(srcPath: string, outPath: string, vars?: any, excludeFilters?: Array<string>, binaryFilters?: Array<string>, force?: boolean): Promise<void>;
46
+ }
@@ -0,0 +1,139 @@
1
+ import jwt from "jsonwebtoken";
2
+ /**
3
+ * Describes user data that is encoded in the payload of a JWT token.
4
+ *
5
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
6
+ */
7
+ export interface JWTUser {
8
+ /**
9
+ * The universally unique identifier of the user.
10
+ */
11
+ uid: string;
12
+ /**
13
+ * The unique name of the user.
14
+ */
15
+ name: string;
16
+ /**
17
+ * The list of roles (by name) that the user is apart of and will assume privileges for.
18
+ */
19
+ roles: string[];
20
+ /**
21
+ * Indicates if the user's e-mail address has been verified.
22
+ */
23
+ verified?: boolean;
24
+ }
25
+ /**
26
+ * Describes the payload data structure of signed JWT tokens.
27
+ */
28
+ export interface JWTPayload extends jwt.JwtPayload {
29
+ /** Indicates if the payload profile has been compressed and with what method. */
30
+ compression?: "zlib";
31
+ /** Indicates if the payload profile has been encrypted. */
32
+ encryption?: boolean;
33
+ /** The user profile of the authenticated user the token is valid for. */
34
+ profile: JWTUser | string;
35
+ /** The unique identifier of the user's authentication session. */
36
+ sessionUid: string;
37
+ }
38
+ /**
39
+ * Describes the different types of support compression methods for JWT payloads.
40
+ */
41
+ export declare enum JWTUtilsCompressionMethods {
42
+ /** Uses the zlib compression method. */
43
+ ZLIB = "zlib"
44
+ }
45
+ /**
46
+ * Describes the configuration options to be used with the `JWTUtilsConfig.payload` property.
47
+ *
48
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
49
+ */
50
+ export interface JWTUtilsPayloadOptions {
51
+ /**
52
+ * Set the method to use for compressing the payload profile, otherwise set to `null` for no compression.
53
+ */
54
+ compress?: JWTUtilsCompressionMethods;
55
+ /**
56
+ * Set to `true` to indicate that the JWT token payload is encrypted, otherwise set to `false`.
57
+ */
58
+ encrypt?: boolean;
59
+ }
60
+ /**
61
+ * Describes the configuration options to be used with the `JWTUtilsConfig.payload` property when performing password
62
+ * based encryption.
63
+ *
64
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
65
+ */
66
+ export interface JWTUtilsPayloadPasswordOptions extends JWTUtilsPayloadOptions {
67
+ /**
68
+ * The cryptographic cipher algorithm to use during encryption/decryption of a JWT token payload.
69
+ */
70
+ algorithm: string;
71
+ /**
72
+ * The initialization vector to use during encryption and decryption.
73
+ */
74
+ iv: Buffer;
75
+ /**
76
+ * The password to use when encrypting or decrypting JWT token payloads.
77
+ */
78
+ password: string;
79
+ }
80
+ /**
81
+ * Describes the configuration options to be used with the `JWTUtilsConfig.payload` property when performing
82
+ * key-based encryption.
83
+ *
84
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
85
+ */
86
+ export interface JWTUtilsPayloadKeyOptions extends JWTUtilsPayloadOptions {
87
+ /**
88
+ * The private key used to encrypt JWT token payloads.
89
+ */
90
+ private_key: string;
91
+ /**
92
+ * The public key used to decrypt JWT token payloads.
93
+ */
94
+ public_key: string;
95
+ }
96
+ /**
97
+ * Describes the configuration options to be used with `JWTUtils` functions.
98
+ *
99
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
100
+ */
101
+ export interface JWTUtilsConfig {
102
+ /**
103
+ * The secret to use for signing and verifying JWT tokens.
104
+ */
105
+ secret: jwt.Secret;
106
+ /**
107
+ * The options to use when performing JWT signing or verification.
108
+ */
109
+ options?: jwt.VerifyOptions;
110
+ /**
111
+ * The options that determine how JWT token payloads will be handled.
112
+ */
113
+ payload?: JWTUtilsPayloadOptions | JWTUtilsPayloadKeyOptions | JWTUtilsPayloadPasswordOptions;
114
+ }
115
+ /**
116
+ * Utility class for working with Json Web Token (JWT) authentication tokens.
117
+ *
118
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
119
+ */
120
+ export declare class JWTUtils {
121
+ /**
122
+ * Generates a new JWT token for the given config and user object. The user object must be a valid RapidREST
123
+ * user.
124
+ *
125
+ * @param config The JWT configuration to use when generating the token.
126
+ * @param user The user to encode into the token's payload.
127
+ * @param data Additional data to include the token's payload.
128
+ */
129
+ static createToken(config: JWTUtilsConfig, user: JWTUser, data?: any): string;
130
+ /**
131
+ * Decodes the given JWT authentication token using the provided configuration. If the token is not valid an
132
+ * error is thrown with the reason. Returns the encoded user object payload upon success.
133
+ *
134
+ * @param config The JWT configuration to use when validating the token.
135
+ * @param token The JWT token to validate.
136
+ * @returns The data encoded in the token's payload.
137
+ */
138
+ static decodeToken(config: JWTUtilsConfig, token: string): JWTPayload;
139
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a new logger with the specified level and file name to output logs to.
3
+ *
4
+ * @param level The logging level to create the logger with.
5
+ * @param file The name (without an extension) of the file to output logs to.
6
+ */
7
+ export declare const Logger: any;
@@ -0,0 +1,77 @@
1
+ export interface OriginSettings {
2
+ email: string;
3
+ sms: string;
4
+ }
5
+ export interface TemplateMapBase {
6
+ [name: string]: Template;
7
+ }
8
+ export type TemplateMap = Omit<TemplateMapBase, "from"> & {
9
+ from: OriginSettings;
10
+ };
11
+ export interface Template {
12
+ enabled: boolean;
13
+ email_options?: any;
14
+ subject?: string;
15
+ html?: string;
16
+ slack_channel?: string;
17
+ slack_text?: string;
18
+ sms?: string;
19
+ sms_options?: any;
20
+ text?: string;
21
+ }
22
+ export interface SlackConfig {
23
+ name: string;
24
+ token: string;
25
+ signingSecret: string;
26
+ }
27
+ export interface SmtpAuth {
28
+ user: string;
29
+ pass: string;
30
+ }
31
+ export interface SmtpConfig {
32
+ host: string;
33
+ port: number;
34
+ secure: boolean;
35
+ auth?: SmtpAuth;
36
+ }
37
+ export interface TwilioConfig {
38
+ accountSid: string;
39
+ token: string;
40
+ options?: any;
41
+ }
42
+ /**
43
+ * Simple utility class for sending templated messages via e-mail, SMS and more.
44
+ */
45
+ export declare class MessagingUtils {
46
+ protected slackApps: any[];
47
+ protected slackConfigs: any[];
48
+ private smtpConfig?;
49
+ private twilio?;
50
+ private twilioConfig;
51
+ private templates;
52
+ private logger?;
53
+ init(): Promise<void>;
54
+ /**
55
+ * Sends an email using the given template name and variables.
56
+ * @param templateName The name of the email template to send.
57
+ * @param templateVars The map of variables to inject into the template.
58
+ * @param options The map of additional options to pass into the sendMail function.
59
+ * @returns
60
+ */
61
+ sendEmail(templateName: string, templateVars: any, options?: any): Promise<any>;
62
+ /**
63
+ * Sends an Slack message using the given template name and variables.
64
+ * @param templateName The name of the Slack template to send.
65
+ * @param templateVars The map of variables to inject into the template.
66
+ * @returns
67
+ */
68
+ sendSlack(templateName: string, templateVars: any): Promise<any[] | undefined>;
69
+ /**
70
+ * Sends an SMS using the given template name and variables.
71
+ * @param templateName The name of the SMS template to send.
72
+ * @param templateVars The map of variables to inject into the template.
73
+ * @param options The map of additional options to pass into the sendMail function.
74
+ * @returns
75
+ */
76
+ sendSMS(templateName: string, templateVars: any, options?: any): Promise<any>;
77
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Utility functions for sending push notifications to registered clients.
3
+ *
4
+ * @author Jean-Philippe Steinmetz
5
+ */
6
+ export declare class NotificationUtils {
7
+ /** The redis client to use for broadcasting messages. */
8
+ private redis;
9
+ /**
10
+ * Initializes the utility using the given redis connection.
11
+ *
12
+ * @param {any} redis The redis connection to publish to.
13
+ */
14
+ constructor(redis: any);
15
+ /**
16
+ * Broadcasts a given message to all users.
17
+ *
18
+ * @param {any} type The type of message being sent.
19
+ * @param {string} action The action performed on the data (if applicable).
20
+ * @param {string} data The contents of the message to send.
21
+ */
22
+ broadcastMessage(type: any, action: string, data: any): void;
23
+ /**
24
+ * Sends a given message to the room or user with the specified uid(s).
25
+ *
26
+ * @param {string} uids The universally unique identifier of the room or user to send the message to.
27
+ * @param {string} type The type of message being sent.
28
+ * @param {string} action The action performed on the data (if applicable).
29
+ * @param {string} data The contents of the message to send to the room or user.
30
+ */
31
+ sendMessage(uids: string | string[], type: string, action: string, data: any): void;
32
+ }
@@ -0,0 +1,54 @@
1
+ export declare class OASUtils {
2
+ /**
3
+ * Gets the datastore definition with the specified name.
4
+ *
5
+ * @param spec The OpenAPI specification to search.
6
+ * @param name The name of the datastore to retrieve.
7
+ * @returns The definition for the datastore with the given name if found, otherwise `undefined`.
8
+ */
9
+ static getDatastore(spec: any, name: string): any;
10
+ /**
11
+ * Gets the specification object at the specified path.
12
+ *
13
+ * @param {any} spec The OpenAPI specification to reference.
14
+ * @param {string} path The path of the object to retrieve.
15
+ * @returns {any} The object at the specified path if found, otherwise `undefined`.
16
+ */
17
+ static getObject(spec: any, path: string): any;
18
+ /**
19
+ * Returns the first available response object for a 2XX response as defined by the provided Operation schema object.
20
+ *
21
+ * @param {any} obj The Operation schema object to search.
22
+ */
23
+ static getResponse(obj: any): any;
24
+ /**
25
+ * Returns the first available response content object for a 2XX response as defined by the provided Operation schema object.
26
+ *
27
+ * @param {any} obj The Operation schema object to search.
28
+ */
29
+ static getResponseContent(obj: any): any;
30
+ /**
31
+ * Retrieves the schema definition with the given name.
32
+ *
33
+ * @param {any} spec The OpenAPI specification object to reference.
34
+ * @param {string} name The name of the schema to retrieve.
35
+ * @returns {any} The schema definition with the given name.
36
+ */
37
+ static getSchema(spec: any, name: string): any;
38
+ /**
39
+ * Extracts the type information for a given schema Object definition.
40
+ *
41
+ * @param {any} schemaDef The schema definition object to extract type information from.
42
+ * @param {any} spec The entire OpenAPI specification object.
43
+ * @param {Function} convertDataType The function that converts OpenAPI Specification types to native types.
44
+ * @returns {any} A tuple containing the type, subType and subSchemaRef information.
45
+ */
46
+ static getTypeInfo(schemaDef: any, spec: any, convertDataType: Function): any;
47
+ /**
48
+ * Attempts to load the Open API specification at the given path or URL.
49
+ *
50
+ * @param {string} file The path or URL of the OpenAPI Specification file to load.
51
+ * @returns {Promise<any>} A promise whose result will be the loaded OpenAPI Specification as an object.
52
+ */
53
+ static loadSpec(file: string): Promise<any>;
54
+ }
@@ -0,0 +1,77 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * The set of options to use when creating new instances of objects.
4
+ */
5
+ export interface InstanceOptions {
6
+ args?: any[];
7
+ name?: string;
8
+ initialize?: boolean;
9
+ }
10
+ /**
11
+ * The `ObjectFactory` is a manager for creating objects based on registered
12
+ * class types. This allows for the tracking of multiple instances of objects
13
+ * so that references can be referenced by unique name.
14
+ *
15
+ * @author Jean-Philippe Steinmetz
16
+ */
17
+ export declare class ObjectFactory {
18
+ /** A map for string fully qualified class names to their class types. */
19
+ readonly classes: Map<string, any>;
20
+ /** The global application configuration object. */
21
+ protected config: any;
22
+ /** A map for the unique name to the intance of a particular class type. */
23
+ readonly instances: Map<string, any>;
24
+ /** The application logging utility. */
25
+ protected logger: any;
26
+ constructor(config?: any, logger?: any);
27
+ /**
28
+ * Destroys the specified objects. If `undefined` is passed in, all objects managed by the factory are destroyed.
29
+ */
30
+ destroy(objs?: any | any[]): Promise<void>;
31
+ /**
32
+ * Deletes all instantiated objects.
33
+ */
34
+ clear(): void;
35
+ /**
36
+ * Deletes all instantiated objects and registered class types.
37
+ */
38
+ clearAll(): void;
39
+ /**
40
+ * Scans the given object for any properties with the `@Inject` decorator and assigns the correct values.
41
+ * @param obj The object to initialize with injected defaults
42
+ */
43
+ initialize<T>(obj: any): Promise<T>;
44
+ /**
45
+ * Searches an object for one or more functions that implement a `@Init` decorator.
46
+ *
47
+ * @param obj The object to search.
48
+ * @returns The list of functions that implements the `@Init` decorator if found, otherwise undefined.
49
+ */
50
+ getInitMethods(obj: any): Function[];
51
+ /**
52
+ * Returns the object instance with the given unique name. Unique names take the form `<ClassName>:<InstanceName>`.
53
+ * It is possible to only specifiy the `<ClassName>`, doing so will automatically look for the `<ClassName>:default`
54
+ * instance or the first found instance of the given type.
55
+ * @param nameOrType The unique name or class type of the object to retrieve.
56
+ * @returns The object instance associated with the given name if found, otherwise `undefined`.
57
+ */
58
+ getInstance<T>(nameOrType: any): T | undefined;
59
+ /**
60
+ * Creates a new instance of the class specified with the provided unique name or type and constructor arguments. If an existing
61
+ * object has already been created with the given name, that instance is returned, otherwise a new instance is created
62
+ * using the provided arguments.
63
+ *
64
+ * @param type The fully qualified name or type of the class to instantiate. If a type is given it's class name will be inferred
65
+ * via the constructor name.
66
+ * @param name The unique name to give the class instance. Set to `undefined` if you wish to force a new object is created.
67
+ * @param initialize Set to `true` to initialize the object after creation, otherwise set to `false`. Default is `true`.
68
+ * @param args The set of constructor arguments to use during construction
69
+ */
70
+ newInstance<T>(type: any, options?: InstanceOptions): T | Promise<T>;
71
+ /**
72
+ * Registers the given class type for the provided fully qualified name.
73
+ * @param clazz The class type to register.
74
+ * @param fqn The fully qualified name of the class to register. If not specified, the class name will be used.
75
+ */
76
+ register(clazz: any, fqn?: string): void;
77
+ }
@@ -0,0 +1,17 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Utility class for working with objects.
4
+ *
5
+ * @author Jean-Philippe Steinmetz
6
+ */
7
+ export declare class ObjectUtils {
8
+ /**
9
+ * Performs validation of the given object or array. Validation is performed by scanning the object class for properties
10
+ * decorated with `@Validator` and executing the provided validation function.
11
+ *
12
+ * @param obj The object or array of objects to validate.
13
+ * @param clazz The class type that contains the validation metadata.
14
+ * @param recurse Set to `true` to validate all child objects.
15
+ */
16
+ static validate(obj: any, clazz?: any, recurse?: boolean): void;
17
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Utility functions for working with strings.
3
+ *
4
+ * @author Jean-Philippe Steinmetz
5
+ */
6
+ export declare class StringUtils {
7
+ /**
8
+ * Returns a list of all parameters contained within the string. A parameter is a bracket delimited substring
9
+ * (e.g. /my/{key}/with/{id}).
10
+ *
11
+ * @param {any} str The string to search for parameters.
12
+ * @returns {array} A list of parameters contained in the provided string.
13
+ */
14
+ static getParameters(str: string): Array<string>;
15
+ /**
16
+ * Performs a search and replace on the provided contents with the map of variable replacements. The contents
17
+ * must use Mustache formatted tokens such as `{{toreplace}}`.
18
+ *
19
+ * @param {string} contents The stringt to perform the find and replace on.
20
+ * @param {object} variables A map of key=>value pairs to search for and replace.
21
+ */
22
+ static findAndReplace(contents: string, variables: any): string;
23
+ /**
24
+ * Replaces all instances of the match regex pattern with the contents of the inner regular expression pattern for
25
+ * the given string.
26
+ *
27
+ * e.g.
28
+ *
29
+ * let result = replaceAll('/my/path/{id}', new RegExp('\\{([^\\}]+)\\}'), ':');
30
+ * console.log(result); // -> /my/path/:id
31
+ *
32
+ * @param {string} str The string to perform replacement on.
33
+ * @param {RegExp} match The regular expression pattern to match containing an outer and inner pattern.
34
+ * @param {string} prefix The prefix to prepend the replacement text with.
35
+ * @returns {string} The fully replaced contents of the string.
36
+ */
37
+ static replaceAll(str: string, match: string | RegExp, prefix: string): string;
38
+ /**
39
+ * Converts the first character in the given string to be lowercase (e.g. myVariable).
40
+ *
41
+ * @param {string} str The string to convert to camelCase.
42
+ * @returns {string} The string converted to camelCase.
43
+ */
44
+ static toCamelCase(str: string): string;
45
+ /**
46
+ * Converts the first character in the given string to be uppercase (e.g. MyVariable).
47
+ *
48
+ * @param {string} str The string to convert to PascalCase.
49
+ * @returns {string} The string converted to PascalCase.
50
+ */
51
+ static toPascalCase(str: string): string;
52
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Describes the required fields when creating a new telemetry event.
3
+ *
4
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
5
+ */
6
+ export interface NewEvent {
7
+ /** The type of event begin recorded. */
8
+ type: string;
9
+ }
10
+ /**
11
+ * Describes a single telemetry event. A telemetry event is when something occurs in the system.
12
+ *
13
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
14
+ */
15
+ export declare class Event implements NewEvent {
16
+ /**
17
+ * The universally unique identifier of the event.
18
+ */
19
+ readonly uid: string;
20
+ /**
21
+ * The name of the environment that the event originated from. This is typically `dev` or `prod`.
22
+ */
23
+ readonly environment: string;
24
+ /**
25
+ * The unique name of the service or client that the event originated from.
26
+ */
27
+ readonly origin: string;
28
+ /**
29
+ * The date and time that the event occured.
30
+ */
31
+ readonly timestamp: Date;
32
+ /**
33
+ * The type of event being recorded.
34
+ */
35
+ readonly type: string;
36
+ /**
37
+ * The universally unique identifer of the user that sent the event.
38
+ */
39
+ readonly userId: string;
40
+ constructor(config: any, userId: string, data: NewEvent);
41
+ }
42
+ /**
43
+ * Provides a common set of static functions for recording and working with telemetry `Event` instances.
44
+ *
45
+ * The `init` function must be called before any other function can be called.
46
+ *
47
+ * The `record` function is used to send an event to a configured `telemetry_services` service for permanent storage.
48
+ *
49
+ * The `on` function allows code within the same application or service to listen for outgoing events that have been
50
+ * sent via the `record` function.
51
+ *
52
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
53
+ */
54
+ export declare class EventUtils {
55
+ private static initialized;
56
+ private static config;
57
+ private static listeners;
58
+ private static logger;
59
+ private static token;
60
+ private static userId;
61
+ /**
62
+ * Initializes `EventUtils` with the provided defaults.
63
+ *
64
+ * @param config The application configuration to use.
65
+ * @param logger The logging utility to use.
66
+ * @param jwtToken The user's JWT token to send telemetry events on behalf of.
67
+ */
68
+ static init(config: any, logger: any, jwtToken: string): void;
69
+ /**
70
+ * Sends the given event to the telemetry service for permanent recording.
71
+ *
72
+ * @param evt The event to send and record.
73
+ * @param type The type of event to record. Overrides any `type` value set in `evt`.
74
+ */
75
+ static record(evt: NewEvent | any, type?: string): Promise<void>;
76
+ /**
77
+ * Registers a `callback` function to receive notifications of recorded events of the given `type`. Note that only
78
+ * events originating from the same application or service will be notified.
79
+ *
80
+ * @param type The type of event to be notified of.
81
+ * @param callback The function to call when an event is recorded.
82
+ */
83
+ static on(type: string, callback: Function): void;
84
+ }