backend-manager 5.0.189 → 5.0.190
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 +1 -1
- package/src/manager/events/auth/before-create.js +4 -0
- package/src/manager/events/auth/before-signin.js +5 -0
- package/src/manager/events/auth/on-create.js +6 -1
- package/src/manager/events/auth/on-delete.js +6 -1
- package/src/manager/events/auth/utils.js +46 -1
- package/src/manager/functions/core/actions/api/admin/cron.js +1 -1
- package/src/manager/index.js +1 -1
- package/src/manager/libraries/abandoned-cart-config.js +1 -1
- package/src/manager/routes/admin/cron/post.js +1 -1
- /package/src/manager/{cron → events/cron}/daily/data-requests.js +0 -0
- /package/src/manager/{cron → events/cron}/daily/expire-paypal-cancellations.js +0 -0
- /package/src/manager/{cron → events/cron}/daily/ghostii-auto-publisher.js +0 -0
- /package/src/manager/{cron → events/cron}/daily/marketing-newsletter-generate.js +0 -0
- /package/src/manager/{cron → events/cron}/daily/marketing-prune.js +0 -0
- /package/src/manager/{cron → events/cron}/daily/reset-usage.js +0 -0
- /package/src/manager/{cron → events/cron}/daily.js +0 -0
- /package/src/manager/{cron → events/cron}/frequent/abandoned-carts.js +0 -0
- /package/src/manager/{cron → events/cron}/frequent/email-queue.js +0 -0
- /package/src/manager/{cron → events/cron}/frequent/marketing-campaigns.js +0 -0
- /package/src/manager/{cron → events/cron}/frequent.js +0 -0
- /package/src/manager/{cron → events/cron}/runner.js +0 -0
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { isDisposable } = require('../../libraries/email/validation.js');
|
|
2
|
+
const { runAuthHook } = require('./utils.js');
|
|
2
3
|
|
|
3
4
|
const ERROR_TOO_MANY_ATTEMPTS = 'Unable to create account at this time. Please try again later.';
|
|
4
5
|
const ERROR_DISPOSABLE_EMAIL = 'This email domain is not allowed. Please use a different email address.';
|
|
@@ -71,5 +72,8 @@ module.exports = async ({ Manager, assistant, user, context, libraries }) => {
|
|
|
71
72
|
usage.increment('signups');
|
|
72
73
|
await usage.update();
|
|
73
74
|
|
|
75
|
+
// Run consumer hook (can throw HttpsError to block signup)
|
|
76
|
+
await runAuthHook('before-create', { Manager, assistant, user, context, libraries });
|
|
77
|
+
|
|
74
78
|
assistant.log(`beforeCreate: Completed for ${user.uid} (${Date.now() - startTime}ms)`);
|
|
75
79
|
};
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
* Note: recaptchaScore requires reCAPTCHA Enterprise (Google Cloud level), NOT the Firebase SMS fraud toggle.
|
|
25
25
|
* Note: credential tokens (idToken, accessToken, refreshToken) require opt-in via BlockingOptions.
|
|
26
26
|
*/
|
|
27
|
+
const { runAuthHook } = require('./utils.js');
|
|
28
|
+
|
|
27
29
|
module.exports = async ({ Manager, assistant, user, context, libraries }) => {
|
|
28
30
|
const startTime = Date.now();
|
|
29
31
|
const { admin } = libraries;
|
|
@@ -60,5 +62,8 @@ module.exports = async ({ Manager, assistant, user, context, libraries }) => {
|
|
|
60
62
|
assistant.log(`beforeSignIn: Updated user activity`);
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
// Run consumer hook (can throw HttpsError to block sign-in)
|
|
66
|
+
await runAuthHook('before-signin', { Manager, assistant, user, context, libraries });
|
|
67
|
+
|
|
63
68
|
assistant.log(`beforeSignIn: Completed for ${user.uid} (${Date.now() - startTime}ms)`);
|
|
64
69
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { retryWrite, MAX_RETRIES } = require('./utils.js');
|
|
1
|
+
const { retryWrite, runAuthHook, MAX_RETRIES } = require('./utils.js');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* onCreate - Create user doc
|
|
@@ -87,6 +87,11 @@ module.exports = async ({ Manager, assistant, user, context, libraries }) => {
|
|
|
87
87
|
// Don't reject - the user was already created in Auth
|
|
88
88
|
// The user/signup endpoint will handle creating the doc if it's missing
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
// Run consumer hook (non-blocking — errors logged but don't fail)
|
|
92
|
+
await runAuthHook('on-create', { Manager, assistant, user, context, libraries }).catch(e => {
|
|
93
|
+
assistant.error('onCreate: Consumer hook error:', e);
|
|
94
|
+
});
|
|
90
95
|
};
|
|
91
96
|
|
|
92
97
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { retryWrite, MAX_RETRIES } = require('./utils.js');
|
|
1
|
+
const { retryWrite, runAuthHook, MAX_RETRIES } = require('./utils.js');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* onDelete - Delete user doc
|
|
@@ -70,5 +70,10 @@ module.exports = async ({ Manager, assistant, user, context, libraries }) => {
|
|
|
70
70
|
uuid: user.uid,
|
|
71
71
|
}).event('user_delete', {});
|
|
72
72
|
|
|
73
|
+
// Run consumer hook (non-blocking — errors logged but don't fail)
|
|
74
|
+
await runAuthHook('on-delete', { Manager, assistant, user, context, libraries }).catch(e => {
|
|
75
|
+
assistant.error('onDelete: Consumer hook error:', e);
|
|
76
|
+
});
|
|
77
|
+
|
|
73
78
|
assistant.log(`onDelete: Completed for ${user.uid} (${Date.now() - startTime}ms)`);
|
|
74
79
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const jetpack = require('fs-jetpack');
|
|
2
|
+
|
|
1
3
|
const MAX_RETRIES = 3;
|
|
2
4
|
const RETRY_DELAY_MS = 1000;
|
|
3
5
|
|
|
@@ -26,4 +28,47 @@ async function retryWrite(assistant, tag, fn) {
|
|
|
26
28
|
throw lastError; // All retries failed
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Run consumer auth hooks from hooks/auth/{eventName}.js
|
|
33
|
+
*
|
|
34
|
+
* Similar to how cron discovers hooks at hooks/cron/{schedule}/*.js,
|
|
35
|
+
* auth hooks are discovered at hooks/auth/{eventName}.js in the consumer project.
|
|
36
|
+
*
|
|
37
|
+
* For blocking functions (before-create, before-signin):
|
|
38
|
+
* - Hook can throw HttpsError to block the operation
|
|
39
|
+
* - Hook runs AFTER BEM's core checks (disposable email, rate limiting, etc.)
|
|
40
|
+
*
|
|
41
|
+
* For trigger functions (on-create, on-delete):
|
|
42
|
+
* - Hook errors are logged but don't block the operation
|
|
43
|
+
*
|
|
44
|
+
* Hook signature:
|
|
45
|
+
* module.exports = async ({ Manager, assistant, user, context, libraries }) => { ... }
|
|
46
|
+
*
|
|
47
|
+
* Consumer project structure:
|
|
48
|
+
* functions/
|
|
49
|
+
* hooks/
|
|
50
|
+
* auth/
|
|
51
|
+
* before-create.js — runs after BEM checks, can block signup
|
|
52
|
+
* before-signin.js — runs after BEM signin logic, can block signin
|
|
53
|
+
* on-create.js — runs after BEM creates user doc
|
|
54
|
+
* on-delete.js — runs after BEM deletes user doc
|
|
55
|
+
*/
|
|
56
|
+
async function runAuthHook(eventName, args) {
|
|
57
|
+
const { Manager, assistant } = args;
|
|
58
|
+
const hookPath = `${Manager.cwd}/hooks/auth/${eventName}.js`;
|
|
59
|
+
|
|
60
|
+
// Check if hook file exists
|
|
61
|
+
if (!jetpack.exists(hookPath)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
assistant.log(`${eventName}: Running consumer hook @ ${hookPath}`);
|
|
66
|
+
|
|
67
|
+
// Load and execute — passes the same args object the BEM handler received
|
|
68
|
+
const hook = require(hookPath);
|
|
69
|
+
await hook(args);
|
|
70
|
+
|
|
71
|
+
assistant.log(`${eventName}: Consumer hook completed`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { retryWrite, runAuthHook, MAX_RETRIES };
|
|
@@ -22,7 +22,7 @@ Module.prototype.main = function () {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Run the cron job
|
|
25
|
-
Manager._process((new (require(
|
|
25
|
+
Manager._process((new (require(`${Manager.rootDirectory}/events/cron/${payload.data.payload.id}.js`))()).init(Manager, { context: {}, }))
|
|
26
26
|
.then((res) => {
|
|
27
27
|
return resolve({data: res});
|
|
28
28
|
})
|
package/src/manager/index.js
CHANGED
|
@@ -14,8 +14,8 @@ const util = require('util');
|
|
|
14
14
|
const core = './functions/core';
|
|
15
15
|
const wrappers = './functions/wrappers';
|
|
16
16
|
const _legacy = './functions/_legacy';
|
|
17
|
-
const cron = path.resolve(__dirname, './cron');
|
|
18
17
|
const events = path.resolve(__dirname, './events');
|
|
18
|
+
const cron = path.resolve(events, './cron');
|
|
19
19
|
|
|
20
20
|
const BEM_CONFIG_TEMPLATE_PATH = path.resolve(__dirname, '../../templates/backend-manager-config.json');
|
|
21
21
|
const BEM_PACKAGE = require('../../package.json');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Abandoned cart reminder configuration (SSOT)
|
|
3
3
|
*
|
|
4
4
|
* Used by:
|
|
5
|
-
* - cron/frequent/abandoned-carts.js (processing reminders)
|
|
5
|
+
* - events/cron/frequent/abandoned-carts.js (processing reminders)
|
|
6
6
|
* - Client-side checkout page (creating cart doc with first delay)
|
|
7
7
|
*/
|
|
8
8
|
module.exports = {
|
|
@@ -22,7 +22,7 @@ module.exports = async ({ assistant, Manager, user, settings, analytics }) => {
|
|
|
22
22
|
assistant.log('Running cron job:', settings.id);
|
|
23
23
|
|
|
24
24
|
// Run the cron job
|
|
25
|
-
const cronPath =
|
|
25
|
+
const cronPath = `${Manager.rootDirectory}/events/cron/${settings.id}.js`;
|
|
26
26
|
const cronHandler = require(cronPath);
|
|
27
27
|
const result = await cronHandler({ Manager, assistant, context: {}, libraries: Manager.libraries }).catch(e => e);
|
|
28
28
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|