@enterprisestandard/react 0.0.5-beta.20260115.1 → 0.0.5-beta.20260115.2

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.
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Session management for tracking user sessions and enabling backchannel logout.
3
+ *
4
+ * Session stores are optional - the package works with JWT cookies alone.
5
+ * Sessions are only required for backchannel logout functionality.
6
+ *
7
+ * ## Session Validation Strategies
8
+ *
9
+ * When using a session store, you can configure when sessions are validated:
10
+ *
11
+ * ### 'always' (default)
12
+ * Validates session on every authenticated request.
13
+ * - **Security**: Maximum - immediate session revocation
14
+ * - **Performance**: InMemory ~0.00005ms, Redis ~1-2ms per request
15
+ * - **Backchannel Logout**: Takes effect immediately
16
+ * - **Use when**: Security is paramount, using InMemory or Redis backend
17
+ *
18
+ * ### 'refresh-only'
19
+ * Validates session only during token refresh (typically every 5-15 minutes).
20
+ * - **Security**: Good - 5-15 minute revocation window
21
+ * - **Performance**: 99% reduction in session lookups
22
+ * - **Backchannel Logout**: Takes effect within token TTL (5-15 min)
23
+ * - **Use when**: Performance is critical AND delayed revocation is acceptable
24
+ * - **WARNING**: Compromised sessions remain valid until next refresh
25
+ *
26
+ * ### 'disabled'
27
+ * Never validates sessions against the store.
28
+ * - **Security**: None - backchannel logout doesn't work
29
+ * - **Performance**: No overhead
30
+ * - **Use when**: Cookie-only mode without session store
31
+ * - **WARNING**: Do not use with session_store configured
32
+ *
33
+ * ## Performance Characteristics
34
+ *
35
+ * | Backend | Lookup Time | Impact on Request | Recommendation |
36
+ * |--------------|-------------|-------------------|------------------------|
37
+ * | InMemory | <0.00005ms | Negligible | Use 'always' |
38
+ * | Redis | 1-2ms | 2-4% increase | Use 'always' or test |
39
+ * | Database | 5-20ms | 10-40% increase | Use Redis cache layer |
40
+ *
41
+ * ## Example Usage
42
+ *
43
+ * ```typescript
44
+ * import { sso, InMemorySessionStore } from '@enterprisestandard/react/server';
45
+ *
46
+ * // Maximum security (default)
47
+ * const secure = sso({
48
+ * // ... other config
49
+ * session_store: new InMemorySessionStore(),
50
+ * session_validation: 'always', // Immediate revocation
51
+ * });
52
+ *
53
+ * // High performance
54
+ * const fast = sso({
55
+ * // ... other config
56
+ * session_store: new InMemorySessionStore(),
57
+ * session_validation: {
58
+ * strategy: 'refresh-only' // 5-15 min revocation delay
59
+ * }
60
+ * });
61
+ * ```
62
+ */
63
+ /**
64
+ * In-memory session store implementation using Maps.
65
+ *
66
+ * Suitable for:
67
+ * - Development and testing
68
+ * - Single-server deployments
69
+ * - Applications without high availability requirements
70
+ *
71
+ * NOT suitable for:
72
+ * - Multi-server deployments (sessions not shared)
73
+ * - High availability scenarios (sessions lost on restart)
74
+ * - Production applications with distributed architecture
75
+ *
76
+ * For production, implement SessionStore with Redis or a database.
77
+ *
78
+ * @template TExtended - Type-safe custom data that consumers can add to sessions
79
+ */
80
+ export class InMemorySessionStore {
81
+ constructor() {
82
+ this.sessions = new Map();
83
+ }
84
+ async create(session) {
85
+ if (this.sessions.has(session.sid)) {
86
+ throw new Error(`Session with sid ${session.sid} already exists`);
87
+ }
88
+ this.sessions.set(session.sid, session);
89
+ }
90
+ async get(sid) {
91
+ return this.sessions.get(sid) ?? null;
92
+ }
93
+ async update(sid, data) {
94
+ const session = this.sessions.get(sid);
95
+ if (!session) {
96
+ throw new Error(`Session with sid ${sid} not found`);
97
+ }
98
+ // Merge the update data
99
+ const updated = { ...session, ...data };
100
+ this.sessions.set(sid, updated);
101
+ }
102
+ async delete(sid) {
103
+ this.sessions.delete(sid);
104
+ }
105
+ }
@@ -1,4 +1,4 @@
1
- import { EnterpriseStandard } from '.';
1
+ import type { EnterpriseStandard } from '.';
2
2
  import type { LoginConfig } from './sso';
3
3
  /**
4
4
  * Helper gets the user from the Request using the supplied EnterpriseStandard or the default instance
@@ -1 +1 @@
1
- {"version":3,"file":"sso-server.d.ts","sourceRoot":"","sources":["../src/sso-server.ts"],"names":[],"mappings":"AAAA,OAAO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AAEhC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { getES } from './utils';
2
+ /**
3
+ * Returns a 503 response indicating that the SSO is unavailable
4
+ */
5
+ function unavailable(error) {
6
+ error = error ?? 'SSO Unavailable';
7
+ new Response(JSON.stringify({ error }), {
8
+ status: 503,
9
+ statusText: error,
10
+ headers: { 'Content-Type': 'application/json' },
11
+ });
12
+ }
13
+ /**
14
+ * Helper gets the user from the Request using the supplied EnterpriseStandard or the default instance
15
+ */
16
+ export async function getUser(request, es) {
17
+ return getES(es)?.sso.getUser(request);
18
+ }
19
+ export async function getRequiredUser(request, es) {
20
+ const sso = getES(es)?.sso;
21
+ if (!sso)
22
+ throw unavailable();
23
+ return sso.getRequiredUser(request);
24
+ }
25
+ export async function initiateLogin(config, es) {
26
+ const sso = getES(es)?.sso;
27
+ if (!sso)
28
+ throw unavailable();
29
+ return sso.initiateLogin(config);
30
+ }
31
+ export async function callback(request, es) {
32
+ const sso = getES(es)?.sso;
33
+ if (!sso)
34
+ throw unavailable();
35
+ return sso.callbackHandler(request);
36
+ }
37
+ export async function handler(request, es) {
38
+ es = getES(es);
39
+ if (!es)
40
+ throw unavailable();
41
+ return es.sso.handler(request, es);
42
+ }
43
+ // Tenant server helpers
44
+ export * from './tenant-server';
45
+ // Workload server helpers
46
+ export * from './workload-server';