@atol-sh/js 0.1.0 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  No unreleased changes yet.
10
10
 
11
+ ## [0.1.2] - 2026-07-08
12
+
13
+ ### Added
14
+
15
+ - `initialTestSession` config option (gated on `allowTestSessions`). When set,
16
+ `createAtolBrowserAuth(...).init()` adopts the given token response
17
+ deterministically and SKIPS the cold-load restore entirely -- no
18
+ redirect-callback handling, no hidden-iframe silent renew. The session settles
19
+ authenticated at first paint, race-free (unlike calling `seedTestSession`
20
+ after mount). This is the clean way to bootstrap a browser e2e session against
21
+ a stubbed backend with no IdP at the `issuer`, where the restore iframe would
22
+ otherwise block until it times out. Ignored unless `allowTestSessions: true`;
23
+ warns when the token has no future `exp`.
24
+
25
+ ## [0.1.1] - 2026-07-08
26
+
27
+ ### Added
28
+
29
+ - `seedTestSession(tokens)` on the browser auth client, gated behind a new
30
+ `allowTestSessions` config flag (default `false`). It establishes an
31
+ authenticated session directly from a token response — bypassing the OIDC
32
+ redirect/callback and signature/state/nonce checks — so browser e2e tests
33
+ can bootstrap a logged-in session against the in-memory token store without
34
+ a live IdP. Adopted through the same `applyTokens` path as a real login, so
35
+ `onSessionChange` subscribers flip to authenticated. Deny-by-default: it
36
+ throws unless `allowTestSessions: true`; enabling it logs a one-time
37
+ `console.warn`, and seeding a token without a future `exp` warns too (such a
38
+ token triggers an immediate renewal that can drop the session). Never enable
39
+ in production. Consumed by `@atol-sh/react/testing`.
40
+
11
41
  ## [0.1.0] - 2026-07-05
12
42
 
13
43
  Initial release. Framework-agnostic browser security core extracted from
package/dist/index.cjs CHANGED
@@ -864,6 +864,14 @@ function dpopEnabled(cfg) {
864
864
  if (typeof cfg === "boolean") return cfg;
865
865
  return cfg?.required === true;
866
866
  }
867
+ function warnIfSeedTokenNotFresh(accessToken) {
868
+ const exp = getTokenExpiry(accessToken);
869
+ if ((exp === null || exp <= Date.now()) && typeof console !== "undefined") {
870
+ console.warn(
871
+ "[Atol] test session: the access token has no future `exp` claim; the seeded session may immediately attempt renewal and drop. Seed a token whose exp is in the future."
872
+ );
873
+ }
874
+ }
867
875
  function createAtolBrowserAuth(config) {
868
876
  const issuer = config.issuer;
869
877
  const clientId = config.clientId;
@@ -873,6 +881,13 @@ function createAtolBrowserAuth(config) {
873
881
  const useRefreshTokens = config.useRefreshTokens ?? false;
874
882
  const useRefreshTokensFallback = config.useRefreshTokensFallback ?? false;
875
883
  const deriveEncryptionKey = config.deriveEncryptionKey ?? false;
884
+ const allowTestSessions = config.allowTestSessions ?? false;
885
+ const initialTestSession = allowTestSessions ? config.initialTestSession : void 0;
886
+ if (allowTestSessions && typeof console !== "undefined") {
887
+ console.warn(
888
+ "[Atol] allowTestSessions is ENABLED: seedTestSession can establish a session without OIDC validation. This is for tests only and must never be enabled in production."
889
+ );
890
+ }
876
891
  const requestedScopes = config.scopes ?? DEFAULT_SCOPES;
877
892
  const scope = useRefreshTokens && !requestedScopes.split(" ").includes("offline_access") ? `${requestedScopes} offline_access` : requestedScopes;
878
893
  const manager = createUserManager(issuer, clientId, redirectUri, scope, audience);
@@ -1221,6 +1236,11 @@ function createAtolBrowserAuth(config) {
1221
1236
  broadcast.subscribe((message) => {
1222
1237
  void onBroadcast(message);
1223
1238
  });
1239
+ if (initialTestSession) {
1240
+ warnIfSeedTokenNotFresh(initialTestSession.access_token);
1241
+ await applyTokens(initialTestSession);
1242
+ return session();
1243
+ }
1224
1244
  if (isCallbackUrl()) {
1225
1245
  try {
1226
1246
  await completeLogin();
@@ -1290,6 +1310,16 @@ function createAtolBrowserAuth(config) {
1290
1310
  const proof = dpop ? await dpop.signProof(method, url, { accessToken: token }) : void 0;
1291
1311
  return { token, proof };
1292
1312
  }
1313
+ async function seedTestSession(tokens) {
1314
+ if (!allowTestSessions) {
1315
+ throw new Error(
1316
+ "seedTestSession is disabled: pass allowTestSessions:true to createAtolBrowserAuth to enable it. It bypasses OIDC signature, state, and nonce validation and must never be enabled in production."
1317
+ );
1318
+ }
1319
+ warnIfSeedTokenNotFresh(tokens.access_token);
1320
+ await applyTokens(tokens);
1321
+ return session();
1322
+ }
1293
1323
  function onSessionChange(cb) {
1294
1324
  subscribers.add(cb);
1295
1325
  try {
@@ -1327,6 +1357,7 @@ function createAtolBrowserAuth(config) {
1327
1357
  signDPoPProof,
1328
1358
  isDPoPActive: () => dpop !== null,
1329
1359
  onSessionChange,
1360
+ seedTestSession,
1330
1361
  destroy
1331
1362
  };
1332
1363
  }