backend-manager 5.0.40 → 5.0.41
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/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EventMiddleware
|
|
3
3
|
* Used to handle middleware for event triggers (auth, firestore, cron)
|
|
4
|
+
*
|
|
5
|
+
* Usage in consumer projects:
|
|
6
|
+
* exports.userOnCreate = functions
|
|
7
|
+
* .firestore.document('users/{uid}')
|
|
8
|
+
* .onCreate((snapshot, context) =>
|
|
9
|
+
* Manager.EventMiddleware({ snapshot, context }).run('users/on-create')
|
|
10
|
+
* );
|
|
11
|
+
*
|
|
12
|
+
* Handler location: functions/hooks/events/{name}.js
|
|
4
13
|
*/
|
|
5
14
|
|
|
6
15
|
function EventMiddleware(m, payload) {
|
|
@@ -10,7 +19,7 @@ function EventMiddleware(m, payload) {
|
|
|
10
19
|
self.payload = payload;
|
|
11
20
|
}
|
|
12
21
|
|
|
13
|
-
EventMiddleware.prototype.run = function (
|
|
22
|
+
EventMiddleware.prototype.run = function (handlerName, options) {
|
|
14
23
|
const self = this;
|
|
15
24
|
|
|
16
25
|
// Shortcuts
|
|
@@ -21,6 +30,16 @@ EventMiddleware.prototype.run = function (handlerPath, options) {
|
|
|
21
30
|
const assistant = Manager.Assistant();
|
|
22
31
|
options = options || {};
|
|
23
32
|
|
|
33
|
+
// Resolve handler path
|
|
34
|
+
// If it's an absolute path, use it directly
|
|
35
|
+
// Otherwise, look in the consumer's hooks/events/ directory
|
|
36
|
+
let handlerPath;
|
|
37
|
+
if (handlerName.startsWith('/')) {
|
|
38
|
+
handlerPath = handlerName;
|
|
39
|
+
} else {
|
|
40
|
+
handlerPath = `${Manager.cwd}/hooks/events/${handlerName}.js`;
|
|
41
|
+
}
|
|
42
|
+
|
|
24
43
|
// Build context based on event type
|
|
25
44
|
const context = {
|
|
26
45
|
Manager,
|
|
@@ -30,6 +49,7 @@ EventMiddleware.prototype.run = function (handlerPath, options) {
|
|
|
30
49
|
user: payload.user,
|
|
31
50
|
context: payload.context,
|
|
32
51
|
change: payload.change,
|
|
52
|
+
snapshot: payload.snapshot,
|
|
33
53
|
};
|
|
34
54
|
|
|
35
55
|
// Load handler
|
|
@@ -59,8 +59,11 @@ module.exports = async ({ assistant, Manager, user, settings, libraries }) => {
|
|
|
59
59
|
? 'https://localhost:4000/oauth2'
|
|
60
60
|
: `${Manager.config.brand.url}/oauth2`;
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// Get OAuth2 credentials from environment variables
|
|
63
|
+
// Format: OAUTH2_{PROVIDER}_CLIENT_ID, OAUTH2_{PROVIDER}_CLIENT_SECRET
|
|
64
|
+
const providerEnvKey = settings.provider.toUpperCase().replace(/-/g, '_');
|
|
65
|
+
const client_id = process.env[`OAUTH2_${providerEnvKey}_CLIENT_ID`];
|
|
66
|
+
const client_secret = process.env[`OAUTH2_${providerEnvKey}_CLIENT_SECRET`];
|
|
64
67
|
|
|
65
68
|
const state = settings.state;
|
|
66
69
|
|