@pod-os/core 0.16.1-rc.bdd004d.0 → 0.16.2-rc.2f9e99a.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.
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/dist/index.js CHANGED
@@ -10372,11 +10372,6 @@ function checkSigCryptoKey(key3, alg, ...usages) {
10372
10372
  }
10373
10373
  break;
10374
10374
  }
10375
- case "Ed25519": {
10376
- if (!isAlgorithm(key3.algorithm, "Ed25519"))
10377
- throw unusable("Ed25519");
10378
- break;
10379
- }
10380
10375
  case "ES256":
10381
10376
  case "ES384":
10382
10377
  case "ES512": {
@@ -10560,10 +10555,6 @@ function subtleMapping(jwk) {
10560
10555
  }
10561
10556
  case "OKP": {
10562
10557
  switch (jwk.alg) {
10563
- case "Ed25519":
10564
- algorithm3 = { name: "Ed25519" };
10565
- keyUsages = jwk.d ? ["sign"] : ["verify"];
10566
- break;
10567
10558
  case "EdDSA":
10568
10559
  algorithm3 = { name: jwk.crv };
10569
10560
  keyUsages = jwk.d ? ["sign"] : ["verify"];
@@ -10681,7 +10672,7 @@ async function importJWK(jwk, alg) {
10681
10672
  }
10682
10673
  return decode(jwk.k);
10683
10674
  case "RSA":
10684
- if ("oth" in jwk && jwk.oth !== void 0) {
10675
+ if (jwk.oth !== void 0) {
10685
10676
  throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
10686
10677
  }
10687
10678
  case "EC":
@@ -10852,8 +10843,6 @@ function subtleDsa(alg, algorithm3) {
10852
10843
  case "ES384":
10853
10844
  case "ES512":
10854
10845
  return { hash: hash2, name: "ECDSA", namedCurve: algorithm3.namedCurve };
10855
- case "Ed25519":
10856
- return { name: "Ed25519" };
10857
10846
  case "EdDSA":
10858
10847
  return { name: algorithm3.name };
10859
10848
  default:
@@ -11427,6 +11416,9 @@ var LocalJWKSet = class {
11427
11416
  if (candidate4 && Array.isArray(jwk2.key_ops)) {
11428
11417
  candidate4 = jwk2.key_ops.includes("verify");
11429
11418
  }
11419
+ if (candidate4 && alg === "EdDSA") {
11420
+ candidate4 = jwk2.crv === "Ed25519" || jwk2.crv === "Ed448";
11421
+ }
11430
11422
  if (candidate4) {
11431
11423
  switch (alg) {
11432
11424
  case "ES256":
@@ -11441,12 +11433,6 @@ var LocalJWKSet = class {
11441
11433
  case "ES512":
11442
11434
  candidate4 = jwk2.crv === "P-521";
11443
11435
  break;
11444
- case "Ed25519":
11445
- candidate4 = jwk2.crv === "Ed25519";
11446
- break;
11447
- case "EdDSA":
11448
- candidate4 = jwk2.crv === "Ed25519" || jwk2.crv === "Ed448";
11449
- break;
11450
11436
  }
11451
11437
  }
11452
11438
  return candidate4;
@@ -11537,7 +11523,7 @@ function isCloudflareWorkers() {
11537
11523
  var USER_AGENT;
11538
11524
  if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
11539
11525
  const NAME = "jose";
11540
- const VERSION = "v5.10.0";
11526
+ const VERSION = "v5.9.6";
11541
11527
  USER_AGENT = `${NAME}/${VERSION}`;
11542
11528
  }
11543
11529
  var jwksCache = Symbol();
@@ -11710,10 +11696,6 @@ async function generateKeyPair(alg, options) {
11710
11696
  algorithm3 = { name: "ECDSA", namedCurve: "P-521" };
11711
11697
  keyUsages = ["sign", "verify"];
11712
11698
  break;
11713
- case "Ed25519":
11714
- algorithm3 = { name: "Ed25519" };
11715
- keyUsages = ["sign", "verify"];
11716
- break;
11717
11699
  case "EdDSA": {
11718
11700
  keyUsages = ["sign", "verify"];
11719
11701
  const crv = options?.crv ?? "Ed25519";
@@ -11792,17 +11774,11 @@ function v4(options, buf, offset3) {
11792
11774
  return native_default.randomUUID();
11793
11775
  }
11794
11776
  options = options || {};
11795
- const rnds = options.random ?? options.rng?.() ?? rng();
11796
- if (rnds.length < 16) {
11797
- throw new Error("Random bytes length must be >= 16");
11798
- }
11777
+ const rnds = options.random || (options.rng || rng)();
11799
11778
  rnds[6] = rnds[6] & 15 | 64;
11800
11779
  rnds[8] = rnds[8] & 63 | 128;
11801
11780
  if (buf) {
11802
11781
  offset3 = offset3 || 0;
11803
- if (offset3 < 0 || offset3 + 16 > buf.length) {
11804
- throw new RangeError(`UUID byte range ${offset3}:${offset3 + 15} is out of buffer bounds`);
11805
- }
11806
11782
  for (let i = 0; i < 16; ++i) {
11807
11783
  buf[offset3 + i] = rnds[i];
11808
11784
  }
@@ -11821,8 +11797,6 @@ var EVENTS = {
11821
11797
  LOGIN: "login",
11822
11798
  LOGOUT: "logout",
11823
11799
  NEW_REFRESH_TOKEN: "newRefreshToken",
11824
- NEW_TOKENS: "newTokens",
11825
- AUTHORIZATION_REQUEST: "authorizationRequest",
11826
11800
  SESSION_EXPIRED: "sessionExpired",
11827
11801
  SESSION_EXTENDED: "sessionExtended",
11828
11802
  SESSION_RESTORED: "sessionRestore",
@@ -11834,7 +11808,6 @@ var SCOPE_OFFLINE = "offline_access";
11834
11808
  var SCOPE_WEBID = "webid";
11835
11809
  var DEFAULT_SCOPES = [SCOPE_OPENID, SCOPE_OFFLINE, SCOPE_WEBID].join(" ");
11836
11810
  var AggregateHandler = class {
11837
- handleables;
11838
11811
  constructor(handleables) {
11839
11812
  this.handleables = handleables;
11840
11813
  this.handleables = handleables;
@@ -11930,21 +11903,19 @@ function booleanWithFallback(value7, fallback) {
11930
11903
  return Boolean(fallback);
11931
11904
  }
11932
11905
  var AuthorizationCodeWithPkceOidcHandlerBase = class {
11933
- storageUtility;
11934
- redirector;
11935
11906
  constructor(storageUtility, redirector) {
11936
11907
  this.storageUtility = storageUtility;
11937
11908
  this.redirector = redirector;
11909
+ this.parametersGuard = (oidcLoginOptions) => {
11910
+ return oidcLoginOptions.issuerConfiguration.grantTypesSupported !== void 0 && oidcLoginOptions.issuerConfiguration.grantTypesSupported.indexOf("authorization_code") > -1 && oidcLoginOptions.redirectUrl !== void 0;
11911
+ };
11938
11912
  this.storageUtility = storageUtility;
11939
11913
  this.redirector = redirector;
11940
11914
  }
11941
- parametersGuard = (oidcLoginOptions) => {
11942
- return oidcLoginOptions.issuerConfiguration.grantTypesSupported !== void 0 && oidcLoginOptions.issuerConfiguration.grantTypesSupported.indexOf("authorization_code") > -1 && oidcLoginOptions.redirectUrl !== void 0;
11943
- };
11944
11915
  async canHandle(oidcLoginOptions) {
11945
11916
  return this.parametersGuard(oidcLoginOptions);
11946
11917
  }
11947
- async setupRedirectHandler({ oidcLoginOptions, state: state2, codeVerifier, targetUrl: targetUrl3 }) {
11918
+ async handleRedirect({ oidcLoginOptions, state: state2, codeVerifier, targetUrl: targetUrl3 }) {
11948
11919
  if (!this.parametersGuard(oidcLoginOptions)) {
11949
11920
  throw new Error("The authorization code grant requires a redirectUrl.");
11950
11921
  }
@@ -11981,7 +11952,6 @@ var AuthorizationCodeWithPkceOidcHandlerBase = class {
11981
11952
  }
11982
11953
  };
11983
11954
  var GeneralLogoutHandler = class {
11984
- sessionInfoManager;
11985
11955
  constructor(sessionInfoManager) {
11986
11956
  this.sessionInfoManager = sessionInfoManager;
11987
11957
  this.sessionInfoManager = sessionInfoManager;
@@ -11994,16 +11964,15 @@ var GeneralLogoutHandler = class {
11994
11964
  }
11995
11965
  };
11996
11966
  var IRpLogoutHandler = class {
11997
- redirector;
11998
11967
  constructor(redirector) {
11999
11968
  this.redirector = redirector;
12000
11969
  this.redirector = redirector;
12001
11970
  }
12002
11971
  async canHandle(userId, options) {
12003
- return options?.logoutType === "idp";
11972
+ return (options === null || options === void 0 ? void 0 : options.logoutType) === "idp";
12004
11973
  }
12005
11974
  async handle(userId, options) {
12006
- if (options?.logoutType !== "idp") {
11975
+ if ((options === null || options === void 0 ? void 0 : options.logoutType) !== "idp") {
12007
11976
  throw new Error("Attempting to call idp logout handler to perform app logout");
12008
11977
  }
12009
11978
  if (options.toLogoutUrl === void 0) {
@@ -12015,7 +11984,6 @@ var IRpLogoutHandler = class {
12015
11984
  }
12016
11985
  };
12017
11986
  var IWaterfallLogoutHandler = class {
12018
- handlers;
12019
11987
  constructor(sessionInfoManager, redirector) {
12020
11988
  this.handlers = [
12021
11989
  new GeneralLogoutHandler(sessionInfoManager),
@@ -12046,7 +12014,6 @@ async function clear(sessionId, storage2) {
12046
12014
  ]);
12047
12015
  }
12048
12016
  var SessionInfoManagerBase = class {
12049
- storageUtility;
12050
12017
  constructor(storageUtility) {
12051
12018
  this.storageUtility = storageUtility;
12052
12019
  this.storageUtility = storageUtility;
@@ -12054,9 +12021,6 @@ var SessionInfoManagerBase = class {
12054
12021
  update(_sessionId, _options) {
12055
12022
  throw new Error("Not Implemented");
12056
12023
  }
12057
- set(_sessionId, _sessionInfo) {
12058
- throw new Error("Not Implemented");
12059
- }
12060
12024
  get(_) {
12061
12025
  throw new Error("Not implemented");
12062
12026
  }
@@ -12067,6 +12031,7 @@ var SessionInfoManagerBase = class {
12067
12031
  /**
12068
12032
  * This function removes all session-related information from storage.
12069
12033
  * @param sessionId the session identifier
12034
+ * @param storage the storage where session info is stored
12070
12035
  * @hidden
12071
12036
  */
12072
12037
  async clear(sessionId) {
@@ -12074,6 +12039,7 @@ var SessionInfoManagerBase = class {
12074
12039
  }
12075
12040
  /**
12076
12041
  * Registers a new session, so that its ID can be retrieved.
12042
+ * @param sessionId
12077
12043
  */
12078
12044
  async register(_sessionId) {
12079
12045
  throw new Error("Not implemented");
@@ -12091,12 +12057,6 @@ var SessionInfoManagerBase = class {
12091
12057
  async clearAll() {
12092
12058
  throw new Error("Not implemented");
12093
12059
  }
12094
- /**
12095
- * Sets authorization request state in storage for a given session ID.
12096
- */
12097
- async setOidcContext(_sessionId, _authorizationRequestState) {
12098
- throw new Error("Not implemented");
12099
- }
12100
12060
  };
12101
12061
  function getEndSessionUrl({ endSessionEndpoint, idTokenHint, postLogoutRedirectUri, state: state2 }) {
12102
12062
  const url7 = new URL(endSessionEndpoint);
@@ -12128,14 +12088,15 @@ function isValidUrl(url7) {
12128
12088
  try {
12129
12089
  new URL(url7);
12130
12090
  return true;
12131
- } catch {
12091
+ } catch (_a) {
12132
12092
  return false;
12133
12093
  }
12134
12094
  }
12135
12095
  function determineSigningAlg(supported, preferred2) {
12136
- return preferred2.find((signingAlg) => {
12096
+ var _a;
12097
+ return (_a = preferred2.find((signingAlg) => {
12137
12098
  return supported.includes(signingAlg);
12138
- }) ?? null;
12099
+ })) !== null && _a !== void 0 ? _a : null;
12139
12100
  }
12140
12101
  function isStaticClient(options) {
12141
12102
  return options.clientId !== void 0 && !isValidUrl(options.clientId);
@@ -12183,40 +12144,33 @@ async function handleRegistration(options, issuerConfig, storageUtility, clientR
12183
12144
  }
12184
12145
  var boundFetch = (request2, init) => fetch(request2, init);
12185
12146
  var ClientAuthentication = class {
12186
- loginHandler;
12187
- redirectHandler;
12188
- logoutHandler;
12189
- sessionInfoManager;
12190
- issuerConfigFetcher;
12191
- boundLogout;
12192
12147
  constructor(loginHandler, redirectHandler, logoutHandler, sessionInfoManager, issuerConfigFetcher) {
12193
12148
  this.loginHandler = loginHandler;
12194
12149
  this.redirectHandler = redirectHandler;
12195
12150
  this.logoutHandler = logoutHandler;
12196
12151
  this.sessionInfoManager = sessionInfoManager;
12197
12152
  this.issuerConfigFetcher = issuerConfigFetcher;
12153
+ this.fetch = boundFetch;
12154
+ this.logout = async (sessionId, options) => {
12155
+ await this.logoutHandler.handle(sessionId, (options === null || options === void 0 ? void 0 : options.logoutType) === "idp" ? {
12156
+ ...options,
12157
+ toLogoutUrl: this.boundLogout
12158
+ } : options);
12159
+ this.fetch = boundFetch;
12160
+ delete this.boundLogout;
12161
+ };
12162
+ this.getSessionInfo = async (sessionId) => {
12163
+ return this.sessionInfoManager.get(sessionId);
12164
+ };
12165
+ this.getAllSessionInfo = async () => {
12166
+ return this.sessionInfoManager.getAll();
12167
+ };
12198
12168
  this.loginHandler = loginHandler;
12199
12169
  this.redirectHandler = redirectHandler;
12200
12170
  this.logoutHandler = logoutHandler;
12201
12171
  this.sessionInfoManager = sessionInfoManager;
12202
12172
  this.issuerConfigFetcher = issuerConfigFetcher;
12203
12173
  }
12204
- // By default, our fetch() resolves to the environment fetch() function.
12205
- fetch = boundFetch;
12206
- logout = async (sessionId, options) => {
12207
- await this.logoutHandler.handle(sessionId, options?.logoutType === "idp" ? {
12208
- ...options,
12209
- toLogoutUrl: this.boundLogout
12210
- } : options);
12211
- this.fetch = boundFetch;
12212
- delete this.boundLogout;
12213
- };
12214
- getSessionInfo = async (sessionId) => {
12215
- return this.sessionInfoManager.get(sessionId);
12216
- };
12217
- getAllSessionInfo = async () => {
12218
- return this.sessionInfoManager.getAll();
12219
- };
12220
12174
  };
12221
12175
  async function loadOidcContextFromStorage(sessionId, storageUtility, configFetcher) {
12222
12176
  try {
@@ -12264,8 +12218,6 @@ async function saveSessionInfoToStorage(storageUtility, sessionId, webId, client
12264
12218
  }
12265
12219
  }
12266
12220
  var StorageUtility = class {
12267
- secureStorage;
12268
- insecureStorage;
12269
12221
  constructor(secureStorage, insecureStorage) {
12270
12222
  this.secureStorage = secureStorage;
12271
12223
  this.insecureStorage = insecureStorage;
@@ -12290,26 +12242,26 @@ var StorageUtility = class {
12290
12242
  await (secure ? this.secureStorage : this.insecureStorage).set(this.getKey(userId), JSON.stringify(data2));
12291
12243
  }
12292
12244
  async get(key3, options) {
12293
- const value7 = await (options?.secure ? this.secureStorage : this.insecureStorage).get(key3);
12294
- if (value7 === void 0 && options?.errorIfNull) {
12245
+ const value7 = await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).get(key3);
12246
+ if (value7 === void 0 && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
12295
12247
  throw new Error(`[${key3}] is not stored`);
12296
12248
  }
12297
12249
  return value7;
12298
12250
  }
12299
12251
  async set(key3, value7, options) {
12300
- return (options?.secure ? this.secureStorage : this.insecureStorage).set(key3, value7);
12252
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).set(key3, value7);
12301
12253
  }
12302
12254
  async delete(key3, options) {
12303
- return (options?.secure ? this.secureStorage : this.insecureStorage).delete(key3);
12255
+ return ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(key3);
12304
12256
  }
12305
12257
  async getForUser(userId, key3, options) {
12306
- const userData = await this.getUserData(userId, options?.secure);
12258
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
12307
12259
  let value7;
12308
12260
  if (!userData || !userData[key3]) {
12309
12261
  value7 = void 0;
12310
12262
  }
12311
12263
  value7 = userData[key3];
12312
- if (value7 === void 0 && options?.errorIfNull) {
12264
+ if (value7 === void 0 && (options === null || options === void 0 ? void 0 : options.errorIfNull)) {
12313
12265
  throw new Error(`Field [${key3}] for user [${userId}] is not stored`);
12314
12266
  }
12315
12267
  return value7 || void 0;
@@ -12317,23 +12269,25 @@ var StorageUtility = class {
12317
12269
  async setForUser(userId, values2, options) {
12318
12270
  let userData;
12319
12271
  try {
12320
- userData = await this.getUserData(userId, options?.secure);
12321
- } catch {
12272
+ userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
12273
+ } catch (_a) {
12322
12274
  userData = {};
12323
12275
  }
12324
- await this.setUserData(userId, { ...userData, ...values2 }, options?.secure);
12276
+ await this.setUserData(userId, { ...userData, ...values2 }, options === null || options === void 0 ? void 0 : options.secure);
12325
12277
  }
12326
12278
  async deleteForUser(userId, key3, options) {
12327
- const userData = await this.getUserData(userId, options?.secure);
12279
+ const userData = await this.getUserData(userId, options === null || options === void 0 ? void 0 : options.secure);
12328
12280
  delete userData[key3];
12329
- await this.setUserData(userId, userData, options?.secure);
12281
+ await this.setUserData(userId, userData, options === null || options === void 0 ? void 0 : options.secure);
12330
12282
  }
12331
12283
  async deleteAllUserData(userId, options) {
12332
- await (options?.secure ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
12284
+ await ((options === null || options === void 0 ? void 0 : options.secure) ? this.secureStorage : this.insecureStorage).delete(this.getKey(userId));
12333
12285
  }
12334
12286
  };
12335
12287
  var InMemoryStorage = class {
12336
- map = {};
12288
+ constructor() {
12289
+ this.map = {};
12290
+ }
12337
12291
  async get(key3) {
12338
12292
  return this.map[key3] || void 0;
12339
12293
  }
@@ -12351,7 +12305,6 @@ var ConfigurationError = class extends Error {
12351
12305
  }
12352
12306
  };
12353
12307
  var InvalidResponseError = class extends Error {
12354
- missingFields;
12355
12308
  /* istanbul ignore next */
12356
12309
  constructor(missingFields) {
12357
12310
  super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
@@ -12359,8 +12312,6 @@ var InvalidResponseError = class extends Error {
12359
12312
  }
12360
12313
  };
12361
12314
  var OidcProviderError = class extends Error {
12362
- error;
12363
- errorDescription;
12364
12315
  /* istanbul ignore next */
12365
12316
  constructor(message5, error4, errorDescription) {
12366
12317
  super(message5);
@@ -12397,9 +12348,10 @@ function isExpectedAuthError(statusCode2) {
12397
12348
  return [401, 403].includes(statusCode2);
12398
12349
  }
12399
12350
  async function buildDpopFetchOptions(targetUrl3, authToken, dpopKey, defaultOptions) {
12400
- const headers = new Headers(defaultOptions?.headers);
12351
+ var _a;
12352
+ const headers = new Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
12401
12353
  headers.set("Authorization", `DPoP ${authToken}`);
12402
- headers.set("DPoP", await createDpopHeader(targetUrl3, defaultOptions?.method ?? "get", dpopKey));
12354
+ headers.set("DPoP", await createDpopHeader(targetUrl3, (_a = defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.method) !== null && _a !== void 0 ? _a : "get", dpopKey));
12403
12355
  return {
12404
12356
  ...defaultOptions,
12405
12357
  headers
@@ -12409,7 +12361,7 @@ async function buildAuthenticatedHeaders(targetUrl3, authToken, dpopKey, default
12409
12361
  if (dpopKey !== void 0) {
12410
12362
  return buildDpopFetchOptions(targetUrl3, authToken, dpopKey, defaultOptions);
12411
12363
  }
12412
- const headers = new Headers(defaultOptions?.headers);
12364
+ const headers = new Headers(defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.headers);
12413
12365
  headers.set("Authorization", `Bearer ${authToken}`);
12414
12366
  return {
12415
12367
  ...defaultOptions,
@@ -12420,8 +12372,12 @@ async function makeAuthenticatedRequest(accessToken, url7, defaultRequestInit, d
12420
12372
  return fetch(url7, await buildAuthenticatedHeaders(url7.toString(), accessToken, dpopKey, defaultRequestInit));
12421
12373
  }
12422
12374
  async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
12375
+ var _a;
12423
12376
  const tokenSet = await refreshOptions.tokenRefresher.refresh(refreshOptions.sessionId, refreshOptions.refreshToken, dpopKey);
12424
- eventEmitter?.emit(EVENTS.SESSION_EXTENDED, tokenSet.expiresIn ?? DEFAULT_EXPIRATION_TIME_SECONDS);
12377
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.SESSION_EXTENDED, (_a = tokenSet.expiresIn) !== null && _a !== void 0 ? _a : DEFAULT_EXPIRATION_TIME_SECONDS);
12378
+ if (typeof tokenSet.refreshToken === "string") {
12379
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
12380
+ }
12425
12381
  return {
12426
12382
  accessToken: tokenSet.accessToken,
12427
12383
  refreshToken: tokenSet.refreshToken,
@@ -12437,12 +12393,14 @@ var computeRefreshDelay = (expiresIn) => {
12437
12393
  }
12438
12394
  return DEFAULT_EXPIRATION_TIME_SECONDS;
12439
12395
  };
12440
- function buildAuthenticatedFetch(accessToken, options) {
12396
+ async function buildAuthenticatedFetch(accessToken, options) {
12397
+ var _a;
12441
12398
  let currentAccessToken = accessToken;
12442
12399
  let latestTimeout;
12443
- const currentRefreshOptions = options?.refreshOptions;
12400
+ const currentRefreshOptions = options === null || options === void 0 ? void 0 : options.refreshOptions;
12444
12401
  if (currentRefreshOptions !== void 0) {
12445
12402
  const proactivelyRefreshToken = async () => {
12403
+ var _a2, _b, _c, _d;
12446
12404
  try {
12447
12405
  const { accessToken: refreshedAccessToken, refreshToken, expiresIn } = await refreshAccessToken(
12448
12406
  currentRefreshOptions,
@@ -12458,14 +12416,14 @@ function buildAuthenticatedFetch(accessToken, options) {
12458
12416
  }
12459
12417
  clearTimeout(latestTimeout);
12460
12418
  latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(expiresIn) * 1e3);
12461
- options.eventEmitter?.emit(EVENTS.TIMEOUT_SET, latestTimeout);
12419
+ (_a2 = options.eventEmitter) === null || _a2 === void 0 ? void 0 : _a2.emit(EVENTS.TIMEOUT_SET, latestTimeout);
12462
12420
  } catch (e) {
12463
12421
  if (e instanceof OidcProviderError) {
12464
- options?.eventEmitter?.emit(EVENTS.ERROR, e.error, e.errorDescription);
12465
- options?.eventEmitter?.emit(EVENTS.SESSION_EXPIRED);
12422
+ (_b = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _b === void 0 ? void 0 : _b.emit(EVENTS.ERROR, e.error, e.errorDescription);
12423
+ (_c = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _c === void 0 ? void 0 : _c.emit(EVENTS.SESSION_EXPIRED);
12466
12424
  }
12467
12425
  if (e instanceof InvalidResponseError && e.missingFields.includes("access_token")) {
12468
- options?.eventEmitter?.emit(EVENTS.SESSION_EXPIRED);
12426
+ (_d = options === null || options === void 0 ? void 0 : options.eventEmitter) === null || _d === void 0 ? void 0 : _d.emit(EVENTS.SESSION_EXPIRED);
12469
12427
  }
12470
12428
  }
12471
12429
  };
@@ -12475,7 +12433,7 @@ function buildAuthenticatedFetch(accessToken, options) {
12475
12433
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12476
12434
  computeRefreshDelay(options.expiresIn) * 1e3
12477
12435
  );
12478
- options.eventEmitter?.emit(EVENTS.TIMEOUT_SET, latestTimeout);
12436
+ (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
12479
12437
  } else if (options !== void 0 && options.eventEmitter !== void 0) {
12480
12438
  const expirationTimeout = setTimeout(() => {
12481
12439
  options.eventEmitter.emit(EVENTS.SESSION_EXPIRED);
@@ -12483,13 +12441,13 @@ function buildAuthenticatedFetch(accessToken, options) {
12483
12441
  options.eventEmitter.emit(EVENTS.TIMEOUT_SET, expirationTimeout);
12484
12442
  }
12485
12443
  return async (url7, requestInit) => {
12486
- let response6 = await makeAuthenticatedRequest(currentAccessToken, url7, requestInit, options?.dpopKey);
12444
+ let response6 = await makeAuthenticatedRequest(currentAccessToken, url7, requestInit, options === null || options === void 0 ? void 0 : options.dpopKey);
12487
12445
  const failedButNotExpectedAuthError = !response6.ok && !isExpectedAuthError(response6.status);
12488
12446
  if (response6.ok || failedButNotExpectedAuthError) {
12489
12447
  return response6;
12490
12448
  }
12491
12449
  const hasBeenRedirected = response6.url !== url7;
12492
- if (hasBeenRedirected && options?.dpopKey !== void 0) {
12450
+ if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== void 0) {
12493
12451
  response6 = await makeAuthenticatedRequest(
12494
12452
  currentAccessToken,
12495
12453
  // Replace the original target IRI (`url`) by the redirection target
@@ -12534,17 +12492,11 @@ function v42(options, buf, offset3) {
12534
12492
  return native_default2.randomUUID();
12535
12493
  }
12536
12494
  options = options || {};
12537
- const rnds = options.random ?? options.rng?.() ?? rng2();
12538
- if (rnds.length < 16) {
12539
- throw new Error("Random bytes length must be >= 16");
12540
- }
12495
+ const rnds = options.random || (options.rng || rng2)();
12541
12496
  rnds[6] = rnds[6] & 15 | 64;
12542
12497
  rnds[8] = rnds[8] & 63 | 128;
12543
12498
  if (buf) {
12544
12499
  offset3 = offset3 || 0;
12545
- if (offset3 < 0 || offset3 + 16 > buf.length) {
12546
- throw new RangeError(`UUID byte range ${offset3}:${offset3 + 15} is out of buffer bounds`);
12547
- }
12548
12500
  for (let i = 0; i < 16; ++i) {
12549
12501
  buf[offset3 + i] = rnds[i];
12550
12502
  }
@@ -12561,32 +12513,27 @@ var import_events = __toESM(require_events(), 1);
12561
12513
  var import_oidc_client = __toESM(require_oidc_client_min());
12562
12514
  var import_oidc_client2 = __toESM(require_oidc_client_min());
12563
12515
  function processErrorResponse(responseBody, options) {
12516
+ var _a, _b, _c, _d;
12564
12517
  if (responseBody.error === "invalid_redirect_uri") {
12565
- throw new Error(`Dynamic client registration failed: the provided redirect uri [${options.redirectUrl?.toString()}] is invalid - ${responseBody.error_description ?? ""}`);
12518
+ 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 : ""}`);
12566
12519
  }
12567
12520
  if (responseBody.error === "invalid_client_metadata") {
12568
- throw new Error(`Dynamic client registration failed: the provided client metadata ${JSON.stringify(options)} is invalid - ${responseBody.error_description ?? ""}`);
12521
+ 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 : ""}`);
12569
12522
  }
12570
- throw new Error(`Dynamic client registration failed: ${responseBody.error} - ${responseBody.error_description ?? ""}`);
12571
- }
12572
- function hasClientId(body) {
12573
- return typeof body.client_id === "string";
12574
- }
12575
- function hasRedirectUri(body) {
12576
- return Array.isArray(body.redirect_uris) && body.redirect_uris.every((uri6) => typeof uri6 === "string");
12523
+ throw new Error(`Dynamic client registration failed: ${responseBody.error} - ${(_d = responseBody.error_description) !== null && _d !== void 0 ? _d : ""}`);
12577
12524
  }
12578
12525
  function validateRegistrationResponse(responseBody, options) {
12579
- if (!hasClientId(responseBody)) {
12526
+ if (responseBody.client_id === void 0) {
12580
12527
  throw new Error(`Dynamic client registration failed: no client_id has been found on ${JSON.stringify(responseBody)}`);
12581
12528
  }
12582
- if (options.redirectUrl && hasRedirectUri(responseBody) && responseBody.redirect_uris[0] !== options.redirectUrl.toString()) {
12529
+ if (options.redirectUrl && (responseBody.redirect_uris === void 0 || responseBody.redirect_uris[0] !== options.redirectUrl.toString())) {
12583
12530
  throw new Error(`Dynamic client registration failed: the returned redirect URIs ${JSON.stringify(responseBody.redirect_uris)} don't match the provided ${JSON.stringify([
12584
12531
  options.redirectUrl.toString()
12585
12532
  ])}`);
12586
12533
  }
12587
- return true;
12588
12534
  }
12589
12535
  async function registerClient(options, issuerConfig) {
12536
+ var _a;
12590
12537
  if (!issuerConfig.registrationEndpoint) {
12591
12538
  throw new Error("Dynamic Registration could not be completed because the issuer has no registration endpoint.");
12592
12539
  }
@@ -12598,7 +12545,7 @@ async function registerClient(options, issuerConfig) {
12598
12545
  /* eslint-disable camelcase */
12599
12546
  client_name: options.clientName,
12600
12547
  application_type: "web",
12601
- redirect_uris: [options.redirectUrl?.toString()],
12548
+ redirect_uris: [(_a = options.redirectUrl) === null || _a === void 0 ? void 0 : _a.toString()],
12602
12549
  subject_type: "public",
12603
12550
  token_endpoint_auth_method: "client_secret_basic",
12604
12551
  id_token_signed_response_alg: signingAlg,
@@ -12619,7 +12566,6 @@ async function registerClient(options, issuerConfig) {
12619
12566
  return {
12620
12567
  clientId: responseBody.client_id,
12621
12568
  clientSecret: responseBody.client_secret,
12622
- expiresAt: responseBody.client_secret_expires_at,
12623
12569
  idTokenSignedResponseAlg: responseBody.id_token_signed_response_alg,
12624
12570
  clientType: "dynamic"
12625
12571
  };
@@ -12727,7 +12673,7 @@ var isValidUrl2 = (url7) => {
12727
12673
  try {
12728
12674
  new URL(url7);
12729
12675
  return true;
12730
- } catch {
12676
+ } catch (_a) {
12731
12677
  return false;
12732
12678
  }
12733
12679
  };
@@ -12828,54 +12774,50 @@ var StorageUtilityBrowser = class extends StorageUtility {
12828
12774
  }
12829
12775
  };
12830
12776
  var ClientAuthentication2 = class extends ClientAuthentication {
12831
- // Define these functions as properties so that they don't get accidentally re-bound.
12832
- // Isn't Javascript fun?
12833
- login = async (options, eventEmitter) => {
12834
- if (options.prompt !== "none") {
12777
+ constructor() {
12778
+ super(...arguments);
12779
+ this.login = async (options, eventEmitter) => {
12780
+ var _a, _b;
12835
12781
  await this.sessionInfoManager.clear(options.sessionId);
12836
- }
12837
- const redirectUrl = options.redirectUrl ?? normalizeCallbackUrl(window.location.href);
12838
- if (!isValidRedirectUrl(redirectUrl)) {
12839
- 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').`);
12840
- }
12841
- await this.loginHandler.handle({
12842
- ...options,
12843
- redirectUrl,
12844
- // If no clientName is provided, the clientId may be used instead.
12845
- clientName: options.clientName ?? options.clientId,
12846
- eventEmitter
12847
- });
12848
- };
12849
- // Collects session information from storage, and returns them. Returns null
12850
- // if the expected information cannot be found.
12851
- // Note that the ID token is not stored, which means the session information
12852
- // cannot be validated at this point.
12853
- validateCurrentSession = async (currentSessionId) => {
12854
- const sessionInfo = await this.sessionInfoManager.get(currentSessionId);
12855
- if (sessionInfo === void 0 || sessionInfo.clientAppId === void 0 || sessionInfo.issuer === void 0) {
12856
- return null;
12857
- }
12858
- return sessionInfo;
12859
- };
12860
- handleIncomingRedirect = async (url7, eventEmitter) => {
12861
- try {
12862
- const redirectInfo = await this.redirectHandler.handle(url7, eventEmitter, void 0);
12863
- this.fetch = redirectInfo.fetch.bind(window);
12864
- this.boundLogout = redirectInfo.getLogoutUrl;
12865
- await this.cleanUrlAfterRedirect(url7);
12866
- return {
12867
- isLoggedIn: redirectInfo.isLoggedIn,
12868
- webId: redirectInfo.webId,
12869
- sessionId: redirectInfo.sessionId,
12870
- expirationDate: redirectInfo.expirationDate,
12871
- clientAppId: redirectInfo.clientAppId
12872
- };
12873
- } catch (err) {
12874
- await this.cleanUrlAfterRedirect(url7);
12875
- eventEmitter.emit(EVENTS.ERROR, "redirect", err);
12876
- return void 0;
12877
- }
12878
- };
12782
+ const redirectUrl = (_a = options.redirectUrl) !== null && _a !== void 0 ? _a : normalizeCallbackUrl(window.location.href);
12783
+ if (!isValidRedirectUrl(redirectUrl)) {
12784
+ 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').`);
12785
+ }
12786
+ await this.loginHandler.handle({
12787
+ ...options,
12788
+ redirectUrl,
12789
+ // If no clientName is provided, the clientId may be used instead.
12790
+ clientName: (_b = options.clientName) !== null && _b !== void 0 ? _b : options.clientId,
12791
+ eventEmitter
12792
+ });
12793
+ };
12794
+ this.validateCurrentSession = async (currentSessionId) => {
12795
+ const sessionInfo = await this.sessionInfoManager.get(currentSessionId);
12796
+ if (sessionInfo === void 0 || sessionInfo.clientAppId === void 0 || sessionInfo.issuer === void 0) {
12797
+ return null;
12798
+ }
12799
+ return sessionInfo;
12800
+ };
12801
+ this.handleIncomingRedirect = async (url7, eventEmitter) => {
12802
+ try {
12803
+ const redirectInfo = await this.redirectHandler.handle(url7, eventEmitter, void 0);
12804
+ this.fetch = redirectInfo.fetch.bind(window);
12805
+ this.boundLogout = redirectInfo.getLogoutUrl;
12806
+ await this.cleanUrlAfterRedirect(url7);
12807
+ return {
12808
+ isLoggedIn: redirectInfo.isLoggedIn,
12809
+ webId: redirectInfo.webId,
12810
+ sessionId: redirectInfo.sessionId,
12811
+ expirationDate: redirectInfo.expirationDate,
12812
+ clientAppId: redirectInfo.clientAppId
12813
+ };
12814
+ } catch (err) {
12815
+ await this.cleanUrlAfterRedirect(url7);
12816
+ eventEmitter.emit(EVENTS.ERROR, "redirect", err);
12817
+ return void 0;
12818
+ }
12819
+ };
12820
+ }
12879
12821
  async cleanUrlAfterRedirect(url7) {
12880
12822
  const cleanedUpUrl = removeOpenIdParams(url7).href;
12881
12823
  window.history.replaceState(null, "", cleanedUpUrl);
@@ -12893,10 +12835,6 @@ function hasRedirectUrl(options) {
12893
12835
  return typeof options.redirectUrl === "string";
12894
12836
  }
12895
12837
  var OidcLoginHandler = class {
12896
- storageUtility;
12897
- oidcHandler;
12898
- issuerConfigFetcher;
12899
- clientRegistrar;
12900
12838
  constructor(storageUtility, oidcHandler, issuerConfigFetcher, clientRegistrar) {
12901
12839
  this.storageUtility = storageUtility;
12902
12840
  this.oidcHandler = oidcHandler;
@@ -12937,6 +12875,7 @@ var OidcLoginHandler = class {
12937
12875
  };
12938
12876
  var AuthorizationCodeWithPkceOidcHandler = class extends AuthorizationCodeWithPkceOidcHandlerBase {
12939
12877
  async handle(oidcLoginOptions) {
12878
+ var _a;
12940
12879
  const oidcOptions = {
12941
12880
  authority: oidcLoginOptions.issuer.toString(),
12942
12881
  client_id: oidcLoginOptions.client.clientId,
@@ -12950,12 +12889,12 @@ var AuthorizationCodeWithPkceOidcHandler = class extends AuthorizationCodeWithPk
12950
12889
  // profile referenced by the WebId.
12951
12890
  loadUserInfo: false,
12952
12891
  code_verifier: true,
12953
- prompt: oidcLoginOptions.prompt ?? "consent"
12892
+ prompt: (_a = oidcLoginOptions.prompt) !== null && _a !== void 0 ? _a : "consent"
12954
12893
  };
12955
12894
  const oidcClientLibrary = new import_oidc_client2.OidcClient(oidcOptions);
12956
12895
  try {
12957
12896
  const signingRequest = await oidcClientLibrary.createSigninRequest();
12958
- return await this.setupRedirectHandler({
12897
+ return await this.handleRedirect({
12959
12898
  oidcLoginOptions,
12960
12899
  // eslint-disable-next-line no-underscore-dangle
12961
12900
  state: signingRequest.state._id,
@@ -13070,7 +13009,6 @@ function processConfig(config2) {
13070
13009
  return parsedConfig;
13071
13010
  }
13072
13011
  var IssuerConfigFetcher = class _IssuerConfigFetcher {
13073
- storageUtility;
13074
13012
  constructor(storageUtility) {
13075
13013
  this.storageUtility = storageUtility;
13076
13014
  this.storageUtility = storageUtility;
@@ -13153,7 +13091,7 @@ var SessionInfoManager = class extends SessionInfoManagerBase {
13153
13091
  clientAppId: clientId,
13154
13092
  clientAppSecret: clientSecret,
13155
13093
  // Default the token type to DPoP if unspecified.
13156
- tokenType: tokenType ?? "DPoP"
13094
+ tokenType: tokenType !== null && tokenType !== void 0 ? tokenType : "DPoP"
13157
13095
  };
13158
13096
  }
13159
13097
  /**
@@ -13180,11 +13118,6 @@ var FallbackRedirectHandler = class {
13180
13118
  }
13181
13119
  };
13182
13120
  var AuthCodeRedirectHandler = class {
13183
- storageUtility;
13184
- sessionInfoManager;
13185
- issuerConfigFetcher;
13186
- clientRegistrar;
13187
- tokerRefresher;
13188
13121
  constructor(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokerRefresher) {
13189
13122
  this.storageUtility = storageUtility;
13190
13123
  this.sessionInfoManager = sessionInfoManager;
@@ -13244,7 +13177,7 @@ var AuthCodeRedirectHandler = class {
13244
13177
  tokenRefresher: this.tokerRefresher
13245
13178
  };
13246
13179
  }
13247
- const authFetch = buildAuthenticatedFetch(tokens.accessToken, {
13180
+ const authFetch = await buildAuthenticatedFetch(tokens.accessToken, {
13248
13181
  dpopKey: tokens.dpopKey,
13249
13182
  refreshOptions,
13250
13183
  eventEmitter,
@@ -13296,22 +13229,18 @@ var Redirector = class {
13296
13229
  }
13297
13230
  };
13298
13231
  var ClientRegistrar = class {
13299
- storageUtility;
13300
13232
  constructor(storageUtility) {
13301
13233
  this.storageUtility = storageUtility;
13302
13234
  this.storageUtility = storageUtility;
13303
13235
  }
13304
13236
  async getClient(options, issuerConfig) {
13305
- const [storedClientId, storedClientSecret, expiresAt, storedClientName, storedClientType] = await Promise.all([
13237
+ const [storedClientId, storedClientSecret, storedClientName, storedClientType] = await Promise.all([
13306
13238
  this.storageUtility.getForUser(options.sessionId, "clientId", {
13307
13239
  secure: false
13308
13240
  }),
13309
13241
  this.storageUtility.getForUser(options.sessionId, "clientSecret", {
13310
13242
  secure: false
13311
13243
  }),
13312
- this.storageUtility.getForUser(options.sessionId, "expiresAt", {
13313
- secure: false
13314
- }),
13315
13244
  this.storageUtility.getForUser(options.sessionId, "clientName", {
13316
13245
  secure: false
13317
13246
  }),
@@ -13319,22 +13248,13 @@ var ClientRegistrar = class {
13319
13248
  secure: false
13320
13249
  })
13321
13250
  ]);
13322
- const expirationDate2 = expiresAt !== void 0 ? Number.parseInt(expiresAt, 10) : -1;
13323
- const expired = storedClientSecret !== void 0 && Math.floor(Date.now() / 1e3) > expirationDate2;
13324
- if (storedClientId && isKnownClientType(storedClientType) && !expired) {
13325
- return storedClientSecret !== void 0 ? {
13251
+ if (storedClientId && isKnownClientType(storedClientType)) {
13252
+ return {
13326
13253
  clientId: storedClientId,
13327
13254
  clientSecret: storedClientSecret,
13328
13255
  clientName: storedClientName,
13329
13256
  // Note: static clients are not applicable in a browser context.
13330
- clientType: "dynamic",
13331
- expiresAt: expirationDate2
13332
- } : {
13333
- clientId: storedClientId,
13334
- clientName: storedClientName,
13335
- // Note: static clients are not applicable in a browser context.
13336
13257
  clientType: storedClientType
13337
- // The type assertion is required even though the type should match the declaration.
13338
13258
  };
13339
13259
  }
13340
13260
  try {
@@ -13343,9 +13263,8 @@ var ClientRegistrar = class {
13343
13263
  clientId: registeredClient.clientId,
13344
13264
  clientType: "dynamic"
13345
13265
  };
13346
- if (registeredClient.clientSecret !== void 0) {
13266
+ if (registeredClient.clientSecret) {
13347
13267
  infoToSave.clientSecret = registeredClient.clientSecret;
13348
- infoToSave.expiresAt = String(registeredClient.expiresAt);
13349
13268
  }
13350
13269
  if (registeredClient.idTokenSignedResponseAlg) {
13351
13270
  infoToSave.idTokenSignedResponseAlg = registeredClient.idTokenSignedResponseAlg;
@@ -13358,7 +13277,7 @@ var ClientRegistrar = class {
13358
13277
  });
13359
13278
  return registeredClient;
13360
13279
  } catch (error4) {
13361
- throw new Error(`Client registration failed.`, { cause: error4 });
13280
+ throw new Error(`Client registration failed: [${error4}]`);
13362
13281
  }
13363
13282
  }
13364
13283
  };
@@ -13381,9 +13300,6 @@ var ErrorOidcHandler = class {
13381
13300
  }
13382
13301
  };
13383
13302
  var TokenRefresher = class {
13384
- storageUtility;
13385
- issuerConfigFetcher;
13386
- clientRegistrar;
13387
13303
  constructor(storageUtility, issuerConfigFetcher, clientRegistrar) {
13388
13304
  this.storageUtility = storageUtility;
13389
13305
  this.issuerConfigFetcher = issuerConfigFetcher;
@@ -13403,7 +13319,7 @@ var TokenRefresher = class {
13403
13319
  }
13404
13320
  const tokenSet = await refresh(refreshToken, oidcContext.issuerConfig, clientInfo, dpopKey);
13405
13321
  if (tokenSet.refreshToken !== void 0) {
13406
- eventEmitter?.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
13322
+ eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
13407
13323
  }
13408
13324
  return tokenSet;
13409
13325
  }
@@ -13431,6 +13347,7 @@ function getClientAuthenticationWithDependencies(dependencies3) {
13431
13347
  var KEY_CURRENT_SESSION = `${SOLID_CLIENT_AUTHN_KEY_PREFIX}currentSession`;
13432
13348
  var KEY_CURRENT_URL = `${SOLID_CLIENT_AUTHN_KEY_PREFIX}currentUrl`;
13433
13349
  async function silentlyAuthenticate(sessionId, clientAuthn, session4) {
13350
+ var _a;
13434
13351
  const storedSessionInfo = await clientAuthn.validateCurrentSession(sessionId);
13435
13352
  if (storedSessionInfo !== null) {
13436
13353
  window.localStorage.setItem(KEY_CURRENT_URL, window.location.href);
@@ -13441,28 +13358,16 @@ async function silentlyAuthenticate(sessionId, clientAuthn, session4) {
13441
13358
  redirectUrl: storedSessionInfo.redirectUrl,
13442
13359
  clientId: storedSessionInfo.clientAppId,
13443
13360
  clientSecret: storedSessionInfo.clientAppSecret,
13444
- tokenType: storedSessionInfo.tokenType ?? "DPoP"
13361
+ tokenType: (_a = storedSessionInfo.tokenType) !== null && _a !== void 0 ? _a : "DPoP"
13445
13362
  }, session4.events);
13446
13363
  return true;
13447
13364
  }
13448
13365
  return false;
13449
13366
  }
13450
13367
  function isLoggedIn(sessionInfo) {
13451
- return !!sessionInfo?.isLoggedIn;
13368
+ return !!(sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.isLoggedIn);
13452
13369
  }
13453
13370
  var Session = class {
13454
- /**
13455
- * Information regarding the current session.
13456
- */
13457
- info;
13458
- /**
13459
- * Session attribute exposing the EventEmitter interface, to listen on session
13460
- * events such as login, logout, etc.
13461
- * @since 1.15.0
13462
- */
13463
- events;
13464
- clientAuthentication;
13465
- tokenRequestInProgress = false;
13466
13371
  /**
13467
13372
  * Session object constructor. Typically called as follows:
13468
13373
  *
@@ -13479,6 +13384,62 @@ var Session = class {
13479
13384
  *
13480
13385
  */
13481
13386
  constructor(sessionOptions = {}, sessionId = void 0) {
13387
+ this.tokenRequestInProgress = false;
13388
+ this.login = async (options) => {
13389
+ var _a;
13390
+ await this.clientAuthentication.login({
13391
+ sessionId: this.info.sessionId,
13392
+ ...options,
13393
+ // Defaults the token type to DPoP
13394
+ tokenType: (_a = options.tokenType) !== null && _a !== void 0 ? _a : "DPoP"
13395
+ }, this.events);
13396
+ return new Promise(() => {
13397
+ });
13398
+ };
13399
+ this.fetch = (url7, init) => this.clientAuthentication.fetch(url7, init);
13400
+ this.internalLogout = async (emitSignal, options) => {
13401
+ window.localStorage.removeItem(KEY_CURRENT_SESSION);
13402
+ await this.clientAuthentication.logout(this.info.sessionId, options);
13403
+ this.info.isLoggedIn = false;
13404
+ if (emitSignal) {
13405
+ this.events.emit(EVENTS.LOGOUT);
13406
+ }
13407
+ };
13408
+ this.logout = async (options) => this.internalLogout(true, options);
13409
+ this.handleIncomingRedirect = async (inputOptions = {}) => {
13410
+ var _a;
13411
+ if (this.info.isLoggedIn) {
13412
+ return this.info;
13413
+ }
13414
+ if (this.tokenRequestInProgress) {
13415
+ return void 0;
13416
+ }
13417
+ const options = typeof inputOptions === "string" ? { url: inputOptions } : inputOptions;
13418
+ const url7 = (_a = options.url) !== null && _a !== void 0 ? _a : window.location.href;
13419
+ this.tokenRequestInProgress = true;
13420
+ const sessionInfo = await this.clientAuthentication.handleIncomingRedirect(url7, this.events);
13421
+ if (isLoggedIn(sessionInfo)) {
13422
+ this.setSessionInfo(sessionInfo);
13423
+ const currentUrl = window.localStorage.getItem(KEY_CURRENT_URL);
13424
+ if (currentUrl === null) {
13425
+ this.events.emit(EVENTS.LOGIN);
13426
+ } else {
13427
+ window.localStorage.removeItem(KEY_CURRENT_URL);
13428
+ this.events.emit(EVENTS.SESSION_RESTORED, currentUrl);
13429
+ }
13430
+ } else if (options.restorePreviousSession === true) {
13431
+ const storedSessionId = window.localStorage.getItem(KEY_CURRENT_SESSION);
13432
+ if (storedSessionId !== null) {
13433
+ const attemptedSilentAuthentication = await silentlyAuthenticate(storedSessionId, this.clientAuthentication, this);
13434
+ if (attemptedSilentAuthentication) {
13435
+ return new Promise(() => {
13436
+ });
13437
+ }
13438
+ }
13439
+ }
13440
+ this.tokenRequestInProgress = false;
13441
+ return sessionInfo;
13442
+ };
13482
13443
  this.events = new import_events.default();
13483
13444
  if (sessionOptions.clientAuthentication) {
13484
13445
  this.clientAuthentication = sessionOptions.clientAuthentication;
@@ -13499,7 +13460,7 @@ var Session = class {
13499
13460
  };
13500
13461
  } else {
13501
13462
  this.info = {
13502
- sessionId: sessionId ?? v4_default2(),
13463
+ sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : v4_default2(),
13503
13464
  isLoggedIn: false
13504
13465
  };
13505
13466
  }
@@ -13507,123 +13468,6 @@ var Session = class {
13507
13468
  this.events.on(EVENTS.SESSION_EXPIRED, () => this.internalLogout(false));
13508
13469
  this.events.on(EVENTS.ERROR, () => this.internalLogout(false));
13509
13470
  }
13510
- /**
13511
- * Triggers the login process. Note that this method will redirect the user away from your app.
13512
- *
13513
- * @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.
13514
- * @returns This method should redirect the user away from the app: it does not return anything. The login process is completed by {@linkcode handleIncomingRedirect}.
13515
- */
13516
- // Define these functions as properties so that they don't get accidentally re-bound.
13517
- // Isn't Javascript fun?
13518
- login = async (options) => {
13519
- await this.clientAuthentication.login({
13520
- sessionId: this.info.sessionId,
13521
- ...options,
13522
- // Defaults the token type to DPoP
13523
- tokenType: options.tokenType ?? "DPoP"
13524
- }, this.events);
13525
- return new Promise(() => {
13526
- });
13527
- };
13528
- /**
13529
- * 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).
13530
- *
13531
- * @param url The URL from which data should be fetched.
13532
- * @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/).
13533
- */
13534
- fetch = (url7, init) => this.clientAuthentication.fetch(url7, init);
13535
- /**
13536
- * An internal logout function, to control whether or not the logout signal
13537
- * should be sent, i.e. if the logout was user-initiated or is the result of
13538
- * an external event.
13539
- *
13540
- * @hidden
13541
- */
13542
- internalLogout = async (emitSignal, options) => {
13543
- window.localStorage.removeItem(KEY_CURRENT_SESSION);
13544
- await this.clientAuthentication.logout(this.info.sessionId, options);
13545
- this.info.isLoggedIn = false;
13546
- if (emitSignal) {
13547
- this.events.emit(EVENTS.LOGOUT);
13548
- }
13549
- };
13550
- /**
13551
- * Logs the user out of the application.
13552
- *
13553
- * There are 2 types of logout supported by this library,
13554
- * `app` logout and `idp` logout.
13555
- *
13556
- * App logout will log the user out within the application
13557
- * by clearing any session data from the browser. It does
13558
- * not log the user out of their Solid identity provider,
13559
- * and should not redirect the user away.
13560
- * App logout can be performed as follows:
13561
- * ```typescript
13562
- * await session.logout({ logoutType: 'app' });
13563
- * ```
13564
- *
13565
- * IDP logout will log the user out of their Solid identity provider,
13566
- * and will redirect the user away from the application to do so. In order
13567
- * for users to be redirected back to `postLogoutUrl` you MUST include the
13568
- * `postLogoutUrl` value in the `post_logout_redirect_uris` field in the
13569
- * [Client ID Document](https://docs.inrupt.com/ess/latest/security/authentication/#client-identifier-client-id).
13570
- * IDP logout can be performed as follows:
13571
- * ```typescript
13572
- * await session.logout({
13573
- * logoutType: 'idp',
13574
- * // An optional URL to redirect to after logout has completed;
13575
- * // this MUST match a logout URL listed in the Client ID Document
13576
- * // of the application that is logged in.
13577
- * // If the application is logged in with a Client ID that is not
13578
- * // a URI dereferencing to a Client ID Document then users will
13579
- * // not be redirected back to the `postLogoutUrl` after logout.
13580
- * postLogoutUrl: 'https://example.com/logout',
13581
- * // An optional value to be included in the query parameters
13582
- * // when the IDP provider redirects the user to the postLogoutRedirectUrl.
13583
- * state: "my-state"
13584
- * });
13585
- * ```
13586
- */
13587
- logout = async (options) => this.internalLogout(true, options);
13588
- /**
13589
- * Completes the login process by processing the information provided by the
13590
- * Solid identity provider through redirect.
13591
- *
13592
- * @param options See {@link IHandleIncomingRedirectOptions}.
13593
- */
13594
- handleIncomingRedirect = async (inputOptions = {}) => {
13595
- if (this.info.isLoggedIn) {
13596
- return this.info;
13597
- }
13598
- if (this.tokenRequestInProgress) {
13599
- return void 0;
13600
- }
13601
- const options = typeof inputOptions === "string" ? { url: inputOptions } : inputOptions;
13602
- const url7 = options.url ?? window.location.href;
13603
- this.tokenRequestInProgress = true;
13604
- const sessionInfo = await this.clientAuthentication.handleIncomingRedirect(url7, this.events);
13605
- if (isLoggedIn(sessionInfo)) {
13606
- this.setSessionInfo(sessionInfo);
13607
- const currentUrl = window.localStorage.getItem(KEY_CURRENT_URL);
13608
- if (currentUrl === null) {
13609
- this.events.emit(EVENTS.LOGIN);
13610
- } else {
13611
- window.localStorage.removeItem(KEY_CURRENT_URL);
13612
- this.events.emit(EVENTS.SESSION_RESTORED, currentUrl);
13613
- }
13614
- } else if (options.restorePreviousSession === true) {
13615
- const storedSessionId = window.localStorage.getItem(KEY_CURRENT_SESSION);
13616
- if (storedSessionId !== null) {
13617
- const attemptedSilentAuthentication = await silentlyAuthenticate(storedSessionId, this.clientAuthentication, this);
13618
- if (attemptedSilentAuthentication) {
13619
- return new Promise(() => {
13620
- });
13621
- }
13622
- }
13623
- }
13624
- this.tokenRequestInProgress = false;
13625
- return sessionInfo;
13626
- };
13627
13471
  setSessionInfo(sessionInfo) {
13628
13472
  this.info.isLoggedIn = sessionInfo.isLoggedIn;
13629
13473
  this.info.webId = sessionInfo.webId;