@versini/auth0-auth-js-stub 1.0.0 → 1.2.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/README.md CHANGED
@@ -7,9 +7,16 @@ first-paint weight) and powers only the **MFA / Passkey / MyAccount / DPoP** API
7
7
  your app uses only basic Auth0 login (`loginWithRedirect`, `getAccessTokenSilently`,
8
8
  `logout`, `isAuthenticated`, `user`), that weight is dead code.
9
9
 
10
- This stub satisfies the symbols `@auth0/auth0-spa-js` imports at runtime. `AuthClient`
11
- constructs without throwing (it runs on every login), and any MFA/Passkey method call
12
- throws a clear, actionable error.
10
+ This stub satisfies the symbols `@auth0/auth0-spa-js` imports or re-exports at runtime.
11
+ `AuthClient` constructs without throwing (it runs on every login). Any MFA, Passkey, or
12
+ anonymous-session method call throws a clear, actionable error, and `isFederatedDomain`
13
+ returns a promise that rejects with one. The exception is `anonymous.mintTransferToken`:
14
+ it resolves `null`. spa-js 2.28 calls it at login whenever a stored anonymous session token
15
+ exists (one left by an earlier non-thin deployment), and the stub never has a session to link.
16
+
17
+ > ⚠️ Do not set `createAnonymousSessionOnFailedSilentAuth` with this stub. spa-js 2.27
18
+ > calls the anonymous client from `checkSession` when that option is on and swallows the
19
+ > stub's error in a `try/catch`, so the fallback silently does nothing.
13
20
 
14
21
  ## Usage
15
22
 
package/index.cjs CHANGED
@@ -7,20 +7,38 @@ const notSupported = feature => () => {
7
7
  );
8
8
  };
9
9
 
10
- const throwingClient = label =>
10
+ // `methods` are the few sub-client calls spa-js makes on a core path; every
11
+ // other property is a throwing function.
12
+ const throwingClient = (label, methods = {}) =>
11
13
  new Proxy(
12
14
  {},
13
- { get: (_t, prop) => notSupported(`${label}.${String(prop)}`) }
15
+ {
16
+ get: (_t, prop) =>
17
+ Object.prototype.hasOwnProperty.call(methods, prop)
18
+ ? methods[prop]
19
+ : notSupported(`${label}.${String(prop)}`)
20
+ }
14
21
  );
15
22
 
16
23
  class AuthClient {
17
24
  constructor(_options) {
18
25
  this.mfa = throwingClient('mfa');
19
26
  this.passkey = throwingClient('passkey');
27
+ // On every login spa-js 2.28 asks its anonymous wrapper for a transfer token,
28
+ // and the wrapper calls this whenever a stored anonymous session token exists
29
+ // (one left by an earlier non-thin deployment). This stub can never create
30
+ // such a session, so there is nothing to link: resolve null, never throw.
31
+ this.anonymous = throwingClient('anonymous', { mintTransferToken: async () => null });
20
32
  }
21
33
  }
22
34
 
23
35
  class MfaClient {}
36
+ class AnonymousSessionClient {}
37
+
38
+ // Enterprise Connect domain discovery. spa-js wraps it in its own exported
39
+ // isFederatedDomain, which only the app calls. Async upstream, so reject
40
+ // rather than throw.
41
+ const isFederatedDomain = async (..._args) => notSupported('isFederatedDomain')();
24
42
 
