@niledatabase/server 5.0.0-alpha.16 → 5.0.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import pg from 'pg';
5
5
  var ExtensionState = /* @__PURE__ */ ((ExtensionState2) => {
6
6
  ExtensionState2["onHandleRequest"] = "onHandleRequest";
7
7
  ExtensionState2["onRequest"] = "onRequest";
8
- ExtensionState2["onResponse"] = "onResposne";
8
+ ExtensionState2["onResponse"] = "onResponse";
9
9
  return ExtensionState2;
10
10
  })(ExtensionState || {});
11
11
  var APIErrorErrorCodeEnum = {
@@ -215,7 +215,7 @@ async function request(url, _init, config) {
215
215
  text: await loggingRes?.text()
216
216
  });
217
217
  const updatedRes = await config.extensionCtx?.runExtensions(
218
- "onResposne" /* onResponse */,
218
+ "onResponse" /* onResponse */,
219
219
  config,
220
220
  params
221
221
  );
@@ -3078,7 +3078,7 @@ function bindRunExtensions(instance) {
3078
3078
  debug(`${ext.id ?? create2.name} ran onRequest`);
3079
3079
  continue;
3080
3080
  }
3081
- if (ext.onResponse && toRun === "onResposne" /* onResponse */) {
3081
+ if (ext.onResponse && toRun === "onResponse" /* onResponse */) {
3082
3082
  const result = await ext.onResponse(param);
3083
3083
  if (result != null) {
3084
3084
  return result;
@@ -3223,6 +3223,19 @@ var Server = class {
3223
3223
  * @returns undefined
3224
3224
  */
3225
3225
  setContext = (req, ...remaining) => {
3226
+ let ok = false;
3227
+ if (req && typeof req === "object" && "tenantId" in req) {
3228
+ ok = true;
3229
+ this.#config.tenantId = req.tenantId;
3230
+ }
3231
+ if (req && typeof req === "object" && "userId" in req) {
3232
+ ok = true;
3233
+ this.#config.userId = req.userId;
3234
+ }
3235
+ if (req && typeof req === "object" && "preserveHeaders" in req) {
3236
+ ok = true;
3237
+ this.#preserveHeaders = Boolean(req.preserveHeaders);
3238
+ }
3226
3239
  let atLeastOne = false;
3227
3240
  if (this.#config?.extensions) {
3228
3241
  for (const create2 of this.#config.extensions) {
@@ -3255,19 +3268,6 @@ var Server = class {
3255
3268
  }
3256
3269
  } catch {
3257
3270
  }
3258
- let ok = false;
3259
- if (req && typeof req === "object" && "tenantId" in req) {
3260
- ok = true;
3261
- this.#config.tenantId = req.tenantId;
3262
- }
3263
- if (req && typeof req === "object" && "userId" in req) {
3264
- ok = true;
3265
- this.#config.userId = req.userId;
3266
- }
3267
- if (req && typeof req === "object" && "preserveHeaders" in req) {
3268
- ok = true;
3269
- this.#preserveHeaders = Boolean(req.preserveHeaders);
3270
- }
3271
3271
  if (ok) {
3272
3272
  return;
3273
3273
  }
@@ -3290,6 +3290,17 @@ var Server = class {
3290
3290
  }
3291
3291
  };
3292
3292
  getContext() {
3293
+ if (this.#config?.extensions) {
3294
+ for (const create2 of this.#config.extensions) {
3295
+ if (typeof create2 !== "function") {
3296
+ continue;
3297
+ }
3298
+ const ext = create2(this);
3299
+ if (typeof ext.onGetContext === "function") {
3300
+ return ext.onGetContext();
3301
+ }
3302
+ }
3303
+ }
3293
3304
  return {
3294
3305
  headers: this.#headers,
3295
3306
  userId: this.#config?.userId,