@whippsp/auth0-helper 1.0.7 → 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 +36 -31
  2. package/package.json +1 -1
package/Auth0Helper.js CHANGED
@@ -1,40 +1,45 @@
1
1
  // Auth0Helper.js
2
- module.exports = function(userModule) {
3
- // Safety check: Ensure we have a valid module object
4
- if (!userModule || !userModule.exports) {
5
- console.error("Auth0Helper: userModule.exports is undefined. Ensure you pass 'module'.");
6
- return;
7
- }
2
+ module.exports = function(userModule, initialConfig = {}) {
3
+ // We don't wait for a getter/setter.
4
+ // We wrap the user's function immediately when they assign it.
5
+ const originalHandler = userModule.exports.onExecutePostLogin;
8
6
 
9
- let originalHandler = null;
7
+ Object.defineProperty(userModule.exports, 'onExecutePostLogin', {
8
+ configurable: true,
9
+ enumerable: true,
10
+ get: function() {
11
+ return async (event, api) => {
10
12
 
11
- try {
12
- Object.defineProperty(userModule.exports, 'onExecutePostLogin', {
13
- get: () => {
14
- if (typeof originalHandler !== 'function') return originalHandler;
13
+ let runtimeConfig = { ...initialConfig };
15
14
 
16
- return async (event, api) => {
17
- // 1. Skip logic
18
- if (event.transaction?.metadata?.skipremainingactions === 'true') {
19
- return;
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}`);
20
22
  }
23
+ };
21
24
 
22
- // 2. Method Injection
23
- api.skipRemaining = () => {
24
- api.transaction.setMetadata('skipremainingactions', 'true');
25
- };
25
+ if (event.transaction?.metadata?.skipremainingactions === 'true') {
26
+ log(`Auth0Helper: Skipping execution ${runtimeConfig.ActionName}.`);
27
+ return;
28
+ }
26
29
 
27
- // 3. Call your code
28
- return await originalHandler(event, api);
30
+ api.skipRemaining = () => {
31
+ log("skipRemaining called. Setting metadata flag.");
32
+ api.transaction.setMetadata('skipremainingactions', 'true');
29
33
  };
30
- },
31
- set: (value) => {
32
- originalHandler = value;
33
- },
34
- configurable: true,
35
- enumerable: true
36
- });
37
- } catch (e) {
38
- console.error("Auth0Helper: Failed to define property. Runtime may be restricted.", e);
39
- }
34
+
35
+ const targetFn = this._rawHandler || originalHandler;
36
+ if (typeof targetFn === 'function') {
37
+ return await targetFn(event, api);
38
+ }
39
+ };
40
+ },
41
+ set: function(fn) {
42
+ this._rawHandler = fn;
43
+ }
44
+ });
40
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whippsp/auth0-helper",
3
- "version": "1.0.7",
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": {