@friggframework/core 0.2.13-canary.599e990.0 → 0.2.13-canary.ac41c25.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.
package/Delegate.js CHANGED
@@ -2,8 +2,8 @@ const { get } = require('@friggframework/assertions');
2
2
 
3
3
  class Delegate {
4
4
  constructor(params) {
5
- this.delegate = get(params, 'delegate', this);
6
- this.delegateTypes = get(params, 'events', []);
5
+ this.delegate = get(params, 'delegate', null);
6
+ this.delegateTypes = [];
7
7
  }
8
8
 
9
9
  async notify(delegateString, object = null) {
@@ -0,0 +1,58 @@
1
+ // This line should be at the top of the webpacked output, so be sure to require createHandler first in any handlers. "Soon" sourcemaps will be built into Node... after that, this package won't be needed.
2
+ require('source-map-support').install();
3
+
4
+ const { connectToDatabase } = require('@friggframework/database/mongo');
5
+ const { initDebugLog, flushDebugLog } = require('@friggframework/logs');
6
+
7
+ const createHandler = (optionByName = {}) => {
8
+ const {
9
+ eventName = 'Event',
10
+ isUserFacingResponse = true,
11
+ method,
12
+ shouldUseDatabase = true,
13
+ } = optionByName;
14
+
15
+ if (!method) {
16
+ throw new Error('Method is required for handler.');
17
+ }
18
+
19
+ return async (event, context) => {
20
+ try {
21
+ initDebugLog(eventName, event);
22
+
23
+ // Helps mongoose reuse the connection. Lowers response times.
24
+ context.callbackWaitsForEmptyEventLoop = false;
25
+
26
+ if (shouldUseDatabase) {
27
+ await connectToDatabase();
28
+ }
29
+
30
+ // Run the Lambda
31
+ return await method(event, context);
32
+ } catch (error) {
33
+ flushDebugLog(error);
34
+
35
+ // Don't leak implementation details to end users.
36
+ if (isUserFacingResponse) {
37
+ return {
38
+ statusCode: 500,
39
+ body: JSON.stringify({
40
+ error: 'An Internal Error Occurred',
41
+ }),
42
+ };
43
+ }
44
+
45
+ // Handle server-to-server responses.
46
+
47
+ // Halt errors are logged but suceed and won't be retried.
48
+ if (error.isHaltError === true) {
49
+ return;
50
+ }
51
+
52
+ // Here we can just rethrow and let AWS build the response.
53
+ throw error;
54
+ }
55
+ };
56
+ };
57
+
58
+ module.exports = { createHandler };
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const { Delegate } = require('./Delegate');
2
2
  const { Worker } = require('./Worker');
3
3
  const { loadInstalledModules } = require('./load-installed-modules');
4
+ const { createHandler } = require('./create-handler');
4
5
 
5
- module.exports = { Delegate, Worker, loadInstalledModules };
6
+ module.exports = { Delegate, Worker, loadInstalledModules, createHandler };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "0.2.13-canary.599e990.0",
4
+ "version": "0.2.13-canary.ac41c25.0",
5
5
  "devDependencies": {
6
6
  "@friggframework/eslint-config": "^1.0.8",
7
7
  "eslint": "^8.22.0",
@@ -32,5 +32,5 @@
32
32
  "node-fetch": "^2.6.7"
33
33
  },
34
34
  "description": "",
35
- "gitHead": "599e99041e865efa26576d166e68540c790b8920"
35
+ "gitHead": "ac41c253976bc005c265a426e793301870e7f817"
36
36
  }