25
43
  class StubError extends Error {
26
44
  constructor(code, message) {
@@ -65,14 +83,23 @@ class PasskeyGetTokenError extends StubError {
65
83
  this.name = 'PasskeyGetTokenError';
66
84
  }
67
85
  }
86
+ class AnonymousSessionError extends StubError {
87
+ constructor(c, m) {
88
+ super(c, m);
89
+ this.name = 'AnonymousSessionError';
90
+ }
91
+ }
68
92
 
69
93
  module.exports = {
70
94
  AuthClient,
71
95
  MfaClient,
96
+ AnonymousSessionClient,
97
+ isFederatedDomain,
72
98
  MfaListAuthenticatorsError,
73
99
  MfaEnrollmentError,
74
100
  MfaChallengeError,
75
101
  PasskeyRegisterError,
76
102
  PasskeyChallengeError,
77
- PasskeyGetTokenError
103
+ PasskeyGetTokenError,
104
+ AnonymousSessionError
78
105
  };
package/index.d.ts CHANGED
@@ -1,14 +1,23 @@
1
1
  // Type stub for @auth0/auth0-auth-js — permissive shapes for the symbols the
2
- // @auth0/auth0-spa-js typings reference. MFA/Passkey are not used in this app.
2
+ // @auth0/auth0-spa-js typings reference. MFA/Passkey/anonymous sessions and
3
+ // Enterprise Connect domain discovery are not used in this app.
3
4
 
4
5
  export declare class AuthClient {
5
6
  constructor(options?: unknown);
6
7
  mfa: any;
7
8
  passkey: any;
9
+ anonymous: any;
8
10
  }
9
11
 
10
12
  export declare class MfaClient {}
11
13
  export declare class PasskeyClient {}
14
+ export declare class AnonymousSessionClient {}
15
+
16
+ export declare function isFederatedDomain(
17
+ auth0Domain: string,
18
+ emailDomain: string,
19
+ options?: unknown
20
+ ): Promise<boolean>;
12
21
 
13
22
  export declare class MfaListAuthenticatorsError extends Error {
14
23
  code?: string;
@@ -28,6 +37,9 @@ export declare class PasskeyChallengeError extends Error {
28
37
  export declare class PasskeyGetTokenError extends Error {
29
38
  code?: string;
30
39
  }
40
+ export declare class AnonymousSessionError extends Error {
41
+ code?: string;
42
+ }
31
43
 
32
44
  export type MfaApiErrorResponse = any;
33
45
  export type PasskeyCreationOptions = any;
@@ -37,3 +49,9 @@ export type PasskeyLoginChallengeResponse = any;
37
49
  export type PasskeyRequestOptions = any;
38
50
  export type PasskeySignupChallengeOptions = any;
39
51
  export type PasskeySignupChallengeResponse = any;
52
+ export type AnonymousSession = any;
53
+ export type AnonymousSessionClaims = any;
54
+ export type AnonymousSessionErrorCode = any;
55
+ export type CreateAnonymousSessionOptions = any;
56
+ export type GetAnonymousAccessTokenOptions = any;
57
+ export type IsFederatedDomainOptions = any;
package/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  // Featherweight stub of @auth0/auth0-auth-js (ESM).
2
2
  //
3
- // This app does not use Auth0 MFA or Passkey flows. The real package pulls in
3
+ // This app does not use Auth0 MFA, Passkey, anonymous-session or Enterprise
4
+ // Connect domain-discovery flows. The real package pulls in
4
5
  // openid-client + oauth4webapi + jose (~26KB gzip of first-paint weight). It is
5
6
  // swapped for this stub via pnpm overrides so that weight never ships.
6
7
  //
7
8
  // The forked @auth0/auth0-spa-js build (external: ['@auth0/auth0-auth-js'])
8
- // statically imports exactly these symbols; this stub satisfies them at runtime.
9
+ // statically imports or re-exports exactly these symbols; this stub satisfies
10
+ // them at runtime.
9
11
  // `new AuthClient()` runs on every Auth0Client construction, so it must not throw
10
- // — only the (unused) MFA/Passkey method calls do.
12
+ // — only the (unused) MFA/Passkey/anonymous-session method calls do.
11
13
 
12
14
  const notSupported = feature => () => {
13
15
  throw new Error(
@@ -16,20 +18,38 @@ const notSupported = feature => () => {
16
18
  );
17
19
  };
18
20
 
19
- const throwingClient = label =>
21
+ // `methods` are the few sub-client calls spa-js makes on a core path; every
22
+ // other property is a throwing function.
23
+ const throwingClient = (label, methods = {}) =>
20
24
  new Proxy(
21
25
  {},
22
- { get: (_t, prop) => notSupported(`${label}.${String(prop)}`) }
26
+ {
27
+ get: (_t, prop) =>
28
+ Object.prototype.hasOwnProperty.call(methods, prop)
29
+ ? methods[prop]
30
+ : notSupported(`${label}.${String(prop)}`)
31
+ }
23
32
  );
24
33
 
25
34
  export class AuthClient {
26
35
  constructor(_options) {
27
36
  this.mfa = throwingClient('mfa');
28
37
  this.passkey = throwingClient('passkey');
38
+ // On every login spa-js 2.28 asks its anonymous wrapper for a transfer token,
39
+ // and the wrapper calls this whenever a stored anonymous session token exists
40
+ // (one left by an earlier non-thin deployment). This stub can never create
41
+ // such a session, so there is nothing to link: resolve null, never throw.
42
+ this.anonymous = throwingClient('anonymous', { mintTransferToken: async () => null });
29
43
  }
30
44
  }
31
45
 
32
46
  export class MfaClient {}
47
+ export class AnonymousSessionClient {}
48
+
49
+ // Enterprise Connect domain discovery. spa-js wraps it in its own exported
50
+ // isFederatedDomain, which only the app calls. Async upstream, so reject
51
+ // rather than throw.
52
+ export const isFederatedDomain = async (..._args) => notSupported('isFederatedDomain')();
33
53
 
34
54
  class StubError extends Error {
35
55
  constructor(code, message) {
@@ -74,3 +94,9 @@ export class PasskeyGetTokenError extends StubError {
74
94
  this.name = 'PasskeyGetTokenError';
75
95
  }
76
96
  }
97
+ export class AnonymousSessionError extends StubError {
98
+ constructor(c, m) {
99
+ super(c, m);
100
+ this.name = 'AnonymousSessionError';
101
+ }
102
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@versini/auth0-auth-js-stub",
3
- "version": "1.0.0",
4
- "description": "Featherweight no-op stub of @auth0/auth0-auth-js for apps that use only basic Auth0 login (no MFA/Passkey/MyAccount/DPoP). Consumed via a pnpm `npm:` alias override to drop ~26KB gzip (openid-client + oauth4webapi + jose) from first paint. See @versini/auth0-thin.",
3
+ "version": "1.2.0",
4
+ "description": "Featherweight no-op stub of @auth0/auth0-auth-js for apps that use only basic Auth0 login (no MFA/Passkey/anonymous sessions/MyAccount/DPoP). Consumed via a pnpm `npm:` alias override to drop ~26KB gzip (openid-client + oauth4webapi + jose) from first paint. See @versini/auth0-thin.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
7
7
  "module": "./index.js",