@ikonintegration/ikapi 4.0.0-alpha9 → 5.0.0-alpha1

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 (234) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +81 -0
  3. package/.github/workflows/npmpublish.yml +8 -19
  4. package/.github/workflows/prs.yml +12 -0
  5. package/dist/index.d.ts +16 -0
  6. package/dist/index.js +27 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/package-lock.json +11886 -0
  9. package/dist/package.json +81 -0
  10. package/dist/src/API/Request.d.ts +125 -0
  11. package/dist/src/API/Request.js +185 -0
  12. package/dist/src/API/Request.js.map +1 -0
  13. package/dist/src/API/Response.d.ts +188 -0
  14. package/dist/src/API/Response.js +270 -0
  15. package/dist/src/API/Response.js.map +1 -0
  16. package/dist/src/BaseEvent/DynamoTransaction.d.ts +20 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.js +81 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  19. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  20. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  21. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  22. package/dist/src/BaseEvent/Process.d.ts +50 -0
  23. package/dist/src/BaseEvent/Process.js +64 -0
  24. package/dist/src/BaseEvent/Process.js.map +1 -0
  25. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  26. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  27. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  28. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  29. package/dist/src/BaseEvent/Transaction.js +224 -0
  30. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  31. package/dist/src/Cache/Redis.d.ts +29 -0
  32. package/dist/src/Cache/Redis.js +80 -0
  33. package/dist/src/Cache/Redis.js.map +1 -0
  34. package/dist/src/Cache/types.d.ts +31 -0
  35. package/dist/src/Cache/types.js +2 -0
  36. package/dist/src/Cache/types.js.map +1 -0
  37. package/dist/src/Config/Configuration.d.ts +123 -0
  38. package/dist/src/Config/Configuration.js +109 -0
  39. package/dist/src/Config/Configuration.js.map +1 -0
  40. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  41. package/dist/src/Config/EnvironmentVar.js +138 -0
  42. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  43. package/dist/src/Crypto/Crypto.d.ts +45 -0
  44. package/dist/src/Crypto/Crypto.js +72 -0
  45. package/dist/src/Crypto/Crypto.js.map +1 -0
  46. package/dist/src/Database/Database.d.ts +21 -0
  47. package/dist/src/Database/Database.js +15 -0
  48. package/dist/src/Database/Database.js.map +1 -0
  49. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  50. package/dist/src/Database/DatabaseManager.js +60 -0
  51. package/dist/src/Database/DatabaseManager.js.map +1 -0
  52. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  53. package/dist/src/Database/DatabaseTransaction.js +126 -0
  54. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  55. package/dist/src/Database/index.d.ts +10 -0
  56. package/dist/src/Database/index.js +15 -0
  57. package/dist/src/Database/index.js.map +1 -0
  58. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  61. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  64. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  67. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  73. package/dist/src/Database/types.d.ts +76 -0
  74. package/dist/src/Database/types.js +2 -0
  75. package/dist/src/Database/types.js.map +1 -0
  76. package/dist/src/Globals.d.ts +93 -0
  77. package/dist/src/Globals.js +99 -0
  78. package/dist/src/Globals.js.map +1 -0
  79. package/dist/src/Logger/Logger.d.ts +161 -0
  80. package/dist/src/Logger/Logger.js +297 -0
  81. package/dist/src/Logger/Logger.js.map +1 -0
  82. package/dist/src/Mailer/Mailer.d.ts +78 -0
  83. package/dist/src/Mailer/Mailer.js +182 -0
  84. package/dist/src/Mailer/Mailer.js.map +1 -0
  85. package/dist/src/Publisher/Publisher.d.ts +39 -0
  86. package/dist/src/Publisher/Publisher.js +77 -0
  87. package/dist/src/Publisher/Publisher.js.map +1 -0
  88. package/dist/src/Server/RouteResolver.d.ts +33 -0
  89. package/dist/src/Server/RouteResolver.js +100 -0
  90. package/dist/src/Server/RouteResolver.js.map +1 -0
  91. package/dist/src/Server/Router.d.ts +157 -0
  92. package/dist/src/Server/Router.js +32 -0
  93. package/dist/src/Server/Router.js.map +1 -0
  94. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  95. package/dist/src/Server/lib/ContainerServer.js +66 -0
  96. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  97. package/dist/src/Server/lib/Server.d.ts +45 -0
  98. package/dist/src/Server/lib/Server.js +93 -0
  99. package/dist/src/Server/lib/Server.js.map +1 -0
  100. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  101. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  103. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  106. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  107. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  109. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  110. package/dist/src/Server/lib/container/Proxy.js +143 -0
  111. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  112. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  113. package/dist/src/Server/lib/container/Utils.js +37 -0
  114. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  115. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  116. package/dist/src/Util/AsyncSingleton.js +83 -0
  117. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  118. package/dist/src/Util/Utils.d.ts +61 -0
  119. package/dist/src/Util/Utils.js +147 -0
  120. package/dist/src/Util/Utils.js.map +1 -0
  121. package/dist/src/Validation/Validator.d.ts +17 -0
  122. package/dist/src/Validation/Validator.js +39 -0
  123. package/dist/src/Validation/Validator.js.map +1 -0
  124. package/index.ts +41 -0
  125. package/jest.config.ts +37 -0
  126. package/jest.smoke.config.ts +34 -0
  127. package/package.json +66 -22
  128. package/src/API/Request.ts +214 -0
  129. package/src/API/Response.ts +370 -0
  130. package/src/BaseEvent/DynamoTransaction.ts +125 -0
  131. package/src/BaseEvent/EventProcessor.ts +140 -0
  132. package/src/BaseEvent/Process.ts +78 -0
  133. package/src/BaseEvent/StepTransaction.ts +35 -0
  134. package/src/BaseEvent/Transaction.ts +323 -0
  135. package/src/Cache/Redis.ts +89 -0
  136. package/src/Cache/types.ts +33 -0
  137. package/src/Config/Configuration.ts +199 -0
  138. package/src/Config/EnvironmentVar.ts +147 -0
  139. package/src/Crypto/Crypto.ts +89 -0
  140. package/src/Database/Database.ts +22 -0
  141. package/src/Database/DatabaseManager.ts +67 -0
  142. package/src/Database/DatabaseTransaction.ts +170 -0
  143. package/src/Database/index.ts +27 -0
  144. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  145. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  146. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  147. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  148. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  149. package/src/Database/types.ts +85 -0
  150. package/src/Globals.ts +103 -0
  151. package/src/Logger/Logger.ts +360 -0
  152. package/src/Mailer/Mailer.ts +217 -0
  153. package/src/Publisher/Publisher.ts +96 -0
  154. package/src/Server/RouteResolver.ts +124 -0
  155. package/src/Server/Router.ts +200 -0
  156. package/src/Server/lib/ContainerServer.ts +65 -0
  157. package/src/Server/lib/Server.ts +109 -0
  158. package/src/Server/lib/container/GenericHandler.ts +76 -0
  159. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  160. package/src/Server/lib/container/HealthHandler.ts +11 -0
  161. package/src/Server/lib/container/Proxy.ts +172 -0
  162. package/src/Server/lib/container/Utils.ts +33 -0
  163. package/src/Util/AsyncSingleton.ts +86 -0
  164. package/src/Util/Utils.ts +131 -0
  165. package/src/Validation/Validator.ts +45 -0
  166. package/tests/API/Request.test.ts +273 -0
  167. package/tests/API/Response.test.ts +367 -0
  168. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  169. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  170. package/tests/BaseEvent/Process.test.ts +47 -0
  171. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  172. package/tests/BaseEvent/Transaction.test.ts +402 -0
  173. package/tests/Cache/Redis-client.test.ts +90 -0
  174. package/tests/Cache/Redis-cluster.test.ts +100 -0
  175. package/tests/Config/Config.test.ts +205 -0
  176. package/tests/Config/EnvironmentVar.test.ts +251 -0
  177. package/tests/Crypto/Crypto.test.ts +88 -0
  178. package/tests/Database/DatabaseManager.test.ts +79 -0
  179. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  180. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  181. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  182. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  183. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  184. package/tests/Logger/Logger.test.ts +215 -0
  185. package/tests/Mailer/Mailer.test.ts +59 -0
  186. package/tests/Publisher/Publisher.test.ts +60 -0
  187. package/tests/Server/RouteResolver.test.ts +116 -0
  188. package/tests/Server/Router.test.ts +39 -0
  189. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  190. package/tests/Server/lib/Server.test.ts +12 -0
  191. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  192. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  193. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  194. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  195. package/tests/Server/lib/container/Utils.test.ts +47 -0
  196. package/tests/Test.utils.ts +78 -0
  197. package/tests/Utils/Utils.test.ts +230 -0
  198. package/tests/Validation/Validator.test.ts +82 -0
  199. package/tsconfig.json +26 -0
  200. package/tsconfig.smoke.json +26 -0
  201. package/index.js +0 -88
  202. package/src/API/IKRequest.js +0 -52
  203. package/src/API/IKResponse.js +0 -119
  204. package/src/API/IKUtils.js +0 -51
  205. package/src/BaseEvent/IKProcess.js +0 -77
  206. package/src/BaseEvent/IKTransaction.js +0 -139
  207. package/src/Cache/Prototype/IKCache.js +0 -17
  208. package/src/Cache/Redis/IKRedis.js +0 -148
  209. package/src/Database/DDB/IKDB.js +0 -56
  210. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  211. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  212. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  213. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  214. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  215. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  216. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  217. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  218. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  219. package/src/Database/DDB/IKDBQueryUpdate.js +0 -219
  220. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  221. package/src/Database/PSQL/IKDB.js +0 -41
  222. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  223. package/src/Database/Prototype/IKDB.js +0 -21
  224. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  225. package/src/IKDynamoStream.js +0 -42
  226. package/src/IKEventProcessor.js +0 -42
  227. package/src/IKGlobals.js +0 -24
  228. package/src/IKRouter.js +0 -47
  229. package/src/IKStepTransaction.js +0 -14
  230. package/src/Logger/IKLogger.js +0 -136
  231. package/src/Mailer/IKMailer.js +0 -68
  232. package/src/Publisher/IKPublisher.js +0 -44
  233. package/src/Tracker/IKExecutionTracker.js +0 -79
  234. package/src/Validation/IKValidation.js +0 -77
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/Cache/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Represents the schema for the configuration object.
3
+ * @typedef {Object} ConfigurationSchema
4
+ * @property {Object} [name] - The name of the configuration property.
5
+ * @property {boolean} [name.isLocal] - Indicates if the property is for local use.
6
+ * @property {boolean} [name.isRemote] - Indicates if the property is for remote use.
7
+ * @property {boolean} [name.required] - Indicates if the property is required.
8
+ * @property {string} [name.cachingPolicy] - The caching policy for the property.
9
+ * @property {string} [name.nameOverride] - The optional name override if the key differs
10
+ */
11
+ export type ConfigurationSchema = {
12
+ [name: string]: {
13
+ isLocal?: boolean;
14
+ isRemote?: boolean;
15
+ isSecure?: boolean;
16
+ required?: boolean;
17
+ noPrefix?: boolean;
18
+ cachingPolicy?: string;
19
+ nameOverride?: string;
20
+ };
21
+ };
22
+ /**
23
+ * Extracts the properties from a given type that have the `isRemote` property set to `true`.
24
+ * @param {Type} - The type to extract properties from.
25
+ * @returns An object type with the extracted properties.
26
+ */
27
+ type ExtractRemote<Type> = {
28
+ [Property in keyof Type]-?: Type[Property] extends {
29
+ isRemote: true;
30
+ } ? Property : null;
31
+ };
32
+ /**
33
+ * Extracts the properties from a given type that have the `isLocal` property set to `true`.
34
+ * @typeparam Type - The type to extract properties from.
35
+ * @returns An object type with the extracted properties as keys and their corresponding types.
36
+ */
37
+ type ExtractLocal<Type> = {
38
+ [Property in keyof Type]-?: Type[Property] extends {
39
+ isLocal: true;
40
+ } ? Property : null;
41
+ };
42
+ /**
43
+ * Creates a new type by omitting keys from type T whose values are of type U.
44
+ * @param {T} - The original type
45
+ * @param {U} - The type to omit from T
46
+ * @returns A new type with the omitted keys
47
+ */
48
+ type OmitKeysByValueType<T, U> = {
49
+ [P in keyof T]: T[P] extends U ? never : P;
50
+ }[keyof T];
51
+ /**
52
+ * Omit properties from an object type by their value type.
53
+ * @template T - The object type to omit properties from.
54
+ * @template V - The value type of properties to omit.
55
+ * @typedef OmitByValueType
56
+ * @property {T} T - The object type to omit properties from.
57
+ * @property {V} V - The value type of properties to omit.
58
+ * @returns {OmitKeysByValueType<T, V>} - The resulting object type after omitting properties.
59
+ */
60
+ type OmitByValueType<T, V> = T extends infer _ ? {
61
+ [key in OmitKeysByValueType<T, V>]: T[key];
62
+ } : never;
63
+ /**
64
+ * Represents a configuration object with a specified schema and remote prefix.
65
+ * @template T - The type of the configuration schema.
66
+ */
67
+ export default class Configuration<T extends ConfigurationSchema> {
68
+ /**
69
+ * The schema for the private readonly property.
70
+ * @type {T}
71
+ */
72
+ private readonly schema;
73
+ /**
74
+ * The prefix used for remote resources.
75
+ * @type {string}
76
+ */
77
+ private readonly remotePrefix;
78
+ /**
79
+ * Indicates if config is local and should attempt to override
80
+ * remote values from local.
81
+ * @type {string}
82
+ */
83
+ private static readonly isLocal;
84
+ /**
85
+ * Constructs a new instance of the class.
86
+ * @param {T} schema - The schema object.
87
+ * @param {string} remotePrefix - The remote prefix string.
88
+ * @returns None
89
+ */
90
+ constructor(schema: T, remotePrefix: string);
91
+ /**
92
+ * Retrieves the value of a property from the environment variables or cache.
93
+ * @param {keyof OmitByValueType<ExtractLocal<T>, null>} propName - The name of the property to retrieve.
94
+ * @returns The value of the property.
95
+ */
96
+ get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any;
97
+ /**
98
+ * Asynchronously retrieves the value of a property from the remote environment.
99
+ * @param {keyof OmitByValueType<ExtractRemote<T>, null>} propName - The name of the property to retrieve.
100
+ * @returns {Promise<any>} - A promise that resolves to the value of the property.
101
+ */
102
+ asyncGet(propName: keyof OmitByValueType<ExtractRemote<T>, null>): Promise<any>;
103
+ /**
104
+ * Retrieves the cached value associated with the given key from the cache store.
105
+ * @param {string} valueKey - The key of the value to retrieve from the cache.
106
+ * @returns The cached value associated with the given key, or undefined if the key does not exist in the cache.
107
+ */
108
+ private getCachedValue;
109
+ /**
110
+ * Caches a value with the specified key and expiration policy.
111
+ * @param {string} valueKey - The key to associate with the cached value.
112
+ * @param {any} value - The value to be cached.
113
+ * @param {string} [policy='1d'] - The expiration policy for the cached value. Defaults to '1d' (1 day).
114
+ * @returns None
115
+ */
116
+ private cacheValue;
117
+ /**
118
+ * Resets the cache by creating a new instance of the MemCache class and assigning it to the cacheStore variable.
119
+ * @returns None
120
+ */
121
+ private resetCache;
122
+ }
123
+ export {};
@@ -0,0 +1,109 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import MemCache from 'node-cache';
11
+ import DurationParser from 'parse-duration';
12
+ import EnvironmentVar, { EnvironmentType } from './EnvironmentVar.js';
13
+ // Hold cached values at nodeVM level
14
+ // eslint-disable-next-line no-var
15
+ /**
16
+ * Creates a new instance of a memory cache store.
17
+ * @returns {MemCache} A new instance of a memory cache store.
18
+ */
19
+ let cacheStore = new MemCache();
20
+ /**
21
+ * Represents a configuration object with a specified schema and remote prefix.
22
+ * @template T - The type of the configuration schema.
23
+ */
24
+ class Configuration {
25
+ /**
26
+ * Constructs a new instance of the class.
27
+ * @param {T} schema - The schema object.
28
+ * @param {string} remotePrefix - The remote prefix string.
29
+ * @returns None
30
+ */
31
+ constructor(schema, remotePrefix) {
32
+ this.schema = schema;
33
+ this.remotePrefix = remotePrefix;
34
+ }
35
+ /**
36
+ * Retrieves the value of a property from the environment variables or cache.
37
+ * @param {keyof OmitByValueType<ExtractLocal<T>, null>} propName - The name of the property to retrieve.
38
+ * @returns The value of the property.
39
+ */
40
+ get(propName) {
41
+ const propString = propName;
42
+ const propSchema = this.schema[propString];
43
+ let v = this.getCachedValue(propString);
44
+ v =
45
+ v ||
46
+ new EnvironmentVar(propSchema.nameOverride || propString, EnvironmentType.Local, !propSchema.required, !propSchema.noPrefix ? this.remotePrefix : '').syncResolve();
47
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
48
+ return v;
49
+ }
50
+ /**
51
+ * Asynchronously retrieves the value of a property from the remote environment.
52
+ * @param {keyof OmitByValueType<ExtractRemote<T>, null>} propName - The name of the property to retrieve.
53
+ * @returns {Promise<any>} - A promise that resolves to the value of the property.
54
+ */
55
+ asyncGet(propName) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const propString = propName;
58
+ const propSchema = this.schema[propString];
59
+ // check cache
60
+ let v = this.getCachedValue(propString);
61
+ if (v !== undefined)
62
+ return v;
63
+ // check for local override
64
+ if (Configuration.isLocal && process.env[propString] !== undefined) {
65
+ console.log(`Overriding remote variable ${propString} with local value!`);
66
+ const v = process.env[propString];
67
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
68
+ return v;
69
+ }
70
+ // remote
71
+ v = yield new EnvironmentVar(propSchema.nameOverride || propString, propSchema.isSecure ? EnvironmentType.SecureRemote : EnvironmentType.PlainRemote, !propSchema.required, !propSchema.noPrefix ? this.remotePrefix : '').resolve();
72
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
73
+ return v;
74
+ });
75
+ }
76
+ /**
77
+ * Retrieves the cached value associated with the given key from the cache store.
78
+ * @param {string} valueKey - The key of the value to retrieve from the cache.
79
+ * @returns The cached value associated with the given key, or undefined if the key does not exist in the cache.
80
+ */
81
+ getCachedValue(valueKey) {
82
+ return cacheStore.get(valueKey);
83
+ }
84
+ /**
85
+ * Caches a value with the specified key and expiration policy.
86
+ * @param {string} valueKey - The key to associate with the cached value.
87
+ * @param {any} value - The value to be cached.
88
+ * @param {string} [policy='1d'] - The expiration policy for the cached value. Defaults to '1d' (1 day).
89
+ * @returns None
90
+ */
91
+ cacheValue(valueKey, value, policy = '1d') {
92
+ cacheStore.set(valueKey, value, DurationParser(policy, 's') || '');
93
+ }
94
+ /**
95
+ * Resets the cache by creating a new instance of the MemCache class and assigning it to the cacheStore variable.
96
+ * @returns None
97
+ */
98
+ resetCache() {
99
+ cacheStore = new MemCache();
100
+ }
101
+ }
102
+ /**
103
+ * Indicates if config is local and should attempt to override
104
+ * remote values from local.
105
+ * @type {string}
106
+ */
107
+ Configuration.isLocal = process.env.NODE_ENV == 'local';
108
+ export default Configuration;
109
+ //# sourceMappingURL=Configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../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K,UAAU;QAChB,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;IAC7B,CAAC;;AA9FD;;;;GAIG;AACqB,qBAAO,GAAY,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAA;eAhBvD,aAAa"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * An enumeration representing different types of environments.
3
+ * @enum {number}
4
+ * @readonly
5
+ * @property {number} PlainRemote - Represents a plain remote environment.
6
+ * @property {number} SecureRemote - Represents a secure remote environment.
7
+ * @property {number} Local - Represents a local environment.
8
+ */
9
+ export declare enum EnvironmentType {
10
+ PlainRemote = 0,
11
+ SecureRemote = 1,
12
+ Local = 2
13
+ }
14
+ /**
15
+ * Represents an environment variable with methods to resolve its value based on the environment type.
16
+ * @template T - The type of the environment variable value.
17
+ */
18
+ export default class EnvironmentVar<T> {
19
+ /**
20
+ * The name of the parameter.
21
+ */
22
+ private readonly paramName;
23
+ /**
24
+ * The type of environment.
25
+ * @readonly
26
+ */
27
+ private readonly type;
28
+ /**
29
+ * A boolean flag indicating whether the field is optional or not.
30
+ */
31
+ private readonly optional;
32
+ /**
33
+ * The prefix used for parameters in the class.
34
+ * @type {string}
35
+ */
36
+ private readonly paramPrefix;
37
+ /**
38
+ * Constructs a new instance of the EnvironmentVar class.
39
+ * @param {string} paramName - The name of the environment variable.
40
+ * @param {EnvironmentType} type - The type of the environment.
41
+ * @param {boolean} [optional] - Indicates whether the environment variable is optional.
42
+ * @param {string} [paramPrefix] - The prefix to be added to the environment variable name.
43
+ */
44
+ constructor(paramName: string, type: EnvironmentType, optional: boolean | undefined, paramPrefix: string);
45
+ /**
46
+ * Resolves the value of the environment variable synchronously.
47
+ * @returns {T} - The resolved value of the environment variable.
48
+ * @throws {Error} - If the environment type is not 'Local'.
49
+ */
50
+ syncResolve(): T;
51
+ /**
52
+ * Resolves the value based on the environment type.
53
+ * @returns {Promise<any>} - The resolved value.
54
+ */
55
+ resolve(): Promise<T | undefined>;
56
+ /**
57
+ * Retrieves the value of a local environment variable.
58
+ * @returns {T} - The value of the local environment variable.
59
+ * @throws {Error} - If the local environment variable is not defined and is not optional.
60
+ */
61
+ private getLocalValue;
62
+ /**
63
+ * Retrieves the plain value of a remote environment parameter.
64
+ * @returns {Promise<T>} - A promise that resolves to the plain value of the parameter.
65
+ * @throws {Error} - If the parameter cannot be retrieved and is not optional.
66
+ */
67
+ private getPlainValue;
68
+ /**
69
+ * Retrieves a secure value from the secrets manager.
70
+ * @returns {Promise<T>} - A promise that resolves to the secure value.
71
+ * @throws {Error} - Throws an error if the secure value cannot be retrieved and is not optional.
72
+ */
73
+ private getSecureValue;
74
+ }
@@ -0,0 +1,138 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
11
+ import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm';
12
+ // Explicity setting VM level variables in order to persist
13
+ // client across different important and instances.
14
+ // eslint-disable-next-line no-var
15
+ /**
16
+ * Variables to hold instances of SSMClient and SecretsManagerClient, initialized as null.
17
+ * @type {SSMClient | null} ssmClient - Instance of SSMClient or null if not initialized.
18
+ * @type {SecretsManagerClient | null} secretsClient - Instance of SecretsManagerClient or null if not initialized.
19
+ */
20
+ let ssmClient = null, secretsClient = null;
21
+ /**
22
+ * An enumeration representing different types of environments.
23
+ * @enum {number}
24
+ * @readonly
25
+ * @property {number} PlainRemote - Represents a plain remote environment.
26
+ * @property {number} SecureRemote - Represents a secure remote environment.
27
+ * @property {number} Local - Represents a local environment.
28
+ */
29
+ export var EnvironmentType;
30
+ (function (EnvironmentType) {
31
+ EnvironmentType[EnvironmentType["PlainRemote"] = 0] = "PlainRemote";
32
+ EnvironmentType[EnvironmentType["SecureRemote"] = 1] = "SecureRemote";
33
+ EnvironmentType[EnvironmentType["Local"] = 2] = "Local";
34
+ })(EnvironmentType || (EnvironmentType = {}));
35
+ /**
36
+ * Represents an environment variable with methods to resolve its value based on the environment type.
37
+ * @template T - The type of the environment variable value.
38
+ */
39
+ export default class EnvironmentVar {
40
+ /**
41
+ * Constructs a new instance of the EnvironmentVar class.
42
+ * @param {string} paramName - The name of the environment variable.
43
+ * @param {EnvironmentType} type - The type of the environment.
44
+ * @param {boolean} [optional] - Indicates whether the environment variable is optional.
45
+ * @param {string} [paramPrefix] - The prefix to be added to the environment variable name.
46
+ */
47
+ constructor(paramName, type, optional = true, paramPrefix) {
48
+ this.paramName = paramName;
49
+ this.type = type;
50
+ this.optional = !!optional;
51
+ this.paramPrefix = paramPrefix;
52
+ }
53
+ /**
54
+ * Resolves the value of the environment variable synchronously.
55
+ * @returns {T} - The resolved value of the environment variable.
56
+ * @throws {Error} - If the environment type is not 'Local'.
57
+ */
58
+ syncResolve() {
59
+ if (this.type == EnvironmentType.Local)
60
+ return this.getLocalValue();
61
+ else {
62
+ throw new Error("EnvironmentVar syncResolve method can only be called for environments of type 'Local'");
63
+ }
64
+ }
65
+ /**
66
+ * Resolves the value based on the environment type.
67
+ * @returns {Promise<any>} - The resolved value.
68
+ */
69
+ resolve() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ if (this.type == EnvironmentType.Local)
72
+ return this.getLocalValue();
73
+ else if (this.type == EnvironmentType.SecureRemote)
74
+ return this.getSecureValue();
75
+ else
76
+ return this.getPlainValue();
77
+ });
78
+ }
79
+ /**
80
+ * Retrieves the value of a local environment variable.
81
+ * @returns {T} - The value of the local environment variable.
82
+ * @throws {Error} - If the local environment variable is not defined and is not optional.
83
+ */
84
+ getLocalValue() {
85
+ const value = process.env[this.paramName];
86
+ if (!value && !this.optional) {
87
+ throw new Error(`Local environment ${this.paramName} is not defined, please reconfigure the application and redeploy!`);
88
+ }
89
+ return value;
90
+ }
91
+ /**
92
+ * Retrieves the plain value of a remote environment parameter.
93
+ * @returns {Promise<T>} - A promise that resolves to the plain value of the parameter.
94
+ * @throws {Error} - If the parameter cannot be retrieved and is not optional.
95
+ */
96
+ getPlainValue() {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ if (!ssmClient)
99
+ ssmClient = new SSMClient();
100
+ const pName = `${this.paramPrefix}${this.paramName}`;
101
+ try {
102
+ const data = yield ssmClient.send(new GetParameterCommand({ Name: pName }));
103
+ if (data.Parameter && data.Parameter.Value)
104
+ return data.Parameter.Value;
105
+ }
106
+ catch (error) {
107
+ console.error(error);
108
+ }
109
+ if (!this.optional) {
110
+ throw new Error(`Unable to retrieve plain remote env value: ${pName}`);
111
+ }
112
+ });
113
+ }
114
+ /**
115
+ * Retrieves a secure value from the secrets manager.
116
+ * @returns {Promise<T>} - A promise that resolves to the secure value.
117
+ * @throws {Error} - Throws an error if the secure value cannot be retrieved and is not optional.
118
+ */
119
+ getSecureValue() {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ if (!secretsClient)
122
+ secretsClient = new SecretsManagerClient();
123
+ const pName = `${this.paramPrefix}${this.paramName}`;
124
+ try {
125
+ const data = yield secretsClient.send(new GetSecretValueCommand({ SecretId: pName }));
126
+ if (data.SecretString)
127
+ return data.SecretString;
128
+ }
129
+ catch (error) {
130
+ console.error(error);
131
+ }
132
+ if (!this.optional) {
133
+ throw new Error(`Unable to retrieve secure remote env: ${pName}`);
134
+ }
135
+ });
136
+ }
137
+ }
138
+ //# sourceMappingURL=EnvironmentVar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentVar.js","sourceRoot":"","sources":["../../../src/Config/EnvironmentVar.ts"],"names":[],"mappings":";;;;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Aa,CAAC,IAAI,CAAC,IAAI,qBAAqB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;gBACrF,IAAI,IAAI,CAAC,YAAY;oBAAE,OAAO,IAAI,CAAC,YAAiB,CAAA;YACtD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACtB,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,yCAAyC,KAAK,EAAE,CAAC,CAAA;YACnE,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,45 @@
1
+ import { EncryptionAlgorithmSpec } from '@aws-sdk/client-kms';
2
+ /**
3
+ * Represents a Crypto class that provides encryption and decryption functionality using AWS KMS.
4
+ */
5
+ export default class Crypto {
6
+ /**
7
+ * The KMSClient instance used for making requests to the Key Management Service (KMS).
8
+ */
9
+ private readonly client;
10
+ /**
11
+ * The AWS region of the object. This property is readonly and cannot be modified once set.
12
+ */
13
+ private readonly region;
14
+ /**
15
+ * The unique identifier for the KMS.
16
+ * @readonly
17
+ * @type {string}
18
+ */
19
+ private readonly keyId;
20
+ /**
21
+ * Specifies the encryption algorithm used for encryption.
22
+ */
23
+ private readonly encryptionAlgorithm;
24
+ /**
25
+ * Constructs a new instance of a KeyManager with the provided region, keyId, and optional encryption algorithm.
26
+ * @param {string} region - The region where the key is stored.
27
+ * @param {string} keyId - The ID of the key.
28
+ * @param {EncryptionAlgorithmSpec} [optEncryptionAlgorithm='RSAES_OAEP_SHA_256'] - The encryption algorithm to use (default is RSAES_OAEP_SHA_256).
29
+ * @returns None
30
+ */
31
+ constructor(region: string, keyId: string, optEncryptionAlgorithm?: EncryptionAlgorithmSpec);
32
+ /**
33
+ * Encrypts the given data using RSAES_OAEP_SHA_256 encryption algorithm.
34
+ * @param {string | any} data - The data to be encrypted.
35
+ * @returns {Promise<string | null>} - A promise that resolves to the encrypted data as a hexadecimal string.
36
+ */
37
+ encryptData(data: string | any): Promise<string | null>;
38
+ /**
39
+ * Decrypts the given data using the RSAES_OAEP_SHA_256 encryption algorithm.
40
+ * @param {string} data - The encrypted data to decrypt.
41
+ * @returns {Promise<string | null>} - A promise that resolves to the decrypted plaintext string.
42
+ * If decryption fails, null is returned.
43
+ */
44
+ decryptData(data: string): Promise<string | null>;
45
+ }
@@ -0,0 +1,72 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { KMSClient, EncryptCommand, DecryptCommand, } from '@aws-sdk/client-kms';
11
+ /**
12
+ * Represents a Crypto class that provides encryption and decryption functionality using AWS KMS.
13
+ */
14
+ export default class Crypto {
15
+ /**
16
+ * Constructs a new instance of a KeyManager with the provided region, keyId, and optional encryption algorithm.
17
+ * @param {string} region - The region where the key is stored.
18
+ * @param {string} keyId - The ID of the key.
19
+ * @param {EncryptionAlgorithmSpec} [optEncryptionAlgorithm='RSAES_OAEP_SHA_256'] - The encryption algorithm to use (default is RSAES_OAEP_SHA_256).
20
+ * @returns None
21
+ */
22
+ constructor(region, keyId, optEncryptionAlgorithm) {
23
+ this.region = region;
24
+ this.keyId = keyId;
25
+ this.encryptionAlgorithm = optEncryptionAlgorithm || 'RSAES_OAEP_SHA_256';
26
+ this.client = new KMSClient({ region: this.region });
27
+ }
28
+ /**
29
+ * Encrypts the given data using RSAES_OAEP_SHA_256 encryption algorithm.
30
+ * @param {string | any} data - The data to be encrypted.
31
+ * @returns {Promise<string | null>} - A promise that resolves to the encrypted data as a hexadecimal string.
32
+ */
33
+ encryptData(data) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ const resp = yield this.client.send(new EncryptCommand({
37
+ KeyId: this.keyId,
38
+ EncryptionAlgorithm: this.encryptionAlgorithm,
39
+ Plaintext: new TextEncoder().encode(typeof data === 'string' ? data : JSON.stringify(data)),
40
+ }));
41
+ return Buffer.from(resp.CiphertextBlob, 'utf8').toString('hex');
42
+ }
43
+ catch (e) {
44
+ console.error('Encryption failure', e);
45
+ return null;
46
+ }
47
+ });
48
+ }
49
+ /**
50
+ * Decrypts the given data using the RSAES_OAEP_SHA_256 encryption algorithm.
51
+ * @param {string} data - The encrypted data to decrypt.
52
+ * @returns {Promise<string | null>} - A promise that resolves to the decrypted plaintext string.
53
+ * If decryption fails, null is returned.
54
+ */
55
+ decryptData(data) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ const resp = yield this.client.send(new DecryptCommand({
59
+ KeyId: this.keyId,
60
+ CiphertextBlob: Buffer.from(data, 'hex'),
61
+ EncryptionAlgorithm: this.encryptionAlgorithm,
62
+ }));
63
+ return new TextDecoder().decode(resp.Plaintext);
64
+ }
65
+ catch (e) {
66
+ console.error('Decryption failure', e);
67
+ return null;
68
+ }
69
+ });
70
+ }
71
+ }
72
+ //# sourceMappingURL=Crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,GAEf,MAAM,qBAAqB,CAAA;AAE5B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAoBzB;;;;;;OAMG;IACH,YAAY,MAAc,EAAE,KAAa,EAAE,sBAAgD;QACzF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAA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AAC,SAAS,CAAC,CAAA;YACjD,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAA;gBACtC,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,21 @@
1
+ import { DatabaseTransaction } from './DatabaseTransaction.js';
2
+ import { DbConfig } from './types.js';
3
+ /**
4
+ * Abstract class representing a Database with a generic type extending DatabaseTransaction.
5
+ * @template T - The type of DatabaseTransaction to be used.
6
+ */
7
+ export declare abstract class Database<T extends DatabaseTransaction> {
8
+ readonly config: DbConfig<any>;
9
+ /**
10
+ * Constructor for a class that takes in a database configuration object.
11
+ * @param {DbConfig<any>} config - The database configuration object.
12
+ * @returns None
13
+ */
14
+ protected constructor(config: DbConfig<any>);
15
+ /**
16
+ * Represents an abstract method for a transaction that returns a Promise of type T.
17
+ * This method needs to be implemented by subclasses.
18
+ * @returns A Promise that resolves to a value of type T.
19
+ */
20
+ abstract transaction(): Promise<T>;
21
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Abstract class representing a Database with a generic type extending DatabaseTransaction.
3
+ * @template T - The type of DatabaseTransaction to be used.
4
+ */
5
+ export class Database {
6
+ /**
7
+ * Constructor for a class that takes in a database configuration object.
8
+ * @param {DbConfig<any>} config - The database configuration object.
9
+ * @returns None
10
+ */
11
+ constructor(config) {
12
+ this.config = config;
13
+ }
14
+ }
15
+ //# sourceMappingURL=Database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Database.js","sourceRoot":"","sources":["../../../src/Database/Database.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IAC5B;;;;OAIG;IACH,YAAsC,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;CAQhE"}