@niledatabase/server 4.2.0 → 5.0.0-alpha.1
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/express.d.mts +2 -2
- package/dist/express.d.ts +2 -2
- package/dist/express.js +1225 -13
- package/dist/express.js.map +1 -1
- package/dist/express.mjs +1225 -13
- package/dist/express.mjs.map +1 -1
- package/dist/index.d.mts +335 -228
- package/dist/index.d.ts +335 -228
- package/dist/index.js +1959 -2278
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1956 -2279
- package/dist/index.mjs.map +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nitro.js.map +1 -1
- package/dist/nitro.mjs +1 -1
- package/dist/nitro.mjs.map +1 -1
- package/package.json +2 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
import pg, { PoolConfig, PoolClient } from 'pg';
|
|
2
2
|
|
|
3
|
+
declare class Config {
|
|
4
|
+
routes: Routes;
|
|
5
|
+
handlers: {
|
|
6
|
+
GET: (req: Request) => Promise<void | Response>;
|
|
7
|
+
POST: (req: Request) => Promise<void | Response>;
|
|
8
|
+
DELETE: (req: Request) => Promise<void | Response>;
|
|
9
|
+
PUT: (req: Request) => Promise<void | Response>;
|
|
10
|
+
};
|
|
11
|
+
paths: {
|
|
12
|
+
get: string[];
|
|
13
|
+
post: string[];
|
|
14
|
+
delete: string[];
|
|
15
|
+
put: string[];
|
|
16
|
+
};
|
|
17
|
+
logger?: LoggerType;
|
|
18
|
+
/**
|
|
19
|
+
* Stores the set tenant id from Server for use in sub classes
|
|
20
|
+
*/
|
|
21
|
+
tenantId: string | null | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Stores the set user id from Server for use in sub classes
|
|
24
|
+
*/
|
|
25
|
+
userId: string | null | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Stores the headers to be used in `fetch` calls
|
|
28
|
+
*/
|
|
29
|
+
headers: Headers;
|
|
30
|
+
/**
|
|
31
|
+
* The nile-auth url
|
|
32
|
+
*/
|
|
33
|
+
apiUrl: string;
|
|
34
|
+
origin?: string | undefined | null;
|
|
35
|
+
debug?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* To use secure cookies or not in the fetch
|
|
38
|
+
*/
|
|
39
|
+
secureCookies?: boolean;
|
|
40
|
+
callbackUrl?: string;
|
|
41
|
+
/**
|
|
42
|
+
* change the starting route
|
|
43
|
+
*/
|
|
44
|
+
routePrefix: string;
|
|
45
|
+
db: NilePoolConfig;
|
|
46
|
+
constructor(config?: NileConfig, logger?: string);
|
|
47
|
+
}
|
|
48
|
+
|
|
3
49
|
type Routes = {
|
|
4
50
|
SIGNIN: string;
|
|
5
51
|
SESSION: string;
|
|
@@ -9,6 +55,7 @@ type Routes = {
|
|
|
9
55
|
SIGNOUT: string;
|
|
10
56
|
ERROR: string;
|
|
11
57
|
ME: string;
|
|
58
|
+
USER_TENANTS: string;
|
|
12
59
|
USERS: string;
|
|
13
60
|
TENANTS: string;
|
|
14
61
|
TENANT: string;
|
|
@@ -20,53 +67,6 @@ type Routes = {
|
|
|
20
67
|
LOG: string;
|
|
21
68
|
};
|
|
22
69
|
|
|
23
|
-
type ApiParams = {
|
|
24
|
-
basePath?: string | undefined;
|
|
25
|
-
cookieKey?: string;
|
|
26
|
-
token?: string | undefined;
|
|
27
|
-
callbackUrl?: string | undefined;
|
|
28
|
-
routes?: Partial<Routes>;
|
|
29
|
-
routePrefix?: string | undefined;
|
|
30
|
-
secureCookies?: boolean;
|
|
31
|
-
origin?: null | undefined | string;
|
|
32
|
-
headers?: null | Headers | Record<string, string>;
|
|
33
|
-
};
|
|
34
|
-
declare class ApiConfig {
|
|
35
|
-
#private;
|
|
36
|
-
cookieKey?: string;
|
|
37
|
-
basePath?: string | undefined;
|
|
38
|
-
routes?: Partial<Routes>;
|
|
39
|
-
routePrefix?: string;
|
|
40
|
-
secureCookies?: boolean;
|
|
41
|
-
origin?: string | null;
|
|
42
|
-
headers?: Headers | null;
|
|
43
|
-
/**
|
|
44
|
-
* 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
|
|
45
|
-
* If this is set, any `callbackUrl` from the client will be ignored.
|
|
46
|
-
*/
|
|
47
|
-
callbackUrl?: string;
|
|
48
|
-
constructor(config?: ServerConfig, logger?: string);
|
|
49
|
-
get token(): string | undefined;
|
|
50
|
-
set token(value: string | undefined);
|
|
51
|
-
}
|
|
52
|
-
declare class Config {
|
|
53
|
-
#private;
|
|
54
|
-
user: string;
|
|
55
|
-
password: string;
|
|
56
|
-
databaseId: string;
|
|
57
|
-
databaseName: string;
|
|
58
|
-
logger?: LoggerType;
|
|
59
|
-
debug: boolean;
|
|
60
|
-
db: NilePoolConfig;
|
|
61
|
-
api: ApiConfig;
|
|
62
|
-
get tenantId(): string | undefined | null;
|
|
63
|
-
set tenantId(value: string | undefined | null);
|
|
64
|
-
get userId(): string | undefined | null;
|
|
65
|
-
set userId(value: string | undefined | null);
|
|
66
|
-
constructor(config?: ServerConfig, logger?: string);
|
|
67
|
-
configure: (config: ServerConfig) => Promise<Config>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
70
|
type Opts = {
|
|
71
71
|
basePath?: string;
|
|
72
72
|
fetch?: typeof fetch;
|
|
@@ -80,31 +80,175 @@ type LoggerType = {
|
|
|
80
80
|
error?: (args: unknown | unknown[]) => void;
|
|
81
81
|
debug?: (args: unknown | unknown[]) => void;
|
|
82
82
|
};
|
|
83
|
-
type
|
|
83
|
+
type NileConfig = {
|
|
84
|
+
/**
|
|
85
|
+
* The specific database id. Either passed in or figured out by NILEDB_API_URL
|
|
86
|
+
* process.env.NILEDB_ID
|
|
87
|
+
*/
|
|
84
88
|
databaseId?: string;
|
|
89
|
+
/**
|
|
90
|
+
* The user UUID to the database
|
|
91
|
+
* process.env.NILEDB_USER
|
|
92
|
+
*/
|
|
85
93
|
user?: string;
|
|
94
|
+
/**
|
|
95
|
+
* The password UUID to the database
|
|
96
|
+
* process.env.NILEDB_PASSWORD
|
|
97
|
+
*/
|
|
86
98
|
password?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The name of the database. Automatically obtained from NILEDB_POSTGRES_URL
|
|
101
|
+
* process.env.NILEDB_NAME
|
|
102
|
+
*/
|
|
87
103
|
databaseName?: string;
|
|
104
|
+
/**
|
|
105
|
+
* A tenant id. Scopes requests to a specific tenant, both API and DB
|
|
106
|
+
* process.env.NILEDB_TENANT
|
|
107
|
+
*/
|
|
88
108
|
tenantId?: string | null | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* A user id. Possibly not the logged in user, used for setting database context (nile.user_id)
|
|
111
|
+
* Generally speaking, this wouldn't be used for authentication, and in some cases simply won't do anything on some endpoints
|
|
112
|
+
*/
|
|
89
113
|
userId?: string | null | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Shows a bunch of logging on the server side to see what's being done between the sdk and nile-auth
|
|
116
|
+
*/
|
|
90
117
|
debug?: boolean;
|
|
91
|
-
|
|
118
|
+
/**
|
|
119
|
+
* DB configuration overrides. Environment variables are the way to go, but maybe you need something more
|
|
120
|
+
*/
|
|
92
121
|
db?: NilePoolConfig;
|
|
93
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Some kind of logger if you want to send to an external service
|
|
124
|
+
*/
|
|
94
125
|
logger?: LoggerType;
|
|
126
|
+
/**
|
|
127
|
+
* The configuration value that maps to `NILEDB_API_URL` - its going to be nile-auth (or similar service)
|
|
128
|
+
*/
|
|
129
|
+
apiUrl?: string | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Ignore client callbackUrls by setting this.
|
|
132
|
+
* You can force the callback URL server side to be sure nile-auth redirects to whatever location.
|
|
133
|
+
*/
|
|
134
|
+
callbackUrl?: string | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Need to override some routes? Change it here
|
|
137
|
+
*/
|
|
138
|
+
routes?: Partial<Routes>;
|
|
139
|
+
/**
|
|
140
|
+
* don't like the default `/api`? change it here
|
|
141
|
+
*/
|
|
142
|
+
routePrefix?: string | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* In some cases, you may want to force secure cookies.
|
|
145
|
+
* The SDK handles this for you, but might be necessary in some firewall / internal cases
|
|
146
|
+
*/
|
|
147
|
+
secureCookies?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* The origin for the requests.
|
|
150
|
+
* Allows the setting of the callback origin to a random FE
|
|
151
|
+
* eg FE localhost:3001 -> BE: localhost:5432 would set to localhost:3001 to be sure nile-auth uses that.
|
|
152
|
+
* In full stack cases, will just be the `host` header of the incoming request, which is used by default
|
|
153
|
+
*/
|
|
154
|
+
origin?: null | undefined | string;
|
|
155
|
+
/**
|
|
156
|
+
* Set the headers to use in API requests.
|
|
157
|
+
* The `cookie` would be expected if you are setting this, else most calls will be unauthorized
|
|
158
|
+
*/
|
|
159
|
+
headers?: null | Headers | Record<string, string>;
|
|
95
160
|
};
|
|
96
161
|
type NileDb = NilePoolConfig & {
|
|
97
162
|
tenantId?: string;
|
|
98
163
|
};
|
|
99
164
|
type AfterCreate = (conn: PoolClient, done: (err: null | Error, conn: PoolClient) => void) => void;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
165
|
+
interface NileBody<R, B> {
|
|
166
|
+
readonly body: ReadableStream<Uint8Array> | null | B;
|
|
167
|
+
readonly bodyUsed: boolean;
|
|
168
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
169
|
+
blob(): Promise<Blob>;
|
|
170
|
+
formData(): Promise<FormData>;
|
|
171
|
+
json(): Promise<R>;
|
|
172
|
+
text(): Promise<string>;
|
|
173
|
+
}
|
|
174
|
+
interface NResponse<T> extends NileBody<T, any> {
|
|
175
|
+
readonly headers: Headers;
|
|
176
|
+
readonly ok: boolean;
|
|
177
|
+
readonly redirected: boolean;
|
|
178
|
+
readonly status: number;
|
|
179
|
+
readonly statusText: string;
|
|
180
|
+
readonly type: ResponseType;
|
|
181
|
+
readonly url: string;
|
|
182
|
+
clone(): Response;
|
|
183
|
+
}
|
|
184
|
+
interface NRequest<T> extends NileBody<any, T> {
|
|
185
|
+
/** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
|
|
186
|
+
readonly cache: RequestCache;
|
|
187
|
+
/** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
|
|
188
|
+
readonly credentials: RequestCredentials;
|
|
189
|
+
/** Returns the kind of resource requested by request, e.g., "document" or "script". */
|
|
190
|
+
readonly destination: RequestDestination;
|
|
191
|
+
/** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
|
|
192
|
+
readonly headers: Headers;
|
|
193
|
+
/** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
|
|
194
|
+
readonly integrity: string;
|
|
195
|
+
/** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
|
|
196
|
+
readonly keepalive: boolean;
|
|
197
|
+
/** Returns request's HTTP method, which is "GET" by default. */
|
|
198
|
+
readonly method: string;
|
|
199
|
+
/** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
|
|
200
|
+
readonly mode: RequestMode;
|
|
201
|
+
/** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
|
|
202
|
+
readonly redirect: RequestRedirect;
|
|
203
|
+
/** Returns the referrer of request. Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the `Referer` header of the request being made. */
|
|
204
|
+
readonly referrer: string;
|
|
205
|
+
/** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
|
|
206
|
+
readonly referrerPolicy: ReferrerPolicy;
|
|
207
|
+
/** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
|
|
208
|
+
readonly signal: AbortSignal;
|
|
209
|
+
/** Returns the URL of request as a string. */
|
|
210
|
+
readonly url: string;
|
|
211
|
+
clone(): Request;
|
|
212
|
+
}
|
|
213
|
+
type NileRequest<T> = NRequest<T> | T;
|
|
214
|
+
declare const APIErrorErrorCodeEnum: {
|
|
215
|
+
readonly InternalError: "internal_error";
|
|
216
|
+
readonly BadRequest: "bad_request";
|
|
217
|
+
readonly EntityNotFound: "entity_not_found";
|
|
218
|
+
readonly DuplicateEntity: "duplicate_entity";
|
|
219
|
+
readonly InvalidCredentials: "invalid_credentials";
|
|
220
|
+
readonly UnknownOidcProvider: "unknown_oidc_provider";
|
|
221
|
+
readonly ProviderAlreadyExists: "provider_already_exists";
|
|
222
|
+
readonly ProviderConfigError: "provider_config_error";
|
|
223
|
+
readonly ProviderMismatch: "provider_mismatch";
|
|
224
|
+
readonly ProviderUpdateError: "provider_update_error";
|
|
225
|
+
readonly SessionStateMissing: "session_state_missing";
|
|
226
|
+
readonly SessionStateMismatch: "session_state_mismatch";
|
|
227
|
+
readonly OidcCodeMissing: "oidc_code_missing";
|
|
107
228
|
};
|
|
229
|
+
type APIErrorErrorCodeEnum = (typeof APIErrorErrorCodeEnum)[keyof typeof APIErrorErrorCodeEnum];
|
|
230
|
+
interface APIError {
|
|
231
|
+
[key: string]: any | any;
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
* @type {string}
|
|
235
|
+
* @memberof APIError
|
|
236
|
+
*/
|
|
237
|
+
errorCode: APIErrorErrorCodeEnum;
|
|
238
|
+
/**
|
|
239
|
+
*
|
|
240
|
+
* @type {string}
|
|
241
|
+
* @memberof APIError
|
|
242
|
+
*/
|
|
243
|
+
message: string;
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @type {number}
|
|
247
|
+
* @memberof APIError
|
|
248
|
+
*/
|
|
249
|
+
statusCode: number;
|
|
250
|
+
}
|
|
251
|
+
type NileResponse<T> = Promise<T | NResponse<T & APIError>>;
|
|
108
252
|
|
|
109
253
|
interface CreateBasicUserRequest {
|
|
110
254
|
email: string;
|
|
@@ -150,9 +294,7 @@ interface User {
|
|
|
150
294
|
created: string;
|
|
151
295
|
updated?: string;
|
|
152
296
|
emailVerified?: string | null;
|
|
153
|
-
tenants:
|
|
154
|
-
id: string;
|
|
155
|
-
}[];
|
|
297
|
+
tenants: string[];
|
|
156
298
|
}
|
|
157
299
|
|
|
158
300
|
type Tenant = {
|
|
@@ -160,12 +302,13 @@ type Tenant = {
|
|
|
160
302
|
name: string;
|
|
161
303
|
};
|
|
162
304
|
|
|
305
|
+
type ProviderName = 'discord' | 'github' | 'google' | 'hubspot' | 'linkedin' | 'slack' | 'twitter' | 'email' | 'credentials' | 'azure';
|
|
163
306
|
type Provider = {
|
|
164
307
|
id: string;
|
|
165
308
|
name: string;
|
|
166
309
|
type: string;
|
|
167
310
|
signinUrl: string;
|
|
168
|
-
|
|
311
|
+
callbackUrl: string;
|
|
169
312
|
};
|
|
170
313
|
type JWT = {
|
|
171
314
|
email: string;
|
|
@@ -188,193 +331,157 @@ type ActiveSession = {
|
|
|
188
331
|
};
|
|
189
332
|
};
|
|
190
333
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
text(): Promise<string>;
|
|
199
|
-
}
|
|
200
|
-
interface NRequest<T> extends NileBody<any, T> {
|
|
201
|
-
/** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
|
|
202
|
-
readonly cache: RequestCache;
|
|
203
|
-
/** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
|
|
204
|
-
readonly credentials: RequestCredentials;
|
|
205
|
-
/** Returns the kind of resource requested by request, e.g., "document" or "script". */
|
|
206
|
-
readonly destination: RequestDestination;
|
|
207
|
-
/** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
|
|
208
|
-
readonly headers: Headers;
|
|
209
|
-
/** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
|
|
210
|
-
readonly integrity: string;
|
|
211
|
-
/** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
|
|
212
|
-
readonly keepalive: boolean;
|
|
213
|
-
/** Returns request's HTTP method, which is "GET" by default. */
|
|
214
|
-
readonly method: string;
|
|
215
|
-
/** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
|
|
216
|
-
readonly mode: RequestMode;
|
|
217
|
-
/** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
|
|
218
|
-
readonly redirect: RequestRedirect;
|
|
219
|
-
/** Returns the referrer of request. Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the `Referer` header of the request being made. */
|
|
220
|
-
readonly referrer: string;
|
|
221
|
-
/** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
|
|
222
|
-
readonly referrerPolicy: ReferrerPolicy;
|
|
223
|
-
/** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
|
|
224
|
-
readonly signal: AbortSignal;
|
|
225
|
-
/** Returns the URL of request as a string. */
|
|
226
|
-
readonly url: string;
|
|
227
|
-
clone(): Request;
|
|
228
|
-
}
|
|
229
|
-
type NileRequest<T> = NRequest<T> | T;
|
|
230
|
-
|
|
231
|
-
declare class Auth extends Config {
|
|
232
|
-
headers?: Headers;
|
|
233
|
-
resetHeaders?: (headers?: Headers) => void;
|
|
234
|
-
constructor(config: Config, headers?: Headers, params?: {
|
|
235
|
-
resetHeaders: () => void;
|
|
236
|
-
});
|
|
237
|
-
handleHeaders(init?: RequestInit): RequestInit | undefined;
|
|
238
|
-
get sessionUrl(): string;
|
|
239
|
-
getSession: <T = JWT | ActiveSession | Response | undefined>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
|
|
240
|
-
get getCsrfUrl(): string;
|
|
241
|
-
getCsrf<T = Response | JSON>(req: NileRequest<void> | Headers, init?: RequestInit, raw?: boolean): Promise<T>;
|
|
242
|
-
get listProvidersUrl(): string;
|
|
243
|
-
listProviders: <T = Response | {
|
|
244
|
-
[key: string]: Provider;
|
|
245
|
-
}>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
|
|
246
|
-
get signOutUrl(): string;
|
|
247
|
-
signOut: <T = Response | {
|
|
248
|
-
url: string;
|
|
249
|
-
}>(req: NileRequest<void | {
|
|
250
|
-
callbackUrl?: string;
|
|
251
|
-
}> | Headers, init?: RequestInit) => Promise<T>;
|
|
334
|
+
declare class Users {
|
|
335
|
+
#private;
|
|
336
|
+
constructor(config: Config);
|
|
337
|
+
updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated'>>, rawResponse?: boolean): Promise<T>;
|
|
338
|
+
removeSelf(): Promise<Response>;
|
|
339
|
+
getSelf(rawResponse?: true): Promise<Response>;
|
|
340
|
+
getSelf<T = User | Response>(): Promise<T>;
|
|
252
341
|
}
|
|
253
342
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
343
|
+
type ReqContext = {
|
|
344
|
+
userId?: string;
|
|
345
|
+
tenantId?: string;
|
|
346
|
+
};
|
|
347
|
+
type JoinTenantRequest = string | ReqContext | {
|
|
348
|
+
id: string;
|
|
349
|
+
};
|
|
350
|
+
declare class Tenants {
|
|
351
|
+
#private;
|
|
352
|
+
constructor(config: Config);
|
|
353
|
+
create<T = Tenant | Response>(name: string, rawResponse?: boolean): Promise<T>;
|
|
354
|
+
create<T = Tenant | Response>(payload: {
|
|
261
355
|
name: string;
|
|
262
356
|
id?: string;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}> | Headers | string | void, init?: RequestInit) => Promise<T>;
|
|
267
|
-
get tenantListUrl(): string;
|
|
268
|
-
listTenants: <T = Tenant[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
|
|
269
|
-
deleteTenant: <T = Response>(req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<T>;
|
|
270
|
-
updateTenant: <T = Tenant | Response>(req: NileRequest<void> | Headers | {
|
|
271
|
-
name: string;
|
|
272
|
-
}, init?: RequestInit) => Promise<T>;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
declare class Users extends Config {
|
|
276
|
-
headers?: Headers;
|
|
277
|
-
constructor(config: Config, headers?: Headers);
|
|
278
|
-
usersUrl(user: CreateBasicUserRequest): string;
|
|
279
|
-
get tenantUsersUrl(): string;
|
|
280
|
-
get linkUsersUrl(): string;
|
|
281
|
-
get tenantUserUrl(): string;
|
|
282
|
-
handleHeaders(init?: RequestInit): RequestInit | undefined;
|
|
283
|
-
createUser: <T = User | Response>(user: CreateBasicUserRequest, init?: RequestInit) => Promise<T>;
|
|
284
|
-
createTenantUser: <T = User | Response>(req: NileRequest<CreateTenantUserRequest>, init?: RequestInit) => Promise<T>;
|
|
285
|
-
updateUser: <T = User[] | Response>(req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<T>;
|
|
286
|
-
listUsers: <T = User[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
|
|
287
|
-
linkUser: <T = User | Response>(req: NileRequest<{
|
|
357
|
+
}, rawResponse?: boolean): Promise<T>;
|
|
358
|
+
delete<T = Response>(id?: string): Promise<T>;
|
|
359
|
+
delete<T = Response>(payload: {
|
|
288
360
|
id: string;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
361
|
+
}): Promise<T>;
|
|
362
|
+
get(rawResponse: true): Promise<Response>;
|
|
363
|
+
get<T = Tenant | Response>(id: string, rawResponse?: boolean): Promise<T>;
|
|
364
|
+
get<T = Tenant | Response>(payload: {
|
|
292
365
|
id: string;
|
|
366
|
+
}, rawResponse?: boolean): Promise<T>;
|
|
367
|
+
update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
|
|
368
|
+
update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
|
|
369
|
+
list(rawResponse: true): Promise<Response>;
|
|
370
|
+
list<T = Tenant[] | Response>(): Promise<T>;
|
|
371
|
+
leaveTenant<T = Response>(req?: string | {
|
|
372
|
+
tenantId: string;
|
|
373
|
+
}): Promise<T>;
|
|
374
|
+
addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
|
|
375
|
+
addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
|
|
376
|
+
removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
|
|
377
|
+
users(req: boolean): Promise<Response>;
|
|
378
|
+
users<T = User[] | Response>(req?: boolean | {
|
|
293
379
|
tenantId?: string;
|
|
294
|
-
}
|
|
295
|
-
get meUrl(): string;
|
|
296
|
-
me: <T = User | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
|
|
297
|
-
updateMe: <T = User | Response>(req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<T>;
|
|
380
|
+
}, rawResponse?: boolean): Promise<T>;
|
|
298
381
|
}
|
|
299
382
|
|
|
300
|
-
|
|
383
|
+
type SignUpPayload = {
|
|
384
|
+
email: string;
|
|
385
|
+
password: string;
|
|
386
|
+
tenantId?: string;
|
|
387
|
+
newTenantName?: string;
|
|
388
|
+
};
|
|
389
|
+
declare class Auth {
|
|
301
390
|
#private;
|
|
302
|
-
config: Config;
|
|
303
|
-
users: Users;
|
|
304
|
-
auth: Auth;
|
|
305
|
-
tenants: Tenants;
|
|
306
|
-
routes: Routes;
|
|
307
|
-
handlers: {
|
|
308
|
-
GET: (req: Request) => Promise<void | Response>;
|
|
309
|
-
POST: (req: Request) => Promise<void | Response>;
|
|
310
|
-
DELETE: (req: Request) => Promise<void | Response>;
|
|
311
|
-
PUT: (req: Request) => Promise<void | Response>;
|
|
312
|
-
};
|
|
313
|
-
handlersWithContext: {
|
|
314
|
-
GET: (req: Request) => Promise<{
|
|
315
|
-
response: void | Response;
|
|
316
|
-
nile: Server;
|
|
317
|
-
}>;
|
|
318
|
-
POST: (req: Request) => Promise<{
|
|
319
|
-
response: void | Response;
|
|
320
|
-
nile: Server;
|
|
321
|
-
}>;
|
|
322
|
-
DELETE: (req: Request) => Promise<{
|
|
323
|
-
response: void | Response;
|
|
324
|
-
nile: Server;
|
|
325
|
-
}>;
|
|
326
|
-
PUT: (req: Request) => Promise<{
|
|
327
|
-
response: void | Response;
|
|
328
|
-
nile: Server;
|
|
329
|
-
}>;
|
|
330
|
-
};
|
|
331
|
-
paths: {
|
|
332
|
-
get: string[];
|
|
333
|
-
post: string[];
|
|
334
|
-
delete: string[];
|
|
335
|
-
put: string[];
|
|
336
|
-
};
|
|
337
391
|
constructor(config: Config);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
392
|
+
getSession(rawResponse: true): Promise<Response>;
|
|
393
|
+
getSession<T = JWT | ActiveSession | undefined>(rawResponse?: false): Promise<T>;
|
|
394
|
+
getCsrf(rawResponse: true): Promise<Response>;
|
|
395
|
+
getCsrf<T = Response | JSON>(rawResponse?: false): Promise<T>;
|
|
396
|
+
listProviders(rawResponse: true): Promise<Response>;
|
|
397
|
+
listProviders<T = {
|
|
398
|
+
[key: string]: Provider;
|
|
399
|
+
}>(rawResponse?: false): Promise<T>;
|
|
400
|
+
signOut(): Promise<Response>;
|
|
341
401
|
/**
|
|
342
|
-
*
|
|
402
|
+
* signUp only works with email + password
|
|
403
|
+
* @param payload
|
|
404
|
+
* @param rawResponse
|
|
343
405
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
406
|
+
signUp(payload: SignUpPayload, rawResponse: true): Promise<Response>;
|
|
407
|
+
signUp<T = User | Response>(payload: SignUpPayload): Promise<T>;
|
|
408
|
+
/**
|
|
409
|
+
* The return value from this will be a redirect for the client
|
|
410
|
+
* In most cases, you should forward the response directly to the client
|
|
411
|
+
* @param payload
|
|
412
|
+
* @param rawResponse
|
|
413
|
+
*/
|
|
414
|
+
signIn<T = Response>(provider: ProviderName, payload?: {
|
|
348
415
|
email: string;
|
|
349
416
|
password: string;
|
|
350
|
-
},
|
|
351
|
-
returnResponse?: boolean;
|
|
352
|
-
}) => Promise<Response | undefined>;
|
|
353
|
-
session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
|
|
354
|
-
setContext: (req: Request | Headers | Record<string, string> | unknown) => void;
|
|
417
|
+
}, rawResponse?: true): Promise<T>;
|
|
355
418
|
}
|
|
419
|
+
declare function parseCSRF(headers?: Headers): string | undefined;
|
|
420
|
+
declare function parseCallback(headers?: Headers): string | undefined;
|
|
421
|
+
declare function parseToken(headers?: Headers): string | undefined;
|
|
422
|
+
|
|
423
|
+
type CTXHandlerType = {
|
|
424
|
+
GET: (req: Request) => Promise<{
|
|
425
|
+
response: void | Response;
|
|
426
|
+
nile: Server;
|
|
427
|
+
}>;
|
|
428
|
+
POST: (req: Request) => Promise<{
|
|
429
|
+
response: void | Response;
|
|
430
|
+
nile: Server;
|
|
431
|
+
}>;
|
|
432
|
+
DELETE: (req: Request) => Promise<{
|
|
433
|
+
response: void | Response;
|
|
434
|
+
nile: Server;
|
|
435
|
+
}>;
|
|
436
|
+
PUT: (req: Request) => Promise<{
|
|
437
|
+
response: void | Response;
|
|
438
|
+
nile: Server;
|
|
439
|
+
}>;
|
|
440
|
+
};
|
|
356
441
|
|
|
357
442
|
declare class Server {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
set userId(userId: string | undefined | null);
|
|
367
|
-
get tenantId(): string | undefined | null;
|
|
368
|
-
set tenantId(tenantId: string | undefined | null);
|
|
369
|
-
get token(): string | undefined | null;
|
|
370
|
-
set token(token: string | undefined | null);
|
|
371
|
-
get db(): pg.Pool;
|
|
372
|
-
clearConnections(): void;
|
|
443
|
+
#private;
|
|
444
|
+
users: Users;
|
|
445
|
+
tenants: Tenants;
|
|
446
|
+
auth: Auth;
|
|
447
|
+
constructor(config?: NileConfig);
|
|
448
|
+
get db(): pg.Pool & {
|
|
449
|
+
clearConnections: () => void;
|
|
450
|
+
};
|
|
373
451
|
/**
|
|
374
452
|
* A convenience function that applies a config and ensures whatever was passed is set properly
|
|
375
453
|
*/
|
|
376
|
-
getInstance<T = Request | Headers | Record<string, string>>(config:
|
|
454
|
+
getInstance<T = Request | Headers | Record<string, string>>(config: NileConfig, req?: T): Server;
|
|
455
|
+
getPaths(): {
|
|
456
|
+
get: string[];
|
|
457
|
+
post: string[];
|
|
458
|
+
delete: string[];
|
|
459
|
+
put: string[];
|
|
460
|
+
};
|
|
461
|
+
get handlers(): {
|
|
462
|
+
GET: (req: Request) => Promise<void | Response>;
|
|
463
|
+
POST: (req: Request) => Promise<void | Response>;
|
|
464
|
+
DELETE: (req: Request) => Promise<void | Response>;
|
|
465
|
+
PUT: (req: Request) => Promise<void | Response>;
|
|
466
|
+
withContext: CTXHandlerType;
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Allow the setting of headers from a req or header object.
|
|
470
|
+
* Makes it possible to handle REST requests easily
|
|
471
|
+
* Also makes it easy to set user + tenant in some way
|
|
472
|
+
* @param req
|
|
473
|
+
* @returns undefined
|
|
474
|
+
*/
|
|
475
|
+
setContext(req: Request | Headers | Record<string, string> | unknown | {
|
|
476
|
+
tenantId?: string;
|
|
477
|
+
userId?: string;
|
|
478
|
+
}): void;
|
|
479
|
+
getContext(): {
|
|
480
|
+
headers: Headers | undefined;
|
|
481
|
+
userId: string | null | undefined;
|
|
482
|
+
tenantId: string | null | undefined;
|
|
483
|
+
};
|
|
377
484
|
}
|
|
378
|
-
declare function create(config?:
|
|
485
|
+
declare function create(config?: NileConfig): Server;
|
|
379
486
|
|
|
380
|
-
export { type ActiveSession, type AfterCreate, type CreateBasicUserRequest, type CreateTenantUserRequest, type
|
|
487
|
+
export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CreateBasicUserRequest, type CreateTenantUserRequest, type JWT, type LoggerType, type LoginUserResponse, type LoginUserResponseToken, LoginUserResponseTokenTypeEnum, create as Nile, type NileConfig, type NileDb, type NilePoolConfig, type NileRequest, type NileResponse, type Opts, Server, type Tenant, type User, parseCSRF, parseCallback, parseToken };
|