@niledatabase/server 3.0.1-alpha.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.d.mts +55 -53
- package/dist/index.d.ts +55 -53
- package/dist/index.js +28 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
import pg, { PoolConfig, PoolClient } from 'pg';
|
|
2
2
|
|
|
3
|
+
type ConfigRoutes = {
|
|
4
|
+
SIGNIN?: string;
|
|
5
|
+
SESSION?: string;
|
|
6
|
+
PROVIDERS?: string;
|
|
7
|
+
CSRF?: string;
|
|
8
|
+
CALLBACK?: string;
|
|
9
|
+
SIGNOUT?: string;
|
|
10
|
+
ME?: string;
|
|
11
|
+
ERROR?: string;
|
|
12
|
+
TENANTS?: string;
|
|
13
|
+
TENANT_USERS?: string;
|
|
14
|
+
USERS?: string;
|
|
15
|
+
};
|
|
16
|
+
type ApiParams = {
|
|
17
|
+
basePath?: string | undefined;
|
|
18
|
+
cookieKey?: string;
|
|
19
|
+
token?: string | undefined;
|
|
20
|
+
callbackUrl?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
declare class ApiConfig {
|
|
23
|
+
cookieKey?: string;
|
|
24
|
+
basePath?: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* 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
|
|
27
|
+
* If this is set, any `callbackUrl` from the client will be ignored.
|
|
28
|
+
*/
|
|
29
|
+
callbackUrl?: string;
|
|
30
|
+
private _token?;
|
|
31
|
+
constructor({ basePath, cookieKey, token, callbackUrl }: ApiParams);
|
|
32
|
+
get token(): string | undefined;
|
|
33
|
+
set token(value: string | undefined);
|
|
34
|
+
}
|
|
35
|
+
declare class Config {
|
|
36
|
+
user: string;
|
|
37
|
+
password: string;
|
|
38
|
+
databaseId: string;
|
|
39
|
+
databaseName: string;
|
|
40
|
+
routePrefix?: string;
|
|
41
|
+
routes?: ConfigRoutes;
|
|
42
|
+
logger?: LoggerType;
|
|
43
|
+
secureCookies?: boolean | undefined;
|
|
44
|
+
debug: boolean;
|
|
45
|
+
db: NilePoolConfig;
|
|
46
|
+
api: ApiConfig;
|
|
47
|
+
private _tenantId?;
|
|
48
|
+
private _userId?;
|
|
49
|
+
get tenantId(): string | undefined | null;
|
|
50
|
+
set tenantId(value: string | undefined | null);
|
|
51
|
+
get userId(): string | undefined | null;
|
|
52
|
+
set userId(value: string | undefined | null);
|
|
53
|
+
constructor(config?: ServerConfig, logger?: string);
|
|
54
|
+
configure: (config: ServerConfig) => Promise<Config>;
|
|
55
|
+
}
|
|
56
|
+
|
|
3
57
|
type Opts = {
|
|
4
58
|
basePath?: string;
|
|
5
59
|
fetch?: typeof fetch;
|
|
@@ -24,12 +78,7 @@ type ServerConfig = {
|
|
|
24
78
|
configureUrl?: string;
|
|
25
79
|
secureCookies?: boolean;
|
|
26
80
|
db?: NilePoolConfig;
|
|
27
|
-
api?:
|
|
28
|
-
version?: number;
|
|
29
|
-
basePath?: string;
|
|
30
|
-
cookieKey?: string;
|
|
31
|
-
token?: string;
|
|
32
|
-
};
|
|
81
|
+
api?: ApiParams;
|
|
33
82
|
logger?: LoggerType;
|
|
34
83
|
};
|
|
35
84
|
type NileDb = NilePoolConfig & {
|
|
@@ -87,53 +136,6 @@ type Tenant = {
|
|
|
87
136
|
name: string;
|
|
88
137
|
};
|
|
89
138
|
|
|
90
|
-
type ConfigRoutes = {
|
|
91
|
-
SIGNIN?: string;
|
|
92
|
-
SESSION?: string;
|
|
93
|
-
PROVIDERS?: string;
|
|
94
|
-
CSRF?: string;
|
|
95
|
-
CALLBACK?: string;
|
|
96
|
-
SIGNOUT?: string;
|
|
97
|
-
ME?: string;
|
|
98
|
-
ERROR?: string;
|
|
99
|
-
TENANTS?: string;
|
|
100
|
-
TENANT_USERS?: string;
|
|
101
|
-
USERS?: string;
|
|
102
|
-
};
|
|
103
|
-
declare class ApiConfig {
|
|
104
|
-
cookieKey?: string;
|
|
105
|
-
basePath?: string | undefined;
|
|
106
|
-
private _token?;
|
|
107
|
-
constructor({ basePath, cookieKey, token, }: {
|
|
108
|
-
basePath?: string | undefined;
|
|
109
|
-
cookieKey: string;
|
|
110
|
-
token: string | undefined;
|
|
111
|
-
});
|
|
112
|
-
get token(): string | undefined;
|
|
113
|
-
set token(value: string | undefined);
|
|
114
|
-
}
|
|
115
|
-
declare class Config {
|
|
116
|
-
user: string;
|
|
117
|
-
password: string;
|
|
118
|
-
databaseId: string;
|
|
119
|
-
databaseName: string;
|
|
120
|
-
routePrefix?: string;
|
|
121
|
-
routes?: ConfigRoutes;
|
|
122
|
-
logger?: LoggerType;
|
|
123
|
-
secureCookies?: boolean | undefined;
|
|
124
|
-
debug: boolean;
|
|
125
|
-
db: NilePoolConfig;
|
|
126
|
-
api: ApiConfig;
|
|
127
|
-
private _tenantId?;
|
|
128
|
-
private _userId?;
|
|
129
|
-
get tenantId(): string | undefined | null;
|
|
130
|
-
set tenantId(value: string | undefined | null);
|
|
131
|
-
get userId(): string | undefined | null;
|
|
132
|
-
set userId(value: string | undefined | null);
|
|
133
|
-
constructor(config?: ServerConfig, logger?: string);
|
|
134
|
-
configure: (config: ServerConfig) => Promise<Config>;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
139
|
type JWT = {
|
|
138
140
|
email: string;
|
|
139
141
|
sub: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
import pg, { PoolConfig, PoolClient } from 'pg';
|
|
2
2
|
|
|
3
|
+
type ConfigRoutes = {
|
|
4
|
+
SIGNIN?: string;
|
|
5
|
+
SESSION?: string;
|
|
6
|
+
PROVIDERS?: string;
|
|
7
|
+
CSRF?: string;
|
|
8
|
+
CALLBACK?: string;
|
|
9
|
+
SIGNOUT?: string;
|
|
10
|
+
ME?: string;
|
|
11
|
+
ERROR?: string;
|
|
12
|
+
TENANTS?: string;
|
|
13
|
+
TENANT_USERS?: string;
|
|
14
|
+
USERS?: string;
|
|
15
|
+
};
|
|
16
|
+
type ApiParams = {
|
|
17
|
+
basePath?: string | undefined;
|
|
18
|
+
cookieKey?: string;
|
|
19
|
+
token?: string | undefined;
|
|
20
|
+
callbackUrl?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
declare class ApiConfig {
|
|
23
|
+
cookieKey?: string;
|
|
24
|
+
basePath?: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* 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
|
|
27
|
+
* If this is set, any `callbackUrl` from the client will be ignored.
|
|
28
|
+
*/
|
|
29
|
+
callbackUrl?: string;
|
|
30
|
+
private _token?;
|
|
31
|
+
constructor({ basePath, cookieKey, token, callbackUrl }: ApiParams);
|
|
32
|
+
get token(): string | undefined;
|
|
33
|
+
set token(value: string | undefined);
|
|
34
|
+
}
|
|
35
|
+
declare class Config {
|
|
36
|
+
user: string;
|
|
37
|
+
password: string;
|
|
38
|
+
databaseId: string;
|
|
39
|
+
databaseName: string;
|
|
40
|
+
routePrefix?: string;
|
|
41
|
+
routes?: ConfigRoutes;
|
|
42
|
+
logger?: LoggerType;
|
|
43
|
+
secureCookies?: boolean | undefined;
|
|
44
|
+
debug: boolean;
|
|
45
|
+
db: NilePoolConfig;
|
|
46
|
+
api: ApiConfig;
|
|
47
|
+
private _tenantId?;
|
|
48
|
+
private _userId?;
|
|
49
|
+
get tenantId(): string | undefined | null;
|
|
50
|
+
set tenantId(value: string | undefined | null);
|
|
51
|
+
get userId(): string | undefined | null;
|
|
52
|
+
set userId(value: string | undefined | null);
|
|
53
|
+
constructor(config?: ServerConfig, logger?: string);
|
|
54
|
+
configure: (config: ServerConfig) => Promise<Config>;
|
|
55
|
+
}
|
|
56
|
+
|
|
3
57
|
type Opts = {
|
|
4
58
|
basePath?: string;
|
|
5
59
|
fetch?: typeof fetch;
|
|
@@ -24,12 +78,7 @@ type ServerConfig = {
|
|
|
24
78
|
configureUrl?: string;
|
|
25
79
|
secureCookies?: boolean;
|
|
26
80
|
db?: NilePoolConfig;
|
|
27
|
-
api?:
|
|
28
|
-
version?: number;
|
|
29
|
-
basePath?: string;
|
|
30
|
-
cookieKey?: string;
|
|
31
|
-
token?: string;
|
|
32
|
-
};
|
|
81
|
+
api?: ApiParams;
|
|
33
82
|
logger?: LoggerType;
|
|
34
83
|
};
|
|
35
84
|
type NileDb = NilePoolConfig & {
|
|
@@ -87,53 +136,6 @@ type Tenant = {
|
|
|
87
136
|
name: string;
|
|
88
137
|
};
|
|
89
138
|
|
|
90
|
-
type ConfigRoutes = {
|
|
91
|
-
SIGNIN?: string;
|
|
92
|
-
SESSION?: string;
|
|
93
|
-
PROVIDERS?: string;
|
|
94
|
-
CSRF?: string;
|
|
95
|
-
CALLBACK?: string;
|
|
96
|
-
SIGNOUT?: string;
|
|
97
|
-
ME?: string;
|
|
98
|
-
ERROR?: string;
|
|
99
|
-
TENANTS?: string;
|
|
100
|
-
TENANT_USERS?: string;
|
|
101
|
-
USERS?: string;
|
|
102
|
-
};
|
|
103
|
-
declare class ApiConfig {
|
|
104
|
-
cookieKey?: string;
|
|
105
|
-
basePath?: string | undefined;
|
|
106
|
-
private _token?;
|
|
107
|
-
constructor({ basePath, cookieKey, token, }: {
|
|
108
|
-
basePath?: string | undefined;
|
|
109
|
-
cookieKey: string;
|
|
110
|
-
token: string | undefined;
|
|
111
|
-
});
|
|
112
|
-
get token(): string | undefined;
|
|
113
|
-
set token(value: string | undefined);
|
|
114
|
-
}
|
|
115
|
-
declare class Config {
|
|
116
|
-
user: string;
|
|
117
|
-
password: string;
|
|
118
|
-
databaseId: string;
|
|
119
|
-
databaseName: string;
|
|
120
|
-
routePrefix?: string;
|
|
121
|
-
routes?: ConfigRoutes;
|
|
122
|
-
logger?: LoggerType;
|
|
123
|
-
secureCookies?: boolean | undefined;
|
|
124
|
-
debug: boolean;
|
|
125
|
-
db: NilePoolConfig;
|
|
126
|
-
api: ApiConfig;
|
|
127
|
-
private _tenantId?;
|
|
128
|
-
private _userId?;
|
|
129
|
-
get tenantId(): string | undefined | null;
|
|
130
|
-
set tenantId(value: string | undefined | null);
|
|
131
|
-
get userId(): string | undefined | null;
|
|
132
|
-
set userId(value: string | undefined | null);
|
|
133
|
-
constructor(config?: ServerConfig, logger?: string);
|
|
134
|
-
configure: (config: ServerConfig) => Promise<Config>;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
139
|
type JWT = {
|
|
138
140
|
email: string;
|
|
139
141
|
sub: string;
|
package/dist/index.js
CHANGED
|
@@ -96,7 +96,11 @@ async function request(url, _init, config) {
|
|
|
96
96
|
updatedHeaders.set(X_NILE_SECURECOOKIES, String(config.secureCookies));
|
|
97
97
|
}
|
|
98
98
|
updatedHeaders.set("host", requestUrl.host);
|
|
99
|
-
|
|
99
|
+
if (config.api.callbackUrl) {
|
|
100
|
+
updatedHeaders.set(X_NILE_ORIGIN, config.api.callbackUrl);
|
|
101
|
+
} else {
|
|
102
|
+
updatedHeaders.set(X_NILE_ORIGIN, requestUrl.origin);
|
|
103
|
+
}
|
|
100
104
|
const params = { ...init, headers: updatedHeaders };
|
|
101
105
|
if (params.method === "POST" || params.method === "PUT") {
|
|
102
106
|
try {
|
|
@@ -168,6 +172,13 @@ async function auth(req, config) {
|
|
|
168
172
|
return void 0;
|
|
169
173
|
}
|
|
170
174
|
}
|
|
175
|
+
var getCallbackUrl = (cfg) => {
|
|
176
|
+
const { config } = cfg;
|
|
177
|
+
if (stringCheck(process.env.NILEDB_CALLBACK_URL)) {
|
|
178
|
+
return process.env.NILEDB_CALLBACK_URL;
|
|
179
|
+
}
|
|
180
|
+
return config?.api?.callbackUrl;
|
|
181
|
+
};
|
|
171
182
|
var getSecureCookies = (cfg) => {
|
|
172
183
|
const { config } = cfg;
|
|
173
184
|
if (stringCheck(process.env.NILEDB_SECURECOOKIES)) {
|
|
@@ -399,14 +410,16 @@ var stringCheck = (str) => {
|
|
|
399
410
|
var ApiConfig = class {
|
|
400
411
|
cookieKey;
|
|
401
412
|
basePath;
|
|
413
|
+
/**
|
|
414
|
+
* 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
|
|
415
|
+
* If this is set, any `callbackUrl` from the client will be ignored.
|
|
416
|
+
*/
|
|
417
|
+
callbackUrl;
|
|
402
418
|
_token;
|
|
403
|
-
constructor({
|
|
404
|
-
basePath,
|
|
405
|
-
cookieKey,
|
|
406
|
-
token
|
|
407
|
-
}) {
|
|
419
|
+
constructor({ basePath, cookieKey, token, callbackUrl }) {
|
|
408
420
|
this.basePath = basePath;
|
|
409
421
|
this.cookieKey = cookieKey;
|
|
422
|
+
this.callbackUrl = callbackUrl;
|
|
410
423
|
this._token = token;
|
|
411
424
|
}
|
|
412
425
|
get token() {
|
|
@@ -465,6 +478,7 @@ var Config = class {
|
|
|
465
478
|
this._tenantId = getTenantId(envVarConfig);
|
|
466
479
|
this.debug = Boolean(config?.debug);
|
|
467
480
|
this._userId = config?.userId;
|
|
481
|
+
const callbackUrl = config?.api?.callbackUrl ?? getCallbackUrl(envVarConfig);
|
|
468
482
|
const basePath = getBasePath(envVarConfig);
|
|
469
483
|
const { host, port, ...dbConfig } = config?.db ?? {};
|
|
470
484
|
const configuredHost = host ?? getDbHost(envVarConfig);
|
|
@@ -472,7 +486,8 @@ var Config = class {
|
|
|
472
486
|
this.api = new ApiConfig({
|
|
473
487
|
basePath,
|
|
474
488
|
cookieKey: config?.api?.cookieKey ?? "token",
|
|
475
|
-
token: getToken({ config })
|
|
489
|
+
token: getToken({ config }),
|
|
490
|
+
callbackUrl
|
|
476
491
|
});
|
|
477
492
|
this.db = {
|
|
478
493
|
user: this.user,
|
|
@@ -491,6 +506,7 @@ var Config = class {
|
|
|
491
506
|
config
|
|
492
507
|
};
|
|
493
508
|
const { host, port, ...dbConfig } = config.db ?? {};
|
|
509
|
+
const callbackUrl = config?.api?.callbackUrl ?? getCallbackUrl(envVarConfig);
|
|
494
510
|
let configuredHost = host ?? getDbHost(envVarConfig);
|
|
495
511
|
const configuredPort = port ?? getDbPort(envVarConfig);
|
|
496
512
|
let basePath = getBasePath(envVarConfig);
|
|
@@ -499,7 +515,8 @@ var Config = class {
|
|
|
499
515
|
this.api = new ApiConfig({
|
|
500
516
|
basePath,
|
|
501
517
|
cookieKey: config?.api?.cookieKey ?? "token",
|
|
502
|
-
token: getToken({ config })
|
|
518
|
+
token: getToken({ config }),
|
|
519
|
+
callbackUrl
|
|
503
520
|
});
|
|
504
521
|
this.db = {
|
|
505
522
|
user: this.user,
|
|
@@ -588,7 +605,8 @@ var Config = class {
|
|
|
588
605
|
this.api = new ApiConfig({
|
|
589
606
|
basePath,
|
|
590
607
|
cookieKey: config?.api?.cookieKey ?? "token",
|
|
591
|
-
token: getToken({ config })
|
|
608
|
+
token: getToken({ config }),
|
|
609
|
+
callbackUrl
|
|
592
610
|
});
|
|
593
611
|
this.db = {
|
|
594
612
|
user: this.user,
|
|
@@ -1474,7 +1492,7 @@ async function route10(request2, config) {
|
|
|
1474
1492
|
if (request2.method === "POST") {
|
|
1475
1493
|
init.body = request2.body;
|
|
1476
1494
|
const [provider] = new URL(request2.url).pathname.split("/").reverse();
|
|
1477
|
-
url = `${proxyRoutes(config)[key7]}
|
|
1495
|
+
url = `${proxyRoutes(config)[key7]}${provider !== "signout" ? `/${provider}` : ""}`;
|
|
1478
1496
|
}
|
|
1479
1497
|
const res = await request(url, { ...init, request: request2 }, config);
|
|
1480
1498
|
return res;
|