@niledatabase/server 3.0.0 → 3.1.0-alpha.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.
package/dist/index.mjs CHANGED
@@ -90,7 +90,11 @@ async function request(url, _init, config) {
90
90
  updatedHeaders.set(X_NILE_SECURECOOKIES, String(config.secureCookies));
91
91
  }
92
92
  updatedHeaders.set("host", requestUrl.host);
93
- updatedHeaders.set(X_NILE_ORIGIN, requestUrl.origin);
93
+ if (config.api.callbackUrl) {
94
+ updatedHeaders.set(X_NILE_ORIGIN, config.api.callbackUrl);
95
+ } else {
96
+ updatedHeaders.set(X_NILE_ORIGIN, requestUrl.origin);
97
+ }
94
98
  const params = { ...init, headers: updatedHeaders };
95
99
  if (params.method === "POST" || params.method === "PUT") {
96
100
  try {
@@ -162,6 +166,13 @@ async function auth(req, config) {
162
166
  return void 0;
163
167
  }
164
168
  }
169
+ var getCallbackUrl = (cfg) => {
170
+ const { config } = cfg;
171
+ if (stringCheck(process.env.NILEDB_CALLBACK_URL)) {
172
+ return process.env.NILEDB_CALLBACK_URL;
173
+ }
174
+ return config?.api?.callbackUrl;
175
+ };
165
176
  var getSecureCookies = (cfg) => {
166
177
  const { config } = cfg;
167
178
  if (stringCheck(process.env.NILEDB_SECURECOOKIES)) {
@@ -393,14 +404,16 @@ var stringCheck = (str) => {
393
404
  var ApiConfig = class {
394
405
  cookieKey;
395
406
  basePath;
407
+ /**
408
+ * The client side callback url. Defaults to nothing (so nile.origin will be it), but in the cases of x-origin, you want to set this explicitly to be sure nile-auth does the right thing
409
+ * If this is set, any `callbackUrl` from the client will be ignored.
410
+ */
411
+ callbackUrl;
396
412
  _token;
397
- constructor({
398
- basePath,
399
- cookieKey,
400
- token
401
- }) {
413
+ constructor({ basePath, cookieKey, token, callbackUrl }) {
402
414
  this.basePath = basePath;
403
415
  this.cookieKey = cookieKey;
416
+ this.callbackUrl = callbackUrl;
404
417
  this._token = token;
405
418
  }
406
419
  get token() {
@@ -459,6 +472,7 @@ var Config = class {
459
472
  this._tenantId = getTenantId(envVarConfig);
460
473
  this.debug = Boolean(config?.debug);
461
474
  this._userId = config?.userId;
475
+ const callbackUrl = config?.api?.callbackUrl ?? getCallbackUrl(envVarConfig);
462
476
  const basePath = getBasePath(envVarConfig);
463
477
  const { host, port, ...dbConfig } = config?.db ?? {};
464
478
  const configuredHost = host ?? getDbHost(envVarConfig);
@@ -466,7 +480,8 @@ var Config = class {
466
480
  this.api = new ApiConfig({
467
481
  basePath,
468
482
  cookieKey: config?.api?.cookieKey ?? "token",
469
- token: getToken({ config })
483
+ token: getToken({ config }),
484
+ callbackUrl
470
485
  });
471
486
  this.db = {
472
487
  user: this.user,
@@ -485,6 +500,7 @@ var Config = class {
485
500
  config
486
501
  };
487
502
  const { host, port, ...dbConfig } = config.db ?? {};
503
+ const callbackUrl = config?.api?.callbackUrl ?? getCallbackUrl(envVarConfig);
488
504
  let configuredHost = host ?? getDbHost(envVarConfig);
489
505
  const configuredPort = port ?? getDbPort(envVarConfig);
490
506
  let basePath = getBasePath(envVarConfig);
@@ -493,7 +509,8 @@ var Config = class {
493
509
  this.api = new ApiConfig({
494
510
  basePath,
495
511
  cookieKey: config?.api?.cookieKey ?? "token",
496
- token: getToken({ config })
512
+ token: getToken({ config }),
513
+ callbackUrl
497
514
  });
498
515
  this.db = {
499
516
  user: this.user,
@@ -582,7 +599,8 @@ var Config = class {
582
599
  this.api = new ApiConfig({
583
600
  basePath,
584
601
  cookieKey: config?.api?.cookieKey ?? "token",
585
- token: getToken({ config })
602
+ token: getToken({ config }),
603
+ callbackUrl
586
604
  });
587
605
  this.db = {
588
606
  user: this.user,
@@ -1468,7 +1486,7 @@ async function route10(request2, config) {
1468
1486
  if (request2.method === "POST") {
1469
1487
  init.body = request2.body;
1470
1488
  const [provider] = new URL(request2.url).pathname.split("/").reverse();
1471
- url = `${proxyRoutes(config)[key7]}/${provider}`;
1489
+ url = `${proxyRoutes(config)[key7]}${provider !== "signout" ? `/${provider}` : ""}`;
1472
1490
  }
1473
1491
  const res = await request(url, { ...init, request: request2 }, config);
1474
1492
  return res;