@atol-sh/js 0.1.1 → 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,20 @@ 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
+
11
25
  ## [0.1.1] - 2026-07-08
12
26
 
13
27
  ### Added
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;
@@ -874,6 +882,7 @@ function createAtolBrowserAuth(config) {
874
882
  const useRefreshTokensFallback = config.useRefreshTokensFallback ?? false;
875
883
  const deriveEncryptionKey = config.deriveEncryptionKey ?? false;
876
884
  const allowTestSessions = config.allowTestSessions ?? false;
885
+ const initialTestSession = allowTestSessions ? config.initialTestSession : void 0;
877
886
  if (allowTestSessions && typeof console !== "undefined") {
878
887
  console.warn(
879
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."
@@ -1227,6 +1236,11 @@ function createAtolBrowserAuth(config) {
1227
1236
  broadcast.subscribe((message) => {
1228
1237
  void onBroadcast(message);
1229
1238
  });
1239
+ if (initialTestSession) {
1240
+ warnIfSeedTokenNotFresh(initialTestSession.access_token);
1241
+ await applyTokens(initialTestSession);
1242
+ return session();
1243
+ }
1230
1244
  if (isCallbackUrl()) {
1231
1245
  try {
1232
1246
  await completeLogin();
@@ -1302,12 +1316,7 @@ function createAtolBrowserAuth(config) {
1302
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."
1303
1317
  );
1304
1318
  }
1305
- const exp = getTokenExpiry(tokens.access_token);
1306
- if ((exp === null || exp <= Date.now()) && typeof console !== "undefined") {
1307
- console.warn(
1308
- "[Atol] seedTestSession: 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."
1309
- );
1310
- }
1319
+ warnIfSeedTokenNotFresh(tokens.access_token);
1311
1320
  await applyTokens(tokens);
1312
1321
  return session();
1313
1322
  }