@pod-os/core 0.11.1-62070fe.0 → 0.11.1-62e1055.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 +437 -42
  2. package/lib/index.js +437 -42
  3. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -12833,39 +12833,65 @@ var require_implementation = __commonJS({
12833
12833
  "../node_modules/function-bind/implementation.js"(exports, module3) {
12834
12834
  "use strict";
12835
12835
  var ERROR_MESSAGE = "Function.prototype.bind called on incompatible ";
12836
- var slice = Array.prototype.slice;
12837
12836
  var toStr = Object.prototype.toString;
12837
+ var max2 = Math.max;
12838
12838
  var funcType = "[object Function]";
12839
+ var concatty = function concatty2(a, b) {
12840
+ var arr = [];
12841
+ for (var i = 0; i < a.length; i += 1) {
12842
+ arr[i] = a[i];
12843
+ }
12844
+ for (var j = 0; j < b.length; j += 1) {
12845
+ arr[j + a.length] = b[j];
12846
+ }
12847
+ return arr;
12848
+ };
12849
+ var slicy = function slicy2(arrLike, offset3) {
12850
+ var arr = [];
12851
+ for (var i = offset3 || 0, j = 0; i < arrLike.length; i += 1, j += 1) {
12852
+ arr[j] = arrLike[i];
12853
+ }
12854
+ return arr;
12855
+ };
12856
+ var joiny = function(arr, joiner) {
12857
+ var str = "";
12858
+ for (var i = 0; i < arr.length; i += 1) {
12859
+ str += arr[i];
12860
+ if (i + 1 < arr.length) {
12861
+ str += joiner;
12862
+ }
12863
+ }
12864
+ return str;
12865
+ };
12839
12866
  module3.exports = function bind(that) {
12840
12867
  var target5 = this;
12841
- if (typeof target5 !== "function" || toStr.call(target5) !== funcType) {
12868
+ if (typeof target5 !== "function" || toStr.apply(target5) !== funcType) {
12842
12869
  throw new TypeError(ERROR_MESSAGE + target5);
12843
12870
  }
12844
- var args = slice.call(arguments, 1);
12871
+ var args = slicy(arguments, 1);
12845
12872
  var bound;
12846
12873
  var binder = function() {
12847
12874
  if (this instanceof bound) {
12848
12875
  var result5 = target5.apply(
12849
12876
  this,
12850
- args.concat(slice.call(arguments))
12877
+ concatty(args, arguments)
12851
12878
  );
12852
12879
  if (Object(result5) === result5) {
12853
12880
  return result5;
12854
12881
  }
12855
12882
  return this;
12856
- } else {
12857
- return target5.apply(
12858
- that,
12859
- args.concat(slice.call(arguments))
12860
- );
12861
12883
  }
12884
+ return target5.apply(
12885
+ that,
12886
+ concatty(args, arguments)
12887
+ );
12862
12888
  };
12863
- var boundLength = Math.max(0, target5.length - args.length);
12889
+ var boundLength = max2(0, target5.length - args.length);
12864
12890
  var boundArgs = [];
12865
12891
  for (var i = 0; i < boundLength; i++) {
12866
- boundArgs.push("$" + i);
12892
+ boundArgs[i] = "$" + i;
12867
12893
  }
12868
- bound = Function("binder", "return function (" + boundArgs.join(",") + "){ return binder.apply(this,arguments); }")(binder);
12894
+ bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
12869
12895
  if (target5.prototype) {
12870
12896
  var Empty = function Empty2() {
12871
12897
  };
@@ -12887,12 +12913,14 @@ var require_function_bind = __commonJS({
12887
12913
  }
12888
12914
  });
12889
12915
 
12890
- // ../node_modules/has/src/index.js
12891
- var require_src = __commonJS({
12892
- "../node_modules/has/src/index.js"(exports, module3) {
12916
+ // ../node_modules/hasown/index.js
12917
+ var require_hasown = __commonJS({
12918
+ "../node_modules/hasown/index.js"(exports, module3) {
12893
12919
  "use strict";
12920
+ var call = Function.prototype.call;
12921
+ var $hasOwn = Object.prototype.hasOwnProperty;
12894
12922
  var bind = require_function_bind();
12895
- module3.exports = bind.call(Function.call, Object.prototype.hasOwnProperty);
12923
+ module3.exports = bind.call(call, $hasOwn);
12896
12924
  }
12897
12925
  });
12898
12926
 
@@ -13094,7 +13122,7 @@ var require_get_intrinsic = __commonJS({
13094
13122
  "%WeakSetPrototype%": ["WeakSet", "prototype"]
13095
13123
  };
13096
13124
  var bind = require_function_bind();
13097
- var hasOwn = require_src();
13125
+ var hasOwn = require_hasown();
13098
13126
  var $concat = bind.call(Function.call, Array.prototype.concat);
13099
13127
  var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
13100
13128
  var $replace = bind.call(Function.call, String.prototype.replace);
@@ -13203,16 +13231,163 @@ var require_get_intrinsic = __commonJS({
13203
13231
  }
13204
13232
  });
13205
13233
 
13234
+ // ../node_modules/has-property-descriptors/index.js
13235
+ var require_has_property_descriptors = __commonJS({
13236
+ "../node_modules/has-property-descriptors/index.js"(exports, module3) {
13237
+ "use strict";
13238
+ var GetIntrinsic = require_get_intrinsic();
13239
+ var $defineProperty = GetIntrinsic("%Object.defineProperty%", true);
13240
+ var hasPropertyDescriptors = function hasPropertyDescriptors2() {
13241
+ if ($defineProperty) {
13242
+ try {
13243
+ $defineProperty({}, "a", { value: 1 });
13244
+ return true;
13245
+ } catch (e) {
13246
+ return false;
13247
+ }
13248
+ }
13249
+ return false;
13250
+ };
13251
+ hasPropertyDescriptors.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
13252
+ if (!hasPropertyDescriptors()) {
13253
+ return null;
13254
+ }
13255
+ try {
13256
+ return $defineProperty([], "length", { value: 1 }).length !== 1;
13257
+ } catch (e) {
13258
+ return true;
13259
+ }
13260
+ };
13261
+ module3.exports = hasPropertyDescriptors;
13262
+ }
13263
+ });
13264
+
13265
+ // ../node_modules/gopd/index.js
13266
+ var require_gopd = __commonJS({
13267
+ "../node_modules/gopd/index.js"(exports, module3) {
13268
+ "use strict";
13269
+ var GetIntrinsic = require_get_intrinsic();
13270
+ var $gOPD = GetIntrinsic("%Object.getOwnPropertyDescriptor%", true);
13271
+ if ($gOPD) {
13272
+ try {
13273
+ $gOPD([], "length");
13274
+ } catch (e) {
13275
+ $gOPD = null;
13276
+ }
13277
+ }
13278
+ module3.exports = $gOPD;
13279
+ }
13280
+ });
13281
+
13282
+ // ../node_modules/define-data-property/index.js
13283
+ var require_define_data_property = __commonJS({
13284
+ "../node_modules/define-data-property/index.js"(exports, module3) {
13285
+ "use strict";
13286
+ var hasPropertyDescriptors = require_has_property_descriptors()();
13287
+ var GetIntrinsic = require_get_intrinsic();
13288
+ var $defineProperty = hasPropertyDescriptors && GetIntrinsic("%Object.defineProperty%", true);
13289
+ if ($defineProperty) {
13290
+ try {
13291
+ $defineProperty({}, "a", { value: 1 });
13292
+ } catch (e) {
13293
+ $defineProperty = false;
13294
+ }
13295
+ }
13296
+ var $SyntaxError = GetIntrinsic("%SyntaxError%");
13297
+ var $TypeError = GetIntrinsic("%TypeError%");
13298
+ var gopd = require_gopd();
13299
+ module3.exports = function defineDataProperty(obj, property3, value6) {
13300
+ if (!obj || typeof obj !== "object" && typeof obj !== "function") {
13301
+ throw new $TypeError("`obj` must be an object or a function`");
13302
+ }
13303
+ if (typeof property3 !== "string" && typeof property3 !== "symbol") {
13304
+ throw new $TypeError("`property` must be a string or a symbol`");
13305
+ }
13306
+ if (arguments.length > 3 && typeof arguments[3] !== "boolean" && arguments[3] !== null) {
13307
+ throw new $TypeError("`nonEnumerable`, if provided, must be a boolean or null");
13308
+ }
13309
+ if (arguments.length > 4 && typeof arguments[4] !== "boolean" && arguments[4] !== null) {
13310
+ throw new $TypeError("`nonWritable`, if provided, must be a boolean or null");
13311
+ }
13312
+ if (arguments.length > 5 && typeof arguments[5] !== "boolean" && arguments[5] !== null) {
13313
+ throw new $TypeError("`nonConfigurable`, if provided, must be a boolean or null");
13314
+ }
13315
+ if (arguments.length > 6 && typeof arguments[6] !== "boolean") {
13316
+ throw new $TypeError("`loose`, if provided, must be a boolean");
13317
+ }
13318
+ var nonEnumerable = arguments.length > 3 ? arguments[3] : null;
13319
+ var nonWritable = arguments.length > 4 ? arguments[4] : null;
13320
+ var nonConfigurable = arguments.length > 5 ? arguments[5] : null;
13321
+ var loose = arguments.length > 6 ? arguments[6] : false;
13322
+ var desc = !!gopd && gopd(obj, property3);
13323
+ if ($defineProperty) {
13324
+ $defineProperty(obj, property3, {
13325
+ configurable: nonConfigurable === null && desc ? desc.configurable : !nonConfigurable,
13326
+ enumerable: nonEnumerable === null && desc ? desc.enumerable : !nonEnumerable,
13327
+ value: value6,
13328
+ writable: nonWritable === null && desc ? desc.writable : !nonWritable
13329
+ });
13330
+ } else if (loose || !nonEnumerable && !nonWritable && !nonConfigurable) {
13331
+ obj[property3] = value6;
13332
+ } else {
13333
+ throw new $SyntaxError("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.");
13334
+ }
13335
+ };
13336
+ }
13337
+ });
13338
+
13339
+ // ../node_modules/set-function-length/index.js
13340
+ var require_set_function_length = __commonJS({
13341
+ "../node_modules/set-function-length/index.js"(exports, module3) {
13342
+ "use strict";
13343
+ var GetIntrinsic = require_get_intrinsic();
13344
+ var define2 = require_define_data_property();
13345
+ var hasDescriptors = require_has_property_descriptors()();
13346
+ var gOPD = require_gopd();
13347
+ var $TypeError = GetIntrinsic("%TypeError%");
13348
+ var $floor = GetIntrinsic("%Math.floor%");
13349
+ module3.exports = function setFunctionLength(fn2, length2) {
13350
+ if (typeof fn2 !== "function") {
13351
+ throw new $TypeError("`fn` is not a function");
13352
+ }
13353
+ if (typeof length2 !== "number" || length2 < 0 || length2 > 4294967295 || $floor(length2) !== length2) {
13354
+ throw new $TypeError("`length` must be a positive 32-bit integer");
13355
+ }
13356
+ var loose = arguments.length > 2 && !!arguments[2];
13357
+ var functionLengthIsConfigurable = true;
13358
+ var functionLengthIsWritable = true;
13359
+ if ("length" in fn2 && gOPD) {
13360
+ var desc = gOPD(fn2, "length");
13361
+ if (desc && !desc.configurable) {
13362
+ functionLengthIsConfigurable = false;
13363
+ }
13364
+ if (desc && !desc.writable) {
13365
+ functionLengthIsWritable = false;
13366
+ }
13367
+ }
13368
+ if (functionLengthIsConfigurable || functionLengthIsWritable || !loose) {
13369
+ if (hasDescriptors) {
13370
+ define2(fn2, "length", length2, true, true);
13371
+ } else {
13372
+ define2(fn2, "length", length2);
13373
+ }
13374
+ }
13375
+ return fn2;
13376
+ };
13377
+ }
13378
+ });
13379
+
13206
13380
  // ../node_modules/call-bind/index.js
13207
13381
  var require_call_bind = __commonJS({
13208
13382
  "../node_modules/call-bind/index.js"(exports, module3) {
13209
13383
  "use strict";
13210
13384
  var bind = require_function_bind();
13211
13385
  var GetIntrinsic = require_get_intrinsic();
13386
+ var setFunctionLength = require_set_function_length();
13387
+ var $TypeError = GetIntrinsic("%TypeError%");
13212
13388
  var $apply = GetIntrinsic("%Function.prototype.apply%");
13213
13389
  var $call = GetIntrinsic("%Function.prototype.call%");
13214
13390
  var $reflectApply = GetIntrinsic("%Reflect.apply%", true) || bind.call($call, $apply);
13215
- var $gOPD = GetIntrinsic("%Object.getOwnPropertyDescriptor%", true);
13216
13391
  var $defineProperty = GetIntrinsic("%Object.defineProperty%", true);
13217
13392
  var $max = GetIntrinsic("%Math.max%");
13218
13393
  if ($defineProperty) {
@@ -13223,18 +13398,15 @@ var require_call_bind = __commonJS({
13223
13398
  }
13224
13399
  }
13225
13400
  module3.exports = function callBind(originalFunction) {
13226
- var func = $reflectApply(bind, $call, arguments);
13227
- if ($gOPD && $defineProperty) {
13228
- var desc = $gOPD(func, "length");
13229
- if (desc.configurable) {
13230
- $defineProperty(
13231
- func,
13232
- "length",
13233
- { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
13234
- );
13235
- }
13401
+ if (typeof originalFunction !== "function") {
13402
+ throw new $TypeError("a function is required");
13236
13403
  }
13237
- return func;
13404
+ var func = $reflectApply(bind, $call, arguments);
13405
+ return setFunctionLength(
13406
+ func,
13407
+ 1 + $max(0, originalFunction.length - (arguments.length - 1)),
13408
+ true
13409
+ );
13238
13410
  };
13239
13411
  var applyBind = function applyBind2() {
13240
13412
  return $reflectApply(bind, $apply, arguments);
@@ -13486,6 +13658,12 @@ var require_object_inspect = __commonJS({
13486
13658
  if (isString(obj)) {
13487
13659
  return markBoxed(inspect(String(obj)));
13488
13660
  }
13661
+ if (typeof window !== "undefined" && obj === window) {
13662
+ return "{ [object Window] }";
13663
+ }
13664
+ if (obj === global) {
13665
+ return "{ [object globalThis] }";
13666
+ }
13489
13667
  if (!isDate(obj) && !isRegExp(obj)) {
13490
13668
  var ys = arrObjKeys(obj, inspect);
13491
13669
  var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
@@ -19834,9 +20012,9 @@ var require_queue_microtask = __commonJS({
19834
20012
  }
19835
20013
  });
19836
20014
 
19837
- // ../node_modules/cross-fetch/dist/browser-ponyfill.js
20015
+ // ../node_modules/rdflib/node_modules/cross-fetch/dist/browser-ponyfill.js
19838
20016
  var require_browser_ponyfill = __commonJS({
19839
- "../node_modules/cross-fetch/dist/browser-ponyfill.js"(exports, module3) {
20017
+ "../node_modules/rdflib/node_modules/cross-fetch/dist/browser-ponyfill.js"(exports, module3) {
19840
20018
  var global3 = typeof self !== "undefined" ? self : exports;
19841
20019
  var __self__ = function() {
19842
20020
  function F() {
@@ -23358,6 +23536,7 @@ var v4_default = v4;
23358
23536
  var SOLID_CLIENT_AUTHN_KEY_PREFIX = "solidClientAuthn:";
23359
23537
  var PREFERRED_SIGNING_ALG = ["ES256", "RS256"];
23360
23538
  var EVENTS = {
23539
+ // Note that an `error` events MUST be listened to: https://nodejs.org/dist/latest-v16.x/docs/api/events.html#error-events.
23361
23540
  ERROR: "error",
23362
23541
  LOGIN: "login",
23363
23542
  LOGOUT: "logout",
@@ -23373,6 +23552,9 @@ var SCOPE_OFFLINE = "offline_access";
23373
23552
  var SCOPE_WEBID = "webid";
23374
23553
  var DEFAULT_SCOPES = [SCOPE_OPENID, SCOPE_OFFLINE, SCOPE_WEBID].join(" ");
23375
23554
  var buildProxyHandler = (toExclude, errorMessage) => ({
23555
+ // This proxy is only a temporary measure until Session no longer extends
23556
+ // SessionEventEmitter, and the proxying is no longer necessary.
23557
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23376
23558
  get(target5, prop, receiver2) {
23377
23559
  if (!Object.getOwnPropertyNames(import_events.EventEmitter).includes(prop) && Object.getOwnPropertyNames(toExclude).includes(prop)) {
23378
23560
  throw new Error(`${errorMessage}: [${prop}] is not supported`);
@@ -23385,6 +23567,11 @@ var AggregateHandler = class {
23385
23567
  this.handleables = handleables;
23386
23568
  this.handleables = handleables;
23387
23569
  }
23570
+ /**
23571
+ * Helper function that will asynchronously determine the proper handler to use. If multiple
23572
+ * handlers can handle, it will choose the first one in the list
23573
+ * @param params Paramerters to feed to the handler
23574
+ */
23388
23575
  async getProperHandler(params2) {
23389
23576
  const canHandleList = await Promise.all(this.handleables.map((handleable) => handleable.canHandle(...params2)));
23390
23577
  for (let i = 0; i < canHandleList.length; i += 1) {
@@ -23471,12 +23658,28 @@ var AuthorizationCodeWithPkceOidcHandlerBase = class {
23471
23658
  }
23472
23659
  async handleRedirect({ oidcLoginOptions, state: state2, codeVerifier, targetUrl: targetUrl3 }) {
23473
23660
  await Promise.all([
23661
+ // We use the OAuth 'state' value (which should be crypto-random) as
23662
+ // the key in our storage to store our actual SessionID. We do this
23663
+ // 'cos we'll need to lookup our session information again when the
23664
+ // browser is redirected back to us (i.e. the OAuth client
23665
+ // application) from the Authorization Server.
23666
+ // We don't want to use our session ID as the OAuth 'state' value, as
23667
+ // that session ID can be any developer-specified value, and therefore
23668
+ // may not be appropriate (since the OAuth 'state' value should really
23669
+ // be an unguessable crypto-random value).
23670
+ // eslint-disable-next-line no-underscore-dangle
23474
23671
  this.storageUtility.setForUser(state2, {
23475
23672
  sessionId: oidcLoginOptions.sessionId
23476
23673
  }),
23674
+ // Store our login-process state using the session ID as the key.
23675
+ // Strictly speaking, this indirection from our OAuth state value to
23676
+ // our session ID is unnecessary, but it provides a slightly cleaner
23677
+ // separation of concerns.
23477
23678
  this.storageUtility.setForUser(oidcLoginOptions.sessionId, {
23679
+ // eslint-disable-next-line no-underscore-dangle
23478
23680
  codeVerifier,
23479
23681
  issuer: oidcLoginOptions.issuer.toString(),
23682
+ // The redirect URL is read after redirect, so it must be stored now.
23480
23683
  redirectUrl: oidcLoginOptions.redirectUrl,
23481
23684
  dpop: oidcLoginOptions.dpop ? "true" : "false"
23482
23685
  })
@@ -23560,18 +23763,36 @@ var SessionInfoManagerBase = class {
23560
23763
  get(_) {
23561
23764
  throw new Error("Not implemented");
23562
23765
  }
23766
+ // eslint-disable-next-line class-methods-use-this
23563
23767
  async getAll() {
23564
23768
  throw new Error("Not implemented");
23565
23769
  }
23770
+ /**
23771
+ * This function removes all session-related information from storage.
23772
+ * @param sessionId the session identifier
23773
+ * @param storage the storage where session info is stored
23774
+ * @hidden
23775
+ */
23566
23776
  async clear(sessionId) {
23567
23777
  return clear(sessionId, this.storageUtility);
23568
23778
  }
23779
+ /**
23780
+ * Registers a new session, so that its ID can be retrieved.
23781
+ * @param sessionId
23782
+ */
23569
23783
  async register(_sessionId) {
23570
23784
  throw new Error("Not implemented");
23571
23785
  }
23786
+ /**
23787
+ * Returns all the registered session IDs. Differs from getAll, which also
23788
+ * returns additional session information.
23789
+ */
23572
23790
  async getRegisteredSessionIdAll() {
23573
23791
  throw new Error("Not implemented");
23574
23792
  }
23793
+ /**
23794
+ * Deletes all information about all sessions, including their registrations.
23795
+ */
23575
23796
  async clearAll() {
23576
23797
  throw new Error("Not implemented");
23577
23798
  }
@@ -23635,6 +23856,8 @@ async function handleRegistration(options, issuerConfig, storageUtility, clientR
23635
23856
  }, issuerConfig);
23636
23857
  }
23637
23858
  await storageUtility.setForUser(options.sessionId, {
23859
+ // If the client is either static or solid-oidc compliant, its client ID cannot be undefined.
23860
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
23638
23861
  clientId: options.clientId
23639
23862
  });
23640
23863
  if (options.clientSecret) {
@@ -23648,6 +23871,7 @@ async function handleRegistration(options, issuerConfig, storageUtility, clientR
23648
23871
  });
23649
23872
  }
23650
23873
  return {
23874
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
23651
23875
  clientId: options.clientId,
23652
23876
  clientSecret: options.clientSecret,
23653
23877
  clientName: options.clientName,
@@ -23788,17 +24012,20 @@ var InMemoryStorage = class {
23788
24012
  }
23789
24013
  };
23790
24014
  var ConfigurationError = class extends Error {
24015
+ /* istanbul ignore next */
23791
24016
  constructor(message4) {
23792
24017
  super(message4);
23793
24018
  }
23794
24019
  };
23795
24020
  var InvalidResponseError = class extends Error {
24021
+ /* istanbul ignore next */
23796
24022
  constructor(missingFields) {
23797
24023
  super(`Invalid response from OIDC provider: missing fields ${missingFields}`);
23798
24024
  this.missingFields = missingFields;
23799
24025
  }
23800
24026
  };
23801
24027
  var OidcProviderError = class extends Error {
24028
+ /* istanbul ignore next */
23802
24029
  constructor(message4, error5, errorDescription) {
23803
24030
  super(message4);
23804
24031
  this.error = error5;
@@ -23872,7 +24099,10 @@ async function refreshAccessToken(refreshOptions, dpopKey, eventEmitter) {
23872
24099
  }
23873
24100
  var computeRefreshDelay = (expiresIn) => {
23874
24101
  if (expiresIn !== void 0) {
23875
- return expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS > 0 ? expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS : expiresIn;
24102
+ return expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS > 0 ? (
24103
+ // We want to refresh the token 5 seconds before they actually expire.
24104
+ expiresIn - REFRESH_BEFORE_EXPIRATION_SECONDS
24105
+ ) : expiresIn;
23876
24106
  }
23877
24107
  return DEFAULT_EXPIRATION_TIME_SECONDS;
23878
24108
  };
@@ -23885,7 +24115,14 @@ async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
23885
24115
  const proactivelyRefreshToken = async () => {
23886
24116
  var _a2, _b, _c, _d;
23887
24117
  try {
23888
- const { accessToken: refreshedAccessToken, refreshToken, expiresIn } = await refreshAccessToken(currentRefreshOptions, options.dpopKey, options.eventEmitter);
24118
+ const { accessToken: refreshedAccessToken, refreshToken, expiresIn } = await refreshAccessToken(
24119
+ currentRefreshOptions,
24120
+ // If currentRefreshOptions is defined, options is necessarily defined too.
24121
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24122
+ options.dpopKey,
24123
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24124
+ options.eventEmitter
24125
+ );
23889
24126
  currentAccessToken = refreshedAccessToken;
23890
24127
  if (refreshToken !== void 0) {
23891
24128
  currentRefreshOptions.refreshToken = refreshToken;
@@ -23903,7 +24140,12 @@ async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
23903
24140
  }
23904
24141
  }
23905
24142
  };
23906
- latestTimeout = setTimeout(proactivelyRefreshToken, computeRefreshDelay(options.expiresIn) * 1e3);
24143
+ latestTimeout = setTimeout(
24144
+ proactivelyRefreshToken,
24145
+ // If currentRefreshOptions is defined, options is necessarily defined too.
24146
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24147
+ computeRefreshDelay(options.expiresIn) * 1e3
24148
+ );
23907
24149
  (_a = options.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit(EVENTS.TIMEOUT_SET, latestTimeout);
23908
24150
  } else if (options !== void 0 && options.eventEmitter !== void 0) {
23909
24151
  const expirationTimeout = setTimeout(() => {
@@ -23919,7 +24161,14 @@ async function buildAuthenticatedFetch(unauthFetch, accessToken, options) {
23919
24161
  }
23920
24162
  const hasBeenRedirected = response6.url !== url7;
23921
24163
  if (hasBeenRedirected && (options === null || options === void 0 ? void 0 : options.dpopKey) !== void 0) {
23922
- response6 = await makeAuthenticatedRequest(unauthFetch, currentAccessToken, response6.url, requestInit, options.dpopKey);
24164
+ response6 = await makeAuthenticatedRequest(
24165
+ unauthFetch,
24166
+ currentAccessToken,
24167
+ // Replace the original target IRI (`url`) by the redirection target
24168
+ response6.url,
24169
+ requestInit,
24170
+ options.dpopKey
24171
+ );
23923
24172
  }
23924
24173
  return response6;
23925
24174
  };
@@ -23961,6 +24210,7 @@ async function registerClient(options, issuerConfig) {
23961
24210
  }
23962
24211
  const signingAlg = determineSigningAlg(issuerConfig.idTokenSigningAlgValuesSupported, PREFERRED_SIGNING_ALG);
23963
24212
  const config = {
24213
+ /* eslint-disable camelcase */
23964
24214
  client_name: options.clientName,
23965
24215
  application_type: "web",
23966
24216
  redirect_uris: [(_a = options.redirectUrl) === null || _a === void 0 ? void 0 : _a.toString()],
@@ -23968,6 +24218,7 @@ async function registerClient(options, issuerConfig) {
23968
24218
  token_endpoint_auth_method: "client_secret_basic",
23969
24219
  id_token_signed_response_alg: signingAlg,
23970
24220
  grant_types: ["authorization_code", "refresh_token"]
24221
+ /* eslint-enable camelcase */
23971
24222
  };
23972
24223
  const headers = {
23973
24224
  "Content-Type": "application/json"
@@ -24059,11 +24310,13 @@ async function getTokens(issuer2, client, data2, dpop) {
24059
24310
  headers.Authorization = `Basic ${btoa(`${client.clientId}:${client.clientSecret}`)}`;
24060
24311
  }
24061
24312
  const requestBody = {
24313
+ /* eslint-disable camelcase */
24062
24314
  grant_type: data2.grantType,
24063
24315
  redirect_uri: data2.redirectUrl,
24064
24316
  code: data2.code,
24065
24317
  code_verifier: data2.codeVerifier,
24066
24318
  client_id: client.clientId
24319
+ /* eslint-enable camelcase */
24067
24320
  };
24068
24321
  const tokenRequestInit = {
24069
24322
  method: "POST",
@@ -24087,7 +24340,26 @@ async function getBearerToken(redirectUrl) {
24087
24340
  let signinResponse;
24088
24341
  try {
24089
24342
  const client = new import_oidc_client.OidcClient({
24343
+ // TODO: We should look at the various interfaces being used for storage,
24344
+ // i.e. between oidc-client-js (WebStorageStoreState), localStorage
24345
+ // (which has an interface Storage), and our own proprietary interface
24346
+ // IStorage - i.e. we should really just be using the browser Web Storage
24347
+ // API, e.g. "stateStore: window.localStorage,".
24348
+ // We are instantiating a new instance here, so the only value we need to
24349
+ // explicitly provide is the response mode (default otherwise will look
24350
+ // for a hash '#' fragment!).
24351
+ // eslint-disable-next-line camelcase
24090
24352
  response_mode: "query",
24353
+ // The userinfo endpoint on NSS fails, so disable this for now
24354
+ // Note that in Solid, information should be retrieved from the
24355
+ // profile referenced by the WebId.
24356
+ // TODO: Note that this is heavy-handed, and that this userinfo check
24357
+ // verifies that the `sub` claim in the id token you get along with the
24358
+ // access token matches the sub claim associated with the access token at
24359
+ // the userinfo endpoint.
24360
+ // That is a useful check, and in the future it should be only disabled
24361
+ // against NSS, and not in general.
24362
+ // Issue tracker: https://github.com/solid/node-solid-server/issues/1490
24091
24363
  loadUserInfo: false
24092
24364
  });
24093
24365
  signinResponse = await client.processSigninResponse(redirectUrl);
@@ -24108,6 +24380,13 @@ async function getBearerToken(redirectUrl) {
24108
24380
  accessToken: signinResponse.access_token,
24109
24381
  idToken: signinResponse.id_token,
24110
24382
  webId,
24383
+ // Although not a field in the TypeScript response interface, the refresh
24384
+ // token (which can optionally come back with the access token (if, as per
24385
+ // the OAuth2 spec, we requested one using the scope of 'offline_access')
24386
+ // will be included in the signin response object.
24387
+ // eslint-disable-next-line camelcase
24388
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24389
+ // @ts-ignore
24111
24390
  refreshToken: signinResponse.refresh_token
24112
24391
  };
24113
24392
  } catch (err) {
@@ -24143,6 +24422,8 @@ async function refresh(refreshToken, issuer2, client, dpopKey) {
24143
24422
  let authHeader = {};
24144
24423
  if (client.clientSecret !== void 0) {
24145
24424
  authHeader = {
24425
+ // We assume that client_secret_basic is the client authentication method.
24426
+ // TODO: Get the authentication method from the IClient configuration object.
24146
24427
  Authorization: `Basic ${btoa(`${client.clientId}:${client.clientSecret}`)}`
24147
24428
  };
24148
24429
  } else if (isValidUrl2(client.clientId)) {
@@ -24179,13 +24460,28 @@ function removeOidcQueryParam(redirectUrl) {
24179
24460
  cleanedUrl.searchParams.delete("code");
24180
24461
  cleanedUrl.searchParams.delete("state");
24181
24462
  cleanedUrl.hash = "";
24182
- if (redirectUrl.includes(`${cleanedUrl.origin}/`)) {
24463
+ if (
24464
+ // The trailing slash is present in the original redirect URL
24465
+ redirectUrl.includes(`${cleanedUrl.origin}/`)
24466
+ ) {
24183
24467
  return cleanedUrl.href;
24184
24468
  }
24185
- return `${cleanedUrl.origin}${cleanedUrl.href.substring(cleanedUrl.origin.length + 1)}`;
24469
+ return `${cleanedUrl.origin}${cleanedUrl.href.substring(
24470
+ // Adds 1 to the origin length to remove the trailing slash
24471
+ cleanedUrl.origin.length + 1
24472
+ )}`;
24186
24473
  }
24187
24474
  async function clearOidcPersistentStorage() {
24188
24475
  const client = new import_oidc_client.OidcClient({
24476
+ // TODO: We should look at the various interfaces being used for storage,
24477
+ // i.e. between oidc-client-js (WebStorageStoreState), localStorage
24478
+ // (which has an interface Storage), and our own proprietary interface
24479
+ // IStorage - i.e. we should really just be using the browser Web Storage
24480
+ // API, e.g. "stateStore: window.localStorage,".
24481
+ // We are instantiating a new instance here, so the only value we need to
24482
+ // explicitly provide is the response mode (default otherwise will look
24483
+ // for a hash '#' fragment!).
24484
+ // eslint-disable-next-line camelcase
24189
24485
  response_mode: "query"
24190
24486
  });
24191
24487
  await client.clearStaleState(new import_oidc_client.WebStorageStateStore({}));
@@ -24219,6 +24515,7 @@ var ClientAuthentication2 = class extends ClientAuthentication {
24219
24515
  await this.loginHandler.handle({
24220
24516
  ...options,
24221
24517
  redirectUrl,
24518
+ // If no clientName is provided, the clientId may be used instead.
24222
24519
  clientName: (_b = options.clientName) !== null && _b !== void 0 ? _b : options.clientId,
24223
24520
  eventEmitter
24224
24521
  });
@@ -24235,7 +24532,7 @@ var ClientAuthentication2 = class extends ClientAuthentication {
24235
24532
  const redirectInfo = await this.redirectHandler.handle(url7, eventEmitter);
24236
24533
  this.fetch = redirectInfo.fetch.bind(window);
24237
24534
  this.boundLogout = redirectInfo.getLogoutUrl;
24238
- this.cleanUrlAfterRedirect(url7);
24535
+ await this.cleanUrlAfterRedirect(url7);
24239
24536
  return {
24240
24537
  isLoggedIn: redirectInfo.isLoggedIn,
24241
24538
  webId: redirectInfo.webId,
@@ -24243,13 +24540,13 @@ var ClientAuthentication2 = class extends ClientAuthentication {
24243
24540
  expirationDate: redirectInfo.expirationDate
24244
24541
  };
24245
24542
  } catch (err) {
24246
- this.cleanUrlAfterRedirect(url7);
24543
+ await this.cleanUrlAfterRedirect(url7);
24247
24544
  eventEmitter.emit(EVENTS.ERROR, "redirect", err);
24248
24545
  return void 0;
24249
24546
  }
24250
24547
  };
24251
24548
  }
24252
- cleanUrlAfterRedirect(url7) {
24549
+ async cleanUrlAfterRedirect(url7) {
24253
24550
  const cleanedUpUrl = new URL(url7);
24254
24551
  cleanedUpUrl.searchParams.delete("state");
24255
24552
  cleanedUpUrl.searchParams.delete("code");
@@ -24259,6 +24556,11 @@ var ClientAuthentication2 = class extends ClientAuthentication {
24259
24556
  cleanedUpUrl.searchParams.delete("error_description");
24260
24557
  cleanedUpUrl.searchParams.delete("iss");
24261
24558
  window.history.replaceState(null, "", cleanedUpUrl.toString());
24559
+ while (window.location.href !== cleanedUpUrl.href) {
24560
+ await new Promise((resolve) => {
24561
+ setTimeout(() => resolve(), 1);
24562
+ });
24563
+ }
24262
24564
  }
24263
24565
  };
24264
24566
  function hasIssuer(options) {
@@ -24291,7 +24593,13 @@ var OidcLoginHandler = class {
24291
24593
  const issuerConfig = await this.issuerConfigFetcher.fetchConfig(options.oidcIssuer);
24292
24594
  const clientRegistration = await handleRegistration(options, issuerConfig, this.storageUtility, this.clientRegistrar);
24293
24595
  const OidcOptions = {
24596
+ // Note that here, the issuer is not the one from the received options, but
24597
+ // from the issuer's config. This enforces the canonical URL is used and stored,
24598
+ // which is also the one present in the ID token, so storing a technically
24599
+ // valid, but different issuer URL (e.g. using a trailing slash or not) now
24600
+ // could prevent from validating the ID token later.
24294
24601
  issuer: issuerConfig.issuer,
24602
+ // TODO: differentiate if DPoP should be true
24295
24603
  dpop: options.tokenType.toLowerCase() === "dpop",
24296
24604
  ...options,
24297
24605
  issuerConfiguration: issuerConfig,
@@ -24312,6 +24620,9 @@ var AuthorizationCodeWithPkceOidcHandler = class extends AuthorizationCodeWithPk
24312
24620
  response_type: "code",
24313
24621
  scope: DEFAULT_SCOPES,
24314
24622
  filterProtocolClaims: true,
24623
+ // The userinfo endpoint on NSS fails, so disable this for now
24624
+ // Note that in Solid, information should be retrieved from the
24625
+ // profile referenced by the WebId.
24315
24626
  loadUserInfo: false,
24316
24627
  code_verifier: true,
24317
24628
  prompt: (_a = oidcLoginOptions.prompt) !== null && _a !== void 0 ? _a : "consent"
@@ -24321,7 +24632,9 @@ var AuthorizationCodeWithPkceOidcHandler = class extends AuthorizationCodeWithPk
24321
24632
  const signingRequest = await oidcClientLibrary.createSigninRequest();
24322
24633
  return await this.handleRedirect({
24323
24634
  oidcLoginOptions,
24635
+ // eslint-disable-next-line no-underscore-dangle
24324
24636
  state: signingRequest.state._id,
24637
+ // eslint-disable-next-line no-underscore-dangle
24325
24638
  codeVerifier: signingRequest.state._code_verifier,
24326
24639
  targetUrl: signingRequest.url.toString()
24327
24640
  });
@@ -24436,12 +24749,19 @@ var IssuerConfigFetcher = class _IssuerConfigFetcher {
24436
24749
  this.storageUtility = storageUtility;
24437
24750
  this.storageUtility = storageUtility;
24438
24751
  }
24752
+ // This method needs no state (so can be static), and can be exposed to allow
24753
+ // callers to know where this implementation puts state it needs.
24439
24754
  static getLocalStorageKey(issuer2) {
24440
24755
  return `issuerConfig:${issuer2}`;
24441
24756
  }
24442
24757
  async fetchConfig(issuer2) {
24443
24758
  let issuerConfig;
24444
- const openIdConfigUrl = new URL(WELL_KNOWN_OPENID_CONFIG, issuer2.endsWith("/") ? issuer2 : `${issuer2}/`).href;
24759
+ const openIdConfigUrl = new URL(
24760
+ WELL_KNOWN_OPENID_CONFIG,
24761
+ // Make sure to append a slash at issuer URL, so that the .well-known URL
24762
+ // includes the full issuer path. See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig.
24763
+ issuer2.endsWith("/") ? issuer2 : `${issuer2}/`
24764
+ ).href;
24445
24765
  const issuerConfigRequestBody = await fetch2.call(globalThis, openIdConfigUrl);
24446
24766
  try {
24447
24767
  issuerConfig = processConfig(await issuerConfigRequestBody.json());
@@ -24506,9 +24826,16 @@ var SessionInfoManager = class extends SessionInfoManagerBase {
24506
24826
  issuer: issuer2,
24507
24827
  clientAppId: clientId,
24508
24828
  clientAppSecret: clientSecret,
24829
+ // Default the token type to DPoP if unspecified.
24509
24830
  tokenType: tokenType !== null && tokenType !== void 0 ? tokenType : "DPoP"
24510
24831
  };
24511
24832
  }
24833
+ /**
24834
+ * This function removes all session-related information from storage.
24835
+ * @param sessionId the session identifier
24836
+ * @param storage the storage where session info is stored
24837
+ * @hidden
24838
+ */
24512
24839
  async clear(sessionId) {
24513
24840
  return clear2(sessionId, this.storageUtility);
24514
24841
  }
@@ -24574,6 +24901,8 @@ var AuthCodeRedirectHandler = class {
24574
24901
  if (isDpop) {
24575
24902
  tokens = await getDpopToken(issuerConfig, client, {
24576
24903
  grantType: "authorization_code",
24904
+ // We rely on our 'canHandle' function checking that the OAuth 'code'
24905
+ // parameter is present in our query string.
24577
24906
  code: url7.searchParams.get("code"),
24578
24907
  codeVerifier,
24579
24908
  redirectUrl: storedRedirectIri
@@ -24650,13 +24979,21 @@ var ClientRegistrar = class {
24650
24979
  this.storageUtility = storageUtility;
24651
24980
  }
24652
24981
  async getClient(options, issuerConfig) {
24653
- const [storedClientId, storedClientSecret] = await Promise.all([
24982
+ const [
24983
+ storedClientId,
24984
+ storedClientSecret
24985
+ // storedClientName,
24986
+ ] = await Promise.all([
24654
24987
  this.storageUtility.getForUser(options.sessionId, "clientId", {
24655
24988
  secure: false
24656
24989
  }),
24657
24990
  this.storageUtility.getForUser(options.sessionId, "clientSecret", {
24658
24991
  secure: false
24659
24992
  })
24993
+ // this.storageUtility.getForUser(options.sessionId, "clientName", {
24994
+ // // FIXME: figure out how to persist secure storage at reload
24995
+ // secure: false,
24996
+ // }),
24660
24997
  ]);
24661
24998
  if (storedClientId) {
24662
24999
  return {
@@ -24677,6 +25014,9 @@ var ClientRegistrar = class {
24677
25014
  infoToSave.idTokenSignedResponseAlg = registeredClient.idTokenSignedResponseAlg;
24678
25015
  }
24679
25016
  await this.storageUtility.setForUser(options.sessionId, infoToSave, {
25017
+ // FIXME: figure out how to persist secure storage at reload
25018
+ // Otherwise, the client info cannot be retrieved from storage, and
25019
+ // the lib tries to re-register the client on each fetch
24680
25020
  secure: false
24681
25021
  });
24682
25022
  return registeredClient;
@@ -24745,6 +25085,8 @@ function getClientAuthenticationWithDependencies(dependencies3) {
24745
25085
  const redirectHandler = new AggregateRedirectHandler([
24746
25086
  new ErrorOidcHandler(),
24747
25087
  new AuthCodeRedirectHandler(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokenRefresher),
25088
+ // This catch-all class will always be able to handle the
25089
+ // redirect IRI, so it must be registered last.
24748
25090
  new FallbackRedirectHandler()
24749
25091
  ]);
24750
25092
  return new ClientAuthentication2(loginHandler, redirectHandler, new IWaterfallLogoutHandler(sessionInfoManager, redirector), sessionInfoManager, issuerConfigFetcher);
@@ -24773,6 +25115,21 @@ function isLoggedIn(sessionInfo) {
24773
25115
  return !!(sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.isLoggedIn);
24774
25116
  }
24775
25117
  var Session = class _Session extends import_events2.default {
25118
+ /**
25119
+ * Session object constructor. Typically called as follows:
25120
+ *
25121
+ * ```typescript
25122
+ * const session = new Session();
25123
+ * ```
25124
+ *
25125
+ * See also [getDefaultSession](https://docs.inrupt.com/developer-tools/api/javascript/solid-client-authn-browser/functions.html#getdefaultsession).
25126
+ *
25127
+ * @param sessionOptions The options enabling the correct instantiation of
25128
+ * the session. Either both storages or clientAuthentication are required. For
25129
+ * more information, see {@link ISessionOptions}.
25130
+ * @param sessionId A string uniquely identifying the session.
25131
+ *
25132
+ */
24776
25133
  constructor(sessionOptions = {}, sessionId = void 0) {
24777
25134
  super();
24778
25135
  this.tokenRequestInProgress = false;
@@ -24781,6 +25138,7 @@ var Session = class _Session extends import_events2.default {
24781
25138
  await this.clientAuthentication.login({
24782
25139
  sessionId: this.info.sessionId,
24783
25140
  ...options,
25141
+ // Defaults the token type to DPoP
24784
25142
  tokenType: (_a = options.tokenType) !== null && _a !== void 0 ? _a : "DPoP"
24785
25143
  }, this.events);
24786
25144
  return new Promise(() => {
@@ -24857,18 +25215,55 @@ var Session = class _Session extends import_events2.default {
24857
25215
  this.events.on(EVENTS.SESSION_EXPIRED, () => this.internalLogout(false));
24858
25216
  this.events.on(EVENTS.ERROR, () => this.internalLogout(false));
24859
25217
  }
25218
+ /**
25219
+ * Register a callback function to be called when a user completes login.
25220
+ *
25221
+ * The callback is called when {@link handleIncomingRedirect} completes successfully.
25222
+ *
25223
+ * @param callback The function called when a user completes login.
25224
+ * @deprecated Prefer session.events.on(EVENTS.LOGIN, callback)
25225
+ */
24860
25226
  onLogin(callback) {
24861
25227
  this.events.on(EVENTS.LOGIN, callback);
24862
25228
  }
25229
+ /**
25230
+ * Register a callback function to be called when a user logs out:
25231
+ *
25232
+ * @param callback The function called when a user completes logout.
25233
+ * @deprecated Prefer session.events.on(EVENTS.LOGOUT, callback)
25234
+ */
24863
25235
  onLogout(callback) {
24864
25236
  this.events.on(EVENTS.LOGOUT, callback);
24865
25237
  }
25238
+ /**
25239
+ * Register a callback function to be called when a user logs out:
25240
+ *
25241
+ * @param callback The function called when an error occurs.
25242
+ * @since 1.11.0
25243
+ * @deprecated Prefer session.events.on(EVENTS.ERROR, callback)
25244
+ */
24866
25245
  onError(callback) {
24867
25246
  this.events.on(EVENTS.ERROR, callback);
24868
25247
  }
25248
+ /**
25249
+ * Register a callback function to be called when a session is restored.
25250
+ *
25251
+ * Note: the callback will be called with the saved value of the 'current URL'
25252
+ * at the time the session was restored.
25253
+ *
25254
+ * @param callback The function called when a user's already logged-in session is restored, e.g., after a silent authentication is completed after a page refresh.
25255
+ * @deprecated Prefer session.events.on(EVENTS.SESSION_RESTORED, callback)
25256
+ */
24869
25257
  onSessionRestore(callback) {
24870
25258
  this.events.on(EVENTS.SESSION_RESTORED, callback);
24871
25259
  }
25260
+ /**
25261
+ * Register a callback that runs when the session expires and can no longer
25262
+ * make authenticated requests, but following a user logout.
25263
+ * @param callback The function that runs on session expiration.
25264
+ * @since 1.11.0
25265
+ * @deprecated Prefer session.events.on(EVENTS.SESSION_EXPIRED, callback)
25266
+ */
24872
25267
  onSessionExpiration(callback) {
24873
25268
  this.events.on(EVENTS.SESSION_EXPIRED, callback);
24874
25269
  }