@pod-os/core 0.16.1-rc.bdd004d.0 → 0.16.1

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 (3) hide show
  1. package/dist/index.js +192 -348
  2. package/lib/index.js +192 -348
  3. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -43332,11 +43332,6 @@ _:patch
43332
43332
  }
43333
43333
  break;
43334
43334
  }
43335
- case "Ed25519": {
43336
- if (!isAlgorithm(key3.algorithm, "Ed25519"))
43337
- throw unusable("Ed25519");
43338
- break;
43339
- }
43340
43335
  case "ES256":
43341
43336
  case "ES384":
43342
43337
  case "ES512": {
@@ -43520,10 +43515,6 @@ _:patch
43520
43515
  }
43521
43516
  case "OKP": {
43522
43517
  switch (jwk.alg) {
43523
- case "Ed25519":
43524
- algorithm3 = { name: "Ed25519" };
43525
- keyUsages = jwk.d ? ["sign"] : ["verify"];
43526
- break;
43527
43518
  case "EdDSA":
43528
43519
  algorithm3 = { name: jwk.crv };
43529
43520
  keyUsages = jwk.d ? ["sign"] : ["verify"];
@@ -43641,7 +43632,7 @@ _:patch
43641
43632
  }
43642
43633
  return decode(jwk.k);
43643
43634
  case "RSA":
43644
- if ("oth" in jwk && jwk.oth !== void 0) {
43635
+ if (jwk.oth !== void 0) {
43645
43636
  throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
43646
43637
  }
43647
43638
  case "EC":
@@ -43812,8 +43803,6 @@ _:patch
43812
43803
  case "ES384":
43813
43804
  case "ES512":
43814
43805
  return { hash: hash2, name: "ECDSA", namedCurve: algorithm3.namedCurve };
43815
- case "Ed25519":
43816
- return { name: "Ed25519" };
43817
43806
  case "EdDSA":
43818
43807
  return { name: algorithm3.name };
43819
43808
  default:
@@ -44387,6 +44376,9 @@ _:patch
44387
44376
  if (candidate4 && Array.isArray(jwk2.key_ops)) {
44388
44377
  candidate4 = jwk2.key_ops.includes("verify");
44389
44378
  }
44379
+ if (candidate4 && alg === "EdDSA") {
44380
+ candidate4 = jwk2.crv === "Ed25519" || jwk2.crv === "Ed448";
44381
+ }
44390
44382
  if (candidate4) {
44391
44383
  switch (alg) {
44392
44384
  case "ES256":
@@ -44401,12 +44393,6 @@ _:patch
44401
44393
  case "ES512":
44402
44394
  candidate4 = jwk2.crv === "P-521";
44403
44395
  break;
44404
- case "Ed25519":
44405
- candidate4 = jwk2.crv === "Ed25519";
44406
- break;
44407
- case "EdDSA":
44408
- candidate4 = jwk2.crv === "Ed25519" || jwk2.crv === "Ed448";
44409
- break;
44410
44396
  }
44411
44397
  }
44412
44398
  return candidate4;
@@ -44497,7 +44483,7 @@ _:patch
44497
44483
  var USER_AGENT;
44498
44484
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
44499
44485
  const NAME = "jose";
44500
- const VERSION = "v5.10.0";
44486
+ const VERSION = "v5.9.6";
44501
44487
  USER_AGENT = `${NAME}/${VERSION}`;
44502
44488
  }
44503
44489
  var jwksCache = Symbol();
@@ -44670,10 +44656,6 @@ _:patch
44670
44656
  algorithm3 = { name: "ECDSA", namedCurve: "P-521" };
44671
44657
  keyUsages = ["sign", "verify"];
44672
44658
  break;
44673
- case "Ed25519":
44674
- algorithm3 = { name: "Ed25519" };
44675
- keyUsages = ["sign", "verify"];
44676
- break;
44677
44659
  case "EdDSA": {
44678
44660
  keyUsages = ["sign", "verify"];
44679
44661
  const crv = options?.crv ?? "Ed25519";
@@ -44752,17 +44734,11 @@ _:patch
44752
44734
  return native_default.randomUUID();
44753
44735
  }
44754
44736
  options = options || {};
44755
- const rnds = options.random ?? options.rng?.() ?? rng();
44756
- if (rnds.length < 16) {
44757
- throw new Error("Random bytes length must be >= 16");
44758
- }
44737
+ const rnds = options.random || (options.rng || rng)();
44759
44738
  rnds[6] = rnds[6] & 15 | 64;
44760
44739
  rnds[8] = rnds[8] & 63 | 128;
44761
44740
  if (buf) {
44762
44741
  offset3 = offset3 || 0;
44763
- if (offset3 < 0 || offset3 + 16 > buf.length) {
44764
- throw new RangeError(`UUID byte range ${offset3}:${offset3 + 15} is out of buffer bounds`);
44765
- }
44766
44742
  for (let i = 0; i < 16; ++i) {
44767
44743
  buf[offset3 + i] = rnds[i];
44768
44744
  }
@@ -44781,8 +44757,6 @@ _:patch
44781
44757
  LOGIN: "login",
44782
44758
  LOGOUT: "logout",
44783
44759
  NEW_REFRESH_TOKEN: "newRefreshToken",
44784
- NEW_TOKENS: "newTokens",
44785
- AUTHORIZATION_REQUEST: "authorizationRequest",
44786
44760
  SESSION_EXPIRED: "sessionExpired",
44787
44761
  SESSION_EXTENDED: "sessionExtended",
44788
44762
  SESSION_RESTORED: "sessionRestore",
@@ -44794,7 +44768,6 @@ _:patch
44794
44768
  var SCOPE_WEBID = "webid";
44795
44769
  var DEFAULT_SCOPES = [SCOPE_OPENID, SCOPE_OFFLINE, SCOPE_WEBID].join(" ");
44796
44770
  var AggregateHandler = class {
44797
- handleables;
44798
44771
  constructor(handleables) {
44799
44772
  this.handleables = handleables;
44800
44773
  this.handleables = handleables;
@@ -44890,21 +44863,19 @@ _:patch
44890
44863
  return Boolean(fallback);
44891
44864
  }
44892
44865
  var AuthorizationCodeWithPkceOidcHandlerBase = class {
44893
- storageUtility;
44894
- redirector;
44895
44866
  constructor(storageUtility, redirector) {
44896
44867
  this.storageUtility = storageUtility;
44897
44868
  this.redirector = redirector;
44869
+ this.parametersGuard = (oidcLoginOptions) => {
44870
+ return oidcLoginOptions.issuerConfiguration.grantTypesSupported !== void 0 && oidcLoginOptions.issuerConfiguration.grantTypesSupported.indexOf("authorization_code") > -1 && oidcLoginOptions.redirectUrl !== void 0;
44871
+ };
44898
44872
  this.storageUtility = storageUtility;
44899
44873
  this.redirector = redirector;
44900
44874
  }
44901
- parametersGuard = (oidcLoginOptions) => {
44902
- return oidcLoginOptions.issuerConfiguration.grantTypesSupported !== void 0 && oidcLoginOptions.issuerConfiguration.grantTypesSupported.indexOf("authorization_code") > -1 && oidcLoginOptions.redirectUrl !== void 0;
44903
- };
44904
44875
  async canHandle(oidcLoginOptions) {
44905
44876
  return this.parametersGuard(oidcLoginOptions);
44906
44877
  }
44907
- async setupRedirectHandler({ oidcLoginOptions, state: state2, codeVerifier, targetUrl: targetUrl3 }) {
44878
+ async handleRedirect({ oidcLoginOptions, state: state2, codeVerifier, targetUrl: targetUrl3 }) {
44908
44879
  if (!this.parametersGuard(oidcLoginOptions)) {
44909
44880
  throw new Error("The authorization code grant requires a redirectUrl.");
44910
44881
  }
@@ -44941,7 +44912,6 @@ _:patch
44941
44912
  }
44942
44913
  };
44943
44914
  var GeneralLogoutHandler = class {
44944
- sessionInfoManager;
44945
44915
  constructor(sessionInfoManager) {
44946
44916
  this.sessionInfoManager = sessionInfoManager;
44947
44917
  this.sessionInfoManager = sessionInfoManager;
@@ -44954,16 +44924,15 @@ _:patch
44954
44924
  }
44955
44925
  };
44956
44926
  var IRpLogoutHandler = class {
44957
- redirector;
44958
44927
  constructor(redirector) {
44959
44928
  this.redirector = redirector;
44960
44929
  this.redirector = redirector;
44961
44930
  }
44962
44931
  async canHandle(userId, options) {
44963
- return options?.logoutType === "idp";
44932
+ return (options === null || options === void 0 ? void 0 : options.logoutType) === "idp";
44964
44933
  }
44965
44934
  async handle(userId, options) {
44966
- if (options?.logoutType !== "idp") {
44935
+ if ((options === null || options === void 0 ? void 0 : options.logoutType) !== "idp") {
44967
44936
  throw new Error("Attempting to call idp logout handler to perform app logout");
44968
44937
  }
44969
44938
  if (options.toLogoutUrl === void 0) {
@@ -44975,7 +44944,6 @@ _:patch
44975
44944
  }
44976
44945
  };
44977
44946
  var IWaterfallLogoutHandler = class {
44978
- handlers;
44979
44947
  constructor(sessionInfoManager, redirector) {
44980
44948
  this.handlers = [
44981
44949
  new GeneralLogoutHandler(sessionInfoManager),
@@ -45006,7 +44974,6 @@ _:patch
45006
44974
  ]);
45007
44975
  }
45008
44976
  var SessionInfoManagerBase = class {
45009
- storageUtility;
45010
44977
  constructor(storageUtility) {
45011
44978
  this.storageUtility = storageUtility;
45012
44979
  this.storageUtility = storageUtility;
@@ -45014,9 +44981,6 @@ _:patch
45014
44981
  update(_sessionId, _options) {
45015
44982
  throw new Error("Not Implemented");
45016
44983
  }
45017
- set(_sessionId, _sessionInfo) {
45018
- throw new Error("Not Implemented");
45019
- }
45020
44984
  get(_) {
45021
44985
  throw new Error("Not implemented");
45022
44986
  }
@@ -45027,6 +44991,7 @@ _:patch
45027
44991
  /**
45028
44992
  * This function removes all session-related information from storage.
45029
44993
  * @param sessionId the session identifier
44994
+ * @param storage the storage where session info is stored
45030
44995
  * @hidden
45031
44996
  */
45032
44997
  async clear(sessionId) {
@@ -45034,6 +44999,7 @@ _:patch
45034
44999
  }
45035
45000
  /**
45036
45001
  * Registers a new session, so that its ID can be retrieved.
45002
+ * @param sessionId
45037
45003
  */
45038
45004
  async register(_sessionId) {
45039
45005
  throw new Error("Not implemented");
@@ -45051,12 +45017,6 @@ _:patch
45051
45017
  async clearAll() {
45052
45018
  throw new Error("Not implemented");
45053
45019
  }
45054
- /**
45055
- * Sets authorization request state in storage for a given session ID.
45056
- */
45057
- async setOidcContext(_sessionId, _authorizationRequestState) {
45058
- throw new Error("Not implemented");
45059
- }
45060
45020
  };
45061
45021
  function getEndSessionUrl({ endSessionEndpoint, idTokenHint, postLogoutRedirectUri, state: state2 }) {
45062
45022
  const url7 = new URL(endSessionEndpoint);
@@ -45088,14 +45048,15 @@ _:patch
45088
45048
  try {
45089
45049
  new URL(url7);
45090
45050
  return true;
45091
- } catch {
45051
+ } catch (_a) {
45092
45052
  return false;
45093
45053
  }
45094
45054
  }
45095
45055
  function determineSigningAlg(supported, preferred2) {
45096
- return preferred2.find((signingAlg) => {
45056
+ var _a;
45057
+ return (_a = preferred2.find((signingAlg) => {
45097
45058
  return supported.includes(signingAlg);
45098
- }) ?? null;
45059
+ })) !== null && _a !== void 0 ? _a : null;
45099
45060
  }
45100
45061
  function isStaticClient(options) {
45101
45062
  return options.clientId !== void 0 && !isValidUrl(options.clientId);
@@ -45143,40 +45104,33 @@ _:patch
45143
45104
  }
45144
45105
  var boundFetch = (request2, init) => fetch(request2, init);
45145
45106
  var ClientAuthentication = class {
45146
- loginHandler;
45147
- redirectHandler;
45148
- logoutHandler;
45149
- sessionInfoManager;
45150
- issuerConfigFetcher;
45151
- boundLogout;
45152
45107
  constructor(loginHandler, redirectHandler, logoutHandler, sessionInfoManager, issuerConfigFetcher) {
45153
45108
  this.loginHandler = loginHandler;
45154
45109
  this.redirectHandler = redirectHandler;
45155
45110
  this.logoutHandler = logoutHandler;
45156
45111
  this.sessionInfoManager = sessionInfoManager;
45157
45112
  this.issuerConfigFetcher = issuerConfigFetcher;
45113
+ this.fetch = boundFetch;
45114
+ this.logout = async (sessionId, options) => {
45115
+ await this.logoutHandler.handle(sessionId, (options === null || options === void 0 ? void 0 : options.logoutType) === "idp" ? {
45116
+ ...options,
45117
+ toLogoutUrl: this.boundLogout
45118
+ } : options);
45119
+ this.fetch = boundFetch;
45120
+ delete this.boundLogout;
45121
+ };
45122
+ this.getSessionInfo = async (sessionId) => {
45123
+ return this.sessionInfoManager.get(sessionId);
45124
+ };
45125
+ this.getAllSessionInfo = async () => {
45126
+ return this.sessionInfoManager.getAll();
45127
+ };
45158
45128
  this.loginHandler = loginHandler;
45159
45129
  this.redirectHandler = redirectHandler;
45160
45130
  this.logoutHandler = logoutHandler;
45161
45131
  this.sessionInfoManager = sessionInfoManager;
45162
45132
  this.issuerConfigFetcher = issuerConfigFetcher;
45163
45133
  }
45164
- // By default, our fetch() resolves to the environment fetch() function.
45165
- fetch = boundFetch;
45166
- logout = async (sessionId, options) => {
45167
- await this.logoutHandler.handle(sessionId, options?.logoutType === "idp" ? {
45168
- ...options,
45169
- toLogoutUrl: this.boundLogout
45170
- } : options);
45171
- this.fetch = boundFetch;
45172
- delete this.boundLogout;
45173
- };
45174
- getSessionInfo = async (sessionId) => {
45175
- return this.sessionInfoManager.get(sessionId);
45176
- };
45177
- getAllSessionInfo = async () => {
45178
- return this.sessionInfoManager.getAll();
45179
- };
45180
45134
  };
45181
45135
  async function loadOidcContextFromStorage(sessionId, storageUtility, configFetcher) {
45182
45136
  try {
@@ -45224,8 +45178,6 @@ _:patch
45224
45178
  }
45225
45179
  }
45226
45180
  var StorageUtility = class {
45227
- secureStorage;
45228
- insecureStorage;
45229
45181
  constructor(secureStorage, insecureStorage) {
45230
45182
  this.secureStorage = secureStorage;
45231
45183
  this.insecureStorage = insecureStorage;
@@ -45250,26 +45202,26 @@ _:patch
45250
45202
  await (secure ? this.secureStorage : this.insecureStorage).set(this.getKey(userId), JSON.stringify(data2));
45251
45203
  }
45252
45204
  async get(key3, options) {
45253
- const value7 = await (options?.secure ? this.secureStorage : this.insecureStorage).get(key3);
45254
- if (value7 === void 0 && options?.errorIfNull) {
45205
+ const value7 = await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).get(key3);
45206
+ if (value7 === void 0 && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
45255
45207
  throw new Error(`[${key3}] is not stored`);
45256
45208
  }
45257
45209
  return value7;
45258
45210
  }
45259
45211
  async set(key3, value7, options) {
45260
- return (options?.secure ? this.secureStorage : this.insecureStorage).set(key3, value7);
45212
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).set(key3, value7);
45261
45213
  }
45262
45214
  async delete(key3, options) {
45263
- return (options?.secure ? this.secureStorage : this.insecureStorage).delete(key3);
45215
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(key3);
45264
45216
  }
45265
45217
  async getForUser(userId, key3, options) {
45266
- const userData = await this.getUserData(userId, options?.secure);
45218
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
45267
45219
  let value7;
45268
45220
  if (!userData || !userData[key3]) {
45269
45221
  value7 = void 0;
45270
45222
  }
45271
45223
  value7 = userData[key3];
45272
- if (value7 === void 0 && options?.errorIfNull) {
45224
+ if (value7 === void 0 && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
45273
45225
  throw new Error(`Field [${key3}] for user [${userId}] is not stored`);
45274
45226
  }
45275
45227
  return value7 || void 0;
@@ -45277,23 +45229,25 @@ _:patch
45277
45229
  async setForUser(userId, values2, options) {
45278
45230
  let userData;
45279
45231
  try {
45280
- userData = await this.getUserData(userId, options?.secure);
45281
- } catch {
45232
+ userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
45233
+ } catch (_a) {
45282
45234
  userData = {};
45283
45235
  }
45284
- await this.setUserData(userId, { ...userData, ...values2 }, options?.secure);
45236
+ await this.setUserData(userId, { ...userData, ...values2 }, options === null || options === void 0 ? void 0 : options.secure);
45285
45237
  }
45286
45238
  async deleteForUser(userId, key3, options) {
45287
- const userData = await this.getUserData(userId, options?.secure);
45239
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
45288
45240
  delete userData[key3];
45289
- await this.setUserData(userId, userData, options?.secure);
45241
+ await this.setUserData(userId, userData, options === null || options === void 0 ? void 0 : options.secure);
45290
45242
  }
45291
45243
  async deleteAllUserData(userId, options) {
45292
- await (options?.secure ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
45244
+ await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
45293
45245
  }
45294
45246
  };
45295
45247
  var InMemoryStorage = class {
45296
- map = {};
45248
+ constructor() {
45249
+ this.map = {};
45250
+ }
45297
45251
  async get(key3) {
45298
45252
  return this.map[key3] || void 0;
45299
45253
  }
@@ -45311,7 +45265,6 @@ _:patch
45311
45265
  }
45312
45266
  };
45313
45267
  var InvalidResponseError = class extends Error {
45314
- missingFields;
45315
45268
  /* istanbul ignore next */
45316
45269
  constructor(missingFields) {
45317
45270
  super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
@@ -45319,8 +45272,6 @@ _:patch
45319
45272
  }
45320
45273
  };
45321
45274
  var OidcProviderError = class extends Error {
45322
- error;
45323
- errorDescription;
45324
45275
  /* istanbul ignore next */
45325
45276
  constructor(message5, error4, errorDescription) {
45326
45277
  super(message5);
@@ -45357,9 +45308,10 @@ _:patch
45357
45308
  return [401, 403].includes(statusCode2);
45358
45309
  }
45359
45310
  async function buildDpopFetchOptions(targetUrl3, authToken, dpopKey, defaultOptions) {
45360
- const headers = new Headers(defaultOptions?.headers);
45311
+ var _a;
45312
+ const headers = new Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
45361
45313
  headers.set("Authorization", `DPoP ${authToken}`);
45362
- headers.set("DPoP", await createDpopHeader(targetUrl3, defaultOptions?.method ?? "get", dpopKey));
45314
+ headers.set("DPoP", await createDpopHeader(targetUrl3, (_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.method) !== null && _a !== void 0 ? _a : "get", dpopKey));
45363
45315
  return {
45364
45316
  ...defaultOptions,
45365
45317
  headers
@@ -45369,7 +45321,7 @@ _:patch
45369
45321
  if (dpopKey !== void 0) {
45370
45322
  return buildDpopFetchOptions(targetUrl3, authToken, dpopKey, defaultOptions);
45371
45323
  }
45372
- const headers = new Headers(defaultOptions?.headers);
45324
+ const headers = new Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
45373
45325
  headers.set("Authorization", `Bearer ${authToken}`);
45374
45326
  return {
45375
45327
  ...defaultOptions,
@@ -45380,8 +45332,12 @@ _:patch
45380
45332
  return fetch(url7, await buildAuthenticatedHeaders(url7.toString(), accessToken, dpopKey, defaultRequestInit));
45381
45333
  }
45382
45334
  async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
45335
+ var _a;
45383
45336
  const tokenSet = await refreshOptions.tokenRefresher.refresh(refreshOptions.sessionId, refreshOptions.refreshToken, dpopKey);
45384
- eventEmitter?.emit(EVENTS.SESSION_EXTENDED, tokenSet.expiresIn ?? DEFAULT_EXPIRATION_TIME_SECONDS);
45337
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.SESSION_EXTENDED, (_a = tokenSet.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_EXPIRATION_TIME_SECONDS);
45338
+ if (typeof tokenSet.refreshToken === "string") {
45339
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
45340
+ }
45385
45341
  return {
45386
45342
  accessToken: tokenSet.accessToken,
45387
45343
  refreshToken: tokenSet.refreshToken,
@@ -45397,12 +45353,14 @@ _:patch
45397
45353
  }
45398
45354
  return DEFAULT_EXPIRATION_TIME_SECONDS;
45399
45355
  };
45400
- function buildAuthenticatedFetch(accessToken, options) {
45356
+ async function buildAuthenticatedFetch(accessToken, options) {
45357
+ var _a;
45401
45358
  let currentAccessToken = accessToken;
45402
45359
  let latestTimeout;
45403
- const currentRefreshOptions = options?.refreshOptions;
45360
+ const currentRefreshOptions = options === null || options === void 0 ? void 0 : options.refreshOptions;
45404
45361
  if (currentRefreshOptions !== void 0) {
45405
45362
  const proactivelyRefreshToken = async () => {
45363
+ var _a2, _b, _c, _d;
45406
45364
  try {
45407
45365
  const { accessToken: refreshedAccessToken, refreshToken, expiresIn } = await refreshAccessToken(
45408
45366
  currentRefreshOptions,
@@ -45418,14 +45376,14 @@ _:patch
45418
45376
  }
45419
45377
  clearTimeout(latestTimeout);
45420
45378
  latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(expiresIn) * 1e3);
45421
- options.eventEmitter?.emit(EVENTS.TIMEOUT_SET, latestTimeout);
45379
+ (_a2 = options.eventEmitter) === null || _a2 === void 0 ? void 0 : _a2.emit(EVENTS.TIMEOUT_SET, latestTimeout);
45422
45380
  } catch (e) {
45423
45381
  if (e instanceof OidcProviderError) {
45424
- options?.eventEmitter?.emit(EVENTS.ERROR, e.error, e.errorDescription);
45425
- options?.eventEmitter?.emit(EVENTS.SESSION_EXPIRED);
45382
+ (_b = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(EVENTS.ERROR, e.error, e.errorDescription);
45383
+ (_c = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _c === void 0 ? void 0 : _c.emit(EVENTS.SESSION_EXPIRED);
45426
45384
  }
45427
45385
  if (e instanceof InvalidResponseError && e.missingFields.includes("access_token")) {
45428
- options?.eventEmitter?.emit(EVENTS.SESSION_EXPIRED);
45386
+ (_d = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _d === void 0 ? void 0 : _d.emit(EVENTS.SESSION_EXPIRED);
45429
45387
  }
45430
45388
  }
45431
45389
  };
@@ -45435,7 +45393,7 @@ _:patch
45435
45393
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45436
45394
  computeRefreshDelay(options.expiresIn) * 1e3
45437
45395
  );
45438
- options.eventEmitter?.emit(EVENTS.TIMEOUT_SET, latestTimeout);
45396
+ (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
45439
45397
  } else if (options !== void 0 && options.eventEmitter !== void 0) {
45440
45398
  const expirationTimeout = setTimeout(() => {
45441
45399
  options.eventEmitter.emit(EVENTS.SESSION_EXPIRED);
@@ -45443,13 +45401,13 @@ _:patch
45443
45401
  options.eventEmitter.emit(EVENTS.TIMEOUT_SET, expirationTimeout);
45444
45402
  }
45445
45403
  return async (url7, requestInit) => {
45446
- let response6 = await makeAuthenticatedRequest(currentAccessToken, url7, requestInit, options?.dpopKey);
45404
+ let response6 = await makeAuthenticatedRequest(currentAccessToken, url7, requestInit, options === null || options === void 0 ? void 0 : options.dpopKey);
45447
45405
  const failedButNotExpectedAuthError = !response6.ok && !isExpectedAuthError(response6.status);
45448
45406
  if (response6.ok || failedButNotExpectedAuthError) {
45449
45407
  return response6;
45450
45408
  }
45451
45409
  const hasBeenRedirected = response6.url !== url7;
45452
- if (hasBeenRedirected && options?.dpopKey !== void 0) {
45410
+ if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== void 0) {
45453
45411
  response6 = await makeAuthenticatedRequest(
45454
45412
  currentAccessToken,
45455
45413
  // Replace the original target IRI (`url`) by the redirection target
@@ -45494,17 +45452,11 @@ _:patch
45494
45452
  return native_default2.randomUUID();
45495
45453
  }
45496
45454
  options = options || {};
45497
- const rnds = options.random ?? options.rng?.() ?? rng2();
45498
- if (rnds.length < 16) {
45499
- throw new Error("Random bytes length must be >= 16");
45500
- }
45455
+ const rnds = options.random || (options.rng || rng2)();
45501
45456
  rnds[6] = rnds[6] & 15 | 64;
45502
45457
  rnds[8] = rnds[8] & 63 | 128;
45503
45458
  if (buf) {
45504
45459
  offset3 = offset3 || 0;
45505
- if (offset3 < 0 || offset3 + 16 > buf.length) {
45506
- throw new RangeError(`UUID byte range ${offset3}:${offset3 + 15} is out of buffer bounds`);
45507
- }
45508
45460
  for (let i = 0; i < 16; ++i) {
45509
45461
  buf[offset3 + i] = rnds[i];
45510
45462
  }
@@ -45521,32 +45473,27 @@ _:patch
45521
45473
  var import_oidc_client = __toESM(require_oidc_client_min());
45522
45474
  var import_oidc_client2 = __toESM(require_oidc_client_min());
45523
45475
  function processErrorResponse(responseBody, options) {
45476
+ var _a, _b, _c, _d;
45524
45477
  if (responseBody.error === "invalid_redirect_uri") {
45525
- throw new Error(`Dynamic client registration failed: the provided redirect uri [${options.redirectUrl?.toString()}] is invalid - ${responseBody.error_description ?? ""}`);
45478
+ throw new Error(`Dynamic client registration failed: the provided redirect uri [${(_a = options.redirectUrl) === null || _a === void 0 ? void 0 : _a.toString()}] is invalid - ${(_b = responseBody.error_description) !== null && _b !== void 0 ? _b : ""}`);
45526
45479
  }
45527
45480
  if (responseBody.error === "invalid_client_metadata") {
45528
- throw new Error(`Dynamic client registration failed: the provided client metadata ${JSON.stringify(options)} is invalid - ${responseBody.error_description ?? ""}`);
45481
+ throw new Error(`Dynamic client registration failed: the provided client metadata ${JSON.stringify(options)} is invalid - ${(_c = responseBody.error_description) !== null && _c !== void 0 ? _c : ""}`);
45529
45482
  }
45530
- throw new Error(`Dynamic client registration failed: ${responseBody.error} - ${responseBody.error_description ?? ""}`);
45531
- }
45532
- function hasClientId(body) {
45533
- return typeof body.client_id === "string";
45534
- }
45535
- function hasRedirectUri(body) {
45536
- return Array.isArray(body.redirect_uris) && body.redirect_uris.every((uri6) => typeof uri6 === "string");
45483
+ throw new Error(`Dynamic client registration failed: ${responseBody.error} - ${(_d = responseBody.error_description) !== null && _d !== void 0 ? _d : ""}`);
45537
45484
  }
45538
45485
  function validateRegistrationResponse(responseBody, options) {
45539
- if (!hasClientId(responseBody)) {
45486
+ if (responseBody.client_id === void 0) {
45540
45487
  throw new Error(`Dynamic client registration failed: no client_id has been found on ${JSON.stringify(responseBody)}`);
45541
45488
  }
45542
- if (options.redirectUrl && hasRedirectUri(responseBody) && responseBody.redirect_uris[0] !== options.redirectUrl.toString()) {
45489
+ if (options.redirectUrl && (responseBody.redirect_uris === void 0 || responseBody.redirect_uris[0] !== options.redirectUrl.toString())) {
45543
45490
  throw new Error(`Dynamic client registration failed: the returned redirect URIs ${JSON.stringify(responseBody.redirect_uris)} don't match the provided ${JSON.stringify([
45544
45491
  options.redirectUrl.toString()
45545
45492
  ])}`);
45546
45493
  }
45547
- return true;
45548
45494
  }
45549
45495
  async function registerClient(options, issuerConfig) {
45496
+ var _a;
45550
45497
  if (!issuerConfig.registrationEndpoint) {
45551
45498
  throw new Error("Dynamic Registration could not be completed because the issuer has no registration endpoint.");
45552
45499
  }
@@ -45558,7 +45505,7 @@ _:patch
45558
45505
  /* eslint-disable camelcase */
45559
45506
  client_name: options.clientName,
45560
45507
  application_type: "web",
45561
- redirect_uris: [options.redirectUrl?.toString()],
45508
+ redirect_uris: [(_a = options.redirectUrl) === null || _a === void 0 ? void 0 : _a.toString()],
45562
45509
  subject_type: "public",
45563
45510
  token_endpoint_auth_method: "client_secret_basic",
45564
45511
  id_token_signed_response_alg: signingAlg,
@@ -45579,7 +45526,6 @@ _:patch
45579
45526
  return {
45580
45527
  clientId: responseBody.client_id,
45581
45528
  clientSecret: responseBody.client_secret,
45582
- expiresAt: responseBody.client_secret_expires_at,
45583
45529
  idTokenSignedResponseAlg: responseBody.id_token_signed_response_alg,
45584
45530
  clientType: "dynamic"
45585
45531
  };
@@ -45687,7 +45633,7 @@ _:patch
45687
45633
  try {
45688
45634
  new URL(url7);
45689
45635
  return true;
45690
- } catch {
45636
+ } catch (_a) {
45691
45637
  return false;
45692
45638
  }
45693
45639
  };
@@ -45788,54 +45734,50 @@ _:patch
45788
45734
  }
45789
45735
  };
45790
45736
  var ClientAuthentication2 = class extends ClientAuthentication {
45791
- // Define these functions as properties so that they don't get accidentally re-bound.
45792
- // Isn't Javascript fun?
45793
- login = async (options, eventEmitter) => {
45794
- if (options.prompt !== "none") {
45737
+ constructor() {
45738
+ super(...arguments);
45739
+ this.login = async (options, eventEmitter) => {
45740
+ var _a, _b;
45795
45741
  await this.sessionInfoManager.clear(options.sessionId);
45796
- }
45797
- const redirectUrl = options.redirectUrl ?? normalizeCallbackUrl(window.location.href);
45798
- if (!isValidRedirectUrl(redirectUrl)) {
45799
- throw new Error(`${redirectUrl} is not a valid redirect URL, it is either a malformed IRI, includes a hash fragment, or reserved query parameters ('code' or 'state').`);
45800
- }
45801
- await this.loginHandler.handle({
45802
- ...options,
45803
- redirectUrl,
45804
- // If no clientName is provided, the clientId may be used instead.
45805
- clientName: options.clientName ?? options.clientId,
45806
- eventEmitter
45807
- });
45808
- };
45809
- // Collects session information from storage, and returns them. Returns null
45810
- // if the expected information cannot be found.
45811
- // Note that the ID token is not stored, which means the session information
45812
- // cannot be validated at this point.
45813
- validateCurrentSession = async (currentSessionId) => {
45814
- const sessionInfo = await this.sessionInfoManager.get(currentSessionId);
45815
- if (sessionInfo === void 0 || sessionInfo.clientAppId === void 0 || sessionInfo.issuer === void 0) {
45816
- return null;
45817
- }
45818
- return sessionInfo;
45819
- };
45820
- handleIncomingRedirect = async (url7, eventEmitter) => {
45821
- try {
45822
- const redirectInfo = await this.redirectHandler.handle(url7, eventEmitter, void 0);
45823
- this.fetch = redirectInfo.fetch.bind(window);
45824
- this.boundLogout = redirectInfo.getLogoutUrl;
45825
- await this.cleanUrlAfterRedirect(url7);
45826
- return {
45827
- isLoggedIn: redirectInfo.isLoggedIn,
45828
- webId: redirectInfo.webId,
45829
- sessionId: redirectInfo.sessionId,
45830
- expirationDate: redirectInfo.expirationDate,
45831
- clientAppId: redirectInfo.clientAppId
45832
- };
45833
- } catch (err) {
45834
- await this.cleanUrlAfterRedirect(url7);
45835
- eventEmitter.emit(EVENTS.ERROR, "redirect", err);
45836
- return void 0;
45837
- }
45838
- };
45742
+ const redirectUrl = (_a = options.redirectUrl) !== null && _a !== void 0 ? _a : normalizeCallbackUrl(window.location.href);
45743
+ if (!isValidRedirectUrl(redirectUrl)) {
45744
+ throw new Error(`${redirectUrl} is not a valid redirect URL, it is either a malformed IRI, includes a hash fragment, or reserved query parameters ('code' or 'state').`);
45745
+ }
45746
+ await this.loginHandler.handle({
45747
+ ...options,
45748
+ redirectUrl,
45749
+ // If no clientName is provided, the clientId may be used instead.
45750
+ clientName: (_b = options.clientName) !== null && _b !== void 0 ? _b : options.clientId,
45751
+ eventEmitter
45752
+ });
45753
+ };
45754
+ this.validateCurrentSession = async (currentSessionId) => {
45755
+ const sessionInfo = await this.sessionInfoManager.get(currentSessionId);
45756
+ if (sessionInfo === void 0 || sessionInfo.clientAppId === void 0 || sessionInfo.issuer === void 0) {
45757
+ return null;
45758
+ }
45759
+ return sessionInfo;
45760
+ };
45761
+ this.handleIncomingRedirect = async (url7, eventEmitter) => {
45762
+ try {
45763
+ const redirectInfo = await this.redirectHandler.handle(url7, eventEmitter, void 0);
45764
+ this.fetch = redirectInfo.fetch.bind(window);
45765
+ this.boundLogout = redirectInfo.getLogoutUrl;
45766
+ await this.cleanUrlAfterRedirect(url7);
45767
+ return {
45768
+ isLoggedIn: redirectInfo.isLoggedIn,
45769
+ webId: redirectInfo.webId,
45770
+ sessionId: redirectInfo.sessionId,
45771
+ expirationDate: redirectInfo.expirationDate,
45772
+ clientAppId: redirectInfo.clientAppId
45773
+ };
45774
+ } catch (err) {
45775
+ await this.cleanUrlAfterRedirect(url7);
45776
+ eventEmitter.emit(EVENTS.ERROR, "redirect", err);
45777
+ return void 0;
45778
+ }
45779
+ };
45780
+ }
45839
45781
  async cleanUrlAfterRedirect(url7) {
45840
45782
  const cleanedUpUrl = removeOpenIdParams(url7).href;
45841
45783
  window.history.replaceState(null, "", cleanedUpUrl);
@@ -45853,10 +45795,6 @@ _:patch
45853
45795
  return typeof options.redirectUrl === "string";
45854
45796
  }
45855
45797
  var OidcLoginHandler = class {
45856
- storageUtility;
45857
- oidcHandler;
45858
- issuerConfigFetcher;
45859
- clientRegistrar;
45860
45798
  constructor(storageUtility, oidcHandler, issuerConfigFetcher, clientRegistrar) {
45861
45799
  this.storageUtility = storageUtility;
45862
45800
  this.oidcHandler = oidcHandler;
@@ -45897,6 +45835,7 @@ _:patch
45897
45835
  };
45898
45836
  var AuthorizationCodeWithPkceOidcHandler = class extends AuthorizationCodeWithPkceOidcHandlerBase {
45899
45837
  async handle(oidcLoginOptions) {
45838
+ var _a;
45900
45839
  const oidcOptions = {
45901
45840
  authority: oidcLoginOptions.issuer.toString(),
45902
45841
  client_id: oidcLoginOptions.client.clientId,
@@ -45910,12 +45849,12 @@ _:patch
45910
45849
  // profile referenced by the WebId.
45911
45850
  loadUserInfo: false,
45912
45851
  code_verifier: true,
45913
- prompt: oidcLoginOptions.prompt ?? "consent"
45852
+ prompt: (_a = oidcLoginOptions.prompt) !== null && _a !== void 0 ? _a : "consent"
45914
45853
  };
45915
45854
  const oidcClientLibrary = new import_oidc_client2.OidcClient(oidcOptions);
45916
45855
  try {
45917
45856
  const signingRequest = await oidcClientLibrary.createSigninRequest();
45918
- return await this.setupRedirectHandler({
45857
+ return await this.handleRedirect({
45919
45858
  oidcLoginOptions,
45920
45859
  // eslint-disable-next-line no-underscore-dangle
45921
45860
  state: signingRequest.state._id,
@@ -46030,7 +45969,6 @@ _:patch
46030
45969
  return parsedConfig;
46031
45970
  }
46032
45971
  var IssuerConfigFetcher = class _IssuerConfigFetcher {
46033
- storageUtility;
46034
45972
  constructor(storageUtility) {
46035
45973
  this.storageUtility = storageUtility;
46036
45974
  this.storageUtility = storageUtility;
@@ -46113,7 +46051,7 @@ _:patch
46113
46051
  clientAppId: clientId,
46114
46052
  clientAppSecret: clientSecret,
46115
46053
  // Default the token type to DPoP if unspecified.
46116
- tokenType: tokenType ?? "DPoP"
46054
+ tokenType: tokenType !== null && tokenType !== void 0 ? tokenType : "DPoP"
46117
46055
  };
46118
46056
  }
46119
46057
  /**
@@ -46140,11 +46078,6 @@ _:patch
46140
46078
  }
46141
46079
  };
46142
46080
  var AuthCodeRedirectHandler = class {
46143
- storageUtility;
46144
- sessionInfoManager;
46145
- issuerConfigFetcher;
46146
- clientRegistrar;
46147
- tokerRefresher;
46148
46081
  constructor(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokerRefresher) {
46149
46082
  this.storageUtility = storageUtility;
46150
46083
  this.sessionInfoManager = sessionInfoManager;
@@ -46204,7 +46137,7 @@ _:patch
46204
46137
  tokenRefresher: this.tokerRefresher
46205
46138
  };
46206
46139
  }
46207
- const authFetch = buildAuthenticatedFetch(tokens.accessToken, {
46140
+ const authFetch = await buildAuthenticatedFetch(tokens.accessToken, {
46208
46141
  dpopKey: tokens.dpopKey,
46209
46142
  refreshOptions,
46210
46143
  eventEmitter,
@@ -46256,22 +46189,18 @@ _:patch
46256
46189
  }
46257
46190
  };
46258
46191
  var ClientRegistrar = class {
46259
- storageUtility;
46260
46192
  constructor(storageUtility) {
46261
46193
  this.storageUtility = storageUtility;
46262
46194
  this.storageUtility = storageUtility;
46263
46195
  }
46264
46196
  async getClient(options, issuerConfig) {
46265
- const [storedClientId, storedClientSecret, expiresAt, storedClientName, storedClientType] = await Promise.all([
46197
+ const [storedClientId, storedClientSecret, storedClientName, storedClientType] = await Promise.all([
46266
46198
  this.storageUtility.getForUser(options.sessionId, "clientId", {
46267
46199
  secure: false
46268
46200
  }),
46269
46201
  this.storageUtility.getForUser(options.sessionId, "clientSecret", {
46270
46202
  secure: false
46271
46203
  }),
46272
- this.storageUtility.getForUser(options.sessionId, "expiresAt", {
46273
- secure: false
46274
- }),
46275
46204
  this.storageUtility.getForUser(options.sessionId, "clientName", {
46276
46205
  secure: false
46277
46206
  }),
@@ -46279,22 +46208,13 @@ _:patch
46279
46208
  secure: false
46280
46209
  })
46281
46210
  ]);
46282
- const expirationDate2 = expiresAt !== void 0 ? Number.parseInt(expiresAt, 10) : -1;
46283
- const expired = storedClientSecret !== void 0 && Math.floor(Date.now() / 1e3) > expirationDate2;
46284
- if (storedClientId && isKnownClientType(storedClientType) && !expired) {
46285
- return storedClientSecret !== void 0 ? {
46211
+ if (storedClientId && isKnownClientType(storedClientType)) {
46212
+ return {
46286
46213
  clientId: storedClientId,
46287
46214
  clientSecret: storedClientSecret,
46288
46215
  clientName: storedClientName,
46289
46216
  // Note: static clients are not applicable in a browser context.
46290
- clientType: "dynamic",
46291
- expiresAt: expirationDate2
46292
- } : {
46293
- clientId: storedClientId,
46294
- clientName: storedClientName,
46295
- // Note: static clients are not applicable in a browser context.
46296
46217
  clientType: storedClientType
46297
- // The type assertion is required even though the type should match the declaration.
46298
46218
  };
46299
46219
  }
46300
46220
  try {
@@ -46303,9 +46223,8 @@ _:patch
46303
46223
  clientId: registeredClient.clientId,
46304
46224
  clientType: "dynamic"
46305
46225
  };
46306
- if (registeredClient.clientSecret !== void 0) {
46226
+ if (registeredClient.clientSecret) {
46307
46227
  infoToSave.clientSecret = registeredClient.clientSecret;
46308
- infoToSave.expiresAt = String(registeredClient.expiresAt);
46309
46228
  }
46310
46229
  if (registeredClient.idTokenSignedResponseAlg) {
46311
46230
  infoToSave.idTokenSignedResponseAlg = registeredClient.idTokenSignedResponseAlg;
@@ -46318,7 +46237,7 @@ _:patch
46318
46237
  });
46319
46238
  return registeredClient;
46320
46239
  } catch (error4) {
46321
- throw new Error(`Client registration failed.`, { cause: error4 });
46240
+ throw new Error(`Client registration failed: [${error4}]`);
46322
46241
  }
46323
46242
  }
46324
46243
  };
@@ -46341,9 +46260,6 @@ _:patch
46341
46260
  }
46342
46261
  };
46343
46262
  var TokenRefresher = class {
46344
- storageUtility;
46345
- issuerConfigFetcher;
46346
- clientRegistrar;
46347
46263
  constructor(storageUtility, issuerConfigFetcher, clientRegistrar) {
46348
46264
  this.storageUtility = storageUtility;
46349
46265
  this.issuerConfigFetcher = issuerConfigFetcher;
@@ -46363,7 +46279,7 @@ _:patch
46363
46279
  }
46364
46280
  const tokenSet = await refresh(refreshToken, oidcContext.issuerConfig, clientInfo, dpopKey);
46365
46281
  if (tokenSet.refreshToken !== void 0) {
46366
- eventEmitter?.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
46282
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
46367
46283
  }
46368
46284
  return tokenSet;
46369
46285
  }
@@ -46391,6 +46307,7 @@ _:patch
46391
46307
  var KEY_CURRENT_SESSION = `${SOLID_CLIENT_AUTHN_KEY_PREFIX}currentSession`;
46392
46308
  var KEY_CURRENT_URL = `${SOLID_CLIENT_AUTHN_KEY_PREFIX}currentUrl`;
46393
46309
  async function silentlyAuthenticate(sessionId, clientAuthn, session4) {
46310
+ var _a;
46394
46311
  const storedSessionInfo = await clientAuthn.validateCurrentSession(sessionId);
46395
46312
  if (storedSessionInfo !== null) {
46396
46313
  window.localStorage.setItem(KEY_CURRENT_URL, window.location.href);
@@ -46401,28 +46318,16 @@ _:patch
46401
46318
  redirectUrl: storedSessionInfo.redirectUrl,
46402
46319
  clientId: storedSessionInfo.clientAppId,
46403
46320
  clientSecret: storedSessionInfo.clientAppSecret,
46404
- tokenType: storedSessionInfo.tokenType ?? "DPoP"
46321
+ tokenType: (_a = storedSessionInfo.tokenType) !== null && _a !== void 0 ? _a : "DPoP"
46405
46322
  }, session4.events);
46406
46323
  return true;
46407
46324
  }
46408
46325
  return false;
46409
46326
  }
46410
46327
  function isLoggedIn(sessionInfo) {
46411
- return !!sessionInfo?.isLoggedIn;
46328
+ return !!(sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.isLoggedIn);
46412
46329
  }
46413
46330
  var Session = class {
46414
- /**
46415
- * Information regarding the current session.
46416
- */
46417
- info;
46418
- /**
46419
- * Session attribute exposing the EventEmitter interface, to listen on session
46420
- * events such as login, logout, etc.
46421
- * @since 1.15.0
46422
- */
46423
- events;
46424
- clientAuthentication;
46425
- tokenRequestInProgress = false;
46426
46331
  /**
46427
46332
  * Session object constructor. Typically called as follows:
46428
46333
  *
@@ -46439,6 +46344,62 @@ _:patch
46439
46344
  *
46440
46345
  */
46441
46346
  constructor(sessionOptions = {}, sessionId = void 0) {
46347
+ this.tokenRequestInProgress = false;
46348
+ this.login = async (options) => {
46349
+ var _a;
46350
+ await this.clientAuthentication.login({
46351
+ sessionId: this.info.sessionId,
46352
+ ...options,
46353
+ // Defaults the token type to DPoP
46354
+ tokenType: (_a = options.tokenType) !== null && _a !== void 0 ? _a : "DPoP"
46355
+ }, this.events);
46356
+ return new Promise(() => {
46357
+ });
46358
+ };
46359
+ this.fetch = (url7, init) => this.clientAuthentication.fetch(url7, init);
46360
+ this.internalLogout = async (emitSignal, options) => {
46361
+ window.localStorage.removeItem(KEY_CURRENT_SESSION);
46362
+ await this.clientAuthentication.logout(this.info.sessionId, options);
46363
+ this.info.isLoggedIn = false;
46364
+ if (emitSignal) {
46365
+ this.events.emit(EVENTS.LOGOUT);
46366
+ }
46367
+ };
46368
+ this.logout = async (options) => this.internalLogout(true, options);
46369
+ this.handleIncomingRedirect = async (inputOptions = {}) => {
46370
+ var _a;
46371
+ if (this.info.isLoggedIn) {
46372
+ return this.info;
46373
+ }
46374
+ if (this.tokenRequestInProgress) {
46375
+ return void 0;
46376
+ }
46377
+ const options = typeof inputOptions === "string" ? { url: inputOptions } : inputOptions;
46378
+ const url7 = (_a = options.url) !== null && _a !== void 0 ? _a : window.location.href;
46379
+ this.tokenRequestInProgress = true;
46380
+ const sessionInfo = await this.clientAuthentication.handleIncomingRedirect(url7, this.events);
46381
+ if (isLoggedIn(sessionInfo)) {
46382
+ this.setSessionInfo(sessionInfo);
46383
+ const currentUrl = window.localStorage.getItem(KEY_CURRENT_URL);
46384
+ if (currentUrl === null) {
46385
+ this.events.emit(EVENTS.LOGIN);
46386
+ } else {
46387
+ window.localStorage.removeItem(KEY_CURRENT_URL);
46388
+ this.events.emit(EVENTS.SESSION_RESTORED, currentUrl);
46389
+ }
46390
+ } else if (options.restorePreviousSession === true) {
46391
+ const storedSessionId = window.localStorage.getItem(KEY_CURRENT_SESSION);
46392
+ if (storedSessionId !== null) {
46393
+ const attemptedSilentAuthentication = await silentlyAuthenticate(storedSessionId, this.clientAuthentication, this);
46394
+ if (attemptedSilentAuthentication) {
46395
+ return new Promise(() => {
46396
+ });
46397
+ }
46398
+ }
46399
+ }
46400
+ this.tokenRequestInProgress = false;
46401
+ return sessionInfo;
46402
+ };
46442
46403
  this.events = new import_events.default();
46443
46404
  if (sessionOptions.clientAuthentication) {
46444
46405
  this.clientAuthentication = sessionOptions.clientAuthentication;
@@ -46459,7 +46420,7 @@ _:patch
46459
46420
  };
46460
46421
  } else {
46461
46422
  this.info = {
46462
- sessionId: sessionId ?? v4_default2(),
46423
+ sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : v4_default2(),
46463
46424
  isLoggedIn: false
46464
46425
  };
46465
46426
  }
@@ -46467,123 +46428,6 @@ _:patch
46467
46428
  this.events.on(EVENTS.SESSION_EXPIRED, () => this.internalLogout(false));
46468
46429
  this.events.on(EVENTS.ERROR, () => this.internalLogout(false));
46469
46430
  }
46470
- /**
46471
- * Triggers the login process. Note that this method will redirect the user away from your app.
46472
- *
46473
- * @param options Parameter to customize the login behaviour. In particular, two options are mandatory: `options.oidcIssuer`, the user's identity provider, and `options.redirectUrl`, the URL to which the user will be redirected after logging in their identity provider.
46474
- * @returns This method should redirect the user away from the app: it does not return anything. The login process is completed by {@linkcode handleIncomingRedirect}.
46475
- */
46476
- // Define these functions as properties so that they don't get accidentally re-bound.
46477
- // Isn't Javascript fun?
46478
- login = async (options) => {
46479
- await this.clientAuthentication.login({
46480
- sessionId: this.info.sessionId,
46481
- ...options,
46482
- // Defaults the token type to DPoP
46483
- tokenType: options.tokenType ?? "DPoP"
46484
- }, this.events);
46485
- return new Promise(() => {
46486
- });
46487
- };
46488
- /**
46489
- * Fetches data using available login information. If the user is not logged in, this will behave as a regular `fetch`. The signature of this method is identical to the [canonical `fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
46490
- *
46491
- * @param url The URL from which data should be fetched.
46492
- * @param init Optional parameters customizing the request, by specifying an HTTP method, headers, a body, etc. Follows the [WHATWG Fetch Standard](https://fetch.spec.whatwg.org/).
46493
- */
46494
- fetch = (url7, init) => this.clientAuthentication.fetch(url7, init);
46495
- /**
46496
- * An internal logout function, to control whether or not the logout signal
46497
- * should be sent, i.e. if the logout was user-initiated or is the result of
46498
- * an external event.
46499
- *
46500
- * @hidden
46501
- */
46502
- internalLogout = async (emitSignal, options) => {
46503
- window.localStorage.removeItem(KEY_CURRENT_SESSION);
46504
- await this.clientAuthentication.logout(this.info.sessionId, options);
46505
- this.info.isLoggedIn = false;
46506
- if (emitSignal) {
46507
- this.events.emit(EVENTS.LOGOUT);
46508
- }
46509
- };
46510
- /**
46511
- * Logs the user out of the application.
46512
- *
46513
- * There are 2 types of logout supported by this library,
46514
- * `app` logout and `idp` logout.
46515
- *
46516
- * App logout will log the user out within the application
46517
- * by clearing any session data from the browser. It does
46518
- * not log the user out of their Solid identity provider,
46519
- * and should not redirect the user away.
46520
- * App logout can be performed as follows:
46521
- * ```typescript
46522
- * await session.logout({ logoutType: 'app' });
46523
- * ```
46524
- *
46525
- * IDP logout will log the user out of their Solid identity provider,
46526
- * and will redirect the user away from the application to do so. In order
46527
- * for users to be redirected back to `postLogoutUrl` you MUST include the
46528
- * `postLogoutUrl` value in the `post_logout_redirect_uris` field in the
46529
- * [Client ID Document](https://docs.inrupt.com/ess/latest/security/authentication/#client-identifier-client-id).
46530
- * IDP logout can be performed as follows:
46531
- * ```typescript
46532
- * await session.logout({
46533
- * logoutType: 'idp',
46534
- * // An optional URL to redirect to after logout has completed;
46535
- * // this MUST match a logout URL listed in the Client ID Document
46536
- * // of the application that is logged in.
46537
- * // If the application is logged in with a Client ID that is not
46538
- * // a URI dereferencing to a Client ID Document then users will
46539
- * // not be redirected back to the `postLogoutUrl` after logout.
46540
- * postLogoutUrl: 'https://example.com/logout',
46541
- * // An optional value to be included in the query parameters
46542
- * // when the IDP provider redirects the user to the postLogoutRedirectUrl.
46543
- * state: "my-state"
46544
- * });
46545
- * ```
46546
- */
46547
- logout = async (options) => this.internalLogout(true, options);
46548
- /**
46549
- * Completes the login process by processing the information provided by the
46550
- * Solid identity provider through redirect.
46551
- *
46552
- * @param options See {@link IHandleIncomingRedirectOptions}.
46553
- */
46554
- handleIncomingRedirect = async (inputOptions = {}) => {
46555
- if (this.info.isLoggedIn) {
46556
- return this.info;
46557
- }
46558
- if (this.tokenRequestInProgress) {
46559
- return void 0;
46560
- }
46561
- const options = typeof inputOptions === "string" ? { url: inputOptions } : inputOptions;
46562
- const url7 = options.url ?? window.location.href;
46563
- this.tokenRequestInProgress = true;
46564
- const sessionInfo = await this.clientAuthentication.handleIncomingRedirect(url7, this.events);
46565
- if (isLoggedIn(sessionInfo)) {
46566
- this.setSessionInfo(sessionInfo);
46567
- const currentUrl = window.localStorage.getItem(KEY_CURRENT_URL);
46568
- if (currentUrl === null) {
46569
- this.events.emit(EVENTS.LOGIN);
46570
- } else {
46571
- window.localStorage.removeItem(KEY_CURRENT_URL);
46572
- this.events.emit(EVENTS.SESSION_RESTORED, currentUrl);
46573
- }
46574
- } else if (options.restorePreviousSession === true) {
46575
- const storedSessionId = window.localStorage.getItem(KEY_CURRENT_SESSION);
46576
- if (storedSessionId !== null) {
46577
- const attemptedSilentAuthentication = await silentlyAuthenticate(storedSessionId, this.clientAuthentication, this);
46578
- if (attemptedSilentAuthentication) {
46579
- return new Promise(() => {
46580
- });
46581
- }
46582
- }
46583
- }
46584
- this.tokenRequestInProgress = false;
46585
- return sessionInfo;
46586
- };
46587
46431
  setSessionInfo(sessionInfo) {
46588
46432
  this.info.isLoggedIn = sessionInfo.isLoggedIn;
46589
46433
  this.info.webId = sessionInfo.webId;