@etohq/framework 1.0.0

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/README.md +0 -0
  2. package/dist/build-tools/compiler.d.ts +49 -0
  3. package/dist/build-tools/compiler.d.ts.map +1 -0
  4. package/dist/build-tools/compiler.js +291 -0
  5. package/dist/build-tools/compiler.js.map +1 -0
  6. package/dist/build-tools/index.d.ts +2 -0
  7. package/dist/build-tools/index.d.ts.map +1 -0
  8. package/dist/build-tools/index.js +18 -0
  9. package/dist/build-tools/index.js.map +1 -0
  10. package/dist/config/config.d.ts +34 -0
  11. package/dist/config/config.d.ts.map +1 -0
  12. package/dist/config/config.js +132 -0
  13. package/dist/config/config.js.map +1 -0
  14. package/dist/config/index.d.ts +5 -0
  15. package/dist/config/index.d.ts.map +1 -0
  16. package/dist/config/index.js +21 -0
  17. package/dist/config/index.js.map +1 -0
  18. package/dist/config/loader.d.ts +11 -0
  19. package/dist/config/loader.d.ts.map +1 -0
  20. package/dist/config/loader.js +35 -0
  21. package/dist/config/loader.js.map +1 -0
  22. package/dist/config/types.d.ts +901 -0
  23. package/dist/config/types.d.ts.map +1 -0
  24. package/dist/config/types.js +3 -0
  25. package/dist/config/types.js.map +1 -0
  26. package/dist/container.d.ts +3 -0
  27. package/dist/container.d.ts.map +1 -0
  28. package/dist/container.js +21 -0
  29. package/dist/container.js.map +1 -0
  30. package/dist/database/index.d.ts +3 -0
  31. package/dist/database/index.d.ts.map +1 -0
  32. package/dist/database/index.js +19 -0
  33. package/dist/database/index.js.map +1 -0
  34. package/dist/database/pg-connection-loader.d.ts +6 -0
  35. package/dist/database/pg-connection-loader.d.ts.map +1 -0
  36. package/dist/database/pg-connection-loader.js +37 -0
  37. package/dist/database/pg-connection-loader.js.map +1 -0
  38. package/dist/eto-app-loader.d.ts +51 -0
  39. package/dist/eto-app-loader.d.ts.map +1 -0
  40. package/dist/eto-app-loader.js +183 -0
  41. package/dist/eto-app-loader.js.map +1 -0
  42. package/dist/feature-flags/feature-flag-loader.d.ts +8 -0
  43. package/dist/feature-flags/feature-flag-loader.d.ts.map +1 -0
  44. package/dist/feature-flags/feature-flag-loader.js +81 -0
  45. package/dist/feature-flags/feature-flag-loader.js.map +1 -0
  46. package/dist/feature-flags/flag-router.d.ts +32 -0
  47. package/dist/feature-flags/flag-router.d.ts.map +1 -0
  48. package/dist/feature-flags/flag-router.js +67 -0
  49. package/dist/feature-flags/flag-router.js.map +1 -0
  50. package/dist/feature-flags/index.d.ts +5 -0
  51. package/dist/feature-flags/index.d.ts.map +1 -0
  52. package/dist/feature-flags/index.js +21 -0
  53. package/dist/feature-flags/index.js.map +1 -0
  54. package/dist/feature-flags/types.d.ts +31 -0
  55. package/dist/feature-flags/types.d.ts.map +1 -0
  56. package/dist/feature-flags/types.js +3 -0
  57. package/dist/feature-flags/types.js.map +1 -0
  58. package/dist/http/express-loader.d.ts +8 -0
  59. package/dist/http/express-loader.d.ts.map +1 -0
  60. package/dist/http/express-loader.js +85 -0
  61. package/dist/http/express-loader.js.map +1 -0
  62. package/dist/http/index.d.ts +15 -0
  63. package/dist/http/index.d.ts.map +1 -0
  64. package/dist/http/index.js +31 -0
  65. package/dist/http/index.js.map +1 -0
  66. package/dist/http/middlewares/apply-default-filters.d.ts +3 -0
  67. package/dist/http/middlewares/apply-default-filters.d.ts.map +1 -0
  68. package/dist/http/middlewares/apply-default-filters.js +32 -0
  69. package/dist/http/middlewares/apply-default-filters.js.map +1 -0
  70. package/dist/http/middlewares/apply-params-as-filters.d.ts +5 -0
  71. package/dist/http/middlewares/apply-params-as-filters.d.ts.map +1 -0
  72. package/dist/http/middlewares/apply-params-as-filters.js +14 -0
  73. package/dist/http/middlewares/apply-params-as-filters.js.map +1 -0
  74. package/dist/http/middlewares/authenticate-middleware.d.ts +11 -0
  75. package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -0
  76. package/dist/http/middlewares/authenticate-middleware.js +135 -0
  77. package/dist/http/middlewares/authenticate-middleware.js.map +1 -0
  78. package/dist/http/middlewares/clear-filters-by-key.d.ts +3 -0
  79. package/dist/http/middlewares/clear-filters-by-key.d.ts.map +1 -0
  80. package/dist/http/middlewares/clear-filters-by-key.js +12 -0
  81. package/dist/http/middlewares/clear-filters-by-key.js.map +1 -0
  82. package/dist/http/middlewares/ensure-publishable-api-key.d.ts +3 -0
  83. package/dist/http/middlewares/ensure-publishable-api-key.d.ts.map +1 -0
  84. package/dist/http/middlewares/ensure-publishable-api-key.js +49 -0
  85. package/dist/http/middlewares/ensure-publishable-api-key.js.map +1 -0
  86. package/dist/http/middlewares/error-handler.d.ts +23 -0
  87. package/dist/http/middlewares/error-handler.d.ts.map +1 -0
  88. package/dist/http/middlewares/error-handler.js +85 -0
  89. package/dist/http/middlewares/error-handler.js.map +1 -0
  90. package/dist/http/middlewares/exception-formatter.d.ts +9 -0
  91. package/dist/http/middlewares/exception-formatter.d.ts.map +1 -0
  92. package/dist/http/middlewares/exception-formatter.js +36 -0
  93. package/dist/http/middlewares/exception-formatter.js.map +1 -0
  94. package/dist/http/middlewares/index.d.ts +8 -0
  95. package/dist/http/middlewares/index.d.ts.map +1 -0
  96. package/dist/http/middlewares/index.js +24 -0
  97. package/dist/http/middlewares/index.js.map +1 -0
  98. package/dist/http/middlewares/set-context.d.ts +3 -0
  99. package/dist/http/middlewares/set-context.d.ts.map +1 -0
  100. package/dist/http/middlewares/set-context.js +18 -0
  101. package/dist/http/middlewares/set-context.js.map +1 -0
  102. package/dist/http/router.d.ts +100 -0
  103. package/dist/http/router.d.ts.map +1 -0
  104. package/dist/http/router.js +764 -0
  105. package/dist/http/router.js.map +1 -0
  106. package/dist/http/types.d.ts +141 -0
  107. package/dist/http/types.d.ts.map +1 -0
  108. package/dist/http/types.js +16 -0
  109. package/dist/http/types.js.map +1 -0
  110. package/dist/http/utils/define-middlewares.d.ts +18 -0
  111. package/dist/http/utils/define-middlewares.d.ts.map +1 -0
  112. package/dist/http/utils/define-middlewares.js +40 -0
  113. package/dist/http/utils/define-middlewares.js.map +1 -0
  114. package/dist/http/utils/get-query-config.d.ts +42 -0
  115. package/dist/http/utils/get-query-config.d.ts.map +1 -0
  116. package/dist/http/utils/get-query-config.js +183 -0
  117. package/dist/http/utils/get-query-config.js.map +1 -0
  118. package/dist/http/utils/http-compression.d.ts +5 -0
  119. package/dist/http/utils/http-compression.d.ts.map +1 -0
  120. package/dist/http/utils/http-compression.js +33 -0
  121. package/dist/http/utils/http-compression.js.map +1 -0
  122. package/dist/http/utils/maybe-apply-link-filter.d.ts +8 -0
  123. package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -0
  124. package/dist/http/utils/maybe-apply-link-filter.js +71 -0
  125. package/dist/http/utils/maybe-apply-link-filter.js.map +1 -0
  126. package/dist/http/utils/refetch-entities.d.ts +5 -0
  127. package/dist/http/utils/refetch-entities.d.ts.map +1 -0
  128. package/dist/http/utils/refetch-entities.js +29 -0
  129. package/dist/http/utils/refetch-entities.js.map +1 -0
  130. package/dist/http/utils/restricted-fields.d.ts +6 -0
  131. package/dist/http/utils/restricted-fields.d.ts.map +1 -0
  132. package/dist/http/utils/restricted-fields.js +30 -0
  133. package/dist/http/utils/restricted-fields.js.map +1 -0
  134. package/dist/http/utils/unless-path.d.ts +9 -0
  135. package/dist/http/utils/unless-path.d.ts.map +1 -0
  136. package/dist/http/utils/unless-path.js +19 -0
  137. package/dist/http/utils/unless-path.js.map +1 -0
  138. package/dist/http/utils/validate-body.d.ts +5 -0
  139. package/dist/http/utils/validate-body.d.ts.map +1 -0
  140. package/dist/http/utils/validate-body.js +23 -0
  141. package/dist/http/utils/validate-body.js.map +1 -0
  142. package/dist/http/utils/validate-query.d.ts +6 -0
  143. package/dist/http/utils/validate-query.d.ts.map +1 -0
  144. package/dist/http/utils/validate-query.js +79 -0
  145. package/dist/http/utils/validate-query.js.map +1 -0
  146. package/dist/index.d.ts +16 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +34 -0
  149. package/dist/index.js.map +1 -0
  150. package/dist/jobs/index.d.ts +2 -0
  151. package/dist/jobs/index.d.ts.map +1 -0
  152. package/dist/jobs/index.js +18 -0
  153. package/dist/jobs/index.js.map +1 -0
  154. package/dist/jobs/job-loader.d.ts +37 -0
  155. package/dist/jobs/job-loader.d.ts.map +1 -0
  156. package/dist/jobs/job-loader.js +130 -0
  157. package/dist/jobs/job-loader.js.map +1 -0
  158. package/dist/links/index.d.ts +2 -0
  159. package/dist/links/index.d.ts.map +1 -0
  160. package/dist/links/index.js +18 -0
  161. package/dist/links/index.js.map +1 -0
  162. package/dist/links/link-loader.d.ts +10 -0
  163. package/dist/links/link-loader.d.ts.map +1 -0
  164. package/dist/links/link-loader.js +74 -0
  165. package/dist/links/link-loader.js.map +1 -0
  166. package/dist/logger/index.d.ts +3 -0
  167. package/dist/logger/index.d.ts.map +1 -0
  168. package/dist/logger/index.js +9 -0
  169. package/dist/logger/index.js.map +1 -0
  170. package/dist/mikro-orm-cli/bin.d.ts +14 -0
  171. package/dist/mikro-orm-cli/bin.d.ts.map +1 -0
  172. package/dist/mikro-orm-cli/bin.js +54 -0
  173. package/dist/mikro-orm-cli/bin.js.map +1 -0
  174. package/dist/modules-sdk/index.d.ts +2 -0
  175. package/dist/modules-sdk/index.d.ts.map +1 -0
  176. package/dist/modules-sdk/index.js +18 -0
  177. package/dist/modules-sdk/index.js.map +1 -0
  178. package/dist/orchestration/index.d.ts +2 -0
  179. package/dist/orchestration/index.d.ts.map +1 -0
  180. package/dist/orchestration/index.js +18 -0
  181. package/dist/orchestration/index.js.map +1 -0
  182. package/dist/subscribers/index.d.ts +3 -0
  183. package/dist/subscribers/index.d.ts.map +1 -0
  184. package/dist/subscribers/index.js +19 -0
  185. package/dist/subscribers/index.js.map +1 -0
  186. package/dist/subscribers/subscriber-loader.d.ts +11 -0
  187. package/dist/subscribers/subscriber-loader.d.ts.map +1 -0
  188. package/dist/subscribers/subscriber-loader.js +196 -0
  189. package/dist/subscribers/subscriber-loader.js.map +1 -0
  190. package/dist/subscribers/types.d.ts +15 -0
  191. package/dist/subscribers/types.d.ts.map +1 -0
  192. package/dist/subscribers/types.js +3 -0
  193. package/dist/subscribers/types.js.map +1 -0
  194. package/dist/telemetry/index.d.ts +50 -0
  195. package/dist/telemetry/index.d.ts.map +1 -0
  196. package/dist/telemetry/index.js +81 -0
  197. package/dist/telemetry/index.js.map +1 -0
  198. package/dist/types/container.d.ts +62 -0
  199. package/dist/types/container.d.ts.map +1 -0
  200. package/dist/types/container.js +3 -0
  201. package/dist/types/container.js.map +1 -0
  202. package/dist/types/index.d.ts +2 -0
  203. package/dist/types/index.d.ts.map +1 -0
  204. package/dist/types/index.js +18 -0
  205. package/dist/types/index.js.map +1 -0
  206. package/dist/utils/index.d.ts +3 -0
  207. package/dist/utils/index.d.ts.map +1 -0
  208. package/dist/utils/index.js +19 -0
  209. package/dist/utils/index.js.map +1 -0
  210. package/dist/workflows/index.d.ts +3 -0
  211. package/dist/workflows/index.d.ts.map +1 -0
  212. package/dist/workflows/index.js +19 -0
  213. package/dist/workflows/index.js.map +1 -0
  214. package/dist/workflows/workflow-loader.d.ts +10 -0
  215. package/dist/workflows/workflow-loader.d.ts.map +1 -0
  216. package/dist/workflows/workflow-loader.js +74 -0
  217. package/dist/workflows/workflow-loader.js.map +1 -0
  218. package/dist/workflows-sdk/composer.d.ts +2 -0
  219. package/dist/workflows-sdk/composer.d.ts.map +1 -0
  220. package/dist/workflows-sdk/composer.js +18 -0
  221. package/dist/workflows-sdk/composer.js.map +1 -0
  222. package/dist/workflows-sdk/index.d.ts +3 -0
  223. package/dist/workflows-sdk/index.d.ts.map +1 -0
  224. package/dist/workflows-sdk/index.js +19 -0
  225. package/dist/workflows-sdk/index.js.map +1 -0
  226. package/dist/zod/index.d.ts +2 -0
  227. package/dist/zod/index.d.ts.map +1 -0
  228. package/dist/zod/index.js +18 -0
  229. package/dist/zod/index.js.map +1 -0
  230. package/dist/zod/zod-helpers.d.ts +3 -0
  231. package/dist/zod/zod-helpers.d.ts.map +1 -0
  232. package/dist/zod/zod-helpers.js +95 -0
  233. package/dist/zod/zod-helpers.js.map +1 -0
  234. package/package.json +120 -0
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("../types/container");
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./feature-flag-loader"), exports);
20
+ __exportStar(require("./flag-router"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/feature-flags/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8BAA2B;AAE3B,0CAAuB;AACvB,wDAAqC;AACrC,gDAA6B"}
@@ -0,0 +1,31 @@
1
+ export interface IFlagRouter {
2
+ isFeatureEnabled: (key: string) => boolean;
3
+ listFlags: () => FeatureFlagsResponse;
4
+ }
5
+ /**
6
+ * @schema FeatureFlagsResponse
7
+ * type: array
8
+ * items:
9
+ * type: object
10
+ * required:
11
+ * - key
12
+ * - value
13
+ * properties:
14
+ * key:
15
+ * description: The key of the feature flag.
16
+ * type: string
17
+ * value:
18
+ * description: The value of the feature flag.
19
+ * type: boolean
20
+ */
21
+ export type FeatureFlagsResponse = {
22
+ key: string;
23
+ value: boolean | Record<string, boolean>;
24
+ }[];
25
+ export type FlagSettings = {
26
+ key: string;
27
+ description: string;
28
+ env_key: string;
29
+ default_val: boolean;
30
+ };
31
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/feature-flags/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IAC1C,SAAS,EAAE,MAAM,oBAAoB,CAAA;CACtC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACzC,EAAE,CAAA;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/feature-flags/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { Express } from "express";
2
+ export declare function expressLoader({ app }: {
3
+ app: Express;
4
+ }): Promise<{
5
+ app: Express;
6
+ shutdown: () => Promise<void>;
7
+ }>;
8
+ //# sourceMappingURL=express-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express-loader.d.ts","sourceRoot":"","sources":["../../src/http/express-loader.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAW1C,wBAAsB,aAAa,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC;IACtE,GAAG,EAAE,OAAO,CAAA;IACZ,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9B,CAAC,CAsFD"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.expressLoader = expressLoader;
7
+ const connect_redis_1 = __importDefault(require("connect-redis"));
8
+ const cookie_parser_1 = __importDefault(require("cookie-parser"));
9
+ const express_1 = __importDefault(require("express"));
10
+ const express_session_1 = __importDefault(require("express-session"));
11
+ const ioredis_1 = __importDefault(require("ioredis"));
12
+ const morgan_1 = __importDefault(require("morgan"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const logger_1 = require("../logger");
15
+ const config_1 = require("../config");
16
+ const NOISY_ENDPOINTS_CHUNKS = ["@fs", "@id", "@vite", "@react", "node_modules"];
17
+ async function expressLoader({ app }) {
18
+ const baseDir = config_1.configManager.baseDir;
19
+ const configModule = config_1.configManager.config;
20
+ const isProduction = config_1.configManager.isProduction;
21
+ const NODE_ENV = process.env.NODE_ENV || "development";
22
+ const IS_DEV = NODE_ENV.startsWith("dev");
23
+ const isStaging = NODE_ENV === "staging";
24
+ const isTest = NODE_ENV === "test";
25
+ let sameSite = false;
26
+ let secure = false;
27
+ if (isProduction || isStaging) {
28
+ secure = true;
29
+ sameSite = "none";
30
+ }
31
+ const { http, sessionOptions } = configModule.projectConfig;
32
+ const sessionOpts = {
33
+ name: sessionOptions?.name ?? "connect.sid",
34
+ resave: sessionOptions?.resave ?? true,
35
+ rolling: sessionOptions?.rolling ?? false,
36
+ saveUninitialized: sessionOptions?.saveUninitialized ?? true,
37
+ proxy: true,
38
+ secret: sessionOptions?.secret ?? http?.cookieSecret,
39
+ cookie: {
40
+ sameSite,
41
+ secure,
42
+ maxAge: sessionOptions?.ttl ?? 10 * 60 * 60 * 1000,
43
+ },
44
+ store: null,
45
+ };
46
+ let redisClient;
47
+ if (configModule?.projectConfig?.redisUrl) {
48
+ const RedisStore = (0, connect_redis_1.default)(express_session_1.default);
49
+ redisClient = new ioredis_1.default(configModule.projectConfig.redisUrl, configModule.projectConfig.redisOptions ?? {});
50
+ sessionOpts.store = new RedisStore({
51
+ client: redisClient,
52
+ prefix: `${configModule?.projectConfig?.redisPrefix ?? ""}sess:`,
53
+ });
54
+ }
55
+ app.set("trust proxy", 1);
56
+ /**
57
+ * Method to skip logging HTTP requests. We skip in test environment
58
+ * and also exclude files served by vite during development
59
+ */
60
+ function shouldSkipHttpLog(req, res) {
61
+ return (isTest || NOISY_ENDPOINTS_CHUNKS.some((chunk) => req.url.includes(chunk)));
62
+ }
63
+ /**
64
+ * The middleware to use for logging. We write the log messages
65
+ * using winston, but rely on morgan to hook into HTTP requests
66
+ */
67
+ const loggingMiddleware = (0, morgan_1.default)(IS_DEV
68
+ ? ":method :url ← :referrer (:status) - :response-time ms"
69
+ : "combined", {
70
+ skip: shouldSkipHttpLog,
71
+ stream: {
72
+ write: (message) => logger_1.logger.http(message.trim()),
73
+ },
74
+ });
75
+ app.use(loggingMiddleware);
76
+ app.use((0, cookie_parser_1.default)());
77
+ app.use((0, express_session_1.default)(sessionOpts));
78
+ // Currently we don't allow configuration of static files, but this can be revisited as needed.
79
+ app.use("/static", express_1.default.static(path_1.default.join(baseDir, "static")));
80
+ const shutdown = async () => {
81
+ redisClient?.disconnect();
82
+ };
83
+ return { app, shutdown };
84
+ }
85
+ //# sourceMappingURL=express-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express-loader.js","sourceRoot":"","sources":["../../src/http/express-loader.ts"],"names":[],"mappings":";;;;;AAaA,sCAyFC;AAtGD,kEAAuC;AACvC,kEAAwC;AACxC,sDAA0C;AAC1C,sEAAqC;AACrC,sDAA2B;AAC3B,oDAA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AAG,CAAC,GAAG,CAAC,IAAA,yBAAO,EAAC,WAAW,CAAC,CAAC,CAAA;IAE7B,+FAA+F;IAC/F,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,iBAAO,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAEhE,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,WAAW,EAAE,UAAU,EAAE,CAAA;IAC3B,CAAC,CAAA;IAED,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;AAC1B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import "../types/container";
2
+ export * from "./express-loader";
3
+ export * from "./router";
4
+ export * from "./types";
5
+ export * from "./middlewares";
6
+ export * from "./utils/http-compression";
7
+ export * from "./utils/validate-body";
8
+ export * from "./utils/validate-query";
9
+ export * from "./utils/get-query-config";
10
+ export * from "./utils/define-middlewares";
11
+ export * from "./utils/maybe-apply-link-filter";
12
+ export * from "./utils/refetch-entities";
13
+ export * from "./utils/unless-path";
14
+ export * from "./utils/restricted-fields";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAE3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("../types/container");
18
+ __exportStar(require("./express-loader"), exports);
19
+ __exportStar(require("./router"), exports);
20
+ __exportStar(require("./types"), exports);
21
+ __exportStar(require("./middlewares"), exports);
22
+ __exportStar(require("./utils/http-compression"), exports);
23
+ __exportStar(require("./utils/validate-body"), exports);
24
+ __exportStar(require("./utils/validate-query"), exports);
25
+ __exportStar(require("./utils/get-query-config"), exports);
26
+ __exportStar(require("./utils/define-middlewares"), exports);
27
+ __exportStar(require("./utils/maybe-apply-link-filter"), exports);
28
+ __exportStar(require("./utils/refetch-entities"), exports);
29
+ __exportStar(require("./utils/unless-path"), exports);
30
+ __exportStar(require("./utils/restricted-fields"), exports);
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8BAA2B;AAE3B,mDAAgC;AAChC,2CAAwB;AACxB,0CAAuB;AACvB,gDAA6B;AAC7B,2DAAwC;AACxC,wDAAqC;AACrC,yDAAsC;AACtC,2DAAwC;AACxC,6DAA0C;AAC1C,kEAA+C;AAC/C,2DAAwC;AACxC,sDAAmC;AACnC,4DAAyC"}
@@ -0,0 +1,3 @@
1
+ import { EtoNextFunction, EtoRequest } from "../types";
2
+ export declare function applyDefaultFilters<TFilter extends object>(filtersToApply: TFilter): (req: EtoRequest, _: any, next: EtoNextFunction) => Promise<void>;
3
+ //# sourceMappingURL=apply-default-filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-default-filters.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/apply-default-filters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEtD,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,cAAc,EAAE,OAAO,SAEJ,UAAU,gBAAW,eAAe,mBA2BxD"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyDefaultFilters = applyDefaultFilters;
4
+ const utils_1 = require("@etohq/utils");
5
+ function applyDefaultFilters(filtersToApply) {
6
+ return async (req, _, next) => {
7
+ for (const [filter, filterValue] of Object.entries(filtersToApply)) {
8
+ let valueToApply = filterValue;
9
+ // If certain manipulations need to be done on a middleware level, we can provide a simple
10
+ // function that mutates the data based on any custom requirement
11
+ if (typeof filterValue === "function") {
12
+ // pass the actual filterable fields so that the function can mutate the original object.
13
+ // Currently we only need it to delete filter keys from the request filter object, but this could
14
+ // be used for other purposes. If we can't find other purposes, we can refactor to accept an array
15
+ // of strings to delete after filters have been applied.
16
+ valueToApply = filterValue(req.filterableFields, req.queryConfig.fields);
17
+ }
18
+ // If the value to apply is an object, we add it to any existing filters thats already applied
19
+ if ((0, utils_1.isObject)(valueToApply)) {
20
+ req.filterableFields[filter] = {
21
+ ...(req.filterableFields[filter] || {}),
22
+ ...valueToApply,
23
+ };
24
+ }
25
+ else if ((0, utils_1.isPresent)(valueToApply)) {
26
+ req.filterableFields[filter] = valueToApply;
27
+ }
28
+ }
29
+ return next();
30
+ };
31
+ }
32
+ //# sourceMappingURL=apply-default-filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-default-filters.js","sourceRoot":"","sources":["../../../src/http/middlewares/apply-default-filters.ts"],"names":[],"mappings":";;AAGA,kDA8BC;AAjCD,wCAAkD;AAGlD,SAAgB,mBAAmB,CACjC,cAAuB;IAEvB,OAAO,KAAK,EAAE,GAAe,EAAE,CAAC,EAAE,IAAqB,EAAE,EAAE;QACzD,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACnE,IAAI,YAAY,GAAG,WAAW,CAAA;YAE9B,0FAA0F;YAC1F,iEAAiE;YACjE,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;gBACtC,yFAAyF;gBACzF,iGAAiG;gBACjG,kGAAkG;gBAClG,wDAAwD;gBACxD,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;YAC1E,CAAC;YAED,8FAA8F;YAC9F,IAAI,IAAA,gBAAQ,EAAC,YAAY,CAAC,EAAE,CAAC;gBAC3B,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG;oBAC7B,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;oBACvC,GAAG,YAAY;iBAChB,CAAA;YACH,CAAC;iBAAM,IAAI,IAAA,iBAAS,EAAC,YAAY,CAAC,EAAE,CAAC;gBACnC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,YAAY,CAAA;YAC7C,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { EtoNextFunction, EtoRequest } from "../types";
2
+ export declare function applyParamsAsFilters(mappings: {
3
+ [param: string]: string;
4
+ }): (req: EtoRequest, _: any, next: EtoNextFunction) => Promise<void>;
5
+ //# sourceMappingURL=apply-params-as-filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-params-as-filters.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/apply-params-as-filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEtD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,SACrD,UAAU,gBAAW,eAAe,mBASxD"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyParamsAsFilters = applyParamsAsFilters;
4
+ function applyParamsAsFilters(mappings) {
5
+ return async (req, _, next) => {
6
+ for (const [param, paramValue] of Object.entries(req.params)) {
7
+ if (mappings[param]) {
8
+ req.filterableFields[mappings[param]] = paramValue;
9
+ }
10
+ }
11
+ return next();
12
+ };
13
+ }
14
+ //# sourceMappingURL=apply-params-as-filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-params-as-filters.js","sourceRoot":"","sources":["../../../src/http/middlewares/apply-params-as-filters.ts"],"names":[],"mappings":";;AAEA,oDAUC;AAVD,SAAgB,oBAAoB,CAAC,QAAqC;IACxE,OAAO,KAAK,EAAE,GAAe,EAAE,CAAC,EAAE,IAAqB,EAAE,EAAE;QACzD,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7D,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,GAAG,CAAC,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAA;YACpD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { RequestHandler } from "express";
2
+ declare const SESSION_AUTH = "session";
3
+ declare const BEARER_AUTH = "bearer";
4
+ declare const API_KEY_AUTH = "api-key";
5
+ export type AuthType = typeof SESSION_AUTH | typeof BEARER_AUTH | typeof API_KEY_AUTH;
6
+ export declare const authenticate: (actorType: string | string[], authType: AuthType | AuthType[], options?: {
7
+ allowUnauthenticated?: boolean;
8
+ allowUnregistered?: boolean;
9
+ }) => RequestHandler;
10
+ export {};
11
+ //# sourceMappingURL=authenticate-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticate-middleware.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/authenticate-middleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,cAAc,EAAE,MAAM,SAAS,CAAA;AAUtD,QAAA,MAAM,YAAY,YAAY,CAAA;AAC9B,QAAA,MAAM,WAAW,WAAW,CAAA;AAC5B,QAAA,MAAM,YAAY,YAAY,CAAA;AAK9B,MAAM,MAAM,QAAQ,GAChB,OAAO,YAAY,GACnB,OAAO,WAAW,GAClB,OAAO,YAAY,CAAA;AAMvB,eAAO,MAAM,YAAY,cACZ,MAAM,GAAG,MAAM,EAAE,YAClB,QAAQ,GAAG,QAAQ,EAAE,YACtB;IAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,KACvE,cA4EF,CAAA"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authenticate = void 0;
4
+ const utils_1 = require("@etohq/utils");
5
+ const jsonwebtoken_1 = require("jsonwebtoken");
6
+ const SESSION_AUTH = "session";
7
+ const BEARER_AUTH = "bearer";
8
+ const API_KEY_AUTH = "api-key";
9
+ // This is the only hard-coded actor type, as API keys have special handling for now. We could also generalize API keys to carry the actor type with them.
10
+ const ADMIN_ACTOR_TYPE = "user";
11
+ const authenticate = (actorType, authType, options = {}) => {
12
+ const authenticateMiddleware = async (req, res, next) => {
13
+ const authTypes = Array.isArray(authType) ? authType : [authType];
14
+ const actorTypes = Array.isArray(actorType) ? actorType : [actorType];
15
+ const req_ = req;
16
+ // We only allow authenticating using a secret API key on the admin
17
+ const isExclusivelyUser = actorTypes.length === 1 && actorTypes[0] === ADMIN_ACTOR_TYPE;
18
+ if (authTypes.includes(API_KEY_AUTH) && isExclusivelyUser) {
19
+ const apiKey = await getApiKeyInfo(req);
20
+ if (apiKey) {
21
+ req_.auth_context = {
22
+ actor_id: apiKey.id,
23
+ actor_type: "api-key",
24
+ auth_identity_id: "",
25
+ app_metadata: {},
26
+ };
27
+ return next();
28
+ }
29
+ }
30
+ // We try to extract the auth context either from the session or from a JWT token
31
+ let authContext = getAuthContextFromSession(req.session, authTypes, actorTypes);
32
+ if (!authContext) {
33
+ const { projectConfig: { http }, } = req.scope.resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
34
+ authContext = getAuthContextFromJwtToken(req.headers.authorization, http.jwtSecret, authTypes, actorTypes);
35
+ }
36
+ // If the entity is authenticated, and it is a registered actor we can continue
37
+ if (authContext?.actor_id) {
38
+ req_.auth_context = authContext;
39
+ return next();
40
+ }
41
+ // If the entity is authenticated, but there is no registered actor yet, we can continue (eg. in the case of a user invite) if allow unregistered is set
42
+ // We also don't want to allow creating eg. a customer with a token created for a `user` provider.
43
+ if (authContext?.auth_identity_id &&
44
+ options.allowUnregistered &&
45
+ isActorTypePermitted(actorTypes, authContext.actor_type)) {
46
+ req_.auth_context = authContext;
47
+ return next();
48
+ }
49
+ // If we allow unauthenticated requests (i.e public endpoints), just continue
50
+ if (options.allowUnauthenticated) {
51
+ return next();
52
+ }
53
+ res.status(401).json({ message: "Unauthorized" });
54
+ };
55
+ return authenticateMiddleware;
56
+ };
57
+ exports.authenticate = authenticate;
58
+ const getApiKeyInfo = async (req) => {
59
+ const authHeader = req.headers.authorization;
60
+ if (!authHeader) {
61
+ return null;
62
+ }
63
+ const [tokenType, token] = authHeader.split(" ");
64
+ if (tokenType.toLowerCase() !== "basic" || !token) {
65
+ return null;
66
+ }
67
+ // The token could have been base64 encoded, we want to decode it first.
68
+ let normalizedToken = token;
69
+ if (!token.startsWith("sk_")) {
70
+ normalizedToken = Buffer.from(token, "base64").toString("utf-8");
71
+ }
72
+ // Basic auth is defined as a username:password set, and since the token is set to the username we need to trim the colon
73
+ if (normalizedToken.endsWith(":")) {
74
+ normalizedToken = normalizedToken.slice(0, -1);
75
+ }
76
+ // Secret tokens start with 'sk_', and if it doesn't it could be a user JWT or a malformed token
77
+ if (!normalizedToken.startsWith("sk_")) {
78
+ return null;
79
+ }
80
+ const apiKeyModule = req.scope.resolve(utils_1.Modules.API_KEY);
81
+ try {
82
+ const apiKey = await apiKeyModule.authenticate(normalizedToken);
83
+ if (!apiKey) {
84
+ return null;
85
+ }
86
+ return apiKey;
87
+ }
88
+ catch (error) {
89
+ console.error(error);
90
+ return null;
91
+ }
92
+ };
93
+ const getAuthContextFromSession = (session = {}, authTypes, actorTypes) => {
94
+ if (!authTypes.includes(SESSION_AUTH)) {
95
+ return null;
96
+ }
97
+ if (session.auth_context &&
98
+ isActorTypePermitted(actorTypes, session.auth_context?.actor_type)) {
99
+ return session.auth_context;
100
+ }
101
+ return null;
102
+ };
103
+ const getAuthContextFromJwtToken = (authHeader, jwtSecret, authTypes, actorTypes) => {
104
+ if (!authTypes.includes(BEARER_AUTH)) {
105
+ return null;
106
+ }
107
+ if (!authHeader) {
108
+ return null;
109
+ }
110
+ const re = /(\S+)\s+(\S+)/;
111
+ const matches = authHeader.match(re);
112
+ // TODO: figure out how to obtain token (and store correct data in token)
113
+ if (matches) {
114
+ const tokenType = matches[1];
115
+ const token = matches[2];
116
+ if (tokenType.toLowerCase() === BEARER_AUTH) {
117
+ // get config jwt secret
118
+ // verify token and set authUser
119
+ try {
120
+ const verified = (0, jsonwebtoken_1.verify)(token, jwtSecret);
121
+ if (isActorTypePermitted(actorTypes, verified.actor_type)) {
122
+ return verified;
123
+ }
124
+ }
125
+ catch (err) {
126
+ return null;
127
+ }
128
+ }
129
+ }
130
+ return null;
131
+ };
132
+ const isActorTypePermitted = (actorTypes, currentActorType) => {
133
+ return actorTypes.includes("*") || actorTypes.includes(currentActorType);
134
+ };
135
+ //# sourceMappingURL=authenticate-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticate-middleware.js","sourceRoot":"","sources":["../../../src/http/middlewares/authenticate-middleware.ts"],"names":[],"mappings":";;;AACA,wCAAiE;AAEjE,+CAAiD;AASjD,MAAM,YAAY,GAAG,SAAS,CAAA;AAC9B,MAAM,WAAW,GAAG,QAAQ,CAAA;AAC5B,MAAM,YAAY,GAAG,SAAS,CAAA;AAE9B,0JAA0J;AAC1J,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAWxB,MAAM,YAAY,GAAG,CAC1B,SAA4B,EAC5B,QAA+B,EAC/B,UAA2E,EAAE,EAC7D,EAAE;IAClB,MAAM,sBAAsB,GAAG,KAAK,EAClC,GAAe,EACf,GAAgB,EAChB,IAAkB,EACH,EAAE;QACjB,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QACjE,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QACrE,MAAM,IAAI,GAAG,GAA8B,CAAA;QAE3C,mEAAmE;QACnE,MAAM,iBAAiB,GACrB,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAA;QAE/D,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,iBAAiB,EAAE,CAAC;YAC1D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;YACvC,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,GAA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AAQ,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC1D,OAAO,QAAuB,CAAA;gBAChC,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,oBAAoB,GAAG,CAC3B,UAA6B,EAC7B,gBAAwB,EACxB,EAAE;IACF,OAAO,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;AAC1E,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { EtoNextFunction, EtoRequest } from "../types";
2
+ export declare function clearFiltersByKey(keys: string[]): (req: EtoRequest, _: any, next: EtoNextFunction) => Promise<void>;
3
+ //# sourceMappingURL=clear-filters-by-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear-filters-by-key.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/clear-filters-by-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEtD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAC3B,UAAU,gBAAW,eAAe,mBAOxD"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearFiltersByKey = clearFiltersByKey;
4
+ function clearFiltersByKey(keys) {
5
+ return async (req, _, next) => {
6
+ keys.forEach((key) => {
7
+ delete req.filterableFields[key];
8
+ });
9
+ return next();
10
+ };
11
+ }
12
+ //# sourceMappingURL=clear-filters-by-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear-filters-by-key.js","sourceRoot":"","sources":["../../../src/http/middlewares/clear-filters-by-key.ts"],"names":[],"mappings":";;AAEA,8CAQC;AARD,SAAgB,iBAAiB,CAAC,IAAc;IAC9C,OAAO,KAAK,EAAE,GAAe,EAAE,CAAC,EAAE,IAAqB,EAAE,EAAE;QACzD,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { EtoNextFunction, EtoResponse, EtoStoreRequest } from "../../http";
2
+ export declare function ensurePublishableApiKeyMiddleware(req: EtoStoreRequest, _res: EtoResponse, next: EtoNextFunction): Promise<void>;
3
+ //# sourceMappingURL=ensure-publishable-api-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure-publishable-api-key.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/ensure-publishable-api-key.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EAChB,MAAM,YAAY,CAAA;AAEnB,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,eAAe,iBA2DtB"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensurePublishableApiKeyMiddleware = ensurePublishableApiKeyMiddleware;
4
+ const utils_1 = require("@etohq/utils");
5
+ async function ensurePublishableApiKeyMiddleware(req, _res, next) {
6
+ const publishableApiKey = req.get(utils_1.PUBLISHABLE_KEY_HEADER);
7
+ if (!(0, utils_1.isPresent)(publishableApiKey)) {
8
+ try {
9
+ throw new utils_1.EtoError(utils_1.EtoError.Types.NOT_ALLOWED, `Publishable API key required in the request header: ${utils_1.PUBLISHABLE_KEY_HEADER}. You can manage your keys in settings in the dashboard.`);
10
+ }
11
+ catch (e) {
12
+ return next(e);
13
+ }
14
+ }
15
+ let apiKey;
16
+ const query = req.scope.resolve(utils_1.ContainerRegistrationKeys.QUERY);
17
+ try {
18
+ const { data } = await query.graph({
19
+ entity: "api_key",
20
+ fields: ["id", "token", "sales_channels_link.sales_channel_id"],
21
+ filters: {
22
+ token: publishableApiKey,
23
+ type: utils_1.ApiKeyType.PUBLISHABLE,
24
+ $or: [
25
+ { revoked_at: { $eq: null } },
26
+ { revoked_at: { $gt: new Date() } },
27
+ ],
28
+ },
29
+ }, { throwIfKeyNotFound: true });
30
+ apiKey = data[0];
31
+ }
32
+ catch (e) {
33
+ return next(e);
34
+ }
35
+ if (!apiKey) {
36
+ try {
37
+ throw new utils_1.EtoError(utils_1.EtoError.Types.NOT_ALLOWED, `A valid publishable key is required to proceed with the request`);
38
+ }
39
+ catch (e) {
40
+ return next(e);
41
+ }
42
+ }
43
+ req.publishable_key_context = {
44
+ key: apiKey.token,
45
+ sales_channel_ids: apiKey.sales_channels_link.map((link) => link.sales_channel_id),
46
+ };
47
+ return next();
48
+ }
49
+ //# sourceMappingURL=ensure-publishable-api-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure-publishable-api-key.js","sourceRoot":"","sources":["../../../src/http/middlewares/ensure-publishable-api-key.ts"],"names":[],"mappings":";;AAaA,8EA8DC;AA3ED,wCAMqB;AAOd,KAAK,UAAU,iCAAiC,CACrD,GAAoB,EACpB,IAAiB,EACjB,IAAqB;IAErB,MAAM,iBAAiB,GAAG,GAAG,CAAC,GAAG,CAAC,8BAAsB,CAAC,CAAA;IAEzD,IAAI,CAAC,IAAA,iBAAS,EAAC,iBAAiB,CAAC,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,MAAM,IAAI,gBAAQ,CAChB,gBAAQ,CAAC,KAAK,CAAC,WAAW,EAC1B,uDAAuD,8BAAsB,0DAA0D,CACxI,CAAA;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,CAAC,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAA;IACV,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express";
2
+ import { EtoError } from "@etohq/utils";
3
+ import { EtoRequest } from "../types";
4
+ export declare function errorHandler(): (err: EtoError, req: EtoRequest, res: Response, next: NextFunction) => void;
5
+ /**
6
+ * @schema Error
7
+ * title: "Response Error"
8
+ * type: object
9
+ * properties:
10
+ * code:
11
+ * type: string
12
+ * description: A slug code to indicate the type of the error.
13
+ * enum: [invalid_state_error, invalid_request_error, api_error, unknown_error]
14
+ * message:
15
+ * type: string
16
+ * description: Description of the error that occurred.
17
+ * example: "first_name must be a string"
18
+ * type:
19
+ * type: string
20
+ * description: A slug indicating the type of the error.
21
+ * enum: [QueryRunnerAlreadyReleasedError, TransactionAlreadyStartedError, TransactionNotStartedError, conflict, unauthorized, payment_authorization_error, duplicate_error, not_allowed, invalid_data, not_found, database_error, unexpected_state, invalid_argument, unknown_error]
22
+ */
23
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,EAA6B,QAAQ,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAUrC,wBAAgB,YAAY,UAEnB,QAAQ,OACR,UAAU,OACV,QAAQ,QACP,YAAY,UA4DrB;AAED;;;;;;;;;;;;;;;;;GAiBG"}