@whippsp/auth0-helper 1.0.8 → 1.0.9

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 (2) hide show
  1. package/Auth0Helper.js +21 -10
  2. package/package.json +1 -1
package/Auth0Helper.js CHANGED
@@ -1,8 +1,6 @@
1
1
  // Auth0Helper.js
2
- module.exports = function(userModule) {
3
- console.log("Auth0Helper: Module Initialized");
4
-
5
- // We don't wait for a getter/setter.
2
+ module.exports = function(userModule, initialConfig = {}) {
3
+ // We don't wait for a getter/setter.
6
4
  // We wrap the user's function immediately when they assign it.
7
5
  const originalHandler = userModule.exports.onExecutePostLogin;
8
6
 
@@ -11,20 +9,33 @@ module.exports = function(userModule) {
11
9
  enumerable: true,
12
10
  get: function() {
13
11
  return async (event, api) => {
14
- // 1. Check skip flag
12
+
13
+ let runtimeConfig = { ...initialConfig };
14
+
15
+ api.setHelperConfig = (newConfig) => {
16
+ runtimeConfig = { ...runtimeConfig, ...newConfig };
17
+ };
18
+
19
+ const log = (message) => {
20
+ if (runtimeConfig.debug === true) {
21
+ console.log(`[${runtimeConfig.ActionName || "Auth0Action"}] ${message}`);
22
+ }
23
+ };
24
+
15
25
  if (event.transaction?.metadata?.skipremainingactions === 'true') {
16
- console.log("Auth0Helper: Skipping execution.");
26
+ log(`Auth0Helper: Skipping execution ${runtimeConfig.ActionName}.`);
17
27
  return;
18
28
  }
19
29
 
20
- // 2. Immediate Injection
21
30
  api.skipRemaining = () => {
31
+ log("skipRemaining called. Setting metadata flag.");
22
32
  api.transaction.setMetadata('skipremainingactions', 'true');
23
33
  };
24
34
 
25
- // 3. Call your code
26
- // We use a private variable to store the real logic
27
- return await this._rawHandler(event, api);
35
+ const targetFn = this._rawHandler || originalHandler;
36
+ if (typeof targetFn === 'function') {
37
+ return await targetFn(event, api);
38
+ }
28
39
  };
29
40
  },
30
41
  set: function(fn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whippsp/auth0-helper",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "A helper to override Auth0 Actions handlers with skip logic.",
5
5
  "main": "Auth0Helper.js",
6
6
  "publishConfig": {